function e(e,n,r){return(n=t(n))in e?Object.defineProperty(e,n,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[n]=r,e}function t(e){var t=n(e,`string`);return typeof t==`symbol`?t:t+``}function n(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}import{t as r}from"./chunk/Log.js";import{t as i}from"./chunk/units.js";var a=class{constructor(){e(this,`fields`,new Map)}},o;(function(e){e[e.INT=0]=`INT`,e[e.LONG=1]=`LONG`,e[e.DOUBLE=2]=`DOUBLE`,e[e.STRING=3]=`STRING`,e[e.BOOLEAN=4]=`BOOLEAN`})(o||={});var s=class{constructor(){e(this,`constants`,[])}},c=class{constructor(t){e(this,`schema`,void 0),this.schema=t}},l=class{constructor(){e(this,`SUPPORTED_LOG_REVISIONS`,[0,1]),e(this,`STRING_DECODER`,new TextDecoder(`UTF-8`)),e(this,`magic`,null),e(this,`logRevision`,null),e(this,`firstRRTimestamp`,null),e(this,`lastTimestamp`,0),e(this,`lastProgressTimestamp`,0),e(this,`keyIDs`,{}),e(this,`keySchemas`,{})}decode(e,t,n){let r=new DataView(t.buffer),l=0;function u(e){return(l+=e)-e}let d=()=>{let e=r.getInt32(u(4)),n=this.STRING_DECODER.decode(t.subarray(l,l+e));return l+=e,n};function f(){let e=r.getInt32(u(4));if(e===0){let e=new a,t=r.getInt32(u(4));for(let n=0;n<t;n++)e.fields.set(d(),f());return e}else if(e===1)return o.INT;else if(e===2)return o.LONG;else if(e===3)return o.DOUBLE;else if(e===4)return o.STRING;else if(e===5)return o.BOOLEAN;else if(e===6){let e=new s,t=r.getInt32(u(4));for(let n=0;n<t;n++)e.constants.push(d());return e}else if(e===7)return new c(f());else throw`Unknown schema type: `+e}function p(e){if(e instanceof a){let t=0;for(let n of e.fields.entries())t+=p(n[1]);return t}else if(e instanceof c)return 1+p(e.schema);else return 0}function m(e){if(e instanceof a){let t=new Map;for(let[n,r]of e.fields.entries())t.set(n,m(r));return t}else if(e===o.INT)return r.getInt32(u(4));else if(e===o.LONG)return r.getBigInt64(u(8));else if(e===o.DOUBLE)return r.getFloat64(u(8));else if(e===o.STRING)return d();else if(e===o.BOOLEAN)return t[u(1)]!==0;else if(e instanceof s){let t=r.getInt32(u(4));return e.constants[t]}else if(e instanceof c){let t=r.getInt32(u(4)),n=[];for(let r=0;r<t;++r)n.push(m(e.schema));return n}else throw`Unknown schema type: `+e}let h=e=>(this.firstRRTimestamp===null&&(this.firstRRTimestamp=e),Number(e-this.firstRRTimestamp)/1e9);try{if(this.magic===null&&(this.magic=this.STRING_DECODER.decode(t.subarray(l,l+2)),u(2),this.magic!==`RR`)||this.logRevision===null&&(this.logRevision=r.getInt16(u(2)),!this.SUPPORTED_LOG_REVISIONS.includes(this.logRevision)))return!1;for(;;){if(this.STRING_DECODER.decode(t.subarray(l,l+2))===`RR`){if(u(2),this.logRevision=r.getInt16(u(2)),!this.SUPPORTED_LOG_REVISIONS.includes(this.logRevision))return!1;this.keyIDs={},this.keySchemas={}}let a;try{if(a=r.getInt32(u(4)),a===void 0)break;let t;switch(a){case 0:t=Object.keys(this.keyIDs).length,this.keyIDs[t]=d();let n=f();this.keySchemas[t]=n,this.logRevision===0&&u(4*p(n));break;case 1:t=r.getInt32(u(4));let a=this.keyIDs[t],o=this.keySchemas[t],s=m(o);if((a===`OPMODE_PRE_INIT`||a===`OPMODE_PRE_START`||a===`OPMODE_POST_STOP`||a===`TIMESTAMP`)&&typeof s==`bigint`)this.lastTimestamp=h(s),a===`OPMODE_PRE_START`?e.putBoolean(`RUNNING`,this.lastTimestamp+.05,!0):a===`OPMODE_POST_STOP`&&e.putBoolean(`RUNNING`,this.lastTimestamp,!1);else if(s instanceof Map&&s.has(`timestamp`)){let e=s.get(`timestamp`);e!==void 0&&typeof e==`bigint`&&(this.lastTimestamp=h(e))}let c=this.lastTimestamp;switch(typeof s){case`boolean`:e.putBoolean(a,c,s);break;case`number`:e.putNumber(a,c,s);break;case`bigint`:e.putNumber(a,c,Number(s));break;case`string`:e.putString(a,c,s);break;default:s instanceof Map&&s.has(`x`)&&s.has(`y`)&&s.has(`heading`)?e.putPose(a,c,{translation:[i.convert(s.get(`x`),`inches`,`meters`),i.convert(s.get(`y`),`inches`,`meters`)],rotation:s.get(`heading`)}):e.putUnknownStruct(a,c,s,!0);break}break}}catch(e){if(e instanceof RangeError&&e.message===`Offset is outside the bounds of the DataView`)break;return console.error(e),!1}if(n!==void 0){let e=new Date().getTime();e-this.lastProgressTimestamp>1e3/60&&(this.lastProgressTimestamp=e,n(l/r.byteLength))}}return!0}catch(e){return console.error(e),!1}}};function u(e){self.postMessage(e)}self.onmessage=async e=>{let t=e.data;if(t.type!==`start`)return;let n=e=>{u({type:`progress`,value:e})},i=new r(!1);new l().decode(i,t.data[0],n)?(n(1),u({type:`initial`,log:i.toSerialized(),isPartial:!1})):u({type:`failed`})};