@kymoscope/sdk 0.8.0 → 0.8.1

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.
@@ -203,8 +203,8 @@ void main() {
203
203
  if (cov <= 0.0) discard;
204
204
  float alpha = v_color.a * cov;
205
205
  outColor = vec4(v_color.rgb * alpha, alpha);
206
- }`;function YV(e,t,n,r){let i=e.length,a=0;for(let t=0;t<i;t++)Number.isFinite(r[t])&&Number.isFinite(e[t])&&a++;if(a===i)return null;let o=new Float32Array(a),s=new Float32Array(a),c=new Uint8Array(a),l=0,u=!1;for(let a=0;a<i;a++)n[a]&&(u=!0),Number.isFinite(r[a])&&Number.isFinite(e[a])&&(o[l]=t[a],s[l]=r[a],u&&=(c[l]=255,!1),l++);return{x:o,y:s,starts:c}}function XV(e,t,n){let r=e.length,i=0;for(let t=0;t<r;t++)if(Number.isFinite(e[t])){i=e[t];break}let a=new Float32Array(r);for(let t=0;t<r;t++)a[t]=e[t]-i;let o=new Uint8Array(r);if(t)for(let e=0;e<r;e++)t[e]&&(o[e]=255);let s=n.map(t=>YV(e,a,o,t)??{x:a,y:t,starts:o}),c=s.map(e=>e.y.length),l=c.reduce((e,t)=>e+t,0),u=new Float32Array(l),d=new Float32Array(l),f=new Uint8Array(l),p=new Float32Array(l),m=0;return s.forEach((e,t)=>{u.set(e.x,m),d.set(e.y,m),f.set(e.starts,m),e.y.length>0&&(f[m]=255),p.fill(t,m,m+e.y.length),m+=e.y.length}),{origin:i,x:u,y:d,starts:f,sid:p,counts:c}}function ZV(e,t,n,r,i,a){let o=(i-r)/a,s=(t,n)=>{let r=0,i=e.length;for(;r<i;){let a=r+i>>>1;(n?e[a]<=t:e[a]<t)?r=a+1:i=a}return r},c=s(r,!1),l=s(i,!0),u=t.length*(2*a+2),d=new Float32Array(u),f=new Float32Array(u),p=new Uint8Array(u),m=new Float32Array(u),h=0,g=(e,t,r)=>{d[h]=e-n,f[h]=t,m[h]=r,h++};return t.forEach((t,n)=>{let i=h;for(let r=c-1;r>=Math.max(0,c-64);r--)if(t[r]===t[r]){g(e[r],t[r],n);break}let s=c;for(let i=0;i<a&&s<l;i++){let c=i===a-1?1/0:r+(i+1)*o,u=1/0,d=-1/0,f=-1,p=-1;for(;s<l&&e[s]<c;s++){let e=t[s];e<u&&(u=e,f=s),e>d&&(d=e,p=s)}f<0||(f===p?g(e[f],u,n):f<p?(g(e[f],u,n),g(e[p],d,n)):(g(e[p],d,n),g(e[f],u,n)))}for(let r=l;r<Math.min(e.length,l+64);r++)if(t[r]===t[r]){g(e[r],t[r],n);break}h>i&&(p[i]=255)}),{x:d.subarray(0,h),y:f.subarray(0,h),starts:p.subarray(0,h),sid:m.subarray(0,h),bucket:o}}function QV(e){for(let t=1;t<e.length;t++)if(!(e[t]>=e[t-1]))return!1;return e.length===0||e[0]===e[0]}function $V(e,t=1){let n=e.getContext(`webgl2`,{antialias:!1,alpha:!0,premultipliedAlpha:!0});if(!n)return null;let r=WV(n,n.VERTEX_SHADER,qV),i=WV(n,n.FRAGMENT_SHADER,JV);if(!r||!i)return null;let a=n.createProgram();if(!a)return null;if(n.attachShader(a,r),n.attachShader(a,i),n.linkProgram(a),!n.getProgramParameter(a,n.LINK_STATUS))return console.error(`glSeries program link failed:`,n.getProgramInfoLog(a)),null;let o=e=>n.getAttribLocation(a,e),s=o(`a_corner`),c=o(`a_ax`),l=o(`a_bx`),u=o(`a_ay`),d=o(`a_by`),f=o(`a_bstart`),p=o(`a_sid`),m=[c,l,u,d,f,p],h=e=>n.getUniformLocation(a,e),g={res:h(`u_resolution`),styles:h(`u_styles`),left:h(`u_left`),plotW:h(`u_plotW`),xoff:h(`u_xoff`),xscale:h(`u_xscale`),xR:h(`u_xR`),minGap:h(`u_minGap`),cutPx:h(`u_cutPx`)},_=n.createBuffer();n.bindBuffer(n.ARRAY_BUFFER,_),n.bufferData(n.ARRAY_BUFFER,Float32Array.from([-1,-1,1,-1,-1,1,1,1]),n.STATIC_DRAW);let v=n.createFramebuffer(),y=n.createRenderbuffer(),b=1,x=1,S=(`clientWidth`in e?e.clientWidth:0)||1,C=(`clientHeight`in e?e.clientHeight:0)||1,w=[],T=0,E=1,D=1/0,O=e=>{let t=n.createBuffer();return n.bindBuffer(n.ARRAY_BUFFER,t),n.bufferData(n.ARRAY_BUFFER,e,n.STATIC_DRAW),t},k=e=>{if(e)for(let t of[e.x,e.y,e.starts,e.sid])n.deleteBuffer(t)},A=e=>{e&&(k(e.full),k(e.res),n.deleteTexture(e.styles))},j=e=>({x:O(e.x),y:O(e.y),starts:O(e.starts),sid:O(e.sid),total:e.x.length}),M=e=>{let t=e.full;if(t&&t.version===e.version)return t;if(t&&e.valuesOnly&&t.whole&&e.counts.every(t=>t===e.xs.length)){let r=e.xs.length,i=e.columns.length===1?e.columns[0]:new Float32Array(r*e.columns.length);return e.columns.length>1&&e.columns.forEach((e,t)=>i.set(e,t*r)),n.bindBuffer(n.ARRAY_BUFFER,t.y),n.bufferSubData(n.ARRAY_BUFFER,0,i),t.version=e.version,t}k(t);let r=XV(e.xs,e.breaks,e.columns);return e.full={...j(r),version:e.version,whole:r.counts.every(t=>t===e.xs.length)},e.full},N=t=>{let n=Math.max(1,Math.round(t.plotW*(e.width/S)));if(t.resamplable&&E>T){let e=t.xs,r=0,i=e.length;for(;r<i;){let t=r+i>>>1;e[t]<T?r=t+1:i=t}let a=r;for(i=e.length;r<i;){let t=r+i>>>1;e[t]<=E?r=t+1:i=t}if(r-a>n*4){let r=`${t.version}|${T}|${E}|${n}`;if(t.res?.key!==r){k(t.res);let i=ZV(e,t.columns,t.origin,T,E,n);t.res={...j(i),key:r,bucket:i.bucket}}return{d:t.res,minGap:t.res.bucket*2.5}}}return{d:M(t),minGap:0}},P=(e,r)=>{let i=e.counts.length,a=Math.max(1,Math.ceil(i/KV)),o=3*Math.min(Math.max(i,1),KV),s=new Float32Array(o*a*4);for(let n=0;n<i;n++){let i=r[n],a=(Math.floor(n/KV)*o+n%KV*3)*4;if(!i)continue;let c=i.width??t;s.set([Math.min(i.scaleMin,i.scaleMax),Math.max(i.scaleMin,i.scaleMax),i.bandTop,i.bandBottom],a),s.set(i.color,a+4),s.set([i.gapMedian,c/2,c/2+VV,+(e.counts[n]>=2)],a+8)}n.bindTexture(n.TEXTURE_2D,e.styles),n.texImage2D(n.TEXTURE_2D,0,n.RGBA32F,o,a,0,n.RGBA,n.FLOAT,s),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.NEAREST)};return{resize(t,r,i){S=Math.max(1,t),C=Math.max(1,r),e.width=Math.round(S*i),e.height=Math.round(C*i),b=e.width*2,x=e.height*2,v&&y&&(n.bindRenderbuffer(n.RENDERBUFFER,y),n.renderbufferStorage(n.RENDERBUFFER,n.RGBA8,b,x),n.bindFramebuffer(n.FRAMEBUFFER,v),n.framebufferRenderbuffer(n.FRAMEBUFFER,n.COLOR_ATTACHMENT0,n.RENDERBUFFER,y),n.bindFramebuffer(n.FRAMEBUFFER,null))},setData(e,t,r,i){let a=w[e],o=!t&&!!a&&i.length===a.columns.length;if(!t){if(!a)return;t=a.xs,r=a.breaks}let s=0;for(let e=0;e<t.length;e++)if(Number.isFinite(t[e])){s=t[e];break}let c=i.map(e=>{let t=0;for(let n=0;n<e.length;n++)e[n]===e[n]&&t++;return t});if(a&&(o||a.xs===t)){a.columns=i,a.counts=c,a.valuesOnly=o,a.version++,o||(k(a.full),a.full=null);return}let l={xs:t,breaks:r,columns:i,origin:s,counts:c,resamplable:!r?.some(e=>e)&&QV(t),version:0,valuesOnly:!1,full:null,res:null,styles:n.createTexture(),left:a?.left??0,plotW:a?.plotW??0};P(l,[]),w[e]=l,A(a)},setStyles(e,t,n,r){let i=w[e];i&&(P(i,t),i.left=n,i.plotW=r)},clearLayer(e){A(w[e]),w[e]=null},setView(e,t,n=1/0){T=e,E=t,D=n},render(){n.bindFramebuffer(n.FRAMEBUFFER,v),n.viewport(0,0,v?b:e.width,v?x:e.height),n.disable(n.SCISSOR_TEST),n.clearColor(0,0,0,0),n.clear(n.COLOR_BUFFER_BIT),n.useProgram(a),n.uniform2f(g.res,S,C),n.uniform1i(g.styles,0),n.activeTexture(n.TEXTURE0),n.enable(n.BLEND),n.blendFunc(n.ONE,n.ONE_MINUS_SRC_ALPHA),n.bindBuffer(n.ARRAY_BUFFER,_),n.enableVertexAttribArray(s),n.vertexAttribPointer(s,2,n.FLOAT,!1,0,0),n.vertexAttribDivisor(s,0);for(let e of m)n.enableVertexAttribArray(e),n.vertexAttribDivisor(e,1);let t=E-T||1;for(let e of w){if(!e)continue;n.uniform1f(g.left,e.left),n.uniform1f(g.plotW,e.plotW),n.uniform1f(g.xoff,T-e.origin),n.uniform1f(g.xscale,e.plotW/t),n.uniform1f(g.xR,t),n.uniform1f(g.cutPx,Number.isFinite(D)?e.left+(D-T)*(e.plotW/t):1e9);let{d:r,minGap:i}=N(e);r.total<2||(n.uniform1f(g.minGap,i),n.bindTexture(n.TEXTURE_2D,e.styles),n.bindBuffer(n.ARRAY_BUFFER,r.x),n.vertexAttribPointer(c,1,n.FLOAT,!1,4,0),n.vertexAttribPointer(l,1,n.FLOAT,!1,4,4),n.bindBuffer(n.ARRAY_BUFFER,r.y),n.vertexAttribPointer(u,1,n.FLOAT,!1,4,0),n.vertexAttribPointer(d,1,n.FLOAT,!1,4,4),n.bindBuffer(n.ARRAY_BUFFER,r.starts),n.vertexAttribPointer(f,1,n.UNSIGNED_BYTE,!0,1,1),n.bindBuffer(n.ARRAY_BUFFER,r.sid),n.vertexAttribPointer(p,1,n.FLOAT,!1,4,0),n.drawArraysInstanced(n.TRIANGLE_STRIP,0,4,r.total-1))}for(let e of m)n.vertexAttribDivisor(e,0);v&&(n.bindFramebuffer(n.READ_FRAMEBUFFER,v),n.bindFramebuffer(n.DRAW_FRAMEBUFFER,null),n.blitFramebuffer(0,0,b,x,0,0,e.width,e.height,n.COLOR_BUFFER_BIT,n.LINEAR),n.bindFramebuffer(n.FRAMEBUFFER,null))},dispose(){for(let e of w)A(e);w.length=0,n.deleteBuffer(_),n.deleteFramebuffer(v),n.deleteRenderbuffer(y),n.deleteProgram(a),n.deleteShader(r),n.deleteShader(i),n.getExtension(`WEBGL_lose_context`)?.loseContext()}}}var eH=12,tH=0,nH=null;function rH(){return tH<eH}function iH(){tH++;let e=!1;return()=>{e||(e=!0,tH--)}}function aH(){if(nH&&!nH.gl.isContextLost())return nH;let e=document.createElement(`canvas`);e.width=1,e.height=1;let t=e.getContext(`webgl2`,{antialias:!1,alpha:!0,premultipliedAlpha:!0,preserveDrawingBuffer:!1});return nH=t?{canvas:e,gl:t}:null,nH}function oH(e){if(tH<eH)return{canvas:e,shared:!1,present(){},release:iH()};let t=aH();if(!t)return{canvas:e,shared:!1,present(){},release(){}};let n=1,r=1,i={get width(){return n},set width(e){n=Math.max(1,Math.round(e)),t.canvas.width<n&&(t.canvas.width=n)},get height(){return r},set height(e){r=Math.max(1,Math.round(e)),t.canvas.height<r&&(t.canvas.height=r)},getContext(e){return e===`webgl2`?t.gl:null}},a=null;return{canvas:i,shared:!0,present(){e.width!==n&&(e.width=n),e.height!==r&&(e.height=r),a??=e.getContext(`2d`),a&&(a.globalCompositeOperation=`copy`,a.drawImage(t.canvas,0,t.canvas.height-r,n,r,0,0,n,r),a.globalCompositeOperation=`source-over`)},release(){}}}var sH=new WeakMap;function cH(e,t,n){let r=sH.get(e);return r||sH.set(e,r=new Map),r.has(t)||r.set(t,n()),r.get(t)}function lH(e,t){let n=oH(e),r=t(n.canvas);if(!r)return n.release(),null;let i=r.render.bind(r),a=r.dispose.bind(r);return r.render=()=>{i(),n.present()},r.dispose=()=>{a(),n.release()},r}var uH=``+new URL(`assets/offscreenLineWorker-BWa91vu3.js`,import.meta.url).href;function dH(e,t=1){if(typeof e.transferControlToOffscreen!=`function`||typeof Worker>`u`)return null;let n;try{n=AE(uH)}catch{return null}let r;try{r=e.transferControlToOffscreen()}catch{return n.terminate(),null}n.postMessage({type:`init`,canvas:r,lineWidth:t},[r]);let i=iH(),a=-1,o=-1,s=-1;return{resize(e,t,r){e===a&&t===o&&r===s||(a=e,o=t,s=r,n.postMessage({type:`resize`,w:e,h:t,dpr:r}))},setData(e,t){let r=[];t.xs&&r.push(t.xs.buffer),t.breaks&&r.push(t.breaks.buffer);for(let e of t.columns)r.push(e.buffer);n.postMessage({type:`data`,layer:e,...t},r)},setStyle(e,t){n.postMessage({type:`style`,layer:e,...t})},clear(e){n.postMessage({type:`clear`,layer:e})},setView(e,t,r){n.postMessage({type:`view`,xmin:e,xmax:t,cut:r})},dispose(){try{n.postMessage({type:`dispose`})}catch{}n.terminate(),i()}}}function fH(e,t=1){let n=lH(e,e=>$V(e,t));if(!n)return null;let r=0,i=1,a,o=``,s=(e,t)=>{n.setStyles(e,t.styles,t.left,t.plotW),r=t.xmin,i=t.xmax,a=t.cut,n.setView(r,i,a),n.render()};return{resize(e,t,r){let i=`${e}|${t}|${r}`;i!==o&&(o=i,n.resize(e,t,r),n.render())},setData(e,t){n.setData(e,t.xs,t.breaks,t.columns),s(e,t)},setStyle(e,t){s(e,t)},clear(e){n.clearLayer(e),n.render()},setView(e,t,o){e===r&&t===i&&o===a||(r=e,i=t,a=o,n.setView(e,t,o),n.render())},dispose(){n.dispose()}}}var pH=new Set;function mH(e){pH.add(e)}function hH(e){pH.delete(e)}function gH(){let e=typeof window>`u`?[]:[window];for(let t of pH)t.closed||e.push(t);return e}var _H=1,vH=new Map;function yH(e){let t=_H++,n=gH();if(n.length===1){let r=n[0].requestAnimationFrame(n=>{vH.delete(t),e(n)});return vH.set(t,[{w:n[0],id:r}]),t}let r=[],i=n=>{vH.has(t)&&(bH(t),e(n))};for(let e of n)r.push({w:e,id:e.requestAnimationFrame(i)});return vH.set(t,r),t}function bH(e){if(e==null)return;let t=vH.get(e);if(t){vH.delete(e);for(let{w:e,id:n}of t)e.closed||e.cancelAnimationFrame(n)}}var xH=new WeakMap;function SH(e){e&&xH.set(e,(xH.get(e)??0)+1)}function CH(e){let t=xH.get(e)??0;for(let n of e.querySelectorAll(`*`))t+=xH.get(n)??0;return t}function wH(){return gH().every(e=>e.document.hidden)}var TH=class{#e;#t=new Map;constructor(e){this.#e=e}observe(e,t){let n=e.ownerDocument.defaultView??window,r=this.#t.get(n);r||(r=new(n.ResizeObserver??ResizeObserver)(e=>this.#e(e,this)),this.#t.set(n,r)),r.observe(e,t)}unobserve(e){for(let t of this.#t.values())t.unobserve(e)}disconnect(){for(let e of this.#t.values())e.disconnect();this.#t.clear()}};function EH(e,t){let n=0,r=null,i=t=>{n=0,r=t,e()};return{schedule(){n||=yH(i)},now(){let a=t()?.timeline?.currentTime;if(typeof a!=`number`||a===r){n||=yH(i);return}n&&=(bH(n),0),r=a,e()},cancel(){n&&bH(n),n=0}}}function DH(e,t=typeof window>`u`?null:e=>{yH(e)}){let n=!1,r=null;return{set(i){if(r=i,!t){e(i);return}n||(n=!0,t(()=>{n=!1,e(r)}))}}}function OH(e,t,n,r,i){return r+(e-t)/n*(i-r)}function kH(e,t,n,r){let i=new Map,a=n.length;if(a===0)return i;let o=new Float64Array(a),s=new Float64Array(a).fill(1/0);for(let r of e){let e=r.x;for(let i=0;i<a;i++){let a=r.cols.get(n[i]);if(!a)continue;let c=s[i],l=o[i];for(let n=0;n<r.length;n++){let r=e[n],i=r<t?t-r:r-t;if(i>=c)continue;let o=a[n];Number.isFinite(o)&&(c=i,l=o)}s[i]=c,o[i]=l}}for(let e=0;e<a;e++)s[e]!==1/0&&(r&&s[e]>(r.get(n[e])??1/0)||i.set(n[e],o[e]));return i}function AH(e,t,n,r=64){let i=new Map;if(t.length===0||!Number.isFinite(n))return i;let a=new Map;for(let o of e){if(o.length===0)continue;let e=0,s=o.length-1;for(;e<s;){let t=e+s>>1;o.x[t]<n?e=t+1:s=t}for(let s of t){let t=o.cols.get(s);if(t)for(let c=0;c<=r;c++){let r=e-c,l=e+c,u=r>=0&&Number.isFinite(t[r])?r:l<o.length&&Number.isFinite(t[l])?l:-1;if(u<0)continue;let d=Math.abs(o.x[u]-n);d<(a.get(s)??1/0)&&(a.set(s,d),i.set(s,t[u]));break}}}return i}function jH(e,t){let n=new Map;if(t.length===0)return n;for(let r=e.length-1;r>=0&&n.size<t.length;r--){let i=e[r];for(let e of t){if(n.has(e))continue;let t=i.cols.get(e);if(t){for(let r=i.length-1;r>=0;r--)if(Number.isFinite(t[r])){n.set(e,t[r]);break}}}}return n}function MH(e,t){return!(e>0)||!(t>0)?1:1-Math.exp(-e/t)}function NH(e,t,n,r=t){if(!(t>e)||n==null||!(n>0))return[e,t];let i=Number.isFinite(r)?Math.min(t,Math.max(e,r)):t;return i-n<e?[e,Math.min(t,e+n)]:[i-n,i]}function PH(e,t){let n=Math.round(e*t*2);return Math.min(8e3,Math.max(2e3,n))}var FH=.5;function IH(e,t,n,r=FH){if(!(t>0))return e;let i=e!=null&&e>0?Math.min(e,t):t,a=n?i*.88:i/.88;return a>=t*.999?null:Math.max(r,a)}function LH(e=0){return{d:null,lastT:NaN,wall:0,base:NaN,wait:e,waitAge:0}}var RH=new Map,zH=250,BH=3,VH=90,HH=30,UH=.001;function WH(e,t,n){if(!Number.isFinite(t))return t;n>zH&&e.d!==null&&(e.d=null,e.base=NaN),n=Math.min(n,zH);let r=n/1e3;if(e.wall+=r,t<e.lastT&&Object.assign(e,LH(),{wall:e.wall}),t<=e.lastT)e.base+=r*UH;else{let n=e.wall-t;e.base=Number.isNaN(e.base)?n:Math.min(e.base+r*UH,n)}e.lastT=t;let i=e.wall-t-e.base;e.waitAge+=r,i>e.wait?(e.wait=Math.min(BH,i),e.waitAge=0):i>e.wait*.8?e.waitAge=0:e.waitAge>VH&&(e.wait*=Math.exp(-r/HH));let a=e.wall-e.base-Math.min(BH,e.wait*1.2+.05);return e.d===null?e.d=e.wait>0?Math.min(t,a):t:e.d<a-2?e.d=a:(e.d+=r,e.d+=(a-e.d)*Math.min(1,n/500)),e.d>t&&(e.d=t),e.d}var GH=(e,t)=>e.log?(Math.log10(Math.max(t,Number.MIN_VALUE))-Math.log10(e.v0))/(Math.log10(e.v1)-Math.log10(e.v0)||1):(t-e.v0)/(e.v1-e.v0||1),KH=(e,t)=>e.log?10**(Math.log10(e.v0)+t*(Math.log10(e.v1)-Math.log10(e.v0))):e.v0+t*(e.v1-e.v0),qH=(e,t)=>e.left+GH(e.x,t)*e.width,JH=(e,t)=>KH(e.x,(t-e.left)/(e.width||1)),YH=(e,t)=>e.top+(1-GH(e.y,t))*e.height,XH=e=>!e||Number.isFinite(e.v0)&&Number.isFinite(e.v1)&&e.v0!==e.v1&&(!e.log||e.v0>0&&e.v1>0),ZH=(e,t)=>e===t||!!e&&!!t&&e.v0===t.v0&&e.v1===t.v1&&!!e.log==!!t.log;function QH(){let e=null,t=new Set;return{get:()=>e,set:n=>{if(n&&(n.width>0&&n.height>0?(!XH(n.x)||!XH(n.y))&&(n={...n,x:XH(n.x)?n.x:void 0,y:XH(n.y)?n.y:void 0}):n=null),!(n===e||n&&e&&n.left===e.left&&n.top===e.top&&n.width===e.width&&n.height===e.height&&ZH(n.x,e.x)&&ZH(n.y,e.y))){e=n;for(let e of[...t])e()}},subscribe:e=>(t.add(e),()=>{t.delete(e)})}}var $H=it(()=>{}),eU=()=>lt($H),tU=`M5 .8a3.1 3.1 0 0 0-3.1 3.1v2.3L.8 7.6h8.4L8.1 6.2V3.9A3.1 3.1 0 0 0 5 .8zM3.9 8.4a1.1 1.1 0 0 0 2.2 0z`,nU=[5,4],rU=null;function iU(e,t,n,r){typeof Path2D>`u`||(rU??=new Path2D(tU),e.save(),e.setLineDash([]),e.translate(t,n),e.fillStyle=r,e.fill(rU),e.restore())}var aU=(()=>{try{return localStorage.getItem(`glLines`)!==`0`}catch{return!0}})(),oU=(()=>{try{return localStorage.getItem(`offscreenGl`)!==`0`}catch{return!0}})(),sU=70;function cU(e){return e===`dashed`?[5,4]:e===`dotted`?[1,4]:[]}var lU={top:14,right:160,bottom:40,left:110},uU={top:14,right:100,bottom:40,left:70},dU=640,fU={top:3,right:3,bottom:3,left:3},pU=260;function mU(e){return e<pU?fU:e<dU?uU:lU}var hU=220,gU=2e3,_U=4,vU=1e3/120,yU=`11.25px ${Q.mono}`,bU=11*1.125,xU=24*1.125,SU=xU-bU+26,CU=.6,wU=13,TU=10,EU=5,DU=14,OU=4;function kU(e,t,n){return Math.min(n,Math.max(t,e))}function AU(e,t,n,r,i){let a=Math.min(r,i),o=Math.max(r,i);return t+(1-kU(o===a?.5:(e-a)/(o-a),0,1))*(n-t)}function jU(e,t,n,r){let i=e+t;return{bandTop:i-r/100*t,bandBottom:i-n/100*t}}function MU(e){return e.replace(/__(\d+|ref)$/,``)}function NU(e,t,n){let r=Math.floor((n-t-bU)/wU)+1;return Math.max(0,Math.min(e,r))}function PU(e){let t=0;for(let n of e)t+=n.length;return t}function FU(e,t){let n=e.cols.get(t);return n?Float32Array.from(n):new Float32Array(e.length).fill(NaN)}function IU(e){let t=new Map;for(let n of e){let e=MU(n.column),r=t.get(e)??[];r.push(n),t.set(e,r)}let n=new Set,r=[];for(let i of e){let e=MU(i.column);if(n.has(e))continue;n.add(e);let a=t.get(e);r.push({base:e,leader:a[0],members:a})}return r}function LU(e,t,n){let r=new Map,i=e.map((e,r)=>{let{bandTop:i}=jU(t,n,e.leader.bandFromPct,e.leader.bandToPct);return{g:e,i:r,bandTop:i,blockDY:e.members.length>1?bU+(e.members.length+1)*wU:SU}});i.sort((e,t)=>e.bandTop-t.bandTop||e.i-t.i);let a=-1/0;for(let{g:e,bandTop:t,blockDY:n}of i){let i=t+bU,o=Math.max(i,a),s=o-bU;r.set(e.leader.id,s),a=o+n}return r}function RU(e,t){let n=e.cols.get(t);if(!n)return 0;let r=e.x;return n.length===e.length&&u.has(n)?zU(r,e.length):VU(r,e.length,e=>Number.isFinite(n[e]))}function zU(e,t){let n=BU.get(e);return n===void 0&&(n=VU(e,t,()=>!0),BU.set(e,n)),n}var BU=g(new WeakMap);function VU(e,t,n){let r=null,i=0,a=0;for(let o=0;o<t;o++)n(o)&&(r!==null&&e[o]!==r&&(i+=Math.abs(e[o]-r),a++),r=e[o]);return a===0?0:i/a}function HU(e,t){return e>0?Math.max(e*4,t*1e-9):Math.max(t*1e-6,1e-12)}var UU=1e30,WU=250;function GU({xLabel:e,series:t,points:n,columnUnits:r={},height:i=440,onPlotContextMenu:a,backgroundToken:o=``,viewXRange:s=null,onViewXRangeChange:c,liveZoom:l,liveZoomId:u,fullXRange:d=null,shiftMode:f,xAxisLine:p,yAxisLine:m,gridLine:h,lineWidth:g=1,envelopes:_,showLatestValues:v=!1,liveSource:y,liveWindowSeconds:b=null,onLiveWindowChange:x,liveZoomMode:S,onPlotWidthCss:C,onCursorX:w}){let T=eU(),E=K(null),D=K(null),O=K(null),k=K(null),A=K(C);A.current=C;let j=K(-1),M=K(null),N=K(!1),P=K(null),F=K(!1),I=K(!1),L=K(null),R=K(null),z=K({pts:null,layers:[]}),B=K(new Map),V=K([]),ee=K(null),te=K(null),H=K(null),ne=K(null),re=K(0),ie=K(0),U=K(!1),ae=K(0),oe=K(gU),se=K(y),ce=K(null),le=K(LH()),ue=K(0),de=K(void 0),fe=K(0),pe=K(0),me=K(16),he=K(!0);G(()=>{se.current=y,ce.current=null,z.current={pts:null,layers:[]},B.current.clear()},[y]);let ge=K(b);G(()=>{ge.current=b},[b]);let _e=K(x);_e.current=x;let ve=S??(x?`follow`:`free`),ye=K(ve);ye.current=ve;let be=K(null);G(()=>{be.current=null},[ve,e]);let xe=K([]),Se=K(!1),Ce=K(0),we=K(0),Te=K(0),Ee=K(0),De=K(`none`),Oe=K(0),ke=K(0),Ae=K(0),je=K(null),Me=K(null),Ne=K(f),Pe=K(null),Fe=K({pts:null,x0:NaN,x1:NaN,ser:null}),Ie=K(0),Le=K(0),Re=K(null),ze=K(null),Be=K(null),Ve=K(null);G(()=>{Ne.current=f},[f]),W(()=>(L.current&&=(clearTimeout(L.current),null),()=>{M.current?.dispose(),M.current=null;let e=P.current;e&&(L.current=setTimeout(()=>{e.dispose(),P.current===e&&(P.current=null),L.current=null},0))}),[]);let He=pt(Wz,Uz),Ue=K({xLabel:e,series:t,points:n,height:i,columnUnits:r,shiftMode:f,xAxisLine:p,yAxisLine:m,gridLine:h,lineWidth:g,showLatestValues:v,envelopes:_}),We=K(null),Ge=K(null);G(()=>{Ue.current={xLabel:e,series:t,points:n,height:i,columnUnits:r,shiftMode:f,xAxisLine:p,yAxisLine:m,gridLine:h,lineWidth:g,showLatestValues:v,envelopes:_}},[e,t,n,i,r,f,p,m,h,g,v,_]);let Ke=K(c),qe=K(w);qe.current=w,G(()=>{Ke.current=c},[c]);let Je=K(l),Ye=K(u);G(()=>{Je.current=l,Ye.current=u},[l,u]),W(()=>{if(!(!l||!u))return l.subscribe((e,t)=>{e!==u&&(ee.current=t?.[0]??null,te.current=t?.[1]??null,gt())})},[l,u]);let Xe=K(a);G(()=>{Xe.current=a},[a]);let Ze=dt(()=>{if(d&&d[1]>d[0])return{xmin:d[0],xmax:d[1]};let e=1/0,t=-1/0;for(let r of n)for(let n=0;n<r.length;n++){let i=r.x[n];i<e&&(e=i),i>t&&(t=i)}return(!Number.isFinite(e)||e===t)&&(--e,t+=1),{xmin:e,xmax:t}},[n,d]),Qe=K(Ze);G(()=>{Qe.current=Ze},[Ze]);function $e(){return se.current!=null&&ee.current===null&&te.current===null&&!Se.current&&Pe.current===null}function et(){let{xmin:e,xmax:t}=Qe.current,n=ee.current,r=te.current;if(n!==null&&r!==null&&r>n&&Number.isFinite(n)&&Number.isFinite(r))return{xmin:n,xmax:r};let i=H.current,a=ne.current;return $e()&&i!==null&&a!==null&&a>i&&Number.isFinite(i)&&Number.isFinite(a)?{xmin:i,xmax:a}:{xmin:e,xmax:t}}function tt(e,t){let n=se.current;if(!n?.latestValues)return jH(e,t);let r=n.latestValues(t),i=t.filter(e=>!r.has(e)),a=n.latestX?.();if(i.length>0&&a!=null)for(let[t,n]of AH(e,i,a))r.set(t,n);return r}function nt(){return se.current?xe.current:Ue.current.points}function rt(e,t,n){let r=new Map;for(let i of t)r.set(i,HU(ct(e,i),n));return r}function it(e){if(z.current.pts===e)return z.current.layers;let t=z.current.layers,n=se.current?.version?.(),r=e.map((e,r)=>({pts:e,key:t[r]?.pts===e?t[r].key:n??e}));return z.current={pts:e,layers:r},r}function at(e,t){let n=B.current.get(e),r=performance.now(),i=n&&(n.key===t.key||typeof t.key==`number`&&typeof n.key==`number`&&r-n.at<WU);return(!n||!i)&&(n={key:t.key,at:r,has:new Map,median:new Map},B.current.set(e,n)),n}function ot(e,t,n){let r=at(e,t),i=r.has.get(n);if(i===void 0){let e=t.pts.cols.get(n);i=!!e&&e.some(Number.isFinite),r.has.set(n,i)}return i}function st(e,t){return it(e).some((e,n)=>ot(n,e,t))}function ct(e,t){let n=it(e);for(let e=0;e<n.length;e++){if(!ot(e,n[e],t))continue;let r=at(e,n[e]),i=r.median.get(t);return i===void 0&&(i=RU(n[e].pts,t),r.median.set(t,i)),i}return 0}function lt(){if(Ve.current)return Ve.current;let e=k.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return Ve.current=n,n}function ut(){let e=k.current,t=Math.max(1,e?.clientWidth||200),n=e?.clientHeight??0;return{w:t,h:Math.max(1,n>0?n:Ue.current.height)}}function ft(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function mt(){let e=E.current;if(!e)return;let{w:t,h:n}=ut(),r=ft(e,t,n);if(!r)return;{let e=nt(),t=et(),n=Ue.current.series,r=Fe.current;(r.pts!==e||r.x0!==t.xmin||r.x1!==t.xmax||r.ser!==n)&&(Fe.current={pts:e,x0:t.xmin,x1:t.xmax,ser:n},SH(k.current))}let i=mU(t),a=i===fU,{top:o,right:s,bottom:c}=i,l=i.left,u=t-l-s,d=n-o-c,{bg:f,muted:p,grid:m}=lt(),{xLabel:h,series:g,xAxisLine:_,yAxisLine:v,gridLine:y,lineWidth:b,columnUnits:x,showLatestValues:S}=Ue.current,C=nt();if(r.fillStyle=f,r.fillRect(0,0,t,n),PU(C)<2||u<=0||d<=0){if(r.fillStyle=p,r.font=`13px ${Q.sans}`,r.fillText(`Not enough data to plot`,l,o+24),M.current&&(M.current.resize(t,n,window.devicePixelRatio||1),M.current.draw([])),P.current){P.current.resize(t,n,window.devicePixelRatio||1);for(let e=0;e<V.current.length;e++)P.current.clear(e);V.current=[]}return}let{xmin:w,xmax:O}=et(),A=O-w,j=e=>l+(e-w)/A*u;T({left:l,top:o,width:u,height:d,x:{v0:w,v1:O}});let R=g.filter(e=>e.bandToPct>e.bandFromPct&&e.scaleMin!==e.scaleMax&&st(C,e.column)),z=IU(R),B=LU(z,o,d),ee=new Map;for(let e of z){let t=B.get(e.leader.id);t!==void 0&&e.members.forEach(e=>ee.set(e.id,t))}let te=new Set,H=new Set;for(let e of z)e.members.length>1&&e.members.forEach(e=>te.add(e.id)),H.add(e.leader.id);let ne=`11px ${Q.mono}`,re=R.map(e=>{let{bandTop:t,bandBottom:n}=jU(o,d,e.bandFromPct,e.bandToPct),r=Math.min(e.scaleMin,e.scaleMax),i=Math.max(e.scaleMin,e.scaleMax),{majorStep:a,minorStep:s}=Ez(e.scaleMin,e.scaleMax,e.yMajorStep??0,e.yMinorStep??0),c=a,l=Dz(r,i,c);l.length>120&&(l=Dz(r,i,c=Ez(e.scaleMin,e.scaleMax,0,0).majorStep));let u=Oz(r,i,s,l);return u.length>400&&(u=[]),{s:e,bandTop:t,bandBottom:n,majors:l,minors:u,step:c}}),ie=new Map,U=0;{r.save(),r.font=ne;let e=re.filter(e=>H.has(e.s.id));e.sort((e,t)=>{let n=Math.abs(e.s.bandToPct-e.s.bandFromPct),r=Math.abs(t.s.bandToPct-t.s.bandFromPct);return n===r?re.indexOf(e)-re.indexOf(t):r-n});let n=new Map,a=[];for(let t of e){let r=0;for(;r<e.length;r++){let e=a[r];if(!e||e.length===0||!e.some(e=>t.bandTop<e.bandBottom&&t.bandBottom>e.bandTop))break}n.set(t.s.id,r),a[r]||(a[r]=[]),a[r].push(t)}let o=new Map,c=new Map;for(let t of e){let e=0;for(let n of t.majors){let i=jz(n,t.step),a=c.get(i);a===void 0&&c.set(i,a=r.measureText(i).width),a>e&&(e=a)}o.set(t.s.id,e)}let u=[],d=[],f=0;for(let e=0;e<a.length;e++){u[e]=f;let t=0;for(let n of a[e]??[]){let e=o.get(n.s.id)??0;e>t&&(t=e)}d[e]=t,f+=t+22}for(let e of re){let t=n.get(e.s.id)??0;ie.set(e.s.id,u[t]??0)}let p=i.left;for(let e=0;e<a.length;e++){let t=a[e];if(!t||t.length===0)continue;let n=(u[e]??0)+OU+DU+(d[e]??0)+6;n>p&&(p=n)}let m=Math.max(i.left,t-s-Math.max(120,t*.4)),h=Math.min(Math.ceil(p),m);h>l&&(U=h-l),r.restore()}U>0&&(l+=U,u=Math.max(1,t-l-s)),oe.current=PH(u,window.devicePixelRatio||1);let ae=(e,t)=>1-(1-e)**t,se=new Map,ce=new Map;for(let e of re){let t=`${e.bandTop}|${e.bandBottom}|${e.s.scaleMin}|${e.s.scaleMax}|${e.majors.join(`,`)}`,n=se.get(t);n?n.k++:se.set(t,{c:e,k:1});let r=te.has(e.s.id)?p:e.s.color,i=`${e.bandTop}|${e.bandBottom}|${r}`,a=ce.get(i);a?a.k++:ce.set(i,{c:e,color:r,k:1})}if((v?.style??`dashed`)!==`none`)for(let{c:{s:e,bandTop:t,bandBottom:n,majors:i},k:a}of se.values()){r.save(),r.strokeStyle=v?.color??m,r.globalAlpha=ae(.1,a),r.lineWidth=v?.width??1,r.lineCap=`round`,r.setLineDash(cU(v?.style??`dashed`));for(let a of i){let i=AU(a,t,n,e.scaleMin,e.scaleMax);r.beginPath(),r.moveTo(l,i),r.lineTo(l+u,i),r.stroke()}r.restore()}for(let{c:{bandTop:e,bandBottom:t},color:n,k:i}of ce.values())r.strokeStyle=n,r.lineWidth=1,r.setLineDash([]),r.globalAlpha=ae(.45,i),r.beginPath(),r.moveTo(l,e),r.lineTo(l,t),r.stroke(),r.globalAlpha=1;for(let{s:e,bandTop:t,bandBottom:n,majors:i,minors:o,step:s}of a?[]:re){let a=te.has(e.id)?p:e.color;if(H.has(e.id)){let c=ie.get(e.id)??0,u=l-c-OU;r.strokeStyle=a,r.lineWidth=1;for(let i of o){let a=AU(i,t,n,e.scaleMin,e.scaleMax);r.beginPath(),r.moveTo(u-EU,a),r.lineTo(u,a),r.stroke()}r.font=ne,r.textAlign=`right`,r.textBaseline=`middle`,r.strokeStyle=a,r.fillStyle=a;for(let a of i){let i=AU(a,t,n,e.scaleMin,e.scaleMax);r.beginPath(),r.moveTo(u-TU,i),r.lineTo(u,i),r.stroke(),r.fillText(jz(a,s),u-DU,i)}}}if((y?.style??`solid`)!==`none`&&(r.strokeStyle=y?.color??m,r.lineWidth=y?.width??1,r.setLineDash(cU(y?.style??`solid`)),r.strokeRect(l,o,u,d),r.setLineDash([])),(_?.style??`dashed`)!==`none`){r.strokeStyle=_?.color??m,r.lineWidth=_?.width??1,r.setLineDash(cU(_?.style??`dashed`));for(let e=1;e<6;e++){let t=l+e/6*u;r.beginPath(),r.moveTo(t,o),r.lineTo(t,o+d),r.stroke()}r.setLineDash([])}let le=o+d+10;r.fillStyle=p,r.font=`11px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`top`;let ue=Fz(h,w,w+A);for(let e=0;e<=(a?-1:6);e++){let t=w+e/6*A;r.fillText(ue?Gz(t,A/6,A):jz(t,A/6),l+e/6*u,le)}r.textBaseline=`bottom`,a||r.fillText(h,l+u/2,n-5);let{shiftMode:fe}=Ue.current;fe&&(r.globalAlpha=.8,r.font=`10px ${Q.sans}`,r.fillStyle=p,r.textAlign=`center`,r.textBaseline=`top`,r.fillText(`⇄ shifting: ${fe.label}`,l+u/2,o+3),r.globalAlpha=1);let pe=Ue.current.envelopes;if(pe?.length){r.save(),r.beginPath(),r.rect(l,o,u,d),r.clip();for(let e of pe){let t=R.find(t=>t.id===e.seriesId||t.id.startsWith(`${e.seriesId}__`));if(!t)continue;let{bandTop:n,bandBottom:i}=jU(o,d,t.bandFromPct,t.bandToPct),a=e=>AU(e,n,i,t.scaleMin,t.scaleMax);r.fillStyle=e.color,r.globalAlpha=.2;let s=0;for(;s<e.x.length;){for(;s<e.x.length&&e.lo[s]!==e.lo[s];)s++;let t=s;for(;s<e.x.length&&e.lo[s]===e.lo[s];)s++;if(!(s-t<2)){r.beginPath(),r.moveTo(j(e.x[t]),a(e.hi[t]));for(let n=t+1;n<s;n++)r.lineTo(j(e.x[n]),a(e.hi[n]));for(let n=s-1;n>=t;n--)r.lineTo(j(e.x[n]),a(e.lo[n]));r.closePath(),r.fill()}}}r.restore()}L.current&&=(clearTimeout(L.current),null);let me=oU&&!F.current?P.current:null;if(oU&&!me&&!F.current&&D.current&&!I.current&&(me=rH()?dH(D.current):fH(D.current),me?(P.current=me,I.current=!0):F.current=!0),me){me.resize(t,n,window.devicePixelRatio||1);let e=`${l.toFixed(2)}|${u.toFixed(2)}|${o}|${d}|${b}|`+R.map(e=>`${e.id}:${e.column}:${e.bandFromPct}:${e.bandToPct}:${e.scaleMin}:${e.scaleMax}:${e.color}`).join(`,`),r=it(C),i=V.current;for(let t=0;t<Math.max(r.length,i.length);t++){let n=r[t];if(!n){i[t]&&me.clear(t),i[t]=null;continue}let a=R.filter(e=>ot(t,n,e.column)),s=a.map(e=>e.column).join(`
207
- `),c=i[t];if(c&&c.pts===n.pts&&c.sig===e&&c.cols===s)continue;i[t]={pts:n.pts,sig:e,cols:s};let f={styles:a.map(e=>{let{bandTop:t,bandBottom:r}=jU(o,d,e.bandFromPct,e.bandToPct);return{color:zV(e.color),bandTop:t,bandBottom:r,scaleMin:e.scaleMin,scaleMax:e.scaleMax,gapMedian:n.pts.hold?UU:ct(C,e.column),width:b}}),left:l,plotW:u,xmin:w,xmax:O,cut:de.current};if(c&&c.pts===n.pts&&c.cols===s){me.setStyle(t,f);continue}let p=n.pts,m=!!c&&c.pts.x===p.x&&c.pts.brk===p.brk&&c.cols===s;me.setData(t,{...f,xs:m?null:p.x.slice(),breaks:m?void 0:p.brk?.slice(),columns:a.map(e=>FU(p,e.column))})}i.length=r.length,me.setView(w,O,de.current)}else{let e=M.current;aU&&!e&&!N.current&&D.current&&!I.current&&(e=GV(D.current),e?M.current=e:N.current=!0);let i=!!e;i&&e&&e.resize(t,n,window.devicePixelRatio||1);let a=[],s=rt(C,R.map(e=>e.column),A);for(let e of R){let{bandTop:t,bandBottom:n}=jU(o,d,e.bandFromPct,e.bandToPct),c=s.get(e.column);if(i){let r={x:l,y:t,w:u,h:n-t},i=zV(e.color),o=[],s=null,d=()=>{o.length>=4&&a.push({points:Float32Array.from(o),color:i,clip:r,width:b}),o=[]};for(let r of C){let i=r.cols.get(e.column);if(i){s=null;for(let a=0;a<r.length;a++){r.brk?.[a]&&d();let l=i[a];if(!Number.isFinite(l))continue;let u=r.x[a];s!==null&&!r.hold&&Math.abs(u-s)>c&&d(),o.push(j(u),AU(l,t,n,e.scaleMin,e.scaleMax)),s=u}d()}}d();continue}r.strokeStyle=e.color,r.lineWidth=b,r.lineJoin=`round`,r.lineCap=`round`,r.save(),r.beginPath(),r.rect(l,t,u,n-t),r.clip(),r.beginPath();let f=!1,p=null,m=!1;for(let i of C){let a=i.cols.get(e.column);if(a){m=!0;for(let o=0;o<i.length;o++){i.brk?.[o]&&(m=!0);let s=a[o];if(!Number.isFinite(s))continue;let l=i.x[o],u=j(l),d=AU(s,t,n,e.scaleMin,e.scaleMax);f?m||p!==null&&!i.hold&&Math.abs(l-p)>c?(r.stroke(),r.beginPath(),r.moveTo(u,d),p=l,m=!1):(r.lineTo(u,d),p=l):(r.moveTo(u,d),f=!0,p=l,m=!1)}}}f&&r.stroke(),r.restore()}i&&e&&e.draw(a)}for(let e of R){if(!e.alarm)continue;let{bandTop:t,bandBottom:n}=jU(o,d,e.bandFromPct,e.bandToPct),i=AU(e.alarm.value,t,n,e.scaleMin,e.scaleMax);r.save(),r.beginPath(),r.rect(l,t,u,n-t),r.clip(),r.strokeStyle=e.alarm.color,r.lineWidth=e.alarm.width,r.setLineDash(e.alarm.linked===`active`?nU:cU(e.alarm.style)),r.beginPath(),r.moveTo(l,i),r.lineTo(l+u,i),r.stroke(),r.setLineDash([]),e.alarm.linked&&iU(r,l+u-10-3,i-10-2,e.alarm.color),r.restore()}if(a)return;let he=S?tt(C,R.map(e=>e.column)):null,ge=e=>{let t=he?.get(e.column);if(typeof t!=`number`)return`-`;let n=x[e.column]?.trim()??``;return`${Mz(t)}${n?` ${n}`:``}`},_e=l+u+8;r.font=yU,r.textAlign=`left`;for(let e of z){let t=B.get(e.leader.id);if(t===void 0)continue;let i=e.members.length>1;if(r.fillStyle=i?p:e.leader.color,r.globalAlpha=1,r.fillText(e.base,_e,t+bU),i){let i=NU(e.members.length,t,n);for(let n=0;n<i;n++)r.fillStyle=e.members[n].color,r.globalAlpha=CU,r.fillText(ge(e.members[n]),_e,t+bU+(n+1)*wU)}else r.fillStyle=e.leader.color,r.globalAlpha=CU,r.fillText(ge(e.leader),_e,t+xU);r.globalAlpha=1}}function ht(){let e=O.current;if(!e)return;let{w:t,h:n}=ut(),r=ft(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let{top:i,right:a,bottom:o,left:s}=mU(t),c=t-s-a,l=n-i-o,{series:u,columnUnits:d,xLabel:f}=Ue.current,p=nt();if(Se.current&&c>0&&l>0){let e=Ce.current,t=we.current,n=Te.current,i=Ee.current,a=Math.min(e,n),o=Math.min(t,i),s=Math.abs(n-e),c=Math.abs(i-t);r.fillStyle=`rgba(59, 130, 246, 0.12)`,r.fillRect(a,o,s,c),r.strokeStyle=`rgba(59, 130, 246, 0.85)`,r.setLineDash([4,3]),r.lineWidth=1,r.strokeRect(a,o,s,c),r.setLineDash([])}let m=R.current;if(m===null||PU(p)<2||c<=0||l<=0)return;let{xmin:h,xmax:g}=et(),_=u.filter(e=>e.bandToPct>e.bandFromPct&&e.scaleMin!==e.scaleMax&&st(p,e.column)),v=[...new Set(_.map(e=>e.column))],y=rt(p,v,g-h),{bg:b,muted:x}=lt();r.strokeStyle=x,r.globalAlpha=.5,r.lineWidth=1,r.beginPath(),r.moveTo(m,i),r.lineTo(m,i+l),r.stroke(),r.globalAlpha=1;let S=IU(_),C=LU(S,i,l),w=s+c+8;r.font=yU,r.textAlign=`left`;let T=OH(m,s,c,h,g),E=kH(p,T,v,y),D=e=>{let t=E.get(e.column);if(typeof t!=`number`)return`-`;let n=d[e.column]?.trim()??``;return`${Mz(t)}${n?` ${n}`:``}`};for(let e of S){let t=C.get(e.leader.id)??jU(i,l,e.leader.bandFromPct,e.leader.bandToPct).bandTop;if(e.members.length>1){let i=e.members.length*wU+4;r.fillStyle=b,r.fillRect(s+c+6,t+bU+2,a-8,i);let o=NU(e.members.length,t,n);for(let n=0;n<o;n++){let i=e.members[n];r.fillStyle=i.color,r.globalAlpha=CU,r.fillText(D(i),w,t+bU+(n+1)*wU)}}else{let n=e.leader;r.fillStyle=b,r.fillRect(s+c+6,t+bU+2,a-8,xU-bU+6),r.fillStyle=n.color,r.globalAlpha=CU,r.fillText(D(n),w,t+xU)}r.globalAlpha=1}let k=/^(.*?)\s*\(([^)]*)\)\s*$/.exec(f),A=k?k[1]:f,j=k?k[2].trim():``,M=Fz(f,h,g)?Kz(T):``,N=M.lastIndexOf(` `),P=M?[`${A} ${M.slice(0,N)}`,M.slice(N+1)]:[`${A} ${Math.round(T)}${j}`];r.font=yU,r.textAlign=`left`,r.textBaseline=`alphabetic`,P.forEach((e,t)=>{let n=r.measureText(e).width,a=i+l-(P.length-1-t)*15;r.fillStyle=b,r.fillRect(w-2,a-11,n+6,15),r.fillStyle=x,r.globalAlpha=1,r.fillText(e,w,a)})}function gt(){if(se.current){U.current=!0;return}Re.current=()=>{mt(),ht()},!Ie.current&&(Ie.current=yH(e=>{Ie.current=0,ze.current=e,Re.current?.()}))}function vt(){if(se.current){U.current=!0;return}let e=k.current?.ownerDocument.timeline?.currentTime;if(typeof e!=`number`||e===ze.current){gt();return}ze.current=e,bH(Ie.current),Ie.current=0,mt(),ht()}function yt(){Be.current=ht,!Le.current&&(Le.current=yH(()=>{Le.current=0,Be.current?.()}))}function bt(e){re.current=yH(bt);let t=se.current;if(!t||(me.current+=(Math.min(50,pe.current?e-pe.current:16)-me.current)*.1,pe.current=e,!he.current)||fe.current&&e-fe.current<vU-me.current/2)return;fe.current=e;let n=t.xBounds();n&&n[1]>n[0]&&(Qe.current={xmin:n[0],xmax:n[1]});let r=ue.current?e-ue.current:16;ue.current=e,r>250&&(H.current=null,ne.current=null);let i=t.latestT?.(),a;if(i!==void 0&&t.xAtTime&&Number.isFinite(i)){let e=le.current;e.d===null&&e.wait===0&&t.id&&(e.wait=RH.get(t.id)??0);let n=t.xAtTime(WH(e,i,r));t.id&&e.wait>0&&RH.set(t.id,e.wait),Number.isFinite(n)&&(a=n)}if($e()){let n=a??t.latestX?.()??Qe.current.xmax,r=ge.current,i=r!=null&&t.spanForSeconds?t.spanForSeconds(r):r??be.current,[o,s]=NH(Qe.current.xmin,Qe.current.xmax,i,n??void 0);if(!t.spanForSeconds&&a!==void 0&&a>o&&(s=Math.min(s,a)),Number.isFinite(o)&&Number.isFinite(s)&&s>o){let t=s-o,n=ne.current!==null&&s<ne.current-t;if(H.current===null||ne.current===null||n)H.current=o,ne.current=s,ie.current=e;else{let n=ie.current;ie.current=e;let r=MH(n?Math.min(64,e-n):16,hU);H.current+=(o-H.current)*r,ne.current+=(s-ne.current)*r,Math.abs(o-H.current)<t*1e-6&&(H.current=o),Math.abs(s-ne.current)<t*1e-6&&(ne.current=s)}}}else H.current=null,ne.current=null,ie.current=0;let o=et(),s=t.version?.(),c=oe.current,l=ce.current,u=l!==null&&s!==void 0&&l.ver===s&&l.x0===o.xmin&&l.x1===o.xmax&&l.mp===c&&l.cut===a;(PU(xe.current)===0||!u&&e-ae.current>=_U)&&(ae.current=e,de.current=t.cutOnGpu&&P.current?a:void 0,xe.current=t.pull(o.xmin,o.xmax,c,a,de.current!==void 0),ce.current=s===void 0?null:{ver:s,x0:o.xmin,x1:o.xmax,mp:c,cut:a}),U.current=!1,mt(),ht()}function xt(){re.current||=(ie.current=0,yH(bt))}function St(){re.current&&(bH(re.current),re.current=0,ue.current=0,H.current=null,ne.current=null,xe.current=[],de.current=void 0)}W(()=>{let e=k.current,t=e?.ownerDocument.defaultView?.IntersectionObserver;if(!e||!t)return;let n=new t(e=>{he.current=e[e.length-1].isIntersecting});return n.observe(e),()=>{n.disconnect(),he.current=!0}},[]),W(()=>(y?xt():(St(),gt()),St),[!!y]),W(()=>eB(k.current,()=>{Ve.current=null,gt()}),[]),W(()=>{Ve.current=null,gt()},[o]);let Ct=!!f;W(()=>{let e=O.current;e&&(e.style.cursor=Ct?`ew-resize`:``),gt()},[Ct,f?.label??``]);let wt=s?.[0]??null,Tt=s?.[1]??null;return G(()=>{ee.current===wt&&te.current===Tt||(ee.current=wt,te.current=Tt,gt())},[wt,Tt]),W(()=>{vt()},[t,n,i,e,p,m,h,g,v,He]),W(()=>()=>{bH(Ie.current),bH(Le.current),Ie.current=0,Le.current=0},[]),W(()=>{let e=O.current,t=k.current;if(!e||!t)return;let n=()=>{let e=Math.round(t.clientWidth);e>0&&e!==j.current&&(j.current=e,A.current?.(e))};n();let r=new TH(()=>{Ve.current=null,n(),gt()});r.observe(t);let i=DH(e=>qe.current?.(e)),a=t=>{if(Se.current||Pe.current!==null)return;if(PU(nt())<2){R.current!==null&&(R.current=null,yt(),i.set(null));return}let n=e.getBoundingClientRect(),r=t.clientX-n.left,a=t.clientY-n.top,{left:o,top:s,right:c,bottom:l}=mU(n.width),u=Math.max(1,n.width-o-c),d=n.height-s-l;if(r<o||r>o+u||a<s||a>s+d){R.current!==null&&(R.current=null,yt(),i.set(null));return}R.current!==r&&(R.current=r,yt());let{xmin:f,xmax:p}=et();i.set(OH(r,o,u,f,p))},o=()=>{R.current!==null&&(R.current=null,yt()),i.set(null)},s=e=>{We.current&&clearTimeout(We.current),We.current=setTimeout(()=>{We.current=null,Ke.current?.(e)},sU)},c=t=>{if(De.current!==`none`||t.buttons&2||Date.now()-Ae.current<300||PU(nt())<2)return;let n=e.getBoundingClientRect(),r=t.clientX-n.left,i=t.clientY-n.top,{top:a,left:o,right:c,bottom:l}=mU(n.width),u=Math.max(1,n.width-o-c),d=Math.max(1,n.height-a-l);if(r<o||r>o+u||i<a||i>a+d)return;t.preventDefault();let f=Qe.current,p=f.xmax-f.xmin;if(!(p>0))return;if(ye.current===`follow`&&$e()&&!_e.current){be.current=IH(be.current,p,t.deltaY<0,p*.001);return}if(ye.current===`follow`&&$e()){let e=IH(ge.current,se.current?.bufferedSeconds?.()??p,t.deltaY<0);ge.current=e,Ge.current&&clearTimeout(Ge.current),Ge.current=setTimeout(()=>{Ge.current=null,_e.current?.(e)},sU);return}let m=ee.current??f.xmin,h=(te.current??f.xmax)-m;if(!(h>0))return;let g=Date.now();g-ke.current>300&&(je.current=ee.current,Me.current=te.current),ke.current=g;let _=m+(r-o)/u*h,v=t.deltaY<0,y=.88,b=v?h*y:h/y,x=Math.max(p*1e-7,1e-12);if(v)b=Math.max(b,x);else{if(b>=p*.999){ee.current=null,te.current=null,s(null),Je.current?.publish(Ye.current??``,null),gt();return}b=Math.min(b,p)}let S=(_-m)/h,C=_-S*b,w=_+(1-S)*b;C<f.xmin&&(w+=f.xmin-C,C=f.xmin),w>f.xmax&&(C-=w-f.xmax,w=f.xmax),w-C<b-1e-12&&(C=Math.max(f.xmin,_-b/2),w=C+b,w>f.xmax&&(w=f.xmax,C=w-b)),w-C>=p*.999?(ee.current=null,te.current=null,s(null),Je.current?.publish(Ye.current??``,null)):(ee.current=C,te.current=w,s([C,w]),Je.current?.publish(Ye.current??``,[C,w])),gt()},l=e=>{if(e.preventDefault(),Ae.current=Date.now(),Date.now()-ke.current<300){ee.current=je.current,te.current=Me.current;let e=je.current,t=Me.current;We.current&&=(clearTimeout(We.current),null),Ke.current?.(e===null&&t===null?null:[e,t]),ke.current=0,gt()}},u=t=>{if(t.button===0&&Ne.current){let n=e.getBoundingClientRect(),{left:r,top:i,right:a,bottom:o}=mU(n.width),s=Math.max(1,n.width-r-a),c=n.height-i-o,l=t.clientX-n.left,u=t.clientY-n.top;if(l>=r&&l<=r+s&&u>=i&&u<=i+c){Pe.current=t.clientX,Ne.current.onDragStart();try{e.setPointerCapture(t.pointerId)}catch{}}return}if(t.button!==2)return;if(t.preventDefault(),t.buttons===0){Xe.current?.({clientX:t.clientX,clientY:t.clientY});return}if(De.current!==`none`){Se.current=!1,De.current=`none`;try{e.releasePointerCapture(t.pointerId)}catch{}}let n=e.getBoundingClientRect(),r=t.clientX-n.left,i=t.clientY-n.top;Oe.current=Date.now(),De.current=`menuOnly`,Se.current=!1,Ce.current=r,we.current=i,Te.current=r,Ee.current=i;try{e.setPointerCapture(t.pointerId)}catch{}},d=t=>{if(Pe.current!==null){let n=t.clientX-Pe.current,r=e.getBoundingClientRect(),{left:i,right:a}=mU(r.width),o=Math.max(1,r.width-i-a),{xmin:s,xmax:c}=et(),l=c-s;l>0&&o>0&&Ne.current?.onDragOffset(n/o*l);return}if(De.current===`none`)return;let n=e.getBoundingClientRect(),r=t.clientX-n.left,i=t.clientY-n.top;if(De.current===`menuOnly`){if(Date.now()-Oe.current<150)return;let e=r-Ce.current,t=i-we.current;if(Math.sqrt(e*e+t*t)<12)return;let a=nt(),{top:o,left:s,right:c,bottom:l}=mU(n.width),u=n.width-s-c,d=n.height-o-l,f=u>0&&d>0&&Ce.current>=s&&Ce.current<=s+u&&we.current>=o&&we.current<=o+d;if(PU(a)<2||!f)return;De.current=`rubber`,Se.current=!0,R.current=null}De.current===`rubber`&&(t.preventDefault(),Te.current=r,Ee.current=i,yt())},f=t=>{if(t.button!==2)return;t.preventDefault();let n=De.current;De.current=`none`;try{e.releasePointerCapture(t.pointerId)}catch{}if(n===`menuOnly`){Se.current=!1,yt(),Xe.current?.({clientX:t.clientX,clientY:t.clientY});return}if(n!==`rubber`||!Se.current){Se.current=!1,yt();return}Se.current=!1;let r=nt(),i=e.getBoundingClientRect(),{left:a,right:o}=mU(i.width),s=Math.max(1,i.width-a-o),c=Ce.current,l=Te.current,u=Math.abs(l-c);if(PU(r)<2||u<12){Xe.current?.({clientX:t.clientX,clientY:t.clientY}),yt();return}let d=kU(Math.min(c,l),a,a+s),f=kU(Math.max(c,l),a,a+s),{xmin:p,xmax:m}=et(),h=m-p;if(!(h>0)){Xe.current?.({clientX:t.clientX,clientY:t.clientY}),yt();return}let g=p+(d-a)/s*h,_=p+(f-a)/s*h;if(g>_){let e=g;g=_,_=e}let v=Qe.current,y=Math.min(v.xmin,v.xmax),b=Math.max(v.xmin,v.xmax);g=kU(g,y,b),_=kU(_,y,b);let x=_-g;if(x<=(b-y)*1e-12||x<=0){Xe.current?.({clientX:t.clientX,clientY:t.clientY}),yt();return}Xe.current?.({clientX:t.clientX,clientY:t.clientY,zoomXRange:[g,_]}),yt()},p=t=>{if(t.button===0&&Pe.current!==null){Pe.current=null;try{e.releasePointerCapture(t.pointerId)}catch{}return}if(t.button===2){f(t);return}if(t.buttons===0&&De.current!==`none`){De.current=`none`,Se.current=!1;try{e.releasePointerCapture(t.pointerId)}catch{}Xe.current?.({clientX:t.clientX,clientY:t.clientY}),yt()}},m=t=>{Pe.current!==null&&(Pe.current=null),De.current!==`none`&&(Se.current=!1,De.current=`none`);try{e.releasePointerCapture(t.pointerId)}catch{}yt()},h=t=>{if(t.button!==0||PU(nt())<2)return;let n=e.getBoundingClientRect(),r=t.clientX-n.left,i=t.clientY-n.top,{top:a,left:o,right:s,bottom:c}=mU(n.width),l=Math.max(1,n.width-o-s),u=Math.max(1,n.height-a-c);r<o||r>o+l||i<a||i>a+u||ee.current===null&&te.current===null||(ee.current=null,te.current=null,We.current&&=(clearTimeout(We.current),null),Ke.current?.(null),Je.current?.publish(Ye.current??``,null),gt(),yt())},g=e=>{if(e.key!==`Escape`)return;let t=!1;De.current!==`none`&&(De.current=`none`,Se.current=!1,t=!0),Pe.current!==null&&(Pe.current=null,t=!0),t&&yt()};e.addEventListener(`mousemove`,a),e.addEventListener(`mouseleave`,o),e.addEventListener(`wheel`,c,{passive:!1}),e.addEventListener(`contextmenu`,l),e.addEventListener(`pointerdown`,u),e.addEventListener(`pointermove`,d),e.addEventListener(`pointerup`,p),e.addEventListener(`pointercancel`,m),e.addEventListener(`dblclick`,h);let _=e.ownerDocument.defaultView??window;return _.addEventListener(`keydown`,g),()=>{r.disconnect(),e.removeEventListener(`mousemove`,a),e.removeEventListener(`mouseleave`,o),e.removeEventListener(`wheel`,c),e.removeEventListener(`contextmenu`,l),e.removeEventListener(`pointerdown`,u),e.removeEventListener(`pointermove`,d),e.removeEventListener(`pointerup`,p),e.removeEventListener(`pointercancel`,m),e.removeEventListener(`dblclick`,h),_.removeEventListener(`keydown`,g),We.current&&clearTimeout(We.current),Ge.current&&clearTimeout(Ge.current)}},[]),_t(`div`,{ref:k,className:`chart-canvas-wrap`,children:[q(`canvas`,{ref:E,className:`chart-canvas`,role:`img`,"aria-label":`Chart of ${e}`}),q(`canvas`,{ref:D,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),q(`canvas`,{ref:O,className:`chart-canvas chart-overlay`})]})}function KU(){try{if(localStorage.getItem(`perfLog`)===`1`)return!0;if(localStorage.getItem(`perfLog`)===`0`)return!1}catch{}return!1}var qU=!1;function JU(){let e=KU();return e&&!qU&&(qU=!0,console.log(`[perf] logging enabled — zoom an out-of-core chart to see decimate()/sampleRows timings`)),e}JU();var YU=new Map;function XU(e,t){let n=(YU.get(e)??0)+1;YU.set(e,n),console.log(`[perf] ${e} #${n} ${t.toFixed(1)}ms`)}async function ZU(e,t){if(!JU())return t();let n=performance.now();try{return await t()}finally{XU(e,performance.now()-n)}}var QU=20;async function $U(e,t,n,r){let{x0:i,bucket:a,rows:o,columns:s}=await ZU(`decimate(${t.length}col)`,()=>e.getSeriesMulti(t,n,r));return T(o,s,i,a)}function eW(e,t,n,r,i=0,a=!1,o=0){let[s,c]=ft({points:Ye,fetchedViewport:null}),[l,u]=ft(!1),d=`${t.join(`,`)}|${n?`${n.xKey}:${n.x0}:${n.x1}`:`none`}|${r}|${i}`,f=dt(()=>{if(!a||!e?.getSeriesMultiSync||!n||t.length===0)return null;let i=o>0?e.getColumnsSync?.(t,n,o):null;if(i)return{points:i,loading:!1,fetchedViewport:n,full:!0};let s=e.getSeriesMultiSync(t,n,r);return{points:T(s.rows,s.columns,s.x0,s.bucket),loading:!1,fetchedViewport:n}},[a,e,d,o]);return W(()=>{if(a)return;if(!e||!n||t.length===0){c({points:Ye,fetchedViewport:null});return}let i=!0;u(!0);let o=setTimeout(()=>{$U(e,t,n,r).then(t=>{i&&(c({points:t,fetchedViewport:n,source:e}),u(!1))}).catch(()=>{i&&u(!1)})},QU);return()=>{i=!1,clearTimeout(o)}},[e,d,a]),f||(s.source!==void 0&&s.source!==e?{points:Ye,loading:l,fetchedViewport:null}:{points:s.points,loading:l,fetchedViewport:s.fetchedViewport})}var tW=250,nW=2,rW=6e3,iW=2e6,aW=[];function oW(e,t,n,r,i,a){let o=!!e&&e.columnSet.has(n),s=dt(()=>e&&o?t.filter(t=>e.columnSet.has(t)):aW,[e,o,t]),c=e&&o&&s.length>0?e.source:null,l=!!c&&!e?.live&&!!c.getSeriesMultiSync&&!!c.xBoundsSync,u=dt(()=>l&&c?c.xBoundsSync(n):null,[l,c,n]),[d,f]=ft(null),p=!!e?.live;W(()=>{if(!c||l)return;let e=!0,t=()=>c.xBounds(n).then(t=>{let r=c.version?.()??0;e&&f(e=>e&&e.source===c&&e.xKey===n&&e.ver===r?e:{source:c,xKey:n,b:t,ver:r})}).catch(()=>{});t();let r=p?setInterval(t,tW):void 0;return()=>{e=!1,clearInterval(r)}},[c,n,p,l]);let m=d&&d.source===c&&d.xKey===n?d:null,h=u??m?.b??null,g=m?.ver??0,{points:_,loading:v,full:y}=eW(c,s,c&&h&&h.x1>h.x0?{xKey:n,x0:h.x0,x1:h.x1}:null,Math.min(rW,i*nW),g,l,a),b=e?.xOffset??0,x=r&&r[1]>r[0]?r[0]-b:null,S=r&&r[1]>r[0]?r[1]-b:null,C=y||!!h&&x!==null&&S!==null&&x<=h.x0&&S>=h.x1,{points:w,fetchedViewport:T}=eW(c,s,c&&x!==null&&S!==null&&!C?{xKey:n,x0:x,x1:S}:null,i,g,l,a),E=dt(()=>!T||w.length===0?_:Je([N(_,e=>e<T.x0),w,N(_,e=>e>T.x1)]),[_,w,T]),D=!!c&&(h===null||v);return dt(()=>e?{points:Te(E,e.keySuffix,e.xOffset),bounds:h?{x0:h.x0+e.xOffset,x1:h.x1+e.xOffset}:null,loading:D}:{points:Ye,bounds:null,loading:!1},[e,E,h,D])}var sW=new WeakMap,cW=0;function lW(e){if(e.key!==void 0)return e.key;let t=sW.get(e.source);return t===void 0&&sW.set(e.source,t=cW++),`${t}${e.keySuffix}`}function uW(){let[e,t]=ft(()=>new Map);return[e,ct((e,n)=>t(t=>{if(n?t.get(e)===n:!t.has(e))return t;let r=new Map(t);return n?r.set(e,n):r.delete(e),r}),[])]}var dW=ot(function({id:e,layer:t,columns:n,xKey:r,view:i,mp:a,rawLimit:o,report:s}){let c=oW(t,n,r,i,a,o);return G(()=>{s(e,c)},[e,c,s]),G(()=>()=>s(e,null),[e,s]),null});function fW({layers:e,xKey:t,columns:n,maxPoints:r,...i}){let a=i.viewXRange??null,[o,s]=ft(null),c=typeof window<`u`?Math.min(3,Math.max(1,window.devicePixelRatio||1)):1,l=o==null?r:Math.min(r,Math.round(o*c/50)*50),u=Math.max(1e3,Math.round(l/Math.sqrt(Math.max(1,e.length)))),d=Math.floor(iW/Math.max(1,e.length)),[f,p]=uW(),m=dt(()=>e.map(lW),[e]),h=dt(()=>m.map(e=>f.get(e)),[m,f]),g=dt(()=>h.flatMap(e=>e&&e.points.length>0?[e.points]:[]),[h]),_=dt(()=>{let e=1/0,t=-1/0;for(let n of h){let r=n?.bounds;r&&(e=Math.min(e,r.x0),t=Math.max(t,r.x1))}return Number.isFinite(e)&&t>e?[e,t]:null},[h]),v=h.some(e=>!e||e.loading);return _t(gt,{children:[e.map((e,r)=>q(dW,{id:m[r],layer:e,columns:n,xKey:t,view:a,mp:u,rawLimit:d,report:p},m[r])),g.length===0?_t(`div`,{className:`chart-placeholder chart-placeholder--no-data`,onContextMenu:e=>{e.preventDefault(),i.onPlotContextMenu?.({clientX:e.clientX,clientY:e.clientY})},children:[q(`span`,{className:`content-empty-icon`,"aria-hidden":!0}),q(`h2`,{children:v?`Loading…`:`No data for the selected X axis`}),v?null:q(`p`,{children:`None of the selected datasets has this X column together with a plotted channel.`})]}):q(GU,{points:g,fullXRange:_,...i,onPlotWidthCss:s})]})}function pW(e){return!!e&&!Array.isArray(e)&&typeof e.length==`number`&&`x`in e&&`y`in e}function mW(e){let t=e.length,n=new Float64Array(t),r=new Float64Array(t),i=t>0&&e[0].c!==void 0?new Float32Array(t):void 0,a=e.some(e=>e.d!==void 0)?new Uint8Array(t):void 0;for(let o=0;o<t;o++){let t=e[o];n[o]=t.x,r[o]=t.y,i&&(i[o]=t.c??0),a&&(a[o]=t.d??0)}return{length:t,x:n,y:r,c:i,d:a}}function hW(e,t,n){let r=n?.get(t);if(r)return r;let i=Ue(e);if(i)return pe(i,t);if(e.length===0||!(t in e[0]))return;let a=new Float64Array(e.length);for(let n=0;n<e.length;n++){let r=e[n][t];a[n]=typeof r==`number`?r:NaN}return a}function gW(e,t,n){let r=hW(e,t,n);if(!r||u.has(r))return r;let i=0;for(let e=0;e<r.length;e++)r[e]-r[e]===0&&i++;if(i===r.length)return r;let a=new Float64Array(i);for(let e=0,t=0;e<r.length;e++)r[e]-r[e]===0&&(a[t++]=r[e]);return a}function _W(e,t,n,r){if(!n){let n=gW(e,t,r);return n?[{label:t,values:n}]:[]}let i=hW(e,t,r);if(!i)return[];let a=i.length,o=r?.has(n)||e.length>0&&typeof e[0][n]==`number`?hW(e,n,r):void 0,s=t=>{if(o){let e=o[t];return e===e?String(e):`unknown`}return String(e[t]?.[n]??`unknown`)},c=new Map,l=[],u=new Int32Array(a),d=[];for(let e=0;e<a;e++){if(i[e]-i[e]!==0){u[e]=-1;continue}let t=s(e),n=c.get(t);n===void 0&&(c.set(t,n=l.length),l.push(t),d.push(0)),u[e]=n,d[n]++}let f=l.map((e,t)=>({label:e,values:new Float64Array(d[t])})),p=new Int32Array(l.length);for(let e=0;e<a;e++){let t=u[e];t>=0&&(f[t].values[p[t]++]=i[e])}return f}function vW(e){let t=NaN,n=NaN,r=0;for(let i=0;i<e.length;i++){let a=e[i];a-a===0&&(r===0&&(t=a),n=a,r++)}let i=n-t;return r>1&&i>0?(r-1)/i:null}function yW(e,t,n){let r=0;for(let i=0;i<e.length;i++)e[i]>=t&&e[i]<=n&&r++;let i=new Uint32Array(r),a=0;for(let r=0;r<e.length;r++)e[r]>=t&&e[r]<=n&&(i[a++]=r);return i}function bW(e,t){let n=new Float64Array(t.length);for(let r=0;r<t.length;r++)n[r]=e[t[r]];return n}function xW(e,t,n,r){let i=hW(e.rows,t,e.full),a=hW(e.rows,n,e.full);if(!i||!a)return null;let o=r.colorCol?hW(e.rows,r.colorCol,e.full):void 0;if(r.viewXRange){let t=hW(e.rows,r.xKey,e.full);if(t){let e=yW(t,r.viewXRange[0],r.viewXRange[1]);i=bW(i,e),a=bW(a,e),o&&=bW(o,e)}}let s=Math.min(i.length,a.length);if(!o)return{cols:{length:s,x:i,y:a}};let c=1/0,l=-1/0;for(let e=0;e<s;e++){let t=o[e];t<c&&(c=t),t>l&&(l=t)}if(!(l>c))return{cols:{length:s,x:i,y:a}};let u=new Float32Array(s),d=l-c;for(let e=0;e<s;e++){let t=o[e];u[e]=t===t?(t-c)/d:0}return{cols:{length:s,x:i,y:a,c:u},color:{label:r.colorCol,min:c,max:l}}}function SW(e,t,n,r){let i=[],a=[];e.forEach((e,o)=>{a.push(Jz(r.colorOverrides,e.id,o,r.palette));let s=xW(e,t,n,{xKey:r.xKey,viewXRange:r.viewXRange});i.push(s?.cols??{length:0,x:[],y:[]})});let o=i.reduce((e,t)=>e+t.length,0),s=new Float64Array(o),c=new Float64Array(o),l=new Uint8Array(o),u=0;return i.forEach((e,t)=>{for(let t=0;t<e.length;t++)s[u+t]=e.x[t],c[u+t]=e.y[t];l.fill(Math.min(t,255),u,u+e.length),u+=e.length}),{cols:{length:o,x:s,y:c,d:l},colors:a}}var CW=e=>pW(e)?e:mW(e),wW=(e,t,n)=>t===t&&n===n&&(!e||t>=e.xmin&&t<=e.xmax&&n>=e.ymin&&n<=e.ymax);function TW(e,t,n){let r=t+1,i=Array.from({length:r},()=>Array(r).fill(0)),a=Array(r).fill(0),o=new Float64Array(2*r-1),s=0;for(let t=0;t<e.length;t++){let c=e.x[t],l=e.y[t];if(wW(n,c,l)){s++,o[0]=1;for(let e=1;e<o.length;e++)o[e]=o[e-1]*c;for(let e=0;e<r;e++){for(let t=0;t<r;t++)i[e][t]+=o[e+t];a[e]+=o[e]*l}}}if(s<r)return null;let c=i.map((e,t)=>[...e,a[t]]);for(let e=0;e<r;e++){let t=e;for(let n=e+1;n<r;n++)Math.abs(c[n][e])>Math.abs(c[t][e])&&(t=n);if([c[e],c[t]]=[c[t],c[e]],Math.abs(c[e][e])<1e-10)return null;let n=c[e][e];for(let t=e;t<=r;t++)c[e][t]/=n;for(let t=0;t<r;t++){if(t===e)continue;let n=c[t][e];for(let i=e;i<=r;i++)c[t][i]-=n*c[e][i]}}return c.map(e=>e[r])}function EW(e,t,n){return TW(CW(e),t,n)}function DW(e,t){let n=CW(e),r=0,i=0;for(let e=0;e<n.length;e++)wW(void 0,n.x[e],n.y[e])&&(r++,i+=n.y[e]);if(r===0)return 0;let a=i/r,o=0,s=0;for(let e=0;e<n.length;e++){let r=n.x[e],i=n.y[e];if(!wW(void 0,r,i))continue;let c=0;for(let e=t.length-1;e>=0;e--)c=c*r+t[e];o+=(i-a)**2,s+=(i-c)**2}return o<1e-15?1:Math.max(0,1-s/o)}function OW(e,t=4){if(!Number.isFinite(e))return`?`;let n=Math.abs(e);return n===0?`0`:n>=1e5||n>0&&n<.001?e.toExponential(2):e.toPrecision(t).replace(/\.?0+$/,``)}function kW(e,t,n){let r=[];for(let n=e.length-1;n>=0;n--){let i=e[n];n===0?r.push(OW(i)):n===1?r.push(`${OW(i)}·${t}`):r.push(`${OW(i)}·${t}${n>1?`^${n}`:``}`)}return`${n} = ${r.join(` + `).replace(/\+ -/g,`− `)}`}var AW=[[0,45,80,160],[.25,40,145,175],[.5,60,180,110],[.75,220,175,55],[1,210,75,55]];function jW(e){let t=0;for(let n=1;n<AW.length;n++){if(e<=AW[n][0]){t=n-1;break}n===AW.length-1&&(t=n-1)}let n=t+1,r=(e-AW[t][0])/(AW[n][0]-AW[t][0]);return{r:Math.round(AW[t][1]+r*(AW[n][1]-AW[t][1])),g:Math.round(AW[t][2]+r*(AW[n][2]-AW[t][2])),b:Math.round(AW[t][3]+r*(AW[n][3]-AW[t][3]))}}function MW(e){let{r:t,g:n,b:r}=jW(e);return`rgb(${t},${n},${r})`}function NW(e,t){if(!Number.isFinite(e))return 0;let n=Math.floor(e*t);return n<0?0:n>=t?t-1:n}var PW=`#version 300 es
206
+ }`;function YV(e,t,n,r){let i=e.length,a=0;for(let t=0;t<i;t++)Number.isFinite(r[t])&&Number.isFinite(e[t])&&a++;if(a===i)return null;let o=new Float32Array(a),s=new Float32Array(a),c=new Uint8Array(a),l=0,u=!1;for(let a=0;a<i;a++)n[a]&&(u=!0),Number.isFinite(r[a])&&Number.isFinite(e[a])&&(o[l]=t[a],s[l]=r[a],u&&=(c[l]=255,!1),l++);return{x:o,y:s,starts:c}}function XV(e,t,n){let r=e.length,i=0;for(let t=0;t<r;t++)if(Number.isFinite(e[t])){i=e[t];break}let a=new Float32Array(r);for(let t=0;t<r;t++)a[t]=e[t]-i;let o=new Uint8Array(r);if(t)for(let e=0;e<r;e++)t[e]&&(o[e]=255);let s=n.map(t=>YV(e,a,o,t)??{x:a,y:t,starts:o}),c=s.map(e=>e.y.length),l=c.reduce((e,t)=>e+t,0),u=new Float32Array(l),d=new Float32Array(l),f=new Uint8Array(l),p=new Float32Array(l),m=0;return s.forEach((e,t)=>{u.set(e.x,m),d.set(e.y,m),f.set(e.starts,m),e.y.length>0&&(f[m]=255),p.fill(t,m,m+e.y.length),m+=e.y.length}),{origin:i,x:u,y:d,starts:f,sid:p,counts:c}}function ZV(e,t,n,r,i,a){let o=(i-r)/a,s=(t,n)=>{let r=0,i=e.length;for(;r<i;){let a=r+i>>>1;(n?e[a]<=t:e[a]<t)?r=a+1:i=a}return r},c=s(r,!1),l=s(i,!0),u=t.length*(2*a+2),d=new Float32Array(u),f=new Float32Array(u),p=new Uint8Array(u),m=new Float32Array(u),h=0,g=(e,t,r)=>{d[h]=e-n,f[h]=t,m[h]=r,h++};return t.forEach((t,n)=>{let i=h;for(let r=c-1;r>=Math.max(0,c-64);r--)if(t[r]===t[r]){g(e[r],t[r],n);break}let s=c;for(let i=0;i<a&&s<l;i++){let c=i===a-1?1/0:r+(i+1)*o,u=1/0,d=-1/0,f=-1,p=-1;for(;s<l&&e[s]<c;s++){let e=t[s];e<u&&(u=e,f=s),e>d&&(d=e,p=s)}f<0||(f===p?g(e[f],u,n):f<p?(g(e[f],u,n),g(e[p],d,n)):(g(e[p],d,n),g(e[f],u,n)))}for(let r=l;r<Math.min(e.length,l+64);r++)if(t[r]===t[r]){g(e[r],t[r],n);break}h>i&&(p[i]=255)}),{x:d.subarray(0,h),y:f.subarray(0,h),starts:p.subarray(0,h),sid:m.subarray(0,h),bucket:o}}function QV(e){for(let t=1;t<e.length;t++)if(!(e[t]>=e[t-1]))return!1;return e.length===0||e[0]===e[0]}function $V(e,t=1){let n=e.getContext(`webgl2`,{antialias:!1,alpha:!0,premultipliedAlpha:!0}),r=typeof HTMLCanvasElement<`u`&&e instanceof HTMLCanvasElement||typeof OffscreenCanvas<`u`&&e instanceof OffscreenCanvas;if(!n)return null;let i=WV(n,n.VERTEX_SHADER,qV),a=WV(n,n.FRAGMENT_SHADER,JV);if(!i||!a)return null;let o=n.createProgram();if(!o)return null;if(n.attachShader(o,i),n.attachShader(o,a),n.linkProgram(o),!n.getProgramParameter(o,n.LINK_STATUS))return console.error(`glSeries program link failed:`,n.getProgramInfoLog(o)),null;let s=e=>n.getAttribLocation(o,e),c=s(`a_corner`),l=s(`a_ax`),u=s(`a_bx`),d=s(`a_ay`),f=s(`a_by`),p=s(`a_bstart`),m=s(`a_sid`),h=[l,u,d,f,p,m],g=e=>n.getUniformLocation(o,e),_={res:g(`u_resolution`),styles:g(`u_styles`),left:g(`u_left`),plotW:g(`u_plotW`),xoff:g(`u_xoff`),xscale:g(`u_xscale`),xR:g(`u_xR`),minGap:g(`u_minGap`),cutPx:g(`u_cutPx`)},v=n.createBuffer();n.bindBuffer(n.ARRAY_BUFFER,v),n.bufferData(n.ARRAY_BUFFER,Float32Array.from([-1,-1,1,-1,-1,1,1,1]),n.STATIC_DRAW);let y=n.createFramebuffer(),b=n.createRenderbuffer(),x=1,S=1,C=(`clientWidth`in e?e.clientWidth:0)||1,w=(`clientHeight`in e?e.clientHeight:0)||1,T=[],E=0,D=1,O=1/0,k=e=>{let t=n.createBuffer();return n.bindBuffer(n.ARRAY_BUFFER,t),n.bufferData(n.ARRAY_BUFFER,e,n.STATIC_DRAW),t},A=e=>{if(e)for(let t of[e.x,e.y,e.starts,e.sid])n.deleteBuffer(t)},j=e=>{e&&(A(e.full),A(e.res),n.deleteTexture(e.styles))},M=e=>({x:k(e.x),y:k(e.y),starts:k(e.starts),sid:k(e.sid),total:e.x.length}),N=e=>{let t=e.full;if(t&&t.version===e.version)return t;if(t&&e.valuesOnly&&t.whole&&e.counts.every(t=>t===e.xs.length)){let r=e.xs.length,i=e.columns.length===1?e.columns[0]:new Float32Array(r*e.columns.length);return e.columns.length>1&&e.columns.forEach((e,t)=>i.set(e,t*r)),n.bindBuffer(n.ARRAY_BUFFER,t.y),n.bufferSubData(n.ARRAY_BUFFER,0,i),t.version=e.version,t}A(t);let r=XV(e.xs,e.breaks,e.columns);return e.full={...M(r),version:e.version,whole:r.counts.every(t=>t===e.xs.length)},e.full},P=t=>{let n=Math.max(1,Math.round(t.plotW*(e.width/C)));if(t.resamplable&&D>E){let e=t.xs,r=0,i=e.length;for(;r<i;){let t=r+i>>>1;e[t]<E?r=t+1:i=t}let a=r;for(i=e.length;r<i;){let t=r+i>>>1;e[t]<=D?r=t+1:i=t}if(r-a>n*4){let r=`${t.version}|${E}|${D}|${n}`;if(t.res?.key!==r){A(t.res);let i=ZV(e,t.columns,t.origin,E,D,n);t.res={...M(i),key:r,bucket:i.bucket}}return{d:t.res,minGap:t.res.bucket*2.5}}}return{d:N(t),minGap:0}},F=(e,r)=>{let i=e.counts.length,a=Math.max(1,Math.ceil(i/KV)),o=3*Math.min(Math.max(i,1),KV),s=new Float32Array(o*a*4);for(let n=0;n<i;n++){let i=r[n],a=(Math.floor(n/KV)*o+n%KV*3)*4;if(!i)continue;let c=i.width??t;s.set([Math.min(i.scaleMin,i.scaleMax),Math.max(i.scaleMin,i.scaleMax),i.bandTop,i.bandBottom],a),s.set(i.color,a+4),s.set([i.gapMedian,c/2,c/2+VV,+(e.counts[n]>=2)],a+8)}n.bindTexture(n.TEXTURE_2D,e.styles),n.texImage2D(n.TEXTURE_2D,0,n.RGBA32F,o,a,0,n.RGBA,n.FLOAT,s),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.NEAREST)};return{resize(t,r,i){C=Math.max(1,t),w=Math.max(1,r),e.width=Math.round(C*i),e.height=Math.round(w*i),x=e.width*2,S=e.height*2,y&&b&&(n.bindRenderbuffer(n.RENDERBUFFER,b),n.renderbufferStorage(n.RENDERBUFFER,n.RGBA8,x,S),n.bindFramebuffer(n.FRAMEBUFFER,y),n.framebufferRenderbuffer(n.FRAMEBUFFER,n.COLOR_ATTACHMENT0,n.RENDERBUFFER,b),n.bindFramebuffer(n.FRAMEBUFFER,null))},setData(e,t,r,i){let a=T[e],o=!t&&!!a&&i.length===a.columns.length;if(!t){if(!a)return;t=a.xs,r=a.breaks}let s=0;for(let e=0;e<t.length;e++)if(Number.isFinite(t[e])){s=t[e];break}let c=i.map(e=>{let t=0;for(let n=0;n<e.length;n++)e[n]===e[n]&&t++;return t});if(a&&(o||a.xs===t)){a.columns=i,a.counts=c,a.valuesOnly=o,a.version++,o||(A(a.full),a.full=null);return}let l={xs:t,breaks:r,columns:i,origin:s,counts:c,resamplable:!r?.some(e=>e)&&QV(t),version:0,valuesOnly:!1,full:null,res:null,styles:n.createTexture(),left:a?.left??0,plotW:a?.plotW??0};F(l,[]),T[e]=l,j(a)},setStyles(e,t,n,r){let i=T[e];i&&(F(i,t),i.left=n,i.plotW=r)},clearLayer(e){j(T[e]),T[e]=null},setView(e,t,n=1/0){E=e,D=t,O=n},render(){n.bindFramebuffer(n.FRAMEBUFFER,y),n.viewport(0,0,y?x:e.width,y?S:e.height),n.disable(n.SCISSOR_TEST),n.clearColor(0,0,0,0),n.clear(n.COLOR_BUFFER_BIT),n.useProgram(o),n.uniform2f(_.res,C,w),n.uniform1i(_.styles,0),n.activeTexture(n.TEXTURE0),n.enable(n.BLEND),n.blendFunc(n.ONE,n.ONE_MINUS_SRC_ALPHA),n.bindBuffer(n.ARRAY_BUFFER,v),n.enableVertexAttribArray(c),n.vertexAttribPointer(c,2,n.FLOAT,!1,0,0),n.vertexAttribDivisor(c,0);for(let e of h)n.enableVertexAttribArray(e),n.vertexAttribDivisor(e,1);let t=D-E||1;for(let e of T){if(!e)continue;n.uniform1f(_.left,e.left),n.uniform1f(_.plotW,e.plotW),n.uniform1f(_.xoff,E-e.origin),n.uniform1f(_.xscale,e.plotW/t),n.uniform1f(_.xR,t),n.uniform1f(_.cutPx,Number.isFinite(O)?e.left+(O-E)*(e.plotW/t):1e9);let{d:r,minGap:i}=P(e);r.total<2||(n.uniform1f(_.minGap,i),n.bindTexture(n.TEXTURE_2D,e.styles),n.bindBuffer(n.ARRAY_BUFFER,r.x),n.vertexAttribPointer(l,1,n.FLOAT,!1,4,0),n.vertexAttribPointer(u,1,n.FLOAT,!1,4,4),n.bindBuffer(n.ARRAY_BUFFER,r.y),n.vertexAttribPointer(d,1,n.FLOAT,!1,4,0),n.vertexAttribPointer(f,1,n.FLOAT,!1,4,4),n.bindBuffer(n.ARRAY_BUFFER,r.starts),n.vertexAttribPointer(p,1,n.UNSIGNED_BYTE,!0,1,1),n.bindBuffer(n.ARRAY_BUFFER,r.sid),n.vertexAttribPointer(m,1,n.FLOAT,!1,4,0),n.drawArraysInstanced(n.TRIANGLE_STRIP,0,4,r.total-1))}for(let e of h)n.vertexAttribDivisor(e,0);y&&(n.bindFramebuffer(n.READ_FRAMEBUFFER,y),n.bindFramebuffer(n.DRAW_FRAMEBUFFER,null),n.blitFramebuffer(0,0,x,S,0,0,e.width,e.height,n.COLOR_BUFFER_BIT,n.LINEAR),n.bindFramebuffer(n.FRAMEBUFFER,null))},dispose(){for(let e of T)j(e);T.length=0,n.deleteBuffer(v),n.deleteFramebuffer(y),n.deleteRenderbuffer(b),n.deleteProgram(o),n.deleteShader(i),n.deleteShader(a),r&&n.getExtension(`WEBGL_lose_context`)?.loseContext()}}}var eH=12,tH=0,nH=null;function rH(){return tH<eH}function iH(){tH++;let e=!1;return()=>{e||(e=!0,tH--)}}var aH=new Set;function oH(){if(nH&&!nH.gl.isContextLost())return nH;let e=document.createElement(`canvas`);e.width=1,e.height=1;let t=e.getContext(`webgl2`,{antialias:!1,alpha:!0,premultipliedAlpha:!0,preserveDrawingBuffer:!1});return nH=t?{canvas:e,gl:t}:null,e.addEventListener(`webglcontextlost`,e=>{e.preventDefault(),setTimeout(()=>{for(let e of[...aH])e()},0)}),nH}function sH(e,t=!1){if(t&&tH<eH){let t=iH();return{canvas:e,shared:!1,present(){},lost:()=>!1,release(){t();try{e.getContext(`webgl2`)?.getExtension(`WEBGL_lose_context`)?.loseContext()}catch{}}}}let n=oH();if(!n)return{canvas:e,shared:!1,present(){},lost:()=>!1,release(){}};let r=1,i=1,a={get width(){return r},set width(e){r=Math.max(1,Math.round(e)),n.canvas.width<r&&(n.canvas.width=r)},get height(){return i},set height(e){i=Math.max(1,Math.round(e)),n.canvas.height<i&&(n.canvas.height=i)},getContext(e){return e===`webgl2`?n.gl:null}},o=null;return{canvas:a,shared:!0,present(){e.width!==r&&(e.width=r),e.height!==i&&(e.height=i),o??=e.getContext(`2d`),o&&(o.globalCompositeOperation=`copy`,o.drawImage(n.canvas,0,n.canvas.height-i,r,i,0,0,r,i),o.globalCompositeOperation=`source-over`)},lost:()=>n.gl.isContextLost(),release(){}}}var cH=new WeakMap;function lH(e,t,n){let r=cH.get(e);return r||cH.set(e,r=new Map),r.has(t)||r.set(t,n()),r.get(t)}function uH(e,t){let n=sH(e),r=t(n.canvas);if(!r)return n.release(),null;let i=new Map,a=(e,t)=>{let n=t[0];return typeof n==`string`||typeof n==`number`&&(e===`setData`||e===`setStyles`)?`${e}:${n}`:e},o=(e,t)=>{let n=e=>{for(let t of[...i.keys()]){let n=t.indexOf(`:`);n>0&&!e(t.slice(n+1))&&i.delete(t)}};if(e===`remove`||e===`clearLayer`)n(e=>e!==String(t[0]));else if(e===`keep`&&Array.isArray(t[0])){let e=new Set(t[0].map(String));n(t=>e.has(t))}},s=()=>{try{r.dispose()}catch{}n.release(),n=sH(e);let a=t(n.canvas);if(!a)return!1;r=a;let o=[...i.values()];for(let e of o.filter(e=>e.name===`resize`).concat(o.filter(e=>e.name!==`resize`)))r[e.name](...e.args);return!0},c=()=>(n.lost()&&s(),r),l=()=>{n.lost()&&s()&&(r.render(),n.present())};return aH.add(l),new Proxy({},{get(e,t){if(t===`dispose`)return()=>{aH.delete(l),i.clear(),r.dispose(),n.release()};if(t===`render`)return()=>{c().render(),n.present()};let s=c()[t];return typeof s!=`function`||typeof t!=`string`?s:(...e)=>{if(o(t,e),t.startsWith(`set`)||t===`resize`){let n=a(t,e),r=i.get(n),o=t===`setData`&&typeof e[0]==`number`&&e[1]===null&&r?[e[0],r.args[1],r.args[2],...e.slice(3)]:e;i.delete(n),i.set(n,{name:t,args:o})}return s.apply(c(),e)}}})}var dH=``+new URL(`assets/offscreenLineWorker-DscQ1i3-.js`,import.meta.url).href;function fH(e,t=1,n){if(typeof e.transferControlToOffscreen!=`function`||typeof Worker>`u`)return null;let r;try{r=AE(dH)}catch{return null}let i;try{i=e.transferControlToOffscreen()}catch{return r.terminate(),null}r.postMessage({type:`init`,canvas:i,lineWidth:t},[i]),r.onmessage=e=>{e.data?.type===`lost`&&n?.()};let a=iH(),o=-1,s=-1,c=-1;return{resize(e,t,n){e===o&&t===s&&n===c||(o=e,s=t,c=n,r.postMessage({type:`resize`,w:e,h:t,dpr:n}))},setData(e,t){let n=[];t.xs&&n.push(t.xs.buffer),t.breaks&&n.push(t.breaks.buffer);for(let e of t.columns)n.push(e.buffer);r.postMessage({type:`data`,layer:e,...t},n)},setStyle(e,t){r.postMessage({type:`style`,layer:e,...t})},clear(e){r.postMessage({type:`clear`,layer:e})},setView(e,t,n){r.postMessage({type:`view`,xmin:e,xmax:t,cut:n})},dispose(){try{r.postMessage({type:`dispose`})}catch{}r.terminate(),a()}}}function pH(e,t=1){let n=uH(e,e=>$V(e,t));if(!n)return null;let r=0,i=1,a,o=``,s=(e,t)=>{n.setStyles(e,t.styles,t.left,t.plotW),r=t.xmin,i=t.xmax,a=t.cut,n.setView(r,i,a),n.render()};return{resize(e,t,r){let i=`${e}|${t}|${r}`;i!==o&&(o=i,n.resize(e,t,r),n.render())},setData(e,t){n.setData(e,t.xs,t.breaks,t.columns),s(e,t)},setStyle(e,t){s(e,t)},clear(e){n.clearLayer(e),n.render()},setView(e,t,o){e===r&&t===i&&o===a||(r=e,i=t,a=o,n.setView(e,t,o),n.render())},dispose(){n.dispose()}}}var mH=new Set;function hH(e){mH.add(e)}function gH(e){mH.delete(e)}function _H(){let e=typeof window>`u`?[]:[window];for(let t of mH)t.closed||e.push(t);return e}var vH=1,yH=new Map;function bH(e){let t=vH++,n=_H();if(n.length===1){let r=n[0].requestAnimationFrame(n=>{yH.delete(t),e(n)});return yH.set(t,[{w:n[0],id:r}]),t}let r=[],i=n=>{yH.has(t)&&(xH(t),e(n))};for(let e of n)r.push({w:e,id:e.requestAnimationFrame(i)});return yH.set(t,r),t}function xH(e){if(e==null)return;let t=yH.get(e);if(t){yH.delete(e);for(let{w:e,id:n}of t)e.closed||e.cancelAnimationFrame(n)}}var SH=new WeakMap;function CH(e){e&&SH.set(e,(SH.get(e)??0)+1)}function wH(e){let t=SH.get(e)??0;for(let n of e.querySelectorAll(`*`))t+=SH.get(n)??0;return t}function TH(){return _H().every(e=>e.document.hidden)}var EH=class{#e;#t=new Map;constructor(e){this.#e=e}observe(e,t){let n=e.ownerDocument.defaultView??window,r=this.#t.get(n);r||(r=new(n.ResizeObserver??ResizeObserver)(e=>this.#e(e,this)),this.#t.set(n,r)),r.observe(e,t)}unobserve(e){for(let t of this.#t.values())t.unobserve(e)}disconnect(){for(let e of this.#t.values())e.disconnect();this.#t.clear()}};function DH(e,t){let n=0,r=null,i=()=>{let e=t();return!!e&&e.isConnected&&typeof e.checkVisibility==`function`&&!e.checkVisibility()},a=t=>{n=0,!i()&&(r=t,e())};return{schedule(){n||=bH(a)},now(){if(i())return;let o=t()?.ownerDocument?.timeline?.currentTime;if(typeof o!=`number`||o===r){n||=bH(a);return}n&&=(xH(n),0),r=o,e()},cancel(){n&&xH(n),n=0}}}function OH(e,t=typeof window>`u`?null:e=>{bH(e)}){let n=!1,r=null;return{set(i){if(r=i,!t){e(i);return}n||(n=!0,t(()=>{n=!1,e(r)}))}}}function kH(e,t,n,r,i){return r+(e-t)/n*(i-r)}function AH(e,t,n,r){let i=new Map,a=n.length;if(a===0)return i;let o=new Float64Array(a),s=new Float64Array(a).fill(1/0);for(let r of e){let e=r.x;for(let i=0;i<a;i++){let a=r.cols.get(n[i]);if(!a)continue;let c=s[i],l=o[i];for(let n=0;n<r.length;n++){let r=e[n],i=r<t?t-r:r-t;if(i>=c)continue;let o=a[n];Number.isFinite(o)&&(c=i,l=o)}s[i]=c,o[i]=l}}for(let e=0;e<a;e++)s[e]!==1/0&&(r&&s[e]>(r.get(n[e])??1/0)||i.set(n[e],o[e]));return i}function jH(e,t,n,r=64){let i=new Map;if(t.length===0||!Number.isFinite(n))return i;let a=new Map;for(let o of e){if(o.length===0)continue;let e=0,s=o.length-1;for(;e<s;){let t=e+s>>1;o.x[t]<n?e=t+1:s=t}for(let s of t){let t=o.cols.get(s);if(t)for(let c=0;c<=r;c++){let r=e-c,l=e+c,u=r>=0&&Number.isFinite(t[r])?r:l<o.length&&Number.isFinite(t[l])?l:-1;if(u<0)continue;let d=Math.abs(o.x[u]-n);d<(a.get(s)??1/0)&&(a.set(s,d),i.set(s,t[u]));break}}}return i}function MH(e,t){let n=new Map;if(t.length===0)return n;for(let r=e.length-1;r>=0&&n.size<t.length;r--){let i=e[r];for(let e of t){if(n.has(e))continue;let t=i.cols.get(e);if(t){for(let r=i.length-1;r>=0;r--)if(Number.isFinite(t[r])){n.set(e,t[r]);break}}}}return n}function NH(e,t){return!(e>0)||!(t>0)?1:1-Math.exp(-e/t)}function PH(e,t,n,r=t){if(!(t>e)||n==null||!(n>0))return[e,t];let i=Number.isFinite(r)?Math.min(t,Math.max(e,r)):t;return i-n<e?[e,Math.min(t,e+n)]:[i-n,i]}function FH(e,t){let n=Math.round(e*t*2);return Math.min(8e3,Math.max(2e3,n))}var IH=.5;function LH(e,t,n,r=IH){if(!(t>0))return e;let i=e!=null&&e>0?Math.min(e,t):t,a=n?i*.88:i/.88;return a>=t*.999?null:Math.max(r,a)}function RH(e=0){return{d:null,lastT:NaN,wall:0,base:NaN,wait:e,waitAge:0}}var zH=new Map;function BH(e,t,n){let r=zH.get(e);if(r||zH.set(e,r={p:RH(),at:NaN,d:NaN}),n-r.at<2&&Number.isFinite(r.d))return r.d;let i=Number.isNaN(r.at)?16:n-r.at;return r.at=n,r.d=KH(r.p,t,i),r.d}var VH=250,HH=3,UH=90,WH=30,GH=.001;function KH(e,t,n){if(!Number.isFinite(t))return t;let r=n/1e3;e.wall+=r;let i=n>VH&&e.d!==null;if(t<e.lastT&&Object.assign(e,RH(),{wall:e.wall}),t<=e.lastT)e.base+=r*GH;else{let n=e.wall-t;e.base=Number.isNaN(e.base)?n:Math.min(e.base+r*GH,n)}e.lastT=t;let a=e.wall-t-e.base;i||(e.waitAge+=r),i||(a>e.wait?(e.wait=Math.min(HH,a),e.waitAge=0):a>e.wait*.8?e.waitAge=0:e.waitAge>UH&&(e.wait*=Math.exp(-r/WH)));let o=e.wall-e.base-Math.min(HH,e.wait*1.2+.05);if(e.d===null)e.d=e.wait>0?Math.min(t,o):t;else if(i||e.d<o-2)e.d=Math.min(t,o);else{let t=Math.min(n,64);e.d+=t/1e3,e.d+=(o-e.d)*Math.min(1,t/500)}return e.d>t&&(e.d=t),e.d}var qH=(e,t)=>e.log?(Math.log10(Math.max(t,Number.MIN_VALUE))-Math.log10(e.v0))/(Math.log10(e.v1)-Math.log10(e.v0)||1):(t-e.v0)/(e.v1-e.v0||1),JH=(e,t)=>e.log?10**(Math.log10(e.v0)+t*(Math.log10(e.v1)-Math.log10(e.v0))):e.v0+t*(e.v1-e.v0),YH=(e,t)=>e.left+qH(e.x,t)*e.width,XH=(e,t)=>JH(e.x,(t-e.left)/(e.width||1)),ZH=(e,t)=>e.top+(1-qH(e.y,t))*e.height,QH=e=>!e||Number.isFinite(e.v0)&&Number.isFinite(e.v1)&&e.v0!==e.v1&&(!e.log||e.v0>0&&e.v1>0),$H=(e,t)=>e===t||!!e&&!!t&&e.v0===t.v0&&e.v1===t.v1&&!!e.log==!!t.log;function eU(){let e=null,t=new Set;return{get:()=>e,set:n=>{if(n&&(n.width>0&&n.height>0?(!QH(n.x)||!QH(n.y))&&(n={...n,x:QH(n.x)?n.x:void 0,y:QH(n.y)?n.y:void 0}):n=null),!(n===e||n&&e&&n.left===e.left&&n.top===e.top&&n.width===e.width&&n.height===e.height&&$H(n.x,e.x)&&$H(n.y,e.y))){e=n;for(let e of[...t])e()}},subscribe:e=>(t.add(e),()=>{t.delete(e)})}}var tU=it(()=>{}),nU=()=>lt(tU),rU=`M5 .8a3.1 3.1 0 0 0-3.1 3.1v2.3L.8 7.6h8.4L8.1 6.2V3.9A3.1 3.1 0 0 0 5 .8zM3.9 8.4a1.1 1.1 0 0 0 2.2 0z`,iU=[5,4],aU=null;function oU(e,t,n,r){typeof Path2D>`u`||(aU??=new Path2D(rU),e.save(),e.setLineDash([]),e.translate(t,n),e.fillStyle=r,e.fill(aU),e.restore())}var sU=(()=>{try{return localStorage.getItem(`glLines`)!==`0`}catch{return!0}})(),cU=(()=>{try{return localStorage.getItem(`offscreenGl`)!==`0`}catch{return!0}})(),lU=70;function uU(e){return e===`dashed`?[5,4]:e===`dotted`?[1,4]:[]}var dU={top:14,right:160,bottom:40,left:110},fU={top:14,right:100,bottom:40,left:70},pU=640,mU={top:3,right:3,bottom:3,left:3},hU=260;function gU(e){return e<hU?mU:e<pU?fU:dU}var _U=220,vU=2e3,yU=4,bU=1e3/120,xU=`11.25px ${Q.mono}`,SU=11*1.125,CU=24*1.125,wU=CU-SU+26,TU=.6,EU=13,DU=10,OU=5,kU=14,AU=4;function jU(e,t,n){return Math.min(n,Math.max(t,e))}function MU(e,t,n,r,i){let a=Math.min(r,i),o=Math.max(r,i);return t+(1-jU(o===a?.5:(e-a)/(o-a),0,1))*(n-t)}function NU(e,t,n,r){let i=e+t;return{bandTop:i-r/100*t,bandBottom:i-n/100*t}}function PU(e){return e.replace(/__(\d+|ref)$/,``)}function FU(e,t,n){let r=Math.floor((n-t-SU)/EU)+1;return Math.max(0,Math.min(e,r))}function IU(e){let t=0;for(let n of e)t+=n.length;return t}function LU(e,t){let n=e.cols.get(t);return n?Float32Array.from(n):new Float32Array(e.length).fill(NaN)}function RU(e){let t=new Map;for(let n of e){let e=PU(n.column),r=t.get(e)??[];r.push(n),t.set(e,r)}let n=new Set,r=[];for(let i of e){let e=PU(i.column);if(n.has(e))continue;n.add(e);let a=t.get(e);r.push({base:e,leader:a[0],members:a})}return r}function zU(e,t,n){let r=new Map,i=e.map((e,r)=>{let{bandTop:i}=NU(t,n,e.leader.bandFromPct,e.leader.bandToPct);return{g:e,i:r,bandTop:i,blockDY:e.members.length>1?SU+(e.members.length+1)*EU:wU}});i.sort((e,t)=>e.bandTop-t.bandTop||e.i-t.i);let a=-1/0;for(let{g:e,bandTop:t,blockDY:n}of i){let i=t+SU,o=Math.max(i,a),s=o-SU;r.set(e.leader.id,s),a=o+n}return r}function BU(e,t){let n=e.cols.get(t);if(!n)return 0;let r=e.x;return n.length===e.length&&u.has(n)?VU(r,e.length):UU(r,e.length,e=>Number.isFinite(n[e]))}function VU(e,t){let n=HU.get(e);return n===void 0&&(n=UU(e,t,()=>!0),HU.set(e,n)),n}var HU=g(new WeakMap);function UU(e,t,n){let r=null,i=0,a=0;for(let o=0;o<t;o++)n(o)&&(r!==null&&e[o]!==r&&(i+=Math.abs(e[o]-r),a++),r=e[o]);return a===0?0:i/a}function WU(e,t){return e>0?Math.max(e*4,t*1e-9):Math.max(t*1e-6,1e-12)}var GU=1e30,KU=250;function qU({xLabel:e,series:t,points:n,columnUnits:r={},height:i=440,onPlotContextMenu:a,backgroundToken:o=``,viewXRange:s=null,onViewXRangeChange:c,liveZoom:l,liveZoomId:u,fullXRange:d=null,shiftMode:f,xAxisLine:p,yAxisLine:m,gridLine:h,lineWidth:g=1,envelopes:_,showLatestValues:v=!1,liveSource:y,liveWindowSeconds:b=null,onLiveWindowChange:x,liveZoomMode:S,onPlotWidthCss:C,onCursorX:w}){let T=nU(),E=K(null),D=K(null),O=K(null),k=K(null),A=K(C);A.current=C;let j=K(-1),M=K(null),N=K(!1),P=K(null),F=K(!1),I=K(!1),L=K(null),R=K(null),z=K({pts:null,layers:[]}),B=K(new Map),V=K([]),ee=K(null),te=K(null),H=K(null),ne=K(null),re=K(0),ie=K(0),U=K(!1),ae=K(0),oe=K(vU),se=K(y),ce=K(null),le=K(RH()),ue=K(0),de=K(void 0),fe=K(0),pe=K(0),me=K(16),he=K(!0),ge=K(!1),[_e,ve]=ft(0);function ye(){P.current?.dispose(),P.current=null,I.current=!1,F.current=!1,V.current=[],ve(e=>e+1)}W(()=>{_e&&St()},[_e]),G(()=>{se.current=y,ce.current=null,z.current={pts:null,layers:[]},B.current.clear()},[y]);let be=K(b);G(()=>{be.current=b},[b]);let xe=K(x);xe.current=x;let Se=S??(x?`follow`:`free`),Ce=K(Se);Ce.current=Se;let we=K(null);G(()=>{we.current=null},[Se,e]);let Te=K([]),Ee=K(!1),De=K(0),Oe=K(0),ke=K(0),Ae=K(0),je=K(`none`),Me=K(0),Ne=K(0),Pe=K(0),Fe=K(null),Ie=K(null),Le=K(f),Re=K(null),ze=K({pts:null,x0:NaN,x1:NaN,ser:null}),Be=K(0),Ve=K(0),He=K(null),Ue=K(null),We=K(null),Ge=K(null);G(()=>{Le.current=f},[f]),W(()=>(L.current&&=(clearTimeout(L.current),null),()=>{M.current?.dispose(),M.current=null;let e=P.current;e&&(L.current=setTimeout(()=>{e.dispose(),P.current===e&&(P.current=null),L.current=null},0))}),[]);let Ke=pt(Wz,Uz),qe=K({xLabel:e,series:t,points:n,height:i,columnUnits:r,shiftMode:f,xAxisLine:p,yAxisLine:m,gridLine:h,lineWidth:g,showLatestValues:v,envelopes:_}),Je=K(null),Ye=K(null);G(()=>{qe.current={xLabel:e,series:t,points:n,height:i,columnUnits:r,shiftMode:f,xAxisLine:p,yAxisLine:m,gridLine:h,lineWidth:g,showLatestValues:v,envelopes:_}},[e,t,n,i,r,f,p,m,h,g,v,_]);let Xe=K(c),Ze=K(w);Ze.current=w,G(()=>{Xe.current=c},[c]);let Qe=K(l),$e=K(u);G(()=>{Qe.current=l,$e.current=u},[l,u]),W(()=>{if(!(!l||!u))return l.subscribe((e,t)=>{e!==u&&(ee.current=t?.[0]??null,te.current=t?.[1]??null,St())})},[l,u]);let et=K(a);G(()=>{et.current=a},[a]);let tt=dt(()=>{if(d&&d[1]>d[0])return{xmin:d[0],xmax:d[1]};let e=1/0,t=-1/0;for(let r of n)for(let n=0;n<r.length;n++){let i=r.x[n];i<e&&(e=i),i>t&&(t=i)}return(!Number.isFinite(e)||e===t)&&(--e,t+=1),{xmin:e,xmax:t}},[n,d]),nt=K(tt);G(()=>{nt.current=tt},[tt]);function rt(){return se.current!=null&&ee.current===null&&te.current===null&&!Ee.current&&Re.current===null}function it(){let{xmin:e,xmax:t}=nt.current,n=ee.current,r=te.current;if(n!==null&&r!==null&&r>n&&Number.isFinite(n)&&Number.isFinite(r))return{xmin:n,xmax:r};let i=H.current,a=ne.current;return rt()&&i!==null&&a!==null&&a>i&&Number.isFinite(i)&&Number.isFinite(a)?{xmin:i,xmax:a}:{xmin:e,xmax:t}}function at(e,t){let n=se.current;if(!n?.latestValues)return MH(e,t);let r=n.latestValues(t),i=t.filter(e=>!r.has(e)),a=n.latestX?.();if(i.length>0&&a!=null)for(let[t,n]of jH(e,i,a))r.set(t,n);return r}function ot(){return se.current?Te.current:qe.current.points}function st(e,t,n){let r=new Map;for(let i of t)r.set(i,WU(ht(e,i),n));return r}function ct(e){if(z.current.pts===e)return z.current.layers;let t=z.current.layers,n=se.current?.version?.(),r=e.map((e,r)=>({pts:e,key:t[r]?.pts===e?t[r].key:n??e}));return z.current={pts:e,layers:r},r}function lt(e,t){let n=B.current.get(e),r=performance.now(),i=n&&(n.key===t.key||typeof t.key==`number`&&typeof n.key==`number`&&r-n.at<KU);return(!n||!i)&&(n={key:t.key,at:r,has:new Map,median:new Map},B.current.set(e,n)),n}function ut(e,t,n){let r=lt(e,t),i=r.has.get(n);if(i===void 0){let e=t.pts.cols.get(n);i=!!e&&e.some(Number.isFinite),r.has.set(n,i)}return i}function mt(e,t){return ct(e).some((e,n)=>ut(n,e,t))}function ht(e,t){let n=ct(e);for(let e=0;e<n.length;e++){if(!ut(e,n[e],t))continue;let r=lt(e,n[e]),i=r.median.get(t);return i===void 0&&(i=BU(n[e].pts,t),r.median.set(t,i)),i}return 0}function gt(){if(Ge.current)return Ge.current;let e=k.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return Ge.current=n,n}function vt(){let e=k.current,t=Math.max(1,e?.clientWidth||200),n=e?.clientHeight??0;return{w:t,h:Math.max(1,n>0?n:qe.current.height)}}function yt(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function bt(){let e=E.current;if(!e)return;let{w:t,h:n}=vt(),r=yt(e,t,n);if(!r)return;{let e=ot(),t=it(),n=qe.current.series,r=ze.current;(r.pts!==e||r.x0!==t.xmin||r.x1!==t.xmax||r.ser!==n)&&(ze.current={pts:e,x0:t.xmin,x1:t.xmax,ser:n},CH(k.current))}let i=gU(t),a=i===mU,{top:o,right:s,bottom:c}=i,l=i.left,u=t-l-s,d=n-o-c,{bg:f,muted:p,grid:m}=gt(),{xLabel:h,series:g,xAxisLine:_,yAxisLine:v,gridLine:y,lineWidth:b,columnUnits:x,showLatestValues:S}=qe.current,C=ot();if(r.fillStyle=f,r.fillRect(0,0,t,n),IU(C)<2||u<=0||d<=0){if(r.fillStyle=p,r.font=`13px ${Q.sans}`,r.fillText(`Not enough data to plot`,l,o+24),M.current&&(M.current.resize(t,n,window.devicePixelRatio||1),M.current.draw([])),P.current){P.current.resize(t,n,window.devicePixelRatio||1);for(let e=0;e<V.current.length;e++)P.current.clear(e);V.current=[]}return}let{xmin:w,xmax:O}=it(),A=O-w,j=e=>l+(e-w)/A*u;T({left:l,top:o,width:u,height:d,x:{v0:w,v1:O}});let R=g.filter(e=>e.bandToPct>e.bandFromPct&&e.scaleMin!==e.scaleMax&&mt(C,e.column)),z=RU(R),B=zU(z,o,d),ee=new Map;for(let e of z){let t=B.get(e.leader.id);t!==void 0&&e.members.forEach(e=>ee.set(e.id,t))}let te=new Set,H=new Set;for(let e of z)e.members.length>1&&e.members.forEach(e=>te.add(e.id)),H.add(e.leader.id);let ne=`11px ${Q.mono}`,re=R.map(e=>{let{bandTop:t,bandBottom:n}=NU(o,d,e.bandFromPct,e.bandToPct),r=Math.min(e.scaleMin,e.scaleMax),i=Math.max(e.scaleMin,e.scaleMax),{majorStep:a,minorStep:s}=Ez(e.scaleMin,e.scaleMax,e.yMajorStep??0,e.yMinorStep??0),c=a,l=Dz(r,i,c);l.length>120&&(l=Dz(r,i,c=Ez(e.scaleMin,e.scaleMax,0,0).majorStep));let u=Oz(r,i,s,l);return u.length>400&&(u=[]),{s:e,bandTop:t,bandBottom:n,majors:l,minors:u,step:c}}),ie=new Map,U=0;{r.save(),r.font=ne;let e=re.filter(e=>H.has(e.s.id));e.sort((e,t)=>{let n=Math.abs(e.s.bandToPct-e.s.bandFromPct),r=Math.abs(t.s.bandToPct-t.s.bandFromPct);return n===r?re.indexOf(e)-re.indexOf(t):r-n});let n=new Map,a=[];for(let t of e){let r=0;for(;r<e.length;r++){let e=a[r];if(!e||e.length===0||!e.some(e=>t.bandTop<e.bandBottom&&t.bandBottom>e.bandTop))break}n.set(t.s.id,r),a[r]||(a[r]=[]),a[r].push(t)}let o=new Map,c=new Map;for(let t of e){let e=0;for(let n of t.majors){let i=jz(n,t.step),a=c.get(i);a===void 0&&c.set(i,a=r.measureText(i).width),a>e&&(e=a)}o.set(t.s.id,e)}let u=[],d=[],f=0;for(let e=0;e<a.length;e++){u[e]=f;let t=0;for(let n of a[e]??[]){let e=o.get(n.s.id)??0;e>t&&(t=e)}d[e]=t,f+=t+22}for(let e of re){let t=n.get(e.s.id)??0;ie.set(e.s.id,u[t]??0)}let p=i.left;for(let e=0;e<a.length;e++){let t=a[e];if(!t||t.length===0)continue;let n=(u[e]??0)+AU+kU+(d[e]??0)+6;n>p&&(p=n)}let m=Math.max(i.left,t-s-Math.max(120,t*.4)),h=Math.min(Math.ceil(p),m);h>l&&(U=h-l),r.restore()}U>0&&(l+=U,u=Math.max(1,t-l-s)),oe.current=FH(u,window.devicePixelRatio||1);let ae=(e,t)=>1-(1-e)**t,se=new Map,ce=new Map;for(let e of re){let t=`${e.bandTop}|${e.bandBottom}|${e.s.scaleMin}|${e.s.scaleMax}|${e.majors.join(`,`)}`,n=se.get(t);n?n.k++:se.set(t,{c:e,k:1});let r=te.has(e.s.id)?p:e.s.color,i=`${e.bandTop}|${e.bandBottom}|${r}`,a=ce.get(i);a?a.k++:ce.set(i,{c:e,color:r,k:1})}if((v?.style??`dashed`)!==`none`)for(let{c:{s:e,bandTop:t,bandBottom:n,majors:i},k:a}of se.values()){r.save(),r.strokeStyle=v?.color??m,r.globalAlpha=ae(.1,a),r.lineWidth=v?.width??1,r.lineCap=`round`,r.setLineDash(uU(v?.style??`dashed`));for(let a of i){let i=MU(a,t,n,e.scaleMin,e.scaleMax);r.beginPath(),r.moveTo(l,i),r.lineTo(l+u,i),r.stroke()}r.restore()}for(let{c:{bandTop:e,bandBottom:t},color:n,k:i}of ce.values())r.strokeStyle=n,r.lineWidth=1,r.setLineDash([]),r.globalAlpha=ae(.45,i),r.beginPath(),r.moveTo(l,e),r.lineTo(l,t),r.stroke(),r.globalAlpha=1;for(let{s:e,bandTop:t,bandBottom:n,majors:i,minors:o,step:s}of a?[]:re){let a=te.has(e.id)?p:e.color;if(H.has(e.id)){let c=ie.get(e.id)??0,u=l-c-AU;r.strokeStyle=a,r.lineWidth=1;for(let i of o){let a=MU(i,t,n,e.scaleMin,e.scaleMax);r.beginPath(),r.moveTo(u-OU,a),r.lineTo(u,a),r.stroke()}r.font=ne,r.textAlign=`right`,r.textBaseline=`middle`,r.strokeStyle=a,r.fillStyle=a;for(let a of i){let i=MU(a,t,n,e.scaleMin,e.scaleMax);r.beginPath(),r.moveTo(u-DU,i),r.lineTo(u,i),r.stroke(),r.fillText(jz(a,s),u-kU,i)}}}if((y?.style??`solid`)!==`none`&&(r.strokeStyle=y?.color??m,r.lineWidth=y?.width??1,r.setLineDash(uU(y?.style??`solid`)),r.strokeRect(l,o,u,d),r.setLineDash([])),(_?.style??`dashed`)!==`none`){r.strokeStyle=_?.color??m,r.lineWidth=_?.width??1,r.setLineDash(uU(_?.style??`dashed`));for(let e=1;e<6;e++){let t=l+e/6*u;r.beginPath(),r.moveTo(t,o),r.lineTo(t,o+d),r.stroke()}r.setLineDash([])}let le=o+d+10;r.fillStyle=p,r.font=`11px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`top`;let ue=Fz(h,w,w+A);for(let e=0;e<=(a?-1:6);e++){let t=w+e/6*A;r.fillText(ue?Gz(t,A/6,A):jz(t,A/6),l+e/6*u,le)}r.textBaseline=`bottom`,a||r.fillText(h,l+u/2,n-5);let{shiftMode:fe}=qe.current;fe&&(r.globalAlpha=.8,r.font=`10px ${Q.sans}`,r.fillStyle=p,r.textAlign=`center`,r.textBaseline=`top`,r.fillText(`⇄ shifting: ${fe.label}`,l+u/2,o+3),r.globalAlpha=1);let pe=qe.current.envelopes;if(pe?.length){r.save(),r.beginPath(),r.rect(l,o,u,d),r.clip();for(let e of pe){let t=R.find(t=>t.id===e.seriesId||t.id.startsWith(`${e.seriesId}__`));if(!t)continue;let{bandTop:n,bandBottom:i}=NU(o,d,t.bandFromPct,t.bandToPct),a=e=>MU(e,n,i,t.scaleMin,t.scaleMax);r.fillStyle=e.color,r.globalAlpha=.2;let s=0;for(;s<e.x.length;){for(;s<e.x.length&&e.lo[s]!==e.lo[s];)s++;let t=s;for(;s<e.x.length&&e.lo[s]===e.lo[s];)s++;if(!(s-t<2)){r.beginPath(),r.moveTo(j(e.x[t]),a(e.hi[t]));for(let n=t+1;n<s;n++)r.lineTo(j(e.x[n]),a(e.hi[n]));for(let n=s-1;n>=t;n--)r.lineTo(j(e.x[n]),a(e.lo[n]));r.closePath(),r.fill()}}}r.restore()}L.current&&=(clearTimeout(L.current),null);let me=cU&&!F.current?P.current:null;if(cU&&!me&&!F.current&&D.current&&!I.current&&(me=rH()?fH(D.current,1,ye):pH(D.current),me?(P.current=me,I.current=!0):F.current=!0),me){me.resize(t,n,window.devicePixelRatio||1);let e=`${l.toFixed(2)}|${u.toFixed(2)}|${o}|${d}|${b}|`+R.map(e=>`${e.id}:${e.column}:${e.bandFromPct}:${e.bandToPct}:${e.scaleMin}:${e.scaleMax}:${e.color}`).join(`,`),r=ct(C),i=V.current;for(let t=0;t<Math.max(r.length,i.length);t++){let n=r[t];if(!n){i[t]&&me.clear(t),i[t]=null;continue}let a=R.filter(e=>ut(t,n,e.column)),s=a.map(e=>e.column).join(`
207
+ `),c=i[t];if(c&&c.pts===n.pts&&c.sig===e&&c.cols===s)continue;i[t]={pts:n.pts,sig:e,cols:s};let f={styles:a.map(e=>{let{bandTop:t,bandBottom:r}=NU(o,d,e.bandFromPct,e.bandToPct);return{color:zV(e.color),bandTop:t,bandBottom:r,scaleMin:e.scaleMin,scaleMax:e.scaleMax,gapMedian:n.pts.hold?GU:ht(C,e.column),width:b}}),left:l,plotW:u,xmin:w,xmax:O,cut:de.current};if(c&&c.pts===n.pts&&c.cols===s){me.setStyle(t,f);continue}let p=n.pts,m=!!c&&c.pts.x===p.x&&c.pts.brk===p.brk&&c.cols===s;me.setData(t,{...f,xs:m?null:p.x.slice(),breaks:m?void 0:p.brk?.slice(),columns:a.map(e=>LU(p,e.column))})}i.length=r.length,me.setView(w,O,de.current)}else{let e=M.current;sU&&!e&&!N.current&&D.current&&!I.current&&(e=GV(D.current),e?M.current=e:N.current=!0);let i=!!e;i&&e&&e.resize(t,n,window.devicePixelRatio||1);let a=[],s=st(C,R.map(e=>e.column),A);for(let e of R){let{bandTop:t,bandBottom:n}=NU(o,d,e.bandFromPct,e.bandToPct),c=s.get(e.column);if(i){let r={x:l,y:t,w:u,h:n-t},i=zV(e.color),o=[],s=null,d=()=>{o.length>=4&&a.push({points:Float32Array.from(o),color:i,clip:r,width:b}),o=[]};for(let r of C){let i=r.cols.get(e.column);if(i){s=null;for(let a=0;a<r.length;a++){r.brk?.[a]&&d();let l=i[a];if(!Number.isFinite(l))continue;let u=r.x[a];s!==null&&!r.hold&&Math.abs(u-s)>c&&d(),o.push(j(u),MU(l,t,n,e.scaleMin,e.scaleMax)),s=u}d()}}d();continue}r.strokeStyle=e.color,r.lineWidth=b,r.lineJoin=`round`,r.lineCap=`round`,r.save(),r.beginPath(),r.rect(l,t,u,n-t),r.clip(),r.beginPath();let f=!1,p=null,m=!1;for(let i of C){let a=i.cols.get(e.column);if(a){m=!0;for(let o=0;o<i.length;o++){i.brk?.[o]&&(m=!0);let s=a[o];if(!Number.isFinite(s))continue;let l=i.x[o],u=j(l),d=MU(s,t,n,e.scaleMin,e.scaleMax);f?m||p!==null&&!i.hold&&Math.abs(l-p)>c?(r.stroke(),r.beginPath(),r.moveTo(u,d),p=l,m=!1):(r.lineTo(u,d),p=l):(r.moveTo(u,d),f=!0,p=l,m=!1)}}}f&&r.stroke(),r.restore()}i&&e&&e.draw(a)}for(let e of R){if(!e.alarm)continue;let{bandTop:t,bandBottom:n}=NU(o,d,e.bandFromPct,e.bandToPct),i=MU(e.alarm.value,t,n,e.scaleMin,e.scaleMax);r.save(),r.beginPath(),r.rect(l,t,u,n-t),r.clip(),r.strokeStyle=e.alarm.color,r.lineWidth=e.alarm.width,r.setLineDash(e.alarm.linked===`active`?iU:uU(e.alarm.style)),r.beginPath(),r.moveTo(l,i),r.lineTo(l+u,i),r.stroke(),r.setLineDash([]),e.alarm.linked&&oU(r,l+u-10-3,i-10-2,e.alarm.color),r.restore()}if(a)return;let he=S?at(C,R.map(e=>e.column)):null,ge=e=>{let t=he?.get(e.column);if(typeof t!=`number`)return`-`;let n=x[e.column]?.trim()??``;return`${Mz(t)}${n?` ${n}`:``}`},_e=l+u+8;r.font=xU,r.textAlign=`left`;for(let e of z){let t=B.get(e.leader.id);if(t===void 0)continue;let i=e.members.length>1;if(r.fillStyle=i?p:e.leader.color,r.globalAlpha=1,r.fillText(e.base,_e,t+SU),i){let i=FU(e.members.length,t,n);for(let n=0;n<i;n++)r.fillStyle=e.members[n].color,r.globalAlpha=TU,r.fillText(ge(e.members[n]),_e,t+SU+(n+1)*EU)}else r.fillStyle=e.leader.color,r.globalAlpha=TU,r.fillText(ge(e.leader),_e,t+CU);r.globalAlpha=1}}function xt(){let e=O.current;if(!e)return;let{w:t,h:n}=vt(),r=yt(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let{top:i,right:a,bottom:o,left:s}=gU(t),c=t-s-a,l=n-i-o,{series:u,columnUnits:d,xLabel:f}=qe.current,p=ot();if(Ee.current&&c>0&&l>0){let e=De.current,t=Oe.current,n=ke.current,i=Ae.current,a=Math.min(e,n),o=Math.min(t,i),s=Math.abs(n-e),c=Math.abs(i-t);r.fillStyle=`rgba(59, 130, 246, 0.12)`,r.fillRect(a,o,s,c),r.strokeStyle=`rgba(59, 130, 246, 0.85)`,r.setLineDash([4,3]),r.lineWidth=1,r.strokeRect(a,o,s,c),r.setLineDash([])}let m=R.current;if(m===null||IU(p)<2||c<=0||l<=0)return;let{xmin:h,xmax:g}=it(),_=u.filter(e=>e.bandToPct>e.bandFromPct&&e.scaleMin!==e.scaleMax&&mt(p,e.column)),v=[...new Set(_.map(e=>e.column))],y=st(p,v,g-h),{bg:b,muted:x}=gt();r.strokeStyle=x,r.globalAlpha=.5,r.lineWidth=1,r.beginPath(),r.moveTo(m,i),r.lineTo(m,i+l),r.stroke(),r.globalAlpha=1;let S=RU(_),C=zU(S,i,l),w=s+c+8;r.font=xU,r.textAlign=`left`;let T=kH(m,s,c,h,g),E=AH(p,T,v,y),D=e=>{let t=E.get(e.column);if(typeof t!=`number`)return`-`;let n=d[e.column]?.trim()??``;return`${Mz(t)}${n?` ${n}`:``}`};for(let e of S){let t=C.get(e.leader.id)??NU(i,l,e.leader.bandFromPct,e.leader.bandToPct).bandTop;if(e.members.length>1){let i=e.members.length*EU+4;r.fillStyle=b,r.fillRect(s+c+6,t+SU+2,a-8,i);let o=FU(e.members.length,t,n);for(let n=0;n<o;n++){let i=e.members[n];r.fillStyle=i.color,r.globalAlpha=TU,r.fillText(D(i),w,t+SU+(n+1)*EU)}}else{let n=e.leader;r.fillStyle=b,r.fillRect(s+c+6,t+SU+2,a-8,CU-SU+6),r.fillStyle=n.color,r.globalAlpha=TU,r.fillText(D(n),w,t+CU)}r.globalAlpha=1}let k=/^(.*?)\s*\(([^)]*)\)\s*$/.exec(f),A=k?k[1]:f,j=k?k[2].trim():``,M=Fz(f,h,g)?Kz(T):``,N=M.lastIndexOf(` `),P=M?[`${A} ${M.slice(0,N)}`,M.slice(N+1)]:[`${A} ${Math.round(T)}${j}`];r.font=xU,r.textAlign=`left`,r.textBaseline=`alphabetic`,P.forEach((e,t)=>{let n=r.measureText(e).width,a=i+l-(P.length-1-t)*15;r.fillStyle=b,r.fillRect(w-2,a-11,n+6,15),r.fillStyle=x,r.globalAlpha=1,r.fillText(e,w,a)})}function St(){if(se.current){U.current=!0;return}He.current=()=>{bt(),xt()},!Be.current&&(Be.current=bH(e=>{Be.current=0;let t=k.current;t&&t.isConnected&&typeof t.checkVisibility==`function`&&!t.checkVisibility()||(Ue.current=e,He.current?.())}))}function Ct(){if(se.current){U.current=!0;return}let e=k.current?.ownerDocument.timeline?.currentTime;if(typeof e!=`number`||e===Ue.current){St();return}Ue.current=e,xH(Be.current),Be.current=0,bt(),xt()}function wt(){We.current=xt,!Ve.current&&(Ve.current=bH(()=>{Ve.current=0,We.current?.()}))}function Tt(e){re.current=bH(Tt);let t=se.current;if(!t)return;me.current+=(Math.min(50,pe.current?e-pe.current:16)-me.current)*.1,pe.current=e;let n=k.current;if(!(he.current&&(!n||typeof n.checkVisibility!=`function`||n.checkVisibility()))){if(!ge.current){ge.current=!0;let e=P.current;e&&(V.current.forEach((t,n)=>{t&&e.clear(n)}),V.current=[],e.resize(1,1,1))}return}if(ge.current=!1,fe.current&&e-fe.current<bU-me.current/2)return;fe.current=e;let r=t.xBounds();r&&r[1]>r[0]&&(nt.current={xmin:r[0],xmax:r[1]});let i=ue.current?e-ue.current:16;ue.current=e,i>250&&(H.current=null,ne.current=null);let a=t.latestT?.(),o;if(a!==void 0&&t.xAtTime&&Number.isFinite(a)){let e=t.id?BH(t.id,a,performance.now()):KH(le.current,a,i),n=t.xAtTime(e);Number.isFinite(n)&&(o=n)}if(rt()){let n=o??t.latestX?.()??nt.current.xmax,r=be.current,i=r!=null&&t.spanForSeconds?t.spanForSeconds(r):r??we.current,[a,s]=PH(nt.current.xmin,nt.current.xmax,i,n??void 0);if(!t.spanForSeconds&&o!==void 0&&o>a&&(s=Math.min(s,o)),Number.isFinite(a)&&Number.isFinite(s)&&s>a){let t=s-a,n=ne.current!==null&&s<ne.current-t;if(H.current===null||ne.current===null||n)H.current=a,ne.current=s,ie.current=e;else{let n=ie.current;ie.current=e;let r=NH(n?Math.min(64,e-n):16,_U);H.current+=(a-H.current)*r,ne.current+=(s-ne.current)*r,Math.abs(a-H.current)<t*1e-6&&(H.current=a),Math.abs(s-ne.current)<t*1e-6&&(ne.current=s)}}}else H.current=null,ne.current=null,ie.current=0;let s=it(),c=t.version?.(),l=oe.current,u=ce.current,d=u!==null&&c!==void 0&&u.ver===c&&u.x0===s.xmin&&u.x1===s.xmax&&u.mp===l&&u.cut===o;(IU(Te.current)===0||!d&&e-ae.current>=yU)&&(ae.current=e,de.current=t.cutOnGpu&&P.current?o:void 0,Te.current=t.pull(s.xmin,s.xmax,l,o,de.current!==void 0),ce.current=c===void 0?null:{ver:c,x0:s.xmin,x1:s.xmax,mp:l,cut:o}),U.current=!1,bt(),xt()}function Et(){re.current||=(ie.current=0,bH(Tt))}function Dt(){re.current&&(xH(re.current),re.current=0,ue.current=0,H.current=null,ne.current=null,Te.current=[],de.current=void 0)}W(()=>{let e=k.current,t=e?.ownerDocument.defaultView?.IntersectionObserver;if(!e||!t)return;let n=new t(e=>{let t=e[e.length-1];(t.isIntersecting||t.boundingClientRect.width>0)&&(he.current=t.isIntersecting)});return n.observe(e),()=>{n.disconnect(),he.current=!0}},[]),W(()=>(y?Et():(Dt(),St()),Dt),[!!y]),W(()=>eB(k.current,()=>{Ge.current=null,St()}),[]),W(()=>{Ge.current=null,St()},[o]);let Ot=!!f;W(()=>{let e=O.current;e&&(e.style.cursor=Ot?`ew-resize`:``),St()},[Ot,f?.label??``]);let kt=s?.[0]??null,At=s?.[1]??null;return G(()=>{ee.current===kt&&te.current===At||(ee.current=kt,te.current=At,St())},[kt,At]),W(()=>{Ct()},[t,n,i,e,p,m,h,g,v,Ke]),W(()=>()=>{xH(Be.current),xH(Ve.current),Be.current=0,Ve.current=0},[]),W(()=>{let e=O.current,t=k.current;if(!e||!t)return;let n=()=>{let e=Math.round(t.clientWidth);e>0&&e!==j.current&&(j.current=e,A.current?.(e))};n();let r=new EH(()=>{Ge.current=null,n(),St()});r.observe(t);let i=OH(e=>Ze.current?.(e)),a=t=>{if(Ee.current||Re.current!==null)return;if(IU(ot())<2){R.current!==null&&(R.current=null,wt(),i.set(null));return}let n=e.getBoundingClientRect(),r=t.clientX-n.left,a=t.clientY-n.top,{left:o,top:s,right:c,bottom:l}=gU(n.width),u=Math.max(1,n.width-o-c),d=n.height-s-l;if(r<o||r>o+u||a<s||a>s+d){R.current!==null&&(R.current=null,wt(),i.set(null));return}R.current!==r&&(R.current=r,wt());let{xmin:f,xmax:p}=it();i.set(kH(r,o,u,f,p))},o=()=>{R.current!==null&&(R.current=null,wt()),i.set(null)},s=e=>{Je.current&&clearTimeout(Je.current),Je.current=setTimeout(()=>{Je.current=null,Xe.current?.(e)},lU)},c=t=>{if(je.current!==`none`||t.buttons&2||Date.now()-Pe.current<300||IU(ot())<2)return;let n=e.getBoundingClientRect(),r=t.clientX-n.left,i=t.clientY-n.top,{top:a,left:o,right:c,bottom:l}=gU(n.width),u=Math.max(1,n.width-o-c),d=Math.max(1,n.height-a-l);if(r<o||r>o+u||i<a||i>a+d)return;t.preventDefault();let f=nt.current,p=f.xmax-f.xmin;if(!(p>0))return;if(Ce.current===`follow`&&rt()&&!xe.current){we.current=LH(we.current,p,t.deltaY<0,p*.001);return}if(Ce.current===`follow`&&rt()){let e=LH(be.current,se.current?.bufferedSeconds?.()??p,t.deltaY<0);be.current=e,Ye.current&&clearTimeout(Ye.current),Ye.current=setTimeout(()=>{Ye.current=null,xe.current?.(e)},lU);return}let m=ee.current??f.xmin,h=(te.current??f.xmax)-m;if(!(h>0))return;let g=Date.now();g-Ne.current>300&&(Fe.current=ee.current,Ie.current=te.current),Ne.current=g;let _=m+(r-o)/u*h,v=t.deltaY<0,y=.88,b=v?h*y:h/y,x=Math.max(p*1e-7,1e-12);if(v)b=Math.max(b,x);else{if(b>=p*.999){ee.current=null,te.current=null,s(null),Qe.current?.publish($e.current??``,null),St();return}b=Math.min(b,p)}let S=(_-m)/h,C=_-S*b,w=_+(1-S)*b;C<f.xmin&&(w+=f.xmin-C,C=f.xmin),w>f.xmax&&(C-=w-f.xmax,w=f.xmax),w-C<b-1e-12&&(C=Math.max(f.xmin,_-b/2),w=C+b,w>f.xmax&&(w=f.xmax,C=w-b)),w-C>=p*.999?(ee.current=null,te.current=null,s(null),Qe.current?.publish($e.current??``,null)):(ee.current=C,te.current=w,s([C,w]),Qe.current?.publish($e.current??``,[C,w])),St()},l=e=>{if(e.preventDefault(),Pe.current=Date.now(),Date.now()-Ne.current<300){ee.current=Fe.current,te.current=Ie.current;let e=Fe.current,t=Ie.current;Je.current&&=(clearTimeout(Je.current),null),Xe.current?.(e===null&&t===null?null:[e,t]),Ne.current=0,St()}},u=t=>{if(t.button===0&&Le.current){let n=e.getBoundingClientRect(),{left:r,top:i,right:a,bottom:o}=gU(n.width),s=Math.max(1,n.width-r-a),c=n.height-i-o,l=t.clientX-n.left,u=t.clientY-n.top;if(l>=r&&l<=r+s&&u>=i&&u<=i+c){Re.current=t.clientX,Le.current.onDragStart();try{e.setPointerCapture(t.pointerId)}catch{}}return}if(t.button!==2)return;if(t.preventDefault(),t.buttons===0){et.current?.({clientX:t.clientX,clientY:t.clientY});return}if(je.current!==`none`){Ee.current=!1,je.current=`none`;try{e.releasePointerCapture(t.pointerId)}catch{}}let n=e.getBoundingClientRect(),r=t.clientX-n.left,i=t.clientY-n.top;Me.current=Date.now(),je.current=`menuOnly`,Ee.current=!1,De.current=r,Oe.current=i,ke.current=r,Ae.current=i;try{e.setPointerCapture(t.pointerId)}catch{}},d=t=>{if(Re.current!==null){let n=t.clientX-Re.current,r=e.getBoundingClientRect(),{left:i,right:a}=gU(r.width),o=Math.max(1,r.width-i-a),{xmin:s,xmax:c}=it(),l=c-s;l>0&&o>0&&Le.current?.onDragOffset(n/o*l);return}if(je.current===`none`)return;let n=e.getBoundingClientRect(),r=t.clientX-n.left,i=t.clientY-n.top;if(je.current===`menuOnly`){if(Date.now()-Me.current<150)return;let e=r-De.current,t=i-Oe.current;if(Math.sqrt(e*e+t*t)<12)return;let a=ot(),{top:o,left:s,right:c,bottom:l}=gU(n.width),u=n.width-s-c,d=n.height-o-l,f=u>0&&d>0&&De.current>=s&&De.current<=s+u&&Oe.current>=o&&Oe.current<=o+d;if(IU(a)<2||!f)return;je.current=`rubber`,Ee.current=!0,R.current=null}je.current===`rubber`&&(t.preventDefault(),ke.current=r,Ae.current=i,wt())},f=t=>{if(t.button!==2)return;t.preventDefault();let n=je.current;je.current=`none`;try{e.releasePointerCapture(t.pointerId)}catch{}if(n===`menuOnly`){Ee.current=!1,wt(),et.current?.({clientX:t.clientX,clientY:t.clientY});return}if(n!==`rubber`||!Ee.current){Ee.current=!1,wt();return}Ee.current=!1;let r=ot(),i=e.getBoundingClientRect(),{left:a,right:o}=gU(i.width),s=Math.max(1,i.width-a-o),c=De.current,l=ke.current,u=Math.abs(l-c);if(IU(r)<2||u<12){et.current?.({clientX:t.clientX,clientY:t.clientY}),wt();return}let d=jU(Math.min(c,l),a,a+s),f=jU(Math.max(c,l),a,a+s),{xmin:p,xmax:m}=it(),h=m-p;if(!(h>0)){et.current?.({clientX:t.clientX,clientY:t.clientY}),wt();return}let g=p+(d-a)/s*h,_=p+(f-a)/s*h;if(g>_){let e=g;g=_,_=e}let v=nt.current,y=Math.min(v.xmin,v.xmax),b=Math.max(v.xmin,v.xmax);g=jU(g,y,b),_=jU(_,y,b);let x=_-g;if(x<=(b-y)*1e-12||x<=0){et.current?.({clientX:t.clientX,clientY:t.clientY}),wt();return}et.current?.({clientX:t.clientX,clientY:t.clientY,zoomXRange:[g,_]}),wt()},p=t=>{if(t.button===0&&Re.current!==null){Re.current=null;try{e.releasePointerCapture(t.pointerId)}catch{}return}if(t.button===2){f(t);return}if(t.buttons===0&&je.current!==`none`){je.current=`none`,Ee.current=!1;try{e.releasePointerCapture(t.pointerId)}catch{}et.current?.({clientX:t.clientX,clientY:t.clientY}),wt()}},m=t=>{Re.current!==null&&(Re.current=null),je.current!==`none`&&(Ee.current=!1,je.current=`none`);try{e.releasePointerCapture(t.pointerId)}catch{}wt()},h=t=>{if(t.button!==0||IU(ot())<2)return;let n=e.getBoundingClientRect(),r=t.clientX-n.left,i=t.clientY-n.top,{top:a,left:o,right:s,bottom:c}=gU(n.width),l=Math.max(1,n.width-o-s),u=Math.max(1,n.height-a-c);r<o||r>o+l||i<a||i>a+u||ee.current===null&&te.current===null||(ee.current=null,te.current=null,Je.current&&=(clearTimeout(Je.current),null),Xe.current?.(null),Qe.current?.publish($e.current??``,null),St(),wt())},g=e=>{if(e.key!==`Escape`)return;let t=!1;je.current!==`none`&&(je.current=`none`,Ee.current=!1,t=!0),Re.current!==null&&(Re.current=null,t=!0),t&&wt()};e.addEventListener(`mousemove`,a),e.addEventListener(`mouseleave`,o),e.addEventListener(`wheel`,c,{passive:!1}),e.addEventListener(`contextmenu`,l),e.addEventListener(`pointerdown`,u),e.addEventListener(`pointermove`,d),e.addEventListener(`pointerup`,p),e.addEventListener(`pointercancel`,m),e.addEventListener(`dblclick`,h);let _=e.ownerDocument.defaultView??window;return _.addEventListener(`keydown`,g),()=>{r.disconnect(),e.removeEventListener(`mousemove`,a),e.removeEventListener(`mouseleave`,o),e.removeEventListener(`wheel`,c),e.removeEventListener(`contextmenu`,l),e.removeEventListener(`pointerdown`,u),e.removeEventListener(`pointermove`,d),e.removeEventListener(`pointerup`,p),e.removeEventListener(`pointercancel`,m),e.removeEventListener(`dblclick`,h),_.removeEventListener(`keydown`,g),Je.current&&clearTimeout(Je.current),Ye.current&&clearTimeout(Ye.current)}},[]),_t(`div`,{ref:k,className:`chart-canvas-wrap`,children:[q(`canvas`,{ref:E,className:`chart-canvas`,role:`img`,"aria-label":`Chart of ${e}`}),q(`canvas`,{ref:D,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}},_e),q(`canvas`,{ref:O,className:`chart-canvas chart-overlay`})]})}function JU(){try{if(localStorage.getItem(`perfLog`)===`1`)return!0;if(localStorage.getItem(`perfLog`)===`0`)return!1}catch{}return!1}var YU=!1;function XU(){let e=JU();return e&&!YU&&(YU=!0,console.log(`[perf] logging enabled — zoom an out-of-core chart to see decimate()/sampleRows timings`)),e}XU();var ZU=new Map;function QU(e,t){let n=(ZU.get(e)??0)+1;ZU.set(e,n),console.log(`[perf] ${e} #${n} ${t.toFixed(1)}ms`)}async function $U(e,t){if(!XU())return t();let n=performance.now();try{return await t()}finally{QU(e,performance.now()-n)}}var eW=20;async function tW(e,t,n,r){let{x0:i,bucket:a,rows:o,columns:s}=await $U(`decimate(${t.length}col)`,()=>e.getSeriesMulti(t,n,r));return T(o,s,i,a)}function nW(e,t,n,r,i=0,a=!1,o=0){let[s,c]=ft({points:Ye,fetchedViewport:null}),[l,u]=ft(!1),d=`${t.join(`,`)}|${n?`${n.xKey}:${n.x0}:${n.x1}`:`none`}|${r}|${i}`,f=dt(()=>{if(!a||!e?.getSeriesMultiSync||!n||t.length===0)return null;let i=o>0?e.getColumnsSync?.(t,n,o):null;if(i)return{points:i,loading:!1,fetchedViewport:n,full:!0};let s=e.getSeriesMultiSync(t,n,r);return{points:T(s.rows,s.columns,s.x0,s.bucket),loading:!1,fetchedViewport:n}},[a,e,d,o]);return W(()=>{if(a)return;if(!e||!n||t.length===0){c({points:Ye,fetchedViewport:null});return}let i=!0;u(!0);let o=setTimeout(()=>{tW(e,t,n,r).then(t=>{i&&(c({points:t,fetchedViewport:n,source:e}),u(!1))}).catch(()=>{i&&u(!1)})},eW);return()=>{i=!1,clearTimeout(o)}},[e,d,a]),f||(s.source!==void 0&&s.source!==e?{points:Ye,loading:l,fetchedViewport:null}:{points:s.points,loading:l,fetchedViewport:s.fetchedViewport})}var rW=250,iW=2,aW=6e3,oW=2e6,sW=[];function cW(e,t,n,r,i,a){let o=!!e&&e.columnSet.has(n),s=dt(()=>e&&o?t.filter(t=>e.columnSet.has(t)):sW,[e,o,t]),c=e&&o&&s.length>0?e.source:null,l=!!c&&!e?.live&&!!c.getSeriesMultiSync&&!!c.xBoundsSync,u=dt(()=>l&&c?c.xBoundsSync(n):null,[l,c,n]),[d,f]=ft(null),p=!!e?.live;W(()=>{if(!c||l)return;let e=!0,t=()=>c.xBounds(n).then(t=>{let r=c.version?.()??0;e&&f(e=>e&&e.source===c&&e.xKey===n&&e.ver===r?e:{source:c,xKey:n,b:t,ver:r})}).catch(()=>{});t();let r=p?setInterval(t,rW):void 0;return()=>{e=!1,clearInterval(r)}},[c,n,p,l]);let m=d&&d.source===c&&d.xKey===n?d:null,h=u??m?.b??null,g=m?.ver??0,{points:_,loading:v,full:y}=nW(c,s,c&&h&&h.x1>h.x0?{xKey:n,x0:h.x0,x1:h.x1}:null,Math.min(aW,i*iW),g,l,a),b=e?.xOffset??0,x=r&&r[1]>r[0]?r[0]-b:null,S=r&&r[1]>r[0]?r[1]-b:null,C=y||!!h&&x!==null&&S!==null&&x<=h.x0&&S>=h.x1,{points:w,fetchedViewport:T}=nW(c,s,c&&x!==null&&S!==null&&!C?{xKey:n,x0:x,x1:S}:null,i,g,l,a),E=dt(()=>!T||w.length===0?_:Je([N(_,e=>e<T.x0),w,N(_,e=>e>T.x1)]),[_,w,T]),D=!!c&&(h===null||v);return dt(()=>e?{points:Te(E,e.keySuffix,e.xOffset),bounds:h?{x0:h.x0+e.xOffset,x1:h.x1+e.xOffset}:null,loading:D}:{points:Ye,bounds:null,loading:!1},[e,E,h,D])}var lW=new WeakMap,uW=0;function dW(e){if(e.key!==void 0)return e.key;let t=lW.get(e.source);return t===void 0&&lW.set(e.source,t=uW++),`${t}${e.keySuffix}`}function fW(){let[e,t]=ft(()=>new Map);return[e,ct((e,n)=>t(t=>{if(n?t.get(e)===n:!t.has(e))return t;let r=new Map(t);return n?r.set(e,n):r.delete(e),r}),[])]}var pW=ot(function({id:e,layer:t,columns:n,xKey:r,view:i,mp:a,rawLimit:o,report:s}){let c=cW(t,n,r,i,a,o);return G(()=>{s(e,c)},[e,c,s]),G(()=>()=>s(e,null),[e,s]),null});function mW({layers:e,xKey:t,columns:n,maxPoints:r,...i}){let a=i.viewXRange??null,[o,s]=ft(null),c=typeof window<`u`?Math.min(3,Math.max(1,window.devicePixelRatio||1)):1,l=o==null?r:Math.min(r,Math.round(o*c/50)*50),u=Math.max(1e3,Math.round(l/Math.sqrt(Math.max(1,e.length)))),d=Math.floor(oW/Math.max(1,e.length)),[f,p]=fW(),m=dt(()=>e.map(dW),[e]),h=dt(()=>m.map(e=>f.get(e)),[m,f]),g=dt(()=>h.flatMap(e=>e&&e.points.length>0?[e.points]:[]),[h]),_=dt(()=>{let e=1/0,t=-1/0;for(let n of h){let r=n?.bounds;r&&(e=Math.min(e,r.x0),t=Math.max(t,r.x1))}return Number.isFinite(e)&&t>e?[e,t]:null},[h]),v=h.some(e=>!e||e.loading);return _t(gt,{children:[e.map((e,r)=>q(pW,{id:m[r],layer:e,columns:n,xKey:t,view:a,mp:u,rawLimit:d,report:p},m[r])),g.length===0?_t(`div`,{className:`chart-placeholder chart-placeholder--no-data`,onContextMenu:e=>{e.preventDefault(),i.onPlotContextMenu?.({clientX:e.clientX,clientY:e.clientY})},children:[q(`span`,{className:`content-empty-icon`,"aria-hidden":!0}),q(`h2`,{children:v?`Loading…`:`No data for the selected X axis`}),v?null:q(`p`,{children:`None of the selected datasets has this X column together with a plotted channel.`})]}):q(qU,{points:g,fullXRange:_,...i,onPlotWidthCss:s})]})}function hW(e){return!!e&&!Array.isArray(e)&&typeof e.length==`number`&&`x`in e&&`y`in e}function gW(e){let t=e.length,n=new Float64Array(t),r=new Float64Array(t),i=t>0&&e[0].c!==void 0?new Float32Array(t):void 0,a=e.some(e=>e.d!==void 0)?new Uint8Array(t):void 0;for(let o=0;o<t;o++){let t=e[o];n[o]=t.x,r[o]=t.y,i&&(i[o]=t.c??0),a&&(a[o]=t.d??0)}return{length:t,x:n,y:r,c:i,d:a}}function _W(e,t,n){let r=n?.get(t);if(r)return r;let i=Ue(e);if(i)return pe(i,t);if(e.length===0||!(t in e[0]))return;let a=new Float64Array(e.length);for(let n=0;n<e.length;n++){let r=e[n][t];a[n]=typeof r==`number`?r:NaN}return a}function vW(e,t,n){let r=_W(e,t,n);if(!r||u.has(r))return r;let i=0;for(let e=0;e<r.length;e++)r[e]-r[e]===0&&i++;if(i===r.length)return r;let a=new Float64Array(i);for(let e=0,t=0;e<r.length;e++)r[e]-r[e]===0&&(a[t++]=r[e]);return a}function yW(e,t,n,r){if(!n){let n=vW(e,t,r);return n?[{label:t,values:n}]:[]}let i=_W(e,t,r);if(!i)return[];let a=i.length,o=r?.has(n)||e.length>0&&typeof e[0][n]==`number`?_W(e,n,r):void 0,s=t=>{if(o){let e=o[t];return e===e?String(e):`unknown`}return String(e[t]?.[n]??`unknown`)},c=new Map,l=[],u=new Int32Array(a),d=[];for(let e=0;e<a;e++){if(i[e]-i[e]!==0){u[e]=-1;continue}let t=s(e),n=c.get(t);n===void 0&&(c.set(t,n=l.length),l.push(t),d.push(0)),u[e]=n,d[n]++}let f=l.map((e,t)=>({label:e,values:new Float64Array(d[t])})),p=new Int32Array(l.length);for(let e=0;e<a;e++){let t=u[e];t>=0&&(f[t].values[p[t]++]=i[e])}return f}function bW(e){let t=NaN,n=NaN,r=0;for(let i=0;i<e.length;i++){let a=e[i];a-a===0&&(r===0&&(t=a),n=a,r++)}let i=n-t;return r>1&&i>0?(r-1)/i:null}function xW(e,t,n){let r=0;for(let i=0;i<e.length;i++)e[i]>=t&&e[i]<=n&&r++;let i=new Uint32Array(r),a=0;for(let r=0;r<e.length;r++)e[r]>=t&&e[r]<=n&&(i[a++]=r);return i}function SW(e,t){let n=new Float64Array(t.length);for(let r=0;r<t.length;r++)n[r]=e[t[r]];return n}function CW(e,t,n,r){let i=_W(e.rows,t,e.full),a=_W(e.rows,n,e.full);if(!i||!a)return null;let o=r.colorCol?_W(e.rows,r.colorCol,e.full):void 0;if(r.viewXRange){let t=_W(e.rows,r.xKey,e.full);if(t){let e=xW(t,r.viewXRange[0],r.viewXRange[1]);i=SW(i,e),a=SW(a,e),o&&=SW(o,e)}}let s=Math.min(i.length,a.length);if(!o)return{cols:{length:s,x:i,y:a}};let c=1/0,l=-1/0;for(let e=0;e<s;e++){let t=o[e];t<c&&(c=t),t>l&&(l=t)}if(!(l>c))return{cols:{length:s,x:i,y:a}};let u=new Float32Array(s),d=l-c;for(let e=0;e<s;e++){let t=o[e];u[e]=t===t?(t-c)/d:0}return{cols:{length:s,x:i,y:a,c:u},color:{label:r.colorCol,min:c,max:l}}}function wW(e,t,n,r){let i=[],a=[];e.forEach((e,o)=>{a.push(Jz(r.colorOverrides,e.id,o,r.palette));let s=CW(e,t,n,{xKey:r.xKey,viewXRange:r.viewXRange});i.push(s?.cols??{length:0,x:[],y:[]})});let o=i.reduce((e,t)=>e+t.length,0),s=new Float64Array(o),c=new Float64Array(o),l=new Uint8Array(o),u=0;return i.forEach((e,t)=>{for(let t=0;t<e.length;t++)s[u+t]=e.x[t],c[u+t]=e.y[t];l.fill(Math.min(t,255),u,u+e.length),u+=e.length}),{cols:{length:o,x:s,y:c,d:l},colors:a}}var TW=e=>hW(e)?e:gW(e),EW=(e,t,n)=>t===t&&n===n&&(!e||t>=e.xmin&&t<=e.xmax&&n>=e.ymin&&n<=e.ymax);function DW(e,t,n){let r=t+1,i=Array.from({length:r},()=>Array(r).fill(0)),a=Array(r).fill(0),o=new Float64Array(2*r-1),s=0;for(let t=0;t<e.length;t++){let c=e.x[t],l=e.y[t];if(EW(n,c,l)){s++,o[0]=1;for(let e=1;e<o.length;e++)o[e]=o[e-1]*c;for(let e=0;e<r;e++){for(let t=0;t<r;t++)i[e][t]+=o[e+t];a[e]+=o[e]*l}}}if(s<r)return null;let c=i.map((e,t)=>[...e,a[t]]);for(let e=0;e<r;e++){let t=e;for(let n=e+1;n<r;n++)Math.abs(c[n][e])>Math.abs(c[t][e])&&(t=n);if([c[e],c[t]]=[c[t],c[e]],Math.abs(c[e][e])<1e-10)return null;let n=c[e][e];for(let t=e;t<=r;t++)c[e][t]/=n;for(let t=0;t<r;t++){if(t===e)continue;let n=c[t][e];for(let i=e;i<=r;i++)c[t][i]-=n*c[e][i]}}return c.map(e=>e[r])}function OW(e,t,n){return DW(TW(e),t,n)}function kW(e,t){let n=TW(e),r=0,i=0;for(let e=0;e<n.length;e++)EW(void 0,n.x[e],n.y[e])&&(r++,i+=n.y[e]);if(r===0)return 0;let a=i/r,o=0,s=0;for(let e=0;e<n.length;e++){let r=n.x[e],i=n.y[e];if(!EW(void 0,r,i))continue;let c=0;for(let e=t.length-1;e>=0;e--)c=c*r+t[e];o+=(i-a)**2,s+=(i-c)**2}return o<1e-15?1:Math.max(0,1-s/o)}function AW(e,t=4){if(!Number.isFinite(e))return`?`;let n=Math.abs(e);return n===0?`0`:n>=1e5||n>0&&n<.001?e.toExponential(2):e.toPrecision(t).replace(/\.?0+$/,``)}function jW(e,t,n){let r=[];for(let n=e.length-1;n>=0;n--){let i=e[n];n===0?r.push(AW(i)):n===1?r.push(`${AW(i)}·${t}`):r.push(`${AW(i)}·${t}${n>1?`^${n}`:``}`)}return`${n} = ${r.join(` + `).replace(/\+ -/g,`− `)}`}var MW=[[0,45,80,160],[.25,40,145,175],[.5,60,180,110],[.75,220,175,55],[1,210,75,55]];function NW(e){let t=0;for(let n=1;n<MW.length;n++){if(e<=MW[n][0]){t=n-1;break}n===MW.length-1&&(t=n-1)}let n=t+1,r=(e-MW[t][0])/(MW[n][0]-MW[t][0]);return{r:Math.round(MW[t][1]+r*(MW[n][1]-MW[t][1])),g:Math.round(MW[t][2]+r*(MW[n][2]-MW[t][2])),b:Math.round(MW[t][3]+r*(MW[n][3]-MW[t][3]))}}function PW(e){let{r:t,g:n,b:r}=NW(e);return`rgb(${t},${n},${r})`}function FW(e,t){if(!Number.isFinite(e))return 0;let n=Math.floor(e*t);return n<0?0:n>=t?t-1:n}var IW=`#version 300 es
208
208
  in vec2 a_corner;
209
209
  in float a_x;
210
210
  in float a_y;
@@ -229,7 +229,7 @@ void main() {
229
229
  v_tex = (clamp(floor(a_k * u_kScale + 0.5), 0.0, 255.0) + 0.5) / 256.0;
230
230
  vec2 clip = pos / u_resolution * 2.0 - 1.0;
231
231
  gl_Position = vec4(clip.x, -clip.y, 0.0, 1.0);
232
- }`,FW=`#version 300 es
232
+ }`,LW=`#version 300 es
233
233
  precision highp float;
234
234
  in vec2 v_local;
235
235
  in float v_tex;
@@ -249,7 +249,7 @@ void main() {
249
249
  vec4 c = texture(u_palette, vec2(v_tex, 0.5));
250
250
  float a = c.a * u_alpha * cov;
251
251
  outColor = vec4(c.rgb * a, a);
252
- }`,IW=`#version 300 es
252
+ }`,RW=`#version 300 es
253
253
  in float a_x;
254
254
  in float a_y;
255
255
  in float a_k;
@@ -268,7 +268,7 @@ void main() {
268
268
  v_tex = (clamp(floor(a_k * u_kScale + 0.5), 0.0, 255.0) + 0.5) / 256.0;
269
269
  vec2 clip = p / u_resolution * 2.0 - 1.0;
270
270
  gl_Position = vec4(clip.x, -clip.y, 0.0, 1.0);
271
- }`,LW=`#version 300 es
271
+ }`,zW=`#version 300 es
272
272
  precision highp float;
273
273
  in float v_tex;
274
274
  uniform sampler2D u_palette;
@@ -287,7 +287,7 @@ void main() {
287
287
  vec4 c = texture(u_palette, vec2(v_tex, 0.5));
288
288
  float a = c.a * u_alpha * cov;
289
289
  outColor = vec4(c.rgb * a, a);
290
- }`,RW=`#version 300 es
290
+ }`,BW=`#version 300 es
291
291
  in vec2 a_corner;
292
292
  in float a_ax;
293
293
  in float a_ay;
@@ -322,7 +322,7 @@ void main() {
322
322
  v_tex = (clamp(floor(a_k * u_kScale + 0.5), 0.0, 255.0) + 0.5) / 256.0;
323
323
  vec2 clip = pos / u_resolution * 2.0 - 1.0;
324
324
  gl_Position = vec4(clip.x, -clip.y, 0.0, 1.0);
325
- }`,zW=`#version 300 es
325
+ }`,VW=`#version 300 es
326
326
  precision highp float;
327
327
  flat in vec2 v_a;
328
328
  flat in vec2 v_b;
@@ -343,7 +343,7 @@ void main() {
343
343
  vec4 c = texture(u_palette, vec2(v_tex, 0.5));
344
344
  float a = c.a * cov;
345
345
  outColor = vec4(c.rgb * a, a);
346
- }`,BW=`
346
+ }`,HW=`
347
347
  uniform vec2 u_ox;
348
348
  uniform vec2 u_oy;
349
349
  float dbl(uvec2 b, vec2 o) {
@@ -357,21 +357,21 @@ float dbl(uvec2 b, vec2 o) {
357
357
  float l = float(b.x & 0x1FFFFFFFu) * exp2(float(int(e) - 1075));
358
358
  return (h - o.x) + ((sgn != 0u ? -l : l) - o.y);
359
359
  }
360
- `;function VW(e,t,n,r){let i=BW,a=e,o=[];for(let[e,r]of[[t,`u_ox`],[n,`u_oy`]])for(let t of e)a=a.replace(`in float ${t};`,`in uvec2 ${t}_bits;`),o.push(` float ${t} = dbl(${t}_bits, ${r});`);let s=[...t,...n].map(e=>`${e} != ${e}`).join(` || `),c=r?`\n if (${s}) { gl_Position = vec4(2.0, 2.0, 2.0, 1.0); return; }`:``;return a.replace(`void main() {`,`${i}void main() {\n${o.join(`
361
- `)}${c}`)}var HW=`#version 300 es
360
+ `;function UW(e,t,n,r){let i=HW,a=e,o=[];for(let[e,r]of[[t,`u_ox`],[n,`u_oy`]])for(let t of e)a=a.replace(`in float ${t};`,`in uvec2 ${t}_bits;`),o.push(` float ${t} = dbl(${t}_bits, ${r});`);let s=[...t,...n].map(e=>`${e} != ${e}`).join(` || `),c=r?`\n if (${s}) { gl_Position = vec4(2.0, 2.0, 2.0, 1.0); return; }`:``;return a.replace(`void main() {`,`${i}void main() {\n${o.join(`
361
+ `)}${c}`)}var WW=`#version 300 es
362
362
  in uvec2 a_x_bits;
363
363
  in uvec2 a_y_bits;
364
364
  out float v_x;
365
365
  out float v_y;
366
- ${BW}
366
+ ${HW}
367
367
  void main() {
368
368
  v_x = dbl(a_x_bits, u_ox);
369
369
  v_y = dbl(a_y_bits, u_oy);
370
370
  gl_Position = vec4(0.0);
371
- }`,UW=`#version 300 es
371
+ }`,GW=`#version 300 es
372
372
  precision mediump float;
373
373
  out vec4 o;
374
- void main() { o = vec4(0.0); }`;function WW(e,t,n,r){let i=WV(e,e.VERTEX_SHADER,t),a=WV(e,e.FRAGMENT_SHADER,n);if(!i||!a)return null;let o=e.createProgram();return e.attachShader(o,i),e.attachShader(o,a),r&&e.transformFeedbackVaryings(o,r,e.SEPARATE_ATTRIBS),e.linkProgram(o),e.getProgramParameter(o,e.LINK_STATUS)?{prog:o,shaders:[i,a]}:(console.error(`glPoints program link failed:`,e.getProgramInfoLog(o)),null)}function GW(e){let t=e.getContext(`webgl2`,{antialias:!1,alpha:!0,premultipliedAlpha:!0});if(!t)return null;let n=cH(t,`glPoints|points`,()=>WW(t,PW,FW)),r=cH(t,`glPoints|lines`,()=>WW(t,RW,zW)),i=cH(t,`glPoints|points64`,()=>WW(t,VW(PW,[`a_x`],[`a_y`],!0),FW)),a=cH(t,`glPoints|sprites`,()=>WW(t,IW,LW)),o=cH(t,`glPoints|sprites64`,()=>WW(t,VW(IW,[`a_x`],[`a_y`],!0),LW)),s=t.getParameter(t.ALIASED_POINT_SIZE_RANGE)[1],c=cH(t,`glPoints|decode`,()=>WW(t,HW,UW,[`v_x`,`v_y`])),l=t.createVertexArray();if(!n||!r)return null;let d=(e,n)=>Object.fromEntries(n.map(n=>[n,t.getAttribLocation(e,n)])),f=(e,n)=>Object.fromEntries(n.map(n=>[n,t.getUniformLocation(e,n)])),p=d(n.prog,[`a_corner`,`a_x`,`a_y`,`a_k`,`a_r`]),m=f(n.prog,[`u_resolution`,`u_plot`,`u_view`,`u_radius`,`u_kScale`,`u_palette`,`u_alpha`,`u_clip`,`u_dpr`,`u_height`]),h=d(r.prog,[`a_corner`,`a_ax`,`a_ay`,`a_bx`,`a_by`,`a_bstart`,`a_k`]),g=f(r.prog,[`u_resolution`,`u_plot`,`u_view`,`u_ext`,`u_kScale`,`u_palette`,`u_half`,`u_clip`]),_=i&&d(i.prog,[`a_corner`,`a_x_bits`,`a_y_bits`,`a_k`,`a_r`]),v=i&&f(i.prog,[`u_resolution`,`u_plot`,`u_view`,`u_radius`,`u_kScale`,`u_palette`,`u_alpha`,`u_clip`,`u_dpr`,`u_height`,`u_ox`,`u_oy`]),y=[`u_resolution`,`u_plot`,`u_view`,`u_radius`,`u_kScale`,`u_palette`,`u_alpha`,`u_clip`,`u_dpr`,`u_height`],b=a&&d(a.prog,[`a_x`,`a_y`,`a_k`]),x=a&&f(a.prog,y),S=o&&d(o.prog,[`a_x_bits`,`a_y_bits`,`a_k`]),C=o&&f(o.prog,[...y,`u_ox`,`u_oy`]),w=c&&d(c.prog,[`a_x_bits`,`a_y_bits`]),T=c&&f(c.prog,[`u_ox`,`u_oy`]),E=t.createTransformFeedback(),D=t.createVertexArray(),O=t.createBuffer(),k=t.createBuffer(),A=!1,j=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,j),t.bufferData(t.ARRAY_BUFFER,Float32Array.from([-1,-1,1,-1,-1,1,1,1]),t.STATIC_DRAW);let M=t.createBuffer(),N=t.createBuffer(),P=t.createBuffer(),F=t.createBuffer(),I=t.createBuffer(),L=t.createTexture(),R=0,z=!1,B=!1,V=!1,ee=0,te=0,H=1,ne=1,re=1,ie=1.8,U=.8,ae=255,oe=!0,se=!1,ce=1,le={xmin:0,xmax:1,ymin:0,ymax:1},ue={left:0,top:0,width:1,height:1},de=new Float32Array,fe=new Float32Array,pe=new Float32Array,me=new Uint8Array,he=new Float32Array,ge=new Map,_e=(e,n,r)=>{t.bindBuffer(t.ARRAY_BUFFER,e);let i=r*n.BYTES_PER_ELEMENT;i<=(ge.get(e)??0)?t.bufferSubData(t.ARRAY_BUFFER,0,n,0,r):(t.bufferData(t.ARRAY_BUFFER,n.subarray(0,r),t.DYNAMIC_DRAW),ge.set(e,i))},ve=(e,n,r=0,i=t.FLOAT)=>{t.bindBuffer(t.ARRAY_BUFFER,n),t.enableVertexAttribArray(e);let a=i===t.FLOAT?4:1;t.vertexAttribPointer(e,1,i,i!==t.FLOAT,a,r*a),t.vertexAttribDivisor(e,1)},ye=(e,n,r=0)=>{t.bindBuffer(t.ARRAY_BUFFER,n),t.enableVertexAttribArray(e),t.vertexAttribIPointer(e,2,t.UNSIGNED_INT,8,r*8),t.vertexAttribDivisor(e,1)},be=e=>{t.bindBuffer(t.ARRAY_BUFFER,j),t.enableVertexAttribArray(e),t.vertexAttribPointer(e,2,t.FLOAT,!1,0,0),t.vertexAttribDivisor(e,0)};return{resize(t,n,r){H=Math.max(1,t),ne=Math.max(1,n),re=r,e.width=Math.round(H*re),e.height=Math.round(ne*re)},setData(e,t,n,r=!1,i){let a=Math.min(e.length,t.length);de.length<a&&(de=new Float32Array(a),fe=new Float32Array(a)),z=!!n,B=!!i,n&&pe.length<a&&(pe=new Float32Array(a)),i&&he.length<a&&(he=new Float32Array(a)),se&&me.length<a&&(me=new Uint8Array(a)),ee=0,te=0;for(let n=0;n<a;n++)if(e[n]-e[n]===0&&t[n]-t[n]===0){ee=e[n],te=t[n];break}let o=u.has(e)&&u.has(t);if(V=!!_&&!!c&&e instanceof Float64Array&&t instanceof Float64Array&&(o||!se),A=!1,V){if(_e(M,e,a),_e(N,t,a),n){for(let e=0;e<a;e++)pe[e]=n[e];_e(P,pe,a)}if(i){for(let e=0;e<a;e++)he[e]=i[e];_e(I,he,a)}if(se){if(me.fill(0,0,a),a&&(me[0]=255),n&&r)for(let e=1;e<a;e++)n[e]!==n[e-1]&&(me[e]=255);_e(F,me,a)}R=a;return}let s=0;if(u.has(e)&&u.has(t)){for(let t=0;t<a;t++)de[t]=e[t]-ee;for(let e=0;e<a;e++)fe[e]=t[e]-te;if(n)for(let e=0;e<a;e++)pe[e]=n[e];if(i)for(let e=0;e<a;e++)he[e]=i[e];if(se&&(me.fill(0,0,a),a&&(me[0]=255),n&&r))for(let e=1;e<a;e++)n[e]!==n[e-1]&&(me[e]=255);s=a}else{let o=!0;for(let c=0;c<a;c++){let a=e[c],l=t[c];if(a-a!==0||l-l!==0){o=!0;continue}de[s]=a-ee,fe[s]=l-te,n&&(pe[s]=n[c]),i&&(he[s]=i[c]),se&&(me[s]=o||r&&n&&s>0&&n[c]!==pe[s-1]?255:0),o=!1,s++}}R=s,_e(M,de,s),_e(N,fe,s),n&&_e(P,pe,s),i&&_e(I,he,s),se&&_e(F,me,s)},setStyle(e,n,r){ie=n,U=r;let i=new Uint8Array(256*4);if(e.kind===`single`){let t=e.rgba.map(e=>Math.round(e*255));for(let e=0;e<256;e++)i.set(t,e*4);ae=0}else i.set(e.palette.subarray(0,256*4)),ae=e.kind===`colormap`?255:1;t.bindTexture(t.TEXTURE_2D,L),t.texImage2D(t.TEXTURE_2D,0,t.RGBA8,256,1,0,t.RGBA,t.UNSIGNED_BYTE,i),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE)},setDraw(e,t,n){oe=e,se=t,ce=n},setView(e,t,n,r,i){le={xmin:e,xmax:t,ymin:n,ymax:r},ue=i},render(){if(t.bindFramebuffer(t.FRAMEBUFFER,null),t.viewport(0,0,e.width,e.height),t.disable(t.SCISSOR_TEST),t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT),R===0)return;t.bindVertexArray(l),t.enable(t.BLEND),t.blendFunc(t.ONE,t.ONE_MINUS_SRC_ALPHA),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,L);let u=z?ae:0,d=[le.xmin-ee,le.xmax-ee,le.ymin-te,le.ymax-te],f=[ue.left,ue.top,ue.left+ue.width,ue.top+ue.height],y=e=>{let t=Math.fround(e);return[t,e-t]},j=V,de=M,fe=N;if(V&&se&&R>1){if(!A){for(let e of[O,k])t.bindBuffer(t.ARRAY_BUFFER,e),(ge.get(e)??0)<R*4&&(t.bufferData(t.ARRAY_BUFFER,R*4,t.DYNAMIC_COPY),ge.set(e,R*4));t.bindBuffer(t.ARRAY_BUFFER,null),t.bindVertexArray(D),t.useProgram(c.prog),t.uniform2f(T.u_ox,...y(ee)),t.uniform2f(T.u_oy,...y(te)),ye(w.a_x_bits,M),ye(w.a_y_bits,N),t.vertexAttribDivisor(w.a_x_bits,0),t.vertexAttribDivisor(w.a_y_bits,0),t.enable(t.RASTERIZER_DISCARD),t.bindTransformFeedback(t.TRANSFORM_FEEDBACK,E),t.bindBufferBase(t.TRANSFORM_FEEDBACK_BUFFER,0,O),t.bindBufferBase(t.TRANSFORM_FEEDBACK_BUFFER,1,k),t.beginTransformFeedback(t.POINTS),t.drawArrays(t.POINTS,0,R),t.endTransformFeedback(),t.bindBufferBase(t.TRANSFORM_FEEDBACK_BUFFER,0,null),t.bindBufferBase(t.TRANSFORM_FEEDBACK_BUFFER,1,null),t.bindTransformFeedback(t.TRANSFORM_FEEDBACK,null),t.disable(t.RASTERIZER_DISCARD),t.bindVertexArray(l),A=!0}j=!1,de=O,fe=k}if(se&&R>1){let e=g,n=h;t.useProgram(r.prog),t.uniform2f(e.u_resolution,H,ne),t.uniform4f(e.u_plot,ue.left,ue.top,ue.width,ue.height),t.uniform4f(e.u_view,...d),t.uniform1f(e.u_half,ce/2),t.uniform1f(e.u_ext,ce/2+1),t.uniform1f(e.u_kScale,u),t.uniform4f(e.u_clip,...f),t.uniform1i(e.u_palette,0),be(n.a_corner),ve(n.a_ax,de,0),ve(n.a_bx,de,1),ve(n.a_ay,fe,0),ve(n.a_by,fe,1),ve(n.a_bstart,F,1,t.UNSIGNED_BYTE),z?ve(n.a_k,P,0):(t.disableVertexAttribArray(n.a_k),t.vertexAttrib1f(n.a_k,0)),t.drawArraysInstanced(t.TRIANGLE_STRIP,0,4,R-1);for(let e of Object.values(n))t.vertexAttribDivisor(e,0)}if(oe&&!B&&2*(ie+.5)*re<=s&&(j?o:a)){let n=j?C:x,r=j?S:b;t.useProgram((j?o:a).prog),j&&(t.uniform2f(n.u_ox,...y(ee)),t.uniform2f(n.u_oy,...y(te))),t.uniform2f(n.u_resolution,H,ne),t.uniform4f(n.u_plot,ue.left,ue.top,ue.width,ue.height),t.uniform4f(n.u_view,...d),t.uniform1f(n.u_radius,ie),t.uniform1f(n.u_kScale,u),t.uniform1f(n.u_alpha,U),t.uniform4f(n.u_clip,...f),t.uniform1f(n.u_dpr,re),t.uniform1f(n.u_height,e.height),t.uniform1i(n.u_palette,0),j?(ye(r.a_x_bits,M),ye(r.a_y_bits,N)):(ve(r.a_x,de),ve(r.a_y,fe)),z?ve(r.a_k,P):(t.disableVertexAttribArray(r.a_k),t.vertexAttrib1f(r.a_k,0));for(let e of Object.values(r))t.vertexAttribDivisor(e,0);t.drawArrays(t.POINTS,0,R)}else if(oe){let r=j?v:m,a=j?_:p;t.useProgram(j?i.prog:n.prog),j&&(t.uniform2f(r.u_ox,...y(ee)),t.uniform2f(r.u_oy,...y(te))),t.uniform2f(r.u_resolution,H,ne),t.uniform4f(r.u_plot,ue.left,ue.top,ue.width,ue.height),t.uniform4f(r.u_view,...d),t.uniform1f(r.u_radius,ie),t.uniform1f(r.u_kScale,u),t.uniform1f(r.u_alpha,U),t.uniform4f(r.u_clip,...f),t.uniform1f(r.u_dpr,re),t.uniform1f(r.u_height,e.height),t.uniform1i(r.u_palette,0),be(a.a_corner),j?(ye(a.a_x_bits,M),ye(a.a_y_bits,N)):(ve(a.a_x,de),ve(a.a_y,fe)),z?ve(a.a_k,P):(t.disableVertexAttribArray(a.a_k),t.vertexAttrib1f(a.a_k,0)),B?ve(a.a_r,I):(t.disableVertexAttribArray(a.a_r),t.vertexAttrib1f(a.a_r,0)),t.drawArraysInstanced(t.TRIANGLE_STRIP,0,4,R);for(let e of Object.values(a))t.vertexAttribDivisor(e,0)}t.bindVertexArray(null)},dispose(){for(let e of[j,M,N,P,F,I,O,k])t.deleteBuffer(e);t.deleteTransformFeedback(E),t.deleteVertexArray(D),t.deleteTexture(L),t.deleteVertexArray(l)}}}var KW={top:3,right:3,bottom:3,left:3};function qW(e,t,n){return t<200||n<120?{...KW,tiny:!0}:{...e,tiny:!1}}var JW={top:14,right:24,bottom:40,left:78},YW=70,XW=6,ZW=8,QW=1.8;function $W(e,t,n){return Math.min(n,Math.max(t,e))}function eG(e,t){let n=e[t],r=1/0,i=-1/0;for(let t=0;t<e.length;t++){let e=n[t];e<r&&(r=e),e>i&&(i=e)}(!Number.isFinite(r)||r===i)&&(--r,i+=1);let a=(i-r)*.04;return{min:r-a,max:i+a}}function tG(e){return e===`dashed`?[5,4]:e===`dotted`?[1,4]:[]}function nG({points:e,xLabel:t,yLabel:n,color:r=`#38bdf8`,datasetColors:i,colorLabel:a,colorRange:o,height:s=400,pointRadius:c=QW,drawMode:l=`points`,lineWidth:u=1,backgroundToken:d=``,onPlotContextMenu:f,xAxisLine:p,yAxisLine:m,gridLine:h,fitSettings:g,xScale:_,yScale:v}){let y=eU(),b=K(null),x=K(null),S=K(null),C=K(f);G(()=>{C.current=f},[f]);let w=K(null),T=K(null),E=K(null),D=K(null),O=K(null),k=K(0),A=K(null),j=dt(()=>pW(e)?e:mW(e),[e]),M=K({cols:j,xLabel:t,yLabel:n,color:r,datasetColors:i,colorLabel:a,colorRange:o,height:s,pointRadius:c,drawMode:l,lineWidth:u,xAxisLine:p,yAxisLine:m,gridLine:h,fitSettings:g,xScale:_,yScale:v});G(()=>{M.current={cols:j,xLabel:t,yLabel:n,color:r,datasetColors:i,colorLabel:a,colorRange:o,height:s,pointRadius:c,drawMode:l,lineWidth:u,xAxisLine:p,yAxisLine:m,gridLine:h,fitSettings:g,xScale:_,yScale:v}},[j,t,n,r,i,a,o,s,c,l,u,p,m,h,g,_,v]);let N=K({cols:null,value:{x:{min:0,max:1},y:{min:0,max:1}}});function P(){let e=M.current.cols,t=N.current;return t.cols!==e&&(t.value={x:eG(e,`x`),y:eG(e,`y`)},t.cols=e),t.value}W(()=>{T.current=null,E.current=null,D.current=null,O.current=null},[t,n]);function F(){let e=P(),t=T.current,n=E.current,r=D.current,i=O.current;return{xmin:t!==null&&n!==null&&n>t?t:e.x.min,xmax:t!==null&&n!==null&&n>t?n:e.x.max,ymin:r!==null&&i!==null&&i>r?r:e.y.min,ymax:r!==null&&i!==null&&i>r?i:e.y.max}}function I(){if(T.current!==null||D.current!==null)return F();let{xScale:e,yScale:t}=M.current,n=e=>{if(!e)return null;let t=parseFloat(e.scaleMin),n=parseFloat(e.scaleMax);return Number.isFinite(t)&&Number.isFinite(n)&&t<n?{min:t,max:n}:null},r=n(e)??P().x,i=n(t)??P().y;return{xmin:r.min,xmax:r.max,ymin:i.min,ymax:i.max}}function L(){if(A.current)return A.current;let e=S.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`,accent:`#f97316`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`,accent:t.getPropertyValue(`--accent`).trim()||`#f97316`};return A.current=n,n}function R(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function z(){let e=S.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||M.current.height)}}let B=K(null),V=K(null),ee=K({r:null,failed:!1,data:null,mode:``,style:``,size:``});function te(e,t){let n=ee.current;!n.r&&!n.failed&&V.current&&(n.r=lH(V.current,GW),n.failed=!n.r);let r=n.r;if(!r||!V.current)return null;let{cols:i,color:a,datasetColors:o,pointRadius:s,drawMode:c,lineWidth:l}=M.current,u=Math.min(2,window.devicePixelRatio||1),d=`${e}x${t}@${u}`;n.size!==d&&(r.resize(e,t,u),V.current.style.width=`${e}px`,V.current.style.height=`${t}px`,n.size=d);let f=o&&o.length>0&&i.d?`dataset`:i.c?`colormap`:`single`,p=c!==`points`;r.setDraw(c!==`lines`,p,l),(n.data!==i||n.mode!==`${f}|${p}`)&&(r.setData(i.x,i.y,f===`dataset`?i.d:f===`colormap`?i.c:void 0,f===`dataset`),n.data=i,n.mode=`${f}|${p}`);let m=`${f}|${a}|${f===`dataset`?o.join(`,`):``}|${s}`;return n.style!==m&&(r.setStyle(iG(f,a,o),Math.max(.25,s),.8),n.style=m),r}W(()=>()=>{ee.current.r?.dispose(),ee.current.r=null},[]);let H=K({cols:null,key:``,coeffs:null});function ne(e,t,n){let r=`${t}|${n.xmin}|${n.xmax}|${n.ymin}|${n.ymax}`,i=H.current;return(i.cols!==e||i.key!==r)&&(H.current={cols:e,key:r,coeffs:EW(e,t,n)}),H.current.coeffs}let re=K({pts:null,view:``}),ie=K(``);function U(){let e=b.current;if(!e)return;let{w:t,h:n}=z(),r=R(e,t,n);if(!r)return;let{cols:i,xLabel:a,yLabel:o,color:s,datasetColors:c,colorLabel:l,colorRange:u,pointRadius:d,xAxisLine:f,yAxisLine:p,gridLine:m,fitSettings:h,xScale:g,yScale:_}=M.current,v=!!c&&c.length>0&&!!i.d,x=!v&&i.length>0&&!!i.c,C=qW(JW,t,n),w=C.tiny?C.right:x?YW:C.right,{top:T,bottom:E,left:D}=C,O=t-D-w,k=n-T-E,{bg:A,muted:j,grid:N,accent:P}=L(),F=Math.max(.25,d),V=te(t,n),ee=i.length>=1&&O>0&&k>0?I():null,H=[t,n,e.width,ee&&`${ee.xmin}|${ee.xmax}|${ee.ymin}|${ee.ymax}`,a,o,x,v,l,u?.join(),JSON.stringify([f,p,m,g,_]),A,j,N,P].join(`§`);if(V&&ee&&!h&&ie.current===H){let e=re.current;e.pts!==i&&(re.current={pts:i,view:e.view},SH(S.current)),V.setView(ee.xmin,ee.xmax,ee.ymin,ee.ymax,{left:D,top:T,width:O,height:k}),V.render();return}ie.current=H,r.fillStyle=A,r.fillRect(0,0,t,n);let U=B.current?R(B.current,t,n):null;U?.clearRect(0,0,t,n);let ae=V;if(i.length<1||O<=0||k<=0){ae?.render(),r.fillStyle=j,r.font=`13px ${Q.sans}`,r.fillText(`No data`,D,T+24);return}let{xmin:oe,xmax:se,ymin:ce,ymax:le}=I(),ue=se-oe,de=le-ce,fe=e=>D+(e-oe)/ue*O;y({left:D,top:T,width:O,height:k,x:{v0:oe,v1:se}});let pe=e=>T+(le-e)/de*k,me=(()=>{if(_?.majorStep){let e=parseFloat(_.majorStep);if(Number.isFinite(e)&&e>0)return e}return wz(de,6)})(),he=Dz(ce,le,me);if((p?.style??`dashed`)!==`none`){r.strokeStyle=p?.color??N,r.lineWidth=p?.width??1,r.setLineDash(tG(p?.style??`dashed`));for(let e of he){let t=pe(e);r.beginPath(),r.moveTo(D,t),r.lineTo(D+O,t),r.stroke()}r.setLineDash([])}r.strokeStyle=j,r.lineWidth=1,r.fillStyle=j,r.font=`11px ${Q.mono}`,r.textAlign=`right`,r.textBaseline=`middle`;for(let e of C.tiny?[]:he){let t=pe(e);r.beginPath(),r.moveTo(D-XW,t),r.lineTo(D,t),r.stroke(),r.fillText(jz(e,me),D-ZW,t)}let ge=(()=>{if(g?.majorStep){let e=parseFloat(g.majorStep);if(Number.isFinite(e)&&e>0)return e}return wz(ue,Tz(O))})(),_e=Dz(oe,se,ge);if((f?.style??`dashed`)!==`none`){r.strokeStyle=f?.color??N,r.lineWidth=f?.width??1,r.setLineDash(tG(f?.style??`dashed`));for(let e of _e){let t=fe(e);r.beginPath(),r.moveTo(t,T),r.lineTo(t,T+k),r.stroke()}r.setLineDash([])}r.strokeStyle=j,r.lineWidth=1,r.fillStyle=j,r.textAlign=`center`,r.textBaseline=`top`;for(let e of C.tiny?[]:_e){let t=fe(e);r.beginPath(),r.moveTo(t,T+k),r.lineTo(t,T+k+XW),r.stroke(),r.fillText(jz(e,ge),t,T+k+XW+2)}(m?.style??`solid`)!==`none`&&(r.strokeStyle=m?.color??N,r.lineWidth=m?.width??1,r.setLineDash(tG(m?.style??`solid`)),r.strokeRect(D,T,O,k),r.setLineDash([])),r.fillStyle=j,r.font=`11px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`bottom`,C.tiny||(r.fillText(a,D+O/2,n-4),r.save(),r.translate(14,T+k/2),r.rotate(-Math.PI/2),r.fillText(o,0,0),r.restore());let ve=re.current;if((ve.pts!==i||ve.view!==`${oe}|${se}|${ce}|${le}`)&&(re.current={pts:i,view:`${oe}|${se}|${ce}|${le}`},SH(S.current)),ae)ae.setView(oe,se,ce,le,{left:D,top:T,width:O,height:k}),ae.render();else{let e={xToPx:fe,yToPx:pe,left:D,top:T,plotW:O,plotH:k,dotR:F,col:s,dsColors:v?c:null,hasColormap:x};M.current.drawMode!==`points`&&oG(r,i,e,M.current.lineWidth),M.current.drawMode!==`lines`&&aG(r,i,e)}if(x&&!C.tiny){let e=D+O+10,n=k;for(let t=0;t<64;t++)r.fillStyle=MW(1-t/64),r.fillRect(e,T+t/64*n,10,n/64+1);r.strokeStyle=j,r.lineWidth=.5,r.strokeRect(e,T,10,n),r.fillStyle=j,r.font=`10px ${Q.mono}`,r.textAlign=`left`,r.textBaseline=`top`;let i=u?String(u[1].toPrecision(3)):`1`,a=u?String(u[0].toPrecision(3)):`0`;r.fillText(i,e+10+3,T),r.textBaseline=`bottom`,r.fillText(a,e+10+3,T+n),l&&(r.save(),r.textBaseline=`middle`,r.translate(t-6,T+n/2),r.rotate(Math.PI/2),r.fillText(l,0,0),r.restore())}if(h&&U){let e=ne(i,h.degree,{xmin:oe,xmax:se,ymin:ce,ymax:le});if(e){U.save(),U.beginPath(),U.rect(D,T,O,k),U.clip(),U.strokeStyle=h.color,U.lineWidth=h.width,U.setLineDash(tG(h.lineStyle)),U.beginPath();for(let t=0;t<=300;t++){let n=oe+t/300*ue,r=e.reduce((e,t,r)=>e+t*n**+r,0),i=fe(n),a=pe(r);t===0?U.moveTo(i,a):U.lineTo(i,a)}U.stroke(),U.setLineDash([]);let t=kW(e,`x`,`y`);U.fillStyle=P,U.font=`10px ${Q.mono}`,U.textAlign=`right`,U.textBaseline=`top`,U.fillText(t,D+O-8,T+8),U.restore()}}if((g?.alarm||_?.alarm)&&U){if(U.save(),U.beginPath(),U.rect(D,T,O,k),U.clip(),g?.alarm){let e=g.alarm;U.strokeStyle=e.color,U.lineWidth=e.width,U.setLineDash(e.linked===`active`?nU:tG(e.style));let t=fe(e.value);U.beginPath(),U.moveTo(t,T),U.lineTo(t,T+k),U.stroke(),U.setLineDash([]),e.linked&&iU(U,t+3,T+2,e.color)}if(_?.alarm){let e=_.alarm;U.strokeStyle=e.color,U.lineWidth=e.width,U.setLineDash(e.linked===`active`?nU:tG(e.style));let t=pe(e.value);U.beginPath(),U.moveTo(D,t),U.lineTo(D+O,t),U.stroke(),U.setLineDash([]),e.linked&&iU(U,D+O-10-3,t-10-2,e.color)}U.restore()}}let ae=K(``);function oe(){let e=x.current;if(!e)return;let{w:t,h:n}=z(),r=`${t}x${n}`;if(w.current===null&&ae.current===r)return;let i=R(e,t,n);if(!i)return;i.clearRect(0,0,t,n),ae.current=w.current===null?r:``;let a=w.current,{cols:o,color:s,datasetColors:c,pointRadius:l}=M.current;if(a===null||a>=o.length||o.length<1)return;let u=Math.max(4,l*2),d=o.d?.[a],f=c&&c.length>0&&d!==void 0?c[d]??s:s,{top:p,right:m,bottom:h,left:g}=qW(JW,t,n),_=t-g-m,v=n-p-h;if(_<=0||v<=0)return;let{xmin:y,xmax:b,ymin:S,ymax:C}=I(),T=b-y,E=C-S,D={x:o.x[a],y:o.y[a]},O=g+(D.x-y)/T*_,k=p+(C-D.y)/E*v,{bg:A,muted:j}=L();i.strokeStyle=j,i.globalAlpha=.4,i.lineWidth=1,i.setLineDash([3,3]),i.beginPath(),i.moveTo(O,p),i.lineTo(O,p+v),i.stroke(),i.beginPath(),i.moveTo(g,k),i.lineTo(g+_,k),i.stroke(),i.setLineDash([]),i.globalAlpha=1,i.fillStyle=f,i.beginPath(),i.arc(O,k,u,0,Math.PI*2),i.fill(),i.strokeStyle=A,i.lineWidth=1.5,i.beginPath(),i.arc(O,k,u,0,Math.PI*2),i.stroke();let N=`(${Mz(D.x)}, ${Mz(D.y)})`;i.font=`11px ${Q.mono}`;let P=i.measureText(N).width+12,F=O+10,B=k-24;F+P>g+_&&(F=O-P-10),B<p&&(B=k+10),i.fillStyle=A,i.globalAlpha=.85,i.beginPath(),rG(i,F,B,P,20,4),i.fill(),i.globalAlpha=1,i.strokeStyle=j,i.lineWidth=.5,i.beginPath(),rG(i,F,B,P,20,4),i.stroke(),i.fillStyle=j,i.textAlign=`left`,i.textBaseline=`middle`,i.fillText(N,F+6,B+20/2)}let se=K(U),ce=K(oe);G(()=>{se.current=U,ce.current=oe});let le=K(null);le.current??=EH(()=>{se.current(),ce.current()},()=>S.current?.ownerDocument);function ue(){le.current.schedule()}function de(){k.current||=yH(()=>{k.current=0,ce.current()})}W(()=>()=>{le.current?.cancel(),bH(k.current),k.current=0},[]);let fe=K(ue),pe=K(de);return G(()=>{fe.current=ue,pe.current=de}),W(()=>eB(S.current,()=>{A.current=null,fe.current()}),[]),W(()=>{A.current=null,fe.current()},[d]),W(()=>{le.current.now()},[e,t,n,r,i,s,c,l,u,p,m,h,g,_,v]),W(()=>{let e=x.current,t=S.current;if(!e||!t)return;let n=new TH(()=>{A.current=null,fe.current()});n.observe(t);let r=null;function i(e,t){let n=M.current.cols;if(n.length===0)return null;let{w:i,h:a}=z(),{top:o,right:s,bottom:c,left:l}=qW(JW,i,a),u=i-l-s,d=a-o-c,{xmin:f,xmax:p,ymin:m,ymax:h}=I(),g=p-f,_=h-m,v=Math.max(12,M.current.pointRadius*10),y=`${i}|${a}|${f}|${p}|${m}|${h}|${v}`;if(!r||r.cols!==n||r.key!==y){let e=Math.max(1,Math.ceil(u/v)),t=Math.max(1,Math.ceil(d/v)),i=t=>{let r=(n.x[t]-f)/g*u,i=(h-n.y[t])/_*d;return r>=0&&r<u&&i>=0&&i<d?Math.floor(i/v)*e+Math.floor(r/v):-1},a=new Uint32Array(e*t+1);for(let e=0;e<n.length;e++){let t=i(e);t>=0&&a[t+1]++}for(let n=0;n<e*t;n++)a[n+1]+=a[n];let o=a.slice(0,e*t),s=new Uint32Array(a[e*t]);for(let e=0;e<n.length;e++){let t=i(e);t>=0&&(s[o[t]++]=e)}r={cols:n,key:y,cell:v,nx:e,start:a,ix:s}}let b=r,x=Math.floor((e-l)/b.cell),S=Math.floor((t-o)/b.cell),C=(b.start.length-1)/b.nx,w=-1,T=v*v;for(let r=S-1;r<=S+1;r++)if(!(r<0||r>=C))for(let i=x-1;i<=x+1;i++){if(i<0||i>=b.nx)continue;let a=r*b.nx+i;for(let r=b.start[a];r<b.start[a+1];r++){let i=b.ix[r],a=l+(n.x[i]-f)/g*u,s=o+(h-n.y[i])/_*d,c=(a-e)**2+(s-t)**2;c<T&&(T=c,w=i)}}return w<0?null:w}let a=t=>{if(M.current.cols.length<1){w.current!==null&&(w.current=null,pe.current());return}let n=e.getBoundingClientRect(),r=t.clientX-n.left,a=t.clientY-n.top,{left:o,top:s,right:c,bottom:l}=qW(JW,n.width,n.height),u=Math.max(1,n.width-o-c),d=n.height-s-l;if(r<o||r>o+u||a<s||a>s+d){w.current!==null&&(w.current=null,pe.current());return}let f=i(r,a);w.current!==f&&(w.current=f,pe.current())},o=()=>{w.current!==null&&(w.current=null,pe.current())},s=t=>{if(M.current.cols.length<1)return;let n=e.getBoundingClientRect(),r=t.clientX-n.left,i=t.clientY-n.top,{top:a,left:o,right:s,bottom:c}=qW(JW,n.width,n.height),l=Math.max(1,n.width-o-s),u=Math.max(1,n.height-a-c);if(r<o||r>o+l||i<a||i>a+u)return;t.preventDefault();let d=P(),f=d.x.max-d.x.min,p=d.y.max-d.y.min,m=I(),h=m.xmin,g=m.xmax,_=m.ymin,v=m.ymax,y=g-h,b=v-_,x=(r-o)/l,S=(i-a)/u,C=h+x*y,w=v-S*b,k=t.deltaY<0,A=.88,j=k?A:1/A,N=y*j,F=b*j;if(!k&&N>=f*.999&&F>=p*.999){T.current=null,E.current=null,D.current=null,O.current=null,fe.current();return}N=$W(N,Math.max(f*1e-7,1e-12),f),F=$W(F,Math.max(p*1e-7,1e-12),p);let L=C-x*N,R=C+(1-x)*N;L<d.x.min&&(R+=d.x.min-L,L=d.x.min),R>d.x.max&&(L-=R-d.x.max,R=d.x.max);let z=w-(1-S)*F,B=w+S*F;z<d.y.min&&(B+=d.y.min-z,z=d.y.min),B>d.y.max&&(z-=B-d.y.max,B=d.y.max),T.current=L,E.current=R,D.current=z,O.current=B,fe.current()},c=e=>{e.button===0&&(T.current===null&&D.current===null||(T.current=null,E.current=null,D.current=null,O.current=null,fe.current(),pe.current()))},l=e=>{e.preventDefault(),C.current?.({clientX:e.clientX,clientY:e.clientY})};return e.addEventListener(`mousemove`,a),e.addEventListener(`mouseleave`,o),e.addEventListener(`wheel`,s,{passive:!1}),e.addEventListener(`contextmenu`,l),e.addEventListener(`dblclick`,c),()=>{n.disconnect(),e.removeEventListener(`mousemove`,a),e.removeEventListener(`mouseleave`,o),e.removeEventListener(`wheel`,s),e.removeEventListener(`contextmenu`,l),e.removeEventListener(`dblclick`,c)}},[]),_t(`div`,{ref:S,className:`chart-canvas-wrap`,children:[q(`canvas`,{ref:b,className:`chart-canvas`,role:`img`,"aria-label":`Scatter ${t} vs ${n}`}),q(`canvas`,{ref:V,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),q(`canvas`,{ref:B,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),q(`canvas`,{ref:x,className:`chart-canvas chart-overlay`})]})}function rG(e,t,n,r,i,a){e.moveTo(t+a,n),e.lineTo(t+r-a,n),e.arcTo(t+r,n,t+r,n+a,a),e.lineTo(t+r,n+i-a),e.arcTo(t+r,n+i,t+r-a,n+i,a),e.lineTo(t+a,n+i),e.arcTo(t,n+i,t,n+i-a,a),e.lineTo(t,n+a),e.arcTo(t,n,t+a,n,a)}function iG(e,t,n){if(e===`single`)return{kind:`single`,rgba:zV(t)};let r=new Uint8Array(256*4);for(let t=0;t<256;t++)if(e===`colormap`){let{r:e,g:n,b:i}=jW(t/255);r.set([e,n,i,255],t*4)}else{let e=zV(n[Math.min(t,n.length-1)]);r.set([e[0]*255,e[1]*255,e[2]*255,e[3]*255],t*4)}return{kind:e===`colormap`?`colormap`:`dataset`,palette:r}}function aG(e,t,n){let r=Math.PI*2,i=n.dsColors?n.dsColors.length:n.hasColormap?24:1,a=Array.from({length:i},()=>new Path2D);for(let e=0;e<t.length;e++){let o=n.xToPx(t.x[e]),s=n.yToPx(t.y[e]);if(!(o>=n.left&&o<=n.left+n.plotW&&s>=n.top&&s<=n.top+n.plotH))continue;let c=n.dsColors?Math.min(t.d?.[e]??0,i-1):n.hasColormap?NW(t.c?.[e]??0,24):0;a[c].moveTo(o+n.dotR,s),a[c].arc(o,s,n.dotR,0,r)}e.globalAlpha=.8;for(let t=0;t<i;t++)e.fillStyle=n.dsColors?n.dsColors[t]:n.hasColormap?MW((t+.5)/24):n.col,e.fill(a[t]);e.globalAlpha=1}function oG(e,t,n,r){e.save(),e.beginPath(),e.rect(n.left,n.top,n.plotW,n.plotH),e.clip(),e.lineWidth=r;let i=n.dsColors?n.dsColors.length:1;for(let r=0;r<i;r++){e.beginPath();let i=!1;for(let a=0;a<t.length;a++){if(n.dsColors&&(t.d?.[a]??0)!==r){i=!1;continue}let o=t.x[a],s=t.y[a];if(o-o!==0||s-s!==0){i=!1;continue}i?e.lineTo(n.xToPx(o),n.yToPx(s)):(e.moveTo(n.xToPx(o),n.yToPx(s)),i=!0)}e.strokeStyle=n.dsColors?n.dsColors[r]:n.col,e.stroke()}e.restore()}var sG=11102230246251565e-32,cG=134217729,lG=(3+8*sG)*sG;function uG(e,t,n,r,i){let a,o,s,c,l=t[0],u=r[0],d=0,f=0;u>l==u>-l?(a=l,l=t[++d]):(a=u,u=r[++f]);let p=0;if(d<e&&f<n)for(u>l==u>-l?(o=l+a,s=a-(o-l),l=t[++d]):(o=u+a,s=a-(o-u),u=r[++f]),a=o,s!==0&&(i[p++]=s);d<e&&f<n;)u>l==u>-l?(o=a+l,c=o-a,s=a-(o-c)+(l-c),l=t[++d]):(o=a+u,c=o-a,s=a-(o-c)+(u-c),u=r[++f]),a=o,s!==0&&(i[p++]=s);for(;d<e;)o=a+l,c=o-a,s=a-(o-c)+(l-c),l=t[++d],a=o,s!==0&&(i[p++]=s);for(;f<n;)o=a+u,c=o-a,s=a-(o-c)+(u-c),u=r[++f],a=o,s!==0&&(i[p++]=s);return(a!==0||p===0)&&(i[p++]=a),p}function dG(e,t){let n=t[0];for(let r=1;r<e;r++)n+=t[r];return n}function $(e){return new Float64Array(e)}var fG=(3+16*sG)*sG,pG=(2+12*sG)*sG,mG=(9+64*sG)*sG*sG,hG=$(4),gG=$(8),_G=$(12),vG=$(16),yG=$(4);function bG(e,t,n,r,i,a,o){let s,c,l,u,d,f,p,m,h,g,_,v,y,b,x,S,C,w,T=e-i,E=n-i,D=t-a,O=r-a;b=T*O,f=cG*T,p=f-(f-T),m=T-p,f=cG*O,h=f-(f-O),g=O-h,x=m*g-(b-p*h-m*h-p*g),S=D*E,f=cG*D,p=f-(f-D),m=D-p,f=cG*E,h=f-(f-E),g=E-h,C=m*g-(S-p*h-m*h-p*g),_=x-C,d=x-_,hG[0]=x-(_+d)+(d-C),v=b+_,d=v-b,y=b-(v-d)+(_-d),_=y-S,d=y-_,hG[1]=y-(_+d)+(d-S),w=v+_,d=w-v,hG[2]=v-(w-d)+(_-d),hG[3]=w;let k=dG(4,hG),A=pG*o;if(k>=A||-k>=A||(d=e-T,s=e-(T+d)+(d-i),d=n-E,l=n-(E+d)+(d-i),d=t-D,c=t-(D+d)+(d-a),d=r-O,u=r-(O+d)+(d-a),s===0&&c===0&&l===0&&u===0)||(A=mG*o+lG*Math.abs(k),k+=T*u+O*s-(D*l+E*c),k>=A||-k>=A))return k;b=s*O,f=cG*s,p=f-(f-s),m=s-p,f=cG*O,h=f-(f-O),g=O-h,x=m*g-(b-p*h-m*h-p*g),S=c*E,f=cG*c,p=f-(f-c),m=c-p,f=cG*E,h=f-(f-E),g=E-h,C=m*g-(S-p*h-m*h-p*g),_=x-C,d=x-_,yG[0]=x-(_+d)+(d-C),v=b+_,d=v-b,y=b-(v-d)+(_-d),_=y-S,d=y-_,yG[1]=y-(_+d)+(d-S),w=v+_,d=w-v,yG[2]=v-(w-d)+(_-d),yG[3]=w;let j=uG(4,hG,4,yG,gG);b=T*u,f=cG*T,p=f-(f-T),m=T-p,f=cG*u,h=f-(f-u),g=u-h,x=m*g-(b-p*h-m*h-p*g),S=D*l,f=cG*D,p=f-(f-D),m=D-p,f=cG*l,h=f-(f-l),g=l-h,C=m*g-(S-p*h-m*h-p*g),_=x-C,d=x-_,yG[0]=x-(_+d)+(d-C),v=b+_,d=v-b,y=b-(v-d)+(_-d),_=y-S,d=y-_,yG[1]=y-(_+d)+(d-S),w=v+_,d=w-v,yG[2]=v-(w-d)+(_-d),yG[3]=w;let M=uG(j,gG,4,yG,_G);return b=s*u,f=cG*s,p=f-(f-s),m=s-p,f=cG*u,h=f-(f-u),g=u-h,x=m*g-(b-p*h-m*h-p*g),S=c*l,f=cG*c,p=f-(f-c),m=c-p,f=cG*l,h=f-(f-l),g=l-h,C=m*g-(S-p*h-m*h-p*g),_=x-C,d=x-_,yG[0]=x-(_+d)+(d-C),v=b+_,d=v-b,y=b-(v-d)+(_-d),_=y-S,d=y-_,yG[1]=y-(_+d)+(d-S),w=v+_,d=w-v,yG[2]=v-(w-d)+(_-d),yG[3]=w,vG[uG(M,_G,4,yG,vG)-1]}function xG(e,t,n,r,i,a){let o=(t-a)*(n-i),s=(e-i)*(r-a),c=o-s,l=Math.abs(o+s);return Math.abs(c)>=fG*l?c:-bG(e,t,n,r,i,a,l)}(7+56*sG)*sG,(3+28*sG)*sG,(26+288*sG)*sG*sG,$(4),$(4),$(4),$(4),$(4),$(4),$(4),$(4),$(4),$(8),$(8),$(8),$(4),$(8),$(8),$(16),$(12),$(192),$(192),(10+96*sG)*sG,(4+48*sG)*sG,(44+576*sG)*sG*sG,$(4),$(4),$(4),$(4),$(4),$(4),$(4),$(4),$(8),$(8),$(8),$(8),$(8),$(8),$(8),$(8),$(8),$(4),$(4),$(4),$(8),$(16),$(16),$(16),$(32),$(32),$(48),$(64),$(1152),$(1152),(16+224*sG)*sG,(5+72*sG)*sG,(71+1408*sG)*sG*sG,$(4),$(4),$(4),$(4),$(4),$(4),$(4),$(4),$(4),$(4),$(24),$(24),$(24),$(24),$(24),$(24),$(24),$(24),$(24),$(24),$(1152),$(1152),$(1152),$(1152),$(1152),$(2304),$(2304),$(3456),$(5760),$(8),$(8),$(8),$(16),$(24),$(48),$(48),$(96),$(192),$(384),$(384),$(384),$(768),$(96),$(96),$(96),$(1152);var SG=2**-52,CG=new Uint32Array(512),wG=class e{static from(t,n=MG,r=NG){let i=t.length,a=new Float64Array(i*2);for(let e=0;e<i;e++){let i=t[e];a[2*e]=n(i),a[2*e+1]=r(i)}return new e(a)}constructor(e){let t=e.length>>1;if(t>0&&typeof e[0]!=`number`)throw Error(`Expected coords to contain numbers.`);this.coords=e;let n=Math.max(2*t-5,0);this._triangles=new Uint32Array(n*3),this._halfedges=new Int32Array(n*3),this._hashSize=Math.ceil(Math.sqrt(t)),this._hullPrev=new Uint32Array(t),this._hullNext=new Uint32Array(t),this._hullTri=new Uint32Array(t),this._hullHash=new Int32Array(this._hashSize),this._ids=new Uint32Array(t),this._dists=new Float64Array(t),this.trianglesLen=0,this._cx=0,this._cy=0,this._hullStart=0,this.hull=this._triangles,this.triangles=this._triangles,this.halfedges=this._halfedges,this.update()}update(){let{coords:e,_hullPrev:t,_hullNext:n,_hullTri:r,_hullHash:i}=this,a=e.length>>1,o=1/0,s=1/0,c=-1/0,l=-1/0;for(let t=0;t<a;t++){let n=e[2*t],r=e[2*t+1];n<o&&(o=n),r<s&&(s=r),n>c&&(c=n),r>l&&(l=r),this._ids[t]=t}let u=(o+c)/2,d=(s+l)/2,f=0,p=0,m=0;for(let t=0,n=1/0;t<a;t++){let r=EG(u,d,e[2*t],e[2*t+1]);r<n&&(f=t,n=r)}let h=e[2*f],g=e[2*f+1];for(let t=0,n=1/0;t<a;t++){if(t===f)continue;let r=EG(h,g,e[2*t],e[2*t+1]);r<n&&r>0&&(p=t,n=r)}let _=e[2*p],v=e[2*p+1],y=1/0;for(let t=0;t<a;t++){if(t===f||t===p)continue;let n=OG(h,g,_,v,e[2*t],e[2*t+1]);n<y&&(m=t,y=n)}let b=e[2*m],x=e[2*m+1];if(y===1/0){for(let t=0;t<a;t++)this._dists[t]=e[2*t]-e[0]||e[2*t+1]-e[1];AG(this._ids,this._dists,0,a-1);let t=new Uint32Array(a),n=0;for(let e=0,r=-1/0;e<a;e++){let i=this._ids[e],a=this._dists[i];a>r&&(t[n++]=i,r=a)}this.hull=t.subarray(0,n),this.triangles=new Uint32Array,this.halfedges=new Int32Array;return}if(xG(h,g,_,v,b,x)<0){let e=p,t=_,n=v;p=m,_=b,v=x,m=e,b=t,x=n}let S=kG(h,g,_,v,b,x);this._cx=S.x,this._cy=S.y;for(let t=0;t<a;t++)this._dists[t]=EG(e[2*t],e[2*t+1],S.x,S.y);AG(this._ids,this._dists,0,a-1),this._hullStart=f;let C=3;n[f]=t[m]=p,n[p]=t[f]=m,n[m]=t[p]=f,r[f]=0,r[p]=1,r[m]=2,i.fill(-1),i[this._hashKey(h,g)]=f,i[this._hashKey(_,v)]=p,i[this._hashKey(b,x)]=m,this.trianglesLen=0,this._addTriangle(f,p,m,-1,-1,-1);for(let a=0,o=0,s=0;a<this._ids.length;a++){let c=this._ids[a],l=e[2*c],u=e[2*c+1];if(a>0&&Math.abs(l-o)<=SG&&Math.abs(u-s)<=SG||(o=l,s=u,c===f||c===p||c===m))continue;let d=0;for(let e=0,t=this._hashKey(l,u);e<this._hashSize&&(d=i[(t+e)%this._hashSize],!(d!==-1&&d!==n[d]));e++);d=t[d];let h=d,g;for(;g=n[h],xG(l,u,e[2*h],e[2*h+1],e[2*g],e[2*g+1])>=0;)if(h=g,h===d){h=-1;break}if(h===-1)continue;let _=this._addTriangle(h,c,n[h],-1,-1,r[h]);r[c]=this._legalize(_+2),r[h]=_,C++;let v=n[h];for(;g=n[v],xG(l,u,e[2*v],e[2*v+1],e[2*g],e[2*g+1])<0;)_=this._addTriangle(v,c,g,r[c],-1,r[v]),r[c]=this._legalize(_+2),n[v]=v,C--,v=g;if(h===d)for(;g=t[h],xG(l,u,e[2*g],e[2*g+1],e[2*h],e[2*h+1])<0;)_=this._addTriangle(g,c,h,-1,r[h],r[g]),this._legalize(_+2),r[g]=_,n[h]=h,C--,h=g;this._hullStart=t[c]=h,n[h]=t[v]=c,n[c]=v,i[this._hashKey(l,u)]=c,i[this._hashKey(e[2*h],e[2*h+1])]=h}this.hull=new Uint32Array(C);for(let e=0,t=this._hullStart;e<C;e++)this.hull[e]=t,t=n[t];this.triangles=this._triangles.subarray(0,this.trianglesLen),this.halfedges=this._halfedges.subarray(0,this.trianglesLen)}_hashKey(e,t){return Math.floor(TG(e-this._cx,t-this._cy)*this._hashSize)%this._hashSize}_legalize(e){let{_triangles:t,_halfedges:n,coords:r}=this,i=0,a=0;for(;;){let o=n[e],s=e-e%3;if(a=s+(e+2)%3,o===-1){if(i===0)break;e=CG[--i];continue}let c=o-o%3,l=s+(e+1)%3,u=c+(o+2)%3,d=t[a],f=t[e],p=t[l],m=t[u];if(DG(r[2*d],r[2*d+1],r[2*f],r[2*f+1],r[2*p],r[2*p+1],r[2*m],r[2*m+1])){t[e]=m,t[o]=d;let r=n[u];if(r===-1){let t=this._hullStart;do{if(this._hullTri[t]===u){this._hullTri[t]=e;break}t=this._hullPrev[t]}while(t!==this._hullStart)}this._link(e,r),this._link(o,n[a]),this._link(a,u);let s=c+(o+1)%3;i<CG.length&&(CG[i++]=s)}else{if(i===0)break;e=CG[--i]}}return a}_link(e,t){this._halfedges[e]=t,t!==-1&&(this._halfedges[t]=e)}_addTriangle(e,t,n,r,i,a){let o=this.trianglesLen;return this._triangles[o]=e,this._triangles[o+1]=t,this._triangles[o+2]=n,this._link(o,r),this._link(o+1,i),this._link(o+2,a),this.trianglesLen+=3,o}};function TG(e,t){let n=e/(Math.abs(e)+Math.abs(t));return(t>0?3-n:1+n)/4}function EG(e,t,n,r){let i=e-n,a=t-r;return i*i+a*a}function DG(e,t,n,r,i,a,o,s){let c=e-o,l=t-s,u=n-o,d=r-s,f=i-o,p=a-s,m=c*c+l*l,h=u*u+d*d,g=f*f+p*p;return c*(d*g-h*p)-l*(u*g-h*f)+m*(u*p-d*f)<0}function OG(e,t,n,r,i,a){let o=n-e,s=r-t,c=i-e,l=a-t,u=o*o+s*s,d=c*c+l*l,f=.5/(o*l-s*c),p=(l*u-s*d)*f,m=(o*d-c*u)*f;return p*p+m*m}function kG(e,t,n,r,i,a){let o=n-e,s=r-t,c=i-e,l=a-t,u=o*o+s*s,d=c*c+l*l,f=.5/(o*l-s*c);return{x:e+(l*u-s*d)*f,y:t+(o*d-c*u)*f}}function AG(e,t,n,r){if(r-n<=20)for(let i=n+1;i<=r;i++){let r=e[i],a=t[r],o=i-1;for(;o>=n&&t[e[o]]>a;)e[o+1]=e[o--];e[o+1]=r}else{let i=n+r>>1,a=n+1,o=r;jG(e,i,a),t[e[n]]>t[e[r]]&&jG(e,n,r),t[e[a]]>t[e[r]]&&jG(e,a,r),t[e[n]]>t[e[a]]&&jG(e,n,a);let s=e[a],c=t[s];for(;;){do a++;while(t[e[a]]<c);do o--;while(t[e[o]]>c);if(o<a)break;jG(e,a,o)}e[n+1]=e[o],e[o]=s,r-a+1>=o-n?(AG(e,t,a,r),AG(e,t,n,o-1)):(AG(e,t,n,o-1),AG(e,t,a,r))}}function jG(e,t,n){let r=e[t];e[t]=e[n],e[n]=r}function MG(e){return e[0]}function NG(e){return e[1]}var PG=`
374
+ void main() { o = vec4(0.0); }`;function KW(e,t,n,r){let i=WV(e,e.VERTEX_SHADER,t),a=WV(e,e.FRAGMENT_SHADER,n);if(!i||!a)return null;let o=e.createProgram();return e.attachShader(o,i),e.attachShader(o,a),r&&e.transformFeedbackVaryings(o,r,e.SEPARATE_ATTRIBS),e.linkProgram(o),e.getProgramParameter(o,e.LINK_STATUS)?{prog:o,shaders:[i,a]}:(console.error(`glPoints program link failed:`,e.getProgramInfoLog(o)),null)}function qW(e){let t=e.getContext(`webgl2`,{antialias:!1,alpha:!0,premultipliedAlpha:!0});if(!t)return null;let n=lH(t,`glPoints|points`,()=>KW(t,IW,LW)),r=lH(t,`glPoints|lines`,()=>KW(t,BW,VW)),i=lH(t,`glPoints|points64`,()=>KW(t,UW(IW,[`a_x`],[`a_y`],!0),LW)),a=lH(t,`glPoints|sprites`,()=>KW(t,RW,zW)),o=lH(t,`glPoints|sprites64`,()=>KW(t,UW(RW,[`a_x`],[`a_y`],!0),zW)),s=t.getParameter(t.ALIASED_POINT_SIZE_RANGE)[1],c=lH(t,`glPoints|decode`,()=>KW(t,WW,GW,[`v_x`,`v_y`])),l=t.createVertexArray();if(!n||!r)return null;let d=(e,n)=>Object.fromEntries(n.map(n=>[n,t.getAttribLocation(e,n)])),f=(e,n)=>Object.fromEntries(n.map(n=>[n,t.getUniformLocation(e,n)])),p=d(n.prog,[`a_corner`,`a_x`,`a_y`,`a_k`,`a_r`]),m=f(n.prog,[`u_resolution`,`u_plot`,`u_view`,`u_radius`,`u_kScale`,`u_palette`,`u_alpha`,`u_clip`,`u_dpr`,`u_height`]),h=d(r.prog,[`a_corner`,`a_ax`,`a_ay`,`a_bx`,`a_by`,`a_bstart`,`a_k`]),g=f(r.prog,[`u_resolution`,`u_plot`,`u_view`,`u_ext`,`u_kScale`,`u_palette`,`u_half`,`u_clip`]),_=i&&d(i.prog,[`a_corner`,`a_x_bits`,`a_y_bits`,`a_k`,`a_r`]),v=i&&f(i.prog,[`u_resolution`,`u_plot`,`u_view`,`u_radius`,`u_kScale`,`u_palette`,`u_alpha`,`u_clip`,`u_dpr`,`u_height`,`u_ox`,`u_oy`]),y=[`u_resolution`,`u_plot`,`u_view`,`u_radius`,`u_kScale`,`u_palette`,`u_alpha`,`u_clip`,`u_dpr`,`u_height`],b=a&&d(a.prog,[`a_x`,`a_y`,`a_k`]),x=a&&f(a.prog,y),S=o&&d(o.prog,[`a_x_bits`,`a_y_bits`,`a_k`]),C=o&&f(o.prog,[...y,`u_ox`,`u_oy`]),w=c&&d(c.prog,[`a_x_bits`,`a_y_bits`]),T=c&&f(c.prog,[`u_ox`,`u_oy`]),E=t.createTransformFeedback(),D=t.createVertexArray(),O=t.createBuffer(),k=t.createBuffer(),A=!1,j=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,j),t.bufferData(t.ARRAY_BUFFER,Float32Array.from([-1,-1,1,-1,-1,1,1,1]),t.STATIC_DRAW);let M=t.createBuffer(),N=t.createBuffer(),P=t.createBuffer(),F=t.createBuffer(),I=t.createBuffer(),L=t.createTexture(),R=0,z=!1,B=!1,V=!1,ee=0,te=0,H=1,ne=1,re=1,ie=1.8,U=.8,ae=255,oe=!0,se=!1,ce=1,le={xmin:0,xmax:1,ymin:0,ymax:1},ue={left:0,top:0,width:1,height:1},de=new Float32Array,fe=new Float32Array,pe=new Float32Array,me=new Uint8Array,he=new Float32Array,ge=new Map,_e=(e,n,r)=>{t.bindBuffer(t.ARRAY_BUFFER,e);let i=r*n.BYTES_PER_ELEMENT;i<=(ge.get(e)??0)?t.bufferSubData(t.ARRAY_BUFFER,0,n,0,r):(t.bufferData(t.ARRAY_BUFFER,n.subarray(0,r),t.DYNAMIC_DRAW),ge.set(e,i))},ve=(e,n,r=0,i=t.FLOAT)=>{t.bindBuffer(t.ARRAY_BUFFER,n),t.enableVertexAttribArray(e);let a=i===t.FLOAT?4:1;t.vertexAttribPointer(e,1,i,i!==t.FLOAT,a,r*a),t.vertexAttribDivisor(e,1)},ye=(e,n,r=0)=>{t.bindBuffer(t.ARRAY_BUFFER,n),t.enableVertexAttribArray(e),t.vertexAttribIPointer(e,2,t.UNSIGNED_INT,8,r*8),t.vertexAttribDivisor(e,1)},be=e=>{t.bindBuffer(t.ARRAY_BUFFER,j),t.enableVertexAttribArray(e),t.vertexAttribPointer(e,2,t.FLOAT,!1,0,0),t.vertexAttribDivisor(e,0)};return{resize(t,n,r){H=Math.max(1,t),ne=Math.max(1,n),re=r,e.width=Math.round(H*re),e.height=Math.round(ne*re)},setData(e,t,n,r=!1,i){let a=Math.min(e.length,t.length);de.length<a&&(de=new Float32Array(a),fe=new Float32Array(a)),z=!!n,B=!!i,n&&pe.length<a&&(pe=new Float32Array(a)),i&&he.length<a&&(he=new Float32Array(a)),se&&me.length<a&&(me=new Uint8Array(a)),ee=0,te=0;for(let n=0;n<a;n++)if(e[n]-e[n]===0&&t[n]-t[n]===0){ee=e[n],te=t[n];break}let o=u.has(e)&&u.has(t);if(V=!!_&&!!c&&e instanceof Float64Array&&t instanceof Float64Array&&(o||!se),A=!1,V){if(_e(M,e,a),_e(N,t,a),n){for(let e=0;e<a;e++)pe[e]=n[e];_e(P,pe,a)}if(i){for(let e=0;e<a;e++)he[e]=i[e];_e(I,he,a)}if(se){if(me.fill(0,0,a),a&&(me[0]=255),n&&r)for(let e=1;e<a;e++)n[e]!==n[e-1]&&(me[e]=255);_e(F,me,a)}R=a;return}let s=0;if(u.has(e)&&u.has(t)){for(let t=0;t<a;t++)de[t]=e[t]-ee;for(let e=0;e<a;e++)fe[e]=t[e]-te;if(n)for(let e=0;e<a;e++)pe[e]=n[e];if(i)for(let e=0;e<a;e++)he[e]=i[e];if(se&&(me.fill(0,0,a),a&&(me[0]=255),n&&r))for(let e=1;e<a;e++)n[e]!==n[e-1]&&(me[e]=255);s=a}else{let o=!0;for(let c=0;c<a;c++){let a=e[c],l=t[c];if(a-a!==0||l-l!==0){o=!0;continue}de[s]=a-ee,fe[s]=l-te,n&&(pe[s]=n[c]),i&&(he[s]=i[c]),se&&(me[s]=o||r&&n&&s>0&&n[c]!==pe[s-1]?255:0),o=!1,s++}}R=s,_e(M,de,s),_e(N,fe,s),n&&_e(P,pe,s),i&&_e(I,he,s),se&&_e(F,me,s)},setStyle(e,n,r){ie=n,U=r;let i=new Uint8Array(256*4);if(e.kind===`single`){let t=e.rgba.map(e=>Math.round(e*255));for(let e=0;e<256;e++)i.set(t,e*4);ae=0}else i.set(e.palette.subarray(0,256*4)),ae=e.kind===`colormap`?255:1;t.bindTexture(t.TEXTURE_2D,L),t.texImage2D(t.TEXTURE_2D,0,t.RGBA8,256,1,0,t.RGBA,t.UNSIGNED_BYTE,i),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE)},setDraw(e,t,n){oe=e,se=t,ce=n},setView(e,t,n,r,i){le={xmin:e,xmax:t,ymin:n,ymax:r},ue=i},render(){if(t.bindFramebuffer(t.FRAMEBUFFER,null),t.viewport(0,0,e.width,e.height),t.disable(t.SCISSOR_TEST),t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT),R===0)return;t.bindVertexArray(l),t.enable(t.BLEND),t.blendFunc(t.ONE,t.ONE_MINUS_SRC_ALPHA),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,L);let u=z?ae:0,d=[le.xmin-ee,le.xmax-ee,le.ymin-te,le.ymax-te],f=[ue.left,ue.top,ue.left+ue.width,ue.top+ue.height],y=e=>{let t=Math.fround(e);return[t,e-t]},j=V,de=M,fe=N;if(V&&se&&R>1){if(!A){for(let e of[O,k])t.bindBuffer(t.ARRAY_BUFFER,e),(ge.get(e)??0)<R*4&&(t.bufferData(t.ARRAY_BUFFER,R*4,t.DYNAMIC_COPY),ge.set(e,R*4));t.bindBuffer(t.ARRAY_BUFFER,null),t.bindVertexArray(D),t.useProgram(c.prog),t.uniform2f(T.u_ox,...y(ee)),t.uniform2f(T.u_oy,...y(te)),ye(w.a_x_bits,M),ye(w.a_y_bits,N),t.vertexAttribDivisor(w.a_x_bits,0),t.vertexAttribDivisor(w.a_y_bits,0),t.enable(t.RASTERIZER_DISCARD),t.bindTransformFeedback(t.TRANSFORM_FEEDBACK,E),t.bindBufferBase(t.TRANSFORM_FEEDBACK_BUFFER,0,O),t.bindBufferBase(t.TRANSFORM_FEEDBACK_BUFFER,1,k),t.beginTransformFeedback(t.POINTS),t.drawArrays(t.POINTS,0,R),t.endTransformFeedback(),t.bindBufferBase(t.TRANSFORM_FEEDBACK_BUFFER,0,null),t.bindBufferBase(t.TRANSFORM_FEEDBACK_BUFFER,1,null),t.bindTransformFeedback(t.TRANSFORM_FEEDBACK,null),t.disable(t.RASTERIZER_DISCARD),t.bindVertexArray(l),A=!0}j=!1,de=O,fe=k}if(se&&R>1){let e=g,n=h;t.useProgram(r.prog),t.uniform2f(e.u_resolution,H,ne),t.uniform4f(e.u_plot,ue.left,ue.top,ue.width,ue.height),t.uniform4f(e.u_view,...d),t.uniform1f(e.u_half,ce/2),t.uniform1f(e.u_ext,ce/2+1),t.uniform1f(e.u_kScale,u),t.uniform4f(e.u_clip,...f),t.uniform1i(e.u_palette,0),be(n.a_corner),ve(n.a_ax,de,0),ve(n.a_bx,de,1),ve(n.a_ay,fe,0),ve(n.a_by,fe,1),ve(n.a_bstart,F,1,t.UNSIGNED_BYTE),z?ve(n.a_k,P,0):(t.disableVertexAttribArray(n.a_k),t.vertexAttrib1f(n.a_k,0)),t.drawArraysInstanced(t.TRIANGLE_STRIP,0,4,R-1);for(let e of Object.values(n))t.vertexAttribDivisor(e,0)}if(oe&&!B&&2*(ie+.5)*re<=s&&(j?o:a)){let n=j?C:x,r=j?S:b;t.useProgram((j?o:a).prog),j&&(t.uniform2f(n.u_ox,...y(ee)),t.uniform2f(n.u_oy,...y(te))),t.uniform2f(n.u_resolution,H,ne),t.uniform4f(n.u_plot,ue.left,ue.top,ue.width,ue.height),t.uniform4f(n.u_view,...d),t.uniform1f(n.u_radius,ie),t.uniform1f(n.u_kScale,u),t.uniform1f(n.u_alpha,U),t.uniform4f(n.u_clip,...f),t.uniform1f(n.u_dpr,re),t.uniform1f(n.u_height,e.height),t.uniform1i(n.u_palette,0),j?(ye(r.a_x_bits,M),ye(r.a_y_bits,N)):(ve(r.a_x,de),ve(r.a_y,fe)),z?ve(r.a_k,P):(t.disableVertexAttribArray(r.a_k),t.vertexAttrib1f(r.a_k,0));for(let e of Object.values(r))t.vertexAttribDivisor(e,0);t.drawArrays(t.POINTS,0,R)}else if(oe){let r=j?v:m,a=j?_:p;t.useProgram(j?i.prog:n.prog),j&&(t.uniform2f(r.u_ox,...y(ee)),t.uniform2f(r.u_oy,...y(te))),t.uniform2f(r.u_resolution,H,ne),t.uniform4f(r.u_plot,ue.left,ue.top,ue.width,ue.height),t.uniform4f(r.u_view,...d),t.uniform1f(r.u_radius,ie),t.uniform1f(r.u_kScale,u),t.uniform1f(r.u_alpha,U),t.uniform4f(r.u_clip,...f),t.uniform1f(r.u_dpr,re),t.uniform1f(r.u_height,e.height),t.uniform1i(r.u_palette,0),be(a.a_corner),j?(ye(a.a_x_bits,M),ye(a.a_y_bits,N)):(ve(a.a_x,de),ve(a.a_y,fe)),z?ve(a.a_k,P):(t.disableVertexAttribArray(a.a_k),t.vertexAttrib1f(a.a_k,0)),B?ve(a.a_r,I):(t.disableVertexAttribArray(a.a_r),t.vertexAttrib1f(a.a_r,0)),t.drawArraysInstanced(t.TRIANGLE_STRIP,0,4,R);for(let e of Object.values(a))t.vertexAttribDivisor(e,0)}t.bindVertexArray(null)},dispose(){for(let e of[j,M,N,P,F,I,O,k])t.deleteBuffer(e);t.deleteTransformFeedback(E),t.deleteVertexArray(D),t.deleteTexture(L),t.deleteVertexArray(l)}}}var JW={top:3,right:3,bottom:3,left:3};function YW(e,t,n){return t<200||n<120?{...JW,tiny:!0}:{...e,tiny:!1}}var XW={top:14,right:24,bottom:40,left:78},ZW=70,QW=6,$W=8,eG=1.8;function tG(e,t,n){return Math.min(n,Math.max(t,e))}function nG(e,t){let n=e[t],r=1/0,i=-1/0;for(let t=0;t<e.length;t++){let e=n[t];e<r&&(r=e),e>i&&(i=e)}(!Number.isFinite(r)||r===i)&&(--r,i+=1);let a=(i-r)*.04;return{min:r-a,max:i+a}}function rG(e){return e===`dashed`?[5,4]:e===`dotted`?[1,4]:[]}function iG({points:e,xLabel:t,yLabel:n,color:r=`#38bdf8`,datasetColors:i,colorLabel:a,colorRange:o,height:s=400,pointRadius:c=eG,drawMode:l=`points`,lineWidth:u=1,backgroundToken:d=``,onPlotContextMenu:f,xAxisLine:p,yAxisLine:m,gridLine:h,fitSettings:g,xScale:_,yScale:v}){let y=nU(),b=K(null),x=K(null),S=K(null),C=K(f);G(()=>{C.current=f},[f]);let w=K(null),T=K(null),E=K(null),D=K(null),O=K(null),k=K(0),A=K(null),j=dt(()=>hW(e)?e:gW(e),[e]),M=K({cols:j,xLabel:t,yLabel:n,color:r,datasetColors:i,colorLabel:a,colorRange:o,height:s,pointRadius:c,drawMode:l,lineWidth:u,xAxisLine:p,yAxisLine:m,gridLine:h,fitSettings:g,xScale:_,yScale:v});G(()=>{M.current={cols:j,xLabel:t,yLabel:n,color:r,datasetColors:i,colorLabel:a,colorRange:o,height:s,pointRadius:c,drawMode:l,lineWidth:u,xAxisLine:p,yAxisLine:m,gridLine:h,fitSettings:g,xScale:_,yScale:v}},[j,t,n,r,i,a,o,s,c,l,u,p,m,h,g,_,v]);let N=K({cols:null,value:{x:{min:0,max:1},y:{min:0,max:1}}});function P(){let e=M.current.cols,t=N.current;return t.cols!==e&&(t.value={x:nG(e,`x`),y:nG(e,`y`)},t.cols=e),t.value}W(()=>{T.current=null,E.current=null,D.current=null,O.current=null},[t,n]);function F(){let e=P(),t=T.current,n=E.current,r=D.current,i=O.current;return{xmin:t!==null&&n!==null&&n>t?t:e.x.min,xmax:t!==null&&n!==null&&n>t?n:e.x.max,ymin:r!==null&&i!==null&&i>r?r:e.y.min,ymax:r!==null&&i!==null&&i>r?i:e.y.max}}function I(){if(T.current!==null||D.current!==null)return F();let{xScale:e,yScale:t}=M.current,n=e=>{if(!e)return null;let t=parseFloat(e.scaleMin),n=parseFloat(e.scaleMax);return Number.isFinite(t)&&Number.isFinite(n)&&t<n?{min:t,max:n}:null},r=n(e)??P().x,i=n(t)??P().y;return{xmin:r.min,xmax:r.max,ymin:i.min,ymax:i.max}}function L(){if(A.current)return A.current;let e=S.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`,accent:`#f97316`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`,accent:t.getPropertyValue(`--accent`).trim()||`#f97316`};return A.current=n,n}function R(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function z(){let e=S.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||M.current.height)}}let B=K(null),V=K(null),ee=K({r:null,failed:!1,data:null,mode:``,style:``,size:``});function te(e,t){let n=ee.current;!n.r&&!n.failed&&V.current&&(n.r=uH(V.current,qW),n.failed=!n.r);let r=n.r;if(!r||!V.current)return null;let{cols:i,color:a,datasetColors:o,pointRadius:s,drawMode:c,lineWidth:l}=M.current,u=Math.min(2,window.devicePixelRatio||1),d=`${e}x${t}@${u}`;n.size!==d&&(r.resize(e,t,u),V.current.style.width=`${e}px`,V.current.style.height=`${t}px`,n.size=d);let f=o&&o.length>0&&i.d?`dataset`:i.c?`colormap`:`single`,p=c!==`points`;r.setDraw(c!==`lines`,p,l),(n.data!==i||n.mode!==`${f}|${p}`)&&(r.setData(i.x,i.y,f===`dataset`?i.d:f===`colormap`?i.c:void 0,f===`dataset`),n.data=i,n.mode=`${f}|${p}`);let m=`${f}|${a}|${f===`dataset`?o.join(`,`):``}|${s}`;return n.style!==m&&(r.setStyle(oG(f,a,o),Math.max(.25,s),.8),n.style=m),r}W(()=>()=>{ee.current.r?.dispose(),ee.current.r=null},[]);let H=K({cols:null,key:``,coeffs:null});function ne(e,t,n){let r=`${t}|${n.xmin}|${n.xmax}|${n.ymin}|${n.ymax}`,i=H.current;return(i.cols!==e||i.key!==r)&&(H.current={cols:e,key:r,coeffs:OW(e,t,n)}),H.current.coeffs}let re=K({pts:null,view:``}),ie=K(``);function U(){let e=b.current;if(!e)return;let{w:t,h:n}=z(),r=R(e,t,n);if(!r)return;let{cols:i,xLabel:a,yLabel:o,color:s,datasetColors:c,colorLabel:l,colorRange:u,pointRadius:d,xAxisLine:f,yAxisLine:p,gridLine:m,fitSettings:h,xScale:g,yScale:_}=M.current,v=!!c&&c.length>0&&!!i.d,x=!v&&i.length>0&&!!i.c,C=YW(XW,t,n),w=C.tiny?C.right:x?ZW:C.right,{top:T,bottom:E,left:D}=C,O=t-D-w,k=n-T-E,{bg:A,muted:j,grid:N,accent:P}=L(),F=Math.max(.25,d),V=te(t,n),ee=i.length>=1&&O>0&&k>0?I():null,H=[t,n,e.width,ee&&`${ee.xmin}|${ee.xmax}|${ee.ymin}|${ee.ymax}`,a,o,x,v,l,u?.join(),JSON.stringify([f,p,m,g,_]),A,j,N,P].join(`§`);if(V&&ee&&!h&&ie.current===H){let e=re.current;e.pts!==i&&(re.current={pts:i,view:e.view},CH(S.current)),V.setView(ee.xmin,ee.xmax,ee.ymin,ee.ymax,{left:D,top:T,width:O,height:k}),V.render();return}ie.current=H,r.fillStyle=A,r.fillRect(0,0,t,n);let U=B.current?R(B.current,t,n):null;U?.clearRect(0,0,t,n);let ae=V;if(i.length<1||O<=0||k<=0){ae?.render(),r.fillStyle=j,r.font=`13px ${Q.sans}`,r.fillText(`No data`,D,T+24);return}let{xmin:oe,xmax:se,ymin:ce,ymax:le}=I(),ue=se-oe,de=le-ce,fe=e=>D+(e-oe)/ue*O;y({left:D,top:T,width:O,height:k,x:{v0:oe,v1:se}});let pe=e=>T+(le-e)/de*k,me=(()=>{if(_?.majorStep){let e=parseFloat(_.majorStep);if(Number.isFinite(e)&&e>0)return e}return wz(de,6)})(),he=Dz(ce,le,me);if((p?.style??`dashed`)!==`none`){r.strokeStyle=p?.color??N,r.lineWidth=p?.width??1,r.setLineDash(rG(p?.style??`dashed`));for(let e of he){let t=pe(e);r.beginPath(),r.moveTo(D,t),r.lineTo(D+O,t),r.stroke()}r.setLineDash([])}r.strokeStyle=j,r.lineWidth=1,r.fillStyle=j,r.font=`11px ${Q.mono}`,r.textAlign=`right`,r.textBaseline=`middle`;for(let e of C.tiny?[]:he){let t=pe(e);r.beginPath(),r.moveTo(D-QW,t),r.lineTo(D,t),r.stroke(),r.fillText(jz(e,me),D-$W,t)}let ge=(()=>{if(g?.majorStep){let e=parseFloat(g.majorStep);if(Number.isFinite(e)&&e>0)return e}return wz(ue,Tz(O))})(),_e=Dz(oe,se,ge);if((f?.style??`dashed`)!==`none`){r.strokeStyle=f?.color??N,r.lineWidth=f?.width??1,r.setLineDash(rG(f?.style??`dashed`));for(let e of _e){let t=fe(e);r.beginPath(),r.moveTo(t,T),r.lineTo(t,T+k),r.stroke()}r.setLineDash([])}r.strokeStyle=j,r.lineWidth=1,r.fillStyle=j,r.textAlign=`center`,r.textBaseline=`top`;for(let e of C.tiny?[]:_e){let t=fe(e);r.beginPath(),r.moveTo(t,T+k),r.lineTo(t,T+k+QW),r.stroke(),r.fillText(jz(e,ge),t,T+k+QW+2)}(m?.style??`solid`)!==`none`&&(r.strokeStyle=m?.color??N,r.lineWidth=m?.width??1,r.setLineDash(rG(m?.style??`solid`)),r.strokeRect(D,T,O,k),r.setLineDash([])),r.fillStyle=j,r.font=`11px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`bottom`,C.tiny||(r.fillText(a,D+O/2,n-4),r.save(),r.translate(14,T+k/2),r.rotate(-Math.PI/2),r.fillText(o,0,0),r.restore());let ve=re.current;if((ve.pts!==i||ve.view!==`${oe}|${se}|${ce}|${le}`)&&(re.current={pts:i,view:`${oe}|${se}|${ce}|${le}`},CH(S.current)),ae)ae.setView(oe,se,ce,le,{left:D,top:T,width:O,height:k}),ae.render();else{let e={xToPx:fe,yToPx:pe,left:D,top:T,plotW:O,plotH:k,dotR:F,col:s,dsColors:v?c:null,hasColormap:x};M.current.drawMode!==`points`&&cG(r,i,e,M.current.lineWidth),M.current.drawMode!==`lines`&&sG(r,i,e)}if(x&&!C.tiny){let e=D+O+10,n=k;for(let t=0;t<64;t++)r.fillStyle=PW(1-t/64),r.fillRect(e,T+t/64*n,10,n/64+1);r.strokeStyle=j,r.lineWidth=.5,r.strokeRect(e,T,10,n),r.fillStyle=j,r.font=`10px ${Q.mono}`,r.textAlign=`left`,r.textBaseline=`top`;let i=u?String(u[1].toPrecision(3)):`1`,a=u?String(u[0].toPrecision(3)):`0`;r.fillText(i,e+10+3,T),r.textBaseline=`bottom`,r.fillText(a,e+10+3,T+n),l&&(r.save(),r.textBaseline=`middle`,r.translate(t-6,T+n/2),r.rotate(Math.PI/2),r.fillText(l,0,0),r.restore())}if(h&&U){let e=ne(i,h.degree,{xmin:oe,xmax:se,ymin:ce,ymax:le});if(e){U.save(),U.beginPath(),U.rect(D,T,O,k),U.clip(),U.strokeStyle=h.color,U.lineWidth=h.width,U.setLineDash(rG(h.lineStyle)),U.beginPath();for(let t=0;t<=300;t++){let n=oe+t/300*ue,r=e.reduce((e,t,r)=>e+t*n**+r,0),i=fe(n),a=pe(r);t===0?U.moveTo(i,a):U.lineTo(i,a)}U.stroke(),U.setLineDash([]);let t=jW(e,`x`,`y`);U.fillStyle=P,U.font=`10px ${Q.mono}`,U.textAlign=`right`,U.textBaseline=`top`,U.fillText(t,D+O-8,T+8),U.restore()}}if((g?.alarm||_?.alarm)&&U){if(U.save(),U.beginPath(),U.rect(D,T,O,k),U.clip(),g?.alarm){let e=g.alarm;U.strokeStyle=e.color,U.lineWidth=e.width,U.setLineDash(e.linked===`active`?iU:rG(e.style));let t=fe(e.value);U.beginPath(),U.moveTo(t,T),U.lineTo(t,T+k),U.stroke(),U.setLineDash([]),e.linked&&oU(U,t+3,T+2,e.color)}if(_?.alarm){let e=_.alarm;U.strokeStyle=e.color,U.lineWidth=e.width,U.setLineDash(e.linked===`active`?iU:rG(e.style));let t=pe(e.value);U.beginPath(),U.moveTo(D,t),U.lineTo(D+O,t),U.stroke(),U.setLineDash([]),e.linked&&oU(U,D+O-10-3,t-10-2,e.color)}U.restore()}}let ae=K(``);function oe(){let e=x.current;if(!e)return;let{w:t,h:n}=z(),r=`${t}x${n}`;if(w.current===null&&ae.current===r)return;let i=R(e,t,n);if(!i)return;i.clearRect(0,0,t,n),ae.current=w.current===null?r:``;let a=w.current,{cols:o,color:s,datasetColors:c,pointRadius:l}=M.current;if(a===null||a>=o.length||o.length<1)return;let u=Math.max(4,l*2),d=o.d?.[a],f=c&&c.length>0&&d!==void 0?c[d]??s:s,{top:p,right:m,bottom:h,left:g}=YW(XW,t,n),_=t-g-m,v=n-p-h;if(_<=0||v<=0)return;let{xmin:y,xmax:b,ymin:S,ymax:C}=I(),T=b-y,E=C-S,D={x:o.x[a],y:o.y[a]},O=g+(D.x-y)/T*_,k=p+(C-D.y)/E*v,{bg:A,muted:j}=L();i.strokeStyle=j,i.globalAlpha=.4,i.lineWidth=1,i.setLineDash([3,3]),i.beginPath(),i.moveTo(O,p),i.lineTo(O,p+v),i.stroke(),i.beginPath(),i.moveTo(g,k),i.lineTo(g+_,k),i.stroke(),i.setLineDash([]),i.globalAlpha=1,i.fillStyle=f,i.beginPath(),i.arc(O,k,u,0,Math.PI*2),i.fill(),i.strokeStyle=A,i.lineWidth=1.5,i.beginPath(),i.arc(O,k,u,0,Math.PI*2),i.stroke();let N=`(${Mz(D.x)}, ${Mz(D.y)})`;i.font=`11px ${Q.mono}`;let P=i.measureText(N).width+12,F=O+10,B=k-24;F+P>g+_&&(F=O-P-10),B<p&&(B=k+10),i.fillStyle=A,i.globalAlpha=.85,i.beginPath(),aG(i,F,B,P,20,4),i.fill(),i.globalAlpha=1,i.strokeStyle=j,i.lineWidth=.5,i.beginPath(),aG(i,F,B,P,20,4),i.stroke(),i.fillStyle=j,i.textAlign=`left`,i.textBaseline=`middle`,i.fillText(N,F+6,B+20/2)}let se=K(U),ce=K(oe);G(()=>{se.current=U,ce.current=oe});let le=K(null);le.current??=DH(()=>{se.current(),ce.current()},()=>S.current);function ue(){le.current.schedule()}function de(){k.current||=bH(()=>{k.current=0,ce.current()})}W(()=>()=>{le.current?.cancel(),xH(k.current),k.current=0},[]);let fe=K(ue),pe=K(de);return G(()=>{fe.current=ue,pe.current=de}),W(()=>eB(S.current,()=>{A.current=null,fe.current()}),[]),W(()=>{A.current=null,fe.current()},[d]),W(()=>{le.current.now()},[e,t,n,r,i,s,c,l,u,p,m,h,g,_,v]),W(()=>{let e=x.current,t=S.current;if(!e||!t)return;let n=new EH(()=>{A.current=null,fe.current()});n.observe(t);let r=null;function i(e,t){let n=M.current.cols;if(n.length===0)return null;let{w:i,h:a}=z(),{top:o,right:s,bottom:c,left:l}=YW(XW,i,a),u=i-l-s,d=a-o-c,{xmin:f,xmax:p,ymin:m,ymax:h}=I(),g=p-f,_=h-m,v=Math.max(12,M.current.pointRadius*10),y=`${i}|${a}|${f}|${p}|${m}|${h}|${v}`;if(!r||r.cols!==n||r.key!==y){let e=Math.max(1,Math.ceil(u/v)),t=Math.max(1,Math.ceil(d/v)),i=t=>{let r=(n.x[t]-f)/g*u,i=(h-n.y[t])/_*d;return r>=0&&r<u&&i>=0&&i<d?Math.floor(i/v)*e+Math.floor(r/v):-1},a=new Uint32Array(e*t+1);for(let e=0;e<n.length;e++){let t=i(e);t>=0&&a[t+1]++}for(let n=0;n<e*t;n++)a[n+1]+=a[n];let o=a.slice(0,e*t),s=new Uint32Array(a[e*t]);for(let e=0;e<n.length;e++){let t=i(e);t>=0&&(s[o[t]++]=e)}r={cols:n,key:y,cell:v,nx:e,start:a,ix:s}}let b=r,x=Math.floor((e-l)/b.cell),S=Math.floor((t-o)/b.cell),C=(b.start.length-1)/b.nx,w=-1,T=v*v;for(let r=S-1;r<=S+1;r++)if(!(r<0||r>=C))for(let i=x-1;i<=x+1;i++){if(i<0||i>=b.nx)continue;let a=r*b.nx+i;for(let r=b.start[a];r<b.start[a+1];r++){let i=b.ix[r],a=l+(n.x[i]-f)/g*u,s=o+(h-n.y[i])/_*d,c=(a-e)**2+(s-t)**2;c<T&&(T=c,w=i)}}return w<0?null:w}let a=t=>{if(M.current.cols.length<1){w.current!==null&&(w.current=null,pe.current());return}let n=e.getBoundingClientRect(),r=t.clientX-n.left,a=t.clientY-n.top,{left:o,top:s,right:c,bottom:l}=YW(XW,n.width,n.height),u=Math.max(1,n.width-o-c),d=n.height-s-l;if(r<o||r>o+u||a<s||a>s+d){w.current!==null&&(w.current=null,pe.current());return}let f=i(r,a);w.current!==f&&(w.current=f,pe.current())},o=()=>{w.current!==null&&(w.current=null,pe.current())},s=t=>{if(M.current.cols.length<1)return;let n=e.getBoundingClientRect(),r=t.clientX-n.left,i=t.clientY-n.top,{top:a,left:o,right:s,bottom:c}=YW(XW,n.width,n.height),l=Math.max(1,n.width-o-s),u=Math.max(1,n.height-a-c);if(r<o||r>o+l||i<a||i>a+u)return;t.preventDefault();let d=P(),f=d.x.max-d.x.min,p=d.y.max-d.y.min,m=I(),h=m.xmin,g=m.xmax,_=m.ymin,v=m.ymax,y=g-h,b=v-_,x=(r-o)/l,S=(i-a)/u,C=h+x*y,w=v-S*b,k=t.deltaY<0,A=.88,j=k?A:1/A,N=y*j,F=b*j;if(!k&&N>=f*.999&&F>=p*.999){T.current=null,E.current=null,D.current=null,O.current=null,fe.current();return}N=tG(N,Math.max(f*1e-7,1e-12),f),F=tG(F,Math.max(p*1e-7,1e-12),p);let L=C-x*N,R=C+(1-x)*N;L<d.x.min&&(R+=d.x.min-L,L=d.x.min),R>d.x.max&&(L-=R-d.x.max,R=d.x.max);let z=w-(1-S)*F,B=w+S*F;z<d.y.min&&(B+=d.y.min-z,z=d.y.min),B>d.y.max&&(z-=B-d.y.max,B=d.y.max),T.current=L,E.current=R,D.current=z,O.current=B,fe.current()},c=e=>{e.button===0&&(T.current===null&&D.current===null||(T.current=null,E.current=null,D.current=null,O.current=null,fe.current(),pe.current()))},l=e=>{e.preventDefault(),C.current?.({clientX:e.clientX,clientY:e.clientY})};return e.addEventListener(`mousemove`,a),e.addEventListener(`mouseleave`,o),e.addEventListener(`wheel`,s,{passive:!1}),e.addEventListener(`contextmenu`,l),e.addEventListener(`dblclick`,c),()=>{n.disconnect(),e.removeEventListener(`mousemove`,a),e.removeEventListener(`mouseleave`,o),e.removeEventListener(`wheel`,s),e.removeEventListener(`contextmenu`,l),e.removeEventListener(`dblclick`,c)}},[]),_t(`div`,{ref:S,className:`chart-canvas-wrap`,children:[q(`canvas`,{ref:b,className:`chart-canvas`,role:`img`,"aria-label":`Scatter ${t} vs ${n}`}),q(`canvas`,{ref:V,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),q(`canvas`,{ref:B,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),q(`canvas`,{ref:x,className:`chart-canvas chart-overlay`})]})}function aG(e,t,n,r,i,a){e.moveTo(t+a,n),e.lineTo(t+r-a,n),e.arcTo(t+r,n,t+r,n+a,a),e.lineTo(t+r,n+i-a),e.arcTo(t+r,n+i,t+r-a,n+i,a),e.lineTo(t+a,n+i),e.arcTo(t,n+i,t,n+i-a,a),e.lineTo(t,n+a),e.arcTo(t,n,t+a,n,a)}function oG(e,t,n){if(e===`single`)return{kind:`single`,rgba:zV(t)};let r=new Uint8Array(256*4);for(let t=0;t<256;t++)if(e===`colormap`){let{r:e,g:n,b:i}=NW(t/255);r.set([e,n,i,255],t*4)}else{let e=zV(n[Math.min(t,n.length-1)]);r.set([e[0]*255,e[1]*255,e[2]*255,e[3]*255],t*4)}return{kind:e===`colormap`?`colormap`:`dataset`,palette:r}}function sG(e,t,n){let r=Math.PI*2,i=n.dsColors?n.dsColors.length:n.hasColormap?24:1,a=Array.from({length:i},()=>new Path2D);for(let e=0;e<t.length;e++){let o=n.xToPx(t.x[e]),s=n.yToPx(t.y[e]);if(!(o>=n.left&&o<=n.left+n.plotW&&s>=n.top&&s<=n.top+n.plotH))continue;let c=n.dsColors?Math.min(t.d?.[e]??0,i-1):n.hasColormap?FW(t.c?.[e]??0,24):0;a[c].moveTo(o+n.dotR,s),a[c].arc(o,s,n.dotR,0,r)}e.globalAlpha=.8;for(let t=0;t<i;t++)e.fillStyle=n.dsColors?n.dsColors[t]:n.hasColormap?PW((t+.5)/24):n.col,e.fill(a[t]);e.globalAlpha=1}function cG(e,t,n,r){e.save(),e.beginPath(),e.rect(n.left,n.top,n.plotW,n.plotH),e.clip(),e.lineWidth=r;let i=n.dsColors?n.dsColors.length:1;for(let r=0;r<i;r++){e.beginPath();let i=!1;for(let a=0;a<t.length;a++){if(n.dsColors&&(t.d?.[a]??0)!==r){i=!1;continue}let o=t.x[a],s=t.y[a];if(o-o!==0||s-s!==0){i=!1;continue}i?e.lineTo(n.xToPx(o),n.yToPx(s)):(e.moveTo(n.xToPx(o),n.yToPx(s)),i=!0)}e.strokeStyle=n.dsColors?n.dsColors[r]:n.col,e.stroke()}e.restore()}var lG=11102230246251565e-32,uG=134217729,dG=(3+8*lG)*lG;function fG(e,t,n,r,i){let a,o,s,c,l=t[0],u=r[0],d=0,f=0;u>l==u>-l?(a=l,l=t[++d]):(a=u,u=r[++f]);let p=0;if(d<e&&f<n)for(u>l==u>-l?(o=l+a,s=a-(o-l),l=t[++d]):(o=u+a,s=a-(o-u),u=r[++f]),a=o,s!==0&&(i[p++]=s);d<e&&f<n;)u>l==u>-l?(o=a+l,c=o-a,s=a-(o-c)+(l-c),l=t[++d]):(o=a+u,c=o-a,s=a-(o-c)+(u-c),u=r[++f]),a=o,s!==0&&(i[p++]=s);for(;d<e;)o=a+l,c=o-a,s=a-(o-c)+(l-c),l=t[++d],a=o,s!==0&&(i[p++]=s);for(;f<n;)o=a+u,c=o-a,s=a-(o-c)+(u-c),u=r[++f],a=o,s!==0&&(i[p++]=s);return(a!==0||p===0)&&(i[p++]=a),p}function pG(e,t){let n=t[0];for(let r=1;r<e;r++)n+=t[r];return n}function $(e){return new Float64Array(e)}var mG=(3+16*lG)*lG,hG=(2+12*lG)*lG,gG=(9+64*lG)*lG*lG,_G=$(4),vG=$(8),yG=$(12),bG=$(16),xG=$(4);function SG(e,t,n,r,i,a,o){let s,c,l,u,d,f,p,m,h,g,_,v,y,b,x,S,C,w,T=e-i,E=n-i,D=t-a,O=r-a;b=T*O,f=uG*T,p=f-(f-T),m=T-p,f=uG*O,h=f-(f-O),g=O-h,x=m*g-(b-p*h-m*h-p*g),S=D*E,f=uG*D,p=f-(f-D),m=D-p,f=uG*E,h=f-(f-E),g=E-h,C=m*g-(S-p*h-m*h-p*g),_=x-C,d=x-_,_G[0]=x-(_+d)+(d-C),v=b+_,d=v-b,y=b-(v-d)+(_-d),_=y-S,d=y-_,_G[1]=y-(_+d)+(d-S),w=v+_,d=w-v,_G[2]=v-(w-d)+(_-d),_G[3]=w;let k=pG(4,_G),A=hG*o;if(k>=A||-k>=A||(d=e-T,s=e-(T+d)+(d-i),d=n-E,l=n-(E+d)+(d-i),d=t-D,c=t-(D+d)+(d-a),d=r-O,u=r-(O+d)+(d-a),s===0&&c===0&&l===0&&u===0)||(A=gG*o+dG*Math.abs(k),k+=T*u+O*s-(D*l+E*c),k>=A||-k>=A))return k;b=s*O,f=uG*s,p=f-(f-s),m=s-p,f=uG*O,h=f-(f-O),g=O-h,x=m*g-(b-p*h-m*h-p*g),S=c*E,f=uG*c,p=f-(f-c),m=c-p,f=uG*E,h=f-(f-E),g=E-h,C=m*g-(S-p*h-m*h-p*g),_=x-C,d=x-_,xG[0]=x-(_+d)+(d-C),v=b+_,d=v-b,y=b-(v-d)+(_-d),_=y-S,d=y-_,xG[1]=y-(_+d)+(d-S),w=v+_,d=w-v,xG[2]=v-(w-d)+(_-d),xG[3]=w;let j=fG(4,_G,4,xG,vG);b=T*u,f=uG*T,p=f-(f-T),m=T-p,f=uG*u,h=f-(f-u),g=u-h,x=m*g-(b-p*h-m*h-p*g),S=D*l,f=uG*D,p=f-(f-D),m=D-p,f=uG*l,h=f-(f-l),g=l-h,C=m*g-(S-p*h-m*h-p*g),_=x-C,d=x-_,xG[0]=x-(_+d)+(d-C),v=b+_,d=v-b,y=b-(v-d)+(_-d),_=y-S,d=y-_,xG[1]=y-(_+d)+(d-S),w=v+_,d=w-v,xG[2]=v-(w-d)+(_-d),xG[3]=w;let M=fG(j,vG,4,xG,yG);return b=s*u,f=uG*s,p=f-(f-s),m=s-p,f=uG*u,h=f-(f-u),g=u-h,x=m*g-(b-p*h-m*h-p*g),S=c*l,f=uG*c,p=f-(f-c),m=c-p,f=uG*l,h=f-(f-l),g=l-h,C=m*g-(S-p*h-m*h-p*g),_=x-C,d=x-_,xG[0]=x-(_+d)+(d-C),v=b+_,d=v-b,y=b-(v-d)+(_-d),_=y-S,d=y-_,xG[1]=y-(_+d)+(d-S),w=v+_,d=w-v,xG[2]=v-(w-d)+(_-d),xG[3]=w,bG[fG(M,yG,4,xG,bG)-1]}function CG(e,t,n,r,i,a){let o=(t-a)*(n-i),s=(e-i)*(r-a),c=o-s,l=Math.abs(o+s);return Math.abs(c)>=mG*l?c:-SG(e,t,n,r,i,a,l)}(7+56*lG)*lG,(3+28*lG)*lG,(26+288*lG)*lG*lG,$(4),$(4),$(4),$(4),$(4),$(4),$(4),$(4),$(4),$(8),$(8),$(8),$(4),$(8),$(8),$(16),$(12),$(192),$(192),(10+96*lG)*lG,(4+48*lG)*lG,(44+576*lG)*lG*lG,$(4),$(4),$(4),$(4),$(4),$(4),$(4),$(4),$(8),$(8),$(8),$(8),$(8),$(8),$(8),$(8),$(8),$(4),$(4),$(4),$(8),$(16),$(16),$(16),$(32),$(32),$(48),$(64),$(1152),$(1152),(16+224*lG)*lG,(5+72*lG)*lG,(71+1408*lG)*lG*lG,$(4),$(4),$(4),$(4),$(4),$(4),$(4),$(4),$(4),$(4),$(24),$(24),$(24),$(24),$(24),$(24),$(24),$(24),$(24),$(24),$(1152),$(1152),$(1152),$(1152),$(1152),$(2304),$(2304),$(3456),$(5760),$(8),$(8),$(8),$(16),$(24),$(48),$(48),$(96),$(192),$(384),$(384),$(384),$(768),$(96),$(96),$(96),$(1152);var wG=2**-52,TG=new Uint32Array(512),EG=class e{static from(t,n=PG,r=FG){let i=t.length,a=new Float64Array(i*2);for(let e=0;e<i;e++){let i=t[e];a[2*e]=n(i),a[2*e+1]=r(i)}return new e(a)}constructor(e){let t=e.length>>1;if(t>0&&typeof e[0]!=`number`)throw Error(`Expected coords to contain numbers.`);this.coords=e;let n=Math.max(2*t-5,0);this._triangles=new Uint32Array(n*3),this._halfedges=new Int32Array(n*3),this._hashSize=Math.ceil(Math.sqrt(t)),this._hullPrev=new Uint32Array(t),this._hullNext=new Uint32Array(t),this._hullTri=new Uint32Array(t),this._hullHash=new Int32Array(this._hashSize),this._ids=new Uint32Array(t),this._dists=new Float64Array(t),this.trianglesLen=0,this._cx=0,this._cy=0,this._hullStart=0,this.hull=this._triangles,this.triangles=this._triangles,this.halfedges=this._halfedges,this.update()}update(){let{coords:e,_hullPrev:t,_hullNext:n,_hullTri:r,_hullHash:i}=this,a=e.length>>1,o=1/0,s=1/0,c=-1/0,l=-1/0;for(let t=0;t<a;t++){let n=e[2*t],r=e[2*t+1];n<o&&(o=n),r<s&&(s=r),n>c&&(c=n),r>l&&(l=r),this._ids[t]=t}let u=(o+c)/2,d=(s+l)/2,f=0,p=0,m=0;for(let t=0,n=1/0;t<a;t++){let r=OG(u,d,e[2*t],e[2*t+1]);r<n&&(f=t,n=r)}let h=e[2*f],g=e[2*f+1];for(let t=0,n=1/0;t<a;t++){if(t===f)continue;let r=OG(h,g,e[2*t],e[2*t+1]);r<n&&r>0&&(p=t,n=r)}let _=e[2*p],v=e[2*p+1],y=1/0;for(let t=0;t<a;t++){if(t===f||t===p)continue;let n=AG(h,g,_,v,e[2*t],e[2*t+1]);n<y&&(m=t,y=n)}let b=e[2*m],x=e[2*m+1];if(y===1/0){for(let t=0;t<a;t++)this._dists[t]=e[2*t]-e[0]||e[2*t+1]-e[1];MG(this._ids,this._dists,0,a-1);let t=new Uint32Array(a),n=0;for(let e=0,r=-1/0;e<a;e++){let i=this._ids[e],a=this._dists[i];a>r&&(t[n++]=i,r=a)}this.hull=t.subarray(0,n),this.triangles=new Uint32Array,this.halfedges=new Int32Array;return}if(CG(h,g,_,v,b,x)<0){let e=p,t=_,n=v;p=m,_=b,v=x,m=e,b=t,x=n}let S=jG(h,g,_,v,b,x);this._cx=S.x,this._cy=S.y;for(let t=0;t<a;t++)this._dists[t]=OG(e[2*t],e[2*t+1],S.x,S.y);MG(this._ids,this._dists,0,a-1),this._hullStart=f;let C=3;n[f]=t[m]=p,n[p]=t[f]=m,n[m]=t[p]=f,r[f]=0,r[p]=1,r[m]=2,i.fill(-1),i[this._hashKey(h,g)]=f,i[this._hashKey(_,v)]=p,i[this._hashKey(b,x)]=m,this.trianglesLen=0,this._addTriangle(f,p,m,-1,-1,-1);for(let a=0,o=0,s=0;a<this._ids.length;a++){let c=this._ids[a],l=e[2*c],u=e[2*c+1];if(a>0&&Math.abs(l-o)<=wG&&Math.abs(u-s)<=wG||(o=l,s=u,c===f||c===p||c===m))continue;let d=0;for(let e=0,t=this._hashKey(l,u);e<this._hashSize&&(d=i[(t+e)%this._hashSize],!(d!==-1&&d!==n[d]));e++);d=t[d];let h=d,g;for(;g=n[h],CG(l,u,e[2*h],e[2*h+1],e[2*g],e[2*g+1])>=0;)if(h=g,h===d){h=-1;break}if(h===-1)continue;let _=this._addTriangle(h,c,n[h],-1,-1,r[h]);r[c]=this._legalize(_+2),r[h]=_,C++;let v=n[h];for(;g=n[v],CG(l,u,e[2*v],e[2*v+1],e[2*g],e[2*g+1])<0;)_=this._addTriangle(v,c,g,r[c],-1,r[v]),r[c]=this._legalize(_+2),n[v]=v,C--,v=g;if(h===d)for(;g=t[h],CG(l,u,e[2*g],e[2*g+1],e[2*h],e[2*h+1])<0;)_=this._addTriangle(g,c,h,-1,r[h],r[g]),this._legalize(_+2),r[g]=_,n[h]=h,C--,h=g;this._hullStart=t[c]=h,n[h]=t[v]=c,n[c]=v,i[this._hashKey(l,u)]=c,i[this._hashKey(e[2*h],e[2*h+1])]=h}this.hull=new Uint32Array(C);for(let e=0,t=this._hullStart;e<C;e++)this.hull[e]=t,t=n[t];this.triangles=this._triangles.subarray(0,this.trianglesLen),this.halfedges=this._halfedges.subarray(0,this.trianglesLen)}_hashKey(e,t){return Math.floor(DG(e-this._cx,t-this._cy)*this._hashSize)%this._hashSize}_legalize(e){let{_triangles:t,_halfedges:n,coords:r}=this,i=0,a=0;for(;;){let o=n[e],s=e-e%3;if(a=s+(e+2)%3,o===-1){if(i===0)break;e=TG[--i];continue}let c=o-o%3,l=s+(e+1)%3,u=c+(o+2)%3,d=t[a],f=t[e],p=t[l],m=t[u];if(kG(r[2*d],r[2*d+1],r[2*f],r[2*f+1],r[2*p],r[2*p+1],r[2*m],r[2*m+1])){t[e]=m,t[o]=d;let r=n[u];if(r===-1){let t=this._hullStart;do{if(this._hullTri[t]===u){this._hullTri[t]=e;break}t=this._hullPrev[t]}while(t!==this._hullStart)}this._link(e,r),this._link(o,n[a]),this._link(a,u);let s=c+(o+1)%3;i<TG.length&&(TG[i++]=s)}else{if(i===0)break;e=TG[--i]}}return a}_link(e,t){this._halfedges[e]=t,t!==-1&&(this._halfedges[t]=e)}_addTriangle(e,t,n,r,i,a){let o=this.trianglesLen;return this._triangles[o]=e,this._triangles[o+1]=t,this._triangles[o+2]=n,this._link(o,r),this._link(o+1,i),this._link(o+2,a),this.trianglesLen+=3,o}};function DG(e,t){let n=e/(Math.abs(e)+Math.abs(t));return(t>0?3-n:1+n)/4}function OG(e,t,n,r){let i=e-n,a=t-r;return i*i+a*a}function kG(e,t,n,r,i,a,o,s){let c=e-o,l=t-s,u=n-o,d=r-s,f=i-o,p=a-s,m=c*c+l*l,h=u*u+d*d,g=f*f+p*p;return c*(d*g-h*p)-l*(u*g-h*f)+m*(u*p-d*f)<0}function AG(e,t,n,r,i,a){let o=n-e,s=r-t,c=i-e,l=a-t,u=o*o+s*s,d=c*c+l*l,f=.5/(o*l-s*c),p=(l*u-s*d)*f,m=(o*d-c*u)*f;return p*p+m*m}function jG(e,t,n,r,i,a){let o=n-e,s=r-t,c=i-e,l=a-t,u=o*o+s*s,d=c*c+l*l,f=.5/(o*l-s*c);return{x:e+(l*u-s*d)*f,y:t+(o*d-c*u)*f}}function MG(e,t,n,r){if(r-n<=20)for(let i=n+1;i<=r;i++){let r=e[i],a=t[r],o=i-1;for(;o>=n&&t[e[o]]>a;)e[o+1]=e[o--];e[o+1]=r}else{let i=n+r>>1,a=n+1,o=r;NG(e,i,a),t[e[n]]>t[e[r]]&&NG(e,n,r),t[e[a]]>t[e[r]]&&NG(e,a,r),t[e[n]]>t[e[a]]&&NG(e,n,a);let s=e[a],c=t[s];for(;;){do a++;while(t[e[a]]<c);do o--;while(t[e[o]]>c);if(o<a)break;NG(e,a,o)}e[n+1]=e[o],e[o]=s,r-a+1>=o-n?(MG(e,t,a,r),MG(e,t,n,o-1)):(MG(e,t,n,o-1),MG(e,t,a,r))}}function NG(e,t,n){let r=e[t];e[t]=e[n],e[n]=r}function PG(e){return e[0]}function FG(e){return e[1]}var IG=`
375
375
  uniform vec3 u_lo; // the box minimum, relative to the data origin
376
376
  uniform vec3 u_span; // the box size (0: a flat axis)
377
377
  uniform int u_flat; // 0: 3D camera, 1: a 2D view
@@ -407,17 +407,17 @@ vec4 place(vec3 d) {
407
407
  float z = clamp(cz / 16.0, 0.0, 1.0) * 2.0 - 1.0;
408
408
  return vec4(c.x * cz, -c.y * cz, z * cz, cz);
409
409
  }
410
- `,FG=`bool outside(vec3 n) { return any(greaterThan(abs(n), vec3(1.0001))); }`,IG=`#version 300 es
410
+ `,LG=`bool outside(vec3 n) { return any(greaterThan(abs(n), vec3(1.0001))); }`,RG=`#version 300 es
411
411
  in float a_x; in float a_y; in float a_z;
412
412
  uniform float u_size;
413
- ${PG}
414
- ${FG}
413
+ ${IG}
414
+ ${LG}
415
415
  void main() {
416
416
  vec3 d = vec3(a_x, a_y, a_z);
417
417
  gl_Position = place(d);
418
418
  gl_PointSize = u_size;
419
419
  if (a_x != a_x || a_y != a_y || a_z != a_z || outside(v_n)) gl_Position = vec4(2.0, 2.0, 2.0, 1.0);
420
- }`,LG=`#version 300 es
420
+ }`,zG=`#version 300 es
421
421
  precision highp float;
422
422
  in vec3 v_n; in vec4 v_color;
423
423
  uniform float u_size; // device px
@@ -428,10 +428,10 @@ void main() {
428
428
  if (u_size >= 3.0 && r > u_size * 0.5) discard;
429
429
  vec4 c = r > u_size * 0.5 - u_rim ? vec4(0.0588, 0.0627, 0.0784, 0.85) : v_color;
430
430
  o = vec4(c.rgb * c.a, c.a);
431
- }`,RG=`#version 300 es
431
+ }`,BG=`#version 300 es
432
432
  in float a_x; in float a_y; in float a_z;
433
- ${PG}
434
- void main() { gl_Position = place(vec3(a_x, a_y, a_z)); }`,zG=`#version 300 es
433
+ ${IG}
434
+ void main() { gl_Position = place(vec3(a_x, a_y, a_z)); }`,VG=`#version 300 es
435
435
  precision highp int;
436
436
  uniform highp sampler2D u_z;
437
437
  uniform ivec2 u_n; // grid size
@@ -440,7 +440,7 @@ uniform int u_wstep; // grid cells between wire lines
440
440
  uniform int u_wire;
441
441
  uniform vec4 u_ext; // x0, x1, y0, y1 (relative to the origin)
442
442
  out float v_hole;
443
- ${PG}
443
+ ${IG}
444
444
  void main() {
445
445
  int cx = (u_n.x - 2) / u_step + 1, cy = (u_n.y - 2) / u_step + 1;
446
446
  int id = gl_VertexID, gx, gy;
@@ -459,29 +459,29 @@ void main() {
459
459
  v_hole = z != z ? 1.0 : 0.0;
460
460
  float fx = u_n.x > 1 ? float(gx) / float(u_n.x - 1) : 0.0, fy = u_n.y > 1 ? float(gy) / float(u_n.y - 1) : 0.0;
461
461
  gl_Position = place(vec3(mix(u_ext.x, u_ext.y, fx), mix(u_ext.z, u_ext.w, fy), z == z ? z : 0.0));
462
- }`,BG=`#version 300 es
462
+ }`,HG=`#version 300 es
463
463
  precision highp float;
464
464
  in vec3 v_n; in vec4 v_color;
465
465
  uniform float u_alpha;
466
466
  uniform vec4 u_solid; // a colour of its own (wire) when its alpha is set
467
- ${FG}
467
+ ${LG}
468
468
  out vec4 o;
469
469
  void main() {
470
470
  if (outside(v_n)) discard;
471
471
  vec4 c = u_solid.a > 0.0 ? u_solid : vec4(v_color.rgb, u_alpha);
472
472
  o = vec4(c.rgb * c.a, c.a);
473
- }`,VG=`#version 300 es
473
+ }`,UG=`#version 300 es
474
474
  precision highp float;
475
475
  in vec3 v_n; in vec4 v_color; in float v_hole;
476
476
  uniform float u_alpha;
477
477
  uniform vec4 u_solid;
478
- ${FG}
478
+ ${LG}
479
479
  out vec4 o;
480
480
  void main() {
481
481
  if (v_hole > 0.0 || outside(v_n)) discard;
482
482
  vec4 c = u_solid.a > 0.0 ? u_solid : vec4(v_color.rgb, u_alpha);
483
483
  o = vec4(c.rgb * c.a, c.a);
484
- }`,HG=16e6,UG=128,WG=[`u_lo`,`u_span`,`u_flat`,`u_eye`,`u_right`,`u_up`,`u_fwd`,`u_f`,`u_h`,`u_v`,`u_c`,`u_plot`,`u_resolution`,`u_palette`];function GG(e){for(let t=0;t<e.length;t++)if(e[t]===e[t]&&Math.abs(e[t])!==1/0)return e[t];return 0}function KG(e){let t=e.getContext(`webgl2`,{antialias:!0,alpha:!0,premultipliedAlpha:!0,depth:!0});if(!t)return null;let n=(e,n,r,i)=>cH(t,`gl3d|${e}|${n}`,()=>{let a=WV(t,t.VERTEX_SHADER,e),o=WV(t,t.FRAGMENT_SHADER,n);if(!a||!o)return null;let s=t.createProgram();return t.attachShader(s,a),t.attachShader(s,o),t.linkProgram(s),t.getProgramParameter(s,t.LINK_STATUS)?{prog:s,a:Object.fromEntries(r.map(e=>[e,t.getAttribLocation(s,e)])),u:Object.fromEntries([...WG,...i].map(e=>[e,t.getUniformLocation(s,e)]))}:(console.error(`gl3d program link failed:`,t.getProgramInfoLog(s)),null)}),r=[`a_x`,`a_y`,`a_z`],i=n(IG,LG,r,[`u_size`,`u_rim`]),a=n(RG,BG,r,[`u_alpha`,`u_solid`]),o=n(zG,VG,[],[`u_alpha`,`u_solid`,`u_z`,`u_n`,`u_step`,`u_wstep`,`u_wire`,`u_ext`]);if(!i||!a||!o)return null;let s=t.getParameter(t.MAX_TEXTURE_SIZE),c=t.createVertexArray(),l={x:t.createBuffer(),y:t.createBuffer(),z:t.createBuffer()},u=t.createBuffer(),d=t.createBuffer(),f=new Map,p=t.createTexture(),m=t.createTexture(),h=1,g=1,_=1,v={minX:0,maxX:1,minY:0,maxY:1,minZ:0,maxZ:1},y={kind:`2d`,h:0,v:1},b={left:0,top:0,width:1,height:1},x=null,S=0,C=[0,0,0],w=0,T=0,E=null,D={w:0,h:0},O=new Float32Array,k=(e,n,r)=>{t.bindBuffer(e,n),r.byteLength<=(f.get(n)??0)?t.bufferSubData(e,0,r):(t.bufferData(e,r,t.DYNAMIC_DRAW),f.set(n,r.byteLength))},A=(e,t)=>{let n=e.length;O.length<n&&(O=new Float32Array(n));for(let r=0;r<n;r++)O[r]=e[r]-t;return O.subarray(0,n)},j=(e,n)=>{let r=e.u,i=v;t.uniform3f(r.u_lo,i.minX-n[0],i.minY-n[1],i.minZ-n[2]);let a=(e,t)=>t-e>1e-12*Math.max(1,Math.abs(e))?t-e:0;t.uniform3f(r.u_span,a(i.minX,i.maxX),a(i.minY,i.maxY),a(i.minZ,i.maxZ));let o=e=>[+(e===0),+(e===1),+(e===2)];y.kind===`3d`?(t.uniform1i(r.u_flat,0),t.uniform3f(r.u_eye,...y.eye),t.uniform3f(r.u_right,...y.right),t.uniform3f(r.u_up,...y.up),t.uniform3f(r.u_fwd,...y.fwd),t.uniform1f(r.u_f,y.f)):(t.uniform1i(r.u_flat,1),t.uniform3f(r.u_h,...o(y.h)),t.uniform3f(r.u_v,...o(y.v))),t.uniform3f(r.u_c,...o(x.colorAxis)),t.uniform4f(r.u_plot,b.left,b.top,b.width,b.height),t.uniform2f(r.u_resolution,h,g),t.uniform1i(r.u_palette,0)},M=e=>{for(let n of[`x`,`y`,`z`]){let r=e.a[`a_${n}`];t.bindBuffer(t.ARRAY_BUFFER,l[n]),t.enableVertexAttribArray(r),t.vertexAttribPointer(r,1,t.FLOAT,!1,0,0)}};return{maxTextureSize:s,resize(t,n,r){h=Math.max(1,t),g=Math.max(1,n),_=r,e.width=Math.max(1,Math.round(h*_)),e.height=Math.max(1,Math.round(g*_))},setBounds(e){v=e},setView(e,t){y=e,b=t},setPoints(e,n,r){if(!e||!n||!r){S=0;return}S=Math.min(e.length,n.length,r.length),C=[GG(e),GG(n),GG(r)],k(t.ARRAY_BUFFER,l.x,A(e,C[0]).subarray(0,S)),k(t.ARRAY_BUFFER,l.y,A(n,C[1]).subarray(0,S)),k(t.ARRAY_BUFFER,l.z,A(r,C[2]).subarray(0,S))},setTriangles(e){if(!e||e.length<3){w=T=0;return}w=e.length-e.length%3,k(t.ELEMENT_ARRAY_BUFFER,u,e.subarray(0,w));let n=new Uint32Array(w*2);for(let t=0;t<w;t+=3){let r=e[t],i=e[t+1],a=e[t+2],o=t*2;n[o]=r,n[o+1]=i,n[o+2]=i,n[o+3]=a,n[o+4]=a,n[o+5]=r}T=n.length,k(t.ELEMENT_ARRAY_BUFFER,d,n)},setSurface(e,n=0,r=0,i=[0,1],a=[0,1]){if(!e||n<2||r<2||n>s||r>s){E=null;return}let o=GG(e),c=A(e,o).subarray(0,n*r);t.bindTexture(t.TEXTURE_2D,m),t.pixelStorei(t.UNPACK_ALIGNMENT,4),D.w===n&&D.h===r?t.texSubImage2D(t.TEXTURE_2D,0,0,0,n,r,t.RED,t.FLOAT,c):(t.texImage2D(t.TEXTURE_2D,0,t.R32F,n,r,0,t.RED,t.FLOAT,c),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),D={w:n,h:r}),E={w:n,h:r,origin:o,ext:[i[0],i[1],a[0],a[1]]}},setStyle(e){x?.palette!==e.palette&&(t.bindTexture(t.TEXTURE_2D,p),t.texImage2D(t.TEXTURE_2D,0,t.RGBA8,256,1,0,t.RGBA,t.UNSIGNED_BYTE,e.palette),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE)),x=e},render(){t.viewport(0,0,e.width,e.height),t.clearColor(0,0,0,0),t.clearDepth(1),t.clear(t.COLOR_BUFFER_BIT|t.DEPTH_BUFFER_BIT);let n=x;if(!n)return;t.bindVertexArray(c),t.enable(t.BLEND),t.blendFunc(t.ONE,t.ONE_MINUS_SRC_ALPHA),t.enable(t.DEPTH_TEST),t.depthFunc(t.LEQUAL),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,p),t.enable(t.POLYGON_OFFSET_FILL),t.polygonOffset(1,1);let r=n.wireColor;if(E){let e=o;t.useProgram(e.prog);let[i,a,s,c]=E.ext;j(e,[i,s,E.origin]),t.uniform4f(e.u.u_ext,0,a-i,0,c-s),t.activeTexture(t.TEXTURE1),t.bindTexture(t.TEXTURE_2D,m),t.uniform1i(e.u.u_z,1),t.uniform2i(e.u.u_n,E.w,E.h);let l=(E.w-1)*(E.h-1),u=Math.max(1,Math.ceil(Math.sqrt(l/HG))),d=Math.floor((E.w-2)/u)+1,f=Math.floor((E.h-2)/u)+1;if(t.uniform1i(e.u.u_step,u),t.uniform1f(e.u.u_alpha,n.fillAlpha),n.fill&&(t.uniform1i(e.u.u_wire,0),t.uniform4f(e.u.u_solid,0,0,0,0),t.drawArrays(t.TRIANGLES,0,d*f*6)),n.wire){let n=u*Math.max(1,Math.ceil(Math.max(d,f)/UG)),i=Math.floor((E.h-1)/n)+1,a=Math.floor((E.w-1)/n)+1;t.uniform1i(e.u.u_wire,1),t.uniform1i(e.u.u_wstep,n),t.uniform4f(e.u.u_solid,...r),t.drawArrays(t.LINES,0,(i*d+a*f)*2)}t.activeTexture(t.TEXTURE0)}if(S>0){if(w>0&&(n.fill||n.wire)){let e=a;t.useProgram(e.prog),j(e,C),M(e),t.uniform1f(e.u.u_alpha,n.fillAlpha),n.fill&&(t.uniform4f(e.u.u_solid,0,0,0,0),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,u),t.drawElements(t.TRIANGLES,w,t.UNSIGNED_INT,0)),n.wire&&(t.uniform4f(e.u.u_solid,...r),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,d),t.drawElements(t.LINES,T,t.UNSIGNED_INT,0))}let e=i;t.useProgram(e.prog),j(e,C),M(e);let o=Math.max(1,2*n.pointRadius*_);t.uniform1f(e.u.u_size,o),t.uniform1f(e.u.u_rim,o>=3?Math.max(.9,n.pointRadius*.3)*_:0),t.drawArrays(t.POINTS,0,S)}t.disable(t.POLYGON_OFFSET_FILL),t.disable(t.DEPTH_TEST),t.bindVertexArray(null)},dispose(){for(let e of[l.x,l.y,l.z,u,d])t.deleteBuffer(e);t.deleteTexture(p),t.deleteTexture(m),t.deleteVertexArray(c)}}}var qG=new Map;function JG(e,t){let n=qG.get(e);if(!n){let r=typeof OffscreenCanvas>`u`?null:new OffscreenCanvas(1,1).getContext(`2d`,{willReadFrequently:!0});if(!r)return[0,0,0,t];r.fillStyle=e,r.fillRect(0,0,1,1);let i=r.getImageData(0,0,1,1).data;qG.set(e,n=[i[0]/255,i[1]/255,i[2]/255,i[3]/255])}return[n[0],n[1],n[2],n[3]*t]}function YG(e,t){return{x:e.x-t.x,y:e.y-t.y,z:e.z-t.z}}function XG(e,t){return{x:e.y*t.z-e.z*t.y,y:e.z*t.x-e.x*t.z,z:e.x*t.y-e.y*t.x}}function ZG(e,t){return e.x*t.x+e.y*t.y+e.z*t.z}function QG(e){return Math.sqrt(e.x*e.x+e.y*e.y+e.z*e.z)}function $G(e){let t=QG(e);return t>1e-12?{x:e.x/t,y:e.y/t,z:e.z/t}:{x:0,y:0,z:1}}function eK(e,t,n,r){let i=Math.cos(n),a=Math.sin(n),o=Math.cos(r),s=Math.sin(r);return{x:e.x+t*o*a,y:e.y+t*s,z:e.z+t*o*i}}function tK(e,t,n){let r=$G(YG(t,e)),i=$G(XG(r,n));return{right:i,up:XG(i,r),fwd:r,eye:e}}function nK(e,t,n,r,i){let a=YG(e,t.eye),o=ZG(a,t.right),s=ZG(a,t.up),c=ZG(a,t.fwd);if(c<.01)return{sx:-9999,sy:-9999,depth:c};let l=1/Math.tan(n/2);return{sx:r/2+o/c*l*(i/2),sy:i/2-s/c*l*(i/2),depth:c}}function rK(e,t,n,r){let i=(e,t,n)=>{let r=n-t;return r<1e-12?0:(e-t)/r*2-1};return{x:i(e,r.minX,r.maxX),y:i(n,r.minZ,r.maxZ),z:i(t,r.minY,r.maxY)}}var iK=16,aK=.1,oK=Math.PI/4,sK=Math.PI/5,cK=3.2,lK=2e4,uK=(()=>{let e=new Uint8Array(256*4);for(let t=0;t<256;t++){let{r:n,g:r,b:i}=jW(t/255);e.set([n,r,i,255],t*4)}return e})();function dK(e){if(!Array.isArray(e))return e;let t=e.length,n=new Float64Array(t),r=new Float64Array(t),i=new Float64Array(t);for(let a=0;a<t;a++)n[a]=e[a].x,r[a]=e[a].y,i[a]=e[a].z;return{length:t,x:n,y:r,z:i}}var fK=(e,t)=>!t||e>=t[0]&&e<=t[1];function pK(e,t,n,r){let i=new Uint32Array(e.length),a=0;for(let o=0;o<e.length;o++){let s=e.x[o],c=e.y[o],l=e.z[o];s-s===0&&c-c===0&&l-l===0&&fK(s,t)&&fK(c,n)&&fK(l,r)&&(i[a++]=o)}if(a<3)return null;let o=new Float64Array(a*2);for(let t=0;t<a;t++)o[2*t]=e.x[i[t]],o[2*t+1]=e.y[i[t]];try{let e=new wG(o).triangles;for(let t=0;t<e.length;t++)e[t]=i[e[t]];return e.length>=3?e:null}catch{return null}}var mK=at(function({points:e,surface:t,xLabel:n,yLabel:r,zLabel:i,height:a=500,backgroundToken:o=``,xRange:s,yRange:c,zRange:l,viewMode:u,pointRadius:d=4,alarms:f,showMesh:p=!1,meshStyle:m=`filled`,meshOpacity:h=.85,onPlotContextMenu:g},_){let v=K(g);G(()=>{v.current=g},[g]);let y=K(null),b=K(null),x=K(null),S=K(oK),C=K(sK),w=K(cK),T=K(null),E=K({xLabel:n,yLabel:r,zLabel:i,height:a,viewMode:u,pointRadius:d,alarms:f??[],showMesh:p,meshStyle:m,meshOpacity:h});G(()=>{E.current={xLabel:n,yLabel:r,zLabel:i,height:a,viewMode:u,pointRadius:d,alarms:f??[],showMesh:p,meshStyle:m,meshOpacity:h}},[n,r,i,a,u,d,f,p,m,h]);let D=dt(()=>{let n=dK(e),r=1/0,i=-1/0,a=1/0,o=-1/0,u=1/0,d=-1/0,f=0,p=0,m=0,h=0;for(let e=0;e<n.length;e++){let t=n.x[e],g=n.y[e],_=n.z[e];t-t!==0||g-g!==0||_-_!==0||!fK(t,s)||!fK(g,c)||!fK(_,l)||(t<r&&(r=t),t>i&&(i=t),g<a&&(a=g),g>o&&(o=g),_<u&&(u=_),_>d&&(d=_),f+=t,p+=g,m+=_,h++)}let g=null;if(t&&t.w>=2&&t.h>=2){let e=t.values,n=!1;for(let r=0;r<t.w*t.h;r++){let t=e[r];t-t===0&&(n=!0,t<u&&(u=t),t>d&&(d=t))}n&&(g=t,r=Math.min(r,t.x[0],t.x[1]),i=Math.max(i,t.x[0],t.x[1]),a=Math.min(a,t.y[0],t.y[1]),o=Math.max(o,t.y[0],t.y[1]))}if(h===0&&!g)return null;s&&(r=s[0],i=s[1]),c&&(a=c[0],o=c[1]),l&&(u=l[0],d=l[1]);let _={minX:r,maxX:i,minY:a,maxY:o,minZ:u,maxZ:d},v=h>0?rK(f/h,p/h,m/h,_):{x:0,y:0,z:0};return{cols:h>0?n:null,surface:g,bounds:_,center:v}},[e,t,s,c,l]),O=u??`3d`,k=p&&(O===`3d`||O===`xy`),A=dt(()=>k&&D?.cols?pK(D.cols,s,c,l):null,[k,D,s,c,l]),j=K({model:D,triangles:A});G(()=>{j.current={model:D,triangles:A}},[D,A]);let M=K({r:null,failed:!1,cols:null,surface:null,tris:null,size:``});function N(e,t,n){let r=M.current;!r.r&&!r.failed&&b.current&&(r.r=lH(b.current,KG),r.failed=!r.r);let i=r.r;if(!i||!b.current)return null;let a=`${e}x${t}@${n}`;r.size!==a&&(i.resize(e,t,n),b.current.style.width=`${e}px`,b.current.style.height=`${t}px`,r.size=a);let{model:o,triangles:s}=j.current,c=o?.cols??null;r.cols!==c&&(i.setPoints(c?.x??null,c?.y,c?.z),r.cols=c);let l=o?.surface??null;return r.surface!==l&&(i.setSurface(l?.values??null,l?.w,l?.h,l?.x,l?.y),r.surface=l),r.tris!==s&&(i.setTriangles(s),r.tris=s),i}W(()=>()=>{M.current.r?.dispose(),M.current.r=null},[]);let P=K(null);function F(){let e=y.current,t=x.current;if(!e||!t)return;let n=Math.max(1,t.clientWidth),r=Math.max(1,t.clientHeight),i=Math.min(2,window.devicePixelRatio||1),a=Math.floor(n*i),o=Math.floor(r*i);(e.width!==a||e.height!==o)&&(e.width=a,e.height=o);let s=e.getContext(`2d`);if(!s)return;s.setTransform(i,0,0,i,0,0);let{bg:c,muted:l,grid:u}=I(),{xLabel:d,yLabel:f,zLabel:p}=E.current,m=Math.max(.25,E.current.pointRadius??4),h=qW({top:0,right:0,bottom:0,left:0},n,r).tiny;s.fillStyle=c,s.fillRect(0,0,n,r);let g=j.current.model,_=N(n,r,i);if(!g){if(_?.setStyle({palette:uK,colorAxis:2,pointRadius:m,fill:!1,wire:!1,fillAlpha:1,wireColor:[0,0,0,0]}),_?.setPoints(null),M.current.cols=null,_?.render(),h)return;s.fillStyle=l,s.font=`13px ${Q.sans}`,s.fillText(`Need at least one sample point`,iK,32);return}let v=g.bounds,b=E.current.viewMode??`3d`,T=b===`xz`?1:b===`yz`?0:2,D=[v.minX,v.minY,v.minZ][T],O=[v.maxX,v.maxY,v.maxZ][T],k=(e,t,n)=>{let r=T===0?e:T===1?t:n,i=O-D;return i>1e-12?(r-D)/i:.5},A,F,L,R=(e,t,r)=>{let i=n-28,a=t/32;for(let t=0;t<32;t++)s.fillStyle=MW(1-t/32),s.fillRect(i,e+t*a,14,a+1);s.strokeStyle=u,s.lineWidth=1,s.strokeRect(i,e,14,t),s.fillStyle=l,s.font=`9px ${Q.mono}`,s.textAlign=`right`,s.fillText(Mz(O),i-4,e+4),s.fillText(Mz(D),i-4,e+t),s.fillText(r,i-4,e-6)},z=e=>{s.fillStyle=l,s.font=`10px ${Q.sans}`,s.textAlign=`left`,s.globalAlpha=.7,s.fillText(e,iK,r-6),s.globalAlpha=1};if(b!==`3d`){let e,t,i,a,o,c,m,g,_;b===`xy`?(e=d,t=f,i=p,a=v.minX,o=v.maxX,c=v.minY,m=v.maxY,g=0,_=1):b===`xz`?(e=d,t=p,i=f,a=v.minX,o=v.maxX,c=v.minZ,m=v.maxZ,g=0,_=2):(e=f,t=p,i=d,a=v.minY,o=v.maxY,c=v.minZ,m=v.maxZ,g=1,_=2);let y=qW({left:72,right:48,top:24,bottom:52},n,r),x=Math.max(1,n-y.left-y.right),S=Math.max(1,r-y.top-y.bottom),C=o-a||1,w=m-c||1,T=e=>y.left+(e-a)/C*x,D=e=>y.top+S-(e-c)/w*S;A={left:y.left,top:y.top,width:x,height:S},L={kind:`2d`,h:g,v:_},F=(e,t,n)=>{let r=[e,t,n];return[T(r[g]),D(r[_])]};let O=wz(C,8),k=wz(w,8),j=Dz(a,o,O),M=Dz(c,m,k);s.strokeStyle=u,s.lineWidth=.5,s.globalAlpha=.3;for(let e of j){let t=T(e);s.beginPath(),s.moveTo(t,y.top),s.lineTo(t,y.top+S),s.stroke()}for(let e of M){let t=D(e);s.beginPath(),s.moveTo(y.left,t),s.lineTo(y.left+x,t),s.stroke()}s.globalAlpha=1,s.strokeStyle=u,s.lineWidth=1,s.strokeRect(y.left,y.top,x,S),s.save(),s.beginPath(),s.rect(y.left,y.top,x,S),s.clip();for(let e of E.current.alarms){let{axis:t,value:n,color:r,style:i,width:a}=e,o=null,c=null;b===`xy`?t===`x`?o=T(n):t===`y`&&(c=D(n)):b===`xz`?t===`x`?o=T(n):t===`z`&&(c=D(n)):t===`y`?o=T(n):t===`z`&&(c=D(n)),!(o===null&&c===null)&&(i===`dashed`?s.setLineDash([7,4]):i===`dotted`?s.setLineDash([2,4]):s.setLineDash([]),s.strokeStyle=r,s.lineWidth=a,s.globalAlpha=.9,s.beginPath(),o===null?c!==null&&(s.moveTo(y.left,c),s.lineTo(y.left+x,c)):(s.moveTo(o,y.top),s.lineTo(o,y.top+S)),s.stroke(),s.setLineDash([]),s.globalAlpha=1,s.fillStyle=r,s.font=`bold 10px ${Q.mono}`,s.globalAlpha=.95,o===null?c!==null&&(s.textAlign=`left`,s.textBaseline=`bottom`,s.fillText(Mz(n),y.left+3,c-2)):(s.textAlign=`left`,s.textBaseline=`top`,s.fillText(Mz(n),o+3,y.top+2)),s.globalAlpha=1,s.textBaseline=`alphabetic`)}if(s.restore(),!h){s.fillStyle=l,s.font=`10px ${Q.mono}`,s.textAlign=`center`,s.textBaseline=`top`;for(let e of j)s.fillText(jz(e,O),T(e),y.top+S+6);s.textAlign=`right`,s.textBaseline=`middle`;for(let e of M)s.fillText(jz(e,k),y.left-8,D(e));s.textBaseline=`alphabetic`,s.font=`bold 11px ${Q.mono}`,s.textAlign=`center`,s.fillStyle=`#fb7185`,s.fillText(e,y.left+x/2,r-8),s.save(),s.translate(14,y.top+S/2),s.rotate(-Math.PI/2),s.fillStyle=`#38bdf8`,s.textAlign=`center`,s.fillText(t,0,0),s.restore(),R(y.top+8,Math.min(S-20,180),i),z(`2D projection: ${b.toUpperCase()} plane · Color = ${i}`)}}else{let e=S.current,t=C.current,i=w.current,a=tK(eK(g.center,i,e,t),g.center,{x:0,y:1,z:0}),o=Math.PI/3,c=h?3:iK,m=Math.max(1,n-c*2),_=Math.max(1,r-c*2-(h?0:24));A={left:c,top:c,width:m,height:_};let y=e=>[e.x,e.y,e.z];L={kind:`3d`,eye:y(a.eye),right:y(a.right),up:y(a.up),fwd:y(a.fwd),f:1/Math.tan(o/2)};let b=e=>{let t=nK(e,a,o,m,_);return{sx:t.sx+c,sy:t.sy+c,depth:t.depth}};F=(e,t,n)=>{let r=b(rK(e,t,n,v));return r.depth<.02?null:[r.sx,r.sy]};let x=(e,t,n)=>{let r=b(e),i=b(t);r.depth<.02||i.depth<.02||(s.strokeStyle=n.color,s.lineWidth=n.width,s.globalAlpha=n.alpha??1,s.beginPath(),s.moveTo(r.sx,r.sy),s.lineTo(i.sx,i.sy),s.stroke(),s.globalAlpha=1)},T=wz(v.maxX-v.minX,6),D=wz(v.maxY-v.minY,6),O=wz(v.maxZ-v.minZ,6),k=Dz(v.minX,v.maxX,T),j=Dz(v.minY,v.maxY,D),M=Dz(v.minZ,v.maxZ,O),N=Oz(v.minX,v.maxX,T/5,k),P=Oz(v.minY,v.maxY,D/5,j),I=Oz(v.minZ,v.maxZ,O/5,M);for(let[e,t]of[[{x:-1,y:-1,z:-1},{x:1,y:-1,z:-1}],[{x:1,y:-1,z:-1},{x:1,y:-1,z:1}],[{x:1,y:-1,z:1},{x:-1,y:-1,z:1}],[{x:-1,y:-1,z:1},{x:-1,y:-1,z:-1}],[{x:-1,y:1,z:-1},{x:1,y:1,z:-1}],[{x:1,y:1,z:-1},{x:1,y:1,z:1}],[{x:1,y:1,z:1},{x:-1,y:1,z:1}],[{x:-1,y:1,z:1},{x:-1,y:1,z:-1}],[{x:-1,y:-1,z:-1},{x:-1,y:1,z:-1}],[{x:1,y:-1,z:-1},{x:1,y:1,z:-1}],[{x:1,y:-1,z:1},{x:1,y:1,z:1}],[{x:-1,y:-1,z:1},{x:-1,y:1,z:1}]])x(e,t,{color:u,width:1,alpha:.65});if(!h){for(let e of k){let t=rK(e,v.minY,v.minZ,v).x;x({x:t,y:-1,z:-1},{x:t,y:-1,z:1},{color:u,width:.75,alpha:.45})}for(let e of j){let t=rK(v.minX,e,v.minZ,v).z;x({x:-1,y:-1,z:t},{x:1,y:-1,z:t},{color:u,width:.75,alpha:.45})}for(let e of P){let t=rK(v.minX,e,v.minZ,v).z;x({x:-1,y:-1,z:t},{x:1,y:-1,z:t},{color:u,width:.5,alpha:.22})}for(let e of N){let t=rK(e,v.minY,v.minZ,v).x;x({x:t,y:-1,z:-1},{x:t,y:-1,z:1},{color:u,width:.5,alpha:.22})}let e=(e,t)=>{let n=aK*(t?1:.55);x({x:e,y:-1,z:-1},{x:e,y:-1+n,z:-1},{color:`#fb7185`,width:t?1.25:.75,alpha:.95})},t=(e,t)=>{let n=aK*(t?1:.55);x({x:-1,y:-1,z:e},{x:-1+n,y:-1,z:e},{color:`#38bdf8`,width:t?1.25:.75,alpha:.95})},n=(e,t)=>{let n=aK*(t?1:.55);x({x:-1,y:e,z:-1},{x:-1+n,y:e,z:-1},{color:`#4ade80`,width:t?1.25:.75,alpha:.95})};for(let t of N)e(rK(t,v.minY,v.minZ,v).x,!1);for(let t of k)e(rK(t,v.minY,v.minZ,v).x,!0);for(let e of P)t(rK(v.minX,e,v.minZ,v).z,!1);for(let e of j)t(rK(v.minX,e,v.minZ,v).z,!0);for(let e of I)n(rK(v.minX,v.minY,e,v).y,!1);for(let e of M)n(rK(v.minX,v.minY,e,v).y,!0)}let B=(e,t,n)=>{let r=n-t;return r<1e-12?0:(e-t)/r*2-1};for(let e of E.current.alarms){let{axis:t,value:n,color:r,style:i,width:a}=e,o;if(t===`z`){let e=B(n,v.minZ,v.maxZ);o=[{x:-1,y:e,z:-1},{x:1,y:e,z:-1},{x:1,y:e,z:1},{x:-1,y:e,z:1}]}else if(t===`x`){let e=B(n,v.minX,v.maxX);o=[{x:e,y:-1,z:-1},{x:e,y:1,z:-1},{x:e,y:1,z:1},{x:e,y:-1,z:1}]}else{let e=B(n,v.minY,v.maxY);o=[{x:-1,y:-1,z:e},{x:1,y:-1,z:e},{x:1,y:1,z:e},{x:-1,y:1,z:e}]}let c=o.map(e=>b(e));if(c.every(e=>e.depth>=.02)){s.beginPath(),s.moveTo(c[0].sx,c[0].sy);for(let e=1;e<c.length;e++)s.lineTo(c[e].sx,c[e].sy);s.closePath(),s.fillStyle=r,s.globalAlpha=.18,s.fill(),i===`dashed`?s.setLineDash([7,4]):i===`dotted`?s.setLineDash([2,4]):s.setLineDash([]),s.strokeStyle=r,s.lineWidth=a,s.globalAlpha=.9,s.beginPath(),s.moveTo(c[0].sx,c[0].sy);for(let e=1;e<c.length;e++)s.lineTo(c[e].sx,c[e].sy);s.closePath(),s.stroke(),s.setLineDash([]),s.globalAlpha=1;let e=c.reduce((e,t)=>t.sy>e.sy?t:e);s.fillStyle=r,s.font=`bold 10px ${Q.mono}`,s.textAlign=`center`,s.globalAlpha=.95,s.fillText(`${t.toUpperCase()}=${Mz(n)}`,e.sx,e.sy-6),s.globalAlpha=1}}if(!h){s.font=`10px ${Q.mono}`,s.textBaseline=`middle`;for(let e of k){let t=rK(e,v.minY,v.minZ,v).x,n=b({x:t,y:-1.2,z:-1.2});n.depth<.02||(s.fillStyle=l,s.textAlign=`center`,s.fillText(jz(e,T),n.sx,n.sy+12))}for(let e of j){let t=rK(v.minX,e,v.minZ,v).z,n=b({x:-1.22,y:-1,z:t});n.depth<.02||(s.textAlign=`right`,s.fillText(jz(e,D),n.sx-4,n.sy))}for(let e of M){let t=rK(v.minX,v.minY,e,v).y,n=b({x:-1.22,y:t,z:-1.2});n.depth<.02||(s.textAlign=`right`,s.fillText(jz(e,O),n.sx-4,n.sy))}s.textBaseline=`alphabetic`,s.font=`bold 11px ${Q.mono}`;let e=b({x:1.15,y:-1,z:-1.15});e.depth>=.02&&(s.fillStyle=`#fb7185`,s.textAlign=`center`,s.fillText(d,e.sx,e.sy+16)),e=b({x:-1.18,y:-1,z:1.15}),e.depth>=.02&&(s.fillStyle=`#38bdf8`,s.textAlign=`center`,s.fillText(f,e.sx-10,e.sy)),e=b({x:-1.18,y:1.15,z:-1.18}),e.depth>=.02&&(s.fillStyle=`#4ade80`,s.textAlign=`center`,s.fillText(p,e.sx-10,e.sy)),R(iK+8,Math.min(r-80,180),p),z(`Drag: rotate | Wheel: zoom | Dbl‑click: reset · ${g.surface?`Surface`:E.current.showMesh?`Mesh: ${E.current.meshStyle}`:`Scatter`} · color = Z`)}}let{showMesh:B,meshStyle:V,meshOpacity:ee}=E.current,te=!!g.surface||B;if(_)_.setBounds(v),_.setView(L,A),_.setStyle({palette:uK,colorAxis:T,pointRadius:m,fill:te&&(V===`filled`||V===`both`),wire:te&&(V===`wireframe`||V===`both`),fillAlpha:ee,wireColor:JG(u,.5)}),_.render(),P.current!==g&&(P.current=g,SH(t));else if(g.cols){let e=g.cols,t=Math.max(1,Math.ceil(e.length/lK));for(let n=0;n<e.length;n+=t){let t=e.x[n],r=e.y[n],i=e.z[n];if(!(t>=v.minX&&t<=v.maxX&&r>=v.minY&&r<=v.maxY&&i>=v.minZ&&i<=v.maxZ))continue;let a=F(t,r,i);a&&(s.fillStyle=MW(k(t,r,i)),s.beginPath(),s.arc(a[0],a[1],m,0,Math.PI*2),s.fill())}}}function I(){if(T.current)return T.current;let e=x.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return T.current=n,n}let L=K(F);G(()=>{L.current=F});let R=K(null);R.current??=EH(()=>L.current(),()=>x.current?.ownerDocument),W(()=>()=>R.current?.cancel(),[]);let z=()=>{S.current=oK,C.current=sK,w.current=cK,R.current.schedule()};return ut(_,()=>({autoscale:z}),[]),W(()=>eB(x.current,()=>{T.current=null,R.current.schedule()}),[]),W(()=>{T.current=null,R.current.schedule()},[o]),W(()=>{R.current.now()},[D,A,n,r,i,a,u,d,f,p,m,h]),W(()=>{let e=y.current,t=x.current;if(!e||!t)return;let n=()=>R.current.schedule(),r=new TH(()=>{T.current=null,n()});r.observe(t);let i=!1,a=0,o=0,s=t=>{t.button===0&&(i=!0,a=t.clientX,o=t.clientY,e.setPointerCapture(t.pointerId))},c=e=>{if(!i)return;let t=e.clientX-a,r=e.clientY-o;a=e.clientX,o=e.clientY,S.current-=t*.008,C.current+=r*.008,C.current=Math.max(-Math.PI/2+.05,Math.min(Math.PI/2-.05,C.current)),n()},l=()=>{i=!1},u=e=>{e.preventDefault();let t=e.deltaY>0?1.08:.92;w.current=Math.max(1.2,Math.min(12,w.current*t)),n()},d=()=>{S.current=oK,C.current=sK,w.current=cK,n()},f=e=>{e.preventDefault(),v.current?.({clientX:e.clientX,clientY:e.clientY})};return e.addEventListener(`pointerdown`,s),e.addEventListener(`pointermove`,c),e.addEventListener(`pointerup`,l),e.addEventListener(`pointercancel`,l),e.addEventListener(`wheel`,u,{passive:!1}),e.addEventListener(`contextmenu`,f),e.addEventListener(`dblclick`,d),()=>{r.disconnect(),e.removeEventListener(`pointerdown`,s),e.removeEventListener(`pointermove`,c),e.removeEventListener(`pointerup`,l),e.removeEventListener(`pointercancel`,l),e.removeEventListener(`wheel`,u),e.removeEventListener(`contextmenu`,f),e.removeEventListener(`dblclick`,d)}},[]),_t(`div`,{ref:x,className:`chart-canvas-wrap`,children:[q(`canvas`,{ref:y,className:`chart-canvas`,role:`img`,"aria-label":`3D scatter: ${n} vs ${r} vs ${i}`,style:{display:`block`,width:`100%`,height:`100%`,cursor:`grab`}}),q(`canvas`,{ref:b,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}})]})}),hK={top:14,right:24,bottom:40,left:64},gK=5;function _K(e){return e===`dashed`?[5,4]:e===`dotted`?[1,4]:[]}function vK(e){return Math.max(10,Math.min(200,Math.ceil(Math.sqrt(e))))}function yK(e,t,n){let r=(e-t)/n;return Math.exp(-.5*r*r)/(n*Math.sqrt(2*Math.PI))}function bK(e,t){let n=e.length;if(n===0)return null;let r=1/0,i=-1/0,a=0;for(let t=0;t<n;t++){let n=e[t];n<r&&(r=n),n>i&&(i=n),a+=n}r===i&&(--r,i+=1);let o=t>0?t:vK(n),s=(i-r)/o,c=Array(o).fill(0),l=a/n,u=0;for(let t=0;t<n;t++){let n=e[t];c[Math.min(o-1,Math.floor((n-r)/s))]++,u+=(n-l)**2}return{lo:r,hi:i,nBins:o,width:s,counts:c,mean:l,sd:Math.sqrt(u/n),total:n}}function xK({values:e,label:t,bins:n=0,color:r=`#38bdf8`,showNormal:i=!1,logY:a=!1,height:o=400,backgroundToken:s=``,onPlotContextMenu:c}){let l=eU(),u=K(null),d=K(null),f=K(null),p=K(null),m=K(0),h=K(null),g=K(c);G(()=>{g.current=c},[c]);let _=K({values:e,label:t,bins:n,color:r,showNormal:i,logY:a,height:o});G(()=>{_.current={values:e,label:t,bins:n,color:r,showNormal:i,logY:a,height:o}},[e,t,n,r,i,a,o]);function v(){if(h.current)return h.current;let e=f.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return h.current=n,n}function y(){let e=f.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||_.current.height)}}function b(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}let x=dt(()=>bK(e,n),[e,n]),S=K(x);G(()=>{S.current=x},[x]);let C=()=>S.current;function w(){let e=u.current;if(!e)return;let{w:t,h:n}=y(),r=b(e,t,n);if(!r)return;let{top:i,right:a,bottom:o,left:s}=hK,c=t-s-a,d=n-i-o,{bg:f,muted:p,grid:m}=v(),{label:h,color:g,showNormal:x,logY:S}=_.current;r.fillStyle=f,r.fillRect(0,0,t,n);let w=C();if(!w||c<=0||d<=0){r.fillStyle=p,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`No data`,s+8,i+8);return}let{lo:T,hi:E,nBins:D,width:O,counts:k,mean:A,sd:j,total:M}=w,N=Math.max(...k),P=S?Math.log10(N+1)+.1:N*1.08,F=e=>s+(e-T)/(E-T)*c;l({left:s,top:i,width:c,height:d,x:{v0:T,v1:E}});let I=e=>i+(P-(S?e>0?Math.log10(e):0:e))/(P-0)*d,L=S?1:wz(P,5),R=Dz(0,S?P:N,L);r.strokeStyle=m,r.lineWidth=1,r.setLineDash(_K(`dashed`));for(let e of R){let t=I(e);r.beginPath(),r.moveTo(s,t),r.lineTo(s+c,t),r.stroke()}r.setLineDash([]);let z=Math.max(.5,c/D*.04);for(let e=0;e<D;e++){let t=F(T+e*O)+z/2,n=F(T+(e+1)*O)-z/2,i=I(0),a=I(k[e]);r.fillStyle=g,r.globalAlpha=.75,r.fillRect(t,a,n-t,i-a),r.globalAlpha=1}if(x&&j>0){r.beginPath();for(let e=0;e<=200;e++){let t=T+e/200*(E-T),n=yK(t,A,j)*M*O,i=F(t),a=I(n);e===0?r.moveTo(i,a):r.lineTo(i,a)}r.strokeStyle=`#f97316`,r.lineWidth=1,r.stroke()}r.strokeStyle=p,r.lineWidth=1,r.fillStyle=p,r.font=`11px ${Q.mono}`,r.textAlign=`right`,r.textBaseline=`middle`;for(let e of R){let t=I(e);r.beginPath(),r.moveTo(s-gK,t),r.lineTo(s,t),r.stroke(),r.fillText(S?`10^${e.toFixed(0)}`:jz(e,L),s-4,t)}let B=wz(E-T,Tz(c)),V=Dz(T,E,B);r.fillStyle=p,r.textAlign=`center`,r.textBaseline=`top`;for(let e of V){let t=F(e);r.beginPath(),r.moveTo(t,i+d),r.lineTo(t,i+d+gK),r.stroke(),r.fillText(jz(e,B),t,i+d+gK+2)}r.strokeStyle=m,r.lineWidth=1,r.strokeRect(s,i,c,d),r.fillStyle=p,r.font=`11px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`bottom`,r.fillText(h,s+c/2,n-4),r.save(),r.translate(14,i+d/2),r.rotate(-Math.PI/2),r.textAlign=`center`,r.textBaseline=`middle`,r.fillText(S?`log₁₀(count)`:`count`,0,0),r.restore()}let T=K(w);T.current=w;let E=K(null);E.current??=EH(()=>T.current(),()=>f.current?.ownerDocument);let D=()=>E.current.schedule();function O(e){let t=d.current;if(!t)return;let{w:n,h:r}=y(),i=b(t,n,r);if(!i||(i.clearRect(0,0,n,r),e===null))return;let{top:a,right:o,bottom:s,left:c}=hK,l=n-c-o,u=r-a-s,{muted:f}=v(),p=C();if(!p)return;let{lo:m,hi:h,width:g,counts:_}=p,x=e=>c+(e-m)/(h-m)*l,S=x(m+e*g),w=x(m+(e+1)*g);i.fillStyle=`rgba(255,255,255,0.12)`,i.fillRect(S,a,w-S,u);let T=(S+w)/2,E=_[e],D=(E/p.total*100).toFixed(1),O=`${Mz(m+e*g)} – ${Mz(m+(e+1)*g)}`,k=`n = ${E} (${D}%)`;i.font=`11px ${Q.mono}`;let A=i.measureText(k).width,j=i.measureText(O).width,M=Math.max(A,j),N=Math.min(T+8,c+l-M-8);i.fillStyle=f,i.textAlign=`left`,i.textBaseline=`top`,i.fillText(O,N,a+8),i.fillText(k,N,a+22)}function k(){bH(m.current),m.current=yH(()=>O(p.current))}return W(()=>{E.current.now()}),W(()=>()=>E.current?.cancel(),[]),W(()=>{h.current=null,D()},[s]),G(()=>{let e=f.current;if(!e)return;let t=new TH(()=>{h.current=null,D(),k()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=d.current;if(!e)return;function t(t){let n=e.getBoundingClientRect(),{left:r}=hK,i=n.width-hK.left-hK.right,a=C();if(!a||i<=0){p.current=null,k();return}let o=t.clientX-n.left-r,s=Math.floor(o/i*a.nBins);p.current=s>=0&&s<a.nBins?s:null,k()}function n(){p.current=null,k()}function r(e){e.preventDefault(),g.current?.({clientX:e.clientX,clientY:e.clientY})}return e.addEventListener(`mousemove`,t),e.addEventListener(`mouseleave`,n),e.addEventListener(`contextmenu`,r),()=>{e.removeEventListener(`mousemove`,t),e.removeEventListener(`mouseleave`,n),e.removeEventListener(`contextmenu`,r)}},[]),_t(`div`,{ref:f,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:u,className:`chart-canvas`,role:`img`,"aria-label":`Histogram of ${t}`}),q(`canvas`,{ref:d,className:`chart-canvas chart-overlay`})]})}var SK=`
484
+ }`,WG=16e6,GG=128,KG=[`u_lo`,`u_span`,`u_flat`,`u_eye`,`u_right`,`u_up`,`u_fwd`,`u_f`,`u_h`,`u_v`,`u_c`,`u_plot`,`u_resolution`,`u_palette`];function qG(e){for(let t=0;t<e.length;t++)if(e[t]===e[t]&&Math.abs(e[t])!==1/0)return e[t];return 0}function JG(e){let t=e.getContext(`webgl2`,{antialias:!0,alpha:!0,premultipliedAlpha:!0,depth:!0});if(!t)return null;let n=(e,n,r,i)=>lH(t,`gl3d|${e}|${n}`,()=>{let a=WV(t,t.VERTEX_SHADER,e),o=WV(t,t.FRAGMENT_SHADER,n);if(!a||!o)return null;let s=t.createProgram();return t.attachShader(s,a),t.attachShader(s,o),t.linkProgram(s),t.getProgramParameter(s,t.LINK_STATUS)?{prog:s,a:Object.fromEntries(r.map(e=>[e,t.getAttribLocation(s,e)])),u:Object.fromEntries([...KG,...i].map(e=>[e,t.getUniformLocation(s,e)]))}:(console.error(`gl3d program link failed:`,t.getProgramInfoLog(s)),null)}),r=[`a_x`,`a_y`,`a_z`],i=n(RG,zG,r,[`u_size`,`u_rim`]),a=n(BG,HG,r,[`u_alpha`,`u_solid`]),o=n(VG,UG,[],[`u_alpha`,`u_solid`,`u_z`,`u_n`,`u_step`,`u_wstep`,`u_wire`,`u_ext`]);if(!i||!a||!o)return null;let s=t.getParameter(t.MAX_TEXTURE_SIZE),c=t.createVertexArray(),l={x:t.createBuffer(),y:t.createBuffer(),z:t.createBuffer()},u=t.createBuffer(),d=t.createBuffer(),f=new Map,p=t.createTexture(),m=t.createTexture(),h=1,g=1,_=1,v={minX:0,maxX:1,minY:0,maxY:1,minZ:0,maxZ:1},y={kind:`2d`,h:0,v:1},b={left:0,top:0,width:1,height:1},x=null,S=0,C=[0,0,0],w=0,T=0,E=null,D={w:0,h:0},O=new Float32Array,k=(e,n,r)=>{t.bindBuffer(e,n),r.byteLength<=(f.get(n)??0)?t.bufferSubData(e,0,r):(t.bufferData(e,r,t.DYNAMIC_DRAW),f.set(n,r.byteLength))},A=(e,t)=>{let n=e.length;O.length<n&&(O=new Float32Array(n));for(let r=0;r<n;r++)O[r]=e[r]-t;return O.subarray(0,n)},j=(e,n)=>{let r=e.u,i=v;t.uniform3f(r.u_lo,i.minX-n[0],i.minY-n[1],i.minZ-n[2]);let a=(e,t)=>t-e>1e-12*Math.max(1,Math.abs(e))?t-e:0;t.uniform3f(r.u_span,a(i.minX,i.maxX),a(i.minY,i.maxY),a(i.minZ,i.maxZ));let o=e=>[+(e===0),+(e===1),+(e===2)];y.kind===`3d`?(t.uniform1i(r.u_flat,0),t.uniform3f(r.u_eye,...y.eye),t.uniform3f(r.u_right,...y.right),t.uniform3f(r.u_up,...y.up),t.uniform3f(r.u_fwd,...y.fwd),t.uniform1f(r.u_f,y.f)):(t.uniform1i(r.u_flat,1),t.uniform3f(r.u_h,...o(y.h)),t.uniform3f(r.u_v,...o(y.v))),t.uniform3f(r.u_c,...o(x.colorAxis)),t.uniform4f(r.u_plot,b.left,b.top,b.width,b.height),t.uniform2f(r.u_resolution,h,g),t.uniform1i(r.u_palette,0)},M=e=>{for(let n of[`x`,`y`,`z`]){let r=e.a[`a_${n}`];t.bindBuffer(t.ARRAY_BUFFER,l[n]),t.enableVertexAttribArray(r),t.vertexAttribPointer(r,1,t.FLOAT,!1,0,0)}};return{maxTextureSize:s,resize(t,n,r){h=Math.max(1,t),g=Math.max(1,n),_=r,e.width=Math.max(1,Math.round(h*_)),e.height=Math.max(1,Math.round(g*_))},setBounds(e){v=e},setView(e,t){y=e,b=t},setPoints(e,n,r){if(!e||!n||!r){S=0;return}S=Math.min(e.length,n.length,r.length),C=[qG(e),qG(n),qG(r)],k(t.ARRAY_BUFFER,l.x,A(e,C[0]).subarray(0,S)),k(t.ARRAY_BUFFER,l.y,A(n,C[1]).subarray(0,S)),k(t.ARRAY_BUFFER,l.z,A(r,C[2]).subarray(0,S))},setTriangles(e){if(!e||e.length<3){w=T=0;return}w=e.length-e.length%3,k(t.ELEMENT_ARRAY_BUFFER,u,e.subarray(0,w));let n=new Uint32Array(w*2);for(let t=0;t<w;t+=3){let r=e[t],i=e[t+1],a=e[t+2],o=t*2;n[o]=r,n[o+1]=i,n[o+2]=i,n[o+3]=a,n[o+4]=a,n[o+5]=r}T=n.length,k(t.ELEMENT_ARRAY_BUFFER,d,n)},setSurface(e,n=0,r=0,i=[0,1],a=[0,1]){if(!e||n<2||r<2||n>s||r>s){E=null;return}let o=qG(e),c=A(e,o).subarray(0,n*r);t.bindTexture(t.TEXTURE_2D,m),t.pixelStorei(t.UNPACK_ALIGNMENT,4),D.w===n&&D.h===r?t.texSubImage2D(t.TEXTURE_2D,0,0,0,n,r,t.RED,t.FLOAT,c):(t.texImage2D(t.TEXTURE_2D,0,t.R32F,n,r,0,t.RED,t.FLOAT,c),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),D={w:n,h:r}),E={w:n,h:r,origin:o,ext:[i[0],i[1],a[0],a[1]]}},setStyle(e){x?.palette!==e.palette&&(t.bindTexture(t.TEXTURE_2D,p),t.texImage2D(t.TEXTURE_2D,0,t.RGBA8,256,1,0,t.RGBA,t.UNSIGNED_BYTE,e.palette),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE)),x=e},render(){t.viewport(0,0,e.width,e.height),t.clearColor(0,0,0,0),t.clearDepth(1),t.clear(t.COLOR_BUFFER_BIT|t.DEPTH_BUFFER_BIT);let n=x;if(!n)return;t.bindVertexArray(c),t.enable(t.BLEND),t.blendFunc(t.ONE,t.ONE_MINUS_SRC_ALPHA),t.enable(t.DEPTH_TEST),t.depthFunc(t.LEQUAL),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,p),t.enable(t.POLYGON_OFFSET_FILL),t.polygonOffset(1,1);let r=n.wireColor;if(E){let e=o;t.useProgram(e.prog);let[i,a,s,c]=E.ext;j(e,[i,s,E.origin]),t.uniform4f(e.u.u_ext,0,a-i,0,c-s),t.activeTexture(t.TEXTURE1),t.bindTexture(t.TEXTURE_2D,m),t.uniform1i(e.u.u_z,1),t.uniform2i(e.u.u_n,E.w,E.h);let l=(E.w-1)*(E.h-1),u=Math.max(1,Math.ceil(Math.sqrt(l/WG))),d=Math.floor((E.w-2)/u)+1,f=Math.floor((E.h-2)/u)+1;if(t.uniform1i(e.u.u_step,u),t.uniform1f(e.u.u_alpha,n.fillAlpha),n.fill&&(t.uniform1i(e.u.u_wire,0),t.uniform4f(e.u.u_solid,0,0,0,0),t.drawArrays(t.TRIANGLES,0,d*f*6)),n.wire){let n=u*Math.max(1,Math.ceil(Math.max(d,f)/GG)),i=Math.floor((E.h-1)/n)+1,a=Math.floor((E.w-1)/n)+1;t.uniform1i(e.u.u_wire,1),t.uniform1i(e.u.u_wstep,n),t.uniform4f(e.u.u_solid,...r),t.drawArrays(t.LINES,0,(i*d+a*f)*2)}t.activeTexture(t.TEXTURE0)}if(S>0){if(w>0&&(n.fill||n.wire)){let e=a;t.useProgram(e.prog),j(e,C),M(e),t.uniform1f(e.u.u_alpha,n.fillAlpha),n.fill&&(t.uniform4f(e.u.u_solid,0,0,0,0),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,u),t.drawElements(t.TRIANGLES,w,t.UNSIGNED_INT,0)),n.wire&&(t.uniform4f(e.u.u_solid,...r),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,d),t.drawElements(t.LINES,T,t.UNSIGNED_INT,0))}let e=i;t.useProgram(e.prog),j(e,C),M(e);let o=Math.max(1,2*n.pointRadius*_);t.uniform1f(e.u.u_size,o),t.uniform1f(e.u.u_rim,o>=3?Math.max(.9,n.pointRadius*.3)*_:0),t.drawArrays(t.POINTS,0,S)}t.disable(t.POLYGON_OFFSET_FILL),t.disable(t.DEPTH_TEST),t.bindVertexArray(null)},dispose(){for(let e of[l.x,l.y,l.z,u,d])t.deleteBuffer(e);t.deleteTexture(p),t.deleteTexture(m),t.deleteVertexArray(c)}}}var YG=new Map;function XG(e,t){let n=YG.get(e);if(!n){let r=typeof OffscreenCanvas>`u`?null:new OffscreenCanvas(1,1).getContext(`2d`,{willReadFrequently:!0});if(!r)return[0,0,0,t];r.fillStyle=e,r.fillRect(0,0,1,1);let i=r.getImageData(0,0,1,1).data;YG.set(e,n=[i[0]/255,i[1]/255,i[2]/255,i[3]/255])}return[n[0],n[1],n[2],n[3]*t]}function ZG(e,t){return{x:e.x-t.x,y:e.y-t.y,z:e.z-t.z}}function QG(e,t){return{x:e.y*t.z-e.z*t.y,y:e.z*t.x-e.x*t.z,z:e.x*t.y-e.y*t.x}}function $G(e,t){return e.x*t.x+e.y*t.y+e.z*t.z}function eK(e){return Math.sqrt(e.x*e.x+e.y*e.y+e.z*e.z)}function tK(e){let t=eK(e);return t>1e-12?{x:e.x/t,y:e.y/t,z:e.z/t}:{x:0,y:0,z:1}}function nK(e,t,n,r){let i=Math.cos(n),a=Math.sin(n),o=Math.cos(r),s=Math.sin(r);return{x:e.x+t*o*a,y:e.y+t*s,z:e.z+t*o*i}}function rK(e,t,n){let r=tK(ZG(t,e)),i=tK(QG(r,n));return{right:i,up:QG(i,r),fwd:r,eye:e}}function iK(e,t,n,r,i){let a=ZG(e,t.eye),o=$G(a,t.right),s=$G(a,t.up),c=$G(a,t.fwd);if(c<.01)return{sx:-9999,sy:-9999,depth:c};let l=1/Math.tan(n/2);return{sx:r/2+o/c*l*(i/2),sy:i/2-s/c*l*(i/2),depth:c}}function aK(e,t,n,r){let i=(e,t,n)=>{let r=n-t;return r<1e-12?0:(e-t)/r*2-1};return{x:i(e,r.minX,r.maxX),y:i(n,r.minZ,r.maxZ),z:i(t,r.minY,r.maxY)}}var oK=16,sK=.1,cK=Math.PI/4,lK=Math.PI/5,uK=3.2,dK=2e4,fK=(()=>{let e=new Uint8Array(256*4);for(let t=0;t<256;t++){let{r:n,g:r,b:i}=NW(t/255);e.set([n,r,i,255],t*4)}return e})();function pK(e){if(!Array.isArray(e))return e;let t=e.length,n=new Float64Array(t),r=new Float64Array(t),i=new Float64Array(t);for(let a=0;a<t;a++)n[a]=e[a].x,r[a]=e[a].y,i[a]=e[a].z;return{length:t,x:n,y:r,z:i}}var mK=(e,t)=>!t||e>=t[0]&&e<=t[1];function hK(e,t,n,r){let i=new Uint32Array(e.length),a=0;for(let o=0;o<e.length;o++){let s=e.x[o],c=e.y[o],l=e.z[o];s-s===0&&c-c===0&&l-l===0&&mK(s,t)&&mK(c,n)&&mK(l,r)&&(i[a++]=o)}if(a<3)return null;let o=new Float64Array(a*2);for(let t=0;t<a;t++)o[2*t]=e.x[i[t]],o[2*t+1]=e.y[i[t]];try{let e=new EG(o).triangles;for(let t=0;t<e.length;t++)e[t]=i[e[t]];return e.length>=3?e:null}catch{return null}}var gK=at(function({points:e,surface:t,xLabel:n,yLabel:r,zLabel:i,height:a=500,backgroundToken:o=``,xRange:s,yRange:c,zRange:l,viewMode:u,pointRadius:d=4,alarms:f,showMesh:p=!1,meshStyle:m=`filled`,meshOpacity:h=.85,onPlotContextMenu:g},_){let v=K(g);G(()=>{v.current=g},[g]);let y=K(null),b=K(null),x=K(null),S=K(cK),C=K(lK),w=K(uK),T=K(null),E=K({xLabel:n,yLabel:r,zLabel:i,height:a,viewMode:u,pointRadius:d,alarms:f??[],showMesh:p,meshStyle:m,meshOpacity:h});G(()=>{E.current={xLabel:n,yLabel:r,zLabel:i,height:a,viewMode:u,pointRadius:d,alarms:f??[],showMesh:p,meshStyle:m,meshOpacity:h}},[n,r,i,a,u,d,f,p,m,h]);let D=dt(()=>{let n=pK(e),r=1/0,i=-1/0,a=1/0,o=-1/0,u=1/0,d=-1/0,f=0,p=0,m=0,h=0;for(let e=0;e<n.length;e++){let t=n.x[e],g=n.y[e],_=n.z[e];t-t!==0||g-g!==0||_-_!==0||!mK(t,s)||!mK(g,c)||!mK(_,l)||(t<r&&(r=t),t>i&&(i=t),g<a&&(a=g),g>o&&(o=g),_<u&&(u=_),_>d&&(d=_),f+=t,p+=g,m+=_,h++)}let g=null;if(t&&t.w>=2&&t.h>=2){let e=t.values,n=!1;for(let r=0;r<t.w*t.h;r++){let t=e[r];t-t===0&&(n=!0,t<u&&(u=t),t>d&&(d=t))}n&&(g=t,r=Math.min(r,t.x[0],t.x[1]),i=Math.max(i,t.x[0],t.x[1]),a=Math.min(a,t.y[0],t.y[1]),o=Math.max(o,t.y[0],t.y[1]))}if(h===0&&!g)return null;s&&(r=s[0],i=s[1]),c&&(a=c[0],o=c[1]),l&&(u=l[0],d=l[1]);let _={minX:r,maxX:i,minY:a,maxY:o,minZ:u,maxZ:d},v=h>0?aK(f/h,p/h,m/h,_):{x:0,y:0,z:0};return{cols:h>0?n:null,surface:g,bounds:_,center:v}},[e,t,s,c,l]),O=u??`3d`,k=p&&(O===`3d`||O===`xy`),A=dt(()=>k&&D?.cols?hK(D.cols,s,c,l):null,[k,D,s,c,l]),j=K({model:D,triangles:A});G(()=>{j.current={model:D,triangles:A}},[D,A]);let M=K({r:null,failed:!1,cols:null,surface:null,tris:null,size:``});function N(e,t,n){let r=M.current;!r.r&&!r.failed&&b.current&&(r.r=uH(b.current,JG),r.failed=!r.r);let i=r.r;if(!i||!b.current)return null;let a=`${e}x${t}@${n}`;r.size!==a&&(i.resize(e,t,n),b.current.style.width=`${e}px`,b.current.style.height=`${t}px`,r.size=a);let{model:o,triangles:s}=j.current,c=o?.cols??null;r.cols!==c&&(i.setPoints(c?.x??null,c?.y,c?.z),r.cols=c);let l=o?.surface??null;return r.surface!==l&&(i.setSurface(l?.values??null,l?.w,l?.h,l?.x,l?.y),r.surface=l),r.tris!==s&&(i.setTriangles(s),r.tris=s),i}W(()=>()=>{M.current.r?.dispose(),M.current.r=null},[]);let P=K(null);function F(){let e=y.current,t=x.current;if(!e||!t)return;let n=Math.max(1,t.clientWidth),r=Math.max(1,t.clientHeight),i=Math.min(2,window.devicePixelRatio||1),a=Math.floor(n*i),o=Math.floor(r*i);(e.width!==a||e.height!==o)&&(e.width=a,e.height=o);let s=e.getContext(`2d`);if(!s)return;s.setTransform(i,0,0,i,0,0);let{bg:c,muted:l,grid:u}=I(),{xLabel:d,yLabel:f,zLabel:p}=E.current,m=Math.max(.25,E.current.pointRadius??4),h=YW({top:0,right:0,bottom:0,left:0},n,r).tiny;s.fillStyle=c,s.fillRect(0,0,n,r);let g=j.current.model,_=N(n,r,i);if(!g){if(_?.setStyle({palette:fK,colorAxis:2,pointRadius:m,fill:!1,wire:!1,fillAlpha:1,wireColor:[0,0,0,0]}),_?.setPoints(null),M.current.cols=null,_?.render(),h)return;s.fillStyle=l,s.font=`13px ${Q.sans}`,s.fillText(`Need at least one sample point`,oK,32);return}let v=g.bounds,b=E.current.viewMode??`3d`,T=b===`xz`?1:b===`yz`?0:2,D=[v.minX,v.minY,v.minZ][T],O=[v.maxX,v.maxY,v.maxZ][T],k=(e,t,n)=>{let r=T===0?e:T===1?t:n,i=O-D;return i>1e-12?(r-D)/i:.5},A,F,L,R=(e,t,r)=>{let i=n-28,a=t/32;for(let t=0;t<32;t++)s.fillStyle=PW(1-t/32),s.fillRect(i,e+t*a,14,a+1);s.strokeStyle=u,s.lineWidth=1,s.strokeRect(i,e,14,t),s.fillStyle=l,s.font=`9px ${Q.mono}`,s.textAlign=`right`,s.fillText(Mz(O),i-4,e+4),s.fillText(Mz(D),i-4,e+t),s.fillText(r,i-4,e-6)},z=e=>{s.fillStyle=l,s.font=`10px ${Q.sans}`,s.textAlign=`left`,s.globalAlpha=.7,s.fillText(e,oK,r-6),s.globalAlpha=1};if(b!==`3d`){let e,t,i,a,o,c,m,g,_;b===`xy`?(e=d,t=f,i=p,a=v.minX,o=v.maxX,c=v.minY,m=v.maxY,g=0,_=1):b===`xz`?(e=d,t=p,i=f,a=v.minX,o=v.maxX,c=v.minZ,m=v.maxZ,g=0,_=2):(e=f,t=p,i=d,a=v.minY,o=v.maxY,c=v.minZ,m=v.maxZ,g=1,_=2);let y=YW({left:72,right:48,top:24,bottom:52},n,r),x=Math.max(1,n-y.left-y.right),S=Math.max(1,r-y.top-y.bottom),C=o-a||1,w=m-c||1,T=e=>y.left+(e-a)/C*x,D=e=>y.top+S-(e-c)/w*S;A={left:y.left,top:y.top,width:x,height:S},L={kind:`2d`,h:g,v:_},F=(e,t,n)=>{let r=[e,t,n];return[T(r[g]),D(r[_])]};let O=wz(C,8),k=wz(w,8),j=Dz(a,o,O),M=Dz(c,m,k);s.strokeStyle=u,s.lineWidth=.5,s.globalAlpha=.3;for(let e of j){let t=T(e);s.beginPath(),s.moveTo(t,y.top),s.lineTo(t,y.top+S),s.stroke()}for(let e of M){let t=D(e);s.beginPath(),s.moveTo(y.left,t),s.lineTo(y.left+x,t),s.stroke()}s.globalAlpha=1,s.strokeStyle=u,s.lineWidth=1,s.strokeRect(y.left,y.top,x,S),s.save(),s.beginPath(),s.rect(y.left,y.top,x,S),s.clip();for(let e of E.current.alarms){let{axis:t,value:n,color:r,style:i,width:a}=e,o=null,c=null;b===`xy`?t===`x`?o=T(n):t===`y`&&(c=D(n)):b===`xz`?t===`x`?o=T(n):t===`z`&&(c=D(n)):t===`y`?o=T(n):t===`z`&&(c=D(n)),!(o===null&&c===null)&&(i===`dashed`?s.setLineDash([7,4]):i===`dotted`?s.setLineDash([2,4]):s.setLineDash([]),s.strokeStyle=r,s.lineWidth=a,s.globalAlpha=.9,s.beginPath(),o===null?c!==null&&(s.moveTo(y.left,c),s.lineTo(y.left+x,c)):(s.moveTo(o,y.top),s.lineTo(o,y.top+S)),s.stroke(),s.setLineDash([]),s.globalAlpha=1,s.fillStyle=r,s.font=`bold 10px ${Q.mono}`,s.globalAlpha=.95,o===null?c!==null&&(s.textAlign=`left`,s.textBaseline=`bottom`,s.fillText(Mz(n),y.left+3,c-2)):(s.textAlign=`left`,s.textBaseline=`top`,s.fillText(Mz(n),o+3,y.top+2)),s.globalAlpha=1,s.textBaseline=`alphabetic`)}if(s.restore(),!h){s.fillStyle=l,s.font=`10px ${Q.mono}`,s.textAlign=`center`,s.textBaseline=`top`;for(let e of j)s.fillText(jz(e,O),T(e),y.top+S+6);s.textAlign=`right`,s.textBaseline=`middle`;for(let e of M)s.fillText(jz(e,k),y.left-8,D(e));s.textBaseline=`alphabetic`,s.font=`bold 11px ${Q.mono}`,s.textAlign=`center`,s.fillStyle=`#fb7185`,s.fillText(e,y.left+x/2,r-8),s.save(),s.translate(14,y.top+S/2),s.rotate(-Math.PI/2),s.fillStyle=`#38bdf8`,s.textAlign=`center`,s.fillText(t,0,0),s.restore(),R(y.top+8,Math.min(S-20,180),i),z(`2D projection: ${b.toUpperCase()} plane · Color = ${i}`)}}else{let e=S.current,t=C.current,i=w.current,a=rK(nK(g.center,i,e,t),g.center,{x:0,y:1,z:0}),o=Math.PI/3,c=h?3:oK,m=Math.max(1,n-c*2),_=Math.max(1,r-c*2-(h?0:24));A={left:c,top:c,width:m,height:_};let y=e=>[e.x,e.y,e.z];L={kind:`3d`,eye:y(a.eye),right:y(a.right),up:y(a.up),fwd:y(a.fwd),f:1/Math.tan(o/2)};let b=e=>{let t=iK(e,a,o,m,_);return{sx:t.sx+c,sy:t.sy+c,depth:t.depth}};F=(e,t,n)=>{let r=b(aK(e,t,n,v));return r.depth<.02?null:[r.sx,r.sy]};let x=(e,t,n)=>{let r=b(e),i=b(t);r.depth<.02||i.depth<.02||(s.strokeStyle=n.color,s.lineWidth=n.width,s.globalAlpha=n.alpha??1,s.beginPath(),s.moveTo(r.sx,r.sy),s.lineTo(i.sx,i.sy),s.stroke(),s.globalAlpha=1)},T=wz(v.maxX-v.minX,6),D=wz(v.maxY-v.minY,6),O=wz(v.maxZ-v.minZ,6),k=Dz(v.minX,v.maxX,T),j=Dz(v.minY,v.maxY,D),M=Dz(v.minZ,v.maxZ,O),N=Oz(v.minX,v.maxX,T/5,k),P=Oz(v.minY,v.maxY,D/5,j),I=Oz(v.minZ,v.maxZ,O/5,M);for(let[e,t]of[[{x:-1,y:-1,z:-1},{x:1,y:-1,z:-1}],[{x:1,y:-1,z:-1},{x:1,y:-1,z:1}],[{x:1,y:-1,z:1},{x:-1,y:-1,z:1}],[{x:-1,y:-1,z:1},{x:-1,y:-1,z:-1}],[{x:-1,y:1,z:-1},{x:1,y:1,z:-1}],[{x:1,y:1,z:-1},{x:1,y:1,z:1}],[{x:1,y:1,z:1},{x:-1,y:1,z:1}],[{x:-1,y:1,z:1},{x:-1,y:1,z:-1}],[{x:-1,y:-1,z:-1},{x:-1,y:1,z:-1}],[{x:1,y:-1,z:-1},{x:1,y:1,z:-1}],[{x:1,y:-1,z:1},{x:1,y:1,z:1}],[{x:-1,y:-1,z:1},{x:-1,y:1,z:1}]])x(e,t,{color:u,width:1,alpha:.65});if(!h){for(let e of k){let t=aK(e,v.minY,v.minZ,v).x;x({x:t,y:-1,z:-1},{x:t,y:-1,z:1},{color:u,width:.75,alpha:.45})}for(let e of j){let t=aK(v.minX,e,v.minZ,v).z;x({x:-1,y:-1,z:t},{x:1,y:-1,z:t},{color:u,width:.75,alpha:.45})}for(let e of P){let t=aK(v.minX,e,v.minZ,v).z;x({x:-1,y:-1,z:t},{x:1,y:-1,z:t},{color:u,width:.5,alpha:.22})}for(let e of N){let t=aK(e,v.minY,v.minZ,v).x;x({x:t,y:-1,z:-1},{x:t,y:-1,z:1},{color:u,width:.5,alpha:.22})}let e=(e,t)=>{let n=sK*(t?1:.55);x({x:e,y:-1,z:-1},{x:e,y:-1+n,z:-1},{color:`#fb7185`,width:t?1.25:.75,alpha:.95})},t=(e,t)=>{let n=sK*(t?1:.55);x({x:-1,y:-1,z:e},{x:-1+n,y:-1,z:e},{color:`#38bdf8`,width:t?1.25:.75,alpha:.95})},n=(e,t)=>{let n=sK*(t?1:.55);x({x:-1,y:e,z:-1},{x:-1+n,y:e,z:-1},{color:`#4ade80`,width:t?1.25:.75,alpha:.95})};for(let t of N)e(aK(t,v.minY,v.minZ,v).x,!1);for(let t of k)e(aK(t,v.minY,v.minZ,v).x,!0);for(let e of P)t(aK(v.minX,e,v.minZ,v).z,!1);for(let e of j)t(aK(v.minX,e,v.minZ,v).z,!0);for(let e of I)n(aK(v.minX,v.minY,e,v).y,!1);for(let e of M)n(aK(v.minX,v.minY,e,v).y,!0)}let B=(e,t,n)=>{let r=n-t;return r<1e-12?0:(e-t)/r*2-1};for(let e of E.current.alarms){let{axis:t,value:n,color:r,style:i,width:a}=e,o;if(t===`z`){let e=B(n,v.minZ,v.maxZ);o=[{x:-1,y:e,z:-1},{x:1,y:e,z:-1},{x:1,y:e,z:1},{x:-1,y:e,z:1}]}else if(t===`x`){let e=B(n,v.minX,v.maxX);o=[{x:e,y:-1,z:-1},{x:e,y:1,z:-1},{x:e,y:1,z:1},{x:e,y:-1,z:1}]}else{let e=B(n,v.minY,v.maxY);o=[{x:-1,y:-1,z:e},{x:1,y:-1,z:e},{x:1,y:1,z:e},{x:-1,y:1,z:e}]}let c=o.map(e=>b(e));if(c.every(e=>e.depth>=.02)){s.beginPath(),s.moveTo(c[0].sx,c[0].sy);for(let e=1;e<c.length;e++)s.lineTo(c[e].sx,c[e].sy);s.closePath(),s.fillStyle=r,s.globalAlpha=.18,s.fill(),i===`dashed`?s.setLineDash([7,4]):i===`dotted`?s.setLineDash([2,4]):s.setLineDash([]),s.strokeStyle=r,s.lineWidth=a,s.globalAlpha=.9,s.beginPath(),s.moveTo(c[0].sx,c[0].sy);for(let e=1;e<c.length;e++)s.lineTo(c[e].sx,c[e].sy);s.closePath(),s.stroke(),s.setLineDash([]),s.globalAlpha=1;let e=c.reduce((e,t)=>t.sy>e.sy?t:e);s.fillStyle=r,s.font=`bold 10px ${Q.mono}`,s.textAlign=`center`,s.globalAlpha=.95,s.fillText(`${t.toUpperCase()}=${Mz(n)}`,e.sx,e.sy-6),s.globalAlpha=1}}if(!h){s.font=`10px ${Q.mono}`,s.textBaseline=`middle`;for(let e of k){let t=aK(e,v.minY,v.minZ,v).x,n=b({x:t,y:-1.2,z:-1.2});n.depth<.02||(s.fillStyle=l,s.textAlign=`center`,s.fillText(jz(e,T),n.sx,n.sy+12))}for(let e of j){let t=aK(v.minX,e,v.minZ,v).z,n=b({x:-1.22,y:-1,z:t});n.depth<.02||(s.textAlign=`right`,s.fillText(jz(e,D),n.sx-4,n.sy))}for(let e of M){let t=aK(v.minX,v.minY,e,v).y,n=b({x:-1.22,y:t,z:-1.2});n.depth<.02||(s.textAlign=`right`,s.fillText(jz(e,O),n.sx-4,n.sy))}s.textBaseline=`alphabetic`,s.font=`bold 11px ${Q.mono}`;let e=b({x:1.15,y:-1,z:-1.15});e.depth>=.02&&(s.fillStyle=`#fb7185`,s.textAlign=`center`,s.fillText(d,e.sx,e.sy+16)),e=b({x:-1.18,y:-1,z:1.15}),e.depth>=.02&&(s.fillStyle=`#38bdf8`,s.textAlign=`center`,s.fillText(f,e.sx-10,e.sy)),e=b({x:-1.18,y:1.15,z:-1.18}),e.depth>=.02&&(s.fillStyle=`#4ade80`,s.textAlign=`center`,s.fillText(p,e.sx-10,e.sy)),R(oK+8,Math.min(r-80,180),p),z(`Drag: rotate | Wheel: zoom | Dbl‑click: reset · ${g.surface?`Surface`:E.current.showMesh?`Mesh: ${E.current.meshStyle}`:`Scatter`} · color = Z`)}}let{showMesh:B,meshStyle:V,meshOpacity:ee}=E.current,te=!!g.surface||B;if(_)_.setBounds(v),_.setView(L,A),_.setStyle({palette:fK,colorAxis:T,pointRadius:m,fill:te&&(V===`filled`||V===`both`),wire:te&&(V===`wireframe`||V===`both`),fillAlpha:ee,wireColor:XG(u,.5)}),_.render(),P.current!==g&&(P.current=g,CH(t));else if(g.cols){let e=g.cols,t=Math.max(1,Math.ceil(e.length/dK));for(let n=0;n<e.length;n+=t){let t=e.x[n],r=e.y[n],i=e.z[n];if(!(t>=v.minX&&t<=v.maxX&&r>=v.minY&&r<=v.maxY&&i>=v.minZ&&i<=v.maxZ))continue;let a=F(t,r,i);a&&(s.fillStyle=PW(k(t,r,i)),s.beginPath(),s.arc(a[0],a[1],m,0,Math.PI*2),s.fill())}}}function I(){if(T.current)return T.current;let e=x.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return T.current=n,n}let L=K(F);G(()=>{L.current=F});let R=K(null);R.current??=DH(()=>L.current(),()=>x.current),W(()=>()=>R.current?.cancel(),[]);let z=()=>{S.current=cK,C.current=lK,w.current=uK,R.current.schedule()};return ut(_,()=>({autoscale:z}),[]),W(()=>eB(x.current,()=>{T.current=null,R.current.schedule()}),[]),W(()=>{T.current=null,R.current.schedule()},[o]),W(()=>{R.current.now()},[D,A,n,r,i,a,u,d,f,p,m,h]),W(()=>{let e=y.current,t=x.current;if(!e||!t)return;let n=()=>R.current.schedule(),r=new EH(()=>{T.current=null,n()});r.observe(t);let i=!1,a=0,o=0,s=t=>{t.button===0&&(i=!0,a=t.clientX,o=t.clientY,e.setPointerCapture(t.pointerId))},c=e=>{if(!i)return;let t=e.clientX-a,r=e.clientY-o;a=e.clientX,o=e.clientY,S.current-=t*.008,C.current+=r*.008,C.current=Math.max(-Math.PI/2+.05,Math.min(Math.PI/2-.05,C.current)),n()},l=()=>{i=!1},u=e=>{e.preventDefault();let t=e.deltaY>0?1.08:.92;w.current=Math.max(1.2,Math.min(12,w.current*t)),n()},d=()=>{S.current=cK,C.current=lK,w.current=uK,n()},f=e=>{e.preventDefault(),v.current?.({clientX:e.clientX,clientY:e.clientY})};return e.addEventListener(`pointerdown`,s),e.addEventListener(`pointermove`,c),e.addEventListener(`pointerup`,l),e.addEventListener(`pointercancel`,l),e.addEventListener(`wheel`,u,{passive:!1}),e.addEventListener(`contextmenu`,f),e.addEventListener(`dblclick`,d),()=>{r.disconnect(),e.removeEventListener(`pointerdown`,s),e.removeEventListener(`pointermove`,c),e.removeEventListener(`pointerup`,l),e.removeEventListener(`pointercancel`,l),e.removeEventListener(`wheel`,u),e.removeEventListener(`contextmenu`,f),e.removeEventListener(`dblclick`,d)}},[]),_t(`div`,{ref:x,className:`chart-canvas-wrap`,children:[q(`canvas`,{ref:y,className:`chart-canvas`,role:`img`,"aria-label":`3D scatter: ${n} vs ${r} vs ${i}`,style:{display:`block`,width:`100%`,height:`100%`,cursor:`grab`}}),q(`canvas`,{ref:b,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}})]})}),_K={top:14,right:24,bottom:40,left:64},vK=5;function yK(e){return e===`dashed`?[5,4]:e===`dotted`?[1,4]:[]}function bK(e){return Math.max(10,Math.min(200,Math.ceil(Math.sqrt(e))))}function xK(e,t,n){let r=(e-t)/n;return Math.exp(-.5*r*r)/(n*Math.sqrt(2*Math.PI))}function SK(e,t){let n=e.length;if(n===0)return null;let r=1/0,i=-1/0,a=0;for(let t=0;t<n;t++){let n=e[t];n<r&&(r=n),n>i&&(i=n),a+=n}r===i&&(--r,i+=1);let o=t>0?t:bK(n),s=(i-r)/o,c=Array(o).fill(0),l=a/n,u=0;for(let t=0;t<n;t++){let n=e[t];c[Math.min(o-1,Math.floor((n-r)/s))]++,u+=(n-l)**2}return{lo:r,hi:i,nBins:o,width:s,counts:c,mean:l,sd:Math.sqrt(u/n),total:n}}function CK({values:e,label:t,bins:n=0,color:r=`#38bdf8`,showNormal:i=!1,logY:a=!1,height:o=400,backgroundToken:s=``,onPlotContextMenu:c}){let l=nU(),u=K(null),d=K(null),f=K(null),p=K(null),m=K(0),h=K(null),g=K(c);G(()=>{g.current=c},[c]);let _=K({values:e,label:t,bins:n,color:r,showNormal:i,logY:a,height:o});G(()=>{_.current={values:e,label:t,bins:n,color:r,showNormal:i,logY:a,height:o}},[e,t,n,r,i,a,o]);function v(){if(h.current)return h.current;let e=f.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return h.current=n,n}function y(){let e=f.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||_.current.height)}}function b(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}let x=dt(()=>SK(e,n),[e,n]),S=K(x);G(()=>{S.current=x},[x]);let C=()=>S.current;function w(){let e=u.current;if(!e)return;let{w:t,h:n}=y(),r=b(e,t,n);if(!r)return;let{top:i,right:a,bottom:o,left:s}=_K,c=t-s-a,d=n-i-o,{bg:f,muted:p,grid:m}=v(),{label:h,color:g,showNormal:x,logY:S}=_.current;r.fillStyle=f,r.fillRect(0,0,t,n);let w=C();if(!w||c<=0||d<=0){r.fillStyle=p,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`No data`,s+8,i+8);return}let{lo:T,hi:E,nBins:D,width:O,counts:k,mean:A,sd:j,total:M}=w,N=Math.max(...k),P=S?Math.log10(N+1)+.1:N*1.08,F=e=>s+(e-T)/(E-T)*c;l({left:s,top:i,width:c,height:d,x:{v0:T,v1:E}});let I=e=>i+(P-(S?e>0?Math.log10(e):0:e))/(P-0)*d,L=S?1:wz(P,5),R=Dz(0,S?P:N,L);r.strokeStyle=m,r.lineWidth=1,r.setLineDash(yK(`dashed`));for(let e of R){let t=I(e);r.beginPath(),r.moveTo(s,t),r.lineTo(s+c,t),r.stroke()}r.setLineDash([]);let z=Math.max(.5,c/D*.04);for(let e=0;e<D;e++){let t=F(T+e*O)+z/2,n=F(T+(e+1)*O)-z/2,i=I(0),a=I(k[e]);r.fillStyle=g,r.globalAlpha=.75,r.fillRect(t,a,n-t,i-a),r.globalAlpha=1}if(x&&j>0){r.beginPath();for(let e=0;e<=200;e++){let t=T+e/200*(E-T),n=xK(t,A,j)*M*O,i=F(t),a=I(n);e===0?r.moveTo(i,a):r.lineTo(i,a)}r.strokeStyle=`#f97316`,r.lineWidth=1,r.stroke()}r.strokeStyle=p,r.lineWidth=1,r.fillStyle=p,r.font=`11px ${Q.mono}`,r.textAlign=`right`,r.textBaseline=`middle`;for(let e of R){let t=I(e);r.beginPath(),r.moveTo(s-vK,t),r.lineTo(s,t),r.stroke(),r.fillText(S?`10^${e.toFixed(0)}`:jz(e,L),s-4,t)}let B=wz(E-T,Tz(c)),V=Dz(T,E,B);r.fillStyle=p,r.textAlign=`center`,r.textBaseline=`top`;for(let e of V){let t=F(e);r.beginPath(),r.moveTo(t,i+d),r.lineTo(t,i+d+vK),r.stroke(),r.fillText(jz(e,B),t,i+d+vK+2)}r.strokeStyle=m,r.lineWidth=1,r.strokeRect(s,i,c,d),r.fillStyle=p,r.font=`11px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`bottom`,r.fillText(h,s+c/2,n-4),r.save(),r.translate(14,i+d/2),r.rotate(-Math.PI/2),r.textAlign=`center`,r.textBaseline=`middle`,r.fillText(S?`log₁₀(count)`:`count`,0,0),r.restore()}let T=K(w);T.current=w;let E=K(null);E.current??=DH(()=>T.current(),()=>f.current);let D=()=>E.current.schedule();function O(e){let t=d.current;if(!t)return;let{w:n,h:r}=y(),i=b(t,n,r);if(!i||(i.clearRect(0,0,n,r),e===null))return;let{top:a,right:o,bottom:s,left:c}=_K,l=n-c-o,u=r-a-s,{muted:f}=v(),p=C();if(!p)return;let{lo:m,hi:h,width:g,counts:_}=p,x=e=>c+(e-m)/(h-m)*l,S=x(m+e*g),w=x(m+(e+1)*g);i.fillStyle=`rgba(255,255,255,0.12)`,i.fillRect(S,a,w-S,u);let T=(S+w)/2,E=_[e],D=(E/p.total*100).toFixed(1),O=`${Mz(m+e*g)} – ${Mz(m+(e+1)*g)}`,k=`n = ${E} (${D}%)`;i.font=`11px ${Q.mono}`;let A=i.measureText(k).width,j=i.measureText(O).width,M=Math.max(A,j),N=Math.min(T+8,c+l-M-8);i.fillStyle=f,i.textAlign=`left`,i.textBaseline=`top`,i.fillText(O,N,a+8),i.fillText(k,N,a+22)}function k(){xH(m.current),m.current=bH(()=>O(p.current))}return W(()=>{E.current.now()}),W(()=>()=>E.current?.cancel(),[]),W(()=>{h.current=null,D()},[s]),G(()=>{let e=f.current;if(!e)return;let t=new EH(()=>{h.current=null,D(),k()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=d.current;if(!e)return;function t(t){let n=e.getBoundingClientRect(),{left:r}=_K,i=n.width-_K.left-_K.right,a=C();if(!a||i<=0){p.current=null,k();return}let o=t.clientX-n.left-r,s=Math.floor(o/i*a.nBins);p.current=s>=0&&s<a.nBins?s:null,k()}function n(){p.current=null,k()}function r(e){e.preventDefault(),g.current?.({clientX:e.clientX,clientY:e.clientY})}return e.addEventListener(`mousemove`,t),e.addEventListener(`mouseleave`,n),e.addEventListener(`contextmenu`,r),()=>{e.removeEventListener(`mousemove`,t),e.removeEventListener(`mouseleave`,n),e.removeEventListener(`contextmenu`,r)}},[]),_t(`div`,{ref:f,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:u,className:`chart-canvas`,role:`img`,"aria-label":`Histogram of ${t}`}),q(`canvas`,{ref:d,className:`chart-canvas chart-overlay`})]})}var wK=`
485
485
  uniform vec2 u_resolution;
486
486
  uniform vec4 u_plot; // left, top, width, height (CSS px)
487
487
  uniform vec4 u_view; // xmin, xmax, ymin, ymax (relative to the layer origin)
@@ -490,7 +490,7 @@ vec2 project(float x, float y) {
490
490
  u_plot.y + (u_view.w - y) / (u_view.w - u_view.z) * u_plot.w);
491
491
  }
492
492
  vec4 toClip(vec2 p) { vec2 c = p / u_resolution * 2.0 - 1.0; return vec4(c.x, -c.y, 0.0, 1.0); }
493
- `,CK=`
493
+ `,TK=`
494
494
  uniform vec4 u_clip; // left, top, right, bottom (CSS px)
495
495
  uniform float u_dpr;
496
496
  uniform float u_height; // canvas height (device px)
@@ -498,23 +498,23 @@ bool outside() {
498
498
  vec2 f = vec2(gl_FragCoord.x, u_height - gl_FragCoord.y) / u_dpr;
499
499
  return f.x < u_clip.x || f.x > u_clip.z || f.y < u_clip.y || f.y > u_clip.w;
500
500
  }
501
- `,wK=`#version 300 es
501
+ `,EK=`#version 300 es
502
502
  in vec2 a_corner; // (0|1 along x, 0 = lo | 1 = hi)
503
503
  in float a_xa; in float a_xb;
504
504
  in float a_loa; in float a_lob;
505
505
  in float a_hia; in float a_hib;
506
506
  in float a_bstart;
507
- ${SK}
507
+ ${wK}
508
508
  void main() {
509
509
  if (a_bstart > 0.5) { gl_Position = vec4(2.0, 2.0, 2.0, 1.0); return; }
510
510
  float x = a_corner.x < 0.5 ? a_xa : a_xb;
511
511
  float lo = a_corner.x < 0.5 ? a_loa : a_lob;
512
512
  float hi = a_corner.x < 0.5 ? a_hia : a_hib;
513
513
  gl_Position = toClip(project(x, a_corner.y < 0.5 ? lo : hi));
514
- }`,TK=`#version 300 es
514
+ }`,DK=`#version 300 es
515
515
  in vec2 a_corner; // (0|1, 0|1)
516
516
  in float a_x0; in float a_x1; in float a_y0; in float a_y1; in float a_k;
517
- ${SK}
517
+ ${wK}
518
518
  flat out float v_k;
519
519
  void main() {
520
520
  vec2 p0 = project(a_x0, a_y0), p1 = project(a_x1, a_y1);
@@ -524,29 +524,29 @@ void main() {
524
524
  vec2 half_ = max((hi - lo) * 0.5, vec2(0.5));
525
525
  v_k = a_k;
526
526
  gl_Position = toClip(c + (a_corner * 2.0 - 1.0) * half_);
527
- }`,EK=`#version 300 es
527
+ }`,OK=`#version 300 es
528
528
  precision highp float;
529
529
  uniform vec4 u_color;
530
- ${CK}
530
+ ${TK}
531
531
  out vec4 outColor;
532
532
  void main() {
533
533
  if (outside()) discard;
534
534
  outColor = vec4(u_color.rgb * u_color.a, u_color.a);
535
- }`,DK=`#version 300 es
535
+ }`,kK=`#version 300 es
536
536
  precision highp float;
537
537
  flat in float v_k;
538
538
  uniform sampler2D u_palette;
539
- ${CK}
539
+ ${TK}
540
540
  out vec4 outColor;
541
541
  void main() {
542
542
  if (outside()) discard;
543
543
  vec4 c = texture(u_palette, vec2((v_k + 0.5) / 256.0, 0.5));
544
544
  outColor = vec4(c.rgb * c.a, c.a);
545
- }`,OK=`#version 300 es
545
+ }`,AK=`#version 300 es
546
546
  in vec2 a_corner;
547
547
  in float a_ax; in float a_ay; in float a_bx; in float a_by;
548
548
  in float a_bstart;
549
- ${SK}
549
+ ${wK}
550
550
  uniform float u_ext;
551
551
  flat out vec2 v_a;
552
552
  flat out vec2 v_b;
@@ -562,14 +562,14 @@ void main() {
562
562
  vec2 pos = base + dir * (a_corner.x * u_ext) + n * (a_corner.y * u_ext);
563
563
  v_a = a; v_b = b; v_pos = pos;
564
564
  gl_Position = toClip(pos);
565
- }`,kK=`#version 300 es
565
+ }`,jK=`#version 300 es
566
566
  precision highp float;
567
567
  flat in vec2 v_a;
568
568
  flat in vec2 v_b;
569
569
  in vec2 v_pos;
570
570
  uniform vec4 u_color;
571
571
  uniform float u_half;
572
- ${CK}
572
+ ${TK}
573
573
  out vec4 outColor;
574
574
  void main() {
575
575
  if (outside()) discard;
@@ -581,21 +581,21 @@ void main() {
581
581
  if (cov <= 0.0) discard;
582
582
  float a = u_color.a * cov;
583
583
  outColor = vec4(u_color.rgb * a, a);
584
- }`,AK=`#version 300 es
584
+ }`,MK=`#version 300 es
585
585
  in vec2 a_corner; // (0|1, 0|1)
586
586
  uniform vec4 u_extent; // x0, x1, y0, y1 (relative to the layer origin)
587
- ${SK}
587
+ ${wK}
588
588
  out vec2 v_uv;
589
589
  void main() {
590
590
  v_uv = a_corner;
591
591
  gl_Position = toClip(project(mix(u_extent.x, u_extent.y, a_corner.x), mix(u_extent.z, u_extent.w, a_corner.y)));
592
- }`,jK=`#version 300 es
592
+ }`,NK=`#version 300 es
593
593
  precision highp float;
594
594
  in vec2 v_uv;
595
595
  uniform highp sampler2D u_values;
596
596
  uniform sampler2D u_palette;
597
597
  uniform vec2 u_range; // vmin, vmax
598
- ${CK}
598
+ ${TK}
599
599
  out vec4 outColor;
600
600
  void main() {
601
601
  if (outside()) discard;
@@ -604,17 +604,17 @@ void main() {
604
604
  float t = u_range.y > u_range.x ? clamp((v - u_range.x) / (u_range.y - u_range.x), 0.0, 1.0) : 0.5;
605
605
  vec4 c = texture(u_palette, vec2((floor(t * 255.0) + 0.5) / 256.0, 0.5));
606
606
  outColor = vec4(c.rgb * c.a, c.a);
607
- }`,MK=-3e38;function NK(e){for(let t=0;t<e.length;t++)if(e[t]-e[t]===0)return e[t];return 0}function PK(e){let t=e.getContext(`webgl2`,{antialias:!1,alpha:!0,premultipliedAlpha:!0});if(!t)return null;let n=(e,n,i,a)=>cH(t,`glPlot|${e}|${n}`,()=>r(e,n,i,a)),r=(e,n,r,i)=>{let a=WV(t,t.VERTEX_SHADER,e),o=WV(t,t.FRAGMENT_SHADER,n);if(!a||!o)return null;let s=t.createProgram();if(t.attachShader(s,a),t.attachShader(s,o),t.linkProgram(s),!t.getProgramParameter(s,t.LINK_STATUS))return console.error(`glPlot program link failed:`,t.getProgramInfoLog(s)),null;let c=[`u_resolution`,`u_plot`,`u_view`,`u_clip`,`u_dpr`,`u_height`];return{prog:s,shaders:[a,o],a:Object.fromEntries([`a_corner`,...r].map(e=>[e,t.getAttribLocation(s,e)])),u:Object.fromEntries([...c,...i].map(e=>[e,t.getUniformLocation(s,e)]))}},i=n(wK,EK,[`a_xa`,`a_xb`,`a_loa`,`a_lob`,`a_hia`,`a_hib`,`a_bstart`],[`u_color`]),a=n(TK,DK,[`a_x0`,`a_x1`,`a_y0`,`a_y1`,`a_k`],[`u_palette`]),o=n(OK,kK,[`a_ax`,`a_ay`,`a_bx`,`a_by`,`a_bstart`],[`u_color`,`u_half`,`u_ext`]),s=n(AK,jK,[],[`u_extent`,`u_values`,`u_palette`,`u_range`]);if(!i||!a||!o||!s)return null;let c=t.getParameter(t.MAX_TEXTURE_SIZE),l=t.createVertexArray(),u=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,u),t.bufferData(t.ARRAY_BUFFER,Float32Array.from([0,0,1,0,0,1,1,1]),t.STATIC_DRAW);let d=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,d),t.bufferData(t.ARRAY_BUFFER,Float32Array.from([-1,-1,1,-1,-1,1,1,1]),t.STATIC_DRAW);let f=new Map,p=1,m=1,h=1,g={xmin:0,xmax:1,ymin:0,ymax:1},_={left:0,top:0,width:1,height:1},v=new WeakMap,y=new Float32Array,b=e=>{for(let n of Object.values(e.buffers))t.deleteBuffer(n);e.palette&&t.deleteTexture(e.palette),e.values&&t.deleteTexture(e.values)},x=new Float32Array,S=(e,n)=>{t.bindTexture(t.TEXTURE_2D,e),t.texImage2D(t.TEXTURE_2D,0,t.RGBA8,256,1,0,t.RGBA,t.UNSIGNED_BYTE,n),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE)},C=(e,t)=>{let n=f.get(e);if(n&&n.kind===t)return n;n&&b(n);let r={kind:t,n:0,ox:0,oy:0,buffers:{},color:[0,0,0,1],width:1};return f.set(e,r),r},w=(e,n,r)=>{let i=e.buffers[n]??=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,i),r.byteLength<=(v.get(i)??0)?t.bufferSubData(t.ARRAY_BUFFER,0,r):(t.bufferData(t.ARRAY_BUFFER,r,t.DYNAMIC_DRAW),v.set(i,r.byteLength))},T=(e,t,n,r)=>{let i=n.length;y.length<i&&(y=new Float32Array(i));for(let e=0;e<i;e++)y[e]=n[e]-r;w(e,t,y.subarray(0,i))},E=(e,t,n)=>{let r=new Uint8Array(e);t&&r.set(t.subarray(0,e)),e&&(r[0]=255);for(let t=0;t<e;t++)n(t)||(r[t]=255,t+1<e&&(r[t+1]=255));return r},D=(e,n,r=0,i=t.FLOAT)=>{if(e<0)return;t.bindBuffer(t.ARRAY_BUFFER,n),t.enableVertexAttribArray(e);let a=i===t.FLOAT?4:1;t.vertexAttribPointer(e,1,i,i!==t.FLOAT,a,r*a),t.vertexAttribDivisor(e,1)},O=(n,r,i)=>{t.useProgram(n.prog),t.uniform2f(n.u.u_resolution,p,m),t.uniform4f(n.u.u_plot,_.left,_.top,_.width,_.height),t.uniform4f(n.u.u_view,g.xmin-r.ox,g.xmax-r.ox,g.ymin-r.oy,g.ymax-r.oy),t.uniform4f(n.u.u_clip,_.left,_.top,_.left+_.width,_.top+_.height),t.uniform1f(n.u.u_dpr,h),t.uniform1f(n.u.u_height,e.height),t.bindBuffer(t.ARRAY_BUFFER,i),t.enableVertexAttribArray(n.a.a_corner),t.vertexAttribPointer(n.a.a_corner,2,t.FLOAT,!1,0,0),t.vertexAttribDivisor(n.a.a_corner,0)},k=e=>{for(let n of Object.values(e.a))n>=0&&t.vertexAttribDivisor(n,0)};return{resize(t,n,r){p=Math.max(1,t),m=Math.max(1,n),h=r,e.width=Math.round(p*h),e.height=Math.round(m*h)},setView(e,t,n,r,i){g={xmin:e,xmax:t,ymin:n,ymax:r},_=i},setBands(e,t,n,r,i,a){let o=C(e,`bands`),s=Math.min(t.length,n.length,r.length);o.ox=NK(t),o.oy=NK(r),T(o,`x`,t,o.ox),T(o,`lo`,n,o.oy),T(o,`hi`,r,o.oy),w(o,`start`,E(s,a,e=>t[e]-t[e]===0&&n[e]-n[e]===0&&r[e]-r[e]===0)),o.n=Math.max(0,s-1),o.color=i},setRects(e,n,r,i,a,o,s){let c=C(e,`rects`),l=Math.min(n.length,r.length,i.length,a.length);c.ox=NK(n),c.oy=NK(i),T(c,`x0`,n,c.ox),T(c,`x1`,r,c.ox),T(c,`y0`,i,c.oy),T(c,`y1`,a,c.oy),s?T(c,`k`,s,0):delete c.buffers.k;let u=new Uint8Array(256*4);for(let e=0;e<256;e++){let t=o[Math.min(e,o.length-1)]??[0,0,0,1];u.set([t[0]*255,t[1]*255,t[2]*255,t[3]*255],e*4)}c.palette??=t.createTexture(),t.bindTexture(t.TEXTURE_2D,c.palette),t.texImage2D(t.TEXTURE_2D,0,t.RGBA8,256,1,0,t.RGBA,t.UNSIGNED_BYTE,u),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),c.n=l},setLine(e,t,n,r,i,a){let o=C(e,`line`),s=Math.min(t.length,n.length);o.ox=NK(t),o.oy=NK(n),T(o,`x`,t,o.ox),T(o,`y`,n,o.oy),w(o,`start`,E(s,a,e=>t[e]-t[e]===0&&n[e]-n[e]===0)),o.n=Math.max(0,s-1),o.color=r,o.width=i},maxTextureSize:c,setGrid(e,n,r,i,a,o,s,c){let l=C(e,`grid`),u=r*i,d=0;for(let e=0;e<u;e++)d+=n[e]*0;let f=n.subarray(0,u);if(d!==0){x.length<u&&(x=new Float32Array(u));for(let e=0;e<u;e++){let t=n[e];x[e]=t===t?t:MK}f=x.subarray(0,u)}let p=!l.values;l.values??=t.createTexture(),t.bindTexture(t.TEXTURE_2D,l.values),t.pixelStorei(t.UNPACK_ALIGNMENT,4),!p&&l.grid&&l.grid.w===r&&l.grid.h===i?t.texSubImage2D(t.TEXTURE_2D,0,0,0,r,i,t.RED,t.FLOAT,f):(t.texImage2D(t.TEXTURE_2D,0,t.R32F,r,i,0,t.RED,t.FLOAT,f),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE)),l.palette??=t.createTexture(),S(l.palette,o);let[m,h,g,_]=a;l.ox=m,l.oy=g,l.grid={w:r,h:i,x0:m,x1:h,y0:g,y1:_,vmin:s,vmax:c},l.n=1},setGridRange(e,t,n){let r=f.get(e);r?.grid&&(r.grid.vmin=t,r.grid.vmax=n)},remove(e){let t=f.get(e);t&&(b(t),f.delete(e))},keep(e){let t=new Set(e);for(let e of[...f.keys()])t.has(e)||this.remove(e)},render(){t.bindFramebuffer(t.FRAMEBUFFER,null),t.viewport(0,0,e.width,e.height),t.disable(t.SCISSOR_TEST),t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT),t.bindVertexArray(l),t.enable(t.BLEND),t.blendFunc(t.ONE,t.ONE_MINUS_SRC_ALPHA);for(let e of f.values()){if(e.n<=0)continue;let n=e.buffers;if(e.kind===`bands`)O(i,e,u),t.uniform4f(i.u.u_color,...e.color),D(i.a.a_xa,n.x,0),D(i.a.a_xb,n.x,1),D(i.a.a_loa,n.lo,0),D(i.a.a_lob,n.lo,1),D(i.a.a_hia,n.hi,0),D(i.a.a_hib,n.hi,1),D(i.a.a_bstart,n.start,1,t.UNSIGNED_BYTE),t.drawArraysInstanced(t.TRIANGLE_STRIP,0,4,e.n),k(i);else if(e.kind===`grid`){let n=e.grid;O(s,e,u),t.uniform4f(s.u.u_extent,0,n.x1-n.x0,0,n.y1-n.y0),t.uniform2f(s.u.u_range,n.vmin,n.vmax),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,e.values),t.uniform1i(s.u.u_values,0),t.activeTexture(t.TEXTURE1),t.bindTexture(t.TEXTURE_2D,e.palette),t.uniform1i(s.u.u_palette,1),t.drawArrays(t.TRIANGLE_STRIP,0,4),t.activeTexture(t.TEXTURE0)}else e.kind===`rects`?(O(a,e,u),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,e.palette),t.uniform1i(a.u.u_palette,0),D(a.a.a_x0,n.x0),D(a.a.a_x1,n.x1),D(a.a.a_y0,n.y0),D(a.a.a_y1,n.y1),n.k?D(a.a.a_k,n.k):(t.disableVertexAttribArray(a.a.a_k),t.vertexAttrib1f(a.a.a_k,0)),t.drawArraysInstanced(t.TRIANGLE_STRIP,0,4,e.n),k(a)):(O(o,e,d),t.uniform4f(o.u.u_color,...e.color),t.uniform1f(o.u.u_half,e.width/2),t.uniform1f(o.u.u_ext,e.width/2+1.5),D(o.a.a_ax,n.x,0),D(o.a.a_bx,n.x,1),D(o.a.a_ay,n.y,0),D(o.a.a_by,n.y,1),D(o.a.a_bstart,n.start,1,t.UNSIGNED_BYTE),t.drawArraysInstanced(t.TRIANGLE_STRIP,0,4,e.n),k(o))}t.bindVertexArray(null)},dispose(){for(let e of f.values())b(e);f.clear(),t.deleteBuffer(u),t.deleteBuffer(d),t.deleteVertexArray(l)}}}function FK(e){let t=K({plot:null,failed:!1,size:``});return W(()=>()=>{t.current.plot?.dispose(),t.current.plot=null},[]),ct((n,r)=>{let i=t.current,a=e.current;if(!i.plot&&!i.failed&&a&&(i.plot=lH(a,PK),i.failed=!i.plot),!i.plot||!a)return null;let o=Math.min(2,window.devicePixelRatio||1),s=`${n}x${r}@${o}`;return i.size!==s&&(i.plot.resize(n,r,o),a.style.width=`${n}px`,a.style.height=`${r}px`,i.size=s),i.plot},[e])}function IK(e){let t=!1;for(let n=0;n<e.length;n++)if(Math.abs(e[n])>Math.PI*2){t=!0;break}let n=new Float64Array(e.length);for(let r=0;r<e.length;r++)n[r]=t?e[r]*Math.PI/180:e[r];return n}var LK=16;function RK(e,t,n,r){let i=IK(e),a=Math.min(i.length,t.length),o=1/0,s=-1/0;for(let e=0;e<a;e++){let n=t[e];n<o&&(o=n),n>s&&(s=n)}let c=n??Math.min(0,o),l=r??s,u=l-c||1,d=new Float64Array(a),f=new Float64Array(a),p=new Float64Array(LK),m=new Int32Array(LK);for(let e=0;e<a;e++){let n=Math.max(0,(t[e]-c)/u),r=i[e];n>1.0001?d[e]=f[e]=NaN:(d[e]=Math.sin(r)*n,f[e]=Math.cos(r)*n);let a=r%(2*Math.PI);a<0&&(a+=2*Math.PI);let o=Math.min(LK-1,Math.floor(a/(2*Math.PI)*LK));p[o]+=t[e],m[o]++}return{n:a,rMin:c,rMax:l,x:d,y:f,means:Array.from({length:LK},(e,t)=>m[t]>0?p[t]/m[t]:0)}}function zK({angles:e,radii:t,angleLabel:n,radiusLabel:r,color:i=`#a78bfa`,mode:a=`waveform`,radiusMin:o,radiusMax:s,height:c=400,backgroundToken:l=``,onPlotContextMenu:u}){let d=K(null),f=K(null),p=K(null),m=K(u);G(()=>{m.current=u},[u]);let h=K({angles:e,radii:t,angleLabel:n,radiusLabel:r,color:i,mode:a,radiusMin:o,radiusMax:s,height:c});G(()=>{h.current={angles:e,radii:t,angleLabel:n,radiusLabel:r,color:i,mode:a,radiusMin:o,radiusMax:s,height:c}},[e,t,n,r,i,a,o,s,c]);let g=dt(()=>RK(e,t,o,s),[e,t,o,s]),_=K(g);G(()=>{_.current=g},[g]);let v=K(null),y=FK(v),b=K({geo:null,color:``});function x(){if(p.current)return p.current;let e=f.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return p.current=n,n}function S(){let e=f.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||h.current.height)}}function C(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function w(){let e=d.current;if(!e)return;let{w:t,h:n}=S(),r=C(e,t,n);if(!r)return;let{bg:i,muted:a,grid:o}=x(),{angleLabel:s,radiusLabel:c,color:l,mode:u}=h.current,f=_.current,{n:p,rMin:m,rMax:g}=f;r.fillStyle=i,r.fillRect(0,0,t,n);let v=y(t,n);if(p===0){v?.keep([]),v?.render(),r.fillStyle=a,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`No data`,16,16);return}let w=g-m||1,T=(Math.min(t-64,n-32-24)-4)/2,E=t/2,D=32+T,O=wz(w,4),k=Dz(m,g,O);r.strokeStyle=o,r.lineWidth=1,r.setLineDash([3,3]);for(let e of k){let t=(e-m)/w*T;t<0||(r.beginPath(),r.arc(E,D,t,0,Math.PI*2),r.stroke())}r.setLineDash([]),r.strokeStyle=o,r.lineWidth=1;for(let e=0;e<360;e+=30){let t=e*Math.PI/180;r.beginPath(),r.moveTo(E,D),r.lineTo(E+Math.cos(-t+Math.PI/2)*T,D+Math.sin(-t+Math.PI/2)*T),r.stroke()}r.fillStyle=a,r.font=`10px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`middle`;for(let e=0;e<360;e+=30){let t=e*Math.PI/180,n=E+Math.sin(t)*(T+14),i=D-Math.cos(t)*(T+14);r.fillText(`${e}°`,n,i)}r.textAlign=`left`,r.textBaseline=`middle`;for(let e of k){let t=(e-m)/w*T;t<4||r.fillText(jz(e,O),E+4,D-t)}if(r.strokeStyle=a,r.lineWidth=1,r.setLineDash([]),r.beginPath(),r.arc(E,D,T,0,Math.PI*2),r.stroke(),r.save(),r.beginPath(),r.arc(E,D,T,0,Math.PI*2),r.clip(),u===`waveform`)if(v)(b.current.geo!==f||b.current.color!==l)&&(v.setLine(`wave`,f.x,f.y,JG(l,.9),1),b.current={geo:f,color:l}),v.keep([`wave`]),v.setView(-1,1,-1,1,{left:E-T,top:D-T,width:T*2,height:T*2}),v.render();else{r.strokeStyle=l,r.lineWidth=1,r.globalAlpha=.9,r.beginPath();let e=!1;for(let t=0;t<p;t++){let n=E+f.x[t]*T,i=D-f.y[t]*T;if(n!==n){e=!1;continue}e?r.lineTo(n,i):(r.moveTo(n,i),e=!0)}r.stroke(),r.globalAlpha=1}else{v?.keep([]),v?.render();let e=f.means,t=Math.max(...e,1e-10),n=2*Math.PI/LK;r.fillStyle=l,r.globalAlpha=.75;for(let i=0;i<LK;i++){let a=e[i]/t*T,o=i*n-Math.PI/2-n/2;r.beginPath(),r.moveTo(E,D),r.arc(E,D,a,o,o+n),r.closePath(),r.fill()}r.globalAlpha=1,r.strokeStyle=l,r.lineWidth=.5,r.globalAlpha=.4;for(let i=0;i<LK;i++){let a=e[i]/t*T,o=i*n-Math.PI/2-n/2;r.beginPath(),r.moveTo(E,D),r.arc(E,D,a,o,o+n),r.closePath(),r.stroke()}r.globalAlpha=1}r.restore(),r.fillStyle=a,r.font=`11px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`bottom`,r.fillText(`${s} / ${c}`,E,n-4)}let T=K(w);T.current=w;let E=K(null);E.current??=EH(()=>T.current(),()=>f.current?.ownerDocument);let D=()=>E.current.schedule();return W(()=>{E.current.now()}),W(()=>()=>E.current?.cancel(),[]),W(()=>{p.current=null,D()},[l]),G(()=>{let e=f.current;if(!e)return;let t=new TH(()=>{p.current=null,D()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=d.current;if(!e)return;let t=e=>{e.preventDefault(),m.current?.({clientX:e.clientX,clientY:e.clientY})};return e.addEventListener(`contextmenu`,t),()=>e.removeEventListener(`contextmenu`,t)},[]),_t(`div`,{ref:f,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:d,className:`chart-canvas`,role:`img`,"aria-label":`Polar chart: ${n} vs ${r}`}),q(`canvas`,{ref:v,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}})]})}function BK(e,t,n,r,i){let a=Math.min(e.length,t.length),o=(t,n)=>{let r=0,i=a;for(;r<i;){let a=r+i>>>1;(n?e[a]<=t:e[a]<t)?r=a+1:i=a}return r},s=o(n,!1),c=o(r,!0),l=Math.max(0,s-1),u=Math.min(a,c+1);if(u-l<=2*i){let e=new Uint32Array(u-l);for(let t=0;t<e.length;t++)e[t]=l+t;return e}let d=new Uint32Array(2*i+2),f=0;s>0&&(d[f++]=s-1);let p=(r-n)/i,m=s;for(let r=0;r<i&&m<c;r++){let a=r===i-1?1/0:n+(r+1)*p,o=1/0,s=-1/0,l=-1,u=-1;for(;m<c&&e[m]<a;m++){let e=t[m];e<o&&(o=e,l=m),e>s&&(s=e,u=m)}l<0||(l===u?d[f++]=l:l<u?(d[f++]=l,d[f++]=u):(d[f++]=u,d[f++]=l))}return c<a&&(d[f++]=c),d.subarray(0,f)}function VK(e,t){let n=e.length;if(n<=2*t)return Uint32Array.from({length:n},(e,t)=>t);let r=new Uint32Array(2*t),i=0;for(let a=0;a<t;a++){let o=Math.floor(a*n/t),s=Math.floor((a+1)*n/t),c=1/0,l=-1/0,u=-1,d=-1;for(let t=o;t<s;t++){let n=e[t];n<c&&(c=n,u=t),n>l&&(l=n,d=t)}u<0||(u===d?r[i++]=u:u<d?(r[i++]=u,r[i++]=d):(r[i++]=d,r[i++]=u))}return r.subarray(0,i)}function HK(e,t){let n=new Float64Array(t.length);for(let r=0;r<t.length;r++)n[r]=e[t[r]];return n}function UK(e){for(let t=1;t<e.length;t++)if(!(e[t]>=e[t-1]))return!1;return e.length===0||e[0]===e[0]}function WK(e,t){let n=e.length;for(let r=1,i=0;r<n;r++){let a=n>>1;for(;i&a;a>>=1)i^=a;if(i^=a,r<i){let n=e[r];e[r]=e[i],e[i]=n,n=t[r],t[r]=t[i],t[i]=n}}for(let r=2;r<=n;r<<=1){let i=r>>1,a=-2*Math.PI/r,o=Math.cos(a),s=Math.sin(a);for(let a=0;a<n;a+=r){let n=1,r=0;for(let c=0;c<i;c++){let l=a+c,u=l+i,d=e[u]*n-t[u]*r,f=e[u]*r+t[u]*n;e[u]=e[l]-d,t[u]=t[l]-f,e[l]+=d,t[l]+=f;let p=n*o-r*s;r=n*s+r*o,n=p}}}}var GK=new Float64Array,KK=new Float64Array;function qK(e,t,n){let r=t>>1;GK.length<r&&(GK=new Float64Array(r),KK=new Float64Array(r));let i=GK.subarray(0,r),a=KK.subarray(0,r),o=e.length;for(let t=0;t<r;t++){let r=2*t,s=r+1;i[t]=r<o?e[r]*(n?n[r]:1):0,a[t]=s<o?e[s]*(n?n[s]:1):0}WK(i,a);let s=new Float64Array(r),c=-2*Math.PI/t,l=Math.cos(c),u=Math.sin(c),d=1,f=0;for(let e=0;e<r;e++){let t=e===0?0:r-e,n=i[e],o=a[e],c=i[t],p=-a[t],m=(n+c)/2,h=(o+p)/2,g=(o-p)/2,_=-(n-c)/2,v=m+d*g-f*_,y=h+d*_+f*g;s[e]=Math.sqrt(v*v+y*y);let b=d*l-f*u;f=d*u+f*l,d=b}return s}var JK=new Float64Array,YK=0;function XK(e){if(YK===e)return JK.subarray(0,e);JK.length<e&&(JK=new Float64Array(Math.max(e,JK.length*2)));let t=2*Math.PI/Math.max(1,e-1),n=Math.cos(t),r=Math.sin(t),i=1,a=0;for(let t=0;t<e;t++){JK[t]=.5*(1-i);let e=i*n-a*r;a=a*n+i*r,i=e}return YK=e,JK.subarray(0,e)}var ZK={top:14,right:24,bottom:40,left:64},QK=5;function $K(e){let t=1;for(;t<e;)t<<=1;return t}function eq(e,t,n,r){let i=e.length,a=Math.max(2,$K(i)),o=qK(e,a,n===`hann`?XK(i):void 0),s=a/2,c=new Float64Array(s),l=2/a;for(let e=0;e<s;e++){c[e]=e*t/a;let n=o[e]*l;o[e]=r===`db`?20*Math.log10(Math.max(n,1e-12)):n}return{freqs:c,amps:o}}function tq({signal:e,sampleRate:t=1,label:n,xMode:r=`hz`,yMode:i=`amplitude`,window:a=`hann`,color:o=`#34d399`,logX:s=!1,height:c=400,backgroundToken:l=``,onPlotContextMenu:u}){let d=eU(),f=K(null),p=K(null),m=K(null),h=K(u);G(()=>{h.current=u},[u]);let g=K({signal:e,sampleRate:t,label:n,xMode:r,yMode:i,window:a,color:o,logX:s,height:c});G(()=>{g.current={signal:e,sampleRate:t,label:n,xMode:r,yMode:i,window:a,color:o,logX:s,height:c}},[e,t,n,r,i,a,o,s,c]);let _=dt(()=>e.length>=4?eq(e,t,a,i):null,[e,t,a,i]),v=dt(()=>_&&s?_.freqs.map(e=>Math.log10(e)):null,[_,s]),y=K(_&&{..._,logFreqs:v});G(()=>{y.current=_&&{..._,logFreqs:v}},[_,v]);function b(){if(m.current)return m.current;let e=p.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return m.current=n,n}function x(){let e=p.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||g.current.height)}}function S(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function C(){let e=f.current;if(!e)return;let{w:t,h:n}=x(),r=S(e,t,n);if(!r)return;let{top:i,right:a,bottom:o,left:s}=ZK,c=t-s-a,l=n-i-o,{bg:u,muted:p,grid:m}=b(),{sampleRate:h,label:_,xMode:v,yMode:C,color:w,logX:T}=g.current,E=y.current;if(r.fillStyle=u,r.fillRect(0,0,t,n),!E||c<=0||l<=0){r.fillStyle=p,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`No data`,s+8,i+8);return}let{freqs:D,amps:O,logFreqs:k}=E,A=D.length,j=v===`hz`?`${_} (Hz)`:`${_} (order)`,M=v===`order`&&h>0?h:1,N=D[1]/M,P=D[A-1]/M,F=1/0,I=-1/0;for(let e=1;e<A;e++)O[e]<F&&(F=O[e]),O[e]>I&&(I=O[e]);if(!Number.isFinite(F)||!Number.isFinite(I)){r.fillStyle=p,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`No data`,s+8,i+8);return}let L=(I-F)*.05||.1;F-=L,I+=L;let R=T?e=>{if(e<=0||N<=0)return s;let t=Math.log10(N),n=Math.log10(P);return s+(Math.log10(e)-t)/(n-t)*c}:e=>s+(e-N)/(P-N)*c;T&&N<=0&&(N=D[1]>0?D[1]/M:.001),d({left:s,top:i,width:c,height:l,x:{v0:N,v1:P,log:T},y:{v0:F,v1:I}});let z=e=>i+(I-e)/(I-F)*l,B=wz(I-F,5),V=Dz(F,I,B);r.strokeStyle=m,r.lineWidth=1,r.setLineDash([3,3]);for(let e of V)r.beginPath(),r.moveTo(s,z(e)),r.lineTo(s+c,z(e)),r.stroke();r.setLineDash([]);let ee=T?1:wz(P-N,Tz(c)),te=T?(()=>{let e=[],t=Math.ceil(Math.log10(Math.max(N,1e-12))),n=Math.floor(Math.log10(P));for(let r=t;r<=n;r++)for(let t of[1,2,5]){let n=t*10**r;n>=N&&n<=P&&e.push(n)}return e})():Dz(N,P,ee);r.strokeStyle=m,r.lineWidth=1,r.setLineDash([3,3]);for(let e of te)r.beginPath(),r.moveTo(R(e),i),r.lineTo(R(e),i+l),r.stroke();r.setLineDash([]),r.strokeStyle=p,r.lineWidth=1,r.fillStyle=p,r.font=`11px ${Q.mono}`,r.textAlign=`right`,r.textBaseline=`middle`;for(let e of V)r.beginPath(),r.moveTo(s-QK,z(e)),r.lineTo(s,z(e)),r.stroke(),r.fillText(jz(e,B),s-4,z(e));r.textAlign=`center`,r.textBaseline=`top`;for(let e of te)r.beginPath(),r.moveTo(R(e),i+l),r.lineTo(R(e),i+l+QK),r.stroke(),r.fillText(jz(e,T?e:ee),R(e),i+l+QK+2);r.strokeStyle=m,r.lineWidth=1,r.strokeRect(s,i,c,l),r.save(),r.beginPath(),r.rect(s,i,c,l),r.clip(),r.strokeStyle=w,r.lineWidth=1,r.beginPath();let H=!1,ne=Math.min(2,window.devicePixelRatio||1),re=Math.max(1,Math.round(c*ne)),ie=A>re*4?T&&k?BK(k,O,Math.log10(N*M),Math.log10(P*M),re):BK(D,O,N*M,P*M,re):null;for(let e=+!ie;e<(ie?ie.length:A);e++){let t=ie?ie[e]:e;if(t<1)continue;let n=D[t]/M;if(n<N||n>P)continue;let i=R(n),a=z(O[t]);H?r.lineTo(i,a):(r.moveTo(i,a),H=!0)}r.stroke(),r.restore(),r.fillStyle=p,r.font=`11px ${Q.mono}`,r.save(),r.translate(14,i+l/2),r.rotate(-Math.PI/2),r.textAlign=`center`,r.textBaseline=`middle`,r.fillText(C===`db`?`dB`:`Amplitude`,0,0),r.restore(),r.textAlign=`center`,r.textBaseline=`bottom`,r.fillText(j,s+c/2,n-4)}let w=K(C);w.current=C;let T=K(null);T.current??=EH(()=>w.current(),()=>p.current?.ownerDocument);let E=()=>T.current.schedule();return W(()=>{T.current.now()}),W(()=>()=>T.current?.cancel(),[]),W(()=>{m.current=null,E()},[l]),G(()=>{let e=p.current;if(!e)return;let t=new TH(()=>{m.current=null,E()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=f.current;if(!e)return;let t=e=>{e.preventDefault(),h.current?.({clientX:e.clientX,clientY:e.clientY})};return e.addEventListener(`contextmenu`,t),()=>e.removeEventListener(`contextmenu`,t)},[]),q(`div`,{ref:p,style:{position:`relative`,width:`100%`,height:`100%`},children:q(`canvas`,{ref:f,className:`chart-canvas`,role:`img`,"aria-label":`Spectrum of ${n}`})})}function nq(e,t,n=0,r=e.length-1){for(;r>n;){let i=n+r>>>1,a=e[n],o=e[i],s=e[r];if(a>o){let e=a;a=o,o=e}o>s&&(o=s),a>o&&(o=a);let c=o,l=n,u=r;for(;l<=u;){for(;e[l]<c;)l++;for(;e[u]>c;)u--;if(l<=u){let t=e[l];e[l]=e[u],e[u]=t,l++,u--}}if(t<=u)r=u;else if(t>=l)n=l;else break}return e[t]}function rq(e,t){let n=e.length;if(n===0)return t.map(()=>0);let r=[...new Set(t.flatMap(e=>{let t=e/100*(n-1);return[Math.floor(t),Math.ceil(t)]}))].sort((e,t)=>e-t),i=new Map,a=0;for(let t of r)i.set(t,nq(e,t,a)),a=t;return t.map(e=>{let t=e/100*(n-1),r=Math.floor(t);return i.get(r)+(i.get(Math.ceil(t))-i.get(r))*(t-r)})}var iq={top:14,right:24,bottom:48,left:64},aq=5;function oq(e,t){let n=e.length;if(n===0)return null;let[r,i,a,o,s]=rq(Float64Array.from(e),[0,25,50,75,100]),c=0;for(let t=0;t<n;t++)c+=e[t];let l=c/n;if(t!==`1.5iqr`)return{q1:i,median:a,q3:o,mean:l,whiskerLo:r,whiskerHi:s,outliers:new Float64Array};let u=o-i,d=i-1.5*u,f=o+1.5*u,p=1/0,m=-1/0,h=0;for(let t=0;t<n;t++){let n=e[t];if(n<d||n>f){h++;continue}n<p&&(p=n),n>m&&(m=n)}let g=new Float64Array(h);for(let t=0,r=0;t<n;t++){let n=e[t];(n<d||n>f)&&(g[r++]=n)}return g.sort(),{q1:i,median:a,q3:o,mean:l,whiskerLo:p<=m?p:i,whiskerHi:p<=m?m:o,outliers:g}}function sq({groups:e,color:t=`#fb923c`,whiskers:n=`1.5iqr`,height:r=400,backgroundToken:i=``,onPlotContextMenu:a}){let o=eU(),s=K(null),c=K(null),l=K(null),u=K(a);G(()=>{u.current=a},[a]);let d=K({groups:e,color:t,whiskers:n,height:r});G(()=>{d.current={groups:e,color:t,whiskers:n,height:r}},[e,t,n,r]);let f=dt(()=>e.filter(e=>e.values.length>0).map(e=>({label:e.label,box:oq(e.values,n)})),[e,n]),p=K(f);G(()=>{p.current=f},[f]);function m(){if(l.current)return l.current;let e=c.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return l.current=n,n}function h(){let e=c.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||d.current.height)}}function g(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function _(){let e=s.current;if(!e)return;let{w:t,h:n}=h(),r=g(e,t,n);if(!r)return;let{top:i,right:a,bottom:c,left:l}=iq,u=t-l-a,f=n-i-c,{bg:_,muted:v,grid:y}=m(),{color:b}=d.current;r.fillStyle=_,r.fillRect(0,0,t,n);let x=p.current;if(x.length===0||u<=0||f<=0){r.fillStyle=v,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`No data`,l+8,i+8);return}let S=1/0,C=-1/0;for(let e of x){e.box.whiskerLo<S&&(S=e.box.whiskerLo),e.box.whiskerHi>C&&(C=e.box.whiskerHi);for(let t of e.box.outliers)t<S&&(S=t),t>C&&(C=t)}let w=(C-S)*.08||1;S-=w,C+=w;let T=e=>i+(C-e)/(C-S)*f;o({left:l,top:i,width:u,height:f,y:{v0:S,v1:C}});let E=wz(C-S,5),D=Dz(S,C,E);r.strokeStyle=y,r.lineWidth=1,r.setLineDash([3,3]);for(let e of D)r.beginPath(),r.moveTo(l,T(e)),r.lineTo(l+u,T(e)),r.stroke();r.setLineDash([]),r.strokeStyle=v,r.lineWidth=1,r.fillStyle=v,r.font=`11px ${Q.mono}`,r.textAlign=`right`,r.textBaseline=`middle`;for(let e of D)r.beginPath(),r.moveTo(l-aq,T(e)),r.lineTo(l,T(e)),r.stroke(),r.fillText(jz(e,E),l-4,T(e));r.strokeStyle=y,r.lineWidth=1,r.strokeRect(l,i,u,f),r.save(),r.beginPath(),r.rect(l,i,u,f),r.clip();let O=x.length,k=u/O,A=Math.min(k*.55,60);for(let e=0;e<O;e++){let{box:t}=x[e],n=l+k*e+k/2;r.strokeStyle=b,r.lineWidth=1.5,r.beginPath(),r.moveTo(n,T(t.whiskerLo)),r.lineTo(n,T(t.whiskerHi)),r.stroke();let i=A*.35;r.beginPath(),r.moveTo(n-i,T(t.whiskerLo)),r.lineTo(n+i,T(t.whiskerLo)),r.moveTo(n-i,T(t.whiskerHi)),r.lineTo(n+i,T(t.whiskerHi)),r.stroke();let a=n-A/2,o=T(t.q3),s=Math.max(1,T(t.q1)-o);r.fillStyle=b,r.globalAlpha=.25,r.fillRect(a,o,A,s),r.globalAlpha=1,r.strokeStyle=b,r.lineWidth=1.5,r.strokeRect(a,o,A,s),r.strokeStyle=b,r.lineWidth=2.5,r.beginPath(),r.moveTo(a,T(t.median)),r.lineTo(a+A,T(t.median)),r.stroke();let c=T(t.mean);r.fillStyle=b,r.beginPath(),r.moveTo(n,c-5),r.lineTo(n+5,c),r.lineTo(n,c+5),r.lineTo(n-5,c),r.closePath(),r.fill(),r.fillStyle=b,r.globalAlpha=.6;let u=NaN;for(let e of t.outliers){let t=T(e);Math.abs(t-u)<.5||(u=t,r.beginPath(),r.arc(n,t,2.5,0,Math.PI*2),r.fill())}r.globalAlpha=1}r.restore(),r.fillStyle=v,r.font=`11px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`top`;for(let e=0;e<O;e++){let t=l+k*e+k/2,n=x[e].label;r.save(),r.rect(l+k*e+2,i+f+aq+2,k-4,c-aq-4),r.clip(),r.fillText(n,t,i+f+aq+2),r.restore()}}let v=K(_);v.current=_;let y=K(null);y.current??=EH(()=>v.current(),()=>c.current?.ownerDocument);let b=()=>y.current.schedule();return W(()=>{y.current.now()}),W(()=>()=>y.current?.cancel(),[]),W(()=>{l.current=null,b()},[i]),G(()=>{let e=c.current;if(!e)return;let t=new TH(()=>{l.current=null,b()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=s.current;if(!e)return;let t=e=>{e.preventDefault(),u.current?.({clientX:e.clientX,clientY:e.clientY})};return e.addEventListener(`contextmenu`,t),()=>e.removeEventListener(`contextmenu`,t)},[]),q(`div`,{ref:c,style:{position:`relative`,width:`100%`,height:`100%`},children:q(`canvas`,{ref:s,className:`chart-canvas`,role:`img`,"aria-label":`Box plot`})})}function cq(e,t){if(e.w<=t)return{grid:e,per:1};let n=e.w/t,r=new Float32Array(t*e.h);for(let i=0;i<e.h;i++){let a=i*e.w;for(let o=0;o<t;o++){let s=Math.floor(o*n),c=Math.min(e.w,Math.floor((o+1)*n)),l=0,u=0;for(let t=s;t<c;t++){let n=e.values[a+t];n===n&&(l+=n,u++)}r[i*t+o]=u?l/u:NaN}}let i=e.xLabels;return{grid:{w:t,h:e.h,values:r,xLabels:e=>typeof i==`function`?i(Math.floor(e*n)):i[Math.floor(e*n)],yLabels:e.yLabels},per:n}}var lq=e=>e.includes(`.`)&&!e.includes(`e`)?e.replace(/\.?0+$/,``):e;function uq(e){return e>=1e3?`${lq((e/1e3).toPrecision(3))}k`:lq(e.toPrecision(3))}function dq(e,t,n,r,i,a,o){let s=t>>1,c=e.length,l=c>=t?Math.floor((c-t)/n)+1:0,u=`${t}|${n}|${r}|${i}|${a?a.join(`,`):``}`,d=-1,f=0;if(o&&o.key===u&&o.frames>0&&c>0){let r=o.sig;for(let i=0;i*n<r.length&&f===0;i++){let a=i*n;if(r[a]!==e[0])continue;let s=Math.min(r.length-a,c),u=!0;for(let t=0;t<s;t++)if(r[a+t]!==e[t]){u=!1;break}if(!u)continue;let p=s>=t?Math.floor((s-t)/n)+1:0;d=i,f=Math.max(0,Math.min(p,o.frames-i,l))}}let p=new Float32Array(l*s),m=new Float32Array(l);if(f>0){for(let e=0;e<s;e++)p.set(o.values.subarray(e*o.frames+d,e*o.frames+d+f),e*l);m.set(o.frameMax.subarray(d,d+f))}let h=new Float64Array(t);for(let e=0;e<t;e++)h[e]=r?.5*(1-Math.cos(2*Math.PI*e/(t-1))):1;let g=Math.log2(t),_=new Uint32Array(t);for(let e=0;e<t;e++){let t=0,n=e;for(let e=0;e<g;e++)t=t<<1|n&1,n>>=1;_[e]=t}let v=new Float64Array(t),y=new Float64Array(t),b=new Float64Array(s);for(let r=f;r<l;r++){let o=r*n;for(let n=0;n<t;n++){let t=_[n];v[n]=e[o+t]*h[t],y[n]=0}for(let e=2;e<=t;e<<=1){let n=e>>1,r=-2*Math.PI/e,i=Math.cos(r),a=Math.sin(r);for(let r=0;r<t;r+=e){let e=1,t=0;for(let o=0;o<n;o++){let s=r+o,c=s+n,l=v[c]*e-y[c]*t,u=v[c]*t+y[c]*e;v[c]=v[s]-l,y[c]=y[s]-u,v[s]+=l,y[s]+=u;let d=e*i-t*a;t=e*a+t*i,e=d}}}let c=0;for(let e=0;e<s;e++){let n=Math.sqrt(v[e]*v[e]+y[e]*y[e])/t;b[e]=n,n>c&&(c=n)}m[r]=c;for(let e=0;e<s;e++){let t=b[a?a[e]:e];p[e*l+r]=i?20*Math.log10(Math.max(t,1e-12)):t}}let x=1e-10;for(let e=0;e<l;e++)m[e]>x&&(x=m[e]);return{values:p,frames:l,bins:s,max:x,computed:l-f,sig:Float64Array.from(e),frameMax:m,key:u}}var fq={top:14,right:24,bottom:40,left:68},pq=[[8,0,16],[48,0,96],[104,0,144],[160,0,128],[200,32,64],[230,100,16],[250,200,32],[255,255,220]],mq=-80;function hq(e){let t=pq.length-1,n=Math.min(t-1,Math.floor(e*t)),r=e*t-n,[i,a,o]=pq[n],[s,c,l]=pq[n+1];return[i+(s-i)*r,a+(c-a)*r,o+(l-o)*r]}var gq=(()=>{let e=new Uint8Array(256*4);for(let t=0;t<256;t++){let[n,r,i]=hq(t/255);e.set([n,r,i,255],t*4)}return e})();function _q(e){let t=1;for(;t<e;)t<<=1;return t}var vq=(e,t)=>Math.log(1+e/t*9)/Math.log(10),yq=(e,t)=>t*(10**e-1)/9;function bq({signal:e,sampleRate:t=1e3,windowSize:n=512,overlap:r=.5,winFunc:i=`hann`,yMode:a=`db`,logFreq:o=!1,label:s=``,backgroundToken:c=``,onPlotContextMenu:l}){let u=eU(),d=K(null),f=K(null),p=K(null),m=K(null),h=K(null),g=K(l);G(()=>{g.current=l},[l]);let _=_q(Math.max(4,Math.min(n,4096))),v=Math.max(1,Math.round(_*(1-Math.max(0,Math.min(.95,r))))),y=dt(()=>{if(!o)return null;let e=_>>1,n=t/2;return Int32Array.from({length:e},(t,r)=>Math.min(e-1,Math.floor(yq((r+.5)/e,n)/n*e)))},[o,_,t]),b=K(null),x=dt(()=>b.current=dq(e,_,v,i===`hann`,a===`db`,y,b.current),[e,_,v,i,a,y]),S=dt(()=>({w:x.frames,h:x.bins,values:x.values,xLabels:[],yLabels:[]}),[x]),C=a===`db`?20*Math.log10(x.max):x.max,w=a===`db`?[C+mq,C]:[0,C],T=K({grid:S,range:w,sampleRate:t,winSz:_,step:v,yMode:a,logFreq:o,label:s});G(()=>{T.current={grid:S,range:w,sampleRate:t,winSz:_,step:v,yMode:a,logFreq:o,label:s}},[S,w[0],w[1],t,_,v,a,o,s]);let E=K({plot:null,failed:!1,size:``,grid:null,shown:null});W(()=>()=>{E.current.plot?.dispose(),E.current.plot=null},[]);function D(){if(h.current)return h.current;let e=m.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return h.current=n,n}function O(){let e=m.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function k(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function A(e,t){let n=E.current;if(!n.plot&&!n.failed&&f.current&&(n.plot=lH(f.current,PK),n.failed=!n.plot),!n.plot||!f.current)return null;let r=Math.min(2,window.devicePixelRatio||1),i=`${e}x${t}@${r}`;return n.size!==i&&(n.plot.resize(e,t,r),f.current.style.width=`${e}px`,f.current.style.height=`${t}px`,n.size=i),n.plot}function j(){let e=d.current;if(!e)return;let{w:t,h:n}=O(),r=k(e,t,n);if(!r)return;let i=p.current?k(p.current,t,n):null;i?.clearRect(0,0,t,n);let a=qW(fq,t,n),{top:o,right:s,bottom:c,left:l}=a,f=t-l-s,h=n-o-c,{bg:g,muted:_,grid:v}=D(),{grid:y,sampleRate:b,winSz:x,step:S,logFreq:C,label:w}=T.current;r.fillStyle=g,r.fillRect(0,0,t,n);let j=A(t,n);if(y.w===0||f<=0||h<=0){if(j?.keep([]),j?.render(),a.tiny)return;r.fillStyle=_,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`No data`,l+8,o+8);return}let M=Math.min(2,window.devicePixelRatio||1),N=j?j.maxTextureSize:Math.max(1,Math.round(f*M)),[P,F]=T.current.range;if(E.current.grid!==y||!E.current.shown||!j&&E.current.shown.w>N){let e=cq(y,N).grid;j&&j.setGrid(`cells`,e.values,e.w,Math.min(e.h,j.maxTextureSize),[0,e.w,0,e.h],gq,P,F),E.current.grid=y,E.current.shown=e,SH(m.current)}let I=E.current.shown;if(j)j.keep([`cells`]),j.setGridRange(`cells`,P,F),j.setView(0,I.w,0,I.h,{left:l,top:o,width:f,height:h}),j.render();else{let e=document.createElement(`canvas`);e.width=I.w,e.height=I.h;let t=e.getContext(`2d`),n=t.createImageData(I.w,I.h);for(let e=0;e<I.h;e++)for(let t=0;t<I.w;t++){let[r,i,a]=hq(Math.max(0,Math.min(1,(I.values[e*I.w+t]-P)/(F-P)))),o=(t+(I.h-1-e)*I.w)*4;n.data[o]=r,n.data[o+1]=i,n.data[o+2]=a,n.data[o+3]=255}t.putImageData(n,0,0),r.drawImage(e,l,o,f,h)}if(a.tiny)return;let L=i??r,R=b/2,z=e=>o+h*(1-(C?vq(e,R):e/R));L.strokeStyle=v,L.lineWidth=.5,L.globalAlpha=.4;let B=Dz(0,R,wz(R,5));L.setLineDash([3,4]);for(let e of B){let t=z(e);L.beginPath(),L.moveTo(l,t),L.lineTo(l+f,t),L.stroke()}L.setLineDash([]),L.globalAlpha=1,L.strokeStyle=v,L.strokeRect(l,o,f,h),r.fillStyle=_,r.font=`10px ${Q.mono}`,r.textAlign=`right`,r.textBaseline=`middle`,r.strokeStyle=_,r.lineWidth=1;for(let e of B){let t=z(e);r.beginPath(),r.moveTo(l-4,t),r.lineTo(l,t),r.stroke(),r.fillText(uq(e),l-6,t)}let V=(y.w*S+x)/b;u({left:l,top:o,width:f,height:h,x:{v0:0,v1:V}});let ee=wz(V,6),te=Dz(0,V,ee);r.textAlign=`center`,r.textBaseline=`top`;for(let e of te){let t=l+e/V*f;r.beginPath(),r.moveTo(t,o+h),r.lineTo(t,o+h+4),r.stroke(),r.fillText(jz(e,ee),t,o+h+6)}r.fillStyle=_,r.textAlign=`center`,r.textBaseline=`bottom`,r.fillText(w||`Time (s)`,l+f/2,n-4),r.save(),r.translate(12,o+h/2),r.rotate(-Math.PI/2),r.textAlign=`center`,r.fillText(`Frequency (Hz)`,0,0),r.restore()}let M=K(j);G(()=>{M.current=j});let N=K(null);return N.current??=EH(()=>M.current(),()=>m.current?.ownerDocument),W(()=>{N.current.now()},[S,w[0],w[1],t,_,v,a,o,s]),W(()=>()=>N.current?.cancel(),[]),W(()=>{h.current=null,N.current.schedule()},[c]),G(()=>{let e=m.current;if(!e)return;let t=new TH(()=>{h.current=null,N.current.schedule()});return t.observe(e),()=>t.disconnect()},[]),G(()=>{let e=p.current;if(!e)return;let t=e=>{e.preventDefault(),g.current?.({clientX:e.clientX,clientY:e.clientY})};return e.addEventListener(`contextmenu`,t),()=>e.removeEventListener(`contextmenu`,t)},[]),_t(`div`,{ref:m,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:d,className:`chart-canvas`,role:`img`,"aria-label":`Spectrogram`}),q(`canvas`,{ref:f,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),q(`canvas`,{ref:p,className:`chart-canvas chart-overlay`})]})}var xq=300,Sq=256,Cq=-60,wq=[];function Tq({signal:e,sampleRate:t,windowSize:n,overlap:r,winFunc:i,yMode:a,backgroundToken:o,onPlotContextMenu:s}){let c=2**Math.ceil(Math.log2(Math.max(4,Math.min(n,4096)))),l=Math.max(1,Math.round(c*(1-Math.max(0,Math.min(.95,r))))),u=a===`db`,d=dt(()=>dq(e,c,l,i===`hann`,u,null),[e,c,l,i,u]);return q(mK,{points:wq,surface:dt(()=>Eq(d,t,c,l,u),[d,t,c,l,u]),xLabel:`Time (s)`,yLabel:`Frequency (Hz)`,zLabel:u?`Level (dB)`:`Amplitude`,viewMode:`3d`,showMesh:!0,meshStyle:`filled`,meshOpacity:1,backgroundToken:o,onPlotContextMenu:s})}function Eq(e,t,n,r,i){let{frames:a,bins:o,values:s}=e;if(a<2||o<2)return;let c=Math.min(a,xq),l=Math.min(o,Sq),u=i?20*Math.log10(Math.max(e.max,1e-12))+Cq:-1/0,d=new Float32Array(c*l);for(let e=0;e<l;e++){let t=Math.floor(e*o/l),n=Math.max(t+1,Math.floor((e+1)*o/l));for(let r=0;r<c;r++){let i=Math.floor(r*a/c),o=Math.max(i+1,Math.floor((r+1)*a/c)),l=-1/0;for(let e=t;e<n;e++)for(let t=i;t<o;t++){let n=s[e*a+t];n>l&&(l=n)}d[e*c+r]=Math.max(u,l)}}let f=e=>(e*r+n/2)/t;return{w:c,h:l,values:d,x:[f(0),f(a-1)],y:[0,(o-1)*t/n]}}function Dq(e,t,n){return Array.from({length:n},(r,i)=>e+(i+1)/(n+1)*(t-e))}function Oq(e,t,n,r){let i=[],a=(n,r)=>e[r*t+n],o=(e,t)=>(r-e)/(t-e);for(let e=0;e+1<n;e++)for(let n=0;n+1<t;n++){let t=a(n,e),s=a(n+1,e),c=a(n+1,e+1),l=a(n,e+1);if(t!==t||s!==s||c!==c||l!==l)continue;let u=(t>=r?8:0)|(s>=r?4:0)|(c>=r?2:0)|l>=r;if(u===0||u===15)continue;let d=()=>[n+o(t,s),e],f=()=>[n+1,e+o(s,c)],p=()=>[n+o(l,c),e+1],m=()=>[n,e+o(t,l)],h=(e,t)=>i.push([e[0],e[1],t[0],t[1]]);switch(u){case 1:case 14:h(m(),p());break;case 2:case 13:h(p(),f());break;case 3:case 12:h(m(),f());break;case 4:case 11:h(d(),f());break;case 6:case 9:h(d(),p());break;case 7:case 8:h(m(),d());break;case 5:case 10:{let e=(t+s+c+l)/4>=r;u===5===e?(h(m(),d()),h(p(),f())):(h(d(),f()),h(m(),p()));break}}}return i}function kq(e){let t=e.length,n=new Float64Array(t+1);if(t===1)return n[0]=e[0]-.5,n[1]=e[0]+.5,n;for(let r=1;r<t;r++)n[r]=(e[r-1]+e[r])/2;return n[0]=e[0]-(n[1]-e[0]),n[t]=e[t-1]+(e[t-1]-n[t-1]),n}function Aq(e){if(e.length===0)return!1;for(let t=0;t<e.length;t++)if(!Number.isFinite(e[t])||t>0&&!(e[t]>e[t-1]))return!1;return!0}var jq={top:14,right:32,bottom:80,left:80};function Mq(e,t,n){return[e[0]+(t[0]-e[0])*n,e[1]+(t[1]-e[1])*n,e[2]+(t[2]-e[2])*n]}var Nq=[[33,102,172],[103,169,207],[209,229,240],[247,247,247],[253,219,199],[239,138,98],[178,24,43]],Pq=[[13,8,135],[84,2,163],[139,10,165],[185,50,137],[219,92,104],[244,136,73],[254,188,43],[240,249,33]],Fq=[[68,1,84],[72,40,120],[62,83,160],[49,120,178],[38,153,185],[31,184,187],[53,213,158],[117,231,101],[198,239,82],[253,231,37]];function Iq(e,t){let n=e.length-1,r=Math.min(n-1,Math.floor(t*n));return Mq(e[r],e[r+1],t*n-r)}function Lq(e,t){return Iq(t===`plasma`?Pq:t===`viridis`?Fq:Nq,e)}function Rq(e){let t=new Uint8Array(256*4);for(let n=0;n<256;n++){let[r,i,a]=Lq(n/255,e);t.set([r,i,a,255],n*4)}return t}function zq(e){return Math.abs(e)>=1e4||Math.abs(e)<.01&&e!==0?e.toExponential(1):String(parseFloat(e.toPrecision(3)))}function Bq(e,t,n){let r=new Map(t.map((e,t)=>[e,t])),i=new Map(n.map((e,t)=>[e,t])),a=new Float32Array(t.length*n.length);for(let n of e){let e=r.get(n.x),o=i.get(n.y);e!==void 0&&o!==void 0&&(a[o*t.length+e]=n.value)}return{w:t.length,h:n.length,values:a,xLabels:t,yLabels:n}}function Vq(e,t,n,r,i,a,o){let s=(e,t,n)=>Float64Array.from({length:e+1},(r,i)=>t+i/e*n),c=!!a&&a.length===e.w,l=!!o&&o.length===e.h,u=s(e.w,t,r),d=s(e.h,n,i);if(c){let n=kq(a),i=n[e.w]-n[0];u=Float64Array.from(n,e=>t+(e-n[0])/i*r)}if(l){let t=kq(Float64Array.from(o).reverse()),r=e.h,a=t[r]-t[0];d=Float64Array.from({length:r+1},(e,o)=>n+(t[r]-t[r-o])/a*i)}return{xB:u,yB:d,byValue:c||l}}function Hq(e,t){if(t<e[0]||t>=e[e.length-1])return-1;let n=0,r=e.length-1;for(;r-n>1;){let i=n+r>>1;e[i]<=t?n=i:r=i}return n}function Uq(e,t,n,r,i,a){let o=Math.max(1,i),s=Math.max(1,a),c=Int32Array.from({length:o},(e,r)=>Hq(t.xB,n+r+.5)),l=new Float32Array(o*s);for(let n=0;n<s;n++){let i=Hq(t.yB,r+n+.5),a=i*e.w;for(let t=0;t<o;t++)l[n*o+t]=i<0||c[t]<0?NaN:e.values[a+c[t]]}return{w:o,h:s,values:l,xLabels:e.xLabels,yLabels:e.yLabels}}function Wq({cells:e,xLabels:t,yLabels:n,grid:r,showValues:i=!0,colorScheme:a=`diverging`,vMin:o,vMax:s,xCentres:c,yCentres:l,contours:u=0,backgroundToken:d=``,onPlotContextMenu:f}){let p=K(null),m=K(null),h=K(null),g=K(null),_=K(null),v=K(null),y=K(null),b=K(0),x=K(f);G(()=>{x.current=f},[f]);let S=dt(()=>r??Bq(e??[],t??[],n??[]),[r,e,t,n]),C=dt(()=>{let e=o??1/0,t=s??-1/0;if(o===void 0||s===void 0){let n=1/0,r=-1/0;for(let e=0;e<S.w*S.h;e++){let t=S.values[e];t<n&&(n=t),t>r&&(r=t)}o===void 0&&(e=n),s===void 0&&(t=r)}return t>e||(e=Number.isFinite(e)?e-1:0,t=e+2),{lo:e,hi:t}},[S,o,s]),w=K({data:S,range:C,showValues:i,colorScheme:a,xCentres:c,yCentres:l,contours:u});G(()=>{w.current={data:S,range:C,showValues:i,colorScheme:a,xCentres:c,yCentres:l,contours:u}},[S,C,i,a,c,l,u]);let T=K({plot:null,failed:!1,size:``,data:null,key:``,shown:null,geo:null}),E=K({key:``,grid:null,segs:[]});W(()=>()=>{T.current.plot?.dispose(),T.current.plot=null},[]);let D=K({data:null,range:``});function O(){if(v.current)return v.current;let e=_.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return v.current=n,n}function k(){let e=_.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function A(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function j(e,t){let n=T.current;if(!n.plot&&!n.failed&&m.current&&(n.plot=lH(m.current,PK),n.failed=!n.plot),!n.plot||!m.current)return null;let r=Math.min(2,window.devicePixelRatio||1),i=`${e}x${t}@${r}`;return n.size!==i&&(n.plot.resize(e,t,r),m.current.style.width=`${e}px`,m.current.style.height=`${t}px`,n.size=i),n.plot}let M=(e,t)=>typeof e==`function`?e(t):e[t];function N(){let e=p.current;if(!e)return;let{w:t,h:n}=k(),r=A(e,t,n);if(!r)return;let i=h.current?A(h.current,t,n):null;i?.clearRect(0,0,t,n);let a=qW(jq,t,n),{top:o,right:s,bottom:c,left:l}=a,{bg:u,muted:d,grid:f}=O(),{data:m,range:{lo:g,hi:v},showValues:y,colorScheme:b}=w.current;r.fillStyle=u,r.fillRect(0,0,t,n);let x=j(t,n);if(m.w===0||m.h===0){x?.keep([]),x?.render(),r.fillStyle=d,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`No data`,l+8,o+8);return}let S=t-l-s,C=n-o-c,N=Math.min(2,window.devicePixelRatio||1),P=D.current;(P.data!==m||P.range!==`${g}|${v}`)&&(D.current={data:m,range:`${g}|${v}`},SH(_.current));let{xCentres:F,yCentres:I,contours:L}=w.current,R=x?x.maxTextureSize:Math.max(1,Math.round(S*N)),z=cq(m,R).grid,B=Vq(z,l,o,S,C,z===m?F:void 0,z===m?I:void 0),V=B.byValue,ee=`${R}|${b}|${V?`${S}x${C}`:``}`,te=T.current.shown;if(T.current.data!==m||T.current.key!==ee||!te){te=z;let e=V?Uq(te,B,l,o,Math.round(S),Math.round(C)):te;x&&x.setGrid(`cells`,e.values,e.w,Math.min(e.h,x.maxTextureSize),[0,e.w,0,e.h],Rq(b),g,v),T.current.data=m,T.current.key=ee,T.current.shown=te}T.current.geo=B;let H=V?Math.round(S):te.w,ne=V?Math.round(C):te.h,re=e=>B.xB[e+1]-B.xB[e],ie=e=>B.yB[e+1]-B.yB[e];if(x)x.keep([`cells`]),x.setGridRange(`cells`,g,v),x.setView(0,H,ne,0,{left:l,top:o,width:S,height:C}),x.render();else for(let e=0;e<te.h;e++)for(let t=0;t<te.w;t++){let n=te.values[e*te.w+t];if(Number.isNaN(n))continue;let[i,a,o]=Lq(Math.max(0,Math.min(1,(n-g)/(v-g))),b);r.fillStyle=`rgb(${i|0},${a|0},${o|0})`,r.fillRect(B.xB[t],B.yB[e],re(t)+.5,ie(e)+.5)}let U=i??r;if(y){for(let e=0;e<te.h;e++)if(!(ie(e)<=16)){U.font=`${Math.min(12,Math.max(8,ie(e)*.4))}px ${Q.mono}`,U.textAlign=`center`,U.textBaseline=`middle`;for(let t=0;t<te.w;t++){let n=te.values[e*te.w+t];if(Number.isNaN(n)||re(t)<=28)continue;let[r,i,a]=Lq(Math.max(0,Math.min(1,(n-g)/(v-g))),b);U.fillStyle=.299*r+.587*i+.114*a>128?`#000`:`#fff`,U.fillText(zq(n),(B.xB[t]+B.xB[t+1])/2,(B.yB[e]+B.yB[e+1])/2)}}}if(S/te.w>=4&&C/te.h>=4){U.strokeStyle=u,U.lineWidth=.5;for(let e=0;e<=te.w;e++)U.beginPath(),U.moveTo(B.xB[e],o),U.lineTo(B.xB[e],o+C),U.stroke();for(let e=0;e<=te.h;e++)U.beginPath(),U.moveTo(l,B.yB[e]),U.lineTo(l+S,B.yB[e]),U.stroke()}let ae=L>0?Dq(g,v,L):[];if(ae.length&&te.w>=2&&te.h>=2&&te.w*te.h<=4e6){let e=`${g}|${v}|${L}`;if(E.current.grid!==te||E.current.key!==e){let t=te;E.current={key:e,grid:t,segs:ae.map(e=>Oq(t.values,t.w,t.h,e))}}let t=(e,t)=>{let n=Math.min(t.length-3,Math.max(0,Math.floor(e))),r=(t[n]+t[n+1])/2;return r+((t[n+1]+t[n+2])/2-r)*(e-n)};U.save(),U.beginPath(),U.rect(l,o,S,C),U.clip(),U.lineCap=`round`,U.lineJoin=`round`;for(let[e,n]of[[2.6,`rgba(0,0,0,0.38)`],[1.1,`rgba(255,255,255,0.92)`]]){U.lineWidth=e,U.strokeStyle=n,U.beginPath();for(let e of E.current.segs)for(let[n,r,i,a]of e)U.moveTo(t(n,B.xB),t(r,B.yB)),U.lineTo(t(i,B.xB),t(a,B.yB));U.stroke()}U.restore()}r.fillStyle=d,r.font=`10px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`top`;let oe=-1/0;for(let e=0;e<(a.tiny?0:te.w);e++){let t=(B.xB[e]+B.xB[e+1])/2;t-oe<18||(oe=t,r.save(),r.translate(t,o+C+4),r.rotate(-Math.PI/4),r.fillText(M(te.xLabels,e),0,0),r.restore())}r.textAlign=`right`,r.textBaseline=`middle`;let se=-1/0;for(let e=0;e<(a.tiny?0:te.h);e++){let t=(B.yB[e]+B.yB[e+1])/2;t-se<12||(se=t,r.fillText(te.yLabels[e]??``,l-4,t))}if(a.tiny)return;let ce=t-s+4,le=o,ue=C;for(let e=0;e<ue;e++){let[t,n,i]=Lq(1-e/ue,b);r.fillStyle=`rgb(${t|0},${n|0},${i|0})`,r.fillRect(ce,le+e,12,1)}r.strokeStyle=f,r.lineWidth=.5,r.strokeRect(ce,le,12,ue),r.fillStyle=d,r.font=`9px ${Q.mono}`,r.textAlign=`left`,r.textBaseline=`middle`,r.fillText(zq(v),ce+12+2,le),r.fillText(zq(g),ce+12+2,le+ue),r.fillText(zq((g+v)/2),ce+12+2,le+ue/2),r.strokeStyle=`rgba(255,255,255,0.92)`,r.lineWidth=1;for(let e of ae){let t=le+ue*(1-(e-g)/(v-g));r.beginPath(),r.moveTo(ce-2,t),r.lineTo(ce+12+2,t),r.stroke()}}function P(){let e=g.current;if(!e)return;let{w:t,h:n}=k(),r=A(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=y.current,a=T.current.shown,o=T.current.geo;if(!i||!a||!o)return;let{top:s,right:c,bottom:l}=qW(jq,t,n),{xi:u,yi:d}=i;if(u>=a.w||d>=a.h)return;let f=o.xB[u],p=o.xB[u+1],m=o.yB[d],h=o.yB[d+1];r.strokeStyle=`rgba(255,255,255,0.7)`,r.lineWidth=1.5,r.strokeRect(f+.5,m+.5,Math.max(1,p-f-1),Math.max(1,h-m-1));let _=a.values[d*a.w+u];if(!Number.isNaN(_)){let e=`${M(a.xLabels,u)} × ${a.yLabels[d]}: ${zq(_)}`;r.font=`11px ${Q.mono}`;let n=r.measureText(e).width,i=Math.min(p+.1*(p-f),t-c-n-6),o=Math.max(s+4,m-.3*(h-m));r.fillStyle=`rgba(0,0,0,0.7)`,r.fillRect(i-3,o-3,n+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(e,i,o)}}let F=K(N);F.current=N;let I=K(null);I.current??=EH(()=>F.current(),()=>_.current?.ownerDocument);let L=()=>{b.current||=yH(()=>{b.current=0,P()})};return W(()=>{I.current.now()},[S,C,i,a,c,l,u]),W(()=>()=>{I.current?.cancel(),bH(b.current)},[]),W(()=>{v.current=null,I.current.schedule()},[d]),G(()=>{let e=_.current;if(!e)return;let t=new TH(()=>{v.current=null,I.current.schedule(),L()});return t.observe(e),()=>t.disconnect()},[]),G(()=>{let e=g.current;if(!e)return;let t=e=>{e.preventDefault(),x.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),{shown:r,geo:i}=T.current;if(!r||!i)return;let a=Hq(i.xB,t.clientX-n.left),o=Hq(i.yB,t.clientY-n.top);y.current=a>=0&&a<r.w&&o>=0&&o<r.h?{xi:a,yi:o}:null,L()},r=()=>{y.current=null,L()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),_t(`div`,{ref:_,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:p,className:`chart-canvas`,role:`img`,"aria-label":`Heatmap`}),q(`canvas`,{ref:m,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),q(`canvas`,{ref:h,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),q(`canvas`,{ref:g,className:`chart-canvas chart-overlay`})]})}var Gq=2e3,Kq=1024;function qq(e,t,n,r,i){let a=e.length,o=1/(a*t*Math.sqrt(2*Math.PI)),s=new Float64Array(n.length);if(a<=Gq){for(let r=0;r<n.length;r++){let i=0;for(let o=0;o<a;o++){let a=(n[r]-e[o])/t;i+=Math.exp(-.5*a*a)}s[r]=i*o}return s}let c=new Float64Array(Kq),l=(i-r)/Kq||1;for(let t=0;t<a;t++)c[Math.max(0,Math.min(Kq-1,Math.floor((e[t]-r)/l)))]++;for(let e=0;e<n.length;e++){let i=0;for(let a=0;a<Kq;a++){if(c[a]===0)continue;let o=(n[e]-(r+(a+.5)*l))/t;i+=c[a]*Math.exp(-.5*o*o)}s[e]=i*o}return s}var Jq={top:14,right:24,bottom:48,left:64},Yq=120;function Xq(e,t,n){let r=e.length;if(r<2)return 1;let i=0;for(let t=0;t<r;t++)i+=e[t];let a=i/r,o=0;for(let t=0;t<r;t++)o+=(e[t]-a)**2;let s=Math.sqrt(o/(r-1));return .9*Math.min(s,(n-t)/1.34)*r**-.2}function Zq(e,t){let n=e.filter(e=>e.values.length>=2),r=1/0,i=-1/0,a=n.map(e=>{let[t,n,a,o,s]=rq(Float64Array.from(e.values),[0,25,50,75,100]);return t<r&&(r=t),s>i&&(i=s),{q1:n,median:a,q3:o}}),o=(i-r)*.1||1;r-=o,i+=o;let s=Float64Array.from({length:Yq},(e,t)=>r+t/(Yq-1)*(i-r));return{shapes:n.map((e,n)=>{let{q1:o,median:c,q3:l}=a[n],u=qq(e.values,t>0?t:Xq(e.values,o,l),s,r,i),d=1e-10;for(let e of u)e>d&&(d=e);return{label:e.label,density:u,maxDensity:d,q1:o,median:c,q3:l}}),pts:s,yMin:r,yMax:i}}function Qq({groups:e,color:t=`#818cf8`,showBox:n=!0,bandwidth:r=0,orientation:i=`vertical`,backgroundToken:a=``,onPlotContextMenu:o}){let s=eU(),c=K(null),l=K(null),u=K(null),d=K(o);G(()=>{d.current=o},[o]);let f=K({groups:e,color:t,showBox:n,bandwidth:r,orientation:i});G(()=>{f.current={groups:e,color:t,showBox:n,bandwidth:r,orientation:i}},[e,t,n,r,i]);let p=dt(()=>Zq(e,r),[e,r]),m=K(p);G(()=>{m.current=p},[p]);function h(){if(u.current)return u.current;let e=l.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return u.current=n,n}function g(){let e=l.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function _(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function v(){let e=c.current;if(!e)return;let{w:t,h:n}=g(),r=_(e,t,n);if(!r)return;let{top:i,right:a,bottom:o,left:l}=Jq,u=t-l-a,d=n-i-o,{bg:p,muted:v,grid:y}=h(),{color:b,showBox:x,orientation:S}=f.current;r.fillStyle=p,r.fillRect(0,0,t,n);let{shapes:C,pts:w,yMin:T,yMax:E}=m.current;if(C.length===0||u<=0||d<=0){r.fillStyle=v,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`No data`,l+8,i+8);return}let D=S===`vertical`,O=D?e=>i+d*(1-(e-T)/(E-T)):e=>l+u*((e-T)/(E-T));s({left:l,top:i,width:u,height:d,...D?{y:{v0:T,v1:E}}:{x:{v0:T,v1:E}}});let k=wz(E-T,5),A=Dz(T,E,k);r.strokeStyle=y,r.lineWidth=1,r.setLineDash([3,3]);for(let e of A)D?(r.beginPath(),r.moveTo(l,O(e)),r.lineTo(l+u,O(e)),r.stroke()):(r.beginPath(),r.moveTo(O(e),i),r.lineTo(O(e),i+d),r.stroke());if(r.setLineDash([]),r.fillStyle=v,r.font=`11px ${Q.mono}`,r.strokeStyle=v,r.lineWidth=1,D){r.textAlign=`right`,r.textBaseline=`middle`;for(let e of A)r.beginPath(),r.moveTo(l-4,O(e)),r.lineTo(l,O(e)),r.stroke(),r.fillText(jz(e,k),l-6,O(e))}else{r.textAlign=`center`,r.textBaseline=`top`;for(let e of A)r.beginPath(),r.moveTo(O(e),i+d),r.lineTo(O(e),i+d+4),r.stroke(),r.fillText(jz(e,k),O(e),i+d+6)}r.strokeStyle=y,r.strokeRect(l,i,u,d),r.save(),r.beginPath(),r.rect(l,i,u,d),r.clip();let j=C.length,M=D?u/j:d/j;for(let e=0;e<j;e++){let{density:t,maxDensity:n,q1:a,median:o,q3:s}=C[e],c=D?l+M*e+M/2:i+M*e+M/2,u=M*.45;r.beginPath();for(let e=0;e<Yq;e++){let i=t[e]/n*u,a=O(w[e]);D?e===0?r.moveTo(c-i,a):r.lineTo(c-i,a):e===0?r.moveTo(a,c-i):r.lineTo(a,c-i)}for(let e=Yq-1;e>=0;e--){let i=t[e]/n*u,a=O(w[e]);D?r.lineTo(c+i,a):r.lineTo(a,c+i)}if(r.closePath(),r.fillStyle=b,r.globalAlpha=.35,r.fill(),r.strokeStyle=b,r.lineWidth=1,r.globalAlpha=.9,r.stroke(),r.globalAlpha=1,x){let e=u*.22;D?(r.fillStyle=b,r.globalAlpha=.7,r.fillRect(c-e,O(s),e*2,O(a)-O(s)),r.globalAlpha=1,r.strokeStyle=b,r.lineWidth=2,r.beginPath(),r.moveTo(c-e,O(o)),r.lineTo(c+e,O(o)),r.stroke()):(r.fillStyle=b,r.globalAlpha=.7,r.fillRect(O(a),c-e,O(s)-O(a),e*2),r.globalAlpha=1,r.strokeStyle=b,r.lineWidth=2,r.beginPath(),r.moveTo(O(o),c-e),r.lineTo(O(o),c+e),r.stroke())}}if(r.restore(),r.fillStyle=v,r.font=`11px ${Q.mono}`,D){r.textAlign=`center`,r.textBaseline=`top`;for(let e=0;e<j;e++)r.fillText(C[e].label,l+M*e+M/2,i+d+6)}else{r.textAlign=`right`,r.textBaseline=`middle`;for(let e=0;e<j;e++)r.fillText(C[e].label,l-6,i+M*e+M/2)}}let y=K(v);y.current=v;let b=K(null);b.current??=EH(()=>y.current(),()=>l.current?.ownerDocument);let x=()=>b.current.schedule();return W(()=>{b.current.now()}),W(()=>()=>b.current?.cancel(),[]),W(()=>{u.current=null,x()},[a]),G(()=>{let e=l.current;if(!e)return;let t=new TH(()=>{u.current=null,x()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=c.current;if(!e)return;let t=e=>{e.preventDefault(),d.current?.({clientX:e.clientX,clientY:e.clientY})};return e.addEventListener(`contextmenu`,t),()=>e.removeEventListener(`contextmenu`,t)},[]),q(`div`,{ref:l,style:{position:`relative`,width:`100%`,height:`100%`},children:q(`canvas`,{ref:c,className:`chart-canvas`,role:`img`,"aria-label":`Violin plot`})})}var $q={top:48,right:16,bottom:72,left:80},eJ=[8,24,64],tJ=[56,189,248];function nJ(e,t,n){return[e[0]+(t[0]-e[0])*n,e[1]+(t[1]-e[1])*n,e[2]+(t[2]-e[2])*n]}function rJ(e){return`${(e*100).toFixed(1)}%`}function iJ(e,t,n){if(e.length===0)return null;let r=Math.min(e.length,t.length),i=Array(r),a=Array(r),o=new Set,s=0;for(let n=0;n<r;n++)i[n]=String(e[n]),a[n]=String(t[n]),o.add(i[n]),o.add(a[n]),i[n]===a[n]&&s++;let c=[...o].sort(),l=c.length,u=new Map(c.map((e,t)=>[e,t])),d=Array.from({length:l},()=>Array(l).fill(0));for(let e=0;e<r;e++)d[u.get(i[e])][u.get(a[e])]++;let f=d.map(e=>e.reduce((e,t)=>e+t,0));return{classes:c,matrix:n?d.map((e,t)=>e.map(e=>f[t]>0?e/f[t]:0)):d,raw:d,accuracy:s/e.length}}function aJ({actual:e,predicted:t,normalize:n=!1,backgroundToken:r=``,onPlotContextMenu:i}){let a=K(null),o=K(null),s=K(null),c=K(null),l=K(null),u=K(0),d=K(i);G(()=>{d.current=i},[i]);let f=K({actual:e,predicted:t,normalize:n});G(()=>{f.current={actual:e,predicted:t,normalize:n}},[e,t,n]);function p(){if(c.current)return c.current;let e=s.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return c.current=n,n}function m(){let e=s.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function h(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}let g=dt(()=>iJ(e,t,n),[e,t,n]),_=K(g);G(()=>{_.current=g},[g]);let v=()=>_.current;function y(){let e=a.current;if(!e)return;let{w:t,h:n}=m(),r=h(e,t,n);if(!r)return;let{top:i,right:o,bottom:s,left:c}=$q,{bg:l,muted:u,grid:d}=p();r.fillStyle=l,r.fillRect(0,0,t,n);let g=v();if(!g){r.fillStyle=u,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`No data`,c+8,i+8);return}let{classes:_,matrix:y,accuracy:b}=g,x=_.length,S=t-c-o,C=n-i-s,w=S/x,T=C/x,E=0;for(let e of y)for(let t of e)t>E&&(E=t);for(let e=0;e<x;e++)for(let t=0;t<x;t++){let n=y[e][t],[a,o,s]=nJ(eJ,tJ,E>0?n/E:0);if(r.fillStyle=`rgb(${a|0},${o|0},${s|0})`,r.fillRect(c+t*w,i+e*T,w,T),w>24&&T>14){r.fillStyle=.299*a+.587*o+.114*s>100?`#000`:`#fff`,r.font=`${Math.min(12,Math.max(8,T*.38))}px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`middle`;let l=f.current.normalize;r.fillText(l?rJ(n):String(n|0),c+(t+.5)*w,i+(e+.5)*T)}}r.strokeStyle=l,r.lineWidth=.5;for(let e=0;e<=x;e++)r.beginPath(),r.moveTo(c+e*w,i),r.lineTo(c+e*w,i+C),r.stroke(),r.beginPath(),r.moveTo(c,i+e*T),r.lineTo(c+S,i+e*T),r.stroke();r.strokeStyle=d,r.strokeRect(c,i,S,C),r.fillStyle=u,r.font=`10px ${Q.mono}`,r.textAlign=`right`,r.textBaseline=`middle`;for(let e=0;e<x;e++)r.fillText(_[e],c-4,i+(e+.5)*T);r.textAlign=`center`,r.textBaseline=`top`;for(let e=0;e<x;e++)r.save(),r.translate(c+(e+.5)*w,i+C+4),r.rotate(-Math.PI/4),r.fillText(_[e],0,0),r.restore();r.fillStyle=u,r.font=`11px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`bottom`,r.fillText(`Predicted`,c+S/2,n-4),r.save(),r.translate(12,i+C/2),r.rotate(-Math.PI/2),r.textAlign=`center`,r.fillText(`Actual`,0,0),r.restore(),r.fillStyle=u,r.font=`11px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`middle`,r.fillText(`Accuracy: ${rJ(b)}`,c+S/2,i/2)}function b(){let e=o.current;if(!e)return;let{w:t,h:n}=m(),r=h(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=l.current;if(!i)return;let{top:a,right:s,bottom:c,left:u}=$q,d=v();if(!d)return;let{classes:p,matrix:g}=d,_=p.length,y=t-u-s,b=n-a-c,x=y/_,S=b/_;r.strokeStyle=`rgba(255,255,255,0.8)`,r.lineWidth=2,r.strokeRect(u+i.c*x+1,a+i.r*S+1,x-2,S-2);let C=g[i.r][i.c],w=f.current.normalize,T=`${p[i.r]} → ${p[i.c]}: ${w?rJ(C):C|0}`;r.font=`11px ${Q.mono}`;let E=r.measureText(T).width,D=Math.min(u+(i.c+1.1)*x,t-E-6),O=Math.max(6,a+(i.r-.3)*S);r.fillStyle=`rgba(0,0,0,0.75)`,r.fillRect(D-3,O-3,E+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(T,D,O)}let x=K(y);x.current=y;let S=K(null);S.current??=EH(()=>x.current(),()=>s.current?.ownerDocument);let C=()=>S.current.schedule(),w=()=>{bH(u.current),u.current=yH(b)};return W(()=>{S.current.now()}),W(()=>()=>S.current?.cancel(),[]),W(()=>{c.current=null,C()},[r]),G(()=>{let e=s.current;if(!e)return;let t=new TH(()=>{c.current=null,C(),w()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=o.current;if(!e)return;let t=e=>{e.preventDefault(),d.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),{top:r,right:i,bottom:a,left:o}=$q,s=v();if(!s)return;let c=s.classes.length,u=n.width-o-i,d=n.height-r-a,f=Math.floor((t.clientX-n.left-o)/(u/c)),p=Math.floor((t.clientY-n.top-r)/(d/c));l.current=p>=0&&p<c&&f>=0&&f<c?{r:p,c:f}:null,w()},r=()=>{l.current=null,w()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),_t(`div`,{ref:s,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:a,className:`chart-canvas`,role:`img`,"aria-label":`Confusion matrix`}),q(`canvas`,{ref:o,className:`chart-canvas chart-overlay`})]})}var oJ={top:24,right:24,bottom:48,left:64};function sJ(e,t){let n=0,r=0,i=Math.min(e.length,t.length);for(let a=0;a<i;a++)e[a]-e[a]!==0||t[a]-t[a]!==0||(t[a]===1?n++:r++);let a=new Float64Array(n),o=new Float64Array(r);for(let n=0,r=0,s=0;n<i;n++)e[n]-e[n]!==0||t[n]-t[n]!==0||(t[n]===1?a[r++]=e[n]:o[s++]=e[n]);a.sort(),o.sort();let s=new Uint8Array(n+r);for(let e=0,t=n-1,i=r-1;e<s.length;e++)i<0||t>=0&&a[t]>=o[i]?(s[e]=1,t--):(s[e]=0,i--);return s}function cJ(e){let t=0;for(let n of e)t+=n;let n=e.length-t;if(t===0||n===0)return null;let r=new Float64Array(e.length+2),i=new Float64Array(e.length+2),a=0,o=0,s=0;for(let c=0;c<e.length;c++)e[c]===1?a++:o++,r[c+1]=o/n,i[c+1]=a/t,s+=(r[c+1]-r[c])*(i[c+1]+i[c])/2;return r[e.length+1]=1,i[e.length+1]=1,{fpr:r,tpr:i,auc:s}}function lJ(e){let t=0;for(let n of e)t+=n;if(t===0)return null;let n=new Float64Array(e.length),r=new Float64Array(e.length),i=0,a=0,o=0;for(let s=0;s<e.length;s++)e[s]===1?i++:a++,n[s]=i/t,r[s]=i/(i+a),s>0&&(o+=(n[s]-n[s-1])*r[s]);return{recall:n,precision:r,ap:o}}function uJ(e,t,n,r){let i=n(0),a=r(0);e.moveTo(i,a);for(let o=1;o<t;o++){let s=n(o),c=r(o);o<t-1&&Math.abs(s-i)<.5&&Math.abs(c-a)<.5||(e.lineTo(s,c),i=s,a=c)}}function dJ({scores:e,labels:t,mode:n=`roc`,color:r=`#f472b6`,backgroundToken:i=``,onPlotContextMenu:a}){let o=K(null),s=K(null),c=K(null),l=K(a);G(()=>{l.current=a},[a]);let u=K({scores:e,labels:t,mode:n,color:r});G(()=>{u.current={scores:e,labels:t,mode:n,color:r}},[e,t,n,r]);let d=dt(()=>sJ(e,t),[e,t]),f=dt(()=>n===`pr`?{roc:null,pr:lJ(d)}:{roc:cJ(d),pr:null},[d,n]),p=K(f);G(()=>{p.current=f},[f]);function m(){if(c.current)return c.current;let e=s.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return c.current=n,n}function h(){let e=s.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function g(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function _(){let e=o.current;if(!e)return;let{w:t,h:n}=h(),r=g(e,t,n);if(!r)return;let{top:i,right:a,bottom:s,left:c}=oJ,l=t-c-a,d=n-i-s,{bg:f,muted:_,grid:v}=m(),{scores:y,mode:b,color:x}=u.current;if(r.fillStyle=f,r.fillRect(0,0,t,n),y.length===0){r.fillStyle=_,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`No data`,c+8,i+8);return}let S=e=>c+e*l,C=e=>i+(1-e)*d,w=Dz(0,1,wz(1,5));r.strokeStyle=v,r.lineWidth=1,r.setLineDash([3,3]);for(let e of w)r.beginPath(),r.moveTo(S(e),i),r.lineTo(S(e),i+d),r.stroke(),r.beginPath(),r.moveTo(c,C(e)),r.lineTo(c+l,C(e)),r.stroke();if(r.setLineDash([]),b===`roc`&&(r.strokeStyle=_,r.lineWidth=1,r.setLineDash([4,4]),r.beginPath(),r.moveTo(S(0),C(0)),r.lineTo(S(1),C(1)),r.stroke(),r.setLineDash([])),b===`roc`){let e=p.current.roc;if(e){let t=e.fpr.length,n=t=>S(e.fpr[t]),a=t=>C(e.tpr[t]);r.beginPath(),uJ(r,t,n,a),r.strokeStyle=x,r.lineWidth=1,r.stroke(),r.beginPath(),uJ(r,t,n,a),r.lineTo(S(1),C(0)),r.lineTo(S(0),C(0)),r.closePath(),r.fillStyle=x,r.globalAlpha=.15,r.fill(),r.globalAlpha=1,r.fillStyle=x,r.font=`bold 13px ${Q.mono}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`AUC = ${e.auc.toFixed(3)}`,c+8,i+8)}}else{let e=p.current.pr;if(e){let t=BK(e.recall,e.precision,0,1,Math.max(1,Math.round(l*Math.min(2,window.devicePixelRatio||1))));r.beginPath();for(let n=0;n<t.length;n++){let i=S(e.recall[t[n]]),a=C(e.precision[t[n]]);n===0?r.moveTo(i,a):r.lineTo(i,a)}r.strokeStyle=x,r.lineWidth=1,r.stroke(),r.fillStyle=x,r.font=`bold 13px ${Q.mono}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`AP = ${e.ap.toFixed(3)}`,c+8,i+8)}}r.fillStyle=_,r.font=`11px ${Q.mono}`,r.strokeStyle=_,r.lineWidth=1,r.textAlign=`right`,r.textBaseline=`middle`;for(let e of w)r.beginPath(),r.moveTo(c-4,C(e)),r.lineTo(c,C(e)),r.stroke(),r.fillText(e.toFixed(1),c-6,C(e));r.textAlign=`center`,r.textBaseline=`top`;for(let e of w)r.beginPath(),r.moveTo(S(e),i+d),r.lineTo(S(e),i+d+4),r.stroke(),r.fillText(e.toFixed(1),S(e),i+d+6);r.strokeStyle=v,r.strokeRect(c,i,l,d),r.fillStyle=_,r.textAlign=`center`,r.textBaseline=`bottom`,r.fillText(b===`roc`?`False Positive Rate`:`Recall`,c+l/2,n-4),r.save(),r.translate(12,i+d/2),r.rotate(-Math.PI/2),r.textAlign=`center`,r.fillText(b===`roc`?`True Positive Rate`:`Precision`,0,0),r.restore()}let v=K(_);v.current=_;let y=K(null);y.current??=EH(()=>v.current(),()=>s.current?.ownerDocument);let b=()=>y.current.schedule();return W(()=>{y.current.now()}),W(()=>()=>y.current?.cancel(),[]),W(()=>{c.current=null,b()},[i]),G(()=>{let e=s.current;if(!e)return;let t=new TH(()=>{c.current=null,b()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=o.current;if(!e)return;let t=e=>{e.preventDefault(),l.current?.({clientX:e.clientX,clientY:e.clientY})};return e.addEventListener(`contextmenu`,t),()=>e.removeEventListener(`contextmenu`,t)},[]),q(`div`,{ref:s,style:{position:`relative`,width:`100%`,height:`100%`},children:q(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`ROC / PR curve`})})}var fJ={top:20,right:64,bottom:48,left:64};function pJ({xValues:e,series:t,xLabel:n=`Epoch`,backgroundToken:r=``,onPlotContextMenu:i}){let a=eU(),o=K(null),s=K(null),c=K(null),l=K(null),u=K(null),d=K(0),f=K(i);G(()=>{f.current=i},[i]);let p=K({xValues:e,series:t,xLabel:n});G(()=>{p.current={xValues:e,series:t,xLabel:n}},[e,t,n]);function m(){if(l.current)return l.current;let e=c.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return l.current=n,n}function h(){let e=c.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function g(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}let _=dt(()=>{let n=e=>{let t=1/0,n=-1/0;for(let r of e)for(let e=0;e<r.values.length;e++){let i=r.values[e];i<t&&(t=i),i>n&&(n=i)}if(!Number.isFinite(t))return{lo:0,hi:1};let r=(n-t)*.06||.1;return{lo:t-r,hi:n+r}},r=t.filter(e=>e.axis===`left`),i=t.filter(e=>e.axis===`right`),a=1/0,o=-1/0;for(let t=0;t<e.length;t++){let n=e[t];n<a&&(a=n),n>o&&(o=n)}return{leftExt:n(r.length?r:t),rightExt:n(i.length?i:t),hasRight:i.length>0,xMin:a,xMax:o,ascending:UK(e)}},[e,t]),v=K(_);G(()=>{v.current=_},[_]);function y(){let e=o.current;if(!e)return;let{w:t,h:n}=h(),r=g(e,t,n);if(!r)return;let{top:i,right:s,bottom:c,left:l}=fJ,u=t-l-s,d=n-i-c,{bg:f,muted:_,grid:y}=m(),{xValues:b,series:x,xLabel:S}=p.current;if(r.fillStyle=f,r.fillRect(0,0,t,n),b.length===0||x.length===0){r.fillStyle=_,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`No data`,l+8,i+8);return}let{leftExt:C,rightExt:w,hasRight:T,xMin:E,xMax:D,ascending:O}=v.current,k=e=>l+(e-E)/(D-E||1)*u;a({left:l,top:i,width:u,height:d,x:{v0:E,v1:D},y:{v0:C.lo,v1:C.hi}});let A=e=>i+(1-(e-C.lo)/(C.hi-C.lo))*d,j=e=>i+(1-(e-w.lo)/(w.hi-w.lo))*d,M=wz(C.hi-C.lo,5),N=Dz(C.lo,C.hi,M);r.strokeStyle=y,r.lineWidth=1,r.setLineDash([3,3]);for(let e of N)r.beginPath(),r.moveTo(l,A(e)),r.lineTo(l+u,A(e)),r.stroke();let P=wz(D-E,6),F=Dz(E,D,P);for(let e of F)r.beginPath(),r.moveTo(k(e),i),r.lineTo(k(e),i+d),r.stroke();r.setLineDash([]);let I=Math.min(2,window.devicePixelRatio||1),L=Math.max(1,Math.round(u*I));for(let e of x){let t=e.axis===`right`&&T?j:A,n=Math.min(b.length,e.values.length),i=O&&n>4*L?BK(b,e.values,E,D,L):null;r.beginPath();let a=!1;for(let o=0;o<(i?i.length:n);o++){let n=i?i[o]:o,s=b[n],c=e.values[n];if(s-s!==0||c-c!==0){a=!1;continue}let l=k(s),u=t(c);a?r.lineTo(l,u):(r.moveTo(l,u),a=!0)}r.strokeStyle=e.color,r.lineWidth=1,r.stroke()}r.fillStyle=_,r.font=`11px ${Q.mono}`,r.strokeStyle=_,r.lineWidth=1,r.textAlign=`right`,r.textBaseline=`middle`;for(let e of N)r.beginPath(),r.moveTo(l-4,A(e)),r.lineTo(l,A(e)),r.stroke(),r.fillText(jz(e,M),l-6,A(e));if(T){let e=wz(w.hi-w.lo,5),t=Dz(w.lo,w.hi,e);r.textAlign=`left`;for(let n of t)r.beginPath(),r.moveTo(l+u,j(n)),r.lineTo(l+u+4,j(n)),r.stroke(),r.fillText(jz(n,e),l+u+6,j(n))}r.textAlign=`center`,r.textBaseline=`top`;for(let e of F)r.beginPath(),r.moveTo(k(e),i+d),r.lineTo(k(e),i+d+4),r.stroke(),r.fillText(jz(e,P),k(e),i+d+6);r.strokeStyle=y,r.strokeRect(l,i,u,d),r.fillStyle=_,r.textAlign=`center`,r.textBaseline=`bottom`,r.fillText(S,l+u/2,n-4);let R=l+8,z=i+6;r.font=`10px ${Q.mono}`,r.textBaseline=`middle`;for(let e of x)r.fillStyle=e.color,r.fillRect(R,z-4,16,3),r.fillStyle=_,r.textAlign=`left`,r.fillText(e.label,R+20,z),R+=r.measureText(e.label).width+36,R>l+u-60&&(R=l+8,z+=14)}function b(){let e=s.current;if(!e)return;let{w:t,h:n}=h(),r=g(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=u.current;if(i===null)return;let{top:a,right:o,bottom:c,left:l}=fJ,d=t-l-o,f=n-a-c,{muted:_}=m(),{xValues:y,series:b}=p.current;if(y.length===0)return;let{xMin:x,xMax:S,ascending:C}=v.current,w=e=>l+(e-x)/(S-x||1)*d,T=Math.max(l,Math.min(l+d,i));r.strokeStyle=_,r.lineWidth=1,r.setLineDash([3,3]),r.beginPath(),r.moveTo(T,a),r.lineTo(T,a+f),r.stroke(),r.setLineDash([]);let E=(T-l)/d,D=Math.round(E*(y.length-1));if(C){let e=x+E*(S-x),t=0,n=y.length;for(;t<n;){let r=t+n>>>1;y[r]<e?t=r+1:n=r}D=t>0&&(t>=y.length||e-y[t-1]<y[t]-e)?t-1:t}if(D<0||D>=y.length)return;let O=a+8;r.font=`10px ${Q.mono}`,r.textBaseline=`top`;for(let e of b)D<e.values.length&&Number.isFinite(e.values[D])&&(r.fillStyle=e.color,r.textAlign=`left`,r.fillText(`${e.label}: ${Mz(e.values[D])}`,T+6,O),O+=14);w(0)}let x=K(y);x.current=y;let S=K(null);S.current??=EH(()=>x.current(),()=>c.current?.ownerDocument);let C=()=>S.current.schedule(),w=()=>{bH(d.current),d.current=yH(b)};return W(()=>{S.current.now()}),W(()=>()=>S.current?.cancel(),[]),W(()=>{l.current=null,C()},[r]),G(()=>{let e=c.current;if(!e)return;let t=new TH(()=>{l.current=null,C(),w()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=s.current;if(!e)return;let t=e=>{e.preventDefault(),f.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect();u.current=t.clientX-n.left,w()},r=()=>{u.current=null,w()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),_t(`div`,{ref:c,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`Loss curves`}),q(`canvas`,{ref:s,className:`chart-canvas chart-overlay`})]})}var mJ={top:40,right:24,bottom:40,left:72},hJ=`#ef4444`,gJ=`#f97316`,_J=`#22d3ee`;function vJ(e,t){let n=e.length,r=e.value;if(n===0)return null;let i=0;for(let e=0;e<n;e++)i+=r[e];let a=i/n,o=0;for(let e=0;e<n;e++)o+=(r[e]-a)**2;let s=Math.sqrt(o/n),c=a+t*s,l=a-t*s,u=l,d=c,f=0;for(let e=0;e<n;e++){let t=r[e];t<u&&(u=t),t>d&&(d=t),(t>c||t<l)&&f++}let p=(d-u)*.08||.5,m=new Uint32Array(f);for(let e=0,t=0;e<n;e++)(r[e]>c||r[e]<l)&&(m[t++]=e);return{mean:a,sd:s,ucl:c,lcl:l,yMin:u-p,yMax:d+p,ooc:m}}function yJ({points:e,sigmaLevel:t=3,color:n=`#22d3ee`,backgroundToken:r=``,onPlotContextMenu:i}){let a=eU(),o=K(null),s=K(null),c=K(null),l=K(null),u=K(null),d=K(0),f=K(i);G(()=>{f.current=i},[i]);let p=K({points:e,sigmaLevel:t,color:n});G(()=>{p.current={points:e,sigmaLevel:t,color:n}},[e,t,n]);function m(){if(l.current)return l.current;let e=c.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return l.current=n,n}function h(){let e=c.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function g(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}let _=dt(()=>vJ(e,t),[e,t]),v=K(_);G(()=>{v.current=_},[_]);let y=()=>v.current;function b(){let e=o.current;if(!e)return;let{w:t,h:n}=h(),r=g(e,t,n);if(!r)return;let{top:i,right:s,bottom:c,left:l}=mJ,u=t-l-s,d=n-i-c,{bg:f,muted:_,grid:v}=m(),{points:b,color:x}=p.current;if(r.fillStyle=f,r.fillRect(0,0,t,n),b.length===0){r.fillStyle=_,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`No data`,l+8,i+8);return}let S=y(),{mean:C,ucl:w,lcl:T,yMin:E,yMax:D}=S,O=e=>l+e/(b.length-1||1)*u;a({left:l,top:i,width:u,height:d,x:{v0:0,v1:b.length-1||1}});let k=e=>i+(1-(e-E)/(D-E))*d,A=wz(D-E,5),j=Dz(E,D,A);r.strokeStyle=v,r.lineWidth=1,r.setLineDash([3,3]);for(let e of j)r.beginPath(),r.moveTo(l,k(e)),r.lineTo(l+u,k(e)),r.stroke();r.setLineDash([]);let M=(e,t,n,a=[])=>{let o=k(e);o<i||o>i+d||(r.strokeStyle=t,r.lineWidth=1.2,r.setLineDash(a),r.beginPath(),r.moveTo(l,o),r.lineTo(l+u,o),r.stroke(),r.setLineDash([]),r.fillStyle=t,r.font=`9px ${Q.mono}`,r.textAlign=`right`,r.textBaseline=`middle`,r.fillText(`${n} ${Mz(e)}`,l+u-2,o-5))};M(w,gJ,`UCL`,[5,3]),M(C,_J,`CL`,[]),M(T,gJ,`LCL`,[5,3]);let N=Math.min(2,window.devicePixelRatio||1),P=Math.max(1,Math.round(u*N)),F=b.length,I=b.value,L=VK(I,P);r.beginPath();for(let e=0;e<L.length;e++){let t=L[e],n=O(t),i=k(I[t]);e===0?r.moveTo(n,i):r.lineTo(n,i)}r.strokeStyle=x,r.lineWidth=1,r.stroke();let R=(e,t)=>{r.beginPath(),r.arc(O(e),k(I[e]),t?4:3,0,Math.PI*2),r.fillStyle=t?hJ:x,r.fill()};if(F<=u/4)for(let e=0;e<F;e++)R(e,I[e]>w||I[e]<T);else{let e=NaN,t=NaN;for(let n of S.ooc){let r=Math.round(O(n)),i=Math.round(k(I[n]));r===e&&i===t||(e=r,t=i,R(n,!0))}}r.fillStyle=_,r.font=`11px ${Q.mono}`,r.strokeStyle=_,r.lineWidth=1,r.textAlign=`right`,r.textBaseline=`middle`;for(let e of j)r.beginPath(),r.moveTo(l-4,k(e)),r.lineTo(l,k(e)),r.stroke(),r.fillText(jz(e,A),l-6,k(e));r.strokeStyle=v,r.strokeRect(l,i,u,d)}function x(){let e=s.current;if(!e)return;let{w:t,h:n}=h(),r=g(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=u.current;if(i===null)return;let{top:a,right:o,bottom:c,left:l}=mJ,d=t-l-o,f=n-a-c,{muted:_}=m(),{points:v}=p.current;if(v.length===0)return;let{ucl:b,lcl:x,yMin:S,yMax:C}=y(),w=e=>l+e/(v.length-1||1)*d,T=e=>a+(1-(e-S)/(C-S))*f,E=Math.round((i-l)/d*(v.length-1));if(E<0||E>=v.length)return;let D=v.value[E],O=w(E),k=T(D);r.strokeStyle=_,r.lineWidth=1,r.setLineDash([3,3]),r.beginPath(),r.moveTo(O,a),r.lineTo(O,a+f),r.stroke(),r.setLineDash([]);let A=v.subgroup?.(E),j=`${A?`${A}: `:`#${E+1}: `}${Mz(D)}`;r.font=`11px ${Q.mono}`;let M=r.measureText(j).width,N=O+8+M>l+d?O-M-10:O+8;r.fillStyle=`rgba(0,0,0,0.75)`,r.fillRect(N-3,k-12,M+6,18),r.fillStyle=D>b||D<x?hJ:_,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(j,N,k-11)}let S=K(b);S.current=b;let C=K(null);C.current??=EH(()=>S.current(),()=>c.current?.ownerDocument);let w=()=>C.current.schedule(),T=()=>{bH(d.current),d.current=yH(x)};return W(()=>{C.current.now()}),W(()=>()=>C.current?.cancel(),[]),W(()=>{l.current=null,w()},[r]),G(()=>{let e=c.current;if(!e)return;let t=new TH(()=>{l.current=null,w(),T()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=s.current;if(!e)return;let t=e=>{e.preventDefault(),f.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect();u.current=t.clientX-n.left,T()},r=()=>{u.current=null,T()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),_t(`div`,{ref:c,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`Control chart`}),q(`canvas`,{ref:s,className:`chart-canvas chart-overlay`})]})}var bJ={top:32,right:24,bottom:24,left:24},xJ=[`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`,`#facc15`,`#60a5fa`],SJ=16;function CJ(e){return`rgb(${Math.round(255*Math.min(1,Math.max(0,3.5*e-.5)))},${Math.round(255*Math.min(1,Math.max(0,e<.5?2*e:2-2*e)))},${Math.round(255*Math.min(1,Math.max(0,1.5-3.5*e)))})`}function wJ(e,t,n,r){let i=Math.min(t,e.columns.length),a=e.columns.slice(0,i).map(t=>{let n=1/0,r=-1/0;for(let i=0;i<e.length;i++){let e=t[i];e<n&&(n=e),e>r&&(r=e)}if(!Number.isFinite(n))return{lo:0,hi:1};let i=(r-n)*.05||.5;return{lo:n-i,hi:r+i}}),o={lo:0,hi:1},s=new Int32Array(e.length),c=[r];if(n&&e.colorValue){let t=e.colorValue,n=1/0,r=-1/0;for(let i=0;i<e.length;i++)t[i]<n&&(n=t[i]),t[i]>r&&(r=t[i]);Number.isFinite(n)&&(o={lo:n,hi:r}),c=Array.from({length:SJ},(e,t)=>CJ((t+.5)/SJ));for(let n=0;n<e.length;n++){let e=(t[n]-o.lo)/(o.hi-o.lo||1);s[n]=t[n]===t[n]?Math.max(0,Math.min(SJ-1,Math.floor(e*SJ))):-1}for(let t=0;t<e.length;t++)s[t]<0&&(s[t]=0)}else if(!n&&e.colorIndex){c=xJ;for(let t=0;t<e.length;t++)s[t]=Math.max(0,e.colorIndex[t])%xJ.length}let l=new Int32Array(c.length);for(let t=0;t<e.length;t++)l[s[t]]++;let u=c.map((e,t)=>({color:e,x:new Float64Array(l[t]*i),y:new Float64Array(l[t]*i),starts:new Uint8Array(l[t]*i)})),d=new Int32Array(c.length);for(let t=0;t<e.length;t++){let n=u[s[t]],r=d[s[t]]++*i;n.starts[r]=1;for(let o=0;o<i;o++,r++){let i=a[o];n.x[r]=o,n.y[r]=(e.columns[o][t]-i.lo)/(i.hi-i.lo)}}return{k:i,extents:a,colorExt:o,groups:u.filter(e=>e.x.length>0)}}function TJ({rows:e,axes:t,color:n=`#64748b`,colorByNumeric:r=!1,backgroundToken:i=``,onPlotContextMenu:a}){let o=K(null),s=K(null),c=K(null),l=K(null),u=K(null),d=K(null),f=K(null),p=K(0),m=K(a);G(()=>{m.current=a},[a]);let h=dt(()=>wJ(e,t.length,r,n),[e,t.length,r,n]),g=K({rows:e,axes:t,colorByNumeric:r,model:h});G(()=>{g.current={rows:e,axes:t,colorByNumeric:r,model:h}},[e,t,r,h]);let _=FK(s),v=K(null);function y(){if(d.current)return d.current;let e=u.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return d.current=n,n}function b(){let e=u.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function x(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function S(){let e=o.current;if(!e)return;let{w:t,h:n}=b(),r=x(e,t,n);if(!r)return;let i=c.current?x(c.current,t,n):null;i?.clearRect(0,0,t,n);let a=i??r,{top:s,right:l,bottom:d,left:f}=bJ,{bg:p,muted:m}=y(),{rows:h,axes:S,colorByNumeric:C,model:w}=g.current;r.fillStyle=p,r.fillRect(0,0,t,n);let T=_(t,n);if(S.length<2||h.length===0||w.k<2){T?.keep([]),T?.render(),r.fillStyle=m,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`Select ≥ 2 axes`,f+8,s+8);return}let E=t-f-l,D=n-s-d,O=w.k,k=Array.from({length:O},(e,t)=>f+t/(O-1)*E),A=(e,t)=>{let n=w.extents[t];return s+(1-(e-n.lo)/(n.hi-n.lo))*D},j=Math.max(.05,Math.min(.7,60/h.length));if(T)v.current!==w&&(w.groups.forEach((e,t)=>T.setLine(`c${t}`,e.x,e.y,JG(e.color,j),1,e.starts)),v.current=w,SH(u.current)),T.keep(w.groups.map((e,t)=>`c${t}`)),T.setView(0,O-1,0,1,{left:f,top:s,width:E,height:D}),T.render();else{r.globalAlpha=j;for(let e of w.groups){r.beginPath();let t=!1;for(let n=0;n<e.x.length;n++){let i=e.y[n];if(e.starts[n]&&(t=!1),i!==i){t=!1;continue}let a=f+e.x[n]/(O-1)*E,o=s+(1-i)*D;t?r.lineTo(a,o):(r.moveTo(a,o),t=!0)}r.strokeStyle=e.color,r.lineWidth=1,r.stroke()}r.globalAlpha=1}a.strokeStyle=m,a.lineWidth=1.5;for(let e=0;e<O;e++)a.beginPath(),a.moveTo(k[e],s),a.lineTo(k[e],s+D),a.stroke();a.fillStyle=m,a.font=`9px ${Q.mono}`;for(let e=0;e<O;e++){let t=w.extents[e];for(let n of[0,.25,.5,.75,1]){let r=t.lo+n*(t.hi-t.lo),i=A(r,e);a.beginPath(),a.moveTo(k[e]-3,i),a.lineTo(k[e]+3,i),a.stroke(),a.textAlign=e===O-1?`left`:`right`,a.textBaseline=`middle`,a.fillText(jz(r,(t.hi-t.lo)/4),k[e]+(e===O-1?5:-5),i)}a.font=`10px ${Q.mono}`,a.textAlign=`center`,a.textBaseline=`bottom`,a.fillText(S[e],k[e],s-4)}let M=h.colorLabels??[];if(!C&&M.length>0&&M.length<=10){let e=f,t=s+D+8;a.font=`9px ${Q.mono}`,a.textBaseline=`top`,M.forEach((n,r)=>{a.fillStyle=xJ[r%xJ.length],a.fillRect(e,t,10,8),a.fillStyle=m,a.textAlign=`left`,a.fillText(n,e+13,t),e+=a.measureText(n).width+26,e>f+E-40&&(e=f,t+=12)})}}function C(){let e=l.current;if(!e)return;let{w:t,h:n}=b(),r=x(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=f.current;if(i===null)return;let{top:a,right:o,bottom:s,left:c}=bJ,{axes:u}=g.current;if(u.length<2)return;let d=t-c-o,p=c+i/(u.length-1)*d;r.strokeStyle=`rgba(255,255,255,0.6)`,r.lineWidth=2,r.beginPath(),r.moveTo(p,a-4),r.lineTo(p,a+(n-a-s)+4),r.stroke()}let w=K(S);w.current=S;let T=K(null);T.current??=EH(()=>w.current(),()=>u.current?.ownerDocument);let E=()=>T.current.schedule(),D=()=>{bH(p.current),p.current=yH(C)};return W(()=>{T.current.now()}),W(()=>()=>T.current?.cancel(),[]),W(()=>{d.current=null,E()},[i]),G(()=>{let e=u.current;if(!e)return;let t=new TH(()=>{d.current=null,E(),D()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=l.current;if(!e)return;let t=e=>{e.preventDefault(),m.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),{axes:r}=g.current;if(r.length<2)return;let i=n.width-bJ.left-bJ.right,a=r.length,o=t.clientX-n.left-bJ.left,s=Math.round(o/i*(a-1));f.current=Math.abs(o-s/(a-1)*i)<20&&s>=0&&s<a?s:null,D()},r=()=>{f.current=null,D()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),_t(`div`,{ref:u,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`Parallel coordinates`}),q(`canvas`,{ref:s,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),q(`canvas`,{ref:c,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),q(`canvas`,{ref:l,className:`chart-canvas chart-overlay`})]})}function EJ(e,t,n,r,i,a){let o=Math.max(1,Math.ceil(t/r)),s=Math.max(1,Math.ceil(n/r)),c=e=>{let s=i(e),c=a(e);return s>=0&&s<t&&c>=0&&c<n?Math.floor(c/r)*o+Math.floor(s/r):-1},l=new Uint32Array(o*s+1);for(let t=0;t<e;t++){let e=c(t);e>=0&&l[e+1]++}for(let e=0;e<o*s;e++)l[e+1]+=l[e];let u=l.slice(0,o*s),d=new Uint32Array(l[o*s]);for(let t=0;t<e;t++){let e=c(t);e>=0&&(d[u[e]++]=t)}return{cell:r,nx:o,ny:s,start:l,ix:d}}function DJ(e,t,n,r,i,a,o){let s=Math.floor(t/e.cell),c=Math.floor(n/e.cell),l=-1,u=r*r;for(let r=c-1;r<=c+1;r++)if(!(r<0||r>=e.ny))for(let c=s-1;c<=s+1;c++){if(c<0||c>=e.nx)continue;let s=r*e.nx+c;for(let r=e.start[s];r<e.start[s+1];r++){let s=e.ix[r],c=(i(s)-t)**2+(a(s)-n)**2;c<u&&(!o||c<o(s)**2)&&(u=c,l=s)}}return l<0?null:l}var OJ={top:16,right:16,bottom:16,left:16},kJ=[`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`,`#facc15`,`#60a5fa`];function AJ(e){return[Math.round(255*Math.min(1,Math.max(0,3.5*e-.5))),Math.round(255*Math.min(1,Math.max(0,e<.5?2*e:2-2*e))),Math.round(255*Math.min(1,Math.max(0,1.5-3.5*e)))]}function jJ(e){let[t,n,r]=AJ(e);return`rgb(${t},${n},${r})`}var MJ=(()=>{let e=new Uint8Array(1024);for(let t=0;t<256;t++)e.set([...AJ(t/255),255],t*4);return e})(),NJ=(()=>{let e=new Uint8Array(1024);for(let t=0;t<256;t++){let[n,r,i]=JG(kJ[t%kJ.length],1);e.set([n*255,r*255,i*255,255],t*4)}return e});function PJ(e,t){let n=1/0,r=-1/0,i=1/0,a=-1/0;for(let t=0;t<e.length;t++){let o=e.x[t],s=e.y[t];o<n&&(n=o),o>r&&(r=o),s<i&&(i=s),s>a&&(a=s)}let o=!Number.isFinite(n)||!Number.isFinite(i)?{xLo:-1,xHi:1,yLo:-1,yHi:1}:(()=>{let e=(r-n)*.05||.5,t=(a-i)*.05||.5;return{xLo:n-e,xHi:r+e,yLo:i-t,yHi:a+t}})(),s={lo:0,hi:1},c=null,l=`single`;if(t&&e.colorValue){let t=e.colorValue,n=1/0,r=-1/0;for(let i=0;i<e.length;i++){let e=t[i];e<n&&(n=e),e>r&&(r=e)}Number.isFinite(n)&&(s={lo:n,hi:r}),c=new Float32Array(e.length);let i=s.hi-s.lo;for(let n=0;n<e.length;n++)c[n]=t[n]===t[n]?Math.max(0,Math.min(1,i>0?(t[n]-s.lo)/i:.5)):0;l=`colormap`}else !t&&e.colorIndex&&(c=Float32Array.from(e.colorIndex,e=>e>=0?e%256:0),l=`dataset`);return{ext:o,colorExt:s,key:c,mode:l}}function FJ({points:e,color:t=`#64748b`,colorByNumeric:n=!1,pointSize:r=4,backgroundToken:i=``,onPlotContextMenu:a}){let o=K(null),s=K(null),c=K(null),l=K(null),u=K(null),d=K(null),f=K(0),p=K(a);G(()=>{p.current=a},[a]);let m=dt(()=>PJ(e,n),[e,n]),h=K({points:e,color:t,colorByNumeric:n,pointSize:r,model:m});G(()=>{h.current={points:e,color:t,colorByNumeric:n,pointSize:r,model:m}},[e,t,n,r,m]);let g=K({r:null,failed:!1,size:``,model:null,style:``});W(()=>()=>{g.current.r?.dispose(),g.current.r=null},[]);function _(){if(u.current)return u.current;let e=l.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return u.current=n,n}function v(){let e=l.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function y(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function b(e,t){let{top:n,right:r,bottom:i,left:a}=OJ,o=e-a-r,s=t-n-i,c=h.current.model.ext;return{xToPx:e=>a+(e-c.xLo)/(c.xHi-c.xLo)*o,yToPx:e=>n+(1-(e-c.yLo)/(c.yHi-c.yLo))*s,plotW:o,plotH:s,ext:c}}function x(e,t){let n=g.current;!n.r&&!n.failed&&s.current&&(n.r=lH(s.current,GW),n.failed=!n.r);let r=n.r;if(!r||!s.current)return null;let i=Math.min(2,window.devicePixelRatio||1),a=`${e}x${t}@${i}`;n.size!==a&&(r.resize(e,t,i),s.current.style.width=`${e}px`,s.current.style.height=`${t}px`,n.size=a);let{points:o,model:c,color:u,pointSize:d}=h.current;n.model!==c&&(r.setData(o.x,o.y,c.key??void 0),n.model=c,SH(l.current));let f=`${c.mode}|${u}|${d}`;return n.style!==f&&(r.setStyle(c.mode===`single`?{kind:`single`,rgba:JG(u,1)}:{kind:c.mode,palette:c.mode===`colormap`?MJ:NJ()},d,.8),r.setDraw(!0,!1,0),n.style=f),r}function S(){let e=o.current;if(!e)return;let{w:t,h:n}=v(),r=y(e,t,n);if(!r)return;let{bg:i,muted:a}=_(),{points:s,color:c,colorByNumeric:l,pointSize:u,model:d}=h.current;r.fillStyle=i,r.fillRect(0,0,t,n);let f=x(t,n);if(s.length===0){f?.setData([],[]),g.current.model=null,f?.render(),r.fillStyle=a,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`No data`,OJ.left+8,OJ.top+8);return}let p=d.colorExt,{xToPx:m,yToPx:S,plotW:C,plotH:w,ext:T}=b(t,n);if(f)f.setView(T.xLo,T.xHi,T.yLo,T.yHi,{left:OJ.left,top:OJ.top,width:C,height:w}),f.render();else{for(let e=0;e<s.length;e++){let t=s.x[e],n=s.y[e];if(t!==t||n!==n)continue;let i=d.key?.[e]??0;r.beginPath(),r.arc(m(t),S(n),u,0,Math.PI*2),r.fillStyle=d.mode===`colormap`?jJ(i):d.mode===`dataset`?kJ[i%kJ.length]:c,r.globalAlpha=.8,r.fill()}r.globalAlpha=1}if(l){let e=Math.min(120,Math.floor((n-OJ.top-OJ.bottom)*.4)),i=t-OJ.right-12,o=OJ.top+8;for(let t=0;t<e;t++)r.fillStyle=jJ(1-t/(e-1)),r.fillRect(i,o+t,8,1);r.fillStyle=a,r.font=`9px ${Q.mono}`,r.textAlign=`left`,r.textBaseline=`middle`;let s=e=>Math.abs(e)>=1e4||Math.abs(e)<.001&&e!==0?e.toExponential(1):String(parseFloat(e.toPrecision(3)));r.fillText(s(p.hi),i+10,o),r.fillText(s(p.lo),i+10,o+e)}let E=s.colorLabels??[];if(!l&&E.length>0&&E.length<=10){let e=OJ.left,i=n-OJ.bottom-10;r.font=`9px ${Q.mono}`,r.textBaseline=`top`,E.forEach((n,o)=>{e>t-OJ.right-60&&(e=OJ.left,i-=14),r.fillStyle=kJ[o%kJ.length],r.beginPath(),r.arc(e+4,i+4,4,0,Math.PI*2),r.fill(),r.fillStyle=a,r.textAlign=`left`,r.fillText(n,e+10,i),e+=r.measureText(n).width+20})}}function C(){let e=c.current;if(!e)return;let{w:t,h:n}=v(),r=y(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=d.current;if(i===null)return;let{points:a,pointSize:o}=h.current;if(i<0||i>=a.length)return;let{xToPx:s,yToPx:l}=b(t,n),u=a.x[i],f=a.y[i],p=s(u),m=l(f);r.beginPath(),r.arc(p,m,o+3,0,Math.PI*2),r.strokeStyle=`rgba(255,255,255,0.9)`,r.lineWidth=2,r.stroke();let g=[],_=a.label?.(i);_&&g.push(_);let x=a.colorIndex?.[i];x!==void 0&&x>=0&&a.colorLabels?g.push(a.colorLabels[x]):a.colorValue&&g.push(a.colorValue[i].toFixed(3)),g.push(`(${u.toFixed(3)}, ${f.toFixed(3)})`);let S=g.join(` · `);r.font=`11px ${Q.mono}`;let C=r.measureText(S).width,w=Math.max(4,Math.min(t-C-8,p+10)),T=m-20<OJ.top?m+10:m-20;r.fillStyle=`rgba(0,0,0,0.75)`,r.fillRect(w-3,T-3,C+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(S,w,T)}let w=K(S);w.current=S;let T=K(null);T.current??=EH(()=>w.current(),()=>l.current?.ownerDocument);let E=()=>T.current.schedule(),D=()=>{bH(f.current),f.current=yH(C)};return W(()=>{T.current.now()}),W(()=>()=>T.current?.cancel(),[]),W(()=>{u.current=null,E()},[i]),G(()=>{let e=l.current;if(!e)return;let t=new TH(()=>{u.current=null,E(),D()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=c.current;if(!e)return;let t=null,n=e=>{e.preventDefault(),p.current?.({clientX:e.clientX,clientY:e.clientY})},r=n=>{let r=e.getBoundingClientRect(),{points:i,pointSize:a,model:o}=h.current,{w:s,h:c}=v(),{xToPx:l,yToPx:u,plotW:f,plotH:p}=b(s,c),m=e=>l(i.x[e])-OJ.left,g=e=>u(i.y[e])-OJ.top,_=a+8,y=`${s}|${c}|${_}`;(!t||t.model!==o||t.key!==y)&&(t={model:o,key:y,g:EJ(i.length,f,p,_,m,g)}),d.current=DJ(t.g,n.clientX-r.left-OJ.left,n.clientY-r.top-OJ.top,_,m,g),D()},i=()=>{d.current=null,D()};return e.addEventListener(`contextmenu`,n),e.addEventListener(`mousemove`,r),e.addEventListener(`mouseleave`,i),()=>{e.removeEventListener(`contextmenu`,n),e.removeEventListener(`mousemove`,r),e.removeEventListener(`mouseleave`,i)}},[]),_t(`div`,{ref:l,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`Embedding / scatter`}),q(`canvas`,{ref:s,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),q(`canvas`,{ref:c,className:`chart-canvas chart-overlay`})]})}var IJ={top:8,right:8,bottom:8,left:8},LJ=20,RJ=[`#f97316`,`#fb923c`,`#fdba74`,`#fbbf24`,`#fcd34d`,`#4ade80`,`#34d399`,`#38bdf8`,`#818cf8`,`#a78bfa`];function zJ(e){let t=new Map;for(let n of e){let e=n.parent??``;t.has(e)||t.set(e,[]),t.get(e).push(n)}function n(r,i){let a=(t.get(r)??[]).map(e=>n(e.name,i+1)),o=e.find(e=>e.name===r),s=a.reduce((e,t)=>e+t.value,0);return{name:r,value:o?Math.max(o.value,s):s,children:a,depth:i,x0:0,x1:1}}let r=new Set(e.map(e=>e.name)),i=e.filter(e=>!e.parent||!r.has(e.parent)).map(e=>n(e.name,0)),a=i.reduce((e,t)=>e+t.value,0)||1;function o(e,t,n){e.x0=t,e.x1=n;let r=n-t,i=t;for(let t of e.children){let n=t.value/e.value*r;o(t,i,i+n),i+=n}}let s=0;for(let e of i){let t=e.value/a;o(e,s,s+t),s+=t}return i}function BJ(e){let t=[];function n(e){t.push(e);for(let t of e.children)n(t)}for(let t of e)n(t);return t}function VJ(e){let t=0;function n(e){e.depth>t&&(t=e.depth);for(let t of e.children)n(t)}for(let t of e)n(t);return t}function HJ(e){return RJ[e%RJ.length]}function UJ({nodes:e,direction:t=`bottomup`,backgroundToken:n=``,onPlotContextMenu:r}){let i=K(null),a=K(null),o=K(null),s=K(null),c=K(null),l=K(0),u=K(r);G(()=>{u.current=r},[r]);let d=K({nodes:e,direction:t});G(()=>{d.current={nodes:e,direction:t}},[e,t]);let f=dt(()=>{let t=zJ(e);return{roots:t,flat:BJ(t),numRows:VJ(t)+1}},[e]),p=K(f);G(()=>{p.current=f},[f]);function m(){if(s.current)return s.current;let e=o.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return s.current=n,n}function h(){let e=o.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function g(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function _(e,t,n,r,i){let a=IJ.left+e.x0*t,o=(e.x1-e.x0)*t;return{x:a,y:i===`topdown`?IJ.top+e.depth*LJ:IJ.top+n-(e.depth+1)*LJ,w:o,h:LJ-1}}function v(){let e=i.current;if(!e)return;let{w:t,h:n}=h(),r=g(e,t,n);if(!r)return;let{bg:a,muted:o}=m(),{nodes:s,direction:c}=d.current;if(r.fillStyle=a,r.fillRect(0,0,t,n),s.length===0){r.fillStyle=o,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`No data`,IJ.left+8,IJ.top+8);return}let{flat:l,numRows:u}=p.current,f=t-IJ.left-IJ.right,v=u*LJ;for(let e of l){let t=_(e,f,v,u,c);if(!(t.w<1)&&(r.fillStyle=HJ(e.depth),r.fillRect(t.x,t.y,t.w,t.h),t.w>24)){r.fillStyle=`rgba(0,0,0,0.75)`,r.font=`${Math.min(11,LJ-4)}px ${Q.mono}`,r.textAlign=`left`,r.textBaseline=`middle`;let n=e.name,i=Math.floor((t.w-4)/7),a=n.length>i?n.slice(0,i-1)+`…`:n;r.fillText(a,t.x+3,t.y+LJ/2)}}}function y(){let e=a.current;if(!e)return;let{w:t,h:n}=h(),r=g(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=c.current;if(!i)return;let{direction:o}=d.current,{roots:s,numRows:l}=p.current;if(s.length===0)return;let u=_(i,t-IJ.left-IJ.right,l*LJ,l,o);r.strokeStyle=`rgba(255,255,255,0.9)`,r.lineWidth=2,r.strokeRect(u.x+1,u.y+1,u.w-2,u.h-2);let f=`${i.name} (${i.value.toLocaleString()})`;r.font=`11px ${Q.mono}`;let m=r.measureText(f).width,v=Math.max(4,Math.min(t-m-8,u.x+u.w/2-m/2)),y=u.y<30?u.y+LJ+4:u.y-20;r.fillStyle=`rgba(0,0,0,0.8)`,r.fillRect(v-3,y-3,m+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(f,v,y)}let b=K(v);b.current=v;let x=K(null);x.current??=EH(()=>b.current(),()=>o.current?.ownerDocument);let S=()=>x.current.schedule(),C=()=>{bH(l.current),l.current=yH(y)};return W(()=>{x.current.now()}),W(()=>()=>x.current?.cancel(),[]),W(()=>{s.current=null,S()},[n]),G(()=>{let e=o.current;if(!e)return;let t=new TH(()=>{s.current=null,S(),C()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=a.current;if(!e)return;let t=e=>{e.preventDefault(),u.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),{direction:r}=d.current,{roots:i,flat:a,numRows:o}=p.current;if(i.length===0){c.current=null,C();return}let s=t.clientX-n.left,l=t.clientY-n.top,u=n.width-IJ.left-IJ.right,f=o*LJ,m=null;for(let e of a){let t=_(e,u,f,o,r);if(s>=t.x&&s<=t.x+t.w&&l>=t.y&&l<=t.y+t.h){m=e;break}}c.current=m,C()},r=()=>{c.current=null,C()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),_t(`div`,{ref:o,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:i,className:`chart-canvas`,role:`img`,"aria-label":`Flame graph`}),q(`canvas`,{ref:a,className:`chart-canvas chart-overlay`})]})}var WJ={top:24,right:24,bottom:52,left:56},GJ=[`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`,`#facc15`,`#60a5fa`],KJ=.8;function qJ(e,t,n,r){let i,a,o;if(t)a=t.length,i=t.values,o=e=>String(e+1);else{let t=e??[];a=t.length,i=Array.from({length:n},(e,n)=>Float64Array.from(t,e=>e.values[n]??0)),o=e=>t[e].label}let s=0,c=0;if(r===`stacked`)for(let e=0;e<a;e++){let t=0,n=0;for(let r of i){let i=r[e];i>0?t+=i:i<0&&(n+=i)}t>c&&(c=t),n<s&&(s=n)}else for(let e of i)for(let t=0;t<a;t++){let n=e[t];n>c&&(c=n),n<s&&(s=n)}return c===s&&(c=s+1),{n:a,values:i,label:o,lo:s,hi:c}}function JJ(e,t,n){let r=e.values.length,i=[],a=[],o=[],s=[],c=[],l=(e,t,n,r,l)=>{i.push(e),a.push(t),o.push(n),s.push(r),c.push(l)};if(e.n<=n)for(let n=0;n<e.n;n++)if(t===`grouped`){let t=.8/r;for(let i=0;i<r;i++){let r=e.values[i][n];r===r&&l(n-.4+i*t,n-.4+(i+1)*t-t*.05,0,r,i)}}else{let t=0,i=0;for(let a=0;a<r;a++){let r=e.values[a][n];r!==r||r===0||(r>0?(l(n-.4,n+.4,t,t+r,a),t+=r):(l(n-.4,n+.4,i,i+r,a),i+=r))}}else{let i=e.n/n,a=new Float64Array(r),o=new Float64Array(r);for(let s=0;s<n;s++){let n=Math.floor(s*i),c=Math.min(e.n,Math.floor((s+1)*i));if(!(c<=n)){a.fill(0),o.fill(0);for(let i=n;i<c;i++){let n=0,s=0;for(let c=0;c<r;c++){let r=e.values[c][i];r===r&&(t===`stacked`?r>0?(n+=r,n>o[c]&&(o[c]=n)):(s+=r,s<a[c]&&(a[c]=s)):(r>o[c]&&(o[c]=r),r<a[c]&&(a[c]=r)))}}for(let e=t===`stacked`?r-1:0;t===`stacked`?e>=0:e<r;t===`stacked`?e--:e++)(o[e]!==0||a[e]!==0)&&l(n-.5,c-.5,a[e],o[e],e)}}}return{x0:Float64Array.from(i),x1:Float64Array.from(a),y0:Float64Array.from(o),y1:Float64Array.from(s),k:Float64Array.from(c)}}function YJ({groups:e,columns:t,seriesNames:n,colors:r,mode:i=`grouped`,horizontal:a=!1,valueRange:o,backgroundToken:s=``,onPlotContextMenu:c}){let l=eU(),u=K(null),d=K(null),f=K(null),p=K(null),m=K(null),h=K(null),g=K(0),_=K(c);G(()=>{_.current=c},[c]);let v=K(null),y=dt(()=>{let r=[e,i,n.length,t?.length,...t?.values??[]],a=v.current;if(a&&a.key.length===r.length&&a.key.every((e,t)=>e===r[t]))return a.value;let o=qJ(e,t,n.length,i);return v.current={key:r,value:o},o},[e,t,n.length,i]),b=K({bars:y,seriesNames:n,colors:r,mode:i,horizontal:a,valueRange:o});G(()=>{b.current={bars:y,seriesNames:n,colors:r,mode:i,horizontal:a,valueRange:o}},[y,n,r,i,a,o]);let x=K({plot:null,failed:!1,key:``,data:null,size:``});W(()=>()=>{x.current.plot?.dispose(),x.current.plot=null},[]);let S=K({bars:null,view:``});function C(){if(m.current)return m.current;let e=p.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return m.current=n,n}function w(){let e=p.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||300)}}function T(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function E(e){let t=b.current.colors??[];return Array.from({length:e},(e,n)=>t[n]??GJ[n%GJ.length])}function D(e,t){let{bars:n,valueRange:r}=b.current,i=n.lo,a=n.hi;r?.min!==void 0&&Number.isFinite(r.min)&&(i=r.min),r?.max!==void 0&&Number.isFinite(r.max)&&(a=r.max);let o=qW(WJ,e,t),{top:s,right:c,bottom:l,left:u}=o;return{lo:i,hi:a,top:s,left:u,plotW:e-u-c,plotH:t-s-l,tiny:o.tiny}}function O(e,t){let n=x.current;if(!n.plot&&!n.failed&&d.current&&(n.plot=lH(d.current,PK),n.failed=!n.plot),!n.plot||!d.current)return null;let r=Math.min(2,window.devicePixelRatio||1),i=`${e}x${t}@${r}`;return n.size!==i&&(n.plot.resize(e,t,r),d.current.style.width=`${e}px`,d.current.style.height=`${t}px`,n.size=i),n.plot}function k(){let e=u.current;if(!e)return;let{w:t,h:n}=w(),r=T(e,t,n);if(!r)return;let{bg:i,muted:a,grid:o}=C(),{bars:s,seriesNames:c,mode:d,horizontal:f}=b.current;r.fillStyle=i,r.fillRect(0,0,t,n);let m=O(t,n);if(s.n===0||c.length===0){m?.keep([]),m?.render(),r.fillStyle=a,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`No data`,WJ.left+8,WJ.top+8);return}let{lo:h,hi:g,top:_,left:v,plotW:y,plotH:k,tiny:A}=D(t,n),j=E(c.length),M=f?k:y,N=e=>f?v+(e-h)/(g-h)*y:_+k-(e-h)/(g-h)*k,P=e=>(f?_:v)+(e+.5)/s.n*M;l({left:v,top:_,width:y,height:k,...f?{x:{v0:h,v1:g}}:{y:{v0:h,v1:g}}}),r.strokeStyle=o,r.lineWidth=1;for(let e=0;e<=5;e++){let t=h+e/5*(g-h),n=N(t);r.beginPath(),f?(r.moveTo(n,_),r.lineTo(n,_+k)):(r.moveTo(v,n),r.lineTo(v+y,n)),r.stroke(),r.fillStyle=a,r.font=`9px ${Q.mono}`,!A&&(f?(r.textAlign=`center`,r.textBaseline=`top`,r.fillText(jz(t,(g-h)/5),n,_+k+4)):(r.textAlign=`right`,r.textBaseline=`middle`,r.fillText(jz(t,(g-h)/5),v-4,n)))}let F=`${h}|${g}|${f}`;(S.current.bars!==s||S.current.view!==F)&&(S.current={bars:s,view:F},SH(p.current));let I=Math.min(2,window.devicePixelRatio||1),L=Math.max(1,Math.round(M*I)),R=j.map(e=>{let t=zV(e);return[t[0],t[1],t[2],KJ]}),z={left:v,top:_,width:y,height:k};if(m){let e=`${d}|${f}|${L}|${j.join(`,`)}`;if(x.current.key!==e||x.current.data!==s){let t=JJ(s,d,L);f?m.setRects(`bars`,t.y0,t.y1,t.x0,t.x1,R,t.k):m.setRects(`bars`,t.x0,t.x1,t.y0,t.y1,R,t.k),m.keep([`bars`]),x.current.key=e,x.current.data=s}f?m.setView(h,g,s.n-.5,-.5,z):m.setView(-.5,s.n-.5,h,g,z),m.render()}else{let e=JJ(s,d,L);r.globalAlpha=KJ;for(let t=0;t<e.x0.length;t++){r.fillStyle=j[e.k[t]];let n=P(e.x0[t]-.5),i=P(e.x1[t]-.5),a=N(e.y0[t]),o=N(e.y1[t]);f?r.fillRect(Math.min(a,o),n,Math.max(1,Math.abs(o-a)),Math.max(1,i-n)):r.fillRect(n,Math.min(a,o),Math.max(1,i-n),Math.max(1,Math.abs(o-a)))}r.globalAlpha=1}if(h<0&&g>0){let e=N(0);r.strokeStyle=a,r.lineWidth=1.5,r.beginPath(),f?(r.moveTo(e,_),r.lineTo(e,_+k)):(r.moveTo(v,e),r.lineTo(v+y,e)),r.stroke()}r.fillStyle=a,r.font=`9px ${Q.mono}`;let B=Math.max(1,Math.ceil(s.n/Math.max(1,Math.floor(M/(f?14:48)))));for(let e=0;e<(A?0:s.n);e+=B){let t=P(e),n=s.label(e),i=n.length>14?n.slice(0,13)+`…`:n;f?(r.textAlign=`right`,r.textBaseline=`middle`,r.fillText(i,v-4,t)):(r.textAlign=`center`,r.textBaseline=`top`,r.fillText(i,t,_+k+4))}if(c.length>1&&!A){let e=f?_-14:_+k+32,t=v;r.font=`9px ${Q.mono}`,r.textBaseline=`top`;for(let n=0;n<c.length&&(r.fillStyle=j[n],r.fillRect(t,e,10,8),r.fillStyle=a,r.textAlign=`left`,r.fillText(c[n],t+13,e),t+=r.measureText(c[n]).width+26,!(t>v+y-30));n++);}}function A(){let e=f.current;if(!e)return;let{w:t,h:n}=w(),r=T(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=h.current,{bars:a,seriesNames:o,horizontal:s}=b.current;if(i===null||i>=a.n)return;let{top:c,left:l,plotW:u,plotH:d}=D(t,n),p=s?d:u,m=(s?c:l)+(i+.5)/a.n*p,g=Math.max(1,p/a.n);r.fillStyle=`rgba(255,255,255,0.08)`,s?r.fillRect(l,m-g/2,u,g):r.fillRect(m-g/2,c,g,d);let _=a.values.map((e,t)=>`${o.length>1?o[t]+` `:``}${Mz(e[i])}`).join(` `),v=`${a.label(i)}: ${_}`;r.font=`11px ${Q.mono}`;let y=r.measureText(v).width,x=s?l+u/2:m,S=s?m:c+d/2,C=Math.max(4,Math.min(t-y-8,x-y/2)),E=S-28<c?S+10:S-24;r.fillStyle=`rgba(0,0,0,0.8)`,r.fillRect(C-3,E-3,y+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(v,C,E)}let j=K(k);j.current=k;let M=K(null);M.current??=EH(()=>j.current(),()=>p.current?.ownerDocument);let N=()=>{g.current||=yH(()=>{g.current=0,A()})};return W(()=>{M.current.now()},[y,n,r,i,a,o]),W(()=>()=>{M.current?.cancel(),bH(g.current)},[]),W(()=>{m.current=null,M.current.schedule()},[s]),G(()=>{let e=p.current;if(!e)return;let t=new TH(()=>{m.current=null,M.current.schedule(),N()});return t.observe(e),()=>t.disconnect()},[]),G(()=>{let e=f.current;if(!e)return;let t=e=>{e.preventDefault(),_.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),{bars:r,horizontal:i}=b.current,{w:a,h:o}=w(),{top:s,left:c,plotW:l,plotH:u}=D(a,o),d=i?t.clientY-n.top-s:t.clientX-n.left-c,f=i?u:l,p=d>=0&&d<f&&r.n>0?Math.min(r.n-1,Math.floor(d/f*r.n)):null;p!==h.current&&(h.current=p,N())},r=()=>{h.current=null,N()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),_t(`div`,{ref:p,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:u,className:`chart-canvas`,role:`img`,"aria-label":`Bar chart`}),q(`canvas`,{ref:d,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),q(`canvas`,{ref:f,className:`chart-canvas chart-overlay`})]})}var XJ=[`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`];function ZJ(e,t){if(!t)return XJ[e%XJ.length];if(e===0)return t;let n=XJ.filter(e=>e.toLowerCase()!==t.toLowerCase());return n[(e-1)%n.length]}var QJ={top:36,right:36,bottom:36,left:36};function $J({axes:e,series:t,fill:n=!0,color:r,backgroundToken:i=``,onPlotContextMenu:a}){let o=K(null),s=K(null),c=K(null),l=K(null),u=K(a);G(()=>{u.current=a},[a]);let d=K({axes:e,series:t,fill:n,color:r});G(()=>{d.current={axes:e,series:t,fill:n,color:r}},[e,t,n,r]);function f(){if(l.current)return l.current;let e=c.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return l.current=n,n}function p(){let e=c.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||300)}}function m(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function h(){let e=o.current;if(!e)return;let{w:t,h:n}=p(),r=m(e,t,n);if(!r)return;let{bg:i,muted:a,grid:s}=f(),{axes:c,series:l,fill:u}=d.current;if(r.fillStyle=i,r.fillRect(0,0,t,n),c.length<3||l.length===0){r.fillStyle=a,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`Select ≥ 3 axes`,QJ.left+8,QJ.top+8);return}let h=c.length,g=t/2,_=n/2,v=Math.min(t-QJ.left-QJ.right,n-QJ.top-QJ.bottom)/2,y=c.map((e,t)=>{let n=0;for(let e of l){let r=e.values[t]??0;r>n&&(n=r)}return n||1});function b(e){return Math.PI*2*e/h-Math.PI/2}function x(e,t){let n=b(e);return{x:g+Math.cos(n)*v*t,y:_+Math.sin(n)*v*t}}for(let e=1;e<=4;e++){let t=e/4;r.beginPath();for(let e=0;e<h;e++){let n=x(e,t);e===0?r.moveTo(n.x,n.y):r.lineTo(n.x,n.y)}r.closePath(),r.strokeStyle=s,r.lineWidth=1,r.stroke()}r.strokeStyle=a,r.lineWidth=1;for(let e=0;e<h;e++){let t=x(e,1);r.beginPath(),r.moveTo(g,_),r.lineTo(t.x,t.y),r.stroke(),r.fillStyle=a,r.font=`10px ${Q.mono}`;let n=b(e),i=x(e,1+10/v);r.textAlign=Math.abs(Math.cos(n))<.1?`center`:Math.cos(n)<0?`right`:`left`,r.textBaseline=Math.abs(Math.sin(n))<.1?`middle`:Math.sin(n)<0?`bottom`:`top`;let o=c[e].length>12?c[e].slice(0,11)+`…`:c[e];r.fillText(o,i.x,i.y)}for(let e=0;e<l.length;e++){let t=l[e],n=ZJ(e,d.current.color);r.beginPath();for(let e=0;e<h;e++){let n=Math.max(0,Math.min(1,(t.values[e]??0)/y[e])),i=x(e,n);e===0?r.moveTo(i.x,i.y):r.lineTo(i.x,i.y)}r.closePath(),u&&(r.fillStyle=n,r.globalAlpha=.15,r.fill()),r.globalAlpha=1,r.strokeStyle=n,r.lineWidth=1,r.stroke();for(let e=0;e<h;e++){let i=Math.max(0,Math.min(1,(t.values[e]??0)/y[e])),a=x(e,i);r.beginPath(),r.arc(a.x,a.y,3,0,Math.PI*2),r.fillStyle=n,r.globalAlpha=.9,r.fill()}r.globalAlpha=1}if(l.length>1){let e=QJ.left,i=n-QJ.bottom-10;r.font=`9px ${Q.mono}`,r.textBaseline=`top`;for(let n=0;n<l.length&&(r.fillStyle=ZJ(n,d.current.color),r.fillRect(e,i,10,8),r.fillStyle=a,r.textAlign=`left`,r.fillText(l[n].name,e+13,i),e+=r.measureText(l[n].name).width+26,!(e>t-QJ.right-30));n++);}}let g=K(h);g.current=h;let _=K(null);_.current??=EH(()=>g.current(),()=>c.current?.ownerDocument);let v=()=>_.current.schedule();return W(()=>{_.current.now()}),W(()=>()=>_.current?.cancel(),[]),W(()=>{l.current=null,v()},[i]),G(()=>{let e=c.current;if(!e)return;let t=new TH(()=>{l.current=null,v()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=s.current;if(!e)return;let t=e=>{e.preventDefault(),u.current?.({clientX:e.clientX,clientY:e.clientY})};return e.addEventListener(`contextmenu`,t),()=>{e.removeEventListener(`contextmenu`,t)}},[]),_t(`div`,{ref:c,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`Radar chart`}),q(`canvas`,{ref:s,className:`chart-canvas chart-overlay`})]})}var eY={top:16,right:16,bottom:40,left:52},tY=[`#38bdf8`,`#4ade80`,`#fb7185`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`];function nY(e,t){let n=e.length>0&&e.every(t=>t.x===e[0].x||t.x.length===e[0].x.length),r=t&&n,i=e.map(e=>e.x),a=[],o=[],s=null;for(let t of e){if(!r){a.push(t.y),o.push(null);continue}let e=t.x.length,n=new Float64Array(e);for(let r=0;r<e;r++){let e=t.y[r];n[r]=(s?s[r]:0)+(e>0?e:0)}a.push(n),o.push(s??null),s=n}let c=1/0,l=-1/0,u=0,d=0;for(let e of i)for(let t=0;t<e.length;t++){let n=e[t];n<c&&(c=n),n>l&&(l=n)}for(let e of a)for(let t=0;t<e.length;t++){let n=e[t];n<u&&(u=n),n>d&&(d=n)}return Number.isFinite(c)||(c=0,l=1),{x:i,lo:o,hi:a,ascending:i.map(e=>UK(e)),xLo:c,xHi:l,yLo:u,yHi:d}}function rY({series:e,stacked:t=!1,yRange:n,backgroundToken:r=``,onPlotContextMenu:i}){let a=eU(),o=K(null),s=K(null),c=K(null),l=K(null),u=K(null),d=K(null),f=K(0),p=K(i);G(()=>{p.current=i},[i]);let m=K(null),h=dt(()=>{let n=m.current;if(n&&n.stacked===t&&n.series.length===e.length&&n.series.every((t,n)=>t.x===e[n].x&&t.y===e[n].y&&t.name===e[n].name))return n.value;let r=nY(e,t);return m.current={series:e,stacked:t,value:r},r},[e,t]),g=K({series:e,prepared:h,yRange:n});G(()=>{g.current={series:e,prepared:h,yRange:n}},[e,h,n]);let _=K({plot:null,failed:!1,key:``,size:``});W(()=>()=>{_.current.plot?.dispose(),_.current.plot=null},[]);let v=K({prepared:null,view:``});function y(){if(u.current)return u.current;let e=l.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return u.current=n,n}function b(){let e=l.current;return{w:Math.max(1,e?.clientWidth||600),h:Math.max(1,e?.clientHeight||300)}}function x(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function S(e,t){let n=(e.xHi-e.xLo)*.01||.5,r=e.yLo,i=e.yHi;return i===r&&(i=r+1),i+=(i-r)*.05,t?.min!==void 0&&Number.isFinite(t.min)&&(r=t.min),t?.max!==void 0&&Number.isFinite(t.max)&&(i=t.max),{xLo:e.xLo-n,xHi:e.xHi+n,yLo:r,yHi:i}}function C(e,t,n,r,i){let a=e.x[t],o=e.hi[t],s=e.lo[t];if(!e.ascending[t]||a.length<=2*i)return{x:a,hi:o,lo:s??new Float64Array(a.length)};let c=BK(a,o,n,r,i);return{x:HK(a,c),hi:HK(o,c),lo:s?HK(s,c):new Float64Array(c.length)}}function w(){let e=o.current;if(!e)return;let{w:n,h:r}=b(),i=x(e,n,r);if(!i)return;let{bg:s,muted:c,grid:u}=y(),{series:d,prepared:f,yRange:p}=g.current;i.fillStyle=s,i.fillRect(0,0,n,r);let m=_.current.plot;if(d.length===0){m?.keep([]),m?.render(),i.fillStyle=c,i.font=`13px ${Q.sans}`,i.textAlign=`left`,i.textBaseline=`top`,i.fillText(`No data`,eY.left+8,eY.top+8);return}let h=qW(eY,n,r),{top:w,right:D,bottom:O,left:k}=h,A=n-k-D,j=r-w-O,{xLo:M,xHi:N,yLo:P,yHi:F}=S(f,p),I=e=>k+(e-M)/(N-M)*A,L=e=>w+j-(e-P)/(F-P)*j;a({left:k,top:w,width:A,height:j,x:{v0:M,v1:N},y:{v0:P,v1:F}}),i.strokeStyle=u,i.lineWidth=1;for(let e=0;e<=5;e++){let t=P+e/5*(F-P),n=L(t);i.beginPath(),i.moveTo(k,n),i.lineTo(k+A,n),i.stroke(),i.fillStyle=c,i.font=`9px ${Q.mono}`,i.textAlign=`right`,i.textBaseline=`middle`,h.tiny||i.fillText(jz(t,(F-P)/5),k-4,n)}let R=Math.min(8,f.x[0]?.length??5);for(let e=0;e<=R;e++){let t=M+e/R*(N-M),n=I(t);i.beginPath(),i.moveTo(n,w),i.lineTo(n,w+j),i.stroke(),i.fillStyle=c,i.font=`9px ${Q.mono}`,i.textAlign=`center`,i.textBaseline=`top`,h.tiny||i.fillText(jz(t,(N-M)/R),n,w+j+4)}let z=`${M}|${N}|${P}|${F}`;(v.current.prepared!==f||v.current.view!==z)&&(v.current={prepared:f,view:z},SH(l.current));let B=E(n,r),V=Math.min(2,window.devicePixelRatio||1),ee=Math.max(1,Math.round(A*V)),te=d.map((e,t)=>zV(tY[t%tY.length]));if(B){let e=`${M}|${N}|${ee}`;if(_.current.key!==e||T.current!==f){let n=[];for(let e=0;e<d.length;e++){let r=C(f,e,M,N,ee),i=te[e],a=[i[0],i[1],i[2],f.lo[e]||t?.7:.25];B.setBands(`b${e}`,r.x,r.lo,r.hi,a),B.setLine(`l${e}`,r.x,r.hi,i,1),n.push(`b${e}`,`l${e}`)}B.keep(n),_.current.key=e,T.current=f}B.setView(M,N,P,F,{left:k,top:w,width:A,height:j}),B.render()}else for(let e=0;e<d.length;e++){let n=C(f,e,M,N,ee),r=tY[e%tY.length];i.save(),i.beginPath(),i.rect(k,w,A,j),i.clip(),i.beginPath();for(let e=0;e<n.x.length;e++){let t=I(n.x[e]);e===0?i.moveTo(t,L(n.lo[e])):i.lineTo(t,L(n.lo[e]))}for(let e=n.x.length-1;e>=0;e--)i.lineTo(I(n.x[e]),L(n.hi[e]));i.closePath(),i.fillStyle=r,i.globalAlpha=f.lo[e]||t?.7:.25,i.fill(),i.beginPath();for(let e=0;e<n.x.length;e++){let t=I(n.x[e]),r=L(n.hi[e]);e===0?i.moveTo(t,r):i.lineTo(t,r)}i.globalAlpha=1,i.strokeStyle=r,i.lineWidth=1,i.stroke(),i.restore()}if(d.length>1&&!h.tiny){let e=k,t=w+j+24;i.font=`9px ${Q.mono}`,i.textBaseline=`top`;for(let n=0;n<d.length&&(i.fillStyle=tY[n%tY.length],i.fillRect(e,t,10,8),i.fillStyle=c,i.textAlign=`left`,i.fillText(d[n].name,e+13,t),e+=i.measureText(d[n].name).width+26,!(e>k+A-30));n++);}}let T=K(null);function E(e,t){let n=_.current;if(!n.plot&&!n.failed&&s.current&&(n.plot=lH(s.current,PK),n.failed=!n.plot),!n.plot||!s.current)return null;let r=Math.min(2,window.devicePixelRatio||1),i=`${e}x${t}@${r}`;return n.size!==i&&(n.plot.resize(e,t,r),s.current.style.width=`${e}px`,s.current.style.height=`${t}px`,n.size=i),n.plot}function D(){let e=c.current;if(!e)return;let{w:t,h:n}=b(),r=x(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=d.current;if(i===null)return;let{prepared:a,yRange:o}=g.current,{top:s,right:l,left:u,bottom:f}=qW(eY,t,n),p=n-s-f;r.strokeStyle=`rgba(255,255,255,0.4)`,r.lineWidth=1,r.setLineDash([4,4]),r.beginPath(),r.moveTo(i,s),r.lineTo(i,s+p),r.stroke(),r.setLineDash([]);let{xLo:m,xHi:h}=S(a,o),_=t-u-l,v=`x=${Mz(m+(i-u)/_*(h-m))}`;r.font=`11px ${Q.mono}`;let y=r.measureText(v).width,C=Math.max(4,Math.min(t-y-8,i-y/2));r.fillStyle=`rgba(0,0,0,0.7)`,r.fillRect(C-3,s-3,y+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(v,C,s)}let O=K(w);O.current=w;let k=K(null);k.current??=EH(()=>O.current(),()=>l.current?.ownerDocument);let A=()=>{f.current||=yH(()=>{f.current=0,D()})};return W(()=>{k.current.now()},[e,h,n]),W(()=>()=>{k.current?.cancel(),bH(f.current)},[]),W(()=>{u.current=null,k.current.schedule()},[r]),G(()=>{let e=l.current;if(!e)return;let t=new TH(()=>{u.current=null,k.current.schedule(),A()});return t.observe(e),()=>t.disconnect()},[]),G(()=>{let e=c.current;if(!e)return;let t=e=>{e.preventDefault(),p.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect();d.current=t.clientX-n.left,A()},r=()=>{d.current=null,A()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),_t(`div`,{ref:l,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`Area chart`}),q(`canvas`,{ref:s,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),q(`canvas`,{ref:c,className:`chart-canvas chart-overlay`})]})}var iY={top:16,right:16,bottom:40,left:52},aY=[`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`];function oY({series:e,complement:t=!1,logX:n=!1,backgroundToken:r=``,onPlotContextMenu:i}){let a=eU(),o=K(null),s=K(null),c=K(null),l=K(null),u=K(null),d=K(0),f=K(i);G(()=>{f.current=i},[i]);let p=K({series:e,complement:t,logX:n});G(()=>{p.current={series:e,complement:t,logX:n}},[e,t,n]);let m=dt(()=>{let t=e.map(e=>Float64Array.from(e.values).sort()),n=1/0,r=-1/0;for(let e of t)e.length&&(n=Math.min(n,e[0]),r=Math.max(r,e[e.length-1]));return{all:t,xLo:n,xHi:r}},[e]),h=K(m);G(()=>{h.current=m},[m]);function g(){if(l.current)return l.current;let e=c.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return l.current=n,n}function _(){let e=c.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||300)}}function v(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function y(){let e=o.current;if(!e)return;let{w:t,h:n}=_(),r=v(e,t,n);if(!r)return;let{bg:i,muted:s,grid:c}=g(),{series:l,complement:u,logX:d}=p.current;if(r.fillStyle=i,r.fillRect(0,0,t,n),l.length===0){r.fillStyle=s,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`No data`,iY.left+8,iY.top+8);return}let{top:f,right:m,bottom:y,left:b}=iY,x=t-b-m,S=n-f-y,{xLo:C,xHi:w}=h.current;Number.isFinite(C)||(C=0,w=1);let T=e=>Math.log10(Math.max(1e-10,e)),E=d?T(C):C,D=d?T(w):w,O=e=>b+((d?T(e):e)-E)/(D-E||1)*x,k=e=>f+S-e*S;a({left:b,top:f,width:x,height:S,x:{v0:C,v1:w,log:d}});for(let e=0;e<=5;e++){let t=e/5,n=k(t);r.strokeStyle=c,r.lineWidth=1,r.beginPath(),r.moveTo(b,n),r.lineTo(b+x,n),r.stroke(),r.fillStyle=s,r.font=`9px ${Q.mono}`,r.textAlign=`right`,r.textBaseline=`middle`,r.fillText(String(t.toFixed(2)),b-4,n)}for(let e=0;e<=6;e++){let t=C+e/6*(w-C),n=O(t);r.strokeStyle=c,r.lineWidth=1,r.beginPath(),r.moveTo(n,f),r.lineTo(n,f+S),r.stroke(),r.fillStyle=s,r.font=`9px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`top`,r.fillText(jz(t,(w-C)/6),n,f+S+4)}for(let e=0;e<l.length;e++){let t=h.current.all[e],n=t?.length??0;if(n===0)continue;let i=e=>k(u?1-(e+1)/n:(e+1)/n),a=O(t[0]),o=k(+!!u);r.beginPath(),r.moveTo(a,o);for(let e=0;e<n;e++){if(e+1<n&&t[e+1]===t[e])continue;let s=O(t[e]),c=i(e);if(Math.abs(s-a)<.5){o=c;continue}r.lineTo(a,o),r.lineTo(s,o),a=s,o=c}r.lineTo(a,o),r.strokeStyle=aY[e%aY.length],r.lineWidth=1,r.stroke()}if(l.length>1){let e=b,t=f+S+24;r.font=`9px ${Q.mono}`,r.textBaseline=`top`;for(let n=0;n<l.length&&(r.fillStyle=aY[n%aY.length],r.fillRect(e,t,16,2),r.fillStyle=s,r.textAlign=`left`,r.fillText(l[n].name,e+20,t-3),e+=r.measureText(l[n].name).width+30,!(e>b+x-30));n++);}r.save(),r.translate(12,f+S/2),r.rotate(-Math.PI/2),r.fillStyle=s,r.font=`9px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`middle`,r.fillText(u?`CCDF`:`CDF`,0,0),r.restore()}function b(){let e=s.current;if(!e)return;let{w:t,h:n}=_(),r=v(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=u.current;if(i===null)return;let{top:a,left:o,right:c}=iY,l=n-a-iY.bottom,d=t-o-c;r.strokeStyle=`rgba(255,255,255,0.4)`,r.lineWidth=1,r.setLineDash([4,4]),r.beginPath(),r.moveTo(i,a),r.lineTo(i,a+l),r.stroke(),r.setLineDash([]);let{xLo:f,xHi:p}=h.current;if(!Number.isFinite(f))return;let m=Mz(f+(i-o)/d*(p-f));r.font=`11px ${Q.mono}`;let g=r.measureText(m).width,y=Math.max(4,Math.min(t-g-8,i-g/2));r.fillStyle=`rgba(0,0,0,0.7)`,r.fillRect(y-3,a+l+2,g+6,16),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(m,y,a+l+4)}let x=K(y);x.current=y;let S=K(null);S.current??=EH(()=>x.current(),()=>c.current?.ownerDocument);let C=()=>S.current.schedule(),w=()=>{bH(d.current),d.current=yH(b)};return W(()=>{S.current.now()}),W(()=>()=>S.current?.cancel(),[]),W(()=>{l.current=null,C()},[r]),G(()=>{let e=c.current;if(!e)return;let t=new TH(()=>{l.current=null,C(),w()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=s.current;if(!e)return;let t=e=>{e.preventDefault(),f.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect();u.current=t.clientX-n.left,w()},r=()=>{u.current=null,w()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),_t(`div`,{ref:c,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`CDF chart`}),q(`canvas`,{ref:s,className:`chart-canvas chart-overlay`})]})}var sY={top:16,right:40,bottom:40,left:52},cY=[`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`,`#facc15`,`#60a5fa`];function lY(e){return[Math.round(255*Math.min(1,Math.max(0,3.5*e-.5))),Math.round(255*Math.min(1,Math.max(0,e<.5?2*e:2-2*e))),Math.round(255*Math.min(1,Math.max(0,1.5-3.5*e)))]}function uY(e){let[t,n,r]=lY(e);return`rgb(${t},${n},${r})`}var dY=(()=>{let e=new Uint8Array(1024);for(let t=0;t<256;t++)e.set([...lY(t/255),255],t*4);return e})(),fY=()=>{let e=new Uint8Array(1024);for(let t=0;t<256;t++){let[n,r,i]=JG(cY[t%cY.length],1);e.set([n*255,r*255,i*255,255],t*4)}return e};function pY(e,t,n){let r=e.length,i=1/0,a=-1/0,o=1/0,s=-1/0,c=1/0,l=-1/0;for(let t=0;t<r;t++){let n=e.x[t],r=e.y[t],u=e.size[t];n<i&&(i=n),n>a&&(a=n),r<o&&(o=r),r>s&&(s=r),u<c&&(c=u),u>l&&(l=u)}let u=Number.isFinite(i)?(()=>{let e=(a-i)*.1||1,t=(s-o)*.1||1;return{xLo:i-e,xHi:a+e,yLo:o-t,yHi:s+t,sLo:c,sHi:l}})():{xLo:-1,xHi:1,yLo:-1,yHi:1,sLo:1,sHi:1},d=u.sHi-u.sLo||1,f=new Float32Array(r);for(let t=0;t<r;t++)f[t]=3+(e.size[t]-u.sLo)/d*(n-3);let p=0,m=1,h=null,g=`single`;if(t&&e.colorValue){let t=e.colorValue,n=1/0,i=-1/0;for(let e=0;e<r;e++)t[e]<n&&(n=t[e]),t[e]>i&&(i=t[e]);Number.isFinite(n)&&(p=n,m=i),h=new Float32Array(r);for(let e=0;e<r;e++)h[e]=t[e]===t[e]?Math.max(0,Math.min(1,(t[e]-p)/(m-p||1))):0;g=`colormap`}else !t&&e.colorIndex&&(h=Float32Array.from(e.colorIndex,e=>e>=0?e%256:0),g=`dataset`);let _=Uint32Array.from({length:r},(e,t)=>t).sort((e,t)=>(f[t]||0)-(f[e]||0)),v=e=>{let t=new Float64Array(r);for(let n=0;n<r;n++)t[n]=e[_[n]];return t};return{ext:u,radius:f,key:h,mode:g,colorLo:p,colorHi:m,drawn:{x:v(e.x),y:v(e.y),r:v(f),k:h?v(h):void 0}}}function mY({points:e,color:t=`#64748b`,colorByNumeric:n=!1,maxRadius:r=24,backgroundToken:i=``,onPlotContextMenu:a}){let o=eU(),s=K(null),c=K(null),l=K(null),u=K(null),d=K(null),f=K(null),p=K(0),m=K(a);G(()=>{m.current=a},[a]);let h=dt(()=>pY(e,n,r),[e,n,r]),g=K({points:e,color:t,colorByNumeric:n,maxRadius:r,model:h});G(()=>{g.current={points:e,color:t,colorByNumeric:n,maxRadius:r,model:h}},[e,t,n,r,h]);let _=K({r:null,failed:!1,size:``,model:null,style:``});W(()=>()=>{_.current.r?.dispose(),_.current.r=null},[]);function v(){if(d.current)return d.current;let e=u.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return d.current=n,n}function y(){let e=u.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||300)}}function b(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function x(e,t){let{xLo:n,xHi:r,yLo:i,yHi:a}=g.current.model.ext,{top:s,right:c,bottom:l,left:u}=sY,d=e-u-c,f=t-s-l;return o({left:u,top:s,width:d,height:f,x:{v0:n,v1:r},y:{v0:i,v1:a}}),{plotW:d,plotH:f,xToPx:e=>u+(e-n)/(r-n)*d,yToPx:e=>s+(1-(e-i)/(a-i))*f}}function S(e,t){let n=_.current;!n.r&&!n.failed&&c.current&&(n.r=lH(c.current,GW),n.failed=!n.r);let r=n.r;if(!r||!c.current)return null;let i=Math.min(2,window.devicePixelRatio||1),a=`${e}x${t}@${i}`;n.size!==a&&(r.resize(e,t,i),c.current.style.width=`${e}px`,c.current.style.height=`${t}px`,n.size=a);let{model:o,color:s}=g.current;n.model!==o&&(r.setData(o.drawn.x,o.drawn.y,o.drawn.k,!1,o.drawn.r),n.model=o,SH(u.current));let l=`${o.mode}|${s}`;return n.style!==l&&(r.setStyle(o.mode===`single`?{kind:`single`,rgba:JG(s,1)}:{kind:o.mode,palette:o.mode===`colormap`?dY:fY()},3,.65),r.setDraw(!0,!1,0),n.style=l),r}function C(){let e=s.current;if(!e)return;let{w:t,h:n}=y(),r=b(e,t,n);if(!r)return;let{bg:i,muted:a,grid:o}=v(),{points:c,color:l,colorByNumeric:u,model:d}=g.current;r.fillStyle=i,r.fillRect(0,0,t,n);let f=S(t,n);if(c.length===0){f?.setData([],[]),_.current.model=null,f?.render(),r.fillStyle=a,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`No data`,sY.left+8,sY.top+8);return}let{xLo:p,xHi:m,yLo:h,yHi:C}=d.ext,{top:w,left:T}=sY,{plotW:E,plotH:D,xToPx:O,yToPx:k}=x(t,n);r.strokeStyle=o,r.lineWidth=1;for(let e=0;e<=5;e++){let t=p+e/5*(m-p),n=O(t);r.beginPath(),r.moveTo(n,w),r.lineTo(n,w+D),r.stroke(),r.fillStyle=a,r.font=`9px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`top`,r.fillText(jz(t,(m-p)/5),n,w+D+4);let i=h+e/5*(C-h),o=k(i);r.beginPath(),r.moveTo(T,o),r.lineTo(T+E,o),r.stroke(),r.fillStyle=a,r.textAlign=`right`,r.textBaseline=`middle`,r.fillText(jz(i,(C-h)/5),T-4,o)}if(f)f.setView(p,m,h,C,{left:T,top:w,width:E,height:D}),f.render();else{let e=d.drawn;r.globalAlpha=.65;for(let t=0;t<e.x.length;t++){if(e.x[t]!==e.x[t]||e.y[t]!==e.y[t])continue;let n=e.k?.[t]??0;r.fillStyle=d.mode===`colormap`?uY(n):d.mode===`dataset`?cY[n%cY.length]:l,r.beginPath(),r.arc(O(e.x[t]),k(e.y[t]),e.r[t],0,Math.PI*2),r.fill()}r.globalAlpha=1}let A=c.colorLabels??[];if(!u&&A.length>0&&A.length<=10){let e=T,t=n-sY.bottom-10;r.font=`9px ${Q.mono}`,r.textBaseline=`top`;for(let n=0;n<A.length;n++){let i=A[n];if(r.fillStyle=cY[n%cY.length],r.beginPath(),r.arc(e+4,t+4,4,0,Math.PI*2),r.fill(),r.fillStyle=a,r.textAlign=`left`,r.fillText(i,e+10,t),e+=r.measureText(i).width+20,e>T+E-60)break}}}function w(){let e=l.current;if(!e)return;let{w:t,h:n}=y(),r=b(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=f.current;if(i===null)return;let{points:a,model:o}=g.current;if(i<0||i>=a.length)return;let{xToPx:s,yToPx:c}=x(t,n),u=o.radius[i],d=s(a.x[i]),p=c(a.y[i]);r.beginPath(),r.arc(d,p,u+2,0,Math.PI*2),r.strokeStyle=`rgba(255,255,255,0.9)`,r.lineWidth=2,r.stroke();let m=[],h=a.label?.(i);h&&m.push(h),m.push(`(${Mz(a.x[i])}, ${Mz(a.y[i])})`),m.push(`size=${Mz(a.size[i])}`);let _=a.colorIndex?.[i];_!==void 0&&_>=0&&a.colorLabels?m.push(a.colorLabels[_]):a.colorValue&&m.push(Mz(a.colorValue[i]));let v=m.join(` · `);r.font=`11px ${Q.mono}`;let S=r.measureText(v).width,C=Math.max(4,Math.min(t-S-8,d+u+4)),w=p-20<sY.top?p+u+4:p-20;r.fillStyle=`rgba(0,0,0,0.8)`,r.fillRect(C-3,w-3,S+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(v,C,w)}let T=K(C);T.current=C;let E=K(null);E.current??=EH(()=>T.current(),()=>u.current?.ownerDocument);let D=()=>E.current.schedule(),O=()=>{bH(p.current),p.current=yH(w)};return W(()=>{E.current.now()}),W(()=>()=>E.current?.cancel(),[]),W(()=>{d.current=null,D()},[i]),G(()=>{let e=u.current;if(!e)return;let t=new TH(()=>{d.current=null,D(),O()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=l.current;if(!e)return;let t=null,n=e=>{e.preventDefault(),m.current?.({clientX:e.clientX,clientY:e.clientY})},r=n=>{let r=e.getBoundingClientRect(),{points:i,maxRadius:a,model:o}=g.current,{w:s,h:c}=y(),{plotW:l,plotH:u,xToPx:d,yToPx:p}=x(s,c),m=e=>d(i.x[e])-sY.left,h=e=>p(i.y[e])-sY.top,_=a+6,v=`${s}|${c}|${_}`;(!t||t.model!==o||t.key!==v)&&(t={model:o,key:v,g:EJ(i.length,l,u,_,m,h)}),f.current=DJ(t.g,n.clientX-r.left-sY.left,n.clientY-r.top-sY.top,_,m,h,e=>o.radius[e]+6),O()},i=()=>{f.current=null,O()};return e.addEventListener(`contextmenu`,n),e.addEventListener(`mousemove`,r),e.addEventListener(`mouseleave`,i),()=>{e.removeEventListener(`contextmenu`,n),e.removeEventListener(`mousemove`,r),e.removeEventListener(`mouseleave`,i)}},[]),_t(`div`,{ref:u,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:s,className:`chart-canvas`,role:`img`,"aria-label":`Bubble chart`}),q(`canvas`,{ref:c,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),q(`canvas`,{ref:l,className:`chart-canvas chart-overlay`})]})}var hY={top:8,right:8,bottom:8,left:8},gY=[`#f97316`,`#38bdf8`,`#4ade80`,`#a78bfa`,`#fbbf24`,`#fb7185`,`#34d399`,`#e879f9`,`#facc15`,`#60a5fa`];function _Y(e){let t=new Map;for(let n of e){let e=n.parent??``;t.has(e)||t.set(e,[]),t.get(e).push(n)}function n(r,i){let a=(t.get(r)??[]).map(e=>n(e.name,i+1)),o=e.find(e=>e.name===r),s=a.reduce((e,t)=>e+t.value,0);return{name:r,value:o?Math.max(o.value,s):s,children:a,depth:i}}let r=new Set(e.map(e=>e.name));return e.filter(e=>!e.parent||!r.has(e.parent)).map(e=>n(e.name,0))}function vY(e,t,n,r,i,a){if(e.length===0||r<=0||i<=0||e.reduce((e,t)=>e+t.value,0)===0)return[];let o=[],s=[...e].sort((e,t)=>t.value-e.value),c=t,l=n,u=r,d=i;for(;s.length>0;){let e=u*d,t=s.reduce((e,t)=>e+t.value,0),n=e/t,r=[],i=1/0;for(let e=1;e<=s.length;e++){let a=s.slice(0,e),o=a.reduce((e,t)=>e+t.value,0)/t*(u<=d?d:u),c=0;for(let e of a){let t=e.value*n/o,r=Math.max(t/o,o/t);r>c&&(c=r)}if(c<i)i=c,r=a;else break}let f=r.reduce((e,t)=>e+t.value,0),p=u<=d,m=f/t*(p?d:u),h=0;for(let e of r){let t=e.value/f,n=p?u:t*u,r=p?t*d:d,i=p?c:c+h,s=p?l+h:l,g=p?m:n,_=p?r:m;if(o.push({node:e,x:i,y:s,w:g,h:_,depth:a}),e.children.length>0&&g>4&&_>4){let t=vY(e.children,i+1,s+1,g-2,_-2,a+1);for(let e of t)o.push(e)}h+=p?r:n}s=s.slice(r.length),p?(c+=m,u-=m):(l+=m,d-=m)}return o}function yY({nodes:e,backgroundToken:t=``,onPlotContextMenu:n}){let r=K(null),i=K(null),a=K(null),o=K(null),s=K([]),c=K(null),l=K(0),u=K(n);G(()=>{u.current=n},[n]);let d=K({nodes:e});G(()=>{d.current={nodes:e}},[e]);let f=dt(()=>_Y(e),[e]),p=K(f);G(()=>{p.current=f},[f]);function m(){if(o.current)return o.current;let e=a.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return o.current=n,n}function h(){let e=a.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||300)}}function g(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function _(){let e=r.current;if(!e)return;let{w:t,h:n}=h(),i=g(e,t,n);if(!i)return;let{bg:a,muted:o}=m(),{nodes:l}=d.current;if(i.fillStyle=a,i.fillRect(0,0,t,n),l.length===0){i.fillStyle=o,i.font=`13px ${Q.sans}`,i.textAlign=`left`,i.textBaseline=`top`,i.fillText(`No data`,hY.left+8,hY.top+8);return}let u=p.current,f=t-hY.left-hY.right,_=n-hY.top-hY.bottom,v=vY(u,hY.left,hY.top,f,_,0);s.current=v;for(let e=0;e<v.length;e++){let{node:t,x:n,y:r,w:o,h:s,depth:l}=v[e];if(o<2||s<2)continue;let u=gY[l%gY.length],d=c.current===e;if(i.fillStyle=u,i.globalAlpha=d?.95:.75,i.fillRect(n,r,o,s),i.globalAlpha=1,i.strokeStyle=a,i.lineWidth=1,i.strokeRect(n,r,o,s),o>20&&s>14){i.fillStyle=`rgba(0,0,0,0.75)`,i.font=`${Math.min(11,s-4)}px ${Q.mono}`,i.textAlign=`left`,i.textBaseline=`top`;let e=Math.floor((o-4)/6),a=t.name.length>e?t.name.slice(0,e-1)+`…`:t.name;i.fillText(a,n+3,r+3)}}i.globalAlpha=1}function v(){let e=i.current;if(!e)return;let{w:t,h:n}=h(),r=g(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let a=c.current;if(a===null)return;let o=s.current;if(a<0||a>=o.length)return;let{node:l,x:u,y:d,w:f,h:p}=o[a];r.strokeStyle=`rgba(255,255,255,0.9)`,r.lineWidth=2,r.strokeRect(u+1,d+1,f-2,p-2);let m=`${l.name}: ${l.value.toLocaleString()}`;r.font=`11px ${Q.mono}`;let _=r.measureText(m).width,v=Math.max(4,Math.min(t-_-8,u+f/2-_/2)),y=d<30?d+p+4:d-20;r.fillStyle=`rgba(0,0,0,0.8)`,r.fillRect(v-3,y-3,_+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(m,v,y)}let y=K(_);y.current=_;let b=K(null);b.current??=EH(()=>y.current(),()=>a.current?.ownerDocument);let x=()=>b.current.schedule(),S=()=>{bH(l.current),l.current=yH(v)};return W(()=>{b.current.now()}),W(()=>()=>b.current?.cancel(),[]),W(()=>{o.current=null,x()},[t]),G(()=>{let e=a.current;if(!e)return;let t=new TH(()=>{o.current=null,x(),S()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=i.current;if(!e)return;let t=e=>{e.preventDefault(),u.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),r=t.clientX-n.left,i=t.clientY-n.top,a=s.current,o=null;for(let e=0;e<a.length;e++){let t=a[e];r>=t.x&&r<=t.x+t.w&&i>=t.y&&i<=t.y+t.h&&(o=e)}c.current=o,S()},r=()=>{c.current=null,S()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),_t(`div`,{ref:a,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:r,className:`chart-canvas`,role:`img`,"aria-label":`Treemap`}),q(`canvas`,{ref:i,className:`chart-canvas chart-overlay`})]})}var bY={top:8,right:8,bottom:8,left:8},xY=14,SY=8,CY=[`#38bdf8`,`#4ade80`,`#fb7185`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`,`#facc15`,`#60a5fa`];function wY(e,t,n,r){if(e.length===0||t.length===0)return{nodes:[],links:[]};let i=n-bY.left-bY.right,a=r-bY.top-bY.bottom,o=new Map;for(let t of e)o.set(t,0);let s=!0;for(;s;){s=!1;for(let e of t){let t=o.get(e.source)??0;(o.get(e.target)??0)<=t&&(o.set(e.target,t+1),s=!0)}}let c=Math.max(0,...Array.from(o.values())),l=e=>bY.left+e/Math.max(1,c)*(i-xY),u=new Map;for(let[e,t]of o)u.has(t)||u.set(t,[]),u.get(t).push(e);let d=new Map;for(let t of e)d.set(t,0);for(let e of t)d.set(e.source,(d.get(e.source)??0)+e.value),d.set(e.target,(d.get(e.target)??0)+e.value);let f=Math.max(1,...Array.from(d.values())),p=new Map;for(let[t,n]of u){let r=a-(n.length-1)*SY,i=0;for(let e of n)i+=Math.max(8,(d.get(e)??0)/f*r*.8);let o=bY.top+(a-i-(n.length-1)*SY)/2;for(let i=0;i<n.length;i++){let a=n[i],s=Math.max(8,(d.get(a)??0)/f*r*.8);p.set(a,{name:a,x:l(t),y:o,h:s,color:CY[e.indexOf(a)%CY.length]}),o+=s+SY}}let m=new Map,h=new Map;for(let[e,t]of p)m.set(e,t.y),h.set(e,t.y);let g=[];for(let e of t){let t=p.get(e.source),n=p.get(e.target);if(!t||!n)continue;let r=Math.max(1,e.value/f*t.h),i=m.get(e.source)??t.y,a=h.get(e.target)??n.y;m.set(e.source,i+r),h.set(e.target,a+r),g.push({sx:t.x+xY,sy:i+r/2,tx:n.x,ty:a+r/2,h:r,color:t.color,label:`${e.source} → ${e.target}: ${e.value.toLocaleString()}`})}return{nodes:Array.from(p.values()),links:g}}function TY({nodeNames:e,links:t,backgroundToken:n=``,onPlotContextMenu:r}){let i=K(null),a=K(null),o=K(null),s=K(null),c=K({nodes:[],links:[]}),l=K(null),u=K(0),d=K(r);G(()=>{d.current=r},[r]);let f=K({nodeNames:e,links:t});G(()=>{f.current={nodeNames:e,links:t}},[e,t]);function p(){if(s.current)return s.current;let e=o.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return s.current=n,n}function m(){let e=o.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||300)}}function h(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function g(){let e=i.current;if(!e)return;let{w:t,h:n}=m(),r=h(e,t,n);if(!r)return;let{bg:a,muted:o}=p(),{nodeNames:s,links:u}=f.current;if(r.fillStyle=a,r.fillRect(0,0,t,n),s.length===0||u.length===0){r.fillStyle=o,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`No data — set source/target/value columns`,bY.left+8,bY.top+8);return}let d=wY(s,u,t,n);c.current=d;for(let e=0;e<d.links.length;e++){let t=d.links[e],n=l.current===e,i=(t.tx-t.sx)/2;r.beginPath(),r.moveTo(t.sx,t.sy-t.h/2),r.bezierCurveTo(t.sx+i,t.sy-t.h/2,t.tx-i,t.ty-t.h/2,t.tx,t.ty-t.h/2),r.lineTo(t.tx,t.ty+t.h/2),r.bezierCurveTo(t.tx-i,t.ty+t.h/2,t.sx+i,t.sy+t.h/2,t.sx,t.sy+t.h/2),r.closePath(),r.fillStyle=t.color,r.globalAlpha=n?.55:.3,r.fill()}r.globalAlpha=1;for(let e of d.nodes)r.fillStyle=e.color,r.globalAlpha=.9,r.fillRect(e.x,e.y,xY,e.h),r.globalAlpha=1,r.fillStyle=o,r.font=`9px ${Q.mono}`,r.textBaseline=`middle`,e.x>t/2?(r.textAlign=`right`,r.fillText(e.name,e.x-3,e.y+e.h/2)):(r.textAlign=`left`,r.fillText(e.name,e.x+xY+3,e.y+e.h/2));r.globalAlpha=1}function _(){let e=a.current;if(!e)return;let{w:t,h:n}=m(),r=h(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=l.current;if(i===null)return;let o=c.current;if(i<0||i>=o.links.length)return;let s=o.links[i],u=s.label;r.font=`11px ${Q.mono}`;let d=r.measureText(u).width,f=Math.max(4,Math.min(t-d-8,(s.sx+s.tx)/2-d/2)),p=Math.max(4,(s.sy+s.ty)/2-10);r.fillStyle=`rgba(0,0,0,0.8)`,r.fillRect(f-3,p-3,d+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(u,f,p)}let v=K(g);v.current=g;let y=K(null);y.current??=EH(()=>v.current(),()=>o.current?.ownerDocument);let b=()=>y.current.schedule(),x=()=>{bH(u.current),u.current=yH(_)};return W(()=>{y.current.now()}),W(()=>()=>y.current?.cancel(),[]),W(()=>{s.current=null,b()},[n]),G(()=>{let e=o.current;if(!e)return;let t=new TH(()=>{s.current=null,b(),x()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=a.current;if(!e)return;let t=e=>{e.preventDefault(),d.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),r=t.clientX-n.left,i=t.clientY-n.top,a=c.current,o=null;for(let e=0;e<a.links.length;e++){let t=a.links[e];if(r>=t.sx&&r<=t.tx&&Math.abs(i-(t.sy+t.ty)/2)<t.h/2+6){o=e;break}}l.current=o,x()},r=()=>{l.current=null,x()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),_t(`div`,{ref:o,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:i,className:`chart-canvas`,role:`img`,"aria-label":`Sankey diagram`}),q(`canvas`,{ref:a,className:`chart-canvas chart-overlay`})]})}var EY={top:24,right:24,bottom:52,left:52};function DY({bins:e,color:t=`#38bdf8`,backgroundToken:n=``,onPlotContextMenu:r}){let i=K(null),a=K(null),o=K(null),s=K(null),c=K(null),l=K(0),u=K(r);G(()=>{u.current=r},[r]);let d=K({bins:e,color:t});G(()=>{d.current={bins:e,color:t}},[e,t]);function f(){if(s.current)return s.current;let e=o.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return s.current=n,n}function p(){let e=o.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||300)}}function m(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function h(){let e=i.current;if(!e)return;let{w:t,h:n}=p(),r=m(e,t,n);if(!r)return;let{bg:a,muted:o,grid:s}=f(),{bins:l,color:u}=d.current;if(r.fillStyle=a,r.fillRect(0,0,t,n),l.length===0){r.fillStyle=o,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`No data`,EY.left+8,EY.top+8);return}let{top:h,right:g,bottom:_,left:v}=EY,y=t-v-g,b=n-h-_,x=e=>v+e*y,S=e=>h+(1-e)*b;for(let e=0;e<=5;e++){let t=e/5;r.strokeStyle=s,r.lineWidth=1,r.beginPath(),r.moveTo(v,S(t)),r.lineTo(v+y,S(t)),r.stroke(),r.beginPath(),r.moveTo(x(t),h),r.lineTo(x(t),h+b),r.stroke(),r.fillStyle=o,r.font=`9px ${Q.mono}`,r.textAlign=`right`,r.textBaseline=`middle`,r.fillText(t.toFixed(2),v-4,S(t)),r.textAlign=`center`,r.textBaseline=`top`,r.fillText(t.toFixed(2),x(t),h+b+4)}r.strokeStyle=o,r.lineWidth=1.5,r.setLineDash([6,4]),r.beginPath(),r.moveTo(x(0),S(0)),r.lineTo(x(1),S(1)),r.stroke(),r.setLineDash([]);let C=Math.max(1,...l.map(e=>e.count)),w=b*.15;for(let e of l){let t=Math.max(1,y/l.length*.7),n=x(e.center)-t/2,i=e.count/C*w;r.fillStyle=u,r.globalAlpha=.3,r.fillRect(n,h+b-i,t,i)}r.globalAlpha=1,r.beginPath();for(let e=0;e<l.length;e++){let t=x(l[e].center),n=S(l[e].actual);e===0?r.moveTo(t,n):r.lineTo(t,n)}r.strokeStyle=u,r.lineWidth=1,r.stroke();for(let e=0;e<l.length;e++){let t=c.current===e;r.beginPath(),r.arc(x(l[e].center),S(l[e].actual),t?6:4,0,Math.PI*2),r.fillStyle=u,r.globalAlpha=t?1:.85,r.fill()}r.globalAlpha=1,r.fillStyle=o,r.font=`10px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`bottom`,r.fillText(`Predicted probability`,v+y/2,n-4),r.save(),r.translate(12,h+b/2),r.rotate(-Math.PI/2),r.textAlign=`center`,r.textBaseline=`middle`,r.fillText(`Actual rate`,0,0),r.restore()}function g(){let e=a.current;if(!e)return;let{w:t,h:n}=p(),r=m(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=c.current;if(i===null)return;let{bins:o}=d.current;if(i<0||i>=o.length)return;let s=o[i],{top:l,left:u}=EY,f=t-u-EY.right,h=n-l-EY.bottom,g=u+s.center*f,_=l+(1-s.actual)*h,v=`pred=${s.center.toFixed(2)} actual=${s.actual.toFixed(3)} n=${s.count}`;r.font=`11px ${Q.mono}`;let y=r.measureText(v).width,b=Math.max(4,Math.min(t-y-8,g-y/2)),x=_-28<l?_+12:_-24;r.fillStyle=`rgba(0,0,0,0.8)`,r.fillRect(b-3,x-3,y+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(v,b,x)}let _=K(h);_.current=h;let v=K(null);v.current??=EH(()=>_.current(),()=>o.current?.ownerDocument);let y=()=>v.current.schedule(),b=()=>{bH(l.current),l.current=yH(g)};return W(()=>{v.current.now()}),W(()=>()=>v.current?.cancel(),[]),W(()=>{s.current=null,y()},[n]),G(()=>{let e=o.current;if(!e)return;let t=new TH(()=>{s.current=null,y(),b()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=a.current;if(!e)return;let t=e=>{e.preventDefault(),u.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),{bins:r}=d.current,{w:i}=p(),a=t.clientX-n.left,o=i-EY.left-EY.right,s=-1,l=20;for(let e=0;e<r.length;e++){let t=EY.left+r[e].center*o,n=Math.abs(a-t);n<l&&(l=n,s=e)}c.current=s>=0?s:null,b()},r=()=>{c.current=null,b()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),_t(`div`,{ref:o,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:i,className:`chart-canvas`,role:`img`,"aria-label":`Calibration curve`}),q(`canvas`,{ref:a,className:`chart-canvas chart-overlay`})]})}var OY={top:24,right:24,bottom:48,left:52};function kY({points:e,color:t=`#a78bfa`,backgroundToken:n=``,onPlotContextMenu:r}){let i=eU(),a=K(null),o=K(null),s=K(null),c=K(null),l=K(null),u=K(0),d=K(r);G(()=>{d.current=r},[r]);let f=K({points:e,color:t});G(()=>{f.current={points:e,color:t}},[e,t]);function p(){if(c.current)return c.current;let e=s.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return c.current=n,n}function m(){let e=s.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||300)}}function h(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function g(){let{points:e}=f.current,t=1/0,n=-1/0,r=1/0,i=-1/0;if(e.length>0&&(t=e.theoretical[0],n=e.theoretical[e.length-1],r=e.sample[0],i=e.sample[e.length-1]),!Number.isFinite(t))return{xLo:-3,xHi:3,yLo:-3,yHi:3};let a=(n-t)*.05||.5,o=(i-r)*.05||.5;return{xLo:t-a,xHi:n+a,yLo:r-o,yHi:i+o}}function _(){let e=a.current;if(!e)return;let{w:t,h:n}=m(),r=h(e,t,n);if(!r)return;let{bg:o,muted:s,grid:c}=p(),{points:u,color:d}=f.current;if(r.fillStyle=o,r.fillRect(0,0,t,n),u.length===0){r.fillStyle=s,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`No data`,OY.left+8,OY.top+8);return}let{xLo:_,xHi:v,yLo:y,yHi:b}=g(),{top:x,right:S,bottom:C,left:w}=OY,T=t-w-S,E=n-x-C,D=e=>w+(e-_)/(v-_)*T,O=e=>x+(1-(e-y)/(b-y))*E;i({left:w,top:x,width:T,height:E,x:{v0:_,v1:v}}),r.strokeStyle=c,r.lineWidth=1;for(let e=0;e<=5;e++){let t=_+e/5*(v-_),n=D(t);r.beginPath(),r.moveTo(n,x),r.lineTo(n,x+E),r.stroke(),r.fillStyle=s,r.font=`9px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`top`,r.fillText(jz(t,(v-_)/5),n,x+E+4);let i=y+e/5*(b-y),a=O(i);r.beginPath(),r.moveTo(w,a),r.lineTo(w+T,a),r.stroke(),r.fillStyle=s,r.textAlign=`right`,r.textBaseline=`middle`,r.fillText(jz(i,(b-y)/5),w-4,a)}let k=Math.max(_,y),A=Math.min(v,b);k<A&&(r.strokeStyle=s,r.lineWidth=1.5,r.setLineDash([6,4]),r.beginPath(),r.moveTo(D(k),O(k)),r.lineTo(D(A),O(A)),r.stroke(),r.setLineDash([])),r.fillStyle=d,r.globalAlpha=.75;let j=NaN,M=NaN;for(let e=0;e<u.length;e++){let t=Math.round(D(u.theoretical[e])),n=Math.round(O(u.sample[e]));t===j&&n===M||(j=t,M=n,r.beginPath(),r.arc(t,n,3,0,Math.PI*2),r.fill())}let N=l.current;N!==null&&N<u.length&&(r.globalAlpha=1,r.beginPath(),r.arc(D(u.theoretical[N]),O(u.sample[N]),5,0,Math.PI*2),r.fill()),r.globalAlpha=1,r.fillStyle=s,r.font=`10px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`bottom`,r.fillText(`Theoretical quantiles`,w+T/2,n-4),r.save(),r.translate(12,x+E/2),r.rotate(-Math.PI/2),r.textAlign=`center`,r.textBaseline=`middle`,r.fillText(`Sample quantiles`,0,0),r.restore()}function v(){let e=o.current;if(!e)return;let{w:t,h:n}=m(),r=h(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=l.current;if(i===null)return;let{points:a}=f.current;if(i<0||i>=a.length)return;let s={theoretical:a.theoretical[i],sample:a.sample[i]},{xLo:c,xHi:u,yLo:d,yHi:p}=g(),{top:_,left:v}=OY,y=t-v-OY.right,b=n-_-OY.bottom,x=v+(s.theoretical-c)/(u-c)*y,S=_+(1-(s.sample-d)/(p-d))*b;r.beginPath(),r.arc(x,S,6,0,Math.PI*2),r.strokeStyle=`rgba(255,255,255,0.9)`,r.lineWidth=2,r.stroke();let C=`(${Mz(s.theoretical)}, ${Mz(s.sample)})`;r.font=`11px ${Q.mono}`;let w=r.measureText(C).width,T=Math.max(4,Math.min(t-w-8,x+10)),E=S-20<_?S+10:S-20;r.fillStyle=`rgba(0,0,0,0.8)`,r.fillRect(T-3,E-3,w+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(C,T,E)}let y=K(_);y.current=_;let b=K(null);b.current??=EH(()=>y.current(),()=>s.current?.ownerDocument);let x=()=>b.current.schedule(),S=()=>{bH(u.current),u.current=yH(v)};return W(()=>{b.current.now()}),W(()=>()=>b.current?.cancel(),[]),W(()=>{c.current=null,x()},[n]),G(()=>{let e=s.current;if(!e)return;let t=new TH(()=>{c.current=null,x(),S()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=o.current;if(!e)return;let t=e=>{e.preventDefault(),d.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),{points:r}=f.current,{w:i}=m(),{xLo:a,xHi:o,yLo:s,yHi:c}=g(),{top:u,left:d}=OY,p=i-d-OY.right,h=n.height-u-OY.bottom,_=t.clientX-n.left,v=t.clientY-n.top,y=e=>a+(e-d)/p*(o-a),b=e=>{let t=0,n=r.length;for(;t<n;){let i=t+n>>>1;r.theoretical[i]<e?t=i+1:n=i}return t},x=b(y(_-10)),C=Math.min(r.length,b(y(_+10))+1),w=-1,T=10**2;for(let e=x;e<C;e++){let t=d+(r.theoretical[e]-a)/(o-a)*p,n=u+(1-(r.sample[e]-s)/(c-s))*h,i=(_-t)**2+(v-n)**2;i<T&&(T=i,w=e)}l.current=w>=0?w:null,S()},r=()=>{l.current=null,S()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),_t(`div`,{ref:s,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:a,className:`chart-canvas`,role:`img`,"aria-label":`Q-Q plot`}),q(`canvas`,{ref:o,className:`chart-canvas chart-overlay`})]})}var AY={top:8,right:16,bottom:40,left:120},jY=22,MY=3,NY=[`#38bdf8`,`#4ade80`,`#fb7185`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`,`#facc15`,`#60a5fa`];function PY({tasks:e,backgroundToken:t=``,onPlotContextMenu:n}){let r=eU(),i=K(null),a=K(null),o=K(null),s=K(null),c=K(null),l=K(0),u=K(n);G(()=>{u.current=n},[n]);let d=K({tasks:e});G(()=>{d.current={tasks:e}},[e]);function f(){if(s.current)return s.current;let e=o.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return s.current=n,n}function p(){let e=o.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||300)}}function m(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function h(){let e=i.current;if(!e)return;let{w:t,h:n}=p(),a=m(e,t,n);if(!a)return;let{bg:o,muted:s,grid:l}=f(),{tasks:u}=d.current;if(a.fillStyle=o,a.fillRect(0,0,t,n),u.length===0){a.fillStyle=s,a.font=`13px ${Q.sans}`,a.textAlign=`left`,a.textBaseline=`top`,a.fillText(`No data`,AY.left+8,AY.top+8);return}let h=1/0,g=-1/0;for(let e of u)e.start<h&&(h=e.start),e.end>g&&(g=e.end);Number.isFinite(h)||(h=0,g=1);let _=(g-h)*.02||1;h-=_,g+=_;let{top:v,right:y,bottom:b,left:x}=AY,S=t-x-y,C=e=>x+(e-h)/(g-h)*S;r({left:x,top:v,width:S,height:n-v-b,x:{v0:h,v1:g}});let w=new Map;for(let e of u){let t=e.group??e.label;w.has(t)||w.set(t,w.size)}let T=Math.min(8,Math.floor(S/60));a.strokeStyle=l,a.lineWidth=1;for(let e=0;e<=T;e++){let t=h+e/T*(g-h),n=C(t),r=u.length*(jY+MY)+v;a.beginPath(),a.moveTo(n,v),a.lineTo(n,r),a.stroke(),a.fillStyle=s,a.font=`9px ${Q.mono}`,a.textAlign=`center`,a.textBaseline=`top`,a.fillText(jz(t,(g-h)/T),n,r+4)}for(let e=0;e<u.length;e++){let t=u[e],n=v+e*(jY+MY),r=NY[(w.get(t.group??t.label)??0)%NY.length],i=c.current===e,o=C(t.start),l=C(t.end),d=Math.max(2,l-o);a.fillStyle=r,a.globalAlpha=i?.95:.75,a.fillRect(o,n,d,jY-MY),a.globalAlpha=1,a.fillStyle=s,a.font=`9px ${Q.mono}`,a.textAlign=`right`,a.textBaseline=`middle`;let f=t.label.length>16?t.label.slice(0,15)+`…`:t.label;a.fillText(f,x-4,n+(jY-MY)/2)}a.globalAlpha=1}function g(){let e=a.current;if(!e)return;let{w:t,h:n}=p(),r=m(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=c.current;if(i===null)return;let{tasks:o}=d.current;if(i<0||i>=o.length)return;let s=o[i],l=s.end-s.start,u=`${s.label}: ${Mz(s.start)} → ${Mz(s.end)} (${Mz(l)})`;r.font=`11px ${Q.mono}`;let f=r.measureText(u).width,h=1/0,g=-1/0;for(let e of o)e.start<h&&(h=e.start),e.end>g&&(g=e.end);let _=(g-h)*.02||1;h-=_,g+=_;let v=t-AY.left-AY.right,y=e=>AY.left+(e-h)/(g-h)*v,b=AY.top+i*(jY+MY),x=(y(s.start)+y(s.end))/2,S=Math.max(4,Math.min(t-f-8,x-f/2)),C=b-22<AY.top?b+jY+4:b-20;r.fillStyle=`rgba(0,0,0,0.8)`,r.fillRect(S-3,C-3,f+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(u,S,C)}let _=K(h);_.current=h;let v=K(null);v.current??=EH(()=>_.current(),()=>o.current?.ownerDocument);let y=()=>v.current.schedule(),b=()=>{bH(l.current),l.current=yH(g)};return W(()=>{v.current.now()}),W(()=>()=>v.current?.cancel(),[]),W(()=>{s.current=null,y()},[t]),G(()=>{let e=o.current;if(!e)return;let t=new TH(()=>{s.current=null,y(),b()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=a.current;if(!e)return;let t=e=>{e.preventDefault(),u.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),{tasks:r}=d.current,i=t.clientY-n.top,a=Math.floor((i-AY.top)/(jY+MY));c.current=a>=0&&a<r.length?a:null,b()},r=()=>{c.current=null,b()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),_t(`div`,{ref:o,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:i,className:`chart-canvas`,role:`img`,"aria-label":`Gantt chart`}),q(`canvas`,{ref:a,className:`chart-canvas chart-overlay`})]})}var FY=e=>[...e].filter(e=>Number.isFinite(e.at)).sort((e,t)=>e.at-t.at),IY=e=>{let t=/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})/i.exec(e);return t?[parseInt(t[1],16),parseInt(t[2],16),parseInt(t[3],16)]:[128,128,128]},LY=e=>`#${e.map(e=>Math.round(e).toString(16).padStart(2,`0`)).join(``)}`;function RY(e,t,n,r){let i=t?FY(t):[];if(!e||e===`solid`||i.length===0||!Number.isFinite(r))return n;if(e===`zones`){let e=i[0].color;for(let t of i)r>=t.at&&(e=t.color);return e}if(r<=i[0].at)return i[0].color;if(r>=i[i.length-1].at)return i[i.length-1].color;let a=0;for(;i[a+1].at<r;)a++;let o=i[a],s=i[a+1],c=(r-o.at)/(s.at-o.at||1),l=IY(o.color),u=IY(s.color);return LY([l[0]+(u[0]-l[0])*c,l[1]+(u[1]-l[1])*c,l[2]+(u[2]-l[2])*c])}function zY(e,t,n,r,i,a=96){let o=i-r||1,s=t?FY(t):[];if(!e||e===`solid`||s.length===0)return[{f0:0,f1:1,color:n}];if(e===`zones`){let e=[0,...s.slice(1).map(e=>(e.at-r)/o).filter(e=>e>0&&e<1),1];return e.slice(0,-1).map((t,i)=>({f0:t,f1:e[i+1],color:RY(`zones`,s,n,r+(t+e[i+1])/2*o)}))}return Array.from({length:a},(e,t)=>({f0:t/a,f1:(t+1)/a,color:RY(`gradient`,s,n,r+(t+.5)/a*o)}))}function BY(e,t,n){let r=e=>+(t+e*(n-t)).toPrecision(6),i=`#22c55e`,a=`#ef4444`;if(e===`traffic`)return{mode:`zones`,stops:[{at:r(0),color:i},{at:r(.7),color:`#f5a524`},{at:r(.9),color:a}]};let o=[{at:r(0),color:i},{at:r(.5),color:`#eab308`},{at:r(1),color:a}];return{mode:`gradient`,stops:e===`green-red`?o:o.map((e,t)=>({...e,color:o[o.length-1-t].color}))}}function VY(e,t,n){let r=t?FY(t):[];if(!e||e===`solid`||r.length===0)return n;let i=r[0].at,a=r[r.length-1].at,o=e=>`${((e-i)/(a-i||1)*100).toFixed(1)}%`;if(e===`gradient`)return`linear-gradient(90deg, ${r.map(e=>`${e.color} ${o(e.at)}`).join(`, `)})`;let s=100/r.length;return`linear-gradient(90deg, ${r.map((e,t)=>`${e.color} ${(t*s).toFixed(1)}% ${((t+1)*s).toFixed(1)}%`).join(`, `)})`}var HY=.75*Math.PI,UY=1.5*Math.PI;function WY({gauges:e,live:t,backgroundToken:n=``,onPlotContextMenu:r}){let i=K(null),a=K(null),o=K(null),s=K(r);G(()=>{s.current=r},[r]);let c=K({gauges:e,live:t});G(()=>{c.current={gauges:e,live:t}},[e,t]);let l=K(LH()),u=K(0);function d(){if(o.current)return o.current;let e=a.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`,ink:`#e4e4e7`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`,ink:t.getPropertyValue(`--chart-fg`).trim()||`#e4e4e7`};return o.current=n,n}function f(){let e=i.current,t=a.current;if(!e||!t)return;let n=Math.max(1,t.clientWidth),r=Math.max(1,t.clientHeight),o=Math.min(2,window.devicePixelRatio||1),s=Math.floor(n*o),f=Math.floor(r*o);(e.width!==s||e.height!==f)&&(e.width=s,e.height=f),e.style.width=`${n}px`,e.style.height=`${r}px`;let p=e.getContext(`2d`);if(!p)return;p.setTransform(o,0,0,o,0,0);let h=d(),{gauges:g,live:_}=c.current,v=g;if(_){let e=performance.now(),t=WH(l.current,_.latestT(),e-u.current);u.current=e,v=g.map(e=>{if((e.stat??`last`)!==`last`)return e;let n=_.valueAt(e.name,t);return Number.isFinite(n)?{...e,value:n}:e}),m.current.schedule()}if(p.fillStyle=h.bg,p.fillRect(0,0,n,r),v.length===0){p.fillStyle=h.muted,p.font=`13px ${Q.sans}`,p.textAlign=`left`,p.textBaseline=`top`,p.fillText(`No data`,16,16);return}let{cols:y,rows:b}=GY(v.length,n,r,v.some(e=>e.style===`arc`)?1.15:3.2),x=n/y,S=r/b;v.forEach((e,t)=>{let n=t%y*x,r=Math.floor(t/y)*S;e.style===`arc`?tX(p,e,n,r,x,S,e.color,e.alarm??null,h):nX(p,e,n,r,x,S,e.color,e.alarm??null,h)})}let p=K(f);p.current=f;let m=K(null);return m.current??=EH(()=>p.current(),()=>a.current?.ownerDocument),W(()=>{m.current.now()}),W(()=>()=>m.current?.cancel(),[]),W(()=>{o.current=null,m.current.schedule()},[n]),G(()=>{let e=a.current;if(!e)return;let t=new TH(()=>{o.current=null,m.current.schedule()});return t.observe(e),()=>t.disconnect()},[]),q(`div`,{ref:a,style:{position:`relative`,width:`100%`,height:`100%`},children:q(`canvas`,{ref:i,className:`chart-canvas`,role:`img`,"aria-label":`Gauges: ${e.map(e=>`${e.name} ${Number.isFinite(e.value)?KY(e.value,e.max-e.min):`no value`}${e.unit?` ${e.unit}`:``}`).join(`, `)}`,onContextMenu:e=>{e.preventDefault(),s.current?.({clientX:e.clientX,clientY:e.clientY})}})})}function GY(e,t,n,r){let i={cols:1,rows:e,size:-1};for(let a=1;a<=e;a++){let o=Math.ceil(e/a),s=t/a,c=n/o,l=Math.min(s,c*r);l>i.size&&(i={cols:a,rows:o,size:l})}return{cols:i.cols,rows:i.rows}}var KY=(e,t)=>jz(e,wz(Math.abs(t),100)),qY=(e,t)=>Math.max(0,Math.min(1,(t-e.min)/(e.max-e.min||1))),JY=(e,t)=>{let n=e.fromZero?qY(e,0):0;return[Math.min(n,t),Math.max(n,t)]},YY=(e,t)=>!!t&&(t.linked?t.linked===`active`:Number.isFinite(e.value)&&e.value>=t.value),XY=e=>(e.colorMode===`gradient`||e.colorMode===`zones`)&&!!e.stops?.length,ZY=(e,t)=>YY(e,t)?t.color:RY(e.colorMode,e.stops,e.color,e.value);function QY(e,t,n){for(let r of zY(t.colorMode,t.stops,t.color,t.min,t.max))e.addColorStop(n(r.f0),r.color),e.addColorStop(n(r.f1),r.color);return e}function $Y(e,t,n){if(e.measureText(t).width<=n)return t;let r=t;for(;r.length>1&&e.measureText(`${r}…`).width>n;)r=r.slice(0,-1);return n>0?`${r}…`:``}var eX=Math.SQRT1_2;function tX(e,t,n,r,i,a,o,s,c){let l=Math.max(6,Math.min(i,a)*.06),u=t.max-t.min,d=KY(t.min,u),f=KY(t.max,u),p=e=>Math.max(9,Math.min(22,e*.1)),m=e=>Math.max(4,e*.13),h=Math.max(8,Math.min((i-2*l)/2,(a-2*l)/1.9)),g=0;for(let t=0;t<2;t++){e.font=`${p(h)}px ${Q.mono}`,g=Math.max(e.measureText(d).width,e.measureText(f).width);let t=m(h),n=Math.max(h+t/2,eX*h+g/2),r=h+t/2+eX*h+t/2+6+p(h)*1.2;h=Math.max(8,Math.min(h*(i-2*l)/(2*n),h*(a-2*l)/r))}let _=m(h),v=p(h),y=h+_/2+eX*h+_/2+6+v*1.2,b=n+i/2,x=r+l+h+_/2+Math.max(0,(a-2*l-y)/2),S=e=>HY+e*UY;e.lineCap=`round`,e.lineWidth=_,e.strokeStyle=c.grid,e.beginPath(),e.arc(b,x,h,HY,HY+UY),e.stroke(),s&&s.value<t.max&&(e.globalAlpha=.3,e.strokeStyle=s.color,e.lineCap=`butt`,e.beginPath(),e.arc(b,x,h,S(qY(t,s.value)),HY+UY),e.stroke(),e.globalAlpha=1,e.lineCap=`round`);let[C,w]=JY(t,Number.isFinite(t.value)?qY(t,t.value):0),T=()=>{e.lineCap=t.fromZero?`butt`:`round`,e.beginPath(),e.arc(b,x,h,S(C),Math.max(S(C)+1e-4,S(w))),e.stroke(),e.lineCap=`round`};if(XY(t)){let n=UY/(2*Math.PI),r=QY(e.createConicGradient(HY,b,x),t,e=>e*n);r.addColorStop(1,RY(t.colorMode,t.stops,t.color,t.min)),e.strokeStyle=r,e.globalAlpha=.24,e.beginPath(),e.arc(b,x,h,HY,HY+UY),e.stroke(),e.globalAlpha=1,Number.isFinite(t.value)&&!YY(t,s)&&T()}if(Number.isFinite(t.value)&&(!XY(t)||YY(t,s))&&(e.strokeStyle=YY(t,s)?s.color:o,T()),t.fromZero&&t.min<0&&t.max>0){let n=S(qY(t,0));e.strokeStyle=c.muted,e.lineWidth=1.5,e.lineCap=`butt`,e.beginPath(),e.moveTo(b+Math.cos(n)*(h-_*.75),x+Math.sin(n)*(h-_*.75)),e.lineTo(b+Math.cos(n)*(h+_*.75),x+Math.sin(n)*(h+_*.75)),e.stroke(),e.lineWidth=_,e.lineCap=`round`}if(s&&s.value>=t.min&&s.value<=t.max){let n=S(qY(t,s.value));e.strokeStyle=s.color,e.lineWidth=Math.max(1.5,s.width),e.lineCap=`butt`,e.beginPath(),e.moveTo(b+Math.cos(n)*(h-_*.9),x+Math.sin(n)*(h-_*.9)),e.lineTo(b+Math.cos(n)*(h+_*.9),x+Math.sin(n)*(h+_*.9)),e.stroke();let r=h+_*.9+10*.7;s.linked&&iU(e,b+Math.cos(n)*r-10/2,x+Math.sin(n)*r-10/2,s.color)}let E=Number.isFinite(t.value)?KY(t.value,u):`—`,D=2*(h-_)*.82,O=Math.max(11,h*.42);e.font=`650 ${O}px ${Q.sans}`;let k=e.measureText(E).width;k>D&&(O=Math.max(9,O*D/k),e.font=`650 ${O}px ${Q.sans}`),e.textAlign=`center`,e.textBaseline=`alphabetic`,e.fillStyle=YY(t,s)||XY(t)?ZY(t,s):c.ink,e.fillText(E,b,x+O*.32),e.fillStyle=c.muted,t.unit&&(e.font=`600 ${Math.max(9,h*.13)}px ${Q.sans}`,e.fillText($Y(e,t.unit,D),b,x+O*.32+Math.max(11,h*.19)));let A=x+eX*h+_/2+6,j=eX*h;e.textBaseline=`top`,e.font=`${v}px ${Q.mono}`,e.fillText(d,b-j,A),e.fillText(f,b+j,A);let M=2*j-g-16,N=Math.max(10,Math.min(26,h*.13));e.font=`600 ${N}px ${Q.sans}`;let P=e.measureText(t.name).width;P>M&&N>9&&(N=Math.max(9,N*M/P),e.font=`600 ${N}px ${Q.sans}`),e.fillText($Y(e,t.name,M),b,A+(v-N)/2)}function nX(e,t,n,r,i,a,o,s,c){let l=Math.max(14,i*.06),u=n+l,d=n+i-l,f=d-u,p=Math.max(6,Math.min(16,a*.14)),m=Math.max(12,Math.min(34,a*.28)),h=r+a/2+m*.35,g=e=>u+qY(t,e)*f;e.textBaseline=`alphabetic`,e.fillStyle=c.muted,e.font=`600 ${Math.max(10,m*.42)}px ${Q.sans}`,e.textAlign=`left`,e.fillText($Y(e,t.name,f),u,h-p/2-m-4),e.textAlign=`right`,e.fillStyle=YY(t,s)?s.color:c.ink,e.font=`650 ${m}px ${Q.sans}`;let _=t.unit?(e.font=`600 ${Math.max(9,m*.4)}px ${Q.sans}`,e.measureText(` ${t.unit}`).width):0;t.unit&&(e.fillStyle=c.muted,e.fillText(` ${t.unit}`,d,h-p/2-8)),e.fillStyle=YY(t,s)||XY(t)?ZY(t,s):c.ink,e.font=`650 ${m}px ${Q.sans}`,e.fillText(Number.isFinite(t.value)?KY(t.value,t.max-t.min):`—`,d-_,h-p/2-8),e.lineCap=`round`,e.lineWidth=p,e.strokeStyle=c.grid,e.beginPath(),e.moveTo(u,h),e.lineTo(d,h),e.stroke(),s&&s.value<t.max&&(e.globalAlpha=.3,e.strokeStyle=s.color,e.lineCap=`butt`,e.beginPath(),e.moveTo(g(s.value),h),e.lineTo(d,h),e.stroke(),e.globalAlpha=1,e.lineCap=`round`);let v=Number.isFinite(t.value)?qY(t,t.value):0,y=e=>u+e*f,[b,x]=JY(t,v),S=()=>{e.lineCap=t.fromZero?`butt`:`round`,e.beginPath(),e.moveTo(y(b),h),e.lineTo(Math.max(y(b)+.5,y(x)),h),e.stroke(),e.lineCap=`round`};XY(t)&&(e.strokeStyle=QY(e.createLinearGradient(u,0,d,0),t,e=>e),e.globalAlpha=.24,e.beginPath(),e.moveTo(u,h),e.lineTo(d,h),e.stroke(),e.globalAlpha=1,Number.isFinite(t.value)&&!YY(t,s)&&S()),Number.isFinite(t.value)&&(!XY(t)||YY(t,s))&&(e.strokeStyle=YY(t,s)?s.color:o,S()),t.fromZero&&t.min<0&&t.max>0&&(e.strokeStyle=c.muted,e.lineWidth=1.5,e.lineCap=`butt`,e.beginPath(),e.moveTo(g(0),h-p*.75),e.lineTo(g(0),h+p*.75),e.stroke(),e.lineWidth=p,e.lineCap=`round`),s&&s.value>=t.min&&s.value<=t.max&&(e.strokeStyle=s.color,e.lineWidth=Math.max(1.5,s.width),e.lineCap=`butt`,e.beginPath(),e.moveTo(g(s.value),h-p),e.lineTo(g(s.value),h+p),e.stroke(),s.linked&&iU(e,g(s.value)-10/2,h-p-10-2,s.color)),e.fillStyle=c.muted,e.font=`${Math.max(9,m*.34)}px ${Q.mono}`,e.textBaseline=`top`,e.textAlign=`left`,e.fillText(KY(t.min,t.max-t.min),u,h+p/2+4),e.textAlign=`right`,e.fillText(KY(t.max,t.max-t.min),d,h+p/2+4)}var rX=720;function iX(e,t){return t?e<rX:e<640}function aX(e){return e<=1?{cols:1,rows:1}:e===2?{cols:2,rows:1}:e<=4?{cols:2,rows:2}:{cols:3,rows:3}}function oX(e,t){return e.flatMap(e=>{let n=e.info?.meta;if(!n?.recordingId)return[];let r=n.wallOrigin?Number(n.wallOrigin):NaN,i=n.wallQuality;return[{recordingId:n.recordingId,wallOrigin:Number.isFinite(r)?r:null,wallQuality:i===`exact`||i===`approx`?i:null,xOffset:t[e.id]??0}]})}var sX={get:()=>null,subscribe:()=>()=>{}};function cX(e){let[t,n]=ft(null);return G(()=>{let t=e.current;if(!t)return;let r=e=>n(t=>iX(e,t??!1));if(r(t.clientWidth),typeof ResizeObserver>`u`)return;let i=new ResizeObserver(e=>{for(let t of e)r(t.contentRect.width)});return i.observe(t),()=>i.disconnect()},[e]),t}function lX(e){let t=Wn(e.settings),[n,r]=ft(null),[i,a]=ft(null),o=K(null);W(()=>{i&&o.current?.querySelector(`[data-camera="${CSS.escape(i)}"]`)?.focus()},[i]);let s=e.recordings??[],c=e=>s.findIndex(t=>t.recordingId===e.recordingId),l=(e.video??[]).filter(e=>e.kind===`recorded`&&c(e)>=0).sort((e,t)=>c(e)-c(t)),u=e.onContextMenu?t=>{t.preventDefault(),e.onContextMenu({clientX:t.clientX,clientY:t.clientY})}:void 0;if(!t.length){let t=[...new Set([...e.live.filter(e=>e.kind===`camera`&&!e.lowOf),...l].map(t=>Vn(t,e.live)))].sort();return q(dX,{onContextMenu:u,title:`Choose a camera in this panel's settings`,detail:t.length?t.join(`, `):void 0})}let d={panel:e,recorded:l,recIndex:c};if(t.length===1)return q(uX,{...d,id:t[0],onMenu:u});let f=n&&t.includes(n)?n:null,p=f?[f]:t,{cols:m,rows:h}=aX(p.length),g=()=>{a(f),r(null)};return _t(`div`,{ref:o,className:`kymo-camera-wall`,style:{gridTemplateColumns:`repeat(${m}, minmax(0, 1fr))`,gridTemplateRows:`repeat(${h}, minmax(0, 1fr))`},onContextMenu:u,onKeyDown:e=>{e.key===`Escape`&&f&&(e.stopPropagation(),g())},children:[p.map(e=>q(uX,{...d,id:e,multi:!0,wall:!f,onPick:f?void 0:()=>{a(null),r(e)}},e)),f?_t(`button`,{type:`button`,className:`kymo-camera__all`,onClick:g,autoFocus:!0,children:[_t(`svg`,{viewBox:`0 0 16 16`,"aria-hidden":`true`,children:[q(`rect`,{x:`2`,y:`2`,width:`5`,height:`5`,rx:`1`}),q(`rect`,{x:`9`,y:`2`,width:`5`,height:`5`,rx:`1`}),q(`rect`,{x:`2`,y:`9`,width:`5`,height:`5`,rx:`1`}),q(`rect`,{x:`9`,y:`9`,width:`5`,height:`5`,rx:`1`})]}),`All cameras`]}):null]})}function uX({panel:e,recorded:t,recIndex:n,id:r,multi:i,wall:a,onPick:o,onMenu:s}){let c=e.recordings??[],l={onMenu:s,wall:a,onPick:o},u=t.find(e=>e.id===r);if(u)return q(fX,{...e,...l,source:u,name:i?Vn(u,e.live):u.name,rec:c[n(u)]},`rec:${u.recordingId}:${u.id}`);let d=e.live.find(e=>e.id===r&&e.kind===`camera`);if(!d?.video||d.status===`error`)return q(dX,{onContextMenu:s,title:`Camera offline`,detail:d?Vn(d,e.live):void 0});let f=e.live.find(e=>e.kind===`camera`&&e.lowOf===d.id&&e.video&&e.status!==`error`),p=f?.video?DE({...f,video:f.video}):void 0;return q(fX,{...e,...l,source:DE({...d,video:d.video}),low:p,name:i?Vn(d,e.live):d.name,conn:d},d.id)}function dX({title:e,detail:t,onContextMenu:n}){return q(`div`,{className:`kymo-camera`,onContextMenu:n,children:_t(`div`,{className:`kymo-camera__empty`,children:[_t(`svg`,{className:`kymo-camera__empty-icon`,viewBox:`0 0 24 24`,"aria-hidden":`true`,children:[q(`rect`,{x:`2.5`,y:`6`,width:`13`,height:`12`,rx:`2.5`}),q(`path`,{d:`M15.5 10.5 21.5 7v10l-6-3.5`})]}),q(`p`,{className:`kymo-camera__empty-title`,children:e}),t?q(`p`,{className:`kymo-camera__empty-detail`,children:t}):null]})})}function fX(e){let{settings:t,source:n}=e,r=e.cursor??sX,i=pt(r.subscribe,r.get),a=e=>e.kind===`data`,o=e.rec?void 0:t.syncStreamId?e.live.find(e=>e.id===t.syncStreamId&&a(e)):e.live.find(t=>t.id===e.conn.parentId&&a(t))??e.live.find(t=>a(t)&&e.selection.includes(t.id))??e.live.find(a),s=i??e.viewXRange?.[1]??null,c=null,l=null,u=o?.clock?.quality()??`none`;if(e.rec){let{wallOrigin:r,wallQuality:i,xOffset:a}=e.rec;u=i??`none`;let o=n.range()?.[0]??null;s===null?c=o:r===null?(c=o,l=`This recording has no wall clock`):e.xKey===`Time`?c=r+s-a+t.offsetMs/1e3:e.xKey===`ElapsedTime`&&i===`exact`?c=s-a+t.offsetMs/1e3:(c=o,l=`Sync needs a time X axis`)}else s!==null&&(e.xIsTime?(c=o?.clock?.toWall(s,t.offsetMs)??null,c===null&&(l=`No data stream to sync with`)):l=`Sync needs a time X axis`);let d=K(null),f=K(null),p=cX(d),m=p===null?null:e.low&&(p||e.wall)?e.low:n,h=K(t.fit),g=K(c);G(()=>{h.current=t.fit,g.current=c});let _=K(null),v=K(null),[y,b]=ft(null),x=y??m??n,[S,C]=ft(!1),[w,T]=ft(!0);W(()=>{if(!m||_.current?.source===m)return;let e=!_.current,t=null,n=!1,r=()=>t?_.current===t:e,i=t=mX(m,f.current,()=>h.current,g.current,{unsupported:()=>{r()&&C(!0)},buffered:e=>{r()&&T(e)},frame:()=>{if(_.current===t){n||(n=!0,b(m));return}_.current?.dispose(),_.current=i,v.current=null,i.show(),n=!0,b(m),T(i.buffered())}},e);if(e){_.current=i;return}return v.current=i,()=>{_.current!==i&&(i.dispose(),v.current===i&&(v.current=null))}},[m]),W(()=>()=>{_.current?.dispose(),_.current=null},[]),W(()=>{_.current?.setTarget(c),v.current?.setTarget(c)},[c]);let E=!!x.lowOf,D=x.info().latestT,O=!e.rec&&c!==null&&D!==null?c-D:null,k=e.rec?`No video at this time`:`Not buffered`;return _t(`div`,{ref:d,className:`kymo-camera${e.onPick?` is-tile`:``}`,onContextMenu:e.onMenu,...e.onPick?{role:`button`,tabIndex:0,"data-camera":n.id,"aria-label":`Show ${e.name} alone`,onClick:e.onPick,onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),e.onPick())}}:{},children:[q(`canvas`,{ref:f,className:`kymo-camera__video`,role:`img`,"aria-label":`Video from ${e.name}`}),S?q(`div`,{className:`kymo-camera__empty`,children:q(`p`,{className:`kymo-camera__empty-title`,children:`This browser can't decode this camera`})}):_t(`div`,{className:`kymo-camera__overlay`,children:[q(`span`,{className:`kymo-camera__name`,children:e.name}),e.rec?q(`span`,{className:`kymo-camera__rec`,children:`Recording`}):c===null?q(`span`,{className:`kymo-camera__live`,children:`LIVE`}):q(`span`,{className:`kymo-camera__ago`,children:O===null?``:pX(O)}),E?q(`span`,{className:`kymo-camera__badge`,title:`Low-quality copy (small panel)`,children:`LQ`}):null,c!==null&&u!==`none`?q(`span`,{className:`kymo-camera__badge${u===`exact`?` is-exact`:``}`,children:u===`exact`?`Exact`:`Approx.`}):null,l??(c!==null&&!w?k:null)?q(`span`,{className:`kymo-camera__note`,children:l??k}):null]})]})}function pX(e){let t=Math.abs(e).toFixed(1);return t===`0.0`?`0.0 s`:`${e<0?`−`:`+`}${t} s`}function mX(e,t,n,r,i,a=!0){let o=e.acquire?.(),s=!1,c=!0,l=e=>{c=e,i.buffered(e)},u=null,d=null,f=r,p=`live`,m=!0,h=!1,g=!1,_=null,v=null,y=null,b=[],x=e=>{if(s){e.close();return}p===`seek`?(_?.close(),_=e):(v?.close(),v=e,i.frame?.())},S=()=>{!d||d.state===`closed`?d=new VideoDecoder({output:x,error:()=>{}}):d.reset(),d.configure(u),m=!0},C=e=>{d?.state===`closed`&&e.key&&S(),!(d?.state!==`configured`||m&&!e.key)&&(m=!1,d.decode(new EncodedVideoChunk({type:e.key?`key`:`delta`,timestamp:Math.round(e.t*1e6),data:e.data})))},w=()=>{p=`live`,l(!0),S();for(let t of e.livePlan?.()??[])C(t)},T=async()=>{if(!h){h=!0;try{for(;!s&&p===`seek`&&g;){g=!1;let t=[];try{t=await e.seekPlan(f)}catch{}if(!(s||p!==`seek`||g)&&(l(t.length>0),t.length)){S();for(let e of t)C(e);try{await d.flush()}catch{}p===`seek`&&_&&(v?.close(),v=_,_=null,i.frame?.())}}}finally{h=!1,_?.close(),_=null}}},E=()=>{f===null?p!==`live`&&w():(p=`seek`,g=!0,T())};e.onUnit&&b.push(e.onUnit(e=>{u&&p===`live`&&C(e)})),(async()=>{if(typeof VideoDecoder>`u`){i.unsupported();return}if(e.info().codec||(e.ready?await e.ready():e.onUnit&&await new Promise(t=>{let n=e.onUnit(()=>{e.info().codec&&(n(),t())});b.push(n)})),s)return;if(!e.info().codec){l(!1);return}let t={codec:e.info().codec,optimizeForLatency:!0,hardwareAcceleration:`no-preference`},n=!1;try{n=(await VideoDecoder.isConfigSupported(t)).supported===!0}catch{}if(!s){if(!n){i.unsupported();return}u=t,f===null?w():E()}})();let D=n(),O=()=>{if(!a)return;let e=window.devicePixelRatio||1,r=Math.max(1,Math.round(t.clientWidth*e)),i=Math.max(1,Math.round(t.clientHeight*e)),o=!1;if((t.width!==r||t.height!==i)&&(t.width=r,t.height=i,o=!0),v&&(y?.close(),y=v,v=null,o=!0),n()!==D&&(D=n(),o=!0),!o||!y)return;let s=t.getContext(`2d`);if(!s)return;let c=y.displayWidth,l=y.displayHeight,u=D===`cover`?Math.max(r/c,i/l):Math.min(r/c,i/l),d=c*u,f=l*u;s.clearRect(0,0,r,i),s.drawImage(y,(r-d)/2,(i-f)/2,d,f)},k=0,A=()=>{k=yH(A),O()};return k=yH(A),{source:e,show(){a=!0},buffered:()=>c,setTarget(e){e!==f&&(f=e,u&&E())},dispose(){s=!0,bH(k),b.forEach(e=>e()),d&&d.state!==`closed`&&d.close();for(let e of[_,v,y])e?.close();_=v=y=null,o?.()}}}function hX(e,t){let n=e.filter(e=>e.x.length>=2&&gX(e.x));if(n.length<2)return null;let r=1/0,i=-1/0;for(let e of n)e.x[0]<r&&(r=e.x[0]),e.x[e.x.length-1]>i&&(i=e.x[e.x.length-1]);if(!(i>r))return null;let a=Math.max(2,t),o=Float64Array.from({length:a},(e,t)=>r+t/(a-1)*(i-r)),s=new Float64Array(a).fill(1/0),c=new Float64Array(a).fill(-1/0),l=new Uint16Array(a);for(let e of n){let t=0;for(let n=0;n<a;n++){let r=o[n];if(r<e.x[0]||r>e.x[e.x.length-1])continue;for(;t<e.x.length-2&&e.x[t+1]<r;)t++;let i=e.x[t],a=e.x[t+1],u=e.y[t],d=e.y[t+1],f=a===i?u:u+(d-u)*(r-i)/(a-i);f-f===0&&(f<s[n]&&(s[n]=f),f>c[n]&&(c[n]=f),l[n]++)}}for(let e=0;e<a;e++)l[e]<2&&(s[e]=NaN,c[e]=NaN);return{x:o,lo:s,hi:c}}function gX(e){for(let t=1;t<e.length;t++)if(!(e[t]>=e[t-1]))return!1;return!0}function _X(e){if(e.length===0)return null;if(e.length===1)return e[0];let t=new Set,n={};for(let r of e)for(let e=0;e<r.columnNames.length;e++){let i=r.columnNames[e];t.add(i),r.units[e]?.trim()&&(n[i]=r.units[e])}let r=[...t];return{meta:``,columnNames:r,units:r.map(e=>n[e]??``),rows:e.flatMap(e=>e.rows)}}function vX(e,t,n,r,i){return n||e.length===0||(t>0?e.length!==1:e.length<2||r!==`ElapsedTime`)?null:e.map((e,n)=>({conn:e,keySuffix:`__${t+n}`,offset:i[e.id]??0}))}function yX(e,t,n,r,i){if(e.length===1){let a=e[0];return bX(a.conn,t,n,a.keySuffix,a.offset,r,i)}let a=e.map(e=>bX(e.conn,t,n,e.keySuffix,e.offset,[],null)),o=()=>a.reduce((e,t)=>t.latestT()>e.latestT()?t:e);return{pull:(e,t,n,i)=>[...r,...a.flatMap(r=>r.pull(e,t,n,i))],xBounds:()=>{let e=i;for(let t of a){let n=t.xBounds();n&&(e=e?[Math.min(e[0],n[0]),Math.max(e[1],n[1])]:n)}return e},latestX:()=>o().latestX(),version:()=>a.reduce((e,t)=>e+t.version(),0),latestT:()=>o().latestT(),xAtTime:e=>o().xAtTime(e),latestValues:e=>new Map(a.flatMap(t=>[...t.latestValues(e)]))}}function bX(e,t,n,r,i,a,s){let l=null;return{pull:(s,u,d,f)=>{let p=e.source.version();if(!l||l.ver!==p||l.x0!==s||l.x1!==u||l.mp!==d){let a=e.source.getPointsSync(n,{xKey:t,x0:s-i,x1:u-i},d),o=i===0?a.x:a.x.map(e=>e+i);l={ver:p,x0:s,x1:u,mp:d,pts:{...a,x:o,cols:new Map([...a.cols].map(([e,t])=>[e+r,t]))}}}let m=o(l.pts,f);if(t!==`ElapsedTime`)return[...a,m];let h=Math.min(e.source.latestTimeSync(),f===void 0?1/0:f-i),g=c(n,t=>e.source.lastKnownSync(t),s-i,u-i,h);if(!g)return[...a,m];let _=i===0?g.x:g.x.map(e=>e+i);return[...a,m,{...g,x:_,cols:new Map([...g.cols].map(([e,t])=>[e+r,t]))}]},xBounds:()=>{let n=e.source.xBoundsSync(t);return n.x1>n.x0?s?[Math.min(s[0],n.x0+i),Math.max(s[1],n.x1+i)]:[n.x0+i,n.x1+i]:s},latestX:()=>{let n=e.source.latestSync(t);return Number.isFinite(n)?n+i:null},version:()=>e.source.version(),latestT:()=>e.source.latestTimeSync(),xAtTime:n=>e.source.xAtTimeSync(t,n)+i,latestValues:t=>{let n=new Map,i=t.filter(e=>e.endsWith(r)),a=e.source.latestValuesSync(i.map(e=>e.slice(0,-r.length)));for(let e of i){let t=a.get(e.slice(0,-r.length));t!==void 0&&n.set(e,t)}return n}}}function xX(e,t){return e.filter(e=>B(t,e))}var SX=`__ref`,CX=8e3;function wX(e,t){return e.map(e=>({...e,id:`${e.id}${SX}`,column:`${e.column}${SX}`,color:t}))}var TX=new WeakMap;function EX(e,t,r){let i=e.data.rows,a=`${t}\n${r.join(`
608
- `)}`,o=TX.get(i);o||(o=new Map,TX.set(i,o));let s=o.get(a);if(s)return s;let c=DX(n(i,t,r,CX,SX)),l={points:c,span:c.length>1?[c.x[0],c.x[c.length-1]]:null};return o.set(a,l),l}function DX(e){let t=!0;for(let n=1;n<e.length&&t;n++)t=e.x[n-1]<=e.x[n];if(t)return e;let n=Array.from({length:e.length},(e,t)=>t).sort((t,n)=>e.x[t]-e.x[n]),r=new Map;for(let[t,i]of e.cols)r.set(t,Float64Array.from(n,e=>i[e]));return{length:e.length,x:Float64Array.from(n,t=>e.x[t]),cols:r}}function OX(e,t){return e?t?[Math.min(e[0],t[0]),Math.max(e[1],t[1])]:e:t}function kX(e,t,n,r,i){e.source.trackCycles(t);let a=r.reference===`dataset`&&i?EX(i,t,n):null,s=null;return{pull:(i,c,l,u)=>{let d=e.source.version();if(!s||s.ver!==d||s.x0!==i||s.x1!==c||s.mp!==l){let o=Ye;if(r.reference===`previous`){let r=e.source.cyclePointsSync(t,`previous`,n,{x0:i,x1:c},l);o={...r,cols:new Map([...r.cols].map(([e,t])=>[e+SX,t]))}}else a&&(o=j(a.points,i,c));s={ver:d,x0:i,x1:c,mp:l,live:e.source.cyclePointsSync(t,`current`,n,{x0:i,x1:c},l),ref:o}}return[s.ref,o(s.live,u)]},latestT:()=>e.source.latestTimeSync(),xAtTime:n=>e.source.xAtTimeSync(t,n),xBounds:()=>OX(e.source.cycleSpanSync(t),a?.span??null),latestX:()=>{let n=e.source.latestSync(t);return Number.isFinite(n)?n:null},version:()=>e.source.version(),latestValues:t=>e.source.latestValuesSync(t)}}function AX(e,t){return e.reference===`previous`?e.previousColor:e.reference===`dataset`&&t?e.datasetColor:null}function jX(e,t,n,r,i=0){let a=e.bands;if(!a)return[];let o=n.filter(e=>a[e.column]);if(o.length===0||e.data.rows.length!==a[o[0].column].lo.length)return[];let s=Float64Array.from(e.data.rows,e=>{let n=e[t];return typeof n==`number`?n+i:NaN});return o.map(e=>({seriesId:e.id,color:r??e.color,x:s,lo:a[e.column].lo,hi:a[e.column].hi}))}var MX=class{#e;#t;#n;#r=new Map;constructor(e,t={}){this.#e=e,this.#t=[...e.keys()].map(e=>({name:e,type:`number`,unit:t[e]??``})),this.#n=e.size?e.values().next().value.length:0}get length(){return this.#n}get columnMap(){return this.#e}async getSchema(){return this.#t}async getSeries(e){let t=this.#e.get(e.viewport.xKey),n=this.#e.get(e.column);return!t||!n?$e(new Float64Array,new Float64Array,e.viewport.x0,e.viewport.x1,e.maxPoints):$e(t,n,e.viewport.x0,e.viewport.x1,e.maxPoints)}async getSeriesMulti(e,t,n){return this.getSeriesMultiSync(e,t,n)}getSeriesMultiSync(e,t,n){let r=this.#e.get(t.xKey),i=r?e.filter(e=>this.#e.has(e)):[];return!r||i.length===0?{x0:t.x0,bucket:0,rows:[],columns:i}:a(r,i.map(e=>this.#e.get(e)),i,t.x0,t.x1,n)}getColumnsSync(e,t,n){let r=this.#e.get(t.xKey),i=r?e.filter(e=>this.#e.has(e)):[];return!r||i.length===0?null:R(r,i.map(e=>this.#e.get(e)),i,t.x0,t.x1,n)}async readColumns(e,t,n){let r={};for(let i of e){let e=this.#e.get(i);e&&(r[i]=e.slice(t,t+n))}return r}async xBounds(e){return this.xBoundsSync(e)}xBoundsSync(e){let t=this.#r.get(e);if(!t){let n=this.#e.get(e),r=1/0,i=-1/0;if(n)for(let e=0;e<n.length;e++){let t=n[e];t<r&&(r=t),t>i&&(i=t)}t=r<=i?{x0:r,x1:i}:{x0:0,x1:0},this.#r.set(e,t)}return t}sampleRowsSync(e,t){let n=t?this.#e.get(t.xcol):void 0,r=null;if(t&&n){r=[];for(let e=0;e<n.length;e++)n[e]>=t.x0&&n[e]<=t.x1&&r.push(e)}let i=r?r.length:this.#n,a=Math.max(1,Math.ceil(i/e)),o=[...this.#e.keys()],s=o.map(e=>this.#e.get(e)),c=[];for(let e=0;e<i;e+=a){let t=r?r[e]:e,n={};for(let e=0;e<o.length;e++){let r=s[e][t];n[o[e]]=Number.isNaN(r)?null:r}c.push(n)}return c}async sampleRows(e,t){return this.sampleRowsSync(e,t)}async dispose(){}};function NX(e){if(!Number.isFinite(e))return`—`;let t=Math.abs(e);return t>=1e4||t<.01&&e!==0?e.toExponential(1):String(parseFloat(e.toPrecision(4)))}function PX(e,t){let n=Math.max(1,Math.min(50,Math.floor(t.xBins))),r=Math.max(1,Math.min(50,Math.floor(t.yBins))),i=t.xMin,a=t.xMax,o=t.yMin,s=t.yMax;if(i===void 0||a===void 0||o===void 0||s===void 0){let n=1/0,r=-1/0,c=1/0,l=-1/0;for(let i of e){let e=i[t.xCol],a=i[t.yCol];typeof e==`number`&&Number.isFinite(e)&&(e<n&&(n=e),e>r&&(r=e)),typeof a==`number`&&Number.isFinite(a)&&(a<c&&(c=a),a>l&&(l=a))}i===void 0&&(i=n),a===void 0&&(a=r),o===void 0&&(o=c),s===void 0&&(s=l)}let c=a-i,l=s-o;if(!(c>0)||!(l>0))return{cells:[],xLabels:[],yLabels:[]};let u=new Float64Array(n*r),d=new Float64Array(n*r),f=t.valueCol===``;for(let p of e){let e=p[t.xCol],m=p[t.yCol];if(typeof e!=`number`||!Number.isFinite(e)||typeof m!=`number`||!Number.isFinite(m)||e<i||e>a||m<o||m>s)continue;let h=Math.floor((e-i)/c*n);h>=n&&(h=n-1),h<0&&(h=0);let g=Math.floor((m-o)/l*r);g>=r&&(g=r-1),g<0&&(g=0);let _=g*n+h;if(f)d[_]+=1;else{let e=p[t.valueCol];if(typeof e!=`number`||!Number.isFinite(e))continue;u[_]+=e,d[_]+=1}}let p=Array.from({length:n},(e,t)=>NX(i+(t+.5)*(c/n))),m=Array.from({length:r},(e,t)=>NX(o+(r-1-t+.5)*(l/r))),h=[];for(let e=0;e<r;e++){let t=r-1-e;for(let r=0;r<n;r++){let i=e*n+r,a=d[i],o=f?a:a>0?u[i]/a:NaN;h.push({x:p[r],y:m[t],value:o})}}return{cells:h,xLabels:p,yLabels:m}}function FX(e,t){return t.some(t=>t.name===e)}function IX(e,t){return FX(e,t)?`ƒ ${e}`:e}var LX=8e3,RX=3e3,zX=[];function BX(e){return`live`in e?e.live.source.columns():`source`in e&&e.source instanceof MX?e.source.columnMap:void 0}var VX=4e3,HX=new WeakMap;function UX(e,t,n){let r=HX.get(e);r||HX.set(e,r=new Map);let i=JSON.stringify([n,...t]),a=r.get(i);return a||r.set(i,a=new LE({meta:``,columnNames:[n,...t],units:[],rows:e})),a}var WX=new WeakMap;function GX(e,t){if(t!==`parallel`||e.length===0)return e;let n=e.length,r=100/n;return e.map((e,t)=>({...e,bandFromPct:Math.round((n-1-t)*r),bandToPct:Math.round((n-t)*r)}))}function KX(e,t){let n=1/0,r=-1/0;for(let{rows:i,offset:a}of e){let e=WX.get(i);e||(e=new Map,WX.set(i,e));let o=e.get(t);if(o===void 0){let n=1/0,r=-1/0;for(let e of i){let i=e[t];typeof i!=`number`||!Number.isFinite(i)||(i<n&&(n=i),i>r&&(r=i))}o=Number.isFinite(n)?[n,r]:null,e.set(t,o)}o&&(n=Math.min(n,o[0]+a),r=Math.max(r,o[1]+a))}return Number.isFinite(n)&&r>n?[n,r]:null}function qX(e,t){let n={};for(let t=0;t<e.columnNames.length;t++){let r=e.units[t]?.trim();r&&(n[e.columnNames[t]]=r)}let r=Object.entries(n);for(let e=0;e<t;e++)for(let[t,i]of r)n[`${t}__${e}`]=i;return n}function JX(e,t){let n=1/0,r=-1/0;for(let i of e){let e=i[t];typeof e!=`number`||!Number.isFinite(e)||(e<n&&(n=e),e>r&&(r=e))}if(!(r>n))return e;let i=(r-n)/2,a=0,o=NaN;for(let n=0;n<e.length;n++){let r=e[n][t];typeof r!=`number`||!Number.isFinite(r)||(r<o-i&&(a=n),o=r)}return a===0?e:e.slice(a)}var YX=new Map;function XX(e){let t=YX.get(e);return t||(t=Float64Array.from({length:e},(e,t)=>t),YX.clear(),YX.set(e,t)),t}function ZX(e){let{worksheet:t,viewXRange:r,selectedIds:i,selectedDatasets:a,mathChannels:o,datasetOffsets:s,datasetColors:c,datasetPalette:l}=e,u=t.panels,d=t.panelChartSettings,f=t.xKey,p={connections:dt(()=>f===`ElapsedTime`?e.liveConnections:e.liveConnections.map(e=>{let t=JX(e.dataset.rows,f);return t===e.dataset.rows?e:{...e,dataset:{...e.dataset,rows:t}}}),[e.liveConnections,f])},[m,h]=ft({}),g=dt(()=>u.some(e=>e.kind!==`multiband`),[u]),_=dt(()=>p.connections.some(e=>i.includes(e.id)),[p.connections,i]),v=dt(()=>{let e=p.connections.filter(e=>i.includes(e.id));return e.length===1&&a.length===0?e[0]:null},[p.connections,i,a]),y=dt(()=>_X(a.map(e=>{let t=m[e.id];return t?{...e.data,rows:t}:e.data})),[a,m]),b=dt(()=>{let e=p.connections.filter(e=>i.includes(e.id)).map(e=>e.dataset);return e.length===0?y:_X(y?[y,...e]:e)},[y,p.connections,i]),x=dt(()=>SE(o,d,f).map(e=>e.id).join(`
607
+ }`,PK=-3e38;function FK(e){for(let t=0;t<e.length;t++)if(e[t]-e[t]===0)return e[t];return 0}function IK(e){let t=e.getContext(`webgl2`,{antialias:!1,alpha:!0,premultipliedAlpha:!0});if(!t)return null;let n=(e,n,i,a)=>lH(t,`glPlot|${e}|${n}`,()=>r(e,n,i,a)),r=(e,n,r,i)=>{let a=WV(t,t.VERTEX_SHADER,e),o=WV(t,t.FRAGMENT_SHADER,n);if(!a||!o)return null;let s=t.createProgram();if(t.attachShader(s,a),t.attachShader(s,o),t.linkProgram(s),!t.getProgramParameter(s,t.LINK_STATUS))return console.error(`glPlot program link failed:`,t.getProgramInfoLog(s)),null;let c=[`u_resolution`,`u_plot`,`u_view`,`u_clip`,`u_dpr`,`u_height`];return{prog:s,shaders:[a,o],a:Object.fromEntries([`a_corner`,...r].map(e=>[e,t.getAttribLocation(s,e)])),u:Object.fromEntries([...c,...i].map(e=>[e,t.getUniformLocation(s,e)]))}},i=n(EK,OK,[`a_xa`,`a_xb`,`a_loa`,`a_lob`,`a_hia`,`a_hib`,`a_bstart`],[`u_color`]),a=n(DK,kK,[`a_x0`,`a_x1`,`a_y0`,`a_y1`,`a_k`],[`u_palette`]),o=n(AK,jK,[`a_ax`,`a_ay`,`a_bx`,`a_by`,`a_bstart`],[`u_color`,`u_half`,`u_ext`]),s=n(MK,NK,[],[`u_extent`,`u_values`,`u_palette`,`u_range`]);if(!i||!a||!o||!s)return null;let c=t.getParameter(t.MAX_TEXTURE_SIZE),l=t.createVertexArray(),u=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,u),t.bufferData(t.ARRAY_BUFFER,Float32Array.from([0,0,1,0,0,1,1,1]),t.STATIC_DRAW);let d=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,d),t.bufferData(t.ARRAY_BUFFER,Float32Array.from([-1,-1,1,-1,-1,1,1,1]),t.STATIC_DRAW);let f=new Map,p=1,m=1,h=1,g={xmin:0,xmax:1,ymin:0,ymax:1},_={left:0,top:0,width:1,height:1},v=new WeakMap,y=new Float32Array,b=e=>{for(let n of Object.values(e.buffers))t.deleteBuffer(n);e.palette&&t.deleteTexture(e.palette),e.values&&t.deleteTexture(e.values)},x=new Float32Array,S=(e,n)=>{t.bindTexture(t.TEXTURE_2D,e),t.texImage2D(t.TEXTURE_2D,0,t.RGBA8,256,1,0,t.RGBA,t.UNSIGNED_BYTE,n),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE)},C=(e,t)=>{let n=f.get(e);if(n&&n.kind===t)return n;n&&b(n);let r={kind:t,n:0,ox:0,oy:0,buffers:{},color:[0,0,0,1],width:1};return f.set(e,r),r},w=(e,n,r)=>{let i=e.buffers[n]??=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,i),r.byteLength<=(v.get(i)??0)?t.bufferSubData(t.ARRAY_BUFFER,0,r):(t.bufferData(t.ARRAY_BUFFER,r,t.DYNAMIC_DRAW),v.set(i,r.byteLength))},T=(e,t,n,r)=>{let i=n.length;y.length<i&&(y=new Float32Array(i));for(let e=0;e<i;e++)y[e]=n[e]-r;w(e,t,y.subarray(0,i))},E=(e,t,n)=>{let r=new Uint8Array(e);t&&r.set(t.subarray(0,e)),e&&(r[0]=255);for(let t=0;t<e;t++)n(t)||(r[t]=255,t+1<e&&(r[t+1]=255));return r},D=(e,n,r=0,i=t.FLOAT)=>{if(e<0)return;t.bindBuffer(t.ARRAY_BUFFER,n),t.enableVertexAttribArray(e);let a=i===t.FLOAT?4:1;t.vertexAttribPointer(e,1,i,i!==t.FLOAT,a,r*a),t.vertexAttribDivisor(e,1)},O=(n,r,i)=>{t.useProgram(n.prog),t.uniform2f(n.u.u_resolution,p,m),t.uniform4f(n.u.u_plot,_.left,_.top,_.width,_.height),t.uniform4f(n.u.u_view,g.xmin-r.ox,g.xmax-r.ox,g.ymin-r.oy,g.ymax-r.oy),t.uniform4f(n.u.u_clip,_.left,_.top,_.left+_.width,_.top+_.height),t.uniform1f(n.u.u_dpr,h),t.uniform1f(n.u.u_height,e.height),t.bindBuffer(t.ARRAY_BUFFER,i),t.enableVertexAttribArray(n.a.a_corner),t.vertexAttribPointer(n.a.a_corner,2,t.FLOAT,!1,0,0),t.vertexAttribDivisor(n.a.a_corner,0)},k=e=>{for(let n of Object.values(e.a))n>=0&&t.vertexAttribDivisor(n,0)};return{resize(t,n,r){p=Math.max(1,t),m=Math.max(1,n),h=r,e.width=Math.round(p*h),e.height=Math.round(m*h)},setView(e,t,n,r,i){g={xmin:e,xmax:t,ymin:n,ymax:r},_=i},setBands(e,t,n,r,i,a){let o=C(e,`bands`),s=Math.min(t.length,n.length,r.length);o.ox=FK(t),o.oy=FK(r),T(o,`x`,t,o.ox),T(o,`lo`,n,o.oy),T(o,`hi`,r,o.oy),w(o,`start`,E(s,a,e=>t[e]-t[e]===0&&n[e]-n[e]===0&&r[e]-r[e]===0)),o.n=Math.max(0,s-1),o.color=i},setRects(e,n,r,i,a,o,s){let c=C(e,`rects`),l=Math.min(n.length,r.length,i.length,a.length);c.ox=FK(n),c.oy=FK(i),T(c,`x0`,n,c.ox),T(c,`x1`,r,c.ox),T(c,`y0`,i,c.oy),T(c,`y1`,a,c.oy),s?T(c,`k`,s,0):delete c.buffers.k;let u=new Uint8Array(256*4);for(let e=0;e<256;e++){let t=o[Math.min(e,o.length-1)]??[0,0,0,1];u.set([t[0]*255,t[1]*255,t[2]*255,t[3]*255],e*4)}c.palette??=t.createTexture(),t.bindTexture(t.TEXTURE_2D,c.palette),t.texImage2D(t.TEXTURE_2D,0,t.RGBA8,256,1,0,t.RGBA,t.UNSIGNED_BYTE,u),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),c.n=l},setLine(e,t,n,r,i,a){let o=C(e,`line`),s=Math.min(t.length,n.length);o.ox=FK(t),o.oy=FK(n),T(o,`x`,t,o.ox),T(o,`y`,n,o.oy),w(o,`start`,E(s,a,e=>t[e]-t[e]===0&&n[e]-n[e]===0)),o.n=Math.max(0,s-1),o.color=r,o.width=i},maxTextureSize:c,setGrid(e,n,r,i,a,o,s,c){let l=C(e,`grid`),u=r*i,d=0;for(let e=0;e<u;e++)d+=n[e]*0;let f=n.subarray(0,u);if(d!==0){x.length<u&&(x=new Float32Array(u));for(let e=0;e<u;e++){let t=n[e];x[e]=t===t?t:PK}f=x.subarray(0,u)}let p=!l.values;l.values??=t.createTexture(),t.bindTexture(t.TEXTURE_2D,l.values),t.pixelStorei(t.UNPACK_ALIGNMENT,4),!p&&l.grid&&l.grid.w===r&&l.grid.h===i?t.texSubImage2D(t.TEXTURE_2D,0,0,0,r,i,t.RED,t.FLOAT,f):(t.texImage2D(t.TEXTURE_2D,0,t.R32F,r,i,0,t.RED,t.FLOAT,f),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE)),l.palette??=t.createTexture(),S(l.palette,o);let[m,h,g,_]=a;l.ox=m,l.oy=g,l.grid={w:r,h:i,x0:m,x1:h,y0:g,y1:_,vmin:s,vmax:c},l.n=1},setGridRange(e,t,n){let r=f.get(e);r?.grid&&(r.grid.vmin=t,r.grid.vmax=n)},remove(e){let t=f.get(e);t&&(b(t),f.delete(e))},keep(e){let t=new Set(e);for(let e of[...f.keys()])t.has(e)||this.remove(e)},render(){t.bindFramebuffer(t.FRAMEBUFFER,null),t.viewport(0,0,e.width,e.height),t.disable(t.SCISSOR_TEST),t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT),t.bindVertexArray(l),t.enable(t.BLEND),t.blendFunc(t.ONE,t.ONE_MINUS_SRC_ALPHA);for(let e of f.values()){if(e.n<=0)continue;let n=e.buffers;if(e.kind===`bands`)O(i,e,u),t.uniform4f(i.u.u_color,...e.color),D(i.a.a_xa,n.x,0),D(i.a.a_xb,n.x,1),D(i.a.a_loa,n.lo,0),D(i.a.a_lob,n.lo,1),D(i.a.a_hia,n.hi,0),D(i.a.a_hib,n.hi,1),D(i.a.a_bstart,n.start,1,t.UNSIGNED_BYTE),t.drawArraysInstanced(t.TRIANGLE_STRIP,0,4,e.n),k(i);else if(e.kind===`grid`){let n=e.grid;O(s,e,u),t.uniform4f(s.u.u_extent,0,n.x1-n.x0,0,n.y1-n.y0),t.uniform2f(s.u.u_range,n.vmin,n.vmax),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,e.values),t.uniform1i(s.u.u_values,0),t.activeTexture(t.TEXTURE1),t.bindTexture(t.TEXTURE_2D,e.palette),t.uniform1i(s.u.u_palette,1),t.drawArrays(t.TRIANGLE_STRIP,0,4),t.activeTexture(t.TEXTURE0)}else e.kind===`rects`?(O(a,e,u),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,e.palette),t.uniform1i(a.u.u_palette,0),D(a.a.a_x0,n.x0),D(a.a.a_x1,n.x1),D(a.a.a_y0,n.y0),D(a.a.a_y1,n.y1),n.k?D(a.a.a_k,n.k):(t.disableVertexAttribArray(a.a.a_k),t.vertexAttrib1f(a.a.a_k,0)),t.drawArraysInstanced(t.TRIANGLE_STRIP,0,4,e.n),k(a)):(O(o,e,d),t.uniform4f(o.u.u_color,...e.color),t.uniform1f(o.u.u_half,e.width/2),t.uniform1f(o.u.u_ext,e.width/2+1.5),D(o.a.a_ax,n.x,0),D(o.a.a_bx,n.x,1),D(o.a.a_ay,n.y,0),D(o.a.a_by,n.y,1),D(o.a.a_bstart,n.start,1,t.UNSIGNED_BYTE),t.drawArraysInstanced(t.TRIANGLE_STRIP,0,4,e.n),k(o))}t.bindVertexArray(null)},dispose(){for(let e of f.values())b(e);f.clear(),t.deleteBuffer(u),t.deleteBuffer(d),t.deleteVertexArray(l)}}}function LK(e){let t=K({plot:null,failed:!1,size:``});return W(()=>()=>{t.current.plot?.dispose(),t.current.plot=null},[]),ct((n,r)=>{let i=t.current,a=e.current;if(!i.plot&&!i.failed&&a&&(i.plot=uH(a,IK),i.failed=!i.plot),!i.plot||!a)return null;let o=Math.min(2,window.devicePixelRatio||1),s=`${n}x${r}@${o}`;return i.size!==s&&(i.plot.resize(n,r,o),a.style.width=`${n}px`,a.style.height=`${r}px`,i.size=s),i.plot},[e])}function RK(e){let t=!1;for(let n=0;n<e.length;n++)if(Math.abs(e[n])>Math.PI*2){t=!0;break}let n=new Float64Array(e.length);for(let r=0;r<e.length;r++)n[r]=t?e[r]*Math.PI/180:e[r];return n}var zK=16;function BK(e,t,n,r){let i=RK(e),a=Math.min(i.length,t.length),o=1/0,s=-1/0;for(let e=0;e<a;e++){let n=t[e];n<o&&(o=n),n>s&&(s=n)}let c=n??Math.min(0,o),l=r??s,u=l-c||1,d=new Float64Array(a),f=new Float64Array(a),p=new Float64Array(zK),m=new Int32Array(zK);for(let e=0;e<a;e++){let n=Math.max(0,(t[e]-c)/u),r=i[e];n>1.0001?d[e]=f[e]=NaN:(d[e]=Math.sin(r)*n,f[e]=Math.cos(r)*n);let a=r%(2*Math.PI);a<0&&(a+=2*Math.PI);let o=Math.min(zK-1,Math.floor(a/(2*Math.PI)*zK));p[o]+=t[e],m[o]++}return{n:a,rMin:c,rMax:l,x:d,y:f,means:Array.from({length:zK},(e,t)=>m[t]>0?p[t]/m[t]:0)}}function VK({angles:e,radii:t,angleLabel:n,radiusLabel:r,color:i=`#a78bfa`,mode:a=`waveform`,radiusMin:o,radiusMax:s,height:c=400,backgroundToken:l=``,onPlotContextMenu:u}){let d=K(null),f=K(null),p=K(null),m=K(u);G(()=>{m.current=u},[u]);let h=K({angles:e,radii:t,angleLabel:n,radiusLabel:r,color:i,mode:a,radiusMin:o,radiusMax:s,height:c});G(()=>{h.current={angles:e,radii:t,angleLabel:n,radiusLabel:r,color:i,mode:a,radiusMin:o,radiusMax:s,height:c}},[e,t,n,r,i,a,o,s,c]);let g=dt(()=>BK(e,t,o,s),[e,t,o,s]),_=K(g);G(()=>{_.current=g},[g]);let v=K(null),y=LK(v),b=K({geo:null,color:``});function x(){if(p.current)return p.current;let e=f.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return p.current=n,n}function S(){let e=f.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||h.current.height)}}function C(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function w(){let e=d.current;if(!e)return;let{w:t,h:n}=S(),r=C(e,t,n);if(!r)return;let{bg:i,muted:a,grid:o}=x(),{angleLabel:s,radiusLabel:c,color:l,mode:u}=h.current,f=_.current,{n:p,rMin:m,rMax:g}=f;r.fillStyle=i,r.fillRect(0,0,t,n);let v=y(t,n);if(p===0){v?.keep([]),v?.render(),r.fillStyle=a,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`No data`,16,16);return}let w=g-m||1,T=(Math.min(t-64,n-32-24)-4)/2,E=t/2,D=32+T,O=wz(w,4),k=Dz(m,g,O);r.strokeStyle=o,r.lineWidth=1,r.setLineDash([3,3]);for(let e of k){let t=(e-m)/w*T;t<0||(r.beginPath(),r.arc(E,D,t,0,Math.PI*2),r.stroke())}r.setLineDash([]),r.strokeStyle=o,r.lineWidth=1;for(let e=0;e<360;e+=30){let t=e*Math.PI/180;r.beginPath(),r.moveTo(E,D),r.lineTo(E+Math.cos(-t+Math.PI/2)*T,D+Math.sin(-t+Math.PI/2)*T),r.stroke()}r.fillStyle=a,r.font=`10px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`middle`;for(let e=0;e<360;e+=30){let t=e*Math.PI/180,n=E+Math.sin(t)*(T+14),i=D-Math.cos(t)*(T+14);r.fillText(`${e}°`,n,i)}r.textAlign=`left`,r.textBaseline=`middle`;for(let e of k){let t=(e-m)/w*T;t<4||r.fillText(jz(e,O),E+4,D-t)}if(r.strokeStyle=a,r.lineWidth=1,r.setLineDash([]),r.beginPath(),r.arc(E,D,T,0,Math.PI*2),r.stroke(),r.save(),r.beginPath(),r.arc(E,D,T,0,Math.PI*2),r.clip(),u===`waveform`)if(v)(b.current.geo!==f||b.current.color!==l)&&(v.setLine(`wave`,f.x,f.y,XG(l,.9),1),b.current={geo:f,color:l}),v.keep([`wave`]),v.setView(-1,1,-1,1,{left:E-T,top:D-T,width:T*2,height:T*2}),v.render();else{r.strokeStyle=l,r.lineWidth=1,r.globalAlpha=.9,r.beginPath();let e=!1;for(let t=0;t<p;t++){let n=E+f.x[t]*T,i=D-f.y[t]*T;if(n!==n){e=!1;continue}e?r.lineTo(n,i):(r.moveTo(n,i),e=!0)}r.stroke(),r.globalAlpha=1}else{v?.keep([]),v?.render();let e=f.means,t=Math.max(...e,1e-10),n=2*Math.PI/zK;r.fillStyle=l,r.globalAlpha=.75;for(let i=0;i<zK;i++){let a=e[i]/t*T,o=i*n-Math.PI/2-n/2;r.beginPath(),r.moveTo(E,D),r.arc(E,D,a,o,o+n),r.closePath(),r.fill()}r.globalAlpha=1,r.strokeStyle=l,r.lineWidth=.5,r.globalAlpha=.4;for(let i=0;i<zK;i++){let a=e[i]/t*T,o=i*n-Math.PI/2-n/2;r.beginPath(),r.moveTo(E,D),r.arc(E,D,a,o,o+n),r.closePath(),r.stroke()}r.globalAlpha=1}r.restore(),r.fillStyle=a,r.font=`11px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`bottom`,r.fillText(`${s} / ${c}`,E,n-4)}let T=K(w);T.current=w;let E=K(null);E.current??=DH(()=>T.current(),()=>f.current);let D=()=>E.current.schedule();return W(()=>{E.current.now()}),W(()=>()=>E.current?.cancel(),[]),W(()=>{p.current=null,D()},[l]),G(()=>{let e=f.current;if(!e)return;let t=new EH(()=>{p.current=null,D()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=d.current;if(!e)return;let t=e=>{e.preventDefault(),m.current?.({clientX:e.clientX,clientY:e.clientY})};return e.addEventListener(`contextmenu`,t),()=>e.removeEventListener(`contextmenu`,t)},[]),_t(`div`,{ref:f,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:d,className:`chart-canvas`,role:`img`,"aria-label":`Polar chart: ${n} vs ${r}`}),q(`canvas`,{ref:v,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}})]})}function HK(e,t,n,r,i){let a=Math.min(e.length,t.length),o=(t,n)=>{let r=0,i=a;for(;r<i;){let a=r+i>>>1;(n?e[a]<=t:e[a]<t)?r=a+1:i=a}return r},s=o(n,!1),c=o(r,!0),l=Math.max(0,s-1),u=Math.min(a,c+1);if(u-l<=2*i){let e=new Uint32Array(u-l);for(let t=0;t<e.length;t++)e[t]=l+t;return e}let d=new Uint32Array(2*i+2),f=0;s>0&&(d[f++]=s-1);let p=(r-n)/i,m=s;for(let r=0;r<i&&m<c;r++){let a=r===i-1?1/0:n+(r+1)*p,o=1/0,s=-1/0,l=-1,u=-1;for(;m<c&&e[m]<a;m++){let e=t[m];e<o&&(o=e,l=m),e>s&&(s=e,u=m)}l<0||(l===u?d[f++]=l:l<u?(d[f++]=l,d[f++]=u):(d[f++]=u,d[f++]=l))}return c<a&&(d[f++]=c),d.subarray(0,f)}function UK(e,t){let n=e.length;if(n<=2*t)return Uint32Array.from({length:n},(e,t)=>t);let r=new Uint32Array(2*t),i=0;for(let a=0;a<t;a++){let o=Math.floor(a*n/t),s=Math.floor((a+1)*n/t),c=1/0,l=-1/0,u=-1,d=-1;for(let t=o;t<s;t++){let n=e[t];n<c&&(c=n,u=t),n>l&&(l=n,d=t)}u<0||(u===d?r[i++]=u:u<d?(r[i++]=u,r[i++]=d):(r[i++]=d,r[i++]=u))}return r.subarray(0,i)}function WK(e,t){let n=new Float64Array(t.length);for(let r=0;r<t.length;r++)n[r]=e[t[r]];return n}function GK(e){for(let t=1;t<e.length;t++)if(!(e[t]>=e[t-1]))return!1;return e.length===0||e[0]===e[0]}function KK(e,t){let n=e.length;for(let r=1,i=0;r<n;r++){let a=n>>1;for(;i&a;a>>=1)i^=a;if(i^=a,r<i){let n=e[r];e[r]=e[i],e[i]=n,n=t[r],t[r]=t[i],t[i]=n}}for(let r=2;r<=n;r<<=1){let i=r>>1,a=-2*Math.PI/r,o=Math.cos(a),s=Math.sin(a);for(let a=0;a<n;a+=r){let n=1,r=0;for(let c=0;c<i;c++){let l=a+c,u=l+i,d=e[u]*n-t[u]*r,f=e[u]*r+t[u]*n;e[u]=e[l]-d,t[u]=t[l]-f,e[l]+=d,t[l]+=f;let p=n*o-r*s;r=n*s+r*o,n=p}}}}var qK=new Float64Array,JK=new Float64Array;function YK(e,t,n){let r=t>>1;qK.length<r&&(qK=new Float64Array(r),JK=new Float64Array(r));let i=qK.subarray(0,r),a=JK.subarray(0,r),o=e.length;for(let t=0;t<r;t++){let r=2*t,s=r+1;i[t]=r<o?e[r]*(n?n[r]:1):0,a[t]=s<o?e[s]*(n?n[s]:1):0}KK(i,a);let s=new Float64Array(r),c=-2*Math.PI/t,l=Math.cos(c),u=Math.sin(c),d=1,f=0;for(let e=0;e<r;e++){let t=e===0?0:r-e,n=i[e],o=a[e],c=i[t],p=-a[t],m=(n+c)/2,h=(o+p)/2,g=(o-p)/2,_=-(n-c)/2,v=m+d*g-f*_,y=h+d*_+f*g;s[e]=Math.sqrt(v*v+y*y);let b=d*l-f*u;f=d*u+f*l,d=b}return s}var XK=new Float64Array,ZK=0;function QK(e){if(ZK===e)return XK.subarray(0,e);XK.length<e&&(XK=new Float64Array(Math.max(e,XK.length*2)));let t=2*Math.PI/Math.max(1,e-1),n=Math.cos(t),r=Math.sin(t),i=1,a=0;for(let t=0;t<e;t++){XK[t]=.5*(1-i);let e=i*n-a*r;a=a*n+i*r,i=e}return ZK=e,XK.subarray(0,e)}var $K={top:14,right:24,bottom:40,left:64},eq=5;function tq(e){let t=1;for(;t<e;)t<<=1;return t}function nq(e,t,n,r){let i=e.length,a=Math.max(2,tq(i)),o=YK(e,a,n===`hann`?QK(i):void 0),s=a/2,c=new Float64Array(s),l=2/a;for(let e=0;e<s;e++){c[e]=e*t/a;let n=o[e]*l;o[e]=r===`db`?20*Math.log10(Math.max(n,1e-12)):n}return{freqs:c,amps:o}}function rq({signal:e,sampleRate:t=1,label:n,xMode:r=`hz`,yMode:i=`amplitude`,window:a=`hann`,color:o=`#34d399`,logX:s=!1,height:c=400,backgroundToken:l=``,onPlotContextMenu:u}){let d=nU(),f=K(null),p=K(null),m=K(null),h=K(u);G(()=>{h.current=u},[u]);let g=K({signal:e,sampleRate:t,label:n,xMode:r,yMode:i,window:a,color:o,logX:s,height:c});G(()=>{g.current={signal:e,sampleRate:t,label:n,xMode:r,yMode:i,window:a,color:o,logX:s,height:c}},[e,t,n,r,i,a,o,s,c]);let _=dt(()=>e.length>=4?nq(e,t,a,i):null,[e,t,a,i]),v=dt(()=>_&&s?_.freqs.map(e=>Math.log10(e)):null,[_,s]),y=K(_&&{..._,logFreqs:v});G(()=>{y.current=_&&{..._,logFreqs:v}},[_,v]);function b(){if(m.current)return m.current;let e=p.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return m.current=n,n}function x(){let e=p.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||g.current.height)}}function S(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function C(){let e=f.current;if(!e)return;let{w:t,h:n}=x(),r=S(e,t,n);if(!r)return;let{top:i,right:a,bottom:o,left:s}=$K,c=t-s-a,l=n-i-o,{bg:u,muted:p,grid:m}=b(),{sampleRate:h,label:_,xMode:v,yMode:C,color:w,logX:T}=g.current,E=y.current;if(r.fillStyle=u,r.fillRect(0,0,t,n),!E||c<=0||l<=0){r.fillStyle=p,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`No data`,s+8,i+8);return}let{freqs:D,amps:O,logFreqs:k}=E,A=D.length,j=v===`hz`?`${_} (Hz)`:`${_} (order)`,M=v===`order`&&h>0?h:1,N=D[1]/M,P=D[A-1]/M,F=1/0,I=-1/0;for(let e=1;e<A;e++)O[e]<F&&(F=O[e]),O[e]>I&&(I=O[e]);if(!Number.isFinite(F)||!Number.isFinite(I)){r.fillStyle=p,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`No data`,s+8,i+8);return}let L=(I-F)*.05||.1;F-=L,I+=L;let R=T?e=>{if(e<=0||N<=0)return s;let t=Math.log10(N),n=Math.log10(P);return s+(Math.log10(e)-t)/(n-t)*c}:e=>s+(e-N)/(P-N)*c;T&&N<=0&&(N=D[1]>0?D[1]/M:.001),d({left:s,top:i,width:c,height:l,x:{v0:N,v1:P,log:T},y:{v0:F,v1:I}});let z=e=>i+(I-e)/(I-F)*l,B=wz(I-F,5),V=Dz(F,I,B);r.strokeStyle=m,r.lineWidth=1,r.setLineDash([3,3]);for(let e of V)r.beginPath(),r.moveTo(s,z(e)),r.lineTo(s+c,z(e)),r.stroke();r.setLineDash([]);let ee=T?1:wz(P-N,Tz(c)),te=T?(()=>{let e=[],t=Math.ceil(Math.log10(Math.max(N,1e-12))),n=Math.floor(Math.log10(P));for(let r=t;r<=n;r++)for(let t of[1,2,5]){let n=t*10**r;n>=N&&n<=P&&e.push(n)}return e})():Dz(N,P,ee);r.strokeStyle=m,r.lineWidth=1,r.setLineDash([3,3]);for(let e of te)r.beginPath(),r.moveTo(R(e),i),r.lineTo(R(e),i+l),r.stroke();r.setLineDash([]),r.strokeStyle=p,r.lineWidth=1,r.fillStyle=p,r.font=`11px ${Q.mono}`,r.textAlign=`right`,r.textBaseline=`middle`;for(let e of V)r.beginPath(),r.moveTo(s-eq,z(e)),r.lineTo(s,z(e)),r.stroke(),r.fillText(jz(e,B),s-4,z(e));r.textAlign=`center`,r.textBaseline=`top`;for(let e of te)r.beginPath(),r.moveTo(R(e),i+l),r.lineTo(R(e),i+l+eq),r.stroke(),r.fillText(jz(e,T?e:ee),R(e),i+l+eq+2);r.strokeStyle=m,r.lineWidth=1,r.strokeRect(s,i,c,l),r.save(),r.beginPath(),r.rect(s,i,c,l),r.clip(),r.strokeStyle=w,r.lineWidth=1,r.beginPath();let H=!1,ne=Math.min(2,window.devicePixelRatio||1),re=Math.max(1,Math.round(c*ne)),ie=A>re*4?T&&k?HK(k,O,Math.log10(N*M),Math.log10(P*M),re):HK(D,O,N*M,P*M,re):null;for(let e=+!ie;e<(ie?ie.length:A);e++){let t=ie?ie[e]:e;if(t<1)continue;let n=D[t]/M;if(n<N||n>P)continue;let i=R(n),a=z(O[t]);H?r.lineTo(i,a):(r.moveTo(i,a),H=!0)}r.stroke(),r.restore(),r.fillStyle=p,r.font=`11px ${Q.mono}`,r.save(),r.translate(14,i+l/2),r.rotate(-Math.PI/2),r.textAlign=`center`,r.textBaseline=`middle`,r.fillText(C===`db`?`dB`:`Amplitude`,0,0),r.restore(),r.textAlign=`center`,r.textBaseline=`bottom`,r.fillText(j,s+c/2,n-4)}let w=K(C);w.current=C;let T=K(null);T.current??=DH(()=>w.current(),()=>p.current);let E=()=>T.current.schedule();return W(()=>{T.current.now()}),W(()=>()=>T.current?.cancel(),[]),W(()=>{m.current=null,E()},[l]),G(()=>{let e=p.current;if(!e)return;let t=new EH(()=>{m.current=null,E()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=f.current;if(!e)return;let t=e=>{e.preventDefault(),h.current?.({clientX:e.clientX,clientY:e.clientY})};return e.addEventListener(`contextmenu`,t),()=>e.removeEventListener(`contextmenu`,t)},[]),q(`div`,{ref:p,style:{position:`relative`,width:`100%`,height:`100%`},children:q(`canvas`,{ref:f,className:`chart-canvas`,role:`img`,"aria-label":`Spectrum of ${n}`})})}function iq(e,t,n=0,r=e.length-1){for(;r>n;){let i=n+r>>>1,a=e[n],o=e[i],s=e[r];if(a>o){let e=a;a=o,o=e}o>s&&(o=s),a>o&&(o=a);let c=o,l=n,u=r;for(;l<=u;){for(;e[l]<c;)l++;for(;e[u]>c;)u--;if(l<=u){let t=e[l];e[l]=e[u],e[u]=t,l++,u--}}if(t<=u)r=u;else if(t>=l)n=l;else break}return e[t]}function aq(e,t){let n=e.length;if(n===0)return t.map(()=>0);let r=[...new Set(t.flatMap(e=>{let t=e/100*(n-1);return[Math.floor(t),Math.ceil(t)]}))].sort((e,t)=>e-t),i=new Map,a=0;for(let t of r)i.set(t,iq(e,t,a)),a=t;return t.map(e=>{let t=e/100*(n-1),r=Math.floor(t);return i.get(r)+(i.get(Math.ceil(t))-i.get(r))*(t-r)})}var oq={top:14,right:24,bottom:48,left:64},sq=5;function cq(e,t){let n=e.length;if(n===0)return null;let[r,i,a,o,s]=aq(Float64Array.from(e),[0,25,50,75,100]),c=0;for(let t=0;t<n;t++)c+=e[t];let l=c/n;if(t!==`1.5iqr`)return{q1:i,median:a,q3:o,mean:l,whiskerLo:r,whiskerHi:s,outliers:new Float64Array};let u=o-i,d=i-1.5*u,f=o+1.5*u,p=1/0,m=-1/0,h=0;for(let t=0;t<n;t++){let n=e[t];if(n<d||n>f){h++;continue}n<p&&(p=n),n>m&&(m=n)}let g=new Float64Array(h);for(let t=0,r=0;t<n;t++){let n=e[t];(n<d||n>f)&&(g[r++]=n)}return g.sort(),{q1:i,median:a,q3:o,mean:l,whiskerLo:p<=m?p:i,whiskerHi:p<=m?m:o,outliers:g}}function lq({groups:e,color:t=`#fb923c`,whiskers:n=`1.5iqr`,height:r=400,backgroundToken:i=``,onPlotContextMenu:a}){let o=nU(),s=K(null),c=K(null),l=K(null),u=K(a);G(()=>{u.current=a},[a]);let d=K({groups:e,color:t,whiskers:n,height:r});G(()=>{d.current={groups:e,color:t,whiskers:n,height:r}},[e,t,n,r]);let f=dt(()=>e.filter(e=>e.values.length>0).map(e=>({label:e.label,box:cq(e.values,n)})),[e,n]),p=K(f);G(()=>{p.current=f},[f]);function m(){if(l.current)return l.current;let e=c.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return l.current=n,n}function h(){let e=c.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||d.current.height)}}function g(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function _(){let e=s.current;if(!e)return;let{w:t,h:n}=h(),r=g(e,t,n);if(!r)return;let{top:i,right:a,bottom:c,left:l}=oq,u=t-l-a,f=n-i-c,{bg:_,muted:v,grid:y}=m(),{color:b}=d.current;r.fillStyle=_,r.fillRect(0,0,t,n);let x=p.current;if(x.length===0||u<=0||f<=0){r.fillStyle=v,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`No data`,l+8,i+8);return}let S=1/0,C=-1/0;for(let e of x){e.box.whiskerLo<S&&(S=e.box.whiskerLo),e.box.whiskerHi>C&&(C=e.box.whiskerHi);for(let t of e.box.outliers)t<S&&(S=t),t>C&&(C=t)}let w=(C-S)*.08||1;S-=w,C+=w;let T=e=>i+(C-e)/(C-S)*f;o({left:l,top:i,width:u,height:f,y:{v0:S,v1:C}});let E=wz(C-S,5),D=Dz(S,C,E);r.strokeStyle=y,r.lineWidth=1,r.setLineDash([3,3]);for(let e of D)r.beginPath(),r.moveTo(l,T(e)),r.lineTo(l+u,T(e)),r.stroke();r.setLineDash([]),r.strokeStyle=v,r.lineWidth=1,r.fillStyle=v,r.font=`11px ${Q.mono}`,r.textAlign=`right`,r.textBaseline=`middle`;for(let e of D)r.beginPath(),r.moveTo(l-sq,T(e)),r.lineTo(l,T(e)),r.stroke(),r.fillText(jz(e,E),l-4,T(e));r.strokeStyle=y,r.lineWidth=1,r.strokeRect(l,i,u,f),r.save(),r.beginPath(),r.rect(l,i,u,f),r.clip();let O=x.length,k=u/O,A=Math.min(k*.55,60);for(let e=0;e<O;e++){let{box:t}=x[e],n=l+k*e+k/2;r.strokeStyle=b,r.lineWidth=1.5,r.beginPath(),r.moveTo(n,T(t.whiskerLo)),r.lineTo(n,T(t.whiskerHi)),r.stroke();let i=A*.35;r.beginPath(),r.moveTo(n-i,T(t.whiskerLo)),r.lineTo(n+i,T(t.whiskerLo)),r.moveTo(n-i,T(t.whiskerHi)),r.lineTo(n+i,T(t.whiskerHi)),r.stroke();let a=n-A/2,o=T(t.q3),s=Math.max(1,T(t.q1)-o);r.fillStyle=b,r.globalAlpha=.25,r.fillRect(a,o,A,s),r.globalAlpha=1,r.strokeStyle=b,r.lineWidth=1.5,r.strokeRect(a,o,A,s),r.strokeStyle=b,r.lineWidth=2.5,r.beginPath(),r.moveTo(a,T(t.median)),r.lineTo(a+A,T(t.median)),r.stroke();let c=T(t.mean);r.fillStyle=b,r.beginPath(),r.moveTo(n,c-5),r.lineTo(n+5,c),r.lineTo(n,c+5),r.lineTo(n-5,c),r.closePath(),r.fill(),r.fillStyle=b,r.globalAlpha=.6;let u=NaN;for(let e of t.outliers){let t=T(e);Math.abs(t-u)<.5||(u=t,r.beginPath(),r.arc(n,t,2.5,0,Math.PI*2),r.fill())}r.globalAlpha=1}r.restore(),r.fillStyle=v,r.font=`11px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`top`;for(let e=0;e<O;e++){let t=l+k*e+k/2,n=x[e].label;r.save(),r.rect(l+k*e+2,i+f+sq+2,k-4,c-sq-4),r.clip(),r.fillText(n,t,i+f+sq+2),r.restore()}}let v=K(_);v.current=_;let y=K(null);y.current??=DH(()=>v.current(),()=>c.current);let b=()=>y.current.schedule();return W(()=>{y.current.now()}),W(()=>()=>y.current?.cancel(),[]),W(()=>{l.current=null,b()},[i]),G(()=>{let e=c.current;if(!e)return;let t=new EH(()=>{l.current=null,b()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=s.current;if(!e)return;let t=e=>{e.preventDefault(),u.current?.({clientX:e.clientX,clientY:e.clientY})};return e.addEventListener(`contextmenu`,t),()=>e.removeEventListener(`contextmenu`,t)},[]),q(`div`,{ref:c,style:{position:`relative`,width:`100%`,height:`100%`},children:q(`canvas`,{ref:s,className:`chart-canvas`,role:`img`,"aria-label":`Box plot`})})}function uq(e,t){if(e.w<=t)return{grid:e,per:1};let n=e.w/t,r=new Float32Array(t*e.h);for(let i=0;i<e.h;i++){let a=i*e.w;for(let o=0;o<t;o++){let s=Math.floor(o*n),c=Math.min(e.w,Math.floor((o+1)*n)),l=0,u=0;for(let t=s;t<c;t++){let n=e.values[a+t];n===n&&(l+=n,u++)}r[i*t+o]=u?l/u:NaN}}let i=e.xLabels;return{grid:{w:t,h:e.h,values:r,xLabels:e=>typeof i==`function`?i(Math.floor(e*n)):i[Math.floor(e*n)],yLabels:e.yLabels},per:n}}var dq=e=>e.includes(`.`)&&!e.includes(`e`)?e.replace(/\.?0+$/,``):e;function fq(e){return e>=1e3?`${dq((e/1e3).toPrecision(3))}k`:dq(e.toPrecision(3))}function pq(e,t,n,r,i,a,o){let s=t>>1,c=e.length,l=c>=t?Math.floor((c-t)/n)+1:0,u=`${t}|${n}|${r}|${i}|${a?a.join(`,`):``}`,d=-1,f=0;if(o&&o.key===u&&o.frames>0&&c>0){let r=o.sig;for(let i=0;i*n<r.length&&f===0;i++){let a=i*n;if(r[a]!==e[0])continue;let s=Math.min(r.length-a,c),u=!0;for(let t=0;t<s;t++)if(r[a+t]!==e[t]){u=!1;break}if(!u)continue;let p=s>=t?Math.floor((s-t)/n)+1:0;d=i,f=Math.max(0,Math.min(p,o.frames-i,l))}}let p=new Float32Array(l*s),m=new Float32Array(l);if(f>0){for(let e=0;e<s;e++)p.set(o.values.subarray(e*o.frames+d,e*o.frames+d+f),e*l);m.set(o.frameMax.subarray(d,d+f))}let h=new Float64Array(t);for(let e=0;e<t;e++)h[e]=r?.5*(1-Math.cos(2*Math.PI*e/(t-1))):1;let g=Math.log2(t),_=new Uint32Array(t);for(let e=0;e<t;e++){let t=0,n=e;for(let e=0;e<g;e++)t=t<<1|n&1,n>>=1;_[e]=t}let v=new Float64Array(t),y=new Float64Array(t),b=new Float64Array(s);for(let r=f;r<l;r++){let o=r*n;for(let n=0;n<t;n++){let t=_[n];v[n]=e[o+t]*h[t],y[n]=0}for(let e=2;e<=t;e<<=1){let n=e>>1,r=-2*Math.PI/e,i=Math.cos(r),a=Math.sin(r);for(let r=0;r<t;r+=e){let e=1,t=0;for(let o=0;o<n;o++){let s=r+o,c=s+n,l=v[c]*e-y[c]*t,u=v[c]*t+y[c]*e;v[c]=v[s]-l,y[c]=y[s]-u,v[s]+=l,y[s]+=u;let d=e*i-t*a;t=e*a+t*i,e=d}}}let c=0;for(let e=0;e<s;e++){let n=Math.sqrt(v[e]*v[e]+y[e]*y[e])/t;b[e]=n,n>c&&(c=n)}m[r]=c;for(let e=0;e<s;e++){let t=b[a?a[e]:e];p[e*l+r]=i?20*Math.log10(Math.max(t,1e-12)):t}}let x=1e-10;for(let e=0;e<l;e++)m[e]>x&&(x=m[e]);return{values:p,frames:l,bins:s,max:x,computed:l-f,sig:Float64Array.from(e),frameMax:m,key:u}}var mq={top:14,right:24,bottom:40,left:68},hq=[[8,0,16],[48,0,96],[104,0,144],[160,0,128],[200,32,64],[230,100,16],[250,200,32],[255,255,220]],gq=-80;function _q(e){let t=hq.length-1,n=Math.min(t-1,Math.floor(e*t)),r=e*t-n,[i,a,o]=hq[n],[s,c,l]=hq[n+1];return[i+(s-i)*r,a+(c-a)*r,o+(l-o)*r]}var vq=(()=>{let e=new Uint8Array(256*4);for(let t=0;t<256;t++){let[n,r,i]=_q(t/255);e.set([n,r,i,255],t*4)}return e})();function yq(e){let t=1;for(;t<e;)t<<=1;return t}var bq=(e,t)=>Math.log(1+e/t*9)/Math.log(10),xq=(e,t)=>t*(10**e-1)/9;function Sq({signal:e,sampleRate:t=1e3,windowSize:n=512,overlap:r=.5,winFunc:i=`hann`,yMode:a=`db`,logFreq:o=!1,label:s=``,backgroundToken:c=``,onPlotContextMenu:l}){let u=nU(),d=K(null),f=K(null),p=K(null),m=K(null),h=K(null),g=K(l);G(()=>{g.current=l},[l]);let _=yq(Math.max(4,Math.min(n,4096))),v=Math.max(1,Math.round(_*(1-Math.max(0,Math.min(.95,r))))),y=dt(()=>{if(!o)return null;let e=_>>1,n=t/2;return Int32Array.from({length:e},(t,r)=>Math.min(e-1,Math.floor(xq((r+.5)/e,n)/n*e)))},[o,_,t]),b=K(null),x=dt(()=>b.current=pq(e,_,v,i===`hann`,a===`db`,y,b.current),[e,_,v,i,a,y]),S=dt(()=>({w:x.frames,h:x.bins,values:x.values,xLabels:[],yLabels:[]}),[x]),C=a===`db`?20*Math.log10(x.max):x.max,w=a===`db`?[C+gq,C]:[0,C],T=K({grid:S,range:w,sampleRate:t,winSz:_,step:v,yMode:a,logFreq:o,label:s});G(()=>{T.current={grid:S,range:w,sampleRate:t,winSz:_,step:v,yMode:a,logFreq:o,label:s}},[S,w[0],w[1],t,_,v,a,o,s]);let E=K({plot:null,failed:!1,size:``,grid:null,shown:null});W(()=>()=>{E.current.plot?.dispose(),E.current.plot=null},[]);function D(){if(h.current)return h.current;let e=m.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return h.current=n,n}function O(){let e=m.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function k(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function A(e,t){let n=E.current;if(!n.plot&&!n.failed&&f.current&&(n.plot=uH(f.current,IK),n.failed=!n.plot),!n.plot||!f.current)return null;let r=Math.min(2,window.devicePixelRatio||1),i=`${e}x${t}@${r}`;return n.size!==i&&(n.plot.resize(e,t,r),f.current.style.width=`${e}px`,f.current.style.height=`${t}px`,n.size=i),n.plot}function j(){let e=d.current;if(!e)return;let{w:t,h:n}=O(),r=k(e,t,n);if(!r)return;let i=p.current?k(p.current,t,n):null;i?.clearRect(0,0,t,n);let a=YW(mq,t,n),{top:o,right:s,bottom:c,left:l}=a,f=t-l-s,h=n-o-c,{bg:g,muted:_,grid:v}=D(),{grid:y,sampleRate:b,winSz:x,step:S,logFreq:C,label:w}=T.current;r.fillStyle=g,r.fillRect(0,0,t,n);let j=A(t,n);if(y.w===0||f<=0||h<=0){if(j?.keep([]),j?.render(),a.tiny)return;r.fillStyle=_,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`No data`,l+8,o+8);return}let M=Math.min(2,window.devicePixelRatio||1),N=j?j.maxTextureSize:Math.max(1,Math.round(f*M)),[P,F]=T.current.range;if(E.current.grid!==y||!E.current.shown||!j&&E.current.shown.w>N){let e=uq(y,N).grid;j&&j.setGrid(`cells`,e.values,e.w,Math.min(e.h,j.maxTextureSize),[0,e.w,0,e.h],vq,P,F),E.current.grid=y,E.current.shown=e,CH(m.current)}let I=E.current.shown;if(j)j.keep([`cells`]),j.setGridRange(`cells`,P,F),j.setView(0,I.w,0,I.h,{left:l,top:o,width:f,height:h}),j.render();else{let e=document.createElement(`canvas`);e.width=I.w,e.height=I.h;let t=e.getContext(`2d`),n=t.createImageData(I.w,I.h);for(let e=0;e<I.h;e++)for(let t=0;t<I.w;t++){let[r,i,a]=_q(Math.max(0,Math.min(1,(I.values[e*I.w+t]-P)/(F-P)))),o=(t+(I.h-1-e)*I.w)*4;n.data[o]=r,n.data[o+1]=i,n.data[o+2]=a,n.data[o+3]=255}t.putImageData(n,0,0),r.drawImage(e,l,o,f,h)}if(a.tiny)return;let L=i??r,R=b/2,z=e=>o+h*(1-(C?bq(e,R):e/R));L.strokeStyle=v,L.lineWidth=.5,L.globalAlpha=.4;let B=Dz(0,R,wz(R,5));L.setLineDash([3,4]);for(let e of B){let t=z(e);L.beginPath(),L.moveTo(l,t),L.lineTo(l+f,t),L.stroke()}L.setLineDash([]),L.globalAlpha=1,L.strokeStyle=v,L.strokeRect(l,o,f,h),r.fillStyle=_,r.font=`10px ${Q.mono}`,r.textAlign=`right`,r.textBaseline=`middle`,r.strokeStyle=_,r.lineWidth=1;for(let e of B){let t=z(e);r.beginPath(),r.moveTo(l-4,t),r.lineTo(l,t),r.stroke(),r.fillText(fq(e),l-6,t)}let V=(y.w*S+x)/b;u({left:l,top:o,width:f,height:h,x:{v0:0,v1:V}});let ee=wz(V,6),te=Dz(0,V,ee);r.textAlign=`center`,r.textBaseline=`top`;for(let e of te){let t=l+e/V*f;r.beginPath(),r.moveTo(t,o+h),r.lineTo(t,o+h+4),r.stroke(),r.fillText(jz(e,ee),t,o+h+6)}r.fillStyle=_,r.textAlign=`center`,r.textBaseline=`bottom`,r.fillText(w||`Time (s)`,l+f/2,n-4),r.save(),r.translate(12,o+h/2),r.rotate(-Math.PI/2),r.textAlign=`center`,r.fillText(`Frequency (Hz)`,0,0),r.restore()}let M=K(j);G(()=>{M.current=j});let N=K(null);return N.current??=DH(()=>M.current(),()=>m.current),W(()=>{N.current.now()},[S,w[0],w[1],t,_,v,a,o,s]),W(()=>()=>N.current?.cancel(),[]),W(()=>{h.current=null,N.current.schedule()},[c]),G(()=>{let e=m.current;if(!e)return;let t=new EH(()=>{h.current=null,N.current.schedule()});return t.observe(e),()=>t.disconnect()},[]),G(()=>{let e=p.current;if(!e)return;let t=e=>{e.preventDefault(),g.current?.({clientX:e.clientX,clientY:e.clientY})};return e.addEventListener(`contextmenu`,t),()=>e.removeEventListener(`contextmenu`,t)},[]),_t(`div`,{ref:m,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:d,className:`chart-canvas`,role:`img`,"aria-label":`Spectrogram`}),q(`canvas`,{ref:f,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),q(`canvas`,{ref:p,className:`chart-canvas chart-overlay`})]})}var Cq=300,wq=256,Tq=-60,Eq=[];function Dq({signal:e,sampleRate:t,windowSize:n,overlap:r,winFunc:i,yMode:a,backgroundToken:o,onPlotContextMenu:s}){let c=2**Math.ceil(Math.log2(Math.max(4,Math.min(n,4096)))),l=Math.max(1,Math.round(c*(1-Math.max(0,Math.min(.95,r))))),u=a===`db`,d=dt(()=>pq(e,c,l,i===`hann`,u,null),[e,c,l,i,u]);return q(gK,{points:Eq,surface:dt(()=>Oq(d,t,c,l,u),[d,t,c,l,u]),xLabel:`Time (s)`,yLabel:`Frequency (Hz)`,zLabel:u?`Level (dB)`:`Amplitude`,viewMode:`3d`,showMesh:!0,meshStyle:`filled`,meshOpacity:1,backgroundToken:o,onPlotContextMenu:s})}function Oq(e,t,n,r,i){let{frames:a,bins:o,values:s}=e;if(a<2||o<2)return;let c=Math.min(a,Cq),l=Math.min(o,wq),u=i?20*Math.log10(Math.max(e.max,1e-12))+Tq:-1/0,d=new Float32Array(c*l);for(let e=0;e<l;e++){let t=Math.floor(e*o/l),n=Math.max(t+1,Math.floor((e+1)*o/l));for(let r=0;r<c;r++){let i=Math.floor(r*a/c),o=Math.max(i+1,Math.floor((r+1)*a/c)),l=-1/0;for(let e=t;e<n;e++)for(let t=i;t<o;t++){let n=s[e*a+t];n>l&&(l=n)}d[e*c+r]=Math.max(u,l)}}let f=e=>(e*r+n/2)/t;return{w:c,h:l,values:d,x:[f(0),f(a-1)],y:[0,(o-1)*t/n]}}function kq(e,t,n){return Array.from({length:n},(r,i)=>e+(i+1)/(n+1)*(t-e))}function Aq(e,t,n,r){let i=[],a=(n,r)=>e[r*t+n],o=(e,t)=>(r-e)/(t-e);for(let e=0;e+1<n;e++)for(let n=0;n+1<t;n++){let t=a(n,e),s=a(n+1,e),c=a(n+1,e+1),l=a(n,e+1);if(t!==t||s!==s||c!==c||l!==l)continue;let u=(t>=r?8:0)|(s>=r?4:0)|(c>=r?2:0)|l>=r;if(u===0||u===15)continue;let d=()=>[n+o(t,s),e],f=()=>[n+1,e+o(s,c)],p=()=>[n+o(l,c),e+1],m=()=>[n,e+o(t,l)],h=(e,t)=>i.push([e[0],e[1],t[0],t[1]]);switch(u){case 1:case 14:h(m(),p());break;case 2:case 13:h(p(),f());break;case 3:case 12:h(m(),f());break;case 4:case 11:h(d(),f());break;case 6:case 9:h(d(),p());break;case 7:case 8:h(m(),d());break;case 5:case 10:{let e=(t+s+c+l)/4>=r;u===5===e?(h(m(),d()),h(p(),f())):(h(d(),f()),h(m(),p()));break}}}return i}function jq(e){let t=e.length,n=new Float64Array(t+1);if(t===1)return n[0]=e[0]-.5,n[1]=e[0]+.5,n;for(let r=1;r<t;r++)n[r]=(e[r-1]+e[r])/2;return n[0]=e[0]-(n[1]-e[0]),n[t]=e[t-1]+(e[t-1]-n[t-1]),n}function Mq(e){if(e.length===0)return!1;for(let t=0;t<e.length;t++)if(!Number.isFinite(e[t])||t>0&&!(e[t]>e[t-1]))return!1;return!0}var Nq={top:14,right:32,bottom:80,left:80};function Pq(e,t,n){return[e[0]+(t[0]-e[0])*n,e[1]+(t[1]-e[1])*n,e[2]+(t[2]-e[2])*n]}var Fq=[[33,102,172],[103,169,207],[209,229,240],[247,247,247],[253,219,199],[239,138,98],[178,24,43]],Iq=[[13,8,135],[84,2,163],[139,10,165],[185,50,137],[219,92,104],[244,136,73],[254,188,43],[240,249,33]],Lq=[[68,1,84],[72,40,120],[62,83,160],[49,120,178],[38,153,185],[31,184,187],[53,213,158],[117,231,101],[198,239,82],[253,231,37]];function Rq(e,t){let n=e.length-1,r=Math.min(n-1,Math.floor(t*n));return Pq(e[r],e[r+1],t*n-r)}function zq(e,t){return Rq(t===`plasma`?Iq:t===`viridis`?Lq:Fq,e)}function Bq(e){let t=new Uint8Array(256*4);for(let n=0;n<256;n++){let[r,i,a]=zq(n/255,e);t.set([r,i,a,255],n*4)}return t}function Vq(e){return Math.abs(e)>=1e4||Math.abs(e)<.01&&e!==0?e.toExponential(1):String(parseFloat(e.toPrecision(3)))}function Hq(e,t,n){let r=new Map(t.map((e,t)=>[e,t])),i=new Map(n.map((e,t)=>[e,t])),a=new Float32Array(t.length*n.length);for(let n of e){let e=r.get(n.x),o=i.get(n.y);e!==void 0&&o!==void 0&&(a[o*t.length+e]=n.value)}return{w:t.length,h:n.length,values:a,xLabels:t,yLabels:n}}function Uq(e,t,n,r,i,a,o){let s=(e,t,n)=>Float64Array.from({length:e+1},(r,i)=>t+i/e*n),c=!!a&&a.length===e.w,l=!!o&&o.length===e.h,u=s(e.w,t,r),d=s(e.h,n,i);if(c){let n=jq(a),i=n[e.w]-n[0];u=Float64Array.from(n,e=>t+(e-n[0])/i*r)}if(l){let t=jq(Float64Array.from(o).reverse()),r=e.h,a=t[r]-t[0];d=Float64Array.from({length:r+1},(e,o)=>n+(t[r]-t[r-o])/a*i)}return{xB:u,yB:d,byValue:c||l}}function Wq(e,t){if(t<e[0]||t>=e[e.length-1])return-1;let n=0,r=e.length-1;for(;r-n>1;){let i=n+r>>1;e[i]<=t?n=i:r=i}return n}function Gq(e,t,n,r,i,a){let o=Math.max(1,i),s=Math.max(1,a),c=Int32Array.from({length:o},(e,r)=>Wq(t.xB,n+r+.5)),l=new Float32Array(o*s);for(let n=0;n<s;n++){let i=Wq(t.yB,r+n+.5),a=i*e.w;for(let t=0;t<o;t++)l[n*o+t]=i<0||c[t]<0?NaN:e.values[a+c[t]]}return{w:o,h:s,values:l,xLabels:e.xLabels,yLabels:e.yLabels}}function Kq({cells:e,xLabels:t,yLabels:n,grid:r,showValues:i=!0,colorScheme:a=`diverging`,vMin:o,vMax:s,xCentres:c,yCentres:l,contours:u=0,backgroundToken:d=``,onPlotContextMenu:f}){let p=K(null),m=K(null),h=K(null),g=K(null),_=K(null),v=K(null),y=K(null),b=K(0),x=K(f);G(()=>{x.current=f},[f]);let S=dt(()=>r??Hq(e??[],t??[],n??[]),[r,e,t,n]),C=dt(()=>{let e=o??1/0,t=s??-1/0;if(o===void 0||s===void 0){let n=1/0,r=-1/0;for(let e=0;e<S.w*S.h;e++){let t=S.values[e];t<n&&(n=t),t>r&&(r=t)}o===void 0&&(e=n),s===void 0&&(t=r)}return t>e||(e=Number.isFinite(e)?e-1:0,t=e+2),{lo:e,hi:t}},[S,o,s]),w=K({data:S,range:C,showValues:i,colorScheme:a,xCentres:c,yCentres:l,contours:u});G(()=>{w.current={data:S,range:C,showValues:i,colorScheme:a,xCentres:c,yCentres:l,contours:u}},[S,C,i,a,c,l,u]);let T=K({plot:null,failed:!1,size:``,data:null,key:``,shown:null,geo:null}),E=K({key:``,grid:null,segs:[]});W(()=>()=>{T.current.plot?.dispose(),T.current.plot=null},[]);let D=K({data:null,range:``});function O(){if(v.current)return v.current;let e=_.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return v.current=n,n}function k(){let e=_.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function A(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function j(e,t){let n=T.current;if(!n.plot&&!n.failed&&m.current&&(n.plot=uH(m.current,IK),n.failed=!n.plot),!n.plot||!m.current)return null;let r=Math.min(2,window.devicePixelRatio||1),i=`${e}x${t}@${r}`;return n.size!==i&&(n.plot.resize(e,t,r),m.current.style.width=`${e}px`,m.current.style.height=`${t}px`,n.size=i),n.plot}let M=(e,t)=>typeof e==`function`?e(t):e[t];function N(){let e=p.current;if(!e)return;let{w:t,h:n}=k(),r=A(e,t,n);if(!r)return;let i=h.current?A(h.current,t,n):null;i?.clearRect(0,0,t,n);let a=YW(Nq,t,n),{top:o,right:s,bottom:c,left:l}=a,{bg:u,muted:d,grid:f}=O(),{data:m,range:{lo:g,hi:v},showValues:y,colorScheme:b}=w.current;r.fillStyle=u,r.fillRect(0,0,t,n);let x=j(t,n);if(m.w===0||m.h===0){x?.keep([]),x?.render(),r.fillStyle=d,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`No data`,l+8,o+8);return}let S=t-l-s,C=n-o-c,N=Math.min(2,window.devicePixelRatio||1),P=D.current;(P.data!==m||P.range!==`${g}|${v}`)&&(D.current={data:m,range:`${g}|${v}`},CH(_.current));let{xCentres:F,yCentres:I,contours:L}=w.current,R=x?x.maxTextureSize:Math.max(1,Math.round(S*N)),z=uq(m,R).grid,B=Uq(z,l,o,S,C,z===m?F:void 0,z===m?I:void 0),V=B.byValue,ee=`${R}|${b}|${V?`${S}x${C}`:``}`,te=T.current.shown;if(T.current.data!==m||T.current.key!==ee||!te){te=z;let e=V?Gq(te,B,l,o,Math.round(S),Math.round(C)):te;x&&x.setGrid(`cells`,e.values,e.w,Math.min(e.h,x.maxTextureSize),[0,e.w,0,e.h],Bq(b),g,v),T.current.data=m,T.current.key=ee,T.current.shown=te}T.current.geo=B;let H=V?Math.round(S):te.w,ne=V?Math.round(C):te.h,re=e=>B.xB[e+1]-B.xB[e],ie=e=>B.yB[e+1]-B.yB[e];if(x)x.keep([`cells`]),x.setGridRange(`cells`,g,v),x.setView(0,H,ne,0,{left:l,top:o,width:S,height:C}),x.render();else for(let e=0;e<te.h;e++)for(let t=0;t<te.w;t++){let n=te.values[e*te.w+t];if(Number.isNaN(n))continue;let[i,a,o]=zq(Math.max(0,Math.min(1,(n-g)/(v-g))),b);r.fillStyle=`rgb(${i|0},${a|0},${o|0})`,r.fillRect(B.xB[t],B.yB[e],re(t)+.5,ie(e)+.5)}let U=i??r;if(y){for(let e=0;e<te.h;e++)if(!(ie(e)<=16)){U.font=`${Math.min(12,Math.max(8,ie(e)*.4))}px ${Q.mono}`,U.textAlign=`center`,U.textBaseline=`middle`;for(let t=0;t<te.w;t++){let n=te.values[e*te.w+t];if(Number.isNaN(n)||re(t)<=28)continue;let[r,i,a]=zq(Math.max(0,Math.min(1,(n-g)/(v-g))),b);U.fillStyle=.299*r+.587*i+.114*a>128?`#000`:`#fff`,U.fillText(Vq(n),(B.xB[t]+B.xB[t+1])/2,(B.yB[e]+B.yB[e+1])/2)}}}if(S/te.w>=4&&C/te.h>=4){U.strokeStyle=u,U.lineWidth=.5;for(let e=0;e<=te.w;e++)U.beginPath(),U.moveTo(B.xB[e],o),U.lineTo(B.xB[e],o+C),U.stroke();for(let e=0;e<=te.h;e++)U.beginPath(),U.moveTo(l,B.yB[e]),U.lineTo(l+S,B.yB[e]),U.stroke()}let ae=L>0?kq(g,v,L):[];if(ae.length&&te.w>=2&&te.h>=2&&te.w*te.h<=4e6){let e=`${g}|${v}|${L}`;if(E.current.grid!==te||E.current.key!==e){let t=te;E.current={key:e,grid:t,segs:ae.map(e=>Aq(t.values,t.w,t.h,e))}}let t=(e,t)=>{let n=Math.min(t.length-3,Math.max(0,Math.floor(e))),r=(t[n]+t[n+1])/2;return r+((t[n+1]+t[n+2])/2-r)*(e-n)};U.save(),U.beginPath(),U.rect(l,o,S,C),U.clip(),U.lineCap=`round`,U.lineJoin=`round`;for(let[e,n]of[[2.6,`rgba(0,0,0,0.38)`],[1.1,`rgba(255,255,255,0.92)`]]){U.lineWidth=e,U.strokeStyle=n,U.beginPath();for(let e of E.current.segs)for(let[n,r,i,a]of e)U.moveTo(t(n,B.xB),t(r,B.yB)),U.lineTo(t(i,B.xB),t(a,B.yB));U.stroke()}U.restore()}r.fillStyle=d,r.font=`10px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`top`;let oe=-1/0;for(let e=0;e<(a.tiny?0:te.w);e++){let t=(B.xB[e]+B.xB[e+1])/2;t-oe<18||(oe=t,r.save(),r.translate(t,o+C+4),r.rotate(-Math.PI/4),r.fillText(M(te.xLabels,e),0,0),r.restore())}r.textAlign=`right`,r.textBaseline=`middle`;let se=-1/0;for(let e=0;e<(a.tiny?0:te.h);e++){let t=(B.yB[e]+B.yB[e+1])/2;t-se<12||(se=t,r.fillText(te.yLabels[e]??``,l-4,t))}if(a.tiny)return;let ce=t-s+4,le=o,ue=C;for(let e=0;e<ue;e++){let[t,n,i]=zq(1-e/ue,b);r.fillStyle=`rgb(${t|0},${n|0},${i|0})`,r.fillRect(ce,le+e,12,1)}r.strokeStyle=f,r.lineWidth=.5,r.strokeRect(ce,le,12,ue),r.fillStyle=d,r.font=`9px ${Q.mono}`,r.textAlign=`left`,r.textBaseline=`middle`,r.fillText(Vq(v),ce+12+2,le),r.fillText(Vq(g),ce+12+2,le+ue),r.fillText(Vq((g+v)/2),ce+12+2,le+ue/2),r.strokeStyle=`rgba(255,255,255,0.92)`,r.lineWidth=1;for(let e of ae){let t=le+ue*(1-(e-g)/(v-g));r.beginPath(),r.moveTo(ce-2,t),r.lineTo(ce+12+2,t),r.stroke()}}function P(){let e=g.current;if(!e)return;let{w:t,h:n}=k(),r=A(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=y.current,a=T.current.shown,o=T.current.geo;if(!i||!a||!o)return;let{top:s,right:c,bottom:l}=YW(Nq,t,n),{xi:u,yi:d}=i;if(u>=a.w||d>=a.h)return;let f=o.xB[u],p=o.xB[u+1],m=o.yB[d],h=o.yB[d+1];r.strokeStyle=`rgba(255,255,255,0.7)`,r.lineWidth=1.5,r.strokeRect(f+.5,m+.5,Math.max(1,p-f-1),Math.max(1,h-m-1));let _=a.values[d*a.w+u];if(!Number.isNaN(_)){let e=`${M(a.xLabels,u)} × ${a.yLabels[d]}: ${Vq(_)}`;r.font=`11px ${Q.mono}`;let n=r.measureText(e).width,i=Math.min(p+.1*(p-f),t-c-n-6),o=Math.max(s+4,m-.3*(h-m));r.fillStyle=`rgba(0,0,0,0.7)`,r.fillRect(i-3,o-3,n+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(e,i,o)}}let F=K(N);F.current=N;let I=K(null);I.current??=DH(()=>F.current(),()=>_.current);let L=()=>{b.current||=bH(()=>{b.current=0,P()})};return W(()=>{I.current.now()},[S,C,i,a,c,l,u]),W(()=>()=>{I.current?.cancel(),xH(b.current)},[]),W(()=>{v.current=null,I.current.schedule()},[d]),G(()=>{let e=_.current;if(!e)return;let t=new EH(()=>{v.current=null,I.current.schedule(),L()});return t.observe(e),()=>t.disconnect()},[]),G(()=>{let e=g.current;if(!e)return;let t=e=>{e.preventDefault(),x.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),{shown:r,geo:i}=T.current;if(!r||!i)return;let a=Wq(i.xB,t.clientX-n.left),o=Wq(i.yB,t.clientY-n.top);y.current=a>=0&&a<r.w&&o>=0&&o<r.h?{xi:a,yi:o}:null,L()},r=()=>{y.current=null,L()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),_t(`div`,{ref:_,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:p,className:`chart-canvas`,role:`img`,"aria-label":`Heatmap`}),q(`canvas`,{ref:m,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),q(`canvas`,{ref:h,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),q(`canvas`,{ref:g,className:`chart-canvas chart-overlay`})]})}var qq=2e3,Jq=1024;function Yq(e,t,n,r,i){let a=e.length,o=1/(a*t*Math.sqrt(2*Math.PI)),s=new Float64Array(n.length);if(a<=qq){for(let r=0;r<n.length;r++){let i=0;for(let o=0;o<a;o++){let a=(n[r]-e[o])/t;i+=Math.exp(-.5*a*a)}s[r]=i*o}return s}let c=new Float64Array(Jq),l=(i-r)/Jq||1;for(let t=0;t<a;t++)c[Math.max(0,Math.min(Jq-1,Math.floor((e[t]-r)/l)))]++;for(let e=0;e<n.length;e++){let i=0;for(let a=0;a<Jq;a++){if(c[a]===0)continue;let o=(n[e]-(r+(a+.5)*l))/t;i+=c[a]*Math.exp(-.5*o*o)}s[e]=i*o}return s}var Xq={top:14,right:24,bottom:48,left:64},Zq=120;function Qq(e,t,n){let r=e.length;if(r<2)return 1;let i=0;for(let t=0;t<r;t++)i+=e[t];let a=i/r,o=0;for(let t=0;t<r;t++)o+=(e[t]-a)**2;let s=Math.sqrt(o/(r-1));return .9*Math.min(s,(n-t)/1.34)*r**-.2}function $q(e,t){let n=e.filter(e=>e.values.length>=2),r=1/0,i=-1/0,a=n.map(e=>{let[t,n,a,o,s]=aq(Float64Array.from(e.values),[0,25,50,75,100]);return t<r&&(r=t),s>i&&(i=s),{q1:n,median:a,q3:o}}),o=(i-r)*.1||1;r-=o,i+=o;let s=Float64Array.from({length:Zq},(e,t)=>r+t/(Zq-1)*(i-r));return{shapes:n.map((e,n)=>{let{q1:o,median:c,q3:l}=a[n],u=Yq(e.values,t>0?t:Qq(e.values,o,l),s,r,i),d=1e-10;for(let e of u)e>d&&(d=e);return{label:e.label,density:u,maxDensity:d,q1:o,median:c,q3:l}}),pts:s,yMin:r,yMax:i}}function eJ({groups:e,color:t=`#818cf8`,showBox:n=!0,bandwidth:r=0,orientation:i=`vertical`,backgroundToken:a=``,onPlotContextMenu:o}){let s=nU(),c=K(null),l=K(null),u=K(null),d=K(o);G(()=>{d.current=o},[o]);let f=K({groups:e,color:t,showBox:n,bandwidth:r,orientation:i});G(()=>{f.current={groups:e,color:t,showBox:n,bandwidth:r,orientation:i}},[e,t,n,r,i]);let p=dt(()=>$q(e,r),[e,r]),m=K(p);G(()=>{m.current=p},[p]);function h(){if(u.current)return u.current;let e=l.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return u.current=n,n}function g(){let e=l.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function _(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function v(){let e=c.current;if(!e)return;let{w:t,h:n}=g(),r=_(e,t,n);if(!r)return;let{top:i,right:a,bottom:o,left:l}=Xq,u=t-l-a,d=n-i-o,{bg:p,muted:v,grid:y}=h(),{color:b,showBox:x,orientation:S}=f.current;r.fillStyle=p,r.fillRect(0,0,t,n);let{shapes:C,pts:w,yMin:T,yMax:E}=m.current;if(C.length===0||u<=0||d<=0){r.fillStyle=v,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`No data`,l+8,i+8);return}let D=S===`vertical`,O=D?e=>i+d*(1-(e-T)/(E-T)):e=>l+u*((e-T)/(E-T));s({left:l,top:i,width:u,height:d,...D?{y:{v0:T,v1:E}}:{x:{v0:T,v1:E}}});let k=wz(E-T,5),A=Dz(T,E,k);r.strokeStyle=y,r.lineWidth=1,r.setLineDash([3,3]);for(let e of A)D?(r.beginPath(),r.moveTo(l,O(e)),r.lineTo(l+u,O(e)),r.stroke()):(r.beginPath(),r.moveTo(O(e),i),r.lineTo(O(e),i+d),r.stroke());if(r.setLineDash([]),r.fillStyle=v,r.font=`11px ${Q.mono}`,r.strokeStyle=v,r.lineWidth=1,D){r.textAlign=`right`,r.textBaseline=`middle`;for(let e of A)r.beginPath(),r.moveTo(l-4,O(e)),r.lineTo(l,O(e)),r.stroke(),r.fillText(jz(e,k),l-6,O(e))}else{r.textAlign=`center`,r.textBaseline=`top`;for(let e of A)r.beginPath(),r.moveTo(O(e),i+d),r.lineTo(O(e),i+d+4),r.stroke(),r.fillText(jz(e,k),O(e),i+d+6)}r.strokeStyle=y,r.strokeRect(l,i,u,d),r.save(),r.beginPath(),r.rect(l,i,u,d),r.clip();let j=C.length,M=D?u/j:d/j;for(let e=0;e<j;e++){let{density:t,maxDensity:n,q1:a,median:o,q3:s}=C[e],c=D?l+M*e+M/2:i+M*e+M/2,u=M*.45;r.beginPath();for(let e=0;e<Zq;e++){let i=t[e]/n*u,a=O(w[e]);D?e===0?r.moveTo(c-i,a):r.lineTo(c-i,a):e===0?r.moveTo(a,c-i):r.lineTo(a,c-i)}for(let e=Zq-1;e>=0;e--){let i=t[e]/n*u,a=O(w[e]);D?r.lineTo(c+i,a):r.lineTo(a,c+i)}if(r.closePath(),r.fillStyle=b,r.globalAlpha=.35,r.fill(),r.strokeStyle=b,r.lineWidth=1,r.globalAlpha=.9,r.stroke(),r.globalAlpha=1,x){let e=u*.22;D?(r.fillStyle=b,r.globalAlpha=.7,r.fillRect(c-e,O(s),e*2,O(a)-O(s)),r.globalAlpha=1,r.strokeStyle=b,r.lineWidth=2,r.beginPath(),r.moveTo(c-e,O(o)),r.lineTo(c+e,O(o)),r.stroke()):(r.fillStyle=b,r.globalAlpha=.7,r.fillRect(O(a),c-e,O(s)-O(a),e*2),r.globalAlpha=1,r.strokeStyle=b,r.lineWidth=2,r.beginPath(),r.moveTo(O(o),c-e),r.lineTo(O(o),c+e),r.stroke())}}if(r.restore(),r.fillStyle=v,r.font=`11px ${Q.mono}`,D){r.textAlign=`center`,r.textBaseline=`top`;for(let e=0;e<j;e++)r.fillText(C[e].label,l+M*e+M/2,i+d+6)}else{r.textAlign=`right`,r.textBaseline=`middle`;for(let e=0;e<j;e++)r.fillText(C[e].label,l-6,i+M*e+M/2)}}let y=K(v);y.current=v;let b=K(null);b.current??=DH(()=>y.current(),()=>l.current);let x=()=>b.current.schedule();return W(()=>{b.current.now()}),W(()=>()=>b.current?.cancel(),[]),W(()=>{u.current=null,x()},[a]),G(()=>{let e=l.current;if(!e)return;let t=new EH(()=>{u.current=null,x()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=c.current;if(!e)return;let t=e=>{e.preventDefault(),d.current?.({clientX:e.clientX,clientY:e.clientY})};return e.addEventListener(`contextmenu`,t),()=>e.removeEventListener(`contextmenu`,t)},[]),q(`div`,{ref:l,style:{position:`relative`,width:`100%`,height:`100%`},children:q(`canvas`,{ref:c,className:`chart-canvas`,role:`img`,"aria-label":`Violin plot`})})}var tJ={top:48,right:16,bottom:72,left:80},nJ=[8,24,64],rJ=[56,189,248];function iJ(e,t,n){return[e[0]+(t[0]-e[0])*n,e[1]+(t[1]-e[1])*n,e[2]+(t[2]-e[2])*n]}function aJ(e){return`${(e*100).toFixed(1)}%`}function oJ(e,t,n){if(e.length===0)return null;let r=Math.min(e.length,t.length),i=Array(r),a=Array(r),o=new Set,s=0;for(let n=0;n<r;n++)i[n]=String(e[n]),a[n]=String(t[n]),o.add(i[n]),o.add(a[n]),i[n]===a[n]&&s++;let c=[...o].sort(),l=c.length,u=new Map(c.map((e,t)=>[e,t])),d=Array.from({length:l},()=>Array(l).fill(0));for(let e=0;e<r;e++)d[u.get(i[e])][u.get(a[e])]++;let f=d.map(e=>e.reduce((e,t)=>e+t,0));return{classes:c,matrix:n?d.map((e,t)=>e.map(e=>f[t]>0?e/f[t]:0)):d,raw:d,accuracy:s/e.length}}function sJ({actual:e,predicted:t,normalize:n=!1,backgroundToken:r=``,onPlotContextMenu:i}){let a=K(null),o=K(null),s=K(null),c=K(null),l=K(null),u=K(0),d=K(i);G(()=>{d.current=i},[i]);let f=K({actual:e,predicted:t,normalize:n});G(()=>{f.current={actual:e,predicted:t,normalize:n}},[e,t,n]);function p(){if(c.current)return c.current;let e=s.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return c.current=n,n}function m(){let e=s.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function h(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}let g=dt(()=>oJ(e,t,n),[e,t,n]),_=K(g);G(()=>{_.current=g},[g]);let v=()=>_.current;function y(){let e=a.current;if(!e)return;let{w:t,h:n}=m(),r=h(e,t,n);if(!r)return;let{top:i,right:o,bottom:s,left:c}=tJ,{bg:l,muted:u,grid:d}=p();r.fillStyle=l,r.fillRect(0,0,t,n);let g=v();if(!g){r.fillStyle=u,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`No data`,c+8,i+8);return}let{classes:_,matrix:y,accuracy:b}=g,x=_.length,S=t-c-o,C=n-i-s,w=S/x,T=C/x,E=0;for(let e of y)for(let t of e)t>E&&(E=t);for(let e=0;e<x;e++)for(let t=0;t<x;t++){let n=y[e][t],[a,o,s]=iJ(nJ,rJ,E>0?n/E:0);if(r.fillStyle=`rgb(${a|0},${o|0},${s|0})`,r.fillRect(c+t*w,i+e*T,w,T),w>24&&T>14){r.fillStyle=.299*a+.587*o+.114*s>100?`#000`:`#fff`,r.font=`${Math.min(12,Math.max(8,T*.38))}px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`middle`;let l=f.current.normalize;r.fillText(l?aJ(n):String(n|0),c+(t+.5)*w,i+(e+.5)*T)}}r.strokeStyle=l,r.lineWidth=.5;for(let e=0;e<=x;e++)r.beginPath(),r.moveTo(c+e*w,i),r.lineTo(c+e*w,i+C),r.stroke(),r.beginPath(),r.moveTo(c,i+e*T),r.lineTo(c+S,i+e*T),r.stroke();r.strokeStyle=d,r.strokeRect(c,i,S,C),r.fillStyle=u,r.font=`10px ${Q.mono}`,r.textAlign=`right`,r.textBaseline=`middle`;for(let e=0;e<x;e++)r.fillText(_[e],c-4,i+(e+.5)*T);r.textAlign=`center`,r.textBaseline=`top`;for(let e=0;e<x;e++)r.save(),r.translate(c+(e+.5)*w,i+C+4),r.rotate(-Math.PI/4),r.fillText(_[e],0,0),r.restore();r.fillStyle=u,r.font=`11px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`bottom`,r.fillText(`Predicted`,c+S/2,n-4),r.save(),r.translate(12,i+C/2),r.rotate(-Math.PI/2),r.textAlign=`center`,r.fillText(`Actual`,0,0),r.restore(),r.fillStyle=u,r.font=`11px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`middle`,r.fillText(`Accuracy: ${aJ(b)}`,c+S/2,i/2)}function b(){let e=o.current;if(!e)return;let{w:t,h:n}=m(),r=h(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=l.current;if(!i)return;let{top:a,right:s,bottom:c,left:u}=tJ,d=v();if(!d)return;let{classes:p,matrix:g}=d,_=p.length,y=t-u-s,b=n-a-c,x=y/_,S=b/_;r.strokeStyle=`rgba(255,255,255,0.8)`,r.lineWidth=2,r.strokeRect(u+i.c*x+1,a+i.r*S+1,x-2,S-2);let C=g[i.r][i.c],w=f.current.normalize,T=`${p[i.r]} → ${p[i.c]}: ${w?aJ(C):C|0}`;r.font=`11px ${Q.mono}`;let E=r.measureText(T).width,D=Math.min(u+(i.c+1.1)*x,t-E-6),O=Math.max(6,a+(i.r-.3)*S);r.fillStyle=`rgba(0,0,0,0.75)`,r.fillRect(D-3,O-3,E+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(T,D,O)}let x=K(y);x.current=y;let S=K(null);S.current??=DH(()=>x.current(),()=>s.current);let C=()=>S.current.schedule(),w=()=>{xH(u.current),u.current=bH(b)};return W(()=>{S.current.now()}),W(()=>()=>S.current?.cancel(),[]),W(()=>{c.current=null,C()},[r]),G(()=>{let e=s.current;if(!e)return;let t=new EH(()=>{c.current=null,C(),w()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=o.current;if(!e)return;let t=e=>{e.preventDefault(),d.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),{top:r,right:i,bottom:a,left:o}=tJ,s=v();if(!s)return;let c=s.classes.length,u=n.width-o-i,d=n.height-r-a,f=Math.floor((t.clientX-n.left-o)/(u/c)),p=Math.floor((t.clientY-n.top-r)/(d/c));l.current=p>=0&&p<c&&f>=0&&f<c?{r:p,c:f}:null,w()},r=()=>{l.current=null,w()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),_t(`div`,{ref:s,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:a,className:`chart-canvas`,role:`img`,"aria-label":`Confusion matrix`}),q(`canvas`,{ref:o,className:`chart-canvas chart-overlay`})]})}var cJ={top:24,right:24,bottom:48,left:64};function lJ(e,t){let n=0,r=0,i=Math.min(e.length,t.length);for(let a=0;a<i;a++)e[a]-e[a]!==0||t[a]-t[a]!==0||(t[a]===1?n++:r++);let a=new Float64Array(n),o=new Float64Array(r);for(let n=0,r=0,s=0;n<i;n++)e[n]-e[n]!==0||t[n]-t[n]!==0||(t[n]===1?a[r++]=e[n]:o[s++]=e[n]);a.sort(),o.sort();let s=new Uint8Array(n+r);for(let e=0,t=n-1,i=r-1;e<s.length;e++)i<0||t>=0&&a[t]>=o[i]?(s[e]=1,t--):(s[e]=0,i--);return s}function uJ(e){let t=0;for(let n of e)t+=n;let n=e.length-t;if(t===0||n===0)return null;let r=new Float64Array(e.length+2),i=new Float64Array(e.length+2),a=0,o=0,s=0;for(let c=0;c<e.length;c++)e[c]===1?a++:o++,r[c+1]=o/n,i[c+1]=a/t,s+=(r[c+1]-r[c])*(i[c+1]+i[c])/2;return r[e.length+1]=1,i[e.length+1]=1,{fpr:r,tpr:i,auc:s}}function dJ(e){let t=0;for(let n of e)t+=n;if(t===0)return null;let n=new Float64Array(e.length),r=new Float64Array(e.length),i=0,a=0,o=0;for(let s=0;s<e.length;s++)e[s]===1?i++:a++,n[s]=i/t,r[s]=i/(i+a),s>0&&(o+=(n[s]-n[s-1])*r[s]);return{recall:n,precision:r,ap:o}}function fJ(e,t,n,r){let i=n(0),a=r(0);e.moveTo(i,a);for(let o=1;o<t;o++){let s=n(o),c=r(o);o<t-1&&Math.abs(s-i)<.5&&Math.abs(c-a)<.5||(e.lineTo(s,c),i=s,a=c)}}function pJ({scores:e,labels:t,mode:n=`roc`,color:r=`#f472b6`,backgroundToken:i=``,onPlotContextMenu:a}){let o=K(null),s=K(null),c=K(null),l=K(a);G(()=>{l.current=a},[a]);let u=K({scores:e,labels:t,mode:n,color:r});G(()=>{u.current={scores:e,labels:t,mode:n,color:r}},[e,t,n,r]);let d=dt(()=>lJ(e,t),[e,t]),f=dt(()=>n===`pr`?{roc:null,pr:dJ(d)}:{roc:uJ(d),pr:null},[d,n]),p=K(f);G(()=>{p.current=f},[f]);function m(){if(c.current)return c.current;let e=s.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return c.current=n,n}function h(){let e=s.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function g(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function _(){let e=o.current;if(!e)return;let{w:t,h:n}=h(),r=g(e,t,n);if(!r)return;let{top:i,right:a,bottom:s,left:c}=cJ,l=t-c-a,d=n-i-s,{bg:f,muted:_,grid:v}=m(),{scores:y,mode:b,color:x}=u.current;if(r.fillStyle=f,r.fillRect(0,0,t,n),y.length===0){r.fillStyle=_,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`No data`,c+8,i+8);return}let S=e=>c+e*l,C=e=>i+(1-e)*d,w=Dz(0,1,wz(1,5));r.strokeStyle=v,r.lineWidth=1,r.setLineDash([3,3]);for(let e of w)r.beginPath(),r.moveTo(S(e),i),r.lineTo(S(e),i+d),r.stroke(),r.beginPath(),r.moveTo(c,C(e)),r.lineTo(c+l,C(e)),r.stroke();if(r.setLineDash([]),b===`roc`&&(r.strokeStyle=_,r.lineWidth=1,r.setLineDash([4,4]),r.beginPath(),r.moveTo(S(0),C(0)),r.lineTo(S(1),C(1)),r.stroke(),r.setLineDash([])),b===`roc`){let e=p.current.roc;if(e){let t=e.fpr.length,n=t=>S(e.fpr[t]),a=t=>C(e.tpr[t]);r.beginPath(),fJ(r,t,n,a),r.strokeStyle=x,r.lineWidth=1,r.stroke(),r.beginPath(),fJ(r,t,n,a),r.lineTo(S(1),C(0)),r.lineTo(S(0),C(0)),r.closePath(),r.fillStyle=x,r.globalAlpha=.15,r.fill(),r.globalAlpha=1,r.fillStyle=x,r.font=`bold 13px ${Q.mono}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`AUC = ${e.auc.toFixed(3)}`,c+8,i+8)}}else{let e=p.current.pr;if(e){let t=HK(e.recall,e.precision,0,1,Math.max(1,Math.round(l*Math.min(2,window.devicePixelRatio||1))));r.beginPath();for(let n=0;n<t.length;n++){let i=S(e.recall[t[n]]),a=C(e.precision[t[n]]);n===0?r.moveTo(i,a):r.lineTo(i,a)}r.strokeStyle=x,r.lineWidth=1,r.stroke(),r.fillStyle=x,r.font=`bold 13px ${Q.mono}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`AP = ${e.ap.toFixed(3)}`,c+8,i+8)}}r.fillStyle=_,r.font=`11px ${Q.mono}`,r.strokeStyle=_,r.lineWidth=1,r.textAlign=`right`,r.textBaseline=`middle`;for(let e of w)r.beginPath(),r.moveTo(c-4,C(e)),r.lineTo(c,C(e)),r.stroke(),r.fillText(e.toFixed(1),c-6,C(e));r.textAlign=`center`,r.textBaseline=`top`;for(let e of w)r.beginPath(),r.moveTo(S(e),i+d),r.lineTo(S(e),i+d+4),r.stroke(),r.fillText(e.toFixed(1),S(e),i+d+6);r.strokeStyle=v,r.strokeRect(c,i,l,d),r.fillStyle=_,r.textAlign=`center`,r.textBaseline=`bottom`,r.fillText(b===`roc`?`False Positive Rate`:`Recall`,c+l/2,n-4),r.save(),r.translate(12,i+d/2),r.rotate(-Math.PI/2),r.textAlign=`center`,r.fillText(b===`roc`?`True Positive Rate`:`Precision`,0,0),r.restore()}let v=K(_);v.current=_;let y=K(null);y.current??=DH(()=>v.current(),()=>s.current);let b=()=>y.current.schedule();return W(()=>{y.current.now()}),W(()=>()=>y.current?.cancel(),[]),W(()=>{c.current=null,b()},[i]),G(()=>{let e=s.current;if(!e)return;let t=new EH(()=>{c.current=null,b()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=o.current;if(!e)return;let t=e=>{e.preventDefault(),l.current?.({clientX:e.clientX,clientY:e.clientY})};return e.addEventListener(`contextmenu`,t),()=>e.removeEventListener(`contextmenu`,t)},[]),q(`div`,{ref:s,style:{position:`relative`,width:`100%`,height:`100%`},children:q(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`ROC / PR curve`})})}var mJ={top:20,right:64,bottom:48,left:64};function hJ({xValues:e,series:t,xLabel:n=`Epoch`,backgroundToken:r=``,onPlotContextMenu:i}){let a=nU(),o=K(null),s=K(null),c=K(null),l=K(null),u=K(null),d=K(0),f=K(i);G(()=>{f.current=i},[i]);let p=K({xValues:e,series:t,xLabel:n});G(()=>{p.current={xValues:e,series:t,xLabel:n}},[e,t,n]);function m(){if(l.current)return l.current;let e=c.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return l.current=n,n}function h(){let e=c.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function g(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}let _=dt(()=>{let n=e=>{let t=1/0,n=-1/0;for(let r of e)for(let e=0;e<r.values.length;e++){let i=r.values[e];i<t&&(t=i),i>n&&(n=i)}if(!Number.isFinite(t))return{lo:0,hi:1};let r=(n-t)*.06||.1;return{lo:t-r,hi:n+r}},r=t.filter(e=>e.axis===`left`),i=t.filter(e=>e.axis===`right`),a=1/0,o=-1/0;for(let t=0;t<e.length;t++){let n=e[t];n<a&&(a=n),n>o&&(o=n)}return{leftExt:n(r.length?r:t),rightExt:n(i.length?i:t),hasRight:i.length>0,xMin:a,xMax:o,ascending:GK(e)}},[e,t]),v=K(_);G(()=>{v.current=_},[_]);function y(){let e=o.current;if(!e)return;let{w:t,h:n}=h(),r=g(e,t,n);if(!r)return;let{top:i,right:s,bottom:c,left:l}=mJ,u=t-l-s,d=n-i-c,{bg:f,muted:_,grid:y}=m(),{xValues:b,series:x,xLabel:S}=p.current;if(r.fillStyle=f,r.fillRect(0,0,t,n),b.length===0||x.length===0){r.fillStyle=_,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`No data`,l+8,i+8);return}let{leftExt:C,rightExt:w,hasRight:T,xMin:E,xMax:D,ascending:O}=v.current,k=e=>l+(e-E)/(D-E||1)*u;a({left:l,top:i,width:u,height:d,x:{v0:E,v1:D},y:{v0:C.lo,v1:C.hi}});let A=e=>i+(1-(e-C.lo)/(C.hi-C.lo))*d,j=e=>i+(1-(e-w.lo)/(w.hi-w.lo))*d,M=wz(C.hi-C.lo,5),N=Dz(C.lo,C.hi,M);r.strokeStyle=y,r.lineWidth=1,r.setLineDash([3,3]);for(let e of N)r.beginPath(),r.moveTo(l,A(e)),r.lineTo(l+u,A(e)),r.stroke();let P=wz(D-E,6),F=Dz(E,D,P);for(let e of F)r.beginPath(),r.moveTo(k(e),i),r.lineTo(k(e),i+d),r.stroke();r.setLineDash([]);let I=Math.min(2,window.devicePixelRatio||1),L=Math.max(1,Math.round(u*I));for(let e of x){let t=e.axis===`right`&&T?j:A,n=Math.min(b.length,e.values.length),i=O&&n>4*L?HK(b,e.values,E,D,L):null;r.beginPath();let a=!1;for(let o=0;o<(i?i.length:n);o++){let n=i?i[o]:o,s=b[n],c=e.values[n];if(s-s!==0||c-c!==0){a=!1;continue}let l=k(s),u=t(c);a?r.lineTo(l,u):(r.moveTo(l,u),a=!0)}r.strokeStyle=e.color,r.lineWidth=1,r.stroke()}r.fillStyle=_,r.font=`11px ${Q.mono}`,r.strokeStyle=_,r.lineWidth=1,r.textAlign=`right`,r.textBaseline=`middle`;for(let e of N)r.beginPath(),r.moveTo(l-4,A(e)),r.lineTo(l,A(e)),r.stroke(),r.fillText(jz(e,M),l-6,A(e));if(T){let e=wz(w.hi-w.lo,5),t=Dz(w.lo,w.hi,e);r.textAlign=`left`;for(let n of t)r.beginPath(),r.moveTo(l+u,j(n)),r.lineTo(l+u+4,j(n)),r.stroke(),r.fillText(jz(n,e),l+u+6,j(n))}r.textAlign=`center`,r.textBaseline=`top`;for(let e of F)r.beginPath(),r.moveTo(k(e),i+d),r.lineTo(k(e),i+d+4),r.stroke(),r.fillText(jz(e,P),k(e),i+d+6);r.strokeStyle=y,r.strokeRect(l,i,u,d),r.fillStyle=_,r.textAlign=`center`,r.textBaseline=`bottom`,r.fillText(S,l+u/2,n-4);let R=l+8,z=i+6;r.font=`10px ${Q.mono}`,r.textBaseline=`middle`;for(let e of x)r.fillStyle=e.color,r.fillRect(R,z-4,16,3),r.fillStyle=_,r.textAlign=`left`,r.fillText(e.label,R+20,z),R+=r.measureText(e.label).width+36,R>l+u-60&&(R=l+8,z+=14)}function b(){let e=s.current;if(!e)return;let{w:t,h:n}=h(),r=g(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=u.current;if(i===null)return;let{top:a,right:o,bottom:c,left:l}=mJ,d=t-l-o,f=n-a-c,{muted:_}=m(),{xValues:y,series:b}=p.current;if(y.length===0)return;let{xMin:x,xMax:S,ascending:C}=v.current,w=e=>l+(e-x)/(S-x||1)*d,T=Math.max(l,Math.min(l+d,i));r.strokeStyle=_,r.lineWidth=1,r.setLineDash([3,3]),r.beginPath(),r.moveTo(T,a),r.lineTo(T,a+f),r.stroke(),r.setLineDash([]);let E=(T-l)/d,D=Math.round(E*(y.length-1));if(C){let e=x+E*(S-x),t=0,n=y.length;for(;t<n;){let r=t+n>>>1;y[r]<e?t=r+1:n=r}D=t>0&&(t>=y.length||e-y[t-1]<y[t]-e)?t-1:t}if(D<0||D>=y.length)return;let O=a+8;r.font=`10px ${Q.mono}`,r.textBaseline=`top`;for(let e of b)D<e.values.length&&Number.isFinite(e.values[D])&&(r.fillStyle=e.color,r.textAlign=`left`,r.fillText(`${e.label}: ${Mz(e.values[D])}`,T+6,O),O+=14);w(0)}let x=K(y);x.current=y;let S=K(null);S.current??=DH(()=>x.current(),()=>c.current);let C=()=>S.current.schedule(),w=()=>{xH(d.current),d.current=bH(b)};return W(()=>{S.current.now()}),W(()=>()=>S.current?.cancel(),[]),W(()=>{l.current=null,C()},[r]),G(()=>{let e=c.current;if(!e)return;let t=new EH(()=>{l.current=null,C(),w()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=s.current;if(!e)return;let t=e=>{e.preventDefault(),f.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect();u.current=t.clientX-n.left,w()},r=()=>{u.current=null,w()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),_t(`div`,{ref:c,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`Loss curves`}),q(`canvas`,{ref:s,className:`chart-canvas chart-overlay`})]})}var gJ={top:40,right:24,bottom:40,left:72},_J=`#ef4444`,vJ=`#f97316`,yJ=`#22d3ee`;function bJ(e,t){let n=e.length,r=e.value;if(n===0)return null;let i=0;for(let e=0;e<n;e++)i+=r[e];let a=i/n,o=0;for(let e=0;e<n;e++)o+=(r[e]-a)**2;let s=Math.sqrt(o/n),c=a+t*s,l=a-t*s,u=l,d=c,f=0;for(let e=0;e<n;e++){let t=r[e];t<u&&(u=t),t>d&&(d=t),(t>c||t<l)&&f++}let p=(d-u)*.08||.5,m=new Uint32Array(f);for(let e=0,t=0;e<n;e++)(r[e]>c||r[e]<l)&&(m[t++]=e);return{mean:a,sd:s,ucl:c,lcl:l,yMin:u-p,yMax:d+p,ooc:m}}function xJ({points:e,sigmaLevel:t=3,color:n=`#22d3ee`,backgroundToken:r=``,onPlotContextMenu:i}){let a=nU(),o=K(null),s=K(null),c=K(null),l=K(null),u=K(null),d=K(0),f=K(i);G(()=>{f.current=i},[i]);let p=K({points:e,sigmaLevel:t,color:n});G(()=>{p.current={points:e,sigmaLevel:t,color:n}},[e,t,n]);function m(){if(l.current)return l.current;let e=c.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return l.current=n,n}function h(){let e=c.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function g(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}let _=dt(()=>bJ(e,t),[e,t]),v=K(_);G(()=>{v.current=_},[_]);let y=()=>v.current;function b(){let e=o.current;if(!e)return;let{w:t,h:n}=h(),r=g(e,t,n);if(!r)return;let{top:i,right:s,bottom:c,left:l}=gJ,u=t-l-s,d=n-i-c,{bg:f,muted:_,grid:v}=m(),{points:b,color:x}=p.current;if(r.fillStyle=f,r.fillRect(0,0,t,n),b.length===0){r.fillStyle=_,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`No data`,l+8,i+8);return}let S=y(),{mean:C,ucl:w,lcl:T,yMin:E,yMax:D}=S,O=e=>l+e/(b.length-1||1)*u;a({left:l,top:i,width:u,height:d,x:{v0:0,v1:b.length-1||1}});let k=e=>i+(1-(e-E)/(D-E))*d,A=wz(D-E,5),j=Dz(E,D,A);r.strokeStyle=v,r.lineWidth=1,r.setLineDash([3,3]);for(let e of j)r.beginPath(),r.moveTo(l,k(e)),r.lineTo(l+u,k(e)),r.stroke();r.setLineDash([]);let M=(e,t,n,a=[])=>{let o=k(e);o<i||o>i+d||(r.strokeStyle=t,r.lineWidth=1.2,r.setLineDash(a),r.beginPath(),r.moveTo(l,o),r.lineTo(l+u,o),r.stroke(),r.setLineDash([]),r.fillStyle=t,r.font=`9px ${Q.mono}`,r.textAlign=`right`,r.textBaseline=`middle`,r.fillText(`${n} ${Mz(e)}`,l+u-2,o-5))};M(w,vJ,`UCL`,[5,3]),M(C,yJ,`CL`,[]),M(T,vJ,`LCL`,[5,3]);let N=Math.min(2,window.devicePixelRatio||1),P=Math.max(1,Math.round(u*N)),F=b.length,I=b.value,L=UK(I,P);r.beginPath();for(let e=0;e<L.length;e++){let t=L[e],n=O(t),i=k(I[t]);e===0?r.moveTo(n,i):r.lineTo(n,i)}r.strokeStyle=x,r.lineWidth=1,r.stroke();let R=(e,t)=>{r.beginPath(),r.arc(O(e),k(I[e]),t?4:3,0,Math.PI*2),r.fillStyle=t?_J:x,r.fill()};if(F<=u/4)for(let e=0;e<F;e++)R(e,I[e]>w||I[e]<T);else{let e=NaN,t=NaN;for(let n of S.ooc){let r=Math.round(O(n)),i=Math.round(k(I[n]));r===e&&i===t||(e=r,t=i,R(n,!0))}}r.fillStyle=_,r.font=`11px ${Q.mono}`,r.strokeStyle=_,r.lineWidth=1,r.textAlign=`right`,r.textBaseline=`middle`;for(let e of j)r.beginPath(),r.moveTo(l-4,k(e)),r.lineTo(l,k(e)),r.stroke(),r.fillText(jz(e,A),l-6,k(e));r.strokeStyle=v,r.strokeRect(l,i,u,d)}function x(){let e=s.current;if(!e)return;let{w:t,h:n}=h(),r=g(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=u.current;if(i===null)return;let{top:a,right:o,bottom:c,left:l}=gJ,d=t-l-o,f=n-a-c,{muted:_}=m(),{points:v}=p.current;if(v.length===0)return;let{ucl:b,lcl:x,yMin:S,yMax:C}=y(),w=e=>l+e/(v.length-1||1)*d,T=e=>a+(1-(e-S)/(C-S))*f,E=Math.round((i-l)/d*(v.length-1));if(E<0||E>=v.length)return;let D=v.value[E],O=w(E),k=T(D);r.strokeStyle=_,r.lineWidth=1,r.setLineDash([3,3]),r.beginPath(),r.moveTo(O,a),r.lineTo(O,a+f),r.stroke(),r.setLineDash([]);let A=v.subgroup?.(E),j=`${A?`${A}: `:`#${E+1}: `}${Mz(D)}`;r.font=`11px ${Q.mono}`;let M=r.measureText(j).width,N=O+8+M>l+d?O-M-10:O+8;r.fillStyle=`rgba(0,0,0,0.75)`,r.fillRect(N-3,k-12,M+6,18),r.fillStyle=D>b||D<x?_J:_,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(j,N,k-11)}let S=K(b);S.current=b;let C=K(null);C.current??=DH(()=>S.current(),()=>c.current);let w=()=>C.current.schedule(),T=()=>{xH(d.current),d.current=bH(x)};return W(()=>{C.current.now()}),W(()=>()=>C.current?.cancel(),[]),W(()=>{l.current=null,w()},[r]),G(()=>{let e=c.current;if(!e)return;let t=new EH(()=>{l.current=null,w(),T()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=s.current;if(!e)return;let t=e=>{e.preventDefault(),f.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect();u.current=t.clientX-n.left,T()},r=()=>{u.current=null,T()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),_t(`div`,{ref:c,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`Control chart`}),q(`canvas`,{ref:s,className:`chart-canvas chart-overlay`})]})}var SJ={top:32,right:24,bottom:24,left:24},CJ=[`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`,`#facc15`,`#60a5fa`],wJ=16;function TJ(e){return`rgb(${Math.round(255*Math.min(1,Math.max(0,3.5*e-.5)))},${Math.round(255*Math.min(1,Math.max(0,e<.5?2*e:2-2*e)))},${Math.round(255*Math.min(1,Math.max(0,1.5-3.5*e)))})`}function EJ(e,t,n,r){let i=Math.min(t,e.columns.length),a=e.columns.slice(0,i).map(t=>{let n=1/0,r=-1/0;for(let i=0;i<e.length;i++){let e=t[i];e<n&&(n=e),e>r&&(r=e)}if(!Number.isFinite(n))return{lo:0,hi:1};let i=(r-n)*.05||.5;return{lo:n-i,hi:r+i}}),o={lo:0,hi:1},s=new Int32Array(e.length),c=[r];if(n&&e.colorValue){let t=e.colorValue,n=1/0,r=-1/0;for(let i=0;i<e.length;i++)t[i]<n&&(n=t[i]),t[i]>r&&(r=t[i]);Number.isFinite(n)&&(o={lo:n,hi:r}),c=Array.from({length:wJ},(e,t)=>TJ((t+.5)/wJ));for(let n=0;n<e.length;n++){let e=(t[n]-o.lo)/(o.hi-o.lo||1);s[n]=t[n]===t[n]?Math.max(0,Math.min(wJ-1,Math.floor(e*wJ))):-1}for(let t=0;t<e.length;t++)s[t]<0&&(s[t]=0)}else if(!n&&e.colorIndex){c=CJ;for(let t=0;t<e.length;t++)s[t]=Math.max(0,e.colorIndex[t])%CJ.length}let l=new Int32Array(c.length);for(let t=0;t<e.length;t++)l[s[t]]++;let u=c.map((e,t)=>({color:e,x:new Float64Array(l[t]*i),y:new Float64Array(l[t]*i),starts:new Uint8Array(l[t]*i)})),d=new Int32Array(c.length);for(let t=0;t<e.length;t++){let n=u[s[t]],r=d[s[t]]++*i;n.starts[r]=1;for(let o=0;o<i;o++,r++){let i=a[o];n.x[r]=o,n.y[r]=(e.columns[o][t]-i.lo)/(i.hi-i.lo)}}return{k:i,extents:a,colorExt:o,groups:u.filter(e=>e.x.length>0)}}function DJ({rows:e,axes:t,color:n=`#64748b`,colorByNumeric:r=!1,backgroundToken:i=``,onPlotContextMenu:a}){let o=K(null),s=K(null),c=K(null),l=K(null),u=K(null),d=K(null),f=K(null),p=K(0),m=K(a);G(()=>{m.current=a},[a]);let h=dt(()=>EJ(e,t.length,r,n),[e,t.length,r,n]),g=K({rows:e,axes:t,colorByNumeric:r,model:h});G(()=>{g.current={rows:e,axes:t,colorByNumeric:r,model:h}},[e,t,r,h]);let _=LK(s),v=K(null);function y(){if(d.current)return d.current;let e=u.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return d.current=n,n}function b(){let e=u.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function x(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function S(){let e=o.current;if(!e)return;let{w:t,h:n}=b(),r=x(e,t,n);if(!r)return;let i=c.current?x(c.current,t,n):null;i?.clearRect(0,0,t,n);let a=i??r,{top:s,right:l,bottom:d,left:f}=SJ,{bg:p,muted:m}=y(),{rows:h,axes:S,colorByNumeric:C,model:w}=g.current;r.fillStyle=p,r.fillRect(0,0,t,n);let T=_(t,n);if(S.length<2||h.length===0||w.k<2){T?.keep([]),T?.render(),r.fillStyle=m,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`Select ≥ 2 axes`,f+8,s+8);return}let E=t-f-l,D=n-s-d,O=w.k,k=Array.from({length:O},(e,t)=>f+t/(O-1)*E),A=(e,t)=>{let n=w.extents[t];return s+(1-(e-n.lo)/(n.hi-n.lo))*D},j=Math.max(.05,Math.min(.7,60/h.length));if(T)v.current!==w&&(w.groups.forEach((e,t)=>T.setLine(`c${t}`,e.x,e.y,XG(e.color,j),1,e.starts)),v.current=w,CH(u.current)),T.keep(w.groups.map((e,t)=>`c${t}`)),T.setView(0,O-1,0,1,{left:f,top:s,width:E,height:D}),T.render();else{r.globalAlpha=j;for(let e of w.groups){r.beginPath();let t=!1;for(let n=0;n<e.x.length;n++){let i=e.y[n];if(e.starts[n]&&(t=!1),i!==i){t=!1;continue}let a=f+e.x[n]/(O-1)*E,o=s+(1-i)*D;t?r.lineTo(a,o):(r.moveTo(a,o),t=!0)}r.strokeStyle=e.color,r.lineWidth=1,r.stroke()}r.globalAlpha=1}a.strokeStyle=m,a.lineWidth=1.5;for(let e=0;e<O;e++)a.beginPath(),a.moveTo(k[e],s),a.lineTo(k[e],s+D),a.stroke();a.fillStyle=m,a.font=`9px ${Q.mono}`;for(let e=0;e<O;e++){let t=w.extents[e];for(let n of[0,.25,.5,.75,1]){let r=t.lo+n*(t.hi-t.lo),i=A(r,e);a.beginPath(),a.moveTo(k[e]-3,i),a.lineTo(k[e]+3,i),a.stroke(),a.textAlign=e===O-1?`left`:`right`,a.textBaseline=`middle`,a.fillText(jz(r,(t.hi-t.lo)/4),k[e]+(e===O-1?5:-5),i)}a.font=`10px ${Q.mono}`,a.textAlign=`center`,a.textBaseline=`bottom`,a.fillText(S[e],k[e],s-4)}let M=h.colorLabels??[];if(!C&&M.length>0&&M.length<=10){let e=f,t=s+D+8;a.font=`9px ${Q.mono}`,a.textBaseline=`top`,M.forEach((n,r)=>{a.fillStyle=CJ[r%CJ.length],a.fillRect(e,t,10,8),a.fillStyle=m,a.textAlign=`left`,a.fillText(n,e+13,t),e+=a.measureText(n).width+26,e>f+E-40&&(e=f,t+=12)})}}function C(){let e=l.current;if(!e)return;let{w:t,h:n}=b(),r=x(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=f.current;if(i===null)return;let{top:a,right:o,bottom:s,left:c}=SJ,{axes:u}=g.current;if(u.length<2)return;let d=t-c-o,p=c+i/(u.length-1)*d;r.strokeStyle=`rgba(255,255,255,0.6)`,r.lineWidth=2,r.beginPath(),r.moveTo(p,a-4),r.lineTo(p,a+(n-a-s)+4),r.stroke()}let w=K(S);w.current=S;let T=K(null);T.current??=DH(()=>w.current(),()=>u.current);let E=()=>T.current.schedule(),D=()=>{xH(p.current),p.current=bH(C)};return W(()=>{T.current.now()}),W(()=>()=>T.current?.cancel(),[]),W(()=>{d.current=null,E()},[i]),G(()=>{let e=u.current;if(!e)return;let t=new EH(()=>{d.current=null,E(),D()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=l.current;if(!e)return;let t=e=>{e.preventDefault(),m.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),{axes:r}=g.current;if(r.length<2)return;let i=n.width-SJ.left-SJ.right,a=r.length,o=t.clientX-n.left-SJ.left,s=Math.round(o/i*(a-1));f.current=Math.abs(o-s/(a-1)*i)<20&&s>=0&&s<a?s:null,D()},r=()=>{f.current=null,D()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),_t(`div`,{ref:u,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`Parallel coordinates`}),q(`canvas`,{ref:s,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),q(`canvas`,{ref:c,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),q(`canvas`,{ref:l,className:`chart-canvas chart-overlay`})]})}function OJ(e,t,n,r,i,a){let o=Math.max(1,Math.ceil(t/r)),s=Math.max(1,Math.ceil(n/r)),c=e=>{let s=i(e),c=a(e);return s>=0&&s<t&&c>=0&&c<n?Math.floor(c/r)*o+Math.floor(s/r):-1},l=new Uint32Array(o*s+1);for(let t=0;t<e;t++){let e=c(t);e>=0&&l[e+1]++}for(let e=0;e<o*s;e++)l[e+1]+=l[e];let u=l.slice(0,o*s),d=new Uint32Array(l[o*s]);for(let t=0;t<e;t++){let e=c(t);e>=0&&(d[u[e]++]=t)}return{cell:r,nx:o,ny:s,start:l,ix:d}}function kJ(e,t,n,r,i,a,o){let s=Math.floor(t/e.cell),c=Math.floor(n/e.cell),l=-1,u=r*r;for(let r=c-1;r<=c+1;r++)if(!(r<0||r>=e.ny))for(let c=s-1;c<=s+1;c++){if(c<0||c>=e.nx)continue;let s=r*e.nx+c;for(let r=e.start[s];r<e.start[s+1];r++){let s=e.ix[r],c=(i(s)-t)**2+(a(s)-n)**2;c<u&&(!o||c<o(s)**2)&&(u=c,l=s)}}return l<0?null:l}var AJ={top:16,right:16,bottom:16,left:16},jJ=[`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`,`#facc15`,`#60a5fa`];function MJ(e){return[Math.round(255*Math.min(1,Math.max(0,3.5*e-.5))),Math.round(255*Math.min(1,Math.max(0,e<.5?2*e:2-2*e))),Math.round(255*Math.min(1,Math.max(0,1.5-3.5*e)))]}function NJ(e){let[t,n,r]=MJ(e);return`rgb(${t},${n},${r})`}var PJ=(()=>{let e=new Uint8Array(1024);for(let t=0;t<256;t++)e.set([...MJ(t/255),255],t*4);return e})(),FJ=(()=>{let e=new Uint8Array(1024);for(let t=0;t<256;t++){let[n,r,i]=XG(jJ[t%jJ.length],1);e.set([n*255,r*255,i*255,255],t*4)}return e});function IJ(e,t){let n=1/0,r=-1/0,i=1/0,a=-1/0;for(let t=0;t<e.length;t++){let o=e.x[t],s=e.y[t];o<n&&(n=o),o>r&&(r=o),s<i&&(i=s),s>a&&(a=s)}let o=!Number.isFinite(n)||!Number.isFinite(i)?{xLo:-1,xHi:1,yLo:-1,yHi:1}:(()=>{let e=(r-n)*.05||.5,t=(a-i)*.05||.5;return{xLo:n-e,xHi:r+e,yLo:i-t,yHi:a+t}})(),s={lo:0,hi:1},c=null,l=`single`;if(t&&e.colorValue){let t=e.colorValue,n=1/0,r=-1/0;for(let i=0;i<e.length;i++){let e=t[i];e<n&&(n=e),e>r&&(r=e)}Number.isFinite(n)&&(s={lo:n,hi:r}),c=new Float32Array(e.length);let i=s.hi-s.lo;for(let n=0;n<e.length;n++)c[n]=t[n]===t[n]?Math.max(0,Math.min(1,i>0?(t[n]-s.lo)/i:.5)):0;l=`colormap`}else !t&&e.colorIndex&&(c=Float32Array.from(e.colorIndex,e=>e>=0?e%256:0),l=`dataset`);return{ext:o,colorExt:s,key:c,mode:l}}function LJ({points:e,color:t=`#64748b`,colorByNumeric:n=!1,pointSize:r=4,backgroundToken:i=``,onPlotContextMenu:a}){let o=K(null),s=K(null),c=K(null),l=K(null),u=K(null),d=K(null),f=K(0),p=K(a);G(()=>{p.current=a},[a]);let m=dt(()=>IJ(e,n),[e,n]),h=K({points:e,color:t,colorByNumeric:n,pointSize:r,model:m});G(()=>{h.current={points:e,color:t,colorByNumeric:n,pointSize:r,model:m}},[e,t,n,r,m]);let g=K({r:null,failed:!1,size:``,model:null,style:``});W(()=>()=>{g.current.r?.dispose(),g.current.r=null},[]);function _(){if(u.current)return u.current;let e=l.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return u.current=n,n}function v(){let e=l.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function y(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function b(e,t){let{top:n,right:r,bottom:i,left:a}=AJ,o=e-a-r,s=t-n-i,c=h.current.model.ext;return{xToPx:e=>a+(e-c.xLo)/(c.xHi-c.xLo)*o,yToPx:e=>n+(1-(e-c.yLo)/(c.yHi-c.yLo))*s,plotW:o,plotH:s,ext:c}}function x(e,t){let n=g.current;!n.r&&!n.failed&&s.current&&(n.r=uH(s.current,qW),n.failed=!n.r);let r=n.r;if(!r||!s.current)return null;let i=Math.min(2,window.devicePixelRatio||1),a=`${e}x${t}@${i}`;n.size!==a&&(r.resize(e,t,i),s.current.style.width=`${e}px`,s.current.style.height=`${t}px`,n.size=a);let{points:o,model:c,color:u,pointSize:d}=h.current;n.model!==c&&(r.setData(o.x,o.y,c.key??void 0),n.model=c,CH(l.current));let f=`${c.mode}|${u}|${d}`;return n.style!==f&&(r.setStyle(c.mode===`single`?{kind:`single`,rgba:XG(u,1)}:{kind:c.mode,palette:c.mode===`colormap`?PJ:FJ()},d,.8),r.setDraw(!0,!1,0),n.style=f),r}function S(){let e=o.current;if(!e)return;let{w:t,h:n}=v(),r=y(e,t,n);if(!r)return;let{bg:i,muted:a}=_(),{points:s,color:c,colorByNumeric:l,pointSize:u,model:d}=h.current;r.fillStyle=i,r.fillRect(0,0,t,n);let f=x(t,n);if(s.length===0){f?.setData([],[]),g.current.model=null,f?.render(),r.fillStyle=a,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`No data`,AJ.left+8,AJ.top+8);return}let p=d.colorExt,{xToPx:m,yToPx:S,plotW:C,plotH:w,ext:T}=b(t,n);if(f)f.setView(T.xLo,T.xHi,T.yLo,T.yHi,{left:AJ.left,top:AJ.top,width:C,height:w}),f.render();else{for(let e=0;e<s.length;e++){let t=s.x[e],n=s.y[e];if(t!==t||n!==n)continue;let i=d.key?.[e]??0;r.beginPath(),r.arc(m(t),S(n),u,0,Math.PI*2),r.fillStyle=d.mode===`colormap`?NJ(i):d.mode===`dataset`?jJ[i%jJ.length]:c,r.globalAlpha=.8,r.fill()}r.globalAlpha=1}if(l){let e=Math.min(120,Math.floor((n-AJ.top-AJ.bottom)*.4)),i=t-AJ.right-12,o=AJ.top+8;for(let t=0;t<e;t++)r.fillStyle=NJ(1-t/(e-1)),r.fillRect(i,o+t,8,1);r.fillStyle=a,r.font=`9px ${Q.mono}`,r.textAlign=`left`,r.textBaseline=`middle`;let s=e=>Math.abs(e)>=1e4||Math.abs(e)<.001&&e!==0?e.toExponential(1):String(parseFloat(e.toPrecision(3)));r.fillText(s(p.hi),i+10,o),r.fillText(s(p.lo),i+10,o+e)}let E=s.colorLabels??[];if(!l&&E.length>0&&E.length<=10){let e=AJ.left,i=n-AJ.bottom-10;r.font=`9px ${Q.mono}`,r.textBaseline=`top`,E.forEach((n,o)=>{e>t-AJ.right-60&&(e=AJ.left,i-=14),r.fillStyle=jJ[o%jJ.length],r.beginPath(),r.arc(e+4,i+4,4,0,Math.PI*2),r.fill(),r.fillStyle=a,r.textAlign=`left`,r.fillText(n,e+10,i),e+=r.measureText(n).width+20})}}function C(){let e=c.current;if(!e)return;let{w:t,h:n}=v(),r=y(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=d.current;if(i===null)return;let{points:a,pointSize:o}=h.current;if(i<0||i>=a.length)return;let{xToPx:s,yToPx:l}=b(t,n),u=a.x[i],f=a.y[i],p=s(u),m=l(f);r.beginPath(),r.arc(p,m,o+3,0,Math.PI*2),r.strokeStyle=`rgba(255,255,255,0.9)`,r.lineWidth=2,r.stroke();let g=[],_=a.label?.(i);_&&g.push(_);let x=a.colorIndex?.[i];x!==void 0&&x>=0&&a.colorLabels?g.push(a.colorLabels[x]):a.colorValue&&g.push(a.colorValue[i].toFixed(3)),g.push(`(${u.toFixed(3)}, ${f.toFixed(3)})`);let S=g.join(` · `);r.font=`11px ${Q.mono}`;let C=r.measureText(S).width,w=Math.max(4,Math.min(t-C-8,p+10)),T=m-20<AJ.top?m+10:m-20;r.fillStyle=`rgba(0,0,0,0.75)`,r.fillRect(w-3,T-3,C+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(S,w,T)}let w=K(S);w.current=S;let T=K(null);T.current??=DH(()=>w.current(),()=>l.current);let E=()=>T.current.schedule(),D=()=>{xH(f.current),f.current=bH(C)};return W(()=>{T.current.now()}),W(()=>()=>T.current?.cancel(),[]),W(()=>{u.current=null,E()},[i]),G(()=>{let e=l.current;if(!e)return;let t=new EH(()=>{u.current=null,E(),D()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=c.current;if(!e)return;let t=null,n=e=>{e.preventDefault(),p.current?.({clientX:e.clientX,clientY:e.clientY})},r=n=>{let r=e.getBoundingClientRect(),{points:i,pointSize:a,model:o}=h.current,{w:s,h:c}=v(),{xToPx:l,yToPx:u,plotW:f,plotH:p}=b(s,c),m=e=>l(i.x[e])-AJ.left,g=e=>u(i.y[e])-AJ.top,_=a+8,y=`${s}|${c}|${_}`;(!t||t.model!==o||t.key!==y)&&(t={model:o,key:y,g:OJ(i.length,f,p,_,m,g)}),d.current=kJ(t.g,n.clientX-r.left-AJ.left,n.clientY-r.top-AJ.top,_,m,g),D()},i=()=>{d.current=null,D()};return e.addEventListener(`contextmenu`,n),e.addEventListener(`mousemove`,r),e.addEventListener(`mouseleave`,i),()=>{e.removeEventListener(`contextmenu`,n),e.removeEventListener(`mousemove`,r),e.removeEventListener(`mouseleave`,i)}},[]),_t(`div`,{ref:l,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`Embedding / scatter`}),q(`canvas`,{ref:s,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),q(`canvas`,{ref:c,className:`chart-canvas chart-overlay`})]})}var RJ={top:8,right:8,bottom:8,left:8},zJ=20,BJ=[`#f97316`,`#fb923c`,`#fdba74`,`#fbbf24`,`#fcd34d`,`#4ade80`,`#34d399`,`#38bdf8`,`#818cf8`,`#a78bfa`];function VJ(e){let t=new Map;for(let n of e){let e=n.parent??``;t.has(e)||t.set(e,[]),t.get(e).push(n)}function n(r,i){let a=(t.get(r)??[]).map(e=>n(e.name,i+1)),o=e.find(e=>e.name===r),s=a.reduce((e,t)=>e+t.value,0);return{name:r,value:o?Math.max(o.value,s):s,children:a,depth:i,x0:0,x1:1}}let r=new Set(e.map(e=>e.name)),i=e.filter(e=>!e.parent||!r.has(e.parent)).map(e=>n(e.name,0)),a=i.reduce((e,t)=>e+t.value,0)||1;function o(e,t,n){e.x0=t,e.x1=n;let r=n-t,i=t;for(let t of e.children){let n=t.value/e.value*r;o(t,i,i+n),i+=n}}let s=0;for(let e of i){let t=e.value/a;o(e,s,s+t),s+=t}return i}function HJ(e){let t=[];function n(e){t.push(e);for(let t of e.children)n(t)}for(let t of e)n(t);return t}function UJ(e){let t=0;function n(e){e.depth>t&&(t=e.depth);for(let t of e.children)n(t)}for(let t of e)n(t);return t}function WJ(e){return BJ[e%BJ.length]}function GJ({nodes:e,direction:t=`bottomup`,backgroundToken:n=``,onPlotContextMenu:r}){let i=K(null),a=K(null),o=K(null),s=K(null),c=K(null),l=K(0),u=K(r);G(()=>{u.current=r},[r]);let d=K({nodes:e,direction:t});G(()=>{d.current={nodes:e,direction:t}},[e,t]);let f=dt(()=>{let t=VJ(e);return{roots:t,flat:HJ(t),numRows:UJ(t)+1}},[e]),p=K(f);G(()=>{p.current=f},[f]);function m(){if(s.current)return s.current;let e=o.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return s.current=n,n}function h(){let e=o.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function g(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function _(e,t,n,r,i){let a=RJ.left+e.x0*t,o=(e.x1-e.x0)*t;return{x:a,y:i===`topdown`?RJ.top+e.depth*zJ:RJ.top+n-(e.depth+1)*zJ,w:o,h:zJ-1}}function v(){let e=i.current;if(!e)return;let{w:t,h:n}=h(),r=g(e,t,n);if(!r)return;let{bg:a,muted:o}=m(),{nodes:s,direction:c}=d.current;if(r.fillStyle=a,r.fillRect(0,0,t,n),s.length===0){r.fillStyle=o,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`No data`,RJ.left+8,RJ.top+8);return}let{flat:l,numRows:u}=p.current,f=t-RJ.left-RJ.right,v=u*zJ;for(let e of l){let t=_(e,f,v,u,c);if(!(t.w<1)&&(r.fillStyle=WJ(e.depth),r.fillRect(t.x,t.y,t.w,t.h),t.w>24)){r.fillStyle=`rgba(0,0,0,0.75)`,r.font=`${Math.min(11,zJ-4)}px ${Q.mono}`,r.textAlign=`left`,r.textBaseline=`middle`;let n=e.name,i=Math.floor((t.w-4)/7),a=n.length>i?n.slice(0,i-1)+`…`:n;r.fillText(a,t.x+3,t.y+zJ/2)}}}function y(){let e=a.current;if(!e)return;let{w:t,h:n}=h(),r=g(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=c.current;if(!i)return;let{direction:o}=d.current,{roots:s,numRows:l}=p.current;if(s.length===0)return;let u=_(i,t-RJ.left-RJ.right,l*zJ,l,o);r.strokeStyle=`rgba(255,255,255,0.9)`,r.lineWidth=2,r.strokeRect(u.x+1,u.y+1,u.w-2,u.h-2);let f=`${i.name} (${i.value.toLocaleString()})`;r.font=`11px ${Q.mono}`;let m=r.measureText(f).width,v=Math.max(4,Math.min(t-m-8,u.x+u.w/2-m/2)),y=u.y<30?u.y+zJ+4:u.y-20;r.fillStyle=`rgba(0,0,0,0.8)`,r.fillRect(v-3,y-3,m+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(f,v,y)}let b=K(v);b.current=v;let x=K(null);x.current??=DH(()=>b.current(),()=>o.current);let S=()=>x.current.schedule(),C=()=>{xH(l.current),l.current=bH(y)};return W(()=>{x.current.now()}),W(()=>()=>x.current?.cancel(),[]),W(()=>{s.current=null,S()},[n]),G(()=>{let e=o.current;if(!e)return;let t=new EH(()=>{s.current=null,S(),C()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=a.current;if(!e)return;let t=e=>{e.preventDefault(),u.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),{direction:r}=d.current,{roots:i,flat:a,numRows:o}=p.current;if(i.length===0){c.current=null,C();return}let s=t.clientX-n.left,l=t.clientY-n.top,u=n.width-RJ.left-RJ.right,f=o*zJ,m=null;for(let e of a){let t=_(e,u,f,o,r);if(s>=t.x&&s<=t.x+t.w&&l>=t.y&&l<=t.y+t.h){m=e;break}}c.current=m,C()},r=()=>{c.current=null,C()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),_t(`div`,{ref:o,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:i,className:`chart-canvas`,role:`img`,"aria-label":`Flame graph`}),q(`canvas`,{ref:a,className:`chart-canvas chart-overlay`})]})}var KJ={top:24,right:24,bottom:52,left:56},qJ=[`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`,`#facc15`,`#60a5fa`],JJ=.8;function YJ(e,t,n,r){let i,a,o;if(t)a=t.length,i=t.values,o=e=>String(e+1);else{let t=e??[];a=t.length,i=Array.from({length:n},(e,n)=>Float64Array.from(t,e=>e.values[n]??0)),o=e=>t[e].label}let s=0,c=0;if(r===`stacked`)for(let e=0;e<a;e++){let t=0,n=0;for(let r of i){let i=r[e];i>0?t+=i:i<0&&(n+=i)}t>c&&(c=t),n<s&&(s=n)}else for(let e of i)for(let t=0;t<a;t++){let n=e[t];n>c&&(c=n),n<s&&(s=n)}return c===s&&(c=s+1),{n:a,values:i,label:o,lo:s,hi:c}}function XJ(e,t,n){let r=e.values.length,i=[],a=[],o=[],s=[],c=[],l=(e,t,n,r,l)=>{i.push(e),a.push(t),o.push(n),s.push(r),c.push(l)};if(e.n<=n)for(let n=0;n<e.n;n++)if(t===`grouped`){let t=.8/r;for(let i=0;i<r;i++){let r=e.values[i][n];r===r&&l(n-.4+i*t,n-.4+(i+1)*t-t*.05,0,r,i)}}else{let t=0,i=0;for(let a=0;a<r;a++){let r=e.values[a][n];r!==r||r===0||(r>0?(l(n-.4,n+.4,t,t+r,a),t+=r):(l(n-.4,n+.4,i,i+r,a),i+=r))}}else{let i=e.n/n,a=new Float64Array(r),o=new Float64Array(r);for(let s=0;s<n;s++){let n=Math.floor(s*i),c=Math.min(e.n,Math.floor((s+1)*i));if(!(c<=n)){a.fill(0),o.fill(0);for(let i=n;i<c;i++){let n=0,s=0;for(let c=0;c<r;c++){let r=e.values[c][i];r===r&&(t===`stacked`?r>0?(n+=r,n>o[c]&&(o[c]=n)):(s+=r,s<a[c]&&(a[c]=s)):(r>o[c]&&(o[c]=r),r<a[c]&&(a[c]=r)))}}for(let e=t===`stacked`?r-1:0;t===`stacked`?e>=0:e<r;t===`stacked`?e--:e++)(o[e]!==0||a[e]!==0)&&l(n-.5,c-.5,a[e],o[e],e)}}}return{x0:Float64Array.from(i),x1:Float64Array.from(a),y0:Float64Array.from(o),y1:Float64Array.from(s),k:Float64Array.from(c)}}function ZJ({groups:e,columns:t,seriesNames:n,colors:r,mode:i=`grouped`,horizontal:a=!1,valueRange:o,backgroundToken:s=``,onPlotContextMenu:c}){let l=nU(),u=K(null),d=K(null),f=K(null),p=K(null),m=K(null),h=K(null),g=K(0),_=K(c);G(()=>{_.current=c},[c]);let v=K(null),y=dt(()=>{let r=[e,i,n.length,t?.length,...t?.values??[]],a=v.current;if(a&&a.key.length===r.length&&a.key.every((e,t)=>e===r[t]))return a.value;let o=YJ(e,t,n.length,i);return v.current={key:r,value:o},o},[e,t,n.length,i]),b=K({bars:y,seriesNames:n,colors:r,mode:i,horizontal:a,valueRange:o});G(()=>{b.current={bars:y,seriesNames:n,colors:r,mode:i,horizontal:a,valueRange:o}},[y,n,r,i,a,o]);let x=K({plot:null,failed:!1,key:``,data:null,size:``});W(()=>()=>{x.current.plot?.dispose(),x.current.plot=null},[]);let S=K({bars:null,view:``});function C(){if(m.current)return m.current;let e=p.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return m.current=n,n}function w(){let e=p.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||300)}}function T(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function E(e){let t=b.current.colors??[];return Array.from({length:e},(e,n)=>t[n]??qJ[n%qJ.length])}function D(e,t){let{bars:n,valueRange:r}=b.current,i=n.lo,a=n.hi;r?.min!==void 0&&Number.isFinite(r.min)&&(i=r.min),r?.max!==void 0&&Number.isFinite(r.max)&&(a=r.max);let o=YW(KJ,e,t),{top:s,right:c,bottom:l,left:u}=o;return{lo:i,hi:a,top:s,left:u,plotW:e-u-c,plotH:t-s-l,tiny:o.tiny}}function O(e,t){let n=x.current;if(!n.plot&&!n.failed&&d.current&&(n.plot=uH(d.current,IK),n.failed=!n.plot),!n.plot||!d.current)return null;let r=Math.min(2,window.devicePixelRatio||1),i=`${e}x${t}@${r}`;return n.size!==i&&(n.plot.resize(e,t,r),d.current.style.width=`${e}px`,d.current.style.height=`${t}px`,n.size=i),n.plot}function k(){let e=u.current;if(!e)return;let{w:t,h:n}=w(),r=T(e,t,n);if(!r)return;let{bg:i,muted:a,grid:o}=C(),{bars:s,seriesNames:c,mode:d,horizontal:f}=b.current;r.fillStyle=i,r.fillRect(0,0,t,n);let m=O(t,n);if(s.n===0||c.length===0){m?.keep([]),m?.render(),r.fillStyle=a,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`No data`,KJ.left+8,KJ.top+8);return}let{lo:h,hi:g,top:_,left:v,plotW:y,plotH:k,tiny:A}=D(t,n),j=E(c.length),M=f?k:y,N=e=>f?v+(e-h)/(g-h)*y:_+k-(e-h)/(g-h)*k,P=e=>(f?_:v)+(e+.5)/s.n*M;l({left:v,top:_,width:y,height:k,...f?{x:{v0:h,v1:g}}:{y:{v0:h,v1:g}}}),r.strokeStyle=o,r.lineWidth=1;for(let e=0;e<=5;e++){let t=h+e/5*(g-h),n=N(t);r.beginPath(),f?(r.moveTo(n,_),r.lineTo(n,_+k)):(r.moveTo(v,n),r.lineTo(v+y,n)),r.stroke(),r.fillStyle=a,r.font=`9px ${Q.mono}`,!A&&(f?(r.textAlign=`center`,r.textBaseline=`top`,r.fillText(jz(t,(g-h)/5),n,_+k+4)):(r.textAlign=`right`,r.textBaseline=`middle`,r.fillText(jz(t,(g-h)/5),v-4,n)))}let F=`${h}|${g}|${f}`;(S.current.bars!==s||S.current.view!==F)&&(S.current={bars:s,view:F},CH(p.current));let I=Math.min(2,window.devicePixelRatio||1),L=Math.max(1,Math.round(M*I)),R=j.map(e=>{let t=zV(e);return[t[0],t[1],t[2],JJ]}),z={left:v,top:_,width:y,height:k};if(m){let e=`${d}|${f}|${L}|${j.join(`,`)}`;if(x.current.key!==e||x.current.data!==s){let t=XJ(s,d,L);f?m.setRects(`bars`,t.y0,t.y1,t.x0,t.x1,R,t.k):m.setRects(`bars`,t.x0,t.x1,t.y0,t.y1,R,t.k),m.keep([`bars`]),x.current.key=e,x.current.data=s}f?m.setView(h,g,s.n-.5,-.5,z):m.setView(-.5,s.n-.5,h,g,z),m.render()}else{let e=XJ(s,d,L);r.globalAlpha=JJ;for(let t=0;t<e.x0.length;t++){r.fillStyle=j[e.k[t]];let n=P(e.x0[t]-.5),i=P(e.x1[t]-.5),a=N(e.y0[t]),o=N(e.y1[t]);f?r.fillRect(Math.min(a,o),n,Math.max(1,Math.abs(o-a)),Math.max(1,i-n)):r.fillRect(n,Math.min(a,o),Math.max(1,i-n),Math.max(1,Math.abs(o-a)))}r.globalAlpha=1}if(h<0&&g>0){let e=N(0);r.strokeStyle=a,r.lineWidth=1.5,r.beginPath(),f?(r.moveTo(e,_),r.lineTo(e,_+k)):(r.moveTo(v,e),r.lineTo(v+y,e)),r.stroke()}r.fillStyle=a,r.font=`9px ${Q.mono}`;let B=Math.max(1,Math.ceil(s.n/Math.max(1,Math.floor(M/(f?14:48)))));for(let e=0;e<(A?0:s.n);e+=B){let t=P(e),n=s.label(e),i=n.length>14?n.slice(0,13)+`…`:n;f?(r.textAlign=`right`,r.textBaseline=`middle`,r.fillText(i,v-4,t)):(r.textAlign=`center`,r.textBaseline=`top`,r.fillText(i,t,_+k+4))}if(c.length>1&&!A){let e=f?_-14:_+k+32,t=v;r.font=`9px ${Q.mono}`,r.textBaseline=`top`;for(let n=0;n<c.length&&(r.fillStyle=j[n],r.fillRect(t,e,10,8),r.fillStyle=a,r.textAlign=`left`,r.fillText(c[n],t+13,e),t+=r.measureText(c[n]).width+26,!(t>v+y-30));n++);}}function A(){let e=f.current;if(!e)return;let{w:t,h:n}=w(),r=T(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=h.current,{bars:a,seriesNames:o,horizontal:s}=b.current;if(i===null||i>=a.n)return;let{top:c,left:l,plotW:u,plotH:d}=D(t,n),p=s?d:u,m=(s?c:l)+(i+.5)/a.n*p,g=Math.max(1,p/a.n);r.fillStyle=`rgba(255,255,255,0.08)`,s?r.fillRect(l,m-g/2,u,g):r.fillRect(m-g/2,c,g,d);let _=a.values.map((e,t)=>`${o.length>1?o[t]+` `:``}${Mz(e[i])}`).join(` `),v=`${a.label(i)}: ${_}`;r.font=`11px ${Q.mono}`;let y=r.measureText(v).width,x=s?l+u/2:m,S=s?m:c+d/2,C=Math.max(4,Math.min(t-y-8,x-y/2)),E=S-28<c?S+10:S-24;r.fillStyle=`rgba(0,0,0,0.8)`,r.fillRect(C-3,E-3,y+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(v,C,E)}let j=K(k);j.current=k;let M=K(null);M.current??=DH(()=>j.current(),()=>p.current);let N=()=>{g.current||=bH(()=>{g.current=0,A()})};return W(()=>{M.current.now()},[y,n,r,i,a,o]),W(()=>()=>{M.current?.cancel(),xH(g.current)},[]),W(()=>{m.current=null,M.current.schedule()},[s]),G(()=>{let e=p.current;if(!e)return;let t=new EH(()=>{m.current=null,M.current.schedule(),N()});return t.observe(e),()=>t.disconnect()},[]),G(()=>{let e=f.current;if(!e)return;let t=e=>{e.preventDefault(),_.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),{bars:r,horizontal:i}=b.current,{w:a,h:o}=w(),{top:s,left:c,plotW:l,plotH:u}=D(a,o),d=i?t.clientY-n.top-s:t.clientX-n.left-c,f=i?u:l,p=d>=0&&d<f&&r.n>0?Math.min(r.n-1,Math.floor(d/f*r.n)):null;p!==h.current&&(h.current=p,N())},r=()=>{h.current=null,N()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),_t(`div`,{ref:p,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:u,className:`chart-canvas`,role:`img`,"aria-label":`Bar chart`}),q(`canvas`,{ref:d,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),q(`canvas`,{ref:f,className:`chart-canvas chart-overlay`})]})}var QJ=[`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`];function $J(e,t){if(!t)return QJ[e%QJ.length];if(e===0)return t;let n=QJ.filter(e=>e.toLowerCase()!==t.toLowerCase());return n[(e-1)%n.length]}var eY={top:36,right:36,bottom:36,left:36};function tY({axes:e,series:t,fill:n=!0,color:r,backgroundToken:i=``,onPlotContextMenu:a}){let o=K(null),s=K(null),c=K(null),l=K(null),u=K(a);G(()=>{u.current=a},[a]);let d=K({axes:e,series:t,fill:n,color:r});G(()=>{d.current={axes:e,series:t,fill:n,color:r}},[e,t,n,r]);function f(){if(l.current)return l.current;let e=c.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return l.current=n,n}function p(){let e=c.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||300)}}function m(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function h(){let e=o.current;if(!e)return;let{w:t,h:n}=p(),r=m(e,t,n);if(!r)return;let{bg:i,muted:a,grid:s}=f(),{axes:c,series:l,fill:u}=d.current;if(r.fillStyle=i,r.fillRect(0,0,t,n),c.length<3||l.length===0){r.fillStyle=a,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`Select ≥ 3 axes`,eY.left+8,eY.top+8);return}let h=c.length,g=t/2,_=n/2,v=Math.min(t-eY.left-eY.right,n-eY.top-eY.bottom)/2,y=c.map((e,t)=>{let n=0;for(let e of l){let r=e.values[t]??0;r>n&&(n=r)}return n||1});function b(e){return Math.PI*2*e/h-Math.PI/2}function x(e,t){let n=b(e);return{x:g+Math.cos(n)*v*t,y:_+Math.sin(n)*v*t}}for(let e=1;e<=4;e++){let t=e/4;r.beginPath();for(let e=0;e<h;e++){let n=x(e,t);e===0?r.moveTo(n.x,n.y):r.lineTo(n.x,n.y)}r.closePath(),r.strokeStyle=s,r.lineWidth=1,r.stroke()}r.strokeStyle=a,r.lineWidth=1;for(let e=0;e<h;e++){let t=x(e,1);r.beginPath(),r.moveTo(g,_),r.lineTo(t.x,t.y),r.stroke(),r.fillStyle=a,r.font=`10px ${Q.mono}`;let n=b(e),i=x(e,1+10/v);r.textAlign=Math.abs(Math.cos(n))<.1?`center`:Math.cos(n)<0?`right`:`left`,r.textBaseline=Math.abs(Math.sin(n))<.1?`middle`:Math.sin(n)<0?`bottom`:`top`;let o=c[e].length>12?c[e].slice(0,11)+`…`:c[e];r.fillText(o,i.x,i.y)}for(let e=0;e<l.length;e++){let t=l[e],n=$J(e,d.current.color);r.beginPath();for(let e=0;e<h;e++){let n=Math.max(0,Math.min(1,(t.values[e]??0)/y[e])),i=x(e,n);e===0?r.moveTo(i.x,i.y):r.lineTo(i.x,i.y)}r.closePath(),u&&(r.fillStyle=n,r.globalAlpha=.15,r.fill()),r.globalAlpha=1,r.strokeStyle=n,r.lineWidth=1,r.stroke();for(let e=0;e<h;e++){let i=Math.max(0,Math.min(1,(t.values[e]??0)/y[e])),a=x(e,i);r.beginPath(),r.arc(a.x,a.y,3,0,Math.PI*2),r.fillStyle=n,r.globalAlpha=.9,r.fill()}r.globalAlpha=1}if(l.length>1){let e=eY.left,i=n-eY.bottom-10;r.font=`9px ${Q.mono}`,r.textBaseline=`top`;for(let n=0;n<l.length&&(r.fillStyle=$J(n,d.current.color),r.fillRect(e,i,10,8),r.fillStyle=a,r.textAlign=`left`,r.fillText(l[n].name,e+13,i),e+=r.measureText(l[n].name).width+26,!(e>t-eY.right-30));n++);}}let g=K(h);g.current=h;let _=K(null);_.current??=DH(()=>g.current(),()=>c.current);let v=()=>_.current.schedule();return W(()=>{_.current.now()}),W(()=>()=>_.current?.cancel(),[]),W(()=>{l.current=null,v()},[i]),G(()=>{let e=c.current;if(!e)return;let t=new EH(()=>{l.current=null,v()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=s.current;if(!e)return;let t=e=>{e.preventDefault(),u.current?.({clientX:e.clientX,clientY:e.clientY})};return e.addEventListener(`contextmenu`,t),()=>{e.removeEventListener(`contextmenu`,t)}},[]),_t(`div`,{ref:c,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`Radar chart`}),q(`canvas`,{ref:s,className:`chart-canvas chart-overlay`})]})}var nY={top:16,right:16,bottom:40,left:52},rY=[`#38bdf8`,`#4ade80`,`#fb7185`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`];function iY(e,t){let n=e.length>0&&e.every(t=>t.x===e[0].x||t.x.length===e[0].x.length),r=t&&n,i=e.map(e=>e.x),a=[],o=[],s=null;for(let t of e){if(!r){a.push(t.y),o.push(null);continue}let e=t.x.length,n=new Float64Array(e);for(let r=0;r<e;r++){let e=t.y[r];n[r]=(s?s[r]:0)+(e>0?e:0)}a.push(n),o.push(s??null),s=n}let c=1/0,l=-1/0,u=0,d=0;for(let e of i)for(let t=0;t<e.length;t++){let n=e[t];n<c&&(c=n),n>l&&(l=n)}for(let e of a)for(let t=0;t<e.length;t++){let n=e[t];n<u&&(u=n),n>d&&(d=n)}return Number.isFinite(c)||(c=0,l=1),{x:i,lo:o,hi:a,ascending:i.map(e=>GK(e)),xLo:c,xHi:l,yLo:u,yHi:d}}function aY({series:e,stacked:t=!1,yRange:n,backgroundToken:r=``,onPlotContextMenu:i}){let a=nU(),o=K(null),s=K(null),c=K(null),l=K(null),u=K(null),d=K(null),f=K(0),p=K(i);G(()=>{p.current=i},[i]);let m=K(null),h=dt(()=>{let n=m.current;if(n&&n.stacked===t&&n.series.length===e.length&&n.series.every((t,n)=>t.x===e[n].x&&t.y===e[n].y&&t.name===e[n].name))return n.value;let r=iY(e,t);return m.current={series:e,stacked:t,value:r},r},[e,t]),g=K({series:e,prepared:h,yRange:n});G(()=>{g.current={series:e,prepared:h,yRange:n}},[e,h,n]);let _=K({plot:null,failed:!1,key:``,size:``});W(()=>()=>{_.current.plot?.dispose(),_.current.plot=null},[]);let v=K({prepared:null,view:``});function y(){if(u.current)return u.current;let e=l.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return u.current=n,n}function b(){let e=l.current;return{w:Math.max(1,e?.clientWidth||600),h:Math.max(1,e?.clientHeight||300)}}function x(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function S(e,t){let n=(e.xHi-e.xLo)*.01||.5,r=e.yLo,i=e.yHi;return i===r&&(i=r+1),i+=(i-r)*.05,t?.min!==void 0&&Number.isFinite(t.min)&&(r=t.min),t?.max!==void 0&&Number.isFinite(t.max)&&(i=t.max),{xLo:e.xLo-n,xHi:e.xHi+n,yLo:r,yHi:i}}function C(e,t,n,r,i){let a=e.x[t],o=e.hi[t],s=e.lo[t];if(!e.ascending[t]||a.length<=2*i)return{x:a,hi:o,lo:s??new Float64Array(a.length)};let c=HK(a,o,n,r,i);return{x:WK(a,c),hi:WK(o,c),lo:s?WK(s,c):new Float64Array(c.length)}}function w(){let e=o.current;if(!e)return;let{w:n,h:r}=b(),i=x(e,n,r);if(!i)return;let{bg:s,muted:c,grid:u}=y(),{series:d,prepared:f,yRange:p}=g.current;i.fillStyle=s,i.fillRect(0,0,n,r);let m=_.current.plot;if(d.length===0){m?.keep([]),m?.render(),i.fillStyle=c,i.font=`13px ${Q.sans}`,i.textAlign=`left`,i.textBaseline=`top`,i.fillText(`No data`,nY.left+8,nY.top+8);return}let h=YW(nY,n,r),{top:w,right:D,bottom:O,left:k}=h,A=n-k-D,j=r-w-O,{xLo:M,xHi:N,yLo:P,yHi:F}=S(f,p),I=e=>k+(e-M)/(N-M)*A,L=e=>w+j-(e-P)/(F-P)*j;a({left:k,top:w,width:A,height:j,x:{v0:M,v1:N},y:{v0:P,v1:F}}),i.strokeStyle=u,i.lineWidth=1;for(let e=0;e<=5;e++){let t=P+e/5*(F-P),n=L(t);i.beginPath(),i.moveTo(k,n),i.lineTo(k+A,n),i.stroke(),i.fillStyle=c,i.font=`9px ${Q.mono}`,i.textAlign=`right`,i.textBaseline=`middle`,h.tiny||i.fillText(jz(t,(F-P)/5),k-4,n)}let R=Math.min(8,f.x[0]?.length??5);for(let e=0;e<=R;e++){let t=M+e/R*(N-M),n=I(t);i.beginPath(),i.moveTo(n,w),i.lineTo(n,w+j),i.stroke(),i.fillStyle=c,i.font=`9px ${Q.mono}`,i.textAlign=`center`,i.textBaseline=`top`,h.tiny||i.fillText(jz(t,(N-M)/R),n,w+j+4)}let z=`${M}|${N}|${P}|${F}`;(v.current.prepared!==f||v.current.view!==z)&&(v.current={prepared:f,view:z},CH(l.current));let B=E(n,r),V=Math.min(2,window.devicePixelRatio||1),ee=Math.max(1,Math.round(A*V)),te=d.map((e,t)=>zV(rY[t%rY.length]));if(B){let e=`${M}|${N}|${ee}`;if(_.current.key!==e||T.current!==f){let n=[];for(let e=0;e<d.length;e++){let r=C(f,e,M,N,ee),i=te[e],a=[i[0],i[1],i[2],f.lo[e]||t?.7:.25];B.setBands(`b${e}`,r.x,r.lo,r.hi,a),B.setLine(`l${e}`,r.x,r.hi,i,1),n.push(`b${e}`,`l${e}`)}B.keep(n),_.current.key=e,T.current=f}B.setView(M,N,P,F,{left:k,top:w,width:A,height:j}),B.render()}else for(let e=0;e<d.length;e++){let n=C(f,e,M,N,ee),r=rY[e%rY.length];i.save(),i.beginPath(),i.rect(k,w,A,j),i.clip(),i.beginPath();for(let e=0;e<n.x.length;e++){let t=I(n.x[e]);e===0?i.moveTo(t,L(n.lo[e])):i.lineTo(t,L(n.lo[e]))}for(let e=n.x.length-1;e>=0;e--)i.lineTo(I(n.x[e]),L(n.hi[e]));i.closePath(),i.fillStyle=r,i.globalAlpha=f.lo[e]||t?.7:.25,i.fill(),i.beginPath();for(let e=0;e<n.x.length;e++){let t=I(n.x[e]),r=L(n.hi[e]);e===0?i.moveTo(t,r):i.lineTo(t,r)}i.globalAlpha=1,i.strokeStyle=r,i.lineWidth=1,i.stroke(),i.restore()}if(d.length>1&&!h.tiny){let e=k,t=w+j+24;i.font=`9px ${Q.mono}`,i.textBaseline=`top`;for(let n=0;n<d.length&&(i.fillStyle=rY[n%rY.length],i.fillRect(e,t,10,8),i.fillStyle=c,i.textAlign=`left`,i.fillText(d[n].name,e+13,t),e+=i.measureText(d[n].name).width+26,!(e>k+A-30));n++);}}let T=K(null);function E(e,t){let n=_.current;if(!n.plot&&!n.failed&&s.current&&(n.plot=uH(s.current,IK),n.failed=!n.plot),!n.plot||!s.current)return null;let r=Math.min(2,window.devicePixelRatio||1),i=`${e}x${t}@${r}`;return n.size!==i&&(n.plot.resize(e,t,r),s.current.style.width=`${e}px`,s.current.style.height=`${t}px`,n.size=i),n.plot}function D(){let e=c.current;if(!e)return;let{w:t,h:n}=b(),r=x(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=d.current;if(i===null)return;let{prepared:a,yRange:o}=g.current,{top:s,right:l,left:u,bottom:f}=YW(nY,t,n),p=n-s-f;r.strokeStyle=`rgba(255,255,255,0.4)`,r.lineWidth=1,r.setLineDash([4,4]),r.beginPath(),r.moveTo(i,s),r.lineTo(i,s+p),r.stroke(),r.setLineDash([]);let{xLo:m,xHi:h}=S(a,o),_=t-u-l,v=`x=${Mz(m+(i-u)/_*(h-m))}`;r.font=`11px ${Q.mono}`;let y=r.measureText(v).width,C=Math.max(4,Math.min(t-y-8,i-y/2));r.fillStyle=`rgba(0,0,0,0.7)`,r.fillRect(C-3,s-3,y+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(v,C,s)}let O=K(w);O.current=w;let k=K(null);k.current??=DH(()=>O.current(),()=>l.current);let A=()=>{f.current||=bH(()=>{f.current=0,D()})};return W(()=>{k.current.now()},[e,h,n]),W(()=>()=>{k.current?.cancel(),xH(f.current)},[]),W(()=>{u.current=null,k.current.schedule()},[r]),G(()=>{let e=l.current;if(!e)return;let t=new EH(()=>{u.current=null,k.current.schedule(),A()});return t.observe(e),()=>t.disconnect()},[]),G(()=>{let e=c.current;if(!e)return;let t=e=>{e.preventDefault(),p.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect();d.current=t.clientX-n.left,A()},r=()=>{d.current=null,A()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),_t(`div`,{ref:l,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`Area chart`}),q(`canvas`,{ref:s,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),q(`canvas`,{ref:c,className:`chart-canvas chart-overlay`})]})}var oY={top:16,right:16,bottom:40,left:52},sY=[`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`];function cY({series:e,complement:t=!1,logX:n=!1,backgroundToken:r=``,onPlotContextMenu:i}){let a=nU(),o=K(null),s=K(null),c=K(null),l=K(null),u=K(null),d=K(0),f=K(i);G(()=>{f.current=i},[i]);let p=K({series:e,complement:t,logX:n});G(()=>{p.current={series:e,complement:t,logX:n}},[e,t,n]);let m=dt(()=>{let t=e.map(e=>Float64Array.from(e.values).sort()),n=1/0,r=-1/0;for(let e of t)e.length&&(n=Math.min(n,e[0]),r=Math.max(r,e[e.length-1]));return{all:t,xLo:n,xHi:r}},[e]),h=K(m);G(()=>{h.current=m},[m]);function g(){if(l.current)return l.current;let e=c.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return l.current=n,n}function _(){let e=c.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||300)}}function v(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function y(){let e=o.current;if(!e)return;let{w:t,h:n}=_(),r=v(e,t,n);if(!r)return;let{bg:i,muted:s,grid:c}=g(),{series:l,complement:u,logX:d}=p.current;if(r.fillStyle=i,r.fillRect(0,0,t,n),l.length===0){r.fillStyle=s,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`No data`,oY.left+8,oY.top+8);return}let{top:f,right:m,bottom:y,left:b}=oY,x=t-b-m,S=n-f-y,{xLo:C,xHi:w}=h.current;Number.isFinite(C)||(C=0,w=1);let T=e=>Math.log10(Math.max(1e-10,e)),E=d?T(C):C,D=d?T(w):w,O=e=>b+((d?T(e):e)-E)/(D-E||1)*x,k=e=>f+S-e*S;a({left:b,top:f,width:x,height:S,x:{v0:C,v1:w,log:d}});for(let e=0;e<=5;e++){let t=e/5,n=k(t);r.strokeStyle=c,r.lineWidth=1,r.beginPath(),r.moveTo(b,n),r.lineTo(b+x,n),r.stroke(),r.fillStyle=s,r.font=`9px ${Q.mono}`,r.textAlign=`right`,r.textBaseline=`middle`,r.fillText(String(t.toFixed(2)),b-4,n)}for(let e=0;e<=6;e++){let t=C+e/6*(w-C),n=O(t);r.strokeStyle=c,r.lineWidth=1,r.beginPath(),r.moveTo(n,f),r.lineTo(n,f+S),r.stroke(),r.fillStyle=s,r.font=`9px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`top`,r.fillText(jz(t,(w-C)/6),n,f+S+4)}for(let e=0;e<l.length;e++){let t=h.current.all[e],n=t?.length??0;if(n===0)continue;let i=e=>k(u?1-(e+1)/n:(e+1)/n),a=O(t[0]),o=k(+!!u);r.beginPath(),r.moveTo(a,o);for(let e=0;e<n;e++){if(e+1<n&&t[e+1]===t[e])continue;let s=O(t[e]),c=i(e);if(Math.abs(s-a)<.5){o=c;continue}r.lineTo(a,o),r.lineTo(s,o),a=s,o=c}r.lineTo(a,o),r.strokeStyle=sY[e%sY.length],r.lineWidth=1,r.stroke()}if(l.length>1){let e=b,t=f+S+24;r.font=`9px ${Q.mono}`,r.textBaseline=`top`;for(let n=0;n<l.length&&(r.fillStyle=sY[n%sY.length],r.fillRect(e,t,16,2),r.fillStyle=s,r.textAlign=`left`,r.fillText(l[n].name,e+20,t-3),e+=r.measureText(l[n].name).width+30,!(e>b+x-30));n++);}r.save(),r.translate(12,f+S/2),r.rotate(-Math.PI/2),r.fillStyle=s,r.font=`9px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`middle`,r.fillText(u?`CCDF`:`CDF`,0,0),r.restore()}function b(){let e=s.current;if(!e)return;let{w:t,h:n}=_(),r=v(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=u.current;if(i===null)return;let{top:a,left:o,right:c}=oY,l=n-a-oY.bottom,d=t-o-c;r.strokeStyle=`rgba(255,255,255,0.4)`,r.lineWidth=1,r.setLineDash([4,4]),r.beginPath(),r.moveTo(i,a),r.lineTo(i,a+l),r.stroke(),r.setLineDash([]);let{xLo:f,xHi:p}=h.current;if(!Number.isFinite(f))return;let m=Mz(f+(i-o)/d*(p-f));r.font=`11px ${Q.mono}`;let g=r.measureText(m).width,y=Math.max(4,Math.min(t-g-8,i-g/2));r.fillStyle=`rgba(0,0,0,0.7)`,r.fillRect(y-3,a+l+2,g+6,16),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(m,y,a+l+4)}let x=K(y);x.current=y;let S=K(null);S.current??=DH(()=>x.current(),()=>c.current);let C=()=>S.current.schedule(),w=()=>{xH(d.current),d.current=bH(b)};return W(()=>{S.current.now()}),W(()=>()=>S.current?.cancel(),[]),W(()=>{l.current=null,C()},[r]),G(()=>{let e=c.current;if(!e)return;let t=new EH(()=>{l.current=null,C(),w()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=s.current;if(!e)return;let t=e=>{e.preventDefault(),f.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect();u.current=t.clientX-n.left,w()},r=()=>{u.current=null,w()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),_t(`div`,{ref:c,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`CDF chart`}),q(`canvas`,{ref:s,className:`chart-canvas chart-overlay`})]})}var lY={top:16,right:40,bottom:40,left:52},uY=[`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`,`#facc15`,`#60a5fa`];function dY(e){return[Math.round(255*Math.min(1,Math.max(0,3.5*e-.5))),Math.round(255*Math.min(1,Math.max(0,e<.5?2*e:2-2*e))),Math.round(255*Math.min(1,Math.max(0,1.5-3.5*e)))]}function fY(e){let[t,n,r]=dY(e);return`rgb(${t},${n},${r})`}var pY=(()=>{let e=new Uint8Array(1024);for(let t=0;t<256;t++)e.set([...dY(t/255),255],t*4);return e})(),mY=()=>{let e=new Uint8Array(1024);for(let t=0;t<256;t++){let[n,r,i]=XG(uY[t%uY.length],1);e.set([n*255,r*255,i*255,255],t*4)}return e};function hY(e,t,n){let r=e.length,i=1/0,a=-1/0,o=1/0,s=-1/0,c=1/0,l=-1/0;for(let t=0;t<r;t++){let n=e.x[t],r=e.y[t],u=e.size[t];n<i&&(i=n),n>a&&(a=n),r<o&&(o=r),r>s&&(s=r),u<c&&(c=u),u>l&&(l=u)}let u=Number.isFinite(i)?(()=>{let e=(a-i)*.1||1,t=(s-o)*.1||1;return{xLo:i-e,xHi:a+e,yLo:o-t,yHi:s+t,sLo:c,sHi:l}})():{xLo:-1,xHi:1,yLo:-1,yHi:1,sLo:1,sHi:1},d=u.sHi-u.sLo||1,f=new Float32Array(r);for(let t=0;t<r;t++)f[t]=3+(e.size[t]-u.sLo)/d*(n-3);let p=0,m=1,h=null,g=`single`;if(t&&e.colorValue){let t=e.colorValue,n=1/0,i=-1/0;for(let e=0;e<r;e++)t[e]<n&&(n=t[e]),t[e]>i&&(i=t[e]);Number.isFinite(n)&&(p=n,m=i),h=new Float32Array(r);for(let e=0;e<r;e++)h[e]=t[e]===t[e]?Math.max(0,Math.min(1,(t[e]-p)/(m-p||1))):0;g=`colormap`}else !t&&e.colorIndex&&(h=Float32Array.from(e.colorIndex,e=>e>=0?e%256:0),g=`dataset`);let _=Uint32Array.from({length:r},(e,t)=>t).sort((e,t)=>(f[t]||0)-(f[e]||0)),v=e=>{let t=new Float64Array(r);for(let n=0;n<r;n++)t[n]=e[_[n]];return t};return{ext:u,radius:f,key:h,mode:g,colorLo:p,colorHi:m,drawn:{x:v(e.x),y:v(e.y),r:v(f),k:h?v(h):void 0}}}function gY({points:e,color:t=`#64748b`,colorByNumeric:n=!1,maxRadius:r=24,backgroundToken:i=``,onPlotContextMenu:a}){let o=nU(),s=K(null),c=K(null),l=K(null),u=K(null),d=K(null),f=K(null),p=K(0),m=K(a);G(()=>{m.current=a},[a]);let h=dt(()=>hY(e,n,r),[e,n,r]),g=K({points:e,color:t,colorByNumeric:n,maxRadius:r,model:h});G(()=>{g.current={points:e,color:t,colorByNumeric:n,maxRadius:r,model:h}},[e,t,n,r,h]);let _=K({r:null,failed:!1,size:``,model:null,style:``});W(()=>()=>{_.current.r?.dispose(),_.current.r=null},[]);function v(){if(d.current)return d.current;let e=u.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return d.current=n,n}function y(){let e=u.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||300)}}function b(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function x(e,t){let{xLo:n,xHi:r,yLo:i,yHi:a}=g.current.model.ext,{top:s,right:c,bottom:l,left:u}=lY,d=e-u-c,f=t-s-l;return o({left:u,top:s,width:d,height:f,x:{v0:n,v1:r},y:{v0:i,v1:a}}),{plotW:d,plotH:f,xToPx:e=>u+(e-n)/(r-n)*d,yToPx:e=>s+(1-(e-i)/(a-i))*f}}function S(e,t){let n=_.current;!n.r&&!n.failed&&c.current&&(n.r=uH(c.current,qW),n.failed=!n.r);let r=n.r;if(!r||!c.current)return null;let i=Math.min(2,window.devicePixelRatio||1),a=`${e}x${t}@${i}`;n.size!==a&&(r.resize(e,t,i),c.current.style.width=`${e}px`,c.current.style.height=`${t}px`,n.size=a);let{model:o,color:s}=g.current;n.model!==o&&(r.setData(o.drawn.x,o.drawn.y,o.drawn.k,!1,o.drawn.r),n.model=o,CH(u.current));let l=`${o.mode}|${s}`;return n.style!==l&&(r.setStyle(o.mode===`single`?{kind:`single`,rgba:XG(s,1)}:{kind:o.mode,palette:o.mode===`colormap`?pY:mY()},3,.65),r.setDraw(!0,!1,0),n.style=l),r}function C(){let e=s.current;if(!e)return;let{w:t,h:n}=y(),r=b(e,t,n);if(!r)return;let{bg:i,muted:a,grid:o}=v(),{points:c,color:l,colorByNumeric:u,model:d}=g.current;r.fillStyle=i,r.fillRect(0,0,t,n);let f=S(t,n);if(c.length===0){f?.setData([],[]),_.current.model=null,f?.render(),r.fillStyle=a,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`No data`,lY.left+8,lY.top+8);return}let{xLo:p,xHi:m,yLo:h,yHi:C}=d.ext,{top:w,left:T}=lY,{plotW:E,plotH:D,xToPx:O,yToPx:k}=x(t,n);r.strokeStyle=o,r.lineWidth=1;for(let e=0;e<=5;e++){let t=p+e/5*(m-p),n=O(t);r.beginPath(),r.moveTo(n,w),r.lineTo(n,w+D),r.stroke(),r.fillStyle=a,r.font=`9px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`top`,r.fillText(jz(t,(m-p)/5),n,w+D+4);let i=h+e/5*(C-h),o=k(i);r.beginPath(),r.moveTo(T,o),r.lineTo(T+E,o),r.stroke(),r.fillStyle=a,r.textAlign=`right`,r.textBaseline=`middle`,r.fillText(jz(i,(C-h)/5),T-4,o)}if(f)f.setView(p,m,h,C,{left:T,top:w,width:E,height:D}),f.render();else{let e=d.drawn;r.globalAlpha=.65;for(let t=0;t<e.x.length;t++){if(e.x[t]!==e.x[t]||e.y[t]!==e.y[t])continue;let n=e.k?.[t]??0;r.fillStyle=d.mode===`colormap`?fY(n):d.mode===`dataset`?uY[n%uY.length]:l,r.beginPath(),r.arc(O(e.x[t]),k(e.y[t]),e.r[t],0,Math.PI*2),r.fill()}r.globalAlpha=1}let A=c.colorLabels??[];if(!u&&A.length>0&&A.length<=10){let e=T,t=n-lY.bottom-10;r.font=`9px ${Q.mono}`,r.textBaseline=`top`;for(let n=0;n<A.length;n++){let i=A[n];if(r.fillStyle=uY[n%uY.length],r.beginPath(),r.arc(e+4,t+4,4,0,Math.PI*2),r.fill(),r.fillStyle=a,r.textAlign=`left`,r.fillText(i,e+10,t),e+=r.measureText(i).width+20,e>T+E-60)break}}}function w(){let e=l.current;if(!e)return;let{w:t,h:n}=y(),r=b(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=f.current;if(i===null)return;let{points:a,model:o}=g.current;if(i<0||i>=a.length)return;let{xToPx:s,yToPx:c}=x(t,n),u=o.radius[i],d=s(a.x[i]),p=c(a.y[i]);r.beginPath(),r.arc(d,p,u+2,0,Math.PI*2),r.strokeStyle=`rgba(255,255,255,0.9)`,r.lineWidth=2,r.stroke();let m=[],h=a.label?.(i);h&&m.push(h),m.push(`(${Mz(a.x[i])}, ${Mz(a.y[i])})`),m.push(`size=${Mz(a.size[i])}`);let _=a.colorIndex?.[i];_!==void 0&&_>=0&&a.colorLabels?m.push(a.colorLabels[_]):a.colorValue&&m.push(Mz(a.colorValue[i]));let v=m.join(` · `);r.font=`11px ${Q.mono}`;let S=r.measureText(v).width,C=Math.max(4,Math.min(t-S-8,d+u+4)),w=p-20<lY.top?p+u+4:p-20;r.fillStyle=`rgba(0,0,0,0.8)`,r.fillRect(C-3,w-3,S+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(v,C,w)}let T=K(C);T.current=C;let E=K(null);E.current??=DH(()=>T.current(),()=>u.current);let D=()=>E.current.schedule(),O=()=>{xH(p.current),p.current=bH(w)};return W(()=>{E.current.now()}),W(()=>()=>E.current?.cancel(),[]),W(()=>{d.current=null,D()},[i]),G(()=>{let e=u.current;if(!e)return;let t=new EH(()=>{d.current=null,D(),O()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=l.current;if(!e)return;let t=null,n=e=>{e.preventDefault(),m.current?.({clientX:e.clientX,clientY:e.clientY})},r=n=>{let r=e.getBoundingClientRect(),{points:i,maxRadius:a,model:o}=g.current,{w:s,h:c}=y(),{plotW:l,plotH:u,xToPx:d,yToPx:p}=x(s,c),m=e=>d(i.x[e])-lY.left,h=e=>p(i.y[e])-lY.top,_=a+6,v=`${s}|${c}|${_}`;(!t||t.model!==o||t.key!==v)&&(t={model:o,key:v,g:OJ(i.length,l,u,_,m,h)}),f.current=kJ(t.g,n.clientX-r.left-lY.left,n.clientY-r.top-lY.top,_,m,h,e=>o.radius[e]+6),O()},i=()=>{f.current=null,O()};return e.addEventListener(`contextmenu`,n),e.addEventListener(`mousemove`,r),e.addEventListener(`mouseleave`,i),()=>{e.removeEventListener(`contextmenu`,n),e.removeEventListener(`mousemove`,r),e.removeEventListener(`mouseleave`,i)}},[]),_t(`div`,{ref:u,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:s,className:`chart-canvas`,role:`img`,"aria-label":`Bubble chart`}),q(`canvas`,{ref:c,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),q(`canvas`,{ref:l,className:`chart-canvas chart-overlay`})]})}var _Y={top:8,right:8,bottom:8,left:8},vY=[`#f97316`,`#38bdf8`,`#4ade80`,`#a78bfa`,`#fbbf24`,`#fb7185`,`#34d399`,`#e879f9`,`#facc15`,`#60a5fa`];function yY(e){let t=new Map;for(let n of e){let e=n.parent??``;t.has(e)||t.set(e,[]),t.get(e).push(n)}function n(r,i){let a=(t.get(r)??[]).map(e=>n(e.name,i+1)),o=e.find(e=>e.name===r),s=a.reduce((e,t)=>e+t.value,0);return{name:r,value:o?Math.max(o.value,s):s,children:a,depth:i}}let r=new Set(e.map(e=>e.name));return e.filter(e=>!e.parent||!r.has(e.parent)).map(e=>n(e.name,0))}function bY(e,t,n,r,i,a){if(e.length===0||r<=0||i<=0||e.reduce((e,t)=>e+t.value,0)===0)return[];let o=[],s=[...e].sort((e,t)=>t.value-e.value),c=t,l=n,u=r,d=i;for(;s.length>0;){let e=u*d,t=s.reduce((e,t)=>e+t.value,0),n=e/t,r=[],i=1/0;for(let e=1;e<=s.length;e++){let a=s.slice(0,e),o=a.reduce((e,t)=>e+t.value,0)/t*(u<=d?d:u),c=0;for(let e of a){let t=e.value*n/o,r=Math.max(t/o,o/t);r>c&&(c=r)}if(c<i)i=c,r=a;else break}let f=r.reduce((e,t)=>e+t.value,0),p=u<=d,m=f/t*(p?d:u),h=0;for(let e of r){let t=e.value/f,n=p?u:t*u,r=p?t*d:d,i=p?c:c+h,s=p?l+h:l,g=p?m:n,_=p?r:m;if(o.push({node:e,x:i,y:s,w:g,h:_,depth:a}),e.children.length>0&&g>4&&_>4){let t=bY(e.children,i+1,s+1,g-2,_-2,a+1);for(let e of t)o.push(e)}h+=p?r:n}s=s.slice(r.length),p?(c+=m,u-=m):(l+=m,d-=m)}return o}function xY({nodes:e,backgroundToken:t=``,onPlotContextMenu:n}){let r=K(null),i=K(null),a=K(null),o=K(null),s=K([]),c=K(null),l=K(0),u=K(n);G(()=>{u.current=n},[n]);let d=K({nodes:e});G(()=>{d.current={nodes:e}},[e]);let f=dt(()=>yY(e),[e]),p=K(f);G(()=>{p.current=f},[f]);function m(){if(o.current)return o.current;let e=a.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return o.current=n,n}function h(){let e=a.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||300)}}function g(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function _(){let e=r.current;if(!e)return;let{w:t,h:n}=h(),i=g(e,t,n);if(!i)return;let{bg:a,muted:o}=m(),{nodes:l}=d.current;if(i.fillStyle=a,i.fillRect(0,0,t,n),l.length===0){i.fillStyle=o,i.font=`13px ${Q.sans}`,i.textAlign=`left`,i.textBaseline=`top`,i.fillText(`No data`,_Y.left+8,_Y.top+8);return}let u=p.current,f=t-_Y.left-_Y.right,_=n-_Y.top-_Y.bottom,v=bY(u,_Y.left,_Y.top,f,_,0);s.current=v;for(let e=0;e<v.length;e++){let{node:t,x:n,y:r,w:o,h:s,depth:l}=v[e];if(o<2||s<2)continue;let u=vY[l%vY.length],d=c.current===e;if(i.fillStyle=u,i.globalAlpha=d?.95:.75,i.fillRect(n,r,o,s),i.globalAlpha=1,i.strokeStyle=a,i.lineWidth=1,i.strokeRect(n,r,o,s),o>20&&s>14){i.fillStyle=`rgba(0,0,0,0.75)`,i.font=`${Math.min(11,s-4)}px ${Q.mono}`,i.textAlign=`left`,i.textBaseline=`top`;let e=Math.floor((o-4)/6),a=t.name.length>e?t.name.slice(0,e-1)+`…`:t.name;i.fillText(a,n+3,r+3)}}i.globalAlpha=1}function v(){let e=i.current;if(!e)return;let{w:t,h:n}=h(),r=g(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let a=c.current;if(a===null)return;let o=s.current;if(a<0||a>=o.length)return;let{node:l,x:u,y:d,w:f,h:p}=o[a];r.strokeStyle=`rgba(255,255,255,0.9)`,r.lineWidth=2,r.strokeRect(u+1,d+1,f-2,p-2);let m=`${l.name}: ${l.value.toLocaleString()}`;r.font=`11px ${Q.mono}`;let _=r.measureText(m).width,v=Math.max(4,Math.min(t-_-8,u+f/2-_/2)),y=d<30?d+p+4:d-20;r.fillStyle=`rgba(0,0,0,0.8)`,r.fillRect(v-3,y-3,_+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(m,v,y)}let y=K(_);y.current=_;let b=K(null);b.current??=DH(()=>y.current(),()=>a.current);let x=()=>b.current.schedule(),S=()=>{xH(l.current),l.current=bH(v)};return W(()=>{b.current.now()}),W(()=>()=>b.current?.cancel(),[]),W(()=>{o.current=null,x()},[t]),G(()=>{let e=a.current;if(!e)return;let t=new EH(()=>{o.current=null,x(),S()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=i.current;if(!e)return;let t=e=>{e.preventDefault(),u.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),r=t.clientX-n.left,i=t.clientY-n.top,a=s.current,o=null;for(let e=0;e<a.length;e++){let t=a[e];r>=t.x&&r<=t.x+t.w&&i>=t.y&&i<=t.y+t.h&&(o=e)}c.current=o,S()},r=()=>{c.current=null,S()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),_t(`div`,{ref:a,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:r,className:`chart-canvas`,role:`img`,"aria-label":`Treemap`}),q(`canvas`,{ref:i,className:`chart-canvas chart-overlay`})]})}var SY={top:8,right:8,bottom:8,left:8},CY=14,wY=8,TY=[`#38bdf8`,`#4ade80`,`#fb7185`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`,`#facc15`,`#60a5fa`];function EY(e,t,n,r){if(e.length===0||t.length===0)return{nodes:[],links:[]};let i=n-SY.left-SY.right,a=r-SY.top-SY.bottom,o=new Map;for(let t of e)o.set(t,0);let s=!0;for(;s;){s=!1;for(let e of t){let t=o.get(e.source)??0;(o.get(e.target)??0)<=t&&(o.set(e.target,t+1),s=!0)}}let c=Math.max(0,...Array.from(o.values())),l=e=>SY.left+e/Math.max(1,c)*(i-CY),u=new Map;for(let[e,t]of o)u.has(t)||u.set(t,[]),u.get(t).push(e);let d=new Map;for(let t of e)d.set(t,0);for(let e of t)d.set(e.source,(d.get(e.source)??0)+e.value),d.set(e.target,(d.get(e.target)??0)+e.value);let f=Math.max(1,...Array.from(d.values())),p=new Map;for(let[t,n]of u){let r=a-(n.length-1)*wY,i=0;for(let e of n)i+=Math.max(8,(d.get(e)??0)/f*r*.8);let o=SY.top+(a-i-(n.length-1)*wY)/2;for(let i=0;i<n.length;i++){let a=n[i],s=Math.max(8,(d.get(a)??0)/f*r*.8);p.set(a,{name:a,x:l(t),y:o,h:s,color:TY[e.indexOf(a)%TY.length]}),o+=s+wY}}let m=new Map,h=new Map;for(let[e,t]of p)m.set(e,t.y),h.set(e,t.y);let g=[];for(let e of t){let t=p.get(e.source),n=p.get(e.target);if(!t||!n)continue;let r=Math.max(1,e.value/f*t.h),i=m.get(e.source)??t.y,a=h.get(e.target)??n.y;m.set(e.source,i+r),h.set(e.target,a+r),g.push({sx:t.x+CY,sy:i+r/2,tx:n.x,ty:a+r/2,h:r,color:t.color,label:`${e.source} → ${e.target}: ${e.value.toLocaleString()}`})}return{nodes:Array.from(p.values()),links:g}}function DY({nodeNames:e,links:t,backgroundToken:n=``,onPlotContextMenu:r}){let i=K(null),a=K(null),o=K(null),s=K(null),c=K({nodes:[],links:[]}),l=K(null),u=K(0),d=K(r);G(()=>{d.current=r},[r]);let f=K({nodeNames:e,links:t});G(()=>{f.current={nodeNames:e,links:t}},[e,t]);function p(){if(s.current)return s.current;let e=o.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return s.current=n,n}function m(){let e=o.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||300)}}function h(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function g(){let e=i.current;if(!e)return;let{w:t,h:n}=m(),r=h(e,t,n);if(!r)return;let{bg:a,muted:o}=p(),{nodeNames:s,links:u}=f.current;if(r.fillStyle=a,r.fillRect(0,0,t,n),s.length===0||u.length===0){r.fillStyle=o,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`No data — set source/target/value columns`,SY.left+8,SY.top+8);return}let d=EY(s,u,t,n);c.current=d;for(let e=0;e<d.links.length;e++){let t=d.links[e],n=l.current===e,i=(t.tx-t.sx)/2;r.beginPath(),r.moveTo(t.sx,t.sy-t.h/2),r.bezierCurveTo(t.sx+i,t.sy-t.h/2,t.tx-i,t.ty-t.h/2,t.tx,t.ty-t.h/2),r.lineTo(t.tx,t.ty+t.h/2),r.bezierCurveTo(t.tx-i,t.ty+t.h/2,t.sx+i,t.sy+t.h/2,t.sx,t.sy+t.h/2),r.closePath(),r.fillStyle=t.color,r.globalAlpha=n?.55:.3,r.fill()}r.globalAlpha=1;for(let e of d.nodes)r.fillStyle=e.color,r.globalAlpha=.9,r.fillRect(e.x,e.y,CY,e.h),r.globalAlpha=1,r.fillStyle=o,r.font=`9px ${Q.mono}`,r.textBaseline=`middle`,e.x>t/2?(r.textAlign=`right`,r.fillText(e.name,e.x-3,e.y+e.h/2)):(r.textAlign=`left`,r.fillText(e.name,e.x+CY+3,e.y+e.h/2));r.globalAlpha=1}function _(){let e=a.current;if(!e)return;let{w:t,h:n}=m(),r=h(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=l.current;if(i===null)return;let o=c.current;if(i<0||i>=o.links.length)return;let s=o.links[i],u=s.label;r.font=`11px ${Q.mono}`;let d=r.measureText(u).width,f=Math.max(4,Math.min(t-d-8,(s.sx+s.tx)/2-d/2)),p=Math.max(4,(s.sy+s.ty)/2-10);r.fillStyle=`rgba(0,0,0,0.8)`,r.fillRect(f-3,p-3,d+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(u,f,p)}let v=K(g);v.current=g;let y=K(null);y.current??=DH(()=>v.current(),()=>o.current);let b=()=>y.current.schedule(),x=()=>{xH(u.current),u.current=bH(_)};return W(()=>{y.current.now()}),W(()=>()=>y.current?.cancel(),[]),W(()=>{s.current=null,b()},[n]),G(()=>{let e=o.current;if(!e)return;let t=new EH(()=>{s.current=null,b(),x()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=a.current;if(!e)return;let t=e=>{e.preventDefault(),d.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),r=t.clientX-n.left,i=t.clientY-n.top,a=c.current,o=null;for(let e=0;e<a.links.length;e++){let t=a.links[e];if(r>=t.sx&&r<=t.tx&&Math.abs(i-(t.sy+t.ty)/2)<t.h/2+6){o=e;break}}l.current=o,x()},r=()=>{l.current=null,x()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),_t(`div`,{ref:o,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:i,className:`chart-canvas`,role:`img`,"aria-label":`Sankey diagram`}),q(`canvas`,{ref:a,className:`chart-canvas chart-overlay`})]})}var OY={top:24,right:24,bottom:52,left:52};function kY({bins:e,color:t=`#38bdf8`,backgroundToken:n=``,onPlotContextMenu:r}){let i=K(null),a=K(null),o=K(null),s=K(null),c=K(null),l=K(0),u=K(r);G(()=>{u.current=r},[r]);let d=K({bins:e,color:t});G(()=>{d.current={bins:e,color:t}},[e,t]);function f(){if(s.current)return s.current;let e=o.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return s.current=n,n}function p(){let e=o.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||300)}}function m(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function h(){let e=i.current;if(!e)return;let{w:t,h:n}=p(),r=m(e,t,n);if(!r)return;let{bg:a,muted:o,grid:s}=f(),{bins:l,color:u}=d.current;if(r.fillStyle=a,r.fillRect(0,0,t,n),l.length===0){r.fillStyle=o,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`No data`,OY.left+8,OY.top+8);return}let{top:h,right:g,bottom:_,left:v}=OY,y=t-v-g,b=n-h-_,x=e=>v+e*y,S=e=>h+(1-e)*b;for(let e=0;e<=5;e++){let t=e/5;r.strokeStyle=s,r.lineWidth=1,r.beginPath(),r.moveTo(v,S(t)),r.lineTo(v+y,S(t)),r.stroke(),r.beginPath(),r.moveTo(x(t),h),r.lineTo(x(t),h+b),r.stroke(),r.fillStyle=o,r.font=`9px ${Q.mono}`,r.textAlign=`right`,r.textBaseline=`middle`,r.fillText(t.toFixed(2),v-4,S(t)),r.textAlign=`center`,r.textBaseline=`top`,r.fillText(t.toFixed(2),x(t),h+b+4)}r.strokeStyle=o,r.lineWidth=1.5,r.setLineDash([6,4]),r.beginPath(),r.moveTo(x(0),S(0)),r.lineTo(x(1),S(1)),r.stroke(),r.setLineDash([]);let C=Math.max(1,...l.map(e=>e.count)),w=b*.15;for(let e of l){let t=Math.max(1,y/l.length*.7),n=x(e.center)-t/2,i=e.count/C*w;r.fillStyle=u,r.globalAlpha=.3,r.fillRect(n,h+b-i,t,i)}r.globalAlpha=1,r.beginPath();for(let e=0;e<l.length;e++){let t=x(l[e].center),n=S(l[e].actual);e===0?r.moveTo(t,n):r.lineTo(t,n)}r.strokeStyle=u,r.lineWidth=1,r.stroke();for(let e=0;e<l.length;e++){let t=c.current===e;r.beginPath(),r.arc(x(l[e].center),S(l[e].actual),t?6:4,0,Math.PI*2),r.fillStyle=u,r.globalAlpha=t?1:.85,r.fill()}r.globalAlpha=1,r.fillStyle=o,r.font=`10px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`bottom`,r.fillText(`Predicted probability`,v+y/2,n-4),r.save(),r.translate(12,h+b/2),r.rotate(-Math.PI/2),r.textAlign=`center`,r.textBaseline=`middle`,r.fillText(`Actual rate`,0,0),r.restore()}function g(){let e=a.current;if(!e)return;let{w:t,h:n}=p(),r=m(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=c.current;if(i===null)return;let{bins:o}=d.current;if(i<0||i>=o.length)return;let s=o[i],{top:l,left:u}=OY,f=t-u-OY.right,h=n-l-OY.bottom,g=u+s.center*f,_=l+(1-s.actual)*h,v=`pred=${s.center.toFixed(2)} actual=${s.actual.toFixed(3)} n=${s.count}`;r.font=`11px ${Q.mono}`;let y=r.measureText(v).width,b=Math.max(4,Math.min(t-y-8,g-y/2)),x=_-28<l?_+12:_-24;r.fillStyle=`rgba(0,0,0,0.8)`,r.fillRect(b-3,x-3,y+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(v,b,x)}let _=K(h);_.current=h;let v=K(null);v.current??=DH(()=>_.current(),()=>o.current);let y=()=>v.current.schedule(),b=()=>{xH(l.current),l.current=bH(g)};return W(()=>{v.current.now()}),W(()=>()=>v.current?.cancel(),[]),W(()=>{s.current=null,y()},[n]),G(()=>{let e=o.current;if(!e)return;let t=new EH(()=>{s.current=null,y(),b()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=a.current;if(!e)return;let t=e=>{e.preventDefault(),u.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),{bins:r}=d.current,{w:i}=p(),a=t.clientX-n.left,o=i-OY.left-OY.right,s=-1,l=20;for(let e=0;e<r.length;e++){let t=OY.left+r[e].center*o,n=Math.abs(a-t);n<l&&(l=n,s=e)}c.current=s>=0?s:null,b()},r=()=>{c.current=null,b()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),_t(`div`,{ref:o,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:i,className:`chart-canvas`,role:`img`,"aria-label":`Calibration curve`}),q(`canvas`,{ref:a,className:`chart-canvas chart-overlay`})]})}var AY={top:24,right:24,bottom:48,left:52};function jY({points:e,color:t=`#a78bfa`,backgroundToken:n=``,onPlotContextMenu:r}){let i=nU(),a=K(null),o=K(null),s=K(null),c=K(null),l=K(null),u=K(0),d=K(r);G(()=>{d.current=r},[r]);let f=K({points:e,color:t});G(()=>{f.current={points:e,color:t}},[e,t]);function p(){if(c.current)return c.current;let e=s.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return c.current=n,n}function m(){let e=s.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||300)}}function h(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function g(){let{points:e}=f.current,t=1/0,n=-1/0,r=1/0,i=-1/0;if(e.length>0&&(t=e.theoretical[0],n=e.theoretical[e.length-1],r=e.sample[0],i=e.sample[e.length-1]),!Number.isFinite(t))return{xLo:-3,xHi:3,yLo:-3,yHi:3};let a=(n-t)*.05||.5,o=(i-r)*.05||.5;return{xLo:t-a,xHi:n+a,yLo:r-o,yHi:i+o}}function _(){let e=a.current;if(!e)return;let{w:t,h:n}=m(),r=h(e,t,n);if(!r)return;let{bg:o,muted:s,grid:c}=p(),{points:u,color:d}=f.current;if(r.fillStyle=o,r.fillRect(0,0,t,n),u.length===0){r.fillStyle=s,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`No data`,AY.left+8,AY.top+8);return}let{xLo:_,xHi:v,yLo:y,yHi:b}=g(),{top:x,right:S,bottom:C,left:w}=AY,T=t-w-S,E=n-x-C,D=e=>w+(e-_)/(v-_)*T,O=e=>x+(1-(e-y)/(b-y))*E;i({left:w,top:x,width:T,height:E,x:{v0:_,v1:v}}),r.strokeStyle=c,r.lineWidth=1;for(let e=0;e<=5;e++){let t=_+e/5*(v-_),n=D(t);r.beginPath(),r.moveTo(n,x),r.lineTo(n,x+E),r.stroke(),r.fillStyle=s,r.font=`9px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`top`,r.fillText(jz(t,(v-_)/5),n,x+E+4);let i=y+e/5*(b-y),a=O(i);r.beginPath(),r.moveTo(w,a),r.lineTo(w+T,a),r.stroke(),r.fillStyle=s,r.textAlign=`right`,r.textBaseline=`middle`,r.fillText(jz(i,(b-y)/5),w-4,a)}let k=Math.max(_,y),A=Math.min(v,b);k<A&&(r.strokeStyle=s,r.lineWidth=1.5,r.setLineDash([6,4]),r.beginPath(),r.moveTo(D(k),O(k)),r.lineTo(D(A),O(A)),r.stroke(),r.setLineDash([])),r.fillStyle=d,r.globalAlpha=.75;let j=NaN,M=NaN;for(let e=0;e<u.length;e++){let t=Math.round(D(u.theoretical[e])),n=Math.round(O(u.sample[e]));t===j&&n===M||(j=t,M=n,r.beginPath(),r.arc(t,n,3,0,Math.PI*2),r.fill())}let N=l.current;N!==null&&N<u.length&&(r.globalAlpha=1,r.beginPath(),r.arc(D(u.theoretical[N]),O(u.sample[N]),5,0,Math.PI*2),r.fill()),r.globalAlpha=1,r.fillStyle=s,r.font=`10px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`bottom`,r.fillText(`Theoretical quantiles`,w+T/2,n-4),r.save(),r.translate(12,x+E/2),r.rotate(-Math.PI/2),r.textAlign=`center`,r.textBaseline=`middle`,r.fillText(`Sample quantiles`,0,0),r.restore()}function v(){let e=o.current;if(!e)return;let{w:t,h:n}=m(),r=h(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=l.current;if(i===null)return;let{points:a}=f.current;if(i<0||i>=a.length)return;let s={theoretical:a.theoretical[i],sample:a.sample[i]},{xLo:c,xHi:u,yLo:d,yHi:p}=g(),{top:_,left:v}=AY,y=t-v-AY.right,b=n-_-AY.bottom,x=v+(s.theoretical-c)/(u-c)*y,S=_+(1-(s.sample-d)/(p-d))*b;r.beginPath(),r.arc(x,S,6,0,Math.PI*2),r.strokeStyle=`rgba(255,255,255,0.9)`,r.lineWidth=2,r.stroke();let C=`(${Mz(s.theoretical)}, ${Mz(s.sample)})`;r.font=`11px ${Q.mono}`;let w=r.measureText(C).width,T=Math.max(4,Math.min(t-w-8,x+10)),E=S-20<_?S+10:S-20;r.fillStyle=`rgba(0,0,0,0.8)`,r.fillRect(T-3,E-3,w+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(C,T,E)}let y=K(_);y.current=_;let b=K(null);b.current??=DH(()=>y.current(),()=>s.current);let x=()=>b.current.schedule(),S=()=>{xH(u.current),u.current=bH(v)};return W(()=>{b.current.now()}),W(()=>()=>b.current?.cancel(),[]),W(()=>{c.current=null,x()},[n]),G(()=>{let e=s.current;if(!e)return;let t=new EH(()=>{c.current=null,x(),S()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=o.current;if(!e)return;let t=e=>{e.preventDefault(),d.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),{points:r}=f.current,{w:i}=m(),{xLo:a,xHi:o,yLo:s,yHi:c}=g(),{top:u,left:d}=AY,p=i-d-AY.right,h=n.height-u-AY.bottom,_=t.clientX-n.left,v=t.clientY-n.top,y=e=>a+(e-d)/p*(o-a),b=e=>{let t=0,n=r.length;for(;t<n;){let i=t+n>>>1;r.theoretical[i]<e?t=i+1:n=i}return t},x=b(y(_-10)),C=Math.min(r.length,b(y(_+10))+1),w=-1,T=10**2;for(let e=x;e<C;e++){let t=d+(r.theoretical[e]-a)/(o-a)*p,n=u+(1-(r.sample[e]-s)/(c-s))*h,i=(_-t)**2+(v-n)**2;i<T&&(T=i,w=e)}l.current=w>=0?w:null,S()},r=()=>{l.current=null,S()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),_t(`div`,{ref:s,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:a,className:`chart-canvas`,role:`img`,"aria-label":`Q-Q plot`}),q(`canvas`,{ref:o,className:`chart-canvas chart-overlay`})]})}var MY={top:8,right:16,bottom:40,left:120},NY=22,PY=3,FY=[`#38bdf8`,`#4ade80`,`#fb7185`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`,`#facc15`,`#60a5fa`];function IY({tasks:e,backgroundToken:t=``,onPlotContextMenu:n}){let r=nU(),i=K(null),a=K(null),o=K(null),s=K(null),c=K(null),l=K(0),u=K(n);G(()=>{u.current=n},[n]);let d=K({tasks:e});G(()=>{d.current={tasks:e}},[e]);function f(){if(s.current)return s.current;let e=o.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return s.current=n,n}function p(){let e=o.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||300)}}function m(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function h(){let e=i.current;if(!e)return;let{w:t,h:n}=p(),a=m(e,t,n);if(!a)return;let{bg:o,muted:s,grid:l}=f(),{tasks:u}=d.current;if(a.fillStyle=o,a.fillRect(0,0,t,n),u.length===0){a.fillStyle=s,a.font=`13px ${Q.sans}`,a.textAlign=`left`,a.textBaseline=`top`,a.fillText(`No data`,MY.left+8,MY.top+8);return}let h=1/0,g=-1/0;for(let e of u)e.start<h&&(h=e.start),e.end>g&&(g=e.end);Number.isFinite(h)||(h=0,g=1);let _=(g-h)*.02||1;h-=_,g+=_;let{top:v,right:y,bottom:b,left:x}=MY,S=t-x-y,C=e=>x+(e-h)/(g-h)*S;r({left:x,top:v,width:S,height:n-v-b,x:{v0:h,v1:g}});let w=new Map;for(let e of u){let t=e.group??e.label;w.has(t)||w.set(t,w.size)}let T=Math.min(8,Math.floor(S/60));a.strokeStyle=l,a.lineWidth=1;for(let e=0;e<=T;e++){let t=h+e/T*(g-h),n=C(t),r=u.length*(NY+PY)+v;a.beginPath(),a.moveTo(n,v),a.lineTo(n,r),a.stroke(),a.fillStyle=s,a.font=`9px ${Q.mono}`,a.textAlign=`center`,a.textBaseline=`top`,a.fillText(jz(t,(g-h)/T),n,r+4)}for(let e=0;e<u.length;e++){let t=u[e],n=v+e*(NY+PY),r=FY[(w.get(t.group??t.label)??0)%FY.length],i=c.current===e,o=C(t.start),l=C(t.end),d=Math.max(2,l-o);a.fillStyle=r,a.globalAlpha=i?.95:.75,a.fillRect(o,n,d,NY-PY),a.globalAlpha=1,a.fillStyle=s,a.font=`9px ${Q.mono}`,a.textAlign=`right`,a.textBaseline=`middle`;let f=t.label.length>16?t.label.slice(0,15)+`…`:t.label;a.fillText(f,x-4,n+(NY-PY)/2)}a.globalAlpha=1}function g(){let e=a.current;if(!e)return;let{w:t,h:n}=p(),r=m(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=c.current;if(i===null)return;let{tasks:o}=d.current;if(i<0||i>=o.length)return;let s=o[i],l=s.end-s.start,u=`${s.label}: ${Mz(s.start)} → ${Mz(s.end)} (${Mz(l)})`;r.font=`11px ${Q.mono}`;let f=r.measureText(u).width,h=1/0,g=-1/0;for(let e of o)e.start<h&&(h=e.start),e.end>g&&(g=e.end);let _=(g-h)*.02||1;h-=_,g+=_;let v=t-MY.left-MY.right,y=e=>MY.left+(e-h)/(g-h)*v,b=MY.top+i*(NY+PY),x=(y(s.start)+y(s.end))/2,S=Math.max(4,Math.min(t-f-8,x-f/2)),C=b-22<MY.top?b+NY+4:b-20;r.fillStyle=`rgba(0,0,0,0.8)`,r.fillRect(S-3,C-3,f+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(u,S,C)}let _=K(h);_.current=h;let v=K(null);v.current??=DH(()=>_.current(),()=>o.current);let y=()=>v.current.schedule(),b=()=>{xH(l.current),l.current=bH(g)};return W(()=>{v.current.now()}),W(()=>()=>v.current?.cancel(),[]),W(()=>{s.current=null,y()},[t]),G(()=>{let e=o.current;if(!e)return;let t=new EH(()=>{s.current=null,y(),b()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=a.current;if(!e)return;let t=e=>{e.preventDefault(),u.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),{tasks:r}=d.current,i=t.clientY-n.top,a=Math.floor((i-MY.top)/(NY+PY));c.current=a>=0&&a<r.length?a:null,b()},r=()=>{c.current=null,b()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),_t(`div`,{ref:o,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:i,className:`chart-canvas`,role:`img`,"aria-label":`Gantt chart`}),q(`canvas`,{ref:a,className:`chart-canvas chart-overlay`})]})}var LY=e=>[...e].filter(e=>Number.isFinite(e.at)).sort((e,t)=>e.at-t.at),RY=e=>{let t=/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})/i.exec(e);return t?[parseInt(t[1],16),parseInt(t[2],16),parseInt(t[3],16)]:[128,128,128]},zY=e=>`#${e.map(e=>Math.round(e).toString(16).padStart(2,`0`)).join(``)}`;function BY(e,t,n,r){let i=t?LY(t):[];if(!e||e===`solid`||i.length===0||!Number.isFinite(r))return n;if(e===`zones`){let e=i[0].color;for(let t of i)r>=t.at&&(e=t.color);return e}if(r<=i[0].at)return i[0].color;if(r>=i[i.length-1].at)return i[i.length-1].color;let a=0;for(;i[a+1].at<r;)a++;let o=i[a],s=i[a+1],c=(r-o.at)/(s.at-o.at||1),l=RY(o.color),u=RY(s.color);return zY([l[0]+(u[0]-l[0])*c,l[1]+(u[1]-l[1])*c,l[2]+(u[2]-l[2])*c])}function VY(e,t,n,r,i,a=96){let o=i-r||1,s=t?LY(t):[];if(!e||e===`solid`||s.length===0)return[{f0:0,f1:1,color:n}];if(e===`zones`){let e=[0,...s.slice(1).map(e=>(e.at-r)/o).filter(e=>e>0&&e<1),1];return e.slice(0,-1).map((t,i)=>({f0:t,f1:e[i+1],color:BY(`zones`,s,n,r+(t+e[i+1])/2*o)}))}return Array.from({length:a},(e,t)=>({f0:t/a,f1:(t+1)/a,color:BY(`gradient`,s,n,r+(t+.5)/a*o)}))}function HY(e,t,n){let r=e=>+(t+e*(n-t)).toPrecision(6),i=`#22c55e`,a=`#ef4444`;if(e===`traffic`)return{mode:`zones`,stops:[{at:r(0),color:i},{at:r(.7),color:`#f5a524`},{at:r(.9),color:a}]};let o=[{at:r(0),color:i},{at:r(.5),color:`#eab308`},{at:r(1),color:a}];return{mode:`gradient`,stops:e===`green-red`?o:o.map((e,t)=>({...e,color:o[o.length-1-t].color}))}}function UY(e,t,n){let r=t?LY(t):[];if(!e||e===`solid`||r.length===0)return n;let i=r[0].at,a=r[r.length-1].at,o=e=>`${((e-i)/(a-i||1)*100).toFixed(1)}%`;if(e===`gradient`)return`linear-gradient(90deg, ${r.map(e=>`${e.color} ${o(e.at)}`).join(`, `)})`;let s=100/r.length;return`linear-gradient(90deg, ${r.map((e,t)=>`${e.color} ${(t*s).toFixed(1)}% ${((t+1)*s).toFixed(1)}%`).join(`, `)})`}var WY=.75*Math.PI,GY=1.5*Math.PI;function KY({gauges:e,live:t,backgroundToken:n=``,onPlotContextMenu:r}){let i=K(null),a=K(null),o=K(null),s=K(r);G(()=>{s.current=r},[r]);let c=K({gauges:e,live:t});G(()=>{c.current={gauges:e,live:t}},[e,t]);let l=K(RH()),u=K(0);function d(){if(o.current)return o.current;let e=a.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`,ink:`#e4e4e7`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`,ink:t.getPropertyValue(`--chart-fg`).trim()||`#e4e4e7`};return o.current=n,n}function f(){let e=i.current,t=a.current;if(!e||!t)return;let n=Math.max(1,t.clientWidth),r=Math.max(1,t.clientHeight),o=Math.min(2,window.devicePixelRatio||1),s=Math.floor(n*o),f=Math.floor(r*o);(e.width!==s||e.height!==f)&&(e.width=s,e.height=f),e.style.width=`${n}px`,e.style.height=`${r}px`;let p=e.getContext(`2d`);if(!p)return;p.setTransform(o,0,0,o,0,0);let h=d(),{gauges:g,live:_}=c.current,v=g;if(_){let e=performance.now(),t=KH(l.current,_.latestT(),e-u.current);u.current=e,v=g.map(e=>{if((e.stat??`last`)!==`last`)return e;let n=_.valueAt(e.name,t);return Number.isFinite(n)?{...e,value:n}:e}),m.current.schedule()}if(p.fillStyle=h.bg,p.fillRect(0,0,n,r),v.length===0){p.fillStyle=h.muted,p.font=`13px ${Q.sans}`,p.textAlign=`left`,p.textBaseline=`top`,p.fillText(`No data`,16,16);return}let{cols:y,rows:b}=qY(v.length,n,r,v.some(e=>e.style===`arc`)?1.15:3.2),x=n/y,S=r/b;v.forEach((e,t)=>{let n=t%y*x,r=Math.floor(t/y)*S;e.style===`arc`?rX(p,e,n,r,x,S,e.color,e.alarm??null,h):iX(p,e,n,r,x,S,e.color,e.alarm??null,h)})}let p=K(f);p.current=f;let m=K(null);return m.current??=DH(()=>p.current(),()=>a.current),W(()=>{m.current.now()}),W(()=>()=>m.current?.cancel(),[]),W(()=>{o.current=null,m.current.schedule()},[n]),G(()=>{let e=a.current;if(!e)return;let t=new EH(()=>{o.current=null,m.current.schedule()});return t.observe(e),()=>t.disconnect()},[]),q(`div`,{ref:a,style:{position:`relative`,width:`100%`,height:`100%`},children:q(`canvas`,{ref:i,className:`chart-canvas`,role:`img`,"aria-label":`Gauges: ${e.map(e=>`${e.name} ${Number.isFinite(e.value)?JY(e.value,e.max-e.min):`no value`}${e.unit?` ${e.unit}`:``}`).join(`, `)}`,onContextMenu:e=>{e.preventDefault(),s.current?.({clientX:e.clientX,clientY:e.clientY})}})})}function qY(e,t,n,r){let i={cols:1,rows:e,size:-1};for(let a=1;a<=e;a++){let o=Math.ceil(e/a),s=t/a,c=n/o,l=Math.min(s,c*r);l>i.size&&(i={cols:a,rows:o,size:l})}return{cols:i.cols,rows:i.rows}}var JY=(e,t)=>jz(e,wz(Math.abs(t),100)),YY=(e,t)=>Math.max(0,Math.min(1,(t-e.min)/(e.max-e.min||1))),XY=(e,t)=>{let n=e.fromZero?YY(e,0):0;return[Math.min(n,t),Math.max(n,t)]},ZY=(e,t)=>!!t&&(t.linked?t.linked===`active`:Number.isFinite(e.value)&&e.value>=t.value),QY=e=>(e.colorMode===`gradient`||e.colorMode===`zones`)&&!!e.stops?.length,$Y=(e,t)=>ZY(e,t)?t.color:BY(e.colorMode,e.stops,e.color,e.value);function eX(e,t,n){for(let r of VY(t.colorMode,t.stops,t.color,t.min,t.max))e.addColorStop(n(r.f0),r.color),e.addColorStop(n(r.f1),r.color);return e}function tX(e,t,n){if(e.measureText(t).width<=n)return t;let r=t;for(;r.length>1&&e.measureText(`${r}…`).width>n;)r=r.slice(0,-1);return n>0?`${r}…`:``}var nX=Math.SQRT1_2;function rX(e,t,n,r,i,a,o,s,c){let l=Math.max(6,Math.min(i,a)*.06),u=t.max-t.min,d=JY(t.min,u),f=JY(t.max,u),p=e=>Math.max(9,Math.min(22,e*.1)),m=e=>Math.max(4,e*.13),h=Math.max(8,Math.min((i-2*l)/2,(a-2*l)/1.9)),g=0;for(let t=0;t<2;t++){e.font=`${p(h)}px ${Q.mono}`,g=Math.max(e.measureText(d).width,e.measureText(f).width);let t=m(h),n=Math.max(h+t/2,nX*h+g/2),r=h+t/2+nX*h+t/2+6+p(h)*1.2;h=Math.max(8,Math.min(h*(i-2*l)/(2*n),h*(a-2*l)/r))}let _=m(h),v=p(h),y=h+_/2+nX*h+_/2+6+v*1.2,b=n+i/2,x=r+l+h+_/2+Math.max(0,(a-2*l-y)/2),S=e=>WY+e*GY;e.lineCap=`round`,e.lineWidth=_,e.strokeStyle=c.grid,e.beginPath(),e.arc(b,x,h,WY,WY+GY),e.stroke(),s&&s.value<t.max&&(e.globalAlpha=.3,e.strokeStyle=s.color,e.lineCap=`butt`,e.beginPath(),e.arc(b,x,h,S(YY(t,s.value)),WY+GY),e.stroke(),e.globalAlpha=1,e.lineCap=`round`);let[C,w]=XY(t,Number.isFinite(t.value)?YY(t,t.value):0),T=()=>{e.lineCap=t.fromZero?`butt`:`round`,e.beginPath(),e.arc(b,x,h,S(C),Math.max(S(C)+1e-4,S(w))),e.stroke(),e.lineCap=`round`};if(QY(t)){let n=GY/(2*Math.PI),r=eX(e.createConicGradient(WY,b,x),t,e=>e*n);r.addColorStop(1,BY(t.colorMode,t.stops,t.color,t.min)),e.strokeStyle=r,e.globalAlpha=.24,e.beginPath(),e.arc(b,x,h,WY,WY+GY),e.stroke(),e.globalAlpha=1,Number.isFinite(t.value)&&!ZY(t,s)&&T()}if(Number.isFinite(t.value)&&(!QY(t)||ZY(t,s))&&(e.strokeStyle=ZY(t,s)?s.color:o,T()),t.fromZero&&t.min<0&&t.max>0){let n=S(YY(t,0));e.strokeStyle=c.muted,e.lineWidth=1.5,e.lineCap=`butt`,e.beginPath(),e.moveTo(b+Math.cos(n)*(h-_*.75),x+Math.sin(n)*(h-_*.75)),e.lineTo(b+Math.cos(n)*(h+_*.75),x+Math.sin(n)*(h+_*.75)),e.stroke(),e.lineWidth=_,e.lineCap=`round`}if(s&&s.value>=t.min&&s.value<=t.max){let n=S(YY(t,s.value));e.strokeStyle=s.color,e.lineWidth=Math.max(1.5,s.width),e.lineCap=`butt`,e.beginPath(),e.moveTo(b+Math.cos(n)*(h-_*.9),x+Math.sin(n)*(h-_*.9)),e.lineTo(b+Math.cos(n)*(h+_*.9),x+Math.sin(n)*(h+_*.9)),e.stroke();let r=h+_*.9+10*.7;s.linked&&oU(e,b+Math.cos(n)*r-10/2,x+Math.sin(n)*r-10/2,s.color)}let E=Number.isFinite(t.value)?JY(t.value,u):`—`,D=2*(h-_)*.82,O=Math.max(11,h*.42);e.font=`650 ${O}px ${Q.sans}`;let k=e.measureText(E).width;k>D&&(O=Math.max(9,O*D/k),e.font=`650 ${O}px ${Q.sans}`),e.textAlign=`center`,e.textBaseline=`alphabetic`,e.fillStyle=ZY(t,s)||QY(t)?$Y(t,s):c.ink,e.fillText(E,b,x+O*.32),e.fillStyle=c.muted,t.unit&&(e.font=`600 ${Math.max(9,h*.13)}px ${Q.sans}`,e.fillText(tX(e,t.unit,D),b,x+O*.32+Math.max(11,h*.19)));let A=x+nX*h+_/2+6,j=nX*h;e.textBaseline=`top`,e.font=`${v}px ${Q.mono}`,e.fillText(d,b-j,A),e.fillText(f,b+j,A);let M=2*j-g-16,N=Math.max(10,Math.min(26,h*.13));e.font=`600 ${N}px ${Q.sans}`;let P=e.measureText(t.name).width;P>M&&N>9&&(N=Math.max(9,N*M/P),e.font=`600 ${N}px ${Q.sans}`),e.fillText(tX(e,t.name,M),b,A+(v-N)/2)}function iX(e,t,n,r,i,a,o,s,c){let l=Math.max(14,i*.06),u=n+l,d=n+i-l,f=d-u,p=Math.max(6,Math.min(16,a*.14)),m=Math.max(12,Math.min(34,a*.28)),h=r+a/2+m*.35,g=e=>u+YY(t,e)*f;e.textBaseline=`alphabetic`,e.fillStyle=c.muted,e.font=`600 ${Math.max(10,m*.42)}px ${Q.sans}`,e.textAlign=`left`,e.fillText(tX(e,t.name,f),u,h-p/2-m-4),e.textAlign=`right`,e.fillStyle=ZY(t,s)?s.color:c.ink,e.font=`650 ${m}px ${Q.sans}`;let _=t.unit?(e.font=`600 ${Math.max(9,m*.4)}px ${Q.sans}`,e.measureText(` ${t.unit}`).width):0;t.unit&&(e.fillStyle=c.muted,e.fillText(` ${t.unit}`,d,h-p/2-8)),e.fillStyle=ZY(t,s)||QY(t)?$Y(t,s):c.ink,e.font=`650 ${m}px ${Q.sans}`,e.fillText(Number.isFinite(t.value)?JY(t.value,t.max-t.min):`—`,d-_,h-p/2-8),e.lineCap=`round`,e.lineWidth=p,e.strokeStyle=c.grid,e.beginPath(),e.moveTo(u,h),e.lineTo(d,h),e.stroke(),s&&s.value<t.max&&(e.globalAlpha=.3,e.strokeStyle=s.color,e.lineCap=`butt`,e.beginPath(),e.moveTo(g(s.value),h),e.lineTo(d,h),e.stroke(),e.globalAlpha=1,e.lineCap=`round`);let v=Number.isFinite(t.value)?YY(t,t.value):0,y=e=>u+e*f,[b,x]=XY(t,v),S=()=>{e.lineCap=t.fromZero?`butt`:`round`,e.beginPath(),e.moveTo(y(b),h),e.lineTo(Math.max(y(b)+.5,y(x)),h),e.stroke(),e.lineCap=`round`};QY(t)&&(e.strokeStyle=eX(e.createLinearGradient(u,0,d,0),t,e=>e),e.globalAlpha=.24,e.beginPath(),e.moveTo(u,h),e.lineTo(d,h),e.stroke(),e.globalAlpha=1,Number.isFinite(t.value)&&!ZY(t,s)&&S()),Number.isFinite(t.value)&&(!QY(t)||ZY(t,s))&&(e.strokeStyle=ZY(t,s)?s.color:o,S()),t.fromZero&&t.min<0&&t.max>0&&(e.strokeStyle=c.muted,e.lineWidth=1.5,e.lineCap=`butt`,e.beginPath(),e.moveTo(g(0),h-p*.75),e.lineTo(g(0),h+p*.75),e.stroke(),e.lineWidth=p,e.lineCap=`round`),s&&s.value>=t.min&&s.value<=t.max&&(e.strokeStyle=s.color,e.lineWidth=Math.max(1.5,s.width),e.lineCap=`butt`,e.beginPath(),e.moveTo(g(s.value),h-p),e.lineTo(g(s.value),h+p),e.stroke(),s.linked&&oU(e,g(s.value)-10/2,h-p-10-2,s.color)),e.fillStyle=c.muted,e.font=`${Math.max(9,m*.34)}px ${Q.mono}`,e.textBaseline=`top`,e.textAlign=`left`,e.fillText(JY(t.min,t.max-t.min),u,h+p/2+4),e.textAlign=`right`,e.fillText(JY(t.max,t.max-t.min),d,h+p/2+4)}var aX=720;function oX(e,t){return t?e<aX:e<640}function sX(e){return e<=1?{cols:1,rows:1}:e===2?{cols:2,rows:1}:e<=4?{cols:2,rows:2}:{cols:3,rows:3}}function cX(e,t){return e.flatMap(e=>{let n=e.info?.meta;if(!n?.recordingId)return[];let r=n.wallOrigin?Number(n.wallOrigin):NaN,i=n.wallQuality;return[{recordingId:n.recordingId,wallOrigin:Number.isFinite(r)?r:null,wallQuality:i===`exact`||i===`approx`?i:null,xOffset:t[e.id]??0}]})}var lX={get:()=>null,subscribe:()=>()=>{}};function uX(e){let[t,n]=ft(null);return G(()=>{let t=e.current;if(!t)return;let r=e=>n(t=>oX(e,t??!1));if(r(t.clientWidth),typeof ResizeObserver>`u`)return;let i=new ResizeObserver(e=>{for(let t of e)r(t.contentRect.width)});return i.observe(t),()=>i.disconnect()},[e]),t}function dX(e){let t=Wn(e.settings),[n,r]=ft(null),[i,a]=ft(null),o=K(null);W(()=>{i&&o.current?.querySelector(`[data-camera="${CSS.escape(i)}"]`)?.focus()},[i]);let s=e.recordings??[],c=e=>s.findIndex(t=>t.recordingId===e.recordingId),l=(e.video??[]).filter(e=>e.kind===`recorded`&&c(e)>=0).sort((e,t)=>c(e)-c(t)),u=e.onContextMenu?t=>{t.preventDefault(),e.onContextMenu({clientX:t.clientX,clientY:t.clientY})}:void 0;if(!t.length){let t=[...new Set([...e.live.filter(e=>e.kind===`camera`&&!e.lowOf),...l].map(t=>Vn(t,e.live)))].sort();return q(pX,{onContextMenu:u,title:`Choose a camera in this panel's settings`,detail:t.length?t.join(`, `):void 0})}let d={panel:e,recorded:l,recIndex:c};if(t.length===1)return q(fX,{...d,id:t[0],onMenu:u});let f=n&&t.includes(n)?n:null,p=f?[f]:t,{cols:m,rows:h}=sX(p.length),g=()=>{a(f),r(null)};return _t(`div`,{ref:o,className:`kymo-camera-wall`,style:{gridTemplateColumns:`repeat(${m}, minmax(0, 1fr))`,gridTemplateRows:`repeat(${h}, minmax(0, 1fr))`},onContextMenu:u,onKeyDown:e=>{e.key===`Escape`&&f&&(e.stopPropagation(),g())},children:[p.map(e=>q(fX,{...d,id:e,multi:!0,wall:!f,onPick:f?void 0:()=>{a(null),r(e)}},e)),f?_t(`button`,{type:`button`,className:`kymo-camera__all`,onClick:g,autoFocus:!0,children:[_t(`svg`,{viewBox:`0 0 16 16`,"aria-hidden":`true`,children:[q(`rect`,{x:`2`,y:`2`,width:`5`,height:`5`,rx:`1`}),q(`rect`,{x:`9`,y:`2`,width:`5`,height:`5`,rx:`1`}),q(`rect`,{x:`2`,y:`9`,width:`5`,height:`5`,rx:`1`}),q(`rect`,{x:`9`,y:`9`,width:`5`,height:`5`,rx:`1`})]}),`All cameras`]}):null]})}function fX({panel:e,recorded:t,recIndex:n,id:r,multi:i,wall:a,onPick:o,onMenu:s}){let c=e.recordings??[],l={onMenu:s,wall:a,onPick:o},u=t.find(e=>e.id===r);if(u)return q(mX,{...e,...l,source:u,name:i?Vn(u,e.live):u.name,rec:c[n(u)]},`rec:${u.recordingId}:${u.id}`);let d=e.live.find(e=>e.id===r&&e.kind===`camera`);if(!d?.video||d.status===`error`)return q(pX,{onContextMenu:s,title:`Camera offline`,detail:d?Vn(d,e.live):void 0});let f=e.live.find(e=>e.kind===`camera`&&e.lowOf===d.id&&e.video&&e.status!==`error`),p=f?.video?DE({...f,video:f.video}):void 0;return q(mX,{...e,...l,source:DE({...d,video:d.video}),low:p,name:i?Vn(d,e.live):d.name,conn:d},d.id)}function pX({title:e,detail:t,onContextMenu:n}){return q(`div`,{className:`kymo-camera`,onContextMenu:n,children:_t(`div`,{className:`kymo-camera__empty`,children:[_t(`svg`,{className:`kymo-camera__empty-icon`,viewBox:`0 0 24 24`,"aria-hidden":`true`,children:[q(`rect`,{x:`2.5`,y:`6`,width:`13`,height:`12`,rx:`2.5`}),q(`path`,{d:`M15.5 10.5 21.5 7v10l-6-3.5`})]}),q(`p`,{className:`kymo-camera__empty-title`,children:e}),t?q(`p`,{className:`kymo-camera__empty-detail`,children:t}):null]})})}function mX(e){let{settings:t,source:n}=e,r=e.cursor??lX,i=pt(r.subscribe,r.get),a=e=>e.kind===`data`,o=e.rec?void 0:t.syncStreamId?e.live.find(e=>e.id===t.syncStreamId&&a(e)):e.live.find(t=>t.id===e.conn.parentId&&a(t))??e.live.find(t=>a(t)&&e.selection.includes(t.id))??e.live.find(a),s=i??e.viewXRange?.[1]??null,c=null,l=null,u=o?.clock?.quality()??`none`;if(e.rec){let{wallOrigin:r,wallQuality:i,xOffset:a}=e.rec;u=i??`none`;let o=n.range()?.[0]??null;s===null?c=o:r===null?(c=o,l=`This recording has no wall clock`):e.xKey===`Time`?c=r+s-a+t.offsetMs/1e3:e.xKey===`ElapsedTime`&&i===`exact`?c=s-a+t.offsetMs/1e3:(c=o,l=`Sync needs a time X axis`)}else s!==null&&(e.xIsTime?(c=o?.clock?.toWall(s,t.offsetMs)??null,c===null&&(l=`No data stream to sync with`)):l=`Sync needs a time X axis`);let d=K(null),f=K(null),p=uX(d),m=p===null?null:e.low&&(p||e.wall)?e.low:n,h=K(t.fit),g=K(c);G(()=>{h.current=t.fit,g.current=c});let _=K(null),v=K(null),[y,b]=ft(null),x=y??m??n,[S,C]=ft(!1),[w,T]=ft(!0);W(()=>{if(!m||_.current?.source===m)return;let e=!_.current,t=null,n=!1,r=()=>t?_.current===t:e,i=t=gX(m,f.current,()=>h.current,g.current,{unsupported:()=>{r()&&C(!0)},buffered:e=>{r()&&T(e)},frame:()=>{if(_.current===t){n||(n=!0,b(m));return}_.current?.dispose(),_.current=i,v.current=null,i.show(),n=!0,b(m),T(i.buffered())}},e);if(e){_.current=i;return}return v.current=i,()=>{_.current!==i&&(i.dispose(),v.current===i&&(v.current=null))}},[m]),W(()=>()=>{_.current?.dispose(),_.current=null},[]),W(()=>{_.current?.setTarget(c),v.current?.setTarget(c)},[c]);let E=!!x.lowOf,D=x.info().latestT,O=!e.rec&&c!==null&&D!==null?c-D:null,k=e.rec?`No video at this time`:`Not buffered`;return _t(`div`,{ref:d,className:`kymo-camera${e.onPick?` is-tile`:``}`,onContextMenu:e.onMenu,...e.onPick?{role:`button`,tabIndex:0,"data-camera":n.id,"aria-label":`Show ${e.name} alone`,onClick:e.onPick,onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),e.onPick())}}:{},children:[q(`canvas`,{ref:f,className:`kymo-camera__video`,role:`img`,"aria-label":`Video from ${e.name}`}),S?q(`div`,{className:`kymo-camera__empty`,children:q(`p`,{className:`kymo-camera__empty-title`,children:`This browser can't decode this camera`})}):_t(`div`,{className:`kymo-camera__overlay`,children:[q(`span`,{className:`kymo-camera__name`,children:e.name}),e.rec?q(`span`,{className:`kymo-camera__rec`,children:`Recording`}):c===null?q(`span`,{className:`kymo-camera__live`,children:`LIVE`}):q(`span`,{className:`kymo-camera__ago`,children:O===null?``:hX(O)}),E?q(`span`,{className:`kymo-camera__badge`,title:`Low-quality copy (small panel)`,children:`LQ`}):null,c!==null&&u!==`none`?q(`span`,{className:`kymo-camera__badge${u===`exact`?` is-exact`:``}`,children:u===`exact`?`Exact`:`Approx.`}):null,l??(c!==null&&!w?k:null)?q(`span`,{className:`kymo-camera__note`,children:l??k}):null]})]})}function hX(e){let t=Math.abs(e).toFixed(1);return t===`0.0`?`0.0 s`:`${e<0?`−`:`+`}${t} s`}function gX(e,t,n,r,i,a=!0){let o=e.acquire?.(),s=!1,c=!0,l=e=>{c=e,i.buffered(e)},u=null,d=null,f=r,p=`live`,m=!0,h=!1,g=!1,_=null,v=null,y=null,b=[],x=e=>{if(s){e.close();return}p===`seek`?(_?.close(),_=e):(v?.close(),v=e,i.frame?.())},S=()=>{!d||d.state===`closed`?d=new VideoDecoder({output:x,error:()=>{}}):d.reset(),d.configure(u),m=!0},C=e=>{d?.state===`closed`&&e.key&&S(),!(d?.state!==`configured`||m&&!e.key)&&(m=!1,d.decode(new EncodedVideoChunk({type:e.key?`key`:`delta`,timestamp:Math.round(e.t*1e6),data:e.data})))},w=()=>{p=`live`,l(!0),S();for(let t of e.livePlan?.()??[])C(t)},T=async()=>{if(!h){h=!0;try{for(;!s&&p===`seek`&&g;){g=!1;let t=[];try{t=await e.seekPlan(f)}catch{}if(!(s||p!==`seek`||g)&&(l(t.length>0),t.length)){S();for(let e of t)C(e);try{await d.flush()}catch{}p===`seek`&&_&&(v?.close(),v=_,_=null,i.frame?.())}}}finally{h=!1,_?.close(),_=null}}},E=()=>{f===null?p!==`live`&&w():(p=`seek`,g=!0,T())};e.onUnit&&b.push(e.onUnit(e=>{u&&p===`live`&&C(e)})),(async()=>{if(typeof VideoDecoder>`u`){i.unsupported();return}if(e.info().codec||(e.ready?await e.ready():e.onUnit&&await new Promise(t=>{let n=e.onUnit(()=>{e.info().codec&&(n(),t())});b.push(n)})),s)return;if(!e.info().codec){l(!1);return}let t={codec:e.info().codec,optimizeForLatency:!0,hardwareAcceleration:`no-preference`},n=!1;try{n=(await VideoDecoder.isConfigSupported(t)).supported===!0}catch{}if(!s){if(!n){i.unsupported();return}u=t,f===null?w():E()}})();let D=n(),O=()=>{if(!a)return;let e=window.devicePixelRatio||1,r=Math.max(1,Math.round(t.clientWidth*e)),i=Math.max(1,Math.round(t.clientHeight*e)),o=!1;if((t.width!==r||t.height!==i)&&(t.width=r,t.height=i,o=!0),v&&(y?.close(),y=v,v=null,o=!0),n()!==D&&(D=n(),o=!0),!o||!y)return;let s=t.getContext(`2d`);if(!s)return;let c=y.displayWidth,l=y.displayHeight,u=D===`cover`?Math.max(r/c,i/l):Math.min(r/c,i/l),d=c*u,f=l*u;s.clearRect(0,0,r,i),s.drawImage(y,(r-d)/2,(i-f)/2,d,f)},k=0,A=()=>{k=bH(A),O()};return k=bH(A),{source:e,show(){a=!0},buffered:()=>c,setTarget(e){e!==f&&(f=e,u&&E())},dispose(){s=!0,xH(k),b.forEach(e=>e()),d&&d.state!==`closed`&&d.close();for(let e of[_,v,y])e?.close();_=v=y=null,o?.()}}}function _X(e,t){let n=e.filter(e=>e.x.length>=2&&vX(e.x));if(n.length<2)return null;let r=1/0,i=-1/0;for(let e of n)e.x[0]<r&&(r=e.x[0]),e.x[e.x.length-1]>i&&(i=e.x[e.x.length-1]);if(!(i>r))return null;let a=Math.max(2,t),o=Float64Array.from({length:a},(e,t)=>r+t/(a-1)*(i-r)),s=new Float64Array(a).fill(1/0),c=new Float64Array(a).fill(-1/0),l=new Uint16Array(a);for(let e of n){let t=0;for(let n=0;n<a;n++){let r=o[n];if(r<e.x[0]||r>e.x[e.x.length-1])continue;for(;t<e.x.length-2&&e.x[t+1]<r;)t++;let i=e.x[t],a=e.x[t+1],u=e.y[t],d=e.y[t+1],f=a===i?u:u+(d-u)*(r-i)/(a-i);f-f===0&&(f<s[n]&&(s[n]=f),f>c[n]&&(c[n]=f),l[n]++)}}for(let e=0;e<a;e++)l[e]<2&&(s[e]=NaN,c[e]=NaN);return{x:o,lo:s,hi:c}}function vX(e){for(let t=1;t<e.length;t++)if(!(e[t]>=e[t-1]))return!1;return!0}function yX(e){if(e.length===0)return null;if(e.length===1)return e[0];let t=new Set,n={};for(let r of e)for(let e=0;e<r.columnNames.length;e++){let i=r.columnNames[e];t.add(i),r.units[e]?.trim()&&(n[i]=r.units[e])}let r=[...t];return{meta:``,columnNames:r,units:r.map(e=>n[e]??``),rows:e.flatMap(e=>e.rows)}}function bX(e,t,n,r,i){return n||e.length===0||(t>0?e.length!==1:e.length<2||r!==`ElapsedTime`)?null:e.map((e,n)=>({conn:e,keySuffix:`__${t+n}`,offset:i[e.id]??0}))}function xX(e,t,n,r,i){if(e.length===1){let a=e[0];return SX(a.conn,t,n,a.keySuffix,a.offset,r,i)}let a=e.map(e=>SX(e.conn,t,n,e.keySuffix,e.offset,[],null)),o=()=>a.reduce((e,t)=>t.latestT()>e.latestT()?t:e);return{pull:(e,t,n,i)=>[...r,...a.flatMap(r=>r.pull(e,t,n,i))],xBounds:()=>{let e=i;for(let t of a){let n=t.xBounds();n&&(e=e?[Math.min(e[0],n[0]),Math.max(e[1],n[1])]:n)}return e},latestX:()=>o().latestX(),version:()=>a.reduce((e,t)=>e+t.version(),0),latestT:()=>o().latestT(),xAtTime:e=>o().xAtTime(e),latestValues:e=>new Map(a.flatMap(t=>[...t.latestValues(e)]))}}function SX(e,t,n,r,i,a,s){let l=null;return{pull:(s,u,d,f)=>{let p=e.source.version();if(!l||l.ver!==p||l.x0!==s||l.x1!==u||l.mp!==d){let a=e.source.getPointsSync(n,{xKey:t,x0:s-i,x1:u-i},d),o=i===0?a.x:a.x.map(e=>e+i);l={ver:p,x0:s,x1:u,mp:d,pts:{...a,x:o,cols:new Map([...a.cols].map(([e,t])=>[e+r,t]))}}}let m=o(l.pts,f);if(t!==`ElapsedTime`)return[...a,m];let h=Math.min(e.source.latestTimeSync(),f===void 0?1/0:f-i),g=c(n,t=>e.source.lastKnownSync(t),s-i,u-i,h);if(!g)return[...a,m];let _=i===0?g.x:g.x.map(e=>e+i);return[...a,m,{...g,x:_,cols:new Map([...g.cols].map(([e,t])=>[e+r,t]))}]},xBounds:()=>{let n=e.source.xBoundsSync(t);return n.x1>n.x0?s?[Math.min(s[0],n.x0+i),Math.max(s[1],n.x1+i)]:[n.x0+i,n.x1+i]:s},latestX:()=>{let n=e.source.latestSync(t);return Number.isFinite(n)?n+i:null},version:()=>e.source.version(),id:e.id,latestT:()=>e.source.latestTimeSync(),xAtTime:n=>e.source.xAtTimeSync(t,n)+i,latestValues:t=>{let n=new Map,i=t.filter(e=>e.endsWith(r)),a=e.source.latestValuesSync(i.map(e=>e.slice(0,-r.length)));for(let e of i){let t=a.get(e.slice(0,-r.length));t!==void 0&&n.set(e,t)}return n}}}function CX(e,t){return e.filter(e=>B(t,e))}var wX=`__ref`,TX=8e3;function EX(e,t){return e.map(e=>({...e,id:`${e.id}${wX}`,column:`${e.column}${wX}`,color:t}))}var DX=new WeakMap;function OX(e,t,r){let i=e.data.rows,a=`${t}\n${r.join(`
608
+ `)}`,o=DX.get(i);o||(o=new Map,DX.set(i,o));let s=o.get(a);if(s)return s;let c=kX(n(i,t,r,TX,wX)),l={points:c,span:c.length>1?[c.x[0],c.x[c.length-1]]:null};return o.set(a,l),l}function kX(e){let t=!0;for(let n=1;n<e.length&&t;n++)t=e.x[n-1]<=e.x[n];if(t)return e;let n=Array.from({length:e.length},(e,t)=>t).sort((t,n)=>e.x[t]-e.x[n]),r=new Map;for(let[t,i]of e.cols)r.set(t,Float64Array.from(n,e=>i[e]));return{length:e.length,x:Float64Array.from(n,t=>e.x[t]),cols:r}}function AX(e,t){return e?t?[Math.min(e[0],t[0]),Math.max(e[1],t[1])]:e:t}function jX(e,t,n,r,i){e.source.trackCycles(t);let a=r.reference===`dataset`&&i?OX(i,t,n):null,s=null;return{pull:(i,c,l,u)=>{let d=e.source.version();if(!s||s.ver!==d||s.x0!==i||s.x1!==c||s.mp!==l){let o=Ye;if(r.reference===`previous`){let r=e.source.cyclePointsSync(t,`previous`,n,{x0:i,x1:c},l);o={...r,cols:new Map([...r.cols].map(([e,t])=>[e+wX,t]))}}else a&&(o=j(a.points,i,c));s={ver:d,x0:i,x1:c,mp:l,live:e.source.cyclePointsSync(t,`current`,n,{x0:i,x1:c},l),ref:o}}return[s.ref,o(s.live,u)]},id:e.id,latestT:()=>e.source.latestTimeSync(),xAtTime:n=>e.source.xAtTimeSync(t,n),xBounds:()=>AX(e.source.cycleSpanSync(t),a?.span??null),latestX:()=>{let n=e.source.latestSync(t);return Number.isFinite(n)?n:null},version:()=>e.source.version(),latestValues:t=>e.source.latestValuesSync(t)}}function MX(e,t){return e.reference===`previous`?e.previousColor:e.reference===`dataset`&&t?e.datasetColor:null}function NX(e,t,n,r,i=0){let a=e.bands;if(!a)return[];let o=n.filter(e=>a[e.column]);if(o.length===0||e.data.rows.length!==a[o[0].column].lo.length)return[];let s=Float64Array.from(e.data.rows,e=>{let n=e[t];return typeof n==`number`?n+i:NaN});return o.map(e=>({seriesId:e.id,color:r??e.color,x:s,lo:a[e.column].lo,hi:a[e.column].hi}))}var PX=class{#e;#t;#n;#r=new Map;constructor(e,t={}){this.#e=e,this.#t=[...e.keys()].map(e=>({name:e,type:`number`,unit:t[e]??``})),this.#n=e.size?e.values().next().value.length:0}get length(){return this.#n}get columnMap(){return this.#e}async getSchema(){return this.#t}async getSeries(e){let t=this.#e.get(e.viewport.xKey),n=this.#e.get(e.column);return!t||!n?$e(new Float64Array,new Float64Array,e.viewport.x0,e.viewport.x1,e.maxPoints):$e(t,n,e.viewport.x0,e.viewport.x1,e.maxPoints)}async getSeriesMulti(e,t,n){return this.getSeriesMultiSync(e,t,n)}getSeriesMultiSync(e,t,n){let r=this.#e.get(t.xKey),i=r?e.filter(e=>this.#e.has(e)):[];return!r||i.length===0?{x0:t.x0,bucket:0,rows:[],columns:i}:a(r,i.map(e=>this.#e.get(e)),i,t.x0,t.x1,n)}getColumnsSync(e,t,n){let r=this.#e.get(t.xKey),i=r?e.filter(e=>this.#e.has(e)):[];return!r||i.length===0?null:R(r,i.map(e=>this.#e.get(e)),i,t.x0,t.x1,n)}async readColumns(e,t,n){let r={};for(let i of e){let e=this.#e.get(i);e&&(r[i]=e.slice(t,t+n))}return r}async xBounds(e){return this.xBoundsSync(e)}xBoundsSync(e){let t=this.#r.get(e);if(!t){let n=this.#e.get(e),r=1/0,i=-1/0;if(n)for(let e=0;e<n.length;e++){let t=n[e];t<r&&(r=t),t>i&&(i=t)}t=r<=i?{x0:r,x1:i}:{x0:0,x1:0},this.#r.set(e,t)}return t}sampleRowsSync(e,t){let n=t?this.#e.get(t.xcol):void 0,r=null;if(t&&n){r=[];for(let e=0;e<n.length;e++)n[e]>=t.x0&&n[e]<=t.x1&&r.push(e)}let i=r?r.length:this.#n,a=Math.max(1,Math.ceil(i/e)),o=[...this.#e.keys()],s=o.map(e=>this.#e.get(e)),c=[];for(let e=0;e<i;e+=a){let t=r?r[e]:e,n={};for(let e=0;e<o.length;e++){let r=s[e][t];n[o[e]]=Number.isNaN(r)?null:r}c.push(n)}return c}async sampleRows(e,t){return this.sampleRowsSync(e,t)}async dispose(){}};function FX(e){if(!Number.isFinite(e))return`—`;let t=Math.abs(e);return t>=1e4||t<.01&&e!==0?e.toExponential(1):String(parseFloat(e.toPrecision(4)))}function IX(e,t){let n=Math.max(1,Math.min(50,Math.floor(t.xBins))),r=Math.max(1,Math.min(50,Math.floor(t.yBins))),i=t.xMin,a=t.xMax,o=t.yMin,s=t.yMax;if(i===void 0||a===void 0||o===void 0||s===void 0){let n=1/0,r=-1/0,c=1/0,l=-1/0;for(let i of e){let e=i[t.xCol],a=i[t.yCol];typeof e==`number`&&Number.isFinite(e)&&(e<n&&(n=e),e>r&&(r=e)),typeof a==`number`&&Number.isFinite(a)&&(a<c&&(c=a),a>l&&(l=a))}i===void 0&&(i=n),a===void 0&&(a=r),o===void 0&&(o=c),s===void 0&&(s=l)}let c=a-i,l=s-o;if(!(c>0)||!(l>0))return{cells:[],xLabels:[],yLabels:[]};let u=new Float64Array(n*r),d=new Float64Array(n*r),f=t.valueCol===``;for(let p of e){let e=p[t.xCol],m=p[t.yCol];if(typeof e!=`number`||!Number.isFinite(e)||typeof m!=`number`||!Number.isFinite(m)||e<i||e>a||m<o||m>s)continue;let h=Math.floor((e-i)/c*n);h>=n&&(h=n-1),h<0&&(h=0);let g=Math.floor((m-o)/l*r);g>=r&&(g=r-1),g<0&&(g=0);let _=g*n+h;if(f)d[_]+=1;else{let e=p[t.valueCol];if(typeof e!=`number`||!Number.isFinite(e))continue;u[_]+=e,d[_]+=1}}let p=Array.from({length:n},(e,t)=>FX(i+(t+.5)*(c/n))),m=Array.from({length:r},(e,t)=>FX(o+(r-1-t+.5)*(l/r))),h=[];for(let e=0;e<r;e++){let t=r-1-e;for(let r=0;r<n;r++){let i=e*n+r,a=d[i],o=f?a:a>0?u[i]/a:NaN;h.push({x:p[r],y:m[t],value:o})}}return{cells:h,xLabels:p,yLabels:m}}function LX(e,t){return t.some(t=>t.name===e)}function RX(e,t){return LX(e,t)?`ƒ ${e}`:e}var zX=8e3,BX=3e3,VX=[];function HX(e){return`live`in e?e.live.source.columns():`source`in e&&e.source instanceof PX?e.source.columnMap:void 0}var UX=4e3,WX=new WeakMap;function GX(e,t,n){let r=WX.get(e);r||WX.set(e,r=new Map);let i=JSON.stringify([n,...t]),a=r.get(i);return a||r.set(i,a=new LE({meta:``,columnNames:[n,...t],units:[],rows:e})),a}var KX=new WeakMap;function qX(e,t){if(t!==`parallel`||e.length===0)return e;let n=e.length,r=100/n;return e.map((e,t)=>({...e,bandFromPct:Math.round((n-1-t)*r),bandToPct:Math.round((n-t)*r)}))}function JX(e,t){let n=1/0,r=-1/0;for(let{rows:i,offset:a}of e){let e=KX.get(i);e||(e=new Map,KX.set(i,e));let o=e.get(t);if(o===void 0){let n=1/0,r=-1/0;for(let e of i){let i=e[t];typeof i!=`number`||!Number.isFinite(i)||(i<n&&(n=i),i>r&&(r=i))}o=Number.isFinite(n)?[n,r]:null,e.set(t,o)}o&&(n=Math.min(n,o[0]+a),r=Math.max(r,o[1]+a))}return Number.isFinite(n)&&r>n?[n,r]:null}function YX(e,t){let n={};for(let t=0;t<e.columnNames.length;t++){let r=e.units[t]?.trim();r&&(n[e.columnNames[t]]=r)}let r=Object.entries(n);for(let e=0;e<t;e++)for(let[t,i]of r)n[`${t}__${e}`]=i;return n}function XX(e,t){let n=1/0,r=-1/0;for(let i of e){let e=i[t];typeof e!=`number`||!Number.isFinite(e)||(e<n&&(n=e),e>r&&(r=e))}if(!(r>n))return e;let i=(r-n)/2,a=0,o=NaN;for(let n=0;n<e.length;n++){let r=e[n][t];typeof r!=`number`||!Number.isFinite(r)||(r<o-i&&(a=n),o=r)}return a===0?e:e.slice(a)}var ZX=new Map;function QX(e){let t=ZX.get(e);return t||(t=Float64Array.from({length:e},(e,t)=>t),ZX.clear(),ZX.set(e,t)),t}function $X(e){let{worksheet:t,viewXRange:r,selectedIds:i,selectedDatasets:a,mathChannels:o,datasetOffsets:s,datasetColors:c,datasetPalette:l}=e,u=t.panels,d=t.panelChartSettings,f=t.xKey,p={connections:dt(()=>f===`ElapsedTime`?e.liveConnections:e.liveConnections.map(e=>{let t=XX(e.dataset.rows,f);return t===e.dataset.rows?e:{...e,dataset:{...e.dataset,rows:t}}}),[e.liveConnections,f])},[m,h]=ft({}),g=dt(()=>u.some(e=>e.kind!==`multiband`),[u]),_=dt(()=>p.connections.some(e=>i.includes(e.id)),[p.connections,i]),v=dt(()=>{let e=p.connections.filter(e=>i.includes(e.id));return e.length===1&&a.length===0?e[0]:null},[p.connections,i,a]),y=dt(()=>yX(a.map(e=>{let t=m[e.id];return t?{...e.data,rows:t}:e.data})),[a,m]),b=dt(()=>{let e=p.connections.filter(e=>i.includes(e.id)).map(e=>e.dataset);return e.length===0?y:yX(y?[y,...e]:e)},[y,p.connections,i]),x=dt(()=>SE(o,d,f).map(e=>e.id).join(`
609
609
  `),[o,d,f]),S=dt(()=>{let e=new Set(x.split(`
610
- `));return o.filter(t=>e.has(t.id))},[o,x]),C=dt(()=>{if(!b)return null;let e=[...a.map(e=>{let t=m[e.id];return t?{...e.data,rows:t}:e.data}),...p.connections.filter(e=>i.includes(e.id)).map(e=>e.dataset)];if(S.length===0)return{dataset:b,partRows:e.map(e=>e.rows),parts:e};let t=e.map(e=>xE(e,S,f)),n=new Set(t.flatMap(e=>e.ok.map(e=>e.id))),r=S.filter(e=>n.has(e.id)),o=t.map(e=>e.rows),s=t.map(e=>e.ok.map(e=>e.name));if(r.length===0)return{dataset:b,partRows:o,parts:e};let c=r.filter(e=>!b.columnNames.includes(e.name));return{dataset:{meta:b.meta,columnNames:[...b.columnNames,...c.map(e=>e.name)],units:[...b.units,...c.map(e=>e.units)],rows:o.length===1?o[0]:[].concat(...o)},partRows:o,parts:e,okByPart:s}},[b,a,m,p.connections,i,S,f]),w=C?.dataset??null,T=dt(()=>{let e=p.connections.filter(e=>i.includes(e.id));return e.length===0?a:[...a,...e.map(e=>({id:e.id,name:e.name,data:e.dataset,live:e}))]},[a,p.connections,i]),E=T.length>1,D=dt(()=>T.length===1?BX(T[0]):void 0,[T]),O=C?.partRows??zX;W(()=>{let e=a.filter(e=>e.kind!==`memory`);if(e.length===0)return;if(!r||!g){h(e=>Object.keys(e).length?{}:e);return}let t=!1,n=setTimeout(()=>{(async()=>{let n=await Promise.all(e.map(async e=>{let t={xcol:f,x0:r[0],x1:r[1]};try{let n=e.source,r=await ZU(`sampleRows`,()=>n.sampleRows(RX,t));return[e.id,r]}catch{return null}}));if(t)return;let i={};for(let e of n)e&&(i[e[0]]=e[1]);h(i)})()},150);return()=>{t=!0,clearTimeout(n)}},[a,r,f,g]);let k=dt(()=>w?.columnNames.join(`
610
+ `));return o.filter(t=>e.has(t.id))},[o,x]),C=dt(()=>{if(!b)return null;let e=[...a.map(e=>{let t=m[e.id];return t?{...e.data,rows:t}:e.data}),...p.connections.filter(e=>i.includes(e.id)).map(e=>e.dataset)];if(S.length===0)return{dataset:b,partRows:e.map(e=>e.rows),parts:e};let t=e.map(e=>xE(e,S,f)),n=new Set(t.flatMap(e=>e.ok.map(e=>e.id))),r=S.filter(e=>n.has(e.id)),o=t.map(e=>e.rows),s=t.map(e=>e.ok.map(e=>e.name));if(r.length===0)return{dataset:b,partRows:o,parts:e};let c=r.filter(e=>!b.columnNames.includes(e.name));return{dataset:{meta:b.meta,columnNames:[...b.columnNames,...c.map(e=>e.name)],units:[...b.units,...c.map(e=>e.units)],rows:o.length===1?o[0]:[].concat(...o)},partRows:o,parts:e,okByPart:s}},[b,a,m,p.connections,i,S,f]),w=C?.dataset??null,T=dt(()=>{let e=p.connections.filter(e=>i.includes(e.id));return e.length===0?a:[...a,...e.map(e=>({id:e.id,name:e.name,data:e.dataset,live:e}))]},[a,p.connections,i]),E=T.length>1,D=dt(()=>T.length===1?HX(T[0]):void 0,[T]),O=C?.partRows??VX;W(()=>{let e=a.filter(e=>e.kind!==`memory`);if(e.length===0)return;if(!r||!g){h(e=>Object.keys(e).length?{}:e);return}let t=!1,n=setTimeout(()=>{(async()=>{let n=await Promise.all(e.map(async e=>{let t={xcol:f,x0:r[0],x1:r[1]};try{let n=e.source,r=await $U(`sampleRows`,()=>n.sampleRows(BX,t));return[e.id,r]}catch{return null}}));if(t)return;let i={};for(let e of n)e&&(i[e[0]]=e[1]);h(i)})()},150);return()=>{t=!0,clearTimeout(n)}},[a,r,f,g]);let k=dt(()=>w?.columnNames.join(`
611
611
  `)??``,[w]),A=o.map(e=>e.name).join(`
612
- `),j=dt(()=>{let e=a.filter(e=>e.kind!==`memory`).flatMap(e=>xz(e.schema));return e.length?e:null},[a]),M=dt(()=>a.some(e=>e.kind!==`memory`)||!_&&a.some(e=>e.data.rows.length>LX),[a,_]),N=dt(()=>vX(p.connections.filter(e=>i.includes(e.id)),a.length,M,f,s),[M,a,p.connections,i,s,f]),P=dt(()=>{if(!_||a.length===0||M)return null;let e=a.map((e,t)=>{let n=e.data.rows;return{rows:n.length>0&&typeof n[0][f]==`number`?n:O[t]??n,offset:s[e.id]??0}});if(!N)for(let t of p.connections)i.includes(t.id)&&e.push({rows:t.dataset.rows,offset:s[t.id]??0});return KX(e,f)},[_,a,M,O,s,f,p.connections,i,N]),F=C&&`okByPart`in C?C.okByPart:void 0,I=dt(()=>{if(!M)return[];let e=T.map((e,t)=>({live:`live`in e&&!!e.live,source:`live`in e&&e.live?e.live.source:e.source,columnSet:new Set(`live`in e&&e.live?e.data.columnNames:e.schema.map(e=>e.name)),keySuffix:E?`__${t}`:``,xOffset:s[e.id]??0,key:`${e.id}|${E?t:``}`}));return T.forEach((t,n)=>{let r=F?.[n],i=O[n];`live`in t&&t.live||!r?.length||!i||e.push({...e[n],live:!1,source:UX(i,r,f),columnSet:new Set([f,...r]),key:`${e[n].key}|channels`})}),e},[M,T,E,s,F,O,f]),L=dt(()=>{let e=C?.parts??(w?[w]:[]),t=new Set;for(let n of e)for(let e of xX(n.columnNames,n.rows))t.add(e);let n=w?w.columnNames.filter(e=>t.has(e)):[],r=[...new Set(j?[...n,...j]:n)];if(A===``)return r;let i=new Set(r),a=A.split(`
613
- `).filter(e=>!i.has(e));return a.length?[...r,...a]:r},[k,A,j]),R=dt(()=>{let e=[];for(let t of u){if(t.kind!==`multiband`)continue;let n=d[t.id],r=n&&n.kind===`multiband`?n.series:[];e.push([t.id,[...new Set(r.map(e=>e.column).filter(e=>e!==f))]])}return JSON.stringify(e)},[u,d,f]),z=dt(()=>{let e={};if(!w||M)return e;for(let[t,r]of JSON.parse(R)){let i=[];if(r.length>0)if(!E)i.push(n(w.rows,f,r,LX));else{let e=Math.max(1,Math.floor(LX/T.length));for(let t=0;t<T.length;t++){let a=T[t];if(N&&`live`in a&&a.live)continue;let o=O[t]??a.data.rows;i.push(n(o,f,r,e,`__${t}`,s[a.id]??0))}}e[t]=i}return e},[w,R,f,E,T,s,O,N,M]),B=dt(()=>{let e={};if(!w)return e;for(let t of u){if(t.kind!==`multiband`)continue;let n=d[t.id],r=(n&&n.kind===`multiband`?n.series:[]).filter(e=>e.column!==f),i=n&&n.kind===`multiband`?n.layout:`overlay`,a=e=>GX(e,i),o;if(!E)o=a(r);else{let e=a(r);o=[];for(let t=0;t<T.length;t++){let n=Jz(c,T[t].id,t,l);for(let r of e)o.push({...r,id:`${r.id}__${t}`,column:`${r.column}__${t}`,color:n})}}let u=z[t.id]??[],p=E&&n?.kind===`multiband`&&n.envelope?r.flatMap(e=>{let t=hX(u.flatMap((t,n)=>{let r=t.cols.get(`${e.column}__${n}`);return r?[{x:t.x,y:r}]:[]}),VX);return t?[{seriesId:e.id,color:e.color,...t}]:[]}):void 0,m=T.flatMap((e,t)=>`bands`in e&&e.bands?jX(e,f,r,E?Jz(c,e.id,t,l):void 0,s[e.id]??0):[]),h=[...p??[],...m];e[t.id]={effectiveSeries:o,points:u,envelopes:h.length?h:void 0}}return e},[w,u,d,f,E,T,c,l,s,z]),V=dt(()=>{let e={pts:{},colorMeta:{},datasetColors:{}};if(!w)return e;let t={},n={},i={},a=BX,o=T.map((e,t)=>({id:e.id,rows:O[t]??m[e.id]??e.data.rows,full:a(e)})),s={id:`single`,rows:w.rows,full:T.length===1?a(T[0]):void 0};for(let e of u){if(e.kind!==`xyscatter`)continue;let a=d[e.id];if(!a||a.kind!==`xyscatter`)continue;let{xyXCol:u,xyYCol:p}=a;if(!u||!p){t[e.id]={length:0,x:[],y:[]};continue}if(E){let{cols:n,colors:a}=SW(o,u,p,{xKey:f,viewXRange:r,colorOverrides:c,palette:l});t[e.id]=n,i[e.id]=a;continue}let m=xW(s,u,p,{xKey:f,viewXRange:r,colorCol:a.xyColorCol||void 0});t[e.id]=m?.cols??{length:0,x:[],y:[]},m?.color&&(n[e.id]=m.color)}return{pts:t,colorMeta:n,datasetColors:i}},[w,u,d,r,f,E,T,m,c,l,O]),ee=K(new Map),te=dt(()=>{let e={};if(!w)return e;let t={length:0,x:[],y:[],z:[]},{rows:n}=w,i=D;for(let a of u){if(a.kind!==`xyzmesh`)continue;let o=d[a.id];if(!o||o.kind!==`xyzmesh`)continue;if(o.xyzMode===`matrix`){let r=(o.xyzColumns??[]).flatMap(e=>{let t=hW(n,e,i);return t?[t]:[]}),s=r[0]?.length??0,c=r.length;if(s<2||c<2){e[a.id]={points:t};continue}let l=ee.current.get(a.id);l?.length!==s*c&&ee.current.set(a.id,l=new Float32Array(s*c)),r.forEach((e,t)=>l.set(e.length===s?e:e.subarray(0,s),t*s));let u=hW(n,f,i),d=u&&!(o.xyzColumns??[]).includes(f)&&u.length>=s&&Number.isFinite(u[0])&&Number.isFinite(u[s-1])?[u[0],u[s-1]]:[0,s-1];e[a.id]={points:t,surface:{w:s,h:c,values:l,x:d,y:[0,c-1]}};continue}let{xyzXCol:s,xyzYCol:c,xyzZCol:l}=o,u=s?hW(n,s,i):void 0,p=c?hW(n,c,i):void 0,m=l?hW(n,l,i):void 0;if(!u||!p||!m){e[a.id]={points:t};continue}let h=r?hW(n,f,i):void 0;if(!r||!h){e[a.id]={points:{length:Math.min(u.length,p.length,m.length),x:u,y:p,z:m}};continue}let[g,_]=r,v=0;for(let e=0;e<h.length;e++)h[e]>=g&&h[e]<=_&&v++;let y=new Float64Array(v),b=new Float64Array(v),x=new Float64Array(v);for(let e=0,t=0;e<h.length;e++)h[e]>=g&&h[e]<=_&&(y[t]=u[e],b[t]=p[e],x[t]=m[e],t++);e[a.id]={points:{length:v,x:y,y:b,z:x}}}return e},[w,u,d,r,f,D]),H=dt(()=>{let e={};if(!w)return e;for(let t of u){if(t.kind!==`histogram`)continue;let n=d[t.id];e[t.id]=n?.kind===`histogram`&&n.histColumn&&gW(w.rows,n.histColumn,D)||new Float64Array}return e},[w,u,d,D]),ne=dt(()=>{let e={};if(!w)return e;for(let t of u){if(t.kind!==`polar`)continue;let n=d[t.id],r=n?.kind===`polar`&&n.polarAngleCol?hW(w.rows,n.polarAngleCol,D):void 0,i=n?.kind===`polar`&&n.polarRadiusCol?hW(w.rows,n.polarRadiusCol,D):void 0;e[t.id]=r&&i?{angles:r,radii:i}:{angles:[],radii:[]}}return e},[w,u,d,D]),re=(e,t,n,r)=>{let i=t&&gW(e,t,D)||new Float64Array,a=n?hW(e,n,D):void 0;return{signal:i,rate:a&&vW(a)||parseFloat(r)||1}},ie=dt(()=>{let e={};if(!w)return e;for(let t of u){if(t.kind!==`spectrum`)continue;let n=d[t.id];n?.kind===`spectrum`&&(e[t.id]=re(w.rows,n.specSignalCol,n.specTimeCol,n.specSampleRate))}return e},[w,u,d,D]),U=dt(()=>{let e={};if(!w)return e;for(let t of u){if(t.kind!==`boxplot`)continue;let n=d[t.id];e[t.id]=n?.kind===`boxplot`&&n.boxValueCol?_W(w.rows,n.boxValueCol,n.boxGroupCol||void 0,D):[]}return e},[w,u,d,D]),ae=dt(()=>{let e={};if(!w)return e;for(let t of u){if(t.kind!==`spectrogram`)continue;let n=d[t.id];n?.kind===`spectrogram`&&(e[t.id]=re(w.rows,n.sgSignalCol,n.sgTimeCol,n.sgSampleRate))}return e},[w,u,d,D]),oe=dt(()=>{if(!w)return{};let e={};for(let t of u){if(t.kind!==`heatmap`)continue;let n=d[t.id];if(!n||n.kind!==`heatmap`){e[t.id]={cells:[],xLabels:[],yLabels:[]};continue}if(n.hmMode===`matrix`){let r=w.rows,i=n.hmColumns.flatMap(e=>{let t=hW(r,e,D);return t?[{name:e,v:t}]:[]}),a=i.reduce((e,t)=>Math.min(e,t.v.length),i.length?1/0:0),o=hW(r,f,D),s,c;if(n.hmSpacing===`values`){o&&Aq(o.subarray(0,a))&&(s=Float64Array.from(o.subarray(0,a)));let e=i.map(e=>({c:e,v:parseFloat(e.name)})).sort((e,t)=>t.v-e.v);e.length&&Aq(e.map(e=>e.v).reverse())&&(i=e.map(e=>e.c),c=Float64Array.from(e,e=>e.v))}let l=i.length,u=new Float32Array(a*l);i.forEach((e,t)=>u.set(e.v.subarray(0,a),t*a));let d=e=>String(o?+o[e].toPrecision(6):e+1);e[t.id]={cells:[],xLabels:[],yLabels:i.map(e=>e.name),grid:{w:a,h:l,values:u,xLabels:d,yLabels:i.map(e=>e.name)},xCentres:s,yCentres:c}}else if(n.hmMode===`correlation`){let r=n.hmColumns.filter(e=>L.includes(e));if(r.length<2){e[t.id]={cells:[],xLabels:r,yLabels:r};continue}let i=r.map(e=>{let t=[];for(let n of w.rows){let r=n[e];typeof r==`number`&&Number.isFinite(r)&&t.push(r)}return t}),a=i.map(e=>e.reduce((e,t)=>e+t,0)/(e.length||1)),o=[];for(let e=0;e<r.length;e++)for(let t=0;t<r.length;t++){let n=i[e],s=i[t],c=a[e],l=a[t],u=Math.min(n.length,s.length),d=0,f=0,p=0;for(let e=0;e<u;e++){let t=n[e]-c,r=s[e]-l;d+=t*r,f+=t*t,p+=r*r}let m=f>0&&p>0?d/Math.sqrt(f*p):+(e===t);o.push({x:r[t],y:r[e],value:m})}e[t.id]={cells:o,xLabels:r,yLabels:r}}else if(n.hmMode===`binned`||n.hmMode===`count`){let{hmXCol:r,hmYCol:i}=n,a=n.hmMode===`count`?``:n.hmValueCol;if(!r||!i||n.hmMode===`binned`&&!a){e[t.id]={cells:[],xLabels:[],yLabels:[]};continue}let o=e=>{let t=parseFloat(e);return Number.isFinite(t)?t:void 0};e[t.id]=PX(w.rows,{xCol:r,yCol:i,valueCol:a,xBins:n.hmXBins,yBins:n.hmYBins,xMin:o(n.hmXMin),xMax:o(n.hmXMax),yMin:o(n.hmYMin),yMax:o(n.hmYMax)})}else{let{hmXCol:r,hmYCol:i,hmValueCol:a}=n;if(!r||!i||!a){e[t.id]={cells:[],xLabels:[],yLabels:[]};continue}let o=new Map,s=new Set,c=new Set;for(let e of w.rows){let t=String(e[r]??``),n=String(e[i]??``),l=e[a];if(typeof l!=`number`||!Number.isFinite(l))continue;s.add(t),c.add(n);let u=`${t}\0${n}`,d=o.get(u)??{sum:0,count:0};o.set(u,{sum:d.sum+l,count:d.count+1})}let l=e=>{let t=[...e];return t.every(e=>e.trim()!==``&&Number.isFinite(Number(e)))?t.sort((e,t)=>Number(e)-Number(t)):t.sort()},u=l(s),d=l(c),f,p;if(n.hmSpacing===`values`){let e=Float64Array.from(u,Number),t=Float64Array.from(d,Number);Aq(e)&&(f=e),Aq(t)&&(d=[...d].reverse(),p=t.reverse())}let m=[];for(let e of d)for(let t of u){let n=o.get(`${t}\0${e}`);m.push({x:t,y:e,value:n?n.sum/n.count:0})}e[t.id]={cells:m,xLabels:u,yLabels:d,xCentres:f,yCentres:p}}}return e},[w,u,d,L,f,D]),se=dt(()=>{let e={};if(!w)return e;for(let t of u){if(t.kind!==`violin`)continue;let n=d[t.id];e[t.id]=n?.kind===`violin`&&n.vlValueCol?_W(w.rows,n.vlValueCol,n.vlGroupCol||void 0,D):[]}return e},[w,u,d,D]),ce=dt(()=>{let e={};if(!w)return e;let{rows:t}=w;for(let n of u){if(n.kind!==`confusion`)continue;let r=d[n.id];if(!r||r.kind!==`confusion`||!r.cfActualCol||!r.cfPredictedCol){e[n.id]={actual:[],predicted:[]};continue}let{cfActualCol:i,cfPredictedCol:a}=r,o=D?.get(i),s=D?.get(a);if(o&&s){e[n.id]={actual:o,predicted:s};continue}let c=[],l=[];for(let e of t){let t=e[i],n=e[a];t!==void 0&&n!==void 0&&(c.push(t),l.push(n))}e[n.id]={actual:c,predicted:l}}return e},[w,u,d,D]),le=dt(()=>{let e={};if(!w)return e;for(let t of u){if(t.kind!==`roc`)continue;let n=d[t.id],r=n?.kind===`roc`&&n.rocScoreCol?hW(w.rows,n.rocScoreCol,D):void 0,i=n?.kind===`roc`&&n.rocLabelCol?hW(w.rows,n.rocLabelCol,D):void 0;e[t.id]=r&&i?{scores:r,labels:i}:{scores:[],labels:[]}}return e},[w,u,d,D]),ue=dt(()=>{let e={};if(!w)return e;let{rows:t}=w;for(let n of u){if(n.kind!==`losscurve`)continue;let r=d[n.id];if(!r||r.kind!==`losscurve`){e[n.id]={xValues:[],series:[]};continue}let{lcXCol:i,lcLeftCols:a,lcRightCols:o}=r,s=[...a.map(e=>({...e,axis:`left`})),...o.map(e=>({...e,axis:`right`}))].map(({column:e,color:n,axis:r})=>({label:e,color:n,values:hW(t,e,D)??new Float64Array,axis:r})),c=s[0]?.values.length??t.length,l=i&&hW(t,i,D)||Float64Array.from({length:c},(e,t)=>t);e[n.id]={xValues:l,series:s}}return e},[w,u,d,D]),de=dt(()=>{let e={};if(!w)return e;let{rows:t}=w;for(let n of u){if(n.kind!==`controlchart`)continue;let r=d[n.id],i=r?.kind===`controlchart`&&r.ccValueCol?hW(t,r.ccValueCol,D):void 0;if(!r||r.kind!==`controlchart`||!i){e[n.id]={length:0,value:[]};continue}let a=0;for(let e=0;e<i.length;e++)i[e]-i[e]===0&&a++;let o=a===i.length?null:new Uint32Array(a),s=o?new Float64Array(a):i;if(o)for(let e=0,t=0;e<i.length;e++)i[e]-i[e]===0&&(o[t]=e,s[t++]=i[e]);let c=r.ccSubgroupCol,l=c?D?.get(c):void 0,u=e=>o?o[e]:e;e[n.id]={length:a,value:s,subgroup:c?e=>String(l?l[u(e)]:t[u(e)]?.[c]??``):void 0}}return e},[w,u,d,D]),fe=dt(()=>{let e={};if(!w)return e;let{rows:t}=w;for(let n of u){if(n.kind!==`parallelcoords`)continue;let r=d[n.id];if(!r||r.kind!==`parallelcoords`||r.pcColumns.length<2){e[n.id]={length:0,columns:[]};continue}let i=r.pcColumns.map(e=>hW(t,e,D)??new Float64Array),a=Math.min(...i.map(e=>e.length)),o={length:a,columns:i},s=r.pcColorByCol;if(s)if(L.includes(s))o.colorValue=hW(t,s,D);else{let e=new Map,n=new Int32Array(a);for(let r=0;r<a;r++){let i=String(t[r]?.[s]??``),a=e.get(i);a===void 0&&e.set(i,a=e.size),n[r]=a}o.colorIndex=n,o.colorLabels=[...e.keys()]}e[n.id]=o}return e},[w,u,d,L,D]),pe=dt(()=>{let e={};if(!w)return e;let{rows:t}=w,n={length:0,x:[],y:[]};for(let r of u){if(r.kind!==`embedding`)continue;let i=d[r.id];if(!i||i.kind!==`embedding`||!i.emXCol||!i.emYCol){e[r.id]=n;continue}let{emXCol:a,emYCol:o,emColorCol:s,emColorMode:c,emLabelCol:l}=i,u=hW(t,a,D),f=hW(t,o,D);if(!u||!f){e[r.id]=n;continue}let p=Math.min(u.length,f.length),m={length:p,x:u,y:f};if(s)if(c===`numeric`&&L.includes(s))m.colorValue=hW(t,s,D);else{let e=D?.get(s),n=new Map,r=new Int32Array(p);for(let i=0;i<p;i++){let a=String(e?e[i]:t[i]?.[s]??``),o=n.get(a);o===void 0&&n.set(a,o=n.size),r[i]=o}m.colorIndex=r,m.colorLabels=[...n.keys()]}if(l){let e=D?.get(l);m.label=e?t=>String(e[t]):e=>String(t[e]?.[l]??``)}e[r.id]=m}return e},[w,u,d,L,D]),me=dt(()=>{if(!w)return{};let e={};for(let t of u){if(t.kind!==`flamegraph`)continue;let n=d[t.id];if(!n||n.kind!==`flamegraph`||!n.fgNameCol||!n.fgValueCol){e[t.id]=[];continue}let r=[];for(let e of w.rows){let t=String(e[n.fgNameCol]??``),i=n.fgParentCol?String(e[n.fgParentCol]??``):``,a=e[n.fgValueCol];!t||typeof a!=`number`||!Number.isFinite(a)||r.push({name:t,parent:i,value:a})}e[t.id]=r}return e},[w,u,d]),he=dt(()=>{if(!w)return{};let e={};for(let t of u){if(t.kind!==`barchart`)continue;let n=d[t.id];if(!n||n.kind!==`barchart`||n.bcValueCols.length===0){e[t.id]={groups:[],seriesNames:[]};continue}let r=n.bcValueCols;if(n.bcCategoryCol){let i=new Map;for(let e of w.rows){let t=String(e[n.bcCategoryCol]??`(blank)`);i.has(t)||i.set(t,r.map(()=>0));let a=new Map,o=i.get(t);for(let t=0;t<r.length;t++){let n=e[r[t]];typeof n==`number`&&Number.isFinite(n)&&(o[t]+=n),a.set(r[t],(a.get(r[t])??0)+1)}}e[t.id]={groups:Array.from(i.entries()).map(([e,t])=>({label:e,values:t})),seriesNames:r}}else{let n=w.rows,i=r.map(e=>hW(n,e,D)),a=i.reduce((e,t)=>t?Math.min(e,t.length):e,1/0),o=Number.isFinite(a)?a:n.length,s=i.map(e=>e??new Float64Array(o).fill(NaN));e[t.id]={groups:[],columns:{length:o,values:s},seriesNames:r}}}return e},[w,u,d,D]),ge=dt(()=>{let e={};if(!w)return e;let{rows:t}=w;for(let n of u){if(n.kind!==`radar`)continue;let r=d[n.id];if(!r||r.kind!==`radar`||r.rdAxesCols.length<3){e[n.id]={axes:[],series:[]};continue}let i=r.rdAxesCols,a=i.map(e=>hW(t,e,D));if(r.rdGroupCol){let o=r.rdGroupCol,s=D?.get(o),c=s?s.length:t.length,l=new Map;for(let e=0;e<c;e++){let n=s?s[e]===s[e]?String(s[e]):`(blank)`:String(t[e][o]??`(blank)`),r=l.get(n);r||l.set(n,r=i.map(()=>0));for(let t=0;t<i.length;t++){let n=a[t]?.[e]??NaN;n-n===0&&(r[t]+=n)}}e[n.id]={axes:i,series:Array.from(l.entries()).map(([e,t])=>({name:e,values:t}))}}else{let t=a.map(e=>{let t=0,n=0;if(e)for(let r=0;r<e.length;r++)e[r]-e[r]===0&&(t+=e[r],n++);return t/(n||1)});e[n.id]={axes:i,series:[{name:`Series 1`,values:t}]}}}return e},[w,u,d,D]),_e=dt(()=>{if(!w)return{};let e={};for(let t of u){if(t.kind!==`areachart`)continue;let n=d[t.id];if(!n||n.kind!==`areachart`||n.acYCols.length===0){e[t.id]=[];continue}let r=w.rows,i=n.acYCols.map(e=>hW(r,e,D)),a=i[0]?.length??r.length,o=(n.acXCol?hW(r,n.acXCol,D):void 0)??XX(a);e[t.id]=n.acYCols.flatMap((e,t)=>{let n=i[t];return n?[{name:e,x:o,y:n}]:[]})}return e},[w,u,d,D]),ve=dt(()=>{let e={};if(!w)return e;for(let t of u){if(t.kind!==`cdfchart`)continue;let n=d[t.id];if(!n||n.kind!==`cdfchart`){e[t.id]=[];continue}e[t.id]=n.cdValueCols.map(e=>({name:e,values:gW(w.rows,e,D)??new Float64Array}))}return e},[w,u,d,D]),ye=dt(()=>{let e={};if(!w)return e;let{rows:t}=w,n={length:0,x:[],y:[],size:[]};for(let r of u){if(r.kind!==`bubblechart`)continue;let i=d[r.id];if(!i||i.kind!==`bubblechart`||!i.bbXCol||!i.bbYCol||!i.bbSizeCol){e[r.id]=n;continue}let a=hW(t,i.bbXCol,D),o=hW(t,i.bbYCol,D),s=hW(t,i.bbSizeCol,D);if(!a||!o||!s){e[r.id]=n;continue}let c=Math.min(a.length,o.length,s.length),l=new Float64Array(c);for(let e=0;e<c;e++)l[e]=s[e]===s[e]?Math.max(0,s[e]):NaN;let u=new Float64Array(c);for(let e=0;e<c;e++)u[e]=l[e]===l[e]?a[e]:NaN;let f={length:c,x:u,y:o,size:l};if(i.bbColorCol){if(i.bbColorMode===`numeric`)f.colorValue=hW(t,i.bbColorCol,D);else if(i.bbColorMode===`categorical`){let e=D?.get(i.bbColorCol),n=new Map,r=new Int32Array(c);for(let a=0;a<c;a++){let o=String(e?e[a]:t[a]?.[i.bbColorCol]??``),s=n.get(o);s===void 0&&n.set(o,s=n.size),r[a]=s}f.colorIndex=r,f.colorLabels=[...n.keys()]}}e[r.id]=f}return e},[w,u,d,D]),be=dt(()=>{if(!w)return{};let e={};for(let t of u){if(t.kind!==`treemap`)continue;let n=d[t.id];if(!n||n.kind!==`treemap`||!n.tmNameCol||!n.tmValueCol){e[t.id]=[];continue}let r=[];for(let e of w.rows){let t=String(e[n.tmNameCol]??``),i=n.tmParentCol?String(e[n.tmParentCol]??``):``,a=e[n.tmValueCol];!t||typeof a!=`number`||!Number.isFinite(a)||r.push({name:t,parent:i,value:a})}e[t.id]=r}return e},[w,u,d]),xe=dt(()=>{if(!w)return{};let e={};for(let t of u){if(t.kind!==`sankey`)continue;let n=d[t.id];if(!n||n.kind!==`sankey`||!n.skSourceCol||!n.skTargetCol||!n.skValueCol){e[t.id]={nodeNames:[],links:[]};continue}let r=new Set,i=[];for(let e of w.rows){let t=String(e[n.skSourceCol]??``),a=String(e[n.skTargetCol]??``),o=e[n.skValueCol];!t||!a||typeof o!=`number`||!Number.isFinite(o)||(r.add(t),r.add(a),i.push({source:t,target:a,value:o}))}e[t.id]={nodeNames:Array.from(r),links:i}}return e},[w,u,d]),Se=dt(()=>{let e={};if(!w)return e;for(let t of u){if(t.kind!==`calibration`)continue;let n=d[t.id],r=n?.kind===`calibration`&&n.cbScoreCol?hW(w.rows,n.cbScoreCol,D):void 0,i=n?.kind===`calibration`&&n.cbLabelCol?hW(w.rows,n.cbLabelCol,D):void 0;if(!n||n.kind!==`calibration`||!r||!i){e[t.id]=[];continue}let a=Math.max(2,n.cbBins),o=new Float64Array(a),s=new Float64Array(a);for(let e=0;e<Math.min(r.length,i.length);e++){let t=r[e],n=i[e];if(t-t!==0||n-n!==0)continue;let c=Math.max(0,Math.min(a-1,Math.floor(t*a)));o[c]+=n,s[c]++}e[t.id]=Array.from({length:a},(e,t)=>({center:(t+.5)/a,actual:s[t]>0?o[t]/s[t]:0,count:s[t]})).filter(e=>e.count>0)}return e},[w,u,d,D]),Ce=dt(()=>{let e={};if(!w)return e;let t={length:0,theoretical:[],sample:[]},n=e=>{let t=gW(w.rows,e,D);return t?Float64Array.from(t).sort():new Float64Array};for(let r of u){if(r.kind!==`qqplot`)continue;let i=d[r.id];if(!i||i.kind!==`qqplot`||!i.qqValueCol){e[r.id]=t;continue}let a=n(i.qqValueCol),o=a.length;if(o===0){e[r.id]=t;continue}if(i.qqMode===`column`&&i.qqRefCol){let t=n(i.qqRefCol),s=Math.min(o,t.length);e[r.id]={length:s,theoretical:t.subarray(0,s),sample:a.subarray(0,s)}}else{let t=e=>{let t=[2.515517,.802853,.010328],n=[1.432788,.189269,.001308],r=Math.sqrt(-2*Math.log(Math.min(e,1-e))),i=r-(t[0]+t[1]*r+t[2]*r*r)/(1+n[0]*r+n[1]*r*r+n[2]*r*r*r);return e<.5?-i:i},n=new Float64Array(o);for(let e=0;e<o;e++)n[e]=t((e+.5)/o);e[r.id]={length:o,theoretical:n,sample:a}}}return e},[w,u,d,D]),we=dt(()=>{if(!w)return{};let e={};for(let t of u){if(t.kind!==`gantt`)continue;let n=d[t.id];if(!n||n.kind!==`gantt`||!n.gtLabelCol||!n.gtStartCol||!n.gtEndCol){e[t.id]=[];continue}let r=[];for(let e of w.rows){let t=String(e[n.gtLabelCol]??``),i=e[n.gtStartCol],a=e[n.gtEndCol];if(!t||typeof i!=`number`||typeof a!=`number`||!Number.isFinite(i)||!Number.isFinite(a))continue;let o={label:t,start:i,end:a};n.gtGroupCol&&e[n.gtGroupCol]!==void 0&&(o.group=String(e[n.gtGroupCol])),r.push(o)}e[t.id]=r}return e},[w,u,d]),Te=w&&w.columnNames.indexOf(f)>=0?w.units[w.columnNames.indexOf(f)]??``:``,Ee=dt(()=>w?qX(w,E?T.length:0):{},[w,E,T]);return{dataset:b,datasetWithChannels:w,multiDatasetMode:E,numericCols:L,anyDuckDb:M,duckDbLayers:I,liveConn:v,liveOverlays:N,hasLiveSelected:_,staticXRange:P,xUnit:Te,columnUnits:Ee,multibandDataByPanel:B,xyPointsByPanel:V,xyzPointsByPanel:te,histogramDataByPanel:H,polarDataByPanel:ne,spectrumDataByPanel:ie,boxplotDataByPanel:U,spectrogramDataByPanel:ae,heatmapDataByPanel:oe,violinDataByPanel:se,confusionDataByPanel:ce,rocDataByPanel:le,lossCurveDataByPanel:ue,controlChartDataByPanel:de,parallelCoordsDataByPanel:fe,embeddingDataByPanel:pe,flameGraphDataByPanel:me,barChartDataByPanel:he,radarDataByPanel:ge,areaChartDataByPanel:_e,cdfChartDataByPanel:ve,bubbleChartDataByPanel:ye,treemapDataByPanel:be,sankeyDataByPanel:xe,calibrationDataByPanel:Se,qqPlotDataByPanel:Ce,ganttDataByPanel:we,gaugeDataByPanel:dt(()=>{let e={};if(!w)return e;let t=e=>e.trim()!==``&&Number.isFinite(Number(e))?Number(e):void 0;for(let n of u){if(n.kind!==`gauge`)continue;let r=d[n.id];if(r?.kind!==`gauge`){e[n.id]=[];continue}e[n.id]=r.ggGauges.flatMap(e=>{let n=e.column,r=n?hW(w.rows,n,D):void 0;if(!r)return[];let i=1/0,a=-1/0,o=0,s=0,c=NaN;for(let e=0;e<r.length;e++){let t=r[e];t-t===0&&(t<i&&(i=t),t>a&&(a=t),o+=t,s++,c=t)}let l=s===0?NaN:e.value===`mean`?o/s:e.value===`min`?i:e.value===`max`?a:c,[u,d]=QX(s?i:0,s?a:1,t(e.min),t(e.max));return[{name:n,unit:Ee[n]??``,value:l,min:u,max:d,alarm:e.alarm??null,color:e.color,style:e.style,fromZero:e.fill===`zero`,colorMode:e.colorMode,stops:e.stops,stat:e.value}]})}return e},[w,u,d,D,Ee])}}function QX(e,t,n,r){t<=e&&(t=e+1);let i=wz(t-e,5),a=n??Math.floor(e/i)*i,o=r??Math.ceil(t/i)*i;return o>a?[a,o]:[a,a+1]}var $X=`#fb7185`,eZ=2500;function tZ(e){let{panel:t,data:n,settings:r}=e;if(t.kind===`camera`)return{status:`ready`,data:null,node:q(lX,{settings:r?.kind===`camera`?r:Hn(),live:e.live??[],selection:e.selection??[],viewXRange:e.viewXRange,xIsTime:e.xKey===qe,xKey:e.xKey,video:e.video,recordings:e.recordings,cursor:e.cursor,onContextMenu:t=>e.onContextMenu(t)})};if(!n.dataset)return{status:`no-data`,node:null,data:null};let i=`${e.background??`theme`}|${e.styleToken}`,a=t=>e.onContextMenu(t),s=(e,t)=>({status:`ready`,node:e,data:t}),l={status:`empty`,node:null,data:null},u=t.id;switch(t.kind){case`multiband`:{let t=n.multibandDataByPanel[u],d=t?.points??[],f=t?.effectiveSeries??[],p=r?.kind===`multiband`?r:null,m=[...new Set((p?.series??[]).map(e=>e.column).filter(t=>t!==e.xKey))],h=e.xKey===`ElapsedTime`&&!n.numericCols.includes(`Time`)?`Time`:e.xKey,g={xLabel:n.xUnit?`${h} (${n.xUnit})`:h,series:f,columnUnits:n.columnUnits,height:e.height,backgroundToken:i,viewXRange:e.viewXRange,onViewXRangeChange:e.onViewXRangeChange,onCursorX:e.onCursorX,liveZoom:e.liveZoom,liveZoomId:u,xAxisLine:p?.xAxisLine,yAxisLine:p?.yAxisLine,gridLine:p?.gridLine,lineWidth:p?.lineWidth,onPlotContextMenu:a,shiftMode:e.shiftMode},_=p?.beacon;if(_?.enabled&&e.beaconLive&&m.length>0){let t=GX((p?.series??[]).filter(t=>t.column!==e.xKey),p?.layout??`overlay`),n=_.reference===`dataset`&&_.datasetId?e.findDataset(_.datasetId):void 0,r=AX(_,!!n),i=r?[...wX(t,r),...t]:t;return s(q(GU,{...g,series:i,points:[],showLatestValues:!0,liveSource:kX(e.beaconLive,e.xKey,m,_,n),envelopes:n?jX(n,e.xKey,t,r??void 0):void 0,liveZoomMode:`free`}),{series:i,points:[]})}if(n.anyDuckDb)return f.length===0?l:s(q(fW,{...g,layers:n.duckDbLayers,xKey:e.xKey,columns:m,maxPoints:eZ}),{series:f,columns:m});if(!d.some(e=>e.length>0)&&!n.liveOverlays||f.length===0)return l;let v=n.liveConn,y=null,b=n.liveOverlays,x=!v&&b&&m.length>0?yX(b,e.xKey,m,d,n.staticXRange):void 0,S=!!x&&d.length>0,C=x??(v&&m.length>0?{pull:(t,n,r,i,a)=>{let s=v.source.version();if(a){let i=2**Math.ceil(Math.log2((n-t)/8)),a=Math.floor(t/i)*i,o=Math.ceil(n/i)*i,l=Math.round(r*(o-a)/(n-t));return(!y||y.ver!==s||y.x0!==a||y.x1!==o||Math.abs(y.mp-l)>l*.25)&&(y={ver:s,x0:a,x1:o,mp:l,pts:v.source.getPointsSync(m,{xKey:e.xKey,x0:a,x1:o},l),held:c(m,e=>v.source.lastKnownSync(e),a,o,v.source.latestTimeSync())}),y.held?[y.pts,y.held]:[y.pts]}(!y||y.ver!==s||y.x0!==t||y.x1!==n||y.mp!==r)&&(y={ver:s,x0:t,x1:n,mp:r,pts:v.source.getPointsSync(m,{xKey:e.xKey,x0:t,x1:n},r)});let l=o(y.pts,i);if(e.xKey!==`ElapsedTime`)return[l];let u=c(m,e=>v.source.lastKnownSync(e),t,n,Math.min(v.source.latestTimeSync(),i??1/0));return u?[l,u]:[l]},cutOnGpu:e.xKey===`ElapsedTime`,id:v.id,latestT:()=>v.source.latestTimeSync(),xAtTime:t=>v.source.xAtTimeSync(e.xKey,t),xBounds:()=>{let t=v.source.xBoundsSync(e.xKey);return t.x1>t.x0?[t.x0,t.x1]:null},latestX:()=>{let t=v.source.latestSync(e.xKey);return Number.isFinite(t)?t:null},version:()=>v.source.version(),latestValues:e=>v.source.latestValuesSync(e),...e.xKey===`ElapsedTime`?{}:{spanForSeconds:t=>v.source.xTravelSync(e.xKey,t),bufferedSeconds:()=>{let e=v.source.xBoundsSync(`ElapsedTime`);return e.x1-e.x0}}}:void 0);return s(q(GU,{...g,points:d,envelopes:t?.envelopes,showLatestValues:n.hasLiveSelected,fullXRange:n.staticXRange,liveSource:C,liveWindowSeconds:S?null:e.liveWindowSeconds,onLiveWindowChange:S?void 0:e.onLiveWindowChange,liveZoomMode:S?`free`:`follow`}),{series:f,points:d})}case`xyzmesh`:{let t=r?.kind===`xyzmesh`?r:hn(4),o=n.xyzPointsByPanel[u];if(!o||o.points.length<1&&!o.surface)return l;let c=!!o.surface;return s(q(mK,{ref:e.xyzRef,points:o.points,surface:o.surface,xLabel:c?(t.xyzColumns??[]).includes(e.xKey)?`Row`:e.xKey:t.xyzXCol,yLabel:c?`Column`:t.xyzYCol,zLabel:c?`Value`:t.xyzZCol,height:e.height,backgroundToken:i,xRange:ln(t.xyzXScale.scaleMin,t.xyzXScale.scaleMax),yRange:ln(t.xyzYScale.scaleMin,t.xyzYScale.scaleMax),zRange:ln(t.xyzZScale.scaleMin,t.xyzZScale.scaleMax),viewMode:t.xyzViewMode,pointRadius:t.xyzPointRadius,showMesh:t.showMesh,meshStyle:t.meshStyle,meshOpacity:t.meshOpacity,alarms:[...t.xyzXScale.alarm?[{axis:`x`,...t.xyzXScale.alarm}]:[],...t.xyzYScale.alarm?[{axis:`y`,...t.xyzYScale.alarm}]:[],...t.xyzZScale.alarm?[{axis:`z`,...t.xyzZScale.alarm}]:[]],onPlotContextMenu:a}),o.surface??o.points)}case`xyscatter`:{let t=r?.kind===`xyscatter`?r:mn($X),o=n.xyPointsByPanel.pts[u]??[];if(o.length===0)return l;let c=n.xyPointsByPanel.colorMeta[u];return s(q(nG,{points:o,xLabel:t.xyXCol,yLabel:t.xyYCol,color:t.xyColor,datasetColors:n.xyPointsByPanel.datasetColors[u],colorLabel:c?.label,colorRange:c?[c.min,c.max]:void 0,pointRadius:t.xyPointRadius,drawMode:t.xyDrawMode,lineWidth:t.xyLineWidth,height:e.height,backgroundToken:i,xAxisLine:t.xyXAxisLine,yAxisLine:t.xyYAxisLine,gridLine:t.xyGridLine,fitSettings:t.xyFit,xScale:t.xyXScale,yScale:t.xyYScale,onPlotContextMenu:a}),o)}case`histogram`:{if(r?.kind!==`histogram`)return l;let t=n.histogramDataByPanel[u]??[];return t.length===0?l:s(q(xK,{values:t,label:r.histColumn,bins:r.histBins,color:r.histColor,showNormal:r.histNormal,logY:r.histLogY,height:e.height,backgroundToken:i,onPlotContextMenu:a}),t)}case`polar`:{if(r?.kind!==`polar`)return l;let t=n.polarDataByPanel[u]??{angles:[],radii:[]};if(t.angles.length===0)return l;let o=parseFloat(r.polarRadiusMin),c=parseFloat(r.polarRadiusMax);return s(q(zK,{angles:t.angles,radii:t.radii,angleLabel:r.polarAngleCol,radiusLabel:r.polarRadiusCol,color:r.polarColor,mode:r.polarMode,radiusMin:Number.isFinite(o)?o:void 0,radiusMax:Number.isFinite(c)?c:void 0,height:e.height,backgroundToken:i,onPlotContextMenu:a}),t)}case`spectrum`:{if(r?.kind!==`spectrum`)return l;let{signal:t,rate:o}=n.spectrumDataByPanel[u]??{signal:[],rate:1};return t.length<4?l:s(q(tq,{signal:t,sampleRate:o,label:r.specSignalCol,xMode:r.specXMode,yMode:r.specYMode,window:r.specWindow,color:r.specColor,logX:r.specLogX,height:e.height,backgroundToken:i,onPlotContextMenu:a}),t)}case`boxplot`:{if(r?.kind!==`boxplot`)return l;let t=n.boxplotDataByPanel[u]??[];return t.length===0?l:s(q(sq,{groups:t,color:r.boxColor,whiskers:r.boxWhiskers,height:e.height,backgroundToken:i,onPlotContextMenu:a}),t)}case`spectrogram`:{if(r?.kind!==`spectrogram`)return l;let{signal:e,rate:t}=n.spectrogramDataByPanel[u]??{signal:[],rate:1};return e.length<r.sgWindowSize?l:r.sgView===`waterfall`?s(q(Tq,{signal:e,sampleRate:t,windowSize:r.sgWindowSize,overlap:r.sgOverlap,winFunc:r.sgWinFunc,yMode:r.sgYMode,backgroundToken:i,onPlotContextMenu:a}),e):s(q(bq,{signal:e,sampleRate:t,windowSize:r.sgWindowSize,overlap:r.sgOverlap,winFunc:r.sgWinFunc,yMode:r.sgYMode,logFreq:r.sgLogFreq,backgroundToken:i,onPlotContextMenu:a}),e)}case`heatmap`:{if(r?.kind!==`heatmap`)return l;let e=n.heatmapDataByPanel[u]??{cells:[],xLabels:[],yLabels:[]};if(e.cells.length===0&&!(e.grid&&e.grid.w*e.grid.h>0))return l;let t=e=>e!==void 0&&e.trim()!==``&&Number.isFinite(Number(e))?Number(e):void 0;return s(q(Wq,{cells:e.cells,xLabels:e.xLabels,yLabels:e.yLabels,grid:e.grid,showValues:r.hmShowValues,colorScheme:r.hmColorScheme,xCentres:e.xCentres,yCentres:e.yCentres,contours:r.hmContours??0,vMin:t(r.hmRange?.scaleMin),vMax:t(r.hmRange?.scaleMax),backgroundToken:i,onPlotContextMenu:a}),e)}case`violin`:{if(r?.kind!==`violin`)return l;let e=n.violinDataByPanel[u]??[];return e.some(e=>e.values.length>0)?s(q(Qq,{groups:e,color:r.vlColor,showBox:r.vlShowBox,bandwidth:parseFloat(r.vlBandwidth)||void 0,orientation:r.vlOrientation,backgroundToken:i,onPlotContextMenu:a}),e):l}case`confusion`:{if(r?.kind!==`confusion`)return l;let e=n.confusionDataByPanel[u]??{actual:[],predicted:[]};return e.actual.length===0?l:s(q(aJ,{actual:e.actual,predicted:e.predicted,normalize:r.cfNormalize,backgroundToken:i,onPlotContextMenu:a}),e)}case`roc`:{if(r?.kind!==`roc`)return l;let e=n.rocDataByPanel[u]??{scores:[],labels:[]};return e.scores.length===0?l:s(q(dJ,{scores:e.scores,labels:e.labels,mode:r.rocMode,color:r.rocColor,backgroundToken:i,onPlotContextMenu:a}),e)}case`losscurve`:{if(r?.kind!==`losscurve`)return l;let e=n.lossCurveDataByPanel[u]??{xValues:[],series:[]};return e.series.length===0?l:s(q(pJ,{xValues:e.xValues,series:e.series,xLabel:r.lcXCol||`Step`,backgroundToken:i,onPlotContextMenu:a}),e)}case`controlchart`:{if(r?.kind!==`controlchart`)return l;let e=n.controlChartDataByPanel[u];return!e||e.length<2?l:s(q(yJ,{points:e,sigmaLevel:r.ccSigmaLevel,color:r.ccColor,backgroundToken:i,onPlotContextMenu:a}),e)}case`parallelcoords`:{if(r?.kind!==`parallelcoords`)return l;let e=n.parallelCoordsDataByPanel[u];if(!e||e.length===0||r.pcColumns.length<2)return l;let t=r.pcColorByCol?n.numericCols.includes(r.pcColorByCol):!1;return s(q(TJ,{rows:e,axes:r.pcColumns,color:r.pcColor,colorByNumeric:t,backgroundToken:i,onPlotContextMenu:a}),e)}case`embedding`:{if(r?.kind!==`embedding`)return l;let e=n.embeddingDataByPanel[u];return!e||e.length===0?l:s(q(FJ,{points:e,color:r.emColor,colorByNumeric:r.emColorMode===`numeric`&&!!r.emColorCol,pointSize:r.emPointSize,backgroundToken:i,onPlotContextMenu:a}),e)}case`flamegraph`:{if(r?.kind!==`flamegraph`)return l;let e=n.flameGraphDataByPanel[u]??[];return e.length===0?l:s(q(UJ,{nodes:e,direction:r.fgDirection,backgroundToken:i,onPlotContextMenu:a}),e)}case`barchart`:{if(r?.kind!==`barchart`)return l;let e=n.barChartDataByPanel[u]??{groups:[],seriesNames:[]};if(e.groups.length===0&&!e.columns?.length)return l;let t=e=>e!==void 0&&e.trim()!==``&&Number.isFinite(Number(e))?Number(e):void 0,o=r.bcValueScale?{min:t(r.bcValueScale.scaleMin),max:t(r.bcValueScale.scaleMax)}:void 0;return s(q(YJ,{groups:e.columns?void 0:e.groups,columns:e.columns,seriesNames:e.seriesNames,mode:r.bcMode,horizontal:r.bcHorizontal,valueRange:o,backgroundToken:i,onPlotContextMenu:a}),e)}case`radar`:{if(r?.kind!==`radar`)return l;let e=n.radarDataByPanel[u]??{axes:[],series:[]};return e.axes.length<3?l:s(q($J,{axes:e.axes,series:e.series,fill:r.rdFill,color:r.rdColor,backgroundToken:i,onPlotContextMenu:a}),e)}case`areachart`:{if(r?.kind!==`areachart`)return l;let e=n.areaChartDataByPanel[u]??[];if(e.length===0)return l;let t=e=>e!==void 0&&e.trim()!==``&&Number.isFinite(Number(e))?Number(e):void 0,o=r.acYScale?{min:t(r.acYScale.scaleMin),max:t(r.acYScale.scaleMax)}:void 0;return s(q(rY,{series:e,stacked:r.acStacked,yRange:o,backgroundToken:i,onPlotContextMenu:a}),e)}case`cdfchart`:{if(r?.kind!==`cdfchart`)return l;let e=n.cdfChartDataByPanel[u]??[];return e.length===0?l:s(q(oY,{series:e,complement:r.cdComplement,logX:r.cdLogX,backgroundToken:i,onPlotContextMenu:a}),e)}case`bubblechart`:{if(r?.kind!==`bubblechart`)return l;let e=n.bubbleChartDataByPanel[u];return!e||e.length===0?l:s(q(mY,{points:e,color:r.bbColor,colorByNumeric:r.bbColorMode===`numeric`,maxRadius:r.bbMaxRadius,backgroundToken:i,onPlotContextMenu:a}),e)}case`treemap`:{let e=n.treemapDataByPanel[u]??[];return e.length===0?l:s(q(yY,{nodes:e,backgroundToken:i,onPlotContextMenu:a}),e)}case`sankey`:{let e=n.sankeyDataByPanel[u]??{nodeNames:[],links:[]};return e.links.length===0?l:s(q(TY,{nodeNames:e.nodeNames,links:e.links,backgroundToken:i,onPlotContextMenu:a}),e)}case`calibration`:{if(r?.kind!==`calibration`)return l;let e=n.calibrationDataByPanel[u]??[];return e.length===0?l:s(q(DY,{bins:e,color:r.cbColor,backgroundToken:i,onPlotContextMenu:a}),e)}case`qqplot`:{if(r?.kind!==`qqplot`)return l;let e=n.qqPlotDataByPanel[u];return!e||e.length===0?l:s(q(kY,{points:e,color:r.qqColor,backgroundToken:i,onPlotContextMenu:a}),e)}case`gauge`:{if(r?.kind!==`gauge`)return l;let e=n.gaugeDataByPanel[u]??[];if(e.length===0)return l;let t=n.liveConn??(n.liveOverlays?.length===1?n.liveOverlays[0].conn:void 0);return s(q(WY,{gauges:e,live:t?{latestT:()=>t.source.latestTimeSync(),valueAt:(e,n)=>t.source.xAtTimeSync(e,n,!0)}:void 0,backgroundToken:i,onPlotContextMenu:a}),e)}case`gantt`:{let e=n.ganttDataByPanel[u]??[];return e.length===0?l:s(q(PY,{tasks:e,backgroundToken:i,onPlotContextMenu:a}),e)}}return l}var nZ=500,rZ=1e3;function iZ(e){if(Array.isArray(e))return aZ(e);if(!e||typeof e!=`object`)return null;let t=-1;for(let n of Object.values(e))Array.isArray(n)&&(t=Math.max(t,aZ(n)));return t<0?null:t}function aZ(e){let t=e=>!!e&&typeof e==`object`&&e.x instanceof Float64Array;return e.length>0&&t(e[0])?e.reduce((e,n)=>e+(t(n)?n.length:0),0):e.length}function oZ(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e4?`${Math.round(e/1e3)}k`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function sZ({stats:e,host:t}){let[n,r]=ft(null);if(W(()=>{let n=t.current?.ownerDocument.defaultView??window,i=0,a=0,o=0,s=-1,c=-1,l=e.renders,u=t.current?CH(t.current):0,d=f=>{c>=0&&f-s>rZ&&(c=f,s=f,a=0,o=0,l=e.renders,u=t.current?CH(t.current):0),c<0?(c=f,s=f):f!==s&&(o=Math.max(o,f-s),s=f,a++);let p=f-c;if(p>=nZ){let i=t.current,s=0;if(i)for(let e of i.getElementsByTagName(`canvas`))s+=e.width*e.height;let d=n.performance.memory,m=i?CH(i):0;r({fps:a*1e3/p,repaints:(m-u)*1e3/p,worstFrameMs:o,renderMs:e.lastRenderMs,rendersPerSec:(e.renders-l)*1e3/p,points:iZ(e.data),domNodes:i?i.getElementsByTagName(`*`).length:0,canvasMp:s/1e6,heapMb:d?d.usedJSHeapSize/1048576:null}),a=0,o=0,c=f,l=e.renders,u=m}i=n.requestAnimationFrame(d)};return i=n.requestAnimationFrame(d),()=>n.cancelAnimationFrame(i)},[e,t]),!n)return null;let i=n.fps<20?`var(--danger, #e5484d)`:n.fps<45?`var(--accent, #f5a524)`:void 0;return q(`dl`,{className:`kymo-perf-hud`,style:cZ,children:[[`FPS`,n.fps.toFixed(0),i],[`Repaints/s`,n.repaints.toFixed(0)],[`Slowest frame`,`${n.worstFrameMs.toFixed(1)} ms`],[`Render`,`${n.renderMs.toFixed(1)} ms`],[`Renders/s`,n.rendersPerSec.toFixed(1)],...n.points===null?[]:[[`Points`,oZ(n.points)]],[`DOM nodes`,oZ(n.domNodes)],[`Canvas`,`${n.canvasMp.toFixed(2)} MP`],...n.heapMb===null?[]:[[`JS heap`,`${n.heapMb.toFixed(0)} MB`]]].map(([e,t,n])=>_t(`div`,{style:lZ,children:[q(`dt`,{style:uZ,children:e}),q(`dd`,{style:n?{...dZ,color:n}:dZ,children:t})]},e))})}var cZ={position:`absolute`,top:8,right:8,zIndex:60,flex:`none`,pointerEvents:`none`,userSelect:`none`,margin:0,padding:`6px 9px`,minWidth:148,display:`grid`,gap:1,font:`500 10.5px/1.35 var(--font-sans, system-ui)`,fontVariantNumeric:`tabular-nums`,fontFeatureSettings:`"tnum" 1`,color:`var(--text-strong, #f3f5fa)`,background:`color-mix(in oklch, var(--bg-elevated, #1b2130) 86%, transparent)`,border:`1px solid var(--border, #33405a)`,borderRadius:6,boxShadow:`0 4px 14px color-mix(in oklch, black 28%, transparent)`},lZ={display:`flex`,justifyContent:`space-between`,gap:12},uZ={color:`var(--text-muted, #8a93a6)`},dZ={margin:0,fontWeight:600,textAlign:`right`},fZ=[],pZ=3,mZ=`data-kymo-annotation-controls`;function hZ(e,t,n,r){return e.anchor===`x`&&!r?null:e.points.map(([i,a])=>[e.anchor===`x`?qH(r,i):i*t,a*n])}function gZ(e,t,n,r,i){return t.map(([t,a])=>[e.anchor===`x`&&i?JH(i,t):_Z(t/Math.max(1,n)),_Z(a/Math.max(1,r))])}var _Z=e=>Math.round(e*1e4)/1e4,vZ=ot(function({annotations:e,tool:t,plotFrame:n,onChange:r,onToolEnd:i,onSelect:a,marks:o=fZ,onMarkSelect:s}){let c=K(null),l=pt(n.subscribe,n.get),u=l?.x?l:null,[d,f]=ft({w:0,h:0}),[p,m]=ft(null),[h,g]=ft(null),[_,v]=ft(null),y=K({annotations:e,onChange:r,onToolEnd:i,onSelect:a,tool:t,selected:p,editing:h,frame:u,size:d});y.current={annotations:e,onChange:r,onToolEnd:i,onSelect:a,tool:t,selected:p,editing:h,frame:u,size:d};let b=e=>{y.current.selected!==e&&(y.current.selected=e,m(e),y.current.onSelect(e))};G(()=>{let e=c.current;if(!e)return;let t=e.ownerDocument.defaultView??window,n=()=>f({w:e.clientWidth,h:e.clientHeight});n();let r=new t.ResizeObserver(n);return r.observe(e),()=>r.disconnect()},[]),W(()=>{t&&b(null)}),W(()=>{p&&!e.some(e=>e.id===p)&&b(null)}),W(()=>()=>{y.current.selected&&y.current.onSelect(null)},[]),W(()=>{let e=c.current?.ownerDocument;if(!e)return;let t=e=>{let{selected:t,editing:n,tool:r,annotations:i,onChange:a,onToolEnd:o}=y.current;if(!(n||DZ(e.target))){if(e.key===`Escape`&&r){o();return}t&&(e.key===`Delete`||e.key===`Backspace`?(e.preventDefault(),a(i.filter(e=>e.id!==t)),b(null)):e.key===`Escape`&&b(null))}},n=e=>{let t=y.current.selected,n=e.target;t&&!n?.closest?.(`[data-ann-id="${CSS.escape(t)}"], [data-kymo-annotation-controls]`)&&b(null)};return e.addEventListener(`keydown`,t),e.addEventListener(`pointerdown`,n,!0),()=>{e.removeEventListener(`keydown`,t),e.removeEventListener(`pointerdown`,n,!0)}},[]);let{w:x,h:S}=d,C=e=>{let t=c.current.getBoundingClientRect();return[e.clientX-t.left,e.clientY-t.top]},w=(e,t)=>{let n=c.current.ownerDocument,r=t=>e(C(t),t),i=()=>{n.removeEventListener(`pointermove`,r),n.removeEventListener(`pointerup`,i),n.removeEventListener(`pointercancel`,i),t()};n.addEventListener(`pointermove`,r),n.addEventListener(`pointerup`,i),n.addEventListener(`pointercancel`,i)},T=e=>r([...y.current.annotations,e]),E=e=>r(y.current.annotations.map(t=>t.id===e.id?e:t)),D=e=>{if(!t||e.button!==0||h)return;e.preventDefault(),e.stopPropagation();let n=C(e),r={id:crypto.randomUUID(),kind:t.kind,color:t.color,width:t.width,...u?{anchor:`x`}:{}},i=e=>gZ(r,e,x,S,u);if(t.kind===`text`){v({...r,points:i([n]),text:``}),g(r.id);return}let a=t.kind===`brush`?[n]:[n,n],o={...r,points:i(a)};v(o);let s=!1;w((t,n)=>{if(s||=Math.hypot(n.clientX-e.clientX,n.clientY-e.clientY)>pZ,r.kind===`brush`){let e=a[a.length-1];if(Math.hypot(t[0]-e[0],t[1]-e[1])<2)return;a=[...a,t]}else a=[a[0],t];o={...o,points:i(a)},v(o)},()=>{v(null),s&&o.points.length>=2&&T(o)})},O=(e,t,n)=>{let r=hZ(t,x,S,u);if(!r)return;let i=C(e),a=null;w((o,s)=>{if(!a&&Math.hypot(s.clientX-e.clientX,s.clientY-e.clientY)<=pZ)return;let{size:c,frame:l}=y.current;a={...t,points:gZ(t,n(r,[o[0]-i[0],o[1]-i[1]],o),c.w,c.h,l)},v(a)},()=>{v(null),a&&E(a)})},k=(e,n)=>{t||e.button!==0||h===n.id||(e.preventDefault(),e.stopPropagation(),b(n.id),O(e,n,(e,[t,n])=>e.map(([e,r])=>[e+t,r+n])))},A=(e,t,n)=>{e.button===0&&(e.preventDefault(),e.stopPropagation(),O(e,t,(e,r,i)=>{let a=e.map(e=>[...e]);return t.kind===`arrow`?a[n]=i:(a[+(n===1||n===2)][0]=i[0],a[+(n===2||n===3)][1]=i[1]),a}))},j=e=>{t||e.kind!==`text`&&e.kind!==`box`||(b(e.id),g(e.id))},M=e=>{let t=h;g(null);let n=_&&_.id===t?_:null;if(v(null),e===null||!t)return;let i=e.replace(/\s+$/,``),a=y.current.annotations;if(n){i&&T({...n,text:i});return}let o=a.find(e=>e.id===t);o&&(!i&&o.kind===`text`?r(a.filter(e=>e.id!==t)):E(EZ(o,i)))},N=e=>{r(y.current.annotations.filter(t=>t.id!==e)),b(null)},P=(_?e.some(e=>e.id===_.id)?e.map(e=>e.id===_.id?_:e):[...e,_]:e).flatMap(e=>{let t=hZ(e,x,S,u);return t?[{a:e,px:t}]:[]}),F=p?P.find(e=>e.a.id===p):void 0,I=u?o.map(e=>{let t=hZ(Lt(e,u.x.v1),x,S,u);return{m:e,x0:Math.min(t[0][0],t[1][0]),x1:Math.max(t[0][0],t[1][0])}}):[],L=F&&F.a.kind!==`text`?TZ(F.px):null,R=e=>_t(gt,{children:[q(`svg`,{className:`kymo-ann-svg`,width:x,height:S,viewBox:`0 0 ${x} ${S}`,"aria-hidden":`true`,children:e.map(({a:e,px:t})=>e.kind===`text`?null:q(`g`,{"data-ann-id":e.id,className:`kymo-ann kymo-ann--${e.kind}`,onPointerDown:t=>k(t,e),onDoubleClick:()=>j(e),children:q(xZ,{a:e,px:t})},e.id))}),e.map(({a:e,px:t})=>{if(e.kind!==`text`&&e.kind!==`box`)return null;let n=h===e.id;if(!n&&!e.text)return null;let r=e.kind===`text`?{left:t[0][0],top:t[0][1]}:{left:Math.min(t[0][0],t[1][0]),top:Math.min(t[0][1],t[1][1]),transform:`translateY(calc(-100% - 3px))`};return _t(`div`,{"data-ann-id":e.id,className:`kymo-ann-text kymo-ann-text--${e.kind}${p===e.id&&e.kind===`text`?` is-selected`:``}`,style:{...r,color:e.color,fontSize:e.kind===`text`?e.width:12},onPointerDown:t=>k(t,e),onDoubleClick:()=>j(e),children:[n?q(bZ,{initial:e.text??``,onDone:M}):e.text,p===e.id&&e.kind===`text`&&!n?q(yZ,{onDelete:()=>N(e.id),style:{right:-11,top:-11}}):null]},`t-${e.id}`)})]});return q(`div`,{ref:c,className:`kymo-annotations${t?` is-drawing is-tool-${t.kind}`:``}`,onPointerDown:D,onContextMenu:t?e=>e.preventDefault():void 0,children:x>0&&S>0?_t(gt,{children:[u&&I.length?q(`div`,{className:`kymo-ann-clip`,style:{clipPath:`inset(0 ${Math.max(0,x-u.left-u.width)}px 0 ${Math.max(0,u.left)}px)`},children:q(`svg`,{className:`kymo-ann-svg kymo-marks`,width:x,height:S,viewBox:`0 0 ${x} ${S}`,children:I.map(({m:e,x0:t,x1:n})=>_t(`g`,{"data-mark":e.ruleId,role:`img`,"aria-label":`${e.ruleName}, ${e.severity}`,className:`kymo-mark kymo-mark--${e.severity}`,style:{color:It[e.severity]},children:[q(`rect`,{x:t,y:u.top,width:Math.max(1,n-t),height:u.height,fill:`currentColor`,fillOpacity:.12}),q(`rect`,{x:t,y:u.top,width:Math.max(1,n-t),height:2,fill:`currentColor`}),q(`rect`,{className:`kymo-mark-hit`,x:t,y:u.top,width:Math.max(6,n-t),height:8,onPointerDown:t=>{t.stopPropagation(),s?.(e.ruleId)}})]},e.id))})}):null,R(P.filter(e=>e.a.anchor!==`x`)),u?q(`div`,{className:`kymo-ann-clip`,style:{clipPath:`inset(0 ${Math.max(0,x-u.left-u.width)}px 0 ${Math.max(0,u.left)}px)`},children:R(P.filter(e=>e.a.anchor===`x`))}):null,_t(`svg`,{className:`kymo-ann-svg`,width:x,height:S,viewBox:`0 0 ${x} ${S}`,"aria-hidden":`true`,children:[L?q(`rect`,{className:`kymo-ann-selection`,x:L.x-6,y:L.y-6,width:L.w+12,height:L.h+12,rx:4}):null,F&&!h&&(F.a.kind===`box`||F.a.kind===`arrow`)?q(`g`,{"data-ann-id":F.a.id,children:SZ(F.a,F.px).map(([e,t],n)=>q(`rect`,{className:`kymo-ann-handle kymo-ann-handle--${F.a.kind===`arrow`?`end`:n%2?`nesw`:`nwse`}`,x:e-4.5,y:t-4.5,width:9,height:9,rx:2,onPointerDown:e=>A(e,F.a,n)},n))}):null]}),L&&!h?q(yZ,{onDelete:()=>N(F.a.id),id:F.a.id,style:{left:Math.min(x-12,L.x+L.w+6)-10,top:Math.max(10,L.y-6)-10}}):null]}):null})});function yZ({onDelete:e,style:t,id:n}){return q(`button`,{type:`button`,className:`kymo-ann-delete`,style:t,"data-ann-id":n,"aria-label":`Delete annotation`,title:`Delete (Del)`,onPointerDown:e=>e.stopPropagation(),onClick:e,children:q(`svg`,{viewBox:`0 0 10 10`,width:`8`,height:`8`,"aria-hidden":`true`,children:q(`path`,{d:`M2 2l6 6M8 2l-6 6`})})})}function bZ({initial:e,onDone:t}){let n=K(null),r=K(!1),i=e=>{r.current||(r.current=!0,t(e))};return G(()=>{let t=n.current;if(!t)return;t.textContent=e,t.focus();let r=t.ownerDocument.createRange();r.selectNodeContents(t);let i=t.ownerDocument.defaultView?.getSelection();i?.removeAllRanges(),i?.addRange(r)},[]),q(`div`,{ref:n,className:`kymo-ann-editor`,contentEditable:`plaintext-only`,suppressContentEditableWarning:!0,role:`textbox`,"aria-label":`Annotation text`,"aria-multiline":`true`,onPointerDown:e=>e.stopPropagation(),onKeyDown:e=>{e.stopPropagation(),e.key===`Enter`&&!e.shiftKey?(e.preventDefault(),i(n.current?.innerText??``)):e.key===`Escape`&&(e.preventDefault(),i(null))},onBlur:()=>i(n.current?.innerText??``)})}function xZ({a:e,px:t}){let n={stroke:e.color,strokeWidth:e.width,fill:`none`,strokeLinecap:`round`,strokeLinejoin:`round`},r=t=>q(`path`,{className:`kymo-ann-hit`,d:t,strokeWidth:Math.max(12,e.width+10)});switch(e.kind){case`box`:{let[[i,a],[o,s]]=t,c=`M${i} ${a}H${o}V${s}H${i}Z`;return _t(gt,{children:[r(c),q(`path`,{d:c,...n}),q(`path`,{d:c,fill:e.color,fillOpacity:.06,stroke:`none`,pointerEvents:`none`})]})}case`arrow`:{let[[i,a],[o,s]]=t,c=wZ(i,a,o,s,e.width);return _t(gt,{children:[r(`M${i} ${a}L${o} ${s}`),q(`path`,{d:`M${i} ${a}L${c.base[0]} ${c.base[1]}`,...n}),q(`path`,{d:c.d,fill:e.color,stroke:e.color,strokeWidth:1,strokeLinejoin:`round`})]})}case`brush`:{let e=CZ(t);return _t(gt,{children:[r(e),q(`path`,{d:e,...n})]})}}return null}function SZ(e,t){if(e.kind===`arrow`)return t;let[[n,r],[i,a]]=t;return[[n,r],[i,r],[i,a],[n,a]]}function CZ(e){if(e.length===0)return``;if(e.length<3)return`M${e[0][0]} ${e[0][1]}`+e.slice(1).map(([e,t])=>`L${e} ${t}`).join(``);let t=`M${e[0][0]} ${e[0][1]}`;for(let n=1;n<e.length-1;n++){let[r,i]=e[n],[a,o]=e[n+1];t+=`Q${r} ${i} ${(r+a)/2} ${(i+o)/2}`}let[n,r]=e[e.length-1];return t+`L${n} ${r}`}function wZ(e,t,n,r,i){let a=Math.max(9,i*4),o=Math.atan2(r-t,n-e),s=.42,c=[n-a*Math.cos(o-s),r-a*Math.sin(o-s)],l=[n-a*Math.cos(o+s),r-a*Math.sin(o+s)],u=[n-a*.8*Math.cos(o),r-a*.8*Math.sin(o)];return{d:`M${n} ${r}L${c[0]} ${c[1]}L${l[0]} ${l[1]}Z`,base:u,l:c,r:l}}function TZ(e){let t=e.map(e=>e[0]),n=e.map(e=>e[1]),r=Math.min(...t),i=Math.min(...n);return{x:r,y:i,w:Math.max(...t)-r,h:Math.max(...n)-i}}function EZ(e,t){if(t)return{...e,text:t};let{text:n,...r}=e;return r}function DZ(e){let t=e;return!!t&&(t.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName))}function OZ(e,t,n,r,i,a,o){e.save(),e.scale(i,i),e.lineCap=`round`,e.lineJoin=`round`;for(let i of t){let t=hZ(i,n,r,o);t&&(e.save(),i.anchor===`x`&&o&&(e.beginPath(),e.rect(o.left,0,o.width,r),e.clip()),kZ(e,i,t,a),e.restore())}e.restore()}function kZ(e,t,n,r){if(e.strokeStyle=t.color,e.fillStyle=t.color,e.lineWidth=t.width,t.kind===`box`)e.strokeRect(n[0][0],n[0][1],n[1][0]-n[0][0],n[1][1]-n[0][1]);else if(t.kind===`brush`)e.stroke(new Path2D(CZ(n)));else if(t.kind===`arrow`){let r=wZ(n[0][0],n[0][1],n[1][0],n[1][1],t.width);e.beginPath(),e.moveTo(n[0][0],n[0][1]),e.lineTo(r.base[0],r.base[1]),e.stroke(),e.beginPath(),e.moveTo(n[1][0],n[1][1]),e.lineTo(r.l[0],r.l[1]),e.lineTo(r.r[0],r.r[1]),e.closePath(),e.fill()}if(!t.text)return;let i=t.kind===`text`?t.width:12;e.font=`600 ${i}px ${r}`,e.textBaseline=`top`;let a=t.text.split(`
614
- `),o=i*1.25,s=n[0][0],c=n[0][1];t.kind===`box`&&(s=Math.min(n[0][0],n[1][0]),c=Math.min(n[0][1],n[1][1])-a.length*o-7),a.forEach((t,n)=>e.fillText(t,s+6,c+2+n*o))}var AZ={solid:void 0,dashed:`5 4`,dotted:`1 4`};function jZ(e,t,n){if(!e||!(n===`x`?e.x:e.y))return null;if(n===`x`){let n=qH(e,t.value);return n>=e.left-.5&&n<=e.left+e.width+.5?[n,e.top,n,e.top+e.height]:null}let r=YH(e,t.value);return r>=e.top-.5&&r<=e.top+e.height+.5?[e.left,r,e.left+e.width,r]:null}var MZ=ot(function({frame:e,alarm:t,axis:n}){let r=jZ(pt(e.subscribe,e.get),t,n);if(!r)return null;let i=t.linked?NZ(r,n):null;return _t(`svg`,{className:`kymo-alarm`,"aria-hidden":`true`,children:[q(`line`,{x1:r[0],y1:r[1],x2:r[2],y2:r[3],stroke:t.color,strokeWidth:t.width,strokeDasharray:t.linked===`active`?nU.join(` `):AZ[t.style]}),i?q(`path`,{"data-alert-glyph":``,d:tU,transform:`translate(${i[0]} ${i[1]})`,fill:t.color}):null]})});function NZ(e,t){return t===`y`?[e[2]-10-3,e[1]-10-2]:[e[0]+3,e[1]+2]}function PZ(e,t,n,r,i){let a=jZ(t,n,r);if(a){if(e.save(),e.scale(i,i),e.strokeStyle=n.color,e.lineWidth=n.width,e.setLineDash(n.linked===`active`?nU:AZ[n.style]?.split(` `).map(Number)??[]),e.beginPath(),e.moveTo(a[0],a[1]),e.lineTo(a[2],a[3]),e.stroke(),n.linked){let t=NZ(a,r);iU(e,t[0],t[1],n.color)}e.restore()}}function FZ(e,t,n){return e.handlers?.wsId===n?e.handlers:e.handlers={wsId:n,onViewXRangeChange:r=>{t.view.setXRange(r,n),e.emitter.emit(`viewchange`,r)},onCursorX:e=>{try{t.view.setCursorX(e,n)}catch{}},cursor:{get:()=>{try{return t.view.cursorX(n)}catch{return null}},subscribe:e=>t.on(`cursorchange`,t=>{t.worksheetId===n&&e(t.x)})},onContextMenu:t=>e.emitter.emit(`contextmenu`,t),xyzRef:t=>{e.xyz=t},onAnnotations:n=>t.charts.setAnnotations(e.chartId,n),onAnnotationToolEnd:()=>{e.annotationTool=null,BZ(t).bump(),e.emitter.emit(`annotationtool`,null)},onAnnotationSelect:t=>{e.selectedAnnotation=t,e.emitter.emit(`annotationselect`,t)},onMarkSelect:t=>e.emitter.emit(`markselect`,t)}}var IZ=new WeakMap;function LZ(e,t){let n=IZ.get(e);n||IZ.set(e,n=new Map);let r=n.get(t);return r||n.set(t,r=n=>e.view.setLiveWindow(n,t)),r}var RZ=class{mounts=new Map;version=0;listeners=new Set;root=null;engine;constructor(e){this.engine=e}subscribe=e=>(this.listeners.add(e),()=>{this.listeners.delete(e)});getVersion=()=>this.version;bump(){this.version++;for(let e of[...this.listeners])e()}add(e){this.mounts.set(e.key,e),this.root||(this.root=ht(document.createElement(`div`)),this.root.render(q(KZ,{engine:this.engine,registry:this}))),this.bump()}remove(e){this.mounts.delete(e)&&this.bump()}refresh(){this.bump()}dispose(){this.mounts.clear(),this.root?.unmount(),this.root=null}},zZ=new WeakMap;function BZ(e){let t=zZ.get(e);return t||(t=new RZ(e),zZ.set(e,t)),t}function VZ(e,t,n,r={}){e.charts.get(t);let i=BZ(e),a={key:crypto.randomUUID(),chartId:t,element:n,options:r,shiftDatasetId:null,emitter:RV(),xyz:null,annotationTool:null,selectedAnnotation:null,plotFrame:QH(),status:null,data:null};i.add(a);let o=!1;return{chartId:t,status:()=>a.status,data:()=>a.data,on:(e,t)=>a.emitter.on(e,t),exportPng(){let r=Array.from(n.querySelectorAll(`canvas`));if(r.length===0)return Promise.reject(new kE(`export_failed`,{reason:`nothing to export`}));let i=document.createElement(`canvas`);i.width=r[0].width,i.height=r[0].height;let o=i.getContext(`2d`);if(!o)return Promise.reject(new kE(`export_failed`,{reason:`canvas unavailable`}));for(let e of r)o.drawImage(e,0,0);let s=e.charts.get(t),c=nQ(s.settings,i1(e).alertLines()),l=a.plotFrame.get()?.x?a.plotFrame.get():null,u=e.getState(),d=u.worksheets.find(e=>e.charts.some(e=>e.id===t)),f=aQ(s.annotations,d?rQ(u.marks,u.selection,d.xKey):[],l),p=tr(c);return p&&n.clientWidth>0&&PZ(o,a.plotFrame.get(),p.alarm,p.axis,i.width/n.clientWidth),f.length&&n.clientWidth>0&&OZ(o,f,n.clientWidth,n.clientHeight,i.width/n.clientWidth,Q.sans,l),new Promise((e,t)=>i.toBlob(n=>n?e(n):t(new kE(`export_failed`,{reason:`encode failed`})),`image/png`))},autoscale(){a.xyz?.autoscale()},setShiftMode(e){a.shiftDatasetId!==e&&(a.shiftDatasetId=e,i.bump())},setAnnotationTool(e){a.annotationTool=e?{...e}:null,i.bump()},annotationTool:()=>a.annotationTool,selectedAnnotation:()=>a.selectedAnnotation,setOptions(e){a.options={...e},i.bump()},destroy(){o||(o=!0,a.emitter.clear(),i.remove(a.key))}}}function HZ(e){zZ.get(e)?.refresh()}function UZ(e){zZ.get(e)?.dispose(),zZ.delete(e)}function WZ(e){let t=new MutationObserver(e);return t.observe(document.documentElement,{attributes:!0,attributeFilter:[`data-color-scheme`,`class`,`data-theme`]}),()=>t.disconnect()}var GZ=()=>{let e=document.documentElement;return`${e.getAttribute(`data-color-scheme`)??``}|${e.getAttribute(`data-theme`)??``}|${e.className}`};function KZ({engine:e,registry:t}){pt(t.subscribe,t.getVersion);let n=i1(e),r=pt(n.store.subscribe,n.store.get),i=new Map;for(let e of t.mounts.values()){let t=r.worksheets.find(t=>t.panels.some(t=>t.id===e.chartId));if(!t)continue;let n=i.get(t.id)??{worksheet:t,mounts:[]};n.mounts.push(e),i.set(t.id,n)}return q(gt,{children:[...i.values()].map(t=>q(XZ,{engine:e,worksheet:t.worksheet,mounts:t.mounts},t.worksheet.id))})}var qZ=1e3,JZ=.25;function YZ(e,t,n){let[r,i]=ft(0),a=K(0),o=K(0);return W(()=>{a.current&&=(o.current=performance.now()-a.current,0)}),W(()=>{if(!n)return;let r=0,s=-1,c=0,l=n=>{if(r=yH(l),a.current||n<c||wH())return;let u=0;for(let n of e)t.includes(n.id)&&(u+=n.source.version());u!==s&&(s=u,c=n+o.current*(1/JZ-1),a.current=performance.now(),st(()=>i(e=>e+1)))};return r=yH(l),()=>bH(r)},[n,e,t]),dt(()=>n?e.map(e=>t.includes(e.id)?{...e,dataset:e.source.snapshot(qZ)}:e):e,[e,t,n,r])}function XZ({engine:e,worksheet:t,mounts:n}){let r=i1(e),i=pt(r.store.subscribe,r.store.get),a=r.derived(),o=i.xRanges[t.id]??null,s=dt(()=>i.live.filter(e=>e.kind===`data`),[i.live]),c=a.selectedLive.length,l=e=>{let n=t.panelChartSettings[e];return n?.kind===`multiband`&&n.beacon?.enabled===!0},u=c>0&&t.panels.some(e=>e.kind!==`multiband`&&e.kind!==`camera`||c>1&&!l(e.id)),d=YZ(s,i.selection,u),f=r.alertLines(),p=ZX({worksheet:eQ(t,f),viewXRange:o,selectedIds:i.selection,selectedDatasets:a.selectedDatasets,liveConnections:d,mathChannels:a.channels,datasetOffsets:i.offsets,datasetColors:i.colors,datasetPalette:i.palette}),m=K(IV()).current,h=pt(WZ,GZ),g=t.id,_=LZ(e,g),v=i.licensed,y=a.selectedLive[0]??null,b=e=>i.datasets.find(t=>t.id===e)??Object.values(a.laps).flatMap(e=>e.laps).find(t=>t.id===e);return q(gt,{children:n.map(n=>{let r=t.panels.find(e=>e.id===n.chartId);if(!r)return null;let s=n.shiftDatasetId?a.selectedDatasets.find(e=>e.id===n.shiftDatasetId):void 0,c=FZ(n,e,g),l=nQ(t.panelChartSettings[r.id],f);return mt(q(lQ,{mount:n,annotations:t.panelChartSettings[r.id]?.annotations,marks:rQ(i.marks,i.selection,t.xKey),onMarkSelect:c.onMarkSelect,alarm:tr(l),onAnnotations:c.onAnnotations,onAnnotationToolEnd:c.onAnnotationToolEnd,onAnnotationSelect:c.onAnnotationSelect,render:u=>tZ({panel:r,settings:l,background:n.options.style?.background??t.panelChartBackgrounds[r.id]??null,styleToken:JSON.stringify([h,n.options.theme,n.options.style,Q]),data:p,xKey:t.xKey,height:u,viewXRange:o,onViewXRangeChange:c.onViewXRangeChange,onCursorX:c.onCursorX,liveZoom:m,liveWindowSeconds:t.liveWindowSeconds===void 0?i.liveWindowSeconds:t.liveWindowSeconds,onLiveWindowChange:_,beaconLive:y,findDataset:b,live:i.live,selection:i.selection,cursor:c.cursor,video:e.video.sources(),recordings:oX(a.selectedDatasets,i.offsets),shiftMode:s?ZZ(e,s.id,s.name):void 0,onContextMenu:c.onContextMenu,xyzRef:c.xyzRef}),licensed:v},n.key),n.element,n.key)})})}function ZZ(e,t,n){let r=0;return{label:n,onDragStart:()=>{r=e.getState().datasets.find(e=>e.id===t)?.offset??0},onDragOffset:n=>e.datasets.setOffset(t,r+n)}}var QZ=[],$Z=new WeakMap;function eQ(e,t){if(!t.size)return e;let n=$Z.get(e);if(n&&n.lines===t)return n.out;let r=!1,i={};for(let[n,a]of Object.entries(e.panelChartSettings))i[n]=nQ(a,t),i[n]!==a&&(r=!0);let a=r?{...e,panelChartSettings:i}:e;return $Z.set(e,{lines:t,out:a}),a}var tQ=new WeakMap;function nQ(e,t){if(!e||!t.size)return e;let n=tQ.get(e);if(n&&n.lines===t)return n.out;let r=$n(e,t);return tQ.set(e,{lines:t,out:r}),r}var rQ=oQ((e,t,n)=>{let r=e.filter(e=>e.timeColumn===n&&t.includes(e.targetId));return r.length?r:iQ}),iQ=[];function aQ(e,t,n){return!t.length||!n?.x?e:[...t.map(e=>Lt(e,n.x.v1)),...e]}function oQ(e){let t=null,n;return(r,i,a)=>t&&t[0]===r&&t[1]===i&&t[2]===a?n:(t=[r,i,a],n=e(r,i,a),n)}function sQ(e,t){e.data=t}function cQ(e,t){e.status!==t&&(e.status=t,e.emitter.emit(`status`,t))}function lQ({mount:e,render:t,licensed:n,annotations:r,marks:i,alarm:a,onAnnotations:o,onAnnotationToolEnd:s,onAnnotationSelect:c,onMarkSelect:l}){let u=K(null),[d,f]=ft(0),p=!!e.options.debug,m=K({renderStart:0,lastRenderMs:0,renders:0,data:null}).current;p&&(m.renderStart=performance.now()),G(()=>{p&&(m.lastRenderMs=performance.now()-m.renderStart,m.renders++)}),G(()=>{let e=u.current;if(!e)return;let t=()=>f(Math.max(120,Math.floor(e.clientHeight)));t();let n=new TH(t);return n.observe(e),()=>n.disconnect()},[]);let{status:h,node:g,data:_}=t(d||400);m.data=_,W(()=>{sQ(e,_)}),W(()=>{cQ(e,h)});let{theme:v,style:y,className:b}=e.options,x={};return y?.background&&(x[`--chart-bg`]=y.background),y?.muted&&(x[`--chart-muted`]=y.muted),y?.grid&&(x[`--chart-grid`]=y.grid),y?.accent&&(x[`--accent`]=y.accent),_t(`div`,{ref:u,onContextMenu:h===`ready`?void 0:t=>{t.preventDefault(),e.emitter.emit(`contextmenu`,{clientX:t.clientX,clientY:t.clientY})},className:b?`kymo-chart ${b}`:`kymo-chart`,"data-color-scheme":v,"data-status":h,style:x,children:[q($H.Provider,{value:e.plotFrame.set,children:g}),h===`ready`&&a?q(MZ,{frame:e.plotFrame,alarm:a.alarm,axis:a.axis}):null,h===`ready`&&(r?.length||e.annotationTool||i.length)?q(vZ,{annotations:r??QZ,tool:e.annotationTool,plotFrame:e.plotFrame,onChange:o,onToolEnd:s,onSelect:c,marks:i,onMarkSelect:l}):null,p?q(sZ,{stats:m,host:u}):null,n===!1?q(LV,{}):null]})}var uQ=new WeakMap;function dQ(e,t,n,r={}){let i=uQ.get(e)??new Map;uQ.set(e,i);let a=i.get(t);if(a&&!a.window.closed)return a.window.focus(),a;let o=e.charts.get(t),s=r.title??(o.title||e.charts.label(o.kind)),c=window.open(``,`kymoscope-chart-${t}`,`popup,width=${r.width??960},height=${r.height??600}`);if(!c)throw new kE(`popup_blocked`,{chartId:t});let l=c.document;l.head.replaceChildren(),l.body.replaceChildren(),l.title=s;for(let e of document.querySelectorAll(`style, link[rel="stylesheet"]`)){let t=e.cloneNode(!0);t instanceof HTMLLinkElement&&(t.href=e.href),l.head.appendChild(t)}let u=()=>{for(let e of[...l.documentElement.attributes])l.documentElement.removeAttribute(e.name);for(let e of document.documentElement.attributes)l.documentElement.setAttribute(e.name,e.value);l.body.className=document.body.className};u();let d=new MutationObserver(u);d.observe(document.documentElement,{attributes:!0}),d.observe(document.body,{attributes:!0,attributeFilter:[`class`]}),Object.assign(l.body.style,{margin:`0`,position:`fixed`,inset:`0`,display:`flex`,flexDirection:`column`,background:getComputedStyle(document.body).backgroundColor});let f=l.createElement(`div`);f.className=`kymo-window-controls`;let p=l.createElement(`div`);p.className=`kymo-window-plot`,Object.assign(p.style,{flex:`1`,minHeight:`0`,position:`relative`}),l.body.append(f,p),mH(c);let m=n(p,r.mount),h=RV(),g=!1,_=()=>{g||(g=!0,i.delete(t),hH(c),d.disconnect(),y(),window.removeEventListener(`pagehide`,v),m.destroy(),h.emit(`close`,void 0),h.clear())},v=()=>b.close(),y=e.subscribe(()=>{try{e.charts.get(t)}catch{b.close()}});c.addEventListener(`pagehide`,_),window.addEventListener(`pagehide`,v);let b={chartId:t,window:c,controls:f,view:m,close(){_(),c.closed||c.close()},on:(e,t)=>h.on(e,t)};return i.set(t,b),b}function fQ(e){for(let t of[...uQ.get(e)?.values()??[]])t.close()}function pQ(e,t,n=!1){let r=0,i=e.length;for(;r<i;){let a=r+i>>>1;(n?e[a]<=t:e[a]<t)?r=a+1:i=a}return r}function mQ(e,t,n){if(n<=t)return null;if(t===0&&n===e.t.length)return e;let r=e=>new Map([...e].map(([e,r])=>[e,r.subarray(t,n)])),i=r(e.lo);return{t:e.t.subarray(t,n),lo:i,hi:e.hi===e.lo?i:r(e.hi),level:e.level}}var hQ=(e,t,n)=>mQ(e,pQ(e.t,t),pQ(e.t,n,!0));function gQ(e,t,n,r){let i=[];for(let t of e){let e=mQ(t,0,pQ(t.t,n)),a=mQ(t,pQ(t.t,r,!0),t.t.length);e&&i.push(e),a&&i.push(a)}return[...i,...t]}var _Q=class{pieces;#e;#t;#n=new Map;#r=new Map;constructor(e,t={}){this.pieces=e.filter(e=>e.t.length>0).sort((e,t)=>e.t[0]-t.t[0]),this.#e=t;for(let e of this.pieces)for(let[t,n]of e.lo){let r=e.hi===e.lo?n:e.hi.get(t);if(!r)continue;let i=this.#n.get(t);i||this.#n.set(t,i=[]),i.push({t:e.t,L:n,H:r})}this.#t=[...this.#n.keys()].sort((e,t)=>e.localeCompare(t))}schemaSync(){return[{name:qe,type:`number`,unit:`s`},...this.#t.map(e=>({name:e,type:`number`,unit:this.#e[e]??``}))]}async getSchema(){return this.schemaSync()}async readColumns(e,t,n){let r=e.filter(e=>e===`ElapsedTime`||this.#n.has(e)),i=this.pieces.reduce((e,t)=>e+t.t.length,0),a=Math.max(0,Math.min(n,i-t)),o=Object.fromEntries(r.map(e=>[e,new Float64Array(a).fill(NaN)])),s=0;for(let e of this.pieces){let n=Math.max(0,t-s),i=Math.min(e.t.length,t+a-s);for(let a of r){let r=a===`ElapsedTime`?e.t:e.lo.get(a);r&&i>n&&o[a].set(r.subarray(n,i),s+n-t)}if(s+=e.t.length,s>=t+a)break}return o}getSeriesMultiSync(e,t,n){let{x0:r,x1:i}=t,a=t.xKey===`ElapsedTime`?e.filter(e=>this.#n.has(e)):[];if(!(i>r)||n<1||a.length===0)return{x0:r,bucket:0,rows:[],columns:a};let o=Math.floor(n),s=(i-r)/n,c=a.map(()=>new Float64Array(o).fill(1/0)),l=a.map(()=>new Float64Array(o).fill(-1/0));for(let e=0;e<a.length;e++){let t=c[e],n=l[e];for(let{t:c,L:l,H:u}of this.#n.get(a[e])){if(c[c.length-1]<r||c[0]>i)continue;let e=pQ(c,i,!0);for(let i=pQ(c,r);i<e;i++){let e=l[i];if(e!==e)continue;let a=Math.floor((c[i]-r)/s);a>=o&&(a=o-1),e<t[a]&&(t[a]=e),u[i]>n[a]&&(n[a]=u[i])}}}let u=[];for(let e=0;e<o;e++){let t=null;for(let n=0;n<a.length;n++)c[n][e]!==1/0&&(t??={b:e},t[`y${n}lo`]=c[n][e],t[`y${n}hi`]=l[n][e]);t&&u.push(t)}return{x0:r,bucket:s,rows:u,columns:a}}async getSeriesMulti(e,t,n){return this.getSeriesMultiSync(e,t,n)}async getSeries(e){let t=this.getSeriesMultiSync([e.column],e.viewport,e.maxPoints),n=t.rows.length,r={x:new Float64Array(n),min:new Float64Array(n),max:new Float64Array(n),first:new Float64Array(n),last:new Float64Array(n)};return t.rows.forEach((e,n)=>{r.x[n]=t.x0+(e.b+.5)*t.bucket,r.min[n]=r.first[n]=e.y0lo,r.max[n]=r.last[n]=e.y0hi}),r}xBoundsSync(e){let t=this.#r.get(e);if(t)return t;let n=1/0,r=-1/0;if(e===`ElapsedTime`)for(let e of this.pieces)n=Math.min(n,e.t[0]),r=Math.max(r,e.t[e.t.length-1]);for(let{L:t,H:i}of this.#n.get(e)??[])for(let e=0;e<t.length;e++)t[e]<n&&(n=t[e]),i[e]>r&&(r=i[e]);return t=n<=r?{x0:n,x1:r}:{x0:0,x1:0},this.#r.set(e,t),t}async xBounds(e){return this.xBoundsSync(e)}sampleRowsSync(e){let t=this.pieces.reduce((e,t)=>e+t.t.length,0),n=Math.max(1,Math.ceil(t/Math.max(1,e))),r=[],i=0,a=0;for(let e of this.pieces){let t=i-a;if(a+=e.t.length,!(t>=e.t.length))for(let a=t;a<e.t.length;a+=n,i+=n){let t={[qe]:e.t[a]};for(let[n,r]of e.lo){let e=r[a];t[n]=e===e?e:null}r.push(t)}}return r.sort((e,t)=>e[qe]-t[qe])}async dispose(){}},vQ=12e3,yQ=100;function bQ(e,t=!1){let n,r=0;if(t&&e instanceof Float64Array){n=e;let t=0,i=0,a=0,o=n.length&-4;for(let e=0;e<o;e+=4)r+=n[e]*0,t+=n[e+1]*0,i+=n[e+2]*0,a+=n[e+3]*0;for(let e=o;e<n.length;e++)r+=n[e]*0;r+=t+i+a}else{n=new Float64Array(e.length);for(let t=0;t<n.length;t++){let i=+e[t];n[t]=i,r+=i*0}}if(r===0)return u.add(n),n;for(let e=0;e<n.length;e++){let t=n[e];t-t!==0&&(n[e]=NaN)}return n}function xQ(e,t){let n=Object.keys(t.columns);if(n.length===0)throw new kE(`no_columns`);let r=t.columns[n[0]].length;if(n.some(e=>t.columns[e].length!==r))throw new kE(`column_length_mismatch`);let i=new Map(n.map(e=>[e,bQ(t.columns[e],t.transfer)])),a=SQ(e,t.name,i,t.units??{});if(t.bands){for(let e of Object.values(t.bands))if(e.lo.length!==r||e.hi.length!==r)throw new kE(`column_length_mismatch`);a.bands=Object.fromEntries(Object.entries(t.bands).map(([e,t])=>[e,{lo:Float64Array.from(t.lo),hi:Float64Array.from(t.hi)}]))}return a}function SQ(e,t,n,r,i,a){let o=[...n.keys()],s=n.get(o[0]).length,c=o.map(e=>r[e]??``),l=o.map((e,t)=>({name:e,type:`number`,unit:c[t]})),u=!!a&&a.schema.length===o.length&&a.schema.every((e,t)=>e.name===o[t]),d,f;if(u)d=a.rawText??``,f=a.parseConfig;else{let e=[o.join(`,`)];for(let t=0;t<Math.min(s,yQ);t++)e.push(o.map(e=>{let r=n.get(e)[t];return r===r?String(r):``}).join(`,`));d=e.join(`
615
- `),f=y(d)}let p={id:e,name:t,schema:l,rawText:d,parseConfig:f,fromColumns:!0};if(s>1e6){let e=new MX(n,r);return{...p,kind:`columnar`,source:e,data:{meta:``,columnNames:o,units:c,rows:e.sampleRowsSync(vQ)}}}let m={meta:``,columnNames:o,units:c,rows:Me({keys:o,length:s,values:o.map(e=>n.get(e)),text:o.map(()=>null)},i)};return{...p,kind:`memory`,source:new LE(m),data:m}}function CQ(e,t,n){let r=e.fromColumns?wQ(e):null;if(!r)throw new kE(`invalid_argument`,{reason:`only datasets added with addColumns can be written`});let i=r.values().next().value.length,a=e.columnSpares??new Map,o={};for(let e of t){let t=a.get(e);t&&t.length===i&&t!==r.get(e)?(I(t),o[e]=t):o[e]=new Float64Array(i)}n(o,Object.fromEntries(t.map(e=>[e,r.get(e)])));let s=new Map(a);for(let e of t){let t=r.get(e);t?s.set(e,t):s.delete(e)}return{...TQ(e,o,!0),columnSpares:s}}function wQ(e){if(e.source instanceof MX)return new Map(e.source.columnMap);let t=Ue(e.data.rows);return t?new Map(t.keys.map((e,n)=>[e,t.values[n]])):null}function TQ(e,t,n=!1){let r=e.fromColumns?wQ(e):null;if(!r)throw new kE(`invalid_argument`,{reason:`only datasets added with addColumns can be replaced`});let i=r;for(let e of Object.keys(t))i.set(e,bQ(t[e],n));let a=i.values().next().value.length;for(let e of i.values())if(e.length!==a)throw new kE(`column_length_mismatch`);let o=Object.fromEntries(e.schema.map(e=>[e.name,e.unit])),s=SQ(e.id,e.name,i,o,e.kind===`memory`?e.data.rows:void 0,e),c=s.schema.length===e.schema.length&&s.schema.every((t,n)=>t.name===e.schema[n].name);return{...s,schema:c?e.schema:s.schema,beacon:e.beacon,bands:e.bands}}var EQ=new WeakMap;function DQ(e){let t=e.fromColumns?wQ(e):null;if(!t)return e.rawText??``;let n=e.data.rows,r=EQ.get(n);if(r===void 0){let e=[...t.keys()],i=e.map(e=>t.get(e)),a=[e.join(`,`)],o=i[0].length;for(let e=0;e<o;e++)a.push(i.map(t=>t[e]===t[e]?String(t[e]):``).join(`,`));EQ.set(n,r=a.join(`
616
- `))}return r}function OQ(e,t){let n=new _Q(t.pieces,t.units),r=n.schemaSync();return{id:e,name:t.name,kind:`columnar`,source:n,schema:r,data:{meta:``,columnNames:r.map(e=>e.name),units:r.map(e=>e.unit),rows:n.sampleRowsSync(vQ)}}}function kQ(e){let t=e,n=new Set;return{get:()=>t,set(e){let r=e(t);if(r!==t){t=r;for(let e of[...n])try{e()}catch(e){console.error(`[kymoscope] subscriber failed`,e)}}},subscribe(e){return n.add(e),()=>{n.delete(e)}}}}function AQ(e){let t=null,n;return(...r)=>t&&t.length===r.length&&t.every((e,t)=>e===r[t])?n:(t=r,n=e(...r),n)}function jQ(){let e=AQ(e=>{let t={};for(let n of e){if(n.cut){let e=n.cut.defs.find(e=>e.id===n.cut.cycleId)?.show,r=e&&e.channel!==n.cut.timeKey?UB(e):null;t[n.id]=r?{laps:n.cut.parts,values:n.cut.found.map(e=>e.kpis?.[r]??null),unit:n.schema.find(t=>t.name===e.channel)?.unit??``,isTime:!1}:{laps:n.cut.parts,values:n.cut.found.map(e=>e.tend===null?null:e.tend-e.tstart),unit:`s`,isTime:!0};continue}if(!n.beacon||n.kind!==`memory`)continue;let{channel:e,metric:r,stat:i}=n.beacon,a=vB(n.data.rows,e);if(a.length===0)continue;let o=n.data.units[n.data.columnNames.indexOf(r)]??``;t[n.id]={laps:a.map((e,t)=>{let r={...n.data,rows:n.data.rows.slice(e.start,e.end)};return{...n,id:EB(n.id,t),name:`${n.name} · Cycle ${t+1}`,data:r,source:new LE(r)}}),values:a.map(e=>SB(n.data.rows,e,r,i)),unit:o,isTime:i===`span`&&wB(r,o)}}return t}),t=AQ((e,t,n)=>e.flatMap(e=>t[e.id]?t[e.id].laps.filter(e=>n.includes(e.id)):n.includes(e.id)?[e]:[])),n=AQ((e,t)=>e.filter(e=>e.kind===`data`&&t.includes(e.id))),r=AQ(e=>_X(e.map(e=>e.data))),i=AQ((e,t)=>t.length===0?e:_X(e?[e,...t.map(e=>e.dataset)]:t.map(e=>e.dataset))),a=AQ((e,t,n,r)=>{let i=new Set;if(e)for(let t of n.length>0?n:[e])for(let e of xX(t.columnNames,t.rows))i.add(e);for(let e of r)for(let t of e.dataset.columnNames)(t===`ElapsedTime`||e.source.hasValues(t))&&i.add(t);let a=e?e.columnNames.filter(e=>i.has(e)):[],o=t.filter(e=>e.kind!==`memory`).flatMap(e=>xz(e.schema));return[...new Set([...a,...o])]});return{lapsByDataset:e,selectedDatasets:t,selectedLive:n,staticDataset:r,mergedDataset:i,mergedParts:AQ((e,t)=>[...e.map(e=>e.data),...t.map(e=>e.dataset)]),numericColumns:AQ((e,t,n,r=[],i=[])=>{let o=a(e,t,r,i),s=new Set(o);return[...o,...n.map(e=>e.name).filter(e=>!s.has(e))]}),allColumns:AQ((e,t,n)=>[...new Set([...e?.columnNames??[],...t.filter(e=>e.kind!==`memory`).flatMap(e=>e.schema.map(e=>e.name)),...n.map(e=>e.name)])]),columnUnits:AQ((e,t)=>{let n={};e&&e.columnNames.forEach((t,r)=>{let i=e.units[r]?.trim();i&&(n[t]=i)});for(let e of t)e.units&&(n[e.name]=e.units);return n})}}var MQ=[{kind:`multiband`,label:`Multi-band`},{kind:`xyscatter`,label:`X-Y scatter`},{kind:`xyzmesh`,label:`X-Y-Z mesh`},{kind:`histogram`,label:`Histogram`},{kind:`polar`,label:`Polar`},{kind:`spectrum`,label:`Spectrum`},{kind:`boxplot`,label:`Box Plot`},{kind:`spectrogram`,label:`Spectrogram`},{kind:`heatmap`,label:`Heatmap`},{kind:`violin`,label:`Violin`},{kind:`confusion`,label:`Confusion Matrix`},{kind:`roc`,label:`ROC Curve`},{kind:`losscurve`,label:`Loss Curves`},{kind:`controlchart`,label:`Control Chart`},{kind:`parallelcoords`,label:`Parallel Coords`},{kind:`embedding`,label:`Embedding`},{kind:`flamegraph`,label:`Flame Graph`},{kind:`barchart`,label:`Bar Chart`},{kind:`radar`,label:`Radar`},{kind:`areachart`,label:`Area Chart`},{kind:`cdfchart`,label:`CDF / ECDF`},{kind:`bubblechart`,label:`Bubble Chart`},{kind:`treemap`,label:`Treemap`},{kind:`sankey`,label:`Sankey`},{kind:`calibration`,label:`Calibration Curve`},{kind:`gauge`,label:`Gauges`},{kind:`camera`,label:`Camera`},{kind:`qqplot`,label:`Q-Q Plot`},{kind:`gantt`,label:`Gantt Chart`}],NQ=new Map(MQ.map(e=>[e.kind,e.label]));function PQ(e){return NQ.get(e)??e}var FQ=`kymoscope-live.v1`,IQ=2e3,LQ=3e4,RQ=30,zQ=1e4,BQ=300,VQ=90,HQ=e=>e.startsWith(`eyJ`);function UQ(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 WQ(e,t){return`${e.replace(/\/+$/,``)}/v1/streams/${t}/watch`}function GQ(e,t,n,r){let i=null,a=null,o=null,s=!1,c=0,l=()=>{o&&=(clearTimeout(o),null)},u=(n,r)=>{l();let a=UQ(r);if(a===null)return;let c=HQ(r),d=c?Math.min(a,Date.now()/1e3+BQ):a,f=Math.min(Math.max((d-(c?VQ:RQ))*1e3-Date.now(),zQ),2**31-1);o=setTimeout(async()=>{o=null;let r=null;try{r=await e.getToken(t)}catch{r=null}if(!(s||i!==n||!r)){try{n.send(JSON.stringify({type:`auth`,token:r}))}catch{return}u(n,r)}},f)},d=()=>{if(s||a)return;let e=Math.min(LQ,IQ*2**c++)*(.75+Math.random()/2);a=setTimeout(()=>{a=null,f()},e)},f=async()=>{if(s)return;let a=null;try{a=await e.getToken(t)}catch{a=null}if(s)return;if(!a){r?.(`error`),d();return}let o=new WebSocket(WQ(e.url,t),[FQ,`bearer.${a}`]);o.binaryType=`arraybuffer`,i=o;let f=a;o.onopen=()=>{r?.(`subscribed`),u(o,f)},o.onmessage=e=>{c=0,typeof e.data!=`string`&&n(e.data)},o.onclose=()=>{i===o&&(i=null,l(),!s&&(r?.(`error`),d()))}};return f(),()=>{if(s=!0,a&&=(clearTimeout(a),null),l(),i){let e=i;i=null,e.close(1e3)}}}var KQ=960*1024,qQ=24;function JQ(e){let t=e.key&&e.fragIndex===0?new TextEncoder().encode(e.codec):new Uint8Array;if(t.length>255)throw Error(`codec string too long`);let n=e.key&&e.fragIndex===0?1+t.length:0,r=new Uint8Array(qQ+n+e.payload.length),i=new DataView(r.buffer);i.setUint8(0,1),i.setUint8(1,!!e.key|(e.last?2:0)),i.setUint8(2,1),i.setUint8(3,0),i.setFloat64(4,e.t,!0),i.setUint32(12,e.seq>>>0,!0),i.setUint16(16,e.fragIndex,!0),i.setUint16(18,e.fragCount,!0),i.setUint16(20,e.width,!0),i.setUint16(22,e.height,!0);let a=qQ;return n&&(r[a++]=t.length,r.set(t,a),a+=t.length),r.set(e.payload,a),r}function YQ(e){if(e.length<qQ||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=qQ,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)}}function XQ(e){let t=Math.max(1,Math.ceil(e.data.length/KQ)),n=[];for(let r=0;r<t;r++)n.push(JQ({key:e.key,last:r===t-1,t:e.t,seq:e.seq,fragIndex:r,fragCount:t,width:e.width,height:e.height,codec:e.codec,payload:e.data.subarray(r*KQ,Math.min(e.data.length,(r+1)*KQ))}));return n}var ZQ=class{samples=[];exact=!1;windowS;constructor(e=30){this.windowS=e}observe(e,t){if(e>1e9){this.samples=[],this.exact=!0;return}this.exact=!1;let n=t-e,r=this.samples[this.samples.length-1];for(r&&Math.abs(n-r.off)>1&&(this.samples=[]),this.samples.push({at:t,off:n});this.samples.length&&this.samples[0].at<t-this.windowS;)this.samples.shift()}quality(){return this.exact?`exact`:this.samples.length?`approx`:`none`}toWall(e,t=0){if(this.exact)return e+t/1e3;if(!this.samples.length)return null;let n=1/0;for(let e of this.samples)n=Math.min(n,e.off);return e+n+t/1e3}toStream(e,t=0){let n=this.toWall(0,t);return n===null?null:e-n}},QQ=class{#e;constructor(e){this.#e=typeof e==`function`?e:()=>e}size(){return this.#e().size}get columnNames(){return this.#e().columnNames}version(){return this.#e().version}columns(){let e=this.#e();return new $Q(new Set(e.columnNames),t=>e.mirrorColumn(t))}hasValues(e){return this.#e().hasValues(e)}snapshot(e){return this.#e().toDataset(e)}async getSchema(){let e=this.#e();return e.columnNames.map(t=>({name:t,type:`number`,unit:e.unitOf(t)}))}async getSeries(e){let t=this.#e();return $e(t.columnValues(e.viewport.xKey),t.columnValues(e.column),e.viewport.x0,e.viewport.x1,e.maxPoints)}async getSeriesMulti(e,t,n){return this.getSeriesMultiSync(e,t,n)}getSeriesMultiSync(e,t,n){return this.#e().decimateColumns(t.xKey,e,t.x0,t.x1,n)}getPointsSync(e,t,n){return this.#e().decimatePoints(t.xKey,e,t.x0,t.x1,n)}async xBounds(e){return this.xBoundsSync(e)}xBoundsSync(e){return this.#e().columnBounds(e)}xTravelSync(e,t){return this.#e().xTravel(e,t)}latestTimeSync(){return this.#e().latestTime()}xAtTimeSync(e,t,n=!1){return this.#e().xAtTime(e,t,n)}latestSync(e){return this.#e().lastValue(e)}latestValuesSync(e){let t=this.#e(),n=new Map;for(let r of e){let e=t.lastValue(r),i=t.lastKnown(r);Number.isFinite(e)?n.set(r,e):i&&n.set(r,i.v)}return n}valueBoundsSync(e){let t=this.#e().valueBounds(e),n=this.#e().lastKnown(e);if(!t&&!n)return null;let r=Math.min(t?.x0??1/0,n?.v??1/0),i=Math.max(t?.x1??-1/0,n?.v??-1/0);if(r!==i)return{min:r,max:i};let a=Math.max(.5,Math.abs(r)*.05);return{min:r-a,max:i+a}}lastKnownSync(e){return this.#e().lastKnown(e)}trackCycles(e){this.#e().trackCycles(e)}cycleSpanSync(e){return this.#e().cycleSpan(e)}decimateCycleSync(e,t,n,r,i){return this.#e().decimateCycle(e,t,n,r.x0,r.x1,i)}cyclePointsSync(e,t,n,r,i){return this.#e().decimateCyclePoints(e,t,n,r.x0,r.x1,i)}async readColumns(e,t,n){let r=this.#e(),i=new Set(r.columnNames),a={};for(let o of e)i.has(o)&&(a[o]=r.columnValues(o).slice(t,t+n));return a}async dispose(){}},$Q=class extends Map{#e;#t;constructor(e,t){super(),this.#e=e,this.#t=t}get(e){if(!super.has(e)&&this.#e.has(e)){let t=this.#t(e);t&&super.set(e,t)}return super.get(e)}has(e){return this.#e.has(e)}},e$=4096,t$=5e3,n$=class{startedAt=Date.now();n=0;capacity=e$;time=new Float64Array(e$);cols=new Map;order=[];units=new Map;timeColumn;timeUnit;constructor(e=qe,t=`s`){this.timeColumn=e,this.timeUnit=t}get rows(){return this.n}add(e){this.n===this.capacity&&this.grow();let t=this.n;this.time[t]=e.t;for(let n of e.signals){let e=this.cols.get(n.name);e||(e=new Float64Array(this.capacity).fill(NaN),this.cols.set(n.name,e),this.order.push(n.name)),n.unit&&!this.units.get(n.name)&&this.units.set(n.name,n.unit),e[t]=typeof n.value==`number`?n.value:NaN}this.n++}addColumns(e){let t=se(e,this.timeColumn),n=e.t.length;for(;this.n+n>this.capacity;)this.grow();let r=this.n,i=(e,t)=>{if(t instanceof Float64Array||t instanceof Float32Array)e.set(t,r);else for(let i=0;i<n;i++)e[r+i]=+t[i]};i(this.time,e.t);for(let n of t){let t=this.cols.get(n);t||(t=new Float64Array(this.capacity).fill(NaN),this.cols.set(n,t),this.order.push(n));let r=e.units?.[n];r&&!this.units.get(n)&&this.units.set(n,r),i(t,e.columns[n])}this.n+=n}grow(){let e=this.capacity*2,t=new Float64Array(e);t.set(this.time),this.time=t;for(let[t,n]of this.cols){let r=new Float64Array(e).fill(NaN);r.set(n),this.cols.set(t,r)}this.capacity=e}toCsvParts(){let e=[this.timeColumn,...this.order],t=[this.timeUnit,...this.order.map(e=>this.units.get(e)??``)],n=[`${e.map(r$).join(`,`)}\n${t.map(r$).join(`,`)}\n`],r=this.order.map(e=>this.cols.get(e));for(let e=0;e<this.n;e+=t$){let t=Math.min(this.n,e+t$),i=``;for(let n=e;n<t;n++){i+=String(this.time[n]);for(let e of r){let t=e[n];i+=Number.isNaN(t)?`,`:`,${t}`}i+=`
617
- `}n.push(i)}return n}};function r$(e){let t=/^[=+\-@\t\r]/.test(e)?`'${e}`:e;return/[",\n\r]/.test(t)?`"${t.replace(/"/g,`""`)}"`:t}var i$=512,a$=new WeakMap;function o$(e,t,n){let r=a$.get(e);r||a$.set(e,r=new Map);let i=r.get(t),a={start:n,values:[]};return{carry:{start:e=>{let t=i?.values[e];if(!i||!t)return 0;for(let e=Math.min(n-i.start,t.length-1);e>=0;e--){let n=t[e];if(n!==null&&Number.isFinite(n))return n}return 0},done:(e,t)=>{a.values[e]=t}},keep:()=>{r.set(t,a)}}}function s$(e,t,n){let r=e.endAbs,i=Math.max(n,e.firstAbs);if(i>=r||t.length===0)return;let a=new Set(e.columnNames);for(let n of t){if(!n.enabled)continue;let o=eE(n.formula);if(!o.ok)continue;let{identifiers:s,functions:c}=tE(o.node);if(!s.every(e=>a.has(e)))continue;let l=c.some(e=>QT.includes(e)),u=Math.max(e.firstAbs,i-(l?i$:0)),d=new Map([qe,...s].map(t=>[t,e.range(t,u,r)])),{carry:f,keep:p}=o$(e,`${n.id}|${n.formula}`,u),m=sE(n,e=>d.get(e),qe,r-u,t,f);m.status===`ok`&&(e.writeComputed(n.name,n.units,i,m.values.subarray(i-u)),p())}}function c$(e,t){e.clearComputed(),a$.delete(e),s$(e,t,e.firstAbs)}var l$=8e3,u$=131072;function d$(e,t={}){switch(e.kind){case`elapsed`:return{name:`Elapsed`,unit:`s`};case`event`:return{name:`Since ${e.channel} ${e.op} ${e.value}`,unit:`s`};case`clock`:return{name:`Time of day`,unit:`s`};default:{let n=t[e.channel]??``;return e.integral?{name:`∫${e.channel}`,unit:n?`${n}·s`:`s`}:{name:`${e.channel} since start`,unit:n}}}}var f$=new Map;function p$(e,t){let n=`${t}|${Math.floor(e/900)}`,r=f$.get(n);r===void 0&&(r=dB(e,t),f$.size>1e4&&f$.clear(),f$.set(n,r));let i=(e+r)%86400;return i<0?i+86400:i}var m$=class{axis;#e=NaN;#t=NaN;#n=NaN;#r=0;#i=NaN;#a=NaN;constructor(e){this.axis=e}begin(e){this.#e=e,this.#t=NaN,this.#n=NaN,this.#r=0,this.#i=NaN,this.#a=NaN}x(e,t){let n=this.axis;return n.kind===`clock`?p$(e,n.tz):n.kind===`elapsed`?e-this.#e:e<this.#e?NaN:n.kind===`event`?(this.#t!==this.#t&&t===t&&aB(n.op,t,n.value)&&(this.#t=e),e-this.#t):n.integral?(t===t&&(this.#i===this.#i&&(this.#r+=(t+this.#i)/2*(e-this.#a)),this.#i=t,this.#a=e),this.#i===this.#i?this.#r:NaN):(t===t&&(this.#n!==this.#n&&(this.#n=t),this.#i=t),this.#i===this.#i?this.#i-this.#n:NaN)}};function h$(e,t,n,r){let i=`channel`in r?t.get(r.channel):void 0;if(r.kind===`event`){let a=NaN;for(let t=0;t<e.length&&a!==a;t++){let o=i?i[t]:NaN;e[t]>=n&&o===o&&aB(r.op,o,r.value)&&(a=e[t])}return{x:e.map(e=>e-a),t:e,cols:t}}let a=new m$(r);a.begin(n);let o=new Float64Array(e.length);for(let t=0;t<e.length;t++)o[t]=a.x(e[t],i?i[t]:NaN);return{x:o,t:e,cols:t}}function g$(e,t,n){let r=[];for(let n=0;n<e.length;n++)e[n]===e[n]&&t[n]===t[n]&&r.push(n);let i=!0;for(let t=1;t<r.length&&i;t++)i=e[r[t-1]]<=e[r[t]];i||r.sort((t,n)=>e[t]-e[n]);let a=r.length,o=new Float64Array(n.length).fill(NaN);if(a<2)return o;let s=Float64Array.from(r,t=>e[t]),c=Float64Array.from(r,e=>t[e]),l=Float64Array.from({length:a-1},(e,t)=>s[t+1]-s[t]).sort(),u=l[l.length>>1],d=u>0?4*u:1/0,f=0;for(let e=0;e<n.length;e++){let t=n[e];if(!(t>=s[0]&&t<=s[a-1]))continue;for(;f<a-2&&s[f+1]<t;)f++;let r=s[f],i=s[f+1];i-r>d||(o[e]=i===r?c[f]:c[f]+(c[f+1]-c[f])*(t-r)/(i-r))}return o}function _$(e,t,n){let r=e.length;if(r===0||!(n>=e[0]&&n<=e[r-1]))return NaN;if(r===1)return t[0];let i=(n-e[0])/(e[r-1]-e[0])*(r-1),a=Math.min(r-2,Math.floor(i));return t[a]+(t[a+1]-t[a])*(i-a)}function v$(e,t,n){let r=Math.max(2,Math.min(l$,Math.floor(n)));if(r*t.length>131072)throw Error(`too_many_cells`);let i=1/0,a=-1/0;for(let t of e)for(let e of t.x)e===e&&(e<i&&(i=e),e>a&&(a=e));if(!(a>i))throw Error(`empty`);let o=Float64Array.from({length:r},(e,t)=>i+t*(a-i)/(r-1)),s=new Map;for(let n of t){let t=new Uint16Array(r),i=new Float64Array(r),a=new Float64Array(r),c=new Float32Array(r).fill(1/0),l=new Float32Array(r).fill(-1/0);for(let s of e){let e=s.cols.get(n);if(!e)continue;let u=g$(s.x,e,o);for(let e=0;e<r;e++){let n=u[e];if(n!==n)continue;let r=++t[e],o=n-i[e];i[e]+=o/r,a[e]+=o*(n-i[e]),n<c[e]&&(c[e]=n),n>l[e]&&(l[e]=n)}}let u={mean:new Float32Array(r),sd:new Float32Array(r),min:c,max:l,n:t};for(let e=0;e<r;e++){if(t[e]===0){u.mean[e]=u.sd[e]=u.min[e]=u.max[e]=NaN;continue}u.mean[e]=i[e],u.sd[e]=t[e]>1?Math.sqrt(a[e]/(t[e]-1)):0}s.set(n,u)}return{x:o,channels:s}}function y$(e,t){if(e.unit===`abs`)return e.tolerance;let n=1/0,r=-1/0;for(let e of t.mean)e===e&&(e<n&&(n=e),e>r&&(r=e));return r>=n?Math.max(r-n,Math.abs(r),Math.abs(n))*e.tolerance/100:0}var b$=new WeakMap;function x$(e){let t=b$.get(e);if(t)return t;let n=e.sd.length,r=Math.max(2,Math.round(n/100));t=new Float32Array(n).fill(NaN);for(let i=0;i<n;i++){if(e.n[i]<2)continue;let a=0,o=0;for(let t=Math.max(0,i-r);t<=Math.min(n-1,i+r);t++)e.n[t]>=2&&e.sd[t]===e.sd[t]&&(a+=e.sd[t]**2,o++);t[i]=o?Math.sqrt(a/o):NaN}return b$.set(e,t),t}function S$(e,t,n){if(n===`minmax`)return{lo:e.min,hi:e.max};if(n===`sigma`){let n=x$(e);return{lo:e.mean.map((e,r)=>e-t*n[r]),hi:e.mean.map((e,r)=>e+t*n[r])}}let r=y$(n,e);return{lo:e.mean.map(e=>e-r),hi:e.mean.map(e=>e+r)}}function C$(e,t,n,r=`sigma`,i=0){let a=typeof r==`function`?r:()=>({band:r,k:n}),o=[...t.channels.keys()],s=new Map,c=new Map,l=[],u=new Uint8Array(e.t.length),d=o.map(()=>new Uint8Array(e.t.length)),f=t.x.length;o.forEach((n,r)=>{let i=t.channels.get(n),o=e.cols.get(n);if(!o)return;let{band:p,k:m}=a(n),h=typeof p==`object`?p:null,{lo:g,hi:_}=S$(i,m,p),v=0,y=0,b=0;for(let e of i.mean)if(e===e){v++;let t=e-y;y+=t/v,b+=t*(e-y)}let x=v>1?Math.max(Math.sqrt(b/(v-1)),1e-9):1e-9,S=h?Math.max(y$(h,i),1e-9):0,C=x$(i),w=new Float64Array(e.t.length).fill(NaN),T=new Float64Array(e.t.length).fill(NaN),E=0,D=0;for(let n=0;n<e.t.length;n++){let a=o[n],s=e.x[n];if(a!==a||s!==s)continue;let c=_$(t.x,i.mean,s);if(c!==c)continue;w[n]=a-c;let l=Math.round((s-t.x[0])/(t.x[f-1]-t.x[0])*(f-1));T[n]=Math.abs(a-c)/(h?S:i.n[l]>=2&&C[l]===C[l]?Math.max(C[l],1e-9):x),E+=T[n],D++,(h||i.n[l]>=2)&&(a<_$(t.x,g,s)||a>_$(t.x,_,s))&&(u[n]=1,d[r][n]=1)}s.set(n,w),c.set(n,T),l.push({channel:n,z:D?E/D:0})}),l.sort((e,t)=>t.z-e.z);let p=[];for(let t=0;t<u.length;t++){if(!u[t])continue;let n=t;for(;n<u.length&&u[n];)n++;let r=p[p.length-1];r&&e.t[t]-e.t[Math.min(r[1],u.length-1)]<i?r[1]=n:p.push([t,n]),t=n}let m=[];for(let[t,n]of p){let r=e.t[t],a=e.t[Math.min(n,u.length-1)];a-r>=i&&m.push({t0:r,t1:a,channels:o.filter((e,r)=>d[r].subarray(t,n).includes(1))})}return{delta:s,score:l,deviations:m,z:c}}function w$(e,t){let n=e.x.length,r=t.length,i=new DataView(new ArrayBuffer(12+8*n+r*n*18));[75,82,66,49].forEach((e,t)=>i.setUint8(t,e)),i.setUint32(4,n,!0),i.setUint32(8,r,!0);let a=12;for(let t=0;t<n;t++,a+=8)i.setFloat64(a,e.x[t],!0);for(let r of t){let t=e.channels.get(r);if(!t)throw Error(`The reference has no channel ${r}`);for(let e of[t.mean,t.sd,t.min,t.max])for(let t=0;t<n;t++,a+=4)i.setFloat32(a,e[t],!0);for(let e=0;e<n;e++,a+=2)i.setUint16(a,t.n[e],!0)}return De(new Uint8Array(i.buffer))}function T$(e,t){let n=le(e),r=new DataView(n.buffer,n.byteOffset,n.byteLength);if(n.length<12||String.fromCharCode(n[0],n[1],n[2],n[3])!==`KRB1`)throw Error(`Not a reference band`);let i=r.getUint32(4,!0),a=r.getUint32(8,!0);if(a!==t.length||n.length!==12+8*i+a*i*18)throw Error(`This reference band does not match its channels`);let o=12,s=new Float64Array(i);for(let e=0;e<i;e++,o+=8)s[e]=r.getFloat64(o,!0);let c=new Map;for(let e of t){let t=()=>{let e=new Float32Array(i);for(let t=0;t<i;t++,o+=4)e[t]=r.getFloat32(o,!0);return e},n=t(),a=t(),s=t(),l=t(),u=new Uint16Array(i);for(let e=0;e<i;e++,o+=2)u[e]=r.getUint16(o,!0);c.set(e,{mean:n,sd:a,min:s,max:l,n:u})}return{x:s,channels:c}}var E$=` Δ`,D$=class{#e;constructor(e){this.#e=new jB(e)}assumeOpen(e){}feed(e,t,n){let r=[];for(let i=0;i<e.length;i++)this.#e.step(e[i],e=>{let n=t(e);return n?n[i]:NaN},r),n?.(i,this.#e.open()?.tstart??null);return r.map(e=>({tstart:e.tstart,tend:e.tend,kpis:{duration:(e.tend??e.tstart)-e.tstart},...e.flags.length?{flags:e.flags}:{}}))}};function O$(e){if(!e.cycle&&!e.rule)throw Error(`a live segment axis needs a rule or a cycle rule`);let t=e.cycle?new D$(e.cycle):new gB(e.rule,e.kpis??[]),n=new m$(e.axis),r=NaN;e.start!=null&&(t.assumeOpen(e.start),n.begin(e.start),r=e.start);let i=e.reference??null,a=i?[...i.channels]:[],o=i?i.grid.length:0,s=`channel`in e.axis?e.axis.channel:null,c=[...new Set([...e.cycle?AB(e.cycle):iB(e.rule),...(e.kpis??[]).map(e=>e.channel),...s?[s]:[],...a.map(([e])=>e)])],l=e.minDeviationS??5,u=NaN,d=NaN,f=NaN,p=new Set,m=!1,h=e=>{m&&e({type:`deviation-end`,t0:u,t1:d,channels:[...p]}),u=d=f=NaN,p=new Set,m=!1};return{feed(g,_,v=!1){let y=Math.max(_,g.firstAbs),b=g.endAbs;if(y>=b)return;let x=t=>{v||e.onEvent?.(t)},S=g.range(qe,y,b),C=new Map(c.map(e=>[e,g.range(e,y,b)])),w=new Float64Array(S.length).fill(NaN),T=a.map(([e,t])=>({name:e,b:t,v:C.get(e),d:new Float64Array(S.length).fill(NaN)})),E=s?C.get(s):null,D=t.feed(S,e=>C.get(e),(e,t)=>{if(t===null)return;t!==r&&(h(x),r=t,n.begin(t),x({type:`open`,tstart:t}));let a=n.x(S[e],E?E[e]:NaN);if(w[e]=a,!i||a!==a)return;let s=o>1?Math.round((a-i.grid[0])/(i.grid[o-1]-i.grid[0])*(o-1)):0,c=!1;for(let t of T){let n=t.v[e],r=_$(i.grid,t.b.mean,a);n!==n||r!==r||(t.d[e]=n-r,t.b.n[s]>=2&&(n<_$(i.grid,t.b.lo,a)||n>_$(i.grid,t.b.hi,a))&&(c=!0,p.add(t.name)))}c?(u!==u&&(u=S[e]),d=S[e],f=NaN,!m&&S[e]-u>=l&&(m=!0,x({type:`deviation`,t0:u,channels:[...p]}))):u===u&&(f!==f&&(f=S[e]),S[e]-f>=l&&h(x))});for(let e of D)x({type:`close`,segment:e});g.writeComputed(e.column,e.unit,y,w);for(let e of T)g.writeComputed(`${e.name} Δ`,g.unitOf(e.name),y,e.d)}}}var k$=1e7;function A$(e=globalThis.navigator?.deviceMemory){return Math.max(512,Math.round(((e??0)>0?e:16)*1024/8))}var j$=400,M$=4e3,N$=1e3,P$=3e3,F$=2,I$=5e3,L$=1e4;function R$(e,t,n=`data`){let r=new Xe(t.capacity??k$,void 0,void 0,(t.maxMemoryMB??A$())*1024*1024);return{meta:e,buffer:r,source:new QQ(()=>r),unsub:()=>{},status:`connecting`,error:null,lastFrameAt:Date.now(),lastColCount:0,lastValued:0,recorder:null,schemas:new Map,video:n===`camera`?new OE:null,clock:n===`camera`?null:new ZQ,lagTicks:0,lastRejoinAt:0,rejoin:()=>{},subscribed:!1,releaseTimer:void 0}}function z$(e,t,n=()=>({}),r){let i=new Map,a=e,o=[],s=[],c=``,l=()=>{let e=[];for(let t of i.values())t.lastColCount=t.buffer.columnNames.length,t.lastValued=t.buffer.valuedCount,e.push({...t.meta,kind:t.video?`camera`:`data`,video:t.video,clock:t.clock,dataset:t.buffer.toDataset(j$),source:t.source,rowCount:t.buffer.size,status:t.status,error:t.error,recordingSince:t.recorder?.startedAt??null});o=e,t(o)},u=(e,t)=>{let n=!1,r=e.buffer.endAbs;for(let r of t)r&&typeof r.t==`number`&&Array.isArray(r.signals)&&(e.buffer.push(r),e.recorder?.add(r),n=!0);n&&p(e,r,t[t.length-1]?.t)},d=(e,t)=>{let n=e.buffer.endAbs;e.buffer.pushColumns(t),e.recorder?.addColumns(t),t.t.length>0&&p(e,n,t.t[t.t.length-1])},p=(e,t,n)=>{s$(e.buffer,s,t),e.segAxis?.tracker.feed(e.buffer,t),r?.rows(e.meta.id,e.buffer,t),typeof n==`number`&&e.clock?.observe(n,Date.now()/1e3),m(e,t===0||e.buffer.columnNames.length!==e.lastColCount||e.buffer.valuedCount!==e.lastValued)},m=(e,t)=>{e.lastFrameAt=Date.now();let n=e.status===`stale`||e.status===`connecting`;n&&(e.status=`live`),(n||t)&&l()},h=e=>{let t=i.get(e);t&&(clearTimeout(t.releaseTimer),t.unsub(),i.delete(e),l())},g=setInterval(()=>{let e=Date.now(),t=!1;for(let n of i.values()){n.status===`live`&&e-n.lastFrameAt>M$&&(n.status=`stale`,t=!0);let i=n.video&&n.subscribed&&n.status===`live`?n.video.info().lagMs:null;n.lagTicks=i!==null&&i>P$?n.lagTicks+1:0,n.video&&n.lagTicks>=F$&&e-n.lastRejoinAt>=I$&&(n.lagTicks=0,n.lastRejoinAt=e,n.video.resync(),n.unsub(),n.rejoin()),n.buffer.size&&r?.tick(n.meta.id,n.buffer,n.lastFrameAt)}t&&l()},N$);return{connections:()=>o,disconnect:h,startRecording(e){let t=i.get(e);!t||t.recorder||(t.recorder=new n$,l())},stopRecording(e){let t=i.get(e),n=t?.recorder;return!t||!n?null:(t.recorder=null,l(),{csv:n.toCsvParts(),rows:n.rows,name:t.meta.name,startedAt:n.startedAt})},setRelay(e){a=e},setSegmentAxis(e,t){let n=i.get(e);n&&(n.segAxis=t?{cfg:t,tracker:O$(t)}:void 0,t&&n.segAxis.tracker.feed(n.buffer,n.buffer.firstAbs,!t.replay),l())},setMathChannels(e){let t=JSON.stringify(e.map(e=>[e.id,e.name,e.units,e.formula,e.enabled]));if(t!==c){c=t,s=e;for(let t of i.values())t.video||(c$(t.buffer,e),t.segAxis&&(t.segAxis.tracker=O$(t.segAxis.cfg),t.segAxis.tracker.feed(t.buffer,t.buffer.firstAbs,!0)));i.size>0&&l()}},openLocal(e,t){let r=`local:${crypto.randomUUID()}`,a=R$({id:r,name:e,ownerName:`This page`,visibility:`private`,orgName:null,parentId:null,lowOf:null},{...n(),...t});return i.set(r,a),l(),{id:r,push:e=>{i.get(r)===a&&u(a,Array.isArray(e)?e:[e])},pushColumns:e=>{i.get(r)===a&&d(a,e)},close:()=>h(r)}},async connect(e,t,r){if(i.has(e.id))return;let o=a&&e.relay_url?{...a,url:e.relay_url}:a;if(!o)throw new kE(`relay_unavailable`);let s=typeof t==`string`?await f(ue(t).secret??t,e.salt):`keyFor`in t?e=>t.keyFor(e):t;if(typeof s!=`function`&&!await ge(s,e.key_check))throw new kE(`wrong_password`);let c=R$({id:e.id,name:e.name,ownerName:e.owner_name??``,visibility:e.visibility??`private`,orgName:e.org_name??null,projectName:e.project_name??null,parentId:e.parent_stream_id??null,lowOf:e.low_of_stream_id??null},{...n(),...r},e.kind);i.set(e.id,c);let p=Promise.resolve();c.rejoin=()=>{c.unsub=GQ(o,e.id,t=>{let n=ye(s,t).catch(()=>null);p=p.then(async()=>{try{let t=await n;if(!t||i.get(e.id)!==c)return;if(t.kind===6){let e=YQ(t.plaintext);e&&c.video&&(c.video.push(e),m(c,!1));return}if(t.kind===5){let e=de(t.plaintext);c.schemas.set(e.id,e);return}if(t.kind===7){let e=he(t.plaintext,c.schemas);if(!e)return;let n=c.buffer;for(let t of e)n.setLastKnown(t.name,t.unit,t.t,t.v);(n.columnNames.length!==c.lastColCount||n.valuedCount!==c.lastValued)&&l();return}if(t.kind===4){let e=await Ge(t.plaintext,c.schemas);e&&!e.historical&&d(c,e.block);return}if(t.kind===3)return d(c,Ie(t.plaintext));if(t.kind!==2)return;let r=ie(t.plaintext);u(c,Array.isArray(r?.frames)?r.frames:[])}catch{}})},t=>{!c.subscribed||i.get(e.id)!==c||(t===`subscribed`?(c.status=`live`,c.lastFrameAt=Date.now()):t===`error`&&(c.status=`error`,c.error=`connection_error`),l())})};let h=c.video;h?(c.status=`idle`,h.onDemandChange(t=>{i.get(e.id)===c&&(clearTimeout(c.releaseTimer),t?c.subscribed||(c.subscribed=!0,h.resync(),c.status=`connecting`,c.lastFrameAt=Date.now(),c.rejoin(),l()):c.releaseTimer=setTimeout(()=>{c.subscribed=!1,c.unsub(),c.unsub=()=>{},c.status=`idle`,c.error=null,c.lagTicks=0,l()},L$))})):(c.subscribed=!0,c.rejoin()),l()},dispose(){clearInterval(g);for(let e of i.values())clearTimeout(e.releaseTimer),e.unsub();i.clear(),o=[]}}}var B$=500,V$=1<<20;function H$(e){let t=[],n=new Map,r=[],i=``,a=(e,t)=>`${e}|${t}`,o=(e,t)=>{let n=t.kind===`stream`?e.targets?.streams:t.kind===`history`?e.targets?.histories:e.targets?.datasets;return!n||n.includes(t.kind===`dataset`?t.name??t.id:t.id)},s=()=>[...n.values()].map(e=>{let{state:t,missing:n,since:r}=e.state();return{ruleId:e.rule.id,target:e.target,state:t,...n?{missing:n}:{},...r===void 0?{}:{since:r}}}),c=()=>{let t=s(),n=JSON.stringify(t);n!==i&&(i=n,e.setStates(t))};function l(n,i){let a=t.find(e=>e.id===n.ruleId);if(n.kind===`raised`){r=[...r,{id:`${n.ruleId}|${n.target.id}|${n.t}`,ruleId:n.ruleId,ruleName:a?.name??``,severity:a?.severity??`info`,targetId:n.target.id,timeColumn:i,t0:n.t,t1:null}];let e=r.filter(e=>e.targetId===n.target.id);e.length>B$&&(r=r.filter(t=>t!==e[0]))}else{let e=r.find(e=>e.ruleId===n.ruleId&&e.targetId===n.target.id&&e.t1===null);e&&(r=r.map(t=>t===e?{...t,t1:n.t}:t))}e.setMarks(r),e.emit(n)}function u(){let r=new Set;for(let i of e.targets())for(let e of t){if(!o(e,i))continue;let t=a(e.id,i.id);r.add(t);let s=n.get(t),{channels:c,...u}=i;(!s||s.rule!==e)&&(s=et(e,u),n.set(t,s));for(let e of s.bind(c))l(e,i.kind===`stream`?qe:``)}for(let e of n.keys())r.has(e)||n.delete(e);c()}return{setRules(n){let r=[],i=n.filter(e=>{let t=tt(e);return r.push(...t.map(t=>({ruleId:String(e?.id??``),...t}))),!t.length}),a=e.maxRules();a!==null&&i.length>a&&e.limit();let o=new Map(t.map(e=>[e.id,e]));return t=(a===null?i:i.slice(0,a)).map(e=>{let t=o.get(e.id);return t&&t.version===e.version?t:e}),u(),r},rules:()=>t,state:s,async evaluate(n,i){let a=e.targets().find(e=>e.id===n&&e.kind===`dataset`);if(!a)return[];let{channels:s,...c}=a,u=[],d=t.filter(e=>(!i.ruleIds||i.ruleIds.includes(e.id))&&o(e,c)),f=d.map(e=>{let t=et(e,c);return t.bind(s),t}),p=[...new Set(d.flatMap(e=>Object.values(e.signals).map(e=>`formula`in e?e.formula:e.channel)))];for(let t=0;;t+=V$){let r=await e.readDataset(n,[i.timeColumn,...p],t,V$),a=r[i.timeColumn];if(!a||!a.length)break;for(let e of f)u.push(...e.push({t:a,columns:r}));if(a.length<V$)break}r=r.filter(e=>!(e.targetId===n&&(!i.ruleIds||i.ruleIds.includes(e.ruleId)))),e.setMarks(r);for(let e of u)l(e,i.timeColumn);return u},pushLive(e,t){let r=!1;for(let i of n.values()){if(i.target.id!==e)continue;let n=i.push(t);n.length&&(r=!0);for(let e of n)l(e,qe)}r&&c()},tickLive(e,t){let r=!1;for(let i of n.values()){if(i.target.id!==e)continue;let n=i.tick(t);n.length&&(r=!0);for(let e of n)l(e,qe)}r&&c()},liveColumns(e){let t=new Set;for(let r of n.values())if(r.target.id===e)for(let e of Object.values(r.rule.signals))t.add(`formula`in e?e.formula:e.channel);return[...t]},sync:u,clearMarks(t){r=t?r.filter(e=>e.targetId!==t):[],e.setMarks(r)}}}var U$=class{past=[];future=[];current=null;lastAt=-1/0;o;equals;constructor(e){this.o=e,this.equals=e.equals??Object.is}get canUndo(){return this.past.length>0}get canRedo(){return this.future.length>0}observe(e){if(this.current===null)return this.current=e,!1;if(this.equals(e,this.current))return!1;let t=this.o.now();return t-this.lastAt<this.o.mergeMs&&this.past.length>0||(this.past.push(this.current),this.past.length>this.o.limit&&this.past.shift()),this.current=e,this.future=[],this.lastAt=t,!0}rebase(e){this.current=e}undo(){if(this.past.length===0)return null;let e=this.past.pop();return this.future.push(this.current),this.current=e,this.lastAt=-1/0,e}redo(){if(this.future.length===0)return null;let e=this.future.pop();return this.past.push(this.current),this.current=e,this.lastAt=-1/0,e}clear(e){this.past=[],this.future=[],this.current=e,this.lastAt=-1/0}},W$={maxChartsPerWorksheet:null,maxChannelsPerChart:null,maxWorksheets:null,maxMathChannels:null,maxAlertRules:null,canImportExportWorkspaces:!0},G$=[];function K$(e,t){let n=e.found[t];return{definitionId:n.definitionId,rule:e.defs.find(e=>e.id===n.definitionId)?.name??n.definitionId,index:n.index,parentIndex:n.parentIndex??null,tstart:n.tstart,tend:n.tend,flags:n.flags,kpis:n.kpis??{},incomplete:!!n.incomplete}}var q$=[`#a78bfa`,`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#94a3b8`];function J$(e=`ET`){return{id:crypto.randomUUID(),name:`Worksheet`,panels:[],panelChartSettings:{},panelChartBackgrounds:{},xKey:e}}function Y$(e,t){let n=e.filter(e=>e.source!==`workbook`),r=new Map,i=[];for(let e of t){let t=n.find(t=>t.name===e.name);if(t&&t.formula===e.formula&&t.units===e.units)continue;let a=t?`${e.name} (workbook)`:e.name;t&&r.set(e.name,a),i.push(cr({...e,name:a,source:`workbook`}))}return{channels:i,rename:r}}function X$(e,t){let n=JSON.stringify({xKey:e.xKey,panelChartSettings:e.panelChartSettings});for(let[e,r]of t)n=n.split(JSON.stringify(e)).join(JSON.stringify(r));return{...e,...JSON.parse(n)}}function Z$(e){return typeof e.text==`function`?e.text():new Promise((t,n)=>{let r=new FileReader;r.onload=()=>t(String(r.result??``)),r.onerror=()=>n(r.error),r.readAsText(e)})}function Q$(e,t,n){if(!e||!t)return $t();let{min:r,max:i}=Sz(e.rows,t);if(!Number.isFinite(r)||!Number.isFinite(i))return $t();let a=wz(i-r||1,6),o=a>=1?Math.round(a):a,s=o>=1?1:o/10,c=Math.max(0,Math.ceil(-Math.log10(s))),l=e=>String(Number(e.toFixed(c)));return{...n,scaleMin:l(Math.floor(r/s)*s),scaleMax:l(Math.ceil(i/s)*s),majorStep:l(o),minorStep:``}}function $$(e,t){let n=t.includes(e.xKey)?e.xKey:t.includes(`ET`)?`ET`:t.includes(`ElapsedTime`)?qe:t[0],r={...e.panelChartSettings};for(let n of e.panels){let e=r[n.id];if(n.kind===`multiband`){let i=e&&e.kind===`multiband`?e:pn();r[n.id]={...i,kind:`multiband`,addColumn:i.addColumn&&t.includes(i.addColumn)?i.addColumn:t[0]}}else if(n.kind===`xyscatter`){let i=e&&e.kind===`xyscatter`?e:mn(q$[2]),a=i.xyXCol||t[0],o=i.xyYCol||(t.length>1&&t[1]!==a?t[1]:t[0]);r[n.id]={...i,kind:`xyscatter`,xyXCol:a,xyYCol:o}}else if(n.kind===`xyzmesh`){let i=e&&e.kind===`xyzmesh`?e:hn(4),a=i.xyzXCol||t[0],o=i.xyzYCol||(t.length>1?t[1]:t[0]),s=i.xyzZCol||(t.length>2?t[2]:t[0]);r[n.id]={...i,kind:`xyzmesh`,xyzXCol:a,xyzYCol:o,xyzZCol:s}}}return{...e,xKey:n,panelChartSettings:r}}function e1(e,t){let n=!1,r={...e.panelChartSettings};for(let[i,a]of Object.entries(e.panelChartSettings)){if(a.kind!==`multiband`)continue;let e=a.series.filter(e=>t(e.column));e.length!==a.series.length&&(r[i]={...a,series:e},n=!0)}return n?{...e,panelChartSettings:r}:e}function t1(){return typeof document>`u`?`dark`:$z(null)}function n1(e={}){let t={...e},n=!1,r=J$(),i=kQ({datasets:[],selection:[],worksheets:[r],activeWorksheetId:r.id,xRanges:{},offsets:{},colors:{},liveWindowSeconds:15,segmentContext:null,cycleRules:[],live:[],video:[],mathChannels:[],limits:{...W$,...t.limits},palette:Xz(t.palette,t1()),importing:0,licensed:null,history:{canUndo:!1,canRedo:!1},marks:[],alerts:[],alertRules:[]}),a=RV(),o=()=>{let e=Xz(t.palette,t1());i.set(t=>t.palette.join()===e.join()?t:{...t,palette:e})},s=typeof document>`u`?()=>{}:eB(null,o),c=jQ(),l=()=>{if(n)throw new kE(`disposed`)},u=e=>{throw a.emit(`limit`,{reason:e}),new kE(`limit_reached`,{reason:e})},d=()=>i.get(),f=(e,t)=>{let n=d().limits.maxChannelsPerChart,r=Cz(t);n!==null&&r>n&&r>Cz(e)&&u(`channels-per-chart`)},p=AQ((e,t)=>t===null?e:e.slice(0,t)),m=()=>{let e=d(),t=c.lapsByDataset(e.datasets),n=c.selectedDatasets(e.datasets,t,e.selection),r=c.selectedLive(e.live,e.selection),i=c.staticDataset(n),a=c.mergedDataset(i,r),o=p(e.mathChannels,e.limits.maxMathChannels);return{laps:t,selectedDatasets:n,selectedLive:r,staticDataset:i,merged:a,channels:o,numericColumns:c.numericColumns(a,n,o,c.mergedParts(n,r),r),allColumns:c.allColumns(a,n,o),columnUnits:c.columnUnits(a,o)}},h=(e,t)=>({id:t.id,kind:t.kind,title:t.title??null,settings:e.panelChartSettings[t.id],background:e.panelChartBackgrounds[t.id]??null,annotations:e.panelChartSettings[t.id]?.annotations??G$,layout:t.rect}),g=AQ((e,t,n)=>e.map(e=>({id:e.id,name:e.name,xKey:e.xKey,xRange:t[e.id]??null,liveWindowSeconds:e.liveWindowSeconds===void 0?n:e.liveWindowSeconds,charts:e.panels.map(t=>h(e,t))}))),_=AQ((e,t,n,r,i,a,o)=>{let s=(e,t)=>{let n=a.findIndex(t=>t.id===e);return n>=0?n:t};return e.map((e,a)=>{let c=i[e.id],l=c?.laps.map(e=>e.id)??[],u=l.filter(e=>t.includes(e)).length;return{id:e.id,name:e.name,kind:e.kind,columns:e.schema.map(e=>({name:e.name,unit:e.unit??``,numeric:e.type===`number`})),rowCount:e.data.rows.length,color:Jz(n,e.id,s(e.id,a),o),customColor:e.id in n,offset:r[e.id]??0,parseConfig:e.parseConfig??null,fileInfo:e.info??null,beacon:e.beacon??null,cut:e.cut?{cycleId:e.cut.cycleId,timeKey:e.cut.timeKey,defs:e.cut.defs}:null,laps:c?c.laps.map((i,a)=>({id:i.id,name:i.name,value:c.values[a],unit:c.unit,isTime:c.isTime,color:Jz(n,i.id,s(i.id,a),o),offset:r[i.id]??0,selected:t.includes(i.id),...e.cut?{cycle:K$(e.cut,a)}:{}})):null,selected:c?u===0?!1:u===l.length?!0:`partial`:t.includes(e.id)}})}),v=AQ((e,t,n,r,i)=>{let a=e.filter(e=>t.includes(e.id)).map(e=>e.id);return e.map((e,o)=>({id:e.id,name:e.name,ownerName:e.ownerName,visibility:e.visibility,orgName:e.orgName,kind:e.kind,parentId:e.parentId,lowOf:e.lowOf,status:e.status,error:e.error,rowCount:e.rowCount,selected:t.includes(e.id),color:Jz(n,e.id,a.includes(e.id)?r+a.indexOf(e.id):o,i),customColor:e.id in n,recordingSince:e.recordingSince,channels:e.dataset.columnNames}))}),y=AQ(e=>{let t=m();return{datasets:_(e.datasets,e.selection,e.colors,e.offsets,t.laps,t.selectedDatasets,e.palette),selection:e.selection,worksheets:g(e.worksheets,e.xRanges,e.liveWindowSeconds),activeWorksheetId:e.activeWorksheetId,mathChannels:t.channels,live:v(e.live,e.selection,e.colors,t.selectedDatasets.length,e.palette),liveWindowSeconds:(()=>{let t=e.worksheets.find(t=>t.id===e.activeWorksheetId);return t?.liveWindowSeconds===void 0?e.liveWindowSeconds:t.liveWindowSeconds})(),segmentContext:e.segmentContext,cycleRules:e.cycleRules,limits:e.limits,palette:e.palette,importing:e.importing,licensed:e.licensed,hasData:t.merged!==null,multiDataset:t.selectedDatasets.length+t.selectedLive.length>1,numericColumns:t.numericColumns,allColumns:t.allColumns,columnUnits:t.columnUnits,history:e.history,marks:e.marks,alerts:e.alerts}}),b=(e,t)=>e===t||e.length===t.length&&e.every((e,n)=>e===t[n]||JSON.stringify(e)===JSON.stringify(t[n])),x=new U$({limit:100,mergeMs:500,now:()=>Date.now(),equals:(e,t)=>e.liveWindowSeconds===t.liveWindowSeconds&&b(e.worksheets,t.worksheets)&&b(e.channels,t.channels)}),S=!0,C=0,w=e=>{C++;try{e()}finally{C--}},T=e=>[e.worksheets,e.mathChannels,e.liveWindowSeconds],E=[],D=()=>{let e=d();return{worksheets:e.worksheets,channels:e.mathChannels.filter(e=>e.source===`workbook`),liveWindowSeconds:e.liveWindowSeconds,activeWorksheetId:e.activeWorksheetId}},O=()=>i.set(e=>e.history.canUndo===x.canUndo&&e.history.canRedo===x.canRedo?e:{...e,history:{canUndo:x.canUndo,canRedo:x.canRedo}}),k=()=>{if(S)return;let e=T(d());e.every((e,t)=>e===E[t])||(E=e,C?x.rebase(D()):x.observe(D()),O())},A=()=>{E=T(d()),x.clear(D()),O()},j=e=>{S=!0;let t;try{t=e()}finally{S=!1}return A(),t},M=()=>y(d());i.subscribe(()=>{k(),a.emit(`change`,M())});let N=e=>{let t=d(),n=t.worksheets.find(n=>n.id===(e??t.activeWorksheetId));if(!n)throw new kE(`not_found`,{worksheetId:e});return n},P=e=>{for(let t of d().worksheets){let n=t.panels.find(t=>t.id===e);if(n)return{ws:t,panel:n}}throw new kE(`not_found`,{chartId:e})},F=(e,t)=>i.set(n=>{let r=!1,i=n.worksheets.map(n=>{if(n.id!==e)return n;let i=t(n);return i!==n&&(r=!0),i});return r?{...n,worksheets:i}:n}),I=(e,t)=>{let{ws:n}=P(e);F(n.id,n=>({...n,panelChartSettings:{...n.panelChartSettings,[e]:t(n.panelChartSettings[e])}}))},L=e=>i.set(t=>e.length===t.selection.length&&e.every((e,n)=>e===t.selection[n])?t:{...t,selection:e,xRanges:{}}),R=new Set,z=z$(t.live?.relay,e=>{let t=e.map(e=>e.id),n=e.filter(e=>e.kind===`data`&&!R.has(e.id)).map(e=>e.id),r=[...R].filter(e=>!t.includes(e));if(R=new Set(t),i.set(t=>({...t,live:e})),r.length&&L(d().selection.filter(e=>!r.includes(e))),n.length){let e=d().selection,t=n.filter(t=>!e.includes(t));t.length&&L([...e,...t])}let a=m();if(a.selectedLive.length&&a.merged){let e=a.merged.columnNames;if(e.includes(`ElapsedTime`))for(let t of d().worksheets)e.includes(t.xKey)||w(()=>F(t.id,e=>({...e,xKey:qe})))}},()=>({capacity:t.live?.capacity,maxMemoryMB:t.live?.maxMemoryMB}),{rows:(e,t,n)=>{if(!ce.rules().length)return;t.columnNames.length!==V.get(e)&&(V.set(e,t.columnNames.length),ce.sync());let r=ce.liveColumns(e);if(!r.length)return;let i=t.endAbs,a=Math.max(n,t.firstAbs);if(i<=a)return;let o={};for(let e of r)o[e]=t.range(e,a,i);ce.pushLive(e,{t:t.range(qe,a,i),columns:o,scan:new Map})},tick:(e,t,n)=>{if(!ce.rules().length)return;let r=t.range(qe,t.endAbs-1,t.endAbs)[0];r===r&&ce.tickLive(e,r+(Date.now()-n)/1e3)}}),V=new Map,te=AQ((e,t)=>e.filter(e=>t.some(t=>SE([e],t.panelChartSettings,t.xKey).length>0))),ne=()=>z.setMathChannels(te(p(d().mathChannels,d().limits.maxMathChannels),d().worksheets));ne(),i.subscribe(ne);let re=e=>{i.set(t=>({...t,datasets:[...t.datasets,e]})),L([...d().selection,e.id]);let t=xz(e.schema);t.length&&w(()=>i.set(e=>({...e,worksheets:e.worksheets.map(e=>$$(e,t))})))},ie=Promise.resolve(),U=async(e,r={})=>{l();let o=e.map(e=>e instanceof File?e:e.file);if(o.length===0)return{ids:[],errors:[]};if(await t.beforeImport?.()===!1)throw new kE(`import_vetoed`);let{signal:s}=r;i.set(e=>({...e,importing:e.importing+o.length}));let c=ie.then(async()=>{let e={ids:[],errors:[]},t=o.length,c=e=>{t-=e,i.set(t=>({...t,importing:Math.max(0,t.importing-e)}))};try{let{items:t,errors:i}=await DR(o);c(o.length-t.length);for(let{file:t,error:n}of i)e.errors.push({file:t,error:n}),a.emit(`import`,{file:t,phase:`error`,error:n}),a.emit(`error`,{error:n,context:`import`});for(let i of t){if(n)break;if(s?.aborted){e.cancelled=!0;break}let t=i.main;await new Promise(e=>setTimeout(e,0)),a.emit(`import`,{file:t.name,phase:`start`});try{let o=i.format?await bz({main:t,companions:i.companions,format:i.format.id},{priorInMemoryValues:yR(d().datasets),signal:s,onProgress:e=>a.emit(`import`,{file:t.name,phase:`progress`,fraction:e}),chooseChannels:r.chooseChannels,pickChannels:r.pickChannels}):[await vR(crypto.randomUUID(),t,d().datasets)??await gR(crypto.randomUUID(),t,Z$,void 0,yR(d().datasets),s)];if(n){for(let e of o)e.source.dispose();break}if(s?.aborted){for(let e of o)e.source.dispose();throw new kE(`cancelled`)}for(let t of o)re(t),e.ids.push(t.id);a.emit(`import`,{file:t.name,phase:`done`,datasetId:o[0].id,datasetIds:o.map(e=>e.id)})}catch(n){let r=n instanceof Error?n:Error(String(n));a.emit(`import`,{file:t.name,phase:`error`,error:r}),r instanceof kE&&r.code===`cancelled`?e.cancelled=!0:(e.errors.push({file:t.name,error:r}),a.emit(`error`,{error:r,context:`import`}))}finally{c(1)}if(e.cancelled)break}}finally{t>0&&c(t)}return e});return ie=c.catch(()=>void 0),c},ae=()=>setTimeout(()=>{n||HZ(nt)},0),oe=e=>{let t=t=>e.some(e=>t===e||t.startsWith(`${e}::`)),n=d().datasets.filter(t=>e.includes(t.id));for(let e of n)e.source.dispose().catch(()=>void 0);i.set(n=>{let r={...n.offsets},i={...n.colors};for(let e of Object.keys(r))t(e)&&delete r[e];for(let e of Object.keys(i))t(e)&&delete i[e];return{...n,datasets:n.datasets.filter(t=>!e.includes(t.id)),offsets:r,colors:i}}),L(d().selection.filter(e=>!t(e))),n.length>0&&ae()},se=async(e,t,n={})=>{let[r,...i]=await bz({main:new File(e.chunks,`${e.name}.krc`),companions:[],format:`krc`,keys:e.keys},{priorInMemoryValues:t,...n});for(let e of i)e.source.dispose();return{...r,file:void 0,name:e.name,info:r.info&&{...r.info,startTime:e.startTime??r.info.startTime,meta:{...r.info.meta,recordingId:e.recordingId}}}},ce=H$({targets:()=>[...d().datasets.map(e=>({kind:`dataset`,id:e.id,name:e.name,channels:e.schema.map(e=>e.name)})),...d().live.filter(e=>e.kind===`data`).map(e=>({kind:`stream`,id:e.id,name:e.name,channels:e.source.columnNames}))],maxRules:()=>d().limits.maxAlertRules,emit:e=>a.emit(`alert`,e),limit:()=>a.emit(`limit`,{reason:`alert-rules`}),setMarks:e=>i.set(t=>({...t,marks:e})),setStates:e=>i.set(t=>({...t,alerts:e})),readDataset:(e,t,n,r)=>{let i=d().datasets.find(t=>t.id===e);return i?i.source.readColumns(t,n,r):Promise.resolve({})}}),le=AQ((e,t)=>{let n=new Map;for(let r of e){let e=rt(r);e!==null&&n.set(r.id,{value:e,active:t.some(e=>e.ruleId===r.id&&(e.state===`active`||e.state===`clearing`))})}return n}),ue=null;i.subscribe(()=>{let e=d();ue&&ue[0]===e.datasets&&ue[1]===e.live||(ue=[e.datasets,e.live],ce.rules().length&&ce.sync())});let de={importFiles:U,warmImport(e={}){l(),cz(!!e.formats?.some(e=>e===`hdf5`||e===`mat`))},async splitByRate(e){l();let t=d().datasets.find(t=>t.id===e);if(!t)throw new kE(`not_found`,{datasetId:e});if(!t.info?.combined||!(t.file instanceof File))throw new kE(`invalid_argument`,{reason:`only a combined multi-rate import can be split`});let n=await bz({main:t.file,companions:t.companions??[],format:t.info.importer},{priorInMemoryValues:yR(d().datasets.filter(t=>t.id!==e)),selection:t.info.selection,split:!0});oe([e]);for(let e of n)re(e);return n.map(e=>e.id)},async chooseChannels(e,t){l();let n=d().datasets.find(t=>t.id===e);if(!n)throw new kE(`not_found`,{datasetId:e});if(!n.info||!(n.file instanceof File))throw new kE(`invalid_argument`,{reason:`only binary imports have channels to choose`});try{let r=await bz({main:n.file,companions:n.companions??[],format:n.info.importer},{priorInMemoryValues:yR(d().datasets.filter(t=>t.id!==e)),initial:n.info.selection,chooseChannels:t,pickChannels:!0});oe([e]);for(let e of r)re(e);return r.map(e=>e.id)}catch(e){if(e instanceof kE&&e.code===`cancelled`)return null;throw e}},async combine(e){l();let t=d().datasets.find(t=>t.id===e);if(!t)throw new kE(`not_found`,{datasetId:e});let n=t.info?.splitKey;if(!n||!(t.file instanceof File))throw new kE(`invalid_argument`,{reason:`only datasets split from one file can be combined`});let r=d().datasets.filter(e=>e.info?.splitKey===n),i=await bz({main:t.file,companions:t.companions??[],format:t.info.importer},{priorInMemoryValues:yR(d().datasets.filter(e=>!r.includes(e))),selection:r.flatMap(e=>e.info.selection)});if(i.length!==1){for(let e of i)e.source.dispose();throw new kE(`invalid_argument`,{reason:`these groups have no common time base`})}return oe(r.map(e=>e.id)),re(i[0]),i[0].id},async openRecording(e,t={}){l();let n=await se(e,yR(d().datasets),t);return re(n),n.id},async reopenRecording(e,t){l();let n=d().datasets.find(t=>t.id===e);if(!n)throw new kE(`not_found`,{datasetId:e});let r=await se(t,yR(d().datasets.filter(t=>t.id!==e)));i.set(t=>({...t,datasets:t.datasets.map(t=>t.id===e?{...r,id:e,beacon:n.beacon}:t)})),n.source.dispose().catch(()=>void 0),ae()},openHistoryRange(e){l();let t=OQ(crypto.randomUUID(),e);return re(t),t.id},updateHistoryRange(e,t){l();let n=d().datasets.find(t=>t.id===e);if(!n)throw new kE(`not_found`,{datasetId:e});if(!(n.source instanceof _Q)){let t=`dataset ${e} is not a history range: only datasets opened with openHistoryRange can be updated`;throw Object.assign(new kE(`invalid_argument`,{datasetId:e,reason:t}),{message:t})}let r=OQ(e,t);i.set(t=>({...t,datasets:t.datasets.map(t=>t.id===e?{...r,beacon:n.beacon}:t)})),ae()},addColumns(e){l();let t=xQ(crypto.randomUUID(),e);return re(t),t.id},replaceColumns(e,t,n={}){l();let r=d().datasets.find(t=>t.id===e);if(!r)throw new kE(`not_found`,{datasetId:e});let a=TQ(r,t,n.transfer);i.set(t=>({...t,datasets:t.datasets.map(t=>t.id===e?a:t)}))},writeColumns(e,t,n){l();let r=d().datasets.find(t=>t.id===e);if(!r)throw new kE(`not_found`,{datasetId:e});let a=CQ(r,t,n);i.set(t=>({...t,datasets:t.datasets.map(t=>t.id===e?a:t)}))},async addText(e,t=`dataset.csv`){l();let n=await pR(crypto.randomUUID(),t,e);return re(n),n.id},async findCycles(e,t,n){l();let r=d().datasets.find(t=>t.id===e);if(!r)throw new kE(`not_found`,{datasetId:e});let i=await BB(r.source,n,HB(t)),a=new Map(t.filter(e=>e.kpis?.length).map(e=>[e.id,e.kpis]));return VB(i,t).map(e=>a.has(e.definitionId)?{...e,kpis:WB(i,e,a.get(e.definitionId))}:e)},async addCycles(e,t){l();let n=d().datasets.find(t=>t.id===e);if(!n)throw new kE(`not_found`,{datasetId:e});let r=n.schema.filter(e=>e.type===`number`&&e.name!==t.timeKey).map(e=>e.name),i=await BB(n.source,t.timeKey,r),a={...Object.fromEntries(n.schema.map(e=>[e.name,e.unit])),[RB]:`s`},o=e=>t.defs.find(t=>t.id===e)?.name??e,s=[];for(let e of t.pick){let r=t.found.find(t=>t.definitionId===e.definitionId&&t.index===e.index&&t.parentIndex===e.parentIndex);if(!r)throw new kE(`not_found`,{reason:`no ${o(e.definitionId)} ${e.index} in the cycles found`});let c=r.parentIndex?`${o(t.cycleId)} ${r.parentIndex} · ${o(r.definitionId)}`:`${o(r.definitionId)} ${r.index}`;s.push(de.addColumns({name:`${n.name} · ${c}`,columns:KB(i,t.timeKey,r),units:a}))}if(t.tables!==!1){let e=JB(t.found,t.cycleId,t.defs,i);s.push(await de.addText(YB(e.cycles),`${n.name} · ${o(t.cycleId)}s.csv`)),e.phases.length&&s.push(await de.addText(YB(e.phases),`${n.name} · Phases.csv`))}return s},async cut(e,t){l();let n=d().datasets.find(t=>t.id===e);if(!n)throw new kE(`not_found`,{datasetId:e});let r;if(t){if(!t.defs.some(e=>e.id===t.cycleId))throw new kE(`invalid_argument`,{reason:`cycleId is not one of defs`});let i=n.schema.filter(e=>e.type===`number`&&e.name!==t.timeKey).map(e=>e.name),a=await BB(n.source,t.timeKey,i),o=t.defs.find(e=>e.id===t.cycleId)?.show,s=e=>[...e.kpis??[],...o&&o.channel!==t.timeKey?[o]:[]],c=new Map(t.defs.filter(e=>s(e).length).map(e=>[e.id,s(e)])),l=VB(a,t.defs).sort((e,t)=>e.tstart-t.tstart||!!e.parentIndex-+!!t.parentIndex).map(e=>c.has(e.definitionId)?{...e,kpis:WB(a,e,c.get(e.definitionId))}:e),u={...Object.fromEntries(n.schema.map(e=>[e.name,e.unit])),[RB]:`s`},d=e=>t.defs.find(t=>t.id===e)?.name??e,f=l.map(r=>xQ(`${e}::${r.definitionId}:${r.parentIndex??0}:${r.index}`,{name:r.parentIndex?`${n.name} · ${d(t.cycleId)} ${r.parentIndex} · ${d(r.definitionId)}`:`${n.name} · ${d(r.definitionId)} ${r.index}`,columns:KB(a,t.timeKey,r),units:u})),p=a.t.length?a.t[a.t.length-1]:NaN,m=l.map(e=>e.tend===null&&p===p?{...e,tend:p,incomplete:!0}:e);r={defs:t.defs,cycleId:t.cycleId,timeKey:t.timeKey,found:m,parts:f}}else if(!n.cut)return 0;if(!d().datasets.some(t=>t.id===e))return 0;i.set(t=>({...t,datasets:t.datasets.map(t=>t.id===e?{...t,cut:r}:t)}));let a=d().selection,o=a.some(t=>t===e||t.startsWith(`${e}::`)),s=a.filter(t=>t!==e&&!t.startsWith(`${e}::`)),c=r?r.parts.filter((e,t)=>!r.found[t].parentIndex).map(e=>e.id):[];return L(o?c.length>0?[...s,...c]:[...s,e]:s),c.length},remove(e){l(),oe([e])},clear(){l(),oe(d().datasets.map(e=>e.id))},async configure(e,t){l();let n=d().datasets.find(t=>t.id===e);if(!n)throw new kE(`not_found`,{datasetId:e});if(t.parseConfig&&(n.kind!==`memory`||!n.parseConfig))throw new kE(`invalid_argument`,{reason:n.parseConfig?`out-of-core datasets cannot be re-parsed`:`binary files have no text parse settings`});if(t.beacon!==void 0&&t.beacon!==null&&n.kind!==`memory`)throw new kE(`invalid_argument`,{reason:`laps need an in-memory dataset`});if(t.beacon!==void 0&&JSON.stringify(t.beacon)!==JSON.stringify(n.beacon??null)){let r=t.beacon??void 0;i.set(t=>({...t,datasets:t.datasets.map(t=>t.id===e?{...t,beacon:r}:t)}));let a=d().selection,o=a.some(t=>t===e||t.startsWith(`${e}::`)),s=a.filter(t=>t!==e&&!t.startsWith(`${e}::`)),c=r?vB(n.data.rows,r.channel):[],l=r&&t.selectCycles===`best`?CB(c.map(e=>SB(n.data.rows,e,r.metric,r.stat))):null,u=l===null?c.map((t,n)=>EB(e,n)):[EB(e,l)];L(o?c.length>0?[...s,...u]:[...s,e]:s)}let r=t.parseConfig;if(!r)return;let a=(()=>{try{let e=H(ze(n.rawText??``),r.headerRow);return n.data.columnNames.length===e.length&&n.data.columnNames.every((t,n)=>t===e[n])}catch{return!1}})();if(ee(r,n.parseConfig)&&a)return;let o=n.fromColumns?DQ(n):n.rawText??``,s=await PE(n.file?{file:n.file,config:r}:{rawText:o,config:r}),c=new LE(s),u=await c.getSchema(),f=n.fromColumns?{rawText:o,fromColumns:!1}:{};i.set(t=>({...t,datasets:t.datasets.map(t=>t.id===e?{...t,...f,data:s,source:c,schema:u,parseConfig:r}:t)})),n.source.dispose().catch(()=>void 0),ae(),n.cut&&await de.cut(e,n.cut);let p=m().selectedDatasets,h=new Set(p.flatMap(e=>e.data.columnNames)),g=s.columnNames.filter(e=>B(s.rows,e)),_=g.find(e=>e===`ET`)??g[0];w(()=>i.set(e=>({...e,worksheets:e.worksheets.map(e=>e1(!h.has(e.xKey)&&_?{...e,xKey:_}:e,e=>h.has(e)))})))},setColor(e,t){l(),i.set(n=>{let r={...n.colors};return t===null?delete r[e]:r[e]=t,{...n,colors:r}})},setOffset(e,t){l(),i.set(n=>({...n,offsets:{...n.offsets,[e]:t}}))},resetOffsets(){l(),i.set(e=>Object.keys(e.offsets).length?{...e,offsets:{}}:e)},select(e){l(),L([...e])},toggle(e){l();let t=d().selection,n=m().laps[e];if(n){let e=n.laps.map(e=>e.id);L(e.every(e=>t.includes(e))?t.filter(t=>!e.includes(t)):[...t,...e.filter(e=>!t.includes(e))]);return}L(t.includes(e)?t.filter(t=>t!==e):[...t,e])},selectAll(){l();let e=m().laps,t=d().live.filter(e=>d().selection.includes(e.id)).map(e=>e.id);L([...d().datasets.flatMap(t=>e[t.id]?e[t.id].laps.map(e=>e.id):[t.id]),...t])},deselectAll(){l(),L([])},raw(e){let t=d().datasets.find(t=>t.id===e);if(!t)throw new kE(`not_found`,{datasetId:e});return{get rawText(){return t.kind===`memory`&&t.fromColumns?DQ(t):t.rawText??``},data:t.data,parseConfig:t.parseConfig??null,kind:t.kind,beacon:t.beacon??null}},async columnBounds(e){l();let t=m(),n=t.selectedDatasets.find(t=>t.schema.some(t=>t.name===e));if(n&&n.kind===`memory`){let t=Sz(n.data.rows,e);if(Number.isFinite(t.min)&&Number.isFinite(t.max))return t}else if(n){let t=await n.source.xBounds(e).catch(()=>null);if(t&&Number.isFinite(t.x0)&&Number.isFinite(t.x1)&&t.x1>=t.x0)return{min:t.x0,max:t.x1}}let r=t.selectedLive.find(t=>t.dataset.columnNames.includes(e));if(r){let t=r.source.valueBoundsSync(e);if(t)return t}let i=fe(e);if(!i)return null;let a=Sz(i.rows,e);return Number.isFinite(a.min)&&Number.isFinite(a.max)?a:null}},fe=(e,t=N().xKey)=>{let n=m();if(!n.merged)return null;if(!n.channels.find(t=>t.name===e))return n.merged;let r=xE(n.merged,n.channels,t);return{...n.merged,columnNames:[...n.merged.columnNames,...r.ok.map(e=>e.name)],rows:r.rows}},pe=(e,t,n)=>m().selectedLive.length>0?{...n,scaleMin:``,scaleMax:``,majorStep:``,minorStep:``}:Q$(fe(e,t),e,n),me={fromFileList:e=>EV(Array.from(e)),async fromDataTransfer(e){return DV(Array.from(e.items??[]).map(e=>e.webkitGetAsEntry?.()).filter(e=>!!e))},canPick:OV,pick:kV,tree:(e,t)=>TV(e,t),isImportable:wV},he={add(e=`Worksheet`){l();let t=d(),n=t.limits.maxWorksheets;n!==null&&t.worksheets.length>=n&&u(`worksheets`);let r={...J$(N().xKey||`ET`),name:e};return i.set(e=>({...e,worksheets:[...e.worksheets,r],activeWorksheetId:r.id})),r.id},rename(e,t){l(),N(e),F(e,e=>e.name===t?e:{...e,name:t})},remove(e){l();let t=d();if(N(e),t.worksheets.length<=1)throw new kE(`invalid_argument`,{reason:`the last worksheet cannot be removed`});let n=t.worksheets.findIndex(t=>t.id===e),r=t.worksheets.filter(t=>t.id!==e);i.set(t=>({...t,worksheets:r,activeWorksheetId:t.activeWorksheetId===e?r[Math.max(0,n-1)].id:t.activeWorksheetId}))},reorder(e,t){l(),i.set(n=>{if(e===t||e<0||t<0||e>=n.worksheets.length||t>=n.worksheets.length)return n;let r=[...n.worksheets],[i]=r.splice(e,1);return r.splice(t,0,i),{...n,worksheets:r}})},activate(e){l(),N(e),i.set(t=>t.activeWorksheetId===e?t:{...t,activeWorksheetId:e,xRanges:{...t.xRanges,[e]:null}})},setXKey(e,t){l(),N(e),F(e,e=>e1({...e,xKey:t},e=>e!==t)),i.set(t=>({...t,xRanges:{...t.xRanges,[e]:null},offsets:{}}))}},ge={mount(e,t,n){return l(),VZ(nt,e,t,n)},openWindow(e,t){return l(),P(e),dQ(nt,e,(t,n)=>VZ(nt,e,t,n),t)},setFonts(e){e.sans&&(Q.sans=e.sans),e.mono&&(Q.mono=e.mono),HZ(nt)},kinds:()=>MQ,label:PQ,add(e,t={}){if(l(),!MQ.some(t=>t.kind===e))throw new kE(`invalid_argument`,{kind:e});let n=N(t.worksheetId),r=d().limits.maxChartsPerWorksheet;r!==null&&n.panels.length>=r&&u(`charts-per-worksheet`);let i={...Xt(e,n.panels),...t.title?{title:t.title}:{}};t.layout&&(i.rect={...t.layout});let a=ir([i],{},q$[2],4)[i.id],o=a,s=m().numericColumns;if(s.length&&(o.kind===`multiband`||o.kind===`xyscatter`||o.kind===`xyzmesh`)&&(o=$$({...n,panels:[i],panelChartSettings:{[i.id]:o}},s).panelChartSettings[i.id],o.kind===`multiband`&&(o={...o,addColumn:s.find(e=>e!==n.xKey)??s[0]})),t.settings&&(o={...o,...t.settings,kind:o.kind}),s.length&&o.kind===`xyscatter`){let e=t.settings??{};o={...o,xyXScale:e.xyXScale??pe(o.xyXCol,n.xKey,o.xyXScale),xyYScale:e.xyYScale??pe(o.xyYCol,n.xKey,o.xyYScale)}}return f(a,o),F(n.id,e=>({...e,panels:t.layout?[...e.panels,i]:Qt([...e.panels,i]),panelChartSettings:{...e.panelChartSettings,[i.id]:o}})),i.id},remove(e){l();let{ws:t}=P(e);F(t.id,t=>{let n={...t.panelChartSettings},r={...t.panelChartBackgrounds};return delete n[e],delete r[e],{...t,panels:Qt(t.panels.filter(t=>t.id!==e)),panelChartSettings:n,panelChartBackgrounds:r}})},rename(e,t){l();let{ws:n}=P(e),r=t?.trim()||void 0;F(n.id,t=>({...t,panels:t.panels.map(t=>{if(t.id!==e)return t;let{title:n,...i}=t;return r?{...i,title:r}:i})}))},update(e,t){l();let{ws:n}=P(e),r=n.panelChartSettings[e],i={...r,...t,kind:r.kind};if(r.kind===`xyscatter`&&i.kind===`xyscatter`){let e=t;typeof e.xyXCol==`string`&&e.xyXCol!==r.xyXCol&&!(`xyXScale`in e)&&(i={...i,xyXScale:pe(e.xyXCol,n.xKey,r.xyXScale)}),typeof e.xyYCol==`string`&&e.xyYCol!==r.xyYCol&&!(`xyYScale`in e)&&(i={...i,xyYScale:pe(e.xyYCol,n.xKey,r.xyYScale)})}f(r,i),I(e,()=>i)},replaceSettings(e,t){l();let{ws:n,panel:r}=P(e);if(t.kind!==r.kind)throw new kE(`invalid_argument`,{reason:`settings kind mismatch`});f(n.panelChartSettings[e],t),I(e,()=>t)},setBackground(e,t){l();let{ws:n}=P(e);F(n.id,n=>({...n,panelChartBackgrounds:{...n.panelChartBackgrounds,[e]:t}}))},addAnnotation(e,t){l(),P(e);let n=Nt({...t,id:t.id||crypto.randomUUID()});if(!n)throw new kE(`invalid_argument`,{reason:`not a valid annotation`});return I(e,e=>({...e,annotations:[...(e.annotations??[]).filter(e=>e.id!==n.id),n]})),n.id},updateAnnotation(e,t,n){l();let r=(P(e).ws.panelChartSettings[e]?.annotations??[]).find(e=>e.id===t);if(!r)throw new kE(`not_found`,{annotationId:t});let i=Nt({...r,...n,id:r.id,kind:r.kind});if(!i)throw new kE(`invalid_argument`,{reason:`not a valid annotation`});I(e,e=>({...e,annotations:(e.annotations??[]).map(e=>e.id===i.id?i:e)}))},removeAnnotation(e,t){l(),P(e),I(e,e=>({...e,annotations:(e.annotations??[]).filter(e=>e.id!==t)}))},setAnnotations(e,t){l(),P(e);let n=Pt(t)??[];I(e,e=>({...e,annotations:n}))},setLayout(e,t){l();let{ws:n}=P(e);F(n.id,n=>({...n,panels:n.panels.map(n=>n.id===e?{...n,rect:{...t}}:n)}))},setLayouts(e,t){l(),F(e,e=>({...e,panels:e.panels.map(e=>t[e.id]?{...e,rect:{...t[e.id]}}:e)}))},autoLayout(e){l(),F(N(e).id,e=>({...e,panels:Qt(e.panels)}))},get(e){let{ws:t,panel:n}=P(e);return h(t,n)},list(e){let t=N(e);return t.panels.map(e=>h(t,e))},async addSeries(e,t){l();let{ws:n}=P(e),r=n.panelChartSettings[e];if(!r||r.kind!==`multiband`)throw new kE(`invalid_argument`,{reason:`not a multiband chart`});let i=d().limits.maxChannelsPerChart;i!==null&&Cz(r)>=i&&u(`channels-per-chart`);let a=m().numericColumns,o=new Set(r.series.map(e=>e.column)),s=t??a.find(e=>e!==n.xKey&&!o.has(e))??a.find(e=>e!==n.xKey)??``;if(!s)return null;let c=sr(),f={id:c,column:s,color:q$[r.series.length%q$.length],bandFromPct:0,bandToPct:100,scaleMin:0,scaleMax:1,yMajorStep:0,yMinorStep:0};return I(e,e=>e.kind===`multiband`?{...e,series:[...e.series,f]}:e),await ge.autoScaleSeries(e,c),c},async updateSeries(e,t,n){l();let{ws:r}=P(e),i=r.panelChartSettings[e],a=i&&i.kind===`multiband`?i.series.find(e=>e.id===t):void 0;if(!a)throw new kE(`not_found`,{seriesId:t});I(e,e=>e.kind===`multiband`?{...e,series:e.series.map(e=>e.id===t?{...e,...n,id:e.id}:e)}:e),n.column&&n.column!==a.column&&n.scaleMin===void 0&&n.scaleMax===void 0&&await ge.autoScaleSeries(e,t)},removeSeries(e,t){l(),I(e,e=>e.kind===`multiband`?{...e,series:e.series.filter(e=>e.id!==t)}:e)},reorderSeries(e,t){l(),I(e,e=>{if(e.kind!==`multiband`)return e;let n=new Map(e.series.map(e=>[e.id,e])),r=t.map(e=>n.get(e)).filter(e=>!!e),i=e.series.filter(e=>!t.includes(e.id));return{...e,series:[...r,...i]}})},async autoScaleSeries(e,t){l();let{ws:r}=P(e),i=r.panelChartSettings[e],a=i&&i.kind===`multiband`?i.series.find(e=>e.id===t):void 0;if(!a)return;let o=await de.columnBounds(a.column);!o||n||I(e,e=>e.kind===`multiband`?{...e,series:e.series.map(e=>e.id===t?{...e,scaleMin:o.min,scaleMax:o.max}:e)}:e)}},_e=new Map,ve={setXRange(e,t){l();let n=N(t).id;i.set(t=>{let r=t.xRanges[n]??null;return r===e||r&&e&&r[0]===e[0]&&r[1]===e[1]?t:{...t,xRanges:{...t.xRanges,[n]:e}}})},resetZoom(e){ve.setXRange(null,e)},setCursorX(e,t){l();let n=N(t).id;(_e.get(n)??null)!==e&&(_e.set(n,e),a.emit(`cursorchange`,{worksheetId:n,x:e}))},cursorX(e){return _e.get(N(e).id)??null},setLiveWindow(e,t){l();let n=N(t);n.liveWindowSeconds!==e&&F(n.id,t=>({...t,liveWindowSeconds:e}))},setSegmentContext(e){l(),i.set(t=>JSON.stringify(t.segmentContext)===JSON.stringify(e)?t:{...t,segmentContext:e})}},ye={save(e){l();let t=e.id??crypto.randomUUID(),[n]=LB([{...e,id:t,parentId:e.parentId??null}].concat(d().cycleRules.filter(e=>e.id!==t))).filter(e=>e.id===t);if(!n)throw new kE(`invalid_argument`,{reason:`not a valid cycle rule (or its parent is missing)`});return i.set(e=>({...e,cycleRules:e.cycleRules.some(e=>e.id===t)?e.cycleRules.map(e=>e.id===t?n:e):[...e.cycleRules,n]})),t},remove(e){l();let t=new Set([e]);for(let e=!0;e;){e=!1;for(let n of d().cycleRules)n.parentId&&t.has(n.parentId)&&!t.has(n.id)&&(t.add(n.id),e=!0)}i.set(e=>({...e,cycleRules:e.cycleRules.filter(e=>!t.has(e.id))}))}},be={create(e){l();let n=d(),r=n.limits.maxMathChannels;r!==null&&n.mathChannels.length>=r&&u(`math-channels`);let o=cr(e);return i.set(e=>({...e,mathChannels:[...e.mathChannels,o]})),Promise.resolve(t.mathChannels?.create(o)).catch(e=>a.emit(`error`,{error:e,context:`mathChannels.create`})),o},update(e,n){l();let r=d().mathChannels.find(t=>t.id===e);if(!r)throw new kE(`not_found`,{channelId:e});i.set(t=>({...t,mathChannels:t.mathChannels.map(t=>t.id===e?{...t,...n,updatedAt:Date.now()}:t)})),r.source!==`workbook`&&Promise.resolve(t.mathChannels?.update(e,n)).catch(e=>a.emit(`error`,{error:e,context:`mathChannels.update`}))},remove(e){l();let n=d().mathChannels.find(t=>t.id===e);if(!n)throw new kE(`not_found`,{channelId:e});i.set(t=>({...t,mathChannels:t.mathChannels.filter(t=>t.id!==e)})),n.source!==`workbook`&&Promise.resolve(t.mathChannels?.remove(e)).catch(e=>a.emit(`error`,{error:e,context:`mathChannels.remove`}))},async importFile(e){l();let{channels:n,errors:r}=await TE(e),a=d(),o=a.limits.maxMathChannels===null?n.length:Math.max(0,a.limits.maxMathChannels-a.mathChannels.length);n.length>0&&o===0&&u(`math-channels`);let s=n.slice(0,o);return i.set(e=>({...e,mathChannels:[...e.mathChannels,...s]})),await t.mathChannels?.importMany(s),{channels:s,errors:r}},async importMany(e){l();let n=d(),r=n.limits.maxMathChannels===null?e.length:Math.max(0,n.limits.maxMathChannels-n.mathChannels.length);e.length>0&&r===0&&u(`math-channels`);let a=e.slice(0,r);return i.set(e=>({...e,mathChannels:[...e.mathChannels,...a]})),await t.mathChannels?.importMany(a),a},exportBlob:()=>CE(d().mathChannels),preview(e,t){let n=m();return n.merged?rE(e,n.merged,N(t).xKey,n.channels.filter(t=>t.id!==e.id)):null},sync(e){l(),i.set(t=>{let n=t.mathChannels.filter(e=>e.source===`workbook`),r=n.length?[...e,...n]:e;return t.mathChannels===r?t:{...t,mathChannels:r}})}},xe=AQ((e,t)=>[...e.flatMap(e=>e.kind===`camera`&&e.video?[DE({...e,video:e.video})]:[]),...t]),Se=``;i.subscribe(()=>{let e=xe(d().live,d().video),t=e.map(e=>`${e.kind}:${e.id}:${e.recordingId??``}:${e.name}`).join(`|`);t!==Se&&(Se=t,a.emit(`videochange`,{sources:e}))});let Ce=(e,t,n)=>e.id===t&&(n===void 0||(e.recordingId??null)===n),we={sources:()=>xe(d().live,d().video),register(e){l(),i.set(t=>({...t,video:[...t.video.filter(t=>!Ce(t,e.id,e.recordingId??null)),e]}))},unregister(e,t){l(),i.set(n=>n.video.some(n=>Ce(n,e,t))?{...n,video:n.video.filter(n=>!Ce(n,e,t))}:n)}},Te={openLocal(e,t){return l(),z.openLocal(e,t)},async connect(e,t,n){l(),await z.connect(e,t,n)},startRecording(e){l(),z.startRecording(e)},stopRecording(e){return l(),z.stopRecording(e)},setSegmentAxis(e,t){l(),z.setSegmentAxis(e,t)},rowCount(e){return z.connections().find(t=>t.id===e)?.source.size()??0},disconnect(e){l(),z.disconnect(e),L(d().selection.filter(t=>t!==e))}},Ee=()=>{d().limits.canImportExportWorkspaces||u(`workspaces-io`)},De=async e=>{if(e instanceof Blob)try{return JSON.parse(await e.text())}catch{throw new kE(`bad_file`)}if(typeof e==`string`)try{return JSON.parse(e)}catch{throw new kE(`bad_file`)}return e},Oe=async e=>e instanceof File?e:new File([JSON.stringify(await De(e))],`import.json`,{type:`application/json`}),ke=e=>e.replace(/[^\w.-]+/g,`_`),Ae=e=>new Blob([JSON.stringify(e,null,2)],{type:`application/json`}),je=e=>{let t=rr(e.panelChartSettings,q$[2],4),n={};for(let r of e.panels)t[r.id]?.kind===r.kind&&(n[r.id]=t[r.id]);return{...e,panelChartSettings:ir(e.panels,n,q$[2],4)}},Me=(e,t)=>e.map(e=>{let n=e=>{let n=t.has(e)?crypto.randomUUID():e;return t.add(n),n},r=new Map(e.panels.map(e=>[e.id,n(e.id)])),i=e=>Object.fromEntries(Object.entries(e).map(([e,t])=>[r.get(e)??e,t]));return{...e,id:n(e.id),panels:e.panels.map(e=>({...e,id:r.get(e.id)})),panelChartSettings:i(e.panelChartSettings),panelChartBackgrounds:i(e.panelChartBackgrounds??{})}}),Ne=()=>new Set(d().worksheets.flatMap(e=>[e.id,...e.panels.map(e=>e.id)])),Pe=(e,t=0)=>{let n=d().limits.maxWorksheets,r=Me((n===null?e:e.slice(0,Math.max(1,n))).map(je),new Set),a=r[Math.min(t,r.length-1)];i.set(e=>({...e,worksheets:r,activeWorksheetId:a.id,xRanges:{}}))},Fe=(e,t)=>{let n=N(t),r=d().limits.maxChartsPerWorksheet;r!==null&&n.panels.length>=r&&u(`charts-per-worksheet`);let i=d().limits.maxChannelsPerChart;i!==null&&Cz(e.settings)>i&&u(`channels-per-chart`);let a=crypto.randomUUID(),o={id:a,kind:e.kind,rect:{x:0,y:0,w:6,h:24},...e.title?{title:e.title}:{}};return F(n.id,t=>({...t,panels:Qt([...t.panels,o]),panelChartSettings:{...t.panelChartSettings,[a]:e.settings},panelChartBackgrounds:e.background===null?t.panelChartBackgrounds:{...t.panelChartBackgrounds,[a]:e.background}})),a},Ie=()=>{let e=d();return cV({worksheets:e.worksheets,activeWorksheetId:e.activeWorksheetId,channels:te(p(e.mathChannels,e.limits.maxMathChannels),e.worksheets),liveWindowSeconds:e.liveWindowSeconds,laps:e.datasets.find(e=>e.beacon)?.beacon??null,segments:e.segmentContext,cycles:e.cycleRules})},Le=e=>{if(e.worksheets.length===0)throw new kE(`bad_workspace`,{errors:e.errors});let{channels:t,rename:n}=Y$(d().mathChannels,e.mathChannels);Pe(n.size?e.worksheets.map(e=>X$(e,n)):e.worksheets,e.activeIndex),i.set(n=>({...n,mathChannels:[...n.mathChannels.filter(e=>e.source!==`workbook`),...t],liveWindowSeconds:e.liveWindowSeconds===void 0?n.liveWindowSeconds:e.liveWindowSeconds,segmentContext:e.segments??null,cycleRules:e.cycles}));let r=e.laps;if(r)for(let e of d().datasets)e.kind!==`memory`||e.beacon||!e.data.columnNames.includes(r.channel)||de.configure(e.id,{beacon:r}).catch(e=>a.emit(`error`,{error:e,context:`io.openWorkbook`}));return{worksheets:e.worksheets.length,errors:e.errors}},Re=e=>{if(e===null)return;let t=m().numericColumns,n=t.length?e.worksheets.map(e=>$$(e,t)):e.worksheets;S=!0;try{i.set(t=>{let r=t=>e.worksheets.some(e=>e.id===t);return{...t,worksheets:n,activeWorksheetId:r(t.activeWorksheetId)?t.activeWorksheetId:r(e.activeWorksheetId)?e.activeWorksheetId:e.worksheets[0].id,xRanges:Object.fromEntries(Object.entries(t.xRanges).filter(([e])=>r(e))),mathChannels:[...t.mathChannels.filter(e=>e.source!==`workbook`),...e.channels],liveWindowSeconds:e.liveWindowSeconds}})}finally{S=!1}E=T(d()),x.rebase(D()),O()},Be={undo(){l(),Re(x.undo())},redo(){l(),Re(x.redo())},clear(){l(),A()}},Ve={hasWork:()=>yV(d().worksheets),exportWorksheet(e){l(),Ee();let t=N(e),n=lV(t);return{json:n,blob:Ae(n),filename:`${ke(t.name||`worksheet`)}.json`}},exportChart(e){l(),Ee();let{ws:t,panel:n}=P(e),r=uV(n,t.panelChartSettings[e],t.panelChartBackgrounds[e]??null);return{json:r,blob:Ae(r),filename:`${ke(n.title?.trim()||n.kind)}.json`}},parseFile:e=>SV(e),exportWorkspace(){l(),Ee();let e=Ie();return{json:e,blob:Ae(e),filename:`kymoscope-workspace-${new Date().toISOString().slice(0,10)}.json`}},async exportWorkspaceEncrypted(e){l(),Ee();let t=typeof e==`string`?await QB(Ie(),e):await $B(Ie(),e);return{json:t,blob:Ae(t),filename:`kymoscope-workbook-${new Date().toISOString().slice(0,10)}.kymo`}},async importWorkspace(e,t={}){l(),Ee();let n=await De(e);return eV(n)&&(n=await rV(n,t)),j(()=>Le(vV(n)))},toWorkbook:Ie,openWorkbook(e){return l(),j(()=>Le(vV(e)))},async importWorksheet(e){l(),Ee();let t=d();t.limits.maxWorksheets!==null&&t.worksheets.length>=t.limits.maxWorksheets&&u(`worksheets`);let n=await SV(await Oe(e));if(n.type!==`worksheet`)throw new kE(`bad_file`,{found:n.type});let[r]=Me([je(n.worksheet)],Ne());return i.set(e=>({...e,worksheets:[...e.worksheets,r],activeWorksheetId:r.id})),r.id},async importChart(e,t){l(),Ee();let n=await SV(await Oe(e));if(n.type!==`chart`)throw new kE(`bad_file`,{found:n.type});return Fe(n.chart,t)},snapshot(){let e=d();return{datasets:e.datasets,worksheets:e.worksheets,activeWorksheetId:e.activeWorksheetId,selection:e.selection}},restore(e){l();let t=new Set(e.datasets);for(let e of d().datasets)t.has(e)||e.source.dispose().catch(()=>void 0);let n=e.worksheets.length?e.worksheets.map(je):[J$()];j(()=>i.set(t=>({...t,datasets:e.datasets,worksheets:n,activeWorksheetId:n.some(t=>t.id===e.activeWorksheetId)?e.activeWorksheetId:n[0].id,selection:e.selection,xRanges:{},offsets:{},colors:{}})))},reset(){l(),j(()=>{oe(d().datasets.map(e=>e.id));let e=J$();i.set(t=>({...t,worksheets:[e],activeWorksheetId:e.id,xRanges:{},offsets:{},colors:{},mathChannels:t.mathChannels.filter(e=>e.source!==`workbook`)}))})}},He={merged(e){let t=m();if(!t.merged||t.channels.length===0)return t.merged;let n=xE(t.merged,t.channels,N(e).xKey);return{...t.merged,columnNames:[...t.merged.columnNames,...n.ok.map(e=>e.name)],units:[...t.merged.units,...n.ok.map(e=>e.units)],rows:n.rows}},plotted(){return m().merged}},Ue=typeof location<`u`?location.hostname:``,We=t.license,Ge=t.licenseKey,Ke=!1,Je={},Ye=e=>{n||i.set(t=>({...t,licensed:e}))},Xe=(e,t,n)=>{clearTimeout(Je[e]);let r=Math.max(0,t-Date.now()),i=r>2**31-1;Je[e]=setTimeout(()=>{i?Xe(e,t,n):n()},i?2**31-1:r)},Ze=e=>Xe(`renew`,e,()=>void $e()),Qe=e=>Xe(`expiry`,e*1e3+1e3,()=>{FV(Ge,Ue).then(e=>{n||Ye(e.ok)})});async function $e(){let e=36e5,t,r=null,i;try{t=await Promise.race([We.get(),new Promise((e,t)=>{i=setTimeout(()=>t(Error(`timeout`)),3e4)})]),r=await FV(t,Ue)}catch{}finally{clearTimeout(i)}if(n)return!1;if(r?.ok)return Ge=t,Ke=!0,Ye(!0),Qe(r.exp),Ze(Math.max(r.exp*1e3-168*e,Date.now()+e)),!0;console.warn(`[kymoscope] license renewal failed (${r?r.reason:`license.get failed or timed out`}): keeping the current key`);let a=await FV(Ge,Ue);return n?!1:(Ye(a.ok),Ze(Date.now()+e),a.ok)}let et=!We||t.licenseKey?FV(t.licenseKey,Ue).then(e=>(e.ok||console.warn(`[kymoscope] license ${e.reason}: showing attribution`),!Ke&&!n&&(Ye(e.ok),e.ok&&We&&Qe(e.exp)),e.ok)):null,tt=We?$e():et;S=!1,A();let nt={getState:M,subscribe(e){return i.subscribe(e)},on:a.on,licensed:tt,isLicensed:()=>d().licensed,setOptions(e){if(l(),t={...t,...e},e.live&&z.setRelay(e.live.relay),e.palette&&o(),e.limits){let t={...d().limits,...e.limits};i.set(e=>{let n=t.maxWorksheets===null?e.worksheets:e.worksheets.slice(0,Math.max(1,t.maxWorksheets)),r=n.some(t=>t.id===e.activeWorksheetId)?e.activeWorksheetId:n[0].id;return{...e,limits:t,activeWorksheetId:r}})}},datasets:de,folders:me,worksheets:he,charts:ge,view:ve,mathChannels:be,cycles:ye,live:Te,video:we,io:Ve,history:Be,data:He,alerts:{setRules:e=>{l();let t=ce.setRules(e);return i.set(e=>({...e,alertRules:ce.rules()})),t},rules:ce.rules,state:ce.state,evaluate:(e,t)=>(l(),ce.evaluate(e,t)),clearMarks:ce.clearMarks},marks:{list:()=>d().marks},dispose(){if(!n){n=!0,clearTimeout(Je.renew),clearTimeout(Je.expiry),s(),fQ(nt),UZ(nt),z.dispose();for(let e of d().datasets)e.source.dispose().catch(()=>void 0);a.emit(`dispose`,void 0),a.clear()}}};return r1.set(nt,{store:i,derived:m,live:z,alertLines:()=>le(d().alertRules,d().alerts)}),nt}var r1=new WeakMap;function i1(e){let t=r1.get(e);if(!t)throw new kE(`invalid_argument`,{reason:`not a Kymoscope engine`});return t}var a1=2e3,o1=3;function s1(e){let t=e[0].v.fragCount,n=new Map;for(let r of e)r.v.fragCount===t&&!n.has(r.v.fragIndex)&&n.set(r.v.fragIndex,r);let r=[];for(let e=0;e<t;e++){let t=n.get(e);if(!t)return null;r.push(t.v.payload)}let i=n.get(0),a=r[0];if(t>1){a=new Uint8Array(r.reduce((e,t)=>e+t.length,0));for(let e=0,n=0;e<t;e++)a.set(r[e],n),n+=r[e].length}return{t:i.v.t,seq:i.v.seq,key:i.v.key,data:a,arrivedAt:i.at}}function c1(e){let t=[],n=0;for(;n<e.length&&e[n].v.fragIndex>0&&e[n].v.seq===e[0].v.seq;)t.push(e[n++]);let r=[],i=[],a=[];for(;n<=e.length;n++){let t=e[n];if(a.length&&(!t||t.v.seq!==a[0].v.seq)){let e=s1(a);e?r.push(e):t||(i=a),a=[]}t&&a.push(t)}return{head:t,units:r,tail:i}}var l1=class{kind=`recorded`;id;name;parentId;parentName;recordingId;chunks;fetch;open;maxBytes;cache=new Map;sizes=new Map;bytes=0;width=0;height=0;codec=``;waiting=null;constructor(e){this.id=e.id,this.name=e.name,this.parentId=e.parentId,this.parentName=e.parentName??null,this.recordingId=e.recordingId,this.chunks=[...e.chunks].sort((e,t)=>e.seq-t.seq),this.fetch=e.fetchChunk,this.open=e.open,this.maxBytes=e.maxBytes??256*1024*1024}async parse(e){let t=new Uint8Array(await this.fetch(this.chunks[e].seq)),n=[];for(let e of ae(t).messages){let t=null;try{t=await ye(this.open,e.bytes.slice().buffer)}catch{}if(t?.kind!==6)continue;let r=YQ(t.plaintext);r&&(r.key&&r.fragIndex===0&&!this.codec&&(this.codec=r.codec,this.width=r.width,this.height=r.height),n.push({v:r,at:e.at}))}let r=c1(n),i=e=>e.reduce((e,t)=>e+t.v.payload.length,0);return{...r,bytes:r.units.reduce((e,t)=>e+t.data.length,0)+i(r.head)+i(r.tail)}}parsed(e){let t=this.cache.get(e);if(t)return this.cache.delete(e),this.cache.set(e,t),t;let n=this.parse(e);return this.cache.set(e,n),n.then(t=>{this.cache.get(e)===n&&(this.sizes.set(e,[t.bytes,t.units.length]),this.bytes+=t.bytes,this.evict(e))},()=>{this.cache.get(e)===n&&this.cache.delete(e)}),n}evict(e){for(let t of this.cache.keys()){if(this.bytes<=this.maxBytes)return;let n=this.sizes.get(t);t===e||!n||(this.bytes-=n[0],this.sizes.delete(t),this.cache.delete(t))}}async units(e){let t;try{t=await this.parsed(e)}catch{return[]}if(t.full)return t.full;if(!t.tail.length||e+1>=this.chunks.length)return t.full=t.units;let n=await this.parsed(e+1).catch(()=>null);if(!n)return t.units;let r=null;try{r=s1([...t.tail,...n.head.filter(e=>e.v.seq===t.tail[0].v.seq)])}catch{}return t.full=r?[...t.units,r]:t.units}async seekPlan(e){let t=this.chunks.length;if(!t)return[];let n=e*1e3,r=0;for(;r+1<t&&this.chunks[r+1].t0<=n;)r++;let i=r,a=r+1<t&&this.chunks[r+1].t0-n<a1?r+1:r,o=(await Promise.all(Array.from({length:a-i+1},(e,t)=>this.units(i+t)))).flat(),s=()=>{let t=o.length-1;for(;t>=0&&o[t].t>e;)t--;let n=t;for(;n>=0&&!o[n].key;)n--;return[n,t]},[c,l]=s();for(let e=0;c<0&&i>0&&e<o1;e++)o=[...await this.units(--i),...o],[c,l]=s();return a+1<t&&this.units(a+1),c<0?[]:o.slice(c,l+1)}ready(){return this.waiting??=(async()=>{for(let e=0;e<Math.min(this.chunks.length,o1+1)&&!this.codec;e++)await this.units(e);this.codec||(this.waiting=null)})()}info(){let e=0;for(let[,t]of this.sizes.values())e+=t;return{width:this.width,height:this.height,codec:this.codec,latestT:this.range()?.[1]??null,lagMs:null,units:e,bytes:this.bytes}}range(){let e=this.chunks.length;return e?[this.chunks[0].t0/1e3,this.chunks[e-1].t1/1e3]:null}},u1=1e4,d1=72e4,f1=3e5,p1=3e4,m1=1e4,h1=1e4,g1=64*1024,_1=50,v1=class extends Error{status;code;detail;constructor(e,t,n){super(`${n} (${t})`),this.status=e,this.code=t,this.detail=n}},y1=e=>Uint8Array.from(atob(e),e=>e.charCodeAt(0)),b1=class{opts;deps;auth;secret;password;token=``;ticket=``;ticketRec=!1;authRec=!1;relayUrl=null;apiKeyId=null;projectId=null;e2ee=!1;sid=null;salt=``;key=null;raw=null;epoch=0;haveKey=!1;sealed=null;device=null;senderDeviceId=null;deviceRetried=!1;maxBytesPerSec=0;maxMessageBytes=g1;ws=null;open=!1;everOpen=!1;connectedAt=0;authAt=0;delay=1e3;lastToken=0;viewerCount=0;busy=!1;stopped=!1;refusal=null;heartbeatTimer=null;pingTimer=null;retryTimer=null;statusFns=new Set;viewerFns=new Set;lastStatus=``;constructor(e,t){let{auth:n,secret:r}=ue(e.apiKey);if(!r)throw Error(`This API key has no encryption secret (created before keys carried one). Create a new API key in Kymoscope.`);if(e.kind===`camera`&&!e.parentStreamId)throw Error(`A camera is added to one of your live streams: choose its stream (parentStreamId).`);if(!!e.layer!=!!e.lowOf)throw Error(`A low layer needs both layer: 'low' and lowOf (its high camera's stream id).`);if(e.layer&&e.kind!==`camera`)throw Error(`Only a camera has a low layer.`);if(e.visibility===`open`&&e.password)throw Error(`An open stream has no password: anyone may watch it. Remove the password, or use visibility 'private'.`);this.opts=e,this.deps=t,this.auth=n,this.secret=r,this.password=e.visibility===`open`?Ce:e.password||r}get streamId(){return this.sid}get viewers(){return this.viewerCount}get limits(){return{maxBytesPerSec:this.maxBytesPerSec,maxMessageBytes:this.maxMessageBytes}}onStatus(e){return this.statusFns.add(e),()=>{this.statusFns.delete(e)}}onViewers(e){return this.viewerFns.add(e),()=>{this.viewerFns.delete(e)}}async start(){this.emit();try{let e=await this.deps.store.load();this.salt=e?.salt??L();let t=await this.mint();this.token=t.token,this.relayUrl=t.relayUrl??null,this.maxBytesPerSec=t.maxBytesPerSec||0,this.maxMessageBytes=t.maxMessageBytes||g1,this.apiKeyId=t.apiKeyId??null;let n=t.project;this.e2ee=!!n?.e2ee;let r={};if(this.e2ee){this.projectId=n?.id??null;let t=e?.apiKeyId===this.apiKeyId;this.device=t&&e?.device||await Qe(),t&&e?.streamKey?{key:this.key,epoch:this.epoch,sealed:this.sealed}=e.streamKey:this.key=await z(O()),r.sender_device=await this.senderDevice()}else this.raw=y1(await _(this.password,this.salt)),this.key=await z(this.raw);let i=await this.register(e?.streamId??null,r);if(this.sid=i.stream.id,this.ticket=i.ticket,this.ticketRec=!!i.recording,this.e2ee?(this.senderDeviceId=i.sender_device_id??null,this.projectId=i.project?.id??this.projectId,await this.save(),await this.applyProject(i.project)):(await this.save(),await this.wrapFor(i.devices)),!this.relayUrl)throw Error(`stream-token returned no relayUrl`)}catch(e){throw e instanceof v1&&e.status>=400&&e.status<500&&this.refuse(e),e}this.stopped||(this.lastToken=this.deps.now(),this.connect(),this.heartbeatTimer=setInterval(()=>{this.housekeeping()},u1),this.emit())}async send(e,t){let n=this.key,r=this.e2ee?this.epoch&255:void 0;if(this.stopped||!this.open||!n||this.e2ee&&!this.haveKey)return!1;let i=await _e(n,e,t,r),a=this.ws;if(!this.open||!a)return!1;try{return a.send(i),!0}catch{return!1}}stop(){this.stopped=!0,this.heartbeatTimer&&clearInterval(this.heartbeatTimer),this.retryTimer&&clearTimeout(this.retryTimer),this.heartbeatTimer=this.retryTimer=null;let e=this.ws;if(this.disconnect(),e){e.onopen=e.onmessage=e.onclose=null;try{e.close(1e3)}catch{}}}async post(e,t,n){let r;try{r=await this.deps.fetch(`${this.opts.supabaseUrl.replace(/\/+$/,``)}/functions/v1/${e}`,{method:`POST`,headers:t,body:n===void 0?void 0:JSON.stringify(n)})}catch(e){throw new v1(0,`network`,e?.message??String(e))}let i=await r.text(),a=null;try{a=JSON.parse(i)}catch{}if(r.status!==200)throw new v1(r.status,a?.error??`error`,a?.message??a?.error??i);return a}mint(){return this.post(`stream-token`,{"x-api-key":this.auth})}call(e){return this.post(`stream-publisher`,{Authorization:`Bearer ${this.token}`,"Content-Type":`application/json`},e)}async register(e,t){let n={action:`register`,name:this.opts.name,salt:this.salt,key_check:await p(this.key),visibility:this.opts.visibility??`private`,kind:this.opts.kind,...t};return this.opts.kind===`camera`&&(n.parent_stream_id=this.opts.parentStreamId),this.opts.layer&&(n.layer=this.opts.layer,n.low_of=this.opts.lowOf),e&&(n.stream_id=e),this.call(n)}async senderDevice(){let e=this.device.publicKey;return{public_key:e,binding:await He(await Fe(this.secret),this.apiKeyId??``,e)}}async housekeeping(){if(!(this.busy||this.stopped)){this.busy=!0;try{let e=this.deps.now();if(e-this.lastToken>=d1){this.lastToken=e;try{this.token=(await this.mint()).token}catch{return}}if(this.e2ee){let e=await this.call({action:`heartbeat`,stream_id:this.sid,sender_device_id:this.senderDeviceId,epoch:this.haveKey?this.epoch:0});this.setTicket(e.ticket,!!e.recording),await this.applyProject(e.project)}else{let e=await this.call({action:`heartbeat`,stream_id:this.sid});this.setTicket(e.ticket,!!e.recording),await this.wrapFor(e.devices)}}catch(e){e instanceof v1&&(e.status===401||e.status===403)&&this.refuse(e)}finally{this.busy=!1}}}async wrapFor(e){let t=[];for(let n of e??[])try{t.push({device_id:n.id,wrapped:await ve(n.public_key,this.raw,`${this.sid}|${n.id}`)})}catch{}if(t.length)try{await this.call({action:`wrap_keys`,stream_id:this.sid,keys:t.slice(0,_1)})}catch{}}async applyProject(e){if(!this.e2ee||!e)return;let t=e.key;if(!t){this.emit();return}let n=Number(t.epoch);if(this.haveKey&&n<=this.epoch)return;let r;try{r=await Ke(this.device.privateKey,t.wrapped,ne(this.projectId,n,this.senderDeviceId))}catch{if(this.deviceRetried)return;this.deviceRetried=!0,this.device=await Qe(),await this.reregister();return}let i=Oe(this.sid,this.projectId,n),a=this.key,o=n===this.epoch?this.sealed:null;if(o)try{await b(r,o,i)}catch{o=null}if(!o){let e=O();a=await z(e),o=await Ve(r,e,i),e.fill(0)}try{await this.call({action:`wrap_keys`,stream_id:this.sid,sender_device_id:this.senderDeviceId,project_wrap:{epoch:n,iv:o.iv,ct:o.ct}})}catch{return}this.stopped||(this.key=a,this.sealed=o,this.epoch=n,this.haveKey=!0,await this.save(),this.emit())}async reregister(){let e;try{e=await this.register(this.sid,{sender_device:await this.senderDevice()})}catch{return}this.ticket=e.ticket,this.ticketRec=!!e.recording,this.senderDeviceId=e.sender_device_id??null;let t=e.stream.id;if(t!==this.sid){this.sid=t;let e=this.ws;if(e){this.disconnect(),e.onopen=e.onmessage=e.onclose=null;try{e.close(1e3)}catch{}this.connect()}}await this.save(),await this.applyProject(e.project),this.deviceRetried=!1}async save(){try{await this.deps.store.save({apiKeyId:this.apiKeyId,streamId:this.sid,salt:this.salt,device:this.e2ee?this.device:null,streamKey:this.e2ee&&this.haveKey?{epoch:this.epoch,key:this.key,sealed:this.sealed}:null})}catch{}}connect(){if(this.retryTimer=null,this.stopped)return;let e=this.relayUrl.replace(/\/+$/,``).replace(/^http(s?):\/\//,`ws$1://`),t;try{t=new this.deps.WebSocket(`${e}/v1/streams/${this.sid}/publish`,[FQ,`bearer.${this.ticket}`])}catch{this.dropped();return}t.binaryType=`arraybuffer`,this.ws=t,t.onopen=()=>{t===this.ws&&(this.open=this.everOpen=!0,this.connectedAt=this.authAt=this.deps.now(),this.authRec=this.ticketRec,this.pingTimer=setInterval(()=>{try{t.send(`ping`)}catch{}},p1),this.emit())},t.onmessage=e=>{if(!(t!==this.ws||typeof e.data!=`string`||!e.data.startsWith(`{`)))try{let t=JSON.parse(e.data);t?.type===`viewers`&&this.setViewers(Number(t.count)||0)}catch{}},t.onclose=()=>{t===this.ws&&this.dropped()}}disconnect(){this.ws=null,this.open=!1,this.pingTimer&&clearInterval(this.pingTimer),this.pingTimer=null,this.setViewers(0)}dropped(){let e=this.open&&this.deps.now()-this.connectedAt>=h1;if(this.disconnect(),this.stopped)return;let t=0;e?this.delay=1e3:(t=this.delay,this.delay=Math.min(this.delay*2,m1)),this.retryTimer=setTimeout(()=>this.connect(),t),this.emit()}setTicket(e,t){this.ticket=e,this.ticketRec=t;let n=this.deps.now();if(t||(this.authRec=!1),!(!this.open||!this.ws)&&!(n-this.authAt<f1&&!(t&&!this.authRec)))try{this.ws.send(JSON.stringify({type:`auth`,token:e})),this.authAt=n,this.authRec=t}catch{}}setViewers(e){if(e!==this.viewerCount){this.viewerCount=e;for(let t of this.viewerFns)t(e);this.emit()}}refuse(e){this.refusal={code:e.code,message:e.detail},this.emit(),this.stop()}status(){return this.refusal?{phase:`refused`,...this.refusal}:this.sid?this.e2ee&&!this.haveKey?{phase:`waiting_approval`}:this.open?{phase:`live`,viewers:this.viewerCount}:this.everOpen?{phase:`reconnecting`}:{phase:`registering`}:{phase:`registering`}}emit(){let e=this.status(),t=JSON.stringify(e);if(t!==this.lastStatus){this.lastStatus=t;for(let t of this.statusFns)t(e)}}},x1={"720p30":{width:1280,height:720,fps:30,kbps:2e3},"1080p30":{width:1920,height:1080,fps:30,kbps:4e3}},S1={width:640,height:360,fps:15,kbps:400},C1=[`avc1.640028`,`avc1.4d0028`,`avc1.42e028`],w1=[`avc1.64001f`,`avc1.4d001f`,`avc1.42e01f`],T1=2,E1=1e3,D1=1e3;async function*O1(e){if(typeof MediaStreamTrackProcessor<`u`){let t=new MediaStreamTrackProcessor({track:e}).readable.getReader();try{for(;;){let{value:e,done:n}=await t.read();if(n)return;yield e}}finally{t.cancel().catch(()=>{})}}let t=document.createElement(`video`);t.muted=!0,t.playsInline=!0,t.srcObject=new MediaStream([e]),await t.play();try{for(;e.readyState===`live`;)await new Promise(e=>t.requestVideoFrameCallback(()=>e())),yield new VideoFrame(t,{timestamp:Math.round(performance.now()*1e3)})}finally{t.pause(),t.srcObject=null}}function k1(){let e=null;return(t,n,r)=>(e??=new OffscreenCanvas(n,r).getContext(`2d`),e.drawImage(t,0,0,n,r),new VideoFrame(e.canvas,{timestamp:t.timestamp}))}var A1=class{encoder=null;codec=``;error=null;unsubscribe=null;lastKey=-1/0;keyPending=!1;resume=!0;lastViewers=0;encoding=!1;dropped=0;seq=0;times=new Map;window=[];sending=Promise.resolve();publisher;preset;keyframeMs;Encoder;now;constructor(e,t,n,r,i){this.publisher=e,this.preset=t,this.keyframeMs=n,this.Encoder=r,this.now=i}async configure(){let{width:e,height:t,fps:n,kbps:r}=this.preset,i=this.publisher.limits.maxBytesPerSec,a=i>0?Math.min(r*1e3,i*8/1.25):r*1e3,o=null;for(let r of t>720?C1:w1){let i={codec:r,width:e,height:t,bitrate:a,framerate:n,avc:{format:`annexb`},latencyMode:`realtime`,bitrateMode:`constant`};if((await this.Encoder.isConfigSupported(i)).supported===!0){o=i;break}}return o?(this.codec=o.codec,this.encoder=new this.Encoder({output:e=>this.onChunk(e),error:e=>{this.error=e.message||String(e),this.closeEncoder()}}),this.encoder.configure(o),this.lastViewers=this.publisher.viewers,this.unsubscribe=this.publisher.onViewers(e=>{e>this.lastViewers&&(this.keyPending=!0),this.lastViewers=e}),!0):!1}ready(){let e=this.encoder;return this.encoding=!!e&&!this.error&&this.publisher.viewers>0,!e||!this.encoding?(this.resume=!0,!1):e.encodeQueueSize>T1?(this.dropped++,!1):!0}encode(e){let t=this.now(),n=t-this.lastKey,r=this.resume||n>=this.keyframeMs||this.keyPending&&n>=E1;r&&(this.lastKey=t,this.keyPending=this.resume=!1);let i=(performance.timeOrigin+e.timestamp/1e3)/1e3;Math.abs(i-Date.now()/1e3)>60&&(i=Date.now()/1e3),this.times.set(e.timestamp,i),this.encoder.encode(e,{keyFrame:r})}onChunk(e){let t=new Uint8Array(e.byteLength);e.copyTo(t);let n=this.times.get(e.timestamp)??Date.now()/1e3;this.times.delete(e.timestamp);let{width:r,height:i}=this.preset,a=XQ({key:e.type===`key`,t:n,seq:this.seq++,width:r,height:i,codec:this.codec,data:t});for(let e of a)this.sending=this.sending.then(()=>this.publisher.send(6,e)).catch(()=>!1);this.window.push({at:this.now(),bytes:t.length})}get queue(){return this.encoder?.state===`configured`?this.encoder.encodeQueueSize:0}stats(){let e=this.now();for(;this.window.length&&e-this.window[0].at>=D1;)this.window.shift();let t=this.window.reduce((e,t)=>e+t.bytes,0);return{fps:this.window.length,kbps:t*8/1e3,viewers:this.publisher.viewers,encoding:this.encoding}}stop(){this.encoding=!1,this.closeEncoder(),this.unsubscribe?.(),this.unsubscribe=null}closeEncoder(){this.encoder&&this.encoder.state!==`closed`&&this.encoder.close()}},j1=class{high;lowOpt;low=null;lowAt=-1/0;keyframeMs;Encoder;now;frames;scale;stopped=!1;statsFns=new Set;lastStats=-1/0;constructor(e,t,n={}){this.keyframeMs=(t.keyframeS??2)*1e3,this.Encoder=n.VideoEncoder??VideoEncoder,this.now=n.now??Date.now,this.frames=n.frames??O1,this.scale=n.scale??k1(),this.high=new A1(e,t.preset,this.keyframeMs,this.Encoder,this.now),this.lowOpt=t.low?{publisher:t.low.publisher,preset:t.low.preset??S1}:null}async start(e){if(!await this.high.configure())throw new kE(`camera_codec_unsupported`);if(this.lowOpt){let e=new A1(this.lowOpt.publisher,this.lowOpt.preset,this.keyframeMs,this.Encoder,this.now);await e.configure()&&(this.low=e)}this.loop(e)}async loop(e){for await(let t of this.frames(e)){if(this.stopped){t.close();break}try{this.onFrame(t)}finally{t.close()}this.emitStats()}}onFrame(e){this.high.ready()&&this.high.encode(e);let t=this.low;if(!t)return;let n=this.now();if(n-this.lowAt<750/t.preset.fps||!t.ready())return;this.lowAt=n;let r=this.scale(e,t.preset.width,t.preset.height);try{t.encode(r)}finally{r.close()}}stats(){return{...this.high.stats(),dropped:this.high.dropped,queue:this.high.queue,error:this.high.error,low:this.low?this.low.stats():null}}onStats(e){return this.statsFns.add(e),()=>{this.statsFns.delete(e)}}emitStats(){let e=this.now();if(e-this.lastStats<D1||!this.statsFns.size)return;this.lastStats=e;let t=this.stats();for(let e of this.statsFns)e(t)}stop(){this.stopped=!0,this.high.stop(),this.low?.stop()}},M1=class{#e;constructor(e){this.#e=e}head(){let e=this.#e;return`${e.map(e=>r$(e.name)).join(`,`)}\n${e.map(e=>r$(e.unit)).join(`,`)}\n`}append(e){let t=e.columns,n=``;for(let r=0;r<e.length;r++){for(let e=0;e<t.length;e++){let i=t[e][r];n+=(e?`,`:``)+(Number.isNaN(i)?``:String(i))}n+=`
618
- `}return n}end(){}},N1=new TextEncoder,P1=e=>e+7&-8,F1=104,I1=64,L1=104,R1=160,z1=4;function B1(e,t,n){let r=24+t.length*8+n.length,i=new Uint8Array(P1(r)),a=new DataView(i.buffer);return i.set(N1.encode(e),0),a.setBigUint64(8,BigInt(r),!0),a.setBigUint64(16,BigInt(t.length),!0),t.forEach((e,t)=>a.setBigUint64(24+t*8,BigInt(e),!0)),i.set(n,24+t.length*8),i}var V1=(e,t)=>B1(e,[],N1.encode(`${t}\0`)),H1=e=>BigInt(Math.round(e))*1000000n,U1=class{#e;#t;#n;#r=0;constructor(e,t,n){this.#e=e,this.#t=t?Date.parse(t):Date.now(),this.#n=n}append(e){let t=e.columns,n=t.length,r=new Float64Array(e.length*n);for(let i=0;i<e.length;i++)for(let e=0;e<n;e++)r[i*n+e]=t[e][i];return this.#r+=e.length,new Uint8Array(r.buffer)}end(){if(this.#r!==this.#n)throw Error(`The recording changed while it was exported (${this.#r} of ${this.#n} rows).`)}head(){let e=this.#e.length,t=[],n=64+F1,r=e=>{let r=n;return t.push(e),n+=e.length,r},i=r(V1(`##MD`,`<FHcomment><TX>Kymoscope cloud recording</TX><tool_id>Kymoscope</tool_id><tool_vendor>Kymoscope</tool_vendor><tool_version>1</tool_version></FHcomment>`)),a=new Uint8Array(16);new DataView(a.buffer).setBigUint64(0,H1(this.#t),!0);let o=r(B1(`##FH`,[0,i],a)),s=this.#e.map(e=>r(V1(`##TX`,e.name))),c=this.#e.map(e=>e.unit?r(V1(`##TX`,e.unit)):0),l=n,u=l+I1,d=this.#e.map((e,t)=>u+L1+t*R1),f=B1(`##DG`,[0,u,u+L1+e*R1,0],new Uint8Array(8)),p=new Uint8Array(32),m=new DataView(p.buffer);m.setBigUint64(8,BigInt(this.#n),!0),m.setUint32(24,e*8,!0);let h=B1(`##CG`,[0,d[0],0,0,0,0],p),g=this.#e.map((t,n)=>{let r=new Uint8Array(72),i=new DataView(r.buffer);return i.setUint8(0,n===0?2:0),i.setUint8(1,+(n===0)),i.setUint8(2,z1),i.setUint32(4,n*8,!0),i.setUint32(8,64,!0),i.setUint8(20,255),B1(`##CN`,[n+1<e?d[n+1]:0,0,s[n],0,0,0,c[n],0],r)}),_=new Uint8Array(24);_.set(N1.encode(`##DT`),0),new DataView(_.buffer).setBigUint64(8,BigInt(24+this.#n*e*8),!0);let v=new Uint8Array(64);v.set(N1.encode(`MDF 4.10 Kymoscop`),0),new DataView(v.buffer).setUint16(28,410,!0);let y=new Uint8Array(32);new DataView(y.buffer).setBigUint64(0,H1(this.#t),!0);let b=[v,B1(`##HD`,[l,o,0,0,0,0],y),...t,f,h,...g,_],x=new Uint8Array(b.reduce((e,t)=>e+t.length,0));return b.reduce((e,t)=>(x.set(t,e),e+t.length),0),x}},W1={csv:`text/csv`,mf4:`application/octet-stream`,parquet:`application/vnd.apache.parquet`};async function G1(e,t,n,r={}){let i=uz(`krc`,{main:new File(e.chunks,`${e.name}.krc`),companions:[],keys:e.keys},r.signal,r.createWorker);try{let e=await i.plan(),a=[{group:0,channels:e.groups[0].channels.map((e,t)=>t)}],o=t===`csv`?new M1(QR(e,a)):new U1(QR(e,a),e.startTime,e.groups[0].samples);await n(o.head()),await i.read(a,`stream`,{chunk:async e=>{await n(o.append(e))},progress:r.onProgress}),o.end()}finally{i.close()}}async function K1(e,t,n={}){let r=[];return await G1(e,t,e=>{r.push(e)},n),new Blob(r,{type:W1[t]})}var q1=(e,t)=>`khd1|${e.stream}|${e.day}|${e.kind}|${e.level}|${t}`;function J1(e){if(e.length<9)throw Error(`Not a Kymoscope day file (too short)`);let t=e.subarray(e.length-9);if(String.fromCharCode(t[5],t[6],t[7],t[8])!==`KHD1`)throw Error(`Not a Kymoscope day file`);if(t[4]!==1)throw Error(`Unknown Kymoscope day file format ${t[4]}`);return new DataView(t.buffer,t.byteOffset,4).getUint32(0,!0)}var Y1=new TextEncoder;async function X1(e,t,n,r){let i=await crypto.subtle.decrypt({name:`AES-GCM`,iv:t.subarray(0,12),additionalData:Y1.encode(q1(n,r))},e,t.subarray(12));return new Uint8Array(i)}async function Z1(e,t,n){let r=JSON.parse(new TextDecoder().decode(le(await X1(e,t,n,`footer`))));if(r.format!==1||r.stream!==n.stream||r.day!==n.day||r.kind!==n.kind||r.level!==n.level)throw Error(`This day file belongs to another history or day`);return r}var Q1=0;async function $1(e,t){let n=await zL(),r=e.map(()=>`khd_${++Q1}.parquet`),i=[];try{for(let t=0;t<e.length;t++)await n.registerFileBuffer(r[t],e[t]),i.push(r[t]);let a=await n.connect();try{return await t(r,e=>a.query(e))}finally{await a.close()}}finally{for(let e of i)await n.dropFile(e).catch(()=>void 0)}}var e0=(e,t)=>e.getChild(t).toArray();function t0(){$1([],async(e,t)=>{await t(`COPY (SELECT 1::BIGINT AS t) TO 'khd_warm.parquet' (FORMAT parquet)`),await t(`SELECT t FROM read_parquet('khd_warm.parquet')`)}).catch(()=>void 0)}async function n0(e,t){return $1([e],async([e],n)=>{let r=await n(`SELECT (t::DOUBLE / 1e6) AS t${t.map(e=>`, coalesce("c${e}", 'NaN'::FLOAT) AS "c${e}"`).join(``)} FROM read_parquet('${e}') ORDER BY t`);return{t:Float64Array.from(e0(r,`t`)),cols:t.map(e=>Float32Array.from(e0(r,`c${e}`)))}})}async function r0(e){return e.some(e=>e.channels.length)?$1(e.map(e=>e.bytes),async(t,n)=>{let r=await n(`SELECT k, (t::DOUBLE / 1e6) AS t, ch, "min", "max" FROM (${t.flatMap((t,n)=>e[n].channels.length?[`SELECT ${n} AS k, t, ch, "min", "max" FROM read_parquet('${t}') WHERE ch IN (${e[n].channels.join(`,`)})`]:[]).join(` UNION ALL `)}) ORDER BY k, ch, t`),i=e0(r,`k`),a=e0(r,`t`),o=e0(r,`ch`),s=e0(r,`min`),c=e0(r,`max`),l=[];for(let t=0,n=0;t<e.length;t++){let e=n;for(;e<i.length&&i[e]===t;)e++;l.push({t:Float64Array.from({length:e-n},(e,t)=>a[n+t]),ch:Int32Array.from({length:e-n},(e,t)=>o[n+t]),min:Float32Array.from({length:e-n},(e,t)=>s[n+t]),max:Float32Array.from({length:e-n},(e,t)=>c[n+t])}),n=e}return l}):e.map(()=>({t:new Float64Array,ch:new Int32Array,min:new Float32Array,max:new Float32Array}))}var i0=2*1024**3;async function a0(){try{return await(await navigator.storage.getDirectory()).getDirectoryHandle(`kymoscope-history`,{create:!0})}catch{return null}}async function o0(){try{let e=(await navigator.storage.estimate()).quota??0;return e>0?Math.min(i0,e*.2):i0}catch{return i0}}function s0(e=a0,t=o0){let n=null,r=null,i=0,a=()=>n??=e().catch(()=>null),o=e=>e.replace(/[^A-Za-z0-9._-]/g,`_`),s=()=>r??=(async()=>{let e=new Map,t=await a();if(i=0,t)for await(let[n,r]of t.entries()){if(r.kind!==`file`||!r.getFile)continue;let t=await r.getFile();e.set(n,{size:t.size,at:t.lastModified}),i+=t.size}return e})().catch(e=>{throw r=null,e});return{async get(e){try{let t=await a();return t?new Uint8Array(await(await(await t.getFileHandle(o(e))).getFile()).arrayBuffer()):null}catch{return null}},async put(e,n){try{let r=await a();if(!r)return;let c=await s(),l=o(e),u=await(await r.getFileHandle(l,{create:!0})).createWritable();try{await u.write(n),await u.close()}catch(e){throw await u.abort?.().catch(()=>void 0),e}i+=n.length-(c.get(l)?.size??0),c.set(l,{size:n.length,at:Date.now()});let d=await t();if(i<=d)return;for(let[e,t]of[...c].sort((e,t)=>e[1].at-t[1].at)){if(i<=d*.9)break;try{await r.removeEntry(e)}catch{continue}c.delete(e),i-=t.size}}catch{}}}}var c0=16,l0=2e3,u0=512*1024,d0=64*1024,f0=64*1024,p0=8*1024*1024;function m0(e,t=l0){for(let n of[3600,60])if(e/n>=t/2)return n;return 0}var h0={0:[0,60,3600],60:[60,3600,0],3600:[3600,60,0]};function g0(e,t){let n=new Map;for(let t of e)n.set(t.day,[...n.get(t.day)??[],t]);let r=[];for(let[,e]of[...n].sort((e,t)=>e[0].localeCompare(t[0]))){let n=h0[t].map(t=>e.find(e=>e.level===t)).find(Boolean);n&&r.push(n)}return r}async function _0(e,t,n){let r=Array(e.length),i=0;return await Promise.all(Array.from({length:Math.min(t,e.length)},async()=>{for(;i<e.length;){let t=i++;r[t]=await n(e[t])}})),r}function v0(e){let t=[];for(let n of[...e].sort((e,t)=>e.off-t.off)){let e=t[t.length-1];e&&n.off-e.end<=f0&&n.off+n.len-e.start<=p0?e.end=Math.max(e.end,n.off+n.len):t.push({start:n.off,end:n.off+n.len})}return t}var y0=(e,t)=>({stream:e.historyStreamId,day:t.day,kind:t.kind,level:t.level}),b0=(e,t)=>async(n,r,i)=>{let a=t.get(n.id);return a?a.subarray(r,i):(e.signal?.throwIfAborted(),e.fetchRange(n.id,r,i,e.signal))};async function x0(e,t,n=new Map){let r=e.footers?.get(t.id);if(r)return r;let i=await e.cache?.get(`${t.id}/footer`)??null;if(!i){t.bytes<=u0&&n.set(t.id,await e.fetchRange(t.id,0,t.bytes,e.signal));let r=b0(e,n),a=await r(t,Math.max(0,t.bytes-d0),t.bytes),o=J1(a);i=o+9<=a.length?a.slice(a.length-9-o,a.length-9):(await r(t,t.bytes-9-o,t.bytes-9)).slice(),await e.cache?.put(`${t.id}/footer`,i)}let a=await Z1(await e.key(t.keyId),i,y0(e,t));return e.footers?.set(t.id,a),a}var S0=e=>e?.code===`missing`;async function C0(e){let t=async()=>{let t=g0(e.segments,e.level).map(e=>e.id).join(),n=await e.relist();return g0(n,e.level).map(e=>e.id).join()===t?null:n},n,r;try{n=await w0(e)}catch(n){if(!e.relist||e.signal?.aborted||!(r=await t()))throw n;return w0({...e,segments:r})}return!n.missingDays.length||!e.relist||e.signal?.aborted||!(r=await t())?n:w0({...e,segments:r})}async function w0(e){let t=g0(e.segments,e.level),n=new Set(e.channels),r=new Map,i=b0(e,r),a=new Set,o=async(t,n)=>{try{return await n()}catch(n){if(e.onMissing!==`gap`||!S0(n))throw n;return a.add(t.id),null}},s=await _0(t,16,t=>o(t,()=>x0(e,t,r))),c={},l={},u=[];t.forEach((t,r)=>{let i=s[r];if(i){l[t.day]=t.level;for(let e of i.channels)n.has(e.n)&&e.u&&!c[e.n]&&(c[e.n]=e.u);i.blocks.forEach((r,a)=>{if(r.t1<e.t0||r.t0>e.t1)return;let o=r.ch.filter(e=>n.has(i.channels[e].n));o.length&&u.push({s:t,f:i,i:a,chs:o})})}});let d=new Map;await _0(u,16,async t=>{let n=await e.cache?.get(`${t.s.id}/${t.i}`);n&&d.set(t,n)});let f=new Map;for(let e of u)d.has(e)||f.set(e.s.id,[...f.get(e.s.id)??[],e]);await _0([...f.values()].flatMap(e=>v0(e.map(e=>e.f.blocks[e.i])).map(t=>({js:e,r:t}))),16,async({js:t,r:n})=>{let r=await o(t[0].s,()=>i(t[0].s,n.start,n.end));if(r)for(let i of t){let t=i.f.blocks[i.i];if(t.off<n.start||t.off+t.len>n.end)continue;let a=r.slice(t.off-n.start,t.off-n.start+t.len);d.set(i,a),e.cacheWrite!==!1&&await e.cache?.put(`${i.s.id}/${i.i}`,a)}});let p=[],m=[];return await _0(u.filter(e=>!a.has(e.s.id)),16,async t=>{let n=await X1(await e.key(t.s.keyId),d.get(t),y0(e,t.s),t.i);if(t.s.kind===`rollup`){m.push({j:t,plain:n});return}let r=await n0(n,t.chs),i=new Map(t.chs.map((e,n)=>[t.f.channels[e].n,r.cols[n]])),a=hQ({t:r.t,lo:i,hi:i,level:0},e.t0,e.t1);a&&p.push(a)}),(await r0(m.map(e=>({bytes:e.plain,channels:e.j.chs})))).forEach((t,n)=>{let{j:r}=m[n],i=r.s.level/2;for(let n=0;n<t.ch.length;){let a=n;for(;a<t.ch.length&&t.ch[a]===t.ch[n];)a++;let o=r.f.channels[t.ch[n]].n,s=hQ({t:t.t.slice(n,a).map(e=>e+i),lo:new Map([[o,t.min.slice(n,a)]]),hi:new Map([[o,t.max.slice(n,a)]]),level:r.s.level},e.t0,e.t1);s&&p.push(s),n=a}}),{pieces:p.sort((e,t)=>e.t[0]-t.t[0]),units:c,levels:l,missingDays:t.filter(e=>a.has(e.id)).map(e=>e.day)}}var T0=25e6,E0=3e7,D0=1<<20,O0=8192,k0=65536;function A0(e){for(let t=1;t<10;t++){let n=+e.toPrecision(t);if(Math.fround(n)===e)return String(n)}return String(e)}function j0(e){let t=Math.round(e*1e6),n=Math.floor(t/1e6);return`${new Date(n*1e3).toISOString().slice(0,19)}.${String(t-n*1e6).padStart(6,`0`)}Z`}function M0(e,t){let n=e.filter(e=>t.some(t=>e.lo.has(t))).map(e=>e.t),r=new Float64Array(n.reduce((e,t)=>e+t.length,0)),i=0;for(let e of n)r.set(e,i),i+=e.length;r.sort();let a=0;for(let e=0;e<r.length;e++)(a===0||r[e]!==r[a-1])&&(r[a++]=r[e]);let o=r.slice(0,a);if(o.length*t.length>25e6)throw Error(`too_wide`);let s=t.map(()=>new Float32Array(o.length).fill(NaN));for(let n of e)t.forEach((e,t)=>{let r=n.lo.get(e);if(r){for(let e=0,i=pQ(o,n.t[0]);e<n.t.length;e++)if(r[e]===r[e]){for(;o[i]<n.t[e];)i++;s[t][i]=r[e]}}});return{t:o,cols:s}}async function N0(e,t,n,r={}){if(!e.channels.length)throw Error(`Pick at least one channel to export.`);let i=[...new Set(e.segments.map(e=>e.day))].sort(),a=i.map(t=>e.segments.find(e=>e.day===t&&e.kind===`raw`)).filter(e=>!!e),o=i.filter(e=>!a.some(t=>t.day===e)),s=new Set,c=()=>({skippedDays:[...o,...s].sort(),missingDays:[...s].sort()}),l=async t=>{let n=await C0({...e,segments:[t],level:0,cacheWrite:!1,relist:e.relist&&(async()=>(await e.relist()).filter(e=>e.day===t.day&&e.kind===`raw`))});for(let e of n.missingDays)s.add(e);return n},u=e=>r.onProgress?.((e+1)/a.length);if(t===`parquet`)return await F0(a,l,e.channels,n,u),c();if(t===`csv`){let t=!1;for(let[r,i]of a.entries()){let a=await l(i);!t&&!a.missingDays.length&&(await n(`time,${e.channels.map(r$).join(`,`)}\nUTC,${e.channels.map(e=>r$(a.units[e]??``)).join(`,`)}\n`),t=!0);let o=M0(a.pieces,e.channels);for(let e=0;e<o.t.length;e+=O0){let t=``;for(let n=e;n<Math.min(o.t.length,e+O0);n++){t+=j0(o.t[n]);for(let e of o.cols)t+=e[n]===e[n]?`,${A0(e[n])}`:`,`;t+=`
619
- `}await n(t)}u(r)}return t||await n(`time,${e.channels.map(r$).join(`,`)}\n`),c()}let d=0,f=NaN,p={};for(let t of a){let n=await l(t),r=M0(n.pieces,e.channels);d+=r.t.length,Number.isNaN(f)&&r.t.length&&(f=r.t[0]),p={...n.units,...p}}let m=new U1([{name:`time`,unit:`s`,text:!1},...e.channels.map(e=>({name:e,unit:p[e]??``,text:!1}))],Number.isNaN(f)?null:new Date(f*1e3).toISOString(),d);await n(m.head());for(let[t,r]of a.entries()){let i=M0((await l(r)).pieces,e.channels),a=i.t.map(e=>e-f);for(let e=0;e<i.t.length;e+=k0){let t=Math.min(i.t.length,e+k0);await n(m.append({length:t-e,columns:[a.subarray(e,t),...i.cols.map(n=>Float64Array.from(n.subarray(e,t)))]}))}u(t)}return m.end(),c()}var P0=0;async function F0(e,t,n,r,i,a={max:E0,chunk:D0}){let o=await zL(),s=await o.connect(),c=++P0,l=`khd_values_${c}`,u=`khd_names_${c}`,d=`khd_export_${c}.parquet`,f=new Float64Array(a.chunk),p=new Int32Array(a.chunk),m=new Float32Array(a.chunk),h=0,g=0,_=async()=>{h&&await s.insertArrowTable(dF({time:f.slice(0,h),ch:p.slice(0,h),value:m.slice(0,h)}),{name:l,create:!1}),h=0};try{await s.query(`CREATE TABLE ${u} (ch INTEGER, channel VARCHAR)`),await s.query(`INSERT INTO ${u} VALUES ${n.map((e,t)=>`(${t}, '${e.replace(/'/g,`''`)}')`).join(`, `)}`),await s.query(`CREATE TABLE ${l} (time DOUBLE, ch INTEGER, value FLOAT)`);for(let[r,o]of e.entries()){for(let e of(await t(o)).pieces)for(let[t,r]of n.entries()){let n=e.lo.get(r);if(n){for(let r=0;r<n.length;r++)if(n[r]===n[r]){if(++g>a.max)throw Object.assign(Error(`This export has more than ${(a.max/1e6).toLocaleString(`en-US`)} million values, too many for Parquet in the browser: export a shorter range or fewer channels.`),{code:`too_large`});f[h]=e.t[r],p[h]=t,m[h]=n[r],++h===a.chunk&&await _()}}}await _(),i(r)}await o.registerEmptyFileBuffer(d),await s.query(`COPY (SELECT to_timestamp(v.time) AS time, n.channel, v.value FROM ${l} v JOIN ${u} n USING (ch)
620
- ORDER BY v.time, n.channel) TO '${d}' (FORMAT parquet, COMPRESSION zstd)`),await r(await o.copyFileToBuffer(d))}finally{await s.query(`DROP TABLE IF EXISTS ${l}; DROP TABLE IF EXISTS ${u}`).catch(()=>void 0),await s.close(),await o.dropFile(d).catch(()=>void 0)}}export{mZ as ANNOTATION_CONTROLS_ATTR,Ot as ANNOTATION_KINDS,m$ as AxisState,_B as BEACON_STATS,x1 as CAMERA_PRESETS,er as CHART_ALARM_FIELDS,MQ as CHART_KINDS,RB as CYCLE_TIME,j1 as CameraSender,jB as CycleRunner,MB as CycleSet,Rt as DASHBOARD_GRID_COLS,Bt as DASHBOARD_GRID_GAP_PX,zt as DASHBOARD_GRID_ROWS,qz as DATASET_PALETTE,kt as DEFAULT_ANNOTATION_WIDTH,en as DEFAULT_AXIS_LINE,nn as DEFAULT_BEACON,tn as DEFAULT_GRID_LINE,fn as DEFAULT_TRACE_WIDTH,dn as DEFAULT_XYZ_POINT_RADIUS,un as DEFAULT_XY_POINT_RADIUS,E$ as DELTA_SUFFIX,W1 as EXPORT_TYPES,ST as FUNCTION_REFERENCE,l0 as HISTORY_PIXELS,_Q as HistoryDataSource,CV as IMPORTABLE_EXT,ke as KIND_VIDEO,nB as KPI_STATS,xe as KRC_HEADER_BYTES,hB as KpiAcc,kE as KymoscopeError,nt as LEAF_KEYS,qe as LIVE_TIME_COLUMN,S1 as LOW_PRESET,b1 as LivePublisher,u$ as MAX_BAND_CELLS,l$ as MAX_GRID,Un as MAX_PANEL_CAMERAS,E0 as MAX_PARQUET_VALUES,T0 as MAX_WIDE_CELLS,Wt as MIN_PANEL_H,Ut as MIN_PANEL_W,Ce as OPEN_STREAM_PASSWORD,c0 as RANGE_PARALLEL,l1 as RecordedVideoSource,gB as RuleRunner,Ft as SEVERITY_HEX,W$ as UNLIMITED,KQ as VIDEO_MAX_FRAGMENT,QT as WINDOW_FN_NAMES,C as WORKBOOK_EXPORT_AAD,w as alertRuleAad,h$ as alignSegment,Qt as arrangeAutoLayout,d$ as axisColumn,S$ as bandEdges,CB as bestCycleIndex,D as bindKeyAad,q1 as blockAad,s0 as blockCache,kW as buildEquation,CE as buildMathChannelsBlob,v$ as buildReference,TV as buildTree,Vn as cameraLabel,tr as chartAlarm,Cz as chartChannelCount,PQ as chartLabel,m0 as chooseLevel,or as clampPct,Kt as clampRectForKind,hQ as clipPiece,v0 as coalesce,Zn as coerceAlarmLine,Nt as coerceAnnotation,RY as colorAt,Jz as colorForDataset,$z as colorSchemeOf,VY as colorsCss,B as columnIsNumeric,aB as compareOp,C$ as compareToReference,EW as computePolyFit,DW as computeR2,n1 as createEngine,et as createRuleEvaluator,KB as cutCycle,AB as cycleRuleChannels,JB as cycleTables,yB as cyclicChannels,T$ as decodeBand,YQ as decodeVideo,IX as decorateColumnLabel,Mn as defaultAreaChartPanelSettings,An as defaultBarChartPanelSettings,yn as defaultBoxPlotPanelSettings,Pn as defaultBubbleChartPanelSettings,Rn as defaultCalibrationPanelSettings,Hn as defaultCameraPanelSettings,Nn as defaultCdfChartPanelSettings,Cn as defaultConfusionPanelSettings,En as defaultControlChartPanelSettings,Yz as defaultDatasetPalette,On as defaultEmbeddingPanelSettings,kn as defaultFlameGraphPanelSettings,Bn as defaultGanttPanelSettings,Ln as defaultGaugePanelSettings,xn as defaultHeatmapPanelSettings,gn as defaultHistogramPanelSettings,Tn as defaultLossCurvePanelSettings,pn as defaultMultibandPanelSettings,Dn as defaultParallelCoordsPanelSettings,_n as defaultPolarPanelSettings,zn as defaultQQPlotPanelSettings,jn as defaultRadarPanelSettings,wn as defaultRocPanelSettings,In as defaultSankeyPanelSettings,bn as defaultSpectrogramPanelSettings,vn as defaultSpectrumPanelSettings,Fn as defaultTreemapPanelSettings,Sn as defaultViolinPanelSettings,$t as defaultXyAxisScaleSettings,mn as defaultXyPanelSettings,hn as defaultXyzPanelSettings,HB as definitionChannels,f as deriveKey,_ as deriveRawKeyBase64,S as deviceFingerprint,qt as dragLayout,w$ as encodeBand,JQ as encodeVideo,$B as encryptWorkbookFile,ir as ensurePanelSettingsForPanels,rE as evalChannel,tB as eventWithin,N0 as exportHistoryTo,K1 as exportRecording,G1 as exportRecordingTo,tE as extractFreeIdentifiers,A0 as f32text,VB as findCycles,J1 as footerLength,Gz as formatClockTick,Kz as formatClockValue,TB as formatLapValue,XQ as fragmentVideo,A as generateApiToken,Qe as generateDeviceKeyPair,i as generateRecoveryKeyPair,L as generateSalt,Uz as getClockTimeZone,ze as getRawNonEmptyLines,_$ as gridAt,bB as guessBeaconChannel,h as hashToken,F as historyKeyAad,z as importStreamKey,y as inferParseConfig,Fz as isClockAxis,wV as isImportable,FX as isMathChannelName,j0 as isoMicros,UB as kpiColumn,rB as kpiKey,WB as kpisOf,O$ as liveSegmentTracker,fB as localDay,p$ as localSeconds,p as makeKeyCheck,Lt as markToAnnotation,sn as newGaugeItem,cr as newMathChannel,Xt as newPanel,sB as newResetState,sr as newSeriesId,wz as niceMajorStep,eB as observeColorScheme,pR as openDatasetFromText,Z1 as openFooter,ye as openMessage,X1 as openSealed,b as openUnderProjectKey,Re as openWithKey,v as openWithPassword,Wn as panelCameras,H as parseColumnNames,ee as parseConfigsEqual,LB as parseCycleDefinitions,k as parseDatasetWithConfig,eE as parseFormula,ae as parseKrc,Pe as parseKrcHeader,TE as parseMathChannelsFile,ln as parseOptionalAxisRange,rr as parsePanelChartSettingsMap,te as parseRecoveryCode,g0 as pickSegments,_0 as pool,x$ as pooledSd,BY as presetStops,V as projectConfigKeyAad,ne as projectWrapAad,O as randomKey,x0 as readFooter,C0 as readHistoryRange,BB as readSource,je as recordingKeyAad,Be as recordingKeySealAad,e as recoveryAttestationAad,me as recoveryCode,We as recoveryKeyAad,Ne as recoveryPrivateKey,jX as referenceBands,g$ as resample,cB as resetStep,$n as resolveLinkedAlarms,YB as rowsCsv,iB as ruleChannels,_e as sealMessage,Ve as sealUnderProjectKey,Se as sealWithKey,oe as sealWithPassword,Fe as senderBindKey,He as senderBinding,Hz as setClockTimeZone,mB as shiftDay,mQ as slicePiece,gQ as splicePieces,ue as splitApiKey,vB as splitLaps,Oe as streamKeyAad,t as subsampleIndices,Wz as subscribeClockTimeZone,xB as suggestBeacon,rt as thresholdOf,dB as tzOffsetS,Ke as unwrapForDevice,fe as unwrapStreamKey,tt as validateRule,ge as verifyKeyCheck,FV as verifyLicense,Le as verifySenderBinding,t0 as warmHistoryDecoder,M0 as wideDay,Ae as workbookBodyAad,XB as workbookExportAad,tV as workbookFileInfo,be as workbookKeyAad,ve as wrapForDevice,pB as zonedInstant};
612
+ `),j=dt(()=>{let e=a.filter(e=>e.kind!==`memory`).flatMap(e=>xz(e.schema));return e.length?e:null},[a]),M=dt(()=>a.some(e=>e.kind!==`memory`)||!_&&a.some(e=>e.data.rows.length>zX),[a,_]),N=dt(()=>bX(p.connections.filter(e=>i.includes(e.id)),a.length,M,f,s),[M,a,p.connections,i,s,f]),P=dt(()=>{if(!_||a.length===0||M)return null;let e=a.map((e,t)=>{let n=e.data.rows;return{rows:n.length>0&&typeof n[0][f]==`number`?n:O[t]??n,offset:s[e.id]??0}});if(!N)for(let t of p.connections)i.includes(t.id)&&e.push({rows:t.dataset.rows,offset:s[t.id]??0});return JX(e,f)},[_,a,M,O,s,f,p.connections,i,N]),F=C&&`okByPart`in C?C.okByPart:void 0,I=dt(()=>{if(!M)return[];let e=T.map((e,t)=>({live:`live`in e&&!!e.live,source:`live`in e&&e.live?e.live.source:e.source,columnSet:new Set(`live`in e&&e.live?e.data.columnNames:e.schema.map(e=>e.name)),keySuffix:E?`__${t}`:``,xOffset:s[e.id]??0,key:`${e.id}|${E?t:``}`}));return T.forEach((t,n)=>{let r=F?.[n],i=O[n];`live`in t&&t.live||!r?.length||!i||e.push({...e[n],live:!1,source:GX(i,r,f),columnSet:new Set([f,...r]),key:`${e[n].key}|channels`})}),e},[M,T,E,s,F,O,f]),L=dt(()=>{let e=C?.parts??(w?[w]:[]),t=new Set;for(let n of e)for(let e of CX(n.columnNames,n.rows))t.add(e);let n=w?w.columnNames.filter(e=>t.has(e)):[],r=[...new Set(j?[...n,...j]:n)];if(A===``)return r;let i=new Set(r),a=A.split(`
613
+ `).filter(e=>!i.has(e));return a.length?[...r,...a]:r},[k,A,j]),R=dt(()=>{let e=[];for(let t of u){if(t.kind!==`multiband`)continue;let n=d[t.id],r=n&&n.kind===`multiband`?n.series:[];e.push([t.id,[...new Set(r.map(e=>e.column).filter(e=>e!==f))]])}return JSON.stringify(e)},[u,d,f]),z=dt(()=>{let e={};if(!w||M)return e;for(let[t,r]of JSON.parse(R)){let i=[];if(r.length>0)if(!E)i.push(n(w.rows,f,r,zX));else{let e=Math.max(1,Math.floor(zX/T.length));for(let t=0;t<T.length;t++){let a=T[t];if(N&&`live`in a&&a.live)continue;let o=O[t]??a.data.rows;i.push(n(o,f,r,e,`__${t}`,s[a.id]??0))}}e[t]=i}return e},[w,R,f,E,T,s,O,N,M]),B=dt(()=>{let e={};if(!w)return e;for(let t of u){if(t.kind!==`multiband`)continue;let n=d[t.id],r=(n&&n.kind===`multiband`?n.series:[]).filter(e=>e.column!==f),i=n&&n.kind===`multiband`?n.layout:`overlay`,a=e=>qX(e,i),o;if(!E)o=a(r);else{let e=a(r);o=[];for(let t=0;t<T.length;t++){let n=Jz(c,T[t].id,t,l);for(let r of e)o.push({...r,id:`${r.id}__${t}`,column:`${r.column}__${t}`,color:n})}}let u=z[t.id]??[],p=E&&n?.kind===`multiband`&&n.envelope?r.flatMap(e=>{let t=_X(u.flatMap((t,n)=>{let r=t.cols.get(`${e.column}__${n}`);return r?[{x:t.x,y:r}]:[]}),UX);return t?[{seriesId:e.id,color:e.color,...t}]:[]}):void 0,m=T.flatMap((e,t)=>`bands`in e&&e.bands?NX(e,f,r,E?Jz(c,e.id,t,l):void 0,s[e.id]??0):[]),h=[...p??[],...m];e[t.id]={effectiveSeries:o,points:u,envelopes:h.length?h:void 0}}return e},[w,u,d,f,E,T,c,l,s,z]),V=dt(()=>{let e={pts:{},colorMeta:{},datasetColors:{}};if(!w)return e;let t={},n={},i={},a=HX,o=T.map((e,t)=>({id:e.id,rows:O[t]??m[e.id]??e.data.rows,full:a(e)})),s={id:`single`,rows:w.rows,full:T.length===1?a(T[0]):void 0};for(let e of u){if(e.kind!==`xyscatter`)continue;let a=d[e.id];if(!a||a.kind!==`xyscatter`)continue;let{xyXCol:u,xyYCol:p}=a;if(!u||!p){t[e.id]={length:0,x:[],y:[]};continue}if(E){let{cols:n,colors:a}=wW(o,u,p,{xKey:f,viewXRange:r,colorOverrides:c,palette:l});t[e.id]=n,i[e.id]=a;continue}let m=CW(s,u,p,{xKey:f,viewXRange:r,colorCol:a.xyColorCol||void 0});t[e.id]=m?.cols??{length:0,x:[],y:[]},m?.color&&(n[e.id]=m.color)}return{pts:t,colorMeta:n,datasetColors:i}},[w,u,d,r,f,E,T,m,c,l,O]),ee=K(new Map),te=dt(()=>{let e={};if(!w)return e;let t={length:0,x:[],y:[],z:[]},{rows:n}=w,i=D;for(let a of u){if(a.kind!==`xyzmesh`)continue;let o=d[a.id];if(!o||o.kind!==`xyzmesh`)continue;if(o.xyzMode===`matrix`){let r=(o.xyzColumns??[]).flatMap(e=>{let t=_W(n,e,i);return t?[t]:[]}),s=r[0]?.length??0,c=r.length;if(s<2||c<2){e[a.id]={points:t};continue}let l=ee.current.get(a.id);l?.length!==s*c&&ee.current.set(a.id,l=new Float32Array(s*c)),r.forEach((e,t)=>l.set(e.length===s?e:e.subarray(0,s),t*s));let u=_W(n,f,i),d=u&&!(o.xyzColumns??[]).includes(f)&&u.length>=s&&Number.isFinite(u[0])&&Number.isFinite(u[s-1])?[u[0],u[s-1]]:[0,s-1];e[a.id]={points:t,surface:{w:s,h:c,values:l,x:d,y:[0,c-1]}};continue}let{xyzXCol:s,xyzYCol:c,xyzZCol:l}=o,u=s?_W(n,s,i):void 0,p=c?_W(n,c,i):void 0,m=l?_W(n,l,i):void 0;if(!u||!p||!m){e[a.id]={points:t};continue}let h=r?_W(n,f,i):void 0;if(!r||!h){e[a.id]={points:{length:Math.min(u.length,p.length,m.length),x:u,y:p,z:m}};continue}let[g,_]=r,v=0;for(let e=0;e<h.length;e++)h[e]>=g&&h[e]<=_&&v++;let y=new Float64Array(v),b=new Float64Array(v),x=new Float64Array(v);for(let e=0,t=0;e<h.length;e++)h[e]>=g&&h[e]<=_&&(y[t]=u[e],b[t]=p[e],x[t]=m[e],t++);e[a.id]={points:{length:v,x:y,y:b,z:x}}}return e},[w,u,d,r,f,D]),H=dt(()=>{let e={};if(!w)return e;for(let t of u){if(t.kind!==`histogram`)continue;let n=d[t.id];e[t.id]=n?.kind===`histogram`&&n.histColumn&&vW(w.rows,n.histColumn,D)||new Float64Array}return e},[w,u,d,D]),ne=dt(()=>{let e={};if(!w)return e;for(let t of u){if(t.kind!==`polar`)continue;let n=d[t.id],r=n?.kind===`polar`&&n.polarAngleCol?_W(w.rows,n.polarAngleCol,D):void 0,i=n?.kind===`polar`&&n.polarRadiusCol?_W(w.rows,n.polarRadiusCol,D):void 0;e[t.id]=r&&i?{angles:r,radii:i}:{angles:[],radii:[]}}return e},[w,u,d,D]),re=(e,t,n,r)=>{let i=t&&vW(e,t,D)||new Float64Array,a=n?_W(e,n,D):void 0;return{signal:i,rate:a&&bW(a)||parseFloat(r)||1}},ie=dt(()=>{let e={};if(!w)return e;for(let t of u){if(t.kind!==`spectrum`)continue;let n=d[t.id];n?.kind===`spectrum`&&(e[t.id]=re(w.rows,n.specSignalCol,n.specTimeCol,n.specSampleRate))}return e},[w,u,d,D]),U=dt(()=>{let e={};if(!w)return e;for(let t of u){if(t.kind!==`boxplot`)continue;let n=d[t.id];e[t.id]=n?.kind===`boxplot`&&n.boxValueCol?yW(w.rows,n.boxValueCol,n.boxGroupCol||void 0,D):[]}return e},[w,u,d,D]),ae=dt(()=>{let e={};if(!w)return e;for(let t of u){if(t.kind!==`spectrogram`)continue;let n=d[t.id];n?.kind===`spectrogram`&&(e[t.id]=re(w.rows,n.sgSignalCol,n.sgTimeCol,n.sgSampleRate))}return e},[w,u,d,D]),oe=dt(()=>{if(!w)return{};let e={};for(let t of u){if(t.kind!==`heatmap`)continue;let n=d[t.id];if(!n||n.kind!==`heatmap`){e[t.id]={cells:[],xLabels:[],yLabels:[]};continue}if(n.hmMode===`matrix`){let r=w.rows,i=n.hmColumns.flatMap(e=>{let t=_W(r,e,D);return t?[{name:e,v:t}]:[]}),a=i.reduce((e,t)=>Math.min(e,t.v.length),i.length?1/0:0),o=_W(r,f,D),s,c;if(n.hmSpacing===`values`){o&&Mq(o.subarray(0,a))&&(s=Float64Array.from(o.subarray(0,a)));let e=i.map(e=>({c:e,v:parseFloat(e.name)})).sort((e,t)=>t.v-e.v);e.length&&Mq(e.map(e=>e.v).reverse())&&(i=e.map(e=>e.c),c=Float64Array.from(e,e=>e.v))}let l=i.length,u=new Float32Array(a*l);i.forEach((e,t)=>u.set(e.v.subarray(0,a),t*a));let d=e=>String(o?+o[e].toPrecision(6):e+1);e[t.id]={cells:[],xLabels:[],yLabels:i.map(e=>e.name),grid:{w:a,h:l,values:u,xLabels:d,yLabels:i.map(e=>e.name)},xCentres:s,yCentres:c}}else if(n.hmMode===`correlation`){let r=n.hmColumns.filter(e=>L.includes(e));if(r.length<2){e[t.id]={cells:[],xLabels:r,yLabels:r};continue}let i=r.map(e=>{let t=[];for(let n of w.rows){let r=n[e];typeof r==`number`&&Number.isFinite(r)&&t.push(r)}return t}),a=i.map(e=>e.reduce((e,t)=>e+t,0)/(e.length||1)),o=[];for(let e=0;e<r.length;e++)for(let t=0;t<r.length;t++){let n=i[e],s=i[t],c=a[e],l=a[t],u=Math.min(n.length,s.length),d=0,f=0,p=0;for(let e=0;e<u;e++){let t=n[e]-c,r=s[e]-l;d+=t*r,f+=t*t,p+=r*r}let m=f>0&&p>0?d/Math.sqrt(f*p):+(e===t);o.push({x:r[t],y:r[e],value:m})}e[t.id]={cells:o,xLabels:r,yLabels:r}}else if(n.hmMode===`binned`||n.hmMode===`count`){let{hmXCol:r,hmYCol:i}=n,a=n.hmMode===`count`?``:n.hmValueCol;if(!r||!i||n.hmMode===`binned`&&!a){e[t.id]={cells:[],xLabels:[],yLabels:[]};continue}let o=e=>{let t=parseFloat(e);return Number.isFinite(t)?t:void 0};e[t.id]=IX(w.rows,{xCol:r,yCol:i,valueCol:a,xBins:n.hmXBins,yBins:n.hmYBins,xMin:o(n.hmXMin),xMax:o(n.hmXMax),yMin:o(n.hmYMin),yMax:o(n.hmYMax)})}else{let{hmXCol:r,hmYCol:i,hmValueCol:a}=n;if(!r||!i||!a){e[t.id]={cells:[],xLabels:[],yLabels:[]};continue}let o=new Map,s=new Set,c=new Set;for(let e of w.rows){let t=String(e[r]??``),n=String(e[i]??``),l=e[a];if(typeof l!=`number`||!Number.isFinite(l))continue;s.add(t),c.add(n);let u=`${t}\0${n}`,d=o.get(u)??{sum:0,count:0};o.set(u,{sum:d.sum+l,count:d.count+1})}let l=e=>{let t=[...e];return t.every(e=>e.trim()!==``&&Number.isFinite(Number(e)))?t.sort((e,t)=>Number(e)-Number(t)):t.sort()},u=l(s),d=l(c),f,p;if(n.hmSpacing===`values`){let e=Float64Array.from(u,Number),t=Float64Array.from(d,Number);Mq(e)&&(f=e),Mq(t)&&(d=[...d].reverse(),p=t.reverse())}let m=[];for(let e of d)for(let t of u){let n=o.get(`${t}\0${e}`);m.push({x:t,y:e,value:n?n.sum/n.count:0})}e[t.id]={cells:m,xLabels:u,yLabels:d,xCentres:f,yCentres:p}}}return e},[w,u,d,L,f,D]),se=dt(()=>{let e={};if(!w)return e;for(let t of u){if(t.kind!==`violin`)continue;let n=d[t.id];e[t.id]=n?.kind===`violin`&&n.vlValueCol?yW(w.rows,n.vlValueCol,n.vlGroupCol||void 0,D):[]}return e},[w,u,d,D]),ce=dt(()=>{let e={};if(!w)return e;let{rows:t}=w;for(let n of u){if(n.kind!==`confusion`)continue;let r=d[n.id];if(!r||r.kind!==`confusion`||!r.cfActualCol||!r.cfPredictedCol){e[n.id]={actual:[],predicted:[]};continue}let{cfActualCol:i,cfPredictedCol:a}=r,o=D?.get(i),s=D?.get(a);if(o&&s){e[n.id]={actual:o,predicted:s};continue}let c=[],l=[];for(let e of t){let t=e[i],n=e[a];t!==void 0&&n!==void 0&&(c.push(t),l.push(n))}e[n.id]={actual:c,predicted:l}}return e},[w,u,d,D]),le=dt(()=>{let e={};if(!w)return e;for(let t of u){if(t.kind!==`roc`)continue;let n=d[t.id],r=n?.kind===`roc`&&n.rocScoreCol?_W(w.rows,n.rocScoreCol,D):void 0,i=n?.kind===`roc`&&n.rocLabelCol?_W(w.rows,n.rocLabelCol,D):void 0;e[t.id]=r&&i?{scores:r,labels:i}:{scores:[],labels:[]}}return e},[w,u,d,D]),ue=dt(()=>{let e={};if(!w)return e;let{rows:t}=w;for(let n of u){if(n.kind!==`losscurve`)continue;let r=d[n.id];if(!r||r.kind!==`losscurve`){e[n.id]={xValues:[],series:[]};continue}let{lcXCol:i,lcLeftCols:a,lcRightCols:o}=r,s=[...a.map(e=>({...e,axis:`left`})),...o.map(e=>({...e,axis:`right`}))].map(({column:e,color:n,axis:r})=>({label:e,color:n,values:_W(t,e,D)??new Float64Array,axis:r})),c=s[0]?.values.length??t.length,l=i&&_W(t,i,D)||Float64Array.from({length:c},(e,t)=>t);e[n.id]={xValues:l,series:s}}return e},[w,u,d,D]),de=dt(()=>{let e={};if(!w)return e;let{rows:t}=w;for(let n of u){if(n.kind!==`controlchart`)continue;let r=d[n.id],i=r?.kind===`controlchart`&&r.ccValueCol?_W(t,r.ccValueCol,D):void 0;if(!r||r.kind!==`controlchart`||!i){e[n.id]={length:0,value:[]};continue}let a=0;for(let e=0;e<i.length;e++)i[e]-i[e]===0&&a++;let o=a===i.length?null:new Uint32Array(a),s=o?new Float64Array(a):i;if(o)for(let e=0,t=0;e<i.length;e++)i[e]-i[e]===0&&(o[t]=e,s[t++]=i[e]);let c=r.ccSubgroupCol,l=c?D?.get(c):void 0,u=e=>o?o[e]:e;e[n.id]={length:a,value:s,subgroup:c?e=>String(l?l[u(e)]:t[u(e)]?.[c]??``):void 0}}return e},[w,u,d,D]),fe=dt(()=>{let e={};if(!w)return e;let{rows:t}=w;for(let n of u){if(n.kind!==`parallelcoords`)continue;let r=d[n.id];if(!r||r.kind!==`parallelcoords`||r.pcColumns.length<2){e[n.id]={length:0,columns:[]};continue}let i=r.pcColumns.map(e=>_W(t,e,D)??new Float64Array),a=Math.min(...i.map(e=>e.length)),o={length:a,columns:i},s=r.pcColorByCol;if(s)if(L.includes(s))o.colorValue=_W(t,s,D);else{let e=new Map,n=new Int32Array(a);for(let r=0;r<a;r++){let i=String(t[r]?.[s]??``),a=e.get(i);a===void 0&&e.set(i,a=e.size),n[r]=a}o.colorIndex=n,o.colorLabels=[...e.keys()]}e[n.id]=o}return e},[w,u,d,L,D]),pe=dt(()=>{let e={};if(!w)return e;let{rows:t}=w,n={length:0,x:[],y:[]};for(let r of u){if(r.kind!==`embedding`)continue;let i=d[r.id];if(!i||i.kind!==`embedding`||!i.emXCol||!i.emYCol){e[r.id]=n;continue}let{emXCol:a,emYCol:o,emColorCol:s,emColorMode:c,emLabelCol:l}=i,u=_W(t,a,D),f=_W(t,o,D);if(!u||!f){e[r.id]=n;continue}let p=Math.min(u.length,f.length),m={length:p,x:u,y:f};if(s)if(c===`numeric`&&L.includes(s))m.colorValue=_W(t,s,D);else{let e=D?.get(s),n=new Map,r=new Int32Array(p);for(let i=0;i<p;i++){let a=String(e?e[i]:t[i]?.[s]??``),o=n.get(a);o===void 0&&n.set(a,o=n.size),r[i]=o}m.colorIndex=r,m.colorLabels=[...n.keys()]}if(l){let e=D?.get(l);m.label=e?t=>String(e[t]):e=>String(t[e]?.[l]??``)}e[r.id]=m}return e},[w,u,d,L,D]),me=dt(()=>{if(!w)return{};let e={};for(let t of u){if(t.kind!==`flamegraph`)continue;let n=d[t.id];if(!n||n.kind!==`flamegraph`||!n.fgNameCol||!n.fgValueCol){e[t.id]=[];continue}let r=[];for(let e of w.rows){let t=String(e[n.fgNameCol]??``),i=n.fgParentCol?String(e[n.fgParentCol]??``):``,a=e[n.fgValueCol];!t||typeof a!=`number`||!Number.isFinite(a)||r.push({name:t,parent:i,value:a})}e[t.id]=r}return e},[w,u,d]),he=dt(()=>{if(!w)return{};let e={};for(let t of u){if(t.kind!==`barchart`)continue;let n=d[t.id];if(!n||n.kind!==`barchart`||n.bcValueCols.length===0){e[t.id]={groups:[],seriesNames:[]};continue}let r=n.bcValueCols;if(n.bcCategoryCol){let i=new Map;for(let e of w.rows){let t=String(e[n.bcCategoryCol]??`(blank)`);i.has(t)||i.set(t,r.map(()=>0));let a=new Map,o=i.get(t);for(let t=0;t<r.length;t++){let n=e[r[t]];typeof n==`number`&&Number.isFinite(n)&&(o[t]+=n),a.set(r[t],(a.get(r[t])??0)+1)}}e[t.id]={groups:Array.from(i.entries()).map(([e,t])=>({label:e,values:t})),seriesNames:r}}else{let n=w.rows,i=r.map(e=>_W(n,e,D)),a=i.reduce((e,t)=>t?Math.min(e,t.length):e,1/0),o=Number.isFinite(a)?a:n.length,s=i.map(e=>e??new Float64Array(o).fill(NaN));e[t.id]={groups:[],columns:{length:o,values:s},seriesNames:r}}}return e},[w,u,d,D]),ge=dt(()=>{let e={};if(!w)return e;let{rows:t}=w;for(let n of u){if(n.kind!==`radar`)continue;let r=d[n.id];if(!r||r.kind!==`radar`||r.rdAxesCols.length<3){e[n.id]={axes:[],series:[]};continue}let i=r.rdAxesCols,a=i.map(e=>_W(t,e,D));if(r.rdGroupCol){let o=r.rdGroupCol,s=D?.get(o),c=s?s.length:t.length,l=new Map;for(let e=0;e<c;e++){let n=s?s[e]===s[e]?String(s[e]):`(blank)`:String(t[e][o]??`(blank)`),r=l.get(n);r||l.set(n,r=i.map(()=>0));for(let t=0;t<i.length;t++){let n=a[t]?.[e]??NaN;n-n===0&&(r[t]+=n)}}e[n.id]={axes:i,series:Array.from(l.entries()).map(([e,t])=>({name:e,values:t}))}}else{let t=a.map(e=>{let t=0,n=0;if(e)for(let r=0;r<e.length;r++)e[r]-e[r]===0&&(t+=e[r],n++);return t/(n||1)});e[n.id]={axes:i,series:[{name:`Series 1`,values:t}]}}}return e},[w,u,d,D]),_e=dt(()=>{if(!w)return{};let e={};for(let t of u){if(t.kind!==`areachart`)continue;let n=d[t.id];if(!n||n.kind!==`areachart`||n.acYCols.length===0){e[t.id]=[];continue}let r=w.rows,i=n.acYCols.map(e=>_W(r,e,D)),a=i[0]?.length??r.length,o=(n.acXCol?_W(r,n.acXCol,D):void 0)??QX(a);e[t.id]=n.acYCols.flatMap((e,t)=>{let n=i[t];return n?[{name:e,x:o,y:n}]:[]})}return e},[w,u,d,D]),ve=dt(()=>{let e={};if(!w)return e;for(let t of u){if(t.kind!==`cdfchart`)continue;let n=d[t.id];if(!n||n.kind!==`cdfchart`){e[t.id]=[];continue}e[t.id]=n.cdValueCols.map(e=>({name:e,values:vW(w.rows,e,D)??new Float64Array}))}return e},[w,u,d,D]),ye=dt(()=>{let e={};if(!w)return e;let{rows:t}=w,n={length:0,x:[],y:[],size:[]};for(let r of u){if(r.kind!==`bubblechart`)continue;let i=d[r.id];if(!i||i.kind!==`bubblechart`||!i.bbXCol||!i.bbYCol||!i.bbSizeCol){e[r.id]=n;continue}let a=_W(t,i.bbXCol,D),o=_W(t,i.bbYCol,D),s=_W(t,i.bbSizeCol,D);if(!a||!o||!s){e[r.id]=n;continue}let c=Math.min(a.length,o.length,s.length),l=new Float64Array(c);for(let e=0;e<c;e++)l[e]=s[e]===s[e]?Math.max(0,s[e]):NaN;let u=new Float64Array(c);for(let e=0;e<c;e++)u[e]=l[e]===l[e]?a[e]:NaN;let f={length:c,x:u,y:o,size:l};if(i.bbColorCol){if(i.bbColorMode===`numeric`)f.colorValue=_W(t,i.bbColorCol,D);else if(i.bbColorMode===`categorical`){let e=D?.get(i.bbColorCol),n=new Map,r=new Int32Array(c);for(let a=0;a<c;a++){let o=String(e?e[a]:t[a]?.[i.bbColorCol]??``),s=n.get(o);s===void 0&&n.set(o,s=n.size),r[a]=s}f.colorIndex=r,f.colorLabels=[...n.keys()]}}e[r.id]=f}return e},[w,u,d,D]),be=dt(()=>{if(!w)return{};let e={};for(let t of u){if(t.kind!==`treemap`)continue;let n=d[t.id];if(!n||n.kind!==`treemap`||!n.tmNameCol||!n.tmValueCol){e[t.id]=[];continue}let r=[];for(let e of w.rows){let t=String(e[n.tmNameCol]??``),i=n.tmParentCol?String(e[n.tmParentCol]??``):``,a=e[n.tmValueCol];!t||typeof a!=`number`||!Number.isFinite(a)||r.push({name:t,parent:i,value:a})}e[t.id]=r}return e},[w,u,d]),xe=dt(()=>{if(!w)return{};let e={};for(let t of u){if(t.kind!==`sankey`)continue;let n=d[t.id];if(!n||n.kind!==`sankey`||!n.skSourceCol||!n.skTargetCol||!n.skValueCol){e[t.id]={nodeNames:[],links:[]};continue}let r=new Set,i=[];for(let e of w.rows){let t=String(e[n.skSourceCol]??``),a=String(e[n.skTargetCol]??``),o=e[n.skValueCol];!t||!a||typeof o!=`number`||!Number.isFinite(o)||(r.add(t),r.add(a),i.push({source:t,target:a,value:o}))}e[t.id]={nodeNames:Array.from(r),links:i}}return e},[w,u,d]),Se=dt(()=>{let e={};if(!w)return e;for(let t of u){if(t.kind!==`calibration`)continue;let n=d[t.id],r=n?.kind===`calibration`&&n.cbScoreCol?_W(w.rows,n.cbScoreCol,D):void 0,i=n?.kind===`calibration`&&n.cbLabelCol?_W(w.rows,n.cbLabelCol,D):void 0;if(!n||n.kind!==`calibration`||!r||!i){e[t.id]=[];continue}let a=Math.max(2,n.cbBins),o=new Float64Array(a),s=new Float64Array(a);for(let e=0;e<Math.min(r.length,i.length);e++){let t=r[e],n=i[e];if(t-t!==0||n-n!==0)continue;let c=Math.max(0,Math.min(a-1,Math.floor(t*a)));o[c]+=n,s[c]++}e[t.id]=Array.from({length:a},(e,t)=>({center:(t+.5)/a,actual:s[t]>0?o[t]/s[t]:0,count:s[t]})).filter(e=>e.count>0)}return e},[w,u,d,D]),Ce=dt(()=>{let e={};if(!w)return e;let t={length:0,theoretical:[],sample:[]},n=e=>{let t=vW(w.rows,e,D);return t?Float64Array.from(t).sort():new Float64Array};for(let r of u){if(r.kind!==`qqplot`)continue;let i=d[r.id];if(!i||i.kind!==`qqplot`||!i.qqValueCol){e[r.id]=t;continue}let a=n(i.qqValueCol),o=a.length;if(o===0){e[r.id]=t;continue}if(i.qqMode===`column`&&i.qqRefCol){let t=n(i.qqRefCol),s=Math.min(o,t.length);e[r.id]={length:s,theoretical:t.subarray(0,s),sample:a.subarray(0,s)}}else{let t=e=>{let t=[2.515517,.802853,.010328],n=[1.432788,.189269,.001308],r=Math.sqrt(-2*Math.log(Math.min(e,1-e))),i=r-(t[0]+t[1]*r+t[2]*r*r)/(1+n[0]*r+n[1]*r*r+n[2]*r*r*r);return e<.5?-i:i},n=new Float64Array(o);for(let e=0;e<o;e++)n[e]=t((e+.5)/o);e[r.id]={length:o,theoretical:n,sample:a}}}return e},[w,u,d,D]),we=dt(()=>{if(!w)return{};let e={};for(let t of u){if(t.kind!==`gantt`)continue;let n=d[t.id];if(!n||n.kind!==`gantt`||!n.gtLabelCol||!n.gtStartCol||!n.gtEndCol){e[t.id]=[];continue}let r=[];for(let e of w.rows){let t=String(e[n.gtLabelCol]??``),i=e[n.gtStartCol],a=e[n.gtEndCol];if(!t||typeof i!=`number`||typeof a!=`number`||!Number.isFinite(i)||!Number.isFinite(a))continue;let o={label:t,start:i,end:a};n.gtGroupCol&&e[n.gtGroupCol]!==void 0&&(o.group=String(e[n.gtGroupCol])),r.push(o)}e[t.id]=r}return e},[w,u,d]),Te=w&&w.columnNames.indexOf(f)>=0?w.units[w.columnNames.indexOf(f)]??``:``,Ee=dt(()=>w?YX(w,E?T.length:0):{},[w,E,T]);return{dataset:b,datasetWithChannels:w,multiDatasetMode:E,numericCols:L,anyDuckDb:M,duckDbLayers:I,liveConn:v,liveOverlays:N,hasLiveSelected:_,staticXRange:P,xUnit:Te,columnUnits:Ee,multibandDataByPanel:B,xyPointsByPanel:V,xyzPointsByPanel:te,histogramDataByPanel:H,polarDataByPanel:ne,spectrumDataByPanel:ie,boxplotDataByPanel:U,spectrogramDataByPanel:ae,heatmapDataByPanel:oe,violinDataByPanel:se,confusionDataByPanel:ce,rocDataByPanel:le,lossCurveDataByPanel:ue,controlChartDataByPanel:de,parallelCoordsDataByPanel:fe,embeddingDataByPanel:pe,flameGraphDataByPanel:me,barChartDataByPanel:he,radarDataByPanel:ge,areaChartDataByPanel:_e,cdfChartDataByPanel:ve,bubbleChartDataByPanel:ye,treemapDataByPanel:be,sankeyDataByPanel:xe,calibrationDataByPanel:Se,qqPlotDataByPanel:Ce,ganttDataByPanel:we,gaugeDataByPanel:dt(()=>{let e={};if(!w)return e;let t=e=>e.trim()!==``&&Number.isFinite(Number(e))?Number(e):void 0;for(let n of u){if(n.kind!==`gauge`)continue;let r=d[n.id];if(r?.kind!==`gauge`){e[n.id]=[];continue}e[n.id]=r.ggGauges.flatMap(e=>{let n=e.column,r=n?_W(w.rows,n,D):void 0;if(!r)return[];let i=1/0,a=-1/0,o=0,s=0,c=NaN;for(let e=0;e<r.length;e++){let t=r[e];t-t===0&&(t<i&&(i=t),t>a&&(a=t),o+=t,s++,c=t)}let l=s===0?NaN:e.value===`mean`?o/s:e.value===`min`?i:e.value===`max`?a:c,[u,d]=eZ(s?i:0,s?a:1,t(e.min),t(e.max));return[{name:n,unit:Ee[n]??``,value:l,min:u,max:d,alarm:e.alarm??null,color:e.color,style:e.style,fromZero:e.fill===`zero`,colorMode:e.colorMode,stops:e.stops,stat:e.value}]})}return e},[w,u,d,D,Ee])}}function eZ(e,t,n,r){t<=e&&(t=e+1);let i=wz(t-e,5),a=n??Math.floor(e/i)*i,o=r??Math.ceil(t/i)*i;return o>a?[a,o]:[a,a+1]}var tZ=`#fb7185`,nZ=2500;function rZ(e){let{panel:t,data:n,settings:r}=e;if(t.kind===`camera`)return{status:`ready`,data:null,node:q(dX,{settings:r?.kind===`camera`?r:Hn(),live:e.live??[],selection:e.selection??[],viewXRange:e.viewXRange,xIsTime:e.xKey===qe,xKey:e.xKey,video:e.video,recordings:e.recordings,cursor:e.cursor,onContextMenu:t=>e.onContextMenu(t)})};if(!n.dataset)return{status:`no-data`,node:null,data:null};let i=`${e.background??`theme`}|${e.styleToken}`,a=t=>e.onContextMenu(t),s=(e,t)=>({status:`ready`,node:e,data:t}),l={status:`empty`,node:null,data:null},u=t.id;switch(t.kind){case`multiband`:{let t=n.multibandDataByPanel[u],d=t?.points??[],f=t?.effectiveSeries??[],p=r?.kind===`multiband`?r:null,m=[...new Set((p?.series??[]).map(e=>e.column).filter(t=>t!==e.xKey))],h=e.xKey===`ElapsedTime`&&!n.numericCols.includes(`Time`)?`Time`:e.xKey,g={xLabel:n.xUnit?`${h} (${n.xUnit})`:h,series:f,columnUnits:n.columnUnits,height:e.height,backgroundToken:i,viewXRange:e.viewXRange,onViewXRangeChange:e.onViewXRangeChange,onCursorX:e.onCursorX,liveZoom:e.liveZoom,liveZoomId:u,xAxisLine:p?.xAxisLine,yAxisLine:p?.yAxisLine,gridLine:p?.gridLine,lineWidth:p?.lineWidth,onPlotContextMenu:a,shiftMode:e.shiftMode},_=p?.beacon;if(_?.enabled&&e.beaconLive&&m.length>0){let t=qX((p?.series??[]).filter(t=>t.column!==e.xKey),p?.layout??`overlay`),n=_.reference===`dataset`&&_.datasetId?e.findDataset(_.datasetId):void 0,r=MX(_,!!n),i=r?[...EX(t,r),...t]:t;return s(q(qU,{...g,series:i,points:[],showLatestValues:!0,liveSource:jX(e.beaconLive,e.xKey,m,_,n),envelopes:n?NX(n,e.xKey,t,r??void 0):void 0,liveZoomMode:`free`}),{series:i,points:[]})}if(n.anyDuckDb)return f.length===0?l:s(q(mW,{...g,layers:n.duckDbLayers,xKey:e.xKey,columns:m,maxPoints:nZ}),{series:f,columns:m});if(!d.some(e=>e.length>0)&&!n.liveOverlays||f.length===0)return l;let v=n.liveConn,y=null,b=n.liveOverlays,x=!v&&b&&m.length>0?xX(b,e.xKey,m,d,n.staticXRange):void 0,S=!!x&&d.length>0,C=x??(v&&m.length>0?{pull:(t,n,r,i,a)=>{let s=v.source.version();if(a){let i=2**Math.ceil(Math.log2((n-t)/8)),a=Math.floor(t/i)*i,o=Math.ceil(n/i)*i,l=Math.round(r*(o-a)/(n-t));return(!y||y.ver!==s||y.x0!==a||y.x1!==o||Math.abs(y.mp-l)>l*.25)&&(y={ver:s,x0:a,x1:o,mp:l,pts:v.source.getPointsSync(m,{xKey:e.xKey,x0:a,x1:o},l),held:c(m,e=>v.source.lastKnownSync(e),a,o,v.source.latestTimeSync())}),y.held?[y.pts,y.held]:[y.pts]}(!y||y.ver!==s||y.x0!==t||y.x1!==n||y.mp!==r)&&(y={ver:s,x0:t,x1:n,mp:r,pts:v.source.getPointsSync(m,{xKey:e.xKey,x0:t,x1:n},r)});let l=o(y.pts,i);if(e.xKey!==`ElapsedTime`)return[l];let u=c(m,e=>v.source.lastKnownSync(e),t,n,Math.min(v.source.latestTimeSync(),i??1/0));return u?[l,u]:[l]},cutOnGpu:e.xKey===`ElapsedTime`,id:v.id,latestT:()=>v.source.latestTimeSync(),xAtTime:t=>v.source.xAtTimeSync(e.xKey,t),xBounds:()=>{let t=v.source.xBoundsSync(e.xKey);return t.x1>t.x0?[t.x0,t.x1]:null},latestX:()=>{let t=v.source.latestSync(e.xKey);return Number.isFinite(t)?t:null},version:()=>v.source.version(),latestValues:e=>v.source.latestValuesSync(e),...e.xKey===`ElapsedTime`?{}:{spanForSeconds:t=>v.source.xTravelSync(e.xKey,t),bufferedSeconds:()=>{let e=v.source.xBoundsSync(`ElapsedTime`);return e.x1-e.x0}}}:void 0);return s(q(qU,{...g,points:d,envelopes:t?.envelopes,showLatestValues:n.hasLiveSelected,fullXRange:n.staticXRange,liveSource:C,liveWindowSeconds:S?null:e.liveWindowSeconds,onLiveWindowChange:S?void 0:e.onLiveWindowChange,liveZoomMode:S?`free`:`follow`}),{series:f,points:d})}case`xyzmesh`:{let t=r?.kind===`xyzmesh`?r:hn(4),o=n.xyzPointsByPanel[u];if(!o||o.points.length<1&&!o.surface)return l;let c=!!o.surface;return s(q(gK,{ref:e.xyzRef,points:o.points,surface:o.surface,xLabel:c?(t.xyzColumns??[]).includes(e.xKey)?`Row`:e.xKey:t.xyzXCol,yLabel:c?`Column`:t.xyzYCol,zLabel:c?`Value`:t.xyzZCol,height:e.height,backgroundToken:i,xRange:ln(t.xyzXScale.scaleMin,t.xyzXScale.scaleMax),yRange:ln(t.xyzYScale.scaleMin,t.xyzYScale.scaleMax),zRange:ln(t.xyzZScale.scaleMin,t.xyzZScale.scaleMax),viewMode:t.xyzViewMode,pointRadius:t.xyzPointRadius,showMesh:t.showMesh,meshStyle:t.meshStyle,meshOpacity:t.meshOpacity,alarms:[...t.xyzXScale.alarm?[{axis:`x`,...t.xyzXScale.alarm}]:[],...t.xyzYScale.alarm?[{axis:`y`,...t.xyzYScale.alarm}]:[],...t.xyzZScale.alarm?[{axis:`z`,...t.xyzZScale.alarm}]:[]],onPlotContextMenu:a}),o.surface??o.points)}case`xyscatter`:{let t=r?.kind===`xyscatter`?r:mn(tZ),o=n.xyPointsByPanel.pts[u]??[];if(o.length===0)return l;let c=n.xyPointsByPanel.colorMeta[u];return s(q(iG,{points:o,xLabel:t.xyXCol,yLabel:t.xyYCol,color:t.xyColor,datasetColors:n.xyPointsByPanel.datasetColors[u],colorLabel:c?.label,colorRange:c?[c.min,c.max]:void 0,pointRadius:t.xyPointRadius,drawMode:t.xyDrawMode,lineWidth:t.xyLineWidth,height:e.height,backgroundToken:i,xAxisLine:t.xyXAxisLine,yAxisLine:t.xyYAxisLine,gridLine:t.xyGridLine,fitSettings:t.xyFit,xScale:t.xyXScale,yScale:t.xyYScale,onPlotContextMenu:a}),o)}case`histogram`:{if(r?.kind!==`histogram`)return l;let t=n.histogramDataByPanel[u]??[];return t.length===0?l:s(q(CK,{values:t,label:r.histColumn,bins:r.histBins,color:r.histColor,showNormal:r.histNormal,logY:r.histLogY,height:e.height,backgroundToken:i,onPlotContextMenu:a}),t)}case`polar`:{if(r?.kind!==`polar`)return l;let t=n.polarDataByPanel[u]??{angles:[],radii:[]};if(t.angles.length===0)return l;let o=parseFloat(r.polarRadiusMin),c=parseFloat(r.polarRadiusMax);return s(q(VK,{angles:t.angles,radii:t.radii,angleLabel:r.polarAngleCol,radiusLabel:r.polarRadiusCol,color:r.polarColor,mode:r.polarMode,radiusMin:Number.isFinite(o)?o:void 0,radiusMax:Number.isFinite(c)?c:void 0,height:e.height,backgroundToken:i,onPlotContextMenu:a}),t)}case`spectrum`:{if(r?.kind!==`spectrum`)return l;let{signal:t,rate:o}=n.spectrumDataByPanel[u]??{signal:[],rate:1};return t.length<4?l:s(q(rq,{signal:t,sampleRate:o,label:r.specSignalCol,xMode:r.specXMode,yMode:r.specYMode,window:r.specWindow,color:r.specColor,logX:r.specLogX,height:e.height,backgroundToken:i,onPlotContextMenu:a}),t)}case`boxplot`:{if(r?.kind!==`boxplot`)return l;let t=n.boxplotDataByPanel[u]??[];return t.length===0?l:s(q(lq,{groups:t,color:r.boxColor,whiskers:r.boxWhiskers,height:e.height,backgroundToken:i,onPlotContextMenu:a}),t)}case`spectrogram`:{if(r?.kind!==`spectrogram`)return l;let{signal:e,rate:t}=n.spectrogramDataByPanel[u]??{signal:[],rate:1};return e.length<r.sgWindowSize?l:r.sgView===`waterfall`?s(q(Dq,{signal:e,sampleRate:t,windowSize:r.sgWindowSize,overlap:r.sgOverlap,winFunc:r.sgWinFunc,yMode:r.sgYMode,backgroundToken:i,onPlotContextMenu:a}),e):s(q(Sq,{signal:e,sampleRate:t,windowSize:r.sgWindowSize,overlap:r.sgOverlap,winFunc:r.sgWinFunc,yMode:r.sgYMode,logFreq:r.sgLogFreq,backgroundToken:i,onPlotContextMenu:a}),e)}case`heatmap`:{if(r?.kind!==`heatmap`)return l;let e=n.heatmapDataByPanel[u]??{cells:[],xLabels:[],yLabels:[]};if(e.cells.length===0&&!(e.grid&&e.grid.w*e.grid.h>0))return l;let t=e=>e!==void 0&&e.trim()!==``&&Number.isFinite(Number(e))?Number(e):void 0;return s(q(Kq,{cells:e.cells,xLabels:e.xLabels,yLabels:e.yLabels,grid:e.grid,showValues:r.hmShowValues,colorScheme:r.hmColorScheme,xCentres:e.xCentres,yCentres:e.yCentres,contours:r.hmContours??0,vMin:t(r.hmRange?.scaleMin),vMax:t(r.hmRange?.scaleMax),backgroundToken:i,onPlotContextMenu:a}),e)}case`violin`:{if(r?.kind!==`violin`)return l;let e=n.violinDataByPanel[u]??[];return e.some(e=>e.values.length>0)?s(q(eJ,{groups:e,color:r.vlColor,showBox:r.vlShowBox,bandwidth:parseFloat(r.vlBandwidth)||void 0,orientation:r.vlOrientation,backgroundToken:i,onPlotContextMenu:a}),e):l}case`confusion`:{if(r?.kind!==`confusion`)return l;let e=n.confusionDataByPanel[u]??{actual:[],predicted:[]};return e.actual.length===0?l:s(q(sJ,{actual:e.actual,predicted:e.predicted,normalize:r.cfNormalize,backgroundToken:i,onPlotContextMenu:a}),e)}case`roc`:{if(r?.kind!==`roc`)return l;let e=n.rocDataByPanel[u]??{scores:[],labels:[]};return e.scores.length===0?l:s(q(pJ,{scores:e.scores,labels:e.labels,mode:r.rocMode,color:r.rocColor,backgroundToken:i,onPlotContextMenu:a}),e)}case`losscurve`:{if(r?.kind!==`losscurve`)return l;let e=n.lossCurveDataByPanel[u]??{xValues:[],series:[]};return e.series.length===0?l:s(q(hJ,{xValues:e.xValues,series:e.series,xLabel:r.lcXCol||`Step`,backgroundToken:i,onPlotContextMenu:a}),e)}case`controlchart`:{if(r?.kind!==`controlchart`)return l;let e=n.controlChartDataByPanel[u];return!e||e.length<2?l:s(q(xJ,{points:e,sigmaLevel:r.ccSigmaLevel,color:r.ccColor,backgroundToken:i,onPlotContextMenu:a}),e)}case`parallelcoords`:{if(r?.kind!==`parallelcoords`)return l;let e=n.parallelCoordsDataByPanel[u];if(!e||e.length===0||r.pcColumns.length<2)return l;let t=r.pcColorByCol?n.numericCols.includes(r.pcColorByCol):!1;return s(q(DJ,{rows:e,axes:r.pcColumns,color:r.pcColor,colorByNumeric:t,backgroundToken:i,onPlotContextMenu:a}),e)}case`embedding`:{if(r?.kind!==`embedding`)return l;let e=n.embeddingDataByPanel[u];return!e||e.length===0?l:s(q(LJ,{points:e,color:r.emColor,colorByNumeric:r.emColorMode===`numeric`&&!!r.emColorCol,pointSize:r.emPointSize,backgroundToken:i,onPlotContextMenu:a}),e)}case`flamegraph`:{if(r?.kind!==`flamegraph`)return l;let e=n.flameGraphDataByPanel[u]??[];return e.length===0?l:s(q(GJ,{nodes:e,direction:r.fgDirection,backgroundToken:i,onPlotContextMenu:a}),e)}case`barchart`:{if(r?.kind!==`barchart`)return l;let e=n.barChartDataByPanel[u]??{groups:[],seriesNames:[]};if(e.groups.length===0&&!e.columns?.length)return l;let t=e=>e!==void 0&&e.trim()!==``&&Number.isFinite(Number(e))?Number(e):void 0,o=r.bcValueScale?{min:t(r.bcValueScale.scaleMin),max:t(r.bcValueScale.scaleMax)}:void 0;return s(q(ZJ,{groups:e.columns?void 0:e.groups,columns:e.columns,seriesNames:e.seriesNames,mode:r.bcMode,horizontal:r.bcHorizontal,valueRange:o,backgroundToken:i,onPlotContextMenu:a}),e)}case`radar`:{if(r?.kind!==`radar`)return l;let e=n.radarDataByPanel[u]??{axes:[],series:[]};return e.axes.length<3?l:s(q(tY,{axes:e.axes,series:e.series,fill:r.rdFill,color:r.rdColor,backgroundToken:i,onPlotContextMenu:a}),e)}case`areachart`:{if(r?.kind!==`areachart`)return l;let e=n.areaChartDataByPanel[u]??[];if(e.length===0)return l;let t=e=>e!==void 0&&e.trim()!==``&&Number.isFinite(Number(e))?Number(e):void 0,o=r.acYScale?{min:t(r.acYScale.scaleMin),max:t(r.acYScale.scaleMax)}:void 0;return s(q(aY,{series:e,stacked:r.acStacked,yRange:o,backgroundToken:i,onPlotContextMenu:a}),e)}case`cdfchart`:{if(r?.kind!==`cdfchart`)return l;let e=n.cdfChartDataByPanel[u]??[];return e.length===0?l:s(q(cY,{series:e,complement:r.cdComplement,logX:r.cdLogX,backgroundToken:i,onPlotContextMenu:a}),e)}case`bubblechart`:{if(r?.kind!==`bubblechart`)return l;let e=n.bubbleChartDataByPanel[u];return!e||e.length===0?l:s(q(gY,{points:e,color:r.bbColor,colorByNumeric:r.bbColorMode===`numeric`,maxRadius:r.bbMaxRadius,backgroundToken:i,onPlotContextMenu:a}),e)}case`treemap`:{let e=n.treemapDataByPanel[u]??[];return e.length===0?l:s(q(xY,{nodes:e,backgroundToken:i,onPlotContextMenu:a}),e)}case`sankey`:{let e=n.sankeyDataByPanel[u]??{nodeNames:[],links:[]};return e.links.length===0?l:s(q(DY,{nodeNames:e.nodeNames,links:e.links,backgroundToken:i,onPlotContextMenu:a}),e)}case`calibration`:{if(r?.kind!==`calibration`)return l;let e=n.calibrationDataByPanel[u]??[];return e.length===0?l:s(q(kY,{bins:e,color:r.cbColor,backgroundToken:i,onPlotContextMenu:a}),e)}case`qqplot`:{if(r?.kind!==`qqplot`)return l;let e=n.qqPlotDataByPanel[u];return!e||e.length===0?l:s(q(jY,{points:e,color:r.qqColor,backgroundToken:i,onPlotContextMenu:a}),e)}case`gauge`:{if(r?.kind!==`gauge`)return l;let e=n.gaugeDataByPanel[u]??[];if(e.length===0)return l;let t=n.liveConn??(n.liveOverlays?.length===1?n.liveOverlays[0].conn:void 0);return s(q(KY,{gauges:e,live:t?{latestT:()=>t.source.latestTimeSync(),valueAt:(e,n)=>t.source.xAtTimeSync(e,n,!0)}:void 0,backgroundToken:i,onPlotContextMenu:a}),e)}case`gantt`:{let e=n.ganttDataByPanel[u]??[];return e.length===0?l:s(q(IY,{tasks:e,backgroundToken:i,onPlotContextMenu:a}),e)}}return l}var iZ=500,aZ=1e3;function oZ(e){if(Array.isArray(e))return sZ(e);if(!e||typeof e!=`object`)return null;let t=-1;for(let n of Object.values(e))Array.isArray(n)&&(t=Math.max(t,sZ(n)));return t<0?null:t}function sZ(e){let t=e=>!!e&&typeof e==`object`&&e.x instanceof Float64Array;return e.length>0&&t(e[0])?e.reduce((e,n)=>e+(t(n)?n.length:0),0):e.length}function cZ(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e4?`${Math.round(e/1e3)}k`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function lZ({stats:e,host:t}){let[n,r]=ft(null);if(W(()=>{let n=t.current?.ownerDocument.defaultView??window,i=0,a=0,o=0,s=-1,c=-1,l=e.renders,u=t.current?wH(t.current):0,d=f=>{c>=0&&f-s>aZ&&(c=f,s=f,a=0,o=0,l=e.renders,u=t.current?wH(t.current):0),c<0?(c=f,s=f):f!==s&&(o=Math.max(o,f-s),s=f,a++);let p=f-c;if(p>=iZ){let i=t.current,s=0;if(i)for(let e of i.getElementsByTagName(`canvas`))s+=e.width*e.height;let d=n.performance.memory,m=i?wH(i):0;r({fps:a*1e3/p,repaints:(m-u)*1e3/p,worstFrameMs:o,renderMs:e.lastRenderMs,rendersPerSec:(e.renders-l)*1e3/p,points:oZ(e.data),domNodes:i?i.getElementsByTagName(`*`).length:0,canvasMp:s/1e6,heapMb:d?d.usedJSHeapSize/1048576:null}),a=0,o=0,c=f,l=e.renders,u=m}i=n.requestAnimationFrame(d)};return i=n.requestAnimationFrame(d),()=>n.cancelAnimationFrame(i)},[e,t]),!n)return null;let i=n.fps<20?`var(--danger, #e5484d)`:n.fps<45?`var(--accent, #f5a524)`:void 0;return q(`dl`,{className:`kymo-perf-hud`,style:uZ,children:[[`FPS`,n.fps.toFixed(0),i],[`Repaints/s`,n.repaints.toFixed(0)],[`Slowest frame`,`${n.worstFrameMs.toFixed(1)} ms`],[`Render`,`${n.renderMs.toFixed(1)} ms`],[`Renders/s`,n.rendersPerSec.toFixed(1)],...n.points===null?[]:[[`Points`,cZ(n.points)]],[`DOM nodes`,cZ(n.domNodes)],[`Canvas`,`${n.canvasMp.toFixed(2)} MP`],...n.heapMb===null?[]:[[`JS heap`,`${n.heapMb.toFixed(0)} MB`]]].map(([e,t,n])=>_t(`div`,{style:dZ,children:[q(`dt`,{style:fZ,children:e}),q(`dd`,{style:n?{...pZ,color:n}:pZ,children:t})]},e))})}var uZ={position:`absolute`,top:8,right:8,zIndex:60,flex:`none`,pointerEvents:`none`,userSelect:`none`,margin:0,padding:`6px 9px`,minWidth:148,display:`grid`,gap:1,font:`500 10.5px/1.35 var(--font-sans, system-ui)`,fontVariantNumeric:`tabular-nums`,fontFeatureSettings:`"tnum" 1`,color:`var(--text-strong, #f3f5fa)`,background:`color-mix(in oklch, var(--bg-elevated, #1b2130) 86%, transparent)`,border:`1px solid var(--border, #33405a)`,borderRadius:6,boxShadow:`0 4px 14px color-mix(in oklch, black 28%, transparent)`},dZ={display:`flex`,justifyContent:`space-between`,gap:12},fZ={color:`var(--text-muted, #8a93a6)`},pZ={margin:0,fontWeight:600,textAlign:`right`},mZ=[],hZ=3,gZ=`data-kymo-annotation-controls`;function _Z(e,t,n,r){return e.anchor===`x`&&!r?null:e.points.map(([i,a])=>[e.anchor===`x`?YH(r,i):i*t,a*n])}function vZ(e,t,n,r,i){return t.map(([t,a])=>[e.anchor===`x`&&i?XH(i,t):yZ(t/Math.max(1,n)),yZ(a/Math.max(1,r))])}var yZ=e=>Math.round(e*1e4)/1e4,bZ=ot(function({annotations:e,tool:t,plotFrame:n,onChange:r,onToolEnd:i,onSelect:a,marks:o=mZ,onMarkSelect:s}){let c=K(null),l=pt(n.subscribe,n.get),u=l?.x?l:null,[d,f]=ft({w:0,h:0}),[p,m]=ft(null),[h,g]=ft(null),[_,v]=ft(null),y=K({annotations:e,onChange:r,onToolEnd:i,onSelect:a,tool:t,selected:p,editing:h,frame:u,size:d});y.current={annotations:e,onChange:r,onToolEnd:i,onSelect:a,tool:t,selected:p,editing:h,frame:u,size:d};let b=e=>{y.current.selected!==e&&(y.current.selected=e,m(e),y.current.onSelect(e))};G(()=>{let e=c.current;if(!e)return;let t=e.ownerDocument.defaultView??window,n=()=>f({w:e.clientWidth,h:e.clientHeight});n();let r=new t.ResizeObserver(n);return r.observe(e),()=>r.disconnect()},[]),W(()=>{t&&b(null)}),W(()=>{p&&!e.some(e=>e.id===p)&&b(null)}),W(()=>()=>{y.current.selected&&y.current.onSelect(null)},[]),W(()=>{let e=c.current?.ownerDocument;if(!e)return;let t=e=>{let{selected:t,editing:n,tool:r,annotations:i,onChange:a,onToolEnd:o}=y.current;if(!(n||kZ(e.target))){if(e.key===`Escape`&&r){o();return}t&&(e.key===`Delete`||e.key===`Backspace`?(e.preventDefault(),a(i.filter(e=>e.id!==t)),b(null)):e.key===`Escape`&&b(null))}},n=e=>{let t=y.current.selected,n=e.target;t&&!n?.closest?.(`[data-ann-id="${CSS.escape(t)}"], [data-kymo-annotation-controls]`)&&b(null)};return e.addEventListener(`keydown`,t),e.addEventListener(`pointerdown`,n,!0),()=>{e.removeEventListener(`keydown`,t),e.removeEventListener(`pointerdown`,n,!0)}},[]);let{w:x,h:S}=d,C=e=>{let t=c.current.getBoundingClientRect();return[e.clientX-t.left,e.clientY-t.top]},w=(e,t)=>{let n=c.current.ownerDocument,r=t=>e(C(t),t),i=()=>{n.removeEventListener(`pointermove`,r),n.removeEventListener(`pointerup`,i),n.removeEventListener(`pointercancel`,i),t()};n.addEventListener(`pointermove`,r),n.addEventListener(`pointerup`,i),n.addEventListener(`pointercancel`,i)},T=e=>r([...y.current.annotations,e]),E=e=>r(y.current.annotations.map(t=>t.id===e.id?e:t)),D=e=>{if(!t||e.button!==0||h)return;e.preventDefault(),e.stopPropagation();let n=C(e),r={id:crypto.randomUUID(),kind:t.kind,color:t.color,width:t.width,...u?{anchor:`x`}:{}},i=e=>vZ(r,e,x,S,u);if(t.kind===`text`){v({...r,points:i([n]),text:``}),g(r.id);return}let a=t.kind===`brush`?[n]:[n,n],o={...r,points:i(a)};v(o);let s=!1;w((t,n)=>{if(s||=Math.hypot(n.clientX-e.clientX,n.clientY-e.clientY)>hZ,r.kind===`brush`){let e=a[a.length-1];if(Math.hypot(t[0]-e[0],t[1]-e[1])<2)return;a=[...a,t]}else a=[a[0],t];o={...o,points:i(a)},v(o)},()=>{v(null),s&&o.points.length>=2&&T(o)})},O=(e,t,n)=>{let r=_Z(t,x,S,u);if(!r)return;let i=C(e),a=null;w((o,s)=>{if(!a&&Math.hypot(s.clientX-e.clientX,s.clientY-e.clientY)<=hZ)return;let{size:c,frame:l}=y.current;a={...t,points:vZ(t,n(r,[o[0]-i[0],o[1]-i[1]],o),c.w,c.h,l)},v(a)},()=>{v(null),a&&E(a)})},k=(e,n)=>{t||e.button!==0||h===n.id||(e.preventDefault(),e.stopPropagation(),b(n.id),O(e,n,(e,[t,n])=>e.map(([e,r])=>[e+t,r+n])))},A=(e,t,n)=>{e.button===0&&(e.preventDefault(),e.stopPropagation(),O(e,t,(e,r,i)=>{let a=e.map(e=>[...e]);return t.kind===`arrow`?a[n]=i:(a[+(n===1||n===2)][0]=i[0],a[+(n===2||n===3)][1]=i[1]),a}))},j=e=>{t||e.kind!==`text`&&e.kind!==`box`||(b(e.id),g(e.id))},M=e=>{let t=h;g(null);let n=_&&_.id===t?_:null;if(v(null),e===null||!t)return;let i=e.replace(/\s+$/,``),a=y.current.annotations;if(n){i&&T({...n,text:i});return}let o=a.find(e=>e.id===t);o&&(!i&&o.kind===`text`?r(a.filter(e=>e.id!==t)):E(OZ(o,i)))},N=e=>{r(y.current.annotations.filter(t=>t.id!==e)),b(null)},P=(_?e.some(e=>e.id===_.id)?e.map(e=>e.id===_.id?_:e):[...e,_]:e).flatMap(e=>{let t=_Z(e,x,S,u);return t?[{a:e,px:t}]:[]}),F=p?P.find(e=>e.a.id===p):void 0,I=u?o.map(e=>{let t=_Z(Lt(e,u.x.v1),x,S,u);return{m:e,x0:Math.min(t[0][0],t[1][0]),x1:Math.max(t[0][0],t[1][0])}}):[],L=F&&F.a.kind!==`text`?DZ(F.px):null,R=e=>_t(gt,{children:[q(`svg`,{className:`kymo-ann-svg`,width:x,height:S,viewBox:`0 0 ${x} ${S}`,"aria-hidden":`true`,children:e.map(({a:e,px:t})=>e.kind===`text`?null:q(`g`,{"data-ann-id":e.id,className:`kymo-ann kymo-ann--${e.kind}`,onPointerDown:t=>k(t,e),onDoubleClick:()=>j(e),children:q(CZ,{a:e,px:t})},e.id))}),e.map(({a:e,px:t})=>{if(e.kind!==`text`&&e.kind!==`box`)return null;let n=h===e.id;if(!n&&!e.text)return null;let r=e.kind===`text`?{left:t[0][0],top:t[0][1]}:{left:Math.min(t[0][0],t[1][0]),top:Math.min(t[0][1],t[1][1]),transform:`translateY(calc(-100% - 3px))`};return _t(`div`,{"data-ann-id":e.id,className:`kymo-ann-text kymo-ann-text--${e.kind}${p===e.id&&e.kind===`text`?` is-selected`:``}`,style:{...r,color:e.color,fontSize:e.kind===`text`?e.width:12},onPointerDown:t=>k(t,e),onDoubleClick:()=>j(e),children:[n?q(SZ,{initial:e.text??``,onDone:M}):e.text,p===e.id&&e.kind===`text`&&!n?q(xZ,{onDelete:()=>N(e.id),style:{right:-11,top:-11}}):null]},`t-${e.id}`)})]});return q(`div`,{ref:c,className:`kymo-annotations${t?` is-drawing is-tool-${t.kind}`:``}`,onPointerDown:D,onContextMenu:t?e=>e.preventDefault():void 0,children:x>0&&S>0?_t(gt,{children:[u&&I.length?q(`div`,{className:`kymo-ann-clip`,style:{clipPath:`inset(0 ${Math.max(0,x-u.left-u.width)}px 0 ${Math.max(0,u.left)}px)`},children:q(`svg`,{className:`kymo-ann-svg kymo-marks`,width:x,height:S,viewBox:`0 0 ${x} ${S}`,children:I.map(({m:e,x0:t,x1:n})=>_t(`g`,{"data-mark":e.ruleId,role:`img`,"aria-label":`${e.ruleName}, ${e.severity}`,className:`kymo-mark kymo-mark--${e.severity}`,style:{color:It[e.severity]},children:[q(`rect`,{x:t,y:u.top,width:Math.max(1,n-t),height:u.height,fill:`currentColor`,fillOpacity:.12}),q(`rect`,{x:t,y:u.top,width:Math.max(1,n-t),height:2,fill:`currentColor`}),q(`rect`,{className:`kymo-mark-hit`,x:t,y:u.top,width:Math.max(6,n-t),height:8,onPointerDown:t=>{t.stopPropagation(),s?.(e.ruleId)}})]},e.id))})}):null,R(P.filter(e=>e.a.anchor!==`x`)),u?q(`div`,{className:`kymo-ann-clip`,style:{clipPath:`inset(0 ${Math.max(0,x-u.left-u.width)}px 0 ${Math.max(0,u.left)}px)`},children:R(P.filter(e=>e.a.anchor===`x`))}):null,_t(`svg`,{className:`kymo-ann-svg`,width:x,height:S,viewBox:`0 0 ${x} ${S}`,"aria-hidden":`true`,children:[L?q(`rect`,{className:`kymo-ann-selection`,x:L.x-6,y:L.y-6,width:L.w+12,height:L.h+12,rx:4}):null,F&&!h&&(F.a.kind===`box`||F.a.kind===`arrow`)?q(`g`,{"data-ann-id":F.a.id,children:wZ(F.a,F.px).map(([e,t],n)=>q(`rect`,{className:`kymo-ann-handle kymo-ann-handle--${F.a.kind===`arrow`?`end`:n%2?`nesw`:`nwse`}`,x:e-4.5,y:t-4.5,width:9,height:9,rx:2,onPointerDown:e=>A(e,F.a,n)},n))}):null]}),L&&!h?q(xZ,{onDelete:()=>N(F.a.id),id:F.a.id,style:{left:Math.min(x-12,L.x+L.w+6)-10,top:Math.max(10,L.y-6)-10}}):null]}):null})});function xZ({onDelete:e,style:t,id:n}){return q(`button`,{type:`button`,className:`kymo-ann-delete`,style:t,"data-ann-id":n,"aria-label":`Delete annotation`,title:`Delete (Del)`,onPointerDown:e=>e.stopPropagation(),onClick:e,children:q(`svg`,{viewBox:`0 0 10 10`,width:`8`,height:`8`,"aria-hidden":`true`,children:q(`path`,{d:`M2 2l6 6M8 2l-6 6`})})})}function SZ({initial:e,onDone:t}){let n=K(null),r=K(!1),i=e=>{r.current||(r.current=!0,t(e))};return G(()=>{let t=n.current;if(!t)return;t.textContent=e,t.focus();let r=t.ownerDocument.createRange();r.selectNodeContents(t);let i=t.ownerDocument.defaultView?.getSelection();i?.removeAllRanges(),i?.addRange(r)},[]),q(`div`,{ref:n,className:`kymo-ann-editor`,contentEditable:`plaintext-only`,suppressContentEditableWarning:!0,role:`textbox`,"aria-label":`Annotation text`,"aria-multiline":`true`,onPointerDown:e=>e.stopPropagation(),onKeyDown:e=>{e.stopPropagation(),e.key===`Enter`&&!e.shiftKey?(e.preventDefault(),i(n.current?.innerText??``)):e.key===`Escape`&&(e.preventDefault(),i(null))},onBlur:()=>i(n.current?.innerText??``)})}function CZ({a:e,px:t}){let n={stroke:e.color,strokeWidth:e.width,fill:`none`,strokeLinecap:`round`,strokeLinejoin:`round`},r=t=>q(`path`,{className:`kymo-ann-hit`,d:t,strokeWidth:Math.max(12,e.width+10)});switch(e.kind){case`box`:{let[[i,a],[o,s]]=t,c=`M${i} ${a}H${o}V${s}H${i}Z`;return _t(gt,{children:[r(c),q(`path`,{d:c,...n}),q(`path`,{d:c,fill:e.color,fillOpacity:.06,stroke:`none`,pointerEvents:`none`})]})}case`arrow`:{let[[i,a],[o,s]]=t,c=EZ(i,a,o,s,e.width);return _t(gt,{children:[r(`M${i} ${a}L${o} ${s}`),q(`path`,{d:`M${i} ${a}L${c.base[0]} ${c.base[1]}`,...n}),q(`path`,{d:c.d,fill:e.color,stroke:e.color,strokeWidth:1,strokeLinejoin:`round`})]})}case`brush`:{let e=TZ(t);return _t(gt,{children:[r(e),q(`path`,{d:e,...n})]})}}return null}function wZ(e,t){if(e.kind===`arrow`)return t;let[[n,r],[i,a]]=t;return[[n,r],[i,r],[i,a],[n,a]]}function TZ(e){if(e.length===0)return``;if(e.length<3)return`M${e[0][0]} ${e[0][1]}`+e.slice(1).map(([e,t])=>`L${e} ${t}`).join(``);let t=`M${e[0][0]} ${e[0][1]}`;for(let n=1;n<e.length-1;n++){let[r,i]=e[n],[a,o]=e[n+1];t+=`Q${r} ${i} ${(r+a)/2} ${(i+o)/2}`}let[n,r]=e[e.length-1];return t+`L${n} ${r}`}function EZ(e,t,n,r,i){let a=Math.max(9,i*4),o=Math.atan2(r-t,n-e),s=.42,c=[n-a*Math.cos(o-s),r-a*Math.sin(o-s)],l=[n-a*Math.cos(o+s),r-a*Math.sin(o+s)],u=[n-a*.8*Math.cos(o),r-a*.8*Math.sin(o)];return{d:`M${n} ${r}L${c[0]} ${c[1]}L${l[0]} ${l[1]}Z`,base:u,l:c,r:l}}function DZ(e){let t=e.map(e=>e[0]),n=e.map(e=>e[1]),r=Math.min(...t),i=Math.min(...n);return{x:r,y:i,w:Math.max(...t)-r,h:Math.max(...n)-i}}function OZ(e,t){if(t)return{...e,text:t};let{text:n,...r}=e;return r}function kZ(e){let t=e;return!!t&&(t.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName))}function AZ(e,t,n,r,i,a,o){e.save(),e.scale(i,i),e.lineCap=`round`,e.lineJoin=`round`;for(let i of t){let t=_Z(i,n,r,o);t&&(e.save(),i.anchor===`x`&&o&&(e.beginPath(),e.rect(o.left,0,o.width,r),e.clip()),jZ(e,i,t,a),e.restore())}e.restore()}function jZ(e,t,n,r){if(e.strokeStyle=t.color,e.fillStyle=t.color,e.lineWidth=t.width,t.kind===`box`)e.strokeRect(n[0][0],n[0][1],n[1][0]-n[0][0],n[1][1]-n[0][1]);else if(t.kind===`brush`)e.stroke(new Path2D(TZ(n)));else if(t.kind===`arrow`){let r=EZ(n[0][0],n[0][1],n[1][0],n[1][1],t.width);e.beginPath(),e.moveTo(n[0][0],n[0][1]),e.lineTo(r.base[0],r.base[1]),e.stroke(),e.beginPath(),e.moveTo(n[1][0],n[1][1]),e.lineTo(r.l[0],r.l[1]),e.lineTo(r.r[0],r.r[1]),e.closePath(),e.fill()}if(!t.text)return;let i=t.kind===`text`?t.width:12;e.font=`600 ${i}px ${r}`,e.textBaseline=`top`;let a=t.text.split(`
614
+ `),o=i*1.25,s=n[0][0],c=n[0][1];t.kind===`box`&&(s=Math.min(n[0][0],n[1][0]),c=Math.min(n[0][1],n[1][1])-a.length*o-7),a.forEach((t,n)=>e.fillText(t,s+6,c+2+n*o))}var MZ={solid:void 0,dashed:`5 4`,dotted:`1 4`};function NZ(e,t,n){if(!e||!(n===`x`?e.x:e.y))return null;if(n===`x`){let n=YH(e,t.value);return n>=e.left-.5&&n<=e.left+e.width+.5?[n,e.top,n,e.top+e.height]:null}let r=ZH(e,t.value);return r>=e.top-.5&&r<=e.top+e.height+.5?[e.left,r,e.left+e.width,r]:null}var PZ=ot(function({frame:e,alarm:t,axis:n}){let r=NZ(pt(e.subscribe,e.get),t,n);if(!r)return null;let i=t.linked?FZ(r,n):null;return _t(`svg`,{className:`kymo-alarm`,"aria-hidden":`true`,children:[q(`line`,{x1:r[0],y1:r[1],x2:r[2],y2:r[3],stroke:t.color,strokeWidth:t.width,strokeDasharray:t.linked===`active`?iU.join(` `):MZ[t.style]}),i?q(`path`,{"data-alert-glyph":``,d:rU,transform:`translate(${i[0]} ${i[1]})`,fill:t.color}):null]})});function FZ(e,t){return t===`y`?[e[2]-10-3,e[1]-10-2]:[e[0]+3,e[1]+2]}function IZ(e,t,n,r,i){let a=NZ(t,n,r);if(a){if(e.save(),e.scale(i,i),e.strokeStyle=n.color,e.lineWidth=n.width,e.setLineDash(n.linked===`active`?iU:MZ[n.style]?.split(` `).map(Number)??[]),e.beginPath(),e.moveTo(a[0],a[1]),e.lineTo(a[2],a[3]),e.stroke(),n.linked){let t=FZ(a,r);oU(e,t[0],t[1],n.color)}e.restore()}}function LZ(e,t,n){return e.handlers?.wsId===n?e.handlers:e.handlers={wsId:n,onViewXRangeChange:r=>{t.view.setXRange(r,n),e.emitter.emit(`viewchange`,r)},onCursorX:e=>{try{t.view.setCursorX(e,n)}catch{}},cursor:{get:()=>{try{return t.view.cursorX(n)}catch{return null}},subscribe:e=>t.on(`cursorchange`,t=>{t.worksheetId===n&&e(t.x)})},onContextMenu:t=>e.emitter.emit(`contextmenu`,t),xyzRef:t=>{e.xyz=t},onAnnotations:n=>t.charts.setAnnotations(e.chartId,n),onAnnotationToolEnd:()=>{e.annotationTool=null,HZ(t).bump(),e.emitter.emit(`annotationtool`,null)},onAnnotationSelect:t=>{e.selectedAnnotation=t,e.emitter.emit(`annotationselect`,t)},onMarkSelect:t=>e.emitter.emit(`markselect`,t)}}var RZ=new WeakMap;function zZ(e,t){let n=RZ.get(e);n||RZ.set(e,n=new Map);let r=n.get(t);return r||n.set(t,r=n=>e.view.setLiveWindow(n,t)),r}var BZ=class{mounts=new Map;version=0;listeners=new Set;root=null;engine;constructor(e){this.engine=e}subscribe=e=>(this.listeners.add(e),()=>{this.listeners.delete(e)});getVersion=()=>this.version;bump(){this.version++;for(let e of[...this.listeners])e()}add(e){this.mounts.set(e.key,e),this.root||(this.root=ht(document.createElement(`div`)),this.root.render(q(JZ,{engine:this.engine,registry:this}))),this.bump()}remove(e){this.mounts.delete(e)&&this.bump()}refresh(){this.bump()}dispose(){this.mounts.clear(),this.root?.unmount(),this.root=null}},VZ=new WeakMap;function HZ(e){let t=VZ.get(e);return t||(t=new BZ(e),VZ.set(e,t)),t}function UZ(e,t,n,r={}){e.charts.get(t);let i=HZ(e),a={key:crypto.randomUUID(),chartId:t,element:n,options:r,shiftDatasetId:null,emitter:RV(),xyz:null,annotationTool:null,selectedAnnotation:null,plotFrame:eU(),status:null,data:null};i.add(a);let o=!1;return{chartId:t,status:()=>a.status,data:()=>a.data,on:(e,t)=>a.emitter.on(e,t),exportPng(){let r=Array.from(n.querySelectorAll(`canvas`));if(r.length===0)return Promise.reject(new kE(`export_failed`,{reason:`nothing to export`}));let i=document.createElement(`canvas`);i.width=r[0].width,i.height=r[0].height;let o=i.getContext(`2d`);if(!o)return Promise.reject(new kE(`export_failed`,{reason:`canvas unavailable`}));for(let e of r)o.drawImage(e,0,0);let s=e.charts.get(t),c=iQ(s.settings,o1(e).alertLines()),l=a.plotFrame.get()?.x?a.plotFrame.get():null,u=e.getState(),d=u.worksheets.find(e=>e.charts.some(e=>e.id===t)),f=sQ(s.annotations,d?aQ(u.marks,u.selection,d.xKey):[],l),p=tr(c);return p&&n.clientWidth>0&&IZ(o,a.plotFrame.get(),p.alarm,p.axis,i.width/n.clientWidth),f.length&&n.clientWidth>0&&AZ(o,f,n.clientWidth,n.clientHeight,i.width/n.clientWidth,Q.sans,l),new Promise((e,t)=>i.toBlob(n=>n?e(n):t(new kE(`export_failed`,{reason:`encode failed`})),`image/png`))},autoscale(){a.xyz?.autoscale()},setShiftMode(e){a.shiftDatasetId!==e&&(a.shiftDatasetId=e,i.bump())},setAnnotationTool(e){a.annotationTool=e?{...e}:null,i.bump()},annotationTool:()=>a.annotationTool,selectedAnnotation:()=>a.selectedAnnotation,setOptions(e){a.options={...e},i.bump()},destroy(){o||(o=!0,a.emitter.clear(),i.remove(a.key))}}}function WZ(e){VZ.get(e)?.refresh()}function GZ(e){VZ.get(e)?.dispose(),VZ.delete(e)}function KZ(e){let t=new MutationObserver(e);return t.observe(document.documentElement,{attributes:!0,attributeFilter:[`data-color-scheme`,`class`,`data-theme`]}),()=>t.disconnect()}var qZ=()=>{let e=document.documentElement;return`${e.getAttribute(`data-color-scheme`)??``}|${e.getAttribute(`data-theme`)??``}|${e.className}`};function JZ({engine:e,registry:t}){pt(t.subscribe,t.getVersion);let n=o1(e),r=pt(n.store.subscribe,n.store.get),i=new Map;for(let e of t.mounts.values()){let t=r.worksheets.find(t=>t.panels.some(t=>t.id===e.chartId));if(!t)continue;let n=i.get(t.id)??{worksheet:t,mounts:[]};n.mounts.push(e),i.set(t.id,n)}return q(gt,{children:[...i.values()].map(t=>q(QZ,{engine:e,worksheet:t.worksheet,mounts:t.mounts},t.worksheet.id))})}var YZ=1e3,XZ=.25;function ZZ(e,t,n,r){let[i,a]=ft(0),o=K(0),s=K(0);return W(()=>{o.current&&=(s.current=performance.now()-o.current,0)}),W(()=>{if(!n)return;let i=0,c=-1,l=0,u=n=>{if(i=bH(u),o.current||n<l||TH()||!r())return;let d=0;for(let n of e)t.includes(n.id)&&(d+=n.source.version());d!==c&&(c=d,l=n+s.current*(1/XZ-1),o.current=performance.now(),st(()=>a(e=>e+1)))};return i=bH(u),()=>xH(i)},[n,e,t]),dt(()=>n?e.map(e=>t.includes(e.id)?{...e,dataset:e.source.snapshot(YZ)}:e):e,[e,t,n,i])}function QZ({engine:e,worksheet:t,mounts:n}){let r=o1(e),i=pt(r.store.subscribe,r.store.get),a=r.derived(),o=i.xRanges[t.id]??null,s=dt(()=>i.live.filter(e=>e.kind===`data`),[i.live]),c=a.selectedLive.length,l=e=>{let n=t.panelChartSettings[e];return n?.kind===`multiband`&&n.beacon?.enabled===!0},u=c>0&&t.panels.some(e=>e.kind!==`multiband`&&e.kind!==`camera`||c>1&&!l(e.id)),d=K(n);d.current=n;let f=K(()=>d.current.some(e=>e.element.isConnected&&(typeof e.element.checkVisibility!=`function`||e.element.checkVisibility()))).current,p=ZZ(s,i.selection,u,f),m=r.alertLines(),h=$X({worksheet:nQ(t,m),viewXRange:o,selectedIds:i.selection,selectedDatasets:a.selectedDatasets,liveConnections:p,mathChannels:a.channels,datasetOffsets:i.offsets,datasetColors:i.colors,datasetPalette:i.palette}),g=K(IV()).current,_=pt(KZ,qZ),v=t.id,y=zZ(e,v),b=i.licensed,x=a.selectedLive[0]??null,S=e=>i.datasets.find(t=>t.id===e)??Object.values(a.laps).flatMap(e=>e.laps).find(t=>t.id===e);return q(gt,{children:n.map(n=>{let r=t.panels.find(e=>e.id===n.chartId);if(!r)return null;let s=n.shiftDatasetId?a.selectedDatasets.find(e=>e.id===n.shiftDatasetId):void 0,c=LZ(n,e,v),l=iQ(t.panelChartSettings[r.id],m);return mt(q(dQ,{mount:n,annotations:t.panelChartSettings[r.id]?.annotations,marks:aQ(i.marks,i.selection,t.xKey),onMarkSelect:c.onMarkSelect,alarm:tr(l),onAnnotations:c.onAnnotations,onAnnotationToolEnd:c.onAnnotationToolEnd,onAnnotationSelect:c.onAnnotationSelect,render:u=>rZ({panel:r,settings:l,background:n.options.style?.background??t.panelChartBackgrounds[r.id]??null,styleToken:JSON.stringify([_,n.options.theme,n.options.style,Q]),data:h,xKey:t.xKey,height:u,viewXRange:o,onViewXRangeChange:c.onViewXRangeChange,onCursorX:c.onCursorX,liveZoom:g,liveWindowSeconds:t.liveWindowSeconds===void 0?i.liveWindowSeconds:t.liveWindowSeconds,onLiveWindowChange:y,beaconLive:x,findDataset:S,live:i.live,selection:i.selection,cursor:c.cursor,video:e.video.sources(),recordings:cX(a.selectedDatasets,i.offsets),shiftMode:s?$Z(e,s.id,s.name):void 0,onContextMenu:c.onContextMenu,xyzRef:c.xyzRef}),licensed:b},n.key),n.element,n.key)})})}function $Z(e,t,n){let r=0;return{label:n,onDragStart:()=>{r=e.getState().datasets.find(e=>e.id===t)?.offset??0},onDragOffset:n=>e.datasets.setOffset(t,r+n)}}var eQ=[],tQ=new WeakMap;function nQ(e,t){if(!t.size)return e;let n=tQ.get(e);if(n&&n.lines===t)return n.out;let r=!1,i={};for(let[n,a]of Object.entries(e.panelChartSettings))i[n]=iQ(a,t),i[n]!==a&&(r=!0);let a=r?{...e,panelChartSettings:i}:e;return tQ.set(e,{lines:t,out:a}),a}var rQ=new WeakMap;function iQ(e,t){if(!e||!t.size)return e;let n=rQ.get(e);if(n&&n.lines===t)return n.out;let r=$n(e,t);return rQ.set(e,{lines:t,out:r}),r}var aQ=cQ((e,t,n)=>{let r=e.filter(e=>e.timeColumn===n&&t.includes(e.targetId));return r.length?r:oQ}),oQ=[];function sQ(e,t,n){return!t.length||!n?.x?e:[...t.map(e=>Lt(e,n.x.v1)),...e]}function cQ(e){let t=null,n;return(r,i,a)=>t&&t[0]===r&&t[1]===i&&t[2]===a?n:(t=[r,i,a],n=e(r,i,a),n)}function lQ(e,t){e.data=t}function uQ(e,t){e.status!==t&&(e.status=t,e.emitter.emit(`status`,t))}function dQ({mount:e,render:t,licensed:n,annotations:r,marks:i,alarm:a,onAnnotations:o,onAnnotationToolEnd:s,onAnnotationSelect:c,onMarkSelect:l}){let u=K(null),[d,f]=ft(0),p=!!e.options.debug,m=K({renderStart:0,lastRenderMs:0,renders:0,data:null}).current;p&&(m.renderStart=performance.now()),G(()=>{p&&(m.lastRenderMs=performance.now()-m.renderStart,m.renders++)}),G(()=>{let e=u.current;if(!e)return;let t=()=>f(Math.max(120,Math.floor(e.clientHeight)));t();let n=new EH(t);return n.observe(e),()=>n.disconnect()},[]);let{status:h,node:g,data:_}=t(d||400);m.data=_,W(()=>{lQ(e,_)}),W(()=>{uQ(e,h)});let{theme:v,style:y,className:b}=e.options,x={};return y?.background&&(x[`--chart-bg`]=y.background),y?.muted&&(x[`--chart-muted`]=y.muted),y?.grid&&(x[`--chart-grid`]=y.grid),y?.accent&&(x[`--accent`]=y.accent),_t(`div`,{ref:u,onContextMenu:h===`ready`?void 0:t=>{t.preventDefault(),e.emitter.emit(`contextmenu`,{clientX:t.clientX,clientY:t.clientY})},className:b?`kymo-chart ${b}`:`kymo-chart`,"data-color-scheme":v,"data-status":h,style:x,children:[q(tU.Provider,{value:e.plotFrame.set,children:g}),h===`ready`&&a?q(PZ,{frame:e.plotFrame,alarm:a.alarm,axis:a.axis}):null,h===`ready`&&(r?.length||e.annotationTool||i.length)?q(bZ,{annotations:r??eQ,tool:e.annotationTool,plotFrame:e.plotFrame,onChange:o,onToolEnd:s,onSelect:c,marks:i,onMarkSelect:l}):null,p?q(lZ,{stats:m,host:u}):null,n===!1?q(LV,{}):null]})}var fQ=new WeakMap;function pQ(e,t,n,r={}){let i=fQ.get(e)??new Map;fQ.set(e,i);let a=i.get(t);if(a&&!a.window.closed)return a.window.focus(),a;let o=e.charts.get(t),s=r.title??(o.title||e.charts.label(o.kind)),c=window.open(``,`kymoscope-chart-${t}`,`popup,width=${r.width??960},height=${r.height??600}`);if(!c)throw new kE(`popup_blocked`,{chartId:t});let l=c.document;l.head.replaceChildren(),l.body.replaceChildren(),l.title=s;for(let e of document.querySelectorAll(`style, link[rel="stylesheet"]`)){let t=e.cloneNode(!0);t instanceof HTMLLinkElement&&(t.href=e.href),l.head.appendChild(t)}let u=()=>{for(let e of[...l.documentElement.attributes])l.documentElement.removeAttribute(e.name);for(let e of document.documentElement.attributes)l.documentElement.setAttribute(e.name,e.value);l.body.className=document.body.className};u();let d=new MutationObserver(u);d.observe(document.documentElement,{attributes:!0}),d.observe(document.body,{attributes:!0,attributeFilter:[`class`]}),Object.assign(l.body.style,{margin:`0`,position:`fixed`,inset:`0`,display:`flex`,flexDirection:`column`,background:getComputedStyle(document.body).backgroundColor});let f=l.createElement(`div`);f.className=`kymo-window-controls`;let p=l.createElement(`div`);p.className=`kymo-window-plot`,Object.assign(p.style,{flex:`1`,minHeight:`0`,position:`relative`}),l.body.append(f,p),hH(c);let m=n(p,r.mount),h=RV(),g=!1,_=()=>{g||(g=!0,i.delete(t),gH(c),d.disconnect(),y(),window.removeEventListener(`pagehide`,v),m.destroy(),h.emit(`close`,void 0),h.clear())},v=()=>b.close(),y=e.subscribe(()=>{try{e.charts.get(t)}catch{b.close()}});c.addEventListener(`pagehide`,_),window.addEventListener(`pagehide`,v);let b={chartId:t,window:c,controls:f,view:m,close(){_(),c.closed||c.close()},on:(e,t)=>h.on(e,t)};return i.set(t,b),b}function mQ(e){for(let t of[...fQ.get(e)?.values()??[]])t.close()}function hQ(e,t,n=!1){let r=0,i=e.length;for(;r<i;){let a=r+i>>>1;(n?e[a]<=t:e[a]<t)?r=a+1:i=a}return r}function gQ(e,t,n){if(n<=t)return null;if(t===0&&n===e.t.length)return e;let r=e=>new Map([...e].map(([e,r])=>[e,r.subarray(t,n)])),i=r(e.lo);return{t:e.t.subarray(t,n),lo:i,hi:e.hi===e.lo?i:r(e.hi),level:e.level}}var _Q=(e,t,n)=>gQ(e,hQ(e.t,t),hQ(e.t,n,!0));function vQ(e,t,n,r){let i=[];for(let t of e){let e=gQ(t,0,hQ(t.t,n)),a=gQ(t,hQ(t.t,r,!0),t.t.length);e&&i.push(e),a&&i.push(a)}return[...i,...t]}var yQ=class{pieces;#e;#t;#n=new Map;#r=new Map;constructor(e,t={}){this.pieces=e.filter(e=>e.t.length>0).sort((e,t)=>e.t[0]-t.t[0]),this.#e=t;for(let e of this.pieces)for(let[t,n]of e.lo){let r=e.hi===e.lo?n:e.hi.get(t);if(!r)continue;let i=this.#n.get(t);i||this.#n.set(t,i=[]),i.push({t:e.t,L:n,H:r})}this.#t=[...this.#n.keys()].sort((e,t)=>e.localeCompare(t))}schemaSync(){return[{name:qe,type:`number`,unit:`s`},...this.#t.map(e=>({name:e,type:`number`,unit:this.#e[e]??``}))]}async getSchema(){return this.schemaSync()}async readColumns(e,t,n){let r=e.filter(e=>e===`ElapsedTime`||this.#n.has(e)),i=this.pieces.reduce((e,t)=>e+t.t.length,0),a=Math.max(0,Math.min(n,i-t)),o=Object.fromEntries(r.map(e=>[e,new Float64Array(a).fill(NaN)])),s=0;for(let e of this.pieces){let n=Math.max(0,t-s),i=Math.min(e.t.length,t+a-s);for(let a of r){let r=a===`ElapsedTime`?e.t:e.lo.get(a);r&&i>n&&o[a].set(r.subarray(n,i),s+n-t)}if(s+=e.t.length,s>=t+a)break}return o}getSeriesMultiSync(e,t,n){let{x0:r,x1:i}=t,a=t.xKey===`ElapsedTime`?e.filter(e=>this.#n.has(e)):[];if(!(i>r)||n<1||a.length===0)return{x0:r,bucket:0,rows:[],columns:a};let o=Math.floor(n),s=(i-r)/n,c=a.map(()=>new Float64Array(o).fill(1/0)),l=a.map(()=>new Float64Array(o).fill(-1/0));for(let e=0;e<a.length;e++){let t=c[e],n=l[e];for(let{t:c,L:l,H:u}of this.#n.get(a[e])){if(c[c.length-1]<r||c[0]>i)continue;let e=hQ(c,i,!0);for(let i=hQ(c,r);i<e;i++){let e=l[i];if(e!==e)continue;let a=Math.floor((c[i]-r)/s);a>=o&&(a=o-1),e<t[a]&&(t[a]=e),u[i]>n[a]&&(n[a]=u[i])}}}let u=[];for(let e=0;e<o;e++){let t=null;for(let n=0;n<a.length;n++)c[n][e]!==1/0&&(t??={b:e},t[`y${n}lo`]=c[n][e],t[`y${n}hi`]=l[n][e]);t&&u.push(t)}return{x0:r,bucket:s,rows:u,columns:a}}async getSeriesMulti(e,t,n){return this.getSeriesMultiSync(e,t,n)}async getSeries(e){let t=this.getSeriesMultiSync([e.column],e.viewport,e.maxPoints),n=t.rows.length,r={x:new Float64Array(n),min:new Float64Array(n),max:new Float64Array(n),first:new Float64Array(n),last:new Float64Array(n)};return t.rows.forEach((e,n)=>{r.x[n]=t.x0+(e.b+.5)*t.bucket,r.min[n]=r.first[n]=e.y0lo,r.max[n]=r.last[n]=e.y0hi}),r}xBoundsSync(e){let t=this.#r.get(e);if(t)return t;let n=1/0,r=-1/0;if(e===`ElapsedTime`)for(let e of this.pieces)n=Math.min(n,e.t[0]),r=Math.max(r,e.t[e.t.length-1]);for(let{L:t,H:i}of this.#n.get(e)??[])for(let e=0;e<t.length;e++)t[e]<n&&(n=t[e]),i[e]>r&&(r=i[e]);return t=n<=r?{x0:n,x1:r}:{x0:0,x1:0},this.#r.set(e,t),t}async xBounds(e){return this.xBoundsSync(e)}sampleRowsSync(e){let t=this.pieces.reduce((e,t)=>e+t.t.length,0),n=Math.max(1,Math.ceil(t/Math.max(1,e))),r=[],i=0,a=0;for(let e of this.pieces){let t=i-a;if(a+=e.t.length,!(t>=e.t.length))for(let a=t;a<e.t.length;a+=n,i+=n){let t={[qe]:e.t[a]};for(let[n,r]of e.lo){let e=r[a];t[n]=e===e?e:null}r.push(t)}}return r.sort((e,t)=>e[qe]-t[qe])}async dispose(){}},bQ=12e3,xQ=100;function SQ(e,t=!1){let n,r=0;if(t&&e instanceof Float64Array){n=e;let t=0,i=0,a=0,o=n.length&-4;for(let e=0;e<o;e+=4)r+=n[e]*0,t+=n[e+1]*0,i+=n[e+2]*0,a+=n[e+3]*0;for(let e=o;e<n.length;e++)r+=n[e]*0;r+=t+i+a}else{n=new Float64Array(e.length);for(let t=0;t<n.length;t++){let i=+e[t];n[t]=i,r+=i*0}}if(r===0)return u.add(n),n;for(let e=0;e<n.length;e++){let t=n[e];t-t!==0&&(n[e]=NaN)}return n}function CQ(e,t){let n=Object.keys(t.columns);if(n.length===0)throw new kE(`no_columns`);let r=t.columns[n[0]].length;if(n.some(e=>t.columns[e].length!==r))throw new kE(`column_length_mismatch`);let i=new Map(n.map(e=>[e,SQ(t.columns[e],t.transfer)])),a=wQ(e,t.name,i,t.units??{});if(t.bands){for(let e of Object.values(t.bands))if(e.lo.length!==r||e.hi.length!==r)throw new kE(`column_length_mismatch`);a.bands=Object.fromEntries(Object.entries(t.bands).map(([e,t])=>[e,{lo:Float64Array.from(t.lo),hi:Float64Array.from(t.hi)}]))}return a}function wQ(e,t,n,r,i,a){let o=[...n.keys()],s=n.get(o[0]).length,c=o.map(e=>r[e]??``),l=o.map((e,t)=>({name:e,type:`number`,unit:c[t]})),u=!!a&&a.schema.length===o.length&&a.schema.every((e,t)=>e.name===o[t]),d,f;if(u)d=a.rawText??``,f=a.parseConfig;else{let e=[o.join(`,`)];for(let t=0;t<Math.min(s,xQ);t++)e.push(o.map(e=>{let r=n.get(e)[t];return r===r?String(r):``}).join(`,`));d=e.join(`
615
+ `),f=y(d)}let p={id:e,name:t,schema:l,rawText:d,parseConfig:f,fromColumns:!0};if(s>1e6){let e=new PX(n,r);return{...p,kind:`columnar`,source:e,data:{meta:``,columnNames:o,units:c,rows:e.sampleRowsSync(bQ)}}}let m={meta:``,columnNames:o,units:c,rows:Me({keys:o,length:s,values:o.map(e=>n.get(e)),text:o.map(()=>null)},i)};return{...p,kind:`memory`,source:new LE(m),data:m}}function TQ(e,t,n){let r=e.fromColumns?EQ(e):null;if(!r)throw new kE(`invalid_argument`,{reason:`only datasets added with addColumns can be written`});let i=r.values().next().value.length,a=e.columnSpares??new Map,o={};for(let e of t){let t=a.get(e);t&&t.length===i&&t!==r.get(e)?(I(t),o[e]=t):o[e]=new Float64Array(i)}n(o,Object.fromEntries(t.map(e=>[e,r.get(e)])));let s=new Map(a);for(let e of t){let t=r.get(e);t?s.set(e,t):s.delete(e)}return{...DQ(e,o,!0),columnSpares:s}}function EQ(e){if(e.source instanceof PX)return new Map(e.source.columnMap);let t=Ue(e.data.rows);return t?new Map(t.keys.map((e,n)=>[e,t.values[n]])):null}function DQ(e,t,n=!1){let r=e.fromColumns?EQ(e):null;if(!r)throw new kE(`invalid_argument`,{reason:`only datasets added with addColumns can be replaced`});let i=r;for(let e of Object.keys(t))i.set(e,SQ(t[e],n));let a=i.values().next().value.length;for(let e of i.values())if(e.length!==a)throw new kE(`column_length_mismatch`);let o=Object.fromEntries(e.schema.map(e=>[e.name,e.unit])),s=wQ(e.id,e.name,i,o,e.kind===`memory`?e.data.rows:void 0,e),c=s.schema.length===e.schema.length&&s.schema.every((t,n)=>t.name===e.schema[n].name);return{...s,schema:c?e.schema:s.schema,beacon:e.beacon,bands:e.bands}}var OQ=new WeakMap;function kQ(e){let t=e.fromColumns?EQ(e):null;if(!t)return e.rawText??``;let n=e.data.rows,r=OQ.get(n);if(r===void 0){let e=[...t.keys()],i=e.map(e=>t.get(e)),a=[e.join(`,`)],o=i[0].length;for(let e=0;e<o;e++)a.push(i.map(t=>t[e]===t[e]?String(t[e]):``).join(`,`));OQ.set(n,r=a.join(`
616
+ `))}return r}function AQ(e,t){let n=new yQ(t.pieces,t.units),r=n.schemaSync();return{id:e,name:t.name,kind:`columnar`,source:n,schema:r,data:{meta:``,columnNames:r.map(e=>e.name),units:r.map(e=>e.unit),rows:n.sampleRowsSync(bQ)}}}function jQ(e){let t=e,n=new Set;return{get:()=>t,set(e){let r=e(t);if(r!==t){t=r;for(let e of[...n])try{e()}catch(e){console.error(`[kymoscope] subscriber failed`,e)}}},subscribe(e){return n.add(e),()=>{n.delete(e)}}}}function MQ(e){let t=null,n;return(...r)=>t&&t.length===r.length&&t.every((e,t)=>e===r[t])?n:(t=r,n=e(...r),n)}function NQ(){let e=MQ(e=>{let t={};for(let n of e){if(n.cut){let e=n.cut.defs.find(e=>e.id===n.cut.cycleId)?.show,r=e&&e.channel!==n.cut.timeKey?UB(e):null;t[n.id]=r?{laps:n.cut.parts,values:n.cut.found.map(e=>e.kpis?.[r]??null),unit:n.schema.find(t=>t.name===e.channel)?.unit??``,isTime:!1}:{laps:n.cut.parts,values:n.cut.found.map(e=>e.tend===null?null:e.tend-e.tstart),unit:`s`,isTime:!0};continue}if(!n.beacon||n.kind!==`memory`)continue;let{channel:e,metric:r,stat:i}=n.beacon,a=vB(n.data.rows,e);if(a.length===0)continue;let o=n.data.units[n.data.columnNames.indexOf(r)]??``;t[n.id]={laps:a.map((e,t)=>{let r={...n.data,rows:n.data.rows.slice(e.start,e.end)};return{...n,id:EB(n.id,t),name:`${n.name} · Cycle ${t+1}`,data:r,source:new LE(r)}}),values:a.map(e=>SB(n.data.rows,e,r,i)),unit:o,isTime:i===`span`&&wB(r,o)}}return t}),t=MQ((e,t,n)=>e.flatMap(e=>t[e.id]?t[e.id].laps.filter(e=>n.includes(e.id)):n.includes(e.id)?[e]:[])),n=MQ((e,t)=>e.filter(e=>e.kind===`data`&&t.includes(e.id))),r=MQ(e=>yX(e.map(e=>e.data))),i=MQ((e,t)=>t.length===0?e:yX(e?[e,...t.map(e=>e.dataset)]:t.map(e=>e.dataset))),a=MQ((e,t,n,r)=>{let i=new Set;if(e)for(let t of n.length>0?n:[e])for(let e of CX(t.columnNames,t.rows))i.add(e);for(let e of r)for(let t of e.dataset.columnNames)(t===`ElapsedTime`||e.source.hasValues(t))&&i.add(t);let a=e?e.columnNames.filter(e=>i.has(e)):[],o=t.filter(e=>e.kind!==`memory`).flatMap(e=>xz(e.schema));return[...new Set([...a,...o])]});return{lapsByDataset:e,selectedDatasets:t,selectedLive:n,staticDataset:r,mergedDataset:i,mergedParts:MQ((e,t)=>[...e.map(e=>e.data),...t.map(e=>e.dataset)]),numericColumns:MQ((e,t,n,r=[],i=[])=>{let o=a(e,t,r,i),s=new Set(o);return[...o,...n.map(e=>e.name).filter(e=>!s.has(e))]}),allColumns:MQ((e,t,n)=>[...new Set([...e?.columnNames??[],...t.filter(e=>e.kind!==`memory`).flatMap(e=>e.schema.map(e=>e.name)),...n.map(e=>e.name)])]),columnUnits:MQ((e,t)=>{let n={};e&&e.columnNames.forEach((t,r)=>{let i=e.units[r]?.trim();i&&(n[t]=i)});for(let e of t)e.units&&(n[e.name]=e.units);return n})}}var PQ=[{kind:`multiband`,label:`Multi-band`},{kind:`xyscatter`,label:`X-Y scatter`},{kind:`xyzmesh`,label:`X-Y-Z mesh`},{kind:`histogram`,label:`Histogram`},{kind:`polar`,label:`Polar`},{kind:`spectrum`,label:`Spectrum`},{kind:`boxplot`,label:`Box Plot`},{kind:`spectrogram`,label:`Spectrogram`},{kind:`heatmap`,label:`Heatmap`},{kind:`violin`,label:`Violin`},{kind:`confusion`,label:`Confusion Matrix`},{kind:`roc`,label:`ROC Curve`},{kind:`losscurve`,label:`Loss Curves`},{kind:`controlchart`,label:`Control Chart`},{kind:`parallelcoords`,label:`Parallel Coords`},{kind:`embedding`,label:`Embedding`},{kind:`flamegraph`,label:`Flame Graph`},{kind:`barchart`,label:`Bar Chart`},{kind:`radar`,label:`Radar`},{kind:`areachart`,label:`Area Chart`},{kind:`cdfchart`,label:`CDF / ECDF`},{kind:`bubblechart`,label:`Bubble Chart`},{kind:`treemap`,label:`Treemap`},{kind:`sankey`,label:`Sankey`},{kind:`calibration`,label:`Calibration Curve`},{kind:`gauge`,label:`Gauges`},{kind:`camera`,label:`Camera`},{kind:`qqplot`,label:`Q-Q Plot`},{kind:`gantt`,label:`Gantt Chart`}],FQ=new Map(PQ.map(e=>[e.kind,e.label]));function IQ(e){return FQ.get(e)??e}var LQ=`kymoscope-live.v1`,RQ=2e3,zQ=3e4,BQ=30,VQ=1e4,HQ=300,UQ=90,WQ=e=>e.startsWith(`eyJ`);function GQ(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 KQ(e,t){return`${e.replace(/\/+$/,``)}/v1/streams/${t}/watch`}function qQ(e,t,n,r){let i=null,a=null,o=null,s=!1,c=0,l=()=>{o&&=(clearTimeout(o),null)},u=(n,r)=>{l();let a=GQ(r);if(a===null)return;let c=WQ(r),d=c?Math.min(a,Date.now()/1e3+HQ):a,f=Math.min(Math.max((d-(c?UQ:BQ))*1e3-Date.now(),VQ),2**31-1);o=setTimeout(async()=>{o=null;let r=null;try{r=await e.getToken(t)}catch{r=null}if(!(s||i!==n||!r)){try{n.send(JSON.stringify({type:`auth`,token:r}))}catch{return}u(n,r)}},f)},d=()=>{if(s||a)return;let e=Math.min(zQ,RQ*2**c++)*(.75+Math.random()/2);a=setTimeout(()=>{a=null,f()},e)},f=async()=>{if(s)return;let a=null;try{a=await e.getToken(t)}catch{a=null}if(s)return;if(!a){r?.(`error`),d();return}let o=new WebSocket(KQ(e.url,t),[LQ,`bearer.${a}`]);o.binaryType=`arraybuffer`,i=o;let f=a;o.onopen=()=>{r?.(`subscribed`),u(o,f)},o.onmessage=e=>{c=0,typeof e.data!=`string`&&n(e.data)},o.onclose=()=>{i===o&&(i=null,l(),!s&&(r?.(`error`),d()))}};return f(),()=>{if(s=!0,a&&=(clearTimeout(a),null),l(),i){let e=i;i=null,e.close(1e3)}}}var JQ=960*1024,YQ=24;function XQ(e){let t=e.key&&e.fragIndex===0?new TextEncoder().encode(e.codec):new Uint8Array;if(t.length>255)throw Error(`codec string too long`);let n=e.key&&e.fragIndex===0?1+t.length:0,r=new Uint8Array(YQ+n+e.payload.length),i=new DataView(r.buffer);i.setUint8(0,1),i.setUint8(1,!!e.key|(e.last?2:0)),i.setUint8(2,1),i.setUint8(3,0),i.setFloat64(4,e.t,!0),i.setUint32(12,e.seq>>>0,!0),i.setUint16(16,e.fragIndex,!0),i.setUint16(18,e.fragCount,!0),i.setUint16(20,e.width,!0),i.setUint16(22,e.height,!0);let a=YQ;return n&&(r[a++]=t.length,r.set(t,a),a+=t.length),r.set(e.payload,a),r}function ZQ(e){if(e.length<YQ||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=YQ,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)}}function QQ(e){let t=Math.max(1,Math.ceil(e.data.length/JQ)),n=[];for(let r=0;r<t;r++)n.push(XQ({key:e.key,last:r===t-1,t:e.t,seq:e.seq,fragIndex:r,fragCount:t,width:e.width,height:e.height,codec:e.codec,payload:e.data.subarray(r*JQ,Math.min(e.data.length,(r+1)*JQ))}));return n}var $Q=class{samples=[];exact=!1;windowS;constructor(e=30){this.windowS=e}observe(e,t){if(e>1e9){this.samples=[],this.exact=!0;return}this.exact=!1;let n=t-e,r=this.samples[this.samples.length-1];for(r&&Math.abs(n-r.off)>1&&(this.samples=[]),this.samples.push({at:t,off:n});this.samples.length&&this.samples[0].at<t-this.windowS;)this.samples.shift()}quality(){return this.exact?`exact`:this.samples.length?`approx`:`none`}toWall(e,t=0){if(this.exact)return e+t/1e3;if(!this.samples.length)return null;let n=1/0;for(let e of this.samples)n=Math.min(n,e.off);return e+n+t/1e3}toStream(e,t=0){let n=this.toWall(0,t);return n===null?null:e-n}},e$=class{#e;constructor(e){this.#e=typeof e==`function`?e:()=>e}size(){return this.#e().size}get columnNames(){return this.#e().columnNames}version(){return this.#e().version}columns(){let e=this.#e();return new t$(new Set(e.columnNames),t=>e.mirrorColumn(t))}hasValues(e){return this.#e().hasValues(e)}snapshot(e){return this.#e().toDataset(e)}async getSchema(){let e=this.#e();return e.columnNames.map(t=>({name:t,type:`number`,unit:e.unitOf(t)}))}async getSeries(e){let t=this.#e();return $e(t.columnValues(e.viewport.xKey),t.columnValues(e.column),e.viewport.x0,e.viewport.x1,e.maxPoints)}async getSeriesMulti(e,t,n){return this.getSeriesMultiSync(e,t,n)}getSeriesMultiSync(e,t,n){return this.#e().decimateColumns(t.xKey,e,t.x0,t.x1,n)}getPointsSync(e,t,n){return this.#e().decimatePoints(t.xKey,e,t.x0,t.x1,n)}async xBounds(e){return this.xBoundsSync(e)}xBoundsSync(e){return this.#e().columnBounds(e)}xTravelSync(e,t){return this.#e().xTravel(e,t)}latestTimeSync(){return this.#e().latestTime()}xAtTimeSync(e,t,n=!1){return this.#e().xAtTime(e,t,n)}latestSync(e){return this.#e().lastValue(e)}latestValuesSync(e){let t=this.#e(),n=new Map;for(let r of e){let e=t.lastValue(r),i=t.lastKnown(r);Number.isFinite(e)?n.set(r,e):i&&n.set(r,i.v)}return n}valueBoundsSync(e){let t=this.#e().valueBounds(e),n=this.#e().lastKnown(e);if(!t&&!n)return null;let r=Math.min(t?.x0??1/0,n?.v??1/0),i=Math.max(t?.x1??-1/0,n?.v??-1/0);if(r!==i)return{min:r,max:i};let a=Math.max(.5,Math.abs(r)*.05);return{min:r-a,max:i+a}}lastKnownSync(e){return this.#e().lastKnown(e)}trackCycles(e){this.#e().trackCycles(e)}cycleSpanSync(e){return this.#e().cycleSpan(e)}decimateCycleSync(e,t,n,r,i){return this.#e().decimateCycle(e,t,n,r.x0,r.x1,i)}cyclePointsSync(e,t,n,r,i){return this.#e().decimateCyclePoints(e,t,n,r.x0,r.x1,i)}async readColumns(e,t,n){let r=this.#e(),i=new Set(r.columnNames),a={};for(let o of e)i.has(o)&&(a[o]=r.columnValues(o).slice(t,t+n));return a}async dispose(){}},t$=class extends Map{#e;#t;constructor(e,t){super(),this.#e=e,this.#t=t}get(e){if(!super.has(e)&&this.#e.has(e)){let t=this.#t(e);t&&super.set(e,t)}return super.get(e)}has(e){return this.#e.has(e)}},n$=4096,r$=5e3,i$=class{startedAt=Date.now();n=0;capacity=n$;time=new Float64Array(n$);cols=new Map;order=[];units=new Map;timeColumn;timeUnit;constructor(e=qe,t=`s`){this.timeColumn=e,this.timeUnit=t}get rows(){return this.n}add(e){this.n===this.capacity&&this.grow();let t=this.n;this.time[t]=e.t;for(let n of e.signals){let e=this.cols.get(n.name);e||(e=new Float64Array(this.capacity).fill(NaN),this.cols.set(n.name,e),this.order.push(n.name)),n.unit&&!this.units.get(n.name)&&this.units.set(n.name,n.unit),e[t]=typeof n.value==`number`?n.value:NaN}this.n++}addColumns(e){let t=se(e,this.timeColumn),n=e.t.length;for(;this.n+n>this.capacity;)this.grow();let r=this.n,i=(e,t)=>{if(t instanceof Float64Array||t instanceof Float32Array)e.set(t,r);else for(let i=0;i<n;i++)e[r+i]=+t[i]};i(this.time,e.t);for(let n of t){let t=this.cols.get(n);t||(t=new Float64Array(this.capacity).fill(NaN),this.cols.set(n,t),this.order.push(n));let r=e.units?.[n];r&&!this.units.get(n)&&this.units.set(n,r),i(t,e.columns[n])}this.n+=n}grow(){let e=this.capacity*2,t=new Float64Array(e);t.set(this.time),this.time=t;for(let[t,n]of this.cols){let r=new Float64Array(e).fill(NaN);r.set(n),this.cols.set(t,r)}this.capacity=e}toCsvParts(){let e=[this.timeColumn,...this.order],t=[this.timeUnit,...this.order.map(e=>this.units.get(e)??``)],n=[`${e.map(a$).join(`,`)}\n${t.map(a$).join(`,`)}\n`],r=this.order.map(e=>this.cols.get(e));for(let e=0;e<this.n;e+=r$){let t=Math.min(this.n,e+r$),i=``;for(let n=e;n<t;n++){i+=String(this.time[n]);for(let e of r){let t=e[n];i+=Number.isNaN(t)?`,`:`,${t}`}i+=`
617
+ `}n.push(i)}return n}};function a$(e){let t=/^[=+\-@\t\r]/.test(e)?`'${e}`:e;return/[",\n\r]/.test(t)?`"${t.replace(/"/g,`""`)}"`:t}var o$=512,s$=new WeakMap;function c$(e,t,n){let r=s$.get(e);r||s$.set(e,r=new Map);let i=r.get(t),a={start:n,values:[]};return{carry:{start:e=>{let t=i?.values[e];if(!i||!t)return 0;for(let e=Math.min(n-i.start,t.length-1);e>=0;e--){let n=t[e];if(n!==null&&Number.isFinite(n))return n}return 0},done:(e,t)=>{a.values[e]=t}},keep:()=>{r.set(t,a)}}}function l$(e,t,n){let r=e.endAbs,i=Math.max(n,e.firstAbs);if(i>=r||t.length===0)return;let a=new Set(e.columnNames);for(let n of t){if(!n.enabled)continue;let o=eE(n.formula);if(!o.ok)continue;let{identifiers:s,functions:c}=tE(o.node);if(!s.every(e=>a.has(e)))continue;let l=c.some(e=>QT.includes(e)),u=Math.max(e.firstAbs,i-(l?o$:0)),d=new Map([qe,...s].map(t=>[t,e.range(t,u,r)])),{carry:f,keep:p}=c$(e,`${n.id}|${n.formula}`,u),m=sE(n,e=>d.get(e),qe,r-u,t,f);m.status===`ok`&&(e.writeComputed(n.name,n.units,i,m.values.subarray(i-u)),p())}}function u$(e,t){e.clearComputed(),s$.delete(e),l$(e,t,e.firstAbs)}var d$=8e3,f$=131072;function p$(e,t={}){switch(e.kind){case`elapsed`:return{name:`Elapsed`,unit:`s`};case`event`:return{name:`Since ${e.channel} ${e.op} ${e.value}`,unit:`s`};case`clock`:return{name:`Time of day`,unit:`s`};default:{let n=t[e.channel]??``;return e.integral?{name:`∫${e.channel}`,unit:n?`${n}·s`:`s`}:{name:`${e.channel} since start`,unit:n}}}}var m$=new Map;function h$(e,t){let n=`${t}|${Math.floor(e/900)}`,r=m$.get(n);r===void 0&&(r=dB(e,t),m$.size>1e4&&m$.clear(),m$.set(n,r));let i=(e+r)%86400;return i<0?i+86400:i}var g$=class{axis;#e=NaN;#t=NaN;#n=NaN;#r=0;#i=NaN;#a=NaN;constructor(e){this.axis=e}begin(e){this.#e=e,this.#t=NaN,this.#n=NaN,this.#r=0,this.#i=NaN,this.#a=NaN}x(e,t){let n=this.axis;return n.kind===`clock`?h$(e,n.tz):n.kind===`elapsed`?e-this.#e:e<this.#e?NaN:n.kind===`event`?(this.#t!==this.#t&&t===t&&aB(n.op,t,n.value)&&(this.#t=e),e-this.#t):n.integral?(t===t&&(this.#i===this.#i&&(this.#r+=(t+this.#i)/2*(e-this.#a)),this.#i=t,this.#a=e),this.#i===this.#i?this.#r:NaN):(t===t&&(this.#n!==this.#n&&(this.#n=t),this.#i=t),this.#i===this.#i?this.#i-this.#n:NaN)}};function _$(e,t,n,r){let i=`channel`in r?t.get(r.channel):void 0;if(r.kind===`event`){let a=NaN;for(let t=0;t<e.length&&a!==a;t++){let o=i?i[t]:NaN;e[t]>=n&&o===o&&aB(r.op,o,r.value)&&(a=e[t])}return{x:e.map(e=>e-a),t:e,cols:t}}let a=new g$(r);a.begin(n);let o=new Float64Array(e.length);for(let t=0;t<e.length;t++)o[t]=a.x(e[t],i?i[t]:NaN);return{x:o,t:e,cols:t}}function v$(e,t,n){let r=[];for(let n=0;n<e.length;n++)e[n]===e[n]&&t[n]===t[n]&&r.push(n);let i=!0;for(let t=1;t<r.length&&i;t++)i=e[r[t-1]]<=e[r[t]];i||r.sort((t,n)=>e[t]-e[n]);let a=r.length,o=new Float64Array(n.length).fill(NaN);if(a<2)return o;let s=Float64Array.from(r,t=>e[t]),c=Float64Array.from(r,e=>t[e]),l=Float64Array.from({length:a-1},(e,t)=>s[t+1]-s[t]).sort(),u=l[l.length>>1],d=u>0?4*u:1/0,f=0;for(let e=0;e<n.length;e++){let t=n[e];if(!(t>=s[0]&&t<=s[a-1]))continue;for(;f<a-2&&s[f+1]<t;)f++;let r=s[f],i=s[f+1];i-r>d||(o[e]=i===r?c[f]:c[f]+(c[f+1]-c[f])*(t-r)/(i-r))}return o}function y$(e,t,n){let r=e.length;if(r===0||!(n>=e[0]&&n<=e[r-1]))return NaN;if(r===1)return t[0];let i=(n-e[0])/(e[r-1]-e[0])*(r-1),a=Math.min(r-2,Math.floor(i));return t[a]+(t[a+1]-t[a])*(i-a)}function b$(e,t,n){let r=Math.max(2,Math.min(d$,Math.floor(n)));if(r*t.length>131072)throw Error(`too_many_cells`);let i=1/0,a=-1/0;for(let t of e)for(let e of t.x)e===e&&(e<i&&(i=e),e>a&&(a=e));if(!(a>i))throw Error(`empty`);let o=Float64Array.from({length:r},(e,t)=>i+t*(a-i)/(r-1)),s=new Map;for(let n of t){let t=new Uint16Array(r),i=new Float64Array(r),a=new Float64Array(r),c=new Float32Array(r).fill(1/0),l=new Float32Array(r).fill(-1/0);for(let s of e){let e=s.cols.get(n);if(!e)continue;let u=v$(s.x,e,o);for(let e=0;e<r;e++){let n=u[e];if(n!==n)continue;let r=++t[e],o=n-i[e];i[e]+=o/r,a[e]+=o*(n-i[e]),n<c[e]&&(c[e]=n),n>l[e]&&(l[e]=n)}}let u={mean:new Float32Array(r),sd:new Float32Array(r),min:c,max:l,n:t};for(let e=0;e<r;e++){if(t[e]===0){u.mean[e]=u.sd[e]=u.min[e]=u.max[e]=NaN;continue}u.mean[e]=i[e],u.sd[e]=t[e]>1?Math.sqrt(a[e]/(t[e]-1)):0}s.set(n,u)}return{x:o,channels:s}}function x$(e,t){if(e.unit===`abs`)return e.tolerance;let n=1/0,r=-1/0;for(let e of t.mean)e===e&&(e<n&&(n=e),e>r&&(r=e));return r>=n?Math.max(r-n,Math.abs(r),Math.abs(n))*e.tolerance/100:0}var S$=new WeakMap;function C$(e){let t=S$.get(e);if(t)return t;let n=e.sd.length,r=Math.max(2,Math.round(n/100));t=new Float32Array(n).fill(NaN);for(let i=0;i<n;i++){if(e.n[i]<2)continue;let a=0,o=0;for(let t=Math.max(0,i-r);t<=Math.min(n-1,i+r);t++)e.n[t]>=2&&e.sd[t]===e.sd[t]&&(a+=e.sd[t]**2,o++);t[i]=o?Math.sqrt(a/o):NaN}return S$.set(e,t),t}function w$(e,t,n){if(n===`minmax`)return{lo:e.min,hi:e.max};if(n===`sigma`){let n=C$(e);return{lo:e.mean.map((e,r)=>e-t*n[r]),hi:e.mean.map((e,r)=>e+t*n[r])}}let r=x$(n,e);return{lo:e.mean.map(e=>e-r),hi:e.mean.map(e=>e+r)}}function T$(e,t,n,r=`sigma`,i=0){let a=typeof r==`function`?r:()=>({band:r,k:n}),o=[...t.channels.keys()],s=new Map,c=new Map,l=[],u=new Uint8Array(e.t.length),d=o.map(()=>new Uint8Array(e.t.length)),f=t.x.length;o.forEach((n,r)=>{let i=t.channels.get(n),o=e.cols.get(n);if(!o)return;let{band:p,k:m}=a(n),h=typeof p==`object`?p:null,{lo:g,hi:_}=w$(i,m,p),v=0,y=0,b=0;for(let e of i.mean)if(e===e){v++;let t=e-y;y+=t/v,b+=t*(e-y)}let x=v>1?Math.max(Math.sqrt(b/(v-1)),1e-9):1e-9,S=h?Math.max(x$(h,i),1e-9):0,C=C$(i),w=new Float64Array(e.t.length).fill(NaN),T=new Float64Array(e.t.length).fill(NaN),E=0,D=0;for(let n=0;n<e.t.length;n++){let a=o[n],s=e.x[n];if(a!==a||s!==s)continue;let c=y$(t.x,i.mean,s);if(c!==c)continue;w[n]=a-c;let l=Math.round((s-t.x[0])/(t.x[f-1]-t.x[0])*(f-1));T[n]=Math.abs(a-c)/(h?S:i.n[l]>=2&&C[l]===C[l]?Math.max(C[l],1e-9):x),E+=T[n],D++,(h||i.n[l]>=2)&&(a<y$(t.x,g,s)||a>y$(t.x,_,s))&&(u[n]=1,d[r][n]=1)}s.set(n,w),c.set(n,T),l.push({channel:n,z:D?E/D:0})}),l.sort((e,t)=>t.z-e.z);let p=[];for(let t=0;t<u.length;t++){if(!u[t])continue;let n=t;for(;n<u.length&&u[n];)n++;let r=p[p.length-1];r&&e.t[t]-e.t[Math.min(r[1],u.length-1)]<i?r[1]=n:p.push([t,n]),t=n}let m=[];for(let[t,n]of p){let r=e.t[t],a=e.t[Math.min(n,u.length-1)];a-r>=i&&m.push({t0:r,t1:a,channels:o.filter((e,r)=>d[r].subarray(t,n).includes(1))})}return{delta:s,score:l,deviations:m,z:c}}function E$(e,t){let n=e.x.length,r=t.length,i=new DataView(new ArrayBuffer(12+8*n+r*n*18));[75,82,66,49].forEach((e,t)=>i.setUint8(t,e)),i.setUint32(4,n,!0),i.setUint32(8,r,!0);let a=12;for(let t=0;t<n;t++,a+=8)i.setFloat64(a,e.x[t],!0);for(let r of t){let t=e.channels.get(r);if(!t)throw Error(`The reference has no channel ${r}`);for(let e of[t.mean,t.sd,t.min,t.max])for(let t=0;t<n;t++,a+=4)i.setFloat32(a,e[t],!0);for(let e=0;e<n;e++,a+=2)i.setUint16(a,t.n[e],!0)}return De(new Uint8Array(i.buffer))}function D$(e,t){let n=le(e),r=new DataView(n.buffer,n.byteOffset,n.byteLength);if(n.length<12||String.fromCharCode(n[0],n[1],n[2],n[3])!==`KRB1`)throw Error(`Not a reference band`);let i=r.getUint32(4,!0),a=r.getUint32(8,!0);if(a!==t.length||n.length!==12+8*i+a*i*18)throw Error(`This reference band does not match its channels`);let o=12,s=new Float64Array(i);for(let e=0;e<i;e++,o+=8)s[e]=r.getFloat64(o,!0);let c=new Map;for(let e of t){let t=()=>{let e=new Float32Array(i);for(let t=0;t<i;t++,o+=4)e[t]=r.getFloat32(o,!0);return e},n=t(),a=t(),s=t(),l=t(),u=new Uint16Array(i);for(let e=0;e<i;e++,o+=2)u[e]=r.getUint16(o,!0);c.set(e,{mean:n,sd:a,min:s,max:l,n:u})}return{x:s,channels:c}}var O$=` Δ`,k$=class{#e;constructor(e){this.#e=new jB(e)}assumeOpen(e){}feed(e,t,n){let r=[];for(let i=0;i<e.length;i++)this.#e.step(e[i],e=>{let n=t(e);return n?n[i]:NaN},r),n?.(i,this.#e.open()?.tstart??null);return r.map(e=>({tstart:e.tstart,tend:e.tend,kpis:{duration:(e.tend??e.tstart)-e.tstart},...e.flags.length?{flags:e.flags}:{}}))}};function A$(e){if(!e.cycle&&!e.rule)throw Error(`a live segment axis needs a rule or a cycle rule`);let t=e.cycle?new k$(e.cycle):new gB(e.rule,e.kpis??[]),n=new g$(e.axis),r=NaN;e.start!=null&&(t.assumeOpen(e.start),n.begin(e.start),r=e.start);let i=e.reference??null,a=i?[...i.channels]:[],o=i?i.grid.length:0,s=`channel`in e.axis?e.axis.channel:null,c=[...new Set([...e.cycle?AB(e.cycle):iB(e.rule),...(e.kpis??[]).map(e=>e.channel),...s?[s]:[],...a.map(([e])=>e)])],l=e.minDeviationS??5,u=NaN,d=NaN,f=NaN,p=new Set,m=!1,h=e=>{m&&e({type:`deviation-end`,t0:u,t1:d,channels:[...p]}),u=d=f=NaN,p=new Set,m=!1};return{feed(g,_,v=!1){let y=Math.max(_,g.firstAbs),b=g.endAbs;if(y>=b)return;let x=t=>{v||e.onEvent?.(t)},S=g.range(qe,y,b),C=new Map(c.map(e=>[e,g.range(e,y,b)])),w=new Float64Array(S.length).fill(NaN),T=a.map(([e,t])=>({name:e,b:t,v:C.get(e),d:new Float64Array(S.length).fill(NaN)})),E=s?C.get(s):null,D=t.feed(S,e=>C.get(e),(e,t)=>{if(t===null)return;t!==r&&(h(x),r=t,n.begin(t),x({type:`open`,tstart:t}));let a=n.x(S[e],E?E[e]:NaN);if(w[e]=a,!i||a!==a)return;let s=o>1?Math.round((a-i.grid[0])/(i.grid[o-1]-i.grid[0])*(o-1)):0,c=!1;for(let t of T){let n=t.v[e],r=y$(i.grid,t.b.mean,a);n!==n||r!==r||(t.d[e]=n-r,t.b.n[s]>=2&&(n<y$(i.grid,t.b.lo,a)||n>y$(i.grid,t.b.hi,a))&&(c=!0,p.add(t.name)))}c?(u!==u&&(u=S[e]),d=S[e],f=NaN,!m&&S[e]-u>=l&&(m=!0,x({type:`deviation`,t0:u,channels:[...p]}))):u===u&&(f!==f&&(f=S[e]),S[e]-f>=l&&h(x))});for(let e of D)x({type:`close`,segment:e});g.writeComputed(e.column,e.unit,y,w);for(let e of T)g.writeComputed(`${e.name} Δ`,g.unitOf(e.name),y,e.d)}}}var j$=1e7;function M$(e=globalThis.navigator?.deviceMemory){return Math.max(512,Math.round(((e??0)>0?e:16)*1024/8))}var N$=400,P$=4e3,F$=1e3,I$=3e3,L$=2,R$=5e3,z$=1e4;function B$(e,t,n=`data`){let r=new Xe(t.capacity??j$,void 0,void 0,(t.maxMemoryMB??M$())*1024*1024);return{meta:e,buffer:r,source:new e$(()=>r),unsub:()=>{},status:`connecting`,error:null,lastFrameAt:Date.now(),lastColCount:0,lastValued:0,recorder:null,schemas:new Map,video:n===`camera`?new OE:null,clock:n===`camera`?null:new $Q,lagTicks:0,lastRejoinAt:0,rejoin:()=>{},subscribed:!1,releaseTimer:void 0}}function V$(e,t,n=()=>({}),r){let i=new Map,a=e,o=[],s=[],c=``,l=()=>{let e=[];for(let t of i.values())t.lastColCount=t.buffer.columnNames.length,t.lastValued=t.buffer.valuedCount,e.push({...t.meta,kind:t.video?`camera`:`data`,video:t.video,clock:t.clock,dataset:t.buffer.toDataset(N$),source:t.source,rowCount:t.buffer.size,status:t.status,error:t.error,recordingSince:t.recorder?.startedAt??null});o=e,t(o)},u=(e,t)=>{let n=!1,r=e.buffer.endAbs;for(let r of t)r&&typeof r.t==`number`&&Array.isArray(r.signals)&&(e.buffer.push(r),e.recorder?.add(r),n=!0);n&&p(e,r,t[t.length-1]?.t)},d=(e,t)=>{let n=e.buffer.endAbs;e.buffer.pushColumns(t),e.recorder?.addColumns(t),t.t.length>0&&p(e,n,t.t[t.t.length-1])},p=(e,t,n)=>{l$(e.buffer,s,t),e.segAxis?.tracker.feed(e.buffer,t),r?.rows(e.meta.id,e.buffer,t),typeof n==`number`&&e.clock?.observe(n,Date.now()/1e3),m(e,t===0||e.buffer.columnNames.length!==e.lastColCount||e.buffer.valuedCount!==e.lastValued)},m=(e,t)=>{e.lastFrameAt=Date.now();let n=e.status===`stale`||e.status===`connecting`;n&&(e.status=`live`),(n||t)&&l()},h=e=>{let t=i.get(e);t&&(clearTimeout(t.releaseTimer),t.unsub(),i.delete(e),l())},g=setInterval(()=>{let e=Date.now(),t=!1;for(let n of i.values()){n.status===`live`&&e-n.lastFrameAt>P$&&(n.status=`stale`,t=!0);let i=n.video&&n.subscribed&&n.status===`live`?n.video.info().lagMs:null;n.lagTicks=i!==null&&i>I$?n.lagTicks+1:0,n.video&&n.lagTicks>=L$&&e-n.lastRejoinAt>=R$&&(n.lagTicks=0,n.lastRejoinAt=e,n.video.resync(),n.unsub(),n.rejoin()),n.buffer.size&&r?.tick(n.meta.id,n.buffer,n.lastFrameAt)}t&&l()},F$);return{connections:()=>o,disconnect:h,startRecording(e){let t=i.get(e);!t||t.recorder||(t.recorder=new i$,l())},stopRecording(e){let t=i.get(e),n=t?.recorder;return!t||!n?null:(t.recorder=null,l(),{csv:n.toCsvParts(),rows:n.rows,name:t.meta.name,startedAt:n.startedAt})},setRelay(e){a=e},setSegmentAxis(e,t){let n=i.get(e);n&&(n.segAxis=t?{cfg:t,tracker:A$(t)}:void 0,t&&n.segAxis.tracker.feed(n.buffer,n.buffer.firstAbs,!t.replay),l())},setMathChannels(e){let t=JSON.stringify(e.map(e=>[e.id,e.name,e.units,e.formula,e.enabled]));if(t!==c){c=t,s=e;for(let t of i.values())t.video||(u$(t.buffer,e),t.segAxis&&(t.segAxis.tracker=A$(t.segAxis.cfg),t.segAxis.tracker.feed(t.buffer,t.buffer.firstAbs,!0)));i.size>0&&l()}},openLocal(e,t){let r=`local:${crypto.randomUUID()}`,a=B$({id:r,name:e,ownerName:`This page`,visibility:`private`,orgName:null,parentId:null,lowOf:null},{...n(),...t});return i.set(r,a),l(),{id:r,push:e=>{i.get(r)===a&&u(a,Array.isArray(e)?e:[e])},pushColumns:e=>{i.get(r)===a&&d(a,e)},close:()=>h(r)}},async connect(e,t,r){if(i.has(e.id))return;let o=a&&e.relay_url?{...a,url:e.relay_url}:a;if(!o)throw new kE(`relay_unavailable`);let s=typeof t==`string`?await f(ue(t).secret??t,e.salt):`keyFor`in t?e=>t.keyFor(e):t;if(typeof s!=`function`&&!await ge(s,e.key_check))throw new kE(`wrong_password`);let c=B$({id:e.id,name:e.name,ownerName:e.owner_name??``,visibility:e.visibility??`private`,orgName:e.org_name??null,projectName:e.project_name??null,parentId:e.parent_stream_id??null,lowOf:e.low_of_stream_id??null},{...n(),...r},e.kind);i.set(e.id,c);let p=Promise.resolve();c.rejoin=()=>{c.unsub=qQ(o,e.id,t=>{let n=ye(s,t).catch(()=>null);p=p.then(async()=>{try{let t=await n;if(!t||i.get(e.id)!==c)return;if(t.kind===6){let e=ZQ(t.plaintext);e&&c.video&&(c.video.push(e),m(c,!1));return}if(t.kind===5){let e=de(t.plaintext);c.schemas.set(e.id,e);return}if(t.kind===7){let e=he(t.plaintext,c.schemas);if(!e)return;let n=c.buffer;for(let t of e)n.setLastKnown(t.name,t.unit,t.t,t.v);(n.columnNames.length!==c.lastColCount||n.valuedCount!==c.lastValued)&&l();return}if(t.kind===4){let e=await Ge(t.plaintext,c.schemas);e&&!e.historical&&d(c,e.block);return}if(t.kind===3)return d(c,Ie(t.plaintext));if(t.kind!==2)return;let r=ie(t.plaintext);u(c,Array.isArray(r?.frames)?r.frames:[])}catch{}})},t=>{!c.subscribed||i.get(e.id)!==c||(t===`subscribed`?(c.status=`live`,c.lastFrameAt=Date.now()):t===`error`&&(c.status=`error`,c.error=`connection_error`),l())})};let h=c.video;h?(c.status=`idle`,h.onDemandChange(t=>{i.get(e.id)===c&&(clearTimeout(c.releaseTimer),t?c.subscribed||(c.subscribed=!0,h.resync(),c.status=`connecting`,c.lastFrameAt=Date.now(),c.rejoin(),l()):c.releaseTimer=setTimeout(()=>{c.subscribed=!1,c.unsub(),c.unsub=()=>{},c.status=`idle`,c.error=null,c.lagTicks=0,l()},z$))})):(c.subscribed=!0,c.rejoin()),l()},dispose(){clearInterval(g);for(let e of i.values())clearTimeout(e.releaseTimer),e.unsub();i.clear(),o=[]}}}var H$=500,U$=1<<20;function W$(e){let t=[],n=new Map,r=[],i=``,a=(e,t)=>`${e}|${t}`,o=(e,t)=>{let n=t.kind===`stream`?e.targets?.streams:t.kind===`history`?e.targets?.histories:e.targets?.datasets;return!n||n.includes(t.kind===`dataset`?t.name??t.id:t.id)},s=()=>[...n.values()].map(e=>{let{state:t,missing:n,since:r}=e.state();return{ruleId:e.rule.id,target:e.target,state:t,...n?{missing:n}:{},...r===void 0?{}:{since:r}}}),c=()=>{let t=s(),n=JSON.stringify(t);n!==i&&(i=n,e.setStates(t))};function l(n,i){let a=t.find(e=>e.id===n.ruleId);if(n.kind===`raised`){r=[...r,{id:`${n.ruleId}|${n.target.id}|${n.t}`,ruleId:n.ruleId,ruleName:a?.name??``,severity:a?.severity??`info`,targetId:n.target.id,timeColumn:i,t0:n.t,t1:null}];let e=r.filter(e=>e.targetId===n.target.id);e.length>H$&&(r=r.filter(t=>t!==e[0]))}else{let e=r.find(e=>e.ruleId===n.ruleId&&e.targetId===n.target.id&&e.t1===null);e&&(r=r.map(t=>t===e?{...t,t1:n.t}:t))}e.setMarks(r),e.emit(n)}function u(){let r=new Set;for(let i of e.targets())for(let e of t){if(!o(e,i))continue;let t=a(e.id,i.id);r.add(t);let s=n.get(t),{channels:c,...u}=i;(!s||s.rule!==e)&&(s=et(e,u),n.set(t,s));for(let e of s.bind(c))l(e,i.kind===`stream`?qe:``)}for(let e of n.keys())r.has(e)||n.delete(e);c()}return{setRules(n){let r=[],i=n.filter(e=>{let t=tt(e);return r.push(...t.map(t=>({ruleId:String(e?.id??``),...t}))),!t.length}),a=e.maxRules();a!==null&&i.length>a&&e.limit();let o=new Map(t.map(e=>[e.id,e]));return t=(a===null?i:i.slice(0,a)).map(e=>{let t=o.get(e.id);return t&&t.version===e.version?t:e}),u(),r},rules:()=>t,state:s,async evaluate(n,i){let a=e.targets().find(e=>e.id===n&&e.kind===`dataset`);if(!a)return[];let{channels:s,...c}=a,u=[],d=t.filter(e=>(!i.ruleIds||i.ruleIds.includes(e.id))&&o(e,c)),f=d.map(e=>{let t=et(e,c);return t.bind(s),t}),p=[...new Set(d.flatMap(e=>Object.values(e.signals).map(e=>`formula`in e?e.formula:e.channel)))];for(let t=0;;t+=U$){let r=await e.readDataset(n,[i.timeColumn,...p],t,U$),a=r[i.timeColumn];if(!a||!a.length)break;for(let e of f)u.push(...e.push({t:a,columns:r}));if(a.length<U$)break}r=r.filter(e=>!(e.targetId===n&&(!i.ruleIds||i.ruleIds.includes(e.ruleId)))),e.setMarks(r);for(let e of u)l(e,i.timeColumn);return u},pushLive(e,t){let r=!1;for(let i of n.values()){if(i.target.id!==e)continue;let n=i.push(t);n.length&&(r=!0);for(let e of n)l(e,qe)}r&&c()},tickLive(e,t){let r=!1;for(let i of n.values()){if(i.target.id!==e)continue;let n=i.tick(t);n.length&&(r=!0);for(let e of n)l(e,qe)}r&&c()},liveColumns(e){let t=new Set;for(let r of n.values())if(r.target.id===e)for(let e of Object.values(r.rule.signals))t.add(`formula`in e?e.formula:e.channel);return[...t]},sync:u,clearMarks(t){r=t?r.filter(e=>e.targetId!==t):[],e.setMarks(r)}}}var G$=class{past=[];future=[];current=null;lastAt=-1/0;o;equals;constructor(e){this.o=e,this.equals=e.equals??Object.is}get canUndo(){return this.past.length>0}get canRedo(){return this.future.length>0}observe(e){if(this.current===null)return this.current=e,!1;if(this.equals(e,this.current))return!1;let t=this.o.now();return t-this.lastAt<this.o.mergeMs&&this.past.length>0||(this.past.push(this.current),this.past.length>this.o.limit&&this.past.shift()),this.current=e,this.future=[],this.lastAt=t,!0}rebase(e){this.current=e}undo(){if(this.past.length===0)return null;let e=this.past.pop();return this.future.push(this.current),this.current=e,this.lastAt=-1/0,e}redo(){if(this.future.length===0)return null;let e=this.future.pop();return this.past.push(this.current),this.current=e,this.lastAt=-1/0,e}clear(e){this.past=[],this.future=[],this.current=e,this.lastAt=-1/0}},K$={maxChartsPerWorksheet:null,maxChannelsPerChart:null,maxWorksheets:null,maxMathChannels:null,maxAlertRules:null,canImportExportWorkspaces:!0},q$=[];function J$(e,t){let n=e.found[t];return{definitionId:n.definitionId,rule:e.defs.find(e=>e.id===n.definitionId)?.name??n.definitionId,index:n.index,parentIndex:n.parentIndex??null,tstart:n.tstart,tend:n.tend,flags:n.flags,kpis:n.kpis??{},incomplete:!!n.incomplete}}var Y$=[`#a78bfa`,`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#94a3b8`];function X$(e=`ET`){return{id:crypto.randomUUID(),name:`Worksheet`,panels:[],panelChartSettings:{},panelChartBackgrounds:{},xKey:e}}function Z$(e,t){let n=e.filter(e=>e.source!==`workbook`),r=new Map,i=[];for(let e of t){let t=n.find(t=>t.name===e.name);if(t&&t.formula===e.formula&&t.units===e.units)continue;let a=t?`${e.name} (workbook)`:e.name;t&&r.set(e.name,a),i.push(cr({...e,name:a,source:`workbook`}))}return{channels:i,rename:r}}function Q$(e,t){let n=JSON.stringify({xKey:e.xKey,panelChartSettings:e.panelChartSettings});for(let[e,r]of t)n=n.split(JSON.stringify(e)).join(JSON.stringify(r));return{...e,...JSON.parse(n)}}function $$(e){return typeof e.text==`function`?e.text():new Promise((t,n)=>{let r=new FileReader;r.onload=()=>t(String(r.result??``)),r.onerror=()=>n(r.error),r.readAsText(e)})}function e1(e,t,n){if(!e||!t)return $t();let{min:r,max:i}=Sz(e.rows,t);if(!Number.isFinite(r)||!Number.isFinite(i))return $t();let a=wz(i-r||1,6),o=a>=1?Math.round(a):a,s=o>=1?1:o/10,c=Math.max(0,Math.ceil(-Math.log10(s))),l=e=>String(Number(e.toFixed(c)));return{...n,scaleMin:l(Math.floor(r/s)*s),scaleMax:l(Math.ceil(i/s)*s),majorStep:l(o),minorStep:``}}function t1(e,t){let n=t.includes(e.xKey)?e.xKey:t.includes(`ET`)?`ET`:t.includes(`ElapsedTime`)?qe:t[0],r={...e.panelChartSettings};for(let n of e.panels){let e=r[n.id];if(n.kind===`multiband`){let i=e&&e.kind===`multiband`?e:pn();r[n.id]={...i,kind:`multiband`,addColumn:i.addColumn&&t.includes(i.addColumn)?i.addColumn:t[0]}}else if(n.kind===`xyscatter`){let i=e&&e.kind===`xyscatter`?e:mn(Y$[2]),a=i.xyXCol||t[0],o=i.xyYCol||(t.length>1&&t[1]!==a?t[1]:t[0]);r[n.id]={...i,kind:`xyscatter`,xyXCol:a,xyYCol:o}}else if(n.kind===`xyzmesh`){let i=e&&e.kind===`xyzmesh`?e:hn(4),a=i.xyzXCol||t[0],o=i.xyzYCol||(t.length>1?t[1]:t[0]),s=i.xyzZCol||(t.length>2?t[2]:t[0]);r[n.id]={...i,kind:`xyzmesh`,xyzXCol:a,xyzYCol:o,xyzZCol:s}}}return{...e,xKey:n,panelChartSettings:r}}function n1(e,t){let n=!1,r={...e.panelChartSettings};for(let[i,a]of Object.entries(e.panelChartSettings)){if(a.kind!==`multiband`)continue;let e=a.series.filter(e=>t(e.column));e.length!==a.series.length&&(r[i]={...a,series:e},n=!0)}return n?{...e,panelChartSettings:r}:e}function r1(){return typeof document>`u`?`dark`:$z(null)}function i1(e={}){let t={...e},n=!1,r=X$(),i=jQ({datasets:[],selection:[],worksheets:[r],activeWorksheetId:r.id,xRanges:{},offsets:{},colors:{},liveWindowSeconds:15,segmentContext:null,cycleRules:[],live:[],video:[],mathChannels:[],limits:{...K$,...t.limits},palette:Xz(t.palette,r1()),importing:0,licensed:null,history:{canUndo:!1,canRedo:!1},marks:[],alerts:[],alertRules:[]}),a=RV(),o=()=>{let e=Xz(t.palette,r1());i.set(t=>t.palette.join()===e.join()?t:{...t,palette:e})},s=typeof document>`u`?()=>{}:eB(null,o),c=NQ(),l=()=>{if(n)throw new kE(`disposed`)},u=e=>{throw a.emit(`limit`,{reason:e}),new kE(`limit_reached`,{reason:e})},d=()=>i.get(),f=(e,t)=>{let n=d().limits.maxChannelsPerChart,r=Cz(t);n!==null&&r>n&&r>Cz(e)&&u(`channels-per-chart`)},p=MQ((e,t)=>t===null?e:e.slice(0,t)),m=()=>{let e=d(),t=c.lapsByDataset(e.datasets),n=c.selectedDatasets(e.datasets,t,e.selection),r=c.selectedLive(e.live,e.selection),i=c.staticDataset(n),a=c.mergedDataset(i,r),o=p(e.mathChannels,e.limits.maxMathChannels);return{laps:t,selectedDatasets:n,selectedLive:r,staticDataset:i,merged:a,channels:o,numericColumns:c.numericColumns(a,n,o,c.mergedParts(n,r),r),allColumns:c.allColumns(a,n,o),columnUnits:c.columnUnits(a,o)}},h=(e,t)=>({id:t.id,kind:t.kind,title:t.title??null,settings:e.panelChartSettings[t.id],background:e.panelChartBackgrounds[t.id]??null,annotations:e.panelChartSettings[t.id]?.annotations??q$,layout:t.rect}),g=MQ((e,t,n)=>e.map(e=>({id:e.id,name:e.name,xKey:e.xKey,xRange:t[e.id]??null,liveWindowSeconds:e.liveWindowSeconds===void 0?n:e.liveWindowSeconds,charts:e.panels.map(t=>h(e,t))}))),_=MQ((e,t,n,r,i,a,o)=>{let s=(e,t)=>{let n=a.findIndex(t=>t.id===e);return n>=0?n:t};return e.map((e,a)=>{let c=i[e.id],l=c?.laps.map(e=>e.id)??[],u=l.filter(e=>t.includes(e)).length;return{id:e.id,name:e.name,kind:e.kind,columns:e.schema.map(e=>({name:e.name,unit:e.unit??``,numeric:e.type===`number`})),rowCount:e.data.rows.length,color:Jz(n,e.id,s(e.id,a),o),customColor:e.id in n,offset:r[e.id]??0,parseConfig:e.parseConfig??null,fileInfo:e.info??null,beacon:e.beacon??null,cut:e.cut?{cycleId:e.cut.cycleId,timeKey:e.cut.timeKey,defs:e.cut.defs}:null,laps:c?c.laps.map((i,a)=>({id:i.id,name:i.name,value:c.values[a],unit:c.unit,isTime:c.isTime,color:Jz(n,i.id,s(i.id,a),o),offset:r[i.id]??0,selected:t.includes(i.id),...e.cut?{cycle:J$(e.cut,a)}:{}})):null,selected:c?u===0?!1:u===l.length?!0:`partial`:t.includes(e.id)}})}),v=MQ((e,t,n,r,i)=>{let a=e.filter(e=>t.includes(e.id)).map(e=>e.id);return e.map((e,o)=>({id:e.id,name:e.name,ownerName:e.ownerName,visibility:e.visibility,orgName:e.orgName,kind:e.kind,parentId:e.parentId,lowOf:e.lowOf,status:e.status,error:e.error,rowCount:e.rowCount,selected:t.includes(e.id),color:Jz(n,e.id,a.includes(e.id)?r+a.indexOf(e.id):o,i),customColor:e.id in n,recordingSince:e.recordingSince,channels:e.dataset.columnNames}))}),y=MQ(e=>{let t=m();return{datasets:_(e.datasets,e.selection,e.colors,e.offsets,t.laps,t.selectedDatasets,e.palette),selection:e.selection,worksheets:g(e.worksheets,e.xRanges,e.liveWindowSeconds),activeWorksheetId:e.activeWorksheetId,mathChannels:t.channels,live:v(e.live,e.selection,e.colors,t.selectedDatasets.length,e.palette),liveWindowSeconds:(()=>{let t=e.worksheets.find(t=>t.id===e.activeWorksheetId);return t?.liveWindowSeconds===void 0?e.liveWindowSeconds:t.liveWindowSeconds})(),segmentContext:e.segmentContext,cycleRules:e.cycleRules,limits:e.limits,palette:e.palette,importing:e.importing,licensed:e.licensed,hasData:t.merged!==null,multiDataset:t.selectedDatasets.length+t.selectedLive.length>1,numericColumns:t.numericColumns,allColumns:t.allColumns,columnUnits:t.columnUnits,history:e.history,marks:e.marks,alerts:e.alerts}}),b=(e,t)=>e===t||e.length===t.length&&e.every((e,n)=>e===t[n]||JSON.stringify(e)===JSON.stringify(t[n])),x=new G$({limit:100,mergeMs:500,now:()=>Date.now(),equals:(e,t)=>e.liveWindowSeconds===t.liveWindowSeconds&&b(e.worksheets,t.worksheets)&&b(e.channels,t.channels)}),S=!0,C=0,w=e=>{C++;try{e()}finally{C--}},T=e=>[e.worksheets,e.mathChannels,e.liveWindowSeconds],E=[],D=()=>{let e=d();return{worksheets:e.worksheets,channels:e.mathChannels.filter(e=>e.source===`workbook`),liveWindowSeconds:e.liveWindowSeconds,activeWorksheetId:e.activeWorksheetId}},O=()=>i.set(e=>e.history.canUndo===x.canUndo&&e.history.canRedo===x.canRedo?e:{...e,history:{canUndo:x.canUndo,canRedo:x.canRedo}}),k=()=>{if(S)return;let e=T(d());e.every((e,t)=>e===E[t])||(E=e,C?x.rebase(D()):x.observe(D()),O())},A=()=>{E=T(d()),x.clear(D()),O()},j=e=>{S=!0;let t;try{t=e()}finally{S=!1}return A(),t},M=()=>y(d());i.subscribe(()=>{k(),a.emit(`change`,M())});let N=e=>{let t=d(),n=t.worksheets.find(n=>n.id===(e??t.activeWorksheetId));if(!n)throw new kE(`not_found`,{worksheetId:e});return n},P=e=>{for(let t of d().worksheets){let n=t.panels.find(t=>t.id===e);if(n)return{ws:t,panel:n}}throw new kE(`not_found`,{chartId:e})},F=(e,t)=>i.set(n=>{let r=!1,i=n.worksheets.map(n=>{if(n.id!==e)return n;let i=t(n);return i!==n&&(r=!0),i});return r?{...n,worksheets:i}:n}),I=(e,t)=>{let{ws:n}=P(e);F(n.id,n=>({...n,panelChartSettings:{...n.panelChartSettings,[e]:t(n.panelChartSettings[e])}}))},L=e=>i.set(t=>e.length===t.selection.length&&e.every((e,n)=>e===t.selection[n])?t:{...t,selection:e,xRanges:{}}),R=new Set,z=V$(t.live?.relay,e=>{let t=e.map(e=>e.id),n=e.filter(e=>e.kind===`data`&&!R.has(e.id)).map(e=>e.id),r=[...R].filter(e=>!t.includes(e));if(R=new Set(t),i.set(t=>({...t,live:e})),r.length&&L(d().selection.filter(e=>!r.includes(e))),n.length){let e=d().selection,t=n.filter(t=>!e.includes(t));t.length&&L([...e,...t])}let a=m();if(a.selectedLive.length&&a.merged){let e=a.merged.columnNames;if(e.includes(`ElapsedTime`))for(let t of d().worksheets)e.includes(t.xKey)||w(()=>F(t.id,e=>({...e,xKey:qe})))}},()=>({capacity:t.live?.capacity,maxMemoryMB:t.live?.maxMemoryMB}),{rows:(e,t,n)=>{if(!ce.rules().length)return;t.columnNames.length!==V.get(e)&&(V.set(e,t.columnNames.length),ce.sync());let r=ce.liveColumns(e);if(!r.length)return;let i=t.endAbs,a=Math.max(n,t.firstAbs);if(i<=a)return;let o={};for(let e of r)o[e]=t.range(e,a,i);ce.pushLive(e,{t:t.range(qe,a,i),columns:o,scan:new Map})},tick:(e,t,n)=>{if(!ce.rules().length)return;let r=t.range(qe,t.endAbs-1,t.endAbs)[0];r===r&&ce.tickLive(e,r+(Date.now()-n)/1e3)}}),V=new Map,te=MQ((e,t)=>e.filter(e=>t.some(t=>SE([e],t.panelChartSettings,t.xKey).length>0))),ne=()=>z.setMathChannels(te(p(d().mathChannels,d().limits.maxMathChannels),d().worksheets));ne(),i.subscribe(ne);let re=e=>{i.set(t=>({...t,datasets:[...t.datasets,e]})),L([...d().selection,e.id]);let t=xz(e.schema);t.length&&w(()=>i.set(e=>({...e,worksheets:e.worksheets.map(e=>t1(e,t))})))},ie=Promise.resolve(),U=async(e,r={})=>{l();let o=e.map(e=>e instanceof File?e:e.file);if(o.length===0)return{ids:[],errors:[]};if(await t.beforeImport?.()===!1)throw new kE(`import_vetoed`);let{signal:s}=r;i.set(e=>({...e,importing:e.importing+o.length}));let c=ie.then(async()=>{let e={ids:[],errors:[]},t=o.length,c=e=>{t-=e,i.set(t=>({...t,importing:Math.max(0,t.importing-e)}))};try{let{items:t,errors:i}=await DR(o);c(o.length-t.length);for(let{file:t,error:n}of i)e.errors.push({file:t,error:n}),a.emit(`import`,{file:t,phase:`error`,error:n}),a.emit(`error`,{error:n,context:`import`});for(let i of t){if(n)break;if(s?.aborted){e.cancelled=!0;break}let t=i.main;await new Promise(e=>setTimeout(e,0)),a.emit(`import`,{file:t.name,phase:`start`});try{let o=i.format?await bz({main:t,companions:i.companions,format:i.format.id},{priorInMemoryValues:yR(d().datasets),signal:s,onProgress:e=>a.emit(`import`,{file:t.name,phase:`progress`,fraction:e}),chooseChannels:r.chooseChannels,pickChannels:r.pickChannels}):[await vR(crypto.randomUUID(),t,d().datasets)??await gR(crypto.randomUUID(),t,$$,void 0,yR(d().datasets),s)];if(n){for(let e of o)e.source.dispose();break}if(s?.aborted){for(let e of o)e.source.dispose();throw new kE(`cancelled`)}for(let t of o)re(t),e.ids.push(t.id);a.emit(`import`,{file:t.name,phase:`done`,datasetId:o[0].id,datasetIds:o.map(e=>e.id)})}catch(n){let r=n instanceof Error?n:Error(String(n));a.emit(`import`,{file:t.name,phase:`error`,error:r}),r instanceof kE&&r.code===`cancelled`?e.cancelled=!0:(e.errors.push({file:t.name,error:r}),a.emit(`error`,{error:r,context:`import`}))}finally{c(1)}if(e.cancelled)break}}finally{t>0&&c(t)}return e});return ie=c.catch(()=>void 0),c},ae=()=>setTimeout(()=>{n||WZ(nt)},0),oe=e=>{let t=t=>e.some(e=>t===e||t.startsWith(`${e}::`)),n=d().datasets.filter(t=>e.includes(t.id));for(let e of n)e.source.dispose().catch(()=>void 0);i.set(n=>{let r={...n.offsets},i={...n.colors};for(let e of Object.keys(r))t(e)&&delete r[e];for(let e of Object.keys(i))t(e)&&delete i[e];return{...n,datasets:n.datasets.filter(t=>!e.includes(t.id)),offsets:r,colors:i}}),L(d().selection.filter(e=>!t(e))),n.length>0&&ae()},se=async(e,t,n={})=>{let[r,...i]=await bz({main:new File(e.chunks,`${e.name}.krc`),companions:[],format:`krc`,keys:e.keys},{priorInMemoryValues:t,...n});for(let e of i)e.source.dispose();return{...r,file:void 0,name:e.name,info:r.info&&{...r.info,startTime:e.startTime??r.info.startTime,meta:{...r.info.meta,recordingId:e.recordingId}}}},ce=W$({targets:()=>[...d().datasets.map(e=>({kind:`dataset`,id:e.id,name:e.name,channels:e.schema.map(e=>e.name)})),...d().live.filter(e=>e.kind===`data`).map(e=>({kind:`stream`,id:e.id,name:e.name,channels:e.source.columnNames}))],maxRules:()=>d().limits.maxAlertRules,emit:e=>a.emit(`alert`,e),limit:()=>a.emit(`limit`,{reason:`alert-rules`}),setMarks:e=>i.set(t=>({...t,marks:e})),setStates:e=>i.set(t=>({...t,alerts:e})),readDataset:(e,t,n,r)=>{let i=d().datasets.find(t=>t.id===e);return i?i.source.readColumns(t,n,r):Promise.resolve({})}}),le=MQ((e,t)=>{let n=new Map;for(let r of e){let e=rt(r);e!==null&&n.set(r.id,{value:e,active:t.some(e=>e.ruleId===r.id&&(e.state===`active`||e.state===`clearing`))})}return n}),ue=null;i.subscribe(()=>{let e=d();ue&&ue[0]===e.datasets&&ue[1]===e.live||(ue=[e.datasets,e.live],ce.rules().length&&ce.sync())});let de={importFiles:U,warmImport(e={}){l(),cz(!!e.formats?.some(e=>e===`hdf5`||e===`mat`))},async splitByRate(e){l();let t=d().datasets.find(t=>t.id===e);if(!t)throw new kE(`not_found`,{datasetId:e});if(!t.info?.combined||!(t.file instanceof File))throw new kE(`invalid_argument`,{reason:`only a combined multi-rate import can be split`});let n=await bz({main:t.file,companions:t.companions??[],format:t.info.importer},{priorInMemoryValues:yR(d().datasets.filter(t=>t.id!==e)),selection:t.info.selection,split:!0});oe([e]);for(let e of n)re(e);return n.map(e=>e.id)},async chooseChannels(e,t){l();let n=d().datasets.find(t=>t.id===e);if(!n)throw new kE(`not_found`,{datasetId:e});if(!n.info||!(n.file instanceof File))throw new kE(`invalid_argument`,{reason:`only binary imports have channels to choose`});try{let r=await bz({main:n.file,companions:n.companions??[],format:n.info.importer},{priorInMemoryValues:yR(d().datasets.filter(t=>t.id!==e)),initial:n.info.selection,chooseChannels:t,pickChannels:!0});oe([e]);for(let e of r)re(e);return r.map(e=>e.id)}catch(e){if(e instanceof kE&&e.code===`cancelled`)return null;throw e}},async combine(e){l();let t=d().datasets.find(t=>t.id===e);if(!t)throw new kE(`not_found`,{datasetId:e});let n=t.info?.splitKey;if(!n||!(t.file instanceof File))throw new kE(`invalid_argument`,{reason:`only datasets split from one file can be combined`});let r=d().datasets.filter(e=>e.info?.splitKey===n),i=await bz({main:t.file,companions:t.companions??[],format:t.info.importer},{priorInMemoryValues:yR(d().datasets.filter(e=>!r.includes(e))),selection:r.flatMap(e=>e.info.selection)});if(i.length!==1){for(let e of i)e.source.dispose();throw new kE(`invalid_argument`,{reason:`these groups have no common time base`})}return oe(r.map(e=>e.id)),re(i[0]),i[0].id},async openRecording(e,t={}){l();let n=await se(e,yR(d().datasets),t);return re(n),n.id},async reopenRecording(e,t){l();let n=d().datasets.find(t=>t.id===e);if(!n)throw new kE(`not_found`,{datasetId:e});let r=await se(t,yR(d().datasets.filter(t=>t.id!==e)));i.set(t=>({...t,datasets:t.datasets.map(t=>t.id===e?{...r,id:e,beacon:n.beacon}:t)})),n.source.dispose().catch(()=>void 0),ae()},openHistoryRange(e){l();let t=AQ(crypto.randomUUID(),e);return re(t),t.id},updateHistoryRange(e,t){l();let n=d().datasets.find(t=>t.id===e);if(!n)throw new kE(`not_found`,{datasetId:e});if(!(n.source instanceof yQ)){let t=`dataset ${e} is not a history range: only datasets opened with openHistoryRange can be updated`;throw Object.assign(new kE(`invalid_argument`,{datasetId:e,reason:t}),{message:t})}let r=AQ(e,t);i.set(t=>({...t,datasets:t.datasets.map(t=>t.id===e?{...r,beacon:n.beacon}:t)})),ae()},addColumns(e){l();let t=CQ(crypto.randomUUID(),e);return re(t),t.id},replaceColumns(e,t,n={}){l();let r=d().datasets.find(t=>t.id===e);if(!r)throw new kE(`not_found`,{datasetId:e});let a=DQ(r,t,n.transfer);i.set(t=>({...t,datasets:t.datasets.map(t=>t.id===e?a:t)}))},writeColumns(e,t,n){l();let r=d().datasets.find(t=>t.id===e);if(!r)throw new kE(`not_found`,{datasetId:e});let a=TQ(r,t,n);i.set(t=>({...t,datasets:t.datasets.map(t=>t.id===e?a:t)}))},async addText(e,t=`dataset.csv`){l();let n=await pR(crypto.randomUUID(),t,e);return re(n),n.id},async findCycles(e,t,n){l();let r=d().datasets.find(t=>t.id===e);if(!r)throw new kE(`not_found`,{datasetId:e});let i=await BB(r.source,n,HB(t)),a=new Map(t.filter(e=>e.kpis?.length).map(e=>[e.id,e.kpis]));return VB(i,t).map(e=>a.has(e.definitionId)?{...e,kpis:WB(i,e,a.get(e.definitionId))}:e)},async addCycles(e,t){l();let n=d().datasets.find(t=>t.id===e);if(!n)throw new kE(`not_found`,{datasetId:e});let r=n.schema.filter(e=>e.type===`number`&&e.name!==t.timeKey).map(e=>e.name),i=await BB(n.source,t.timeKey,r),a={...Object.fromEntries(n.schema.map(e=>[e.name,e.unit])),[RB]:`s`},o=e=>t.defs.find(t=>t.id===e)?.name??e,s=[];for(let e of t.pick){let r=t.found.find(t=>t.definitionId===e.definitionId&&t.index===e.index&&t.parentIndex===e.parentIndex);if(!r)throw new kE(`not_found`,{reason:`no ${o(e.definitionId)} ${e.index} in the cycles found`});let c=r.parentIndex?`${o(t.cycleId)} ${r.parentIndex} · ${o(r.definitionId)}`:`${o(r.definitionId)} ${r.index}`;s.push(de.addColumns({name:`${n.name} · ${c}`,columns:KB(i,t.timeKey,r),units:a}))}if(t.tables!==!1){let e=JB(t.found,t.cycleId,t.defs,i);s.push(await de.addText(YB(e.cycles),`${n.name} · ${o(t.cycleId)}s.csv`)),e.phases.length&&s.push(await de.addText(YB(e.phases),`${n.name} · Phases.csv`))}return s},async cut(e,t){l();let n=d().datasets.find(t=>t.id===e);if(!n)throw new kE(`not_found`,{datasetId:e});let r;if(t){if(!t.defs.some(e=>e.id===t.cycleId))throw new kE(`invalid_argument`,{reason:`cycleId is not one of defs`});let i=n.schema.filter(e=>e.type===`number`&&e.name!==t.timeKey).map(e=>e.name),a=await BB(n.source,t.timeKey,i),o=t.defs.find(e=>e.id===t.cycleId)?.show,s=e=>[...e.kpis??[],...o&&o.channel!==t.timeKey?[o]:[]],c=new Map(t.defs.filter(e=>s(e).length).map(e=>[e.id,s(e)])),l=VB(a,t.defs).sort((e,t)=>e.tstart-t.tstart||!!e.parentIndex-+!!t.parentIndex).map(e=>c.has(e.definitionId)?{...e,kpis:WB(a,e,c.get(e.definitionId))}:e),u={...Object.fromEntries(n.schema.map(e=>[e.name,e.unit])),[RB]:`s`},d=e=>t.defs.find(t=>t.id===e)?.name??e,f=l.map(r=>CQ(`${e}::${r.definitionId}:${r.parentIndex??0}:${r.index}`,{name:r.parentIndex?`${n.name} · ${d(t.cycleId)} ${r.parentIndex} · ${d(r.definitionId)}`:`${n.name} · ${d(r.definitionId)} ${r.index}`,columns:KB(a,t.timeKey,r),units:u})),p=a.t.length?a.t[a.t.length-1]:NaN,m=l.map(e=>e.tend===null&&p===p?{...e,tend:p,incomplete:!0}:e);r={defs:t.defs,cycleId:t.cycleId,timeKey:t.timeKey,found:m,parts:f}}else if(!n.cut)return 0;if(!d().datasets.some(t=>t.id===e))return 0;i.set(t=>({...t,datasets:t.datasets.map(t=>t.id===e?{...t,cut:r}:t)}));let a=d().selection,o=a.some(t=>t===e||t.startsWith(`${e}::`)),s=a.filter(t=>t!==e&&!t.startsWith(`${e}::`)),c=r?r.parts.filter((e,t)=>!r.found[t].parentIndex).map(e=>e.id):[];return L(o?c.length>0?[...s,...c]:[...s,e]:s),c.length},remove(e){l(),oe([e])},clear(){l(),oe(d().datasets.map(e=>e.id))},async configure(e,t){l();let n=d().datasets.find(t=>t.id===e);if(!n)throw new kE(`not_found`,{datasetId:e});if(t.parseConfig&&(n.kind!==`memory`||!n.parseConfig))throw new kE(`invalid_argument`,{reason:n.parseConfig?`out-of-core datasets cannot be re-parsed`:`binary files have no text parse settings`});if(t.beacon!==void 0&&t.beacon!==null&&n.kind!==`memory`)throw new kE(`invalid_argument`,{reason:`laps need an in-memory dataset`});if(t.beacon!==void 0&&JSON.stringify(t.beacon)!==JSON.stringify(n.beacon??null)){let r=t.beacon??void 0;i.set(t=>({...t,datasets:t.datasets.map(t=>t.id===e?{...t,beacon:r}:t)}));let a=d().selection,o=a.some(t=>t===e||t.startsWith(`${e}::`)),s=a.filter(t=>t!==e&&!t.startsWith(`${e}::`)),c=r?vB(n.data.rows,r.channel):[],l=r&&t.selectCycles===`best`?CB(c.map(e=>SB(n.data.rows,e,r.metric,r.stat))):null,u=l===null?c.map((t,n)=>EB(e,n)):[EB(e,l)];L(o?c.length>0?[...s,...u]:[...s,e]:s)}let r=t.parseConfig;if(!r)return;let a=(()=>{try{let e=H(ze(n.rawText??``),r.headerRow);return n.data.columnNames.length===e.length&&n.data.columnNames.every((t,n)=>t===e[n])}catch{return!1}})();if(ee(r,n.parseConfig)&&a)return;let o=n.fromColumns?kQ(n):n.rawText??``,s=await PE(n.file?{file:n.file,config:r}:{rawText:o,config:r}),c=new LE(s),u=await c.getSchema(),f=n.fromColumns?{rawText:o,fromColumns:!1}:{};i.set(t=>({...t,datasets:t.datasets.map(t=>t.id===e?{...t,...f,data:s,source:c,schema:u,parseConfig:r}:t)})),n.source.dispose().catch(()=>void 0),ae(),n.cut&&await de.cut(e,n.cut);let p=m().selectedDatasets,h=new Set(p.flatMap(e=>e.data.columnNames)),g=s.columnNames.filter(e=>B(s.rows,e)),_=g.find(e=>e===`ET`)??g[0];w(()=>i.set(e=>({...e,worksheets:e.worksheets.map(e=>n1(!h.has(e.xKey)&&_?{...e,xKey:_}:e,e=>h.has(e)))})))},setColor(e,t){l(),i.set(n=>{let r={...n.colors};return t===null?delete r[e]:r[e]=t,{...n,colors:r}})},setOffset(e,t){l(),i.set(n=>({...n,offsets:{...n.offsets,[e]:t}}))},resetOffsets(){l(),i.set(e=>Object.keys(e.offsets).length?{...e,offsets:{}}:e)},select(e){l(),L([...e])},toggle(e){l();let t=d().selection,n=m().laps[e];if(n){let e=n.laps.map(e=>e.id);L(e.every(e=>t.includes(e))?t.filter(t=>!e.includes(t)):[...t,...e.filter(e=>!t.includes(e))]);return}L(t.includes(e)?t.filter(t=>t!==e):[...t,e])},selectAll(){l();let e=m().laps,t=d().live.filter(e=>d().selection.includes(e.id)).map(e=>e.id);L([...d().datasets.flatMap(t=>e[t.id]?e[t.id].laps.map(e=>e.id):[t.id]),...t])},deselectAll(){l(),L([])},raw(e){let t=d().datasets.find(t=>t.id===e);if(!t)throw new kE(`not_found`,{datasetId:e});return{get rawText(){return t.kind===`memory`&&t.fromColumns?kQ(t):t.rawText??``},data:t.data,parseConfig:t.parseConfig??null,kind:t.kind,beacon:t.beacon??null}},async columnBounds(e){l();let t=m(),n=t.selectedDatasets.find(t=>t.schema.some(t=>t.name===e));if(n&&n.kind===`memory`){let t=Sz(n.data.rows,e);if(Number.isFinite(t.min)&&Number.isFinite(t.max))return t}else if(n){let t=await n.source.xBounds(e).catch(()=>null);if(t&&Number.isFinite(t.x0)&&Number.isFinite(t.x1)&&t.x1>=t.x0)return{min:t.x0,max:t.x1}}let r=t.selectedLive.find(t=>t.dataset.columnNames.includes(e));if(r){let t=r.source.valueBoundsSync(e);if(t)return t}let i=fe(e);if(!i)return null;let a=Sz(i.rows,e);return Number.isFinite(a.min)&&Number.isFinite(a.max)?a:null}},fe=(e,t=N().xKey)=>{let n=m();if(!n.merged)return null;if(!n.channels.find(t=>t.name===e))return n.merged;let r=xE(n.merged,n.channels,t);return{...n.merged,columnNames:[...n.merged.columnNames,...r.ok.map(e=>e.name)],rows:r.rows}},pe=(e,t,n)=>m().selectedLive.length>0?{...n,scaleMin:``,scaleMax:``,majorStep:``,minorStep:``}:e1(fe(e,t),e,n),me={fromFileList:e=>EV(Array.from(e)),async fromDataTransfer(e){return DV(Array.from(e.items??[]).map(e=>e.webkitGetAsEntry?.()).filter(e=>!!e))},canPick:OV,pick:kV,tree:(e,t)=>TV(e,t),isImportable:wV},he={add(e=`Worksheet`){l();let t=d(),n=t.limits.maxWorksheets;n!==null&&t.worksheets.length>=n&&u(`worksheets`);let r={...X$(N().xKey||`ET`),name:e};return i.set(e=>({...e,worksheets:[...e.worksheets,r],activeWorksheetId:r.id})),r.id},rename(e,t){l(),N(e),F(e,e=>e.name===t?e:{...e,name:t})},remove(e){l();let t=d();if(N(e),t.worksheets.length<=1)throw new kE(`invalid_argument`,{reason:`the last worksheet cannot be removed`});let n=t.worksheets.findIndex(t=>t.id===e),r=t.worksheets.filter(t=>t.id!==e);i.set(t=>({...t,worksheets:r,activeWorksheetId:t.activeWorksheetId===e?r[Math.max(0,n-1)].id:t.activeWorksheetId}))},reorder(e,t){l(),i.set(n=>{if(e===t||e<0||t<0||e>=n.worksheets.length||t>=n.worksheets.length)return n;let r=[...n.worksheets],[i]=r.splice(e,1);return r.splice(t,0,i),{...n,worksheets:r}})},activate(e){l(),N(e),i.set(t=>t.activeWorksheetId===e?t:{...t,activeWorksheetId:e,xRanges:{...t.xRanges,[e]:null}})},setXKey(e,t){l(),N(e),F(e,e=>n1({...e,xKey:t},e=>e!==t)),i.set(t=>({...t,xRanges:{...t.xRanges,[e]:null},offsets:{}}))}},ge={mount(e,t,n){return l(),UZ(nt,e,t,n)},openWindow(e,t){return l(),P(e),pQ(nt,e,(t,n)=>UZ(nt,e,t,n),t)},setFonts(e){e.sans&&(Q.sans=e.sans),e.mono&&(Q.mono=e.mono),WZ(nt)},kinds:()=>PQ,label:IQ,add(e,t={}){if(l(),!PQ.some(t=>t.kind===e))throw new kE(`invalid_argument`,{kind:e});let n=N(t.worksheetId),r=d().limits.maxChartsPerWorksheet;r!==null&&n.panels.length>=r&&u(`charts-per-worksheet`);let i={...Xt(e,n.panels),...t.title?{title:t.title}:{}};t.layout&&(i.rect={...t.layout});let a=ir([i],{},Y$[2],4)[i.id],o=a,s=m().numericColumns;if(s.length&&(o.kind===`multiband`||o.kind===`xyscatter`||o.kind===`xyzmesh`)&&(o=t1({...n,panels:[i],panelChartSettings:{[i.id]:o}},s).panelChartSettings[i.id],o.kind===`multiband`&&(o={...o,addColumn:s.find(e=>e!==n.xKey)??s[0]})),t.settings&&(o={...o,...t.settings,kind:o.kind}),s.length&&o.kind===`xyscatter`){let e=t.settings??{};o={...o,xyXScale:e.xyXScale??pe(o.xyXCol,n.xKey,o.xyXScale),xyYScale:e.xyYScale??pe(o.xyYCol,n.xKey,o.xyYScale)}}return f(a,o),F(n.id,e=>({...e,panels:t.layout?[...e.panels,i]:Qt([...e.panels,i]),panelChartSettings:{...e.panelChartSettings,[i.id]:o}})),i.id},remove(e){l();let{ws:t}=P(e);F(t.id,t=>{let n={...t.panelChartSettings},r={...t.panelChartBackgrounds};return delete n[e],delete r[e],{...t,panels:Qt(t.panels.filter(t=>t.id!==e)),panelChartSettings:n,panelChartBackgrounds:r}})},rename(e,t){l();let{ws:n}=P(e),r=t?.trim()||void 0;F(n.id,t=>({...t,panels:t.panels.map(t=>{if(t.id!==e)return t;let{title:n,...i}=t;return r?{...i,title:r}:i})}))},update(e,t){l();let{ws:n}=P(e),r=n.panelChartSettings[e],i={...r,...t,kind:r.kind};if(r.kind===`xyscatter`&&i.kind===`xyscatter`){let e=t;typeof e.xyXCol==`string`&&e.xyXCol!==r.xyXCol&&!(`xyXScale`in e)&&(i={...i,xyXScale:pe(e.xyXCol,n.xKey,r.xyXScale)}),typeof e.xyYCol==`string`&&e.xyYCol!==r.xyYCol&&!(`xyYScale`in e)&&(i={...i,xyYScale:pe(e.xyYCol,n.xKey,r.xyYScale)})}f(r,i),I(e,()=>i)},replaceSettings(e,t){l();let{ws:n,panel:r}=P(e);if(t.kind!==r.kind)throw new kE(`invalid_argument`,{reason:`settings kind mismatch`});f(n.panelChartSettings[e],t),I(e,()=>t)},setBackground(e,t){l();let{ws:n}=P(e);F(n.id,n=>({...n,panelChartBackgrounds:{...n.panelChartBackgrounds,[e]:t}}))},addAnnotation(e,t){l(),P(e);let n=Nt({...t,id:t.id||crypto.randomUUID()});if(!n)throw new kE(`invalid_argument`,{reason:`not a valid annotation`});return I(e,e=>({...e,annotations:[...(e.annotations??[]).filter(e=>e.id!==n.id),n]})),n.id},updateAnnotation(e,t,n){l();let r=(P(e).ws.panelChartSettings[e]?.annotations??[]).find(e=>e.id===t);if(!r)throw new kE(`not_found`,{annotationId:t});let i=Nt({...r,...n,id:r.id,kind:r.kind});if(!i)throw new kE(`invalid_argument`,{reason:`not a valid annotation`});I(e,e=>({...e,annotations:(e.annotations??[]).map(e=>e.id===i.id?i:e)}))},removeAnnotation(e,t){l(),P(e),I(e,e=>({...e,annotations:(e.annotations??[]).filter(e=>e.id!==t)}))},setAnnotations(e,t){l(),P(e);let n=Pt(t)??[];I(e,e=>({...e,annotations:n}))},setLayout(e,t){l();let{ws:n}=P(e);F(n.id,n=>({...n,panels:n.panels.map(n=>n.id===e?{...n,rect:{...t}}:n)}))},setLayouts(e,t){l(),F(e,e=>({...e,panels:e.panels.map(e=>t[e.id]?{...e,rect:{...t[e.id]}}:e)}))},autoLayout(e){l(),F(N(e).id,e=>({...e,panels:Qt(e.panels)}))},get(e){let{ws:t,panel:n}=P(e);return h(t,n)},list(e){let t=N(e);return t.panels.map(e=>h(t,e))},async addSeries(e,t){l();let{ws:n}=P(e),r=n.panelChartSettings[e];if(!r||r.kind!==`multiband`)throw new kE(`invalid_argument`,{reason:`not a multiband chart`});let i=d().limits.maxChannelsPerChart;i!==null&&Cz(r)>=i&&u(`channels-per-chart`);let a=m().numericColumns,o=new Set(r.series.map(e=>e.column)),s=t??a.find(e=>e!==n.xKey&&!o.has(e))??a.find(e=>e!==n.xKey)??``;if(!s)return null;let c=sr(),f={id:c,column:s,color:Y$[r.series.length%Y$.length],bandFromPct:0,bandToPct:100,scaleMin:0,scaleMax:1,yMajorStep:0,yMinorStep:0};return I(e,e=>e.kind===`multiband`?{...e,series:[...e.series,f]}:e),await ge.autoScaleSeries(e,c),c},async updateSeries(e,t,n){l();let{ws:r}=P(e),i=r.panelChartSettings[e],a=i&&i.kind===`multiband`?i.series.find(e=>e.id===t):void 0;if(!a)throw new kE(`not_found`,{seriesId:t});I(e,e=>e.kind===`multiband`?{...e,series:e.series.map(e=>e.id===t?{...e,...n,id:e.id}:e)}:e),n.column&&n.column!==a.column&&n.scaleMin===void 0&&n.scaleMax===void 0&&await ge.autoScaleSeries(e,t)},removeSeries(e,t){l(),I(e,e=>e.kind===`multiband`?{...e,series:e.series.filter(e=>e.id!==t)}:e)},reorderSeries(e,t){l(),I(e,e=>{if(e.kind!==`multiband`)return e;let n=new Map(e.series.map(e=>[e.id,e])),r=t.map(e=>n.get(e)).filter(e=>!!e),i=e.series.filter(e=>!t.includes(e.id));return{...e,series:[...r,...i]}})},async autoScaleSeries(e,t){l();let{ws:r}=P(e),i=r.panelChartSettings[e],a=i&&i.kind===`multiband`?i.series.find(e=>e.id===t):void 0;if(!a)return;let o=await de.columnBounds(a.column);!o||n||I(e,e=>e.kind===`multiband`?{...e,series:e.series.map(e=>e.id===t?{...e,scaleMin:o.min,scaleMax:o.max}:e)}:e)}},_e=new Map,ve={setXRange(e,t){l();let n=N(t).id;i.set(t=>{let r=t.xRanges[n]??null;return r===e||r&&e&&r[0]===e[0]&&r[1]===e[1]?t:{...t,xRanges:{...t.xRanges,[n]:e}}})},resetZoom(e){ve.setXRange(null,e)},setCursorX(e,t){l();let n=N(t).id;(_e.get(n)??null)!==e&&(_e.set(n,e),a.emit(`cursorchange`,{worksheetId:n,x:e}))},cursorX(e){return _e.get(N(e).id)??null},setLiveWindow(e,t){l();let n=N(t);n.liveWindowSeconds!==e&&F(n.id,t=>({...t,liveWindowSeconds:e}))},setSegmentContext(e){l(),i.set(t=>JSON.stringify(t.segmentContext)===JSON.stringify(e)?t:{...t,segmentContext:e})}},ye={save(e){l();let t=e.id??crypto.randomUUID(),[n]=LB([{...e,id:t,parentId:e.parentId??null}].concat(d().cycleRules.filter(e=>e.id!==t))).filter(e=>e.id===t);if(!n)throw new kE(`invalid_argument`,{reason:`not a valid cycle rule (or its parent is missing)`});return i.set(e=>({...e,cycleRules:e.cycleRules.some(e=>e.id===t)?e.cycleRules.map(e=>e.id===t?n:e):[...e.cycleRules,n]})),t},remove(e){l();let t=new Set([e]);for(let e=!0;e;){e=!1;for(let n of d().cycleRules)n.parentId&&t.has(n.parentId)&&!t.has(n.id)&&(t.add(n.id),e=!0)}i.set(e=>({...e,cycleRules:e.cycleRules.filter(e=>!t.has(e.id))}))}},be={create(e){l();let n=d(),r=n.limits.maxMathChannels;r!==null&&n.mathChannels.length>=r&&u(`math-channels`);let o=cr(e);return i.set(e=>({...e,mathChannels:[...e.mathChannels,o]})),Promise.resolve(t.mathChannels?.create(o)).catch(e=>a.emit(`error`,{error:e,context:`mathChannels.create`})),o},update(e,n){l();let r=d().mathChannels.find(t=>t.id===e);if(!r)throw new kE(`not_found`,{channelId:e});i.set(t=>({...t,mathChannels:t.mathChannels.map(t=>t.id===e?{...t,...n,updatedAt:Date.now()}:t)})),r.source!==`workbook`&&Promise.resolve(t.mathChannels?.update(e,n)).catch(e=>a.emit(`error`,{error:e,context:`mathChannels.update`}))},remove(e){l();let n=d().mathChannels.find(t=>t.id===e);if(!n)throw new kE(`not_found`,{channelId:e});i.set(t=>({...t,mathChannels:t.mathChannels.filter(t=>t.id!==e)})),n.source!==`workbook`&&Promise.resolve(t.mathChannels?.remove(e)).catch(e=>a.emit(`error`,{error:e,context:`mathChannels.remove`}))},async importFile(e){l();let{channels:n,errors:r}=await TE(e),a=d(),o=a.limits.maxMathChannels===null?n.length:Math.max(0,a.limits.maxMathChannels-a.mathChannels.length);n.length>0&&o===0&&u(`math-channels`);let s=n.slice(0,o);return i.set(e=>({...e,mathChannels:[...e.mathChannels,...s]})),await t.mathChannels?.importMany(s),{channels:s,errors:r}},async importMany(e){l();let n=d(),r=n.limits.maxMathChannels===null?e.length:Math.max(0,n.limits.maxMathChannels-n.mathChannels.length);e.length>0&&r===0&&u(`math-channels`);let a=e.slice(0,r);return i.set(e=>({...e,mathChannels:[...e.mathChannels,...a]})),await t.mathChannels?.importMany(a),a},exportBlob:()=>CE(d().mathChannels),preview(e,t){let n=m();return n.merged?rE(e,n.merged,N(t).xKey,n.channels.filter(t=>t.id!==e.id)):null},sync(e){l(),i.set(t=>{let n=t.mathChannels.filter(e=>e.source===`workbook`),r=n.length?[...e,...n]:e;return t.mathChannels===r?t:{...t,mathChannels:r}})}},xe=MQ((e,t)=>[...e.flatMap(e=>e.kind===`camera`&&e.video?[DE({...e,video:e.video})]:[]),...t]),Se=``;i.subscribe(()=>{let e=xe(d().live,d().video),t=e.map(e=>`${e.kind}:${e.id}:${e.recordingId??``}:${e.name}`).join(`|`);t!==Se&&(Se=t,a.emit(`videochange`,{sources:e}))});let Ce=(e,t,n)=>e.id===t&&(n===void 0||(e.recordingId??null)===n),we={sources:()=>xe(d().live,d().video),register(e){l(),i.set(t=>({...t,video:[...t.video.filter(t=>!Ce(t,e.id,e.recordingId??null)),e]}))},unregister(e,t){l(),i.set(n=>n.video.some(n=>Ce(n,e,t))?{...n,video:n.video.filter(n=>!Ce(n,e,t))}:n)}},Te={openLocal(e,t){return l(),z.openLocal(e,t)},async connect(e,t,n){l(),await z.connect(e,t,n)},startRecording(e){l(),z.startRecording(e)},stopRecording(e){return l(),z.stopRecording(e)},setSegmentAxis(e,t){l(),z.setSegmentAxis(e,t)},rowCount(e){return z.connections().find(t=>t.id===e)?.source.size()??0},disconnect(e){l(),z.disconnect(e),L(d().selection.filter(t=>t!==e))}},Ee=()=>{d().limits.canImportExportWorkspaces||u(`workspaces-io`)},De=async e=>{if(e instanceof Blob)try{return JSON.parse(await e.text())}catch{throw new kE(`bad_file`)}if(typeof e==`string`)try{return JSON.parse(e)}catch{throw new kE(`bad_file`)}return e},Oe=async e=>e instanceof File?e:new File([JSON.stringify(await De(e))],`import.json`,{type:`application/json`}),ke=e=>e.replace(/[^\w.-]+/g,`_`),Ae=e=>new Blob([JSON.stringify(e,null,2)],{type:`application/json`}),je=e=>{let t=rr(e.panelChartSettings,Y$[2],4),n={};for(let r of e.panels)t[r.id]?.kind===r.kind&&(n[r.id]=t[r.id]);return{...e,panelChartSettings:ir(e.panels,n,Y$[2],4)}},Me=(e,t)=>e.map(e=>{let n=e=>{let n=t.has(e)?crypto.randomUUID():e;return t.add(n),n},r=new Map(e.panels.map(e=>[e.id,n(e.id)])),i=e=>Object.fromEntries(Object.entries(e).map(([e,t])=>[r.get(e)??e,t]));return{...e,id:n(e.id),panels:e.panels.map(e=>({...e,id:r.get(e.id)})),panelChartSettings:i(e.panelChartSettings),panelChartBackgrounds:i(e.panelChartBackgrounds??{})}}),Ne=()=>new Set(d().worksheets.flatMap(e=>[e.id,...e.panels.map(e=>e.id)])),Pe=(e,t=0)=>{let n=d().limits.maxWorksheets,r=Me((n===null?e:e.slice(0,Math.max(1,n))).map(je),new Set),a=r[Math.min(t,r.length-1)];i.set(e=>({...e,worksheets:r,activeWorksheetId:a.id,xRanges:{}}))},Fe=(e,t)=>{let n=N(t),r=d().limits.maxChartsPerWorksheet;r!==null&&n.panels.length>=r&&u(`charts-per-worksheet`);let i=d().limits.maxChannelsPerChart;i!==null&&Cz(e.settings)>i&&u(`channels-per-chart`);let a=crypto.randomUUID(),o={id:a,kind:e.kind,rect:{x:0,y:0,w:6,h:24},...e.title?{title:e.title}:{}};return F(n.id,t=>({...t,panels:Qt([...t.panels,o]),panelChartSettings:{...t.panelChartSettings,[a]:e.settings},panelChartBackgrounds:e.background===null?t.panelChartBackgrounds:{...t.panelChartBackgrounds,[a]:e.background}})),a},Ie=()=>{let e=d();return cV({worksheets:e.worksheets,activeWorksheetId:e.activeWorksheetId,channels:te(p(e.mathChannels,e.limits.maxMathChannels),e.worksheets),liveWindowSeconds:e.liveWindowSeconds,laps:e.datasets.find(e=>e.beacon)?.beacon??null,segments:e.segmentContext,cycles:e.cycleRules})},Le=e=>{if(e.worksheets.length===0)throw new kE(`bad_workspace`,{errors:e.errors});let{channels:t,rename:n}=Z$(d().mathChannels,e.mathChannels);Pe(n.size?e.worksheets.map(e=>Q$(e,n)):e.worksheets,e.activeIndex),i.set(n=>({...n,mathChannels:[...n.mathChannels.filter(e=>e.source!==`workbook`),...t],liveWindowSeconds:e.liveWindowSeconds===void 0?n.liveWindowSeconds:e.liveWindowSeconds,segmentContext:e.segments??null,cycleRules:e.cycles}));let r=e.laps;if(r)for(let e of d().datasets)e.kind!==`memory`||e.beacon||!e.data.columnNames.includes(r.channel)||de.configure(e.id,{beacon:r}).catch(e=>a.emit(`error`,{error:e,context:`io.openWorkbook`}));return{worksheets:e.worksheets.length,errors:e.errors}},Re=e=>{if(e===null)return;let t=m().numericColumns,n=t.length?e.worksheets.map(e=>t1(e,t)):e.worksheets;S=!0;try{i.set(t=>{let r=t=>e.worksheets.some(e=>e.id===t);return{...t,worksheets:n,activeWorksheetId:r(t.activeWorksheetId)?t.activeWorksheetId:r(e.activeWorksheetId)?e.activeWorksheetId:e.worksheets[0].id,xRanges:Object.fromEntries(Object.entries(t.xRanges).filter(([e])=>r(e))),mathChannels:[...t.mathChannels.filter(e=>e.source!==`workbook`),...e.channels],liveWindowSeconds:e.liveWindowSeconds}})}finally{S=!1}E=T(d()),x.rebase(D()),O()},Be={undo(){l(),Re(x.undo())},redo(){l(),Re(x.redo())},clear(){l(),A()}},Ve={hasWork:()=>yV(d().worksheets),exportWorksheet(e){l(),Ee();let t=N(e),n=lV(t);return{json:n,blob:Ae(n),filename:`${ke(t.name||`worksheet`)}.json`}},exportChart(e){l(),Ee();let{ws:t,panel:n}=P(e),r=uV(n,t.panelChartSettings[e],t.panelChartBackgrounds[e]??null);return{json:r,blob:Ae(r),filename:`${ke(n.title?.trim()||n.kind)}.json`}},parseFile:e=>SV(e),exportWorkspace(){l(),Ee();let e=Ie();return{json:e,blob:Ae(e),filename:`kymoscope-workspace-${new Date().toISOString().slice(0,10)}.json`}},async exportWorkspaceEncrypted(e){l(),Ee();let t=typeof e==`string`?await QB(Ie(),e):await $B(Ie(),e);return{json:t,blob:Ae(t),filename:`kymoscope-workbook-${new Date().toISOString().slice(0,10)}.kymo`}},async importWorkspace(e,t={}){l(),Ee();let n=await De(e);return eV(n)&&(n=await rV(n,t)),j(()=>Le(vV(n)))},toWorkbook:Ie,openWorkbook(e){return l(),j(()=>Le(vV(e)))},async importWorksheet(e){l(),Ee();let t=d();t.limits.maxWorksheets!==null&&t.worksheets.length>=t.limits.maxWorksheets&&u(`worksheets`);let n=await SV(await Oe(e));if(n.type!==`worksheet`)throw new kE(`bad_file`,{found:n.type});let[r]=Me([je(n.worksheet)],Ne());return i.set(e=>({...e,worksheets:[...e.worksheets,r],activeWorksheetId:r.id})),r.id},async importChart(e,t){l(),Ee();let n=await SV(await Oe(e));if(n.type!==`chart`)throw new kE(`bad_file`,{found:n.type});return Fe(n.chart,t)},snapshot(){let e=d();return{datasets:e.datasets,worksheets:e.worksheets,activeWorksheetId:e.activeWorksheetId,selection:e.selection}},restore(e){l();let t=new Set(e.datasets);for(let e of d().datasets)t.has(e)||e.source.dispose().catch(()=>void 0);let n=e.worksheets.length?e.worksheets.map(je):[X$()];j(()=>i.set(t=>({...t,datasets:e.datasets,worksheets:n,activeWorksheetId:n.some(t=>t.id===e.activeWorksheetId)?e.activeWorksheetId:n[0].id,selection:e.selection,xRanges:{},offsets:{},colors:{}})))},reset(){l(),j(()=>{oe(d().datasets.map(e=>e.id));let e=X$();i.set(t=>({...t,worksheets:[e],activeWorksheetId:e.id,xRanges:{},offsets:{},colors:{},mathChannels:t.mathChannels.filter(e=>e.source!==`workbook`)}))})}},He={merged(e){let t=m();if(!t.merged||t.channels.length===0)return t.merged;let n=xE(t.merged,t.channels,N(e).xKey);return{...t.merged,columnNames:[...t.merged.columnNames,...n.ok.map(e=>e.name)],units:[...t.merged.units,...n.ok.map(e=>e.units)],rows:n.rows}},plotted(){return m().merged}},Ue=typeof location<`u`?location.hostname:``,We=t.license,Ge=t.licenseKey,Ke=!1,Je={},Ye=e=>{n||i.set(t=>({...t,licensed:e}))},Xe=(e,t,n)=>{clearTimeout(Je[e]);let r=Math.max(0,t-Date.now()),i=r>2**31-1;Je[e]=setTimeout(()=>{i?Xe(e,t,n):n()},i?2**31-1:r)},Ze=e=>Xe(`renew`,e,()=>void $e()),Qe=e=>Xe(`expiry`,e*1e3+1e3,()=>{FV(Ge,Ue).then(e=>{n||Ye(e.ok)})});async function $e(){let e=36e5,t,r=null,i;try{t=await Promise.race([We.get(),new Promise((e,t)=>{i=setTimeout(()=>t(Error(`timeout`)),3e4)})]),r=await FV(t,Ue)}catch{}finally{clearTimeout(i)}if(n)return!1;if(r?.ok)return Ge=t,Ke=!0,Ye(!0),Qe(r.exp),Ze(Math.max(r.exp*1e3-168*e,Date.now()+e)),!0;console.warn(`[kymoscope] license renewal failed (${r?r.reason:`license.get failed or timed out`}): keeping the current key`);let a=await FV(Ge,Ue);return n?!1:(Ye(a.ok),Ze(Date.now()+e),a.ok)}let et=!We||t.licenseKey?FV(t.licenseKey,Ue).then(e=>(e.ok||console.warn(`[kymoscope] license ${e.reason}: showing attribution`),!Ke&&!n&&(Ye(e.ok),e.ok&&We&&Qe(e.exp)),e.ok)):null,tt=We?$e():et;S=!1,A();let nt={getState:M,subscribe(e){return i.subscribe(e)},on:a.on,licensed:tt,isLicensed:()=>d().licensed,setOptions(e){if(l(),t={...t,...e},e.live&&z.setRelay(e.live.relay),e.palette&&o(),e.limits){let t={...d().limits,...e.limits};i.set(e=>{let n=t.maxWorksheets===null?e.worksheets:e.worksheets.slice(0,Math.max(1,t.maxWorksheets)),r=n.some(t=>t.id===e.activeWorksheetId)?e.activeWorksheetId:n[0].id;return{...e,limits:t,activeWorksheetId:r}})}},datasets:de,folders:me,worksheets:he,charts:ge,view:ve,mathChannels:be,cycles:ye,live:Te,video:we,io:Ve,history:Be,data:He,alerts:{setRules:e=>{l();let t=ce.setRules(e);return i.set(e=>({...e,alertRules:ce.rules()})),t},rules:ce.rules,state:ce.state,evaluate:(e,t)=>(l(),ce.evaluate(e,t)),clearMarks:ce.clearMarks},marks:{list:()=>d().marks},dispose(){if(!n){n=!0,clearTimeout(Je.renew),clearTimeout(Je.expiry),s(),mQ(nt),GZ(nt),z.dispose();for(let e of d().datasets)e.source.dispose().catch(()=>void 0);a.emit(`dispose`,void 0),a.clear()}}};return a1.set(nt,{store:i,derived:m,live:z,alertLines:()=>le(d().alertRules,d().alerts)}),nt}var a1=new WeakMap;function o1(e){let t=a1.get(e);if(!t)throw new kE(`invalid_argument`,{reason:`not a Kymoscope engine`});return t}var s1=2e3,c1=3;function l1(e){let t=e[0].v.fragCount,n=new Map;for(let r of e)r.v.fragCount===t&&!n.has(r.v.fragIndex)&&n.set(r.v.fragIndex,r);let r=[];for(let e=0;e<t;e++){let t=n.get(e);if(!t)return null;r.push(t.v.payload)}let i=n.get(0),a=r[0];if(t>1){a=new Uint8Array(r.reduce((e,t)=>e+t.length,0));for(let e=0,n=0;e<t;e++)a.set(r[e],n),n+=r[e].length}return{t:i.v.t,seq:i.v.seq,key:i.v.key,data:a,arrivedAt:i.at}}function u1(e){let t=[],n=0;for(;n<e.length&&e[n].v.fragIndex>0&&e[n].v.seq===e[0].v.seq;)t.push(e[n++]);let r=[],i=[],a=[];for(;n<=e.length;n++){let t=e[n];if(a.length&&(!t||t.v.seq!==a[0].v.seq)){let e=l1(a);e?r.push(e):t||(i=a),a=[]}t&&a.push(t)}return{head:t,units:r,tail:i}}var d1=class{kind=`recorded`;id;name;parentId;parentName;recordingId;chunks;fetch;open;maxBytes;cache=new Map;sizes=new Map;bytes=0;width=0;height=0;codec=``;waiting=null;constructor(e){this.id=e.id,this.name=e.name,this.parentId=e.parentId,this.parentName=e.parentName??null,this.recordingId=e.recordingId,this.chunks=[...e.chunks].sort((e,t)=>e.seq-t.seq),this.fetch=e.fetchChunk,this.open=e.open,this.maxBytes=e.maxBytes??256*1024*1024}async parse(e){let t=new Uint8Array(await this.fetch(this.chunks[e].seq)),n=[];for(let e of ae(t).messages){let t=null;try{t=await ye(this.open,e.bytes.slice().buffer)}catch{}if(t?.kind!==6)continue;let r=ZQ(t.plaintext);r&&(r.key&&r.fragIndex===0&&!this.codec&&(this.codec=r.codec,this.width=r.width,this.height=r.height),n.push({v:r,at:e.at}))}let r=u1(n),i=e=>e.reduce((e,t)=>e+t.v.payload.length,0);return{...r,bytes:r.units.reduce((e,t)=>e+t.data.length,0)+i(r.head)+i(r.tail)}}parsed(e){let t=this.cache.get(e);if(t)return this.cache.delete(e),this.cache.set(e,t),t;let n=this.parse(e);return this.cache.set(e,n),n.then(t=>{this.cache.get(e)===n&&(this.sizes.set(e,[t.bytes,t.units.length]),this.bytes+=t.bytes,this.evict(e))},()=>{this.cache.get(e)===n&&this.cache.delete(e)}),n}evict(e){for(let t of this.cache.keys()){if(this.bytes<=this.maxBytes)return;let n=this.sizes.get(t);t===e||!n||(this.bytes-=n[0],this.sizes.delete(t),this.cache.delete(t))}}async units(e){let t;try{t=await this.parsed(e)}catch{return[]}if(t.full)return t.full;if(!t.tail.length||e+1>=this.chunks.length)return t.full=t.units;let n=await this.parsed(e+1).catch(()=>null);if(!n)return t.units;let r=null;try{r=l1([...t.tail,...n.head.filter(e=>e.v.seq===t.tail[0].v.seq)])}catch{}return t.full=r?[...t.units,r]:t.units}async seekPlan(e){let t=this.chunks.length;if(!t)return[];let n=e*1e3,r=0;for(;r+1<t&&this.chunks[r+1].t0<=n;)r++;let i=r,a=r+1<t&&this.chunks[r+1].t0-n<s1?r+1:r,o=(await Promise.all(Array.from({length:a-i+1},(e,t)=>this.units(i+t)))).flat(),s=()=>{let t=o.length-1;for(;t>=0&&o[t].t>e;)t--;let n=t;for(;n>=0&&!o[n].key;)n--;return[n,t]},[c,l]=s();for(let e=0;c<0&&i>0&&e<c1;e++)o=[...await this.units(--i),...o],[c,l]=s();return a+1<t&&this.units(a+1),c<0?[]:o.slice(c,l+1)}ready(){return this.waiting??=(async()=>{for(let e=0;e<Math.min(this.chunks.length,c1+1)&&!this.codec;e++)await this.units(e);this.codec||(this.waiting=null)})()}info(){let e=0;for(let[,t]of this.sizes.values())e+=t;return{width:this.width,height:this.height,codec:this.codec,latestT:this.range()?.[1]??null,lagMs:null,units:e,bytes:this.bytes}}range(){let e=this.chunks.length;return e?[this.chunks[0].t0/1e3,this.chunks[e-1].t1/1e3]:null}},f1=1e4,p1=72e4,m1=3e5,h1=3e4,g1=1e4,_1=1e4,v1=64*1024,y1=50,b1=class extends Error{status;code;detail;constructor(e,t,n){super(`${n} (${t})`),this.status=e,this.code=t,this.detail=n}},x1=e=>Uint8Array.from(atob(e),e=>e.charCodeAt(0)),S1=class{opts;deps;auth;secret;password;token=``;ticket=``;ticketRec=!1;authRec=!1;relayUrl=null;apiKeyId=null;projectId=null;e2ee=!1;sid=null;salt=``;key=null;raw=null;epoch=0;haveKey=!1;sealed=null;device=null;senderDeviceId=null;deviceRetried=!1;maxBytesPerSec=0;maxMessageBytes=v1;ws=null;open=!1;everOpen=!1;connectedAt=0;authAt=0;delay=1e3;lastToken=0;viewerCount=0;busy=!1;stopped=!1;refusal=null;heartbeatTimer=null;pingTimer=null;retryTimer=null;statusFns=new Set;viewerFns=new Set;lastStatus=``;constructor(e,t){let{auth:n,secret:r}=ue(e.apiKey);if(!r)throw Error(`This API key has no encryption secret (created before keys carried one). Create a new API key in Kymoscope.`);if(e.kind===`camera`&&!e.parentStreamId)throw Error(`A camera is added to one of your live streams: choose its stream (parentStreamId).`);if(!!e.layer!=!!e.lowOf)throw Error(`A low layer needs both layer: 'low' and lowOf (its high camera's stream id).`);if(e.layer&&e.kind!==`camera`)throw Error(`Only a camera has a low layer.`);if(e.visibility===`open`&&e.password)throw Error(`An open stream has no password: anyone may watch it. Remove the password, or use visibility 'private'.`);this.opts=e,this.deps=t,this.auth=n,this.secret=r,this.password=e.visibility===`open`?Ce:e.password||r}get streamId(){return this.sid}get viewers(){return this.viewerCount}get limits(){return{maxBytesPerSec:this.maxBytesPerSec,maxMessageBytes:this.maxMessageBytes}}onStatus(e){return this.statusFns.add(e),()=>{this.statusFns.delete(e)}}onViewers(e){return this.viewerFns.add(e),()=>{this.viewerFns.delete(e)}}async start(){this.emit();try{let e=await this.deps.store.load();this.salt=e?.salt??L();let t=await this.mint();this.token=t.token,this.relayUrl=t.relayUrl??null,this.maxBytesPerSec=t.maxBytesPerSec||0,this.maxMessageBytes=t.maxMessageBytes||v1,this.apiKeyId=t.apiKeyId??null;let n=t.project;this.e2ee=!!n?.e2ee;let r={};if(this.e2ee){this.projectId=n?.id??null;let t=e?.apiKeyId===this.apiKeyId;this.device=t&&e?.device||await Qe(),t&&e?.streamKey?{key:this.key,epoch:this.epoch,sealed:this.sealed}=e.streamKey:this.key=await z(O()),r.sender_device=await this.senderDevice()}else this.raw=x1(await _(this.password,this.salt)),this.key=await z(this.raw);let i=await this.register(e?.streamId??null,r);if(this.sid=i.stream.id,this.ticket=i.ticket,this.ticketRec=!!i.recording,this.e2ee?(this.senderDeviceId=i.sender_device_id??null,this.projectId=i.project?.id??this.projectId,await this.save(),await this.applyProject(i.project)):(await this.save(),await this.wrapFor(i.devices)),!this.relayUrl)throw Error(`stream-token returned no relayUrl`)}catch(e){throw e instanceof b1&&e.status>=400&&e.status<500&&this.refuse(e),e}this.stopped||(this.lastToken=this.deps.now(),this.connect(),this.heartbeatTimer=setInterval(()=>{this.housekeeping()},f1),this.emit())}async send(e,t){let n=this.key,r=this.e2ee?this.epoch&255:void 0;if(this.stopped||!this.open||!n||this.e2ee&&!this.haveKey)return!1;let i=await _e(n,e,t,r),a=this.ws;if(!this.open||!a)return!1;try{return a.send(i),!0}catch{return!1}}stop(){this.stopped=!0,this.heartbeatTimer&&clearInterval(this.heartbeatTimer),this.retryTimer&&clearTimeout(this.retryTimer),this.heartbeatTimer=this.retryTimer=null;let e=this.ws;if(this.disconnect(),e){e.onopen=e.onmessage=e.onclose=null;try{e.close(1e3)}catch{}}}async post(e,t,n){let r;try{r=await this.deps.fetch(`${this.opts.supabaseUrl.replace(/\/+$/,``)}/functions/v1/${e}`,{method:`POST`,headers:t,body:n===void 0?void 0:JSON.stringify(n)})}catch(e){throw new b1(0,`network`,e?.message??String(e))}let i=await r.text(),a=null;try{a=JSON.parse(i)}catch{}if(r.status!==200)throw new b1(r.status,a?.error??`error`,a?.message??a?.error??i);return a}mint(){return this.post(`stream-token`,{"x-api-key":this.auth})}call(e){return this.post(`stream-publisher`,{Authorization:`Bearer ${this.token}`,"Content-Type":`application/json`},e)}async register(e,t){let n={action:`register`,name:this.opts.name,salt:this.salt,key_check:await p(this.key),visibility:this.opts.visibility??`private`,kind:this.opts.kind,...t};return this.opts.kind===`camera`&&(n.parent_stream_id=this.opts.parentStreamId),this.opts.layer&&(n.layer=this.opts.layer,n.low_of=this.opts.lowOf),e&&(n.stream_id=e),this.call(n)}async senderDevice(){let e=this.device.publicKey;return{public_key:e,binding:await He(await Fe(this.secret),this.apiKeyId??``,e)}}async housekeeping(){if(!(this.busy||this.stopped)){this.busy=!0;try{let e=this.deps.now();if(e-this.lastToken>=p1){this.lastToken=e;try{this.token=(await this.mint()).token}catch{return}}if(this.e2ee){let e=await this.call({action:`heartbeat`,stream_id:this.sid,sender_device_id:this.senderDeviceId,epoch:this.haveKey?this.epoch:0});this.setTicket(e.ticket,!!e.recording),await this.applyProject(e.project)}else{let e=await this.call({action:`heartbeat`,stream_id:this.sid});this.setTicket(e.ticket,!!e.recording),await this.wrapFor(e.devices)}}catch(e){e instanceof b1&&(e.status===401||e.status===403)&&this.refuse(e)}finally{this.busy=!1}}}async wrapFor(e){let t=[];for(let n of e??[])try{t.push({device_id:n.id,wrapped:await ve(n.public_key,this.raw,`${this.sid}|${n.id}`)})}catch{}if(t.length)try{await this.call({action:`wrap_keys`,stream_id:this.sid,keys:t.slice(0,y1)})}catch{}}async applyProject(e){if(!this.e2ee||!e)return;let t=e.key;if(!t){this.emit();return}let n=Number(t.epoch);if(this.haveKey&&n<=this.epoch)return;let r;try{r=await Ke(this.device.privateKey,t.wrapped,ne(this.projectId,n,this.senderDeviceId))}catch{if(this.deviceRetried)return;this.deviceRetried=!0,this.device=await Qe(),await this.reregister();return}let i=Oe(this.sid,this.projectId,n),a=this.key,o=n===this.epoch?this.sealed:null;if(o)try{await b(r,o,i)}catch{o=null}if(!o){let e=O();a=await z(e),o=await Ve(r,e,i),e.fill(0)}try{await this.call({action:`wrap_keys`,stream_id:this.sid,sender_device_id:this.senderDeviceId,project_wrap:{epoch:n,iv:o.iv,ct:o.ct}})}catch{return}this.stopped||(this.key=a,this.sealed=o,this.epoch=n,this.haveKey=!0,await this.save(),this.emit())}async reregister(){let e;try{e=await this.register(this.sid,{sender_device:await this.senderDevice()})}catch{return}this.ticket=e.ticket,this.ticketRec=!!e.recording,this.senderDeviceId=e.sender_device_id??null;let t=e.stream.id;if(t!==this.sid){this.sid=t;let e=this.ws;if(e){this.disconnect(),e.onopen=e.onmessage=e.onclose=null;try{e.close(1e3)}catch{}this.connect()}}await this.save(),await this.applyProject(e.project),this.deviceRetried=!1}async save(){try{await this.deps.store.save({apiKeyId:this.apiKeyId,streamId:this.sid,salt:this.salt,device:this.e2ee?this.device:null,streamKey:this.e2ee&&this.haveKey?{epoch:this.epoch,key:this.key,sealed:this.sealed}:null})}catch{}}connect(){if(this.retryTimer=null,this.stopped)return;let e=this.relayUrl.replace(/\/+$/,``).replace(/^http(s?):\/\//,`ws$1://`),t;try{t=new this.deps.WebSocket(`${e}/v1/streams/${this.sid}/publish`,[LQ,`bearer.${this.ticket}`])}catch{this.dropped();return}t.binaryType=`arraybuffer`,this.ws=t,t.onopen=()=>{t===this.ws&&(this.open=this.everOpen=!0,this.connectedAt=this.authAt=this.deps.now(),this.authRec=this.ticketRec,this.pingTimer=setInterval(()=>{try{t.send(`ping`)}catch{}},h1),this.emit())},t.onmessage=e=>{if(!(t!==this.ws||typeof e.data!=`string`||!e.data.startsWith(`{`)))try{let t=JSON.parse(e.data);t?.type===`viewers`&&this.setViewers(Number(t.count)||0)}catch{}},t.onclose=()=>{t===this.ws&&this.dropped()}}disconnect(){this.ws=null,this.open=!1,this.pingTimer&&clearInterval(this.pingTimer),this.pingTimer=null,this.setViewers(0)}dropped(){let e=this.open&&this.deps.now()-this.connectedAt>=_1;if(this.disconnect(),this.stopped)return;let t=0;e?this.delay=1e3:(t=this.delay,this.delay=Math.min(this.delay*2,g1)),this.retryTimer=setTimeout(()=>this.connect(),t),this.emit()}setTicket(e,t){this.ticket=e,this.ticketRec=t;let n=this.deps.now();if(t||(this.authRec=!1),!(!this.open||!this.ws)&&!(n-this.authAt<m1&&!(t&&!this.authRec)))try{this.ws.send(JSON.stringify({type:`auth`,token:e})),this.authAt=n,this.authRec=t}catch{}}setViewers(e){if(e!==this.viewerCount){this.viewerCount=e;for(let t of this.viewerFns)t(e);this.emit()}}refuse(e){this.refusal={code:e.code,message:e.detail},this.emit(),this.stop()}status(){return this.refusal?{phase:`refused`,...this.refusal}:this.sid?this.e2ee&&!this.haveKey?{phase:`waiting_approval`}:this.open?{phase:`live`,viewers:this.viewerCount}:this.everOpen?{phase:`reconnecting`}:{phase:`registering`}:{phase:`registering`}}emit(){let e=this.status(),t=JSON.stringify(e);if(t!==this.lastStatus){this.lastStatus=t;for(let t of this.statusFns)t(e)}}},C1={"720p30":{width:1280,height:720,fps:30,kbps:2e3},"1080p30":{width:1920,height:1080,fps:30,kbps:4e3}},w1={width:640,height:360,fps:15,kbps:400},T1=[`avc1.640028`,`avc1.4d0028`,`avc1.42e028`],E1=[`avc1.64001f`,`avc1.4d001f`,`avc1.42e01f`],D1=2,O1=1e3,k1=1e3;async function*A1(e){if(typeof MediaStreamTrackProcessor<`u`){let t=new MediaStreamTrackProcessor({track:e}).readable.getReader();try{for(;;){let{value:e,done:n}=await t.read();if(n)return;yield e}}finally{t.cancel().catch(()=>{})}}let t=document.createElement(`video`);t.muted=!0,t.playsInline=!0,t.srcObject=new MediaStream([e]),await t.play();try{for(;e.readyState===`live`;)await new Promise(e=>t.requestVideoFrameCallback(()=>e())),yield new VideoFrame(t,{timestamp:Math.round(performance.now()*1e3)})}finally{t.pause(),t.srcObject=null}}function j1(){let e=null;return(t,n,r)=>(e??=new OffscreenCanvas(n,r).getContext(`2d`),e.drawImage(t,0,0,n,r),new VideoFrame(e.canvas,{timestamp:t.timestamp}))}var M1=class{encoder=null;codec=``;error=null;unsubscribe=null;lastKey=-1/0;keyPending=!1;resume=!0;lastViewers=0;encoding=!1;dropped=0;seq=0;times=new Map;window=[];sending=Promise.resolve();publisher;preset;keyframeMs;Encoder;now;constructor(e,t,n,r,i){this.publisher=e,this.preset=t,this.keyframeMs=n,this.Encoder=r,this.now=i}async configure(){let{width:e,height:t,fps:n,kbps:r}=this.preset,i=this.publisher.limits.maxBytesPerSec,a=i>0?Math.min(r*1e3,i*8/1.25):r*1e3,o=null;for(let r of t>720?T1:E1){let i={codec:r,width:e,height:t,bitrate:a,framerate:n,avc:{format:`annexb`},latencyMode:`realtime`,bitrateMode:`constant`};if((await this.Encoder.isConfigSupported(i)).supported===!0){o=i;break}}return o?(this.codec=o.codec,this.encoder=new this.Encoder({output:e=>this.onChunk(e),error:e=>{this.error=e.message||String(e),this.closeEncoder()}}),this.encoder.configure(o),this.lastViewers=this.publisher.viewers,this.unsubscribe=this.publisher.onViewers(e=>{e>this.lastViewers&&(this.keyPending=!0),this.lastViewers=e}),!0):!1}ready(){let e=this.encoder;return this.encoding=!!e&&!this.error&&this.publisher.viewers>0,!e||!this.encoding?(this.resume=!0,!1):e.encodeQueueSize>D1?(this.dropped++,!1):!0}encode(e){let t=this.now(),n=t-this.lastKey,r=this.resume||n>=this.keyframeMs||this.keyPending&&n>=O1;r&&(this.lastKey=t,this.keyPending=this.resume=!1);let i=(performance.timeOrigin+e.timestamp/1e3)/1e3;Math.abs(i-Date.now()/1e3)>60&&(i=Date.now()/1e3),this.times.set(e.timestamp,i),this.encoder.encode(e,{keyFrame:r})}onChunk(e){let t=new Uint8Array(e.byteLength);e.copyTo(t);let n=this.times.get(e.timestamp)??Date.now()/1e3;this.times.delete(e.timestamp);let{width:r,height:i}=this.preset,a=QQ({key:e.type===`key`,t:n,seq:this.seq++,width:r,height:i,codec:this.codec,data:t});for(let e of a)this.sending=this.sending.then(()=>this.publisher.send(6,e)).catch(()=>!1);this.window.push({at:this.now(),bytes:t.length})}get queue(){return this.encoder?.state===`configured`?this.encoder.encodeQueueSize:0}stats(){let e=this.now();for(;this.window.length&&e-this.window[0].at>=k1;)this.window.shift();let t=this.window.reduce((e,t)=>e+t.bytes,0);return{fps:this.window.length,kbps:t*8/1e3,viewers:this.publisher.viewers,encoding:this.encoding}}stop(){this.encoding=!1,this.closeEncoder(),this.unsubscribe?.(),this.unsubscribe=null}closeEncoder(){this.encoder&&this.encoder.state!==`closed`&&this.encoder.close()}},N1=class{high;lowOpt;low=null;lowAt=-1/0;keyframeMs;Encoder;now;frames;scale;stopped=!1;statsFns=new Set;lastStats=-1/0;constructor(e,t,n={}){this.keyframeMs=(t.keyframeS??2)*1e3,this.Encoder=n.VideoEncoder??VideoEncoder,this.now=n.now??Date.now,this.frames=n.frames??A1,this.scale=n.scale??j1(),this.high=new M1(e,t.preset,this.keyframeMs,this.Encoder,this.now),this.lowOpt=t.low?{publisher:t.low.publisher,preset:t.low.preset??w1}:null}async start(e){if(!await this.high.configure())throw new kE(`camera_codec_unsupported`);if(this.lowOpt){let e=new M1(this.lowOpt.publisher,this.lowOpt.preset,this.keyframeMs,this.Encoder,this.now);await e.configure()&&(this.low=e)}this.loop(e)}async loop(e){for await(let t of this.frames(e)){if(this.stopped){t.close();break}try{this.onFrame(t)}finally{t.close()}this.emitStats()}}onFrame(e){this.high.ready()&&this.high.encode(e);let t=this.low;if(!t)return;let n=this.now();if(n-this.lowAt<750/t.preset.fps||!t.ready())return;this.lowAt=n;let r=this.scale(e,t.preset.width,t.preset.height);try{t.encode(r)}finally{r.close()}}stats(){return{...this.high.stats(),dropped:this.high.dropped,queue:this.high.queue,error:this.high.error,low:this.low?this.low.stats():null}}onStats(e){return this.statsFns.add(e),()=>{this.statsFns.delete(e)}}emitStats(){let e=this.now();if(e-this.lastStats<k1||!this.statsFns.size)return;this.lastStats=e;let t=this.stats();for(let e of this.statsFns)e(t)}stop(){this.stopped=!0,this.high.stop(),this.low?.stop()}},P1=class{#e;constructor(e){this.#e=e}head(){let e=this.#e;return`${e.map(e=>a$(e.name)).join(`,`)}\n${e.map(e=>a$(e.unit)).join(`,`)}\n`}append(e){let t=e.columns,n=``;for(let r=0;r<e.length;r++){for(let e=0;e<t.length;e++){let i=t[e][r];n+=(e?`,`:``)+(Number.isNaN(i)?``:String(i))}n+=`
618
+ `}return n}end(){}},F1=new TextEncoder,I1=e=>e+7&-8,L1=104,R1=64,z1=104,B1=160,V1=4;function H1(e,t,n){let r=24+t.length*8+n.length,i=new Uint8Array(I1(r)),a=new DataView(i.buffer);return i.set(F1.encode(e),0),a.setBigUint64(8,BigInt(r),!0),a.setBigUint64(16,BigInt(t.length),!0),t.forEach((e,t)=>a.setBigUint64(24+t*8,BigInt(e),!0)),i.set(n,24+t.length*8),i}var U1=(e,t)=>H1(e,[],F1.encode(`${t}\0`)),W1=e=>BigInt(Math.round(e))*1000000n,G1=class{#e;#t;#n;#r=0;constructor(e,t,n){this.#e=e,this.#t=t?Date.parse(t):Date.now(),this.#n=n}append(e){let t=e.columns,n=t.length,r=new Float64Array(e.length*n);for(let i=0;i<e.length;i++)for(let e=0;e<n;e++)r[i*n+e]=t[e][i];return this.#r+=e.length,new Uint8Array(r.buffer)}end(){if(this.#r!==this.#n)throw Error(`The recording changed while it was exported (${this.#r} of ${this.#n} rows).`)}head(){let e=this.#e.length,t=[],n=64+L1,r=e=>{let r=n;return t.push(e),n+=e.length,r},i=r(U1(`##MD`,`<FHcomment><TX>Kymoscope cloud recording</TX><tool_id>Kymoscope</tool_id><tool_vendor>Kymoscope</tool_vendor><tool_version>1</tool_version></FHcomment>`)),a=new Uint8Array(16);new DataView(a.buffer).setBigUint64(0,W1(this.#t),!0);let o=r(H1(`##FH`,[0,i],a)),s=this.#e.map(e=>r(U1(`##TX`,e.name))),c=this.#e.map(e=>e.unit?r(U1(`##TX`,e.unit)):0),l=n,u=l+R1,d=this.#e.map((e,t)=>u+z1+t*B1),f=H1(`##DG`,[0,u,u+z1+e*B1,0],new Uint8Array(8)),p=new Uint8Array(32),m=new DataView(p.buffer);m.setBigUint64(8,BigInt(this.#n),!0),m.setUint32(24,e*8,!0);let h=H1(`##CG`,[0,d[0],0,0,0,0],p),g=this.#e.map((t,n)=>{let r=new Uint8Array(72),i=new DataView(r.buffer);return i.setUint8(0,n===0?2:0),i.setUint8(1,+(n===0)),i.setUint8(2,V1),i.setUint32(4,n*8,!0),i.setUint32(8,64,!0),i.setUint8(20,255),H1(`##CN`,[n+1<e?d[n+1]:0,0,s[n],0,0,0,c[n],0],r)}),_=new Uint8Array(24);_.set(F1.encode(`##DT`),0),new DataView(_.buffer).setBigUint64(8,BigInt(24+this.#n*e*8),!0);let v=new Uint8Array(64);v.set(F1.encode(`MDF 4.10 Kymoscop`),0),new DataView(v.buffer).setUint16(28,410,!0);let y=new Uint8Array(32);new DataView(y.buffer).setBigUint64(0,W1(this.#t),!0);let b=[v,H1(`##HD`,[l,o,0,0,0,0],y),...t,f,h,...g,_],x=new Uint8Array(b.reduce((e,t)=>e+t.length,0));return b.reduce((e,t)=>(x.set(t,e),e+t.length),0),x}},K1={csv:`text/csv`,mf4:`application/octet-stream`,parquet:`application/vnd.apache.parquet`};async function q1(e,t,n,r={}){let i=uz(`krc`,{main:new File(e.chunks,`${e.name}.krc`),companions:[],keys:e.keys},r.signal,r.createWorker);try{let e=await i.plan(),a=[{group:0,channels:e.groups[0].channels.map((e,t)=>t)}],o=t===`csv`?new P1(QR(e,a)):new G1(QR(e,a),e.startTime,e.groups[0].samples);await n(o.head()),await i.read(a,`stream`,{chunk:async e=>{await n(o.append(e))},progress:r.onProgress}),o.end()}finally{i.close()}}async function J1(e,t,n={}){let r=[];return await q1(e,t,e=>{r.push(e)},n),new Blob(r,{type:K1[t]})}var Y1=(e,t)=>`khd1|${e.stream}|${e.day}|${e.kind}|${e.level}|${t}`;function X1(e){if(e.length<9)throw Error(`Not a Kymoscope day file (too short)`);let t=e.subarray(e.length-9);if(String.fromCharCode(t[5],t[6],t[7],t[8])!==`KHD1`)throw Error(`Not a Kymoscope day file`);if(t[4]!==1)throw Error(`Unknown Kymoscope day file format ${t[4]}`);return new DataView(t.buffer,t.byteOffset,4).getUint32(0,!0)}var Z1=new TextEncoder;async function Q1(e,t,n,r){let i=await crypto.subtle.decrypt({name:`AES-GCM`,iv:t.subarray(0,12),additionalData:Z1.encode(Y1(n,r))},e,t.subarray(12));return new Uint8Array(i)}async function $1(e,t,n){let r=JSON.parse(new TextDecoder().decode(le(await Q1(e,t,n,`footer`))));if(r.format!==1||r.stream!==n.stream||r.day!==n.day||r.kind!==n.kind||r.level!==n.level)throw Error(`This day file belongs to another history or day`);return r}var e0=0;async function t0(e,t){let n=await zL(),r=e.map(()=>`khd_${++e0}.parquet`),i=[];try{for(let t=0;t<e.length;t++)await n.registerFileBuffer(r[t],e[t]),i.push(r[t]);let a=await n.connect();try{return await t(r,e=>a.query(e))}finally{await a.close()}}finally{for(let e of i)await n.dropFile(e).catch(()=>void 0)}}var n0=(e,t)=>e.getChild(t).toArray();function r0(){t0([],async(e,t)=>{await t(`COPY (SELECT 1::BIGINT AS t) TO 'khd_warm.parquet' (FORMAT parquet)`),await t(`SELECT t FROM read_parquet('khd_warm.parquet')`)}).catch(()=>void 0)}async function i0(e,t){return t0([e],async([e],n)=>{let r=await n(`SELECT (t::DOUBLE / 1e6) AS t${t.map(e=>`, coalesce("c${e}", 'NaN'::FLOAT) AS "c${e}"`).join(``)} FROM read_parquet('${e}') ORDER BY t`);return{t:Float64Array.from(n0(r,`t`)),cols:t.map(e=>Float32Array.from(n0(r,`c${e}`)))}})}async function a0(e){return e.some(e=>e.channels.length)?t0(e.map(e=>e.bytes),async(t,n)=>{let r=await n(`SELECT k, (t::DOUBLE / 1e6) AS t, ch, "min", "max" FROM (${t.flatMap((t,n)=>e[n].channels.length?[`SELECT ${n} AS k, t, ch, "min", "max" FROM read_parquet('${t}') WHERE ch IN (${e[n].channels.join(`,`)})`]:[]).join(` UNION ALL `)}) ORDER BY k, ch, t`),i=n0(r,`k`),a=n0(r,`t`),o=n0(r,`ch`),s=n0(r,`min`),c=n0(r,`max`),l=[];for(let t=0,n=0;t<e.length;t++){let e=n;for(;e<i.length&&i[e]===t;)e++;l.push({t:Float64Array.from({length:e-n},(e,t)=>a[n+t]),ch:Int32Array.from({length:e-n},(e,t)=>o[n+t]),min:Float32Array.from({length:e-n},(e,t)=>s[n+t]),max:Float32Array.from({length:e-n},(e,t)=>c[n+t])}),n=e}return l}):e.map(()=>({t:new Float64Array,ch:new Int32Array,min:new Float32Array,max:new Float32Array}))}var o0=2*1024**3;async function s0(){try{return await(await navigator.storage.getDirectory()).getDirectoryHandle(`kymoscope-history`,{create:!0})}catch{return null}}async function c0(){try{let e=(await navigator.storage.estimate()).quota??0;return e>0?Math.min(o0,e*.2):o0}catch{return o0}}function l0(e=s0,t=c0){let n=null,r=null,i=0,a=()=>n??=e().catch(()=>null),o=e=>e.replace(/[^A-Za-z0-9._-]/g,`_`),s=()=>r??=(async()=>{let e=new Map,t=await a();if(i=0,t)for await(let[n,r]of t.entries()){if(r.kind!==`file`||!r.getFile)continue;let t=await r.getFile();e.set(n,{size:t.size,at:t.lastModified}),i+=t.size}return e})().catch(e=>{throw r=null,e});return{async get(e){try{let t=await a();return t?new Uint8Array(await(await(await t.getFileHandle(o(e))).getFile()).arrayBuffer()):null}catch{return null}},async put(e,n){try{let r=await a();if(!r)return;let c=await s(),l=o(e),u=await(await r.getFileHandle(l,{create:!0})).createWritable();try{await u.write(n),await u.close()}catch(e){throw await u.abort?.().catch(()=>void 0),e}i+=n.length-(c.get(l)?.size??0),c.set(l,{size:n.length,at:Date.now()});let d=await t();if(i<=d)return;for(let[e,t]of[...c].sort((e,t)=>e[1].at-t[1].at)){if(i<=d*.9)break;try{await r.removeEntry(e)}catch{continue}c.delete(e),i-=t.size}}catch{}}}}var u0=16,d0=2e3,f0=512*1024,p0=64*1024,m0=64*1024,h0=8*1024*1024;function g0(e,t=d0){for(let n of[3600,60])if(e/n>=t/2)return n;return 0}var _0={0:[0,60,3600],60:[60,3600,0],3600:[3600,60,0]};function v0(e,t){let n=new Map;for(let t of e)n.set(t.day,[...n.get(t.day)??[],t]);let r=[];for(let[,e]of[...n].sort((e,t)=>e[0].localeCompare(t[0]))){let n=_0[t].map(t=>e.find(e=>e.level===t)).find(Boolean);n&&r.push(n)}return r}async function y0(e,t,n){let r=Array(e.length),i=0;return await Promise.all(Array.from({length:Math.min(t,e.length)},async()=>{for(;i<e.length;){let t=i++;r[t]=await n(e[t])}})),r}function b0(e){let t=[];for(let n of[...e].sort((e,t)=>e.off-t.off)){let e=t[t.length-1];e&&n.off-e.end<=m0&&n.off+n.len-e.start<=h0?e.end=Math.max(e.end,n.off+n.len):t.push({start:n.off,end:n.off+n.len})}return t}var x0=(e,t)=>({stream:e.historyStreamId,day:t.day,kind:t.kind,level:t.level}),S0=(e,t)=>async(n,r,i)=>{let a=t.get(n.id);return a?a.subarray(r,i):(e.signal?.throwIfAborted(),e.fetchRange(n.id,r,i,e.signal))};async function C0(e,t,n=new Map){let r=e.footers?.get(t.id);if(r)return r;let i=await e.cache?.get(`${t.id}/footer`)??null;if(!i){t.bytes<=f0&&n.set(t.id,await e.fetchRange(t.id,0,t.bytes,e.signal));let r=S0(e,n),a=await r(t,Math.max(0,t.bytes-p0),t.bytes),o=X1(a);i=o+9<=a.length?a.slice(a.length-9-o,a.length-9):(await r(t,t.bytes-9-o,t.bytes-9)).slice(),await e.cache?.put(`${t.id}/footer`,i)}let a=await $1(await e.key(t.keyId),i,x0(e,t));return e.footers?.set(t.id,a),a}var w0=e=>e?.code===`missing`;async function T0(e){let t=async()=>{let t=v0(e.segments,e.level).map(e=>e.id).join(),n=await e.relist();return v0(n,e.level).map(e=>e.id).join()===t?null:n},n,r;try{n=await E0(e)}catch(n){if(!e.relist||e.signal?.aborted||!(r=await t()))throw n;return E0({...e,segments:r})}return!n.missingDays.length||!e.relist||e.signal?.aborted||!(r=await t())?n:E0({...e,segments:r})}async function E0(e){let t=v0(e.segments,e.level),n=new Set(e.channels),r=new Map,i=S0(e,r),a=new Set,o=async(t,n)=>{try{return await n()}catch(n){if(e.onMissing!==`gap`||!w0(n))throw n;return a.add(t.id),null}},s=await y0(t,16,t=>o(t,()=>C0(e,t,r))),c={},l={},u=[];t.forEach((t,r)=>{let i=s[r];if(i){l[t.day]=t.level;for(let e of i.channels)n.has(e.n)&&e.u&&!c[e.n]&&(c[e.n]=e.u);i.blocks.forEach((r,a)=>{if(r.t1<e.t0||r.t0>e.t1)return;let o=r.ch.filter(e=>n.has(i.channels[e].n));o.length&&u.push({s:t,f:i,i:a,chs:o})})}});let d=new Map;await y0(u,16,async t=>{let n=await e.cache?.get(`${t.s.id}/${t.i}`);n&&d.set(t,n)});let f=new Map;for(let e of u)d.has(e)||f.set(e.s.id,[...f.get(e.s.id)??[],e]);await y0([...f.values()].flatMap(e=>b0(e.map(e=>e.f.blocks[e.i])).map(t=>({js:e,r:t}))),16,async({js:t,r:n})=>{let r=await o(t[0].s,()=>i(t[0].s,n.start,n.end));if(r)for(let i of t){let t=i.f.blocks[i.i];if(t.off<n.start||t.off+t.len>n.end)continue;let a=r.slice(t.off-n.start,t.off-n.start+t.len);d.set(i,a),e.cacheWrite!==!1&&await e.cache?.put(`${i.s.id}/${i.i}`,a)}});let p=[],m=[];return await y0(u.filter(e=>!a.has(e.s.id)),16,async t=>{let n=await Q1(await e.key(t.s.keyId),d.get(t),x0(e,t.s),t.i);if(t.s.kind===`rollup`){m.push({j:t,plain:n});return}let r=await i0(n,t.chs),i=new Map(t.chs.map((e,n)=>[t.f.channels[e].n,r.cols[n]])),a=_Q({t:r.t,lo:i,hi:i,level:0},e.t0,e.t1);a&&p.push(a)}),(await a0(m.map(e=>({bytes:e.plain,channels:e.j.chs})))).forEach((t,n)=>{let{j:r}=m[n],i=r.s.level/2;for(let n=0;n<t.ch.length;){let a=n;for(;a<t.ch.length&&t.ch[a]===t.ch[n];)a++;let o=r.f.channels[t.ch[n]].n,s=_Q({t:t.t.slice(n,a).map(e=>e+i),lo:new Map([[o,t.min.slice(n,a)]]),hi:new Map([[o,t.max.slice(n,a)]]),level:r.s.level},e.t0,e.t1);s&&p.push(s),n=a}}),{pieces:p.sort((e,t)=>e.t[0]-t.t[0]),units:c,levels:l,missingDays:t.filter(e=>a.has(e.id)).map(e=>e.day)}}var D0=25e6,O0=3e7,k0=1<<20,A0=8192,j0=65536;function M0(e){for(let t=1;t<10;t++){let n=+e.toPrecision(t);if(Math.fround(n)===e)return String(n)}return String(e)}function N0(e){let t=Math.round(e*1e6),n=Math.floor(t/1e6);return`${new Date(n*1e3).toISOString().slice(0,19)}.${String(t-n*1e6).padStart(6,`0`)}Z`}function P0(e,t){let n=e.filter(e=>t.some(t=>e.lo.has(t))).map(e=>e.t),r=new Float64Array(n.reduce((e,t)=>e+t.length,0)),i=0;for(let e of n)r.set(e,i),i+=e.length;r.sort();let a=0;for(let e=0;e<r.length;e++)(a===0||r[e]!==r[a-1])&&(r[a++]=r[e]);let o=r.slice(0,a);if(o.length*t.length>25e6)throw Error(`too_wide`);let s=t.map(()=>new Float32Array(o.length).fill(NaN));for(let n of e)t.forEach((e,t)=>{let r=n.lo.get(e);if(r){for(let e=0,i=hQ(o,n.t[0]);e<n.t.length;e++)if(r[e]===r[e]){for(;o[i]<n.t[e];)i++;s[t][i]=r[e]}}});return{t:o,cols:s}}async function F0(e,t,n,r={}){if(!e.channels.length)throw Error(`Pick at least one channel to export.`);let i=[...new Set(e.segments.map(e=>e.day))].sort(),a=i.map(t=>e.segments.find(e=>e.day===t&&e.kind===`raw`)).filter(e=>!!e),o=i.filter(e=>!a.some(t=>t.day===e)),s=new Set,c=()=>({skippedDays:[...o,...s].sort(),missingDays:[...s].sort()}),l=async t=>{let n=await T0({...e,segments:[t],level:0,cacheWrite:!1,relist:e.relist&&(async()=>(await e.relist()).filter(e=>e.day===t.day&&e.kind===`raw`))});for(let e of n.missingDays)s.add(e);return n},u=e=>r.onProgress?.((e+1)/a.length);if(t===`parquet`)return await L0(a,l,e.channels,n,u),c();if(t===`csv`){let t=!1;for(let[r,i]of a.entries()){let a=await l(i);!t&&!a.missingDays.length&&(await n(`time,${e.channels.map(a$).join(`,`)}\nUTC,${e.channels.map(e=>a$(a.units[e]??``)).join(`,`)}\n`),t=!0);let o=P0(a.pieces,e.channels);for(let e=0;e<o.t.length;e+=A0){let t=``;for(let n=e;n<Math.min(o.t.length,e+A0);n++){t+=N0(o.t[n]);for(let e of o.cols)t+=e[n]===e[n]?`,${M0(e[n])}`:`,`;t+=`
619
+ `}await n(t)}u(r)}return t||await n(`time,${e.channels.map(a$).join(`,`)}\n`),c()}let d=0,f=NaN,p={};for(let t of a){let n=await l(t),r=P0(n.pieces,e.channels);d+=r.t.length,Number.isNaN(f)&&r.t.length&&(f=r.t[0]),p={...n.units,...p}}let m=new G1([{name:`time`,unit:`s`,text:!1},...e.channels.map(e=>({name:e,unit:p[e]??``,text:!1}))],Number.isNaN(f)?null:new Date(f*1e3).toISOString(),d);await n(m.head());for(let[t,r]of a.entries()){let i=P0((await l(r)).pieces,e.channels),a=i.t.map(e=>e-f);for(let e=0;e<i.t.length;e+=j0){let t=Math.min(i.t.length,e+j0);await n(m.append({length:t-e,columns:[a.subarray(e,t),...i.cols.map(n=>Float64Array.from(n.subarray(e,t)))]}))}u(t)}return m.end(),c()}var I0=0;async function L0(e,t,n,r,i,a={max:O0,chunk:k0}){let o=await zL(),s=await o.connect(),c=++I0,l=`khd_values_${c}`,u=`khd_names_${c}`,d=`khd_export_${c}.parquet`,f=new Float64Array(a.chunk),p=new Int32Array(a.chunk),m=new Float32Array(a.chunk),h=0,g=0,_=async()=>{h&&await s.insertArrowTable(dF({time:f.slice(0,h),ch:p.slice(0,h),value:m.slice(0,h)}),{name:l,create:!1}),h=0};try{await s.query(`CREATE TABLE ${u} (ch INTEGER, channel VARCHAR)`),await s.query(`INSERT INTO ${u} VALUES ${n.map((e,t)=>`(${t}, '${e.replace(/'/g,`''`)}')`).join(`, `)}`),await s.query(`CREATE TABLE ${l} (time DOUBLE, ch INTEGER, value FLOAT)`);for(let[r,o]of e.entries()){for(let e of(await t(o)).pieces)for(let[t,r]of n.entries()){let n=e.lo.get(r);if(n){for(let r=0;r<n.length;r++)if(n[r]===n[r]){if(++g>a.max)throw Object.assign(Error(`This export has more than ${(a.max/1e6).toLocaleString(`en-US`)} million values, too many for Parquet in the browser: export a shorter range or fewer channels.`),{code:`too_large`});f[h]=e.t[r],p[h]=t,m[h]=n[r],++h===a.chunk&&await _()}}}await _(),i(r)}await o.registerEmptyFileBuffer(d),await s.query(`COPY (SELECT to_timestamp(v.time) AS time, n.channel, v.value FROM ${l} v JOIN ${u} n USING (ch)
620
+ ORDER BY v.time, n.channel) TO '${d}' (FORMAT parquet, COMPRESSION zstd)`),await r(await o.copyFileToBuffer(d))}finally{await s.query(`DROP TABLE IF EXISTS ${l}; DROP TABLE IF EXISTS ${u}`).catch(()=>void 0),await s.close(),await o.dropFile(d).catch(()=>void 0)}}export{gZ as ANNOTATION_CONTROLS_ATTR,Ot as ANNOTATION_KINDS,g$ as AxisState,_B as BEACON_STATS,C1 as CAMERA_PRESETS,er as CHART_ALARM_FIELDS,PQ as CHART_KINDS,RB as CYCLE_TIME,N1 as CameraSender,jB as CycleRunner,MB as CycleSet,Rt as DASHBOARD_GRID_COLS,Bt as DASHBOARD_GRID_GAP_PX,zt as DASHBOARD_GRID_ROWS,qz as DATASET_PALETTE,kt as DEFAULT_ANNOTATION_WIDTH,en as DEFAULT_AXIS_LINE,nn as DEFAULT_BEACON,tn as DEFAULT_GRID_LINE,fn as DEFAULT_TRACE_WIDTH,dn as DEFAULT_XYZ_POINT_RADIUS,un as DEFAULT_XY_POINT_RADIUS,O$ as DELTA_SUFFIX,K1 as EXPORT_TYPES,ST as FUNCTION_REFERENCE,d0 as HISTORY_PIXELS,yQ as HistoryDataSource,CV as IMPORTABLE_EXT,ke as KIND_VIDEO,nB as KPI_STATS,xe as KRC_HEADER_BYTES,hB as KpiAcc,kE as KymoscopeError,nt as LEAF_KEYS,qe as LIVE_TIME_COLUMN,w1 as LOW_PRESET,S1 as LivePublisher,f$ as MAX_BAND_CELLS,d$ as MAX_GRID,Un as MAX_PANEL_CAMERAS,O0 as MAX_PARQUET_VALUES,D0 as MAX_WIDE_CELLS,Wt as MIN_PANEL_H,Ut as MIN_PANEL_W,Ce as OPEN_STREAM_PASSWORD,u0 as RANGE_PARALLEL,d1 as RecordedVideoSource,gB as RuleRunner,Ft as SEVERITY_HEX,K$ as UNLIMITED,JQ as VIDEO_MAX_FRAGMENT,QT as WINDOW_FN_NAMES,C as WORKBOOK_EXPORT_AAD,w as alertRuleAad,_$ as alignSegment,Qt as arrangeAutoLayout,p$ as axisColumn,w$ as bandEdges,CB as bestCycleIndex,D as bindKeyAad,Y1 as blockAad,l0 as blockCache,jW as buildEquation,CE as buildMathChannelsBlob,b$ as buildReference,TV as buildTree,Vn as cameraLabel,tr as chartAlarm,Cz as chartChannelCount,IQ as chartLabel,g0 as chooseLevel,or as clampPct,Kt as clampRectForKind,_Q as clipPiece,b0 as coalesce,Zn as coerceAlarmLine,Nt as coerceAnnotation,BY as colorAt,Jz as colorForDataset,$z as colorSchemeOf,UY as colorsCss,B as columnIsNumeric,aB as compareOp,T$ as compareToReference,OW as computePolyFit,kW as computeR2,i1 as createEngine,et as createRuleEvaluator,KB as cutCycle,AB as cycleRuleChannels,JB as cycleTables,yB as cyclicChannels,D$ as decodeBand,ZQ as decodeVideo,RX as decorateColumnLabel,Mn as defaultAreaChartPanelSettings,An as defaultBarChartPanelSettings,yn as defaultBoxPlotPanelSettings,Pn as defaultBubbleChartPanelSettings,Rn as defaultCalibrationPanelSettings,Hn as defaultCameraPanelSettings,Nn as defaultCdfChartPanelSettings,Cn as defaultConfusionPanelSettings,En as defaultControlChartPanelSettings,Yz as defaultDatasetPalette,On as defaultEmbeddingPanelSettings,kn as defaultFlameGraphPanelSettings,Bn as defaultGanttPanelSettings,Ln as defaultGaugePanelSettings,xn as defaultHeatmapPanelSettings,gn as defaultHistogramPanelSettings,Tn as defaultLossCurvePanelSettings,pn as defaultMultibandPanelSettings,Dn as defaultParallelCoordsPanelSettings,_n as defaultPolarPanelSettings,zn as defaultQQPlotPanelSettings,jn as defaultRadarPanelSettings,wn as defaultRocPanelSettings,In as defaultSankeyPanelSettings,bn as defaultSpectrogramPanelSettings,vn as defaultSpectrumPanelSettings,Fn as defaultTreemapPanelSettings,Sn as defaultViolinPanelSettings,$t as defaultXyAxisScaleSettings,mn as defaultXyPanelSettings,hn as defaultXyzPanelSettings,HB as definitionChannels,f as deriveKey,_ as deriveRawKeyBase64,S as deviceFingerprint,qt as dragLayout,E$ as encodeBand,XQ as encodeVideo,$B as encryptWorkbookFile,ir as ensurePanelSettingsForPanels,rE as evalChannel,tB as eventWithin,F0 as exportHistoryTo,J1 as exportRecording,q1 as exportRecordingTo,tE as extractFreeIdentifiers,M0 as f32text,VB as findCycles,X1 as footerLength,Gz as formatClockTick,Kz as formatClockValue,TB as formatLapValue,QQ as fragmentVideo,A as generateApiToken,Qe as generateDeviceKeyPair,i as generateRecoveryKeyPair,L as generateSalt,Uz as getClockTimeZone,ze as getRawNonEmptyLines,y$ as gridAt,bB as guessBeaconChannel,h as hashToken,F as historyKeyAad,z as importStreamKey,y as inferParseConfig,Fz as isClockAxis,wV as isImportable,LX as isMathChannelName,N0 as isoMicros,UB as kpiColumn,rB as kpiKey,WB as kpisOf,A$ as liveSegmentTracker,fB as localDay,h$ as localSeconds,p as makeKeyCheck,Lt as markToAnnotation,sn as newGaugeItem,cr as newMathChannel,Xt as newPanel,sB as newResetState,sr as newSeriesId,wz as niceMajorStep,eB as observeColorScheme,pR as openDatasetFromText,$1 as openFooter,ye as openMessage,Q1 as openSealed,b as openUnderProjectKey,Re as openWithKey,v as openWithPassword,Wn as panelCameras,H as parseColumnNames,ee as parseConfigsEqual,LB as parseCycleDefinitions,k as parseDatasetWithConfig,eE as parseFormula,ae as parseKrc,Pe as parseKrcHeader,TE as parseMathChannelsFile,ln as parseOptionalAxisRange,rr as parsePanelChartSettingsMap,te as parseRecoveryCode,v0 as pickSegments,y0 as pool,C$ as pooledSd,HY as presetStops,V as projectConfigKeyAad,ne as projectWrapAad,O as randomKey,C0 as readFooter,T0 as readHistoryRange,BB as readSource,je as recordingKeyAad,Be as recordingKeySealAad,e as recoveryAttestationAad,me as recoveryCode,We as recoveryKeyAad,Ne as recoveryPrivateKey,NX as referenceBands,v$ as resample,cB as resetStep,$n as resolveLinkedAlarms,YB as rowsCsv,iB as ruleChannels,_e as sealMessage,Ve as sealUnderProjectKey,Se as sealWithKey,oe as sealWithPassword,Fe as senderBindKey,He as senderBinding,Hz as setClockTimeZone,mB as shiftDay,gQ as slicePiece,vQ as splicePieces,ue as splitApiKey,vB as splitLaps,Oe as streamKeyAad,t as subsampleIndices,Wz as subscribeClockTimeZone,xB as suggestBeacon,rt as thresholdOf,dB as tzOffsetS,Ke as unwrapForDevice,fe as unwrapStreamKey,tt as validateRule,ge as verifyKeyCheck,FV as verifyLicense,Le as verifySenderBinding,r0 as warmHistoryDecoder,P0 as wideDay,Ae as workbookBodyAad,XB as workbookExportAad,tV as workbookFileInfo,be as workbookKeyAad,ve as wrapForDevice,pB as zonedInstant};