@kymoscope/sdk 0.26.0 → 0.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,46 +1,46 @@
1
- var e=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);const t=1<<20,n=16<<20;var r=class{size;bytesRead=0;#e;#t=new Map;constructor(e){this.#e=e,this.size=e.size}async read(e,n){let r=Math.min(this.size,e+n);if(r<=e)return new Uint8Array;if(r-e>t)return this.slice(e,r-e);let i=Math.floor(e/t),a=Math.floor((r-1)/t),o=await this.#n(i);if(i===a)return o.subarray(e-i*t,r-i*t);let s=new Uint8Array(r-e),c=o.subarray(e-i*t);return s.set(c),s.set((await this.#n(a)).subarray(0,r-a*t),c.length),s}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,r=n){let i=Math.min(this.size,e+t);for(let t=e;t<i;t+=r)yield{offset:t,bytes:await this.slice(t,Math.min(r,i-t))}}async#n(e){let n=this.#t.get(e);if(n)return this.#t.delete(e),this.#t.set(e,n),n;let r=await this.slice(e*t,t);return this.#t.size>=64&&this.#t.delete(this.#t.keys().next().value),this.#t.set(e,r),r}};const i=e=>new DataView(e.buffer,e.byteOffset,e.byteLength);function a(e,t,n=!0){let r=e.getUint32(n?t:t+4,n);return e.getUint32(n?t+4:t,n)*4294967296+r}function o(e,t,n=!0){let r=e.getUint32(n?t:t+4,n);return e.getInt32(n?t+4:t,n)*4294967296+r}const s=new TextDecoder(`utf-8`),c=new TextDecoder(`latin1`);function l(e,t=!1){let n=e.indexOf(0);return(t?c:s).decode(n<0?e:e.subarray(0,n))}const u=e=>c.decode(e),d=e=>s.decode(e);function f(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}function p(e,t){return e.selection.find(e=>e.group===t)?.channels??[]}const m={sin:Math.sin,cos:Math.cos,tan:Math.tan,asin:Math.asin,acos:Math.acos,atan:Math.atan,sinh:Math.sinh,cosh:Math.cosh,tanh:Math.tanh,exp:Math.exp,ln:Math.log,log:Math.log,log10:Math.log10,sqrt:Math.sqrt,abs:Math.abs,pow:Math.pow,min:Math.min,max:Math.max};function h(e){if(e.length>4096)return null;let t=e.match(/\d+\.?\d*(?:[eE][+-]?\d+)?|\.\d+(?:[eE][+-]?\d+)?|[A-Za-z_]\w*|\*\*|[-+*/^(),]|\S/g)??[],n=0,r=()=>t[n],i=()=>{throw Error(`formula`)},a=e=>{t[n++]!==e&&i()},o=()=>{let e=s();for(;r()===`+`||r()===`-`;){let r=t[n++],i=e,a=s();e=r===`+`?e=>i(e)+a(e):e=>i(e)-a(e)}return e},s=()=>{let e=c();for(;r()===`*`||r()===`/`;){let r=t[n++],i=e,a=c();e=r===`*`?e=>i(e)*a(e):e=>i(e)/a(e)}return e},c=()=>{if(r()===`-`){n++;let e=c();return t=>-e(t)}return r()===`+`?(n++,c()):l()},l=()=>{let e=u();if(r()===`^`||r()===`**`){n++;let t=c();return n=>e(n)**t(n)}return e},u=()=>{let e=t[n++];if(e===void 0&&i(),e===`(`){let e=o();return a(`)`),e}if(/^[\d.]/.test(e)){let t=Number(e);return Number.isFinite(t)||i(),()=>t}if(e===`X`||e===`x`||e===`X1`)return e=>e;if(Object.hasOwn(m,e)){let t=m[e];a(`(`);let i=[o()];for(;r()===`,`;)n++,i.push(o());return a(`)`),i.length===1?e=>t(i[0](e)):e=>t(...i.map(t=>t(e)))}return i()};try{let e=o();return n===t.length?e:null}catch{return null}}const g={k:`id`};function _(e,t){let{keys:n,vals:r}=e,i=n.length;if(i===0)return t;if(t<=n[0])return r[0];if(t>=n[i-1])return r[i-1];let a=0,o=i-1;for(;o-a>1;){let e=a+o>>1;n[e]<=t?a=e:o=e}return e.interp?r[a]+(r[o]-r[a])*(t-n[a])/(n[o]-n[a]):t-n[a]<=n[o]-t?r[a]:r[o]}function v(e,t){let n=t.length;switch(e.k){case`lin`:{let{a:r,b:i}=e;if(r===1&&i===0)return;for(let e=0;e<n;e++)t[e]=r*t[e]+i;return}case`rat`:{let[r,i,a,o,s,c]=e.p;for(let e=0;e<n;e++){let n=t[e];t[e]=(r*n*n+i*n+a)/(o*n*n+s*n+c)}return}case`poly`:{let[r,i,a,o,s,c]=e.p;for(let e=0;e<n;e++){let n=t[e]-s-c;t[e]=(i-o*n)/(a*n-r)}return}case`alg`:{let r=e.f;for(let e=0;e<n;e++)t[e]=r(t[e]);return}case`tab`:for(let r=0;r<n;r++)t[r]=_(e,t[r]);return;case`rtv`:for(let r=0;r<n;r++){let n=t[r],i=e.def;for(let t=0;t<e.lo.length;t++)if(n>=e.lo[t]&&n<=e.hi[t]){i=e.vals[t];break}t[r]=i}return;default:return}}function y(e,t){let n=Float64Array.of(t);return v(e,n),n[0]}const b=(e,t)=>e===null||typeof e==`string`?e:String(y(e,t));function x(e,t){let n=Array(t.length),r=e.ranges.every(e=>e.lo===e.hi)?new Map(e.ranges.map(e=>[e.lo,e.to])):null;for(let i=0;i<t.length;i++){let a=t[i];if(a!==a){n[i]=null;continue}let o=e.def;if(r){let e=r.get(a);e!==void 0&&(o=e)}else for(let t of e.ranges)if(a>=t.lo&&(e.int||t.lo===t.hi?a<=t.hi:a<t.hi)){o=t.to;break}n[i]=b(o,a)}return n}function S(e,t){let n=(e,t)=>({type:e,bigEndian:t,encoding:`latin1`});switch(e){case 0:return n(`uint`,!t);case 1:return n(`int`,!t);case 2:case 3:return n(`float`,!t);case 7:return n(`string`,!1);case 8:return n(`bytes`,!1);case 9:return n(`uint`,!0);case 10:return n(`int`,!0);case 11:case 12:return n(`float`,!0);case 13:return n(`uint`,!1);case 14:return n(`int`,!1);case 15:case 16:return n(`float`,!1);default:return null}}async function C(e,t,n){let r=i(t).getUint16(24,!0)===0,a=()=>Error(`This MDF file is damaged (a block is cut short or lies outside the file).`),o=async(t,n=4)=>{let o=await e.read(t,4);if(o.length<4)throw a();let s=i(o).getUint16(2,r),c=await e.read(t,s);if(s<n||c.length<s)throw a();return{id:u(c.subarray(0,2)),v:i(c),b:c,size:s}},s=(e,t)=>e.getUint32(t,r),c=(e,t)=>e.getUint16(t,r),d=(e,t)=>e.getFloat64(t,r),f=async e=>e?l((await o(e)).b.subarray(4),!0):``,p=[],m=new Set,_=e=>{if(m.has(e))throw Error(`This MDF file is damaged (its blocks link in a loop).`);m.add(e)},v=async(e,t)=>{if(!e)return{conv:g,unit:``};let{v:n,b:r}=await o(e,46),i=l(r.subarray(22,42),!0),u=c(n,42),p=c(n,44);if(46+(u===0?16:u===1||u===2?16*p:u===6||u===9?48:u===11?40*p:u===12?20*p:0)>r.length)throw a();let m=e=>d(n,46+8*e);switch(u){case 0:return{conv:{k:`lin`,a:m(1),b:m(0)},unit:i};case 1:case 2:{let e=new Float64Array(p),t=new Float64Array(p);for(let n=0;n<p;n++)e[n]=m(2*n),t[n]=m(2*n+1);return{conv:{k:`tab`,keys:e,vals:t,interp:u===1},unit:i}}case 6:return{conv:{k:`poly`,p:[0,1,2,3,4,5].map(m)},unit:i};case 9:return{conv:{k:`rat`,p:[0,1,2,3,4,5].map(m)},unit:i};case 10:{let e=l(r.subarray(46,302),!0),t=h(e);return{conv:t?{k:`alg`,f:t}:{k:`unsupported`,what:`the formula "${e}"`},unit:i}}case 11:return{conv:{k:`text`,ranges:Array.from({length:p},(e,t)=>{let i=46+40*t,a=d(n,i);return{lo:a,hi:a,to:l(r.subarray(i+8,i+40),!0)}}),def:null,int:t},unit:i};case 12:{let e=await Promise.all(Array.from({length:p},async(e,t)=>{let r=46+20*t;return{lo:d(n,r),hi:d(n,r+8),to:await f(s(n,r+16))}}));return{conv:{k:`text`,ranges:e.slice(1),def:e[0]?.to??null,int:t},unit:i}}case 65535:return{conv:g,unit:i};default:return{conv:{k:`unsupported`,what:`MDF3 conversion type ${u}`},unit:i}}},y=await o(64,8),b=null;if(y.size>=172&&(s(y.v,164)||s(y.v,168))){let e=s(y.v,168)*4294967296+s(y.v,164);b=new Date(e/1e6).toISOString()}else{let e=u(y.b.subarray(18,28)),t=u(y.b.subarray(28,36));/^\d\d:\d\d:\d{4}$/.test(e)&&(b=`${e.slice(6)}-${e.slice(3,5)}-${e.slice(0,2)}T${t}`)}let x=[],C=0;for(let e=s(y.v,4),t=0;e;t++){_(e);let n=await o(e,24),i=c(n.v,22),a=[];for(let e=s(n.v,8);e;){_(e);let n=await o(e,26),u=[],d=null;for(let e=s(n.v,8);e;){_(e);let t=await o(e,192),n=l(t.b.subarray(26,58),!0),i=(t.size>=222?await f(s(t.v,218)):``)||n,a=S(c(t.v,190),r),m=c(t.v,186)+(t.size>=228?8*c(t.v,226):0);if(!a)p.push(`${i}: MDF3 data type ${c(t.v,190)} is not supported; skipped.`);else{let{conv:e,unit:n}=await v(s(t.v,8),a.type!==`float`),r={name:i,unit:n,kind:c(t.v,24)===1?`master`:`value`,...a,conv:e,sd:null,sdRecordId:null,byteOffset:m>>3,bitOffset:m&7,bitCount:c(t.v,188),invalBit:null,allInvalid:!1};r.kind===`master`&&!d?d=r:r.kind===`value`&&u.push(r)}e=s(t.v,4)}C++,a.push({name:await f(s(n.v,12))||`Group ${C}`,dg:t,recordId:c(n.v,16),recordIdSize:+(i>0),idTrailer:+(i===2),dataBytes:c(n.v,20),invalBytes:0,cycles:s(n.v,22),vlsdCg:!1,sorted:!0,master:d,channels:u,stream:[],busType:0,busEvent:!1}),e=s(n.v,4)}let u=a.reduce((e,t)=>e+t.cycles*(t.recordIdSize+t.dataBytes+t.idTrailer),0),d=[{offset:s(n.v,16),length:u,zip:null}];for(let e of a)e.stream=d,e.sorted=a.length===1,x.push(e);e=s(n.v,4)}return{version:`MDF ${n}`,startTime:b,groups:x,notes:p,meta:{}}}const w=e=>e*1032+1024,T=128e6,E=1e3,D=(e,t)=>e.length>t?`${e.slice(0,t-1)}…`:e;function O(e){let t=e.notes;for(let n of e.groups){n.name=D(String(n.name),256);for(let e of n.channels)e.name=D(String(e.name),256),e.unit=D(String(e.unit??``),64);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>100&&t.splice(100,t.length-100,`${t.length-100} more notes.`),e.notes=t.map(e=>D(String(e),E));let n={};for(let[t,r]of Object.entries(e.meta).slice(0,200))n[D(t,256)]=D(String(r),E);return e.meta=n,e.events=e.events.filter(e=>Number.isFinite(e.time)).map(e=>({time:e.time,text:D(String(e.text),E)})),e}function k(e){return e instanceof Error&&(e.constructor===Error||e.name===`KymoscopeError`||e.name===`AbortError`)?e:Error(`This file couldn't be read (it may be damaged).`)}function A(e,t){if(e.seen.has(t))throw Error(`This MF4 is damaged (its blocks link in a loop).`);e.seen.add(t)}async function j(e,t){let n=await e.read(t,24);if(n.length<24)throw Error(`This MF4 is damaged (bad block at byte ${t}).`);let r=i(n),o=u(n.subarray(0,4)),s=a(r,8),c=a(r,16);if(!o.startsWith(`##`)||s<24+8*c||s>1<<26)throw Error(`This MF4 is damaged (bad block at byte ${t}).`);let l=await e.read(t,s);if(l.length<s)throw Error(`This MF4 is damaged (the block at byte ${t} runs past the end of the file).`);let d=i(l),f=[];for(let e=0;e<c;e++)f.push(a(d,24+8*e));let p=l.subarray(24+8*c);return{id:o,links:f,data:i(p),bytes:p}}const M={lt:`<`,gt:`>`,amp:`&`,quot:`"`,apos:`'`};function N(e){let t=e.indexOf(`<TX>`),n=t<0?-1:e.indexOf(`</TX>`,t+4);return(n>=0?e.slice(t+4,n):e.replace(/<[^<>]*>/g,``)).replace(/&(lt|gt|amp|quot|apos);/g,(e,t)=>M[t]).trim()}function ee(e,t){if(!t)return Promise.resolve(``);let n=e.texts.get(t);return n||(n=j(e.io,t).then(e=>{let t=l(e.bytes);return e.id===`##MD`?N(t):t}),e.texts.set(t,n)),n}async function P(e,t,n=0){if(!t)return[];let r=e.io,o=await r.read(t,24),s=u(o.subarray(0,4)),c=o.length<24?0:a(i(o),8);switch(s){case`##DT`:case`##SD`:case`##RD`:return[{offset:t+24,length:c-24,zip:null}];case`##DZ`:{let e=i(await r.read(t+24,24));if(e.byteLength<24)throw Error(`This MF4 is damaged (bad block at byte ${t}).`);let n=e.getUint8(2);if(n===2||n===3)throw Error(`This MF4 uses zstd compression, which isn't supported yet.`);if(n===4||n===5)throw Error(`This MF4 uses LZ4 compression, which isn't supported yet.`);if(n>5)throw Error(`This MF4 is damaged (unknown compression type ${n}).`);let o=e.getUint32(4,!0),s=a(e,8),c=a(e,16);if(s>w(c)||n===1&&o===0)throw Error(`This MF4 is damaged (bad compressed block at byte ${t}).`);if(n===1&&s>268435456)throw Error(`This MF4 has a compressed block over 256 MB, which Kymoscope cannot read.`);return[{offset:t+48,length:c,zip:{type:n,param:o,orgLength:s}}]}case`##DL`:{if(n>1)throw Error(`This MF4 is damaged (unexpected ${s} block in its data).`);let i=[];for(let n=t;n;){A(e,n);let t=await j(r,n);for(let n of t.links.slice(1))i.push(...await P(e,n,2));n=t.links[0]}return i}case`##HL`:if(n>0)throw Error(`This MF4 is damaged (unexpected ${s} block in its data).`);return A(e,t),P(e,(await j(r,t)).links[0],1);case`##DV`:case`##DI`:throw Error(`This MF4 uses column-oriented storage (MDF 4.2 DV/DI blocks), which Kymoscope cannot read yet.`);default:throw Error(`This MF4 is damaged (unexpected ${s} block in its data).`)}}async function te(e,t,n){return t?u(await e.io.read(t,4))===`##CC`?ne(e,t,n+1):ee(e,t):null}async function ne(e,t,n=0){if(!t||n>4||e.busy.has(t))return g;let r=e.convs.get(t);if(r)return r;e.busy.add(t);try{let r=await re(e,t,n);return e.convs.set(t,r),r}finally{e.busy.delete(t)}}async function re(e,t,n){let r=await j(e.io,t),i=r.data,a=i.getUint8(0),o=i.getUint16(4,!0),s=i.getUint16(6,!0),c=new Float64Array(s);for(let e=0;e<s;e++)c[e]=i.getFloat64(24+8*e,!0);let l=r.links.slice(4,4+o),u=()=>Promise.all(l.map(t=>te(e,t,n)));switch(a){case 0:return g;case 1:return{k:`lin`,b:c[0],a:c[1]};case 2:return{k:`rat`,p:[...c]};case 3:{let t=await ee(e,l[0]),n=h(t);return n?{k:`alg`,f:n}:{k:`unsupported`,what:`the formula "${t}"`}}case 4:case 5:{let e=s>>1,t=new Float64Array(e),n=new Float64Array(e);for(let r=0;r<e;r++)t[r]=c[2*r],n[r]=c[2*r+1];return{k:`tab`,keys:t,vals:n,interp:a===4}}case 6:{let e=Math.max(0,Math.floor((s-1)/3)),t=new Float64Array(e),n=new Float64Array(e),r=new Float64Array(e);for(let i=0;i<e;i++)t[i]=c[3*i],n[i]=c[3*i+1],r[i]=c[3*i+2];return{k:`rtv`,lo:t,hi:n,vals:r,def:c[s-1]}}case 7:{let e=await u();return{k:`text`,ranges:[...c].map((t,n)=>({lo:t,hi:t,to:e[n]??null})),def:e[s]??null,int:!0}}case 8:{let e=await u(),t=s>>1;return{k:`text`,ranges:Array.from({length:t},(t,n)=>({lo:c[2*n],hi:c[2*n+1],to:e[n]??null})),def:e[t]??null,int:!0}}default:return{k:`unsupported`,what:`conversion type ${a}`}}}const ie={0:{type:`uint`,bigEndian:!1,encoding:`latin1`},1:{type:`uint`,bigEndian:!0,encoding:`latin1`},2:{type:`int`,bigEndian:!1,encoding:`latin1`},3:{type:`int`,bigEndian:!0,encoding:`latin1`},4:{type:`float`,bigEndian:!1,encoding:`latin1`},5:{type:`float`,bigEndian:!0,encoding:`latin1`},6:{type:`string`,bigEndian:!1,encoding:`latin1`},7:{type:`string`,bigEndian:!1,encoding:`utf-8`},8:{type:`string`,bigEndian:!1,encoding:`utf-16le`},9:{type:`string`,bigEndian:!0,encoding:`utf-16be`},10:{type:`bytes`,bigEndian:!1,encoding:`latin1`}};async function ae(e,t){let{io:n,notes:r}=e,i=t.data,o=i.getUint8(0),s=i.getUint8(1),c=i.getUint8(2),l=await ee(e,t.links[2]),d=ie[c];if(!d)return r.push(`${l}: data type ${c} is not supported; the channel was skipped.`),null;let f;if(o===2||o===3)if(s===1)f=o===2?`master`:`vmaster`;else{if(r.push(`The master channel ${l} is not time (sync type ${s}): samples are numbered instead.`),o===3)return null;f=`value`}else if(o===1)f=`vlsd`;else if(o===0||o===4)f=`value`;else return r.push(`${l}: channel type ${o} is not supported; skipped.`),null;let p=await ne(e,t.links[4]),m=p.k===`text`?{...p,int:d.type!==`float`}:p,h=await ee(e,t.links[6]);!h&&t.links[4]&&(h=await ee(e,(await j(n,t.links[4])).links[1]));let g=null,_=null;f===`vlsd`&&t.links[5]&&(u(await n.read(t.links[5],4))===`##CG`?_=a((await j(n,t.links[5])).data,0):g=await P(e,t.links[5]));let v=i.getUint32(12,!0);return{name:l,unit:h,kind:f,...d,conv:m,sd:g,sdRecordId:_,byteOffset:i.getUint32(4,!0),bitOffset:i.getUint8(3),bitCount:i.getUint32(8,!0),invalBit:v&2?i.getUint32(16,!0):null,allInvalid:(v&1)!=0}}async function oe(e,t,n,r=0){let{io:i,notes:a}=e;for(let o=t;o;){A(e,o);let t=await j(i,o),s=t.links[1];s&&r<4&&(u(await i.read(s,4))===`##CN`?await oe(e,s,n,r+1):a.push(`${await ee(e,t.links[2])}: array channels (CA) are not supported yet; skipped.`));let c=await ae(e,t);c&&n.push(c),o=t.links[0]}}async function se(e,t,n,r){let i=t.data,o=i.getUint16(16,!0),s=0;t.links[3]&&(s=(await j(e.io,t.links[3])).data.getUint8(1));let c={name:await ee(e,t.links[2]),dg:n,recordId:a(i,0),recordIdSize:r,idTrailer:0,dataBytes:i.getUint32(24,!0),invalBytes:i.getUint32(28,!0),cycles:a(i,8),vlsdCg:(o&1)!=0,sorted:!0,master:null,channels:[],stream:[],busType:s,busEvent:(o&2)!=0};if(c.vlsdCg)return c;let l=[];await oe(e,t.links[1],l);for(let e of l)e.kind===`master`||e.kind===`vmaster`?c.master||=e:c.channels.push(e);return c}async function ce(e,t){let n=await j(e,64);if(n.id!==`##HD`)throw Error(`This MF4 is damaged (no header block).`);let r=a(n.data,0),i=(n.data.getUint8(12)&1)!=0,o=new Date(r/1e6).toISOString(),s=r>0?i?o.slice(0,-1):o:null,c={io:e,notes:[],seen:new Set,texts:new Map,convs:new Map,busy:new Set},l=[],u=0;for(let t=n.links[0],r=0;t;r++){A(c,t);let n=await j(e,t),i=n.data.getUint8(0),a=[];for(let t=n.links[1];t;){A(c,t);let n=await j(e,t),o=await se(c,n,r,i);o.vlsdCg||(u++,o.name||=`Group ${u}`),a.push(o),t=n.links[0]}let o=await P(c,n.links[2]),s=a.length===1;for(let e of a)e.stream=o,e.sorted=s,l.push(e);t=n.links[0]}return{version:`MF4 ${t}`,startTime:s,groups:l,notes:c.notes,meta:{}}}function le(e){let t=e&32768?-1:1,n=e>>10&31,r=e&1023;return n===0?t*2**-14*(r/1024):n===31?r?NaN:t*(1/0):t*2**(n-15)*(1+r/1024)}function ue(e,t,n,r,a,o,s=0){let c=i(t),l=!e.bigEndian,u=a+e.byteOffset,d=e.bitCount;if(e.bitOffset===0)if(e.type===`float`){if(d===64){for(let e=0;e<n;e++,u+=r)o[s+e]=c.getFloat64(u,l);return}if(d===32){for(let e=0;e<n;e++,u+=r)o[s+e]=c.getFloat32(u,l);return}if(d===16){for(let e=0;e<n;e++,u+=r)o[s+e]=le(c.getUint16(u,l));return}}else if(e.type===`int`){if(d===8){for(let e=0;e<n;e++,u+=r)o[s+e]=c.getInt8(u);return}if(d===16){for(let e=0;e<n;e++,u+=r)o[s+e]=c.getInt16(u,l);return}if(d===32){for(let e=0;e<n;e++,u+=r)o[s+e]=c.getInt32(u,l);return}if(d===64){for(let e=0;e<n;e++,u+=r)o[s+e]=c.getInt32(u+(l?4:0),l)*4294967296+c.getUint32(u+(l?0:4),l);return}}else{if(d===8){for(let e=0;e<n;e++,u+=r)o[s+e]=t[u];return}if(d===16){for(let e=0;e<n;e++,u+=r)o[s+e]=c.getUint16(u,l);return}if(d===32){for(let e=0;e<n;e++,u+=r)o[s+e]=c.getUint32(u,l);return}if(d===64){for(let e=0;e<n;e++,u+=r)o[s+e]=c.getUint32(u+(l?4:0),l)*4294967296+c.getUint32(u+(l?0:4),l);return}}let f=e.bitOffset+d+7>>3,p=2**e.bitOffset,m=2**d,h=m/2,g=e.type===`int`;for(let e=0;e<n;e++,u+=r){let n=0;if(l)for(let e=f-1;e>=0;e--)n=n*256+t[u+e];else for(let e=0;e<f;e++)n=n*256+t[u+e];n=Math.floor(n/p)%m,o[s+e]=g&&n>=h?n-m:n}}const de=new Map,fe=e=>{let t=de.get(e);return t||de.set(e,t=new TextDecoder(e)),t};function pe(e){let t=e.indexOf(`\0`);return t<0?e:e.slice(0,t)}function me(e,t,n,r,i){let a=fe(e.encoding),o=e.bitCount>>3,s=Array(n);for(let c=0,l=i+e.byteOffset;c<n;c++,l+=r)s[c]=pe(a.decode(t.subarray(l,l+o)));return s}function he(e,t,n,r,i,a){let o=a instanceof Float64Array?NaN:null;if(e.allInvalid){for(let e=0;e<n;e++)a[e]=o;return}if(e.invalBit===null)return;let s=1<<(e.invalBit&7);for(let c=0,l=i+(e.invalBit>>3);c<n;c++,l+=r)t[l]&s&&(a[c]=o)}const ge={id:`mdf`,label:`ASAM MDF (MF4, MDF 3)`,extensions:[`.mf4`,`.mdf`,`.mf3`,`.dat`],companions:[{ext:`.dbc`,anyName:!0}],sniff:e=>f(e,`MDF `)||f(e,`UnFinMF `)},_e=e=>e.recordIdSize+e.dataBytes+e.invalBytes+e.idTrailer,ve=(e,t)=>e.reduce((e,n)=>e+(n.zip?n.zip.orgLength:Math.max(0,Math.min(n.length,t-n.offset))),0),ye=e=>e.byteOffset+Math.ceil((e.bitOffset+e.bitCount)/8);function be(e,t){return e.kind===`vmaster`?!0:(e.kind===`vlsd`||e.type===`uint`||e.type===`int`||e.type===`float`?!(e.bitCount>=1&&e.bitCount<=64):!(e.bitCount>=8))?!1:ye(e)<=t.dataBytes}function xe(e,t){let n=e.notes;for(let r of e.groups){if(![0,1,2,4,8].includes(r.recordIdSize))throw Error(`This MDF file is damaged (bad record id size).`);if(r.vlsdCg)continue;let e=_e(r);if(e>67108864||e===0){r.cycles>0&&n.push(`${r.name||`A group`}: its records are ${e===0?`empty`:`too large`} (damaged); skipped.`),r.cycles=0;continue}r.cycles=Math.min(r.cycles,Math.floor(ve(r.stream,t)/e));let i=r.channels.filter(e=>!be(e,r));for(let e of i)n.push(`${e.name}: its bits lie outside its record (damaged); skipped.`);i.length&&(r.channels=r.channels.filter(e=>!i.includes(e))),r.master&&!be(r.master,r)&&(n.push(`${r.master.name}: the time channel lies outside its record (damaged): samples are numbered instead.`),r.master=null);for(let e of r.master?[...r.channels,r.master]:r.channels)e.invalBit!==null&&e.invalBit>=8*r.invalBytes&&(e.invalBit=null)}}function Se(e,t){let n=0;for(let r of e.master?[...t,e.master]:t){if(r.invalBit!==null)return 1/0;r.kind!==`vmaster`&&(n=Math.max(n,r.byteOffset+(r.bitOffset+r.bitCount+7>>3)))}return e.recordIdSize+n}var Ce=Uint8Array,we=Uint16Array,Te=Int32Array,Ee=new Ce([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]),De=new Ce([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]),Oe=new Ce([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),ke=function(e,t){for(var n=new we(31),r=0;r<31;++r)n[r]=t+=1<<e[r-1];for(var i=new Te(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}},Ae=ke(Ee,2),je=Ae.b,Me=Ae.r;je[28]=258,Me[258]=28;var Ne=ke(De,0),Pe=Ne.b;Ne.r;for(var Fe=new we(32768),F=0;F<32768;++F){var Ie=(F&43690)>>1|(F&21845)<<1;Ie=(Ie&52428)>>2|(Ie&13107)<<2,Ie=(Ie&61680)>>4|(Ie&3855)<<4,Fe[F]=((Ie&65280)>>8|(Ie&255)<<8)>>1}for(var Le=(function(e,t,n){for(var r=e.length,i=0,a=new we(t);i<r;++i)e[i]&&++a[e[i]-1];var o=new we(t);for(i=1;i<t;++i)o[i]=o[i-1]+a[i-1]<<1;var s;if(n){s=new we(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[Fe[d]>>c]=l}else for(s=new we(r),i=0;i<r;++i)e[i]&&(s[i]=Fe[o[e[i]-1]++]>>15-e[i]);return s}),Re=new Ce(288),F=0;F<144;++F)Re[F]=8;for(var F=144;F<256;++F)Re[F]=9;for(var F=256;F<280;++F)Re[F]=7;for(var F=280;F<288;++F)Re[F]=8;for(var ze=new Ce(32),F=0;F<32;++F)ze[F]=5;var Be=Le(Re,9,1),Ve=Le(ze,5,1),He=function(e){for(var t=e[0],n=1;n<e.length;++n)e[n]>t&&(t=e[n]);return t},Ue=function(e,t,n){var r=t/8|0;return(e[r]|e[r+1]<<8)>>(t&7)&n},We=function(e,t){var n=t/8|0;return(e[n]|e[n+1]<<8|e[n+2]<<16)>>(t&7)},Ge=function(e){return(e+7)/8|0},Ke=function(e,t,n){return(t==null||t<0)&&(t=0),(n==null||n>e.length)&&(n=e.length),new Ce(e.subarray(t,n))},qe=[`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`],Je=function(e,t,n){var r=Error(t||qe[e]);if(r.code=e,Error.captureStackTrace&&Error.captureStackTrace(r,Je),!n)throw r;return r},Ye=function(e,t,n,r){var i=e.length,a=r?r.length:0;if(!i||t.f&&!t.l)return n||new Ce(0);var o=!n,s=o||t.i!=2,c=t.i;o&&(n=new Ce(i*3));var l=function(e){var t=n.length;if(e>t){var r=new Ce(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=Ue(e,d,1);var v=Ue(e,d+1,3);if(d+=3,!v){var y=Ge(d)+4,b=e[y-4]|e[y-3]<<8,x=y+b;if(x>i){c&&Je(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=Be,m=Ve,h=9,g=5;else if(v==2){var S=Ue(e,d,31)+257,C=Ue(e,d+10,15)+4,w=S+Ue(e,d+5,31)+1;d+=14;for(var T=new Ce(w),E=new Ce(19),D=0;D<C;++D)E[Oe[D]]=Ue(e,d+D*3,7);d+=C*3;for(var O=He(E),k=(1<<O)-1,A=Le(E,O,1),D=0;D<w;){var j=A[Ue(e,d,k)];d+=j&15;var y=j>>4;if(y<16)T[D++]=y;else{var M=0,N=0;for(y==16?(N=3+Ue(e,d,3),d+=2,M=T[D-1]):y==17?(N=3+Ue(e,d,7),d+=3):y==18&&(N=11+Ue(e,d,127),d+=7);N--;)T[D++]=M}}var ee=T.subarray(0,S),P=T.subarray(S);h=He(ee),g=He(P),p=Le(ee,h,1),m=Le(P,g,1)}else Je(1);if(d>_){c&&Je(0);break}}s&&l(f+131072);for(var te=(1<<h)-1,ne=(1<<g)-1,re=d;;re=d){var M=p[We(e,d)&te],ie=M>>4;if(d+=M&15,d>_){c&&Je(0);break}if(M||Je(2),ie<256)n[f++]=ie;else if(ie==256){re=d,p=null;break}else{var ae=ie-254;if(ie>264){var D=ie-257,oe=Ee[D];ae=Ue(e,d,(1<<oe)-1)+je[D],d+=oe}var se=m[We(e,d)&ne],ce=se>>4;se||Je(3),d+=se&15;var P=Pe[ce];if(ce>3){var oe=De[ce];P+=We(e,d)&(1<<oe)-1,d+=oe}if(d>_){c&&Je(0);break}s&&l(f+131072);var le=f+ae;if(f<P){var ue=a-P,de=Math.min(P,le);for(ue+f<0&&Je(3);f<de;++f)n[f]=r[ue+f]}for(;f<le;++f)n[f]=n[f-P]}}t.l=p,t.p=re,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?Ke(n,0,f):n.subarray(0,f)},Xe=new Ce(0),Ze=function(e,t){return((e[0]&15)!=8||e[0]>>4>7||(e[0]<<8|e[1])%31)&&Je(6,`invalid zlib data`),(e[1]>>5&1)==+!t&&Je(6,`invalid zlib data: `+(e[1]&32?`need`:`unexpected`)+` dictionary`),(e[1]>>3&4)+2},Qe=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 Ce(32768),this.p=new Ce(0),n&&this.o.set(n)}return e.prototype.e=function(e){if(this.ondata||Je(5),this.d&&Je(4),!this.p.length)this.p=e;else if(e.length){var t=new Ce(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=Ye(this.p,this.s,this.o);this.ondata(Ke(n,t,this.s.b),this.d),this.o=Ke(n,this.s.b-32768),this.s.b=this.o.length,this.p=Ke(this.p,this.s.p/8|0),this.s.p&=7},e.prototype.push=function(e,t){this.e(e),this.c(t)},e}(),$e=function(){function e(e,t){Qe.call(this,e,t),this.v=e&&e.dictionary?2:1}return e.prototype.push=function(e,t){if(Qe.prototype.e.call(this,e),this.v){if(this.p.length<6&&!t)return;this.p=this.p.subarray(Ze(this.p,this.v-1)),this.v=0}t&&(this.p.length<4&&Je(6,`invalid zlib data`),this.p=this.p.subarray(0,-4)),Qe.prototype.c.call(this,t)},e}(),et=typeof TextDecoder<`u`&&new TextDecoder;try{et.decode(Xe,{stream:!0})}catch{}const tt=65536;async function*nt(e){for(let t=0;t<e.length;t+=tt)yield e.subarray(t,t+tt)}async function*rt(e){if(typeof DecompressionStream!=`function`){let t=[],n=new $e(e=>{t.push(e)});for await(let r of e)for(n.push(r,!1);t.length;)yield t.shift();for(n.push(new Uint8Array,!0);t.length;)yield t.shift();return}let t=new DecompressionStream(`deflate`),n=t.writable.getWriter();(async()=>{for await(let t of e)await n.write(t);await n.close()})().catch(e=>n.abort(e).catch(()=>{}));let r=t.readable.getReader();try{for(;;){let{done:e,value:t}=await r.read().catch(e=>{throw e instanceof TypeError?Error(`This file's compressed data is damaged.`):e});if(e)return;yield t}}finally{r.cancel().catch(()=>{})}}async function it(e,t=-1,n=1/0){let r=[],i=Math.min(t,n),a=t>=0?new Uint8Array(i):null,o=0;for await(let s of rt(nt(e))){if(a){if(o+s.length>t&&n>t)throw Error(`Compressed data is longer than its header says.`);a.set(o+s.length>i?s.subarray(0,i-o):s,o)}else r.push(s);if(o+=s.length,o>=n)break}if(a)return o>=i?a:a.subarray(0,o);let s=r.length===1?r[0]:new Uint8Array(o);return r.length>1&&r.reduce((e,t)=>(s.set(t,e),e+t.length),0),o>n?s.subarray(0,n):s}const at=new Uint8Array(Uint32Array.of(1).buffer)[0]===1;function ot(e,t,n,r=t){let i=Math.floor(n/t),a=new Uint8Array(r<t?i*r:n),o=r%4==0&&at?new Uint32Array(a.buffer,0,i*r>>2):null,s=r>>2;for(let t=0;t<i;t+=512){let n=Math.min(i,t+512);if(o)for(let a=0;a<r;a+=4){let r=a*i,c=r+i,l=c+i,u=l+i;for(let i=t,d=t*s+(a>>2);i<n;i++,d+=s)o[d]=e[r+i]|e[c+i]<<8|e[l+i]<<16|e[u+i]<<24}else for(let o=0;o<r;o++){let s=o*i;for(let i=t,c=t*r+o;i<n;i++,c+=r)a[c]=e[s+i]}}let c=i*t;return r===t&&a.set(e.subarray(c,n),c),a}function st(e,t,n){if(!(n<t)||e.length===0)return t;let r=Math.min(t,n+3&-4);return r===t?t:e.every(e=>e.zip?.type===1&&e.zip.param===t&&e.zip.orgLength%t===0)?r:t}async function ct(e,t,n=1/0,r=1/0){let i=await e.slice(t.offset,t.length),{type:a,param:o,orgLength:s}=t.zip;if(a===0)return it(i,s,r);let c=Math.min(n,o);return ot(await it(i,s,c<o?s/o*c:1/0),o,s,c)}async function*lt(e,t,n,r=1/0){let i=e=>!!e?.zip&&!(e.zip.type===0&&(e.length>16777216||e.zip.orgLength>268435456)),a=null;for(let o=0;o<t.length;o++){let s=t[o];if(n?.throwIfAborted(),!s.zip)for await(let t of e.windows(s.offset,s.length))yield t.bytes;else if(i(s)){let n=a??ct(e,s,r);a=i(t[o+1])?ct(e,t[o+1],r):null,a?.catch(()=>{}),yield await n}else{let t=s.zip.orgLength;for await(let n of rt((async function*(){for await(let t of e.windows(s.offset,s.length))yield t.bytes})()))if(yield n.length>t?n.subarray(0,t):n,(t-=n.length)<=0)break}}}async function*ut(e,t,n,r){if(r<=0||t<=0)return;let i=Math.min(n,r),a=null,o=0,s=0;for await(let n of e){let e=0;for(;e<n.length&&s<r;){if(o===0){let a=Math.min(i,r-s,Math.floor((n.length-e)/t));if(a>0){yield{buf:n.subarray(e,e+a*t),n:a},s+=a,e+=a*t;continue}}a??=new Uint8Array(t*i);let c=Math.min(a.length,(r-s)*t),l=Math.min(n.length-e,c-o);if(a.set(n.subarray(e,e+l),o),o+=l,e+=l,o===c){let e=o/t;yield{buf:a,n:e},s+=e,o=0}}if(s>=r)return}a&&o>=t&&(yield{buf:a,n:Math.floor(o/t)})}async function dt(e,t,n,r){let i=n*r,a=0;for(let n of t){let t=n.zip?n.zip.orgLength:n.length;if(i<a)return null;if(i+r<=a+t)return n.zip?null:e.read(n.offset+i-a,r);a+=t}return null}const ft=(e,t)=>(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0;var pt=class{#e;#t;#n;#r;#i=new Uint8Array;#a=0;#o;#s=0;constructor(e,t,n){this.#e=e,this.#t=t,this.#n=n,this.#r=lt(e,t,n),this.#o=t.reduce((e,t)=>e+(t.zip?t.zip.orgLength:t.length),0)}peek(e){let t=e-this.#a;if(t<0||t+4>this.#i.length)return null;let n=ft(this.#i,t);return t+4+n>this.#i.length?null:this.#i.subarray(t+4,t+4+n)}async get(e){for(;;){let t=this.peek(e);if(t)return t;let n=e-this.#a;if(e+4>this.#o||n>=0&&n+4<=this.#i.length&&e+4+ft(this.#i,n)>this.#o)throw Error(`This MF4 is damaged (string data ends early).`);e<this.#a&&(this.#r=lt(this.#e,this.#t,this.#n),this.#i=new Uint8Array,this.#a=0);let r=await this.#r.next();if(r.done)throw Error(`This MF4 is damaged (string data ends early).`);if((this.#s+=r.value.length)>4*this.#o+16777216)throw Error(`This MF4 is damaged (its string offsets jump back and forth).`);let i=Math.max(0,Math.min(e-this.#a,this.#i.length)),a=this.#i.subarray(i),o=new Uint8Array(a.length+r.value.length);o.set(a),o.set(r.value,a.length),this.#a+=i,this.#i=o}}};const mt=e=>Math.max(1,Math.min(65536,Math.floor((8<<20)/Math.max(1,e))));var ht=class{#e;#t;#n=new Map;#r=new Map;constructor(e,t){this.#e=e,this.#t=t}want(e){this.#r.has(e)||this.#r.set(e,new Map)}wanted(e){return this.#r.has(e)}put(e,t,n){this.#r.get(e).set(t,n)}async bytes(e,t){let n=Array(t.length);if(e.sdRecordId!==null){let r=this.#r.get(e.sdRecordId);for(let e=0;e<t.length;e++)n[e]=r?.get(t[e])??null,r?.delete(t[e]);return n}if(!e.sd)return n.fill(null);let r=this.#n.get(e);r||this.#n.set(e,r=new pt(this.#e,e.sd,this.#t));for(let e=0;e<t.length;e++)n[e]=r.peek(t[e])??await r.get(t[e]);return n}async strings(e,t){let n=fe(e.encoding);return(await this.bytes(e,t)).map(e=>e?pe(n.decode(e)):null)}};function gt(e,t,n,r,i=_e(e),a=new Float64Array(n)){let o=e.master;if(!o)return null;if(o.kind===`vmaster`)for(let e=0;e<n;e++)a[e]=r+e;else ue(o,t,n,i,e.recordIdSize,a);return v(o.conv,a),a}function _t(e,t,n){return n===1?e[t]:n===2?e[t]|e[t+1]<<8:n===4?(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0:((e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0)+4294967296*((e[t+4]|e[t+5]<<8|e[t+6]<<16|e[t+7]<<24)>>>0)}function vt(e,t){let n=new Uint8Array(e.length+t.length);return n.set(e),n.set(t,e.length),n}async function*yt(e,t,n,r,i,a=1/0){let o=t.groups[n[0]];if(o.sorted){let t=st(o.stream,_e(o),a),r=0;for await(let{buf:a,n:s}of ut(lt(e,o.stream,i,t),t,mt(t),o.cycles))yield{g:n[0],buf:a,n:s,start:r,size:t},r+=s;return}let s=t.groups.map((e,t)=>({g:e,k:t})).filter(({g:e})=>e.dg===o.dg),c=o.recordIdSize,l=new Map;for(let e of n){let n=t.groups[e],r=_e(n);l.set(n.recordId,{k:e,size:r,buf:new Uint8Array(r*Math.min(mt(r),Math.max(1,n.cycles))),fill:0,start:0})}let u=new Map(s.map(({g:e})=>[e.recordId,e.vlsdCg?-1:_e(e)])),d=new Map,f=new Uint8Array;for await(let t of lt(e,o.stream,i)){let e=f.length?vt(f,t):t,n=0;for(;!(n+c>e.length);){let t=_t(e,n,c),i=u.get(t);if(i===void 0)throw Error(`This MF4 is damaged (unknown record id ${t}).`);if(i<0){if(n+c+4>e.length)break;let i=(e[n+c]|e[n+c+1]<<8|e[n+c+2]<<16|e[n+c+3]<<24)>>>0;if(i>67108864)throw Error(`This MF4 is damaged (a string record of ${i} bytes).`);let a=n+c+4+i;if(a>e.length)break;let o=d.get(t)??0;r.wanted(t)&&r.put(t,o,e.slice(n+c+4,a)),d.set(t,o+4+i),n=a;continue}if(n+i>e.length)break;let a=l.get(t);if(a&&(a.buf.set(e.subarray(n,n+i),a.fill),a.fill+=i,a.fill===a.buf.length)){let e=a.fill/a.size;yield{g:a.k,buf:a.buf,n:e,start:a.start,size:a.size},a.start+=e,a.fill=0}n+=i}f=e.slice(n)}for(let e of l.values())e.fill&&(yield{g:e.k,buf:e.buf,n:e.fill/e.size,start:e.start,size:e.size})}const bt=(e,t)=>t?e+2147483648:e,xt=/^BO_\s+(\d+)\s+(\w+)\s*:\s*(\d+)/,St=/^SG_\s+(\w+)\s*(?:(M|m\d+M?)\s*)?:\s*(\d+)\|(\d+)@([01])([+-])\s*\(([^,)]*),([^)]*)\)\s*\[[^\]]*\]\s*"([^"]*)"/,Ct=/^VAL_\s+(\d+)\s+(\w+)\s+(.*);/,wt=/^SIG_VALTYPE_\s+(\d+)\s+(\w+)\s*:\s*([12])\s*;/,Tt=/^-?\d+(?:\.\d+)?$/;function Et(e){let t=e.split(`"`),n=new Map;for(let e=0;e+1<t.length;e+=2){let r=t[e].trim();Tt.test(r)&&n.set(Number(r),t[e+1])}return n}const Dt=(e,t)=>e<=511&&t>=1&&t<=64;function Ot(e){let t=new Map,n=new Map,r=new Map,i=(e,t)=>{let i=n.get(Number(e));return i?r.get(i)?.get(t):void 0},a=null;for(let o of e.split(/\r?\n/)){let e=o.trim(),s;if(s=xt.exec(e)){let e=Number(s[1]),r=e>=2147483648,i=r?e-2147483648:e;a={id:i,extended:r,name:s[2],size:Number(s[3]),signals:[]},t.set(bt(i,r),a),n.set(e,a)}else if((s=St.exec(e))&&a){let e=s[2],t=Number(s[3]),n=Number(s[4]);if(!Dt(t,n)||!s[7].trim()||!s[8].trim())continue;let i={name:s[1],start:t,length:n,littleEndian:s[5]===`1`,signed:s[6]===`-`,factor:Number(s[7]),offset:Number(s[8]),unit:s[9],mux:e?e===`M`?`switch`:parseInt(e.slice(1),10):null,float:0,values:null};a.signals.push(i);let o=r.get(a);o||r.set(a,o=new Map),o.has(i.name)||o.set(i.name,i)}else if(s=Ct.exec(e)){let e=i(s[1],s[2]);e&&(e.values=Et(s[3]))}else if(s=wt.exec(e)){let e=i(s[1],s[2]);e&&(e.float=s[3]===`1`?32:64)}else (e.startsWith(`BO_`)||e===``)&&e===``&&(a=null)}return t}function kt(e){if(e.float){let t=e.float/8,n=e.start>>3,r=e.littleEndian,i=new DataView(new ArrayBuffer(8));return(e,a)=>{for(let r=0;r<t;r++)i.setUint8(r,e[a+n+r]??0);return t===4?i.getFloat32(0,r):i.getFloat64(0,r)}}let t=e.length,n=2**t,r=n/2,i=e.signed;if(e.littleEndian){let a=e.start>>3,o=e.start&7;if(o+t<=32){let e=t===32?-1:(1<<t)-1;return(t,s)=>{let c=s+a,l=((t[c]|t[c+1]<<8|t[c+2]<<16|t[c+3]<<24)>>>o&e)>>>0;return i&&l>=r?l-n:l}}let s=o+t+7>>3,c=2**(t-(32-o)),l=2**(32-o);return(e,t)=>{let u=t+a,d=(e[u]|e[u+1]<<8|e[u+2]<<16|e[u+3]<<24)>>>o,f=0;for(let t=s-1;t>=4;t--)f=f*256+(e[u+t]??0);let p=d+f%c*l;return i&&p>=r?p-n:p}}let a=e.start>>3,o=e.start&7;if(7-o+t<=32){let e=32-(7-o)-t,s=t===32?-1:(1<<t)-1;return(t,o)=>{let c=o+a,l=((t[c]<<24|t[c+1]<<16|t[c+2]<<8|t[c+3])>>>e&s)>>>0;return i&&l>=r?l-n:l}}let s=(1<<o+1)-1,c=t-(o+1)>>3,l=t-(o+1)&7,u=2**l;return(e,t)=>{let o=(e[t+a]??0)&s,d=t+a+1;for(let t=0;t<c;t++)o=o*256+(e[d++]??0);return l>0&&(o=o*u+((e[d]??0)>>8-l)),i&&o>=r?o-n:o}}function At(e){let t=e.length,n=2**t,r=n/2,i=e.signed,a=t===32?-1:(1<<t)-1;if(!e.float&&e.littleEndian&&(e.start&7)+t<=32){let t=e.start>>3,o=e.start&7;return(e,s,c,l,u,d,f)=>{for(let p=0;p<l;p++){let l=s[c[p]]+t,m=((e[l]|e[l+1]<<8|e[l+2]<<16|e[l+3]<<24)>>>o&a)>>>0;u[p]=(i&&m>=r?m-n:m)*d+f}}}if(!e.float&&!e.littleEndian&&7-(e.start&7)+t<=32){let o=e.start>>3,s=32-(7-(e.start&7))-t;return(e,t,c,l,u,d,f)=>{for(let p=0;p<l;p++){let l=t[c[p]]+o,m=((e[l]<<24|e[l+1]<<16|e[l+2]<<8|e[l+3])>>>s&a)>>>0;u[p]=(i&&m>=r?m-n:m)*d+f}}}let o=kt(e);return(e,t,n,r,i,a,s)=>{for(let c=0;c<r;c++)i[c]=o(e,t[n[c]])*a+s}}function jt(e){if(!e.busEvent||e.busType!==2)return null;let t=t=>e.channels.find(e=>e.name.endsWith(t))??null,n=t(`DataFrame.ID`),r=t(`DataFrame.DataBytes`);return!n||!r?null:{id:n,ide:t(`DataFrame.IDE`),data:r}}const Mt=()=>({n:0,time:new Float64Array,key:new Float64Array,id:new Float64Array,ide:new Float64Array,bytes:null,buf:new Uint8Array,dataAt:new Int32Array});async function Nt(e,t,n,r,i,a,o,s){s.key.length<r&&Object.assign(s,{time:new Float64Array(r),key:new Float64Array(r),id:new Float64Array(r),ide:new Float64Array(r),dataAt:new Int32Array(r)});let c=e.recordIdSize,{id:l,ide:u,key:d,dataAt:f}=s;ue(t.id,n,r,a,c,l),t.ide&&ue(t.ide,n,r,a,c,u);for(let e=0;e<r;e++){let n=l[e],r=n&536870911;d[e]=bt(r,t.ide?u[e]!==0:n>=2147483648||r>2047)}if(s.bytes=null,t.data.kind===`vlsd`){let e=new Float64Array(r);ue({...t.data,type:`uint`},n,r,a,c,e),s.bytes=await o.bytes(t.data,e)}else for(let e=0,n=c+t.data.byteOffset;e<r;e++,n+=a)f[e]=n;if(!gt(e,n,r,i,a,s.time.subarray(0,r)))for(let e=0;e<r;e++)s.time[e]=i+e;return s.n=r,s.buf=n,s}const Pt=new Uint8Array;function Ft(e){return e.float?(e.start>>3)+e.float/8:e.littleEndian?(e.start>>3)+((e.start&7)+e.length+7>>3):(e.start>>3)+1+(Math.max(0,e.length-((e.start&7)+1))+7>>3)}function It(e,t,n){let r=0;for(let e of n.values())for(let t of e.signals)r=Math.max(r,Ft(t));let i=t.data.kind===`vlsd`?t.data:{...t.data,bitCount:Math.min(t.data.bitCount,r*8)};return Se(e,t.ide?[t.id,t.ide,i]:[t.id,i])}function Lt(e,t){let n=t.map(t=>e.signals[e.channels[t].s]);return{route:e,col:n.map(At),read:n.map(kt),factor:n.map(e=>e.factor),offset:n.map(e=>e.offset),table:t.map((t,r)=>e.channels[t].text?n[r].values:null),idx:new Int32Array,cnt:0,n:0,t0:NaN,t1:NaN}}function Rt(e,t,n,r,i,a=1,o=0){let s=new Float64Array(i);if(n.bytes)for(let e=0;e<i;e++)s[e]=t(n.bytes[r[e]]??Pt,0)*a+o;else e(n.buf,n.dataAt,r,i,s,a,o);return s}function zt(e,t){let{idx:n,cnt:r}=e,i=new Float64Array(r);for(let e=0;e<r;e++)i[e]=t.time[n[e]];return e.n===0&&(e.t0=i[0]),e.t1=i[r-1],e.n+=r,e.cnt=0,{time:i,cols:e.col.map((i,a)=>{let o=e.table[a];return o?Array.from(Rt(i,e.read[a],t,n,r),e=>o.get(e)??null):Rt(i,e.read[a],t,n,r,e.factor[a],e.offset[a])})}}const Bt=e=>({key:e,skip:!0,frames:0,all:null,sw:null,byMux:new Map,idx:new Int32Array,cnt:0});function Vt(e,t){let n=e.signals.find(e=>e.mux===`switch`);return{key:bt(e.id,e.extended),skip:!1,frames:0,all:t,sw:n?{col:At(n),read:kt(n)}:null,byMux:new Map,idx:new Int32Array,cnt:0}}var Ht=class{#e=Array(2048);#t=new Map;#n;constructor(e){this.#n=e}get(e){let t=e<2048?this.#e[e]:this.#t.get(e);return t||(t=this.#n(e),e<2048?this.#e[e]=t:this.#t.set(e,t)),t}};function Ut(e,t,n){let r=[];for(let n=0;n<e.n;n++){let i=t.get(e.key[n]);if(i.skip){i.frames++;continue}i.cnt===0&&(r.push(i),i.idx.length<e.n&&(i.idx=new Int32Array(e.n))),i.idx[i.cnt++]=n}let i=[];for(let t of r){if(t.all&&(t.all.idx=t.idx,t.all.cnt=t.cnt,i.push(t.all)),t.sw){let r=Rt(t.sw.col,t.sw.read,e,t.idx,t.cnt);for(let e=0;e<t.cnt;e++){let a=t.byMux.get(r[e]);a===void 0&&((a=n(t,r[e]))||t.byMux.size<4096)&&t.byMux.set(r[e],a),a&&(a.cnt===0&&(i.push(a),a.idx.length<t.cnt&&(a.idx=new Int32Array(t.cnt))),a.idx[a.cnt++]=t.idx[e])}}t.cnt=0}return i}async function Wt(e,t,n,r){let i=new Map;if(t.groups.forEach((e,t)=>{let n=jt(e);n&&e.cycles>0&&i.set(t,n)}),i.size===0)return null;if(n.length===0)return{dbc:new Map,layouts:i,routes:[],notes:[],cache:new Map};let a=Ot(d(new Uint8Array(await n[0].arrayBuffer()))),o=[],s=new Map,c=new Map,l=0,u=new ht(e,r);for(let[n,d]of i){let i=t.groups[n],f=(e,t)=>{let n=e.signals.filter(e=>t===null?typeof e.mux!=`number`:e.mux===t),r=[];return n.forEach((e,t)=>{r.push({s:t,text:!1}),e.values&&r.push({s:t,text:!0})}),Lt({key:bt(e.id,e.extended),mux:t,signals:n,channels:r},r.map((e,t)=>t))},p=new Ht(e=>{let t=a.get(e);if(!t){let t=Bt(e);return s.set(e,t),t}let r=Vt(t,f(t,null));return o.push({model:n,m:r}),r});d.data.sdRecordId!==null&&u.want(d.data.sdRecordId);let m=Mt();for await(let o of yt(e,t,[n],u,r,It(i,d,a))){let e=await Nt(i,d,o.buf,o.n,o.start,o.size,u,m),t=(e,t)=>{let n=a.get(e.key);return n.signals.some(e=>e.mux===t)?f(n,t):null};for(let n of Ut(e,p,t)){let t=zt(n,e);if(l<0)continue;if((l+=t.time.length*(1+t.cols.length))>48e6){l=-1,c.clear();continue}let r=c.get(n);r||c.set(n,r=[]),r.push(t)}}}let f=[],p=new Map;for(let{model:e,m:t}of o)for(let n of[t.all,...t.byMux.values()]){if(!n)continue;let{route:t,n:r,t0:i,t1:o}=n;if(t.signals.length===0)continue;let s=a.get(t.key);l>=0&&p.set(t,c.get(n)??[]),f.push({model:e,route:t,group:{name:t.mux===null?s.name:`${s.name} [m=${t.mux}]`,channels:t.channels.map(e=>({name:e.text?`${t.signals[e.s].name} (text)`:t.signals[e.s].name,unit:e.text?``:t.signals[e.s].unit,text:e.text})),samples:r,time:{kind:`timestamps`},rateHz:r>1&&o>i?Math.round((r-1)/(o-i)*1e6)/1e6:null}})}let m=[];if(s.size){let e=[...s.values()].reduce((e,t)=>e+t.frames,0),t=[...s.keys()].map(e=>`0x${(e%2147483648).toString(16).toUpperCase()}`).join(`, `);m.push(`${e} frame${e===1?``:`s`} with ${s.size} id${s.size===1?``:`s`} not in the DBC ${e===1?`was`:`were`} skipped (${t}).`)}return{dbc:a,layouts:i,routes:f,notes:m,cache:p}}async function*Gt(e,t,n,r,i,a){let o=[];for(let e of i){let t=r.cache.get(e.route);if(!t){o.push(e);continue}r.cache.delete(e.route);let n=0;for(let r of t)yield{group:e.group,start:n,length:r.time.length,time:r.time,columns:e.sel.map(e=>r.cols[e])},n+=r.time.length}if(!o.length)return;let s=r.layouts.get(n),c=t.groups[n],l=new Map,u=new Map;for(let e of o){let t=Lt(e.route,e.sel);l.set(t,e.group);let n=u.get(e.route.key);n||u.set(e.route.key,n={all:null,byMux:new Map}),e.route.mux===null?n.all=t:n.byMux.set(e.route.mux,t)}let d=new Ht(e=>{let t=u.get(e);if(!t)return Bt(e);let n=Vt(r.dbc.get(e),t.all);return t.byMux.size||(n.sw=null),n}),f=new ht(e,a);s.data.sdRecordId!==null&&f.want(s.data.sdRecordId);let p=Mt();for await(let i of yt(e,t,[n],f,a,It(c,s,r.dbc))){let e=await Nt(c,s,i.buf,i.n,i.start,i.size,f,p);for(let t of Ut(e,d,(e,t)=>u.get(e.key).byMux.get(t)??null)){let n=t.n,r=zt(t,e);yield{group:l.get(t),start:n,length:r.time.length,time:r.time,columns:r.cols}}}}const Kt=e=>Math.round(e*1e6)/1e6,qt=e=>e.kind===`value`?e.type!==`bytes`:e.kind===`vlsd`&&e.type===`string`,Jt=e=>({name:e.name,unit:e.unit,text:e.type===`string`||e.kind===`vlsd`||e.conv.k===`text`});async function Yt(e,t){let n=t.master;if(!n||t.cycles<2)return null;if(n.kind===`vmaster`)return n.conv.k===`lin`&&n.conv.a>0?Kt(1/n.conv.a):null;if(!t.sorted)return null;let r=_e(t),i=t.cycles,a,o;if(t.stream[0]?.zip){let n=st(t.stream.slice(0,1),r,Se(t,[])),s=await ct(e,t.stream[0],n,4096*r);if(i=Math.min(t.cycles,Math.floor(s.length/n)),i<2)return null;a=s.subarray(0,n),o=s.subarray((i-1)*n,i*n)}else a=await dt(e,t.stream,0,r),o=await dt(e,t.stream,t.cycles-1,r);if(!a||!o)return null;let s=new Float64Array(2);return ue(n,a,1,r,t.recordIdSize,s,0),ue(n,o,1,r,t.recordIdSize,s,1),v(n.conv,s),s[1]>s[0]?Kt((i-1)/(s[1]-s[0])):null}async function Xt(e,t,n,r,i,a,o){let s;if(e.kind===`vlsd`){let a=new Float64Array(n);ue({...e,type:`uint`},t,n,r,i,a),s=await o.strings(e,a)}else if(e.type===`string`)s=me(e,t,n,r,i);else{let a=new Float64Array(n);ue(e,t,n,r,i,a),e.conv.k===`text`?s=x(e.conv,a):(v(e.conv,a),s=a)}return he(e,t,n,r,a,s),s}async function Zt(e,t,n,r,i,a,o,s){let c=e.recordIdSize,l=[];for(let i of t)l.push(await Xt(e.channels[i],n,r,a,c,c+e.dataBytes,s));return{group:o,time:gt(e,n,r,i,a),start:i,length:r,columns:l}}async function*Qt(e,t){let n=e.plan.state,r=t.filter(e=>n.groups[e].route),i=t.filter(e=>!n.groups[e].route);if(r.length){let t=r.map(t=>({group:t,route:n.groups[t].route,sel:p(e,t)}));yield*Gt(e.io,n.model,n.groups[r[0]].model,n.bus,t,e.signal)}if(!i.length)return;let a=new ht(e.io,e.signal),o=new Map;for(let t of i){let r=n.groups[t],i=p(e,t).map(e=>r.channels[e]);for(let e of i){let t=n.model.groups[r.model].channels[e].sdRecordId;t!==null&&a.want(t)}o.set(r.model,{pg:t,cols:i})}let[s,{cols:c}]=o.entries().next().value,l=n.model.groups[s],u=o.size===1?Se(l,c.map(e=>l.channels[e])):1/0;for await(let t of yt(e.io,n.model,[...o.keys()],a,e.signal,u)){let{pg:e,cols:r}=o.get(t.g);yield await Zt(n.model.groups[t.g],r,t.buf,t.n,t.start,t.size,e,a)}}function $t(e){let t=e.plan.state,n=new Map;for(let r of e.selection){let e=t.model.groups[t.groups[r.group].model].dg;n.set(e,[...n.get(e)??[],r.group])}return[...n].sort((e,t)=>e[0]-t[0]).map(([,e])=>e)}const en={...ge,async plan(e,t){let n=await t.read(0,64);if(f(n,`UnFinMF`))throw Error(`This MF4 was not finalized by its logger (it starts with UnFinMF). Finalize it with the logger software or asammdf, then open it again.`);let r=u(n.subarray(8,16)).replace(/\0/g,``).trim(),i=Number(r.replace(`.`,``).slice(0,3))>=400?await ce(t,r):await C(t,n,r);xe(i,t.size);let a=await Wt(t,i,e.companions.filter(e=>e.name.toLowerCase().endsWith(`.dbc`))),o=new Set(a?.layouts.keys()??[]),s=[],c=[],l=[...i.notes],d=0;for(let e=0;e<i.groups.length;e++){let n=i.groups[e];if(n.vlsdCg||n.cycles===0||o.has(e))continue;let r=[];if(n.channels.forEach((e,t)=>{qt(e)?r.push(t):d++}),r.length!==0){for(let e of r){let t=n.channels[e].conv;t.k===`unsupported`&&l.push(`${n.channels[e].name}: ${t.what} is not supported; raw values are shown.`)}c.push({model:e,channels:r}),s.push({name:n.name,channels:r.map(e=>Jt(n.channels[e])),samples:n.cycles,time:n.master?{kind:`timestamps`}:{kind:`index`},rateHz:await Yt(t,n)})}}if(d&&l.push(`${d} byte-array channel${d===1?` was`:`s were`} skipped.`),a){if(a.routes.length===0&&a.dbc.size===0){if(s.length===0)throw Error(`This MF4 has raw CAN frames. Drop its .dbc file together with it to decode signals.`);l.push(`This MF4 also has raw CAN frames. Drop its .dbc file together with it to decode signals.`)}for(let e of a.routes)c.push({model:e.model,route:e.route}),s.push(e.group);l.push(...a.notes)}if(s.length===0)throw Error(`This MDF file has no channels with samples.`);let p={model:i,groups:c,bus:a};return{format:i.version,startTime:i.startTime,groups:s,meta:i.meta,events:[],notes:l,interleaved:!!a?.routes.length||i.groups.some(e=>!e.sorted&&!e.vlsdCg),state:p}},async*stream(e){for(let t of $t(e))yield*Qt(e,t)},streamGroup(e,t){return Qt(e,[t])}},tn={id:`edf`,label:`EDF / BDF (+)`,extensions:[`.edf`,`.bdf`,`.rec`],sniff:e=>f(e,`0 `)||e[0]===255&&f(e,`BIOSEMI`,1)};function nn(e){let t=[];for(let n of d(e).split(`\0`)){if(!n)continue;let e=n.split(``),r=parseFloat(e[0].split(``)[0]);Number.isFinite(r)&&t.push({onset:r,texts:e.slice(1).filter(e=>e.length>0)})}return t}function rn(e,t){let n=/^(\d\d)\.(\d\d)\.(\d\d)$/.exec(e),r=/^(\d\d)\.(\d\d)\.(\d\d)$/.exec(t);if(!n||!r)return null;let i=Number(n[3]);return`${i>=85?1900+i:2e3+i}-${n[2]}-${n[1]}T${r[1]}:${r[2]}:${r[3]}`}const an=e=>`${+e.toFixed(6)} Hz`;function on(e,t,n,r,i,a,o,s){let{bit:c,off:l}=e;if(a===2)for(let e=0;e<i;e++)o[s+e]=c*(l+t.getInt16(r+2*e,!0));else for(let e=0,t=r;e<i;e++,t+=3)o[s+e]=c*(l+((n[t]|n[t+1]<<8|n[t+2]<<16)<<8>>8))}const sn={...tn,async plan(e,t){let n=await t.read(0,256),r=(e,t)=>u(n.subarray(e,e+t)).trim(),i=n[0]===255,a=parseInt(r(252,4),10),o=parseInt(r(184,8),10),s=r(192,44),c=/^(EDF|BDF)\+/.test(s),l=/^(EDF|BDF)\+D/.test(s),d=parseFloat(r(244,8));if(!(a>0)||o!==256*(a+1)||!(d>0))throw Error(`This EDF/BDF header is damaged.`);let f=await t.read(256,a*256),p=(e,t,n)=>u(f.subarray(e*a+t*n,e*a+t*(n+1))).trim(),m=i?3:2,h=[],g=0;for(let e=0;e<a;e++){let t=parseFloat(p(104,8,e)),n=parseFloat(p(112,8,e)),r=parseFloat(p(120,8,e)),i=parseFloat(p(128,8,e)),a=Number(p(216,8,e));if(!(Number.isInteger(a)&&a>=0))throw Error(`This EDF/BDF header is damaged (samples per record).`);let o=(n-t)/(i-r);h.push({label:p(0,16,e),unit:p(96,8,e),spr:a,offset:g,bit:o,off:n/o-i}),g+=a*m}let _=g;if(!(_>0&&o+_<=t.size))throw Error(`This EDF/BDF file is damaged (its data records do not fit in it).`);let v=Math.floor((t.size-o)/_),y=parseInt(r(236,8),10),b=[];y>=0?y>v&&(b.push(`The file is shorter than its header says: ${v} of ${y} data records were read.`),y=v):y=v;let x=c?h.flatMap((e,t)=>/^(EDF|BDF) Annotations$/.test(e.label)?[t]:[]):[],S=new Map;h.forEach((e,t)=>{!x.includes(t)&&e.spr>0&&S.set(e.spr,[...S.get(e.spr)??[],t])});let C=[...S.values()],w=C.map(e=>{let t=h[e[0]].spr/d;return{name:an(t),channels:e.map(e=>({name:h[e].label,unit:h[e].unit})),samples:y*h[e[0]].spr,rateHz:t,time:l?{kind:`timestamps`}:{kind:`rate`,rate:t,start:0}}}),T={headerBytes:o,records:y,duration:d,recordBytes:_,bps:m,signals:h,groups:C,annotations:x,discontinuous:l};return{format:`${i?`BDF`:`EDF`}${c?l?`+D`:`+`:``}`,startTime:rn(r(168,8),r(176,8)),groups:w,meta:{patient:r(8,80),recording:r(88,80)},events:[],notes:l?[`Discontinuous recording: each gap shows as a break in the traces.`,...b]:b,state:T}},async*stream(e){let t=e.plan.state,r=Math.max(1,Math.floor(n/t.recordBytes)),a=e.selection.map(e=>({g:e.group,chans:e.channels.map(n=>t.signals[t.groups[e.group][n]]),spr:t.signals[t.groups[e.group][0]].spr})),o=a.map(()=>0),s=0,c=NaN;for await(let n of e.io.windows(t.headerBytes,t.records*t.recordBytes,r*t.recordBytes)){e.signal?.throwIfAborted();let r=Math.floor(n.bytes.length/t.recordBytes);if(r===0)break;let l=i(n.bytes),u=new Float64Array(r),d=[];for(let e=0;e<r;e++)u[e]=(s+e)*t.duration,t.annotations.forEach((r,i)=>{let a=t.signals[r],o=e*t.recordBytes+a.offset,s=nn(n.bytes.subarray(o,o+a.spr*t.bps));i===0&&s.length&&(u[e]=s[0].onset);for(let e of s)for(let t of e.texts)d.push({time:e.onset,text:t})});let f=new Uint8Array(r),p=0;if(t.discontinuous)for(let e=0;e<r;e++){let n=e?u[e-1]+t.duration:c;n===n&&u[e]>n+1e-9&&(f[e]=1,p++)}for(let e=0;e<a.length;e++){let i=a[e],s=i.spr/t.duration,m=r*i.spr+p,h=t.discontinuous?new Float64Array(m):null,g=i.chans.map(()=>new Float64Array(m)),_=0;for(let e=0;e<r;e++){if(f[e]){h[_]=e?u[e-1]+t.duration:c;for(let e of g)e[_]=NaN;_++}if(h)for(let t=0;t<i.spr;t++)h[_+t]=u[e]+t/s;let r=e*t.recordBytes;i.chans.forEach((e,a)=>on(e,l,n.bytes,r+e.offset,i.spr,t.bps,g[a],_)),_+=i.spr}let v={group:i.g,time:h,start:o[e],length:m,columns:g};e===0&&d.length&&(v.events=d),o[e]+=m,yield v}c=u[r-1]+t.duration,s+=r}}};function cn(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})}const ln={id:`xdf`,label:`XDF (Lab Streaming Layer)`,extensions:[`.xdf`],sniff:e=>f(e,`XDF:`)},un={float32:4,double64:8,int8:1,int16:2,int32:4,int64:8};function dn(e,t,n=0){let r=e.indexOf(`<${t}>`,n);if(r<0)return``;let i=e.indexOf(`</${t}>`,r);return i<0?``:e.slice(r+t.length+2,i).trim()}function fn(e,t){let n=[];for(let r=e.indexOf(`<${t}>`);r>=0;){let i=e.indexOf(`</${t}>`,r);if(i<0)break;n.push(e.slice(r,i+t.length+3)),r=e.indexOf(`<${t}>`,i)}return n}const pn=e=>e.fmt===`string`||un[e.fmt]!==void 0;function mn(e,t,n){let r=e[n];if((r===1||r===4||r===8)&&n+1+r<=e.length)return r===1?[e[n+1],2]:r===4?[t.getUint32(n+1,!0),5]:[a(t,n+1),9];throw Error(`This XDF file is damaged (bad length field).`)}function hn(e,t,n,r){if(n>=e.length)return-1;if(e[n++]===8&&(n+=8),r.fmt!==`string`)return n+un[r.fmt]*r.nch<=e.length?n+un[r.fmt]*r.nch:-1;for(let i=0;i<r.nch;i++){if(n>=e.length)return-1;let[r,i]=mn(e,t,n);n+=i+r}return n<=e.length?n:-1}async function*gn(e,t){let n=new Uint8Array;for await(let r of e.windows(4,e.size-4)){t?.throwIfAborted();let a=r.bytes,o=r.offset-n.length;if(n.length){let e=new Uint8Array(n.length+a.length);e.set(n),e.set(a,n.length),a=e}let s=i(a),c=0;for(;!(c+1>a.length);){let t=a[c];if(c+1+t>a.length)break;let[n,r]=mn(a,s,c),i=c+r+n;if(o+i>e.size)return;if(i>a.length)break;yield{tag:a[c+r]|a[c+r+1]<<8,body:a.subarray(c+r+2,i)},c=i}n=a.slice(c)}}function _n(e,t,n){let r=t-e.i0,i=n-e.t0;e.n++,e.si+=r,e.st+=i,e.sii+=r*r,e.sit+=r*i}function vn(e){let t=e.n*e.sii-e.si*e.si;e.b=t>0?(e.n*e.sit-e.si*e.st)/t:0,e.a=(e.st-e.b*e.si)/Math.max(1,e.n)}function yn(e){if(e.length===0)return[0,0];if(e.length===1)return[e[0][1],0];let t={i0:e[0][0],t0:0,n:0,si:0,st:0,sii:0,sit:0,a:0,b:0};for(let[n,r]of e)_n(t,n,r);return vn(t),[t.a-t.b*t.i0,t.b]}function bn(e,t,n){let r=t.t0+t.a+t.b*(n-t.i0);return r+e.c0+e.c1*r}const xn={...ln,async plan(e,t){let n=new Map,r=``;for await(let e of gn(t)){let t=i(e.body);if(e.tag===1)r=d(e.body);else if(e.tag===2){let r=t.getUint32(0,!0),i=d(e.body.subarray(4)),a=parseInt(dn(i,`channel_count`),10)||1;if(!(a>=1&&a<=1e5))throw Error(`This XDF file is damaged (a stream with ${a} channels).`);let o=fn(i,`channel`);n.set(r,{id:r,name:dn(i,`name`)||`Stream ${r}`,nch:a,srate:parseFloat(dn(i,`nominal_srate`))||0,fmt:dn(i,`channel_format`)||`float32`,labels:Array.from({length:a},(e,t)=>dn(o[t]??``,`label`)||`Ch${t+1}`),units:Array.from({length:a},(e,t)=>dn(o[t]??``,`unit`)),count:0,segs:[],clock:[],c0:0,c1:0,lastTs:NaN})}else if(e.tag===3){let r=n.get(t.getUint32(0,!0));if(!r||!pn(r))continue;let[i,a]=mn(e.body,t,4),o=4+a,s=un[r.fmt],c=r.srate>0?Math.max(1,500/r.srate):1/0;for(let n=0;n<i&&!(hn(e.body,t,o,r)<0);n++){let n;if(e.body[o++]===8?(n=t.getFloat64(o,!0),o+=8):n=r.lastTs+(r.srate>0?1/r.srate:0),r.fmt===`string`)for(let n=0;n<r.nch;n++){let[n,r]=mn(e.body,t,o);o+=r+n}else o+=s*r.nch;if(r.srate>0){let e=r.segs[r.segs.length-1];(!e||n-r.lastTs>c)&&r.segs.push(e={i0:r.count,t0:n,n:0,si:0,st:0,sii:0,sit:0,a:0,b:0}),_n(e,r.count,n)}else r.count===0&&r.segs.push({i0:0,t0:n,n:1,si:0,st:0,sii:0,sit:0,a:0,b:0});r.lastTs=n,r.count++}}else if(e.tag===4){let e=n.get(t.getUint32(0,!0));e&&e.clock.push([t.getFloat64(4,!0),t.getFloat64(12,!0)])}}let a=[],o=[...n.values()].sort((e,t)=>e.id-t.id).filter(e=>(pn(e)||a.push(`${e.name}: channel format ${e.fmt} is not supported; skipped.`),pn(e))),s=1/0;for(let e of o){[e.c0,e.c1]=yn(e.clock);for(let t of e.segs)vn(t);if(e.count===0)continue;let t=e.srate>0?bn(e,e.segs[0],0):e.segs[0].t0+e.c0+e.c1*e.segs[0].t0;s=Math.min(s,t)}let c=cn(o.map(e=>e.name),[]),l=o.map((e,t)=>({name:c[t],channels:e.labels.map((t,n)=>({name:t,unit:e.units[n],...e.fmt===`string`?{text:!0,sparse:!0}:{}})),samples:e.count,time:{kind:`timestamps`},rateHz:e.srate>0?e.srate:null,irregular:e.srate===0})),u=dn(r,`version`);return{format:`XDF ${u||`1.0`}`,startTime:null,groups:l,meta:{header:u},events:[],notes:a,state:{streams:o,origin:Number.isFinite(s)?s:0}}},async*stream(e){let t=e.plan.state,n=8192,r=new Map,a=e=>e.sel.map(()=>e.s.fmt===`string`?Array(n):new Float64Array(n));for(let i of e.selection){let o=t.streams[i.group],s={g:i.group,s:o,sel:p(e,i.group),time:new Float64Array(n),cols:[],n:0,start:0,seg:0,i:0,raw:NaN};s.cols=a(s),r.set(o.id,s)}let o=e=>{let t={group:e.g,time:e.time.slice(0,e.n),start:e.start,length:e.n,columns:e.cols.map(t=>t.slice(0,e.n))};return e.start+=e.n,e.n=0,e.time=new Float64Array(n),e.cols=a(e),t};for await(let a of gn(e.io,e.signal)){if(a.tag!==3)continue;let e=i(a.body),s=r.get(e.getUint32(0,!0));if(!s)continue;let c=s.s,[l,u]=mn(a.body,e,4),f=4+u,p=un[c.fmt],m=[];for(let r=0;r<l&&!(hn(a.body,e,f,c)<0);r++){let r;a.body[f++]===8?(r=e.getFloat64(f,!0),f+=8):r=s.raw+(c.srate>0?1/c.srate:0),s.raw=r;let i;if(c.srate>0){for(;s.seg+1<c.segs.length&&c.segs[s.seg+1].i0<=s.i;)s.seg++;i=bn(c,c.segs[s.seg],s.i)}else i=r+c.c0+c.c1*r;if(s.time[s.n]=i-t.origin,c.fmt===`string`){let n=[];for(let t=0;t<c.nch;t++){let[t,r]=mn(a.body,e,f);n.push(d(a.body.subarray(f+r,f+r+t))),f+=r+t}s.sel.forEach((e,t)=>{s.cols[t][s.n]=n[e]}),m.push({time:i-t.origin,text:n.join(` `)})}else s.sel.forEach((t,n)=>{let r=f+t*p,i=s.cols[n];switch(c.fmt){case`float32`:i[s.n]=e.getFloat32(r,!0);break;case`double64`:i[s.n]=e.getFloat64(r,!0);break;case`int8`:i[s.n]=e.getInt8(r);break;case`int16`:i[s.n]=e.getInt16(r,!0);break;case`int32`:i[s.n]=e.getInt32(r,!0);break;default:i[s.n]=e.getInt32(r+4,!0)*4294967296+e.getUint32(r,!0)}}),f+=p*c.nch;s.i++,++s.n===n&&(yield o(s))}m.length&&(yield{group:s.g,time:new Float64Array,start:s.start,length:0,columns:s.sel.map(()=>new Float64Array),events:m})}for(let e of r.values())e.n&&(yield o(e))}},Sn={id:`tdms`,label:`NI TDMS`,extensions:[`.tdms`],companions:[{ext:`.tdms_index`}],sniff:e=>f(e,`TDSm`)},Cn=4713,wn=4714,Tn={1:1,2:2,3:4,4:8,5:1,6:2,7:4,8:8,9:4,10:8,25:4,26:8,33:1,68:16},En={0:5,1:1,2:6,3:2,4:7,5:3,6:8,7:4,8:9,9:10,4294967295:68},Dn=(e,t,n)=>n?o(e,t+8,n)+a(e,t,n)/2**64:o(e,t,n)+a(e,t+8,n)/2**64,On=()=>Error(`This TDMS file is damaged (its metadata is cut short).`);function kn(e,t,n,r,i){if(n+(r===32?4:Tn[r]??0)>t.length)throw On();switch(r){case 32:{let r=e.getUint32(n,i);if(n+4+r>t.length)throw On();return[d(t.subarray(n+4,n+4+r)),4+r]}case 1:return[e.getInt8(n),1];case 2:return[e.getInt16(n,i),2];case 3:return[e.getInt32(n,i),4];case 4:return[o(e,n,i),8];case 5:return[e.getUint8(n),1];case 6:return[e.getUint16(n,i),2];case 7:return[e.getUint32(n,i),4];case 8:return[a(e,n,i),8];case 9:case 25:return[e.getFloat32(n,i),4];case 10:case 26:return[e.getFloat64(n,i),8];case 33:return[e.getUint8(n)!==0,1];case 68:return[Dn(e,n,i),16];default:throw Error(`This TDMS file has a property of type ${r}, which Kymoscope cannot read.`)}}function An(e){let t=/^\/'((?:[^']|'')*)'(?:\/'((?:[^']|'')*)')?$/.exec(e);return t?[t[1].replace(/''/g,`'`),(t[2]??``).replace(/''/g,`'`)]:null}const jn=4294967295;function Mn(e){if(e.has(`NI_Number_Of_Scales`))return Number(e.get(`NI_Number_Of_Scales`));let t=0;for(let n of e.keys()){let e=/^NI_Scale\[(\d+)\]_Scale_Type$/.exec(n);e&&(t=Math.max(t,Number(e[1])+1))}return t}function Nn(e,t,n){let r=e.find(e=>Mn(e)>0);if(!r||r.get(`NI_Scaling_Status`)===`scaled`)return null;let i=(e,a)=>{if(e===jn||e<0||a>8)return e=>e;let o=r.get(`NI_Scale[${e}]_Scale_Type`);if(o===void 0)return e=>e;if(o===`Linear`){let t=Number(r.get(`NI_Scale[${e}]_Linear_Slope`)),n=Number(r.get(`NI_Scale[${e}]_Linear_Y_Intercept`)??0),o=i(Number(r.get(`NI_Scale[${e}]_Linear_Input_Source`)??jn),a+1);return o&&(e=>t*o(e)+n)}if(o===`Polynomial`){let o=Number(r.get(`NI_Scale[${e}]_Polynomial_Coefficients_Size`)??4);if(!(Number.isInteger(o)&&o>=0&&o<=64))return t.push(`${n}: an NI polynomial scale with ${o} coefficients is not supported; raw values are shown.`),null;let s=Array.from({length:o},(t,n)=>Number(r.get(`NI_Scale[${e}]_Polynomial_Coefficients[${n}]`))),c=i(Number(r.get(`NI_Scale[${e}]_Polynomial_Input_Source`)??jn),a+1);return c&&(e=>{let t=c(e),n=0;for(let e=o-1;e>=0;e--)n=n*t+s[e];return n})}return t.push(`${n}: NI scale type ${String(o)} is not supported; raw values are shown.`),null};return i(Mn(r)-1,0)}const Pn={1:Int8Array,2:Int16Array,3:Int32Array,5:Uint8Array,6:Uint16Array,7:Uint32Array,9:Float32Array,10:Float64Array,25:Float32Array,26:Float64Array,33:Uint8Array};function Fn(e,t,n,r,i,s,c,l){let u=Pn[e];if(u&&s&&r===Tn[e]&&(t.byteOffset+n)%r===0){c.set(new u(t.buffer,t.byteOffset+n,i),l);return}switch(e){case 1:for(let e=0;e<i;e++,n+=r)c[l+e]=t.getInt8(n);return;case 2:for(let e=0;e<i;e++,n+=r)c[l+e]=t.getInt16(n,s);return;case 3:for(let e=0;e<i;e++,n+=r)c[l+e]=t.getInt32(n,s);return;case 4:for(let e=0;e<i;e++,n+=r)c[l+e]=o(t,n,s);return;case 5:case 33:for(let e=0;e<i;e++,n+=r)c[l+e]=t.getUint8(n);return;case 6:for(let e=0;e<i;e++,n+=r)c[l+e]=t.getUint16(n,s);return;case 7:for(let e=0;e<i;e++,n+=r)c[l+e]=t.getUint32(n,s);return;case 8:for(let e=0;e<i;e++,n+=r)c[l+e]=a(t,n,s);return;case 9:case 25:for(let e=0;e<i;e++,n+=r)c[l+e]=t.getFloat32(n,s);return;case 10:case 26:for(let e=0;e<i;e++,n+=r)c[l+e]=t.getFloat64(n,s);return;case 68:for(let e=0;e<i;e++,n+=r)c[l+e]=Dn(t,n,s);return;default:c.fill(NaN,l,l+i)}}async function In(e,t,n){let r=new Map,o=[],s=[],c=new Map,l=new Map,u=t??e,f=0,p=0;for(;f+28<=e.size&&p+28<=u.size;){let m=t?p:f,h=await u.read(m,28),g=i(h);if(!(h[0]===84&&h[1]===68&&h[2]===83&&(h[3]===109||h[3]===104)))throw Error(`This TDMS file is damaged (no segment lead-in where one should be).`);let _=g.getUint32(4,!0),v=!(_&64),y=a(g,12,v),b=a(g,20,v),x=y>=2**53?e.size:Math.min(e.size,f+28+y);if(b>x-f-28)throw Error(`This TDMS file is damaged (segment metadata longer than its segment).`);if(_&2){let e=await u.read(m+28,b),t=i(e);_&4&&(s=[],c=new Map);let o=0,f=t=>{if(o+t>e.length)throw On()};f(4);let p=t.getUint32(o,v);o+=4;for(let i=0;i<p;i++){f(4);let i=t.getUint32(o,v);f(4+i);let u=d(e.subarray(o+4,o+4+i));o+=4+i;let p=An(u),m=r.get(u);m||r.set(u,m={path:u,group:p?.[0]??``,name:p?.[1]??``,type:0,props:new Map,pieces:[],total:0}),f(4);let h=t.getUint32(o,v);o+=4;let g=null;if(h===4294967295)g=null;else if(h===0)g=l.get(m)??null;else if(h===Cn||h===wn){f(32);let e=a(t,o+8,v),r=t.getUint32(o+16,v),i=h===Cn?20:17,s=o+20,c=En[t.getUint32(s,v)]??0,l=t.getUint32(s+8,v);o=s+r*i,f(4);let u=t.getUint32(o,v);o+=4,f(4*u);let d=0;for(let e=0;e<u;e++)d+=t.getUint32(o+4*e,v);o+=4*u,h===wn?n.push(`${m.name}: DAQmx digital line data is not supported; skipped.`):(r>1&&n.push(`${m.name}: only the first of its ${r} DAQmx scalers is read.`),g={type:c,count:e,bytes:0,daqmx:{byteOffset:l,stride:d}})}else{if(h<20)throw On();f(h-4);let e=t.getUint32(o,v);e===32&&f(24);let n=a(t,o+8,v),r=e===32?a(t,o+16,v):n*(Tn[e]??0);o+=h-4,g={type:e,count:n,bytes:r,daqmx:null}}g&&(m.type=g.type,l.set(m,g)),f(4);let _=t.getUint32(o,v);o+=4;for(let n=0;n<_;n++){f(4);let n=t.getUint32(o,v);f(8+n);let r=d(e.subarray(o+4,o+4+n));o+=4+n;let i=t.getUint32(o,v);o+=4;let[a,s]=kn(t,e,o,i,v);m.props.set(r,a),o+=s}let y=c.get(m);y===void 0?c.set(m,s.push({obj:m,idx:g})-1):s[y].idx=g}}if(_&8){let e=f+28+b,t=s.filter(e=>e.idx&&e.idx.count>0),n=t.filter(e=>e.idx.daqmx),r=(_&32)!=0,i=0,a=0;n.length?(a=n[0].idx.daqmx.stride,i=n[0].idx.count*a):r?(a=t.reduce((e,t)=>e+(Tn[t.idx.type]??0),0),i=(t[0]?.idx.count??0)*a):i=t.reduce((e,t)=>e+t.idx.bytes,0);let c=i>0?Math.floor((x-e)/i):0,l=o.push({rawStart:e,chunkSize:i,chunks:c,le:v})-1,u=0;for(let e of t){let t=e.idx,n=Tn[t.type]??0,o=t.daqmx?{seg:l,count:t.count,offset:t.daqmx.byteOffset,bytes:0,stride:a,type:t.type}:{seg:l,count:t.count,offset:u,bytes:t.bytes,stride:r?a:n,type:t.type};t.daqmx||(u+=r?n:t.bytes),o.type===32?o.count=Math.min(o.count,Math.floor(o.bytes/4)):n>0&&(o.count=Math.min(o.count,o.stride>0?Math.max(0,Math.floor((i-o.offset-n)/o.stride)+1):0)),e.obj.pieces.push(o),c&&(e.obj.total+=o.count*c)}}if(f=x,p+=28+b,x>=e.size)break}return{objs:[...r.values()],segments:o}}const Ln={...Sn,async plan(e,t){let n=e.companions.find(e=>e.name.toLowerCase().endsWith(`.tdms_index`)),a=[],{objs:o,segments:s}=await In(t,n?new r(n):null,a),c=o.find(e=>e.path===`/`)?.props,l=o.filter(e=>e.name&&e.total>0&&(e.type===32||Tn[e.type])),u=new Set(l);for(let e of o)e.name&&e.total>0&&!u.has(e)&&a.push(`${e.name}: TDMS data type ${e.type} is not supported; skipped.`);let d=l.map(e=>e.props.get(`wf_start_time`)).filter(e=>typeof e==`number`),f=d.reduce((e,t)=>Math.min(e,t),d.length?1/0:0),p=new Map;for(let e of l){let t=`${e.total}|${e.props.get(`wf_increment`)??``}`,n=p.get(e.group)??new Map,r=n.get(t);r?r.push(e):n.set(t,[e]),p.set(e.group,n)}let m=[],h=[];for(let[e,t]of p)for(let n of t.values()){let r=n[0].props.get(`wf_increment`),i=typeof r==`number`&&r>0?1/r:null,a=i?null:n.find(e=>e.type===68)??n.find(e=>e.type!==32&&/^(time|timestamp|t)$/i.test(e.name))??null,o=n.filter(e=>e!==a),s=n[0].props.get(`wf_start_time`),c=i?Number(n[0].props.get(`wf_start_offset`)??0)+(typeof s==`number`?s-f:0):0;m.push({name:t.size===1?e:`${e} (${i?+i.toFixed(6):n[0].total} ${i?`Hz`:`samples`})`,channels:o.map(e=>({name:e.name,unit:String(e.props.get(`unit_string`)??``),text:e.type===32})),samples:n[0].total,time:i?{kind:`rate`,rate:i,start:c}:a?{kind:`timestamps`}:{kind:`index`},rateHz:i}),h.push({channels:o,time:a,origin:0})}if(m.length===0)throw Error(`This TDMS file has no channels with data.`);let g=[];for(let e of h){if(!e.time)continue;let n=e.time.pieces[0],r=s[n.seg],a=await t.read(r.rawStart+n.offset,Tn[n.type]??8),o=new Float64Array(1);Fn(n.type,i(a),0,0,1,r.le,o,0),g.push(o[0])}let _=g.reduce((e,t)=>Math.min(e,t),g.length?1/0:0);for(let e of h)e.origin=_;let v=new Date(Date.UTC(1904,0,1)+f*1e3),y=f&&Number.isFinite(v.getTime())?v.toISOString():null,b={objs:o,segments:s,groups:h},x={};for(let[e,t]of c??[])typeof t==`string`&&(x[e]=t);return{format:`TDMS`,startTime:y,groups:m,meta:x,events:[],notes:a,state:b}},async*stream(e){for(let t of e.selection)yield*zn(e,t.group)},streamGroup:(e,t)=>zn(e,t)};function Rn(e,t,n,r,i,a){let o=0;for(;o<i&&r.pi<t.pieces.length;){let s=t.pieces[r.pi],c=e.segments[s.seg];if(r.chunk>=c.chunks){r.pi++,r.chunk=0,r.row=0;continue}let l=Math.min(i-o,s.count-r.row),u=c.rawStart+r.chunk*c.chunkSize+s.offset;if(s.type===32)a.push({ch:n,at:u,end:u+s.bytes,rows:l,first:r.row,out:o,piece:s,le:c.le,range:0});else{let e=u+r.row*s.stride;a.push({ch:n,at:e,end:e+(l-1)*s.stride+Tn[s.type],rows:l,first:r.row,out:o,piece:s,le:c.le,range:0})}o+=l,r.row+=l,r.row>=s.count&&(r.chunk++,r.row=0)}}async function*zn(e,t){let n=e.plan.state,r=n.groups[t],a=p(e,t).map(e=>r.channels[e]),o=r.time?[r.time,...a]:a;if(!o.length)return;let s=new Map(n.objs.map(e=>[e.path,e.props])),c=e=>s.get(e)??new Map,l=c(`/`),u=o.map(e=>Nn([e.props,c(`/'${e.group.replace(/'/g,`''`)}'`),l],[],e.name)),f=o.map(()=>({pi:0,chunk:0,row:0})),m=o.reduce((e,t)=>Math.min(e,t.total),1/0);for(let a=0;a<m;){e.signal?.throwIfAborted();let s=Math.min(65536,m-a),c=[];o.forEach((e,t)=>Rn(n,e,t,f[t],s,c));let l=c.slice().sort((e,t)=>e.at-t.at),p=[];for(let e of l){let t=p[p.length-1];t&&e.at<=t.end+65536&&Math.max(t.end,e.end)-t.at<=16777216?t.end=Math.max(t.end,e.end):p.push({at:e.at,end:e.end}),e.range=p.length-1}let h=[];for(let t of p)h.push(await e.io.slice(t.at,t.end-t.at));let g=h.map(i),_=o.map(e=>e.type===32?Array(s).fill(null):new Float64Array(s).fill(NaN));for(let e of c){let t=e.at-p[e.range].at,n=e.piece;if(n.type===32){let r=h[e.range],i=g[e.range],a=t+4*n.count,o=_[e.ch];for(let n=0;n<e.rows;n++){let s=e.first+n,c=s===0?0:i.getUint32(t+4*(s-1),e.le),l=i.getUint32(t+4*s,e.le);o[e.out+n]=d(r.subarray(a+c,a+l))}}else Fn(n.type,g[e.range],t,n.stride,e.rows,e.le,_[e.ch],e.out)}for(let e=0;e<o.length;e++){let t=u[e],n=_[e];if(t&&n instanceof Float64Array)for(let e=0;e<s;e++)n[e]=t(n[e])}let v=null;if(r.time){v=_.shift();for(let e=0;e<s;e++)v[e]-=r.origin}yield{group:t,time:v,start:a,length:s,columns:_},a+=s}}const Bn={id:`hdf5`,label:`HDF5`,extensions:[`.h5`,`.hdf5`,`.hdf`,`.he5`,`.nc`],sniff:e=>[0,512,1024,2048].some(t=>f(e,`‰HDF\r
1
+ var e=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);const t=1<<20,n=16<<20;var r=class{size;bytesRead=0;#e;#t=new Map;constructor(e){this.#e=e,this.size=e.size}async read(e,n){let r=Math.min(this.size,e+n);if(r<=e)return new Uint8Array;if(r-e>t)return this.slice(e,r-e);let i=Math.floor(e/t),a=Math.floor((r-1)/t),o=await this.#n(i);if(i===a)return o.subarray(e-i*t,r-i*t);let s=new Uint8Array(r-e),c=o.subarray(e-i*t);return s.set(c),s.set((await this.#n(a)).subarray(0,r-a*t),c.length),s}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,r=n){let i=Math.min(this.size,e+t);for(let t=e;t<i;t+=r)yield{offset:t,bytes:await this.slice(t,Math.min(r,i-t))}}async#n(e){let n=this.#t.get(e);if(n)return this.#t.delete(e),this.#t.set(e,n),n;let r=await this.slice(e*t,t);return this.#t.size>=64&&this.#t.delete(this.#t.keys().next().value),this.#t.set(e,r),r}};const i=e=>new DataView(e.buffer,e.byteOffset,e.byteLength);function a(e,t,n=!0){let r=e.getUint32(n?t:t+4,n);return e.getUint32(n?t+4:t,n)*4294967296+r}function o(e,t,n=!0){let r=e.getUint32(n?t:t+4,n);return e.getInt32(n?t+4:t,n)*4294967296+r}const s=new TextDecoder(`utf-8`),c=new TextDecoder(`latin1`);function l(e,t=!1){let n=e.indexOf(0);return(t?c:s).decode(n<0?e:e.subarray(0,n))}const u=e=>c.decode(e),d=e=>s.decode(e);function f(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}function p(e,t){return e.selection.find(e=>e.group===t)?.channels??[]}const m={sin:Math.sin,cos:Math.cos,tan:Math.tan,asin:Math.asin,acos:Math.acos,atan:Math.atan,sinh:Math.sinh,cosh:Math.cosh,tanh:Math.tanh,exp:Math.exp,ln:Math.log,log:Math.log,log10:Math.log10,sqrt:Math.sqrt,abs:Math.abs,pow:Math.pow,min:Math.min,max:Math.max};function h(e){if(e.length>4096)return null;let t=e.match(/\d+\.?\d*(?:[eE][+-]?\d+)?|\.\d+(?:[eE][+-]?\d+)?|[A-Za-z_]\w*|\*\*|[-+*/^(),]|\S/g)??[],n=0,r=()=>t[n],i=()=>{throw Error(`formula`)},a=e=>{t[n++]!==e&&i()},o=()=>{let e=s();for(;r()===`+`||r()===`-`;){let r=t[n++],i=e,a=s();e=r===`+`?e=>i(e)+a(e):e=>i(e)-a(e)}return e},s=()=>{let e=c();for(;r()===`*`||r()===`/`;){let r=t[n++],i=e,a=c();e=r===`*`?e=>i(e)*a(e):e=>i(e)/a(e)}return e},c=()=>{if(r()===`-`){n++;let e=c();return t=>-e(t)}return r()===`+`?(n++,c()):l()},l=()=>{let e=u();if(r()===`^`||r()===`**`){n++;let t=c();return n=>e(n)**t(n)}return e},u=()=>{let e=t[n++];if(e===void 0&&i(),e===`(`){let e=o();return a(`)`),e}if(/^[\d.]/.test(e)){let t=Number(e);return Number.isFinite(t)||i(),()=>t}if(e===`X`||e===`x`||e===`X1`)return e=>e;if(Object.hasOwn(m,e)){let t=m[e];a(`(`);let i=[o()];for(;r()===`,`;)n++,i.push(o());return a(`)`),i.length===1?e=>t(i[0](e)):e=>t(...i.map(t=>t(e)))}return i()};try{let e=o();return n===t.length?e:null}catch{return null}}const g={k:`id`};function _(e,t){let{keys:n,vals:r}=e,i=n.length;if(i===0)return t;if(t<=n[0])return r[0];if(t>=n[i-1])return r[i-1];let a=0,o=i-1;for(;o-a>1;){let e=a+o>>1;n[e]<=t?a=e:o=e}return e.interp?r[a]+(r[o]-r[a])*(t-n[a])/(n[o]-n[a]):t-n[a]<=n[o]-t?r[a]:r[o]}function v(e,t){let n=t.length;switch(e.k){case`lin`:{let{a:r,b:i}=e;if(r===1&&i===0)return;for(let e=0;e<n;e++)t[e]=r*t[e]+i;return}case`rat`:{let[r,i,a,o,s,c]=e.p;for(let e=0;e<n;e++){let n=t[e];t[e]=(r*n*n+i*n+a)/(o*n*n+s*n+c)}return}case`poly`:{let[r,i,a,o,s,c]=e.p;for(let e=0;e<n;e++){let n=t[e]-s-c;t[e]=(i-o*n)/(a*n-r)}return}case`alg`:{let r=e.f;for(let e=0;e<n;e++)t[e]=r(t[e]);return}case`tab`:for(let r=0;r<n;r++)t[r]=_(e,t[r]);return;case`rtv`:for(let r=0;r<n;r++){let n=t[r],i=e.def;for(let t=0;t<e.lo.length;t++)if(n>=e.lo[t]&&n<=e.hi[t]){i=e.vals[t];break}t[r]=i}return;default:return}}function y(e,t){let n=Float64Array.of(t);return v(e,n),n[0]}const b=(e,t)=>e===null||typeof e==`string`?e:String(y(e,t));function x(e,t){let n=Array(t.length),r=e.ranges.every(e=>e.lo===e.hi)?new Map(e.ranges.map(e=>[e.lo,e.to])):null;for(let i=0;i<t.length;i++){let a=t[i];if(a!==a){n[i]=null;continue}let o=e.def;if(r){let e=r.get(a);e!==void 0&&(o=e)}else for(let t of e.ranges)if(a>=t.lo&&(e.int||t.lo===t.hi?a<=t.hi:a<t.hi)){o=t.to;break}n[i]=b(o,a)}return n}function S(e,t){let n=(e,t)=>({type:e,bigEndian:t,encoding:`latin1`});switch(e){case 0:return n(`uint`,!t);case 1:return n(`int`,!t);case 2:case 3:return n(`float`,!t);case 7:return n(`string`,!1);case 8:return n(`bytes`,!1);case 9:return n(`uint`,!0);case 10:return n(`int`,!0);case 11:case 12:return n(`float`,!0);case 13:return n(`uint`,!1);case 14:return n(`int`,!1);case 15:case 16:return n(`float`,!1);default:return null}}async function C(e,t,n){let r=i(t).getUint16(24,!0)===0,a=()=>Error(`This MDF file is damaged (a block is cut short or lies outside the file).`),o=async(t,n=4)=>{let o=await e.read(t,4);if(o.length<4)throw a();let s=i(o).getUint16(2,r),c=await e.read(t,s);if(s<n||c.length<s)throw a();return{id:u(c.subarray(0,2)),v:i(c),b:c,size:s}},s=(e,t)=>e.getUint32(t,r),c=(e,t)=>e.getUint16(t,r),d=(e,t)=>e.getFloat64(t,r),f=async e=>e?l((await o(e)).b.subarray(4),!0):``,p=[],m=new Set,_=e=>{if(m.has(e))throw Error(`This MDF file is damaged (its blocks link in a loop).`);m.add(e)},v=async(e,t)=>{if(!e)return{conv:g,unit:``};let{v:n,b:r}=await o(e,46),i=l(r.subarray(22,42),!0),u=c(n,42),p=c(n,44);if(46+(u===0?16:u===1||u===2?16*p:u===6||u===9?48:u===11?40*p:u===12?20*p:0)>r.length)throw a();let m=e=>d(n,46+8*e);switch(u){case 0:return{conv:{k:`lin`,a:m(1),b:m(0)},unit:i};case 1:case 2:{let e=new Float64Array(p),t=new Float64Array(p);for(let n=0;n<p;n++)e[n]=m(2*n),t[n]=m(2*n+1);return{conv:{k:`tab`,keys:e,vals:t,interp:u===1},unit:i}}case 6:return{conv:{k:`poly`,p:[0,1,2,3,4,5].map(m)},unit:i};case 9:return{conv:{k:`rat`,p:[0,1,2,3,4,5].map(m)},unit:i};case 10:{let e=l(r.subarray(46,302),!0),t=h(e);return{conv:t?{k:`alg`,f:t}:{k:`unsupported`,what:`the formula "${e}"`},unit:i}}case 11:return{conv:{k:`text`,ranges:Array.from({length:p},(e,t)=>{let i=46+40*t,a=d(n,i);return{lo:a,hi:a,to:l(r.subarray(i+8,i+40),!0)}}),def:null,int:t},unit:i};case 12:{let e=await Promise.all(Array.from({length:p},async(e,t)=>{let r=46+20*t;return{lo:d(n,r),hi:d(n,r+8),to:await f(s(n,r+16))}}));return{conv:{k:`text`,ranges:e.slice(1),def:e[0]?.to??null,int:t},unit:i}}case 65535:return{conv:g,unit:i};default:return{conv:{k:`unsupported`,what:`MDF3 conversion type ${u}`},unit:i}}},y=await o(64,8),b=null;if(y.size>=172&&(s(y.v,164)||s(y.v,168))){let e=s(y.v,168)*4294967296+s(y.v,164);b=new Date(e/1e6).toISOString()}else{let e=u(y.b.subarray(18,28)),t=u(y.b.subarray(28,36));/^\d\d:\d\d:\d{4}$/.test(e)&&(b=`${e.slice(6)}-${e.slice(3,5)}-${e.slice(0,2)}T${t}`)}let x=[],C=0;for(let e=s(y.v,4),t=0;e;t++){_(e);let n=await o(e,24),i=c(n.v,22),a=[];for(let e=s(n.v,8);e;){_(e);let n=await o(e,26),u=[],d=null;for(let e=s(n.v,8);e;){_(e);let t=await o(e,192),n=l(t.b.subarray(26,58),!0),i=(t.size>=222?await f(s(t.v,218)):``)||n,a=S(c(t.v,190),r),m=c(t.v,186)+(t.size>=228?8*c(t.v,226):0);if(!a)p.push(`${i}: MDF3 data type ${c(t.v,190)} is not supported; skipped.`);else{let{conv:e,unit:n}=await v(s(t.v,8),a.type!==`float`),r={name:i,unit:n,kind:c(t.v,24)===1?`master`:`value`,...a,conv:e,sd:null,sdRecordId:null,byteOffset:m>>3,bitOffset:m&7,bitCount:c(t.v,188),invalBit:null,allInvalid:!1};r.kind===`master`&&!d?d=r:r.kind===`value`&&u.push(r)}e=s(t.v,4)}C++,a.push({name:await f(s(n.v,12))||`Group ${C}`,dg:t,recordId:c(n.v,16),recordIdSize:+(i>0),idTrailer:+(i===2),dataBytes:c(n.v,20),invalBytes:0,cycles:s(n.v,22),vlsdCg:!1,sorted:!0,master:d,channels:u,stream:[],busType:0,busEvent:!1}),e=s(n.v,4)}let u=a.reduce((e,t)=>e+t.cycles*(t.recordIdSize+t.dataBytes+t.idTrailer),0),d=[{offset:s(n.v,16),length:u,zip:null}];for(let e of a)e.stream=d,e.sorted=a.length===1,x.push(e);e=s(n.v,4)}return{version:`MDF ${n}`,startTime:b,groups:x,notes:p,meta:{}}}const w=e=>e*1032+1024,T=128e6,E=1e3,D=(e,t)=>e.length>t?`${e.slice(0,t-1)}…`:e;function O(e){let t=e.notes;for(let n of e.groups){n.name=D(String(n.name),256);for(let e of n.channels)e.name=D(String(e.name),256),e.unit=D(String(e.unit??``),64);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>100&&t.splice(100,t.length-100,`${t.length-100} more notes.`),e.notes=t.map(e=>D(String(e),E));let n={};for(let[t,r]of Object.entries(e.meta).slice(0,200))n[D(t,256)]=D(String(r),E);return e.meta=n,e.events=e.events.filter(e=>Number.isFinite(e.time)).map(e=>({time:e.time,text:D(String(e.text),E)})),e}function k(e){return e instanceof Error&&(e.constructor===Error||e.name===`KymoscopeError`||e.name===`AbortError`)?e:Error(`This file couldn't be read (it may be damaged).`)}function A(e,t){if(e.seen.has(t))throw Error(`This MF4 is damaged (its blocks link in a loop).`);e.seen.add(t)}async function j(e,t){let n=await e.read(t,24);if(n.length<24)throw Error(`This MF4 is damaged (bad block at byte ${t}).`);let r=i(n),o=u(n.subarray(0,4)),s=a(r,8),c=a(r,16);if(!o.startsWith(`##`)||s<24+8*c||s>1<<26)throw Error(`This MF4 is damaged (bad block at byte ${t}).`);let l=await e.read(t,s);if(l.length<s)throw Error(`This MF4 is damaged (the block at byte ${t} runs past the end of the file).`);let d=i(l),f=[];for(let e=0;e<c;e++)f.push(a(d,24+8*e));let p=l.subarray(24+8*c);return{id:o,links:f,data:i(p),bytes:p}}const M={lt:`<`,gt:`>`,amp:`&`,quot:`"`,apos:`'`};function N(e){let t=e.indexOf(`<TX>`),n=t<0?-1:e.indexOf(`</TX>`,t+4);return(n>=0?e.slice(t+4,n):e.replace(/<[^<>]*>/g,``)).replace(/&(lt|gt|amp|quot|apos);/g,(e,t)=>M[t]).trim()}function P(e,t){if(!t)return Promise.resolve(``);let n=e.texts.get(t);return n||(n=j(e.io,t).then(e=>{let t=l(e.bytes);return e.id===`##MD`?N(t):t}),e.texts.set(t,n)),n}async function ee(e,t,n=0){if(!t)return[];let r=e.io,o=await r.read(t,24),s=u(o.subarray(0,4)),c=o.length<24?0:a(i(o),8);switch(s){case`##DT`:case`##SD`:case`##RD`:return[{offset:t+24,length:c-24,zip:null}];case`##DZ`:{let e=i(await r.read(t+24,24));if(e.byteLength<24)throw Error(`This MF4 is damaged (bad block at byte ${t}).`);let n=e.getUint8(2);if(n===2||n===3)throw Error(`This MF4 uses zstd compression, which isn't supported yet.`);if(n===4||n===5)throw Error(`This MF4 uses LZ4 compression, which isn't supported yet.`);if(n>5)throw Error(`This MF4 is damaged (unknown compression type ${n}).`);let o=e.getUint32(4,!0),s=a(e,8),c=a(e,16);if(s>w(c)||n===1&&o===0)throw Error(`This MF4 is damaged (bad compressed block at byte ${t}).`);if(n===1&&s>268435456)throw Error(`This MF4 has a compressed block over 256 MB, which Kymoscope cannot read.`);return[{offset:t+48,length:c,zip:{type:n,param:o,orgLength:s}}]}case`##DL`:{if(n>1)throw Error(`This MF4 is damaged (unexpected ${s} block in its data).`);let i=[];for(let n=t;n;){A(e,n);let t=await j(r,n);for(let n of t.links.slice(1))i.push(...await ee(e,n,2));n=t.links[0]}return i}case`##HL`:if(n>0)throw Error(`This MF4 is damaged (unexpected ${s} block in its data).`);return A(e,t),ee(e,(await j(r,t)).links[0],1);case`##DV`:case`##DI`:throw Error(`This MF4 uses column-oriented storage (MDF 4.2 DV/DI blocks), which Kymoscope cannot read yet.`);default:throw Error(`This MF4 is damaged (unexpected ${s} block in its data).`)}}async function te(e,t,n){return t?u(await e.io.read(t,4))===`##CC`?ne(e,t,n+1):P(e,t):null}async function ne(e,t,n=0){if(!t||n>4||e.busy.has(t))return g;let r=e.convs.get(t);if(r)return r;e.busy.add(t);try{let r=await re(e,t,n);return e.convs.set(t,r),r}finally{e.busy.delete(t)}}async function re(e,t,n){let r=await j(e.io,t),i=r.data,a=i.getUint8(0),o=i.getUint16(4,!0),s=i.getUint16(6,!0),c=new Float64Array(s);for(let e=0;e<s;e++)c[e]=i.getFloat64(24+8*e,!0);let l=r.links.slice(4,4+o),u=()=>Promise.all(l.map(t=>te(e,t,n)));switch(a){case 0:return g;case 1:return{k:`lin`,b:c[0],a:c[1]};case 2:return{k:`rat`,p:[...c]};case 3:{let t=await P(e,l[0]),n=h(t);return n?{k:`alg`,f:n}:{k:`unsupported`,what:`the formula "${t}"`}}case 4:case 5:{let e=s>>1,t=new Float64Array(e),n=new Float64Array(e);for(let r=0;r<e;r++)t[r]=c[2*r],n[r]=c[2*r+1];return{k:`tab`,keys:t,vals:n,interp:a===4}}case 6:{let e=Math.max(0,Math.floor((s-1)/3)),t=new Float64Array(e),n=new Float64Array(e),r=new Float64Array(e);for(let i=0;i<e;i++)t[i]=c[3*i],n[i]=c[3*i+1],r[i]=c[3*i+2];return{k:`rtv`,lo:t,hi:n,vals:r,def:c[s-1]}}case 7:{let e=await u();return{k:`text`,ranges:[...c].map((t,n)=>({lo:t,hi:t,to:e[n]??null})),def:e[s]??null,int:!0}}case 8:{let e=await u(),t=s>>1;return{k:`text`,ranges:Array.from({length:t},(t,n)=>({lo:c[2*n],hi:c[2*n+1],to:e[n]??null})),def:e[t]??null,int:!0}}default:return{k:`unsupported`,what:`conversion type ${a}`}}}const ie={0:{type:`uint`,bigEndian:!1,encoding:`latin1`},1:{type:`uint`,bigEndian:!0,encoding:`latin1`},2:{type:`int`,bigEndian:!1,encoding:`latin1`},3:{type:`int`,bigEndian:!0,encoding:`latin1`},4:{type:`float`,bigEndian:!1,encoding:`latin1`},5:{type:`float`,bigEndian:!0,encoding:`latin1`},6:{type:`string`,bigEndian:!1,encoding:`latin1`},7:{type:`string`,bigEndian:!1,encoding:`utf-8`},8:{type:`string`,bigEndian:!1,encoding:`utf-16le`},9:{type:`string`,bigEndian:!0,encoding:`utf-16be`},10:{type:`bytes`,bigEndian:!1,encoding:`latin1`}};async function ae(e,t){let{io:n,notes:r}=e,i=t.data,o=i.getUint8(0),s=i.getUint8(1),c=i.getUint8(2),l=await P(e,t.links[2]),d=ie[c];if(!d)return r.push(`${l}: data type ${c} is not supported; the channel was skipped.`),null;let f;if(o===2||o===3)if(s===1)f=o===2?`master`:`vmaster`;else{if(r.push(`The master channel ${l} is not time (sync type ${s}): samples are numbered instead.`),o===3)return null;f=`value`}else if(o===1)f=`vlsd`;else if(o===0||o===4)f=`value`;else return r.push(`${l}: channel type ${o} is not supported; skipped.`),null;let p=await ne(e,t.links[4]),m=p.k===`text`?{...p,int:d.type!==`float`}:p,h=await P(e,t.links[6]);!h&&t.links[4]&&(h=await P(e,(await j(n,t.links[4])).links[1]));let g=null,_=null;f===`vlsd`&&t.links[5]&&(u(await n.read(t.links[5],4))===`##CG`?_=a((await j(n,t.links[5])).data,0):g=await ee(e,t.links[5]));let v=i.getUint32(12,!0);return{name:l,unit:h,kind:f,...d,conv:m,sd:g,sdRecordId:_,byteOffset:i.getUint32(4,!0),bitOffset:i.getUint8(3),bitCount:i.getUint32(8,!0),invalBit:v&2?i.getUint32(16,!0):null,allInvalid:(v&1)!=0}}async function oe(e,t,n,r=0){let{io:i,notes:a}=e;for(let o=t;o;){A(e,o);let t=await j(i,o),s=t.links[1];s&&r<4&&(u(await i.read(s,4))===`##CN`?await oe(e,s,n,r+1):a.push(`${await P(e,t.links[2])}: array channels (CA) are not supported yet; skipped.`));let c=await ae(e,t);c&&n.push(c),o=t.links[0]}}async function se(e,t,n,r){let i=t.data,o=i.getUint16(16,!0),s=0;t.links[3]&&(s=(await j(e.io,t.links[3])).data.getUint8(1));let c={name:await P(e,t.links[2]),dg:n,recordId:a(i,0),recordIdSize:r,idTrailer:0,dataBytes:i.getUint32(24,!0),invalBytes:i.getUint32(28,!0),cycles:a(i,8),vlsdCg:(o&1)!=0,sorted:!0,master:null,channels:[],stream:[],busType:s,busEvent:(o&2)!=0};if(c.vlsdCg)return c;let l=[];await oe(e,t.links[1],l);for(let e of l)e.kind===`master`||e.kind===`vmaster`?c.master||=e:c.channels.push(e);return c}async function ce(e,t){let n=await j(e,64);if(n.id!==`##HD`)throw Error(`This MF4 is damaged (no header block).`);let r=a(n.data,0),i=(n.data.getUint8(12)&1)!=0,o=new Date(r/1e6).toISOString(),s=r>0?i?o.slice(0,-1):o:null,c={io:e,notes:[],seen:new Set,texts:new Map,convs:new Map,busy:new Set},l=[],u=0;for(let t=n.links[0],r=0;t;r++){A(c,t);let n=await j(e,t),i=n.data.getUint8(0),a=[];for(let t=n.links[1];t;){A(c,t);let n=await j(e,t),o=await se(c,n,r,i);o.vlsdCg||(u++,o.name||=`Group ${u}`),a.push(o),t=n.links[0]}let o=await ee(c,n.links[2]),s=a.length===1;for(let e of a)e.stream=o,e.sorted=s,l.push(e);t=n.links[0]}return{version:`MF4 ${t}`,startTime:s,groups:l,notes:c.notes,meta:{}}}function le(e){let t=e&32768?-1:1,n=e>>10&31,r=e&1023;return n===0?t*2**-14*(r/1024):n===31?r?NaN:t*(1/0):t*2**(n-15)*(1+r/1024)}function ue(e,t,n,r,a,o,s=0){let c=i(t),l=!e.bigEndian,u=a+e.byteOffset,d=e.bitCount;if(e.bitOffset===0)if(e.type===`float`){if(d===64){for(let e=0;e<n;e++,u+=r)o[s+e]=c.getFloat64(u,l);return}if(d===32){for(let e=0;e<n;e++,u+=r)o[s+e]=c.getFloat32(u,l);return}if(d===16){for(let e=0;e<n;e++,u+=r)o[s+e]=le(c.getUint16(u,l));return}}else if(e.type===`int`){if(d===8){for(let e=0;e<n;e++,u+=r)o[s+e]=c.getInt8(u);return}if(d===16){for(let e=0;e<n;e++,u+=r)o[s+e]=c.getInt16(u,l);return}if(d===32){for(let e=0;e<n;e++,u+=r)o[s+e]=c.getInt32(u,l);return}if(d===64){for(let e=0;e<n;e++,u+=r)o[s+e]=c.getInt32(u+(l?4:0),l)*4294967296+c.getUint32(u+(l?0:4),l);return}}else{if(d===8){for(let e=0;e<n;e++,u+=r)o[s+e]=t[u];return}if(d===16){for(let e=0;e<n;e++,u+=r)o[s+e]=c.getUint16(u,l);return}if(d===32){for(let e=0;e<n;e++,u+=r)o[s+e]=c.getUint32(u,l);return}if(d===64){for(let e=0;e<n;e++,u+=r)o[s+e]=c.getUint32(u+(l?4:0),l)*4294967296+c.getUint32(u+(l?0:4),l);return}}let f=e.bitOffset+d+7>>3,p=2**e.bitOffset,m=2**d,h=m/2,g=e.type===`int`;for(let e=0;e<n;e++,u+=r){let n=0;if(l)for(let e=f-1;e>=0;e--)n=n*256+t[u+e];else for(let e=0;e<f;e++)n=n*256+t[u+e];n=Math.floor(n/p)%m,o[s+e]=g&&n>=h?n-m:n}}const de=new Map,fe=e=>{let t=de.get(e);return t||de.set(e,t=new TextDecoder(e)),t};function pe(e){let t=e.indexOf(`\0`);return t<0?e:e.slice(0,t)}function me(e,t,n,r,i){let a=fe(e.encoding),o=e.bitCount>>3,s=Array(n);for(let c=0,l=i+e.byteOffset;c<n;c++,l+=r)s[c]=pe(a.decode(t.subarray(l,l+o)));return s}function he(e,t,n,r,i,a){let o=a instanceof Float64Array?NaN:null;if(e.allInvalid){for(let e=0;e<n;e++)a[e]=o;return}if(e.invalBit===null)return;let s=1<<(e.invalBit&7);for(let c=0,l=i+(e.invalBit>>3);c<n;c++,l+=r)t[l]&s&&(a[c]=o)}const ge={id:`mdf`,label:`ASAM MDF (MF4, MDF 3)`,extensions:[`.mf4`,`.mdf`,`.mf3`,`.dat`],companions:[{ext:`.dbc`,anyName:!0}],sniff:e=>f(e,`MDF `)||f(e,`UnFinMF `)},_e=e=>e.recordIdSize+e.dataBytes+e.invalBytes+e.idTrailer,ve=(e,t)=>e.reduce((e,n)=>e+(n.zip?n.zip.orgLength:Math.max(0,Math.min(n.length,t-n.offset))),0),ye=e=>e.byteOffset+Math.ceil((e.bitOffset+e.bitCount)/8);function be(e,t){return e.kind===`vmaster`?!0:(e.kind===`vlsd`||e.type===`uint`||e.type===`int`||e.type===`float`?!(e.bitCount>=1&&e.bitCount<=64):!(e.bitCount>=8))?!1:ye(e)<=t.dataBytes}function xe(e,t){let n=e.notes;for(let r of e.groups){if(![0,1,2,4,8].includes(r.recordIdSize))throw Error(`This MDF file is damaged (bad record id size).`);if(r.vlsdCg)continue;let e=_e(r);if(e>67108864||e===0){r.cycles>0&&n.push(`${r.name||`A group`}: its records are ${e===0?`empty`:`too large`} (damaged); skipped.`),r.cycles=0;continue}r.cycles=Math.min(r.cycles,Math.floor(ve(r.stream,t)/e));let i=r.channels.filter(e=>!be(e,r));for(let e of i)n.push(`${e.name}: its bits lie outside its record (damaged); skipped.`);i.length&&(r.channels=r.channels.filter(e=>!i.includes(e))),r.master&&!be(r.master,r)&&(n.push(`${r.master.name}: the time channel lies outside its record (damaged): samples are numbered instead.`),r.master=null);for(let e of r.master?[...r.channels,r.master]:r.channels)e.invalBit!==null&&e.invalBit>=8*r.invalBytes&&(e.invalBit=null)}}function Se(e,t){let n=0;for(let r of e.master?[...t,e.master]:t){if(r.invalBit!==null)return 1/0;r.kind!==`vmaster`&&(n=Math.max(n,r.byteOffset+(r.bitOffset+r.bitCount+7>>3)))}return e.recordIdSize+n}var Ce=Uint8Array,we=Uint16Array,Te=Int32Array,Ee=new Ce([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]),De=new Ce([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]),Oe=new Ce([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),ke=function(e,t){for(var n=new we(31),r=0;r<31;++r)n[r]=t+=1<<e[r-1];for(var i=new Te(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}},Ae=ke(Ee,2),je=Ae.b,Me=Ae.r;je[28]=258,Me[258]=28;var Ne=ke(De,0),Pe=Ne.b;Ne.r;for(var Fe=new we(32768),F=0;F<32768;++F){var Ie=(F&43690)>>1|(F&21845)<<1;Ie=(Ie&52428)>>2|(Ie&13107)<<2,Ie=(Ie&61680)>>4|(Ie&3855)<<4,Fe[F]=((Ie&65280)>>8|(Ie&255)<<8)>>1}for(var Le=(function(e,t,n){for(var r=e.length,i=0,a=new we(t);i<r;++i)e[i]&&++a[e[i]-1];var o=new we(t);for(i=1;i<t;++i)o[i]=o[i-1]+a[i-1]<<1;var s;if(n){s=new we(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[Fe[d]>>c]=l}else for(s=new we(r),i=0;i<r;++i)e[i]&&(s[i]=Fe[o[e[i]-1]++]>>15-e[i]);return s}),Re=new Ce(288),F=0;F<144;++F)Re[F]=8;for(var F=144;F<256;++F)Re[F]=9;for(var F=256;F<280;++F)Re[F]=7;for(var F=280;F<288;++F)Re[F]=8;for(var ze=new Ce(32),F=0;F<32;++F)ze[F]=5;var Be=Le(Re,9,1),Ve=Le(ze,5,1),He=function(e){for(var t=e[0],n=1;n<e.length;++n)e[n]>t&&(t=e[n]);return t},Ue=function(e,t,n){var r=t/8|0;return(e[r]|e[r+1]<<8)>>(t&7)&n},We=function(e,t){var n=t/8|0;return(e[n]|e[n+1]<<8|e[n+2]<<16)>>(t&7)},Ge=function(e){return(e+7)/8|0},Ke=function(e,t,n){return(t==null||t<0)&&(t=0),(n==null||n>e.length)&&(n=e.length),new Ce(e.subarray(t,n))},qe=[`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`],Je=function(e,t,n){var r=Error(t||qe[e]);if(r.code=e,Error.captureStackTrace&&Error.captureStackTrace(r,Je),!n)throw r;return r},Ye=function(e,t,n,r){var i=e.length,a=r?r.length:0;if(!i||t.f&&!t.l)return n||new Ce(0);var o=!n,s=o||t.i!=2,c=t.i;o&&(n=new Ce(i*3));var l=function(e){var t=n.length;if(e>t){var r=new Ce(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=Ue(e,d,1);var v=Ue(e,d+1,3);if(d+=3,!v){var y=Ge(d)+4,b=e[y-4]|e[y-3]<<8,x=y+b;if(x>i){c&&Je(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=Be,m=Ve,h=9,g=5;else if(v==2){var S=Ue(e,d,31)+257,C=Ue(e,d+10,15)+4,w=S+Ue(e,d+5,31)+1;d+=14;for(var T=new Ce(w),E=new Ce(19),D=0;D<C;++D)E[Oe[D]]=Ue(e,d+D*3,7);d+=C*3;for(var O=He(E),k=(1<<O)-1,A=Le(E,O,1),D=0;D<w;){var j=A[Ue(e,d,k)];d+=j&15;var y=j>>4;if(y<16)T[D++]=y;else{var M=0,N=0;for(y==16?(N=3+Ue(e,d,3),d+=2,M=T[D-1]):y==17?(N=3+Ue(e,d,7),d+=3):y==18&&(N=11+Ue(e,d,127),d+=7);N--;)T[D++]=M}}var P=T.subarray(0,S),ee=T.subarray(S);h=He(P),g=He(ee),p=Le(P,h,1),m=Le(ee,g,1)}else Je(1);if(d>_){c&&Je(0);break}}s&&l(f+131072);for(var te=(1<<h)-1,ne=(1<<g)-1,re=d;;re=d){var M=p[We(e,d)&te],ie=M>>4;if(d+=M&15,d>_){c&&Je(0);break}if(M||Je(2),ie<256)n[f++]=ie;else if(ie==256){re=d,p=null;break}else{var ae=ie-254;if(ie>264){var D=ie-257,oe=Ee[D];ae=Ue(e,d,(1<<oe)-1)+je[D],d+=oe}var se=m[We(e,d)&ne],ce=se>>4;se||Je(3),d+=se&15;var ee=Pe[ce];if(ce>3){var oe=De[ce];ee+=We(e,d)&(1<<oe)-1,d+=oe}if(d>_){c&&Je(0);break}s&&l(f+131072);var le=f+ae;if(f<ee){var ue=a-ee,de=Math.min(ee,le);for(ue+f<0&&Je(3);f<de;++f)n[f]=r[ue+f]}for(;f<le;++f)n[f]=n[f-ee]}}t.l=p,t.p=re,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?Ke(n,0,f):n.subarray(0,f)},Xe=new Ce(0),Ze=function(e,t){return((e[0]&15)!=8||e[0]>>4>7||(e[0]<<8|e[1])%31)&&Je(6,`invalid zlib data`),(e[1]>>5&1)==+!t&&Je(6,`invalid zlib data: `+(e[1]&32?`need`:`unexpected`)+` dictionary`),(e[1]>>3&4)+2},Qe=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 Ce(32768),this.p=new Ce(0),n&&this.o.set(n)}return e.prototype.e=function(e){if(this.ondata||Je(5),this.d&&Je(4),!this.p.length)this.p=e;else if(e.length){var t=new Ce(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=Ye(this.p,this.s,this.o);this.ondata(Ke(n,t,this.s.b),this.d),this.o=Ke(n,this.s.b-32768),this.s.b=this.o.length,this.p=Ke(this.p,this.s.p/8|0),this.s.p&=7},e.prototype.push=function(e,t){this.e(e),this.c(t)},e}(),$e=function(){function e(e,t){Qe.call(this,e,t),this.v=e&&e.dictionary?2:1}return e.prototype.push=function(e,t){if(Qe.prototype.e.call(this,e),this.v){if(this.p.length<6&&!t)return;this.p=this.p.subarray(Ze(this.p,this.v-1)),this.v=0}t&&(this.p.length<4&&Je(6,`invalid zlib data`),this.p=this.p.subarray(0,-4)),Qe.prototype.c.call(this,t)},e}(),et=typeof TextDecoder<`u`&&new TextDecoder;try{et.decode(Xe,{stream:!0})}catch{}const tt=65536;async function*nt(e){for(let t=0;t<e.length;t+=tt)yield e.subarray(t,t+tt)}async function*rt(e){if(typeof DecompressionStream!=`function`){let t=[],n=new $e(e=>{t.push(e)});for await(let r of e)for(n.push(r,!1);t.length;)yield t.shift();for(n.push(new Uint8Array,!0);t.length;)yield t.shift();return}let t=new DecompressionStream(`deflate`),n=t.writable.getWriter();(async()=>{for await(let t of e)await n.write(t);await n.close()})().catch(e=>n.abort(e).catch(()=>{}));let r=t.readable.getReader();try{for(;;){let{done:e,value:t}=await r.read().catch(e=>{throw e instanceof TypeError?Error(`This file's compressed data is damaged.`):e});if(e)return;yield t}}finally{r.cancel().catch(()=>{})}}async function it(e,t=-1,n=1/0){let r=[],i=Math.min(t,n),a=t>=0?new Uint8Array(i):null,o=0;for await(let s of rt(nt(e))){if(a){if(o+s.length>t&&n>t)throw Error(`Compressed data is longer than its header says.`);a.set(o+s.length>i?s.subarray(0,i-o):s,o)}else r.push(s);if(o+=s.length,o>=n)break}if(a)return o>=i?a:a.subarray(0,o);let s=r.length===1?r[0]:new Uint8Array(o);return r.length>1&&r.reduce((e,t)=>(s.set(t,e),e+t.length),0),o>n?s.subarray(0,n):s}const at=new Uint8Array(Uint32Array.of(1).buffer)[0]===1;function ot(e,t,n,r=t){let i=Math.floor(n/t),a=new Uint8Array(r<t?i*r:n),o=r%4==0&&at?new Uint32Array(a.buffer,0,i*r>>2):null,s=r>>2;for(let t=0;t<i;t+=512){let n=Math.min(i,t+512);if(o)for(let a=0;a<r;a+=4){let r=a*i,c=r+i,l=c+i,u=l+i;for(let i=t,d=t*s+(a>>2);i<n;i++,d+=s)o[d]=e[r+i]|e[c+i]<<8|e[l+i]<<16|e[u+i]<<24}else for(let o=0;o<r;o++){let s=o*i;for(let i=t,c=t*r+o;i<n;i++,c+=r)a[c]=e[s+i]}}let c=i*t;return r===t&&a.set(e.subarray(c,n),c),a}function st(e,t,n){if(!(n<t)||e.length===0)return t;let r=Math.min(t,n+3&-4);return r===t?t:e.every(e=>e.zip?.type===1&&e.zip.param===t&&e.zip.orgLength%t===0)?r:t}async function ct(e,t,n=1/0,r=1/0){let i=await e.slice(t.offset,t.length),{type:a,param:o,orgLength:s}=t.zip;if(a===0)return it(i,s,r);let c=Math.min(n,o);return ot(await it(i,s,c<o?s/o*c:1/0),o,s,c)}async function*lt(e,t,n,r=1/0){let i=e=>!!e?.zip&&!(e.zip.type===0&&(e.length>16777216||e.zip.orgLength>268435456)),a=null;for(let o=0;o<t.length;o++){let s=t[o];if(n?.throwIfAborted(),!s.zip)for await(let t of e.windows(s.offset,s.length))yield t.bytes;else if(i(s)){let n=a??ct(e,s,r);a=i(t[o+1])?ct(e,t[o+1],r):null,a?.catch(()=>{}),yield await n}else{let t=s.zip.orgLength;for await(let n of rt((async function*(){for await(let t of e.windows(s.offset,s.length))yield t.bytes})()))if(yield n.length>t?n.subarray(0,t):n,(t-=n.length)<=0)break}}}async function*ut(e,t,n,r){if(r<=0||t<=0)return;let i=Math.min(n,r),a=null,o=0,s=0;for await(let n of e){let e=0;for(;e<n.length&&s<r;){if(o===0){let a=Math.min(i,r-s,Math.floor((n.length-e)/t));if(a>0){yield{buf:n.subarray(e,e+a*t),n:a},s+=a,e+=a*t;continue}}a??=new Uint8Array(t*i);let c=Math.min(a.length,(r-s)*t),l=Math.min(n.length-e,c-o);if(a.set(n.subarray(e,e+l),o),o+=l,e+=l,o===c){let e=o/t;yield{buf:a,n:e},s+=e,o=0}}if(s>=r)return}a&&o>=t&&(yield{buf:a,n:Math.floor(o/t)})}async function dt(e,t,n,r){let i=n*r,a=0;for(let n of t){let t=n.zip?n.zip.orgLength:n.length;if(i<a)return null;if(i+r<=a+t)return n.zip?null:e.read(n.offset+i-a,r);a+=t}return null}const ft=(e,t)=>(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0;var pt=class{#e;#t;#n;#r;#i=new Uint8Array;#a=0;#o;#s=0;constructor(e,t,n){this.#e=e,this.#t=t,this.#n=n,this.#r=lt(e,t,n),this.#o=t.reduce((e,t)=>e+(t.zip?t.zip.orgLength:t.length),0)}peek(e){let t=e-this.#a;if(t<0||t+4>this.#i.length)return null;let n=ft(this.#i,t);return t+4+n>this.#i.length?null:this.#i.subarray(t+4,t+4+n)}async get(e){for(;;){let t=this.peek(e);if(t)return t;let n=e-this.#a;if(e+4>this.#o||n>=0&&n+4<=this.#i.length&&e+4+ft(this.#i,n)>this.#o)throw Error(`This MF4 is damaged (string data ends early).`);e<this.#a&&(this.#r=lt(this.#e,this.#t,this.#n),this.#i=new Uint8Array,this.#a=0);let r=await this.#r.next();if(r.done)throw Error(`This MF4 is damaged (string data ends early).`);if((this.#s+=r.value.length)>4*this.#o+16777216)throw Error(`This MF4 is damaged (its string offsets jump back and forth).`);let i=Math.max(0,Math.min(e-this.#a,this.#i.length)),a=this.#i.subarray(i),o=new Uint8Array(a.length+r.value.length);o.set(a),o.set(r.value,a.length),this.#a+=i,this.#i=o}}};const mt=e=>Math.max(1,Math.min(65536,Math.floor((8<<20)/Math.max(1,e))));var ht=class{#e;#t;#n=new Map;#r=new Map;constructor(e,t){this.#e=e,this.#t=t}want(e){this.#r.has(e)||this.#r.set(e,new Map)}wanted(e){return this.#r.has(e)}put(e,t,n){this.#r.get(e).set(t,n)}async bytes(e,t){let n=Array(t.length);if(e.sdRecordId!==null){let r=this.#r.get(e.sdRecordId);for(let e=0;e<t.length;e++)n[e]=r?.get(t[e])??null,r?.delete(t[e]);return n}if(!e.sd)return n.fill(null);let r=this.#n.get(e);r||this.#n.set(e,r=new pt(this.#e,e.sd,this.#t));for(let e=0;e<t.length;e++)n[e]=r.peek(t[e])??await r.get(t[e]);return n}async strings(e,t){let n=fe(e.encoding);return(await this.bytes(e,t)).map(e=>e?pe(n.decode(e)):null)}};function gt(e,t,n,r,i=_e(e),a=new Float64Array(n)){let o=e.master;if(!o)return null;if(o.kind===`vmaster`)for(let e=0;e<n;e++)a[e]=r+e;else ue(o,t,n,i,e.recordIdSize,a);return v(o.conv,a),a}function _t(e,t,n){return n===1?e[t]:n===2?e[t]|e[t+1]<<8:n===4?(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0:((e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0)+4294967296*((e[t+4]|e[t+5]<<8|e[t+6]<<16|e[t+7]<<24)>>>0)}function vt(e,t){let n=new Uint8Array(e.length+t.length);return n.set(e),n.set(t,e.length),n}async function*yt(e,t,n,r,i,a=1/0){let o=t.groups[n[0]];if(o.sorted){let t=st(o.stream,_e(o),a),r=0;for await(let{buf:a,n:s}of ut(lt(e,o.stream,i,t),t,mt(t),o.cycles))yield{g:n[0],buf:a,n:s,start:r,size:t},r+=s;return}let s=t.groups.map((e,t)=>({g:e,k:t})).filter(({g:e})=>e.dg===o.dg),c=o.recordIdSize,l=new Map;for(let e of n){let n=t.groups[e],r=_e(n);l.set(n.recordId,{k:e,size:r,buf:new Uint8Array(r*Math.min(mt(r),Math.max(1,n.cycles))),fill:0,start:0})}let u=new Map(s.map(({g:e})=>[e.recordId,e.vlsdCg?-1:_e(e)])),d=new Map,f=new Uint8Array;for await(let t of lt(e,o.stream,i)){let e=f.length?vt(f,t):t,n=0;for(;!(n+c>e.length);){let t=_t(e,n,c),i=u.get(t);if(i===void 0)throw Error(`This MF4 is damaged (unknown record id ${t}).`);if(i<0){if(n+c+4>e.length)break;let i=(e[n+c]|e[n+c+1]<<8|e[n+c+2]<<16|e[n+c+3]<<24)>>>0;if(i>67108864)throw Error(`This MF4 is damaged (a string record of ${i} bytes).`);let a=n+c+4+i;if(a>e.length)break;let o=d.get(t)??0;r.wanted(t)&&r.put(t,o,e.slice(n+c+4,a)),d.set(t,o+4+i),n=a;continue}if(n+i>e.length)break;let a=l.get(t);if(a&&(a.buf.set(e.subarray(n,n+i),a.fill),a.fill+=i,a.fill===a.buf.length)){let e=a.fill/a.size;yield{g:a.k,buf:a.buf,n:e,start:a.start,size:a.size},a.start+=e,a.fill=0}n+=i}f=e.slice(n)}for(let e of l.values())e.fill&&(yield{g:e.k,buf:e.buf,n:e.fill/e.size,start:e.start,size:e.size})}const bt=(e,t)=>t?e+2147483648:e,xt=/^BO_\s+(\d+)\s+(\w+)\s*:\s*(\d+)/,St=/^SG_\s+(\w+)\s*(?:(M|m\d+M?)\s*)?:\s*(\d+)\|(\d+)@([01])([+-])\s*\(([^,)]*),([^)]*)\)\s*\[[^\]]*\]\s*"([^"]*)"/,Ct=/^VAL_\s+(\d+)\s+(\w+)\s+(.*);/,wt=/^SIG_VALTYPE_\s+(\d+)\s+(\w+)\s*:\s*([12])\s*;/,Tt=/^-?\d+(?:\.\d+)?$/;function Et(e){let t=e.split(`"`),n=new Map;for(let e=0;e+1<t.length;e+=2){let r=t[e].trim();Tt.test(r)&&n.set(Number(r),t[e+1])}return n}const Dt=(e,t)=>e<=511&&t>=1&&t<=64;function Ot(e){let t=new Map,n=new Map,r=new Map,i=(e,t)=>{let i=n.get(Number(e));return i?r.get(i)?.get(t):void 0},a=null;for(let o of e.split(/\r?\n/)){let e=o.trim(),s;if(s=xt.exec(e)){let e=Number(s[1]),r=e>=2147483648,i=r?e-2147483648:e;a={id:i,extended:r,name:s[2],size:Number(s[3]),signals:[]},t.set(bt(i,r),a),n.set(e,a)}else if((s=St.exec(e))&&a){let e=s[2],t=Number(s[3]),n=Number(s[4]);if(!Dt(t,n)||!s[7].trim()||!s[8].trim())continue;let i={name:s[1],start:t,length:n,littleEndian:s[5]===`1`,signed:s[6]===`-`,factor:Number(s[7]),offset:Number(s[8]),unit:s[9],mux:e?e===`M`?`switch`:parseInt(e.slice(1),10):null,float:0,values:null};a.signals.push(i);let o=r.get(a);o||r.set(a,o=new Map),o.has(i.name)||o.set(i.name,i)}else if(s=Ct.exec(e)){let e=i(s[1],s[2]);e&&(e.values=Et(s[3]))}else if(s=wt.exec(e)){let e=i(s[1],s[2]);e&&(e.float=s[3]===`1`?32:64)}else (e.startsWith(`BO_`)||e===``)&&e===``&&(a=null)}return t}function kt(e){if(e.float){let t=e.float/8,n=e.start>>3,r=e.littleEndian,i=new DataView(new ArrayBuffer(8));return(e,a)=>{for(let r=0;r<t;r++)i.setUint8(r,e[a+n+r]??0);return t===4?i.getFloat32(0,r):i.getFloat64(0,r)}}let t=e.length,n=2**t,r=n/2,i=e.signed;if(e.littleEndian){let a=e.start>>3,o=e.start&7;if(o+t<=32){let e=t===32?-1:(1<<t)-1;return(t,s)=>{let c=s+a,l=((t[c]|t[c+1]<<8|t[c+2]<<16|t[c+3]<<24)>>>o&e)>>>0;return i&&l>=r?l-n:l}}let s=o+t+7>>3,c=2**(t-(32-o)),l=2**(32-o);return(e,t)=>{let u=t+a,d=(e[u]|e[u+1]<<8|e[u+2]<<16|e[u+3]<<24)>>>o,f=0;for(let t=s-1;t>=4;t--)f=f*256+(e[u+t]??0);let p=d+f%c*l;return i&&p>=r?p-n:p}}let a=e.start>>3,o=e.start&7;if(7-o+t<=32){let e=32-(7-o)-t,s=t===32?-1:(1<<t)-1;return(t,o)=>{let c=o+a,l=((t[c]<<24|t[c+1]<<16|t[c+2]<<8|t[c+3])>>>e&s)>>>0;return i&&l>=r?l-n:l}}let s=(1<<o+1)-1,c=t-(o+1)>>3,l=t-(o+1)&7,u=2**l;return(e,t)=>{let o=(e[t+a]??0)&s,d=t+a+1;for(let t=0;t<c;t++)o=o*256+(e[d++]??0);return l>0&&(o=o*u+((e[d]??0)>>8-l)),i&&o>=r?o-n:o}}function At(e){let t=e.length,n=2**t,r=n/2,i=e.signed,a=t===32?-1:(1<<t)-1;if(!e.float&&e.littleEndian&&(e.start&7)+t<=32){let t=e.start>>3,o=e.start&7;return(e,s,c,l,u,d,f)=>{for(let p=0;p<l;p++){let l=s[c[p]]+t,m=((e[l]|e[l+1]<<8|e[l+2]<<16|e[l+3]<<24)>>>o&a)>>>0;u[p]=(i&&m>=r?m-n:m)*d+f}}}if(!e.float&&!e.littleEndian&&7-(e.start&7)+t<=32){let o=e.start>>3,s=32-(7-(e.start&7))-t;return(e,t,c,l,u,d,f)=>{for(let p=0;p<l;p++){let l=t[c[p]]+o,m=((e[l]<<24|e[l+1]<<16|e[l+2]<<8|e[l+3])>>>s&a)>>>0;u[p]=(i&&m>=r?m-n:m)*d+f}}}let o=kt(e);return(e,t,n,r,i,a,s)=>{for(let c=0;c<r;c++)i[c]=o(e,t[n[c]])*a+s}}function jt(e){if(!e.busEvent||e.busType!==2)return null;let t=t=>e.channels.find(e=>e.name.endsWith(t))??null,n=t(`DataFrame.ID`),r=t(`DataFrame.DataBytes`);return!n||!r?null:{id:n,ide:t(`DataFrame.IDE`),data:r}}const Mt=()=>({n:0,time:new Float64Array,key:new Float64Array,id:new Float64Array,ide:new Float64Array,bytes:null,buf:new Uint8Array,dataAt:new Int32Array});async function Nt(e,t,n,r,i,a,o,s){s.key.length<r&&Object.assign(s,{time:new Float64Array(r),key:new Float64Array(r),id:new Float64Array(r),ide:new Float64Array(r),dataAt:new Int32Array(r)});let c=e.recordIdSize,{id:l,ide:u,key:d,dataAt:f}=s;ue(t.id,n,r,a,c,l),t.ide&&ue(t.ide,n,r,a,c,u);for(let e=0;e<r;e++){let n=l[e],r=n&536870911;d[e]=bt(r,t.ide?u[e]!==0:n>=2147483648||r>2047)}if(s.bytes=null,t.data.kind===`vlsd`){let e=new Float64Array(r);ue({...t.data,type:`uint`},n,r,a,c,e),s.bytes=await o.bytes(t.data,e)}else for(let e=0,n=c+t.data.byteOffset;e<r;e++,n+=a)f[e]=n;if(!gt(e,n,r,i,a,s.time.subarray(0,r)))for(let e=0;e<r;e++)s.time[e]=i+e;return s.n=r,s.buf=n,s}const Pt=new Uint8Array;function Ft(e){return e.float?(e.start>>3)+e.float/8:e.littleEndian?(e.start>>3)+((e.start&7)+e.length+7>>3):(e.start>>3)+1+(Math.max(0,e.length-((e.start&7)+1))+7>>3)}function It(e,t,n){let r=0;for(let e of n.values())for(let t of e.signals)r=Math.max(r,Ft(t));let i=t.data.kind===`vlsd`?t.data:{...t.data,bitCount:Math.min(t.data.bitCount,r*8)};return Se(e,t.ide?[t.id,t.ide,i]:[t.id,i])}function Lt(e,t){let n=t.map(t=>e.signals[e.channels[t].s]);return{route:e,col:n.map(At),read:n.map(kt),factor:n.map(e=>e.factor),offset:n.map(e=>e.offset),table:t.map((t,r)=>e.channels[t].text?n[r].values:null),idx:new Int32Array,cnt:0,n:0,t0:NaN,t1:NaN}}function Rt(e,t,n,r,i,a=1,o=0){let s=new Float64Array(i);if(n.bytes)for(let e=0;e<i;e++)s[e]=t(n.bytes[r[e]]??Pt,0)*a+o;else e(n.buf,n.dataAt,r,i,s,a,o);return s}function zt(e,t){let{idx:n,cnt:r}=e,i=new Float64Array(r);for(let e=0;e<r;e++)i[e]=t.time[n[e]];return e.n===0&&(e.t0=i[0]),e.t1=i[r-1],e.n+=r,e.cnt=0,{time:i,cols:e.col.map((i,a)=>{let o=e.table[a];return o?Array.from(Rt(i,e.read[a],t,n,r),e=>o.get(e)??null):Rt(i,e.read[a],t,n,r,e.factor[a],e.offset[a])})}}const Bt=e=>({key:e,skip:!0,frames:0,all:null,sw:null,byMux:new Map,idx:new Int32Array,cnt:0});function Vt(e,t){let n=e.signals.find(e=>e.mux===`switch`);return{key:bt(e.id,e.extended),skip:!1,frames:0,all:t,sw:n?{col:At(n),read:kt(n)}:null,byMux:new Map,idx:new Int32Array,cnt:0}}var Ht=class{#e=Array(2048);#t=new Map;#n;constructor(e){this.#n=e}get(e){let t=e<2048?this.#e[e]:this.#t.get(e);return t||(t=this.#n(e),e<2048?this.#e[e]=t:this.#t.set(e,t)),t}};function Ut(e,t,n){let r=[];for(let n=0;n<e.n;n++){let i=t.get(e.key[n]);if(i.skip){i.frames++;continue}i.cnt===0&&(r.push(i),i.idx.length<e.n&&(i.idx=new Int32Array(e.n))),i.idx[i.cnt++]=n}let i=[];for(let t of r){if(t.all&&(t.all.idx=t.idx,t.all.cnt=t.cnt,i.push(t.all)),t.sw){let r=Rt(t.sw.col,t.sw.read,e,t.idx,t.cnt);for(let e=0;e<t.cnt;e++){let a=t.byMux.get(r[e]);a===void 0&&((a=n(t,r[e]))||t.byMux.size<4096)&&t.byMux.set(r[e],a),a&&(a.cnt===0&&(i.push(a),a.idx.length<t.cnt&&(a.idx=new Int32Array(t.cnt))),a.idx[a.cnt++]=t.idx[e])}}t.cnt=0}return i}async function Wt(e,t,n,r){let i=new Map;if(t.groups.forEach((e,t)=>{let n=jt(e);n&&e.cycles>0&&i.set(t,n)}),i.size===0)return null;if(n.length===0)return{dbc:new Map,layouts:i,routes:[],notes:[],cache:new Map};let a=Ot(d(new Uint8Array(await n[0].arrayBuffer()))),o=[],s=new Map,c=new Map,l=0,u=new ht(e,r);for(let[n,d]of i){let i=t.groups[n],f=(e,t)=>{let n=e.signals.filter(e=>t===null?typeof e.mux!=`number`:e.mux===t),r=[];return n.forEach((e,t)=>{r.push({s:t,text:!1}),e.values&&r.push({s:t,text:!0})}),Lt({key:bt(e.id,e.extended),mux:t,signals:n,channels:r},r.map((e,t)=>t))},p=new Ht(e=>{let t=a.get(e);if(!t){let t=Bt(e);return s.set(e,t),t}let r=Vt(t,f(t,null));return o.push({model:n,m:r}),r});d.data.sdRecordId!==null&&u.want(d.data.sdRecordId);let m=Mt();for await(let o of yt(e,t,[n],u,r,It(i,d,a))){let e=await Nt(i,d,o.buf,o.n,o.start,o.size,u,m),t=(e,t)=>{let n=a.get(e.key);return n.signals.some(e=>e.mux===t)?f(n,t):null};for(let n of Ut(e,p,t)){let t=zt(n,e);if(l<0)continue;if((l+=t.time.length*(1+t.cols.length))>48e6){l=-1,c.clear();continue}let r=c.get(n);r||c.set(n,r=[]),r.push(t)}}}let f=[],p=new Map;for(let{model:e,m:t}of o)for(let n of[t.all,...t.byMux.values()]){if(!n)continue;let{route:t,n:r,t0:i,t1:o}=n;if(t.signals.length===0)continue;let s=a.get(t.key);l>=0&&p.set(t,c.get(n)??[]),f.push({model:e,route:t,group:{name:t.mux===null?s.name:`${s.name} [m=${t.mux}]`,channels:t.channels.map(e=>({name:e.text?`${t.signals[e.s].name} (text)`:t.signals[e.s].name,unit:e.text?``:t.signals[e.s].unit,text:e.text})),samples:r,time:{kind:`timestamps`},rateHz:r>1&&o>i?Math.round((r-1)/(o-i)*1e6)/1e6:null}})}let m=[];if(s.size){let e=[...s.values()].reduce((e,t)=>e+t.frames,0),t=[...s.keys()].map(e=>`0x${(e%2147483648).toString(16).toUpperCase()}`).join(`, `);m.push(`${e} frame${e===1?``:`s`} with ${s.size} id${s.size===1?``:`s`} not in the DBC ${e===1?`was`:`were`} skipped (${t}).`)}return{dbc:a,layouts:i,routes:f,notes:m,cache:p}}async function*Gt(e,t,n,r,i,a){let o=[];for(let e of i){let t=r.cache.get(e.route);if(!t){o.push(e);continue}r.cache.delete(e.route);let n=0;for(let r of t)yield{group:e.group,start:n,length:r.time.length,time:r.time,columns:e.sel.map(e=>r.cols[e])},n+=r.time.length}if(!o.length)return;let s=r.layouts.get(n),c=t.groups[n],l=new Map,u=new Map;for(let e of o){let t=Lt(e.route,e.sel);l.set(t,e.group);let n=u.get(e.route.key);n||u.set(e.route.key,n={all:null,byMux:new Map}),e.route.mux===null?n.all=t:n.byMux.set(e.route.mux,t)}let d=new Ht(e=>{let t=u.get(e);if(!t)return Bt(e);let n=Vt(r.dbc.get(e),t.all);return t.byMux.size||(n.sw=null),n}),f=new ht(e,a);s.data.sdRecordId!==null&&f.want(s.data.sdRecordId);let p=Mt();for await(let i of yt(e,t,[n],f,a,It(c,s,r.dbc))){let e=await Nt(c,s,i.buf,i.n,i.start,i.size,f,p);for(let t of Ut(e,d,(e,t)=>u.get(e.key).byMux.get(t)??null)){let n=t.n,r=zt(t,e);yield{group:l.get(t),start:n,length:r.time.length,time:r.time,columns:r.cols}}}}const Kt=e=>Math.round(e*1e6)/1e6,qt=e=>e.kind===`value`?e.type!==`bytes`:e.kind===`vlsd`&&e.type===`string`,Jt=e=>({name:e.name,unit:e.unit,text:e.type===`string`||e.kind===`vlsd`||e.conv.k===`text`});async function Yt(e,t){let n=t.master;if(!n||t.cycles<2)return null;if(n.kind===`vmaster`)return n.conv.k===`lin`&&n.conv.a>0?Kt(1/n.conv.a):null;if(!t.sorted)return null;let r=_e(t),i=t.cycles,a,o;if(t.stream[0]?.zip){let n=st(t.stream.slice(0,1),r,Se(t,[])),s=await ct(e,t.stream[0],n,4096*r);if(i=Math.min(t.cycles,Math.floor(s.length/n)),i<2)return null;a=s.subarray(0,n),o=s.subarray((i-1)*n,i*n)}else a=await dt(e,t.stream,0,r),o=await dt(e,t.stream,t.cycles-1,r);if(!a||!o)return null;let s=new Float64Array(2);return ue(n,a,1,r,t.recordIdSize,s,0),ue(n,o,1,r,t.recordIdSize,s,1),v(n.conv,s),s[1]>s[0]?Kt((i-1)/(s[1]-s[0])):null}async function Xt(e,t,n,r,i,a,o){let s;if(e.kind===`vlsd`){let a=new Float64Array(n);ue({...e,type:`uint`},t,n,r,i,a),s=await o.strings(e,a)}else if(e.type===`string`)s=me(e,t,n,r,i);else{let a=new Float64Array(n);ue(e,t,n,r,i,a),e.conv.k===`text`?s=x(e.conv,a):(v(e.conv,a),s=a)}return he(e,t,n,r,a,s),s}async function Zt(e,t,n,r,i,a,o,s){let c=e.recordIdSize,l=[];for(let i of t)l.push(await Xt(e.channels[i],n,r,a,c,c+e.dataBytes,s));return{group:o,time:gt(e,n,r,i,a),start:i,length:r,columns:l}}async function*Qt(e,t){let n=e.plan.state,r=t.filter(e=>n.groups[e].route),i=t.filter(e=>!n.groups[e].route);if(r.length){let t=r.map(t=>({group:t,route:n.groups[t].route,sel:p(e,t)}));yield*Gt(e.io,n.model,n.groups[r[0]].model,n.bus,t,e.signal)}if(!i.length)return;let a=new ht(e.io,e.signal),o=new Map;for(let t of i){let r=n.groups[t],i=p(e,t).map(e=>r.channels[e]);for(let e of i){let t=n.model.groups[r.model].channels[e].sdRecordId;t!==null&&a.want(t)}o.set(r.model,{pg:t,cols:i})}let[s,{cols:c}]=o.entries().next().value,l=n.model.groups[s],u=o.size===1?Se(l,c.map(e=>l.channels[e])):1/0;for await(let t of yt(e.io,n.model,[...o.keys()],a,e.signal,u)){let{pg:e,cols:r}=o.get(t.g);yield await Zt(n.model.groups[t.g],r,t.buf,t.n,t.start,t.size,e,a)}}function $t(e){let t=e.plan.state,n=new Map;for(let r of e.selection){let e=t.model.groups[t.groups[r.group].model].dg;n.set(e,[...n.get(e)??[],r.group])}return[...n].sort((e,t)=>e[0]-t[0]).map(([,e])=>e)}const en={...ge,async plan(e,t){let n=await t.read(0,64);if(f(n,`UnFinMF`))throw Error(`This MF4 was not finalized by its logger (it starts with UnFinMF). Finalize it with the logger software or asammdf, then open it again.`);let r=u(n.subarray(8,16)).replace(/\0/g,``).trim(),i=Number(r.replace(`.`,``).slice(0,3))>=400?await ce(t,r):await C(t,n,r);xe(i,t.size);let a=await Wt(t,i,e.companions.filter(e=>e.name.toLowerCase().endsWith(`.dbc`))),o=new Set(a?.layouts.keys()??[]),s=[],c=[],l=[...i.notes],d=0;for(let e=0;e<i.groups.length;e++){let n=i.groups[e];if(n.vlsdCg||n.cycles===0||o.has(e))continue;let r=[];if(n.channels.forEach((e,t)=>{qt(e)?r.push(t):d++}),r.length!==0){for(let e of r){let t=n.channels[e].conv;t.k===`unsupported`&&l.push(`${n.channels[e].name}: ${t.what} is not supported; raw values are shown.`)}c.push({model:e,channels:r}),s.push({name:n.name,channels:r.map(e=>Jt(n.channels[e])),samples:n.cycles,time:n.master?{kind:`timestamps`}:{kind:`index`},rateHz:await Yt(t,n)})}}if(d&&l.push(`${d} byte-array channel${d===1?` was`:`s were`} skipped.`),a){if(a.routes.length===0&&a.dbc.size===0){if(s.length===0)throw Error(`This MF4 has raw CAN frames. Drop its .dbc file together with it to decode signals.`);l.push(`This MF4 also has raw CAN frames. Drop its .dbc file together with it to decode signals.`)}for(let e of a.routes)c.push({model:e.model,route:e.route}),s.push(e.group);l.push(...a.notes)}if(s.length===0)throw Error(`This MDF file has no channels with samples.`);let p={model:i,groups:c,bus:a};return{format:i.version,startTime:i.startTime,groups:s,meta:i.meta,events:[],notes:l,interleaved:!!a?.routes.length||i.groups.some(e=>!e.sorted&&!e.vlsdCg),state:p}},async*stream(e){for(let t of $t(e))yield*Qt(e,t)},streamGroup(e,t){return Qt(e,[t])}},tn={id:`edf`,label:`EDF / BDF (+)`,extensions:[`.edf`,`.bdf`,`.rec`],sniff:e=>f(e,`0 `)||e[0]===255&&f(e,`BIOSEMI`,1)};function nn(e){let t=[];for(let n of d(e).split(`\0`)){if(!n)continue;let e=n.split(``),r=parseFloat(e[0].split(``)[0]);Number.isFinite(r)&&t.push({onset:r,texts:e.slice(1).filter(e=>e.length>0)})}return t}function rn(e,t){let n=/^(\d\d)\.(\d\d)\.(\d\d)$/.exec(e),r=/^(\d\d)\.(\d\d)\.(\d\d)$/.exec(t);if(!n||!r)return null;let i=Number(n[3]);return`${i>=85?1900+i:2e3+i}-${n[2]}-${n[1]}T${r[1]}:${r[2]}:${r[3]}`}const an=e=>`${+e.toFixed(6)} Hz`;function on(e,t,n,r,i,a,o,s){let{bit:c,off:l}=e;if(a===2)for(let e=0;e<i;e++)o[s+e]=c*(l+t.getInt16(r+2*e,!0));else for(let e=0,t=r;e<i;e++,t+=3)o[s+e]=c*(l+((n[t]|n[t+1]<<8|n[t+2]<<16)<<8>>8))}const sn={...tn,async plan(e,t){let n=await t.read(0,256),r=(e,t)=>u(n.subarray(e,e+t)).trim(),i=n[0]===255,a=parseInt(r(252,4),10),o=parseInt(r(184,8),10),s=r(192,44),c=/^(EDF|BDF)\+/.test(s),l=/^(EDF|BDF)\+D/.test(s),d=parseFloat(r(244,8));if(!(a>0)||o!==256*(a+1)||!(d>0))throw Error(`This EDF/BDF header is damaged.`);let f=await t.read(256,a*256),p=(e,t,n)=>u(f.subarray(e*a+t*n,e*a+t*(n+1))).trim(),m=i?3:2,h=[],g=0;for(let e=0;e<a;e++){let t=parseFloat(p(104,8,e)),n=parseFloat(p(112,8,e)),r=parseFloat(p(120,8,e)),i=parseFloat(p(128,8,e)),a=Number(p(216,8,e));if(!(Number.isInteger(a)&&a>=0))throw Error(`This EDF/BDF header is damaged (samples per record).`);let o=(n-t)/(i-r);h.push({label:p(0,16,e),unit:p(96,8,e),spr:a,offset:g,bit:o,off:n/o-i}),g+=a*m}let _=g;if(!(_>0&&o+_<=t.size))throw Error(`This EDF/BDF file is damaged (its data records do not fit in it).`);let v=Math.floor((t.size-o)/_),y=parseInt(r(236,8),10),b=[];y>=0?y>v&&(b.push(`The file is shorter than its header says: ${v} of ${y} data records were read.`),y=v):y=v;let x=c?h.flatMap((e,t)=>/^(EDF|BDF) Annotations$/.test(e.label)?[t]:[]):[],S=new Map;h.forEach((e,t)=>{!x.includes(t)&&e.spr>0&&S.set(e.spr,[...S.get(e.spr)??[],t])});let C=[...S.values()],w=C.map(e=>{let t=h[e[0]].spr/d;return{name:an(t),channels:e.map(e=>({name:h[e].label,unit:h[e].unit})),samples:y*h[e[0]].spr,rateHz:t,time:l?{kind:`timestamps`}:{kind:`rate`,rate:t,start:0}}}),T={headerBytes:o,records:y,duration:d,recordBytes:_,bps:m,signals:h,groups:C,annotations:x,discontinuous:l};return{format:`${i?`BDF`:`EDF`}${c?l?`+D`:`+`:``}`,startTime:rn(r(168,8),r(176,8)),groups:w,meta:{patient:r(8,80),recording:r(88,80)},events:[],notes:l?[`Discontinuous recording: each gap shows as a break in the traces.`,...b]:b,state:T}},async*stream(e){let t=e.plan.state,r=Math.max(1,Math.floor(n/t.recordBytes)),a=e.selection.map(e=>({g:e.group,chans:e.channels.map(n=>t.signals[t.groups[e.group][n]]),spr:t.signals[t.groups[e.group][0]].spr})),o=a.map(()=>0),s=0,c=NaN;for await(let n of e.io.windows(t.headerBytes,t.records*t.recordBytes,r*t.recordBytes)){e.signal?.throwIfAborted();let r=Math.floor(n.bytes.length/t.recordBytes);if(r===0)break;let l=i(n.bytes),u=new Float64Array(r),d=[];for(let e=0;e<r;e++)u[e]=(s+e)*t.duration,t.annotations.forEach((r,i)=>{let a=t.signals[r],o=e*t.recordBytes+a.offset,s=nn(n.bytes.subarray(o,o+a.spr*t.bps));i===0&&s.length&&(u[e]=s[0].onset);for(let e of s)for(let t of e.texts)d.push({time:e.onset,text:t})});let f=new Uint8Array(r),p=0;if(t.discontinuous)for(let e=0;e<r;e++){let n=e?u[e-1]+t.duration:c;n===n&&u[e]>n+1e-9&&(f[e]=1,p++)}for(let e=0;e<a.length;e++){let i=a[e],s=i.spr/t.duration,m=r*i.spr+p,h=t.discontinuous?new Float64Array(m):null,g=i.chans.map(()=>new Float64Array(m)),_=0;for(let e=0;e<r;e++){if(f[e]){h[_]=e?u[e-1]+t.duration:c;for(let e of g)e[_]=NaN;_++}if(h)for(let t=0;t<i.spr;t++)h[_+t]=u[e]+t/s;let r=e*t.recordBytes;i.chans.forEach((e,a)=>on(e,l,n.bytes,r+e.offset,i.spr,t.bps,g[a],_)),_+=i.spr}let v={group:i.g,time:h,start:o[e],length:m,columns:g};e===0&&d.length&&(v.events=d),o[e]+=m,yield v}c=u[r-1]+t.duration,s+=r}}};function cn(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})}const ln={id:`xdf`,label:`XDF (Lab Streaming Layer)`,extensions:[`.xdf`],sniff:e=>f(e,`XDF:`)},un={float32:4,double64:8,int8:1,int16:2,int32:4,int64:8};function dn(e,t,n=0){let r=e.indexOf(`<${t}>`,n);if(r<0)return``;let i=e.indexOf(`</${t}>`,r);return i<0?``:e.slice(r+t.length+2,i).trim()}function fn(e,t){let n=[];for(let r=e.indexOf(`<${t}>`);r>=0;){let i=e.indexOf(`</${t}>`,r);if(i<0)break;n.push(e.slice(r,i+t.length+3)),r=e.indexOf(`<${t}>`,i)}return n}const pn=e=>e.fmt===`string`||un[e.fmt]!==void 0;function mn(e,t,n){let r=e[n];if((r===1||r===4||r===8)&&n+1+r<=e.length)return r===1?[e[n+1],2]:r===4?[t.getUint32(n+1,!0),5]:[a(t,n+1),9];throw Error(`This XDF file is damaged (bad length field).`)}function hn(e,t,n,r){if(n>=e.length)return-1;if(e[n++]===8&&(n+=8),r.fmt!==`string`)return n+un[r.fmt]*r.nch<=e.length?n+un[r.fmt]*r.nch:-1;for(let i=0;i<r.nch;i++){if(n>=e.length)return-1;let[r,i]=mn(e,t,n);n+=i+r}return n<=e.length?n:-1}async function*gn(e,t){let n=new Uint8Array;for await(let r of e.windows(4,e.size-4)){t?.throwIfAborted();let a=r.bytes,o=r.offset-n.length;if(n.length){let e=new Uint8Array(n.length+a.length);e.set(n),e.set(a,n.length),a=e}let s=i(a),c=0;for(;!(c+1>a.length);){let t=a[c];if(c+1+t>a.length)break;let[n,r]=mn(a,s,c),i=c+r+n;if(o+i>e.size)return;if(i>a.length)break;yield{tag:a[c+r]|a[c+r+1]<<8,body:a.subarray(c+r+2,i)},c=i}n=a.slice(c)}}function _n(e,t,n){let r=t-e.i0,i=n-e.t0;e.n++,e.si+=r,e.st+=i,e.sii+=r*r,e.sit+=r*i}function vn(e){let t=e.n*e.sii-e.si*e.si;e.b=t>0?(e.n*e.sit-e.si*e.st)/t:0,e.a=(e.st-e.b*e.si)/Math.max(1,e.n)}function yn(e){if(e.length===0)return[0,0];if(e.length===1)return[e[0][1],0];let t={i0:e[0][0],t0:0,n:0,si:0,st:0,sii:0,sit:0,a:0,b:0};for(let[n,r]of e)_n(t,n,r);return vn(t),[t.a-t.b*t.i0,t.b]}function bn(e,t,n){let r=t.t0+t.a+t.b*(n-t.i0);return r+e.c0+e.c1*r}const xn={...ln,async plan(e,t){let n=new Map,r=``;for await(let e of gn(t)){let t=i(e.body);if(e.tag===1)r=d(e.body);else if(e.tag===2){let r=t.getUint32(0,!0),i=d(e.body.subarray(4)),a=parseInt(dn(i,`channel_count`),10)||1;if(!(a>=1&&a<=1e5))throw Error(`This XDF file is damaged (a stream with ${a} channels).`);let o=fn(i,`channel`);n.set(r,{id:r,name:dn(i,`name`)||`Stream ${r}`,nch:a,srate:parseFloat(dn(i,`nominal_srate`))||0,fmt:dn(i,`channel_format`)||`float32`,labels:Array.from({length:a},(e,t)=>dn(o[t]??``,`label`)||`Ch${t+1}`),units:Array.from({length:a},(e,t)=>dn(o[t]??``,`unit`)),count:0,segs:[],clock:[],c0:0,c1:0,lastTs:NaN})}else if(e.tag===3){let r=n.get(t.getUint32(0,!0));if(!r||!pn(r))continue;let[i,a]=mn(e.body,t,4),o=4+a,s=un[r.fmt],c=r.srate>0?Math.max(1,500/r.srate):1/0;for(let n=0;n<i&&!(hn(e.body,t,o,r)<0);n++){let n;if(e.body[o++]===8?(n=t.getFloat64(o,!0),o+=8):n=r.lastTs+(r.srate>0?1/r.srate:0),r.fmt===`string`)for(let n=0;n<r.nch;n++){let[n,r]=mn(e.body,t,o);o+=r+n}else o+=s*r.nch;if(r.srate>0){let e=r.segs[r.segs.length-1];(!e||n-r.lastTs>c)&&r.segs.push(e={i0:r.count,t0:n,n:0,si:0,st:0,sii:0,sit:0,a:0,b:0}),_n(e,r.count,n)}else r.count===0&&r.segs.push({i0:0,t0:n,n:1,si:0,st:0,sii:0,sit:0,a:0,b:0});r.lastTs=n,r.count++}}else if(e.tag===4){let e=n.get(t.getUint32(0,!0));e&&e.clock.push([t.getFloat64(4,!0),t.getFloat64(12,!0)])}}let a=[],o=[...n.values()].sort((e,t)=>e.id-t.id).filter(e=>(pn(e)||a.push(`${e.name}: channel format ${e.fmt} is not supported; skipped.`),pn(e))),s=1/0;for(let e of o){[e.c0,e.c1]=yn(e.clock);for(let t of e.segs)vn(t);if(e.count===0)continue;let t=e.srate>0?bn(e,e.segs[0],0):e.segs[0].t0+e.c0+e.c1*e.segs[0].t0;s=Math.min(s,t)}let c=cn(o.map(e=>e.name),[]),l=o.map((e,t)=>({name:c[t],channels:e.labels.map((t,n)=>({name:t,unit:e.units[n],...e.fmt===`string`?{text:!0,sparse:!0}:{}})),samples:e.count,time:{kind:`timestamps`},rateHz:e.srate>0?e.srate:null,irregular:e.srate===0})),u=dn(r,`version`);return{format:`XDF ${u||`1.0`}`,startTime:null,groups:l,meta:{header:u},events:[],notes:a,state:{streams:o,origin:Number.isFinite(s)?s:0}}},async*stream(e){let t=e.plan.state,n=8192,r=new Map,a=e=>e.sel.map(()=>e.s.fmt===`string`?Array(n):new Float64Array(n));for(let i of e.selection){let o=t.streams[i.group],s={g:i.group,s:o,sel:p(e,i.group),time:new Float64Array(n),cols:[],n:0,start:0,seg:0,i:0,raw:NaN};s.cols=a(s),r.set(o.id,s)}let o=e=>{let t={group:e.g,time:e.time.slice(0,e.n),start:e.start,length:e.n,columns:e.cols.map(t=>t.slice(0,e.n))};return e.start+=e.n,e.n=0,e.time=new Float64Array(n),e.cols=a(e),t};for await(let a of gn(e.io,e.signal)){if(a.tag!==3)continue;let e=i(a.body),s=r.get(e.getUint32(0,!0));if(!s)continue;let c=s.s,[l,u]=mn(a.body,e,4),f=4+u,p=un[c.fmt],m=[];for(let r=0;r<l&&!(hn(a.body,e,f,c)<0);r++){let r;a.body[f++]===8?(r=e.getFloat64(f,!0),f+=8):r=s.raw+(c.srate>0?1/c.srate:0),s.raw=r;let i;if(c.srate>0){for(;s.seg+1<c.segs.length&&c.segs[s.seg+1].i0<=s.i;)s.seg++;i=bn(c,c.segs[s.seg],s.i)}else i=r+c.c0+c.c1*r;if(s.time[s.n]=i-t.origin,c.fmt===`string`){let n=[];for(let t=0;t<c.nch;t++){let[t,r]=mn(a.body,e,f);n.push(d(a.body.subarray(f+r,f+r+t))),f+=r+t}s.sel.forEach((e,t)=>{s.cols[t][s.n]=n[e]}),m.push({time:i-t.origin,text:n.join(` `)})}else s.sel.forEach((t,n)=>{let r=f+t*p,i=s.cols[n];switch(c.fmt){case`float32`:i[s.n]=e.getFloat32(r,!0);break;case`double64`:i[s.n]=e.getFloat64(r,!0);break;case`int8`:i[s.n]=e.getInt8(r);break;case`int16`:i[s.n]=e.getInt16(r,!0);break;case`int32`:i[s.n]=e.getInt32(r,!0);break;default:i[s.n]=e.getInt32(r+4,!0)*4294967296+e.getUint32(r,!0)}}),f+=p*c.nch;s.i++,++s.n===n&&(yield o(s))}m.length&&(yield{group:s.g,time:new Float64Array,start:s.start,length:0,columns:s.sel.map(()=>new Float64Array),events:m})}for(let e of r.values())e.n&&(yield o(e))}},Sn={id:`tdms`,label:`NI TDMS`,extensions:[`.tdms`],companions:[{ext:`.tdms_index`}],sniff:e=>f(e,`TDSm`)},Cn=4713,wn=4714,Tn={1:1,2:2,3:4,4:8,5:1,6:2,7:4,8:8,9:4,10:8,25:4,26:8,33:1,68:16},En={0:5,1:1,2:6,3:2,4:7,5:3,6:8,7:4,8:9,9:10,4294967295:68},Dn=(e,t,n)=>n?o(e,t+8,n)+a(e,t,n)/2**64:o(e,t,n)+a(e,t+8,n)/2**64,On=()=>Error(`This TDMS file is damaged (its metadata is cut short).`);function kn(e,t,n,r,i){if(n+(r===32?4:Tn[r]??0)>t.length)throw On();switch(r){case 32:{let r=e.getUint32(n,i);if(n+4+r>t.length)throw On();return[d(t.subarray(n+4,n+4+r)),4+r]}case 1:return[e.getInt8(n),1];case 2:return[e.getInt16(n,i),2];case 3:return[e.getInt32(n,i),4];case 4:return[o(e,n,i),8];case 5:return[e.getUint8(n),1];case 6:return[e.getUint16(n,i),2];case 7:return[e.getUint32(n,i),4];case 8:return[a(e,n,i),8];case 9:case 25:return[e.getFloat32(n,i),4];case 10:case 26:return[e.getFloat64(n,i),8];case 33:return[e.getUint8(n)!==0,1];case 68:return[Dn(e,n,i),16];default:throw Error(`This TDMS file has a property of type ${r}, which Kymoscope cannot read.`)}}function An(e){let t=/^\/'((?:[^']|'')*)'(?:\/'((?:[^']|'')*)')?$/.exec(e);return t?[t[1].replace(/''/g,`'`),(t[2]??``).replace(/''/g,`'`)]:null}const jn=4294967295;function Mn(e){if(e.has(`NI_Number_Of_Scales`))return Number(e.get(`NI_Number_Of_Scales`));let t=0;for(let n of e.keys()){let e=/^NI_Scale\[(\d+)\]_Scale_Type$/.exec(n);e&&(t=Math.max(t,Number(e[1])+1))}return t}function Nn(e,t,n){let r=e.find(e=>Mn(e)>0);if(!r||r.get(`NI_Scaling_Status`)===`scaled`)return null;let i=(e,a)=>{if(e===jn||e<0||a>8)return e=>e;let o=r.get(`NI_Scale[${e}]_Scale_Type`);if(o===void 0)return e=>e;if(o===`Linear`){let t=Number(r.get(`NI_Scale[${e}]_Linear_Slope`)),n=Number(r.get(`NI_Scale[${e}]_Linear_Y_Intercept`)??0),o=i(Number(r.get(`NI_Scale[${e}]_Linear_Input_Source`)??jn),a+1);return o&&(e=>t*o(e)+n)}if(o===`Polynomial`){let o=Number(r.get(`NI_Scale[${e}]_Polynomial_Coefficients_Size`)??4);if(!(Number.isInteger(o)&&o>=0&&o<=64))return t.push(`${n}: an NI polynomial scale with ${o} coefficients is not supported; raw values are shown.`),null;let s=Array.from({length:o},(t,n)=>Number(r.get(`NI_Scale[${e}]_Polynomial_Coefficients[${n}]`))),c=i(Number(r.get(`NI_Scale[${e}]_Polynomial_Input_Source`)??jn),a+1);return c&&(e=>{let t=c(e),n=0;for(let e=o-1;e>=0;e--)n=n*t+s[e];return n})}return t.push(`${n}: NI scale type ${String(o)} is not supported; raw values are shown.`),null};return i(Mn(r)-1,0)}const Pn={1:Int8Array,2:Int16Array,3:Int32Array,5:Uint8Array,6:Uint16Array,7:Uint32Array,9:Float32Array,10:Float64Array,25:Float32Array,26:Float64Array,33:Uint8Array};function Fn(e,t,n,r,i,s,c,l){let u=Pn[e];if(u&&s&&r===Tn[e]&&(t.byteOffset+n)%r===0){c.set(new u(t.buffer,t.byteOffset+n,i),l);return}switch(e){case 1:for(let e=0;e<i;e++,n+=r)c[l+e]=t.getInt8(n);return;case 2:for(let e=0;e<i;e++,n+=r)c[l+e]=t.getInt16(n,s);return;case 3:for(let e=0;e<i;e++,n+=r)c[l+e]=t.getInt32(n,s);return;case 4:for(let e=0;e<i;e++,n+=r)c[l+e]=o(t,n,s);return;case 5:case 33:for(let e=0;e<i;e++,n+=r)c[l+e]=t.getUint8(n);return;case 6:for(let e=0;e<i;e++,n+=r)c[l+e]=t.getUint16(n,s);return;case 7:for(let e=0;e<i;e++,n+=r)c[l+e]=t.getUint32(n,s);return;case 8:for(let e=0;e<i;e++,n+=r)c[l+e]=a(t,n,s);return;case 9:case 25:for(let e=0;e<i;e++,n+=r)c[l+e]=t.getFloat32(n,s);return;case 10:case 26:for(let e=0;e<i;e++,n+=r)c[l+e]=t.getFloat64(n,s);return;case 68:for(let e=0;e<i;e++,n+=r)c[l+e]=Dn(t,n,s);return;default:c.fill(NaN,l,l+i)}}async function In(e,t,n){let r=new Map,o=[],s=[],c=new Map,l=new Map,u=t??e,f=0,p=0;for(;f+28<=e.size&&p+28<=u.size;){let m=t?p:f,h=await u.read(m,28),g=i(h);if(!(h[0]===84&&h[1]===68&&h[2]===83&&(h[3]===109||h[3]===104)))throw Error(`This TDMS file is damaged (no segment lead-in where one should be).`);let _=g.getUint32(4,!0),v=!(_&64),y=a(g,12,v),b=a(g,20,v),x=y>=2**53?e.size:Math.min(e.size,f+28+y);if(b>x-f-28)throw Error(`This TDMS file is damaged (segment metadata longer than its segment).`);if(_&2){let e=await u.read(m+28,b),t=i(e);_&4&&(s=[],c=new Map);let o=0,f=t=>{if(o+t>e.length)throw On()};f(4);let p=t.getUint32(o,v);o+=4;for(let i=0;i<p;i++){f(4);let i=t.getUint32(o,v);f(4+i);let u=d(e.subarray(o+4,o+4+i));o+=4+i;let p=An(u),m=r.get(u);m||r.set(u,m={path:u,group:p?.[0]??``,name:p?.[1]??``,type:0,props:new Map,pieces:[],total:0}),f(4);let h=t.getUint32(o,v);o+=4;let g=null;if(h===4294967295)g=null;else if(h===0)g=l.get(m)??null;else if(h===Cn||h===wn){f(32);let e=a(t,o+8,v),r=t.getUint32(o+16,v),i=h===Cn?20:17,s=o+20,c=En[t.getUint32(s,v)]??0,l=t.getUint32(s+8,v);o=s+r*i,f(4);let u=t.getUint32(o,v);o+=4,f(4*u);let d=0;for(let e=0;e<u;e++)d+=t.getUint32(o+4*e,v);o+=4*u,h===wn?n.push(`${m.name}: DAQmx digital line data is not supported; skipped.`):(r>1&&n.push(`${m.name}: only the first of its ${r} DAQmx scalers is read.`),g={type:c,count:e,bytes:0,daqmx:{byteOffset:l,stride:d}})}else{if(h<20)throw On();f(h-4);let e=t.getUint32(o,v);e===32&&f(24);let n=a(t,o+8,v),r=e===32?a(t,o+16,v):n*(Tn[e]??0);o+=h-4,g={type:e,count:n,bytes:r,daqmx:null}}g&&(m.type=g.type,l.set(m,g)),f(4);let _=t.getUint32(o,v);o+=4;for(let n=0;n<_;n++){f(4);let n=t.getUint32(o,v);f(8+n);let r=d(e.subarray(o+4,o+4+n));o+=4+n;let i=t.getUint32(o,v);o+=4;let[a,s]=kn(t,e,o,i,v);m.props.set(r,a),o+=s}let y=c.get(m);y===void 0?c.set(m,s.push({obj:m,idx:g})-1):s[y].idx=g}}if(_&8){let e=f+28+b,t=s.filter(e=>e.idx&&e.idx.count>0),n=t.filter(e=>e.idx.daqmx),r=(_&32)!=0,i=0,a=0;n.length?(a=n[0].idx.daqmx.stride,i=n[0].idx.count*a):r?(a=t.reduce((e,t)=>e+(Tn[t.idx.type]??0),0),i=(t[0]?.idx.count??0)*a):i=t.reduce((e,t)=>e+t.idx.bytes,0);let c=i>0?Math.floor((x-e)/i):0,l=o.push({rawStart:e,chunkSize:i,chunks:c,le:v})-1,u=0;for(let e of t){let t=e.idx,n=Tn[t.type]??0,o=t.daqmx?{seg:l,count:t.count,offset:t.daqmx.byteOffset,bytes:0,stride:a,type:t.type}:{seg:l,count:t.count,offset:u,bytes:t.bytes,stride:r?a:n,type:t.type};t.daqmx||(u+=r?n:t.bytes),o.type===32?o.count=Math.min(o.count,Math.floor(o.bytes/4)):n>0&&(o.count=Math.min(o.count,o.stride>0?Math.max(0,Math.floor((i-o.offset-n)/o.stride)+1):0)),e.obj.pieces.push(o),c&&(e.obj.total+=o.count*c)}}if(f=x,p+=28+b,x>=e.size)break}return{objs:[...r.values()],segments:o}}const Ln={...Sn,async plan(e,t){let n=e.companions.find(e=>e.name.toLowerCase().endsWith(`.tdms_index`)),a=[],{objs:o,segments:s}=await In(t,n?new r(n):null,a),c=o.find(e=>e.path===`/`)?.props,l=o.filter(e=>e.name&&e.total>0&&(e.type===32||Tn[e.type])),u=new Set(l);for(let e of o)e.name&&e.total>0&&!u.has(e)&&a.push(`${e.name}: TDMS data type ${e.type} is not supported; skipped.`);let d=l.map(e=>e.props.get(`wf_start_time`)).filter(e=>typeof e==`number`),f=d.reduce((e,t)=>Math.min(e,t),d.length?1/0:0),p=new Map;for(let e of l){let t=`${e.total}|${e.props.get(`wf_increment`)??``}`,n=p.get(e.group)??new Map,r=n.get(t);r?r.push(e):n.set(t,[e]),p.set(e.group,n)}let m=[],h=[];for(let[e,t]of p)for(let n of t.values()){let r=n[0].props.get(`wf_increment`),i=typeof r==`number`&&r>0?1/r:null,a=i?null:n.find(e=>e.type===68)??n.find(e=>e.type!==32&&/^(time|timestamp|t)$/i.test(e.name))??null,o=n.filter(e=>e!==a),s=n[0].props.get(`wf_start_time`),c=i?Number(n[0].props.get(`wf_start_offset`)??0)+(typeof s==`number`?s-f:0):0;m.push({name:t.size===1?e:`${e} (${i?+i.toFixed(6):n[0].total} ${i?`Hz`:`samples`})`,channels:o.map(e=>({name:e.name,unit:String(e.props.get(`unit_string`)??``),text:e.type===32})),samples:n[0].total,time:i?{kind:`rate`,rate:i,start:c}:a?{kind:`timestamps`}:{kind:`index`},rateHz:i}),h.push({channels:o,time:a,origin:0})}if(m.length===0)throw Error(`This TDMS file has no channels with data.`);let g=[];for(let e of h){if(!e.time)continue;let n=e.time.pieces[0],r=s[n.seg],a=await t.read(r.rawStart+n.offset,Tn[n.type]??8),o=new Float64Array(1);Fn(n.type,i(a),0,0,1,r.le,o,0),g.push(o[0])}let _=g.reduce((e,t)=>Math.min(e,t),g.length?1/0:0);for(let e of h)e.origin=_;let v=new Date(Date.UTC(1904,0,1)+f*1e3),y=f&&Number.isFinite(v.getTime())?v.toISOString():null,b={objs:o,segments:s,groups:h},x={};for(let[e,t]of c??[])typeof t==`string`&&(x[e]=t);return{format:`TDMS`,startTime:y,groups:m,meta:x,events:[],notes:a,state:b}},async*stream(e){for(let t of e.selection)yield*zn(e,t.group)},streamGroup:(e,t)=>zn(e,t)};function Rn(e,t,n,r,i,a){let o=0;for(;o<i&&r.pi<t.pieces.length;){let s=t.pieces[r.pi],c=e.segments[s.seg];if(r.chunk>=c.chunks){r.pi++,r.chunk=0,r.row=0;continue}let l=Math.min(i-o,s.count-r.row),u=c.rawStart+r.chunk*c.chunkSize+s.offset;if(s.type===32)a.push({ch:n,at:u,end:u+s.bytes,rows:l,first:r.row,out:o,piece:s,le:c.le,range:0});else{let e=u+r.row*s.stride;a.push({ch:n,at:e,end:e+(l-1)*s.stride+Tn[s.type],rows:l,first:r.row,out:o,piece:s,le:c.le,range:0})}o+=l,r.row+=l,r.row>=s.count&&(r.chunk++,r.row=0)}}async function*zn(e,t){let n=e.plan.state,r=n.groups[t],a=p(e,t).map(e=>r.channels[e]),o=r.time?[r.time,...a]:a;if(!o.length)return;let s=new Map(n.objs.map(e=>[e.path,e.props])),c=e=>s.get(e)??new Map,l=c(`/`),u=o.map(e=>Nn([e.props,c(`/'${e.group.replace(/'/g,`''`)}'`),l],[],e.name)),f=o.map(()=>({pi:0,chunk:0,row:0})),m=o.reduce((e,t)=>Math.min(e,t.total),1/0);for(let a=0;a<m;){e.signal?.throwIfAborted();let s=Math.min(65536,m-a),c=[];o.forEach((e,t)=>Rn(n,e,t,f[t],s,c));let l=c.slice().sort((e,t)=>e.at-t.at),p=[];for(let e of l){let t=p[p.length-1];t&&e.at<=t.end+65536&&Math.max(t.end,e.end)-t.at<=16777216?t.end=Math.max(t.end,e.end):p.push({at:e.at,end:e.end}),e.range=p.length-1}let h=[];for(let t of p)h.push(await e.io.slice(t.at,t.end-t.at));let g=h.map(i),_=o.map(e=>e.type===32?Array(s).fill(null):new Float64Array(s).fill(NaN));for(let e of c){let t=e.at-p[e.range].at,n=e.piece;if(n.type===32){let r=h[e.range],i=g[e.range],a=t+4*n.count,o=_[e.ch];for(let n=0;n<e.rows;n++){let s=e.first+n,c=s===0?0:i.getUint32(t+4*(s-1),e.le),l=i.getUint32(t+4*s,e.le);o[e.out+n]=d(r.subarray(a+c,a+l))}}else Fn(n.type,g[e.range],t,n.stride,e.rows,e.le,_[e.ch],e.out)}for(let e=0;e<o.length;e++){let t=u[e],n=_[e];if(t&&n instanceof Float64Array)for(let e=0;e<s;e++)n[e]=t(n[e])}let v=null;if(r.time){v=_.shift();for(let e=0;e<s;e++)v[e]-=r.origin}yield{group:t,time:v,start:a,length:s,columns:_},a+=s}}const Bn={id:`hdf5`,label:`HDF5`,extensions:[`.h5`,`.hdf5`,`.hdf`,`.he5`,`.nc`],sniff:e=>[0,512,1024,2048].some(t=>f(e,`‰HDF\r
2
2
  
3
3
  `,t))},Vn=e=>!!e&&typeof e.keys==`function`,Hn=1e5;function Un(){let e=new Set,t=0,n=!1;return{enter(t){let r=null;try{r=t.create_reference?Array.prototype.join.call(t.create_reference().ref_data,`,`):null}catch{r=null}return r===null?!0:e.has(r)?(n=!0,!1):(e.add(r),!0)},count:()=>++t<=Hn,note:()=>t>1e5?`This file has more than ${Hn.toLocaleString(`en-US`)} objects (or links that repeat its groups); only the first were read.`:n?`Some groups of this file link back to a group already read; each was read once.`:null}}function Wn(e,t,n,r){return t.reduce((e,t)=>e*t,1)*Math.max(1,e.metadata.size||1)>(r?n*1032+1024:n)}const Gn=e=>!!e&&typeof e.slice==`function`;let Kn=null,qn=null;function Jn(e){Kn=e,qn=null}const Yn=new WeakMap;function Xn(){!Kn||qn||(qn=Kn(),qn.catch(()=>{qn=null}))}function Zn(e){if(!Kn)return Promise.reject(Error(`HDF5 and MAT 7.3 files are read in the import worker, and this environment has no workers.`));Xn();let t=Yn.get(e);return t||(t=qn.then(t=>t(e)).then(e=>({root:e.root,close:()=>{}})),Yn.set(e,t),t.catch(()=>Yn.delete(e))),t}const Qn=new WeakMap;function $n(e,t,n){let r=Qn.get(e);r||Qn.set(e,r=new Map);let i=r.get(t);return i||r.set(t,i=n??e.get(t)),i}function er(e){return e instanceof Float64Array?e:e instanceof BigInt64Array||e instanceof BigUint64Array?Float64Array.from(e,e=>Number(e)):ArrayBuffer.isView(e)?new Float64Array(e):Float64Array.from(e)}const tr={s:1,sec:1,second:1,seconds:1,ms:.001,msec:.001,us:1e-6,µs:1e-6,ns:1e-9};function nr(e,...t){for(let n of t){let t=e[n]?.value;if(typeof t==`string`)return t;if(Array.isArray(t)&&typeof t[0]==`string`)return t[0]}return``}function rr(e,...t){for(let n of t){let t=e[n]?.value,r=typeof t==`number`?t:ArrayBuffer.isView(t)?Number(t[0]):NaN;if(Number.isFinite(r))return r}return null}const ir=new Set([1,2,3,4,5,6]),ar=/^(time|t|timestamps?|.*[_ ]time|time[_ ].*)$/i,or=[`sampling_rate`,`sample_rate`,`samplerate`,`sampleRate`,`fs`,`Fs`,`rate`];function sr(e,t,n,r,i,a,o=0){i.set(n,t.attrs);for(let s of t.keys()){if(!a.count())return;let c=n===`/`?`/${s}`:`${n}/${s}`,l=t.get(s);if(Vn(l))o<16&&a.enter(l)&&sr(e,l,c,r,i,a,o+1);else if(Gn(l)){let t=$n(e,c,l);r.push({path:c,parent:n,name:s,ds:t,attrs:t.attrs})}}}const cr=e=>e===`/`?`root`:e.slice(1),lr=e=>Math.max(4096,Math.min(1<<20,Math.floor((8<<20)/(8*Math.max(1,e)))));async function ur(e,t){let n=$n(e,t.path);if(t.col===null)return er(n.slice([[0,1]]))[0]*t.factor;let r=n.slice([[0,1]]);return Number(r[0][t.col])*t.factor}const dr={...Bn,async plan(e){let t=await Zn(e.main);try{let n=[],r=new Map,i=Un();i.enter(t.root),sr(t.root,t.root,`/`,n,r,i);let a=[],o=i.note();o&&a.push(o);let s=new Map,c=[],l=0;for(let t of n){let n=t.ds.metadata.shape??[],r=t.ds.metadata.type,i=t.ds.metadata.chunks?t.ds.filters??[]:[],o=i.find(e=>!ir.has(e.id)),u=!o;if(u&&i.length>0&&n.length>0&&n.every(e=>e>0))try{t.ds.slice(n.map(()=>[0,1]))}catch{u=!1}if(!u){a.push(`${t.path}: compressed with a filter Kymoscope cannot read${o?` (${o.name||o.id})`:``}; skipped.`);continue}if(Wn(t.ds,n,e.main.size,i.length>0)){a.push(`${t.path}: larger than the file can hold (never written, or damaged); skipped.`);continue}if(n.length===1&&n[0]>1&&(r===0||r===1||r===3)){let e=`${t.parent}|${n[0]}`,r=s.get(e)??{parent:t.parent,n:n[0],leaves:[]};r.leaves.push(t),s.set(e,r)}else if(n.length===2&&n[0]>1&&n[1]<=4096&&(r===0||r===1)){let e=rr(t.attrs,...or);c.push({name:cr(t.path),kind:`matrix`,rows:n[0],rate:e,time:null,origin:0,cols:Array.from({length:n[1]},(e,n)=>({path:t.path,col:n,text:!1,factor:1}))})}else if(n.length===1&&r===6){let e=(t.ds.metadata.compound_type?.members??[]).flatMap((e,n)=>e.type===0||e.type===1?[{path:t.path,col:n,text:!1,factor:1,name:e.name}]:[]),r=e.find(e=>ar.test(e.name));c.push({name:cr(t.path),kind:`compound`,rows:n[0],rate:null,origin:0,time:r??null,cols:e.filter(e=>e!==r)})}else l++}for(let e of s.values()){let t=[...s.values()].filter(t=>t.parent===e.parent).length>1,n=e.leaves.find(e=>nr(e.attrs,`CLASS`)===`DIMENSION_SCALE`)??e.leaves.find(e=>ar.test(e.name)&&e.ds.metadata.type!==3),i=n?tr[nr(n.attrs,`units`,`unit`,`Units`)]??1:1,a=n?null:rr(r.get(e.parent)??{},...or);c.push({name:t?`${cr(e.parent)} (${e.n} rows)`:cr(e.parent),kind:`vectors`,rows:e.n,rate:a,origin:0,time:n?{path:n.path,col:null,text:!1,factor:i}:null,cols:e.leaves.filter(e=>e!==n).map(e=>({path:e.path,col:null,text:e.ds.metadata.type===3,factor:1}))})}l&&a.push(`${l} dataset${l===1?``:`s`} with other shapes or types (images, references, 3-D) skipped.`),c.sort((e,t)=>e.name.localeCompare(t.name));let u=c.map((e,t)=>e.time||e.rate?t:-1).filter(e=>e>=0),d=1/0;for(let e of c)e.time&&(d=Math.min(d,await ur(t.root,e.time)));for(let e of c)e.origin=Number.isFinite(d)?d:0;let f=new Map(n.map(e=>[e.path,e]));for(let e of c)e.chunk=[...e.cols,...e.time?[e.time]:[]].reduce((e,t)=>Math.max(e,f.get(t.path).ds.metadata.chunks?.[0]??0),0);let p=e=>nr(f.get(e.path).attrs,`units`,`unit`,`Units`,`UNITS`),m=(e,t)=>e.kind===`matrix`?`${e.name.split(`/`).pop()}[${t.col+1}]`:e.kind===`compound`?f.get(t.path).ds.metadata.compound_type.members[t.col].name:t.path.split(`/`).pop(),h=c.map(e=>({name:e.name,channels:e.cols.map(t=>({name:m(e,t),unit:e.kind===`vectors`?p(t):``,text:t.text})),samples:e.rows,time:e.time?{kind:`timestamps`}:e.rate?{kind:`rate`,rate:e.rate,start:0}:{kind:`index`},rateHz:e.rate}));if(h.length===0)throw Error(`This HDF5 file has no datasets Kymoscope can plot.`);let g=h.length>20||h.length>1&&u.length<h.length,_=g?u.length?u:[c.reduce((e,t,n)=>t.rows*t.cols.length>c[e].rows*c[e].cols.length?n:e,0)]:void 0;return g&&a.push(`Only the groups with a time base are read unless you choose others in the channel picker.`),{format:`HDF5`,startTime:null,groups:h,meta:{},events:[],notes:a,pick:g,defaultGroups:_,state:{groups:c}}}finally{t.close()}},async*stream(e){for(let t of e.selection)yield*fr(e,t.group)},streamGroup:(e,t)=>fr(e,t)};async function*fr(e,t){let n=e.plan.state.groups[t],r=p(e,t).map(e=>n.cols[e]),i=await Zn(e.files.main);try{let a=n.chunk??0,o=a>0?Math.max(1,Math.min(Math.floor((1<<20)/a),Math.ceil(lr(r.length+1)/a)))*a:lr(r.length+1);for(let a=0;a<n.rows;a+=o){e.signal?.throwIfAborted();let s=Math.min(n.rows,a+o),c=s-a,l=null,u=e=>{let t=$n(i.root,e.path);if(n.kind===`vectors`){let n=t.slice([[a,s]]);if(e.text)return Array.from(n,e=>e==null?null:String(e));let r=er(n);if(e.factor!==1)for(let t=0;t<c;t++)r[t]*=e.factor;return r}let r=new Float64Array(c);if(n.kind===`matrix`){let n=(t.shape??[0,1])[1],i=l??=t.slice([[a,s],[0,n]]);for(let t=0;t<c;t++)r[t]=Number(i[t*n+e.col])}else{let n=l??=t.slice([[a,s]]);for(let t=0;t<c;t++)r[t]=Number(n[t][e.col])*e.factor}return r},d=null;if(n.time){d=u(n.time);for(let e=0;e<c;e++)d[e]-=n.origin}yield{group:t,time:d,start:a,length:c,columns:r.map(u)}}}finally{i.close()}}const pr={id:`mat`,label:`MATLAB MAT (v5, v7.3)`,extensions:[`.mat`],sniff:e=>f(e,`MATLAB 5.0 MAT-file`)||f(e,`MATLAB 7.3 MAT-file`)},mr=/^(time|t|tout|timestamps?)$/i,hr=/^(fs|sample_?rate|sampling_?rate|rate|samplerate)$/i,gr=e=>e.slice(e.lastIndexOf(`.`)+1),_r=e=>e.includes(`.`)?e.slice(0,e.lastIndexOf(`.`)):``;function vr(e,t){let n=/^(.*)\.values(\[\d+\])?$/.exec(e.name),r=n&&(t.get(`${n[1]}.label`)||t.get(`${n[1]}.blockName`));return r?{...e,name:`${r}${n[2]??``}`}:e}function yr(e,t,n){let r=new Map;for(let t of e){if(!(t.length>1))continue;let e=r.get(t.length);e?e.push(t):r.set(t.length,[t])}let i=[...n].filter(([e])=>hr.test(gr(e))),a=i.length===1?i[0][1]:null,o=[];for(let[e,n]of r){let r=n.find(e=>mr.test(gr(e.name))||/(_time|\.Time)$/.test(e.name))??null;o.push({name:r?_r(r.name)||r.name:`${e} samples`,channels:n.filter(e=>e!==r).map(e=>vr(e,t)),time:r,rate:r?null:a,origin:0})}return o}function br(e){return e.map(e=>({name:e.name,channels:e.channels.map(e=>({name:e.name,unit:``})),samples:e.channels[0]?.length??e.time?.length??0,time:e.time?{kind:`timestamps`}:e.rate?{kind:`rate`,rate:e.rate,start:0}:{kind:`index`},rateHz:e.rate}))}async function xr(e){let t=1/0;for(let n of e)n.time&&(t=Math.min(t,(await n.time.read(0,1))[0]));for(let n of e)n.origin=Number.isFinite(t)?t:0}var Sr=class{#e;size;constructor(e){this.#e=e,this.size=e.size}read(e,t){return t>=65536?this.#e.slice(e,t):this.#e.read(e,t)}release(){}},Cr=class{#e;#t;#n;#r=null;keep=!0;size;constructor(e,t,n,r){this.#e=e,this.#t=t,this.#n=n,this.#r=r,this.size=r.length}async read(e,t){return this.#r??=await it(await this.#e.slice(this.#t,this.#n),this.size,this.size),this.#r.subarray(e,e+t)}release(){this.keep||(this.#r=null)}};const wr={1:1,2:1,3:2,4:2,5:4,6:4,7:4,9:8,12:8,13:8};function Tr(e,t,n,r,a=1){let o=i(t),s=r.length,c=wr[e]*a;if(e===9&&a===1&&n){r.set(t.byteOffset%8==0?new Float64Array(t.buffer,t.byteOffset,s):new Float64Array(t.slice(0,s*8).buffer));return}switch(e){case 1:for(let e=0,t=0;e<s;e++,t+=c)r[e]=o.getInt8(t);return;case 2:for(let e=0,t=0;e<s;e++,t+=c)r[e]=o.getUint8(t);return;case 3:for(let e=0,t=0;e<s;e++,t+=c)r[e]=o.getInt16(t,n);return;case 4:for(let e=0,t=0;e<s;e++,t+=c)r[e]=o.getUint16(t,n);return;case 5:for(let e=0,t=0;e<s;e++,t+=c)r[e]=o.getInt32(t,n);return;case 6:for(let e=0,t=0;e<s;e++,t+=c)r[e]=o.getUint32(t,n);return;case 7:for(let e=0,t=0;e<s;e++,t+=c)r[e]=o.getFloat32(t,n);return;case 9:for(let e=0,t=0;e<s;e++,t+=c)r[e]=o.getFloat64(t,n);return;case 12:for(let e=0,t=0;e<s;e++,t+=c)r[e]=o.getInt32(t+(n?4:0),n)*4294967296+o.getUint32(t+(n?0:4),n);return;case 13:for(let e=0,t=0;e<s;e++,t+=c)r[e]=o.getUint32(t+(n?4:0),n)*4294967296+o.getUint32(t+(n?0:4),n);return;default:r.fill(NaN)}}async function Er(e,t,n){let r=i(await e.read(t,8)),a=r.getUint32(0,n);if(a>>>16)return{type:a&65535,bytes:a>>>16,data:t+4,next:t+8};let o=r.getUint32(4,n);return{type:a,bytes:o,data:t+8,next:a===15?t+8+o:t+8+o+(8-o%8)%8}}function Dr(e,t,n,r,i){let[a,o]=t,s=wr[r.type];if(!s)return[];let c=(e,t)=>async(a,o)=>{let c=new Float64Array(o-a);return t===1?Tr(r.type,await n.read(r.data+(e+a)*s,(o-a)*s),i,c):Tr(r.type,await n.read(r.data+(e+a*t)*s,((o-a-1)*t+1)*s),i,c,t),c};return a===1||o===1?[{name:e,length:a*o,read:c(0,1)}]:a>=o?Array.from({length:o},(t,n)=>({name:`${e}[${n+1}]`,length:a,read:c(n*a,1)})):Array.from({length:a},(t,n)=>({name:`${e}[${n+1}]`,length:o,read:c(n,a)}))}async function Or(e,t,n,r,a,o,s){let c=t,f=await Er(e,c,n),p=i(await e.read(f.data,8)).getUint32(0,n),m=p&255;c=f.next;let h=await Er(e,c,n);if(h.bytes>128){o.notes.push(`A MAT variable with more than 32 dimensions was skipped (damaged).`);return}let g=i(await e.read(h.data,h.bytes)),_=Array.from({length:h.bytes/4},(e,t)=>g.getInt32(4*t,n));c=h.next;let v=await Er(e,c,n),y=u(await e.read(v.data,v.bytes));c=v.next;let b=a??y,x=r?`${r}.${b}`:b,S=_.reduce((e,t)=>e*t,1);if(m>=6&&m<=15){if(S===0)return;let t=await Er(e,c,n);if(p&2048&&o.notes.push(`${x}: the imaginary part was skipped.`),_.length>2){o.notes.push(`${x}: arrays with more than two dimensions are skipped.`);return}if(!wr[t.type])return;if(!(S>0)||S*wr[t.type]>t.bytes||t.data+t.bytes>e.size){o.notes.push(`${x}: its data is shorter than its dimensions (damaged); skipped.`);return}if(S===1){let r=new Float64Array(1);Tr(t.type,await e.read(t.data,wr[t.type]??8),n,r),o.scalars.set(x,r[0]);return}o.channels.push(...Dr(x,_,e,t,n));return}if(m===4){let t=await Er(e,c,n);if(t.bytes>kr)return;let r=await e.read(t.data,t.bytes),i=t.type===3||t.type===4||t.type===17?new TextDecoder(n?`utf-16le`:`utf-16be`).decode(r.subarray(0,r.length&-2)):d(r);_[0]<=1&&o.strings.set(x,i);return}if(m===2){let t=await Er(e,c,n),r=i(await e.read(t.data,4)).getInt32(0,n);c=t.next;let a=await Er(e,c,n);if(!(r>0))return;let u=await e.read(a.data,a.bytes),d=Array.from({length:Math.floor(u.length/r)},(e,t)=>l(u.subarray(t*r,(t+1)*r)));if(c=a.next,d.length===0||S*d.length*8>e.size-c){S>0&&d.length>0&&o.notes.push(`${x}: its fields are longer than the file (damaged); skipped.`);return}for(let t=0;t<S;t++){let r=S>1?`${x}(${t+1})`:x;for(let t of d){let i=await Er(e,c,n);i.type===14&&i.bytes>0&&s<16&&await Or(e,i.data,n,r,t,o,s+1),c=i.next}}return}m===1?o.notes.push(`${x}: cell arrays are skipped.`):m===5?o.notes.push(`${x}: sparse arrays are skipped.`):o.notes.includes(Ar)||o.notes.push(Ar)}const kr=1<<17,Ar=`MATLAB objects (timeseries, SimulationOutput) were skipped: save them as 'Structure with time' or as structs.`;async function jr(e){let t=u((await e.read(0,128)).subarray(126,128))===`IM`,n={channels:[],strings:new Map,scalars:new Map,notes:[],sources:[]},r=new Sr(e),a=0;for(let o=128;o+8<=e.size;){let s=await Er(r,o,t);if(s.type===15){if(s.bytes>1<<30)throw Error(`A compressed variable in this MAT file is over 1 GB; save it with -v7.3 to open it here.`);let r=await e.slice(s.data,s.bytes),o=await it(r,-1,8),c=o.length<8?0:8+i(o).getUint32(4,t);if(c>w(s.bytes))throw Error(`A compressed variable in this MAT file is damaged.`);if(c>1<<30)throw Error(`A compressed variable in this MAT file is over 1 GB; save it with -v7.3 to open it here.`);let l=await it(r,c,c),u=new Cr(e,s.data,s.bytes,l);n.sources.push(u),a+=l.length;let d=await Er(u,0,t);if(d.type===14&&await Or(u,d.data,t,``,null,n,0),a>536870912)for(let e of n.sources)e.keep=!1,e.release()}else s.type===14&&await Or(r,s.data,t,``,null,n,0);o=s.next}return n}const Mr=new Set([`double`,`single`,`int8`,`uint8`,`int16`,`uint16`,`int32`,`uint32`,`int64`,`uint64`,`logical`]);function Nr(e,t){let n={channels:[],strings:new Map,scalars:new Map,notes:[]},r=Un();r.enter(e);let i=t=>$n(e,t),a=(e,t,n)=>{let r=null;return(a,o)=>((r?.s!==a||r.e!==o)&&(r={s:a,e:o,v:er(t?i(e).slice([[0,n],[a,o]]):i(e).slice([[a,o],[0,n]]))}),r.v)},o=(e,s,c,l)=>{for(let u of e.keys()){if(!r.count())return;if(u.startsWith(`#`))continue;let d=e.get(u);if(!d)continue;let f=`${s}/${u}`,p=c?`${c}.${u}`:u,m=d.attrs,h=nr(m,`MATLAB_class`);if(m.MATLAB_empty)continue;if(Vn(d)){h===`struct`&&l<16&&r.enter(d)&&o(d,f,p,l+1);continue}if(!Gn(d))continue;let g=d.shape??[];if(h===`char`){if(g.reduce((e,t)=>e*t,1)>65536)continue;let e=er(d.slice(g.map(e=>[0,e])));n.strings.set(p,new TextDecoder(`utf-16le`).decode(Uint16Array.from(e)))}else if(Mr.has(h)&&g.length===2&&Wn(d,g,t,!!d.metadata.chunks))n.notes.push(`${p}: larger than the file can hold (never written, or damaged); skipped.`);else if(Mr.has(h)&&g.length===2){let[e,t]=g;if(e*t===1){n.scalars.set(p,er(i(f).slice([[0,1],[0,1]]))[0]);continue}if(e===1||t===1){let r=e*t;n.channels.push({name:p,length:r,read:async(t,n)=>er(e===1?i(f).slice([[0,1],[t,n]]):i(f).slice([[t,n],[0,1]]))})}else if(t>=e){let r=a(f,!0,e);for(let i=0;i<e;i++)n.channels.push({name:`${p}[${i+1}]`,length:t,read:async(e,t)=>r(e,t).slice(i*(t-e),(i+1)*(t-e))})}else{let r=a(f,!1,t);for(let i=0;i<t;i++)n.channels.push({name:`${p}[${i+1}]`,length:e,read:async(e,n)=>{let a=r(e,n),o=new Float64Array(n-e);for(let e=0;e<o.length;e++)o[e]=a[e*t+i];return o}})}}else h===`cell`?n.notes.push(`${p}: cell arrays are skipped.`):h&&n.notes.push(`${p}: MATLAB class ${h} is skipped.`)}};o(e,``,``,0);let s=r.note();return s&&n.notes.push(s),n}const Pr=e=>Math.max(4096,Math.min(1<<18,Math.floor((16<<20)/(8*Math.max(1,e))))),Fr={...pr,async plan(e,t){let n=f(await t.read(0,20),`MATLAB 7.3`),r,i=[];if(n)r=Nr((await Zn(e.main)).root,e.main.size);else{let e=await jr(t);i=e.sources,r=e}let a=yr(r.channels,r.strings,r.scalars).filter(e=>e.channels.length>0);await xr(a);let o=br(a);if(o.length===0)throw Error(`This MAT file has no numeric vectors or matrices to plot.`);let s=o.flatMap((e,t)=>e.time.kind===`index`?[]:[t]),c=o.length>1&&s.length<o.length,l=Object.fromEntries(r.strings);for(let[e,t]of r.scalars)l[e]=String(t);return{format:n?`MAT 7.3`:`MAT 5`,startTime:null,groups:o,meta:l,events:[],notes:r.notes,pick:c,defaultGroups:c&&s.length?s:void 0,state:{groups:a,sources:i}}},async*stream(e){for(let t of e.selection)yield*Ir(e,t.group)},streamGroup:(e,t)=>Ir(e,t)};async function*Ir(e,t){let n=e.plan.state,r=n.groups[t],i=p(e,t).map(e=>r.channels[e]),a=r.channels[0].length,o=Pr(i.length+1);try{for(let n=0;n<a;n+=o){e.signal?.throwIfAborted();let s=Math.min(a,n+o),c=null;if(r.time){c=await r.time.read(n,s);for(let e=0;e<c.length;e++)c[e]-=r.origin}let l=[];for(let e of i)l.push(await e.read(n,s));yield{group:t,time:c,start:n,length:s-n,columns:l}}}finally{for(let e of n.sources)e.release()}}const Lr={id:`comtrade`,label:`COMTRADE (IEEE C37.111)`,extensions:[`.cfg`,`.cff`],companions:[{ext:`.dat`}],sniff:e=>{let t=u(e.subarray(0,512));if(/^---\s*file type:\s*CFG/i.test(t))return!0;let n=t.split(/\r?\n/);return n.length>2&&/^\s*\d+\s*,\s*\d+A\s*,\s*\d+D\s*$/i.test(n[1])}};function Rr(e,t){let n=/^\s*(\d{1,2})\/(\d{1,2})\/(\d{2,4})\s*,\s*(\d{1,2}):(\d{2}):(\d{2})(?:\.(\d+))?/.exec(e??``);if(!n)return[null,0,!1];let[r,i]=t===1991?[n[2],n[1]]:[n[1],n[2]],a=n[3].length===2?2e3+Number(n[3]):Number(n[3]),o=Number(`${n[6]}.${n[7]??`0`}`);return[`${a}-${i.padStart(2,`0`)}-${r.padStart(2,`0`)}T${n[4].padStart(2,`0`)}:${n[5]}:${o.toFixed(3).padStart(6,`0`)}`,Date.UTC(a,Number(i)-1,Number(r),Number(n[4]),Number(n[5]))/1e3+o,(n[7]??``).length>6]}function zr(e){let t=e.split(/\r?\n/).map(e=>e.trim()),[n,,r]=t[0].split(`,`),i=Number(r)||1991,a=/(\d+)A\s*,\s*(\d+)D/i.exec(t[1]??``);if(!a)throw Error(`This COMTRADE .cfg is damaged (second line).`);let o=Number(a[1]),s=Number(a[2]);if(o+s>t.length)throw Error(`This COMTRADE .cfg is damaged (more channels than lines).`);let c=2,l=[];for(let e=0;e<o;e++,c++){let e=(t[c]??``).split(`,`);l.push({name:(e[1]??``).trim(),unit:(e[4]??``).trim(),a:Number(e[5]),b:Number(e[6]??0)||0})}let u=[];for(let e=0;e<s;e++,c++)u.push(((t[c]??``).split(`,`)[1]??``).trim());c++;let d=Number(t[c++]);if(!(Number.isInteger(d)&&d>=0&&d<=t.length-c))throw Error(`This COMTRADE .cfg is damaged (sample rates).`);let f=[];for(let e=0;e<Math.max(1,d);e++,c++){let[e,n]=(t[c]??``).split(`,`).map(Number);f.push([d===0?0:e,n])}let[p,m,h]=Rr(t[c++],i),[g,_,v]=Rr(t[c++],i),y=(t[c++]||`ASCII`).toUpperCase(),b=Number(t[c++])||1;return{station:n.trim(),rev:i,analog:l,digital:u,rates:f,start:p,trigger:g,startSec:m,triggerSec:_,ft:y,timemult:b,timebase:h||v?1e-9:1e-6}}const Br={BINARY:2,BINARY32:4,FLOAT32:4};async function Vr(e){let t=u(await e.read(0,Math.min(e.size,1<<20))),n=t.search(/---\s*file type:\s*CFG\s*---\r?\n/i),r=/---\s*file type:\s*DAT\s+(ASCII|BINARY32|BINARY|FLOAT32)(?:\s*:\s*(\d+))?\s*---\r?\n/i.exec(t);if(n<0||!r)throw Error(`This COMTRADE .cff is damaged (no CFG or DAT section in its first megabyte).`);let i=t.indexOf(`
4
4
  `,n)+1,a=t.slice(i).search(/---\s*file type:\s*(INF|HDR|DAT)/i),o=t.slice(i,a<0?void 0:i+a),s=r.index+r[0].length;return{cfg:o,offset:s,length:r[2]?Number(r[2]):e.size-s}}function Hr(e,t,n,r){let i=0,a=0,o=t,s=0;for(let[t,c]of e){for(;o<c&&s<n;)r[s++]=a+(o-i)/t,o++;if(a+=(c-i)/t,i=c,s>=n)return}let c=e[e.length-1];for(;s<n;s++,o++)r[s]=a+(o-i)/c[0]}const Ur=e=>e.companions.find(e=>e.name.toLowerCase().endsWith(`.dat`)),Wr={...Lr,async plan(e,t){let n=e.main.name.toLowerCase().endsWith(`.cff`),r,i;if(n){let e=await Vr(t);r=e.cfg,i={data:`self`,offset:e.offset,length:e.length}}else{let n=Ur(e);if(!n)throw Error(`This COMTRADE .cfg needs its .dat file: drop both together.`);if(t.size>16777216)throw Error(`This .cfg is too large to be a COMTRADE configuration file.`);r=u(await t.read(0,t.size)),i={data:`companion`,offset:0,length:n.size}}let a=zr(r);if(a.ft!==`ASCII`&&!Br[a.ft])throw Error(`This COMTRADE file has data file type ${a.ft}, which Kymoscope cannot read.`);let o=Math.ceil(a.digital.length/16),s=a.ft===`ASCII`?0:8+a.analog.length*Br[a.ft]+2*o,c=s?Math.floor(i.length/s):i.length,l=Math.min(a.rates[a.rates.length-1][1]||(s?c:-1),c),d=a.rates.length===1&&a.rates[0][0]>0?a.rates[0][0]:null,f=[`Analog values are shown as recorded (primary or secondary, per the CFG).`];return{format:`COMTRADE ${a.rev} (${a.ft})`,startTime:a.start,meta:{station:a.station,trigger:a.trigger??``},groups:[{name:a.station||`COMTRADE`,channels:[...a.analog.map(e=>({name:e.name,unit:e.unit})),...a.digital.map(e=>({name:e,unit:``}))],samples:l,time:{kind:`timestamps`},rateHz:d}],events:a.start&&a.trigger?[{time:Math.round((a.triggerSec-a.startSec)*1e6)/1e6,text:`Trigger`}]:[],notes:f,state:{...i,cfg:a,samples:l,recordSize:s}}},stream:e=>Gr(e)};async function*Gr(e){let t=e.plan.state,{cfg:a}=t,o=t.data===`self`?e.io:new r(Ur(e.files)),s=p(e,0),c=a.analog.length,l=a.rates[0][0]>0,u=a.timemult*a.timebase,d=65536,f=0,m=(e,t,n)=>{let r=new Float64Array(e);if(l)Hr(a.rates,f,e,r);else for(let n=0;n<e;n++)r[n]=t[n]*u;let i={group:0,time:r,start:f,length:e,columns:n};return f+=e,i};if(a.ft===`ASCII`){let n=a.rev>=1999?`99999`:``,r=s.map(e=>e<c?a.analog[e]:null),i=new Float64Array(d),l=s.map(()=>new Float64Array(d)),u=0,f=(e,t,a)=>{let o=e.slice(t,a).split(`,`);if(!(o.length<2)){i[u]=Number(o[1]);for(let e=0;e<s.length;e++){let t=(o[2+s[e]]??``).trim(),i=r[e];l[e][u]=t===``||i&&t===n?NaN:i?i.a*Number(t)+i.b:Number(t)}u++}},p=``,h=new TextDecoder(`latin1`);for await(let n of o.windows(t.offset,t.length)){e.signal?.throwIfAborted();let t=p+h.decode(n.bytes),r=0;for(let e=t.indexOf(`
5
5
  `,r);e>=0;e=t.indexOf(`
6
- `,r))f(t,r,e),r=e+1,u===d&&(yield m(u,i,l),i=new Float64Array(d),l=s.map(()=>new Float64Array(d)),u=0);p=t.slice(r)}p.trim()&&f(p,0,p.length),u&&(yield m(u,i.slice(0,u),l.map(e=>e.slice(0,u))));return}let h=t.recordSize,g=Br[a.ft],_=Math.max(1,Math.floor(Math.min(n,d*h)/h)),v=t.samples;for await(let n of o.windows(t.offset,Math.min(t.length,t.samples*h),_*h)){e.signal?.throwIfAborted();let t=Math.min(v,Math.floor(n.bytes.length/h));if(t<=0)break;let r=i(n.bytes),o=new Float64Array(t);if(!l)for(let e=0;e<t;e++)o[e]=r.getUint32(e*h+4,!0);yield m(t,o,s.map(e=>{let n=new Float64Array(t);if(e<c){let{a:i,b:o}=a.analog[e],s=8+e*g;if(a.ft===`BINARY`)for(let e=0,a=s;e<t;e++,a+=h){let t=r.getInt16(a,!0);n[e]=t===-32768?NaN:i*t+o}else if(a.ft===`BINARY32`)for(let e=0,a=s;e<t;e++,a+=h){let t=r.getInt32(a,!0);n[e]=t===-2147483648?NaN:i*t+o}else for(let e=0,a=s;e<t;e++,a+=h)n[e]=i*r.getFloat32(a,!0)+o}else{let i=e-c,a=8+c*g+2*(i>>4),o=1<<(i&15);for(let e=0,i=a;e<t;e++,i+=h)n[e]=r.getUint16(i,!0)&o?1:0}return n})),v-=t}}function Kr(e,t){if(t+24>e.length||e[t]!==37||e[t+1]!==235)return!1;let n=0;for(let r=0;r<22;r+=2)n+=e[t+r]|e[t+r+1]<<8;if((n&65535)!=(e[t+22]|e[t+23]<<8))return!1;let r=(e[t+4]|e[t+5]<<8|e[t+6]<<16)+e[t+7]*16777216,i=(e[t+8]|e[t+9]<<8|e[t+10]<<16)+e[t+11]*16777216,a=e[t+14]&128?36:24;return r<=(e[t+15]===1?134217728:524288)&&i+a<=r}const qr={id:`ch10`,label:`IRIG 106 Chapter 10`,extensions:[`.ch10`,`.c10`],sniff:e=>Kr(e,0)},Jr=(e,t)=>(e[t]|e[t+1]<<8|e[t+2]<<16)+e[t+3]*16777216;function Yr(e,t){let{b:n,dv:r,o:i}=e;if(e.flags&128){let e=0,t=0;for(let a=24;a<34;a+=2)e+=r.getUint16(i+a,!0),t+=n[i+a]+n[i+a+1];let a=r.getUint16(i+34,!0);if((e&65535)!==a&&(t&65535)!==a)return!1}let a=[0,1,2,4][e.flags&3];if(!a)return!0;let o=i+e.hdr,s=i+t-a;if((s-o)%a)return!1;let c=0;if(a===1){for(let e=o;e<s;e++)c+=n[e];return(c&255)===n[s]}if(a===2){for(let e=o;e<s;e+=2)c+=r.getUint16(e,!0);return(c&65535)===r.getUint16(s,!0)}for(let e=o;e<s;e+=4)c=(c+r.getUint32(e,!0))%4294967296;return c===r.getUint32(s,!0)}async function*Xr(e,t,r,i){let a=e.size,o={},s=(e,t,n)=>Kr(e,t)&&n+Jr(e,t+4)<=a,c=0,l=!1;for(;c<a;){i?.throwIfAborted();let u=await e.slice(c,Math.min(n,a-c)),d=new DataView(u.buffer,u.byteOffset,u.byteLength),f=0,p=-1;for(;p<0;){if(c+f+24>a){c+f<a&&!l&&(r.cut=!0),p=a;break}if(f+24>u.length){p=c+f;break}let n=c+f;if(Kr(u,f)&&n+Jr(u,f+4)>a){r.cut=!0,p=a;break}if(!s(u,f,n)){l||=(r.damaged++,!0);let e=f+1;for(;e+24<=u.length&&!(u[e]===37&&u[e+1]===235&&s(u,e,c+e));)e++;f=e;continue}l=!1;let i=Jr(u,f+4);if(f+i>u.length){if(i<=16777216){p=n;break}let a=await e.slice(n,i);Zr(o,a,new DataView(a.buffer,a.byteOffset,a.byteLength),0,n,i,t,r),p=n+i;break}Zr(o,u,d,f,n,i,t,r),f+=Math.max(i,24)}c=p,yield}}function Zr(e,t,n,r,i,a,o,s){if(e.b=t,e.dv=n,e.o=r,e.at=i,e.ch=n.getUint16(r+2,!0),e.flags=t[r+14],e.type=t[r+15],e.rtc=n.getUint32(r+16,!0)+n.getUint16(r+20,!0)*4294967296,e.hdr=e.flags&128?36:24,e.dlen=Jr(t,r+8),!Yr(e,a)){s.damaged++;return}o(e)}function Qr(e,t,n){let r=e.getUint32(t,!0),i=e.getUint32(t+4,!0);return n===1?i+r/1e9:n===2?(i*4294967296+r)/1e9:(i>>>0)*.01+(r>>>16)*1e-6}function $r(e,t){let{dv:n}=e;if(!(e.flags&64)||!(e.flags&128))return n.getUint32(t,!0)+n.getUint16(t+4,!0)*4294967296;let r=e.flags>>2&3;return e.rtc+(Qr(n,t,r)-Qr(n,e.o+24,r))*1e7}function ei(e,t){let{dv:n}=e,r=e.o+e.hdr;if(e.dlen<10)return null;let i=n.getUint32(r,!0);if((i>>4&15)==15||(i&15)==15)return null;let a=i>>9&1;if(a&&e.dlen<12)return null;let o=e=>n.getUint16(r+4+2*e,!0),s=(e,t,n=15)=>e>>t&n,c=[s(o(0),0),s(o(0),4),s(o(0),8),s(o(0),12,7),s(o(1),0),s(o(1),4,7),s(o(1),8),s(o(1),12,3),s(o(2),0),s(o(2),4)];if(c.some(e=>e>9))return null;let l=c[0]*10+c[1]*100,u=c[2]+c[3]*10,d=c[4]+c[5]*10,f=c[6]+c[7]*10;if(u>60||d>59||f>23)return null;if(!a){let e=s(o(2),8,3),n=c[8]+c[9]*10+e*100;return e>3||n<1||n>366?null:(n===1&&t.day>=365&&t.year++,t.day=n,{ms:Date.UTC(t.year,0,n,f,d,u,l),hasYear:!1})}let p=s(o(2),8)+s(o(2),12,1)*10,m=[s(o(3),0),s(o(3),4),s(o(3),8),s(o(3),12,3)];if(m.some(e=>e>9)||s(o(2),8)>9||p<1||p>12)return null;let h=c[8]+c[9]*10;return h<1||h>31?null:{ms:Date.UTC(m[0]+m[1]*10+m[2]*100+m[3]*1e3,p-1,h,f,d,u,l),hasYear:!0}}const ti=4e6;function ni(e){let t=new Map;for(let n of e.split(`;`)){let e=n.indexOf(`:`);if(e<0)continue;let r=n.slice(0,e).replace(/\s+/g,``).toUpperCase();r&&t.set(r,n.slice(e+1).trim())}return t}const I=e=>e!==void 0&&/^\s*[+-]?\d+\s*$/.test(e)?Number(e):null,ri=e=>{if(e===void 0||e.trim()===``)return null;let t=Number(e);return Number.isFinite(t)?t:null};function ii(e,t){let n=[];for(let r of e.keys()){let e=t.exec(r);e&&n.push(e)}return n}const ai=new WeakMap;function oi(e,t){let n=ai.get(e);if(!n){ai.set(e,n=new Map);for(let t of e.keys()){let e=/^(.*\D)(\d+)$/.exec(t);if(!e)continue;let r=n.get(e[1]);r?r.push([t,e[2]]):n.set(e[1],[[t,e[2]]])}}return n.get(t)??[]}function si(e){for(let t of[`G\\OD`,`G\\UD`,`G\\RD`]){let n=/(\d{4})\s*$/.exec(e.get(t)??``);if(n)return Number(n[1])}return null}const ci=e=>t=>{let n=0;for(let r=0;r<e.length;r++)n+=e[r]*t**r;return n};function li(e,t,n){let r=n+1,i=Array.from({length:r},()=>Array(r+1).fill(0));for(let n=0;n<e.length;n++)for(let a=0;a<r;a++){for(let t=0;t<r;t++)i[a][t]+=e[n]**(a+t);i[a][r]+=t[n]*e[n]**a}for(let e=0;e<r;e++){let t=e;for(let n=e+1;n<r;n++)Math.abs(i[n][e])>Math.abs(i[t][e])&&(t=n);if(i[t][e]===0)return null;[i[e],i[t]]=[i[t],i[e]];for(let t=0;t<r;t++){if(t===e)continue;let n=i[t][e]/i[e][e];for(let a=e;a<=r;a++)i[t][a]-=n*i[e][a]}}return i.map((e,t)=>e[r]/e[t])}function ui(e){return e.sort((e,t)=>e[0]-t[0]),t=>{let n=0;for(;n<e.length-2&&t>e[n+1][0];)n++;let[r,i]=e[n],[a,o]=e[n+1];return i+(t-r)*(o-i)/(a-r)}}function di(e,t){let n=n=>e.get(`C-${t}\\${n}`),r={unit:n(`MN3`)??``,bfm:n(`BFM`)?.toUpperCase()??null,fpf:n(`FPF`)?.toUpperCase()??null,apply:null,unsupported:null},i=(n(`DCT`)??`NON`).toUpperCase();if(i===`PRS`){let e=Math.min(32,I(n(`PS\\N`))??0),t=[];for(let r=1;r<=e;r++){let e=ri(n(`PS3-${r}`)),i=ri(n(`PS4-${r}`));e!==null&&i!==null&&t.push([e,i])}if(t.length<2||new Set(t.map(e=>e[0])).size!==t.length)r.unsupported=`pair sets that do not define a conversion`;else if((n(`PS1`)??`N`).toUpperCase()===`Y`){let e=Math.min(I(n(`PS2`))??t.length-1,t.length-1,5),i=li(t.map(e=>e[0]),t.map(e=>e[1]),Math.max(1,e));i?r.apply=ci(i):r.unsupported=`pair sets that do not define a conversion`}else r.apply=ui(t)}else if(i===`COE`||i===`NPC`){let e=i===`COE`?`CO`:`NPC`,t=I(n(`${e}\\N`)),a=t!==null&&t>=0&&t<=100?[ri(n(e)),...Array.from({length:t},(t,r)=>ri(n(`${e}-${r+1}`)))]:[];if(!a.length||a.some(e=>e===null))r.unsupported=`coefficients missing`;else if(i===`COE`)r.apply=ci(a);else{let e=ci(a);r.apply=t=>e(1/t)}}else i!==`NON`&&(r.unsupported=`conversion type ${i}`);return r}function fi(e){let t=new Map;for(let n of ii(e,/^C-(\d+)\\DCN$/)){let r=e.get(n[0]);t.has(r)||t.set(r,di(e,n[1]))}return t}function pi(e,t,n,r){let i=2**(t-1);switch(n){case null:case`UNS`:return e;case`TWO`:case`INT`:return e>=i?e-2*i:e;case`OFF`:return e-i;case`ONE`:return e>=i?-(2*i-1-e):e;case`SIG`:return e>=i?-(e-i):e;case`SIM`:return e>=i?e-i:-e;case`FPT`:return t!==32||r!==null&&r!==`IEEE_32`?NaN:(mi.setUint32(0,e),mi.getFloat32(0));case`BCD`:{let n=0;for(let r=Math.ceil(t/4)-1;r>=0;r--){let t=Math.floor(e/2**(4*r))%16;if(t>9)return NaN;n=n*10+t}return n}default:return e}}const mi=new DataView(new ArrayBuffer(4)),hi=(e,t)=>e===null||[`UNS`,`TWO`,`INT`,`OFF`,`ONE`,`SIG`,`SIM`,`BCD`].includes(e)||e===`FPT`&&(t===null||t===`IEEE_32`),gi={1:`ONE`,2:`TWO`,3:`SIG`,4:`SIM`,B:`OFF`,U:`UNS`,F:`FPT`};function _i(e){let t=new Map;for(let n of ii(e,/^R-(\d+)\\TK1-(\d+)$/)){let r=I(e.get(n[0]));if(r===null||r<0||r>65535||t.has(r))continue;let[i,a]=[n[1],n[2]],o=t=>e.get(`R-${i}\\${t}-${a}`),s=ri(o(`ASR`)),c={id:r,name:o(`DSI`)??``,type:(o(`CDT`)??``).toUpperCase(),dln:o(`CDLN`)??``,rate:s&&s>=1e-6&&s<=1e10?s:null,analog:new Map,discrete:[]};for(let t of oi(e,`R-${i}\\AMN-${a}-`)){let n=t[1],r=I(e.get(`R-${i}\\AMCN-${a}-${n}`))??Number(n);c.analog.set(r,{name:e.get(t[0]),bfm:gi[(e.get(`R-${i}\\AF-${a}-${n}`)??``).toUpperCase()]??null})}for(let t of oi(e,`R-${i}\\DMN-${a}-`).sort((e,t)=>Number(e[1])-Number(t[1]))){let n=(e.get(`R-${i}\\DMSK-${a}-${t[1]}`)??``).toUpperCase();(n===`FW`||/^[01]{1,32}$/.test(n))&&c.discrete.push({name:e.get(t[0]),mask:n===`FW`?null:n})}t.set(r,c)}return t}function vi(e,t){let n=new Map;for(let r of ii(e,/^P-(\d+)\\DLN$/)){let i=r[1],a=e.get(r[0]),o=t=>e.get(`P-${i}\\${t}`),s=I(o(`MF1`)),c=I(o(`MF\\N`))??1,l=I(o(`F1`)),u=I(o(`MF4`));if(s===null||s<2||s>16384||c<1||c>1024||l===null||l<1||l>64||u===null||u<1||u>64){t(`PCM format ${a} (its frame is not described or out of range)`);continue}let d=[u,...Array(s-1).fill(l)];for(let t of oi(e,`P-${i}\\MFW1-`)){let n=I(e.get(t[0])),r=I(o(`MFW2-${t[1]}`));n!==null&&n>=1&&n<s&&r!==null&&r>=1&&r<=64&&(d[n]=r)}let f=d.reduce((e,t)=>e+t,0),p=I(o(`MF2`)),m=(o(`MF5`)??``).replace(/\s/g,``).toUpperCase(),h=ri(o(`D2`)),g=(o(`F2`)??`M`).toUpperCase()===`L`,_=null;if((I(o(`ISF\\N`))??0)>=1){let e=I(o(`IDC1-1`)),t=I(o(`IDC3-1`))??1,n=I(o(`IDC4-1`));if(e!==null&&e>=1&&e<s&&n!==null&&n>=1&&t>=1&&t+n-1<=d[e]&&n<=32){let r=I(o(`IDC6-1`))??0,i=(o(`IDC10-1`)??`INC`).toUpperCase()===`DEC`,a=(o(`IDC5-1`)??`D`).toUpperCase();_={word:e,len:n,shift:d[e]-(t+n-1),lsbFirst:a===`L`||a===`D`&&g,init:r,end:I(o(`IDC8-1`))??(i?r-(c-1):r+c-1),initFrame:I(o(`IDC7-1`))??1,dec:i}}}n.set(a,{dln:a,mfn:c,widths:d,frameBits:Math.max(f,Math.min(p??0,f+65536)),sync:m.length===u&&/^[01X]+$/.test(m)?m:``,bitRate:h&&h>=1e-6&&h<=1e10?h:null,lsbFirst:g,idc:_,params:[]})}for(let r of ii(e,/^D-(\d+)\\DLN$/)){let i=n.get(e.get(r[0]));if(!i)continue;let a=r[1],o=t=>e.get(`D-${a}\\${t}`),s=i.lsbFirst;(I(o(`ML\\N`))??1)>1&&t(`measurement lists after the first of ${i.dln}`);let c=0,l=oi(e,`D-${a}\\MN-1-`).sort((e,t)=>Number(e[1])-Number(t[1]));for(let n of l){let r=n[1],a=e.get(n[0]),l=(o(`LT-1-${r}`)??`WDFR`).toUpperCase();if(l!==`WDFR`){t(`${a} (${l===`TD`?`tagged data`:l===`REL`?`a relative location`:`location type ${l}`})`);continue}let u=(o(`MN3-1-${r}`)??`D`).toUpperCase(),d=u===`L`||u===`D`&&s,f=Math.min(I(o(`MML\\N-1-${r}`))??1,9999),p=null,m=[],h=``;for(let e=1;e<=f&&!h;e++){let t=I(o(`MNF\\N-1-${r}-${e}`))??1;if(t<1||t>8){h=`fragments out of range`;break}let n=[];for(let a=1;a<=t;a++){let t=t=>o(`${t}-1-${r}-${e}-${a}`),s=I(t(`WP`)),l=I(t(`WI`))??0,u=I(t(`FP`))??1,f=I(t(`FI`))??0;if(s===null||s<1||s>=i.widths.length||u<1||u>i.mfn||l<0||f<0){h=`a location outside its frame`;break}let p=(f?Math.floor((i.mfn-u)/f)+1:1)*(l?Math.floor((i.widths.length-1-s)/l)+1:1);if(c+p>ti){h=`too many locations`;break}let m=[];for(let e=u;e<=i.mfn;e+=f||i.mfn)for(let t=s;t<i.widths.length;t+=l||i.widths.length)m.push([e,t]);let g=(t(`WFM`)??`FW`).toUpperCase(),_=g===`FW`||g===``?null:/^[01]+$/.test(g)&&g.length<=i.widths[s]?g.padEnd(i.widths[s],`0`):void 0;if(_===void 0){h=`a bit mask that does not fit its word`;break}let v=(t(`WFT`)??`D`).toUpperCase();n.push({pos:m,mask:_,lsbFirst:v===`D`?d:v===`L`,at:I(t(`WFP`))??a})}if(h)break;n.sort((e,t)=>e.at-t.at);let a=n.map(e=>({mask:e.mask,lsbFirst:e.lsbFirst}));if(p&&JSON.stringify(p)!==JSON.stringify(a)){h=`locations that differ in their fragments`;break}p=a;let s=n[0].pos.length;if(n.some(e=>e.pos.length!==s)){h=`fragments in different numbers of places`;break}for(let e=0;e<s;e++){let t=n[0].pos[e][0];if(n.some(n=>n.pos[e][0]!==t)){h=`fragments in different minor frames`;break}m.push({frame:t,words:n.map(t=>t.pos[e][1])})}(c+=s+i.mfn)>ti&&(h=`too many locations`)}if(!h&&p&&p.reduce((e,t,n)=>e+(p[n].mask?[...p[n].mask].filter(e=>e===`1`).length:i.widths[m[0]?.words[n]??0]),0)>64&&(h=`more than 64 bits`),h||!p||!m.length){t(`${a} (${h||`no location`})`);continue}let g=new Set,_=m.filter(e=>{let t=`${e.frame}:${e.words.join(`,`)}`;return g.has(t)?!1:(g.add(t),!0)});_.sort((e,t)=>e.frame-t.frame||Math.min(...e.words)-Math.min(...t.words)),i.params.push({name:a,frags:p,occ:_})}}return n}function yi(e,t){let n=[],r=0;for(let t of e.widths)n.push(r),r+=t;let i=Math.max(r,e.frameBits),a=-i&8*t-1;return{offsets:n,frameBytes:(i+a)/8,tail:a?i-i%(8*t):1/0,fill:a}}function bi(e,t){let n=e.widths[0],r=n<=16?16:n<=32?32:t===4?Math.ceil(n/32)*32:Math.ceil(n/16)*16,i=[r-n],a=r;for(let t=1;t<e.widths.length;t++){let n=Math.ceil(e.widths[t]/16)*16;i.push(a+n-e.widths[t]),a+=n}return t===4&&a%32&&(a+=16),{offsets:i,frameBytes:a/8,tail:1/0,fill:0}}function xi(e,t,n,r,i){let a=0,o=r,s=i;for(;s>0;){let r=e[t+(o>>3^n)],i=o&7,c=Math.min(8-i,s);a=a*(1<<c)+(r>>8-i-c&(1<<c)-1),s-=c,o+=c}return a}function Si(e,t,n,r){let i=0,a=0,o=n;for(;a<r;){let n=o&7,s=Math.min(8-n,r-a);i+=(e[t+(o>>3)]>>n&(1<<s)-1)*2**a,a+=s,o+=s}return i}function Ci(e,t){let n=0;for(let r=0;r<t;r++)n=n*2+e%2,e=Math.floor(e/2);return n}function wi(e,t,n){let r=e.offsets[t],i=Math.min(Math.max(e.tail-r,0),n),a=(t,n)=>xi(e.b,e.base,e.xor,e.bit0+t,n);return i===n?a(r,n):i===0?a(r+e.fill,n):a(r,i)*2**(n-i)+a(e.tail+e.fill,n-i)}function Ti(e,t,n){let r=t.frags.map(e=>e.mask?[...e.mask].flatMap((e,t)=>e===`1`?[t]:[]):null),i=t.frags.map(e=>e.lsbFirst),a=n?.bfm??null,o=n?.fpf??null,s=n?.apply??null;return(t,n)=>{let c=0,l=0;for(let a=0;a<n.length;a++){let o=n[a],s=e.widths[o],u=wi(t,o,s);i[a]&&(u=Ci(u,s));let d=r[a];if(d)for(let e of d)c=c*2+Math.floor(u/2**(s-1-e))%2,l++;else c=c*2**s+u,l+=s}let u=pi(c,l,a,o);return s?s(u):u}}function Ei(e,t){let n=e.idc,r=e.widths[n.word],i=Math.floor(wi(t,n.word,r)/2**n.shift)%2**n.len;return n.lsbFirst&&(i=Ci(i,n.len)),i<Math.min(n.init,n.end)||i>Math.max(n.init,n.end)?0:((((n.dec?n.init-i:i-n.init)%e.mfn+e.mfn)%e.mfn+n.initFrame-1)%e.mfn+e.mfn)%e.mfn+1}var Di=class{#e=new Uint8Array;#t=0;#n=0;#r=!1;#i=[];#a;#o;#s;constructor(e){this.#a=e,this.#o=e.frameBits,this.#s=yi(e,2).offsets}#c(e){let t=this.#a.sync,n=this.#e;for(let r=0;r<t.length;r++){let i=t.charCodeAt(r);if(i===88)continue;let a=e+r;if((n[a>>3]>>7-(a&7)&1)!=i-48)return!1}return!0}push(e,t,n,r,i,a){n-=n%(r+1);let o=this.#n>>3,s=(this.#t>>3)-o,c=new Uint8Array(s+n);c.set(this.#e.subarray(o,o+s));for(let i=0;i<n;i++)c[s+i]=e[t+(i^r)];this.#e=c,this.#n-=o*8,this.#t=c.length*8;for(let e of this.#i)e.bit-=o*8;for(;this.#i.length>1&&this.#i[1].bit<=this.#n;)this.#i.shift();this.#i.push({bit:s*8,sec:i});let l=this.#a.sync.length,u={b:c,base:0,xor:0,bit0:0,offsets:this.#s,tail:1/0,fill:0};for(;;){if(!this.#r){let e=this.#n;for(;e+l<=this.#t&&!this.#c(e);)e++;if(this.#n=e,e+l>this.#t)return;this.#r=!0}if(this.#n+this.#o>this.#t)return;if(!this.#c(this.#n)){this.#r=!1,this.#n++;continue}let e=this.#i.length-1;for(;e>0&&this.#i[e].bit>this.#n;)e--;let t=this.#i[e];u.bit0=this.#n,a(u,t.sec+(this.#a.bitRate?(this.#n-t.bit)/this.#a.bitRate:0)),this.#n+=this.#o}}};function Oi(e){let t=[[[0],`Computer-generated`,`computer-generated`],[[1],`TMATS`,`TMATS`],[[2],`Recording events`,`recording event`],[[3],`Recording index`,`recording index`],[[4],`Streaming configuration`,`streaming configuration`],[[9],`PCM`,`PCM`],[[17],`Time`,`time`],[[18],`Network time`,`network time`],[[25,26],`MIL-STD-1553`,`MIL-STD-1553`],[[33],`Analog`,`analog`],[[41],`Discrete`,`discrete`],[[48],`Message`,`message`],[[56],`ARINC-429`,`ARINC-429`],[[64,65,66,67,68],`Video`,`video`],[[72,73,74],`Image`,`image`],[[80],`UART`,`UART`],[[88,89],`IEEE 1394`,`IEEE 1394`],[[96],`Parallel`,`parallel`],[[104,105],`Ethernet`,`Ethernet`],[[112,113,114],`TSPI/CTS`,`TSPI/CTS`],[[120],`CAN bus`,`CAN bus`],[[121,122],`Fibre Channel`,`Fibre Channel`]].find(([t])=>t.includes(e)),n=`data type 0x${e.toString(16).padStart(2,`0`)}`;return t?[t[1],t[2]]:[n[0].toUpperCase()+n.slice(1),n]}const ki=(e,t,n=`${t}s`)=>`${e} ${e===1?t:n}`,Ai=(e,t)=>{let n=e.ref??e.first;return n?(n.ms-e.baseMs)/1e3+ji(t-n.rtc)/1e7:ji(t-(e.baseRtc??0))/1e7},ji=e=>e-Math.round(e/2**48)*2**48;function Mi(e,t){let{dv:n}=e,r=e.o+e.hdr;if(e.dlen<4)return null;let i=n.getUint32(r,!0),a=i>>>28&1,o=i>>>16&255||256,s=a?1:o;if(e.dlen<4*s)return null;let c=[];for(let e=0;e<o;e++){let t=a?i:n.getUint32(r+4*e,!0),o=t&3;if(o===2)return null;c.push({sub:a?e+1:t>>>8&255||256,factor:t>>>24&15,len:t>>>2&63||64,mode:o})}let l=c.map(e=>`${e.sub}/${e.factor}/${e.len}/${e.mode}`).join(`,`);if(t)return l===t.sig?t:`other`;let u=2**Math.max(...c.map(e=>e.factor)),d=e=>e.mode?Math.ceil(e.len/16)*16:e.len;if(c.reduce((e,t)=>e+d(t)*(u/2**t.factor),0)>(e.dlen-4*s)*8)return null;let f=[],p=0;for(let e=0;e<u;e++){let t=[];c.forEach((n,r)=>{(e+1)%2**n.factor||(t.push([r,p+(n.mode===1?d(n)-n.len:0)]),p+=d(n))}),f.push(t)}return{sig:l,subs:c,ncsdw:s,nsim:u,sims:f,schedBits:p}}function Ni(e,t,n,r){let i=n.model.convs,a=yi(t,2).offsets,o=new Map,s=t.params.map(e=>{let n=Array.from({length:t.mfn+1},()=>[]);for(let t of e.occ)n[t.frame].push(t.words);return n}),c=s.map(e=>e.some(e=>e.length>1));t.params.forEach((e,t)=>{let n=s[t].map(e=>e.map(e=>c[t]?Math.min(...e.map(e=>a[e])):-1).join(`,`)).join(`|`)+(c[t]?`+`:``),r=o.get(n);r?r.push(t):o.set(n,[t])});let l=t.bitRate?t.bitRate/t.frameBits:null,u=0;return{f:t,groups:[...o].map(([o,d])=>{let f=d[0],p=s[f].reduce((e,t)=>e+t.length,0),m=p===t.mfn?``:p%t.mfn===0?` (×${p/t.mfn})`:t.mfn%p===0?` (÷${t.mfn/p})`:` (${p}/${t.mfn})`;return{gid:n.out.id(`p:${e}:${o}`,()=>({name:r+m,rate:l?l*p/t.mfn:null,order:u++,channels:d.map(e=>({name:t.params[e].name,unit:i.get(t.params[e].name)?.unit??``}))})),params:d,rows:s[f].map((e,n)=>e.map((e,r)=>({dt:c[f]&&t.bitRate?Math.min(...e.map(e=>a[e]))/t.bitRate:0,words:d.map(e=>s[e][n][r])})))}}),layouts:new Map,framer:null,counter:0,readers:t.params.map(e=>Ti(t,e,i.get(e.name)))}}function Pi(e,t,n,r,i){let a=e.f.idc?Ei(e.f,t):r;if(!a){i.problems.frames++;return}let o=i.out;for(let r of e.groups)for(let i of r.rows[a])if(o.row(r.gid,n+i.dt))for(let n=0;n<r.params.length;n++)o.put(r.gid,n,e.readers[r.params[n]](t,i.words[n]))}function Fi(e,t,n){let{dv:r}=e,i=e.o+e.hdr,a=()=>{n.problems.pcmMismatch++};if(e.dlen<4)return a();let o=r.getUint32(i,!0),s=o>>>18&1,c=o>>>19&1,l=o>>>20&1,u=o>>>21&1?4:2,d=u-1,f=Ai(n.clock,e.rtc),p=t.f;if(s+c+l!==1)return a();if(l){if(!p.sync)return a();t.framer??=new Di(p),t.framer.push(e.b,i+4,e.dlen-4,d,f,(e,r)=>Pi(t,e,r,t.counter++%p.mfn+1,n));return}let m=c*2+ +(u===4),h=t.layouts.get(m);h||t.layouts.set(m,h=c?yi(p,u):bi(p,u));let g=o>>>30&1?u===4?12:10:0,_=g+h.frameBytes,v=(e.dlen-4)/_;if(!Number.isInteger(v))return a();o>>>29&1&&(t.counter=0);let y={b:e.b,base:0,xor:d,bit0:0,offsets:h.offsets,tail:h.tail,fill:h.fill};for(let r=0;r<v;r++){let a=i+4+r*_;y.base=a+g,Pi(t,y,g?Ai(n.clock,$r(e,a)):f+(p.bitRate?r*p.frameBits/p.bitRate:0),t.counter++%p.mfn+1,n)}}function Ii(e,t,n,r,i,a){let o=Mi(e,n.layout);if(o===`other`){r.problems.analogLayout++;return}if(!o){r.problems.damaged++;return}if(!n.layout){n.layout=o;let e=new Map;o.subs.forEach((t,n)=>{let r=e.get(t.factor);r?r.push(n):e.set(t.factor,[n])});let s=[...e.keys()].sort((e,t)=>e-t),c=o.subs.map(e=>a?.analog.get(e.sub));n.convs=c.map(e=>e?r.model?.convs.get(e.name):void 0),n.bfm=c.map((e,t)=>n.convs[t]?.bfm??e?.bfm??null);for(let a of s){let s=e.get(a),l=r.out.id(`a:${t}:${a}`,()=>({name:a?`${i} (÷${2**a})`:i,order:a,rate:(n.rate??r.rates.get(t)??NaN)/2**a,channels:s.map(e=>({name:c[e]?.name||`Subchannel ${o.subs[e].sub}`,unit:n.convs[e]?.unit??``}))}));n.groups.set(a,{gid:l,subs:s})}}let s=Math.floor((e.dlen-4*o.ncsdw)*8/o.schedBits);n.packets++,n.first=Math.min(n.first,e.rtc),e.rtc>=n.last&&(n.last=e.rtc,n.lastSims=s*o.nsim),n.sims+=s*o.nsim;let c=n.rate??r.rates.get(t)??1/0,l=Ai(r.clock,e.rtc),u=e.o+e.hdr+4*o.ncsdw,d=r.out,f=new Int32Array(o.subs.length);for(let e of n.groups.values())e.subs.forEach((e,t)=>{f[e]=t});for(let t=0;t<s;t++)for(let r=0;r<o.nsim;r++){let i=l+(t*o.nsim+r)/c;for(let[a,s]of n.groups)if(!((r+1)%2**a||!d.row(s.gid,i)))for(let[i,c]of o.sims[r]){if(o.subs[i].factor!==a)continue;let r=o.subs[i],l=pi(Si(e.b,u,t*o.schedBits+c,r.len),r.len,n.bfm[i],n.convs[i]?.fpf??null),p=n.convs[i]?.apply;d.put(s.gid,f[i],p?p(l):l)}}}function Li(e,t,n){let{dv:r}=e,i=e.o+e.hdr;if(e.dlen<4){n.problems.damaged++;return}let a=r.getUint32(i,!0),o=a>>>3&31||32,s=a>>>1&1,c=Math.floor((e.dlen-4)/12);for(let a=0;a<c;a++){let c=i+4+12*a;if(!n.out.row(t.gid,Ai(n.clock,$r(e,c))))continue;let l=r.getUint32(c+8,!0);s&&o<32&&(l>>>=32-o),t.masks.forEach((e,r)=>{let i=0;for(let t of e)i=i*2+(l>>>t&1);n.out.put(t.gid,r,i)})}}const Ri=e=>[...e].flatMap((t,n)=>t===`1`?[e.length-1-n]:[]);async function*zi(e,t,n,r,i){let a=new Map,o=t.model,s=(e,t)=>o?.rch.get(e)?.name||`${t} ${e}`,c={year:o?.year??1970,day:0},l=0,u=e=>{if(r){let t=r.get(e.ch);t||r.set(e.ch,t=new Map),t.set(e.type,(t.get(e.type)??0)+1)}++l%4096==0&&t.out.row(-2,0);let n=t.clock;if(n.baseRtc??=e.rtc,e.type===17){let t=ei(e,c);t&&(n.ref={rtc:e.rtc,ms:t.ms},n.first||(n.first=n.ref,n.baseMs=t.ms,n.firstHasYear=t.hasYear));return}if(e.type!==33&&e.type!==41&&e.type!==9)return;let i=`${e.type}:${e.ch}`,u=a.get(i);if(!u){u={id:e.ch};let n=o?.rch.get(e.ch);if(e.type===33)u.analog={layout:null,groups:new Map,convs:[],bfm:[],rate:n?.rate??null,first:1/0,last:-1/0,sims:0,lastSims:0,packets:0};else if(e.type===41){let r=n?.discrete??[],i=(e.dlen>=4?e.dv.getUint32(e.o+e.hdr,!0)>>>3:0)&31||32,a=Array.from({length:i},(e,t)=>i-1-t),c=r.length?r.map(e=>({name:e.name,bits:e.mask?Ri(e.mask):a})):Array.from({length:i},(t,n)=>({name:`Discrete ${e.ch} bit ${n}`,bits:[n]})),l=s(e.ch,`Discrete`),d=t.out.id(`d:${e.ch}`,()=>({name:l,rate:null,order:0,channels:c.map(e=>({name:e.name,unit:o?.convs.get(e.name)?.unit??``}))}));u.discrete={gid:d,masks:c.map(e=>e.bits)}}else{let r=n?o?.pcm.get(n.dln):void 0;r&&r.params.length&&(u.pcm=Ni(e.ch,r,t,s(e.ch,`PCM`)))}a.set(i,u)}u.analog?Ii(e,e.ch,u.analog,t,s(e.ch,`Analog`),o?.rch.get(e.ch)):u.discrete?Li(e,u.discrete,t):u.pcm?Fi(e,u.pcm,t):t.problems.noFormat.set(e.ch,(t.problems.noFormat.get(e.ch)??0)+1)};for(let t=Xr(e,u,n,i);!(await t.next()).done;)yield;if(t.plan)for(let e of a.values()){let n=e.analog;n&&n.rate===null&&n.packets>1&&n.last>n.first&&t.rates.set(e.id,(n.sims-n.lastSims)/((n.last-n.first)/1e7))}}async function Bi(e,t){let n=[],r=0,i=0,a=!1,o=!1,s=new TextDecoder(`latin1`),c=Xr(e,e=>{if(a)return;if(e.type!==1){a=!0;return}if(e.dlen<4)return;let c=e.dv.getUint32(e.o+e.hdr,!0);if(i||=c&255,c>>>9&1){o=!0,a=!0;return}let l=Math.min(e.dlen-4,1048576-r);n.push(s.decode(e.b.subarray(e.o+e.hdr+4,e.o+e.hdr+4+l))),r+=l,r>=1048576&&(a=!0,t.push(`The setup record is longer than 1 MB; only its first 1 MB was read.`))},{damaged:0,cut:!1});for(;!a&&!(await c.next()).done;);return await c.return(void 0),o&&t.push(`The setup record is in TMATS XML, which Kymoscope does not read: channels are named by their ids, and PCM is not decoded.`),n.length?{text:n.join(``),version:i}:null}const Vi={7:`106-07`,8:`106-09`,9:`106-11`,10:`106-13`,11:`106-15`,12:`106-17`},Hi={...qr,async plan(e,t){try{return await Ui(t)}catch(e){throw k(e)}},async*stream(e){let t=e.plan.state,n=new Map(t.keys.map((e,t)=>[e,t])),r=new Map,i=e=>{e.cap=Math.max(1,Math.min(65536,e.total-e.start)),e.time=new Float64Array(e.cap),e.cols=e.cols.map(()=>new Float64Array(e.cap))};for(let t of e.selection){let n=p(e,t.group),a=new Int32Array(e.plan.groups[t.group].channels.length).fill(-1);n.forEach((e,t)=>{a[e]=t});let o={cols:n.map(()=>new Float64Array),slot:a,time:new Float64Array,n:0,cap:0,start:0,total:e.plan.groups[t.group].samples};i(o),r.set(t.group,o)}let a=[],o=(e,t)=>{let n=t.n===t.cap;if(a.push({group:e,time:n?t.time:t.time.slice(0,t.n),start:t.start,length:t.n,columns:t.cols.map(e=>n?e:e.slice(0,t.n))}),t.start+=t.n,n)i(t);else for(let e of t.cols)e.fill(0,0,t.n);t.n=0},s,c=-1,l={model:t.model,out:{id:e=>n.get(e)??-1,row(e,n){if(e===-2){for(let[e,t]of r)t.n&&o(e,t);return!1}return s=r.get(e),!s||s.start+s.n>=s.total?!1:(s.n===s.cap&&o(e,s),c=s.n++,s.time[c]=n-t.t0,!0)},put(e,t,n){let r=s.slot[t];r>=0&&(s.cols[r][c]=n)}},plan:!1,rates:t.rates,clock:{...t.clock,ref:null},problems:{analogLayout:0,damaged:0,pcmMismatch:0,frames:0,noFormat:new Map}};try{for(let t=zi(e.io,l,{damaged:0,cut:!1},null,e.signal);!(await t.next()).done;)yield*a,a.length=0}catch(e){throw k(e)}for(let[e,t]of r)t.n&&o(e,t);yield*a},streamGroup(e,t){return this.stream({...e,selection:e.selection.filter(e=>e.group===t)})}};async function Ui(e){let t=[],n={},r=await Bi(e,t),i=null,a=[];if(r){let e=ni(r.text);i={attrs:e,rch:_i(e),convs:fi(e),pcm:vi(e,e=>a.push(e)),year:si(e)??1970};for(let[t,r]of[[`program`,`G\\PN`],[`test item`,`G\\TA`],[`test number`,`G\\TN`],[`setup record date`,`G\\OD`]]){let i=e.get(r);i&&(n[t]=i)}}let o=new Map,s=[],c=[],l=1/0,u=1/0,d={id(e,t){let n=o.get(e);return n||(n={def:null,id:c.length},o.set(e,n),c.push({key:e,def:t}),s.push(0)),n.id},row(e,t){return e<0?!1:(s[e]++,f.first?l=Math.min(l,t):u=Math.min(u,t),!1)},put(){}},f={ref:null,first:null,baseMs:0,baseRtc:null,firstHasYear:!1},p={analogLayout:0,damaged:0,pcmMismatch:0,frames:0,noFormat:new Map},m=new Map,h={damaged:0,cut:!1},g={model:i,out:d,problems:p,rates:new Map,plan:!0,clock:f};for(let t=zi(e,g,h,m);!(await t.next()).done;);if(m.size===0)throw Error(`This is not an IRIG 106 Chapter 10 file: no packets were found.`);let _=c.map((e,t)=>({...e,i:t})).filter(e=>s[e.i]>0),v=e=>Number(e.split(`:`)[1]),y=_.map(e=>({...e,d:e.def()}));y.sort((e,t)=>v(e.key)-v(t.key)||e.d.order-t.d.order||e.i-t.i);let b=cn(y.map(e=>e.d.name),[]),x=y.map((e,t)=>{let n=e.d.rate,r=cn(e.d.channels.map(e=>e.name));return{name:b[t],channels:e.d.channels.map((e,t)=>({name:r[t],unit:e.unit})),samples:s[e.i],time:{kind:`timestamps`},rateHz:n&&Number.isFinite(n)?n:null,irregular:!0}}),S=f.first?u+ji((f.baseRtc??0)-f.first.rtc)/1e7:u,C=Math.min(l,S),w=Number.isFinite(C)?C:0,T=[],E=new Set([1,17,33,41,9,3]);for(let[e,t]of[...m].sort((e,t)=>e[0]-t[0])){n[`Channel ${e}`]=[...t].map(([e,t])=>`${Oi(e)[0]} (${ki(t,`packet`)})`).join(`, `);for(let[n,r]of t)E.has(n)||T.push(`${ki(r,`${Oi(n)[1]} packet`)} (channel ${e})`)}if(T.length&&t.push(`Skipped: ${T.join(`, `)}; they need an ICD or aren't time series.`),p.noFormat.size){let e=[...p.noFormat.values()].reduce((e,t)=>e+t,0);t.push(`Not decoded: ${ki(e,`PCM packet`)} (${p.noFormat.size===1?`channel`:`channels`} ${[...p.noFormat.keys()].join(`, `)}); the setup record has no PCM format with measurements for ${p.noFormat.size===1?`it`:`them`}.`)}let D=h.damaged+p.damaged;D&&t.push(`${ki(D,`damaged packet`)} ${D===1?`was`:`were`} skipped.`),p.pcmMismatch&&t.push(`${ki(p.pcmMismatch,`PCM packet`)} that ${p.pcmMismatch===1?`does`:`do`} not match the setup record's PCM format ${p.pcmMismatch===1?`was`:`were`} skipped.`),p.analogLayout&&t.push(`${ki(p.analogLayout,`analog packet`)} whose subchannels differ from their channel's first packet ${p.analogLayout===1?`was`:`were`} skipped.`),h.cut&&t.push(`The file ends in the middle of a packet.`),p.frames&&t.push(`${ki(p.frames,`PCM minor frame`)} with a subframe ID count outside the major frame ${p.frames===1?`was`:`were`} skipped.`),a.length&&t.push(`Not decoded from the setup record: ${a.slice(0,20).join(`, `)}${a.length>20?`, and ${a.length-20} more`:``}.`);let O=i?[...i.convs].filter(([,e])=>e.unsupported||!hi(e.bfm,e.fpf)).map(([e,t])=>`${e} (${t.unsupported??`binary format ${t.bfm}${t.fpf?` ${t.fpf}`:``}`})`):[];O.length&&t.push(`Read without their conversion or format: ${O.slice(0,20).join(`, `)}${O.length>20?`, and ${O.length-20} more`:``}.`);let k=[...g.rates.keys()].filter(e=>!i?.rch.get(e)?.rate);k.length&&t.push(`The setup record has no sample rate for analog channel ${k.join(`, `)}: estimated from the packet times.`),r||t.push(`This file has no setup record (TMATS): channels are named by their ids, and PCM is not decoded.`);let A=null,j=i?si(i.attrs):null;if(f.first){let e=f.baseMs+w*1e3;(f.firstHasYear||j!==null)&&Math.abs(e)<=864e13&&(A=new Date(e).toISOString()),!f.firstHasYear&&j!==null?t.push(`The time packets give the day of the year; the year (${j}) is the setup record's date.`):f.firstHasYear||t.push(`Its time packets give the day of the year but no year: the start time is not known; times are from the first sample.`)}else t.push(`This file has no time packets: times are from the first sample (recorder clock), and the start time is not known.`);if(!x.length)throw Error(`This Chapter 10 file has no analog, discrete or PCM data Kymoscope can read. ${t.filter(e=>!e.includes(`time packets`)).join(` `)}`.trim());let M={model:i,clock:f,t0:w,keys:y.map(e=>e.key),rates:g.rates};return{format:`IRIG 106 Chapter 10${r&&Vi[r.version]?` (${Vi[r.version]})`:``}`,startTime:A,groups:x,meta:n,events:[],notes:t,interleaved:!0,state:M}}const Wi=()=>({frames:0,other:0,truncated:0,incomplete:0,cut:!1,damagedAt:null}),Gi=new Map([[2712847316,{le:!0,ns:!1}],[3569595041,{le:!1,ns:!1}],[2712812621,{le:!0,ns:!0}],[1295823521,{le:!1,ns:!0}]]),Ki=168627466;function qi(e){if(e.length<24)return null;let t=new DataView(e.buffer,e.byteOffset,e.byteLength).getUint32(0,!0);if(Gi.has(t))return`pcap`;if(t===Ki&&e.length>=12){let t=new DataView(e.buffer,e.byteOffset,e.byteLength).getUint32(8,!0);if(t===439041101||t===1295788826)return`pcapng`}return null}var Ji=class{#e;stats;done=!1;#t=null;#n=!0;#r=!1;#i=1;#a=[];#o=NaN;#s=new Map;#c=0;#l=null;#u={time:0,sport:0,dport:0,b:new Uint8Array,o:0,n:0};constructor(e,t=Wi()){this.#e=e,this.stats=t}feed(e,t){let n=new DataView(e.buffer,e.byteOffset,e.byteLength),r=0,i=e=>{this.stats.damagedAt=t+e,this.done=!0};if(!this.#t){if(this.#t=qi(e),!this.#t)return i(0),0;if(this.#t===`pcap`){let e=Gi.get(n.getUint32(0,!0));this.#n=e.le,this.#r=e.ns,this.#i=n.getUint32(20,this.#n)&65535,r=24}}if(this.#t===`pcap`){let t=this.#n;for(;!this.done&&e.length-r>=16;){let a=n.getUint32(r+8,t);if(a>262144){i(r);break}if(e.length-r-16<a)break;let o=n.getUint32(r,t)*1e3+n.getUint32(r+4,t)/(this.#r?1e6:1e3);this.#f(this.#i,e,n,r+16,a,o),r+=16+a}return r}for(;!this.done&&e.length-r>=12;){let t=n.getUint32(r,this.#n);if(t===Ki){let e=n.getUint32(r+8,!0);if(e!==439041101&&e!==1295788826){i(r);break}this.#n=e===439041101,t=Ki}let a=this.#n,o=n.getUint32(r+4,a);if(o<12||o%4||o>327680){i(r);break}if(e.length-r<o)break;if(n.getUint32(r+o-4,a)!==o){i(r);break}if(t===Ki)this.#a=[];else if(t===1&&o>=20)this.#a.push(this.#d(e,n,r,o));else if(t===6&&o>=32){let t=this.#a[n.getUint32(r+8,a)],i=n.getUint32(r+20,a);if(!t||i>o-32)this.stats.other++;else{let o=(n.getUint32(r+12,a)*4294967296+n.getUint32(r+16,a))*t.tick+t.offsetMs;this.#o=o,this.#f(t.link,e,n,r+28,i,o)}}else if(t===3&&o>=16){let t=this.#a[0],i=Math.min(n.getUint32(r+8,a),o-16);t?this.#f(t.link,e,n,r+12,i,this.#o):this.stats.other++}r+=o}return r}finish(){this.#m(),this.stats.incomplete+=this.#s.size,this.#s.clear(),this.#c=0}#d(e,t,n,r){let i=this.#n,a={link:t.getUint16(n+8,i),tick:.001,offsetMs:0};for(let o=n+16;o+4<=n+r-4;){let s=t.getUint16(o,i),c=t.getUint16(o+2,i);if(s===0||o+4+c>n+r-4)break;if(s===9&&c>=1){let t=e[o+4];a.tick=(t&128?2**-(t&127):10**-t)*1e3}else s===14&&c>=8&&(a.offsetMs=(t.getInt32(o+4+(i?4:0),i)*4294967296+t.getUint32(o+4+(i?0:4),i))*1e3);o+=4+c+(-c&3)}return a}#f(e,t,n,r,i,a){this.stats.frames++;let o=r+i,s=r,c;if(e===1){if(i<14)return void this.stats.other++;for(c=n.getUint16(s+12),s+=14;(c===33024||c===34984||c===37120)&&s+4<=o;)c=n.getUint16(s+2),s+=4}else if(e===113){if(i<16)return void this.stats.other++;c=n.getUint16(s+14),s+=16}else if(e===276){if(i<20)return void this.stats.other++;c=n.getUint16(s),s+=20}else if(e===101||e===228||e===229){if(i<1)return void this.stats.other++;c=t[s]>>4==4?2048:t[s]>>4==6?34525:0}else return void this.stats.other++;c===2048?this.#p(t,n,s,o,a):c===34525?this.#g(t,n,s,o,a):this.stats.other++}#p(e,t,n,r,i){if(r-n<20||e[n]>>4!=4)return void this.stats.other++;let a=(e[n]&15)*4,o=t.getUint16(n+2);if(a<20||o<a||e[n+9]!==17)return void this.stats.other++;if(n+o>r)return void this.stats.truncated++;let s=t.getUint16(n+6),c=(s&8191)*8,l=(s&8192)!=0,u=n+a,d=o-a;if(!c&&!l)return this.#_(e,t,u,u+d,i);if(c+d>65535)return void this.stats.other++;let f=`${t.getUint32(n+12)}:${t.getUint32(n+16)}:${t.getUint16(n+4)}`;this.#l&&this.#l.key!==f&&this.#m();for(let e of this.#s.values()){if(!(e.ms<i-3e4))break;this.#h(e)}for(;this.#s.size&&this.#c+d>67108864;)this.#h(this.#s.values().next().value);let p=e.subarray(u,u+d),m=this.#s.get(f);if(m){let e=Yi(m,c,p,l);if(e<0&&m.whole)return;if(e>=0){m.counted||this.stats.incomplete++,m.counted=!0,m===this.#l&&(this.#l=null),m.whole=null;for(let t of m.parts.splice(0,e+1))m.held-=t.b.length,this.#c-=t.b.length;m.ms=m.parts.reduce((e,t)=>Math.min(e,t.ms),i),this.#s.delete(f),this.#s.set(f,m)}}else{for(;this.#s.size>=1e4;)this.#h(this.#s.values().next().value);this.#s.set(f,m={key:f,parts:[],held:0,ms:i,counted:!1,whole:null,wholeMs:0})}if(m.held+d>2*65535){this.#s.delete(f),this.#c-=m.held,this.stats.incomplete++;return}m.parts.push({off:c,b:p.slice(),ms:i,last:!l}),m.held+=d,this.#c+=d;let h=Xi(m.parts);h&&(m.whole=h,m.wholeMs=i,this.#l=m)}#m(){let e=this.#l;e&&(this.#l=null,this.#s.delete(e.key),this.#c-=e.held,this.#_(e.whole,new DataView(e.whole.buffer),0,e.whole.length,e.wholeMs))}#h(e){if(e===this.#l)return this.#m();this.#s.delete(e.key),this.#c-=e.held,this.stats.incomplete++}#g(e,t,n,r,i){if(r-n<40||e[n]>>4!=6)return void this.stats.other++;let a=n+40+t.getUint16(n+4);if(a>r)return void this.stats.truncated++;let o=e[n+6];for(n+=40;(o===0||o===43||o===60)&&n+8<=a;){let t=e[n];n+=(e[n+1]+1)*8,o=t}if(o!==17||n>a)return void this.stats.other++;this.#_(e,t,n,a,i)}#_(e,t,n,r,i){if(this.#l&&this.#m(),r-n<8)return void this.stats.other++;let a=t.getUint16(n+4);if(a<8)return void this.stats.other++;if(n+a>r)return void this.stats.truncated++;let o=this.#u;o.time=i,o.sport=t.getUint16(n),o.dport=t.getUint16(n+2),o.b=e,o.o=n+8,o.n=a-8,this.#e(o)}};function Yi(e,t,n,r){let i=t+n.length,a=-1;return e.parts.forEach((e,o)=>{let s=e.off+e.b.length;if(e.last&&(r?i>s:i!==s)||!r&&s>i){a=o;return}for(let r=Math.max(t,e.off);r<Math.min(i,s);r++)if(n[r-t]!==e.b[r-e.off]){a=o;return}}),a}function Xi(e){let t=e.find(e=>e.last);if(!t)return null;let n=t.off+t.b.length,r=[...e].sort((e,t)=>e.off-t.off),i=0;for(let e of r){if(e.off>i)return null;i=Math.max(i,e.off+e.b.length)}if(i<n)return null;let a=new Uint8Array(n);for(let e of r)a.set(e.b.subarray(0,Math.max(0,n-e.off)),e.off);return a}async function*Zi(e,t,r,i){let a=new Ji(t,r),o=0;for(;o<e.size&&!a.done;){i?.throwIfAborted();let t=await e.slice(o,Math.min(n,e.size-o)),s=o+t.length>=e.size,c=a.feed(t,o);if(o+=c,s||c===0){!a.done&&o<e.size&&(r.cut=!0);break}yield}a.finish()}function Qi(e,t,n,r=57005){if(n<16||n&1||(e[t+2]<<8|e[t+3])*2!==n)return!1;let i=e[t+n-2]<<8|e[t+n-1];return i===57005||i===r}function $i(e){if(!qi(e))return!1;let t=!1,n=new Ji(e=>{e.n>=16&&!(e.n&1)&&(e.b[e.o+2]<<8|e.b[e.o+3])*2===e.n&&(t=n.done=!0)});try{n.feed(e,0),t||n.finish()}catch{return!1}return t}const ea={id:`iena`,label:`IENA flight-test network capture`,extensions:[`.pcap`,`.pcapng`,`.cap`],companions:[`.xidml`,`.xml`,`.yaml`,`.yml`,`.csv`].map(e=>({ext:e,anyName:!0})),sniff:$i,sniffBytes:e=>qi(e)?1<<20:0};
6
+ `,r))f(t,r,e),r=e+1,u===d&&(yield m(u,i,l),i=new Float64Array(d),l=s.map(()=>new Float64Array(d)),u=0);p=t.slice(r)}p.trim()&&f(p,0,p.length),u&&(yield m(u,i.slice(0,u),l.map(e=>e.slice(0,u))));return}let h=t.recordSize,g=Br[a.ft],_=Math.max(1,Math.floor(Math.min(n,d*h)/h)),v=t.samples;for await(let n of o.windows(t.offset,Math.min(t.length,t.samples*h),_*h)){e.signal?.throwIfAborted();let t=Math.min(v,Math.floor(n.bytes.length/h));if(t<=0)break;let r=i(n.bytes),o=new Float64Array(t);if(!l)for(let e=0;e<t;e++)o[e]=r.getUint32(e*h+4,!0);yield m(t,o,s.map(e=>{let n=new Float64Array(t);if(e<c){let{a:i,b:o}=a.analog[e],s=8+e*g;if(a.ft===`BINARY`)for(let e=0,a=s;e<t;e++,a+=h){let t=r.getInt16(a,!0);n[e]=t===-32768?NaN:i*t+o}else if(a.ft===`BINARY32`)for(let e=0,a=s;e<t;e++,a+=h){let t=r.getInt32(a,!0);n[e]=t===-2147483648?NaN:i*t+o}else for(let e=0,a=s;e<t;e++,a+=h)n[e]=i*r.getFloat32(a,!0)+o}else{let i=e-c,a=8+c*g+2*(i>>4),o=1<<(i&15);for(let e=0,i=a;e<t;e++,i+=h)n[e]=r.getUint16(i,!0)&o?1:0}return n})),v-=t}}var Kr=class extends Error{};const qr=[`name`,`unit`,`channel`,`rt`,`tr`,`sa`,`word`,`label`,`sdi`,`bus`,`bit`,`bits`,`type`,`scale`,`add`];function Jr(e,t){let n=[],r=``,i=!1;for(let a=0;a<e.length;a++){let o=e[a];i?o===`"`&&e[a+1]===`"`?(r+=`"`,a++):o===`"`?i=!1:r+=o:o===`"`?i=!0:o===t?(n.push(r.trim()),r=``):r+=o}return n.push(r.trim()),n}function Yr(e){let t=e.replace(/^\uFEFF/,``).split(/\r?\n/).filter(e=>e.trim()&&!e.trim().startsWith(`#`));if(!t.length)throw new Kr(`it is empty`);let n=t[0].split(`;`).length>t[0].split(`,`).length?`;`:`,`,r=Jr(t[0],n).map(e=>e.toLowerCase());if(!r.includes(`name`)||!r.includes(`rt`)&&!r.includes(`label`))throw new Kr(`its first row must name the columns: name, and rt, tr, sa, word (MIL-STD-1553) or label (ARINC-429)`);let i=r.filter(e=>e&&!qr.includes(e));if(i.length)throw new Kr(`unknown column ${i.map(e=>`"${e}"`).join(`, `)} (columns: ${qr.join(`, `)})`);let a=[];return t.slice(1).forEach((e,t)=>{let i=Jr(e,n),o=e=>{let t=r.indexOf(e);return t>=0?(i[t]??``).trim():``},s=`row ${t+2}`,c=(e,t,n=10)=>{let r=o(e);if(r===``)return t;let i=n===8?parseInt(r,8):Number(r);if(!Number.isFinite(i)||n===8&&!/^[0-7]+$/.test(r))throw new Kr(`${s}: ${e} "${r}" is not ${n===8?`an octal number`:`a number`}`);return i},l=o(`name`);if(!l)throw new Kr(`${s}: no name`);let u=o(`label`)!==``,d=o(`type`).toLowerCase()||`u`;if(![`u`,`s`,`bcd`,`f32`].includes(d))throw new Kr(`${s}: type "${o(`type`)}" (u, s, bcd or f32)`);let f={name:l,unit:o(`unit`),channel:o(`channel`)||null,kind:u?`429`:`1553`,rt:0,tr:`R`,sa:0,words:[],label:0,sdi:null,bus:null,bit:0,bits:0,type:d,scale:c(`scale`,1),add:c(`add`,0)};if(u){if(f.label=c(`label`,0,8),f.sdi=c(`sdi`,null),f.bus=c(`bus`,null),f.bit=c(`bit`,10),f.bits=c(`bits`,19),f.label>255)throw new Kr(`${s}: label ${o(`label`)} is above 377`);if(f.bit+f.bits>32)throw new Kr(`${s}: bit + bits is more than the word's 32`)}else{if(o(`rt`)===``||o(`sa`)===``||o(`word`)===``)throw new Kr(`${s}: a MIL-STD-1553 measurement needs rt, sa and word (or a label for ARINC-429)`);f.rt=c(`rt`,0),f.sa=c(`sa`,0);let e=(o(`tr`)||`R`).toUpperCase();if(e!==`T`&&e!==`R`)throw new Kr(`${s}: tr "${o(`tr`)}" (T or R)`);if(f.tr=e,f.words=o(`word`).split(`+`).map(e=>Number(e.trim())),f.words.some(e=>!Number.isInteger(e)||e<1||e>32)||f.words.length>2)throw new Kr(`${s}: word "${o(`word`)}" (1 to 32, or two as 3+4)`);if(f.bit=c(`bit`,0),f.bits=c(`bits`,16*f.words.length),f.bit+f.bits>16*f.words.length)throw new Kr(`${s}: bit + bits is more than the word's ${16*f.words.length}`);if(f.rt>31||f.sa>31)throw new Kr(`${s}: rt and sa go from 0 to 31`)}if(f.bits<1)throw new Kr(`${s}: bits must be at least 1`);if(d===`f32`&&f.bits!==32)throw new Kr(`${s}: type f32 needs 32 bits (word 3+4 for 1553)`);a.push(f)}),a}const Xr=new DataView(new ArrayBuffer(4));function Zr(e,t){let n=Math.floor(t/2**e.bit)%2**e.bits;if(e.type===`s`&&n>=2**(e.bits-1))n-=2**e.bits;else if(e.type===`bcd`){let t=0;for(let r=Math.ceil(e.bits/4)-1;r>=0;r--)t=t*10+Math.floor(n/16**r)%16;n=t}else e.type===`f32`&&(Xr.setUint32(0,n),n=Xr.getFloat32(0));return n*e.scale+e.add}const Qr=e=>{let t=e&255,n=0;for(let e=0;e<8;e++)n=n<<1|t&1,t>>=1;return n},$r=e=>e.toString(8).padStart(3,`0`);function ei(e,t){if(!e.length)return null;let n=e[0],r;if(t){if(e.length<3)return null;n=e[1],r=3}let i=n>>>11,a=n>>>10&1,o=n>>>5&31,s=n&31;if(o===0||o===31){if(s<16)return null;let t=a?2:1;return e.length>t?{rt:i,tr:a?`T`:`R`,sa:o,mode:s,data:[e[t]]}:null}let c=s||32;return r??=a?2:1,e.length<r+c?null:{rt:i,tr:a?`T`:`R`,sa:o,mode:null,data:e.slice(r,r+c)}}function ti(e,t,n,r,i){if(n<4)return 1;let a=e.getUint32(t,!0)&16777215,o=t+4,s=t+n,c=0;for(let t=0;t<a;t++){if(o+14>s)return c+1;let t=e.getUint16(o+8,!0),n=e.getUint16(o+12,!0);if(o+14+n>s||n%2)return c+1;if(t&5688)c++;else{let a=[];for(let t=0;t<n;t+=2)a.push(e.getUint16(o+14+t,!0));i(r(o),t,a)}o+=14+n}return c}function ni(e,t,n,r,i){if(n<4)return 1;let a=e.getUint32(t,!0)&65535,o=r,s=0;for(let r=0;r<a;r++){let a=t+4+8*r;if(a+8>t+n)return s+1;let c=e.getUint32(a,!0);if(o+=c&1048575,c>>>22&3){s++;continue}i(o,c>>>24,e.getUint32(a+4,!0))}return s}const ri=(e,t,n,r,i,a)=>i===null?`${e} RT${t} ${n} SA${r} W${a}`:`${e} RT${t} mode ${i}`,ii=(e,t,n,r)=>`${e} bus ${t} label ${$r(n)}${r?` SDI ${r}`:``}`,ai=(e,t,n)=>e.filter(e=>e.channel===null||e.channel===String(t)||e.channel===n);function oi(e,t){if(t+24>e.length||e[t]!==37||e[t+1]!==235)return!1;let n=0;for(let r=0;r<22;r+=2)n+=e[t+r]|e[t+r+1]<<8;if((n&65535)!=(e[t+22]|e[t+23]<<8))return!1;let r=(e[t+4]|e[t+5]<<8|e[t+6]<<16)+e[t+7]*16777216,i=(e[t+8]|e[t+9]<<8|e[t+10]<<16)+e[t+11]*16777216,a=e[t+14]&128?36:24;return r<=(e[t+15]===1?134217728:524288)&&i+a<=r}const si={id:`ch10`,label:`IRIG 106 Chapter 10`,extensions:[`.ch10`,`.c10`],sniff:e=>oi(e,0),companions:[{ext:`.csv`,anyName:!0}]},ci=(e,t)=>(e[t]|e[t+1]<<8|e[t+2]<<16)+e[t+3]*16777216;function li(e,t){let{b:n,dv:r,o:i}=e;if(e.flags&128){let e=0,t=0;for(let a=24;a<34;a+=2)e+=r.getUint16(i+a,!0),t+=n[i+a]+n[i+a+1];let a=r.getUint16(i+34,!0);if((e&65535)!==a&&(t&65535)!==a)return!1}let a=[0,1,2,4][e.flags&3];if(!a)return!0;let o=i+e.hdr,s=i+t-a;if((s-o)%a)return!1;let c=0;if(a===1){for(let e=o;e<s;e++)c+=n[e];return(c&255)===n[s]}if(a===2){for(let e=o;e<s;e+=2)c+=r.getUint16(e,!0);return(c&65535)===r.getUint16(s,!0)}for(let e=o;e<s;e+=4)c=(c+r.getUint32(e,!0))%4294967296;return c===r.getUint32(s,!0)}async function*ui(e,t,r,i){let a=e.size,o={},s=(e,t,n)=>oi(e,t)&&n+ci(e,t+4)<=a,c=0,l=!1;for(;c<a;){i?.throwIfAborted();let u=await e.slice(c,Math.min(n,a-c)),d=new DataView(u.buffer,u.byteOffset,u.byteLength),f=0,p=-1;for(;p<0;){if(c+f+24>a){c+f<a&&!l&&(r.cut=!0),p=a;break}if(f+24>u.length){p=c+f;break}let n=c+f;if(oi(u,f)&&n+ci(u,f+4)>a){r.cut=!0,p=a;break}if(!s(u,f,n)){l||=(r.damaged++,!0);let e=f+1;for(;e+24<=u.length&&!(u[e]===37&&u[e+1]===235&&s(u,e,c+e));)e++;f=e;continue}l=!1;let i=ci(u,f+4);if(f+i>u.length){if(i<=16777216){p=n;break}let a=await e.slice(n,i);di(o,a,new DataView(a.buffer,a.byteOffset,a.byteLength),0,n,i,t,r),p=n+i;break}di(o,u,d,f,n,i,t,r),f+=Math.max(i,24)}c=p,yield}}function di(e,t,n,r,i,a,o,s){if(e.b=t,e.dv=n,e.o=r,e.at=i,e.ch=n.getUint16(r+2,!0),e.flags=t[r+14],e.type=t[r+15],e.rtc=n.getUint32(r+16,!0)+n.getUint16(r+20,!0)*4294967296,e.hdr=e.flags&128?36:24,e.dlen=ci(t,r+8),!li(e,a)){s.damaged++;return}o(e)}function fi(e,t,n){let r=e.getUint32(t,!0),i=e.getUint32(t+4,!0);return n===1?i+r/1e9:n===2?(i*4294967296+r)/1e9:(i>>>0)*.01+(r>>>16)*1e-6}function pi(e,t){let{dv:n}=e;if(!(e.flags&64)||!(e.flags&128))return n.getUint32(t,!0)+n.getUint16(t+4,!0)*4294967296;let r=e.flags>>2&3;return e.rtc+(fi(n,t,r)-fi(n,e.o+24,r))*1e7}function mi(e,t){let{dv:n}=e,r=e.o+e.hdr;if(e.dlen<10)return null;let i=n.getUint32(r,!0);if((i>>4&15)==15||(i&15)==15)return null;let a=i>>9&1;if(a&&e.dlen<12)return null;let o=e=>n.getUint16(r+4+2*e,!0),s=(e,t,n=15)=>e>>t&n,c=[s(o(0),0),s(o(0),4),s(o(0),8),s(o(0),12,7),s(o(1),0),s(o(1),4,7),s(o(1),8),s(o(1),12,3),s(o(2),0),s(o(2),4)];if(c.some(e=>e>9))return null;let l=c[0]*10+c[1]*100,u=c[2]+c[3]*10,d=c[4]+c[5]*10,f=c[6]+c[7]*10;if(u>60||d>59||f>23)return null;if(!a){let e=s(o(2),8,3),n=c[8]+c[9]*10+e*100;return e>3||n<1||n>366?null:(n===1&&t.day>=365&&t.year++,t.day=n,{ms:Date.UTC(t.year,0,n,f,d,u,l),hasYear:!1})}let p=s(o(2),8)+s(o(2),12,1)*10,m=[s(o(3),0),s(o(3),4),s(o(3),8),s(o(3),12,3)];if(m.some(e=>e>9)||s(o(2),8)>9||p<1||p>12)return null;let h=c[8]+c[9]*10;return h<1||h>31?null:{ms:Date.UTC(m[0]+m[1]*10+m[2]*100+m[3]*1e3,p-1,h,f,d,u,l),hasYear:!0}}const hi=4e6;function gi(e){let t=new Map;for(let n of e.split(`;`)){let e=n.indexOf(`:`);if(e<0)continue;let r=n.slice(0,e).replace(/\s+/g,``).toUpperCase();r&&t.set(r,n.slice(e+1).trim())}return t}const I=e=>e!==void 0&&/^\s*[+-]?\d+\s*$/.test(e)?Number(e):null,_i=e=>{if(e===void 0||e.trim()===``)return null;let t=Number(e);return Number.isFinite(t)?t:null};function vi(e,t){let n=[];for(let r of e.keys()){let e=t.exec(r);e&&n.push(e)}return n}const yi=new WeakMap;function bi(e,t){let n=yi.get(e);if(!n){yi.set(e,n=new Map);for(let t of e.keys()){let e=/^(.*\D)(\d+)$/.exec(t);if(!e)continue;let r=n.get(e[1]);r?r.push([t,e[2]]):n.set(e[1],[[t,e[2]]])}}return n.get(t)??[]}function xi(e){for(let t of[`G\\OD`,`G\\UD`,`G\\RD`]){let n=/(\d{4})\s*$/.exec(e.get(t)??``);if(n)return Number(n[1])}return null}const Si=e=>t=>{let n=0;for(let r=0;r<e.length;r++)n+=e[r]*t**r;return n};function Ci(e,t,n){let r=n+1,i=Array.from({length:r},()=>Array(r+1).fill(0));for(let n=0;n<e.length;n++)for(let a=0;a<r;a++){for(let t=0;t<r;t++)i[a][t]+=e[n]**(a+t);i[a][r]+=t[n]*e[n]**a}for(let e=0;e<r;e++){let t=e;for(let n=e+1;n<r;n++)Math.abs(i[n][e])>Math.abs(i[t][e])&&(t=n);if(i[t][e]===0)return null;[i[e],i[t]]=[i[t],i[e]];for(let t=0;t<r;t++){if(t===e)continue;let n=i[t][e]/i[e][e];for(let a=e;a<=r;a++)i[t][a]-=n*i[e][a]}}return i.map((e,t)=>e[r]/e[t])}function wi(e){return e.sort((e,t)=>e[0]-t[0]),t=>{let n=0;for(;n<e.length-2&&t>e[n+1][0];)n++;let[r,i]=e[n],[a,o]=e[n+1];return i+(t-r)*(o-i)/(a-r)}}function Ti(e,t){let n=n=>e.get(`C-${t}\\${n}`),r={unit:n(`MN3`)??``,bfm:n(`BFM`)?.toUpperCase()??null,fpf:n(`FPF`)?.toUpperCase()??null,apply:null,unsupported:null},i=(n(`DCT`)??`NON`).toUpperCase();if(i===`PRS`){let e=Math.min(32,I(n(`PS\\N`))??0),t=[];for(let r=1;r<=e;r++){let e=_i(n(`PS3-${r}`)),i=_i(n(`PS4-${r}`));e!==null&&i!==null&&t.push([e,i])}if(t.length<2||new Set(t.map(e=>e[0])).size!==t.length)r.unsupported=`pair sets that do not define a conversion`;else if((n(`PS1`)??`N`).toUpperCase()===`Y`){let e=Math.min(I(n(`PS2`))??t.length-1,t.length-1,5),i=Ci(t.map(e=>e[0]),t.map(e=>e[1]),Math.max(1,e));i?r.apply=Si(i):r.unsupported=`pair sets that do not define a conversion`}else r.apply=wi(t)}else if(i===`COE`||i===`NPC`){let e=i===`COE`?`CO`:`NPC`,t=I(n(`${e}\\N`)),a=t!==null&&t>=0&&t<=100?[_i(n(e)),...Array.from({length:t},(t,r)=>_i(n(`${e}-${r+1}`)))]:[];if(!a.length||a.some(e=>e===null))r.unsupported=`coefficients missing`;else if(i===`COE`)r.apply=Si(a);else{let e=Si(a);r.apply=t=>e(1/t)}}else i!==`NON`&&(r.unsupported=`conversion type ${i}`);return r}function Ei(e){let t=new Map;for(let n of vi(e,/^C-(\d+)\\DCN$/)){let r=e.get(n[0]);t.has(r)||t.set(r,Ti(e,n[1]))}return t}function Di(e,t,n,r){let i=2**(t-1);switch(n){case null:case`UNS`:return e;case`TWO`:case`INT`:return e>=i?e-2*i:e;case`OFF`:return e-i;case`ONE`:return e>=i?-(2*i-1-e):e;case`SIG`:return e>=i?-(e-i):e;case`SIM`:return e>=i?e-i:-e;case`FPT`:return t!==32||r!==null&&r!==`IEEE_32`?NaN:(Oi.setUint32(0,e),Oi.getFloat32(0));case`BCD`:{let n=0;for(let r=Math.ceil(t/4)-1;r>=0;r--){let t=Math.floor(e/2**(4*r))%16;if(t>9)return NaN;n=n*10+t}return n}default:return e}}const Oi=new DataView(new ArrayBuffer(4)),ki=(e,t)=>e===null||[`UNS`,`TWO`,`INT`,`OFF`,`ONE`,`SIG`,`SIM`,`BCD`].includes(e)||e===`FPT`&&(t===null||t===`IEEE_32`),Ai={1:`ONE`,2:`TWO`,3:`SIG`,4:`SIM`,B:`OFF`,U:`UNS`,F:`FPT`};function ji(e){let t=new Map;for(let n of vi(e,/^R-(\d+)\\TK1-(\d+)$/)){let r=I(e.get(n[0]));if(r===null||r<0||r>65535||t.has(r))continue;let[i,a]=[n[1],n[2]],o=t=>e.get(`R-${i}\\${t}-${a}`),s=_i(o(`ASR`)),c={id:r,name:o(`DSI`)??``,type:(o(`CDT`)??``).toUpperCase(),dln:o(`CDLN`)??``,rate:s&&s>=1e-6&&s<=1e10?s:null,analog:new Map,discrete:[]};for(let t of bi(e,`R-${i}\\AMN-${a}-`)){let n=t[1],r=I(e.get(`R-${i}\\AMCN-${a}-${n}`))??Number(n);c.analog.set(r,{name:e.get(t[0]),bfm:Ai[(e.get(`R-${i}\\AF-${a}-${n}`)??``).toUpperCase()]??null})}for(let t of bi(e,`R-${i}\\DMN-${a}-`).sort((e,t)=>Number(e[1])-Number(t[1]))){let n=(e.get(`R-${i}\\DMSK-${a}-${t[1]}`)??``).toUpperCase();(n===`FW`||/^[01]{1,32}$/.test(n))&&c.discrete.push({name:e.get(t[0]),mask:n===`FW`?null:n})}t.set(r,c)}return t}function Mi(e,t){let n=new Map;for(let r of vi(e,/^P-(\d+)\\DLN$/)){let i=r[1],a=e.get(r[0]),o=t=>e.get(`P-${i}\\${t}`),s=I(o(`MF1`)),c=I(o(`MF\\N`))??1,l=I(o(`F1`)),u=I(o(`MF4`));if(s===null||s<2||s>16384||c<1||c>1024||l===null||l<1||l>64||u===null||u<1||u>64){t(`PCM format ${a} (its frame is not described or out of range)`);continue}let d=[u,...Array(s-1).fill(l)];for(let t of bi(e,`P-${i}\\MFW1-`)){let n=I(e.get(t[0])),r=I(o(`MFW2-${t[1]}`));n!==null&&n>=1&&n<s&&r!==null&&r>=1&&r<=64&&(d[n]=r)}let f=d.reduce((e,t)=>e+t,0),p=I(o(`MF2`)),m=(o(`MF5`)??``).replace(/\s/g,``).toUpperCase(),h=_i(o(`D2`)),g=(o(`F2`)??`M`).toUpperCase()===`L`,_=null;if((I(o(`ISF\\N`))??0)>=1){let e=I(o(`IDC1-1`)),t=I(o(`IDC3-1`))??1,n=I(o(`IDC4-1`));if(e!==null&&e>=1&&e<s&&n!==null&&n>=1&&t>=1&&t+n-1<=d[e]&&n<=32){let r=I(o(`IDC6-1`))??0,i=(o(`IDC10-1`)??`INC`).toUpperCase()===`DEC`,a=(o(`IDC5-1`)??`D`).toUpperCase();_={word:e,len:n,shift:d[e]-(t+n-1),lsbFirst:a===`L`||a===`D`&&g,init:r,end:I(o(`IDC8-1`))??(i?r-(c-1):r+c-1),initFrame:I(o(`IDC7-1`))??1,dec:i}}}n.set(a,{dln:a,mfn:c,widths:d,frameBits:Math.max(f,Math.min(p??0,f+65536)),sync:m.length===u&&/^[01X]+$/.test(m)?m:``,bitRate:h&&h>=1e-6&&h<=1e10?h:null,lsbFirst:g,idc:_,params:[]})}for(let r of vi(e,/^D-(\d+)\\DLN$/)){let i=n.get(e.get(r[0]));if(!i)continue;let a=r[1],o=t=>e.get(`D-${a}\\${t}`),s=i.lsbFirst;(I(o(`ML\\N`))??1)>1&&t(`measurement lists after the first of ${i.dln}`);let c=0,l=bi(e,`D-${a}\\MN-1-`).sort((e,t)=>Number(e[1])-Number(t[1]));for(let n of l){let r=n[1],a=e.get(n[0]),l=(o(`LT-1-${r}`)??`WDFR`).toUpperCase();if(l!==`WDFR`){t(`${a} (${l===`TD`?`tagged data`:l===`REL`?`a relative location`:`location type ${l}`})`);continue}let u=(o(`MN3-1-${r}`)??`D`).toUpperCase(),d=u===`L`||u===`D`&&s,f=Math.min(I(o(`MML\\N-1-${r}`))??1,9999),p=null,m=[],h=``;for(let e=1;e<=f&&!h;e++){let t=I(o(`MNF\\N-1-${r}-${e}`))??1;if(t<1||t>8){h=`fragments out of range`;break}let n=[];for(let a=1;a<=t;a++){let t=t=>o(`${t}-1-${r}-${e}-${a}`),s=I(t(`WP`)),l=I(t(`WI`))??0,u=I(t(`FP`))??1,f=I(t(`FI`))??0;if(s===null||s<1||s>=i.widths.length||u<1||u>i.mfn||l<0||f<0){h=`a location outside its frame`;break}let p=(f?Math.floor((i.mfn-u)/f)+1:1)*(l?Math.floor((i.widths.length-1-s)/l)+1:1);if(c+p>hi){h=`too many locations`;break}let m=[];for(let e=u;e<=i.mfn;e+=f||i.mfn)for(let t=s;t<i.widths.length;t+=l||i.widths.length)m.push([e,t]);let g=(t(`WFM`)??`FW`).toUpperCase(),_=g===`FW`||g===``?null:/^[01]+$/.test(g)&&g.length<=i.widths[s]?g.padEnd(i.widths[s],`0`):void 0;if(_===void 0){h=`a bit mask that does not fit its word`;break}let v=(t(`WFT`)??`D`).toUpperCase();n.push({pos:m,mask:_,lsbFirst:v===`D`?d:v===`L`,at:I(t(`WFP`))??a})}if(h)break;n.sort((e,t)=>e.at-t.at);let a=n.map(e=>({mask:e.mask,lsbFirst:e.lsbFirst}));if(p&&JSON.stringify(p)!==JSON.stringify(a)){h=`locations that differ in their fragments`;break}p=a;let s=n[0].pos.length;if(n.some(e=>e.pos.length!==s)){h=`fragments in different numbers of places`;break}for(let e=0;e<s;e++){let t=n[0].pos[e][0];if(n.some(n=>n.pos[e][0]!==t)){h=`fragments in different minor frames`;break}m.push({frame:t,words:n.map(t=>t.pos[e][1])})}(c+=s+i.mfn)>hi&&(h=`too many locations`)}if(!h&&p&&p.reduce((e,t,n)=>e+(p[n].mask?[...p[n].mask].filter(e=>e===`1`).length:i.widths[m[0]?.words[n]??0]),0)>64&&(h=`more than 64 bits`),h||!p||!m.length){t(`${a} (${h||`no location`})`);continue}let g=new Set,_=m.filter(e=>{let t=`${e.frame}:${e.words.join(`,`)}`;return g.has(t)?!1:(g.add(t),!0)});_.sort((e,t)=>e.frame-t.frame||Math.min(...e.words)-Math.min(...t.words)),i.params.push({name:a,frags:p,occ:_})}}return n}function Ni(e,t){let n=[],r=0;for(let t of e.widths)n.push(r),r+=t;let i=Math.max(r,e.frameBits),a=-i&8*t-1;return{offsets:n,frameBytes:(i+a)/8,tail:a?i-i%(8*t):1/0,fill:a}}function Pi(e,t){let n=e.widths[0],r=n<=16?16:n<=32?32:t===4?Math.ceil(n/32)*32:Math.ceil(n/16)*16,i=[r-n],a=r;for(let t=1;t<e.widths.length;t++){let n=Math.ceil(e.widths[t]/16)*16;i.push(a+n-e.widths[t]),a+=n}return t===4&&a%32&&(a+=16),{offsets:i,frameBytes:a/8,tail:1/0,fill:0}}function Fi(e,t,n,r,i){let a=0,o=r,s=i;for(;s>0;){let r=e[t+(o>>3^n)],i=o&7,c=Math.min(8-i,s);a=a*(1<<c)+(r>>8-i-c&(1<<c)-1),s-=c,o+=c}return a}function Ii(e,t,n,r){let i=0,a=0,o=n;for(;a<r;){let n=o&7,s=Math.min(8-n,r-a);i+=(e[t+(o>>3)]>>n&(1<<s)-1)*2**a,a+=s,o+=s}return i}function Li(e,t){let n=0;for(let r=0;r<t;r++)n=n*2+e%2,e=Math.floor(e/2);return n}function Ri(e,t,n){let r=e.offsets[t],i=Math.min(Math.max(e.tail-r,0),n),a=(t,n)=>Fi(e.b,e.base,e.xor,e.bit0+t,n);return i===n?a(r,n):i===0?a(r+e.fill,n):a(r,i)*2**(n-i)+a(e.tail+e.fill,n-i)}function zi(e,t,n){let r=t.frags.map(e=>e.mask?[...e.mask].flatMap((e,t)=>e===`1`?[t]:[]):null),i=t.frags.map(e=>e.lsbFirst),a=n?.bfm??null,o=n?.fpf??null,s=n?.apply??null;return(t,n)=>{let c=0,l=0;for(let a=0;a<n.length;a++){let o=n[a],s=e.widths[o],u=Ri(t,o,s);i[a]&&(u=Li(u,s));let d=r[a];if(d)for(let e of d)c=c*2+Math.floor(u/2**(s-1-e))%2,l++;else c=c*2**s+u,l+=s}let u=Di(c,l,a,o);return s?s(u):u}}function Bi(e,t){let n=e.idc,r=e.widths[n.word],i=Math.floor(Ri(t,n.word,r)/2**n.shift)%2**n.len;return n.lsbFirst&&(i=Li(i,n.len)),i<Math.min(n.init,n.end)||i>Math.max(n.init,n.end)?0:((((n.dec?n.init-i:i-n.init)%e.mfn+e.mfn)%e.mfn+n.initFrame-1)%e.mfn+e.mfn)%e.mfn+1}var Vi=class{#e=new Uint8Array;#t=0;#n=0;#r=!1;#i=[];#a;#o;#s;constructor(e){this.#a=e,this.#o=e.frameBits,this.#s=Ni(e,2).offsets}#c(e){let t=this.#a.sync,n=this.#e;for(let r=0;r<t.length;r++){let i=t.charCodeAt(r);if(i===88)continue;let a=e+r;if((n[a>>3]>>7-(a&7)&1)!=i-48)return!1}return!0}push(e,t,n,r,i,a){n-=n%(r+1);let o=this.#n>>3,s=(this.#t>>3)-o,c=new Uint8Array(s+n);c.set(this.#e.subarray(o,o+s));for(let i=0;i<n;i++)c[s+i]=e[t+(i^r)];this.#e=c,this.#n-=o*8,this.#t=c.length*8;for(let e of this.#i)e.bit-=o*8;for(;this.#i.length>1&&this.#i[1].bit<=this.#n;)this.#i.shift();this.#i.push({bit:s*8,sec:i});let l=this.#a.sync.length,u={b:c,base:0,xor:0,bit0:0,offsets:this.#s,tail:1/0,fill:0};for(;;){if(!this.#r){let e=this.#n;for(;e+l<=this.#t&&!this.#c(e);)e++;if(this.#n=e,e+l>this.#t)return;this.#r=!0}if(this.#n+this.#o>this.#t)return;if(!this.#c(this.#n)){this.#r=!1,this.#n++;continue}let e=this.#i.length-1;for(;e>0&&this.#i[e].bit>this.#n;)e--;let t=this.#i[e];u.bit0=this.#n,a(u,t.sec+(this.#a.bitRate?(this.#n-t.bit)/this.#a.bitRate:0)),this.#n+=this.#o}}};function Hi(e){let t=[[[0],`Computer-generated`,`computer-generated`],[[1],`TMATS`,`TMATS`],[[2],`Recording events`,`recording event`],[[3],`Recording index`,`recording index`],[[4],`Streaming configuration`,`streaming configuration`],[[9],`PCM`,`PCM`],[[17],`Time`,`time`],[[18],`Network time`,`network time`],[[25,26],`MIL-STD-1553`,`MIL-STD-1553`],[[33],`Analog`,`analog`],[[41],`Discrete`,`discrete`],[[48],`Message`,`message`],[[56],`ARINC-429`,`ARINC-429`],[[64,65,66,67,68],`Video`,`video`],[[72,73,74],`Image`,`image`],[[80],`UART`,`UART`],[[88,89],`IEEE 1394`,`IEEE 1394`],[[96],`Parallel`,`parallel`],[[104,105],`Ethernet`,`Ethernet`],[[112,113,114],`TSPI/CTS`,`TSPI/CTS`],[[120],`CAN bus`,`CAN bus`],[[121,122],`Fibre Channel`,`Fibre Channel`]].find(([t])=>t.includes(e)),n=`data type 0x${e.toString(16).padStart(2,`0`)}`;return t?[t[1],t[2]]:[n[0].toUpperCase()+n.slice(1),n]}const Ui=(e,t,n=`${t}s`)=>`${e} ${e===1?t:n}`,Wi=(e,t)=>{let n=e.ref??e.first;return n?(n.ms-e.baseMs)/1e3+Gi(t-n.rtc)/1e7:Gi(t-(e.baseRtc??0))/1e7},Gi=e=>e-Math.round(e/2**48)*2**48;function Ki(e,t,n,r){let i=e.owners.get(n);return i===void 0?(e.owners.set(n,t),n):i===t?n:`${r} ${n}`}function qi(e,t,n,r,i,a){let o=ei(n,r);if(!o)return;let s=o.mode===null?`${o.rt}:${o.tr}:${o.sa}`:`${o.rt}:mode:${o.mode}`,c=t.msgs.get(s);if(c===void 0){let n=o.mode===null?`RT${o.rt} ${o.tr} SA${o.sa}`:`RT${o.rt} mode ${o.mode}`;if(t.rows){let r=o.mode===null?t.rows.filter(e=>e.kind===`1553`&&e.rt===o.rt&&e.tr===o.tr&&e.sa===o.sa):[];if(!r.length)a.problems.unnamed.add(`${t.name} ${n}`),c=null;else{let i=r.map(n=>({name:Ki(a,String(e.ch),n.name,t.name),unit:n.unit}));c={gid:a.out.id(`b:${e.ch}:${s}`,()=>({name:`${t.name} ${n}`,rate:null,order:0,channels:i})),read:r.map(e=>t=>t.length<Math.max(...e.words)?NaN:Zr(e,e.words.reduce((e,n)=>e*65536+t[n-1],0)))}}}else{let r={n:o.data.length};t.words.set(s,r),c={gid:a.out.id(`b:${e.ch}:${s}`,()=>({name:`${t.name} ${n}`,rate:null,order:0,channels:Array.from({length:r.n},(e,n)=>({name:ri(t.name,o.rt,o.tr,o.sa,o.mode,n+1),unit:``}))})),read:Array.from({length:32},(e,t)=>e=>t<e.length?e[t]:NaN)}}t.msgs.set(s,c)}if(!c)return;let l=t.words.get(s);if(l&&o.data.length>l.n&&(l.n=o.data.length),!a.out.row(c.gid,Wi(a.clock,i)))return;let u=t.rows?c.read.length:o.data.length;for(let e=0;e<u;e++)a.out.put(c.gid,e,c.read[e](o.data,0))}function Ji(e,t,n,r,i,a){let o=Qr(r),s=r>>>8&3,c=`${n}:${o}:${s}`,l=t.msgs.get(c);if(l===void 0){let r=ii(t.name,n,o,s);if(t.rows){let i=t.rows.filter(e=>e.kind===`429`&&e.label===o&&(e.sdi===null||e.sdi===s)&&(e.bus===null||e.bus===n));if(!i.length)a.problems.unnamed.add(r),l=null;else{let o=i.map(r=>({name:Ki(a,`${e.ch}/${n}`,r.name,`${t.name} bus ${n}`),unit:r.unit}));l={gid:a.out.id(`l:${e.ch}:${c}`,()=>({name:r,rate:null,order:0,channels:o})),read:i.map(e=>(t,n)=>Zr(e,n))}}}else l={gid:a.out.id(`l:${e.ch}:${c}`,()=>({name:r,rate:null,order:0,channels:[{name:r,unit:``}]})),read:[(e,t)=>t>>>10&524287]};t.msgs.set(c,l)}if(!(!l||!a.out.row(l.gid,Wi(a.clock,i))))for(let e=0;e<l.read.length;e++)a.out.put(l.gid,e,l.read[e]([],r>>>0))}function Yi(e,t,n){let r=e.o+e.hdr;e.type===25?n.problems.busErrors+=ti(e.dv,r,e.dlen,t=>pi(e,t),(r,i,a)=>qi(e,t,a,(i>>>11&1)==1,r,n)):n.problems.busErrors+=ni(e.dv,r,e.dlen,e.rtc,(r,i,a)=>Ji(e,t,i,a,r,n))}function Xi(e,t){let{dv:n}=e,r=e.o+e.hdr;if(e.dlen<4)return null;let i=n.getUint32(r,!0),a=i>>>28&1,o=i>>>16&255||256,s=a?1:o;if(e.dlen<4*s)return null;let c=[];for(let e=0;e<o;e++){let t=a?i:n.getUint32(r+4*e,!0),o=t&3;if(o===2)return null;c.push({sub:a?e+1:t>>>8&255||256,factor:t>>>24&15,len:t>>>2&63||64,mode:o})}let l=c.map(e=>`${e.sub}/${e.factor}/${e.len}/${e.mode}`).join(`,`);if(t)return l===t.sig?t:`other`;let u=2**Math.max(...c.map(e=>e.factor)),d=e=>e.mode?Math.ceil(e.len/16)*16:e.len;if(c.reduce((e,t)=>e+d(t)*(u/2**t.factor),0)>(e.dlen-4*s)*8)return null;let f=[],p=0;for(let e=0;e<u;e++){let t=[];c.forEach((n,r)=>{(e+1)%2**n.factor||(t.push([r,p+(n.mode===1?d(n)-n.len:0)]),p+=d(n))}),f.push(t)}return{sig:l,subs:c,ncsdw:s,nsim:u,sims:f,schedBits:p}}function Zi(e,t,n,r){let i=n.model.convs,a=Ni(t,2).offsets,o=new Map,s=t.params.map(e=>{let n=Array.from({length:t.mfn+1},()=>[]);for(let t of e.occ)n[t.frame].push(t.words);return n}),c=s.map(e=>e.some(e=>e.length>1));t.params.forEach((e,t)=>{let n=s[t].map(e=>e.map(e=>c[t]?Math.min(...e.map(e=>a[e])):-1).join(`,`)).join(`|`)+(c[t]?`+`:``),r=o.get(n);r?r.push(t):o.set(n,[t])});let l=t.bitRate?t.bitRate/t.frameBits:null,u=0;return{f:t,groups:[...o].map(([o,d])=>{let f=d[0],p=s[f].reduce((e,t)=>e+t.length,0),m=p===t.mfn?``:p%t.mfn===0?` (×${p/t.mfn})`:t.mfn%p===0?` (÷${t.mfn/p})`:` (${p}/${t.mfn})`;return{gid:n.out.id(`p:${e}:${o}`,()=>({name:r+m,rate:l?l*p/t.mfn:null,order:u++,channels:d.map(e=>({name:t.params[e].name,unit:i.get(t.params[e].name)?.unit??``}))})),params:d,rows:s[f].map((e,n)=>e.map((e,r)=>({dt:c[f]&&t.bitRate?Math.min(...e.map(e=>a[e]))/t.bitRate:0,words:d.map(e=>s[e][n][r])})))}}),layouts:new Map,framer:null,counter:0,readers:t.params.map(e=>zi(t,e,i.get(e.name)))}}function Qi(e,t,n,r,i){let a=e.f.idc?Bi(e.f,t):r;if(!a){i.problems.frames++;return}let o=i.out;for(let r of e.groups)for(let i of r.rows[a])if(o.row(r.gid,n+i.dt))for(let n=0;n<r.params.length;n++)o.put(r.gid,n,e.readers[r.params[n]](t,i.words[n]))}function $i(e,t,n){let{dv:r}=e,i=e.o+e.hdr,a=()=>{n.problems.pcmMismatch++};if(e.dlen<4)return a();let o=r.getUint32(i,!0),s=o>>>18&1,c=o>>>19&1,l=o>>>20&1,u=o>>>21&1?4:2,d=u-1,f=Wi(n.clock,e.rtc),p=t.f;if(s+c+l!==1)return a();if(l){if(!p.sync)return a();t.framer??=new Vi(p),t.framer.push(e.b,i+4,e.dlen-4,d,f,(e,r)=>Qi(t,e,r,t.counter++%p.mfn+1,n));return}let m=c*2+ +(u===4),h=t.layouts.get(m);h||t.layouts.set(m,h=c?Ni(p,u):Pi(p,u));let g=o>>>30&1?u===4?12:10:0,_=g+h.frameBytes,v=(e.dlen-4)/_;if(!Number.isInteger(v))return a();o>>>29&1&&(t.counter=0);let y={b:e.b,base:0,xor:d,bit0:0,offsets:h.offsets,tail:h.tail,fill:h.fill};for(let r=0;r<v;r++){let a=i+4+r*_;y.base=a+g,Qi(t,y,g?Wi(n.clock,pi(e,a)):f+(p.bitRate?r*p.frameBits/p.bitRate:0),t.counter++%p.mfn+1,n)}}function ea(e,t,n,r,i,a){let o=Xi(e,n.layout);if(o===`other`){r.problems.analogLayout++;return}if(!o){r.problems.damaged++;return}if(!n.layout){n.layout=o;let e=new Map;o.subs.forEach((t,n)=>{let r=e.get(t.factor);r?r.push(n):e.set(t.factor,[n])});let s=[...e.keys()].sort((e,t)=>e-t),c=o.subs.map(e=>a?.analog.get(e.sub));n.convs=c.map(e=>e?r.model?.convs.get(e.name):void 0),n.bfm=c.map((e,t)=>n.convs[t]?.bfm??e?.bfm??null);for(let a of s){let s=e.get(a),l=r.out.id(`a:${t}:${a}`,()=>({name:a?`${i} (÷${2**a})`:i,order:a,rate:(n.rate??r.rates.get(t)??NaN)/2**a,channels:s.map(e=>({name:c[e]?.name||`Subchannel ${o.subs[e].sub}`,unit:n.convs[e]?.unit??``}))}));n.groups.set(a,{gid:l,subs:s})}}let s=Math.floor((e.dlen-4*o.ncsdw)*8/o.schedBits);n.packets++,n.first=Math.min(n.first,e.rtc),e.rtc>=n.last&&(n.last=e.rtc,n.lastSims=s*o.nsim),n.sims+=s*o.nsim;let c=n.rate??r.rates.get(t)??1/0,l=Wi(r.clock,e.rtc),u=e.o+e.hdr+4*o.ncsdw,d=r.out,f=new Int32Array(o.subs.length);for(let e of n.groups.values())e.subs.forEach((e,t)=>{f[e]=t});for(let t=0;t<s;t++)for(let r=0;r<o.nsim;r++){let i=l+(t*o.nsim+r)/c;for(let[a,s]of n.groups)if(!((r+1)%2**a||!d.row(s.gid,i)))for(let[i,c]of o.sims[r]){if(o.subs[i].factor!==a)continue;let r=o.subs[i],l=Di(Ii(e.b,u,t*o.schedBits+c,r.len),r.len,n.bfm[i],n.convs[i]?.fpf??null),p=n.convs[i]?.apply;d.put(s.gid,f[i],p?p(l):l)}}}function ta(e,t,n){let{dv:r}=e,i=e.o+e.hdr;if(e.dlen<4){n.problems.damaged++;return}let a=r.getUint32(i,!0),o=a>>>3&31||32,s=a>>>1&1,c=Math.floor((e.dlen-4)/12);for(let a=0;a<c;a++){let c=i+4+12*a;if(!n.out.row(t.gid,Wi(n.clock,pi(e,c))))continue;let l=r.getUint32(c+8,!0);s&&o<32&&(l>>>=32-o),t.masks.forEach((e,r)=>{let i=0;for(let t of e)i=i*2+(l>>>t&1);n.out.put(t.gid,r,i)})}}const na=e=>[...e].flatMap((t,n)=>t===`1`?[e.length-1-n]:[]);async function*ra(e,t,n,r,i){let a=new Map,o=t.model,s=(e,t)=>o?.rch.get(e)?.name||`${t} ${e}`,c={year:o?.year??1970,day:0},l=0,u=e=>{if(r){let t=r.get(e.ch);t||r.set(e.ch,t=new Map),t.set(e.type,(t.get(e.type)??0)+1)}++l%4096==0&&t.out.row(-2,0);let n=t.clock;if(n.baseRtc??=e.rtc,e.type===17){let t=mi(e,c);t&&(n.ref={rtc:e.rtc,ms:t.ms},n.first||(n.first=n.ref,n.baseMs=t.ms,n.firstHasYear=t.hasYear));return}if(e.type!==33&&e.type!==41&&e.type!==9&&e.type!==25&&e.type!==56)return;let i=`${e.type}:${e.ch}`,u=a.get(i);if(!u){u={id:e.ch};let n=o?.rch.get(e.ch);if(e.type===25||e.type===56){let n=s(e.ch,e.type===25?`1553`:`ARINC-429`);u.bus={name:n,rows:t.icd?ai(t.icd,e.ch,n):null,msgs:new Map,words:new Map}}else if(e.type===33)u.analog={layout:null,groups:new Map,convs:[],bfm:[],rate:n?.rate??null,first:1/0,last:-1/0,sims:0,lastSims:0,packets:0};else if(e.type===41){let r=n?.discrete??[],i=(e.dlen>=4?e.dv.getUint32(e.o+e.hdr,!0)>>>3:0)&31||32,a=Array.from({length:i},(e,t)=>i-1-t),c=r.length?r.map(e=>({name:e.name,bits:e.mask?na(e.mask):a})):Array.from({length:i},(t,n)=>({name:`Discrete ${e.ch} bit ${n}`,bits:[n]})),l=s(e.ch,`Discrete`),d=t.out.id(`d:${e.ch}`,()=>({name:l,rate:null,order:0,channels:c.map(e=>({name:e.name,unit:o?.convs.get(e.name)?.unit??``}))}));u.discrete={gid:d,masks:c.map(e=>e.bits)}}else{let r=n?o?.pcm.get(n.dln):void 0;r&&r.params.length&&(u.pcm=Zi(e.ch,r,t,s(e.ch,`PCM`)))}a.set(i,u)}u.bus?Yi(e,u.bus,t):u.analog?ea(e,e.ch,u.analog,t,s(e.ch,`Analog`),o?.rch.get(e.ch)):u.discrete?ta(e,u.discrete,t):u.pcm?$i(e,u.pcm,t):t.problems.noFormat.set(e.ch,(t.problems.noFormat.get(e.ch)??0)+1)};for(let t=ui(e,u,n,i);!(await t.next()).done;)yield;if(t.plan)for(let e of a.values()){let n=e.analog;n&&n.rate===null&&n.packets>1&&n.last>n.first&&t.rates.set(e.id,(n.sims-n.lastSims)/((n.last-n.first)/1e7))}}async function ia(e,t){let n=[],r=0,i=0,a=!1,o=!1,s=new TextDecoder(`latin1`),c=ui(e,e=>{if(a)return;if(e.type!==1){a=!0;return}if(e.dlen<4)return;let c=e.dv.getUint32(e.o+e.hdr,!0);if(i||=c&255,c>>>9&1){o=!0,a=!0;return}let l=Math.min(e.dlen-4,1048576-r);n.push(s.decode(e.b.subarray(e.o+e.hdr+4,e.o+e.hdr+4+l))),r+=l,r>=1048576&&(a=!0,t.push(`The setup record is longer than 1 MB; only its first 1 MB was read.`))},{damaged:0,cut:!1});for(;!a&&!(await c.next()).done;);return await c.return(void 0),o&&t.push(`The setup record is in TMATS XML, which Kymoscope does not read: channels are named by their ids, and PCM is not decoded.`),n.length?{text:n.join(``),version:i}:null}const aa={7:`106-07`,8:`106-09`,9:`106-11`,10:`106-13`,11:`106-15`,12:`106-17`},oa={...si,async plan(e,t){try{return await sa(t,e.companions)}catch(e){throw k(e)}},async*stream(e){let t=e.plan.state,n=new Map(t.keys.map((e,t)=>[e,t])),r=new Map,i=e=>{e.cap=Math.max(1,Math.min(65536,e.total-e.start)),e.time=new Float64Array(e.cap),e.cols=e.cols.map(()=>new Float64Array(e.cap))};for(let t of e.selection){let n=p(e,t.group),a=new Int32Array(e.plan.groups[t.group].channels.length).fill(-1);n.forEach((e,t)=>{a[e]=t});let o={cols:n.map(()=>new Float64Array),slot:a,time:new Float64Array,n:0,cap:0,start:0,total:e.plan.groups[t.group].samples};i(o),r.set(t.group,o)}let a=[],o=(e,t)=>{let n=t.n===t.cap;if(a.push({group:e,time:n?t.time:t.time.slice(0,t.n),start:t.start,length:t.n,columns:t.cols.map(e=>n?e:e.slice(0,t.n))}),t.start+=t.n,n)i(t);else for(let e of t.cols)e.fill(0,0,t.n);t.n=0},s,c=-1,l={model:t.model,out:{id:e=>n.get(e)??-1,row(e,n){if(e===-2){for(let[e,t]of r)t.n&&o(e,t);return!1}return s=r.get(e),!s||s.start+s.n>=s.total?!1:(s.n===s.cap&&o(e,s),c=s.n++,s.time[c]=n-t.t0,!0)},put(e,t,n){let r=s.slot[t];r>=0&&(s.cols[r][c]=n)}},plan:!1,rates:t.rates,icd:t.icd,owners:new Map,clock:{...t.clock,ref:null},problems:{analogLayout:0,damaged:0,pcmMismatch:0,frames:0,noFormat:new Map,busErrors:0,unnamed:new Set}};try{for(let t=ra(e.io,l,{damaged:0,cut:!1},null,e.signal);!(await t.next()).done;)yield*a,a.length=0}catch(e){throw k(e)}for(let[e,t]of r)t.n&&o(e,t);yield*a},streamGroup(e,t){return this.stream({...e,selection:e.selection.filter(e=>e.group===t)})}};async function sa(e,t=[]){let n=[],r={},i=null,a=t.find(e=>/\.csv$/i.test(e.name));if(a){try{i=Yr(await a.text())}catch(e){throw e instanceof Kr?Error(`The ICD ${a.name} can't be read: ${e.message}.`):e}r.ICD=`${a.name} (${Ui(i.length,`measurement`)})`}let o=await ia(e,n),s=null,c=[];if(o){let e=gi(o.text);s={attrs:e,rch:ji(e),convs:Ei(e),pcm:Mi(e,e=>c.push(e)),year:xi(e)??1970};for(let[t,n]of[[`program`,`G\\PN`],[`test item`,`G\\TA`],[`test number`,`G\\TN`],[`setup record date`,`G\\OD`]]){let i=e.get(n);i&&(r[t]=i)}}let l=new Map,u=[],d=[],f=1/0,p=1/0,m={id(e,t){let n=l.get(e);return n||(n={def:null,id:d.length},l.set(e,n),d.push({key:e,def:t}),u.push(0)),n.id},row(e,t){return e<0?!1:(u[e]++,h.first?f=Math.min(f,t):p=Math.min(p,t),!1)},put(){}},h={ref:null,first:null,baseMs:0,baseRtc:null,firstHasYear:!1},g={analogLayout:0,damaged:0,pcmMismatch:0,frames:0,noFormat:new Map,busErrors:0,unnamed:new Set},_=new Map,v={damaged:0,cut:!1},y={model:s,out:m,problems:g,rates:new Map,plan:!0,clock:h,icd:i,owners:new Map};for(let t=ra(e,y,v,_);!(await t.next()).done;);if(_.size===0)throw Error(`This is not an IRIG 106 Chapter 10 file: no packets were found.`);let b=d.map((e,t)=>({...e,i:t})).filter(e=>u[e.i]>0),x=e=>Number(e.split(`:`)[1]),S=b.map(e=>({...e,d:e.def()}));S.sort((e,t)=>x(e.key)-x(t.key)||e.d.order-t.d.order||e.i-t.i);let C=cn(S.map(e=>e.d.name),[]),w=S.map((e,t)=>{let n=e.d.rate,r=cn(e.d.channels.map(e=>e.name));return{name:C[t],channels:e.d.channels.map((e,t)=>({name:r[t],unit:e.unit})),samples:u[e.i],time:{kind:`timestamps`},rateHz:n&&Number.isFinite(n)?n:null,irregular:!0}}),T=h.first?p+Gi((h.baseRtc??0)-h.first.rtc)/1e7:p,E=Math.min(f,T),D=Number.isFinite(E)?E:0,O=[],k=new Set([1,17,33,41,9,3,25,56]);for(let[e,t]of[..._].sort((e,t)=>e[0]-t[0])){r[`Channel ${e}`]=[...t].map(([e,t])=>`${Hi(e)[0]} (${Ui(t,`packet`)})`).join(`, `);for(let[n,r]of t)k.has(n)||O.push(`${Ui(r,`${Hi(n)[1]} packet`)} (channel ${e})`)}if(O.length&&n.push(`Skipped: ${O.join(`, `)}; they need an ICD or aren't time series.`),[..._.values()].some(e=>e.has(25)||e.has(56))&&!i&&n.push(`MIL-STD-1553 words and ARINC-429 labels are raw (no ICD): drop the ICD as a CSV with the file to name and scale them.`),g.unnamed.size){let e=[...g.unnamed];n.push(`Not in the ICD, skipped: ${e.slice(0,20).join(`, `)}${e.length>20?`, and ${e.length-20} more`:``}.`)}if(g.busErrors&&n.push(`${Ui(g.busErrors,`bus message`)} with an error flag (or cut short) ${g.busErrors===1?`was`:`were`} skipped.`),g.noFormat.size){let e=[...g.noFormat.values()].reduce((e,t)=>e+t,0);n.push(`Not decoded: ${Ui(e,`PCM packet`)} (${g.noFormat.size===1?`channel`:`channels`} ${[...g.noFormat.keys()].join(`, `)}); the setup record has no PCM format with measurements for ${g.noFormat.size===1?`it`:`them`}.`)}let A=v.damaged+g.damaged;A&&n.push(`${Ui(A,`damaged packet`)} ${A===1?`was`:`were`} skipped.`),g.pcmMismatch&&n.push(`${Ui(g.pcmMismatch,`PCM packet`)} that ${g.pcmMismatch===1?`does`:`do`} not match the setup record's PCM format ${g.pcmMismatch===1?`was`:`were`} skipped.`),g.analogLayout&&n.push(`${Ui(g.analogLayout,`analog packet`)} whose subchannels differ from their channel's first packet ${g.analogLayout===1?`was`:`were`} skipped.`),v.cut&&n.push(`The file ends in the middle of a packet.`),g.frames&&n.push(`${Ui(g.frames,`PCM minor frame`)} with a subframe ID count outside the major frame ${g.frames===1?`was`:`were`} skipped.`),c.length&&n.push(`Not decoded from the setup record: ${c.slice(0,20).join(`, `)}${c.length>20?`, and ${c.length-20} more`:``}.`);let j=s?[...s.convs].filter(([,e])=>e.unsupported||!ki(e.bfm,e.fpf)).map(([e,t])=>`${e} (${t.unsupported??`binary format ${t.bfm}${t.fpf?` ${t.fpf}`:``}`})`):[];j.length&&n.push(`Read without their conversion or format: ${j.slice(0,20).join(`, `)}${j.length>20?`, and ${j.length-20} more`:``}.`);let M=[...y.rates.keys()].filter(e=>!s?.rch.get(e)?.rate);M.length&&n.push(`The setup record has no sample rate for analog channel ${M.join(`, `)}: estimated from the packet times.`),o||n.push(`This file has no setup record (TMATS): channels are named by their ids, and PCM is not decoded.`);let N=null,P=s?xi(s.attrs):null;if(h.first){let e=h.baseMs+D*1e3;(h.firstHasYear||P!==null)&&Math.abs(e)<=864e13&&(N=new Date(e).toISOString()),!h.firstHasYear&&P!==null?n.push(`The time packets give the day of the year; the year (${P}) is the setup record's date.`):h.firstHasYear||n.push(`Its time packets give the day of the year but no year: the start time is not known; times are from the first sample.`)}else n.push(`This file has no time packets: times are from the first sample (recorder clock), and the start time is not known.`);if(!w.length)throw Error(`This Chapter 10 file has no analog, discrete, PCM or bus data Kymoscope can read. ${n.filter(e=>!e.includes(`time packets`)).join(` `)}`.trim());let ee={model:s,clock:h,t0:D,keys:S.map(e=>e.key),rates:y.rates,icd:i};return{format:`IRIG 106 Chapter 10${o&&aa[o.version]?` (${aa[o.version]})`:``}`,startTime:N,groups:w,meta:r,events:[],notes:n,interleaved:!0,state:ee}}const ca=()=>({frames:0,other:0,truncated:0,incomplete:0,cut:!1,damagedAt:null}),la=new Map([[2712847316,{le:!0,ns:!1}],[3569595041,{le:!1,ns:!1}],[2712812621,{le:!0,ns:!0}],[1295823521,{le:!1,ns:!0}]]),ua=168627466;function da(e){if(e.length<24)return null;let t=new DataView(e.buffer,e.byteOffset,e.byteLength).getUint32(0,!0);if(la.has(t))return`pcap`;if(t===ua&&e.length>=12){let t=new DataView(e.buffer,e.byteOffset,e.byteLength).getUint32(8,!0);if(t===439041101||t===1295788826)return`pcapng`}return null}var fa=class{#e;stats;done=!1;#t=null;#n=!0;#r=!1;#i=1;#a=[];#o=NaN;#s=new Map;#c=0;#l=null;#u={time:0,sport:0,dport:0,b:new Uint8Array,o:0,n:0};constructor(e,t=ca()){this.#e=e,this.stats=t}feed(e,t){let n=new DataView(e.buffer,e.byteOffset,e.byteLength),r=0,i=e=>{this.stats.damagedAt=t+e,this.done=!0};if(!this.#t){if(this.#t=da(e),!this.#t)return i(0),0;if(this.#t===`pcap`){let e=la.get(n.getUint32(0,!0));this.#n=e.le,this.#r=e.ns,this.#i=n.getUint32(20,this.#n)&65535,r=24}}if(this.#t===`pcap`){let t=this.#n;for(;!this.done&&e.length-r>=16;){let a=n.getUint32(r+8,t);if(a>262144){i(r);break}if(e.length-r-16<a)break;let o=n.getUint32(r,t)*1e3+n.getUint32(r+4,t)/(this.#r?1e6:1e3);this.#f(this.#i,e,n,r+16,a,o),r+=16+a}return r}for(;!this.done&&e.length-r>=12;){let t=n.getUint32(r,this.#n);if(t===ua){let e=n.getUint32(r+8,!0);if(e!==439041101&&e!==1295788826){i(r);break}this.#n=e===439041101,t=ua}let a=this.#n,o=n.getUint32(r+4,a);if(o<12||o%4||o>327680){i(r);break}if(e.length-r<o)break;if(n.getUint32(r+o-4,a)!==o){i(r);break}if(t===ua)this.#a=[];else if(t===1&&o>=20)this.#a.push(this.#d(e,n,r,o));else if(t===6&&o>=32){let t=this.#a[n.getUint32(r+8,a)],i=n.getUint32(r+20,a);if(!t||i>o-32)this.stats.other++;else{let o=(n.getUint32(r+12,a)*4294967296+n.getUint32(r+16,a))*t.tick+t.offsetMs;this.#o=o,this.#f(t.link,e,n,r+28,i,o)}}else if(t===3&&o>=16){let t=this.#a[0],i=Math.min(n.getUint32(r+8,a),o-16);t?this.#f(t.link,e,n,r+12,i,this.#o):this.stats.other++}r+=o}return r}finish(){this.#m(),this.stats.incomplete+=this.#s.size,this.#s.clear(),this.#c=0}#d(e,t,n,r){let i=this.#n,a={link:t.getUint16(n+8,i),tick:.001,offsetMs:0};for(let o=n+16;o+4<=n+r-4;){let s=t.getUint16(o,i),c=t.getUint16(o+2,i);if(s===0||o+4+c>n+r-4)break;if(s===9&&c>=1){let t=e[o+4];a.tick=(t&128?2**-(t&127):10**-t)*1e3}else s===14&&c>=8&&(a.offsetMs=(t.getInt32(o+4+(i?4:0),i)*4294967296+t.getUint32(o+4+(i?0:4),i))*1e3);o+=4+c+(-c&3)}return a}#f(e,t,n,r,i,a){this.stats.frames++;let o=r+i,s=r,c;if(e===1){if(i<14)return void this.stats.other++;for(c=n.getUint16(s+12),s+=14;(c===33024||c===34984||c===37120)&&s+4<=o;)c=n.getUint16(s+2),s+=4}else if(e===113){if(i<16)return void this.stats.other++;c=n.getUint16(s+14),s+=16}else if(e===276){if(i<20)return void this.stats.other++;c=n.getUint16(s),s+=20}else if(e===101||e===228||e===229){if(i<1)return void this.stats.other++;c=t[s]>>4==4?2048:t[s]>>4==6?34525:0}else return void this.stats.other++;c===2048?this.#p(t,n,s,o,a):c===34525?this.#g(t,n,s,o,a):this.stats.other++}#p(e,t,n,r,i){if(r-n<20||e[n]>>4!=4)return void this.stats.other++;let a=(e[n]&15)*4,o=t.getUint16(n+2);if(a<20||o<a||e[n+9]!==17)return void this.stats.other++;if(n+o>r)return void this.stats.truncated++;let s=t.getUint16(n+6),c=(s&8191)*8,l=(s&8192)!=0,u=n+a,d=o-a;if(!c&&!l)return this.#_(e,t,u,u+d,i);if(c+d>65535)return void this.stats.other++;let f=`${t.getUint32(n+12)}:${t.getUint32(n+16)}:${t.getUint16(n+4)}`;this.#l&&this.#l.key!==f&&this.#m();for(let e of this.#s.values()){if(!(e.ms<i-3e4))break;this.#h(e)}for(;this.#s.size&&this.#c+d>67108864;)this.#h(this.#s.values().next().value);let p=e.subarray(u,u+d),m=this.#s.get(f);if(m){let e=pa(m,c,p,l);if(e<0&&m.whole)return;if(e>=0){m.counted||this.stats.incomplete++,m.counted=!0,m===this.#l&&(this.#l=null),m.whole=null;for(let t of m.parts.splice(0,e+1))m.held-=t.b.length,this.#c-=t.b.length;m.ms=m.parts.reduce((e,t)=>Math.min(e,t.ms),i),this.#s.delete(f),this.#s.set(f,m)}}else{for(;this.#s.size>=1e4;)this.#h(this.#s.values().next().value);this.#s.set(f,m={key:f,parts:[],held:0,ms:i,counted:!1,whole:null,wholeMs:0})}if(m.held+d>2*65535){this.#s.delete(f),this.#c-=m.held,this.stats.incomplete++;return}m.parts.push({off:c,b:p.slice(),ms:i,last:!l}),m.held+=d,this.#c+=d;let h=ma(m.parts);h&&(m.whole=h,m.wholeMs=i,this.#l=m)}#m(){let e=this.#l;e&&(this.#l=null,this.#s.delete(e.key),this.#c-=e.held,this.#_(e.whole,new DataView(e.whole.buffer),0,e.whole.length,e.wholeMs))}#h(e){if(e===this.#l)return this.#m();this.#s.delete(e.key),this.#c-=e.held,this.stats.incomplete++}#g(e,t,n,r,i){if(r-n<40||e[n]>>4!=6)return void this.stats.other++;let a=n+40+t.getUint16(n+4);if(a>r)return void this.stats.truncated++;let o=e[n+6];for(n+=40;(o===0||o===43||o===60)&&n+8<=a;){let t=e[n];n+=(e[n+1]+1)*8,o=t}if(o!==17||n>a)return void this.stats.other++;this.#_(e,t,n,a,i)}#_(e,t,n,r,i){if(this.#l&&this.#m(),r-n<8)return void this.stats.other++;let a=t.getUint16(n+4);if(a<8)return void this.stats.other++;if(n+a>r)return void this.stats.truncated++;let o=this.#u;o.time=i,o.sport=t.getUint16(n),o.dport=t.getUint16(n+2),o.b=e,o.o=n+8,o.n=a-8,this.#e(o)}};function pa(e,t,n,r){let i=t+n.length,a=-1;return e.parts.forEach((e,o)=>{let s=e.off+e.b.length;if(e.last&&(r?i>s:i!==s)||!r&&s>i){a=o;return}for(let r=Math.max(t,e.off);r<Math.min(i,s);r++)if(n[r-t]!==e.b[r-e.off]){a=o;return}}),a}function ma(e){let t=e.find(e=>e.last);if(!t)return null;let n=t.off+t.b.length,r=[...e].sort((e,t)=>e.off-t.off),i=0;for(let e of r){if(e.off>i)return null;i=Math.max(i,e.off+e.b.length)}if(i<n)return null;let a=new Uint8Array(n);for(let e of r)a.set(e.b.subarray(0,Math.max(0,n-e.off)),e.off);return a}async function*ha(e,t,r,i){let a=new fa(t,r),o=0;for(;o<e.size&&!a.done;){i?.throwIfAborted();let t=await e.slice(o,Math.min(n,e.size-o)),s=o+t.length>=e.size,c=a.feed(t,o);if(o+=c,s||c===0){!a.done&&o<e.size&&(r.cut=!0);break}yield}a.finish()}function ga(e,t,n,r=57005){if(n<16||n&1||(e[t+2]<<8|e[t+3])*2!==n)return!1;let i=e[t+n-2]<<8|e[t+n-1];return i===57005||i===r}function _a(e){if(!da(e))return!1;let t=!1,n=new fa(e=>{e.n>=16&&!(e.n&1)&&(e.b[e.o+2]<<8|e.b[e.o+3])*2===e.n&&(t=n.done=!0)});try{n.feed(e,0),t||n.finish()}catch{return!1}return t}const va={id:`iena`,label:`IENA flight-test network capture`,extensions:[`.pcap`,`.pcapng`,`.cap`],companions:[`.xidml`,`.xml`,`.yaml`,`.yml`,`.csv`].map(e=>({ext:e,anyName:!0})),sniff:_a,sniffBytes:e=>da(e)?1<<20:0};
7
7
  /*! js-yaml 4.1.1 https://github.com/nodeca/js-yaml @license MIT */
8
- function ta(e){return e==null}function na(e){return typeof e==`object`&&!!e}function ra(e){return Array.isArray(e)?e:ta(e)?[]:[e]}function ia(e,t){var n,r,i,a;if(t)for(a=Object.keys(t),n=0,r=a.length;n<r;n+=1)i=a[n],e[i]=t[i];return e}function aa(e,t){var n=``,r;for(r=0;r<t;r+=1)n+=e;return n}function oa(e){return e===0&&1/e==-1/0}var L={isNothing:ta,isObject:na,toArray:ra,repeat:aa,isNegativeZero:oa,extend:ia};function sa(e,t){var n=``,r=e.reason||`(unknown reason)`;return e.mark?(e.mark.name&&(n+=`in "`+e.mark.name+`" `),n+=`(`+(e.mark.line+1)+`:`+(e.mark.column+1)+`)`,!t&&e.mark.snippet&&(n+=`
8
+ function ya(e){return e==null}function ba(e){return typeof e==`object`&&!!e}function xa(e){return Array.isArray(e)?e:ya(e)?[]:[e]}function Sa(e,t){var n,r,i,a;if(t)for(a=Object.keys(t),n=0,r=a.length;n<r;n+=1)i=a[n],e[i]=t[i];return e}function Ca(e,t){var n=``,r;for(r=0;r<t;r+=1)n+=e;return n}function wa(e){return e===0&&1/e==-1/0}var L={isNothing:ya,isObject:ba,toArray:xa,repeat:Ca,isNegativeZero:wa,extend:Sa};function Ta(e,t){var n=``,r=e.reason||`(unknown reason)`;return e.mark?(e.mark.name&&(n+=`in "`+e.mark.name+`" `),n+=`(`+(e.mark.line+1)+`:`+(e.mark.column+1)+`)`,!t&&e.mark.snippet&&(n+=`
9
9
 
10
- `+e.mark.snippet),r+` `+n):r}function ca(e,t){Error.call(this),this.name=`YAMLException`,this.reason=e,this.mark=t,this.message=sa(this,!1),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=Error().stack||``}ca.prototype=Object.create(Error.prototype),ca.prototype.constructor=ca,ca.prototype.toString=function(e){return this.name+`: `+sa(this,e)};var la=ca;function ua(e,t,n,r,i){var a=``,o=``,s=Math.floor(i/2)-1;return r-t>s&&(a=` ... `,t=r-s+a.length),n-r>s&&(o=` ...`,n=r+s-o.length),{str:a+e.slice(t,n).replace(/\t/g,`→`)+o,pos:r-t+a.length}}function da(e,t){return L.repeat(` `,t-e.length)+e}function fa(e,t){if(t=Object.create(t||null),!e.buffer)return null;t.maxLength||=79,typeof t.indent!=`number`&&(t.indent=1),typeof t.linesBefore!=`number`&&(t.linesBefore=3),typeof t.linesAfter!=`number`&&(t.linesAfter=2);for(var n=/\r?\n|\r|\0/g,r=[0],i=[],a,o=-1;a=n.exec(e.buffer);)i.push(a.index),r.push(a.index+a[0].length),e.position<=a.index&&o<0&&(o=r.length-2);o<0&&(o=r.length-1);var s=``,c,l,u=Math.min(e.line+t.linesAfter,i.length).toString().length,d=t.maxLength-(t.indent+u+3);for(c=1;c<=t.linesBefore&&!(o-c<0);c++)l=ua(e.buffer,r[o-c],i[o-c],e.position-(r[o]-r[o-c]),d),s=L.repeat(` `,t.indent)+da((e.line-c+1).toString(),u)+` | `+l.str+`
11
- `+s;for(l=ua(e.buffer,r[o],i[o],e.position,d),s+=L.repeat(` `,t.indent)+da((e.line+1).toString(),u)+` | `+l.str+`
10
+ `+e.mark.snippet),r+` `+n):r}function Ea(e,t){Error.call(this),this.name=`YAMLException`,this.reason=e,this.mark=t,this.message=Ta(this,!1),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=Error().stack||``}Ea.prototype=Object.create(Error.prototype),Ea.prototype.constructor=Ea,Ea.prototype.toString=function(e){return this.name+`: `+Ta(this,e)};var Da=Ea;function Oa(e,t,n,r,i){var a=``,o=``,s=Math.floor(i/2)-1;return r-t>s&&(a=` ... `,t=r-s+a.length),n-r>s&&(o=` ...`,n=r+s-o.length),{str:a+e.slice(t,n).replace(/\t/g,`→`)+o,pos:r-t+a.length}}function ka(e,t){return L.repeat(` `,t-e.length)+e}function Aa(e,t){if(t=Object.create(t||null),!e.buffer)return null;t.maxLength||=79,typeof t.indent!=`number`&&(t.indent=1),typeof t.linesBefore!=`number`&&(t.linesBefore=3),typeof t.linesAfter!=`number`&&(t.linesAfter=2);for(var n=/\r?\n|\r|\0/g,r=[0],i=[],a,o=-1;a=n.exec(e.buffer);)i.push(a.index),r.push(a.index+a[0].length),e.position<=a.index&&o<0&&(o=r.length-2);o<0&&(o=r.length-1);var s=``,c,l,u=Math.min(e.line+t.linesAfter,i.length).toString().length,d=t.maxLength-(t.indent+u+3);for(c=1;c<=t.linesBefore&&!(o-c<0);c++)l=Oa(e.buffer,r[o-c],i[o-c],e.position-(r[o]-r[o-c]),d),s=L.repeat(` `,t.indent)+ka((e.line-c+1).toString(),u)+` | `+l.str+`
11
+ `+s;for(l=Oa(e.buffer,r[o],i[o],e.position,d),s+=L.repeat(` `,t.indent)+ka((e.line+1).toString(),u)+` | `+l.str+`
12
12
  `,s+=L.repeat(`-`,t.indent+u+3+l.pos)+`^
13
- `,c=1;c<=t.linesAfter&&!(o+c>=i.length);c++)l=ua(e.buffer,r[o+c],i[o+c],e.position-(r[o]-r[o+c]),d),s+=L.repeat(` `,t.indent)+da((e.line+c+1).toString(),u)+` | `+l.str+`
14
- `;return s.replace(/\n$/,``)}var pa=fa,ma=[`kind`,`multi`,`resolve`,`construct`,`instanceOf`,`predicate`,`represent`,`representName`,`defaultStyle`,`styleAliases`],ha=[`scalar`,`sequence`,`mapping`];function ga(e){var t={};return e!==null&&Object.keys(e).forEach(function(n){e[n].forEach(function(e){t[String(e)]=n})}),t}function _a(e,t){if(t||={},Object.keys(t).forEach(function(t){if(ma.indexOf(t)===-1)throw new la(`Unknown option "`+t+`" is met in definition of "`+e+`" YAML type.`)}),this.options=t,this.tag=e,this.kind=t.kind||null,this.resolve=t.resolve||function(){return!0},this.construct=t.construct||function(e){return e},this.instanceOf=t.instanceOf||null,this.predicate=t.predicate||null,this.represent=t.represent||null,this.representName=t.representName||null,this.defaultStyle=t.defaultStyle||null,this.multi=t.multi||!1,this.styleAliases=ga(t.styleAliases||null),ha.indexOf(this.kind)===-1)throw new la(`Unknown kind "`+this.kind+`" is specified for "`+e+`" YAML type.`)}var va=_a;function ya(e,t){var n=[];return e[t].forEach(function(e){var t=n.length;n.forEach(function(n,r){n.tag===e.tag&&n.kind===e.kind&&n.multi===e.multi&&(t=r)}),n[t]=e}),n}function ba(){var e={scalar:{},sequence:{},mapping:{},fallback:{},multi:{scalar:[],sequence:[],mapping:[],fallback:[]}},t,n;function r(t){t.multi?(e.multi[t.kind].push(t),e.multi.fallback.push(t)):e[t.kind][t.tag]=e.fallback[t.tag]=t}for(t=0,n=arguments.length;t<n;t+=1)arguments[t].forEach(r);return e}function xa(e){return this.extend(e)}xa.prototype.extend=function(e){var t=[],n=[];if(e instanceof va)n.push(e);else if(Array.isArray(e))n=n.concat(e);else if(e&&(Array.isArray(e.implicit)||Array.isArray(e.explicit)))e.implicit&&(t=t.concat(e.implicit)),e.explicit&&(n=n.concat(e.explicit));else throw new la(`Schema.extend argument should be a Type, [ Type ], or a schema definition ({ implicit: [...], explicit: [...] })`);t.forEach(function(e){if(!(e instanceof va))throw new la(`Specified list of YAML types (or a single Type object) contains a non-Type object.`);if(e.loadKind&&e.loadKind!==`scalar`)throw new la(`There is a non-scalar type in the implicit list of a schema. Implicit resolving of such types is not supported.`);if(e.multi)throw new la(`There is a multi type in the implicit list of a schema. Multi tags can only be listed as explicit.`)}),n.forEach(function(e){if(!(e instanceof va))throw new la(`Specified list of YAML types (or a single Type object) contains a non-Type object.`)});var r=Object.create(xa.prototype);return r.implicit=(this.implicit||[]).concat(t),r.explicit=(this.explicit||[]).concat(n),r.compiledImplicit=ya(r,`implicit`),r.compiledExplicit=ya(r,`explicit`),r.compiledTypeMap=ba(r.compiledImplicit,r.compiledExplicit),r};var Sa=new xa({explicit:[new va(`tag:yaml.org,2002:str`,{kind:`scalar`,construct:function(e){return e===null?``:e}}),new va(`tag:yaml.org,2002:seq`,{kind:`sequence`,construct:function(e){return e===null?[]:e}}),new va(`tag:yaml.org,2002:map`,{kind:`mapping`,construct:function(e){return e===null?{}:e}})]});function Ca(e){if(e===null)return!0;var t=e.length;return t===1&&e===`~`||t===4&&(e===`null`||e===`Null`||e===`NULL`)}function wa(){return null}function Ta(e){return e===null}var Ea=new va(`tag:yaml.org,2002:null`,{kind:`scalar`,resolve:Ca,construct:wa,predicate:Ta,represent:{canonical:function(){return`~`},lowercase:function(){return`null`},uppercase:function(){return`NULL`},camelcase:function(){return`Null`},empty:function(){return``}},defaultStyle:`lowercase`});function Da(e){if(e===null)return!1;var t=e.length;return t===4&&(e===`true`||e===`True`||e===`TRUE`)||t===5&&(e===`false`||e===`False`||e===`FALSE`)}function Oa(e){return e===`true`||e===`True`||e===`TRUE`}function ka(e){return Object.prototype.toString.call(e)===`[object Boolean]`}var Aa=new va(`tag:yaml.org,2002:bool`,{kind:`scalar`,resolve:Da,construct:Oa,predicate:ka,represent:{lowercase:function(e){return e?`true`:`false`},uppercase:function(e){return e?`TRUE`:`FALSE`},camelcase:function(e){return e?`True`:`False`}},defaultStyle:`lowercase`});function ja(e){return 48<=e&&e<=57||65<=e&&e<=70||97<=e&&e<=102}function Ma(e){return 48<=e&&e<=55}function Na(e){return 48<=e&&e<=57}function Pa(e){if(e===null)return!1;var t=e.length,n=0,r=!1,i;if(!t)return!1;if(i=e[n],(i===`-`||i===`+`)&&(i=e[++n]),i===`0`){if(n+1===t)return!0;if(i=e[++n],i===`b`){for(n++;n<t;n++)if(i=e[n],i!==`_`){if(i!==`0`&&i!==`1`)return!1;r=!0}return r&&i!==`_`}if(i===`x`){for(n++;n<t;n++)if(i=e[n],i!==`_`){if(!ja(e.charCodeAt(n)))return!1;r=!0}return r&&i!==`_`}if(i===`o`){for(n++;n<t;n++)if(i=e[n],i!==`_`){if(!Ma(e.charCodeAt(n)))return!1;r=!0}return r&&i!==`_`}}if(i===`_`)return!1;for(;n<t;n++)if(i=e[n],i!==`_`){if(!Na(e.charCodeAt(n)))return!1;r=!0}return!(!r||i===`_`)}function Fa(e){var t=e,n=1,r;if(t.indexOf(`_`)!==-1&&(t=t.replace(/_/g,``)),r=t[0],(r===`-`||r===`+`)&&(r===`-`&&(n=-1),t=t.slice(1),r=t[0]),t===`0`)return 0;if(r===`0`){if(t[1]===`b`)return n*parseInt(t.slice(2),2);if(t[1]===`x`)return n*parseInt(t.slice(2),16);if(t[1]===`o`)return n*parseInt(t.slice(2),8)}return n*parseInt(t,10)}function Ia(e){return Object.prototype.toString.call(e)===`[object Number]`&&e%1==0&&!L.isNegativeZero(e)}var La=new va(`tag:yaml.org,2002:int`,{kind:`scalar`,resolve:Pa,construct:Fa,predicate:Ia,represent:{binary:function(e){return e>=0?`0b`+e.toString(2):`-0b`+e.toString(2).slice(1)},octal:function(e){return e>=0?`0o`+e.toString(8):`-0o`+e.toString(8).slice(1)},decimal:function(e){return e.toString(10)},hexadecimal:function(e){return e>=0?`0x`+e.toString(16).toUpperCase():`-0x`+e.toString(16).toUpperCase().slice(1)}},defaultStyle:`decimal`,styleAliases:{binary:[2,`bin`],octal:[8,`oct`],decimal:[10,`dec`],hexadecimal:[16,`hex`]}}),Ra=RegExp(`^(?:[-+]?(?:[0-9][0-9_]*)(?:\\.[0-9_]*)?(?:[eE][-+]?[0-9]+)?|\\.[0-9_]+(?:[eE][-+]?[0-9]+)?|[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$`);function za(e){return!(e===null||!Ra.test(e)||e[e.length-1]===`_`)}function Ba(e){var t=e.replace(/_/g,``).toLowerCase(),n=t[0]===`-`?-1:1;return`+-`.indexOf(t[0])>=0&&(t=t.slice(1)),t===`.inf`?n===1?1/0:-1/0:t===`.nan`?NaN:n*parseFloat(t,10)}var Va=/^[-+]?[0-9]+e/;function Ha(e,t){var n;if(isNaN(e))switch(t){case`lowercase`:return`.nan`;case`uppercase`:return`.NAN`;case`camelcase`:return`.NaN`}else if(e===1/0)switch(t){case`lowercase`:return`.inf`;case`uppercase`:return`.INF`;case`camelcase`:return`.Inf`}else if(e===-1/0)switch(t){case`lowercase`:return`-.inf`;case`uppercase`:return`-.INF`;case`camelcase`:return`-.Inf`}else if(L.isNegativeZero(e))return`-0.0`;return n=e.toString(10),Va.test(n)?n.replace(`e`,`.e`):n}function Ua(e){return Object.prototype.toString.call(e)===`[object Number]`&&(e%1!=0||L.isNegativeZero(e))}var Wa=new va(`tag:yaml.org,2002:float`,{kind:`scalar`,resolve:za,construct:Ba,predicate:Ua,represent:Ha,defaultStyle:`lowercase`}),Ga=Sa.extend({implicit:[Ea,Aa,La,Wa]}),Ka=RegExp(`^([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])$`),qa=RegExp(`^([0-9][0-9][0-9][0-9])-([0-9][0-9]?)-([0-9][0-9]?)(?:[Tt]|[ \\t]+)([0-9][0-9]?):([0-9][0-9]):([0-9][0-9])(?:\\.([0-9]*))?(?:[ \\t]*(Z|([-+])([0-9][0-9]?)(?::([0-9][0-9]))?))?$`);function Ja(e){return e===null?!1:Ka.exec(e)!==null||qa.exec(e)!==null}function Ya(e){var t,n,r,i,a,o,s,c=0,l=null,u,d,f;if(t=Ka.exec(e),t===null&&(t=qa.exec(e)),t===null)throw Error(`Date resolve error`);if(n=+t[1],r=t[2]-1,i=+t[3],!t[4])return new Date(Date.UTC(n,r,i));if(a=+t[4],o=+t[5],s=+t[6],t[7]){for(c=t[7].slice(0,3);c.length<3;)c+=`0`;c=+c}return t[9]&&(u=+t[10],d=+(t[11]||0),l=(u*60+d)*6e4,t[9]===`-`&&(l=-l)),f=new Date(Date.UTC(n,r,i,a,o,s,c)),l&&f.setTime(f.getTime()-l),f}function Xa(e){return e.toISOString()}var Za=new va(`tag:yaml.org,2002:timestamp`,{kind:`scalar`,resolve:Ja,construct:Ya,instanceOf:Date,represent:Xa});function Qa(e){return e===`<<`||e===null}var $a=new va(`tag:yaml.org,2002:merge`,{kind:`scalar`,resolve:Qa}),eo=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=
15
- \r`;function to(e){if(e===null)return!1;var t,n,r=0,i=e.length,a=eo;for(n=0;n<i;n++)if(t=a.indexOf(e.charAt(n)),!(t>64)){if(t<0)return!1;r+=6}return r%8==0}function no(e){var t,n,r=e.replace(/[\r\n=]/g,``),i=r.length,a=eo,o=0,s=[];for(t=0;t<i;t++)t%4==0&&t&&(s.push(o>>16&255),s.push(o>>8&255),s.push(o&255)),o=o<<6|a.indexOf(r.charAt(t));return n=i%4*6,n===0?(s.push(o>>16&255),s.push(o>>8&255),s.push(o&255)):n===18?(s.push(o>>10&255),s.push(o>>2&255)):n===12&&s.push(o>>4&255),new Uint8Array(s)}function ro(e){var t=``,n=0,r,i,a=e.length,o=eo;for(r=0;r<a;r++)r%3==0&&r&&(t+=o[n>>18&63],t+=o[n>>12&63],t+=o[n>>6&63],t+=o[n&63]),n=(n<<8)+e[r];return i=a%3,i===0?(t+=o[n>>18&63],t+=o[n>>12&63],t+=o[n>>6&63],t+=o[n&63]):i===2?(t+=o[n>>10&63],t+=o[n>>4&63],t+=o[n<<2&63],t+=o[64]):i===1&&(t+=o[n>>2&63],t+=o[n<<4&63],t+=o[64],t+=o[64]),t}function io(e){return Object.prototype.toString.call(e)===`[object Uint8Array]`}var ao=new va(`tag:yaml.org,2002:binary`,{kind:`scalar`,resolve:to,construct:no,predicate:io,represent:ro}),oo=Object.prototype.hasOwnProperty,so=Object.prototype.toString;function co(e){if(e===null)return!0;var t=[],n,r,i,a,o,s=e;for(n=0,r=s.length;n<r;n+=1){if(i=s[n],o=!1,so.call(i)!==`[object Object]`)return!1;for(a in i)if(oo.call(i,a))if(!o)o=!0;else return!1;if(!o)return!1;if(t.indexOf(a)===-1)t.push(a);else return!1}return!0}function lo(e){return e===null?[]:e}var uo=new va(`tag:yaml.org,2002:omap`,{kind:`sequence`,resolve:co,construct:lo}),fo=Object.prototype.toString;function po(e){if(e===null)return!0;var t,n,r,i,a,o=e;for(a=Array(o.length),t=0,n=o.length;t<n;t+=1){if(r=o[t],fo.call(r)!==`[object Object]`||(i=Object.keys(r),i.length!==1))return!1;a[t]=[i[0],r[i[0]]]}return!0}function mo(e){if(e===null)return[];var t,n,r,i,a,o=e;for(a=Array(o.length),t=0,n=o.length;t<n;t+=1)r=o[t],i=Object.keys(r),a[t]=[i[0],r[i[0]]];return a}var ho=new va(`tag:yaml.org,2002:pairs`,{kind:`sequence`,resolve:po,construct:mo}),go=Object.prototype.hasOwnProperty;function _o(e){if(e===null)return!0;var t,n=e;for(t in n)if(go.call(n,t)&&n[t]!==null)return!1;return!0}function vo(e){return e===null?{}:e}var yo=new va(`tag:yaml.org,2002:set`,{kind:`mapping`,resolve:_o,construct:vo}),bo=Ga.extend({implicit:[Za,$a],explicit:[ao,uo,ho,yo]}),xo=Object.prototype.hasOwnProperty,So=1,Co=2,wo=3,To=4,Eo=1,Do=2,Oo=3,ko=/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/,Ao=/[\x85\u2028\u2029]/,jo=/[,\[\]\{\}]/,Mo=/^(?:!|!!|![a-z\-]+!)$/i,No=/^(?:!|[^,\[\]\{\}])(?:%[0-9a-f]{2}|[0-9a-z\-#;\/\?:@&=\+\$,_\.!~\*'\(\)\[\]])*$/i;function Po(e){return Object.prototype.toString.call(e)}function Fo(e){return e===10||e===13}function Io(e){return e===9||e===32}function Lo(e){return e===9||e===32||e===10||e===13}function Ro(e){return e===44||e===91||e===93||e===123||e===125}function zo(e){var t;return 48<=e&&e<=57?e-48:(t=e|32,97<=t&&t<=102?t-97+10:-1)}function Bo(e){return e===120?2:e===117?4:e===85?8:0}function Vo(e){return 48<=e&&e<=57?e-48:-1}function Ho(e){return e===48?`\0`:e===97?`\x07`:e===98?`\b`:e===116||e===9?` `:e===110?`
16
- `:e===118?`\v`:e===102?`\f`:e===114?`\r`:e===101?`\x1B`:e===32?` `:e===34?`"`:e===47?`/`:e===92?`\\`:e===78?`…`:e===95?`\xA0`:e===76?`\u2028`:e===80?`\u2029`:``}function Uo(e){return e<=65535?String.fromCharCode(e):String.fromCharCode((e-65536>>10)+55296,(e-65536&1023)+56320)}function Wo(e,t,n){t===`__proto__`?Object.defineProperty(e,t,{configurable:!0,enumerable:!0,writable:!0,value:n}):e[t]=n}for(var Go=Array(256),Ko=Array(256),qo=0;qo<256;qo++)Go[qo]=+!!Ho(qo),Ko[qo]=Ho(qo);function Jo(e,t){this.input=e,this.filename=t.filename||null,this.schema=t.schema||bo,this.onWarning=t.onWarning||null,this.legacy=t.legacy||!1,this.json=t.json||!1,this.listener=t.listener||null,this.implicitTypes=this.schema.compiledImplicit,this.typeMap=this.schema.compiledTypeMap,this.length=e.length,this.position=0,this.line=0,this.lineStart=0,this.lineIndent=0,this.firstTabInLine=-1,this.documents=[]}function Yo(e,t){var n={name:e.filename,buffer:e.input.slice(0,-1),position:e.position,line:e.line,column:e.position-e.lineStart};return n.snippet=pa(n),new la(t,n)}function R(e,t){throw Yo(e,t)}function Xo(e,t){e.onWarning&&e.onWarning.call(null,Yo(e,t))}var Zo={YAML:function(e,t,n){var r,i,a;e.version!==null&&R(e,`duplication of %YAML directive`),n.length!==1&&R(e,`YAML directive accepts exactly one argument`),r=/^([0-9]+)\.([0-9]+)$/.exec(n[0]),r===null&&R(e,`ill-formed argument of the YAML directive`),i=parseInt(r[1],10),a=parseInt(r[2],10),i!==1&&R(e,`unacceptable YAML version of the document`),e.version=n[0],e.checkLineBreaks=a<2,a!==1&&a!==2&&Xo(e,`unsupported YAML version of the document`)},TAG:function(e,t,n){var r,i;n.length!==2&&R(e,`TAG directive accepts exactly two arguments`),r=n[0],i=n[1],Mo.test(r)||R(e,`ill-formed tag handle (first argument) of the TAG directive`),xo.call(e.tagMap,r)&&R(e,`there is a previously declared suffix for "`+r+`" tag handle`),No.test(i)||R(e,`ill-formed tag prefix (second argument) of the TAG directive`);try{i=decodeURIComponent(i)}catch{R(e,`tag prefix is malformed: `+i)}e.tagMap[r]=i}};function Qo(e,t,n,r){var i,a,o,s;if(t<n){if(s=e.input.slice(t,n),r)for(i=0,a=s.length;i<a;i+=1)o=s.charCodeAt(i),o===9||32<=o&&o<=1114111||R(e,`expected valid JSON character`);else ko.test(s)&&R(e,`the stream contains non-printable characters`);e.result+=s}}function $o(e,t,n,r){var i,a,o,s;for(L.isObject(n)||R(e,`cannot merge mappings; the provided source object is unacceptable`),i=Object.keys(n),o=0,s=i.length;o<s;o+=1)a=i[o],xo.call(t,a)||(Wo(t,a,n[a]),r[a]=!0)}function es(e,t,n,r,i,a,o,s,c){var l,u;if(Array.isArray(i))for(i=Array.prototype.slice.call(i),l=0,u=i.length;l<u;l+=1)Array.isArray(i[l])&&R(e,`nested arrays are not supported inside keys`),typeof i==`object`&&Po(i[l])===`[object Object]`&&(i[l]=`[object Object]`);if(typeof i==`object`&&Po(i)===`[object Object]`&&(i=`[object Object]`),i=String(i),t===null&&(t={}),r===`tag:yaml.org,2002:merge`)if(Array.isArray(a))for(l=0,u=a.length;l<u;l+=1)$o(e,t,a[l],n);else $o(e,t,a,n);else !e.json&&!xo.call(n,i)&&xo.call(t,i)&&(e.line=o||e.line,e.lineStart=s||e.lineStart,e.position=c||e.position,R(e,`duplicated mapping key`)),Wo(t,i,a),delete n[i];return t}function ts(e){var t=e.input.charCodeAt(e.position);t===10?e.position++:t===13?(e.position++,e.input.charCodeAt(e.position)===10&&e.position++):R(e,`a line break is expected`),e.line+=1,e.lineStart=e.position,e.firstTabInLine=-1}function z(e,t,n){for(var r=0,i=e.input.charCodeAt(e.position);i!==0;){for(;Io(i);)i===9&&e.firstTabInLine===-1&&(e.firstTabInLine=e.position),i=e.input.charCodeAt(++e.position);if(t&&i===35)do i=e.input.charCodeAt(++e.position);while(i!==10&&i!==13&&i!==0);if(Fo(i))for(ts(e),i=e.input.charCodeAt(e.position),r++,e.lineIndent=0;i===32;)e.lineIndent++,i=e.input.charCodeAt(++e.position);else break}return n!==-1&&r!==0&&e.lineIndent<n&&Xo(e,`deficient indentation`),r}function ns(e){var t=e.position,n=e.input.charCodeAt(t);return!!((n===45||n===46)&&n===e.input.charCodeAt(t+1)&&n===e.input.charCodeAt(t+2)&&(t+=3,n=e.input.charCodeAt(t),n===0||Lo(n)))}function rs(e,t){t===1?e.result+=` `:t>1&&(e.result+=L.repeat(`
17
- `,t-1))}function is(e,t,n){var r,i,a,o,s,c,l,u,d=e.kind,f=e.result,p=e.input.charCodeAt(e.position);if(Lo(p)||Ro(p)||p===35||p===38||p===42||p===33||p===124||p===62||p===39||p===34||p===37||p===64||p===96||(p===63||p===45)&&(i=e.input.charCodeAt(e.position+1),Lo(i)||n&&Ro(i)))return!1;for(e.kind=`scalar`,e.result=``,a=o=e.position,s=!1;p!==0;){if(p===58){if(i=e.input.charCodeAt(e.position+1),Lo(i)||n&&Ro(i))break}else if(p===35){if(r=e.input.charCodeAt(e.position-1),Lo(r))break}else if(e.position===e.lineStart&&ns(e)||n&&Ro(p))break;else if(Fo(p))if(c=e.line,l=e.lineStart,u=e.lineIndent,z(e,!1,-1),e.lineIndent>=t){s=!0,p=e.input.charCodeAt(e.position);continue}else{e.position=o,e.line=c,e.lineStart=l,e.lineIndent=u;break}s&&=(Qo(e,a,o,!1),rs(e,e.line-c),a=o=e.position,!1),Io(p)||(o=e.position+1),p=e.input.charCodeAt(++e.position)}return Qo(e,a,o,!1),e.result?!0:(e.kind=d,e.result=f,!1)}function as(e,t){var n=e.input.charCodeAt(e.position),r,i;if(n!==39)return!1;for(e.kind=`scalar`,e.result=``,e.position++,r=i=e.position;(n=e.input.charCodeAt(e.position))!==0;)if(n===39)if(Qo(e,r,e.position,!0),n=e.input.charCodeAt(++e.position),n===39)r=e.position,e.position++,i=e.position;else return!0;else Fo(n)?(Qo(e,r,i,!0),rs(e,z(e,!1,t)),r=i=e.position):e.position===e.lineStart&&ns(e)?R(e,`unexpected end of the document within a single quoted scalar`):(e.position++,i=e.position);R(e,`unexpected end of the stream within a single quoted scalar`)}function os(e,t){var n,r,i,a,o,s=e.input.charCodeAt(e.position);if(s!==34)return!1;for(e.kind=`scalar`,e.result=``,e.position++,n=r=e.position;(s=e.input.charCodeAt(e.position))!==0;)if(s===34)return Qo(e,n,e.position,!0),e.position++,!0;else if(s===92){if(Qo(e,n,e.position,!0),s=e.input.charCodeAt(++e.position),Fo(s))z(e,!1,t);else if(s<256&&Go[s])e.result+=Ko[s],e.position++;else if((o=Bo(s))>0){for(i=o,a=0;i>0;i--)s=e.input.charCodeAt(++e.position),(o=zo(s))>=0?a=(a<<4)+o:R(e,`expected hexadecimal character`);e.result+=Uo(a),e.position++}else R(e,`unknown escape sequence`);n=r=e.position}else Fo(s)?(Qo(e,n,r,!0),rs(e,z(e,!1,t)),n=r=e.position):e.position===e.lineStart&&ns(e)?R(e,`unexpected end of the document within a double quoted scalar`):(e.position++,r=e.position);R(e,`unexpected end of the stream within a double quoted scalar`)}function ss(e,t){var n=!0,r,i,a,o=e.tag,s,c=e.anchor,l,u,d,f,p,m=Object.create(null),h,g,_,v=e.input.charCodeAt(e.position);if(v===91)u=93,p=!1,s=[];else if(v===123)u=125,p=!0,s={};else return!1;for(e.anchor!==null&&(e.anchorMap[e.anchor]=s),v=e.input.charCodeAt(++e.position);v!==0;){if(z(e,!0,t),v=e.input.charCodeAt(e.position),v===u)return e.position++,e.tag=o,e.anchor=c,e.kind=p?`mapping`:`sequence`,e.result=s,!0;n?v===44&&R(e,`expected the node content, but found ','`):R(e,`missed comma between flow collection entries`),g=h=_=null,d=f=!1,v===63&&(l=e.input.charCodeAt(e.position+1),Lo(l)&&(d=f=!0,e.position++,z(e,!0,t))),r=e.line,i=e.lineStart,a=e.position,ms(e,t,So,!1,!0),g=e.tag,h=e.result,z(e,!0,t),v=e.input.charCodeAt(e.position),(f||e.line===r)&&v===58&&(d=!0,v=e.input.charCodeAt(++e.position),z(e,!0,t),ms(e,t,So,!1,!0),_=e.result),p?es(e,s,m,g,h,_,r,i,a):d?s.push(es(e,null,m,g,h,_,r,i,a)):s.push(h),z(e,!0,t),v=e.input.charCodeAt(e.position),v===44?(n=!0,v=e.input.charCodeAt(++e.position)):n=!1}R(e,`unexpected end of the stream within a flow collection`)}function cs(e,t){var n,r,i=Eo,a=!1,o=!1,s=t,c=0,l=!1,u,d=e.input.charCodeAt(e.position);if(d===124)r=!1;else if(d===62)r=!0;else return!1;for(e.kind=`scalar`,e.result=``;d!==0;)if(d=e.input.charCodeAt(++e.position),d===43||d===45)Eo===i?i=d===43?Oo:Do:R(e,`repeat of a chomping mode identifier`);else if((u=Vo(d))>=0)u===0?R(e,`bad explicit indentation width of a block scalar; it cannot be less than one`):o?R(e,`repeat of an indentation width identifier`):(s=t+u-1,o=!0);else break;if(Io(d)){do d=e.input.charCodeAt(++e.position);while(Io(d));if(d===35)do d=e.input.charCodeAt(++e.position);while(!Fo(d)&&d!==0)}for(;d!==0;){for(ts(e),e.lineIndent=0,d=e.input.charCodeAt(e.position);(!o||e.lineIndent<s)&&d===32;)e.lineIndent++,d=e.input.charCodeAt(++e.position);if(!o&&e.lineIndent>s&&(s=e.lineIndent),Fo(d)){c++;continue}if(e.lineIndent<s){i===Oo?e.result+=L.repeat(`
18
- `,a?1+c:c):i===Eo&&a&&(e.result+=`
19
- `);break}for(r?Io(d)?(l=!0,e.result+=L.repeat(`
13
+ `,c=1;c<=t.linesAfter&&!(o+c>=i.length);c++)l=Oa(e.buffer,r[o+c],i[o+c],e.position-(r[o]-r[o+c]),d),s+=L.repeat(` `,t.indent)+ka((e.line+c+1).toString(),u)+` | `+l.str+`
14
+ `;return s.replace(/\n$/,``)}var ja=Aa,Ma=[`kind`,`multi`,`resolve`,`construct`,`instanceOf`,`predicate`,`represent`,`representName`,`defaultStyle`,`styleAliases`],Na=[`scalar`,`sequence`,`mapping`];function Pa(e){var t={};return e!==null&&Object.keys(e).forEach(function(n){e[n].forEach(function(e){t[String(e)]=n})}),t}function Fa(e,t){if(t||={},Object.keys(t).forEach(function(t){if(Ma.indexOf(t)===-1)throw new Da(`Unknown option "`+t+`" is met in definition of "`+e+`" YAML type.`)}),this.options=t,this.tag=e,this.kind=t.kind||null,this.resolve=t.resolve||function(){return!0},this.construct=t.construct||function(e){return e},this.instanceOf=t.instanceOf||null,this.predicate=t.predicate||null,this.represent=t.represent||null,this.representName=t.representName||null,this.defaultStyle=t.defaultStyle||null,this.multi=t.multi||!1,this.styleAliases=Pa(t.styleAliases||null),Na.indexOf(this.kind)===-1)throw new Da(`Unknown kind "`+this.kind+`" is specified for "`+e+`" YAML type.`)}var Ia=Fa;function La(e,t){var n=[];return e[t].forEach(function(e){var t=n.length;n.forEach(function(n,r){n.tag===e.tag&&n.kind===e.kind&&n.multi===e.multi&&(t=r)}),n[t]=e}),n}function Ra(){var e={scalar:{},sequence:{},mapping:{},fallback:{},multi:{scalar:[],sequence:[],mapping:[],fallback:[]}},t,n;function r(t){t.multi?(e.multi[t.kind].push(t),e.multi.fallback.push(t)):e[t.kind][t.tag]=e.fallback[t.tag]=t}for(t=0,n=arguments.length;t<n;t+=1)arguments[t].forEach(r);return e}function za(e){return this.extend(e)}za.prototype.extend=function(e){var t=[],n=[];if(e instanceof Ia)n.push(e);else if(Array.isArray(e))n=n.concat(e);else if(e&&(Array.isArray(e.implicit)||Array.isArray(e.explicit)))e.implicit&&(t=t.concat(e.implicit)),e.explicit&&(n=n.concat(e.explicit));else throw new Da(`Schema.extend argument should be a Type, [ Type ], or a schema definition ({ implicit: [...], explicit: [...] })`);t.forEach(function(e){if(!(e instanceof Ia))throw new Da(`Specified list of YAML types (or a single Type object) contains a non-Type object.`);if(e.loadKind&&e.loadKind!==`scalar`)throw new Da(`There is a non-scalar type in the implicit list of a schema. Implicit resolving of such types is not supported.`);if(e.multi)throw new Da(`There is a multi type in the implicit list of a schema. Multi tags can only be listed as explicit.`)}),n.forEach(function(e){if(!(e instanceof Ia))throw new Da(`Specified list of YAML types (or a single Type object) contains a non-Type object.`)});var r=Object.create(za.prototype);return r.implicit=(this.implicit||[]).concat(t),r.explicit=(this.explicit||[]).concat(n),r.compiledImplicit=La(r,`implicit`),r.compiledExplicit=La(r,`explicit`),r.compiledTypeMap=Ra(r.compiledImplicit,r.compiledExplicit),r};var Ba=new za({explicit:[new Ia(`tag:yaml.org,2002:str`,{kind:`scalar`,construct:function(e){return e===null?``:e}}),new Ia(`tag:yaml.org,2002:seq`,{kind:`sequence`,construct:function(e){return e===null?[]:e}}),new Ia(`tag:yaml.org,2002:map`,{kind:`mapping`,construct:function(e){return e===null?{}:e}})]});function Va(e){if(e===null)return!0;var t=e.length;return t===1&&e===`~`||t===4&&(e===`null`||e===`Null`||e===`NULL`)}function Ha(){return null}function Ua(e){return e===null}var Wa=new Ia(`tag:yaml.org,2002:null`,{kind:`scalar`,resolve:Va,construct:Ha,predicate:Ua,represent:{canonical:function(){return`~`},lowercase:function(){return`null`},uppercase:function(){return`NULL`},camelcase:function(){return`Null`},empty:function(){return``}},defaultStyle:`lowercase`});function Ga(e){if(e===null)return!1;var t=e.length;return t===4&&(e===`true`||e===`True`||e===`TRUE`)||t===5&&(e===`false`||e===`False`||e===`FALSE`)}function Ka(e){return e===`true`||e===`True`||e===`TRUE`}function qa(e){return Object.prototype.toString.call(e)===`[object Boolean]`}var Ja=new Ia(`tag:yaml.org,2002:bool`,{kind:`scalar`,resolve:Ga,construct:Ka,predicate:qa,represent:{lowercase:function(e){return e?`true`:`false`},uppercase:function(e){return e?`TRUE`:`FALSE`},camelcase:function(e){return e?`True`:`False`}},defaultStyle:`lowercase`});function Ya(e){return 48<=e&&e<=57||65<=e&&e<=70||97<=e&&e<=102}function Xa(e){return 48<=e&&e<=55}function Za(e){return 48<=e&&e<=57}function Qa(e){if(e===null)return!1;var t=e.length,n=0,r=!1,i;if(!t)return!1;if(i=e[n],(i===`-`||i===`+`)&&(i=e[++n]),i===`0`){if(n+1===t)return!0;if(i=e[++n],i===`b`){for(n++;n<t;n++)if(i=e[n],i!==`_`){if(i!==`0`&&i!==`1`)return!1;r=!0}return r&&i!==`_`}if(i===`x`){for(n++;n<t;n++)if(i=e[n],i!==`_`){if(!Ya(e.charCodeAt(n)))return!1;r=!0}return r&&i!==`_`}if(i===`o`){for(n++;n<t;n++)if(i=e[n],i!==`_`){if(!Xa(e.charCodeAt(n)))return!1;r=!0}return r&&i!==`_`}}if(i===`_`)return!1;for(;n<t;n++)if(i=e[n],i!==`_`){if(!Za(e.charCodeAt(n)))return!1;r=!0}return!(!r||i===`_`)}function $a(e){var t=e,n=1,r;if(t.indexOf(`_`)!==-1&&(t=t.replace(/_/g,``)),r=t[0],(r===`-`||r===`+`)&&(r===`-`&&(n=-1),t=t.slice(1),r=t[0]),t===`0`)return 0;if(r===`0`){if(t[1]===`b`)return n*parseInt(t.slice(2),2);if(t[1]===`x`)return n*parseInt(t.slice(2),16);if(t[1]===`o`)return n*parseInt(t.slice(2),8)}return n*parseInt(t,10)}function eo(e){return Object.prototype.toString.call(e)===`[object Number]`&&e%1==0&&!L.isNegativeZero(e)}var to=new Ia(`tag:yaml.org,2002:int`,{kind:`scalar`,resolve:Qa,construct:$a,predicate:eo,represent:{binary:function(e){return e>=0?`0b`+e.toString(2):`-0b`+e.toString(2).slice(1)},octal:function(e){return e>=0?`0o`+e.toString(8):`-0o`+e.toString(8).slice(1)},decimal:function(e){return e.toString(10)},hexadecimal:function(e){return e>=0?`0x`+e.toString(16).toUpperCase():`-0x`+e.toString(16).toUpperCase().slice(1)}},defaultStyle:`decimal`,styleAliases:{binary:[2,`bin`],octal:[8,`oct`],decimal:[10,`dec`],hexadecimal:[16,`hex`]}}),no=RegExp(`^(?:[-+]?(?:[0-9][0-9_]*)(?:\\.[0-9_]*)?(?:[eE][-+]?[0-9]+)?|\\.[0-9_]+(?:[eE][-+]?[0-9]+)?|[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$`);function ro(e){return!(e===null||!no.test(e)||e[e.length-1]===`_`)}function io(e){var t=e.replace(/_/g,``).toLowerCase(),n=t[0]===`-`?-1:1;return`+-`.indexOf(t[0])>=0&&(t=t.slice(1)),t===`.inf`?n===1?1/0:-1/0:t===`.nan`?NaN:n*parseFloat(t,10)}var ao=/^[-+]?[0-9]+e/;function oo(e,t){var n;if(isNaN(e))switch(t){case`lowercase`:return`.nan`;case`uppercase`:return`.NAN`;case`camelcase`:return`.NaN`}else if(e===1/0)switch(t){case`lowercase`:return`.inf`;case`uppercase`:return`.INF`;case`camelcase`:return`.Inf`}else if(e===-1/0)switch(t){case`lowercase`:return`-.inf`;case`uppercase`:return`-.INF`;case`camelcase`:return`-.Inf`}else if(L.isNegativeZero(e))return`-0.0`;return n=e.toString(10),ao.test(n)?n.replace(`e`,`.e`):n}function so(e){return Object.prototype.toString.call(e)===`[object Number]`&&(e%1!=0||L.isNegativeZero(e))}var co=new Ia(`tag:yaml.org,2002:float`,{kind:`scalar`,resolve:ro,construct:io,predicate:so,represent:oo,defaultStyle:`lowercase`}),lo=Ba.extend({implicit:[Wa,Ja,to,co]}),uo=RegExp(`^([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])$`),fo=RegExp(`^([0-9][0-9][0-9][0-9])-([0-9][0-9]?)-([0-9][0-9]?)(?:[Tt]|[ \\t]+)([0-9][0-9]?):([0-9][0-9]):([0-9][0-9])(?:\\.([0-9]*))?(?:[ \\t]*(Z|([-+])([0-9][0-9]?)(?::([0-9][0-9]))?))?$`);function po(e){return e===null?!1:uo.exec(e)!==null||fo.exec(e)!==null}function mo(e){var t,n,r,i,a,o,s,c=0,l=null,u,d,f;if(t=uo.exec(e),t===null&&(t=fo.exec(e)),t===null)throw Error(`Date resolve error`);if(n=+t[1],r=t[2]-1,i=+t[3],!t[4])return new Date(Date.UTC(n,r,i));if(a=+t[4],o=+t[5],s=+t[6],t[7]){for(c=t[7].slice(0,3);c.length<3;)c+=`0`;c=+c}return t[9]&&(u=+t[10],d=+(t[11]||0),l=(u*60+d)*6e4,t[9]===`-`&&(l=-l)),f=new Date(Date.UTC(n,r,i,a,o,s,c)),l&&f.setTime(f.getTime()-l),f}function ho(e){return e.toISOString()}var go=new Ia(`tag:yaml.org,2002:timestamp`,{kind:`scalar`,resolve:po,construct:mo,instanceOf:Date,represent:ho});function _o(e){return e===`<<`||e===null}var vo=new Ia(`tag:yaml.org,2002:merge`,{kind:`scalar`,resolve:_o}),yo=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=
15
+ \r`;function bo(e){if(e===null)return!1;var t,n,r=0,i=e.length,a=yo;for(n=0;n<i;n++)if(t=a.indexOf(e.charAt(n)),!(t>64)){if(t<0)return!1;r+=6}return r%8==0}function xo(e){var t,n,r=e.replace(/[\r\n=]/g,``),i=r.length,a=yo,o=0,s=[];for(t=0;t<i;t++)t%4==0&&t&&(s.push(o>>16&255),s.push(o>>8&255),s.push(o&255)),o=o<<6|a.indexOf(r.charAt(t));return n=i%4*6,n===0?(s.push(o>>16&255),s.push(o>>8&255),s.push(o&255)):n===18?(s.push(o>>10&255),s.push(o>>2&255)):n===12&&s.push(o>>4&255),new Uint8Array(s)}function So(e){var t=``,n=0,r,i,a=e.length,o=yo;for(r=0;r<a;r++)r%3==0&&r&&(t+=o[n>>18&63],t+=o[n>>12&63],t+=o[n>>6&63],t+=o[n&63]),n=(n<<8)+e[r];return i=a%3,i===0?(t+=o[n>>18&63],t+=o[n>>12&63],t+=o[n>>6&63],t+=o[n&63]):i===2?(t+=o[n>>10&63],t+=o[n>>4&63],t+=o[n<<2&63],t+=o[64]):i===1&&(t+=o[n>>2&63],t+=o[n<<4&63],t+=o[64],t+=o[64]),t}function Co(e){return Object.prototype.toString.call(e)===`[object Uint8Array]`}var wo=new Ia(`tag:yaml.org,2002:binary`,{kind:`scalar`,resolve:bo,construct:xo,predicate:Co,represent:So}),To=Object.prototype.hasOwnProperty,Eo=Object.prototype.toString;function Do(e){if(e===null)return!0;var t=[],n,r,i,a,o,s=e;for(n=0,r=s.length;n<r;n+=1){if(i=s[n],o=!1,Eo.call(i)!==`[object Object]`)return!1;for(a in i)if(To.call(i,a))if(!o)o=!0;else return!1;if(!o)return!1;if(t.indexOf(a)===-1)t.push(a);else return!1}return!0}function Oo(e){return e===null?[]:e}var ko=new Ia(`tag:yaml.org,2002:omap`,{kind:`sequence`,resolve:Do,construct:Oo}),Ao=Object.prototype.toString;function jo(e){if(e===null)return!0;var t,n,r,i,a,o=e;for(a=Array(o.length),t=0,n=o.length;t<n;t+=1){if(r=o[t],Ao.call(r)!==`[object Object]`||(i=Object.keys(r),i.length!==1))return!1;a[t]=[i[0],r[i[0]]]}return!0}function Mo(e){if(e===null)return[];var t,n,r,i,a,o=e;for(a=Array(o.length),t=0,n=o.length;t<n;t+=1)r=o[t],i=Object.keys(r),a[t]=[i[0],r[i[0]]];return a}var No=new Ia(`tag:yaml.org,2002:pairs`,{kind:`sequence`,resolve:jo,construct:Mo}),Po=Object.prototype.hasOwnProperty;function Fo(e){if(e===null)return!0;var t,n=e;for(t in n)if(Po.call(n,t)&&n[t]!==null)return!1;return!0}function Io(e){return e===null?{}:e}var Lo=new Ia(`tag:yaml.org,2002:set`,{kind:`mapping`,resolve:Fo,construct:Io}),Ro=lo.extend({implicit:[go,vo],explicit:[wo,ko,No,Lo]}),zo=Object.prototype.hasOwnProperty,Bo=1,Vo=2,Ho=3,Uo=4,Wo=1,Go=2,Ko=3,qo=/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/,Jo=/[\x85\u2028\u2029]/,Yo=/[,\[\]\{\}]/,Xo=/^(?:!|!!|![a-z\-]+!)$/i,Zo=/^(?:!|[^,\[\]\{\}])(?:%[0-9a-f]{2}|[0-9a-z\-#;\/\?:@&=\+\$,_\.!~\*'\(\)\[\]])*$/i;function Qo(e){return Object.prototype.toString.call(e)}function $o(e){return e===10||e===13}function es(e){return e===9||e===32}function ts(e){return e===9||e===32||e===10||e===13}function ns(e){return e===44||e===91||e===93||e===123||e===125}function rs(e){var t;return 48<=e&&e<=57?e-48:(t=e|32,97<=t&&t<=102?t-97+10:-1)}function is(e){return e===120?2:e===117?4:e===85?8:0}function as(e){return 48<=e&&e<=57?e-48:-1}function os(e){return e===48?`\0`:e===97?`\x07`:e===98?`\b`:e===116||e===9?` `:e===110?`
16
+ `:e===118?`\v`:e===102?`\f`:e===114?`\r`:e===101?`\x1B`:e===32?` `:e===34?`"`:e===47?`/`:e===92?`\\`:e===78?`…`:e===95?`\xA0`:e===76?`\u2028`:e===80?`\u2029`:``}function ss(e){return e<=65535?String.fromCharCode(e):String.fromCharCode((e-65536>>10)+55296,(e-65536&1023)+56320)}function cs(e,t,n){t===`__proto__`?Object.defineProperty(e,t,{configurable:!0,enumerable:!0,writable:!0,value:n}):e[t]=n}for(var ls=Array(256),us=Array(256),ds=0;ds<256;ds++)ls[ds]=+!!os(ds),us[ds]=os(ds);function fs(e,t){this.input=e,this.filename=t.filename||null,this.schema=t.schema||Ro,this.onWarning=t.onWarning||null,this.legacy=t.legacy||!1,this.json=t.json||!1,this.listener=t.listener||null,this.implicitTypes=this.schema.compiledImplicit,this.typeMap=this.schema.compiledTypeMap,this.length=e.length,this.position=0,this.line=0,this.lineStart=0,this.lineIndent=0,this.firstTabInLine=-1,this.documents=[]}function ps(e,t){var n={name:e.filename,buffer:e.input.slice(0,-1),position:e.position,line:e.line,column:e.position-e.lineStart};return n.snippet=ja(n),new Da(t,n)}function R(e,t){throw ps(e,t)}function ms(e,t){e.onWarning&&e.onWarning.call(null,ps(e,t))}var hs={YAML:function(e,t,n){var r,i,a;e.version!==null&&R(e,`duplication of %YAML directive`),n.length!==1&&R(e,`YAML directive accepts exactly one argument`),r=/^([0-9]+)\.([0-9]+)$/.exec(n[0]),r===null&&R(e,`ill-formed argument of the YAML directive`),i=parseInt(r[1],10),a=parseInt(r[2],10),i!==1&&R(e,`unacceptable YAML version of the document`),e.version=n[0],e.checkLineBreaks=a<2,a!==1&&a!==2&&ms(e,`unsupported YAML version of the document`)},TAG:function(e,t,n){var r,i;n.length!==2&&R(e,`TAG directive accepts exactly two arguments`),r=n[0],i=n[1],Xo.test(r)||R(e,`ill-formed tag handle (first argument) of the TAG directive`),zo.call(e.tagMap,r)&&R(e,`there is a previously declared suffix for "`+r+`" tag handle`),Zo.test(i)||R(e,`ill-formed tag prefix (second argument) of the TAG directive`);try{i=decodeURIComponent(i)}catch{R(e,`tag prefix is malformed: `+i)}e.tagMap[r]=i}};function gs(e,t,n,r){var i,a,o,s;if(t<n){if(s=e.input.slice(t,n),r)for(i=0,a=s.length;i<a;i+=1)o=s.charCodeAt(i),o===9||32<=o&&o<=1114111||R(e,`expected valid JSON character`);else qo.test(s)&&R(e,`the stream contains non-printable characters`);e.result+=s}}function _s(e,t,n,r){var i,a,o,s;for(L.isObject(n)||R(e,`cannot merge mappings; the provided source object is unacceptable`),i=Object.keys(n),o=0,s=i.length;o<s;o+=1)a=i[o],zo.call(t,a)||(cs(t,a,n[a]),r[a]=!0)}function vs(e,t,n,r,i,a,o,s,c){var l,u;if(Array.isArray(i))for(i=Array.prototype.slice.call(i),l=0,u=i.length;l<u;l+=1)Array.isArray(i[l])&&R(e,`nested arrays are not supported inside keys`),typeof i==`object`&&Qo(i[l])===`[object Object]`&&(i[l]=`[object Object]`);if(typeof i==`object`&&Qo(i)===`[object Object]`&&(i=`[object Object]`),i=String(i),t===null&&(t={}),r===`tag:yaml.org,2002:merge`)if(Array.isArray(a))for(l=0,u=a.length;l<u;l+=1)_s(e,t,a[l],n);else _s(e,t,a,n);else !e.json&&!zo.call(n,i)&&zo.call(t,i)&&(e.line=o||e.line,e.lineStart=s||e.lineStart,e.position=c||e.position,R(e,`duplicated mapping key`)),cs(t,i,a),delete n[i];return t}function ys(e){var t=e.input.charCodeAt(e.position);t===10?e.position++:t===13?(e.position++,e.input.charCodeAt(e.position)===10&&e.position++):R(e,`a line break is expected`),e.line+=1,e.lineStart=e.position,e.firstTabInLine=-1}function z(e,t,n){for(var r=0,i=e.input.charCodeAt(e.position);i!==0;){for(;es(i);)i===9&&e.firstTabInLine===-1&&(e.firstTabInLine=e.position),i=e.input.charCodeAt(++e.position);if(t&&i===35)do i=e.input.charCodeAt(++e.position);while(i!==10&&i!==13&&i!==0);if($o(i))for(ys(e),i=e.input.charCodeAt(e.position),r++,e.lineIndent=0;i===32;)e.lineIndent++,i=e.input.charCodeAt(++e.position);else break}return n!==-1&&r!==0&&e.lineIndent<n&&ms(e,`deficient indentation`),r}function bs(e){var t=e.position,n=e.input.charCodeAt(t);return!!((n===45||n===46)&&n===e.input.charCodeAt(t+1)&&n===e.input.charCodeAt(t+2)&&(t+=3,n=e.input.charCodeAt(t),n===0||ts(n)))}function xs(e,t){t===1?e.result+=` `:t>1&&(e.result+=L.repeat(`
17
+ `,t-1))}function Ss(e,t,n){var r,i,a,o,s,c,l,u,d=e.kind,f=e.result,p=e.input.charCodeAt(e.position);if(ts(p)||ns(p)||p===35||p===38||p===42||p===33||p===124||p===62||p===39||p===34||p===37||p===64||p===96||(p===63||p===45)&&(i=e.input.charCodeAt(e.position+1),ts(i)||n&&ns(i)))return!1;for(e.kind=`scalar`,e.result=``,a=o=e.position,s=!1;p!==0;){if(p===58){if(i=e.input.charCodeAt(e.position+1),ts(i)||n&&ns(i))break}else if(p===35){if(r=e.input.charCodeAt(e.position-1),ts(r))break}else if(e.position===e.lineStart&&bs(e)||n&&ns(p))break;else if($o(p))if(c=e.line,l=e.lineStart,u=e.lineIndent,z(e,!1,-1),e.lineIndent>=t){s=!0,p=e.input.charCodeAt(e.position);continue}else{e.position=o,e.line=c,e.lineStart=l,e.lineIndent=u;break}s&&=(gs(e,a,o,!1),xs(e,e.line-c),a=o=e.position,!1),es(p)||(o=e.position+1),p=e.input.charCodeAt(++e.position)}return gs(e,a,o,!1),e.result?!0:(e.kind=d,e.result=f,!1)}function Cs(e,t){var n=e.input.charCodeAt(e.position),r,i;if(n!==39)return!1;for(e.kind=`scalar`,e.result=``,e.position++,r=i=e.position;(n=e.input.charCodeAt(e.position))!==0;)if(n===39)if(gs(e,r,e.position,!0),n=e.input.charCodeAt(++e.position),n===39)r=e.position,e.position++,i=e.position;else return!0;else $o(n)?(gs(e,r,i,!0),xs(e,z(e,!1,t)),r=i=e.position):e.position===e.lineStart&&bs(e)?R(e,`unexpected end of the document within a single quoted scalar`):(e.position++,i=e.position);R(e,`unexpected end of the stream within a single quoted scalar`)}function ws(e,t){var n,r,i,a,o,s=e.input.charCodeAt(e.position);if(s!==34)return!1;for(e.kind=`scalar`,e.result=``,e.position++,n=r=e.position;(s=e.input.charCodeAt(e.position))!==0;)if(s===34)return gs(e,n,e.position,!0),e.position++,!0;else if(s===92){if(gs(e,n,e.position,!0),s=e.input.charCodeAt(++e.position),$o(s))z(e,!1,t);else if(s<256&&ls[s])e.result+=us[s],e.position++;else if((o=is(s))>0){for(i=o,a=0;i>0;i--)s=e.input.charCodeAt(++e.position),(o=rs(s))>=0?a=(a<<4)+o:R(e,`expected hexadecimal character`);e.result+=ss(a),e.position++}else R(e,`unknown escape sequence`);n=r=e.position}else $o(s)?(gs(e,n,r,!0),xs(e,z(e,!1,t)),n=r=e.position):e.position===e.lineStart&&bs(e)?R(e,`unexpected end of the document within a double quoted scalar`):(e.position++,r=e.position);R(e,`unexpected end of the stream within a double quoted scalar`)}function Ts(e,t){var n=!0,r,i,a,o=e.tag,s,c=e.anchor,l,u,d,f,p,m=Object.create(null),h,g,_,v=e.input.charCodeAt(e.position);if(v===91)u=93,p=!1,s=[];else if(v===123)u=125,p=!0,s={};else return!1;for(e.anchor!==null&&(e.anchorMap[e.anchor]=s),v=e.input.charCodeAt(++e.position);v!==0;){if(z(e,!0,t),v=e.input.charCodeAt(e.position),v===u)return e.position++,e.tag=o,e.anchor=c,e.kind=p?`mapping`:`sequence`,e.result=s,!0;n?v===44&&R(e,`expected the node content, but found ','`):R(e,`missed comma between flow collection entries`),g=h=_=null,d=f=!1,v===63&&(l=e.input.charCodeAt(e.position+1),ts(l)&&(d=f=!0,e.position++,z(e,!0,t))),r=e.line,i=e.lineStart,a=e.position,Ms(e,t,Bo,!1,!0),g=e.tag,h=e.result,z(e,!0,t),v=e.input.charCodeAt(e.position),(f||e.line===r)&&v===58&&(d=!0,v=e.input.charCodeAt(++e.position),z(e,!0,t),Ms(e,t,Bo,!1,!0),_=e.result),p?vs(e,s,m,g,h,_,r,i,a):d?s.push(vs(e,null,m,g,h,_,r,i,a)):s.push(h),z(e,!0,t),v=e.input.charCodeAt(e.position),v===44?(n=!0,v=e.input.charCodeAt(++e.position)):n=!1}R(e,`unexpected end of the stream within a flow collection`)}function Es(e,t){var n,r,i=Wo,a=!1,o=!1,s=t,c=0,l=!1,u,d=e.input.charCodeAt(e.position);if(d===124)r=!1;else if(d===62)r=!0;else return!1;for(e.kind=`scalar`,e.result=``;d!==0;)if(d=e.input.charCodeAt(++e.position),d===43||d===45)Wo===i?i=d===43?Ko:Go:R(e,`repeat of a chomping mode identifier`);else if((u=as(d))>=0)u===0?R(e,`bad explicit indentation width of a block scalar; it cannot be less than one`):o?R(e,`repeat of an indentation width identifier`):(s=t+u-1,o=!0);else break;if(es(d)){do d=e.input.charCodeAt(++e.position);while(es(d));if(d===35)do d=e.input.charCodeAt(++e.position);while(!$o(d)&&d!==0)}for(;d!==0;){for(ys(e),e.lineIndent=0,d=e.input.charCodeAt(e.position);(!o||e.lineIndent<s)&&d===32;)e.lineIndent++,d=e.input.charCodeAt(++e.position);if(!o&&e.lineIndent>s&&(s=e.lineIndent),$o(d)){c++;continue}if(e.lineIndent<s){i===Ko?e.result+=L.repeat(`
18
+ `,a?1+c:c):i===Wo&&a&&(e.result+=`
19
+ `);break}for(r?es(d)?(l=!0,e.result+=L.repeat(`
20
20
  `,a?1+c:c)):l?(l=!1,e.result+=L.repeat(`
21
21
  `,c+1)):c===0?a&&(e.result+=` `):e.result+=L.repeat(`
22
22
  `,c):e.result+=L.repeat(`
23
- `,a?1+c:c),a=!0,o=!0,c=0,n=e.position;!Fo(d)&&d!==0;)d=e.input.charCodeAt(++e.position);Qo(e,n,e.position,!1)}return!0}function ls(e,t){var n,r=e.tag,i=e.anchor,a=[],o,s=!1,c;if(e.firstTabInLine!==-1)return!1;for(e.anchor!==null&&(e.anchorMap[e.anchor]=a),c=e.input.charCodeAt(e.position);c!==0&&(e.firstTabInLine!==-1&&(e.position=e.firstTabInLine,R(e,`tab characters must not be used in indentation`)),!(c!==45||(o=e.input.charCodeAt(e.position+1),!Lo(o))));){if(s=!0,e.position++,z(e,!0,-1)&&e.lineIndent<=t){a.push(null),c=e.input.charCodeAt(e.position);continue}if(n=e.line,ms(e,t,wo,!1,!0),a.push(e.result),z(e,!0,-1),c=e.input.charCodeAt(e.position),(e.line===n||e.lineIndent>t)&&c!==0)R(e,`bad indentation of a sequence entry`);else if(e.lineIndent<t)break}return s?(e.tag=r,e.anchor=i,e.kind=`sequence`,e.result=a,!0):!1}function us(e,t,n){var r,i,a,o,s,c,l=e.tag,u=e.anchor,d={},f=Object.create(null),p=null,m=null,h=null,g=!1,_=!1,v;if(e.firstTabInLine!==-1)return!1;for(e.anchor!==null&&(e.anchorMap[e.anchor]=d),v=e.input.charCodeAt(e.position);v!==0;){if(!g&&e.firstTabInLine!==-1&&(e.position=e.firstTabInLine,R(e,`tab characters must not be used in indentation`)),r=e.input.charCodeAt(e.position+1),a=e.line,(v===63||v===58)&&Lo(r))v===63?(g&&(es(e,d,f,p,m,null,o,s,c),p=m=h=null),_=!0,g=!0,i=!0):g?(g=!1,i=!0):R(e,`incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line`),e.position+=1,v=r;else{if(o=e.line,s=e.lineStart,c=e.position,!ms(e,n,Co,!1,!0))break;if(e.line===a){for(v=e.input.charCodeAt(e.position);Io(v);)v=e.input.charCodeAt(++e.position);if(v===58)v=e.input.charCodeAt(++e.position),Lo(v)||R(e,`a whitespace character is expected after the key-value separator within a block mapping`),g&&(es(e,d,f,p,m,null,o,s,c),p=m=h=null),_=!0,g=!1,i=!1,p=e.tag,m=e.result;else if(_)R(e,`can not read an implicit mapping pair; a colon is missed`);else return e.tag=l,e.anchor=u,!0}else if(_)R(e,`can not read a block mapping entry; a multiline key may not be an implicit key`);else return e.tag=l,e.anchor=u,!0}if((e.line===a||e.lineIndent>t)&&(g&&(o=e.line,s=e.lineStart,c=e.position),ms(e,t,To,!0,i)&&(g?m=e.result:h=e.result),g||(es(e,d,f,p,m,h,o,s,c),p=m=h=null),z(e,!0,-1),v=e.input.charCodeAt(e.position)),(e.line===a||e.lineIndent>t)&&v!==0)R(e,`bad indentation of a mapping entry`);else if(e.lineIndent<t)break}return g&&es(e,d,f,p,m,null,o,s,c),_&&(e.tag=l,e.anchor=u,e.kind=`mapping`,e.result=d),_}function ds(e){var t,n=!1,r=!1,i,a,o=e.input.charCodeAt(e.position);if(o!==33)return!1;if(e.tag!==null&&R(e,`duplication of a tag property`),o=e.input.charCodeAt(++e.position),o===60?(n=!0,o=e.input.charCodeAt(++e.position)):o===33?(r=!0,i=`!!`,o=e.input.charCodeAt(++e.position)):i=`!`,t=e.position,n){do o=e.input.charCodeAt(++e.position);while(o!==0&&o!==62);e.position<e.length?(a=e.input.slice(t,e.position),o=e.input.charCodeAt(++e.position)):R(e,`unexpected end of the stream within a verbatim tag`)}else{for(;o!==0&&!Lo(o);)o===33&&(r?R(e,`tag suffix cannot contain exclamation marks`):(i=e.input.slice(t-1,e.position+1),Mo.test(i)||R(e,`named tag handle cannot contain such characters`),r=!0,t=e.position+1)),o=e.input.charCodeAt(++e.position);a=e.input.slice(t,e.position),jo.test(a)&&R(e,`tag suffix cannot contain flow indicator characters`)}a&&!No.test(a)&&R(e,`tag name cannot contain such characters: `+a);try{a=decodeURIComponent(a)}catch{R(e,`tag name is malformed: `+a)}return n?e.tag=a:xo.call(e.tagMap,i)?e.tag=e.tagMap[i]+a:i===`!`?e.tag=`!`+a:i===`!!`?e.tag=`tag:yaml.org,2002:`+a:R(e,`undeclared tag handle "`+i+`"`),!0}function fs(e){var t,n=e.input.charCodeAt(e.position);if(n!==38)return!1;for(e.anchor!==null&&R(e,`duplication of an anchor property`),n=e.input.charCodeAt(++e.position),t=e.position;n!==0&&!Lo(n)&&!Ro(n);)n=e.input.charCodeAt(++e.position);return e.position===t&&R(e,`name of an anchor node must contain at least one character`),e.anchor=e.input.slice(t,e.position),!0}function ps(e){var t,n,r=e.input.charCodeAt(e.position);if(r!==42)return!1;for(r=e.input.charCodeAt(++e.position),t=e.position;r!==0&&!Lo(r)&&!Ro(r);)r=e.input.charCodeAt(++e.position);return e.position===t&&R(e,`name of an alias node must contain at least one character`),n=e.input.slice(t,e.position),xo.call(e.anchorMap,n)||R(e,`unidentified alias "`+n+`"`),e.result=e.anchorMap[n],z(e,!0,-1),!0}function ms(e,t,n,r,i){var a,o,s,c=1,l=!1,u=!1,d,f,p,m,h,g;if(e.listener!==null&&e.listener(`open`,e),e.tag=null,e.anchor=null,e.kind=null,e.result=null,a=o=s=To===n||wo===n,r&&z(e,!0,-1)&&(l=!0,e.lineIndent>t?c=1:e.lineIndent===t?c=0:e.lineIndent<t&&(c=-1)),c===1)for(;ds(e)||fs(e);)z(e,!0,-1)?(l=!0,s=a,e.lineIndent>t?c=1:e.lineIndent===t?c=0:e.lineIndent<t&&(c=-1)):s=!1;if(s&&=l||i,(c===1||To===n)&&(h=So===n||Co===n?t:t+1,g=e.position-e.lineStart,c===1?s&&(ls(e,g)||us(e,g,h))||ss(e,h)?u=!0:(o&&cs(e,h)||as(e,h)||os(e,h)?u=!0:ps(e)?(u=!0,(e.tag!==null||e.anchor!==null)&&R(e,`alias node should not have any properties`)):is(e,h,So===n)&&(u=!0,e.tag===null&&(e.tag=`?`)),e.anchor!==null&&(e.anchorMap[e.anchor]=e.result)):c===0&&(u=s&&ls(e,g))),e.tag===null)e.anchor!==null&&(e.anchorMap[e.anchor]=e.result);else if(e.tag===`?`){for(e.result!==null&&e.kind!==`scalar`&&R(e,`unacceptable node kind for !<?> tag; it should be "scalar", not "`+e.kind+`"`),d=0,f=e.implicitTypes.length;d<f;d+=1)if(m=e.implicitTypes[d],m.resolve(e.result)){e.result=m.construct(e.result),e.tag=m.tag,e.anchor!==null&&(e.anchorMap[e.anchor]=e.result);break}}else if(e.tag!==`!`){if(xo.call(e.typeMap[e.kind||`fallback`],e.tag))m=e.typeMap[e.kind||`fallback`][e.tag];else for(m=null,p=e.typeMap.multi[e.kind||`fallback`],d=0,f=p.length;d<f;d+=1)if(e.tag.slice(0,p[d].tag.length)===p[d].tag){m=p[d];break}m||R(e,`unknown tag !<`+e.tag+`>`),e.result!==null&&m.kind!==e.kind&&R(e,`unacceptable node kind for !<`+e.tag+`> tag; it should be "`+m.kind+`", not "`+e.kind+`"`),m.resolve(e.result,e.tag)?(e.result=m.construct(e.result,e.tag),e.anchor!==null&&(e.anchorMap[e.anchor]=e.result)):R(e,`cannot resolve a node with !<`+e.tag+`> explicit tag`)}return e.listener!==null&&e.listener(`close`,e),e.tag!==null||e.anchor!==null||u}function hs(e){var t=e.position,n,r,i,a=!1,o;for(e.version=null,e.checkLineBreaks=e.legacy,e.tagMap=Object.create(null),e.anchorMap=Object.create(null);(o=e.input.charCodeAt(e.position))!==0&&(z(e,!0,-1),o=e.input.charCodeAt(e.position),!(e.lineIndent>0||o!==37));){for(a=!0,o=e.input.charCodeAt(++e.position),n=e.position;o!==0&&!Lo(o);)o=e.input.charCodeAt(++e.position);for(r=e.input.slice(n,e.position),i=[],r.length<1&&R(e,`directive name must not be less than one character in length`);o!==0;){for(;Io(o);)o=e.input.charCodeAt(++e.position);if(o===35){do o=e.input.charCodeAt(++e.position);while(o!==0&&!Fo(o));break}if(Fo(o))break;for(n=e.position;o!==0&&!Lo(o);)o=e.input.charCodeAt(++e.position);i.push(e.input.slice(n,e.position))}o!==0&&ts(e),xo.call(Zo,r)?Zo[r](e,r,i):Xo(e,`unknown document directive "`+r+`"`)}if(z(e,!0,-1),e.lineIndent===0&&e.input.charCodeAt(e.position)===45&&e.input.charCodeAt(e.position+1)===45&&e.input.charCodeAt(e.position+2)===45?(e.position+=3,z(e,!0,-1)):a&&R(e,`directives end mark is expected`),ms(e,e.lineIndent-1,To,!1,!0),z(e,!0,-1),e.checkLineBreaks&&Ao.test(e.input.slice(t,e.position))&&Xo(e,`non-ASCII line breaks are interpreted as content`),e.documents.push(e.result),e.position===e.lineStart&&ns(e)){e.input.charCodeAt(e.position)===46&&(e.position+=3,z(e,!0,-1));return}if(e.position<e.length-1)R(e,`end of the stream or a document separator is expected`);else return}function gs(e,t){e=String(e),t||={},e.length!==0&&(e.charCodeAt(e.length-1)!==10&&e.charCodeAt(e.length-1)!==13&&(e+=`
24
- `),e.charCodeAt(0)===65279&&(e=e.slice(1)));var n=new Jo(e,t),r=e.indexOf(`\0`);for(r!==-1&&(n.position=r,R(n,`null byte is not allowed in input`)),n.input+=`\0`;n.input.charCodeAt(n.position)===32;)n.lineIndent+=1,n.position+=1;for(;n.position<n.length-1;)hs(n);return n.documents}function _s(e,t,n){typeof t==`object`&&t&&n===void 0&&(n=t,t=null);var r=gs(e,n);if(typeof t!=`function`)return r;for(var i=0,a=r.length;i<a;i+=1)t(r[i])}function vs(e,t){var n=gs(e,t);if(n.length!==0){if(n.length===1)return n[0];throw new la(`expected a single document in the stream, but found more`)}}var ys={loadAll:_s,load:vs},bs=Object.prototype.toString,xs=Object.prototype.hasOwnProperty,Ss=65279,Cs=9,ws=10,Ts=13,Es=32,Ds=33,Os=34,ks=35,As=37,js=38,Ms=39,Ns=42,Ps=44,Fs=45,Is=58,Ls=61,Rs=62,zs=63,Bs=64,Vs=91,Hs=93,Us=96,Ws=123,Gs=124,Ks=125,qs={};qs[0]=`\\0`,qs[7]=`\\a`,qs[8]=`\\b`,qs[9]=`\\t`,qs[10]=`\\n`,qs[11]=`\\v`,qs[12]=`\\f`,qs[13]=`\\r`,qs[27]=`\\e`,qs[34]=`\\"`,qs[92]=`\\\\`,qs[133]=`\\N`,qs[160]=`\\_`,qs[8232]=`\\L`,qs[8233]=`\\P`;var Js=[`y`,`Y`,`yes`,`Yes`,`YES`,`on`,`On`,`ON`,`n`,`N`,`no`,`No`,`NO`,`off`,`Off`,`OFF`],Ys=/^[-+]?[0-9_]+(?::[0-9_]+)+(?:\.[0-9_]*)?$/;function Xs(e,t){var n,r,i,a,o,s,c;if(t===null)return{};for(n={},r=Object.keys(t),i=0,a=r.length;i<a;i+=1)o=r[i],s=String(t[o]),o.slice(0,2)===`!!`&&(o=`tag:yaml.org,2002:`+o.slice(2)),c=e.compiledTypeMap.fallback[o],c&&xs.call(c.styleAliases,s)&&(s=c.styleAliases[s]),n[o]=s;return n}function Zs(e){var t=e.toString(16).toUpperCase(),n,r;if(e<=255)n=`x`,r=2;else if(e<=65535)n=`u`,r=4;else if(e<=4294967295)n=`U`,r=8;else throw new la(`code point within a string may not be greater than 0xFFFFFFFF`);return`\\`+n+L.repeat(`0`,r-t.length)+t}var Qs=1,$s=2;function ec(e){this.schema=e.schema||bo,this.indent=Math.max(1,e.indent||2),this.noArrayIndent=e.noArrayIndent||!1,this.skipInvalid=e.skipInvalid||!1,this.flowLevel=L.isNothing(e.flowLevel)?-1:e.flowLevel,this.styleMap=Xs(this.schema,e.styles||null),this.sortKeys=e.sortKeys||!1,this.lineWidth=e.lineWidth||80,this.noRefs=e.noRefs||!1,this.noCompatMode=e.noCompatMode||!1,this.condenseFlow=e.condenseFlow||!1,this.quotingType=e.quotingType===`"`?$s:Qs,this.forceQuotes=e.forceQuotes||!1,this.replacer=typeof e.replacer==`function`?e.replacer:null,this.implicitTypes=this.schema.compiledImplicit,this.explicitTypes=this.schema.compiledExplicit,this.tag=null,this.result=``,this.duplicates=[],this.usedDuplicates=null}function tc(e,t){for(var n=L.repeat(` `,t),r=0,i=-1,a=``,o,s=e.length;r<s;)i=e.indexOf(`
23
+ `,a?1+c:c),a=!0,o=!0,c=0,n=e.position;!$o(d)&&d!==0;)d=e.input.charCodeAt(++e.position);gs(e,n,e.position,!1)}return!0}function Ds(e,t){var n,r=e.tag,i=e.anchor,a=[],o,s=!1,c;if(e.firstTabInLine!==-1)return!1;for(e.anchor!==null&&(e.anchorMap[e.anchor]=a),c=e.input.charCodeAt(e.position);c!==0&&(e.firstTabInLine!==-1&&(e.position=e.firstTabInLine,R(e,`tab characters must not be used in indentation`)),!(c!==45||(o=e.input.charCodeAt(e.position+1),!ts(o))));){if(s=!0,e.position++,z(e,!0,-1)&&e.lineIndent<=t){a.push(null),c=e.input.charCodeAt(e.position);continue}if(n=e.line,Ms(e,t,Ho,!1,!0),a.push(e.result),z(e,!0,-1),c=e.input.charCodeAt(e.position),(e.line===n||e.lineIndent>t)&&c!==0)R(e,`bad indentation of a sequence entry`);else if(e.lineIndent<t)break}return s?(e.tag=r,e.anchor=i,e.kind=`sequence`,e.result=a,!0):!1}function Os(e,t,n){var r,i,a,o,s,c,l=e.tag,u=e.anchor,d={},f=Object.create(null),p=null,m=null,h=null,g=!1,_=!1,v;if(e.firstTabInLine!==-1)return!1;for(e.anchor!==null&&(e.anchorMap[e.anchor]=d),v=e.input.charCodeAt(e.position);v!==0;){if(!g&&e.firstTabInLine!==-1&&(e.position=e.firstTabInLine,R(e,`tab characters must not be used in indentation`)),r=e.input.charCodeAt(e.position+1),a=e.line,(v===63||v===58)&&ts(r))v===63?(g&&(vs(e,d,f,p,m,null,o,s,c),p=m=h=null),_=!0,g=!0,i=!0):g?(g=!1,i=!0):R(e,`incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line`),e.position+=1,v=r;else{if(o=e.line,s=e.lineStart,c=e.position,!Ms(e,n,Vo,!1,!0))break;if(e.line===a){for(v=e.input.charCodeAt(e.position);es(v);)v=e.input.charCodeAt(++e.position);if(v===58)v=e.input.charCodeAt(++e.position),ts(v)||R(e,`a whitespace character is expected after the key-value separator within a block mapping`),g&&(vs(e,d,f,p,m,null,o,s,c),p=m=h=null),_=!0,g=!1,i=!1,p=e.tag,m=e.result;else if(_)R(e,`can not read an implicit mapping pair; a colon is missed`);else return e.tag=l,e.anchor=u,!0}else if(_)R(e,`can not read a block mapping entry; a multiline key may not be an implicit key`);else return e.tag=l,e.anchor=u,!0}if((e.line===a||e.lineIndent>t)&&(g&&(o=e.line,s=e.lineStart,c=e.position),Ms(e,t,Uo,!0,i)&&(g?m=e.result:h=e.result),g||(vs(e,d,f,p,m,h,o,s,c),p=m=h=null),z(e,!0,-1),v=e.input.charCodeAt(e.position)),(e.line===a||e.lineIndent>t)&&v!==0)R(e,`bad indentation of a mapping entry`);else if(e.lineIndent<t)break}return g&&vs(e,d,f,p,m,null,o,s,c),_&&(e.tag=l,e.anchor=u,e.kind=`mapping`,e.result=d),_}function ks(e){var t,n=!1,r=!1,i,a,o=e.input.charCodeAt(e.position);if(o!==33)return!1;if(e.tag!==null&&R(e,`duplication of a tag property`),o=e.input.charCodeAt(++e.position),o===60?(n=!0,o=e.input.charCodeAt(++e.position)):o===33?(r=!0,i=`!!`,o=e.input.charCodeAt(++e.position)):i=`!`,t=e.position,n){do o=e.input.charCodeAt(++e.position);while(o!==0&&o!==62);e.position<e.length?(a=e.input.slice(t,e.position),o=e.input.charCodeAt(++e.position)):R(e,`unexpected end of the stream within a verbatim tag`)}else{for(;o!==0&&!ts(o);)o===33&&(r?R(e,`tag suffix cannot contain exclamation marks`):(i=e.input.slice(t-1,e.position+1),Xo.test(i)||R(e,`named tag handle cannot contain such characters`),r=!0,t=e.position+1)),o=e.input.charCodeAt(++e.position);a=e.input.slice(t,e.position),Yo.test(a)&&R(e,`tag suffix cannot contain flow indicator characters`)}a&&!Zo.test(a)&&R(e,`tag name cannot contain such characters: `+a);try{a=decodeURIComponent(a)}catch{R(e,`tag name is malformed: `+a)}return n?e.tag=a:zo.call(e.tagMap,i)?e.tag=e.tagMap[i]+a:i===`!`?e.tag=`!`+a:i===`!!`?e.tag=`tag:yaml.org,2002:`+a:R(e,`undeclared tag handle "`+i+`"`),!0}function As(e){var t,n=e.input.charCodeAt(e.position);if(n!==38)return!1;for(e.anchor!==null&&R(e,`duplication of an anchor property`),n=e.input.charCodeAt(++e.position),t=e.position;n!==0&&!ts(n)&&!ns(n);)n=e.input.charCodeAt(++e.position);return e.position===t&&R(e,`name of an anchor node must contain at least one character`),e.anchor=e.input.slice(t,e.position),!0}function js(e){var t,n,r=e.input.charCodeAt(e.position);if(r!==42)return!1;for(r=e.input.charCodeAt(++e.position),t=e.position;r!==0&&!ts(r)&&!ns(r);)r=e.input.charCodeAt(++e.position);return e.position===t&&R(e,`name of an alias node must contain at least one character`),n=e.input.slice(t,e.position),zo.call(e.anchorMap,n)||R(e,`unidentified alias "`+n+`"`),e.result=e.anchorMap[n],z(e,!0,-1),!0}function Ms(e,t,n,r,i){var a,o,s,c=1,l=!1,u=!1,d,f,p,m,h,g;if(e.listener!==null&&e.listener(`open`,e),e.tag=null,e.anchor=null,e.kind=null,e.result=null,a=o=s=Uo===n||Ho===n,r&&z(e,!0,-1)&&(l=!0,e.lineIndent>t?c=1:e.lineIndent===t?c=0:e.lineIndent<t&&(c=-1)),c===1)for(;ks(e)||As(e);)z(e,!0,-1)?(l=!0,s=a,e.lineIndent>t?c=1:e.lineIndent===t?c=0:e.lineIndent<t&&(c=-1)):s=!1;if(s&&=l||i,(c===1||Uo===n)&&(h=Bo===n||Vo===n?t:t+1,g=e.position-e.lineStart,c===1?s&&(Ds(e,g)||Os(e,g,h))||Ts(e,h)?u=!0:(o&&Es(e,h)||Cs(e,h)||ws(e,h)?u=!0:js(e)?(u=!0,(e.tag!==null||e.anchor!==null)&&R(e,`alias node should not have any properties`)):Ss(e,h,Bo===n)&&(u=!0,e.tag===null&&(e.tag=`?`)),e.anchor!==null&&(e.anchorMap[e.anchor]=e.result)):c===0&&(u=s&&Ds(e,g))),e.tag===null)e.anchor!==null&&(e.anchorMap[e.anchor]=e.result);else if(e.tag===`?`){for(e.result!==null&&e.kind!==`scalar`&&R(e,`unacceptable node kind for !<?> tag; it should be "scalar", not "`+e.kind+`"`),d=0,f=e.implicitTypes.length;d<f;d+=1)if(m=e.implicitTypes[d],m.resolve(e.result)){e.result=m.construct(e.result),e.tag=m.tag,e.anchor!==null&&(e.anchorMap[e.anchor]=e.result);break}}else if(e.tag!==`!`){if(zo.call(e.typeMap[e.kind||`fallback`],e.tag))m=e.typeMap[e.kind||`fallback`][e.tag];else for(m=null,p=e.typeMap.multi[e.kind||`fallback`],d=0,f=p.length;d<f;d+=1)if(e.tag.slice(0,p[d].tag.length)===p[d].tag){m=p[d];break}m||R(e,`unknown tag !<`+e.tag+`>`),e.result!==null&&m.kind!==e.kind&&R(e,`unacceptable node kind for !<`+e.tag+`> tag; it should be "`+m.kind+`", not "`+e.kind+`"`),m.resolve(e.result,e.tag)?(e.result=m.construct(e.result,e.tag),e.anchor!==null&&(e.anchorMap[e.anchor]=e.result)):R(e,`cannot resolve a node with !<`+e.tag+`> explicit tag`)}return e.listener!==null&&e.listener(`close`,e),e.tag!==null||e.anchor!==null||u}function Ns(e){var t=e.position,n,r,i,a=!1,o;for(e.version=null,e.checkLineBreaks=e.legacy,e.tagMap=Object.create(null),e.anchorMap=Object.create(null);(o=e.input.charCodeAt(e.position))!==0&&(z(e,!0,-1),o=e.input.charCodeAt(e.position),!(e.lineIndent>0||o!==37));){for(a=!0,o=e.input.charCodeAt(++e.position),n=e.position;o!==0&&!ts(o);)o=e.input.charCodeAt(++e.position);for(r=e.input.slice(n,e.position),i=[],r.length<1&&R(e,`directive name must not be less than one character in length`);o!==0;){for(;es(o);)o=e.input.charCodeAt(++e.position);if(o===35){do o=e.input.charCodeAt(++e.position);while(o!==0&&!$o(o));break}if($o(o))break;for(n=e.position;o!==0&&!ts(o);)o=e.input.charCodeAt(++e.position);i.push(e.input.slice(n,e.position))}o!==0&&ys(e),zo.call(hs,r)?hs[r](e,r,i):ms(e,`unknown document directive "`+r+`"`)}if(z(e,!0,-1),e.lineIndent===0&&e.input.charCodeAt(e.position)===45&&e.input.charCodeAt(e.position+1)===45&&e.input.charCodeAt(e.position+2)===45?(e.position+=3,z(e,!0,-1)):a&&R(e,`directives end mark is expected`),Ms(e,e.lineIndent-1,Uo,!1,!0),z(e,!0,-1),e.checkLineBreaks&&Jo.test(e.input.slice(t,e.position))&&ms(e,`non-ASCII line breaks are interpreted as content`),e.documents.push(e.result),e.position===e.lineStart&&bs(e)){e.input.charCodeAt(e.position)===46&&(e.position+=3,z(e,!0,-1));return}if(e.position<e.length-1)R(e,`end of the stream or a document separator is expected`);else return}function Ps(e,t){e=String(e),t||={},e.length!==0&&(e.charCodeAt(e.length-1)!==10&&e.charCodeAt(e.length-1)!==13&&(e+=`
24
+ `),e.charCodeAt(0)===65279&&(e=e.slice(1)));var n=new fs(e,t),r=e.indexOf(`\0`);for(r!==-1&&(n.position=r,R(n,`null byte is not allowed in input`)),n.input+=`\0`;n.input.charCodeAt(n.position)===32;)n.lineIndent+=1,n.position+=1;for(;n.position<n.length-1;)Ns(n);return n.documents}function Fs(e,t,n){typeof t==`object`&&t&&n===void 0&&(n=t,t=null);var r=Ps(e,n);if(typeof t!=`function`)return r;for(var i=0,a=r.length;i<a;i+=1)t(r[i])}function Is(e,t){var n=Ps(e,t);if(n.length!==0){if(n.length===1)return n[0];throw new Da(`expected a single document in the stream, but found more`)}}var Ls={loadAll:Fs,load:Is},Rs=Object.prototype.toString,zs=Object.prototype.hasOwnProperty,Bs=65279,Vs=9,Hs=10,Us=13,Ws=32,Gs=33,Ks=34,qs=35,Js=37,Ys=38,Xs=39,Zs=42,Qs=44,$s=45,ec=58,tc=61,nc=62,rc=63,ic=64,ac=91,oc=93,sc=96,cc=123,lc=124,uc=125,dc={};dc[0]=`\\0`,dc[7]=`\\a`,dc[8]=`\\b`,dc[9]=`\\t`,dc[10]=`\\n`,dc[11]=`\\v`,dc[12]=`\\f`,dc[13]=`\\r`,dc[27]=`\\e`,dc[34]=`\\"`,dc[92]=`\\\\`,dc[133]=`\\N`,dc[160]=`\\_`,dc[8232]=`\\L`,dc[8233]=`\\P`;var fc=[`y`,`Y`,`yes`,`Yes`,`YES`,`on`,`On`,`ON`,`n`,`N`,`no`,`No`,`NO`,`off`,`Off`,`OFF`],pc=/^[-+]?[0-9_]+(?::[0-9_]+)+(?:\.[0-9_]*)?$/;function mc(e,t){var n,r,i,a,o,s,c;if(t===null)return{};for(n={},r=Object.keys(t),i=0,a=r.length;i<a;i+=1)o=r[i],s=String(t[o]),o.slice(0,2)===`!!`&&(o=`tag:yaml.org,2002:`+o.slice(2)),c=e.compiledTypeMap.fallback[o],c&&zs.call(c.styleAliases,s)&&(s=c.styleAliases[s]),n[o]=s;return n}function hc(e){var t=e.toString(16).toUpperCase(),n,r;if(e<=255)n=`x`,r=2;else if(e<=65535)n=`u`,r=4;else if(e<=4294967295)n=`U`,r=8;else throw new Da(`code point within a string may not be greater than 0xFFFFFFFF`);return`\\`+n+L.repeat(`0`,r-t.length)+t}var gc=1,_c=2;function vc(e){this.schema=e.schema||Ro,this.indent=Math.max(1,e.indent||2),this.noArrayIndent=e.noArrayIndent||!1,this.skipInvalid=e.skipInvalid||!1,this.flowLevel=L.isNothing(e.flowLevel)?-1:e.flowLevel,this.styleMap=mc(this.schema,e.styles||null),this.sortKeys=e.sortKeys||!1,this.lineWidth=e.lineWidth||80,this.noRefs=e.noRefs||!1,this.noCompatMode=e.noCompatMode||!1,this.condenseFlow=e.condenseFlow||!1,this.quotingType=e.quotingType===`"`?_c:gc,this.forceQuotes=e.forceQuotes||!1,this.replacer=typeof e.replacer==`function`?e.replacer:null,this.implicitTypes=this.schema.compiledImplicit,this.explicitTypes=this.schema.compiledExplicit,this.tag=null,this.result=``,this.duplicates=[],this.usedDuplicates=null}function yc(e,t){for(var n=L.repeat(` `,t),r=0,i=-1,a=``,o,s=e.length;r<s;)i=e.indexOf(`
25
25
  `,r),i===-1?(o=e.slice(r),r=s):(o=e.slice(r,i+1),r=i+1),o.length&&o!==`
26
- `&&(a+=n),a+=o;return a}function nc(e,t){return`
27
- `+L.repeat(` `,e.indent*t)}function rc(e,t){var n,r,i;for(n=0,r=e.implicitTypes.length;n<r;n+=1)if(i=e.implicitTypes[n],i.resolve(t))return!0;return!1}function ic(e){return e===Es||e===Cs}function ac(e){return 32<=e&&e<=126||161<=e&&e<=55295&&e!==8232&&e!==8233||57344<=e&&e<=65533&&e!==Ss||65536<=e&&e<=1114111}function oc(e){return ac(e)&&e!==Ss&&e!==Ts&&e!==ws}function sc(e,t,n){var r=oc(e),i=r&&!ic(e);return(n?r:r&&e!==Ps&&e!==Vs&&e!==Hs&&e!==Ws&&e!==Ks)&&e!==ks&&!(t===Is&&!i)||oc(t)&&!ic(t)&&e===ks||t===Is&&i}function cc(e){return ac(e)&&e!==Ss&&!ic(e)&&e!==Fs&&e!==zs&&e!==Is&&e!==Ps&&e!==Vs&&e!==Hs&&e!==Ws&&e!==Ks&&e!==ks&&e!==js&&e!==Ns&&e!==Ds&&e!==Gs&&e!==Ls&&e!==Rs&&e!==Ms&&e!==Os&&e!==As&&e!==Bs&&e!==Us}function lc(e){return!ic(e)&&e!==Is}function uc(e,t){var n=e.charCodeAt(t),r;return n>=55296&&n<=56319&&t+1<e.length&&(r=e.charCodeAt(t+1),r>=56320&&r<=57343)?(n-55296)*1024+r-56320+65536:n}function dc(e){return/^\n* /.test(e)}var fc=1,pc=2,mc=3,hc=4,gc=5;function _c(e,t,n,r,i,a,o,s){var c,l=0,u=null,d=!1,f=!1,p=r!==-1,m=-1,h=cc(uc(e,0))&&lc(uc(e,e.length-1));if(t||o)for(c=0;c<e.length;l>=65536?c+=2:c++){if(l=uc(e,c),!ac(l))return gc;h&&=sc(l,u,s),u=l}else{for(c=0;c<e.length;l>=65536?c+=2:c++){if(l=uc(e,c),l===ws)d=!0,p&&(f||=c-m-1>r&&e[m+1]!==` `,m=c);else if(!ac(l))return gc;h&&=sc(l,u,s),u=l}f||=p&&c-m-1>r&&e[m+1]!==` `}return!d&&!f?h&&!o&&!i(e)?fc:a===$s?gc:pc:n>9&&dc(e)?gc:o?a===$s?gc:pc:f?hc:mc}function vc(e,t,n,r,i){e.dump=function(){if(t.length===0)return e.quotingType===$s?`""`:`''`;if(!e.noCompatMode&&(Js.indexOf(t)!==-1||Ys.test(t)))return e.quotingType===$s?`"`+t+`"`:`'`+t+`'`;var a=e.indent*Math.max(1,n),o=e.lineWidth===-1?-1:Math.max(Math.min(e.lineWidth,40),e.lineWidth-a),s=r||e.flowLevel>-1&&n>=e.flowLevel;function c(t){return rc(e,t)}switch(_c(t,s,e.indent,o,c,e.quotingType,e.forceQuotes&&!r,i)){case fc:return t;case pc:return`'`+t.replace(/'/g,`''`)+`'`;case mc:return`|`+yc(t,e.indent)+bc(tc(t,a));case hc:return`>`+yc(t,e.indent)+bc(tc(xc(t,o),a));case gc:return`"`+Cc(t)+`"`;default:throw new la(`impossible error: invalid scalar style`)}}()}function yc(e,t){var n=dc(e)?String(t):``,r=e[e.length-1]===`
26
+ `&&(a+=n),a+=o;return a}function bc(e,t){return`
27
+ `+L.repeat(` `,e.indent*t)}function xc(e,t){var n,r,i;for(n=0,r=e.implicitTypes.length;n<r;n+=1)if(i=e.implicitTypes[n],i.resolve(t))return!0;return!1}function Sc(e){return e===Ws||e===Vs}function Cc(e){return 32<=e&&e<=126||161<=e&&e<=55295&&e!==8232&&e!==8233||57344<=e&&e<=65533&&e!==Bs||65536<=e&&e<=1114111}function wc(e){return Cc(e)&&e!==Bs&&e!==Us&&e!==Hs}function Tc(e,t,n){var r=wc(e),i=r&&!Sc(e);return(n?r:r&&e!==Qs&&e!==ac&&e!==oc&&e!==cc&&e!==uc)&&e!==qs&&!(t===ec&&!i)||wc(t)&&!Sc(t)&&e===qs||t===ec&&i}function Ec(e){return Cc(e)&&e!==Bs&&!Sc(e)&&e!==$s&&e!==rc&&e!==ec&&e!==Qs&&e!==ac&&e!==oc&&e!==cc&&e!==uc&&e!==qs&&e!==Ys&&e!==Zs&&e!==Gs&&e!==lc&&e!==tc&&e!==nc&&e!==Xs&&e!==Ks&&e!==Js&&e!==ic&&e!==sc}function Dc(e){return!Sc(e)&&e!==ec}function Oc(e,t){var n=e.charCodeAt(t),r;return n>=55296&&n<=56319&&t+1<e.length&&(r=e.charCodeAt(t+1),r>=56320&&r<=57343)?(n-55296)*1024+r-56320+65536:n}function kc(e){return/^\n* /.test(e)}var Ac=1,jc=2,Mc=3,Nc=4,Pc=5;function Fc(e,t,n,r,i,a,o,s){var c,l=0,u=null,d=!1,f=!1,p=r!==-1,m=-1,h=Ec(Oc(e,0))&&Dc(Oc(e,e.length-1));if(t||o)for(c=0;c<e.length;l>=65536?c+=2:c++){if(l=Oc(e,c),!Cc(l))return Pc;h&&=Tc(l,u,s),u=l}else{for(c=0;c<e.length;l>=65536?c+=2:c++){if(l=Oc(e,c),l===Hs)d=!0,p&&(f||=c-m-1>r&&e[m+1]!==` `,m=c);else if(!Cc(l))return Pc;h&&=Tc(l,u,s),u=l}f||=p&&c-m-1>r&&e[m+1]!==` `}return!d&&!f?h&&!o&&!i(e)?Ac:a===_c?Pc:jc:n>9&&kc(e)?Pc:o?a===_c?Pc:jc:f?Nc:Mc}function Ic(e,t,n,r,i){e.dump=function(){if(t.length===0)return e.quotingType===_c?`""`:`''`;if(!e.noCompatMode&&(fc.indexOf(t)!==-1||pc.test(t)))return e.quotingType===_c?`"`+t+`"`:`'`+t+`'`;var a=e.indent*Math.max(1,n),o=e.lineWidth===-1?-1:Math.max(Math.min(e.lineWidth,40),e.lineWidth-a),s=r||e.flowLevel>-1&&n>=e.flowLevel;function c(t){return xc(e,t)}switch(Fc(t,s,e.indent,o,c,e.quotingType,e.forceQuotes&&!r,i)){case Ac:return t;case jc:return`'`+t.replace(/'/g,`''`)+`'`;case Mc:return`|`+Lc(t,e.indent)+Rc(yc(t,a));case Nc:return`>`+Lc(t,e.indent)+Rc(yc(zc(t,o),a));case Pc:return`"`+Vc(t)+`"`;default:throw new Da(`impossible error: invalid scalar style`)}}()}function Lc(e,t){var n=kc(e)?String(t):``,r=e[e.length-1]===`
28
28
  `;return n+(r&&(e[e.length-2]===`
29
29
  `||e===`
30
30
  `)?`+`:r?``:`-`)+`
31
- `}function bc(e){return e[e.length-1]===`
32
- `?e.slice(0,-1):e}function xc(e,t){for(var n=/(\n+)([^\n]*)/g,r=function(){var r=e.indexOf(`
33
- `);return r=r===-1?e.length:r,n.lastIndex=r,Sc(e.slice(0,r),t)}(),i=e[0]===`
31
+ `}function Rc(e){return e[e.length-1]===`
32
+ `?e.slice(0,-1):e}function zc(e,t){for(var n=/(\n+)([^\n]*)/g,r=function(){var r=e.indexOf(`
33
+ `);return r=r===-1?e.length:r,n.lastIndex=r,Bc(e.slice(0,r),t)}(),i=e[0]===`
34
34
  `||e[0]===` `,a,o;o=n.exec(e);){var s=o[1],c=o[2];a=c[0]===` `,r+=s+(!i&&!a&&c!==``?`
35
- `:``)+Sc(c,t),i=a}return r}function Sc(e,t){if(e===``||e[0]===` `)return e;for(var n=/ [^ ]/g,r,i=0,a,o=0,s=0,c=``;r=n.exec(e);)s=r.index,s-i>t&&(a=o>i?o:s,c+=`
35
+ `:``)+Bc(c,t),i=a}return r}function Bc(e,t){if(e===``||e[0]===` `)return e;for(var n=/ [^ ]/g,r,i=0,a,o=0,s=0,c=``;r=n.exec(e);)s=r.index,s-i>t&&(a=o>i?o:s,c+=`
36
36
  `+e.slice(i,a),i=a+1),o=s;return c+=`
37
37
  `,e.length-i>t&&o>i?c+=e.slice(i,o)+`
38
- `+e.slice(o+1):c+=e.slice(i),c.slice(1)}function Cc(e){for(var t=``,n=0,r,i=0;i<e.length;n>=65536?i+=2:i++)n=uc(e,i),r=qs[n],!r&&ac(n)?(t+=e[i],n>=65536&&(t+=e[i+1])):t+=r||Zs(n);return t}function wc(e,t,n){var r=``,i=e.tag,a,o,s;for(a=0,o=n.length;a<o;a+=1)s=n[a],e.replacer&&(s=e.replacer.call(n,String(a),s)),(kc(e,t,s,!1,!1)||s===void 0&&kc(e,t,null,!1,!1))&&(r!==``&&(r+=`,`+(e.condenseFlow?``:` `)),r+=e.dump);e.tag=i,e.dump=`[`+r+`]`}function Tc(e,t,n,r){var i=``,a=e.tag,o,s,c;for(o=0,s=n.length;o<s;o+=1)c=n[o],e.replacer&&(c=e.replacer.call(n,String(o),c)),(kc(e,t+1,c,!0,!0,!1,!0)||c===void 0&&kc(e,t+1,null,!0,!0,!1,!0))&&((!r||i!==``)&&(i+=nc(e,t)),e.dump&&ws===e.dump.charCodeAt(0)?i+=`-`:i+=`- `,i+=e.dump);e.tag=a,e.dump=i||`[]`}function Ec(e,t,n){var r=``,i=e.tag,a=Object.keys(n),o,s,c,l,u;for(o=0,s=a.length;o<s;o+=1)u=``,r!==``&&(u+=`, `),e.condenseFlow&&(u+=`"`),c=a[o],l=n[c],e.replacer&&(l=e.replacer.call(n,c,l)),kc(e,t,c,!1,!1)&&(e.dump.length>1024&&(u+=`? `),u+=e.dump+(e.condenseFlow?`"`:``)+`:`+(e.condenseFlow?``:` `),kc(e,t,l,!1,!1)&&(u+=e.dump,r+=u));e.tag=i,e.dump=`{`+r+`}`}function Dc(e,t,n,r){var i=``,a=e.tag,o=Object.keys(n),s,c,l,u,d,f;if(e.sortKeys===!0)o.sort();else if(typeof e.sortKeys==`function`)o.sort(e.sortKeys);else if(e.sortKeys)throw new la(`sortKeys must be a boolean or a function`);for(s=0,c=o.length;s<c;s+=1)f=``,(!r||i!==``)&&(f+=nc(e,t)),l=o[s],u=n[l],e.replacer&&(u=e.replacer.call(n,l,u)),kc(e,t+1,l,!0,!0,!0)&&(d=e.tag!==null&&e.tag!==`?`||e.dump&&e.dump.length>1024,d&&(e.dump&&ws===e.dump.charCodeAt(0)?f+=`?`:f+=`? `),f+=e.dump,d&&(f+=nc(e,t)),kc(e,t+1,u,!0,d)&&(e.dump&&ws===e.dump.charCodeAt(0)?f+=`:`:f+=`: `,f+=e.dump,i+=f));e.tag=a,e.dump=i||`{}`}function Oc(e,t,n){var r,i=n?e.explicitTypes:e.implicitTypes,a,o,s,c;for(a=0,o=i.length;a<o;a+=1)if(s=i[a],(s.instanceOf||s.predicate)&&(!s.instanceOf||typeof t==`object`&&t instanceof s.instanceOf)&&(!s.predicate||s.predicate(t))){if(n?s.multi&&s.representName?e.tag=s.representName(t):e.tag=s.tag:e.tag=`?`,s.represent){if(c=e.styleMap[s.tag]||s.defaultStyle,bs.call(s.represent)===`[object Function]`)r=s.represent(t,c);else if(xs.call(s.represent,c))r=s.represent[c](t,c);else throw new la(`!<`+s.tag+`> tag resolver accepts not "`+c+`" style`);e.dump=r}return!0}return!1}function kc(e,t,n,r,i,a,o){e.tag=null,e.dump=n,Oc(e,n,!1)||Oc(e,n,!0);var s=bs.call(e.dump),c=r,l;r&&=e.flowLevel<0||e.flowLevel>t;var u=s===`[object Object]`||s===`[object Array]`,d,f;if(u&&(d=e.duplicates.indexOf(n),f=d!==-1),(e.tag!==null&&e.tag!==`?`||f||e.indent!==2&&t>0)&&(i=!1),f&&e.usedDuplicates[d])e.dump=`*ref_`+d;else{if(u&&f&&!e.usedDuplicates[d]&&(e.usedDuplicates[d]=!0),s===`[object Object]`)r&&Object.keys(e.dump).length!==0?(Dc(e,t,e.dump,i),f&&(e.dump=`&ref_`+d+e.dump)):(Ec(e,t,e.dump),f&&(e.dump=`&ref_`+d+` `+e.dump));else if(s===`[object Array]`)r&&e.dump.length!==0?(e.noArrayIndent&&!o&&t>0?Tc(e,t-1,e.dump,i):Tc(e,t,e.dump,i),f&&(e.dump=`&ref_`+d+e.dump)):(wc(e,t,e.dump),f&&(e.dump=`&ref_`+d+` `+e.dump));else if(s===`[object String]`)e.tag!==`?`&&vc(e,e.dump,t,a,c);else if(s===`[object Undefined]`)return!1;else{if(e.skipInvalid)return!1;throw new la(`unacceptable kind of an object to dump `+s)}e.tag!==null&&e.tag!==`?`&&(l=encodeURI(e.tag[0]===`!`?e.tag.slice(1):e.tag).replace(/!/g,`%21`),l=e.tag[0]===`!`?`!`+l:l.slice(0,18)===`tag:yaml.org,2002:`?`!!`+l.slice(18):`!<`+l+`>`,e.dump=l+` `+e.dump)}return!0}function Ac(e,t){var n=[],r=[],i,a;for(jc(e,n,r),i=0,a=r.length;i<a;i+=1)t.duplicates.push(n[r[i]]);t.usedDuplicates=Array(a)}function jc(e,t,n){var r,i,a;if(typeof e==`object`&&e)if(i=t.indexOf(e),i!==-1)n.indexOf(i)===-1&&n.push(i);else if(t.push(e),Array.isArray(e))for(i=0,a=e.length;i<a;i+=1)jc(e[i],t,n);else for(r=Object.keys(e),i=0,a=r.length;i<a;i+=1)jc(e[r[i]],t,n)}function Mc(e,t){t||={};var n=new ec(t);n.noRefs||Ac(e,n);var r=e;return n.replacer&&(r=n.replacer.call({"":r},``,r)),kc(n,0,r,!0,!0)?n.dump+`
39
- `:``}var Nc={dump:Mc},Pc=ys.load;ys.loadAll,Nc.dump;const Fc=/^(tag|tag ?name|channel|name|signal|point|item|variable)$/i,Ic=/^(value|val|pv|reading|measurement)$/i;function Lc(e){let t=t=>e.flatMap((e,n)=>e.kind===t?[n]:[]),n=t(`time`),r=t(`text`),i=t(`number`);if(n.length!==1||i.length!==1||r.length<1||r.length>2)return null;let a=t=>Fc.test(e[t].name.trim()),o=r.length===2&&a(r[1])&&!a(r[0])?r[1]:r[0];return!a(o)&&!Ic.test(e[i[0]].name.trim())?null:{time:n[0],tag:o,value:i[0],unit:r.find(e=>e!==o)??null}}async function Rc(e,t,n){let r=new Map,i=[],a=[],o=0,s=0,c=!0,l=-1/0,u=1/0,d=0,f=[];for await(let p of e.read(t.unit===null?[t.time,t.tag]:[t.time,t.tag,t.unit],n)){let e=p.columns[0],t=p.columns[1],n=p.columns[2];for(let m=0;m<p.length;m++){let p=t[m],h=e[m];if(!p||Number.isNaN(h))continue;o++,h<l&&(c=!1),h!==l&&s++,l=h,h<u&&(u=h);let g=n?.[m]??``,_=r.get(p);if(_===void 0)r.set(p,i.length),f.push(h),i.push(p),a.push(g);else{if(n&&a[_]!==g)return null;f[_]===h&&d++,f[_]=h}}}return i.length===0||i.length*2>o?null:{tags:i,units:a,rows:o,times:c?s:o,sorted:c,start:u,repeated:c?d:0}}async function*zc(e,t,n,r,i,a,o){let s=new Map;r.forEach((e,t)=>s.set(n.tags[e],t));let c=Math.max(1,Math.min(4096,Math.floor(4e6/Math.max(1,r.length)))),l=new Float64Array(r.length).fill(NaN),u=()=>r.map(()=>new Float64Array(c).fill(NaN)),d=new Float64Array(c),f=u(),p=0,m=0,h=()=>{let e=p===c,t={group:i,time:e?d:d.slice(0,p),start:m,length:p,columns:e?f:f.map(e=>e.slice(0,p))};return m+=p,p=0,d=new Float64Array(c),f=u(),t},g=(e,t,n)=>{if(l[t]===e||Number.isNaN(n))return!0;let r=e-a;return p>0&&d[p-1]===r?(f[t][p-1]=n,l[t]=e,!0):p===c?!1:(l[t]=e,d[p]=r,f[t][p++]=n,!0)},_=e.read([t.time,t.tag,t.value],o);if(n.sorted)for await(let e of _){let t=e.columns[0],n=e.columns[1],r=e.columns[2];for(let i=0;i<e.length;i++){let e=n[i]?s.get(n[i]):void 0;e!==void 0&&!Number.isNaN(t[i])&&!g(t[i],e,r[i])&&(yield h(),g(t[i],e,r[i]))}}else{let e=new Float64Array(4096),t=new Int32Array(4096),n=new Float64Array(4096),r=0;for await(let i of _){let a=i.columns[0],o=i.columns[1],c=i.columns[2];for(let l=0;l<i.length;l++){let i=o[l]?s.get(o[l]):void 0;if(!(i===void 0||Number.isNaN(a[l]))){if(r===e.length){let r=e=>{let t=new e.constructor(e.length*2);return t.set(e),t};e=r(e),t=r(t),n=r(n)}e[r]=a[l],t[r]=i,n[r++]=c[l]}}}let i=Uint32Array.from({length:r},(e,t)=>t).sort((t,n)=>e[t]-e[n]||t-n);for(let r of i)g(e[r],t[r],n[r])||(yield h(),g(e[r],t[r],n[r]))}p>0&&(yield h())}const Bc=/^(t|time|timestamp|elapsed ?time|[\w ]*_time)\s*(\[[^\]]*\]|\([^)]*\))?$/i,Vc=/^\d{4}[-/]\d{2}[-/]\d{2}[T ]\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:?\d{2})?$/;function Hc(e){let t=e.trim();return Vc.test(t)?Date.parse(t.slice(0,10).replace(/\//g,`-`)+`T`+t.slice(11))/1e3:NaN}function Uc(e){let t=Math.floor(e*1e3),n=new Date(t),r=new Date(n.getUTCFullYear(),n.getUTCMonth(),n.getUTCDate(),n.getUTCHours(),n.getUTCMinutes(),n.getUTCSeconds(),n.getUTCMilliseconds());return n.getUTCFullYear()<100&&r.setFullYear(n.getUTCFullYear()),r.getTime()/1e3+(e-t/1e3)}const Wc=e=>Math.round(Uc(e)-e);async function Gc(e,t,n){for await(let r of e.read([t],n)){let e=r.columns[0];for(let t=0;t<r.length;t++)if(!Number.isNaN(e[t]))return e[t]}return NaN}function Kc(e,t){if(!e.includes(`"`))return e.split(t);let n=[],r=``,i=!1;for(let a=0;a<e.length;a++){let o=e[a];i?o===`"`?e[a+1]===`"`?(r+=`"`,a++):i=!1:r+=o:o===`"`?i=!0:o===t?(n.push(r),r=``):r+=o}return n.push(r),n}function qc(e){for(let t of[` `,`;`,`,`]){let n=Kc(e[0],t).length;if(n>=3&&e.every(e=>Kc(e,t).length===n))return t}return null}function Jc(e,t){let n=e.trim();return n===``?NaN:Number(t?n.replace(`,`,`.`):n)}function Yc(e,t,n){return e.map((e,r)=>{let i=e.trim(),a=0,o=0,s=0;for(let e of t){let t=(e[r]??``).trim();t&&(Number.isNaN(Jc(t,n))?Number.isNaN(Hc(t))?s++:o++:a++)}let c=o>0&&o>=a+s?`time`:a>0&&a>=s?Bc.test(i)?`time`:`number`:`text`;return{name:i,unit:c===`time`&&o===0?`s`:``,kind:c,absolute:c===`time`&&o>0}})}function Xc(e){let t=e.split(/\r?\n/).slice(0,-1).filter(e=>e.trim()).slice(0,50);if(t.length<3)return!1;let n=qc(t);return n?Lc(Yc(Kc(t[0],n),t.slice(1).map(e=>Kc(e,n)),n===`;`))!==null:!1}var B=class extends Error{};const Zc=()=>new B(`it names more than ${1e6.toLocaleString(`en-US`)} parameter occurrences`),Qc={u8:[1,`u`],i8:[1,`i`],u16:[2,`u`],i16:[2,`i`],u24:[3,`u`],u32:[4,`u`],i32:[4,`i`],u48:[6,`u`],u64:[8,`u`],i64:[8,`i`],f16:[2,`f`],f32:[4,`f`],f64:[8,`f`],bool:[1,`b`]},$c={little:!0,"<":!0,big:!1,">":!1},el=[`name`,`type`,`offset`,`count`,`endian`,`scale`,`add`,`unit`,`bit`,`bits`,`sample_rate_hz`],tl=e=>e==null||e===``;function nl(e,t,n){let r=String(e).trim();if(/^[+-]?(0x[0-9a-f]+|0o[0-7]+|0b[01]+|[1-9]\d*|0)$/i.test(r.replace(/_/g,``))){let e=r.startsWith(`-`),t=Number(r.replace(/^[+-]/,``).replace(/_/g,``));if(Number.isSafeInteger(t))return e?-t:t}throw new B(`${n}: '${t}' must be a number`)}function rl(e,t,n){let r=typeof e==`number`?e:Number(String(e).trim());if(tl(e)||Number.isNaN(r)&&!/^[+-]?nan$/i.test(String(e).trim()))throw new B(`${n}: '${t}' must be a number`);return r}function il(e){let t=e>>10&31,n=e&1023,r=e&32768?-1:1;return t===31?n?NaN:r*(1/0):t?r*2**(t-15)*(1+n/1024):r*2**-14*(n/1024)}function al(e,t){switch(e){case`u8`:case`bool`:return(e,t)=>e.getUint8(t);case`i8`:return(e,t)=>e.getInt8(t);case`u16`:return(e,n)=>e.getUint16(n,t);case`i16`:return(e,n)=>e.getInt16(n,t);case`u24`:return(e,n)=>t?e.getUint16(n,!0)+e.getUint8(n+2)*65536:e.getUint16(n)*256+e.getUint8(n+2);case`u48`:return(e,n)=>t?e.getUint32(n,!0)+e.getUint16(n+4,!0)*4294967296:e.getUint16(n)*4294967296+e.getUint32(n+2);case`u32`:return(e,n)=>e.getUint32(n,t);case`i32`:return(e,n)=>e.getInt32(n,t);case`u64`:return(e,n)=>e.getUint32(n+(t?4:0),t)*4294967296+e.getUint32(n+(t?0:4),t);case`i64`:return(e,n)=>e.getInt32(n+(t?4:0),t)*4294967296+e.getUint32(n+(t?0:4),t);case`f16`:return(e,n)=>il(e.getUint16(n,t));case`f32`:return(e,n)=>e.getFloat32(n,t);default:return(e,n)=>e.getFloat64(n,t)}}function ol(e,t,n,r,i){let a=String(e.name??``).trim();if(!a)throw new B(`${i}: every field needs a 'name'`);i=`${i}, field '${a}'`;let o=String(e.type??``);if(!(o in Qc))throw new B(`${i}: 'type' must be one of ${Object.keys(Qc).join(`, `)}`);let[s,c]=Qc[o],l=$c[String(tl(e.endian)?n:e.endian)];if(l===void 0)throw new B(`${i}: 'endian' must be little or big`);let u=tl(e.count)?1:nl(e.count,`count`,i);if(u<1||u>4096)throw new B(`${i}: 'count' must be 1-4096`);let d=tl(e.offset)?t:nl(e.offset,`offset`,i);if(d<0||d>1<<24)throw new B(`${i}: 'offset' must be 0 or more`);let f=tl(e.bit)?null:nl(e.bit,`bit`,i),p=tl(e.bits)?1:nl(e.bits,`bits`,i);if(!tl(e.bits)&&f===null)throw new B(`${i}: 'bits' needs 'bit', the lowest of them`);if(f!==null&&(c!==`u`&&c!==`i`||u!==1||f<0||p<1||f+p>8*s))throw new B(`${i}: 'bit' (and 'bits') need one integer (u8..u64) and bits inside it`);let m=tl(e.scale)?1:rl(e.scale,`scale`,i),h=tl(e.add)?0:rl(e.add,`add`,i),g=tl(e.sample_rate_hz)?null:rl(e.sample_rate_hz,`sample_rate_hz`,i);if(g!==null&&(!(g>0)||o===`bool`||o===`u24`||o===`u48`||f!==null))throw new B(`${i}: 'sample_rate_hz' must be above 0, on a number field (not bool, bit, u24 or u48)`);let _=String(e.unit??``),v=al(o,l),y=f===null?v:(e,t)=>Math.floor(v(e,t)/2**f)%2**p,b=o===`bool`||f!==null&&p===1,x=(e,t)=>{let n=y(e,t);return b?n=+!!n:(g!==null||m!==1||h!==0)&&(n=n*m+h),Number.isFinite(n)?n:NaN},S=(e,t,n)=>x(t,n>>>3),C=u===1||g!==null?[r+a]:Array.from({length:u},(e,t)=>`${r}${a}[${t}]`),w=e=>(d+e*s)*8,T=g===null?C.map((e,t)=>({name:e,unit:_,at:[w(t)],bits:s*8,read:S})):[{name:C[0],unit:_,at:Array.from({length:u},(e,t)=>w(t)),bits:s*8,dt:1/g,read:S}];return{name:a,off:d,size:s,count:u,int:(c===`u`||c===`i`)&&!b,raw:y,tags:C,field:T}}function sl(e,t,n,r,i={n:0}){if(!Array.isArray(e.fields)||!e.fields.length)throw new B(`${r}: needs a non-empty 'fields' list`);t=String(e.endian||t);let a=String(e.prefix??``),o=[],s=new Set,c=n;for(let n of e.fields){if(!n||typeof n!=`object`||Array.isArray(n))throw new B(`${r}: each field must be a mapping with name and type`);let e=ol(n,c,t,a,r);if((i.n+=e.count)>1e6)throw Zc();c=e.off+e.size*e.count;for(let t of e.tags){if(s.has(t))throw new B(`${r}: field name '${t}' is repeated`);s.add(t)}o.push(e)}let l=new Map(o.map(e=>[e.name,e])),u=new Set;if(e.seq){let t=l.get(String(e.seq));if(!t||t.count!==1)throw new B(`${r}: 'seq' must name a field holding one integer`);u.add(t.name)}if(e.timestamp){let t=e.timestamp,n=typeof t==`object`?l.get(String(t.field)):void 0;if(!n||n.count!==1)throw new B(`${r}: 'timestamp.field' must name a field holding one number`);u.add(n.name)}return{name:null,kind:`P`,rate:null,end:null,fields:o.filter(e=>!u.has(e.name)).flatMap(e=>e.field),minBytes:Math.max(...o.map(e=>e.off+e.size*e.count))}}function cl(e,t){let n=String(e.endian||`little`);if(!(n in $c))throw new B(`${t}: 'endian' must be little or big`);let r={source:`layout`,keys:new Map,any:null,notes:[]};if(!e.packet_id){if(`packets`in e)throw new B(`${t}: 'packets' needs a 'packet_id' to tell them apart`);return r.any=sl(e,n,0,t),r}if(typeof e.packet_id!=`object`)throw new B(`${t}: 'packet_id' must be one integer field`);let i=ol({name:`packet_id`,...e.packet_id},0,n,``,`${t} packet_id`);if(i.count!==1||!i.int)throw new B(`${t}: 'packet_id' must be one integer field`);r.pid={off:i.off,size:i.size,read:i.raw};let a=e.packets;if(!a||typeof a!=`object`||Array.isArray(a)||!Object.keys(a).length)throw new B(`${t}: 'packet_id' needs a 'packets' mapping of id to packet`);let o={n:0};for(let[e,s]of Object.entries(a)){let a=nl(e,`packets`,t);r.keys.set(a,sl(s??{},n,i.off+i.size,`${t} packet ${e}`,o))}return r}function ll(e,t){let n=e.replace(/^\uFEFF/,``).split(/\r?\n/),r=Kc(n[0]??``,`,`).map(e=>e.trim());if(!r.includes(`name`)||!r.includes(`type`))throw new B(`${t}: a layout CSV needs the columns packet, name, type, offset…`);let i={},a=new Map;for(let e of n.slice(1)){if(!e.trim())continue;let t=Kc(e,`,`),n={};if(r.forEach((e,r)=>{e&&(n[e]=(t[r]??``).trim())}),!n.name)continue;let o={};for(let e of el)n[e]&&(o[e]=n[e]);let s=n.role??``,c=n.packet||null;if(s===`id`){i.packet_id=Object.fromEntries(Object.entries(o).filter(([e])=>e!==`name`));continue}let l=a.get(c);l||a.set(c,l={fields:[]}),s===`time`||s===`time_relative`?(l.timestamp={field:o.name,unit:o.unit??`s`,mode:s===`time`?`epoch`:`relative`},delete o.unit):s===`seq`&&(l.seq=o.name),l.fields.push(o)}return a.size===1&&a.has(null)&&!(`packet_id`in i)?a.get(null):(i.packets=Object.fromEntries([...a].map(([e,t])=>[String(e),t])),i)}function ul(e,t){let n=`the layout ${t}`,r;if(/\.csv$/i.test(t))r=ll(e,n);else try{r=Pc(e)}catch(e){throw new B(`${n}: not YAML (${e.message.split(`
40
- `)[0]})`)}if(!r||typeof r!=`object`||Array.isArray(r))throw new B(`${n} must be a mapping`);return cl(r,n)}const dl=/<(?:[\w.-]+:)?t(?:\s[^>]*)?>([\s\S]*?)<\/(?:[\w.-]+:)?t>/g,fl={amp:`&`,lt:`<`,gt:`>`,quot:`"`,apos:`'`},pl=e=>e.includes(`&`)?e.replace(/&(#x[0-9a-fA-F]+|#\d+|amp|lt|gt|quot|apos);/g,(e,t)=>t[0]===`#`?String.fromCodePoint(t[1]===`x`?parseInt(t.slice(2),16):parseInt(t.slice(1),10)):fl[t]):e;function ml(e,t){let n=` ${t}="`,r=(` `+e).indexOf(n);if(r<0)return;let i=r-1+n.length;return pl(e.slice(i,e.indexOf(`"`,i)))}function hl(e,t){let n=new Map;for(let e of t.matchAll(/<(?:[\w.-]+:)?Relationship\b([^>]*)>/g)){let t=ml(e[1],`Id`),r=ml(e[1],`Target`);t&&r&&n.set(t,r.startsWith(`/`)?r.slice(1):`xl/${r.replace(/^\.\//,``)}`)}let r=[...e.matchAll(/<(?:[\w.-]+:)?sheet\b([^>]*)>/g)].flatMap(e=>{let t=ml(e[1],`name`),r=n.get(ml(e[1],`r:id`)??``);return t&&r?[{name:t,path:r}]:[]}),i=ml(/<(?:[\w.-]+:)?workbookPr\b([^>]*)>/.exec(e)?.[1]??``,`date1904`);return{sheets:r,date1904:i===`1`||i===`true`}}const gl=new Set([14,15,16,17,18,19,20,21,22,45,46,47]);function _l(e,t){if(t===void 0)return gl.has(e);let n=t.replace(/"[^"]*"/g,``).replace(/\\./g,``).replace(/\[(?![hms]+\])[^\]]*\]/gi,``);return/[dmyhs]/i.test(n)&&!/general/i.test(n)}function vl(e){let t=new Map;for(let n of e.matchAll(/<(?:[\w.-]+:)?numFmt\b([^>]*)>/g)){let e=ml(n[1],`formatCode`);e!==void 0&&t.set(Number(ml(n[1],`numFmtId`)),e)}return[...(/<(?:[\w.-]+:)?cellXfs\b[^>]*>([\s\S]*?)<\/(?:[\w.-]+:)?cellXfs>/.exec(e)?.[1]??``).matchAll(/<(?:[\w.-]+:)?xf\b([^>]*)>/g)].map(e=>{let n=Number(ml(e[1],`numFmtId`)??0);return _l(n,t.get(n))})}function yl(e,t=T){let n=[];for(let r of e.matchAll(/<(?:[\w.-]+:)?si>([\s\S]*?)<\/(?:[\w.-]+:)?si>|<(?:[\w.-]+:)?si\/>/g)){let e=(r[1]??``).replace(/<(?:[\w.-]+:)?rPh\b[\s\S]*?<\/(?:[\w.-]+:)?rPh>/g,``),i=``;for(let t of e.matchAll(dl))i+=t[1];if(n.length>=t)throw Error(`This workbook is too large to open (over ${t.toLocaleString(`en-US`)} shared strings).`);n.push(pl(i))}return n}const bl=Array.from({length:23},(e,t)=>10**t);let xl=-1;function Sl(e,t){let n=e.length,r=t,i=e.charCodeAt(r)===45;i&&r++;let a=0,o=0,s=0,c=-1,l=!0;for(;r<n;r++){let t=e.charCodeAt(r);if(t===60)break;if(t===46&&c<0){c=0;continue}let n=t-48;if(n<0||n>9){l=!1;break}a=a*10+n,o++,a&&s++,c>=0&&c++}if(l&&r<n&&o>0&&s<=15&&c<=22){xl=r;let e=c>0?a/bl[c]:a;return i?-e:e}return xl=e.indexOf(`<`,r),xl<0?NaN:Number(e.slice(t,xl))}const Cl=e=>e===32||e===9||e===10||e===13,wl=(e,t,n,r)=>e.charCodeAt(t)===60&&e.charCodeAt(t+1)===47&&e.charCodeAt(t+2+r.length)===n&&e.charCodeAt(t+3+r.length)===62&&(!r||e.startsWith(r,t+2));async function Tl(e,t,n,r){let i=-1,a=-1,o=0,s=``,c=(e,c)=>{let l=e.length,u=t=>c?``:e.slice(t),d=0;for(;;){let c=e.indexOf(`<`,d);if(c<0)return``;let f=c+1,p=-1,m=e.charCodeAt(f);for(;f<l&&!Cl(m)&&m!==62&&m!==47;)m===58&&(p=f),m=e.charCodeAt(++f);if(f>=l)return u(c);let h=p<0?c+1:p+1,g=f-h,_=g===1&&e.charCodeAt(h)===99;if(!_&&!(g===3&&e.startsWith(`row`,h))){let t=e.indexOf(`>`,f);if(t<0)return u(c);d=t+1;continue}(h-c-1!==s.length||!e.startsWith(s,c+1))&&(s=e.slice(c+1,h));let v=-1,y=0,b=0,x=f;for(;;){for(;x<l&&Cl(e.charCodeAt(x));)x++;if(x>=l)return u(c);if(m=e.charCodeAt(x),m===62||m===47)break;let t=x;for(;x<l&&(m=e.charCodeAt(x))!==61&&!Cl(m)&&m!==62;)x++;let n=x-t;for(;x<l&&Cl(e.charCodeAt(x));)x++;if(x>=l)return u(c);if(e.charCodeAt(x)!==61)continue;for(x++;x<l&&Cl(e.charCodeAt(x));)x++;let r=e.charCodeAt(x);if(r!==34&&r!==39)continue;let i=x+1,a=e.indexOf(r===34?`"`:`'`,i);if(a<0)return u(c);if(x=a+1,n!==1)continue;let o=e.charCodeAt(t);if(o===114){let t=0,n=i;if(_){for(;n<a;n++){let r=e.charCodeAt(n);if(r<65||r>90)break;t=t*26+r-64}v=t-1}else{for(;n<a;n++){let r=e.charCodeAt(n)-48;if(r<0||r>9)break;t=t*10+r}v=n>i?t-1:-1}}else if(o===116){let t=a-i,n=e.charCodeAt(i);y=t===1?n===115?1:n===98?3:n===101?4:n===110?0:-1:t===3&&n===115&&e.startsWith(`str`,i)?2:t===9&&e.startsWith(`inlineStr`,i)?5:-1}else if(o===115){let t=0;for(let n=i;n<a;n++){let r=e.charCodeAt(n)-48;if(r<0||r>9)break;t=t*10+r}b=t}}let S=m===47,C=e.indexOf(`>`,x);if(C<0)return u(c);if(!_){i=v>=0?v:i+1,a=-1,d=C+1;continue}let w=v>=0?v:a+1;if(S){a=w,d=C+1;continue}let T=s.length;if(y===0&&e.charCodeAt(C+1)===60&&e.charCodeAt(C+2+T)===118&&e.charCodeAt(C+3+T)===62&&(!T||e.startsWith(s,C+2))){let t=Sl(e,C+4+T),o=xl;if(o>C+4+T&&wl(e,o,118,s)&&wl(e,o+4+T,99,s)){a=w,Number.isNaN(t)||r(i,a,t,n[b]??!1),d=o+8+2*T;continue}}let E=-1,D=-1,O=!1,k=-1;for(let t=C+1;;){let n=e.indexOf(`<`,t);if(n<0)return u(c);let r=e.charCodeAt(n+1)===47,i=r?n+2:n+1;if(t=n+1,s&&!e.startsWith(s,i))continue;let o=e.charCodeAt(i+T),l=e.charCodeAt(i+T+1);if(r){if(o===99&&l===62){k=n,d=i+T+2,a=w;break}}else if(o===118&&l===62){if(E=i+T+2,D=e.indexOf(`<`,E),D<0)return u(c);t=D}else o===102&&(l===62||l===47||Cl(l))&&(O=!0)}if(y===5){let t=``;for(let n of e.slice(C+1,k).matchAll(dl))t+=n[1];t&&r(i,a,pl(t),!1);continue}if(D<=E){O&&o++;continue}if(y===0){let t=Sl(e,E);Number.isNaN(t)||r(i,a,t,n[b]??!1)}else y===1?r(i,a,t[Sl(e,E)]??``,!1):y===2?r(i,a,pl(e.slice(E,D)),!1):y===3&&r(i,a,+(D-E===1&&e.charCodeAt(E)===49),!1)}},l=``;for await(let t of e)l=c(l?l+t:t,!1);return c(l,!0),o}function El(e){let t={name:``,attrs:``,kids:[],text:``},n=[t],r=0,i=(t,n)=>{let r=e.indexOf(t,n);return r<0?e.length:r+t.length};for(;r<e.length;){let t=e.indexOf(`<`,r),a=n[n.length-1];if(t<0){a.text+=pl(e.slice(r));break}if(t>r&&(a.text+=pl(e.slice(r,t))),e.startsWith(`<!--`,t)){r=i(`-->`,t+4);continue}if(e.startsWith(`<![CDATA[`,t)){let n=e.indexOf(`]]>`,t);a.text+=e.slice(t+9,n<0?e.length:n),r=n<0?e.length:n+3;continue}if(e[t+1]===`?`||e[t+1]===`!`){r=i(`>`,t);continue}let o=``,s=t+1;for(;s<e.length;s++){let t=e[s];if(o)t===o&&(o=``);else if(t===`"`||t===`'`)o=t;else if(t===`>`)break}let c=e.slice(t+1,s);if(r=s+1,c[0]===`/`){n.length>1&&n.pop();continue}let l=c.endsWith(`/`),u=/^[^\s/>]+/.exec(c),d={name:(u?.[0]??``).replace(/^.*:/,``),attrs:c.slice(u?.[0].length??0,l?-1:void 0),kids:[],text:``};if(a.kids.push(d),!l){if(n.length>256)throw new B(`the XidML file nests deeper than 256 elements`);n.push(d)}}return t}const V=(e,t)=>e?.kids.find(e=>e.name===t),Dl=(e,t)=>e?.kids.filter(e=>e.name===t)??[],H=(e,t)=>V(e,t)?.text.trim(),U=(e,t)=>{let n=RegExp(`(?:^|\\s)${t}\\s*=\\s*("([^"]*)"|'([^']*)')`).exec(e.attrs);return n?pl(n[2]??n[3]):void 0};function Ol(e,t){let n=[],r=[e];for(;r.length;){let e=r.pop();e.name===t&&n.push(e);for(let t=e.kids.length-1;t>=0;t--)r.push(e.kids[t])}return n}const W=e=>{if(e===void 0||e===``)return null;let t=Number(e);return Number.isFinite(t)?t:null};function kl(e,t,n){let r=0;for(;n>0;){let i=Math.floor(t/8),a=t%8,o=Math.min(8-a,n);r=r*2**o+(e[i]>>8-a-o&(1<<o)-1),t+=o,n-=o}return r}const Al=new DataView(new ArrayBuffer(8)),jl=(e,t)=>(Math.floor(e/2**32)&Math.floor(t/2**32))*2**32+((e&t)>>>0);function Ml(e,t,n,r=null,i=!1){if(n&&t%8)return`little-endian with a size that is not whole bytes`;if((r!==null||i)&&(n||t>53))return`a mask or complement on a little-endian or wide parameter`;let a=2**t-1,o=n?(e,n)=>{let r=0;for(let i=t/8-1;i>=0;i--)r=r*256+kl(e,n+8*i,8);return r}:r!==null||i?(e,n)=>{let o=kl(e,n,t);return r!==null&&(o=jl(o,r)),i?a-o:o}:(e,n)=>kl(e,n,t),s=2**(t-1);switch(e){case`BitVector`:return t<=53?o:`more than 53 bits`;case`OffsetBinary`:return t<=53?(e,t)=>o(e,t)-s:`more than 53 bits`;case`TwosComplement`:return t<=53?(e,t)=>{let n=o(e,t);return n>=s?n-2*s:n}:`more than 53 bits`;case`SignedMagnitude`:return t<=53?(e,t)=>{let n=o(e,t);return n>=s?-(n-s):n}:`more than 53 bits`;case`BinaryCodedDecimal`:return t%4||t>52?`BCD that is not whole digits`:(e,n)=>{let r=o(e,n),i=0;for(let e=t/4-1;e>=0;e--){let t=Math.floor(r/16**e)%16;if(t>9)return NaN;i=i*10+t}return i};case`IEEE-754-Float-Single`:return t===32?(e,t)=>(Al.setUint32(0,o(e,t)),Al.getFloat32(0)):`a single float that is not 32 bits`;case`IEEE-754-Float-Double`:return t===64?r!==null||i?`a mask or complement on a double`:n?(e,t)=>{for(let n=0;n<8;n++)Al.setUint8(7-n,kl(e,t+8*n,8));return Al.getFloat64(0)}:(e,t)=>(Al.setUint32(0,kl(e,t,32)),Al.setUint32(4,kl(e,t+32,32)),Al.getFloat64(0)):`a double that is not 64 bits`;default:return`data format ${e}`}}const Nl={"P Type":`P`,"D Type":`D`,"N Type":`N`,"M Type":`M`,"Q Type":`Q`},Pl=65506*8;function Fl(e){let t=V(El(e),`xidml`);if(!t)throw new B(`it has no <xidml> element`);let n=[],r=[],i=!1,a=0,o=new Map;for(let e of Ol(V(t,`Parameters`)??t,`Parameter`)){let t=U(e,`Name`);t&&!o.has(t)&&o.set(t,e)}let s=new Map;for(let e of Ol(t,`ParameterUnit`)){let t=U(e,`Name`);t&&s.set(t,{scale:W(H(e,`Scale`))??1,offset:W(H(e,`Offset`))??0})}let c=new Map;for(let e of Ol(t,`AlgorithmSet`))for(let t of e.kids){let e=U(t,`Name`);if(e)if(t.name===`Polynomial`){let n=Dl(t,`Term`).map(e=>[W(H(e,`Coefficient`))??0,W(H(e,`Exponent`))??0]);c.set(e,e=>n.reduce((t,[n,r])=>t+n*e**r,0))}else c.set(e,t.name)}let l=(e,t,l)=>{(V(e,`FillValue`)||(H(e,`Parity`)??`None`)!==`None`)&&(i=!0);let u=H(e,`ParameterReference`),d=u===void 0?V(e,`Parameter`):o.get(u),f=u??(d?U(d,`Name`):void 0);if(!f)return null;if(!d)return r.push(`${f} (${t}: no parameter definition)`),null;let p=W(H(e,`NumberOfDataBits`))??W(H(d,`SizeInBits`))??16;if(!Number.isInteger(p)||p<1||p>64)return r.push(`${f} (${p} bits)`),null;let m=H(d,`Endianness`);if(m===`Mixed-Endian`||m===`Bit-Endian`)return r.push(`${f} (${m})`),null;if(H(e,`MostSignificantBit`)===`Last`)return r.push(`${f} (least significant bit first)`),null;let h=H(e,`Justification`)===`Right`?Math.ceil(p/16)*16-p:0,g=H(e,`Mask`)?.replace(/^0x/i,``),_=null;if(g!==void 0){let e=g.length*4;if(!/^[0-9a-f]+$/i.test(g)||e<h+p)return r.push(`${f} (mask ${g})`),null;_=Number(BigInt(`0x${g}`)>>BigInt(e-h-p)&(1n<<BigInt(p))-1n)}let v=H(e,`Complement`)===`Yes`,y=Ml(H(d,`DataFormat`)??`OffsetBinary`,p,m===`Little-Endian`,_,v);if(typeof y==`string`)return r.push(`${f} (${y})`),null;let b=H(d,`ParameterUnitReference`),x=b?s.get(b):void 0,S=H(d,`BaseUnit`),C=x?b:S&&S!==`Unitless`&&S!==`BitVector`?S:``,w=H(d,`AlgorithmReference`),T=w?c.get(w):void 0;w&&typeof T!=`function`&&n.push(`${f}: its algorithm ${w} (${T??`not defined`}) is not applied.`);let E=typeof T==`function`?T:null,D=x||E?(e,t,n)=>{let r=y(e,n);return E&&(r=E(r)),x?r*x.scale+x.offset:r}:(e,t,n)=>y(e,n),O=[],k;for(let t of Dl(e,`Location`)){let e=W(H(t,`Offset_Words`)),n=e===null?W(H(t,`Offset_Bits`)):e*16+h;if(n===null||!Number.isInteger(n)||n<0||n>Pl)return r.push(`${f} (a location outside any IENA packet)`),null;let i=W(H(t,`Occurrences`))??1;if(!Number.isInteger(i)||i<1||i*p>Pl)return r.push(`${f} (${i} occurrences)`),null;if((a+=i)>1e6)throw Zc();if(i===1)O.push(n);else if(l){let t=e===null?p:Math.ceil(p/16)*16;for(let e=0;e<i;e++)O.push(n+e*t)}else O.push(n),k=i}return O.length?k&&O.length>1?(r.push(`${f} (several locations and occurrences)`),null):{name:f,unit:C,at:O,spread:k,bits:p,read:D}:(r.push(`${f} (${t}: no location)`),null)},u=new Map;for(let e of[...Ol(t,`IENA`),...Ol(t,`IENA-Ethernet-UDP-Basic`)]){let t=U(e,`Name`)??null,r=V(e,`Properties`),i=parseInt(H(r,`Key`)??``,16);if(!(i>=0&&i<=65535)){n.push(`The XidML package ${t??`(no name)`} has no IENA key; it is not used.`);continue}if(u.has(i)){n.push(`The XidML names key 0x${Il(i)} twice; the first package is used.`);continue}let a=Nl[H(r,`PayloadType`)??`P Type`]??`P`,o=parseInt(H(r,`EndWord`)??``,16),s=/^(true|1)$/i.test(H(e,`PlaceParametersContiguously`)??``),c=Dl(V(e,`Content`),`Mapping`);a!==`P`&&c.length&&n.push(`${t}: a ${a} type packet names its parameters by id; its mappings are not used.`);let d=a===`P`?c.map(e=>l(e,t??Il(i),s)).filter(e=>e!==null):[],f=W(H(e,`PackageRate`));u.set(i,{name:t,kind:a,fields:d,minBytes:0,rate:f&&f>0?f:null,end:o>=0&&o<=65535&&o!==57005?o:null})}if(!u.size)throw new B(`it has no IENA packages`);return i&&n.push(`XidML Parity and FillValue are not checked.`),r.length&&n.push(`Not decoded from the XidML: ${r.slice(0,20).join(`, `)}${r.length>20?`, and ${r.length-20} more`:``}.`),{source:`XidML`,keys:u,any:null,notes:n}}const Il=e=>e.toString(16).toUpperCase().padStart(4,`0`),Ll=2e3,Rl=1e5,zl=(e,t,n=`${t}s`)=>`${e} ${e===1?t:n}`,Bl=e=>e===1?`was`:`were`;function Vl(e,t,n,r,i,a){a.length=0;let o=n+r-2,s=n+14,c=e[n+10]&7;if(i===`N`||i===`D`){let e=i===`D`?4:2,n=e+2*c;if((o-s)%n)return null;for(;s<o;s+=n)a.push([t.getUint16(s),i===`D`?t.getUint16(s+2):0,s+e,c]);return a}let l=i===`M`?6:4;for(;s<o;){if(o-s<l)return null;let e=t.getUint16(s+l-2),n=s+l+e+(e&1);if(n>o)return null;a.push([t.getUint16(s),i===`M`?t.getUint16(s+2):0,s+l,e+1>>1]),s=n}return a}var Hl=class{dated=!1;#e=null;#t=1970;#n=new Map;#r(e){let t=this.#n.get(e);return t===void 0&&(t=Date.UTC(e,0,1)*1e3,this.#n.set(e,t)),t}abs(e,t){if(this.#e===null){let n=new Date(e).getUTCFullYear();return this.#t=Number.isFinite(n)?n:1970,this.dated=this.#t>=2e3,this.#e=this.#r(this.#t)+t}let n=0,r=this.#t;for(let e of[this.#t,this.#t+1,this.#t-1]){let i=this.#r(e)+t;(e===this.#t||Math.abs(i-this.#e)<Math.abs(n-this.#e))&&(n=i,r=e)}return this.#t=r,this.#e=n}};const Ul=(e,t)=>e?.keys.get(t)??e?.any??null;function Wl(e,t){let{b:n,o:r,n:i}=e,a=t.ports.get(e.dport);a||t.ports.set(e.dport,a=[0,0]);let o=t.dict?.pid,s=i>=2?n[r]<<8|n[r+1]:-1,c=s>=0&&!o?Ul(t.dict,s):null;if(!Qi(n,r,i,c?.end??57005))return a[1]++,null;a[0]++;let l=new DataView(n.buffer,n.byteOffset,n.byteLength);if(o){if(o.off+o.size>i)return t.damaged++,null;s=o.read(l,r+o.off),c=t.dict.keys.get(s)??null}let u=l.getUint16(r+4)*4294967296+l.getUint32(r+6);return{key:s,kd:c,abs:t.clock.abs(e.time,u),dv:l}}const Gl=e=>e?.kind??`P`,Kl=e=>!!e&&e.kind===`P`&&e.fields.length>0,ql=e=>e.spread??e.at.length,Jl=e=>ql(e)>1||e.dt!==void 0,Yl=(e,t)=>(e?.source===`XidML`?t-2:t)*8;function Xl(e,t,n,r){r.length=0;let i=2*Math.floor(n/e.bits);if(e.spread){let a=Math.floor((t-16>>1)/e.spread)*16;for(let t=0;t<(a>0?e.spread:1)&&r.length<i;t++){let i=e.at[0]+t*a;i+e.bits<=n&&r.push(i,t)}}else for(let t=0;t<e.at.length&&r.length<i;t++)e.at[t]+e.bits<=n&&r.push(e.at[t],t);return r}async function Zl(e,t){let n=e=>/\.(xidml|xml)$/i.test(e.name),r=e=>/\.(ya?ml|csv)$/i.test(e.name),i=[...e.filter(n),...e.filter(r)];if(!i.length)return null;let a=i[0];for(let e of i.slice(1))t.push(`${e.name} was not used: ${a.name} is the dictionary.`);let o=n(a)?`XidML file`:`layout`;try{if(a.size>67108864)throw new B(`it is larger than 64 MB`);let e=d(new Uint8Array(await a.arrayBuffer())),r=n(a)?Fl(e):ul(e,a.name);return t.push(...r.notes),r}catch(e){let n=e instanceof B?e.message:`it may be damaged`;return t.push(`${a.name} isn't a usable ${o} (${n}); IENA keys are read as raw 16-bit words.`),null}}async function Ql(e,t){let n=[],r={},i=await Zl(e.companions,n),a=qi(await t.read(0,64));if(!a)throw Error(`This is not a pcap or pcapng capture.`);let o={dict:i,clock:new Hl,stats:Wi(),ports:new Map,damaged:0},s=new Map,c=[],l=[],u=1/0,d=0,f=e=>{let t=Wl(e,o);if(!t)return;let{key:n,kd:r,abs:a,dv:f}=t,p=Gl(r),m=s.get(n),h=Kl(r),g=!h&&p!==`P`?Vl(e.b,f,e.o,e.n,p,c):null;if(!h&&p!==`P`&&!g){o.damaged++;return}if(!m)s.set(n,m={packets:0,short:0,words:0,rows:[],ids:new Map,first:a,last:a,steps:0,seq:f.getUint16(e.o+12)});else{let t=f.getUint16(e.o+12),n=t-m.seq&65535;n&&n<32768&&(m.steps+=n,m.seq=t,m.last=Math.max(m.last,a),m.first=Math.min(m.first,a))}if(m.packets++,u=Math.min(u,a),h&&e.n<r.minBytes){m.short++;return}if(h){r.fields.forEach((t,n)=>{Jl(t)&&(m.rows[n]=(m.rows[n]??0)+Xl(t,e.n,Yl(i,e.n),l).length/2)});return}if(p===`P`){m.words=Math.max(m.words,e.n-16>>1);return}let _=new Map;for(let[e,,,t]of g){let n=m.ids.get(e);n||m.ids.set(e,n={words:0,max:0,total:0}),t>64&&d++,n.words=Math.max(n.words,Math.min(t,64)),n.total++,_.set(e,(_.get(e)??0)+1)}for(let[e,t]of _){let n=m.ids.get(e);n.max=Math.max(n.max,t)}};for(let e=Zi(t,f,o.stats);!(await e.next()).done;);let p=[],m=new Map,h=0,g=0,_=e=>p.length>=Ll||h+e.channels.length>Rl?(g++,-1):(h+=e.channels.length,p.push(e),p.length-1),v=[...s].sort((e,t)=>e[0]-t[0]),y=[],b=0;for(let[e,t]of v){let n=Ul(i,e);i&&!n&&y.push(e);let a=Gl(n),o=n?.name||`IENA 0x${Il(e)}`,s=n?.rate?1e6/n.rate:t.steps?(t.last-t.first)/t.steps:0,c=s>0?1e6/s:null,l={dict:n,kind:a,fields:[],main:-1,rawWords:0,ids:new Map,period:s};m.set(e,l),r[`Key 0x${Il(e)}`]=`${n?.name?`${n.name}: `:``}${n?i.source===`layout`?`layout`:`${a} type`:`raw words`}, ${zl(t.packets,`packet`)}`;let u=(e,t,n,r)=>({name:e,channels:t,samples:n,time:{kind:`timestamps`},rateHz:r,irregular:!0});if(Kl(n)){b+=t.short;let e=t.packets-t.short;if(!e)continue;let r=n.fields.filter(e=>!Jl(e)),i=cn(r.map(e=>e.name));r.length&&(l.main=_(u(o,r.map((e,t)=>({name:i[t],unit:e.unit})),e,c))),r.forEach((e,t)=>l.fields.push({f:e,g:l.main,c:t,occ:1})),n.fields.forEach((e,n)=>{if(!Jl(e)||!t.rows[n])return;let r=ql(e),i=e.dt?1/e.dt:c&&c*r;l.fields.push({f:e,g:_(u(`${o} ${e.name}`,[{name:e.name,unit:e.unit}],t.rows[n],i)),c:0,occ:r})})}else if(a===`P`)l.rawWords=t.words,t.words&&(l.main=_(u(o,Array.from({length:t.words},(e,t)=>({name:`${o} w${t}`,unit:``})),t.packets,c)));else{let e=[...t.ids].sort((e,t)=>e[0]-t[0]),n=(e,t)=>Array.from({length:t},(n,r)=>({name:`${o} 0x${Il(e)}${t>1?` w${r}`:``}`,unit:``})),r=e=>a===`D`||a===`M`||e.max>1,i=e.filter(([,e])=>!r(e)).flatMap(([e,t])=>n(e,t.words));i.length&&(l.main=_(u(o,i,t.packets,c)));let s=0;for(let[t,i]of e){if(!r(i)){l.ids.set(t,{g:l.main,c:s,words:i.words,own:!1}),s+=i.words;continue}let e=i.words?_(u(`${o} 0x${Il(t)}`,n(t,i.words),i.total,null)):-1;l.ids.set(t,{g:e,c:0,words:i.words,own:!0})}}}if(!s.size)throw Error(`This capture has no IENA packets${o.stats.damagedAt===null?``:` Kymoscope could read (it is damaged)`}: no UDP datagram holds an IENA header, its size and end field.`);if(!i&&!n.length&&n.push(`No XidML or layout file came with the capture: every IENA key is read as raw 16-bit words.`),y.length){let e=y.slice(0,10).map(e=>`0x${Il(e)}`).join(`, `);n.push(`Not in the ${i.source}: ${y.length===1?`key`:`keys`} ${e}${y.length>10?`, and ${y.length-10} more`:``}; read as raw 16-bit words.`)}let x=o.damaged,S=0;for(let[e,t]of o.ports.values())e?x+=t:S+=t;let C=o.stats;x&&n.push(`${zl(x,`damaged IENA packet`)} ${Bl(x)} skipped.`);let w=[S?`${zl(S,`UDP datagram`)} that ${S===1?`isn't`:`aren't`} IENA`:``,C.other?`${zl(C.other,`frame`)} that ${C.other===1?`isn't`:`aren't`} UDP`:``].filter(Boolean);w.length&&n.push(`Skipped: ${w.join(`, `)}.`),C.incomplete&&n.push(`${zl(C.incomplete,`fragmented datagram`)} ${Bl(C.incomplete)} incomplete and skipped.`),C.truncated&&n.push(`${zl(C.truncated,`packet`)} captured shorter than sent (snap length) ${Bl(C.truncated)} skipped.`),b&&n.push(`${zl(b,`IENA packet`)} shorter than the layout ${Bl(b)} skipped (as the collector does).`),d&&n.push(`${zl(d,`message dataset`)} longer than 64 words ${d===1?`is`:`are`} read to its first 64 words.`),g&&n.push(`${zl(g,`group`)} past ${Ll.toLocaleString(`en-US`)} groups or ${Rl.toLocaleString(`en-US`)} channels ${Bl(g)} not read.`),C.cut&&n.push(`The capture ends in the middle of a packet.`),C.damagedAt!==null&&n.push(`The capture is damaged at byte ${C.damagedAt}; the rest of it was not read.`),cn(p.map(e=>e.name),[]).forEach((e,t)=>{p[t].name=e});let T={keys:m,dict:i,t0:u};return{format:`IENA (${a})`,startTime:Number.isFinite(u)&&o.clock.dated?new Date(u/1e3).toISOString():null,groups:p,meta:r,events:[],notes:n,interleaved:!0,state:T}}const $l={...ea,async plan(e,t){try{return await Ql(e,t)}catch(e){throw k(e)}},async*stream(e){let t=e.plan.state,n=new Map,r=e=>{e.cap=Math.max(1,Math.min(65536,e.total-e.start)),e.time=new Float64Array(e.cap),e.cols=e.cols.map(()=>new Float64Array(e.cap).fill(NaN))};for(let t of e.selection){let i=p(e,t.group),a=new Int32Array(e.plan.groups[t.group].channels.length).fill(-1);i.forEach((e,t)=>{a[e]=t});let o={cols:i.map(()=>new Float64Array),slot:a,time:new Float64Array,n:0,cap:0,start:0,total:e.plan.groups[t.group].samples};r(o),n.set(t.group,o)}let i=[],a=(e,t)=>{let n=t.n===t.cap;if(i.push({group:e,time:n?t.time:t.time.slice(0,t.n),start:t.start,length:t.n,columns:t.cols.map(e=>n?e:e.slice(0,t.n))}),t.start+=t.n,n)r(t);else for(let e of t.cols)e.fill(NaN,0,t.n);t.n=0},o,s=-1,c=(e,t)=>(o=n.get(e),!o||o.start+o.n>=o.total?!1:(o.n===o.cap&&a(e,o),s=o.n++,o.time[s]=t,!0)),l=(e,t)=>{let n=o.slot[e];n>=0&&(o.cols[n][s]=t)},u={dict:t.dict,clock:new Hl,stats:Wi(),ports:new Map,damaged:0},d=[],f=[],m=0,h=e=>{if(++m%4096==0)for(let[e,t]of n)t.n&&a(e,t);let r=Wl(e,u);if(!r)return;let i=t.keys.get(r.key);if(!i)return;let{b:p,o:h,n:g}=e,{dv:_}=r,v=(r.abs-t.t0)/1e6,y=Yl(t.dict,g),b=h*8,x=e=>e+2<=h+g-2?_.getUint16(e):NaN;if(i.fields.length||Kl(i.dict)){if(g<i.dict.minBytes)return;let e=i.main>=0&&c(i.main,v);for(let{f:t,g:n,c:r,occ:a}of i.fields){if(n===i.main){e&&l(r,t.at[0]+t.bits<=y?t.read(p,_,b+t.at[0]):NaN);continue}if(!(n<0)){Xl(t,g,y,f);for(let e=0;e<f.length;e+=2){let r=f[e+1];if(!c(n,t.dt?v+r*t.dt:v+r*i.period/a/1e6))break;l(0,t.read(p,_,b+f[e]))}}}return}if(i.kind===`P`){if(i.main>=0&&c(i.main,v))for(let e=0;e<i.rawWords;e++)l(e,x(h+14+2*e));return}let S=Vl(p,_,h,g,i.kind,d);if(!S)return;let C=i.main>=0&&c(i.main,v),w=o,T=s,E=new Map;for(let[e]of S)i.ids.get(e)?.own&&i.kind!==`D`&&i.kind!==`M`&&E.set(e,(E.get(e)??0)+1);let D=new Map;for(let[e,t,n,r]of S){let a=i.ids.get(e);if(!a||a.g<0)continue;let u=Math.min(r,a.words);if(!a.own){if(!C)continue;o=w,s=T;for(let e=0;e<u;e++)l(a.c+e,x(n+2*e));continue}let d=v+t/1e6;if(E.has(e)){let t=D.get(e)??0;D.set(e,t+1),d=v+t*i.period/E.get(e)/1e6}if(c(a.g,d))for(let e=0;e<u;e++)l(e,x(n+2*e))}};try{for(let t=Zi(e.io,h,u.stats,e.signal);!(await t.next()).done;)yield*i,i.length=0}catch(e){throw k(e)}for(let[e,t]of n)t.n&&a(e,t);yield*i},streamGroup(e,t){return this.stream({...e,selection:e.selection.filter(e=>e.group===t)})}},eu=65542,tu=(e,t)=>(e[t]&224)==0,nu=(e,t)=>(e[t]&7)<<8|e[t+1],ru=(e,t)=>e[t+2]>>6,iu=(e,t)=>(e[t+2]&63)<<8|e[t+3],au=(e,t)=>(e[t+4]<<8|e[t+5])+7,ou=()=>({idle:0,segments:0,skipped:0,cut:!1});var su=class{#e=new Map;#t;#n;constructor(e,t){this.#t=e,this.#n=t}push(e,t,n){let r=nu(e,t);if(r===2047){this.#n.idle++;return}let i=ru(e,t);if(i===3){this.#t(e,t,n);return}let a=this.#e.get(r),o=iu(e,t);if(i===1){a&&(this.#n.segments++,this.#e.delete(r));let i=new Uint8Array(Math.min(eu,Math.max(n*2,256)));i.set(e.subarray(t,t+n)),this.#e.set(r,{buf:i,n,count:o});return}if(!a||(a.count+1&16383)!==o||a.n+n-6>65542){this.#n.segments+=a?2:1,this.#e.delete(r);return}let s=a.n+n-6;if(s>a.buf.length){let e=new Uint8Array(Math.min(eu,Math.max(s,a.buf.length*2)));e.set(a.buf.subarray(0,a.n)),a.buf=e}a.buf.set(e.subarray(t+6,t+n),a.n),a.n=s,a.count=o,i===2&&(this.#e.delete(r),this.#t(a.buf,0,a.n))}};function cu(e,t,n,r,i){let a=0,o=e.length;for(;a+6<=o;){if(!tu(e,a)){n.skipped++,i.on=!0,a++;continue}let s=au(e,a);if(a+s>o){if(!r)return a;if(i.on){n.skipped++,a++;continue}return n.cut=!0,o}if(i.on){if(a+s+6<=o){if(!tu(e,a+s)){n.skipped++,a++;continue}}else if(!r)return a;i.on=!1}t.push(e,a,s),a+=s}return r&&a<o?(n.cut=!0,o):a}function lu(e,t=4){let n=0,r=0,i=!1,a=!0,o=new Map;for(;n+6<=e.length&&!(r>=t&&n>=4096);){if(!tu(e,n))return!1;let t=nu(e,n),s=iu(e,n),c=o.get(t);c!==void 0&&(c+1&16383)===s&&(i=!0),o.set(t,s),e[n]|e[n+1]|e[n+2]|e[n+3]&&(a=!1),n+=au(e,n),r++}return r>=t&&i&&!a}const uu=Uint8Array.of(26,207,252,29),du=(()=>{let e=new Uint8Array(255),t=255;for(let n=0;n<2040;n++){let r=t>>7;e[n>>3]|=r<<7-(n&7);let i=t>>7^t>>4^t>>2^t;t=(t<<1|i&1)&255}return e})(),fu=(()=>{let e=new Uint16Array(256);for(let t=0;t<256;t++){let n=t<<8;for(let e=0;e<8;e++)n=n&32768?n<<1^4129:n<<1;e[t]=n&65535}return e})();function pu(e,t,n){let r=65535;for(let i=t;i<t+n;i++)r=(r<<8^fu[(r>>8^e[i])&255])&65535;return r}const mu=(e,t)=>t+4<=e.length&&e[t]===26&&e[t+1]===207&&e[t+2]===252&&e[t+3]===29;function hu(e,t){for(let n=e.indexOf(26,t);n>=0;n=e.indexOf(26,n+1))if(mu(e,n))return n;return-1}function gu(e,t,n,r,i){let a=i.subarray(0,n);if(a.set(e.subarray(t,t+n)),r)for(let e=0;e<n;e++)a[e]^=du[e%255];return a}const _u=Uint8Array.from({length:256},(e,t)=>{let n=0;for(let e=t;e;e&=e-1)n++;return n});function vu(e,t){if(t+4>e.length)return!1;let n=0;for(let r=0;r<4&&n<=2;r++)n+=_u[e[t+r]^uu[r]];return n<=2}function yu(e,t,n,r,i){let a=new Map,o=0;for(let s of t){if(s+n>e.length)break;let t=gu(e,s,n,r,i),c=t[1]>>1&7,l=t[4]<<8|t[5],u=6+(l&32768?(t[6]&63)+1:0),d=n-(t[1]&1?4:0),f=l&2047,p=a.get(c),m=p&&(p[0]+1&255)===t[3]?p[1]:-1,h=-1;if(u<d&&f===2047)h=m>=d-u?m-(d-u):-1;else if(f<2046&&u+f<d){m>=0&&m===f&&o++;let e=u+f;for(;d-e>=6&&e+au(t,e)<=d;)e+=au(t,e);h=e===d?0:d-e>=6?e+au(t,e)-d:-1}a.set(c,[t[3],h])}return o}function bu(e){let t=hu(e,0);if(t<0||t>65536)return null;for(let n=t+4+7;n-t-4<=65536&&n+4<=e.length;n++){if(!vu(e,n))continue;let r=n-t,i=0,a=0,o=[];for(let n=t;n+4<=e.length;n+=r)i++,vu(e,n)&&(a++,n+r<=e.length&&o.push(n+4));if(a<3||a<.9*i||o.length<2)continue;let s=new Uint8Array(r),c=t=>{let n=0,i=-1,a=-1,c=[];for(let l of o){let o=gu(e,l,Math.min(6,r-4),t,s),u=(o[0]&63)<<4|o[1]>>4,d=o[1]>>1&7;!(o[0]>>6)&&(a<0||u===a)&&n++,i>=0&&(i+1&255)===o[2]&&n++,c[d]!==void 0&&(c[d]+1&255)===o[3]&&n++,i=o[2],c[d]=o[3],a=u}return n},l=c(!1),u=c(!0),d=u>l,f=-1;if(2*Math.max(l,u)<3*o.length)for(let t of[!1,!0]){let n=o.map(n=>{let r=gu(e,n,1,t,s)[0];return r>>6==1?1:r>>4==12?12:-1});if(n[0]>=0&&n.every(e=>e===n[0])){f=n[0],d=t;break}}let p=gu(e,o[0],Math.min(6,r-4),d,s);f<0&&(f=p[0]>>6==3&&p[0]>>4==12?12:p[0]>>6);let m=(r-4)%255==0&&(r-4)/255<=8,h=m?[223,239].map(e=>(r-4)/255*e).concat(r-4):[r-4],g=h.find(t=>o.filter(n=>pu(gu(e,n,t,d,s),0,t)===0).length*2>o.length),_=g??r-4;if(g===void 0&&m&&f===0){let t=-1;for(let n of h){let r=yu(e,o,n,d,s);r>t&&(t=r,_=n)}}return{start:t,cadu:r,frame:_,randomized:d,fecf:g!==void 0,version:f,scid:(p[0]&63)<<4|p[1]>>4}}return null}const xu=()=>({frames:0,vcs:new Set,badFecf:0,gaps:new Map,idleFrames:0,partial:0,damaged:0,notPackets:0,outOfSync:0,badSync:0});var Su=class{#e=[];#t;#n;#r;constructor(e,t,n){this.#t=e,this.#n=t,this.#r=n}#i(e){e.open&&this.#r.partial++,e.open=!1}#a(e,t,n,r){for(;n<r&&e.open;){let i=e.need<0?6:e.need,a=Math.min(i-e.n,r-n);if(e.buf.set(t.subarray(n,n+a),e.n),e.n+=a,n+=a,e.n<i)break;if(e.need<0){if(!tu(e.buf,0)){this.#i(e);break}if(e.need=au(e.buf,0),e.buf.length<e.need){let t=new Uint8Array(e.need);t.set(e.buf.subarray(0,e.n)),e.buf=t}continue}e.open=!1,this.#n.push(e.buf,0,e.n)}return n}#o(e,t,n,r){e.open=!0,e.n=0,e.need=-1,this.#a(e,t,n,r)}frame(e){let t=this.#r,n=this.#t,r=n.frame;t.frames++;let i=(e[0]&63)<<4|e[1]>>4;if(e[0]>>6||i!==n.scid){t.damaged++;return}let a=e[1]>>1&7,o=this.#e[a];o||(this.#e[a]=o={buf:new Uint8Array(256),n:0,need:-1,count:-1,open:!1,orphan:!1}),t.vcs.add(a);let s=e[3];if(o.count>=0&&s!==(o.count+1&255)){let e=t.gaps.get(a)??[0,0];e[0]++,e[1]+=s-o.count-1&255,t.gaps.set(a,e),this.#i(o)}if(o.count=s,n.fecf&&pu(e,0,r)!==0){t.badFecf++,this.#i(o),o.orphan=!0;return}let c=e[1]&1,l=e[4]<<8|e[5],u=6;l&32768&&(u+=(e[6]&63)+1);let d=r-(c?4:0)-(n.fecf?2:0);if(u>d){t.damaged++,this.#i(o);return}if(l&16384){t.notPackets++;return}let f=l&2047;if(f===2046){t.idleFrames++;return}if(f===2047){o.open?this.#a(o,e,u,d):o.orphan||(t.partial++,o.orphan=!0);return}let p=u+f;if(p>=d){t.damaged++,this.#i(o);return}o.open?(this.#a(o,e,u,p),o.open&&this.#i(o)):f>0&&!o.orphan&&t.partial++,o.orphan=!1;let m=p;for(;m<d;){if(d-m>=6){if(!tu(e,m)){t.partial++;break}let n=au(e,m);if(m+n<=d){this.#n.push(e,m,n),m+=n;continue}}this.#o(o,e,m,d);break}}};const Cu={id:`ccsds`,label:`CCSDS space telemetry`,extensions:[`.bin`,`.dat`,`.tlm`,`.raw`,`.cadu`,`.tm`],companions:[`.xml`,`.xtce`].map(e=>({ext:e,anyName:!0})),sniff:e=>bu(e)!==null||lu(e),sniffBytes:e=>hu(e,0)>=0?196624:e.length>=6&&tu(e,0)?4*eu:0};var wu=class extends Error{};const Tu=1e5,Eu=1e4,Du=2e6,Ou=[[63072e3,10],[78796800,11],[94694400,12],[126230400,13],[157766400,14],[189302400,15],[220924800,16],[252460800,17],[283996800,18],[315532800,19],[362793600,20],[394329600,21],[425865600,22],[489024e3,23],[567993600,24],[631152e3,25],[662688e3,26],[709948800,27],[741484800,28],[773020800,29],[820454400,30],[867715200,31],[915148800,32],[1136073600,33],[1230768e3,34],[1341100800,35],[1435708800,36],[1483228800,37]];function ku(e){let t=0;for(let[n,r]of Ou)e>=n+r&&(t=r);return e-t}function Au(e){switch(e){case`TAI`:return e=>ku(-378691200+e);case`GPS`:return e=>ku(315964819+e);case`J2000`:return e=>ku(946727967.816+e);case`UNIX`:case`POSIX`:return e=>e}let t=Date.parse(/[zZ]|[+-]\d\d:\d\d$/.test(e)?e:/T/.test(e)?`${e}Z`:`${e}T00:00:00Z`);return Number.isFinite(t)?e=>t/1e3+e:null}const ju={seconds:1,picoSeconds:1e-12,days:86400},Mu=new DataView(new ArrayBuffer(8));function Nu(e,t){return t?(t,n)=>{let r=0;for(let i=e/8-1;i>=0;i--)r=r*256+kl(t,n+8*i,8);return r}:(t,n)=>kl(t,n,e)}function Pu(e){let t=V(e,`ContextCalibratorList`)?`ContextCalibratorList`:``,n=V(e,`DefaultCalibrator`);if(!n)return{cal:null,why:t};let r=n.kids[0];if(!r)return{cal:null,why:t};if(r.name===`PolynomialCalibrator`){let e=Dl(r,`Term`).map(e=>[W(U(e,`coefficient`))??0,W(U(e,`exponent`))??0]);return{cal:t=>e.reduce((e,[n,r])=>e+n*t**r,0),why:t}}if(r.name===`SplineCalibrator`){let e=W(U(r,`order`))??1,n=/^(true|1)$/.test(U(r,`extrapolate`)??``),i=Dl(r,`SplinePoint`).map(e=>[W(U(e,`raw`)),W(U(e,`calibrated`))]).filter(e=>e[0]!==null&&e[1]!==null).sort((e,t)=>e[0]-t[0]);if(i.length<2||e>1)return{cal:null,why:`SplineCalibrator${e>1?` of order ${e}`:``}`};let a=i.length-1;return{cal:t=>{if(!(t>=i[0][0]&&t<=i[a][0])&&!n)return NaN;let r=0;for(;r<a-1&&t>i[r+1][0];)r++;if(e===0)return t>=i[r+1][0]?i[r+1][1]:i[r][1];let[o,s]=i[r],[c,l]=i[r+1];return c===o?s:s+(l-s)*(t-o)/(c-o)},why:t}}return{cal:null,why:r.name}}function Fu(e){let t=V(e,`SizeInBits`),n=W(H(V(t,`Fixed`),`FixedValue`)??H(t,`FixedValue`));return n!==null&&Number.isInteger(n)&&n>=0&&n<=65542*8?n:-1}function Iu(e){let t=(e,t=-1)=>({bits:t,read:null,why:e,cal:null,calWhy:``});if(!e)return t(`no encoding`);if((U(e,`bitOrder`)??`mostSignificantBitFirst`)!==`mostSignificantBitFirst`)return t(`least significant bit first`);let n=U(e,`byteOrder`),r=V(e,`ByteOrderList`),i=n===`leastSignificantByteFirst`||r!==void 0&&U(r.kids[0]??e,`byteSignificance`)===`0`;if(n&&n!==`leastSignificantByteFirst`&&n!==`mostSignificantByteFirst`)return t(`byte order ${n}`);if(e.name===`StringDataEncoding`)return t(`a string`,Fu(e));if(e.name===`BinaryDataEncoding`)return t(`binary data`,Fu(e));let a=W(U(e,`sizeInBits`))??(e.name===`FloatDataEncoding`?32:8);if(!Number.isInteger(a)||a<1||a>64)return t(`${a} bits`);if(i&&a%8)return t(`little-endian with a size that is not whole bytes`,a);let{cal:o,why:s}=Pu(e),c=Nu(a,i),l=null,u=``;if(e.name===`IntegerDataEncoding`){let t=2**(a-1);switch(U(e,`encoding`)??`unsigned`){case`unsigned`:l=c;break;case`twosComplement`:case`twosCompliment`:l=(e,n)=>{let r=c(e,n);return r>=t?r-2*t:r};break;case`signMagnitude`:l=(e,n)=>{let r=c(e,n);return r>=t?-(r-t):r};break;case`onesComplement`:l=(e,n)=>{let r=c(e,n);return r>=t?-(2*t-1-r):r};break;default:u=`${U(e,`encoding`)} integers`}}else if(e.name===`FloatDataEncoding`){let t=U(e,`encoding`)??`IEEE754_1985`;t!==`IEEE754_1985`&&t!==`IEEE754`?u=`${t} floats`:a===32?l=(e,t)=>(Mu.setUint32(0,c(e,t)),Mu.getFloat32(0)):a===64?l=i?(e,t)=>{for(let n=0;n<8;n++)Mu.setUint8(7-n,kl(e,t+8*n,8));return Mu.getFloat64(0)}:(e,t)=>(Mu.setUint32(0,kl(e,t,32)),Mu.setUint32(4,kl(e,t+32,32)),Mu.getFloat64(0)):u=`${a}-bit floats`}else return t(e.name);return{bits:a,read:l,why:u,cal:o,calWhy:s}}const Lu=new Set([`IntegerDataEncoding`,`FloatDataEncoding`,`StringDataEncoding`,`BinaryDataEncoding`]),Ru=e=>e?.kids.find(e=>Lu.has(e.name)),zu=e=>H(V(e,`UnitSet`),`Unit`)??``;function Bu(e){let t={unit:zu(e),kind:`number`,labels:[],time:null};switch(e.name){case`IntegerParameterType`:case`FloatParameterType`:{let n=Iu(Ru(e));return{...t,...n}}case`BooleanParameterType`:{let n=Iu(Ru(e));return{...t,...n,cal:null,kind:`bool`,labels:[[U(e,`zeroStringValue`)??`False`,0],[U(e,`oneStringValue`)??`True`,1]]}}case`EnumeratedParameterType`:{let n=Iu(Ru(e)),r=Dl(V(e,`EnumerationList`),`Enumeration`).flatMap(e=>{let t=W(U(e,`value`)),n=U(e,`label`);return t!==null&&n!==void 0?[[n,t]]:[]});return{...t,...n,cal:null,kind:`enum`,labels:r}}case`AbsoluteTimeParameterType`:case`RelativeTimeParameterType`:{let n=V(e,`Encoding`),r=Iu(Ru(n)),i=ju[(n&&U(n,`units`))??`seconds`],a=(W(n&&U(n,`scale`))??1)*(i??1),o=(W(n&&U(n,`offset`))??0)*(i??1),s=e=>e*a+o;if(!i)return{...t,...r,read:null,why:`time in ${U(n,`units`)}`};if(e.name===`RelativeTimeParameterType`)return{...t,...r,unit:`s`,cal:s};let c=V(e,`ReferenceTime`),l=H(c,`Epoch`),u=l?Au(l):V(c,`OffsetFrom`)?null:Au(`TAI`);return u?{...t,...r,unit:`s`,cal:s,kind:`time`,time:u}:{...t,...r,read:null,why:l?`epoch ${l}`:`a time offset from another parameter`}}case`StringParameterType`:return{...t,...Iu(Ru(e)),read:null,why:`a string`};case`BinaryParameterType`:return{...t,...Iu(Ru(e)),read:null,why:`binary data`};case`AggregateParameterType`:return{...t,...Iu(void 0),why:`an aggregate`};case`ArrayParameterType`:return{...t,...Iu(void 0),why:`an array`};default:return{...t,...Iu(void 0),why:e.name}}}function Vu(e,t,n,r){let i=e=>{let t=[];for(let n of e.split(`/`))n===`..`?t.pop():n&&n!==`.`&&t.push(n);return`/${t.join(`/`)}`};if(n.startsWith(`/`))return e.get(i(n));for(let a=r;;a=a.slice(0,a.lastIndexOf(`/`))){let r=e.get(i(`${a}/${n}`));if(r!==void 0||!a)return r??t.get(n.slice(n.lastIndexOf(`/`)+1))}}const Hu={ArrayParameterRefEntry:`an array entry`,IndirectParameterRefEntry:`an indirect parameter entry`,StreamSegmentEntry:`a stream segment entry`,ParameterSegmentRefEntry:`a parameter segment entry`,ContainerSegmentRefEntry:`a container segment entry`};var Uu=class{params=[];containers=[];roots=[];chans=[];timeParam=[];notes=[];short=!1;#e=new Float64Array;#t=new Float64Array;#n=new Int32Array;#r=0;#i=0;constructor(e){let t=V(El(e),`SpaceSystem`);if(!t)throw new wu(`it has no <SpaceSystem> element`);let n=new Map,r=new Map,i=new Map,a=new Map,o=new Map,s=new Map,c=[],l=[],u=[[t,``]];for(;u.length;){let[e,t]=u.pop(),d=`${t}/${U(e,`name`)??``}`,f=V(e,`TelemetryMetaData`);for(let e of V(f,`ParameterTypeSet`)?.kids??[]){let t=U(e,`name`);t&&(n.set(`${d}/${t}`,[e,d]),r.has(t)||r.set(t,[e,d]))}for(let e of Dl(V(f,`ParameterSet`),`Parameter`)){let t=U(e,`name`);if(t){if(l.length>=Tu)throw new wu(`it defines more than ${Tu.toLocaleString(`en-US`)} parameters`);i.set(`${d}/${t}`,l.length),a.has(t)||a.set(t,l.length),l.push([e,d])}}for(let e of Dl(V(f,`ContainerSet`),`SequenceContainer`)){let t=U(e,`name`);if(t){if(c.length>=Eu)throw new wu(`it defines more than ${Eu.toLocaleString(`en-US`)} containers`);o.set(`${d}/${t}`,c.length),s.has(t)||s.set(t,c.length),c.push([e,d])}}let p=Dl(e,`SpaceSystem`);for(let e=p.length-1;e>=0;e--)u.push([p[e],d])}if(!c.length)throw new wu(`it has no SequenceContainers`);let d=new Map,f=new Map,p=new Map;for(let[e,t]of l){let i=U(e,`name`),a=U(e,`parameterTypeRef`),o=a?Vu(n,r,a,t):void 0,s=o&&p.get(o[0]);o&&!s&&p.set(o[0],s=Bu(o[0]));let c=s??{...Bu({name:`no type`,attrs:``,kids:[],text:``}),why:`no type`};this.params.push({name:i,unit:c.unit,bits:c.bits,read:c.why?null:c.read,cal:c.cal,kind:c.kind,labels:c.labels,time:c.time})}let m=e=>{let[t,i]=l[e],a=U(t,`parameterTypeRef`),o=a?Vu(n,r,a,i):void 0,s=o&&p.get(o[0]);return s?[s.why,s.calWhy]:[`no type`,``]},h=(e,t,n,r,o,s)=>{let c=Vu(i,a,e,o),l=!/^(false|0)$/.test(n??`true`);if(c===void 0||![`==`,`!=`,`<`,`<=`,`>`,`>=`].includes(t))return d.set(s,`a comparison it cannot read`),null;let u=this.params[c],f;return l&&(u.kind===`enum`||u.kind===`bool`)?(f=u.labels.find(([e])=>e===r)?.[1],f===void 0&&u.kind===`bool`&&(f=/^(true|1)$/i.test(r)?1:/^(false|0)$/i.test(r)?0:void 0)):f=W(r)??void 0,f===void 0?(d.set(s,`a comparison with ${r}`),null):{p:c,cal:l,op:t,v:f}},g=(e,t,n)=>{if(e.name===`Condition`){let r=Dl(e,`ParameterInstanceRef`),i=H(e,`Value`);return r.length!==1||i===void 0?(d.set(n,`a condition against another parameter`),null):h(U(r[0],`parameterRef`)??``,(H(e,`ComparisonOperator`)??`==`).trim(),U(r[0],`useCalibratedValue`),i.trim(),t,n)}if(e.name!==`ANDedConditions`&&e.name!==`ORedConditions`)return d.set(n,`a ${e.name}`),null;let r=[];for(let i of e.kids){let e=g(i,t,n);if(!e)return null;r.push(e)}return{and:e.name===`ANDedConditions`,of:r}},_=(e,t,n)=>{if(!e)return null;let r=e.kids[0];if(r?.name===`BooleanExpression`&&r.kids[0])return g(r.kids[0],t,n)??`unsupported`;let i=r?.name===`Comparison`?[r]:r?.name===`ComparisonList`?Dl(r,`Comparison`):null;if(!i)return d.set(n,`a ${r?.name??`condition`}`),`unsupported`;let a=[];for(let e of i){let r=h(U(e,`parameterRef`)??``,U(e,`comparisonOperator`)??`==`,U(e,`useCalibratedValue`),U(e,`value`)??``,t,n);if(!r)return`unsupported`;a.push(r)}return a.length===1?a[0]:{and:!0,of:a}};c.forEach(([e,t])=>{let n=U(e,`name`),r=V(e,`BaseContainer`),c=-1,l=!1,u=null;if(r){let e=Vu(o,s,U(r,`containerRef`)??``,t);e===void 0?(d.set(`container ${n}`,`its base container is not defined`),l=!0):c=e;let i=_(V(r,`RestrictionCriteria`),t,`container ${n}`);i===`unsupported`?l=!0:u=i}let p=[];for(let r of V(e,`EntryList`)?.kids??[]){let e=(e,t)=>{d.set(e,t),p.push({p:-1,c:-1,abs:-1,rel:0,cond:null,stop:!0})};if(Hu[r.name]){e(`${n} entry`,Hu[r.name]);continue}if(r.name!==`ParameterRefEntry`&&r.name!==`ContainerRefEntry`)continue;let c=U(r,r.name===`ParameterRefEntry`?`parameterRef`:`containerRef`)??``;if(V(r,`RepeatEntry`)){e(c,`a RepeatEntry`);continue}let l=V(r,`LocationInContainerInBits`),u=-1,h=0;if(l){let t=W(H(l,`FixedValue`)),n=U(l,`referenceLocation`)??`previousEntry`;if(t===null||!Number.isInteger(t)||Math.abs(t)>65542*8){e(c,`a location that is not a fixed value`);continue}if(n===`containerStart`)u=t;else if(n===`previousEntry`)h=t;else{e(c,`a location from the ${n===`containerEnd`?`container end`:`next entry`}`);continue}}let g=_(V(r,`IncludeCondition`),t,c);if(g===`unsupported`){p.push({p:-1,c:-1,abs:-1,rel:0,cond:null,stop:!0});continue}if(r.name===`ContainerRefEntry`){let n=Vu(o,s,c,t);if(n===void 0){e(c,`not defined`);continue}p.push({p:-1,c:n,abs:u,rel:h,cond:g,stop:!1});continue}let v=Vu(i,a,c,t);if(v===void 0){e(c,`not defined`);continue}let y=this.params[v],[b,x]=m(v);b&&d.set(y.name,b),x&&f.set(y.name,x),p.push({p:v,c:-1,abs:u,rel:h,cond:g,stop:y.bits<0})}this.containers.push({name:n,abstract:/^(true|1)$/.test(U(e,`abstract`)??``),base:c,never:l,restrict:u,entries:p,kids:[]})}),this.containers.forEach((e,t)=>{let n=0;for(let r=e.base;r>=0;r=this.containers[r].base){if(r===t)throw new wu(`its containers inherit from each other in a loop`);if(++n>64)throw new wu(`its containers inherit through more than 64 base containers`)}e.base>=0&&this.containers[e.base].kids.push(t)});let v=new Uint8Array(this.containers.length),y=(e,t)=>{if(v[e]!==2){if(v[e]===1)throw new wu(`its containers refer to each other in a loop`);if(t>64)throw new wu(`its containers nest more than 64 deep`);v[e]=1;for(let n of this.containers[e].entries)n.c>=0&&y(n.c,t+1);v[e]=2}};this.containers.forEach((e,t)=>y(t,0)),this.roots=this.containers.flatMap((e,t)=>e.base<0&&e.kids.length?[t]:[]),this.roots.length||(this.roots=this.containers.flatMap((e,t)=>e.base<0&&!e.abstract?[t]:[]));let b=0,x=[],S=new Set,C=(e,t,n,r)=>{for(let i of this.containers[e].entries){if(++b>Du)throw new wu(`its containers nest more than ${Du.toLocaleString(`en-US`)} entries`);if(i.stop){i.cond||(r=!1);continue}i.abs>=0&&(r=n),i.c>=0?r=C(i.c,t,r,r):i.p>=0&&this.params[i.p].read&&(r?t.add(i.p):S.add(i.p))}return r};if(this.containers.forEach((e,t)=>{if(this.chans.push([]),this.timeParam.push(-1),e.abstract)return;let n=[];for(let e=t;e>=0;e=this.containers[e].base)n.unshift(e);let r=new Set;S=new Set;let i=!0;for(let e of n)i=C(e,r,!0,i);let a=[...r],o=a.find(e=>this.params[e].kind===`time`)??-1;this.timeParam[t]=o,this.chans[t]=a.filter(e=>e!==o);let s=[...S].filter(e=>!r.has(e)).map(e=>this.params[e].name);s.length&&x.push(`${s.join(`, `)} in ${e.name}`)}),d.size){let e=[...d].map(([e,t])=>`${e} (${t})`);this.notes.push(`Not decoded from the XTCE: ${e.slice(0,20).join(`, `)}${e.length>20?`, and ${e.length-20} more`:``}.`)}if(x.length&&this.notes.push(`Not read (they follow an entry of no fixed size): ${x.slice(0,20).join(`; `)}${x.length>20?`; and ${x.length-20} more containers`:``}.`),f.size){let e=[...f].map(([e,t])=>`${e} (${t})`);this.notes.push(`Calibrators not applied: ${e.slice(0,20).join(`, `)}${e.length>20?`, and ${e.length-20} more`:``}.`)}let w=this.params.length;this.#e=new Float64Array(w),this.#t=new Float64Array(w),this.#n=new Int32Array(w)}#a(e){if(!e)return!0;if(`of`in e){for(let t of e.of)if(this.#a(t)!==e.and)return!e.and;return e.and}if(this.#n[e.p]!==this.#r)return!1;let t=e.cal?this.#t[e.p]:this.#e[e.p];return e.op===`==`?t===e.v:e.op===`!=`?t!==e.v:e.op===`<`?t<e.v:e.op===`<=`?t<=e.v:e.op===`>`?t>e.v:t>=e.v}#o(e,t,n,r,i,a){for(let o of this.containers[e].entries){if(--this.#i<0)return NaN;if(o.cond&&!this.#a(o.cond))continue;if(o.stop){n=NaN;continue}if(n=o.abs>=0?t+o.abs:n+o.rel,o.c>=0){n=this.#o(o.c,n,n,r,i,a);continue}let e=this.params[o.p];if(!(n>=0&&n+e.bits<=a)){n>=0&&(this.short=!0),n+=e.bits;continue}if(e.read){let t=e.read(r,i+n);this.#e[o.p]=t,this.#t[o.p]=e.cal?e.cal(t):e.kind===`bool`?+!!t:t,this.#n[o.p]=this.#r}n+=e.bits}return n}#s(e,t,n,r){this.#r=this.#r+1|0,this.short=!1;let i=0;for(let a of e)i=this.#o(a,0,i,t,n,r)}#c(e,t,n,r,i){let a=this.containers[e[e.length-1]];for(let o of a.kids){let a=this.containers[o];if(a.never||!this.#a(a.restrict))continue;e.push(o);let s=this.#c(e,this.#o(o,0,t,n,r,i),n,r,i);if(s>=0)return s;e.pop(),this.#s(e,n,r,i)}return a.abstract?-1:e[e.length-1]}decode(e,t,n){for(let r of this.roots){this.#r=this.#r+1|0,this.short=!1,this.#i=8*n+256;let i=this.#c([r],this.#o(r,0,0,e,t*8,n*8),e,t*8,n*8);if(i>=0)return i}return-1}value(e){return this.#n[e]===this.#r?this.#t[e]:NaN}time(e){let t=this.timeParam[e];return t<0?NaN:this.params[t].time(this.value(t))}};const Wu=2e3,Gu=1e5,Ku=(e,t,n=`${t}s`)=>`${e.toLocaleString(`en-US`)} ${e===1?t:n}`,qu=e=>e===1?`was`:`were`,Ju=e=>`0x${e.toString(16).toUpperCase().padStart(3,`0`)}`,Yu=(e,t=10)=>`${e.slice(0,t).join(`, `)}${e.length>t?`, and ${e.length-t} more`:``}`;async function*Xu(e,t,n,r,i,a){let o=new su(n,r),s=new Uint8Array,c={on:!1},l=t&&new Su(t,o,i),u=t?new Uint8Array(t.frame):null,d=!0;for await(let n of e.windows(0,e.size)){a?.throwIfAborted();let f=n.offset+n.bytes.length>=e.size,p=n.bytes;s.length&&(p=new Uint8Array(s.length+n.bytes.length),p.set(s),p.set(n.bytes,s.length));let m=0;if(!t)m=cu(p,o,r,f,c);else{d&&(m=t.start,i.outOfSync+=m);let e=4+t.frame;for(;f?m+e<=p.length:m+Math.max(e,t.cadu)<=p.length;){if(!mu(p,m)){if(vu(p,m)){i.badSync++,m+=t.cadu;continue}let e=hu(p,m+1),n=e>=0?e:f?p.length:Math.max(m,p.length-3);if(i.outOfSync+=n-m,m=n,e<0)break;continue}let n=p.subarray(m+4,m+e);if(t.randomized){u.set(n);for(let e=0;e<n.length;e++)u[e]^=du[e%255];n=u}l.frame(n),m+=t.cadu}f&&m<p.length&&(p.length-m>4&&(r.cut=!0),m=p.length)}d=!1,s=p.slice(m),yield}}async function Zu(e,t){let n=e.filter(e=>/\.(xml|xtce)$/i.test(e.name));if(!n.length)return null;let r=n[0];for(let e of n.slice(1))t.push(`${e.name} was not used: ${r.name} is the XTCE file.`);try{if(r.size>52428800)throw new wu(`it is larger than 50 MB`);let e=new Uu(d(new Uint8Array(await r.arrayBuffer())));return t.push(...e.notes),e}catch(e){let n=e instanceof wu?e.message:e instanceof B?`it nests deeper than 256 elements`:`it may be damaged`;return t.push(`${r.name} isn't a usable XTCE file (${n}); every APID is read as raw bytes of its data field.`),null}}const Qu=(e,t,n,r)=>{let i=e?e.decode(t,n,r):-1;return i>=0&&e.chans[i].length?i:-1};async function $u(e,t){let n=[],r={},i=bu(await t.read(0,196624));if(i&&i.version!==0)throw Error(`These are CCSDS ${i.version===1?`AOS (732.0-B)`:i.version===12?`USLP (732.1-B)`:`version ${i.version}`} transfer frames, which Kymoscope does not read; TM frames (132.0-B) and Space Packets are read.`);let a=await Zu(e.companions,n),o=ou(),s=xu(),c=new Map,l=new Map,u=1/0,d=0,f=0,p=0,m=(e,t,n)=>{d++;let r=Qu(a,e,t,n);if(r>=0){if(a.short&&f++,a.timeParam[r]>=0){let e=a.time(r);if(!Number.isFinite(e)){p++;return}u=Math.min(u,e)}c.set(r,(c.get(r)??0)+1);return}let i=nu(e,t),o=l.get(i);o?(o.n++,o.width=Math.max(o.width,n-6)):l.set(i,{n:1,width:n-6})};for(let e=Xu(t,i,m,o,s);!(await e.next()).done;);if(!d)throw Error(i?`This file has CCSDS TM frames but no Space Packets Kymoscope could read in them.`:`This file has no CCSDS Space Packets Kymoscope could read.`);let h=[],g=0,_=0,v=e=>h.length>=Wu||g+e.channels.length>Gu?(_++,-1):(g+=e.channels.length,h.push(e),h.length-1),y=new Int32Array(a?.containers.length??0).fill(-1);if(a)for(let e of[...c.keys()].sort((e,t)=>e-t)){let t=a.containers[e],i=a.chans[e].map(e=>a.params[e]),o=cn(i.map(e=>e.name)),s=a.timeParam[e]>=0;s||n.push(`${t.name} has no AbsoluteTime parameter in the XTCE: its packets are numbered.`),y[e]=v({name:t.name,channels:i.map((e,t)=>({name:o[t],unit:e.unit})),samples:c.get(e),time:s?{kind:`timestamps`}:{kind:`index`},rateHz:null,irregular:s||void 0});for(let e of i)e.labels.length&&(e.kind===`enum`||e.kind===`bool`)&&(r[`${e.name} values`]=e.labels.map(([e,t])=>`${t} = ${e}`).join(`, `))}let b=new Map,x=[...l].sort((e,t)=>e[0]-t[0]),S=[];for(let[e,t]of x){let n=`APID ${Ju(e)}`,r=Math.min(t.width,256);t.width>256&&S.push(n),b.set(e,{g:v({name:n,channels:Array.from({length:r},(e,t)=>({name:`${n} b${t}`,unit:``})),samples:t.n,time:{kind:`index`},rateHz:null}),width:r})}let C=x.map(([e])=>Ju(e));!a&&!n.length?n.push(`No XTCE file came with the telemetry: every APID is read as raw bytes of its data field, numbered (no time).`):a&&C.length&&n.push(`Not in the XTCE: ${C.length===1?`APID`:`APIDs`} ${Yu(C)}; read as raw bytes of the data field, numbered (no time).`);for(let e of S)n.push(`${e}: only the first 256 bytes of its data field are read.`);f&&n.push(`${Ku(f,`packet`)} shorter than ${f===1?`its`:`their`} XTCE container: the values past ${f===1?`its`:`their`} end are empty.`),p&&n.push(`${Ku(p,`packet`)} with no usable time ${qu(p)} skipped.`),s.badFecf&&n.push(`${Ku(s.badFecf,`frame`)} failed ${s.badFecf===1?`its`:`their`} FECF check and ${qu(s.badFecf)} skipped.`);let w=[...s.gaps].sort((e,t)=>e[0]-t[0]);if(w.length){let e=w.reduce((e,[,[t]])=>e+t,0);n.push(`${Ku(e,`frame-count gap`)} (${w.map(([e,[,t]])=>`VC ${e}, ${Ku(t,`frame`)} missing`).join(`; `)}).`)}s.damaged&&n.push(`${Ku(s.damaged,`frame`)} of another spacecraft or version, or with a damaged data field, ${qu(s.damaged)} skipped.`),s.notPackets&&n.push(`${Ku(s.notPackets,`frame`)} carrying VCA data rather than packets ${qu(s.notPackets)} skipped.`),s.idleFrames&&n.push(`${Ku(s.idleFrames,`idle frame`)} ${qu(s.idleFrames)} skipped.`),o.idle&&n.push(`${Ku(o.idle,`idle packet`)} ${qu(o.idle)} skipped.`),s.partial&&n.push(`${Ku(s.partial,`partial packet`)} ${qu(s.partial)} dropped (frame-count gaps, frames skipped).`),o.segments&&n.push(`${Ku(o.segments,`packet segment`)} out of order ${qu(o.segments)} dropped.`),o.skipped&&n.push(`${Ku(o.skipped,`byte`)} that hold${o.skipped===1?`s`:``} no packet ${qu(o.skipped)} skipped.`),s.outOfSync&&n.push(`${Ku(s.outOfSync,`byte`)} out of sync (no ASM where a frame should start) ${qu(s.outOfSync)} skipped.`),s.badSync&&n.push(`${Ku(s.badSync,`frame`)} with a damaged sync marker (ASM) ${qu(s.badSync)} skipped.`),i&&i.frame<i.cadu-4&&n.push(`Reed-Solomon check bytes present (not corrected): the ${i.cadu}-byte CADUs are read as frames of ${i.frame} bytes.`),_&&n.push(`${Ku(_,`group`)} past ${Wu.toLocaleString(`en-US`)} groups or ${Gu.toLocaleString(`en-US`)} channels ${qu(_)} not read.`),o.cut&&n.push(`The file ends in the middle of a ${i?`frame`:`packet`}.`),i&&(r.Spacecraft=`0x${i.scid.toString(16).toUpperCase()}`,r.Frames=`${s.frames} (${[...s.vcs].sort((e,t)=>e-t).map(e=>`VC ${e}`).join(`, `)})`,r.FECF=i.fecf?`checked`:`none`),r.Packets=String(d),cn(h.map(e=>e.name),[]).forEach((e,t)=>{h[t].name=e});let T={shape:i,dict:a,t0:u,leafGroup:y,raw:b};return{format:i?`CCSDS TM frames (${i.frame} bytes${i.randomized?`, randomized`:``})`:`CCSDS Space Packets`,startTime:Number.isFinite(u)?new Date(u*1e3).toISOString():null,groups:h,meta:r,events:[],notes:n,interleaved:!0,state:T}}const ed={...Cu,async plan(e,t){try{return await $u(e,t)}catch(e){throw k(e)}},async*stream(e){let t=e.plan.state,n=new Map,r=e=>{e.cap=Math.max(1,Math.min(65536,e.total-e.start,Math.floor(4e6/Math.max(1,e.cols.length)))),e.time&&=new Float64Array(e.cap),e.cols=e.cols.map(()=>new Float64Array(e.cap).fill(NaN))};for(let t of e.selection){let i=e.plan.groups[t.group],a=p(e,t.group),o={cols:a.map(()=>new Float64Array),sel:a,time:i.time.kind===`timestamps`?new Float64Array:null,n:0,cap:0,start:0,total:i.samples};r(o),n.set(t.group,o)}let i=[],a=(e,t)=>{let n=t.n===t.cap;if(i.push({group:e,time:t.time&&(n?t.time:t.time.slice(0,t.n)),start:t.start,length:t.n,columns:t.cols.map(e=>n?e:e.slice(0,t.n))}),t.start+=t.n,n)r(t);else for(let e of t.cols)e.fill(NaN,0,t.n);t.n=0},o,s=-1,c=(e,t)=>(o=n.get(e),!o||o.start+o.n>=o.total?!1:(o.n===o.cap&&a(e,o),s=o.n++,o.time&&(o.time[s]=t),!0)),l=t.dict,u=0,d=(e,r,i)=>{if(++u%4096==0)for(let[e,t]of n)t.n&&a(e,t);let d=Qu(l,e,r,i);if(d>=0){let e=0;if(l.timeParam[d]>=0){if(e=l.time(d),!Number.isFinite(e))return;e-=t.t0}let n=t.leafGroup[d];if(n<0||!c(n,e))return;let r=l.chans[d],{sel:i,cols:a}=o;for(let e=0;e<i.length;e++)a[e][s]=l.value(r[i[e]]);return}let f=t.raw.get(nu(e,r));if(!f||f.g<0||!c(f.g,0))return;let{sel:p,cols:m}=o;for(let t=0;t<p.length;t++)p[t]<i-6&&(m[t][s]=e[r+6+p[t]])};try{for(let n=Xu(e.io,t.shape,d,ou(),xu(),e.signal);!(await n.next()).done;)yield*i,i.length=0}catch(e){throw k(e)}for(let[e,t]of n)t.n&&a(e,t);yield*i},streamGroup(e,t){return this.stream({...e,selection:e.selection.filter(e=>e.group===t)})}};function td(e,t,n){if(e.length<t+10)return!1;let r=new DataView(e.buffer,e.byteOffset,e.byteLength),i=r.getUint16(t,n),a=r.getUint16(t+2,n);return i>=1900&&i<=2100&&a>=1&&a<=366&&e[t+4]<=23&&e[t+5]<=59&&e[t+6]<=60}function nd(e,t=0){if(e.length<t+48)return!1;for(let n=0;n<6;n++){let r=e[t+n];if(!(r===32||r>=48&&r<=57))return!1}return!`DRQM`.includes(String.fromCharCode(e[t+6]))||!(e[t+7]===32||e[t+7]===0)?!1:td(e,t+20,!1)||td(e,t+20,!0)}const rd=(e,t=0)=>e.length>=t+40&&e[t]===77&&e[t+1]===83&&e[t+2]===3,id={id:`mseed`,label:`MiniSEED`,extensions:[`.mseed`,`.miniseed`,`.ms`],sniff:e=>rd(e)||nd(e)},ad=`This MiniSEED file's compressed data is damaged.`;function od(e,t,n,r=!1){let i=new Int32Array(n);if(n===0)return i;let a=new DataView(e.buffer,e.byteOffset,e.byteLength),o=Math.floor(e.length/64);if(o===0)throw Error(ad);let s=a.getInt32(4,r),c=a.getInt32(8,r),l=0,u=e=>{l<n&&(i[l++]=e)};for(let e=0;e<o&&l<n;e++){let i=e*64,o=a.getUint32(i,r);for(let s=e===0?3:1;s<16&&l<n;s++){let e=o>>>30-2*s&3;if(e===0)continue;let n=a.getInt32(i+4*s,r);if(e===1){for(let e=0;e<4;e++)u(a.getInt8(i+4*s+e));continue}if(t===1){e===2?(u(a.getInt16(i+4*s,r)),u(a.getInt16(i+4*s+2,r))):u(n);continue}let c=n>>>30;if(e===2)if(c===1)u(n<<2>>2);else if(c===2)u(n<<2>>17),u(n<<17>>17);else if(c===3)for(let e=0;e<3;e++)u(n<<2+10*e>>22);else throw Error(ad);else if(c===0)for(let e=0;e<5;e++)u(n<<2+6*e>>26);else if(c===1)for(let e=0;e<6;e++)u(n<<2+5*e>>27);else if(c===2)for(let e=0;e<7;e++)u(n<<4+4*e>>28);else throw Error(ad)}}if(l<n)throw Error(ad);i[0]=s;for(let e=1;e<n;e++)i[e]=i[e-1]+i[e];if(i[n-1]!==c)throw Error(ad);return i}const sd={1:2,3:4,4:4,5:8},cd={1:1/2,3:1/4,4:1/4,5:1/8,10:1,11:7/4},ld=65536,ud=(e,t,n,r,i)=>Date.UTC(e,0,1,n,r,i)+(t-1)*864e5;function dd(e,t){return e===0||t===0?0:e>0?t>0?e*t:-e/t:t>0?-t/e:1/(e*t)}function fd(e){let t=/^FDSN:([^_]*)_([^_]*)_([^_]*)_(.*)$/.exec(e);return t?`${t[1]}.${t[2]}.${t[3]}.${t[4].replace(/_/g,``)}`:e}function pd(e,t){let n=i(e),r=e[33],a=n.getUint16(34,!0),o=n.getUint32(36,!0),s=40+r+a+o,c=n.getFloat64(16,!0);c<0&&(c=-1/c);let l=ud(n.getUint16(8,!0),n.getUint16(10,!0),e[12],e[13],e[14])*1e3+n.getUint32(4,!0)/1e3;return{rec:{data:t+40+r+a,dataLen:o,enc:e[15],n:n.getUint32(24,!0),le:!0,steimLe:!1,t:l,rate:c,source:fd(u(e.subarray(40,40+r)))},length:s}}async function md(e,t,n){let r=!td(t,20,!1),a=i(t),o=(e,n)=>u(t.subarray(e,n)).trim(),s=`${o(18,20)}.${o(8,13)}.${o(13,15)}.${o(15,18)}`,c=dd(a.getInt16(32,r),a.getInt16(34,r)),l=ud(a.getUint16(20,r),a.getUint16(22,r),t[24],t[25],t[26])*1e3+a.getUint16(28,r)*100;t[36]&2||(l+=a.getInt32(40,r)*100);let d=-1,f=r,p=0;for(let e=a.getUint16(46,r),n=0;e>=48&&e+8<=t.length&&n<64;n++){let n=a.getUint16(e,r);n===1e3?(d=t[e+4],f=t[e+5]===0,p=t[e+6]>=7&&t[e+6]<=20?2**t[e+6]:0):n===1001?l+=a.getInt8(e+5):n===100&&(c=a.getFloat32(e+4,r));let i=a.getUint16(e+2,r);if(i<=e)break;e=i}if(!p){for(let t of[4096,512,256,1024,2048,8192,128,16384,32768,65536])if(n+t===e.size||n+t<e.size&&nd(await e.read(n+t,64))){p=t;break}return p?{rec:null,length:p,skipped:`without blockette 1000 (no encoding)`}:{rec:null,length:0}}let m=a.getUint16(44,r);return m<48||m>p?{rec:null,length:p,skipped:`with a damaged header`}:{rec:{data:n+m,dataLen:p-m,enc:d,n:a.getUint16(30,r),le:f,steimLe:f,t:l,rate:c,source:s},length:p}}async function*hd(e,t){let n=e.selection.find(e=>e.group===t);if(!n||n.channels.length===0)return;let r=e.plan.state,i=e.plan.groups[t].samples,a=0,o=new Float64Array(Math.min(ld,i)),s=0,c=()=>{let e={group:t,time:null,start:a,length:s,columns:n.channels.map((e,t)=>t?o.slice():o)};return a+=s,s=0,o=new Float64Array(Math.min(ld,i-a)),e};for(let n of r.groups[t]){e.signal?.throwIfAborted();for(let e=0;e<n.pad;){let t=Math.min(n.pad-e,o.length-s);o.fill(NaN,s,s+t),s+=t,e+=t,s===o.length&&(yield c())}let t=r.recs[n.rec],i=t.damaged?new Float64Array(t.n).fill(NaN):gd(t,await e.io.read(t.data,t.dataLen));for(let e=n.skip;e<i.length;){let t=Math.min(i.length-e,o.length-s);o.set(i.subarray(e,e+t),s),s+=t,e+=t,s===o.length&&(yield c())}}}function gd(e,t){if(e.enc===10||e.enc===11)return od(t,e.enc===10?1:2,e.n,e.steimLe);let n=i(t),r=new Float64Array(e.n),a=sd[e.enc];for(let t=0,i=0;t<e.n;t++,i+=a)r[t]=e.enc===1?n.getInt16(i,e.le):e.enc===3?n.getInt32(i,e.le):e.enc===4?n.getFloat32(i,e.le):n.getFloat64(i,e.le);return r}const _d={...id,async plan(e,t){let n=[],r=[],i=new Map,a=e=>i.set(e,(i.get(e)??0)+1),o=new Set,s=0;for(let e=0;e<t.size;){let i=await t.read(e,4096),c=rd(i);if(!c&&!nd(i)){r.push(`The last ${t.size-e} bytes of the file are not MiniSEED records and were not read.`);break}let l=c?pd(i,e):await md(t,i,e);if(!l.length||e+l.length>t.size){r.push(`The file ends inside a record (damaged or cut short): the data from byte ${e} on was not read.`);break}o.add(c?3:2),e+=l.length;let u=l.rec;if(!u){a(l.skipped);continue}if(u.n!==0){if(!(u.enc in cd)){a(`in encoding ${u.enc}, which Kymoscope cannot read`);continue}if(u.n>u.dataLen*cd[u.enc]){a(`declaring more samples than they hold (damaged)`);continue}if(!(Number.isFinite(u.rate)&&u.rate>0)){a(`without a sample rate`);continue}if(u.enc===10||u.enc===11){let n=u.data-(e-l.length);try{gd(u,n+u.dataLen<=i.length?i.subarray(n,n+u.dataLen):await t.read(u.data,u.dataLen))}catch{u.damaged=!0,s++}}n.push(u)}}s&&r.push(`${s} damaged record${s===1?` was`:`s were`} left empty.`);for(let[e,t]of i)r.push(`${t} record${t===1?``:`s`} ${e} ${t===1?`was`:`were`} skipped.`);if(n.length===0)throw Error(`This MiniSEED file has no data records Kymoscope can read.`);let c=new Map;n.forEach((e,t)=>{let n=c.get(e.source);n?n.push(t):c.set(e.source,[t])});let l=n.reduce((e,t)=>Math.min(e,t.t),1/0),u=[],d=[];for(let[e,t]of c){t.sort((e,t)=>n[e].t-n[t].t);let i=!1,a=0,o=null,s=()=>{if(!o)return;let t=a++?`${e} (${a})`:e;u.push({name:t,channels:[{name:t,unit:`counts`}],samples:o.samples,time:{kind:`rate`,rate:o.rate,start:(o.start-l)/1e6},rateHz:o.rate}),d.push(o.pieces)};for(let e of t){let t=n[e];if(o&&Math.abs(t.rate-o.rate)<=1e-6*o.rate){let n=(t.t-o.start)/1e6*o.rate-o.samples;if(n>.5&&(Math.round(n)>=1e4||o.padded+Math.round(n)>o.samples-o.padded+t.n))s(),o=null;else{let r=n>.5?Math.round(n):0,a=n<-.5?Math.round(-n):0;if(a&&(i=!0),a>=t.n)continue;o.pieces.push({rec:e,skip:a,pad:r}),o.samples+=r+t.n-a,o.padded+=r;continue}}else s();o={rate:t.rate,start:t.t,samples:t.n,padded:0,pieces:[{rec:e,skip:0,pad:0}]}}s(),i&&r.push(`${e}: records overlap; the samples read first were kept and the overlapping ones dropped.`)}let f={recs:n,groups:d};return{format:`MiniSEED ${[...o].sort().join(` + `)}`,startTime:new Date(Math.floor(l/1e3)).toISOString(),groups:u,meta:{records:String(n.length)},events:[],notes:r,state:f}},streamGroup:(e,t)=>hd(e,t),async*stream(e){for(let t of e.selection)yield*hd(e,t.group)}},vd={id:`ulog`,label:`PX4 ULog`,extensions:[`.ulg`],sniff:e=>f(e,`ULog5`)},yd={int8_t:[1,0],uint8_t:[1,1],int16_t:[2,2],uint16_t:[2,3],int32_t:[4,4],uint32_t:[4,5],int64_t:[8,6],uint64_t:[8,7],float:[4,8],double:[8,9],bool:[1,10],char:[1,11]},bd=65535,xd=1e5,Sd=[`EMERGENCY`,`ALERT`,`CRITICAL`,`ERROR`,`WARNING`,`NOTICE`,`INFO`,`DEBUG`];function Cd(e){let t=e.indexOf(`:`);if(t<0)throw Error(`bad format`);let n=[];for(let r of e.slice(t+1).split(`;`)){if(!r)continue;let[e,t]=r.split(` `),i=e.indexOf(`[`),a=i<0?0:Number(e.slice(i+1,e.indexOf(`]`)));if(!t||!(Number.isInteger(a)&&a>=0&&a<=bd))throw Error(`bad field`);n.push({type:i<0?e:e.slice(0,i),n:a,name:t})}return[e.slice(0,t),n]}function wd(e,t){let n=new Map,r=(t,i)=>{if(yd[t])return yd[t][0];let a=n.get(t);if(a!==void 0)return a;let o=e.get(t);if(!o)throw Error(`its format uses ${t}, which the file does not define`);if(i>8)throw Error(`its format nests too deep`);let s=0;for(let e of o)if((s+=r(e.type,i+1)*Math.max(1,e.n))>bd)throw Error(`its format is larger than a message`);return n.set(t,s),s};r(t,0);let i=[],a=-1,o=0,s=(t,n,c,l)=>{if(l>8)throw Error(`its format nests too deep`);for(let u of e.get(t)){let e=r(u.type,l+1),t=Math.max(1,u.n);if(u.name.startsWith(`_padding`)){c+=e*t;continue}let d=yd[u.type];if(l===0&&u.name===`timestamp`&&u.type===`uint64_t`&&u.n===0)a=c;else if(d?.[1]===11)i.push({name:n+u.name,code:11,off:c,n:t});else if(d)for(let r=0;r<t;r++)i.push({name:n+u.name+(u.n?`[${r}]`:``),code:d[1],off:c+r*e,n:1});else if(e>0)for(let r=0;r<t;r++)s(u.type,`${n}${u.name}${u.n?`[${r}]`:``}.`,c+r*e,l+1);c+=e*t,l===0&&(o=c)}};if(s(t,``,0,0),a<0)throw Error(`its format has no uint64_t timestamp`);return{leaves:i,tsOff:a,minSize:o}}async function*Td(e,t,n,r,a){let o=new Uint8Array;for await(let r of e.windows(16,t-16)){a?.throwIfAborted();let e=r.bytes;if(o.length){let t=new Uint8Array(o.length+e.length);t.set(o),t.set(e,o.length),e=t}let t=i(e),s=0;for(;!(s+3>e.length);){let r=e[s]|e[s+1]<<8;if(s+3+r>e.length)break;n(e[s+2],e,t,s+3,r),s+=3+r}o=e.slice(s),yield}r.cut=o.length>0}function Ed(e,t,n){switch(n){case 0:return e.getInt8(t);case 1:return e.getUint8(t);case 2:return e.getInt16(t,!0);case 3:return e.getUint16(t,!0);case 4:return e.getInt32(t,!0);case 5:return e.getUint32(t,!0);case 6:return o(e,t);case 7:return a(e,t);case 8:return e.getFloat32(t,!0);case 9:return e.getFloat64(t,!0);default:return+!!e.getUint8(t)}}function Dd(e){for(let t=1;t<10;t++){let n=Number(e.toPrecision(t));if(Math.fround(n)===e)return String(n)}return String(e)}function Od(e,t,n,r,i){if(e.startsWith(`char[`))return l(t.subarray(r,i));let a=yd[e];if(!a||a[1]===11||r+a[0]>i)return null;let o=Ed(n,r,a[1]);return a[1]===8?Dd(o):String(o)}function kd(e,t,n){let r=e[t];if(t+1+r>n)return null;let[i,a]=d(e.subarray(t+1,t+1+r)).split(` `);return a?[i,a,t+1+r]:null}const Ad=(e,t)=>`[${Sd[e>=48?e-48:e]??`UNKNOWN`}] ${t}`,jd={...vd,async plan(e,t){let n=await t.read(0,59);if(n.length<16||!f(n,`ULog5`))throw Error(`This is not a ULog file.`);let r=i(n),o=[],s=t.size;if(n.length>=59&&n[18]===66){let e=n.subarray(27,35);if(e[0]&-2||e.subarray(1).some(e=>e))throw Error(`This ULog file uses features this reader does not know.`);let t=a(r,35);e[0]&1&&t>16&&t<s&&(s=t,o.push(`This file has data appended after logging ended; only the data before it was read.`))}let c=new Map,u=new Map,p=new Set,m=[],h=new Map,g=[],_=0,v=0,y=0,b=0,x={},S=[],C=1/0,w=0,T=0,E=0,D=(e,t,n,r,i)=>{let s=r+i;switch(e){case 70:try{let[e,n]=Cd(d(t.subarray(r,s)));c.set(e,n),h.clear()}catch{o.push(`A message format in the file could not be read; skipped.`)}break;case 73:case 80:{let i=kd(t,r,s);if(!i)break;let a=`${e===73?`info`:`param`}.${i[1]}`,o=Od(i[0],t,n,i[2],s);o!==null&&(e===73||!(a in x))&&(x[a]=o);break}case 77:{if(i<2)break;let e=kd(t,r+1,s);if(!e||!e[0].startsWith(`char[`))break;let n=`info.${e[1]}`,a=l(t.subarray(e[2],s));x[n]=n in x?x[n]+(t[r]?``:`
41
- `)+a:a;break}case 65:{if(i<3)break;let e=t[r],a=n.getUint16(r+1,!0),l=d(t.subarray(r+3,s)),f=_++;u.delete(a),p.delete(a);let g=h.get(l);if(!g){try{g=wd(c,l)}catch(e){g=e}h.set(l,g)}if(g instanceof Error){o.push(`${l}: ${g.message}; skipped.`);break}if(v+g.leaves.length>xd){y++,p.add(a);break}v+=g.leaves.length;let b={ord:f,name:e>0?`${l}_${e}`:l,count:0,...g};u.set(a,b),m.push(b);break}case 82:i>=2&&(u.delete(n.getUint16(r,!0)),p.delete(n.getUint16(r,!0)));break;case 68:{let e=i>=2?u.get(n.getUint16(r,!0)):void 0;if(!e&&i>=2&&p.has(n.getUint16(r,!0)))break;if(!e||i-2<e.minSize){w++;break}e.count++;let t=a(n,r+2+e.tsOff);C=Math.min(C,t),b=Math.max(b,t);break}case 76:i>=9&&S.push({ts:a(n,r+1),text:Ad(t[r],d(t.subarray(r+9,s)))});break;case 67:i>=11&&S.push({ts:a(n,r+3),text:Ad(t[r],d(t.subarray(r+11,s)))});break;case 79:if(i>=2){T++,E+=n.getUint16(r,!0),g.push(b);for(let e of u.values())e.count&&e.count++}break}},O={cut:!1};for(let e=Td(t,s,D,O);!(await e.next()).done;);O.cut&&o.push(`The file ends in the middle of a message.`),w&&o.push(`${w} data message${w===1?``:`s`} did not match a subscription; skipped.`),y&&o.push(`${y} subscription${y===1?` was`:`s were`} skipped: the file has more than ${xd.toLocaleString(`en-US`)} channels.`),T&&o.push(`${T} dropout${T===1?``:`s`} while logging (${E} ms in total).`),Number.isFinite(C)||(C=a(r,8));let k=m.filter(e=>e.count>0),A=cn(k.map(e=>e.name),[]),j=k.map((e,t)=>({name:A[t],channels:e.leaves.map(e=>({name:e.name,unit:``,...e.code===11?{text:!0}:{}})),samples:e.count,time:{kind:`timestamps`},rateHz:null,irregular:!0})),M=S.map(e=>({time:(e.ts-C)/1e6,text:e.text}));return{format:`ULog v${n[7]}`,startTime:null,groups:j,meta:x,events:M,notes:o,interleaved:!0,state:{subs:k,t0:C,end:s,drops:g}}},async*stream(e){let t=e.plan.state,n=new Map,r=e=>{e.cap=Math.max(1,Math.min(65536,e.sub.count-e.start)),e.time=new Float64Array(e.cap),e.cols=e.leaves.map(t=>t.code===11?Array(e.cap):new Float64Array(e.cap))};for(let i of e.selection){let a=t.subs[i.group],o={g:i.group,sub:a,leaves:p(e,i.group).map(e=>a.leaves[e]),time:new Float64Array,cols:[],n:0,cap:0,start:0};r(o),n.set(a.ord,o)}let i=new Map,o=0,s=0,c=0,u=[],d=e=>{let t=e.n===e.cap;u.push({group:e.g,time:t?e.time:e.time.slice(0,e.n),start:e.start,length:e.n,columns:e.cols.map(n=>t?n:n.slice(0,e.n))}),e.start+=e.n,e.n=0,r(e)},f=(e,r,u,f,p)=>{if(++c%65536==0)for(let e of n.values())e.n&&d(e);if(e===65){p>=3&&i.set(u.getUint16(f+1,!0),o++);return}if(e===82){p>=2&&i.delete(u.getUint16(f,!0));return}if(e===79){if(p<2)return;let e=(t.drops[s++]-t.t0)/1e6;for(let t of i.values()){let r=n.get(t);if(!(!r||r.start+r.n===0)){r.time[r.n]=e;for(let e=0;e<r.leaves.length;e++)r.leaves[e].code===11?r.cols[e][r.n]=null:r.cols[e][r.n]=NaN;++r.n===r.cap&&d(r)}}return}if(e!==68||p<2)return;let m=i.get(u.getUint16(f,!0)),h=m===void 0?void 0:n.get(m);if(!h||p-2<h.sub.minSize)return;let g=f+2;h.time[h.n]=(a(u,g+h.sub.tsOff)-t.t0)/1e6;for(let e=0;e<h.leaves.length;e++){let t=h.leaves[e];t.code===11?h.cols[e][h.n]=l(r.subarray(g+t.off,g+t.off+t.n)):h.cols[e][h.n]=Ed(u,g+t.off,t.code)}++h.n===h.cap&&d(h)};for(let n=Td(e.io,t.end,f,{cut:!1},e.signal);!(await n.next()).done;)yield*u,u.length=0;for(let e of n.values())e.n&&d(e);yield*u},streamGroup(e,t){return this.stream({...e,selection:e.selection.filter(e=>e.group===t)})}};function Md({polynomial:e,numTables:t}){let n=new Uint32Array(256*t);for(let t=0;t<256;t++){let r=t;r=(r&1)*e^r>>>1,r=(r&1)*e^r>>>1,r=(r&1)*e^r>>>1,r=(r&1)*e^r>>>1,r=(r&1)*e^r>>>1,r=(r&1)*e^r>>>1,r=(r&1)*e^r>>>1,r=(r&1)*e^r>>>1,n[t]=r}for(let e=256;e<n.length;e++){let t=n[e-256];n[e]=n[t&255]^t>>>8}return n}const Nd=Md({polynomial:3988292384,numTables:8});function Pd(){return-1}function Fd(e,t){let n=t.byteLength,r=new DataView(t.buffer,t.byteOffset,n),i=e,a=0,o=-r.byteOffset&3;for(;a<o&&a<n;a++)i=Nd[(i^r.getUint8(a))&255]^i>>>8;if(a===n)return i;a=o;let s=n-a;for(;s>=8;a+=8,s-=8){i^=r.getUint32(a,!0);let e=r.getUint32(a+4,!0);i=Nd[0+(e>>>24&255)]^Nd[1*256+(e>>>16&255)]^Nd[2*256+(e>>>8&255)]^Nd[3*256+(e>>>0&255)]^Nd[4*256+(i>>>24&255)]^Nd[5*256+(i>>>16&255)]^Nd[6*256+(i>>>8&255)]^Nd[7*256+(i>>>0&255)]}for(let e=a;e<n;e++)i=Nd[(i^r.getUint8(e))&255]^i>>>8;return i}function Id(e){return(e^-1)>>>0}function Ld(e){return Id(Fd(Pd(),e))}var G=function(e,t,n,r){function i(e){return e instanceof n?e:new n(function(t){t(e)})}return new(n||=Promise)(function(n,a){function o(e){try{c(r.next(e))}catch(e){a(e)}}function s(e){try{c(r.throw(e))}catch(e){a(e)}}function c(e){e.done?n(e.value):i(e.value).then(o,s)}c((r=r.apply(e,t||[])).next())})},K=function(e,t){var n={label:0,sent:function(){if(a[0]&1)throw a[1];return a[1]},trys:[],ops:[]},r,i,a,o=Object.create((typeof Iterator==`function`?Iterator:Object).prototype);return o.next=s(0),o.throw=s(1),o.return=s(2),typeof Symbol==`function`&&(o[Symbol.iterator]=function(){return this}),o;function s(e){return function(t){return c([e,t])}}function c(s){if(r)throw TypeError(`Generator is already executing.`);for(;o&&(o=0,s[0]&&(n=0)),n;)try{if(r=1,i&&(a=s[0]&2?i.return:s[0]?i.throw||((a=i.return)&&a.call(i),0):i.next)&&!(a=a.call(i,s[1])).done)return a;switch(i=0,a&&(s=[s[0]&2,a.value]),s[0]){case 0:case 1:a=s;break;case 4:return n.label++,{value:s[1],done:!1};case 5:n.label++,i=s[1],s=[0];continue;case 7:s=n.ops.pop(),n.trys.pop();continue;default:if((a=n.trys,!(a=a.length>0&&a[a.length-1]))&&(s[0]===6||s[0]===2)){n=0;continue}if(s[0]===3&&(!a||s[1]>a[0]&&s[1]<a[3])){n.label=s[1];break}if(s[0]===6&&n.label<a[1]){n.label=a[1],a=s;break}if(a&&n.label<a[2]){n.label=a[2],n.ops.push(s);break}a[2]&&n.ops.pop(),n.trys.pop();continue}s=t.call(e,n)}catch(e){s=[6,e],i=0}finally{r=a=0}if(s[0]&5)throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}},Rd=function(e,t){var n=typeof Symbol==`function`&&e[Symbol.iterator];if(!n)return e;var r=n.call(e),i,a=[],o;try{for(;(t===void 0||t-- >0)&&!(i=r.next()).done;)a.push(i.value)}catch(e){o={error:e}}finally{try{i&&!i.done&&(n=r.return)&&n.call(r)}finally{if(o)throw o.error}}return a},zd=function(e,t,n){if(n||arguments.length===2)for(var r=0,i=t.length,a;r<i;r++)(a||!(r in t))&&(a||=Array.prototype.slice.call(t,0,r),a[r]=t[r]);return e.concat(a||Array.prototype.slice.call(t))},Bd=function(e){var t=typeof Symbol==`function`&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&typeof e.length==`number`)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw TypeError(t?`Object is not iterable.`:`Symbol.iterator is not defined.`)};(function(){function e(t){t===void 0&&(t=e.minComparator);var n=this;this.compare=t,this.heapArray=[],this._limit=0,this.offer=this.add,this.element=this.peek,this.poll=this.pop,this._invertedCompare=function(e,t){return n.compare(e,t).then(function(e){return-1*e})}}return e.getChildrenIndexOf=function(e){return[e*2+1,e*2+2]},e.getParentIndexOf=function(e){if(e<=0)return-1;var t=e%2?1:2;return Math.floor((e-t)/2)},e.getSiblingIndexOf=function(e){return e<=0?-1:e+(e%2?1:-1)},e.minComparator=function(e,t){return G(this,void 0,void 0,function(){return K(this,function(n){return e>t?[2,1]:e<t?[2,-1]:[2,0]})})},e.maxComparator=function(e,t){return G(this,void 0,void 0,function(){return K(this,function(n){return t>e?[2,1]:t<e?[2,-1]:[2,0]})})},e.minComparatorNumber=function(e,t){return G(this,void 0,void 0,function(){return K(this,function(n){return[2,e-t]})})},e.maxComparatorNumber=function(e,t){return G(this,void 0,void 0,function(){return K(this,function(n){return[2,t-e]})})},e.defaultIsEqual=function(e,t){return G(this,void 0,void 0,function(){return K(this,function(n){return[2,e===t]})})},e.print=function(t){function n(t){var n=e.getParentIndexOf(t);return Math.floor(Math.log2(n+1))}function r(e,t){for(var n=``;t>0;--t)n+=e;return n}for(var i=0,a=[],o=n(t.length-1)+2,s=0;i<t.length;){var c=n(i)+1;i===0&&(c=0);var l=String(t.get(i));l.length>s&&(s=l.length),a[c]=a[c]||[],a[c].push(l),i+=1}return a.map(function(e,t){var n=2**(o-t)-1;return r(` `,Math.floor(n/2)*s)+e.map(function(e){var t=(s-e.length)/2;return r(` `,Math.ceil(t))+e+r(` `,Math.floor(t))}).join(r(` `,n*s))}).join(`
42
- `)},e.heapify=function(t,n){return G(this,void 0,void 0,function(){var r;return K(this,function(i){switch(i.label){case 0:return r=new e(n),r.heapArray=t,[4,r.init()];case 1:return i.sent(),[2,r]}})})},e.heappop=function(t,n){var r=new e(n);return r.heapArray=t,r.pop()},e.heappush=function(t,n,r){return G(this,void 0,void 0,function(){var i;return K(this,function(a){switch(a.label){case 0:return i=new e(r),i.heapArray=t,[4,i.push(n)];case 1:return a.sent(),[2]}})})},e.heappushpop=function(t,n,r){var i=new e(r);return i.heapArray=t,i.pushpop(n)},e.heapreplace=function(t,n,r){var i=new e(r);return i.heapArray=t,i.replace(n)},e.heaptop=function(t,n,r){n===void 0&&(n=1);var i=new e(r);return i.heapArray=t,i.top(n)},e.heapbottom=function(t,n,r){n===void 0&&(n=1);var i=new e(r);return i.heapArray=t,i.bottom(n)},e.nlargest=function(t,n,r){return G(this,void 0,void 0,function(){var i;return K(this,function(a){switch(a.label){case 0:return i=new e(r),i.heapArray=zd([],Rd(n),!1),[4,i.init()];case 1:return a.sent(),[2,i.top(t)]}})})},e.nsmallest=function(t,n,r){return G(this,void 0,void 0,function(){var i;return K(this,function(a){switch(a.label){case 0:return i=new e(r),i.heapArray=zd([],Rd(n),!1),[4,i.init()];case 1:return a.sent(),[2,i.bottom(t)]}})})},e.prototype.add=function(e){return G(this,void 0,void 0,function(){return K(this,function(t){switch(t.label){case 0:return[4,this._sortNodeUp(this.heapArray.push(e)-1)];case 1:return t.sent(),this._applyLimit(),[2,!0]}})})},e.prototype.addAll=function(e){return G(this,void 0,void 0,function(){var t,n,r;return K(this,function(i){switch(i.label){case 0:t=this.length,(r=this.heapArray).push.apply(r,zd([],Rd(e),!1)),n=this.length,i.label=1;case 1:return t<n?[4,this._sortNodeUp(t)]:[3,4];case 2:i.sent(),i.label=3;case 3:return++t,[3,1];case 4:return this._applyLimit(),[2,!0]}})})},e.prototype.bottom=function(){return G(this,arguments,void 0,function(e){return e===void 0&&(e=1),K(this,function(t){return this.heapArray.length===0||e<=0?[2,[]]:this.heapArray.length===1?[2,[this.heapArray[0]]]:e>=this.heapArray.length?[2,zd([],Rd(this.heapArray),!1)]:[2,this._bottomN_push(~~e)]})})},e.prototype.check=function(){return G(this,void 0,void 0,function(){var e,t,n,r,i,a,o,s,c;return K(this,function(l){switch(l.label){case 0:e=0,l.label=1;case 1:if(!(e<this.heapArray.length))return[3,10];t=this.heapArray[e],n=this.getChildrenOf(e),l.label=2;case 2:l.trys.push([2,7,8,9]),r=(s=void 0,Bd(n)),i=r.next(),l.label=3;case 3:return i.done?[3,6]:(a=i.value,[4,this.compare(t,a)]);case 4:if(l.sent()>0)return[2,t];l.label=5;case 5:return i=r.next(),[3,3];case 6:return[3,9];case 7:return o=l.sent(),s={error:o},[3,9];case 8:try{i&&!i.done&&(c=r.return)&&c.call(r)}finally{if(s)throw s.error}return[7];case 9:return++e,[3,1];case 10:return[2]}})})},e.prototype.clear=function(){this.heapArray=[]},e.prototype.clone=function(){var t=new e(this.comparator());return t.heapArray=this.toArray(),t._limit=this._limit,t},e.prototype.comparator=function(){return this.compare},e.prototype.contains=function(t){return G(this,arguments,void 0,function(t,n){var r,i,a,o,s,c;return n===void 0&&(n=e.defaultIsEqual),K(this,function(e){switch(e.label){case 0:e.trys.push([0,5,6,7]),r=Bd(this.heapArray),i=r.next(),e.label=1;case 1:return i.done?[3,4]:(a=i.value,[4,n(a,t)]);case 2:if(e.sent())return[2,!0];e.label=3;case 3:return i=r.next(),[3,1];case 4:return[3,7];case 5:return o=e.sent(),s={error:o},[3,7];case 6:try{i&&!i.done&&(c=r.return)&&c.call(r)}finally{if(s)throw s.error}return[7];case 7:return[2,!1]}})})},e.prototype.init=function(t){return G(this,void 0,void 0,function(){var n;return K(this,function(r){switch(r.label){case 0:t&&(this.heapArray=zd([],Rd(t),!1)),n=e.getParentIndexOf(this.length-1),r.label=1;case 1:return n>=0?[4,this._sortNodeDown(n)]:[3,4];case 2:r.sent(),r.label=3;case 3:return--n,[3,1];case 4:return this._applyLimit(),[2]}})})},e.prototype.isEmpty=function(){return this.length===0},e.prototype.leafs=function(){if(this.heapArray.length===0)return[];var t=e.getParentIndexOf(this.heapArray.length-1);return this.heapArray.slice(t+1)},Object.defineProperty(e.prototype,`length`,{get:function(){return this.heapArray.length},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,`limit`,{get:function(){return this._limit},set:function(e){this._limit=~~e,this._applyLimit()},enumerable:!1,configurable:!0}),e.prototype.peek=function(){return this.heapArray[0]},e.prototype.pop=function(){return G(this,void 0,void 0,function(){var e;return K(this,function(t){return e=this.heapArray.pop(),this.length>0&&e!==void 0?[2,this.replace(e)]:[2,e]})})},e.prototype.push=function(){var e=[...arguments];return G(this,void 0,void 0,function(){return K(this,function(t){return e.length<1?[2,!1]:e.length===1?[2,this.add(e[0])]:[2,this.addAll(e)]})})},e.prototype.pushpop=function(e){return G(this,void 0,void 0,function(){var t;return K(this,function(n){switch(n.label){case 0:return[4,this.compare(this.heapArray[0],e)];case 1:return n.sent()<0?(t=Rd([this.heapArray[0],e],2),e=t[0],this.heapArray[0]=t[1],[4,this._sortNodeDown(0)]):[3,3];case 2:n.sent(),n.label=3;case 3:return[2,e]}})})},e.prototype.remove=function(t){return G(this,arguments,void 0,function(t,n){var r,i,a,o=this;return n===void 0&&(n=e.defaultIsEqual),K(this,function(s){switch(s.label){case 0:return this.heapArray.length?t===void 0?[4,this.pop()]:[3,2]:[2,!1];case 1:return s.sent(),[2,!0];case 2:r=[0],s.label=3;case 3:return r.length?(i=r.shift(),[4,n(this.heapArray[i],t)]):[3,13];case 4:return s.sent()?i===0?[4,this.pop()]:[3,6]:[3,11];case 5:return s.sent(),[3,10];case 6:return i===this.heapArray.length-1?(this.heapArray.pop(),[3,10]):[3,7];case 7:return this.heapArray.splice(i,1,this.heapArray.pop()),[4,this._sortNodeUp(i)];case 8:return s.sent(),[4,this._sortNodeDown(i)];case 9:s.sent(),s.label=10;case 10:return[2,!0];case 11:a=e.getChildrenIndexOf(i).filter(function(e){return e<o.heapArray.length}),r.push.apply(r,zd([],Rd(a),!1)),s.label=12;case 12:return[3,3];case 13:return[2,!1]}})})},e.prototype.replace=function(e){return G(this,void 0,void 0,function(){var t;return K(this,function(n){switch(n.label){case 0:return t=this.heapArray[0],this.heapArray[0]=e,[4,this._sortNodeDown(0)];case 1:return n.sent(),[2,t]}})})},e.prototype.size=function(){return this.length},e.prototype.top=function(){return G(this,arguments,void 0,function(e){return e===void 0&&(e=1),K(this,function(t){return this.heapArray.length===0||e<=0?[2,[]]:this.heapArray.length===1||e===1?[2,[this.heapArray[0]]]:e>=this.heapArray.length?[2,zd([],Rd(this.heapArray),!1)]:[2,this._topN_push(~~e)]})})},e.prototype.toArray=function(){return zd([],Rd(this.heapArray),!1)},e.prototype.toString=function(){return this.heapArray.toString()},e.prototype.get=function(e){return this.heapArray[e]},e.prototype.getChildrenOf=function(t){var n=this;return e.getChildrenIndexOf(t).map(function(e){return n.heapArray[e]}).filter(function(e){return e!==void 0})},e.prototype.getParentOf=function(t){var n=e.getParentIndexOf(t);return this.heapArray[n]},e.prototype[Symbol.iterator]=function(){return K(this,function(e){switch(e.label){case 0:return this.length?[4,this.pop()]:[3,2];case 1:return e.sent(),[3,0];case 2:return[2]}})},e.prototype.iterator=function(){return this},e.prototype._applyLimit=function(){if(this._limit&&this._limit<this.heapArray.length)for(var e=this.heapArray.length-this._limit;e;)this.heapArray.pop(),--e},e.prototype._bottomN_push=function(t){return G(this,void 0,void 0,function(){var n,r,i,a,o,s,o;return K(this,function(c){switch(c.label){case 0:return n=new e(this.compare),n.limit=t,n.heapArray=this.heapArray.slice(-t),[4,n.init()];case 1:for(c.sent(),r=this.heapArray.length-1-t,i=e.getParentIndexOf(r),a=[],o=r;o>i;--o)a.push(o);s=this.heapArray,c.label=2;case 2:return a.length?(o=a.shift(),[4,this.compare(s[o],n.peek())]):[3,6];case 3:return c.sent()>0?[4,n.replace(s[o])]:[3,5];case 4:c.sent(),o%2&&a.push(e.getParentIndexOf(o)),c.label=5;case 5:return[3,2];case 6:return[2,n.toArray()]}})})},e.prototype._moveNode=function(e,t){var n=this.heapArray[e];this.heapArray[e]=this.heapArray[t],this.heapArray[t]=n},e.prototype._sortNodeDown=function(e){return G(this,void 0,void 0,function(){var t,n,r,i,a,o,s;return K(this,function(c){switch(c.label){case 0:t=this.heapArray.length,n=e,r=this.heapArray[e],i=2*e+1,c.label=1;case 1:return i<t?(a=i+1,s=a>=t,s?[3,3]:[4,this.compare(this.heapArray[i],this.heapArray[a])]):[3,5];case 2:s=c.sent()<0,c.label=3;case 3:return o=s?i:a,[4,this.compare(this.heapArray[o],r)];case 4:if(c.sent()<0)this.heapArray[e]=this.heapArray[o],e=o,i=2*e+1;else return[3,5];return[3,1];case 5:return e!==n&&(this.heapArray[e]=r),[2]}})})},e.prototype._sortNodeUp=function(t){return G(this,void 0,void 0,function(){var n,r,i;return K(this,function(a){switch(a.label){case 0:n=this.heapArray[t],r=t,a.label=1;case 1:return t>0?(i=e.getParentIndexOf(t),[4,this.compare(n,this.heapArray[i])]):[3,3];case 2:if(a.sent()<0)this.heapArray[t]=this.heapArray[i],t=i;else return[3,3];return[3,1];case 3:return t!==r&&(this.heapArray[t]=n),[2]}})})},e.prototype._topN_push=function(t){return G(this,void 0,void 0,function(){var n,r,i,a;return K(this,function(o){switch(o.label){case 0:n=new e(this._invertedCompare),n.limit=t,r=[0],i=this.heapArray,o.label=1;case 1:return r.length?(a=r.shift(),a<i.length?n.length<t?[4,n.push(i[a])]:[3,3]:[3,6]):[3,7];case 2:return o.sent(),r.push.apply(r,zd([],Rd(e.getChildrenIndexOf(a)),!1)),[3,6];case 3:return[4,this.compare(i[a],n.peek())];case 4:return o.sent()<0?[4,n.replace(i[a])]:[3,6];case 5:o.sent(),r.push.apply(r,zd([],Rd(e.getChildrenIndexOf(a)),!1)),o.label=6;case 6:return[3,1];case 7:return[2,n.toArray()]}})})},e.prototype._topN_fill=function(t){return G(this,void 0,void 0,function(){var n,r,i,a,o,o;return K(this,function(s){switch(s.label){case 0:return n=this.heapArray,r=new e(this._invertedCompare),r.limit=t,r.heapArray=n.slice(0,t),[4,r.init()];case 1:for(s.sent(),i=e.getParentIndexOf(t-1)+1,a=[],o=i;o<t;++o)a.push.apply(a,zd([],Rd(e.getChildrenIndexOf(o).filter(function(e){return e<n.length})),!1));(t-1)%2&&a.push(t),s.label=2;case 2:return a.length?(o=a.shift(),o<n.length?[4,this.compare(n[o],r.peek())]:[3,5]):[3,6];case 3:return s.sent()<0?[4,r.replace(n[o])]:[3,5];case 4:s.sent(),a.push.apply(a,zd([],Rd(e.getChildrenIndexOf(o)),!1)),s.label=5;case 5:return[3,2];case 6:return[2,r.toArray()]}})})},e.prototype._topN_heap=function(e){return G(this,void 0,void 0,function(){var t,n,r,i,a;return K(this,function(o){switch(o.label){case 0:t=this.clone(),n=[],r=0,o.label=1;case 1:return r<e?(a=(i=n).push,[4,t.pop()]):[3,4];case 2:a.apply(i,[o.sent()]),o.label=3;case 3:return++r,[3,1];case 4:return[2,n]}})})},e.prototype._topIdxOf=function(e){return G(this,void 0,void 0,function(){var t,n,r,i;return K(this,function(a){switch(a.label){case 0:if(!e.length)return[2,-1];t=0,n=e[t],r=1,a.label=1;case 1:return r<e.length?[4,this.compare(e[r],n)]:[3,4];case 2:i=a.sent(),i<0&&(t=r,n=e[r]),a.label=3;case 3:return++r,[3,1];case 4:return[2,t]}})})},e.prototype._topOf=function(){var t=[...arguments];return G(this,void 0,void 0,function(){var n;return K(this,function(r){switch(r.label){case 0:return n=new e(this.compare),[4,n.init(t)];case 1:return r.sent(),[2,n.peek()]}})})},e})();var Vd=function(e,t){var n={label:0,sent:function(){if(a[0]&1)throw a[1];return a[1]},trys:[],ops:[]},r,i,a,o=Object.create((typeof Iterator==`function`?Iterator:Object).prototype);return o.next=s(0),o.throw=s(1),o.return=s(2),typeof Symbol==`function`&&(o[Symbol.iterator]=function(){return this}),o;function s(e){return function(t){return c([e,t])}}function c(s){if(r)throw TypeError(`Generator is already executing.`);for(;o&&(o=0,s[0]&&(n=0)),n;)try{if(r=1,i&&(a=s[0]&2?i.return:s[0]?i.throw||((a=i.return)&&a.call(i),0):i.next)&&!(a=a.call(i,s[1])).done)return a;switch(i=0,a&&(s=[s[0]&2,a.value]),s[0]){case 0:case 1:a=s;break;case 4:return n.label++,{value:s[1],done:!1};case 5:n.label++,i=s[1],s=[0];continue;case 7:s=n.ops.pop(),n.trys.pop();continue;default:if((a=n.trys,!(a=a.length>0&&a[a.length-1]))&&(s[0]===6||s[0]===2)){n=0;continue}if(s[0]===3&&(!a||s[1]>a[0]&&s[1]<a[3])){n.label=s[1];break}if(s[0]===6&&n.label<a[1]){n.label=a[1],a=s;break}if(a&&n.label<a[2]){n.label=a[2],n.ops.push(s);break}a[2]&&n.ops.pop(),n.trys.pop();continue}s=t.call(e,n)}catch(e){s=[6,e],i=0}finally{r=a=0}if(s[0]&5)throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}},Hd=function(e,t){var n=typeof Symbol==`function`&&e[Symbol.iterator];if(!n)return e;var r=n.call(e),i,a=[],o;try{for(;(t===void 0||t-- >0)&&!(i=r.next()).done;)a.push(i.value)}catch(e){o={error:e}}finally{try{i&&!i.done&&(n=r.return)&&n.call(r)}finally{if(o)throw o.error}}return a},Ud=function(e,t,n){if(n||arguments.length===2)for(var r=0,i=t.length,a;r<i;r++)(a||!(r in t))&&(a||=Array.prototype.slice.call(t,0,r),a[r]=t[r]);return e.concat(a||Array.prototype.slice.call(t))},Wd=function(){function e(t){t===void 0&&(t=e.minComparator);var n=this;this.compare=t,this.heapArray=[],this._limit=0,this.offer=this.add,this.element=this.peek,this.poll=this.pop,this.removeAll=this.clear,this._invertedCompare=function(e,t){return-1*n.compare(e,t)}}return e.getChildrenIndexOf=function(e){return[e*2+1,e*2+2]},e.getParentIndexOf=function(e){return e<=0?-1:e-1>>1},e.getSiblingIndexOf=function(e){return e<=0?-1:e+(e%2?1:-1)},e.minComparator=function(e,t){return e>t?1:e<t?-1:0},e.maxComparator=function(e,t){return t>e?1:t<e?-1:0},e.minComparatorNumber=function(e,t){return e-t},e.maxComparatorNumber=function(e,t){return t-e},e.defaultIsEqual=function(e,t){return e===t},e.print=function(t){function n(t){var n=e.getParentIndexOf(t);return Math.floor(Math.log2(n+1))}function r(e,t){for(var n=``;t>0;--t)n+=e;return n}for(var i=0,a=[],o=n(t.length-1)+2,s=0;i<t.length;){var c=n(i)+1;i===0&&(c=0);var l=String(t.get(i));l.length>s&&(s=l.length),a[c]=a[c]||[],a[c].push(l),i+=1}return a.map(function(e,t){var n=2**(o-t)-1;return r(` `,Math.floor(n/2)*s)+e.map(function(e){var t=(s-e.length)/2;return r(` `,Math.ceil(t))+e+r(` `,Math.floor(t))}).join(r(` `,n*s))}).join(`
43
- `)},e.heapify=function(t,n){var r=new e(n);return r.heapArray=t,r.init(),r},e.heappop=function(t,n){var r=new e(n);return r.heapArray=t,r.pop()},e.heappush=function(t,n,r){var i=new e(r);i.heapArray=t,i.push(n)},e.heappushpop=function(t,n,r){var i=new e(r);return i.heapArray=t,i.pushpop(n)},e.heapreplace=function(t,n,r){var i=new e(r);return i.heapArray=t,i.replace(n)},e.heaptop=function(t,n,r){n===void 0&&(n=1);var i=new e(r);return i.heapArray=t,i.top(n)},e.heapbottom=function(t,n,r){n===void 0&&(n=1);var i=new e(r);return i.heapArray=t,i.bottom(n)},e.nlargest=function(t,n,r){var i=new e(r);return i.heapArray=Ud([],Hd(n),!1),i.init(),i.top(t)},e.nsmallest=function(t,n,r){var i=new e(r);return i.heapArray=Ud([],Hd(n),!1),i.init(),i.bottom(t)},e.prototype.add=function(e){return this._sortNodeUp(this.heapArray.push(e)-1),this._applyLimit(),!0},e.prototype.addAll=function(e){var t,n=this.length;(t=this.heapArray).push.apply(t,Ud([],Hd(e),!1));for(var r=this.length;n<r;++n)this._sortNodeUp(n);return this._applyLimit(),!0},e.prototype.bottom=function(e){return e===void 0&&(e=1),this.heapArray.length===0||e<=0?[]:this.heapArray.length===1?[this.heapArray[0]]:e>=this.heapArray.length?Ud([],Hd(this.heapArray),!1):this._bottomN_push(~~e)},e.prototype.check=function(){var e=this;return this.heapArray.find(function(t,n){return!!e.getChildrenOf(n).find(function(n){return e.compare(t,n)>0})})},e.prototype.clear=function(){this.heapArray=[]},e.prototype.clone=function(){var t=new e(this.comparator());return t.heapArray=this.toArray(),t._limit=this._limit,t},e.prototype.comparator=function(){return this.compare},e.prototype.contains=function(t,n){return n===void 0&&(n=e.defaultIsEqual),this.indexOf(t,n)!==-1},e.prototype.init=function(t){t&&(this.heapArray=Ud([],Hd(t),!1));for(var n=e.getParentIndexOf(this.length-1);n>=0;--n)this._sortNodeDown(n);this._applyLimit()},e.prototype.isEmpty=function(){return this.length===0},e.prototype.indexOf=function(t,n){if(n===void 0&&(n=e.defaultIsEqual),this.heapArray.length===0)return-1;for(var r=[],i=0;i<this.heapArray.length;){var a=this.heapArray[i];if(n(a,t))return i;this.compare(a,t)<=0&&r.push.apply(r,Ud([],Hd(e.getChildrenIndexOf(i)),!1)),i=r.shift()||this.heapArray.length}return-1},e.prototype.indexOfEvery=function(t,n){if(n===void 0&&(n=e.defaultIsEqual),this.heapArray.length===0)return[];for(var r=[],i=[],a=0;a<this.heapArray.length;){var o=this.heapArray[a];n(o,t)?(i.push(a),r.push.apply(r,Ud([],Hd(e.getChildrenIndexOf(a)),!1))):this.compare(o,t)<=0&&r.push.apply(r,Ud([],Hd(e.getChildrenIndexOf(a)),!1)),a=r.shift()||this.heapArray.length}return i},e.prototype.leafs=function(){if(this.heapArray.length===0)return[];var t=e.getParentIndexOf(this.heapArray.length-1);return this.heapArray.slice(t+1)},Object.defineProperty(e.prototype,`length`,{get:function(){return this.heapArray.length},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,`limit`,{get:function(){return this._limit},set:function(e){e<0||isNaN(e)?this._limit=0:this._limit=~~e,this._applyLimit()},enumerable:!1,configurable:!0}),e.prototype.setLimit=function(e){return this.limit=e,e<0||isNaN(e)?NaN:this._limit},e.prototype.peek=function(){return this.heapArray[0]},e.prototype.pop=function(){var e=this.heapArray.pop();return this.length>0&&e!==void 0?this.replace(e):e},e.prototype.push=function(){var e=[...arguments];return e.length<1?!1:e.length===1?this.add(e[0]):this.addAll(e)},e.prototype.pushpop=function(e){var t;return this.compare(this.heapArray[0],e)<0&&(t=Hd([this.heapArray[0],e],2),e=t[0],this.heapArray[0]=t[1],this._sortNodeDown(0)),e},e.prototype.remove=function(t,n){var r=this;if(n===void 0&&(n=e.defaultIsEqual),!this.heapArray.length)return!1;if(t===void 0)return this.pop(),!0;for(var i=[0];i.length;){var a=i.shift();if(n(this.heapArray[a],t))return a===0?this.pop():a===this.heapArray.length-1?this.heapArray.pop():(this.heapArray.splice(a,1,this.heapArray.pop()),this._sortNodeUp(a),this._sortNodeDown(a)),!0;if(this.compare(this.heapArray[a],t)<=0){var o=e.getChildrenIndexOf(a).filter(function(e){return e<r.heapArray.length});i.push.apply(i,Ud([],Hd(o),!1))}}return!1},e.prototype.replace=function(e){var t=this.heapArray[0];return this.heapArray[0]=e,this._sortNodeDown(0),t},e.prototype.size=function(){return this.length},e.prototype.top=function(e){return e===void 0&&(e=1),this.heapArray.length===0||e<=0?[]:this.heapArray.length===1||e===1?[this.heapArray[0]]:e>=this.heapArray.length?Ud([],Hd(this.heapArray),!1):this._topN_push(~~e)},e.prototype.toArray=function(){return Ud([],Hd(this.heapArray),!1)},e.prototype.toString=function(){return this.heapArray.toString()},e.prototype.get=function(e){return this.heapArray[e]},e.prototype.getChildrenOf=function(t){var n=this;return e.getChildrenIndexOf(t).map(function(e){return n.heapArray[e]}).filter(function(e){return e!==void 0})},e.prototype.getParentOf=function(t){var n=e.getParentIndexOf(t);return this.heapArray[n]},e.prototype[Symbol.iterator]=function(){return Vd(this,function(e){switch(e.label){case 0:return this.length?[4,this.pop()]:[3,2];case 1:return e.sent(),[3,0];case 2:return[2]}})},e.prototype.iterator=function(){return this.toArray()},e.prototype._applyLimit=function(){if(this._limit>0&&this._limit<this.heapArray.length)for(var e=this.heapArray.length-this._limit;e;)this.heapArray.pop(),--e},e.prototype._bottomN_push=function(t){var n=new e(this.compare);n.limit=t,n.heapArray=this.heapArray.slice(-t),n.init();for(var r=this.heapArray.length-1-t,i=e.getParentIndexOf(r),a=[],o=r;o>i;--o)a.push(o);for(var s=this.heapArray;a.length;){var o=a.shift();this.compare(s[o],n.peek())>0&&(n.replace(s[o]),o%2&&a.push(e.getParentIndexOf(o)))}return n.toArray()},e.prototype._moveNode=function(e,t){var n=this.heapArray[e];this.heapArray[e]=this.heapArray[t],this.heapArray[t]=n},e.prototype._sortNodeDown=function(e){for(var t=this.heapArray.length,n=e,r=this.heapArray[e],i=2*e+1;i<t;){var a=i+1,o=a>=t||this.compare(this.heapArray[i],this.heapArray[a])<0?i:a;if(this.compare(this.heapArray[o],r)<0)this.heapArray[e]=this.heapArray[o],e=o,i=2*e+1;else break}e!==n&&(this.heapArray[e]=r)},e.prototype._sortNodeUp=function(t){for(var n=this.heapArray[t],r=t;t>0;){var i=e.getParentIndexOf(t);if(this.compare(n,this.heapArray[i])<0)this.heapArray[t]=this.heapArray[i],t=i;else break}t!==r&&(this.heapArray[t]=n)},e.prototype._topN_push=function(t){var n=new e(this._invertedCompare);n.limit=t;for(var r=[0],i=this.heapArray;r.length;){var a=r.shift();a<i.length&&(n.length<t?(n.push(i[a]),r.push.apply(r,Ud([],Hd(e.getChildrenIndexOf(a)),!1))):this.compare(i[a],n.peek())<0&&(n.replace(i[a]),r.push.apply(r,Ud([],Hd(e.getChildrenIndexOf(a)),!1))))}return n.toArray()},e.prototype._topN_fill=function(t){var n=this.heapArray,r=new e(this._invertedCompare);r.limit=t,r.heapArray=n.slice(0,t),r.init();for(var i=e.getParentIndexOf(t-1)+1,a=[],o=i;o<t;++o)a.push.apply(a,Ud([],Hd(e.getChildrenIndexOf(o).filter(function(e){return e<n.length})),!1));for((t-1)%2&&a.push(t);a.length;){var o=a.shift();o<n.length&&this.compare(n[o],r.peek())<0&&(r.replace(n[o]),a.push.apply(a,Ud([],Hd(e.getChildrenIndexOf(o)),!1)))}return r.toArray()},e.prototype._topN_heap=function(e){for(var t=this.clone(),n=[],r=0;r<e;++r)n.push(t.pop());return n},e.prototype._topIdxOf=function(e){if(!e.length)return-1;for(var t=0,n=e[t],r=1;r<e.length;++r)this.compare(e[r],n)<0&&(t=r,n=e[r]);return t},e.prototype._topOf=function(){var t=[...arguments],n=new e(this.compare);return n.init(t),n.peek()},e}(),Gd=class{#e;#t=new Map;#n;#r=0;#i;constructor(e,t){this.#e=e,this.#n=t}async size(){return this.#i??=await this.#e.size(),this.#i}async read(e,t,n){let r=Number(t),i=this.#t.get(e);if(i!=null&&i.byteLength>=r)return i.byteLength===r?i:i.subarray(0,r);let a=await this.#e.read(e,t,n);if(this.#r+a.byteLength<=this.#n){let t=new Uint8Array(a);return this.#t.set(e,t),this.#r+=t.byteLength,t}return a}};const Kd=typeof DataView.prototype.getBigUint64==`function`?DataView.prototype.getBigUint64:function(e,t){let n=t===!0?this.getUint32(e,t):this.getUint32(e+4,t),r=t===!0?this.getUint32(e+4,t):this.getUint32(e,t);return BigInt(r)<<32n|BigInt(n)},qd=new TextDecoder;var Jd=class{#e;#t;offset;constructor(e,t=0){this.#e=e,this.#t=new Uint8Array(e.buffer,e.byteOffset,e.byteLength),this.offset=t}reset(e,t=0){this.#e=e,this.#t=new Uint8Array(e.buffer,e.byteOffset,e.byteLength),this.offset=t}bytesRemaining(){return this.#t.length-this.offset}uint8(){let e=this.#e.getUint8(this.offset);return this.offset+=1,e}uint16(){let e=this.#e.getUint16(this.offset,!0);return this.offset+=2,e}uint32(){let e=this.#e.getUint32(this.offset,!0);return this.offset+=4,e}uint64(){let e=Kd.call(this.#e,this.offset,!0);return this.offset+=8,e}string(){let e=this.uint32();if(e===0)return``;if(e>this.bytesRemaining())throw Error(`String length ${e} exceeds bounds of buffer`);return qd.decode(this.u8ArrayBorrow(e))}keyValuePairs(e,t){let n=this.uint32();if(this.offset+n>this.#e.byteLength)throw Error(`Key-value pairs length ${n} exceeds bounds of buffer`);let r=[],i=this.offset+n;try{for(;this.offset<i;)r.push([e(this),t(this)])}catch(e){throw Error(`Error reading key-value pairs: ${e.message}`)}if(this.offset!==i)throw Error(`Key-value pairs length (${this.offset-i+n}) greater than expected (${n})`);return r}map(e,t){let n=this.uint32();if(this.offset+n>this.#e.byteLength)throw Error(`Map length ${n} exceeds bounds of buffer`);let r=new Map,i=this.offset+n;try{for(;this.offset<i;){let n=e(this),i=t(this),a=r.get(n);if(a!=null)throw Error(`Duplicate key ${String(n)} (${String(a)} vs ${String(i)})`);r.set(n,i)}}catch(e){throw Error(`Error reading map: ${e.message}`)}if(this.offset!==i)throw Error(`Map length (${this.offset-i+n}) greater than expected (${n})`);return r}u8ArrayBorrow(e){if(!(e>=0&&e<=this.bytesRemaining()))throw Error(`Byte array length ${e} exceeds bounds of buffer`);let t=this.#t.subarray(this.offset,this.offset+e);return this.offset+=e,t}u8ArrayCopy(e){if(!(e>=0&&e<=this.bytesRemaining()))throw Error(`Byte array length ${e} exceeds bounds of buffer`);let t=this.#t.slice(this.offset,this.offset+e);return this.offset+=e,t}};const Yd=Object.freeze([137,77,67,65,80,48,13,10]);var Xd;(function(e){e[e.MIN=1]=`MIN`,e[e.HEADER=1]=`HEADER`,e[e.FOOTER=2]=`FOOTER`,e[e.SCHEMA=3]=`SCHEMA`,e[e.CHANNEL=4]=`CHANNEL`,e[e.MESSAGE=5]=`MESSAGE`,e[e.CHUNK=6]=`CHUNK`,e[e.MESSAGE_INDEX=7]=`MESSAGE_INDEX`,e[e.CHUNK_INDEX=8]=`CHUNK_INDEX`,e[e.ATTACHMENT=9]=`ATTACHMENT`,e[e.ATTACHMENT_INDEX=10]=`ATTACHMENT_INDEX`,e[e.STATISTICS=11]=`STATISTICS`,e[e.METADATA=12]=`METADATA`,e[e.METADATA_INDEX=13]=`METADATA_INDEX`,e[e.SUMMARY_OFFSET=14]=`SUMMARY_OFFSET`,e[e.DATA_END=15]=`DATA_END`,e[e.MAX=15]=`MAX`})(Xd||={});function Zd(e){if(e.bytesRemaining()<Yd.length)return;let t=e.u8ArrayBorrow(Yd.length);if(!Yd.every((e,n)=>e===t[n]))throw Error(`Expected MCAP magic '${Yd.map(e=>e.toString(16).padStart(2,`0`)).join(` `)}', found '${Array.from(t,(e,n)=>t[n].toString(16).padStart(2,`0`)).join(` `)}'`);return{specVersion:`0`}}function Qd(e,t=!1){if(e.bytesRemaining()<9)return;let n=e.offset,r=e.uint8(),i=e.uint64();if(i>2**53-1)throw Error(`Record content length ${i} is too large`);let a=Number(i);if(e.bytesRemaining()<a){e.offset=n;return}let o;switch(r){case Xd.HEADER:o=ef(e,a);break;case Xd.FOOTER:o=tf(e,a);break;case Xd.SCHEMA:o=nf(e,a);break;case Xd.CHANNEL:o=rf(e,a);break;case Xd.MESSAGE:o=af(e,a);break;case Xd.CHUNK:o=of(e,a);break;case Xd.MESSAGE_INDEX:o=sf(e,a);break;case Xd.CHUNK_INDEX:o=cf(e,a);break;case Xd.ATTACHMENT:o=lf(e,a,t);break;case Xd.ATTACHMENT_INDEX:o=uf(e,a);break;case Xd.STATISTICS:o=df(e,a);break;case Xd.METADATA:o=ff(e,a);break;case Xd.METADATA_INDEX:o=pf(e,a);break;case Xd.SUMMARY_OFFSET:o=mf(e,a);break;case Xd.DATA_END:o=hf(e,a);break;default:o=$d(e,a,r);break}return e.offset=n+9+a,o}function $d(e,t,n){return{type:`Unknown`,opcode:n,data:e.u8ArrayBorrow(t)}}function ef(e,t){let n=e.offset,r=e.string(),i=e.string();return e.offset=n+t,{type:`Header`,profile:r,library:i}}function tf(e,t){let n=e.offset,r=e.uint64(),i=e.uint64(),a=e.uint32();return e.offset=n+t,{type:`Footer`,summaryStart:r,summaryOffsetStart:i,summaryCrc:a}}function nf(e,t){let n=e.offset,r=e.uint16(),i=e.string(),a=e.string(),o=e.uint32();if(t-(e.offset-n)<o)throw Error(`Schema data length ${o} exceeds bounds of record`);let s=e.u8ArrayCopy(o);return e.offset=n+t,{type:`Schema`,id:r,encoding:a,name:i,data:s}}function rf(e,t){let n=e.offset,r=e.uint16(),i=e.uint16(),a=e.string(),o=e.string(),s=e.map(e=>e.string(),e=>e.string());return e.offset=n+t,{type:`Channel`,id:r,schemaId:i,topic:a,messageEncoding:o,metadata:s}}function af(e,t){if(t<22)throw Error(`Message record length ${t} is less than 22 bytes`);return{type:`Message`,channelId:e.uint16(),sequence:e.uint32(),logTime:e.uint64(),publishTime:e.uint64(),data:e.u8ArrayCopy(t-22)}}function of(e,t){let n=e.offset,r=e.uint64(),i=e.uint64(),a=e.uint64(),o=e.uint32(),s=e.string(),c=Number(e.uint64());if(c+(e.offset-n)>t)throw Error(`Chunk records length exceeds remaining record size`);let l=e.u8ArrayCopy(c);return e.offset=n+t,{type:`Chunk`,messageStartTime:r,messageEndTime:i,compression:s,uncompressedSize:a,uncompressedCrc:o,records:l}}function sf(e,t){let n=e.offset,r=e.uint16(),i=e.keyValuePairs(e=>e.uint64(),e=>e.uint64());return e.offset=n+t,{type:`MessageIndex`,channelId:r,records:i}}function cf(e,t){let n=e.offset,r=e.uint64(),i=e.uint64(),a=e.uint64(),o=e.uint64(),s=e.map(e=>e.uint16(),e=>e.uint64()),c=e.uint64(),l=e.string(),u=e.uint64(),d=e.uint64();return e.offset=n+t,{type:`ChunkIndex`,messageStartTime:r,messageEndTime:i,chunkStartOffset:a,chunkLength:o,messageIndexOffsets:s,messageIndexLength:c,compression:l,compressedSize:u,uncompressedSize:d}}function lf(e,t,n){let r=e.offset,i=e.uint64(),a=e.uint64(),o=e.string(),s=e.string(),c=e.uint64();if(BigInt(e.offset)+c>2**53-1)throw Error(`Attachment too large: ${c}`);if(e.offset+Number(c)+4>r+t)throw Error(`Attachment data length ${c} exceeds bounds of record`);let l=e.u8ArrayCopy(Number(c)),u=e.offset-r,d=e.uint32();if(n&&d!==0){e.offset=r;let t=Ld(e.u8ArrayBorrow(u));if(e.offset=r+u+4,t!==d)throw Error(`Attachment CRC32 mismatch: expected ${d}, actual ${t}`)}return e.offset=r+t,{type:`Attachment`,logTime:i,createTime:a,name:o,mediaType:s,data:l}}function uf(e,t){let n=e.offset,r=e.uint64(),i=e.uint64(),a=e.uint64(),o=e.uint64(),s=e.uint64(),c=e.string(),l=e.string();return e.offset=n+t,{type:`AttachmentIndex`,offset:r,length:i,logTime:a,createTime:o,dataSize:s,name:c,mediaType:l}}function df(e,t){let n=e.offset,r=e.uint64(),i=e.uint16(),a=e.uint32(),o=e.uint32(),s=e.uint32(),c=e.uint32(),l=e.uint64(),u=e.uint64(),d=e.map(e=>e.uint16(),e=>e.uint64());return e.offset=n+t,{type:`Statistics`,messageCount:r,schemaCount:i,channelCount:a,attachmentCount:o,metadataCount:s,chunkCount:c,messageStartTime:l,messageEndTime:u,channelMessageCounts:d}}function ff(e,t){let n=e.offset,r=e.string(),i=e.map(e=>e.string(),e=>e.string());return e.offset=n+t,{type:`Metadata`,metadata:i,name:r}}function pf(e,t){let n=e.offset,r=e.uint64(),i=e.uint64(),a=e.string();return e.offset=n+t,{type:`MetadataIndex`,offset:r,length:i,name:a}}function mf(e,t){let n=e.offset,r=e.uint8(),i=e.uint64(),a=e.uint64();return e.offset=n+t,{type:`SummaryOffset`,groupOpcode:r,groupStart:i,groupLength:a}}function hf(e,t){let n=e.offset,r=e.uint32();return e.offset=n+t,{type:`DataEnd`,dataSectionCrc:r}}function gf(e,t,n){let r=0,i=e.length;if(i===0)return 0;let a=n(t);for(;r<i;){let t=r+i>>>1;n(e[t][0])<a?r=t+1:i=t}return i}function _f(e,t,n){let r=0,i=e.length;if(i===0)return 0;let a=n(t);for(;r<i;){let t=r+i>>>1;n(e[t][0])<=a?r=t+1:i=t}return i}var vf=class{chunkIndex;#e;#t;#n;#r;#i;#a;#o=0;constructor(e){if(this.chunkIndex=e.chunkIndex,this.#e=e.relevantChannels,this.#t=e.startingAt,this.#n=e.endingAt,this.#r=e.reverse,this.#i=e.readFullMessageIndexRange??!1,this.chunkIndex.messageIndexLength===0n&&(this.chunkIndex.messageStartTime!==0n||this.chunkIndex.messageEndTime!==0n))throw Error(`Encountered a chunk index without message indexes and non-zero start and end times`)}compare(e){if(this.#r!==e.#r)throw Error(`Cannot compare a reversed ChunkCursor to a non-reversed ChunkCursor`);let t=Number(this.#s()-e.#s());return t===0&&(t=Number(this.chunkIndex.chunkStartOffset-e.chunkIndex.chunkStartOffset)),this.#r?-t:t}hasMoreMessages(){if(this.#a==null)throw Error(`loadMessageIndexes() must be called before hasMore()`);return this.#o<this.#a.length}popMessage(){if(this.#a==null)throw Error(`loadMessageIndexes() must be called before popMessage()`);if(this.#o>=this.#a.length)throw Error(`Unexpected popMessage() call when no more messages are available, in chunk at offset ${this.chunkIndex.chunkStartOffset}`);return this.#a[this.#o++]}hasMessageIndexes(){return this.#a!=null}async loadMessageIndexes(e,t){let n=this.#r,r,i,a=this.#i;for(let[e,t]of this.chunkIndex.messageIndexOffsets)(r==null||t<r)&&(r=t),(a||!this.#e||this.#e.has(e))&&(i==null||t<i)&&(i=t);if(r==null||i==null){this.#a=[];return}let o=r+this.chunkIndex.messageIndexLength,s=await e.read(i,o-i,t),c=new Jd(new DataView(s.buffer,s.byteOffset,s.byteLength)),l=[],u;for(;u=Qd(c,!0);)u.type===`MessageIndex`&&(u.records.length===0||this.#e&&!this.#e.has(u.channelId)||l.push(u.records));if(c.bytesRemaining()!==0)throw Error(`${c.bytesRemaining()} bytes remaining in message index section`);if(this.#a=l.flat().sort(([e,t],[n,r])=>{let i=Number(e-n);return i===0&&(i=Number(t-r)),i}),n&&this.#a.reverse(),this.#a.length===0)return;let[d]=this.#a[0];if(d<this.chunkIndex.messageStartTime)throw Error(`Chunk at offset ${this.chunkIndex.chunkStartOffset} contains a message with logTime (${d}) earlier than chunk messageStartTime (${this.chunkIndex.messageStartTime})`);let[f]=this.#a[this.#a.length-1];if(f>this.chunkIndex.messageEndTime)throw Error(`Chunk at offset ${this.chunkIndex.chunkStartOffset} contains a message with logTime (${f}) later than chunk messageEndTime (${this.chunkIndex.messageEndTime})`);let p=n?this.#n:this.#t,m=n?this.#t:this.#n,h=n?e=>-e:e=>e,g,_;p!=null&&(g=gf(this.#a,p,h)),m!=null&&(_=_f(this.#a,m,h)),(g!=null||_!=null)&&(this.#a=this.#a.slice(g,_))}#s(){return this.#a!=null&&this.#a.length>0&&this.#o<this.#a.length?this.#a[this.#o][0]:this.#r?this.chunkIndex.messageEndTime:this.chunkIndex.messageStartTime}},yf=class e{chunkIndexes;attachmentIndexes;metadataIndexes=[];channelsById;schemasById;statistics;summaryOffsetsByOpcode;header;footer;dataEndOffset;dataSectionCrc;#e;#t;#n;#r;#i;#a;#o;constructor(e){this.#e=e.readable,this.chunkIndexes=e.chunkIndexes,this.attachmentIndexes=e.attachmentIndexes,this.metadataIndexes=e.metadataIndexes,this.statistics=e.statistics,this.#n=e.decompressHandlers,this.channelsById=e.channelsById,this.schemasById=e.schemasById,this.summaryOffsetsByOpcode=e.summaryOffsetsByOpcode,this.header=e.header,this.footer=e.footer,this.dataEndOffset=e.dataEndOffset,this.dataSectionCrc=e.dataSectionCrc;let t=e.messageIndexCacheSizeBytes??0;this.#t=t>0?new Gd(this.#e,t):this.#e;for(let t of e.chunkIndexes)(this.#r==null||t.messageStartTime<this.#r)&&(this.#r=t.messageStartTime),(this.#i==null||t.messageEndTime>this.#i)&&(this.#i=t.messageEndTime);for(let t of e.attachmentIndexes)(this.#a==null||t.logTime<this.#a)&&(this.#a=t.logTime),(this.#o==null||t.logTime>this.#o)&&(this.#o=t.logTime)}#s(e){return Error(`${e} [library=${this.header.library}]`)}static async Initialize({readable:t,decompressHandlers:n,messageIndexCacheSizeBytes:r,readOptions:i}){let a=await t.size(),o,s;{let e=await t.read(0n,BigInt(Yd.length+1+8),i),n=new DataView(e.buffer,e.byteOffset,e.byteLength);Zd(new Jd(n));let r=9n+n.getBigUint64(Yd.length+1,!0),a=await t.read(BigInt(Yd.length),r,i);s=BigInt(Yd.length)+r;let c=new Jd(new DataView(a.buffer,a.byteOffset,a.byteLength)),l=Qd(c,!0);if(l?.type!==`Header`)throw Error(`Unable to read header at beginning of file; found ${l?.type??`nothing`}`);if(c.bytesRemaining()!==0)throw Error(`${c.bytesRemaining()} bytes remaining after parsing header`);o=l}function c(e){return Error(`${e} [library=${o.library}]`)}let l,u;{let e=BigInt(Yd.length+1+8+4+4),n=BigInt(29+Yd.length);if(a<e+n)throw c(`File size (${a}) is too small to be valid MCAP`);l=a-n;let r=await t.read(l,n,i);u=new DataView(r.buffer,r.byteOffset,r.byteLength)}try{Zd(new Jd(u,u.byteLength-Yd.length))}catch(e){throw c(e.message)}let d;{let e=new Jd(u),t=Qd(e,!0);if(t?.type!==`Footer`)throw c(`Unable to read footer from end of file (offset ${l}); found ${t?.type??`nothing`}`);if(e.bytesRemaining()!==Yd.length)throw c(`${e.bytesRemaining()-Yd.length} bytes remaining after parsing footer`);d=t}if(d.summaryStart===0n)throw c(`File is not indexed`);let f=new Uint8Array(25);f.set(new Uint8Array(u.buffer,u.byteOffset,f.byteLength));let p=13n,m=d.summaryStart-p;if(m<s)throw c(`Expected DataEnd position (summary start ${d.summaryStart} - ${p} = ${m}) to be after Header end offset (${s})`);let h=await t.read(m,l-m,i);if(d.summaryCrc!==0){let e=Pd();if(e=Fd(e,h.subarray(Number(p))),e=Fd(e,f),e=Id(e),e!==d.summaryCrc)throw c(`Incorrect summary CRC ${e} (expected ${d.summaryCrc})`)}let g=new Jd(new DataView(h.buffer,h.byteOffset,h.byteLength)),_=new Map,v=new Map,y=[],b=[],x=[],S=new Map,C,w,T=!0,E;for(;E=Qd(g,!0);){if(T&&E.type!==`DataEnd`)throw c(`Expected DataEnd record to precede summary section, but found ${E.type}`);switch(T=!1,E.type){case`Schema`:v.set(E.id,E);break;case`Channel`:_.set(E.id,E);break;case`ChunkIndex`:y.push(E);break;case`AttachmentIndex`:b.push(E);break;case`MetadataIndex`:x.push(E);break;case`Statistics`:if(C)throw c(`Duplicate Statistics record`);C=E;break;case`SummaryOffset`:S.set(E.groupOpcode,E);break;case`DataEnd`:w=E.dataSectionCrc===0?void 0:E.dataSectionCrc;break;case`Header`:case`Footer`:case`Message`:case`Chunk`:case`MessageIndex`:case`Attachment`:case`Metadata`:throw c(`${E.type} record not allowed in index section`);case`Unknown`:break}}if(g.bytesRemaining()!==0)throw c(`${g.bytesRemaining()} bytes remaining in index section`);return new e({readable:t,chunkIndexes:y,attachmentIndexes:b,metadataIndexes:x,statistics:C,decompressHandlers:n,channelsById:_,schemasById:v,summaryOffsetsByOpcode:S,header:o,footer:d,dataEndOffset:m,dataSectionCrc:w,messageIndexCacheSizeBytes:r})}async*readMessages(e={}){let{topics:t,reverse:n=!1,validateCrcs:r,readOptions:i}=e,{startingAt:a,endingAt:o}=bf(e,this.#r,this.#i);if(a==null||o==null)return;let s;if(t){s=new Set;for(let e of this.channelsById.values())t.includes(e.topic)&&s.add(e.id)}let c=new Wd((e,t)=>e.compare(t)),l=!0,u,d=this.#t!==this.#e;for(let e of this.chunkIndexes)e.messageStartTime<=o&&e.messageEndTime>=a&&(c.push(new vf({chunkIndex:e,relevantChannels:s,startingAt:a,endingAt:o,reverse:n,readFullMessageIndexRange:d})),l&&u!=null&&(l=e.messageStartTime>=u),u=e.messageEndTime);let f=new Map,p=new Jd(new DataView(new ArrayBuffer(0)));for(let e;e=c.peek();){if(!e.hasMessageIndexes()){await e.loadMessageIndexes(this.#t,i),e.hasMoreMessages()?c.replace(e):c.pop();continue}let t=f.get(e.chunkIndex.chunkStartOffset);t||(t=await this.#c(e.chunkIndex,{validateCrcs:r??!0,readOptions:i}),f.set(e.chunkIndex.chunkStartOffset,t));let[n,a]=e.popMessage();if(a>=BigInt(t.byteLength))throw this.#s(`Message offset beyond chunk bounds (log time ${n}, offset ${a}, chunk data length ${t.byteLength}) in chunk at offset ${e.chunkIndex.chunkStartOffset}`);p.reset(t,Number(a));let o=Qd(p,r??!0);if(!o)throw this.#s(`Unable to parse record at offset ${a} in chunk at offset ${e.chunkIndex.chunkStartOffset}`);if(o.type!==`Message`)throw this.#s(`Unexpected record type ${o.type} in message index (time ${n}, offset ${a} in chunk at offset ${e.chunkIndex.chunkStartOffset})`);if(o.logTime!==n)throw this.#s(`Message log time ${o.logTime} did not match message index entry (${n} at offset ${a} in chunk at offset ${e.chunkIndex.chunkStartOffset})`);yield o,e.hasMoreMessages()?l||c.replace(e):(c.pop(),f.delete(e.chunkIndex.chunkStartOffset))}}async*readMetadata(e={}){let{name:t,readOptions:n}=e;for(let e of this.metadataIndexes){if(t!=null&&e.name!==t)continue;let r=await this.#e.read(e.offset,e.length,n),i=Qd(new Jd(new DataView(r.buffer,r.byteOffset,r.byteLength)),!1);if(i?.type!==`Metadata`)throw this.#s(`Metadata data at offset ${e.offset} does not point to metadata record (found ${String(i?.type)})`);yield i}}async*readAttachments(e={}){let{name:t,mediaType:n,validateCrcs:r,readOptions:i}=e,{startingAt:a,endingAt:o}=bf(e,this.#a,this.#o);if(!(a==null||o==null))for(let e of this.attachmentIndexes){if(t!=null&&e.name!==t||n!=null&&e.mediaType!==n||e.logTime>o||e.logTime<a)continue;let s=await this.#e.read(e.offset,e.length,i),c=Qd(new Jd(new DataView(s.buffer,s.byteOffset,s.byteLength)),r??!0);if(c?.type!==`Attachment`)throw this.#s(`Attachment data at offset ${e.offset} does not point to attachment record (found ${String(c?.type)})`);yield c}}async#c(e,t){let n=await this.#e.read(e.chunkStartOffset,e.chunkLength,t?.readOptions),r=Qd(new Jd(new DataView(n.buffer,n.byteOffset,n.byteLength)),t?.validateCrcs??!0);if(r?.type!==`Chunk`)throw this.#s(`Chunk start offset ${e.chunkStartOffset} does not point to chunk record (found ${String(r?.type)})`);let i=r,a=i.records;if(i.compression!==``&&a.byteLength>0){let e=this.#n?.[i.compression];if(!e)throw this.#s(`Unsupported compression ${i.compression}`);a=e(a,i.uncompressedSize)}if(i.uncompressedCrc!==0&&t?.validateCrcs!==!1){let e=Ld(a);if(e!==i.uncompressedCrc)throw this.#s(`Incorrect chunk CRC ${e} (expected ${i.uncompressedCrc})`)}return new DataView(a.buffer,a.byteOffset,a.byteLength)}};function bf(e,t,n){if([e.startTime,e.startingAt,e.startingAfter].filter(e=>e!=null).length>1)throw Error(`Provide at most one of startTime, startingAt, startingAfter`);if([e.endTime,e.endingAt,e.endingBefore].filter(e=>e!=null).length>1)throw Error(`Provide at most one of endTime, endingAt, endingBefore`);let r=e.startingAt??e.startTime;e.startingAfter!=null&&(r=e.startingAfter+1n);let i=e.endingAt??e.endTime;if(e.endingBefore!=null&&(i=e.endingBefore-1n),r!=null&&i!=null&&r>i+1n)throw Error(`end time cannot come before start time`);return{startingAt:r??t,endingAt:i??n}}var xf=class{#e=new ArrayBuffer(Yd.length*2);#t=new DataView(this.#e,0,0);#n=new Jd(this.#t);#r;#i;#a;#o;#s;#c=!1;#l=this.#f();#u=new Map;constructor({includeChunks:e=!1,emitChunks:t=!1,decompressHandlers:n={},validateCrcs:r=!0,noMagicPrefix:i=!1}={}){this.#i=e,this.#a=t,this.#r=n,this.#o=r,this.#s=i}done(){return this.#c}bytesRemaining(){return this.#n.bytesRemaining()}append(e){if(this.#c)throw Error(`Already done reading`);this.#d(e)}#d(e){let t=this.#n.offset,n=this.#t.byteLength-t,r=n+e.byteLength;if(r<=this.#e.byteLength)if(this.#t.byteOffset+this.#t.byteLength+e.byteLength<=this.#e.byteLength)new Uint8Array(this.#e,this.#t.byteOffset).set(e,this.#t.byteLength),this.#t=new DataView(this.#e,this.#t.byteOffset,this.#t.byteLength+e.byteLength),this.#n.reset(this.#t,this.#n.offset);else{let r=new Uint8Array(this.#e,this.#t.byteOffset+t,n),i=new Uint8Array(this.#e);i.set(r,0),i.set(e,r.byteLength),this.#t=new DataView(this.#e,0,r.byteLength+e.byteLength),this.#n.reset(this.#t)}else{this.#e=new ArrayBuffer(r*2);let i=new Uint8Array(this.#e),a=new Uint8Array(this.#t.buffer,this.#t.byteOffset+t,n);i.set(a,0),i.set(e,a.byteLength),this.#t=new DataView(this.#e,0,a.byteLength+e.byteLength),this.#n.reset(this.#t)}}nextRecord(){if(this.#c)return;let e=this.#l.next();if(e.value?.type===`Channel`){let t=this.#u.get(e.value.id);if(this.#u.set(e.value.id,e.value),t&&!Sf(t,e.value))throw Error(`Channel record for id ${e.value.id} (topic: ${e.value.topic}) differs from previous channel record of the same id.`)}else if(!this.#a&&e.value?.type===`Message`){let t=e.value.channelId;if(!this.#u.get(t))throw Error(`Encountered message on channel ${t} without prior channel record`)}return e.done===!0&&(this.#c=!0),e.value}*#f(){if(!this.#s){let e;for(;e=Zd(this.#n),!e;)yield}let e;function t(t){return Error(`${t} ${e?`[library=${e.library}]`:`[no header]`}`)}for(;;){let n;for(;n=Qd(this.#n,this.#o),!n;)yield;switch(n.type){case`Header`:if(e)throw Error(`Duplicate Header record: library=${e.library} profile=${e.profile} vs. library=${n.library} profile=${n.profile}`);e=n,yield n;break;case`Unknown`:case`Schema`:case`Channel`:case`Message`:case`MessageIndex`:case`ChunkIndex`:case`Attachment`:case`AttachmentIndex`:case`Statistics`:case`Metadata`:case`MetadataIndex`:case`SummaryOffset`:case`DataEnd`:yield n;break;case`Chunk`:{if(this.#a){yield n;break}this.#i&&(yield n);let e=n.records;if(n.compression!==``&&e.byteLength>0){let r=this.#r[n.compression];if(!r)throw t(`Unsupported compression ${n.compression}`);e=r(e,n.uncompressedSize)}if(this.#o&&n.uncompressedCrc!==0){let r=Ld(e);if(r!==n.uncompressedCrc)throw t(`Incorrect chunk CRC ${r} (expected ${n.uncompressedCrc})`)}let r=new Jd(new DataView(e.buffer,e.byteOffset,e.byteLength)),i;for(;i=Qd(r,this.#o);)switch(i.type){case`Header`:case`Footer`:case`Chunk`:case`MessageIndex`:case`ChunkIndex`:case`Attachment`:case`AttachmentIndex`:case`Statistics`:case`Metadata`:case`MetadataIndex`:case`SummaryOffset`:case`DataEnd`:throw t(`${i.type} record not allowed inside a chunk`);case`Unknown`:case`Schema`:case`Channel`:case`Message`:yield i;break}if(r.bytesRemaining()!==0)throw t(`${r.bytesRemaining()} bytes remaining in chunk`);break}case`Footer`:try{let e;for(;e=Zd(this.#n),!e;)yield}catch(e){throw t(e.message)}if(this.#n.bytesRemaining()!==0)throw t(`${this.#n.bytesRemaining()} bytes remaining after MCAP footer and trailing magic`);return n}}}};function Sf(e,t){if(!(e.id===t.id&&e.messageEncoding===t.messageEncoding&&e.schemaId===t.schemaId&&e.topic===t.topic&&e.metadata.size===t.metadata.size))return!1;for(let[n,r]of e.metadata.entries())if(r!==t.metadata.get(n))return!1;return!0}var Cf=ArrayBuffer,q=Uint8Array,wf=Uint16Array,Tf=Int16Array,Ef=Int32Array,Df=function(e,t,n){if(q.prototype.slice)return q.prototype.slice.call(e,t,n);(t==null||t<0)&&(t=0),(n==null||n>e.length)&&(n=e.length);var r=new q(n-t);return r.set(e.subarray(t,n)),r},Of=function(e,t,n,r){if(q.prototype.fill)return q.prototype.fill.call(e,t,n,r);for((n==null||n<0)&&(n=0),(r==null||r>e.length)&&(r=e.length);n<r;++n)e[n]=t;return e},kf=function(e,t,n,r){if(q.prototype.copyWithin)return q.prototype.copyWithin.call(e,t,n,r);for((n==null||n<0)&&(n=0),(r==null||r>e.length)&&(r=e.length);n<r;)e[t++]=e[n++]},Af=[`invalid zstd data`,`window size too large (>2046MB)`,`invalid block type`,`FSE accuracy too high`,`match distance too far back`,`unexpected EOF`],J=function(e,t,n){var r=Error(t||Af[e]);if(r.code=e,Error.captureStackTrace&&Error.captureStackTrace(r,J),!n)throw r;return r},jf=function(e,t,n){for(var r=0,i=0;r<n;++r)i|=e[t++]<<(r<<3);return i},Mf=function(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0},Nf=function(e,t){var n=e[0]|e[1]<<8|e[2]<<16;if(n==3126568&&e[3]==253){var r=e[4],i=r>>5&1,a=r>>2&1,o=r&3,s=r>>6;r&8&&J(0);var c=6-i,l=o==3?4:o,u=jf(e,c,l);c+=l;var d=s?1<<s:i,f=jf(e,c,d)+(s==1&&256),p=f;if(!i){var m=1<<10+(e[5]>>3);p=m+(m>>3)*(e[5]&7)}p>2145386496&&J(1);var h=new q((t==1?f||p:t?0:p)+12);return h[0]=1,h[4]=4,h[8]=8,{b:c+d,y:0,l:0,d:u,w:t&&t!=1?t:h.subarray(12),e:p,o:new Ef(h.buffer,0,3),u:f,c:a,m:Math.min(131072,p)}}else if((n>>4|e[3]<<20)==25481893)return Mf(e,4)+8;J(0)},Pf=function(e){for(var t=0;1<<t<=e;++t);return t-1},Ff=function(e,t,n){var r=(t<<3)+4,i=(e[t]&15)+5;i>n&&J(3);for(var a=1<<i,o=a,s=-1,c=-1,l=-1,u=a,d=new Cf(512+(a<<2)),f=new Tf(d,0,256),p=new wf(d,0,256),m=new wf(d,512,a),h=512+(a<<1),g=new q(d,h,a),_=new q(d,h+a);s<255&&o>0;){var v=Pf(o+1),y=r>>3,b=(1<<v+1)-1,x=(e[y]|e[y+1]<<8|e[y+2]<<16)>>(r&7)&b,S=(1<<v)-1,C=b-o-1,w=x&S;if(w<C?(r+=v,x=w):(r+=v+1,x>S&&(x-=C)),f[++s]=--x,x==-1?(o+=x,g[--u]=s):o-=x,!x)do{var T=r>>3;c=(e[T]|e[T+1]<<8)>>(r&7)&3,r+=2,s+=c}while(c==3)}(s>255||o)&&J(0);for(var E=0,D=(a>>1)+(a>>3)+3,O=a-1,k=0;k<=s;++k){var A=f[k];if(A<1){p[k]=-A;continue}for(l=0;l<A;++l){g[E]=k;do E=E+D&O;while(E>=u)}}for(E&&J(0),l=0;l<a;++l){var j=p[g[l]]++;m[l]=(j<<(_[l]=i-Pf(j)))-a}return[r+7>>3,{b:i,s:g,n:_,t:m}]},If=function(e,t){var n=0,r=-1,i=new q(292),a=e[t],o=i.subarray(0,256),s=i.subarray(256,268),c=new wf(i.buffer,268);if(a<128){var l=Ff(e,t+1,6),u=l[0],d=l[1];t+=a;var f=u<<3,p=e[t];p||J(0);for(var m=0,h=0,g=d.b,_=g,v=(++t<<3)-8+Pf(p);v-=g,!(v<f);){var y=v>>3;if(m+=(e[y]|e[y+1]<<8)>>(v&7)&(1<<g)-1,o[++r]=d.s[m],v-=_,v<f)break;y=v>>3,h+=(e[y]|e[y+1]<<8)>>(v&7)&(1<<_)-1,o[++r]=d.s[h],g=d.n[m],m=d.t[m],_=d.n[h],h=d.t[h]}++r>255&&J(0)}else{for(r=a-127;n<r;n+=2){var b=e[++t];o[n]=b>>4,o[n+1]=b&15}++t}var x=0;for(n=0;n<r;++n){var S=o[n];S>11&&J(0),x+=S&&1<<S-1}var C=Pf(x)+1,w=1<<C,T=w-x;for(T&T-1&&J(0),o[r++]=Pf(T)+1,n=0;n<r;++n){var S=o[n];++s[o[n]=S&&C+1-S]}var E=new q(w<<1),D=E.subarray(0,w),O=E.subarray(w);for(c[C]=0,n=C;n>0;--n){var k=c[n];Of(O,n,k,c[n-1]=k+s[n]*(1<<C-n))}for(c[0]!=w&&J(0),n=0;n<r;++n){var A=o[n];if(A){var j=c[A];Of(D,n,j,c[A]=j+(1<<C-A))}}return[t,{n:O,b:C,s:D}]},Lf=Ff(new q([81,16,99,140,49,198,24,99,12,33,196,24,99,102,102,134,70,146,4]),0,6)[1],Rf=Ff(new q([33,20,196,24,99,140,33,132,16,66,8,33,132,16,66,8,33,68,68,68,68,68,68,68,68,36,9]),0,6)[1],zf=Ff(new q([32,132,16,66,102,70,68,68,68,68,36,73,2]),0,5)[1],Bf=function(e,t){for(var n=e.length,r=new Ef(n),i=0;i<n;++i)r[i]=t,t+=1<<e[i];return r},Vf=new q(new Ef([0,0,0,0,16843009,50528770,134678020,202050057,269422093]).buffer,0,36),Hf=Bf(Vf,0),Uf=new q(new Ef([0,0,0,0,0,0,0,0,16843009,50528770,117769220,185207048,252579084,16]).buffer,0,53),Wf=Bf(Uf,3),Gf=function(e,t,n){var r=e.length,i=t.length,a=e[r-1],o=(1<<n.b)-1,s=-n.b;a||J(0);for(var c=0,l=n.b,u=(r<<3)-8+Pf(a)-l,d=-1;u>s&&d<i;){var f=u>>3,p=(e[f]|e[f+1]<<8|e[f+2]<<16)>>(u&7);c=(c<<l|p)&o,t[++d]=n.s[c],u-=l=n.n[c]}(u!=s||d+1!=i)&&J(0)},Kf=function(e,t,n){var r=6,i=t.length+3>>2,a=i<<1,o=i+a;Gf(e.subarray(r,r+=e[0]|e[1]<<8),t.subarray(0,i),n),Gf(e.subarray(r,r+=e[2]|e[3]<<8),t.subarray(i,a),n),Gf(e.subarray(r,r+=e[4]|e[5]<<8),t.subarray(a,o),n),Gf(e.subarray(r),t.subarray(o),n)},qf=function(e,t,n){var r,i=t.b,a=e[i],o=a>>1&3;t.l=a&1;var s=a>>3|e[i+1]<<5|e[i+2]<<13,c=(i+=3)+s;if(o==1)return i>=e.length?void 0:(t.b=i+1,n?(Of(n,e[i],t.y,t.y+=s),n):Of(new q(s),e[i]));if(!(c>e.length)){if(o==0)return t.b=c,n?(n.set(e.subarray(i,c),t.y),t.y+=s,n):Df(e,i,c);if(o==2){var l=e[i],u=l&3,d=l>>2&3,f=l>>4,p=0,m=0;u<2?d&1?f|=e[++i]<<4|(d&2&&e[++i]<<12):f=l>>3:(m=d,d<2?(f|=(e[++i]&63)<<4,p=e[i]>>6|e[++i]<<2):d==2?(f|=e[++i]<<4|(e[++i]&3)<<12,p=e[i]>>2|e[++i]<<6):(f|=e[++i]<<4|(e[++i]&63)<<12,p=e[i]>>6|e[++i]<<2|e[++i]<<10)),++i;var h=n?n.subarray(t.y,t.y+t.m):new q(t.m),g=h.length-f;if(u==0)h.set(e.subarray(i,i+=f),g);else if(u==1)Of(h,e[i++],g);else{var _=t.h;if(u==2){var v=If(e,i);p+=i-(i=v[0]),t.h=_=v[1]}else _||J(0);(m?Kf:Gf)(e.subarray(i,i+=p),h.subarray(g),_)}var y=e[i++];if(y){y==255?y=(e[i++]|e[i++]<<8)+32512:y>127&&(y=y-128<<8|e[i++]);var b=e[i++];b&3&&J(0);for(var x=[Rf,zf,Lf],S=2;S>-1;--S){var C=b>>(S<<1)+2&3;if(C==1){var w=new q([0,0,e[i++]]);x[S]={s:w.subarray(2,3),n:w.subarray(0,1),t:new wf(w.buffer,0,1),b:0}}else C==2?(r=Ff(e,i,9-(S&1)),i=r[0],x[S]=r[1]):C==3&&(t.t||J(0),x[S]=t.t[S])}var T=t.t=x,E=T[0],D=T[1],O=T[2],k=e[c-1];k||J(0);var A=(c<<3)-8+Pf(k)-O.b,j=A>>3,M=0,N=(e[j]|e[j+1]<<8)>>(A&7)&(1<<O.b)-1;j=(A-=D.b)>>3;var ee=(e[j]|e[j+1]<<8)>>(A&7)&(1<<D.b)-1;j=(A-=E.b)>>3;var P=(e[j]|e[j+1]<<8)>>(A&7)&(1<<E.b)-1;for(++y;--y;){var te=O.s[N],ne=O.n[N],re=E.s[P],ie=E.n[P],ae=D.s[ee],oe=D.n[ee];j=(A-=ae)>>3;var se=1<<ae,ce=se+((e[j]|e[j+1]<<8|e[j+2]<<16|e[j+3]<<24)>>>(A&7)&se-1);j=(A-=Uf[re])>>3;var le=Wf[re]+((e[j]|e[j+1]<<8|e[j+2]<<16)>>(A&7)&(1<<Uf[re])-1);j=(A-=Vf[te])>>3;var ue=Hf[te]+((e[j]|e[j+1]<<8|e[j+2]<<16)>>(A&7)&(1<<Vf[te])-1);if(j=(A-=ne)>>3,N=O.t[N]+((e[j]|e[j+1]<<8)>>(A&7)&(1<<ne)-1),j=(A-=ie)>>3,P=E.t[P]+((e[j]|e[j+1]<<8)>>(A&7)&(1<<ie)-1),j=(A-=oe)>>3,ee=D.t[ee]+((e[j]|e[j+1]<<8)>>(A&7)&(1<<oe)-1),ce>3)t.o[2]=t.o[1],t.o[1]=t.o[0],t.o[0]=ce-=3;else{var de=ce-(ue!=0);de?(ce=de==3?t.o[0]-1:t.o[de],de>1&&(t.o[2]=t.o[1]),t.o[1]=t.o[0],t.o[0]=ce):ce=t.o[0]}for(var S=0;S<ue;++S)h[M+S]=h[g+S];M+=ue,g+=ue;var fe=M-ce;if(fe<0){var pe=-fe,me=t.e+fe;pe>le&&(pe=le);for(var S=0;S<pe;++S)h[M+S]=t.w[me+S];M+=pe,le-=pe,fe=0}for(var S=0;S<le;++S)h[M+S]=h[fe+S];M+=le}if(M!=g)for(;g<h.length;)h[M++]=h[g++];else M=h.length;n?t.y+=M:h=Df(h,0,M)}else if(n){if(t.y+=f,g)for(var S=0;S<f;++S)h[S]=h[g+S]}else g&&(h=Df(h,g));return t.b=c,h}J(2)}},Jf=function(e,t){if(e.length==1)return e[0];for(var n=new q(t),r=0,i=0;r<e.length;++r){var a=e[r];n.set(a,i),i+=a.length}return n};function Yf(e,t){for(var n=[],r=+!t,i=0,a=0;e.length;){var o=Nf(e,r||t);if(typeof o==`object`){for(r?(t=null,o.w.length==o.u&&(n.push(t=o.w),a+=o.u)):(n.push(t),o.e=0);!o.l;){var s=qf(e,o,t);s||J(5),t?o.e=o.y:(n.push(s),a+=s.length,kf(o.w,0,s.length),o.w.set(s,o.w.length-s.length))}i=o.b+o.c*4}else i=o;e=e.subarray(i)}return Jf(n,a)}var Xf=e(((e,t)=>{(()=>{var e={91:((e,t)=>{Object.defineProperty(t,`__esModule`,{value:!0}),t.buildRos2Type=w;let n=String.raw`(?<type>[a-zA-Z0-9_/]+)`,r=String.raw`(?:<=(?<stringBound>\d+))`,i=String.raw`(?:(?<unboundedArray>\[\])|\[(?<arrayLength>\d+)\]|\[<=(?<arrayBound>\d+)\])`,a=String.raw`(?<name>[a-zA-Z0-9_]+)`,o=String.raw`'(?:\\.|[^'\\])*'|"(?:\\.|[^"\\])*"`,s=String.raw`(?:${o}|(?:\\.|[^\s'"#\\])(?:\\.|[^#\\])*)`,c=String.raw`(?:${o}|(?:\\.|[^\s'"\],#\\])(?:\\.|[^\],#\\])*)`,l=String.raw`\s*=\s*(?<constantValue>${s}?)`,u=String.raw`\[(?:${c},)*${c}?\]`,d=String.raw`(?<defaultValue>${u}|${s})`,f=String.raw`(?:#.*)`,p=new RegExp(String.raw`^${n}${r}?${i}?\s+${a}(?:${l}|\s+${d})?\s*${f}?$`),m=String.raw`\\(?<char>['"abfnrtv\\])|\\(?<oct>[0-7]{1,3})|\\x(?<hex2>[a-fA-F0-9]{2})|\\u(?<hex4>[a-fA-F0-9]{4})|\\U(?<hex8>[a-fA-F0-9]{8})`,h=[`bool`,`byte`,`char`,`float32`,`float64`,`int8`,`uint8`,`int16`,`uint16`,`int32`,`uint32`,`int64`,`uint64`,`string`,`wstring`,`time`,`duration`,`builtin_interfaces/Time`,`builtin_interfaces/Duration`,`builtin_interfaces/msg/Time`,`builtin_interfaces/msg/Duration`];function g(e,t,n){let r=BigInt(e);if(r<t||r>n)throw Error(`Number ${e} out of range [${t}, ${n}]`);return r}function _(e,t,n){let r=parseInt(e);if(Number.isNaN(r))throw Error(`Invalid numeric literal: ${e}`);if(r<t||r>n)throw Error(`Number ${e} out of range [${t}, ${n}]`);return r}let v=new RegExp(c,`y`),y=/\s*(,)\s*|\s*$/y;function b(e,t){if(!t.startsWith(`[`)||!t.endsWith(`]`))throw Error(`Array must start with [ and end with ]`);let n=t.substring(1,t.length-1);if(e===`string`||e===`wstring`){let e=[],t=0;for(;t<n.length;){if(n[t]===`,`)throw Error(`Expected array element before comma`);v.lastIndex=t;let r=v.exec(n);if(r&&(e.push(x(r[0])),t=v.lastIndex),y.lastIndex=t,r=y.exec(n),!r)throw Error(`Expected comma or end of array`);if(!r[1])break;t=y.lastIndex}return e}return n.split(`,`).map(t=>S(e,t.trim()))}function x(e){let t=``,n=e;for(let r of[`'`,`"`])if(e.startsWith(r)){if(!e.endsWith(r))throw Error(`Expected terminating ${r} in string literal: ${e}`);t=r,n=e.substring(r.length,e.length-r.length);break}if(!new RegExp(String.raw`^(?:[^\\${t}]|${m})*$`).test(n)==null)throw Error(`Invalid string literal: ${n}`);return n.replace(new RegExp(m,`g`),(...e)=>{let{char:t,oct:n,hex2:r,hex4:i,hex8:a}=e[e.length-1],o=r??i??a;if(t!=null)return{"'":`'`,'"':`"`,a:`\x07`,b:`\b`,f:`\f`,n:`
38
+ `+e.slice(o+1):c+=e.slice(i),c.slice(1)}function Vc(e){for(var t=``,n=0,r,i=0;i<e.length;n>=65536?i+=2:i++)n=Oc(e,i),r=dc[n],!r&&Cc(n)?(t+=e[i],n>=65536&&(t+=e[i+1])):t+=r||hc(n);return t}function Hc(e,t,n){var r=``,i=e.tag,a,o,s;for(a=0,o=n.length;a<o;a+=1)s=n[a],e.replacer&&(s=e.replacer.call(n,String(a),s)),(qc(e,t,s,!1,!1)||s===void 0&&qc(e,t,null,!1,!1))&&(r!==``&&(r+=`,`+(e.condenseFlow?``:` `)),r+=e.dump);e.tag=i,e.dump=`[`+r+`]`}function Uc(e,t,n,r){var i=``,a=e.tag,o,s,c;for(o=0,s=n.length;o<s;o+=1)c=n[o],e.replacer&&(c=e.replacer.call(n,String(o),c)),(qc(e,t+1,c,!0,!0,!1,!0)||c===void 0&&qc(e,t+1,null,!0,!0,!1,!0))&&((!r||i!==``)&&(i+=bc(e,t)),e.dump&&Hs===e.dump.charCodeAt(0)?i+=`-`:i+=`- `,i+=e.dump);e.tag=a,e.dump=i||`[]`}function Wc(e,t,n){var r=``,i=e.tag,a=Object.keys(n),o,s,c,l,u;for(o=0,s=a.length;o<s;o+=1)u=``,r!==``&&(u+=`, `),e.condenseFlow&&(u+=`"`),c=a[o],l=n[c],e.replacer&&(l=e.replacer.call(n,c,l)),qc(e,t,c,!1,!1)&&(e.dump.length>1024&&(u+=`? `),u+=e.dump+(e.condenseFlow?`"`:``)+`:`+(e.condenseFlow?``:` `),qc(e,t,l,!1,!1)&&(u+=e.dump,r+=u));e.tag=i,e.dump=`{`+r+`}`}function Gc(e,t,n,r){var i=``,a=e.tag,o=Object.keys(n),s,c,l,u,d,f;if(e.sortKeys===!0)o.sort();else if(typeof e.sortKeys==`function`)o.sort(e.sortKeys);else if(e.sortKeys)throw new Da(`sortKeys must be a boolean or a function`);for(s=0,c=o.length;s<c;s+=1)f=``,(!r||i!==``)&&(f+=bc(e,t)),l=o[s],u=n[l],e.replacer&&(u=e.replacer.call(n,l,u)),qc(e,t+1,l,!0,!0,!0)&&(d=e.tag!==null&&e.tag!==`?`||e.dump&&e.dump.length>1024,d&&(e.dump&&Hs===e.dump.charCodeAt(0)?f+=`?`:f+=`? `),f+=e.dump,d&&(f+=bc(e,t)),qc(e,t+1,u,!0,d)&&(e.dump&&Hs===e.dump.charCodeAt(0)?f+=`:`:f+=`: `,f+=e.dump,i+=f));e.tag=a,e.dump=i||`{}`}function Kc(e,t,n){var r,i=n?e.explicitTypes:e.implicitTypes,a,o,s,c;for(a=0,o=i.length;a<o;a+=1)if(s=i[a],(s.instanceOf||s.predicate)&&(!s.instanceOf||typeof t==`object`&&t instanceof s.instanceOf)&&(!s.predicate||s.predicate(t))){if(n?s.multi&&s.representName?e.tag=s.representName(t):e.tag=s.tag:e.tag=`?`,s.represent){if(c=e.styleMap[s.tag]||s.defaultStyle,Rs.call(s.represent)===`[object Function]`)r=s.represent(t,c);else if(zs.call(s.represent,c))r=s.represent[c](t,c);else throw new Da(`!<`+s.tag+`> tag resolver accepts not "`+c+`" style`);e.dump=r}return!0}return!1}function qc(e,t,n,r,i,a,o){e.tag=null,e.dump=n,Kc(e,n,!1)||Kc(e,n,!0);var s=Rs.call(e.dump),c=r,l;r&&=e.flowLevel<0||e.flowLevel>t;var u=s===`[object Object]`||s===`[object Array]`,d,f;if(u&&(d=e.duplicates.indexOf(n),f=d!==-1),(e.tag!==null&&e.tag!==`?`||f||e.indent!==2&&t>0)&&(i=!1),f&&e.usedDuplicates[d])e.dump=`*ref_`+d;else{if(u&&f&&!e.usedDuplicates[d]&&(e.usedDuplicates[d]=!0),s===`[object Object]`)r&&Object.keys(e.dump).length!==0?(Gc(e,t,e.dump,i),f&&(e.dump=`&ref_`+d+e.dump)):(Wc(e,t,e.dump),f&&(e.dump=`&ref_`+d+` `+e.dump));else if(s===`[object Array]`)r&&e.dump.length!==0?(e.noArrayIndent&&!o&&t>0?Uc(e,t-1,e.dump,i):Uc(e,t,e.dump,i),f&&(e.dump=`&ref_`+d+e.dump)):(Hc(e,t,e.dump),f&&(e.dump=`&ref_`+d+` `+e.dump));else if(s===`[object String]`)e.tag!==`?`&&Ic(e,e.dump,t,a,c);else if(s===`[object Undefined]`)return!1;else{if(e.skipInvalid)return!1;throw new Da(`unacceptable kind of an object to dump `+s)}e.tag!==null&&e.tag!==`?`&&(l=encodeURI(e.tag[0]===`!`?e.tag.slice(1):e.tag).replace(/!/g,`%21`),l=e.tag[0]===`!`?`!`+l:l.slice(0,18)===`tag:yaml.org,2002:`?`!!`+l.slice(18):`!<`+l+`>`,e.dump=l+` `+e.dump)}return!0}function Jc(e,t){var n=[],r=[],i,a;for(Yc(e,n,r),i=0,a=r.length;i<a;i+=1)t.duplicates.push(n[r[i]]);t.usedDuplicates=Array(a)}function Yc(e,t,n){var r,i,a;if(typeof e==`object`&&e)if(i=t.indexOf(e),i!==-1)n.indexOf(i)===-1&&n.push(i);else if(t.push(e),Array.isArray(e))for(i=0,a=e.length;i<a;i+=1)Yc(e[i],t,n);else for(r=Object.keys(e),i=0,a=r.length;i<a;i+=1)Yc(e[r[i]],t,n)}function Xc(e,t){t||={};var n=new vc(t);n.noRefs||Jc(e,n);var r=e;return n.replacer&&(r=n.replacer.call({"":r},``,r)),qc(n,0,r,!0,!0)?n.dump+`
39
+ `:``}var Zc={dump:Xc},Qc=Ls.load;Ls.loadAll,Zc.dump;const $c=/^(tag|tag ?name|channel|name|signal|point|item|variable)$/i,el=/^(value|val|pv|reading|measurement)$/i;function tl(e){let t=t=>e.flatMap((e,n)=>e.kind===t?[n]:[]),n=t(`time`),r=t(`text`),i=t(`number`);if(n.length!==1||i.length!==1||r.length<1||r.length>2)return null;let a=t=>$c.test(e[t].name.trim()),o=r.length===2&&a(r[1])&&!a(r[0])?r[1]:r[0];return!a(o)&&!el.test(e[i[0]].name.trim())?null:{time:n[0],tag:o,value:i[0],unit:r.find(e=>e!==o)??null}}async function nl(e,t,n){let r=new Map,i=[],a=[],o=0,s=0,c=!0,l=-1/0,u=1/0,d=0,f=[];for await(let p of e.read(t.unit===null?[t.time,t.tag]:[t.time,t.tag,t.unit],n)){let e=p.columns[0],t=p.columns[1],n=p.columns[2];for(let m=0;m<p.length;m++){let p=t[m],h=e[m];if(!p||Number.isNaN(h))continue;o++,h<l&&(c=!1),h!==l&&s++,l=h,h<u&&(u=h);let g=n?.[m]??``,_=r.get(p);if(_===void 0)r.set(p,i.length),f.push(h),i.push(p),a.push(g);else{if(n&&a[_]!==g)return null;f[_]===h&&d++,f[_]=h}}}return i.length===0||i.length*2>o?null:{tags:i,units:a,rows:o,times:c?s:o,sorted:c,start:u,repeated:c?d:0}}async function*rl(e,t,n,r,i,a,o){let s=new Map;r.forEach((e,t)=>s.set(n.tags[e],t));let c=Math.max(1,Math.min(4096,Math.floor(4e6/Math.max(1,r.length)))),l=new Float64Array(r.length).fill(NaN),u=()=>r.map(()=>new Float64Array(c).fill(NaN)),d=new Float64Array(c),f=u(),p=0,m=0,h=()=>{let e=p===c,t={group:i,time:e?d:d.slice(0,p),start:m,length:p,columns:e?f:f.map(e=>e.slice(0,p))};return m+=p,p=0,d=new Float64Array(c),f=u(),t},g=(e,t,n)=>{if(l[t]===e||Number.isNaN(n))return!0;let r=e-a;return p>0&&d[p-1]===r?(f[t][p-1]=n,l[t]=e,!0):p===c?!1:(l[t]=e,d[p]=r,f[t][p++]=n,!0)},_=e.read([t.time,t.tag,t.value],o);if(n.sorted)for await(let e of _){let t=e.columns[0],n=e.columns[1],r=e.columns[2];for(let i=0;i<e.length;i++){let e=n[i]?s.get(n[i]):void 0;e!==void 0&&!Number.isNaN(t[i])&&!g(t[i],e,r[i])&&(yield h(),g(t[i],e,r[i]))}}else{let e=new Float64Array(4096),t=new Int32Array(4096),n=new Float64Array(4096),r=0;for await(let i of _){let a=i.columns[0],o=i.columns[1],c=i.columns[2];for(let l=0;l<i.length;l++){let i=o[l]?s.get(o[l]):void 0;if(!(i===void 0||Number.isNaN(a[l]))){if(r===e.length){let r=e=>{let t=new e.constructor(e.length*2);return t.set(e),t};e=r(e),t=r(t),n=r(n)}e[r]=a[l],t[r]=i,n[r++]=c[l]}}}let i=Uint32Array.from({length:r},(e,t)=>t).sort((t,n)=>e[t]-e[n]||t-n);for(let r of i)g(e[r],t[r],n[r])||(yield h(),g(e[r],t[r],n[r]))}p>0&&(yield h())}const il=/^(t|time|timestamp|elapsed ?time|[\w ]*_time)\s*(\[[^\]]*\]|\([^)]*\))?$/i,al=/^\d{4}[-/]\d{2}[-/]\d{2}[T ]\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:?\d{2})?$/;function ol(e){let t=e.trim();return al.test(t)?Date.parse(t.slice(0,10).replace(/\//g,`-`)+`T`+t.slice(11))/1e3:NaN}function sl(e){let t=Math.floor(e*1e3),n=new Date(t),r=new Date(n.getUTCFullYear(),n.getUTCMonth(),n.getUTCDate(),n.getUTCHours(),n.getUTCMinutes(),n.getUTCSeconds(),n.getUTCMilliseconds());return n.getUTCFullYear()<100&&r.setFullYear(n.getUTCFullYear()),r.getTime()/1e3+(e-t/1e3)}const cl=e=>Math.round(sl(e)-e);async function ll(e,t,n){for await(let r of e.read([t],n)){let e=r.columns[0];for(let t=0;t<r.length;t++)if(!Number.isNaN(e[t]))return e[t]}return NaN}function ul(e,t){if(!e.includes(`"`))return e.split(t);let n=[],r=``,i=!1;for(let a=0;a<e.length;a++){let o=e[a];i?o===`"`?e[a+1]===`"`?(r+=`"`,a++):i=!1:r+=o:o===`"`?i=!0:o===t?(n.push(r),r=``):r+=o}return n.push(r),n}function dl(e){for(let t of[` `,`;`,`,`]){let n=ul(e[0],t).length;if(n>=3&&e.every(e=>ul(e,t).length===n))return t}return null}function fl(e,t){let n=e.trim();return n===``?NaN:Number(t?n.replace(`,`,`.`):n)}function pl(e,t,n){return e.map((e,r)=>{let i=e.trim(),a=0,o=0,s=0;for(let e of t){let t=(e[r]??``).trim();t&&(Number.isNaN(fl(t,n))?Number.isNaN(ol(t))?s++:o++:a++)}let c=o>0&&o>=a+s?`time`:a>0&&a>=s?il.test(i)?`time`:`number`:`text`;return{name:i,unit:c===`time`&&o===0?`s`:``,kind:c,absolute:c===`time`&&o>0}})}function ml(e){let t=e.split(/\r?\n/).slice(0,-1).filter(e=>e.trim()).slice(0,50);if(t.length<3)return!1;let n=dl(t);return n?tl(pl(ul(t[0],n),t.slice(1).map(e=>ul(e,n)),n===`;`))!==null:!1}var B=class extends Error{};const hl=()=>new B(`it names more than ${1e6.toLocaleString(`en-US`)} parameter occurrences`),gl={u8:[1,`u`],i8:[1,`i`],u16:[2,`u`],i16:[2,`i`],u24:[3,`u`],u32:[4,`u`],i32:[4,`i`],u48:[6,`u`],u64:[8,`u`],i64:[8,`i`],f16:[2,`f`],f32:[4,`f`],f64:[8,`f`],bool:[1,`b`]},_l={little:!0,"<":!0,big:!1,">":!1},vl=[`name`,`type`,`offset`,`count`,`endian`,`scale`,`add`,`unit`,`bit`,`bits`,`sample_rate_hz`],yl=e=>e==null||e===``;function bl(e,t,n){let r=String(e).trim();if(/^[+-]?(0x[0-9a-f]+|0o[0-7]+|0b[01]+|[1-9]\d*|0)$/i.test(r.replace(/_/g,``))){let e=r.startsWith(`-`),t=Number(r.replace(/^[+-]/,``).replace(/_/g,``));if(Number.isSafeInteger(t))return e?-t:t}throw new B(`${n}: '${t}' must be a number`)}function xl(e,t,n){let r=typeof e==`number`?e:Number(String(e).trim());if(yl(e)||Number.isNaN(r)&&!/^[+-]?nan$/i.test(String(e).trim()))throw new B(`${n}: '${t}' must be a number`);return r}function Sl(e){let t=e>>10&31,n=e&1023,r=e&32768?-1:1;return t===31?n?NaN:r*(1/0):t?r*2**(t-15)*(1+n/1024):r*2**-14*(n/1024)}function Cl(e,t){switch(e){case`u8`:case`bool`:return(e,t)=>e.getUint8(t);case`i8`:return(e,t)=>e.getInt8(t);case`u16`:return(e,n)=>e.getUint16(n,t);case`i16`:return(e,n)=>e.getInt16(n,t);case`u24`:return(e,n)=>t?e.getUint16(n,!0)+e.getUint8(n+2)*65536:e.getUint16(n)*256+e.getUint8(n+2);case`u48`:return(e,n)=>t?e.getUint32(n,!0)+e.getUint16(n+4,!0)*4294967296:e.getUint16(n)*4294967296+e.getUint32(n+2);case`u32`:return(e,n)=>e.getUint32(n,t);case`i32`:return(e,n)=>e.getInt32(n,t);case`u64`:return(e,n)=>e.getUint32(n+(t?4:0),t)*4294967296+e.getUint32(n+(t?0:4),t);case`i64`:return(e,n)=>e.getInt32(n+(t?4:0),t)*4294967296+e.getUint32(n+(t?0:4),t);case`f16`:return(e,n)=>Sl(e.getUint16(n,t));case`f32`:return(e,n)=>e.getFloat32(n,t);default:return(e,n)=>e.getFloat64(n,t)}}function wl(e,t,n,r,i){let a=String(e.name??``).trim();if(!a)throw new B(`${i}: every field needs a 'name'`);i=`${i}, field '${a}'`;let o=String(e.type??``);if(!(o in gl))throw new B(`${i}: 'type' must be one of ${Object.keys(gl).join(`, `)}`);let[s,c]=gl[o],l=_l[String(yl(e.endian)?n:e.endian)];if(l===void 0)throw new B(`${i}: 'endian' must be little or big`);let u=yl(e.count)?1:bl(e.count,`count`,i);if(u<1||u>4096)throw new B(`${i}: 'count' must be 1-4096`);let d=yl(e.offset)?t:bl(e.offset,`offset`,i);if(d<0||d>1<<24)throw new B(`${i}: 'offset' must be 0 or more`);let f=yl(e.bit)?null:bl(e.bit,`bit`,i),p=yl(e.bits)?1:bl(e.bits,`bits`,i);if(!yl(e.bits)&&f===null)throw new B(`${i}: 'bits' needs 'bit', the lowest of them`);if(f!==null&&(c!==`u`&&c!==`i`||u!==1||f<0||p<1||f+p>8*s))throw new B(`${i}: 'bit' (and 'bits') need one integer (u8..u64) and bits inside it`);let m=yl(e.scale)?1:xl(e.scale,`scale`,i),h=yl(e.add)?0:xl(e.add,`add`,i),g=yl(e.sample_rate_hz)?null:xl(e.sample_rate_hz,`sample_rate_hz`,i);if(g!==null&&(!(g>0)||o===`bool`||o===`u24`||o===`u48`||f!==null))throw new B(`${i}: 'sample_rate_hz' must be above 0, on a number field (not bool, bit, u24 or u48)`);let _=String(e.unit??``),v=Cl(o,l),y=f===null?v:(e,t)=>Math.floor(v(e,t)/2**f)%2**p,b=o===`bool`||f!==null&&p===1,x=(e,t)=>{let n=y(e,t);return b?n=+!!n:(g!==null||m!==1||h!==0)&&(n=n*m+h),Number.isFinite(n)?n:NaN},S=(e,t,n)=>x(t,n>>>3),C=u===1||g!==null?[r+a]:Array.from({length:u},(e,t)=>`${r}${a}[${t}]`),w=e=>(d+e*s)*8,T=g===null?C.map((e,t)=>({name:e,unit:_,at:[w(t)],bits:s*8,read:S})):[{name:C[0],unit:_,at:Array.from({length:u},(e,t)=>w(t)),bits:s*8,dt:1/g,read:S}];return{name:a,off:d,size:s,count:u,int:(c===`u`||c===`i`)&&!b,raw:y,tags:C,field:T}}function Tl(e,t,n,r,i={n:0}){if(!Array.isArray(e.fields)||!e.fields.length)throw new B(`${r}: needs a non-empty 'fields' list`);t=String(e.endian||t);let a=String(e.prefix??``),o=[],s=new Set,c=n;for(let n of e.fields){if(!n||typeof n!=`object`||Array.isArray(n))throw new B(`${r}: each field must be a mapping with name and type`);let e=wl(n,c,t,a,r);if((i.n+=e.count)>1e6)throw hl();c=e.off+e.size*e.count;for(let t of e.tags){if(s.has(t))throw new B(`${r}: field name '${t}' is repeated`);s.add(t)}o.push(e)}let l=new Map(o.map(e=>[e.name,e])),u=new Set;if(e.seq){let t=l.get(String(e.seq));if(!t||t.count!==1)throw new B(`${r}: 'seq' must name a field holding one integer`);u.add(t.name)}if(e.timestamp){let t=e.timestamp,n=typeof t==`object`?l.get(String(t.field)):void 0;if(!n||n.count!==1)throw new B(`${r}: 'timestamp.field' must name a field holding one number`);u.add(n.name)}return{name:null,kind:`P`,rate:null,end:null,fields:o.filter(e=>!u.has(e.name)).flatMap(e=>e.field),minBytes:Math.max(...o.map(e=>e.off+e.size*e.count))}}function El(e,t){let n=String(e.endian||`little`);if(!(n in _l))throw new B(`${t}: 'endian' must be little or big`);let r={source:`layout`,keys:new Map,any:null,notes:[]};if(!e.packet_id){if(`packets`in e)throw new B(`${t}: 'packets' needs a 'packet_id' to tell them apart`);return r.any=Tl(e,n,0,t),r}if(typeof e.packet_id!=`object`)throw new B(`${t}: 'packet_id' must be one integer field`);let i=wl({name:`packet_id`,...e.packet_id},0,n,``,`${t} packet_id`);if(i.count!==1||!i.int)throw new B(`${t}: 'packet_id' must be one integer field`);r.pid={off:i.off,size:i.size,read:i.raw};let a=e.packets;if(!a||typeof a!=`object`||Array.isArray(a)||!Object.keys(a).length)throw new B(`${t}: 'packet_id' needs a 'packets' mapping of id to packet`);let o={n:0};for(let[e,s]of Object.entries(a)){let a=bl(e,`packets`,t);r.keys.set(a,Tl(s??{},n,i.off+i.size,`${t} packet ${e}`,o))}return r}function Dl(e,t){let n=e.replace(/^\uFEFF/,``).split(/\r?\n/),r=ul(n[0]??``,`,`).map(e=>e.trim());if(!r.includes(`name`)||!r.includes(`type`))throw new B(`${t}: a layout CSV needs the columns packet, name, type, offset…`);let i={},a=new Map;for(let e of n.slice(1)){if(!e.trim())continue;let t=ul(e,`,`),n={};if(r.forEach((e,r)=>{e&&(n[e]=(t[r]??``).trim())}),!n.name)continue;let o={};for(let e of vl)n[e]&&(o[e]=n[e]);let s=n.role??``,c=n.packet||null;if(s===`id`){i.packet_id=Object.fromEntries(Object.entries(o).filter(([e])=>e!==`name`));continue}let l=a.get(c);l||a.set(c,l={fields:[]}),s===`time`||s===`time_relative`?(l.timestamp={field:o.name,unit:o.unit??`s`,mode:s===`time`?`epoch`:`relative`},delete o.unit):s===`seq`&&(l.seq=o.name),l.fields.push(o)}return a.size===1&&a.has(null)&&!(`packet_id`in i)?a.get(null):(i.packets=Object.fromEntries([...a].map(([e,t])=>[String(e),t])),i)}function Ol(e,t){let n=`the layout ${t}`,r;if(/\.csv$/i.test(t))r=Dl(e,n);else try{r=Qc(e)}catch(e){throw new B(`${n}: not YAML (${e.message.split(`
40
+ `)[0]})`)}if(!r||typeof r!=`object`||Array.isArray(r))throw new B(`${n} must be a mapping`);return El(r,n)}const kl=/<(?:[\w.-]+:)?t(?:\s[^>]*)?>([\s\S]*?)<\/(?:[\w.-]+:)?t>/g,Al={amp:`&`,lt:`<`,gt:`>`,quot:`"`,apos:`'`},jl=e=>e.includes(`&`)?e.replace(/&(#x[0-9a-fA-F]+|#\d+|amp|lt|gt|quot|apos);/g,(e,t)=>t[0]===`#`?String.fromCodePoint(t[1]===`x`?parseInt(t.slice(2),16):parseInt(t.slice(1),10)):Al[t]):e;function Ml(e,t){let n=` ${t}="`,r=(` `+e).indexOf(n);if(r<0)return;let i=r-1+n.length;return jl(e.slice(i,e.indexOf(`"`,i)))}function Nl(e,t){let n=new Map;for(let e of t.matchAll(/<(?:[\w.-]+:)?Relationship\b([^>]*)>/g)){let t=Ml(e[1],`Id`),r=Ml(e[1],`Target`);t&&r&&n.set(t,r.startsWith(`/`)?r.slice(1):`xl/${r.replace(/^\.\//,``)}`)}let r=[...e.matchAll(/<(?:[\w.-]+:)?sheet\b([^>]*)>/g)].flatMap(e=>{let t=Ml(e[1],`name`),r=n.get(Ml(e[1],`r:id`)??``);return t&&r?[{name:t,path:r}]:[]}),i=Ml(/<(?:[\w.-]+:)?workbookPr\b([^>]*)>/.exec(e)?.[1]??``,`date1904`);return{sheets:r,date1904:i===`1`||i===`true`}}const Pl=new Set([14,15,16,17,18,19,20,21,22,45,46,47]);function Fl(e,t){if(t===void 0)return Pl.has(e);let n=t.replace(/"[^"]*"/g,``).replace(/\\./g,``).replace(/\[(?![hms]+\])[^\]]*\]/gi,``);return/[dmyhs]/i.test(n)&&!/general/i.test(n)}function Il(e){let t=new Map;for(let n of e.matchAll(/<(?:[\w.-]+:)?numFmt\b([^>]*)>/g)){let e=Ml(n[1],`formatCode`);e!==void 0&&t.set(Number(Ml(n[1],`numFmtId`)),e)}return[...(/<(?:[\w.-]+:)?cellXfs\b[^>]*>([\s\S]*?)<\/(?:[\w.-]+:)?cellXfs>/.exec(e)?.[1]??``).matchAll(/<(?:[\w.-]+:)?xf\b([^>]*)>/g)].map(e=>{let n=Number(Ml(e[1],`numFmtId`)??0);return Fl(n,t.get(n))})}function Ll(e,t=T){let n=[];for(let r of e.matchAll(/<(?:[\w.-]+:)?si>([\s\S]*?)<\/(?:[\w.-]+:)?si>|<(?:[\w.-]+:)?si\/>/g)){let e=(r[1]??``).replace(/<(?:[\w.-]+:)?rPh\b[\s\S]*?<\/(?:[\w.-]+:)?rPh>/g,``),i=``;for(let t of e.matchAll(kl))i+=t[1];if(n.length>=t)throw Error(`This workbook is too large to open (over ${t.toLocaleString(`en-US`)} shared strings).`);n.push(jl(i))}return n}const Rl=Array.from({length:23},(e,t)=>10**t);let zl=-1;function Bl(e,t){let n=e.length,r=t,i=e.charCodeAt(r)===45;i&&r++;let a=0,o=0,s=0,c=-1,l=!0;for(;r<n;r++){let t=e.charCodeAt(r);if(t===60)break;if(t===46&&c<0){c=0;continue}let n=t-48;if(n<0||n>9){l=!1;break}a=a*10+n,o++,a&&s++,c>=0&&c++}if(l&&r<n&&o>0&&s<=15&&c<=22){zl=r;let e=c>0?a/Rl[c]:a;return i?-e:e}return zl=e.indexOf(`<`,r),zl<0?NaN:Number(e.slice(t,zl))}const Vl=e=>e===32||e===9||e===10||e===13,Hl=(e,t,n,r)=>e.charCodeAt(t)===60&&e.charCodeAt(t+1)===47&&e.charCodeAt(t+2+r.length)===n&&e.charCodeAt(t+3+r.length)===62&&(!r||e.startsWith(r,t+2));async function Ul(e,t,n,r){let i=-1,a=-1,o=0,s=``,c=(e,c)=>{let l=e.length,u=t=>c?``:e.slice(t),d=0;for(;;){let c=e.indexOf(`<`,d);if(c<0)return``;let f=c+1,p=-1,m=e.charCodeAt(f);for(;f<l&&!Vl(m)&&m!==62&&m!==47;)m===58&&(p=f),m=e.charCodeAt(++f);if(f>=l)return u(c);let h=p<0?c+1:p+1,g=f-h,_=g===1&&e.charCodeAt(h)===99;if(!_&&!(g===3&&e.startsWith(`row`,h))){let t=e.indexOf(`>`,f);if(t<0)return u(c);d=t+1;continue}(h-c-1!==s.length||!e.startsWith(s,c+1))&&(s=e.slice(c+1,h));let v=-1,y=0,b=0,x=f;for(;;){for(;x<l&&Vl(e.charCodeAt(x));)x++;if(x>=l)return u(c);if(m=e.charCodeAt(x),m===62||m===47)break;let t=x;for(;x<l&&(m=e.charCodeAt(x))!==61&&!Vl(m)&&m!==62;)x++;let n=x-t;for(;x<l&&Vl(e.charCodeAt(x));)x++;if(x>=l)return u(c);if(e.charCodeAt(x)!==61)continue;for(x++;x<l&&Vl(e.charCodeAt(x));)x++;let r=e.charCodeAt(x);if(r!==34&&r!==39)continue;let i=x+1,a=e.indexOf(r===34?`"`:`'`,i);if(a<0)return u(c);if(x=a+1,n!==1)continue;let o=e.charCodeAt(t);if(o===114){let t=0,n=i;if(_){for(;n<a;n++){let r=e.charCodeAt(n);if(r<65||r>90)break;t=t*26+r-64}v=t-1}else{for(;n<a;n++){let r=e.charCodeAt(n)-48;if(r<0||r>9)break;t=t*10+r}v=n>i?t-1:-1}}else if(o===116){let t=a-i,n=e.charCodeAt(i);y=t===1?n===115?1:n===98?3:n===101?4:n===110?0:-1:t===3&&n===115&&e.startsWith(`str`,i)?2:t===9&&e.startsWith(`inlineStr`,i)?5:-1}else if(o===115){let t=0;for(let n=i;n<a;n++){let r=e.charCodeAt(n)-48;if(r<0||r>9)break;t=t*10+r}b=t}}let S=m===47,C=e.indexOf(`>`,x);if(C<0)return u(c);if(!_){i=v>=0?v:i+1,a=-1,d=C+1;continue}let w=v>=0?v:a+1;if(S){a=w,d=C+1;continue}let T=s.length;if(y===0&&e.charCodeAt(C+1)===60&&e.charCodeAt(C+2+T)===118&&e.charCodeAt(C+3+T)===62&&(!T||e.startsWith(s,C+2))){let t=Bl(e,C+4+T),o=zl;if(o>C+4+T&&Hl(e,o,118,s)&&Hl(e,o+4+T,99,s)){a=w,Number.isNaN(t)||r(i,a,t,n[b]??!1),d=o+8+2*T;continue}}let E=-1,D=-1,O=!1,k=-1;for(let t=C+1;;){let n=e.indexOf(`<`,t);if(n<0)return u(c);let r=e.charCodeAt(n+1)===47,i=r?n+2:n+1;if(t=n+1,s&&!e.startsWith(s,i))continue;let o=e.charCodeAt(i+T),l=e.charCodeAt(i+T+1);if(r){if(o===99&&l===62){k=n,d=i+T+2,a=w;break}}else if(o===118&&l===62){if(E=i+T+2,D=e.indexOf(`<`,E),D<0)return u(c);t=D}else o===102&&(l===62||l===47||Vl(l))&&(O=!0)}if(y===5){let t=``;for(let n of e.slice(C+1,k).matchAll(kl))t+=n[1];t&&r(i,a,jl(t),!1);continue}if(D<=E){O&&o++;continue}if(y===0){let t=Bl(e,E);Number.isNaN(t)||r(i,a,t,n[b]??!1)}else y===1?r(i,a,t[Bl(e,E)]??``,!1):y===2?r(i,a,jl(e.slice(E,D)),!1):y===3&&r(i,a,+(D-E===1&&e.charCodeAt(E)===49),!1)}},l=``;for await(let t of e)l=c(l?l+t:t,!1);return c(l,!0),o}function Wl(e){let t={name:``,attrs:``,kids:[],text:``},n=[t],r=0,i=(t,n)=>{let r=e.indexOf(t,n);return r<0?e.length:r+t.length};for(;r<e.length;){let t=e.indexOf(`<`,r),a=n[n.length-1];if(t<0){a.text+=jl(e.slice(r));break}if(t>r&&(a.text+=jl(e.slice(r,t))),e.startsWith(`<!--`,t)){r=i(`-->`,t+4);continue}if(e.startsWith(`<![CDATA[`,t)){let n=e.indexOf(`]]>`,t);a.text+=e.slice(t+9,n<0?e.length:n),r=n<0?e.length:n+3;continue}if(e[t+1]===`?`||e[t+1]===`!`){r=i(`>`,t);continue}let o=``,s=t+1;for(;s<e.length;s++){let t=e[s];if(o)t===o&&(o=``);else if(t===`"`||t===`'`)o=t;else if(t===`>`)break}let c=e.slice(t+1,s);if(r=s+1,c[0]===`/`){n.length>1&&n.pop();continue}let l=c.endsWith(`/`),u=/^[^\s/>]+/.exec(c),d={name:(u?.[0]??``).replace(/^.*:/,``),attrs:c.slice(u?.[0].length??0,l?-1:void 0),kids:[],text:``};if(a.kids.push(d),!l){if(n.length>256)throw new B(`the XidML file nests deeper than 256 elements`);n.push(d)}}return t}const V=(e,t)=>e?.kids.find(e=>e.name===t),Gl=(e,t)=>e?.kids.filter(e=>e.name===t)??[],H=(e,t)=>V(e,t)?.text.trim(),U=(e,t)=>{let n=RegExp(`(?:^|\\s)${t}\\s*=\\s*("([^"]*)"|'([^']*)')`).exec(e.attrs);return n?jl(n[2]??n[3]):void 0};function Kl(e,t){let n=[],r=[e];for(;r.length;){let e=r.pop();e.name===t&&n.push(e);for(let t=e.kids.length-1;t>=0;t--)r.push(e.kids[t])}return n}const W=e=>{if(e===void 0||e===``)return null;let t=Number(e);return Number.isFinite(t)?t:null};function ql(e,t,n){let r=0;for(;n>0;){let i=Math.floor(t/8),a=t%8,o=Math.min(8-a,n);r=r*2**o+(e[i]>>8-a-o&(1<<o)-1),t+=o,n-=o}return r}const Jl=new DataView(new ArrayBuffer(8)),Yl=(e,t)=>(Math.floor(e/2**32)&Math.floor(t/2**32))*2**32+((e&t)>>>0);function Xl(e,t,n,r=null,i=!1){if(n&&t%8)return`little-endian with a size that is not whole bytes`;if((r!==null||i)&&(n||t>53))return`a mask or complement on a little-endian or wide parameter`;let a=2**t-1,o=n?(e,n)=>{let r=0;for(let i=t/8-1;i>=0;i--)r=r*256+ql(e,n+8*i,8);return r}:r!==null||i?(e,n)=>{let o=ql(e,n,t);return r!==null&&(o=Yl(o,r)),i?a-o:o}:(e,n)=>ql(e,n,t),s=2**(t-1);switch(e){case`BitVector`:return t<=53?o:`more than 53 bits`;case`OffsetBinary`:return t<=53?(e,t)=>o(e,t)-s:`more than 53 bits`;case`TwosComplement`:return t<=53?(e,t)=>{let n=o(e,t);return n>=s?n-2*s:n}:`more than 53 bits`;case`SignedMagnitude`:return t<=53?(e,t)=>{let n=o(e,t);return n>=s?-(n-s):n}:`more than 53 bits`;case`BinaryCodedDecimal`:return t%4||t>52?`BCD that is not whole digits`:(e,n)=>{let r=o(e,n),i=0;for(let e=t/4-1;e>=0;e--){let t=Math.floor(r/16**e)%16;if(t>9)return NaN;i=i*10+t}return i};case`IEEE-754-Float-Single`:return t===32?(e,t)=>(Jl.setUint32(0,o(e,t)),Jl.getFloat32(0)):`a single float that is not 32 bits`;case`IEEE-754-Float-Double`:return t===64?r!==null||i?`a mask or complement on a double`:n?(e,t)=>{for(let n=0;n<8;n++)Jl.setUint8(7-n,ql(e,t+8*n,8));return Jl.getFloat64(0)}:(e,t)=>(Jl.setUint32(0,ql(e,t,32)),Jl.setUint32(4,ql(e,t+32,32)),Jl.getFloat64(0)):`a double that is not 64 bits`;default:return`data format ${e}`}}const Zl={"P Type":`P`,"D Type":`D`,"N Type":`N`,"M Type":`M`,"Q Type":`Q`},Ql=65506*8;function $l(e){let t=V(Wl(e),`xidml`);if(!t)throw new B(`it has no <xidml> element`);let n=[],r=[],i=!1,a=0,o=new Map;for(let e of Kl(V(t,`Parameters`)??t,`Parameter`)){let t=U(e,`Name`);t&&!o.has(t)&&o.set(t,e)}let s=new Map;for(let e of Kl(t,`ParameterUnit`)){let t=U(e,`Name`);t&&s.set(t,{scale:W(H(e,`Scale`))??1,offset:W(H(e,`Offset`))??0})}let c=new Map;for(let e of Kl(t,`AlgorithmSet`))for(let t of e.kids){let e=U(t,`Name`);if(e)if(t.name===`Polynomial`){let n=Gl(t,`Term`).map(e=>[W(H(e,`Coefficient`))??0,W(H(e,`Exponent`))??0]);c.set(e,e=>n.reduce((t,[n,r])=>t+n*e**r,0))}else c.set(e,t.name)}let l=(e,t,l)=>{(V(e,`FillValue`)||(H(e,`Parity`)??`None`)!==`None`)&&(i=!0);let u=H(e,`ParameterReference`),d=u===void 0?V(e,`Parameter`):o.get(u),f=u??(d?U(d,`Name`):void 0);if(!f)return null;if(!d)return r.push(`${f} (${t}: no parameter definition)`),null;let p=W(H(e,`NumberOfDataBits`))??W(H(d,`SizeInBits`))??16;if(!Number.isInteger(p)||p<1||p>64)return r.push(`${f} (${p} bits)`),null;let m=H(d,`Endianness`);if(m===`Mixed-Endian`||m===`Bit-Endian`)return r.push(`${f} (${m})`),null;if(H(e,`MostSignificantBit`)===`Last`)return r.push(`${f} (least significant bit first)`),null;let h=H(e,`Justification`)===`Right`?Math.ceil(p/16)*16-p:0,g=H(e,`Mask`)?.replace(/^0x/i,``),_=null;if(g!==void 0){let e=g.length*4;if(!/^[0-9a-f]+$/i.test(g)||e<h+p)return r.push(`${f} (mask ${g})`),null;_=Number(BigInt(`0x${g}`)>>BigInt(e-h-p)&(1n<<BigInt(p))-1n)}let v=H(e,`Complement`)===`Yes`,y=Xl(H(d,`DataFormat`)??`OffsetBinary`,p,m===`Little-Endian`,_,v);if(typeof y==`string`)return r.push(`${f} (${y})`),null;let b=H(d,`ParameterUnitReference`),x=b?s.get(b):void 0,S=H(d,`BaseUnit`),C=x?b:S&&S!==`Unitless`&&S!==`BitVector`?S:``,w=H(d,`AlgorithmReference`),T=w?c.get(w):void 0;w&&typeof T!=`function`&&n.push(`${f}: its algorithm ${w} (${T??`not defined`}) is not applied.`);let E=typeof T==`function`?T:null,D=x||E?(e,t,n)=>{let r=y(e,n);return E&&(r=E(r)),x?r*x.scale+x.offset:r}:(e,t,n)=>y(e,n),O=[],k;for(let t of Gl(e,`Location`)){let e=W(H(t,`Offset_Words`)),n=e===null?W(H(t,`Offset_Bits`)):e*16+h;if(n===null||!Number.isInteger(n)||n<0||n>Ql)return r.push(`${f} (a location outside any IENA packet)`),null;let i=W(H(t,`Occurrences`))??1;if(!Number.isInteger(i)||i<1||i*p>Ql)return r.push(`${f} (${i} occurrences)`),null;if((a+=i)>1e6)throw hl();if(i===1)O.push(n);else if(l){let t=e===null?p:Math.ceil(p/16)*16;for(let e=0;e<i;e++)O.push(n+e*t)}else O.push(n),k=i}return O.length?k&&O.length>1?(r.push(`${f} (several locations and occurrences)`),null):{name:f,unit:C,at:O,spread:k,bits:p,read:D}:(r.push(`${f} (${t}: no location)`),null)},u=new Map;for(let e of[...Kl(t,`IENA`),...Kl(t,`IENA-Ethernet-UDP-Basic`)]){let t=U(e,`Name`)??null,r=V(e,`Properties`),i=parseInt(H(r,`Key`)??``,16);if(!(i>=0&&i<=65535)){n.push(`The XidML package ${t??`(no name)`} has no IENA key; it is not used.`);continue}if(u.has(i)){n.push(`The XidML names key 0x${eu(i)} twice; the first package is used.`);continue}let a=Zl[H(r,`PayloadType`)??`P Type`]??`P`,o=parseInt(H(r,`EndWord`)??``,16),s=/^(true|1)$/i.test(H(e,`PlaceParametersContiguously`)??``),c=Gl(V(e,`Content`),`Mapping`);a!==`P`&&c.length&&n.push(`${t}: a ${a} type packet names its parameters by id; its mappings are not used.`);let d=a===`P`?c.map(e=>l(e,t??eu(i),s)).filter(e=>e!==null):[],f=W(H(e,`PackageRate`));u.set(i,{name:t,kind:a,fields:d,minBytes:0,rate:f&&f>0?f:null,end:o>=0&&o<=65535&&o!==57005?o:null})}if(!u.size)throw new B(`it has no IENA packages`);return i&&n.push(`XidML Parity and FillValue are not checked.`),r.length&&n.push(`Not decoded from the XidML: ${r.slice(0,20).join(`, `)}${r.length>20?`, and ${r.length-20} more`:``}.`),{source:`XidML`,keys:u,any:null,notes:n}}const eu=e=>e.toString(16).toUpperCase().padStart(4,`0`),tu=2e3,nu=1e5,ru=(e,t,n=`${t}s`)=>`${e} ${e===1?t:n}`,iu=e=>e===1?`was`:`were`;function au(e,t,n,r,i,a){a.length=0;let o=n+r-2,s=n+14,c=e[n+10]&7;if(i===`N`||i===`D`){let e=i===`D`?4:2,n=e+2*c;if((o-s)%n)return null;for(;s<o;s+=n)a.push([t.getUint16(s),i===`D`?t.getUint16(s+2):0,s+e,c]);return a}let l=i===`M`?6:4;for(;s<o;){if(o-s<l)return null;let e=t.getUint16(s+l-2),n=s+l+e+(e&1);if(n>o)return null;a.push([t.getUint16(s),i===`M`?t.getUint16(s+2):0,s+l,e+1>>1]),s=n}return a}var ou=class{dated=!1;#e=null;#t=1970;#n=new Map;#r(e){let t=this.#n.get(e);return t===void 0&&(t=Date.UTC(e,0,1)*1e3,this.#n.set(e,t)),t}abs(e,t){if(this.#e===null){let n=new Date(e).getUTCFullYear();return this.#t=Number.isFinite(n)?n:1970,this.dated=this.#t>=2e3,this.#e=this.#r(this.#t)+t}let n=0,r=this.#t;for(let e of[this.#t,this.#t+1,this.#t-1]){let i=this.#r(e)+t;(e===this.#t||Math.abs(i-this.#e)<Math.abs(n-this.#e))&&(n=i,r=e)}return this.#t=r,this.#e=n}};const su=(e,t)=>e?.keys.get(t)??e?.any??null;function cu(e,t){let{b:n,o:r,n:i}=e,a=t.ports.get(e.dport);a||t.ports.set(e.dport,a=[0,0]);let o=t.dict?.pid,s=i>=2?n[r]<<8|n[r+1]:-1,c=s>=0&&!o?su(t.dict,s):null;if(!ga(n,r,i,c?.end??57005))return a[1]++,null;a[0]++;let l=new DataView(n.buffer,n.byteOffset,n.byteLength);if(o){if(o.off+o.size>i)return t.damaged++,null;s=o.read(l,r+o.off),c=t.dict.keys.get(s)??null}let u=l.getUint16(r+4)*4294967296+l.getUint32(r+6);return{key:s,kd:c,abs:t.clock.abs(e.time,u),dv:l}}const lu=e=>e?.kind??`P`,uu=e=>!!e&&e.kind===`P`&&e.fields.length>0,du=e=>e.spread??e.at.length,fu=e=>du(e)>1||e.dt!==void 0,pu=(e,t)=>(e?.source===`XidML`?t-2:t)*8;function mu(e,t,n,r){r.length=0;let i=2*Math.floor(n/e.bits);if(e.spread){let a=Math.floor((t-16>>1)/e.spread)*16;for(let t=0;t<(a>0?e.spread:1)&&r.length<i;t++){let i=e.at[0]+t*a;i+e.bits<=n&&r.push(i,t)}}else for(let t=0;t<e.at.length&&r.length<i;t++)e.at[t]+e.bits<=n&&r.push(e.at[t],t);return r}async function hu(e,t){let n=e=>/\.(xidml|xml)$/i.test(e.name),r=e=>/\.(ya?ml|csv)$/i.test(e.name),i=[...e.filter(n),...e.filter(r)];if(!i.length)return null;let a=i[0];for(let e of i.slice(1))t.push(`${e.name} was not used: ${a.name} is the dictionary.`);let o=n(a)?`XidML file`:`layout`;try{if(a.size>67108864)throw new B(`it is larger than 64 MB`);let e=d(new Uint8Array(await a.arrayBuffer())),r=n(a)?$l(e):Ol(e,a.name);return t.push(...r.notes),r}catch(e){let n=e instanceof B?e.message:`it may be damaged`;return t.push(`${a.name} isn't a usable ${o} (${n}); IENA keys are read as raw 16-bit words.`),null}}async function gu(e,t){let n=[],r={},i=await hu(e.companions,n),a=da(await t.read(0,64));if(!a)throw Error(`This is not a pcap or pcapng capture.`);let o={dict:i,clock:new ou,stats:ca(),ports:new Map,damaged:0},s=new Map,c=[],l=[],u=1/0,d=0,f=e=>{let t=cu(e,o);if(!t)return;let{key:n,kd:r,abs:a,dv:f}=t,p=lu(r),m=s.get(n),h=uu(r),g=!h&&p!==`P`?au(e.b,f,e.o,e.n,p,c):null;if(!h&&p!==`P`&&!g){o.damaged++;return}if(!m)s.set(n,m={packets:0,short:0,words:0,rows:[],ids:new Map,first:a,last:a,steps:0,seq:f.getUint16(e.o+12)});else{let t=f.getUint16(e.o+12),n=t-m.seq&65535;n&&n<32768&&(m.steps+=n,m.seq=t,m.last=Math.max(m.last,a),m.first=Math.min(m.first,a))}if(m.packets++,u=Math.min(u,a),h&&e.n<r.minBytes){m.short++;return}if(h){r.fields.forEach((t,n)=>{fu(t)&&(m.rows[n]=(m.rows[n]??0)+mu(t,e.n,pu(i,e.n),l).length/2)});return}if(p===`P`){m.words=Math.max(m.words,e.n-16>>1);return}let _=new Map;for(let[e,,,t]of g){let n=m.ids.get(e);n||m.ids.set(e,n={words:0,max:0,total:0}),t>64&&d++,n.words=Math.max(n.words,Math.min(t,64)),n.total++,_.set(e,(_.get(e)??0)+1)}for(let[e,t]of _){let n=m.ids.get(e);n.max=Math.max(n.max,t)}};for(let e=ha(t,f,o.stats);!(await e.next()).done;);let p=[],m=new Map,h=0,g=0,_=e=>p.length>=tu||h+e.channels.length>nu?(g++,-1):(h+=e.channels.length,p.push(e),p.length-1),v=[...s].sort((e,t)=>e[0]-t[0]),y=[],b=0;for(let[e,t]of v){let n=su(i,e);i&&!n&&y.push(e);let a=lu(n),o=n?.name||`IENA 0x${eu(e)}`,s=n?.rate?1e6/n.rate:t.steps?(t.last-t.first)/t.steps:0,c=s>0?1e6/s:null,l={dict:n,kind:a,fields:[],main:-1,rawWords:0,ids:new Map,period:s};m.set(e,l),r[`Key 0x${eu(e)}`]=`${n?.name?`${n.name}: `:``}${n?i.source===`layout`?`layout`:`${a} type`:`raw words`}, ${ru(t.packets,`packet`)}`;let u=(e,t,n,r)=>({name:e,channels:t,samples:n,time:{kind:`timestamps`},rateHz:r,irregular:!0});if(uu(n)){b+=t.short;let e=t.packets-t.short;if(!e)continue;let r=n.fields.filter(e=>!fu(e)),i=cn(r.map(e=>e.name));r.length&&(l.main=_(u(o,r.map((e,t)=>({name:i[t],unit:e.unit})),e,c))),r.forEach((e,t)=>l.fields.push({f:e,g:l.main,c:t,occ:1})),n.fields.forEach((e,n)=>{if(!fu(e)||!t.rows[n])return;let r=du(e),i=e.dt?1/e.dt:c&&c*r;l.fields.push({f:e,g:_(u(`${o} ${e.name}`,[{name:e.name,unit:e.unit}],t.rows[n],i)),c:0,occ:r})})}else if(a===`P`)l.rawWords=t.words,t.words&&(l.main=_(u(o,Array.from({length:t.words},(e,t)=>({name:`${o} w${t}`,unit:``})),t.packets,c)));else{let e=[...t.ids].sort((e,t)=>e[0]-t[0]),n=(e,t)=>Array.from({length:t},(n,r)=>({name:`${o} 0x${eu(e)}${t>1?` w${r}`:``}`,unit:``})),r=e=>a===`D`||a===`M`||e.max>1,i=e.filter(([,e])=>!r(e)).flatMap(([e,t])=>n(e,t.words));i.length&&(l.main=_(u(o,i,t.packets,c)));let s=0;for(let[t,i]of e){if(!r(i)){l.ids.set(t,{g:l.main,c:s,words:i.words,own:!1}),s+=i.words;continue}let e=i.words?_(u(`${o} 0x${eu(t)}`,n(t,i.words),i.total,null)):-1;l.ids.set(t,{g:e,c:0,words:i.words,own:!0})}}}if(!s.size)throw Error(`This capture has no IENA packets${o.stats.damagedAt===null?``:` Kymoscope could read (it is damaged)`}: no UDP datagram holds an IENA header, its size and end field.`);if(!i&&!n.length&&n.push(`No XidML or layout file came with the capture: every IENA key is read as raw 16-bit words.`),y.length){let e=y.slice(0,10).map(e=>`0x${eu(e)}`).join(`, `);n.push(`Not in the ${i.source}: ${y.length===1?`key`:`keys`} ${e}${y.length>10?`, and ${y.length-10} more`:``}; read as raw 16-bit words.`)}let x=o.damaged,S=0;for(let[e,t]of o.ports.values())e?x+=t:S+=t;let C=o.stats;x&&n.push(`${ru(x,`damaged IENA packet`)} ${iu(x)} skipped.`);let w=[S?`${ru(S,`UDP datagram`)} that ${S===1?`isn't`:`aren't`} IENA`:``,C.other?`${ru(C.other,`frame`)} that ${C.other===1?`isn't`:`aren't`} UDP`:``].filter(Boolean);w.length&&n.push(`Skipped: ${w.join(`, `)}.`),C.incomplete&&n.push(`${ru(C.incomplete,`fragmented datagram`)} ${iu(C.incomplete)} incomplete and skipped.`),C.truncated&&n.push(`${ru(C.truncated,`packet`)} captured shorter than sent (snap length) ${iu(C.truncated)} skipped.`),b&&n.push(`${ru(b,`IENA packet`)} shorter than the layout ${iu(b)} skipped (as the collector does).`),d&&n.push(`${ru(d,`message dataset`)} longer than 64 words ${d===1?`is`:`are`} read to its first 64 words.`),g&&n.push(`${ru(g,`group`)} past ${tu.toLocaleString(`en-US`)} groups or ${nu.toLocaleString(`en-US`)} channels ${iu(g)} not read.`),C.cut&&n.push(`The capture ends in the middle of a packet.`),C.damagedAt!==null&&n.push(`The capture is damaged at byte ${C.damagedAt}; the rest of it was not read.`),cn(p.map(e=>e.name),[]).forEach((e,t)=>{p[t].name=e});let T={keys:m,dict:i,t0:u};return{format:`IENA (${a})`,startTime:Number.isFinite(u)&&o.clock.dated?new Date(u/1e3).toISOString():null,groups:p,meta:r,events:[],notes:n,interleaved:!0,state:T}}const _u={...va,async plan(e,t){try{return await gu(e,t)}catch(e){throw k(e)}},async*stream(e){let t=e.plan.state,n=new Map,r=e=>{e.cap=Math.max(1,Math.min(65536,e.total-e.start)),e.time=new Float64Array(e.cap),e.cols=e.cols.map(()=>new Float64Array(e.cap).fill(NaN))};for(let t of e.selection){let i=p(e,t.group),a=new Int32Array(e.plan.groups[t.group].channels.length).fill(-1);i.forEach((e,t)=>{a[e]=t});let o={cols:i.map(()=>new Float64Array),slot:a,time:new Float64Array,n:0,cap:0,start:0,total:e.plan.groups[t.group].samples};r(o),n.set(t.group,o)}let i=[],a=(e,t)=>{let n=t.n===t.cap;if(i.push({group:e,time:n?t.time:t.time.slice(0,t.n),start:t.start,length:t.n,columns:t.cols.map(e=>n?e:e.slice(0,t.n))}),t.start+=t.n,n)r(t);else for(let e of t.cols)e.fill(NaN,0,t.n);t.n=0},o,s=-1,c=(e,t)=>(o=n.get(e),!o||o.start+o.n>=o.total?!1:(o.n===o.cap&&a(e,o),s=o.n++,o.time[s]=t,!0)),l=(e,t)=>{let n=o.slot[e];n>=0&&(o.cols[n][s]=t)},u={dict:t.dict,clock:new ou,stats:ca(),ports:new Map,damaged:0},d=[],f=[],m=0,h=e=>{if(++m%4096==0)for(let[e,t]of n)t.n&&a(e,t);let r=cu(e,u);if(!r)return;let i=t.keys.get(r.key);if(!i)return;let{b:p,o:h,n:g}=e,{dv:_}=r,v=(r.abs-t.t0)/1e6,y=pu(t.dict,g),b=h*8,x=e=>e+2<=h+g-2?_.getUint16(e):NaN;if(i.fields.length||uu(i.dict)){if(g<i.dict.minBytes)return;let e=i.main>=0&&c(i.main,v);for(let{f:t,g:n,c:r,occ:a}of i.fields){if(n===i.main){e&&l(r,t.at[0]+t.bits<=y?t.read(p,_,b+t.at[0]):NaN);continue}if(!(n<0)){mu(t,g,y,f);for(let e=0;e<f.length;e+=2){let r=f[e+1];if(!c(n,t.dt?v+r*t.dt:v+r*i.period/a/1e6))break;l(0,t.read(p,_,b+f[e]))}}}return}if(i.kind===`P`){if(i.main>=0&&c(i.main,v))for(let e=0;e<i.rawWords;e++)l(e,x(h+14+2*e));return}let S=au(p,_,h,g,i.kind,d);if(!S)return;let C=i.main>=0&&c(i.main,v),w=o,T=s,E=new Map;for(let[e]of S)i.ids.get(e)?.own&&i.kind!==`D`&&i.kind!==`M`&&E.set(e,(E.get(e)??0)+1);let D=new Map;for(let[e,t,n,r]of S){let a=i.ids.get(e);if(!a||a.g<0)continue;let u=Math.min(r,a.words);if(!a.own){if(!C)continue;o=w,s=T;for(let e=0;e<u;e++)l(a.c+e,x(n+2*e));continue}let d=v+t/1e6;if(E.has(e)){let t=D.get(e)??0;D.set(e,t+1),d=v+t*i.period/E.get(e)/1e6}if(c(a.g,d))for(let e=0;e<u;e++)l(e,x(n+2*e))}};try{for(let t=ha(e.io,h,u.stats,e.signal);!(await t.next()).done;)yield*i,i.length=0}catch(e){throw k(e)}for(let[e,t]of n)t.n&&a(e,t);yield*i},streamGroup(e,t){return this.stream({...e,selection:e.selection.filter(e=>e.group===t)})}},vu=65542,yu=(e,t)=>(e[t]&224)==0,bu=(e,t)=>(e[t]&7)<<8|e[t+1],xu=(e,t)=>e[t+2]>>6,Su=(e,t)=>(e[t+2]&63)<<8|e[t+3],Cu=(e,t)=>(e[t+4]<<8|e[t+5])+7,wu=()=>({idle:0,segments:0,skipped:0,cut:!1});var Tu=class{#e=new Map;#t;#n;constructor(e,t){this.#t=e,this.#n=t}push(e,t,n){let r=bu(e,t);if(r===2047){this.#n.idle++;return}let i=xu(e,t);if(i===3){this.#t(e,t,n);return}let a=this.#e.get(r),o=Su(e,t);if(i===1){a&&(this.#n.segments++,this.#e.delete(r));let i=new Uint8Array(Math.min(vu,Math.max(n*2,256)));i.set(e.subarray(t,t+n)),this.#e.set(r,{buf:i,n,count:o});return}if(!a||(a.count+1&16383)!==o||a.n+n-6>65542){this.#n.segments+=a?2:1,this.#e.delete(r);return}let s=a.n+n-6;if(s>a.buf.length){let e=new Uint8Array(Math.min(vu,Math.max(s,a.buf.length*2)));e.set(a.buf.subarray(0,a.n)),a.buf=e}a.buf.set(e.subarray(t+6,t+n),a.n),a.n=s,a.count=o,i===2&&(this.#e.delete(r),this.#t(a.buf,0,a.n))}};function Eu(e,t,n,r,i){let a=0,o=e.length;for(;a+6<=o;){if(!yu(e,a)){n.skipped++,i.on=!0,a++;continue}let s=Cu(e,a);if(a+s>o){if(!r)return a;if(i.on){n.skipped++,a++;continue}return n.cut=!0,o}if(i.on){if(a+s+6<=o){if(!yu(e,a+s)){n.skipped++,a++;continue}}else if(!r)return a;i.on=!1}t.push(e,a,s),a+=s}return r&&a<o?(n.cut=!0,o):a}function Du(e,t=4){let n=0,r=0,i=!1,a=!0,o=new Map;for(;n+6<=e.length&&!(r>=t&&n>=4096);){if(!yu(e,n))return!1;let t=bu(e,n),s=Su(e,n),c=o.get(t);c!==void 0&&(c+1&16383)===s&&(i=!0),o.set(t,s),e[n]|e[n+1]|e[n+2]|e[n+3]&&(a=!1),n+=Cu(e,n),r++}return r>=t&&i&&!a}const Ou=Uint8Array.of(26,207,252,29),ku=(()=>{let e=new Uint8Array(255),t=255;for(let n=0;n<2040;n++){let r=t>>7;e[n>>3]|=r<<7-(n&7);let i=t>>7^t>>4^t>>2^t;t=(t<<1|i&1)&255}return e})(),Au=(()=>{let e=new Uint16Array(256);for(let t=0;t<256;t++){let n=t<<8;for(let e=0;e<8;e++)n=n&32768?n<<1^4129:n<<1;e[t]=n&65535}return e})();function ju(e,t,n){let r=65535;for(let i=t;i<t+n;i++)r=(r<<8^Au[(r>>8^e[i])&255])&65535;return r}const Mu=(e,t)=>t+4<=e.length&&e[t]===26&&e[t+1]===207&&e[t+2]===252&&e[t+3]===29;function Nu(e,t){for(let n=e.indexOf(26,t);n>=0;n=e.indexOf(26,n+1))if(Mu(e,n))return n;return-1}function Pu(e,t,n,r,i){let a=i.subarray(0,n);if(a.set(e.subarray(t,t+n)),r)for(let e=0;e<n;e++)a[e]^=ku[e%255];return a}const Fu=Uint8Array.from({length:256},(e,t)=>{let n=0;for(let e=t;e;e&=e-1)n++;return n});function Iu(e,t){if(t+4>e.length)return!1;let n=0;for(let r=0;r<4&&n<=2;r++)n+=Fu[e[t+r]^Ou[r]];return n<=2}function Lu(e,t,n,r,i){let a=new Map,o=0;for(let s of t){if(s+n>e.length)break;let t=Pu(e,s,n,r,i),c=t[1]>>1&7,l=t[4]<<8|t[5],u=6+(l&32768?(t[6]&63)+1:0),d=n-(t[1]&1?4:0),f=l&2047,p=a.get(c),m=p&&(p[0]+1&255)===t[3]?p[1]:-1,h=-1;if(u<d&&f===2047)h=m>=d-u?m-(d-u):-1;else if(f<2046&&u+f<d){m>=0&&m===f&&o++;let e=u+f;for(;d-e>=6&&e+Cu(t,e)<=d;)e+=Cu(t,e);h=e===d?0:d-e>=6?e+Cu(t,e)-d:-1}a.set(c,[t[3],h])}return o}function Ru(e){let t=Nu(e,0);if(t<0||t>65536)return null;for(let n=t+4+7;n-t-4<=65536&&n+4<=e.length;n++){if(!Iu(e,n))continue;let r=n-t,i=0,a=0,o=[];for(let n=t;n+4<=e.length;n+=r)i++,Iu(e,n)&&(a++,n+r<=e.length&&o.push(n+4));if(a<3||a<.9*i||o.length<2)continue;let s=new Uint8Array(r),c=t=>{let n=0,i=-1,a=-1,c=[];for(let l of o){let o=Pu(e,l,Math.min(6,r-4),t,s),u=(o[0]&63)<<4|o[1]>>4,d=o[1]>>1&7;!(o[0]>>6)&&(a<0||u===a)&&n++,i>=0&&(i+1&255)===o[2]&&n++,c[d]!==void 0&&(c[d]+1&255)===o[3]&&n++,i=o[2],c[d]=o[3],a=u}return n},l=c(!1),u=c(!0),d=u>l,f=-1;if(2*Math.max(l,u)<3*o.length)for(let t of[!1,!0]){let n=o.map(n=>{let r=Pu(e,n,1,t,s)[0];return r>>6==1?1:r>>4==12?12:-1});if(n[0]>=0&&n.every(e=>e===n[0])){f=n[0],d=t;break}}let p=Pu(e,o[0],Math.min(6,r-4),d,s);f<0&&(f=p[0]>>6==3&&p[0]>>4==12?12:p[0]>>6);let m=(r-4)%255==0&&(r-4)/255<=8,h=m?[223,239].map(e=>(r-4)/255*e).concat(r-4):[r-4],g=h.find(t=>o.filter(n=>ju(Pu(e,n,t,d,s),0,t)===0).length*2>o.length),_=g??r-4;if(g===void 0&&m&&f===0){let t=-1;for(let n of h){let r=Lu(e,o,n,d,s);r>t&&(t=r,_=n)}}return{start:t,cadu:r,frame:_,randomized:d,fecf:g!==void 0,version:f,scid:(p[0]&63)<<4|p[1]>>4}}return null}const zu=()=>({frames:0,vcs:new Set,badFecf:0,gaps:new Map,idleFrames:0,partial:0,damaged:0,notPackets:0,outOfSync:0,badSync:0});var Bu=class{#e=[];#t;#n;#r;constructor(e,t,n){this.#t=e,this.#n=t,this.#r=n}#i(e){e.open&&this.#r.partial++,e.open=!1}#a(e,t,n,r){for(;n<r&&e.open;){let i=e.need<0?6:e.need,a=Math.min(i-e.n,r-n);if(e.buf.set(t.subarray(n,n+a),e.n),e.n+=a,n+=a,e.n<i)break;if(e.need<0){if(!yu(e.buf,0)){this.#i(e);break}if(e.need=Cu(e.buf,0),e.buf.length<e.need){let t=new Uint8Array(e.need);t.set(e.buf.subarray(0,e.n)),e.buf=t}continue}e.open=!1,this.#n.push(e.buf,0,e.n)}return n}#o(e,t,n,r){e.open=!0,e.n=0,e.need=-1,this.#a(e,t,n,r)}frame(e){let t=this.#r,n=this.#t,r=n.frame;t.frames++;let i=(e[0]&63)<<4|e[1]>>4;if(e[0]>>6||i!==n.scid){t.damaged++;return}let a=e[1]>>1&7,o=this.#e[a];o||(this.#e[a]=o={buf:new Uint8Array(256),n:0,need:-1,count:-1,open:!1,orphan:!1}),t.vcs.add(a);let s=e[3];if(o.count>=0&&s!==(o.count+1&255)){let e=t.gaps.get(a)??[0,0];e[0]++,e[1]+=s-o.count-1&255,t.gaps.set(a,e),this.#i(o)}if(o.count=s,n.fecf&&ju(e,0,r)!==0){t.badFecf++,this.#i(o),o.orphan=!0;return}let c=e[1]&1,l=e[4]<<8|e[5],u=6;l&32768&&(u+=(e[6]&63)+1);let d=r-(c?4:0)-(n.fecf?2:0);if(u>d){t.damaged++,this.#i(o);return}if(l&16384){t.notPackets++;return}let f=l&2047;if(f===2046){t.idleFrames++;return}if(f===2047){o.open?this.#a(o,e,u,d):o.orphan||(t.partial++,o.orphan=!0);return}let p=u+f;if(p>=d){t.damaged++,this.#i(o);return}o.open?(this.#a(o,e,u,p),o.open&&this.#i(o)):f>0&&!o.orphan&&t.partial++,o.orphan=!1;let m=p;for(;m<d;){if(d-m>=6){if(!yu(e,m)){t.partial++;break}let n=Cu(e,m);if(m+n<=d){this.#n.push(e,m,n),m+=n;continue}}this.#o(o,e,m,d);break}}};const Vu={id:`ccsds`,label:`CCSDS space telemetry`,extensions:[`.bin`,`.dat`,`.tlm`,`.raw`,`.cadu`,`.tm`],companions:[`.xml`,`.xtce`].map(e=>({ext:e,anyName:!0})),sniff:e=>Ru(e)!==null||Du(e),sniffBytes:e=>Nu(e,0)>=0?196624:e.length>=6&&yu(e,0)?4*vu:0};var Hu=class extends Error{};const Uu=1e5,Wu=1e4,Gu=2e6,Ku=[[63072e3,10],[78796800,11],[94694400,12],[126230400,13],[157766400,14],[189302400,15],[220924800,16],[252460800,17],[283996800,18],[315532800,19],[362793600,20],[394329600,21],[425865600,22],[489024e3,23],[567993600,24],[631152e3,25],[662688e3,26],[709948800,27],[741484800,28],[773020800,29],[820454400,30],[867715200,31],[915148800,32],[1136073600,33],[1230768e3,34],[1341100800,35],[1435708800,36],[1483228800,37]];function qu(e){let t=0;for(let[n,r]of Ku)e>=n+r&&(t=r);return e-t}function Ju(e){switch(e){case`TAI`:return e=>qu(-378691200+e);case`GPS`:return e=>qu(315964819+e);case`J2000`:return e=>qu(946727967.816+e);case`UNIX`:case`POSIX`:return e=>e}let t=Date.parse(/[zZ]|[+-]\d\d:\d\d$/.test(e)?e:/T/.test(e)?`${e}Z`:`${e}T00:00:00Z`);return Number.isFinite(t)?e=>t/1e3+e:null}const Yu={seconds:1,picoSeconds:1e-12,days:86400},Xu=new DataView(new ArrayBuffer(8));function Zu(e,t){return t?(t,n)=>{let r=0;for(let i=e/8-1;i>=0;i--)r=r*256+ql(t,n+8*i,8);return r}:(t,n)=>ql(t,n,e)}function Qu(e){let t=V(e,`ContextCalibratorList`)?`ContextCalibratorList`:``,n=V(e,`DefaultCalibrator`);if(!n)return{cal:null,why:t};let r=n.kids[0];if(!r)return{cal:null,why:t};if(r.name===`PolynomialCalibrator`){let e=Gl(r,`Term`).map(e=>[W(U(e,`coefficient`))??0,W(U(e,`exponent`))??0]);return{cal:t=>e.reduce((e,[n,r])=>e+n*t**r,0),why:t}}if(r.name===`SplineCalibrator`){let e=W(U(r,`order`))??1,n=/^(true|1)$/.test(U(r,`extrapolate`)??``),i=Gl(r,`SplinePoint`).map(e=>[W(U(e,`raw`)),W(U(e,`calibrated`))]).filter(e=>e[0]!==null&&e[1]!==null).sort((e,t)=>e[0]-t[0]);if(i.length<2||e>1)return{cal:null,why:`SplineCalibrator${e>1?` of order ${e}`:``}`};let a=i.length-1;return{cal:t=>{if(!(t>=i[0][0]&&t<=i[a][0])&&!n)return NaN;let r=0;for(;r<a-1&&t>i[r+1][0];)r++;if(e===0)return t>=i[r+1][0]?i[r+1][1]:i[r][1];let[o,s]=i[r],[c,l]=i[r+1];return c===o?s:s+(l-s)*(t-o)/(c-o)},why:t}}return{cal:null,why:r.name}}function $u(e){let t=V(e,`SizeInBits`),n=W(H(V(t,`Fixed`),`FixedValue`)??H(t,`FixedValue`));return n!==null&&Number.isInteger(n)&&n>=0&&n<=65542*8?n:-1}function ed(e){let t=(e,t=-1)=>({bits:t,read:null,why:e,cal:null,calWhy:``});if(!e)return t(`no encoding`);if((U(e,`bitOrder`)??`mostSignificantBitFirst`)!==`mostSignificantBitFirst`)return t(`least significant bit first`);let n=U(e,`byteOrder`),r=V(e,`ByteOrderList`),i=n===`leastSignificantByteFirst`||r!==void 0&&U(r.kids[0]??e,`byteSignificance`)===`0`;if(n&&n!==`leastSignificantByteFirst`&&n!==`mostSignificantByteFirst`)return t(`byte order ${n}`);if(e.name===`StringDataEncoding`)return t(`a string`,$u(e));if(e.name===`BinaryDataEncoding`)return t(`binary data`,$u(e));let a=W(U(e,`sizeInBits`))??(e.name===`FloatDataEncoding`?32:8);if(!Number.isInteger(a)||a<1||a>64)return t(`${a} bits`);if(i&&a%8)return t(`little-endian with a size that is not whole bytes`,a);let{cal:o,why:s}=Qu(e),c=Zu(a,i),l=null,u=``;if(e.name===`IntegerDataEncoding`){let t=2**(a-1);switch(U(e,`encoding`)??`unsigned`){case`unsigned`:l=c;break;case`twosComplement`:case`twosCompliment`:l=(e,n)=>{let r=c(e,n);return r>=t?r-2*t:r};break;case`signMagnitude`:l=(e,n)=>{let r=c(e,n);return r>=t?-(r-t):r};break;case`onesComplement`:l=(e,n)=>{let r=c(e,n);return r>=t?-(2*t-1-r):r};break;default:u=`${U(e,`encoding`)} integers`}}else if(e.name===`FloatDataEncoding`){let t=U(e,`encoding`)??`IEEE754_1985`;t!==`IEEE754_1985`&&t!==`IEEE754`?u=`${t} floats`:a===32?l=(e,t)=>(Xu.setUint32(0,c(e,t)),Xu.getFloat32(0)):a===64?l=i?(e,t)=>{for(let n=0;n<8;n++)Xu.setUint8(7-n,ql(e,t+8*n,8));return Xu.getFloat64(0)}:(e,t)=>(Xu.setUint32(0,ql(e,t,32)),Xu.setUint32(4,ql(e,t+32,32)),Xu.getFloat64(0)):u=`${a}-bit floats`}else return t(e.name);return{bits:a,read:l,why:u,cal:o,calWhy:s}}const td=new Set([`IntegerDataEncoding`,`FloatDataEncoding`,`StringDataEncoding`,`BinaryDataEncoding`]),nd=e=>e?.kids.find(e=>td.has(e.name)),rd=e=>H(V(e,`UnitSet`),`Unit`)??``;function id(e){let t={unit:rd(e),kind:`number`,labels:[],time:null};switch(e.name){case`IntegerParameterType`:case`FloatParameterType`:{let n=ed(nd(e));return{...t,...n}}case`BooleanParameterType`:{let n=ed(nd(e));return{...t,...n,cal:null,kind:`bool`,labels:[[U(e,`zeroStringValue`)??`False`,0],[U(e,`oneStringValue`)??`True`,1]]}}case`EnumeratedParameterType`:{let n=ed(nd(e)),r=Gl(V(e,`EnumerationList`),`Enumeration`).flatMap(e=>{let t=W(U(e,`value`)),n=U(e,`label`);return t!==null&&n!==void 0?[[n,t]]:[]});return{...t,...n,cal:null,kind:`enum`,labels:r}}case`AbsoluteTimeParameterType`:case`RelativeTimeParameterType`:{let n=V(e,`Encoding`),r=ed(nd(n)),i=Yu[(n&&U(n,`units`))??`seconds`],a=(W(n&&U(n,`scale`))??1)*(i??1),o=(W(n&&U(n,`offset`))??0)*(i??1),s=e=>e*a+o;if(!i)return{...t,...r,read:null,why:`time in ${U(n,`units`)}`};if(e.name===`RelativeTimeParameterType`)return{...t,...r,unit:`s`,cal:s};let c=V(e,`ReferenceTime`),l=H(c,`Epoch`),u=l?Ju(l):V(c,`OffsetFrom`)?null:Ju(`TAI`);return u?{...t,...r,unit:`s`,cal:s,kind:`time`,time:u}:{...t,...r,read:null,why:l?`epoch ${l}`:`a time offset from another parameter`}}case`StringParameterType`:return{...t,...ed(nd(e)),read:null,why:`a string`};case`BinaryParameterType`:return{...t,...ed(nd(e)),read:null,why:`binary data`};case`AggregateParameterType`:return{...t,...ed(void 0),why:`an aggregate`};case`ArrayParameterType`:return{...t,...ed(void 0),why:`an array`};default:return{...t,...ed(void 0),why:e.name}}}function ad(e,t,n,r){let i=e=>{let t=[];for(let n of e.split(`/`))n===`..`?t.pop():n&&n!==`.`&&t.push(n);return`/${t.join(`/`)}`};if(n.startsWith(`/`))return e.get(i(n));for(let a=r;;a=a.slice(0,a.lastIndexOf(`/`))){let r=e.get(i(`${a}/${n}`));if(r!==void 0||!a)return r??t.get(n.slice(n.lastIndexOf(`/`)+1))}}const od={ArrayParameterRefEntry:`an array entry`,IndirectParameterRefEntry:`an indirect parameter entry`,StreamSegmentEntry:`a stream segment entry`,ParameterSegmentRefEntry:`a parameter segment entry`,ContainerSegmentRefEntry:`a container segment entry`};var sd=class{params=[];containers=[];roots=[];chans=[];timeParam=[];notes=[];short=!1;#e=new Float64Array;#t=new Float64Array;#n=new Int32Array;#r=0;#i=0;constructor(e){let t=V(Wl(e),`SpaceSystem`);if(!t)throw new Hu(`it has no <SpaceSystem> element`);let n=new Map,r=new Map,i=new Map,a=new Map,o=new Map,s=new Map,c=[],l=[],u=[[t,``]];for(;u.length;){let[e,t]=u.pop(),d=`${t}/${U(e,`name`)??``}`,f=V(e,`TelemetryMetaData`);for(let e of V(f,`ParameterTypeSet`)?.kids??[]){let t=U(e,`name`);t&&(n.set(`${d}/${t}`,[e,d]),r.has(t)||r.set(t,[e,d]))}for(let e of Gl(V(f,`ParameterSet`),`Parameter`)){let t=U(e,`name`);if(t){if(l.length>=Uu)throw new Hu(`it defines more than ${Uu.toLocaleString(`en-US`)} parameters`);i.set(`${d}/${t}`,l.length),a.has(t)||a.set(t,l.length),l.push([e,d])}}for(let e of Gl(V(f,`ContainerSet`),`SequenceContainer`)){let t=U(e,`name`);if(t){if(c.length>=Wu)throw new Hu(`it defines more than ${Wu.toLocaleString(`en-US`)} containers`);o.set(`${d}/${t}`,c.length),s.has(t)||s.set(t,c.length),c.push([e,d])}}let p=Gl(e,`SpaceSystem`);for(let e=p.length-1;e>=0;e--)u.push([p[e],d])}if(!c.length)throw new Hu(`it has no SequenceContainers`);let d=new Map,f=new Map,p=new Map;for(let[e,t]of l){let i=U(e,`name`),a=U(e,`parameterTypeRef`),o=a?ad(n,r,a,t):void 0,s=o&&p.get(o[0]);o&&!s&&p.set(o[0],s=id(o[0]));let c=s??{...id({name:`no type`,attrs:``,kids:[],text:``}),why:`no type`};this.params.push({name:i,unit:c.unit,bits:c.bits,read:c.why?null:c.read,cal:c.cal,kind:c.kind,labels:c.labels,time:c.time})}let m=e=>{let[t,i]=l[e],a=U(t,`parameterTypeRef`),o=a?ad(n,r,a,i):void 0,s=o&&p.get(o[0]);return s?[s.why,s.calWhy]:[`no type`,``]},h=(e,t,n,r,o,s)=>{let c=ad(i,a,e,o),l=!/^(false|0)$/.test(n??`true`);if(c===void 0||![`==`,`!=`,`<`,`<=`,`>`,`>=`].includes(t))return d.set(s,`a comparison it cannot read`),null;let u=this.params[c],f;return l&&(u.kind===`enum`||u.kind===`bool`)?(f=u.labels.find(([e])=>e===r)?.[1],f===void 0&&u.kind===`bool`&&(f=/^(true|1)$/i.test(r)?1:/^(false|0)$/i.test(r)?0:void 0)):f=W(r)??void 0,f===void 0?(d.set(s,`a comparison with ${r}`),null):{p:c,cal:l,op:t,v:f}},g=(e,t,n)=>{if(e.name===`Condition`){let r=Gl(e,`ParameterInstanceRef`),i=H(e,`Value`);return r.length!==1||i===void 0?(d.set(n,`a condition against another parameter`),null):h(U(r[0],`parameterRef`)??``,(H(e,`ComparisonOperator`)??`==`).trim(),U(r[0],`useCalibratedValue`),i.trim(),t,n)}if(e.name!==`ANDedConditions`&&e.name!==`ORedConditions`)return d.set(n,`a ${e.name}`),null;let r=[];for(let i of e.kids){let e=g(i,t,n);if(!e)return null;r.push(e)}return{and:e.name===`ANDedConditions`,of:r}},_=(e,t,n)=>{if(!e)return null;let r=e.kids[0];if(r?.name===`BooleanExpression`&&r.kids[0])return g(r.kids[0],t,n)??`unsupported`;let i=r?.name===`Comparison`?[r]:r?.name===`ComparisonList`?Gl(r,`Comparison`):null;if(!i)return d.set(n,`a ${r?.name??`condition`}`),`unsupported`;let a=[];for(let e of i){let r=h(U(e,`parameterRef`)??``,U(e,`comparisonOperator`)??`==`,U(e,`useCalibratedValue`),U(e,`value`)??``,t,n);if(!r)return`unsupported`;a.push(r)}return a.length===1?a[0]:{and:!0,of:a}};c.forEach(([e,t])=>{let n=U(e,`name`),r=V(e,`BaseContainer`),c=-1,l=!1,u=null;if(r){let e=ad(o,s,U(r,`containerRef`)??``,t);e===void 0?(d.set(`container ${n}`,`its base container is not defined`),l=!0):c=e;let i=_(V(r,`RestrictionCriteria`),t,`container ${n}`);i===`unsupported`?l=!0:u=i}let p=[];for(let r of V(e,`EntryList`)?.kids??[]){let e=(e,t)=>{d.set(e,t),p.push({p:-1,c:-1,abs:-1,rel:0,cond:null,stop:!0})};if(od[r.name]){e(`${n} entry`,od[r.name]);continue}if(r.name!==`ParameterRefEntry`&&r.name!==`ContainerRefEntry`)continue;let c=U(r,r.name===`ParameterRefEntry`?`parameterRef`:`containerRef`)??``;if(V(r,`RepeatEntry`)){e(c,`a RepeatEntry`);continue}let l=V(r,`LocationInContainerInBits`),u=-1,h=0;if(l){let t=W(H(l,`FixedValue`)),n=U(l,`referenceLocation`)??`previousEntry`;if(t===null||!Number.isInteger(t)||Math.abs(t)>65542*8){e(c,`a location that is not a fixed value`);continue}if(n===`containerStart`)u=t;else if(n===`previousEntry`)h=t;else{e(c,`a location from the ${n===`containerEnd`?`container end`:`next entry`}`);continue}}let g=_(V(r,`IncludeCondition`),t,c);if(g===`unsupported`){p.push({p:-1,c:-1,abs:-1,rel:0,cond:null,stop:!0});continue}if(r.name===`ContainerRefEntry`){let n=ad(o,s,c,t);if(n===void 0){e(c,`not defined`);continue}p.push({p:-1,c:n,abs:u,rel:h,cond:g,stop:!1});continue}let v=ad(i,a,c,t);if(v===void 0){e(c,`not defined`);continue}let y=this.params[v],[b,x]=m(v);b&&d.set(y.name,b),x&&f.set(y.name,x),p.push({p:v,c:-1,abs:u,rel:h,cond:g,stop:y.bits<0})}this.containers.push({name:n,abstract:/^(true|1)$/.test(U(e,`abstract`)??``),base:c,never:l,restrict:u,entries:p,kids:[]})}),this.containers.forEach((e,t)=>{let n=0;for(let r=e.base;r>=0;r=this.containers[r].base){if(r===t)throw new Hu(`its containers inherit from each other in a loop`);if(++n>64)throw new Hu(`its containers inherit through more than 64 base containers`)}e.base>=0&&this.containers[e.base].kids.push(t)});let v=new Uint8Array(this.containers.length),y=(e,t)=>{if(v[e]!==2){if(v[e]===1)throw new Hu(`its containers refer to each other in a loop`);if(t>64)throw new Hu(`its containers nest more than 64 deep`);v[e]=1;for(let n of this.containers[e].entries)n.c>=0&&y(n.c,t+1);v[e]=2}};this.containers.forEach((e,t)=>y(t,0)),this.roots=this.containers.flatMap((e,t)=>e.base<0&&e.kids.length?[t]:[]),this.roots.length||(this.roots=this.containers.flatMap((e,t)=>e.base<0&&!e.abstract?[t]:[]));let b=0,x=[],S=new Set,C=(e,t,n,r)=>{for(let i of this.containers[e].entries){if(++b>Gu)throw new Hu(`its containers nest more than ${Gu.toLocaleString(`en-US`)} entries`);if(i.stop){i.cond||(r=!1);continue}i.abs>=0&&(r=n),i.c>=0?r=C(i.c,t,r,r):i.p>=0&&this.params[i.p].read&&(r?t.add(i.p):S.add(i.p))}return r};if(this.containers.forEach((e,t)=>{if(this.chans.push([]),this.timeParam.push(-1),e.abstract)return;let n=[];for(let e=t;e>=0;e=this.containers[e].base)n.unshift(e);let r=new Set;S=new Set;let i=!0;for(let e of n)i=C(e,r,!0,i);let a=[...r],o=a.find(e=>this.params[e].kind===`time`)??-1;this.timeParam[t]=o,this.chans[t]=a.filter(e=>e!==o);let s=[...S].filter(e=>!r.has(e)).map(e=>this.params[e].name);s.length&&x.push(`${s.join(`, `)} in ${e.name}`)}),d.size){let e=[...d].map(([e,t])=>`${e} (${t})`);this.notes.push(`Not decoded from the XTCE: ${e.slice(0,20).join(`, `)}${e.length>20?`, and ${e.length-20} more`:``}.`)}if(x.length&&this.notes.push(`Not read (they follow an entry of no fixed size): ${x.slice(0,20).join(`; `)}${x.length>20?`; and ${x.length-20} more containers`:``}.`),f.size){let e=[...f].map(([e,t])=>`${e} (${t})`);this.notes.push(`Calibrators not applied: ${e.slice(0,20).join(`, `)}${e.length>20?`, and ${e.length-20} more`:``}.`)}let w=this.params.length;this.#e=new Float64Array(w),this.#t=new Float64Array(w),this.#n=new Int32Array(w)}#a(e){if(!e)return!0;if(`of`in e){for(let t of e.of)if(this.#a(t)!==e.and)return!e.and;return e.and}if(this.#n[e.p]!==this.#r)return!1;let t=e.cal?this.#t[e.p]:this.#e[e.p];return e.op===`==`?t===e.v:e.op===`!=`?t!==e.v:e.op===`<`?t<e.v:e.op===`<=`?t<=e.v:e.op===`>`?t>e.v:t>=e.v}#o(e,t,n,r,i,a){for(let o of this.containers[e].entries){if(--this.#i<0)return NaN;if(o.cond&&!this.#a(o.cond))continue;if(o.stop){n=NaN;continue}if(n=o.abs>=0?t+o.abs:n+o.rel,o.c>=0){n=this.#o(o.c,n,n,r,i,a);continue}let e=this.params[o.p];if(!(n>=0&&n+e.bits<=a)){n>=0&&(this.short=!0),n+=e.bits;continue}if(e.read){let t=e.read(r,i+n);this.#e[o.p]=t,this.#t[o.p]=e.cal?e.cal(t):e.kind===`bool`?+!!t:t,this.#n[o.p]=this.#r}n+=e.bits}return n}#s(e,t,n,r){this.#r=this.#r+1|0,this.short=!1;let i=0;for(let a of e)i=this.#o(a,0,i,t,n,r)}#c(e,t,n,r,i){let a=this.containers[e[e.length-1]];for(let o of a.kids){let a=this.containers[o];if(a.never||!this.#a(a.restrict))continue;e.push(o);let s=this.#c(e,this.#o(o,0,t,n,r,i),n,r,i);if(s>=0)return s;e.pop(),this.#s(e,n,r,i)}return a.abstract?-1:e[e.length-1]}decode(e,t,n){for(let r of this.roots){this.#r=this.#r+1|0,this.short=!1,this.#i=8*n+256;let i=this.#c([r],this.#o(r,0,0,e,t*8,n*8),e,t*8,n*8);if(i>=0)return i}return-1}value(e){return this.#n[e]===this.#r?this.#t[e]:NaN}time(e){let t=this.timeParam[e];return t<0?NaN:this.params[t].time(this.value(t))}};const cd=2e3,ld=1e5,ud=(e,t,n=`${t}s`)=>`${e.toLocaleString(`en-US`)} ${e===1?t:n}`,dd=e=>e===1?`was`:`were`,fd=e=>`0x${e.toString(16).toUpperCase().padStart(3,`0`)}`,pd=(e,t=10)=>`${e.slice(0,t).join(`, `)}${e.length>t?`, and ${e.length-t} more`:``}`;async function*md(e,t,n,r,i,a){let o=new Tu(n,r),s=new Uint8Array,c={on:!1},l=t&&new Bu(t,o,i),u=t?new Uint8Array(t.frame):null,d=!0;for await(let n of e.windows(0,e.size)){a?.throwIfAborted();let f=n.offset+n.bytes.length>=e.size,p=n.bytes;s.length&&(p=new Uint8Array(s.length+n.bytes.length),p.set(s),p.set(n.bytes,s.length));let m=0;if(!t)m=Eu(p,o,r,f,c);else{d&&(m=t.start,i.outOfSync+=m);let e=4+t.frame;for(;f?m+e<=p.length:m+Math.max(e,t.cadu)<=p.length;){if(!Mu(p,m)){if(Iu(p,m)){i.badSync++,m+=t.cadu;continue}let e=Nu(p,m+1),n=e>=0?e:f?p.length:Math.max(m,p.length-3);if(i.outOfSync+=n-m,m=n,e<0)break;continue}let n=p.subarray(m+4,m+e);if(t.randomized){u.set(n);for(let e=0;e<n.length;e++)u[e]^=ku[e%255];n=u}l.frame(n),m+=t.cadu}f&&m<p.length&&(p.length-m>4&&(r.cut=!0),m=p.length)}d=!1,s=p.slice(m),yield}}async function hd(e,t){let n=e.filter(e=>/\.(xml|xtce)$/i.test(e.name));if(!n.length)return null;let r=n[0];for(let e of n.slice(1))t.push(`${e.name} was not used: ${r.name} is the XTCE file.`);try{if(r.size>52428800)throw new Hu(`it is larger than 50 MB`);let e=new sd(d(new Uint8Array(await r.arrayBuffer())));return t.push(...e.notes),e}catch(e){let n=e instanceof Hu?e.message:e instanceof B?`it nests deeper than 256 elements`:`it may be damaged`;return t.push(`${r.name} isn't a usable XTCE file (${n}); every APID is read as raw bytes of its data field.`),null}}const gd=(e,t,n,r)=>{let i=e?e.decode(t,n,r):-1;return i>=0&&e.chans[i].length?i:-1};async function _d(e,t){let n=[],r={},i=Ru(await t.read(0,196624));if(i&&i.version!==0)throw Error(`These are CCSDS ${i.version===1?`AOS (732.0-B)`:i.version===12?`USLP (732.1-B)`:`version ${i.version}`} transfer frames, which Kymoscope does not read; TM frames (132.0-B) and Space Packets are read.`);let a=await hd(e.companions,n),o=wu(),s=zu(),c=new Map,l=new Map,u=1/0,d=0,f=0,p=0,m=(e,t,n)=>{d++;let r=gd(a,e,t,n);if(r>=0){if(a.short&&f++,a.timeParam[r]>=0){let e=a.time(r);if(!Number.isFinite(e)){p++;return}u=Math.min(u,e)}c.set(r,(c.get(r)??0)+1);return}let i=bu(e,t),o=l.get(i);o?(o.n++,o.width=Math.max(o.width,n-6)):l.set(i,{n:1,width:n-6})};for(let e=md(t,i,m,o,s);!(await e.next()).done;);if(!d)throw Error(i?`This file has CCSDS TM frames but no Space Packets Kymoscope could read in them.`:`This file has no CCSDS Space Packets Kymoscope could read.`);let h=[],g=0,_=0,v=e=>h.length>=cd||g+e.channels.length>ld?(_++,-1):(g+=e.channels.length,h.push(e),h.length-1),y=new Int32Array(a?.containers.length??0).fill(-1);if(a)for(let e of[...c.keys()].sort((e,t)=>e-t)){let t=a.containers[e],i=a.chans[e].map(e=>a.params[e]),o=cn(i.map(e=>e.name)),s=a.timeParam[e]>=0;s||n.push(`${t.name} has no AbsoluteTime parameter in the XTCE: its packets are numbered.`),y[e]=v({name:t.name,channels:i.map((e,t)=>({name:o[t],unit:e.unit})),samples:c.get(e),time:s?{kind:`timestamps`}:{kind:`index`},rateHz:null,irregular:s||void 0});for(let e of i)e.labels.length&&(e.kind===`enum`||e.kind===`bool`)&&(r[`${e.name} values`]=e.labels.map(([e,t])=>`${t} = ${e}`).join(`, `))}let b=new Map,x=[...l].sort((e,t)=>e[0]-t[0]),S=[];for(let[e,t]of x){let n=`APID ${fd(e)}`,r=Math.min(t.width,256);t.width>256&&S.push(n),b.set(e,{g:v({name:n,channels:Array.from({length:r},(e,t)=>({name:`${n} b${t}`,unit:``})),samples:t.n,time:{kind:`index`},rateHz:null}),width:r})}let C=x.map(([e])=>fd(e));!a&&!n.length?n.push(`No XTCE file came with the telemetry: every APID is read as raw bytes of its data field, numbered (no time).`):a&&C.length&&n.push(`Not in the XTCE: ${C.length===1?`APID`:`APIDs`} ${pd(C)}; read as raw bytes of the data field, numbered (no time).`);for(let e of S)n.push(`${e}: only the first 256 bytes of its data field are read.`);f&&n.push(`${ud(f,`packet`)} shorter than ${f===1?`its`:`their`} XTCE container: the values past ${f===1?`its`:`their`} end are empty.`),p&&n.push(`${ud(p,`packet`)} with no usable time ${dd(p)} skipped.`),s.badFecf&&n.push(`${ud(s.badFecf,`frame`)} failed ${s.badFecf===1?`its`:`their`} FECF check and ${dd(s.badFecf)} skipped.`);let w=[...s.gaps].sort((e,t)=>e[0]-t[0]);if(w.length){let e=w.reduce((e,[,[t]])=>e+t,0);n.push(`${ud(e,`frame-count gap`)} (${w.map(([e,[,t]])=>`VC ${e}, ${ud(t,`frame`)} missing`).join(`; `)}).`)}s.damaged&&n.push(`${ud(s.damaged,`frame`)} of another spacecraft or version, or with a damaged data field, ${dd(s.damaged)} skipped.`),s.notPackets&&n.push(`${ud(s.notPackets,`frame`)} carrying VCA data rather than packets ${dd(s.notPackets)} skipped.`),s.idleFrames&&n.push(`${ud(s.idleFrames,`idle frame`)} ${dd(s.idleFrames)} skipped.`),o.idle&&n.push(`${ud(o.idle,`idle packet`)} ${dd(o.idle)} skipped.`),s.partial&&n.push(`${ud(s.partial,`partial packet`)} ${dd(s.partial)} dropped (frame-count gaps, frames skipped).`),o.segments&&n.push(`${ud(o.segments,`packet segment`)} out of order ${dd(o.segments)} dropped.`),o.skipped&&n.push(`${ud(o.skipped,`byte`)} that hold${o.skipped===1?`s`:``} no packet ${dd(o.skipped)} skipped.`),s.outOfSync&&n.push(`${ud(s.outOfSync,`byte`)} out of sync (no ASM where a frame should start) ${dd(s.outOfSync)} skipped.`),s.badSync&&n.push(`${ud(s.badSync,`frame`)} with a damaged sync marker (ASM) ${dd(s.badSync)} skipped.`),i&&i.frame<i.cadu-4&&n.push(`Reed-Solomon check bytes present (not corrected): the ${i.cadu}-byte CADUs are read as frames of ${i.frame} bytes.`),_&&n.push(`${ud(_,`group`)} past ${cd.toLocaleString(`en-US`)} groups or ${ld.toLocaleString(`en-US`)} channels ${dd(_)} not read.`),o.cut&&n.push(`The file ends in the middle of a ${i?`frame`:`packet`}.`),i&&(r.Spacecraft=`0x${i.scid.toString(16).toUpperCase()}`,r.Frames=`${s.frames} (${[...s.vcs].sort((e,t)=>e-t).map(e=>`VC ${e}`).join(`, `)})`,r.FECF=i.fecf?`checked`:`none`),r.Packets=String(d),cn(h.map(e=>e.name),[]).forEach((e,t)=>{h[t].name=e});let T={shape:i,dict:a,t0:u,leafGroup:y,raw:b};return{format:i?`CCSDS TM frames (${i.frame} bytes${i.randomized?`, randomized`:``})`:`CCSDS Space Packets`,startTime:Number.isFinite(u)?new Date(u*1e3).toISOString():null,groups:h,meta:r,events:[],notes:n,interleaved:!0,state:T}}const vd={...Vu,async plan(e,t){try{return await _d(e,t)}catch(e){throw k(e)}},async*stream(e){let t=e.plan.state,n=new Map,r=e=>{e.cap=Math.max(1,Math.min(65536,e.total-e.start,Math.floor(4e6/Math.max(1,e.cols.length)))),e.time&&=new Float64Array(e.cap),e.cols=e.cols.map(()=>new Float64Array(e.cap).fill(NaN))};for(let t of e.selection){let i=e.plan.groups[t.group],a=p(e,t.group),o={cols:a.map(()=>new Float64Array),sel:a,time:i.time.kind===`timestamps`?new Float64Array:null,n:0,cap:0,start:0,total:i.samples};r(o),n.set(t.group,o)}let i=[],a=(e,t)=>{let n=t.n===t.cap;if(i.push({group:e,time:t.time&&(n?t.time:t.time.slice(0,t.n)),start:t.start,length:t.n,columns:t.cols.map(e=>n?e:e.slice(0,t.n))}),t.start+=t.n,n)r(t);else for(let e of t.cols)e.fill(NaN,0,t.n);t.n=0},o,s=-1,c=(e,t)=>(o=n.get(e),!o||o.start+o.n>=o.total?!1:(o.n===o.cap&&a(e,o),s=o.n++,o.time&&(o.time[s]=t),!0)),l=t.dict,u=0,d=(e,r,i)=>{if(++u%4096==0)for(let[e,t]of n)t.n&&a(e,t);let d=gd(l,e,r,i);if(d>=0){let e=0;if(l.timeParam[d]>=0){if(e=l.time(d),!Number.isFinite(e))return;e-=t.t0}let n=t.leafGroup[d];if(n<0||!c(n,e))return;let r=l.chans[d],{sel:i,cols:a}=o;for(let e=0;e<i.length;e++)a[e][s]=l.value(r[i[e]]);return}let f=t.raw.get(bu(e,r));if(!f||f.g<0||!c(f.g,0))return;let{sel:p,cols:m}=o;for(let t=0;t<p.length;t++)p[t]<i-6&&(m[t][s]=e[r+6+p[t]])};try{for(let n=md(e.io,t.shape,d,wu(),zu(),e.signal);!(await n.next()).done;)yield*i,i.length=0}catch(e){throw k(e)}for(let[e,t]of n)t.n&&a(e,t);yield*i},streamGroup(e,t){return this.stream({...e,selection:e.selection.filter(e=>e.group===t)})}};function yd(e,t,n){if(e.length<t+10)return!1;let r=new DataView(e.buffer,e.byteOffset,e.byteLength),i=r.getUint16(t,n),a=r.getUint16(t+2,n);return i>=1900&&i<=2100&&a>=1&&a<=366&&e[t+4]<=23&&e[t+5]<=59&&e[t+6]<=60}function bd(e,t=0){if(e.length<t+48)return!1;for(let n=0;n<6;n++){let r=e[t+n];if(!(r===32||r>=48&&r<=57))return!1}return!`DRQM`.includes(String.fromCharCode(e[t+6]))||!(e[t+7]===32||e[t+7]===0)?!1:yd(e,t+20,!1)||yd(e,t+20,!0)}const xd=(e,t=0)=>e.length>=t+40&&e[t]===77&&e[t+1]===83&&e[t+2]===3,Sd={id:`mseed`,label:`MiniSEED`,extensions:[`.mseed`,`.miniseed`,`.ms`],sniff:e=>xd(e)||bd(e)},Cd=`This MiniSEED file's compressed data is damaged.`;function wd(e,t,n,r=!1){let i=new Int32Array(n);if(n===0)return i;let a=new DataView(e.buffer,e.byteOffset,e.byteLength),o=Math.floor(e.length/64);if(o===0)throw Error(Cd);let s=a.getInt32(4,r),c=a.getInt32(8,r),l=0,u=e=>{l<n&&(i[l++]=e)};for(let e=0;e<o&&l<n;e++){let i=e*64,o=a.getUint32(i,r);for(let s=e===0?3:1;s<16&&l<n;s++){let e=o>>>30-2*s&3;if(e===0)continue;let n=a.getInt32(i+4*s,r);if(e===1){for(let e=0;e<4;e++)u(a.getInt8(i+4*s+e));continue}if(t===1){e===2?(u(a.getInt16(i+4*s,r)),u(a.getInt16(i+4*s+2,r))):u(n);continue}let c=n>>>30;if(e===2)if(c===1)u(n<<2>>2);else if(c===2)u(n<<2>>17),u(n<<17>>17);else if(c===3)for(let e=0;e<3;e++)u(n<<2+10*e>>22);else throw Error(Cd);else if(c===0)for(let e=0;e<5;e++)u(n<<2+6*e>>26);else if(c===1)for(let e=0;e<6;e++)u(n<<2+5*e>>27);else if(c===2)for(let e=0;e<7;e++)u(n<<4+4*e>>28);else throw Error(Cd)}}if(l<n)throw Error(Cd);i[0]=s;for(let e=1;e<n;e++)i[e]=i[e-1]+i[e];if(i[n-1]!==c)throw Error(Cd);return i}const Td={1:2,3:4,4:4,5:8},Ed={1:1/2,3:1/4,4:1/4,5:1/8,10:1,11:7/4},Dd=65536,Od=(e,t,n,r,i)=>Date.UTC(e,0,1,n,r,i)+(t-1)*864e5;function kd(e,t){return e===0||t===0?0:e>0?t>0?e*t:-e/t:t>0?-t/e:1/(e*t)}function Ad(e){let t=/^FDSN:([^_]*)_([^_]*)_([^_]*)_(.*)$/.exec(e);return t?`${t[1]}.${t[2]}.${t[3]}.${t[4].replace(/_/g,``)}`:e}function jd(e,t){let n=i(e),r=e[33],a=n.getUint16(34,!0),o=n.getUint32(36,!0),s=40+r+a+o,c=n.getFloat64(16,!0);c<0&&(c=-1/c);let l=Od(n.getUint16(8,!0),n.getUint16(10,!0),e[12],e[13],e[14])*1e3+n.getUint32(4,!0)/1e3;return{rec:{data:t+40+r+a,dataLen:o,enc:e[15],n:n.getUint32(24,!0),le:!0,steimLe:!1,t:l,rate:c,source:Ad(u(e.subarray(40,40+r)))},length:s}}async function Md(e,t,n){let r=!yd(t,20,!1),a=i(t),o=(e,n)=>u(t.subarray(e,n)).trim(),s=`${o(18,20)}.${o(8,13)}.${o(13,15)}.${o(15,18)}`,c=kd(a.getInt16(32,r),a.getInt16(34,r)),l=Od(a.getUint16(20,r),a.getUint16(22,r),t[24],t[25],t[26])*1e3+a.getUint16(28,r)*100;t[36]&2||(l+=a.getInt32(40,r)*100);let d=-1,f=r,p=0;for(let e=a.getUint16(46,r),n=0;e>=48&&e+8<=t.length&&n<64;n++){let n=a.getUint16(e,r);n===1e3?(d=t[e+4],f=t[e+5]===0,p=t[e+6]>=7&&t[e+6]<=20?2**t[e+6]:0):n===1001?l+=a.getInt8(e+5):n===100&&(c=a.getFloat32(e+4,r));let i=a.getUint16(e+2,r);if(i<=e)break;e=i}if(!p){for(let t of[4096,512,256,1024,2048,8192,128,16384,32768,65536])if(n+t===e.size||n+t<e.size&&bd(await e.read(n+t,64))){p=t;break}return p?{rec:null,length:p,skipped:`without blockette 1000 (no encoding)`}:{rec:null,length:0}}let m=a.getUint16(44,r);return m<48||m>p?{rec:null,length:p,skipped:`with a damaged header`}:{rec:{data:n+m,dataLen:p-m,enc:d,n:a.getUint16(30,r),le:f,steimLe:f,t:l,rate:c,source:s},length:p}}async function*Nd(e,t){let n=e.selection.find(e=>e.group===t);if(!n||n.channels.length===0)return;let r=e.plan.state,i=e.plan.groups[t].samples,a=0,o=new Float64Array(Math.min(Dd,i)),s=0,c=()=>{let e={group:t,time:null,start:a,length:s,columns:n.channels.map((e,t)=>t?o.slice():o)};return a+=s,s=0,o=new Float64Array(Math.min(Dd,i-a)),e};for(let n of r.groups[t]){e.signal?.throwIfAborted();for(let e=0;e<n.pad;){let t=Math.min(n.pad-e,o.length-s);o.fill(NaN,s,s+t),s+=t,e+=t,s===o.length&&(yield c())}let t=r.recs[n.rec],i=t.damaged?new Float64Array(t.n).fill(NaN):Pd(t,await e.io.read(t.data,t.dataLen));for(let e=n.skip;e<i.length;){let t=Math.min(i.length-e,o.length-s);o.set(i.subarray(e,e+t),s),s+=t,e+=t,s===o.length&&(yield c())}}}function Pd(e,t){if(e.enc===10||e.enc===11)return wd(t,e.enc===10?1:2,e.n,e.steimLe);let n=i(t),r=new Float64Array(e.n),a=Td[e.enc];for(let t=0,i=0;t<e.n;t++,i+=a)r[t]=e.enc===1?n.getInt16(i,e.le):e.enc===3?n.getInt32(i,e.le):e.enc===4?n.getFloat32(i,e.le):n.getFloat64(i,e.le);return r}const Fd={...Sd,async plan(e,t){let n=[],r=[],i=new Map,a=e=>i.set(e,(i.get(e)??0)+1),o=new Set,s=0;for(let e=0;e<t.size;){let i=await t.read(e,4096),c=xd(i);if(!c&&!bd(i)){r.push(`The last ${t.size-e} bytes of the file are not MiniSEED records and were not read.`);break}let l=c?jd(i,e):await Md(t,i,e);if(!l.length||e+l.length>t.size){r.push(`The file ends inside a record (damaged or cut short): the data from byte ${e} on was not read.`);break}o.add(c?3:2),e+=l.length;let u=l.rec;if(!u){a(l.skipped);continue}if(u.n!==0){if(!(u.enc in Ed)){a(`in encoding ${u.enc}, which Kymoscope cannot read`);continue}if(u.n>u.dataLen*Ed[u.enc]){a(`declaring more samples than they hold (damaged)`);continue}if(!(Number.isFinite(u.rate)&&u.rate>0)){a(`without a sample rate`);continue}if(u.enc===10||u.enc===11){let n=u.data-(e-l.length);try{Pd(u,n+u.dataLen<=i.length?i.subarray(n,n+u.dataLen):await t.read(u.data,u.dataLen))}catch{u.damaged=!0,s++}}n.push(u)}}s&&r.push(`${s} damaged record${s===1?` was`:`s were`} left empty.`);for(let[e,t]of i)r.push(`${t} record${t===1?``:`s`} ${e} ${t===1?`was`:`were`} skipped.`);if(n.length===0)throw Error(`This MiniSEED file has no data records Kymoscope can read.`);let c=new Map;n.forEach((e,t)=>{let n=c.get(e.source);n?n.push(t):c.set(e.source,[t])});let l=n.reduce((e,t)=>Math.min(e,t.t),1/0),u=[],d=[];for(let[e,t]of c){t.sort((e,t)=>n[e].t-n[t].t);let i=!1,a=0,o=null,s=()=>{if(!o)return;let t=a++?`${e} (${a})`:e;u.push({name:t,channels:[{name:t,unit:`counts`}],samples:o.samples,time:{kind:`rate`,rate:o.rate,start:(o.start-l)/1e6},rateHz:o.rate}),d.push(o.pieces)};for(let e of t){let t=n[e];if(o&&Math.abs(t.rate-o.rate)<=1e-6*o.rate){let n=(t.t-o.start)/1e6*o.rate-o.samples;if(n>.5&&(Math.round(n)>=1e4||o.padded+Math.round(n)>o.samples-o.padded+t.n))s(),o=null;else{let r=n>.5?Math.round(n):0,a=n<-.5?Math.round(-n):0;if(a&&(i=!0),a>=t.n)continue;o.pieces.push({rec:e,skip:a,pad:r}),o.samples+=r+t.n-a,o.padded+=r;continue}}else s();o={rate:t.rate,start:t.t,samples:t.n,padded:0,pieces:[{rec:e,skip:0,pad:0}]}}s(),i&&r.push(`${e}: records overlap; the samples read first were kept and the overlapping ones dropped.`)}let f={recs:n,groups:d};return{format:`MiniSEED ${[...o].sort().join(` + `)}`,startTime:new Date(Math.floor(l/1e3)).toISOString(),groups:u,meta:{records:String(n.length)},events:[],notes:r,state:f}},streamGroup:(e,t)=>Nd(e,t),async*stream(e){for(let t of e.selection)yield*Nd(e,t.group)}},Id={id:`ulog`,label:`PX4 ULog`,extensions:[`.ulg`],sniff:e=>f(e,`ULog5`)},Ld={int8_t:[1,0],uint8_t:[1,1],int16_t:[2,2],uint16_t:[2,3],int32_t:[4,4],uint32_t:[4,5],int64_t:[8,6],uint64_t:[8,7],float:[4,8],double:[8,9],bool:[1,10],char:[1,11]},Rd=65535,zd=1e5,Bd=[`EMERGENCY`,`ALERT`,`CRITICAL`,`ERROR`,`WARNING`,`NOTICE`,`INFO`,`DEBUG`];function Vd(e){let t=e.indexOf(`:`);if(t<0)throw Error(`bad format`);let n=[];for(let r of e.slice(t+1).split(`;`)){if(!r)continue;let[e,t]=r.split(` `),i=e.indexOf(`[`),a=i<0?0:Number(e.slice(i+1,e.indexOf(`]`)));if(!t||!(Number.isInteger(a)&&a>=0&&a<=Rd))throw Error(`bad field`);n.push({type:i<0?e:e.slice(0,i),n:a,name:t})}return[e.slice(0,t),n]}function Hd(e,t){let n=new Map,r=(t,i)=>{if(Ld[t])return Ld[t][0];let a=n.get(t);if(a!==void 0)return a;let o=e.get(t);if(!o)throw Error(`its format uses ${t}, which the file does not define`);if(i>8)throw Error(`its format nests too deep`);let s=0;for(let e of o)if((s+=r(e.type,i+1)*Math.max(1,e.n))>Rd)throw Error(`its format is larger than a message`);return n.set(t,s),s};r(t,0);let i=[],a=-1,o=0,s=(t,n,c,l)=>{if(l>8)throw Error(`its format nests too deep`);for(let u of e.get(t)){let e=r(u.type,l+1),t=Math.max(1,u.n);if(u.name.startsWith(`_padding`)){c+=e*t;continue}let d=Ld[u.type];if(l===0&&u.name===`timestamp`&&u.type===`uint64_t`&&u.n===0)a=c;else if(d?.[1]===11)i.push({name:n+u.name,code:11,off:c,n:t});else if(d)for(let r=0;r<t;r++)i.push({name:n+u.name+(u.n?`[${r}]`:``),code:d[1],off:c+r*e,n:1});else if(e>0)for(let r=0;r<t;r++)s(u.type,`${n}${u.name}${u.n?`[${r}]`:``}.`,c+r*e,l+1);c+=e*t,l===0&&(o=c)}};if(s(t,``,0,0),a<0)throw Error(`its format has no uint64_t timestamp`);return{leaves:i,tsOff:a,minSize:o}}async function*Ud(e,t,n,r,a){let o=new Uint8Array;for await(let r of e.windows(16,t-16)){a?.throwIfAborted();let e=r.bytes;if(o.length){let t=new Uint8Array(o.length+e.length);t.set(o),t.set(e,o.length),e=t}let t=i(e),s=0;for(;!(s+3>e.length);){let r=e[s]|e[s+1]<<8;if(s+3+r>e.length)break;n(e[s+2],e,t,s+3,r),s+=3+r}o=e.slice(s),yield}r.cut=o.length>0}function Wd(e,t,n){switch(n){case 0:return e.getInt8(t);case 1:return e.getUint8(t);case 2:return e.getInt16(t,!0);case 3:return e.getUint16(t,!0);case 4:return e.getInt32(t,!0);case 5:return e.getUint32(t,!0);case 6:return o(e,t);case 7:return a(e,t);case 8:return e.getFloat32(t,!0);case 9:return e.getFloat64(t,!0);default:return+!!e.getUint8(t)}}function Gd(e){for(let t=1;t<10;t++){let n=Number(e.toPrecision(t));if(Math.fround(n)===e)return String(n)}return String(e)}function Kd(e,t,n,r,i){if(e.startsWith(`char[`))return l(t.subarray(r,i));let a=Ld[e];if(!a||a[1]===11||r+a[0]>i)return null;let o=Wd(n,r,a[1]);return a[1]===8?Gd(o):String(o)}function qd(e,t,n){let r=e[t];if(t+1+r>n)return null;let[i,a]=d(e.subarray(t+1,t+1+r)).split(` `);return a?[i,a,t+1+r]:null}const Jd=(e,t)=>`[${Bd[e>=48?e-48:e]??`UNKNOWN`}] ${t}`,Yd={...Id,async plan(e,t){let n=await t.read(0,59);if(n.length<16||!f(n,`ULog5`))throw Error(`This is not a ULog file.`);let r=i(n),o=[],s=t.size;if(n.length>=59&&n[18]===66){let e=n.subarray(27,35);if(e[0]&-2||e.subarray(1).some(e=>e))throw Error(`This ULog file uses features this reader does not know.`);let t=a(r,35);e[0]&1&&t>16&&t<s&&(s=t,o.push(`This file has data appended after logging ended; only the data before it was read.`))}let c=new Map,u=new Map,p=new Set,m=[],h=new Map,g=[],_=0,v=0,y=0,b=0,x={},S=[],C=1/0,w=0,T=0,E=0,D=(e,t,n,r,i)=>{let s=r+i;switch(e){case 70:try{let[e,n]=Vd(d(t.subarray(r,s)));c.set(e,n),h.clear()}catch{o.push(`A message format in the file could not be read; skipped.`)}break;case 73:case 80:{let i=qd(t,r,s);if(!i)break;let a=`${e===73?`info`:`param`}.${i[1]}`,o=Kd(i[0],t,n,i[2],s);o!==null&&(e===73||!(a in x))&&(x[a]=o);break}case 77:{if(i<2)break;let e=qd(t,r+1,s);if(!e||!e[0].startsWith(`char[`))break;let n=`info.${e[1]}`,a=l(t.subarray(e[2],s));x[n]=n in x?x[n]+(t[r]?``:`
41
+ `)+a:a;break}case 65:{if(i<3)break;let e=t[r],a=n.getUint16(r+1,!0),l=d(t.subarray(r+3,s)),f=_++;u.delete(a),p.delete(a);let g=h.get(l);if(!g){try{g=Hd(c,l)}catch(e){g=e}h.set(l,g)}if(g instanceof Error){o.push(`${l}: ${g.message}; skipped.`);break}if(v+g.leaves.length>zd){y++,p.add(a);break}v+=g.leaves.length;let b={ord:f,name:e>0?`${l}_${e}`:l,count:0,...g};u.set(a,b),m.push(b);break}case 82:i>=2&&(u.delete(n.getUint16(r,!0)),p.delete(n.getUint16(r,!0)));break;case 68:{let e=i>=2?u.get(n.getUint16(r,!0)):void 0;if(!e&&i>=2&&p.has(n.getUint16(r,!0)))break;if(!e||i-2<e.minSize){w++;break}e.count++;let t=a(n,r+2+e.tsOff);C=Math.min(C,t),b=Math.max(b,t);break}case 76:i>=9&&S.push({ts:a(n,r+1),text:Jd(t[r],d(t.subarray(r+9,s)))});break;case 67:i>=11&&S.push({ts:a(n,r+3),text:Jd(t[r],d(t.subarray(r+11,s)))});break;case 79:if(i>=2){T++,E+=n.getUint16(r,!0),g.push(b);for(let e of u.values())e.count&&e.count++}break}},O={cut:!1};for(let e=Ud(t,s,D,O);!(await e.next()).done;);O.cut&&o.push(`The file ends in the middle of a message.`),w&&o.push(`${w} data message${w===1?``:`s`} did not match a subscription; skipped.`),y&&o.push(`${y} subscription${y===1?` was`:`s were`} skipped: the file has more than ${zd.toLocaleString(`en-US`)} channels.`),T&&o.push(`${T} dropout${T===1?``:`s`} while logging (${E} ms in total).`),Number.isFinite(C)||(C=a(r,8));let k=m.filter(e=>e.count>0),A=cn(k.map(e=>e.name),[]),j=k.map((e,t)=>({name:A[t],channels:e.leaves.map(e=>({name:e.name,unit:``,...e.code===11?{text:!0}:{}})),samples:e.count,time:{kind:`timestamps`},rateHz:null,irregular:!0})),M=S.map(e=>({time:(e.ts-C)/1e6,text:e.text}));return{format:`ULog v${n[7]}`,startTime:null,groups:j,meta:x,events:M,notes:o,interleaved:!0,state:{subs:k,t0:C,end:s,drops:g}}},async*stream(e){let t=e.plan.state,n=new Map,r=e=>{e.cap=Math.max(1,Math.min(65536,e.sub.count-e.start)),e.time=new Float64Array(e.cap),e.cols=e.leaves.map(t=>t.code===11?Array(e.cap):new Float64Array(e.cap))};for(let i of e.selection){let a=t.subs[i.group],o={g:i.group,sub:a,leaves:p(e,i.group).map(e=>a.leaves[e]),time:new Float64Array,cols:[],n:0,cap:0,start:0};r(o),n.set(a.ord,o)}let i=new Map,o=0,s=0,c=0,u=[],d=e=>{let t=e.n===e.cap;u.push({group:e.g,time:t?e.time:e.time.slice(0,e.n),start:e.start,length:e.n,columns:e.cols.map(n=>t?n:n.slice(0,e.n))}),e.start+=e.n,e.n=0,r(e)},f=(e,r,u,f,p)=>{if(++c%65536==0)for(let e of n.values())e.n&&d(e);if(e===65){p>=3&&i.set(u.getUint16(f+1,!0),o++);return}if(e===82){p>=2&&i.delete(u.getUint16(f,!0));return}if(e===79){if(p<2)return;let e=(t.drops[s++]-t.t0)/1e6;for(let t of i.values()){let r=n.get(t);if(!(!r||r.start+r.n===0)){r.time[r.n]=e;for(let e=0;e<r.leaves.length;e++)r.leaves[e].code===11?r.cols[e][r.n]=null:r.cols[e][r.n]=NaN;++r.n===r.cap&&d(r)}}return}if(e!==68||p<2)return;let m=i.get(u.getUint16(f,!0)),h=m===void 0?void 0:n.get(m);if(!h||p-2<h.sub.minSize)return;let g=f+2;h.time[h.n]=(a(u,g+h.sub.tsOff)-t.t0)/1e6;for(let e=0;e<h.leaves.length;e++){let t=h.leaves[e];t.code===11?h.cols[e][h.n]=l(r.subarray(g+t.off,g+t.off+t.n)):h.cols[e][h.n]=Wd(u,g+t.off,t.code)}++h.n===h.cap&&d(h)};for(let n=Ud(e.io,t.end,f,{cut:!1},e.signal);!(await n.next()).done;)yield*u,u.length=0;for(let e of n.values())e.n&&d(e);yield*u},streamGroup(e,t){return this.stream({...e,selection:e.selection.filter(e=>e.group===t)})}};function Xd({polynomial:e,numTables:t}){let n=new Uint32Array(256*t);for(let t=0;t<256;t++){let r=t;r=(r&1)*e^r>>>1,r=(r&1)*e^r>>>1,r=(r&1)*e^r>>>1,r=(r&1)*e^r>>>1,r=(r&1)*e^r>>>1,r=(r&1)*e^r>>>1,r=(r&1)*e^r>>>1,r=(r&1)*e^r>>>1,n[t]=r}for(let e=256;e<n.length;e++){let t=n[e-256];n[e]=n[t&255]^t>>>8}return n}const Zd=Xd({polynomial:3988292384,numTables:8});function Qd(){return-1}function $d(e,t){let n=t.byteLength,r=new DataView(t.buffer,t.byteOffset,n),i=e,a=0,o=-r.byteOffset&3;for(;a<o&&a<n;a++)i=Zd[(i^r.getUint8(a))&255]^i>>>8;if(a===n)return i;a=o;let s=n-a;for(;s>=8;a+=8,s-=8){i^=r.getUint32(a,!0);let e=r.getUint32(a+4,!0);i=Zd[0+(e>>>24&255)]^Zd[1*256+(e>>>16&255)]^Zd[2*256+(e>>>8&255)]^Zd[3*256+(e>>>0&255)]^Zd[4*256+(i>>>24&255)]^Zd[5*256+(i>>>16&255)]^Zd[6*256+(i>>>8&255)]^Zd[7*256+(i>>>0&255)]}for(let e=a;e<n;e++)i=Zd[(i^r.getUint8(e))&255]^i>>>8;return i}function ef(e){return(e^-1)>>>0}function tf(e){return ef($d(Qd(),e))}var G=function(e,t,n,r){function i(e){return e instanceof n?e:new n(function(t){t(e)})}return new(n||=Promise)(function(n,a){function o(e){try{c(r.next(e))}catch(e){a(e)}}function s(e){try{c(r.throw(e))}catch(e){a(e)}}function c(e){e.done?n(e.value):i(e.value).then(o,s)}c((r=r.apply(e,t||[])).next())})},K=function(e,t){var n={label:0,sent:function(){if(a[0]&1)throw a[1];return a[1]},trys:[],ops:[]},r,i,a,o=Object.create((typeof Iterator==`function`?Iterator:Object).prototype);return o.next=s(0),o.throw=s(1),o.return=s(2),typeof Symbol==`function`&&(o[Symbol.iterator]=function(){return this}),o;function s(e){return function(t){return c([e,t])}}function c(s){if(r)throw TypeError(`Generator is already executing.`);for(;o&&(o=0,s[0]&&(n=0)),n;)try{if(r=1,i&&(a=s[0]&2?i.return:s[0]?i.throw||((a=i.return)&&a.call(i),0):i.next)&&!(a=a.call(i,s[1])).done)return a;switch(i=0,a&&(s=[s[0]&2,a.value]),s[0]){case 0:case 1:a=s;break;case 4:return n.label++,{value:s[1],done:!1};case 5:n.label++,i=s[1],s=[0];continue;case 7:s=n.ops.pop(),n.trys.pop();continue;default:if((a=n.trys,!(a=a.length>0&&a[a.length-1]))&&(s[0]===6||s[0]===2)){n=0;continue}if(s[0]===3&&(!a||s[1]>a[0]&&s[1]<a[3])){n.label=s[1];break}if(s[0]===6&&n.label<a[1]){n.label=a[1],a=s;break}if(a&&n.label<a[2]){n.label=a[2],n.ops.push(s);break}a[2]&&n.ops.pop(),n.trys.pop();continue}s=t.call(e,n)}catch(e){s=[6,e],i=0}finally{r=a=0}if(s[0]&5)throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}},nf=function(e,t){var n=typeof Symbol==`function`&&e[Symbol.iterator];if(!n)return e;var r=n.call(e),i,a=[],o;try{for(;(t===void 0||t-- >0)&&!(i=r.next()).done;)a.push(i.value)}catch(e){o={error:e}}finally{try{i&&!i.done&&(n=r.return)&&n.call(r)}finally{if(o)throw o.error}}return a},rf=function(e,t,n){if(n||arguments.length===2)for(var r=0,i=t.length,a;r<i;r++)(a||!(r in t))&&(a||=Array.prototype.slice.call(t,0,r),a[r]=t[r]);return e.concat(a||Array.prototype.slice.call(t))},af=function(e){var t=typeof Symbol==`function`&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&typeof e.length==`number`)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw TypeError(t?`Object is not iterable.`:`Symbol.iterator is not defined.`)};(function(){function e(t){t===void 0&&(t=e.minComparator);var n=this;this.compare=t,this.heapArray=[],this._limit=0,this.offer=this.add,this.element=this.peek,this.poll=this.pop,this._invertedCompare=function(e,t){return n.compare(e,t).then(function(e){return-1*e})}}return e.getChildrenIndexOf=function(e){return[e*2+1,e*2+2]},e.getParentIndexOf=function(e){if(e<=0)return-1;var t=e%2?1:2;return Math.floor((e-t)/2)},e.getSiblingIndexOf=function(e){return e<=0?-1:e+(e%2?1:-1)},e.minComparator=function(e,t){return G(this,void 0,void 0,function(){return K(this,function(n){return e>t?[2,1]:e<t?[2,-1]:[2,0]})})},e.maxComparator=function(e,t){return G(this,void 0,void 0,function(){return K(this,function(n){return t>e?[2,1]:t<e?[2,-1]:[2,0]})})},e.minComparatorNumber=function(e,t){return G(this,void 0,void 0,function(){return K(this,function(n){return[2,e-t]})})},e.maxComparatorNumber=function(e,t){return G(this,void 0,void 0,function(){return K(this,function(n){return[2,t-e]})})},e.defaultIsEqual=function(e,t){return G(this,void 0,void 0,function(){return K(this,function(n){return[2,e===t]})})},e.print=function(t){function n(t){var n=e.getParentIndexOf(t);return Math.floor(Math.log2(n+1))}function r(e,t){for(var n=``;t>0;--t)n+=e;return n}for(var i=0,a=[],o=n(t.length-1)+2,s=0;i<t.length;){var c=n(i)+1;i===0&&(c=0);var l=String(t.get(i));l.length>s&&(s=l.length),a[c]=a[c]||[],a[c].push(l),i+=1}return a.map(function(e,t){var n=2**(o-t)-1;return r(` `,Math.floor(n/2)*s)+e.map(function(e){var t=(s-e.length)/2;return r(` `,Math.ceil(t))+e+r(` `,Math.floor(t))}).join(r(` `,n*s))}).join(`
42
+ `)},e.heapify=function(t,n){return G(this,void 0,void 0,function(){var r;return K(this,function(i){switch(i.label){case 0:return r=new e(n),r.heapArray=t,[4,r.init()];case 1:return i.sent(),[2,r]}})})},e.heappop=function(t,n){var r=new e(n);return r.heapArray=t,r.pop()},e.heappush=function(t,n,r){return G(this,void 0,void 0,function(){var i;return K(this,function(a){switch(a.label){case 0:return i=new e(r),i.heapArray=t,[4,i.push(n)];case 1:return a.sent(),[2]}})})},e.heappushpop=function(t,n,r){var i=new e(r);return i.heapArray=t,i.pushpop(n)},e.heapreplace=function(t,n,r){var i=new e(r);return i.heapArray=t,i.replace(n)},e.heaptop=function(t,n,r){n===void 0&&(n=1);var i=new e(r);return i.heapArray=t,i.top(n)},e.heapbottom=function(t,n,r){n===void 0&&(n=1);var i=new e(r);return i.heapArray=t,i.bottom(n)},e.nlargest=function(t,n,r){return G(this,void 0,void 0,function(){var i;return K(this,function(a){switch(a.label){case 0:return i=new e(r),i.heapArray=rf([],nf(n),!1),[4,i.init()];case 1:return a.sent(),[2,i.top(t)]}})})},e.nsmallest=function(t,n,r){return G(this,void 0,void 0,function(){var i;return K(this,function(a){switch(a.label){case 0:return i=new e(r),i.heapArray=rf([],nf(n),!1),[4,i.init()];case 1:return a.sent(),[2,i.bottom(t)]}})})},e.prototype.add=function(e){return G(this,void 0,void 0,function(){return K(this,function(t){switch(t.label){case 0:return[4,this._sortNodeUp(this.heapArray.push(e)-1)];case 1:return t.sent(),this._applyLimit(),[2,!0]}})})},e.prototype.addAll=function(e){return G(this,void 0,void 0,function(){var t,n,r;return K(this,function(i){switch(i.label){case 0:t=this.length,(r=this.heapArray).push.apply(r,rf([],nf(e),!1)),n=this.length,i.label=1;case 1:return t<n?[4,this._sortNodeUp(t)]:[3,4];case 2:i.sent(),i.label=3;case 3:return++t,[3,1];case 4:return this._applyLimit(),[2,!0]}})})},e.prototype.bottom=function(){return G(this,arguments,void 0,function(e){return e===void 0&&(e=1),K(this,function(t){return this.heapArray.length===0||e<=0?[2,[]]:this.heapArray.length===1?[2,[this.heapArray[0]]]:e>=this.heapArray.length?[2,rf([],nf(this.heapArray),!1)]:[2,this._bottomN_push(~~e)]})})},e.prototype.check=function(){return G(this,void 0,void 0,function(){var e,t,n,r,i,a,o,s,c;return K(this,function(l){switch(l.label){case 0:e=0,l.label=1;case 1:if(!(e<this.heapArray.length))return[3,10];t=this.heapArray[e],n=this.getChildrenOf(e),l.label=2;case 2:l.trys.push([2,7,8,9]),r=(s=void 0,af(n)),i=r.next(),l.label=3;case 3:return i.done?[3,6]:(a=i.value,[4,this.compare(t,a)]);case 4:if(l.sent()>0)return[2,t];l.label=5;case 5:return i=r.next(),[3,3];case 6:return[3,9];case 7:return o=l.sent(),s={error:o},[3,9];case 8:try{i&&!i.done&&(c=r.return)&&c.call(r)}finally{if(s)throw s.error}return[7];case 9:return++e,[3,1];case 10:return[2]}})})},e.prototype.clear=function(){this.heapArray=[]},e.prototype.clone=function(){var t=new e(this.comparator());return t.heapArray=this.toArray(),t._limit=this._limit,t},e.prototype.comparator=function(){return this.compare},e.prototype.contains=function(t){return G(this,arguments,void 0,function(t,n){var r,i,a,o,s,c;return n===void 0&&(n=e.defaultIsEqual),K(this,function(e){switch(e.label){case 0:e.trys.push([0,5,6,7]),r=af(this.heapArray),i=r.next(),e.label=1;case 1:return i.done?[3,4]:(a=i.value,[4,n(a,t)]);case 2:if(e.sent())return[2,!0];e.label=3;case 3:return i=r.next(),[3,1];case 4:return[3,7];case 5:return o=e.sent(),s={error:o},[3,7];case 6:try{i&&!i.done&&(c=r.return)&&c.call(r)}finally{if(s)throw s.error}return[7];case 7:return[2,!1]}})})},e.prototype.init=function(t){return G(this,void 0,void 0,function(){var n;return K(this,function(r){switch(r.label){case 0:t&&(this.heapArray=rf([],nf(t),!1)),n=e.getParentIndexOf(this.length-1),r.label=1;case 1:return n>=0?[4,this._sortNodeDown(n)]:[3,4];case 2:r.sent(),r.label=3;case 3:return--n,[3,1];case 4:return this._applyLimit(),[2]}})})},e.prototype.isEmpty=function(){return this.length===0},e.prototype.leafs=function(){if(this.heapArray.length===0)return[];var t=e.getParentIndexOf(this.heapArray.length-1);return this.heapArray.slice(t+1)},Object.defineProperty(e.prototype,`length`,{get:function(){return this.heapArray.length},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,`limit`,{get:function(){return this._limit},set:function(e){this._limit=~~e,this._applyLimit()},enumerable:!1,configurable:!0}),e.prototype.peek=function(){return this.heapArray[0]},e.prototype.pop=function(){return G(this,void 0,void 0,function(){var e;return K(this,function(t){return e=this.heapArray.pop(),this.length>0&&e!==void 0?[2,this.replace(e)]:[2,e]})})},e.prototype.push=function(){var e=[...arguments];return G(this,void 0,void 0,function(){return K(this,function(t){return e.length<1?[2,!1]:e.length===1?[2,this.add(e[0])]:[2,this.addAll(e)]})})},e.prototype.pushpop=function(e){return G(this,void 0,void 0,function(){var t;return K(this,function(n){switch(n.label){case 0:return[4,this.compare(this.heapArray[0],e)];case 1:return n.sent()<0?(t=nf([this.heapArray[0],e],2),e=t[0],this.heapArray[0]=t[1],[4,this._sortNodeDown(0)]):[3,3];case 2:n.sent(),n.label=3;case 3:return[2,e]}})})},e.prototype.remove=function(t){return G(this,arguments,void 0,function(t,n){var r,i,a,o=this;return n===void 0&&(n=e.defaultIsEqual),K(this,function(s){switch(s.label){case 0:return this.heapArray.length?t===void 0?[4,this.pop()]:[3,2]:[2,!1];case 1:return s.sent(),[2,!0];case 2:r=[0],s.label=3;case 3:return r.length?(i=r.shift(),[4,n(this.heapArray[i],t)]):[3,13];case 4:return s.sent()?i===0?[4,this.pop()]:[3,6]:[3,11];case 5:return s.sent(),[3,10];case 6:return i===this.heapArray.length-1?(this.heapArray.pop(),[3,10]):[3,7];case 7:return this.heapArray.splice(i,1,this.heapArray.pop()),[4,this._sortNodeUp(i)];case 8:return s.sent(),[4,this._sortNodeDown(i)];case 9:s.sent(),s.label=10;case 10:return[2,!0];case 11:a=e.getChildrenIndexOf(i).filter(function(e){return e<o.heapArray.length}),r.push.apply(r,rf([],nf(a),!1)),s.label=12;case 12:return[3,3];case 13:return[2,!1]}})})},e.prototype.replace=function(e){return G(this,void 0,void 0,function(){var t;return K(this,function(n){switch(n.label){case 0:return t=this.heapArray[0],this.heapArray[0]=e,[4,this._sortNodeDown(0)];case 1:return n.sent(),[2,t]}})})},e.prototype.size=function(){return this.length},e.prototype.top=function(){return G(this,arguments,void 0,function(e){return e===void 0&&(e=1),K(this,function(t){return this.heapArray.length===0||e<=0?[2,[]]:this.heapArray.length===1||e===1?[2,[this.heapArray[0]]]:e>=this.heapArray.length?[2,rf([],nf(this.heapArray),!1)]:[2,this._topN_push(~~e)]})})},e.prototype.toArray=function(){return rf([],nf(this.heapArray),!1)},e.prototype.toString=function(){return this.heapArray.toString()},e.prototype.get=function(e){return this.heapArray[e]},e.prototype.getChildrenOf=function(t){var n=this;return e.getChildrenIndexOf(t).map(function(e){return n.heapArray[e]}).filter(function(e){return e!==void 0})},e.prototype.getParentOf=function(t){var n=e.getParentIndexOf(t);return this.heapArray[n]},e.prototype[Symbol.iterator]=function(){return K(this,function(e){switch(e.label){case 0:return this.length?[4,this.pop()]:[3,2];case 1:return e.sent(),[3,0];case 2:return[2]}})},e.prototype.iterator=function(){return this},e.prototype._applyLimit=function(){if(this._limit&&this._limit<this.heapArray.length)for(var e=this.heapArray.length-this._limit;e;)this.heapArray.pop(),--e},e.prototype._bottomN_push=function(t){return G(this,void 0,void 0,function(){var n,r,i,a,o,s,o;return K(this,function(c){switch(c.label){case 0:return n=new e(this.compare),n.limit=t,n.heapArray=this.heapArray.slice(-t),[4,n.init()];case 1:for(c.sent(),r=this.heapArray.length-1-t,i=e.getParentIndexOf(r),a=[],o=r;o>i;--o)a.push(o);s=this.heapArray,c.label=2;case 2:return a.length?(o=a.shift(),[4,this.compare(s[o],n.peek())]):[3,6];case 3:return c.sent()>0?[4,n.replace(s[o])]:[3,5];case 4:c.sent(),o%2&&a.push(e.getParentIndexOf(o)),c.label=5;case 5:return[3,2];case 6:return[2,n.toArray()]}})})},e.prototype._moveNode=function(e,t){var n=this.heapArray[e];this.heapArray[e]=this.heapArray[t],this.heapArray[t]=n},e.prototype._sortNodeDown=function(e){return G(this,void 0,void 0,function(){var t,n,r,i,a,o,s;return K(this,function(c){switch(c.label){case 0:t=this.heapArray.length,n=e,r=this.heapArray[e],i=2*e+1,c.label=1;case 1:return i<t?(a=i+1,s=a>=t,s?[3,3]:[4,this.compare(this.heapArray[i],this.heapArray[a])]):[3,5];case 2:s=c.sent()<0,c.label=3;case 3:return o=s?i:a,[4,this.compare(this.heapArray[o],r)];case 4:if(c.sent()<0)this.heapArray[e]=this.heapArray[o],e=o,i=2*e+1;else return[3,5];return[3,1];case 5:return e!==n&&(this.heapArray[e]=r),[2]}})})},e.prototype._sortNodeUp=function(t){return G(this,void 0,void 0,function(){var n,r,i;return K(this,function(a){switch(a.label){case 0:n=this.heapArray[t],r=t,a.label=1;case 1:return t>0?(i=e.getParentIndexOf(t),[4,this.compare(n,this.heapArray[i])]):[3,3];case 2:if(a.sent()<0)this.heapArray[t]=this.heapArray[i],t=i;else return[3,3];return[3,1];case 3:return t!==r&&(this.heapArray[t]=n),[2]}})})},e.prototype._topN_push=function(t){return G(this,void 0,void 0,function(){var n,r,i,a;return K(this,function(o){switch(o.label){case 0:n=new e(this._invertedCompare),n.limit=t,r=[0],i=this.heapArray,o.label=1;case 1:return r.length?(a=r.shift(),a<i.length?n.length<t?[4,n.push(i[a])]:[3,3]:[3,6]):[3,7];case 2:return o.sent(),r.push.apply(r,rf([],nf(e.getChildrenIndexOf(a)),!1)),[3,6];case 3:return[4,this.compare(i[a],n.peek())];case 4:return o.sent()<0?[4,n.replace(i[a])]:[3,6];case 5:o.sent(),r.push.apply(r,rf([],nf(e.getChildrenIndexOf(a)),!1)),o.label=6;case 6:return[3,1];case 7:return[2,n.toArray()]}})})},e.prototype._topN_fill=function(t){return G(this,void 0,void 0,function(){var n,r,i,a,o,o;return K(this,function(s){switch(s.label){case 0:return n=this.heapArray,r=new e(this._invertedCompare),r.limit=t,r.heapArray=n.slice(0,t),[4,r.init()];case 1:for(s.sent(),i=e.getParentIndexOf(t-1)+1,a=[],o=i;o<t;++o)a.push.apply(a,rf([],nf(e.getChildrenIndexOf(o).filter(function(e){return e<n.length})),!1));(t-1)%2&&a.push(t),s.label=2;case 2:return a.length?(o=a.shift(),o<n.length?[4,this.compare(n[o],r.peek())]:[3,5]):[3,6];case 3:return s.sent()<0?[4,r.replace(n[o])]:[3,5];case 4:s.sent(),a.push.apply(a,rf([],nf(e.getChildrenIndexOf(o)),!1)),s.label=5;case 5:return[3,2];case 6:return[2,r.toArray()]}})})},e.prototype._topN_heap=function(e){return G(this,void 0,void 0,function(){var t,n,r,i,a;return K(this,function(o){switch(o.label){case 0:t=this.clone(),n=[],r=0,o.label=1;case 1:return r<e?(a=(i=n).push,[4,t.pop()]):[3,4];case 2:a.apply(i,[o.sent()]),o.label=3;case 3:return++r,[3,1];case 4:return[2,n]}})})},e.prototype._topIdxOf=function(e){return G(this,void 0,void 0,function(){var t,n,r,i;return K(this,function(a){switch(a.label){case 0:if(!e.length)return[2,-1];t=0,n=e[t],r=1,a.label=1;case 1:return r<e.length?[4,this.compare(e[r],n)]:[3,4];case 2:i=a.sent(),i<0&&(t=r,n=e[r]),a.label=3;case 3:return++r,[3,1];case 4:return[2,t]}})})},e.prototype._topOf=function(){var t=[...arguments];return G(this,void 0,void 0,function(){var n;return K(this,function(r){switch(r.label){case 0:return n=new e(this.compare),[4,n.init(t)];case 1:return r.sent(),[2,n.peek()]}})})},e})();var of=function(e,t){var n={label:0,sent:function(){if(a[0]&1)throw a[1];return a[1]},trys:[],ops:[]},r,i,a,o=Object.create((typeof Iterator==`function`?Iterator:Object).prototype);return o.next=s(0),o.throw=s(1),o.return=s(2),typeof Symbol==`function`&&(o[Symbol.iterator]=function(){return this}),o;function s(e){return function(t){return c([e,t])}}function c(s){if(r)throw TypeError(`Generator is already executing.`);for(;o&&(o=0,s[0]&&(n=0)),n;)try{if(r=1,i&&(a=s[0]&2?i.return:s[0]?i.throw||((a=i.return)&&a.call(i),0):i.next)&&!(a=a.call(i,s[1])).done)return a;switch(i=0,a&&(s=[s[0]&2,a.value]),s[0]){case 0:case 1:a=s;break;case 4:return n.label++,{value:s[1],done:!1};case 5:n.label++,i=s[1],s=[0];continue;case 7:s=n.ops.pop(),n.trys.pop();continue;default:if((a=n.trys,!(a=a.length>0&&a[a.length-1]))&&(s[0]===6||s[0]===2)){n=0;continue}if(s[0]===3&&(!a||s[1]>a[0]&&s[1]<a[3])){n.label=s[1];break}if(s[0]===6&&n.label<a[1]){n.label=a[1],a=s;break}if(a&&n.label<a[2]){n.label=a[2],n.ops.push(s);break}a[2]&&n.ops.pop(),n.trys.pop();continue}s=t.call(e,n)}catch(e){s=[6,e],i=0}finally{r=a=0}if(s[0]&5)throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}},sf=function(e,t){var n=typeof Symbol==`function`&&e[Symbol.iterator];if(!n)return e;var r=n.call(e),i,a=[],o;try{for(;(t===void 0||t-- >0)&&!(i=r.next()).done;)a.push(i.value)}catch(e){o={error:e}}finally{try{i&&!i.done&&(n=r.return)&&n.call(r)}finally{if(o)throw o.error}}return a},cf=function(e,t,n){if(n||arguments.length===2)for(var r=0,i=t.length,a;r<i;r++)(a||!(r in t))&&(a||=Array.prototype.slice.call(t,0,r),a[r]=t[r]);return e.concat(a||Array.prototype.slice.call(t))},lf=function(){function e(t){t===void 0&&(t=e.minComparator);var n=this;this.compare=t,this.heapArray=[],this._limit=0,this.offer=this.add,this.element=this.peek,this.poll=this.pop,this.removeAll=this.clear,this._invertedCompare=function(e,t){return-1*n.compare(e,t)}}return e.getChildrenIndexOf=function(e){return[e*2+1,e*2+2]},e.getParentIndexOf=function(e){return e<=0?-1:e-1>>1},e.getSiblingIndexOf=function(e){return e<=0?-1:e+(e%2?1:-1)},e.minComparator=function(e,t){return e>t?1:e<t?-1:0},e.maxComparator=function(e,t){return t>e?1:t<e?-1:0},e.minComparatorNumber=function(e,t){return e-t},e.maxComparatorNumber=function(e,t){return t-e},e.defaultIsEqual=function(e,t){return e===t},e.print=function(t){function n(t){var n=e.getParentIndexOf(t);return Math.floor(Math.log2(n+1))}function r(e,t){for(var n=``;t>0;--t)n+=e;return n}for(var i=0,a=[],o=n(t.length-1)+2,s=0;i<t.length;){var c=n(i)+1;i===0&&(c=0);var l=String(t.get(i));l.length>s&&(s=l.length),a[c]=a[c]||[],a[c].push(l),i+=1}return a.map(function(e,t){var n=2**(o-t)-1;return r(` `,Math.floor(n/2)*s)+e.map(function(e){var t=(s-e.length)/2;return r(` `,Math.ceil(t))+e+r(` `,Math.floor(t))}).join(r(` `,n*s))}).join(`
43
+ `)},e.heapify=function(t,n){var r=new e(n);return r.heapArray=t,r.init(),r},e.heappop=function(t,n){var r=new e(n);return r.heapArray=t,r.pop()},e.heappush=function(t,n,r){var i=new e(r);i.heapArray=t,i.push(n)},e.heappushpop=function(t,n,r){var i=new e(r);return i.heapArray=t,i.pushpop(n)},e.heapreplace=function(t,n,r){var i=new e(r);return i.heapArray=t,i.replace(n)},e.heaptop=function(t,n,r){n===void 0&&(n=1);var i=new e(r);return i.heapArray=t,i.top(n)},e.heapbottom=function(t,n,r){n===void 0&&(n=1);var i=new e(r);return i.heapArray=t,i.bottom(n)},e.nlargest=function(t,n,r){var i=new e(r);return i.heapArray=cf([],sf(n),!1),i.init(),i.top(t)},e.nsmallest=function(t,n,r){var i=new e(r);return i.heapArray=cf([],sf(n),!1),i.init(),i.bottom(t)},e.prototype.add=function(e){return this._sortNodeUp(this.heapArray.push(e)-1),this._applyLimit(),!0},e.prototype.addAll=function(e){var t,n=this.length;(t=this.heapArray).push.apply(t,cf([],sf(e),!1));for(var r=this.length;n<r;++n)this._sortNodeUp(n);return this._applyLimit(),!0},e.prototype.bottom=function(e){return e===void 0&&(e=1),this.heapArray.length===0||e<=0?[]:this.heapArray.length===1?[this.heapArray[0]]:e>=this.heapArray.length?cf([],sf(this.heapArray),!1):this._bottomN_push(~~e)},e.prototype.check=function(){var e=this;return this.heapArray.find(function(t,n){return!!e.getChildrenOf(n).find(function(n){return e.compare(t,n)>0})})},e.prototype.clear=function(){this.heapArray=[]},e.prototype.clone=function(){var t=new e(this.comparator());return t.heapArray=this.toArray(),t._limit=this._limit,t},e.prototype.comparator=function(){return this.compare},e.prototype.contains=function(t,n){return n===void 0&&(n=e.defaultIsEqual),this.indexOf(t,n)!==-1},e.prototype.init=function(t){t&&(this.heapArray=cf([],sf(t),!1));for(var n=e.getParentIndexOf(this.length-1);n>=0;--n)this._sortNodeDown(n);this._applyLimit()},e.prototype.isEmpty=function(){return this.length===0},e.prototype.indexOf=function(t,n){if(n===void 0&&(n=e.defaultIsEqual),this.heapArray.length===0)return-1;for(var r=[],i=0;i<this.heapArray.length;){var a=this.heapArray[i];if(n(a,t))return i;this.compare(a,t)<=0&&r.push.apply(r,cf([],sf(e.getChildrenIndexOf(i)),!1)),i=r.shift()||this.heapArray.length}return-1},e.prototype.indexOfEvery=function(t,n){if(n===void 0&&(n=e.defaultIsEqual),this.heapArray.length===0)return[];for(var r=[],i=[],a=0;a<this.heapArray.length;){var o=this.heapArray[a];n(o,t)?(i.push(a),r.push.apply(r,cf([],sf(e.getChildrenIndexOf(a)),!1))):this.compare(o,t)<=0&&r.push.apply(r,cf([],sf(e.getChildrenIndexOf(a)),!1)),a=r.shift()||this.heapArray.length}return i},e.prototype.leafs=function(){if(this.heapArray.length===0)return[];var t=e.getParentIndexOf(this.heapArray.length-1);return this.heapArray.slice(t+1)},Object.defineProperty(e.prototype,`length`,{get:function(){return this.heapArray.length},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,`limit`,{get:function(){return this._limit},set:function(e){e<0||isNaN(e)?this._limit=0:this._limit=~~e,this._applyLimit()},enumerable:!1,configurable:!0}),e.prototype.setLimit=function(e){return this.limit=e,e<0||isNaN(e)?NaN:this._limit},e.prototype.peek=function(){return this.heapArray[0]},e.prototype.pop=function(){var e=this.heapArray.pop();return this.length>0&&e!==void 0?this.replace(e):e},e.prototype.push=function(){var e=[...arguments];return e.length<1?!1:e.length===1?this.add(e[0]):this.addAll(e)},e.prototype.pushpop=function(e){var t;return this.compare(this.heapArray[0],e)<0&&(t=sf([this.heapArray[0],e],2),e=t[0],this.heapArray[0]=t[1],this._sortNodeDown(0)),e},e.prototype.remove=function(t,n){var r=this;if(n===void 0&&(n=e.defaultIsEqual),!this.heapArray.length)return!1;if(t===void 0)return this.pop(),!0;for(var i=[0];i.length;){var a=i.shift();if(n(this.heapArray[a],t))return a===0?this.pop():a===this.heapArray.length-1?this.heapArray.pop():(this.heapArray.splice(a,1,this.heapArray.pop()),this._sortNodeUp(a),this._sortNodeDown(a)),!0;if(this.compare(this.heapArray[a],t)<=0){var o=e.getChildrenIndexOf(a).filter(function(e){return e<r.heapArray.length});i.push.apply(i,cf([],sf(o),!1))}}return!1},e.prototype.replace=function(e){var t=this.heapArray[0];return this.heapArray[0]=e,this._sortNodeDown(0),t},e.prototype.size=function(){return this.length},e.prototype.top=function(e){return e===void 0&&(e=1),this.heapArray.length===0||e<=0?[]:this.heapArray.length===1||e===1?[this.heapArray[0]]:e>=this.heapArray.length?cf([],sf(this.heapArray),!1):this._topN_push(~~e)},e.prototype.toArray=function(){return cf([],sf(this.heapArray),!1)},e.prototype.toString=function(){return this.heapArray.toString()},e.prototype.get=function(e){return this.heapArray[e]},e.prototype.getChildrenOf=function(t){var n=this;return e.getChildrenIndexOf(t).map(function(e){return n.heapArray[e]}).filter(function(e){return e!==void 0})},e.prototype.getParentOf=function(t){var n=e.getParentIndexOf(t);return this.heapArray[n]},e.prototype[Symbol.iterator]=function(){return of(this,function(e){switch(e.label){case 0:return this.length?[4,this.pop()]:[3,2];case 1:return e.sent(),[3,0];case 2:return[2]}})},e.prototype.iterator=function(){return this.toArray()},e.prototype._applyLimit=function(){if(this._limit>0&&this._limit<this.heapArray.length)for(var e=this.heapArray.length-this._limit;e;)this.heapArray.pop(),--e},e.prototype._bottomN_push=function(t){var n=new e(this.compare);n.limit=t,n.heapArray=this.heapArray.slice(-t),n.init();for(var r=this.heapArray.length-1-t,i=e.getParentIndexOf(r),a=[],o=r;o>i;--o)a.push(o);for(var s=this.heapArray;a.length;){var o=a.shift();this.compare(s[o],n.peek())>0&&(n.replace(s[o]),o%2&&a.push(e.getParentIndexOf(o)))}return n.toArray()},e.prototype._moveNode=function(e,t){var n=this.heapArray[e];this.heapArray[e]=this.heapArray[t],this.heapArray[t]=n},e.prototype._sortNodeDown=function(e){for(var t=this.heapArray.length,n=e,r=this.heapArray[e],i=2*e+1;i<t;){var a=i+1,o=a>=t||this.compare(this.heapArray[i],this.heapArray[a])<0?i:a;if(this.compare(this.heapArray[o],r)<0)this.heapArray[e]=this.heapArray[o],e=o,i=2*e+1;else break}e!==n&&(this.heapArray[e]=r)},e.prototype._sortNodeUp=function(t){for(var n=this.heapArray[t],r=t;t>0;){var i=e.getParentIndexOf(t);if(this.compare(n,this.heapArray[i])<0)this.heapArray[t]=this.heapArray[i],t=i;else break}t!==r&&(this.heapArray[t]=n)},e.prototype._topN_push=function(t){var n=new e(this._invertedCompare);n.limit=t;for(var r=[0],i=this.heapArray;r.length;){var a=r.shift();a<i.length&&(n.length<t?(n.push(i[a]),r.push.apply(r,cf([],sf(e.getChildrenIndexOf(a)),!1))):this.compare(i[a],n.peek())<0&&(n.replace(i[a]),r.push.apply(r,cf([],sf(e.getChildrenIndexOf(a)),!1))))}return n.toArray()},e.prototype._topN_fill=function(t){var n=this.heapArray,r=new e(this._invertedCompare);r.limit=t,r.heapArray=n.slice(0,t),r.init();for(var i=e.getParentIndexOf(t-1)+1,a=[],o=i;o<t;++o)a.push.apply(a,cf([],sf(e.getChildrenIndexOf(o).filter(function(e){return e<n.length})),!1));for((t-1)%2&&a.push(t);a.length;){var o=a.shift();o<n.length&&this.compare(n[o],r.peek())<0&&(r.replace(n[o]),a.push.apply(a,cf([],sf(e.getChildrenIndexOf(o)),!1)))}return r.toArray()},e.prototype._topN_heap=function(e){for(var t=this.clone(),n=[],r=0;r<e;++r)n.push(t.pop());return n},e.prototype._topIdxOf=function(e){if(!e.length)return-1;for(var t=0,n=e[t],r=1;r<e.length;++r)this.compare(e[r],n)<0&&(t=r,n=e[r]);return t},e.prototype._topOf=function(){var t=[...arguments],n=new e(this.compare);return n.init(t),n.peek()},e}(),uf=class{#e;#t=new Map;#n;#r=0;#i;constructor(e,t){this.#e=e,this.#n=t}async size(){return this.#i??=await this.#e.size(),this.#i}async read(e,t,n){let r=Number(t),i=this.#t.get(e);if(i!=null&&i.byteLength>=r)return i.byteLength===r?i:i.subarray(0,r);let a=await this.#e.read(e,t,n);if(this.#r+a.byteLength<=this.#n){let t=new Uint8Array(a);return this.#t.set(e,t),this.#r+=t.byteLength,t}return a}};const df=typeof DataView.prototype.getBigUint64==`function`?DataView.prototype.getBigUint64:function(e,t){let n=t===!0?this.getUint32(e,t):this.getUint32(e+4,t),r=t===!0?this.getUint32(e+4,t):this.getUint32(e,t);return BigInt(r)<<32n|BigInt(n)},ff=new TextDecoder;var pf=class{#e;#t;offset;constructor(e,t=0){this.#e=e,this.#t=new Uint8Array(e.buffer,e.byteOffset,e.byteLength),this.offset=t}reset(e,t=0){this.#e=e,this.#t=new Uint8Array(e.buffer,e.byteOffset,e.byteLength),this.offset=t}bytesRemaining(){return this.#t.length-this.offset}uint8(){let e=this.#e.getUint8(this.offset);return this.offset+=1,e}uint16(){let e=this.#e.getUint16(this.offset,!0);return this.offset+=2,e}uint32(){let e=this.#e.getUint32(this.offset,!0);return this.offset+=4,e}uint64(){let e=df.call(this.#e,this.offset,!0);return this.offset+=8,e}string(){let e=this.uint32();if(e===0)return``;if(e>this.bytesRemaining())throw Error(`String length ${e} exceeds bounds of buffer`);return ff.decode(this.u8ArrayBorrow(e))}keyValuePairs(e,t){let n=this.uint32();if(this.offset+n>this.#e.byteLength)throw Error(`Key-value pairs length ${n} exceeds bounds of buffer`);let r=[],i=this.offset+n;try{for(;this.offset<i;)r.push([e(this),t(this)])}catch(e){throw Error(`Error reading key-value pairs: ${e.message}`)}if(this.offset!==i)throw Error(`Key-value pairs length (${this.offset-i+n}) greater than expected (${n})`);return r}map(e,t){let n=this.uint32();if(this.offset+n>this.#e.byteLength)throw Error(`Map length ${n} exceeds bounds of buffer`);let r=new Map,i=this.offset+n;try{for(;this.offset<i;){let n=e(this),i=t(this),a=r.get(n);if(a!=null)throw Error(`Duplicate key ${String(n)} (${String(a)} vs ${String(i)})`);r.set(n,i)}}catch(e){throw Error(`Error reading map: ${e.message}`)}if(this.offset!==i)throw Error(`Map length (${this.offset-i+n}) greater than expected (${n})`);return r}u8ArrayBorrow(e){if(!(e>=0&&e<=this.bytesRemaining()))throw Error(`Byte array length ${e} exceeds bounds of buffer`);let t=this.#t.subarray(this.offset,this.offset+e);return this.offset+=e,t}u8ArrayCopy(e){if(!(e>=0&&e<=this.bytesRemaining()))throw Error(`Byte array length ${e} exceeds bounds of buffer`);let t=this.#t.slice(this.offset,this.offset+e);return this.offset+=e,t}};const mf=Object.freeze([137,77,67,65,80,48,13,10]);var hf;(function(e){e[e.MIN=1]=`MIN`,e[e.HEADER=1]=`HEADER`,e[e.FOOTER=2]=`FOOTER`,e[e.SCHEMA=3]=`SCHEMA`,e[e.CHANNEL=4]=`CHANNEL`,e[e.MESSAGE=5]=`MESSAGE`,e[e.CHUNK=6]=`CHUNK`,e[e.MESSAGE_INDEX=7]=`MESSAGE_INDEX`,e[e.CHUNK_INDEX=8]=`CHUNK_INDEX`,e[e.ATTACHMENT=9]=`ATTACHMENT`,e[e.ATTACHMENT_INDEX=10]=`ATTACHMENT_INDEX`,e[e.STATISTICS=11]=`STATISTICS`,e[e.METADATA=12]=`METADATA`,e[e.METADATA_INDEX=13]=`METADATA_INDEX`,e[e.SUMMARY_OFFSET=14]=`SUMMARY_OFFSET`,e[e.DATA_END=15]=`DATA_END`,e[e.MAX=15]=`MAX`})(hf||={});function gf(e){if(e.bytesRemaining()<mf.length)return;let t=e.u8ArrayBorrow(mf.length);if(!mf.every((e,n)=>e===t[n]))throw Error(`Expected MCAP magic '${mf.map(e=>e.toString(16).padStart(2,`0`)).join(` `)}', found '${Array.from(t,(e,n)=>t[n].toString(16).padStart(2,`0`)).join(` `)}'`);return{specVersion:`0`}}function _f(e,t=!1){if(e.bytesRemaining()<9)return;let n=e.offset,r=e.uint8(),i=e.uint64();if(i>2**53-1)throw Error(`Record content length ${i} is too large`);let a=Number(i);if(e.bytesRemaining()<a){e.offset=n;return}let o;switch(r){case hf.HEADER:o=yf(e,a);break;case hf.FOOTER:o=bf(e,a);break;case hf.SCHEMA:o=xf(e,a);break;case hf.CHANNEL:o=Sf(e,a);break;case hf.MESSAGE:o=Cf(e,a);break;case hf.CHUNK:o=wf(e,a);break;case hf.MESSAGE_INDEX:o=Tf(e,a);break;case hf.CHUNK_INDEX:o=Ef(e,a);break;case hf.ATTACHMENT:o=Df(e,a,t);break;case hf.ATTACHMENT_INDEX:o=Of(e,a);break;case hf.STATISTICS:o=kf(e,a);break;case hf.METADATA:o=Af(e,a);break;case hf.METADATA_INDEX:o=jf(e,a);break;case hf.SUMMARY_OFFSET:o=Mf(e,a);break;case hf.DATA_END:o=Nf(e,a);break;default:o=vf(e,a,r);break}return e.offset=n+9+a,o}function vf(e,t,n){return{type:`Unknown`,opcode:n,data:e.u8ArrayBorrow(t)}}function yf(e,t){let n=e.offset,r=e.string(),i=e.string();return e.offset=n+t,{type:`Header`,profile:r,library:i}}function bf(e,t){let n=e.offset,r=e.uint64(),i=e.uint64(),a=e.uint32();return e.offset=n+t,{type:`Footer`,summaryStart:r,summaryOffsetStart:i,summaryCrc:a}}function xf(e,t){let n=e.offset,r=e.uint16(),i=e.string(),a=e.string(),o=e.uint32();if(t-(e.offset-n)<o)throw Error(`Schema data length ${o} exceeds bounds of record`);let s=e.u8ArrayCopy(o);return e.offset=n+t,{type:`Schema`,id:r,encoding:a,name:i,data:s}}function Sf(e,t){let n=e.offset,r=e.uint16(),i=e.uint16(),a=e.string(),o=e.string(),s=e.map(e=>e.string(),e=>e.string());return e.offset=n+t,{type:`Channel`,id:r,schemaId:i,topic:a,messageEncoding:o,metadata:s}}function Cf(e,t){if(t<22)throw Error(`Message record length ${t} is less than 22 bytes`);return{type:`Message`,channelId:e.uint16(),sequence:e.uint32(),logTime:e.uint64(),publishTime:e.uint64(),data:e.u8ArrayCopy(t-22)}}function wf(e,t){let n=e.offset,r=e.uint64(),i=e.uint64(),a=e.uint64(),o=e.uint32(),s=e.string(),c=Number(e.uint64());if(c+(e.offset-n)>t)throw Error(`Chunk records length exceeds remaining record size`);let l=e.u8ArrayCopy(c);return e.offset=n+t,{type:`Chunk`,messageStartTime:r,messageEndTime:i,compression:s,uncompressedSize:a,uncompressedCrc:o,records:l}}function Tf(e,t){let n=e.offset,r=e.uint16(),i=e.keyValuePairs(e=>e.uint64(),e=>e.uint64());return e.offset=n+t,{type:`MessageIndex`,channelId:r,records:i}}function Ef(e,t){let n=e.offset,r=e.uint64(),i=e.uint64(),a=e.uint64(),o=e.uint64(),s=e.map(e=>e.uint16(),e=>e.uint64()),c=e.uint64(),l=e.string(),u=e.uint64(),d=e.uint64();return e.offset=n+t,{type:`ChunkIndex`,messageStartTime:r,messageEndTime:i,chunkStartOffset:a,chunkLength:o,messageIndexOffsets:s,messageIndexLength:c,compression:l,compressedSize:u,uncompressedSize:d}}function Df(e,t,n){let r=e.offset,i=e.uint64(),a=e.uint64(),o=e.string(),s=e.string(),c=e.uint64();if(BigInt(e.offset)+c>2**53-1)throw Error(`Attachment too large: ${c}`);if(e.offset+Number(c)+4>r+t)throw Error(`Attachment data length ${c} exceeds bounds of record`);let l=e.u8ArrayCopy(Number(c)),u=e.offset-r,d=e.uint32();if(n&&d!==0){e.offset=r;let t=tf(e.u8ArrayBorrow(u));if(e.offset=r+u+4,t!==d)throw Error(`Attachment CRC32 mismatch: expected ${d}, actual ${t}`)}return e.offset=r+t,{type:`Attachment`,logTime:i,createTime:a,name:o,mediaType:s,data:l}}function Of(e,t){let n=e.offset,r=e.uint64(),i=e.uint64(),a=e.uint64(),o=e.uint64(),s=e.uint64(),c=e.string(),l=e.string();return e.offset=n+t,{type:`AttachmentIndex`,offset:r,length:i,logTime:a,createTime:o,dataSize:s,name:c,mediaType:l}}function kf(e,t){let n=e.offset,r=e.uint64(),i=e.uint16(),a=e.uint32(),o=e.uint32(),s=e.uint32(),c=e.uint32(),l=e.uint64(),u=e.uint64(),d=e.map(e=>e.uint16(),e=>e.uint64());return e.offset=n+t,{type:`Statistics`,messageCount:r,schemaCount:i,channelCount:a,attachmentCount:o,metadataCount:s,chunkCount:c,messageStartTime:l,messageEndTime:u,channelMessageCounts:d}}function Af(e,t){let n=e.offset,r=e.string(),i=e.map(e=>e.string(),e=>e.string());return e.offset=n+t,{type:`Metadata`,metadata:i,name:r}}function jf(e,t){let n=e.offset,r=e.uint64(),i=e.uint64(),a=e.string();return e.offset=n+t,{type:`MetadataIndex`,offset:r,length:i,name:a}}function Mf(e,t){let n=e.offset,r=e.uint8(),i=e.uint64(),a=e.uint64();return e.offset=n+t,{type:`SummaryOffset`,groupOpcode:r,groupStart:i,groupLength:a}}function Nf(e,t){let n=e.offset,r=e.uint32();return e.offset=n+t,{type:`DataEnd`,dataSectionCrc:r}}function Pf(e,t,n){let r=0,i=e.length;if(i===0)return 0;let a=n(t);for(;r<i;){let t=r+i>>>1;n(e[t][0])<a?r=t+1:i=t}return i}function Ff(e,t,n){let r=0,i=e.length;if(i===0)return 0;let a=n(t);for(;r<i;){let t=r+i>>>1;n(e[t][0])<=a?r=t+1:i=t}return i}var If=class{chunkIndex;#e;#t;#n;#r;#i;#a;#o=0;constructor(e){if(this.chunkIndex=e.chunkIndex,this.#e=e.relevantChannels,this.#t=e.startingAt,this.#n=e.endingAt,this.#r=e.reverse,this.#i=e.readFullMessageIndexRange??!1,this.chunkIndex.messageIndexLength===0n&&(this.chunkIndex.messageStartTime!==0n||this.chunkIndex.messageEndTime!==0n))throw Error(`Encountered a chunk index without message indexes and non-zero start and end times`)}compare(e){if(this.#r!==e.#r)throw Error(`Cannot compare a reversed ChunkCursor to a non-reversed ChunkCursor`);let t=Number(this.#s()-e.#s());return t===0&&(t=Number(this.chunkIndex.chunkStartOffset-e.chunkIndex.chunkStartOffset)),this.#r?-t:t}hasMoreMessages(){if(this.#a==null)throw Error(`loadMessageIndexes() must be called before hasMore()`);return this.#o<this.#a.length}popMessage(){if(this.#a==null)throw Error(`loadMessageIndexes() must be called before popMessage()`);if(this.#o>=this.#a.length)throw Error(`Unexpected popMessage() call when no more messages are available, in chunk at offset ${this.chunkIndex.chunkStartOffset}`);return this.#a[this.#o++]}hasMessageIndexes(){return this.#a!=null}async loadMessageIndexes(e,t){let n=this.#r,r,i,a=this.#i;for(let[e,t]of this.chunkIndex.messageIndexOffsets)(r==null||t<r)&&(r=t),(a||!this.#e||this.#e.has(e))&&(i==null||t<i)&&(i=t);if(r==null||i==null){this.#a=[];return}let o=r+this.chunkIndex.messageIndexLength,s=await e.read(i,o-i,t),c=new pf(new DataView(s.buffer,s.byteOffset,s.byteLength)),l=[],u;for(;u=_f(c,!0);)u.type===`MessageIndex`&&(u.records.length===0||this.#e&&!this.#e.has(u.channelId)||l.push(u.records));if(c.bytesRemaining()!==0)throw Error(`${c.bytesRemaining()} bytes remaining in message index section`);if(this.#a=l.flat().sort(([e,t],[n,r])=>{let i=Number(e-n);return i===0&&(i=Number(t-r)),i}),n&&this.#a.reverse(),this.#a.length===0)return;let[d]=this.#a[0];if(d<this.chunkIndex.messageStartTime)throw Error(`Chunk at offset ${this.chunkIndex.chunkStartOffset} contains a message with logTime (${d}) earlier than chunk messageStartTime (${this.chunkIndex.messageStartTime})`);let[f]=this.#a[this.#a.length-1];if(f>this.chunkIndex.messageEndTime)throw Error(`Chunk at offset ${this.chunkIndex.chunkStartOffset} contains a message with logTime (${f}) later than chunk messageEndTime (${this.chunkIndex.messageEndTime})`);let p=n?this.#n:this.#t,m=n?this.#t:this.#n,h=n?e=>-e:e=>e,g,_;p!=null&&(g=Pf(this.#a,p,h)),m!=null&&(_=Ff(this.#a,m,h)),(g!=null||_!=null)&&(this.#a=this.#a.slice(g,_))}#s(){return this.#a!=null&&this.#a.length>0&&this.#o<this.#a.length?this.#a[this.#o][0]:this.#r?this.chunkIndex.messageEndTime:this.chunkIndex.messageStartTime}},Lf=class e{chunkIndexes;attachmentIndexes;metadataIndexes=[];channelsById;schemasById;statistics;summaryOffsetsByOpcode;header;footer;dataEndOffset;dataSectionCrc;#e;#t;#n;#r;#i;#a;#o;constructor(e){this.#e=e.readable,this.chunkIndexes=e.chunkIndexes,this.attachmentIndexes=e.attachmentIndexes,this.metadataIndexes=e.metadataIndexes,this.statistics=e.statistics,this.#n=e.decompressHandlers,this.channelsById=e.channelsById,this.schemasById=e.schemasById,this.summaryOffsetsByOpcode=e.summaryOffsetsByOpcode,this.header=e.header,this.footer=e.footer,this.dataEndOffset=e.dataEndOffset,this.dataSectionCrc=e.dataSectionCrc;let t=e.messageIndexCacheSizeBytes??0;this.#t=t>0?new uf(this.#e,t):this.#e;for(let t of e.chunkIndexes)(this.#r==null||t.messageStartTime<this.#r)&&(this.#r=t.messageStartTime),(this.#i==null||t.messageEndTime>this.#i)&&(this.#i=t.messageEndTime);for(let t of e.attachmentIndexes)(this.#a==null||t.logTime<this.#a)&&(this.#a=t.logTime),(this.#o==null||t.logTime>this.#o)&&(this.#o=t.logTime)}#s(e){return Error(`${e} [library=${this.header.library}]`)}static async Initialize({readable:t,decompressHandlers:n,messageIndexCacheSizeBytes:r,readOptions:i}){let a=await t.size(),o,s;{let e=await t.read(0n,BigInt(mf.length+1+8),i),n=new DataView(e.buffer,e.byteOffset,e.byteLength);gf(new pf(n));let r=9n+n.getBigUint64(mf.length+1,!0),a=await t.read(BigInt(mf.length),r,i);s=BigInt(mf.length)+r;let c=new pf(new DataView(a.buffer,a.byteOffset,a.byteLength)),l=_f(c,!0);if(l?.type!==`Header`)throw Error(`Unable to read header at beginning of file; found ${l?.type??`nothing`}`);if(c.bytesRemaining()!==0)throw Error(`${c.bytesRemaining()} bytes remaining after parsing header`);o=l}function c(e){return Error(`${e} [library=${o.library}]`)}let l,u;{let e=BigInt(mf.length+1+8+4+4),n=BigInt(29+mf.length);if(a<e+n)throw c(`File size (${a}) is too small to be valid MCAP`);l=a-n;let r=await t.read(l,n,i);u=new DataView(r.buffer,r.byteOffset,r.byteLength)}try{gf(new pf(u,u.byteLength-mf.length))}catch(e){throw c(e.message)}let d;{let e=new pf(u),t=_f(e,!0);if(t?.type!==`Footer`)throw c(`Unable to read footer from end of file (offset ${l}); found ${t?.type??`nothing`}`);if(e.bytesRemaining()!==mf.length)throw c(`${e.bytesRemaining()-mf.length} bytes remaining after parsing footer`);d=t}if(d.summaryStart===0n)throw c(`File is not indexed`);let f=new Uint8Array(25);f.set(new Uint8Array(u.buffer,u.byteOffset,f.byteLength));let p=13n,m=d.summaryStart-p;if(m<s)throw c(`Expected DataEnd position (summary start ${d.summaryStart} - ${p} = ${m}) to be after Header end offset (${s})`);let h=await t.read(m,l-m,i);if(d.summaryCrc!==0){let e=Qd();if(e=$d(e,h.subarray(Number(p))),e=$d(e,f),e=ef(e),e!==d.summaryCrc)throw c(`Incorrect summary CRC ${e} (expected ${d.summaryCrc})`)}let g=new pf(new DataView(h.buffer,h.byteOffset,h.byteLength)),_=new Map,v=new Map,y=[],b=[],x=[],S=new Map,C,w,T=!0,E;for(;E=_f(g,!0);){if(T&&E.type!==`DataEnd`)throw c(`Expected DataEnd record to precede summary section, but found ${E.type}`);switch(T=!1,E.type){case`Schema`:v.set(E.id,E);break;case`Channel`:_.set(E.id,E);break;case`ChunkIndex`:y.push(E);break;case`AttachmentIndex`:b.push(E);break;case`MetadataIndex`:x.push(E);break;case`Statistics`:if(C)throw c(`Duplicate Statistics record`);C=E;break;case`SummaryOffset`:S.set(E.groupOpcode,E);break;case`DataEnd`:w=E.dataSectionCrc===0?void 0:E.dataSectionCrc;break;case`Header`:case`Footer`:case`Message`:case`Chunk`:case`MessageIndex`:case`Attachment`:case`Metadata`:throw c(`${E.type} record not allowed in index section`);case`Unknown`:break}}if(g.bytesRemaining()!==0)throw c(`${g.bytesRemaining()} bytes remaining in index section`);return new e({readable:t,chunkIndexes:y,attachmentIndexes:b,metadataIndexes:x,statistics:C,decompressHandlers:n,channelsById:_,schemasById:v,summaryOffsetsByOpcode:S,header:o,footer:d,dataEndOffset:m,dataSectionCrc:w,messageIndexCacheSizeBytes:r})}async*readMessages(e={}){let{topics:t,reverse:n=!1,validateCrcs:r,readOptions:i}=e,{startingAt:a,endingAt:o}=Rf(e,this.#r,this.#i);if(a==null||o==null)return;let s;if(t){s=new Set;for(let e of this.channelsById.values())t.includes(e.topic)&&s.add(e.id)}let c=new lf((e,t)=>e.compare(t)),l=!0,u,d=this.#t!==this.#e;for(let e of this.chunkIndexes)e.messageStartTime<=o&&e.messageEndTime>=a&&(c.push(new If({chunkIndex:e,relevantChannels:s,startingAt:a,endingAt:o,reverse:n,readFullMessageIndexRange:d})),l&&u!=null&&(l=e.messageStartTime>=u),u=e.messageEndTime);let f=new Map,p=new pf(new DataView(new ArrayBuffer(0)));for(let e;e=c.peek();){if(!e.hasMessageIndexes()){await e.loadMessageIndexes(this.#t,i),e.hasMoreMessages()?c.replace(e):c.pop();continue}let t=f.get(e.chunkIndex.chunkStartOffset);t||(t=await this.#c(e.chunkIndex,{validateCrcs:r??!0,readOptions:i}),f.set(e.chunkIndex.chunkStartOffset,t));let[n,a]=e.popMessage();if(a>=BigInt(t.byteLength))throw this.#s(`Message offset beyond chunk bounds (log time ${n}, offset ${a}, chunk data length ${t.byteLength}) in chunk at offset ${e.chunkIndex.chunkStartOffset}`);p.reset(t,Number(a));let o=_f(p,r??!0);if(!o)throw this.#s(`Unable to parse record at offset ${a} in chunk at offset ${e.chunkIndex.chunkStartOffset}`);if(o.type!==`Message`)throw this.#s(`Unexpected record type ${o.type} in message index (time ${n}, offset ${a} in chunk at offset ${e.chunkIndex.chunkStartOffset})`);if(o.logTime!==n)throw this.#s(`Message log time ${o.logTime} did not match message index entry (${n} at offset ${a} in chunk at offset ${e.chunkIndex.chunkStartOffset})`);yield o,e.hasMoreMessages()?l||c.replace(e):(c.pop(),f.delete(e.chunkIndex.chunkStartOffset))}}async*readMetadata(e={}){let{name:t,readOptions:n}=e;for(let e of this.metadataIndexes){if(t!=null&&e.name!==t)continue;let r=await this.#e.read(e.offset,e.length,n),i=_f(new pf(new DataView(r.buffer,r.byteOffset,r.byteLength)),!1);if(i?.type!==`Metadata`)throw this.#s(`Metadata data at offset ${e.offset} does not point to metadata record (found ${String(i?.type)})`);yield i}}async*readAttachments(e={}){let{name:t,mediaType:n,validateCrcs:r,readOptions:i}=e,{startingAt:a,endingAt:o}=Rf(e,this.#a,this.#o);if(!(a==null||o==null))for(let e of this.attachmentIndexes){if(t!=null&&e.name!==t||n!=null&&e.mediaType!==n||e.logTime>o||e.logTime<a)continue;let s=await this.#e.read(e.offset,e.length,i),c=_f(new pf(new DataView(s.buffer,s.byteOffset,s.byteLength)),r??!0);if(c?.type!==`Attachment`)throw this.#s(`Attachment data at offset ${e.offset} does not point to attachment record (found ${String(c?.type)})`);yield c}}async#c(e,t){let n=await this.#e.read(e.chunkStartOffset,e.chunkLength,t?.readOptions),r=_f(new pf(new DataView(n.buffer,n.byteOffset,n.byteLength)),t?.validateCrcs??!0);if(r?.type!==`Chunk`)throw this.#s(`Chunk start offset ${e.chunkStartOffset} does not point to chunk record (found ${String(r?.type)})`);let i=r,a=i.records;if(i.compression!==``&&a.byteLength>0){let e=this.#n?.[i.compression];if(!e)throw this.#s(`Unsupported compression ${i.compression}`);a=e(a,i.uncompressedSize)}if(i.uncompressedCrc!==0&&t?.validateCrcs!==!1){let e=tf(a);if(e!==i.uncompressedCrc)throw this.#s(`Incorrect chunk CRC ${e} (expected ${i.uncompressedCrc})`)}return new DataView(a.buffer,a.byteOffset,a.byteLength)}};function Rf(e,t,n){if([e.startTime,e.startingAt,e.startingAfter].filter(e=>e!=null).length>1)throw Error(`Provide at most one of startTime, startingAt, startingAfter`);if([e.endTime,e.endingAt,e.endingBefore].filter(e=>e!=null).length>1)throw Error(`Provide at most one of endTime, endingAt, endingBefore`);let r=e.startingAt??e.startTime;e.startingAfter!=null&&(r=e.startingAfter+1n);let i=e.endingAt??e.endTime;if(e.endingBefore!=null&&(i=e.endingBefore-1n),r!=null&&i!=null&&r>i+1n)throw Error(`end time cannot come before start time`);return{startingAt:r??t,endingAt:i??n}}var zf=class{#e=new ArrayBuffer(mf.length*2);#t=new DataView(this.#e,0,0);#n=new pf(this.#t);#r;#i;#a;#o;#s;#c=!1;#l=this.#f();#u=new Map;constructor({includeChunks:e=!1,emitChunks:t=!1,decompressHandlers:n={},validateCrcs:r=!0,noMagicPrefix:i=!1}={}){this.#i=e,this.#a=t,this.#r=n,this.#o=r,this.#s=i}done(){return this.#c}bytesRemaining(){return this.#n.bytesRemaining()}append(e){if(this.#c)throw Error(`Already done reading`);this.#d(e)}#d(e){let t=this.#n.offset,n=this.#t.byteLength-t,r=n+e.byteLength;if(r<=this.#e.byteLength)if(this.#t.byteOffset+this.#t.byteLength+e.byteLength<=this.#e.byteLength)new Uint8Array(this.#e,this.#t.byteOffset).set(e,this.#t.byteLength),this.#t=new DataView(this.#e,this.#t.byteOffset,this.#t.byteLength+e.byteLength),this.#n.reset(this.#t,this.#n.offset);else{let r=new Uint8Array(this.#e,this.#t.byteOffset+t,n),i=new Uint8Array(this.#e);i.set(r,0),i.set(e,r.byteLength),this.#t=new DataView(this.#e,0,r.byteLength+e.byteLength),this.#n.reset(this.#t)}else{this.#e=new ArrayBuffer(r*2);let i=new Uint8Array(this.#e),a=new Uint8Array(this.#t.buffer,this.#t.byteOffset+t,n);i.set(a,0),i.set(e,a.byteLength),this.#t=new DataView(this.#e,0,a.byteLength+e.byteLength),this.#n.reset(this.#t)}}nextRecord(){if(this.#c)return;let e=this.#l.next();if(e.value?.type===`Channel`){let t=this.#u.get(e.value.id);if(this.#u.set(e.value.id,e.value),t&&!Bf(t,e.value))throw Error(`Channel record for id ${e.value.id} (topic: ${e.value.topic}) differs from previous channel record of the same id.`)}else if(!this.#a&&e.value?.type===`Message`){let t=e.value.channelId;if(!this.#u.get(t))throw Error(`Encountered message on channel ${t} without prior channel record`)}return e.done===!0&&(this.#c=!0),e.value}*#f(){if(!this.#s){let e;for(;e=gf(this.#n),!e;)yield}let e;function t(t){return Error(`${t} ${e?`[library=${e.library}]`:`[no header]`}`)}for(;;){let n;for(;n=_f(this.#n,this.#o),!n;)yield;switch(n.type){case`Header`:if(e)throw Error(`Duplicate Header record: library=${e.library} profile=${e.profile} vs. library=${n.library} profile=${n.profile}`);e=n,yield n;break;case`Unknown`:case`Schema`:case`Channel`:case`Message`:case`MessageIndex`:case`ChunkIndex`:case`Attachment`:case`AttachmentIndex`:case`Statistics`:case`Metadata`:case`MetadataIndex`:case`SummaryOffset`:case`DataEnd`:yield n;break;case`Chunk`:{if(this.#a){yield n;break}this.#i&&(yield n);let e=n.records;if(n.compression!==``&&e.byteLength>0){let r=this.#r[n.compression];if(!r)throw t(`Unsupported compression ${n.compression}`);e=r(e,n.uncompressedSize)}if(this.#o&&n.uncompressedCrc!==0){let r=tf(e);if(r!==n.uncompressedCrc)throw t(`Incorrect chunk CRC ${r} (expected ${n.uncompressedCrc})`)}let r=new pf(new DataView(e.buffer,e.byteOffset,e.byteLength)),i;for(;i=_f(r,this.#o);)switch(i.type){case`Header`:case`Footer`:case`Chunk`:case`MessageIndex`:case`ChunkIndex`:case`Attachment`:case`AttachmentIndex`:case`Statistics`:case`Metadata`:case`MetadataIndex`:case`SummaryOffset`:case`DataEnd`:throw t(`${i.type} record not allowed inside a chunk`);case`Unknown`:case`Schema`:case`Channel`:case`Message`:yield i;break}if(r.bytesRemaining()!==0)throw t(`${r.bytesRemaining()} bytes remaining in chunk`);break}case`Footer`:try{let e;for(;e=gf(this.#n),!e;)yield}catch(e){throw t(e.message)}if(this.#n.bytesRemaining()!==0)throw t(`${this.#n.bytesRemaining()} bytes remaining after MCAP footer and trailing magic`);return n}}}};function Bf(e,t){if(!(e.id===t.id&&e.messageEncoding===t.messageEncoding&&e.schemaId===t.schemaId&&e.topic===t.topic&&e.metadata.size===t.metadata.size))return!1;for(let[n,r]of e.metadata.entries())if(r!==t.metadata.get(n))return!1;return!0}var Vf=ArrayBuffer,q=Uint8Array,Hf=Uint16Array,Uf=Int16Array,Wf=Int32Array,Gf=function(e,t,n){if(q.prototype.slice)return q.prototype.slice.call(e,t,n);(t==null||t<0)&&(t=0),(n==null||n>e.length)&&(n=e.length);var r=new q(n-t);return r.set(e.subarray(t,n)),r},Kf=function(e,t,n,r){if(q.prototype.fill)return q.prototype.fill.call(e,t,n,r);for((n==null||n<0)&&(n=0),(r==null||r>e.length)&&(r=e.length);n<r;++n)e[n]=t;return e},qf=function(e,t,n,r){if(q.prototype.copyWithin)return q.prototype.copyWithin.call(e,t,n,r);for((n==null||n<0)&&(n=0),(r==null||r>e.length)&&(r=e.length);n<r;)e[t++]=e[n++]},Jf=[`invalid zstd data`,`window size too large (>2046MB)`,`invalid block type`,`FSE accuracy too high`,`match distance too far back`,`unexpected EOF`],J=function(e,t,n){var r=Error(t||Jf[e]);if(r.code=e,Error.captureStackTrace&&Error.captureStackTrace(r,J),!n)throw r;return r},Yf=function(e,t,n){for(var r=0,i=0;r<n;++r)i|=e[t++]<<(r<<3);return i},Xf=function(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0},Zf=function(e,t){var n=e[0]|e[1]<<8|e[2]<<16;if(n==3126568&&e[3]==253){var r=e[4],i=r>>5&1,a=r>>2&1,o=r&3,s=r>>6;r&8&&J(0);var c=6-i,l=o==3?4:o,u=Yf(e,c,l);c+=l;var d=s?1<<s:i,f=Yf(e,c,d)+(s==1&&256),p=f;if(!i){var m=1<<10+(e[5]>>3);p=m+(m>>3)*(e[5]&7)}p>2145386496&&J(1);var h=new q((t==1?f||p:t?0:p)+12);return h[0]=1,h[4]=4,h[8]=8,{b:c+d,y:0,l:0,d:u,w:t&&t!=1?t:h.subarray(12),e:p,o:new Wf(h.buffer,0,3),u:f,c:a,m:Math.min(131072,p)}}else if((n>>4|e[3]<<20)==25481893)return Xf(e,4)+8;J(0)},Qf=function(e){for(var t=0;1<<t<=e;++t);return t-1},$f=function(e,t,n){var r=(t<<3)+4,i=(e[t]&15)+5;i>n&&J(3);for(var a=1<<i,o=a,s=-1,c=-1,l=-1,u=a,d=new Vf(512+(a<<2)),f=new Uf(d,0,256),p=new Hf(d,0,256),m=new Hf(d,512,a),h=512+(a<<1),g=new q(d,h,a),_=new q(d,h+a);s<255&&o>0;){var v=Qf(o+1),y=r>>3,b=(1<<v+1)-1,x=(e[y]|e[y+1]<<8|e[y+2]<<16)>>(r&7)&b,S=(1<<v)-1,C=b-o-1,w=x&S;if(w<C?(r+=v,x=w):(r+=v+1,x>S&&(x-=C)),f[++s]=--x,x==-1?(o+=x,g[--u]=s):o-=x,!x)do{var T=r>>3;c=(e[T]|e[T+1]<<8)>>(r&7)&3,r+=2,s+=c}while(c==3)}(s>255||o)&&J(0);for(var E=0,D=(a>>1)+(a>>3)+3,O=a-1,k=0;k<=s;++k){var A=f[k];if(A<1){p[k]=-A;continue}for(l=0;l<A;++l){g[E]=k;do E=E+D&O;while(E>=u)}}for(E&&J(0),l=0;l<a;++l){var j=p[g[l]]++;m[l]=(j<<(_[l]=i-Qf(j)))-a}return[r+7>>3,{b:i,s:g,n:_,t:m}]},ep=function(e,t){var n=0,r=-1,i=new q(292),a=e[t],o=i.subarray(0,256),s=i.subarray(256,268),c=new Hf(i.buffer,268);if(a<128){var l=$f(e,t+1,6),u=l[0],d=l[1];t+=a;var f=u<<3,p=e[t];p||J(0);for(var m=0,h=0,g=d.b,_=g,v=(++t<<3)-8+Qf(p);v-=g,!(v<f);){var y=v>>3;if(m+=(e[y]|e[y+1]<<8)>>(v&7)&(1<<g)-1,o[++r]=d.s[m],v-=_,v<f)break;y=v>>3,h+=(e[y]|e[y+1]<<8)>>(v&7)&(1<<_)-1,o[++r]=d.s[h],g=d.n[m],m=d.t[m],_=d.n[h],h=d.t[h]}++r>255&&J(0)}else{for(r=a-127;n<r;n+=2){var b=e[++t];o[n]=b>>4,o[n+1]=b&15}++t}var x=0;for(n=0;n<r;++n){var S=o[n];S>11&&J(0),x+=S&&1<<S-1}var C=Qf(x)+1,w=1<<C,T=w-x;for(T&T-1&&J(0),o[r++]=Qf(T)+1,n=0;n<r;++n){var S=o[n];++s[o[n]=S&&C+1-S]}var E=new q(w<<1),D=E.subarray(0,w),O=E.subarray(w);for(c[C]=0,n=C;n>0;--n){var k=c[n];Kf(O,n,k,c[n-1]=k+s[n]*(1<<C-n))}for(c[0]!=w&&J(0),n=0;n<r;++n){var A=o[n];if(A){var j=c[A];Kf(D,n,j,c[A]=j+(1<<C-A))}}return[t,{n:O,b:C,s:D}]},tp=$f(new q([81,16,99,140,49,198,24,99,12,33,196,24,99,102,102,134,70,146,4]),0,6)[1],np=$f(new q([33,20,196,24,99,140,33,132,16,66,8,33,132,16,66,8,33,68,68,68,68,68,68,68,68,36,9]),0,6)[1],rp=$f(new q([32,132,16,66,102,70,68,68,68,68,36,73,2]),0,5)[1],ip=function(e,t){for(var n=e.length,r=new Wf(n),i=0;i<n;++i)r[i]=t,t+=1<<e[i];return r},ap=new q(new Wf([0,0,0,0,16843009,50528770,134678020,202050057,269422093]).buffer,0,36),op=ip(ap,0),sp=new q(new Wf([0,0,0,0,0,0,0,0,16843009,50528770,117769220,185207048,252579084,16]).buffer,0,53),cp=ip(sp,3),lp=function(e,t,n){var r=e.length,i=t.length,a=e[r-1],o=(1<<n.b)-1,s=-n.b;a||J(0);for(var c=0,l=n.b,u=(r<<3)-8+Qf(a)-l,d=-1;u>s&&d<i;){var f=u>>3,p=(e[f]|e[f+1]<<8|e[f+2]<<16)>>(u&7);c=(c<<l|p)&o,t[++d]=n.s[c],u-=l=n.n[c]}(u!=s||d+1!=i)&&J(0)},up=function(e,t,n){var r=6,i=t.length+3>>2,a=i<<1,o=i+a;lp(e.subarray(r,r+=e[0]|e[1]<<8),t.subarray(0,i),n),lp(e.subarray(r,r+=e[2]|e[3]<<8),t.subarray(i,a),n),lp(e.subarray(r,r+=e[4]|e[5]<<8),t.subarray(a,o),n),lp(e.subarray(r),t.subarray(o),n)},dp=function(e,t,n){var r,i=t.b,a=e[i],o=a>>1&3;t.l=a&1;var s=a>>3|e[i+1]<<5|e[i+2]<<13,c=(i+=3)+s;if(o==1)return i>=e.length?void 0:(t.b=i+1,n?(Kf(n,e[i],t.y,t.y+=s),n):Kf(new q(s),e[i]));if(!(c>e.length)){if(o==0)return t.b=c,n?(n.set(e.subarray(i,c),t.y),t.y+=s,n):Gf(e,i,c);if(o==2){var l=e[i],u=l&3,d=l>>2&3,f=l>>4,p=0,m=0;u<2?d&1?f|=e[++i]<<4|(d&2&&e[++i]<<12):f=l>>3:(m=d,d<2?(f|=(e[++i]&63)<<4,p=e[i]>>6|e[++i]<<2):d==2?(f|=e[++i]<<4|(e[++i]&3)<<12,p=e[i]>>2|e[++i]<<6):(f|=e[++i]<<4|(e[++i]&63)<<12,p=e[i]>>6|e[++i]<<2|e[++i]<<10)),++i;var h=n?n.subarray(t.y,t.y+t.m):new q(t.m),g=h.length-f;if(u==0)h.set(e.subarray(i,i+=f),g);else if(u==1)Kf(h,e[i++],g);else{var _=t.h;if(u==2){var v=ep(e,i);p+=i-(i=v[0]),t.h=_=v[1]}else _||J(0);(m?up:lp)(e.subarray(i,i+=p),h.subarray(g),_)}var y=e[i++];if(y){y==255?y=(e[i++]|e[i++]<<8)+32512:y>127&&(y=y-128<<8|e[i++]);var b=e[i++];b&3&&J(0);for(var x=[np,rp,tp],S=2;S>-1;--S){var C=b>>(S<<1)+2&3;if(C==1){var w=new q([0,0,e[i++]]);x[S]={s:w.subarray(2,3),n:w.subarray(0,1),t:new Hf(w.buffer,0,1),b:0}}else C==2?(r=$f(e,i,9-(S&1)),i=r[0],x[S]=r[1]):C==3&&(t.t||J(0),x[S]=t.t[S])}var T=t.t=x,E=T[0],D=T[1],O=T[2],k=e[c-1];k||J(0);var A=(c<<3)-8+Qf(k)-O.b,j=A>>3,M=0,N=(e[j]|e[j+1]<<8)>>(A&7)&(1<<O.b)-1;j=(A-=D.b)>>3;var P=(e[j]|e[j+1]<<8)>>(A&7)&(1<<D.b)-1;j=(A-=E.b)>>3;var ee=(e[j]|e[j+1]<<8)>>(A&7)&(1<<E.b)-1;for(++y;--y;){var te=O.s[N],ne=O.n[N],re=E.s[ee],ie=E.n[ee],ae=D.s[P],oe=D.n[P];j=(A-=ae)>>3;var se=1<<ae,ce=se+((e[j]|e[j+1]<<8|e[j+2]<<16|e[j+3]<<24)>>>(A&7)&se-1);j=(A-=sp[re])>>3;var le=cp[re]+((e[j]|e[j+1]<<8|e[j+2]<<16)>>(A&7)&(1<<sp[re])-1);j=(A-=ap[te])>>3;var ue=op[te]+((e[j]|e[j+1]<<8|e[j+2]<<16)>>(A&7)&(1<<ap[te])-1);if(j=(A-=ne)>>3,N=O.t[N]+((e[j]|e[j+1]<<8)>>(A&7)&(1<<ne)-1),j=(A-=ie)>>3,ee=E.t[ee]+((e[j]|e[j+1]<<8)>>(A&7)&(1<<ie)-1),j=(A-=oe)>>3,P=D.t[P]+((e[j]|e[j+1]<<8)>>(A&7)&(1<<oe)-1),ce>3)t.o[2]=t.o[1],t.o[1]=t.o[0],t.o[0]=ce-=3;else{var de=ce-(ue!=0);de?(ce=de==3?t.o[0]-1:t.o[de],de>1&&(t.o[2]=t.o[1]),t.o[1]=t.o[0],t.o[0]=ce):ce=t.o[0]}for(var S=0;S<ue;++S)h[M+S]=h[g+S];M+=ue,g+=ue;var fe=M-ce;if(fe<0){var pe=-fe,me=t.e+fe;pe>le&&(pe=le);for(var S=0;S<pe;++S)h[M+S]=t.w[me+S];M+=pe,le-=pe,fe=0}for(var S=0;S<le;++S)h[M+S]=h[fe+S];M+=le}if(M!=g)for(;g<h.length;)h[M++]=h[g++];else M=h.length;n?t.y+=M:h=Gf(h,0,M)}else if(n){if(t.y+=f,g)for(var S=0;S<f;++S)h[S]=h[g+S]}else g&&(h=Gf(h,g));return t.b=c,h}J(2)}},fp=function(e,t){if(e.length==1)return e[0];for(var n=new q(t),r=0,i=0;r<e.length;++r){var a=e[r];n.set(a,i),i+=a.length}return n};function pp(e,t){for(var n=[],r=+!t,i=0,a=0;e.length;){var o=Zf(e,r||t);if(typeof o==`object`){for(r?(t=null,o.w.length==o.u&&(n.push(t=o.w),a+=o.u)):(n.push(t),o.e=0);!o.l;){var s=dp(e,o,t);s||J(5),t?o.e=o.y:(n.push(s),a+=s.length,qf(o.w,0,s.length),o.w.set(s,o.w.length-s.length))}i=o.b+o.c*4}else i=o;e=e.subarray(i)}return fp(n,a)}var mp=e(((e,t)=>{(()=>{var e={91:((e,t)=>{Object.defineProperty(t,`__esModule`,{value:!0}),t.buildRos2Type=w;let n=String.raw`(?<type>[a-zA-Z0-9_/]+)`,r=String.raw`(?:<=(?<stringBound>\d+))`,i=String.raw`(?:(?<unboundedArray>\[\])|\[(?<arrayLength>\d+)\]|\[<=(?<arrayBound>\d+)\])`,a=String.raw`(?<name>[a-zA-Z0-9_]+)`,o=String.raw`'(?:\\.|[^'\\])*'|"(?:\\.|[^"\\])*"`,s=String.raw`(?:${o}|(?:\\.|[^\s'"#\\])(?:\\.|[^#\\])*)`,c=String.raw`(?:${o}|(?:\\.|[^\s'"\],#\\])(?:\\.|[^\],#\\])*)`,l=String.raw`\s*=\s*(?<constantValue>${s}?)`,u=String.raw`\[(?:${c},)*${c}?\]`,d=String.raw`(?<defaultValue>${u}|${s})`,f=String.raw`(?:#.*)`,p=new RegExp(String.raw`^${n}${r}?${i}?\s+${a}(?:${l}|\s+${d})?\s*${f}?$`),m=String.raw`\\(?<char>['"abfnrtv\\])|\\(?<oct>[0-7]{1,3})|\\x(?<hex2>[a-fA-F0-9]{2})|\\u(?<hex4>[a-fA-F0-9]{4})|\\U(?<hex8>[a-fA-F0-9]{8})`,h=[`bool`,`byte`,`char`,`float32`,`float64`,`int8`,`uint8`,`int16`,`uint16`,`int32`,`uint32`,`int64`,`uint64`,`string`,`wstring`,`time`,`duration`,`builtin_interfaces/Time`,`builtin_interfaces/Duration`,`builtin_interfaces/msg/Time`,`builtin_interfaces/msg/Duration`];function g(e,t,n){let r=BigInt(e);if(r<t||r>n)throw Error(`Number ${e} out of range [${t}, ${n}]`);return r}function _(e,t,n){let r=parseInt(e);if(Number.isNaN(r))throw Error(`Invalid numeric literal: ${e}`);if(r<t||r>n)throw Error(`Number ${e} out of range [${t}, ${n}]`);return r}let v=new RegExp(c,`y`),y=/\s*(,)\s*|\s*$/y;function b(e,t){if(!t.startsWith(`[`)||!t.endsWith(`]`))throw Error(`Array must start with [ and end with ]`);let n=t.substring(1,t.length-1);if(e===`string`||e===`wstring`){let e=[],t=0;for(;t<n.length;){if(n[t]===`,`)throw Error(`Expected array element before comma`);v.lastIndex=t;let r=v.exec(n);if(r&&(e.push(x(r[0])),t=v.lastIndex),y.lastIndex=t,r=y.exec(n),!r)throw Error(`Expected comma or end of array`);if(!r[1])break;t=y.lastIndex}return e}return n.split(`,`).map(t=>S(e,t.trim()))}function x(e){let t=``,n=e;for(let r of[`'`,`"`])if(e.startsWith(r)){if(!e.endsWith(r))throw Error(`Expected terminating ${r} in string literal: ${e}`);t=r,n=e.substring(r.length,e.length-r.length);break}if(!new RegExp(String.raw`^(?:[^\\${t}]|${m})*$`).test(n)==null)throw Error(`Invalid string literal: ${n}`);return n.replace(new RegExp(m,`g`),(...e)=>{let{char:t,oct:n,hex2:r,hex4:i,hex8:a}=e[e.length-1],o=r??i??a;if(t!=null)return{"'":`'`,'"':`"`,a:`\x07`,b:`\b`,f:`\f`,n:`
44
44
  `,r:`\r`,t:` `,v:`\v`,"\\":`\\`}[t];if(n!=null)return String.fromCodePoint(parseInt(n,8));if(o!=null)return String.fromCodePoint(parseInt(o,16));throw Error(`Expected exactly one matched group`)})}function S(e,t){switch(e){case`bool`:if([`true`,`True`,`1`].includes(t))return!0;if([`false`,`False`,`0`].includes(t))return!1;break;case`float32`:case`float64`:{let e=parseFloat(t);if(!Number.isNaN(e))return e;break}case`int8`:return _(t,-128,127);case`uint8`:return _(t,0,255);case`int16`:return _(t,-32768,32767);case`uint16`:return _(t,0,65535);case`int32`:return _(t,-2147483648,2147483647);case`uint32`:return _(t,0,4294967295);case`int64`:return g(t,-9223372036854775808n,9223372036854775807n);case`uint64`:return g(t,0n,18446744073709551615n);case`string`:case`wstring`:return x(t)}throw Error(`Invalid literal of type ${e}: ${t}`)}function C(e){switch(e){case`char`:return`uint8`;case`byte`:return`uint8`;case`builtin_interfaces/Time`:case`builtin_interfaces/msg/Time`:return`time`;case`builtin_interfaces/Duration`:case`builtin_interfaces/msg/Duration`:return`duration`}return e}function w(e){let t=[],n;for(let{line:r}of e){let e;if(!r.startsWith(`#`))if(e=/^MSG: ([^ ]+)\s*(?:#.+)?$/.exec(r)){n=e[1];continue}else if(e=p.exec(r)){let{type:n,stringBound:r,unboundedArray:i,arrayLength:a,arrayBound:o,name:s,constantValue:c,defaultValue:l}=e.groups,u=C(n);if(r!=null&&u!==`string`&&u!==`wstring`)throw Error(`Invalid string bound for type ${u}`);if(c!=null){if(!/^[A-Z](?:_?[A-Z0-9]+)*$/.test(s))throw Error(`Invalid constant name: ${s}`)}else if(!/^[a-z](?:_?[a-z0-9]+)*$/.test(s))throw Error(`Invalid field name: ${s}`);let d=!h.includes(u),f=i!=null||a!=null||o!=null;t.push({name:s,type:u,isComplex:c==null?d:d||void 0,isConstant:c!=null||void 0,isArray:c==null?f:f||void 0,arrayLength:a==null?void 0:parseInt(a),arrayUpperBound:o==null?void 0:parseInt(o),upperBound:r==null?void 0:parseInt(r),defaultValue:l==null?void 0:f?b(u,l.trim()):S(u,l.trim()),value:c==null?void 0:S(u,c.trim()),valueText:c?.trim()})}else throw Error(`Could not parse line: '${r}'`)}return{name:n,definitions:t}}}),155:(function(e,t,n){var r=this&&this.__createBinding||(Object.create?(function(e,t,n,r){r===void 0&&(r=n);var i=Object.getOwnPropertyDescriptor(t,n);(!i||(`get`in i?!t.__esModule:i.writable||i.configurable))&&(i={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,i)}):(function(e,t,n,r){r===void 0&&(r=n),e[r]=t[n]})),i=this&&this.__exportStar||function(e,t){for(var n in e)n!==`default`&&!Object.prototype.hasOwnProperty.call(t,n)&&r(t,e,n)};Object.defineProperty(t,`__esModule`,{value:!0}),i(n(498),t),i(n(900),t)}),425:((e,t,n)=>{Object.defineProperty(t,`__esModule`,{value:!0}),t.md5=a;let r=n(479),i=new Set([`int8`,`uint8`,`int16`,`uint16`,`int32`,`uint32`,`int64`,`uint64`,`float32`,`float64`,`string`,`bool`,`char`,`byte`,`time`,`duration`]);function a(e){if(e.length===0)throw Error(`Cannot produce md5sum for empty msgDefs`);let t=new Map;for(let n of e)n.name!=null&&t.set(n.name,n);let n=e[0];return o(n,t)}function o(e,t){let n=``,i=e.definitions.filter(({isConstant:e})=>e),a=e.definitions.filter(({isConstant:e})=>e==null||!e);for(let e of i)n+=`${e.type} ${e.name}=${e.valueText??String(e.value)}\n`;for(let e of a)if(s(e.type)){let t=e.arrayLength==null?``:String(e.arrayLength),r=e.isArray===!0?`[${t}]`:``;n+=`${e.type}${r} ${e.name}\n`}else{let r=t.get(e.type);if(r==null)throw Error(`Missing definition for submessage type "${e.type}"`);let i=o(r,t);n+=`${i} ${e.name}\n`}return n=n.trimEnd(),r.Md5.init(n)}function s(e){return i.has(e)}}),479:((e,t,n)=>{n.r(t),n.d(t,{Md5:()=>r});var r=function(){function e(){}return e.AddUnsigned=function(e,t){var n,r,i=e&2147483648,a=t&2147483648,o;return n=e&1073741824,r=t&1073741824,o=(e&1073741823)+(t&1073741823),n&r?o^2147483648^i^a:n|r?o&1073741824?o^3221225472^i^a:o^1073741824^i^a:o^i^a},e.FF=function(e,t,n,r,i,a,o){return e=this.AddUnsigned(e,this.AddUnsigned(this.AddUnsigned(this.F(t,n,r),i),o)),this.AddUnsigned(this.RotateLeft(e,a),t)},e.GG=function(e,t,n,r,i,a,o){return e=this.AddUnsigned(e,this.AddUnsigned(this.AddUnsigned(this.G(t,n,r),i),o)),this.AddUnsigned(this.RotateLeft(e,a),t)},e.HH=function(e,t,n,r,i,a,o){return e=this.AddUnsigned(e,this.AddUnsigned(this.AddUnsigned(this.H(t,n,r),i),o)),this.AddUnsigned(this.RotateLeft(e,a),t)},e.II=function(e,t,n,r,i,a,o){return e=this.AddUnsigned(e,this.AddUnsigned(this.AddUnsigned(this.I(t,n,r),i),o)),this.AddUnsigned(this.RotateLeft(e,a),t)},e.ConvertToWordArray=function(e){for(var t,n=e.length,r=n+8,i=((r-r%64)/64+1)*16,a=Array(i-1),o=0,s=0;s<n;)t=(s-s%4)/4,o=s%4*8,a[t]=a[t]|e.charCodeAt(s)<<o,s++;return t=(s-s%4)/4,o=s%4*8,a[t]=a[t]|128<<o,a[i-2]=n<<3,a[i-1]=n>>>29,a},e.WordToHex=function(e){var t=``,n=``,r,i;for(i=0;i<=3;i++)r=e>>>i*8&255,n=`0`+r.toString(16),t+=n.substr(n.length-2,2);return t},e.Utf8Encode=function(e){var t=``,n;e=e.replace(/\r\n/g,`
45
45
  `);for(var r=0;r<e.length;r++)n=e.charCodeAt(r),n<128?t+=String.fromCharCode(n):n>127&&n<2048?(t+=String.fromCharCode(n>>6|192),t+=String.fromCharCode(n&63|128)):(t+=String.fromCharCode(n>>12|224),t+=String.fromCharCode(n>>6&63|128),t+=String.fromCharCode(n&63|128));return t},e.init=function(e){var t;for(typeof e!=`string`&&(e=JSON.stringify(e)),this._string=this.Utf8Encode(e),this.x=this.ConvertToWordArray(this._string),this.a=1732584193,this.b=4023233417,this.c=2562383102,this.d=271733878,this.k=0;this.k<this.x.length;this.k+=16)this.AA=this.a,this.BB=this.b,this.CC=this.c,this.DD=this.d,this.a=this.FF(this.a,this.b,this.c,this.d,this.x[this.k],this.S11,3614090360),this.d=this.FF(this.d,this.a,this.b,this.c,this.x[this.k+1],this.S12,3905402710),this.c=this.FF(this.c,this.d,this.a,this.b,this.x[this.k+2],this.S13,606105819),this.b=this.FF(this.b,this.c,this.d,this.a,this.x[this.k+3],this.S14,3250441966),this.a=this.FF(this.a,this.b,this.c,this.d,this.x[this.k+4],this.S11,4118548399),this.d=this.FF(this.d,this.a,this.b,this.c,this.x[this.k+5],this.S12,1200080426),this.c=this.FF(this.c,this.d,this.a,this.b,this.x[this.k+6],this.S13,2821735955),this.b=this.FF(this.b,this.c,this.d,this.a,this.x[this.k+7],this.S14,4249261313),this.a=this.FF(this.a,this.b,this.c,this.d,this.x[this.k+8],this.S11,1770035416),this.d=this.FF(this.d,this.a,this.b,this.c,this.x[this.k+9],this.S12,2336552879),this.c=this.FF(this.c,this.d,this.a,this.b,this.x[this.k+10],this.S13,4294925233),this.b=this.FF(this.b,this.c,this.d,this.a,this.x[this.k+11],this.S14,2304563134),this.a=this.FF(this.a,this.b,this.c,this.d,this.x[this.k+12],this.S11,1804603682),this.d=this.FF(this.d,this.a,this.b,this.c,this.x[this.k+13],this.S12,4254626195),this.c=this.FF(this.c,this.d,this.a,this.b,this.x[this.k+14],this.S13,2792965006),this.b=this.FF(this.b,this.c,this.d,this.a,this.x[this.k+15],this.S14,1236535329),this.a=this.GG(this.a,this.b,this.c,this.d,this.x[this.k+1],this.S21,4129170786),this.d=this.GG(this.d,this.a,this.b,this.c,this.x[this.k+6],this.S22,3225465664),this.c=this.GG(this.c,this.d,this.a,this.b,this.x[this.k+11],this.S23,643717713),this.b=this.GG(this.b,this.c,this.d,this.a,this.x[this.k],this.S24,3921069994),this.a=this.GG(this.a,this.b,this.c,this.d,this.x[this.k+5],this.S21,3593408605),this.d=this.GG(this.d,this.a,this.b,this.c,this.x[this.k+10],this.S22,38016083),this.c=this.GG(this.c,this.d,this.a,this.b,this.x[this.k+15],this.S23,3634488961),this.b=this.GG(this.b,this.c,this.d,this.a,this.x[this.k+4],this.S24,3889429448),this.a=this.GG(this.a,this.b,this.c,this.d,this.x[this.k+9],this.S21,568446438),this.d=this.GG(this.d,this.a,this.b,this.c,this.x[this.k+14],this.S22,3275163606),this.c=this.GG(this.c,this.d,this.a,this.b,this.x[this.k+3],this.S23,4107603335),this.b=this.GG(this.b,this.c,this.d,this.a,this.x[this.k+8],this.S24,1163531501),this.a=this.GG(this.a,this.b,this.c,this.d,this.x[this.k+13],this.S21,2850285829),this.d=this.GG(this.d,this.a,this.b,this.c,this.x[this.k+2],this.S22,4243563512),this.c=this.GG(this.c,this.d,this.a,this.b,this.x[this.k+7],this.S23,1735328473),this.b=this.GG(this.b,this.c,this.d,this.a,this.x[this.k+12],this.S24,2368359562),this.a=this.HH(this.a,this.b,this.c,this.d,this.x[this.k+5],this.S31,4294588738),this.d=this.HH(this.d,this.a,this.b,this.c,this.x[this.k+8],this.S32,2272392833),this.c=this.HH(this.c,this.d,this.a,this.b,this.x[this.k+11],this.S33,1839030562),this.b=this.HH(this.b,this.c,this.d,this.a,this.x[this.k+14],this.S34,4259657740),this.a=this.HH(this.a,this.b,this.c,this.d,this.x[this.k+1],this.S31,2763975236),this.d=this.HH(this.d,this.a,this.b,this.c,this.x[this.k+4],this.S32,1272893353),this.c=this.HH(this.c,this.d,this.a,this.b,this.x[this.k+7],this.S33,4139469664),this.b=this.HH(this.b,this.c,this.d,this.a,this.x[this.k+10],this.S34,3200236656),this.a=this.HH(this.a,this.b,this.c,this.d,this.x[this.k+13],this.S31,681279174),this.d=this.HH(this.d,this.a,this.b,this.c,this.x[this.k],this.S32,3936430074),this.c=this.HH(this.c,this.d,this.a,this.b,this.x[this.k+3],this.S33,3572445317),this.b=this.HH(this.b,this.c,this.d,this.a,this.x[this.k+6],this.S34,76029189),this.a=this.HH(this.a,this.b,this.c,this.d,this.x[this.k+9],this.S31,3654602809),this.d=this.HH(this.d,this.a,this.b,this.c,this.x[this.k+12],this.S32,3873151461),this.c=this.HH(this.c,this.d,this.a,this.b,this.x[this.k+15],this.S33,530742520),this.b=this.HH(this.b,this.c,this.d,this.a,this.x[this.k+2],this.S34,3299628645),this.a=this.II(this.a,this.b,this.c,this.d,this.x[this.k],this.S41,4096336452),this.d=this.II(this.d,this.a,this.b,this.c,this.x[this.k+7],this.S42,1126891415),this.c=this.II(this.c,this.d,this.a,this.b,this.x[this.k+14],this.S43,2878612391),this.b=this.II(this.b,this.c,this.d,this.a,this.x[this.k+5],this.S44,4237533241),this.a=this.II(this.a,this.b,this.c,this.d,this.x[this.k+12],this.S41,1700485571),this.d=this.II(this.d,this.a,this.b,this.c,this.x[this.k+3],this.S42,2399980690),this.c=this.II(this.c,this.d,this.a,this.b,this.x[this.k+10],this.S43,4293915773),this.b=this.II(this.b,this.c,this.d,this.a,this.x[this.k+1],this.S44,2240044497),this.a=this.II(this.a,this.b,this.c,this.d,this.x[this.k+8],this.S41,1873313359),this.d=this.II(this.d,this.a,this.b,this.c,this.x[this.k+15],this.S42,4264355552),this.c=this.II(this.c,this.d,this.a,this.b,this.x[this.k+6],this.S43,2734768916),this.b=this.II(this.b,this.c,this.d,this.a,this.x[this.k+13],this.S44,1309151649),this.a=this.II(this.a,this.b,this.c,this.d,this.x[this.k+4],this.S41,4149444226),this.d=this.II(this.d,this.a,this.b,this.c,this.x[this.k+11],this.S42,3174756917),this.c=this.II(this.c,this.d,this.a,this.b,this.x[this.k+2],this.S43,718787259),this.b=this.II(this.b,this.c,this.d,this.a,this.x[this.k+9],this.S44,3951481745),this.a=this.AddUnsigned(this.a,this.AA),this.b=this.AddUnsigned(this.b,this.BB),this.c=this.AddUnsigned(this.c,this.CC),this.d=this.AddUnsigned(this.d,this.DD);return t=this.WordToHex(this.a)+this.WordToHex(this.b)+this.WordToHex(this.c)+this.WordToHex(this.d),t.toLowerCase()},e.x=[],e.S11=7,e.S12=12,e.S13=17,e.S14=22,e.S21=5,e.S22=9,e.S23=14,e.S24=20,e.S31=4,e.S32=11,e.S33=16,e.S34=23,e.S41=6,e.S42=10,e.S43=15,e.S44=21,e.RotateLeft=function(e,t){return e<<t|e>>>32-t},e.F=function(e,t,n){return e&t|~e&n},e.G=function(e,t,n){return e&n|t&~n},e.H=function(e,t,n){return e^t^n},e.I=function(e,t,n){return t^(e|~n)},e}()}),498:((e,t)=>{Object.defineProperty(t,`__esModule`,{value:!0})}),662:(function(e){(function(t,n){e.exports?e.exports=n():t.nearley=n()})(this,function(){function e(t,n,r){return this.id=++e.highestId,this.name=t,this.symbols=n,this.postprocess=r,this}e.highestId=0,e.prototype.toString=function(e){var t=e===void 0?this.symbols.map(s).join(` `):this.symbols.slice(0,e).map(s).join(` `)+` ● `+this.symbols.slice(e).map(s).join(` `);return this.name+` → `+t};function t(e,t,n,r){this.rule=e,this.dot=t,this.reference=n,this.data=[],this.wantedBy=r,this.isComplete=this.dot===e.symbols.length}t.prototype.toString=function(){return`{`+this.rule.toString(this.dot)+`}, from: `+(this.reference||0)},t.prototype.nextState=function(e){var n=new t(this.rule,this.dot+1,this.reference,this.wantedBy);return n.left=this,n.right=e,n.isComplete&&(n.data=n.build(),n.right=void 0),n},t.prototype.build=function(){var e=[],t=this;do e.push(t.right.data),t=t.left;while(t.left);return e.reverse(),e},t.prototype.finish=function(){this.rule.postprocess&&(this.data=this.rule.postprocess(this.data,this.reference,a.fail))};function n(e,t){this.grammar=e,this.index=t,this.states=[],this.wants={},this.scannable=[],this.completed={}}n.prototype.process=function(e){for(var t=this.states,n=this.wants,r=this.completed,i=0;i<t.length;i++){var o=t[i];if(o.isComplete){if(o.finish(),o.data!==a.fail){for(var s=o.wantedBy,c=s.length;c--;){var l=s[c];this.complete(l,o)}if(o.reference===this.index){var u=o.rule.name;(this.completed[u]=this.completed[u]||[]).push(o)}}}else{var u=o.rule.symbols[o.dot];if(typeof u!=`string`){this.scannable.push(o);continue}if(n[u]){if(n[u].push(o),r.hasOwnProperty(u))for(var d=r[u],c=0;c<d.length;c++){var f=d[c];this.complete(o,f)}}else n[u]=[o],this.predict(u)}}},n.prototype.predict=function(e){for(var n=this.grammar.byName[e]||[],r=0;r<n.length;r++){var i=n[r],a=this.wants[e],o=new t(i,0,this.index,a);this.states.push(o)}},n.prototype.complete=function(e,t){var n=e.nextState(t);this.states.push(n)};function r(e,t){this.rules=e,this.start=t||this.rules[0].name;var n=this.byName={};this.rules.forEach(function(e){n.hasOwnProperty(e.name)||(n[e.name]=[]),n[e.name].push(e)})}r.fromCompiled=function(t,n){var i=t.Lexer;t.ParserStart&&(n=t.ParserStart,t=t.ParserRules);var t=t.map(function(t){return new e(t.name,t.symbols,t.postprocess)}),a=new r(t,n);return a.lexer=i,a};function i(){this.reset(``)}i.prototype.reset=function(e,t){this.buffer=e,this.index=0,this.line=t?t.line:1,this.lastLineBreak=t?-t.col:0},i.prototype.next=function(){if(this.index<this.buffer.length){var e=this.buffer[this.index++];return e===`
46
46
  `&&(this.line+=1,this.lastLineBreak=this.index),{value:e}}},i.prototype.save=function(){return{line:this.line,col:this.index-this.lastLineBreak}},i.prototype.formatError=function(e,t){var n=this.buffer;if(typeof n==`string`){var r=n.split(`
@@ -64,8 +64,8 @@ Use (?: … ) instead`);if(!h.lineBreaks&&S.test(`
64
64
  ================================================================================
65
65
  `,t+=`MSG: ${i.name??``}\n`);for(let e of a)t+=`${e.type} ${e.name} = ${e.valueText??String(e.value)}\n`;if(o.length>0){t.length>0&&(t+=`
66
66
  `);for(let e of o){let n=e.upperBound==null?``:`<=${e.upperBound}`,i=e.arrayLength==null?e.arrayUpperBound==null?``:`<=${e.arrayUpperBound}`:String(e.arrayLength),a=e.isArray===!0?`[${i}]`:``,o=e.defaultValue==null?``:` ${r(e.defaultValue)}`;t+=`${e.type}${n}${a} ${e.name}${o}\n`}}}return t.trimEnd()}function r(e){return Array.isArray(e)?`[${e.map(e=>typeof e==`bigint`?e.toString():JSON.stringify(e)).join(`, `)}]`:typeof e==`bigint`?e.toString():JSON.stringify(e)}}),881:(function(e,t,n){var r=this&&this.__createBinding||(Object.create?(function(e,t,n,r){r===void 0&&(r=n);var i=Object.getOwnPropertyDescriptor(t,n);(!i||(`get`in i?!t.__esModule:i.writable||i.configurable))&&(i={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,i)}):(function(e,t,n,r){r===void 0&&(r=n),e[r]=t[n]})),i=this&&this.__exportStar||function(e,t){for(var n in e)n!==`default`&&!Object.prototype.hasOwnProperty.call(t,n)&&r(t,e,n)};Object.defineProperty(t,`__esModule`,{value:!0}),i(n(425),t),i(n(954),t),i(n(812),t)}),900:((e,t)=>{Object.defineProperty(t,`__esModule`,{value:!0}),t.isMsgDefFieldEqual=r,t.isMsgDefEqual=i;function n(e,t){if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}return e===t}function r(e,t){return e.type===t.type&&e.name===t.name&&(e.isComplex??!1)===(t.isComplex??!1)&&e.enumType===t.enumType&&(e.isArray??!1)===(t.isArray??!1)&&e.arrayLength===t.arrayLength&&(e.isConstant??!1)===(t.isConstant??!1)&&e.value===t.value&&e.valueText===t.valueText&&e.upperBound===t.upperBound&&e.arrayUpperBound===t.arrayUpperBound&&(e.deprecated??!1)===(t.deprecated??!1)&&n(e.defaultValue,t.defaultValue)}function i(e,t){return(e.name==null||t.name==null||e.name===t.name)&&e.definitions.length===t.definitions.length&&e.definitions.every((e,n)=>r(e,t.definitions[n]))}}),954:(function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,`__esModule`,{value:!0}),t.parse=l,t.fixupTypes=u,t.normalizeType=m;let i=n(155),a=n(662),o=n(91),s=r(n(666)),c=a.Grammar.fromCompiled(s.default);function l(e,t={}){let n=e.split(`
67
- `).map(e=>e.trim()).filter(e=>e),r=[],a=[];n.forEach(e=>{e.startsWith(`#`)||(e.startsWith(`==`)?(a.push(t.ros2===!0?(0,o.buildRos2Type)(r):d(r,c)),r=[]):r.push({line:e}))}),a.push(t.ros2===!0?(0,o.buildRos2Type)(r):d(r,c));let s=[],l=a.filter(e=>s.find(t=>(0,i.isMsgDefEqual)(e,t))?!1:s.push(e));return t.skipTypeFixup!==!0&&u(l),l}function u(e){e.forEach(({definitions:t,name:n})=>{t.forEach(t=>{if(t.isComplex===!0){let r=n?.split(`/`).slice(0,-1).join(`/`),i=p(e,t.type,r).name;if(i==null)throw Error(`Missing type definition for ${t.type}`);t.type=i}})})}function d(e,t){let n=[],r;return e.forEach(({line:e})=>{if(e.startsWith(`MSG:`)){let[t,n]=f(e);r=n?.trim();return}let i=new a.Parser(t);i.feed(e);let o=i.finish();if(o.length===0)throw Error(`Could not parse line: '${e}'`);if(o.length>1)throw Error(`Ambiguous line: '${e}'`);let s=o[0];s!=null&&(s.type=m(s.type),n.push(s))}),{name:r,definitions:n}}function f(e){return e.replace(/#.*/gi,``).split(` `).filter(e=>e)}function p(e,t,n){let r=e.filter(e=>{let r=e.name??``;return t.length===0?r.length===0:t.includes(`/`)?r===t:t===`Header`?r===`std_msgs/Header`:n?r===`${n}/${t}`:r.endsWith(`/${t}`)});if(r[0]==null)throw Error(`Expected 1 top level type definition for '${t}' but found ${r.length}`);if(r.length>1)throw Error(`Cannot unambiguously determine fully-qualified type name for '${t}'`);return r[0]}function m(e){return e===`char`?`uint8`:e===`byte`?`int8`:e}})},n={};function r(t){var i=n[t];if(i!==void 0)return i.exports;var a=n[t]={exports:{}};return e[t].call(a.exports,a,a.exports,r),a.exports}r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{typeof Symbol<`u`&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:`Module`}),Object.defineProperty(e,`__esModule`,{value:!0})},t.exports=r(881)})()})),Zf=e((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.EncapsulationKind=void 0;var t;(function(e){e[e.CDR_BE=0]=`CDR_BE`,e[e.CDR_LE=1]=`CDR_LE`,e[e.PL_CDR_BE=2]=`PL_CDR_BE`,e[e.PL_CDR_LE=3]=`PL_CDR_LE`,e[e.CDR2_BE=16]=`CDR2_BE`,e[e.CDR2_LE=17]=`CDR2_LE`,e[e.PL_CDR2_BE=18]=`PL_CDR2_BE`,e[e.PL_CDR2_LE=19]=`PL_CDR2_LE`,e[e.DELIMITED_CDR2_BE=20]=`DELIMITED_CDR2_BE`,e[e.DELIMITED_CDR2_LE=21]=`DELIMITED_CDR2_LE`,e[e.RTPS_CDR2_BE=6]=`RTPS_CDR2_BE`,e[e.RTPS_CDR2_LE=7]=`RTPS_CDR2_LE`,e[e.RTPS_DELIMITED_CDR2_BE=8]=`RTPS_DELIMITED_CDR2_BE`,e[e.RTPS_DELIMITED_CDR2_LE=9]=`RTPS_DELIMITED_CDR2_LE`,e[e.RTPS_PL_CDR2_BE=10]=`RTPS_PL_CDR2_BE`,e[e.RTPS_PL_CDR2_LE=11]=`RTPS_PL_CDR2_LE`})(t||(e.EncapsulationKind=t={}))})),Qf=e((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.getEncapsulationKindInfo=void 0;let t=Zf();e.getEncapsulationKindInfo=e=>{let n=e>t.EncapsulationKind.PL_CDR_LE,r=e===t.EncapsulationKind.CDR_LE||e===t.EncapsulationKind.PL_CDR_LE||e===t.EncapsulationKind.CDR2_LE||e===t.EncapsulationKind.PL_CDR2_LE||e===t.EncapsulationKind.DELIMITED_CDR2_LE||e===t.EncapsulationKind.RTPS_CDR2_LE||e===t.EncapsulationKind.RTPS_PL_CDR2_LE||e===t.EncapsulationKind.RTPS_DELIMITED_CDR2_LE,i=e===t.EncapsulationKind.DELIMITED_CDR2_BE||e===t.EncapsulationKind.DELIMITED_CDR2_LE||e===t.EncapsulationKind.RTPS_DELIMITED_CDR2_BE||e===t.EncapsulationKind.RTPS_DELIMITED_CDR2_LE,a=e===t.EncapsulationKind.PL_CDR2_BE||e===t.EncapsulationKind.PL_CDR2_LE||e===t.EncapsulationKind.RTPS_PL_CDR2_BE||e===t.EncapsulationKind.RTPS_PL_CDR2_LE,o=e===t.EncapsulationKind.PL_CDR_BE||e===t.EncapsulationKind.PL_CDR_LE;return{isCDR2:n,littleEndian:r,usesDelimiterHeader:i||a,usesMemberHeader:a||o}}})),$f=e((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.isBigEndian=r;let t=new Uint8Array(4),n=new Uint32Array(t.buffer);n[0]=1;function r(){return t[3]===1}})),ep=e((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.lengthCodeToObjectSizes=void 0,e.getLengthCodeForObjectSize=t;function t(e){let t;switch(e){case 1:t=0;break;case 2:t=1;break;case 4:t=2;break;case 8:t=3;break}if(t==null){if(e>4294967295)throw Error(`Object size ${e} for EMHEADER too large without specifying length code. Max size is 4294967295`);t=4}return t}e.lengthCodeToObjectSizes={0:1,1:2,2:4,3:8}})),tp=e((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.SENTINEL_PID=e.EXTENDED_PID=void 0,e.EXTENDED_PID=16129,e.SENTINEL_PID=16130})),np=e((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.CdrReader=void 0;let t=Qf(),n=$f(),r=ep(),i=tp(),a=new TextDecoder(`utf8`);e.CdrReader=class e{get kind(){return this.view.getUint8(1)}get decodedBytes(){return this.offset}get byteLength(){return this.view.byteLength}constructor(e){if(this.origin=0,e.byteLength<4)throw Error(`Invalid CDR data size ${e.byteLength}, must contain at least a 4-byte header`);this.view=new DataView(e.buffer,e.byteOffset,e.byteLength);let r=this.kind,{isCDR2:i,littleEndian:a,usesDelimiterHeader:o,usesMemberHeader:s}=(0,t.getEncapsulationKindInfo)(r);this.usesDelimiterHeader=o,this.usesMemberHeader=s,this.littleEndian=a,this.hostLittleEndian=!(0,n.isBigEndian)(),this.isCDR2=i,this.eightByteAlignment=i?4:8,this.origin=4,this.offset=4}int8(){let e=this.view.getInt8(this.offset);return this.offset+=1,e}uint8(){let e=this.view.getUint8(this.offset);return this.offset+=1,e}int16(){this.align(2);let e=this.view.getInt16(this.offset,this.littleEndian);return this.offset+=2,e}uint16(){this.align(2);let e=this.view.getUint16(this.offset,this.littleEndian);return this.offset+=2,e}int32(){this.align(4);let e=this.view.getInt32(this.offset,this.littleEndian);return this.offset+=4,e}uint32(){this.align(4);let e=this.view.getUint32(this.offset,this.littleEndian);return this.offset+=4,e}int64(){this.align(this.eightByteAlignment);let e=this.view.getBigInt64(this.offset,this.littleEndian);return this.offset+=8,e}uint64(){this.align(this.eightByteAlignment);let e=this.view.getBigUint64(this.offset,this.littleEndian);return this.offset+=8,e}uint16BE(){this.align(2);let e=this.view.getUint16(this.offset,!1);return this.offset+=2,e}uint32BE(){this.align(4);let e=this.view.getUint32(this.offset,!1);return this.offset+=4,e}uint64BE(){this.align(this.eightByteAlignment);let e=this.view.getBigUint64(this.offset,!1);return this.offset+=8,e}float32(){this.align(4);let e=this.view.getFloat32(this.offset,this.littleEndian);return this.offset+=4,e}float64(){this.align(this.eightByteAlignment);let e=this.view.getFloat64(this.offset,this.littleEndian);return this.offset+=8,e}string(e){let t=e??this.uint32();if(t<=1)return this.offset+=t,``;let n=new Uint8Array(this.view.buffer,this.view.byteOffset+this.offset,t-1),r=a.decode(n);return this.offset+=t,r}dHeader(){return this.uint32()}emHeader(){return this.isCDR2?this.memberHeaderV2():this.memberHeaderV1()}memberHeaderV1(){this.align(4);let e=this.uint16(),t=(e&16384)>>14==1,n=(e&32768)>>15==1,r=(e&16383)===i.EXTENDED_PID;if((e&16383)===i.SENTINEL_PID)return this.uint16(),{id:i.SENTINEL_PID,objectSize:0,mustUnderstand:!1,readSentinelHeader:!0};if((e&16383)>i.SENTINEL_PID||n)throw Error(`Unsupported parameter ID header ${e.toString(16)}`);r&&this.uint16();let a=r?this.uint32():e&16383,o=r?this.uint32():this.uint16();return this.resetOrigin(),{id:a,objectSize:o,mustUnderstand:t}}resetOrigin(){this.origin=this.offset}isPresentFlag(){if(!this.isCDR2)throw Error(`isPresentFlag is only supported for CDR2`);return!!this.uint8()}sentinelHeader(){return this.isCDR2?!1:(this.align(4),(this.uint16()&16383)===i.SENTINEL_PID?(this.uint16(),!0):!1)}memberHeaderV2(){let e=this.uint32(),t=Math.abs((e&2147483648)>>31)===1,n=(e&1879048192)>>28;return{mustUnderstand:t,id:e&268435455,objectSize:this.emHeaderObjectSize(n),lengthCode:n}}emHeaderObjectSize(e){switch(e){case 0:case 1:case 2:case 3:return r.lengthCodeToObjectSizes[e];case 4:case 5:return this.uint32();case 6:return 4*this.uint32();case 7:return 8*this.uint32();default:throw Error(`Invalid length code ${e} in EMHEADER at offset ${this.offset-4}`)}}sequenceLength(){return this.uint32()}int8Array(e=this.sequenceLength()){let t=new Int8Array(this.view.buffer,this.view.byteOffset+this.offset,e);return this.offset+=e,t}uint8Array(e=this.sequenceLength()){let t=new Uint8Array(this.view.buffer,this.view.byteOffset+this.offset,e);return this.offset+=e,t}int16Array(e=this.sequenceLength()){return this.typedArray(Int16Array,`getInt16`,e)}uint16Array(e=this.sequenceLength()){return this.typedArray(Uint16Array,`getUint16`,e)}int32Array(e=this.sequenceLength()){return this.typedArray(Int32Array,`getInt32`,e)}uint32Array(e=this.sequenceLength()){return this.typedArray(Uint32Array,`getUint32`,e)}int64Array(e=this.sequenceLength()){return this.typedArray(BigInt64Array,`getBigInt64`,e,this.eightByteAlignment)}uint64Array(e=this.sequenceLength()){return this.typedArray(BigUint64Array,`getBigUint64`,e,this.eightByteAlignment)}float32Array(e=this.sequenceLength()){return this.typedArray(Float32Array,`getFloat32`,e)}float64Array(e=this.sequenceLength()){return this.typedArray(Float64Array,`getFloat64`,e,this.eightByteAlignment)}stringArray(e=this.sequenceLength()){let t=[];for(let n=0;n<e;n++)t.push(this.string());return t}seek(e){let t=this.offset+e;if(t<4||t>this.view.byteLength)throw Error(`seek(${e}) failed, ${t} is outside the data range`);this.offset=t}seekTo(e){if(e<4||e>this.view.byteLength)throw Error(`seekTo(${e}) failed, value is outside the data range`);this.offset=e}clone(){let t=new e(this.view);return t.offset=this.offset,t.origin=this.origin,t}limit(e){let t=this.offset+e;if(t<=this.view.byteLength)this.view=new DataView(this.view.buffer,this.view.byteOffset,t);else throw RangeError(`length ${e} exceeds byte length of view`)}isAtEnd(){return this.offset>=this.view.byteLength}align(e){let t=(this.offset-this.origin)%e;t>0&&(this.offset+=e-t)}typedArray(e,t,n,r=e.BYTES_PER_ELEMENT){if(n===0)return new e;this.align(r);let i=this.view.byteOffset+this.offset;if(this.littleEndian!==this.hostLittleEndian)return this.typedArraySlow(e,t,n);if(i%e.BYTES_PER_ELEMENT===0){let t=new e(this.view.buffer,i,n);return this.offset+=e.BYTES_PER_ELEMENT*n,t}else return this.typedArrayUnaligned(e,t,n)}typedArrayUnaligned(e,t,n){if(n<10)return this.typedArraySlow(e,t,n);let r=e.BYTES_PER_ELEMENT*n,i=new Uint8Array(r);return i.set(new Uint8Array(this.view.buffer,this.view.byteOffset+this.offset,r)),this.offset+=r,new e(i.buffer,i.byteOffset,n)}typedArraySlow(e,t,n){let r=new e(n),i=this.offset;for(let a=0;a<n;a++)r[a]=this.view[t](i,this.littleEndian),i+=e.BYTES_PER_ELEMENT;return this.offset=i,r}}})),rp=e((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.CdrSizeCalculator=void 0,e.CdrSizeCalculator=class{constructor(){this.offset=4}get size(){return this.offset}int8(){return this.incrementAndReturn(1)}uint8(){return this.incrementAndReturn(1)}int16(){return this.incrementAndReturn(2)}uint16(){return this.incrementAndReturn(2)}int32(){return this.incrementAndReturn(4)}uint32(){return this.incrementAndReturn(4)}int64(){return this.incrementAndReturn(8)}uint64(){return this.incrementAndReturn(8)}float32(){return this.incrementAndReturn(4)}float64(){return this.incrementAndReturn(8)}string(e){return this.uint32(),this.offset+=e+1,this.offset}sequenceLength(){return this.uint32()}incrementAndReturn(e){let t=(this.offset-4)%e;return t>0&&(this.offset+=e-t),this.offset+=e,this.offset}}})),ip=e((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.CdrWriter=void 0;let t=Zf(),n=Qf(),r=$f(),i=ep(),a=tp(),o=new TextEncoder;function s(e){let t=0,n=e.length;for(let r=0;r<n;r++){let n=e.charCodeAt(r);if(n<=127)t+=1;else if(n<=2047)t+=2;else if(55296<=n&&n<=56319){let n=e.charCodeAt(r+1);56320<=n&&n<=57343?(t+=4,r++):t+=3}else t+=3}return t}var c=class e{get data(){return new Uint8Array(this.buffer,0,this.offset)}get size(){return this.offset}get kind(){return this.view.getUint8(1)}constructor(i={}){i.buffer==null?i.size==null?this.buffer=new ArrayBuffer(e.DEFAULT_CAPACITY):this.buffer=new ArrayBuffer(i.size):this.buffer=i.buffer;let a=i.kind??t.EncapsulationKind.CDR_LE,{isCDR2:o,littleEndian:s}=(0,n.getEncapsulationKindInfo)(a);this.isCDR2=o,this.littleEndian=s,this.hostLittleEndian=!(0,r.isBigEndian)(),this.eightByteAlignment=o?4:8,this.array=new Uint8Array(this.buffer),this.view=new DataView(this.buffer),this.resizeIfNeeded(4),this.view.setUint8(0,0),this.view.setUint8(1,a),this.view.setUint16(2,0,!1),this.offset=4,this.origin=4}int8(e){return this.resizeIfNeeded(1),this.view.setInt8(this.offset,e),this.offset+=1,this}uint8(e){return this.resizeIfNeeded(1),this.view.setUint8(this.offset,e),this.offset+=1,this}int16(e){return this.align(2),this.view.setInt16(this.offset,e,this.littleEndian),this.offset+=2,this}uint16(e){return this.align(2),this.view.setUint16(this.offset,e,this.littleEndian),this.offset+=2,this}int32(e){return this.align(4),this.view.setInt32(this.offset,e,this.littleEndian),this.offset+=4,this}uint32(e){return this.align(4),this.view.setUint32(this.offset,e,this.littleEndian),this.offset+=4,this}int64(e){return this.align(this.eightByteAlignment,8),this.view.setBigInt64(this.offset,e,this.littleEndian),this.offset+=8,this}uint64(e){return this.align(this.eightByteAlignment,8),this.view.setBigUint64(this.offset,e,this.littleEndian),this.offset+=8,this}uint16BE(e){return this.align(2),this.view.setUint16(this.offset,e,!1),this.offset+=2,this}uint32BE(e){return this.align(4),this.view.setUint32(this.offset,e,!1),this.offset+=4,this}uint64BE(e){return this.align(this.eightByteAlignment,8),this.view.setBigUint64(this.offset,e,!1),this.offset+=8,this}float32(e){return this.align(4),this.view.setFloat32(this.offset,e,this.littleEndian),this.offset+=4,this}float64(e){return this.align(this.eightByteAlignment,8),this.view.setFloat64(this.offset,e,this.littleEndian),this.offset+=8,this}string(e,t=!0){let n=s(e);return t&&this.uint32(n+1),this.resizeIfNeeded(n+1),o.encodeInto(e,new Uint8Array(this.buffer,this.offset,n)),this.view.setUint8(this.offset+n,0),this.offset+=n+1,this}dHeader(e){let t=e;return this.uint32(t),this}emHeader(e,t,n,r){return this.isCDR2?this.memberHeaderV2(e,t,n,r):this.memberHeaderV1(e,t,n)}memberHeaderV1(e,t,n){this.align(4);let r=e?16384:0;if(t>16128||n>65535){let e=r|a.EXTENDED_PID;this.uint16(e),this.uint16(8),this.uint32(t),this.uint32(n)}else{let e=r|t;this.uint16(e);let i=n&65535;this.uint16(i)}return this.resetOrigin(),this}resetOrigin(){this.origin=this.offset}presentFlag(e){if(!this.isCDR2)throw Error(`presentFlag is only supported for CDR2`);return this.uint8(+!!e),this}sentinelHeader(){return this.isCDR2||(this.align(4),this.uint16(a.SENTINEL_PID),this.uint16(0)),this}memberHeaderV2(e,t,n,r){if(t>268435455)throw Error(`Member ID ${t} is too large. Max value is 268435455`);let a=e?1<<31:0,o=r??(0,i.getLengthCodeForObjectSize)(n),s=a|o<<28|t;switch(this.uint32(s),o){case 0:case 1:case 2:case 3:{let e=i.lengthCodeToObjectSizes[o];if(n!==e)throw Error(`Cannot write a length code ${o} header with an object size not equal to ${e}`);break}case 4:case 5:this.uint32(n);break;case 6:if(n%4!=0)throw Error(`Cannot write a length code 6 header with an object size that is not a multiple of 4`);this.uint32(n>>2);break;case 7:if(n%8!=0)throw Error(`Cannot write a length code 7 header with an object size that is not a multiple of 8`);this.uint32(n>>3);break;default:throw Error(`Unexpected length code ${o}`)}return this}sequenceLength(e){return this.uint32(e)}int8Array(e,t){return t===!0&&this.sequenceLength(e.length),this.resizeIfNeeded(e.length),this.array.set(e,this.offset),this.offset+=e.length,this}uint8Array(e,t){return t===!0&&this.sequenceLength(e.length),this.resizeIfNeeded(e.length),this.array.set(e,this.offset),this.offset+=e.length,this}int16Array(t,n){if(n===!0&&this.sequenceLength(t.length),t instanceof Int16Array&&this.littleEndian===this.hostLittleEndian&&t.length>=e.BUFFER_COPY_THRESHOLD)this.align(t.BYTES_PER_ELEMENT,t.byteLength),this.array.set(new Uint8Array(t.buffer,t.byteOffset,t.byteLength),this.offset),this.offset+=t.byteLength;else for(let e of t)this.int16(e);return this}uint16Array(t,n){if(n===!0&&this.sequenceLength(t.length),t instanceof Uint16Array&&this.littleEndian===this.hostLittleEndian&&t.length>=e.BUFFER_COPY_THRESHOLD)this.align(t.BYTES_PER_ELEMENT,t.byteLength),this.array.set(new Uint8Array(t.buffer,t.byteOffset,t.byteLength),this.offset),this.offset+=t.byteLength;else for(let e of t)this.uint16(e);return this}int32Array(t,n){if(n===!0&&this.sequenceLength(t.length),t instanceof Int32Array&&this.littleEndian===this.hostLittleEndian&&t.length>=e.BUFFER_COPY_THRESHOLD)this.align(t.BYTES_PER_ELEMENT,t.byteLength),this.array.set(new Uint8Array(t.buffer,t.byteOffset,t.byteLength),this.offset),this.offset+=t.byteLength;else for(let e of t)this.int32(e);return this}uint32Array(t,n){if(n===!0&&this.sequenceLength(t.length),t instanceof Uint32Array&&this.littleEndian===this.hostLittleEndian&&t.length>=e.BUFFER_COPY_THRESHOLD)this.align(t.BYTES_PER_ELEMENT,t.byteLength),this.array.set(new Uint8Array(t.buffer,t.byteOffset,t.byteLength),this.offset),this.offset+=t.byteLength;else for(let e of t)this.uint32(e);return this}int64Array(t,n){if(n===!0&&this.sequenceLength(t.length),t instanceof BigInt64Array&&this.littleEndian===this.hostLittleEndian&&t.length>=e.BUFFER_COPY_THRESHOLD)this.align(t.BYTES_PER_ELEMENT,t.byteLength),this.array.set(new Uint8Array(t.buffer,t.byteOffset,t.byteLength),this.offset),this.offset+=t.byteLength;else for(let e of t)this.int64(BigInt(e));return this}uint64Array(t,n){if(n===!0&&this.sequenceLength(t.length),t instanceof BigUint64Array&&this.littleEndian===this.hostLittleEndian&&t.length>=e.BUFFER_COPY_THRESHOLD)this.align(t.BYTES_PER_ELEMENT,t.byteLength),this.array.set(new Uint8Array(t.buffer,t.byteOffset,t.byteLength),this.offset),this.offset+=t.byteLength;else for(let e of t)this.uint64(BigInt(e));return this}float32Array(t,n){if(n===!0&&this.sequenceLength(t.length),t instanceof Float32Array&&this.littleEndian===this.hostLittleEndian&&t.length>=e.BUFFER_COPY_THRESHOLD)this.align(t.BYTES_PER_ELEMENT,t.byteLength),this.array.set(new Uint8Array(t.buffer,t.byteOffset,t.byteLength),this.offset),this.offset+=t.byteLength;else for(let e of t)this.float32(e);return this}float64Array(t,n){if(n===!0&&this.sequenceLength(t.length),t instanceof Float64Array&&this.littleEndian===this.hostLittleEndian&&t.length>=e.BUFFER_COPY_THRESHOLD)this.align(t.BYTES_PER_ELEMENT,t.byteLength),this.array.set(new Uint8Array(t.buffer,t.byteOffset,t.byteLength),this.offset),this.offset+=t.byteLength;else for(let e of t)this.float64(e);return this}align(e,t=e){let n=(this.offset-this.origin)%e,r=n>0?e-n:0;this.resizeIfNeeded(r+t),this.array.fill(0,this.offset,this.offset+r),this.offset+=r}resizeIfNeeded(e){let t=this.offset+e;if(this.buffer.byteLength<t){let e=this.buffer.byteLength*2,n=e>t?e:t;this.resize(n)}}resize(e){if(this.buffer.byteLength>=e)return;let t=new ArrayBuffer(e),n=new Uint8Array(t);n.set(this.array),this.buffer=t,this.array=n,this.view=new DataView(t)}};e.CdrWriter=c,c.DEFAULT_CAPACITY=16,c.BUFFER_COPY_THRESHOLD=10})),ap=e((e=>{var t=e&&e.__createBinding||(Object.create?(function(e,t,n,r){r===void 0&&(r=n);var i=Object.getOwnPropertyDescriptor(t,n);(!i||(`get`in i?!t.__esModule:i.writable||i.configurable))&&(i={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,i)}):(function(e,t,n,r){r===void 0&&(r=n),e[r]=t[n]})),n=e&&e.__exportStar||function(e,n){for(var r in e)r!==`default`&&!Object.prototype.hasOwnProperty.call(n,r)&&t(n,e,r)};Object.defineProperty(e,`__esModule`,{value:!0}),n(np(),e),n(rp(),e),n(ip(),e),n(Zf(),e)})),op=e((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.messageDefinitionHasDataFields=t;function t(e){return e.some(e=>e.isConstant!==!0)}})),sp=e((e=>{var t=e&&e.__classPrivateFieldGet||function(e,t,n,r){if(n===`a`&&!r)throw TypeError(`Private accessor was defined without a getter`);if(typeof t==`function`?e!==t||!r:!t.has(e))throw TypeError(`Cannot read private member from an object whose class did not declare it`);return n===`m`?r:n===`a`?r.call(e):r?r.value:t.get(e)},n=e&&e.__classPrivateFieldSet||function(e,t,n,r,i){if(r===`m`)throw TypeError(`Private method is not writable`);if(r===`a`&&!i)throw TypeError(`Private accessor was defined without a setter`);if(typeof t==`function`?e!==t||!i:!t.has(e))throw TypeError(`Cannot write private member to an object whose class did not declare it`);return r===`a`?i.call(e,n):i?i.value=n:t.set(e,n),n},r,i,a,o,s,c,l;Object.defineProperty(e,`__esModule`,{value:!0}),e.MessageReader=void 0;let u=ap(),d=op();e.MessageReader=class{lastReadHadTrailingBytes(){return t(this,s,`f`)}lastReadByteLength(){return t(this,o,`f`)}constructor(e,t={}){r.add(this),i.set(this,void 0),a.set(this,void 0),o.set(this,0),s.set(this,!1),c.set(this,void 0);let{timeType:l=`sec,nanosec`}=t,u=e.find(e=>!f(e));if(u==null)throw Error(`MessageReader initialized with no root MessageDefinition`);n(this,i,u.definitions,`f`),n(this,a,new Map(e.map(e=>[e.name??``,e.definitions])),`f`),n(this,c,l===`sec,nsec`,`f`)}readMessage(e){let a=new u.CdrReader(e),c=t(this,r,`m`,l).call(this,t(this,i,`f`),a);return n(this,o,a.decodedBytes,`f`),n(this,s,t(this,o,`f`)<e.byteLength&&!p(e,t(this,o,`f`)),`f`),c}},i=new WeakMap,a=new WeakMap,o=new WeakMap,s=new WeakMap,c=new WeakMap,r=new WeakSet,l=function e(n,i){let o={};if(!(0,d.messageDefinitionHasDataFields)(n))return i.uint8(),o;for(let s of n)if(s.isConstant!==!0)if(s.isComplex===!0){let n=t(this,a,`f`).get(s.type);if(n==null)throw Error(`Unrecognized complex type ${s.type}`);if(s.isArray===!0){let a=s.arrayLength??i.sequenceLength(),c=[];for(let o=0;o<a;o++)c.push(t(this,r,`m`,e).call(this,n,i));o[s.name]=c}else o[s.name]=t(this,r,`m`,e).call(this,n,i)}else if(s.isArray===!0){let e=(t(this,c,`f`)?_:g).get(s.type);if(e==null)throw Error(`Unrecognized primitive array type ${s.type}[]`);let n=s.arrayLength??i.sequenceLength();o[s.name]=e(i,n)}else{let e=(t(this,c,`f`)?h:m).get(s.type);if(e==null)throw Error(`Unrecognized primitive type ${s.type}`);o[s.name]=e(i)}return o};function f(e){return e.definitions.length>0&&e.definitions.every(e=>e.isConstant)}function p(e,t){let n=e.byteLength-t;if(n<=0)return!1;let r=(4-t%4)%4,i=(8-t%8)%8;return n!==r&&n!==i?!1:new Uint8Array(e.buffer,e.byteOffset+t,n).every(e=>e===0)}let m=new Map([[`bool`,e=>!!e.int8()],[`int8`,e=>e.int8()],[`uint8`,e=>e.uint8()],[`int16`,e=>e.int16()],[`uint16`,e=>e.uint16()],[`int32`,e=>e.int32()],[`uint32`,e=>e.uint32()],[`int64`,e=>e.int64()],[`uint64`,e=>e.uint64()],[`float32`,e=>e.float32()],[`float64`,e=>e.float64()],[`string`,e=>e.string()],[`wstring`,S],[`time`,e=>({sec:e.int32(),nanosec:e.uint32()})],[`duration`,e=>({sec:e.int32(),nanosec:e.uint32()})]]),h=new Map([...m,[`time`,e=>({sec:e.int32(),nsec:e.uint32()})],[`duration`,e=>({sec:e.int32(),nsec:e.uint32()})]]),g=new Map([[`bool`,v],[`int8`,(e,t)=>e.int8Array(t)],[`uint8`,(e,t)=>e.uint8Array(t)],[`int16`,(e,t)=>e.int16Array(t)],[`uint16`,(e,t)=>e.uint16Array(t)],[`int32`,(e,t)=>e.int32Array(t)],[`uint32`,(e,t)=>e.uint32Array(t)],[`int64`,(e,t)=>e.int64Array(t)],[`uint64`,(e,t)=>e.uint64Array(t)],[`float32`,(e,t)=>e.float32Array(t)],[`float64`,(e,t)=>e.float64Array(t)],[`string`,y],[`wstring`,S],[`time`,x],[`duration`,x]]),_=new Map([...g,[`time`,b],[`duration`,b]]);function v(e,t){let n=Array(t);for(let r=0;r<t;r++)n[r]=!!e.int8();return n}function y(e,t){let n=Array(t);for(let r=0;r<t;r++)n[r]=e.string();return n}function b(e,t){let n=Array(t);for(let r=0;r<t;r++)n[r]={sec:e.int32(),nsec:e.uint32()};return n}function x(e,t){let n=Array(t);for(let r=0;r<t;r++)n[r]={sec:e.int32(),nanosec:e.uint32()};return n}function S(){throw Error(`wstring is implementation-defined and therefore not supported`)}})),cp=e((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.stringLengthUtf8=t;function t(e){let t=0,n=e.length;for(let r=0;r<n;r++){let n=e.charCodeAt(r);if(n<=127)t+=1;else if(n<=2047)t+=2;else if(55296<=n&&n<=56319){let n=e.charCodeAt(r+1);56320<=n&&n<=57343?(t+=4,r++):t+=3}else t+=3}return t}})),lp=e((e=>{var t=e&&e.__classPrivateFieldSet||function(e,t,n,r,i){if(r===`m`)throw TypeError(`Private method is not writable`);if(r===`a`&&!i)throw TypeError(`Private accessor was defined without a setter`);if(typeof t==`function`?e!==t||!i:!t.has(e))throw TypeError(`Cannot write private member to an object whose class did not declare it`);return r===`a`?i.call(e,n):i?i.value=n:t.set(e,n),n},n=e&&e.__classPrivateFieldGet||function(e,t,n,r){if(n===`a`&&!r)throw TypeError(`Private accessor was defined without a getter`);if(typeof t==`function`?e!==t||!r:!t.has(e))throw TypeError(`Cannot read private member from an object whose class did not declare it`);return n===`m`?r:n===`a`?r.call(e):r?r.value:t.get(e)},r,i,a,o,s,c,l,u,d;Object.defineProperty(e,`__esModule`,{value:!0}),e.MessageWriter=void 0;let f=ap(),p=op(),m=cp(),h=new Map([[`bool`,1],[`int8`,1],[`uint8`,1],[`int16`,2],[`uint16`,2],[`int32`,4],[`uint32`,4],[`int64`,8],[`uint64`,8],[`float32`,4],[`float64`,8],[`time`,8],[`duration`,8]]),g=new Map([[`bool`,x],[`int8`,S],[`uint8`,C],[`int16`,w],[`uint16`,T],[`int32`,E],[`uint32`,D],[`int64`,O],[`uint64`,k],[`float32`,A],[`float64`,j],[`string`,M],[`time`,N],[`duration`,N],[`wstring`,v]]),_=new Map([[`bool`,ee],[`int8`,P],[`uint8`,te],[`int16`,ne],[`uint16`,re],[`int32`,ie],[`uint32`,ae],[`int64`,oe],[`uint64`,se],[`float32`,ce],[`float64`,le],[`string`,ue],[`time`,de],[`duration`,de],[`wstring`,v]]);function v(){throw Error(`wstring is implementation-defined and therefore not supported`)}e.MessageWriter=class{constructor(e){r.add(this),i.set(this,void 0),a.set(this,void 0);let n=e.find(e=>!y(e));if(n==null)throw Error(`MessageReader initialized with no root MessageDefinition`);t(this,i,n.definitions,`f`),t(this,a,new Map(e.map(e=>[e.name??``,e.definitions])),`f`)}calculateByteSize(e){return n(this,r,`m`,o).call(this,n(this,i,`f`),e,4)}writeMessage(e,t){let a=new f.CdrWriter({buffer:t,size:t?void 0:this.calculateByteSize(e)});return n(this,r,`m`,s).call(this,n(this,i,`f`),e,a),a.data}},i=new WeakMap,a=new WeakMap,r=new WeakSet,o=function e(t,i,a){let o=i,s=a;if(!(0,p.messageDefinitionHasDataFields)(t))return a+n(this,r,`m`,l).call(this,`uint8`);for(let i of t){if(i.isConstant===!0)continue;let t=o?.[i.name];if(i.isArray===!0){let a=i.arrayLength??b(t),o=Array.isArray(t)||ArrayBuffer.isView(t)?t:[];if(i.arrayLength??(s+=fe(s,4),s+=4),i.isComplex===!0){let t=n(this,r,`m`,c).call(this,i.type);for(let i=0;i<a;i++){let a=o[i]??{};s=n(this,r,`m`,e).call(this,t,a,s)}}else if(i.type===`string`)for(let e=0;e<a;e++){let t=o[e]??``;s+=fe(s,4),s+=4+(0,m.stringLengthUtf8)(t)+1}else{let e=n(this,r,`m`,l).call(this,i.type),t=i.type===`time`||i.type===`duration`?4:e;s+=fe(s,t),s+=e*a}}else if(i.isComplex===!0){let a=n(this,r,`m`,c).call(this,i.type),o=t??{};s=n(this,r,`m`,e).call(this,a,o,s)}else if(i.type===`string`){let e=typeof t==`string`?t:``;s+=fe(s,4),s+=4+(0,m.stringLengthUtf8)(e)+1}else{let e=n(this,r,`m`,l).call(this,i.type),t=i.type===`time`||i.type===`duration`?4:e;s+=fe(s,t),s+=e}}return s},s=function e(t,i,a){let o=i;if(!(0,p.messageDefinitionHasDataFields)(t)){C(0,0,a);return}for(let i of t){if(i.isConstant===!0)continue;let t=o?.[i.name];if(i.isArray===!0){let o=i.arrayLength??b(t),s=Array.isArray(t)||ArrayBuffer.isView(t)?t:[];if(i.arrayLength??a.sequenceLength(o),i.arrayLength!=null&&t!=null){let e=b(t);if(e!==i.arrayLength)throw Error(`Expected ${i.arrayLength} items for fixed-length array field ${i.name} but received ${e}`)}if(i.isComplex===!0){let t=n(this,r,`m`,c).call(this,i.type);for(let i=0;i<o;i++){let o=s[i]??{};n(this,r,`m`,e).call(this,t,o,a)}}else n(this,r,`m`,d).call(this,i.type)(t,i.defaultValue,a,i.arrayLength)}else if(i.isComplex===!0){let o=n(this,r,`m`,c).call(this,i.type),s=t??{};n(this,r,`m`,e).call(this,o,s,a)}else n(this,r,`m`,u).call(this,i.type)(t,i.defaultValue,a)}},c=function(e){let t=n(this,a,`f`).get(e);if(t==null)throw Error(`Unrecognized complex type ${e}`);return t},l=function(e){let t=h.get(e);if(t==null)throw e===`wstring`&&v(),Error(`Unrecognized primitive type ${e}`);return t},u=function(e){let t=g.get(e);if(t==null)throw Error(`Unrecognized primitive type ${e}`);return t},d=function(e){let t=_.get(e);if(t==null)throw Error(`Unrecognized primitive type ${e}[]`);return t};function y(e){return e.definitions.length>0&&e.definitions.every(e=>e.isConstant)}function b(e){let t=e?.length;return typeof t==`number`?t:0}function x(e,t,n){let r=typeof e==`boolean`?e:t??!1;n.int8(+!!r)}function S(e,t,n){n.int8(typeof e==`number`?e:t??0)}function C(e,t,n){n.uint8(typeof e==`number`?e:t??0)}function w(e,t,n){n.int16(typeof e==`number`?e:t??0)}function T(e,t,n){n.uint16(typeof e==`number`?e:t??0)}function E(e,t,n){n.int32(typeof e==`number`?e:t??0)}function D(e,t,n){n.uint32(typeof e==`number`?e:t??0)}function O(e,t,n){typeof e==`bigint`?n.int64(e):typeof e==`number`?n.int64(BigInt(e)):n.int64(t??0n)}function k(e,t,n){typeof e==`bigint`?n.uint64(e):typeof e==`number`?n.uint64(BigInt(e)):n.uint64(t??0n)}function A(e,t,n){n.float32(typeof e==`number`?e:t??0)}function j(e,t,n){n.float64(typeof e==`number`?e:t??0)}function M(e,t,n){n.string(typeof e==`string`?e:t??``)}function N(e,t,n){if(e==null){n.int32(0),n.uint32(0);return}let r=e;n.int32(r.sec??0),n.uint32(r.nsec??r.nanosec??0)}function ee(e,t,n,r){if(Array.isArray(e)){let t=new Int8Array(e);n.int8Array(t)}else n.int8Array(t??new Int8Array(r??0).fill(0))}function P(e,t,n,r){if(e instanceof Int8Array)n.int8Array(e);else if(Array.isArray(e)){let t=new Int8Array(e);n.int8Array(t)}else n.int8Array(t??new Int8Array(r??0).fill(0))}function te(e,t,n,r){if(e instanceof Uint8Array)n.uint8Array(e);else if(e instanceof Uint8ClampedArray)n.uint8Array(new Uint8Array(e));else if(Array.isArray(e)){let t=new Uint8Array(e);n.uint8Array(t)}else n.uint8Array(t??new Uint8Array(r??0).fill(0))}function ne(e,t,n,r){if(e instanceof Int16Array)n.int16Array(e);else if(Array.isArray(e)){let t=new Int16Array(e);n.int16Array(t)}else n.int16Array(t??new Int16Array(r??0).fill(0))}function re(e,t,n,r){if(e instanceof Uint16Array)n.uint16Array(e);else if(Array.isArray(e)){let t=new Uint16Array(e);n.uint16Array(t)}else n.uint16Array(t??new Uint16Array(r??0).fill(0))}function ie(e,t,n,r){if(e instanceof Int32Array)n.int32Array(e);else if(Array.isArray(e)){let t=new Int32Array(e);n.int32Array(t)}else n.int32Array(t??new Int32Array(r??0).fill(0))}function ae(e,t,n,r){if(e instanceof Uint32Array)n.uint32Array(e);else if(Array.isArray(e)){let t=new Uint32Array(e);n.uint32Array(t)}else n.uint32Array(t??new Uint32Array(r??0).fill(0))}function oe(e,t,n,r){if(e instanceof BigInt64Array)n.int64Array(e);else if(Array.isArray(e)){let t=new BigInt64Array(e);n.int64Array(t)}else n.int64Array(t??new BigInt64Array(r??0).fill(0n))}function se(e,t,n,r){if(e instanceof BigUint64Array)n.uint64Array(e);else if(Array.isArray(e)){let t=new BigUint64Array(e);n.uint64Array(t)}else n.uint64Array(t??new BigUint64Array(r??0).fill(0n))}function ce(e,t,n,r){if(e instanceof Float32Array)n.float32Array(e);else if(Array.isArray(e)){let t=new Float32Array(e);n.float32Array(t)}else n.float32Array(t??new Float32Array(r??0).fill(0))}function le(e,t,n,r){if(e instanceof Float64Array)n.float64Array(e);else if(Array.isArray(e)){let t=new Float64Array(e);n.float64Array(t)}else n.float64Array(t??new Float64Array(r??0).fill(0))}function ue(e,t,n,r){if(Array.isArray(e))for(let t of e)n.string(typeof t==`string`?t:``);else{let e=t??Array(r??0).fill(``);for(let t of e)n.string(t)}}function de(e,t,n,r){if(Array.isArray(e))for(let t of e)N(t,void 0,n);else{let e=Array(r).fill(void 0);for(let t of e)N(t,void 0,n)}}function fe(e,t){let n=(e-4)%t;return n>0?t-n:0}})),up=e((e=>{var t=e&&e.__createBinding||(Object.create?(function(e,t,n,r){r===void 0&&(r=n);var i=Object.getOwnPropertyDescriptor(t,n);(!i||(`get`in i?!t.__esModule:i.writable||i.configurable))&&(i={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,i)}):(function(e,t,n,r){r===void 0&&(r=n),e[r]=t[n]})),n=e&&e.__exportStar||function(e,n){for(var r in e)r!==`default`&&!Object.prototype.hasOwnProperty.call(n,r)&&t(n,e,r)};Object.defineProperty(e,`__esModule`,{value:!0}),n(sp(),e),n(lp(),e)})),dp=Xf(),fp=up();const pp=`damaged protobuf data`,mp=4294967296,hp={double:1,float:2,group:10,message:11,bytes:12,enum:14,string:9,bool:8},gp=e=>e===1||e===6||e===16?1:e===2||e===7||e===15?5:e===9||e===11||e===12?2:e===10?3:0;function _p(e,t,n,r){let i=0,a=0;for(let r=0;;r++){if(t>=n||r===10)throw Error(pp);let o=e[t++],s=o&127;if(r<4?i|=s<<7*r:r===4?(i|=s<<28,a|=s>>4):a|=s<<7*r-32,!(o&128))break}return r.lo=i,r.hi=a,t}function vp(e,t,n,r,i=!1){let a={lo:0,hi:0,p:0,s:0,e:0};for(;t<n;){t=_p(e,t,n,a);let o=a.lo>>>3,s=a.lo&7;if(s===0)t=_p(e,t,n,a);else if(s===1||s===5){if(a.p=t,(t+=s===1?8:4)>n)throw Error(pp)}else if(s===2){if(t=_p(e,t,n,a),a.s=t,a.e=t+(a.lo>>>0),a.hi||a.e>n)throw Error(pp);t=a.e}else if(s===3){t=vp(e,t,n,()=>{},!0);continue}else if(s===4&&i)return t;else throw Error(pp);r(o,s,a)}if(i)throw Error(pp);return t}const yp=(e,t)=>d(e.subarray(t.s,t.e));function bp(e){let t=new Map,n=new Map,r=(t,r,i)=>{let a=``,o=new Map;vp(e,t,r,(t,n,r)=>{if(t===1)a=yp(e,r);else if(t===2){let t=``,n=0;vp(e,r.s,r.e,(r,i,a)=>{r===1?t=yp(e,a):r===2&&(n=a.lo|0)}),o.has(n)||o.set(n,t)}}),n.set(i?`${i}.${a}`:a,o)},i=(n,a,o,s)=>{if(s>64)throw Error(pp);let c=``;vp(e,n,a,(t,n,r)=>{t===1&&(c=yp(e,r))});let l=o?`${o}.${c}`:c,u=[];vp(e,n,a,(t,n,a)=>{if(t===2){let t={name:``,number:0,type:0,repeated:!1,oneof:!1,typeName:``,scope:l};vp(e,a.s,a.e,(n,r,i)=>{n===1?t.name=yp(e,i):n===3?t.number=i.lo|0:n===4?t.repeated=i.lo===3:n===5?t.type=i.lo:n===6?t.typeName=yp(e,i):n===9&&(t.oneof=!0)}),u.push(t)}else t===3?i(a.s,a.e,l,s+1):t===4&&r(a.s,a.e,l)}),t.set(l,{list:u,fields:new Map(u.map(e=>[e.number,e]))})};vp(e,0,e.length,(t,n,a)=>{if(t!==1)return;let o=``;vp(e,a.s,a.e,(t,n,r)=>{t===2&&(o=yp(e,r))}),vp(e,a.s,a.e,(e,t,n)=>{e===4?i(n.s,n.e,o,0):e===5&&r(n.s,n.e,o)})});for(let e of t.values())for(let r of e.list)if(r.typeName){if(r.typeName.startsWith(`.`)){r.typeName=r.typeName.slice(1);continue}for(let e=r.scope;;e=e.slice(0,Math.max(0,e.lastIndexOf(`.`)))){let i=e?`${e}.${r.typeName}`:r.typeName;if(t.has(i)||n.has(i)){r.typeName=i;break}if(!e)break}}return{messages:t,enums:n}}function xp(e,t){let n=bp(e),r=n.messages.get(t);if(!r)throw Error(`no type ${t}`);return e=>wp(n,r,e,i(e),0,e.length,0)}const Sp=(e,t,n)=>e.enums.get(t.typeName)?.get(n)??n;function Cp(e,t){switch(t.type){case hp.string:return``;case hp.bytes:return new Uint8Array;case hp.bool:return!1;case hp.enum:{let n=e.enums.get(t.typeName);return n?n.get(0)??n.values().next().value??0:0}default:return 0}}function wp(e,t,n,r,i,a,o){if(o>64)throw Error(pp);let s={};for(let n of t.list)n.repeated?s[n.name]=[]:!n.oneof&&n.type!==hp.message&&n.type!==hp.group&&(s[n.name]=Cp(e,n));let c=(t,i)=>{let{lo:a,hi:s,p:c}=i;switch(t.type){case 1:return r.getFloat64(c,!0);case 2:return r.getFloat32(c,!0);case 3:return(s|0)*mp+(a>>>0);case 4:return(s>>>0)*mp+(a>>>0);case 5:return a|0;case 6:return r.getUint32(c+4,!0)*mp+r.getUint32(c,!0);case 7:return r.getUint32(c,!0);case 8:return a!==0||s!==0;case 9:return yp(n,i);case 11:{let a=e.messages.get(t.typeName);return a?wp(e,a,n,r,i.s,i.e,o+1):void 0}case 12:return n.subarray(i.s,i.e);case 13:return a>>>0;case 14:return Sp(e,t,a|0);case 15:return r.getInt32(c,!0);case 16:return r.getInt32(c+4,!0)*mp+r.getUint32(c,!0);case 17:return a>>>1^-(a&1);case 18:{let e=-(a&1);return(s>>>1^e|0)*mp+(((a>>>1|s<<31)^e)>>>0)}default:return}};return vp(n,i,a,(e,r,i)=>{let a=t.fields.get(e);if(!a)return;let o=gp(a.type);if(a.repeated&&r===2&&o!==2){let e=s[a.name],t={lo:0,hi:0,p:0,s:0,e:0};for(let r=i.s;r<i.e;){if(o===0)r=_p(n,r,i.e,t);else if(t.p=r,(r+=o===1?8:4)>i.e)throw Error(pp);e.push(c(a,t))}return}if(r!==o)throw Error(pp);let l=c(a,i);a.repeated?s[a.name].push(l):s[a.name]=l}),s}const Tp=/(^|[/.])(Image|CompressedImage|RawImage|CompressedVideo|PointCloud|PointCloud2)$/;function Ep(e){if(Tp.test(e.schemaName))return`no numbers (images and point clouds are skipped).`;if(e.messageEncoding===`cdr`&&e.schemaEncoding===`ros2msg`){let t=new fp.MessageReader((0,dp.parse)(d(e.schemaData),{ros2:!0}));return e=>t.readMessage(e)}return e.messageEncoding===`protobuf`&&e.schemaEncoding===`protobuf`?xp(e.schemaData,e.schemaName):e.messageEncoding===`json`&&(e.schemaEncoding===`jsonschema`||e.schemaEncoding===``)?e=>JSON.parse(d(e)):`message encoding ${e.messageEncoding}${e.schemaEncoding?` (schema ${e.schemaEncoding})`:``} is not supported; skipped.`}function Dp(e,t,n,r){switch(typeof e){case`number`:n.set(t,e);return;case`bigint`:n.set(t,Number(e));return;case`boolean`:n.set(t,+!!e);return;case`string`:n.set(t,e);return;case`object`:break;default:return}if(e!==null){if(Array.isArray(e)||ArrayBuffer.isView(e)&&!(e instanceof DataView)){let i=e;if(i.length>16){r.add(`${t} (over 16 values)`);return}for(let e=0;e<i.length;e++){let n=i[e];if(n!==null&&typeof n!=`number`&&typeof n!=`bigint`&&typeof n!=`boolean`){r.add(`${t} (arrays of messages or text)`);return}}for(let e=0;e<i.length;e++)n.set(`${t}[${e}]`,i[e]===null?NaN:Number(i[e]));return}for(let[i,a]of Object.entries(e))Dp(a,t?`${t}.${i}`:i,n,r)}}const Op=e=>Array.isArray(e)||ArrayBuffer.isView(e)&&!(e instanceof DataView);function kp(e,t,n,r=``,i=[]){if(typeof e!=`object`||!e){t.has(r)&&n.set(r,i);return}if(Op(e)){for(let a=0;a<Math.min(e.length,16);a++)t.has(`${r}[${a}]`)&&n.set(`${r}[${a}]`,[...i,a]);return}for(let a of Object.keys(e))kp(e[a],t,n,r?`${r}.${a}`:a,[...i,a])}function Ap(e,t){let n=e;for(let e of t){if(typeof n!=`object`||!n)return;if(typeof e==`number`){if(!Op(n)||n.length>16)return;for(let e=0;e<n.length;e++){let t=n[e];if(t!==null&&typeof t!=`number`&&typeof t!=`bigint`&&typeof t!=`boolean`)return}let t=n[e];return t===null?NaN:t===void 0?void 0:Number(t)}if(Op(n))return;n=n[e]}switch(typeof n){case`number`:case`string`:return n;case`bigint`:return Number(n);case`boolean`:return+!!n;default:return}}const jp={id:`mcap`,label:`MCAP`,extensions:[`.mcap`],sniff:e=>f(e,`‰MCAP0\r
68
- `)},Mp=`damaged LZ4 data`;function Np(e,t){let n=new Uint8Array(t),r=0,i=0,a=()=>{if(r+4>e.length)throw Error(Mp);let t=(e[r]|e[r+1]<<8|e[r+2]<<16|e[r+3]<<24)>>>0;return r+=4,t};for(;r<e.length;){let o=a();if((o&4294967280)==407710288){r+=a();continue}if(o!==407708164||r+3>e.length)throw Error(Mp);let s=e[r];if(s>>6!=1)throw Error(Mp);for(r+=3+(s&8?8:0)+(s&1?4:0);;){let o=a();if(o===0)break;let c=o&2147483647;if(r+c>e.length)throw Error(Mp);if(o&2147483648){if(i+c>t)throw Error(Mp);n.set(e.subarray(r,r+c),i),i+=c}else i=Pp(e,r,r+c,n,i);r+=c+(s&16?4:0)}s&4&&(r+=4)}if(r>e.length||i!==t)throw Error(Mp);return n}function Pp(e,t,n,r,i){let a=r=>{if(r!==15)return r;for(let i=255;i===255;r+=i){if(t>=n)throw Error(Mp);i=e[t++]}return r};for(;t<n;){let o=e[t++],s=a(o>>4);if(t+s>n||i+s>r.length)throw Error(Mp);if(r.set(e.subarray(t,t+s),i),t+=s,i+=s,t===n)return i;if(t+2>n)throw Error(Mp);let c=e[t]|e[t+1]<<8;t+=2;let l=a(o&15)+4;if(c===0||c>i||i+l>r.length)throw Error(Mp);if(c>=l)r.copyWithin(i,i-c,i-c+l);else for(let e=0;e<l;e++)r[i+e]=r[i+e-c];i+=l}throw Error(Mp)}const Fp=`This MCAP file is damaged (its records could not be read).`,Ip=e=>e instanceof Error&&e.name===`AbortError`?e:Error(Fp),Lp=e=>{if(e>BigInt(1073741824))throw Error(Fp);return Number(e)},Rp={zstd:(e,t)=>Yf(e,new Uint8Array(Lp(t))),lz4:(e,t)=>Np(e,Lp(t))};async function zp(e){let t;try{t=await yf.Initialize({readable:{size:async()=>BigInt(e.size),read:async(t,n)=>e.slice(Number(t),Number(n))},decompressHandlers:Rp})}catch{return null}return(t.chunkIndexes.length>0||t.statistics?.messageCount===0n)&&t.chunkIndexes.every(e=>e.messageIndexOffsets.size>0)?t:null}async function*Bp(e,t){let n=new xf({decompressHandlers:Rp});try{for await(let r of e.windows(0,e.size)){t?.throwIfAborted(),n.append(r.bytes);for(let e;e=n.nextRecord();)yield e}}catch(e){throw Ip(e)}}async function*Vp(e){try{for await(let t of e)yield t}catch(e){throw Ip(e)}}const Hp=(e,t)=>({messageEncoding:e.messageEncoding,schemaName:t?.name??``,schemaEncoding:t?.encoding??``,schemaData:t?.data??new Uint8Array});var Up=class{seen=new Map;skipped=new Set;n=0;count=0;first=null;last=null;unsorted=!1;decoder=null;id;topic;info;constructor(e,t,n){this.id=e,this.topic=t,this.info=n}add(e){if(this.count++,(this.first===null||e.logTime<this.first)&&(this.first=e.logTime),this.last!==null&&e.logTime<this.last?this.unsorted=!0:this.last=e.logTime,this.n>=100)return;if(this.n++,this.decoder===null)try{this.decoder=Ep(this.info)}catch{this.decoder=`its schema could not be read; skipped.`}if(typeof this.decoder==`string`)return;let t=new Map;try{Dp(this.decoder(e.data),``,t,this.skipped)}catch{return}for(let[e,n]of t)this.seen.has(e)||this.seen.set(e,typeof n==`string`)}};const Wp=946684800n*1000000000n,Gp=8192;async function*Kp(e,t){let n=e.plan.state,r=e=>{e.cap=e.t.samples<0?Gp:Math.max(1,Math.min(Gp,e.t.samples-e.start)),e.time=new Float64Array(e.cap),e.cols=e.sel.map(t=>e.t.text[t]?Array(e.cap).fill(null):new Float64Array(e.cap))},i=new Map;for(let t of e.selection){let a=n.topics[t.group],o=p(e,t.group),s={g:t.group,t:a,sel:o,text:o.map(e=>a.text[e]),decode:Ep(a.info),at:o.map(()=>void 0),want:new Set(o.map(e=>a.paths[e])),time:new Float64Array,cols:[],n:0,cap:0,start:0};r(s),i.set(a.id,s)}let a=e=>{let t=e.n===e.cap,n={group:e.g,time:t?e.time:e.time.slice(0,e.n),start:e.start,length:e.n,columns:e.cols.map(n=>t?n:n.slice(0,e.n))};return e.start+=e.n,e.n=0,r(e),n},o=0;for await(let r of t){if(++o&1023||e.signal?.throwIfAborted(),o%65536==0)for(let e of i.values())e.n&&(yield a(e));let t=i.get(r.channelId);if(!t)continue;let s;try{s=t.decode(r.data)}catch{s=void 0}if(t.want.size&&s!==void 0){let e=new Map;kp(s,t.want,e),t.sel.forEach((n,r)=>{t.at[r]??=e.get(t.t.paths[n])});for(let n of e.keys())t.want.delete(n)}t.time[t.n]=Number(r.logTime-n.t0)/1e9;for(let e=0;e<t.sel.length;e++){let n=t.at[e],r=n&&s!==void 0?Ap(s,n):void 0;t.text[e]?t.cols[e][t.n]=r===void 0?null:String(r):t.cols[e][t.n]=typeof r==`number`?r:NaN}++t.n===t.cap&&(yield a(t))}for(let e of i.values())e.n&&(yield a(e))}async function*qp(e,t,n){let r=[];for await(let i of Bp(e,n))i.type===`Message`&&(t.has(i.channelId)?r.push({...i,data:i.data.slice()}):yield i);yield*r.sort((e,t)=>e.logTime<t.logTime?-1:+(e.logTime>t.logTime))}const Jp={...jp,async plan(e,t){let n=await zp(t),r=[],i,a=new Map;if(n){i=n.header;for(let[e,t]of n.statistics?.channelMessageCounts??[])a.set(e,Number(t));for(let e of[...n.channelsById.values()].sort((e,t)=>e.id-t.id)){let t=new Up(e.id,e.topic,Hp(e,n.schemasById.get(e.schemaId)));r.push(t);for await(let r of Vp(n.readMessages({topics:[e.topic]})))if(r.channelId===e.id&&(t.add(r),t.n>=100))break}}else{let e=new Map,n=new Map;for await(let a of Bp(t))if(a.type===`Header`)i=a;else if(a.type===`Schema`)e.set(a.id,a);else if(a.type===`Channel`&&!n.has(a.id)){let t=new Up(a.id,a.topic,Hp(a,e.get(a.schemaId)));n.set(a.id,t),r.push(t)}else a.type===`Message`&&n.get(a.channelId)?.add(a);for(let e of r)a.set(e.id,e.count);r.sort((e,t)=>e.id-t.id)}let o=[],s=[],c=null;for(let e of r){e.first!==null&&(c===null||e.first<c)&&(c=e.first);let t=[...e.skipped],n=typeof e.decoder==`string`?e.decoder:e.n===0?`no messages; skipped.`:e.seen.size===0?`no numbers${t.length?` (skipped ${t.slice(0,5).join(`, `)})`:``}.`:null;if(n){o.push(`${e.topic}: ${n}`);continue}t.length&&o.push(`${e.topic}: skipped ${t.slice(0,5).join(`, `)}${t.length>5?`, …`:``}.`),s.push({id:e.id,topic:e.topic,info:e.info,paths:[...e.seen.keys()],text:[...e.seen.values()],samples:a.get(e.id)??-1,unsorted:e.unsorted})}let l=cn(s.map(e=>e.topic),[]),u=s.map((e,t)=>{let n=cn(e.paths);return{name:l[t],channels:n.map((t,n)=>({name:t,unit:``,...e.text[n]?{text:!0}:{}})),samples:e.samples,time:{kind:`timestamps`},rateHz:null,irregular:!0}}),d=i?.profile??``;return{format:d?`MCAP (${d})`:`MCAP`,startTime:c!==null&&c>=Wp?new Date(Number(c/1000000n)).toISOString():null,groups:u,meta:i?{profile:d,library:i.library}:{},events:[],notes:o,interleaved:!n,state:{indexed:!!n,topics:s,t0:c??0n}}},async*stream(e){let t=e.plan.state,n=t.indexed?await zp(e.io):null;if(t.indexed&&!n)throw Error(Fp);let r=[...new Set(e.selection.map(e=>t.topics[e.group].topic))],i=new Set(e.selection.map(e=>t.topics[e.group]).filter(e=>e.unsorted).map(e=>e.id));yield*Kp(e,n?Vp(n.readMessages({topics:r})):qp(e.io,i,e.signal))},async*streamGroup(e,t){let n=await zp(e.io);if(!n)throw Error(Fp);yield*Kp(e,Vp(n.readMessages({topics:[e.plan.state.topics[t].topic]})))}},Yp=[64,20,17,74,159,228,207,17,153,0,80,81,68,73,70,0],Xp={id:`pqdif`,label:`PQDIF (IEEE 1159.3)`,extensions:[`.pqd`],sniff:e=>e.length>=64&&Yp.every((t,n)=>e[n]===t)},Zp={container:`89738606-f1c3-11cf-9d89-0080c72e70a3`,dataSource:`89738619-f1c3-11cf-9d89-0080c72e70a3`,monitorSettings:`b48d858c-f5f5-11cf-9d89-0080c72e70a3`,observation:`8973861a-f1c3-11cf-9d89-0080c72e70a3`},Y={title:`8973860d-f1c3-11cf-9d89-0080c72e70a3`,compressionStyle:`8973861b-f1c3-11cf-9d89-0080c72e70a3`,compressionAlgorithm:`8973861c-f1c3-11cf-9d89-0080c72e70a3`,dataSourceName:`b48d8587-f5f5-11cf-9d89-0080c72e70a3`,channelDefinitions:`b48d858d-f5f5-11cf-9d89-0080c72e70a3`,oneChannelDefinition:`b48d858e-f5f5-11cf-9d89-0080c72e70a3`,channelDefinitionIndex:`b48d858f-f5f5-11cf-9d89-0080c72e70a3`,channelName:`b48d8590-f5f5-11cf-9d89-0080c72e70a3`,phaseId:`b48d8591-f5f5-11cf-9d89-0080c72e70a3`,quantityTypeId:`b48d8592-f5f5-11cf-9d89-0080c72e70a3`,quantityMeasuredId:`c690e872-f755-11cf-9d89-0080c72e70a3`,seriesDefinitions:`b48d8598-f5f5-11cf-9d89-0080c72e70a3`,oneSeriesDefinition:`b48d859a-f5f5-11cf-9d89-0080c72e70a3`,valueTypeId:`b48d859c-f5f5-11cf-9d89-0080c72e70a3`,quantityUnitsId:`b48d859b-f5f5-11cf-9d89-0080c72e70a3`,quantityCharacteristicId:`3d786f9e-f76e-11cf-9d89-0080c72e70a3`,storageMethodId:`b48d85a1-f5f5-11cf-9d89-0080c72e70a3`,valueTypeName:`b48d859d-f5f5-11cf-9d89-0080c72e70a3`,useTransducer:`62f28181-f9c4-11cf-9d89-0080c72e70a3`,channelSettingsArray:`62f28182-f9c4-11cf-9d89-0080c72e70a3`,oneChannelSetting:`3d786f9a-f76e-11cf-9d89-0080c72e70a3`,xdSystemSideRatio:`62f2818a-f9c4-11cf-9d89-0080c72e70a3`,xdMonitorSideRatio:`62f2818b-f9c4-11cf-9d89-0080c72e70a3`,observationName:`3d786f8a-f76e-11cf-9d89-0080c72e70a3`,timeStart:`3d786f8c-f76e-11cf-9d89-0080c72e70a3`,timeTriggered:`3d786f8e-f76e-11cf-9d89-0080c72e70a3`,channelInstances:`3d786f91-f76e-11cf-9d89-0080c72e70a3`,oneChannelInstance:`3d786f92-f76e-11cf-9d89-0080c72e70a3`,seriesInstances:`3d786f93-f76e-11cf-9d89-0080c72e70a3`,oneSeriesInstance:`3d786f94-f76e-11cf-9d89-0080c72e70a3`,seriesScale:`3d786f96-f76e-11cf-9d89-0080c72e70a3`,seriesOffset:`3d786f97-f76e-11cf-9d89-0080c72e70a3`,seriesValues:`3d786f99-f76e-11cf-9d89-0080c72e70a3`,seriesShareChannelIndex:`8973861f-f1c3-11cf-9d89-0080c72e70a3`,seriesShareSeriesIndex:`89738620-f1c3-11cf-9d89-0080c72e70a3`},Qp={"67f6af87-f753-11cf-9d89-0080c72e70a3":[`histogram`,`histograms`],"67f6af88-f753-11cf-9d89-0080c72e70a3":[`3D histogram`,`3D histograms`],"67f6af89-f753-11cf-9d89-0080c72e70a3":[`CPF curve`,`CPF curves`],"67f6af8b-f753-11cf-9d89-0080c72e70a3":[`magnitude-duration table`,`magnitude-duration tables`],"67f6af8d-f753-11cf-9d89-0080c72e70a3":[`magnitude-duration table`,`magnitude-duration tables`],"67f6af8e-f753-11cf-9d89-0080c72e70a3":[`magnitude-duration table`,`magnitude-duration tables`]},$p={"67f6af97-f753-11cf-9d89-0080c72e70a3":``,"67f6af98-f753-11cf-9d89-0080c72e70a3":`Min`,"67f6af99-f753-11cf-9d89-0080c72e70a3":`Max`,"67f6af9a-f753-11cf-9d89-0080c72e70a3":`Avg`,"67f6af9b-f753-11cf-9d89-0080c72e70a3":`Inst`,"3d786f9d-f76e-11cf-9d89-0080c72e70a3":`Angle`,"dc762340-3c56-11d2-ae44-0060083a2628":`Angle Min`,"dc762341-3c56-11d2-ae44-0060083a2628":`Angle Max`,"dc762342-3c56-11d2-ae44-0060083a2628":`Angle Avg`,"67f6af9c-f753-11cf-9d89-0080c72e70a3":`P1`,"67f6af9d-f753-11cf-9d89-0080c72e70a3":`P5`,"67f6af9e-f753-11cf-9d89-0080c72e70a3":`P10`,"67f6af9f-f753-11cf-9d89-0080c72e70a3":`P90`,"c690e860-f755-11cf-9d89-0080c72e70a3":`P95`,"c690e861-f755-11cf-9d89-0080c72e70a3":`P99`,"c690e868-f755-11cf-9d89-0080c72e70a3":`Freq`,"c690e870-f755-11cf-9d89-0080c72e70a3":`Count`,"b82b5c82-55c7-11d5-a4b3-444553540000":`Status`},em={"a6b31adf-b451-11d1-ae17-0060083a2628":``,"a6b31add-b451-11d1-ae17-0060083a2628":``,"a6b31ae9-b451-11d1-ae17-0060083a2628":`Spectra`,"a6b31ae2-b451-11d1-ae17-0060083a2628":`Peak`,"a6b31ae5-b451-11d1-ae17-0060083a2628":`RMS`,"a6b31adc-b451-11d1-ae17-0060083a2628":`HRMS`,"07ef68af-9ff5-11d2-b30b-006008b37183":`Frequency`,"a6b31aec-b451-11d1-ae17-0060083a2628":`THD`,"a6b31ad4-b451-11d1-ae17-0060083a2628":`EvenTHD`,"a6b31ae0-b451-11d1-ae17-0060083a2628":`OddTHD`,"a6b31ad2-b451-11d1-ae17-0060083a2628":`Crest factor`,"a6b31adb-b451-11d1-ae17-0060083a2628":`FormFactor`,"a6b31ad0-b451-11d1-ae17-0060083a2628":`ArithSum`,"a6b31ae7-b451-11d1-ae17-0060083a2628":`S0S1`,"a6b31ae8-b451-11d1-ae17-0060083a2628":`S2S1`,"a6b31aea-b451-11d1-ae17-0060083a2628":`Pos seq`,"d71a4b91-3c92-11d4-9f2c-002078e0b723":`Neg seq`,"d71a4b92-3c92-11d4-9f2c-002078e0b723":`Zero seq`,"a6b31ad1-b451-11d1-ae17-0060083a2628":`Unbalance`,"f3d216e0-2aa5-11d5-a4b3-444553540000":`TotalTHDRMS`,"f3d216e1-2aa5-11d5-a4b3-444553540000":`OddTHDRMS`,"f3d216e2-2aa5-11d5-a4b3-444553540000":`EvenTHDRMS`,"f3d216e3-2aa5-11d5-a4b3-444553540000":`TID`,"f3d216e4-2aa5-11d5-a4b3-444553540000":`TIDRMS`,"f3d216e5-2aa5-11d5-a4b3-444553540000":`IHRMS`,"53be6ba8-0789-455b-9a95-da128683dda7":`SpectraHGroup`,"5e51e006-9c95-4c5e-878f-7ca87c0d2a0e":`SpectraIGroup`,"a6b31aeb-b451-11d1-ae17-0060083a2628":`TIF`,"a6b31ad6-b451-11d1-ae17-0060083a2628":`FlkrMagAvg`,"a6b31ad8-b451-11d1-ae17-0060083a2628":`FlkrMaxDVV`,"a6b31ad5-b451-11d1-ae17-0060083a2628":`FlkrFreqMax`,"a6b31ad7-b451-11d1-ae17-0060083a2628":`FlkrMagMax`,"a6b31ada-b451-11d1-ae17-0060083a2628":`FlkrWgtAvg`,"a6b31ad9-b451-11d1-ae17-0060083a2628":`FlkrSpectrum`,"515bf320-71ca-11d4-a4b3-444553540000":`Pst`,"515bf321-71ca-11d4-a4b3-444553540000":`Plt`,"f3d216e6-2aa5-11d5-a4b3-444553540000":`TIFRMS`,"2257ec05-06ea-4709-b43a-0c00534d554a":`FlkrPLTSlide`,"4d693eec-5d1d-4531-993a-793b5356c63d":`FlkrPiLPF`,"126de61c-6691-4d16-8fdf-46482bca4694":`FlkrPiMax`,"e065b621-ffdb-4598-9330-4d09353988b6":`FlkrPiRoot`,"7d11f283-1ce7-4e58-8af0-79048793b8a7":`FlkrPiRootLPF`,"a6b31ade-b451-11d1-ae17-0060083a2628":`IT`,"07ef68a0-9ff5-11d2-b30b-006008b37183":`RMSDemand`,"8786ca10-9113-11d3-b930-0050da2b1f4d":`ANSITDF`,"8786ca11-9113-11d3-b930-0050da2b1f4d":`K-factor`,"f3d216e7-2aa5-11d5-a4b3-444553540000":`TDD`,"72e82a44-336c-11d5-a4b3-444553540000":`RMSPeakDemand`,"a6b31ae1-b451-11d1-ae17-0060083a2628":`P`,"a6b31ae4-b451-11d1-ae17-0060083a2628":`Q`,"a6b31ae6-b451-11d1-ae17-0060083a2628":`S`,"a6b31ae3-b451-11d1-ae17-0060083a2628":`PF`,"a6b31ad3-b451-11d1-ae17-0060083a2628":`DF`,"07ef68a1-9ff5-11d2-b30b-006008b37183":`PDemand`,"07ef68a2-9ff5-11d2-b30b-006008b37183":`QDemand`,"07ef68a3-9ff5-11d2-b30b-006008b37183":`SDemand`,"07ef68a4-9ff5-11d2-b30b-006008b37183":`DFDemand`,"07ef68a5-9ff5-11d2-b30b-006008b37183":`PFDemand`,"672d0305-7810-11d4-a4b3-444553540000":`PPredDemand`,"672d0306-7810-11d4-a4b3-444553540000":`QPredDemand`,"672d0307-7810-11d4-a4b3-444553540000":`SPredDemand`,"672d030a-7810-11d4-a4b3-444553540000":`PCoQDemand`,"672d030b-7810-11d4-a4b3-444553540000":`PCoSDemand`,"672d030d-7810-11d4-a4b3-444553540000":`QCoPDemand`,"672d030e-7810-11d4-a4b3-444553540000":`QCoSDemand`,"07ef68ad-9ff5-11d2-b30b-006008b37183":`DFCoSDemand`,"07ef68ae-9ff5-11d2-b30b-006008b37183":`PFCoSDemand`,"672d0308-7810-11d4-a4b3-444553540000":`PFCoPDemand`,"672d0309-7810-11d4-a4b3-444553540000":`PFCoQDemand`,"672d030f-7810-11d4-a4b3-444553540000":`AngleFund`,"672d0310-7810-11d4-a4b3-444553540000":`QFund`,"672d0311-7810-11d4-a4b3-444553540000":`PFVector`,"672d0312-7810-11d4-a4b3-444553540000":`DFVector`,"672d0314-7810-11d4-a4b3-444553540000":`SVector`,"672d0315-7810-11d4-a4b3-444553540000":`SVectorFund`,"672d0316-7810-11d4-a4b3-444553540000":`SFund`,"672d0317-7810-11d4-a4b3-444553540000":`SCoPDemand`,"672d0318-7810-11d4-a4b3-444553540000":`SCoQDemand`,"1c39fb00-a6aa-11d4-a4b3-444553540000":`PFArith`,"1c39fb01-a6aa-11d4-a4b3-444553540000":`DFArith`,"1c39fb02-a6aa-11d4-a4b3-444553540000":`SArith`,"1c39fb03-a6aa-11d4-a4b3-444553540000":`SArithFund`,"72e82a43-336c-11d5-a4b3-444553540000":`SPeakDemand`,"72e82a42-336c-11d5-a4b3-444553540000":`QPeakDemand`,"72e82a41-336c-11d5-a4b3-444553540000":`PPeakDemand`,"b82b5c80-55c7-11d5-a4b3-444553540000":`PHarmonic`,"b82b5c81-55c7-11d5-a4b3-444553540000":`PHarmonicUnsigned`,"1cdda475-1ebb-42d8-8087-d01b0b5cfa97":`PFund`,"07ef68a6-9ff5-11d2-b30b-006008b37183":`PIntg`,"07ef68a7-9ff5-11d2-b30b-006008b37183":`PIntgPos`,"672d0300-7810-11d4-a4b3-444553540000":`PIntgPosFund`,"07ef68a8-9ff5-11d2-b30b-006008b37183":`PIntgNeg`,"672d0301-7810-11d4-a4b3-444553540000":`PIntgNegFund`,"07ef68a9-9ff5-11d2-b30b-006008b37183":`QIntg`,"07ef68aa-9ff5-11d2-b30b-006008b37183":`QIntgPos`,"672d0303-7810-11d4-a4b3-444553540000":`QIntgPosFund`,"672d0304-7810-11d4-a4b3-444553540000":`QIntgNegFund`,"07ef68ab-9ff5-11d2-b30b-006008b37183":`QIntgNeg`,"07ef68ac-9ff5-11d2-b30b-006008b37183":`SIntg`,"672d0313-7810-11d4-a4b3-444553540000":`SIntgFund`,"f098a9a0-3ee4-11d5-a4b3-444553540000":`PIVLIntg`,"f098a9a1-3ee4-11d5-a4b3-444553540000":`PIVLIntgPos`,"f098a9a2-3ee4-11d5-a4b3-444553540000":`PIVLIntgPosFund`,"f098a9a3-3ee4-11d5-a4b3-444553540000":`PIVLIntgNeg`,"f098a9a4-3ee4-11d5-a4b3-444553540000":`PIVLIntgNegFund`,"f098a9a5-3ee4-11d5-a4b3-444553540000":`QIVLIntg`,"f098a9a6-3ee4-11d5-a4b3-444553540000":`QIVLIntgPos`,"f098a9a7-3ee4-11d5-a4b3-444553540000":`QIVLIntgPosFund`,"f098a9a8-3ee4-11d5-a4b3-444553540000":`QIVLIntgNegFund`,"f098a9a9-3ee4-11d5-a4b3-444553540000":`QIVLIntgNeg`,"f098a9aa-3ee4-11d5-a4b3-444553540000":`SIVLIntg`,"f098a9ab-3ee4-11d5-a4b3-444553540000":`SIVLIntgFund`,"d347ba65-e34c-11d4-82d9-00e09872a094":`DAxisField`,"d347ba64-e34c-11d4-82d9-00e09872a094":`QAxis`,"d347ba62-e34c-11d4-82d9-00e09872a094":`Rotational`,"d347ba63-e34c-11d4-82d9-00e09872a094":`DAxis`,"d347ba61-e34c-11d4-82d9-00e09872a094":`Linear`,"5202bd07-245c-11d5-a4b3-444553540000":`TransferFunc`,"b82b5c83-55c7-11d5-a4b3-444553540000":`Status`},tm=`This PQDIF file is damaged.`,nm=()=>{throw Error(tm)},rm=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,`0`));function im(e,t){let n=n=>rm[e[t+n]];return`${n(3)}${n(2)}${n(1)}${n(0)}-${n(5)}${n(4)}-${n(7)}${n(6)}-${n(8)}${n(9)}-${n(10)}${n(11)}${n(12)}${n(13)}${n(14)}${n(15)}`}const am={1:1,2:2,3:4,10:1,11:2,20:1,21:2,22:4,30:1,31:2,32:4,40:4,41:8,42:8,43:16,50:12,60:16},om=e=>am[e]??0;async function sm(e,t){if(t<4)return[];let n=Math.floor(t/28)+1,r=async t=>{let n=await e(t,4);return new DataView(n.buffer,n.byteOffset,4).getInt32(0,!0)},i=async(a,o)=>{(o>32||a+4>t)&&nm();let s=await r(a);(s<0||a+4+s*28>t||(n-=s)<0)&&nm();let c=await e(a+4,s*28),l=new DataView(c.buffer,c.byteOffset,c.byteLength),u=[];for(let n=0,d=0;n<s;n++,d+=28){let n=c[d+16],s=c[d+17],f={tag:im(c,d),type:n,phys:s,at:a+4+d+20,size:1,kids:[],bytes:null},p=am[s]??0,m=n===2&&c[d+18];if(!m){let e=l.getInt32(d+20,!0);(e<0||e>=t)&&nm(),f.at=e}if(n===1)f.kids=await i(f.at,o+1);else if(n===3){if(!p||f.at+4>t)continue;f.size=await r(f.at),f.at+=4,(f.size<0||f.at+f.size*p>t)&&nm(),f.size*p<=65536&&(f.bytes=(await e(f.at,f.size*p)).slice())}else if(n===2){if(!p||f.at+p>t)continue;f.bytes=m?c.slice(d+20,d+20+p):(await e(f.at,p)).slice()}else continue;u.push(f)}return u};return i(0,0)}async function cm(e,t){return t.bytes??=await e(t.at,t.size*om(t.phys)),t.bytes}function lm(e,t,n){switch(t){case 1:case 10:case 30:return e.getUint8(n);case 2:case 11:case 31:return e.getUint16(n,!0);case 3:case 32:return e.getUint32(n,!0);case 20:return e.getInt8(n);case 21:return e.getInt16(n,!0);case 22:return e.getInt32(n,!0);case 40:return e.getFloat32(n,!0);case 41:return e.getFloat64(n,!0);default:return NaN}}const um=e=>{if(!e.bytes)throw Error(tm);return new DataView(e.bytes.buffer,e.bytes.byteOffset,e.bytes.byteLength)},dm=(e,t=0)=>lm(um(e),e.phys,t*(am[e.phys]??0)),fm=(e,t=0)=>{let n=um(e);return[n.getUint32(t*12,!0),n.getFloat64(t*12+4,!0)]},pm=([e,t])=>(e-25569)*86400+t;function mm(e){if(!e||e.type!==3||!e.bytes)return``;let t=e.phys===11?new TextDecoder(`utf-16le`).decode(e.bytes):new TextDecoder(`latin1`).decode(e.bytes),n=t.indexOf(`\0`);return(n<0?t:t.slice(0,n)).trim()}const hm=e=>e&&e.phys===60&&e.bytes?im(e.bytes,0):``,X=(e,t)=>e?.find(e=>e.tag===t),gm=(e,t)=>e?.filter(e=>e.tag===t)??[];async function _m(e){let t=[];for(let n=0;;){n+64>e.size&&nm();let r=await e.read(n,64);im(r,0)!==`4a111440-e49f-11cf-9900-505144494600`&&nm();let i=new DataView(r.buffer,r.byteOffset,r.byteLength),a=i.getInt32(36,!0),o=i.getInt32(40,!0);if((a<0||n+64+a>e.size)&&nm(),t.push({type:im(r,16),body:n+64,size:a}),o===0||o===e.size)return t;(o<n+64+a||o>e.size)&&nm(),n=o}}async function vm(e,t,n){let r=await e.slice(t.body,t.size);return!n||r.length===0?r:it(r,-1,Math.min(1073741824,w(r.length)))}async function ym(e,t,n){if(n){let n=await vm(e,t,!0);return{size:n.length,read:async(e,t)=>n.subarray(e,e+t)}}return{size:t.size,read:(n,r)=>e.read(t.body+n,r)}}const bm=65536,xm=new Set([10,11,42,43,50,60]),Sm=[``,`V`,`I`,`Power`,`Energy`,`Temperature`,`Pressure`,`Charge`,`Electric field`,`Magnetic field`,`Velocity`,`Bearing`,`Force`,`Torque`,`Position`,`Flux linkage`,`Flux density`,`Status`],Cm=[``,`A-N`,`B-N`,`C-N`,`N-G`,`A-B`,`B-C`,`C-A`,`Residual`,`Net`,`Pos seq`,`Neg seq`,`Zero seq`,`Total`,`L-N avg`,`L-L avg`,`Worst`,`Plus`,`Minus`],wm=`..s.cycles...V.A.VA.W.var.ohm.S.V/A.J.Hz.°C.°.dB.%.pu.samples.varh.Wh.VAh.m/s.mph.bar.Pa.N.N·m.rpm.rad/s.m.Wb-turns.T.Wb.V/V.A/A.A/V`.split(`.`),Tm=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),Em=e=>e&&e.type===2?dm(e):0,Dm=(e,t)=>(e[0]-t[0])*86400+(e[1]-t[1]);function Om(e){let t=gm(X(e,Y.channelDefinitions)?.kids,Y.oneChannelDefinition).map(e=>({name:mm(X(e.kids,Y.channelName)),phase:Em(X(e.kids,Y.phaseId)),measured:Em(X(e.kids,Y.quantityMeasuredId)),quantityType:hm(X(e.kids,Y.quantityTypeId)),series:gm(X(e.kids,Y.seriesDefinitions)?.kids,Y.oneSeriesDefinition).map(e=>({valueType:hm(X(e.kids,Y.valueTypeId)),units:Em(X(e.kids,Y.quantityUnitsId)),characteristic:hm(X(e.kids,Y.quantityCharacteristicId)),storage:Em(X(e.kids,Y.storageMethodId))||1,name:mm(X(e.kids,Y.valueTypeName))}))}));return{name:mm(X(e,Y.dataSourceName)),defs:t}}function km(e){let t=new Map;for(let n of gm(X(e,Y.channelSettingsArray)?.kids,Y.oneChannelSetting)){let e=Em(X(n.kids,Y.channelDefinitionIndex));if(t.has(e))continue;let r=X(n.kids,Y.xdSystemSideRatio),i=X(n.kids,Y.xdMonitorSideRatio);t.set(e,r&&i?Em(r)/Em(i):null)}return{useTransducer:Em(X(e,Y.useTransducer))!==0,ratio:t}}const Am=e=>gm(X(e,Y.channelInstances)?.kids,Y.oneChannelInstance),jm=e=>gm(X(e?.kids,Y.seriesInstances)?.kids,Y.oneSeriesInstance);function Mm(e,t,n,r=0){let i=jm(e[t])[n]?.kids;if(!i)return{};let a=X(i,Y.seriesShareChannelIndex),o=X(i,Y.seriesShareSeriesIndex),s=a&&o&&r<8?Mm(e,Em(a),Em(o),r+1):{},c=X(i,Y.seriesValues);return{values:s.values??(c?.type===3?c:void 0),scale:X(i,Y.seriesScale)??s.scale,offset:X(i,Y.seriesOffset)??s.offset}}const Nm=(e,t)=>t&2?[e.scale?dm(e.scale):1,e.offset?dm(e.offset):0]:[1,0];function Pm(e,t){let n=e.values,[r,i]=Nm(e,t);return{at:n.at,phys:n.phys,size:n.size,storage:t,scale:r,offset:i}}const Fm=e=>(e.storage&4)!=0&&e.phys!==50;function Im(e){let t=dm(e,0);if(!(Number.isInteger(t)&&t>=0&&1+2*t<=e.size))throw Error(tm);for(let n=0;n<t;n++){let t=dm(e,1+2*n);if(!(Number.isInteger(t)&&t>=0))throw Error(tm)}return t}function Lm(e,t,n){if(!Fm({phys:e.phys,storage:t}))return e.size;let r=0;for(let t=0,n=Im(e);t<n;t++)r+=dm(e,1+2*t);if(r>n||r>128e6)throw Error(tm);return r}async function Rm(e,t,n){let r=t.values,i=2166136261,a=r.size*om(r.phys);for(let t=0;t<a;t+=1<<20){let n=r.bytes?r.bytes.subarray(t,t+(1<<20)):await e(r.at+t,Math.min(1<<20,a-t));for(let e=0;e<n.length;e++)i=Math.imul(i^n[e],16777619)}return`${n}|${r.phys}|${r.size}|${Nm(t,n).join(`,`)}|${i>>>0}`}function zm(e,t,n){let r=Sm[e.measured]??``,i=e.measured===2&&e.phase>=1&&e.phase<=3?`ABC`[e.phase-1]:e.phase>=19&&e.phase<=34?`General ${e.phase-18}`:Cm[e.phase]??``,a=em[t.characteristic],o=$p[t.valueType]??(t.name||`Series ${n+1}`);return a===void 0&&e.name?[e.name,o].filter(Boolean).join(` `):[...r||i?[r,i]:[e.name],a,o].filter(Boolean).join(` `)}async function Bm(e,t,n,r,i){let a=om(e.phys),o=t=>{if(e.phys===50)return t;for(let n=0;n<t.length;n++)t[n]=(e.offset+t[n]*e.scale)*i+r;return t};if(Fm(e)){let n={tag:``,type:3,phys:e.phys,at:0,size:e.size,kids:[],bytes:await t(e.at,e.size*a)},r=Im(n),i=0,s=0,c=0;return async(e,t)=>{let a=new Float64Array(t-e).fill(NaN);for(let e=0;e<a.length&&i<r;){let t=dm(n,1+2*i),r=dm(n,2+2*i),o=Math.min(t-s,a.length-e);for(let t=0;t<o;t++)a[e++]=c+(s+t)*r;s+=o,s>=t&&(c+=t*r,i++,s=0)}return o(a)}}return async(r,i)=>{let s=new Float64Array(i-r).fill(NaN),c=Math.min(i,e.size)-r;if(c>0){let i=Tm(await t(e.at+r*a,c*a));if(e.phys===50)for(let e=0;e<c;e++)s[e]=Dm([i.getUint32(e*12,!0),i.getFloat64(e*12+4,!0)],n);else for(let t=0;t<c;t++)s[t]=lm(i,e.phys,t*a)}return o(s)}}async function*Vm(e,t){let n=p(e,t),r=e.plan.groups[t];if(n.length===0||r.samples<=0)return;let i=e.plan.state,a=i.groups[t],o=i.compressed?await vm(e.io,a.rec,!0):null,s=async(t,n)=>o?o.subarray(t,t+n):e.io.slice(a.rec.body+t,n),c=r.time.kind===`timestamps`?await Bm(a.time,s,i.t0,a.start,1):null,l=await Promise.all(n.map(e=>Bm(a.channels[e],s,i.t0,0,a.channels[e].ratio))),u=r.samples;for(let n=0;n<u;n+=bm){e.signal?.throwIfAborted();let r=Math.min(u,n+bm),i=c?await c(n,r):null,a=[];for(let e of l)a.push(await e(n,r));yield{group:t,time:i,start:n,length:r-n,columns:a}}}var Hm=class{#e=new Map;add(e,t,n=1){if(n<=0)return;let r=this.#e.get(e);r?r.n+=n:this.#e.set(e,{many:t,n})}note(){return this.#e.size?`Skipped: ${[...this.#e].map(([e,{many:t,n}])=>`${n} ${n===1?e:t}`).join(`, `)}.`:null}};const Um={...Xp,async plan(e,t){let n=await _m(t);if(n[0].type!==Zp.container)throw Error(tm);let r=async(e,n)=>{let{read:r,size:i}=await ym(t,e,n);return{read:r,els:await sm(r,i)}},{els:i}=await r(n[0],!1),a=Em(X(i,Y.compressionStyle)),o=Em(X(i,Y.compressionAlgorithm));if(a===1)throw Error(`This PQDIF file compresses the whole file, a style IEEE 1159.3 deprecated, which Kymoscope cannot read.`);if(a===2&&o!==0&&o!==1)throw Error(`This PQDIF file is compressed with algorithm ${o} (not zlib), which Kymoscope cannot read.`);let s=a===2&&o===1,c={},l=mm(X(i,Y.title));l&&(c.title=l);let u=new Hm,d=[],f=null,p=0,m=[],h=[];for(let e of n.slice(1))if(e.type===Zp.dataSource){let t=Om((await r(e,s)).els);d=t.defs,c.dataSource??=t.name}else if(e.type===Zp.monitorSettings)f=km((await r(e,s)).els);else if(e.type===Zp.observation){let{read:t,els:n}=await r(e,s),i=X(n,Y.timeStart);if(i?.phys!==50||i.type!==2)throw Error(tm);let a=fm(i),o=X(n,Y.timeTriggered);o?.phys===50&&o.type===2&&h.push(fm(o));let c=p++,l=mm(X(n,Y.observationName))||`Observation ${c+1}`,g=new Map,_=Am(n),v=0;for(let e of _)for(let t of jm(e)){let e=X(t.kids,Y.seriesValues);e?.type===3&&(v=Math.max(v,e.size))}for(let[n,r]of _.entries()){let i=Em(X(r.kids,Y.channelDefinitionIndex)),o=d[i];if(!o){u.add(`channel without a definition`,`channels without a definition`);continue}let s=Qp[o.quantityType];if(s){u.add(...s);continue}let p=o.series.findIndex(e=>e.valueType===`c690e862-f755-11cf-9d89-0080c72e70a3`),m=p<0?{}:Mm(_,n,p);if(!m.values){u.add(`series without a time series`,`series without a time series`,o.series.length-(p<0?0:1));continue}let h=o.series[p].storage,y=await Rm(t,m,h),b=g.get(y);if(!b){let n=Pm(m,h);Fm(n)&&await cm(t,m.values);let r=Lm(m.values,h,v),i=Fm(n)&&n.size>=3&&dm(m.values,0)===1?dm(m.values,2)*n.scale:0;b={obs:c,rec:e,name:l,start:a,time:n,samples:r,rate:i>0?1/i:null,rateStart:n.offset,channels:[]},g.set(y,b)}let x=f?.useTransducer?f.ratio.get(i)??1:1,S=jm(r);o.series.forEach((e,t)=>{if(t===p)return;let r=t<S.length?Mm(_,n,t):{};if(!r.values){u.add(`series defined without values`,`series defined without values`);return}let i=r.values.phys;if(i===10||i===11){u.add(`text series`,`text series`);return}if(xm.has(i)){u.add(`series with values that are not numbers`,`series with values that are not numbers`);return}b.channels.push({...Pm(r,e.storage),ratio:x,name:zm(o,e,t),channel:o.name,unit:wm[e.units]??``})})}for(let e of g.values())e.channels.length&&m.push(e)}if(m.length===0)throw Error(`This PQDIF file has no time series Kymoscope can read.`);let g=m.reduce((e,t)=>pm(t.start)<pm(e)?t.start:e,m[0].start),_=new Map,v=cn(m.map(e=>{let t=_.get(e.obs)??0;return _.set(e.obs,t+1),t?`${e.name} (${t+1})`:e.name}),[]),y=m.map((e,t)=>{let n=Dm(e.start,g),r=new Map;for(let t of e.channels)r.set(t.name.toLowerCase(),(r.get(t.name.toLowerCase())??0)+1);let i=cn(e.channels.map(e=>r.get(e.name.toLowerCase())>1&&e.channel?`${e.name} (${e.channel})`:e.name));return{name:v[t],channels:e.channels.map((e,t)=>({name:i[t],unit:e.unit})),samples:e.samples,time:e.rate?{kind:`rate`,rate:e.rate,start:n+e.rateStart}:{kind:`timestamps`},rateHz:e.rate,irregular:!0}}),b=h.map(e=>({time:Math.round(Dm(e,g)*1e6)/1e6,text:`Trigger`})).sort((e,t)=>e.time-t.time),x=[],S=u.note();S&&x.push(S),c.observations=String(p);let C={compressed:s,t0:g,groups:m.map(e=>({rec:e.rec,start:Dm(e.start,g),time:e.time,channels:e.channels.map(({at:e,phys:t,size:n,storage:r,scale:i,offset:a,ratio:o})=>({at:e,phys:t,size:n,storage:r,scale:i,offset:a,ratio:o}))}))},w=pm(g)*1e3;return{format:s?`PQDIF (zlib)`:`PQDIF`,startTime:Math.abs(w)<=864e13?new Date(w).toISOString():null,groups:y,meta:c,events:b,notes:x,state:C}},streamGroup:(e,t)=>Vm(e,t),async*stream(e){for(let t of e.selection)yield*Vm(e,t.group)}},Wm=[`BOOLEAN`,`INT32`,`INT64`,`INT96`,`FLOAT`,`DOUBLE`,`BYTE_ARRAY`,`FIXED_LEN_BYTE_ARRAY`],Gm=[`PLAIN`,`GROUP_VAR_INT`,`PLAIN_DICTIONARY`,`RLE`,`BIT_PACKED`,`DELTA_BINARY_PACKED`,`DELTA_LENGTH_BYTE_ARRAY`,`DELTA_BYTE_ARRAY`,`RLE_DICTIONARY`,`BYTE_STREAM_SPLIT`,`ALP`],Km=[`REQUIRED`,`OPTIONAL`,`REPEATED`],qm=[`UTF8`,`MAP`,`MAP_KEY_VALUE`,`LIST`,`ENUM`,`DECIMAL`,`DATE`,`TIME_MILLIS`,`TIME_MICROS`,`TIMESTAMP_MILLIS`,`TIMESTAMP_MICROS`,`UINT_8`,`UINT_16`,`UINT_32`,`UINT_64`,`INT_8`,`INT_16`,`INT_32`,`INT_64`,`JSON`,`BSON`,`INTERVAL`],Jm=[`UNCOMPRESSED`,`SNAPPY`,`GZIP`,`LZO`,`BROTLI`,`LZ4`,`ZSTD`,`LZ4_RAW`],Ym=[`DATA_PAGE`,`INDEX_PAGE`,`DICTIONARY_PAGE`,`DATA_PAGE_V2`],Xm=[`UNORDERED`,`ASCENDING`,`DESCENDING`],Zm=[`SPHERICAL`,`VINCENTY`,`THOMAS`,`ANDOYER`,`KARNEY`];function Qm(e){let t=$m(e);if(t.type===1)return{type:`Point`,coordinates:eh(e,t)};if(t.type===2)return{type:`LineString`,coordinates:th(e,t)};if(t.type===3)return{type:`Polygon`,coordinates:nh(e,t)};if(t.type===4){let n=[];for(let r=0;r<t.count;r++)n.push(eh(e,$m(e)));return{type:`MultiPoint`,coordinates:n}}else if(t.type===5){let n=[];for(let r=0;r<t.count;r++)n.push(th(e,$m(e)));return{type:`MultiLineString`,coordinates:n}}else if(t.type===6){let n=[];for(let r=0;r<t.count;r++)n.push(nh(e,$m(e)));return{type:`MultiPolygon`,coordinates:n}}else if(t.type===7){let n=[];for(let r=0;r<t.count;r++)n.push(Qm(e));return{type:`GeometryCollection`,geometries:n}}else throw Error(`Unsupported geometry type: ${t.type}`)}function $m(e){let{view:t}=e,n=t.getUint8(e.offset++)===1,r=t.getUint32(e.offset,n);e.offset+=4;let i=r%1e3,a=Math.floor(r/1e3),o=0;i>1&&i<=7&&(o=t.getUint32(e.offset,n),e.offset+=4);let s=2;return a&&s++,a===3&&s++,{littleEndian:n,type:i,dim:s,count:o}}function eh(e,t){let n=[];for(let r=0;r<t.dim;r++){let r=e.view.getFloat64(e.offset,t.littleEndian);e.offset+=8,n.push(r)}return n}function th(e,t){let n=[];for(let r=0;r<t.count;r++)n.push(eh(e,t));return n}function nh(e,t){let{view:n}=e,r=[];for(let i=0;i<t.count;i++){let i=n.getUint32(e.offset,t.littleEndian);e.offset+=4,r.push(th(e,{...t,count:i}))}return r}const rh=new TextDecoder(`utf-8`,{ignoreBOM:!0}),ih=new TextDecoder,ah={timestampFromMilliseconds(e){return new Date(Number(e))},timestampFromMicroseconds(e){return new Date(Number(e/1000n))},timestampFromNanoseconds(e){return new Date(Number(e/1000000n))},dateFromDays(e){return new Date(e*864e5)},stringFromBytes(e){return e&&rh.decode(e)},jsonFromBytes(e){return e&&JSON.parse(ih.decode(e))},geometryFromBytes(e){return e&&Qm({view:new DataView(e.buffer,e.byteOffset,e.byteLength),offset:0})},geographyFromBytes(e){return e&&Qm({view:new DataView(e.buffer,e.byteOffset,e.byteLength),offset:0})},uuidFromBytes(e){if(!e)return;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,32)}};function oh(e,t,n,r){if(t&&n.endsWith(`_DICTIONARY`)){let n=e;e instanceof Uint8Array&&!(t instanceof Uint8Array)&&(n=new t.constructor(e.length));for(let r=0;r<e.length;r++)n[r]=t[e[r]];return n}else return sh(e,r)}function sh(e,t){let{element:n,parsers:r,utf8:i=!0,schemaPath:a}=t,{type:o,converted_type:s,logical_type:c}=n,l=n.repetition_type!==`REQUIRED`;if(o===`BYTE_ARRAY`&&n.name===`inline`&&a?.at(-2)?.element.logical_type?.type===`FILE`||a?.some(e=>e.element.logical_type?.type===`VARIANT`)&&o===`BYTE_ARRAY`&&s!==`UTF8`&&c?.type!==`STRING`)return e;if(s===`DECIMAL`){let t=n.scale||0,r=10**t,i=Array(e.length);for(let n=0;n<i.length;n++)e[n]instanceof Uint8Array?i[n]=t>308?ch(e[n])*10**-t:ch(e[n])/r:i[n]=Number(e[n])/r;return i}if(!s&&o===`INT96`)return Array.from(e).map(e=>r.timestampFromNanoseconds(lh(e)));if(s===`DATE`)return Array.from(e).map(e=>r.dateFromDays(e));if(s===`TIMESTAMP_MILLIS`)return Array.from(e).map(e=>r.timestampFromMilliseconds(e));if(s===`TIMESTAMP_MICROS`)return Array.from(e).map(e=>r.timestampFromMicroseconds(e));if(s===`JSON`)return e.map(e=>r.jsonFromBytes(e));if(s===`BSON`)throw Error(`parquet bson not supported`);if(s===`INTERVAL`)throw Error(`parquet interval not supported`);if(c?.type===`GEOMETRY`)return e.map(e=>r.geometryFromBytes(e));if(c?.type===`GEOGRAPHY`)return e.map(e=>r.geographyFromBytes(e));if(c?.type===`UUID`)return e.map(e=>r.uuidFromBytes(e));if(s===`UTF8`||c?.type===`STRING`||i&&o===`BYTE_ARRAY`)return e.map(e=>r.stringFromBytes(e));if(s===`UINT_64`||c?.type===`INTEGER`&&c.bitWidth===64&&!c.isSigned){if(e instanceof BigInt64Array)return new BigUint64Array(e.buffer,e.byteOffset,e.length);let t=l?Array(e.length):new BigUint64Array(e.length);for(let n=0;n<t.length;n++)t[n]=e[n];return t}if(s===`UINT_32`||c?.type===`INTEGER`&&c.bitWidth===32&&!c.isSigned){if(e instanceof Int32Array)return new Uint32Array(e.buffer,e.byteOffset,e.length);let t=l?Array(e.length):new Uint32Array(e.length);for(let n=0;n<t.length;n++)t[n]=e[n]<0?4294967296+e[n]:e[n];return t}if(c?.type===`FLOAT16`)return Array.from(e).map(uh);if(c?.type===`TIMESTAMP`){let{unit:t}=c,n=r.timestampFromMilliseconds;t===`MICROS`&&(n=r.timestampFromMicroseconds),t===`NANOS`&&(n=r.timestampFromNanoseconds);let i=Array(e.length);for(let t=0;t<i.length;t++)i[t]=n(e[t]);return i}return e}function ch(e){if(!e.length)return 0;let t=0n;for(let n of e)t=t*256n+BigInt(n);let n=e.length*8;return t>=2n**BigInt(n-1)&&(t-=2n**BigInt(n)),Number(t)}function lh(e){let t=(e>>64n)-2440588n,n=e&18446744073709551615n;return t*86400000000000n+n}function uh(e){if(!e)return;let t=e[1]<<8|e[0],n=t>>15?-1:1,r=t>>10&31,i=t&1023;return r===0?n*2**-14*(i/1024):r===31?i?NaN:n*(1/0):n*2**(r-15)*(1+i/1024)}function dh(e,t,n){let r=e[t],i=[],a=1;if(r.num_children)for(;i.length<r.num_children;){let r=e[t+a],o=dh(e,t+a,[...n,r.name]);a+=o.count,i.push(o)}return{count:a,element:r,children:i,path:n}}function fh(e,t){return ph(dh(e,0,[]),t)}function ph(e,t){let n=[e];for(let r of t){let i=e.children.find(e=>e.element.name===r);if(!i)throw Error(`parquet schema element not found: ${t}`);n.push(i),e=i}return n}function mh(e){let t=[];function n(e){if(e.children.length)for(let t of e.children)n(t);else t.push(e.path.join(`.`))}return n(e),t}function hh(e){let t=0;for(let{element:n}of e)n.repetition_type===`REPEATED`&&t++;return t}function gh(e){let t=0;for(let{element:n}of e.slice(1))n.repetition_type!==`REQUIRED`&&t++;return t}function _h(e){if(!e||e.element.converted_type!==`LIST`||e.children.length>1)return!1;let t=e.children[0];return!(t.children.length>1||t.element.repetition_type!==`REPEATED`)}function vh(e){if(!e||e.element.converted_type!==`MAP`||e.children.length>1)return!1;let t=e.children[0];return!(t.children.length!==2||t.element.repetition_type!==`REPEATED`||t.children.find(e=>e.element.name===`key`)?.element.repetition_type===`REPEATED`||t.children.find(e=>e.element.name===`value`)?.element.repetition_type===`REPEATED`)}function yh(e){if(e.length!==2)return!1;let[,t]=e;return!(t.element.repetition_type===`REPEATED`||t.children.length)}function bh(e){let t={},n=0;for(;;){if(e.offset>=e.view.byteLength)throw Error(`thrift struct ended without STOP`);let r=e.view.getUint8(e.offset++),i=r&15;if(i===0)break;let a=r>>4;n=a?n+a:wh(e),t[`field_${n}`]=xh(e,i)}return t}function xh(e,t){switch(t){case 1:return!0;case 2:return!1;case 3:return e.view.getInt8(e.offset++);case 4:case 5:return wh(e);case 6:return Th(e);case 7:{let t=e.view.getFloat64(e.offset,!0);return e.offset+=8,t}case 8:{let t=Sh(e);if(e.offset+t>e.view.byteLength)throw Error(`thrift binary length ${t} exceeds remaining ${e.view.byteLength-e.offset} bytes`);let n=new Uint8Array(e.view.buffer,e.view.byteOffset+e.offset,t);return e.offset+=t,n}case 9:{let t=e.view.getUint8(e.offset++),n=t&15,r=t>>4;r===15&&(r=Sh(e));let i=n===1||n===2,a=Array(r);for(let t=0;t<r;t++)a[t]=i?xh(e,3)===1:xh(e,n);return a}case 12:return bh(e);default:throw Error(`thrift unhandled type: ${t}`)}}function Sh(e){let t=0,n=0;for(;;){let r=e.view.getUint8(e.offset++);if(t|=(r&127)<<n,!(r&128))return t;n+=7}}function Ch(e){let t=0n,n=0n;for(;;){let r=e.view.getUint8(e.offset++);if(t|=BigInt(r&127)<<n,!(r&128))return t;n+=7n}}function wh(e){let t=Sh(e);return t>>>1^-(t&1)}function Th(e){let t=Ch(e);return t>>1n^-(t&1n)}function Eh(e,t){let n=new Map,r=t?.find(({key:e})=>e===`geo`)?.value,i=(r&&JSON.parse(r)?.columns)??{};for(let[e,t]of Object.entries(i)){if(t.encoding!==`WKB`)continue;let r=t.edges===`spherical`?`GEOGRAPHY`:`GEOMETRY`,i=t.crs?.id??t.crs?.ids?.[0],a=i?`${i.authority}:${i.code.toString()}`:void 0;n.set(e,{type:r,crs:a})}for(let t=1;t<e.length;t++){let{logical_type:r,name:i,num_children:a,type:o}=e[t];if(a){t+=a;continue}o===`BYTE_ARRAY`&&!r&&(e[t].logical_type=n.get(i))}}const Dh=new TextDecoder(`utf-8`,{ignoreBOM:!0});function Oh(e){return e&&Dh.decode(e)}async function kh(e,{parsers:t,initialFetchSize:n=524288,geoparquet:r=!0}={}){if(!e||!(e.byteLength>=0))throw Error(`parquet expected AsyncBuffer`);let i=Math.max(0,e.byteLength-n),a=await e.slice(i,e.byteLength),o=new DataView(a);if(o.getUint32(a.byteLength-4,!0)!==827474256)throw Error(`parquet file invalid (footer != PAR1)`);let s=o.getUint32(a.byteLength-8,!0);if(s>e.byteLength-8)throw Error(`parquet metadata length ${s} exceeds available buffer ${e.byteLength-8}`);if(s+8>n){let n=e.byteLength-s-8,o=await e.slice(n,i),c=new ArrayBuffer(s+8),l=new Uint8Array(c);return l.set(new Uint8Array(o)),l.set(new Uint8Array(a),i-n),Ah(c,{parsers:t,geoparquet:r})}else return Ah(a,{parsers:t,geoparquet:r})}function Ah(e,{parsers:t,geoparquet:n=!0}={}){let r;if(e instanceof ArrayBuffer)r=new DataView(e);else if(e instanceof Uint8Array)r=new DataView(e.buffer,e.byteOffset,e.byteLength);else throw Error(`parquet expected ArrayBuffer or Uint8Array`);let i={...ah,...t};if(r.byteLength<8)throw Error(`parquet file is too short`);if(r.getUint32(r.byteLength-4,!0)!==827474256)throw Error(`parquet file invalid (footer != PAR1)`);let a=r.byteLength-8,o=r.getUint32(a,!0);if(o>r.byteLength-8)throw Error(`parquet metadata length ${o} exceeds available buffer ${r.byteLength-8}`);let s=a-o,c=bh({view:r,offset:s}),l=c.field_1,u=c.field_2.map(e=>({type:Wm[e.field_1],type_length:e.field_2,repetition_type:Km[e.field_3],name:Oh(e.field_4),num_children:e.field_5,converted_type:qm[e.field_6],scale:e.field_7,precision:e.field_8,field_id:e.field_9,logical_type:Mh(e.field_10)})),d=u.filter(e=>e.type),f=c.field_3,p=c.field_4.map(e=>({columns:e.field_1.map((e,t)=>({file_path:Oh(e.field_1),file_offset:e.field_2,meta_data:e.field_3&&{type:Wm[e.field_3.field_1],encodings:e.field_3.field_2?.map(e=>Gm[e]),path_in_schema:e.field_3.field_3.map(Oh),codec:Jm[e.field_3.field_4],num_values:e.field_3.field_5,total_uncompressed_size:e.field_3.field_6,total_compressed_size:e.field_3.field_7,key_value_metadata:e.field_3.field_8?.map(e=>({key:Oh(e.field_1),value:Oh(e.field_2)})),data_page_offset:e.field_3.field_9,index_page_offset:e.field_3.field_10,dictionary_page_offset:e.field_3.field_11,statistics:Ph(e.field_3.field_12,d[t],i),encoding_stats:e.field_3.field_13?.map(e=>({page_type:Ym[e.field_1],encoding:Gm[e.field_2],count:e.field_3})),bloom_filter_offset:e.field_3.field_14,bloom_filter_length:e.field_3.field_15,size_statistics:e.field_3.field_16&&{unencoded_byte_array_data_bytes:e.field_3.field_16.field_1,repetition_level_histogram:e.field_3.field_16.field_2,definition_level_histogram:e.field_3.field_16.field_3},geospatial_statistics:e.field_3.field_17&&{bbox:e.field_3.field_17.field_1&&{xmin:e.field_3.field_17.field_1.field_1,xmax:e.field_3.field_17.field_1.field_2,ymin:e.field_3.field_17.field_1.field_3,ymax:e.field_3.field_17.field_1.field_4,zmin:e.field_3.field_17.field_1.field_5,zmax:e.field_3.field_17.field_1.field_6,mmin:e.field_3.field_17.field_1.field_7,mmax:e.field_3.field_17.field_1.field_8},geospatial_types:e.field_3.field_17.field_2}},offset_index_offset:e.field_4,offset_index_length:e.field_5,column_index_offset:e.field_6,column_index_length:e.field_7,crypto_metadata:e.field_8,encrypted_column_metadata:e.field_9})),total_byte_size:e.field_2,num_rows:e.field_3,sorting_columns:e.field_4?.map(e=>({column_idx:e.field_1,descending:e.field_2,nulls_first:e.field_3})),file_offset:e.field_5,total_compressed_size:e.field_6,ordinal:e.field_7})),m=c.field_5?.map(e=>({key:Oh(e.field_1),value:Oh(e.field_2)})),h=Oh(c.field_6);return n&&Eh(u,m),{version:l,schema:u,num_rows:f,row_groups:p,key_value_metadata:m,created_by:h,metadata_length:o}}function jh({schema:e}){return fh(e,[])[0]}function Mh(e){return e?.field_1?{type:`STRING`}:e?.field_2?{type:`MAP`}:e?.field_3?{type:`LIST`}:e?.field_4?{type:`ENUM`}:e?.field_5?{type:`DECIMAL`,scale:e.field_5.field_1,precision:e.field_5.field_2}:e?.field_6?{type:`DATE`}:e?.field_7?{type:`TIME`,isAdjustedToUTC:e.field_7.field_1,unit:Nh(e.field_7.field_2)}:e?.field_8?{type:`TIMESTAMP`,isAdjustedToUTC:e.field_8.field_1,unit:Nh(e.field_8.field_2)}:e?.field_10?{type:`INTEGER`,bitWidth:e.field_10.field_1,isSigned:e.field_10.field_2}:e?.field_11?{type:`NULL`}:e?.field_12?{type:`JSON`}:e?.field_13?{type:`BSON`}:e?.field_14?{type:`UUID`}:e?.field_15?{type:`FLOAT16`}:e?.field_16?{type:`VARIANT`,specification_version:e.field_16.field_1}:e?.field_17?{type:`GEOMETRY`,crs:Oh(e.field_17.field_1)}:e?.field_18?{type:`GEOGRAPHY`,crs:Oh(e.field_18.field_1),algorithm:Zm[e.field_18.field_2]}:e?.field_19?{type:`FILE`}:e}function Nh(e){if(e.field_1)return`MILLIS`;if(e.field_2)return`MICROS`;if(e.field_3)return`NANOS`;throw Error(`parquet time unit required`)}function Ph(e,t,n){return e&&{max:Fh(e.field_1,t,n),min:Fh(e.field_2,t,n),null_count:e.field_3,distinct_count:e.field_4,max_value:Fh(e.field_5,t,n),min_value:Fh(e.field_6,t,n),is_max_value_exact:e.field_7,is_min_value_exact:e.field_8}}function Fh(e,t,n){let{type:r,converted_type:i,logical_type:a}=t;if(e===void 0)return e;if(r===`BOOLEAN`)return e[0]===1;if(r===`BYTE_ARRAY`)return n.stringFromBytes(e);let o=new DataView(e.buffer,e.byteOffset,e.byteLength);if(r===`FLOAT`&&o.byteLength===4)return o.getFloat32(0,!0);if(r===`DOUBLE`&&o.byteLength===8)return o.getFloat64(0,!0);if(r===`INT32`&&i===`DECIMAL`&&o.byteLength===4)return o.getInt32(0,!0)/10**(t.scale||0);if(r===`INT64`&&i===`DECIMAL`&&o.byteLength===8)return Number(o.getBigInt64(0,!0))/10**(t.scale||0);if(r===`INT32`&&i===`DATE`)return n.dateFromDays(o.getInt32(0,!0));if(r===`INT64`&&i===`TIMESTAMP_MILLIS`)return n.timestampFromMilliseconds(o.getBigInt64(0,!0));if(r===`INT64`&&i===`TIMESTAMP_MICROS`)return n.timestampFromMicroseconds(o.getBigInt64(0,!0));if(r===`INT64`&&a?.type===`TIMESTAMP`&&a?.unit===`NANOS`)return n.timestampFromNanoseconds(o.getBigInt64(0,!0));if(r===`INT64`&&a?.type===`TIMESTAMP`&&a?.unit===`MICROS`)return n.timestampFromMicroseconds(o.getBigInt64(0,!0));if(r===`INT64`&&a?.type===`TIMESTAMP`)return n.timestampFromMilliseconds(o.getBigInt64(0,!0));let s=i?.startsWith(`UINT_`)||a?.type===`INTEGER`&&!a.isSigned;if(r===`INT32`&&s&&o.byteLength===4)return o.getUint32(0,!0);if(r===`INT64`&&s&&o.byteLength===8)return o.getBigUint64(0,!0);if(r===`INT32`&&o.byteLength===4)return o.getInt32(0,!0);if(r===`INT64`&&o.byteLength===8)return o.getBigInt64(0,!0);if(i===`DECIMAL`){let n=t.scale||0;return n>308?ch(e)*10**-n:ch(e)/10**n}return a?.type===`FLOAT16`?uh(e):a?.type===`UUID`?n.uuidFromBytes(e):e}function Ih(e,t,n=void 0){let r={...ah,...n},i=bh(e);return{null_pages:i.field_1,min_values:i.field_2.map(e=>Fh(e,t,r)),max_values:i.field_3.map(e=>Fh(e,t,r)),boundary_order:Xm[i.field_4],null_counts:i.field_5,repetition_level_histograms:i.field_6,definition_level_histograms:i.field_7}}function Lh(e){let t=bh(e);return{page_locations:t.field_1.map(e=>({offset:e.field_1,compressed_page_size:e.field_2,first_row_index:e.field_3})),unencoded_byte_array_data_bytes:t.field_2}}const Rh=18446744073709551615n,zh=11400714785074694791n,Bh=14029467366897019727n,Vh=1609587929392839161n,Hh=9650029242287828579n,Uh=2870177450012600261n;function Wh(e,t){return(e<<t|e>>64n-t)&Rh}function Gh(e,t){return e=e+t*Bh&Rh,e=Wh(e,31n),e*zh&Rh}function Kh(e,t){return e^=Gh(0n,t),e*zh+Hh&Rh}function qh(e,t=0n){let n=new DataView(e.buffer,e.byteOffset,e.byteLength),r=e.byteLength,i=0,a;if(r>=32){let e=t+zh+Bh&Rh,o=t+Bh&Rh,s=t,c=t-zh&Rh;for(;i+32<=r;)e=Gh(e,n.getBigUint64(i,!0)),i+=8,o=Gh(o,n.getBigUint64(i,!0)),i+=8,s=Gh(s,n.getBigUint64(i,!0)),i+=8,c=Gh(c,n.getBigUint64(i,!0)),i+=8;a=Wh(e,1n)+Wh(o,7n)+Wh(s,12n)+Wh(c,18n)&Rh,a=Kh(a,e),a=Kh(a,o),a=Kh(a,s),a=Kh(a,c)}else a=t+Uh&Rh;for(a=a+BigInt(r)&Rh;i+8<=r;)a^=Gh(0n,n.getBigUint64(i,!0)),a=Wh(a,27n)*zh+Hh&Rh,i+=8;for(i+4<=r&&(a^=BigInt(n.getUint32(i,!0))*zh&Rh,a=Wh(a,23n)*Bh+Vh&Rh,i+=4);i<r;)a^=BigInt(n.getUint8(i))*Uh&Rh,a=Wh(a,11n)*zh&Rh,i+=1;return a^=a>>33n,a=a*Bh&Rh,a^=a>>29n,a=a*Vh&Rh,a^=a>>32n,a}const Jh=new TextEncoder,Yh=new Uint32Array([1203114875,1150766481,2284105051,2729912477,1884591559,770785867,2667333959,1550580529]);function Xh(e,t){return Number((e>>32n)*BigInt(t)>>32n)}function Zh(e){let t=new Uint32Array(8),n=Number(e&4294967295n)|0;for(let e=0;e<8;e++)t[e]=1<<(Math.imul(n,Yh[e])>>>27);return t}function Qh(e,t){let n=Xh(t,e.length>>3)<<3,r=Zh(t);for(let t=0;t<8;t++)if((e[n+t]&r[t])===0)return!1;return!0}function $h(e){let t=bh(e),n=t.field_1;if(typeof n!=`number`||n<=0||n%32!=0||!t.field_2?.field_1||!t.field_3?.field_1||!t.field_4?.field_1)return;let{view:r,offset:i}=e;if(i+n>r.byteLength)throw Error(`parquet bloom filter truncated: need ${n} bytes, have ${r.byteLength-i}`);let a=new Uint32Array(n>>2);for(let e=0;e<a.length;e++)a[e]=r.getUint32(i+e*4,!0);return e.offset=i+n,{numBytes:n,blocks:a}}function eg(e,t){if(e==null)return;let{type:n,converted_type:r,logical_type:i}=t;if(n===`BOOLEAN`)return typeof e==`boolean`?qh(new Uint8Array([+!!e])):void 0;if(n===`FLOAT`){if(typeof e!=`number`)return;let t=new ArrayBuffer(4);return new DataView(t).setFloat32(0,e,!0),qh(new Uint8Array(t))}if(n===`DOUBLE`){if(typeof e!=`number`)return;let t=new ArrayBuffer(8);return new DataView(t).setFloat64(0,e,!0),qh(new Uint8Array(t))}if(n===`INT32`){if(r===`DATE`||r===`DECIMAL`||r===`TIME_MILLIS`||i?.type===`DATE`||i?.type===`TIME`||i?.type===`DECIMAL`||typeof e!=`number`||!Number.isInteger(e))return;let t=new ArrayBuffer(4);return new DataView(t).setInt32(0,e|0,!0),qh(new Uint8Array(t))}if(n===`INT64`){if(r===`TIMESTAMP_MILLIS`||r===`TIMESTAMP_MICROS`||r===`TIME_MICROS`||r===`DECIMAL`||i?.type===`TIMESTAMP`||i?.type===`TIME`||i?.type===`DECIMAL`)return;let t;if(typeof e==`bigint`)t=e;else if(typeof e==`number`&&Number.isSafeInteger(e))t=BigInt(e);else return;let n=new ArrayBuffer(8);return new DataView(n).setBigUint64(0,BigInt.asUintN(64,t),!0),qh(new Uint8Array(n))}if(n===`BYTE_ARRAY`)return r===`JSON`||r===`BSON`||r===`DECIMAL`||i?.type===`JSON`||i?.type===`BSON`||i?.type===`VARIANT`||i?.type===`GEOMETRY`||i?.type===`GEOGRAPHY`?void 0:typeof e==`string`?qh(Jh.encode(e)):e instanceof Uint8Array?qh(e):void 0;if(n===`FIXED_LEN_BYTE_ARRAY`)return r===`DECIMAL`||r===`INTERVAL`||i?.type===`DECIMAL`||i?.type===`UUID`||i?.type===`FLOAT16`||i?.type===`GEOMETRY`||i?.type===`GEOGRAPHY`?void 0:e instanceof Uint8Array?qh(e):void 0}function tg(e){let t=new Set;return ng(e,t),t}function ng(e,t){if(e){if(`$and`in e&&Array.isArray(e.$and)){for(let n of e.$and)ng(n,t);return}if(`$or`in e&&Array.isArray(e.$or)){for(let n of e.$or)ng(n,t);return}if(!(`$nor`in e))for(let[n,r]of Object.entries(e))n.startsWith(`$`)||(typeof r==`object`&&r&&!Array.isArray(r)?(`$eq`in r||`$in`in r)&&t.add(n):t.add(n))}}function rg(e,t){let n=1e4;for(let r=0;r<t.length;r+=n)e.push(...t.slice(r,r+n))}function ig(e,t,n=!0){if(n?e===t:e==t)return!0;if(!e||!t||typeof e!=`object`||typeof t!=`object`)return!1;if(e instanceof Uint8Array&&t instanceof Uint8Array){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}if(e instanceof Date||t instanceof Date)return e instanceof Date&&t instanceof Date&&e.getTime()===t.getTime();if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(!ig(e[r],t[r],n))return!1;return!0}let r=Object.keys(e);if(r.length!==Object.keys(t).length)return!1;for(let i of r)if(!ig(e[i],t[i],n))return!1;return!0}function ag(e){if(!e)return[];if(e.length===1)return e[0];let t=[];for(let n of e)rg(t,n);return t}const og=new TextEncoder;function sg(e){if(!e)return[];let t=[];return`$and`in e&&Array.isArray(e.$and)?t.push(...e.$and.flatMap(sg)):`$or`in e&&Array.isArray(e.$or)?t.push(...e.$or.flatMap(sg)):`$nor`in e&&Array.isArray(e.$nor)?t.push(...e.$nor.flatMap(sg)):t.push(...Object.keys(e)),[...new Set(t)]}function cg(e){return[...new Set(sg(e).map(e=>e.split(`.`)[0]))]}function lg(e,t,n=!0){return`$and`in t&&Array.isArray(t.$and)?t.$and.every(t=>lg(e,t,n)):`$or`in t&&Array.isArray(t.$or)?t.$or.some(t=>lg(e,t,n)):`$nor`in t&&Array.isArray(t.$nor)?!t.$nor.some(t=>lg(e,t,n)):Object.entries(t).every(([t,r])=>{let i=yg(e,t);return typeof r!=`object`||!r||Array.isArray(r)?ig(i,r,n):Object.entries(r||{}).every(([e,t])=>e===`$gt`?i!=null&&i>t:e===`$gte`?i!=null&&i>=t:e===`$lt`?i!=null&&i<t:e===`$lte`?i!=null&&i<=t:e===`$eq`?ig(i,t,n):e===`$ne`?!ig(i,t,n):e===`$in`?Array.isArray(t)&&ug(i,t,n):e===`$nin`?Array.isArray(t)&&!ug(i,t,n):e===`$not`?!lg({value:i},{value:t},n):!0)})}function ug(e,t,n){return t.some(t=>ig(e,t,n)||Array.isArray(e)&&e.some(e=>ig(e,t,n)))}function dg({rowGroup:e,physicalColumns:t,filter:n,strict:r=!0,bloomFilters:i,schemaElements:a}){if(!n)return!1;if(`$and`in n&&Array.isArray(n.$and))return n.$and.some(n=>dg({rowGroup:e,physicalColumns:t,filter:n,strict:r,bloomFilters:i,schemaElements:a}));if(`$or`in n&&Array.isArray(n.$or))return n.$or.every(n=>dg({rowGroup:e,physicalColumns:t,filter:n,strict:r,bloomFilters:i,schemaElements:a}));if(`$nor`in n&&Array.isArray(n.$nor))return!1;for(let[o,s]of Object.entries(n)){let n=t.indexOf(o);if(n===-1)continue;let{min:c,max:l,min_value:u,max_value:d,null_count:f}=e.columns[n].meta_data?.statistics||{},p=u===void 0?c:u,m=d===void 0?l:d,h=p!==void 0&&m!==void 0,g=i?.[o],_=a?.[o],v=lg({value:null},{value:s},r)&&(f===void 0||f>0);if(h&&!v&&fg(s,p,m,r,_))return!0;for(let[e,t]of Object.entries(s||{}))if(g&&_){if(e===`$eq`){let e=eg(t,_);if(e!==void 0&&!Qh(g.blocks,e))return!0}if(e===`$in`&&Array.isArray(t)&&t.length>0){let e=!0;for(let n of t){let t=eg(n,_);if(t===void 0||Qh(g.blocks,t)){e=!1;break}}if(e)return!0}}}return!1}function fg(e,t,n,r,i){if(t===void 0||n===void 0)return!1;let a=i?.type===`FLOAT`||i?.type===`DOUBLE`||i?.logical_type?.type===`FLOAT16`;for(let[o,s]of Object.entries(e||{})){let e=pg(t,s,r,i),c=pg(n,s,r,i),l=!(t instanceof Uint8Array||n instanceof Uint8Array)&&(i?.type!==`BYTE_ARRAY`||typeof s==`string`&&[...s].every(e=>e.charCodeAt(0)<=127));if(o===`$gt`&&l&&c!==void 0&&c<=0||o===`$gte`&&l&&c!==void 0&&c<0||o===`$lt`&&l&&e!==void 0&&e>=0||o===`$lte`&&l&&e!==void 0&&e>0)return!0;if(o===`$eq`){let e=pg(s,t,r,i),a=pg(s,n,r,i);if(e!==void 0&&e<0||a!==void 0&&a>0)return!0}if(o===`$ne`&&!a&&ig(t,n,r)&&ig(t,s,r)||o===`$in`&&Array.isArray(s)&&s.every(e=>{let a=pg(e,t,r,i),o=pg(e,n,r,i);return a!==void 0&&a<0||o!==void 0&&o>0})||o===`$nin`&&!a&&Array.isArray(s)&&ig(t,n,r)&&s.some(e=>ig(t,e,r)))return!0}return!1}function pg(e,t,n,r){if(r?.type===`BYTE_ARRAY`)return typeof e!=`string`||typeof t!=`string`?void 0:mg(og.encode(e),og.encode(t));if(e instanceof Uint8Array||t instanceof Uint8Array)return!(e instanceof Uint8Array)||!(t instanceof Uint8Array)?void 0:mg(e,t);if(e<t)return-1;if(e>t)return 1;if(ig(e,t,n))return 0}function mg(e,t){let n=Math.min(e.length,t.length);for(let r=0;r<n;r++){if(e[r]<t[r])return-1;if(e[r]>t[r])return 1}return e.length<t.length?-1:+(e.length>t.length)}function hg(e,t){return lg({value:null},{value:e},t)}function gg(e,t,n,r=!0){if(!e)return;if(`$and`in e&&Array.isArray(e.$and)){let i;for(let a of e.$and)i=_g(i,gg(a,t,n,r));return i}if(`$or`in e&&Array.isArray(e.$or)){let i=[];for(let a of e.$or){let e=gg(a,t,n,r);if(!e)return;i=vg(i,e)}return i}if(`$nor`in e&&Array.isArray(e.$nor))return;let i;for(let[a,o]of Object.entries(e)){let e=t[a];if(!e)continue;let s=hg(o,r),c=[];for(let t=0;t<e.pageStarts.length;t++){let i=e.pageStarts[t],a=t+1<e.pageStarts.length?e.pageStarts[t+1]:n,l=e.nullCounts?.[t],u=s&&(l===void 0||l>0);if(!(!e.nullPages[t]&&!u&&fg(o,e.minValues[t],e.maxValues[t],r,e.element))){let e=c[c.length-1];e&&e[1]===i?e[1]=a:c.push([i,a])}}i=_g(i,c)}return i}function _g(e,t){if(!e)return t;if(!t)return e;let n=[],r=0,i=0;for(;r<e.length&&i<t.length;){let a=Math.max(e[r][0],t[i][0]),o=Math.min(e[r][1],t[i][1]);a<o&&n.push([a,o]),e[r][1]<t[i][1]?r++:i++}return n}function vg(e,t){let n=[],r=0,i=0;for(;r<e.length||i<t.length;){let a=i>=t.length||r<e.length&&e[r][0]<=t[i][0]?e[r++]:t[i++],o=n[n.length-1];o&&a[0]<=o[1]?o[1]=Math.max(o[1],a[1]):n.push([a[0],a[1]])}return n}function yg(e,t){let n=e;for(let e of t.split(`.`))n=n?.[e];return n}const bg=1<<21;function xg(e){let{metadata:t,rowStart:n=0,columns:r,useOffsetIndex:i=!1}=e;if(!t)throw Error(`parquetPlan requires metadata`);let a=[],o=[],s=[],c=Sg(e);for(let e of c.groups){let t=Cg({...e,columns:r,useOffsetIndex:i});a.push(...t.groups),o.push(...t.fetches),s.push(...t.indexes)}return o.push(...Og(s,0,bg)),{metadata:t,rowStart:n,rowEnd:c.rowEnd,columns:r,fetches:o,groups:a}}function Sg({metadata:e,rowStart:t=0,rowEnd:n=1/0,columns:r,filter:i,filterStrict:a=!0,bloomFiltersByGroup:o,schemaElements:s,pageRangesByGroup:c,pageLocationsByGroup:l}){if(!e)throw Error(`parquetPlan requires metadata`);let u=jh(e),d=mh(u),f=i?{...kg(u),...s}:s,p=[],m=0;for(let s=0;s<e.row_groups.length;s++){let u=e.row_groups[s],h=Number(u.num_rows),g=m+h;if(h>0&&g>t&&m<n&&!dg({rowGroup:u,physicalColumns:d,filter:i,strict:a,bloomFilters:o?.[s],schemaElements:f})){let e=Math.max(t-m,0),i=Math.min(n-m,h),a=c?.[s],o=l?.[s],d=a?a.map(([t,n])=>[Math.max(t,e),Math.min(n,i)]).filter(([e,t])=>e<t):[[e,i]];d.length>1&&(d=u.columns.every(e=>{let t=e.meta_data?.path_in_schema[0],n=e.meta_data?.path_in_schema.join(`.`);return r&&t&&!r.includes(t)?!0:!!(e.offset_index_offset&&e.offset_index_length)||!!(n&&o?.[n])})?wg(d,u,r,o):[[d[0][0],d[d.length-1][1]]]),d.length&&p.push({rowGroup:u,groupIndex:s,groupStart:m,groupRows:h,ranges:d,pageRanges:a,pageLocations:o})}m=g}return{groups:p,rowEnd:isFinite(n)?n:m}}function Cg({rowGroup:e,groupStart:t,groupRows:n,ranges:r,columns:i,useOffsetIndex:a=!1,pageRanges:o,pageLocations:s}){let c=[],l=[],u=[],d=r.length>1||r[0][0]>0||r[0][1]<n;for(let t of e.columns){let e=t.meta_data;if(t.file_path)throw Error(`parquet file_path not supported`);if(!e)throw Error(`parquet column metadata is undefined`);if(i&&!i.includes(e.path_in_schema[0]))continue;let n=e.dictionary_page_offset||e.data_page_offset,r=Number(n),l=Number(n+e.total_compressed_size),u=s?.[e.path_in_schema.join(`.`)];if(u&&d)c.push({columnMetadata:e,pageLocations:u,range:{startByte:r,endByte:l}});else if((a||o)&&t.offset_index_offset&&t.offset_index_length&&d){let r=Number(t.offset_index_offset);c.push({columnMetadata:e,offsetIndex:{startByte:r,endByte:r+t.offset_index_length},range:{startByte:Number(n),endByte:l}})}else c.push({columnMetadata:e,range:{startByte:r,endByte:l}})}let f=[],p;for(let e of c)`pageLocations`in e||(`offsetIndex`in e?u.push(e.offsetIndex):i?f.push(e.range):p&&e.range.endByte-p.startByte<=2097152?p.endByte=e.range.endByte:(p&&l.push(p),p={...e.range}));return p&&l.push(p),l.push(...Og(f,8192,bg)),{groups:r.map(([r,i])=>({chunks:c,rowGroup:e,groupStart:t,groupRows:n,selectStart:r,selectEnd:i})),fetches:l,indexes:u}}function wg(e,t,n,r){let i=t.columns.filter(e=>!n||n.includes(e.meta_data?.path_in_schema[0]||``)).map(e=>r?.[e.meta_data?.path_in_schema.join(`.`)||``]),a=[];for(let n of e){let e=a[a.length-1],r=e&&i.some(r=>{if(!r)return!0;let i=Tg(e,r,Number(t.num_rows)),a=Tg(n,r,Number(t.num_rows));return i[0]<=a[1]&&a[0]<=i[1]});e&&r?e[1]=n[1]:a.push([...n])}return a}function Tg([e,t],n,r){let i=1/0,a=-1/0;for(let o=0;o<n.length;o++){let s=Number(n[o].first_row_index);(o+1<n.length?Number(n[o+1].first_row_index):r)>e&&s<t&&(i=Math.min(i,o),a=o)}return[i,a]}async function Eg({file:e,metadata:t,filter:n,filterStrict:r=!0,rowStart:i=0,rowEnd:a=1/0}){let o=t.row_groups.map(()=>({})),s=tg(n);if(s.size===0)return o;let c=mh(jh(t)),l=[],u=0;if(t.row_groups.forEach((e,t)=>{let o=Number(e.num_rows),d=u+o,f=o>0&&d>i&&u<a;if(u=d,f&&!dg({rowGroup:e,physicalColumns:c,filter:n,strict:r}))for(let n of s){let r=c.indexOf(n);if(r===-1)continue;let i=e.columns[r]?.meta_data;if(!i?.bloom_filter_offset||!i.bloom_filter_length)continue;let a=Number(i.bloom_filter_offset),o=a+i.bloom_filter_length;l.push({rgIdx:t,colName:n,startByte:a,endByte:o})}}),l.length){let t=Ag(e,{fetches:Og(l,0,bg)});await Promise.all(l.map(async({rgIdx:e,colName:n,startByte:r,endByte:i})=>{let a=await t.slice(r,i),s=$h({view:new DataView(a),offset:0});s&&(o[e][n]=s)}))}return o}async function Dg({file:e,metadata:t,filter:n,filterStrict:r=!0,rowStart:i=0,rowEnd:a=1/0,columns:o,bloomFiltersByGroup:s,schemaElements:c,parsers:l}){let u=t.row_groups.map(()=>void 0),d=t.row_groups.map(()=>({}));if(n&&`$nor`in n&&Array.isArray(n.$nor))return{pageRangesByGroup:u,pageLocationsByGroup:d};let f=sg(n);if(!f.length)return{pageRangesByGroup:u,pageLocationsByGroup:d};let p=jh(t),m=mh(p),h={...kg(p),...c},g=[],_=[],v=[],y=0;if(t.row_groups.forEach((e,t)=>{let c=Number(e.num_rows),u=y+c,p=c>0&&u>i&&y<a;if(y=u,!p||dg({rowGroup:e,physicalColumns:m,filter:n,strict:r,bloomFilters:s?.[t],schemaElements:h}))return;let b={},x=0,S=new Set,C=!1;for(let n of f){let r=m.indexOf(n);if(r===-1)continue;let i=e.columns[r];if(!i?.meta_data||!i.column_index_offset||!i.column_index_length||!i.offset_index_offset||!i.offset_index_length)continue;let a=h[n];if(!a)continue;C=!0,S.add(n);let o=Number(i.column_index_offset),s=Number(i.offset_index_offset),c=o+i.column_index_length,u=s+i.offset_index_length;g.push({startByte:o,endByte:c},{startByte:s,endByte:u}),x++,_.push(async e=>{let[r,i]=await Promise.all([e.slice(o,c),e.slice(s,u)]),f=Ih({view:new DataView(r),offset:0},a,l),p=Lh({view:new DataView(i),offset:0});d[t][n]=p.page_locations,b[n]={minValues:f.min_values,maxValues:f.max_values,nullPages:f.null_pages,nullCounts:f.null_counts,pageStarts:p.page_locations.map(e=>Number(e.first_row_index)),element:a}})}if(C)for(let n of e.columns){let e=n.meta_data;if(!e)continue;let r=e.path_in_schema[0],i=e.path_in_schema.join(`.`);if(o&&!o.includes(r)||S.has(i)||!n.offset_index_offset||!n.offset_index_length)continue;S.add(i);let a=Number(n.offset_index_offset),s=a+n.offset_index_length;g.push({startByte:a,endByte:s}),x++,_.push(async e=>{let n=await e.slice(a,s),r=Lh({view:new DataView(n),offset:0});d[t][i]=r.page_locations})}x&&v.push({rgIdx:t,groupRows:c,columnPages:b})}),_.length){let t=Ag(e,{fetches:Og(g)});await Promise.all(_.map(e=>e(t)));for(let{rgIdx:e,groupRows:t,columnPages:i}of v)u[e]=gg(n,i,t,r)}return{pageRangesByGroup:u,pageLocationsByGroup:d}}function Og(e,t=0,n=1/0){let r=e.map(e=>({...e})).sort((e,t)=>e.startByte-t.startByte||e.endByte-t.endByte),i=[];for(let e of r){let r=i[i.length-1];r&&e.startByte<=r.endByte+t&&Math.max(r.endByte,e.endByte)-r.startByte<=n?r.endByte=Math.max(r.endByte,e.endByte):i.push(e)}return i}function kg(e){let t={};function n(e){if(e.children.length)for(let t of e.children)n(t);else t[e.path.join(`.`)]=e.element}return n(e),t}function Ag(e,{fetches:t}){let n=t.map(({startByte:t,endByte:n})=>{try{return e.slice(t,n)}catch(e){return Promise.reject(e)}});return{byteLength:e.byteLength,slice(r,i=e.byteLength){let a=t.findIndex(({startByte:e,endByte:t})=>e<=r&&i<=t);if(a<0)return e.slice(r,i);if(t[a].startByte!==r||t[a].endByte!==i){let e=r-t[a].startByte,o=i-t[a].startByte;return n[a]instanceof Promise?n[a].then(t=>t.slice(e,o)):n[a].slice(e,o)}else return n[a]}}}const jg=new TextDecoder(`utf-8`,{ignoreBOM:!0}),Mg=new WeakMap;function Ng(e,t=ah){if(Array.isArray(e))return e.map(e=>Ng(e,t));if(typeof e!=`object`)return e;if(`metadata`in e){let n=Ig(e.metadata),r=e.typed_value&&Pg(e.typed_value,n,t),i=e.value&&Rg(Fg(e.value),n,t);return r&&i?{...i,...r}:r??i}return e}function Pg(e,t,n){if(e instanceof Date)return e;if(e&&typeof e==`object`&&!Array.isArray(e)&&!(e instanceof Uint8Array)){if(`typed_value`in e&&e.typed_value!==null&&e.typed_value!==void 0)return Pg(e.typed_value,t,n);if(`value`in e&&e.value instanceof Uint8Array)return Rg(Fg(e.value),t,n);if(`typed_value`in e||`value`in e)return null;let r={};for(let[i,a]of Object.entries(e))t.dictionary.includes(i)&&(r[i]=Pg(a,t,n));return r}return e instanceof Uint8Array?Rg(Fg(e),t,n):Array.isArray(e)?e.map(e=>Pg(e,t,n)):e}function Fg(e){return{view:new DataView(e.buffer,e.byteOffset,e.byteLength),offset:0}}function Ig(e){let t=Mg.get(e.buffer);t||(t=new Map,Mg.set(e.buffer,t));let n=`${e.byteOffset}:${e.byteLength}`,r=t.get(n);if(r)return r;let i=Fg(e),a=i.view.getUint8(i.offset++),o=a&15;if(o!==1)throw Error(`parquet unsupported variant metadata version: ${o}`);let s=(a>>4&1)==1,c=(a>>6&3)+1,l=Lg(i,c),u=Array(l+1);for(let e=0;e<u.length;e++)u[e]=Lg(i,c);let d=i.offset,f=Array(l);for(let t=0;t<l;t++){let n=u[t],r=u[t+1],i=new Uint8Array(e.buffer,e.byteOffset+d+n,r-n);f[t]=jg.decode(i)}let p={dictionary:f,sorted:s};return t.set(n,p),p}function Lg(e,t){let n=0;for(let r=0;r<t;r++)n|=e.view.getUint8(e.offset+r)<<r*8;return e.offset+=t,n}function Rg(e,t,n){let r=e.view.getUint8(e.offset++),i=r&3,a=r>>2;if(i===0)return zg(e,a,n);if(i===2)return Bg(e,a,t,n);if(i===3)return Vg(e,a,t,n);let o=new Uint8Array(e.view.buffer,e.view.byteOffset+e.offset,a);return e.offset+=a,jg.decode(o)}function zg(e,t,n){switch(t){case 0:return null;case 1:return!0;case 2:return!1;case 3:{let t=e.view.getInt8(e.offset);return e.offset+=1,t}case 4:{let t=e.view.getInt16(e.offset,!0);return e.offset+=2,t}case 5:{let t=e.view.getInt32(e.offset,!0);return e.offset+=4,t}case 6:{let t=e.view.getBigInt64(e.offset,!0);return e.offset+=8,t}case 7:{let t=e.view.getFloat64(e.offset,!0);return e.offset+=8,t}case 8:return Hg(e,4);case 9:return Hg(e,8);case 10:return Hg(e,16);case 11:{let t=e.view.getInt32(e.offset,!0);return e.offset+=4,n.dateFromDays(t)}case 12:case 13:{let t=e.view.getBigInt64(e.offset,!0);return e.offset+=8,n.timestampFromMicroseconds(t)}case 14:{let t=e.view.getFloat32(e.offset,!0);return e.offset+=4,t}case 15:return Ug(e);case 16:{let t=Ug(e);return jg.decode(t)}case 17:{let t=e.view.getBigInt64(e.offset,!0);return e.offset+=8,t}case 18:case 19:{let t=e.view.getBigInt64(e.offset,!0);return e.offset+=8,n.timestampFromNanoseconds(t)}case 20:{let t=new Uint8Array(e.view.buffer,e.view.byteOffset+e.offset,16);e.offset+=16;let n=Array.from(t,e=>e.toString(16).padStart(2,`0`)).join(``);return`${n.slice(0,8)}-${n.slice(8,12)}-${n.slice(12,16)}-${n.slice(16,20)}-${n.slice(20)}`}default:throw Error(`parquet unsupported variant primitive type: ${t}`)}}function Bg(e,t,n,r){let i=(t&3)+1,a=(t>>2&3)+1,o=t>>4&1?Lg(e,4):e.view.getUint8(e.offset++),s=Array(o);for(let t=0;t<o;t++)s[t]=Lg(e,a);let c=Array(o+1);for(let t=0;t<c.length;t++)c[t]=Lg(e,i);let l={};for(let t=0;t<o;t++){let i=n.dictionary[s[t]];l[i]=Rg({view:e.view,offset:e.offset+c[t]},n,r)}return e.offset+=c[c.length-1],l}function Vg(e,t,n,r){let i=t&3,a=t>>2&1,o=i+1,s=Lg(e,a?4:1),c=Array(s+1);for(let t=0;t<c.length;t++)c[t]=Lg(e,o);let l=e.offset,u=Array(s);for(let t=0;t<s;t++)u[t]=Rg({view:e.view,offset:l+c[t]},n,r);return e.offset=l+c[c.length-1],u}function Hg(e,t){let n=e.view.getUint8(e.offset);e.offset+=1;let r;if(t===4)r=BigInt(e.view.getInt32(e.offset,!0)),e.offset+=4;else if(t===8)r=e.view.getBigInt64(e.offset,!0),e.offset+=8;else{let t=e.view.getBigUint64(e.offset,!0);r=e.view.getBigInt64(e.offset+8,!0)<<64n|t,e.offset+=16}return Number(r)/10**n}function Ug(e){let t=e.view.getUint32(e.offset,!0);e.offset+=4;let n=new Uint8Array(e.view.buffer,e.view.byteOffset+e.offset,t);return e.offset+=t,n}function Wg(e,t,n,r,i){let a=gh(i);if(!t?.length&&!n.length){if(!a||!r.length)return r;t=Array(r.length).fill(a)}let o=t?.length||n.length,s=i.map(({element:e})=>e.repetition_type),c=0,l=[e],u=e,d=0,f=0,p=0;if(n[0])for(;d<s.length-2&&p<n[0];)d++,s[d]!==`REQUIRED`&&(u=u.at(-1),l.push(u),f++),s[d]===`REPEATED`&&p++;for(let e=0;e<o;e++){let i=t?.length?t[e]:a,o=n[e];for(;d&&(o<p||s[d]!==`REPEATED`);)s[d]!==`REQUIRED`&&(l.pop(),f--),s[d]===`REPEATED`&&p--,d--;for(u=l.at(-1);(d<s.length-2||s[d+1]===`REPEATED`)&&(f<i||s[d+1]===`REQUIRED`);){if(d++,s[d]!==`REQUIRED`){let e=[];u.push(e),u=e,l.push(e),f++}s[d]===`REPEATED`&&p++}i===a?u.push(r[c++]):d===s.length-2?u.push(s[d+1]===`REPEATED`?[]:null):u.push([])}if(!e.length)for(let e=0;e<a;e++){let e=[];u.push(e),u=e}return e}function Gg(e,t,n,r=0){let i=t.path.join(`.`),a=t.element.repetition_type===`OPTIONAL`,o=a?r+1:r;if(_h(t)){let s=t.children[0],c=o;s.children.length===1&&(s=s.children[0],c++),Gg(e,s,n,c);let l=s.path.join(`.`),u=e.get(l);if(!u)throw Error(`parquet list column missing values`);a&&Kg(u,r),e.set(i,u),e.delete(l);return}if(vh(t)){let s=t.children[0].element.name;Gg(e,t.children[0].children[0],n,o+1),Gg(e,t.children[0].children[1],n,o+1);let c=e.get(`${i}.${s}.key`),l=e.get(`${i}.${s}.value`);if(!c)throw Error(`parquet map column missing keys`);if(!l)throw Error(`parquet map column missing values`);if(c.length!==l.length)throw Error(`parquet map column key/value length mismatch`);let u=qg(c,l,o);a&&Kg(u,r),e.delete(`${i}.${s}.key`),e.delete(`${i}.${s}.value`),e.set(i,u);return}if(t.children.length){let o=t.element.repetition_type===`REQUIRED`?r:r+1,s={};for(let r of t.children){Gg(e,r,n,o);let t=e.get(r.path.join(`.`));if(!t)throw Error(`parquet struct missing child data`);s[r.element.name]=t}for(let n of t.children)e.delete(n.path.join(`.`));let c=Jg(s,o);t.element.logical_type?.type===`VARIANT`&&(c=Ng(c,n)),a&&Kg(c,r),e.set(i,c)}}function Kg(e,t){for(let n=0;n<e.length;n++)t?Kg(e[n],t-1):e[n]=e[n].length?e[n][0]:null}function qg(e,t,n){let r=[];for(let i=0;i<e.length;i++)if(n)r.push(qg(e[i],t[i],n-1));else if(e[i]){let n={};for(let r=0;r<e[i].length;r++){let a=t[i][r];n[e[i][r]]=a===void 0?null:a}r.push(n)}else r.push(void 0);return r}function Jg(e,t){let n=Object.keys(e),r=e[n[0]]?.length,i=[];for(let a=0;a<r;a++){let o={};for(let t of n){if(e[t].length!==r)throw Error(`parquet struct parsing error`);o[t]=e[t][a]}t?i.push(Jg(o,t-1)):i.push(o)}return i}const Yg=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,0xe8d4a51000,0x9184e72a000,0x5af3107a4000,0x38d7ea4c68000,0x2386f26fc10000,0x16345785d8a0000,0xde0b6b3a7640000],Xg=[1,.1,.01,.001,1e-4,1e-5,1e-6,1e-7,1e-8,1e-9,1e-10,1e-11,1e-12,1e-13,1e-14,1e-15,1e-16,1e-17,1e-18],Zg=Yg.slice(0,11).map(Math.fround),Qg=Xg.slice(0,11).map(Math.fround);function $g(e,t,n){if(n===`FLOAT`)return t_(e,t);if(n===`DOUBLE`)return n_(e,t);throw Error(`ALP encoding unsupported type: ${n}`)}function e_(e){let{view:t}=e,n=t.getUint8(e.offset++);if(n!==0)throw Error(`ALP unsupported compression mode: ${n}`);let r=t.getUint8(e.offset++);if(r!==0)throw Error(`ALP unsupported integer encoding: ${r}`);let i=t.getUint8(e.offset++);if(i<3||i>15)throw Error(`ALP invalid log_vector_size: ${i}`);let a=1<<i,o=t.getInt32(e.offset,!0);e.offset+=4;let s=Math.ceil(o/a),c=e.offset;return e.offset+=s*4,{vectorSize:a,numElements:o,numVectors:s,offsetArrayStart:c}}function t_(e,t){let{view:n}=e,{vectorSize:r,numElements:i,numVectors:a,offsetArrayStart:o}=e_(e);if(i!==t)throw Error(`ALP num_elements ${i} does not match expected ${t}`);let s=new Float32Array(t),c=new Uint8Array(s.buffer);for(let t=0;t<a;t++){e.offset=o+n.getUint32(o+t*4,!0);let a=t*r,l=Math.min(r,i-a),u=n.getUint8(e.offset++),d=n.getUint8(e.offset++),f=n.getUint16(e.offset,!0);e.offset+=2;let p=n.getInt32(e.offset,!0);e.offset+=4;let m=i_(e,l,n.getUint8(e.offset++)),h=Zg[d],g=Qg[u];for(let e=0;e<l;e++){let t=m[e]+p|0;s[a+e]=Math.fround(Math.fround(t)*h)*g}r_(e,f,4,c,a)}return s}function n_(e,t){let{view:n}=e,{vectorSize:r,numElements:i,numVectors:a,offsetArrayStart:o}=e_(e);if(i!==t)throw Error(`ALP num_elements ${i} does not match expected ${t}`);let s=new Float64Array(t),c=new Uint8Array(s.buffer);for(let t=0;t<a;t++){e.offset=o+n.getUint32(o+t*4,!0);let a=t*r,l=Math.min(r,i-a),u=n.getUint8(e.offset++),d=n.getUint8(e.offset++),f=n.getUint16(e.offset,!0);e.offset+=2;let p=n.getBigInt64(e.offset,!0);e.offset+=8;let m=n.getUint8(e.offset++),h=Yg[d],g=Xg[u],_=Number(p);if(m<=32&&Number.isSafeInteger(_)){let t=i_(e,l,m);for(let e=0;e<l;e++)s[a+e]=(t[e]+_)*h*g}else{let t=a_(e,l,m);for(let e=0;e<l;e++){let n=BigInt.asIntN(64,t[e]+p);s[a+e]=Number(n)*h*g}}r_(e,f,8,c,a)}return s}function r_(e,t,n,r,i){if(!t)return;let{view:a}=e,o=e.offset,s=o+t*2,c=new Uint8Array(a.buffer,a.byteOffset+s,t*n);for(let e=0;e<t;e++){let t=(i+a.getUint16(o+e*2,!0))*n;r.set(c.subarray(e*n,(e+1)*n),t)}e.offset=s+t*n}function i_(e,t,n){let r=new Uint32Array(t);if(!n)return r;let{view:i}=e,a=e.offset,o=2**n,s=0;for(let e=0;e<t;e++){let t=a+(s>>>3),c=s&7,l=i.getUint8(t++)>>>c,u=8-c;for(;u<n;)l+=i.getUint8(t++)*2**u,u+=8;r[e]=l%o,s+=n}return e.offset=a+Math.ceil(t*n/8),r}function a_(e,t,n){let r=new BigUint64Array(t);if(!n)return r;let{view:i}=e,a=e.offset,o=(1n<<BigInt(n))-1n,s=0n,c=0,l=a;for(let e=0;e<t;e++){for(;c<n;)s|=BigInt(i.getUint8(l++))<<BigInt(c),c+=8;r[e]=s&o,s>>=BigInt(n),c-=n}return e.offset=a+Math.ceil(t*n/8),r}function o_(e,t,n){if(n instanceof Int32Array){s_(e,t,n);return}let r=Sh(e),i=Sh(e);Sh(e);let a=Th(e),o=0;n[o++]=a;let s=r/i;for(;o<t;){let r=Th(e),c=new Uint8Array(i);for(let t=0;t<i;t++)c[t]=e.view.getUint8(e.offset++);for(let l=0;l<i&&o<t;l++){let i=c[l];if(i){let c=0,l=s,u=(1n<<BigInt(i))-1n;for(;l&&o<t;){let t=BigInt(e.view.getUint32(e.offset,!0)>>>c)&u;for(c+=i;c>=32;)c-=32,e.offset+=4,c&&(t|=BigInt(e.view.getUint32(e.offset,!0))<<BigInt(i-c)&u);let s=r+t;a+=s,n[o++]=a,l--}l&&(e.offset+=Math.ceil((l*i+c)/8))}else for(let e=0;e<s&&o<t;e++)a+=r,n[o++]=a}}}function s_(e,t,n){let r=Sh(e),i=Sh(e);Sh(e);let a=wh(e),o=0;n[o++]=a;let s=r/i,{view:c}=e;for(;o<t;){let r=c_(e),l=e.offset,u=l+i;for(let e=0;e<i&&o<t;e++){let i=c.getUint8(l+e),d=u+s*i/8,f=0;for(let e=0;e<s&&o<t;e++){let e=0,t=0;for(;t<i;){let n=Math.min(8-f,i-t);t<32&&(e|=(c.getUint8(u)>>>f&(1<<n)-1)<<t),t+=n,f+=n,f===8&&(f=0,u++)}a=a+r+e|0,n[o++]=a}u=d}e.offset=u}}function c_(e){let t=e.offset,n=Sh(e),r=e.offset-t===5?e.view.getUint8(t+4)>>>4&1:0;return(n>>>1|r<<31)^-(n&1)}function l_(e,t,n){let r=new Int32Array(t);o_(e,t,r);for(let i=0;i<t;i++)n[i]=new Uint8Array(e.view.buffer,e.view.byteOffset+e.offset,r[i]),e.offset+=r[i]}function u_(e,t,n){let r=new Int32Array(t);o_(e,t,r);let i=new Int32Array(t);o_(e,t,i);for(let a=0;a<t;a++){let t=new Uint8Array(e.view.buffer,e.view.byteOffset+e.offset,i[a]);r[a]?(n[a]=new Uint8Array(r[a]+i[a]),n[a].set(n[a-1].subarray(0,r[a])),n[a].set(t,r[a])):n[a]=t,e.offset+=i[a]}}function d_(e,t,n,r){r===void 0&&(r=e.view.getUint32(e.offset,!0),e.offset+=4);let i=e.offset,a=0;for(;a<n.length;){let r=Sh(e);if(r&1)a=p_(e,r,t,n,a);else{let i=r>>>1;f_(e,i,t,n,a),a+=i}}e.offset=i+r}function f_(e,t,n,r,i){let a=n+7>>3,o=0;for(let t=0;t<a;t++)o|=e.view.getUint8(e.offset++)<<(t<<3);for(let e=0;e<t;e++)r[i+e]=o}function p_(e,t,n,r,i){let a=t>>1<<3,o=(1<<n)-1,s=0;if(e.offset<e.view.byteLength)s=e.view.getUint8(e.offset++);else if(o)throw Error(`parquet bitpack offset ${e.offset} out of range`);let c=8,l=0;for(;a;)l>8?(l-=8,c-=8,s>>>=8):c-l<n?(s|=e.view.getUint8(e.offset)<<c,e.offset++,c+=8):(i<r.length&&(r[i++]=s>>l&o),a--,l+=n);return i}function m_(e,t,n,r){let i=h_(n,r),a=new Uint8Array(t*i);for(let n=0;n<i;n++)for(let r=0;r<t;r++)a[r*i+n]=e.view.getUint8(e.offset++);if(n===`FLOAT`)return new Float32Array(a.buffer);if(n===`DOUBLE`)return new Float64Array(a.buffer);if(n===`INT32`)return new Int32Array(a.buffer);if(n===`INT64`)return new BigInt64Array(a.buffer);if(n===`FIXED_LEN_BYTE_ARRAY`){let e=Array(t);for(let n=0;n<t;n++)e[n]=a.subarray(n*i,(n+1)*i);return e}throw Error(`parquet byte_stream_split unsupported type: ${n}`)}function h_(e,t){switch(e){case`INT32`:case`FLOAT`:return 4;case`INT64`:case`DOUBLE`:return 8;case`FIXED_LEN_BYTE_ARRAY`:if(!t)throw Error(`parquet byteWidth missing type_length`);return t;default:throw Error(`parquet unsupported type: ${e}`)}}function g_(e,t,n,r){if(n===0)return[];if(t===`BOOLEAN`)return __(e,n);if(t===`INT32`)return v_(e,n);if(t===`INT64`)return y_(e,n);if(t===`INT96`)return b_(e,n);if(t===`FLOAT`)return x_(e,n);if(t===`DOUBLE`)return S_(e,n);if(t===`BYTE_ARRAY`)return C_(e,n);if(t===`FIXED_LEN_BYTE_ARRAY`){if(!r)throw Error(`parquet missing fixed length`);return w_(e,n,r)}else throw Error(`parquet unhandled type: ${t}`)}function __(e,t){let n=Array(t);for(let r=0;r<t;r++){let t=e.offset+(r/8|0),i=r%8;n[r]=(e.view.getUint8(t)&1<<i)!=0}return e.offset+=Math.ceil(t/8),n}function v_(e,t){let n=(e.view.byteOffset+e.offset)%4?new Int32Array(T_(e.view.buffer,e.view.byteOffset+e.offset,t*4)):new Int32Array(e.view.buffer,e.view.byteOffset+e.offset,t);return e.offset+=t*4,n}function y_(e,t){let n=(e.view.byteOffset+e.offset)%8?new BigInt64Array(T_(e.view.buffer,e.view.byteOffset+e.offset,t*8)):new BigInt64Array(e.view.buffer,e.view.byteOffset+e.offset,t);return e.offset+=t*8,n}function b_(e,t){let n=Array(t);for(let r=0;r<t;r++){let t=e.view.getBigInt64(e.offset+r*12,!0),i=e.view.getInt32(e.offset+r*12+8,!0);n[r]=BigInt(i)<<64n|t}return e.offset+=t*12,n}function x_(e,t){let n=(e.view.byteOffset+e.offset)%4?new Float32Array(T_(e.view.buffer,e.view.byteOffset+e.offset,t*4)):new Float32Array(e.view.buffer,e.view.byteOffset+e.offset,t);return e.offset+=t*4,n}function S_(e,t){let n=(e.view.byteOffset+e.offset)%8?new Float64Array(T_(e.view.buffer,e.view.byteOffset+e.offset,t*8)):new Float64Array(e.view.buffer,e.view.byteOffset+e.offset,t);return e.offset+=t*8,n}function C_(e,t){let n=Array(t);for(let r=0;r<t;r++){let t=e.view.getUint32(e.offset,!0);e.offset+=4,n[r]=new Uint8Array(e.view.buffer,e.view.byteOffset+e.offset,t),e.offset+=t}return n}function w_(e,t,n){let r=Array(t);for(let i=0;i<t;i++)r[i]=new Uint8Array(e.view.buffer,e.view.byteOffset+e.offset,n),e.offset+=n;return r}function T_(e,t,n){let r=new ArrayBuffer(n);return new Uint8Array(r).set(new Uint8Array(e,t,n)),r}const E_=[0,255,65535,16777215,4294967295];function D_(e,t,n,r,i){for(let a=0;a<i;a++)n[r+a]=e[t+a]}function O_(e,t){let n=e.byteLength,r=t.byteLength,i=0,a=0;for(;i<n;){let t=e[i];if(i++,t<128)break}if(r&&i>=n)throw Error(`invalid snappy length header`);for(;i<n;){let r=e[i],o=0;if(i++,i>=n)throw Error(`missing eof marker`);if(r&3){let s=0;switch(r&3){case 1:o=(r>>>2&7)+4,s=e[i]+(r>>>5<<8),i++;break;case 2:if(n<=i+1)throw Error(`snappy error end of input`);o=(r>>>2)+1,s=e[i]+(e[i+1]<<8),i+=2;break;case 3:if(n<=i+3)throw Error(`snappy error end of input`);o=(r>>>2)+1,s=e[i]+(e[i+1]<<8)+(e[i+2]<<16)+(e[i+3]<<24),i+=4;break;default:break}if(s===0||isNaN(s))throw Error(`invalid offset ${s} pos ${i} inputLength ${n}`);if(s>a)throw Error(`cannot copy from before start of buffer`);D_(t,a-s,t,a,o),a+=o}else{let o=(r>>>2)+1;if(o>60){if(i+3>=n)throw Error(`snappy error literal pos + 3 >= inputLength`);let t=o-60;o=e[i]+(e[i+1]<<8)+(e[i+2]<<16)+(e[i+3]<<24),o=(o&E_[t])+1,i+=t}if(i+o>n)throw Error(`snappy error literal exceeds input length`);D_(e,i,t,a,o),i+=o,a+=o}}if(a!==r)throw Error(`premature end of input`)}function k_(e,t,{type:n,element:r,schemaPath:i}){let a=new DataView(e.buffer,e.byteOffset,e.byteLength),o={view:a,offset:0},s,c=A_(o,t,i),{definitionLevels:l,numNulls:u}=j_(o,t,i),d=t.num_values-u;if(t.encoding===`PLAIN`)s=g_(o,n,d,r.type_length);else if(t.encoding===`PLAIN_DICTIONARY`||t.encoding===`RLE_DICTIONARY`||t.encoding===`RLE`){let e=n===`BOOLEAN`?1:a.getUint8(o.offset++);e?(s=Array(d),n===`BOOLEAN`?(d_(o,e,s),s=s.map(e=>!!e)):d_(o,e,s,a.byteLength-o.offset)):s=new Uint8Array(d)}else if(t.encoding===`BYTE_STREAM_SPLIT`)s=m_(o,d,n,r.type_length);else if(t.encoding===`ALP`)s=$g(o,d,n);else if(t.encoding===`DELTA_BINARY_PACKED`)s=n===`INT32`?new Int32Array(d):new BigInt64Array(d),o_(o,d,s);else if(t.encoding===`DELTA_LENGTH_BYTE_ARRAY`)s=Array(d),l_(o,d,s);else if(t.encoding===`DELTA_BYTE_ARRAY`)s=Array(d),u_(o,d,s);else throw Error(`parquet unsupported encoding: ${t.encoding}`);return{definitionLevels:l,repetitionLevels:c,dataPage:s}}function A_(e,t,n){if(n.length>1){let r=hh(n);if(r){let n=Array(t.num_values);return d_(e,I_(r),n),n}}return[]}function j_(e,t,n){let r=gh(n);if(!r)return{definitionLevels:[],numNulls:0};let i=Array(t.num_values);d_(e,I_(r),i);let a=t.num_values;for(let e of i)e===r&&a--;return a===0&&(i.length=0),{definitionLevels:i,numNulls:a}}function M_(e,t,n,r){let i,a=r?.[n];if(n===`UNCOMPRESSED`)i=e;else if(a)i=a(e,t);else if(n===`SNAPPY`)i=new Uint8Array(t),O_(e,i);else throw Error(`parquet unsupported compression codec: ${n}`);if(i?.length!==t)throw Error(`parquet decompressed page length ${i?.length} does not match header ${t}`);return i}function N_(e,t,n){let r={view:new DataView(e.buffer,e.byteOffset,e.byteLength),offset:0},{type:i,element:a,schemaPath:o,codec:s,compressors:c}=n,l=t.data_page_header_v2;if(!l)throw Error(`parquet data page header v2 is undefined`);let u=P_(r,l,o);r.offset=l.repetition_levels_byte_length;let d=F_(r,l,o),f=t.uncompressed_page_size-l.definition_levels_byte_length-l.repetition_levels_byte_length,p=e.subarray(r.offset);l.is_compressed!==!1&&f&&(p=M_(p,f,s,c));let m=new DataView(p.buffer,p.byteOffset,p.byteLength),h={view:m,offset:0},g,_=l.num_values-l.num_nulls;if(l.encoding===`PLAIN`)g=g_(h,i,_,a.type_length);else if(l.encoding===`RLE`)g=Array(_),d_(h,1,g),g=g.map(e=>!!e);else if(l.encoding===`PLAIN_DICTIONARY`||l.encoding===`RLE_DICTIONARY`){let e=m.getUint8(h.offset++);g=Array(_),d_(h,e,g,f-1)}else if(l.encoding===`DELTA_BINARY_PACKED`)g=i===`INT32`?new Int32Array(_):new BigInt64Array(_),o_(h,_,g);else if(l.encoding===`DELTA_LENGTH_BYTE_ARRAY`)g=Array(_),l_(h,_,g);else if(l.encoding===`DELTA_BYTE_ARRAY`)g=Array(_),u_(h,_,g);else if(l.encoding===`BYTE_STREAM_SPLIT`)g=m_(h,_,i,a.type_length);else if(l.encoding===`ALP`)g=$g(h,_,i);else throw Error(`parquet unsupported encoding: ${l.encoding}`);return{definitionLevels:d,repetitionLevels:u,dataPage:g}}function P_(e,t,n){let r=hh(n);if(!r)return[];let i=Array(t.num_values);return d_(e,I_(r),i,t.repetition_levels_byte_length),i}function F_(e,t,n){let r=gh(n);if(r){let n=Array(t.num_values);return d_(e,I_(r),n,t.definition_levels_byte_length),n}}function I_(e){return 32-Math.clz32(e)}function L_(e,{groupStart:t,selectStart:n,selectEnd:r},i,a){let{pathInSchema:o,schemaPath:s}=i,c=yh(s),l=[],u,d,f=0,p=0,m=a&&(()=>{d&&a({pathInSchema:o,columnData:d,rowStart:t+f-d.length,rowEnd:t+f})});for(;(c?f<r:e.offset<e.view.byteLength-1)&&!(e.offset>=e.view.byteLength-1);){let t=z_(e);if(t.type===`DICTIONARY_PAGE`){let{data:n}=R_(e,t,i,u,void 0,0);n&&(u=sh(n,i))}else{let r=d?.length||0,a=R_(e,t,i,u,d,n-f);a.skipped?(l.length||(p+=a.skipped),f+=a.skipped):a.data&&d===a.data?f+=a.data.length-r:a.data&&a.data.length&&(m?.(),l.push(a.data),f+=a.data.length,d=a.data)}}return m?.(),{data:l,skipped:p}}function R_(e,t,n,r,i,a){let{type:o,element:s,schemaPath:c,codec:l,compressors:u}=n,d=new Uint8Array(e.view.buffer,e.view.byteOffset+e.offset,t.compressed_page_size);if(e.offset+=t.compressed_page_size,t.type===`DATA_PAGE`){let e=t.data_page_header;if(!e)throw Error(`parquet data page header is undefined`);if(a>e.num_values&&yh(c))return{skipped:e.num_values};let{definitionLevels:o,repetitionLevels:s,dataPage:f}=k_(M_(d,Number(t.uncompressed_page_size),l,u),e,n),p=oh(f,r,e.encoding,n);return{skipped:0,data:Wg(Array.isArray(i)?i:[],o,s,p,c)}}else if(t.type===`DATA_PAGE_V2`){let e=t.data_page_header_v2;if(!e)throw Error(`parquet data page header v2 is undefined`);if(a>e.num_rows)return{skipped:e.num_rows};let{definitionLevels:o,repetitionLevels:s,dataPage:l}=N_(d,t,n),u=oh(l,r,e.encoding,n);return{skipped:0,data:Wg(Array.isArray(i)?i:[],o,s,u,c)}}else if(t.type===`DICTIONARY_PAGE`){let e=t.dictionary_page_header;if(!e)throw Error(`parquet dictionary page header is undefined`);let n=M_(d,Number(t.uncompressed_page_size),l,u);return{skipped:0,data:g_({view:new DataView(n.buffer,n.byteOffset,n.byteLength),offset:0},o,e.num_values,s.type_length)}}else throw Error(`parquet unsupported page type: ${t.type}`)}function z_(e){let t=bh(e);return{type:Ym[t.field_1],uncompressed_page_size:t.field_2,compressed_page_size:t.field_3,crc:t.field_4,data_page_header:t.field_5&&{num_values:t.field_5.field_1,encoding:Gm[t.field_5.field_2],definition_level_encoding:Gm[t.field_5.field_3],repetition_level_encoding:Gm[t.field_5.field_4],statistics:B_(t.field_5.field_5)},index_page_header:t.field_6,dictionary_page_header:t.field_7&&{num_values:t.field_7.field_1,encoding:Gm[t.field_7.field_2],is_sorted:t.field_7.field_3},data_page_header_v2:t.field_8&&{num_values:t.field_8.field_1,num_nulls:t.field_8.field_2,num_rows:t.field_8.field_3,encoding:Gm[t.field_8.field_4],definition_levels_byte_length:t.field_8.field_5,repetition_levels_byte_length:t.field_8.field_6,is_compressed:t.field_8.field_7===void 0?!0:t.field_8.field_7,statistics:B_(t.field_8.field_8)}}}function B_(e){return e&&{max:e.field_1,min:e.field_2,null_count:e.field_3,distinct_count:e.field_4,max_value:e.field_5,min_value:e.field_6,is_max_value_exact:e.field_7,is_min_value_exact:e.field_8}}function V_(e,{metadata:t},n){let r=[],i=jh(t),a=n.chunks.filter(e=>`pageLocations`in e||`offsetIndex`in e),o=Promise.all(a.map(async t=>{if(`pageLocations`in t)return H_(n,t,t.pageLocations);if(!(`offsetIndex`in t))throw Error(`parquet expected offset index`);let r=await e.file.slice(t.offsetIndex.startByte,t.offsetIndex.endByte),i=Lh({view:new DataView(r),offset:0}).page_locations;return H_(n,t,i)})).then(t=>{let n=t.flatMap(e=>e.fetches);return{file:Ag(e.file,{fetches:Og(n,0,bg)}),selections:t}}),s=0;for(let t of n.chunks){let{path_in_schema:a}=t.columnMetadata,c=ph(i,a),l={pathInSchema:a,element:c[c.length-1].element,schemaPath:c,...e,...t.columnMetadata,parsers:{...ah,...e.parsers}},{startByte:u,endByte:d}=t.range;if(`pageLocations`in t||`offsetIndex`in t){let t=s++;r.push({pathInSchema:a,data:o.then(({file:r,selections:i})=>U_({...e,file:r},n,i[t],l))})}else r.push({pathInSchema:a,data:Promise.resolve(e.file.slice(u,d)).then(t=>L_({view:new DataView(t),offset:0},n,l,e.onPage))})}return{groupStart:n.groupStart,groupRows:n.groupRows,selectStart:n.selectStart,selectEnd:n.selectEnd,asyncColumns:r}}function H_(e,t,n){let{data_page_offset:r,dictionary_page_offset:i}=t.columnMetadata,{selectStart:a,selectEnd:o}=e,{startByte:s,endByte:c}=t.range,l=-1,u=i||r<n[0].offset;for(let t=0;t<n.length;t++){let r=n[t],i=Number(r.first_row_index),u=t+1<n.length?Number(n[t+1].first_row_index):e.groupRows;l<0&&u>a&&(s=Number(r.offset),l=i),i<o&&(c=Number(r.offset)+r.compressed_page_size)}if(l<0&&(l=0),!u)return{skipped:l,fetches:[{startByte:s,endByte:c}]};if(!l)return{skipped:l,fetches:[{startByte:t.range.startByte,endByte:c}]};let d={startByte:t.range.startByte,endByte:Number(n[0].offset)};return{skipped:l,fetches:[d,{startByte:s,endByte:c}]}}async function U_(e,t,{skipped:n,fetches:r},i){let a;if(r.length>1){let[t,n]=r,i=t.endByte-t.startByte,[o,s]=await Promise.all([e.file.slice(t.startByte,t.endByte),e.file.slice(n.startByte,n.endByte)]),c=new Uint8Array(i+s.byteLength);c.set(new Uint8Array(o,0,i)),c.set(new Uint8Array(s),i),a=new DataView(c.buffer)}else a=new DataView(await e.file.slice(r[0].startByte,r[0].endByte));let{data:o,skipped:s}=L_({view:a,offset:0},n?{...t,groupStart:t.groupStart+n,selectStart:t.selectStart-n,selectEnd:t.selectEnd-n}:t,i,e.onPage);return{data:o,skipped:n+s}}async function W_({asyncColumns:e},t,n,r,i){let a=await Promise.all(e.map(e=>e.data.then(({skipped:e,data:t})=>({skipped:e,data:ag(t)})))),o=n-t;if(i===`object`){let n=Array(o);for(let r=0;r<o;r++){let i={};for(let n=0;n<e.length;n++){let{data:o,skipped:s}=a[n];i[e[n].pathInSchema[0]]=o[t+r-s]}n[r]=i}return n}let s=e.map(e=>e.pathInSchema[0]).filter(e=>!r||r.includes(e)),c=r??s,l=c.map(t=>e.findIndex(e=>e.pathInSchema[0]===t)),u=Array(o);for(let n=0;n<o;n++){let r=Array(e.length);for(let e=0;e<c.length;e++){let i=l[e];if(i<0)throw Error(`parquet column not found: ${c[e]}`);let{data:o,skipped:s}=a[i];r[e]=o[t+n-s]}u[n]=r}return u}function G_(e,t,n){let{asyncColumns:r}=e,i={...ah,...n},a=[];for(let n of t.children)if(n.children.length){let t=r.filter(e=>e.pathInSchema[0]===n.element.name);if(!t.length)continue;a.push({pathInSchema:n.path,data:(async()=>{let r=await Promise.all(t.map(e=>e.data)),a=new Map,o=r.map(({data:e})=>ag(e)),s=Math.max(e.selectStart??0,...r.map(e=>e.skipped)),c=Math.min(e.selectEnd??1/0,...r.map((e,t)=>e.skipped+o[t].length));for(let e=0;e<t.length;e++){let n=s-r[e].skipped,i=Math.max(0,c-s);a.set(t[e].pathInSchema.join(`.`),o[e].slice(n,n+i))}Gg(a,n,i);let l=a.get(n.element.name);if(!l)throw Error(`parquet column data not assembled`);return{data:[l],skipped:s}})()})}else{let e=r.find(e=>e.pathInSchema[0]===n.element.name);e&&a.push(e)}return{...e,asyncColumns:a}}async function K_(e){let t=await q_(e);return{options:t,plan:xg(t)}}async function q_(e){let t=e.metadata??await kh(e.file,e),n=jh(t).children.map(e=>e.element.name),r=cg(e.filter).filter(e=>!n.includes(e));if(r.length)throw Error(`parquet filter columns not found: ${r.join(`, `)}`);if(e.columns){let t=e.columns.filter(e=>!n.includes(e));if(t.length)throw Error(`parquet column not found: ${t[0]}`)}let i={...e,metadata:t};return i=await Y_(i),i=await X_(i),i}function J_(e,t){let n={...e,file:Ag(e.file,t)};return t.groups.map(e=>V_(n,t,e))}async function Y_(e){if(!e.useBloomFilters||!e.filter||!e.metadata)return e;let t=jh(e.metadata),n={};for(let e of t.children)n[e.element.name]=e.element;let r=await Eg({file:e.file,metadata:e.metadata,filter:e.filter,filterStrict:e.filterStrict,rowStart:e.rowStart,rowEnd:e.rowEnd});return{...e,bloomFiltersByGroup:r,schemaElements:n}}async function X_(e){if(!e.usePageIndex||!e.filter||!e.metadata)return e;let{pageRangesByGroup:t,pageLocationsByGroup:n}=await Dg({file:e.file,metadata:e.metadata,filter:e.filter,filterStrict:e.filterStrict,rowStart:e.rowStart,rowEnd:e.rowEnd,columns:e.columns,bloomFiltersByGroup:e.bloomFiltersByGroup,schemaElements:e.schemaElements,parsers:e.parsers});return{...e,pageRangesByGroup:t,pageLocationsByGroup:n}}const Z_=Symbol(`rowIndex`);async function Q_(e){e.metadata??=await kh(e.file,e);let{rowStart:t=0,rowEnd:n,columns:r,onChunk:i,onComplete:a,rowFormat:o,filter:s,filterStrict:c=!0}=e;if(s&&o!==`object`)throw Error(`parquet filter requires rowFormat: "object"`);if(e.includeRowIndex&&o!==`object`)throw Error(`parquet includeRowIndex requires rowFormat: "object"`);let l=cg(s),u=r;if(r&&l.length){let e=new Set(r),t=l.filter(t=>!e.has(t));t.length&&(u=[...r,...t])}let d=await K_(u===r?e:{...e,columns:u}),f=d.options,p=u!==r,m=J_(f,d.plan);if(!a&&!i){await $_(m);return}if(!f.metadata)throw Error(`parquet requires metadata`);let h=jh(f.metadata),g=m.map(t=>G_(t,h,e.parsers));if(i)for(let e of g)for(let t of e.asyncColumns)t.data.then(({data:n,skipped:r})=>{let a=e.groupStart+r;for(let e of n)i({columnName:t.pathInSchema[0],columnData:e,rowStart:a,rowEnd:a+e.length}),a+=e.length},()=>{});if(a){await $_(g);let i=[];for(let a of g){let d=a.selectStart??Math.max(t-a.groupStart,0),f=a.selectEnd??Math.min((n??1/0)-a.groupStart,a.groupRows),m=o===`object`?await W_(a,d,f,u,`object`):await W_(a,d,f,r,`array`);if(e.includeRowIndex)for(let e=0;e<m.length;e++)Object.defineProperty(m[e],Z_,{value:a.groupStart+d+e});if(s){for(let e of m)if(lg(e,s,c)){if(p&&r)for(let t of l)r.includes(t)||delete e[t];i.push(e)}}else rg(i,m)}a(i)}else await $_(g)}async function $_(e){let t=e.flatMap(e=>e.asyncColumns.map(e=>e.data)),n=(await Promise.allSettled(t)).find(e=>e.status===`rejected`);if(n)throw n.reason}function ev(){let e=tv();return(t,n)=>{let{memory:r,uncompress:i}=e.exports,a=68e3,o=a+t.byteLength,s=a+t.byteLength+n;if(r.buffer.byteLength<s){let e=64*1024,t=r.buffer.byteLength/e,n=Math.ceil(s/e)-t;r.grow(n)}let c=new Uint8Array(r.buffer);c.set(t,a);let l=i(a,t.byteLength,o);if(l===-1)throw Error(`invalid snappy length header`);if(l===-2)throw Error(`missing eof marker`);if(l===-3)throw Error(`premature end of input`);if(l)throw Error(`failed to uncompress data ${l}`);return c.slice(o,o+n)}}function tv(){let e=atob(nv),t=new Uint8Array(e.length);for(let n=0;n<e.length;n+=1)t[n]=e.charCodeAt(n);let n=new WebAssembly.Module(t);return new WebAssembly.Instance(n)}const nv=`AGFzbQEAAAABEANgAABgA39/fwF/YAF/AX8DBgUAAQEBAgUDAQACBj8KfwFBoIwEC38AQYAIC38AQaAMC38AQaAMC38AQaCMBAt/AEGACAt/AEGgjAQLfwBBgIAIC38AQQALfwBBAQsHwQEOBm1lbW9yeQIAEV9fd2FzbV9jYWxsX2N0b3JzAAAGbWVtY3B5AAEHbWVtbW92ZQACCnVuY29tcHJlc3MAAwxfX2Rzb19oYW5kbGUDAQpfX2RhdGFfZW5kAwILX19zdGFja19sb3cDAwxfX3N0YWNrX2hpZ2gDBA1fX2dsb2JhbF9iYXNlAwULX19oZWFwX2Jhc2UDBgpfX2hlYXBfZW5kAwcNX19tZW1vcnlfYmFzZQMIDF9fdGFibGVfYmFzZQMJCuASBQIAC8sBAQN/AkAgAkUNAAJAAkAgAkEHcSIDDQAgACEEIAIhBQwBCyAAIQQgAiEFA0AgBCABLQAAOgAAIARBAWohBCABQQFqIQEgBUF/aiEFIANBf2oiAw0ACwsgAkEISQ0AA0AgBCABLQAAOgAAIAQgAS0AAToAASAEIAEtAAI6AAIgBCABLQADOgADIAQgAS0ABDoABCAEIAEtAAU6AAUgBCABLQAGOgAGIAQgAS0ABzoAByAEQQhqIQQgAUEIaiEBIAVBeGoiBQ0ACwsgAAugAwEEfwJAIAAgAUYNAAJAAkAgACABSQ0AIAEgAmoiAyAASw0BCyACRQ0BAkACQCACQQdxIgMNACAAIQQgAiEFDAELIAAhBCACIQUDQCAEIAEtAAA6AAAgBEEBaiEEIAFBAWohASAFQX9qIQUgA0F/aiIDDQALCyACQQhJDQEDQCAEIAEtAAA6AAAgBCABLQABOgABIAQgAS0AAjoAAiAEIAEtAAM6AAMgBCABLQAEOgAEIAQgAS0ABToABSAEIAEtAAY6AAYgBCABLQAHOgAHIARBCGohBCABQQhqIQEgBUF4aiIFDQAMAgsLIAJFDQACQAJAIAJBA3EiBA0AIAAgAmohBiACIQUMAQsgAiEFA0AgBUF/aiIFIABqIgYgBSABaiIDLQAAOgAAIARBf2oiBA0ACwsgAkEESQ0AIAZBfGohASADQXxqIQQDQCABQQNqIARBA2otAAA6AAAgAUECaiAEQQJqLQAAOgAAIAFBAWogBEEBai0AADoAACABIAQtAAA6AAAgAUF8aiEBIARBfGohBCAFQXxqIgUNAAsLIAALswoBCX8jgICAgABBIGsiAySAgICAACADQQlqQgA3AAAgA0IANwIEIAMgA0EYajYCAEF/IQQCQCABRQ0AIAMgAUF/aiIFNgIcIAMgAEEBajYCGCAALAAAIgZB/wBxIQcCQCAGQX9KDQAgBUUNASADIAFBfmoiBTYCHCADIABBAmo2AhggACwAASIGQf8AcUEHdCAHciEHQX8hBCAGQX9KDQAgBUUNASADIAFBfWoiBTYCHCADIABBA2o2AhggACwAAiIGQf8AcUEOdCAHciEHQX8hBCAGQX9KDQAgBUUNASADIAFBfGoiBTYCHCADIABBBGo2AhggACwAAyIGQf8AcUEVdCAHciEHQX8hBCAGQX9KDQAgBUUNASADIAFBe2o2AhwgAyAAQQVqNgIYIAAsAAQiAUEASA0BIAFBHHQgB3IhBwsgAiAHaiEIAkACQCADEISAgIAADQAgAiEADAELIAMoAgQhASACIQADQAJAIAMoAgggAWtBBEoNACADIAE2AgQgAxCEgICAAEUNAiADKAIEIQELIAFBAWohBQJAAkAgAS0AACIGQQNxDQAgCCAAayEJIAMoAggiCiAFayEEIAZBAnYiC0EBaiEHAkAgBkE/Sw0AIARBEEkNACAJQRBIDQAgACABKAIBNgIAIAAgASgCBTYCBCAAIAEoAgk2AgggACABKAINNgIMIAAgB2ohACADKAIIIAUgB2oiAWtBBEoNAyADIAE2AgQgAxCEgICAAEUNBAwCCwJAAkAgBkHwAU8NACAFIQYMAQsgCiAFIAtBRWoiAWoiBmshBCABQQJ0QYCIgIAAaigCACAFKAIAcUEBaiEHCwJAIAcgBE0NAANAIAggAGsgBEkNBSAAIAYgBBCBgICAACEAIAMoAgAiASABKAIAIgkgAygCDCIFaiIGNgIAIAFBBGoiASABKAIAIgogBWsiATYCACADIAE2AgwgACAEaiEAIAFFDQUgAyAJIApqNgIIIAcgBGshByABIQQgByABSw0ACyAIIABrIQkLIAkgB0kNAyAAIAYgBxCBgICAACAHaiEAIAMoAgggBiAHaiIBa0EESg0CIAMgATYCBCADEISAgIAADQEMAwsgACACayAGQQF0QaCIgIAAai8BACIBQQt2IgpBAnRBgIiAgABqKAIAIAUoAgBxIAFBgA5xaiIHQX9qTQ0CIAggAGshBAJAAkAgAUH/AXEiCUEQSw0AIAdBCEkNACAEQRBJDQAgACAAIAdrIgEoAgA2AgAgACABKAIENgIEIAAgASgCCDYCCCAAIAFBDGooAgA2AgwMAQsCQAJAAkAgBCAJQQpqSQ0AIAAgB2shBCAAIQEgCSEGIAdBB0wNAQwCCyAEIAlJDQUgCUEBaiEEQQAgB2shByAAIQEDQCABIAEgB2otAAA6AAAgAUEBaiEBIARBf2oiBEEBSw0ADAMLCwNAIAEgBCgCADYCACABIAQoAgQ2AgQgBiAHayEGIAEgB2oiASAEayIHQQhIDQALCyAGQQFIDQAgBkEIaiEHA0AgASAEKAIANgIAIAEgBCgCBDYCBCABQQhqIQEgBEEIaiEEIAdBeGoiB0EISw0ACwsgACAJaiEAIAMoAgggBSAKaiIBa0EESg0BIAMgATYCBCADEISAgIAARQ0CCyADKAIEIQEMAAsLIAMoAgAiASABKAIEIAMoAgwiBGs2AgQgASAEIAEoAgBqNgIAAkAgAy0AEA0AQX4hBAwBC0EAQX0gCCAARhshBAsgA0EgaiSAgICAACAEC7YDAQd/AkAgACgCBCIBIAAoAggiAkcNACAAKAIAIgIgAigCACIDIAAoAgwiBGoiATYCACACQQRqIgIgAigCACICIARrIgU2AgAgACAFNgIMAkAgAiAERw0AIABBAToAEEEADwsgACADIAJqIgI2AggLAkACQAJAIAIgAWsiAiABLQAAQQF0QaCIgIAAai8BAEELdkEBaiIFTw0AIABBEWogASACEIKAgIAAIQYgACgCDCEEQQAhByAAQQA2AgwgACgCACIBIAEoAgQgBGs2AgQgASAEIAEoAgBqIgM2AgADQCABQQRqKAIAIgFFDQMgBiACaiADIAUgAmsiBCABIAQgAUkbIgQQgYCAgAAaIAAoAgAiASABKAIEIARrNgIEIAEgASgCACAEaiIDNgIAIAQgAmoiAiAFSQ0ACyAAIAY2AgQgACAGIAVqNgIIDAELAkAgAkEESw0AIAAgAEERaiABIAIQgoCAgAAiASACajYCCCAAIAE2AgQgACgCDCECIABBADYCDCAAKAIAIgEgASgCBCACazYCBCABIAIgASgCAGo2AgAMAQsgACABNgIEC0EBIQcLIAcLC6gEAQBBgAgLoAQAAAAA/wAAAP//AAD///8A/////wAAAAAAAAAAAAAAAAEABAgBEAEgAgAFCAIQAiADAAYIAxADIAQABwgEEAQgBQAICAUQBSAGAAkIBhAGIAcACggHEAcgCAALCAgQCCAJAAQJCRAJIAoABQkKEAogCwAGCQsQCyAMAAcJDBAMIA0ACAkNEA0gDgAJCQ4QDiAPAAoJDxAPIBAACwkQEBAgEQAEChEQESASAAUKEhASIBMABgoTEBMgFAAHChQQFCAVAAgKFRAVIBYACQoWEBYgFwAKChcQFyAYAAsKGBAYIBkABAsZEBkgGgAFCxoQGiAbAAYLGxAbIBwABwscEBwgHQAICx0QHSAeAAkLHhAeIB8ACgsfEB8gIAALCyAQICAhAAQMIRAhICIABQwiECIgIwAGDCMQIyAkAAcMJBAkICUACAwlECUgJgAJDCYQJiAnAAoMJxAnICgACwwoECggKQAEDSkQKSAqAAUNKhAqICsABg0rECsgLAAHDSwQLCAtAAgNLRAtIC4ACQ0uEC4gLwAKDS8QLyAwAAsNMBAwIDEABA4xEDEgMgAFDjIQMiAzAAYOMxAzIDQABw40EDQgNQAIDjUQNSA2AAkONhA2IDcACg43EDcgOAALDjgQOCA5AAQPORA5IDoABQ86EDogOwAGDzsQOyA8AAcPPBA8IAEICA89ED0gARAJDz4QPiABGAoPPxA/IAEgCw9AEEAgAGQEbmFtZQE9BQARX193YXNtX2NhbGxfY3RvcnMBBm1lbWNweQIHbWVtbW92ZQMKdW5jb21wcmVzcwQKcmVmaWxsX3RhZwcSAQAPX19zdGFja19wb2ludGVyCQoBAAcucm9kYXRhADIJcHJvZHVjZXJzAQxwcm9jZXNzZWQtYnkBDFVidW50dSBjbGFuZwsxNi4wLjYgKDE1KQAsD3RhcmdldF9mZWF0dXJlcwIrD211dGFibGUtZ2xvYmFscysIc2lnbi1leHQ=`,rv=4096;2*rv+32;const iv=2*rv-1,av=new Uint32Array([0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535,131071,262143,524287,1048575,2097151,4194303,8388607,16777215]);var ov=class{constructor(e){this.buf_=new Uint8Array(8224),this.input_=e,this.buf_ptr_=0,this.val_=0,this.pos_=0,this.bit_pos_=0,this.bit_end_pos_=0,this.eos_=0,this.reset()}static READ_SIZE=rv;static IBUF_MASK=iv;reset(){this.buf_ptr_=0,this.val_=0,this.pos_=0,this.bit_pos_=0,this.bit_end_pos_=0,this.eos_=0,this.readMoreInput();for(let e=0;e<4;e++)this.val_|=this.buf_[this.pos_]<<8*e,this.pos_++;return this.bit_end_pos_>0}readMoreInput(){if(!(this.bit_end_pos_>256))if(this.eos_){if(this.bit_pos_>this.bit_end_pos_)throw Error(`Unexpected end of input `+this.bit_pos_+` `+this.bit_end_pos_)}else{let e=this.buf_ptr_,t=this.input_.read(this.buf_,e,rv);if(t<0)throw Error(`Unexpected end of input`);if(t<rv){this.eos_=1;for(let n=0;n<32;n++)this.buf_[e+t+n]=0}if(e===0){for(let e=0;e<32;e++)this.buf_[(rv<<1)+e]=this.buf_[e];this.buf_ptr_=rv}else this.buf_ptr_=0;this.bit_end_pos_+=t<<3}}fillBitWindow(){for(;this.bit_pos_>=8;)this.val_>>>=8,this.val_|=this.buf_[this.pos_&iv]<<24,this.pos_++,this.bit_pos_=this.bit_pos_-8>>>0,this.bit_end_pos_=this.bit_end_pos_-8>>>0}readBits(e){32-this.bit_pos_<e&&this.fillBitWindow();let t=this.val_>>>this.bit_pos_&av[e];return this.bit_pos_+=e,t}};const sv=new Uint8Array([1,2,3,4,0,5,17,6,16,7,8,9,10,11,12,13,14,15]),cv=new Uint16Array([256,402,436,468,500,534,566,598,630,662,694,726,758,790,822,854,886,920,952,984,1016,1048,1080]);var Z=class{constructor(e,t){this.bits=e,this.value=t}};function lv(e,t){let n=1<<t-1;for(;e&n;)n>>=1;return(e&n-1)+n}function uv(e,t,n,r,i){do r-=n,e[t+r]=new Z(i.bits,i.value);while(r>0)}function dv(e,t,n){let r=1<<t-n;for(;t<15&&(r-=e[t],!(r<=0));)++t,r<<=1;return t-n}function fv(e,t,n,r,i){let a=t,o=new Int32Array(16),s=new Int32Array(16),c=new Int32Array(i);for(let e=0;e<i;e++)o[r[e]]++;s[1]=0;for(let e=1;e<15;e++)s[e+1]=s[e]+o[e];for(let e=0;e<i;e++)r[e]!==0&&(c[s[r[e]]++]=e);let l=n,u=1<<l,d=u;if(s[15]===1){for(let n=0;n<d;++n)e[t+n]=new Z(0,c[0]&65535);return d}let f=0,p=0;for(let r=1,i=2;r<=n;++r,i<<=1)for(;o[r]>0;--o[r]){let n=new Z(r&255,c[p++]&65535);uv(e,t+f,i,u,n),f=lv(f,r)}let m=d-1,h=-1;for(let r=n+1,i=2;r<=15;++r,i<<=1)for(;o[r]>0;--o[r]){(f&m)!==h&&(t+=u,l=dv(o,r,n),u=1<<l,d+=u,h=f&m,e[a+h]=new Z(l+n&255,t-a-h&65535));let s=new Z(r-n&255,c[p++]&65535);uv(e,t+(f>>n),i,u,s),f=lv(f,r)}return d}function pv(e,t,n,r){let i=new Uint8Array(e);r.readMoreInput();let a=r.readBits(2);if(a===1){let t=e-1,n=0,a=new Int32Array(4),o=r.readBits(2)+1;for(;t;)t>>=1,n++;for(let t=0;t<o;t++)a[t]=r.readBits(n)%e,i[a[t]]=2;switch(i[a[0]]=1,o){case 1:break;case 3:if(a[0]===a[1]||a[0]===a[2]||a[1]===a[2])throw Error(`[ReadHuffmanCode] invalid symbols`);break;case 2:if(a[0]===a[1])throw Error(`[ReadHuffmanCode] invalid symbols`);i[a[1]]=1;break;case 4:if(a[0]===a[1]||a[0]===a[2]||a[0]===a[3]||a[1]===a[2]||a[1]===a[3]||a[2]===a[3])throw Error(`[ReadHuffmanCode] invalid symbols`);r.readBits(1)?(i[a[2]]=3,i[a[3]]=3):i[a[0]]=2;break}}else{let t=new Uint8Array(18),n=32,o=0,s=[new Z(2,0),new Z(2,4),new Z(2,3),new Z(3,2),new Z(2,0),new Z(2,4),new Z(2,3),new Z(4,1),new Z(2,0),new Z(2,4),new Z(2,3),new Z(3,2),new Z(2,0),new Z(2,4),new Z(2,3),new Z(4,5)];for(let e=a;e<18&&n>0;e++){let i=sv[e],a=0;r.fillBitWindow(),a+=r.val_>>>r.bit_pos_&15,r.bit_pos_+=s[a].bits;let c=s[a].value;t[i]=c,c!==0&&(n-=32>>c,o++)}if(!(o===1||n===0))throw Error(`[ReadHuffmanCode] invalid num_codes or space`);hv(t,e,i,r)}let o=fv(t,n,8,i,e);if(!o)throw Error(`brotli BuildHuffmanTable failed`);return o}function mv(e,t,n){n.fillBitWindow(),t+=n.val_>>>n.bit_pos_&255;let r=e[t].bits-8;return r>0&&(n.bit_pos_+=8,t+=e[t].value,t+=n.val_>>>n.bit_pos_&(1<<r)-1),n.bit_pos_+=e[t].bits,e[t].value}function hv(e,t,n,r){let i=0,a=8,o=0,s=0,c=32768,l=[];for(let e=0;e<32;e++)l.push(new Z(0,0));for(fv(l,0,5,e,18);i<t&&c>0;){let e=0;r.readMoreInput(),r.fillBitWindow(),e+=r.val_>>>r.bit_pos_&31,r.bit_pos_+=l[e].bits;let u=l[e].value&255;if(u<16)o=0,n[i++]=u,u!==0&&(a=u,c-=32768>>u);else{let e=u-14,l=0;u===16&&(l=a),s!==l&&(o=0,s=l);let d=o;o>0&&(o-=2,o<<=e),o+=r.readBits(e)+3;let f=o-d;if(i+f>t)throw Error(`[ReadHuffmanCodeLengths] symbol + repeat_delta > num_symbols`);for(let e=0;e<f;e++)n[i+e]=s;i+=f,s!==0&&(c-=f<<15-s)}}if(c!==0)throw Error(`[ReadHuffmanCodeLengths] space = `+c);for(;i<t;i++)n[i]=0}var gv=class{constructor(e,t){this.alphabet_size=e,this.num_htrees=t,this.codes=Array(t+t*cv[e+31>>>5]),this.htrees=new Uint32Array(t)}decode(e){let t=0;for(let n=0;n<this.num_htrees;n++)this.htrees[n]=t,t+=pv(this.alphabet_size,this.codes,t,e)}};function _v([e,t]){return{offset:e,nbits:t}}const vv=[[1,2],[5,2],[9,2],[13,2],[17,3],[25,3],[33,3],[41,3],[49,4],[65,4],[81,4],[97,4],[113,5],[145,5],[177,5],[209,5],[241,6],[305,6],[369,7],[497,8],[753,9],[1265,10],[2289,11],[4337,12],[8433,13],[16625,24]].map(_v),yv=[[0,0],[1,0],[2,0],[3,0],[4,0],[5,0],[6,1],[8,1],[10,2],[14,2],[18,3],[26,3],[34,4],[50,4],[66,5],[98,5],[130,6],[194,7],[322,8],[578,9],[1090,10],[2114,12],[6210,14],[22594,24]].map(_v),bv=[[2,0],[3,0],[4,0],[5,0],[6,0],[7,0],[8,0],[9,0],[10,1],[12,1],[14,2],[18,2],[22,3],[30,3],[38,4],[54,4],[70,5],[102,5],[134,6],[198,7],[326,8],[582,9],[1094,10],[2118,24]].map(_v),xv=[0,0,8,8,0,16,8,16,16],Sv=[0,8,0,8,16,0,16,8,16],Cv=1080,wv=new Uint8Array([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]),Tv=new Uint8Array([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]);function Ev(e,t){let n=new Uint16Array(31);for(let r=0;r<31;r++)n[r]=t+=1<<e[r-1];let r=new Int32Array(n[30]);for(let e=1;e<30;e++)for(let t=n[e];t<n[e+1];++t)r[t]=t-n[e]<<5|e;return{base:n,rev:r}}const{base:Dv,rev:Ov}=Ev(wv,2);Dv[28]=258,Ov[258]=28;const{base:kv}=Ev(Tv,0),Av=new Uint16Array(32768);for(let e=0;e<32768;e++){let t=(e&43690)>>1|(e&21845)<<1;t=(t&52428)>>2|(t&13107)<<2,t=(t&61680)>>4|(t&3855)<<4,Av[e]=((t&65280)>>8|(t&255)<<8)>>1}function jv(e,t,n){let r=new Uint16Array(t);for(let t=0;t<e.length;t++)e[t]&&++r[e[t]-1];let i=new Uint16Array(t);for(let e=1;e<t;e++)i[e]=i[e-1]+r[e-1]<<1;let a;if(n){a=new Uint16Array(1<<t);let n=15-t;for(let r=0;r<e.length;r++)if(e[r]){let o=r<<4|e[r],s=t-e[r],c=i[e[r]-1]++<<s;for(let e=c|(1<<s)-1;c<=e;c++)a[Av[c]>>n]=o}}else{a=new Uint16Array(e.length);for(let t=0;t<e.length;t++)e[t]&&(a[t]=Av[i[e[t]-1]++]>>15-e[t])}return a}const Mv=new Uint8Array(288);for(let e=0;e<144;e++)Mv[e]=8;for(let e=144;e<256;e++)Mv[e]=9;for(let e=256;e<280;e++)Mv[e]=7;for(let e=280;e<288;e++)Mv[e]=8;const Nv=new Uint8Array(32);for(let e=0;e<32;e++)Nv[e]=5;const Pv=jv(Mv,9,1),Fv=jv(Nv,5,1);function Iv(e,t,n,r,i,a,o){let s=n*2,c=n,l=mv(t,n*Cv,o),u;u=l===0?i[s+(a[c]&1)]:l===1?i[s+(a[c]-1&1)]+1:l-2,u>=e&&(u-=e),r[n]=u,i[s+(a[c]&1)]=u,a[c]++}function Lv(e){let t={meta_block_length:0,input_end:0,is_uncompressed:0,is_metadata:!1};if(t.input_end=e.readBits(1),t.input_end&&e.readBits(1))return t;let n=e.readBits(2)+4;if(n===7){if(t.is_metadata=!0,e.readBits(1)!==0)throw Error(`Invalid reserved bit`);let n=e.readBits(2);if(n===0)return t;for(let r=0;r<n;r++){let i=e.readBits(8);if(r+1===n&&n>1&&i===0)throw Error(`Invalid size byte`);t.meta_block_length|=i<<r*8}}else for(let r=0;r<n;r++){let i=e.readBits(4);if(r+1===n&&n>4&&i===0)throw Error(`Invalid size nibble`);t.meta_block_length|=i<<r*4}return t.meta_block_length++,!t.input_end&&!t.is_metadata&&(t.is_uncompressed=e.readBits(1)),t}function Rv(e,t,n,r,i,a){let o=i+1,s=n&i,c=a.pos_&ov.IBUF_MASK;if(t<8||a.bit_pos_+(t<<3)<a.bit_end_pos_){for(;t-- >0;)a.readMoreInput(),r[s++]=a.readBits(8),s===o&&(e.write(r,o),s=0);return}if(a.bit_end_pos_<32)throw Error(`copyUncompressedBlockToOutput: br.bit_end_pos_ < 32`);for(;a.bit_pos_<32;)r[s]=a.val_>>>a.bit_pos_,a.bit_pos_+=8,s++,t--;let l=a.bit_end_pos_-a.bit_pos_>>3;if(c+l>ov.IBUF_MASK){let e=ov.IBUF_MASK+1-c;for(let t=0;t<e;t++)r[s+t]=a.buf_[c+t];l-=e,s+=e,t-=e,c=0}for(let e=0;e<l;e++)r[s+e]=a.buf_[c+e];if(s+=l,t-=l,s>=o){e.write(r,o),s-=o;for(let e=0;e<s;e++)r[e]=r[o+e]}for(;s+t>=o;){if(l=o-s,a.input_.read(r,s,l)<l)throw Error(`copyUncompressedBlockToOutput: not enough bytes`);e.write(r,o),t-=l,s=0}if(a.input_.read(r,s,t)<t)throw Error(`copyUncompressedBlockToOutput: not enough bytes`);a.reset()}function zv(e){if(e.readBits(1)){let t=e.readBits(3);return t===0?1:e.readBits(t)+(1<<t)}return 0}function Bv(e){if(e.readBits(1)===0)return 16;let t=e.readBits(3);return t>0?17+t:(t=e.readBits(3),t>0?8+t:17)}function Vv(e){let t=e.bit_pos_+7&-8;return!e.readBits(t-e.bit_pos_)}function Hv(e,t,n){let{offset:r,nbits:i}=vv[mv(e,t,n)];return r+n.readBits(i)}const Uv=new Uint8Array([0,0,0,0,0,0,0,0,0,4,4,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,12,16,12,12,20,12,16,24,28,12,12,32,12,36,12,44,44,44,44,44,44,44,44,44,44,32,32,24,40,28,12,12,48,52,52,52,48,52,52,52,48,52,52,52,52,52,48,52,52,52,52,52,48,52,52,52,52,52,24,12,28,12,12,12,56,60,60,60,56,60,60,60,56,60,60,60,60,60,56,60,60,60,60,60,56,60,60,60,60,60,24,12,28,12,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,0,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,56,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,6,6,6,6,7,7,7,7,8,8,8,8,9,9,9,9,10,10,10,10,11,11,11,11,12,12,12,12,13,13,13,13,14,14,14,14,15,15,15,15,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,22,22,22,22,23,23,23,23,24,24,24,24,25,25,25,25,26,26,26,26,27,27,27,27,28,28,28,28,29,29,29,29,30,30,30,30,31,31,31,31,32,32,32,32,33,33,33,33,34,34,34,34,35,35,35,35,36,36,36,36,37,37,37,37,38,38,38,38,39,39,39,39,40,40,40,40,41,41,41,41,42,42,42,42,43,43,43,43,44,44,44,44,45,45,45,45,46,46,46,46,47,47,47,47,48,48,48,48,49,49,49,49,50,50,50,50,51,51,51,51,52,52,52,52,53,53,53,53,54,54,54,54,55,55,55,55,56,56,56,56,57,57,57,57,58,58,58,58,59,59,59,59,60,60,60,60,61,61,61,61,62,62,62,62,63,63,63,63,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),Wv=new Uint16Array([1024,1536,1280,1536,0,256,768,512]);function Gv(e,t){let n=0;t.readMoreInput();let r=zv(t)+1,i=new Uint8Array(e);if(r<=1)return[r,i];t.readBits(1)&&(n=t.readBits(4)+1);let a=[];for(let e=0;e<Cv;e++)a[e]=new Z(0,0);pv(r+n,a,0,t);for(let r=0;r<e;){t.readMoreInput();let o=mv(a,0,t);if(o===0)i[r]=0,r++;else if(o<=n){let n=1+(1<<o)+t.readBits(o);for(;--n;){if(r>=e)throw Error(`[DecodeContextMap] i >= context_map_size`);i[r]=0,r++}}else i[r]=o-n,r++}return t.readBits(1)&&qv(i,e),[r,i]}function Kv(e,t){let n=e[t];for(let n=t;n;n--)e[n]=e[n-1];e[0]=n}function qv(e,t){let n=new Uint8Array(256);for(let e=0;e<256;e++)n[e]=e;for(let r=0;r<t;r++){let t=e[r];e[r]=n[t],t&&Kv(n,t)}}var Jv=class{constructor(e){this.buffer=e,this.pos=0}read(e,t,n){this.pos+n>this.buffer.length&&(n=this.buffer.length-this.pos);for(let r=0;r<n;r++)e[t+r]=this.buffer[this.pos+r];return this.pos+=n,n}},Yv=class{constructor(e){this.buffer=e,this.pos=0}write(e,t){if(this.pos+t>this.buffer.length)throw Error(`brotli output buffer is not large enough`);return this.buffer.set(e.subarray(0,t),this.pos),this.pos+=t,t}};const Xv=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);function Zv(e,t,n){let r=t/8|0;return(e[r]|e[r+1]<<8)>>(t&7)&n}function Qv(e,t){let n=t/8|0;return(e[n]|e[n+1]<<8|e[n+2]<<16)>>(t&7)}function $v(e){return(e+7)/8|0}function ey(e,t){if(e[t++]!==31||e[t++]!==139||e[t++]!==8)return 0;let n=e[t++];t+=6,n&4&&(t+=(e[t]|e[t+1]<<8)+2);for(let r=(n>>3&1)+(n>>4&1);r>0;r-=Number(!e[t++]));return t+(n&2)}function ty(e,t,n=0,r=0){let i=t??new Uint8Array(1024);if(!(e.length-n))return i;let a=ey(e,n);if(a===e.length-8)return i;if(a>e.length-8)throw Error(`unexpected EOF`);let o=a*8,s=0,c=0,l=0,u,d,f=e.length*8;function p(e){if(!t&&e>i.length){let t=i;i=new Uint8Array(Math.max(t.length*2,e)),i.set(t)}}do{if(!u){s=Zv(e,o,1);let t=Zv(e,o+1,3);if(o+=3,!t){let t=$v(o)+4,n=e[t-4]|e[t-3]<<8,a=t+n;if(a>e.length)throw Error(`unexpected EOF`);p(r+n),i.set(e.subarray(t,a),r),r+=n,o=a*8;continue}else if(t===1)u=Pv,d=Fv,c=9,l=5;else if(t===2){let t=Zv(e,o,31)+257,n=Zv(e,o+10,15)+4,r=t+Zv(e,o+5,31)+1;o+=14;let i=new Uint8Array(r),a=new Uint8Array(19);for(let t=0;t<n;++t)a[Xv[t]]=Zv(e,o+t*3,7);o+=n*3;let s=Math.max(...a),f=(1<<s)-1,p=jv(a,s,1);for(let t=0;t<r;){let n=p[Zv(e,o,f)];o+=n&15;let r=n>>4;if(r<16)i[t++]=r;else{let n=0,a=0;for(r===16?(a=3+Zv(e,o,3),o+=2,n=i[t-1]):r===17?(a=3+Zv(e,o,7),o+=3):r===18&&(a=11+Zv(e,o,127),o+=7);a--;)i[t++]=n}}let m=i.subarray(0,t),h=i.subarray(t);c=Math.max(...m),l=Math.max(...h),u=jv(m,c,1),d=jv(h,l,1)}else throw Error(`invalid block type`);if(o>f)throw Error(`unexpected EOF`)}p(r+131072);let t=(1<<c)-1,n=(1<<l)-1;for(;;){let a=u[Qv(e,o)&t],s=a>>4;if(o+=a&15,o>f)throw Error(`unexpected EOF`);if(!a)throw Error(`invalid length/literal`);if(s<256)i[r++]=s;else if(s===256){u=void 0;break}else{let t=s-254;if(s>264){let n=s-257,r=wv[n];t=Zv(e,o,(1<<r)-1)+Dv[n],o+=r}if(!d)throw Error(`invalid distance map`);let a=d[Qv(e,o)&n],c=a>>4;if(!a)throw Error(`invalid distance`);o+=a&15;let l=kv[c];if(c>3){let t=Tv[c];l+=Qv(e,o)&(1<<t)-1,o+=t}if(o>f)throw Error(`unexpected EOF`);let u=r+t;if(r<l)throw Error(`unexpected dictionary case`);for(p(u);r<u;r++)i[r]=i[r-l]}}u&&(s=1)}while(!s);if(r<i.length){let t=Math.ceil(o/8)+8;ty(e,i,t,r)}return t?i:i.subarray(0,r)}let ny;function ry(){if(!ny){ny=new Uint8Array(122784);let e=atob(`
67
+ `).map(e=>e.trim()).filter(e=>e),r=[],a=[];n.forEach(e=>{e.startsWith(`#`)||(e.startsWith(`==`)?(a.push(t.ros2===!0?(0,o.buildRos2Type)(r):d(r,c)),r=[]):r.push({line:e}))}),a.push(t.ros2===!0?(0,o.buildRos2Type)(r):d(r,c));let s=[],l=a.filter(e=>s.find(t=>(0,i.isMsgDefEqual)(e,t))?!1:s.push(e));return t.skipTypeFixup!==!0&&u(l),l}function u(e){e.forEach(({definitions:t,name:n})=>{t.forEach(t=>{if(t.isComplex===!0){let r=n?.split(`/`).slice(0,-1).join(`/`),i=p(e,t.type,r).name;if(i==null)throw Error(`Missing type definition for ${t.type}`);t.type=i}})})}function d(e,t){let n=[],r;return e.forEach(({line:e})=>{if(e.startsWith(`MSG:`)){let[t,n]=f(e);r=n?.trim();return}let i=new a.Parser(t);i.feed(e);let o=i.finish();if(o.length===0)throw Error(`Could not parse line: '${e}'`);if(o.length>1)throw Error(`Ambiguous line: '${e}'`);let s=o[0];s!=null&&(s.type=m(s.type),n.push(s))}),{name:r,definitions:n}}function f(e){return e.replace(/#.*/gi,``).split(` `).filter(e=>e)}function p(e,t,n){let r=e.filter(e=>{let r=e.name??``;return t.length===0?r.length===0:t.includes(`/`)?r===t:t===`Header`?r===`std_msgs/Header`:n?r===`${n}/${t}`:r.endsWith(`/${t}`)});if(r[0]==null)throw Error(`Expected 1 top level type definition for '${t}' but found ${r.length}`);if(r.length>1)throw Error(`Cannot unambiguously determine fully-qualified type name for '${t}'`);return r[0]}function m(e){return e===`char`?`uint8`:e===`byte`?`int8`:e}})},n={};function r(t){var i=n[t];if(i!==void 0)return i.exports;var a=n[t]={exports:{}};return e[t].call(a.exports,a,a.exports,r),a.exports}r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{typeof Symbol<`u`&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:`Module`}),Object.defineProperty(e,`__esModule`,{value:!0})},t.exports=r(881)})()})),hp=e((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.EncapsulationKind=void 0;var t;(function(e){e[e.CDR_BE=0]=`CDR_BE`,e[e.CDR_LE=1]=`CDR_LE`,e[e.PL_CDR_BE=2]=`PL_CDR_BE`,e[e.PL_CDR_LE=3]=`PL_CDR_LE`,e[e.CDR2_BE=16]=`CDR2_BE`,e[e.CDR2_LE=17]=`CDR2_LE`,e[e.PL_CDR2_BE=18]=`PL_CDR2_BE`,e[e.PL_CDR2_LE=19]=`PL_CDR2_LE`,e[e.DELIMITED_CDR2_BE=20]=`DELIMITED_CDR2_BE`,e[e.DELIMITED_CDR2_LE=21]=`DELIMITED_CDR2_LE`,e[e.RTPS_CDR2_BE=6]=`RTPS_CDR2_BE`,e[e.RTPS_CDR2_LE=7]=`RTPS_CDR2_LE`,e[e.RTPS_DELIMITED_CDR2_BE=8]=`RTPS_DELIMITED_CDR2_BE`,e[e.RTPS_DELIMITED_CDR2_LE=9]=`RTPS_DELIMITED_CDR2_LE`,e[e.RTPS_PL_CDR2_BE=10]=`RTPS_PL_CDR2_BE`,e[e.RTPS_PL_CDR2_LE=11]=`RTPS_PL_CDR2_LE`})(t||(e.EncapsulationKind=t={}))})),gp=e((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.getEncapsulationKindInfo=void 0;let t=hp();e.getEncapsulationKindInfo=e=>{let n=e>t.EncapsulationKind.PL_CDR_LE,r=e===t.EncapsulationKind.CDR_LE||e===t.EncapsulationKind.PL_CDR_LE||e===t.EncapsulationKind.CDR2_LE||e===t.EncapsulationKind.PL_CDR2_LE||e===t.EncapsulationKind.DELIMITED_CDR2_LE||e===t.EncapsulationKind.RTPS_CDR2_LE||e===t.EncapsulationKind.RTPS_PL_CDR2_LE||e===t.EncapsulationKind.RTPS_DELIMITED_CDR2_LE,i=e===t.EncapsulationKind.DELIMITED_CDR2_BE||e===t.EncapsulationKind.DELIMITED_CDR2_LE||e===t.EncapsulationKind.RTPS_DELIMITED_CDR2_BE||e===t.EncapsulationKind.RTPS_DELIMITED_CDR2_LE,a=e===t.EncapsulationKind.PL_CDR2_BE||e===t.EncapsulationKind.PL_CDR2_LE||e===t.EncapsulationKind.RTPS_PL_CDR2_BE||e===t.EncapsulationKind.RTPS_PL_CDR2_LE,o=e===t.EncapsulationKind.PL_CDR_BE||e===t.EncapsulationKind.PL_CDR_LE;return{isCDR2:n,littleEndian:r,usesDelimiterHeader:i||a,usesMemberHeader:a||o}}})),_p=e((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.isBigEndian=r;let t=new Uint8Array(4),n=new Uint32Array(t.buffer);n[0]=1;function r(){return t[3]===1}})),vp=e((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.lengthCodeToObjectSizes=void 0,e.getLengthCodeForObjectSize=t;function t(e){let t;switch(e){case 1:t=0;break;case 2:t=1;break;case 4:t=2;break;case 8:t=3;break}if(t==null){if(e>4294967295)throw Error(`Object size ${e} for EMHEADER too large without specifying length code. Max size is 4294967295`);t=4}return t}e.lengthCodeToObjectSizes={0:1,1:2,2:4,3:8}})),yp=e((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.SENTINEL_PID=e.EXTENDED_PID=void 0,e.EXTENDED_PID=16129,e.SENTINEL_PID=16130})),bp=e((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.CdrReader=void 0;let t=gp(),n=_p(),r=vp(),i=yp(),a=new TextDecoder(`utf8`);e.CdrReader=class e{get kind(){return this.view.getUint8(1)}get decodedBytes(){return this.offset}get byteLength(){return this.view.byteLength}constructor(e){if(this.origin=0,e.byteLength<4)throw Error(`Invalid CDR data size ${e.byteLength}, must contain at least a 4-byte header`);this.view=new DataView(e.buffer,e.byteOffset,e.byteLength);let r=this.kind,{isCDR2:i,littleEndian:a,usesDelimiterHeader:o,usesMemberHeader:s}=(0,t.getEncapsulationKindInfo)(r);this.usesDelimiterHeader=o,this.usesMemberHeader=s,this.littleEndian=a,this.hostLittleEndian=!(0,n.isBigEndian)(),this.isCDR2=i,this.eightByteAlignment=i?4:8,this.origin=4,this.offset=4}int8(){let e=this.view.getInt8(this.offset);return this.offset+=1,e}uint8(){let e=this.view.getUint8(this.offset);return this.offset+=1,e}int16(){this.align(2);let e=this.view.getInt16(this.offset,this.littleEndian);return this.offset+=2,e}uint16(){this.align(2);let e=this.view.getUint16(this.offset,this.littleEndian);return this.offset+=2,e}int32(){this.align(4);let e=this.view.getInt32(this.offset,this.littleEndian);return this.offset+=4,e}uint32(){this.align(4);let e=this.view.getUint32(this.offset,this.littleEndian);return this.offset+=4,e}int64(){this.align(this.eightByteAlignment);let e=this.view.getBigInt64(this.offset,this.littleEndian);return this.offset+=8,e}uint64(){this.align(this.eightByteAlignment);let e=this.view.getBigUint64(this.offset,this.littleEndian);return this.offset+=8,e}uint16BE(){this.align(2);let e=this.view.getUint16(this.offset,!1);return this.offset+=2,e}uint32BE(){this.align(4);let e=this.view.getUint32(this.offset,!1);return this.offset+=4,e}uint64BE(){this.align(this.eightByteAlignment);let e=this.view.getBigUint64(this.offset,!1);return this.offset+=8,e}float32(){this.align(4);let e=this.view.getFloat32(this.offset,this.littleEndian);return this.offset+=4,e}float64(){this.align(this.eightByteAlignment);let e=this.view.getFloat64(this.offset,this.littleEndian);return this.offset+=8,e}string(e){let t=e??this.uint32();if(t<=1)return this.offset+=t,``;let n=new Uint8Array(this.view.buffer,this.view.byteOffset+this.offset,t-1),r=a.decode(n);return this.offset+=t,r}dHeader(){return this.uint32()}emHeader(){return this.isCDR2?this.memberHeaderV2():this.memberHeaderV1()}memberHeaderV1(){this.align(4);let e=this.uint16(),t=(e&16384)>>14==1,n=(e&32768)>>15==1,r=(e&16383)===i.EXTENDED_PID;if((e&16383)===i.SENTINEL_PID)return this.uint16(),{id:i.SENTINEL_PID,objectSize:0,mustUnderstand:!1,readSentinelHeader:!0};if((e&16383)>i.SENTINEL_PID||n)throw Error(`Unsupported parameter ID header ${e.toString(16)}`);r&&this.uint16();let a=r?this.uint32():e&16383,o=r?this.uint32():this.uint16();return this.resetOrigin(),{id:a,objectSize:o,mustUnderstand:t}}resetOrigin(){this.origin=this.offset}isPresentFlag(){if(!this.isCDR2)throw Error(`isPresentFlag is only supported for CDR2`);return!!this.uint8()}sentinelHeader(){return this.isCDR2?!1:(this.align(4),(this.uint16()&16383)===i.SENTINEL_PID?(this.uint16(),!0):!1)}memberHeaderV2(){let e=this.uint32(),t=Math.abs((e&2147483648)>>31)===1,n=(e&1879048192)>>28;return{mustUnderstand:t,id:e&268435455,objectSize:this.emHeaderObjectSize(n),lengthCode:n}}emHeaderObjectSize(e){switch(e){case 0:case 1:case 2:case 3:return r.lengthCodeToObjectSizes[e];case 4:case 5:return this.uint32();case 6:return 4*this.uint32();case 7:return 8*this.uint32();default:throw Error(`Invalid length code ${e} in EMHEADER at offset ${this.offset-4}`)}}sequenceLength(){return this.uint32()}int8Array(e=this.sequenceLength()){let t=new Int8Array(this.view.buffer,this.view.byteOffset+this.offset,e);return this.offset+=e,t}uint8Array(e=this.sequenceLength()){let t=new Uint8Array(this.view.buffer,this.view.byteOffset+this.offset,e);return this.offset+=e,t}int16Array(e=this.sequenceLength()){return this.typedArray(Int16Array,`getInt16`,e)}uint16Array(e=this.sequenceLength()){return this.typedArray(Uint16Array,`getUint16`,e)}int32Array(e=this.sequenceLength()){return this.typedArray(Int32Array,`getInt32`,e)}uint32Array(e=this.sequenceLength()){return this.typedArray(Uint32Array,`getUint32`,e)}int64Array(e=this.sequenceLength()){return this.typedArray(BigInt64Array,`getBigInt64`,e,this.eightByteAlignment)}uint64Array(e=this.sequenceLength()){return this.typedArray(BigUint64Array,`getBigUint64`,e,this.eightByteAlignment)}float32Array(e=this.sequenceLength()){return this.typedArray(Float32Array,`getFloat32`,e)}float64Array(e=this.sequenceLength()){return this.typedArray(Float64Array,`getFloat64`,e,this.eightByteAlignment)}stringArray(e=this.sequenceLength()){let t=[];for(let n=0;n<e;n++)t.push(this.string());return t}seek(e){let t=this.offset+e;if(t<4||t>this.view.byteLength)throw Error(`seek(${e}) failed, ${t} is outside the data range`);this.offset=t}seekTo(e){if(e<4||e>this.view.byteLength)throw Error(`seekTo(${e}) failed, value is outside the data range`);this.offset=e}clone(){let t=new e(this.view);return t.offset=this.offset,t.origin=this.origin,t}limit(e){let t=this.offset+e;if(t<=this.view.byteLength)this.view=new DataView(this.view.buffer,this.view.byteOffset,t);else throw RangeError(`length ${e} exceeds byte length of view`)}isAtEnd(){return this.offset>=this.view.byteLength}align(e){let t=(this.offset-this.origin)%e;t>0&&(this.offset+=e-t)}typedArray(e,t,n,r=e.BYTES_PER_ELEMENT){if(n===0)return new e;this.align(r);let i=this.view.byteOffset+this.offset;if(this.littleEndian!==this.hostLittleEndian)return this.typedArraySlow(e,t,n);if(i%e.BYTES_PER_ELEMENT===0){let t=new e(this.view.buffer,i,n);return this.offset+=e.BYTES_PER_ELEMENT*n,t}else return this.typedArrayUnaligned(e,t,n)}typedArrayUnaligned(e,t,n){if(n<10)return this.typedArraySlow(e,t,n);let r=e.BYTES_PER_ELEMENT*n,i=new Uint8Array(r);return i.set(new Uint8Array(this.view.buffer,this.view.byteOffset+this.offset,r)),this.offset+=r,new e(i.buffer,i.byteOffset,n)}typedArraySlow(e,t,n){let r=new e(n),i=this.offset;for(let a=0;a<n;a++)r[a]=this.view[t](i,this.littleEndian),i+=e.BYTES_PER_ELEMENT;return this.offset=i,r}}})),xp=e((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.CdrSizeCalculator=void 0,e.CdrSizeCalculator=class{constructor(){this.offset=4}get size(){return this.offset}int8(){return this.incrementAndReturn(1)}uint8(){return this.incrementAndReturn(1)}int16(){return this.incrementAndReturn(2)}uint16(){return this.incrementAndReturn(2)}int32(){return this.incrementAndReturn(4)}uint32(){return this.incrementAndReturn(4)}int64(){return this.incrementAndReturn(8)}uint64(){return this.incrementAndReturn(8)}float32(){return this.incrementAndReturn(4)}float64(){return this.incrementAndReturn(8)}string(e){return this.uint32(),this.offset+=e+1,this.offset}sequenceLength(){return this.uint32()}incrementAndReturn(e){let t=(this.offset-4)%e;return t>0&&(this.offset+=e-t),this.offset+=e,this.offset}}})),Sp=e((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.CdrWriter=void 0;let t=hp(),n=gp(),r=_p(),i=vp(),a=yp(),o=new TextEncoder;function s(e){let t=0,n=e.length;for(let r=0;r<n;r++){let n=e.charCodeAt(r);if(n<=127)t+=1;else if(n<=2047)t+=2;else if(55296<=n&&n<=56319){let n=e.charCodeAt(r+1);56320<=n&&n<=57343?(t+=4,r++):t+=3}else t+=3}return t}var c=class e{get data(){return new Uint8Array(this.buffer,0,this.offset)}get size(){return this.offset}get kind(){return this.view.getUint8(1)}constructor(i={}){i.buffer==null?i.size==null?this.buffer=new ArrayBuffer(e.DEFAULT_CAPACITY):this.buffer=new ArrayBuffer(i.size):this.buffer=i.buffer;let a=i.kind??t.EncapsulationKind.CDR_LE,{isCDR2:o,littleEndian:s}=(0,n.getEncapsulationKindInfo)(a);this.isCDR2=o,this.littleEndian=s,this.hostLittleEndian=!(0,r.isBigEndian)(),this.eightByteAlignment=o?4:8,this.array=new Uint8Array(this.buffer),this.view=new DataView(this.buffer),this.resizeIfNeeded(4),this.view.setUint8(0,0),this.view.setUint8(1,a),this.view.setUint16(2,0,!1),this.offset=4,this.origin=4}int8(e){return this.resizeIfNeeded(1),this.view.setInt8(this.offset,e),this.offset+=1,this}uint8(e){return this.resizeIfNeeded(1),this.view.setUint8(this.offset,e),this.offset+=1,this}int16(e){return this.align(2),this.view.setInt16(this.offset,e,this.littleEndian),this.offset+=2,this}uint16(e){return this.align(2),this.view.setUint16(this.offset,e,this.littleEndian),this.offset+=2,this}int32(e){return this.align(4),this.view.setInt32(this.offset,e,this.littleEndian),this.offset+=4,this}uint32(e){return this.align(4),this.view.setUint32(this.offset,e,this.littleEndian),this.offset+=4,this}int64(e){return this.align(this.eightByteAlignment,8),this.view.setBigInt64(this.offset,e,this.littleEndian),this.offset+=8,this}uint64(e){return this.align(this.eightByteAlignment,8),this.view.setBigUint64(this.offset,e,this.littleEndian),this.offset+=8,this}uint16BE(e){return this.align(2),this.view.setUint16(this.offset,e,!1),this.offset+=2,this}uint32BE(e){return this.align(4),this.view.setUint32(this.offset,e,!1),this.offset+=4,this}uint64BE(e){return this.align(this.eightByteAlignment,8),this.view.setBigUint64(this.offset,e,!1),this.offset+=8,this}float32(e){return this.align(4),this.view.setFloat32(this.offset,e,this.littleEndian),this.offset+=4,this}float64(e){return this.align(this.eightByteAlignment,8),this.view.setFloat64(this.offset,e,this.littleEndian),this.offset+=8,this}string(e,t=!0){let n=s(e);return t&&this.uint32(n+1),this.resizeIfNeeded(n+1),o.encodeInto(e,new Uint8Array(this.buffer,this.offset,n)),this.view.setUint8(this.offset+n,0),this.offset+=n+1,this}dHeader(e){let t=e;return this.uint32(t),this}emHeader(e,t,n,r){return this.isCDR2?this.memberHeaderV2(e,t,n,r):this.memberHeaderV1(e,t,n)}memberHeaderV1(e,t,n){this.align(4);let r=e?16384:0;if(t>16128||n>65535){let e=r|a.EXTENDED_PID;this.uint16(e),this.uint16(8),this.uint32(t),this.uint32(n)}else{let e=r|t;this.uint16(e);let i=n&65535;this.uint16(i)}return this.resetOrigin(),this}resetOrigin(){this.origin=this.offset}presentFlag(e){if(!this.isCDR2)throw Error(`presentFlag is only supported for CDR2`);return this.uint8(+!!e),this}sentinelHeader(){return this.isCDR2||(this.align(4),this.uint16(a.SENTINEL_PID),this.uint16(0)),this}memberHeaderV2(e,t,n,r){if(t>268435455)throw Error(`Member ID ${t} is too large. Max value is 268435455`);let a=e?1<<31:0,o=r??(0,i.getLengthCodeForObjectSize)(n),s=a|o<<28|t;switch(this.uint32(s),o){case 0:case 1:case 2:case 3:{let e=i.lengthCodeToObjectSizes[o];if(n!==e)throw Error(`Cannot write a length code ${o} header with an object size not equal to ${e}`);break}case 4:case 5:this.uint32(n);break;case 6:if(n%4!=0)throw Error(`Cannot write a length code 6 header with an object size that is not a multiple of 4`);this.uint32(n>>2);break;case 7:if(n%8!=0)throw Error(`Cannot write a length code 7 header with an object size that is not a multiple of 8`);this.uint32(n>>3);break;default:throw Error(`Unexpected length code ${o}`)}return this}sequenceLength(e){return this.uint32(e)}int8Array(e,t){return t===!0&&this.sequenceLength(e.length),this.resizeIfNeeded(e.length),this.array.set(e,this.offset),this.offset+=e.length,this}uint8Array(e,t){return t===!0&&this.sequenceLength(e.length),this.resizeIfNeeded(e.length),this.array.set(e,this.offset),this.offset+=e.length,this}int16Array(t,n){if(n===!0&&this.sequenceLength(t.length),t instanceof Int16Array&&this.littleEndian===this.hostLittleEndian&&t.length>=e.BUFFER_COPY_THRESHOLD)this.align(t.BYTES_PER_ELEMENT,t.byteLength),this.array.set(new Uint8Array(t.buffer,t.byteOffset,t.byteLength),this.offset),this.offset+=t.byteLength;else for(let e of t)this.int16(e);return this}uint16Array(t,n){if(n===!0&&this.sequenceLength(t.length),t instanceof Uint16Array&&this.littleEndian===this.hostLittleEndian&&t.length>=e.BUFFER_COPY_THRESHOLD)this.align(t.BYTES_PER_ELEMENT,t.byteLength),this.array.set(new Uint8Array(t.buffer,t.byteOffset,t.byteLength),this.offset),this.offset+=t.byteLength;else for(let e of t)this.uint16(e);return this}int32Array(t,n){if(n===!0&&this.sequenceLength(t.length),t instanceof Int32Array&&this.littleEndian===this.hostLittleEndian&&t.length>=e.BUFFER_COPY_THRESHOLD)this.align(t.BYTES_PER_ELEMENT,t.byteLength),this.array.set(new Uint8Array(t.buffer,t.byteOffset,t.byteLength),this.offset),this.offset+=t.byteLength;else for(let e of t)this.int32(e);return this}uint32Array(t,n){if(n===!0&&this.sequenceLength(t.length),t instanceof Uint32Array&&this.littleEndian===this.hostLittleEndian&&t.length>=e.BUFFER_COPY_THRESHOLD)this.align(t.BYTES_PER_ELEMENT,t.byteLength),this.array.set(new Uint8Array(t.buffer,t.byteOffset,t.byteLength),this.offset),this.offset+=t.byteLength;else for(let e of t)this.uint32(e);return this}int64Array(t,n){if(n===!0&&this.sequenceLength(t.length),t instanceof BigInt64Array&&this.littleEndian===this.hostLittleEndian&&t.length>=e.BUFFER_COPY_THRESHOLD)this.align(t.BYTES_PER_ELEMENT,t.byteLength),this.array.set(new Uint8Array(t.buffer,t.byteOffset,t.byteLength),this.offset),this.offset+=t.byteLength;else for(let e of t)this.int64(BigInt(e));return this}uint64Array(t,n){if(n===!0&&this.sequenceLength(t.length),t instanceof BigUint64Array&&this.littleEndian===this.hostLittleEndian&&t.length>=e.BUFFER_COPY_THRESHOLD)this.align(t.BYTES_PER_ELEMENT,t.byteLength),this.array.set(new Uint8Array(t.buffer,t.byteOffset,t.byteLength),this.offset),this.offset+=t.byteLength;else for(let e of t)this.uint64(BigInt(e));return this}float32Array(t,n){if(n===!0&&this.sequenceLength(t.length),t instanceof Float32Array&&this.littleEndian===this.hostLittleEndian&&t.length>=e.BUFFER_COPY_THRESHOLD)this.align(t.BYTES_PER_ELEMENT,t.byteLength),this.array.set(new Uint8Array(t.buffer,t.byteOffset,t.byteLength),this.offset),this.offset+=t.byteLength;else for(let e of t)this.float32(e);return this}float64Array(t,n){if(n===!0&&this.sequenceLength(t.length),t instanceof Float64Array&&this.littleEndian===this.hostLittleEndian&&t.length>=e.BUFFER_COPY_THRESHOLD)this.align(t.BYTES_PER_ELEMENT,t.byteLength),this.array.set(new Uint8Array(t.buffer,t.byteOffset,t.byteLength),this.offset),this.offset+=t.byteLength;else for(let e of t)this.float64(e);return this}align(e,t=e){let n=(this.offset-this.origin)%e,r=n>0?e-n:0;this.resizeIfNeeded(r+t),this.array.fill(0,this.offset,this.offset+r),this.offset+=r}resizeIfNeeded(e){let t=this.offset+e;if(this.buffer.byteLength<t){let e=this.buffer.byteLength*2,n=e>t?e:t;this.resize(n)}}resize(e){if(this.buffer.byteLength>=e)return;let t=new ArrayBuffer(e),n=new Uint8Array(t);n.set(this.array),this.buffer=t,this.array=n,this.view=new DataView(t)}};e.CdrWriter=c,c.DEFAULT_CAPACITY=16,c.BUFFER_COPY_THRESHOLD=10})),Cp=e((e=>{var t=e&&e.__createBinding||(Object.create?(function(e,t,n,r){r===void 0&&(r=n);var i=Object.getOwnPropertyDescriptor(t,n);(!i||(`get`in i?!t.__esModule:i.writable||i.configurable))&&(i={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,i)}):(function(e,t,n,r){r===void 0&&(r=n),e[r]=t[n]})),n=e&&e.__exportStar||function(e,n){for(var r in e)r!==`default`&&!Object.prototype.hasOwnProperty.call(n,r)&&t(n,e,r)};Object.defineProperty(e,`__esModule`,{value:!0}),n(bp(),e),n(xp(),e),n(Sp(),e),n(hp(),e)})),wp=e((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.messageDefinitionHasDataFields=t;function t(e){return e.some(e=>e.isConstant!==!0)}})),Tp=e((e=>{var t=e&&e.__classPrivateFieldGet||function(e,t,n,r){if(n===`a`&&!r)throw TypeError(`Private accessor was defined without a getter`);if(typeof t==`function`?e!==t||!r:!t.has(e))throw TypeError(`Cannot read private member from an object whose class did not declare it`);return n===`m`?r:n===`a`?r.call(e):r?r.value:t.get(e)},n=e&&e.__classPrivateFieldSet||function(e,t,n,r,i){if(r===`m`)throw TypeError(`Private method is not writable`);if(r===`a`&&!i)throw TypeError(`Private accessor was defined without a setter`);if(typeof t==`function`?e!==t||!i:!t.has(e))throw TypeError(`Cannot write private member to an object whose class did not declare it`);return r===`a`?i.call(e,n):i?i.value=n:t.set(e,n),n},r,i,a,o,s,c,l;Object.defineProperty(e,`__esModule`,{value:!0}),e.MessageReader=void 0;let u=Cp(),d=wp();e.MessageReader=class{lastReadHadTrailingBytes(){return t(this,s,`f`)}lastReadByteLength(){return t(this,o,`f`)}constructor(e,t={}){r.add(this),i.set(this,void 0),a.set(this,void 0),o.set(this,0),s.set(this,!1),c.set(this,void 0);let{timeType:l=`sec,nanosec`}=t,u=e.find(e=>!f(e));if(u==null)throw Error(`MessageReader initialized with no root MessageDefinition`);n(this,i,u.definitions,`f`),n(this,a,new Map(e.map(e=>[e.name??``,e.definitions])),`f`),n(this,c,l===`sec,nsec`,`f`)}readMessage(e){let a=new u.CdrReader(e),c=t(this,r,`m`,l).call(this,t(this,i,`f`),a);return n(this,o,a.decodedBytes,`f`),n(this,s,t(this,o,`f`)<e.byteLength&&!p(e,t(this,o,`f`)),`f`),c}},i=new WeakMap,a=new WeakMap,o=new WeakMap,s=new WeakMap,c=new WeakMap,r=new WeakSet,l=function e(n,i){let o={};if(!(0,d.messageDefinitionHasDataFields)(n))return i.uint8(),o;for(let s of n)if(s.isConstant!==!0)if(s.isComplex===!0){let n=t(this,a,`f`).get(s.type);if(n==null)throw Error(`Unrecognized complex type ${s.type}`);if(s.isArray===!0){let a=s.arrayLength??i.sequenceLength(),c=[];for(let o=0;o<a;o++)c.push(t(this,r,`m`,e).call(this,n,i));o[s.name]=c}else o[s.name]=t(this,r,`m`,e).call(this,n,i)}else if(s.isArray===!0){let e=(t(this,c,`f`)?_:g).get(s.type);if(e==null)throw Error(`Unrecognized primitive array type ${s.type}[]`);let n=s.arrayLength??i.sequenceLength();o[s.name]=e(i,n)}else{let e=(t(this,c,`f`)?h:m).get(s.type);if(e==null)throw Error(`Unrecognized primitive type ${s.type}`);o[s.name]=e(i)}return o};function f(e){return e.definitions.length>0&&e.definitions.every(e=>e.isConstant)}function p(e,t){let n=e.byteLength-t;if(n<=0)return!1;let r=(4-t%4)%4,i=(8-t%8)%8;return n!==r&&n!==i?!1:new Uint8Array(e.buffer,e.byteOffset+t,n).every(e=>e===0)}let m=new Map([[`bool`,e=>!!e.int8()],[`int8`,e=>e.int8()],[`uint8`,e=>e.uint8()],[`int16`,e=>e.int16()],[`uint16`,e=>e.uint16()],[`int32`,e=>e.int32()],[`uint32`,e=>e.uint32()],[`int64`,e=>e.int64()],[`uint64`,e=>e.uint64()],[`float32`,e=>e.float32()],[`float64`,e=>e.float64()],[`string`,e=>e.string()],[`wstring`,S],[`time`,e=>({sec:e.int32(),nanosec:e.uint32()})],[`duration`,e=>({sec:e.int32(),nanosec:e.uint32()})]]),h=new Map([...m,[`time`,e=>({sec:e.int32(),nsec:e.uint32()})],[`duration`,e=>({sec:e.int32(),nsec:e.uint32()})]]),g=new Map([[`bool`,v],[`int8`,(e,t)=>e.int8Array(t)],[`uint8`,(e,t)=>e.uint8Array(t)],[`int16`,(e,t)=>e.int16Array(t)],[`uint16`,(e,t)=>e.uint16Array(t)],[`int32`,(e,t)=>e.int32Array(t)],[`uint32`,(e,t)=>e.uint32Array(t)],[`int64`,(e,t)=>e.int64Array(t)],[`uint64`,(e,t)=>e.uint64Array(t)],[`float32`,(e,t)=>e.float32Array(t)],[`float64`,(e,t)=>e.float64Array(t)],[`string`,y],[`wstring`,S],[`time`,x],[`duration`,x]]),_=new Map([...g,[`time`,b],[`duration`,b]]);function v(e,t){let n=Array(t);for(let r=0;r<t;r++)n[r]=!!e.int8();return n}function y(e,t){let n=Array(t);for(let r=0;r<t;r++)n[r]=e.string();return n}function b(e,t){let n=Array(t);for(let r=0;r<t;r++)n[r]={sec:e.int32(),nsec:e.uint32()};return n}function x(e,t){let n=Array(t);for(let r=0;r<t;r++)n[r]={sec:e.int32(),nanosec:e.uint32()};return n}function S(){throw Error(`wstring is implementation-defined and therefore not supported`)}})),Ep=e((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.stringLengthUtf8=t;function t(e){let t=0,n=e.length;for(let r=0;r<n;r++){let n=e.charCodeAt(r);if(n<=127)t+=1;else if(n<=2047)t+=2;else if(55296<=n&&n<=56319){let n=e.charCodeAt(r+1);56320<=n&&n<=57343?(t+=4,r++):t+=3}else t+=3}return t}})),Dp=e((e=>{var t=e&&e.__classPrivateFieldSet||function(e,t,n,r,i){if(r===`m`)throw TypeError(`Private method is not writable`);if(r===`a`&&!i)throw TypeError(`Private accessor was defined without a setter`);if(typeof t==`function`?e!==t||!i:!t.has(e))throw TypeError(`Cannot write private member to an object whose class did not declare it`);return r===`a`?i.call(e,n):i?i.value=n:t.set(e,n),n},n=e&&e.__classPrivateFieldGet||function(e,t,n,r){if(n===`a`&&!r)throw TypeError(`Private accessor was defined without a getter`);if(typeof t==`function`?e!==t||!r:!t.has(e))throw TypeError(`Cannot read private member from an object whose class did not declare it`);return n===`m`?r:n===`a`?r.call(e):r?r.value:t.get(e)},r,i,a,o,s,c,l,u,d;Object.defineProperty(e,`__esModule`,{value:!0}),e.MessageWriter=void 0;let f=Cp(),p=wp(),m=Ep(),h=new Map([[`bool`,1],[`int8`,1],[`uint8`,1],[`int16`,2],[`uint16`,2],[`int32`,4],[`uint32`,4],[`int64`,8],[`uint64`,8],[`float32`,4],[`float64`,8],[`time`,8],[`duration`,8]]),g=new Map([[`bool`,x],[`int8`,S],[`uint8`,C],[`int16`,w],[`uint16`,T],[`int32`,E],[`uint32`,D],[`int64`,O],[`uint64`,k],[`float32`,A],[`float64`,j],[`string`,M],[`time`,N],[`duration`,N],[`wstring`,v]]),_=new Map([[`bool`,P],[`int8`,ee],[`uint8`,te],[`int16`,ne],[`uint16`,re],[`int32`,ie],[`uint32`,ae],[`int64`,oe],[`uint64`,se],[`float32`,ce],[`float64`,le],[`string`,ue],[`time`,de],[`duration`,de],[`wstring`,v]]);function v(){throw Error(`wstring is implementation-defined and therefore not supported`)}e.MessageWriter=class{constructor(e){r.add(this),i.set(this,void 0),a.set(this,void 0);let n=e.find(e=>!y(e));if(n==null)throw Error(`MessageReader initialized with no root MessageDefinition`);t(this,i,n.definitions,`f`),t(this,a,new Map(e.map(e=>[e.name??``,e.definitions])),`f`)}calculateByteSize(e){return n(this,r,`m`,o).call(this,n(this,i,`f`),e,4)}writeMessage(e,t){let a=new f.CdrWriter({buffer:t,size:t?void 0:this.calculateByteSize(e)});return n(this,r,`m`,s).call(this,n(this,i,`f`),e,a),a.data}},i=new WeakMap,a=new WeakMap,r=new WeakSet,o=function e(t,i,a){let o=i,s=a;if(!(0,p.messageDefinitionHasDataFields)(t))return a+n(this,r,`m`,l).call(this,`uint8`);for(let i of t){if(i.isConstant===!0)continue;let t=o?.[i.name];if(i.isArray===!0){let a=i.arrayLength??b(t),o=Array.isArray(t)||ArrayBuffer.isView(t)?t:[];if(i.arrayLength??(s+=fe(s,4),s+=4),i.isComplex===!0){let t=n(this,r,`m`,c).call(this,i.type);for(let i=0;i<a;i++){let a=o[i]??{};s=n(this,r,`m`,e).call(this,t,a,s)}}else if(i.type===`string`)for(let e=0;e<a;e++){let t=o[e]??``;s+=fe(s,4),s+=4+(0,m.stringLengthUtf8)(t)+1}else{let e=n(this,r,`m`,l).call(this,i.type),t=i.type===`time`||i.type===`duration`?4:e;s+=fe(s,t),s+=e*a}}else if(i.isComplex===!0){let a=n(this,r,`m`,c).call(this,i.type),o=t??{};s=n(this,r,`m`,e).call(this,a,o,s)}else if(i.type===`string`){let e=typeof t==`string`?t:``;s+=fe(s,4),s+=4+(0,m.stringLengthUtf8)(e)+1}else{let e=n(this,r,`m`,l).call(this,i.type),t=i.type===`time`||i.type===`duration`?4:e;s+=fe(s,t),s+=e}}return s},s=function e(t,i,a){let o=i;if(!(0,p.messageDefinitionHasDataFields)(t)){C(0,0,a);return}for(let i of t){if(i.isConstant===!0)continue;let t=o?.[i.name];if(i.isArray===!0){let o=i.arrayLength??b(t),s=Array.isArray(t)||ArrayBuffer.isView(t)?t:[];if(i.arrayLength??a.sequenceLength(o),i.arrayLength!=null&&t!=null){let e=b(t);if(e!==i.arrayLength)throw Error(`Expected ${i.arrayLength} items for fixed-length array field ${i.name} but received ${e}`)}if(i.isComplex===!0){let t=n(this,r,`m`,c).call(this,i.type);for(let i=0;i<o;i++){let o=s[i]??{};n(this,r,`m`,e).call(this,t,o,a)}}else n(this,r,`m`,d).call(this,i.type)(t,i.defaultValue,a,i.arrayLength)}else if(i.isComplex===!0){let o=n(this,r,`m`,c).call(this,i.type),s=t??{};n(this,r,`m`,e).call(this,o,s,a)}else n(this,r,`m`,u).call(this,i.type)(t,i.defaultValue,a)}},c=function(e){let t=n(this,a,`f`).get(e);if(t==null)throw Error(`Unrecognized complex type ${e}`);return t},l=function(e){let t=h.get(e);if(t==null)throw e===`wstring`&&v(),Error(`Unrecognized primitive type ${e}`);return t},u=function(e){let t=g.get(e);if(t==null)throw Error(`Unrecognized primitive type ${e}`);return t},d=function(e){let t=_.get(e);if(t==null)throw Error(`Unrecognized primitive type ${e}[]`);return t};function y(e){return e.definitions.length>0&&e.definitions.every(e=>e.isConstant)}function b(e){let t=e?.length;return typeof t==`number`?t:0}function x(e,t,n){let r=typeof e==`boolean`?e:t??!1;n.int8(+!!r)}function S(e,t,n){n.int8(typeof e==`number`?e:t??0)}function C(e,t,n){n.uint8(typeof e==`number`?e:t??0)}function w(e,t,n){n.int16(typeof e==`number`?e:t??0)}function T(e,t,n){n.uint16(typeof e==`number`?e:t??0)}function E(e,t,n){n.int32(typeof e==`number`?e:t??0)}function D(e,t,n){n.uint32(typeof e==`number`?e:t??0)}function O(e,t,n){typeof e==`bigint`?n.int64(e):typeof e==`number`?n.int64(BigInt(e)):n.int64(t??0n)}function k(e,t,n){typeof e==`bigint`?n.uint64(e):typeof e==`number`?n.uint64(BigInt(e)):n.uint64(t??0n)}function A(e,t,n){n.float32(typeof e==`number`?e:t??0)}function j(e,t,n){n.float64(typeof e==`number`?e:t??0)}function M(e,t,n){n.string(typeof e==`string`?e:t??``)}function N(e,t,n){if(e==null){n.int32(0),n.uint32(0);return}let r=e;n.int32(r.sec??0),n.uint32(r.nsec??r.nanosec??0)}function P(e,t,n,r){if(Array.isArray(e)){let t=new Int8Array(e);n.int8Array(t)}else n.int8Array(t??new Int8Array(r??0).fill(0))}function ee(e,t,n,r){if(e instanceof Int8Array)n.int8Array(e);else if(Array.isArray(e)){let t=new Int8Array(e);n.int8Array(t)}else n.int8Array(t??new Int8Array(r??0).fill(0))}function te(e,t,n,r){if(e instanceof Uint8Array)n.uint8Array(e);else if(e instanceof Uint8ClampedArray)n.uint8Array(new Uint8Array(e));else if(Array.isArray(e)){let t=new Uint8Array(e);n.uint8Array(t)}else n.uint8Array(t??new Uint8Array(r??0).fill(0))}function ne(e,t,n,r){if(e instanceof Int16Array)n.int16Array(e);else if(Array.isArray(e)){let t=new Int16Array(e);n.int16Array(t)}else n.int16Array(t??new Int16Array(r??0).fill(0))}function re(e,t,n,r){if(e instanceof Uint16Array)n.uint16Array(e);else if(Array.isArray(e)){let t=new Uint16Array(e);n.uint16Array(t)}else n.uint16Array(t??new Uint16Array(r??0).fill(0))}function ie(e,t,n,r){if(e instanceof Int32Array)n.int32Array(e);else if(Array.isArray(e)){let t=new Int32Array(e);n.int32Array(t)}else n.int32Array(t??new Int32Array(r??0).fill(0))}function ae(e,t,n,r){if(e instanceof Uint32Array)n.uint32Array(e);else if(Array.isArray(e)){let t=new Uint32Array(e);n.uint32Array(t)}else n.uint32Array(t??new Uint32Array(r??0).fill(0))}function oe(e,t,n,r){if(e instanceof BigInt64Array)n.int64Array(e);else if(Array.isArray(e)){let t=new BigInt64Array(e);n.int64Array(t)}else n.int64Array(t??new BigInt64Array(r??0).fill(0n))}function se(e,t,n,r){if(e instanceof BigUint64Array)n.uint64Array(e);else if(Array.isArray(e)){let t=new BigUint64Array(e);n.uint64Array(t)}else n.uint64Array(t??new BigUint64Array(r??0).fill(0n))}function ce(e,t,n,r){if(e instanceof Float32Array)n.float32Array(e);else if(Array.isArray(e)){let t=new Float32Array(e);n.float32Array(t)}else n.float32Array(t??new Float32Array(r??0).fill(0))}function le(e,t,n,r){if(e instanceof Float64Array)n.float64Array(e);else if(Array.isArray(e)){let t=new Float64Array(e);n.float64Array(t)}else n.float64Array(t??new Float64Array(r??0).fill(0))}function ue(e,t,n,r){if(Array.isArray(e))for(let t of e)n.string(typeof t==`string`?t:``);else{let e=t??Array(r??0).fill(``);for(let t of e)n.string(t)}}function de(e,t,n,r){if(Array.isArray(e))for(let t of e)N(t,void 0,n);else{let e=Array(r).fill(void 0);for(let t of e)N(t,void 0,n)}}function fe(e,t){let n=(e-4)%t;return n>0?t-n:0}})),Op=e((e=>{var t=e&&e.__createBinding||(Object.create?(function(e,t,n,r){r===void 0&&(r=n);var i=Object.getOwnPropertyDescriptor(t,n);(!i||(`get`in i?!t.__esModule:i.writable||i.configurable))&&(i={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,i)}):(function(e,t,n,r){r===void 0&&(r=n),e[r]=t[n]})),n=e&&e.__exportStar||function(e,n){for(var r in e)r!==`default`&&!Object.prototype.hasOwnProperty.call(n,r)&&t(n,e,r)};Object.defineProperty(e,`__esModule`,{value:!0}),n(Tp(),e),n(Dp(),e)})),kp=mp(),Ap=Op();const jp=`damaged protobuf data`,Mp=4294967296,Np={double:1,float:2,group:10,message:11,bytes:12,enum:14,string:9,bool:8},Pp=e=>e===1||e===6||e===16?1:e===2||e===7||e===15?5:e===9||e===11||e===12?2:e===10?3:0;function Fp(e,t,n,r){let i=0,a=0;for(let r=0;;r++){if(t>=n||r===10)throw Error(jp);let o=e[t++],s=o&127;if(r<4?i|=s<<7*r:r===4?(i|=s<<28,a|=s>>4):a|=s<<7*r-32,!(o&128))break}return r.lo=i,r.hi=a,t}function Ip(e,t,n,r,i=!1){let a={lo:0,hi:0,p:0,s:0,e:0};for(;t<n;){t=Fp(e,t,n,a);let o=a.lo>>>3,s=a.lo&7;if(s===0)t=Fp(e,t,n,a);else if(s===1||s===5){if(a.p=t,(t+=s===1?8:4)>n)throw Error(jp)}else if(s===2){if(t=Fp(e,t,n,a),a.s=t,a.e=t+(a.lo>>>0),a.hi||a.e>n)throw Error(jp);t=a.e}else if(s===3){t=Ip(e,t,n,()=>{},!0);continue}else if(s===4&&i)return t;else throw Error(jp);r(o,s,a)}if(i)throw Error(jp);return t}const Lp=(e,t)=>d(e.subarray(t.s,t.e));function Rp(e){let t=new Map,n=new Map,r=(t,r,i)=>{let a=``,o=new Map;Ip(e,t,r,(t,n,r)=>{if(t===1)a=Lp(e,r);else if(t===2){let t=``,n=0;Ip(e,r.s,r.e,(r,i,a)=>{r===1?t=Lp(e,a):r===2&&(n=a.lo|0)}),o.has(n)||o.set(n,t)}}),n.set(i?`${i}.${a}`:a,o)},i=(n,a,o,s)=>{if(s>64)throw Error(jp);let c=``;Ip(e,n,a,(t,n,r)=>{t===1&&(c=Lp(e,r))});let l=o?`${o}.${c}`:c,u=[];Ip(e,n,a,(t,n,a)=>{if(t===2){let t={name:``,number:0,type:0,repeated:!1,oneof:!1,typeName:``,scope:l};Ip(e,a.s,a.e,(n,r,i)=>{n===1?t.name=Lp(e,i):n===3?t.number=i.lo|0:n===4?t.repeated=i.lo===3:n===5?t.type=i.lo:n===6?t.typeName=Lp(e,i):n===9&&(t.oneof=!0)}),u.push(t)}else t===3?i(a.s,a.e,l,s+1):t===4&&r(a.s,a.e,l)}),t.set(l,{list:u,fields:new Map(u.map(e=>[e.number,e]))})};Ip(e,0,e.length,(t,n,a)=>{if(t!==1)return;let o=``;Ip(e,a.s,a.e,(t,n,r)=>{t===2&&(o=Lp(e,r))}),Ip(e,a.s,a.e,(e,t,n)=>{e===4?i(n.s,n.e,o,0):e===5&&r(n.s,n.e,o)})});for(let e of t.values())for(let r of e.list)if(r.typeName){if(r.typeName.startsWith(`.`)){r.typeName=r.typeName.slice(1);continue}for(let e=r.scope;;e=e.slice(0,Math.max(0,e.lastIndexOf(`.`)))){let i=e?`${e}.${r.typeName}`:r.typeName;if(t.has(i)||n.has(i)){r.typeName=i;break}if(!e)break}}return{messages:t,enums:n}}function zp(e,t){let n=Rp(e),r=n.messages.get(t);if(!r)throw Error(`no type ${t}`);return e=>Hp(n,r,e,i(e),0,e.length,0)}const Bp=(e,t,n)=>e.enums.get(t.typeName)?.get(n)??n;function Vp(e,t){switch(t.type){case Np.string:return``;case Np.bytes:return new Uint8Array;case Np.bool:return!1;case Np.enum:{let n=e.enums.get(t.typeName);return n?n.get(0)??n.values().next().value??0:0}default:return 0}}function Hp(e,t,n,r,i,a,o){if(o>64)throw Error(jp);let s={};for(let n of t.list)n.repeated?s[n.name]=[]:!n.oneof&&n.type!==Np.message&&n.type!==Np.group&&(s[n.name]=Vp(e,n));let c=(t,i)=>{let{lo:a,hi:s,p:c}=i;switch(t.type){case 1:return r.getFloat64(c,!0);case 2:return r.getFloat32(c,!0);case 3:return(s|0)*Mp+(a>>>0);case 4:return(s>>>0)*Mp+(a>>>0);case 5:return a|0;case 6:return r.getUint32(c+4,!0)*Mp+r.getUint32(c,!0);case 7:return r.getUint32(c,!0);case 8:return a!==0||s!==0;case 9:return Lp(n,i);case 11:{let a=e.messages.get(t.typeName);return a?Hp(e,a,n,r,i.s,i.e,o+1):void 0}case 12:return n.subarray(i.s,i.e);case 13:return a>>>0;case 14:return Bp(e,t,a|0);case 15:return r.getInt32(c,!0);case 16:return r.getInt32(c+4,!0)*Mp+r.getUint32(c,!0);case 17:return a>>>1^-(a&1);case 18:{let e=-(a&1);return(s>>>1^e|0)*Mp+(((a>>>1|s<<31)^e)>>>0)}default:return}};return Ip(n,i,a,(e,r,i)=>{let a=t.fields.get(e);if(!a)return;let o=Pp(a.type);if(a.repeated&&r===2&&o!==2){let e=s[a.name],t={lo:0,hi:0,p:0,s:0,e:0};for(let r=i.s;r<i.e;){if(o===0)r=Fp(n,r,i.e,t);else if(t.p=r,(r+=o===1?8:4)>i.e)throw Error(jp);e.push(c(a,t))}return}if(r!==o)throw Error(jp);let l=c(a,i);a.repeated?s[a.name].push(l):s[a.name]=l}),s}const Up=/(^|[/.])(Image|CompressedImage|RawImage|CompressedVideo|PointCloud|PointCloud2)$/;function Wp(e){if(Up.test(e.schemaName))return`no numbers (images and point clouds are skipped).`;if(e.messageEncoding===`cdr`&&e.schemaEncoding===`ros2msg`){let t=new Ap.MessageReader((0,kp.parse)(d(e.schemaData),{ros2:!0}));return e=>t.readMessage(e)}return e.messageEncoding===`protobuf`&&e.schemaEncoding===`protobuf`?zp(e.schemaData,e.schemaName):e.messageEncoding===`json`&&(e.schemaEncoding===`jsonschema`||e.schemaEncoding===``)?e=>JSON.parse(d(e)):`message encoding ${e.messageEncoding}${e.schemaEncoding?` (schema ${e.schemaEncoding})`:``} is not supported; skipped.`}function Gp(e,t,n,r){switch(typeof e){case`number`:n.set(t,e);return;case`bigint`:n.set(t,Number(e));return;case`boolean`:n.set(t,+!!e);return;case`string`:n.set(t,e);return;case`object`:break;default:return}if(e!==null){if(Array.isArray(e)||ArrayBuffer.isView(e)&&!(e instanceof DataView)){let i=e;if(i.length>16){r.add(`${t} (over 16 values)`);return}for(let e=0;e<i.length;e++){let n=i[e];if(n!==null&&typeof n!=`number`&&typeof n!=`bigint`&&typeof n!=`boolean`){r.add(`${t} (arrays of messages or text)`);return}}for(let e=0;e<i.length;e++)n.set(`${t}[${e}]`,i[e]===null?NaN:Number(i[e]));return}for(let[i,a]of Object.entries(e))Gp(a,t?`${t}.${i}`:i,n,r)}}const Kp=e=>Array.isArray(e)||ArrayBuffer.isView(e)&&!(e instanceof DataView);function qp(e,t,n,r=``,i=[]){if(typeof e!=`object`||!e){t.has(r)&&n.set(r,i);return}if(Kp(e)){for(let a=0;a<Math.min(e.length,16);a++)t.has(`${r}[${a}]`)&&n.set(`${r}[${a}]`,[...i,a]);return}for(let a of Object.keys(e))qp(e[a],t,n,r?`${r}.${a}`:a,[...i,a])}function Jp(e,t){let n=e;for(let e of t){if(typeof n!=`object`||!n)return;if(typeof e==`number`){if(!Kp(n)||n.length>16)return;for(let e=0;e<n.length;e++){let t=n[e];if(t!==null&&typeof t!=`number`&&typeof t!=`bigint`&&typeof t!=`boolean`)return}let t=n[e];return t===null?NaN:t===void 0?void 0:Number(t)}if(Kp(n))return;n=n[e]}switch(typeof n){case`number`:case`string`:return n;case`bigint`:return Number(n);case`boolean`:return+!!n;default:return}}const Yp={id:`mcap`,label:`MCAP`,extensions:[`.mcap`],sniff:e=>f(e,`‰MCAP0\r
68
+ `)},Xp=`damaged LZ4 data`;function Zp(e,t){let n=new Uint8Array(t),r=0,i=0,a=()=>{if(r+4>e.length)throw Error(Xp);let t=(e[r]|e[r+1]<<8|e[r+2]<<16|e[r+3]<<24)>>>0;return r+=4,t};for(;r<e.length;){let o=a();if((o&4294967280)==407710288){r+=a();continue}if(o!==407708164||r+3>e.length)throw Error(Xp);let s=e[r];if(s>>6!=1)throw Error(Xp);for(r+=3+(s&8?8:0)+(s&1?4:0);;){let o=a();if(o===0)break;let c=o&2147483647;if(r+c>e.length)throw Error(Xp);if(o&2147483648){if(i+c>t)throw Error(Xp);n.set(e.subarray(r,r+c),i),i+=c}else i=Qp(e,r,r+c,n,i);r+=c+(s&16?4:0)}s&4&&(r+=4)}if(r>e.length||i!==t)throw Error(Xp);return n}function Qp(e,t,n,r,i){let a=r=>{if(r!==15)return r;for(let i=255;i===255;r+=i){if(t>=n)throw Error(Xp);i=e[t++]}return r};for(;t<n;){let o=e[t++],s=a(o>>4);if(t+s>n||i+s>r.length)throw Error(Xp);if(r.set(e.subarray(t,t+s),i),t+=s,i+=s,t===n)return i;if(t+2>n)throw Error(Xp);let c=e[t]|e[t+1]<<8;t+=2;let l=a(o&15)+4;if(c===0||c>i||i+l>r.length)throw Error(Xp);if(c>=l)r.copyWithin(i,i-c,i-c+l);else for(let e=0;e<l;e++)r[i+e]=r[i+e-c];i+=l}throw Error(Xp)}const $p=`This MCAP file is damaged (its records could not be read).`,em=e=>e instanceof Error&&e.name===`AbortError`?e:Error($p),tm=e=>{if(e>BigInt(1073741824))throw Error($p);return Number(e)},nm={zstd:(e,t)=>pp(e,new Uint8Array(tm(t))),lz4:(e,t)=>Zp(e,tm(t))};async function rm(e){let t;try{t=await Lf.Initialize({readable:{size:async()=>BigInt(e.size),read:async(t,n)=>e.slice(Number(t),Number(n))},decompressHandlers:nm})}catch{return null}return(t.chunkIndexes.length>0||t.statistics?.messageCount===0n)&&t.chunkIndexes.every(e=>e.messageIndexOffsets.size>0)?t:null}async function*im(e,t){let n=new zf({decompressHandlers:nm});try{for await(let r of e.windows(0,e.size)){t?.throwIfAborted(),n.append(r.bytes);for(let e;e=n.nextRecord();)yield e}}catch(e){throw em(e)}}async function*am(e){try{for await(let t of e)yield t}catch(e){throw em(e)}}const om=(e,t)=>({messageEncoding:e.messageEncoding,schemaName:t?.name??``,schemaEncoding:t?.encoding??``,schemaData:t?.data??new Uint8Array});var sm=class{seen=new Map;skipped=new Set;n=0;count=0;first=null;last=null;unsorted=!1;decoder=null;id;topic;info;constructor(e,t,n){this.id=e,this.topic=t,this.info=n}add(e){if(this.count++,(this.first===null||e.logTime<this.first)&&(this.first=e.logTime),this.last!==null&&e.logTime<this.last?this.unsorted=!0:this.last=e.logTime,this.n>=100)return;if(this.n++,this.decoder===null)try{this.decoder=Wp(this.info)}catch{this.decoder=`its schema could not be read; skipped.`}if(typeof this.decoder==`string`)return;let t=new Map;try{Gp(this.decoder(e.data),``,t,this.skipped)}catch{return}for(let[e,n]of t)this.seen.has(e)||this.seen.set(e,typeof n==`string`)}};const cm=946684800n*1000000000n,lm=8192;async function*um(e,t){let n=e.plan.state,r=e=>{e.cap=e.t.samples<0?lm:Math.max(1,Math.min(lm,e.t.samples-e.start)),e.time=new Float64Array(e.cap),e.cols=e.sel.map(t=>e.t.text[t]?Array(e.cap).fill(null):new Float64Array(e.cap))},i=new Map;for(let t of e.selection){let a=n.topics[t.group],o=p(e,t.group),s={g:t.group,t:a,sel:o,text:o.map(e=>a.text[e]),decode:Wp(a.info),at:o.map(()=>void 0),want:new Set(o.map(e=>a.paths[e])),time:new Float64Array,cols:[],n:0,cap:0,start:0};r(s),i.set(a.id,s)}let a=e=>{let t=e.n===e.cap,n={group:e.g,time:t?e.time:e.time.slice(0,e.n),start:e.start,length:e.n,columns:e.cols.map(n=>t?n:n.slice(0,e.n))};return e.start+=e.n,e.n=0,r(e),n},o=0;for await(let r of t){if(++o&1023||e.signal?.throwIfAborted(),o%65536==0)for(let e of i.values())e.n&&(yield a(e));let t=i.get(r.channelId);if(!t)continue;let s;try{s=t.decode(r.data)}catch{s=void 0}if(t.want.size&&s!==void 0){let e=new Map;qp(s,t.want,e),t.sel.forEach((n,r)=>{t.at[r]??=e.get(t.t.paths[n])});for(let n of e.keys())t.want.delete(n)}t.time[t.n]=Number(r.logTime-n.t0)/1e9;for(let e=0;e<t.sel.length;e++){let n=t.at[e],r=n&&s!==void 0?Jp(s,n):void 0;t.text[e]?t.cols[e][t.n]=r===void 0?null:String(r):t.cols[e][t.n]=typeof r==`number`?r:NaN}++t.n===t.cap&&(yield a(t))}for(let e of i.values())e.n&&(yield a(e))}async function*dm(e,t,n){let r=[];for await(let i of im(e,n))i.type===`Message`&&(t.has(i.channelId)?r.push({...i,data:i.data.slice()}):yield i);yield*r.sort((e,t)=>e.logTime<t.logTime?-1:+(e.logTime>t.logTime))}const fm={...Yp,async plan(e,t){let n=await rm(t),r=[],i,a=new Map;if(n){i=n.header;for(let[e,t]of n.statistics?.channelMessageCounts??[])a.set(e,Number(t));for(let e of[...n.channelsById.values()].sort((e,t)=>e.id-t.id)){let t=new sm(e.id,e.topic,om(e,n.schemasById.get(e.schemaId)));r.push(t);for await(let r of am(n.readMessages({topics:[e.topic]})))if(r.channelId===e.id&&(t.add(r),t.n>=100))break}}else{let e=new Map,n=new Map;for await(let a of im(t))if(a.type===`Header`)i=a;else if(a.type===`Schema`)e.set(a.id,a);else if(a.type===`Channel`&&!n.has(a.id)){let t=new sm(a.id,a.topic,om(a,e.get(a.schemaId)));n.set(a.id,t),r.push(t)}else a.type===`Message`&&n.get(a.channelId)?.add(a);for(let e of r)a.set(e.id,e.count);r.sort((e,t)=>e.id-t.id)}let o=[],s=[],c=null;for(let e of r){e.first!==null&&(c===null||e.first<c)&&(c=e.first);let t=[...e.skipped],n=typeof e.decoder==`string`?e.decoder:e.n===0?`no messages; skipped.`:e.seen.size===0?`no numbers${t.length?` (skipped ${t.slice(0,5).join(`, `)})`:``}.`:null;if(n){o.push(`${e.topic}: ${n}`);continue}t.length&&o.push(`${e.topic}: skipped ${t.slice(0,5).join(`, `)}${t.length>5?`, …`:``}.`),s.push({id:e.id,topic:e.topic,info:e.info,paths:[...e.seen.keys()],text:[...e.seen.values()],samples:a.get(e.id)??-1,unsorted:e.unsorted})}let l=cn(s.map(e=>e.topic),[]),u=s.map((e,t)=>{let n=cn(e.paths);return{name:l[t],channels:n.map((t,n)=>({name:t,unit:``,...e.text[n]?{text:!0}:{}})),samples:e.samples,time:{kind:`timestamps`},rateHz:null,irregular:!0}}),d=i?.profile??``;return{format:d?`MCAP (${d})`:`MCAP`,startTime:c!==null&&c>=cm?new Date(Number(c/1000000n)).toISOString():null,groups:u,meta:i?{profile:d,library:i.library}:{},events:[],notes:o,interleaved:!n,state:{indexed:!!n,topics:s,t0:c??0n}}},async*stream(e){let t=e.plan.state,n=t.indexed?await rm(e.io):null;if(t.indexed&&!n)throw Error($p);let r=[...new Set(e.selection.map(e=>t.topics[e.group].topic))],i=new Set(e.selection.map(e=>t.topics[e.group]).filter(e=>e.unsorted).map(e=>e.id));yield*um(e,n?am(n.readMessages({topics:r})):dm(e.io,i,e.signal))},async*streamGroup(e,t){let n=await rm(e.io);if(!n)throw Error($p);yield*um(e,am(n.readMessages({topics:[e.plan.state.topics[t].topic]})))}},pm=[64,20,17,74,159,228,207,17,153,0,80,81,68,73,70,0],mm={id:`pqdif`,label:`PQDIF (IEEE 1159.3)`,extensions:[`.pqd`],sniff:e=>e.length>=64&&pm.every((t,n)=>e[n]===t)},hm={container:`89738606-f1c3-11cf-9d89-0080c72e70a3`,dataSource:`89738619-f1c3-11cf-9d89-0080c72e70a3`,monitorSettings:`b48d858c-f5f5-11cf-9d89-0080c72e70a3`,observation:`8973861a-f1c3-11cf-9d89-0080c72e70a3`},Y={title:`8973860d-f1c3-11cf-9d89-0080c72e70a3`,compressionStyle:`8973861b-f1c3-11cf-9d89-0080c72e70a3`,compressionAlgorithm:`8973861c-f1c3-11cf-9d89-0080c72e70a3`,dataSourceName:`b48d8587-f5f5-11cf-9d89-0080c72e70a3`,channelDefinitions:`b48d858d-f5f5-11cf-9d89-0080c72e70a3`,oneChannelDefinition:`b48d858e-f5f5-11cf-9d89-0080c72e70a3`,channelDefinitionIndex:`b48d858f-f5f5-11cf-9d89-0080c72e70a3`,channelName:`b48d8590-f5f5-11cf-9d89-0080c72e70a3`,phaseId:`b48d8591-f5f5-11cf-9d89-0080c72e70a3`,quantityTypeId:`b48d8592-f5f5-11cf-9d89-0080c72e70a3`,quantityMeasuredId:`c690e872-f755-11cf-9d89-0080c72e70a3`,seriesDefinitions:`b48d8598-f5f5-11cf-9d89-0080c72e70a3`,oneSeriesDefinition:`b48d859a-f5f5-11cf-9d89-0080c72e70a3`,valueTypeId:`b48d859c-f5f5-11cf-9d89-0080c72e70a3`,quantityUnitsId:`b48d859b-f5f5-11cf-9d89-0080c72e70a3`,quantityCharacteristicId:`3d786f9e-f76e-11cf-9d89-0080c72e70a3`,storageMethodId:`b48d85a1-f5f5-11cf-9d89-0080c72e70a3`,valueTypeName:`b48d859d-f5f5-11cf-9d89-0080c72e70a3`,useTransducer:`62f28181-f9c4-11cf-9d89-0080c72e70a3`,channelSettingsArray:`62f28182-f9c4-11cf-9d89-0080c72e70a3`,oneChannelSetting:`3d786f9a-f76e-11cf-9d89-0080c72e70a3`,xdSystemSideRatio:`62f2818a-f9c4-11cf-9d89-0080c72e70a3`,xdMonitorSideRatio:`62f2818b-f9c4-11cf-9d89-0080c72e70a3`,observationName:`3d786f8a-f76e-11cf-9d89-0080c72e70a3`,timeStart:`3d786f8c-f76e-11cf-9d89-0080c72e70a3`,timeTriggered:`3d786f8e-f76e-11cf-9d89-0080c72e70a3`,channelInstances:`3d786f91-f76e-11cf-9d89-0080c72e70a3`,oneChannelInstance:`3d786f92-f76e-11cf-9d89-0080c72e70a3`,seriesInstances:`3d786f93-f76e-11cf-9d89-0080c72e70a3`,oneSeriesInstance:`3d786f94-f76e-11cf-9d89-0080c72e70a3`,seriesScale:`3d786f96-f76e-11cf-9d89-0080c72e70a3`,seriesOffset:`3d786f97-f76e-11cf-9d89-0080c72e70a3`,seriesValues:`3d786f99-f76e-11cf-9d89-0080c72e70a3`,seriesShareChannelIndex:`8973861f-f1c3-11cf-9d89-0080c72e70a3`,seriesShareSeriesIndex:`89738620-f1c3-11cf-9d89-0080c72e70a3`},gm={"67f6af87-f753-11cf-9d89-0080c72e70a3":[`histogram`,`histograms`],"67f6af88-f753-11cf-9d89-0080c72e70a3":[`3D histogram`,`3D histograms`],"67f6af89-f753-11cf-9d89-0080c72e70a3":[`CPF curve`,`CPF curves`],"67f6af8b-f753-11cf-9d89-0080c72e70a3":[`magnitude-duration table`,`magnitude-duration tables`],"67f6af8d-f753-11cf-9d89-0080c72e70a3":[`magnitude-duration table`,`magnitude-duration tables`],"67f6af8e-f753-11cf-9d89-0080c72e70a3":[`magnitude-duration table`,`magnitude-duration tables`]},_m={"67f6af97-f753-11cf-9d89-0080c72e70a3":``,"67f6af98-f753-11cf-9d89-0080c72e70a3":`Min`,"67f6af99-f753-11cf-9d89-0080c72e70a3":`Max`,"67f6af9a-f753-11cf-9d89-0080c72e70a3":`Avg`,"67f6af9b-f753-11cf-9d89-0080c72e70a3":`Inst`,"3d786f9d-f76e-11cf-9d89-0080c72e70a3":`Angle`,"dc762340-3c56-11d2-ae44-0060083a2628":`Angle Min`,"dc762341-3c56-11d2-ae44-0060083a2628":`Angle Max`,"dc762342-3c56-11d2-ae44-0060083a2628":`Angle Avg`,"67f6af9c-f753-11cf-9d89-0080c72e70a3":`P1`,"67f6af9d-f753-11cf-9d89-0080c72e70a3":`P5`,"67f6af9e-f753-11cf-9d89-0080c72e70a3":`P10`,"67f6af9f-f753-11cf-9d89-0080c72e70a3":`P90`,"c690e860-f755-11cf-9d89-0080c72e70a3":`P95`,"c690e861-f755-11cf-9d89-0080c72e70a3":`P99`,"c690e868-f755-11cf-9d89-0080c72e70a3":`Freq`,"c690e870-f755-11cf-9d89-0080c72e70a3":`Count`,"b82b5c82-55c7-11d5-a4b3-444553540000":`Status`},vm={"a6b31adf-b451-11d1-ae17-0060083a2628":``,"a6b31add-b451-11d1-ae17-0060083a2628":``,"a6b31ae9-b451-11d1-ae17-0060083a2628":`Spectra`,"a6b31ae2-b451-11d1-ae17-0060083a2628":`Peak`,"a6b31ae5-b451-11d1-ae17-0060083a2628":`RMS`,"a6b31adc-b451-11d1-ae17-0060083a2628":`HRMS`,"07ef68af-9ff5-11d2-b30b-006008b37183":`Frequency`,"a6b31aec-b451-11d1-ae17-0060083a2628":`THD`,"a6b31ad4-b451-11d1-ae17-0060083a2628":`EvenTHD`,"a6b31ae0-b451-11d1-ae17-0060083a2628":`OddTHD`,"a6b31ad2-b451-11d1-ae17-0060083a2628":`Crest factor`,"a6b31adb-b451-11d1-ae17-0060083a2628":`FormFactor`,"a6b31ad0-b451-11d1-ae17-0060083a2628":`ArithSum`,"a6b31ae7-b451-11d1-ae17-0060083a2628":`S0S1`,"a6b31ae8-b451-11d1-ae17-0060083a2628":`S2S1`,"a6b31aea-b451-11d1-ae17-0060083a2628":`Pos seq`,"d71a4b91-3c92-11d4-9f2c-002078e0b723":`Neg seq`,"d71a4b92-3c92-11d4-9f2c-002078e0b723":`Zero seq`,"a6b31ad1-b451-11d1-ae17-0060083a2628":`Unbalance`,"f3d216e0-2aa5-11d5-a4b3-444553540000":`TotalTHDRMS`,"f3d216e1-2aa5-11d5-a4b3-444553540000":`OddTHDRMS`,"f3d216e2-2aa5-11d5-a4b3-444553540000":`EvenTHDRMS`,"f3d216e3-2aa5-11d5-a4b3-444553540000":`TID`,"f3d216e4-2aa5-11d5-a4b3-444553540000":`TIDRMS`,"f3d216e5-2aa5-11d5-a4b3-444553540000":`IHRMS`,"53be6ba8-0789-455b-9a95-da128683dda7":`SpectraHGroup`,"5e51e006-9c95-4c5e-878f-7ca87c0d2a0e":`SpectraIGroup`,"a6b31aeb-b451-11d1-ae17-0060083a2628":`TIF`,"a6b31ad6-b451-11d1-ae17-0060083a2628":`FlkrMagAvg`,"a6b31ad8-b451-11d1-ae17-0060083a2628":`FlkrMaxDVV`,"a6b31ad5-b451-11d1-ae17-0060083a2628":`FlkrFreqMax`,"a6b31ad7-b451-11d1-ae17-0060083a2628":`FlkrMagMax`,"a6b31ada-b451-11d1-ae17-0060083a2628":`FlkrWgtAvg`,"a6b31ad9-b451-11d1-ae17-0060083a2628":`FlkrSpectrum`,"515bf320-71ca-11d4-a4b3-444553540000":`Pst`,"515bf321-71ca-11d4-a4b3-444553540000":`Plt`,"f3d216e6-2aa5-11d5-a4b3-444553540000":`TIFRMS`,"2257ec05-06ea-4709-b43a-0c00534d554a":`FlkrPLTSlide`,"4d693eec-5d1d-4531-993a-793b5356c63d":`FlkrPiLPF`,"126de61c-6691-4d16-8fdf-46482bca4694":`FlkrPiMax`,"e065b621-ffdb-4598-9330-4d09353988b6":`FlkrPiRoot`,"7d11f283-1ce7-4e58-8af0-79048793b8a7":`FlkrPiRootLPF`,"a6b31ade-b451-11d1-ae17-0060083a2628":`IT`,"07ef68a0-9ff5-11d2-b30b-006008b37183":`RMSDemand`,"8786ca10-9113-11d3-b930-0050da2b1f4d":`ANSITDF`,"8786ca11-9113-11d3-b930-0050da2b1f4d":`K-factor`,"f3d216e7-2aa5-11d5-a4b3-444553540000":`TDD`,"72e82a44-336c-11d5-a4b3-444553540000":`RMSPeakDemand`,"a6b31ae1-b451-11d1-ae17-0060083a2628":`P`,"a6b31ae4-b451-11d1-ae17-0060083a2628":`Q`,"a6b31ae6-b451-11d1-ae17-0060083a2628":`S`,"a6b31ae3-b451-11d1-ae17-0060083a2628":`PF`,"a6b31ad3-b451-11d1-ae17-0060083a2628":`DF`,"07ef68a1-9ff5-11d2-b30b-006008b37183":`PDemand`,"07ef68a2-9ff5-11d2-b30b-006008b37183":`QDemand`,"07ef68a3-9ff5-11d2-b30b-006008b37183":`SDemand`,"07ef68a4-9ff5-11d2-b30b-006008b37183":`DFDemand`,"07ef68a5-9ff5-11d2-b30b-006008b37183":`PFDemand`,"672d0305-7810-11d4-a4b3-444553540000":`PPredDemand`,"672d0306-7810-11d4-a4b3-444553540000":`QPredDemand`,"672d0307-7810-11d4-a4b3-444553540000":`SPredDemand`,"672d030a-7810-11d4-a4b3-444553540000":`PCoQDemand`,"672d030b-7810-11d4-a4b3-444553540000":`PCoSDemand`,"672d030d-7810-11d4-a4b3-444553540000":`QCoPDemand`,"672d030e-7810-11d4-a4b3-444553540000":`QCoSDemand`,"07ef68ad-9ff5-11d2-b30b-006008b37183":`DFCoSDemand`,"07ef68ae-9ff5-11d2-b30b-006008b37183":`PFCoSDemand`,"672d0308-7810-11d4-a4b3-444553540000":`PFCoPDemand`,"672d0309-7810-11d4-a4b3-444553540000":`PFCoQDemand`,"672d030f-7810-11d4-a4b3-444553540000":`AngleFund`,"672d0310-7810-11d4-a4b3-444553540000":`QFund`,"672d0311-7810-11d4-a4b3-444553540000":`PFVector`,"672d0312-7810-11d4-a4b3-444553540000":`DFVector`,"672d0314-7810-11d4-a4b3-444553540000":`SVector`,"672d0315-7810-11d4-a4b3-444553540000":`SVectorFund`,"672d0316-7810-11d4-a4b3-444553540000":`SFund`,"672d0317-7810-11d4-a4b3-444553540000":`SCoPDemand`,"672d0318-7810-11d4-a4b3-444553540000":`SCoQDemand`,"1c39fb00-a6aa-11d4-a4b3-444553540000":`PFArith`,"1c39fb01-a6aa-11d4-a4b3-444553540000":`DFArith`,"1c39fb02-a6aa-11d4-a4b3-444553540000":`SArith`,"1c39fb03-a6aa-11d4-a4b3-444553540000":`SArithFund`,"72e82a43-336c-11d5-a4b3-444553540000":`SPeakDemand`,"72e82a42-336c-11d5-a4b3-444553540000":`QPeakDemand`,"72e82a41-336c-11d5-a4b3-444553540000":`PPeakDemand`,"b82b5c80-55c7-11d5-a4b3-444553540000":`PHarmonic`,"b82b5c81-55c7-11d5-a4b3-444553540000":`PHarmonicUnsigned`,"1cdda475-1ebb-42d8-8087-d01b0b5cfa97":`PFund`,"07ef68a6-9ff5-11d2-b30b-006008b37183":`PIntg`,"07ef68a7-9ff5-11d2-b30b-006008b37183":`PIntgPos`,"672d0300-7810-11d4-a4b3-444553540000":`PIntgPosFund`,"07ef68a8-9ff5-11d2-b30b-006008b37183":`PIntgNeg`,"672d0301-7810-11d4-a4b3-444553540000":`PIntgNegFund`,"07ef68a9-9ff5-11d2-b30b-006008b37183":`QIntg`,"07ef68aa-9ff5-11d2-b30b-006008b37183":`QIntgPos`,"672d0303-7810-11d4-a4b3-444553540000":`QIntgPosFund`,"672d0304-7810-11d4-a4b3-444553540000":`QIntgNegFund`,"07ef68ab-9ff5-11d2-b30b-006008b37183":`QIntgNeg`,"07ef68ac-9ff5-11d2-b30b-006008b37183":`SIntg`,"672d0313-7810-11d4-a4b3-444553540000":`SIntgFund`,"f098a9a0-3ee4-11d5-a4b3-444553540000":`PIVLIntg`,"f098a9a1-3ee4-11d5-a4b3-444553540000":`PIVLIntgPos`,"f098a9a2-3ee4-11d5-a4b3-444553540000":`PIVLIntgPosFund`,"f098a9a3-3ee4-11d5-a4b3-444553540000":`PIVLIntgNeg`,"f098a9a4-3ee4-11d5-a4b3-444553540000":`PIVLIntgNegFund`,"f098a9a5-3ee4-11d5-a4b3-444553540000":`QIVLIntg`,"f098a9a6-3ee4-11d5-a4b3-444553540000":`QIVLIntgPos`,"f098a9a7-3ee4-11d5-a4b3-444553540000":`QIVLIntgPosFund`,"f098a9a8-3ee4-11d5-a4b3-444553540000":`QIVLIntgNegFund`,"f098a9a9-3ee4-11d5-a4b3-444553540000":`QIVLIntgNeg`,"f098a9aa-3ee4-11d5-a4b3-444553540000":`SIVLIntg`,"f098a9ab-3ee4-11d5-a4b3-444553540000":`SIVLIntgFund`,"d347ba65-e34c-11d4-82d9-00e09872a094":`DAxisField`,"d347ba64-e34c-11d4-82d9-00e09872a094":`QAxis`,"d347ba62-e34c-11d4-82d9-00e09872a094":`Rotational`,"d347ba63-e34c-11d4-82d9-00e09872a094":`DAxis`,"d347ba61-e34c-11d4-82d9-00e09872a094":`Linear`,"5202bd07-245c-11d5-a4b3-444553540000":`TransferFunc`,"b82b5c83-55c7-11d5-a4b3-444553540000":`Status`},ym=`This PQDIF file is damaged.`,bm=()=>{throw Error(ym)},xm=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,`0`));function Sm(e,t){let n=n=>xm[e[t+n]];return`${n(3)}${n(2)}${n(1)}${n(0)}-${n(5)}${n(4)}-${n(7)}${n(6)}-${n(8)}${n(9)}-${n(10)}${n(11)}${n(12)}${n(13)}${n(14)}${n(15)}`}const Cm={1:1,2:2,3:4,10:1,11:2,20:1,21:2,22:4,30:1,31:2,32:4,40:4,41:8,42:8,43:16,50:12,60:16},wm=e=>Cm[e]??0;async function Tm(e,t){if(t<4)return[];let n=Math.floor(t/28)+1,r=async t=>{let n=await e(t,4);return new DataView(n.buffer,n.byteOffset,4).getInt32(0,!0)},i=async(a,o)=>{(o>32||a+4>t)&&bm();let s=await r(a);(s<0||a+4+s*28>t||(n-=s)<0)&&bm();let c=await e(a+4,s*28),l=new DataView(c.buffer,c.byteOffset,c.byteLength),u=[];for(let n=0,d=0;n<s;n++,d+=28){let n=c[d+16],s=c[d+17],f={tag:Sm(c,d),type:n,phys:s,at:a+4+d+20,size:1,kids:[],bytes:null},p=Cm[s]??0,m=n===2&&c[d+18];if(!m){let e=l.getInt32(d+20,!0);(e<0||e>=t)&&bm(),f.at=e}if(n===1)f.kids=await i(f.at,o+1);else if(n===3){if(!p||f.at+4>t)continue;f.size=await r(f.at),f.at+=4,(f.size<0||f.at+f.size*p>t)&&bm(),f.size*p<=65536&&(f.bytes=(await e(f.at,f.size*p)).slice())}else if(n===2){if(!p||f.at+p>t)continue;f.bytes=m?c.slice(d+20,d+20+p):(await e(f.at,p)).slice()}else continue;u.push(f)}return u};return i(0,0)}async function Em(e,t){return t.bytes??=await e(t.at,t.size*wm(t.phys)),t.bytes}function Dm(e,t,n){switch(t){case 1:case 10:case 30:return e.getUint8(n);case 2:case 11:case 31:return e.getUint16(n,!0);case 3:case 32:return e.getUint32(n,!0);case 20:return e.getInt8(n);case 21:return e.getInt16(n,!0);case 22:return e.getInt32(n,!0);case 40:return e.getFloat32(n,!0);case 41:return e.getFloat64(n,!0);default:return NaN}}const Om=e=>{if(!e.bytes)throw Error(ym);return new DataView(e.bytes.buffer,e.bytes.byteOffset,e.bytes.byteLength)},km=(e,t=0)=>Dm(Om(e),e.phys,t*(Cm[e.phys]??0)),Am=(e,t=0)=>{let n=Om(e);return[n.getUint32(t*12,!0),n.getFloat64(t*12+4,!0)]},jm=([e,t])=>(e-25569)*86400+t;function Mm(e){if(!e||e.type!==3||!e.bytes)return``;let t=e.phys===11?new TextDecoder(`utf-16le`).decode(e.bytes):new TextDecoder(`latin1`).decode(e.bytes),n=t.indexOf(`\0`);return(n<0?t:t.slice(0,n)).trim()}const Nm=e=>e&&e.phys===60&&e.bytes?Sm(e.bytes,0):``,X=(e,t)=>e?.find(e=>e.tag===t),Pm=(e,t)=>e?.filter(e=>e.tag===t)??[];async function Fm(e){let t=[];for(let n=0;;){n+64>e.size&&bm();let r=await e.read(n,64);Sm(r,0)!==`4a111440-e49f-11cf-9900-505144494600`&&bm();let i=new DataView(r.buffer,r.byteOffset,r.byteLength),a=i.getInt32(36,!0),o=i.getInt32(40,!0);if((a<0||n+64+a>e.size)&&bm(),t.push({type:Sm(r,16),body:n+64,size:a}),o===0||o===e.size)return t;(o<n+64+a||o>e.size)&&bm(),n=o}}async function Im(e,t,n){let r=await e.slice(t.body,t.size);return!n||r.length===0?r:it(r,-1,Math.min(1073741824,w(r.length)))}async function Lm(e,t,n){if(n){let n=await Im(e,t,!0);return{size:n.length,read:async(e,t)=>n.subarray(e,e+t)}}return{size:t.size,read:(n,r)=>e.read(t.body+n,r)}}const Rm=65536,zm=new Set([10,11,42,43,50,60]),Bm=[``,`V`,`I`,`Power`,`Energy`,`Temperature`,`Pressure`,`Charge`,`Electric field`,`Magnetic field`,`Velocity`,`Bearing`,`Force`,`Torque`,`Position`,`Flux linkage`,`Flux density`,`Status`],Vm=[``,`A-N`,`B-N`,`C-N`,`N-G`,`A-B`,`B-C`,`C-A`,`Residual`,`Net`,`Pos seq`,`Neg seq`,`Zero seq`,`Total`,`L-N avg`,`L-L avg`,`Worst`,`Plus`,`Minus`],Hm=`..s.cycles...V.A.VA.W.var.ohm.S.V/A.J.Hz.°C.°.dB.%.pu.samples.varh.Wh.VAh.m/s.mph.bar.Pa.N.N·m.rpm.rad/s.m.Wb-turns.T.Wb.V/V.A/A.A/V`.split(`.`),Um=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),Wm=e=>e&&e.type===2?km(e):0,Gm=(e,t)=>(e[0]-t[0])*86400+(e[1]-t[1]);function Km(e){let t=Pm(X(e,Y.channelDefinitions)?.kids,Y.oneChannelDefinition).map(e=>({name:Mm(X(e.kids,Y.channelName)),phase:Wm(X(e.kids,Y.phaseId)),measured:Wm(X(e.kids,Y.quantityMeasuredId)),quantityType:Nm(X(e.kids,Y.quantityTypeId)),series:Pm(X(e.kids,Y.seriesDefinitions)?.kids,Y.oneSeriesDefinition).map(e=>({valueType:Nm(X(e.kids,Y.valueTypeId)),units:Wm(X(e.kids,Y.quantityUnitsId)),characteristic:Nm(X(e.kids,Y.quantityCharacteristicId)),storage:Wm(X(e.kids,Y.storageMethodId))||1,name:Mm(X(e.kids,Y.valueTypeName))}))}));return{name:Mm(X(e,Y.dataSourceName)),defs:t}}function qm(e){let t=new Map;for(let n of Pm(X(e,Y.channelSettingsArray)?.kids,Y.oneChannelSetting)){let e=Wm(X(n.kids,Y.channelDefinitionIndex));if(t.has(e))continue;let r=X(n.kids,Y.xdSystemSideRatio),i=X(n.kids,Y.xdMonitorSideRatio);t.set(e,r&&i?Wm(r)/Wm(i):null)}return{useTransducer:Wm(X(e,Y.useTransducer))!==0,ratio:t}}const Jm=e=>Pm(X(e,Y.channelInstances)?.kids,Y.oneChannelInstance),Ym=e=>Pm(X(e?.kids,Y.seriesInstances)?.kids,Y.oneSeriesInstance);function Xm(e,t,n,r=0){let i=Ym(e[t])[n]?.kids;if(!i)return{};let a=X(i,Y.seriesShareChannelIndex),o=X(i,Y.seriesShareSeriesIndex),s=a&&o&&r<8?Xm(e,Wm(a),Wm(o),r+1):{},c=X(i,Y.seriesValues);return{values:s.values??(c?.type===3?c:void 0),scale:X(i,Y.seriesScale)??s.scale,offset:X(i,Y.seriesOffset)??s.offset}}const Zm=(e,t)=>t&2?[e.scale?km(e.scale):1,e.offset?km(e.offset):0]:[1,0];function Qm(e,t){let n=e.values,[r,i]=Zm(e,t);return{at:n.at,phys:n.phys,size:n.size,storage:t,scale:r,offset:i}}const $m=e=>(e.storage&4)!=0&&e.phys!==50;function eh(e){let t=km(e,0);if(!(Number.isInteger(t)&&t>=0&&1+2*t<=e.size))throw Error(ym);for(let n=0;n<t;n++){let t=km(e,1+2*n);if(!(Number.isInteger(t)&&t>=0))throw Error(ym)}return t}function th(e,t,n){if(!$m({phys:e.phys,storage:t}))return e.size;let r=0;for(let t=0,n=eh(e);t<n;t++)r+=km(e,1+2*t);if(r>n||r>128e6)throw Error(ym);return r}async function nh(e,t,n){let r=t.values,i=2166136261,a=r.size*wm(r.phys);for(let t=0;t<a;t+=1<<20){let n=r.bytes?r.bytes.subarray(t,t+(1<<20)):await e(r.at+t,Math.min(1<<20,a-t));for(let e=0;e<n.length;e++)i=Math.imul(i^n[e],16777619)}return`${n}|${r.phys}|${r.size}|${Zm(t,n).join(`,`)}|${i>>>0}`}function rh(e,t,n){let r=Bm[e.measured]??``,i=e.measured===2&&e.phase>=1&&e.phase<=3?`ABC`[e.phase-1]:e.phase>=19&&e.phase<=34?`General ${e.phase-18}`:Vm[e.phase]??``,a=vm[t.characteristic],o=_m[t.valueType]??(t.name||`Series ${n+1}`);return a===void 0&&e.name?[e.name,o].filter(Boolean).join(` `):[...r||i?[r,i]:[e.name],a,o].filter(Boolean).join(` `)}async function ih(e,t,n,r,i){let a=wm(e.phys),o=t=>{if(e.phys===50)return t;for(let n=0;n<t.length;n++)t[n]=(e.offset+t[n]*e.scale)*i+r;return t};if($m(e)){let n={tag:``,type:3,phys:e.phys,at:0,size:e.size,kids:[],bytes:await t(e.at,e.size*a)},r=eh(n),i=0,s=0,c=0;return async(e,t)=>{let a=new Float64Array(t-e).fill(NaN);for(let e=0;e<a.length&&i<r;){let t=km(n,1+2*i),r=km(n,2+2*i),o=Math.min(t-s,a.length-e);for(let t=0;t<o;t++)a[e++]=c+(s+t)*r;s+=o,s>=t&&(c+=t*r,i++,s=0)}return o(a)}}return async(r,i)=>{let s=new Float64Array(i-r).fill(NaN),c=Math.min(i,e.size)-r;if(c>0){let i=Um(await t(e.at+r*a,c*a));if(e.phys===50)for(let e=0;e<c;e++)s[e]=Gm([i.getUint32(e*12,!0),i.getFloat64(e*12+4,!0)],n);else for(let t=0;t<c;t++)s[t]=Dm(i,e.phys,t*a)}return o(s)}}async function*ah(e,t){let n=p(e,t),r=e.plan.groups[t];if(n.length===0||r.samples<=0)return;let i=e.plan.state,a=i.groups[t],o=i.compressed?await Im(e.io,a.rec,!0):null,s=async(t,n)=>o?o.subarray(t,t+n):e.io.slice(a.rec.body+t,n),c=r.time.kind===`timestamps`?await ih(a.time,s,i.t0,a.start,1):null,l=await Promise.all(n.map(e=>ih(a.channels[e],s,i.t0,0,a.channels[e].ratio))),u=r.samples;for(let n=0;n<u;n+=Rm){e.signal?.throwIfAborted();let r=Math.min(u,n+Rm),i=c?await c(n,r):null,a=[];for(let e of l)a.push(await e(n,r));yield{group:t,time:i,start:n,length:r-n,columns:a}}}var oh=class{#e=new Map;add(e,t,n=1){if(n<=0)return;let r=this.#e.get(e);r?r.n+=n:this.#e.set(e,{many:t,n})}note(){return this.#e.size?`Skipped: ${[...this.#e].map(([e,{many:t,n}])=>`${n} ${n===1?e:t}`).join(`, `)}.`:null}};const sh={...mm,async plan(e,t){let n=await Fm(t);if(n[0].type!==hm.container)throw Error(ym);let r=async(e,n)=>{let{read:r,size:i}=await Lm(t,e,n);return{read:r,els:await Tm(r,i)}},{els:i}=await r(n[0],!1),a=Wm(X(i,Y.compressionStyle)),o=Wm(X(i,Y.compressionAlgorithm));if(a===1)throw Error(`This PQDIF file compresses the whole file, a style IEEE 1159.3 deprecated, which Kymoscope cannot read.`);if(a===2&&o!==0&&o!==1)throw Error(`This PQDIF file is compressed with algorithm ${o} (not zlib), which Kymoscope cannot read.`);let s=a===2&&o===1,c={},l=Mm(X(i,Y.title));l&&(c.title=l);let u=new oh,d=[],f=null,p=0,m=[],h=[];for(let e of n.slice(1))if(e.type===hm.dataSource){let t=Km((await r(e,s)).els);d=t.defs,c.dataSource??=t.name}else if(e.type===hm.monitorSettings)f=qm((await r(e,s)).els);else if(e.type===hm.observation){let{read:t,els:n}=await r(e,s),i=X(n,Y.timeStart);if(i?.phys!==50||i.type!==2)throw Error(ym);let a=Am(i),o=X(n,Y.timeTriggered);o?.phys===50&&o.type===2&&h.push(Am(o));let c=p++,l=Mm(X(n,Y.observationName))||`Observation ${c+1}`,g=new Map,_=Jm(n),v=0;for(let e of _)for(let t of Ym(e)){let e=X(t.kids,Y.seriesValues);e?.type===3&&(v=Math.max(v,e.size))}for(let[n,r]of _.entries()){let i=Wm(X(r.kids,Y.channelDefinitionIndex)),o=d[i];if(!o){u.add(`channel without a definition`,`channels without a definition`);continue}let s=gm[o.quantityType];if(s){u.add(...s);continue}let p=o.series.findIndex(e=>e.valueType===`c690e862-f755-11cf-9d89-0080c72e70a3`),m=p<0?{}:Xm(_,n,p);if(!m.values){u.add(`series without a time series`,`series without a time series`,o.series.length-(p<0?0:1));continue}let h=o.series[p].storage,y=await nh(t,m,h),b=g.get(y);if(!b){let n=Qm(m,h);$m(n)&&await Em(t,m.values);let r=th(m.values,h,v),i=$m(n)&&n.size>=3&&km(m.values,0)===1?km(m.values,2)*n.scale:0;b={obs:c,rec:e,name:l,start:a,time:n,samples:r,rate:i>0?1/i:null,rateStart:n.offset,channels:[]},g.set(y,b)}let x=f?.useTransducer?f.ratio.get(i)??1:1,S=Ym(r);o.series.forEach((e,t)=>{if(t===p)return;let r=t<S.length?Xm(_,n,t):{};if(!r.values){u.add(`series defined without values`,`series defined without values`);return}let i=r.values.phys;if(i===10||i===11){u.add(`text series`,`text series`);return}if(zm.has(i)){u.add(`series with values that are not numbers`,`series with values that are not numbers`);return}b.channels.push({...Qm(r,e.storage),ratio:x,name:rh(o,e,t),channel:o.name,unit:Hm[e.units]??``})})}for(let e of g.values())e.channels.length&&m.push(e)}if(m.length===0)throw Error(`This PQDIF file has no time series Kymoscope can read.`);let g=m.reduce((e,t)=>jm(t.start)<jm(e)?t.start:e,m[0].start),_=new Map,v=cn(m.map(e=>{let t=_.get(e.obs)??0;return _.set(e.obs,t+1),t?`${e.name} (${t+1})`:e.name}),[]),y=m.map((e,t)=>{let n=Gm(e.start,g),r=new Map;for(let t of e.channels)r.set(t.name.toLowerCase(),(r.get(t.name.toLowerCase())??0)+1);let i=cn(e.channels.map(e=>r.get(e.name.toLowerCase())>1&&e.channel?`${e.name} (${e.channel})`:e.name));return{name:v[t],channels:e.channels.map((e,t)=>({name:i[t],unit:e.unit})),samples:e.samples,time:e.rate?{kind:`rate`,rate:e.rate,start:n+e.rateStart}:{kind:`timestamps`},rateHz:e.rate,irregular:!0}}),b=h.map(e=>({time:Math.round(Gm(e,g)*1e6)/1e6,text:`Trigger`})).sort((e,t)=>e.time-t.time),x=[],S=u.note();S&&x.push(S),c.observations=String(p);let C={compressed:s,t0:g,groups:m.map(e=>({rec:e.rec,start:Gm(e.start,g),time:e.time,channels:e.channels.map(({at:e,phys:t,size:n,storage:r,scale:i,offset:a,ratio:o})=>({at:e,phys:t,size:n,storage:r,scale:i,offset:a,ratio:o}))}))},w=jm(g)*1e3;return{format:s?`PQDIF (zlib)`:`PQDIF`,startTime:Math.abs(w)<=864e13?new Date(w).toISOString():null,groups:y,meta:c,events:b,notes:x,state:C}},streamGroup:(e,t)=>ah(e,t),async*stream(e){for(let t of e.selection)yield*ah(e,t.group)}},ch=[`BOOLEAN`,`INT32`,`INT64`,`INT96`,`FLOAT`,`DOUBLE`,`BYTE_ARRAY`,`FIXED_LEN_BYTE_ARRAY`],lh=[`PLAIN`,`GROUP_VAR_INT`,`PLAIN_DICTIONARY`,`RLE`,`BIT_PACKED`,`DELTA_BINARY_PACKED`,`DELTA_LENGTH_BYTE_ARRAY`,`DELTA_BYTE_ARRAY`,`RLE_DICTIONARY`,`BYTE_STREAM_SPLIT`,`ALP`],uh=[`REQUIRED`,`OPTIONAL`,`REPEATED`],dh=[`UTF8`,`MAP`,`MAP_KEY_VALUE`,`LIST`,`ENUM`,`DECIMAL`,`DATE`,`TIME_MILLIS`,`TIME_MICROS`,`TIMESTAMP_MILLIS`,`TIMESTAMP_MICROS`,`UINT_8`,`UINT_16`,`UINT_32`,`UINT_64`,`INT_8`,`INT_16`,`INT_32`,`INT_64`,`JSON`,`BSON`,`INTERVAL`],fh=[`UNCOMPRESSED`,`SNAPPY`,`GZIP`,`LZO`,`BROTLI`,`LZ4`,`ZSTD`,`LZ4_RAW`],ph=[`DATA_PAGE`,`INDEX_PAGE`,`DICTIONARY_PAGE`,`DATA_PAGE_V2`],mh=[`UNORDERED`,`ASCENDING`,`DESCENDING`],hh=[`SPHERICAL`,`VINCENTY`,`THOMAS`,`ANDOYER`,`KARNEY`];function gh(e){let t=_h(e);if(t.type===1)return{type:`Point`,coordinates:vh(e,t)};if(t.type===2)return{type:`LineString`,coordinates:yh(e,t)};if(t.type===3)return{type:`Polygon`,coordinates:bh(e,t)};if(t.type===4){let n=[];for(let r=0;r<t.count;r++)n.push(vh(e,_h(e)));return{type:`MultiPoint`,coordinates:n}}else if(t.type===5){let n=[];for(let r=0;r<t.count;r++)n.push(yh(e,_h(e)));return{type:`MultiLineString`,coordinates:n}}else if(t.type===6){let n=[];for(let r=0;r<t.count;r++)n.push(bh(e,_h(e)));return{type:`MultiPolygon`,coordinates:n}}else if(t.type===7){let n=[];for(let r=0;r<t.count;r++)n.push(gh(e));return{type:`GeometryCollection`,geometries:n}}else throw Error(`Unsupported geometry type: ${t.type}`)}function _h(e){let{view:t}=e,n=t.getUint8(e.offset++)===1,r=t.getUint32(e.offset,n);e.offset+=4;let i=r%1e3,a=Math.floor(r/1e3),o=0;i>1&&i<=7&&(o=t.getUint32(e.offset,n),e.offset+=4);let s=2;return a&&s++,a===3&&s++,{littleEndian:n,type:i,dim:s,count:o}}function vh(e,t){let n=[];for(let r=0;r<t.dim;r++){let r=e.view.getFloat64(e.offset,t.littleEndian);e.offset+=8,n.push(r)}return n}function yh(e,t){let n=[];for(let r=0;r<t.count;r++)n.push(vh(e,t));return n}function bh(e,t){let{view:n}=e,r=[];for(let i=0;i<t.count;i++){let i=n.getUint32(e.offset,t.littleEndian);e.offset+=4,r.push(yh(e,{...t,count:i}))}return r}const xh=new TextDecoder(`utf-8`,{ignoreBOM:!0}),Sh=new TextDecoder,Ch={timestampFromMilliseconds(e){return new Date(Number(e))},timestampFromMicroseconds(e){return new Date(Number(e/1000n))},timestampFromNanoseconds(e){return new Date(Number(e/1000000n))},dateFromDays(e){return new Date(e*864e5)},stringFromBytes(e){return e&&xh.decode(e)},jsonFromBytes(e){return e&&JSON.parse(Sh.decode(e))},geometryFromBytes(e){return e&&gh({view:new DataView(e.buffer,e.byteOffset,e.byteLength),offset:0})},geographyFromBytes(e){return e&&gh({view:new DataView(e.buffer,e.byteOffset,e.byteLength),offset:0})},uuidFromBytes(e){if(!e)return;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,32)}};function wh(e,t,n,r){if(t&&n.endsWith(`_DICTIONARY`)){let n=e;e instanceof Uint8Array&&!(t instanceof Uint8Array)&&(n=new t.constructor(e.length));for(let r=0;r<e.length;r++)n[r]=t[e[r]];return n}else return Th(e,r)}function Th(e,t){let{element:n,parsers:r,utf8:i=!0,schemaPath:a}=t,{type:o,converted_type:s,logical_type:c}=n,l=n.repetition_type!==`REQUIRED`;if(o===`BYTE_ARRAY`&&n.name===`inline`&&a?.at(-2)?.element.logical_type?.type===`FILE`||a?.some(e=>e.element.logical_type?.type===`VARIANT`)&&o===`BYTE_ARRAY`&&s!==`UTF8`&&c?.type!==`STRING`)return e;if(s===`DECIMAL`){let t=n.scale||0,r=10**t,i=Array(e.length);for(let n=0;n<i.length;n++)e[n]instanceof Uint8Array?i[n]=t>308?Eh(e[n])*10**-t:Eh(e[n])/r:i[n]=Number(e[n])/r;return i}if(!s&&o===`INT96`)return Array.from(e).map(e=>r.timestampFromNanoseconds(Dh(e)));if(s===`DATE`)return Array.from(e).map(e=>r.dateFromDays(e));if(s===`TIMESTAMP_MILLIS`)return Array.from(e).map(e=>r.timestampFromMilliseconds(e));if(s===`TIMESTAMP_MICROS`)return Array.from(e).map(e=>r.timestampFromMicroseconds(e));if(s===`JSON`)return e.map(e=>r.jsonFromBytes(e));if(s===`BSON`)throw Error(`parquet bson not supported`);if(s===`INTERVAL`)throw Error(`parquet interval not supported`);if(c?.type===`GEOMETRY`)return e.map(e=>r.geometryFromBytes(e));if(c?.type===`GEOGRAPHY`)return e.map(e=>r.geographyFromBytes(e));if(c?.type===`UUID`)return e.map(e=>r.uuidFromBytes(e));if(s===`UTF8`||c?.type===`STRING`||i&&o===`BYTE_ARRAY`)return e.map(e=>r.stringFromBytes(e));if(s===`UINT_64`||c?.type===`INTEGER`&&c.bitWidth===64&&!c.isSigned){if(e instanceof BigInt64Array)return new BigUint64Array(e.buffer,e.byteOffset,e.length);let t=l?Array(e.length):new BigUint64Array(e.length);for(let n=0;n<t.length;n++)t[n]=e[n];return t}if(s===`UINT_32`||c?.type===`INTEGER`&&c.bitWidth===32&&!c.isSigned){if(e instanceof Int32Array)return new Uint32Array(e.buffer,e.byteOffset,e.length);let t=l?Array(e.length):new Uint32Array(e.length);for(let n=0;n<t.length;n++)t[n]=e[n]<0?4294967296+e[n]:e[n];return t}if(c?.type===`FLOAT16`)return Array.from(e).map(Oh);if(c?.type===`TIMESTAMP`){let{unit:t}=c,n=r.timestampFromMilliseconds;t===`MICROS`&&(n=r.timestampFromMicroseconds),t===`NANOS`&&(n=r.timestampFromNanoseconds);let i=Array(e.length);for(let t=0;t<i.length;t++)i[t]=n(e[t]);return i}return e}function Eh(e){if(!e.length)return 0;let t=0n;for(let n of e)t=t*256n+BigInt(n);let n=e.length*8;return t>=2n**BigInt(n-1)&&(t-=2n**BigInt(n)),Number(t)}function Dh(e){let t=(e>>64n)-2440588n,n=e&18446744073709551615n;return t*86400000000000n+n}function Oh(e){if(!e)return;let t=e[1]<<8|e[0],n=t>>15?-1:1,r=t>>10&31,i=t&1023;return r===0?n*2**-14*(i/1024):r===31?i?NaN:n*(1/0):n*2**(r-15)*(1+i/1024)}function kh(e,t,n){let r=e[t],i=[],a=1;if(r.num_children)for(;i.length<r.num_children;){let r=e[t+a],o=kh(e,t+a,[...n,r.name]);a+=o.count,i.push(o)}return{count:a,element:r,children:i,path:n}}function Ah(e,t){return jh(kh(e,0,[]),t)}function jh(e,t){let n=[e];for(let r of t){let i=e.children.find(e=>e.element.name===r);if(!i)throw Error(`parquet schema element not found: ${t}`);n.push(i),e=i}return n}function Mh(e){let t=[];function n(e){if(e.children.length)for(let t of e.children)n(t);else t.push(e.path.join(`.`))}return n(e),t}function Nh(e){let t=0;for(let{element:n}of e)n.repetition_type===`REPEATED`&&t++;return t}function Ph(e){let t=0;for(let{element:n}of e.slice(1))n.repetition_type!==`REQUIRED`&&t++;return t}function Fh(e){if(!e||e.element.converted_type!==`LIST`||e.children.length>1)return!1;let t=e.children[0];return!(t.children.length>1||t.element.repetition_type!==`REPEATED`)}function Ih(e){if(!e||e.element.converted_type!==`MAP`||e.children.length>1)return!1;let t=e.children[0];return!(t.children.length!==2||t.element.repetition_type!==`REPEATED`||t.children.find(e=>e.element.name===`key`)?.element.repetition_type===`REPEATED`||t.children.find(e=>e.element.name===`value`)?.element.repetition_type===`REPEATED`)}function Lh(e){if(e.length!==2)return!1;let[,t]=e;return!(t.element.repetition_type===`REPEATED`||t.children.length)}function Rh(e){let t={},n=0;for(;;){if(e.offset>=e.view.byteLength)throw Error(`thrift struct ended without STOP`);let r=e.view.getUint8(e.offset++),i=r&15;if(i===0)break;let a=r>>4;n=a?n+a:Hh(e),t[`field_${n}`]=zh(e,i)}return t}function zh(e,t){switch(t){case 1:return!0;case 2:return!1;case 3:return e.view.getInt8(e.offset++);case 4:case 5:return Hh(e);case 6:return Uh(e);case 7:{let t=e.view.getFloat64(e.offset,!0);return e.offset+=8,t}case 8:{let t=Bh(e);if(e.offset+t>e.view.byteLength)throw Error(`thrift binary length ${t} exceeds remaining ${e.view.byteLength-e.offset} bytes`);let n=new Uint8Array(e.view.buffer,e.view.byteOffset+e.offset,t);return e.offset+=t,n}case 9:{let t=e.view.getUint8(e.offset++),n=t&15,r=t>>4;r===15&&(r=Bh(e));let i=n===1||n===2,a=Array(r);for(let t=0;t<r;t++)a[t]=i?zh(e,3)===1:zh(e,n);return a}case 12:return Rh(e);default:throw Error(`thrift unhandled type: ${t}`)}}function Bh(e){let t=0,n=0;for(;;){let r=e.view.getUint8(e.offset++);if(t|=(r&127)<<n,!(r&128))return t;n+=7}}function Vh(e){let t=0n,n=0n;for(;;){let r=e.view.getUint8(e.offset++);if(t|=BigInt(r&127)<<n,!(r&128))return t;n+=7n}}function Hh(e){let t=Bh(e);return t>>>1^-(t&1)}function Uh(e){let t=Vh(e);return t>>1n^-(t&1n)}function Wh(e,t){let n=new Map,r=t?.find(({key:e})=>e===`geo`)?.value,i=(r&&JSON.parse(r)?.columns)??{};for(let[e,t]of Object.entries(i)){if(t.encoding!==`WKB`)continue;let r=t.edges===`spherical`?`GEOGRAPHY`:`GEOMETRY`,i=t.crs?.id??t.crs?.ids?.[0],a=i?`${i.authority}:${i.code.toString()}`:void 0;n.set(e,{type:r,crs:a})}for(let t=1;t<e.length;t++){let{logical_type:r,name:i,num_children:a,type:o}=e[t];if(a){t+=a;continue}o===`BYTE_ARRAY`&&!r&&(e[t].logical_type=n.get(i))}}const Gh=new TextDecoder(`utf-8`,{ignoreBOM:!0});function Kh(e){return e&&Gh.decode(e)}async function qh(e,{parsers:t,initialFetchSize:n=524288,geoparquet:r=!0}={}){if(!e||!(e.byteLength>=0))throw Error(`parquet expected AsyncBuffer`);let i=Math.max(0,e.byteLength-n),a=await e.slice(i,e.byteLength),o=new DataView(a);if(o.getUint32(a.byteLength-4,!0)!==827474256)throw Error(`parquet file invalid (footer != PAR1)`);let s=o.getUint32(a.byteLength-8,!0);if(s>e.byteLength-8)throw Error(`parquet metadata length ${s} exceeds available buffer ${e.byteLength-8}`);if(s+8>n){let n=e.byteLength-s-8,o=await e.slice(n,i),c=new ArrayBuffer(s+8),l=new Uint8Array(c);return l.set(new Uint8Array(o)),l.set(new Uint8Array(a),i-n),Jh(c,{parsers:t,geoparquet:r})}else return Jh(a,{parsers:t,geoparquet:r})}function Jh(e,{parsers:t,geoparquet:n=!0}={}){let r;if(e instanceof ArrayBuffer)r=new DataView(e);else if(e instanceof Uint8Array)r=new DataView(e.buffer,e.byteOffset,e.byteLength);else throw Error(`parquet expected ArrayBuffer or Uint8Array`);let i={...Ch,...t};if(r.byteLength<8)throw Error(`parquet file is too short`);if(r.getUint32(r.byteLength-4,!0)!==827474256)throw Error(`parquet file invalid (footer != PAR1)`);let a=r.byteLength-8,o=r.getUint32(a,!0);if(o>r.byteLength-8)throw Error(`parquet metadata length ${o} exceeds available buffer ${r.byteLength-8}`);let s=a-o,c=Rh({view:r,offset:s}),l=c.field_1,u=c.field_2.map(e=>({type:ch[e.field_1],type_length:e.field_2,repetition_type:uh[e.field_3],name:Kh(e.field_4),num_children:e.field_5,converted_type:dh[e.field_6],scale:e.field_7,precision:e.field_8,field_id:e.field_9,logical_type:Xh(e.field_10)})),d=u.filter(e=>e.type),f=c.field_3,p=c.field_4.map(e=>({columns:e.field_1.map((e,t)=>({file_path:Kh(e.field_1),file_offset:e.field_2,meta_data:e.field_3&&{type:ch[e.field_3.field_1],encodings:e.field_3.field_2?.map(e=>lh[e]),path_in_schema:e.field_3.field_3.map(Kh),codec:fh[e.field_3.field_4],num_values:e.field_3.field_5,total_uncompressed_size:e.field_3.field_6,total_compressed_size:e.field_3.field_7,key_value_metadata:e.field_3.field_8?.map(e=>({key:Kh(e.field_1),value:Kh(e.field_2)})),data_page_offset:e.field_3.field_9,index_page_offset:e.field_3.field_10,dictionary_page_offset:e.field_3.field_11,statistics:Qh(e.field_3.field_12,d[t],i),encoding_stats:e.field_3.field_13?.map(e=>({page_type:ph[e.field_1],encoding:lh[e.field_2],count:e.field_3})),bloom_filter_offset:e.field_3.field_14,bloom_filter_length:e.field_3.field_15,size_statistics:e.field_3.field_16&&{unencoded_byte_array_data_bytes:e.field_3.field_16.field_1,repetition_level_histogram:e.field_3.field_16.field_2,definition_level_histogram:e.field_3.field_16.field_3},geospatial_statistics:e.field_3.field_17&&{bbox:e.field_3.field_17.field_1&&{xmin:e.field_3.field_17.field_1.field_1,xmax:e.field_3.field_17.field_1.field_2,ymin:e.field_3.field_17.field_1.field_3,ymax:e.field_3.field_17.field_1.field_4,zmin:e.field_3.field_17.field_1.field_5,zmax:e.field_3.field_17.field_1.field_6,mmin:e.field_3.field_17.field_1.field_7,mmax:e.field_3.field_17.field_1.field_8},geospatial_types:e.field_3.field_17.field_2}},offset_index_offset:e.field_4,offset_index_length:e.field_5,column_index_offset:e.field_6,column_index_length:e.field_7,crypto_metadata:e.field_8,encrypted_column_metadata:e.field_9})),total_byte_size:e.field_2,num_rows:e.field_3,sorting_columns:e.field_4?.map(e=>({column_idx:e.field_1,descending:e.field_2,nulls_first:e.field_3})),file_offset:e.field_5,total_compressed_size:e.field_6,ordinal:e.field_7})),m=c.field_5?.map(e=>({key:Kh(e.field_1),value:Kh(e.field_2)})),h=Kh(c.field_6);return n&&Wh(u,m),{version:l,schema:u,num_rows:f,row_groups:p,key_value_metadata:m,created_by:h,metadata_length:o}}function Yh({schema:e}){return Ah(e,[])[0]}function Xh(e){return e?.field_1?{type:`STRING`}:e?.field_2?{type:`MAP`}:e?.field_3?{type:`LIST`}:e?.field_4?{type:`ENUM`}:e?.field_5?{type:`DECIMAL`,scale:e.field_5.field_1,precision:e.field_5.field_2}:e?.field_6?{type:`DATE`}:e?.field_7?{type:`TIME`,isAdjustedToUTC:e.field_7.field_1,unit:Zh(e.field_7.field_2)}:e?.field_8?{type:`TIMESTAMP`,isAdjustedToUTC:e.field_8.field_1,unit:Zh(e.field_8.field_2)}:e?.field_10?{type:`INTEGER`,bitWidth:e.field_10.field_1,isSigned:e.field_10.field_2}:e?.field_11?{type:`NULL`}:e?.field_12?{type:`JSON`}:e?.field_13?{type:`BSON`}:e?.field_14?{type:`UUID`}:e?.field_15?{type:`FLOAT16`}:e?.field_16?{type:`VARIANT`,specification_version:e.field_16.field_1}:e?.field_17?{type:`GEOMETRY`,crs:Kh(e.field_17.field_1)}:e?.field_18?{type:`GEOGRAPHY`,crs:Kh(e.field_18.field_1),algorithm:hh[e.field_18.field_2]}:e?.field_19?{type:`FILE`}:e}function Zh(e){if(e.field_1)return`MILLIS`;if(e.field_2)return`MICROS`;if(e.field_3)return`NANOS`;throw Error(`parquet time unit required`)}function Qh(e,t,n){return e&&{max:$h(e.field_1,t,n),min:$h(e.field_2,t,n),null_count:e.field_3,distinct_count:e.field_4,max_value:$h(e.field_5,t,n),min_value:$h(e.field_6,t,n),is_max_value_exact:e.field_7,is_min_value_exact:e.field_8}}function $h(e,t,n){let{type:r,converted_type:i,logical_type:a}=t;if(e===void 0)return e;if(r===`BOOLEAN`)return e[0]===1;if(r===`BYTE_ARRAY`)return n.stringFromBytes(e);let o=new DataView(e.buffer,e.byteOffset,e.byteLength);if(r===`FLOAT`&&o.byteLength===4)return o.getFloat32(0,!0);if(r===`DOUBLE`&&o.byteLength===8)return o.getFloat64(0,!0);if(r===`INT32`&&i===`DECIMAL`&&o.byteLength===4)return o.getInt32(0,!0)/10**(t.scale||0);if(r===`INT64`&&i===`DECIMAL`&&o.byteLength===8)return Number(o.getBigInt64(0,!0))/10**(t.scale||0);if(r===`INT32`&&i===`DATE`)return n.dateFromDays(o.getInt32(0,!0));if(r===`INT64`&&i===`TIMESTAMP_MILLIS`)return n.timestampFromMilliseconds(o.getBigInt64(0,!0));if(r===`INT64`&&i===`TIMESTAMP_MICROS`)return n.timestampFromMicroseconds(o.getBigInt64(0,!0));if(r===`INT64`&&a?.type===`TIMESTAMP`&&a?.unit===`NANOS`)return n.timestampFromNanoseconds(o.getBigInt64(0,!0));if(r===`INT64`&&a?.type===`TIMESTAMP`&&a?.unit===`MICROS`)return n.timestampFromMicroseconds(o.getBigInt64(0,!0));if(r===`INT64`&&a?.type===`TIMESTAMP`)return n.timestampFromMilliseconds(o.getBigInt64(0,!0));let s=i?.startsWith(`UINT_`)||a?.type===`INTEGER`&&!a.isSigned;if(r===`INT32`&&s&&o.byteLength===4)return o.getUint32(0,!0);if(r===`INT64`&&s&&o.byteLength===8)return o.getBigUint64(0,!0);if(r===`INT32`&&o.byteLength===4)return o.getInt32(0,!0);if(r===`INT64`&&o.byteLength===8)return o.getBigInt64(0,!0);if(i===`DECIMAL`){let n=t.scale||0;return n>308?Eh(e)*10**-n:Eh(e)/10**n}return a?.type===`FLOAT16`?Oh(e):a?.type===`UUID`?n.uuidFromBytes(e):e}function eg(e,t,n=void 0){let r={...Ch,...n},i=Rh(e);return{null_pages:i.field_1,min_values:i.field_2.map(e=>$h(e,t,r)),max_values:i.field_3.map(e=>$h(e,t,r)),boundary_order:mh[i.field_4],null_counts:i.field_5,repetition_level_histograms:i.field_6,definition_level_histograms:i.field_7}}function tg(e){let t=Rh(e);return{page_locations:t.field_1.map(e=>({offset:e.field_1,compressed_page_size:e.field_2,first_row_index:e.field_3})),unencoded_byte_array_data_bytes:t.field_2}}const ng=18446744073709551615n,rg=11400714785074694791n,ig=14029467366897019727n,ag=1609587929392839161n,og=9650029242287828579n,sg=2870177450012600261n;function cg(e,t){return(e<<t|e>>64n-t)&ng}function lg(e,t){return e=e+t*ig&ng,e=cg(e,31n),e*rg&ng}function ug(e,t){return e^=lg(0n,t),e*rg+og&ng}function dg(e,t=0n){let n=new DataView(e.buffer,e.byteOffset,e.byteLength),r=e.byteLength,i=0,a;if(r>=32){let e=t+rg+ig&ng,o=t+ig&ng,s=t,c=t-rg&ng;for(;i+32<=r;)e=lg(e,n.getBigUint64(i,!0)),i+=8,o=lg(o,n.getBigUint64(i,!0)),i+=8,s=lg(s,n.getBigUint64(i,!0)),i+=8,c=lg(c,n.getBigUint64(i,!0)),i+=8;a=cg(e,1n)+cg(o,7n)+cg(s,12n)+cg(c,18n)&ng,a=ug(a,e),a=ug(a,o),a=ug(a,s),a=ug(a,c)}else a=t+sg&ng;for(a=a+BigInt(r)&ng;i+8<=r;)a^=lg(0n,n.getBigUint64(i,!0)),a=cg(a,27n)*rg+og&ng,i+=8;for(i+4<=r&&(a^=BigInt(n.getUint32(i,!0))*rg&ng,a=cg(a,23n)*ig+ag&ng,i+=4);i<r;)a^=BigInt(n.getUint8(i))*sg&ng,a=cg(a,11n)*rg&ng,i+=1;return a^=a>>33n,a=a*ig&ng,a^=a>>29n,a=a*ag&ng,a^=a>>32n,a}const fg=new TextEncoder,pg=new Uint32Array([1203114875,1150766481,2284105051,2729912477,1884591559,770785867,2667333959,1550580529]);function mg(e,t){return Number((e>>32n)*BigInt(t)>>32n)}function hg(e){let t=new Uint32Array(8),n=Number(e&4294967295n)|0;for(let e=0;e<8;e++)t[e]=1<<(Math.imul(n,pg[e])>>>27);return t}function gg(e,t){let n=mg(t,e.length>>3)<<3,r=hg(t);for(let t=0;t<8;t++)if((e[n+t]&r[t])===0)return!1;return!0}function _g(e){let t=Rh(e),n=t.field_1;if(typeof n!=`number`||n<=0||n%32!=0||!t.field_2?.field_1||!t.field_3?.field_1||!t.field_4?.field_1)return;let{view:r,offset:i}=e;if(i+n>r.byteLength)throw Error(`parquet bloom filter truncated: need ${n} bytes, have ${r.byteLength-i}`);let a=new Uint32Array(n>>2);for(let e=0;e<a.length;e++)a[e]=r.getUint32(i+e*4,!0);return e.offset=i+n,{numBytes:n,blocks:a}}function vg(e,t){if(e==null)return;let{type:n,converted_type:r,logical_type:i}=t;if(n===`BOOLEAN`)return typeof e==`boolean`?dg(new Uint8Array([+!!e])):void 0;if(n===`FLOAT`){if(typeof e!=`number`)return;let t=new ArrayBuffer(4);return new DataView(t).setFloat32(0,e,!0),dg(new Uint8Array(t))}if(n===`DOUBLE`){if(typeof e!=`number`)return;let t=new ArrayBuffer(8);return new DataView(t).setFloat64(0,e,!0),dg(new Uint8Array(t))}if(n===`INT32`){if(r===`DATE`||r===`DECIMAL`||r===`TIME_MILLIS`||i?.type===`DATE`||i?.type===`TIME`||i?.type===`DECIMAL`||typeof e!=`number`||!Number.isInteger(e))return;let t=new ArrayBuffer(4);return new DataView(t).setInt32(0,e|0,!0),dg(new Uint8Array(t))}if(n===`INT64`){if(r===`TIMESTAMP_MILLIS`||r===`TIMESTAMP_MICROS`||r===`TIME_MICROS`||r===`DECIMAL`||i?.type===`TIMESTAMP`||i?.type===`TIME`||i?.type===`DECIMAL`)return;let t;if(typeof e==`bigint`)t=e;else if(typeof e==`number`&&Number.isSafeInteger(e))t=BigInt(e);else return;let n=new ArrayBuffer(8);return new DataView(n).setBigUint64(0,BigInt.asUintN(64,t),!0),dg(new Uint8Array(n))}if(n===`BYTE_ARRAY`)return r===`JSON`||r===`BSON`||r===`DECIMAL`||i?.type===`JSON`||i?.type===`BSON`||i?.type===`VARIANT`||i?.type===`GEOMETRY`||i?.type===`GEOGRAPHY`?void 0:typeof e==`string`?dg(fg.encode(e)):e instanceof Uint8Array?dg(e):void 0;if(n===`FIXED_LEN_BYTE_ARRAY`)return r===`DECIMAL`||r===`INTERVAL`||i?.type===`DECIMAL`||i?.type===`UUID`||i?.type===`FLOAT16`||i?.type===`GEOMETRY`||i?.type===`GEOGRAPHY`?void 0:e instanceof Uint8Array?dg(e):void 0}function yg(e){let t=new Set;return bg(e,t),t}function bg(e,t){if(e){if(`$and`in e&&Array.isArray(e.$and)){for(let n of e.$and)bg(n,t);return}if(`$or`in e&&Array.isArray(e.$or)){for(let n of e.$or)bg(n,t);return}if(!(`$nor`in e))for(let[n,r]of Object.entries(e))n.startsWith(`$`)||(typeof r==`object`&&r&&!Array.isArray(r)?(`$eq`in r||`$in`in r)&&t.add(n):t.add(n))}}function xg(e,t){let n=1e4;for(let r=0;r<t.length;r+=n)e.push(...t.slice(r,r+n))}function Sg(e,t,n=!0){if(n?e===t:e==t)return!0;if(!e||!t||typeof e!=`object`||typeof t!=`object`)return!1;if(e instanceof Uint8Array&&t instanceof Uint8Array){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}if(e instanceof Date||t instanceof Date)return e instanceof Date&&t instanceof Date&&e.getTime()===t.getTime();if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(!Sg(e[r],t[r],n))return!1;return!0}let r=Object.keys(e);if(r.length!==Object.keys(t).length)return!1;for(let i of r)if(!Sg(e[i],t[i],n))return!1;return!0}function Cg(e){if(!e)return[];if(e.length===1)return e[0];let t=[];for(let n of e)xg(t,n);return t}const wg=new TextEncoder;function Tg(e){if(!e)return[];let t=[];return`$and`in e&&Array.isArray(e.$and)?t.push(...e.$and.flatMap(Tg)):`$or`in e&&Array.isArray(e.$or)?t.push(...e.$or.flatMap(Tg)):`$nor`in e&&Array.isArray(e.$nor)?t.push(...e.$nor.flatMap(Tg)):t.push(...Object.keys(e)),[...new Set(t)]}function Eg(e){return[...new Set(Tg(e).map(e=>e.split(`.`)[0]))]}function Dg(e,t,n=!0){return`$and`in t&&Array.isArray(t.$and)?t.$and.every(t=>Dg(e,t,n)):`$or`in t&&Array.isArray(t.$or)?t.$or.some(t=>Dg(e,t,n)):`$nor`in t&&Array.isArray(t.$nor)?!t.$nor.some(t=>Dg(e,t,n)):Object.entries(t).every(([t,r])=>{let i=Lg(e,t);return typeof r!=`object`||!r||Array.isArray(r)?Sg(i,r,n):Object.entries(r||{}).every(([e,t])=>e===`$gt`?i!=null&&i>t:e===`$gte`?i!=null&&i>=t:e===`$lt`?i!=null&&i<t:e===`$lte`?i!=null&&i<=t:e===`$eq`?Sg(i,t,n):e===`$ne`?!Sg(i,t,n):e===`$in`?Array.isArray(t)&&Og(i,t,n):e===`$nin`?Array.isArray(t)&&!Og(i,t,n):e===`$not`?!Dg({value:i},{value:t},n):!0)})}function Og(e,t,n){return t.some(t=>Sg(e,t,n)||Array.isArray(e)&&e.some(e=>Sg(e,t,n)))}function kg({rowGroup:e,physicalColumns:t,filter:n,strict:r=!0,bloomFilters:i,schemaElements:a}){if(!n)return!1;if(`$and`in n&&Array.isArray(n.$and))return n.$and.some(n=>kg({rowGroup:e,physicalColumns:t,filter:n,strict:r,bloomFilters:i,schemaElements:a}));if(`$or`in n&&Array.isArray(n.$or))return n.$or.every(n=>kg({rowGroup:e,physicalColumns:t,filter:n,strict:r,bloomFilters:i,schemaElements:a}));if(`$nor`in n&&Array.isArray(n.$nor))return!1;for(let[o,s]of Object.entries(n)){let n=t.indexOf(o);if(n===-1)continue;let{min:c,max:l,min_value:u,max_value:d,null_count:f}=e.columns[n].meta_data?.statistics||{},p=u===void 0?c:u,m=d===void 0?l:d,h=p!==void 0&&m!==void 0,g=i?.[o],_=a?.[o],v=Dg({value:null},{value:s},r)&&(f===void 0||f>0);if(h&&!v&&Ag(s,p,m,r,_))return!0;for(let[e,t]of Object.entries(s||{}))if(g&&_){if(e===`$eq`){let e=vg(t,_);if(e!==void 0&&!gg(g.blocks,e))return!0}if(e===`$in`&&Array.isArray(t)&&t.length>0){let e=!0;for(let n of t){let t=vg(n,_);if(t===void 0||gg(g.blocks,t)){e=!1;break}}if(e)return!0}}}return!1}function Ag(e,t,n,r,i){if(t===void 0||n===void 0)return!1;let a=i?.type===`FLOAT`||i?.type===`DOUBLE`||i?.logical_type?.type===`FLOAT16`;for(let[o,s]of Object.entries(e||{})){let e=jg(t,s,r,i),c=jg(n,s,r,i),l=!(t instanceof Uint8Array||n instanceof Uint8Array)&&(i?.type!==`BYTE_ARRAY`||typeof s==`string`&&[...s].every(e=>e.charCodeAt(0)<=127));if(o===`$gt`&&l&&c!==void 0&&c<=0||o===`$gte`&&l&&c!==void 0&&c<0||o===`$lt`&&l&&e!==void 0&&e>=0||o===`$lte`&&l&&e!==void 0&&e>0)return!0;if(o===`$eq`){let e=jg(s,t,r,i),a=jg(s,n,r,i);if(e!==void 0&&e<0||a!==void 0&&a>0)return!0}if(o===`$ne`&&!a&&Sg(t,n,r)&&Sg(t,s,r)||o===`$in`&&Array.isArray(s)&&s.every(e=>{let a=jg(e,t,r,i),o=jg(e,n,r,i);return a!==void 0&&a<0||o!==void 0&&o>0})||o===`$nin`&&!a&&Array.isArray(s)&&Sg(t,n,r)&&s.some(e=>Sg(t,e,r)))return!0}return!1}function jg(e,t,n,r){if(r?.type===`BYTE_ARRAY`)return typeof e!=`string`||typeof t!=`string`?void 0:Mg(wg.encode(e),wg.encode(t));if(e instanceof Uint8Array||t instanceof Uint8Array)return!(e instanceof Uint8Array)||!(t instanceof Uint8Array)?void 0:Mg(e,t);if(e<t)return-1;if(e>t)return 1;if(Sg(e,t,n))return 0}function Mg(e,t){let n=Math.min(e.length,t.length);for(let r=0;r<n;r++){if(e[r]<t[r])return-1;if(e[r]>t[r])return 1}return e.length<t.length?-1:+(e.length>t.length)}function Ng(e,t){return Dg({value:null},{value:e},t)}function Pg(e,t,n,r=!0){if(!e)return;if(`$and`in e&&Array.isArray(e.$and)){let i;for(let a of e.$and)i=Fg(i,Pg(a,t,n,r));return i}if(`$or`in e&&Array.isArray(e.$or)){let i=[];for(let a of e.$or){let e=Pg(a,t,n,r);if(!e)return;i=Ig(i,e)}return i}if(`$nor`in e&&Array.isArray(e.$nor))return;let i;for(let[a,o]of Object.entries(e)){let e=t[a];if(!e)continue;let s=Ng(o,r),c=[];for(let t=0;t<e.pageStarts.length;t++){let i=e.pageStarts[t],a=t+1<e.pageStarts.length?e.pageStarts[t+1]:n,l=e.nullCounts?.[t],u=s&&(l===void 0||l>0);if(!(!e.nullPages[t]&&!u&&Ag(o,e.minValues[t],e.maxValues[t],r,e.element))){let e=c[c.length-1];e&&e[1]===i?e[1]=a:c.push([i,a])}}i=Fg(i,c)}return i}function Fg(e,t){if(!e)return t;if(!t)return e;let n=[],r=0,i=0;for(;r<e.length&&i<t.length;){let a=Math.max(e[r][0],t[i][0]),o=Math.min(e[r][1],t[i][1]);a<o&&n.push([a,o]),e[r][1]<t[i][1]?r++:i++}return n}function Ig(e,t){let n=[],r=0,i=0;for(;r<e.length||i<t.length;){let a=i>=t.length||r<e.length&&e[r][0]<=t[i][0]?e[r++]:t[i++],o=n[n.length-1];o&&a[0]<=o[1]?o[1]=Math.max(o[1],a[1]):n.push([a[0],a[1]])}return n}function Lg(e,t){let n=e;for(let e of t.split(`.`))n=n?.[e];return n}const Rg=1<<21;function zg(e){let{metadata:t,rowStart:n=0,columns:r,useOffsetIndex:i=!1}=e;if(!t)throw Error(`parquetPlan requires metadata`);let a=[],o=[],s=[],c=Bg(e);for(let e of c.groups){let t=Vg({...e,columns:r,useOffsetIndex:i});a.push(...t.groups),o.push(...t.fetches),s.push(...t.indexes)}return o.push(...Kg(s,0,Rg)),{metadata:t,rowStart:n,rowEnd:c.rowEnd,columns:r,fetches:o,groups:a}}function Bg({metadata:e,rowStart:t=0,rowEnd:n=1/0,columns:r,filter:i,filterStrict:a=!0,bloomFiltersByGroup:o,schemaElements:s,pageRangesByGroup:c,pageLocationsByGroup:l}){if(!e)throw Error(`parquetPlan requires metadata`);let u=Yh(e),d=Mh(u),f=i?{...qg(u),...s}:s,p=[],m=0;for(let s=0;s<e.row_groups.length;s++){let u=e.row_groups[s],h=Number(u.num_rows),g=m+h;if(h>0&&g>t&&m<n&&!kg({rowGroup:u,physicalColumns:d,filter:i,strict:a,bloomFilters:o?.[s],schemaElements:f})){let e=Math.max(t-m,0),i=Math.min(n-m,h),a=c?.[s],o=l?.[s],d=a?a.map(([t,n])=>[Math.max(t,e),Math.min(n,i)]).filter(([e,t])=>e<t):[[e,i]];d.length>1&&(d=u.columns.every(e=>{let t=e.meta_data?.path_in_schema[0],n=e.meta_data?.path_in_schema.join(`.`);return r&&t&&!r.includes(t)?!0:!!(e.offset_index_offset&&e.offset_index_length)||!!(n&&o?.[n])})?Hg(d,u,r,o):[[d[0][0],d[d.length-1][1]]]),d.length&&p.push({rowGroup:u,groupIndex:s,groupStart:m,groupRows:h,ranges:d,pageRanges:a,pageLocations:o})}m=g}return{groups:p,rowEnd:isFinite(n)?n:m}}function Vg({rowGroup:e,groupStart:t,groupRows:n,ranges:r,columns:i,useOffsetIndex:a=!1,pageRanges:o,pageLocations:s}){let c=[],l=[],u=[],d=r.length>1||r[0][0]>0||r[0][1]<n;for(let t of e.columns){let e=t.meta_data;if(t.file_path)throw Error(`parquet file_path not supported`);if(!e)throw Error(`parquet column metadata is undefined`);if(i&&!i.includes(e.path_in_schema[0]))continue;let n=e.dictionary_page_offset||e.data_page_offset,r=Number(n),l=Number(n+e.total_compressed_size),u=s?.[e.path_in_schema.join(`.`)];if(u&&d)c.push({columnMetadata:e,pageLocations:u,range:{startByte:r,endByte:l}});else if((a||o)&&t.offset_index_offset&&t.offset_index_length&&d){let r=Number(t.offset_index_offset);c.push({columnMetadata:e,offsetIndex:{startByte:r,endByte:r+t.offset_index_length},range:{startByte:Number(n),endByte:l}})}else c.push({columnMetadata:e,range:{startByte:r,endByte:l}})}let f=[],p;for(let e of c)`pageLocations`in e||(`offsetIndex`in e?u.push(e.offsetIndex):i?f.push(e.range):p&&e.range.endByte-p.startByte<=2097152?p.endByte=e.range.endByte:(p&&l.push(p),p={...e.range}));return p&&l.push(p),l.push(...Kg(f,8192,Rg)),{groups:r.map(([r,i])=>({chunks:c,rowGroup:e,groupStart:t,groupRows:n,selectStart:r,selectEnd:i})),fetches:l,indexes:u}}function Hg(e,t,n,r){let i=t.columns.filter(e=>!n||n.includes(e.meta_data?.path_in_schema[0]||``)).map(e=>r?.[e.meta_data?.path_in_schema.join(`.`)||``]),a=[];for(let n of e){let e=a[a.length-1],r=e&&i.some(r=>{if(!r)return!0;let i=Ug(e,r,Number(t.num_rows)),a=Ug(n,r,Number(t.num_rows));return i[0]<=a[1]&&a[0]<=i[1]});e&&r?e[1]=n[1]:a.push([...n])}return a}function Ug([e,t],n,r){let i=1/0,a=-1/0;for(let o=0;o<n.length;o++){let s=Number(n[o].first_row_index);(o+1<n.length?Number(n[o+1].first_row_index):r)>e&&s<t&&(i=Math.min(i,o),a=o)}return[i,a]}async function Wg({file:e,metadata:t,filter:n,filterStrict:r=!0,rowStart:i=0,rowEnd:a=1/0}){let o=t.row_groups.map(()=>({})),s=yg(n);if(s.size===0)return o;let c=Mh(Yh(t)),l=[],u=0;if(t.row_groups.forEach((e,t)=>{let o=Number(e.num_rows),d=u+o,f=o>0&&d>i&&u<a;if(u=d,f&&!kg({rowGroup:e,physicalColumns:c,filter:n,strict:r}))for(let n of s){let r=c.indexOf(n);if(r===-1)continue;let i=e.columns[r]?.meta_data;if(!i?.bloom_filter_offset||!i.bloom_filter_length)continue;let a=Number(i.bloom_filter_offset),o=a+i.bloom_filter_length;l.push({rgIdx:t,colName:n,startByte:a,endByte:o})}}),l.length){let t=Jg(e,{fetches:Kg(l,0,Rg)});await Promise.all(l.map(async({rgIdx:e,colName:n,startByte:r,endByte:i})=>{let a=await t.slice(r,i),s=_g({view:new DataView(a),offset:0});s&&(o[e][n]=s)}))}return o}async function Gg({file:e,metadata:t,filter:n,filterStrict:r=!0,rowStart:i=0,rowEnd:a=1/0,columns:o,bloomFiltersByGroup:s,schemaElements:c,parsers:l}){let u=t.row_groups.map(()=>void 0),d=t.row_groups.map(()=>({}));if(n&&`$nor`in n&&Array.isArray(n.$nor))return{pageRangesByGroup:u,pageLocationsByGroup:d};let f=Tg(n);if(!f.length)return{pageRangesByGroup:u,pageLocationsByGroup:d};let p=Yh(t),m=Mh(p),h={...qg(p),...c},g=[],_=[],v=[],y=0;if(t.row_groups.forEach((e,t)=>{let c=Number(e.num_rows),u=y+c,p=c>0&&u>i&&y<a;if(y=u,!p||kg({rowGroup:e,physicalColumns:m,filter:n,strict:r,bloomFilters:s?.[t],schemaElements:h}))return;let b={},x=0,S=new Set,C=!1;for(let n of f){let r=m.indexOf(n);if(r===-1)continue;let i=e.columns[r];if(!i?.meta_data||!i.column_index_offset||!i.column_index_length||!i.offset_index_offset||!i.offset_index_length)continue;let a=h[n];if(!a)continue;C=!0,S.add(n);let o=Number(i.column_index_offset),s=Number(i.offset_index_offset),c=o+i.column_index_length,u=s+i.offset_index_length;g.push({startByte:o,endByte:c},{startByte:s,endByte:u}),x++,_.push(async e=>{let[r,i]=await Promise.all([e.slice(o,c),e.slice(s,u)]),f=eg({view:new DataView(r),offset:0},a,l),p=tg({view:new DataView(i),offset:0});d[t][n]=p.page_locations,b[n]={minValues:f.min_values,maxValues:f.max_values,nullPages:f.null_pages,nullCounts:f.null_counts,pageStarts:p.page_locations.map(e=>Number(e.first_row_index)),element:a}})}if(C)for(let n of e.columns){let e=n.meta_data;if(!e)continue;let r=e.path_in_schema[0],i=e.path_in_schema.join(`.`);if(o&&!o.includes(r)||S.has(i)||!n.offset_index_offset||!n.offset_index_length)continue;S.add(i);let a=Number(n.offset_index_offset),s=a+n.offset_index_length;g.push({startByte:a,endByte:s}),x++,_.push(async e=>{let n=await e.slice(a,s),r=tg({view:new DataView(n),offset:0});d[t][i]=r.page_locations})}x&&v.push({rgIdx:t,groupRows:c,columnPages:b})}),_.length){let t=Jg(e,{fetches:Kg(g)});await Promise.all(_.map(e=>e(t)));for(let{rgIdx:e,groupRows:t,columnPages:i}of v)u[e]=Pg(n,i,t,r)}return{pageRangesByGroup:u,pageLocationsByGroup:d}}function Kg(e,t=0,n=1/0){let r=e.map(e=>({...e})).sort((e,t)=>e.startByte-t.startByte||e.endByte-t.endByte),i=[];for(let e of r){let r=i[i.length-1];r&&e.startByte<=r.endByte+t&&Math.max(r.endByte,e.endByte)-r.startByte<=n?r.endByte=Math.max(r.endByte,e.endByte):i.push(e)}return i}function qg(e){let t={};function n(e){if(e.children.length)for(let t of e.children)n(t);else t[e.path.join(`.`)]=e.element}return n(e),t}function Jg(e,{fetches:t}){let n=t.map(({startByte:t,endByte:n})=>{try{return e.slice(t,n)}catch(e){return Promise.reject(e)}});return{byteLength:e.byteLength,slice(r,i=e.byteLength){let a=t.findIndex(({startByte:e,endByte:t})=>e<=r&&i<=t);if(a<0)return e.slice(r,i);if(t[a].startByte!==r||t[a].endByte!==i){let e=r-t[a].startByte,o=i-t[a].startByte;return n[a]instanceof Promise?n[a].then(t=>t.slice(e,o)):n[a].slice(e,o)}else return n[a]}}}const Yg=new TextDecoder(`utf-8`,{ignoreBOM:!0}),Xg=new WeakMap;function Zg(e,t=Ch){if(Array.isArray(e))return e.map(e=>Zg(e,t));if(typeof e!=`object`)return e;if(`metadata`in e){let n=e_(e.metadata),r=e.typed_value&&Qg(e.typed_value,n,t),i=e.value&&n_($g(e.value),n,t);return r&&i?{...i,...r}:r??i}return e}function Qg(e,t,n){if(e instanceof Date)return e;if(e&&typeof e==`object`&&!Array.isArray(e)&&!(e instanceof Uint8Array)){if(`typed_value`in e&&e.typed_value!==null&&e.typed_value!==void 0)return Qg(e.typed_value,t,n);if(`value`in e&&e.value instanceof Uint8Array)return n_($g(e.value),t,n);if(`typed_value`in e||`value`in e)return null;let r={};for(let[i,a]of Object.entries(e))t.dictionary.includes(i)&&(r[i]=Qg(a,t,n));return r}return e instanceof Uint8Array?n_($g(e),t,n):Array.isArray(e)?e.map(e=>Qg(e,t,n)):e}function $g(e){return{view:new DataView(e.buffer,e.byteOffset,e.byteLength),offset:0}}function e_(e){let t=Xg.get(e.buffer);t||(t=new Map,Xg.set(e.buffer,t));let n=`${e.byteOffset}:${e.byteLength}`,r=t.get(n);if(r)return r;let i=$g(e),a=i.view.getUint8(i.offset++),o=a&15;if(o!==1)throw Error(`parquet unsupported variant metadata version: ${o}`);let s=(a>>4&1)==1,c=(a>>6&3)+1,l=t_(i,c),u=Array(l+1);for(let e=0;e<u.length;e++)u[e]=t_(i,c);let d=i.offset,f=Array(l);for(let t=0;t<l;t++){let n=u[t],r=u[t+1],i=new Uint8Array(e.buffer,e.byteOffset+d+n,r-n);f[t]=Yg.decode(i)}let p={dictionary:f,sorted:s};return t.set(n,p),p}function t_(e,t){let n=0;for(let r=0;r<t;r++)n|=e.view.getUint8(e.offset+r)<<r*8;return e.offset+=t,n}function n_(e,t,n){let r=e.view.getUint8(e.offset++),i=r&3,a=r>>2;if(i===0)return r_(e,a,n);if(i===2)return i_(e,a,t,n);if(i===3)return a_(e,a,t,n);let o=new Uint8Array(e.view.buffer,e.view.byteOffset+e.offset,a);return e.offset+=a,Yg.decode(o)}function r_(e,t,n){switch(t){case 0:return null;case 1:return!0;case 2:return!1;case 3:{let t=e.view.getInt8(e.offset);return e.offset+=1,t}case 4:{let t=e.view.getInt16(e.offset,!0);return e.offset+=2,t}case 5:{let t=e.view.getInt32(e.offset,!0);return e.offset+=4,t}case 6:{let t=e.view.getBigInt64(e.offset,!0);return e.offset+=8,t}case 7:{let t=e.view.getFloat64(e.offset,!0);return e.offset+=8,t}case 8:return o_(e,4);case 9:return o_(e,8);case 10:return o_(e,16);case 11:{let t=e.view.getInt32(e.offset,!0);return e.offset+=4,n.dateFromDays(t)}case 12:case 13:{let t=e.view.getBigInt64(e.offset,!0);return e.offset+=8,n.timestampFromMicroseconds(t)}case 14:{let t=e.view.getFloat32(e.offset,!0);return e.offset+=4,t}case 15:return s_(e);case 16:{let t=s_(e);return Yg.decode(t)}case 17:{let t=e.view.getBigInt64(e.offset,!0);return e.offset+=8,t}case 18:case 19:{let t=e.view.getBigInt64(e.offset,!0);return e.offset+=8,n.timestampFromNanoseconds(t)}case 20:{let t=new Uint8Array(e.view.buffer,e.view.byteOffset+e.offset,16);e.offset+=16;let n=Array.from(t,e=>e.toString(16).padStart(2,`0`)).join(``);return`${n.slice(0,8)}-${n.slice(8,12)}-${n.slice(12,16)}-${n.slice(16,20)}-${n.slice(20)}`}default:throw Error(`parquet unsupported variant primitive type: ${t}`)}}function i_(e,t,n,r){let i=(t&3)+1,a=(t>>2&3)+1,o=t>>4&1?t_(e,4):e.view.getUint8(e.offset++),s=Array(o);for(let t=0;t<o;t++)s[t]=t_(e,a);let c=Array(o+1);for(let t=0;t<c.length;t++)c[t]=t_(e,i);let l={};for(let t=0;t<o;t++){let i=n.dictionary[s[t]];l[i]=n_({view:e.view,offset:e.offset+c[t]},n,r)}return e.offset+=c[c.length-1],l}function a_(e,t,n,r){let i=t&3,a=t>>2&1,o=i+1,s=t_(e,a?4:1),c=Array(s+1);for(let t=0;t<c.length;t++)c[t]=t_(e,o);let l=e.offset,u=Array(s);for(let t=0;t<s;t++)u[t]=n_({view:e.view,offset:l+c[t]},n,r);return e.offset=l+c[c.length-1],u}function o_(e,t){let n=e.view.getUint8(e.offset);e.offset+=1;let r;if(t===4)r=BigInt(e.view.getInt32(e.offset,!0)),e.offset+=4;else if(t===8)r=e.view.getBigInt64(e.offset,!0),e.offset+=8;else{let t=e.view.getBigUint64(e.offset,!0);r=e.view.getBigInt64(e.offset+8,!0)<<64n|t,e.offset+=16}return Number(r)/10**n}function s_(e){let t=e.view.getUint32(e.offset,!0);e.offset+=4;let n=new Uint8Array(e.view.buffer,e.view.byteOffset+e.offset,t);return e.offset+=t,n}function c_(e,t,n,r,i){let a=Ph(i);if(!t?.length&&!n.length){if(!a||!r.length)return r;t=Array(r.length).fill(a)}let o=t?.length||n.length,s=i.map(({element:e})=>e.repetition_type),c=0,l=[e],u=e,d=0,f=0,p=0;if(n[0])for(;d<s.length-2&&p<n[0];)d++,s[d]!==`REQUIRED`&&(u=u.at(-1),l.push(u),f++),s[d]===`REPEATED`&&p++;for(let e=0;e<o;e++){let i=t?.length?t[e]:a,o=n[e];for(;d&&(o<p||s[d]!==`REPEATED`);)s[d]!==`REQUIRED`&&(l.pop(),f--),s[d]===`REPEATED`&&p--,d--;for(u=l.at(-1);(d<s.length-2||s[d+1]===`REPEATED`)&&(f<i||s[d+1]===`REQUIRED`);){if(d++,s[d]!==`REQUIRED`){let e=[];u.push(e),u=e,l.push(e),f++}s[d]===`REPEATED`&&p++}i===a?u.push(r[c++]):d===s.length-2?u.push(s[d+1]===`REPEATED`?[]:null):u.push([])}if(!e.length)for(let e=0;e<a;e++){let e=[];u.push(e),u=e}return e}function l_(e,t,n,r=0){let i=t.path.join(`.`),a=t.element.repetition_type===`OPTIONAL`,o=a?r+1:r;if(Fh(t)){let s=t.children[0],c=o;s.children.length===1&&(s=s.children[0],c++),l_(e,s,n,c);let l=s.path.join(`.`),u=e.get(l);if(!u)throw Error(`parquet list column missing values`);a&&u_(u,r),e.set(i,u),e.delete(l);return}if(Ih(t)){let s=t.children[0].element.name;l_(e,t.children[0].children[0],n,o+1),l_(e,t.children[0].children[1],n,o+1);let c=e.get(`${i}.${s}.key`),l=e.get(`${i}.${s}.value`);if(!c)throw Error(`parquet map column missing keys`);if(!l)throw Error(`parquet map column missing values`);if(c.length!==l.length)throw Error(`parquet map column key/value length mismatch`);let u=d_(c,l,o);a&&u_(u,r),e.delete(`${i}.${s}.key`),e.delete(`${i}.${s}.value`),e.set(i,u);return}if(t.children.length){let o=t.element.repetition_type===`REQUIRED`?r:r+1,s={};for(let r of t.children){l_(e,r,n,o);let t=e.get(r.path.join(`.`));if(!t)throw Error(`parquet struct missing child data`);s[r.element.name]=t}for(let n of t.children)e.delete(n.path.join(`.`));let c=f_(s,o);t.element.logical_type?.type===`VARIANT`&&(c=Zg(c,n)),a&&u_(c,r),e.set(i,c)}}function u_(e,t){for(let n=0;n<e.length;n++)t?u_(e[n],t-1):e[n]=e[n].length?e[n][0]:null}function d_(e,t,n){let r=[];for(let i=0;i<e.length;i++)if(n)r.push(d_(e[i],t[i],n-1));else if(e[i]){let n={};for(let r=0;r<e[i].length;r++){let a=t[i][r];n[e[i][r]]=a===void 0?null:a}r.push(n)}else r.push(void 0);return r}function f_(e,t){let n=Object.keys(e),r=e[n[0]]?.length,i=[];for(let a=0;a<r;a++){let o={};for(let t of n){if(e[t].length!==r)throw Error(`parquet struct parsing error`);o[t]=e[t][a]}t?i.push(f_(o,t-1)):i.push(o)}return i}const p_=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,0xe8d4a51000,0x9184e72a000,0x5af3107a4000,0x38d7ea4c68000,0x2386f26fc10000,0x16345785d8a0000,0xde0b6b3a7640000],m_=[1,.1,.01,.001,1e-4,1e-5,1e-6,1e-7,1e-8,1e-9,1e-10,1e-11,1e-12,1e-13,1e-14,1e-15,1e-16,1e-17,1e-18],h_=p_.slice(0,11).map(Math.fround),g_=m_.slice(0,11).map(Math.fround);function __(e,t,n){if(n===`FLOAT`)return y_(e,t);if(n===`DOUBLE`)return b_(e,t);throw Error(`ALP encoding unsupported type: ${n}`)}function v_(e){let{view:t}=e,n=t.getUint8(e.offset++);if(n!==0)throw Error(`ALP unsupported compression mode: ${n}`);let r=t.getUint8(e.offset++);if(r!==0)throw Error(`ALP unsupported integer encoding: ${r}`);let i=t.getUint8(e.offset++);if(i<3||i>15)throw Error(`ALP invalid log_vector_size: ${i}`);let a=1<<i,o=t.getInt32(e.offset,!0);e.offset+=4;let s=Math.ceil(o/a),c=e.offset;return e.offset+=s*4,{vectorSize:a,numElements:o,numVectors:s,offsetArrayStart:c}}function y_(e,t){let{view:n}=e,{vectorSize:r,numElements:i,numVectors:a,offsetArrayStart:o}=v_(e);if(i!==t)throw Error(`ALP num_elements ${i} does not match expected ${t}`);let s=new Float32Array(t),c=new Uint8Array(s.buffer);for(let t=0;t<a;t++){e.offset=o+n.getUint32(o+t*4,!0);let a=t*r,l=Math.min(r,i-a),u=n.getUint8(e.offset++),d=n.getUint8(e.offset++),f=n.getUint16(e.offset,!0);e.offset+=2;let p=n.getInt32(e.offset,!0);e.offset+=4;let m=S_(e,l,n.getUint8(e.offset++)),h=h_[d],g=g_[u];for(let e=0;e<l;e++){let t=m[e]+p|0;s[a+e]=Math.fround(Math.fround(t)*h)*g}x_(e,f,4,c,a)}return s}function b_(e,t){let{view:n}=e,{vectorSize:r,numElements:i,numVectors:a,offsetArrayStart:o}=v_(e);if(i!==t)throw Error(`ALP num_elements ${i} does not match expected ${t}`);let s=new Float64Array(t),c=new Uint8Array(s.buffer);for(let t=0;t<a;t++){e.offset=o+n.getUint32(o+t*4,!0);let a=t*r,l=Math.min(r,i-a),u=n.getUint8(e.offset++),d=n.getUint8(e.offset++),f=n.getUint16(e.offset,!0);e.offset+=2;let p=n.getBigInt64(e.offset,!0);e.offset+=8;let m=n.getUint8(e.offset++),h=p_[d],g=m_[u],_=Number(p);if(m<=32&&Number.isSafeInteger(_)){let t=S_(e,l,m);for(let e=0;e<l;e++)s[a+e]=(t[e]+_)*h*g}else{let t=C_(e,l,m);for(let e=0;e<l;e++){let n=BigInt.asIntN(64,t[e]+p);s[a+e]=Number(n)*h*g}}x_(e,f,8,c,a)}return s}function x_(e,t,n,r,i){if(!t)return;let{view:a}=e,o=e.offset,s=o+t*2,c=new Uint8Array(a.buffer,a.byteOffset+s,t*n);for(let e=0;e<t;e++){let t=(i+a.getUint16(o+e*2,!0))*n;r.set(c.subarray(e*n,(e+1)*n),t)}e.offset=s+t*n}function S_(e,t,n){let r=new Uint32Array(t);if(!n)return r;let{view:i}=e,a=e.offset,o=2**n,s=0;for(let e=0;e<t;e++){let t=a+(s>>>3),c=s&7,l=i.getUint8(t++)>>>c,u=8-c;for(;u<n;)l+=i.getUint8(t++)*2**u,u+=8;r[e]=l%o,s+=n}return e.offset=a+Math.ceil(t*n/8),r}function C_(e,t,n){let r=new BigUint64Array(t);if(!n)return r;let{view:i}=e,a=e.offset,o=(1n<<BigInt(n))-1n,s=0n,c=0,l=a;for(let e=0;e<t;e++){for(;c<n;)s|=BigInt(i.getUint8(l++))<<BigInt(c),c+=8;r[e]=s&o,s>>=BigInt(n),c-=n}return e.offset=a+Math.ceil(t*n/8),r}function w_(e,t,n){if(n instanceof Int32Array){T_(e,t,n);return}let r=Bh(e),i=Bh(e);Bh(e);let a=Uh(e),o=0;n[o++]=a;let s=r/i;for(;o<t;){let r=Uh(e),c=new Uint8Array(i);for(let t=0;t<i;t++)c[t]=e.view.getUint8(e.offset++);for(let l=0;l<i&&o<t;l++){let i=c[l];if(i){let c=0,l=s,u=(1n<<BigInt(i))-1n;for(;l&&o<t;){let t=BigInt(e.view.getUint32(e.offset,!0)>>>c)&u;for(c+=i;c>=32;)c-=32,e.offset+=4,c&&(t|=BigInt(e.view.getUint32(e.offset,!0))<<BigInt(i-c)&u);let s=r+t;a+=s,n[o++]=a,l--}l&&(e.offset+=Math.ceil((l*i+c)/8))}else for(let e=0;e<s&&o<t;e++)a+=r,n[o++]=a}}}function T_(e,t,n){let r=Bh(e),i=Bh(e);Bh(e);let a=Hh(e),o=0;n[o++]=a;let s=r/i,{view:c}=e;for(;o<t;){let r=E_(e),l=e.offset,u=l+i;for(let e=0;e<i&&o<t;e++){let i=c.getUint8(l+e),d=u+s*i/8,f=0;for(let e=0;e<s&&o<t;e++){let e=0,t=0;for(;t<i;){let n=Math.min(8-f,i-t);t<32&&(e|=(c.getUint8(u)>>>f&(1<<n)-1)<<t),t+=n,f+=n,f===8&&(f=0,u++)}a=a+r+e|0,n[o++]=a}u=d}e.offset=u}}function E_(e){let t=e.offset,n=Bh(e),r=e.offset-t===5?e.view.getUint8(t+4)>>>4&1:0;return(n>>>1|r<<31)^-(n&1)}function D_(e,t,n){let r=new Int32Array(t);w_(e,t,r);for(let i=0;i<t;i++)n[i]=new Uint8Array(e.view.buffer,e.view.byteOffset+e.offset,r[i]),e.offset+=r[i]}function O_(e,t,n){let r=new Int32Array(t);w_(e,t,r);let i=new Int32Array(t);w_(e,t,i);for(let a=0;a<t;a++){let t=new Uint8Array(e.view.buffer,e.view.byteOffset+e.offset,i[a]);r[a]?(n[a]=new Uint8Array(r[a]+i[a]),n[a].set(n[a-1].subarray(0,r[a])),n[a].set(t,r[a])):n[a]=t,e.offset+=i[a]}}function k_(e,t,n,r){r===void 0&&(r=e.view.getUint32(e.offset,!0),e.offset+=4);let i=e.offset,a=0;for(;a<n.length;){let r=Bh(e);if(r&1)a=j_(e,r,t,n,a);else{let i=r>>>1;A_(e,i,t,n,a),a+=i}}e.offset=i+r}function A_(e,t,n,r,i){let a=n+7>>3,o=0;for(let t=0;t<a;t++)o|=e.view.getUint8(e.offset++)<<(t<<3);for(let e=0;e<t;e++)r[i+e]=o}function j_(e,t,n,r,i){let a=t>>1<<3,o=(1<<n)-1,s=0;if(e.offset<e.view.byteLength)s=e.view.getUint8(e.offset++);else if(o)throw Error(`parquet bitpack offset ${e.offset} out of range`);let c=8,l=0;for(;a;)l>8?(l-=8,c-=8,s>>>=8):c-l<n?(s|=e.view.getUint8(e.offset)<<c,e.offset++,c+=8):(i<r.length&&(r[i++]=s>>l&o),a--,l+=n);return i}function M_(e,t,n,r){let i=N_(n,r),a=new Uint8Array(t*i);for(let n=0;n<i;n++)for(let r=0;r<t;r++)a[r*i+n]=e.view.getUint8(e.offset++);if(n===`FLOAT`)return new Float32Array(a.buffer);if(n===`DOUBLE`)return new Float64Array(a.buffer);if(n===`INT32`)return new Int32Array(a.buffer);if(n===`INT64`)return new BigInt64Array(a.buffer);if(n===`FIXED_LEN_BYTE_ARRAY`){let e=Array(t);for(let n=0;n<t;n++)e[n]=a.subarray(n*i,(n+1)*i);return e}throw Error(`parquet byte_stream_split unsupported type: ${n}`)}function N_(e,t){switch(e){case`INT32`:case`FLOAT`:return 4;case`INT64`:case`DOUBLE`:return 8;case`FIXED_LEN_BYTE_ARRAY`:if(!t)throw Error(`parquet byteWidth missing type_length`);return t;default:throw Error(`parquet unsupported type: ${e}`)}}function P_(e,t,n,r){if(n===0)return[];if(t===`BOOLEAN`)return F_(e,n);if(t===`INT32`)return I_(e,n);if(t===`INT64`)return L_(e,n);if(t===`INT96`)return R_(e,n);if(t===`FLOAT`)return z_(e,n);if(t===`DOUBLE`)return B_(e,n);if(t===`BYTE_ARRAY`)return V_(e,n);if(t===`FIXED_LEN_BYTE_ARRAY`){if(!r)throw Error(`parquet missing fixed length`);return H_(e,n,r)}else throw Error(`parquet unhandled type: ${t}`)}function F_(e,t){let n=Array(t);for(let r=0;r<t;r++){let t=e.offset+(r/8|0),i=r%8;n[r]=(e.view.getUint8(t)&1<<i)!=0}return e.offset+=Math.ceil(t/8),n}function I_(e,t){let n=(e.view.byteOffset+e.offset)%4?new Int32Array(U_(e.view.buffer,e.view.byteOffset+e.offset,t*4)):new Int32Array(e.view.buffer,e.view.byteOffset+e.offset,t);return e.offset+=t*4,n}function L_(e,t){let n=(e.view.byteOffset+e.offset)%8?new BigInt64Array(U_(e.view.buffer,e.view.byteOffset+e.offset,t*8)):new BigInt64Array(e.view.buffer,e.view.byteOffset+e.offset,t);return e.offset+=t*8,n}function R_(e,t){let n=Array(t);for(let r=0;r<t;r++){let t=e.view.getBigInt64(e.offset+r*12,!0),i=e.view.getInt32(e.offset+r*12+8,!0);n[r]=BigInt(i)<<64n|t}return e.offset+=t*12,n}function z_(e,t){let n=(e.view.byteOffset+e.offset)%4?new Float32Array(U_(e.view.buffer,e.view.byteOffset+e.offset,t*4)):new Float32Array(e.view.buffer,e.view.byteOffset+e.offset,t);return e.offset+=t*4,n}function B_(e,t){let n=(e.view.byteOffset+e.offset)%8?new Float64Array(U_(e.view.buffer,e.view.byteOffset+e.offset,t*8)):new Float64Array(e.view.buffer,e.view.byteOffset+e.offset,t);return e.offset+=t*8,n}function V_(e,t){let n=Array(t);for(let r=0;r<t;r++){let t=e.view.getUint32(e.offset,!0);e.offset+=4,n[r]=new Uint8Array(e.view.buffer,e.view.byteOffset+e.offset,t),e.offset+=t}return n}function H_(e,t,n){let r=Array(t);for(let i=0;i<t;i++)r[i]=new Uint8Array(e.view.buffer,e.view.byteOffset+e.offset,n),e.offset+=n;return r}function U_(e,t,n){let r=new ArrayBuffer(n);return new Uint8Array(r).set(new Uint8Array(e,t,n)),r}const W_=[0,255,65535,16777215,4294967295];function G_(e,t,n,r,i){for(let a=0;a<i;a++)n[r+a]=e[t+a]}function K_(e,t){let n=e.byteLength,r=t.byteLength,i=0,a=0;for(;i<n;){let t=e[i];if(i++,t<128)break}if(r&&i>=n)throw Error(`invalid snappy length header`);for(;i<n;){let r=e[i],o=0;if(i++,i>=n)throw Error(`missing eof marker`);if(r&3){let s=0;switch(r&3){case 1:o=(r>>>2&7)+4,s=e[i]+(r>>>5<<8),i++;break;case 2:if(n<=i+1)throw Error(`snappy error end of input`);o=(r>>>2)+1,s=e[i]+(e[i+1]<<8),i+=2;break;case 3:if(n<=i+3)throw Error(`snappy error end of input`);o=(r>>>2)+1,s=e[i]+(e[i+1]<<8)+(e[i+2]<<16)+(e[i+3]<<24),i+=4;break;default:break}if(s===0||isNaN(s))throw Error(`invalid offset ${s} pos ${i} inputLength ${n}`);if(s>a)throw Error(`cannot copy from before start of buffer`);G_(t,a-s,t,a,o),a+=o}else{let o=(r>>>2)+1;if(o>60){if(i+3>=n)throw Error(`snappy error literal pos + 3 >= inputLength`);let t=o-60;o=e[i]+(e[i+1]<<8)+(e[i+2]<<16)+(e[i+3]<<24),o=(o&W_[t])+1,i+=t}if(i+o>n)throw Error(`snappy error literal exceeds input length`);G_(e,i,t,a,o),i+=o,a+=o}}if(a!==r)throw Error(`premature end of input`)}function q_(e,t,{type:n,element:r,schemaPath:i}){let a=new DataView(e.buffer,e.byteOffset,e.byteLength),o={view:a,offset:0},s,c=J_(o,t,i),{definitionLevels:l,numNulls:u}=Y_(o,t,i),d=t.num_values-u;if(t.encoding===`PLAIN`)s=P_(o,n,d,r.type_length);else if(t.encoding===`PLAIN_DICTIONARY`||t.encoding===`RLE_DICTIONARY`||t.encoding===`RLE`){let e=n===`BOOLEAN`?1:a.getUint8(o.offset++);e?(s=Array(d),n===`BOOLEAN`?(k_(o,e,s),s=s.map(e=>!!e)):k_(o,e,s,a.byteLength-o.offset)):s=new Uint8Array(d)}else if(t.encoding===`BYTE_STREAM_SPLIT`)s=M_(o,d,n,r.type_length);else if(t.encoding===`ALP`)s=__(o,d,n);else if(t.encoding===`DELTA_BINARY_PACKED`)s=n===`INT32`?new Int32Array(d):new BigInt64Array(d),w_(o,d,s);else if(t.encoding===`DELTA_LENGTH_BYTE_ARRAY`)s=Array(d),D_(o,d,s);else if(t.encoding===`DELTA_BYTE_ARRAY`)s=Array(d),O_(o,d,s);else throw Error(`parquet unsupported encoding: ${t.encoding}`);return{definitionLevels:l,repetitionLevels:c,dataPage:s}}function J_(e,t,n){if(n.length>1){let r=Nh(n);if(r){let n=Array(t.num_values);return k_(e,ev(r),n),n}}return[]}function Y_(e,t,n){let r=Ph(n);if(!r)return{definitionLevels:[],numNulls:0};let i=Array(t.num_values);k_(e,ev(r),i);let a=t.num_values;for(let e of i)e===r&&a--;return a===0&&(i.length=0),{definitionLevels:i,numNulls:a}}function X_(e,t,n,r){let i,a=r?.[n];if(n===`UNCOMPRESSED`)i=e;else if(a)i=a(e,t);else if(n===`SNAPPY`)i=new Uint8Array(t),K_(e,i);else throw Error(`parquet unsupported compression codec: ${n}`);if(i?.length!==t)throw Error(`parquet decompressed page length ${i?.length} does not match header ${t}`);return i}function Z_(e,t,n){let r={view:new DataView(e.buffer,e.byteOffset,e.byteLength),offset:0},{type:i,element:a,schemaPath:o,codec:s,compressors:c}=n,l=t.data_page_header_v2;if(!l)throw Error(`parquet data page header v2 is undefined`);let u=Q_(r,l,o);r.offset=l.repetition_levels_byte_length;let d=$_(r,l,o),f=t.uncompressed_page_size-l.definition_levels_byte_length-l.repetition_levels_byte_length,p=e.subarray(r.offset);l.is_compressed!==!1&&f&&(p=X_(p,f,s,c));let m=new DataView(p.buffer,p.byteOffset,p.byteLength),h={view:m,offset:0},g,_=l.num_values-l.num_nulls;if(l.encoding===`PLAIN`)g=P_(h,i,_,a.type_length);else if(l.encoding===`RLE`)g=Array(_),k_(h,1,g),g=g.map(e=>!!e);else if(l.encoding===`PLAIN_DICTIONARY`||l.encoding===`RLE_DICTIONARY`){let e=m.getUint8(h.offset++);g=Array(_),k_(h,e,g,f-1)}else if(l.encoding===`DELTA_BINARY_PACKED`)g=i===`INT32`?new Int32Array(_):new BigInt64Array(_),w_(h,_,g);else if(l.encoding===`DELTA_LENGTH_BYTE_ARRAY`)g=Array(_),D_(h,_,g);else if(l.encoding===`DELTA_BYTE_ARRAY`)g=Array(_),O_(h,_,g);else if(l.encoding===`BYTE_STREAM_SPLIT`)g=M_(h,_,i,a.type_length);else if(l.encoding===`ALP`)g=__(h,_,i);else throw Error(`parquet unsupported encoding: ${l.encoding}`);return{definitionLevels:d,repetitionLevels:u,dataPage:g}}function Q_(e,t,n){let r=Nh(n);if(!r)return[];let i=Array(t.num_values);return k_(e,ev(r),i,t.repetition_levels_byte_length),i}function $_(e,t,n){let r=Ph(n);if(r){let n=Array(t.num_values);return k_(e,ev(r),n,t.definition_levels_byte_length),n}}function ev(e){return 32-Math.clz32(e)}function tv(e,{groupStart:t,selectStart:n,selectEnd:r},i,a){let{pathInSchema:o,schemaPath:s}=i,c=Lh(s),l=[],u,d,f=0,p=0,m=a&&(()=>{d&&a({pathInSchema:o,columnData:d,rowStart:t+f-d.length,rowEnd:t+f})});for(;(c?f<r:e.offset<e.view.byteLength-1)&&!(e.offset>=e.view.byteLength-1);){let t=rv(e);if(t.type===`DICTIONARY_PAGE`){let{data:n}=nv(e,t,i,u,void 0,0);n&&(u=Th(n,i))}else{let r=d?.length||0,a=nv(e,t,i,u,d,n-f);a.skipped?(l.length||(p+=a.skipped),f+=a.skipped):a.data&&d===a.data?f+=a.data.length-r:a.data&&a.data.length&&(m?.(),l.push(a.data),f+=a.data.length,d=a.data)}}return m?.(),{data:l,skipped:p}}function nv(e,t,n,r,i,a){let{type:o,element:s,schemaPath:c,codec:l,compressors:u}=n,d=new Uint8Array(e.view.buffer,e.view.byteOffset+e.offset,t.compressed_page_size);if(e.offset+=t.compressed_page_size,t.type===`DATA_PAGE`){let e=t.data_page_header;if(!e)throw Error(`parquet data page header is undefined`);if(a>e.num_values&&Lh(c))return{skipped:e.num_values};let{definitionLevels:o,repetitionLevels:s,dataPage:f}=q_(X_(d,Number(t.uncompressed_page_size),l,u),e,n),p=wh(f,r,e.encoding,n);return{skipped:0,data:c_(Array.isArray(i)?i:[],o,s,p,c)}}else if(t.type===`DATA_PAGE_V2`){let e=t.data_page_header_v2;if(!e)throw Error(`parquet data page header v2 is undefined`);if(a>e.num_rows)return{skipped:e.num_rows};let{definitionLevels:o,repetitionLevels:s,dataPage:l}=Z_(d,t,n),u=wh(l,r,e.encoding,n);return{skipped:0,data:c_(Array.isArray(i)?i:[],o,s,u,c)}}else if(t.type===`DICTIONARY_PAGE`){let e=t.dictionary_page_header;if(!e)throw Error(`parquet dictionary page header is undefined`);let n=X_(d,Number(t.uncompressed_page_size),l,u);return{skipped:0,data:P_({view:new DataView(n.buffer,n.byteOffset,n.byteLength),offset:0},o,e.num_values,s.type_length)}}else throw Error(`parquet unsupported page type: ${t.type}`)}function rv(e){let t=Rh(e);return{type:ph[t.field_1],uncompressed_page_size:t.field_2,compressed_page_size:t.field_3,crc:t.field_4,data_page_header:t.field_5&&{num_values:t.field_5.field_1,encoding:lh[t.field_5.field_2],definition_level_encoding:lh[t.field_5.field_3],repetition_level_encoding:lh[t.field_5.field_4],statistics:iv(t.field_5.field_5)},index_page_header:t.field_6,dictionary_page_header:t.field_7&&{num_values:t.field_7.field_1,encoding:lh[t.field_7.field_2],is_sorted:t.field_7.field_3},data_page_header_v2:t.field_8&&{num_values:t.field_8.field_1,num_nulls:t.field_8.field_2,num_rows:t.field_8.field_3,encoding:lh[t.field_8.field_4],definition_levels_byte_length:t.field_8.field_5,repetition_levels_byte_length:t.field_8.field_6,is_compressed:t.field_8.field_7===void 0?!0:t.field_8.field_7,statistics:iv(t.field_8.field_8)}}}function iv(e){return e&&{max:e.field_1,min:e.field_2,null_count:e.field_3,distinct_count:e.field_4,max_value:e.field_5,min_value:e.field_6,is_max_value_exact:e.field_7,is_min_value_exact:e.field_8}}function av(e,{metadata:t},n){let r=[],i=Yh(t),a=n.chunks.filter(e=>`pageLocations`in e||`offsetIndex`in e),o=Promise.all(a.map(async t=>{if(`pageLocations`in t)return ov(n,t,t.pageLocations);if(!(`offsetIndex`in t))throw Error(`parquet expected offset index`);let r=await e.file.slice(t.offsetIndex.startByte,t.offsetIndex.endByte),i=tg({view:new DataView(r),offset:0}).page_locations;return ov(n,t,i)})).then(t=>{let n=t.flatMap(e=>e.fetches);return{file:Jg(e.file,{fetches:Kg(n,0,Rg)}),selections:t}}),s=0;for(let t of n.chunks){let{path_in_schema:a}=t.columnMetadata,c=jh(i,a),l={pathInSchema:a,element:c[c.length-1].element,schemaPath:c,...e,...t.columnMetadata,parsers:{...Ch,...e.parsers}},{startByte:u,endByte:d}=t.range;if(`pageLocations`in t||`offsetIndex`in t){let t=s++;r.push({pathInSchema:a,data:o.then(({file:r,selections:i})=>sv({...e,file:r},n,i[t],l))})}else r.push({pathInSchema:a,data:Promise.resolve(e.file.slice(u,d)).then(t=>tv({view:new DataView(t),offset:0},n,l,e.onPage))})}return{groupStart:n.groupStart,groupRows:n.groupRows,selectStart:n.selectStart,selectEnd:n.selectEnd,asyncColumns:r}}function ov(e,t,n){let{data_page_offset:r,dictionary_page_offset:i}=t.columnMetadata,{selectStart:a,selectEnd:o}=e,{startByte:s,endByte:c}=t.range,l=-1,u=i||r<n[0].offset;for(let t=0;t<n.length;t++){let r=n[t],i=Number(r.first_row_index),u=t+1<n.length?Number(n[t+1].first_row_index):e.groupRows;l<0&&u>a&&(s=Number(r.offset),l=i),i<o&&(c=Number(r.offset)+r.compressed_page_size)}if(l<0&&(l=0),!u)return{skipped:l,fetches:[{startByte:s,endByte:c}]};if(!l)return{skipped:l,fetches:[{startByte:t.range.startByte,endByte:c}]};let d={startByte:t.range.startByte,endByte:Number(n[0].offset)};return{skipped:l,fetches:[d,{startByte:s,endByte:c}]}}async function sv(e,t,{skipped:n,fetches:r},i){let a;if(r.length>1){let[t,n]=r,i=t.endByte-t.startByte,[o,s]=await Promise.all([e.file.slice(t.startByte,t.endByte),e.file.slice(n.startByte,n.endByte)]),c=new Uint8Array(i+s.byteLength);c.set(new Uint8Array(o,0,i)),c.set(new Uint8Array(s),i),a=new DataView(c.buffer)}else a=new DataView(await e.file.slice(r[0].startByte,r[0].endByte));let{data:o,skipped:s}=tv({view:a,offset:0},n?{...t,groupStart:t.groupStart+n,selectStart:t.selectStart-n,selectEnd:t.selectEnd-n}:t,i,e.onPage);return{data:o,skipped:n+s}}async function cv({asyncColumns:e},t,n,r,i){let a=await Promise.all(e.map(e=>e.data.then(({skipped:e,data:t})=>({skipped:e,data:Cg(t)})))),o=n-t;if(i===`object`){let n=Array(o);for(let r=0;r<o;r++){let i={};for(let n=0;n<e.length;n++){let{data:o,skipped:s}=a[n];i[e[n].pathInSchema[0]]=o[t+r-s]}n[r]=i}return n}let s=e.map(e=>e.pathInSchema[0]).filter(e=>!r||r.includes(e)),c=r??s,l=c.map(t=>e.findIndex(e=>e.pathInSchema[0]===t)),u=Array(o);for(let n=0;n<o;n++){let r=Array(e.length);for(let e=0;e<c.length;e++){let i=l[e];if(i<0)throw Error(`parquet column not found: ${c[e]}`);let{data:o,skipped:s}=a[i];r[e]=o[t+n-s]}u[n]=r}return u}function lv(e,t,n){let{asyncColumns:r}=e,i={...Ch,...n},a=[];for(let n of t.children)if(n.children.length){let t=r.filter(e=>e.pathInSchema[0]===n.element.name);if(!t.length)continue;a.push({pathInSchema:n.path,data:(async()=>{let r=await Promise.all(t.map(e=>e.data)),a=new Map,o=r.map(({data:e})=>Cg(e)),s=Math.max(e.selectStart??0,...r.map(e=>e.skipped)),c=Math.min(e.selectEnd??1/0,...r.map((e,t)=>e.skipped+o[t].length));for(let e=0;e<t.length;e++){let n=s-r[e].skipped,i=Math.max(0,c-s);a.set(t[e].pathInSchema.join(`.`),o[e].slice(n,n+i))}l_(a,n,i);let l=a.get(n.element.name);if(!l)throw Error(`parquet column data not assembled`);return{data:[l],skipped:s}})()})}else{let e=r.find(e=>e.pathInSchema[0]===n.element.name);e&&a.push(e)}return{...e,asyncColumns:a}}async function uv(e){let t=await dv(e);return{options:t,plan:zg(t)}}async function dv(e){let t=e.metadata??await qh(e.file,e),n=Yh(t).children.map(e=>e.element.name),r=Eg(e.filter).filter(e=>!n.includes(e));if(r.length)throw Error(`parquet filter columns not found: ${r.join(`, `)}`);if(e.columns){let t=e.columns.filter(e=>!n.includes(e));if(t.length)throw Error(`parquet column not found: ${t[0]}`)}let i={...e,metadata:t};return i=await pv(i),i=await mv(i),i}function fv(e,t){let n={...e,file:Jg(e.file,t)};return t.groups.map(e=>av(n,t,e))}async function pv(e){if(!e.useBloomFilters||!e.filter||!e.metadata)return e;let t=Yh(e.metadata),n={};for(let e of t.children)n[e.element.name]=e.element;let r=await Wg({file:e.file,metadata:e.metadata,filter:e.filter,filterStrict:e.filterStrict,rowStart:e.rowStart,rowEnd:e.rowEnd});return{...e,bloomFiltersByGroup:r,schemaElements:n}}async function mv(e){if(!e.usePageIndex||!e.filter||!e.metadata)return e;let{pageRangesByGroup:t,pageLocationsByGroup:n}=await Gg({file:e.file,metadata:e.metadata,filter:e.filter,filterStrict:e.filterStrict,rowStart:e.rowStart,rowEnd:e.rowEnd,columns:e.columns,bloomFiltersByGroup:e.bloomFiltersByGroup,schemaElements:e.schemaElements,parsers:e.parsers});return{...e,pageRangesByGroup:t,pageLocationsByGroup:n}}const hv=Symbol(`rowIndex`);async function gv(e){e.metadata??=await qh(e.file,e);let{rowStart:t=0,rowEnd:n,columns:r,onChunk:i,onComplete:a,rowFormat:o,filter:s,filterStrict:c=!0}=e;if(s&&o!==`object`)throw Error(`parquet filter requires rowFormat: "object"`);if(e.includeRowIndex&&o!==`object`)throw Error(`parquet includeRowIndex requires rowFormat: "object"`);let l=Eg(s),u=r;if(r&&l.length){let e=new Set(r),t=l.filter(t=>!e.has(t));t.length&&(u=[...r,...t])}let d=await uv(u===r?e:{...e,columns:u}),f=d.options,p=u!==r,m=fv(f,d.plan);if(!a&&!i){await _v(m);return}if(!f.metadata)throw Error(`parquet requires metadata`);let h=Yh(f.metadata),g=m.map(t=>lv(t,h,e.parsers));if(i)for(let e of g)for(let t of e.asyncColumns)t.data.then(({data:n,skipped:r})=>{let a=e.groupStart+r;for(let e of n)i({columnName:t.pathInSchema[0],columnData:e,rowStart:a,rowEnd:a+e.length}),a+=e.length},()=>{});if(a){await _v(g);let i=[];for(let a of g){let d=a.selectStart??Math.max(t-a.groupStart,0),f=a.selectEnd??Math.min((n??1/0)-a.groupStart,a.groupRows),m=o===`object`?await cv(a,d,f,u,`object`):await cv(a,d,f,r,`array`);if(e.includeRowIndex)for(let e=0;e<m.length;e++)Object.defineProperty(m[e],hv,{value:a.groupStart+d+e});if(s){for(let e of m)if(Dg(e,s,c)){if(p&&r)for(let t of l)r.includes(t)||delete e[t];i.push(e)}}else xg(i,m)}a(i)}else await _v(g)}async function _v(e){let t=e.flatMap(e=>e.asyncColumns.map(e=>e.data)),n=(await Promise.allSettled(t)).find(e=>e.status===`rejected`);if(n)throw n.reason}function vv(){let e=yv();return(t,n)=>{let{memory:r,uncompress:i}=e.exports,a=68e3,o=a+t.byteLength,s=a+t.byteLength+n;if(r.buffer.byteLength<s){let e=64*1024,t=r.buffer.byteLength/e,n=Math.ceil(s/e)-t;r.grow(n)}let c=new Uint8Array(r.buffer);c.set(t,a);let l=i(a,t.byteLength,o);if(l===-1)throw Error(`invalid snappy length header`);if(l===-2)throw Error(`missing eof marker`);if(l===-3)throw Error(`premature end of input`);if(l)throw Error(`failed to uncompress data ${l}`);return c.slice(o,o+n)}}function yv(){let e=atob(bv),t=new Uint8Array(e.length);for(let n=0;n<e.length;n+=1)t[n]=e.charCodeAt(n);let n=new WebAssembly.Module(t);return new WebAssembly.Instance(n)}const bv=`AGFzbQEAAAABEANgAABgA39/fwF/YAF/AX8DBgUAAQEBAgUDAQACBj8KfwFBoIwEC38AQYAIC38AQaAMC38AQaAMC38AQaCMBAt/AEGACAt/AEGgjAQLfwBBgIAIC38AQQALfwBBAQsHwQEOBm1lbW9yeQIAEV9fd2FzbV9jYWxsX2N0b3JzAAAGbWVtY3B5AAEHbWVtbW92ZQACCnVuY29tcHJlc3MAAwxfX2Rzb19oYW5kbGUDAQpfX2RhdGFfZW5kAwILX19zdGFja19sb3cDAwxfX3N0YWNrX2hpZ2gDBA1fX2dsb2JhbF9iYXNlAwULX19oZWFwX2Jhc2UDBgpfX2hlYXBfZW5kAwcNX19tZW1vcnlfYmFzZQMIDF9fdGFibGVfYmFzZQMJCuASBQIAC8sBAQN/AkAgAkUNAAJAAkAgAkEHcSIDDQAgACEEIAIhBQwBCyAAIQQgAiEFA0AgBCABLQAAOgAAIARBAWohBCABQQFqIQEgBUF/aiEFIANBf2oiAw0ACwsgAkEISQ0AA0AgBCABLQAAOgAAIAQgAS0AAToAASAEIAEtAAI6AAIgBCABLQADOgADIAQgAS0ABDoABCAEIAEtAAU6AAUgBCABLQAGOgAGIAQgAS0ABzoAByAEQQhqIQQgAUEIaiEBIAVBeGoiBQ0ACwsgAAugAwEEfwJAIAAgAUYNAAJAAkAgACABSQ0AIAEgAmoiAyAASw0BCyACRQ0BAkACQCACQQdxIgMNACAAIQQgAiEFDAELIAAhBCACIQUDQCAEIAEtAAA6AAAgBEEBaiEEIAFBAWohASAFQX9qIQUgA0F/aiIDDQALCyACQQhJDQEDQCAEIAEtAAA6AAAgBCABLQABOgABIAQgAS0AAjoAAiAEIAEtAAM6AAMgBCABLQAEOgAEIAQgAS0ABToABSAEIAEtAAY6AAYgBCABLQAHOgAHIARBCGohBCABQQhqIQEgBUF4aiIFDQAMAgsLIAJFDQACQAJAIAJBA3EiBA0AIAAgAmohBiACIQUMAQsgAiEFA0AgBUF/aiIFIABqIgYgBSABaiIDLQAAOgAAIARBf2oiBA0ACwsgAkEESQ0AIAZBfGohASADQXxqIQQDQCABQQNqIARBA2otAAA6AAAgAUECaiAEQQJqLQAAOgAAIAFBAWogBEEBai0AADoAACABIAQtAAA6AAAgAUF8aiEBIARBfGohBCAFQXxqIgUNAAsLIAALswoBCX8jgICAgABBIGsiAySAgICAACADQQlqQgA3AAAgA0IANwIEIAMgA0EYajYCAEF/IQQCQCABRQ0AIAMgAUF/aiIFNgIcIAMgAEEBajYCGCAALAAAIgZB/wBxIQcCQCAGQX9KDQAgBUUNASADIAFBfmoiBTYCHCADIABBAmo2AhggACwAASIGQf8AcUEHdCAHciEHQX8hBCAGQX9KDQAgBUUNASADIAFBfWoiBTYCHCADIABBA2o2AhggACwAAiIGQf8AcUEOdCAHciEHQX8hBCAGQX9KDQAgBUUNASADIAFBfGoiBTYCHCADIABBBGo2AhggACwAAyIGQf8AcUEVdCAHciEHQX8hBCAGQX9KDQAgBUUNASADIAFBe2o2AhwgAyAAQQVqNgIYIAAsAAQiAUEASA0BIAFBHHQgB3IhBwsgAiAHaiEIAkACQCADEISAgIAADQAgAiEADAELIAMoAgQhASACIQADQAJAIAMoAgggAWtBBEoNACADIAE2AgQgAxCEgICAAEUNAiADKAIEIQELIAFBAWohBQJAAkAgAS0AACIGQQNxDQAgCCAAayEJIAMoAggiCiAFayEEIAZBAnYiC0EBaiEHAkAgBkE/Sw0AIARBEEkNACAJQRBIDQAgACABKAIBNgIAIAAgASgCBTYCBCAAIAEoAgk2AgggACABKAINNgIMIAAgB2ohACADKAIIIAUgB2oiAWtBBEoNAyADIAE2AgQgAxCEgICAAEUNBAwCCwJAAkAgBkHwAU8NACAFIQYMAQsgCiAFIAtBRWoiAWoiBmshBCABQQJ0QYCIgIAAaigCACAFKAIAcUEBaiEHCwJAIAcgBE0NAANAIAggAGsgBEkNBSAAIAYgBBCBgICAACEAIAMoAgAiASABKAIAIgkgAygCDCIFaiIGNgIAIAFBBGoiASABKAIAIgogBWsiATYCACADIAE2AgwgACAEaiEAIAFFDQUgAyAJIApqNgIIIAcgBGshByABIQQgByABSw0ACyAIIABrIQkLIAkgB0kNAyAAIAYgBxCBgICAACAHaiEAIAMoAgggBiAHaiIBa0EESg0CIAMgATYCBCADEISAgIAADQEMAwsgACACayAGQQF0QaCIgIAAai8BACIBQQt2IgpBAnRBgIiAgABqKAIAIAUoAgBxIAFBgA5xaiIHQX9qTQ0CIAggAGshBAJAAkAgAUH/AXEiCUEQSw0AIAdBCEkNACAEQRBJDQAgACAAIAdrIgEoAgA2AgAgACABKAIENgIEIAAgASgCCDYCCCAAIAFBDGooAgA2AgwMAQsCQAJAAkAgBCAJQQpqSQ0AIAAgB2shBCAAIQEgCSEGIAdBB0wNAQwCCyAEIAlJDQUgCUEBaiEEQQAgB2shByAAIQEDQCABIAEgB2otAAA6AAAgAUEBaiEBIARBf2oiBEEBSw0ADAMLCwNAIAEgBCgCADYCACABIAQoAgQ2AgQgBiAHayEGIAEgB2oiASAEayIHQQhIDQALCyAGQQFIDQAgBkEIaiEHA0AgASAEKAIANgIAIAEgBCgCBDYCBCABQQhqIQEgBEEIaiEEIAdBeGoiB0EISw0ACwsgACAJaiEAIAMoAgggBSAKaiIBa0EESg0BIAMgATYCBCADEISAgIAARQ0CCyADKAIEIQEMAAsLIAMoAgAiASABKAIEIAMoAgwiBGs2AgQgASAEIAEoAgBqNgIAAkAgAy0AEA0AQX4hBAwBC0EAQX0gCCAARhshBAsgA0EgaiSAgICAACAEC7YDAQd/AkAgACgCBCIBIAAoAggiAkcNACAAKAIAIgIgAigCACIDIAAoAgwiBGoiATYCACACQQRqIgIgAigCACICIARrIgU2AgAgACAFNgIMAkAgAiAERw0AIABBAToAEEEADwsgACADIAJqIgI2AggLAkACQAJAIAIgAWsiAiABLQAAQQF0QaCIgIAAai8BAEELdkEBaiIFTw0AIABBEWogASACEIKAgIAAIQYgACgCDCEEQQAhByAAQQA2AgwgACgCACIBIAEoAgQgBGs2AgQgASAEIAEoAgBqIgM2AgADQCABQQRqKAIAIgFFDQMgBiACaiADIAUgAmsiBCABIAQgAUkbIgQQgYCAgAAaIAAoAgAiASABKAIEIARrNgIEIAEgASgCACAEaiIDNgIAIAQgAmoiAiAFSQ0ACyAAIAY2AgQgACAGIAVqNgIIDAELAkAgAkEESw0AIAAgAEERaiABIAIQgoCAgAAiASACajYCCCAAIAE2AgQgACgCDCECIABBADYCDCAAKAIAIgEgASgCBCACazYCBCABIAIgASgCAGo2AgAMAQsgACABNgIEC0EBIQcLIAcLC6gEAQBBgAgLoAQAAAAA/wAAAP//AAD///8A/////wAAAAAAAAAAAAAAAAEABAgBEAEgAgAFCAIQAiADAAYIAxADIAQABwgEEAQgBQAICAUQBSAGAAkIBhAGIAcACggHEAcgCAALCAgQCCAJAAQJCRAJIAoABQkKEAogCwAGCQsQCyAMAAcJDBAMIA0ACAkNEA0gDgAJCQ4QDiAPAAoJDxAPIBAACwkQEBAgEQAEChEQESASAAUKEhASIBMABgoTEBMgFAAHChQQFCAVAAgKFRAVIBYACQoWEBYgFwAKChcQFyAYAAsKGBAYIBkABAsZEBkgGgAFCxoQGiAbAAYLGxAbIBwABwscEBwgHQAICx0QHSAeAAkLHhAeIB8ACgsfEB8gIAALCyAQICAhAAQMIRAhICIABQwiECIgIwAGDCMQIyAkAAcMJBAkICUACAwlECUgJgAJDCYQJiAnAAoMJxAnICgACwwoECggKQAEDSkQKSAqAAUNKhAqICsABg0rECsgLAAHDSwQLCAtAAgNLRAtIC4ACQ0uEC4gLwAKDS8QLyAwAAsNMBAwIDEABA4xEDEgMgAFDjIQMiAzAAYOMxAzIDQABw40EDQgNQAIDjUQNSA2AAkONhA2IDcACg43EDcgOAALDjgQOCA5AAQPORA5IDoABQ86EDogOwAGDzsQOyA8AAcPPBA8IAEICA89ED0gARAJDz4QPiABGAoPPxA/IAEgCw9AEEAgAGQEbmFtZQE9BQARX193YXNtX2NhbGxfY3RvcnMBBm1lbWNweQIHbWVtbW92ZQMKdW5jb21wcmVzcwQKcmVmaWxsX3RhZwcSAQAPX19zdGFja19wb2ludGVyCQoBAAcucm9kYXRhADIJcHJvZHVjZXJzAQxwcm9jZXNzZWQtYnkBDFVidW50dSBjbGFuZwsxNi4wLjYgKDE1KQAsD3RhcmdldF9mZWF0dXJlcwIrD211dGFibGUtZ2xvYmFscysIc2lnbi1leHQ=`,xv=4096;2*xv+32;const Sv=2*xv-1,Cv=new Uint32Array([0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535,131071,262143,524287,1048575,2097151,4194303,8388607,16777215]);var wv=class{constructor(e){this.buf_=new Uint8Array(8224),this.input_=e,this.buf_ptr_=0,this.val_=0,this.pos_=0,this.bit_pos_=0,this.bit_end_pos_=0,this.eos_=0,this.reset()}static READ_SIZE=xv;static IBUF_MASK=Sv;reset(){this.buf_ptr_=0,this.val_=0,this.pos_=0,this.bit_pos_=0,this.bit_end_pos_=0,this.eos_=0,this.readMoreInput();for(let e=0;e<4;e++)this.val_|=this.buf_[this.pos_]<<8*e,this.pos_++;return this.bit_end_pos_>0}readMoreInput(){if(!(this.bit_end_pos_>256))if(this.eos_){if(this.bit_pos_>this.bit_end_pos_)throw Error(`Unexpected end of input `+this.bit_pos_+` `+this.bit_end_pos_)}else{let e=this.buf_ptr_,t=this.input_.read(this.buf_,e,xv);if(t<0)throw Error(`Unexpected end of input`);if(t<xv){this.eos_=1;for(let n=0;n<32;n++)this.buf_[e+t+n]=0}if(e===0){for(let e=0;e<32;e++)this.buf_[(xv<<1)+e]=this.buf_[e];this.buf_ptr_=xv}else this.buf_ptr_=0;this.bit_end_pos_+=t<<3}}fillBitWindow(){for(;this.bit_pos_>=8;)this.val_>>>=8,this.val_|=this.buf_[this.pos_&Sv]<<24,this.pos_++,this.bit_pos_=this.bit_pos_-8>>>0,this.bit_end_pos_=this.bit_end_pos_-8>>>0}readBits(e){32-this.bit_pos_<e&&this.fillBitWindow();let t=this.val_>>>this.bit_pos_&Cv[e];return this.bit_pos_+=e,t}};const Tv=new Uint8Array([1,2,3,4,0,5,17,6,16,7,8,9,10,11,12,13,14,15]),Ev=new Uint16Array([256,402,436,468,500,534,566,598,630,662,694,726,758,790,822,854,886,920,952,984,1016,1048,1080]);var Z=class{constructor(e,t){this.bits=e,this.value=t}};function Dv(e,t){let n=1<<t-1;for(;e&n;)n>>=1;return(e&n-1)+n}function Ov(e,t,n,r,i){do r-=n,e[t+r]=new Z(i.bits,i.value);while(r>0)}function kv(e,t,n){let r=1<<t-n;for(;t<15&&(r-=e[t],!(r<=0));)++t,r<<=1;return t-n}function Av(e,t,n,r,i){let a=t,o=new Int32Array(16),s=new Int32Array(16),c=new Int32Array(i);for(let e=0;e<i;e++)o[r[e]]++;s[1]=0;for(let e=1;e<15;e++)s[e+1]=s[e]+o[e];for(let e=0;e<i;e++)r[e]!==0&&(c[s[r[e]]++]=e);let l=n,u=1<<l,d=u;if(s[15]===1){for(let n=0;n<d;++n)e[t+n]=new Z(0,c[0]&65535);return d}let f=0,p=0;for(let r=1,i=2;r<=n;++r,i<<=1)for(;o[r]>0;--o[r]){let n=new Z(r&255,c[p++]&65535);Ov(e,t+f,i,u,n),f=Dv(f,r)}let m=d-1,h=-1;for(let r=n+1,i=2;r<=15;++r,i<<=1)for(;o[r]>0;--o[r]){(f&m)!==h&&(t+=u,l=kv(o,r,n),u=1<<l,d+=u,h=f&m,e[a+h]=new Z(l+n&255,t-a-h&65535));let s=new Z(r-n&255,c[p++]&65535);Ov(e,t+(f>>n),i,u,s),f=Dv(f,r)}return d}function jv(e,t,n,r){let i=new Uint8Array(e);r.readMoreInput();let a=r.readBits(2);if(a===1){let t=e-1,n=0,a=new Int32Array(4),o=r.readBits(2)+1;for(;t;)t>>=1,n++;for(let t=0;t<o;t++)a[t]=r.readBits(n)%e,i[a[t]]=2;switch(i[a[0]]=1,o){case 1:break;case 3:if(a[0]===a[1]||a[0]===a[2]||a[1]===a[2])throw Error(`[ReadHuffmanCode] invalid symbols`);break;case 2:if(a[0]===a[1])throw Error(`[ReadHuffmanCode] invalid symbols`);i[a[1]]=1;break;case 4:if(a[0]===a[1]||a[0]===a[2]||a[0]===a[3]||a[1]===a[2]||a[1]===a[3]||a[2]===a[3])throw Error(`[ReadHuffmanCode] invalid symbols`);r.readBits(1)?(i[a[2]]=3,i[a[3]]=3):i[a[0]]=2;break}}else{let t=new Uint8Array(18),n=32,o=0,s=[new Z(2,0),new Z(2,4),new Z(2,3),new Z(3,2),new Z(2,0),new Z(2,4),new Z(2,3),new Z(4,1),new Z(2,0),new Z(2,4),new Z(2,3),new Z(3,2),new Z(2,0),new Z(2,4),new Z(2,3),new Z(4,5)];for(let e=a;e<18&&n>0;e++){let i=Tv[e],a=0;r.fillBitWindow(),a+=r.val_>>>r.bit_pos_&15,r.bit_pos_+=s[a].bits;let c=s[a].value;t[i]=c,c!==0&&(n-=32>>c,o++)}if(!(o===1||n===0))throw Error(`[ReadHuffmanCode] invalid num_codes or space`);Nv(t,e,i,r)}let o=Av(t,n,8,i,e);if(!o)throw Error(`brotli BuildHuffmanTable failed`);return o}function Mv(e,t,n){n.fillBitWindow(),t+=n.val_>>>n.bit_pos_&255;let r=e[t].bits-8;return r>0&&(n.bit_pos_+=8,t+=e[t].value,t+=n.val_>>>n.bit_pos_&(1<<r)-1),n.bit_pos_+=e[t].bits,e[t].value}function Nv(e,t,n,r){let i=0,a=8,o=0,s=0,c=32768,l=[];for(let e=0;e<32;e++)l.push(new Z(0,0));for(Av(l,0,5,e,18);i<t&&c>0;){let e=0;r.readMoreInput(),r.fillBitWindow(),e+=r.val_>>>r.bit_pos_&31,r.bit_pos_+=l[e].bits;let u=l[e].value&255;if(u<16)o=0,n[i++]=u,u!==0&&(a=u,c-=32768>>u);else{let e=u-14,l=0;u===16&&(l=a),s!==l&&(o=0,s=l);let d=o;o>0&&(o-=2,o<<=e),o+=r.readBits(e)+3;let f=o-d;if(i+f>t)throw Error(`[ReadHuffmanCodeLengths] symbol + repeat_delta > num_symbols`);for(let e=0;e<f;e++)n[i+e]=s;i+=f,s!==0&&(c-=f<<15-s)}}if(c!==0)throw Error(`[ReadHuffmanCodeLengths] space = `+c);for(;i<t;i++)n[i]=0}var Pv=class{constructor(e,t){this.alphabet_size=e,this.num_htrees=t,this.codes=Array(t+t*Ev[e+31>>>5]),this.htrees=new Uint32Array(t)}decode(e){let t=0;for(let n=0;n<this.num_htrees;n++)this.htrees[n]=t,t+=jv(this.alphabet_size,this.codes,t,e)}};function Fv([e,t]){return{offset:e,nbits:t}}const Iv=[[1,2],[5,2],[9,2],[13,2],[17,3],[25,3],[33,3],[41,3],[49,4],[65,4],[81,4],[97,4],[113,5],[145,5],[177,5],[209,5],[241,6],[305,6],[369,7],[497,8],[753,9],[1265,10],[2289,11],[4337,12],[8433,13],[16625,24]].map(Fv),Lv=[[0,0],[1,0],[2,0],[3,0],[4,0],[5,0],[6,1],[8,1],[10,2],[14,2],[18,3],[26,3],[34,4],[50,4],[66,5],[98,5],[130,6],[194,7],[322,8],[578,9],[1090,10],[2114,12],[6210,14],[22594,24]].map(Fv),Rv=[[2,0],[3,0],[4,0],[5,0],[6,0],[7,0],[8,0],[9,0],[10,1],[12,1],[14,2],[18,2],[22,3],[30,3],[38,4],[54,4],[70,5],[102,5],[134,6],[198,7],[326,8],[582,9],[1094,10],[2118,24]].map(Fv),zv=[0,0,8,8,0,16,8,16,16],Bv=[0,8,0,8,16,0,16,8,16],Vv=1080,Hv=new Uint8Array([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]),Uv=new Uint8Array([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]);function Wv(e,t){let n=new Uint16Array(31);for(let r=0;r<31;r++)n[r]=t+=1<<e[r-1];let r=new Int32Array(n[30]);for(let e=1;e<30;e++)for(let t=n[e];t<n[e+1];++t)r[t]=t-n[e]<<5|e;return{base:n,rev:r}}const{base:Gv,rev:Kv}=Wv(Hv,2);Gv[28]=258,Kv[258]=28;const{base:qv}=Wv(Uv,0),Jv=new Uint16Array(32768);for(let e=0;e<32768;e++){let t=(e&43690)>>1|(e&21845)<<1;t=(t&52428)>>2|(t&13107)<<2,t=(t&61680)>>4|(t&3855)<<4,Jv[e]=((t&65280)>>8|(t&255)<<8)>>1}function Yv(e,t,n){let r=new Uint16Array(t);for(let t=0;t<e.length;t++)e[t]&&++r[e[t]-1];let i=new Uint16Array(t);for(let e=1;e<t;e++)i[e]=i[e-1]+r[e-1]<<1;let a;if(n){a=new Uint16Array(1<<t);let n=15-t;for(let r=0;r<e.length;r++)if(e[r]){let o=r<<4|e[r],s=t-e[r],c=i[e[r]-1]++<<s;for(let e=c|(1<<s)-1;c<=e;c++)a[Jv[c]>>n]=o}}else{a=new Uint16Array(e.length);for(let t=0;t<e.length;t++)e[t]&&(a[t]=Jv[i[e[t]-1]++]>>15-e[t])}return a}const Xv=new Uint8Array(288);for(let e=0;e<144;e++)Xv[e]=8;for(let e=144;e<256;e++)Xv[e]=9;for(let e=256;e<280;e++)Xv[e]=7;for(let e=280;e<288;e++)Xv[e]=8;const Zv=new Uint8Array(32);for(let e=0;e<32;e++)Zv[e]=5;const Qv=Yv(Xv,9,1),$v=Yv(Zv,5,1);function ey(e,t,n,r,i,a,o){let s=n*2,c=n,l=Mv(t,n*Vv,o),u;u=l===0?i[s+(a[c]&1)]:l===1?i[s+(a[c]-1&1)]+1:l-2,u>=e&&(u-=e),r[n]=u,i[s+(a[c]&1)]=u,a[c]++}function ty(e){let t={meta_block_length:0,input_end:0,is_uncompressed:0,is_metadata:!1};if(t.input_end=e.readBits(1),t.input_end&&e.readBits(1))return t;let n=e.readBits(2)+4;if(n===7){if(t.is_metadata=!0,e.readBits(1)!==0)throw Error(`Invalid reserved bit`);let n=e.readBits(2);if(n===0)return t;for(let r=0;r<n;r++){let i=e.readBits(8);if(r+1===n&&n>1&&i===0)throw Error(`Invalid size byte`);t.meta_block_length|=i<<r*8}}else for(let r=0;r<n;r++){let i=e.readBits(4);if(r+1===n&&n>4&&i===0)throw Error(`Invalid size nibble`);t.meta_block_length|=i<<r*4}return t.meta_block_length++,!t.input_end&&!t.is_metadata&&(t.is_uncompressed=e.readBits(1)),t}function ny(e,t,n,r,i,a){let o=i+1,s=n&i,c=a.pos_&wv.IBUF_MASK;if(t<8||a.bit_pos_+(t<<3)<a.bit_end_pos_){for(;t-- >0;)a.readMoreInput(),r[s++]=a.readBits(8),s===o&&(e.write(r,o),s=0);return}if(a.bit_end_pos_<32)throw Error(`copyUncompressedBlockToOutput: br.bit_end_pos_ < 32`);for(;a.bit_pos_<32;)r[s]=a.val_>>>a.bit_pos_,a.bit_pos_+=8,s++,t--;let l=a.bit_end_pos_-a.bit_pos_>>3;if(c+l>wv.IBUF_MASK){let e=wv.IBUF_MASK+1-c;for(let t=0;t<e;t++)r[s+t]=a.buf_[c+t];l-=e,s+=e,t-=e,c=0}for(let e=0;e<l;e++)r[s+e]=a.buf_[c+e];if(s+=l,t-=l,s>=o){e.write(r,o),s-=o;for(let e=0;e<s;e++)r[e]=r[o+e]}for(;s+t>=o;){if(l=o-s,a.input_.read(r,s,l)<l)throw Error(`copyUncompressedBlockToOutput: not enough bytes`);e.write(r,o),t-=l,s=0}if(a.input_.read(r,s,t)<t)throw Error(`copyUncompressedBlockToOutput: not enough bytes`);a.reset()}function ry(e){if(e.readBits(1)){let t=e.readBits(3);return t===0?1:e.readBits(t)+(1<<t)}return 0}function iy(e){if(e.readBits(1)===0)return 16;let t=e.readBits(3);return t>0?17+t:(t=e.readBits(3),t>0?8+t:17)}function ay(e){let t=e.bit_pos_+7&-8;return!e.readBits(t-e.bit_pos_)}function oy(e,t,n){let{offset:r,nbits:i}=Iv[Mv(e,t,n)];return r+n.readBits(i)}const sy=new Uint8Array([0,0,0,0,0,0,0,0,0,4,4,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,12,16,12,12,20,12,16,24,28,12,12,32,12,36,12,44,44,44,44,44,44,44,44,44,44,32,32,24,40,28,12,12,48,52,52,52,48,52,52,52,48,52,52,52,52,52,48,52,52,52,52,52,48,52,52,52,52,52,24,12,28,12,12,12,56,60,60,60,56,60,60,60,56,60,60,60,60,60,56,60,60,60,60,60,56,60,60,60,60,60,24,12,28,12,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,0,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,56,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,6,6,6,6,7,7,7,7,8,8,8,8,9,9,9,9,10,10,10,10,11,11,11,11,12,12,12,12,13,13,13,13,14,14,14,14,15,15,15,15,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,22,22,22,22,23,23,23,23,24,24,24,24,25,25,25,25,26,26,26,26,27,27,27,27,28,28,28,28,29,29,29,29,30,30,30,30,31,31,31,31,32,32,32,32,33,33,33,33,34,34,34,34,35,35,35,35,36,36,36,36,37,37,37,37,38,38,38,38,39,39,39,39,40,40,40,40,41,41,41,41,42,42,42,42,43,43,43,43,44,44,44,44,45,45,45,45,46,46,46,46,47,47,47,47,48,48,48,48,49,49,49,49,50,50,50,50,51,51,51,51,52,52,52,52,53,53,53,53,54,54,54,54,55,55,55,55,56,56,56,56,57,57,57,57,58,58,58,58,59,59,59,59,60,60,60,60,61,61,61,61,62,62,62,62,63,63,63,63,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),cy=new Uint16Array([1024,1536,1280,1536,0,256,768,512]);function ly(e,t){let n=0;t.readMoreInput();let r=ry(t)+1,i=new Uint8Array(e);if(r<=1)return[r,i];t.readBits(1)&&(n=t.readBits(4)+1);let a=[];for(let e=0;e<Vv;e++)a[e]=new Z(0,0);jv(r+n,a,0,t);for(let r=0;r<e;){t.readMoreInput();let o=Mv(a,0,t);if(o===0)i[r]=0,r++;else if(o<=n){let n=1+(1<<o)+t.readBits(o);for(;--n;){if(r>=e)throw Error(`[DecodeContextMap] i >= context_map_size`);i[r]=0,r++}}else i[r]=o-n,r++}return t.readBits(1)&&dy(i,e),[r,i]}function uy(e,t){let n=e[t];for(let n=t;n;n--)e[n]=e[n-1];e[0]=n}function dy(e,t){let n=new Uint8Array(256);for(let e=0;e<256;e++)n[e]=e;for(let r=0;r<t;r++){let t=e[r];e[r]=n[t],t&&uy(n,t)}}var fy=class{constructor(e){this.buffer=e,this.pos=0}read(e,t,n){this.pos+n>this.buffer.length&&(n=this.buffer.length-this.pos);for(let r=0;r<n;r++)e[t+r]=this.buffer[this.pos+r];return this.pos+=n,n}},py=class{constructor(e){this.buffer=e,this.pos=0}write(e,t){if(this.pos+t>this.buffer.length)throw Error(`brotli output buffer is not large enough`);return this.buffer.set(e.subarray(0,t),this.pos),this.pos+=t,t}};const my=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);function hy(e,t,n){let r=t/8|0;return(e[r]|e[r+1]<<8)>>(t&7)&n}function gy(e,t){let n=t/8|0;return(e[n]|e[n+1]<<8|e[n+2]<<16)>>(t&7)}function _y(e){return(e+7)/8|0}function vy(e,t){if(e[t++]!==31||e[t++]!==139||e[t++]!==8)return 0;let n=e[t++];t+=6,n&4&&(t+=(e[t]|e[t+1]<<8)+2);for(let r=(n>>3&1)+(n>>4&1);r>0;r-=Number(!e[t++]));return t+(n&2)}function yy(e,t,n=0,r=0){let i=t??new Uint8Array(1024);if(!(e.length-n))return i;let a=vy(e,n);if(a===e.length-8)return i;if(a>e.length-8)throw Error(`unexpected EOF`);let o=a*8,s=0,c=0,l=0,u,d,f=e.length*8;function p(e){if(!t&&e>i.length){let t=i;i=new Uint8Array(Math.max(t.length*2,e)),i.set(t)}}do{if(!u){s=hy(e,o,1);let t=hy(e,o+1,3);if(o+=3,!t){let t=_y(o)+4,n=e[t-4]|e[t-3]<<8,a=t+n;if(a>e.length)throw Error(`unexpected EOF`);p(r+n),i.set(e.subarray(t,a),r),r+=n,o=a*8;continue}else if(t===1)u=Qv,d=$v,c=9,l=5;else if(t===2){let t=hy(e,o,31)+257,n=hy(e,o+10,15)+4,r=t+hy(e,o+5,31)+1;o+=14;let i=new Uint8Array(r),a=new Uint8Array(19);for(let t=0;t<n;++t)a[my[t]]=hy(e,o+t*3,7);o+=n*3;let s=Math.max(...a),f=(1<<s)-1,p=Yv(a,s,1);for(let t=0;t<r;){let n=p[hy(e,o,f)];o+=n&15;let r=n>>4;if(r<16)i[t++]=r;else{let n=0,a=0;for(r===16?(a=3+hy(e,o,3),o+=2,n=i[t-1]):r===17?(a=3+hy(e,o,7),o+=3):r===18&&(a=11+hy(e,o,127),o+=7);a--;)i[t++]=n}}let m=i.subarray(0,t),h=i.subarray(t);c=Math.max(...m),l=Math.max(...h),u=Yv(m,c,1),d=Yv(h,l,1)}else throw Error(`invalid block type`);if(o>f)throw Error(`unexpected EOF`)}p(r+131072);let t=(1<<c)-1,n=(1<<l)-1;for(;;){let a=u[gy(e,o)&t],s=a>>4;if(o+=a&15,o>f)throw Error(`unexpected EOF`);if(!a)throw Error(`invalid length/literal`);if(s<256)i[r++]=s;else if(s===256){u=void 0;break}else{let t=s-254;if(s>264){let n=s-257,r=Hv[n];t=hy(e,o,(1<<r)-1)+Gv[n],o+=r}if(!d)throw Error(`invalid distance map`);let a=d[gy(e,o)&n],c=a>>4;if(!a)throw Error(`invalid distance`);o+=a&15;let l=qv[c];if(c>3){let t=Uv[c];l+=gy(e,o)&(1<<t)-1,o+=t}if(o>f)throw Error(`unexpected EOF`);let u=r+t;if(r<l)throw Error(`unexpected dictionary case`);for(p(u);r<u;r++)i[r]=i[r-l]}}u&&(s=1)}while(!s);if(r<i.length){let t=Math.ceil(o/8)+8;yy(e,i,t,r)}return t?i:i.subarray(0,r)}let by;function xy(){if(!by){by=new Uint8Array(122784);let e=atob(`
69
69
  H4sIAAAAAAAAAzy96XIcx7Uu+tuI4DuU2meLxDbRAElNJgYHR0neGrgFyr7bPg5FdlV2dwHVVa3KKoBN
70
70
  SRHggIHgAFKcBc4zJQIgOGIggYjDF6D+kf8U56K6GxH3Ie73rYRsGRLQnZWVwxq+tXKtlYlf0V40GAZ+
71
71
  UQe6mBSU2+9GnvZUokw5GozCoGb8RLt+UouqOuxLTRL4/boYaz0Yxf2J3pfUtIqjAR0XIq8W4JdiFFcK
@@ -1035,6 +1035,6 @@ CPLhefDGNiyegGM43mti1BG/TiFdxrtVu4I26ivp3SJGrfCh1B6iJfcSnACcJemVMkZHsJFrI0lnJdms
1035
1035
  s6lwLLwmV4gKR4seJzhMXhnZuy+b9Hd/G3B8zj0TLgY+ZDEEUnkHS7w8hj3Hkm3YGxzI0vvCc9qr2Egb
1036
1036
  MTkwg9sJOkT8/jQ3KmnzBOLJyS9wLo3ELR3NZZ75gRlhN8fndGHhOc1ZSa3T8F7PabYqsjMvqRWKVy/i
1037
1037
  YEruPHv9jvnYZxalzUMH9iWulTvIaLTXEa5ZX8xVa61fFraX9QCIAKg5bh8rVRiy7m8o4pJl5O0ogZ8d
1038
- vmbCnCfH5TJKTBFva0O4Wl+l/Ix13xO6KCJPD5H51fete+aO/R8EyzZRoN8BAA==`),t=new Uint8Array(e.length);for(let n=0;n<e.length;n++)t[n]=e.charCodeAt(n);ty(t,ny)}return ny}var Q=class{constructor(e,t,n){this.prefix=new Uint8Array(e.length),this.transform=t,this.suffix=new Uint8Array(n.length);for(let t=0;t<e.length;t++)this.prefix[t]=e.charCodeAt(t);for(let e=0;e<n.length;e++)this.suffix[e]=n.charCodeAt(e)}};const iy=[new Q(``,0,``),new Q(``,0,` `),new Q(` `,0,` `),new Q(``,12,``),new Q(``,10,` `),new Q(``,0,` the `),new Q(` `,0,``),new Q(`s `,0,` `),new Q(``,0,` of `),new Q(``,10,``),new Q(``,0,` and `),new Q(``,13,``),new Q(``,1,``),new Q(`, `,0,` `),new Q(``,0,`, `),new Q(` `,10,` `),new Q(``,0,` in `),new Q(``,0,` to `),new Q(`e `,0,` `),new Q(``,0,`"`),new Q(``,0,`.`),new Q(``,0,`">`),new Q(``,0,`
1038
+ vmbCnCfH5TJKTBFva0O4Wl+l/Ix13xO6KCJPD5H51fete+aO/R8EyzZRoN8BAA==`),t=new Uint8Array(e.length);for(let n=0;n<e.length;n++)t[n]=e.charCodeAt(n);yy(t,by)}return by}var Q=class{constructor(e,t,n){this.prefix=new Uint8Array(e.length),this.transform=t,this.suffix=new Uint8Array(n.length);for(let t=0;t<e.length;t++)this.prefix[t]=e.charCodeAt(t);for(let e=0;e<n.length;e++)this.suffix[e]=n.charCodeAt(e)}};const Sy=[new Q(``,0,``),new Q(``,0,` `),new Q(` `,0,` `),new Q(``,12,``),new Q(``,10,` `),new Q(``,0,` the `),new Q(` `,0,``),new Q(`s `,0,` `),new Q(``,0,` of `),new Q(``,10,``),new Q(``,0,` and `),new Q(``,13,``),new Q(``,1,``),new Q(`, `,0,` `),new Q(``,0,`, `),new Q(` `,10,` `),new Q(``,0,` in `),new Q(``,0,` to `),new Q(`e `,0,` `),new Q(``,0,`"`),new Q(``,0,`.`),new Q(``,0,`">`),new Q(``,0,`
1039
1039
  `),new Q(``,3,``),new Q(``,0,`]`),new Q(``,0,` for `),new Q(``,14,``),new Q(``,2,``),new Q(``,0,` a `),new Q(``,0,` that `),new Q(` `,10,``),new Q(``,0,`. `),new Q(`.`,0,``),new Q(` `,0,`, `),new Q(``,15,``),new Q(``,0,` with `),new Q(``,0,`'`),new Q(``,0,` from `),new Q(``,0,` by `),new Q(``,16,``),new Q(``,17,``),new Q(` the `,0,``),new Q(``,4,``),new Q(``,0,`. The `),new Q(``,11,``),new Q(``,0,` on `),new Q(``,0,` as `),new Q(``,0,` is `),new Q(``,7,``),new Q(``,1,`ing `),new Q(``,0,`
1040
- `),new Q(``,0,`:`),new Q(` `,0,`. `),new Q(``,0,`ed `),new Q(``,20,``),new Q(``,18,``),new Q(``,6,``),new Q(``,0,`(`),new Q(``,10,`, `),new Q(``,8,``),new Q(``,0,` at `),new Q(``,0,`ly `),new Q(` the `,0,` of `),new Q(``,5,``),new Q(``,9,``),new Q(` `,10,`, `),new Q(``,10,`"`),new Q(`.`,0,`(`),new Q(``,11,` `),new Q(``,10,`">`),new Q(``,0,`="`),new Q(` `,0,`.`),new Q(`.com/`,0,``),new Q(` the `,0,` of the `),new Q(``,10,`'`),new Q(``,0,`. This `),new Q(``,0,`,`),new Q(`.`,0,` `),new Q(``,10,`(`),new Q(``,10,`.`),new Q(``,0,` not `),new Q(` `,0,`="`),new Q(``,0,`er `),new Q(` `,11,` `),new Q(``,0,`al `),new Q(` `,11,``),new Q(``,0,`='`),new Q(``,11,`"`),new Q(``,10,`. `),new Q(` `,0,`(`),new Q(``,0,`ful `),new Q(` `,10,`. `),new Q(``,0,`ive `),new Q(``,0,`less `),new Q(``,11,`'`),new Q(``,0,`est `),new Q(` `,10,`.`),new Q(``,11,`">`),new Q(` `,0,`='`),new Q(``,10,`,`),new Q(``,0,`ize `),new Q(``,11,`.`),new Q(`Â\xA0`,0,``),new Q(` `,0,`,`),new Q(``,10,`="`),new Q(``,11,`="`),new Q(``,0,`ous `),new Q(``,11,`, `),new Q(``,10,`='`),new Q(` `,10,`,`),new Q(` `,11,`="`),new Q(` `,11,`, `),new Q(``,11,`,`),new Q(``,11,`(`),new Q(``,11,`. `),new Q(` `,11,`.`),new Q(``,11,`='`),new Q(` `,11,`. `),new Q(` `,10,`="`),new Q(` `,11,`='`),new Q(` `,10,`='`)],ay=iy.length;function oy(e,t){return e[t]<192?(e[t]>=97&&e[t]<=122&&(e[t]^=32),1):e[t]<224?(e[t+1]^=32,2):(e[t+2]^=5,3)}function sy(e,t,n,r,i){let a=ry(),{prefix:o}=iy[i],{suffix:s}=iy[i],c=iy[i].transform,l=c<12?0:c-11,u=t;l>r&&(l=r);let d=0;for(;d<o.length;)e[t++]=o[d++];n+=l,r-=l,c<=9&&(r-=c);for(let i=0;i<r;i++)e[t++]=a[n+i];let f=t-r;if(c===10)oy(e,f);else if(c===11)for(;r>0;){let t=oy(e,f);f+=t,r-=t}let p=0;for(;p<s.length;)e[t++]=s[p++];return t-u}const cy=new Uint8Array([3,2,1,0,3,3,3,3,3,3,2,2,2,2,2,2]),ly=new Int8Array([0,0,0,0,-1,1,-2,2,-3,3,-1,1,-2,2,-3,3]),uy=new Uint32Array([0,0,0,0,0,4096,9216,21504,35840,44032,53248,63488,74752,87040,93696,100864,104704,106752,108928,113536,115968,118528,119872,121280,122016]),dy=new Uint8Array([0,0,0,0,10,10,11,11,10,10,10,10,10,9,9,8,7,7,8,7,7,6,6,5,5]);function fy(e,t){let n=new Uint8Array(t);return py(new Jv(e),new Yv(n)),n}function py(e,t){let n=0,r=0,i=0,a=[16,15,11,4],o=0,s=[new gv(0,0),new gv(0,0),new gv(0,0)],c=128+ov.READ_SIZE,l=new ov(e),u=Bv(l),d=(1<<u)-16,f=1<<u,p=f-1,m=new Uint8Array(f+c+24),h=f,g=[],_=[];for(let e=0;e<3*Cv;e++)g[e]=new Z(0,0),_[e]=new Z(0,0);for(;!r;){let e=[1<<28,1<<28,1<<28],c=[0],u=[1,1,1],v=[0,1,0,1,0,1],y=[0];for(let e=0;e<3;e++)s[e].codes=[],s[e].htrees=new Uint32Array;l.readMoreInput();let b=Lv(l),x=b.meta_block_length;if(n+x>t.buffer.length){let e=new Uint8Array(n+x);e.set(t.buffer),t.buffer=e}if(r=b.input_end,b.is_metadata){for(Vv(l);x>0;--x)l.readMoreInput(),l.readBits(8);continue}if(x===0)continue;if(b.is_uncompressed){l.bit_pos_=l.bit_pos_+7&-8,Rv(t,x,n,m,p,l),n+=x;continue}for(let t=0;t<3;t++)u[t]=zv(l)+1,u[t]>=2&&(pv(u[t]+2,g,t*Cv,l),pv(26,_,t*Cv,l),e[t]=Hv(_,t*Cv,l),y[t]=1);l.readMoreInput();let S=l.readBits(2),C=16+(l.readBits(4)<<S),w=(1<<S)-1,T=C+(48<<S),E=new Uint8Array(u[0]);for(let e=0;e<u[0];e++)l.readMoreInput(),E[e]=l.readBits(2)<<1;let[D,O]=Gv(u[0]<<6,l),[k,A]=Gv(u[2]<<2,l);s[0]=new gv(256,D),s[1]=new gv(704,u[1]),s[2]=new gv(T,k);for(let e=0;e<3;++e)s[e].decode(l);let j=0,M=0,N=E[c[0]],ee=Wv[N],P=Wv[N+1],te=s[1].htrees[0];for(;x>0;){let r;l.readMoreInput(),e[1]===0&&(Iv(u[1],g,1,c,v,y,l),e[1]=Hv(_,Cv,l),te=s[1].htrees[c[1]]),e[1]--;let b=mv(s[1].codes,te,l),T=b>>6;T>=2?(T-=2,r=-1):r=0;let D=yv[xv[T]+(b>>3&7)],k=D.offset+l.readBits(D.nbits),ne=bv[Sv[T]+(b&7)],re=ne.offset+l.readBits(ne.nbits),ie=m[n-1&p],ae=m[n-2&p];for(let r=0;r<k;r++){l.readMoreInput(),e[0]===0&&(Iv(u[0],g,0,c,v,y,l),e[0]=Hv(_,0,l),j=c[0]<<6,N=E[c[0]],ee=Wv[N],P=Wv[N+1]);let r=Uv[ee+ie]|Uv[P+ae],i=O[j+r];e[0]--,ae=ie,ie=mv(s[0].codes,s[0].htrees[i],l),m[n&p]=ie,(n&p)===p&&t.write(m,f),n++}if(x-=k,x<=0)break;if(r<0){l.readMoreInput(),e[2]===0&&(Iv(u[2],g,2,c,v,y,l),e[2]=Hv(_,2*Cv,l),M=c[2]<<2),e[2]--;let t=(re>4?3:re-2)&255,n=A[M+t];if(r=mv(s[2].codes,s[2].htrees[n],l),r>=C){r-=C;let e=r&w;r>>=S;let t=(r>>1)+1;r=C+((2+(r&1)<<t)-4+l.readBits(t)<<S)+e}}let oe=my(r,a,o);if(oe<0)throw Error(`[BrotliDecompress] invalid distance`);i=n<d&&i!==d?n:d;let se=n&p;if(oe>i)if(re>=4&&re<=24){let e=uy[re],r=oe-i-1,a=dy[re],o=r&(1<<a)-1,s=r>>a;if(e+=o*re,s<ay){let r=sy(m,se,e,re,s);if(se+=r,n+=r,x-=r,se>=h){t.write(m,f);for(let e=0;e<se-h;e++)m[e]=m[h+e]}}else throw Error(`Invalid backward reference`)}else throw Error(`Invalid backward reference`);else{if(r>0&&(a[o&3]=oe,o++),re>x)throw Error(`Invalid backward reference`);for(let e=0;e<re;e++)m[n&p]=m[n-oe&p],(n&p)===p&&t.write(m,f),n++,x--}}n&=1073741823}t.write(m,n&p)}function my(e,t,n){return e<16?(n+=cy[e],n&=3,t[n]+ly[e]):e-16+1}function hy(e,t){let n=new Uint8Array(t);try{let t=0,r=0;for(;t<e.length-8;){let i=e[t++]<<24|e[t++]<<16|e[t++]<<8|e[t++],a=e[t++]<<24|e[t++]<<16|e[t++]<<8|e[t++];if(e.length-t<a||n.length<i||_y(e.subarray(t,t+a),n,r)!==i)throw Error(`lz4 not hadoop`);if(t+=a,r+=i,t===e.length)return n}if(t<e.length)throw Error(`lz4 not hadoop`)}catch(t){if(t instanceof Error&&t.message!==`lz4 not hadoop`)throw t;_y(e,n,0)}return n}function gy(e,t){let n=new Uint8Array(t);return _y(e,n,0),n}function _y(e,t,n){let r=n;for(let i=0;i<e.length;){let a=e[i++],o=a>>4;if(o){let a=o+240;for(;a===255;)o+=a=e[i++];if(t.set(e.subarray(i,i+o),r),r+=o,i+=o,i>=e.length)return r-n}let s=e[i++]|e[i++]<<8;if(!s||s>r)throw Error(`lz4 offset out of range ${s}`);let c=a&15,l=c+240;for(;l===255;)c+=l=e[i++];c+=4;let u=r-s,d=r+c;for(;r<d;)t[r++]=t[u++]}return r-n}const vy={SNAPPY:ev(),GZIP:(e,t)=>ty(e,new Uint8Array(t)),BROTLI:fy,ZSTD:e=>Yf(e),LZ4:hy,LZ4_RAW:gy},yy=1e3,by=e=>e instanceof Float64Array&&(e.byteOffset!==0||e.buffer.byteLength!==e.byteLength)?e.slice():e;function xy(e,t){async function*n(e,t,n){let r=e.groups[t.group],i=e.file.tables[r.table],a=t=>r.absolute&&t!==null?e.origin-(i.columns[t].origin??0):0;if(r.long){yield*zc(i,r.long.shape,r.long.scan,t.channels,t.group,a(r.long.shape.time),n);return}let o=t.channels.map(e=>r.columns[e]),s=0;for await(let e of i.read(r.time===null?o:[r.time,...o],n)){let n=null;if(r.time!==null){let t=e.columns[0],i=a(r.time);n=new Float64Array(e.length);for(let r=0;r<e.length;r++)n[r]=t[r]-i}let c=(r.time===null?e.columns:e.columns.slice(1)).map(by);o.forEach((e,t)=>{let n=i.columns[e].origin;if(n){let e=c[t];for(let t=0;t<e.length;t++)e[t]+=n}}),yield{group:t.group,time:n,start:s,length:e.length,columns:c},s+=e.length}}return{...e,async plan(e,n){let r=await t(e,n),i=[],a=[],o=[...r.notes],s=1/0,c=!1;for(let[t,n]of r.tables.entries()){o.push(...n.notes);let r=e.asTable?null:Lc(n.columns),l=r?await Rc(n,r):null;if(r&&l){let e=!!n.columns[r.time].absolute;e&&(s=Math.min(s,(n.columns[r.time].origin??0)+l.start)),a.push({table:t,long:{shape:r,scan:l},absolute:e}),i.push({name:n.name,channels:l.tags.map((e,t)=>({name:e,unit:l.units[t],sparse:!0})),samples:l.times,time:{kind:`timestamps`},rateHz:null,irregular:!0}),o.push(`${n.name}: one row per sample; ${l.tags.length.toLocaleString(`en-US`)} ${l.tags.length===1?`tag`:`tags`} opened as channels.`),l.sorted||o.push(`${n.name}: the rows were not in time order and were sorted.`),l.repeated&&o.push(`${n.name}: ${l.repeated.toLocaleString(`en-US`)} repeated ${l.repeated===1?`sample`:`samples`} (same time and tag) ${l.repeated===1?`was`:`were`} dropped; the first was kept.`),c=!0;continue}let u=n.columns.findIndex(e=>e.kind===`time`),d=n.columns.flatMap((e,t)=>t===u?[]:[t]);if(d.length===0){o.push(`${n.name}: no channels besides its time; skipped.`);continue}let f=u>=0&&!!n.columns[u].absolute;if(f){let e=await Gc(n,u);Number.isNaN(e)||(s=Math.min(s,(n.columns[u].origin??0)+e))}a.push({table:t,long:null,time:u>=0?u:null,columns:d,absolute:f}),i.push({name:n.name,channels:d.map(e=>({name:n.columns[e].name,unit:n.columns[e].unit,text:n.columns[e].kind===`text`})),samples:n.rows,time:u>=0?{kind:`timestamps`}:{kind:`index`},rateHz:null})}if(i.length===0)throw Error(`${e.main.name}: no numbers to chart in this file.`);let l=i.filter((e,t)=>!a[t].long&&e.time.kind===`timestamps`);if(l.length>1)for(let e of l)e.irregular=!0;Number.isFinite(s)||(s=0);let u=a.some(e=>e.absolute)&&s?new Date(s*1e3).toISOString():null,d,f=i.filter((e,t)=>a[t].long&&e.channels.length>1e3);if(f.length){d=i.map((e,t)=>({group:t,channels:(a[t].long?e.channels.slice(0,yy):e.channels).map((e,t)=>t)}));for(let e of f)o.push(`${e.name}: ${e.channels.length.toLocaleString(`en-US`)} tags; the first ${yy.toLocaleString(`en-US`)} are loaded.`)}return{format:r.format,startTime:u,groups:i,meta:c?{layout:`long`}:{},events:[],notes:o,defaultSelection:d,state:{file:r,groups:a,origin:s}}},stream:e=>(async function*(){for(let t of e.selection)yield*n(e.plan.state,t,e.signal)})(),streamGroup:(e,t)=>n(e.plan.state,e.selection.find(e=>e.group===t),e.signal)}}const Sy={id:`parquet`,label:`Parquet`,extensions:[`.parquet`,`.pq`],sniff:e=>e[0]===80&&e[1]===65&&e[2]===82&&e[3]===49},Cy={timestampFromMilliseconds:e=>e*1000000n,timestampFromMicroseconds:e=>e*1000n,timestampFromNanoseconds:e=>e,dateFromDays:e=>e*86400};function wy(e,t){if(e.first===void 0){e.first=t;let n=Number(t)/1e9;e.column.origin=e.wall?Uc(n):n}let n=Number(t-e.first)/1e9;if(!e.wall)return n;let r=Number(e.first)/1e9;return n+(Wc(r+n)-Wc(r))}function Ty(e,t){let n=e.element,r=n.logical_type?.type,i=n.converted_type,a=e.path.join(`.`);if(r===`LIST`||r===`MAP`||i===`LIST`||i===`MAP`||i===`MAP_KEY_VALUE`||n.repetition_type===`REPEATED`)return t.push(a),[];if(e.children.length)return e.children.flatMap(e=>Ty(e,t));if(n.type===`INT96`)return[{path:e.path,column:{name:a,unit:``,kind:`time`,absolute:!0},wall:!1,ns:!0}];if(r===`TIMESTAMP`||r===`DATE`||i===`TIMESTAMP_MILLIS`||i===`TIMESTAMP_MICROS`||i===`DATE`){let t=r===`DATE`||i===`DATE`,o=n.logical_type?.type===`TIMESTAMP`?!n.logical_type.isAdjustedToUTC:t;return[{path:e.path,column:{name:a,unit:``,kind:`time`,absolute:!0},wall:o,ns:!t}]}if(r===`STRING`||r===`ENUM`||r===`JSON`||i===`UTF8`||i===`ENUM`||i===`JSON`)return[{path:e.path,column:{name:a,unit:``,kind:`text`},wall:!1}];if(!(n.type===`BOOLEAN`||n.type===`INT32`||n.type===`INT64`||n.type===`FLOAT`||n.type===`DOUBLE`||r===`DECIMAL`||i===`DECIMAL`))return t.push(a),[];let o=e.path.length===1&&Bc.test(n.name);return[{path:e.path,column:{name:a,unit:o?`s`:``,kind:o?`time`:`number`},wall:!1}]}const Ey=e=>typeof e==`number`?e:typeof e==`bigint`?Number(e):typeof e==`boolean`?+!!e:NaN,Dy=(e,t)=>{for(let n of t)e=e?.[n];return e},Oy=async e=>{try{return await e}catch{throw Error(`This Parquet file is damaged (its metadata or pages could not be read).`)}};async function ky(e,t=8388608){let n={byteLength:e.size,slice:async(t,n=e.size)=>(await e.slice(t,n-t)).slice().buffer},r=await Oy(kh(n,{parsers:Cy})),i=[],a=jh(r).children.flatMap(e=>Ty(e,i)),o=i.length?[`${i.length} ${i.length===1?`column`:`columns`} skipped (lists, maps or binary): ${i.slice(0,5).join(`, `)}${i.length>5?`, …`:``}.`]:[],s={name:`Table`,columns:a.map(e=>e.column),rows:Number(r.num_rows),notes:o,async*read(e,i){let o=e.map(e=>a[e]),s=[...new Set(o.map(e=>e.path[0]))],c=Math.max(1,Math.floor(t/Math.max(1,o.length))),l=0;for(let e of r.row_groups){let t=l,a=l+Number(e.num_rows);l=a;for(let e=t;e<a;e+=c){i?.throwIfAborted();let t=Math.min(a,e+c),l=-1,u=[];for(let i of s){let a=[];if(await Oy(Q_({file:n,metadata:r,columns:[i],rowStart:e,rowEnd:t,compressors:vy,parsers:Cy,onChunk:e=>{a.push({start:e.rowStart,data:e.columnData})}})),l<0){if(l=Math.min(t-e,a.reduce((t,n)=>Math.max(t,n.start+n.data.length-e),0)),l===0)break;for(let e of o)u.push(e.column.kind===`text`?Array(l).fill(null):new Float64Array(l).fill(NaN))}o.forEach((t,n)=>{if(t.path[0]!==i)return;let r=u[n],o=t.column.kind===`text`;for(let n of a){if(!o&&!t.wall&&!t.iso&&!t.ns&&t.path.length===1&&n.start>=e&&n.start-e+n.data.length<=l&&ArrayBuffer.isView(n.data)&&!(n.data instanceof BigInt64Array)&&!(n.data instanceof BigUint64Array)){r.set(n.data,n.start-e);continue}for(let i=Math.max(0,e-n.start);i<n.data.length;i++){let a=n.start+i-e;if(a>=l)break;let s=t.path.length>1?Dy(n.data[i],t.path.slice(1)):n.data[i];if(o)r[a]=s==null?null:String(s);else if(t.ns)r[a]=typeof s==`bigint`?wy(t,s):NaN;else{let e=t.iso?s==null?NaN:Hc(String(s)):Ey(s);r[a]=t.wall&&!Number.isNaN(e)?Uc(e):e}}}})}if(l<=0)break;yield{length:l,columns:u}}}}},c=a.flatMap((e,t)=>e.column.kind===`text`?[t]:[]);if(c.length)for await(let e of s.read(c)){c.forEach((t,n)=>{let r=e.columns[n];!r.some(e=>e)||r.some(e=>e&&Number.isNaN(Hc(e)))||(a[t].iso=!0,Object.assign(a[t].column,{kind:`time`,absolute:!0}))});break}return{format:`Parquet`,tables:[s],notes:[]}}const Ay=xy(Sy,(e,t)=>ky(t)),jy={id:`xlsx`,label:`Excel workbook`,extensions:[`.xlsx`,`.xlsm`],sniff:e=>e[0]===80&&e[1]===75&&e[2]===3&&e[3]===4&&u(e).includes(`xl/`)},My=`This workbook is damaged (its ZIP structure could not be read).`;async function Ny(e){let t=Math.min(e.size,65557),n=await e.read(e.size-t,t),r=new DataView(n.buffer,n.byteOffset,n.byteLength),i=-1;for(let e=n.length-22;e>=0;e--)if(r.getUint32(e,!0)===101010256){i=e;break}if(i<0)throw Error(My);let a=r.getUint16(i+10,!0),o=r.getUint32(i+12,!0),s=r.getUint32(i+16,!0);if(s===4294967295||a===65535)throw Error(`Workbooks over 4 GB are not supported.`);let c=await e.slice(s,o),l=new DataView(c.buffer,c.byteOffset,c.byteLength),u=new TextDecoder,d=new Map;for(let e=0,t=0;t<a;t++){if(e+46>c.length||l.getUint32(e,!0)!==33639248)throw Error(My);let t=l.getUint16(e+28,!0),n=u.decode(c.subarray(e+46,e+46+t));d.set(n.replace(/^\//,``),{method:l.getUint16(e+10,!0),compressed:l.getUint32(e+20,!0),offset:l.getUint32(e+42,!0)}),e+=46+t+l.getUint16(e+30,!0)+l.getUint16(e+32,!0)}return d}async function*Py(e,t){let n=await e.read(t.offset,30),r=new DataView(n.buffer,n.byteOffset,n.byteLength);if(n.length<30||r.getUint32(0,!0)!==67324752)throw Error(My);let i=t.offset+30+r.getUint16(26,!0)+r.getUint16(28,!0),a=new TextDecoder;if(t.method===0)for await(let n of e.windows(i,t.compressed))yield a.decode(n.bytes,{stream:!0});else if(t.method===8){let n=[],r=new Qe(e=>{n.push(e)});try{for await(let o of e.windows(i,t.compressed,1<<20))for(r.push(o.bytes,!1);n.length;)yield a.decode(n.shift(),{stream:!0});r.push(new Uint8Array,!0)}catch{throw Error(My)}for(;n.length;)yield a.decode(n.shift(),{stream:!0})}else throw Error(`This workbook uses a ZIP compression Kymoscope does not read (method ${t.method}).`);let o=a.decode();o&&(yield o)}async function Fy(e,t,n=268435456){if(!t)return``;let r=``;for await(let i of Py(e,t)){if(r.length+i.length>n)throw Error(`This workbook is too large to read (one of its parts holds over 256 MB of text).`);r+=i}return r}const Iy=1048576;var Ly=class{rows=0;cols=[];#e=0;budget;constructor(e=T){this.budget=e}#t(e){if(this.#e+=e,this.#e>this.budget)throw Error(`This sheet is too large to open (over ${this.budget.toLocaleString(`en-US`)} cells).`)}put(e,t,n,r){if(e<0||t<0)return;if(e>=Iy)throw Error(`This sheet has a cell beyond Excel's last row (1,048,576); the file may be damaged.`);if(t>=16384)throw Error(`This sheet has a cell beyond Excel's last column (XFD); the file may be damaged.`);e>=this.rows&&(this.rows=e+1);let i=this.cols[t];if(i||=(this.#t(256),this.cols[t]={num:new Float64Array(256).fill(NaN),date:new Uint8Array(256),text:new Map}),typeof n==`string`){n.trim()&&(this.#t(1),i.text.set(e,n));return}if(e>=i.num.length){let t=Math.min(Iy,Math.max(e+1,i.num.length*2));this.#t(t-i.num.length);let n=new Float64Array(t).fill(NaN);n.set(i.num);let r=new Uint8Array(t);r.set(i.date),i.num=n,i.date=r}i.num[e]=n,i.date[e]=+!!r}numbersIn(e){return this.cols.reduce((t,n)=>t+(n&&e<n.num.length&&!Number.isNaN(n.num[e])?1:0),0)}textsIn(e){return this.cols.reduce((t,n)=>t+ +!!n?.text.has(e),0)}};const Ry=e=>e<26?String.fromCharCode(65+e):Ry(Math.floor(e/26)-1)+String.fromCharCode(65+e%26),zy=65536;function By(e,t,n,r){let i=t.cols.filter(Boolean).length,a=-1;for(let e=0;e<Math.min(t.rows,50);e++)if(t.textsIn(e)>=Math.max(1,Math.ceil(i/2))&&(t.numbersIn(e+1)>0||t.numbersIn(e+2)>0)){a=e;break}let o=a+1,s=-1;a>=0&&t.numbersIn(o)===0&&t.textsIn(o)>0&&t.cols.every(e=>!e?.text.has(o)||e.text.get(o).length<=16)&&(s=o,o++);let c=[];a>0&&Array.from({length:a},(e,n)=>t.textsIn(n)+t.numbersIn(n)).some(e=>e>0)&&c.push(`${e}: rows 1–${a} above the header were skipped.`),r&&c.push(`${e}: ${r.toLocaleString(`en-US`)} formula ${r===1?`cell has`:`cells have`} no saved value (the workbook was saved without calculating them); ${r===1?`it is`:`they are`} empty.`);let l=[],u=[];return t.cols.forEach((e,r)=>{if(!e)return;let i=0,c=0;for(let n=o;n<Math.min(t.rows,e.num.length);n++)Number.isNaN(e.num[n])||(i++,c+=e.date[n]);let d=0;for(let t of e.text.keys())t>=o&&d++;if(i+d===0)return;let f=(a>=0?e.text.get(a)?.trim():void 0)||`Column ${Ry(r)}`,p=i===0;if(p){for(let[t,n]of e.text)if(t>=o&&Number.isNaN(Hc(n))){p=!1;break}}let m=p?`time`:i>=d?c*2>i||Bc.test(f)?`time`:`number`:`text`,h=p?`iso`:m===`time`&&c*2>i?`serial`:null,g=NaN;if(h===`serial`)for(let t=o;t<e.num.length&&Number.isNaN(g);t++)g=e.num[t];let _=Number.isNaN(g)?void 0:Uc((g-n)*86400);l.push({name:f,unit:s>=0?e.text.get(s)?.trim()??``:``,kind:m,absolute:h!==null,origin:_}),u.push({col:e,kind:m,from:h,first:g})}),l.some(e=>e.kind!==`text`)?{name:e,columns:l,rows:Math.max(0,t.rows-o),notes:c,async*read(e,r){for(let i=o;i<t.rows;i+=zy){r?.throwIfAborted();let a=Math.min(t.rows,i+zy);yield{length:a-i,columns:e.map(e=>{let{col:t,kind:r,from:o,first:s}=u[e];if(r===`text`)return Array.from({length:a-i},(e,n)=>t.text.get(i+n)??(i+n<t.num.length&&!Number.isNaN(t.num[i+n])?String(t.num[i+n]):null));let c=new Float64Array(a-i).fill(NaN);if(o===`iso`){for(let e=0;e<c.length;e++){let n=t.text.get(i+e);n!==void 0&&(c[e]=Hc(n))}return c}if(c.set(t.num.subarray(Math.min(i,t.num.length),Math.min(a,t.num.length))),o===`serial`){let e=Wc((s-n)*86400);for(let t=0;t<c.length;t++){let r=c[t];Number.isNaN(r)||(c[t]=Math.round((r-s)*864e5)/1e3+(Wc((r-n)*86400)-e))}}return c})}}}}:`${e}: no numbers; skipped.`}async function Vy(e){let t=await Ny(e),{sheets:n,date1904:r}=hl(await Fy(e,t.get(`xl/workbook.xml`)),await Fy(e,t.get(`xl/_rels/workbook.xml.rels`)));if(n.length===0)throw Error(`This workbook has no sheets Kymoscope can read.`);let i=yl(await Fy(e,t.get(`xl/sharedStrings.xml`))),a=vl(await Fy(e,t.get(`xl/styles.xml`))),o=r?24107:25569,s=[],c=[];for(let r of n){let n=t.get(r.path);if(!n)continue;let l=new Ly(T-i.length),u=await Tl(Py(e,n),i,a,(e,t,n,r)=>l.put(e,t,n,r)),d=By(r.name,l,o,u);typeof d==`string`?c.push(d):s.push(d)}return{format:`Excel workbook`,tables:s,notes:c}}const Hy=xy(jy,(e,t)=>Vy(t)),Uy={id:`longtext`,label:`Delimited text, one row per sample`,extensions:[`.csv`,`.tsv`,`.txt`,`.dat`],sniff:(e,t)=>/\.(csv|tsv|txt|dat)$/i.test(t)&&!e.includes(0)&&Xc(new TextDecoder().decode(e))},Wy=65536;async function*Gy(e,t){let n=new TextDecoder,r=``;for await(let i of e.windows(0,e.size)){t?.throwIfAborted();let e=(r+n.decode(i.bytes,{stream:!0})).split(/\r?\n/);r=e.pop(),yield*e}r+=n.decode(),r&&(yield r)}async function Ky(e){let t=[];for await(let n of Gy(e))if(n.trim()&&t.push(n),t.length>200)break;if(t.length<2)throw Error(`This file has no rows.`);let n=qc(t.slice(0,50))??`,`,r=n===`;`,i=Yc(Kc(t[0],n),t.slice(1).map(e=>Kc(e,n)),r);return{format:`Delimited text`,tables:[{name:`Table`,columns:i,rows:-1,notes:[],async*read(t,a){let o=()=>t.map(e=>i[e].kind===`text`?Array(Wy).fill(null):new Float64Array(Wy).fill(NaN)),s=o(),c=0,l=!0;for await(let u of Gy(e,a)){if(!u.trim())continue;if(l){l=!1;continue}let e=Kc(u,n);for(let n=0;n<t.length;n++){let a=i[t[n]],o=e[t[n]]??``;a.kind===`text`?s[n][c]=o.trim()===``?null:o.trim():s[n][c]=a.absolute?Hc(o):Jc(o,r)}++c===Wy&&(yield{length:c,columns:s},s=o(),c=0)}c&&(yield{length:c,columns:s.map(e=>e.slice(0,c))})}}],notes:[]}}const qy=xy(Uy,(e,t)=>Ky(t));new TextEncoder;function Jy(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>=4096&&(o+=String.fromCharCode(...a),a.length=0)}return a.length>0&&(o+=String.fromCharCode(...a)),o}const Yy=new TextDecoder;function Xy(e,t,n){let r=e.subarray(t,t+n);return Yy.decode(r)}function Zy(e,t,n){return n>200?Xy(e,t,n):Jy(e,t,n)}var Qy=class{type;data;constructor(e,t){this.type=e,this.data=t}},$y=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 eb(e,t,n){let r=Math.floor(n/4294967296),i=n;e.setUint32(t,r),e.setUint32(t+4,i)}function tb(e,t){let n=e.getInt32(t),r=e.getUint32(t+4);return n*4294967296+r}function nb(e,t){let n=e.getUint32(t),r=e.getUint32(t+4);return n*4294967296+r}function rb({sec:e,nsec:t}){if(e>=0&&t>=0&&e<=17179869183)if(t===0&&e<=4294967295){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),eb(r,4,e),n}}function ib(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 ab(e){return e instanceof Date?rb(ib(e)):null}function ob(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:tb(t,4),nsec:t.getUint32(0)};default:throw new $y(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${e.length}`)}}function sb(e){let t=ob(e);return new Date(t.sec*1e3+t.nsec/1e6)}const cb={type:-1,encode:ab,decode:sb};var lb=class e{static defaultCodec=new e;__brand;builtInEncoders=[];builtInDecoders=[];encoders=[];decoders=[];constructor(){this.register(cb)}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 Qy(-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 Qy(n,i)}}return e instanceof Qy?e:null}decode(e,t,n){let r=t<0?this.builtInDecoders[-1-t]:this.decoders[t];return r?r(e,t,n):new Qy(t,e)}};function ub(e){return e instanceof ArrayBuffer||typeof SharedArrayBuffer<`u`&&e instanceof SharedArrayBuffer}function db(e){return e instanceof Uint8Array?e:ArrayBuffer.isView(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):ub(e)?new Uint8Array(e):Uint8Array.from(e)}function fb(e){return`${e<0?`-`:``}0x${Math.abs(e).toString(16).padStart(2,`0`)}`}var pb=class{hit=0;miss=0;caches;maxKeyLength;maxLengthPerKey;constructor(e=16,t=16){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=Jy(e,t,n),a=Uint8Array.prototype.slice.call(e,t,t+n);return this.store(a,i),i}};const mb=`array`,hb=`map_key`,gb=`map_value`,_b=e=>{if(typeof e==`string`||typeof e==`number`)return e;throw new $y(`The type of key must be string or number but `+typeof e)};var vb=class{stack=[];stackHeadPosition=-1;get length(){return this.stackHeadPosition+1}top(){return this.stack[this.stackHeadPosition]}pushArrayState(e){let t=this.getUninitializedStateFromPool();t.type=mb,t.position=0,t.size=e,t.array=Array(e)}pushMapState(e){let t=this.getUninitializedStateFromPool();t.type=hb,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===mb){let t=e;t.size=0,t.array=void 0,t.position=0,t.type=void 0}if(e.type===hb||e.type===gb){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}};const yb=new DataView(new ArrayBuffer(0)),bb=new Uint8Array(yb.buffer);try{yb.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`)}const xb=RangeError(`Insufficient data`),Sb=new pb;var Cb=class e{extensionCodec;context;useBigInt64;rawStrings;maxStrLength;maxBinLength;maxArrayLength;maxMapLength;maxExtLength;keyDecoder;mapKeyConverter;totalPos=0;pos=0;view=yb;bytes=bb;headByte=-1;stack=new vb;entered=!1;constructor(e){this.extensionCodec=e?.extensionCodec??lb.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?Sb:e.keyDecoder,this.mapKeyConverter=e?.mapKeyConverter??_b}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=-1,this.stack.reset()}setBuffer(e){let t=db(e);this.bytes=t,this.view=new DataView(t.buffer,t.byteOffset,t.byteLength),this.pos=0}appendBuffer(e){if(this.headByte===-1&&!this.hasRemaining(1))this.setBuffer(e);else{let t=this.bytes.subarray(this.pos),n=db(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 ${fb(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 $y(`Unrecognized type byte: ${fb(e)}`);this.complete();let n=this.stack;for(;n.length>0;){let e=n.top();if(e.type===mb)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===hb){if(t===`__proto__`)throw new $y(`The key __proto__ is not allowed`);e.key=this.mapKeyConverter(t),e.type=gb;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=hb;continue DECODE}}return t}}readHeadByte(){return this.headByte===-1&&(this.headByte=this.readU8()),this.headByte}complete(){this.headByte=-1}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 $y(`Unrecognized array type byte: ${fb(e)}`)}}pushMapState(e){if(e>this.maxMapLength)throw new $y(`Max length exceeded: map length (${e}) > maxMapLengthLength (${this.maxMapLength})`);this.stack.pushMapState(e)}pushArrayState(e){if(e>this.maxArrayLength)throw new $y(`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 $y(`Max length exceeded: UTF-8 byte length (${e}) > maxStrLength (${this.maxStrLength})`);if(this.bytes.byteLength<this.pos+t+e)throw xb;let n=this.pos+t,r;return r=this.stateIsMapKey()&&this.keyDecoder?.canBeCached(e)?this.keyDecoder.decode(this.bytes,n,e):Zy(this.bytes,n,e),this.pos+=t+e,r}stateIsMapKey(){return this.stack.length>0?this.stack.top().type===hb:!1}decodeBinary(e,t){if(e>this.maxBinLength)throw new $y(`Max length exceeded: bin length (${e}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining(e+t))throw xb;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 $y(`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=nb(this.view,this.pos);return this.pos+=8,e}readI64(){let e=tb(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 wb(e,t){return new Cb(t).decode(e)}const Tb=e=>e+7&-8;function Eb(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)!==1)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=Tb(s),s+Tb(i*8)+o.reduce((e,t)=>e+Tb(i*t.size),0)>e.byteLength)throw t(`short data`);let c=e.byteOffset,l=new Float64Array(e.buffer,c+s,i);s+=Tb(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+=Tb(i*t.size);return{t:l,columns:u,units:d}}function Db(e){return e.values.map(e=>e.buffer)}const Ob=`ElapsedTime`;function kb(){let e=globalThis.crypto;if(!e?.subtle)throw Error(`WebCrypto SubtleCrypto is not available`);return e.subtle}async function Ab(e,t,n,r){let i=await kb().decrypt({name:`AES-GCM`,iv:t,additionalData:r},e,n);return new Uint8Array(i)}new TextEncoder().encode(`kymoscope-device-wrap-v1`),new TextEncoder().encode(`kymoscope-sender-bind-v1`);const jb=e=>Array.from(e,e=>e.toString(16).padStart(2,`0`)).join(``),Mb=e=>{let t=jb(e);return`${t.slice(0,8)}-${t.slice(8,12)}-${t.slice(12,16)}-${t.slice(16,20)}-${t.slice(20)}`};function Nb(e){if(e.length!==70||e[0]!==1)return null;let t=new DataView(e.buffer,e.byteOffset,e.byteLength);return{streamId:Mb(e.subarray(1,17)),run:jb(e.subarray(17,25)),lane:e[25],seq:t.getBigUint64(26,!0),count:t.getUint32(34,!0),hash:e.slice(38,70)}}const Pb=()=>globalThis.crypto.subtle,Fb=e=>Pb().digest(`SHA-256`,e);async function Ib(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 Fb(n))}const Lb=e=>crypto.subtle.digest(`SHA-256`,e),Rb=e=>Array.from(new Uint8Array(e),e=>e.toString(16).padStart(2,`0`)).join(``),zb=e=>Uint8Array.from(e.replace(/-/g,``).match(/../g)??[],e=>parseInt(e,16));async function Bb(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?Nb(a.plaintext):null,s=Rb(await Lb(zb(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&&Rb((await Ib(t.slice(0,-1).map(e=>Lb(e.bytes)))).buffer)===Rb(o.hash.buffer)?`verified`:`broken`}function Vb(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}const Hb=64*1024*1024,$=(e,t)=>RangeError(`${e}: ${t}`);function Ub(e,t){let n=new TextDecoder(`utf-8`,{fatal:!0}),r=[],i=0;try{for(let a=0;a<t;a++){if(i+3>e.byteLength)throw $(`block schema`,`short channel table`);let t=e[i],a=e[i+1],o=e[i+2];if(i+=3,t!==4&&t!==8)throw $(`block schema`,`value size ${t}`);if(i+a+o>e.byteLength)throw $(`block schema`,`short channel table`);r.push({name:n.decode(e.subarray(i,i+a)),unit:n.decode(e.subarray(i+a,i+a+o)),size:t}),i+=a+o}}catch(e){throw e instanceof RangeError?e:$(`block schema`,`invalid text`)}return r}async function Wb(e){if(e.byteLength<8)throw $(`block schema`,`short`);let t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=t.getUint8(0);if(n===3){if(e.byteLength<12)throw $(`block schema`,`short`);let n=t.getUint32(4,!0);if(n>1e5)throw $(`block schema`,`too many channels`);let r=t.getUint8(1)&1?await Jb(e.subarray(12),n*513,!1):e.subarray(12);return{id:t.getUint32(8,!0),channels:Ub(r,n)}}if(n!==2)throw $(`block schema`,`version ${n}`);return{id:t.getUint32(4,!0),channels:Ub(e.subarray(8),t.getUint16(2,!0))}}function Gb(e,t,n){let r=n.get(t.getUint32(4,!0));if(!r)return null;let i=t.getUint32(8,!0);if(i!==r.channels.length)throw $(`last values`,`channel count differs from its schema`);if(e.byteLength<12+16*i)throw $(`last values`,`short`);let a=[];for(let e=0;e<i;e++){let n=t.getFloat64(12+8*e,!0),o=t.getFloat64(12+8*(i+e),!0);Number.isFinite(n)&&Number.isFinite(o)&&a.push({name:r.channels[e].name,unit:r.channels[e].unit,t:n,v:o})}return a}async function Kb(e,t){if(e.byteLength<12)throw $(`last values`,`short`);let n=new DataView(e.buffer,e.byteOffset,e.byteLength),r=n.getUint8(0);if(r===1)return Gb(e,n,t);if(r!==2)throw $(`last values`,`version ${r}`);if(e.byteLength<20)throw $(`last values`,`short`);let i=n.getUint8(1),a=t.get(n.getUint32(4,!0));if(!a)return null;let o=n.getUint32(8,!0),s=n.getFloat64(12,!0),c=a.channels.length,l=(i&2)!=0;if(o>c||l&&o!==c)throw $(`last values`,`entry count differs from its schema`);let u=(l?0:4*o)+4*o,d=i&1?await Jb(e.subarray(20),u+8*o,!1):e.subarray(20);if(d.byteLength<u)throw $(`last values`,`short`);let f=new DataView(d.buffer,d.byteOffset,d.byteLength),p=[];for(let e=0;e<o;e++){let t=l?e:f.getUint32(4*e,!0);if(t>=c)throw $(`last values`,`channel outside its schema`);p.push(t)}let m=l?0:4*o,h=p.filter(e=>a.channels[e].size===4),g=p.filter(e=>a.channels[e].size===8);if(d.byteLength!==u+4*h.length+8*g.length)throw $(`last values`,`body size mismatch`);let _=qb(d,u,h.length,4),v=qb(d,u+4*h.length,g.length,8),y=new Map;h.forEach((e,t)=>y.set(e,_[t])),g.forEach((e,t)=>y.set(e,v[t]));let b=[];return p.forEach((e,t)=>{let n=s-f.getUint32(m+4*t,!0)/1e3,r=y.get(e);Number.isFinite(n)&&Number.isFinite(r)&&b.push({name:a.channels[e].name,unit:a.channels[e].unit,t:n,v:r})}),b}function qb(e,t,n,r){let i=new Uint8Array(n*r);for(let a=0;a<r;a++)for(let o=0;o<n;o++)i[o*r+a]=e[t+a*n+o];return r===4?new Float32Array(i.buffer):new Float64Array(i.buffer)}async function Jb(e,t,n=!0){let r=new Blob([e]).stream().pipeThrough(new DecompressionStream(`deflate`)).getReader(),i=new Uint8Array(Math.min(t,e.byteLength*4+1024)),a=0;try{for(;;){let{done:e,value:n}=await r.read();if(e)break;if(a+n.length>t)throw $(`block`,`body larger than its header says`);if(a+n.length>i.length){let e=new Uint8Array(Math.min(t,Math.max(2*i.length,a+n.length)));e.set(i.subarray(0,a)),i=e}i.set(n,a),a+=n.length}}catch(e){throw await r.cancel().catch(()=>{}),e instanceof RangeError?e:$(`block`,`body is not valid deflate`)}if(n&&a!==t)throw $(`block`,`body size mismatch`);return i.length===a?i:i.subarray(0,a)}async function Yb(e,t){if(e.byteLength<20)throw $(`block`,`short`);let n=new DataView(e.buffer,e.byteOffset,e.byteLength);if(n.getUint8(0)!==2)throw $(`block`,`version ${n.getUint8(0)}`);let r=n.getUint8(1),i=n.getUint16(2,!0),a=n.getUint32(4,!0),o=n.getUint32(8,!0),s=t.get(o);if(!s)return null;if(s.channels.length!==i)throw $(`block`,`channel count differs from its schema`);let c=n.getFloat64(12,!0),l=Math.max(0,a-1),u=4*l+s.channels.reduce((e,t)=>e+t.size*a,0);if(u>Hb)throw $(`block`,`too large`);let d;if(r&1)d=await Jb(e.subarray(20),u);else if(d=e.subarray(20),d.byteLength<u)throw $(`block`,`body size mismatch`);let f=new DataView(d.buffer,d.byteOffset,d.byteLength),p=new Float64Array(a),m=0;a&&(p[0]=c);for(let e=1;e<a;e++)m+=f.getInt32(4*(e-1),!0),p[e]=c+m/1e6;let h=4*l,g={},_={};for(let e of s.channels)g[e.name]=qb(d,h,a,e.size),e.unit&&(_[e.name]=e.unit),h+=a*e.size;return{block:{t:p,columns:g,units:_},historical:(r&2)!=0,schemaId:o}}async function Xb(e,t){if(e.byteLength<20)throw $(`sparse`,`short`);let n=new DataView(e.buffer,e.byteOffset,e.byteLength);if(n.getUint8(0)!==1)throw $(`sparse`,`version ${n.getUint8(0)}`);let r=n.getUint8(1),i=n.getUint32(4,!0),a=t.get(i);if(!a)return null;let o=n.getUint32(8,!0),s=n.getFloat64(12,!0),c=4*o+4*Math.max(0,o-1);if(c+8*o>Hb)throw $(`sparse`,`too large`);let l=r&1?await Jb(e.subarray(20),c+8*o,!1):e.subarray(20);if(l.byteLength<c)throw $(`sparse`,`body size mismatch`);let u=new Uint32Array(o);for(let e=0;e<o;e++)u[e]=(l[e]|l[o+e]<<8|l[2*o+e]<<16|l[3*o+e]<<24)>>>0;let d=a.channels.length,f=0;for(let e=0;e<o;e++){if(u[e]>=d)throw $(`sparse`,`event outside its schema`);a.channels[u[e]].size===4&&f++}if(l.byteLength!==c+4*f+8*(o-f))throw $(`sparse`,`body size mismatch`);let p=new DataView(l.buffer,l.byteOffset,l.byteLength),m=new Float64Array(o),h=0;o&&(m[0]=s);for(let e=1;e<o;e++)h+=p.getInt32(4*o+4*(e-1),!0),m[e]=s+h/1e6;let g=qb(l,c,f,4),_=qb(l,c+4*f,o-f,8),v=new Float64Array(o);for(let e=0,t=0,n=0;e<o;e++)v[e]=a.channels[u[e]].size===4?g[t++]:_[n++];return{schemaId:i,index:u,t:m,v,historical:(r&2)!=0}}const Zb=[75,82,67,49];function Qb(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 $b(e){if(e.length<56||Zb.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:Qb(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 ex(e){let t=$b(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}}function tx(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+12+16)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 Ab(e,n.subarray(r,r+12),n.subarray(r+12),n.subarray(0,r));return t.set(i,e),{kind:n[0]&-129,plaintext:a}}catch{}return null}}const nx=8192;async function*rx(e){let t=0;for(;t+56<=e.size;){let n=$b(await e.read(t,56));if(yield await e.slice(t,n.bytes),n.bytes<=56)return;t+=n.bytes}}function ix(e){let t=e.filter(e=>e&&typeof e.t==`number`&&Array.isArray(e.signals)),n={},r={};return t.forEach((e,i)=>{for(let a of e.signals){if(!a||typeof a.name!=`string`)continue;let e=n[a.name]??=new Float64Array(t.length).fill(NaN);e[i]=typeof a.value==`number`?a.value:NaN,a.unit&&!r[a.name]&&(r[a.name]=a.unit)}}),{t:t.map(e=>e.t),columns:n,units:r}}function ax(e){let t=2166136261^e.length;for(let n=0,r=Math.min(e.length,64);n<r;n++)t=Math.imul(t^e[n],16777619);return t>>>0}const ox=(e,t)=>e.length===t.length&&e.every((e,n)=>e===t[n]);var sx=class{known=new Map;real=new Set;pending=new Set;held=new Set;note(e){for(let t of e){let e=this.known.get(t.name);(!e||t.t>=e.t)&&this.known.set(t.name,{t:t.t,v:t.v,unit:t.unit}),!this.real.has(t.name)&&!this.held.has(t.name)&&this.pending.add(t.name)}}sampled(e){if(this.pending.size+this.held.size===0)return;let t=e=>{(this.pending.delete(e)||this.held.delete(e))&&this.real.add(e)};for(let[n,r]of Object.entries(e.columns))if(!(!this.pending.has(n)&&!this.held.has(n))){for(let e=0;e<r.length;e++)if(Number.isFinite(r[e])){t(n);break}}if(e.events&&e.schema){let{index:n,v:r}=e.events;for(let i=0;i<r.length;i++)Number.isFinite(r[i])&&t(e.schema.channels[n[i]].name)}}start(e){if(this.pending.size===0||e.t.length===0)return e;let t={...e.columns},n={...e.units};for(let e of this.pending){let r=this.known.get(e);t[e]=Float64Array.of(r.v),r.unit&&!n[e]&&(n[e]=r.unit),this.held.add(e)}let r=[...this.pending];return this.pending.clear(),{...e,columns:t,units:n,more:r}}end(e,t){if(e===null||this.held.size===0)return null;let n={},r={};for(let e of this.held){let t=this.known.get(e);n[e]=Float64Array.of(t.v),t.unit&&(r[e]=t.unit)}return{at:t,t:[e],columns:n,units:r}}};async function*cx(e,t,n,r,i=!1){let a=tx(e.keys??[]),o=new Map,s=new Map,c=r?null:new sx,l=null,u=0,d=e=>c?(c.sampled(e),e.t.length&&(l=+e.t[e.t.length-1],u=e.at),c.start(e)):e,f={results:[]};for await(let e of rx(t)){let{header:t,messages:l}=ex(e);if(n.t0??=t.t0,i){let e=t.recordingId;f.results.push({rid:e,check:await Bb(t,l,a,f.rid===e?(f.seq??-1)+1:0)}),f.rid=e,f.seq=t.seq,n.chain=Vb(f.results)}for(let e of l){let t=ax(e.bytes),i=s.get(t);if(i&&ox(i,e.bytes))continue;s.set(t,e.bytes),s.size>4096&&s.delete(s.keys().next().value);let l=await a(e.bytes);if(!l){n.lost++;continue}try{if(l.kind===5){let e=await Wb(l.plaintext);o.set(e.id,e);continue}if(l.kind===4||l.kind===9){let t;if(l.kind===4){let r=await Yb(l.plaintext,o);if(!r){n.lost++;continue}t={at:e.at,t:r.block.t,columns:r.block.columns,units:r.block.units??{},historical:r.historical,schema:o.get(r.schemaId)}}else{let r=await Xb(l.plaintext,o);if(!r){n.lost++;continue}t={at:e.at,t:r.t,columns:{},units:{},historical:r.historical,events:{index:r.index,v:r.v},schema:o.get(r.schemaId)}}t.historical&&c?.sampled(t),(r===void 0||r===!!t.historical)&&(yield t.historical?t:d(t));continue}if(r)continue;if(l.kind===7){let e=await Kb(l.plaintext,o);e&&c?.note(e)}else if(l.kind===3){let t=Eb(l.plaintext);yield d({at:e.at,t:t.t,columns:t.columns,units:t.units??{}})}else if(l.kind===2){let t=wb(l.plaintext);yield d({at:e.at,...ix(Array.isArray(t?.frames)?t.frames:[])})}}catch{n.lost++}}}let p=c?.end(l,u);p&&(yield p)}function lx(e,t,n){let r=e===null?t:t===null?e:Math.min(e,t);return r===null?{}:r>1e9?{wallOrigin:String(r),wallQuality:`exact`}:Number.isFinite(n)?{wallOrigin:String(r+n),wallQuality:`approx`}:{}}const ux={id:`krc`,label:`Kymoscope recording`,extensions:[],sniff:()=>!1,async plan(e,t){let n=[Ob],r=new Map([[Ob,`s`]]),i={lost:0,t0:null},a=0,o=!1,s=null,c=null,l=0,u=-1/0,d=0,f=1/0,p=(e,t=``)=>{e!==`ElapsedTime`&&(r.has(e)?!r.get(e)&&t&&r.set(e,t):(n.push(e),r.set(e,t)))},m=new Set;for await(let n of cx(e,t,i,void 0,!0)){a+=n.t.length,n.historical&&(o=!0);let e=n.t.length;if(e&&n.historical?c??=+n.t[0]:e&&(s??=+n.t[0],+n.t[0]+l<u&&(l=u+Math.max(0,(n.at-d)/1e3)-+n.t[0]),d=n.at,u=+n.t[e-1]+l,f=Math.min(f,n.at/1e3-u)),n.schema){if(!m.has(n.schema.id)){m.add(n.schema.id);for(let e of n.schema.channels)p(e.name,e.unit)}for(let e of n.more??[])p(e,n.units[e])}else for(let e of Object.keys(n.columns))p(e,n.units[e])}let h=n.map(e=>({name:e,unit:r.get(e)??``})),g=i.lost?[`${i.lost} ${i.lost===1?`message`:`messages`} couldn't be opened with the keys this browser has.`]:[],_=i.chain?.broken??0,v=n.length-1,y=v>1e3?[{group:0,channels:n.slice(0,yy+1).map((e,t)=>t)}]:void 0;return y&&g.push(`This recording has ${v.toLocaleString(`en-US`)} channels; the first ${yy.toLocaleString(`en-US`)} are loaded.`),_&&g.push(`Some of this recording was missing, out of order or changed where it is stored (${_} of ${_+(i.chain?.verified??0)} checked ${_+(i.chain?.verified??0)===1?`chunk`:`chunks`}).`),{format:`Kymoscope recording`,startTime:i.t0===null?null:new Date(i.t0).toISOString(),groups:[{name:`Recording`,channels:h,samples:a,time:{kind:`timestamps`},rateHz:null}],meta:{...lx(s,c,f),...i.chain&&(i.chain.verified||i.chain.broken)?{chainVerified:String(i.chain.verified),chainBroken:String(i.chain.broken),chainUnchecked:String(i.chain.unchecked)}:{}},events:[],notes:g,defaultSelection:y,state:{names:n,backlog:o}}},async*stream(e){let{names:t,backlog:n=!1}=e.plan.state,r=e.selection.find(e=>e.group===0)?.channels??[],i=new Map(r.map((e,n)=>[t[e],n])),a=i.get(Ob),o=()=>r.map(()=>new Float64Array(nx).fill(NaN)),s=new Float64Array(nx),c=o(),l=0,u=0,d=0,f=null,p=()=>{let e={group:0,time:s.slice(0,l),start:u,length:l,columns:c.map(e=>e.slice(0,l))};return u+=l,l=0,s=new Float64Array(nx),c=o(),e},m=new WeakMap,h=e=>{let t=m.get(e);return t||m.set(e,t=Int32Array.from(e.channels,e=>e.name===`ElapsedTime`?-2:i.get(e.name)??-1)),t};function*g(e,t,n,r){let o=Object.entries(e.columns).flatMap(([e,t])=>{let n=e===`ElapsedTime`?void 0:i.get(e);return n===void 0?[]:[[n,+t[0]]]});for(let i=0;i<e.t.length;i++){let u=r[t[i]];if(u===-1&&!(i===0&&o.length))continue;let m=+e.t[i];if(s[l]=m+d-f,a!==void 0&&(c[a][l]=m),u>=0&&(c[u][l]=n[i]),i===0)for(let[e,t]of o)c[e][l]=t;++l===nx&&(yield p())}}function*_(e){let t=e.t.length;if(t&&(f??=+e.t[0]+d),e.events&&e.schema)return yield*g(e,e.events.index,e.events.v,h(e.schema));for(let n=0;n<t;){let r=Math.min(t-n,nx-l);for(let t=0;t<r;t++)s[l+t]=+e.t[n+t]+d-f;if(a!==void 0)for(let t=0;t<r;t++)c[a][l+t]=+e.t[n+t];for(let[t,a]of Object.entries(e.columns)){let e=t===`ElapsedTime`?void 0:i.get(t);if(e===void 0)continue;let o=c[e];if(a instanceof Float64Array||a instanceof Float32Array)o.set(a.subarray(n,n+r),l);else for(let e=0;e<r;e++)o[l+e]=+a[n+e]}l+=r,n+=r,l===nx&&(yield p())}}for await(let t of dx(e.files,e.io,n,e.signal))d=t.shift,yield*_(t.b);l>0&&(yield p())}};async function*dx(e,t,n,r){let i=0,a=-1/0,o=0,s=n?cx(e,t,{lost:0,t0:null},!0):null,c=async()=>{for(let e=await s?.next();e&&!e.done;e=await s.next())if(e.value.t.length)return e.value;return null},l=await c();for await(let s of cx(e,t,{lost:0,t0:null},n?!1:void 0)){if(r?.aborted)return;let e=s.t.length;if(e!==0){for(+s.t[0]+i<a&&(i=a+Math.max(0,(s.at-o)/1e3)-+s.t[0]),o=s.at;l&&+l.t[0]<+s.t[0];l=await c())yield{b:l,shift:i};yield{b:s,shift:i},a=+s.t[e-1]+i}}for(;l&&!r?.aborted;l=await c())yield{b:l,shift:i}}const fx={mdf:en,edf:sn,xdf:xn,tdms:Ln,hdf5:dr,mat:Fr,comtrade:Wr,mseed:_d,ulog:jd,mcap:Jp,pqdif:Um,ch10:Hi,iena:$l,ccsds:ed,parquet:Ay,xlsx:Hy,longtext:qy,krc:ux};function px(e){let t=fx[e];if(!t)throw Error(`No importer for format ${e}.`);return t}const mx=`This file's groups do not interleave in time: reading them together would hold too much in memory. Choose fewer groups, or split them.`,hx=e=>e.length*(1+e.columns.length);function gx(e){let t=e[Symbol.asyncIterator]();return{pull:async()=>{let e=await t.next();return e.done?null:e.value}}}function _x(e,t){let n=Array.from({length:t.size},()=>[]),r=!1,i=0,a=async a=>{for(;;){if(n[a].length){let e=n[a].shift();return i-=hx(e),e}if(r)return null;let o=await e.next();if(o.done){r=!0;continue}let s=t.get(o.value.group);if(s!==void 0&&(n[s].push(o.value),(i+=hx(o.value))>128e6))throw Error(mx)}};return n.map((e,t)=>({pull:()=>a(t)}))}function vx(e,t){if(e.time)return e.time;let n=new Float64Array(e.length);if(t.time.kind===`rate`){let{rate:r,start:i}=t.time;for(let t=0;t<e.length;t++)n[t]=i+(e.start+t)/r}else for(let t=0;t<e.length;t++)n[t]=e.start+t;return n}const yx=new Int32Array,bx={t:new Float64Array,cols:[],from:0};function xx(e,t,n,r){let i=n,a=r;for(;i<a;){let n=i+a>>>1;e[n]<=t?i=n+1:a=n}return i}var Sx=class{group;channels;feed;pending=[];done=!1;last;scratch=[];#e=-1/0;constructor(e,t,n){this.group=e,this.channels=t,this.feed=n,this.last=t.map(e=>e.text?null:NaN)}rows(){let e=0;for(let t of this.pending)e+=t.t.length-t.from;return e}lastTime(){let e=this.pending[this.pending.length-1];return e&&e.t.length>e.from?e.t[e.t.length-1]:-1/0}async fill(){let e=await this.feed.pull();if(!e){this.done=!0;return}if(e.length===0)return;let t=Cx(vx(e,this.group),this.#e);if(t.length&&(this.#e=t[t.length-1]),this.pending.push({t,cols:e.columns,from:0}),this.rows()*(1+this.channels.length)>128e6)throw Error(mx)}};function Cx(e,t){let n=t,r=0;for(;r<e.length;r++){let t=e[r];if(!(t>=n&&t>-1/0&&t<1/0))break;n=t}if(r===e.length)return e;for(n===-1/0&&(n=0);r<e.length;r++){let t=e[r];t>=n&&t<1/0?n=t:e[r]=n}return e}function wx(e,t){let n=e.length,r=e.map(e=>e.t),i=Int32Array.from(e,e=>e.from),a=Int32Array.from(e,e=>xx(e.t,t,e.from,e.t.length));if(n===1)return r[0].subarray(i[0],a[0]);let o=0;for(let e=0;e<n;e++)o+=a[e]-i[e];let s=new Float64Array(o),c=0;for(;;){let e=1/0;for(let t=0;t<n;t++)i[t]<a[t]&&r[t][i[t]]<e&&(e=r[t][i[t]]);if(e===1/0)break;s[c++]=e;for(let t=0;t<n;t++){let n=r[t],o=a[t],s=i[t];for(;s<o&&n[s]===e;)s++;i[t]=s}}return s.subarray(0,c)}function Tx(e,t,n,r,i,a){if(i-r>8)e.set(t.subarray(n+r,n+i),a);else for(let o=r;o<i;o++)e[a+o-r]=t[n+o]}function Ex(e,t,n,r,i,a){let o=0;for(let s=0;s<n.length;s++){let c=n[s],l=c.length;if(l===0)continue;let u=i[s].from,d=i[s].cols[a];e.fill(t,o,c[0]);let f=r[s],p=0;for(let t=0;t<f.length;t++){let n=f[t];Tx(e,d,u,p,n,c[p]);let r=c[n],i=c[n+1],a=d[u+n];if(i-r>16)e.fill(a,r,i);else for(let t=r;t<i;t++)e[t]=a;p=n+1}Tx(e,d,u,p,l-1,c[p]),o=c[l-1],t=d[u+l-1]}e.fill(t,o,e.length)}function Dx(e,t,n,r,i){let a=0;for(let o=0;o<n.length;o++){let s=n[o],c=s.length;if(c===0)continue;let l=r[o].from,u=r[o].cols[i];e.fill(t,a,s[0]);for(let t=0;t<c-1;t++)e.fill(u[l+t],s[t],s[t+1]);a=s[c-1],t=u[l+c-1]}e.fill(t,a,e.length)}function Ox(e,t,n,r,i){let a=n.length,o=null,s=0;for(let c=0;c<i.length;c++){let l=e[t+c],u=r;if(n[r]<l){let e=r,t=1;for(;e+t<a&&n[e+t]<l;)e+=t,t*=2;let i=Math.min(e+t,a-1);for(;i-e>1;){let t=e+i>>>1;n[t]<l?e=t:i=t}r=i}i[c]=r,c>0&&r!==u+1&&((o??=new Int32Array(i.length-1))[s++]=c-1)}return o?o.subarray(0,s):yx}function kx(e,t,n,r,i){let a=t.length;if(r){let t=e.pending[0],n=t.from+a,r=t.cols.map(e=>e instanceof Float64Array?e.subarray(t.from,n):e.slice(t.from,n));if(a>0)for(let i=0;i<r.length;i++)e.last[i]=t.cols[i][n-1];return e.pending=n<t.t.length?[{...t,from:n}]:[],r}let o=e.pending,s=[],c=[];if(a>0){let e=t[a-1],n=0;for(let r of o){let i=r.t,a=xx(i,e,r.from,i.length),o=new Int32Array(a-r.from);if(c.push(Ox(i,r.from,t,n,o)),o.length&&(n=o[o.length-1]),s.push(o),a<i.length)break}}let l=e.channels.map((r,l)=>{if(r.sparse&&n){let e=r.text?Array(a).fill(null):new Float64Array(a).fill(NaN);for(let n=0;n<s.length;n++){let r=s[n],{t:i,from:c}=o[n],u=o[n].cols[l];for(let n=0;n<r.length;n++){let o=r[n];o<a&&t[o]===i[c+n]&&(e[o]=u[c+n])}}return e}if(r.text){let t=Array(a);return Dx(t,e.last[l],s,o,l),t}let u;return i?(e.scratch[l]?.length>=a||(e.scratch[l]=new Float64Array(a)),u=e.scratch[l].subarray(0,a)):u=new Float64Array(a),Ex(u,e.last[l],s,c,o,l),u}),u=[];for(let t=0;t<o.length;t++){let n=o[t],r=t<s.length?s[t].length:0;if(r>0)for(let t=0;t<e.channels.length;t++)e.last[t]=n.cols[t][n.from+r-1];n.from+r<n.t.length&&u.push(r?{...n,from:n.from+r}:n)}return e.pending=u,l}async function Ax(e,t,n,r,i,a=!1){let o=e.map((e,r)=>new Sx(e,t[r],n[r])),s=-1;e.forEach((t,n)=>{!t.irregular&&(s<0||t.samples>e[s].samples)&&(s=n)});let c=e.map((e,t)=>t===s||!!e.irregular),l=o.filter((e,t)=>c[t]),u=l.length===1,d=0;for(;;){i?.throwIfAborted();for(let e of l)for(;!e.done&&e.rows()===0;)await e.fill();if(l.every(e=>e.rows()===0)){let e=o.filter((e,t)=>!c[t]&&(!e.done||e.rows()>0));if(!e.length)break;for(let t of e)c[o.indexOf(t)]=!0,l.push(t);u=!1;continue}let e=1/0;for(let t of l)t.done||(e=Math.min(e,t.lastTime()));for(let t=0;t<o.length;t++)if(!c[t])for(;!o[t].done&&o[t].lastTime()<=e;)await o[t].fill();let t=wx(l.map(e=>e.pending[0]??bx),e),n=[t];for(let e=0;e<o.length;e++)n.push(...kx(o[e],t,c[e],u&&c[e],a));d+=t.length,t.length&&await r({length:t.length,columns:n})}return d}var jx=class{#e;#t;#n;#r=0;constructor(e,t){let n=Math.max(1024,t);this.#e=e.map(e=>e.name),this.#t=e.map(()=>new Float64Array(n)),this.#n=e.map(()=>null)}append(e){let t=this.#r,n=t+e.length;if(n>this.#t[0].length){let e=Math.max(n,Math.ceil(this.#t[0].length*1.5));this.#t=this.#t.map(n=>{let r=new Float64Array(e);return r.set(n.subarray(0,t)),r})}e.columns.forEach((n,r)=>{let i=this.#t[r];if(n instanceof Float64Array){i.set(n.subarray(0,e.length),t);return}let a=this.#n[r];for(let o=0;o<e.length;o++){i[t+o]=NaN;let e=n[o];e!=null&&((a??=this.#n[r]=[])[t+o]=e)}}),this.#r=n}table(){let e=this.#r,t=this.#t.map(t=>t.length-e>t.length/100?t.slice(0,e):t.subarray(0,e));return{keys:this.#e,length:e,values:t,text:this.#n}}};async function Mx(e,t,n){return O(await e.plan(t,n))}const Nx=(e,t,n)=>Math.max(0,Math.min(e,Math.max(1<<20,n),Math.floor(1e8/t)));function Px(e,t){let n=t.flatMap(t=>t.channels.map(n=>({ch:e.groups[t.group].channels[n],group:e.groups[t.group].name}))),r=new Map;for(let{ch:e}of n)r.set(e.name.toLowerCase(),(r.get(e.name.toLowerCase())??0)+1);let i=cn(n.map(({ch:e,group:n})=>t.length>1&&r.get(e.name.toLowerCase())>1?`${e.name} [${n}]`:e.name));return[{name:`Time`,unit:t.every(t=>e.groups[t.group].time.kind===`index`)?``:`s`,text:!1},...n.map(({ch:e},t)=>({name:i[t],unit:e.unit,text:!!e.text}))]}function Fx(e,t){let n=t.map(t=>e.groups[t.group]);if(n.some(e=>e.samples<0))return-1;let r=0,i=0;for(let e of n)e.irregular?i+=e.samples:r=Math.max(r,e.samples);return r+i}async function Ix(e,t,n,r,i,a,o={}){let s=Px(n,i),c=i.map(e=>n.groups[e.group]),l=i.map(e=>e.channels.map(t=>n.groups[e.group].channels[t])),u=[...n.events];async function*d(e){for await(let t of e)t.events&&u.push(...t.events),yield t}let f={files:t,plan:n,io:r,selection:i,signal:o.signal},p=e.streamGroup&&i.length>1&&!n.interleaved?i.map(t=>gx(d(e.streamGroup({...f,selection:[t]},t.group)))):_x(d(e.stream(f)),new Map(i.map((e,t)=>[e.group,t]))),m=Fx(n,i),h=a===`memory`?new jx(s,Nx(m,s.length,r.size)):null,g=0,_=await Ax(c,l,p,async e=>{h?h.append(e):await o.chunk(e);let t=Date.now();o.progress&&t-g>100&&(g=t,o.progress(Math.min(.99,r.bytesRead/Math.max(1,r.size))))},o.signal,!!h);return o.progress?.(1),u.sort((e,t)=>e.time-t.time),{columns:s,rows:_,table:h?.table(),events:u}}function Lx(e){let t=new Set,n=e.columns.map(e=>{if(!(e instanceof Float64Array))return e;let n=e.byteOffset===0&&e.byteLength===e.buffer.byteLength&&!t.has(e.buffer)?e:e.slice();return t.add(n.buffer),n});return[{length:e.length,columns:n},[...t]]}function Rx(e,t=px){let n=null,i=null,a=null,o=null,s=2,c=null;return async l=>{if(l.type===`ack`){s++;let e=c;c=null,e?.();return}if(l.type===`warm`){Xn();return}let u=setInterval(()=>e({type:`alive`,work:a?.bytesRead??0}),1e3);try{if(l.type===`plan`){n=t(l.importer),i=l.files,a=new r(i.main),o=await Mx(n,i,a),e({type:`plan`,plan:{...o,state:void 0}});return}a.bytesRead=0;let u=await Ix(n,i,o,a,l.selection,l.mode,{progress:t=>e({type:`progress`,fraction:t}),chunk:async t=>{for(;s===0;)await new Promise(e=>{c=e});s--;let[n,r]=Lx(t);e({type:`chunk`,chunk:n},r)}});e({type:`done`,result:u},u.table?Db(u.table):[])}catch(t){e({type:`error`,message:k(t).message})}finally{clearInterval(u)}}}const zx=self;let Bx=null;Jn(async()=>{if(!Bx)throw Error(`The import worker was not told where the HDF5 reader is.`);await import(Bx);let e=globalThis.__kymoscopeH5wasm;if(!e)throw Error(`HDF5 reader failed to load.`);let{FS:t}=await e.ready,n=0;return async r=>{let i=`/kymo${++n}`;t.mkdir(i),t.mount(t.filesystems.WORKERFS,{files:[r]},i);try{let n=new e.File(`${i}/${r.name}`,`r`);return{root:n,close:()=>{n.close(),t.unmount(i),t.rmdir(i)}}}catch(e){throw t.unmount(i),t.rmdir(i),e}}});const Vx=Rx((e,t)=>zx.postMessage(e,t??[]));zx.onmessage=e=>{e.data.type===`init`?Bx=e.data.h5Url:Vx(e.data)};
1040
+ `),new Q(``,0,`:`),new Q(` `,0,`. `),new Q(``,0,`ed `),new Q(``,20,``),new Q(``,18,``),new Q(``,6,``),new Q(``,0,`(`),new Q(``,10,`, `),new Q(``,8,``),new Q(``,0,` at `),new Q(``,0,`ly `),new Q(` the `,0,` of `),new Q(``,5,``),new Q(``,9,``),new Q(` `,10,`, `),new Q(``,10,`"`),new Q(`.`,0,`(`),new Q(``,11,` `),new Q(``,10,`">`),new Q(``,0,`="`),new Q(` `,0,`.`),new Q(`.com/`,0,``),new Q(` the `,0,` of the `),new Q(``,10,`'`),new Q(``,0,`. This `),new Q(``,0,`,`),new Q(`.`,0,` `),new Q(``,10,`(`),new Q(``,10,`.`),new Q(``,0,` not `),new Q(` `,0,`="`),new Q(``,0,`er `),new Q(` `,11,` `),new Q(``,0,`al `),new Q(` `,11,``),new Q(``,0,`='`),new Q(``,11,`"`),new Q(``,10,`. `),new Q(` `,0,`(`),new Q(``,0,`ful `),new Q(` `,10,`. `),new Q(``,0,`ive `),new Q(``,0,`less `),new Q(``,11,`'`),new Q(``,0,`est `),new Q(` `,10,`.`),new Q(``,11,`">`),new Q(` `,0,`='`),new Q(``,10,`,`),new Q(``,0,`ize `),new Q(``,11,`.`),new Q(`Â\xA0`,0,``),new Q(` `,0,`,`),new Q(``,10,`="`),new Q(``,11,`="`),new Q(``,0,`ous `),new Q(``,11,`, `),new Q(``,10,`='`),new Q(` `,10,`,`),new Q(` `,11,`="`),new Q(` `,11,`, `),new Q(``,11,`,`),new Q(``,11,`(`),new Q(``,11,`. `),new Q(` `,11,`.`),new Q(``,11,`='`),new Q(` `,11,`. `),new Q(` `,10,`="`),new Q(` `,11,`='`),new Q(` `,10,`='`)],Cy=Sy.length;function wy(e,t){return e[t]<192?(e[t]>=97&&e[t]<=122&&(e[t]^=32),1):e[t]<224?(e[t+1]^=32,2):(e[t+2]^=5,3)}function Ty(e,t,n,r,i){let a=xy(),{prefix:o}=Sy[i],{suffix:s}=Sy[i],c=Sy[i].transform,l=c<12?0:c-11,u=t;l>r&&(l=r);let d=0;for(;d<o.length;)e[t++]=o[d++];n+=l,r-=l,c<=9&&(r-=c);for(let i=0;i<r;i++)e[t++]=a[n+i];let f=t-r;if(c===10)wy(e,f);else if(c===11)for(;r>0;){let t=wy(e,f);f+=t,r-=t}let p=0;for(;p<s.length;)e[t++]=s[p++];return t-u}const Ey=new Uint8Array([3,2,1,0,3,3,3,3,3,3,2,2,2,2,2,2]),Dy=new Int8Array([0,0,0,0,-1,1,-2,2,-3,3,-1,1,-2,2,-3,3]),Oy=new Uint32Array([0,0,0,0,0,4096,9216,21504,35840,44032,53248,63488,74752,87040,93696,100864,104704,106752,108928,113536,115968,118528,119872,121280,122016]),ky=new Uint8Array([0,0,0,0,10,10,11,11,10,10,10,10,10,9,9,8,7,7,8,7,7,6,6,5,5]);function Ay(e,t){let n=new Uint8Array(t);return jy(new fy(e),new py(n)),n}function jy(e,t){let n=0,r=0,i=0,a=[16,15,11,4],o=0,s=[new Pv(0,0),new Pv(0,0),new Pv(0,0)],c=128+wv.READ_SIZE,l=new wv(e),u=iy(l),d=(1<<u)-16,f=1<<u,p=f-1,m=new Uint8Array(f+c+24),h=f,g=[],_=[];for(let e=0;e<3*Vv;e++)g[e]=new Z(0,0),_[e]=new Z(0,0);for(;!r;){let e=[1<<28,1<<28,1<<28],c=[0],u=[1,1,1],v=[0,1,0,1,0,1],y=[0];for(let e=0;e<3;e++)s[e].codes=[],s[e].htrees=new Uint32Array;l.readMoreInput();let b=ty(l),x=b.meta_block_length;if(n+x>t.buffer.length){let e=new Uint8Array(n+x);e.set(t.buffer),t.buffer=e}if(r=b.input_end,b.is_metadata){for(ay(l);x>0;--x)l.readMoreInput(),l.readBits(8);continue}if(x===0)continue;if(b.is_uncompressed){l.bit_pos_=l.bit_pos_+7&-8,ny(t,x,n,m,p,l),n+=x;continue}for(let t=0;t<3;t++)u[t]=ry(l)+1,u[t]>=2&&(jv(u[t]+2,g,t*Vv,l),jv(26,_,t*Vv,l),e[t]=oy(_,t*Vv,l),y[t]=1);l.readMoreInput();let S=l.readBits(2),C=16+(l.readBits(4)<<S),w=(1<<S)-1,T=C+(48<<S),E=new Uint8Array(u[0]);for(let e=0;e<u[0];e++)l.readMoreInput(),E[e]=l.readBits(2)<<1;let[D,O]=ly(u[0]<<6,l),[k,A]=ly(u[2]<<2,l);s[0]=new Pv(256,D),s[1]=new Pv(704,u[1]),s[2]=new Pv(T,k);for(let e=0;e<3;++e)s[e].decode(l);let j=0,M=0,N=E[c[0]],P=cy[N],ee=cy[N+1],te=s[1].htrees[0];for(;x>0;){let r;l.readMoreInput(),e[1]===0&&(ey(u[1],g,1,c,v,y,l),e[1]=oy(_,Vv,l),te=s[1].htrees[c[1]]),e[1]--;let b=Mv(s[1].codes,te,l),T=b>>6;T>=2?(T-=2,r=-1):r=0;let D=Lv[zv[T]+(b>>3&7)],k=D.offset+l.readBits(D.nbits),ne=Rv[Bv[T]+(b&7)],re=ne.offset+l.readBits(ne.nbits),ie=m[n-1&p],ae=m[n-2&p];for(let r=0;r<k;r++){l.readMoreInput(),e[0]===0&&(ey(u[0],g,0,c,v,y,l),e[0]=oy(_,0,l),j=c[0]<<6,N=E[c[0]],P=cy[N],ee=cy[N+1]);let r=sy[P+ie]|sy[ee+ae],i=O[j+r];e[0]--,ae=ie,ie=Mv(s[0].codes,s[0].htrees[i],l),m[n&p]=ie,(n&p)===p&&t.write(m,f),n++}if(x-=k,x<=0)break;if(r<0){l.readMoreInput(),e[2]===0&&(ey(u[2],g,2,c,v,y,l),e[2]=oy(_,2*Vv,l),M=c[2]<<2),e[2]--;let t=(re>4?3:re-2)&255,n=A[M+t];if(r=Mv(s[2].codes,s[2].htrees[n],l),r>=C){r-=C;let e=r&w;r>>=S;let t=(r>>1)+1;r=C+((2+(r&1)<<t)-4+l.readBits(t)<<S)+e}}let oe=My(r,a,o);if(oe<0)throw Error(`[BrotliDecompress] invalid distance`);i=n<d&&i!==d?n:d;let se=n&p;if(oe>i)if(re>=4&&re<=24){let e=Oy[re],r=oe-i-1,a=ky[re],o=r&(1<<a)-1,s=r>>a;if(e+=o*re,s<Cy){let r=Ty(m,se,e,re,s);if(se+=r,n+=r,x-=r,se>=h){t.write(m,f);for(let e=0;e<se-h;e++)m[e]=m[h+e]}}else throw Error(`Invalid backward reference`)}else throw Error(`Invalid backward reference`);else{if(r>0&&(a[o&3]=oe,o++),re>x)throw Error(`Invalid backward reference`);for(let e=0;e<re;e++)m[n&p]=m[n-oe&p],(n&p)===p&&t.write(m,f),n++,x--}}n&=1073741823}t.write(m,n&p)}function My(e,t,n){return e<16?(n+=Ey[e],n&=3,t[n]+Dy[e]):e-16+1}function Ny(e,t){let n=new Uint8Array(t);try{let t=0,r=0;for(;t<e.length-8;){let i=e[t++]<<24|e[t++]<<16|e[t++]<<8|e[t++],a=e[t++]<<24|e[t++]<<16|e[t++]<<8|e[t++];if(e.length-t<a||n.length<i||Fy(e.subarray(t,t+a),n,r)!==i)throw Error(`lz4 not hadoop`);if(t+=a,r+=i,t===e.length)return n}if(t<e.length)throw Error(`lz4 not hadoop`)}catch(t){if(t instanceof Error&&t.message!==`lz4 not hadoop`)throw t;Fy(e,n,0)}return n}function Py(e,t){let n=new Uint8Array(t);return Fy(e,n,0),n}function Fy(e,t,n){let r=n;for(let i=0;i<e.length;){let a=e[i++],o=a>>4;if(o){let a=o+240;for(;a===255;)o+=a=e[i++];if(t.set(e.subarray(i,i+o),r),r+=o,i+=o,i>=e.length)return r-n}let s=e[i++]|e[i++]<<8;if(!s||s>r)throw Error(`lz4 offset out of range ${s}`);let c=a&15,l=c+240;for(;l===255;)c+=l=e[i++];c+=4;let u=r-s,d=r+c;for(;r<d;)t[r++]=t[u++]}return r-n}const Iy={SNAPPY:vv(),GZIP:(e,t)=>yy(e,new Uint8Array(t)),BROTLI:Ay,ZSTD:e=>pp(e),LZ4:Ny,LZ4_RAW:Py},Ly=1e3,Ry=e=>e instanceof Float64Array&&(e.byteOffset!==0||e.buffer.byteLength!==e.byteLength)?e.slice():e;function zy(e,t){async function*n(e,t,n){let r=e.groups[t.group],i=e.file.tables[r.table],a=t=>r.absolute&&t!==null?e.origin-(i.columns[t].origin??0):0;if(r.long){yield*rl(i,r.long.shape,r.long.scan,t.channels,t.group,a(r.long.shape.time),n);return}let o=t.channels.map(e=>r.columns[e]),s=0;for await(let e of i.read(r.time===null?o:[r.time,...o],n)){let n=null;if(r.time!==null){let t=e.columns[0],i=a(r.time);n=new Float64Array(e.length);for(let r=0;r<e.length;r++)n[r]=t[r]-i}let c=(r.time===null?e.columns:e.columns.slice(1)).map(Ry);o.forEach((e,t)=>{let n=i.columns[e].origin;if(n){let e=c[t];for(let t=0;t<e.length;t++)e[t]+=n}}),yield{group:t.group,time:n,start:s,length:e.length,columns:c},s+=e.length}}return{...e,async plan(e,n){let r=await t(e,n),i=[],a=[],o=[...r.notes],s=1/0,c=!1;for(let[t,n]of r.tables.entries()){o.push(...n.notes);let r=e.asTable?null:tl(n.columns),l=r?await nl(n,r):null;if(r&&l){let e=!!n.columns[r.time].absolute;e&&(s=Math.min(s,(n.columns[r.time].origin??0)+l.start)),a.push({table:t,long:{shape:r,scan:l},absolute:e}),i.push({name:n.name,channels:l.tags.map((e,t)=>({name:e,unit:l.units[t],sparse:!0})),samples:l.times,time:{kind:`timestamps`},rateHz:null,irregular:!0}),o.push(`${n.name}: one row per sample; ${l.tags.length.toLocaleString(`en-US`)} ${l.tags.length===1?`tag`:`tags`} opened as channels.`),l.sorted||o.push(`${n.name}: the rows were not in time order and were sorted.`),l.repeated&&o.push(`${n.name}: ${l.repeated.toLocaleString(`en-US`)} repeated ${l.repeated===1?`sample`:`samples`} (same time and tag) ${l.repeated===1?`was`:`were`} dropped; the first was kept.`),c=!0;continue}let u=n.columns.findIndex(e=>e.kind===`time`),d=n.columns.flatMap((e,t)=>t===u?[]:[t]);if(d.length===0){o.push(`${n.name}: no channels besides its time; skipped.`);continue}let f=u>=0&&!!n.columns[u].absolute;if(f){let e=await ll(n,u);Number.isNaN(e)||(s=Math.min(s,(n.columns[u].origin??0)+e))}a.push({table:t,long:null,time:u>=0?u:null,columns:d,absolute:f}),i.push({name:n.name,channels:d.map(e=>({name:n.columns[e].name,unit:n.columns[e].unit,text:n.columns[e].kind===`text`})),samples:n.rows,time:u>=0?{kind:`timestamps`}:{kind:`index`},rateHz:null})}if(i.length===0)throw Error(`${e.main.name}: no numbers to chart in this file.`);let l=i.filter((e,t)=>!a[t].long&&e.time.kind===`timestamps`);if(l.length>1)for(let e of l)e.irregular=!0;Number.isFinite(s)||(s=0);let u=a.some(e=>e.absolute)&&s?new Date(s*1e3).toISOString():null,d,f=i.filter((e,t)=>a[t].long&&e.channels.length>1e3);if(f.length){d=i.map((e,t)=>({group:t,channels:(a[t].long?e.channels.slice(0,Ly):e.channels).map((e,t)=>t)}));for(let e of f)o.push(`${e.name}: ${e.channels.length.toLocaleString(`en-US`)} tags; the first ${Ly.toLocaleString(`en-US`)} are loaded.`)}return{format:r.format,startTime:u,groups:i,meta:c?{layout:`long`}:{},events:[],notes:o,defaultSelection:d,state:{file:r,groups:a,origin:s}}},stream:e=>(async function*(){for(let t of e.selection)yield*n(e.plan.state,t,e.signal)})(),streamGroup:(e,t)=>n(e.plan.state,e.selection.find(e=>e.group===t),e.signal)}}const By={id:`parquet`,label:`Parquet`,extensions:[`.parquet`,`.pq`],sniff:e=>e[0]===80&&e[1]===65&&e[2]===82&&e[3]===49},Vy={timestampFromMilliseconds:e=>e*1000000n,timestampFromMicroseconds:e=>e*1000n,timestampFromNanoseconds:e=>e,dateFromDays:e=>e*86400};function Hy(e,t){if(e.first===void 0){e.first=t;let n=Number(t)/1e9;e.column.origin=e.wall?sl(n):n}let n=Number(t-e.first)/1e9;if(!e.wall)return n;let r=Number(e.first)/1e9;return n+(cl(r+n)-cl(r))}function Uy(e,t){let n=e.element,r=n.logical_type?.type,i=n.converted_type,a=e.path.join(`.`);if(r===`LIST`||r===`MAP`||i===`LIST`||i===`MAP`||i===`MAP_KEY_VALUE`||n.repetition_type===`REPEATED`)return t.push(a),[];if(e.children.length)return e.children.flatMap(e=>Uy(e,t));if(n.type===`INT96`)return[{path:e.path,column:{name:a,unit:``,kind:`time`,absolute:!0},wall:!1,ns:!0}];if(r===`TIMESTAMP`||r===`DATE`||i===`TIMESTAMP_MILLIS`||i===`TIMESTAMP_MICROS`||i===`DATE`){let t=r===`DATE`||i===`DATE`,o=n.logical_type?.type===`TIMESTAMP`?!n.logical_type.isAdjustedToUTC:t;return[{path:e.path,column:{name:a,unit:``,kind:`time`,absolute:!0},wall:o,ns:!t}]}if(r===`STRING`||r===`ENUM`||r===`JSON`||i===`UTF8`||i===`ENUM`||i===`JSON`)return[{path:e.path,column:{name:a,unit:``,kind:`text`},wall:!1}];if(!(n.type===`BOOLEAN`||n.type===`INT32`||n.type===`INT64`||n.type===`FLOAT`||n.type===`DOUBLE`||r===`DECIMAL`||i===`DECIMAL`))return t.push(a),[];let o=e.path.length===1&&il.test(n.name);return[{path:e.path,column:{name:a,unit:o?`s`:``,kind:o?`time`:`number`},wall:!1}]}const Wy=e=>typeof e==`number`?e:typeof e==`bigint`?Number(e):typeof e==`boolean`?+!!e:NaN,Gy=(e,t)=>{for(let n of t)e=e?.[n];return e},Ky=async e=>{try{return await e}catch{throw Error(`This Parquet file is damaged (its metadata or pages could not be read).`)}};async function qy(e,t=8388608){let n={byteLength:e.size,slice:async(t,n=e.size)=>(await e.slice(t,n-t)).slice().buffer},r=await Ky(qh(n,{parsers:Vy})),i=[],a=Yh(r).children.flatMap(e=>Uy(e,i)),o=i.length?[`${i.length} ${i.length===1?`column`:`columns`} skipped (lists, maps or binary): ${i.slice(0,5).join(`, `)}${i.length>5?`, …`:``}.`]:[],s={name:`Table`,columns:a.map(e=>e.column),rows:Number(r.num_rows),notes:o,async*read(e,i){let o=e.map(e=>a[e]),s=[...new Set(o.map(e=>e.path[0]))],c=Math.max(1,Math.floor(t/Math.max(1,o.length))),l=0;for(let e of r.row_groups){let t=l,a=l+Number(e.num_rows);l=a;for(let e=t;e<a;e+=c){i?.throwIfAborted();let t=Math.min(a,e+c),l=-1,u=[];for(let i of s){let a=[];if(await Ky(gv({file:n,metadata:r,columns:[i],rowStart:e,rowEnd:t,compressors:Iy,parsers:Vy,onChunk:e=>{a.push({start:e.rowStart,data:e.columnData})}})),l<0){if(l=Math.min(t-e,a.reduce((t,n)=>Math.max(t,n.start+n.data.length-e),0)),l===0)break;for(let e of o)u.push(e.column.kind===`text`?Array(l).fill(null):new Float64Array(l).fill(NaN))}o.forEach((t,n)=>{if(t.path[0]!==i)return;let r=u[n],o=t.column.kind===`text`;for(let n of a){if(!o&&!t.wall&&!t.iso&&!t.ns&&t.path.length===1&&n.start>=e&&n.start-e+n.data.length<=l&&ArrayBuffer.isView(n.data)&&!(n.data instanceof BigInt64Array)&&!(n.data instanceof BigUint64Array)){r.set(n.data,n.start-e);continue}for(let i=Math.max(0,e-n.start);i<n.data.length;i++){let a=n.start+i-e;if(a>=l)break;let s=t.path.length>1?Gy(n.data[i],t.path.slice(1)):n.data[i];if(o)r[a]=s==null?null:String(s);else if(t.ns)r[a]=typeof s==`bigint`?Hy(t,s):NaN;else{let e=t.iso?s==null?NaN:ol(String(s)):Wy(s);r[a]=t.wall&&!Number.isNaN(e)?sl(e):e}}}})}if(l<=0)break;yield{length:l,columns:u}}}}},c=a.flatMap((e,t)=>e.column.kind===`text`?[t]:[]);if(c.length)for await(let e of s.read(c)){c.forEach((t,n)=>{let r=e.columns[n];!r.some(e=>e)||r.some(e=>e&&Number.isNaN(ol(e)))||(a[t].iso=!0,Object.assign(a[t].column,{kind:`time`,absolute:!0}))});break}return{format:`Parquet`,tables:[s],notes:[]}}const Jy=zy(By,(e,t)=>qy(t)),Yy={id:`xlsx`,label:`Excel workbook`,extensions:[`.xlsx`,`.xlsm`],sniff:e=>e[0]===80&&e[1]===75&&e[2]===3&&e[3]===4&&u(e).includes(`xl/`)},Xy=`This workbook is damaged (its ZIP structure could not be read).`;async function Zy(e){let t=Math.min(e.size,65557),n=await e.read(e.size-t,t),r=new DataView(n.buffer,n.byteOffset,n.byteLength),i=-1;for(let e=n.length-22;e>=0;e--)if(r.getUint32(e,!0)===101010256){i=e;break}if(i<0)throw Error(Xy);let a=r.getUint16(i+10,!0),o=r.getUint32(i+12,!0),s=r.getUint32(i+16,!0);if(s===4294967295||a===65535)throw Error(`Workbooks over 4 GB are not supported.`);let c=await e.slice(s,o),l=new DataView(c.buffer,c.byteOffset,c.byteLength),u=new TextDecoder,d=new Map;for(let e=0,t=0;t<a;t++){if(e+46>c.length||l.getUint32(e,!0)!==33639248)throw Error(Xy);let t=l.getUint16(e+28,!0),n=u.decode(c.subarray(e+46,e+46+t));d.set(n.replace(/^\//,``),{method:l.getUint16(e+10,!0),compressed:l.getUint32(e+20,!0),offset:l.getUint32(e+42,!0)}),e+=46+t+l.getUint16(e+30,!0)+l.getUint16(e+32,!0)}return d}async function*Qy(e,t){let n=await e.read(t.offset,30),r=new DataView(n.buffer,n.byteOffset,n.byteLength);if(n.length<30||r.getUint32(0,!0)!==67324752)throw Error(Xy);let i=t.offset+30+r.getUint16(26,!0)+r.getUint16(28,!0),a=new TextDecoder;if(t.method===0)for await(let n of e.windows(i,t.compressed))yield a.decode(n.bytes,{stream:!0});else if(t.method===8){let n=[],r=new Qe(e=>{n.push(e)});try{for await(let o of e.windows(i,t.compressed,1<<20))for(r.push(o.bytes,!1);n.length;)yield a.decode(n.shift(),{stream:!0});r.push(new Uint8Array,!0)}catch{throw Error(Xy)}for(;n.length;)yield a.decode(n.shift(),{stream:!0})}else throw Error(`This workbook uses a ZIP compression Kymoscope does not read (method ${t.method}).`);let o=a.decode();o&&(yield o)}async function $y(e,t,n=268435456){if(!t)return``;let r=``;for await(let i of Qy(e,t)){if(r.length+i.length>n)throw Error(`This workbook is too large to read (one of its parts holds over 256 MB of text).`);r+=i}return r}const eb=1048576;var tb=class{rows=0;cols=[];#e=0;budget;constructor(e=T){this.budget=e}#t(e){if(this.#e+=e,this.#e>this.budget)throw Error(`This sheet is too large to open (over ${this.budget.toLocaleString(`en-US`)} cells).`)}put(e,t,n,r){if(e<0||t<0)return;if(e>=eb)throw Error(`This sheet has a cell beyond Excel's last row (1,048,576); the file may be damaged.`);if(t>=16384)throw Error(`This sheet has a cell beyond Excel's last column (XFD); the file may be damaged.`);e>=this.rows&&(this.rows=e+1);let i=this.cols[t];if(i||=(this.#t(256),this.cols[t]={num:new Float64Array(256).fill(NaN),date:new Uint8Array(256),text:new Map}),typeof n==`string`){n.trim()&&(this.#t(1),i.text.set(e,n));return}if(e>=i.num.length){let t=Math.min(eb,Math.max(e+1,i.num.length*2));this.#t(t-i.num.length);let n=new Float64Array(t).fill(NaN);n.set(i.num);let r=new Uint8Array(t);r.set(i.date),i.num=n,i.date=r}i.num[e]=n,i.date[e]=+!!r}numbersIn(e){return this.cols.reduce((t,n)=>t+(n&&e<n.num.length&&!Number.isNaN(n.num[e])?1:0),0)}textsIn(e){return this.cols.reduce((t,n)=>t+ +!!n?.text.has(e),0)}};const nb=e=>e<26?String.fromCharCode(65+e):nb(Math.floor(e/26)-1)+String.fromCharCode(65+e%26),rb=65536;function ib(e,t,n,r){let i=t.cols.filter(Boolean).length,a=-1;for(let e=0;e<Math.min(t.rows,50);e++)if(t.textsIn(e)>=Math.max(1,Math.ceil(i/2))&&(t.numbersIn(e+1)>0||t.numbersIn(e+2)>0)){a=e;break}let o=a+1,s=-1;a>=0&&t.numbersIn(o)===0&&t.textsIn(o)>0&&t.cols.every(e=>!e?.text.has(o)||e.text.get(o).length<=16)&&(s=o,o++);let c=[];a>0&&Array.from({length:a},(e,n)=>t.textsIn(n)+t.numbersIn(n)).some(e=>e>0)&&c.push(`${e}: rows 1–${a} above the header were skipped.`),r&&c.push(`${e}: ${r.toLocaleString(`en-US`)} formula ${r===1?`cell has`:`cells have`} no saved value (the workbook was saved without calculating them); ${r===1?`it is`:`they are`} empty.`);let l=[],u=[];return t.cols.forEach((e,r)=>{if(!e)return;let i=0,c=0;for(let n=o;n<Math.min(t.rows,e.num.length);n++)Number.isNaN(e.num[n])||(i++,c+=e.date[n]);let d=0;for(let t of e.text.keys())t>=o&&d++;if(i+d===0)return;let f=(a>=0?e.text.get(a)?.trim():void 0)||`Column ${nb(r)}`,p=i===0;if(p){for(let[t,n]of e.text)if(t>=o&&Number.isNaN(ol(n))){p=!1;break}}let m=p?`time`:i>=d?c*2>i||il.test(f)?`time`:`number`:`text`,h=p?`iso`:m===`time`&&c*2>i?`serial`:null,g=NaN;if(h===`serial`)for(let t=o;t<e.num.length&&Number.isNaN(g);t++)g=e.num[t];let _=Number.isNaN(g)?void 0:sl((g-n)*86400);l.push({name:f,unit:s>=0?e.text.get(s)?.trim()??``:``,kind:m,absolute:h!==null,origin:_}),u.push({col:e,kind:m,from:h,first:g})}),l.some(e=>e.kind!==`text`)?{name:e,columns:l,rows:Math.max(0,t.rows-o),notes:c,async*read(e,r){for(let i=o;i<t.rows;i+=rb){r?.throwIfAborted();let a=Math.min(t.rows,i+rb);yield{length:a-i,columns:e.map(e=>{let{col:t,kind:r,from:o,first:s}=u[e];if(r===`text`)return Array.from({length:a-i},(e,n)=>t.text.get(i+n)??(i+n<t.num.length&&!Number.isNaN(t.num[i+n])?String(t.num[i+n]):null));let c=new Float64Array(a-i).fill(NaN);if(o===`iso`){for(let e=0;e<c.length;e++){let n=t.text.get(i+e);n!==void 0&&(c[e]=ol(n))}return c}if(c.set(t.num.subarray(Math.min(i,t.num.length),Math.min(a,t.num.length))),o===`serial`){let e=cl((s-n)*86400);for(let t=0;t<c.length;t++){let r=c[t];Number.isNaN(r)||(c[t]=Math.round((r-s)*864e5)/1e3+(cl((r-n)*86400)-e))}}return c})}}}}:`${e}: no numbers; skipped.`}async function ab(e){let t=await Zy(e),{sheets:n,date1904:r}=Nl(await $y(e,t.get(`xl/workbook.xml`)),await $y(e,t.get(`xl/_rels/workbook.xml.rels`)));if(n.length===0)throw Error(`This workbook has no sheets Kymoscope can read.`);let i=Ll(await $y(e,t.get(`xl/sharedStrings.xml`))),a=Il(await $y(e,t.get(`xl/styles.xml`))),o=r?24107:25569,s=[],c=[];for(let r of n){let n=t.get(r.path);if(!n)continue;let l=new tb(T-i.length),u=await Ul(Qy(e,n),i,a,(e,t,n,r)=>l.put(e,t,n,r)),d=ib(r.name,l,o,u);typeof d==`string`?c.push(d):s.push(d)}return{format:`Excel workbook`,tables:s,notes:c}}const ob=zy(Yy,(e,t)=>ab(t)),sb={id:`longtext`,label:`Delimited text, one row per sample`,extensions:[`.csv`,`.tsv`,`.txt`,`.dat`],sniff:(e,t)=>/\.(csv|tsv|txt|dat)$/i.test(t)&&!e.includes(0)&&ml(new TextDecoder().decode(e))},cb=65536;async function*lb(e,t){let n=new TextDecoder,r=``;for await(let i of e.windows(0,e.size)){t?.throwIfAborted();let e=(r+n.decode(i.bytes,{stream:!0})).split(/\r?\n/);r=e.pop(),yield*e}r+=n.decode(),r&&(yield r)}async function ub(e){let t=[];for await(let n of lb(e))if(n.trim()&&t.push(n),t.length>200)break;if(t.length<2)throw Error(`This file has no rows.`);let n=dl(t.slice(0,50))??`,`,r=n===`;`,i=pl(ul(t[0],n),t.slice(1).map(e=>ul(e,n)),r);return{format:`Delimited text`,tables:[{name:`Table`,columns:i,rows:-1,notes:[],async*read(t,a){let o=()=>t.map(e=>i[e].kind===`text`?Array(cb).fill(null):new Float64Array(cb).fill(NaN)),s=o(),c=0,l=!0;for await(let u of lb(e,a)){if(!u.trim())continue;if(l){l=!1;continue}let e=ul(u,n);for(let n=0;n<t.length;n++){let a=i[t[n]],o=e[t[n]]??``;a.kind===`text`?s[n][c]=o.trim()===``?null:o.trim():s[n][c]=a.absolute?ol(o):fl(o,r)}++c===cb&&(yield{length:c,columns:s},s=o(),c=0)}c&&(yield{length:c,columns:s.map(e=>e.slice(0,c))})}}],notes:[]}}const db=zy(sb,(e,t)=>ub(t));new TextEncoder;function fb(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>=4096&&(o+=String.fromCharCode(...a),a.length=0)}return a.length>0&&(o+=String.fromCharCode(...a)),o}const pb=new TextDecoder;function mb(e,t,n){let r=e.subarray(t,t+n);return pb.decode(r)}function hb(e,t,n){return n>200?mb(e,t,n):fb(e,t,n)}var gb=class{type;data;constructor(e,t){this.type=e,this.data=t}},_b=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 vb(e,t,n){let r=Math.floor(n/4294967296),i=n;e.setUint32(t,r),e.setUint32(t+4,i)}function yb(e,t){let n=e.getInt32(t),r=e.getUint32(t+4);return n*4294967296+r}function bb(e,t){let n=e.getUint32(t),r=e.getUint32(t+4);return n*4294967296+r}function xb({sec:e,nsec:t}){if(e>=0&&t>=0&&e<=17179869183)if(t===0&&e<=4294967295){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),vb(r,4,e),n}}function Sb(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 Cb(e){return e instanceof Date?xb(Sb(e)):null}function wb(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:yb(t,4),nsec:t.getUint32(0)};default:throw new _b(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${e.length}`)}}function Tb(e){let t=wb(e);return new Date(t.sec*1e3+t.nsec/1e6)}const Eb={type:-1,encode:Cb,decode:Tb};var Db=class e{static defaultCodec=new e;__brand;builtInEncoders=[];builtInDecoders=[];encoders=[];decoders=[];constructor(){this.register(Eb)}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 gb(-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 gb(n,i)}}return e instanceof gb?e:null}decode(e,t,n){let r=t<0?this.builtInDecoders[-1-t]:this.decoders[t];return r?r(e,t,n):new gb(t,e)}};function Ob(e){return e instanceof ArrayBuffer||typeof SharedArrayBuffer<`u`&&e instanceof SharedArrayBuffer}function kb(e){return e instanceof Uint8Array?e:ArrayBuffer.isView(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):Ob(e)?new Uint8Array(e):Uint8Array.from(e)}function Ab(e){return`${e<0?`-`:``}0x${Math.abs(e).toString(16).padStart(2,`0`)}`}var jb=class{hit=0;miss=0;caches;maxKeyLength;maxLengthPerKey;constructor(e=16,t=16){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=fb(e,t,n),a=Uint8Array.prototype.slice.call(e,t,t+n);return this.store(a,i),i}};const Mb=`array`,Nb=`map_key`,Pb=`map_value`,Fb=e=>{if(typeof e==`string`||typeof e==`number`)return e;throw new _b(`The type of key must be string or number but `+typeof e)};var Ib=class{stack=[];stackHeadPosition=-1;get length(){return this.stackHeadPosition+1}top(){return this.stack[this.stackHeadPosition]}pushArrayState(e){let t=this.getUninitializedStateFromPool();t.type=Mb,t.position=0,t.size=e,t.array=Array(e)}pushMapState(e){let t=this.getUninitializedStateFromPool();t.type=Nb,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===Mb){let t=e;t.size=0,t.array=void 0,t.position=0,t.type=void 0}if(e.type===Nb||e.type===Pb){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}};const Lb=new DataView(new ArrayBuffer(0)),Rb=new Uint8Array(Lb.buffer);try{Lb.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`)}const zb=RangeError(`Insufficient data`),Bb=new jb;var Vb=class e{extensionCodec;context;useBigInt64;rawStrings;maxStrLength;maxBinLength;maxArrayLength;maxMapLength;maxExtLength;keyDecoder;mapKeyConverter;totalPos=0;pos=0;view=Lb;bytes=Rb;headByte=-1;stack=new Ib;entered=!1;constructor(e){this.extensionCodec=e?.extensionCodec??Db.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?Bb:e.keyDecoder,this.mapKeyConverter=e?.mapKeyConverter??Fb}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=-1,this.stack.reset()}setBuffer(e){let t=kb(e);this.bytes=t,this.view=new DataView(t.buffer,t.byteOffset,t.byteLength),this.pos=0}appendBuffer(e){if(this.headByte===-1&&!this.hasRemaining(1))this.setBuffer(e);else{let t=this.bytes.subarray(this.pos),n=kb(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 ${Ab(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 _b(`Unrecognized type byte: ${Ab(e)}`);this.complete();let n=this.stack;for(;n.length>0;){let e=n.top();if(e.type===Mb)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===Nb){if(t===`__proto__`)throw new _b(`The key __proto__ is not allowed`);e.key=this.mapKeyConverter(t),e.type=Pb;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=Nb;continue DECODE}}return t}}readHeadByte(){return this.headByte===-1&&(this.headByte=this.readU8()),this.headByte}complete(){this.headByte=-1}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 _b(`Unrecognized array type byte: ${Ab(e)}`)}}pushMapState(e){if(e>this.maxMapLength)throw new _b(`Max length exceeded: map length (${e}) > maxMapLengthLength (${this.maxMapLength})`);this.stack.pushMapState(e)}pushArrayState(e){if(e>this.maxArrayLength)throw new _b(`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 _b(`Max length exceeded: UTF-8 byte length (${e}) > maxStrLength (${this.maxStrLength})`);if(this.bytes.byteLength<this.pos+t+e)throw zb;let n=this.pos+t,r;return r=this.stateIsMapKey()&&this.keyDecoder?.canBeCached(e)?this.keyDecoder.decode(this.bytes,n,e):hb(this.bytes,n,e),this.pos+=t+e,r}stateIsMapKey(){return this.stack.length>0?this.stack.top().type===Nb:!1}decodeBinary(e,t){if(e>this.maxBinLength)throw new _b(`Max length exceeded: bin length (${e}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining(e+t))throw zb;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 _b(`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=bb(this.view,this.pos);return this.pos+=8,e}readI64(){let e=yb(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 Hb(e,t){return new Vb(t).decode(e)}const Ub=e=>e+7&-8;function Wb(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)!==1)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=Ub(s),s+Ub(i*8)+o.reduce((e,t)=>e+Ub(i*t.size),0)>e.byteLength)throw t(`short data`);let c=e.byteOffset,l=new Float64Array(e.buffer,c+s,i);s+=Ub(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+=Ub(i*t.size);return{t:l,columns:u,units:d}}function Gb(e){return e.values.map(e=>e.buffer)}const Kb=`ElapsedTime`;function qb(){let e=globalThis.crypto;if(!e?.subtle)throw Error(`WebCrypto SubtleCrypto is not available`);return e.subtle}async function Jb(e,t,n,r){let i=await qb().decrypt({name:`AES-GCM`,iv:t,additionalData:r},e,n);return new Uint8Array(i)}new TextEncoder().encode(`kymoscope-device-wrap-v1`),new TextEncoder().encode(`kymoscope-sender-bind-v1`);const Yb=e=>Array.from(e,e=>e.toString(16).padStart(2,`0`)).join(``),Xb=e=>{let t=Yb(e);return`${t.slice(0,8)}-${t.slice(8,12)}-${t.slice(12,16)}-${t.slice(16,20)}-${t.slice(20)}`};function Zb(e){if(e.length!==70||e[0]!==1)return null;let t=new DataView(e.buffer,e.byteOffset,e.byteLength);return{streamId:Xb(e.subarray(1,17)),run:Yb(e.subarray(17,25)),lane:e[25],seq:t.getBigUint64(26,!0),count:t.getUint32(34,!0),hash:e.slice(38,70)}}const Qb=()=>globalThis.crypto.subtle,$b=e=>Qb().digest(`SHA-256`,e);async function ex(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 $b(n))}const tx=e=>crypto.subtle.digest(`SHA-256`,e),nx=e=>Array.from(new Uint8Array(e),e=>e.toString(16).padStart(2,`0`)).join(``),rx=e=>Uint8Array.from(e.replace(/-/g,``).match(/../g)??[],e=>parseInt(e,16));async function ix(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?Zb(a.plaintext):null,s=nx(await tx(rx(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&&nx((await ex(t.slice(0,-1).map(e=>tx(e.bytes)))).buffer)===nx(o.hash.buffer)?`verified`:`broken`}function ax(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}const ox=64*1024*1024,$=(e,t)=>RangeError(`${e}: ${t}`);function sx(e,t){let n=new TextDecoder(`utf-8`,{fatal:!0}),r=[],i=0;try{for(let a=0;a<t;a++){if(i+3>e.byteLength)throw $(`block schema`,`short channel table`);let t=e[i],a=e[i+1],o=e[i+2];if(i+=3,t!==4&&t!==8)throw $(`block schema`,`value size ${t}`);if(i+a+o>e.byteLength)throw $(`block schema`,`short channel table`);r.push({name:n.decode(e.subarray(i,i+a)),unit:n.decode(e.subarray(i+a,i+a+o)),size:t}),i+=a+o}}catch(e){throw e instanceof RangeError?e:$(`block schema`,`invalid text`)}return r}async function cx(e){if(e.byteLength<8)throw $(`block schema`,`short`);let t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=t.getUint8(0);if(n===3){if(e.byteLength<12)throw $(`block schema`,`short`);let n=t.getUint32(4,!0);if(n>1e5)throw $(`block schema`,`too many channels`);let r=t.getUint8(1)&1?await fx(e.subarray(12),n*513,!1):e.subarray(12);return{id:t.getUint32(8,!0),channels:sx(r,n)}}if(n!==2)throw $(`block schema`,`version ${n}`);return{id:t.getUint32(4,!0),channels:sx(e.subarray(8),t.getUint16(2,!0))}}function lx(e,t,n){let r=n.get(t.getUint32(4,!0));if(!r)return null;let i=t.getUint32(8,!0);if(i!==r.channels.length)throw $(`last values`,`channel count differs from its schema`);if(e.byteLength<12+16*i)throw $(`last values`,`short`);let a=[];for(let e=0;e<i;e++){let n=t.getFloat64(12+8*e,!0),o=t.getFloat64(12+8*(i+e),!0);Number.isFinite(n)&&Number.isFinite(o)&&a.push({name:r.channels[e].name,unit:r.channels[e].unit,t:n,v:o})}return a}async function ux(e,t){if(e.byteLength<12)throw $(`last values`,`short`);let n=new DataView(e.buffer,e.byteOffset,e.byteLength),r=n.getUint8(0);if(r===1)return lx(e,n,t);if(r!==2)throw $(`last values`,`version ${r}`);if(e.byteLength<20)throw $(`last values`,`short`);let i=n.getUint8(1),a=t.get(n.getUint32(4,!0));if(!a)return null;let o=n.getUint32(8,!0),s=n.getFloat64(12,!0),c=a.channels.length,l=(i&2)!=0;if(o>c||l&&o!==c)throw $(`last values`,`entry count differs from its schema`);let u=(l?0:4*o)+4*o,d=i&1?await fx(e.subarray(20),u+8*o,!1):e.subarray(20);if(d.byteLength<u)throw $(`last values`,`short`);let f=new DataView(d.buffer,d.byteOffset,d.byteLength),p=[];for(let e=0;e<o;e++){let t=l?e:f.getUint32(4*e,!0);if(t>=c)throw $(`last values`,`channel outside its schema`);p.push(t)}let m=l?0:4*o,h=p.filter(e=>a.channels[e].size===4),g=p.filter(e=>a.channels[e].size===8);if(d.byteLength!==u+4*h.length+8*g.length)throw $(`last values`,`body size mismatch`);let _=dx(d,u,h.length,4),v=dx(d,u+4*h.length,g.length,8),y=new Map;h.forEach((e,t)=>y.set(e,_[t])),g.forEach((e,t)=>y.set(e,v[t]));let b=[];return p.forEach((e,t)=>{let n=s-f.getUint32(m+4*t,!0)/1e3,r=y.get(e);Number.isFinite(n)&&Number.isFinite(r)&&b.push({name:a.channels[e].name,unit:a.channels[e].unit,t:n,v:r})}),b}function dx(e,t,n,r){let i=new Uint8Array(n*r);for(let a=0;a<r;a++)for(let o=0;o<n;o++)i[o*r+a]=e[t+a*n+o];return r===4?new Float32Array(i.buffer):new Float64Array(i.buffer)}async function fx(e,t,n=!0){let r=new Blob([e]).stream().pipeThrough(new DecompressionStream(`deflate`)).getReader(),i=new Uint8Array(Math.min(t,e.byteLength*4+1024)),a=0;try{for(;;){let{done:e,value:n}=await r.read();if(e)break;if(a+n.length>t)throw $(`block`,`body larger than its header says`);if(a+n.length>i.length){let e=new Uint8Array(Math.min(t,Math.max(2*i.length,a+n.length)));e.set(i.subarray(0,a)),i=e}i.set(n,a),a+=n.length}}catch(e){throw await r.cancel().catch(()=>{}),e instanceof RangeError?e:$(`block`,`body is not valid deflate`)}if(n&&a!==t)throw $(`block`,`body size mismatch`);return i.length===a?i:i.subarray(0,a)}async function px(e,t){if(e.byteLength<20)throw $(`block`,`short`);let n=new DataView(e.buffer,e.byteOffset,e.byteLength);if(n.getUint8(0)!==2)throw $(`block`,`version ${n.getUint8(0)}`);let r=n.getUint8(1),i=n.getUint16(2,!0),a=n.getUint32(4,!0),o=n.getUint32(8,!0),s=t.get(o);if(!s)return null;if(s.channels.length!==i)throw $(`block`,`channel count differs from its schema`);let c=n.getFloat64(12,!0),l=Math.max(0,a-1),u=4*l+s.channels.reduce((e,t)=>e+t.size*a,0);if(u>ox)throw $(`block`,`too large`);let d;if(r&1)d=await fx(e.subarray(20),u);else if(d=e.subarray(20),d.byteLength<u)throw $(`block`,`body size mismatch`);let f=new DataView(d.buffer,d.byteOffset,d.byteLength),p=new Float64Array(a),m=0;a&&(p[0]=c);for(let e=1;e<a;e++)m+=f.getInt32(4*(e-1),!0),p[e]=c+m/1e6;let h=4*l,g={},_={};for(let e of s.channels)g[e.name]=dx(d,h,a,e.size),e.unit&&(_[e.name]=e.unit),h+=a*e.size;return{block:{t:p,columns:g,units:_},historical:(r&2)!=0,schemaId:o}}async function mx(e,t){if(e.byteLength<20)throw $(`sparse`,`short`);let n=new DataView(e.buffer,e.byteOffset,e.byteLength);if(n.getUint8(0)!==1)throw $(`sparse`,`version ${n.getUint8(0)}`);let r=n.getUint8(1),i=n.getUint32(4,!0),a=t.get(i);if(!a)return null;let o=n.getUint32(8,!0),s=n.getFloat64(12,!0),c=4*o+4*Math.max(0,o-1);if(c+8*o>ox)throw $(`sparse`,`too large`);let l=r&1?await fx(e.subarray(20),c+8*o,!1):e.subarray(20);if(l.byteLength<c)throw $(`sparse`,`body size mismatch`);let u=new Uint32Array(o);for(let e=0;e<o;e++)u[e]=(l[e]|l[o+e]<<8|l[2*o+e]<<16|l[3*o+e]<<24)>>>0;let d=a.channels.length,f=0;for(let e=0;e<o;e++){if(u[e]>=d)throw $(`sparse`,`event outside its schema`);a.channels[u[e]].size===4&&f++}if(l.byteLength!==c+4*f+8*(o-f))throw $(`sparse`,`body size mismatch`);let p=new DataView(l.buffer,l.byteOffset,l.byteLength),m=new Float64Array(o),h=0;o&&(m[0]=s);for(let e=1;e<o;e++)h+=p.getInt32(4*o+4*(e-1),!0),m[e]=s+h/1e6;let g=dx(l,c,f,4),_=dx(l,c+4*f,o-f,8),v=new Float64Array(o);for(let e=0,t=0,n=0;e<o;e++)v[e]=a.channels[u[e]].size===4?g[t++]:_[n++];return{schemaId:i,index:u,t:m,v,historical:(r&2)!=0}}const hx=[75,82,67,49];function gx(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 _x(e){if(e.length<56||hx.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:gx(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 vx(e){let t=_x(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}}function yx(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+12+16)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 Jb(e,n.subarray(r,r+12),n.subarray(r+12),n.subarray(0,r));return t.set(i,e),{kind:n[0]&-129,plaintext:a}}catch{}return null}}const bx=8192;async function*xx(e){let t=0;for(;t+56<=e.size;){let n=_x(await e.read(t,56));if(yield await e.slice(t,n.bytes),n.bytes<=56)return;t+=n.bytes}}function Sx(e){let t=e.filter(e=>e&&typeof e.t==`number`&&Array.isArray(e.signals)),n={},r={};return t.forEach((e,i)=>{for(let a of e.signals){if(!a||typeof a.name!=`string`)continue;let e=n[a.name]??=new Float64Array(t.length).fill(NaN);e[i]=typeof a.value==`number`?a.value:NaN,a.unit&&!r[a.name]&&(r[a.name]=a.unit)}}),{t:t.map(e=>e.t),columns:n,units:r}}function Cx(e){let t=2166136261^e.length;for(let n=0,r=Math.min(e.length,64);n<r;n++)t=Math.imul(t^e[n],16777619);return t>>>0}const wx=(e,t)=>e.length===t.length&&e.every((e,n)=>e===t[n]);var Tx=class{known=new Map;real=new Set;pending=new Set;held=new Set;note(e){for(let t of e){let e=this.known.get(t.name);(!e||t.t>=e.t)&&this.known.set(t.name,{t:t.t,v:t.v,unit:t.unit}),!this.real.has(t.name)&&!this.held.has(t.name)&&this.pending.add(t.name)}}sampled(e){if(this.pending.size+this.held.size===0)return;let t=e=>{(this.pending.delete(e)||this.held.delete(e))&&this.real.add(e)};for(let[n,r]of Object.entries(e.columns))if(!(!this.pending.has(n)&&!this.held.has(n))){for(let e=0;e<r.length;e++)if(Number.isFinite(r[e])){t(n);break}}if(e.events&&e.schema){let{index:n,v:r}=e.events;for(let i=0;i<r.length;i++)Number.isFinite(r[i])&&t(e.schema.channels[n[i]].name)}}start(e){if(this.pending.size===0||e.t.length===0)return e;let t={...e.columns},n={...e.units};for(let e of this.pending){let r=this.known.get(e);t[e]=Float64Array.of(r.v),r.unit&&!n[e]&&(n[e]=r.unit),this.held.add(e)}let r=[...this.pending];return this.pending.clear(),{...e,columns:t,units:n,more:r}}end(e,t){if(e===null||this.held.size===0)return null;let n={},r={};for(let e of this.held){let t=this.known.get(e);n[e]=Float64Array.of(t.v),t.unit&&(r[e]=t.unit)}return{at:t,t:[e],columns:n,units:r}}};async function*Ex(e,t,n,r,i=!1){let a=yx(e.keys??[]),o=new Map,s=new Map,c=r?null:new Tx,l=null,u=0,d=e=>c?(c.sampled(e),e.t.length&&(l=+e.t[e.t.length-1],u=e.at),c.start(e)):e,f={results:[]};for await(let e of xx(t)){let{header:t,messages:l}=vx(e);if(n.t0??=t.t0,i){let e=t.recordingId;f.results.push({rid:e,check:await ix(t,l,a,f.rid===e?(f.seq??-1)+1:0)}),f.rid=e,f.seq=t.seq,n.chain=ax(f.results)}for(let e of l){let t=Cx(e.bytes),i=s.get(t);if(i&&wx(i,e.bytes))continue;s.set(t,e.bytes),s.size>4096&&s.delete(s.keys().next().value);let l=await a(e.bytes);if(!l){n.lost++;continue}try{if(l.kind===5){let e=await cx(l.plaintext);o.set(e.id,e);continue}if(l.kind===4||l.kind===9){let t;if(l.kind===4){let r=await px(l.plaintext,o);if(!r){n.lost++;continue}t={at:e.at,t:r.block.t,columns:r.block.columns,units:r.block.units??{},historical:r.historical,schema:o.get(r.schemaId)}}else{let r=await mx(l.plaintext,o);if(!r){n.lost++;continue}t={at:e.at,t:r.t,columns:{},units:{},historical:r.historical,events:{index:r.index,v:r.v},schema:o.get(r.schemaId)}}t.historical&&c?.sampled(t),(r===void 0||r===!!t.historical)&&(yield t.historical?t:d(t));continue}if(r)continue;if(l.kind===7){let e=await ux(l.plaintext,o);e&&c?.note(e)}else if(l.kind===3){let t=Wb(l.plaintext);yield d({at:e.at,t:t.t,columns:t.columns,units:t.units??{}})}else if(l.kind===2){let t=Hb(l.plaintext);yield d({at:e.at,...Sx(Array.isArray(t?.frames)?t.frames:[])})}}catch{n.lost++}}}let p=c?.end(l,u);p&&(yield p)}function Dx(e,t,n){let r=e===null?t:t===null?e:Math.min(e,t);return r===null?{}:r>1e9?{wallOrigin:String(r),wallQuality:`exact`}:Number.isFinite(n)?{wallOrigin:String(r+n),wallQuality:`approx`}:{}}const Ox={id:`krc`,label:`Kymoscope recording`,extensions:[],sniff:()=>!1,async plan(e,t){let n=[Kb],r=new Map([[Kb,`s`]]),i={lost:0,t0:null},a=0,o=!1,s=null,c=null,l=0,u=-1/0,d=0,f=1/0,p=(e,t=``)=>{e!==`ElapsedTime`&&(r.has(e)?!r.get(e)&&t&&r.set(e,t):(n.push(e),r.set(e,t)))},m=new Set;for await(let n of Ex(e,t,i,void 0,!0)){a+=n.t.length,n.historical&&(o=!0);let e=n.t.length;if(e&&n.historical?c??=+n.t[0]:e&&(s??=+n.t[0],+n.t[0]+l<u&&(l=u+Math.max(0,(n.at-d)/1e3)-+n.t[0]),d=n.at,u=+n.t[e-1]+l,f=Math.min(f,n.at/1e3-u)),n.schema){if(!m.has(n.schema.id)){m.add(n.schema.id);for(let e of n.schema.channels)p(e.name,e.unit)}for(let e of n.more??[])p(e,n.units[e])}else for(let e of Object.keys(n.columns))p(e,n.units[e])}let h=n.map(e=>({name:e,unit:r.get(e)??``})),g=i.lost?[`${i.lost} ${i.lost===1?`message`:`messages`} couldn't be opened with the keys this browser has.`]:[],_=i.chain?.broken??0,v=n.length-1,y=v>1e3?[{group:0,channels:n.slice(0,Ly+1).map((e,t)=>t)}]:void 0;return y&&g.push(`This recording has ${v.toLocaleString(`en-US`)} channels; the first ${Ly.toLocaleString(`en-US`)} are loaded.`),_&&g.push(`Some of this recording was missing, out of order or changed where it is stored (${_} of ${_+(i.chain?.verified??0)} checked ${_+(i.chain?.verified??0)===1?`chunk`:`chunks`}).`),{format:`Kymoscope recording`,startTime:i.t0===null?null:new Date(i.t0).toISOString(),groups:[{name:`Recording`,channels:h,samples:a,time:{kind:`timestamps`},rateHz:null}],meta:{...Dx(s,c,f),...i.chain&&(i.chain.verified||i.chain.broken)?{chainVerified:String(i.chain.verified),chainBroken:String(i.chain.broken),chainUnchecked:String(i.chain.unchecked)}:{}},events:[],notes:g,defaultSelection:y,state:{names:n,backlog:o}}},async*stream(e){let{names:t,backlog:n=!1}=e.plan.state,r=e.selection.find(e=>e.group===0)?.channels??[],i=new Map(r.map((e,n)=>[t[e],n])),a=i.get(Kb),o=()=>r.map(()=>new Float64Array(bx).fill(NaN)),s=new Float64Array(bx),c=o(),l=0,u=0,d=0,f=null,p=()=>{let e={group:0,time:s.slice(0,l),start:u,length:l,columns:c.map(e=>e.slice(0,l))};return u+=l,l=0,s=new Float64Array(bx),c=o(),e},m=new WeakMap,h=e=>{let t=m.get(e);return t||m.set(e,t=Int32Array.from(e.channels,e=>e.name===`ElapsedTime`?-2:i.get(e.name)??-1)),t};function*g(e,t,n,r){let o=Object.entries(e.columns).flatMap(([e,t])=>{let n=e===`ElapsedTime`?void 0:i.get(e);return n===void 0?[]:[[n,+t[0]]]});for(let i=0;i<e.t.length;i++){let u=r[t[i]];if(u===-1&&!(i===0&&o.length))continue;let m=+e.t[i];if(s[l]=m+d-f,a!==void 0&&(c[a][l]=m),u>=0&&(c[u][l]=n[i]),i===0)for(let[e,t]of o)c[e][l]=t;++l===bx&&(yield p())}}function*_(e){let t=e.t.length;if(t&&(f??=+e.t[0]+d),e.events&&e.schema)return yield*g(e,e.events.index,e.events.v,h(e.schema));for(let n=0;n<t;){let r=Math.min(t-n,bx-l);for(let t=0;t<r;t++)s[l+t]=+e.t[n+t]+d-f;if(a!==void 0)for(let t=0;t<r;t++)c[a][l+t]=+e.t[n+t];for(let[t,a]of Object.entries(e.columns)){let e=t===`ElapsedTime`?void 0:i.get(t);if(e===void 0)continue;let o=c[e];if(a instanceof Float64Array||a instanceof Float32Array)o.set(a.subarray(n,n+r),l);else for(let e=0;e<r;e++)o[l+e]=+a[n+e]}l+=r,n+=r,l===bx&&(yield p())}}for await(let t of kx(e.files,e.io,n,e.signal))d=t.shift,yield*_(t.b);l>0&&(yield p())}};async function*kx(e,t,n,r){let i=0,a=-1/0,o=0,s=n?Ex(e,t,{lost:0,t0:null},!0):null,c=async()=>{for(let e=await s?.next();e&&!e.done;e=await s.next())if(e.value.t.length)return e.value;return null},l=await c();for await(let s of Ex(e,t,{lost:0,t0:null},n?!1:void 0)){if(r?.aborted)return;let e=s.t.length;if(e!==0){for(+s.t[0]+i<a&&(i=a+Math.max(0,(s.at-o)/1e3)-+s.t[0]),o=s.at;l&&+l.t[0]<+s.t[0];l=await c())yield{b:l,shift:i};yield{b:s,shift:i},a=+s.t[e-1]+i}}for(;l&&!r?.aborted;l=await c())yield{b:l,shift:i}}const Ax={mdf:en,edf:sn,xdf:xn,tdms:Ln,hdf5:dr,mat:Fr,comtrade:Wr,mseed:Fd,ulog:Yd,mcap:fm,pqdif:sh,ch10:oa,iena:_u,ccsds:vd,parquet:Jy,xlsx:ob,longtext:db,krc:Ox};function jx(e){let t=Ax[e];if(!t)throw Error(`No importer for format ${e}.`);return t}const Mx=`This file's groups do not interleave in time: reading them together would hold too much in memory. Choose fewer groups, or split them.`,Nx=e=>e.length*(1+e.columns.length);function Px(e){let t=e[Symbol.asyncIterator]();return{pull:async()=>{let e=await t.next();return e.done?null:e.value}}}function Fx(e,t){let n=Array.from({length:t.size},()=>[]),r=!1,i=0,a=async a=>{for(;;){if(n[a].length){let e=n[a].shift();return i-=Nx(e),e}if(r)return null;let o=await e.next();if(o.done){r=!0;continue}let s=t.get(o.value.group);if(s!==void 0&&(n[s].push(o.value),(i+=Nx(o.value))>128e6))throw Error(Mx)}};return n.map((e,t)=>({pull:()=>a(t)}))}function Ix(e,t){if(e.time)return e.time;let n=new Float64Array(e.length);if(t.time.kind===`rate`){let{rate:r,start:i}=t.time;for(let t=0;t<e.length;t++)n[t]=i+(e.start+t)/r}else for(let t=0;t<e.length;t++)n[t]=e.start+t;return n}const Lx=new Int32Array,Rx={t:new Float64Array,cols:[],from:0};function zx(e,t,n,r){let i=n,a=r;for(;i<a;){let n=i+a>>>1;e[n]<=t?i=n+1:a=n}return i}var Bx=class{group;channels;feed;pending=[];done=!1;last;scratch=[];#e=-1/0;constructor(e,t,n){this.group=e,this.channels=t,this.feed=n,this.last=t.map(e=>e.text?null:NaN)}rows(){let e=0;for(let t of this.pending)e+=t.t.length-t.from;return e}lastTime(){let e=this.pending[this.pending.length-1];return e&&e.t.length>e.from?e.t[e.t.length-1]:-1/0}async fill(){let e=await this.feed.pull();if(!e){this.done=!0;return}if(e.length===0)return;let t=Vx(Ix(e,this.group),this.#e);if(t.length&&(this.#e=t[t.length-1]),this.pending.push({t,cols:e.columns,from:0}),this.rows()*(1+this.channels.length)>128e6)throw Error(Mx)}};function Vx(e,t){let n=t,r=0;for(;r<e.length;r++){let t=e[r];if(!(t>=n&&t>-1/0&&t<1/0))break;n=t}if(r===e.length)return e;for(n===-1/0&&(n=0);r<e.length;r++){let t=e[r];t>=n&&t<1/0?n=t:e[r]=n}return e}function Hx(e,t){let n=e.length,r=e.map(e=>e.t),i=Int32Array.from(e,e=>e.from),a=Int32Array.from(e,e=>zx(e.t,t,e.from,e.t.length));if(n===1)return r[0].subarray(i[0],a[0]);let o=0;for(let e=0;e<n;e++)o+=a[e]-i[e];let s=new Float64Array(o),c=0;for(;;){let e=1/0;for(let t=0;t<n;t++)i[t]<a[t]&&r[t][i[t]]<e&&(e=r[t][i[t]]);if(e===1/0)break;s[c++]=e;for(let t=0;t<n;t++){let n=r[t],o=a[t],s=i[t];for(;s<o&&n[s]===e;)s++;i[t]=s}}return s.subarray(0,c)}function Ux(e,t,n,r,i,a){if(i-r>8)e.set(t.subarray(n+r,n+i),a);else for(let o=r;o<i;o++)e[a+o-r]=t[n+o]}function Wx(e,t,n,r,i,a){let o=0;for(let s=0;s<n.length;s++){let c=n[s],l=c.length;if(l===0)continue;let u=i[s].from,d=i[s].cols[a];e.fill(t,o,c[0]);let f=r[s],p=0;for(let t=0;t<f.length;t++){let n=f[t];Ux(e,d,u,p,n,c[p]);let r=c[n],i=c[n+1],a=d[u+n];if(i-r>16)e.fill(a,r,i);else for(let t=r;t<i;t++)e[t]=a;p=n+1}Ux(e,d,u,p,l-1,c[p]),o=c[l-1],t=d[u+l-1]}e.fill(t,o,e.length)}function Gx(e,t,n,r,i){let a=0;for(let o=0;o<n.length;o++){let s=n[o],c=s.length;if(c===0)continue;let l=r[o].from,u=r[o].cols[i];e.fill(t,a,s[0]);for(let t=0;t<c-1;t++)e.fill(u[l+t],s[t],s[t+1]);a=s[c-1],t=u[l+c-1]}e.fill(t,a,e.length)}function Kx(e,t,n,r,i){let a=n.length,o=null,s=0;for(let c=0;c<i.length;c++){let l=e[t+c],u=r;if(n[r]<l){let e=r,t=1;for(;e+t<a&&n[e+t]<l;)e+=t,t*=2;let i=Math.min(e+t,a-1);for(;i-e>1;){let t=e+i>>>1;n[t]<l?e=t:i=t}r=i}i[c]=r,c>0&&r!==u+1&&((o??=new Int32Array(i.length-1))[s++]=c-1)}return o?o.subarray(0,s):Lx}function qx(e,t,n,r,i){let a=t.length;if(r){let t=e.pending[0],n=t.from+a,r=t.cols.map(e=>e instanceof Float64Array?e.subarray(t.from,n):e.slice(t.from,n));if(a>0)for(let i=0;i<r.length;i++)e.last[i]=t.cols[i][n-1];return e.pending=n<t.t.length?[{...t,from:n}]:[],r}let o=e.pending,s=[],c=[];if(a>0){let e=t[a-1],n=0;for(let r of o){let i=r.t,a=zx(i,e,r.from,i.length),o=new Int32Array(a-r.from);if(c.push(Kx(i,r.from,t,n,o)),o.length&&(n=o[o.length-1]),s.push(o),a<i.length)break}}let l=e.channels.map((r,l)=>{if(r.sparse&&n){let e=r.text?Array(a).fill(null):new Float64Array(a).fill(NaN);for(let n=0;n<s.length;n++){let r=s[n],{t:i,from:c}=o[n],u=o[n].cols[l];for(let n=0;n<r.length;n++){let o=r[n];o<a&&t[o]===i[c+n]&&(e[o]=u[c+n])}}return e}if(r.text){let t=Array(a);return Gx(t,e.last[l],s,o,l),t}let u;return i?(e.scratch[l]?.length>=a||(e.scratch[l]=new Float64Array(a)),u=e.scratch[l].subarray(0,a)):u=new Float64Array(a),Wx(u,e.last[l],s,c,o,l),u}),u=[];for(let t=0;t<o.length;t++){let n=o[t],r=t<s.length?s[t].length:0;if(r>0)for(let t=0;t<e.channels.length;t++)e.last[t]=n.cols[t][n.from+r-1];n.from+r<n.t.length&&u.push(r?{...n,from:n.from+r}:n)}return e.pending=u,l}async function Jx(e,t,n,r,i,a=!1){let o=e.map((e,r)=>new Bx(e,t[r],n[r])),s=-1;e.forEach((t,n)=>{!t.irregular&&(s<0||t.samples>e[s].samples)&&(s=n)});let c=e.map((e,t)=>t===s||!!e.irregular),l=o.filter((e,t)=>c[t]),u=l.length===1,d=0;for(;;){i?.throwIfAborted();for(let e of l)for(;!e.done&&e.rows()===0;)await e.fill();if(l.every(e=>e.rows()===0)){let e=o.filter((e,t)=>!c[t]&&(!e.done||e.rows()>0));if(!e.length)break;for(let t of e)c[o.indexOf(t)]=!0,l.push(t);u=!1;continue}let e=1/0;for(let t of l)t.done||(e=Math.min(e,t.lastTime()));for(let t=0;t<o.length;t++)if(!c[t])for(;!o[t].done&&o[t].lastTime()<=e;)await o[t].fill();let t=Hx(l.map(e=>e.pending[0]??Rx),e),n=[t];for(let e=0;e<o.length;e++)n.push(...qx(o[e],t,c[e],u&&c[e],a));d+=t.length,t.length&&await r({length:t.length,columns:n})}return d}var Yx=class{#e;#t;#n;#r=0;constructor(e,t){let n=Math.max(1024,t);this.#e=e.map(e=>e.name),this.#t=e.map(()=>new Float64Array(n)),this.#n=e.map(()=>null)}append(e){let t=this.#r,n=t+e.length;if(n>this.#t[0].length){let e=Math.max(n,Math.ceil(this.#t[0].length*1.5));this.#t=this.#t.map(n=>{let r=new Float64Array(e);return r.set(n.subarray(0,t)),r})}e.columns.forEach((n,r)=>{let i=this.#t[r];if(n instanceof Float64Array){i.set(n.subarray(0,e.length),t);return}let a=this.#n[r];for(let o=0;o<e.length;o++){i[t+o]=NaN;let e=n[o];e!=null&&((a??=this.#n[r]=[])[t+o]=e)}}),this.#r=n}table(){let e=this.#r,t=this.#t.map(t=>t.length-e>t.length/100?t.slice(0,e):t.subarray(0,e));return{keys:this.#e,length:e,values:t,text:this.#n}}};async function Xx(e,t,n){return O(await e.plan(t,n))}const Zx=(e,t,n)=>Math.max(0,Math.min(e,Math.max(1<<20,n),Math.floor(1e8/t)));function Qx(e,t){let n=t.flatMap(t=>t.channels.map(n=>({ch:e.groups[t.group].channels[n],group:e.groups[t.group].name}))),r=new Map;for(let{ch:e}of n)r.set(e.name.toLowerCase(),(r.get(e.name.toLowerCase())??0)+1);let i=cn(n.map(({ch:e,group:n})=>t.length>1&&r.get(e.name.toLowerCase())>1?`${e.name} [${n}]`:e.name));return[{name:`Time`,unit:t.every(t=>e.groups[t.group].time.kind===`index`)?``:`s`,text:!1},...n.map(({ch:e},t)=>({name:i[t],unit:e.unit,text:!!e.text}))]}function $x(e,t){let n=t.map(t=>e.groups[t.group]);if(n.some(e=>e.samples<0))return-1;let r=0,i=0;for(let e of n)e.irregular?i+=e.samples:r=Math.max(r,e.samples);return r+i}async function eS(e,t,n,r,i,a,o={}){let s=Qx(n,i),c=i.map(e=>n.groups[e.group]),l=i.map(e=>e.channels.map(t=>n.groups[e.group].channels[t])),u=[...n.events];async function*d(e){for await(let t of e)t.events&&u.push(...t.events),yield t}let f={files:t,plan:n,io:r,selection:i,signal:o.signal},p=e.streamGroup&&i.length>1&&!n.interleaved?i.map(t=>Px(d(e.streamGroup({...f,selection:[t]},t.group)))):Fx(d(e.stream(f)),new Map(i.map((e,t)=>[e.group,t]))),m=$x(n,i),h=a===`memory`?new Yx(s,Zx(m,s.length,r.size)):null,g=0,_=await Jx(c,l,p,async e=>{h?h.append(e):await o.chunk(e);let t=Date.now();o.progress&&t-g>100&&(g=t,o.progress(Math.min(.99,r.bytesRead/Math.max(1,r.size))))},o.signal,!!h);return o.progress?.(1),u.sort((e,t)=>e.time-t.time),{columns:s,rows:_,table:h?.table(),events:u}}function tS(e){let t=new Set,n=e.columns.map(e=>{if(!(e instanceof Float64Array))return e;let n=e.byteOffset===0&&e.byteLength===e.buffer.byteLength&&!t.has(e.buffer)?e:e.slice();return t.add(n.buffer),n});return[{length:e.length,columns:n},[...t]]}function nS(e,t=jx){let n=null,i=null,a=null,o=null,s=2,c=null;return async l=>{if(l.type===`ack`){s++;let e=c;c=null,e?.();return}if(l.type===`warm`){Xn();return}let u=setInterval(()=>e({type:`alive`,work:a?.bytesRead??0}),1e3);try{if(l.type===`plan`){n=t(l.importer),i=l.files,a=new r(i.main),o=await Xx(n,i,a),e({type:`plan`,plan:{...o,state:void 0}});return}a.bytesRead=0;let u=await eS(n,i,o,a,l.selection,l.mode,{progress:t=>e({type:`progress`,fraction:t}),chunk:async t=>{for(;s===0;)await new Promise(e=>{c=e});s--;let[n,r]=tS(t);e({type:`chunk`,chunk:n},r)}});e({type:`done`,result:u},u.table?Gb(u.table):[])}catch(t){e({type:`error`,message:k(t).message})}finally{clearInterval(u)}}}const rS=self;let iS=null;Jn(async()=>{if(!iS)throw Error(`The import worker was not told where the HDF5 reader is.`);await import(iS);let e=globalThis.__kymoscopeH5wasm;if(!e)throw Error(`HDF5 reader failed to load.`);let{FS:t}=await e.ready,n=0;return async r=>{let i=`/kymo${++n}`;t.mkdir(i),t.mount(t.filesystems.WORKERFS,{files:[r]},i);try{let n=new e.File(`${i}/${r.name}`,`r`);return{root:n,close:()=>{n.close(),t.unmount(i),t.rmdir(i)}}}catch(e){throw t.unmount(i),t.rmdir(i),e}}});const aS=nS((e,t)=>rS.postMessage(e,t??[]));rS.onmessage=e=>{e.data.type===`init`?iS=e.data.h5Url:aS(e.data)};