@kymoscope/sdk 0.14.0 → 0.14.2
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.
- package/dist/assets/liveIngestWorker-w4p7hYsW.js +1 -0
- package/dist/{importers-f62zcRz2.js → importers-BLvbdEJq.js} +1 -1
- package/dist/{keys-CdXDP3WJ.js → keys-G_-WLyNR.js} +1 -1
- package/dist/kymoscope-embed.js +53 -53
- package/dist/kymoscope-sdk.js +57 -57
- package/dist/types/components/GaugeChart.d.ts +1 -0
- package/dist/types/components/MultiBandCanvasChart.d.ts +2 -0
- package/dist/types/components/liveFollowEase.d.ts +6 -0
- package/dist/types/components/liveWindow.d.ts +29 -2
- package/dist/types/lib/data/liveDataSource.d.ts +2 -0
- package/dist/types/lib/live/buffer.d.ts +3 -0
- package/dist/types/lib/render/frames.d.ts +2 -1
- package/package.json +1 -1
- package/dist/assets/liveIngestWorker-DQYK0Xxv.js +0 -1
|
@@ -47,6 +47,8 @@ export interface LiveChartSource {
|
|
|
47
47
|
* of in a step per received message. */
|
|
48
48
|
latestT?: () => number;
|
|
49
49
|
xAtTime?: (t: number) => number;
|
|
50
|
+
/** Time of the oldest sample after a time: lets the playout tell late data from a sender that paused. */
|
|
51
|
+
timeAfter?: (t: number) => number;
|
|
50
52
|
/** The stream's id: charts showing the same stream share one playout (see streamPlayout), so they show one instant. */
|
|
51
53
|
id?: string;
|
|
52
54
|
}
|
|
@@ -8,3 +8,9 @@
|
|
|
8
8
|
* gap shrinks by 1/e every `tauMs` of real time.
|
|
9
9
|
*/
|
|
10
10
|
export declare function followEaseFactor(dtMs: number, tauMs: number): number;
|
|
11
|
+
/**
|
|
12
|
+
* One frame of the live window following its target: the target's own small step (the edge scrolling, under `carry`
|
|
13
|
+
* of the span) moves the value with it, the rest is eased by `k` (followEaseFactor). Easing alone kept a steadily
|
|
14
|
+
* moving target `tauMs` behind; carried, the window sits on it while a jump (a new window length) still glides.
|
|
15
|
+
*/
|
|
16
|
+
export declare function followStep(value: number, target: number, prevTarget: number | null, k: number, span: number, carry: number): number;
|
|
@@ -66,11 +66,38 @@ export interface Playout {
|
|
|
66
66
|
wait: number;
|
|
67
67
|
/** Seconds since `wait` last grew. */
|
|
68
68
|
waitAge: number;
|
|
69
|
+
/** The data time one message usually adds (a running mean; NaN until two have come): how far behind the newest a
|
|
70
|
+
* live trace is revealed, so a message's samples appear continuously instead of all at once. */
|
|
71
|
+
gap: number;
|
|
69
72
|
}
|
|
70
73
|
/** Seeded with `wait`: a stream's waits already learned (a chart opened on a stream others showed starts steady). */
|
|
71
74
|
export declare function createPlayout(wait?: number): Playout;
|
|
72
75
|
/** The display time of stream `id` given its newest sample time `t`, advanced once per frame (`now`: ms, a clock
|
|
73
76
|
* shared by every window, performance.now) however many charts ask in it. */
|
|
74
|
-
export declare function streamPlayout(id: string, t: number, now: number): number;
|
|
77
|
+
export declare function streamPlayout(id: string, t: number, now: number, firstAfter?: (t: number) => number): number;
|
|
78
|
+
/** The stream playout advanced most recently, for the perf HUD: its newest sample time, how far the drawn edge is
|
|
79
|
+
* behind it, and the lateness it learned (`wait`, `waitAge` seconds ago). null before any live chart draws. */
|
|
80
|
+
export declare function playoutStats(): {
|
|
81
|
+
newest: number;
|
|
82
|
+
lag: number;
|
|
83
|
+
wait: number;
|
|
84
|
+
waitAge: number;
|
|
85
|
+
} | null;
|
|
86
|
+
/** The lag the playout keeps behind the data's freshest (the waits it learned). */
|
|
87
|
+
export declare function playoutLead(p: Playout): number;
|
|
88
|
+
/** How far behind the data's now a live trace is revealed: one message's worth (playout `gap`), so each message's
|
|
89
|
+
* samples come in continuously, never more than the lead. */
|
|
90
|
+
export declare function playoutReveal(p: Playout): number;
|
|
91
|
+
/** {@link playoutReveal} of stream `id`'s shared playout (0 before it has one). */
|
|
92
|
+
export declare function streamReveal(id: string): number;
|
|
93
|
+
/** {@link playoutLead} of stream `id`'s shared playout (0 before it has one). */
|
|
94
|
+
export declare function streamLead(id: string): number;
|
|
95
|
+
/**
|
|
96
|
+
* X of a live window's right edge: the X at display time `d` carried `lead` seconds on, at the rate X moves there.
|
|
97
|
+
* The edge then sits at the data's "now" and still moves smoothly with the playout, so every sample shows the moment
|
|
98
|
+
* it arrives (the legend's value and the trace agree) instead of `lead` seconds later. Time X: `d + lead`; lap
|
|
99
|
+
* distance: on by the current speed; a wrap (X going back): not carried.
|
|
100
|
+
*/
|
|
101
|
+
export declare function liveEdgeX(xAt: (t: number) => number, d: number, lead: number): number;
|
|
75
102
|
/** Advance `p` one frame (`dtMs`, the real time since the last frame) given the newest sample time `t`; the display time. */
|
|
76
|
-
export declare function advancePlayout(p: Playout, t: number, dtMs: number): number;
|
|
103
|
+
export declare function advancePlayout(p: Playout, t: number, dtMs: number, firstAfter?: (t: number) => number): number;
|
|
@@ -55,6 +55,8 @@ export declare class LiveDataSource implements DataSource {
|
|
|
55
55
|
};
|
|
56
56
|
/** X distance covered by the newest `seconds` of samples (see LiveBuffer.xTravel). */
|
|
57
57
|
xTravelSync(column: string, seconds: number): number;
|
|
58
|
+
/** Time of the oldest sample after `t` (see LiveBuffer.timeAfter). */
|
|
59
|
+
timeAfterSync(t: number): number;
|
|
58
60
|
/** Time of the newest sample (NaN if empty). */
|
|
59
61
|
latestTimeSync(): number;
|
|
60
62
|
/** Value of `column` at time `t` (see LiveBuffer.xAtTime). */
|
|
@@ -275,6 +275,9 @@ export declare class LiveBuffer {
|
|
|
275
275
|
* is `seconds` itself. NaN with fewer than two samples.
|
|
276
276
|
*/
|
|
277
277
|
xTravel(key: string, seconds: number): number;
|
|
278
|
+
/** Time of the oldest sample after `t` (NaN if none, or the time column steps back): where the samples that came
|
|
279
|
+
* since `t` was the newest begin (the live playout's lateness, see advancePlayout). */
|
|
280
|
+
timeAfter(t: number): number;
|
|
278
281
|
/** Time of the newest sample (NaN if empty): the latest time buffered, not the last pushed, as an OPC UA
|
|
279
282
|
* server delivers some tags' samples in a later message than other tags' newer ones. */
|
|
280
283
|
latestTime(): number;
|
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
*/
|
|
8
8
|
export declare function addFrameWindow(w: Window): void;
|
|
9
9
|
export declare function removeFrameWindow(w: Window): void;
|
|
10
|
-
/** requestAnimationFrame from whichever open window paints first; the callback runs once
|
|
10
|
+
/** requestAnimationFrame from whichever open window paints first; the callback runs once, with the frame time on the
|
|
11
|
+
* main window's clock (performance.now()'s) whichever window it was. */
|
|
11
12
|
export declare function raf(cb: FrameRequestCallback): number;
|
|
12
13
|
export declare function cancelRaf(handle: number | null | undefined): void;
|
|
13
14
|
/** Count one frame whose drawn picture changed (data or view), for the perf HUD. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kymoscope/sdk",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.2",
|
|
4
4
|
"description": "The Kymoscope data engine and charts for the browser: import large measurement files, plot them, stream live data end-to-end encrypted.",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
6
6
|
"homepage": "https://kymoscope.com/docs/introduction",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const e=e=>e.startsWith(`eyJ`);function t(e){try{let t=e.split(`.`)[1]??``,n=atob(t.replace(/-/g,`+`).replace(/_/g,`/`)+`===`.slice((t.length+3)%4)),r=JSON.parse(n).exp;return typeof r==`number`?r:null}catch{return null}}function n(e,t){return`${e.replace(/\/+$/,``)}/v1/streams/${t}/watch`}function r(r,i,a,o){let s=null,c=null,l=null,u=!1,d=0,f=()=>{l&&=(clearTimeout(l),null)},p=(n,a)=>{f();let o=t(a);if(o===null)return;let c=e(a),d=c?Math.min(o,Date.now()/1e3+300):o,m=Math.min(Math.max((d-(c?90:30))*1e3-Date.now(),1e4),2**31-1);l=setTimeout(async()=>{l=null;let e=null;try{e=await r.getToken(i)}catch{e=null}if(!(u||s!==n||!e)){try{n.send(JSON.stringify({type:`auth`,token:e}))}catch{return}p(n,e)}},m)},m=()=>{if(u||c)return;let e=Math.min(3e4,2e3*2**d++)*(.75+Math.random()/2);c=setTimeout(()=>{c=null,h()},e)},h=async()=>{if(u)return;let e=null;try{e=await r.getToken(i)}catch{e=null}if(u)return;if(!e){o?.(`error`),m();return}let t=new WebSocket(n(r.url,i),[`kymoscope-live.v1`,`kymoscope-live.ack1`,`kymoscope-live.ack2`,`bearer.${e}`]);t.binaryType=`arraybuffer`,s=t;let c=e,l=0,h=setInterval(()=>{if(!(l===0||t.readyState!==1)){try{t.send(JSON.stringify({type:`ack`,b:l}))}catch{return}l=0}},1e3);t.onopen=()=>{o?.(`subscribed`),p(t,c)},t.onmessage=e=>{if(d=0,typeof e.data!=`string`){l+=e.data.byteLength,a(e.data);return}if(e.data.startsWith(`{"type":"probe"`))try{let n=JSON.parse(e.data).id;typeof n==`string`&&n.length<=64&&t.send(JSON.stringify({type:`ack`,id:n}))}catch{}},t.onclose=()=>{clearInterval(h),s===t&&(s=null,f(),!u&&(o?.(`error`),m()))}};return h(),()=>{if(u=!0,c&&=(clearTimeout(c),null),f(),s){let e=s;s=null,e.close(1e3)}}}new TextEncoder;function i(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 a=new TextDecoder;function o(e,t,n){let r=e.subarray(t,t+n);return a.decode(r)}function s(e,t,n){return n>200?o(e,t,n):i(e,t,n)}var c=class{type;data;constructor(e,t){this.type=e,this.data=t}},l=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 u(e,t,n){let r=Math.floor(n/4294967296),i=n;e.setUint32(t,r),e.setUint32(t+4,i)}function d(e,t){let n=e.getInt32(t),r=e.getUint32(t+4);return n*4294967296+r}function f(e,t){let n=e.getUint32(t),r=e.getUint32(t+4);return n*4294967296+r}function p({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),u(r,4,e),n}}function m(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 h(e){return e instanceof Date?p(m(e)):null}function g(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:d(t,4),nsec:t.getUint32(0)};default:throw new l(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${e.length}`)}}function _(e){let t=g(e);return new Date(t.sec*1e3+t.nsec/1e6)}const ee={type:-1,encode:h,decode:_};var v=class e{static defaultCodec=new e;__brand;builtInEncoders=[];builtInDecoders=[];encoders=[];decoders=[];constructor(){this.register(ee)}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 c(-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 c(n,i)}}return e instanceof c?e:null}decode(e,t,n){let r=t<0?this.builtInDecoders[-1-t]:this.decoders[t];return r?r(e,t,n):new c(t,e)}};function y(e){return e instanceof ArrayBuffer||typeof SharedArrayBuffer<`u`&&e instanceof SharedArrayBuffer}function b(e){return e instanceof Uint8Array?e:ArrayBuffer.isView(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):y(e)?new Uint8Array(e):Uint8Array.from(e)}function x(e){return`${e<0?`-`:``}0x${Math.abs(e).toString(16).padStart(2,`0`)}`}var te=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 a=i(e,t,n),o=Uint8Array.prototype.slice.call(e,t,t+n);return this.store(o,a),a}};const S=`array`,C=`map_key`,w=`map_value`,T=e=>{if(typeof e==`string`||typeof e==`number`)return e;throw new l(`The type of key must be string or number but `+typeof e)};var E=class{stack=[];stackHeadPosition=-1;get length(){return this.stackHeadPosition+1}top(){return this.stack[this.stackHeadPosition]}pushArrayState(e){let t=this.getUninitializedStateFromPool();t.type=S,t.position=0,t.size=e,t.array=Array(e)}pushMapState(e){let t=this.getUninitializedStateFromPool();t.type=C,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===S){let t=e;t.size=0,t.array=void 0,t.position=0,t.type=void 0}if(e.type===C||e.type===w){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 D=new DataView(new ArrayBuffer(0)),ne=new Uint8Array(D.buffer);try{D.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 O=RangeError(`Insufficient data`),re=new te;var ie=class e{extensionCodec;context;useBigInt64;rawStrings;maxStrLength;maxBinLength;maxArrayLength;maxMapLength;maxExtLength;keyDecoder;mapKeyConverter;totalPos=0;pos=0;view=D;bytes=ne;headByte=-1;stack=new E;entered=!1;constructor(e){this.extensionCodec=e?.extensionCodec??v.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?re:e.keyDecoder,this.mapKeyConverter=e?.mapKeyConverter??T}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=b(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=b(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 ${x(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 l(`Unrecognized type byte: ${x(e)}`);this.complete();let n=this.stack;for(;n.length>0;){let e=n.top();if(e.type===S)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===C){if(t===`__proto__`)throw new l(`The key __proto__ is not allowed`);e.key=this.mapKeyConverter(t),e.type=w;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=C;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 l(`Unrecognized array type byte: ${x(e)}`)}}pushMapState(e){if(e>this.maxMapLength)throw new l(`Max length exceeded: map length (${e}) > maxMapLengthLength (${this.maxMapLength})`);this.stack.pushMapState(e)}pushArrayState(e){if(e>this.maxArrayLength)throw new l(`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 l(`Max length exceeded: UTF-8 byte length (${e}) > maxStrLength (${this.maxStrLength})`);if(this.bytes.byteLength<this.pos+t+e)throw O;let n=this.pos+t,r;return r=this.stateIsMapKey()&&this.keyDecoder?.canBeCached(e)?this.keyDecoder.decode(this.bytes,n,e):s(this.bytes,n,e),this.pos+=t+e,r}stateIsMapKey(){return this.stack.length>0?this.stack.top().type===C:!1}decodeBinary(e,t){if(e>this.maxBinLength)throw new l(`Max length exceeded: bin length (${e}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining(e+t))throw O;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 l(`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=f(this.view,this.pos);return this.pos+=8,e}readI64(){let e=d(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 k(e,t){return new ie(t).decode(e)}function A(){let e=globalThis.crypto;if(!e?.subtle)throw Error(`WebCrypto SubtleCrypto is not available`);return e.subtle}async function j(e,t,n,r){let i=await A().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`);function M(e){let t=new Uint8Array(e),n=t.length>0&&t[0]&128?2:1;return t.length<n+12+16?null:{kind:t[0]&-129,keyId:n===2?t[1]:null,iv:t.subarray(n,n+12),ciphertext:t.subarray(n+12),aad:t.subarray(0,n)}}async function N(e,t){let n=M(t);if(!n)return null;let r=typeof e==`function`?await e(n.keyId):e;if(!r)return null;let i=await j(r,n.iv,n.ciphertext,n.aad);return{kind:n.kind,plaintext:i}}const P=e=>e+7&-8;function F(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=P(s),s+P(i*8)+o.reduce((e,t)=>e+P(i*t.size),0)>e.byteLength)throw t(`short data`);let c=e.byteOffset,l=new Float64Array(e.buffer,c+s,i);s+=P(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+=P(i*t.size);return{t:l,columns:u,units:d}}function I(e){if(e.length<24||e[0]!==1||e[2]!==1)return null;let t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=(e[1]&1)!=0,r=t.getUint16(16,!0),i=t.getUint16(18,!0);if(i===0||r>=i)return null;let a=24,o=``;if(n&&r===0){if(e.length<a+1||e.length<a+1+e[a])return null;o=new TextDecoder().decode(e.subarray(a+1,a+1+e[a])),a+=1+e[a]}return{key:n,last:(e[1]&2)!=0,t:t.getFloat64(4,!0),seq:t.getUint32(12,!0),fragIndex:r,fragCount:i,width:t.getUint16(20,!0),height:t.getUint16(22,!0),codec:o,payload:e.subarray(a)}}const L=(e,t)=>RangeError(`${e}: ${t}`);function R(e){if(e.byteLength<8)throw L(`block schema`,`short`);let t=new DataView(e.buffer,e.byteOffset,e.byteLength);if(t.getUint8(0)!==2)throw L(`block schema`,`version ${t.getUint8(0)}`);let n=t.getUint16(2,!0),r=t.getUint32(4,!0),i=new TextDecoder(`utf-8`,{fatal:!0}),a=[],o=8;try{for(let r=0;r<n;r++){if(o+3>e.byteLength)throw L(`block schema`,`short channel table`);let n=t.getUint8(o),r=t.getUint8(o+1),s=t.getUint8(o+2);if(o+=3,n!==4&&n!==8)throw L(`block schema`,`value size ${n}`);if(o+r+s>e.byteLength)throw L(`block schema`,`short channel table`);a.push({name:i.decode(e.subarray(o,o+r)),unit:i.decode(e.subarray(o+r,o+r+s)),size:n}),o+=r+s}}catch(e){throw e instanceof RangeError?e:L(`block schema`,`invalid text`)}return{id:r,channels:a}}function z(e,t){if(e.byteLength<12)throw L(`last values`,`short`);let n=new DataView(e.buffer,e.byteOffset,e.byteLength);if(n.getUint8(0)!==1)throw L(`last values`,`version ${n.getUint8(0)}`);let r=t.get(n.getUint32(4,!0));if(!r)return null;let i=n.getUint32(8,!0);if(i!==r.channels.length)throw L(`last values`,`channel count differs from its schema`);if(e.byteLength<12+16*i)throw L(`last values`,`short`);let a=[];for(let e=0;e<i;e++){let t=n.getFloat64(12+8*e,!0),o=n.getFloat64(12+8*(i+e),!0);Number.isFinite(t)&&Number.isFinite(o)&&a.push({name:r.channels[e].name,unit:r.channels[e].unit,t,v:o})}return a}async function B(e,t){let n=new Blob([e]).stream().pipeThrough(new DecompressionStream(`deflate`)).getReader(),r=new Uint8Array(t),i=0;try{for(;;){let{done:e,value:a}=await n.read();if(e)break;if(i+a.length>t)throw L(`block`,`body larger than its header says`);r.set(a,i),i+=a.length}}catch(e){throw await n.cancel().catch(()=>{}),e instanceof RangeError?e:L(`block`,`body is not valid deflate`)}if(i!==t)throw L(`block`,`body size mismatch`);return r}async function V(e,t){if(e.byteLength<20)throw L(`block`,`short`);let n=new DataView(e.buffer,e.byteOffset,e.byteLength);if(n.getUint8(0)!==2)throw L(`block`,`version ${n.getUint8(0)}`);let r=n.getUint8(1),i=n.getUint16(2,!0),a=n.getUint32(4,!0),o=t.get(n.getUint32(8,!0));if(!o)return null;if(o.channels.length!==i)throw L(`block`,`channel count differs from its schema`);let s=n.getFloat64(12,!0),c=Math.max(0,a-1),l=4*c+o.channels.reduce((e,t)=>e+t.size*a,0);if(l>67108864)throw L(`block`,`too large`);let u;if(r&1)u=await B(e.subarray(20),l);else if(u=e.subarray(20),u.byteLength<l)throw L(`block`,`body size mismatch`);let d=new DataView(u.buffer,u.byteOffset,u.byteLength),f=new Float64Array(a),p=0;a&&(f[0]=s);for(let e=1;e<a;e++)p+=d.getInt32(4*(e-1),!0),f[e]=s+p/1e6;let m=4*c,h={},g={};for(let e of o.channels){let t=new Uint8Array(a*e.size);for(let n=0;n<e.size;n++)for(let r=0;r<a;r++)t[r*e.size+n]=u[m+n*a+r];h[e.name]=e.size===4?new Float32Array(t.buffer):new Float64Array(t.buffer),e.unit&&(g[e.name]=e.unit),m+=a*e.size}return{block:{t:f,columns:h,units:g},historical:(r&2)!=0}}const H=e=>Array.from(e,e=>e.toString(16).padStart(2,`0`)).join(``),U=e=>{let t=H(e);return`${t.slice(0,8)}-${t.slice(8,12)}-${t.slice(12,16)}-${t.slice(16,20)}-${t.slice(20)}`};function W(e){if(e.length!==70||e[0]!==1)return null;let t=new DataView(e.buffer,e.byteOffset,e.byteLength);return{streamId:U(e.subarray(1,17)),run:H(e.subarray(17,25)),lane:e[25],seq:t.getBigUint64(26,!0),count:t.getUint32(34,!0),hash:e.slice(38,70)}}const G=()=>globalThis.crypto.subtle,K=e=>G().digest(`SHA-256`,e);async function q(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 K(n))}function J(e,t,n=()=>Date.now()){let r={verified:0,broken:0},i=null,a=0n,o=null,s=0,c=0,l=0,u=Promise.resolve(),d=e=>{e?r.verified++:(r.broken++,r.lastBrokenAt=n()),t({...r})};return{integrity:r,reset(){i=null,o=null,c=s,l++},arrive(t,n,r){if(n!==8){o&&(o.push(K(t)),s++);return}let f=s;o||(o=[],c=s);let p=l;u=u.then(async()=>{let t=await r.catch(()=>null);if(p!==l)return;let n=t?W(t.plaintext):null;if(!n||n.lane!==0||n.streamId!==e.toLowerCase()){i!==null&&d(!1);return}let s=f-c;if(i===null||n.run!==i){i=n.run,a=n.seq,o=o.slice(Math.max(0,s)),c=Math.max(c,f);return}let u=n.seq===a+1n&&n.count<=s&&ae(await q(o.slice(0,n.count)),n.hash);if(p!==l)return;a=n.seq;let m=u?n.count:s;o=o.slice(m),c+=m,d(u)})}}}const ae=(e,t)=>e.length===t.length&&e.every((e,n)=>e===t[n]);function oe(e,t,n){let r=new Map,i=Promise.resolve(),a=n?J(n,e=>t({type:`integrity`,integrity:e})):null;return Object.assign(n=>{let o=N(e,n).catch(()=>null);a?.arrive(n,new Uint8Array(n,0,1)[0]&127,o),i=i.then(async()=>{try{let e=await o;if(!e)return;if(e.kind===6){let n=I(e.plaintext);n&&t({type:`video`,m:n})}else if(e.kind===5){let t=R(e.plaintext);r.set(t.id,t)}else if(e.kind===7){let n=z(e.plaintext,r);n&&t({type:`last`,values:n})}else if(e.kind===4){let n=await V(e.plaintext,r);n&&!n.historical&&t({type:`columns`,block:n.block})}else if(e.kind===3)t({type:`columns`,block:F(e.plaintext)});else if(e.kind===2){let n=k(e.plaintext);t({type:`frames`,frames:Array.isArray(n?.frames)?n.frames:[]})}}catch{}})},{reset:()=>a?.reset()})}function Y(e){if(e.type!==`columns`)return[];let t=new Set,n=e=>{ArrayBuffer.isView(e)&&Object.prototype.toString.call(e.buffer)===`[object ArrayBuffer]`&&t.add(e.buffer)};n(e.block.t);for(let t of Object.values(e.block.columns))n(t);return[...t]}function se(e,t=67108864){let n=0,r=0,i=0;return{emit(a){let o=Y(a).reduce((e,t)=>e+t.byteLength,0);if(a.type===`columns`&&n>0&&n+o>t){r+=a.block.t.length,i+=a.block.t.length;return}a.type===`columns`&&i>0&&(e({type:`gap`,samples:i},0),i=0),n+=o,e(a,o)},ack(e){n=Math.max(0,n-e)},get dropped(){return r}}}let ce=1;const X=new Map,Z=(e,t)=>new Promise(n=>{let r=ce++;X.set(r,n),self.postMessage({type:`ask`,id:r,what:e,arg:t})});let Q=null;const $=se((e,t)=>self.postMessage({type:`decoded`,d:e,bytes:t},Y(e)));self.onmessage=e=>{let t=e.data;if(t.type===`reply`){X.get(t.id)?.(t.value),X.delete(t.id);return}if(t.type===`ack`){$.ack(t.bytes);return}if(t.type===`stop`){Q?.(),Q=null,self.close();return}let n=new Map,i=oe(t.key??(async e=>{let t=n.get(e);if(t)return t;let r=await Z(`key`,e);return r&&n.set(e,r),r}),$.emit,t.streamId);Q=r({url:t.url,getToken:()=>Z(`token`)},t.streamId,i,e=>{e===`subscribed`&&i.reset(),self.postMessage({type:`status`,status:e})})};
|