@kymoscope/sdk 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{importers-N1JOOVEg.js → importers-DHeUdZcP.js} +1 -1
- package/dist/{krc-D_CI7AI8.js → krc-BIfw0rX1.js} +1 -1
- package/dist/kymoscope-embed.js +11 -11
- package/dist/kymoscope-sdk.js +12 -12
- package/dist/types/components/GaugeChart.d.ts +11 -1
- package/dist/types/lib/data/liveDataSource.d.ts +1 -1
- package/dist/types/lib/live/buffer.d.ts +2 -1
- package/dist/types/lib/panelChartSettings.d.ts +3 -0
- package/package.json +1 -1
package/dist/kymoscope-embed.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*! @kymoscope/sdk (c) 2026 Kymoscope. Proprietary software: use requires a license. See LICENSE.md. */
|
|
2
|
-
var __kymoscopeScriptUrl=document.currentScript&&document.currentScript.src||location.href,Kymoscope=(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:`Module`});var n=Object.create,r=Object.defineProperty,i=Object.getOwnPropertyDescriptor,a=Object.getOwnPropertyNames,o=Object.getPrototypeOf,s=Object.prototype.hasOwnProperty,c=(e,t)=>()=>(e&&(t=e(e=0)),t),l=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),u=(e,t)=>{let n={};for(var i in e)r(n,i,{get:e[i],enumerable:!0});return t||r(n,Symbol.toStringTag,{value:`Module`}),n},d=(e,t,n,o)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var c=a(t),l=0,u=c.length,d;l<u;l++)d=c[l],!s.call(e,d)&&d!==n&&r(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(o=i(t,d))||o.enumerable});return e},f=(e,t,i)=>(i=e==null?{}:n(o(e)),d(t||!e||!e.__esModule?r(i,`default`,{value:e,enumerable:!0}):i,e)),p=[`text`,`brush`,`arrow`,`box`],m={text:14,brush:3,arrow:2,box:2},h=/^#[0-9a-fA-F]{6}$/,g={text:[1,1],arrow:[2,2],box:[2,2],brush:[2,1/0]},_=e=>typeof e==`number`&&Number.isFinite(e);function v(e){if(!e||typeof e!=`object`)return null;let t=e,n=t.kind;if(!p.includes(n)||typeof t.id!=`string`||!t.id||!Array.isArray(t.points))return null;let r=t.points.filter(e=>Array.isArray(e)&&_(e[0])&&_(e[1])).map(([e,t])=>[e,t]),[i,a]=g[n];return r.length<i||r.length>a?null:{id:t.id,kind:n,points:r,...t.anchor===`x`?{anchor:`x`}:{},color:typeof t.color==`string`&&h.test(t.color)?t.color:`#f5a524`,width:_(t.width)&&t.width>0?Math.min(96,t.width):m[n],...typeof t.text==`string`&&t.text!==``?{text:t.text}:{}}}function y(e){return Array.isArray(e)?e.map(v).filter(e=>e!==null):null}var b={multiband:6,xyscatter:6,xyzmesh:6,histogram:6,polar:6,spectrum:6,boxplot:6,spectrogram:6,heatmap:6,violin:6,confusion:6,roc:6,losscurve:6,controlchart:6,parallelcoords:6,embedding:6,flamegraph:6,barchart:6,radar:6,areachart:6,cdfchart:6,bubblechart:6,treemap:6,sankey:6,calibration:6,qqplot:6,gantt:6,gauge:6},x={multiband:24,xyscatter:24,xyzmesh:24,histogram:24,polar:24,spectrum:24,boxplot:24,spectrogram:24,heatmap:24,violin:24,confusion:24,roc:24,losscurve:24,controlchart:24,parallelcoords:24,embedding:24,flamegraph:24,barchart:24,radar:24,areachart:24,cdfchart:24,bubblechart:24,treemap:24,sankey:24,calibration:24,qqplot:24,gantt:24,gauge:24},S=b;function C(e,t){return e.x<t.x+t.w&&t.x<e.x+e.w&&e.y<t.y+t.h&&t.y<e.y+e.h}function w(e,t,n,r=96){let i=b[e],a=x[e],o=Math.max(i,Math.min(t.w,n-Math.max(0,t.x))),s=Math.max(a,Math.min(t.h,r-Math.max(0,t.y)));return{x:Math.max(0,Math.min(t.x,n-o)),y:Math.max(0,Math.min(t.y,r-s)),w:o,h:s}}function T(e,t,n){for(let r of t)if(r.id!==n&&C(e,r.rect))return!0;return!1}function E(e,t,n=96){let r=b[e],i=x[e],a=Math.min(48,n),o=e===`multiband`||e===`xyzmesh`?64:48;for(let i=0;i<384;i+=8)for(let s=0;s<=n-r;s+=8){let r=w(e,{x:s,y:i,w:a,h:o},n);if(!T(r,t,``))return r}return w(e,{x:0,y:0,w:r,h:i},n)}function D(e,t){return{id:crypto.randomUUID(),kind:e,rect:E(e,t)}}function O(e){if(e<=0)return[];if(e===1)return[{x:0,y:0,w:1,h:1}];if(e===2)return[{x:0,y:0,w:.5,h:1},{x:.5,y:0,w:.5,h:1}];if(e===3)return[{x:0,y:0,w:.5,h:.5},{x:.5,y:0,w:.5,h:.5},{x:0,y:.5,w:1,h:.5}];if(e===4)return[{x:0,y:0,w:.5,h:.5},{x:.5,y:0,w:.5,h:.5},{x:0,y:.5,w:.5,h:.5},{x:.5,y:.5,w:.5,h:.5}];let t=O(e-4).map(e=>({x:e.x*.5,y:e.y,w:e.w*.5,h:e.h})),n=O(4).map(e=>({x:.5+e.x*.5,y:e.y,w:e.w*.5,h:e.h}));return[...t,...n]}function k(e,t=96,n=96){let r=O(e.length);return e.map((e,i)=>{let a=r[i];if(!a)return e;let o=Math.round(a.x*t),s=Math.round(a.y*n),c=Math.max(1,Math.round(a.w*t)),l=Math.max(1,Math.round(a.h*n));return{...e,rect:{x:o,y:s,w:c,h:l}}})}function A(){return{scaleMin:``,scaleMax:``,majorStep:``,minorStep:``,alarm:null}}var j={style:`dashed`,width:1,color:null},M={style:`solid`,width:1,color:null},N={enabled:!1,reference:`previous`,datasetId:null,datasetColor:`#94a3b8`,previousColor:`#64748b`},P=/^#[0-9a-f]{6}$/i;function F(e){if(!e||typeof e!=`object`)return;let t=e;return{enabled:t.enabled===!0,reference:t.reference===`dataset`||t.reference===`none`?t.reference:`previous`,datasetId:typeof t.datasetId==`string`&&t.datasetId?t.datasetId:null,datasetColor:typeof t.datasetColor==`string`&&P.test(t.datasetColor)?t.datasetColor:N.datasetColor,previousColor:typeof t.previousColor==`string`&&P.test(t.previousColor)?t.previousColor:N.previousColor}}var I=[`#f5a524`,`#38bdf8`,`#22c55e`,`#f472b6`,`#a78bfa`,`#fb7185`];function L(e,t){if(!e||typeof e!=`object`)return null;let n=e;if(typeof n.column!=`string`)return null;let r=Oe(n.alarm);return{id:typeof n.id==`string`&&n.id?n.id:`g${t}`,column:n.column,color:typeof n.color==`string`?n.color:I[t%I.length],value:n.value===`mean`||n.value===`min`||n.value===`max`?n.value:`last`,style:n.style===`linear`?`linear`:`arc`,min:typeof n.min==`string`?n.min:``,max:typeof n.max==`string`?n.max:``,...r?{alarm:r}:{},...n.colorMode===`gradient`||n.colorMode===`zones`?{colorMode:n.colorMode}:{},...Array.isArray(n.stops)?{stops:n.stops.flatMap(e=>{let t=e;return t&&typeof t.at==`number`&&Number.isFinite(t.at)&&typeof t.color==`string`?[{at:t.at,color:t.color}]:[]})}:{}}}function R(e,t){let n=parseFloat(e),r=parseFloat(t);return Number.isFinite(n)&&Number.isFinite(r)&&n<r?[n,r]:void 0}var z=1.8;function B(){return{kind:`multiband`,series:[],addColumn:``,layout:`overlay`,xAxisLine:{...j},yAxisLine:{...j},gridLine:{...M},lineWidth:1}}function V(e){return{kind:`xyscatter`,xyXCol:``,xyYCol:``,xyColorCol:null,xyColor:e,xyPointRadius:z,xyXAxisLine:{...j},xyYAxisLine:{...j},xyGridLine:{...M},xyFit:null,xyXScale:A(),xyYScale:A()}}function H(e=4){return{kind:`xyzmesh`,xyzXCol:``,xyzYCol:``,xyzZCol:``,xyzViewMode:`3d`,xyzXScale:A(),xyzYScale:A(),xyzZScale:A(),xyzPointRadius:e,showMesh:!1,meshStyle:`filled`,meshOpacity:.85}}function U(){return{kind:`histogram`,histColumn:``,histBins:0,histColor:`#38bdf8`,histNormal:!1,histLogY:!1}}function W(){return{kind:`polar`,polarAngleCol:``,polarRadiusCol:``,polarColor:`#a78bfa`,polarMode:`waveform`,polarRadiusMin:``,polarRadiusMax:``}}function ee(){return{kind:`spectrum`,specSignalCol:``,specTimeCol:``,specSampleRate:`1000`,specXMode:`hz`,specYMode:`amplitude`,specWindow:`hann`,specColor:`#34d399`,specLogX:!1}}function te(){return{kind:`boxplot`,boxValueCol:``,boxGroupCol:``,boxColor:`#fb923c`,boxWhiskers:`1.5iqr`}}function ne(){return{kind:`spectrogram`,sgSignalCol:``,sgTimeCol:``,sgSampleRate:`1000`,sgWindowSize:512,sgOverlap:.5,sgWinFunc:`hann`,sgYMode:`db`,sgLogFreq:!1}}function G(){return{kind:`heatmap`,hmMode:`binned`,hmColumns:[],hmXCol:``,hmYCol:``,hmValueCol:``,hmXBins:6,hmYBins:6,hmXMin:``,hmXMax:``,hmYMin:``,hmYMax:``,hmShowValues:!0,hmColorScheme:`diverging`}}function re(){return{kind:`violin`,vlValueCol:``,vlGroupCol:``,vlColor:`#818cf8`,vlShowBox:!0,vlBandwidth:``,vlOrientation:`vertical`}}function ie(){return{kind:`confusion`,cfActualCol:``,cfPredictedCol:``,cfNormalize:!1}}function ae(){return{kind:`roc`,rocScoreCol:``,rocLabelCol:``,rocMode:`roc`,rocColor:`#f472b6`}}function oe(){return{kind:`losscurve`,lcXCol:``,lcLeftCols:[],lcRightCols:[]}}function se(){return{kind:`controlchart`,ccValueCol:``,ccSubgroupCol:``,ccSigmaLevel:3,ccColor:`#22d3ee`}}function ce(){return{kind:`parallelcoords`,pcColumns:[],pcColorByCol:``,pcColor:`#64748b`}}function le(){return{kind:`embedding`,emXCol:``,emYCol:``,emColorCol:``,emColorMode:`categorical`,emLabelCol:``,emPointSize:3,emColor:`#a78bfa`}}function ue(){return{kind:`flamegraph`,fgNameCol:``,fgParentCol:``,fgValueCol:``,fgDirection:`topdown`}}function de(){return{kind:`barchart`,bcCategoryCol:``,bcValueCols:[],bcMode:`grouped`,bcHorizontal:!1}}function fe(){return{kind:`radar`,rdAxesCols:[],rdGroupCol:``,rdColor:`#38bdf8`,rdFill:!0}}function pe(){return{kind:`areachart`,acXCol:``,acYCols:[],acStacked:!1}}function me(){return{kind:`cdfchart`,cdValueCols:[],cdComplement:!1,cdLogX:!1}}function he(){return{kind:`bubblechart`,bbXCol:``,bbYCol:``,bbSizeCol:``,bbColorCol:``,bbColorMode:`categorical`,bbColor:`#64748b`,bbMaxRadius:24}}function ge(){return{kind:`treemap`,tmNameCol:``,tmParentCol:``,tmValueCol:``}}function _e(){return{kind:`sankey`,skSourceCol:``,skTargetCol:``,skValueCol:``}}function ve(){return{kind:`gauge`,ggGauges:[]}}function ye(){return{kind:`calibration`,cbScoreCol:``,cbLabelCol:``,cbBins:10,cbColor:`#38bdf8`}}function be(){return{kind:`qqplot`,qqValueCol:``,qqMode:`normal`,qqRefCol:``,qqColor:`#a78bfa`}}function xe(){return{kind:`gantt`,gtLabelCol:``,gtStartCol:``,gtEndCol:``,gtGroupCol:``}}function Se(e){if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.id==`string`&&typeof t.column==`string`&&typeof t.color==`string`&&typeof t.bandFromPct==`number`&&typeof t.bandToPct==`number`&&typeof t.scaleMin==`number`&&typeof t.scaleMax==`number`&&typeof t.yMajorStep==`number`&&typeof t.yMinorStep==`number`}function Ce(e){if(!e||typeof e!=`object`)return!1;let t=e;return(t.style===`none`||t.style===`solid`||t.style===`dashed`||t.style===`dotted`)&&typeof t.width==`number`&&(t.color===null||typeof t.color==`string`)}function we(e,t){return Ce(e)?e:{...t}}function Te(e){if(!e||typeof e!=`object`)return!1;let t=e;return t.kind===`multiband`&&Array.isArray(t.series)&&t.series.every(Se)&&typeof t.addColumn==`string`}function Ee(e){if(!e||typeof e!=`object`)return!1;let t=e;return t.kind===`xyscatter`&&typeof t.xyXCol==`string`&&typeof t.xyYCol==`string`&&typeof t.xyColor==`string`&&typeof t.xyPointRadius==`number`}function De(e){if(!e||typeof e!=`object`)return!1;let t=e,n=t.xyzViewMode,r=n===`3d`||n===`xy`||n===`xz`||n===`yz`;return t.kind===`xyzmesh`&&typeof t.xyzXCol==`string`&&typeof t.xyzYCol==`string`&&typeof t.xyzZCol==`string`&&r&&typeof t.xyzPointRadius==`number`}function Oe(e){if(!e||typeof e!=`object`)return null;let t=e;return typeof t.value!=`number`||!Number.isFinite(t.value)||t.style!==`solid`&&t.style!==`dashed`&&t.style!==`dotted`||typeof t.width!=`number`||typeof t.color!=`string`?null:{value:t.value,style:t.style,width:t.width,color:t.color}}var ke={histogram:`histAlarm`,spectrum:`specAlarm`,areachart:`acAlarm`,losscurve:`lcAlarm`,cdfchart:`cdAlarm`,bubblechart:`bbAlarm`,boxplot:`boxAlarm`,violin:`vlAlarm`,barchart:`bcAlarm`,gantt:`gtAlarm`};function Ae(e){if(!e||!(e.kind in ke))return null;let t=e[ke[e.kind]];return t?{alarm:t,axis:e.kind===`histogram`||e.kind===`cdfchart`||e.kind===`gantt`||e.kind===`barchart`&&e.bcHorizontal||e.kind===`violin`&&e.vlOrientation===`horizontal`?`x`:`y`}:null}function je(e){let t=A();if(!e||typeof e!=`object`)return t;let n=e,r=Oe(n.alarm);return{scaleMin:typeof n.scaleMin==`string`?n.scaleMin:t.scaleMin,scaleMax:typeof n.scaleMax==`string`?n.scaleMax:t.scaleMax,majorStep:typeof n.majorStep==`string`?n.majorStep:t.majorStep,minorStep:typeof n.minorStep==`string`?n.minorStep:t.minorStep,alarm:r}}function Me(e,t,n){if(!e||typeof e!=`object`)return{};let r={};for(let[t,n]of Object.entries(e)){if(!t||typeof t!=`string`)continue;if(Te(n)){let e=n;r[t]={kind:`multiband`,series:e.series,addColumn:e.addColumn,layout:e.layout===`parallel`?`parallel`:`overlay`,xAxisLine:we(e.xAxisLine,j),yAxisLine:we(e.yAxisLine,j),gridLine:we(e.gridLine,M),lineWidth:typeof e.lineWidth==`number`&&Number.isFinite(e.lineWidth)?Math.min(6,Math.max(.5,e.lineWidth)):1,...F(e.beacon)?{beacon:F(e.beacon)}:{},...e.envelope===!0?{envelope:!0}:{}}}else if(Ee(n)){let e=n,i=e.xyFit,a=i&&typeof i==`object`&&(i.degree===1||i.degree===2||i.degree===3)&&typeof i.color==`string`&&(i.lineStyle===`solid`||i.lineStyle===`dashed`||i.lineStyle===`dotted`)&&typeof i.width==`number`?{degree:i.degree,color:i.color,lineStyle:i.lineStyle,width:i.width}:null;r[t]={...n,xyColorCol:typeof e.xyColorCol==`string`?e.xyColorCol:null,xyPointRadius:Math.min(16,Math.max(.5,n.xyPointRadius)),xyDrawMode:e.xyDrawMode===`lines`||e.xyDrawMode===`both`?e.xyDrawMode:void 0,xyLineWidth:typeof e.xyLineWidth==`number`&&Number.isFinite(e.xyLineWidth)?Math.min(8,Math.max(.5,e.xyLineWidth)):void 0,xyXAxisLine:we(e.xyXAxisLine,j),xyYAxisLine:we(e.xyYAxisLine,j),xyGridLine:we(e.xyGridLine,M),xyFit:a,xyXScale:je(e.xyXScale),xyYScale:je(e.xyYScale)}}else if(De(n)){let e=e=>typeof e==`string`?e:``,i=n.xyzXScale?null:{scaleMin:e(n.xyzXMin),scaleMax:e(n.xyzXMax),majorStep:``,minorStep:``,alarm:null},a=n.xyzYScale?null:{scaleMin:e(n.xyzYMin),scaleMax:e(n.xyzYMax),majorStep:``,minorStep:``,alarm:null},o=n.xyzZScale?null:{scaleMin:e(n.xyzZMin),scaleMax:e(n.xyzZMax),majorStep:``,minorStep:``,alarm:null};r[t]={kind:`xyzmesh`,xyzXCol:n.xyzXCol,xyzYCol:n.xyzYCol,xyzZCol:n.xyzZCol,xyzViewMode:n.xyzViewMode,xyzXScale:i??je(n.xyzXScale),xyzYScale:a??je(n.xyzYScale),xyzZScale:o??je(n.xyzZScale),xyzPointRadius:Math.min(16,Math.max(.5,n.xyzPointRadius)),showMesh:n.showMesh===!0,meshStyle:n.meshStyle===`wireframe`||n.meshStyle===`both`?n.meshStyle:`filled`,meshOpacity:typeof n.meshOpacity==`number`&&n.meshOpacity>=0&&n.meshOpacity<=1?n.meshOpacity:.85,...n.xyzMode===`matrix`?{xyzMode:`matrix`}:{},...Array.isArray(n.xyzColumns)?{xyzColumns:n.xyzColumns.filter(e=>typeof e==`string`)}:{}}}else if(n&&typeof n==`object`&&n.kind===`histogram`){let e=n;r[t]={kind:`histogram`,histColumn:typeof e.histColumn==`string`?e.histColumn:``,histBins:typeof e.histBins==`number`?e.histBins:0,histColor:typeof e.histColor==`string`?e.histColor:`#38bdf8`,histNormal:e.histNormal===!0,histLogY:e.histLogY===!0}}else if(n&&typeof n==`object`&&n.kind===`polar`){let e=n;r[t]={kind:`polar`,polarAngleCol:typeof e.polarAngleCol==`string`?e.polarAngleCol:``,polarRadiusCol:typeof e.polarRadiusCol==`string`?e.polarRadiusCol:``,polarColor:typeof e.polarColor==`string`?e.polarColor:`#a78bfa`,polarMode:e.polarMode===`rose`?`rose`:`waveform`,polarRadiusMin:typeof e.polarRadiusMin==`string`?e.polarRadiusMin:``,polarRadiusMax:typeof e.polarRadiusMax==`string`?e.polarRadiusMax:``}}else if(n&&typeof n==`object`&&n.kind===`spectrum`){let e=n;r[t]={kind:`spectrum`,specSignalCol:typeof e.specSignalCol==`string`?e.specSignalCol:``,specTimeCol:typeof e.specTimeCol==`string`?e.specTimeCol:``,specSampleRate:typeof e.specSampleRate==`string`?e.specSampleRate:`1000`,specXMode:e.specXMode===`order`?`order`:`hz`,specYMode:e.specYMode===`db`?`db`:`amplitude`,specWindow:e.specWindow===`rectangular`?`rectangular`:`hann`,specColor:typeof e.specColor==`string`?e.specColor:`#34d399`,specLogX:e.specLogX===!0}}else if(n&&typeof n==`object`&&n.kind===`boxplot`){let e=n;r[t]={kind:`boxplot`,boxValueCol:typeof e.boxValueCol==`string`?e.boxValueCol:``,boxGroupCol:typeof e.boxGroupCol==`string`?e.boxGroupCol:``,boxColor:typeof e.boxColor==`string`?e.boxColor:`#fb923c`,boxWhiskers:e.boxWhiskers===`minmax`?`minmax`:`1.5iqr`}}else if(n&&typeof n==`object`&&n.kind===`spectrogram`){let e=n;r[t]={kind:`spectrogram`,sgSignalCol:typeof e.sgSignalCol==`string`?e.sgSignalCol:``,sgTimeCol:typeof e.sgTimeCol==`string`?e.sgTimeCol:``,sgSampleRate:typeof e.sgSampleRate==`string`?e.sgSampleRate:`1000`,sgWindowSize:typeof e.sgWindowSize==`number`?e.sgWindowSize:512,sgOverlap:typeof e.sgOverlap==`number`?e.sgOverlap:.5,sgWinFunc:e.sgWinFunc===`rectangular`?`rectangular`:`hann`,sgYMode:e.sgYMode===`amplitude`?`amplitude`:`db`,sgLogFreq:e.sgLogFreq===!0,...e.sgView===`waterfall`?{sgView:`waterfall`}:{}}}else if(n&&typeof n==`object`&&n.kind===`heatmap`){let e=n,i=Array.isArray(e.hmColumns)?e.hmColumns.filter(e=>typeof e==`string`):[],a=e=>Math.max(1,Math.min(50,typeof e==`number`&&Number.isFinite(e)?Math.floor(e):6)),o=e=>typeof e==`string`?e:``;r[t]={kind:`heatmap`,hmMode:e.hmMode===`raw`||e.hmMode===`binned`||e.hmMode===`count`||e.hmMode===`correlation`||e.hmMode===`matrix`?e.hmMode:`binned`,hmColumns:i,hmXCol:o(e.hmXCol),hmYCol:o(e.hmYCol),hmValueCol:o(e.hmValueCol),hmXBins:a(e.hmXBins),hmYBins:a(e.hmYBins),hmXMin:o(e.hmXMin),hmXMax:o(e.hmXMax),hmYMin:o(e.hmYMin),hmYMax:o(e.hmYMax),hmShowValues:e.hmShowValues!==!1,hmColorScheme:e.hmColorScheme===`plasma`||e.hmColorScheme===`viridis`?e.hmColorScheme:`diverging`,...e.hmSpacing===`values`?{hmSpacing:`values`}:{},...typeof e.hmContours==`number`&&e.hmContours>=1?{hmContours:Math.min(20,Math.round(e.hmContours))}:{},...e.hmRange&&typeof e.hmRange==`object`?{hmRange:{scaleMin:typeof e.hmRange.scaleMin==`string`?e.hmRange.scaleMin:``,scaleMax:typeof e.hmRange.scaleMax==`string`?e.hmRange.scaleMax:``}}:{}}}else if(n&&typeof n==`object`&&n.kind===`violin`){let e=n;r[t]={kind:`violin`,vlValueCol:typeof e.vlValueCol==`string`?e.vlValueCol:``,vlGroupCol:typeof e.vlGroupCol==`string`?e.vlGroupCol:``,vlColor:typeof e.vlColor==`string`?e.vlColor:`#818cf8`,vlShowBox:e.vlShowBox!==!1,vlBandwidth:typeof e.vlBandwidth==`string`?e.vlBandwidth:``,vlOrientation:e.vlOrientation===`horizontal`?`horizontal`:`vertical`}}else if(n&&typeof n==`object`&&n.kind===`confusion`){let e=n;r[t]={kind:`confusion`,cfActualCol:typeof e.cfActualCol==`string`?e.cfActualCol:``,cfPredictedCol:typeof e.cfPredictedCol==`string`?e.cfPredictedCol:``,cfNormalize:e.cfNormalize===!0}}else if(n&&typeof n==`object`&&n.kind===`roc`){let e=n;r[t]={kind:`roc`,rocScoreCol:typeof e.rocScoreCol==`string`?e.rocScoreCol:``,rocLabelCol:typeof e.rocLabelCol==`string`?e.rocLabelCol:``,rocMode:e.rocMode===`pr`?`pr`:`roc`,rocColor:typeof e.rocColor==`string`?e.rocColor:`#f472b6`}}else if(n&&typeof n==`object`&&n.kind===`losscurve`){let e=n,i=e=>Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.column==`string`&&typeof e.color==`string`):[];r[t]={kind:`losscurve`,lcXCol:typeof e.lcXCol==`string`?e.lcXCol:``,lcLeftCols:i(e.lcLeftCols),lcRightCols:i(e.lcRightCols)}}else if(n&&typeof n==`object`&&n.kind===`controlchart`){let e=n;r[t]={kind:`controlchart`,ccValueCol:typeof e.ccValueCol==`string`?e.ccValueCol:``,ccSubgroupCol:typeof e.ccSubgroupCol==`string`?e.ccSubgroupCol:``,ccSigmaLevel:typeof e.ccSigmaLevel==`number`?e.ccSigmaLevel:3,ccColor:typeof e.ccColor==`string`?e.ccColor:`#22d3ee`}}else if(n&&typeof n==`object`&&n.kind===`parallelcoords`){let e=n;r[t]={kind:`parallelcoords`,pcColumns:Array.isArray(e.pcColumns)?e.pcColumns.filter(e=>typeof e==`string`):[],pcColorByCol:typeof e.pcColorByCol==`string`?e.pcColorByCol:``,pcColor:typeof e.pcColor==`string`?e.pcColor:`#64748b`}}else if(n&&typeof n==`object`&&n.kind===`embedding`){let e=n;r[t]={kind:`embedding`,emXCol:typeof e.emXCol==`string`?e.emXCol:``,emYCol:typeof e.emYCol==`string`?e.emYCol:``,emColorCol:typeof e.emColorCol==`string`?e.emColorCol:``,emColorMode:e.emColorMode===`numeric`?`numeric`:`categorical`,emLabelCol:typeof e.emLabelCol==`string`?e.emLabelCol:``,emPointSize:typeof e.emPointSize==`number`?e.emPointSize:3,emColor:typeof e.emColor==`string`?e.emColor:`#a78bfa`}}else if(n&&typeof n==`object`&&n.kind===`flamegraph`){let e=n;r[t]={kind:`flamegraph`,fgNameCol:typeof e.fgNameCol==`string`?e.fgNameCol:``,fgParentCol:typeof e.fgParentCol==`string`?e.fgParentCol:``,fgValueCol:typeof e.fgValueCol==`string`?e.fgValueCol:``,fgDirection:e.fgDirection===`bottomup`?`bottomup`:`topdown`}}else if(n&&typeof n==`object`&&n.kind===`barchart`){let e=n,i=Array.isArray(e.bcValueCols)?e.bcValueCols.filter(e=>typeof e==`string`):[],a=e.bcValueScale;r[t]={kind:`barchart`,bcCategoryCol:typeof e.bcCategoryCol==`string`?e.bcCategoryCol:``,bcValueCols:i,bcMode:e.bcMode===`stacked`?`stacked`:`grouped`,bcHorizontal:e.bcHorizontal===!0,...a&&typeof a==`object`?{bcValueScale:{scaleMin:typeof a.scaleMin==`string`?a.scaleMin:``,scaleMax:typeof a.scaleMax==`string`?a.scaleMax:``}}:{}}}else if(n&&typeof n==`object`&&n.kind===`radar`){let e=n;r[t]={kind:`radar`,rdAxesCols:Array.isArray(e.rdAxesCols)?e.rdAxesCols.filter(e=>typeof e==`string`):[],rdGroupCol:typeof e.rdGroupCol==`string`?e.rdGroupCol:``,rdColor:typeof e.rdColor==`string`?e.rdColor:`#38bdf8`,rdFill:e.rdFill!==!1}}else if(n&&typeof n==`object`&&n.kind===`areachart`){let e=n,i=Array.isArray(e.acYCols)?e.acYCols.filter(e=>typeof e==`string`):[],a=e.acYScale;r[t]={kind:`areachart`,acXCol:typeof e.acXCol==`string`?e.acXCol:``,acYCols:i,acStacked:e.acStacked===!0,...a&&typeof a==`object`?{acYScale:{scaleMin:typeof a.scaleMin==`string`?a.scaleMin:``,scaleMax:typeof a.scaleMax==`string`?a.scaleMax:``}}:{}}}else if(n&&typeof n==`object`&&n.kind===`cdfchart`){let e=n;r[t]={kind:`cdfchart`,cdValueCols:Array.isArray(e.cdValueCols)?e.cdValueCols.filter(e=>typeof e==`string`):[],cdComplement:e.cdComplement===!0,cdLogX:e.cdLogX===!0}}else if(n&&typeof n==`object`&&n.kind===`bubblechart`){let e=n;r[t]={kind:`bubblechart`,bbXCol:typeof e.bbXCol==`string`?e.bbXCol:``,bbYCol:typeof e.bbYCol==`string`?e.bbYCol:``,bbSizeCol:typeof e.bbSizeCol==`string`?e.bbSizeCol:``,bbColorCol:typeof e.bbColorCol==`string`?e.bbColorCol:``,bbColorMode:e.bbColorMode===`numeric`?`numeric`:`categorical`,bbColor:typeof e.bbColor==`string`?e.bbColor:`#64748b`,bbMaxRadius:typeof e.bbMaxRadius==`number`?e.bbMaxRadius:24}}else if(n&&typeof n==`object`&&n.kind===`treemap`){let e=n;r[t]={kind:`treemap`,tmNameCol:typeof e.tmNameCol==`string`?e.tmNameCol:``,tmParentCol:typeof e.tmParentCol==`string`?e.tmParentCol:``,tmValueCol:typeof e.tmValueCol==`string`?e.tmValueCol:``}}else if(n&&typeof n==`object`&&n.kind===`sankey`){let e=n;r[t]={kind:`sankey`,skSourceCol:typeof e.skSourceCol==`string`?e.skSourceCol:``,skTargetCol:typeof e.skTargetCol==`string`?e.skTargetCol:``,skValueCol:typeof e.skValueCol==`string`?e.skValueCol:``}}else if(n&&typeof n==`object`&&n.kind===`gauge`){let e=n;r[t]={kind:`gauge`,ggGauges:Array.isArray(e.ggGauges)?e.ggGauges.flatMap((e,t)=>{let n=L(e,t);return n?[n]:[]}):[]}}else if(n&&typeof n==`object`&&n.kind===`calibration`){let e=n;r[t]={kind:`calibration`,cbScoreCol:typeof e.cbScoreCol==`string`?e.cbScoreCol:``,cbLabelCol:typeof e.cbLabelCol==`string`?e.cbLabelCol:``,cbBins:typeof e.cbBins==`number`?e.cbBins:10,cbColor:typeof e.cbColor==`string`?e.cbColor:`#38bdf8`}}else if(n&&typeof n==`object`&&n.kind===`qqplot`){let e=n;r[t]={kind:`qqplot`,qqValueCol:typeof e.qqValueCol==`string`?e.qqValueCol:``,qqMode:e.qqMode===`column`?`column`:`normal`,qqRefCol:typeof e.qqRefCol==`string`?e.qqRefCol:``,qqColor:typeof e.qqColor==`string`?e.qqColor:`#a78bfa`}}else if(n&&typeof n==`object`&&n.kind===`gantt`){let e=n;r[t]={kind:`gantt`,gtLabelCol:typeof e.gtLabelCol==`string`?e.gtLabelCol:``,gtStartCol:typeof e.gtStartCol==`string`?e.gtStartCol:``,gtEndCol:typeof e.gtEndCol==`string`?e.gtEndCol:``,gtGroupCol:typeof e.gtGroupCol==`string`?e.gtGroupCol:``}}let e=r[t]?y(n?.annotations):null;e?.length&&(r[t]={...r[t],annotations:e});let i=r[t]?ke[r[t].kind]:void 0,a=i?Oe(n[i]):null;i&&a&&(r[t]={...r[t],[i]:a})}return r}function Ne(e,t,n,r){let i={...t},a=!1;for(let t of e)if(t.kind===`multiband`){let e=i[t.id];(!e||e.kind!==`multiband`)&&(i[t.id]=B(),a=!0)}else if(t.kind===`xyscatter`){let e=i[t.id];(!e||e.kind!==`xyscatter`)&&(i[t.id]=V(n),a=!0)}else if(t.kind===`xyzmesh`){let e=i[t.id];(!e||e.kind!==`xyzmesh`)&&(i[t.id]=H(r),a=!0)}else if(t.kind===`histogram`){let e=i[t.id];(!e||e.kind!==`histogram`)&&(i[t.id]=U(),a=!0)}else if(t.kind===`polar`){let e=i[t.id];(!e||e.kind!==`polar`)&&(i[t.id]=W(),a=!0)}else if(t.kind===`spectrum`){let e=i[t.id];(!e||e.kind!==`spectrum`)&&(i[t.id]=ee(),a=!0)}else if(t.kind===`boxplot`){let e=i[t.id];(!e||e.kind!==`boxplot`)&&(i[t.id]=te(),a=!0)}else t.kind===`spectrogram`?(!i[t.id]||i[t.id].kind!==`spectrogram`)&&(i[t.id]=ne(),a=!0):t.kind===`heatmap`?(!i[t.id]||i[t.id].kind!==`heatmap`)&&(i[t.id]=G(),a=!0):t.kind===`violin`?(!i[t.id]||i[t.id].kind!==`violin`)&&(i[t.id]=re(),a=!0):t.kind===`confusion`?(!i[t.id]||i[t.id].kind!==`confusion`)&&(i[t.id]=ie(),a=!0):t.kind===`roc`?(!i[t.id]||i[t.id].kind!==`roc`)&&(i[t.id]=ae(),a=!0):t.kind===`losscurve`?(!i[t.id]||i[t.id].kind!==`losscurve`)&&(i[t.id]=oe(),a=!0):t.kind===`controlchart`?(!i[t.id]||i[t.id].kind!==`controlchart`)&&(i[t.id]=se(),a=!0):t.kind===`parallelcoords`?(!i[t.id]||i[t.id].kind!==`parallelcoords`)&&(i[t.id]=ce(),a=!0):t.kind===`embedding`?(!i[t.id]||i[t.id].kind!==`embedding`)&&(i[t.id]=le(),a=!0):t.kind===`flamegraph`?(!i[t.id]||i[t.id].kind!==`flamegraph`)&&(i[t.id]=ue(),a=!0):t.kind===`barchart`?(!i[t.id]||i[t.id].kind!==`barchart`)&&(i[t.id]=de(),a=!0):t.kind===`radar`?(!i[t.id]||i[t.id].kind!==`radar`)&&(i[t.id]=fe(),a=!0):t.kind===`areachart`?(!i[t.id]||i[t.id].kind!==`areachart`)&&(i[t.id]=pe(),a=!0):t.kind===`cdfchart`?(!i[t.id]||i[t.id].kind!==`cdfchart`)&&(i[t.id]=me(),a=!0):t.kind===`bubblechart`?(!i[t.id]||i[t.id].kind!==`bubblechart`)&&(i[t.id]=he(),a=!0):t.kind===`treemap`?(!i[t.id]||i[t.id].kind!==`treemap`)&&(i[t.id]=ge(),a=!0):t.kind===`sankey`?(!i[t.id]||i[t.id].kind!==`sankey`)&&(i[t.id]=_e(),a=!0):t.kind===`gauge`?(!i[t.id]||i[t.id].kind!==`gauge`)&&(i[t.id]=ve(),a=!0):t.kind===`calibration`?(!i[t.id]||i[t.id].kind!==`calibration`)&&(i[t.id]=ye(),a=!0):t.kind===`qqplot`?(!i[t.id]||i[t.id].kind!==`qqplot`)&&(i[t.id]=be(),a=!0):t.kind===`gantt`&&(!i[t.id]||i[t.id].kind!==`gantt`)&&(i[t.id]=xe(),a=!0);for(let t of Object.keys(i))e.some(e=>e.id===t)||(delete i[t],a=!0);return a?i:t}function Pe(){return crypto.randomUUID()}function Fe(e={}){let t=Date.now();return{id:crypto.randomUUID(),name:``,units:``,formula:``,enabled:!0,createdAt:t,updatedAt:t,source:`personal`,sharedWithOrgId:null,projectId:null,ownerUserId:``,ownerDisplayName:null,ownerLastName:null,...e}}function Ie(e){return Ve.get(e)}function Le(e,t){let n=e.keys.lastIndexOf(t);return n<0?void 0:e.values[n]}function Re(e,t){let n=e.keys.join(`
|
|
2
|
+
var __kymoscopeScriptUrl=document.currentScript&&document.currentScript.src||location.href,Kymoscope=(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:`Module`});var n=Object.create,r=Object.defineProperty,i=Object.getOwnPropertyDescriptor,a=Object.getOwnPropertyNames,o=Object.getPrototypeOf,s=Object.prototype.hasOwnProperty,c=(e,t)=>()=>(e&&(t=e(e=0)),t),l=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),u=(e,t)=>{let n={};for(var i in e)r(n,i,{get:e[i],enumerable:!0});return t||r(n,Symbol.toStringTag,{value:`Module`}),n},d=(e,t,n,o)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var c=a(t),l=0,u=c.length,d;l<u;l++)d=c[l],!s.call(e,d)&&d!==n&&r(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(o=i(t,d))||o.enumerable});return e},f=(e,t,i)=>(i=e==null?{}:n(o(e)),d(t||!e||!e.__esModule?r(i,`default`,{value:e,enumerable:!0}):i,e)),p=[`text`,`brush`,`arrow`,`box`],m={text:14,brush:3,arrow:2,box:2},h=/^#[0-9a-fA-F]{6}$/,g={text:[1,1],arrow:[2,2],box:[2,2],brush:[2,1/0]},_=e=>typeof e==`number`&&Number.isFinite(e);function v(e){if(!e||typeof e!=`object`)return null;let t=e,n=t.kind;if(!p.includes(n)||typeof t.id!=`string`||!t.id||!Array.isArray(t.points))return null;let r=t.points.filter(e=>Array.isArray(e)&&_(e[0])&&_(e[1])).map(([e,t])=>[e,t]),[i,a]=g[n];return r.length<i||r.length>a?null:{id:t.id,kind:n,points:r,...t.anchor===`x`?{anchor:`x`}:{},color:typeof t.color==`string`&&h.test(t.color)?t.color:`#f5a524`,width:_(t.width)&&t.width>0?Math.min(96,t.width):m[n],...typeof t.text==`string`&&t.text!==``?{text:t.text}:{}}}function y(e){return Array.isArray(e)?e.map(v).filter(e=>e!==null):null}var b={multiband:6,xyscatter:6,xyzmesh:6,histogram:6,polar:6,spectrum:6,boxplot:6,spectrogram:6,heatmap:6,violin:6,confusion:6,roc:6,losscurve:6,controlchart:6,parallelcoords:6,embedding:6,flamegraph:6,barchart:6,radar:6,areachart:6,cdfchart:6,bubblechart:6,treemap:6,sankey:6,calibration:6,qqplot:6,gantt:6,gauge:6},x={multiband:24,xyscatter:24,xyzmesh:24,histogram:24,polar:24,spectrum:24,boxplot:24,spectrogram:24,heatmap:24,violin:24,confusion:24,roc:24,losscurve:24,controlchart:24,parallelcoords:24,embedding:24,flamegraph:24,barchart:24,radar:24,areachart:24,cdfchart:24,bubblechart:24,treemap:24,sankey:24,calibration:24,qqplot:24,gantt:24,gauge:24},S=b;function C(e,t){return e.x<t.x+t.w&&t.x<e.x+e.w&&e.y<t.y+t.h&&t.y<e.y+e.h}function w(e,t,n,r=96){let i=b[e],a=x[e],o=Math.max(i,Math.min(t.w,n-Math.max(0,t.x))),s=Math.max(a,Math.min(t.h,r-Math.max(0,t.y)));return{x:Math.max(0,Math.min(t.x,n-o)),y:Math.max(0,Math.min(t.y,r-s)),w:o,h:s}}function T(e,t,n){for(let r of t)if(r.id!==n&&C(e,r.rect))return!0;return!1}function E(e,t,n=96){let r=b[e],i=x[e],a=Math.min(48,n),o=e===`multiband`||e===`xyzmesh`?64:48;for(let i=0;i<384;i+=8)for(let s=0;s<=n-r;s+=8){let r=w(e,{x:s,y:i,w:a,h:o},n);if(!T(r,t,``))return r}return w(e,{x:0,y:0,w:r,h:i},n)}function D(e,t){return{id:crypto.randomUUID(),kind:e,rect:E(e,t)}}function O(e){if(e<=0)return[];if(e===1)return[{x:0,y:0,w:1,h:1}];if(e===2)return[{x:0,y:0,w:.5,h:1},{x:.5,y:0,w:.5,h:1}];if(e===3)return[{x:0,y:0,w:.5,h:.5},{x:.5,y:0,w:.5,h:.5},{x:0,y:.5,w:1,h:.5}];if(e===4)return[{x:0,y:0,w:.5,h:.5},{x:.5,y:0,w:.5,h:.5},{x:0,y:.5,w:.5,h:.5},{x:.5,y:.5,w:.5,h:.5}];let t=O(e-4).map(e=>({x:e.x*.5,y:e.y,w:e.w*.5,h:e.h})),n=O(4).map(e=>({x:.5+e.x*.5,y:e.y,w:e.w*.5,h:e.h}));return[...t,...n]}function k(e,t=96,n=96){let r=O(e.length);return e.map((e,i)=>{let a=r[i];if(!a)return e;let o=Math.round(a.x*t),s=Math.round(a.y*n),c=Math.max(1,Math.round(a.w*t)),l=Math.max(1,Math.round(a.h*n));return{...e,rect:{x:o,y:s,w:c,h:l}}})}function A(){return{scaleMin:``,scaleMax:``,majorStep:``,minorStep:``,alarm:null}}var j={style:`dashed`,width:1,color:null},M={style:`solid`,width:1,color:null},N={enabled:!1,reference:`previous`,datasetId:null,datasetColor:`#94a3b8`,previousColor:`#64748b`},P=/^#[0-9a-f]{6}$/i;function F(e){if(!e||typeof e!=`object`)return;let t=e;return{enabled:t.enabled===!0,reference:t.reference===`dataset`||t.reference===`none`?t.reference:`previous`,datasetId:typeof t.datasetId==`string`&&t.datasetId?t.datasetId:null,datasetColor:typeof t.datasetColor==`string`&&P.test(t.datasetColor)?t.datasetColor:N.datasetColor,previousColor:typeof t.previousColor==`string`&&P.test(t.previousColor)?t.previousColor:N.previousColor}}var I=[`#f5a524`,`#38bdf8`,`#22c55e`,`#f472b6`,`#a78bfa`,`#fb7185`];function L(e,t){if(!e||typeof e!=`object`)return null;let n=e;if(typeof n.column!=`string`)return null;let r=Oe(n.alarm);return{id:typeof n.id==`string`&&n.id?n.id:`g${t}`,column:n.column,color:typeof n.color==`string`?n.color:I[t%I.length],value:n.value===`mean`||n.value===`min`||n.value===`max`?n.value:`last`,style:n.style===`linear`?`linear`:`arc`,...n.fill===`zero`?{fill:`zero`}:{},min:typeof n.min==`string`?n.min:``,max:typeof n.max==`string`?n.max:``,...r?{alarm:r}:{},...n.colorMode===`gradient`||n.colorMode===`zones`?{colorMode:n.colorMode}:{},...Array.isArray(n.stops)?{stops:n.stops.flatMap(e=>{let t=e;return t&&typeof t.at==`number`&&Number.isFinite(t.at)&&typeof t.color==`string`?[{at:t.at,color:t.color}]:[]})}:{}}}function R(e,t){let n=parseFloat(e),r=parseFloat(t);return Number.isFinite(n)&&Number.isFinite(r)&&n<r?[n,r]:void 0}var z=1.8;function B(){return{kind:`multiband`,series:[],addColumn:``,layout:`overlay`,xAxisLine:{...j},yAxisLine:{...j},gridLine:{...M},lineWidth:1}}function V(e){return{kind:`xyscatter`,xyXCol:``,xyYCol:``,xyColorCol:null,xyColor:e,xyPointRadius:z,xyXAxisLine:{...j},xyYAxisLine:{...j},xyGridLine:{...M},xyFit:null,xyXScale:A(),xyYScale:A()}}function H(e=4){return{kind:`xyzmesh`,xyzXCol:``,xyzYCol:``,xyzZCol:``,xyzViewMode:`3d`,xyzXScale:A(),xyzYScale:A(),xyzZScale:A(),xyzPointRadius:e,showMesh:!1,meshStyle:`filled`,meshOpacity:.85}}function U(){return{kind:`histogram`,histColumn:``,histBins:0,histColor:`#38bdf8`,histNormal:!1,histLogY:!1}}function W(){return{kind:`polar`,polarAngleCol:``,polarRadiusCol:``,polarColor:`#a78bfa`,polarMode:`waveform`,polarRadiusMin:``,polarRadiusMax:``}}function ee(){return{kind:`spectrum`,specSignalCol:``,specTimeCol:``,specSampleRate:`1000`,specXMode:`hz`,specYMode:`amplitude`,specWindow:`hann`,specColor:`#34d399`,specLogX:!1}}function te(){return{kind:`boxplot`,boxValueCol:``,boxGroupCol:``,boxColor:`#fb923c`,boxWhiskers:`1.5iqr`}}function ne(){return{kind:`spectrogram`,sgSignalCol:``,sgTimeCol:``,sgSampleRate:`1000`,sgWindowSize:512,sgOverlap:.5,sgWinFunc:`hann`,sgYMode:`db`,sgLogFreq:!1}}function G(){return{kind:`heatmap`,hmMode:`binned`,hmColumns:[],hmXCol:``,hmYCol:``,hmValueCol:``,hmXBins:6,hmYBins:6,hmXMin:``,hmXMax:``,hmYMin:``,hmYMax:``,hmShowValues:!0,hmColorScheme:`diverging`}}function re(){return{kind:`violin`,vlValueCol:``,vlGroupCol:``,vlColor:`#818cf8`,vlShowBox:!0,vlBandwidth:``,vlOrientation:`vertical`}}function ie(){return{kind:`confusion`,cfActualCol:``,cfPredictedCol:``,cfNormalize:!1}}function ae(){return{kind:`roc`,rocScoreCol:``,rocLabelCol:``,rocMode:`roc`,rocColor:`#f472b6`}}function oe(){return{kind:`losscurve`,lcXCol:``,lcLeftCols:[],lcRightCols:[]}}function se(){return{kind:`controlchart`,ccValueCol:``,ccSubgroupCol:``,ccSigmaLevel:3,ccColor:`#22d3ee`}}function ce(){return{kind:`parallelcoords`,pcColumns:[],pcColorByCol:``,pcColor:`#64748b`}}function le(){return{kind:`embedding`,emXCol:``,emYCol:``,emColorCol:``,emColorMode:`categorical`,emLabelCol:``,emPointSize:3,emColor:`#a78bfa`}}function ue(){return{kind:`flamegraph`,fgNameCol:``,fgParentCol:``,fgValueCol:``,fgDirection:`topdown`}}function de(){return{kind:`barchart`,bcCategoryCol:``,bcValueCols:[],bcMode:`grouped`,bcHorizontal:!1}}function fe(){return{kind:`radar`,rdAxesCols:[],rdGroupCol:``,rdColor:`#38bdf8`,rdFill:!0}}function pe(){return{kind:`areachart`,acXCol:``,acYCols:[],acStacked:!1}}function me(){return{kind:`cdfchart`,cdValueCols:[],cdComplement:!1,cdLogX:!1}}function he(){return{kind:`bubblechart`,bbXCol:``,bbYCol:``,bbSizeCol:``,bbColorCol:``,bbColorMode:`categorical`,bbColor:`#64748b`,bbMaxRadius:24}}function ge(){return{kind:`treemap`,tmNameCol:``,tmParentCol:``,tmValueCol:``}}function _e(){return{kind:`sankey`,skSourceCol:``,skTargetCol:``,skValueCol:``}}function ve(){return{kind:`gauge`,ggGauges:[]}}function ye(){return{kind:`calibration`,cbScoreCol:``,cbLabelCol:``,cbBins:10,cbColor:`#38bdf8`}}function be(){return{kind:`qqplot`,qqValueCol:``,qqMode:`normal`,qqRefCol:``,qqColor:`#a78bfa`}}function xe(){return{kind:`gantt`,gtLabelCol:``,gtStartCol:``,gtEndCol:``,gtGroupCol:``}}function Se(e){if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.id==`string`&&typeof t.column==`string`&&typeof t.color==`string`&&typeof t.bandFromPct==`number`&&typeof t.bandToPct==`number`&&typeof t.scaleMin==`number`&&typeof t.scaleMax==`number`&&typeof t.yMajorStep==`number`&&typeof t.yMinorStep==`number`}function Ce(e){if(!e||typeof e!=`object`)return!1;let t=e;return(t.style===`none`||t.style===`solid`||t.style===`dashed`||t.style===`dotted`)&&typeof t.width==`number`&&(t.color===null||typeof t.color==`string`)}function we(e,t){return Ce(e)?e:{...t}}function Te(e){if(!e||typeof e!=`object`)return!1;let t=e;return t.kind===`multiband`&&Array.isArray(t.series)&&t.series.every(Se)&&typeof t.addColumn==`string`}function Ee(e){if(!e||typeof e!=`object`)return!1;let t=e;return t.kind===`xyscatter`&&typeof t.xyXCol==`string`&&typeof t.xyYCol==`string`&&typeof t.xyColor==`string`&&typeof t.xyPointRadius==`number`}function De(e){if(!e||typeof e!=`object`)return!1;let t=e,n=t.xyzViewMode,r=n===`3d`||n===`xy`||n===`xz`||n===`yz`;return t.kind===`xyzmesh`&&typeof t.xyzXCol==`string`&&typeof t.xyzYCol==`string`&&typeof t.xyzZCol==`string`&&r&&typeof t.xyzPointRadius==`number`}function Oe(e){if(!e||typeof e!=`object`)return null;let t=e;return typeof t.value!=`number`||!Number.isFinite(t.value)||t.style!==`solid`&&t.style!==`dashed`&&t.style!==`dotted`||typeof t.width!=`number`||typeof t.color!=`string`?null:{value:t.value,style:t.style,width:t.width,color:t.color}}var ke={histogram:`histAlarm`,spectrum:`specAlarm`,areachart:`acAlarm`,losscurve:`lcAlarm`,cdfchart:`cdAlarm`,bubblechart:`bbAlarm`,boxplot:`boxAlarm`,violin:`vlAlarm`,barchart:`bcAlarm`,gantt:`gtAlarm`};function Ae(e){if(!e||!(e.kind in ke))return null;let t=e[ke[e.kind]];return t?{alarm:t,axis:e.kind===`histogram`||e.kind===`cdfchart`||e.kind===`gantt`||e.kind===`barchart`&&e.bcHorizontal||e.kind===`violin`&&e.vlOrientation===`horizontal`?`x`:`y`}:null}function je(e){let t=A();if(!e||typeof e!=`object`)return t;let n=e,r=Oe(n.alarm);return{scaleMin:typeof n.scaleMin==`string`?n.scaleMin:t.scaleMin,scaleMax:typeof n.scaleMax==`string`?n.scaleMax:t.scaleMax,majorStep:typeof n.majorStep==`string`?n.majorStep:t.majorStep,minorStep:typeof n.minorStep==`string`?n.minorStep:t.minorStep,alarm:r}}function Me(e,t,n){if(!e||typeof e!=`object`)return{};let r={};for(let[t,n]of Object.entries(e)){if(!t||typeof t!=`string`)continue;if(Te(n)){let e=n;r[t]={kind:`multiband`,series:e.series,addColumn:e.addColumn,layout:e.layout===`parallel`?`parallel`:`overlay`,xAxisLine:we(e.xAxisLine,j),yAxisLine:we(e.yAxisLine,j),gridLine:we(e.gridLine,M),lineWidth:typeof e.lineWidth==`number`&&Number.isFinite(e.lineWidth)?Math.min(6,Math.max(.5,e.lineWidth)):1,...F(e.beacon)?{beacon:F(e.beacon)}:{},...e.envelope===!0?{envelope:!0}:{}}}else if(Ee(n)){let e=n,i=e.xyFit,a=i&&typeof i==`object`&&(i.degree===1||i.degree===2||i.degree===3)&&typeof i.color==`string`&&(i.lineStyle===`solid`||i.lineStyle===`dashed`||i.lineStyle===`dotted`)&&typeof i.width==`number`?{degree:i.degree,color:i.color,lineStyle:i.lineStyle,width:i.width}:null;r[t]={...n,xyColorCol:typeof e.xyColorCol==`string`?e.xyColorCol:null,xyPointRadius:Math.min(16,Math.max(.5,n.xyPointRadius)),xyDrawMode:e.xyDrawMode===`lines`||e.xyDrawMode===`both`?e.xyDrawMode:void 0,xyLineWidth:typeof e.xyLineWidth==`number`&&Number.isFinite(e.xyLineWidth)?Math.min(8,Math.max(.5,e.xyLineWidth)):void 0,xyXAxisLine:we(e.xyXAxisLine,j),xyYAxisLine:we(e.xyYAxisLine,j),xyGridLine:we(e.xyGridLine,M),xyFit:a,xyXScale:je(e.xyXScale),xyYScale:je(e.xyYScale)}}else if(De(n)){let e=e=>typeof e==`string`?e:``,i=n.xyzXScale?null:{scaleMin:e(n.xyzXMin),scaleMax:e(n.xyzXMax),majorStep:``,minorStep:``,alarm:null},a=n.xyzYScale?null:{scaleMin:e(n.xyzYMin),scaleMax:e(n.xyzYMax),majorStep:``,minorStep:``,alarm:null},o=n.xyzZScale?null:{scaleMin:e(n.xyzZMin),scaleMax:e(n.xyzZMax),majorStep:``,minorStep:``,alarm:null};r[t]={kind:`xyzmesh`,xyzXCol:n.xyzXCol,xyzYCol:n.xyzYCol,xyzZCol:n.xyzZCol,xyzViewMode:n.xyzViewMode,xyzXScale:i??je(n.xyzXScale),xyzYScale:a??je(n.xyzYScale),xyzZScale:o??je(n.xyzZScale),xyzPointRadius:Math.min(16,Math.max(.5,n.xyzPointRadius)),showMesh:n.showMesh===!0,meshStyle:n.meshStyle===`wireframe`||n.meshStyle===`both`?n.meshStyle:`filled`,meshOpacity:typeof n.meshOpacity==`number`&&n.meshOpacity>=0&&n.meshOpacity<=1?n.meshOpacity:.85,...n.xyzMode===`matrix`?{xyzMode:`matrix`}:{},...Array.isArray(n.xyzColumns)?{xyzColumns:n.xyzColumns.filter(e=>typeof e==`string`)}:{}}}else if(n&&typeof n==`object`&&n.kind===`histogram`){let e=n;r[t]={kind:`histogram`,histColumn:typeof e.histColumn==`string`?e.histColumn:``,histBins:typeof e.histBins==`number`?e.histBins:0,histColor:typeof e.histColor==`string`?e.histColor:`#38bdf8`,histNormal:e.histNormal===!0,histLogY:e.histLogY===!0}}else if(n&&typeof n==`object`&&n.kind===`polar`){let e=n;r[t]={kind:`polar`,polarAngleCol:typeof e.polarAngleCol==`string`?e.polarAngleCol:``,polarRadiusCol:typeof e.polarRadiusCol==`string`?e.polarRadiusCol:``,polarColor:typeof e.polarColor==`string`?e.polarColor:`#a78bfa`,polarMode:e.polarMode===`rose`?`rose`:`waveform`,polarRadiusMin:typeof e.polarRadiusMin==`string`?e.polarRadiusMin:``,polarRadiusMax:typeof e.polarRadiusMax==`string`?e.polarRadiusMax:``}}else if(n&&typeof n==`object`&&n.kind===`spectrum`){let e=n;r[t]={kind:`spectrum`,specSignalCol:typeof e.specSignalCol==`string`?e.specSignalCol:``,specTimeCol:typeof e.specTimeCol==`string`?e.specTimeCol:``,specSampleRate:typeof e.specSampleRate==`string`?e.specSampleRate:`1000`,specXMode:e.specXMode===`order`?`order`:`hz`,specYMode:e.specYMode===`db`?`db`:`amplitude`,specWindow:e.specWindow===`rectangular`?`rectangular`:`hann`,specColor:typeof e.specColor==`string`?e.specColor:`#34d399`,specLogX:e.specLogX===!0}}else if(n&&typeof n==`object`&&n.kind===`boxplot`){let e=n;r[t]={kind:`boxplot`,boxValueCol:typeof e.boxValueCol==`string`?e.boxValueCol:``,boxGroupCol:typeof e.boxGroupCol==`string`?e.boxGroupCol:``,boxColor:typeof e.boxColor==`string`?e.boxColor:`#fb923c`,boxWhiskers:e.boxWhiskers===`minmax`?`minmax`:`1.5iqr`}}else if(n&&typeof n==`object`&&n.kind===`spectrogram`){let e=n;r[t]={kind:`spectrogram`,sgSignalCol:typeof e.sgSignalCol==`string`?e.sgSignalCol:``,sgTimeCol:typeof e.sgTimeCol==`string`?e.sgTimeCol:``,sgSampleRate:typeof e.sgSampleRate==`string`?e.sgSampleRate:`1000`,sgWindowSize:typeof e.sgWindowSize==`number`?e.sgWindowSize:512,sgOverlap:typeof e.sgOverlap==`number`?e.sgOverlap:.5,sgWinFunc:e.sgWinFunc===`rectangular`?`rectangular`:`hann`,sgYMode:e.sgYMode===`amplitude`?`amplitude`:`db`,sgLogFreq:e.sgLogFreq===!0,...e.sgView===`waterfall`?{sgView:`waterfall`}:{}}}else if(n&&typeof n==`object`&&n.kind===`heatmap`){let e=n,i=Array.isArray(e.hmColumns)?e.hmColumns.filter(e=>typeof e==`string`):[],a=e=>Math.max(1,Math.min(50,typeof e==`number`&&Number.isFinite(e)?Math.floor(e):6)),o=e=>typeof e==`string`?e:``;r[t]={kind:`heatmap`,hmMode:e.hmMode===`raw`||e.hmMode===`binned`||e.hmMode===`count`||e.hmMode===`correlation`||e.hmMode===`matrix`?e.hmMode:`binned`,hmColumns:i,hmXCol:o(e.hmXCol),hmYCol:o(e.hmYCol),hmValueCol:o(e.hmValueCol),hmXBins:a(e.hmXBins),hmYBins:a(e.hmYBins),hmXMin:o(e.hmXMin),hmXMax:o(e.hmXMax),hmYMin:o(e.hmYMin),hmYMax:o(e.hmYMax),hmShowValues:e.hmShowValues!==!1,hmColorScheme:e.hmColorScheme===`plasma`||e.hmColorScheme===`viridis`?e.hmColorScheme:`diverging`,...e.hmSpacing===`values`?{hmSpacing:`values`}:{},...typeof e.hmContours==`number`&&e.hmContours>=1?{hmContours:Math.min(20,Math.round(e.hmContours))}:{},...e.hmRange&&typeof e.hmRange==`object`?{hmRange:{scaleMin:typeof e.hmRange.scaleMin==`string`?e.hmRange.scaleMin:``,scaleMax:typeof e.hmRange.scaleMax==`string`?e.hmRange.scaleMax:``}}:{}}}else if(n&&typeof n==`object`&&n.kind===`violin`){let e=n;r[t]={kind:`violin`,vlValueCol:typeof e.vlValueCol==`string`?e.vlValueCol:``,vlGroupCol:typeof e.vlGroupCol==`string`?e.vlGroupCol:``,vlColor:typeof e.vlColor==`string`?e.vlColor:`#818cf8`,vlShowBox:e.vlShowBox!==!1,vlBandwidth:typeof e.vlBandwidth==`string`?e.vlBandwidth:``,vlOrientation:e.vlOrientation===`horizontal`?`horizontal`:`vertical`}}else if(n&&typeof n==`object`&&n.kind===`confusion`){let e=n;r[t]={kind:`confusion`,cfActualCol:typeof e.cfActualCol==`string`?e.cfActualCol:``,cfPredictedCol:typeof e.cfPredictedCol==`string`?e.cfPredictedCol:``,cfNormalize:e.cfNormalize===!0}}else if(n&&typeof n==`object`&&n.kind===`roc`){let e=n;r[t]={kind:`roc`,rocScoreCol:typeof e.rocScoreCol==`string`?e.rocScoreCol:``,rocLabelCol:typeof e.rocLabelCol==`string`?e.rocLabelCol:``,rocMode:e.rocMode===`pr`?`pr`:`roc`,rocColor:typeof e.rocColor==`string`?e.rocColor:`#f472b6`}}else if(n&&typeof n==`object`&&n.kind===`losscurve`){let e=n,i=e=>Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.column==`string`&&typeof e.color==`string`):[];r[t]={kind:`losscurve`,lcXCol:typeof e.lcXCol==`string`?e.lcXCol:``,lcLeftCols:i(e.lcLeftCols),lcRightCols:i(e.lcRightCols)}}else if(n&&typeof n==`object`&&n.kind===`controlchart`){let e=n;r[t]={kind:`controlchart`,ccValueCol:typeof e.ccValueCol==`string`?e.ccValueCol:``,ccSubgroupCol:typeof e.ccSubgroupCol==`string`?e.ccSubgroupCol:``,ccSigmaLevel:typeof e.ccSigmaLevel==`number`?e.ccSigmaLevel:3,ccColor:typeof e.ccColor==`string`?e.ccColor:`#22d3ee`}}else if(n&&typeof n==`object`&&n.kind===`parallelcoords`){let e=n;r[t]={kind:`parallelcoords`,pcColumns:Array.isArray(e.pcColumns)?e.pcColumns.filter(e=>typeof e==`string`):[],pcColorByCol:typeof e.pcColorByCol==`string`?e.pcColorByCol:``,pcColor:typeof e.pcColor==`string`?e.pcColor:`#64748b`}}else if(n&&typeof n==`object`&&n.kind===`embedding`){let e=n;r[t]={kind:`embedding`,emXCol:typeof e.emXCol==`string`?e.emXCol:``,emYCol:typeof e.emYCol==`string`?e.emYCol:``,emColorCol:typeof e.emColorCol==`string`?e.emColorCol:``,emColorMode:e.emColorMode===`numeric`?`numeric`:`categorical`,emLabelCol:typeof e.emLabelCol==`string`?e.emLabelCol:``,emPointSize:typeof e.emPointSize==`number`?e.emPointSize:3,emColor:typeof e.emColor==`string`?e.emColor:`#a78bfa`}}else if(n&&typeof n==`object`&&n.kind===`flamegraph`){let e=n;r[t]={kind:`flamegraph`,fgNameCol:typeof e.fgNameCol==`string`?e.fgNameCol:``,fgParentCol:typeof e.fgParentCol==`string`?e.fgParentCol:``,fgValueCol:typeof e.fgValueCol==`string`?e.fgValueCol:``,fgDirection:e.fgDirection===`bottomup`?`bottomup`:`topdown`}}else if(n&&typeof n==`object`&&n.kind===`barchart`){let e=n,i=Array.isArray(e.bcValueCols)?e.bcValueCols.filter(e=>typeof e==`string`):[],a=e.bcValueScale;r[t]={kind:`barchart`,bcCategoryCol:typeof e.bcCategoryCol==`string`?e.bcCategoryCol:``,bcValueCols:i,bcMode:e.bcMode===`stacked`?`stacked`:`grouped`,bcHorizontal:e.bcHorizontal===!0,...a&&typeof a==`object`?{bcValueScale:{scaleMin:typeof a.scaleMin==`string`?a.scaleMin:``,scaleMax:typeof a.scaleMax==`string`?a.scaleMax:``}}:{}}}else if(n&&typeof n==`object`&&n.kind===`radar`){let e=n;r[t]={kind:`radar`,rdAxesCols:Array.isArray(e.rdAxesCols)?e.rdAxesCols.filter(e=>typeof e==`string`):[],rdGroupCol:typeof e.rdGroupCol==`string`?e.rdGroupCol:``,rdColor:typeof e.rdColor==`string`?e.rdColor:`#38bdf8`,rdFill:e.rdFill!==!1}}else if(n&&typeof n==`object`&&n.kind===`areachart`){let e=n,i=Array.isArray(e.acYCols)?e.acYCols.filter(e=>typeof e==`string`):[],a=e.acYScale;r[t]={kind:`areachart`,acXCol:typeof e.acXCol==`string`?e.acXCol:``,acYCols:i,acStacked:e.acStacked===!0,...a&&typeof a==`object`?{acYScale:{scaleMin:typeof a.scaleMin==`string`?a.scaleMin:``,scaleMax:typeof a.scaleMax==`string`?a.scaleMax:``}}:{}}}else if(n&&typeof n==`object`&&n.kind===`cdfchart`){let e=n;r[t]={kind:`cdfchart`,cdValueCols:Array.isArray(e.cdValueCols)?e.cdValueCols.filter(e=>typeof e==`string`):[],cdComplement:e.cdComplement===!0,cdLogX:e.cdLogX===!0}}else if(n&&typeof n==`object`&&n.kind===`bubblechart`){let e=n;r[t]={kind:`bubblechart`,bbXCol:typeof e.bbXCol==`string`?e.bbXCol:``,bbYCol:typeof e.bbYCol==`string`?e.bbYCol:``,bbSizeCol:typeof e.bbSizeCol==`string`?e.bbSizeCol:``,bbColorCol:typeof e.bbColorCol==`string`?e.bbColorCol:``,bbColorMode:e.bbColorMode===`numeric`?`numeric`:`categorical`,bbColor:typeof e.bbColor==`string`?e.bbColor:`#64748b`,bbMaxRadius:typeof e.bbMaxRadius==`number`?e.bbMaxRadius:24}}else if(n&&typeof n==`object`&&n.kind===`treemap`){let e=n;r[t]={kind:`treemap`,tmNameCol:typeof e.tmNameCol==`string`?e.tmNameCol:``,tmParentCol:typeof e.tmParentCol==`string`?e.tmParentCol:``,tmValueCol:typeof e.tmValueCol==`string`?e.tmValueCol:``}}else if(n&&typeof n==`object`&&n.kind===`sankey`){let e=n;r[t]={kind:`sankey`,skSourceCol:typeof e.skSourceCol==`string`?e.skSourceCol:``,skTargetCol:typeof e.skTargetCol==`string`?e.skTargetCol:``,skValueCol:typeof e.skValueCol==`string`?e.skValueCol:``}}else if(n&&typeof n==`object`&&n.kind===`gauge`){let e=n;r[t]={kind:`gauge`,ggGauges:Array.isArray(e.ggGauges)?e.ggGauges.flatMap((e,t)=>{let n=L(e,t);return n?[n]:[]}):[]}}else if(n&&typeof n==`object`&&n.kind===`calibration`){let e=n;r[t]={kind:`calibration`,cbScoreCol:typeof e.cbScoreCol==`string`?e.cbScoreCol:``,cbLabelCol:typeof e.cbLabelCol==`string`?e.cbLabelCol:``,cbBins:typeof e.cbBins==`number`?e.cbBins:10,cbColor:typeof e.cbColor==`string`?e.cbColor:`#38bdf8`}}else if(n&&typeof n==`object`&&n.kind===`qqplot`){let e=n;r[t]={kind:`qqplot`,qqValueCol:typeof e.qqValueCol==`string`?e.qqValueCol:``,qqMode:e.qqMode===`column`?`column`:`normal`,qqRefCol:typeof e.qqRefCol==`string`?e.qqRefCol:``,qqColor:typeof e.qqColor==`string`?e.qqColor:`#a78bfa`}}else if(n&&typeof n==`object`&&n.kind===`gantt`){let e=n;r[t]={kind:`gantt`,gtLabelCol:typeof e.gtLabelCol==`string`?e.gtLabelCol:``,gtStartCol:typeof e.gtStartCol==`string`?e.gtStartCol:``,gtEndCol:typeof e.gtEndCol==`string`?e.gtEndCol:``,gtGroupCol:typeof e.gtGroupCol==`string`?e.gtGroupCol:``}}let e=r[t]?y(n?.annotations):null;e?.length&&(r[t]={...r[t],annotations:e});let i=r[t]?ke[r[t].kind]:void 0,a=i?Oe(n[i]):null;i&&a&&(r[t]={...r[t],[i]:a})}return r}function Ne(e,t,n,r){let i={...t},a=!1;for(let t of e)if(t.kind===`multiband`){let e=i[t.id];(!e||e.kind!==`multiband`)&&(i[t.id]=B(),a=!0)}else if(t.kind===`xyscatter`){let e=i[t.id];(!e||e.kind!==`xyscatter`)&&(i[t.id]=V(n),a=!0)}else if(t.kind===`xyzmesh`){let e=i[t.id];(!e||e.kind!==`xyzmesh`)&&(i[t.id]=H(r),a=!0)}else if(t.kind===`histogram`){let e=i[t.id];(!e||e.kind!==`histogram`)&&(i[t.id]=U(),a=!0)}else if(t.kind===`polar`){let e=i[t.id];(!e||e.kind!==`polar`)&&(i[t.id]=W(),a=!0)}else if(t.kind===`spectrum`){let e=i[t.id];(!e||e.kind!==`spectrum`)&&(i[t.id]=ee(),a=!0)}else if(t.kind===`boxplot`){let e=i[t.id];(!e||e.kind!==`boxplot`)&&(i[t.id]=te(),a=!0)}else t.kind===`spectrogram`?(!i[t.id]||i[t.id].kind!==`spectrogram`)&&(i[t.id]=ne(),a=!0):t.kind===`heatmap`?(!i[t.id]||i[t.id].kind!==`heatmap`)&&(i[t.id]=G(),a=!0):t.kind===`violin`?(!i[t.id]||i[t.id].kind!==`violin`)&&(i[t.id]=re(),a=!0):t.kind===`confusion`?(!i[t.id]||i[t.id].kind!==`confusion`)&&(i[t.id]=ie(),a=!0):t.kind===`roc`?(!i[t.id]||i[t.id].kind!==`roc`)&&(i[t.id]=ae(),a=!0):t.kind===`losscurve`?(!i[t.id]||i[t.id].kind!==`losscurve`)&&(i[t.id]=oe(),a=!0):t.kind===`controlchart`?(!i[t.id]||i[t.id].kind!==`controlchart`)&&(i[t.id]=se(),a=!0):t.kind===`parallelcoords`?(!i[t.id]||i[t.id].kind!==`parallelcoords`)&&(i[t.id]=ce(),a=!0):t.kind===`embedding`?(!i[t.id]||i[t.id].kind!==`embedding`)&&(i[t.id]=le(),a=!0):t.kind===`flamegraph`?(!i[t.id]||i[t.id].kind!==`flamegraph`)&&(i[t.id]=ue(),a=!0):t.kind===`barchart`?(!i[t.id]||i[t.id].kind!==`barchart`)&&(i[t.id]=de(),a=!0):t.kind===`radar`?(!i[t.id]||i[t.id].kind!==`radar`)&&(i[t.id]=fe(),a=!0):t.kind===`areachart`?(!i[t.id]||i[t.id].kind!==`areachart`)&&(i[t.id]=pe(),a=!0):t.kind===`cdfchart`?(!i[t.id]||i[t.id].kind!==`cdfchart`)&&(i[t.id]=me(),a=!0):t.kind===`bubblechart`?(!i[t.id]||i[t.id].kind!==`bubblechart`)&&(i[t.id]=he(),a=!0):t.kind===`treemap`?(!i[t.id]||i[t.id].kind!==`treemap`)&&(i[t.id]=ge(),a=!0):t.kind===`sankey`?(!i[t.id]||i[t.id].kind!==`sankey`)&&(i[t.id]=_e(),a=!0):t.kind===`gauge`?(!i[t.id]||i[t.id].kind!==`gauge`)&&(i[t.id]=ve(),a=!0):t.kind===`calibration`?(!i[t.id]||i[t.id].kind!==`calibration`)&&(i[t.id]=ye(),a=!0):t.kind===`qqplot`?(!i[t.id]||i[t.id].kind!==`qqplot`)&&(i[t.id]=be(),a=!0):t.kind===`gantt`&&(!i[t.id]||i[t.id].kind!==`gantt`)&&(i[t.id]=xe(),a=!0);for(let t of Object.keys(i))e.some(e=>e.id===t)||(delete i[t],a=!0);return a?i:t}function Pe(){return crypto.randomUUID()}function Fe(e={}){let t=Date.now();return{id:crypto.randomUUID(),name:``,units:``,formula:``,enabled:!0,createdAt:t,updatedAt:t,source:`personal`,sharedWithOrgId:null,projectId:null,ownerUserId:``,ownerDisplayName:null,ownerLastName:null,...e}}function Ie(e){return Ve.get(e)}function Le(e,t){let n=e.keys.lastIndexOf(t);return n<0?void 0:e.values[n]}function Re(e,t){let n=e.keys.join(`
|
|
3
3
|
`),r=t&&He.get(t);if(r&&r.keys===n&&t.length===e.length){r.t=e;let n=new Proxy(r.base,{});return He.set(n,r),Ve.set(n,e),Ve.set(t,e),n}let i=Array(e.length),a={t:e,keys:n,base:i},o={};e.keys.forEach((e,t)=>{Object.defineProperty(o,e,{enumerable:!0,configurable:!0,get(){let e=this[Be],{values:n,text:r}=a.t,i=n[t][e],o=r[t];return i===i?i:o?o[e]??null:null},set(t){Object.defineProperty(this,e,{value:t,writable:!0,enumerable:!0,configurable:!0})}})});for(let t=0;t<e.length;t++){let e=Object.create(o);e[Be]=t,i[t]=e}return He.set(i,a),Ve.set(i,e),i}function ze(e){let t=Array(e.length);for(let n=0;n<e.length;n++){let r={};for(let t=0;t<e.keys.length;t++){let i=e.values[t][n];r[e.keys[t]]=i===i?i:e.text[t]?.[n]??null}t[n]=r}return t}var Be,Ve,He,Ue=c((()=>{Be=Symbol(`row`),Ve=new WeakMap,He=new WeakMap}));function We(){return We=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},We.apply(null,arguments)}var Ge={relTol:1e-12,absTol:1e-15,matrix:`Matrix`,number:`number`,numberFallback:`number`,precision:64,predictable:!1,randomSeed:null,legacySubset:!1};function Ke(e,t){if(Je(e,t)||Ye(e,t))return e[t];throw Qe(e,t)?Error(`Cannot access method "${t}" as a property`):e==null?TypeError(`Cannot access property "${t}": object is ${e}`):Error(`No access to property "`+t+`"`)}function qe(e,t,n){if(Je(e,t)||Ye(e,t))return e[t]=n,n;throw Error(`No access to property "${t}"`)}function Je(e,t){return $e(e)?!(t in Object.prototype):!1}function Ye(e,t){return Array.isArray(e)?typeof t==`number`||typeof t==`string`&&Xe(t)||t===`length`:!1}function Xe(e){return/^\d+$/.test(e)}function Ze(e,t){if(!Qe(e,t))throw Error(`No access to method "`+t+`"`);return e[t]}function Qe(e,t){return e==null||typeof e[t]!=`function`||sn(e,t)&&Object.getPrototypeOf&&t in Object.getPrototypeOf(e)?!1:et.has(t)?!0:!(t in Object.prototype||t in Function.prototype)}function $e(e){return typeof e==`object`&&e&&e.constructor===Object}var et=new Set([`toString`,`valueOf`,`toLocaleString`]),tt=class{constructor(e){this.wrappedObject=e,this[Symbol.iterator]=this.entries}keys(){return Object.keys(this.wrappedObject).filter(e=>this.has(e)).values()}get(e){return Ke(this.wrappedObject,e)}set(e,t){return qe(this.wrappedObject,e,t),this}has(e){return Je(this.wrappedObject,e)&&e in this.wrappedObject}entries(){return rt(this.keys(),e=>[e,this.get(e)])}forEach(e){for(var t of this.keys())e(this.get(t),t,this)}delete(e){Je(this.wrappedObject,e)&&delete this.wrappedObject[e]}clear(){for(var e of this.keys())this.delete(e)}get size(){return Object.keys(this.wrappedObject).length}},nt=class{constructor(e,t,n){this.a=e,this.b=t,this.bKeys=n,this[Symbol.iterator]=this.entries}get(e){return this.bKeys.has(e)?this.b.get(e):this.a.get(e)}set(e,t){return this.bKeys.has(e)?this.b.set(e,t):this.a.set(e,t),this}has(e){return this.b.has(e)||this.a.has(e)}keys(){return new Set([...this.a.keys(),...this.b.keys()])[Symbol.iterator]()}entries(){return rt(this.keys(),e=>[e,this.get(e)])}forEach(e){for(var t of this.keys())e(this.get(t),t,this)}delete(e){return this.bKeys.has(e)?this.b.delete(e):this.a.delete(e)}clear(){this.a.clear(),this.b.clear()}get size(){return[...this.keys()].length}};function rt(e,t){return{next:()=>{var n=e.next();return n.done?n:{value:t(n.value),done:!1}}}}function it(){return new Map}function at(e){if(!e)return it();if(Ot(e))return e;if(Dt(e))return new tt(e);throw Error(`createMap can create maps from objects or Maps`)}function ot(e){if(e instanceof tt)return e.wrappedObject;var t={};for(var n of e.keys())qe(t,n,e.get(n));return t}function st(e){return typeof e==`number`}function ct(e){return!e||typeof e!=`object`||typeof e.constructor!=`function`?!1:e.isBigNumber===!0&&typeof e.constructor.prototype==`object`&&e.constructor.prototype.isBigNumber===!0||typeof e.constructor.isDecimal==`function`&&e.constructor.isDecimal(e)===!0}function lt(e){return typeof e==`bigint`}function ut(e){return e&&typeof e==`object`&&Object.getPrototypeOf(e).isComplex===!0||!1}function dt(e){return e&&typeof e==`object`&&Object.getPrototypeOf(e).isFraction===!0||!1}function ft(e){return e&&e.constructor.prototype.isUnit===!0||!1}function pt(e){return typeof e==`string`}var mt=Array.isArray;function ht(e){return e&&e.constructor.prototype.isMatrix===!0||!1}function gt(e){return Array.isArray(e)||ht(e)}function _t(e){return e&&e.isDenseMatrix&&e.constructor.prototype.isMatrix===!0||!1}function vt(e){return e&&e.isSparseMatrix&&e.constructor.prototype.isMatrix===!0||!1}function yt(e){return e&&e.constructor.prototype.isRange===!0||!1}function bt(e){return e&&e.constructor.prototype.isIndex===!0||!1}function xt(e){return typeof e==`boolean`}function St(e){return e&&e.constructor.prototype.isResultSet===!0||!1}function Ct(e){return e&&e.constructor.prototype.isHelp===!0||!1}function wt(e){return typeof e==`function`}function Tt(e){return e instanceof Date}function Et(e){return e instanceof RegExp}function Dt(e){return!!(e&&typeof e==`object`&&e.constructor===Object&&!ut(e)&&!dt(e))}function Ot(e){return e?e instanceof Map||e instanceof tt||typeof e.set==`function`&&typeof e.get==`function`&&typeof e.keys==`function`&&typeof e.has==`function`:!1}function kt(e){return Ot(e)&&Ot(e.a)&&Ot(e.b)}function At(e){return Ot(e)&&Dt(e.wrappedObject)}function jt(e){return e===null}function Mt(e){return e===void 0}function Nt(e){return e&&e.isAccessorNode===!0&&e.constructor.prototype.isNode===!0||!1}function Pt(e){return e&&e.isArrayNode===!0&&e.constructor.prototype.isNode===!0||!1}function Ft(e){return e&&e.isAssignmentNode===!0&&e.constructor.prototype.isNode===!0||!1}function It(e){return e&&e.isBlockNode===!0&&e.constructor.prototype.isNode===!0||!1}function Lt(e){return e&&e.isConditionalNode===!0&&e.constructor.prototype.isNode===!0||!1}function Rt(e){return e&&e.isConstantNode===!0&&e.constructor.prototype.isNode===!0||!1}function zt(e){return Rt(e)||Gt(e)&&e.args.length===1&&Rt(e.args[0])&&`-+~`.includes(e.op)}function Bt(e){return e&&e.isFunctionAssignmentNode===!0&&e.constructor.prototype.isNode===!0||!1}function Vt(e){return e&&e.isFunctionNode===!0&&e.constructor.prototype.isNode===!0||!1}function Ht(e){return e&&e.isIndexNode===!0&&e.constructor.prototype.isNode===!0||!1}function Ut(e){return e&&e.isNode===!0&&e.constructor.prototype.isNode===!0||!1}function Wt(e){return e&&e.isObjectNode===!0&&e.constructor.prototype.isNode===!0||!1}function Gt(e){return e&&e.isOperatorNode===!0&&e.constructor.prototype.isNode===!0||!1}function Kt(e){return e&&e.isParenthesisNode===!0&&e.constructor.prototype.isNode===!0||!1}function qt(e){return e&&e.isRangeNode===!0&&e.constructor.prototype.isNode===!0||!1}function Jt(e){return e&&e.isRelationalNode===!0&&e.constructor.prototype.isNode===!0||!1}function Yt(e){return e&&e.isSymbolNode===!0&&e.constructor.prototype.isNode===!0||!1}function Xt(e){return e&&e.constructor.prototype.isChain===!0||!1}function Zt(e){var t=typeof e;return t===`object`?e===null?`null`:ct(e)?`BigNumber`:e.constructor&&e.constructor.name?e.constructor.name:`Object`:t}function Qt(e){var t=typeof e;if(t===`number`||t===`bigint`||t===`string`||t===`boolean`||e==null)return e;if(typeof e.clone==`function`)return e.clone();if(Array.isArray(e))return e.map(function(e){return Qt(e)});if(e instanceof Date)return new Date(e.valueOf());if(ct(e))return e;if(Dt(e))return $t(e,Qt);if(t===`function`)return e;throw TypeError(`Cannot clone: unknown type of value (value: ${e})`)}function $t(e,t){var n={};for(var r in e)sn(e,r)&&(n[r]=t(e[r]));return n}function en(e,t){for(var n in t)sn(t,n)&&(e[n]=t[n]);return e}function tn(e,t){if(Array.isArray(t))throw TypeError(`Arrays are not supported by deepExtend`);for(var n in t)if(sn(t,n)&&!(n in Object.prototype)&&!(n in Function.prototype))if(t[n]&&t[n].constructor===Object)e[n]===void 0&&(e[n]={}),e[n]&&e[n].constructor===Object?tn(e[n],t[n]):e[n]=t[n];else if(Array.isArray(t[n]))throw TypeError(`Arrays are not supported by deepExtend`);else e[n]=t[n];return e}function nn(e,t){var n,r,i;if(Array.isArray(e)){if(!Array.isArray(t)||e.length!==t.length)return!1;for(r=0,i=e.length;r<i;r++)if(!nn(e[r],t[r]))return!1;return!0}else if(typeof e==`function`)return e===t;else if(e instanceof Object){if(Array.isArray(t)||!(t instanceof Object))return!1;for(n in e)if(!(n in t)||!nn(e[n],t[n]))return!1;for(n in t)if(!(n in e))return!1;return!0}else return e===t}function rn(e){var t={};return an(e,t),t}function an(e,t){for(var n in e)if(sn(e,n)){var r=e[n];typeof r==`object`&&r?an(r,t):t[n]=r}}function on(e,t,n){var r=!0,i;Object.defineProperty(e,t,{get:function(){return r&&=(i=n(),!1),i},set:function(e){i=e,r=!1},configurable:!0,enumerable:!0})}function sn(e,t){return e&&Object.hasOwnProperty.call(e,t)}function cn(e){return e&&typeof e.factory==`function`}function ln(e,t){for(var n={},r=0;r<t.length;r++){var i=t[r],a=e[i];a!==void 0&&(n[i]=a)}return n}var un=[`Matrix`,`Array`],dn=[`number`,`BigNumber`,`bigint`,`Fraction`];function fn(e,t){function n(r){if(r){if(r.epsilon!==void 0){console.warn(`Warning: The configuration option "epsilon" is deprecated. Use "relTol" and "absTol" instead.`);var i=Qt(r);return i.relTol=r.epsilon,i.absTol=r.epsilon*.001,delete i.epsilon,n(i)}r.legacySubset===!0&&console.warn(`Warning: The configuration option "legacySubset" is for compatibility only and might be deprecated in the future.`);var a=Qt(e);pn(r,`matrix`,un),pn(r,`number`,dn),tn(e,r);var o=Qt(e);return t(`config`,o,a,Qt(r)),o}else return Qt(e)}return n.MATRIX_OPTIONS=un,n.NUMBER_OPTIONS=dn,Object.keys(Ge).forEach(t=>{Object.defineProperty(n,t,{get:()=>e[t],enumerable:!0,configurable:!0})}),n}function pn(e,t,n){e[t]!==void 0&&!n.includes(e[t])&&console.warn(`Warning: Unknown value "`+e[t]+`" for configuration option "`+t+`". Available options: `+n.map(e=>JSON.stringify(e)).join(`, `)+`.`)}var mn=l(((e,t)=>{(function(n,r){typeof e==`object`&&t!==void 0?t.exports=r():typeof define==`function`&&define.amd?define(r):(n=typeof globalThis<`u`?globalThis:n||self,n.typed=r())})(e,(function(){"use strict";function e(){return!0}function t(){return!1}function n(){}let r=`Argument is not a typed-function.`;function i(){function a(e){return typeof e==`object`&&!!e&&e.constructor===Object}let o=[{name:`number`,test:function(e){return typeof e==`number`}},{name:`string`,test:function(e){return typeof e==`string`}},{name:`boolean`,test:function(e){return typeof e==`boolean`}},{name:`Function`,test:function(e){return typeof e==`function`}},{name:`Array`,test:Array.isArray},{name:`Date`,test:function(e){return e instanceof Date}},{name:`RegExp`,test:function(e){return e instanceof RegExp}},{name:`Object`,test:a},{name:`null`,test:function(e){return e===null}},{name:`undefined`,test:function(e){return e===void 0}}],s={name:`any`,test:e,isAny:!0},c,l,u=0,d={createCount:0};function f(e){let t=c.get(e);if(t)return t;let n=`Unknown type "`+e+`"`,r=e.toLowerCase(),i;for(i of l)if(i.toLowerCase()===r){n+=`. Did you mean "`+i+`" ?`;break}throw TypeError(n)}function p(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:`any`,n=t?f(t).index:l.length,r=[];for(let t=0;t<e.length;++t){if(!e[t]||typeof e[t].name!=`string`||typeof e[t].test!=`function`)throw TypeError(`Object with properties {name: string, test: function} expected`);let i=e[t].name;if(c.has(i))throw TypeError(`Duplicate type name "`+i+`"`);r.push(i),c.set(i,{name:i,test:e[t].test,isAny:e[t].isAny,index:n+t,conversionsTo:[]})}let i=l.slice(n);l=l.slice(0,n).concat(r).concat(i);for(let e=n+r.length;e<l.length;++e)c.get(l[e]).index=e}function m(){c=new Map,l=[],u=0,p([s],!1)}m(),p(o);function h(){let e;for(e of l)c.get(e).conversionsTo=[];u=0}function g(e){let t=l.filter(t=>{let n=c.get(t);return!n.isAny&&n.test(e)});return t.length?t:[`any`]}function _(e){return e&&typeof e==`function`&&`_typedFunctionData`in e}function v(e,t,n){if(!_(e))throw TypeError(r);let i=n&&n.exact,a=T(Array.isArray(t)?t.join(`,`):t),o=x(a);if(!i||o in e.signatures){let t=e._typedFunctionData.signatureMap.get(o);if(t)return t}let s=a.length,c;if(i){c=[];let t;for(t in e.signatures)c.push(e._typedFunctionData.signatureMap.get(t))}else c=e._typedFunctionData.signatures;for(let e=0;e<s;++e){let t=a[e],n=[],r;for(r of c){let i=k(r.params,e);if(!(!i||t.restParam&&!i.restParam)){if(!i.hasAny){let e=w(i);if(t.types.some(t=>!e.has(t.name)))continue}n.push(r)}}if(c=n,c.length===0)break}let l;for(l of c)if(l.params.length<=s)return l;throw TypeError(`Signature not found (signature: `+(e.name||`unnamed`)+`(`+x(a,`, `)+`))`)}function y(e,t,n){return v(e,t,n).implementation}function b(e,t){let n=f(t);if(n.test(e))return e;let r=n.conversionsTo;if(r.length===0)throw Error(`There are no conversions to `+t+` defined.`);for(let t=0;t<r.length;t++)if(f(r[t].from).test(e))return r[t].convert(e);throw Error(`Cannot convert `+e+` to `+t)}function x(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:`,`;return e.map(e=>e.name).join(t)}function S(e){let t=e.indexOf(`...`)===0,n=(t?e.length>3?e.slice(3):`any`:e).split(`|`).map(e=>f(e.trim())),r=!1,i=t?`...`:``;return{types:n.map(function(e){return r=e.isAny||r,i+=e.name+`|`,{name:e.name,typeIndex:e.index,test:e.test,isAny:e.isAny,conversion:null,conversionIndex:-1}}),name:i.slice(0,-1),hasAny:r,hasConversion:!1,restParam:t}}function C(e){let t=R(e.types.map(e=>e.name)),n=e.hasAny,r=e.name,i=t.map(function(e){let t=f(e.from);return n=t.isAny||n,r+=`|`+e.from,{name:e.from,typeIndex:t.index,test:t.test,isAny:t.isAny,conversion:e,conversionIndex:e.index}});return{types:e.types.concat(i),name:r,hasAny:n,hasConversion:i.length>0,restParam:e.restParam}}function w(e){return e.typeSet||(e.typeSet=new Set,e.types.forEach(t=>e.typeSet.add(t.name))),e.typeSet}function T(e){let t=[];if(typeof e!=`string`)throw TypeError(`Signatures must be strings`);let n=e.trim();if(n===``)return t;let r=n.split(`,`);for(let e=0;e<r.length;++e){let n=S(r[e].trim());if(n.restParam&&e!==r.length-1)throw SyntaxError(`Unexpected rest parameter "`+r[e]+`": only allowed for the last parameter`);if(n.types.length===0)return null;t.push(n)}return t}function E(e){let t=ie(e);return t?t.restParam:!1}function D(t){if(!t||t.types.length===0)return e;if(t.types.length===1)return f(t.types[0].name).test;if(t.types.length===2){let e=f(t.types[0].name).test,n=f(t.types[1].name).test;return function(t){return e(t)||n(t)}}else{let e=t.types.map(function(e){return f(e.name).test});return function(t){for(let n=0;n<e.length;n++)if(e[n](t))return!0;return!1}}}function O(e){let t,n,r;if(E(e)){t=re(e).map(D);let n=t.length,r=D(ie(e)),i=function(e){for(let t=n;t<e.length;t++)if(!r(e[t]))return!1;return!0};return function(e){for(let n=0;n<t.length;n++)if(!t[n](e[n]))return!1;return i(e)&&e.length>=n+1}}else if(e.length===0)return function(e){return e.length===0};else if(e.length===1)return n=D(e[0]),function(e){return n(e[0])&&e.length===1};else if(e.length===2)return n=D(e[0]),r=D(e[1]),function(e){return n(e[0])&&r(e[1])&&e.length===2};else return t=e.map(D),function(e){for(let n=0;n<t.length;n++)if(!t[n](e[n]))return!1;return e.length===t.length}}function k(e,t){return t<e.length?e[t]:E(e)?ie(e):null}function A(e,t){let n=k(e,t);return n?w(n):new Set}function j(e){return e.conversion===null||e.conversion===void 0}function M(e,t){let n=new Set;return e.forEach(e=>{let r=A(e.params,t),i;for(i of r)n.add(i)}),n.has(`any`)?[`any`]:Array.from(n)}function N(e,t,n){let r,i,a=e||`unnamed`,o=n,s;for(s=0;s<t.length;s++){let e=[];if(o.forEach(n=>{let r=D(k(n.params,s));(s<n.params.length||E(n.params))&&r(t[s])&&e.push(n)}),e.length===0){if(i=M(o,s),i.length>0){let e=g(t[s]);return r=TypeError(`Unexpected type of argument in function `+a+` (expected: `+i.join(` or `)+`, actual: `+e.join(` | `)+`, index: `+s+`)`),r.data={category:`wrongType`,fn:a,index:s,actual:e,expected:i},r}}else o=e}let c=o.map(function(e){return E(e.params)?1/0:e.params.length});if(t.length<Math.min.apply(null,c))return i=M(o,s),r=TypeError(`Too few arguments in function `+a+` (expected: `+i.join(` or `)+`, index: `+t.length+`)`),r.data={category:`tooFewArgs`,fn:a,index:t.length,expected:i},r;let l=Math.max.apply(null,c);if(t.length>l)return r=TypeError(`Too many arguments in function `+a+` (expected: `+l+`, actual: `+t.length+`)`),r.data={category:`tooManyArgs`,fn:a,index:t.length,expectedLength:l},r;let u=[];for(let e=0;e<t.length;++e)u.push(g(t[e]).join(`|`));return r=TypeError(`Arguments of type "`+u.join(`, `)+`" do not match any of the defined signatures of function `+a+`.`),r.data={category:`mismatch`,actual:u},r}function P(e){let t=l.length+1;for(let n=0;n<e.types.length;n++)t=Math.min(t,e.types[n].typeIndex);return t}function F(e){let t=u+1;for(let n=0;n<e.types.length;n++)j(e.types[n])||(t=Math.min(t,e.types[n].conversionIndex));return t}function I(e,t){if(e.hasAny){if(!t.hasAny)return .1}else if(t.hasAny)return-.1;if(e.restParam){if(!t.restParam)return .01}else if(t.restParam)return-.01;let n=P(e)-P(t);if(n<0)return-.001;if(n>0)return .001;let r=F(e),i=F(t);if(e.hasConversion){if(!t.hasConversion)return(1+r)*1e-6}else if(t.hasConversion)return-(1+i)*1e-6;let a=r-i;return a<0?-1e-7:a>0?1e-7:0}function L(e,t){let n=e.params,r=t.params,i=ie(n),a=ie(r),o=E(n),s=E(r);if(o&&i.hasAny){if(!s||!a.hasAny)return 1e7}else if(s&&a.hasAny)return-1e7;let c=0,l=0,u;for(u of n)u.hasAny&&++c,u.hasConversion&&++l;let d=0,f=0;for(u of r)u.hasAny&&++d,u.hasConversion&&++f;if(c!==d)return(c-d)*1e6;if(o&&i.hasConversion){if(!s||!a.hasConversion)return 1e5}else if(s&&a.hasConversion)return-1e5;if(l!==f)return(l-f)*1e4;if(o){if(!s)return 1e3}else if(s)return-1e3;let p=(n.length-r.length)*(o?-100:100);if(p!==0)return p;let m=[],h=0;for(let e=0;e<n.length;++e){let t=I(n[e],r[e]);m.push(t),h+=t}if(h!==0)return(h<0?-10:10)+h;let g,_=9,v=_/(m.length+1);for(g of m){if(g!==0)return(g<0?-_:_)+g;_-=v}return 0}function R(e){if(e.length===0)return[];let t=e.map(f);if(e.length===1)return t[0].conversionsTo;let n=new Set(e),r=new Set;for(let e=0;e<t.length;++e)for(let i of t[e].conversionsTo)n.has(i.from)||r.add(i.from);let i=[];for(let e of r){let n=u+1,r=null;for(let i=0;i<t.length;++i)for(let a of t[i].conversionsTo)a.from===e&&a.index<n&&(n=a.index,r=a);i.push(r)}return i}function z(e,t){let n=t,r=``;if(e.some(e=>e.hasConversion)){let i=E(e),a=e.map(B);r=a.map(e=>e.name).join(`;`),n=function(){let e=[],n=i?arguments.length-1:arguments.length;for(let t=0;t<n;t++)e[t]=a[t](arguments[t]);return i&&(e[n]=arguments[n].map(a[n])),t.apply(this,e)}}let i=n;if(E(e)){let t=e.length-1;i=function(){return n.apply(this,ae(arguments,0,t).concat([ae(arguments,t)]))}}return r&&Object.defineProperty(i,`name`,{value:r}),i}function B(e){let t,n,r,i,a=[],o=[],s=``;e.types.forEach(function(e){e.conversion&&(s+=e.conversion.from+`~>`+e.conversion.to+`,`,a.push(f(e.conversion.from).test),o.push(e.conversion.convert))}),s=s?s.slice(0,-1):`pass`;let c=e=>e;switch(o.length){case 0:break;case 1:t=a[0],r=o[0],c=function(e){return t(e)?r(e):e};break;case 2:t=a[0],n=a[1],r=o[0],i=o[1],c=function(e){return t(e)?r(e):n(e)?i(e):e};break;default:c=function(e){for(let t=0;t<o.length;t++)if(a[t](e))return o[t](e);return e}}return Object.defineProperty(c,`name`,{value:s}),c}function V(e){function t(e,n,r){if(n<e.length){let i=e[n],a=[];if(i.restParam){let e=i.types.filter(j);e.length<i.types.length&&a.push({types:e,name:`...`+e.map(e=>e.name).join(`|`),hasAny:e.some(e=>e.isAny),hasConversion:!1,restParam:!0}),a.push(i)}else a=i.types.map(function(e){return{types:[e],name:e.name,hasAny:e.isAny,hasConversion:e.conversion,restParam:!1}});return se(a,function(i){return t(e,n+1,r.concat([i]))})}else return[r]}return t(e,0,[])}function H(e,t){let n=Math.max(e.length,t.length);for(let r=0;r<n;r++){let n=A(e,r),i=A(t,r),a=!1,o;for(o of i)if(n.has(o)){a=!0;break}if(!a)return!1}let r=e.length,i=t.length,a=E(e),o=E(t);return a?o?r===i:i>=r:o?r>=i:r===i}function U(e){return e.map(e=>fe(e)?ue(e.referToSelf.callback):de(e)?le(e.referTo.references,e.referTo.callback):e)}function W(e,t,n){let r=[],i;for(i of e){let e=n[i];if(typeof e!=`number`)throw TypeError(`No definition for referenced signature "`+i+`"`);if(e=t[e],typeof e!=`function`)return!1;r.push(e)}return r}function ee(e,t,n){let r=U(e),i=Array(r.length).fill(!1),a=!0;for(;a;){a=!1;let e=!0;for(let o=0;o<r.length;++o){if(i[o])continue;let s=r[o];if(fe(s))r[o]=s.referToSelf.callback(n),r[o].referToSelf=s.referToSelf,i[o]=!0,e=!1;else if(de(s)){let n=W(s.referTo.references,r,t);n?(r[o]=s.referTo.callback.apply(this,n),r[o].referTo=s.referTo,i[o]=!0,e=!1):a=!0}}if(e&&a)throw SyntaxError(`Circular reference detected in resolving typed.referTo`)}return r}function te(e){let t=/\bthis(\(|\.signatures\b)/;Object.keys(e).forEach(n=>{let r=e[n];if(t.test(r.toString()))throw SyntaxError("Using `this` to self-reference a function is deprecated since typed-function@3. Use typed.referTo and typed.referToSelf instead.")})}function ne(e,r){if(d.createCount++,Object.keys(r).length===0)throw SyntaxError(`No signatures provided`);d.warnAgainstDeprecatedThis&&te(r);let i=[],a=[],o={},s=[],c;for(c in r){if(!Object.prototype.hasOwnProperty.call(r,c))continue;let e=T(c);if(!e)continue;i.forEach(function(t){if(H(t,e))throw TypeError(`Conflicting signatures "`+x(t)+`" and "`+x(e)+`".`)}),i.push(e);let t=a.length;a.push(r[c]);let n=e.map(C),l;for(l of V(n)){let e=x(l);s.push({params:l,name:e,fn:t}),l.every(e=>!e.hasConversion)&&(o[e]=t)}}s.sort(L);let l=ee(a,o,ge),u;for(u in o)Object.prototype.hasOwnProperty.call(o,u)&&(o[u]=l[o[u]]);let f=[],p=new Map;for(u of s)p.has(u.name)||(u.fn=l[u.fn],f.push(u),p.set(u.name,u));let m=f[0]&&f[0].params.length<=2&&!E(f[0].params),h=f[1]&&f[1].params.length<=2&&!E(f[1].params),g=f[2]&&f[2].params.length<=2&&!E(f[2].params),_=f[3]&&f[3].params.length<=2&&!E(f[3].params),v=f[4]&&f[4].params.length<=2&&!E(f[4].params),y=f[5]&&f[5].params.length<=2&&!E(f[5].params),b=m&&h&&g&&_&&v&&y;for(let e=0;e<f.length;++e)f[e].test=O(f[e].params);let S=m?D(f[0].params[0]):t,w=h?D(f[1].params[0]):t,k=g?D(f[2].params[0]):t,A=_?D(f[3].params[0]):t,j=v?D(f[4].params[0]):t,M=y?D(f[5].params[0]):t,N=m?D(f[0].params[1]):t,P=h?D(f[1].params[1]):t,F=g?D(f[2].params[1]):t,I=_?D(f[3].params[1]):t,R=v?D(f[4].params[1]):t,B=y?D(f[5].params[1]):t;for(let e=0;e<f.length;++e)f[e].implementation=z(f[e].params,f[e].fn);let U=m?f[0].implementation:n,W=h?f[1].implementation:n,ne=g?f[2].implementation:n,G=_?f[3].implementation:n,re=v?f[4].implementation:n,ie=y?f[5].implementation:n,ae=m?f[0].params.length:-1,oe=h?f[1].params.length:-1,se=g?f[2].params.length:-1,ce=_?f[3].params.length:-1,le=v?f[4].params.length:-1,ue=y?f[5].params.length:-1,de=b?6:0,fe=f.length,pe=f.map(e=>e.test),me=f.map(e=>e.implementation),he=function(){for(let e=de;e<fe;e++)if(pe[e](arguments))return me[e].apply(this,arguments);return d.onMismatch(e,arguments,f)};function ge(e,t){return arguments.length===ae&&S(e)&&N(t)?U.apply(this,arguments):arguments.length===oe&&w(e)&&P(t)?W.apply(this,arguments):arguments.length===se&&k(e)&&F(t)?ne.apply(this,arguments):arguments.length===ce&&A(e)&&I(t)?G.apply(this,arguments):arguments.length===le&&j(e)&&R(t)?re.apply(this,arguments):arguments.length===ue&&M(e)&&B(t)?ie.apply(this,arguments):he.apply(this,arguments)}try{Object.defineProperty(ge,`name`,{value:e})}catch{}return ge.signatures=o,ge._typedFunctionData={signatures:f,signatureMap:p},ge}function G(e,t,n){throw N(e,t,n)}function re(e){return ae(e,0,e.length-1)}function ie(e){return e[e.length-1]}function ae(e,t,n){return Array.prototype.slice.call(e,t,n)}function oe(e,t){for(let n=0;n<e.length;n++)if(t(e[n]))return e[n]}function se(e,t){return Array.prototype.concat.apply([],e.map(t))}function ce(){let e=re(arguments).map(e=>x(T(e))),t=ie(arguments);if(typeof t!=`function`)throw TypeError(`Callback function expected as last argument`);return le(e,t)}function le(e,t){return{referTo:{references:e,callback:t}}}function ue(e){if(typeof e!=`function`)throw TypeError(`Callback function expected as first argument`);return{referToSelf:{callback:e}}}function de(e){return e&&typeof e.referTo==`object`&&Array.isArray(e.referTo.references)&&typeof e.referTo.callback==`function`}function fe(e){return e&&typeof e.referToSelf==`object`&&typeof e.referToSelf.callback==`function`}function pe(e,t){if(!e)return t;if(t&&t!==e){let n=Error(`Function names do not match (expected: `+e+`, actual: `+t+`)`);throw n.data={actual:t,expected:e},n}return e}function me(e){let t;for(let n in e)Object.prototype.hasOwnProperty.call(e,n)&&(_(e[n])||typeof e[n].signature==`string`)&&(t=pe(t,e[n].name));return t}function he(e,t){let n;for(n in t)if(Object.prototype.hasOwnProperty.call(t,n)){if(n in e&&t[n]!==e[n]){let r=Error(`Signature "`+n+`" is defined twice`);throw r.data={signature:n,sourceFunction:t[n],destFunction:e[n]},r}e[n]=t[n]}}let ge=d;d=function(e){let t=typeof e==`string`,n=+!!t,r=t?e:``,i={};for(let e=n;e<arguments.length;++e){let n=arguments[e],o={},s;if(typeof n==`function`?(s=n.name,typeof n.signature==`string`?o[n.signature]=n:_(n)&&(o=n.signatures)):a(n)&&(o=n,t||(s=me(n))),Object.keys(o).length===0){let t=TypeError(`Argument to 'typed' at index `+e+` is not a (typed) function, nor an object with signatures as keys and functions as values.`);throw t.data={index:e,argument:n},t}t||(r=pe(r,s)),he(i,o)}return ne(r||``,i)},d.create=i,d.createCount=ge.createCount,d.onMismatch=G,d.throwMismatchError=G,d.createError=N,d.clear=m,d.clearConversions=h,d.addTypes=p,d._findType=f,d.referTo=ce,d.referToSelf=ue,d.convert=b,d.findSignature=v,d.find=y,d.isTypedFunction=_,d.warnAgainstDeprecatedThis=!0,d.addType=function(e,t){let n=`any`;t!==!1&&c.has(`Object`)&&(n=`Object`),d.addTypes([e],n)};function _e(e){if(!e||typeof e.from!=`string`||typeof e.to!=`string`||typeof e.convert!=`function`)throw TypeError(`Object with properties {from: string, to: string, convert: function} expected`);if(e.to===e.from)throw SyntaxError(`Illegal to define conversion from "`+e.from+`" to itself.`)}return d.addConversion=function(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{override:!1};_e(e);let n=f(e.to),r=n.conversionsTo.find(t=>t.from===e.from);if(r)if(t&&t.override)d.removeConversion({from:r.from,to:e.to,convert:r.convert});else throw Error(`There is already a conversion from "`+e.from+`" to "`+n.name+`"`);n.conversionsTo.push({from:e.from,to:n.name,convert:e.convert,index:u++})},d.addConversions=function(e,t){e.forEach(e=>d.addConversion(e,t))},d.removeConversion=function(e){_e(e);let t=f(e.to),n=oe(t.conversionsTo,t=>t.from===e.from);if(!n)throw Error(`Attempt to remove nonexistent conversion from `+e.from+` to `+e.to);if(n.convert!==e.convert)throw Error(`Conversion to remove does not match existing conversion`);let r=t.conversionsTo.indexOf(n);t.conversionsTo.splice(r,1)},d.resolve=function(e,t){if(!_(e))throw TypeError(r);let n=e._typedFunctionData.signatures;for(let e=0;e<n.length;++e)if(n[e].test(t))return n[e];return null},d}return i()}))}));function K(e,t,n,r){function i(r){var i=ln(r,t.map(vn));return gn(e,t,r),n(i)}return i.isFactory=!0,i.fn=e,i.dependencies=t.slice().sort(),r&&(i.meta=r),i}function hn(e){return typeof e==`function`&&typeof e.fn==`string`&&Array.isArray(e.dependencies)}function gn(e,t,n){if(!t.filter(e=>!_n(e)).every(e=>n[e]!==void 0)){var r=t.filter(e=>n[e]===void 0);throw Error(`Cannot create function "${e}", some dependencies are missing: ${r.map(e=>`"${e}"`).join(`, `)}.`)}}function _n(e){return e&&e[0]===`?`}function vn(e){return e&&e[0]===`?`?e.slice(1):e}function yn(e){return typeof e==`boolean`?!0:Number.isFinite(e)?e===Math.round(e):!1}function bn(e,t){if(t.number===`bigint`)try{BigInt(e)}catch{return t.numberFallback}return t.number}var xn=Math.sign||function(e){return e>0?1:e<0?-1:0},Sn=Math.log2||function(e){return Math.log(e)/Math.LN2},Cn=Math.log10||function(e){return Math.log(e)/Math.LN10},wn=Math.log1p||function(e){return Math.log(e+1)},Tn=Math.cbrt||function(e){if(e===0)return e;var t=e<0,n;return t&&(e=-e),Number.isFinite(e)?(n=Math.exp(Math.log(e)/3),n=(e/(n*n)+2*n)/3):n=e,t?-n:n},En=Math.expm1||function(e){return e>=2e-4||e<=-2e-4?Math.exp(e)-1:e+e*e/2+e*e*e/6};function Dn(e,t,n){var r={2:`0b`,8:`0o`,16:`0x`}[t],i=``;if(n){if(n<1)throw Error(`size must be in greater than 0`);if(!yn(n))throw Error(`size must be an integer`);if(e>2**(n-1)-1||e<-(2**(n-1)))throw Error(`Value must be in range [-2^${n-1}, 2^${n-1}-1]`);if(!yn(e))throw Error(`Value must be an integer`);e<0&&(e+=2**n),i=`i${n}`}var a=``;return e<0&&(e=-e,a=`-`),`${a}${r}${e.toString(t)}${i}`}function On(e,t){if(typeof t==`function`)return t(e);if(e===1/0)return`Infinity`;if(e===-1/0)return`-Infinity`;if(isNaN(e))return`NaN`;var{notation:n,precision:r,wordSize:i}=kn(t);switch(n){case`fixed`:return Mn(e,r);case`exponential`:return Nn(e,r);case`engineering`:return jn(e,r);case`bin`:return Dn(e,2,i);case`oct`:return Dn(e,8,i);case`hex`:return Dn(e,16,i);case`auto`:return Pn(e,r,t).replace(/((\.\d*?)(0+))($|e)/,function(){var e=arguments[2],t=arguments[4];return e===`.`?t:e+t});default:throw Error(`Unknown notation "`+n+`". Choose "auto", "exponential", "fixed", "bin", "oct", or "hex.`)}}function kn(e){var t=`auto`,n,r;if(e!==void 0)if(st(e))n=e;else if(ct(e))n=e.toNumber();else if(Dt(e))e.precision!==void 0&&(n=Kn(e.precision,()=>{throw Error(`Option "precision" must be a number or BigNumber`)})),e.wordSize!==void 0&&(r=Kn(e.wordSize,()=>{throw Error(`Option "wordSize" must be a number or BigNumber`)})),e.notation&&(t=e.notation);else throw Error(`Unsupported type of options, number, BigNumber, or object expected`);return{notation:t,precision:n,wordSize:r}}function An(e){var t=String(e).toLowerCase().match(/^(-?)(\d+\.?\d*)(e([+-]?\d+))?$/);if(!t)throw SyntaxError(`Invalid number `+e);var n=t[1],r=t[2],i=parseFloat(t[4]||`0`),a=r.indexOf(`.`);i+=a===-1?r.length-1:a-1;var o=r.replace(`.`,``).replace(/^0*/,function(e){return i-=e.length,``}).replace(/0*$/,``).split(``).map(function(e){return parseInt(e)});return o.length===0&&(o.push(0),i++),{sign:n,coefficients:o,exponent:i}}function jn(e,t){if(isNaN(e)||!Number.isFinite(e))return String(e);var n=Fn(An(e),t),r=n.exponent,i=n.coefficients,a=r%3==0?r:r<0?r-3-r%3:r-r%3;if(st(t))for(;t>i.length||r-a+1>i.length;)i.push(0);else for(var o=Math.abs(r-a)-(i.length-1),s=0;s<o;s++)i.push(0);for(var c=Math.abs(r-a),l=1;c>0;)l++,c--;var u=i.slice(l).join(``),d=st(t)&&u.length||u.match(/[1-9]/)?`.`+u:``,f=i.slice(0,l).join(``)+d+`e`+(r>=0?`+`:``)+a.toString();return n.sign+f}function Mn(e,t){if(isNaN(e)||!Number.isFinite(e))return String(e);var n=An(e),r=typeof t==`number`?Fn(n,n.exponent+1+t):n,i=r.coefficients,a=r.exponent+1,o=a+(t||0);return i.length<o&&(i=i.concat(In(o-i.length))),a<0&&(i=In(-a+1).concat(i),a=1),a<i.length&&i.splice(a,0,a===0?`0.`:`.`),r.sign+i.join(``)}function Nn(e,t){if(isNaN(e)||!Number.isFinite(Number(e)))return String(e);var n=An(e),r=t?Fn(n,t):n,i=r.coefficients,a=r.exponent;i.length<t&&(i=i.concat(In(t-i.length)));var o=i.shift();return r.sign+o+(i.length>0?`.`+i.join(``):``)+`e`+(a>=0?`+`:``)+a}function Pn(e,t,n){if(isNaN(e)||!Number.isFinite(e))return String(e);var r=qn(n?.lowerExp,-3),i=qn(n?.upperExp,5),a=An(e),o=t?Fn(a,t):a;if(o.exponent<r||o.exponent>=i)return Nn(e,t);var s=o.coefficients,c=o.exponent;s.length<t&&(s=s.concat(In(t-s.length))),s=s.concat(In(c-s.length+1+(s.length<t?t-s.length:0))),s=In(-c).concat(s);var l=c>0?c:0;return l<s.length-1&&s.splice(l+1,0,`.`),o.sign+s.join(``)}function Fn(e,t){for(var n={sign:e.sign,coefficients:e.coefficients,exponent:e.exponent},r=n.coefficients;t<=0;)r.unshift(0),n.exponent++,t++;if(r.length>t&&r.splice(t,r.length-t)[0]>=5){var i=t-1;for(r[i]++;r[i]===10;)r.pop(),i===0&&(r.unshift(0),n.exponent++,i++),i--,r[i]++}return n}function In(e){for(var t=[],n=0;n<e;n++)t.push(0);return t}function Ln(e){return e.toExponential().replace(/e.*$/,``).replace(/^0\.?0*|\./,``).length}function Rn(e,t){var n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:1e-8,r=arguments.length>3&&arguments[3]!==void 0?arguments[3]:0;if(n<=0)throw Error(`Relative tolerance must be greater than 0`);if(r<0)throw Error(`Absolute tolerance must be at least 0`);return isNaN(e)||isNaN(t)?!1:!Number.isFinite(e)||!Number.isFinite(t)?e===t:e===t?!0:Math.abs(e-t)<=Math.max(n*Math.max(Math.abs(e),Math.abs(t)),r)}var zn=Math.acosh||function(e){return Math.log(Math.sqrt(e*e-1)+e)},Bn=Math.asinh||function(e){return Math.log(Math.sqrt(e*e+1)+e)},Vn=Math.atanh||function(e){return Math.log((1+e)/(1-e))/2},Hn=Math.cosh||function(e){return(Math.exp(e)+Math.exp(-e))/2},Un=Math.sinh||function(e){return(Math.exp(e)-Math.exp(-e))/2},Wn=Math.tanh||function(e){var t=Math.exp(2*e);return(t-1)/(t+1)};function Gn(e,t){return(e>0?!0:e<0?!1:1/e==1/0)^(t>0?!0:t<0?!1:1/t==1/0)?-e:e}function Kn(e,t){if(st(e))return e;if(ct(e))return e.toNumber();t()}function qn(e,t){return st(e)?e:ct(e)?e.toNumber():t}var Jn=f(mn(),1),Yn=function(){return Yn=Jn.default.create,Jn.default},Xn=K(`typed`,[`?BigNumber`,`?Complex`,`?DenseMatrix`,`?Fraction`],function(e){var{BigNumber:t,Complex:n,DenseMatrix:r,Fraction:i}=e,a=Yn();return a.clear(),a.addTypes([{name:`number`,test:st},{name:`Complex`,test:ut},{name:`BigNumber`,test:ct},{name:`bigint`,test:lt},{name:`Fraction`,test:dt},{name:`Unit`,test:ft},{name:`identifier`,test:e=>pt&&/^(?:[A-Za-z\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0560-\u0588\u05D0-\u05EA\u05EF-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u0860-\u086A\u0870-\u0887\u0889-\u088F\u08A0-\u08C9\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u09FC\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C5C\u0C5D\u0C60\u0C61\u0C80\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDC-\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D04-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D54-\u0D56\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E86-\u0E8A\u0E8C-\u0EA3\u0EA5\u0EA7-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16F1-\u16F8\u1700-\u1711\u171F-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1878\u1880-\u1884\u1887-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4C\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1C80-\u1C8A\u1C90-\u1CBA\u1CBD-\u1CBF\u1CE9-\u1CEC\u1CEE-\u1CF3\u1CF5\u1CF6\u1CFA\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2183\u2184\u2C00-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005\u3006\u3031-\u3035\u303B\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312F\u3131-\u318E\u31A0-\u31BF\u31F0-\u31FF\u3400-\u4DBF\u4E00-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6E5\uA717-\uA71F\uA722-\uA788\uA78B-\uA7DC\uA7F1-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA8FE\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB69\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDE80-\uDE9C\uDEA0-\uDED0\uDF00-\uDF1F\uDF2D-\uDF40\uDF42-\uDF49\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF]|\uD801[\uDC00-\uDC9D\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDD70-\uDD7A\uDD7C-\uDD8A\uDD8C-\uDD92\uDD94\uDD95\uDD97-\uDDA1\uDDA3-\uDDB1\uDDB3-\uDDB9\uDDBB\uDDBC\uDDC0-\uDDF3\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67\uDF80-\uDF85\uDF87-\uDFB0\uDFB2-\uDFBA]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD40-\uDD59\uDD80-\uDDB7\uDDBE\uDDBF\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE35\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE4\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2\uDD00-\uDD23\uDD4A-\uDD65\uDD6F-\uDD85\uDE80-\uDEA9\uDEB0\uDEB1\uDEC2-\uDEC7\uDF00-\uDF1C\uDF27\uDF30-\uDF45\uDF70-\uDF81\uDFB0-\uDFC4\uDFE0-\uDFF6]|\uD804[\uDC03-\uDC37\uDC71\uDC72\uDC75\uDC83-\uDCAF\uDCD0-\uDCE8\uDD03-\uDD26\uDD44\uDD47\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE2B\uDE3F\uDE40\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEDE\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF50\uDF5D-\uDF61\uDF80-\uDF89\uDF8B\uDF8E\uDF90-\uDFB5\uDFB7\uDFD1\uDFD3]|\uD805[\uDC00-\uDC34\uDC47-\uDC4A\uDC5F-\uDC61\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDD80-\uDDAE\uDDD8-\uDDDB\uDE00-\uDE2F\uDE44\uDE80-\uDEAA\uDEB8\uDF00-\uDF1A\uDF40-\uDF46]|\uD806[\uDC00-\uDC2B\uDCA0-\uDCDF\uDCFF-\uDD06\uDD09\uDD0C-\uDD13\uDD15\uDD16\uDD18-\uDD2F\uDD3F\uDD41\uDDA0-\uDDA7\uDDAA-\uDDD0\uDDE1\uDDE3\uDE00\uDE0B-\uDE32\uDE3A\uDE50\uDE5C-\uDE89\uDE9D\uDEB0-\uDEF8\uDFC0-\uDFE0]|\uD807[\uDC00-\uDC08\uDC0A-\uDC2E\uDC40\uDC72-\uDC8F\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD30\uDD46\uDD60-\uDD65\uDD67\uDD68\uDD6A-\uDD89\uDD98\uDDB0-\uDDDB\uDEE0-\uDEF2\uDF02\uDF04-\uDF10\uDF12-\uDF33\uDFB0]|\uD808[\uDC00-\uDF99]|\uD809[\uDC80-\uDD43]|\uD80B[\uDF90-\uDFF0]|[\uD80C\uD80E\uD80F\uD81C-\uD822\uD840-\uD868\uD86A-\uD86D\uD86F-\uD872\uD874-\uD879\uD880-\uD883\uD885-\uD88C][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2F\uDC41-\uDC46\uDC60-\uDFFF]|\uD810[\uDC00-\uDFFA]|\uD811[\uDC00-\uDE46]|\uD818[\uDD00-\uDD1D]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDE70-\uDEBE\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDD40-\uDD6C\uDE40-\uDE7F\uDEA0-\uDEB8\uDEBB-\uDED3\uDF00-\uDF4A\uDF50\uDF93-\uDF9F\uDFE0\uDFE1\uDFE3\uDFF2\uDFF3]|\uD823[\uDC00-\uDCD5\uDCFF-\uDD1E\uDD80-\uDDF2]|\uD82B[\uDFF0-\uDFF3\uDFF5-\uDFFB\uDFFD\uDFFE]|\uD82C[\uDC00-\uDD22\uDD32\uDD50-\uDD52\uDD55\uDD64-\uDD67\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB]|\uD837[\uDF00-\uDF1E\uDF25-\uDF2A]|\uD838[\uDC30-\uDC6D\uDD00-\uDD2C\uDD37-\uDD3D\uDD4E\uDE90-\uDEAD\uDEC0-\uDEEB]|\uD839[\uDCD0-\uDCEB\uDDD0-\uDDED\uDDF0\uDEC0-\uDEDE\uDEE0-\uDEE2\uDEE4\uDEE5\uDEE7-\uDEED\uDEF0-\uDEF4\uDEFE\uDEFF\uDFE0-\uDFE6\uDFE8-\uDFEB\uDFED\uDFEE\uDFF0-\uDFFE]|\uD83A[\uDC00-\uDCC4\uDD00-\uDD43\uDD4B]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDEDF\uDF00-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEAD\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0\uDFF0-\uDFFF]|\uD87B[\uDC00-\uDE5D]|\uD87E[\uDC00-\uDE1D]|\uD884[\uDC00-\uDF4A\uDF50-\uDFFF]|\uD88D[\uDC00-\uDC79])(?:[0-9A-Za-z\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0560-\u0588\u05D0-\u05EA\u05EF-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u0860-\u086A\u0870-\u0887\u0889-\u088F\u08A0-\u08C9\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u09FC\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C5C\u0C5D\u0C60\u0C61\u0C80\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDC-\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D04-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D54-\u0D56\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E86-\u0E8A\u0E8C-\u0EA3\u0EA5\u0EA7-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16F1-\u16F8\u1700-\u1711\u171F-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1878\u1880-\u1884\u1887-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4C\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1C80-\u1C8A\u1C90-\u1CBA\u1CBD-\u1CBF\u1CE9-\u1CEC\u1CEE-\u1CF3\u1CF5\u1CF6\u1CFA\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2183\u2184\u2C00-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005\u3006\u3031-\u3035\u303B\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312F\u3131-\u318E\u31A0-\u31BF\u31F0-\u31FF\u3400-\u4DBF\u4E00-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6E5\uA717-\uA71F\uA722-\uA788\uA78B-\uA7DC\uA7F1-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA8FE\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB69\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDE80-\uDE9C\uDEA0-\uDED0\uDF00-\uDF1F\uDF2D-\uDF40\uDF42-\uDF49\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF]|\uD801[\uDC00-\uDC9D\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDD70-\uDD7A\uDD7C-\uDD8A\uDD8C-\uDD92\uDD94\uDD95\uDD97-\uDDA1\uDDA3-\uDDB1\uDDB3-\uDDB9\uDDBB\uDDBC\uDDC0-\uDDF3\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67\uDF80-\uDF85\uDF87-\uDFB0\uDFB2-\uDFBA]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD40-\uDD59\uDD80-\uDDB7\uDDBE\uDDBF\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE35\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE4\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2\uDD00-\uDD23\uDD4A-\uDD65\uDD6F-\uDD85\uDE80-\uDEA9\uDEB0\uDEB1\uDEC2-\uDEC7\uDF00-\uDF1C\uDF27\uDF30-\uDF45\uDF70-\uDF81\uDFB0-\uDFC4\uDFE0-\uDFF6]|\uD804[\uDC03-\uDC37\uDC71\uDC72\uDC75\uDC83-\uDCAF\uDCD0-\uDCE8\uDD03-\uDD26\uDD44\uDD47\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE2B\uDE3F\uDE40\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEDE\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF50\uDF5D-\uDF61\uDF80-\uDF89\uDF8B\uDF8E\uDF90-\uDFB5\uDFB7\uDFD1\uDFD3]|\uD805[\uDC00-\uDC34\uDC47-\uDC4A\uDC5F-\uDC61\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDD80-\uDDAE\uDDD8-\uDDDB\uDE00-\uDE2F\uDE44\uDE80-\uDEAA\uDEB8\uDF00-\uDF1A\uDF40-\uDF46]|\uD806[\uDC00-\uDC2B\uDCA0-\uDCDF\uDCFF-\uDD06\uDD09\uDD0C-\uDD13\uDD15\uDD16\uDD18-\uDD2F\uDD3F\uDD41\uDDA0-\uDDA7\uDDAA-\uDDD0\uDDE1\uDDE3\uDE00\uDE0B-\uDE32\uDE3A\uDE50\uDE5C-\uDE89\uDE9D\uDEB0-\uDEF8\uDFC0-\uDFE0]|\uD807[\uDC00-\uDC08\uDC0A-\uDC2E\uDC40\uDC72-\uDC8F\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD30\uDD46\uDD60-\uDD65\uDD67\uDD68\uDD6A-\uDD89\uDD98\uDDB0-\uDDDB\uDEE0-\uDEF2\uDF02\uDF04-\uDF10\uDF12-\uDF33\uDFB0]|\uD808[\uDC00-\uDF99]|\uD809[\uDC80-\uDD43]|\uD80B[\uDF90-\uDFF0]|[\uD80C\uD80E\uD80F\uD81C-\uD822\uD840-\uD868\uD86A-\uD86D\uD86F-\uD872\uD874-\uD879\uD880-\uD883\uD885-\uD88C][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2F\uDC41-\uDC46\uDC60-\uDFFF]|\uD810[\uDC00-\uDFFA]|\uD811[\uDC00-\uDE46]|\uD818[\uDD00-\uDD1D]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDE70-\uDEBE\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDD40-\uDD6C\uDE40-\uDE7F\uDEA0-\uDEB8\uDEBB-\uDED3\uDF00-\uDF4A\uDF50\uDF93-\uDF9F\uDFE0\uDFE1\uDFE3\uDFF2\uDFF3]|\uD823[\uDC00-\uDCD5\uDCFF-\uDD1E\uDD80-\uDDF2]|\uD82B[\uDFF0-\uDFF3\uDFF5-\uDFFB\uDFFD\uDFFE]|\uD82C[\uDC00-\uDD22\uDD32\uDD50-\uDD52\uDD55\uDD64-\uDD67\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB]|\uD837[\uDF00-\uDF1E\uDF25-\uDF2A]|\uD838[\uDC30-\uDC6D\uDD00-\uDD2C\uDD37-\uDD3D\uDD4E\uDE90-\uDEAD\uDEC0-\uDEEB]|\uD839[\uDCD0-\uDCEB\uDDD0-\uDDED\uDDF0\uDEC0-\uDEDE\uDEE0-\uDEE2\uDEE4\uDEE5\uDEE7-\uDEED\uDEF0-\uDEF4\uDEFE\uDEFF\uDFE0-\uDFE6\uDFE8-\uDFEB\uDFED\uDFEE\uDFF0-\uDFFE]|\uD83A[\uDC00-\uDCC4\uDD00-\uDD43\uDD4B]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDEDF\uDF00-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEAD\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0\uDFF0-\uDFFF]|\uD87B[\uDC00-\uDE5D]|\uD87E[\uDC00-\uDE1D]|\uD884[\uDC00-\uDF4A\uDF50-\uDFFF]|\uD88D[\uDC00-\uDC79])*$/.test(e)},{name:`string`,test:pt},{name:`Chain`,test:Xt},{name:`Array`,test:mt},{name:`Matrix`,test:ht},{name:`DenseMatrix`,test:_t},{name:`SparseMatrix`,test:vt},{name:`Range`,test:yt},{name:`Index`,test:bt},{name:`boolean`,test:xt},{name:`ResultSet`,test:St},{name:`Help`,test:Ct},{name:`function`,test:wt},{name:`Date`,test:Tt},{name:`RegExp`,test:Et},{name:`null`,test:jt},{name:`undefined`,test:Mt},{name:`AccessorNode`,test:Nt},{name:`ArrayNode`,test:Pt},{name:`AssignmentNode`,test:Ft},{name:`BlockNode`,test:It},{name:`ConditionalNode`,test:Lt},{name:`ConstantNode`,test:Rt},{name:`FunctionNode`,test:Vt},{name:`FunctionAssignmentNode`,test:Bt},{name:`IndexNode`,test:Ht},{name:`Node`,test:Ut},{name:`ObjectNode`,test:Wt},{name:`OperatorNode`,test:Gt},{name:`ParenthesisNode`,test:Kt},{name:`RangeNode`,test:qt},{name:`RelationalNode`,test:Jt},{name:`SymbolNode`,test:Yt},{name:`Map`,test:Ot},{name:`Object`,test:Dt}]),a.addConversions([{from:`number`,to:`BigNumber`,convert:function(e){if(t||Zn(e),Ln(e)>15)throw TypeError(`Cannot implicitly convert a number with >15 significant digits to BigNumber (value: `+e+`). Use function bignumber(x) to convert to BigNumber.`);return new t(e)}},{from:`number`,to:`Complex`,convert:function(e){return n||Qn(e),new n(e,0)}},{from:`BigNumber`,to:`Complex`,convert:function(e){return n||Qn(e),new n(e.toNumber(),0)}},{from:`bigint`,to:`number`,convert:function(e){if(e>2**53-1)throw TypeError(`Cannot implicitly convert bigint to number: value exceeds the max safe integer value (value: `+e+`)`);return Number(e)}},{from:`bigint`,to:`BigNumber`,convert:function(e){return t||Zn(e),new t(e.toString())}},{from:`bigint`,to:`Fraction`,convert:function(e){return i||er(e),new i(e)}},{from:`Fraction`,to:`BigNumber`,convert:function(e){throw TypeError(`Cannot implicitly convert a Fraction to BigNumber or vice versa. Use function bignumber(x) to convert to BigNumber or fraction(x) to convert to Fraction.`)}},{from:`Fraction`,to:`Complex`,convert:function(e){return n||Qn(e),new n(e.valueOf(),0)}},{from:`number`,to:`Fraction`,convert:function(e){i||er(e);var t=new i(e);if(t.valueOf()!==e)throw TypeError(`Cannot implicitly convert a number to a Fraction when there will be a loss of precision (value: `+e+`). Use function fraction(x) to convert to Fraction.`);return t}},{from:`string`,to:`number`,convert:function(e){var t=Number(e);if(isNaN(t))throw Error(`Cannot convert "`+e+`" to a number`);return t}},{from:`string`,to:`BigNumber`,convert:function(e){t||Zn(e);try{return new t(e)}catch{throw Error(`Cannot convert "`+e+`" to BigNumber`)}}},{from:`string`,to:`bigint`,convert:function(e){try{return BigInt(e)}catch{throw Error(`Cannot convert "`+e+`" to BigInt`)}}},{from:`string`,to:`Fraction`,convert:function(e){i||er(e);try{return new i(e)}catch{throw Error(`Cannot convert "`+e+`" to Fraction`)}}},{from:`string`,to:`Complex`,convert:function(e){n||Qn(e);try{return new n(e)}catch{throw Error(`Cannot convert "`+e+`" to Complex`)}}},{from:`boolean`,to:`number`,convert:function(e){return+e}},{from:`boolean`,to:`BigNumber`,convert:function(e){return t||Zn(e),new t(+e)}},{from:`boolean`,to:`bigint`,convert:function(e){return BigInt(+e)}},{from:`boolean`,to:`Fraction`,convert:function(e){return i||er(e),new i(+e)}},{from:`boolean`,to:`string`,convert:function(e){return String(e)}},{from:`Array`,to:`Matrix`,convert:function(e){return r||$n(),new r(e)}},{from:`Matrix`,to:`Array`,convert:function(e){return e.valueOf()}}]),a.onMismatch=(e,t,n)=>{var r=a.createError(e,t,n);if([`wrongType`,`mismatch`].includes(r.data.category)&&t.length===1&>(t[0])&&n.some(e=>!e.params.includes(`,`))){var i=TypeError(`Function '${e}' doesn't apply to matrices. To call it elementwise on a matrix 'M', try 'map(M, ${e})'.`);throw i.data=r.data,i}throw r},a.onMismatch=(e,t,n)=>{var r=a.createError(e,t,n);if([`wrongType`,`mismatch`].includes(r.data.category)&&t.length===1&>(t[0])&&n.some(e=>!e.params.includes(`,`))){var i=TypeError(`Function '${e}' doesn't apply to matrices. To call it elementwise on a matrix 'M', try 'map(M, ${e})'.`);throw i.data=r.data,i}throw r},a});function Zn(e){throw Error(`Cannot convert value ${e} into a BigNumber: no class 'BigNumber' provided`)}function Qn(e){throw Error(`Cannot convert value ${e} into a Complex number: no class 'Complex' provided`)}function $n(){throw Error(`Cannot convert array into a Matrix: no class 'DenseMatrix' provided`)}function er(e){throw Error(`Cannot convert value ${e} into a Fraction, no class 'Fraction' provided.`)}var tr=K(`ResultSet`,[],()=>{function e(t){if(!(this instanceof e))throw SyntaxError(`Constructor must be called with the new operator`);this.entries=t||[]}return e.prototype.type=`ResultSet`,e.prototype.isResultSet=!0,e.prototype.valueOf=function(){return this.entries},e.prototype.toString=function(){return`[`+this.entries.map(String).join(`, `)+`]`},e.prototype.toJSON=function(){return{mathjs:`ResultSet`,entries:this.entries}},e.fromJSON=function(t){return new e(t.entries)},e},{isClass:!0}),nr=9e15,rr=1e9,ir=`0123456789abcdef`,ar=`2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058`,or=`3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789`,sr={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-nr,maxE:nr,crypto:!1},cr,lr,ur=!0,dr=`[DecimalError] `,fr=dr+`Invalid argument: `,pr=dr+`Precision limit exceeded`,mr=dr+`crypto unavailable`,hr=`[object Decimal]`,gr=Math.floor,_r=Math.pow,vr=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,yr=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,br=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,xr=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,Sr=1e7,Cr=7,wr=9007199254740991,Tr=ar.length-1,Er=or.length-1,q={toStringTag:hr};q.absoluteValue=q.abs=function(){var e=new this.constructor(this);return e.s<0&&(e.s=1),Nr(e)},q.ceil=function(){return Nr(new this.constructor(this),this.e+1,2)},q.clampedTo=q.clamp=function(e,t){var n,r=this,i=r.constructor;if(e=new i(e),t=new i(t),!e.s||!t.s)return new i(NaN);if(e.gt(t))throw Error(fr+t);return n=r.cmp(e),n<0?e:r.cmp(t)>0?t:new i(r)},q.comparedTo=q.cmp=function(e){var t,n,r,i,a=this,o=a.d,s=(e=new a.constructor(e)).d,c=a.s,l=e.s;if(!o||!s)return!c||!l?NaN:c===l?o===s?0:!o^c<0?1:-1:c;if(!o[0]||!s[0])return o[0]?c:s[0]?-l:0;if(c!==l)return c;if(a.e!==e.e)return a.e>e.e^c<0?1:-1;for(r=o.length,i=s.length,t=0,n=r<i?r:i;t<n;++t)if(o[t]!==s[t])return o[t]>s[t]^c<0?1:-1;return r===i?0:r>i^c<0?1:-1},q.cosine=q.cos=function(){var e,t,n=this,r=n.constructor;return n.d?n.d[0]?(e=r.precision,t=r.rounding,r.precision=e+Math.max(n.e,n.sd())+Cr,r.rounding=1,n=jr(r,Zr(r,n)),r.precision=e,r.rounding=t,Nr(lr==2||lr==3?n.neg():n,e,t,!0)):new r(1):new r(NaN)},q.cubeRoot=q.cbrt=function(){var e,t,n,r,i,a,o,s,c,l,u=this,d=u.constructor;if(!u.isFinite()||u.isZero())return new d(u);for(ur=!1,a=u.s*_r(u.s*u,1/3),!a||Math.abs(a)==1/0?(n=Dr(u.d),e=u.e,(a=(e-n.length+1)%3)&&(n+=a==1||a==-2?`0`:`00`),a=_r(n,1/3),e=gr((e+1)/3)-(e%3==(e<0?-1:2)),a==1/0?n=`5e`+e:(n=a.toExponential(),n=n.slice(0,n.indexOf(`e`)+1)+e),r=new d(n),r.s=u.s):r=new d(a.toString()),o=(e=d.precision)+3;;)if(s=r,c=s.times(s).times(s),l=c.plus(u),r=Mr(l.plus(u).times(s),l.plus(c),o+2,1),Dr(s.d).slice(0,o)===(n=Dr(r.d)).slice(0,o))if(n=n.slice(o-3,o+1),n==`9999`||!i&&n==`4999`){if(!i&&(Nr(s,e+1,0),s.times(s).times(s).eq(u))){r=s;break}o+=4,i=1}else{(!+n||!+n.slice(1)&&n.charAt(0)==`5`)&&(Nr(r,e+1,1),t=!r.times(r).times(r).eq(u));break}return ur=!0,Nr(r,e,d.rounding,t)},q.decimalPlaces=q.dp=function(){var e,t=this.d,n=NaN;if(t){if(e=t.length-1,n=(e-gr(this.e/Cr))*Cr,e=t[e],e)for(;e%10==0;e/=10)n--;n<0&&(n=0)}return n},q.dividedBy=q.div=function(e){return Mr(this,new this.constructor(e))},q.dividedToIntegerBy=q.divToInt=function(e){var t=this,n=t.constructor;return Nr(Mr(t,new n(e),0,1,1),n.precision,n.rounding)},q.equals=q.eq=function(e){return this.cmp(e)===0},q.floor=function(){return Nr(new this.constructor(this),this.e+1,3)},q.greaterThan=q.gt=function(e){return this.cmp(e)>0},q.greaterThanOrEqualTo=q.gte=function(e){var t=this.cmp(e);return t==1||t===0},q.hyperbolicCosine=q.cosh=function(){var e,t,n,r,i,a=this,o=a.constructor,s=new o(1);if(!a.isFinite())return new o(a.s?1/0:NaN);if(a.isZero())return s;n=o.precision,r=o.rounding,o.precision=n+Math.max(a.e,a.sd())+4,o.rounding=1,i=a.d.length,i<32?(e=Math.ceil(i/3),t=(1/Xr(4,e)).toString()):(e=16,t=`2.3283064365386962890625e-10`),a=Yr(o,1,a.times(t),new o(1),!0);for(var c,l=e,u=new o(8);l--;)c=a.times(a),a=s.minus(c.times(u.minus(c.times(u))));return Nr(a,o.precision=n,o.rounding=r,!0)},q.hyperbolicSine=q.sinh=function(){var e,t,n,r,i=this,a=i.constructor;if(!i.isFinite()||i.isZero())return new a(i);if(t=a.precision,n=a.rounding,a.precision=t+Math.max(i.e,i.sd())+4,a.rounding=1,r=i.d.length,r<3)i=Yr(a,2,i,i,!0);else{e=1.4*Math.sqrt(r),e=e>16?16:e|0,i=i.times(1/Xr(5,e)),i=Yr(a,2,i,i,!0);for(var o,s=new a(5),c=new a(16),l=new a(20);e--;)o=i.times(i),i=i.times(s.plus(o.times(c.times(o).plus(l))))}return a.precision=t,a.rounding=n,Nr(i,t,n,!0)},q.hyperbolicTangent=q.tanh=function(){var e,t,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+7,r.rounding=1,Mr(n.sinh(),n.cosh(),r.precision=e,r.rounding=t)):new r(n.s)},q.inverseCosine=q.acos=function(){var e=this,t=e.constructor,n=e.abs().cmp(1),r=t.precision,i=t.rounding;return n===-1?e.isZero()?Lr(t,r+4,i).times(.5):(t.precision=r+6,t.rounding=1,e=new t(1).minus(e).div(e.plus(1)).sqrt().atan(),t.precision=r,t.rounding=i,e.times(2)):n===0?e.isNeg()?Lr(t,r,i):new t(0):new t(NaN)},q.inverseHyperbolicCosine=q.acosh=function(){var e,t,n=this,r=n.constructor;return n.lte(1)?new r(n.eq(1)?0:NaN):n.isFinite()?(e=r.precision,t=r.rounding,r.precision=e+Math.max(Math.abs(n.e),n.sd())+4,r.rounding=1,ur=!1,n=n.times(n).minus(1).sqrt().plus(n),ur=!0,r.precision=e,r.rounding=t,n.ln()):new r(n)},q.inverseHyperbolicSine=q.asinh=function(){var e,t,n=this,r=n.constructor;return!n.isFinite()||n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+2*Math.max(Math.abs(n.e),n.sd())+6,r.rounding=1,ur=!1,n=n.times(n).plus(1).sqrt().plus(n),ur=!0,r.precision=e,r.rounding=t,n.ln())},q.inverseHyperbolicTangent=q.atanh=function(){var e,t,n,r,i=this,a=i.constructor;return i.isFinite()?i.e>=0?new a(i.abs().eq(1)?i.s/0:i.isZero()?i:NaN):(e=a.precision,t=a.rounding,r=i.sd(),Math.max(r,e)<2*-i.e-1?Nr(new a(i),e,t,!0):(a.precision=n=r-i.e,i=Mr(i.plus(1),new a(1).minus(i),n+e,1),a.precision=e+4,a.rounding=1,i=i.ln(),a.precision=e,a.rounding=t,i.times(.5))):new a(NaN)},q.inverseSine=q.asin=function(){var e,t,n,r,i=this,a=i.constructor;return i.isZero()?new a(i):(t=i.abs().cmp(1),n=a.precision,r=a.rounding,t===-1?(a.precision=n+6,a.rounding=1,i=i.div(new a(1).minus(i.times(i)).sqrt().plus(1)).atan(),a.precision=n,a.rounding=r,i.times(2)):t===0?(e=Lr(a,n+4,r).times(.5),e.s=i.s,e):new a(NaN))},q.inverseTangent=q.atan=function(){var e,t,n,r,i,a,o,s,c,l=this,u=l.constructor,d=u.precision,f=u.rounding;if(!l.isFinite()){if(!l.s)return new u(NaN);if(d+4<=Er)return o=Lr(u,d+4,f).times(.5),o.s=l.s,o}else if(l.isZero())return new u(l);else if(l.abs().eq(1)&&d+4<=Er)return o=Lr(u,d+4,f).times(.25),o.s=l.s,o;for(u.precision=s=d+10,u.rounding=1,n=Math.min(28,s/Cr+2|0),e=n;e;--e)l=l.div(l.times(l).plus(1).sqrt().plus(1));for(ur=!1,t=Math.ceil(s/Cr),r=1,c=l.times(l),o=new u(l),i=l;e!==-1;)if(i=i.times(c),a=o.minus(i.div(r+=2)),i=i.times(c),o=a.plus(i.div(r+=2)),o.d[t]!==void 0)for(e=t;o.d[e]===a.d[e]&&e--;);return n&&(o=o.times(2<<n-1)),ur=!0,Nr(o,u.precision=d,u.rounding=f,!0)},q.isFinite=function(){return!!this.d},q.isInteger=q.isInt=function(){return!!this.d&&gr(this.e/Cr)>this.d.length-2},q.isNaN=function(){return!this.s},q.isNegative=q.isNeg=function(){return this.s<0},q.isPositive=q.isPos=function(){return this.s>0},q.isZero=function(){return!!this.d&&this.d[0]===0},q.lessThan=q.lt=function(e){return this.cmp(e)<0},q.lessThanOrEqualTo=q.lte=function(e){return this.cmp(e)<1},q.logarithm=q.log=function(e){var t,n,r,i,a,o,s,c,l=this,u=l.constructor,d=u.precision,f=u.rounding,p=5;if(e==null)e=new u(10),t=!0;else{if(e=new u(e),n=e.d,e.s<0||!n||!n[0]||e.eq(1))return new u(NaN);t=e.eq(10)}if(n=l.d,l.s<0||!n||!n[0]||l.eq(1))return new u(n&&!n[0]?-1/0:l.s==1?n?0:1/0:NaN);if(t)if(n.length>1)a=!0;else{for(i=n[0];i%10==0;)i/=10;a=i!==1}if(ur=!1,s=d+p,o=Wr(l,s),r=t?Ir(u,s+10):Wr(e,s),c=Mr(o,r,s,1),kr(c.d,i=d,f))do if(s+=10,o=Wr(l,s),r=t?Ir(u,s+10):Wr(e,s),c=Mr(o,r,s,1),!a){+Dr(c.d).slice(i+1,i+15)+1==0x5af3107a4000&&(c=Nr(c,d+1,0));break}while(kr(c.d,i+=10,f));return ur=!0,Nr(c,d,f)},q.minus=q.sub=function(e){var t,n,r,i,a,o,s,c,l,u,d,f,p=this,m=p.constructor;if(e=new m(e),!p.d||!e.d)return!p.s||!e.s?e=new m(NaN):p.d?e.s=-e.s:e=new m(e.d||p.s!==e.s?p:NaN),e;if(p.s!=e.s)return e.s=-e.s,p.plus(e);if(l=p.d,f=e.d,s=m.precision,c=m.rounding,!l[0]||!f[0]){if(f[0])e.s=-e.s;else if(l[0])e=new m(p);else return new m(c===3?-0:0);return ur?Nr(e,s,c):e}if(n=gr(e.e/Cr),u=gr(p.e/Cr),l=l.slice(),a=u-n,a){for(d=a<0,d?(t=l,a=-a,o=f.length):(t=f,n=u,o=l.length),r=Math.max(Math.ceil(s/Cr),o)+2,a>r&&(a=r,t.length=1),t.reverse(),r=a;r--;)t.push(0);t.reverse()}else{for(r=l.length,o=f.length,d=r<o,d&&(o=r),r=0;r<o;r++)if(l[r]!=f[r]){d=l[r]<f[r];break}a=0}for(d&&(t=l,l=f,f=t,e.s=-e.s),o=l.length,r=f.length-o;r>0;--r)l[o++]=0;for(r=f.length;r>a;){if(l[--r]<f[r]){for(i=r;i&&l[--i]===0;)l[i]=Sr-1;--l[i],l[r]+=Sr}l[r]-=f[r]}for(;l[--o]===0;)l.pop();for(;l[0]===0;l.shift())--n;return l[0]?(e.d=l,e.e=Fr(l,n),ur?Nr(e,s,c):e):new m(c===3?-0:0)},q.modulo=q.mod=function(e){var t,n=this,r=n.constructor;return e=new r(e),!n.d||!e.s||e.d&&!e.d[0]?new r(NaN):!e.d||n.d&&!n.d[0]?Nr(new r(n),r.precision,r.rounding):(ur=!1,r.modulo==9?(t=Mr(n,e.abs(),0,3,1),t.s*=e.s):t=Mr(n,e,0,r.modulo,1),t=t.times(e),ur=!0,n.minus(t))},q.naturalExponential=q.exp=function(){return Ur(this)},q.naturalLogarithm=q.ln=function(){return Wr(this)},q.negated=q.neg=function(){var e=new this.constructor(this);return e.s=-e.s,Nr(e)},q.plus=q.add=function(e){var t,n,r,i,a,o,s,c,l,u,d=this,f=d.constructor;if(e=new f(e),!d.d||!e.d)return!d.s||!e.s?e=new f(NaN):d.d||(e=new f(e.d||d.s===e.s?d:NaN)),e;if(d.s!=e.s)return e.s=-e.s,d.minus(e);if(l=d.d,u=e.d,s=f.precision,c=f.rounding,!l[0]||!u[0])return u[0]||(e=new f(d)),ur?Nr(e,s,c):e;if(a=gr(d.e/Cr),r=gr(e.e/Cr),l=l.slice(),i=a-r,i){for(i<0?(n=l,i=-i,o=u.length):(n=u,r=a,o=l.length),a=Math.ceil(s/Cr),o=a>o?a+1:o+1,i>o&&(i=o,n.length=1),n.reverse();i--;)n.push(0);n.reverse()}for(o=l.length,i=u.length,o-i<0&&(i=o,n=u,u=l,l=n),t=0;i;)t=(l[--i]=l[i]+u[i]+t)/Sr|0,l[i]%=Sr;for(t&&(l.unshift(t),++r),o=l.length;l[--o]==0;)l.pop();return e.d=l,e.e=Fr(l,r),ur?Nr(e,s,c):e},q.precision=q.sd=function(e){var t,n=this;if(e!==void 0&&e!==!!e&&e!==1&&e!==0)throw Error(fr+e);return n.d?(t=Rr(n.d),e&&n.e+1>t&&(t=n.e+1)):t=NaN,t},q.round=function(){var e=this,t=e.constructor;return Nr(new t(e),e.e+1,t.rounding)},q.sine=q.sin=function(){var e,t,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+Math.max(n.e,n.sd())+Cr,r.rounding=1,n=Jr(r,Zr(r,n)),r.precision=e,r.rounding=t,Nr(lr>2?n.neg():n,e,t,!0)):new r(NaN)},q.squareRoot=q.sqrt=function(){var e,t,n,r,i,a,o=this,s=o.d,c=o.e,l=o.s,u=o.constructor;if(l!==1||!s||!s[0])return new u(!l||l<0&&(!s||s[0])?NaN:s?o:1/0);for(ur=!1,l=Math.sqrt(+o),l==0||l==1/0?(t=Dr(s),(t.length+c)%2==0&&(t+=`0`),l=Math.sqrt(t),c=gr((c+1)/2)-(c<0||c%2),l==1/0?t=`5e`+c:(t=l.toExponential(),t=t.slice(0,t.indexOf(`e`)+1)+c),r=new u(t)):r=new u(l.toString()),n=(c=u.precision)+3;;)if(a=r,r=a.plus(Mr(o,a,n+2,1)).times(.5),Dr(a.d).slice(0,n)===(t=Dr(r.d)).slice(0,n))if(t=t.slice(n-3,n+1),t==`9999`||!i&&t==`4999`){if(!i&&(Nr(a,c+1,0),a.times(a).eq(o))){r=a;break}n+=4,i=1}else{(!+t||!+t.slice(1)&&t.charAt(0)==`5`)&&(Nr(r,c+1,1),e=!r.times(r).eq(o));break}return ur=!0,Nr(r,c,u.rounding,e)},q.tangent=q.tan=function(){var e,t,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+10,r.rounding=1,n=n.sin(),n.s=1,n=Mr(n,new r(1).minus(n.times(n)).sqrt(),e+10,0),r.precision=e,r.rounding=t,Nr(lr==2||lr==4?n.neg():n,e,t,!0)):new r(NaN)},q.times=q.mul=function(e){var t,n,r,i,a,o,s,c,l,u=this,d=u.constructor,f=u.d,p=(e=new d(e)).d;if(e.s*=u.s,!f||!f[0]||!p||!p[0])return new d(!e.s||f&&!f[0]&&!p||p&&!p[0]&&!f?NaN:!f||!p?e.s/0:e.s*0);for(n=gr(u.e/Cr)+gr(e.e/Cr),c=f.length,l=p.length,c<l&&(a=f,f=p,p=a,o=c,c=l,l=o),a=[],o=c+l,r=o;r--;)a.push(0);for(r=l;--r>=0;){for(t=0,i=c+r;i>r;)s=a[i]+p[r]*f[i-r-1]+t,a[i--]=s%Sr|0,t=s/Sr|0;a[i]=(a[i]+t)%Sr|0}for(;!a[--o];)a.pop();return t?++n:a.shift(),e.d=a,e.e=Fr(a,n),ur?Nr(e,d.precision,d.rounding):e},q.toBinary=function(e,t){return Qr(this,2,e,t)},q.toDecimalPlaces=q.toDP=function(e,t){var n=this,r=n.constructor;return n=new r(n),e===void 0?n:(Or(e,0,rr),t===void 0?t=r.rounding:Or(t,0,8),Nr(n,e+n.e+1,t))},q.toExponential=function(e,t){var n,r=this,i=r.constructor;return e===void 0?n=Pr(r,!0):(Or(e,0,rr),t===void 0?t=i.rounding:Or(t,0,8),r=Nr(new i(r),e+1,t),n=Pr(r,!0,e+1)),r.isNeg()&&!r.isZero()?`-`+n:n},q.toFixed=function(e,t){var n,r,i=this,a=i.constructor;return e===void 0?n=Pr(i):(Or(e,0,rr),t===void 0?t=a.rounding:Or(t,0,8),r=Nr(new a(i),e+i.e+1,t),n=Pr(r,!1,e+r.e+1)),i.isNeg()&&!i.isZero()?`-`+n:n},q.toFraction=function(e){var t,n,r,i,a,o,s,c,l,u,d,f,p=this,m=p.d,h=p.constructor;if(!m)return new h(p);if(l=n=new h(1),r=c=new h(0),t=new h(r),a=t.e=Rr(m)-p.e-1,o=a%Cr,t.d[0]=_r(10,o<0?Cr+o:o),e==null)e=a>0?t:l;else{if(s=new h(e),!s.isInt()||s.lt(l))throw Error(fr+s);e=s.gt(t)?a>0?t:l:s}for(ur=!1,s=new h(Dr(m)),u=h.precision,h.precision=a=m.length*Cr*2;d=Mr(s,t,0,1,1),i=n.plus(d.times(r)),i.cmp(e)!=1;)n=r,r=i,i=l,l=c.plus(d.times(i)),c=i,i=t,t=s.minus(d.times(i)),s=i;return i=Mr(e.minus(n),r,0,1,1),c=c.plus(i.times(l)),n=n.plus(i.times(r)),c.s=l.s=p.s,f=Mr(l,r,a,1).minus(p).abs().cmp(Mr(c,n,a,1).minus(p).abs())<1?[l,r]:[c,n],h.precision=u,ur=!0,f},q.toHexadecimal=q.toHex=function(e,t){return Qr(this,16,e,t)},q.toNearest=function(e,t){var n=this,r=n.constructor;if(n=new r(n),e==null){if(!n.d)return n;e=new r(1),t=r.rounding}else{if(e=new r(e),t===void 0?t=r.rounding:Or(t,0,8),!n.d)return e.s?n:e;if(!e.d)return e.s&&=n.s,e}return e.d[0]?(ur=!1,n=Mr(n,e,0,t,1).times(e),ur=!0,Nr(n)):(e.s=n.s,n=e),n},q.toNumber=function(){return+this},q.toOctal=function(e,t){return Qr(this,8,e,t)},q.toPower=q.pow=function(e){var t,n,r,i,a,o,s=this,c=s.constructor,l=+(e=new c(e));if(!s.d||!e.d||!s.d[0]||!e.d[0])return new c(_r(+s,l));if(s=new c(s),s.eq(1))return s;if(r=c.precision,a=c.rounding,e.eq(1))return Nr(s,r,a);if(t=gr(e.e/Cr),t>=e.d.length-1&&(n=l<0?-l:l)<=wr)return i=Br(c,s,n,r),e.s<0?new c(1).div(i):Nr(i,r,a);if(o=s.s,o<0){if(t<e.d.length-1)return new c(NaN);if(e.d[t]&1||(o=1),s.e==0&&s.d[0]==1&&s.d.length==1)return s.s=o,s}return n=_r(+s,l),t=n==0||!isFinite(n)?gr(l*(Math.log(`0.`+Dr(s.d))/Math.LN10+s.e+1)):new c(n+``).e,t>c.maxE+1||t<c.minE-1?new c(t>0?o/0:0):(ur=!1,c.rounding=s.s=1,n=Math.min(12,(t+``).length),i=Ur(e.times(Wr(s,r+n)),r),i.d&&(i=Nr(i,r+5,1),kr(i.d,r,a)&&(t=r+10,i=Nr(Ur(e.times(Wr(s,t+n)),t),t+5,1),+Dr(i.d).slice(r+1,r+15)+1==0x5af3107a4000&&(i=Nr(i,r+1,0)))),i.s=o,ur=!0,c.rounding=a,Nr(i,r,a))},q.toPrecision=function(e,t){var n,r=this,i=r.constructor;return e===void 0?n=Pr(r,r.e<=i.toExpNeg||r.e>=i.toExpPos):(Or(e,1,rr),t===void 0?t=i.rounding:Or(t,0,8),r=Nr(new i(r),e,t),n=Pr(r,e<=r.e||r.e<=i.toExpNeg,e)),r.isNeg()&&!r.isZero()?`-`+n:n},q.toSignificantDigits=q.toSD=function(e,t){var n=this,r=n.constructor;return e===void 0?(e=r.precision,t=r.rounding):(Or(e,1,rr),t===void 0?t=r.rounding:Or(t,0,8)),Nr(new r(n),e,t)},q.toString=function(){var e=this,t=e.constructor,n=Pr(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()&&!e.isZero()?`-`+n:n},q.truncated=q.trunc=function(){return Nr(new this.constructor(this),this.e+1,1)},q.valueOf=q.toJSON=function(){var e=this,t=e.constructor,n=Pr(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()?`-`+n:n};function Dr(e){var t,n,r,i=e.length-1,a=``,o=e[0];if(i>0){for(a+=o,t=1;t<i;t++)r=e[t]+``,n=Cr-r.length,n&&(a+=zr(n)),a+=r;o=e[t],r=o+``,n=Cr-r.length,n&&(a+=zr(n))}else if(o===0)return`0`;for(;o%10==0;)o/=10;return a+o}function Or(e,t,n){if(e!==~~e||e<t||e>n)throw Error(fr+e)}function kr(e,t,n,r){var i,a,o,s;for(a=e[0];a>=10;a/=10)--t;return--t<0?(t+=Cr,i=0):(i=Math.ceil((t+1)/Cr),t%=Cr),a=_r(10,Cr-t),s=e[i]%a|0,r==null?t<3?(t==0?s=s/100|0:t==1&&(s=s/10|0),o=n<4&&s==99999||n>3&&s==49999||s==5e4||s==0):o=(n<4&&s+1==a||n>3&&s+1==a/2)&&(e[i+1]/a/100|0)==_r(10,t-2)-1||(s==a/2||s==0)&&(e[i+1]/a/100|0)==0:t<4?(t==0?s=s/1e3|0:t==1?s=s/100|0:t==2&&(s=s/10|0),o=(r||n<4)&&s==9999||!r&&n>3&&s==4999):o=((r||n<4)&&s+1==a||!r&&n>3&&s+1==a/2)&&(e[i+1]/a/1e3|0)==_r(10,t-3)-1,o}function Ar(e,t,n){for(var r,i=[0],a,o=0,s=e.length;o<s;){for(a=i.length;a--;)i[a]*=t;for(i[0]+=ir.indexOf(e.charAt(o++)),r=0;r<i.length;r++)i[r]>n-1&&(i[r+1]===void 0&&(i[r+1]=0),i[r+1]+=i[r]/n|0,i[r]%=n)}return i.reverse()}function jr(e,t){var n,r,i;if(t.isZero())return t;r=t.d.length,r<32?(n=Math.ceil(r/3),i=(1/Xr(4,n)).toString()):(n=16,i=`2.3283064365386962890625e-10`),e.precision+=n,t=Yr(e,1,t.times(i),new e(1));for(var a=n;a--;){var o=t.times(t);t=o.times(o).minus(o).times(8).plus(1)}return e.precision-=n,t}var Mr=(function(){function e(e,t,n){var r,i=0,a=e.length;for(e=e.slice();a--;)r=e[a]*t+i,e[a]=r%n|0,i=r/n|0;return i&&e.unshift(i),e}function t(e,t,n,r){var i,a;if(n!=r)a=n>r?1:-1;else for(i=a=0;i<n;i++)if(e[i]!=t[i]){a=e[i]>t[i]?1:-1;break}return a}function n(e,t,n,r){for(var i=0;n--;)e[n]-=i,i=+(e[n]<t[n]),e[n]=i*r+e[n]-t[n];for(;!e[0]&&e.length>1;)e.shift()}return function(r,i,a,o,s,c){var l,u,d,f,p,m,h,g,_,v,y,b,x,S,C,w,T,E,D,O,k=r.constructor,A=r.s==i.s?1:-1,j=r.d,M=i.d;if(!j||!j[0]||!M||!M[0])return new k(!r.s||!i.s||(j?M&&j[0]==M[0]:!M)?NaN:j&&j[0]==0||!M?A*0:A/0);for(c?(p=1,u=r.e-i.e):(c=Sr,p=Cr,u=gr(r.e/p)-gr(i.e/p)),D=M.length,T=j.length,_=new k(A),v=_.d=[],d=0;M[d]==(j[d]||0);d++);if(M[d]>(j[d]||0)&&u--,a==null?(S=a=k.precision,o=k.rounding):S=s?a+(r.e-i.e)+1:a,S<0)v.push(1),m=!0;else{if(S=S/p+2|0,d=0,D==1){for(f=0,M=M[0],S++;(d<T||f)&&S--;d++)C=f*c+(j[d]||0),v[d]=C/M|0,f=C%M|0;m=f||d<T}else{for(f=c/(M[0]+1)|0,f>1&&(M=e(M,f,c),j=e(j,f,c),D=M.length,T=j.length),w=D,y=j.slice(0,D),b=y.length;b<D;)y[b++]=0;O=M.slice(),O.unshift(0),E=M[0],M[1]>=c/2&&++E;do f=0,l=t(M,y,D,b),l<0?(x=y[0],D!=b&&(x=x*c+(y[1]||0)),f=x/E|0,f>1?(f>=c&&(f=c-1),h=e(M,f,c),g=h.length,b=y.length,l=t(h,y,g,b),l==1&&(f--,n(h,D<g?O:M,g,c))):(f==0&&(l=f=1),h=M.slice()),g=h.length,g<b&&h.unshift(0),n(y,h,b,c),l==-1&&(b=y.length,l=t(M,y,D,b),l<1&&(f++,n(y,D<b?O:M,b,c))),b=y.length):l===0&&(f++,y=[0]),v[d++]=f,l&&y[0]?y[b++]=j[w]||0:(y=[j[w]],b=1);while((w++<T||y[0]!==void 0)&&S--);m=y[0]!==void 0}v[0]||v.shift()}if(p==1)_.e=u,cr=m;else{for(d=1,f=v[0];f>=10;f/=10)d++;_.e=d+u*p-1,Nr(_,s?a+_.e+1:a,o,m)}return _}})();function Nr(e,t,n,r){var i,a,o,s,c,l,u,d,f,p=e.constructor;out:if(t!=null){if(d=e.d,!d)return e;for(i=1,s=d[0];s>=10;s/=10)i++;if(a=t-i,a<0)a+=Cr,o=t,u=d[f=0],c=u/_r(10,i-o-1)%10|0;else if(f=Math.ceil((a+1)/Cr),s=d.length,f>=s)if(r){for(;s++<=f;)d.push(0);u=c=0,i=1,a%=Cr,o=a-Cr+1}else break out;else{for(u=s=d[f],i=1;s>=10;s/=10)i++;a%=Cr,o=a-Cr+i,c=o<0?0:u/_r(10,i-o-1)%10|0}if(r=r||t<0||d[f+1]!==void 0||(o<0?u:u%_r(10,i-o-1)),l=n<4?(c||r)&&(n==0||n==(e.s<0?3:2)):c>5||c==5&&(n==4||r||n==6&&(a>0?o>0?u/_r(10,i-o):0:d[f-1])%10&1||n==(e.s<0?8:7)),t<1||!d[0])return d.length=0,l?(t-=e.e+1,d[0]=_r(10,(Cr-t%Cr)%Cr),e.e=-t||0):d[0]=e.e=0,e;if(a==0?(d.length=f,s=1,f--):(d.length=f+1,s=_r(10,Cr-a),d[f]=o>0?(u/_r(10,i-o)%_r(10,o)|0)*s:0),l)for(;;)if(f==0){for(a=1,o=d[0];o>=10;o/=10)a++;for(o=d[0]+=s,s=1;o>=10;o/=10)s++;a!=s&&(e.e++,d[0]==Sr&&(d[0]=1));break}else{if(d[f]+=s,d[f]!=Sr)break;d[f--]=0,s=1}for(a=d.length;d[--a]===0;)d.pop()}return ur&&(e.e>p.maxE?(e.d=null,e.e=NaN):e.e<p.minE&&(e.e=0,e.d=[0])),e}function Pr(e,t,n){if(!e.isFinite())return Gr(e);var r,i=e.e,a=Dr(e.d),o=a.length;return t?(n&&(r=n-o)>0?a=a.charAt(0)+`.`+a.slice(1)+zr(r):o>1&&(a=a.charAt(0)+`.`+a.slice(1)),a=a+(e.e<0?`e`:`e+`)+e.e):i<0?(a=`0.`+zr(-i-1)+a,n&&(r=n-o)>0&&(a+=zr(r))):i>=o?(a+=zr(i+1-o),n&&(r=n-i-1)>0&&(a=a+`.`+zr(r))):((r=i+1)<o&&(a=a.slice(0,r)+`.`+a.slice(r)),n&&(r=n-o)>0&&(i+1===o&&(a+=`.`),a+=zr(r))),a}function Fr(e,t){var n=e[0];for(t*=Cr;n>=10;n/=10)t++;return t}function Ir(e,t,n){if(t>Tr)throw ur=!0,n&&(e.precision=n),Error(pr);return Nr(new e(ar),t,1,!0)}function Lr(e,t,n){if(t>Er)throw Error(pr);return Nr(new e(or),t,n,!0)}function Rr(e){var t=e.length-1,n=t*Cr+1;if(t=e[t],t){for(;t%10==0;t/=10)n--;for(t=e[0];t>=10;t/=10)n++}return n}function zr(e){for(var t=``;e--;)t+=`0`;return t}function Br(e,t,n,r){var i,a=new e(1),o=Math.ceil(r/Cr+4);for(ur=!1;;){if(n%2&&(a=a.times(t),$r(a.d,o)&&(i=!0)),n=gr(n/2),n===0){n=a.d.length-1,i&&a.d[n]===0&&++a.d[n];break}t=t.times(t),$r(t.d,o)}return ur=!0,a}function Vr(e){return e.d[e.d.length-1]&1}function Hr(e,t,n){for(var r,i,a=new e(t[0]),o=0;++o<t.length;){if(i=new e(t[o]),!i.s){a=i;break}r=a.cmp(i),(r===n||r===0&&a.s===n)&&(a=i)}return a}function Ur(e,t){var n,r,i,a,o,s,c,l=0,u=0,d=0,f=e.constructor,p=f.rounding,m=f.precision;if(!e.d||!e.d[0]||e.e>17)return new f(e.d?e.d[0]?e.s<0?0:1/0:1:e.s?e.s<0?0:e:NaN);for(t==null?(ur=!1,c=m):c=t,s=new f(.03125);e.e>-2;)e=e.times(s),d+=5;for(r=Math.log(_r(2,d))/Math.LN10*2+5|0,c+=r,n=a=o=new f(1),f.precision=c;;){if(a=Nr(a.times(e),c,1),n=n.times(++u),s=o.plus(Mr(a,n,c,1)),Dr(s.d).slice(0,c)===Dr(o.d).slice(0,c)){for(i=d;i--;)o=Nr(o.times(o),c,1);if(t==null)if(l<3&&kr(o.d,c-r,p,l))f.precision=c+=10,n=a=s=new f(1),u=0,l++;else return Nr(o,f.precision=m,p,ur=!0);else return f.precision=m,o}o=s}}function Wr(e,t){var n,r,i,a,o,s,c,l,u,d,f,p=1,m=10,h=e,g=h.d,_=h.constructor,v=_.rounding,y=_.precision;if(h.s<0||!g||!g[0]||!h.e&&g[0]==1&&g.length==1)return new _(g&&!g[0]?-1/0:h.s==1?g?0:h:NaN);if(t==null?(ur=!1,u=y):u=t,_.precision=u+=m,n=Dr(g),r=n.charAt(0),Math.abs(a=h.e)<0x5543df729c000){for(;r<7&&r!=1||r==1&&n.charAt(1)>3;)h=h.times(e),n=Dr(h.d),r=n.charAt(0),p++;a=h.e,r>1?(h=new _(`0.`+n),a++):h=new _(r+`.`+n.slice(1))}else return l=Ir(_,u+2,y).times(a+``),h=Wr(new _(r+`.`+n.slice(1)),u-m).plus(l),_.precision=y,t==null?Nr(h,y,v,ur=!0):h;for(d=h,c=o=h=Mr(h.minus(1),h.plus(1),u,1),f=Nr(h.times(h),u,1),i=3;;){if(o=Nr(o.times(f),u,1),l=c.plus(Mr(o,new _(i),u,1)),Dr(l.d).slice(0,u)===Dr(c.d).slice(0,u))if(c=c.times(2),a!==0&&(c=c.plus(Ir(_,u+2,y).times(a+``))),c=Mr(c,new _(p),u,1),t==null)if(kr(c.d,u-m,v,s))_.precision=u+=m,l=o=h=Mr(d.minus(1),d.plus(1),u,1),f=Nr(h.times(h),u,1),i=s=1;else return Nr(c,_.precision=y,v,ur=!0);else return _.precision=y,c;c=l,i+=2}}function Gr(e){return String(e.s*e.s/0)}function Kr(e,t){var n,r,i;for((n=t.indexOf(`.`))>-1&&(t=t.replace(`.`,``)),(r=t.search(/e/i))>0?(n<0&&(n=r),n+=+t.slice(r+1),t=t.substring(0,r)):n<0&&(n=t.length),r=0;t.charCodeAt(r)===48;r++);for(i=t.length;t.charCodeAt(i-1)===48;--i);if(t=t.slice(r,i),t){if(i-=r,e.e=n=n-r-1,e.d=[],r=(n+1)%Cr,n<0&&(r+=Cr),r<i){for(r&&e.d.push(+t.slice(0,r)),i-=Cr;r<i;)e.d.push(+t.slice(r,r+=Cr));t=t.slice(r),r=Cr-t.length}else r-=i;for(;r--;)t+=`0`;e.d.push(+t),ur&&(e.e>e.constructor.maxE?(e.d=null,e.e=NaN):e.e<e.constructor.minE&&(e.e=0,e.d=[0]))}else e.e=0,e.d=[0];return e}function qr(e,t){var n,r,i,a,o,s,c,l,u;if(t.indexOf(`_`)>-1){if(t=t.replace(/(\d)_(?=\d)/g,`$1`),xr.test(t))return Kr(e,t)}else if(t===`Infinity`||t===`NaN`)return+t||(e.s=NaN),e.e=NaN,e.d=null,e;if(yr.test(t))n=16,t=t.toLowerCase();else if(vr.test(t))n=2;else if(br.test(t))n=8;else throw Error(fr+t);for(a=t.search(/p/i),a>0?(c=+t.slice(a+1),t=t.substring(2,a)):t=t.slice(2),a=t.indexOf(`.`),o=a>=0,r=e.constructor,o&&(t=t.replace(`.`,``),s=t.length,a=s-a,i=Br(r,new r(n),a,a*2)),l=Ar(t,n,Sr),u=l.length-1,a=u;l[a]===0;--a)l.pop();return a<0?new r(e.s*0):(e.e=Fr(l,u),e.d=l,ur=!1,o&&(e=Mr(e,i,s*4)),c&&(e=e.times(Math.abs(c)<54?_r(2,c):Vi.pow(2,c))),ur=!0,e)}function Jr(e,t){var n,r=t.d.length;if(r<3)return t.isZero()?t:Yr(e,2,t,t);n=1.4*Math.sqrt(r),n=n>16?16:n|0,t=t.times(1/Xr(5,n)),t=Yr(e,2,t,t);for(var i,a=new e(5),o=new e(16),s=new e(20);n--;)i=t.times(t),t=t.times(a.plus(i.times(o.times(i).minus(s))));return t}function Yr(e,t,n,r,i){var a,o,s,c,l=1,u=e.precision,d=Math.ceil(u/Cr);for(ur=!1,c=n.times(n),s=new e(r);;){if(o=Mr(s.times(c),new e(t++*t++),u,1),s=i?r.plus(o):r.minus(o),r=Mr(o.times(c),new e(t++*t++),u,1),o=s.plus(r),o.d[d]!==void 0){for(a=d;o.d[a]===s.d[a]&&a--;);if(a==-1)break}a=s,s=r,r=o,o=a,l++}return ur=!0,o.d.length=d+1,o}function Xr(e,t){for(var n=e;--t;)n*=e;return n}function Zr(e,t){var n,r=t.s<0,i=Lr(e,e.precision,1),a=i.times(.5);if(t=t.abs(),t.lte(a))return lr=r?4:1,t;if(n=t.divToInt(i),n.isZero())lr=r?3:2;else{if(t=t.minus(n.times(i)),t.lte(a))return lr=Vr(n)?r?2:3:r?4:1,t;lr=Vr(n)?r?1:4:r?3:2}return t.minus(i).abs()}function Qr(e,t,n,r){var i,a,o,s,c,l,u,d,f,p=e.constructor,m=n!==void 0;if(m?(Or(n,1,rr),r===void 0?r=p.rounding:Or(r,0,8)):(n=p.precision,r=p.rounding),!e.isFinite())u=Gr(e);else{for(u=Pr(e),o=u.indexOf(`.`),m?(i=2,t==16?n=n*4-3:t==8&&(n=n*3-2)):i=t,o>=0&&(u=u.replace(`.`,``),f=new p(1),f.e=u.length-o,f.d=Ar(Pr(f),10,i),f.e=f.d.length),d=Ar(u,10,i),a=c=d.length;d[--c]==0;)d.pop();if(!d[0])u=m?`0p+0`:`0`;else{if(o<0?a--:(e=new p(e),e.d=d,e.e=a,e=Mr(e,f,n,r,0,i),d=e.d,a=e.e,l=cr),o=d[n],s=i/2,l||=d[n+1]!==void 0,l=r<4?(o!==void 0||l)&&(r===0||r===(e.s<0?3:2)):o>s||o===s&&(r===4||l||r===6&&d[n-1]&1||r===(e.s<0?8:7)),d.length=n,l)for(;++d[--n]>i-1;)d[n]=0,n||(++a,d.unshift(1));for(c=d.length;!d[c-1];--c);for(o=0,u=``;o<c;o++)u+=ir.charAt(d[o]);if(m){if(c>1)if(t==16||t==8){for(o=t==16?4:3,--c;c%o;c++)u+=`0`;for(d=Ar(u,i,t),c=d.length;!d[c-1];--c);for(o=1,u=`1.`;o<c;o++)u+=ir.charAt(d[o])}else u=u.charAt(0)+`.`+u.slice(1);u=u+(a<0?`p`:`p+`)+a}else if(a<0){for(;++a;)u=`0`+u;u=`0.`+u}else if(++a>c)for(a-=c;a--;)u+=`0`;else a<c&&(u=u.slice(0,a)+`.`+u.slice(a))}u=(t==16?`0x`:t==2?`0b`:t==8?`0o`:``)+u}return e.s<0?`-`+u:u}function $r(e,t){if(e.length>t)return e.length=t,!0}function ei(e){return new this(e).abs()}function ti(e){return new this(e).acos()}function ni(e){return new this(e).acosh()}function ri(e,t){return new this(e).plus(t)}function ii(e){return new this(e).asin()}function ai(e){return new this(e).asinh()}function oi(e){return new this(e).atan()}function si(e){return new this(e).atanh()}function ci(e,t){e=new this(e),t=new this(t);var n,r=this.precision,i=this.rounding,a=r+4;return!e.s||!t.s?n=new this(NaN):!e.d&&!t.d?(n=Lr(this,a,1).times(t.s>0?.25:.75),n.s=e.s):!t.d||e.isZero()?(n=t.s<0?Lr(this,r,i):new this(0),n.s=e.s):!e.d||t.isZero()?(n=Lr(this,a,1).times(.5),n.s=e.s):t.s<0?(this.precision=a,this.rounding=1,n=this.atan(Mr(e,t,a,1)),t=Lr(this,a,1),this.precision=r,this.rounding=i,n=e.s<0?n.minus(t):n.plus(t)):n=this.atan(Mr(e,t,a,1)),n}function li(e){return new this(e).cbrt()}function ui(e){return Nr(e=new this(e),e.e+1,2)}function di(e,t,n){return new this(e).clamp(t,n)}function fi(e){if(!e||typeof e!=`object`)throw Error(dr+`Object expected`);var t,n,r,i=e.defaults===!0,a=[`precision`,1,rr,`rounding`,0,8,`toExpNeg`,-nr,0,`toExpPos`,0,nr,`maxE`,0,nr,`minE`,-nr,0,`modulo`,0,9];for(t=0;t<a.length;t+=3)if(n=a[t],i&&(this[n]=sr[n]),(r=e[n])!==void 0)if(gr(r)===r&&r>=a[t+1]&&r<=a[t+2])this[n]=r;else throw Error(fr+n+`: `+r);if(n=`crypto`,i&&(this[n]=sr[n]),(r=e[n])!==void 0)if(r===!0||r===!1||r===0||r===1)if(r)if(typeof crypto<`u`&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[n]=!0;else throw Error(mr);else this[n]=!1;else throw Error(fr+n+`: `+r);return this}function pi(e){return new this(e).cos()}function mi(e){return new this(e).cosh()}function hi(e){var t,n,r;function i(e){var t,n,r,a=this;if(!(a instanceof i))return new i(e);if(a.constructor=i,bi(e)){a.s=e.s,ur?!e.d||e.e>i.maxE?(a.e=NaN,a.d=null):e.e<i.minE?(a.e=0,a.d=[0]):(a.e=e.e,a.d=e.d.slice()):(a.e=e.e,a.d=e.d?e.d.slice():e.d);return}if(r=typeof e,r===`number`){if(e===0){a.s=1/e<0?-1:1,a.e=0,a.d=[0];return}if(e<0?(e=-e,a.s=-1):a.s=1,e===~~e&&e<1e7){for(t=0,n=e;n>=10;n/=10)t++;ur?t>i.maxE?(a.e=NaN,a.d=null):t<i.minE?(a.e=0,a.d=[0]):(a.e=t,a.d=[e]):(a.e=t,a.d=[e]);return}if(e*0!=0){e||(a.s=NaN),a.e=NaN,a.d=null;return}return Kr(a,e.toString())}if(r===`string`)return(n=e.charCodeAt(0))===45?(e=e.slice(1),a.s=-1):(n===43&&(e=e.slice(1)),a.s=1),xr.test(e)?Kr(a,e):qr(a,e);if(r===`bigint`)return e<0?(e=-e,a.s=-1):a.s=1,Kr(a,e.toString());throw Error(fr+e)}if(i.prototype=q,i.ROUND_UP=0,i.ROUND_DOWN=1,i.ROUND_CEIL=2,i.ROUND_FLOOR=3,i.ROUND_HALF_UP=4,i.ROUND_HALF_DOWN=5,i.ROUND_HALF_EVEN=6,i.ROUND_HALF_CEIL=7,i.ROUND_HALF_FLOOR=8,i.EUCLID=9,i.config=i.set=fi,i.clone=hi,i.isDecimal=bi,i.abs=ei,i.acos=ti,i.acosh=ni,i.add=ri,i.asin=ii,i.asinh=ai,i.atan=oi,i.atanh=si,i.atan2=ci,i.cbrt=li,i.ceil=ui,i.clamp=di,i.cos=pi,i.cosh=mi,i.div=gi,i.exp=_i,i.floor=vi,i.hypot=yi,i.ln=xi,i.log=Si,i.log10=wi,i.log2=Ci,i.max=Ti,i.min=Ei,i.mod=Di,i.mul=Oi,i.pow=ki,i.random=Ai,i.round=ji,i.sign=Mi,i.sin=Ni,i.sinh=Pi,i.sqrt=Fi,i.sub=Ii,i.sum=Li,i.tan=Ri,i.tanh=zi,i.trunc=Bi,e===void 0&&(e={}),e&&e.defaults!==!0)for(r=[`precision`,`rounding`,`toExpNeg`,`toExpPos`,`maxE`,`minE`,`modulo`,`crypto`],t=0;t<r.length;)e.hasOwnProperty(n=r[t++])||(e[n]=this[n]);return i.config(e),i}function gi(e,t){return new this(e).div(t)}function _i(e){return new this(e).exp()}function vi(e){return Nr(e=new this(e),e.e+1,3)}function yi(){var e,t,n=new this(0);for(ur=!1,e=0;e<arguments.length;)if(t=new this(arguments[e++]),t.d)n.d&&(n=n.plus(t.times(t)));else{if(t.s)return ur=!0,new this(1/0);n=t}return ur=!0,n.sqrt()}function bi(e){return e instanceof Vi||e&&e.toStringTag===hr||!1}function xi(e){return new this(e).ln()}function Si(e,t){return new this(e).log(t)}function Ci(e){return new this(e).log(2)}function wi(e){return new this(e).log(10)}function Ti(){return Hr(this,arguments,-1)}function Ei(){return Hr(this,arguments,1)}function Di(e,t){return new this(e).mod(t)}function Oi(e,t){return new this(e).mul(t)}function ki(e,t){return new this(e).pow(t)}function Ai(e){var t,n,r,i,a=0,o=new this(1),s=[];if(e===void 0?e=this.precision:Or(e,1,rr),r=Math.ceil(e/Cr),!this.crypto)for(;a<r;)s[a++]=Math.random()*1e7|0;else if(crypto.getRandomValues)for(t=crypto.getRandomValues(new Uint32Array(r));a<r;)i=t[a],i>=429e7?t[a]=crypto.getRandomValues(new Uint32Array(1))[0]:s[a++]=i%1e7;else if(crypto.randomBytes){for(t=crypto.randomBytes(r*=4);a<r;)i=t[a]+(t[a+1]<<8)+(t[a+2]<<16)+((t[a+3]&127)<<24),i>=214e7?crypto.randomBytes(4).copy(t,a):(s.push(i%1e7),a+=4);a=r/4}else throw Error(mr);for(r=s[--a],e%=Cr,r&&e&&(i=_r(10,Cr-e),s[a]=(r/i|0)*i);s[a]===0;a--)s.pop();if(a<0)n=0,s=[0];else{for(n=-1;s[0]===0;n-=Cr)s.shift();for(r=1,i=s[0];i>=10;i/=10)r++;r<Cr&&(n-=Cr-r)}return o.e=n,o.d=s,o}function ji(e){return Nr(e=new this(e),e.e+1,this.rounding)}function Mi(e){return e=new this(e),e.d?e.d[0]?e.s:0*e.s:e.s||NaN}function Ni(e){return new this(e).sin()}function Pi(e){return new this(e).sinh()}function Fi(e){return new this(e).sqrt()}function Ii(e,t){return new this(e).sub(t)}function Li(){var e=0,t=arguments,n=new this(t[e]);for(ur=!1;n.s&&++e<t.length;)n=n.plus(t[e]);return ur=!0,Nr(n,this.precision,this.rounding)}function Ri(e){return new this(e).tan()}function zi(e){return new this(e).tanh()}function Bi(e){return Nr(e=new this(e),e.e+1,1)}q[Symbol.for(`nodejs.util.inspect.custom`)]=q.toString,q[Symbol.toStringTag]=`Decimal`;var Vi=q.constructor=hi(sr);ar=new Vi(ar),or=new Vi(or);var Hi=K(`BigNumber`,[`?on`,`config`],e=>{var{on:t,config:n}=e,r=Vi.clone({precision:n.precision,modulo:Vi.EUCLID});return r.prototype=Object.create(r.prototype),r.prototype.type=`BigNumber`,r.prototype.isBigNumber=!0,r.prototype.toJSON=function(){return{mathjs:`BigNumber`,value:this.toString()}},r.fromJSON=function(e){return new r(e.value)},t&&t(`config`,function(e,t){e.precision!==t.precision&&r.config({precision:e.precision})}),r},{isClass:!0}),Ui=Math.cosh||function(e){return Math.abs(e)<1e-9?1-e:(Math.exp(e)+Math.exp(-e))*.5},Wi=Math.sinh||function(e){return Math.abs(e)<1e-9?e:(Math.exp(e)-Math.exp(-e))*.5},Gi=e=>{let t=Math.sin(.5*e);return-2*t*t},Ki=function(e,t){return e=Math.abs(e),t=Math.abs(t),e<t&&([e,t]=[t,e]),e<1e8?Math.sqrt(e*e+t*t):(t/=e,e*Math.sqrt(1+t*t))},qi=function(){throw SyntaxError(`Invalid Param`)};function Ji(e,t){let n=Math.abs(e),r=Math.abs(t);return e===0?Math.log(r):t===0?Math.log(n):n<3e3&&r<3e3?Math.log(e*e+t*t)*.5:(e*=.5,t*=.5,.5*Math.log(e*e+t*t)+Math.LN2)}var Yi={re:0,im:0},Xi=function(e,t){let n=Yi;if(e==null)n.re=n.im=0;else if(t!==void 0)n.re=e,n.im=t;else switch(typeof e){case`object`:if(`im`in e&&`re`in e)n.re=e.re,n.im=e.im;else if(`abs`in e&&`arg`in e){if(!isFinite(e.abs)&&isFinite(e.arg))return J.INFINITY;n.re=e.abs*Math.cos(e.arg),n.im=e.abs*Math.sin(e.arg)}else if(`r`in e&&`phi`in e){if(!isFinite(e.r)&&isFinite(e.phi))return J.INFINITY;n.re=e.r*Math.cos(e.phi),n.im=e.r*Math.sin(e.phi)}else e.length===2?(n.re=e[0],n.im=e[1]):qi();break;case`string`:n.im=n.re=0;let t=e.replace(/_/g,``).match(/\d+\.?\d*e[+-]?\d+|\d+\.?\d*|\.\d+|./g),r=1,i=0;t===null&&qi();for(let e=0;e<t.length;e++){let a=t[e];a===` `||a===` `||a===`
|
|
4
4
|
`||(a===`+`?r++:a===`-`?i++:a===`i`||a===`I`?(r+i===0&&qi(),t[e+1]!==` `&&!isNaN(t[e+1])?(n.im+=parseFloat((i%2?`-`:``)+t[e+1]),e++):n.im+=parseFloat((i%2?`-`:``)+`1`),r=i=0):((r+i===0||isNaN(a))&&qi(),t[e+1]===`i`||t[e+1]===`I`?(n.im+=parseFloat((i%2?`-`:``)+a),e++):n.re+=parseFloat((i%2?`-`:``)+a),r=i=0))}r+i>0&&qi();break;case`number`:n.im=0,n.re=e;break;default:qi()}return isNaN(n.re)||isNaN(n.im),n};function J(e,t){if(!(this instanceof J))return new J(e,t);let n=Xi(e,t);this.re=n.re,this.im=n.im}J.prototype={re:0,im:0,sign:function(){let e=Ki(this.re,this.im);return new J(this.re/e,this.im/e)},add:function(e,t){let n=Xi(e,t),r=this.isInfinite(),i=!(isFinite(n.re)&&isFinite(n.im));return r||i?r&&i?J.NAN:J.INFINITY:new J(this.re+n.re,this.im+n.im)},sub:function(e,t){let n=Xi(e,t),r=this.isInfinite(),i=!(isFinite(n.re)&&isFinite(n.im));return r||i?r&&i?J.NAN:J.INFINITY:new J(this.re-n.re,this.im-n.im)},mul:function(e,t){let n=Xi(e,t),r=this.isInfinite(),i=!(isFinite(n.re)&&isFinite(n.im)),a=this.re===0&&this.im===0,o=n.re===0&&n.im===0;return r&&o||i&&a?J.NAN:r||i?J.INFINITY:n.im===0&&this.im===0?new J(this.re*n.re,0):new J(this.re*n.re-this.im*n.im,this.re*n.im+this.im*n.re)},div:function(e,t){let n=Xi(e,t),r=this.isInfinite(),i=!(isFinite(n.re)&&isFinite(n.im)),a=this.re===0&&this.im===0,o=n.re===0&&n.im===0;if(a&&o||r&&i)return J.NAN;if(o||r)return J.INFINITY;if(a||i)return J.ZERO;if(n.im===0)return new J(this.re/n.re,this.im/n.re);if(Math.abs(n.re)<Math.abs(n.im)){let e=n.re/n.im,t=n.re*e+n.im;return new J((this.re*e+this.im)/t,(this.im*e-this.re)/t)}else{let e=n.im/n.re,t=n.im*e+n.re;return new J((this.re+this.im*e)/t,(this.im-this.re*e)/t)}},pow:function(e,t){let n=Xi(e,t),r=this.re===0&&this.im===0;if(n.re===0&&n.im===0)return J.ONE;if(n.im===0){if(this.im===0&&this.re>0)return new J(this.re**+n.re,0);if(this.re===0)switch((n.re%4+4)%4){case 0:return new J(this.im**+n.re,0);case 1:return new J(0,this.im**+n.re);case 2:return new J(-(this.im**+n.re),0);case 3:return new J(0,-(this.im**+n.re))}}if(r&&n.re>0)return J.ZERO;let i=Math.atan2(this.im,this.re),a=Ji(this.re,this.im),o=Math.exp(n.re*a-n.im*i),s=n.im*a+n.re*i;return new J(o*Math.cos(s),o*Math.sin(s))},sqrt:function(){let e=this.re,t=this.im;if(t===0)return e>=0?new J(Math.sqrt(e),0):new J(0,Math.sqrt(-e));let n=Ki(e,t),r=Math.sqrt(.5*(n+Math.abs(e))),i=Math.abs(t)/(2*r);return e>=0?new J(r,t<0?-i:i):new J(i,t<0?-r:r)},exp:function(){let e=Math.exp(this.re);return this.im===0?new J(e,0):new J(e*Math.cos(this.im),e*Math.sin(this.im))},expm1:function(){let e=this.re,t=this.im;return new J(Math.expm1(e)*Math.cos(t)+Gi(t),Math.exp(e)*Math.sin(t))},log:function(){let e=this.re,t=this.im;return t===0&&e>0?new J(Math.log(e),0):new J(Ji(e,t),Math.atan2(t,e))},abs:function(){return Ki(this.re,this.im)},arg:function(){return Math.atan2(this.im,this.re)},sin:function(){let e=this.re,t=this.im;return new J(Math.sin(e)*Ui(t),Math.cos(e)*Wi(t))},cos:function(){let e=this.re,t=this.im;return new J(Math.cos(e)*Ui(t),-Math.sin(e)*Wi(t))},tan:function(){let e=2*this.re,t=2*this.im,n=Math.cos(e)+Ui(t);return new J(Math.sin(e)/n,Wi(t)/n)},cot:function(){let e=2*this.re,t=2*this.im,n=Math.cos(e)-Ui(t);return new J(-Math.sin(e)/n,Wi(t)/n)},sec:function(){let e=this.re,t=this.im,n=.5*Ui(2*t)+.5*Math.cos(2*e);return new J(Math.cos(e)*Ui(t)/n,Math.sin(e)*Wi(t)/n)},csc:function(){let e=this.re,t=this.im,n=.5*Ui(2*t)-.5*Math.cos(2*e);return new J(Math.sin(e)*Ui(t)/n,-Math.cos(e)*Wi(t)/n)},asin:function(){let e=this.re,t=this.im,n=new J(t*t-e*e+1,-2*e*t).sqrt(),r=new J(n.re-t,n.im+e).log();return new J(r.im,-r.re)},acos:function(){let e=this.re,t=this.im,n=new J(t*t-e*e+1,-2*e*t).sqrt(),r=new J(n.re-t,n.im+e).log();return new J(Math.PI/2-r.im,r.re)},atan:function(){let e=this.re,t=this.im;if(e===0){if(t===1)return new J(0,1/0);if(t===-1)return new J(0,-1/0)}let n=e*e+(1-t)*(1-t),r=new J((1-t*t-e*e)/n,-2*e/n).log();return new J(-.5*r.im,.5*r.re)},acot:function(){let e=this.re,t=this.im;if(t===0)return new J(Math.atan2(1,e),0);let n=e*e+t*t;return n===0?new J(e===0?0:e/0,t===0?0:-t/0).atan():new J(e/n,-t/n).atan()},asec:function(){let e=this.re,t=this.im;if(e===0&&t===0)return new J(0,1/0);let n=e*e+t*t;return n===0?new J(e===0?0:e/0,t===0?0:-t/0).acos():new J(e/n,-t/n).acos()},acsc:function(){let e=this.re,t=this.im;if(e===0&&t===0)return new J(Math.PI/2,1/0);let n=e*e+t*t;return n===0?new J(e===0?0:e/0,t===0?0:-t/0).asin():new J(e/n,-t/n).asin()},sinh:function(){let e=this.re,t=this.im;return new J(Wi(e)*Math.cos(t),Ui(e)*Math.sin(t))},cosh:function(){let e=this.re,t=this.im;return new J(Ui(e)*Math.cos(t),Wi(e)*Math.sin(t))},tanh:function(){let e=2*this.re,t=2*this.im,n=Ui(e)+Math.cos(t);return new J(Wi(e)/n,Math.sin(t)/n)},coth:function(){let e=2*this.re,t=2*this.im,n=Ui(e)-Math.cos(t);return new J(Wi(e)/n,-Math.sin(t)/n)},csch:function(){let e=this.re,t=this.im,n=Math.cos(2*t)-Ui(2*e);return new J(-2*Wi(e)*Math.cos(t)/n,2*Ui(e)*Math.sin(t)/n)},sech:function(){let e=this.re,t=this.im,n=Math.cos(2*t)+Ui(2*e);return new J(2*Ui(e)*Math.cos(t)/n,-2*Wi(e)*Math.sin(t)/n)},asinh:function(){let e=this.re,t=this.im;if(t===0){if(e===0)return new J(0,0);let t=Math.abs(e),n=Math.log(t+Math.sqrt(t*t+1));return new J(e<0?-n:n,0)}let n=new J(e*e-t*t+1,2*e*t).sqrt();return new J(e+n.re,t+n.im).log()},acosh:function(){let e=this.re,t=this.im;if(t===0){if(e>1)return new J(Math.log(e+Math.sqrt(e-1)*Math.sqrt(e+1)),0);if(e<-1){let t=Math.sqrt(e*e-1);return new J(Math.log(-e+t),Math.PI)}return new J(0,Math.acos(e))}let n=new J(e-1,t).sqrt(),r=new J(e+1,t).sqrt();return new J(e+n.re*r.re-n.im*r.im,t+n.re*r.im+n.im*r.re).log()},atanh:function(){let e=this.re,t=this.im;if(t===0){if(e===0)return new J(0,0);if(e===1)return new J(1/0,0);if(e===-1)return new J(-1/0,0);if(-1<e&&e<1)return new J(.5*Math.log((1+e)/(1-e)),0);if(e>1){let t=(e+1)/(e-1);return new J(.5*Math.log(t),-Math.PI/2)}let t=(1+e)/(1-e);return new J(.5*Math.log(-t),Math.PI/2)}let n=1-e,r=1+e,i=n*n+t*t;if(i===0)return new J(e===-1?0:e/0,t===0?0:t/0);let a=(r*n-t*t)/i,o=(t*n+r*t)/i;return new J(Ji(a,o)/2,Math.atan2(o,a)/2)},acoth:function(){let e=this.re,t=this.im;if(e===0&&t===0)return new J(0,Math.PI/2);let n=e*e+t*t;return n===0?new J(e===0?0:e/0,t===0?0:-t/0).atanh():new J(e/n,-t/n).atanh()},acsch:function(){let e=this.re,t=this.im;if(t===0){if(e===0)return new J(1/0,0);let t=1/e;return new J(Math.log(t+Math.sqrt(t*t+1)),0)}let n=e*e+t*t;return n===0?new J(e===0?0:e/0,t===0?0:-t/0).asinh():new J(e/n,-t/n).asinh()},asech:function(){let e=this.re,t=this.im;if(this.isZero())return J.INFINITY;let n=e*e+t*t;return n===0?new J(e===0?0:e/0,t===0?0:-t/0).acosh():new J(e/n,-t/n).acosh()},inverse:function(){if(this.isZero())return J.INFINITY;if(this.isInfinite())return J.ZERO;let e=this.re,t=this.im,n=e*e+t*t;return new J(e/n,-t/n)},conjugate:function(){return new J(this.re,-this.im)},neg:function(){return new J(-this.re,-this.im)},ceil:function(e){return e=10**(e||0),new J(Math.ceil(this.re*e)/e,Math.ceil(this.im*e)/e)},floor:function(e){return e=10**(e||0),new J(Math.floor(this.re*e)/e,Math.floor(this.im*e)/e)},round:function(e){return e=10**(e||0),new J(Math.round(this.re*e)/e,Math.round(this.im*e)/e)},equals:function(e,t){let n=Xi(e,t);return Math.abs(n.re-this.re)<=J.EPSILON&&Math.abs(n.im-this.im)<=J.EPSILON},clone:function(){return new J(this.re,this.im)},toString:function(){let e=this.re,t=this.im,n=``;return this.isNaN()?`NaN`:this.isInfinite()?`Infinity`:(Math.abs(e)<J.EPSILON&&(e=0),Math.abs(t)<J.EPSILON&&(t=0),t===0?n+e:(e===0?t<0&&(t=-t,n+=`-`):(n+=e,n+=` `,t<0?(t=-t,n+=`-`):n+=`+`,n+=` `),t!==1&&(n+=t),n+`i`))},toVector:function(){return[this.re,this.im]},valueOf:function(){return this.im===0?this.re:null},isNaN:function(){return isNaN(this.re)||isNaN(this.im)},isZero:function(){return this.im===0&&this.re===0},isFinite:function(){return isFinite(this.re)&&isFinite(this.im)},isInfinite:function(){return!this.isFinite()}},J.ZERO=new J(0,0),J.ONE=new J(1,0),J.I=new J(0,1),J.PI=new J(Math.PI,0),J.E=new J(Math.E,0),J.INFINITY=new J(1/0,1/0),J.NAN=new J(NaN,NaN),J.EPSILON=1e-15;var Zi=K(`Complex`,[],()=>(Object.defineProperty(J,`name`,{value:`Complex`}),J.prototype.constructor=J,J.prototype.type=`Complex`,J.prototype.isComplex=!0,J.prototype.toJSON=function(){return{mathjs:`Complex`,re:this.re,im:this.im}},J.prototype.toPolar=function(){return{r:this.abs(),phi:this.arg()}},J.prototype.format=function(e){var t=``,n=this.im,r=this.re,i=On(this.re,e),a=On(this.im,e),o=st(e)?e:e?e.precision:null;if(o!==null){var s=10**-o;Math.abs(r/n)<s&&(r=0),Math.abs(n/r)<s&&(n=0)}return t=n===0?i:r===0?n===1?`i`:n===-1?`-i`:a+`i`:n<0?n===-1?i+` - i`:i+` - `+a.substring(1)+`i`:n===1?i+` + i`:i+` + `+a+`i`,t},J.fromPolar=function(e){switch(arguments.length){case 1:var t=arguments[0];if(typeof t==`object`)return J(t);throw TypeError(`Input has to be an object with r and phi keys.`);case 2:var n=arguments[0],r=arguments[1];if(st(n)){if(ft(r)&&r.hasBase(`ANGLE`)&&(r=r.toNumber(`rad`)),st(r))return new J({r:n,phi:r});throw TypeError(`Phi is not a number nor an angle unit.`)}else throw TypeError(`Radius r is not a number.`);default:throw SyntaxError(`Wrong number of arguments in function fromPolar`)}},J.prototype.valueOf=J.prototype.toString,J.fromJSON=function(e){return new J(e)},J.compare=function(e,t){return e.re>t.re?1:e.re<t.re?-1:e.im>t.im?1:e.im<t.im?-1:0},J),{isClass:!0});typeof BigInt>`u`&&(BigInt=function(e){if(isNaN(e))throw Error(``);return e});var Qi=BigInt(0),$i=BigInt(1),ea=BigInt(2),ta=BigInt(3),na=BigInt(5),ra=BigInt(10);BigInt(2**53-1);var ia=2e3,aa={s:$i,n:Qi,d:$i};function oa(e,t){try{e=BigInt(e)}catch{throw va()}return e*t}function sa(e){return typeof e==`bigint`?e:Math.floor(e)}function ca(e,t){if(t===Qi)throw _a();let n=Object.create(ga.prototype);n.s=e<Qi?-$i:$i,e=e<Qi?-e:e;let r=ha(e,t);return n.n=e/r,n.d=t/r,n}var la=[ea*ea,ea,ea*ea,ea,ea*ea,ea*ta,ea,ea*ta];function ua(e){let t=Object.create(null);if(e<=$i)return t[e]=$i,t;let n=e=>{t[e]=(t[e]||Qi)+$i};for(;e%ea===Qi;)n(ea),e/=ea;for(;e%ta===Qi;)n(ta),e/=ta;for(;e%na===Qi;)n(na),e/=na;for(let t=0,r=ea+na;r*r<=e;){for(;e%r===Qi;)n(r),e/=r;r+=la[t],t=t+1&7}return e>$i&&n(e),t}var da=function(e,t){let n=Qi,r=$i,i=$i;if(e!=null)if(t!==void 0){if(typeof e==`bigint`)n=e;else if(isNaN(e))throw va();else if(e%1!=0)throw ya();else n=BigInt(e);if(typeof t==`bigint`)r=t;else if(isNaN(t))throw va();else if(t%1!=0)throw ya();else r=BigInt(t);i=n*r}else if(typeof e==`object`){if(`d`in e&&`n`in e)n=BigInt(e.n),r=BigInt(e.d),`s`in e&&(n*=BigInt(e.s));else if(0 in e)n=BigInt(e[0]),1 in e&&(r=BigInt(e[1]));else if(typeof e==`bigint`)n=e;else throw va();i=n*r}else if(typeof e==`number`){if(isNaN(e))throw va();if(e<0&&(i=-$i,e=-e),e%1==0)n=BigInt(e);else{let t=1,i=0,a=1,o=1,s=1,c=1e7;for(e>=1&&(t=10**Math.floor(1+Math.log10(e)),e/=t);a<=c&&s<=c;){let t=(i+o)/(a+s);if(e===t){a+s<=c?(n=i+o,r=a+s):s>a?(n=o,r=s):(n=i,r=a);break}else e>t?(i+=o,a+=s):(o+=i,s+=a),a>c?(n=o,r=s):(n=i,r=a)}n=BigInt(n)*BigInt(t),r=BigInt(r)}}else if(typeof e==`string`){let t=0,a=Qi,o=Qi,s=Qi,c=$i,l=$i,u=e.replace(/_/g,``).match(/\d+|./g);if(u===null)throw va();if(u[t]===`-`?(i=-$i,t++):u[t]===`+`&&t++,u.length===t+1?o=oa(u[t++],i):u[t+1]===`.`||u[t]===`.`?(u[t]!==`.`&&(a=oa(u[t++],i)),t++,(t+1===u.length||u[t+1]===`(`&&u[t+3]===`)`||u[t+1]===`'`&&u[t+3]===`'`)&&(o=oa(u[t],i),c=ra**BigInt(u[t].length),t++),(u[t]===`(`&&u[t+2]===`)`||u[t]===`'`&&u[t+2]===`'`)&&(s=oa(u[t+1],i),l=ra**BigInt(u[t+1].length)-$i,t+=3)):u[t+1]===`/`||u[t+1]===`:`?(o=oa(u[t],i),c=oa(u[t+2],$i),t+=3):u[t+3]===`/`&&u[t+1]===` `&&(a=oa(u[t],i),o=oa(u[t+2],i),c=oa(u[t+4],$i),t+=5),u.length<=t)r=c*l,i=n=s+r*a+l*o;else throw va()}else if(typeof e==`bigint`)n=e,i=e,r=$i;else throw va();if(r===Qi)throw _a();aa.s=i<Qi?-$i:$i,aa.n=n<Qi?-n:n,aa.d=r<Qi?-r:r};function fa(e,t,n){let r=$i;for(;t>Qi;e=e*e%n,t>>=$i)t&$i&&(r=r*e%n);return r}function pa(e,t){for(;t%ea===Qi;t/=ea);for(;t%na===Qi;t/=na);if(t===$i)return Qi;let n=ra%t,r=1;for(;n!==$i;r++)if(n=n*ra%t,r>ia)return Qi;return BigInt(r)}function ma(e,t,n){let r=$i,i=fa(ra,n,t);for(let e=0;e<300;e++){if(r===i)return BigInt(e);r=r*ra%t,i=i*ra%t}return 0}function ha(e,t){if(!e)return t;if(!t)return e;for(;;){if(e%=t,!e)return t;if(t%=e,!t)return e}}function ga(e,t){if(da(e,t),this instanceof ga)e=ha(aa.d,aa.n),this.s=aa.s,this.n=aa.n/e,this.d=aa.d/e;else return ca(aa.s*aa.n,aa.d)}var _a=function(){return Error(`Division by Zero`)},va=function(){return Error(`Invalid argument`)},ya=function(){return Error(`Parameters must be integer`)};ga.prototype={s:$i,n:Qi,d:$i,abs:function(){return ca(this.n,this.d)},neg:function(){return ca(-this.s*this.n,this.d)},add:function(e,t){return da(e,t),ca(this.s*this.n*aa.d+aa.s*this.d*aa.n,this.d*aa.d)},sub:function(e,t){return da(e,t),ca(this.s*this.n*aa.d-aa.s*this.d*aa.n,this.d*aa.d)},mul:function(e,t){return da(e,t),ca(this.s*aa.s*this.n*aa.n,this.d*aa.d)},div:function(e,t){return da(e,t),ca(this.s*aa.s*this.n*aa.d,this.d*aa.n)},clone:function(){return ca(this.s*this.n,this.d)},mod:function(e,t){if(e===void 0)return ca(this.s*this.n%this.d,$i);if(da(e,t),Qi===aa.n*this.d)throw _a();return ca(this.s*(aa.d*this.n)%(aa.n*this.d),aa.d*this.d)},gcd:function(e,t){return da(e,t),ca(ha(aa.n,this.n)*ha(aa.d,this.d),aa.d*this.d)},lcm:function(e,t){return da(e,t),aa.n===Qi&&this.n===Qi?ca(Qi,$i):ca(aa.n*this.n,ha(aa.n,this.n)*ha(aa.d,this.d))},inverse:function(){return ca(this.s*this.d,this.n)},pow:function(e,t){if(da(e,t),aa.d===$i)return aa.s<Qi?ca((this.s*this.d)**aa.n,this.n**aa.n):ca((this.s*this.n)**aa.n,this.d**aa.n);if(this.s<Qi)return null;let n=ua(this.n),r=ua(this.d),i=$i,a=$i;for(let e in n)if(e!==`1`){if(e===`0`){i=Qi;break}if(n[e]*=aa.n,n[e]%aa.d===Qi)n[e]/=aa.d;else return null;i*=BigInt(e)**n[e]}for(let e in r)if(e!==`1`){if(r[e]*=aa.n,r[e]%aa.d===Qi)r[e]/=aa.d;else return null;a*=BigInt(e)**r[e]}return aa.s<Qi?ca(a,i):ca(i,a)},log:function(e,t){if(da(e,t),this.s<=Qi||aa.s<=Qi)return null;let n=Object.create(null),r=ua(aa.n),i=ua(aa.d),a=ua(this.n),o=ua(this.d);for(let e in i)r[e]=(r[e]||Qi)-i[e];for(let e in o)a[e]=(a[e]||Qi)-o[e];for(let e in r)e!==`1`&&(n[e]=!0);for(let e in a)e!==`1`&&(n[e]=!0);let s=null,c=null;for(let e in n){let t=r[e]||Qi,n=a[e]||Qi;if(t===Qi){if(n!==Qi)return null;continue}let i=n,o=t,l=ha(i,o);if(i/=l,o/=l,s===null&&c===null)s=i,c=o;else if(i*c!==s*o)return null}return s!==null&&c!==null?ca(s,c):null},equals:function(e,t){return da(e,t),this.s*this.n*aa.d===aa.s*aa.n*this.d},lt:function(e,t){return da(e,t),this.s*this.n*aa.d<aa.s*aa.n*this.d},lte:function(e,t){return da(e,t),this.s*this.n*aa.d<=aa.s*aa.n*this.d},gt:function(e,t){return da(e,t),this.s*this.n*aa.d>aa.s*aa.n*this.d},gte:function(e,t){return da(e,t),this.s*this.n*aa.d>=aa.s*aa.n*this.d},compare:function(e,t){da(e,t);let n=this.s*this.n*aa.d-aa.s*aa.n*this.d;return(Qi<n)-(n<Qi)},ceil:function(e){return e=ra**BigInt(e||0),ca(sa(this.s*e*this.n/this.d)+(e*this.n%this.d>Qi&&this.s>=Qi?$i:Qi),e)},floor:function(e){return e=ra**BigInt(e||0),ca(sa(this.s*e*this.n/this.d)-(e*this.n%this.d>Qi&&this.s<Qi?$i:Qi),e)},round:function(e){return e=ra**BigInt(e||0),ca(sa(this.s*e*this.n/this.d)+this.s*((this.s>=Qi?$i:Qi)+ea*(e*this.n%this.d)>this.d?$i:Qi),e)},roundTo:function(e,t){da(e,t);let n=this.n*aa.d,r=this.d*aa.n,i=n%r,a=sa(n/r);return i+i>=r&&a++,ca(this.s*a*aa.n,aa.d)},divisible:function(e,t){return da(e,t),aa.n===Qi?!1:this.n*aa.d%(aa.n*this.d)===Qi},valueOf:function(){return Number(this.s*this.n)/Number(this.d)},toString:function(e=15){let t=this.n,n=this.d,r=pa(t,n),i=ma(t,n,r),a=this.s<Qi?`-`:``;if(a+=sa(t/n),t%=n,t*=ra,t&&(a+=`.`),r){for(let e=i;e--;)a+=sa(t/n),t%=n,t*=ra;a+=`(`;for(let e=r;e--;)a+=sa(t/n),t%=n,t*=ra;a+=`)`}else for(let r=e;t&&r--;)a+=sa(t/n),t%=n,t*=ra;return a},toFraction:function(e=!1){let t=this.n,n=this.d,r=this.s<Qi?`-`:``;if(n===$i)r+=t;else{let i=sa(t/n);e&&i>Qi&&(r+=i,r+=` `,t%=n),r+=t,r+=`/`,r+=n}return r},toLatex:function(e=!1){let t=this.n,n=this.d,r=this.s<Qi?`-`:``;if(n===$i)r+=t;else{let i=sa(t/n);e&&i>Qi&&(r+=i,t%=n),r+=`\\frac{`,r+=t,r+=`}{`,r+=n,r+=`}`}return r},toContinued:function(){let e=this.n,t=this.d,n=[];for(;t;){n.push(sa(e/t));let r=e%t;e=t,t=r}return n},simplify:function(e=.001){let t=BigInt(Math.ceil(1/e)),n=this.abs(),r=n.toContinued();for(let e=1;e<r.length;e++){let i=ca(r[e-1],$i);for(let t=e-2;t>=0;t--)i=i.inverse().add(r[t]);let a=i.sub(n);if(a.n*t<a.d)return i.mul(this.s)}return this}};var ba=K(`Fraction`,[],()=>(Object.defineProperty(ga,`name`,{value:`Fraction`}),ga.prototype.constructor=ga,ga.prototype.type=`Fraction`,ga.prototype.isFraction=!0,ga.prototype.toJSON=function(){return{mathjs:`Fraction`,n:String(this.s*this.n),d:String(this.d)}},ga.fromJSON=function(e){return new ga(e)},ga),{isClass:!0}),xa=K(`Range`,[],()=>{function e(t,n,r){if(!(this instanceof e))throw SyntaxError(`Constructor must be called with the new operator`);var i=t!=null,a=n!=null,o=r!=null;if(i){if(ct(t))t=t.toNumber();else if(typeof t!=`number`&&!lt(t))throw TypeError(`Parameter start must be a number or bigint`)}if(a){if(ct(n))n=n.toNumber();else if(typeof n!=`number`&&!lt(n))throw TypeError(`Parameter end must be a number or bigint`)}if(o){if(ct(r))r=r.toNumber();else if(typeof r!=`number`&&!lt(r))throw TypeError(`Parameter step must be a number or bigint`)}if(this.start=i?parseFloat(t):0,this.end=a?parseFloat(n):0,this.step=o?parseFloat(r):1,o&&Rn(this.step,0))throw Error(`Step must not be zero`)}return e.prototype.type=`Range`,e.prototype.isRange=!0,e.parse=function(t){if(typeof t!=`string`)return null;var n=t.split(`:`).map(function(e){return parseFloat(e)});if(n.some(function(e){return isNaN(e)}))return null;switch(n.length){case 2:return new e(n[0],n[1]);case 3:return new e(n[0],n[2],n[1]);default:return null}},e.prototype.clone=function(){return new e(this.start,this.end,this.step)},e.prototype.size=function(){var e=0,t=this.start,n=this.step,r=this.end-t;return xn(n)===xn(r)?e=Math.ceil(r/n):r===0&&(e=0),isNaN(e)&&(e=0),[e]},e.prototype.min=function(){var e=this.size()[0];if(e>0)return this.step>0?this.start:this.start+(e-1)*this.step},e.prototype.max=function(){var e=this.size()[0];if(e>0)return this.step>0?this.start+(e-1)*this.step:this.start},e.prototype.forEach=function(e){var t=this.start,n=this.step,r=this.end,i=0;if(n>0)for(;t<r;)e(t,[i],this),t+=n,i++;else if(n<0)for(;t>r;)e(t,[i],this),t+=n,i++},e.prototype.map=function(e){var t=[];return this.forEach(function(n,r,i){t[r[0]]=e(n,r,i)}),t},e.prototype.toArray=function(){var e=[];return this.forEach(function(t,n){e[n[0]]=t}),e},e.prototype.valueOf=function(){return this.toArray()},e.prototype.format=function(e){var t=On(this.start,e);return this.step!==1&&(t+=`:`+On(this.step,e)),t+=`:`+On(this.end,e),t},e.prototype.toString=function(){return this.format()},e.prototype.toJSON=function(){return{mathjs:`Range`,start:this.start,end:this.end,step:this.step}},e.fromJSON=function(t){return new e(t.start,t.end,t.step)},e},{isClass:!0}),Sa=K(`Matrix`,[],()=>{function e(){if(!(this instanceof e))throw SyntaxError(`Constructor must be called with the new operator`)}return e.prototype.type=`Matrix`,e.prototype.isMatrix=!0,e.prototype.storage=function(){throw Error(`Cannot invoke storage on a Matrix interface`)},e.prototype.datatype=function(){throw Error(`Cannot invoke datatype on a Matrix interface`)},e.prototype.create=function(e,t){throw Error(`Cannot invoke create on a Matrix interface`)},e.prototype.subset=function(e,t,n){throw Error(`Cannot invoke subset on a Matrix interface`)},e.prototype.get=function(e){throw Error(`Cannot invoke get on a Matrix interface`)},e.prototype.set=function(e,t,n){throw Error(`Cannot invoke set on a Matrix interface`)},e.prototype.resize=function(e,t){throw Error(`Cannot invoke resize on a Matrix interface`)},e.prototype.reshape=function(e,t){throw Error(`Cannot invoke reshape on a Matrix interface`)},e.prototype.clone=function(){throw Error(`Cannot invoke clone on a Matrix interface`)},e.prototype.size=function(){throw Error(`Cannot invoke size on a Matrix interface`)},e.prototype.map=function(e,t){throw Error(`Cannot invoke map on a Matrix interface`)},e.prototype.forEach=function(e){throw Error(`Cannot invoke forEach on a Matrix interface`)},e.prototype[Symbol.iterator]=function(){throw Error(`Cannot iterate a Matrix interface`)},e.prototype.toArray=function(){throw Error(`Cannot invoke toArray on a Matrix interface`)},e.prototype.valueOf=function(){throw Error(`Cannot invoke valueOf on a Matrix interface`)},e.prototype.format=function(e){throw Error(`Cannot invoke format on a Matrix interface`)},e.prototype.toString=function(){throw Error(`Cannot invoke toString on a Matrix interface`)},e},{isClass:!0});function Ca(e,t,n){var r=e.constructor,i=new r(2),a=``;if(n){if(n<1)throw Error(`size must be in greater than 0`);if(!yn(n))throw Error(`size must be an integer`);if(e.greaterThan(i.pow(n-1).sub(1))||e.lessThan(i.pow(n-1).mul(-1)))throw Error(`Value must be in range [-2^${n-1}, 2^${n-1}-1]`);if(!e.isInteger())throw Error(`Value must be an integer`);e.lessThan(0)&&(e=e.add(i.pow(n))),a=`i${n}`}switch(t){case 2:return`${e.toBinary()}${a}`;case 8:return`${e.toOctal()}${a}`;case 16:return`${e.toHexadecimal()}${a}`;default:throw Error(`Base ${t} not supported `)}}function wa(e,t){if(typeof t==`function`)return t(e);if(!e.isFinite())return e.isNaN()?`NaN`:e.gt(0)?`Infinity`:`-Infinity`;var{notation:n,precision:r,wordSize:i}=kn(t);switch(n){case`fixed`:return Da(e,r);case`exponential`:return Ea(e,r);case`engineering`:return Ta(e,r);case`bin`:return Ca(e,2,i);case`oct`:return Ca(e,8,i);case`hex`:return Ca(e,16,i);case`auto`:var a=Oa(t?.lowerExp,-3),o=Oa(t?.upperExp,5);if(e.isZero())return`0`;var s,c=e.toSignificantDigits(r),l=c.e;return s=l>=a&&l<o?c.toFixed():Ea(e,r),s.replace(/((\.\d*?)(0+))($|e)/,function(){var e=arguments[2],t=arguments[4];return e===`.`?t:e+t});default:throw Error(`Unknown notation "`+n+`". Choose "auto", "exponential", "fixed", "bin", "oct", or "hex.`)}}function Ta(e,t){var n=e.e,r=n%3==0?n:n<0?n-3-n%3:n-n%3,i=e.mul(10**-r).toPrecision(t);if(i.includes(`e`)){var a=e.constructor;i=new a(i).toFixed()}return i+`e`+(n>=0?`+`:``)+r.toString()}function Ea(e,t){return t===void 0?e.toExponential():e.toExponential(t-1)}function Da(e,t){return e.toFixed(t)}function Oa(e,t){return st(e)?e:ct(e)?e.toNumber():t}function ka(e,t){var n=e.length-t.length,r=e.length;return e.substring(n,r)===t}function Aa(e,t){var n=ja(e,t);return t&&typeof t==`object`&&`truncate`in t&&n.length>t.truncate?n.substring(0,t.truncate-3)+`...`:n}function ja(e,t){return typeof e==`number`?On(e,t):ct(e)?wa(e,t):Ia(e)?!t||t.fraction!==`decimal`?`${e.s*e.n}/${e.d}`:e.toString():Array.isArray(e)?Fa(e,t):pt(e)?Ma(e):typeof e==`function`?e.syntax?String(e.syntax):`function`:e&&typeof e==`object`?typeof e.format==`function`?e.format(t):e&&e.toString(t)!=={}.toString()?e.toString(t):`{`+Object.keys(e).map(n=>Ma(n)+`: `+Aa(e[n],t)).join(`, `)+`}`:String(e)}function Ma(e){for(var t=String(e),n=``,r=0;r<t.length;){var i=t.charAt(r);n+=i in Na?Na[i]:i,r++}return`"`+n+`"`}var Na={'"':`\\"`,"\\":`\\\\`,"\b":`\\b`,"\f":`\\f`,"\n":`\\n`,"\r":`\\r`," ":`\\t`};function Pa(e){var t=String(e);return t=t.replace(/&/g,`&`).replace(/"/g,`"`).replace(/'/g,`'`).replace(/</g,`<`).replace(/>/g,`>`),t}function Fa(e,t){if(Array.isArray(e)){for(var n=`[`,r=e.length,i=0;i<r;i++)i!==0&&(n+=`, `),n+=Fa(e[i],t);return n+=`]`,n}else return Aa(e,t)}function Ia(e){return e&&typeof e==`object`&&typeof e.s==`bigint`&&typeof e.n==`bigint`&&typeof e.d==`bigint`||!1}function La(e,t){if(!pt(e))throw TypeError(`Unexpected type of argument in function compareText (expected: string or Array or Matrix, actual: `+Zt(e)+`, index: 0)`);if(!pt(t))throw TypeError(`Unexpected type of argument in function compareText (expected: string or Array or Matrix, actual: `+Zt(t)+`, index: 1)`);return e===t?0:e>t?1:-1}function Ra(e,t,n){if(!(this instanceof Ra))throw SyntaxError(`Constructor must be called with the new operator`);this.actual=e,this.expected=t,this.relation=n,this.message=`Dimension mismatch (`+(Array.isArray(e)?`[`+e.join(`, `)+`]`:e)+` `+(this.relation||`!=`)+` `+(Array.isArray(t)?`[`+t.join(`, `)+`]`:t)+`)`,this.stack=Error().stack}Ra.prototype=RangeError(),Ra.prototype.constructor=RangeError,Ra.prototype.name=`DimensionError`,Ra.prototype.isDimensionError=!0;function za(e,t,n){if(!(this instanceof za))throw SyntaxError(`Constructor must be called with the new operator`);this.index=e,arguments.length<3?(this.min=0,this.max=t):(this.min=t,this.max=n),this.min!==void 0&&this.index<this.min?this.message=`Index out of range (`+this.index+` < `+this.min+`)`:this.max!==void 0&&this.index>=this.max?this.message=`Index out of range (`+this.index+` > `+(this.max-1)+`)`:this.message=`Index out of range (`+this.index+`)`,this.stack=Error().stack}za.prototype=RangeError(),za.prototype.constructor=RangeError,za.prototype.name=`IndexError`,za.prototype.isIndexError=!0;function Ba(e){for(var t=[];Array.isArray(e);)t.push(e.length),e=e[0];return t}function Va(e,t,n){var r,i=e.length;if(i!==t[n])throw new Ra(i,t[n]);if(n<t.length-1){var a=n+1;for(r=0;r<i;r++){var o=e[r];if(!Array.isArray(o))throw new Ra(t.length-1,t.length,`<`);Va(e[r],t,a)}}else for(r=0;r<i;r++)if(Array.isArray(e[r]))throw new Ra(t.length+1,t.length,`>`)}function Ha(e,t){if(t.length===0){if(Array.isArray(e))throw new Ra(e.length,0)}else Va(e,t,0)}function Ua(e,t){var n=e.isMatrix?e._size:Ba(e);t._sourceSize.forEach((e,t)=>{if(e!==null&&e!==n[t])throw new Ra(e,n[t])})}function Wa(e,t){if(e!==void 0){if(!st(e)||!yn(e))throw TypeError(`Index must be an integer (value: `+e+`)`);if(e<0||typeof t==`number`&&e>=t)throw new za(e,t)}}function Ga(e){for(var t=0;t<e._dimensions.length;++t){var n=e._dimensions[t];if(n._data&&mt(n._data)){if(n._size[0]===0)return!0}else if(n.isRange){if(n.start===n.end)return!0}else if(pt(n)&&n.length===0)return!0}return!1}function Ka(e,t,n){if(!Array.isArray(t))throw TypeError(`Array expected`);if(t.length===0)throw Error(`Resizing to scalar is not supported`);return t.forEach(function(e){if(!st(e)||!yn(e)||e<0)throw TypeError(`Invalid size, must contain positive integers (size: `+Aa(t)+`)`)}),(st(e)||ct(e))&&(e=[e]),qa(e,t,0,n===void 0?0:n),e}function qa(e,t,n,r){var i,a,o=e.length,s=t[n],c=Math.min(o,s);if(e.length=s,n<t.length-1){var l=n+1;for(i=0;i<c;i++)a=e[i],Array.isArray(a)||(a=[a],e[i]=a),qa(a,t,l,r);for(i=c;i<s;i++)a=[],e[i]=a,qa(a,t,l,r)}else{for(i=0;i<c;i++)for(;Array.isArray(e[i]);)e[i]=e[i][0];for(i=c;i<s;i++)e[i]=r}}function Ja(e,t){var n=no(e,!0),r=n.length;if(!Array.isArray(e)||!Array.isArray(t))throw TypeError(`Array expected`);if(t.length===0)throw new Ra(0,r,`!=`);t=Ya(t,r);var i=Xa(t);if(r!==i)throw new Ra(i,r,`!=`);try{return Za(n,t)}catch(e){throw e instanceof Ra?new Ra(i,r,`!=`):e}}function Ya(e,t){var n=Xa(e),r=e.slice(),i=-1,a=e.indexOf(i);if(e.indexOf(i,a+1)>=0)throw Error(`More than one wildcard in sizes`);var o=a>=0,s=t%n===0;if(o)if(s)r[a]=-t/n;else throw Error(`Could not replace wildcard, since `+t+` is no multiple of `+-n);return r}function Xa(e){return e.reduce((e,t)=>e*t,1)}function Za(e,t){for(var n=e,r,i=t.length-1;i>0;i--){var a=t[i];r=[];for(var o=n.length/a,s=0;s<o;s++)r.push(n.slice(s*a,(s+1)*a));n=r}return n}function Qa(e,t){for(var n=t||Ba(e);Array.isArray(e)&&e.length===1;)e=e[0],n.shift();for(var r=n.length;n[r-1]===1;)r--;return r<n.length&&(e=$a(e,r,0),n.length=r),e}function $a(e,t,n){var r,i;if(n<t){var a=n+1;for(r=0,i=e.length;r<i;r++)e[r]=$a(e[r],t,a)}else for(;Array.isArray(e);)e=e[0];return e}function eo(e,t,n,r){var i=r||Ba(e);if(n)for(var a=0;a<n;a++)e=[e],i.unshift(1);for(e=to(e,t,0);i.length<t;)i.push(1);return e}function to(e,t,n){var r,i;if(Array.isArray(e)){var a=n+1;for(r=0,i=e.length;r<i;r++)e[r]=to(e[r],t,a)}else for(var o=n;o<t;o++)e=[e];return e}function no(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:!1;if(!Array.isArray(e))return e;if(typeof t!=`boolean`)throw TypeError(`Boolean expected for second argument of flatten`);var n=[];return t?i(e):r(e),n;function r(e){for(var t=0;t<e.length;t++){var i=e[t];Array.isArray(i)?r(i):n.push(i)}}function i(e){if(Array.isArray(e[0]))for(var t=0;t<e.length;t++)i(e[t]);else for(var r=0;r<e.length;r++)n.push(e[r])}}function ro(e,t){return Array.prototype.map.call(e,t)}function io(e,t){Array.prototype.forEach.call(e,t)}function ao(e,t){if(Ba(e).length!==1)throw Error(`Only one dimensional matrices supported`);return Array.prototype.filter.call(e,t)}function oo(e,t){if(Ba(e).length!==1)throw Error(`Only one dimensional matrices supported`);return Array.prototype.filter.call(e,e=>t.test(e))}function so(e,t){return Array.prototype.join.call(e,t)}function co(e){if(!Array.isArray(e))throw TypeError(`Array input expected`);if(e.length===0)return e;var t=[],n=0;t[0]={value:e[0],identifier:0};for(var r=1;r<e.length;r++)e[r]===e[r-1]?n++:n=0,t.push({value:e[r],identifier:n});return t}function lo(e){if(!Array.isArray(e))throw TypeError(`Array input expected`);if(e.length===0)return e;for(var t=[],n=0;n<e.length;n++)t.push(e[n].value);return t}function uo(e,t){for(var n,r=0,i=0;i<e.length;i++){var a=e[i],o=Array.isArray(a);if(i===0&&o&&(r=a.length),o&&a.length!==r)return;var s=o?uo(a,t):t(a);if(n===void 0)n=s;else if(n!==s)return`mixed`}return n}function fo(e,t,n,r){if(r<n){if(e.length!==t.length)throw new Ra(e.length,t.length);for(var i=[],a=0;a<e.length;a++)i[a]=fo(e[a],t[a],n,r+1);return i}else return e.concat(t)}function po(){var e=Array.prototype.slice.call(arguments,0,-1),t=Array.prototype.slice.call(arguments,-1);if(e.length===1)return e[0];if(e.length>1)return e.slice(1).reduce(function(e,n){return fo(e,n,t,0)},e[0]);throw Error(`Wrong number of arguments in function concat`)}function mo(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];for(var r=t.map(e=>e.length),i=Math.max(...r),a=Array(i).fill(null),o=0;o<t.length;o++)for(var s=t[o],c=r[o],l=0;l<c;l++){var u=i-c+l;s[l]>a[u]&&(a[u]=s[l])}for(var d=0;d<t.length;d++)ho(t[d],a);return a}function ho(e,t){for(var n=t.length,r=e.length,i=0;i<r;i++){var a=n-r+i;if(e[i]<t[a]&&e[i]>1||e[i]>t[a])throw Error(`shape mismatch: mismatch is found in arg with shape (${e}) not possible to broadcast dimension ${r} with size ${e[i]} to size ${t[a]}`)}}function go(e,t){var n=Ba(e);if(nn(n,t))return e;ho(n,t);var r=mo(n,t),i=r.length,a=[...Array(i-n.length).fill(1),...n],o=xo(e);n.length<i&&(o=Ja(o,a),n=Ba(o));for(var s=0;s<i;s++)n[s]<r[s]&&(o=_o(o,r[s],s),n=Ba(o));return o}function _o(e,t,n){return po(...Array(t).fill(e),n)}function vo(e,t){if(!Array.isArray(e))throw Error(`Array expected`);if(!Array.isArray(t))throw Error(`Array expected for index`);var n=Ba(e);if(t.length!==n.length)throw new Ra(t.length,n.length);for(var r=0;r<t.length;r++)Wa(t[r],n[r]);return t.reduce((e,t)=>e[t],e)}function yo(e,t){var n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:!1;if(e.length===0)return[];if(n)return a(e);var r=[];return i(e,0);function i(n,a){if(Array.isArray(n)){for(var o=n.length,s=Array(o),c=0;c<o;c++)r[a]=c,s[c]=i(n[c],a+1);return s}else return t(n,r.slice(0,a),e)}function a(e){if(Array.isArray(e)){for(var n=e.length,r=Array(n),i=0;i<n;i++)r[i]=a(e[i]);return r}else return t(e)}}function bo(e,t){var n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:!1;if(e.length===0)return;if(n){a(e);return}var r=[];i(e,0);function i(n,a){if(Array.isArray(n))for(var o=n.length,s=0;s<o;s++)r[a]=s,i(n[s],a+1);else t(n,r.slice(0,a),e)}function a(e){if(Array.isArray(e))for(var n=e.length,r=0;r<n;r++)a(e[r]);else t(e)}}function xo(e){return We([],e)}function So(e,t,n,r){if(Jn.default.isTypedFunction(e)){var i;if(r)i=1;else{var a=t.isMatrix?t.size():Ba(t);if(!a.length||a[a.length-1]===0)return{isUnary:r,fn:e};var o=a.map(()=>0);i=To(e,t.isMatrix?t.get(o):vo(t,o),o,t)}var s;if(t.isMatrix&&t.dataType!==`mixed`&&t.dataType!==void 0){var c=Co(e,i);s=c===void 0?e:c}else s=e;return i>=1&&i<=3?{isUnary:i===1,fn:function(){for(var t=arguments.length,r=Array(t),a=0;a<t;a++)r[a]=arguments[a];return Eo(s,r.slice(0,i),n,e.name)}}:{isUnary:!1,fn:function(){for(var t=arguments.length,r=Array(t),i=0;i<t;i++)r[i]=arguments[i];return Eo(s,r,n,e.name)}}}return r===void 0?{isUnary:wo(e),fn:e}:{isUnary:r,fn:e}}function Co(e,t){var n=[];if(Object.entries(e.signatures).forEach(e=>{var[r,i]=e;r.split(`,`).length===t&&n.push(i)}),n.length===1)return n[0]}function wo(e){if(e.length!==1)return!1;var t=e.toString();if(/arguments/.test(t))return!1;var n=t.match(/\(.*?\)/);return!/\.\.\./.test(n)}function To(e,t,n,r){for(var i=[t,n,r],a=3;a>0;a--){var o=i.slice(0,a);if(Jn.default.resolve(e,o)!==null)return a}}function Eo(e,t,n,r){try{return e(...t)}catch(e){Do(e,t,n,r)}}function Do(e,t,n,r){if(e instanceof TypeError&&e.data?.category===`wrongType`){var i=[];throw i.push(`value: ${Zt(t[0])}`),t.length>=2&&i.push(`index: ${Zt(t[1])}`),t.length>=3&&i.push(`array: ${Zt(t[2])}`),TypeError(`Function ${n} cannot apply callback arguments ${r}(${i.join(`, `)}) at index ${JSON.stringify(t[1])}`)}else throw TypeError(`Function ${n} cannot apply callback arguments to function ${r}: ${e.message}`)}var Oo=K(`DenseMatrix`,[`Matrix`,`config`],e=>{var{Matrix:t,config:n}=e;function r(e,t){if(!(this instanceof r))throw SyntaxError(`Constructor must be called with the new operator`);if(t&&!pt(t))throw Error(`Invalid datatype: `+t);if(ht(e))e.type===`DenseMatrix`?(this._data=Qt(e._data),this._size=Qt(e._size),this._datatype=t||e._datatype):(this._data=e.toArray(),this._size=e.size(),this._datatype=t||e._datatype);else if(e&&mt(e.data)&&mt(e.size))this._data=e.data,this._size=e.size,Ha(this._data,this._size),this._datatype=t||e.datatype;else if(mt(e))this._data=u(e),this._size=Ba(this._data),Ha(this._data,this._size),this._datatype=t;else if(e)throw TypeError(`Unsupported type of data (`+Zt(e)+`)`);else this._data=[],this._size=[0],this._datatype=t}r.prototype=new t,r.prototype.createDenseMatrix=function(e,t){return new r(e,t)},Object.defineProperty(r,`name`,{value:`DenseMatrix`}),r.prototype.constructor=r,r.prototype.type=`DenseMatrix`,r.prototype.isDenseMatrix=!0,r.prototype.getDataType=function(){return uo(this._data,Zt)},r.prototype.storage=function(){return`dense`},r.prototype.datatype=function(){return this._datatype},r.prototype.create=function(e,t){return new r(e,t)},r.prototype.subset=function(e,t,n){switch(arguments.length){case 1:return i(this,e);case 2:case 3:return o(this,e,t,n);default:throw SyntaxError(`Wrong number of arguments`)}},r.prototype.get=function(e){return vo(this._data,e)},r.prototype.set=function(e,t,n){if(!mt(e))throw TypeError(`Array expected`);if(e.length<this._size.length)throw new Ra(e.length,this._size.length,`<`);var r,i,a,o=e.map(function(e){return e+1});l(this,o,n);var s=this._data;for(r=0,i=e.length-1;r<i;r++)a=e[r],Wa(a,s.length),s=s[a];return a=e[e.length-1],Wa(a,s.length),s[a]=t,this};function i(e,t){if(!bt(t))throw TypeError(`Invalid index`);if(n.legacySubset?t.size().every(e=>e===1):t.isScalar())return e.get(t.min());var i=t.size();if(i.length!==e._size.length)throw new Ra(i.length,e._size.length);for(var o=t.min(),s=t.max(),c=0,l=e._size.length;c<l;c++)Wa(o[c],e._size[c]),Wa(s[c],e._size[c]);var u=new r,d=a(e._data,t);return u._size=d.size,u._datatype=e._datatype,u._data=d.data,n.legacySubset?u.reshape(t.size()):u}function a(e,t){var n=t.size().length-1,r=Array(n);return{data:i(e),size:r.filter(e=>e!==null)};function i(e){var a=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,o=t.dimension(a);function s(e,t){return st(e)?t(e):e.map(t).valueOf()}return st(o)?r[a]=null:r[a]=o.size()[0],a<n?s(o,t=>(Wa(t,e.length),i(e[t],a+1))):s(o,t=>(Wa(t,e.length),e[t]))}}function o(e,t,n,r){if(!t||t.isIndex!==!0)throw TypeError(`Invalid index`);var i=t.size(),a=t.isScalar(),o;if(ht(n)?(o=n.size(),n=n.valueOf()):o=Ba(n),a){if(o.length!==0)throw TypeError(`Scalar expected`);e.set(t.min(),n,r)}else{if(!nn(o,i)){if(o.length===0)n=go([n],i);else try{n=go(n,i)}catch{}o=Ba(n)}if(i.length<e._size.length)throw new Ra(i.length,e._size.length,`<`);if(o.length<i.length){for(var c=0,u=0;i[c]===1&&o[c]===1;)c++;for(;i[c]===1;)u++,c++;n=eo(n,i.length,u,o)}if(!nn(i,o))throw new Ra(i,o,`>`);l(e,t.max().map(function(e){return e+1}),r),s(e._data,t,n)}return e}function s(e,t,n){var r=t.size().length-1;i(e,n);function i(e,n){var a=arguments.length>2&&arguments[2]!==void 0?arguments[2]:0,o=t.dimension(a),s=(t,r)=>{Wa(t,e.length),i(e[t],n[r[0]],a+1)},c=(t,r)=>{Wa(t,e.length),e[t]=n[r[0]]};a<r?st(o)?s(o,[0]):o.forEach(s):st(o)?c(o,[0]):o.forEach(c)}}r.prototype.resize=function(e,t,n){if(!gt(e))throw TypeError(`Array or Matrix expected`);var r=e.valueOf().map(e=>Array.isArray(e)&&e.length===1?e[0]:e);return c(n?this.clone():this,r,t)};function c(e,t,n){if(t.length===0){for(var r=e._data;mt(r);)r=r[0];return r}return e._size=t.slice(0),e._data=Ka(e._data,e._size,n),e}r.prototype.reshape=function(e,t){var n=t?this.clone():this;return n._data=Ja(n._data,e),n._size=Ya(e,n._size.reduce((e,t)=>e*t)),n};function l(e,t,n){for(var r=e._size.slice(0),i=!1;r.length<t.length;)r.push(0),i=!0;for(var a=0,o=t.length;a<o;a++)t[a]>r[a]&&(r[a]=t[a],i=!0);i&&c(e,r,n)}r.prototype.clone=function(){return new r({data:Qt(this._data),size:Qt(this._size),datatype:this._datatype})},r.prototype.size=function(){return this._size.slice(0)},r.prototype.map=function(e){arguments.length>1&&arguments[1]!==void 0&&arguments[1];var t=arguments.length>2&&arguments[2]!==void 0?arguments[2]:!1,n=this,r=n._size.length-1;if(r<0)return n.clone();var i=So(e,n,`map`,t),a=i.fn,o=n.create(void 0,n._datatype);if(o._size=n._size,t||i.isUnary)return o._data=f(n._data),o;if(r===0){for(var s=n.valueOf(),c=Array(s.length),l=0;l<s.length;l++)c[l]=a(s[l],[l],n);return o._data=c,o}var u=[];return o._data=d(n._data),o;function d(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,i=Array(e.length);if(t<r)for(var o=0;o<e.length;o++)u[t]=o,i[o]=d(e[o],t+1);else for(var s=0;s<e.length;s++)u[t]=s,i[s]=a(e[s],u.slice(),n);return i}function f(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,n=Array(e.length);if(t<r)for(var i=0;i<e.length;i++)n[i]=f(e[i],t+1);else for(var o=0;o<e.length;o++)n[o]=a(e[o]);return n}},r.prototype.forEach=function(e){arguments.length>1&&arguments[1]!==void 0&&arguments[1];var t=arguments.length>2&&arguments[2]!==void 0?arguments[2]:!1,n=this,r=n._size.length-1;if(r<0)return;var i=So(e,n,`map`,t),a=i.fn;if(t||i.isUnary){l(n._data);return}if(r===0){for(var o=0;o<n._data.length;o++)a(n._data[o],[o],n);return}var s=[];c(n._data);function c(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0;if(t<r)for(var i=0;i<e.length;i++)s[t]=i,c(e[i],t+1);else for(var o=0;o<e.length;o++)s[t]=o,a(e[o],s.slice(),n)}function l(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0;if(t<r)for(var n=0;n<e.length;n++)l(e[n],t+1);else for(var i=0;i<e.length;i++)a(e[i])}},r.prototype[Symbol.iterator]=function*(){var e=this._size.length-1;if(!(e<0)){if(e===0){for(var t=0;t<this._data.length;t++)yield{value:this._data[t],index:[t]};return}for(var n=Array(e+1).fill(0),r=this._size.reduce((e,t)=>e*t,1),i=0;i<r;i++){for(var a=this._data,o=0;o<e;o++)a=a[n[o]];yield{value:a[n[e]],index:n.slice()};for(var s=e;s>=0&&(n[s]++,!(n[s]<this._size[s]));s--)n[s]=0}}},r.prototype.rows=function(){var e=[];if(this.size().length!==2)throw TypeError(`Rows can only be returned for a 2D matrix.`);for(var t of this._data)e.push(new r([t],this._datatype));return e},r.prototype.columns=function(){var e=this,t=[],n=this.size();if(n.length!==2)throw TypeError(`Rows can only be returned for a 2D matrix.`);for(var i=this._data,a=function(n){var a=i.map(e=>[e[n]]);t.push(new r(a,e._datatype))},o=0;o<n[1];o++)a(o);return t},r.prototype.toArray=function(){return Qt(this._data)},r.prototype.valueOf=function(){return this._data},r.prototype.format=function(e){return Aa(this._data,e)},r.prototype.toString=function(){return Aa(this._data)},r.prototype.toJSON=function(){return{mathjs:`DenseMatrix`,data:this._data,size:this._size,datatype:this._datatype}},r.prototype.diagonal=function(e){if(e){if(ct(e)&&(e=e.toNumber()),!st(e)||!yn(e))throw TypeError(`The parameter k must be an integer number`)}else e=0;for(var t=e>0?e:0,n=e<0?-e:0,i=this._size[0],a=this._size[1],o=Math.min(i-n,a-t),s=[],c=0;c<o;c++)s[c]=this._data[c+n][c+t];return new r({data:s,size:[o],datatype:this._datatype})},r.diagonal=function(e,t,n,i){if(!mt(e))throw TypeError(`Array expected, size parameter`);if(e.length!==2)throw Error(`Only two dimensions matrix are supported`);if(e=e.map(function(e){if(ct(e)&&(e=e.toNumber()),!st(e)||!yn(e)||e<1)throw Error(`Size values must be positive integers`);return e}),n){if(ct(n)&&(n=n.toNumber()),!st(n)||!yn(n))throw TypeError(`The parameter k must be an integer number`)}else n=0;var a=n>0?n:0,o=n<0?-n:0,s=e[0],c=e[1],l=Math.min(s-o,c-a),u;if(mt(t)){if(t.length!==l)throw Error(`Invalid value array length`);u=function(e){return t[e]}}else if(ht(t)){var d=t.size();if(d.length!==1||d[0]!==l)throw Error(`Invalid matrix length`);u=function(e){return t.get([e])}}else u=function(){return t};i||=ct(u(0))?u(0).mul(0):0;var f=[];if(e.length>0){f=Ka(f,e,i);for(var p=0;p<l;p++)f[p+o][p+a]=u(p)}return new r({data:f,size:[s,c]})},r.fromJSON=function(e){return new r(e)},r.prototype.swapRows=function(e,t){if(!st(e)||!yn(e)||!st(t)||!yn(t))throw Error(`Row index must be positive integers`);if(this._size.length!==2)throw Error(`Only two dimensional matrix is supported`);return Wa(e,this._size[0]),Wa(t,this._size[0]),r._swapRows(e,t,this._data),this},r._swapRows=function(e,t,n){var r=n[e];n[e]=n[t],n[t]=r};function u(e){return ht(e)?u(e.valueOf()):mt(e)?e.map(u):e}return r},{isClass:!0}),ko=`clone`,Ao=K(ko,[`typed`],e=>{var{typed:t}=e;return t(ko,{any:Qt})});function jo(e){var t=e.length,n=e[0].length,r,i,a=[];for(i=0;i<n;i++){var o=[];for(r=0;r<t;r++)o.push(e[r][i]);a.push(o)}return a}function Mo(e){for(var t=0;t<e.length;t++)if(gt(e[t]))return!0;return!1}function No(e,t){ht(e)?e.forEach(e=>t(e),!1,!0):bo(e,t,!0)}function Po(e,t,n){if(!n)return ht(e)?e.map(e=>t(e),!1,!0):yo(e,t,!0);var r=e=>e===0?e:t(e);return ht(e)?e.map(e=>r(e),!1,!0):yo(e,r,!0)}function Fo(e,t,n){var r=Array.isArray(e)?Ba(e):e.size();if(t<0||t>=r.length)throw new za(t,r.length);return ht(e)?e.create(Io(e.valueOf(),t,n),e.datatype()):Io(e,t,n)}function Io(e,t,n){var r,i,a,o;if(t<=0)if(Array.isArray(e[0])){for(o=jo(e),i=[],r=0;r<o.length;r++)i[r]=Io(o[r],t-1,n);return i}else{for(a=e[0],r=1;r<e.length;r++)a=n(a,e[r]);return a}else{for(i=[],r=0;r<e.length;r++)i[r]=Io(e[r],t-1,n);return i}}function Lo(e,t,n,r,i,a,o,s,c,l,u){var d=e._values,f=e._index,p=e._ptr,m,h,g,_;if(r)for(h=p[t],g=p[t+1],m=h;m<g;m++)_=f[m],n[_]===a?(r[_]=c?s(d[m],r[_]):s(r[_],d[m]),i[_]=a):(n[_]=a,o.push(_),l?(r[_]=c?s(d[m],u):s(u,d[m]),i[_]=a):r[_]=d[m]);else for(h=p[t],g=p[t+1],m=h;m<g;m++)_=f[m],n[_]===a?i[_]=a:(n[_]=a,o.push(_))}var Ro=`isInteger`,zo=K(Ro,[`typed`,`equal`],e=>{var{typed:t,equal:n}=e;return t(Ro,{number:e=>Number.isFinite(e)?n(e,Math.round(e)):!1,BigNumber:e=>e.isFinite()?n(e.round(),e):!1,bigint:e=>!0,Fraction:e=>e.d===1n,"Array | Matrix":t.referToSelf(e=>t=>Po(t,e))})}),Bo=`number`,Vo=`number, number`;function Ho(e){return Math.abs(e)}Ho.signature=Bo;function Uo(e,t){return e+t}Uo.signature=Vo;function Wo(e,t){return e-t}Wo.signature=Vo;function Go(e,t){return e*t}Go.signature=Vo;function Ko(e,t){return e/t}Ko.signature=Vo;function qo(e){return-e}qo.signature=Bo;function Jo(e){return e}Jo.signature=Bo;function Yo(e){return Tn(e)}Yo.signature=Bo;function Xo(e){return e*e*e}Xo.signature=Bo;function Zo(e){return Math.exp(e)}Zo.signature=Bo;function Qo(e){return En(e)}Qo.signature=Bo;function $o(e,t){if(!yn(e)||!yn(t))throw Error(`Parameters in function gcd must be integer numbers`);for(var n;t!==0;)n=e%t,e=t,t=n;return e<0?-e:e}$o.signature=Vo;function es(e,t){if(!yn(e)||!yn(t))throw Error(`Parameters in function lcm must be integer numbers`);if(e===0||t===0)return 0;for(var n,r=e*t;t!==0;)n=t,t=e%n,e=n;return Math.abs(r/e)}es.signature=Vo;function ts(e,t){return t?Math.log(e)/Math.log(t):Math.log(e)}function ns(e){return Cn(e)}ns.signature=Bo;function rs(e){return Sn(e)}rs.signature=Bo;function is(e){return wn(e)}is.signature=Bo;function as(e,t){return t===0?e:e-t*Math.floor(e/t)}as.signature=Vo;function os(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:2,n=t<0;if(n&&(t=-t),t===0)throw Error(`Root must be non-zero`);if(e<0&&Math.abs(t)%2!=1)throw Error(`Root must be odd when a is negative.`);if(e===0)return n?1/0:0;if(!isFinite(e))return n?0:e;var r=Math.abs(e)**(1/t);return r=e<0?-r:r,n?1/r:r}function ss(e){return xn(e)}ss.signature=Bo;function cs(e){return Math.sqrt(e)}cs.signature=Bo;function ls(e){return e*e}ls.signature=Bo;function us(e,t){var n,r,i,a=0,o=1,s=1,c=0;if(!yn(e)||!yn(t))throw Error(`Parameters in function xgcd must be integer numbers`);for(;t;)r=Math.floor(e/t),i=e-r*t,n=a,a=o-r*a,o=n,n=s,s=c-r*s,c=n,e=t,t=i;return e<0?[-e,-o,-c]:[e,e?o:0,c]}us.signature=Vo;function ds(e,t){return e*e<1&&t===1/0||e*e>1&&t===-1/0?0:e**+t}ds.signature=Vo;function fs(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0;if(!yn(t)||t<0||t>15)throw Error(`Number of decimals in function round must be an integer from 0 to 15 inclusive`);return parseFloat(Mn(e,t))}function ps(e){return Math.abs(e)}ps.signature=Bo;var ms=`number`,hs=`number, number`;function gs(e,t){if(!yn(e)||!yn(t))throw Error(`Integers expected in function bitAnd`);return e&t}gs.signature=hs;function _s(e){if(!yn(e))throw Error(`Integer expected in function bitNot`);return~e}_s.signature=ms;function vs(e,t){if(!yn(e)||!yn(t))throw Error(`Integers expected in function bitOr`);return e|t}vs.signature=hs;function ys(e,t){if(!yn(e)||!yn(t))throw Error(`Integers expected in function bitXor`);return e^t}ys.signature=hs;function bs(e,t){if(!yn(e)||!yn(t))throw Error(`Integers expected in function leftShift`);return e<<t}bs.signature=hs;function xs(e,t){if(!yn(e)||!yn(t))throw Error(`Integers expected in function rightArithShift`);return e>>t}xs.signature=hs;function Ss(e,t){if(!yn(e)||!yn(t))throw Error(`Integers expected in function rightLogShift`);return e>>>t}Ss.signature=hs;function Cs(e,t){if(t<e)return 1;if(t===e)return t;var n=t+e>>1;return Cs(e,n)*Cs(n+1,t)}function ws(e,t){if(!yn(e)||e<0||!yn(t)||t<0)throw TypeError(`Positive integer value expected in function combinations`);if(t>e)throw TypeError(`k must be less than or equal to n`);for(var n=e-t,r=1,i=t<n?n+1:t+1,a=2,o=t<n?t:n,s=i;s<=e;++s)for(r*=s;a<=o&&r%a===0;)r/=a,++a;return a<=o&&(r/=Cs(a,o)),r}ws.signature=`number, number`;var Ts=Math.PI,Es=2*Math.PI,Ds=Math.E,Os=1.618033988749895,ks=`number`,As=`number, number`;function js(e){return!e}js.signature=ks;function Ms(e,t){return!!(e||t)}Ms.signature=As;function Ns(e,t){return!!e!=!!t}Ns.signature=As;function Ps(e,t){return!!(e&&t)}Ps.signature=As;function Fs(e){var t;if(yn(e))return e<=0?Number.isFinite(e)?1/0:NaN:e>171?1/0:Cs(1,e-1);if(e<.5)return Math.PI/(Math.sin(Math.PI*e)*Fs(1-e));if(e>=171.35)return 1/0;if(e>85){var n=e*e,r=n*e,i=r*e,a=i*e;return Math.sqrt(2*Math.PI/e)*(e/Math.E)**+e*(1+1/(12*e)+1/(288*n)-139/(51840*r)-571/(2488320*i)+163879/(209018880*a)+5246819/(75246796800*a*e))}--e,t=Ls[0];for(var o=1;o<Ls.length;++o)t+=Ls[o]/(e+o);var s=e+Is+.5;return Math.sqrt(2*Math.PI)*s**+(e+.5)*Math.exp(-s)*t}Fs.signature=`number`;var Is=4.7421875,Ls=[.9999999999999971,57.15623566586292,-59.59796035547549,14.136097974741746,-.4919138160976202,3399464998481189e-20,4652362892704858e-20,-9837447530487956e-20,.0001580887032249125,-.00021026444172410488,.00021743961811521265,-.0001643181065367639,8441822398385275e-20,-26190838401581408e-21,36899182659531625e-22],Rs=.9189385332046728,zs=[1.000000000190015,76.18009172947146,-86.50532032941678,24.01409824083091,-1.231739572450155,.001208650973866179,-5395239384953e-18];function Bs(e){if(e<0)return NaN;if(e===0)return 1/0;if(!Number.isFinite(e))return e;if(e<.5)return Math.log(Math.PI/Math.sin(Math.PI*e))-Bs(1-e);--e;for(var t=e+5+.5,n=zs[0],r=6;r>=1;r--)n+=zs[r]/(e+r);return Rs+(e+.5)*Math.log(t)-t+Math.log(n)}Bs.signature=`number`;var Vs=`number`,Hs=`number, number`;function Us(e){return Math.acos(e)}Us.signature=Vs;function Ws(e){return zn(e)}Ws.signature=Vs;function Gs(e){return Math.atan(1/e)}Gs.signature=Vs;function Ks(e){return Number.isFinite(e)?(Math.log((e+1)/e)+Math.log(e/(e-1)))/2:0}Ks.signature=Vs;function qs(e){return Math.asin(1/e)}qs.signature=Vs;function Js(e){var t=1/e;return Math.log(t+Math.sqrt(t*t+1))}Js.signature=Vs;function Ys(e){return Math.acos(1/e)}Ys.signature=Vs;function Xs(e){var t=1/e,n=Math.sqrt(t*t-1);return Math.log(n+t)}Xs.signature=Vs;function Zs(e){return Math.asin(e)}Zs.signature=Vs;function Qs(e){return Bn(e)}Qs.signature=Vs;function $s(e){return Math.atan(e)}$s.signature=Vs;function ec(e,t){return Math.atan2(e,t)}ec.signature=Hs;function tc(e){return Vn(e)}tc.signature=Vs;function nc(e){return Math.cos(e)}nc.signature=Vs;function rc(e){return Hn(e)}rc.signature=Vs;function ic(e){return 1/Math.tan(e)}ic.signature=Vs;function ac(e){var t=Math.exp(2*e);return(t+1)/(t-1)}ac.signature=Vs;function oc(e){return 1/Math.sin(e)}oc.signature=Vs;function sc(e){return e===0?1/0:Math.abs(2/(Math.exp(e)-Math.exp(-e)))*xn(e)}sc.signature=Vs;function cc(e){return 1/Math.cos(e)}cc.signature=Vs;function lc(e){return 2/(Math.exp(e)+Math.exp(-e))}lc.signature=Vs;function uc(e){return Math.sin(e)}uc.signature=Vs;function dc(e){return Un(e)}dc.signature=Vs;function fc(e){return Math.tan(e)}fc.signature=Vs;function pc(e){return Wn(e)}pc.signature=Vs;var mc=`number`;function hc(e){return yn(e)}hc.signature=mc;function gc(e){return e<0}gc.signature=mc;function _c(e){return e>0}_c.signature=mc;function vc(e){return e===0}vc.signature=mc;function yc(e){return Number.isNaN(e)}yc.signature=mc;function bc(e,t){var n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:1e-9,r=arguments.length>3&&arguments[3]!==void 0?arguments[3]:0;if(n<=0)throw Error(`Relative tolerance must be greater than 0`);if(r<0)throw Error(`Absolute tolerance must be at least 0`);return e.isNaN()||t.isNaN()?!1:!e.isFinite()||!t.isFinite()?e.eq(t):e.eq(t)?!0:e.minus(t).abs().lte(e.constructor.max(e.constructor.max(e.abs(),t.abs()).mul(n),r))}var xc=`isNegative`,Sc=K(xc,[`typed`,`config`],e=>{var{typed:t,config:n}=e;return t(xc,{number:e=>Rn(e,0,n.relTol,n.absTol)?!1:gc(e),BigNumber:e=>bc(e,new e.constructor(0),n.relTol,n.absTol)?!1:e.isNeg()&&!e.isZero()&&!e.isNaN(),bigint:e=>e<0n,Fraction:e=>e.s<0n,Unit:t.referToSelf(e=>n=>t.find(e,n.valueType())(n.value)),"Array | Matrix":t.referToSelf(e=>t=>Po(t,e))})}),Cc=`isNumeric`,wc=K(Cc,[`typed`],e=>{var{typed:t}=e;return t(Cc,{"number | BigNumber | bigint | Fraction | boolean":()=>!0,"Complex | Unit | string | null | undefined | Node":()=>!1,"Array | Matrix":t.referToSelf(e=>t=>Po(t,e))})}),Tc=`hasNumericValue`,Ec=K(Tc,[`typed`,`isNumeric`],e=>{var{typed:t,isNumeric:n}=e;return t(Tc,{boolean:()=>!0,string:function(e){return e.trim().length>0&&!isNaN(Number(e))},any:function(e){return n(e)}})}),Dc=`isPositive`,Oc=K(Dc,[`typed`,`config`],e=>{var{typed:t,config:n}=e;return t(Dc,{number:e=>Rn(e,0,n.relTol,n.absTol)?!1:_c(e),BigNumber:e=>bc(e,new e.constructor(0),n.relTol,n.absTol)?!1:!e.isNeg()&&!e.isZero()&&!e.isNaN(),bigint:e=>e>0n,Fraction:e=>e.s>0n&&e.n>0n,Unit:t.referToSelf(e=>n=>t.find(e,n.valueType())(n.value)),"Array | Matrix":t.referToSelf(e=>t=>Po(t,e))})}),kc=`isZero`,Ac=K(kc,[`typed`,`equalScalar`],e=>{var{typed:t,equalScalar:n}=e;return t(kc,{"number | BigNumber | Complex | Fraction":e=>n(e,0),bigint:e=>e===0n,Unit:t.referToSelf(e=>n=>t.find(e,n.valueType())(n.value)),"Array | Matrix":t.referToSelf(e=>t=>Po(t,e))})}),jc=`isNaN`,Mc=K(jc,[`typed`],e=>{var{typed:t}=e;return t(jc,{number:yc,BigNumber:function(e){return e.isNaN()},bigint:function(e){return!1},Fraction:function(e){return!1},Complex:function(e){return e.isNaN()},Unit:function(e){return Number.isNaN(e.value)},"Array | Matrix":t.referToSelf(e=>t=>Po(t,e))})}),Nc=`isBounded`,Pc=K(Nc,[`typed`],e=>{var{typed:t}=e;return t(Nc,{number:e=>Number.isFinite(e),"BigNumber | Complex":e=>e.isFinite(),"bigint | Fraction":()=>!0,"null | undefined":()=>!1,Unit:t.referToSelf(e=>t=>e(t.value)),"Array | Matrix":t.referToSelf(e=>t=>(Array.isArray(t)||(t=t.valueOf()),t.every(t=>e(t))))})}),Fc=`isFinite`,Ic=K(Fc,[`typed`,`isBounded`,`map`],e=>{var{typed:t,isBounded:n,map:r}=e;return t(Fc,{"Array | Matrix":e=>r(e,n),any:e=>n(e)})}),Lc=`typeOf`,Rc=K(Lc,[`typed`],e=>{var{typed:t}=e;return t(Lc,{any:Zt})});function zc(e,t,n,r){return Rn(e.re,t.re,n,r)&&Rn(e.im,t.im,n,r)}var Bc=K(`compareUnits`,[`typed`],e=>{var{typed:t}=e;return{"Unit, Unit":t.referToSelf(e=>(n,r)=>{if(!n.equalBase(r))throw Error(`Cannot compare units with different base`);return t.find(e,[n.valueType(),r.valueType()])(n.value,r.value)})}}),Vc=`equalScalar`,Hc=K(Vc,[`typed`,`config`],e=>{var{typed:t,config:n}=e;return t(Vc,{"boolean, boolean":function(e,t){return e===t},"number, number":function(e,t){return Rn(e,t,n.relTol,n.absTol)},"BigNumber, BigNumber":function(e,t){return e.eq(t)||bc(e,t,n.relTol,n.absTol)},"bigint, bigint":function(e,t){return e===t},"Fraction, Fraction":function(e,t){return e.equals(t)},"Complex, Complex":function(e,t){return zc(e,t,n.relTol,n.absTol)}},Bc({typed:t}))});K(Vc,[`typed`,`config`],e=>{var{typed:t,config:n}=e;return t(Vc,{"number, number":function(e,t){return Rn(e,t,n.relTol,n.absTol)}})});var Uc=K(`SparseMatrix`,[`typed`,`equalScalar`,`Matrix`],e=>{var{typed:t,equalScalar:n,Matrix:r}=e;function i(e,t){if(!(this instanceof i))throw SyntaxError(`Constructor must be called with the new operator`);if(t&&!pt(t))throw Error(`Invalid datatype: `+t);if(ht(e))a(this,e,t);else if(e&&mt(e.index)&&mt(e.ptr)&&mt(e.size))this._values=e.values,this._index=e.index,this._ptr=e.ptr,this._size=e.size,this._datatype=t||e.datatype;else if(mt(e))o(this,e,t);else if(e)throw TypeError(`Unsupported type of data (`+Zt(e)+`)`);else this._values=[],this._index=[],this._ptr=[0],this._size=[0,0],this._datatype=t}function a(e,t,n){t.type===`SparseMatrix`?(e._values=t._values?Qt(t._values):void 0,e._index=Qt(t._index),e._ptr=Qt(t._ptr),e._size=Qt(t._size),e._datatype=n||t._datatype):o(e,t.valueOf(),n||t._datatype)}function o(e,r,i){e._values=[],e._index=[],e._ptr=[],e._datatype=i;var a=r.length,o=0,s=n,c=0;if(pt(i)&&(s=t.find(n,[i,i])||n,c=t.convert(0,i)),a>0){var l=0;do{e._ptr.push(e._index.length);for(var u=0;u<a;u++){var d=r[u];if(mt(d)){if(l===0&&o<d.length&&(o=d.length),l<d.length){var f=d[l];s(f,c)||(e._values.push(f),e._index.push(u))}}else l===0&&o<1&&(o=1),s(d,c)||(e._values.push(d),e._index.push(u))}l++}while(l<o)}for(;e._ptr.length<=o;)e._ptr.push(e._index.length);e._size=[a,o]}i.prototype=new r,i.prototype.createSparseMatrix=function(e,t){return new i(e,t)},Object.defineProperty(i,`name`,{value:`SparseMatrix`}),i.prototype.constructor=i,i.prototype.type=`SparseMatrix`,i.prototype.isSparseMatrix=!0,i.prototype.getDataType=function(){return uo(this._values,Zt)},i.prototype.storage=function(){return`sparse`},i.prototype.datatype=function(){return this._datatype},i.prototype.create=function(e,t){return new i(e,t)},i.prototype.density=function(){var e=this._size[0],t=this._size[1];return e!==0&&t!==0?this._index.length/(e*t):0},i.prototype.subset=function(e,t,n){if(!this._values)throw Error(`Cannot invoke subset on a Pattern only matrix`);switch(arguments.length){case 1:return s(this,e);case 2:case 3:return c(this,e,t,n);default:throw SyntaxError(`Wrong number of arguments`)}};function s(e,t){if(!bt(t))throw TypeError(`Invalid index`);if(t.isScalar())return e.get(t.min());var n=t.size();if(n.length!==e._size.length)throw new Ra(n.length,e._size.length);var r,a,o,s,c=t.min(),l=t.max();for(r=0,a=e._size.length;r<a;r++)Wa(c[r],e._size[r]),Wa(l[r],e._size[r]);var u=e._values,d=e._index,f=e._ptr,p=t.dimension(0),m=t.dimension(1),h=[],g=[];function _(e,t){g[e]=t[0],h[e]=!0}Number.isInteger(p)?_(p,[0]):p.forEach(_);var v=u?[]:void 0,y=[],b=[];function x(e){for(b.push(y.length),o=f[e],s=f[e+1];o<s;o++)r=d[o],h[r]===!0&&(y.push(g[r]),v&&v.push(u[o]))}return Number.isInteger(m)?x(m):m.forEach(x),b.push(y.length),new i({values:v,index:y,ptr:b,size:n,datatype:e._datatype})}function c(e,t,n,r){if(!t||t.isIndex!==!0)throw TypeError(`Invalid index`);var i=t.size(),a=t.isScalar(),o;if(ht(n)?(o=n.size(),n=n.toArray()):o=Ba(n),a){if(o.length!==0)throw TypeError(`Scalar expected`);e.set(t.min(),n,r)}else{if(i.length!==1&&i.length!==2)throw new Ra(i.length,e._size.length,`<`);if(o.length<i.length){for(var s=0,c=0;i[s]===1&&o[s]===1;)s++;for(;i[s]===1;)c++,s++;n=eo(n,i.length,c,o)}if(!nn(i,o))throw new Ra(i,o,`>`);if(i.length===1)d(t.dimension(0),(t,i)=>{Wa(t),e.set([t,0],n[i[0]],r)});else{var l=t.dimension(0),u=t.dimension(1);d(l,(t,i)=>{Wa(t),d(u,(a,o)=>{Wa(a),e.set([t,a],n[i[0]][o[0]],r)})})}}return e;function d(e,t){st(e)?t(e,[0]):e.forEach(t)}}i.prototype.get=function(e){if(!mt(e))throw TypeError(`Array expected`);if(e.length!==this._size.length)throw new Ra(e.length,this._size.length);if(!this._values)throw Error(`Cannot invoke get on a Pattern only matrix`);var t=e[0],n=e[1];Wa(t,this._size[0]),Wa(n,this._size[1]);var r=l(t,this._ptr[n],this._ptr[n+1],this._index);return r<this._ptr[n+1]&&this._index[r]===t?this._values[r]:0},i.prototype.set=function(e,r,i){if(!mt(e))throw TypeError(`Array expected`);if(e.length!==this._size.length)throw new Ra(e.length,this._size.length);if(!this._values)throw Error(`Cannot invoke set on a Pattern only matrix`);var a=e[0],o=e[1],s=this._size[0],c=this._size[1],p=n,m=0;pt(this._datatype)&&(p=t.find(n,[this._datatype,this._datatype])||n,m=t.convert(0,this._datatype)),(a>s-1||o>c-1)&&(f(this,Math.max(a+1,s),Math.max(o+1,c),i),s=this._size[0],c=this._size[1]),Wa(a,s),Wa(o,c);var h=l(a,this._ptr[o],this._ptr[o+1],this._index);return h<this._ptr[o+1]&&this._index[h]===a?p(r,m)?u(h,o,this._values,this._index,this._ptr):this._values[h]=r:p(r,m)||d(h,a,o,r,this._values,this._index,this._ptr),this};function l(e,t,n,r){if(n-t===0)return n;for(var i=t;i<n;i++)if(r[i]===e)return i;return t}function u(e,t,n,r,i){n.splice(e,1),r.splice(e,1);for(var a=t+1;a<i.length;a++)i[a]--}function d(e,t,n,r,i,a,o){i.splice(e,0,r),a.splice(e,0,t);for(var s=n+1;s<o.length;s++)o[s]++}i.prototype.resize=function(e,t,n){if(!gt(e))throw TypeError(`Array or Matrix expected`);var r=e.valueOf().map(e=>Array.isArray(e)&&e.length===1?e[0]:e);if(r.length!==2)throw Error(`Only two dimensions matrix are supported`);return r.forEach(function(e){if(!st(e)||!yn(e)||e<0)throw TypeError(`Invalid size, must contain positive integers (size: `+Aa(r)+`)`)}),f(n?this.clone():this,r[0],r[1],t)};function f(e,r,i,a){var o=a||0,s=n,c=0;pt(e._datatype)&&(s=t.find(n,[e._datatype,e._datatype])||n,c=t.convert(0,e._datatype),o=t.convert(o,e._datatype));var l=!s(o,c),u=e._size[0],d=e._size[1],f,p,m;if(i>d){for(p=d;p<i;p++)if(e._ptr[p]=e._values.length,l)for(f=0;f<u;f++)e._values.push(o),e._index.push(f);e._ptr[i]=e._values.length}else i<d&&(e._ptr.splice(i+1,d-i),e._values.splice(e._ptr[i],e._values.length),e._index.splice(e._ptr[i],e._index.length));if(d=i,r>u){if(l){var h=0;for(p=0;p<d;p++){e._ptr[p]=e._ptr[p]+h,m=e._ptr[p+1]+h;var g=0;for(f=u;f<r;f++,g++)e._values.splice(m+g,0,o),e._index.splice(m+g,0,f),h++}e._ptr[d]=e._values.length}}else if(r<u){var _=0;for(p=0;p<d;p++){e._ptr[p]=e._ptr[p]-_;var v=e._ptr[p],y=e._ptr[p+1]-_;for(m=v;m<y;m++)f=e._index[m],f>r-1&&(e._values.splice(m,1),e._index.splice(m,1),_++)}e._ptr[p]=e._values.length}return e._size[0]=r,e._size[1]=i,e}i.prototype.reshape=function(e,t){if(!mt(e))throw TypeError(`Array expected`);if(e.length!==2)throw Error(`Sparse matrices can only be reshaped in two dimensions`);e.forEach(function(t){if(!st(t)||!yn(t)||t<=-2||t===0)throw TypeError(`Invalid size, must contain positive integers or -1 (size: `+Aa(e)+`)`)});var n=this._size[0]*this._size[1];if(e=Ya(e,n),n!==e[0]*e[1])throw Error(`Reshaping sparse matrix will result in the wrong number of elements`);var r=t?this.clone():this;if(this._size[0]===e[0]&&this._size[1]===e[1])return r;for(var i=[],a=0;a<r._ptr.length;a++)for(var o=0;o<r._ptr[a+1]-r._ptr[a];o++)i.push(a);for(var s=r._values.slice(),c=r._index.slice(),u=0;u<r._index.length;u++){var f=c[u],p=i[u],m=f*r._size[1]+p;i[u]=m%e[1],c[u]=Math.floor(m/e[1])}r._values.length=0,r._index.length=0,r._ptr.length=e[1]+1,r._size=e.slice();for(var h=0;h<r._ptr.length;h++)r._ptr[h]=0;for(var g=0;g<s.length;g++){var _=c[g],v=i[g],y=s[g];d(l(_,r._ptr[v],r._ptr[v+1],r._index),_,v,y,r._values,r._index,r._ptr)}return r},i.prototype.clone=function(){return new i({values:this._values?Qt(this._values):void 0,index:Qt(this._index),ptr:Qt(this._ptr),size:Qt(this._size),datatype:this._datatype})},i.prototype.size=function(){return this._size.slice(0)},i.prototype.map=function(e,t){if(!this._values)throw Error(`Cannot invoke map on a Pattern only matrix`);var n=this,r=this._size[0],i=this._size[1],a=So(e,n,`map`);return p(this,0,r-1,0,i-1,function(e,t,r){return a.fn(e,[t,r],n)},t)};function p(e,r,a,o,s,c,l){var u=[],d=[],f=[],p=n,m=0;pt(e._datatype)&&(p=t.find(n,[e._datatype,e._datatype])||n,m=t.convert(0,e._datatype));for(var h=function(e,t,n){var r=c(e,t,n);p(r,m)||(u.push(r),d.push(t))},g=o;g<=s;g++){f.push(u.length);var _=e._ptr[g],v=e._ptr[g+1];if(l)for(var y=_;y<v;y++){var b=e._index[y];b>=r&&b<=a&&h(e._values[y],b-r,g-o)}else{for(var x={},S=_;S<v;S++){var C=e._index[S];x[C]=e._values[S]}for(var w=r;w<=a;w++)h(w in x?x[w]:0,w-r,g-o)}}return f.push(u.length),new i({values:u,index:d,ptr:f,size:[a-r+1,s-o+1]})}i.prototype.forEach=function(e,t){if(!this._values)throw Error(`Cannot invoke forEach on a Pattern only matrix`);for(var n=this,r=this._size[0],i=this._size[1],a=So(e,n,`forEach`),o=0;o<i;o++){var s=this._ptr[o],c=this._ptr[o+1];if(t)for(var l=s;l<c;l++){var u=this._index[l];a.fn(this._values[l],[u,o],n)}else{for(var d={},f=s;f<c;f++){var p=this._index[f];d[p]=this._values[f]}for(var m=0;m<r;m++){var h=m in d?d[m]:0;a.fn(h,[m,o],n)}}}},i.prototype[Symbol.iterator]=function*(){if(!this._values)throw Error(`Cannot iterate a Pattern only matrix`);for(var e=this._size[1],t=0;t<e;t++)for(var n=this._ptr[t],r=this._ptr[t+1],i=n;i<r;i++){var a=this._index[i];yield{value:this._values[i],index:[a,t]}}},i.prototype.toArray=function(){return m(this._values,this._index,this._ptr,this._size,!0)},i.prototype.valueOf=function(){return m(this._values,this._index,this._ptr,this._size,!1)};function m(e,t,n,r,i){var a=r[0],o=r[1],s=[],c,l;for(c=0;c<a;c++)for(s[c]=[],l=0;l<o;l++)s[c][l]=0;for(l=0;l<o;l++)for(var u=n[l],d=n[l+1],f=u;f<d;f++)c=t[f],s[c][l]=e?i?Qt(e[f]):e[f]:1;return s}return i.prototype.format=function(e){for(var t=this._size[0],n=this._size[1],r=this.density(),i=`Sparse Matrix [`+Aa(t,e)+` x `+Aa(n,e)+`] density: `+Aa(r,e)+`
|
|
5
5
|
`,a=0;a<n;a++)for(var o=this._ptr[a],s=this._ptr[a+1],c=o;c<s;c++){var l=this._index[c];i+=`
|
|
@@ -77,7 +77,7 @@ In case of a (multi dimensional) array or matrix, the prob order quantile of all
|
|
|
77
77
|
`,ZI=e=>[0,512,1024,2048].some(t=>NI(e,XI,t)),QI={id:`hdf5`,label:`HDF5`,extensions:[`.h5`,`.hdf5`,`.hdf`,`.he5`,`.nc`],sniff:ZI}})),eL,tL=c((()=>{zI(),eL={id:`comtrade`,label:`COMTRADE (IEEE C37.111)`,extensions:[`.cfg`,`.cff`],companions:[{ext:`.dat`}],sniff:e=>{let t=LI(e.subarray(0,512));if(/^---\s*file type:\s*CFG/i.test(t))return!0;let n=t.split(/\r?\n/);return n.length>2&&/^\s*\d+\s*,\s*\d+A\s*,\s*\d+D\s*$/i.test(n[1])}}}));VI(),UI(),GI(),qI(),YI(),$I(),tL();var nL=4096,rL=[`.dat`,`.txt`,`.csv`,`.tsv`],iL=[BI,HI,WI,KI,JI,QI,eL],aL=e=>{let t=e.lastIndexOf(`.`);return t<=0?``:e.slice(t).toLowerCase()},oL=e=>{let t=e.lastIndexOf(`.`);return(t<=0?e:e.slice(0,t)).toLowerCase()};async function sL(e){let t=new Uint8Array(await e.slice(0,nL).arrayBuffer()),n=aL(e.name),r=iL.filter(e=>e.extensions.includes(n));for(let n of[...r,...iL.filter(e=>!r.includes(e))])if(n.sniff(t,e.name))return n;return null}async function cL(e){return new Uint8Array(await e.slice(0,nL).arrayBuffer()).includes(0)}async function lL(e){let t=await Promise.all(e.map(sL)),n=[],r=new Set;e.forEach((e,i)=>{let a=t[i];a&&(n.push({main:e,companions:[],format:a}),r.add(e))});for(let i of[...n])for(let n of i.format.companions??[]){let a=e.filter((e,r)=>!t[r]&&aL(e.name)===n.ext),o=a.find(e=>oL(e.name)===oL(i.main.name))??(n.anyName&&a.length===1?a[0]:void 0);o&&(i.companions.push(o),r.add(o))}let i=new Set(iL.flatMap(e=>(e.companions??[]).map(e=>e.ext))),a=[];for(let t of e){if(r.has(t))continue;let e=aL(t.name);e===`.dat`&&await cL(t)?a.push({file:t.name,error:Error(`This COMTRADE .dat needs its .cfg file — drop both together.`)}):rL.includes(e)?n.push({main:t,companions:[],format:null}):i.has(e)?a.push({file:t.name,error:Error(`${t.name} is read together with its main file (same name). Drop both files together.`)}):a.push({file:t.name,error:Error(`${t.name}: Kymoscope cannot read this file type.`)})}return n.sort((t,n)=>e.indexOf(t.main)-e.indexOf(n.main)),{items:n,errors:a}}var uL=[...new Set([...rL,...iL.flatMap(e=>[...e.extensions,...(e.companions??[]).map(e=>e.ext)])])];function dL(e){let t=0;for(let n=0;n<e.length;n++)e[n]!==e[n]&&t++;if(t===0)return oj(e);let n=new Uint8Array(e.length+7>>3);for(let t=0;t<e.length;t++)e[t]===e[t]&&(n[t>>3]|=1<<(t&7));return oj(PA({type:new zD,data:e,nullBitmap:n,length:e.length,nullCount:t}))}var fL=122880,pL=class{#e;#t;#n;#r=!1;#i=[];#a=0;#o;rows=0;constructor(e,t,n,r=fL){this.#e=e,this.#t=t,this.#n=new xj(n.map(e=>new Sj(e.name,e.text?new HD:new zD,!0))),this.#o=r}async append(e){let t=e.length;if(t===0)return;let n=this.#n.fields.map((n,r)=>{let i=e.columns[r];return(i instanceof Float64Array?dL(i.subarray(0,t)):gN(i.slice(0,t),new HD)).data[0]});this.#i.push(new TN(this.#n,PA({type:new $D(this.#n.fields),length:t,nullCount:0,children:n}))),this.#a+=t,this.rows+=t,this.#a>=this.#o&&await this.flush()}async flush(){if(this.#a===0)return;let e=new CN(this.#n,this.#i);this.#i=[],this.#a=0,await this.#e.insertArrowTable(e,{name:this.#t,create:!this.#r}),this.#r=!0}};function mL(e){let t=e.notes;for(let n of e.groups){n.name=wL(String(n.name),yL);for(let e of n.channels)e.name=wL(String(e.name),yL),e.unit=wL(String(e.unit??``),bL);Number.isInteger(n.samples)&&n.samples>=-1||(n.samples=-1),n.rateHz===null||Number.isFinite(n.rateHz)&&n.rateHz>0||(n.rateHz=null),n.time.kind===`rate`&&!(Number.isFinite(n.time.rate)&&n.time.rate>0&&Number.isFinite(n.time.start))&&(t.push(`${n.name}: its sample rate in the file is not usable; samples are numbered instead.`),n.time={kind:`index`},n.rateHz=null)}t.length>SL&&t.splice(SL,t.length-SL,`${t.length-SL} more notes.`),e.notes=t.map(e=>wL(String(e),xL));let n={};for(let[t,r]of Object.entries(e.meta).slice(0,CL))n[wL(t,yL)]=wL(String(r),xL);return e.meta=n,e.events=e.events.filter(e=>Number.isFinite(e.time)).map(e=>({time:e.time,text:wL(String(e.text),xL)})),e}function hL(e){return e instanceof Error&&(e.constructor===Error||e.name===`KymoscopeError`||e.name===`AbortError`)?e:Error(gL)}var gL,_L,vL,yL,bL,xL,SL,CL,wL,TL=c((()=>{gL=`This file couldn't be read (it may be damaged).`,_L=1032,vL=e=>e*_L+1024,yL=256,bL=64,xL=1e3,SL=100,CL=200,wL=(e,t)=>e.length>t?`${e.slice(0,t-1)}…`:e}));TL();var EL=`This file's groups do not interleave in time: reading them together would hold too much in memory. Choose fewer groups, or split them.`,DL=e=>e.length*(1+e.columns.length);function OL(e){let t=e[Symbol.asyncIterator]();return{pull:async()=>{let e=await t.next();return e.done?null:e.value}}}function kL(e,t){let n=Array.from({length:t.size},()=>[]),r=!1,i=0,a=async a=>{for(;;){if(n[a].length){let e=n[a].shift();return i-=DL(e),e}if(r)return null;let o=await e.next();if(o.done){r=!0;continue}let s=t.get(o.value.group);if(s!==void 0&&(n[s].push(o.value),(i+=DL(o.value))>128e6))throw Error(EL)}};return n.map((e,t)=>({pull:()=>a(t)}))}function AL(e,t){if(e.time)return e.time;let n=new Float64Array(e.length);if(t.time.kind===`rate`){let{rate:r,start:i}=t.time;for(let t=0;t<e.length;t++)n[t]=i+(e.start+t)/r}else for(let t=0;t<e.length;t++)n[t]=e.start+t;return n}var jL=new Int32Array,ML={t:new Float64Array,cols:[],from:0};function NL(e,t,n,r){let i=n,a=r;for(;i<a;){let n=i+a>>>1;e[n]<=t?i=n+1:a=n}return i}var PL=class{group;channels;feed;pending=[];done=!1;last;scratch=[];#e=-1/0;constructor(e,t,n){this.group=e,this.channels=t,this.feed=n,this.last=t.map(e=>e.text?null:NaN)}rows(){let e=0;for(let t of this.pending)e+=t.t.length-t.from;return e}lastTime(){let e=this.pending[this.pending.length-1];return e&&e.t.length>e.from?e.t[e.t.length-1]:-1/0}async fill(){let e=await this.feed.pull();if(!e){this.done=!0;return}if(e.length===0)return;let t=FL(AL(e,this.group),this.#e);if(t.length&&(this.#e=t[t.length-1]),this.pending.push({t,cols:e.columns,from:0}),this.rows()*(1+this.channels.length)>128e6)throw Error(EL)}};function FL(e,t){let n=t,r=0;for(;r<e.length;r++){let t=e[r];if(!(t>=n&&t>-1/0&&t<1/0))break;n=t}if(r===e.length)return e;for(n===-1/0&&(n=0);r<e.length;r++){let t=e[r];t>=n&&t<1/0?n=t:e[r]=n}return e}function IL(e,t){let n=e.length,r=e.map(e=>e.t),i=Int32Array.from(e,e=>e.from),a=Int32Array.from(e,e=>NL(e.t,t,e.from,e.t.length));if(n===1)return r[0].subarray(i[0],a[0]);let o=0;for(let e=0;e<n;e++)o+=a[e]-i[e];let s=new Float64Array(o),c=0;for(;;){let e=1/0;for(let t=0;t<n;t++)i[t]<a[t]&&r[t][i[t]]<e&&(e=r[t][i[t]]);if(e===1/0)break;s[c++]=e;for(let t=0;t<n;t++){let n=r[t],o=a[t],s=i[t];for(;s<o&&n[s]===e;)s++;i[t]=s}}return s.subarray(0,c)}function LL(e,t,n,r,i,a){if(i-r>8)e.set(t.subarray(n+r,n+i),a);else for(let o=r;o<i;o++)e[a+o-r]=t[n+o]}function RL(e,t,n,r,i,a){let o=0;for(let s=0;s<n.length;s++){let c=n[s],l=c.length;if(l===0)continue;let u=i[s].from,d=i[s].cols[a];e.fill(t,o,c[0]);let f=r[s],p=0;for(let t=0;t<f.length;t++){let n=f[t];LL(e,d,u,p,n,c[p]);let r=c[n],i=c[n+1],a=d[u+n];if(i-r>16)e.fill(a,r,i);else for(let t=r;t<i;t++)e[t]=a;p=n+1}LL(e,d,u,p,l-1,c[p]),o=c[l-1],t=d[u+l-1]}e.fill(t,o,e.length)}function zL(e,t,n,r,i){let a=0;for(let o=0;o<n.length;o++){let s=n[o],c=s.length;if(c===0)continue;let l=r[o].from,u=r[o].cols[i];e.fill(t,a,s[0]);for(let t=0;t<c-1;t++)e.fill(u[l+t],s[t],s[t+1]);a=s[c-1],t=u[l+c-1]}e.fill(t,a,e.length)}function BL(e,t,n,r,i){let a=n.length,o=null,s=0;for(let c=0;c<i.length;c++){let l=e[t+c],u=r;if(n[r]<l){let e=r,t=1;for(;e+t<a&&n[e+t]<l;)e+=t,t*=2;let i=Math.min(e+t,a-1);for(;i-e>1;){let t=e+i>>>1;n[t]<l?e=t:i=t}r=i}i[c]=r,c>0&&r!==u+1&&((o??=new Int32Array(i.length-1))[s++]=c-1)}return o?o.subarray(0,s):jL}function VL(e,t,n,r,i){let a=t.length;if(r){let t=e.pending[0],n=t.from+a,r=t.cols.map(e=>e instanceof Float64Array?e.subarray(t.from,n):e.slice(t.from,n));if(a>0)for(let i=0;i<r.length;i++)e.last[i]=t.cols[i][n-1];return e.pending=n<t.t.length?[{...t,from:n}]:[],r}let o=e.pending,s=[],c=[];if(a>0){let e=t[a-1],n=0;for(let r of o){let i=r.t,a=NL(i,e,r.from,i.length),o=new Int32Array(a-r.from);if(c.push(BL(i,r.from,t,n,o)),o.length&&(n=o[o.length-1]),s.push(o),a<i.length)break}}let l=e.channels.map((r,l)=>{if(r.sparse&&n){let e=r.text?Array(a).fill(null):new Float64Array(a).fill(NaN);for(let n=0;n<s.length;n++){let r=s[n],{t:i,from:c}=o[n],u=o[n].cols[l];for(let n=0;n<r.length;n++){let o=r[n];o<a&&t[o]===i[c+n]&&(e[o]=u[c+n])}}return e}if(r.text){let t=Array(a);return zL(t,e.last[l],s,o,l),t}let u;return i?(e.scratch[l]?.length>=a||(e.scratch[l]=new Float64Array(a)),u=e.scratch[l].subarray(0,a)):u=new Float64Array(a),RL(u,e.last[l],s,c,o,l),u}),u=[];for(let t=0;t<o.length;t++){let n=o[t],r=t<s.length?s[t].length:0;if(r>0)for(let t=0;t<e.channels.length;t++)e.last[t]=n.cols[t][n.from+r-1];n.from+r<n.t.length&&u.push(r?{...n,from:n.from+r}:n)}return e.pending=u,l}async function HL(e,t,n,r,i,a=!1){let o=e.map((e,r)=>new PL(e,t[r],n[r])),s=-1;e.forEach((t,n)=>{!t.irregular&&(s<0||t.samples>e[s].samples)&&(s=n)});let c=e.map((e,t)=>t===s||!!e.irregular),l=o.filter((e,t)=>c[t]),u=l.length===1,d=0;for(;;){i?.throwIfAborted();for(let e of l)for(;!e.done&&e.rows()===0;)await e.fill();if(l.every(e=>e.rows()===0))break;let e=1/0;for(let t of l)t.done||(e=Math.min(e,t.lastTime()));for(let t=0;t<o.length;t++)if(!c[t])for(;!o[t].done&&o[t].lastTime()<=e;)await o[t].fill();let t=IL(l.map(e=>e.pending[0]??ML),e),n=[t];for(let e=0;e<o.length;e++)n.push(...VL(o[e],t,c[e],u&&c[e],a));d+=t.length,t.length&&await r({length:t.length,columns:n})}return d}var UL=class{#e;#t;#n;#r=0;constructor(e,t){let n=Math.max(1024,t);this.#e=e.map(e=>e.name),this.#t=e.map(()=>new Float64Array(n)),this.#n=e.map(()=>null)}append(e){let t=this.#r,n=t+e.length;if(n>this.#t[0].length){let e=Math.max(n,Math.ceil(this.#t[0].length*1.5));this.#t=this.#t.map(n=>{let r=new Float64Array(e);return r.set(n.subarray(0,t)),r})}e.columns.forEach((n,r)=>{let i=this.#t[r];if(n instanceof Float64Array){i.set(n.subarray(0,e.length),t);return}let a=this.#n[r];for(let o=0;o<e.length;o++){i[t+o]=NaN;let e=n[o];e!=null&&((a??=this.#n[r]=[])[t+o]=e)}}),this.#r=n}table(){let e=this.#r,t=this.#t.map(t=>t.length-e>t.length/100?t.slice(0,e):t.subarray(0,e));return{keys:this.#e,length:e,values:t,text:this.#n}}};function WL(e,t=[`Time`]){let n=new Set(t.map(e=>e.toLowerCase())),r=new Map;return e.map(e=>{let t=e.trim()||`Channel`,i=t.toLowerCase(),a=t,o=r.get(i)??2;if(n.has(i)){for(;n.has(`${i} (${o})`);)o++;a=`${t} (${o++})`}return r.set(i,o),n.add(a.toLowerCase()),a})}var GL=c((()=>{}));TL(),GL();async function KL(e,t,n){return mL(await e.plan(t,n))}var qL=(e,t,n)=>Math.max(0,Math.min(e,Math.max(1<<20,n),Math.floor(1e8/t)));function JL(e,t){let n=t.flatMap(t=>t.channels.map(n=>({ch:e.groups[t.group].channels[n],group:e.groups[t.group].name}))),r=new Map;for(let{ch:e}of n)r.set(e.name.toLowerCase(),(r.get(e.name.toLowerCase())??0)+1);let i=WL(n.map(({ch:e,group:n})=>t.length>1&&r.get(e.name.toLowerCase())>1?`${e.name} [${n}]`:e.name));return[{name:`Time`,unit:t.every(t=>e.groups[t.group].time.kind===`index`)?``:`s`,text:!1},...n.map(({ch:e},t)=>({name:i[t],unit:e.unit,text:!!e.text}))]}function YL(e,t){let n=t.map(t=>e.groups[t.group]);if(n.some(e=>e.samples<0))return-1;let r=0,i=0;for(let e of n)e.irregular?i+=e.samples:r=Math.max(r,e.samples);return r+i}function XL(e,t,n){let r=YL(e,t);return r<0?Math.ceil(n/4):r*(1+t.reduce((e,t)=>e+t.channels.length,0))}async function ZL(e,t,n,r,i,a,o={}){let s=JL(n,i),c=i.map(e=>n.groups[e.group]),l=i.map(e=>e.channels.map(t=>n.groups[e.group].channels[t])),u=[...n.events];async function*d(e){for await(let t of e)t.events&&u.push(...t.events),yield t}let f={files:t,plan:n,io:r,selection:i,signal:o.signal},p=e.streamGroup&&i.length>1&&!n.interleaved?i.map(t=>OL(d(e.streamGroup({...f,selection:[t]},t.group)))):kL(d(e.stream(f)),new Map(i.map((e,t)=>[e.group,t]))),m=YL(n,i),h=a===`memory`?new UL(s,qL(m,s.length,r.size)):null,g=0,_=await HL(c,l,p,async e=>{h?h.append(e):await o.chunk(e);let t=Date.now();o.progress&&t-g>100&&(g=t,o.progress(Math.min(.99,r.bytesRead/Math.max(1,r.size))))},o.signal,!!h);return o.progress?.(1),u.sort((e,t)=>e.time-t.time),{columns:s,rows:_,table:h?.table(),events:u}}var QL,$L,eR,tR,nR=c((()=>{QL=1<<20,$L=64,eR=16<<20,tR=class{size;bytesRead=0;#e;#t=new Map;constructor(e){this.#e=e,this.size=e.size}async read(e,t){let n=Math.min(this.size,e+t);if(n<=e)return new Uint8Array;if(n-e>QL)return this.slice(e,n-e);let r=Math.floor(e/QL),i=Math.floor((n-1)/QL),a=await this.#n(r);if(r===i)return a.subarray(e-r*QL,n-r*QL);let o=new Uint8Array(n-e),s=a.subarray(e-r*QL);return o.set(s),o.set((await this.#n(i)).subarray(0,n-i*QL),s.length),o}async slice(e,t){let n=Math.min(this.size,e+t);if(n<=e)return new Uint8Array;let r=new Uint8Array(await this.#e.slice(e,n).arrayBuffer());return this.bytesRead+=r.length,r}async*windows(e,t,n=eR){let r=Math.min(this.size,e+t);for(let t=e;t<r;t+=n)yield{offset:t,bytes:await this.slice(t,Math.min(n,r-t))}}async#n(e){let t=this.#t.get(e);if(t)return this.#t.delete(e),this.#t.set(e,t),t;let n=await this.slice(e*QL,QL);return this.#t.size>=$L&&this.#t.delete(this.#t.keys().next().value),this.#t.set(e,n),n}}}));nR();var rR=``+new URL(`assets/importer.worker-Drm9u2Rc.js`,__kymoscopeScriptUrl).href,iR=``+new URL(`assets/h5wasmModule-BCQWU2Gw.js`,__kymoscopeScriptUrl).href;function aR(e,t){return e.selection.find(e=>e.group===t)?.channels??[]}var oR=c((()=>{}));function sR(e){if(e.length>cR)return null;let t=e.match(/\d+\.?\d*(?:[eE][+-]?\d+)?|\.\d+(?:[eE][+-]?\d+)?|[A-Za-z_]\w*|\*\*|[-+*/^(),]|\S/g)??[],n=0,r=()=>t[n],i=()=>{throw Error(`formula`)},a=e=>{t[n++]!==e&&i()},o=()=>{let e=s();for(;r()===`+`||r()===`-`;){let r=t[n++],i=e,a=s();e=r===`+`?e=>i(e)+a(e):e=>i(e)-a(e)}return e},s=()=>{let e=c();for(;r()===`*`||r()===`/`;){let r=t[n++],i=e,a=c();e=r===`*`?e=>i(e)*a(e):e=>i(e)/a(e)}return e},c=()=>{if(r()===`-`){n++;let e=c();return t=>-e(t)}return r()===`+`?(n++,c()):l()},l=()=>{let e=u();if(r()===`^`||r()===`**`){n++;let t=c();return n=>e(n)**t(n)}return e},u=()=>{let e=t[n++];if(e===void 0&&i(),e===`(`){let e=o();return a(`)`),e}if(/^[\d.]/.test(e)){let t=Number(e);return Number.isFinite(t)||i(),()=>t}if(e===`X`||e===`x`||e===`X1`)return e=>e;if(Object.hasOwn(lR,e)){let t=lR[e];a(`(`);let i=[o()];for(;r()===`,`;)n++,i.push(o());return a(`)`),i.length===1?e=>t(i[0](e)):e=>t(...i.map(t=>t(e)))}return i()};try{let e=o();return n===t.length?e:null}catch{return null}}var cR,lR,uR=c((()=>{cR=4096,lR={sin:Math.sin,cos:Math.cos,tan:Math.tan,asin:Math.asin,acos:Math.acos,atan:Math.atan,sinh:Math.sinh,cosh:Math.cosh,tanh:Math.tanh,exp:Math.exp,ln:Math.log,log:Math.log,log10:Math.log10,sqrt:Math.sqrt,abs:Math.abs,pow:Math.pow,min:Math.min,max:Math.max}}));function dR(e,t){let{keys:n,vals:r}=e,i=n.length;if(i===0)return t;if(t<=n[0])return r[0];if(t>=n[i-1])return r[i-1];let a=0,o=i-1;for(;o-a>1;){let e=a+o>>1;n[e]<=t?a=e:o=e}return e.interp?r[a]+(r[o]-r[a])*(t-n[a])/(n[o]-n[a]):t-n[a]<=n[o]-t?r[a]:r[o]}function fR(e,t){let n=t.length;switch(e.k){case`lin`:{let{a:r,b:i}=e;if(r===1&&i===0)return;for(let e=0;e<n;e++)t[e]=r*t[e]+i;return}case`rat`:{let[r,i,a,o,s,c]=e.p;for(let e=0;e<n;e++){let n=t[e];t[e]=(r*n*n+i*n+a)/(o*n*n+s*n+c)}return}case`poly`:{let[r,i,a,o,s,c]=e.p;for(let e=0;e<n;e++){let n=t[e]-s-c;t[e]=(i-o*n)/(a*n-r)}return}case`alg`:{let r=e.f;for(let e=0;e<n;e++)t[e]=r(t[e]);return}case`tab`:for(let r=0;r<n;r++)t[r]=dR(e,t[r]);return;case`rtv`:for(let r=0;r<n;r++){let n=t[r],i=e.def;for(let t=0;t<e.lo.length;t++)if(n>=e.lo[t]&&n<=e.hi[t]){i=e.vals[t];break}t[r]=i}return;default:return}}function pR(e,t){let n=Float64Array.of(t);return fR(e,n),n[0]}function mR(e,t){let n=Array(t.length),r=e.ranges.every(e=>e.lo===e.hi)?new Map(e.ranges.map(e=>[e.lo,e.to])):null;for(let i=0;i<t.length;i++){let a=t[i];if(a!==a){n[i]=null;continue}let o=e.def;if(r){let e=r.get(a);e!==void 0&&(o=e)}else for(let t of e.ranges)if(a>=t.lo&&(e.int||t.lo===t.hi?a<=t.hi:a<t.hi)){o=t.to;break}n[i]=gR(o,a)}return n}var hR,gR,_R=c((()=>{hR={k:`id`},gR=(e,t)=>e===null||typeof e==`string`?e:String(pR(e,t))}));function vR(e,t){let n=(e,t)=>({type:e,bigEndian:t,encoding:`latin1`});switch(e){case 0:return n(`uint`,!t);case 1:return n(`int`,!t);case 2:case 3:return n(`float`,!t);case 7:return n(`string`,!1);case 8:return n(`bytes`,!1);case 9:return n(`uint`,!0);case 10:return n(`int`,!0);case 11:case 12:return n(`float`,!0);case 13:return n(`uint`,!1);case 14:return n(`int`,!1);case 15:case 16:return n(`float`,!1);default:return null}}async function yR(e,t,n){let r=PI(t).getUint16(24,!0)===0,i=async t=>{let n=PI(await e.read(t,4)).getUint16(2,r),i=await e.read(t,n);return{id:LI(i.subarray(0,2)),v:PI(i),b:i,size:n}},a=(e,t)=>e.getUint32(t,r),o=(e,t)=>e.getUint16(t,r),s=(e,t)=>e.getFloat64(t,r),c=async e=>e?MI((await i(e)).b.subarray(4),!0):``,l=[],u=new Set,d=e=>{if(u.has(e))throw Error(`This MDF file is damaged (its blocks link in a loop).`);u.add(e)},f=async(e,t)=>{if(!e)return{conv:hR,unit:``};let{v:n,b:r}=await i(e),l=MI(r.subarray(22,42),!0),u=o(n,42),d=o(n,44),f=e=>s(n,46+8*e);switch(u){case 0:return{conv:{k:`lin`,a:f(1),b:f(0)},unit:l};case 1:case 2:{let e=new Float64Array(d),t=new Float64Array(d);for(let n=0;n<d;n++)e[n]=f(2*n),t[n]=f(2*n+1);return{conv:{k:`tab`,keys:e,vals:t,interp:u===1},unit:l}}case 6:return{conv:{k:`poly`,p:[0,1,2,3,4,5].map(f)},unit:l};case 9:return{conv:{k:`rat`,p:[0,1,2,3,4,5].map(f)},unit:l};case 10:{let e=MI(r.subarray(46,302),!0),t=sR(e);return{conv:t?{k:`alg`,f:t}:{k:`unsupported`,what:`the formula "${e}"`},unit:l}}case 11:return{conv:{k:`text`,ranges:Array.from({length:d},(e,t)=>{let i=46+40*t,a=s(n,i);return{lo:a,hi:a,to:MI(r.subarray(i+8,i+40),!0)}}),def:null,int:t},unit:l};case 12:{let e=await Promise.all(Array.from({length:d},async(e,t)=>{let r=46+20*t;return{lo:s(n,r),hi:s(n,r+8),to:await c(a(n,r+16))}}));return{conv:{k:`text`,ranges:e.slice(1),def:e[0]?.to??null,int:t},unit:l}}case 65535:return{conv:hR,unit:l};default:return{conv:{k:`unsupported`,what:`MDF3 conversion type ${u}`},unit:l}}},p=await i(64),m=null;if(p.size>=172&&(a(p.v,164)||a(p.v,168))){let e=a(p.v,168)*4294967296+a(p.v,164);m=new Date(e/1e6).toISOString()}else{let e=LI(p.b.subarray(18,28)),t=LI(p.b.subarray(28,36));/^\d\d:\d\d:\d{4}$/.test(e)&&(m=`${e.slice(6)}-${e.slice(3,5)}-${e.slice(0,2)}T${t}`)}let h=[],g=0;for(let e=a(p.v,4),t=0;e;t++){d(e);let n=await i(e),s=o(n.v,22),u=[];for(let e=a(n.v,8);e;){d(e);let n=await i(e),p=[],m=null;for(let e=a(n.v,8);e;){d(e);let t=await i(e),n=MI(t.b.subarray(26,58),!0),s=(t.size>=222?await c(a(t.v,218)):``)||n,u=vR(o(t.v,190),r),h=o(t.v,186)+(t.size>=228?8*o(t.v,226):0);if(!u)l.push(`${s}: MDF3 data type ${o(t.v,190)} is not supported; skipped.`);else{let{conv:e,unit:n}=await f(a(t.v,8),u.type!==`float`),r={name:s,unit:n,kind:o(t.v,24)===1?`master`:`value`,...u,conv:e,sd:null,sdRecordId:null,byteOffset:h>>3,bitOffset:h&7,bitCount:o(t.v,188),invalBit:null,allInvalid:!1};r.kind===`master`&&!m?m=r:r.kind===`value`&&p.push(r)}e=a(t.v,4)}g++,u.push({name:await c(a(n.v,12))||`Group ${g}`,dg:t,recordId:o(n.v,16),recordIdSize:+(s>0),idTrailer:+(s===2),dataBytes:o(n.v,20),invalBytes:0,cycles:a(n.v,22),vlsdCg:!1,sorted:!0,master:m,channels:p,stream:[],busType:0,busEvent:!1}),e=a(n.v,4)}let p=u.reduce((e,t)=>e+t.cycles*(t.recordIdSize+t.dataBytes+t.idTrailer),0),m=[{offset:a(n.v,16),length:p,zip:null}];for(let e of u)e.stream=m,e.sorted=u.length===1,h.push(e);e=a(n.v,4)}return{version:`MDF ${n}`,startTime:m,groups:h,notes:l,meta:{}}}var bR=c((()=>{zI(),uR(),_R()}));function xR(e,t){if(e.seen.has(t))throw Error(NR);e.seen.add(t)}async function SR(e,t){let n=await e.read(t,24);if(n.length<24)throw Error(`This MF4 is damaged (bad block at byte ${t}).`);let r=PI(n),i=LI(n.subarray(0,4)),a=AI(r,8),o=AI(r,16);if(!i.startsWith(`##`)||a<24+8*o||a>1<<26)throw Error(`This MF4 is damaged (bad block at byte ${t}).`);let s=await e.read(t,a);if(s.length<a)throw Error(`This MF4 is damaged (the block at byte ${t} runs past the end of the file).`);let c=PI(s),l=[];for(let e=0;e<o;e++)l.push(AI(c,24+8*e));let u=s.subarray(24+8*o);return{id:i,links:l,data:PI(u),bytes:u}}function CR(e){let t=e.indexOf(`<TX>`),n=t<0?-1:e.indexOf(`</TX>`,t+4);return(n>=0?e.slice(t+4,n):e.replace(/<[^<>]*>/g,``)).replace(/&(lt|gt|amp|quot|apos);/g,(e,t)=>PR[t]).trim()}function wR(e,t){if(!t)return Promise.resolve(``);let n=e.texts.get(t);return n||(n=SR(e.io,t).then(e=>{let t=MI(e.bytes);return e.id===`##MD`?CR(t):t}),e.texts.set(t,n)),n}async function TR(e,t,n=0){if(!t)return[];let r=e.io,i=await r.read(t,24),a=LI(i.subarray(0,4)),o=i.length<24?0:AI(PI(i),8);switch(a){case`##DT`:case`##SD`:case`##RD`:return[{offset:t+24,length:o-24,zip:null}];case`##DZ`:{let e=PI(await r.read(t+24,24));if(e.byteLength<24)throw Error(`This MF4 is damaged (bad block at byte ${t}).`);let n=e.getUint8(2);if(n===2||n===3)throw Error(`This MF4 uses zstd compression, which isn't supported yet.`);if(n===4||n===5)throw Error(`This MF4 uses LZ4 compression, which isn't supported yet.`);if(n>5)throw Error(`This MF4 is damaged (unknown compression type ${n}).`);let i=e.getUint32(4,!0),a=AI(e,8),o=AI(e,16);if(a>vL(o)||n===1&&i===0)throw Error(`This MF4 is damaged (bad compressed block at byte ${t}).`);if(n===1&&a>268435456)throw Error(`This MF4 has a compressed block over 256 MB, which Kymoscope cannot read.`);return[{offset:t+48,length:o,zip:{type:n,param:i,orgLength:a}}]}case`##DL`:{if(n>1)throw Error(`This MF4 is damaged (unexpected ${a} block in its data).`);let i=[];for(let n=t;n;){xR(e,n);let t=await SR(r,n);for(let n of t.links.slice(1))i.push(...await TR(e,n,2));n=t.links[0]}return i}case`##HL`:if(n>0)throw Error(`This MF4 is damaged (unexpected ${a} block in its data).`);return xR(e,t),TR(e,(await SR(r,t)).links[0],1);case`##DV`:case`##DI`:throw Error(`This MF4 uses column-oriented storage (MDF 4.2 DV/DI blocks), which Kymoscope cannot read yet.`);default:throw Error(`This MF4 is damaged (unexpected ${a} block in its data).`)}}async function ER(e,t,n){return t?LI(await e.io.read(t,4))===`##CC`?DR(e,t,n+1):wR(e,t):null}async function DR(e,t,n=0){if(!t||n>4||e.busy.has(t))return hR;let r=e.convs.get(t);if(r)return r;e.busy.add(t);try{let r=await OR(e,t,n);return e.convs.set(t,r),r}finally{e.busy.delete(t)}}async function OR(e,t,n){let r=await SR(e.io,t),i=r.data,a=i.getUint8(0),o=i.getUint16(4,!0),s=i.getUint16(6,!0),c=new Float64Array(s);for(let e=0;e<s;e++)c[e]=i.getFloat64(24+8*e,!0);let l=r.links.slice(4,4+o),u=()=>Promise.all(l.map(t=>ER(e,t,n)));switch(a){case 0:return hR;case 1:return{k:`lin`,b:c[0],a:c[1]};case 2:return{k:`rat`,p:[...c]};case 3:{let t=await wR(e,l[0]),n=sR(t);return n?{k:`alg`,f:n}:{k:`unsupported`,what:`the formula "${t}"`}}case 4:case 5:{let e=s>>1,t=new Float64Array(e),n=new Float64Array(e);for(let r=0;r<e;r++)t[r]=c[2*r],n[r]=c[2*r+1];return{k:`tab`,keys:t,vals:n,interp:a===4}}case 6:{let e=Math.max(0,Math.floor((s-1)/3)),t=new Float64Array(e),n=new Float64Array(e),r=new Float64Array(e);for(let i=0;i<e;i++)t[i]=c[3*i],n[i]=c[3*i+1],r[i]=c[3*i+2];return{k:`rtv`,lo:t,hi:n,vals:r,def:c[s-1]}}case 7:{let e=await u();return{k:`text`,ranges:[...c].map((t,n)=>({lo:t,hi:t,to:e[n]??null})),def:e[s]??null,int:!0}}case 8:{let e=await u(),t=s>>1;return{k:`text`,ranges:Array.from({length:t},(t,n)=>({lo:c[2*n],hi:c[2*n+1],to:e[n]??null})),def:e[t]??null,int:!0}}default:return{k:`unsupported`,what:`conversion type ${a}`}}}async function kR(e,t){let{io:n,notes:r}=e,i=t.data,a=i.getUint8(0),o=i.getUint8(1),s=i.getUint8(2),c=await wR(e,t.links[2]),l=FR[s];if(!l)return r.push(`${c}: data type ${s} is not supported; the channel was skipped.`),null;let u;if(a===2||a===3)if(o===1)u=a===2?`master`:`vmaster`;else{if(r.push(`The master channel ${c} is not time (sync type ${o}): samples are numbered instead.`),a===3)return null;u=`value`}else if(a===1)u=`vlsd`;else if(a===0||a===4)u=`value`;else return r.push(`${c}: channel type ${a} is not supported; skipped.`),null;let d=await DR(e,t.links[4]),f=d.k===`text`?{...d,int:l.type!==`float`}:d,p=await wR(e,t.links[6]);!p&&t.links[4]&&(p=await wR(e,(await SR(n,t.links[4])).links[1]));let m=null,h=null;u===`vlsd`&&t.links[5]&&(LI(await n.read(t.links[5],4))===`##CG`?h=AI((await SR(n,t.links[5])).data,0):m=await TR(e,t.links[5]));let g=i.getUint32(12,!0);return{name:c,unit:p,kind:u,...l,conv:f,sd:m,sdRecordId:h,byteOffset:i.getUint32(4,!0),bitOffset:i.getUint8(3),bitCount:i.getUint32(8,!0),invalBit:g&2?i.getUint32(16,!0):null,allInvalid:(g&1)!=0}}async function AR(e,t,n,r=0){let{io:i,notes:a}=e;for(let o=t;o;){xR(e,o);let t=await SR(i,o),s=t.links[1];s&&r<4&&(LI(await i.read(s,4))===`##CN`?await AR(e,s,n,r+1):a.push(`${await wR(e,t.links[2])}: array channels (CA) are not supported yet; skipped.`));let c=await kR(e,t);c&&n.push(c),o=t.links[0]}}async function jR(e,t,n,r){let i=t.data,a=i.getUint16(16,!0),o=0;t.links[3]&&(o=(await SR(e.io,t.links[3])).data.getUint8(1));let s={name:await wR(e,t.links[2]),dg:n,recordId:AI(i,0),recordIdSize:r,idTrailer:0,dataBytes:i.getUint32(24,!0),invalBytes:i.getUint32(28,!0),cycles:AI(i,8),vlsdCg:(a&1)!=0,sorted:!0,master:null,channels:[],stream:[],busType:o,busEvent:(a&2)!=0};if(s.vlsdCg)return s;let c=[];await AR(e,t.links[1],c);for(let e of c)e.kind===`master`||e.kind===`vmaster`?s.master||=e:s.channels.push(e);return s}async function MR(e,t){let n=await SR(e,64);if(n.id!==`##HD`)throw Error(`This MF4 is damaged (no header block).`);let r=AI(n.data,0),i=(n.data.getUint8(12)&1)!=0,a=new Date(r/1e6).toISOString(),o=r>0?i?a.slice(0,-1):a:null,s={io:e,notes:[],seen:new Set,texts:new Map,convs:new Map,busy:new Set},c=[],l=0;for(let t=n.links[0],r=0;t;r++){xR(s,t);let n=await SR(e,t),i=n.data.getUint8(0),a=[];for(let t=n.links[1];t;){xR(s,t);let n=await SR(e,t),o=await jR(s,n,r,i);o.vlsdCg||(l++,o.name||=`Group ${l}`),a.push(o),t=n.links[0]}let o=await TR(s,n.links[2]),u=a.length===1;for(let e of a)e.stream=o,e.sorted=u,c.push(e);t=n.links[0]}return{version:`MF4 ${t}`,startTime:o,groups:c,notes:s.notes,meta:{}}}var NR,PR,FR,IR=c((()=>{zI(),uR(),TL(),_R(),NR=`This MF4 is damaged (its blocks link in a loop).`,PR={lt:`<`,gt:`>`,amp:`&`,quot:`"`,apos:`'`},FR={0:{type:`uint`,bigEndian:!1,encoding:`latin1`},1:{type:`uint`,bigEndian:!0,encoding:`latin1`},2:{type:`int`,bigEndian:!1,encoding:`latin1`},3:{type:`int`,bigEndian:!0,encoding:`latin1`},4:{type:`float`,bigEndian:!1,encoding:`latin1`},5:{type:`float`,bigEndian:!0,encoding:`latin1`},6:{type:`string`,bigEndian:!1,encoding:`latin1`},7:{type:`string`,bigEndian:!1,encoding:`utf-8`},8:{type:`string`,bigEndian:!1,encoding:`utf-16le`},9:{type:`string`,bigEndian:!0,encoding:`utf-16be`},10:{type:`bytes`,bigEndian:!1,encoding:`latin1`}}}));function LR(e){let t=e&32768?-1:1,n=e>>10&31,r=e&1023;return n===0?t*2**-14*(r/1024):n===31?r?NaN:t*(1/0):t*2**(n-15)*(1+r/1024)}function RR(e,t,n,r,i,a,o=0){let s=PI(t),c=!e.bigEndian,l=i+e.byteOffset,u=e.bitCount;if(e.bitOffset===0)if(e.type===`float`){if(u===64){for(let e=0;e<n;e++,l+=r)a[o+e]=s.getFloat64(l,c);return}if(u===32){for(let e=0;e<n;e++,l+=r)a[o+e]=s.getFloat32(l,c);return}if(u===16){for(let e=0;e<n;e++,l+=r)a[o+e]=LR(s.getUint16(l,c));return}}else if(e.type===`int`){if(u===8){for(let e=0;e<n;e++,l+=r)a[o+e]=s.getInt8(l);return}if(u===16){for(let e=0;e<n;e++,l+=r)a[o+e]=s.getInt16(l,c);return}if(u===32){for(let e=0;e<n;e++,l+=r)a[o+e]=s.getInt32(l,c);return}if(u===64){for(let e=0;e<n;e++,l+=r)a[o+e]=s.getInt32(l+(c?4:0),c)*4294967296+s.getUint32(l+(c?0:4),c);return}}else{if(u===8){for(let e=0;e<n;e++,l+=r)a[o+e]=t[l];return}if(u===16){for(let e=0;e<n;e++,l+=r)a[o+e]=s.getUint16(l,c);return}if(u===32){for(let e=0;e<n;e++,l+=r)a[o+e]=s.getUint32(l,c);return}if(u===64){for(let e=0;e<n;e++,l+=r)a[o+e]=s.getUint32(l+(c?4:0),c)*4294967296+s.getUint32(l+(c?0:4),c);return}}let d=e.bitOffset+u+7>>3,f=2**e.bitOffset,p=2**u,m=p/2,h=e.type===`int`;for(let e=0;e<n;e++,l+=r){let n=0;if(c)for(let e=d-1;e>=0;e--)n=n*256+t[l+e];else for(let e=0;e<d;e++)n=n*256+t[l+e];n=Math.floor(n/f)%p,a[o+e]=h&&n>=m?n-p:n}}function zR(e){let t=e.indexOf(`\0`);return t<0?e:e.slice(0,t)}function BR(e,t,n,r,i){let a=UR(e.encoding),o=e.bitCount>>3,s=Array(n);for(let c=0,l=i+e.byteOffset;c<n;c++,l+=r)s[c]=zR(a.decode(t.subarray(l,l+o)));return s}function VR(e,t,n,r,i,a){let o=a instanceof Float64Array?NaN:null;if(e.allInvalid){for(let e=0;e<n;e++)a[e]=o;return}if(e.invalBit===null)return;let s=1<<(e.invalBit&7);for(let c=0,l=i+(e.invalBit>>3);c<n;c++,l+=r)t[l]&s&&(a[c]=o)}var HR,UR,WR=c((()=>{zI(),HR=new Map,UR=e=>{let t=HR.get(e);return t||HR.set(e,t=new TextDecoder(e)),t}}));function GR(e,t){return e.kind===`vmaster`?!0:(e.kind===`vlsd`||e.type===`uint`||e.type===`int`||e.type===`float`?!(e.bitCount>=1&&e.bitCount<=64):!(e.bitCount>=8))?!1:ZR(e)<=t.dataBytes}function KR(e,t){let n=e.notes;for(let r of e.groups){if(![0,1,2,4,8].includes(r.recordIdSize))throw Error(`This MDF file is damaged (bad record id size).`);if(r.vlsdCg)continue;let e=JR(r);if(e>YR||e===0){r.cycles>0&&n.push(`${r.name||`A group`}: its records are ${e===0?`empty`:`too large`} (damaged); skipped.`),r.cycles=0;continue}r.cycles=Math.min(r.cycles,Math.floor(XR(r.stream,t)/e));let i=r.channels.filter(e=>!GR(e,r));for(let e of i)n.push(`${e.name}: its bits lie outside its record (damaged); skipped.`);i.length&&(r.channels=r.channels.filter(e=>!i.includes(e))),r.master&&!GR(r.master,r)&&(n.push(`${r.master.name}: the time channel lies outside its record (damaged): samples are numbered instead.`),r.master=null);for(let e of r.master?[...r.channels,r.master]:r.channels)e.invalBit!==null&&e.invalBit>=8*r.invalBytes&&(e.invalBit=null)}}function qR(e,t){let n=0;for(let r of e.master?[...t,e.master]:t){if(r.invalBit!==null)return 1/0;r.kind!==`vmaster`&&(n=Math.max(n,r.byteOffset+(r.bitOffset+r.bitCount+7>>3)))}return e.recordIdSize+n}var JR,YR,XR,ZR,QR=c((()=>{JR=e=>e.recordIdSize+e.dataBytes+e.invalBytes+e.idTrailer,YR=64<<20,XR=(e,t)=>e.reduce((e,n)=>e+(n.zip?n.zip.orgLength:Math.max(0,Math.min(n.length,t-n.offset))),0),ZR=e=>e.byteOffset+Math.ceil((e.bitOffset+e.bitCount)/8)})),$R,ez,tz,nz,rz,iz,az,oz,sz,cz,lz,uz,dz,fz,pz,mz,hz,gz,_z,vz,yz,bz,xz,Sz,Cz,wz,Tz,Ez,Dz,Oz,kz,Az,jz,Mz=c((()=>{for($R=Uint8Array,ez=Uint16Array,tz=Int32Array,nz=new $R([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),rz=new $R([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),iz=new $R([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),az=function(e,t){for(var n=new ez(31),r=0;r<31;++r)n[r]=t+=1<<e[r-1];for(var i=new tz(n[30]),r=1;r<30;++r)for(var a=n[r];a<n[r+1];++a)i[a]=a-n[r]<<5|r;return{b:n,r:i}},oz=az(nz,2),sz=oz.b,cz=oz.r,sz[28]=258,cz[258]=28,lz=az(rz,0),uz=lz.b,lz.r,dz=new ez(32768),fz=0;fz<32768;++fz)pz=(fz&43690)>>1|(fz&21845)<<1,pz=(pz&52428)>>2|(pz&13107)<<2,pz=(pz&61680)>>4|(pz&3855)<<4,dz[fz]=((pz&65280)>>8|(pz&255)<<8)>>1;for(mz=(function(e,t,n){for(var r=e.length,i=0,a=new ez(t);i<r;++i)e[i]&&++a[e[i]-1];var o=new ez(t);for(i=1;i<t;++i)o[i]=o[i-1]+a[i-1]<<1;var s;if(n){s=new ez(1<<t);var c=15-t;for(i=0;i<r;++i)if(e[i])for(var l=i<<4|e[i],u=t-e[i],d=o[e[i]-1]++<<u,f=d|(1<<u)-1;d<=f;++d)s[dz[d]>>c]=l}else for(s=new ez(r),i=0;i<r;++i)e[i]&&(s[i]=dz[o[e[i]-1]++]>>15-e[i]);return s}),hz=new $R(288),fz=0;fz<144;++fz)hz[fz]=8;for(fz=144;fz<256;++fz)hz[fz]=9;for(fz=256;fz<280;++fz)hz[fz]=7;for(fz=280;fz<288;++fz)hz[fz]=8;for(gz=new $R(32),fz=0;fz<32;++fz)gz[fz]=5;_z=mz(hz,9,1),vz=mz(gz,5,1),yz=function(e){for(var t=e[0],n=1;n<e.length;++n)e[n]>t&&(t=e[n]);return t},bz=function(e,t,n){var r=t/8|0;return(e[r]|e[r+1]<<8)>>(t&7)&n},xz=function(e,t){var n=t/8|0;return(e[n]|e[n+1]<<8|e[n+2]<<16)>>(t&7)},Sz=function(e){return(e+7)/8|0},Cz=function(e,t,n){return(t==null||t<0)&&(t=0),(n==null||n>e.length)&&(n=e.length),new $R(e.subarray(t,n))},wz=[`unexpected EOF`,`invalid block type`,`invalid length/literal`,`invalid distance`,`stream finished`,`no stream handler`,,`no callback`,`invalid UTF-8 data`,`extra field too long`,`date not in range 1980-2099`,`filename too long`,`stream finishing`,`invalid zip data`],Tz=function(e,t,n){var r=Error(t||wz[e]);if(r.code=e,Error.captureStackTrace&&Error.captureStackTrace(r,Tz),!n)throw r;return r},Ez=function(e,t,n,r){var i=e.length,a=r?r.length:0;if(!i||t.f&&!t.l)return n||new $R(0);var o=!n,s=o||t.i!=2,c=t.i;o&&(n=new $R(i*3));var l=function(e){var t=n.length;if(e>t){var r=new $R(Math.max(t*2,e));r.set(n),n=r}},u=t.f||0,d=t.p||0,f=t.b||0,p=t.l,m=t.d,h=t.m,g=t.n,_=i*8;do{if(!p){u=bz(e,d,1);var v=bz(e,d+1,3);if(d+=3,!v){var y=Sz(d)+4,b=e[y-4]|e[y-3]<<8,x=y+b;if(x>i){c&&Tz(0);break}s&&l(f+b),n.set(e.subarray(y,x),f),t.b=f+=b,t.p=d=x*8,t.f=u;continue}else if(v==1)p=_z,m=vz,h=9,g=5;else if(v==2){var S=bz(e,d,31)+257,C=bz(e,d+10,15)+4,w=S+bz(e,d+5,31)+1;d+=14;for(var T=new $R(w),E=new $R(19),D=0;D<C;++D)E[iz[D]]=bz(e,d+D*3,7);d+=C*3;for(var O=yz(E),k=(1<<O)-1,A=mz(E,O,1),D=0;D<w;){var j=A[bz(e,d,k)];d+=j&15;var y=j>>4;if(y<16)T[D++]=y;else{var M=0,N=0;for(y==16?(N=3+bz(e,d,3),d+=2,M=T[D-1]):y==17?(N=3+bz(e,d,7),d+=3):y==18&&(N=11+bz(e,d,127),d+=7);N--;)T[D++]=M}}var P=T.subarray(0,S),F=T.subarray(S);h=yz(P),g=yz(F),p=mz(P,h,1),m=mz(F,g,1)}else Tz(1);if(d>_){c&&Tz(0);break}}s&&l(f+131072);for(var I=(1<<h)-1,L=(1<<g)-1,R=d;;R=d){var M=p[xz(e,d)&I],z=M>>4;if(d+=M&15,d>_){c&&Tz(0);break}if(M||Tz(2),z<256)n[f++]=z;else if(z==256){R=d,p=null;break}else{var B=z-254;if(z>264){var D=z-257,V=nz[D];B=bz(e,d,(1<<V)-1)+sz[D],d+=V}var H=m[xz(e,d)&L],U=H>>4;H||Tz(3),d+=H&15;var F=uz[U];if(U>3){var V=rz[U];F+=xz(e,d)&(1<<V)-1,d+=V}if(d>_){c&&Tz(0);break}s&&l(f+131072);var W=f+B;if(f<F){var ee=a-F,te=Math.min(F,W);for(ee+f<0&&Tz(3);f<te;++f)n[f]=r[ee+f]}for(;f<W;++f)n[f]=n[f-F]}}t.l=p,t.p=R,t.b=f,t.f=u,p&&(u=1,t.m=h,t.d=m,t.n=g)}while(!u);return f!=n.length&&o?Cz(n,0,f):n.subarray(0,f)},Dz=new $R(0),Oz=function(e,t){return((e[0]&15)!=8||e[0]>>4>7||(e[0]<<8|e[1])%31)&&Tz(6,`invalid zlib data`),(e[1]>>5&1)==+!t&&Tz(6,`invalid zlib data: `+(e[1]&32?`need`:`unexpected`)+` dictionary`),(e[1]>>3&4)+2},kz=function(){function e(e,t){typeof e==`function`&&(t=e,e={}),this.ondata=t;var n=e&&e.dictionary&&e.dictionary.subarray(-32768);this.s={i:0,b:n?n.length:0},this.o=new $R(32768),this.p=new $R(0),n&&this.o.set(n)}return e.prototype.e=function(e){if(this.ondata||Tz(5),this.d&&Tz(4),!this.p.length)this.p=e;else if(e.length){var t=new $R(this.p.length+e.length);t.set(this.p),t.set(e,this.p.length),this.p=t}},e.prototype.c=function(e){this.s.i=+(this.d=e||!1);var t=this.s.b,n=Ez(this.p,this.s,this.o);this.ondata(Cz(n,t,this.s.b),this.d),this.o=Cz(n,this.s.b-32768),this.s.b=this.o.length,this.p=Cz(this.p,this.s.p/8|0),this.s.p&=7},e.prototype.push=function(e,t){this.e(e),this.c(t)},e}(),Az=function(){function e(e,t){kz.call(this,e,t),this.v=e&&e.dictionary?2:1}return e.prototype.push=function(e,t){if(kz.prototype.e.call(this,e),this.v){if(this.p.length<6&&!t)return;this.p=this.p.subarray(Oz(this.p,this.v-1)),this.v=0}t&&(this.p.length<4&&Tz(6,`invalid zlib data`),this.p=this.p.subarray(0,-4)),kz.prototype.c.call(this,t)},e}(),jz=typeof TextDecoder<`u`&&new TextDecoder;try{jz.decode(Dz,{stream:!0})}catch{}}));async function*Nz(e){for(let t=0;t<e.length;t+=Iz)yield e.subarray(t,t+Iz)}async function*Pz(e){if(typeof DecompressionStream!=`function`){let t=[],n=new Az(e=>{t.push(e)});for await(let r of e)for(n.push(r,!1);t.length;)yield t.shift();for(n.push(new Uint8Array,!0);t.length;)yield t.shift();return}let t=new DecompressionStream(`deflate`),n=t.writable.getWriter();(async()=>{for await(let t of e)await n.write(t);await n.close()})().catch(e=>n.abort(e).catch(()=>{}));let r=t.readable.getReader();try{for(;;){let{done:e,value:t}=await r.read().catch(e=>{throw e instanceof TypeError?Error(Lz):e});if(e)return;yield t}}finally{r.cancel().catch(()=>{})}}async function Fz(e,t=-1,n=1/0){let r=[],i=Math.min(t,n),a=t>=0?new Uint8Array(i):null,o=0;for await(let s of Pz(Nz(e))){if(a){if(o+s.length>t&&n>t)throw Error(`Compressed data is longer than its header says.`);a.set(o+s.length>i?s.subarray(0,i-o):s,o)}else r.push(s);if(o+=s.length,o>=n)break}if(a)return o>=i?a:a.subarray(0,o);let s=r.length===1?r[0]:new Uint8Array(o);return r.length>1&&r.reduce((e,t)=>(s.set(t,e),e+t.length),0),o>n?s.subarray(0,n):s}var Iz,Lz,Rz=c((()=>{Mz(),Iz=65536,Lz=`This file's compressed data is damaged.`}));function zz(e,t,n,r=t){let i=Math.floor(n/t),a=new Uint8Array(r<t?i*r:n),o=r%4==0&&Gz?new Uint32Array(a.buffer,0,i*r>>2):null,s=r>>2;for(let t=0;t<i;t+=512){let n=Math.min(i,t+512);if(o)for(let a=0;a<r;a+=4){let r=a*i,c=r+i,l=c+i,u=l+i;for(let i=t,d=t*s+(a>>2);i<n;i++,d+=s)o[d]=e[r+i]|e[c+i]<<8|e[l+i]<<16|e[u+i]<<24}else for(let o=0;o<r;o++){let s=o*i;for(let i=t,c=t*r+o;i<n;i++,c+=r)a[c]=e[s+i]}}let c=i*t;return r===t&&a.set(e.subarray(c,n),c),a}function Bz(e,t,n){if(!(n<t)||e.length===0)return t;let r=Math.min(t,n+3&-4);return r===t?t:e.every(e=>e.zip?.type===1&&e.zip.param===t&&e.zip.orgLength%t===0)?r:t}async function Vz(e,t,n=1/0,r=1/0){let i=await e.slice(t.offset,t.length),{type:a,param:o,orgLength:s}=t.zip;if(a===0)return Fz(i,s,r);let c=Math.min(n,o);return zz(await Fz(i,s,c<o?s/o*c:1/0),o,s,c)}async function*Hz(e,t,n,r=1/0){let i=e=>!!e?.zip&&!(e.zip.type===0&&(e.length>16777216||e.zip.orgLength>268435456)),a=null;for(let o=0;o<t.length;o++){let s=t[o];if(n?.throwIfAborted(),!s.zip)for await(let t of e.windows(s.offset,s.length))yield t.bytes;else if(i(s)){let n=a??Vz(e,s,r);a=i(t[o+1])?Vz(e,t[o+1],r):null,a?.catch(()=>{}),yield await n}else{let t=s.zip.orgLength;for await(let n of Pz((async function*(){for await(let t of e.windows(s.offset,s.length))yield t.bytes})()))if(yield n.length>t?n.subarray(0,t):n,(t-=n.length)<=0)break}}}async function*Uz(e,t,n,r){if(r<=0||t<=0)return;let i=Math.min(n,r),a=null,o=0,s=0;for await(let n of e){let e=0;for(;e<n.length&&s<r;){if(o===0){let a=Math.min(i,r-s,Math.floor((n.length-e)/t));if(a>0){yield{buf:n.subarray(e,e+a*t),n:a},s+=a,e+=a*t;continue}}a??=new Uint8Array(t*i);let c=Math.min(a.length,(r-s)*t),l=Math.min(n.length-e,c-o);if(a.set(n.subarray(e,e+l),o),o+=l,e+=l,o===c){let e=o/t;yield{buf:a,n:e},s+=e,o=0}}if(s>=r)return}a&&o>=t&&(yield{buf:a,n:Math.floor(o/t)})}async function Wz(e,t,n,r){let i=n*r,a=0;for(let n of t){let t=n.zip?n.zip.orgLength:n.length;if(i<a)return null;if(i+r<=a+t)return n.zip?null:e.read(n.offset+i-a,r);a+=t}return null}var Gz,Kz,qz,Jz=c((()=>{Rz(),IR(),Gz=new Uint8Array(Uint32Array.of(1).buffer)[0]===1,Kz=(e,t)=>(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0,qz=class{#e;#t;#n;#r;#i=new Uint8Array;#a=0;#o;#s=0;constructor(e,t,n){this.#e=e,this.#t=t,this.#n=n,this.#r=Hz(e,t,n),this.#o=t.reduce((e,t)=>e+(t.zip?t.zip.orgLength:t.length),0)}peek(e){let t=e-this.#a;if(t<0||t+4>this.#i.length)return null;let n=Kz(this.#i,t);return t+4+n>this.#i.length?null:this.#i.subarray(t+4,t+4+n)}async get(e){for(;;){let t=this.peek(e);if(t)return t;let n=e-this.#a;if(e+4>this.#o||n>=0&&n+4<=this.#i.length&&e+4+Kz(this.#i,n)>this.#o)throw Error(`This MF4 is damaged (string data ends early).`);e<this.#a&&(this.#r=Hz(this.#e,this.#t,this.#n),this.#i=new Uint8Array,this.#a=0);let r=await this.#r.next();if(r.done)throw Error(`This MF4 is damaged (string data ends early).`);if((this.#s+=r.value.length)>4*this.#o+16777216)throw Error(`This MF4 is damaged (its string offsets jump back and forth).`);let i=Math.max(0,Math.min(e-this.#a,this.#i.length)),a=this.#i.subarray(i),o=new Uint8Array(a.length+r.value.length);o.set(a),o.set(r.value,a.length),this.#a+=i,this.#i=o}}}}));function Yz(e,t,n,r,i=JR(e),a=new Float64Array(n)){let o=e.master;if(!o)return null;if(o.kind===`vmaster`)for(let e=0;e<n;e++)a[e]=r+e;else RR(o,t,n,i,e.recordIdSize,a);return fR(o.conv,a),a}function Xz(e,t,n){return n===1?e[t]:n===2?e[t]|e[t+1]<<8:n===4?(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0:((e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0)+4294967296*((e[t+4]|e[t+5]<<8|e[t+6]<<16|e[t+7]<<24)>>>0)}function Zz(e,t){let n=new Uint8Array(e.length+t.length);return n.set(e),n.set(t,e.length),n}async function*Qz(e,t,n,r,i,a=1/0){let o=t.groups[n[0]];if(o.sorted){let t=Bz(o.stream,JR(o),a),r=0;for await(let{buf:a,n:s}of Uz(Hz(e,o.stream,i,t),t,$z(t),o.cycles))yield{g:n[0],buf:a,n:s,start:r,size:t},r+=s;return}let s=t.groups.map((e,t)=>({g:e,k:t})).filter(({g:e})=>e.dg===o.dg),c=o.recordIdSize,l=new Map;for(let e of n){let n=t.groups[e],r=JR(n);l.set(n.recordId,{k:e,size:r,buf:new Uint8Array(r*Math.min($z(r),Math.max(1,n.cycles))),fill:0,start:0})}let u=new Map(s.map(({g:e})=>[e.recordId,e.vlsdCg?-1:JR(e)])),d=new Map,f=new Uint8Array;for await(let t of Hz(e,o.stream,i)){let e=f.length?Zz(f,t):t,n=0;for(;!(n+c>e.length);){let t=Xz(e,n,c),i=u.get(t);if(i===void 0)throw Error(`This MF4 is damaged (unknown record id ${t}).`);if(i<0){if(n+c+4>e.length)break;let i=(e[n+c]|e[n+c+1]<<8|e[n+c+2]<<16|e[n+c+3]<<24)>>>0;if(i>eB)throw Error(`This MF4 is damaged (a string record of ${i} bytes).`);let a=n+c+4+i;if(a>e.length)break;let o=d.get(t)??0;r.wanted(t)&&r.put(t,o,e.slice(n+c+4,a)),d.set(t,o+4+i),n=a;continue}if(n+i>e.length)break;let a=l.get(t);if(a&&(a.buf.set(e.subarray(n,n+i),a.fill),a.fill+=i,a.fill===a.buf.length)){let e=a.fill/a.size;yield{g:a.k,buf:a.buf,n:e,start:a.start,size:a.size},a.start+=e,a.fill=0}n+=i}f=e.slice(n)}for(let e of l.values())e.fill&&(yield{g:e.k,buf:e.buf,n:e.fill/e.size,start:e.start,size:e.size})}var $z,eB,tB,nB=c((()=>{_R(),WR(),QR(),Jz(),$z=e=>Math.max(1,Math.min(65536,Math.floor((8<<20)/Math.max(1,e)))),eB=64<<20,tB=class{#e;#t;#n=new Map;#r=new Map;constructor(e,t){this.#e=e,this.#t=t}want(e){this.#r.has(e)||this.#r.set(e,new Map)}wanted(e){return this.#r.has(e)}put(e,t,n){this.#r.get(e).set(t,n)}async bytes(e,t){let n=Array(t.length);if(e.sdRecordId!==null){let r=this.#r.get(e.sdRecordId);for(let e=0;e<t.length;e++)n[e]=r?.get(t[e])??null,r?.delete(t[e]);return n}if(!e.sd)return n.fill(null);let r=this.#n.get(e);r||this.#n.set(e,r=new qz(this.#e,e.sd,this.#t));for(let e=0;e<t.length;e++)n[e]=r.peek(t[e])??await r.get(t[e]);return n}async strings(e,t){let n=UR(e.encoding);return(await this.bytes(e,t)).map(e=>e?zR(n.decode(e)):null)}}}));function rB(e){let t=e.split(`"`),n=new Map;for(let e=0;e+1<t.length;e+=2){let r=t[e].trim();fB.test(r)&&n.set(Number(r),t[e+1])}return n}function iB(e){let t=new Map,n=new Map,r=new Map,i=(e,t)=>{let i=n.get(Number(e));return i?r.get(i)?.get(t):void 0},a=null;for(let o of e.split(/\r?\n/)){let e=o.trim(),s;if(s=cB.exec(e)){let e=Number(s[1]),r=e>=2147483648,i=r?e-2147483648:e;a={id:i,extended:r,name:s[2],size:Number(s[3]),signals:[]},t.set(sB(i,r),a),n.set(e,a)}else if((s=lB.exec(e))&&a){let e=s[2],t=Number(s[3]),n=Number(s[4]);if(!pB(t,n)||!s[7].trim()||!s[8].trim())continue;let i={name:s[1],start:t,length:n,littleEndian:s[5]===`1`,signed:s[6]===`-`,factor:Number(s[7]),offset:Number(s[8]),unit:s[9],mux:e?e===`M`?`switch`:parseInt(e.slice(1),10):null,float:0,values:null};a.signals.push(i);let o=r.get(a);o||r.set(a,o=new Map),o.has(i.name)||o.set(i.name,i)}else if(s=uB.exec(e)){let e=i(s[1],s[2]);e&&(e.values=rB(s[3]))}else if(s=dB.exec(e)){let e=i(s[1],s[2]);e&&(e.float=s[3]===`1`?32:64)}else (e.startsWith(`BO_`)||e===``)&&e===``&&(a=null)}return t}function aB(e){if(e.float){let t=e.float/8,n=e.start>>3,r=e.littleEndian,i=new DataView(new ArrayBuffer(8));return(e,a)=>{for(let r=0;r<t;r++)i.setUint8(r,e[a+n+r]??0);return t===4?i.getFloat32(0,r):i.getFloat64(0,r)}}let t=e.length,n=2**t,r=n/2,i=e.signed;if(e.littleEndian){let a=e.start>>3,o=e.start&7;if(o+t<=32){let e=t===32?-1:(1<<t)-1;return(t,s)=>{let c=s+a,l=((t[c]|t[c+1]<<8|t[c+2]<<16|t[c+3]<<24)>>>o&e)>>>0;return i&&l>=r?l-n:l}}let s=o+t+7>>3,c=2**(t-(32-o)),l=2**(32-o);return(e,t)=>{let u=t+a,d=(e[u]|e[u+1]<<8|e[u+2]<<16|e[u+3]<<24)>>>o,f=0;for(let t=s-1;t>=4;t--)f=f*256+(e[u+t]??0);let p=d+f%c*l;return i&&p>=r?p-n:p}}let a=e.start>>3,o=e.start&7;if(7-o+t<=32){let e=32-(7-o)-t,s=t===32?-1:(1<<t)-1;return(t,o)=>{let c=o+a,l=((t[c]<<24|t[c+1]<<16|t[c+2]<<8|t[c+3])>>>e&s)>>>0;return i&&l>=r?l-n:l}}let s=(1<<o+1)-1,c=t-(o+1)>>3,l=t-(o+1)&7,u=2**l;return(e,t)=>{let o=(e[t+a]??0)&s,d=t+a+1;for(let t=0;t<c;t++)o=o*256+(e[d++]??0);return l>0&&(o=o*u+((e[d]??0)>>8-l)),i&&o>=r?o-n:o}}function oB(e){let t=e.length,n=2**t,r=n/2,i=e.signed,a=t===32?-1:(1<<t)-1;if(!e.float&&e.littleEndian&&(e.start&7)+t<=32){let t=e.start>>3,o=e.start&7;return(e,s,c,l,u,d,f)=>{for(let p=0;p<l;p++){let l=s[c[p]]+t,m=((e[l]|e[l+1]<<8|e[l+2]<<16|e[l+3]<<24)>>>o&a)>>>0;u[p]=(i&&m>=r?m-n:m)*d+f}}}if(!e.float&&!e.littleEndian&&7-(e.start&7)+t<=32){let o=e.start>>3,s=32-(7-(e.start&7))-t;return(e,t,c,l,u,d,f)=>{for(let p=0;p<l;p++){let l=t[c[p]]+o,m=((e[l]<<24|e[l+1]<<16|e[l+2]<<8|e[l+3])>>>s&a)>>>0;u[p]=(i&&m>=r?m-n:m)*d+f}}}let o=aB(e);return(e,t,n,r,i,a,s)=>{for(let c=0;c<r;c++)i[c]=o(e,t[n[c]])*a+s}}var sB,cB,lB,uB,dB,fB,pB,mB=c((()=>{sB=(e,t)=>t?e+2147483648:e,cB=/^BO_\s+(\d+)\s+(\w+)\s*:\s*(\d+)/,lB=/^SG_\s+(\w+)\s*(?:(M|m\d+M?)\s*)?:\s*(\d+)\|(\d+)@([01])([+-])\s*\(([^,)]*),([^)]*)\)\s*\[[^\]]*\]\s*"([^"]*)"/,uB=/^VAL_\s+(\d+)\s+(\w+)\s+(.*);/,dB=/^SIG_VALTYPE_\s+(\d+)\s+(\w+)\s*:\s*([12])\s*;/,fB=/^-?\d+(?:\.\d+)?$/,pB=(e,t)=>e<=511&&t>=1&&t<=64}));function hB(e){if(!e.busEvent||e.busType!==2)return null;let t=t=>e.channels.find(e=>e.name.endsWith(t))??null,n=t(`DataFrame.ID`),r=t(`DataFrame.DataBytes`);return!n||!r?null:{id:n,ide:t(`DataFrame.IDE`),data:r}}async function gB(e,t,n,r,i,a,o,s){s.key.length<r&&Object.assign(s,{time:new Float64Array(r),key:new Float64Array(r),id:new Float64Array(r),ide:new Float64Array(r),dataAt:new Int32Array(r)});let c=e.recordIdSize,{id:l,ide:u,key:d,dataAt:f}=s;RR(t.id,n,r,a,c,l),t.ide&&RR(t.ide,n,r,a,c,u);for(let e=0;e<r;e++){let n=l[e],r=n&536870911;d[e]=sB(r,t.ide?u[e]!==0:n>=2147483648||r>2047)}if(s.bytes=null,t.data.kind===`vlsd`){let e=new Float64Array(r);RR({...t.data,type:`uint`},n,r,a,c,e),s.bytes=await o.bytes(t.data,e)}else for(let e=0,n=c+t.data.byteOffset;e<r;e++,n+=a)f[e]=n;if(!Yz(e,n,r,i,a,s.time.subarray(0,r)))for(let e=0;e<r;e++)s.time[e]=i+e;return s.n=r,s.buf=n,s}function _B(e){return e.float?(e.start>>3)+e.float/8:e.littleEndian?(e.start>>3)+((e.start&7)+e.length+7>>3):(e.start>>3)+1+(Math.max(0,e.length-((e.start&7)+1))+7>>3)}function vB(e,t,n){let r=0;for(let e of n.values())for(let t of e.signals)r=Math.max(r,_B(t));let i=t.data.kind===`vlsd`?t.data:{...t.data,bitCount:Math.min(t.data.bitCount,r*8)};return qR(e,t.ide?[t.id,t.ide,i]:[t.id,i])}function yB(e,t){let n=t.map(t=>e.signals[e.channels[t].s]);return{route:e,col:n.map(oB),read:n.map(aB),factor:n.map(e=>e.factor),offset:n.map(e=>e.offset),table:t.map((t,r)=>e.channels[t].text?n[r].values:null),idx:new Int32Array,cnt:0,n:0,t0:NaN,t1:NaN}}function bB(e,t,n,r,i,a=1,o=0){let s=new Float64Array(i);if(n.bytes)for(let e=0;e<i;e++)s[e]=t(n.bytes[r[e]]??DB,0)*a+o;else e(n.buf,n.dataAt,r,i,s,a,o);return s}function xB(e,t){let{idx:n,cnt:r}=e,i=new Float64Array(r);for(let e=0;e<r;e++)i[e]=t.time[n[e]];return e.n===0&&(e.t0=i[0]),e.t1=i[r-1],e.n+=r,e.cnt=0,{time:i,cols:e.col.map((i,a)=>{let o=e.table[a];return o?Array.from(bB(i,e.read[a],t,n,r),e=>o.get(e)??null):bB(i,e.read[a],t,n,r,e.factor[a],e.offset[a])})}}function SB(e,t){let n=e.signals.find(e=>e.mux===`switch`);return{key:sB(e.id,e.extended),skip:!1,frames:0,all:t,sw:n?{col:oB(n),read:aB(n)}:null,byMux:new Map,idx:new Int32Array,cnt:0}}function CB(e,t,n){let r=[];for(let n=0;n<e.n;n++){let i=t.get(e.key[n]);if(i.skip){i.frames++;continue}i.cnt===0&&(r.push(i),i.idx.length<e.n&&(i.idx=new Int32Array(e.n))),i.idx[i.cnt++]=n}let i=[];for(let t of r){if(t.all&&(t.all.idx=t.idx,t.all.cnt=t.cnt,i.push(t.all)),t.sw){let r=bB(t.sw.col,t.sw.read,e,t.idx,t.cnt);for(let e=0;e<t.cnt;e++){let a=t.byMux.get(r[e]);a===void 0&&((a=n(t,r[e]))||t.byMux.size<4096)&&t.byMux.set(r[e],a),a&&(a.cnt===0&&(i.push(a),a.idx.length<t.cnt&&(a.idx=new Int32Array(t.cnt))),a.idx[a.cnt++]=t.idx[e])}}t.cnt=0}return i}async function wB(e,t,n,r){let i=new Map;if(t.groups.forEach((e,t)=>{let n=hB(e);n&&e.cycles>0&&i.set(t,n)}),i.size===0)return null;if(n.length===0)return{dbc:new Map,layouts:i,routes:[],notes:[],cache:new Map};let a=iB(RI(new Uint8Array(await n[0].arrayBuffer()))),o=[],s=new Map,c=new Map,l=0,u=new tB(e,r);for(let[n,d]of i){let i=t.groups[n],f=(e,t)=>{let n=e.signals.filter(e=>t===null?typeof e.mux!=`number`:e.mux===t),r=[];return n.forEach((e,t)=>{r.push({s:t,text:!1}),e.values&&r.push({s:t,text:!0})}),yB({key:sB(e.id,e.extended),mux:t,signals:n,channels:r},r.map((e,t)=>t))},p=new kB(e=>{let t=a.get(e);if(!t){let t=OB(e);return s.set(e,t),t}let r=SB(t,f(t,null));return o.push({model:n,m:r}),r});d.data.sdRecordId!==null&&u.want(d.data.sdRecordId);let m=EB();for await(let o of Qz(e,t,[n],u,r,vB(i,d,a))){let e=await gB(i,d,o.buf,o.n,o.start,o.size,u,m),t=(e,t)=>{let n=a.get(e.key);return n.signals.some(e=>e.mux===t)?f(n,t):null};for(let n of CB(e,p,t)){let t=xB(n,e);if(l<0)continue;if((l+=t.time.length*(1+t.cols.length))>AB){l=-1,c.clear();continue}let r=c.get(n);r||c.set(n,r=[]),r.push(t)}}}let d=[],f=new Map;for(let{model:e,m:t}of o)for(let n of[t.all,...t.byMux.values()]){if(!n)continue;let{route:t,n:r,t0:i,t1:o}=n;if(t.signals.length===0)continue;let s=a.get(t.key);l>=0&&f.set(t,c.get(n)??[]),d.push({model:e,route:t,group:{name:t.mux===null?s.name:`${s.name} [m=${t.mux}]`,channels:t.channels.map(e=>({name:e.text?`${t.signals[e.s].name} (text)`:t.signals[e.s].name,unit:e.text?``:t.signals[e.s].unit,text:e.text})),samples:r,time:{kind:`timestamps`},rateHz:r>1&&o>i?Math.round((r-1)/(o-i)*1e6)/1e6:null}})}let p=[];if(s.size){let e=[...s.values()].reduce((e,t)=>e+t.frames,0),t=[...s.keys()].map(e=>`0x${(e%2147483648).toString(16).toUpperCase()}`).join(`, `);p.push(`${e} frame${e===1?``:`s`} with ${s.size} id${s.size===1?``:`s`} not in the DBC ${e===1?`was`:`were`} skipped (${t}).`)}return{dbc:a,layouts:i,routes:d,notes:p,cache:f}}async function*TB(e,t,n,r,i,a){let o=[];for(let e of i){let t=r.cache.get(e.route);if(!t){o.push(e);continue}r.cache.delete(e.route);let n=0;for(let r of t)yield{group:e.group,start:n,length:r.time.length,time:r.time,columns:e.sel.map(e=>r.cols[e])},n+=r.time.length}if(!o.length)return;let s=r.layouts.get(n),c=t.groups[n],l=new Map,u=new Map;for(let e of o){let t=yB(e.route,e.sel);l.set(t,e.group);let n=u.get(e.route.key);n||u.set(e.route.key,n={all:null,byMux:new Map}),e.route.mux===null?n.all=t:n.byMux.set(e.route.mux,t)}let d=new kB(e=>{let t=u.get(e);if(!t)return OB(e);let n=SB(r.dbc.get(e),t.all);return t.byMux.size||(n.sw=null),n}),f=new tB(e,a);s.data.sdRecordId!==null&&f.want(s.data.sdRecordId);let p=EB();for await(let i of Qz(e,t,[n],f,a,vB(c,s,r.dbc))){let e=await gB(c,s,i.buf,i.n,i.start,i.size,f,p);for(let t of CB(e,d,(e,t)=>u.get(e.key).byMux.get(t)??null)){let n=t.n,r=xB(t,e);yield{group:l.get(t),start:n,length:r.time.length,time:r.time,columns:r.cols}}}}var EB,DB,OB,kB,AB,jB=c((()=>{mB(),zI(),WR(),nB(),QR(),EB=()=>({n:0,time:new Float64Array,key:new Float64Array,id:new Float64Array,ide:new Float64Array,bytes:null,buf:new Uint8Array,dataAt:new Int32Array}),DB=new Uint8Array,OB=e=>({key:e,skip:!0,frames:0,all:null,sw:null,byMux:new Map,idx:new Int32Array,cnt:0}),kB=class{#e=Array(2048);#t=new Map;#n;constructor(e){this.#n=e}get(e){let t=e<2048?this.#e[e]:this.#t.get(e);return t||(t=this.#n(e),e<2048?this.#e[e]=t:this.#t.set(e,t)),t}},AB=48e6}));async function MB(e,t){let n=t.master;if(!n||t.cycles<2)return null;if(n.kind===`vmaster`)return n.conv.k===`lin`&&n.conv.a>0?LB(1/n.conv.a):null;if(!t.sorted)return null;let r=JR(t),i=t.cycles,a,o;if(t.stream[0]?.zip){let n=Bz(t.stream.slice(0,1),r,qR(t,[])),s=await Vz(e,t.stream[0],n,4096*r);if(i=Math.min(t.cycles,Math.floor(s.length/n)),i<2)return null;a=s.subarray(0,n),o=s.subarray((i-1)*n,i*n)}else a=await Wz(e,t.stream,0,r),o=await Wz(e,t.stream,t.cycles-1,r);if(!a||!o)return null;let s=new Float64Array(2);return RR(n,a,1,r,t.recordIdSize,s,0),RR(n,o,1,r,t.recordIdSize,s,1),fR(n.conv,s),s[1]>s[0]?LB((i-1)/(s[1]-s[0])):null}async function NB(e,t,n,r,i,a,o){let s;if(e.kind===`vlsd`){let a=new Float64Array(n);RR({...e,type:`uint`},t,n,r,i,a),s=await o.strings(e,a)}else if(e.type===`string`)s=BR(e,t,n,r,i);else{let a=new Float64Array(n);RR(e,t,n,r,i,a),e.conv.k===`text`?s=mR(e.conv,a):(fR(e.conv,a),s=a)}return VR(e,t,n,r,a,s),s}async function PB(e,t,n,r,i,a,o,s){let c=e.recordIdSize,l=[];for(let i of t)l.push(await NB(e.channels[i],n,r,a,c,c+e.dataBytes,s));return{group:o,time:Yz(e,n,r,i,a),start:i,length:r,columns:l}}async function*FB(e,t){let n=e.plan.state,r=t.filter(e=>n.groups[e].route),i=t.filter(e=>!n.groups[e].route);if(r.length){let t=r.map(t=>({group:t,route:n.groups[t].route,sel:aR(e,t)}));yield*TB(e.io,n.model,n.groups[r[0]].model,n.bus,t,e.signal)}if(!i.length)return;let a=new tB(e.io,e.signal),o=new Map;for(let t of i){let r=n.groups[t],i=aR(e,t).map(e=>r.channels[e]);for(let e of i){let t=n.model.groups[r.model].channels[e].sdRecordId;t!==null&&a.want(t)}o.set(r.model,{pg:t,cols:i})}let[s,{cols:c}]=o.entries().next().value,l=n.model.groups[s],u=o.size===1?qR(l,c.map(e=>l.channels[e])):1/0;for await(let t of Qz(e.io,n.model,[...o.keys()],a,e.signal,u)){let{pg:e,cols:r}=o.get(t.g);yield await PB(n.model.groups[t.g],r,t.buf,t.n,t.start,t.size,e,a)}}function IB(e){let t=e.plan.state,n=new Map;for(let r of e.selection){let e=t.model.groups[t.groups[r.group].model].dg;n.set(e,[...n.get(e)??[],r.group])}return[...n].sort((e,t)=>e[0]-t[0]).map(([,e])=>e)}var LB,RB,zB,BB,VB=c((()=>{zI(),oR(),bR(),IR(),_R(),WR(),VI(),QR(),nB(),Jz(),jB(),LB=e=>Math.round(e*1e6)/1e6,RB=e=>e.kind===`value`?e.type!==`bytes`:e.kind===`vlsd`&&e.type===`string`,zB=e=>({name:e.name,unit:e.unit,text:e.type===`string`||e.kind===`vlsd`||e.conv.k===`text`}),BB={...BI,async plan(e,t){let n=await t.read(0,64);if(NI(n,`UnFinMF`))throw Error(`This MF4 was not finalized by its logger (it starts with UnFinMF). Finalize it with the logger software or asammdf, then open it again.`);let r=LI(n.subarray(8,16)).replace(/\0/g,``).trim(),i=Number(r.replace(`.`,``).slice(0,3))>=400?await MR(t,r):await yR(t,n,r);KR(i,t.size);let a=await wB(t,i,e.companions.filter(e=>e.name.toLowerCase().endsWith(`.dbc`))),o=new Set(a?.layouts.keys()??[]),s=[],c=[],l=[...i.notes],u=0;for(let e=0;e<i.groups.length;e++){let n=i.groups[e];if(n.vlsdCg||n.cycles===0||o.has(e))continue;let r=[];if(n.channels.forEach((e,t)=>{RB(e)?r.push(t):u++}),r.length!==0){for(let e of r){let t=n.channels[e].conv;t.k===`unsupported`&&l.push(`${n.channels[e].name}: ${t.what} is not supported; raw values are shown.`)}c.push({model:e,channels:r}),s.push({name:n.name,channels:r.map(e=>zB(n.channels[e])),samples:n.cycles,time:n.master?{kind:`timestamps`}:{kind:`index`},rateHz:await MB(t,n)})}}if(u&&l.push(`${u} byte-array channel${u===1?` was`:`s were`} skipped.`),a){if(a.routes.length===0&&a.dbc.size===0){if(s.length===0)throw Error(`This MF4 has raw CAN frames. Drop its .dbc file together with it to decode signals.`);l.push(`This MF4 also has raw CAN frames. Drop its .dbc file together with it to decode signals.`)}for(let e of a.routes)c.push({model:e.model,route:e.route}),s.push(e.group);l.push(...a.notes)}if(s.length===0)throw Error(`This MDF file has no channels with samples.`);let d={model:i,groups:c,bus:a};return{format:i.version,startTime:i.startTime,groups:s,meta:i.meta,events:[],notes:l,interleaved:!!a?.routes.length||i.groups.some(e=>!e.sorted&&!e.vlsdCg),state:d}},async*stream(e){for(let t of IB(e))yield*FB(e,t)},streamGroup(e,t){return FB(e,[t])}}}));function HB(e){let t=[];for(let n of RI(e).split(`\0`)){if(!n)continue;let e=n.split(``),r=parseFloat(e[0].split(``)[0]);Number.isFinite(r)&&t.push({onset:r,texts:e.slice(1).filter(e=>e.length>0)})}return t}function UB(e,t){let n=/^(\d\d)\.(\d\d)\.(\d\d)$/.exec(e),r=/^(\d\d)\.(\d\d)\.(\d\d)$/.exec(t);if(!n||!r)return null;let i=Number(n[3]);return`${i>=85?1900+i:2e3+i}-${n[2]}-${n[1]}T${r[1]}:${r[2]}:${r[3]}`}function WB(e,t,n,r,i,a,o,s){let{bit:c,off:l}=e;if(a===2)for(let e=0;e<i;e++)o[s+e]=c*(l+t.getInt16(r+2*e,!0));else for(let e=0,t=r;e<i;e++,t+=3)o[s+e]=c*(l+((n[t]|n[t+1]<<8|n[t+2]<<16)<<8>>8))}var GB,KB,qB=c((()=>{nR(),zI(),UI(),GB=e=>`${+e.toFixed(6)} Hz`,KB={...HI,async plan(e,t){let n=await t.read(0,256),r=(e,t)=>LI(n.subarray(e,e+t)).trim(),i=n[0]===255,a=parseInt(r(252,4),10),o=parseInt(r(184,8),10),s=r(192,44),c=/^(EDF|BDF)\+/.test(s),l=/^(EDF|BDF)\+D/.test(s),u=parseFloat(r(244,8));if(!(a>0)||o!==256*(a+1)||!(u>0))throw Error(`This EDF/BDF header is damaged.`);let d=await t.read(256,a*256),f=(e,t,n)=>LI(d.subarray(e*a+t*n,e*a+t*(n+1))).trim(),p=i?3:2,m=[],h=0;for(let e=0;e<a;e++){let t=parseFloat(f(104,8,e)),n=parseFloat(f(112,8,e)),r=parseFloat(f(120,8,e)),i=parseFloat(f(128,8,e)),a=Number(f(216,8,e));if(!(Number.isInteger(a)&&a>=0))throw Error(`This EDF/BDF header is damaged (samples per record).`);let o=(n-t)/(i-r);m.push({label:f(0,16,e),unit:f(96,8,e),spr:a,offset:h,bit:o,off:n/o-i}),h+=a*p}let g=h;if(!(g>0&&o+g<=t.size))throw Error(`This EDF/BDF file is damaged (its data records do not fit in it).`);let _=Math.floor((t.size-o)/g),v=parseInt(r(236,8),10),y=[];v>=0?v>_&&(y.push(`The file is shorter than its header says: ${_} of ${v} data records were read.`),v=_):v=_;let b=c?m.flatMap((e,t)=>/^(EDF|BDF) Annotations$/.test(e.label)?[t]:[]):[],x=new Map;m.forEach((e,t)=>{!b.includes(t)&&e.spr>0&&x.set(e.spr,[...x.get(e.spr)??[],t])});let S=[...x.values()],C=S.map(e=>{let t=m[e[0]].spr/u;return{name:GB(t),channels:e.map(e=>({name:m[e].label,unit:m[e].unit})),samples:v*m[e[0]].spr,rateHz:t,time:l?{kind:`timestamps`}:{kind:`rate`,rate:t,start:0}}}),w={headerBytes:o,records:v,duration:u,recordBytes:g,bps:p,signals:m,groups:S,annotations:b,discontinuous:l};return{format:`${i?`BDF`:`EDF`}${c?l?`+D`:`+`:``}`,startTime:UB(r(168,8),r(176,8)),groups:C,meta:{patient:r(8,80),recording:r(88,80)},events:[],notes:l?[`Discontinuous recording: each gap shows as a break in the traces.`,...y]:y,state:w}},async*stream(e){let t=e.plan.state,n=Math.max(1,Math.floor(eR/t.recordBytes)),r=e.selection.map(e=>({g:e.group,chans:e.channels.map(n=>t.signals[t.groups[e.group][n]]),spr:t.signals[t.groups[e.group][0]].spr})),i=r.map(()=>0),a=0,o=NaN;for await(let s of e.io.windows(t.headerBytes,t.records*t.recordBytes,n*t.recordBytes)){e.signal?.throwIfAborted();let n=Math.floor(s.bytes.length/t.recordBytes);if(n===0)break;let c=PI(s.bytes),l=new Float64Array(n),u=[];for(let e=0;e<n;e++)l[e]=(a+e)*t.duration,t.annotations.forEach((n,r)=>{let i=t.signals[n],a=e*t.recordBytes+i.offset,o=HB(s.bytes.subarray(a,a+i.spr*t.bps));r===0&&o.length&&(l[e]=o[0].onset);for(let e of o)for(let t of e.texts)u.push({time:e.onset,text:t})});let d=new Uint8Array(n),f=0;if(t.discontinuous)for(let e=0;e<n;e++){let n=e?l[e-1]+t.duration:o;n===n&&l[e]>n+1e-9&&(d[e]=1,f++)}for(let e=0;e<r.length;e++){let a=r[e],p=a.spr/t.duration,m=n*a.spr+f,h=t.discontinuous?new Float64Array(m):null,g=a.chans.map(()=>new Float64Array(m)),_=0;for(let e=0;e<n;e++){if(d[e]){h[_]=e?l[e-1]+t.duration:o;for(let e of g)e[_]=NaN;_++}if(h)for(let t=0;t<a.spr;t++)h[_+t]=l[e]+t/p;let n=e*t.recordBytes;a.chans.forEach((e,r)=>WB(e,c,s.bytes,n+e.offset,a.spr,t.bps,g[r],_)),_+=a.spr}let v={group:a.g,time:h,start:i[e],length:m,columns:g};e===0&&u.length&&(v.events=u),i[e]+=m,yield v}o=l[n-1]+t.duration,a+=n}}}}));function JB(e,t,n=0){let r=e.indexOf(`<${t}>`,n);if(r<0)return``;let i=e.indexOf(`</${t}>`,r);return i<0?``:e.slice(r+t.length+2,i).trim()}function YB(e,t){let n=[];for(let r=e.indexOf(`<${t}>`);r>=0;){let i=e.indexOf(`</${t}>`,r);if(i<0)break;n.push(e.slice(r,i+t.length+3)),r=e.indexOf(`<${t}>`,i)}return n}function XB(e,t,n){let r=e[n];if((r===1||r===4||r===8)&&n+1+r<=e.length)return r===1?[e[n+1],2]:r===4?[t.getUint32(n+1,!0),5]:[AI(t,n+1),9];throw Error(`This XDF file is damaged (bad length field).`)}function ZB(e,t,n,r){if(n>=e.length)return-1;if(e[n++]===8&&(n+=8),r.fmt!==`string`)return n+rV[r.fmt]*r.nch<=e.length?n+rV[r.fmt]*r.nch:-1;for(let i=0;i<r.nch;i++){if(n>=e.length)return-1;let[r,i]=XB(e,t,n);n+=i+r}return n<=e.length?n:-1}async function*QB(e,t){let n=new Uint8Array;for await(let r of e.windows(4,e.size-4)){t?.throwIfAborted();let i=r.bytes,a=r.offset-n.length;if(n.length){let e=new Uint8Array(n.length+i.length);e.set(n),e.set(i,n.length),i=e}let o=PI(i),s=0;for(;!(s+1>i.length);){let t=i[s];if(s+1+t>i.length)break;let[n,r]=XB(i,o,s),c=s+r+n;if(a+c>e.size)return;if(c>i.length)break;yield{tag:i[s+r]|i[s+r+1]<<8,body:i.subarray(s+r+2,c)},s=c}n=i.slice(s)}}function $B(e,t,n){let r=t-e.i0,i=n-e.t0;e.n++,e.si+=r,e.st+=i,e.sii+=r*r,e.sit+=r*i}function eV(e){let t=e.n*e.sii-e.si*e.si;e.b=t>0?(e.n*e.sit-e.si*e.st)/t:0,e.a=(e.st-e.b*e.si)/Math.max(1,e.n)}function tV(e){if(e.length===0)return[0,0];if(e.length===1)return[e[0][1],0];let t={i0:e[0][0],t0:0,n:0,si:0,st:0,sii:0,sit:0,a:0,b:0};for(let[n,r]of e)$B(t,n,r);return eV(t),[t.a-t.b*t.i0,t.b]}function nV(e,t,n){let r=t.t0+t.a+t.b*(n-t.i0);return r+e.c0+e.c1*r}var rV,iV,aV,oV,sV=c((()=>{zI(),GL(),oR(),GI(),rV={float32:4,double64:8,int8:1,int16:2,int32:4,int64:8},iV=1e5,aV=e=>e.fmt===`string`||rV[e.fmt]!==void 0,oV={...WI,async plan(e,t){let n=new Map,r=``;for await(let e of QB(t)){let t=PI(e.body);if(e.tag===1)r=RI(e.body);else if(e.tag===2){let r=t.getUint32(0,!0),i=RI(e.body.subarray(4)),a=parseInt(JB(i,`channel_count`),10)||1;if(!(a>=1&&a<=iV))throw Error(`This XDF file is damaged (a stream with ${a} channels).`);let o=YB(i,`channel`);n.set(r,{id:r,name:JB(i,`name`)||`Stream ${r}`,nch:a,srate:parseFloat(JB(i,`nominal_srate`))||0,fmt:JB(i,`channel_format`)||`float32`,labels:Array.from({length:a},(e,t)=>JB(o[t]??``,`label`)||`Ch${t+1}`),units:Array.from({length:a},(e,t)=>JB(o[t]??``,`unit`)),count:0,segs:[],clock:[],c0:0,c1:0,lastTs:NaN})}else if(e.tag===3){let r=n.get(t.getUint32(0,!0));if(!r||!aV(r))continue;let[i,a]=XB(e.body,t,4),o=4+a,s=rV[r.fmt],c=r.srate>0?Math.max(1,500/r.srate):1/0;for(let n=0;n<i&&!(ZB(e.body,t,o,r)<0);n++){let n;if(e.body[o++]===8?(n=t.getFloat64(o,!0),o+=8):n=r.lastTs+(r.srate>0?1/r.srate:0),r.fmt===`string`)for(let n=0;n<r.nch;n++){let[n,r]=XB(e.body,t,o);o+=r+n}else o+=s*r.nch;if(r.srate>0){let e=r.segs[r.segs.length-1];(!e||n-r.lastTs>c)&&r.segs.push(e={i0:r.count,t0:n,n:0,si:0,st:0,sii:0,sit:0,a:0,b:0}),$B(e,r.count,n)}else r.count===0&&r.segs.push({i0:0,t0:n,n:1,si:0,st:0,sii:0,sit:0,a:0,b:0});r.lastTs=n,r.count++}}else if(e.tag===4){let e=n.get(t.getUint32(0,!0));e&&e.clock.push([t.getFloat64(4,!0),t.getFloat64(12,!0)])}}let i=[],a=[...n.values()].sort((e,t)=>e.id-t.id).filter(e=>(aV(e)||i.push(`${e.name}: channel format ${e.fmt} is not supported; skipped.`),aV(e))),o=1/0;for(let e of a){[e.c0,e.c1]=tV(e.clock);for(let t of e.segs)eV(t);if(e.count===0)continue;let t=e.srate>0?nV(e,e.segs[0],0):e.segs[0].t0+e.c0+e.c1*e.segs[0].t0;o=Math.min(o,t)}let s=WL(a.map(e=>e.name),[]),c=a.map((e,t)=>({name:s[t],channels:e.labels.map((t,n)=>({name:t,unit:e.units[n],...e.fmt===`string`?{text:!0,sparse:!0}:{}})),samples:e.count,time:{kind:`timestamps`},rateHz:e.srate>0?e.srate:null,irregular:e.srate===0})),l=JB(r,`version`);return{format:`XDF ${l||`1.0`}`,startTime:null,groups:c,meta:{header:l},events:[],notes:i,state:{streams:a,origin:Number.isFinite(o)?o:0}}},async*stream(e){let t=e.plan.state,n=8192,r=new Map,i=e=>e.sel.map(()=>e.s.fmt===`string`?Array(n):new Float64Array(n));for(let a of e.selection){let o=t.streams[a.group],s={g:a.group,s:o,sel:aR(e,a.group),time:new Float64Array(n),cols:[],n:0,start:0,seg:0,i:0,raw:NaN};s.cols=i(s),r.set(o.id,s)}let a=e=>{let t={group:e.g,time:e.time.slice(0,e.n),start:e.start,length:e.n,columns:e.cols.map(t=>t.slice(0,e.n))};return e.start+=e.n,e.n=0,e.time=new Float64Array(n),e.cols=i(e),t};for await(let i of QB(e.io,e.signal)){if(i.tag!==3)continue;let e=PI(i.body),o=r.get(e.getUint32(0,!0));if(!o)continue;let s=o.s,[c,l]=XB(i.body,e,4),u=4+l,d=rV[s.fmt],f=[];for(let r=0;r<c&&!(ZB(i.body,e,u,s)<0);r++){let r;i.body[u++]===8?(r=e.getFloat64(u,!0),u+=8):r=o.raw+(s.srate>0?1/s.srate:0),o.raw=r;let c;if(s.srate>0){for(;o.seg+1<s.segs.length&&s.segs[o.seg+1].i0<=o.i;)o.seg++;c=nV(s,s.segs[o.seg],o.i)}else c=r+s.c0+s.c1*r;if(o.time[o.n]=c-t.origin,s.fmt===`string`){let n=[];for(let t=0;t<s.nch;t++){let[t,r]=XB(i.body,e,u);n.push(RI(i.body.subarray(u+r,u+r+t))),u+=r+t}o.sel.forEach((e,t)=>{o.cols[t][o.n]=n[e]}),f.push({time:c-t.origin,text:n.join(` `)})}else o.sel.forEach((t,n)=>{let r=u+t*d,i=o.cols[n];switch(s.fmt){case`float32`:i[o.n]=e.getFloat32(r,!0);break;case`double64`:i[o.n]=e.getFloat64(r,!0);break;case`int8`:i[o.n]=e.getInt8(r);break;case`int16`:i[o.n]=e.getInt16(r,!0);break;case`int32`:i[o.n]=e.getInt32(r,!0);break;default:i[o.n]=e.getInt32(r+4,!0)*4294967296+e.getUint32(r,!0)}}),u+=d*s.nch;o.i++,++o.n===n&&(yield a(o))}f.length&&(yield{group:o.g,time:new Float64Array,start:o.start,length:0,columns:o.sel.map(()=>new Float64Array),events:f})}for(let e of r.values())e.n&&(yield a(e))}}}));function cV(e,t,n,r,i){switch(r){case CV:{let r=e.getUint32(n,i);return[RI(t.subarray(n+4,n+4+r)),4+r]}case 1:return[e.getInt8(n),1];case 2:return[e.getInt16(n,i),2];case 3:return[e.getInt32(n,i),4];case 4:return[jI(e,n,i),8];case 5:return[e.getUint8(n),1];case 6:return[e.getUint16(n,i),2];case 7:return[e.getUint32(n,i),4];case 8:return[AI(e,n,i),8];case 9:case 25:return[e.getFloat32(n,i),4];case 10:case 26:return[e.getFloat64(n,i),8];case 33:return[e.getUint8(n)!==0,1];case wV:return[kV(e,n,i),16];default:throw Error(`This TDMS file has a property of type ${r}, which Kymoscope cannot read.`)}}function lV(e){let t=/^\/'((?:[^']|'')*)'(?:\/'((?:[^']|'')*)')?$/.exec(e);return t?[t[1].replace(/''/g,`'`),(t[2]??``).replace(/''/g,`'`)]:null}function uV(e){if(e.has(`NI_Number_Of_Scales`))return Number(e.get(`NI_Number_Of_Scales`));let t=0;for(let n of e.keys()){let e=/^NI_Scale\[(\d+)\]_Scale_Type$/.exec(n);e&&(t=Math.max(t,Number(e[1])+1))}return t}function dV(e,t,n){let r=e.find(e=>uV(e)>0);if(!r||r.get(`NI_Scaling_Status`)===`scaled`)return null;let i=(e,a)=>{if(e===AV||e<0||a>8)return e=>e;let o=r.get(`NI_Scale[${e}]_Scale_Type`);if(o===void 0)return e=>e;if(o===`Linear`){let t=Number(r.get(`NI_Scale[${e}]_Linear_Slope`)),n=Number(r.get(`NI_Scale[${e}]_Linear_Y_Intercept`)??0),o=i(Number(r.get(`NI_Scale[${e}]_Linear_Input_Source`)??AV),a+1);return o&&(e=>t*o(e)+n)}if(o===`Polynomial`){let o=Number(r.get(`NI_Scale[${e}]_Polynomial_Coefficients_Size`)??4);if(!(Number.isInteger(o)&&o>=0&&o<=64))return t.push(`${n}: an NI polynomial scale with ${o} coefficients is not supported; raw values are shown.`),null;let s=Array.from({length:o},(t,n)=>Number(r.get(`NI_Scale[${e}]_Polynomial_Coefficients[${n}]`))),c=i(Number(r.get(`NI_Scale[${e}]_Polynomial_Input_Source`)??AV),a+1);return c&&(e=>{let t=c(e),n=0;for(let e=o-1;e>=0;e--)n=n*t+s[e];return n})}return t.push(`${n}: NI scale type ${String(o)} is not supported; raw values are shown.`),null};return i(uV(r)-1,0)}function fV(e,t,n,r,i,a,o,s){let c=jV[e];if(c&&a&&r===TV[e]&&(t.byteOffset+n)%r===0){o.set(new c(t.buffer,t.byteOffset+n,i),s);return}switch(e){case 1:for(let e=0;e<i;e++,n+=r)o[s+e]=t.getInt8(n);return;case 2:for(let e=0;e<i;e++,n+=r)o[s+e]=t.getInt16(n,a);return;case 3:for(let e=0;e<i;e++,n+=r)o[s+e]=t.getInt32(n,a);return;case 4:for(let e=0;e<i;e++,n+=r)o[s+e]=jI(t,n,a);return;case 5:case 33:for(let e=0;e<i;e++,n+=r)o[s+e]=t.getUint8(n);return;case 6:for(let e=0;e<i;e++,n+=r)o[s+e]=t.getUint16(n,a);return;case 7:for(let e=0;e<i;e++,n+=r)o[s+e]=t.getUint32(n,a);return;case 8:for(let e=0;e<i;e++,n+=r)o[s+e]=AI(t,n,a);return;case 9:case 25:for(let e=0;e<i;e++,n+=r)o[s+e]=t.getFloat32(n,a);return;case 10:case 26:for(let e=0;e<i;e++,n+=r)o[s+e]=t.getFloat64(n,a);return;case wV:for(let e=0;e<i;e++,n+=r)o[s+e]=kV(t,n,a);return;default:o.fill(NaN,s,s+i)}}async function pV(e,t,n){let r=new Map,i=[],a=[],o=new Map,s=new Map,c=t??e,l=0,u=0;for(;l+28<=e.size&&u+28<=c.size;){let d=t?u:l,f=await c.read(d,28),p=PI(f);if(!(f[0]===84&&f[1]===68&&f[2]===83&&(f[3]===109||f[3]===104)))throw Error(`This TDMS file is damaged (no segment lead-in where one should be).`);let m=p.getUint32(4,!0),h=!(m&bV),g=AI(p,12,h),_=AI(p,20,h),v=g>=2**53?e.size:Math.min(e.size,l+28+g);if(_>v-l-28)throw Error(`This TDMS file is damaged (segment metadata longer than its segment).`);if(m&gV){let e=await c.read(d+28,_),t=PI(e);m&vV&&(a=[],o=new Map);let i=0,l=t.getUint32(i,h);i+=4;for(let c=0;c<l;c++){let c=t.getUint32(i,h),l=RI(e.subarray(i+4,i+4+c));i+=4+c;let u=lV(l),d=r.get(l);d||r.set(l,d={path:l,group:u?.[0]??``,name:u?.[1]??``,type:0,props:new Map,pieces:[],total:0});let f=t.getUint32(i,h);i+=4;let p=null;if(f===4294967295)p=null;else if(f===0)p=s.get(d)??null;else if(f===xV||f===SV){let e=AI(t,i+8,h),r=t.getUint32(i+16,h),a=f===xV?20:17,o=i+20,s=EV[t.getUint32(o,h)]??0,c=t.getUint32(o+8,h);i=o+r*a;let l=t.getUint32(i,h);i+=4;let u=0;for(let e=0;e<l;e++)u+=t.getUint32(i+4*e,h);i+=4*l,f===SV?n.push(`${d.name}: DAQmx digital line data is not supported; skipped.`):(r>1&&n.push(`${d.name}: only the first of its ${r} DAQmx scalers is read.`),p={type:s,count:e,bytes:0,daqmx:{byteOffset:c,stride:u}})}else{let e=t.getUint32(i,h),n=AI(t,i+8,h),r=e===CV?AI(t,i+16,h):n*(TV[e]??0);i+=f-4,p={type:e,count:n,bytes:r,daqmx:null}}p&&(d.type=p.type,s.set(d,p));let m=t.getUint32(i,h);i+=4;for(let n=0;n<m;n++){let n=t.getUint32(i,h),r=RI(e.subarray(i+4,i+4+n));i+=4+n;let a=t.getUint32(i,h);i+=4;let[o,s]=cV(t,e,i,a,h);d.props.set(r,o),i+=s}let g=o.get(d);g===void 0?o.set(d,a.push({obj:d,idx:p})-1):a[g].idx=p}}if(m&_V){let e=l+28+_,t=a.filter(e=>e.idx&&e.idx.count>0),n=t.filter(e=>e.idx.daqmx),r=(m&yV)!==0,o=0,s=0;n.length?(s=n[0].idx.daqmx.stride,o=n[0].idx.count*s):r?(s=t.reduce((e,t)=>e+(TV[t.idx.type]??0),0),o=(t[0]?.idx.count??0)*s):o=t.reduce((e,t)=>e+t.idx.bytes,0);let c=o>0?Math.floor((v-e)/o):0,u=i.push({rawStart:e,chunkSize:o,chunks:c,le:h})-1,d=0;for(let e of t){let t=e.idx,n=TV[t.type]??0,i=t.daqmx?{seg:u,count:t.count,offset:t.daqmx.byteOffset,bytes:0,stride:s,type:t.type}:{seg:u,count:t.count,offset:d,bytes:t.bytes,stride:r?s:n,type:t.type};t.daqmx||(d+=r?n:t.bytes),i.type===CV?i.count=Math.min(i.count,Math.floor(i.bytes/4)):n>0&&(i.count=Math.min(i.count,i.stride>0?Math.max(0,Math.floor((o-i.offset-n)/i.stride)+1):0)),e.obj.pieces.push(i),c&&(e.obj.total+=i.count*c)}}if(l=v,u+=28+_,v>=e.size)break}return{objs:[...r.values()],segments:i}}function mV(e,t,n,r,i,a){let o=0;for(;o<i&&r.pi<t.pieces.length;){let s=t.pieces[r.pi],c=e.segments[s.seg];if(r.chunk>=c.chunks){r.pi++,r.chunk=0,r.row=0;continue}let l=Math.min(i-o,s.count-r.row),u=c.rawStart+r.chunk*c.chunkSize+s.offset;if(s.type===CV)a.push({ch:n,at:u,end:u+s.bytes,rows:l,first:r.row,out:o,piece:s,le:c.le,range:0});else{let e=u+r.row*s.stride;a.push({ch:n,at:e,end:e+(l-1)*s.stride+TV[s.type],rows:l,first:r.row,out:o,piece:s,le:c.le,range:0})}o+=l,r.row+=l,r.row>=s.count&&(r.chunk++,r.row=0)}}async function*hV(e,t){let n=e.plan.state,r=n.groups[t],i=aR(e,t).map(e=>r.channels[e]),a=r.time?[r.time,...i]:i;if(!a.length)return;let o=new Map(n.objs.map(e=>[e.path,e.props])),s=e=>o.get(e)??new Map,c=s(`/`),l=a.map(e=>dV([e.props,s(`/'${e.group.replace(/'/g,`''`)}'`),c],[],e.name)),u=a.map(()=>({pi:0,chunk:0,row:0})),d=a.reduce((e,t)=>Math.min(e,t.total),1/0);for(let i=0;i<d;){e.signal?.throwIfAborted();let o=Math.min(DV,d-i),s=[];a.forEach((e,t)=>mV(n,e,t,u[t],o,s));let c=s.slice().sort((e,t)=>e.at-t.at),f=[];for(let e of c){let t=f[f.length-1];t&&e.at<=t.end+OV&&Math.max(t.end,e.end)-t.at<=16777216?t.end=Math.max(t.end,e.end):f.push({at:e.at,end:e.end}),e.range=f.length-1}let p=[];for(let t of f)p.push(await e.io.slice(t.at,t.end-t.at));let m=p.map(PI),h=a.map(e=>e.type===CV?Array(o).fill(null):new Float64Array(o).fill(NaN));for(let e of s){let t=e.at-f[e.range].at,n=e.piece;if(n.type===CV){let r=p[e.range],i=m[e.range],a=t+4*n.count,o=h[e.ch];for(let n=0;n<e.rows;n++){let s=e.first+n,c=s===0?0:i.getUint32(t+4*(s-1),e.le),l=i.getUint32(t+4*s,e.le);o[e.out+n]=RI(r.subarray(a+c,a+l))}}else fV(n.type,m[e.range],t,n.stride,e.rows,e.le,h[e.ch],e.out)}for(let e=0;e<a.length;e++){let t=l[e],n=h[e];if(t&&n instanceof Float64Array)for(let e=0;e<o;e++)n[e]=t(n[e])}let g=null;if(r.time){g=h.shift();for(let e=0;e<o;e++)g[e]-=r.origin}yield{group:t,time:g,start:i,length:o,columns:h},i+=o}}var gV,_V,vV,yV,bV,xV,SV,CV,wV,TV,EV,DV,OV,kV,AV,jV,MV,NV=c((()=>{nR(),zI(),oR(),qI(),gV=2,_V=8,vV=4,yV=32,bV=64,xV=4713,SV=4714,CV=32,wV=68,TV={1:1,2:2,3:4,4:8,5:1,6:2,7:4,8:8,9:4,10:8,25:4,26:8,33:1,68:16},EV={0:5,1:1,2:6,3:2,4:7,5:3,6:8,7:4,8:9,9:10,4294967295:wV},DV=65536,OV=65536,kV=(e,t,n)=>n?jI(e,t+8,n)+AI(e,t,n)/2**64:jI(e,t,n)+AI(e,t+8,n)/2**64,AV=4294967295,jV={1:Int8Array,2:Int16Array,3:Int32Array,5:Uint8Array,6:Uint16Array,7:Uint32Array,9:Float32Array,10:Float64Array,25:Float32Array,26:Float64Array,33:Uint8Array},MV={...KI,async plan(e,t){let n=e.companions.find(e=>e.name.toLowerCase().endsWith(`.tdms_index`)),r=[],{objs:i,segments:a}=await pV(t,n?new tR(n):null,r),o=i.find(e=>e.path===`/`)?.props,s=i.filter(e=>e.name&&e.total>0&&(e.type===CV||TV[e.type])),c=new Set(s);for(let e of i)e.name&&e.total>0&&!c.has(e)&&r.push(`${e.name}: TDMS data type ${e.type} is not supported; skipped.`);let l=s.map(e=>e.props.get(`wf_start_time`)).filter(e=>typeof e==`number`),u=l.reduce((e,t)=>Math.min(e,t),l.length?1/0:0),d=new Map;for(let e of s){let t=`${e.total}|${e.props.get(`wf_increment`)??``}`,n=d.get(e.group)??new Map,r=n.get(t);r?r.push(e):n.set(t,[e]),d.set(e.group,n)}let f=[],p=[];for(let[e,t]of d)for(let n of t.values()){let r=n[0].props.get(`wf_increment`),i=typeof r==`number`&&r>0?1/r:null,a=i?null:n.find(e=>e.type===wV)??n.find(e=>e.type!==CV&&/^(time|timestamp|t)$/i.test(e.name))??null,o=n.filter(e=>e!==a),s=n[0].props.get(`wf_start_time`),c=i?Number(n[0].props.get(`wf_start_offset`)??0)+(typeof s==`number`?s-u:0):0;f.push({name:t.size===1?e:`${e} (${i?+i.toFixed(6):n[0].total} ${i?`Hz`:`samples`})`,channels:o.map(e=>({name:e.name,unit:String(e.props.get(`unit_string`)??``),text:e.type===CV})),samples:n[0].total,time:i?{kind:`rate`,rate:i,start:c}:a?{kind:`timestamps`}:{kind:`index`},rateHz:i}),p.push({channels:o,time:a,origin:0})}if(f.length===0)throw Error(`This TDMS file has no channels with data.`);let m=[];for(let e of p){if(!e.time)continue;let n=e.time.pieces[0],r=a[n.seg],i=await t.read(r.rawStart+n.offset,TV[n.type]??8),o=new Float64Array(1);fV(n.type,PI(i),0,0,1,r.le,o,0),m.push(o[0])}let h=m.reduce((e,t)=>Math.min(e,t),m.length?1/0:0);for(let e of p)e.origin=h;let g=new Date(Date.UTC(1904,0,1)+u*1e3),_=u&&Number.isFinite(g.getTime())?g.toISOString():null,v={objs:i,segments:a,groups:p},y={};for(let[e,t]of o??[])typeof t==`string`&&(y[e]=t);return{format:`TDMS`,startTime:_,groups:f,meta:y,events:[],notes:r,state:v}},async*stream(e){for(let t of e.selection)yield*hV(e,t.group)},streamGroup:(e,t)=>hV(e,t)}}));function PV(){let e=new Set,t=0,n=!1;return{enter(t){let r=null;try{r=t.create_reference?Array.prototype.join.call(t.create_reference().ref_data,`,`):null}catch{r=null}return r===null?!0:e.has(r)?(n=!0,!1):(e.add(r),!0)},count:()=>++t<=UV,note:()=>t>1e5?`This file has more than ${UV.toLocaleString(`en-US`)} objects (or links that repeat its groups); only the first were read.`:n?`Some groups of this file link back to a group already read; each was read once.`:null}}function FV(e,t,n,r){return t.reduce((e,t)=>e*t,1)*Math.max(1,e.metadata.size||1)>(r?n*1032+1024:n)}function IV(){!GV||KV||(KV=GV(),KV.catch(()=>{KV=null}))}function LV(e){if(!GV)return Promise.reject(Error(`HDF5 and MAT 7.3 files are read in the import worker, and this environment has no workers.`));IV();let t=qV.get(e);return t||(t=KV.then(t=>t(e)).then(e=>({root:e.root,close:()=>{}})),qV.set(e,t),t.catch(()=>qV.delete(e))),t}function RV(e,t,n){let r=JV.get(e);r||JV.set(e,r=new Map);let i=r.get(t);return i||r.set(t,i=n??e.get(t)),i}function zV(e){return e instanceof Float64Array?e:e instanceof BigInt64Array||e instanceof BigUint64Array?Float64Array.from(e,e=>Number(e)):ArrayBuffer.isView(e)?new Float64Array(e):Float64Array.from(e)}function BV(e,...t){for(let n of t){let t=e[n]?.value;if(typeof t==`string`)return t;if(Array.isArray(t)&&typeof t[0]==`string`)return t[0]}return``}function VV(e,...t){for(let n of t){let t=e[n]?.value,r=typeof t==`number`?t:ArrayBuffer.isView(t)?Number(t[0]):NaN;if(Number.isFinite(r))return r}return null}var HV,UV,WV,GV,KV,qV,JV,YV,XV=c((()=>{HV=e=>!!e&&typeof e.keys==`function`,UV=1e5,WV=e=>!!e&&typeof e.slice==`function`,GV=null,KV=null,qV=new WeakMap,JV=new WeakMap,YV={s:1,sec:1,second:1,seconds:1,ms:.001,msec:.001,us:1e-6,µs:1e-6,ns:1e-9}}));function ZV(e,t,n,r,i,a,o=0){i.set(n,t.attrs);for(let s of t.keys()){if(!a.count())return;let c=n===`/`?`/${s}`:`${n}/${s}`,l=t.get(s);if(HV(l))o<16&&a.enter(l)&&ZV(e,l,c,r,i,a,o+1);else if(WV(l)){let t=RV(e,c,l);r.push({path:c,parent:n,name:s,ds:t,attrs:t.attrs})}}}async function QV(e,t){let n=RV(e,t.path);if(t.col===null)return zV(n.slice([[0,1]]))[0]*t.factor;let r=n.slice([[0,1]]);return Number(r[0][t.col])*t.factor}async function*$V(e,t){let n=e.plan.state.groups[t],r=aR(e,t).map(e=>n.cols[e]),i=await LV(e.files.main);try{let a=n.chunk??0,o=a>0?Math.max(1,Math.min(Math.floor((1<<20)/a),Math.ceil(cH(r.length+1)/a)))*a:cH(r.length+1);for(let a=0;a<n.rows;a+=o){e.signal?.throwIfAborted();let s=Math.min(n.rows,a+o),c=s-a,l=null,u=e=>{let t=RV(i.root,e.path);if(n.kind===`vectors`){let n=t.slice([[a,s]]);if(e.text)return Array.from(n,e=>e==null?null:String(e));let r=zV(n);if(e.factor!==1)for(let t=0;t<c;t++)r[t]*=e.factor;return r}let r=new Float64Array(c);if(n.kind===`matrix`){let n=(t.shape??[0,1])[1],i=l??=t.slice([[a,s],[0,n]]);for(let t=0;t<c;t++)r[t]=Number(i[t*n+e.col])}else{let n=l??=t.slice([[a,s]]);for(let t=0;t<c;t++)r[t]=Number(n[t][e.col])*e.factor}return r},d=null;if(n.time){d=u(n.time);for(let e=0;e<c;e++)d[e]-=n.origin}yield{group:t,time:d,start:a,length:c,columns:r.map(u)}}}finally{i.close()}}var eH,tH,nH,rH,iH,aH,oH,sH,cH,lH,uH=c((()=>{oR(),$I(),XV(),eH=0,tH=1,nH=3,rH=6,iH=new Set([1,2,3,4,5,6]),aH=/^(time|t|timestamps?|.*[_ ]time|time[_ ].*)$/i,oH=[`sampling_rate`,`sample_rate`,`samplerate`,`sampleRate`,`fs`,`Fs`,`rate`],sH=e=>e===`/`?`root`:e.slice(1),cH=e=>Math.max(4096,Math.min(1<<20,Math.floor((8<<20)/(8*Math.max(1,e))))),lH={...QI,async plan(e){let t=await LV(e.main);try{let n=[],r=new Map,i=PV();i.enter(t.root),ZV(t.root,t.root,`/`,n,r,i);let a=[],o=i.note();o&&a.push(o);let s=new Map,c=[],l=0;for(let t of n){let n=t.ds.metadata.shape??[],r=t.ds.metadata.type,i=t.ds.metadata.chunks?t.ds.filters??[]:[],o=i.find(e=>!iH.has(e.id)),u=!o;if(u&&i.length>0&&n.length>0&&n.every(e=>e>0))try{t.ds.slice(n.map(()=>[0,1]))}catch{u=!1}if(!u){a.push(`${t.path}: compressed with a filter Kymoscope cannot read${o?` (${o.name||o.id})`:``}; skipped.`);continue}if(FV(t.ds,n,e.main.size,i.length>0)){a.push(`${t.path}: larger than the file can hold (never written, or damaged); skipped.`);continue}if(n.length===1&&n[0]>1&&(r===eH||r===tH||r===nH)){let e=`${t.parent}|${n[0]}`,r=s.get(e)??{parent:t.parent,n:n[0],leaves:[]};r.leaves.push(t),s.set(e,r)}else if(n.length===2&&n[0]>1&&n[1]<=4096&&(r===eH||r===tH)){let e=VV(t.attrs,...oH);c.push({name:sH(t.path),kind:`matrix`,rows:n[0],rate:e,time:null,origin:0,cols:Array.from({length:n[1]},(e,n)=>({path:t.path,col:n,text:!1,factor:1}))})}else if(n.length===1&&r===rH){let e=(t.ds.metadata.compound_type?.members??[]).flatMap((e,n)=>e.type===eH||e.type===tH?[{path:t.path,col:n,text:!1,factor:1,name:e.name}]:[]),r=e.find(e=>aH.test(e.name));c.push({name:sH(t.path),kind:`compound`,rows:n[0],rate:null,origin:0,time:r??null,cols:e.filter(e=>e!==r)})}else l++}for(let e of s.values()){let t=[...s.values()].filter(t=>t.parent===e.parent).length>1,n=e.leaves.find(e=>BV(e.attrs,`CLASS`)===`DIMENSION_SCALE`)??e.leaves.find(e=>aH.test(e.name)&&e.ds.metadata.type!==nH),i=n?YV[BV(n.attrs,`units`,`unit`,`Units`)]??1:1,a=n?null:VV(r.get(e.parent)??{},...oH);c.push({name:t?`${sH(e.parent)} (${e.n} rows)`:sH(e.parent),kind:`vectors`,rows:e.n,rate:a,origin:0,time:n?{path:n.path,col:null,text:!1,factor:i}:null,cols:e.leaves.filter(e=>e!==n).map(e=>({path:e.path,col:null,text:e.ds.metadata.type===nH,factor:1}))})}l&&a.push(`${l} dataset${l===1?``:`s`} with other shapes or types (images, references, 3-D) skipped.`),c.sort((e,t)=>e.name.localeCompare(t.name));let u=c.map((e,t)=>e.time||e.rate?t:-1).filter(e=>e>=0),d=1/0;for(let e of c)e.time&&(d=Math.min(d,await QV(t.root,e.time)));for(let e of c)e.origin=Number.isFinite(d)?d:0;let f=new Map(n.map(e=>[e.path,e]));for(let e of c)e.chunk=[...e.cols,...e.time?[e.time]:[]].reduce((e,t)=>Math.max(e,f.get(t.path).ds.metadata.chunks?.[0]??0),0);let p=e=>BV(f.get(e.path).attrs,`units`,`unit`,`Units`,`UNITS`),m=(e,t)=>e.kind===`matrix`?`${e.name.split(`/`).pop()}[${t.col+1}]`:e.kind===`compound`?f.get(t.path).ds.metadata.compound_type.members[t.col].name:t.path.split(`/`).pop(),h=c.map(e=>({name:e.name,channels:e.cols.map(t=>({name:m(e,t),unit:e.kind===`vectors`?p(t):``,text:t.text})),samples:e.rows,time:e.time?{kind:`timestamps`}:e.rate?{kind:`rate`,rate:e.rate,start:0}:{kind:`index`},rateHz:e.rate}));if(h.length===0)throw Error(`This HDF5 file has no datasets Kymoscope can plot.`);let g=h.length>20||h.length>1&&u.length<h.length,_=g?u.length?u:[c.reduce((e,t,n)=>t.rows*t.cols.length>c[e].rows*c[e].cols.length?n:e,0)]:void 0;return g&&a.push(`Only the groups with a time base are read unless you choose others in the channel picker.`),{format:`HDF5`,startTime:null,groups:h,meta:{},events:[],notes:a,pick:g,defaultGroups:_,state:{groups:c}}}finally{t.close()}},async*stream(e){for(let t of e.selection)yield*$V(e,t.group)},streamGroup:(e,t)=>$V(e,t)}}));function dH(e,t){let n=/^(.*)\.values(\[\d+\])?$/.exec(e.name),r=n&&(t.get(`${n[1]}.label`)||t.get(`${n[1]}.blockName`));return r?{...e,name:`${r}${n[2]??``}`}:e}function fH(e,t,n){let r=new Map;for(let t of e){if(!(t.length>1))continue;let e=r.get(t.length);e?e.push(t):r.set(t.length,[t])}let i=[...n].filter(([e])=>gH.test(_H(e))),a=i.length===1?i[0][1]:null,o=[];for(let[e,n]of r){let r=n.find(e=>hH.test(_H(e.name))||/(_time|\.Time)$/.test(e.name))??null;o.push({name:r?vH(r.name)||r.name:`${e} samples`,channels:n.filter(e=>e!==r).map(e=>dH(e,t)),time:r,rate:r?null:a,origin:0})}return o}function pH(e){return e.map(e=>({name:e.name,channels:e.channels.map(e=>({name:e.name,unit:``})),samples:e.channels[0]?.length??e.time?.length??0,time:e.time?{kind:`timestamps`}:e.rate?{kind:`rate`,rate:e.rate,start:0}:{kind:`index`},rateHz:e.rate}))}async function mH(e){let t=1/0;for(let n of e)n.time&&(t=Math.min(t,(await n.time.read(0,1))[0]));for(let n of e)n.origin=Number.isFinite(t)?t:0}var hH,gH,_H,vH,yH=c((()=>{hH=/^(time|t|tout|timestamps?)$/i,gH=/^(fs|sample_?rate|sampling_?rate|rate|samplerate)$/i,_H=e=>e.slice(e.lastIndexOf(`.`)+1),vH=e=>e.includes(`.`)?e.slice(0,e.lastIndexOf(`.`)):``}));function bH(e,t,n,r,i=1){let a=PI(t),o=r.length,s=DH[e]*i;if(e===9&&i===1&&n){r.set(t.byteOffset%8==0?new Float64Array(t.buffer,t.byteOffset,o):new Float64Array(t.slice(0,o*8).buffer));return}switch(e){case 1:for(let e=0,t=0;e<o;e++,t+=s)r[e]=a.getInt8(t);return;case 2:for(let e=0,t=0;e<o;e++,t+=s)r[e]=a.getUint8(t);return;case 3:for(let e=0,t=0;e<o;e++,t+=s)r[e]=a.getInt16(t,n);return;case 4:for(let e=0,t=0;e<o;e++,t+=s)r[e]=a.getUint16(t,n);return;case 5:for(let e=0,t=0;e<o;e++,t+=s)r[e]=a.getInt32(t,n);return;case 6:for(let e=0,t=0;e<o;e++,t+=s)r[e]=a.getUint32(t,n);return;case 7:for(let e=0,t=0;e<o;e++,t+=s)r[e]=a.getFloat32(t,n);return;case 9:for(let e=0,t=0;e<o;e++,t+=s)r[e]=a.getFloat64(t,n);return;case 12:for(let e=0,t=0;e<o;e++,t+=s)r[e]=a.getInt32(t+(n?4:0),n)*4294967296+a.getUint32(t+(n?0:4),n);return;case 13:for(let e=0,t=0;e<o;e++,t+=s)r[e]=a.getUint32(t+(n?4:0),n)*4294967296+a.getUint32(t+(n?0:4),n);return;default:r.fill(NaN)}}async function xH(e,t,n){let r=PI(await e.read(t,8)),i=r.getUint32(0,n);if(i>>>16)return{type:i&65535,bytes:i>>>16,data:t+4,next:t+8};let a=r.getUint32(4,n);return{type:i,bytes:a,data:t+8,next:i===15?t+8+a:t+8+a+(8-a%8)%8}}function SH(e,t,n,r,i){let[a,o]=t,s=DH[r.type];if(!s)return[];let c=(e,t)=>async(a,o)=>{let c=new Float64Array(o-a);return t===1?bH(r.type,await n.read(r.data+(e+a)*s,(o-a)*s),i,c):bH(r.type,await n.read(r.data+(e+a*t)*s,((o-a-1)*t+1)*s),i,c,t),c};return a===1||o===1?[{name:e,length:a*o,read:c(0,1)}]:a>=o?Array.from({length:o},(t,n)=>({name:`${e}[${n+1}]`,length:a,read:c(n*a,1)})):Array.from({length:a},(t,n)=>({name:`${e}[${n+1}]`,length:o,read:c(n,a)}))}async function CH(e,t,n,r,i,a,o){let s=t,c=await xH(e,s,n),l=PI(await e.read(c.data,8)).getUint32(0,n),u=l&255;s=c.next;let d=await xH(e,s,n);if(d.bytes>128){a.notes.push(`A MAT variable with more than 32 dimensions was skipped (damaged).`);return}let f=PI(await e.read(d.data,d.bytes)),p=Array.from({length:d.bytes/4},(e,t)=>f.getInt32(4*t,n));s=d.next;let m=await xH(e,s,n),h=LI(await e.read(m.data,m.bytes));s=m.next;let g=i??h,_=r?`${r}.${g}`:g,v=p.reduce((e,t)=>e*t,1);if(u>=6&&u<=15){if(v===0)return;let t=await xH(e,s,n);if(l&2048&&a.notes.push(`${_}: the imaginary part was skipped.`),p.length>2){a.notes.push(`${_}: arrays with more than two dimensions are skipped.`);return}if(!DH[t.type])return;if(!(v>0)||v*DH[t.type]>t.bytes||t.data+t.bytes>e.size){a.notes.push(`${_}: its data is shorter than its dimensions (damaged); skipped.`);return}if(v===1){let r=new Float64Array(1);bH(t.type,await e.read(t.data,DH[t.type]??8),n,r),a.scalars.set(_,r[0]);return}a.channels.push(...SH(_,p,e,t,n));return}if(u===4){let t=await xH(e,s,n);if(t.bytes>OH)return;let r=await e.read(t.data,t.bytes),i=t.type===3||t.type===4||t.type===17?new TextDecoder(n?`utf-16le`:`utf-16be`).decode(r.subarray(0,r.length&-2)):RI(r);p[0]<=1&&a.strings.set(_,i);return}if(u===2){let t=await xH(e,s,n),r=PI(await e.read(t.data,4)).getInt32(0,n);s=t.next;let i=await xH(e,s,n);if(!(r>0))return;let c=await e.read(i.data,i.bytes),l=Array.from({length:Math.floor(c.length/r)},(e,t)=>MI(c.subarray(t*r,(t+1)*r)));if(s=i.next,l.length===0||v*l.length*8>e.size-s){v>0&&l.length>0&&a.notes.push(`${_}: its fields are longer than the file (damaged); skipped.`);return}for(let t=0;t<v;t++){let r=v>1?`${_}(${t+1})`:_;for(let t of l){let i=await xH(e,s,n);i.type===14&&i.bytes>0&&o<16&&await CH(e,i.data,n,r,t,a,o+1),s=i.next}}return}u===1?a.notes.push(`${_}: cell arrays are skipped.`):u===5?a.notes.push(`${_}: sparse arrays are skipped.`):a.notes.includes(kH)||a.notes.push(kH)}async function wH(e){let t=LI((await e.read(0,128)).subarray(126,128))===`IM`,n={channels:[],strings:new Map,scalars:new Map,notes:[],sources:[]},r=new TH(e),i=0;for(let a=128;a+8<=e.size;){let o=await xH(r,a,t);if(o.type===15){if(o.bytes>1<<30)throw Error(`A compressed variable in this MAT file is over 1 GB; save it with -v7.3 to open it here.`);let r=await e.slice(o.data,o.bytes),a=await Fz(r,-1,8),s=a.length<8?0:8+PI(a).getUint32(4,t);if(s>vL(o.bytes))throw Error(`A compressed variable in this MAT file is damaged.`);if(s>1<<30)throw Error(`A compressed variable in this MAT file is over 1 GB; save it with -v7.3 to open it here.`);let c=await Fz(r,s,s),l=new EH(e,o.data,o.bytes,c);n.sources.push(l),i+=c.length;let u=await xH(l,0,t);if(u.type===14&&await CH(l,u.data,t,``,null,n,0),i>AH)for(let e of n.sources)e.keep=!1,e.release()}else o.type===14&&await CH(r,o.data,t,``,null,n,0);a=o.next}return n}var TH,EH,DH,OH,kH,AH,jH=c((()=>{zI(),TL(),Rz(),TH=class{#e;size;constructor(e){this.#e=e,this.size=e.size}read(e,t){return t>=65536?this.#e.slice(e,t):this.#e.read(e,t)}release(){}},EH=class{#e;#t;#n;#r=null;keep=!0;size;constructor(e,t,n,r){this.#e=e,this.#t=t,this.#n=n,this.#r=r,this.size=r.length}async read(e,t){return this.#r??=await Fz(await this.#e.slice(this.#t,this.#n),this.size,this.size),this.#r.subarray(e,e+t)}release(){this.keep||(this.#r=null)}},DH={1:1,2:1,3:2,4:2,5:4,6:4,7:4,9:8,12:8,13:8},OH=1<<17,kH=`MATLAB objects (timeseries, SimulationOutput) were skipped: save them as 'Structure with time' or as structs.`,AH=512<<20}));function MH(e,t){let n={channels:[],strings:new Map,scalars:new Map,notes:[]},r=PV();r.enter(e);let i=t=>RV(e,t),a=(e,t,n)=>{let r=null;return(a,o)=>((r?.s!==a||r.e!==o)&&(r={s:a,e:o,v:zV(t?i(e).slice([[0,n],[a,o]]):i(e).slice([[a,o],[0,n]]))}),r.v)},o=(e,s,c,l)=>{for(let u of e.keys()){if(!r.count())return;if(u.startsWith(`#`))continue;let d=e.get(u);if(!d)continue;let f=`${s}/${u}`,p=c?`${c}.${u}`:u,m=d.attrs,h=BV(m,`MATLAB_class`);if(m.MATLAB_empty)continue;if(HV(d)){h===`struct`&&l<16&&r.enter(d)&&o(d,f,p,l+1);continue}if(!WV(d))continue;let g=d.shape??[];if(h===`char`){if(g.reduce((e,t)=>e*t,1)>NH)continue;let e=zV(d.slice(g.map(e=>[0,e])));n.strings.set(p,new TextDecoder(`utf-16le`).decode(Uint16Array.from(e)))}else if(PH.has(h)&&g.length===2&&FV(d,g,t,!!d.metadata.chunks))n.notes.push(`${p}: larger than the file can hold (never written, or damaged); skipped.`);else if(PH.has(h)&&g.length===2){let[e,t]=g;if(e*t===1){n.scalars.set(p,zV(i(f).slice([[0,1],[0,1]]))[0]);continue}if(e===1||t===1){let r=e*t;n.channels.push({name:p,length:r,read:async(t,n)=>zV(e===1?i(f).slice([[0,1],[t,n]]):i(f).slice([[t,n],[0,1]]))})}else if(t>=e){let r=a(f,!0,e);for(let i=0;i<e;i++)n.channels.push({name:`${p}[${i+1}]`,length:t,read:async(e,t)=>r(e,t).slice(i*(t-e),(i+1)*(t-e))})}else{let r=a(f,!1,t);for(let i=0;i<t;i++)n.channels.push({name:`${p}[${i+1}]`,length:e,read:async(e,n)=>{let a=r(e,n),o=new Float64Array(n-e);for(let e=0;e<o.length;e++)o[e]=a[e*t+i];return o}})}}else h===`cell`?n.notes.push(`${p}: cell arrays are skipped.`):h&&n.notes.push(`${p}: MATLAB class ${h} is skipped.`)}};o(e,``,``,0);let s=r.note();return s&&n.notes.push(s),n}var NH,PH,FH=c((()=>{XV(),NH=65536,PH=new Set([`double`,`single`,`int8`,`uint8`,`int16`,`uint16`,`int32`,`uint32`,`int64`,`uint64`,`logical`])}));async function*IH(e,t){let n=e.plan.state,r=n.groups[t],i=aR(e,t).map(e=>r.channels[e]),a=r.channels[0].length,o=LH(i.length+1);try{for(let n=0;n<a;n+=o){e.signal?.throwIfAborted();let s=Math.min(a,n+o),c=null;if(r.time){c=await r.time.read(n,s);for(let e=0;e<c.length;e++)c[e]-=r.origin}let l=[];for(let e of i)l.push(await e.read(n,s));yield{group:t,time:c,start:n,length:s-n,columns:l}}}finally{for(let e of n.sources)e.release()}}var LH,RH,zH=c((()=>{zI(),XV(),oR(),YI(),yH(),jH(),FH(),LH=e=>Math.max(4096,Math.min(1<<18,Math.floor((16<<20)/(8*Math.max(1,e))))),RH={...JI,async plan(e,t){let n=NI(await t.read(0,20),`MATLAB 7.3`),r,i=[];if(n)r=MH((await LV(e.main)).root,e.main.size);else{let e=await wH(t);i=e.sources,r=e}let a=fH(r.channels,r.strings,r.scalars).filter(e=>e.channels.length>0);await mH(a);let o=pH(a);if(o.length===0)throw Error(`This MAT file has no numeric vectors or matrices to plot.`);let s=o.flatMap((e,t)=>e.time.kind===`index`?[]:[t]),c=o.length>1&&s.length<o.length,l=Object.fromEntries(r.strings);for(let[e,t]of r.scalars)l[e]=String(t);return{format:n?`MAT 7.3`:`MAT 5`,startTime:null,groups:o,meta:l,events:[],notes:r.notes,pick:c,defaultGroups:c&&s.length?s:void 0,state:{groups:a,sources:i}}},async*stream(e){for(let t of e.selection)yield*IH(e,t.group)},streamGroup:(e,t)=>IH(e,t)}}));function BH(e,t){let n=/^\s*(\d{1,2})\/(\d{1,2})\/(\d{2,4})\s*,\s*(\d{1,2}):(\d{2}):(\d{2})(?:\.(\d+))?/.exec(e??``);if(!n)return[null,0,!1];let[r,i]=t===1991?[n[2],n[1]]:[n[1],n[2]],a=n[3].length===2?2e3+Number(n[3]):Number(n[3]),o=Number(`${n[6]}.${n[7]??`0`}`);return[`${a}-${i.padStart(2,`0`)}-${r.padStart(2,`0`)}T${n[4].padStart(2,`0`)}:${n[5]}:${o.toFixed(3).padStart(6,`0`)}`,Date.UTC(a,Number(i)-1,Number(r),Number(n[4]),Number(n[5]))/1e3+o,(n[7]??``).length>6]}function VH(e){let t=e.split(/\r?\n/).map(e=>e.trim()),[n,,r]=t[0].split(`,`),i=Number(r)||1991,a=/(\d+)A\s*,\s*(\d+)D/i.exec(t[1]??``);if(!a)throw Error(`This COMTRADE .cfg is damaged (second line).`);let o=Number(a[1]),s=Number(a[2]);if(o+s>t.length)throw Error(`This COMTRADE .cfg is damaged (more channels than lines).`);let c=2,l=[];for(let e=0;e<o;e++,c++){let e=(t[c]??``).split(`,`);l.push({name:(e[1]??``).trim(),unit:(e[4]??``).trim(),a:Number(e[5]),b:Number(e[6]??0)||0})}let u=[];for(let e=0;e<s;e++,c++)u.push(((t[c]??``).split(`,`)[1]??``).trim());c++;let d=Number(t[c++]);if(!(Number.isInteger(d)&&d>=0&&d<=t.length-c))throw Error(`This COMTRADE .cfg is damaged (sample rates).`);let f=[];for(let e=0;e<Math.max(1,d);e++,c++){let[e,n]=(t[c]??``).split(`,`).map(Number);f.push([d===0?0:e,n])}let[p,m,h]=BH(t[c++],i),[g,_,v]=BH(t[c++],i),y=(t[c++]||`ASCII`).toUpperCase(),b=Number(t[c++])||1;return{station:n.trim(),rev:i,analog:l,digital:u,rates:f,start:p,trigger:g,startSec:m,triggerSec:_,ft:y,timemult:b,timebase:h||v?1e-9:1e-6}}async function HH(e){let t=LI(await e.read(0,Math.min(e.size,1<<20))),n=t.search(/---\s*file type:\s*CFG\s*---\r?\n/i),r=/---\s*file type:\s*DAT\s+(ASCII|BINARY32|BINARY|FLOAT32)(?:\s*:\s*(\d+))?\s*---\r?\n/i.exec(t);if(n<0||!r)throw Error(`This COMTRADE .cff is damaged (no CFG or DAT section in its first megabyte).`);let i=t.indexOf(`
|
|
78
78
|
`,n)+1,a=t.slice(i).search(/---\s*file type:\s*(INF|HDR|DAT)/i),o=t.slice(i,a<0?void 0:i+a),s=r.index+r[0].length;return{cfg:o,offset:s,length:r[2]?Number(r[2]):e.size-s}}function UH(e,t,n,r){let i=0,a=0,o=t,s=0;for(let[t,c]of e){for(;o<c&&s<n;)r[s++]=a+(o-i)/t,o++;if(a+=(c-i)/t,i=c,s>=n)return}let c=e[e.length-1];for(;s<n;s++,o++)r[s]=a+(o-i)/c[0]}async function*WH(e){let t=e.plan.state,{cfg:n}=t,r=t.data===`self`?e.io:new tR(qH(e.files)),i=aR(e,0),a=n.analog.length,o=n.rates[0][0]>0,s=n.timemult*n.timebase,c=65536,l=0,u=(e,t,r)=>{let i=new Float64Array(e);if(o)UH(n.rates,l,e,i);else for(let n=0;n<e;n++)i[n]=t[n]*s;let a={group:0,time:i,start:l,length:e,columns:r};return l+=e,a};if(n.ft===`ASCII`){let o=n.rev>=1999?`99999`:``,s=i.map(e=>e<a?n.analog[e]:null),l=new Float64Array(c),d=i.map(()=>new Float64Array(c)),f=0,p=(e,t,n)=>{let r=e.slice(t,n).split(`,`);if(!(r.length<2)){l[f]=Number(r[1]);for(let e=0;e<i.length;e++){let t=(r[2+i[e]]??``).trim(),n=s[e];d[e][f]=t===``||n&&t===o?NaN:n?n.a*Number(t)+n.b:Number(t)}f++}},m=``,h=new TextDecoder(`latin1`);for await(let n of r.windows(t.offset,t.length)){e.signal?.throwIfAborted();let t=m+h.decode(n.bytes),r=0;for(let e=t.indexOf(`
|
|
79
79
|
`,r);e>=0;e=t.indexOf(`
|
|
80
|
-
`,r))p(t,r,e),r=e+1,f===c&&(yield u(f,l,d),l=new Float64Array(c),d=i.map(()=>new Float64Array(c)),f=0);m=t.slice(r)}m.trim()&&p(m,0,m.length),f&&(yield u(f,l.slice(0,f),d.map(e=>e.slice(0,f))));return}let d=t.recordSize,f=GH[n.ft],p=Math.max(1,Math.floor(Math.min(eR,c*d)/d)),m=t.samples;for await(let s of r.windows(t.offset,Math.min(t.length,t.samples*d),p*d)){e.signal?.throwIfAborted();let t=Math.min(m,Math.floor(s.bytes.length/d));if(t<=0)break;let r=PI(s.bytes),c=new Float64Array(t);if(!o)for(let e=0;e<t;e++)c[e]=r.getUint32(e*d+4,!0);yield u(t,c,i.map(e=>{let i=new Float64Array(t);if(e<a){let{a,b:o}=n.analog[e],s=8+e*f;if(n.ft===`BINARY`)for(let e=0,n=s;e<t;e++,n+=d){let t=r.getInt16(n,!0);i[e]=t===-32768?NaN:a*t+o}else if(n.ft===`BINARY32`)for(let e=0,n=s;e<t;e++,n+=d){let t=r.getInt32(n,!0);i[e]=t===-2147483648?NaN:a*t+o}else for(let e=0,n=s;e<t;e++,n+=d)i[e]=a*r.getFloat32(n,!0)+o}else{let n=e-a,o=8+a*f+2*(n>>4),s=1<<(n&15);for(let e=0,n=o;e<t;e++,n+=d)i[e]=r.getUint16(n,!0)&s?1:0}return i})),m-=t}}var GH,KH,qH,JH,YH=c((()=>{nR(),zI(),oR(),tL(),GH={BINARY:2,BINARY32:4,FLOAT32:4},KH=16<<20,qH=e=>e.companions.find(e=>e.name.toLowerCase().endsWith(`.dat`)),JH={...eL,async plan(e,t){let n=e.main.name.toLowerCase().endsWith(`.cff`),r,i;if(n){let e=await HH(t);r=e.cfg,i={data:`self`,offset:e.offset,length:e.length}}else{let n=qH(e);if(!n)throw Error(`This COMTRADE .cfg needs its .dat file: drop both together.`);if(t.size>KH)throw Error(`This .cfg is too large to be a COMTRADE configuration file.`);r=LI(await t.read(0,t.size)),i={data:`companion`,offset:0,length:n.size}}let a=VH(r);if(a.ft!==`ASCII`&&!GH[a.ft])throw Error(`This COMTRADE file has data file type ${a.ft}, which Kymoscope cannot read.`);let o=Math.ceil(a.digital.length/16),s=a.ft===`ASCII`?0:8+a.analog.length*GH[a.ft]+2*o,c=s?Math.floor(i.length/s):i.length,l=Math.min(a.rates[a.rates.length-1][1]||(s?c:-1),c),u=a.rates.length===1&&a.rates[0][0]>0?a.rates[0][0]:null,d=[`Analog values are shown as recorded (primary or secondary, per the CFG).`];return{format:`COMTRADE ${a.rev} (${a.ft})`,startTime:a.start,meta:{station:a.station,trigger:a.trigger??``},groups:[{name:a.station||`COMTRADE`,channels:[...a.analog.map(e=>({name:e.name,unit:e.unit})),...a.digital.map(e=>({name:e,unit:``}))],samples:l,time:{kind:`timestamps`},rateHz:u}],events:a.start&&a.trigger?[{time:Math.round((a.triggerSec-a.startSec)*1e6)/1e6,text:`Trigger`}]:[],notes:d,state:{...i,cfg:a,samples:l,recordSize:s}}},stream:e=>WH(e)}}));function XH(e,t,n){let r=t,i=r+n,a=[],o=``;for(;r<i;){let t=e[r++];if(!(t&128))a.push(t);else if((t&224)==192){let n=e[r++]&63;a.push((t&31)<<6|n)}else if((t&240)==224){let n=e[r++]&63,i=e[r++]&63;a.push((t&31)<<12|n<<6|i)}else if((t&248)==240){let n=e[r++]&63,i=e[r++]&63,o=e[r++]&63,s=(t&7)<<18|n<<12|i<<6|o;s>65535&&(s-=65536,a.push(s>>>10&1023|55296),s=56320|s&1023),a.push(s)}else a.push(t);a.length>=$H&&(o+=String.fromCharCode(...a),a.length=0)}return a.length>0&&(o+=String.fromCharCode(...a)),o}function ZH(e,t,n){let r=e.subarray(t,t+n);return eU.decode(r)}function QH(e,t,n){return n>tU?ZH(e,t,n):XH(e,t,n)}var $H,eU,tU,nU=c((()=>{new TextEncoder,$H=4096,eU=new TextDecoder,tU=200})),rU,iU=c((()=>{rU=class{type;data;constructor(e,t){this.type=e,this.data=t}}})),aU,oU=c((()=>{aU=class e extends Error{constructor(t){super(t);let n=Object.create(e.prototype);Object.setPrototypeOf(this,n),Object.defineProperty(this,`name`,{configurable:!0,enumerable:!1,value:e.name})}}}));function sU(e,t,n){let r=Math.floor(n/4294967296),i=n;e.setUint32(t,r),e.setUint32(t+4,i)}function cU(e,t){let n=e.getInt32(t),r=e.getUint32(t+4);return n*4294967296+r}function lU(e,t){let n=e.getUint32(t),r=e.getUint32(t+4);return n*4294967296+r}var uU=c((()=>{}));function dU({sec:e,nsec:t}){if(e>=0&&t>=0&&e<=_U)if(t===0&&e<=gU){let t=new Uint8Array(4);return new DataView(t.buffer).setUint32(0,e),t}else{let n=e/4294967296,r=e&4294967295,i=new Uint8Array(8),a=new DataView(i.buffer);return a.setUint32(0,t<<2|n&3),a.setUint32(4,r),i}else{let n=new Uint8Array(12),r=new DataView(n.buffer);return r.setUint32(0,t),sU(r,4,e),n}}function fU(e){let t=e.getTime(),n=Math.floor(t/1e3),r=(t-n*1e3)*1e6,i=Math.floor(r/1e9);return{sec:n+i,nsec:r-i*1e9}}function pU(e){return e instanceof Date?dU(fU(e)):null}function mU(e){let t=new DataView(e.buffer,e.byteOffset,e.byteLength);switch(e.byteLength){case 4:return{sec:t.getUint32(0),nsec:0};case 8:{let e=t.getUint32(0),n=t.getUint32(4);return{sec:(e&3)*4294967296+n,nsec:e>>>2}}case 12:return{sec:cU(t,4),nsec:t.getUint32(0)};default:throw new aU(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${e.length}`)}}function hU(e){let t=mU(e);return new Date(t.sec*1e3+t.nsec/1e6)}var gU,_U,vU,yU=c((()=>{oU(),uU(),gU=4294967295,_U=17179869183,vU={type:-1,encode:pU,decode:hU}})),bU,xU=c((()=>{iU(),yU(),bU=class e{static defaultCodec=new e;__brand;builtInEncoders=[];builtInDecoders=[];encoders=[];decoders=[];constructor(){this.register(vU)}register({type:e,encode:t,decode:n}){if(e>=0)this.encoders[e]=t,this.decoders[e]=n;else{let r=-1-e;this.builtInEncoders[r]=t,this.builtInDecoders[r]=n}}tryToEncode(e,t){for(let n=0;n<this.builtInEncoders.length;n++){let r=this.builtInEncoders[n];if(r!=null){let i=r(e,t);if(i!=null)return new rU(-1-n,i)}}for(let n=0;n<this.encoders.length;n++){let r=this.encoders[n];if(r!=null){let i=r(e,t);if(i!=null)return new rU(n,i)}}return e instanceof rU?e:null}decode(e,t,n){let r=t<0?this.builtInDecoders[-1-t]:this.decoders[t];return r?r(e,t,n):new rU(t,e)}}}));function SU(e){return e instanceof ArrayBuffer||typeof SharedArrayBuffer<`u`&&e instanceof SharedArrayBuffer}function CU(e){return e instanceof Uint8Array?e:ArrayBuffer.isView(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):SU(e)?new Uint8Array(e):Uint8Array.from(e)}var wU=c((()=>{}));function TU(e){return`${e<0?`-`:``}0x${Math.abs(e).toString(16).padStart(2,`0`)}`}var EU=c((()=>{})),DU,OU,kU,AU=c((()=>{nU(),DU=16,OU=16,kU=class{hit=0;miss=0;caches;maxKeyLength;maxLengthPerKey;constructor(e=DU,t=OU){this.maxKeyLength=e,this.maxLengthPerKey=t,this.caches=[];for(let e=0;e<this.maxKeyLength;e++)this.caches.push([])}canBeCached(e){return e>0&&e<=this.maxKeyLength}find(e,t,n){let r=this.caches[n-1];FIND_CHUNK:for(let i of r){let r=i.bytes;for(let i=0;i<n;i++)if(r[i]!==e[t+i])continue FIND_CHUNK;return i.str}return null}store(e,t){let n=this.caches[e.length-1],r={bytes:e,str:t};n.length>=this.maxLengthPerKey?n[Math.random()*n.length|0]=r:n.push(r)}decode(e,t,n){let r=this.find(e,t,n);if(r!=null)return this.hit++,r;this.miss++;let i=XH(e,t,n),a=Uint8Array.prototype.slice.call(e,t,t+n);return this.store(a,i),i}}})),jU,MU,NU,PU,FU,IU,LU,RU,zU,BU,VU,HU=c((()=>{EU(),xU(),uU(),nU(),wU(),AU(),oU(),jU=`array`,MU=`map_key`,NU=`map_value`,PU=e=>{if(typeof e==`string`||typeof e==`number`)return e;throw new aU(`The type of key must be string or number but `+typeof e)},FU=class{stack=[];stackHeadPosition=-1;get length(){return this.stackHeadPosition+1}top(){return this.stack[this.stackHeadPosition]}pushArrayState(e){let t=this.getUninitializedStateFromPool();t.type=jU,t.position=0,t.size=e,t.array=Array(e)}pushMapState(e){let t=this.getUninitializedStateFromPool();t.type=MU,t.readCount=0,t.size=e,t.map={}}getUninitializedStateFromPool(){return this.stackHeadPosition++,this.stackHeadPosition===this.stack.length&&this.stack.push({type:void 0,size:0,array:void 0,position:0,readCount:0,map:void 0,key:null}),this.stack[this.stackHeadPosition]}release(e){if(this.stack[this.stackHeadPosition]!==e)throw Error(`Invalid stack state. Released state is not on top of the stack.`);if(e.type===jU){let t=e;t.size=0,t.array=void 0,t.position=0,t.type=void 0}if(e.type===MU||e.type===NU){let t=e;t.size=0,t.map=void 0,t.readCount=0,t.type=void 0}this.stackHeadPosition--}reset(){this.stack.length=0,this.stackHeadPosition=-1}},IU=-1,LU=new DataView(new ArrayBuffer(0)),RU=new Uint8Array(LU.buffer);try{LU.getInt8(0)}catch(e){if(!(e instanceof RangeError))throw Error(`This module is not supported in the current JavaScript engine because DataView does not throw RangeError on out-of-bounds access`)}zU=RangeError(`Insufficient data`),BU=new kU,VU=class e{extensionCodec;context;useBigInt64;rawStrings;maxStrLength;maxBinLength;maxArrayLength;maxMapLength;maxExtLength;keyDecoder;mapKeyConverter;totalPos=0;pos=0;view=LU;bytes=RU;headByte=IU;stack=new FU;entered=!1;constructor(e){this.extensionCodec=e?.extensionCodec??bU.defaultCodec,this.context=e?.context,this.useBigInt64=e?.useBigInt64??!1,this.rawStrings=e?.rawStrings??!1,this.maxStrLength=e?.maxStrLength??4294967295,this.maxBinLength=e?.maxBinLength??4294967295,this.maxArrayLength=e?.maxArrayLength??4294967295,this.maxMapLength=e?.maxMapLength??4294967295,this.maxExtLength=e?.maxExtLength??4294967295,this.keyDecoder=e?.keyDecoder===void 0?BU:e.keyDecoder,this.mapKeyConverter=e?.mapKeyConverter??PU}clone(){return new e({extensionCodec:this.extensionCodec,context:this.context,useBigInt64:this.useBigInt64,rawStrings:this.rawStrings,maxStrLength:this.maxStrLength,maxBinLength:this.maxBinLength,maxArrayLength:this.maxArrayLength,maxMapLength:this.maxMapLength,maxExtLength:this.maxExtLength,keyDecoder:this.keyDecoder})}reinitializeState(){this.totalPos=0,this.headByte=IU,this.stack.reset()}setBuffer(e){let t=CU(e);this.bytes=t,this.view=new DataView(t.buffer,t.byteOffset,t.byteLength),this.pos=0}appendBuffer(e){if(this.headByte===IU&&!this.hasRemaining(1))this.setBuffer(e);else{let t=this.bytes.subarray(this.pos),n=CU(e),r=new Uint8Array(t.length+n.length);r.set(t),r.set(n,t.length),this.setBuffer(r)}}hasRemaining(e){return this.view.byteLength-this.pos>=e}createExtraByteError(e){let{view:t,pos:n}=this;return RangeError(`Extra ${t.byteLength-n} of ${t.byteLength} byte(s) found at buffer[${e}]`)}decode(e){if(this.entered)return this.clone().decode(e);try{this.entered=!0,this.reinitializeState(),this.setBuffer(e);let t=this.doDecodeSync();if(this.hasRemaining(1))throw this.createExtraByteError(this.pos);return t}finally{this.entered=!1}}*decodeMulti(e){if(this.entered){yield*this.clone().decodeMulti(e);return}try{for(this.entered=!0,this.reinitializeState(),this.setBuffer(e);this.hasRemaining(1);)yield this.doDecodeSync()}finally{this.entered=!1}}async decodeAsync(e){if(this.entered)return this.clone().decodeAsync(e);try{this.entered=!0;let t=!1,n;for await(let r of e){if(t)throw this.entered=!1,this.createExtraByteError(this.totalPos);this.appendBuffer(r);try{n=this.doDecodeSync(),t=!0}catch(e){if(!(e instanceof RangeError))throw e}this.totalPos+=this.pos}if(t){if(this.hasRemaining(1))throw this.createExtraByteError(this.totalPos);return n}let{headByte:r,pos:i,totalPos:a}=this;throw RangeError(`Insufficient data in parsing ${TU(r)} at ${a} (${i} in the current buffer)`)}finally{this.entered=!1}}decodeArrayStream(e){return this.decodeMultiAsync(e,!0)}decodeStream(e){return this.decodeMultiAsync(e,!1)}async*decodeMultiAsync(e,t){if(this.entered){yield*this.clone().decodeMultiAsync(e,t);return}try{this.entered=!0;let n=t,r=-1;for await(let i of e){if(t&&r===0)throw this.createExtraByteError(this.totalPos);this.appendBuffer(i),n&&(r=this.readArraySize(),n=!1,this.complete());try{for(;yield this.doDecodeSync(),--r!==0;);}catch(e){if(!(e instanceof RangeError))throw e}this.totalPos+=this.pos}}finally{this.entered=!1}}doDecodeSync(){DECODE:for(;;){let e=this.readHeadByte(),t;if(e>=224)t=e-256;else if(e<192)if(e<128)t=e;else if(e<144){let n=e-128;if(n!==0){this.pushMapState(n),this.complete();continue DECODE}else t={}}else if(e<160){let n=e-144;if(n!==0){this.pushArrayState(n),this.complete();continue DECODE}else t=[]}else{let n=e-160;t=this.decodeString(n,0)}else if(e===192)t=null;else if(e===194)t=!1;else if(e===195)t=!0;else if(e===202)t=this.readF32();else if(e===203)t=this.readF64();else if(e===204)t=this.readU8();else if(e===205)t=this.readU16();else if(e===206)t=this.readU32();else if(e===207)t=this.useBigInt64?this.readU64AsBigInt():this.readU64();else if(e===208)t=this.readI8();else if(e===209)t=this.readI16();else if(e===210)t=this.readI32();else if(e===211)t=this.useBigInt64?this.readI64AsBigInt():this.readI64();else if(e===217){let e=this.lookU8();t=this.decodeString(e,1)}else if(e===218){let e=this.lookU16();t=this.decodeString(e,2)}else if(e===219){let e=this.lookU32();t=this.decodeString(e,4)}else if(e===220){let e=this.readU16();if(e!==0){this.pushArrayState(e),this.complete();continue DECODE}else t=[]}else if(e===221){let e=this.readU32();if(e!==0){this.pushArrayState(e),this.complete();continue DECODE}else t=[]}else if(e===222){let e=this.readU16();if(e!==0){this.pushMapState(e),this.complete();continue DECODE}else t={}}else if(e===223){let e=this.readU32();if(e!==0){this.pushMapState(e),this.complete();continue DECODE}else t={}}else if(e===196){let e=this.lookU8();t=this.decodeBinary(e,1)}else if(e===197){let e=this.lookU16();t=this.decodeBinary(e,2)}else if(e===198){let e=this.lookU32();t=this.decodeBinary(e,4)}else if(e===212)t=this.decodeExtension(1,0);else if(e===213)t=this.decodeExtension(2,0);else if(e===214)t=this.decodeExtension(4,0);else if(e===215)t=this.decodeExtension(8,0);else if(e===216)t=this.decodeExtension(16,0);else if(e===199){let e=this.lookU8();t=this.decodeExtension(e,1)}else if(e===200){let e=this.lookU16();t=this.decodeExtension(e,2)}else if(e===201){let e=this.lookU32();t=this.decodeExtension(e,4)}else throw new aU(`Unrecognized type byte: ${TU(e)}`);this.complete();let n=this.stack;for(;n.length>0;){let e=n.top();if(e.type===jU)if(e.array[e.position]=t,e.position++,e.position===e.size)t=e.array,n.release(e);else continue DECODE;else if(e.type===MU){if(t===`__proto__`)throw new aU(`The key __proto__ is not allowed`);e.key=this.mapKeyConverter(t),e.type=NU;continue DECODE}else if(e.map[e.key]=t,e.readCount++,e.readCount===e.size)t=e.map,n.release(e);else{e.key=null,e.type=MU;continue DECODE}}return t}}readHeadByte(){return this.headByte===IU&&(this.headByte=this.readU8()),this.headByte}complete(){this.headByte=IU}readArraySize(){let e=this.readHeadByte();switch(e){case 220:return this.readU16();case 221:return this.readU32();default:if(e<160)return e-144;throw new aU(`Unrecognized array type byte: ${TU(e)}`)}}pushMapState(e){if(e>this.maxMapLength)throw new aU(`Max length exceeded: map length (${e}) > maxMapLengthLength (${this.maxMapLength})`);this.stack.pushMapState(e)}pushArrayState(e){if(e>this.maxArrayLength)throw new aU(`Max length exceeded: array length (${e}) > maxArrayLength (${this.maxArrayLength})`);this.stack.pushArrayState(e)}decodeString(e,t){return!this.rawStrings||this.stateIsMapKey()?this.decodeUtf8String(e,t):this.decodeBinary(e,t)}decodeUtf8String(e,t){if(e>this.maxStrLength)throw new aU(`Max length exceeded: UTF-8 byte length (${e}) > maxStrLength (${this.maxStrLength})`);if(this.bytes.byteLength<this.pos+t+e)throw zU;let n=this.pos+t,r;return r=this.stateIsMapKey()&&this.keyDecoder?.canBeCached(e)?this.keyDecoder.decode(this.bytes,n,e):QH(this.bytes,n,e),this.pos+=t+e,r}stateIsMapKey(){return this.stack.length>0?this.stack.top().type===MU:!1}decodeBinary(e,t){if(e>this.maxBinLength)throw new aU(`Max length exceeded: bin length (${e}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining(e+t))throw zU;let n=this.pos+t,r=this.bytes.subarray(n,n+e);return this.pos+=t+e,r}decodeExtension(e,t){if(e>this.maxExtLength)throw new aU(`Max length exceeded: ext length (${e}) > maxExtLength (${this.maxExtLength})`);let n=this.view.getInt8(this.pos+t),r=this.decodeBinary(e,t+1);return this.extensionCodec.decode(r,n,this.context)}lookU8(){return this.view.getUint8(this.pos)}lookU16(){return this.view.getUint16(this.pos)}lookU32(){return this.view.getUint32(this.pos)}readU8(){let e=this.view.getUint8(this.pos);return this.pos++,e}readI8(){let e=this.view.getInt8(this.pos);return this.pos++,e}readU16(){let e=this.view.getUint16(this.pos);return this.pos+=2,e}readI16(){let e=this.view.getInt16(this.pos);return this.pos+=2,e}readU32(){let e=this.view.getUint32(this.pos);return this.pos+=4,e}readI32(){let e=this.view.getInt32(this.pos);return this.pos+=4,e}readU64(){let e=lU(this.view,this.pos);return this.pos+=8,e}readI64(){let e=cU(this.view,this.pos);return this.pos+=8,e}readU64AsBigInt(){let e=this.view.getBigUint64(this.pos);return this.pos+=8,e}readI64AsBigInt(){let e=this.view.getBigInt64(this.pos);return this.pos+=8,e}readF32(){let e=this.view.getFloat32(this.pos);return this.pos+=4,e}readF64(){let e=this.view.getFloat64(this.pos);return this.pos+=8,e}}}));function UU(e,t){return new VU(t).decode(e)}var WU=c((()=>{HU()})),GU=c((()=>{WU()}));function KU(e){let t=e=>RangeError(`columns message: ${e}`);e.byteOffset%8!=0&&(e=e.slice());let n=new DataView(e.buffer,e.byteOffset,e.byteLength);if(e.byteLength<8)throw t(`short`);if(n.getUint8(0)!==qU)throw t(`version ${n.getUint8(0)}`);let r=n.getUint16(2,!0),i=n.getUint32(4,!0),a=new TextDecoder,o=[],s=8;for(let i=0;i<r;i++){if(s+3>e.byteLength)throw t(`short channel table`);let r=n.getUint8(s),i=n.getUint8(s+1),c=n.getUint8(s+2);if(s+=3,r!==4&&r!==8)throw t(`value size ${r}`);if(s+i+c>e.byteLength)throw t(`short channel table`);o.push({name:a.decode(e.subarray(s,s+i)),unit:a.decode(e.subarray(s+i,s+i+c)),size:r}),s+=i+c}if(s=JU(s),s+JU(i*8)+o.reduce((e,t)=>e+JU(i*t.size),0)>e.byteLength)throw t(`short data`);let c=e.byteOffset,l=new Float64Array(e.buffer,c+s,i);s+=JU(i*8);let u={},d={};for(let t of o)u[t.name]=t.size===4?new Float32Array(e.buffer,c+s,i):new Float64Array(e.buffer,c+s,i),t.unit&&(d[t.name]=t.unit),s+=JU(i*t.size);return{t:l,columns:u,units:d}}var qU,JU,YU=c((()=>{qU=1,JU=e=>e+7&-8}));function XU(e,t,n,r){let i=t.length,a=t.map((e,t)=>`y${t}lo`),o=t.map((e,t)=>`y${t}hi`),s=new Uint8Array(e.length),c=0;for(let t=0;t<e.length;t++){let n=e[t];for(let e=0;e<i;e++){let r=n[o[e]];if(r!=null&&Number(r)!==Number(n[a[e]])){s[t]=1;break}}c+=1+s[t]}let l=new Float64Array(c),u=t.map(()=>new Float64Array(c).fill(NaN)),d,f=0,p=null;for(let t=0;t<e.length;t++){let m=e[t],h=n+(Number(m.b)+.5)*r,g=Number(m.pass??0);p!==null&&g!==p&&((d??=new Uint8Array(c))[f]=1),p=g,l[f]=h;for(let e=0;e<i;e++){let t=m[a[e]];t!=null&&(u[e][f]=Number(t))}if(f++,s[t]){l[f]=h;for(let e=0;e<i;e++){let t=m[o[e]];t!=null&&(u[e][f]=Number(t))}f++}}return{length:c,x:l,brk:d,cols:new Map(t.map((e,t)=>[e,u[t]]))}}function ZU(e,t){if(t>=e.length)return e;let n=new Map;for(let[r,i]of e.cols)n.set(r,i.subarray(0,t));return{length:t,x:e.x.subarray(0,t),brk:e.brk?.subarray(0,t),cols:n}}function QU(e,t){if(t===void 0||e.length===0||e.x[e.length-1]<=t)return e;let n=0,r=e.length;for(;n<r;){let i=n+r>>1;e.x[i]<=t?n=i+1:r=i}return ZU(e,n)}function $U(e,t,n){let r=(t,n)=>{let r=0,i=e.length;for(;r<i;){let a=r+i>>1;(n?e.x[a]<=t:e.x[a]<t)?r=a+1:i=a}return r},i=r(t,!1),a=r(n,!0);if(i===0&&a===e.length)return e;let o=new Map;for(let[t,n]of e.cols)o.set(t,n.subarray(i,a));return{length:a-i,x:e.x.subarray(i,a),brk:e.brk?.subarray(i,a),cols:o}}function eW(e,t){let n=[];for(let r=0;r<e.length;r++)t(e.x[r])&&n.push(r);if(n.length===e.length)return e;let r=(e,t)=>{for(let r=0;r<n.length;r++)t[r]=e[n[r]];return t},i=new Map;for(let[t,a]of e.cols)i.set(t,r(a,new Float64Array(n.length)));return{length:n.length,x:r(e.x,new Float64Array(n.length)),brk:e.brk&&r(e.brk,new Uint8Array(n.length)),cols:i}}function tW(e,t,n,r,i=``,a=0){let o=Ie(e),s=Tw(e.length,r),c=t=>{let n=o&&Le(o,t);return n?e=>n[e]:n=>{let r=e[n][t];return typeof r==`number`?r:NaN}},l=c(t),u=[];for(let e of s)Number.isNaN(l(e))||u.push(e);let d=u.length,f=d===e.length&&a===0,p=o&&Le(o,t),m=f&&p?p:Float64Array.from(u,e=>l(e)+a),h=new Map;for(let e of n){let t=o&&Le(o,e);if(o&&!t)continue;if(f&&t){h.set(e+i,t);continue}let n=c(e),r=Float64Array.from(u,n);!t&&!r.some(e=>!Number.isNaN(e))||h.set(e+i,r)}return{length:d,x:m,cols:h}}function nW(e,t,n){if(!t&&n===0)return e;let r=e.x;if(n!==0){r=new Float64Array(e.length);for(let t=0;t<e.length;t++)r[t]=e.x[t]+n}let i=new Map;for(let[n,r]of e.cols)i.set(n+t,r);return{length:e.length,x:r,brk:e.brk,cols:i}}function rW(e){let t=e.filter(e=>e.length>0);if(t.length===0)return aW;if(t.length===1)return t[0];let n=t.reduce((e,t)=>e+t.length,0),r=new Float64Array(n),i=new Set;for(let e of t)for(let t of e.cols.keys())i.add(t);let a=new Map;for(let e of i)a.set(e,new Float64Array(n).fill(NaN));let o,s=0;for(let e of t){r.set(e.x,s),e.brk&&(o??=new Uint8Array(n)).set(e.brk,s);for(let[t,n]of e.cols)a.get(t).set(n,s);s+=e.length}return{length:n,x:r,brk:o,cols:a}}var iW,aW,oW=c((()=>{Aw(),Ue(),Bw(),iW=Lw(new WeakSet),aW={length:0,x:new Float64Array,cols:new Map}})),sW,cW,lW=c((()=>{sW=64,cW=class{nc;bucket;b;lo;hi;start=0;end=0;rowP;px=new Float64Array;pv=[];pStart=0;pEnd=0;mStart=0;mEnd=0;dirty=1/0;dirtyFront=-1;invalid=!0;constructor(e,t,n=1024){this.nc=e,this.bucket=t,this.b=new Float64Array(n),this.rowP=new Float64Array(n),this.lo=Array.from({length:e},()=>new Float64Array(n)),this.hi=Array.from({length:e},()=>new Float64Array(n))}get count(){return this.end-this.start}lowerBound(e){let t=this.start,n=this.end;for(;t<n;){let r=t+n>>>1;this.b[r]<e?t=r+1:n=r}return t}relocate(e,t){let n=this.count,r=n=>{if(t===n.length&&e<=this.start)return n.copyWithin(e,this.start,this.end),n;let r=new Float64Array(t);return r.set(n.subarray(this.start,this.end),e),r};this.b=r(this.b),this.rowP=r(this.rowP),this.lo=this.lo.map(r),this.hi=this.hi.map(r);let i=e-this.start;this.mStart+=i,this.mEnd+=i,this.dirty!==1/0&&(this.dirty+=i),this.dirtyFront>=0&&(this.dirtyFront+=i),this.start=e,this.end=e+n}touch(e){e===this.start&&e+1<this.mEnd?this.dirtyFront=e:e<this.dirty&&(this.dirty=e)}clearRow(e){for(let t=0;t<this.nc;t++)this.lo[t][e]=NaN,this.hi[t][e]=NaN;this.touch(e)}row(e){let t=this.end;if(t>this.start&&this.b[t-1]===e)return t-1;if(t===this.start||e>this.b[t-1])return t===this.b.length&&(this.start>this.count?this.relocate(0,this.b.length):this.relocate(0,Math.max(1024,this.b.length*2))),this.b[this.end]=e,this.clearRow(this.end),this.end++;let n=this.lowerBound(e);if(this.b[n]===e)return n;if(n!==this.start)throw Error(`TimeBuckets: insert inside the rows`);if(this.start===0){let e=Math.max(1024,this.count);this.relocate(e,2*e+this.count)}return this.start--,this.b[this.start]=e,this.clearRow(this.start),this.invalid=!0,this.start}dropBelow(e){this.start=this.lowerBound(e),this.start===this.end&&(this.start=this.end=0,this.invalid=!0)}reset(e){this.clearRow(e)}fold(e,t,n,r){this.touch(e);for(let i=0;i<t.length;i++){let a=t[i],o=1/0,s=-1/0;for(let e=n;e<r;e++){let t=a[e];t<o&&(o=t),t>s&&(s=t)}if(o===1/0)continue;let c=this.lo[i],l=this.hi[i],u=c[e],d=l[e];c[e]=u<=o?u:o,l[e]=d>=s?d:s}}toRows(e,t,n,r,i){let a=[];for(let o=e;o<t;o++){let e={...n,b:this.b[o],pass:0};for(let t=0;t<this.nc;t++){let n=this.lo[t][o];n===n&&(e[r[t]]=n,e[i[t]]=this.hi[t][o])}a.push(e)}return a}pointsOf(e){for(let t=0;t<this.nc;t++){let n=this.hi[t][e];if(n===n&&n!==this.lo[t][e])return 2}return 1}writeRow(e,t,n){let r=(this.b[e]+.5)*this.bucket;this.px[t]=r;for(let n=0;n<this.nc;n++)this.pv[n][t]=this.lo[n][e];if(n===2){this.px[t+1]=r;for(let n=0;n<this.nc;n++)this.pv[n][t+1]=this.hi[n][e]}}reserve(e){if(this.pEnd+e<=this.px.length)return;let t=this.pEnd-this.pStart,n=sW-this.pStart,r=2*(t+e+sW)<=this.px.length,i=r?this.px.length:Math.max(4096,2*(t+e+sW)),a=e=>{if(r)return e.copyWithin(sW,this.pStart,this.pEnd),e;let t=new Float64Array(i);return t.set(e.subarray(this.pStart,this.pEnd),sW),t};this.px=a(this.px),this.pv=this.pv.map(a);for(let e=this.mStart;e<this.mEnd;e++)this.rowP[e]+=n;this.pStart=sW,this.pEnd=sW+t}writeFrom(e){this.mEnd=e;for(let t=e;t<this.end;t++){let e=this.pointsOf(t);this.reserve(e),this.rowP[t]=this.pEnd,this.writeRow(t,this.pEnd,e),this.pEnd+=e,this.mEnd=t+1}}sync(){if(this.pv.length!==this.nc&&(this.pv=Array.from({length:this.nc},()=>new Float64Array)),this.invalid||this.start<this.mStart||this.start>=this.mEnd)this.pStart=this.pEnd=sW,this.mStart=this.mEnd=this.start,this.reserve(0),this.writeFrom(this.start);else{this.start>this.mStart&&(this.mStart=this.start,this.pStart=this.rowP[this.start]);let e=Math.max(this.start,Math.min(this.dirty,this.mEnd)),t=this.dirtyFront;if(t===this.start)if(t+1<e){let e=this.pointsOf(t),n=this.rowP[t+1]-e;if(n<0)return this.invalid=!0,this.sync();this.rowP[t]=n,this.pStart=n,this.writeRow(t,n,e)}else e=t;e<this.end&&(e<this.mEnd&&(this.pEnd=this.rowP[e]),this.writeFrom(e))}this.dirty=1/0,this.dirtyFront=-1,this.invalid=!1}toPoints(e,t,n){this.sync();let r=e<t?this.rowP[e]:0,i=e<t?t<this.mEnd?this.rowP[t]:this.pEnd:0;return{length:i-r,x:this.px.subarray(r,i),cols:new Map(n.map((e,t)=>[e,this.pv[t].subarray(r,i)]))}}}}));function uW(e){if(!(e>0)||!Number.isFinite(e))return e;let t=10**Math.floor(Math.log10(e)),n=e/t;return(n<1.5?1:n<3.5?2:n<7.5?5:10)*t}function dW(e,t,n,r,i){if(n instanceof Float64Array||n instanceof Float32Array)e.set(n.subarray(r,r+i),t);else for(let a=0;a<i;a++)e[t+a]=+n[r+a]}function fW(e,t){let n=e.t.length,r=Object.keys(e.columns).filter(e=>e!==t);for(let t of r)if(e.columns[t].length!==n)throw RangeError(`live column "${t}" has ${e.columns[t].length} values for ${n} times`);return r}function pW(e){let t=hW[e];if(!t){let n=Array.from({length:e},(e,t)=>`y${t}lo`),r=Array.from({length:e},(e,t)=>`y${t}hi`);t={lo:n,hi:r,row:JSON.parse(JSON.stringify(Object.fromEntries([[`b`,0],[`pass`,0],...n.flatMap((e,t)=>[[e,null],[r[t],null]])])))},hW[e]=t}return t}var mW,hW,gW,_W,vW,yW=c((()=>{qw(),oW(),lW(),mW=`ElapsedTime`,hW=[],gW=4096,_W=4,vW=class{time;alloc;maxBytes;cols=new Map;head=0;count=0;full=!1;pushed=0;clears=0;signalOrder=[];unitByName=new Map;capacity;timeColumn;timeUnit;lastBackAbs=-1;get timeMonotonic(){return this.lastBackAbs<=this.pushed-this.size}lastPushT=-1/0;decCache=null;passTrack=null;prevCyclePts=null;curCyclePts=null;trackers=new Map;debugLastScan=0;timeDec=null;mirrors=new Map;historyDec=null;constructor(e,t=mW,n=`s`,r=1/0){this.capacity=Math.max(2,Math.floor(e)),this.timeColumn=t,this.timeUnit=n,this.maxBytes=r,this.alloc=Math.min(this.capacity,gW),this.time=new Float64Array(this.alloc)}get maxSamples(){return this.capacity}newColumn(){return new Float64Array(this.alloc).fill(NaN)}grow(){let e=Math.min(this.capacity,this.alloc*2);if(e*8*(1+this.cols.size)>this.maxBytes){this.capacity=this.alloc;return}let t=t=>{let n=new Float64Array(e);return n.set(t),n};this.time=t(this.time);for(let[e,n]of this.cols)this.cols.set(e,t(n));this.alloc=e}get version(){return this.pushed+this.clears}get size(){return this.full?this.capacity:this.count}push(e){for(let[t,n]of this.trackers){let r=t===this.timeColumn?e.t:e.signals.find(e=>e.name===t)?.value;r!==void 0&&Number.isFinite(r)&&this.advanceCycle(t,n,r,this.pushed)}e.t<this.lastPushT&&this.steppedBack(this.pushed),this.lastPushT=e.t,!this.full&&this.count===this.alloc&&(this.grow(),this.count===this.capacity&&(this.full=!0));let t=this.full?this.head:this.count;this.time[t]=e.t;for(let e of this.signalOrder)this.cols.get(e)[t]=NaN;for(let n of e.signals){if(this.computed.has(n.name))continue;let e=this.cols.get(n.name);e?n.unit&&n.unit!==this.unitByName.get(n.name)&&(this.unitByName.get(n.name)&&this.dropColumnSamples(n.name,e),this.unitByName.set(n.name,n.unit)):(e=this.newColumn(),this.cols.set(n.name,e),this.signalOrder.push(n.name),this.unitByName.set(n.name,n.unit??``)),e[t]=n.value}this.pushed++,this.full?this.head=(this.head+1)%this.capacity:(this.count++,this.count===this.capacity&&(this.full=!0))}pushColumns(e){let t=e.t,n=t.length,r=fW(e,this.timeColumn);if(n===0)return;if(this.trackers.size>0){for(let i=0;i<n;i++)this.push({t:t[i],signals:r.map(t=>({name:t,unit:e.units?.[t],value:e.columns[t][i]}))});return}for(let t of r){if(this.computed.has(t))continue;let n=e.units?.[t],r=this.cols.get(t);r?n&&n!==this.unitByName.get(t)&&(this.unitByName.get(t)&&this.dropColumnSamples(t,r),this.unitByName.set(t,n)):(this.cols.set(t,this.newColumn()),this.signalOrder.push(t),this.unitByName.set(t,n??``))}for(let e=0;e<n;e++){let n=+t[e];n<this.lastPushT&&this.steppedBack(this.pushed+e),this.lastPushT=n}let i=Math.max(0,n-this.capacity);for(this.pushed+=i;i<n;){!this.full&&this.count===this.alloc&&(this.grow(),this.count===this.capacity&&(this.full=!0));let r=this.full?this.head:this.count,a=Math.min(n-i,this.full?this.capacity-this.head:this.alloc-this.count);dW(this.time,r,t,i,a);for(let t of this.signalOrder){let n=this.cols.get(t),o=this.computed.has(t)?void 0:e.columns[t];o?dW(n,r,o,i,a):n.fill(NaN,r,r+a)}this.pushed+=a,i+=a,this.full?this.head=(this.head+a)%this.capacity:(this.count+=a,this.count===this.capacity&&(this.full=!0))}}steppedBack(e){this.lastBackAbs=e,this.timeDec=null}dropColumnSamples(e,t){t.fill(NaN),this.decCache=null,this.timeDec=null;for(let t of this.trackers.values())t.previous?.cols.delete(e);this.clears++}clear(){this.clears++,this.head=0,this.count=0,this.full=!1,this.pushed=0,this.cols.clear(),this.computed.clear(),this.signalOrder.length=0,this.unitByName.clear(),this.decCache=null,this.timeDec=null,this.lastBackAbs=-1,this.lastPushT=-1/0,this.trackers.clear()}columnArray(e){return e===this.timeColumn?this.time:this.cols.get(e)}physOf(e){let t=e-(this.pushed-this.size);return this.full?(this.head+t)%this.capacity:t}copyRange(e,t,n,r=[this.timeColumn,...this.signalOrder]){let i=Math.max(t,this.pushed-this.size),a=Math.max(0,n-i),o=this.columnArray(e),s=new Float64Array(a),c=new Map;for(let e of r)this.columnArray(e)&&c.set(e,new Float64Array(a));for(let e=0;e<a;e++){let t=this.physOf(i+e);s[e]=o?o[t]:NaN;for(let[n,r]of c)r[e]=this.columnArray(n)[t]}return{x:s,cols:c}}advanceCycle(e,t,n,r){Number.isFinite(t.lastX)&&n<t.lastX&&t.lastX-n>(t.hi-t.lo)/2?(t.previous=this.copyRange(e,t.start,r),t.start=r,t.lo=t.hi=n):Number.isFinite(t.lastX)?(n<t.lo&&(t.lo=n),n>t.hi&&(t.hi=n)):t.lo=t.hi=n,n<t.allLo&&(t.allLo=n),n>t.allHi&&(t.allHi=n),t.lastX=n}trackCycles(e){if(this.trackers.has(e))return;let t={start:this.pushed-this.size,lo:0,hi:0,lastX:NaN,allLo:1/0,allHi:-1/0,previous:null},n=this.columnArray(e),r=this.pushed-this.size;if(n)for(let i=r;i<this.pushed;i++){let r=n[this.physOf(i)];Number.isFinite(r)&&this.advanceCycle(e,t,r,i)}this.trackers.set(e,t)}cycleSpan(e){let t=this.trackers.get(e);return t&&t.allHi>t.allLo?[t.allLo,t.allHi]:null}decimateCycle(e,t,n,r,i,a){let o=this.trackers.get(e),s=n.filter(e=>this.cols.has(e));if(!o)return{x0:r,bucket:0,rows:[],columns:s};let c=t===`previous`?o.previous:this.copyRange(e,o.start,this.pushed,s);if(!c)return{x0:r,bucket:0,rows:[],columns:s};let l=s.map(e=>c.cols.get(e)??new Float64Array(c.x.length).fill(NaN));return Vw(c.x,l,s,r,i,a)}decimateCyclePoints(e,t,n,r,i,a){let o=()=>{let o=this.decimateCycle(e,t,n,r,i,a);return XU(o.rows,o.columns,o.x0,o.bucket)},s=this.trackers.get(e),c=Math.floor(a),l=this.columnArray(e);if(!s||!l||!(i>r)||c<1)return o();let u=n.filter(e=>this.cols.has(e)),d=u.join(` `);if(t===`previous`){let e=this.prevCyclePts;if(e&&e.snap===s.previous&&e.x0===r&&e.x1===i&&e.mp===a&&e.colsKey===d)return e.pts;let t=o();return this.prevCyclePts={snap:s.previous,x0:r,x1:i,mp:a,colsKey:d,pts:t},t}if(s.start<this.pushed-this.size)return o();let f=this.curCyclePts;if((!f||f.key!==e||f.start!==s.start||f.x0!==r||f.x1!==i||f.mp!==a||f.colsKey!==d||f.clears!==this.clears)&&(f=this.curCyclePts={key:e,start:s.start,x0:r,x1:i,mp:a,colsKey:d,clears:this.clears,done:s.start,pts:null,seen:new Uint8Array(c),lo:u.map(()=>new Float64Array(c).fill(1/0)),hi:u.map(()=>new Float64Array(c).fill(-1/0))}),f.pts&&f.done===this.pushed)return f.pts;let p=(i-r)/a,m=u.map(e=>this.columnArray(e));for(let e=f.done;e<this.pushed;e++){let t=this.physOf(e),n=l[t];if(!(n>=r&&n<=i))continue;let a=Math.floor((n-r)/p);a>=c&&(a=c-1),f.seen[a]=1;for(let e=0;e<m.length;e++){let n=m[e][t];n===n&&(n<f.lo[e][a]&&(f.lo[e][a]=n),n>f.hi[e][a]&&(f.hi[e][a]=n))}}f.done=this.pushed;let h=0,g=new Uint8Array(c);for(let e=0;e<c;e++)if(f.seen[e]){for(let t=0;t<m.length;t++){let n=f.hi[t][e];if(n!==-1/0&&n!==f.lo[t][e]){g[e]=1;break}}h+=1+g[e]}let _=new Float64Array(h),v=u.map(()=>new Float64Array(h)),y=0;for(let e=0;e<c;e++){if(!f.seen[e])continue;let t=r+(e+.5)*p;_[y]=t;for(let t=0;t<m.length;t++){let n=f.lo[t][e];v[t][y]=n===1/0?NaN:n}if(y++,g[e]){_[y]=t;for(let t=0;t<m.length;t++){let n=f.hi[t][e];v[t][y]=n===-1/0?NaN:n}y++}}return f.pts={length:h,x:_,cols:new Map(u.map((e,t)=>[e,v[t]]))},f.pts}computed=new Set;get firstAbs(){return this.pushed-this.size}get endAbs(){return this.pushed}range(e,t,n){let r=Math.max(t,this.firstAbs),i=new Float64Array(Math.max(0,Math.min(n,this.pushed)-r)),a=this.columnArray(e);if(!a)return i.fill(NaN);for(let e=0;e<i.length;e++)i[e]=a[this.physOf(r+e)];return i}mirrorColumn(e){let t=this.columnArray(e);if(!t)return;let n=this.firstAbs,r=this.pushed,i=this.mirrors.get(e);if((!i||i.clears!==this.clears)&&(i={arr:new Float64Array(Math.max(16,r-n)),first:n,end:n,clears:this.clears,view:null},this.mirrors.set(e,i)),i.first===n&&i.end===r&&i.view)return i.view;if(n>i.first){let e=Math.max(0,i.end-n);e>0&&i.arr.copyWithin(0,n-i.first,i.end-i.first),i.first=n,i.end=n+e}if(i.arr.length<r-n){let e=new Float64Array(Math.max(r-n,i.arr.length*2));e.set(i.arr.subarray(0,i.end-i.first)),i.arr=e}for(let e=i.end;e<r;){let a=this.physOf(e),o=Math.min(r-e,(this.full?this.capacity:this.alloc)-a);i.arr.set(t.subarray(a,a+o),e-n),e+=o}return i.end=r,i.view=i.arr.subarray(0,r-n),i.view}writeComputed(e,t,n,r){let i=this.mirrors.get(e);i&&n<i.end&&(i.end=Math.max(i.first,n),i.view=null);let a=this.cols.get(e);(!a||!this.computed.has(e))&&(a||(a=this.newColumn(),this.cols.set(e,a),this.signalOrder.push(e)),this.computed.add(e)),this.unitByName.set(e,t);for(let e=0;e<r.length;e++){let t=n+e;t<this.firstAbs||t>=this.pushed||(a[this.physOf(t)]=r[e]??NaN)}}clearComputed(){for(let e of this.computed){this.cols.delete(e),this.unitByName.delete(e);for(let t of this.trackers.values())t.previous?.cols.delete(e)}this.signalOrder.splice(0,this.signalOrder.length,...this.signalOrder.filter(e=>!this.computed.has(e))),this.computed.clear(),this.decCache=null,this.timeDec=null,this.clears++}get columnNames(){return[this.timeColumn,...this.signalOrder]}unitOf(e){return e===this.timeColumn?this.timeUnit:this.unitByName.get(e)??``}columnValues(e){let t=this.size,n=new Float64Array(t),r=e===this.timeColumn?this.time:this.cols.get(e);if(!r)return n.fill(NaN),n;for(let e=0;e<t;e++)n[e]=r[this.full?(this.head+e)%this.capacity:e];return n}accumulate(e,t,n,r,i){let a=pW(i.length),o=n[t];if(Number.isNaN(o))return;let s=Math.floor(o/r),c=e.get(s);c||(c={...a.row,b:s},e.set(s,c));for(let e=0;e<i.length;e++){let n=i[e][t];if(Number.isNaN(n))continue;let r=a.lo[e],o=a.hi[e],s=c[r],l=c[o];c[r]=s==null?n:Math.min(s,n),c[o]=l==null?n:Math.max(l,n)}}decimateColumns(e,t,n,r,i){if(e===this.timeColumn&&this.timeMonotonic)return this.decimateTime(t,n,r,i);let a=e===this.timeColumn?this.time:this.cols.get(e),o=a?t.filter(e=>this.cols.has(e)):[],s=(r-n)/i,c=this.size;if(c>1&&e===this.timeColumn&&this.timeMonotonic&&a){let e=a[this.full?this.head:0],t=(a[this.full?(this.head+c-1)%this.capacity:c-1]-e)/(c-1);t>0&&t<s&&(s=.7*Math.max(t,(r-n)/(i*_W)))}let l=uW(s);{let t=this.decCache;t&&t.xKey===e&&t.colsKey===o.join(` `)&&t.bucket>0&&s>=t.bucket*.5&&s<=t.bucket*2&&(l=t.bucket)}if(!a||o.length===0||!(r>n)||!(l>0))return{x0:n,bucket:0,rows:[],columns:o};let u=o.map(e=>this.cols.get(e)),d=this.size,f=o.join(`\0`);this.debugLastScan=0;let p=this.decCache,m=p!==null&&e===this.timeColumn&&this.timeMonotonic&&p.xKey===e&&p.colsKey===f&&p.bucket===l&&this.pushed>=p.pushed&&this.pushed-p.pushed<d&&p.map.size<this.capacity*2,h=p!==null&&p.xKey===e&&p.colsKey===f&&p.bucket===l&&p.pushed===this.pushed,g=this.pushed-d,_=e===this.timeColumn&&this.timeMonotonic?g:Math.max(g,this.passStart(e,a)),v=p!==null&&(_>g||!this.full)&&p.xKey===e&&p.colsKey===f&&p.bucket===l&&p.passStart===_&&p.pushed>=_&&p.pushed<=this.pushed,y;if(h&&p)y=p.map;else if(v&&p){y=p.map;for(let e=p.pushed;e<this.pushed;e++)this.debugLastScan++,this.accumulate(y,this.physOf(e),a,l,u);p.pushed=this.pushed}else if(m&&p){y=p.map;let e=this.pushed-p.pushed;for(let t=d-e;t<d;t++){let e=this.full?(this.head+t)%this.capacity:t;this.debugLastScan++,this.accumulate(y,e,a,l,u)}if(this.full&&d>0){let e=a[this.head];if(!Number.isNaN(e)){let t=Math.floor(e/l);for(let e=p.lowB;e<t;e++)y.delete(e);y.delete(t);for(let e=0;e<d;e++){let n=(this.head+e)%this.capacity,r=a[n];if(!Number.isNaN(r)){if(Math.floor(r/l)>t)break;this.debugLastScan++,this.accumulate(y,n,a,l,u)}}p.lowB=t}}p.pushed=this.pushed}else{y=new Map;let t=1/0;for(let e=_;e<this.pushed;e++){let n=this.physOf(e),r=a[n];if(Number.isNaN(r))continue;this.debugLastScan++,this.accumulate(y,n,a,l,u);let i=Math.floor(r/l);i<t&&(t=i)}this.decCache={xKey:e,colsKey:f,cols:o,bucket:l,map:y,pushed:this.pushed,lowB:Number.isFinite(t)?t:0,passStart:_}}let b=Math.floor(n/l),x=Math.floor(r/l),S=[];for(let e of y.values()){let t=e.b;t>=b&&t<=x&&S.push(e)}return S.sort((e,t)=>Number(e.b)-Number(t.b)),{x0:0,bucket:l,rows:S,columns:o}}passStart(e,t){let n=this.pushed-this.size,r=this.passTrack;(!r||r.key!==e||r.clears!==this.clears)&&(r=this.passTrack={key:e,clears:this.clears,done:n,prevX:NaN,cuts:[]});let{x0:i,x1:a}=this.columnBounds(e),o=(a-i)/2;for(let e=Math.max(r.done,n);e<this.pushed;e++){let n=t[this.physOf(e)];Number.isNaN(n)||(n<r.prevX-o&&(r.cuts.push({abs:e,drop:r.prevX-n}),r.cuts.length>64&&r.cuts.shift()),r.prevX=n)}for(r.done=this.pushed;r.cuts.length>0&&r.cuts[0].abs<n;)r.cuts.shift();for(let e=r.cuts.length-1;e>=0;e--)if(r.cuts[e].drop>o)return r.cuts[e].abs;return n}timeIndex(e){let t=0,n=this.size;for(;t<n;){let r=t+n>>>1;this.time[this.full?(this.head+r)%this.capacity:r]<e?t=r+1:n=r}return t}foldBuckets(e,t,n,r,i){this.eachBucketRun(t,n,r,(t,n,r)=>e.fold(e.row(t),i,n,r))}eachBucketRun(e,t,n,r){if(t<=e)return;this.debugLastScan+=t-e;let i=this.time,a=e=>Math.floor(i[e]/n),o=(e,t)=>{let n=e;for(;n<t;){let e=a(n),i=n,o=1;for(;n+o<t&&a(n+o)===e;)i=n+o,o*=2;let s=i+1,c=Math.min(n+o,t);for(;s<c;){let t=s+c>>>1;a(t)===e?s=t+1:c=t}r(e,n,s),n=s}};if(!this.full)return o(e,t);let s=(this.head+e)%this.capacity,c=s+(t-e);if(c<=this.capacity)return o(s,c);o(s,this.capacity),o(0,c-this.capacity)}decimateTime(e,t,n,r){let i=this.timeBuckets(e,t,n,r);if(!i.store)return{x0:t,bucket:0,rows:[],columns:i.cols};let a=pW(i.cols.length),o=()=>i.store.toRows(i.i0,i.i1,a.row,a.lo,a.hi),s=this.historyDec;return{x0:0,bucket:i.bucket,rows:s?.store===i.store?s.rows??=o():o(),columns:i.cols}}decimatePoints(e,t,n,r,i){if(e===this.timeColumn&&this.timeMonotonic){let e=this.timeBuckets(t,n,r,i);return e.store?e.store.toPoints(e.i0,e.i1,e.cols):{length:0,x:new Float64Array,cols:new Map(e.cols.map(e=>[e,new Float64Array]))}}let a=this.decimateColumns(e,t,n,r,i);return XU(a.rows,a.columns,a.x0,a.bucket)}timeBuckets(e,t,n,r){let i=e.filter(e=>this.cols.has(e)),a=this.size,o={cols:i,bucket:0,store:null,i0:0,i1:0};if(i.length===0||!(n>t)||a===0)return o;let s=e=>this.full?(this.head+e)%this.capacity:e,c=this.time[s(0)],l=this.time[s(a-1)],u=(n-t)/r;if(a>1){let e=(l-c)/(a-1);e>0&&e<u&&(u=.7*Math.max(e,(n-t)/(r*_W)))}let d=uW(u),f=i.join(` `),p=this.timeDec;if(p&&p.colsKey===f&&u>=p.bucket*.5&&u<=p.bucket*2&&(d=p.bucket),!(d>0))return o;let m=i.map(e=>this.cols.get(e)),h=Math.floor(t/d),g=Math.floor(n/d);this.debugLastScan=0;let _=e=>({cols:i,bucket:d,store:e,i0:e.lowerBound(h),i1:e.lowerBound(g+1)});if(n<l-(n-t)){let e=this.timeIndex(h*d),t=this.timeIndex((g+1)*d),n=this.pushed-a,r=`${f}|${d}|${h}|${g}|${n+e}|${n+t}|${this.clears}`;if(this.historyDec?.key!==r){let n=new cW(i.length,d);this.foldBuckets(n,e,t,d,m),this.historyDec={key:r,store:n}}return _(this.historyDec.store)}let v=p?this.pushed-p.pushed:0;if(p&&p.colsKey===f&&p.bucket===d&&v>=0&&v<a){let e=p.store;if(h<p.fromB){let t=new cW(i.length,d);this.foldBuckets(t,this.timeIndex(h*d),this.timeIndex(p.fromB*d),d,m);for(let n=t.end-1;n>=t.start;n--){let r=e.row(t.b[n]);for(let i=0;i<t.nc;i++)e.lo[i][r]=t.lo[i][n],e.hi[i][r]=t.hi[i][n]}p.fromB=h}v>0&&this.foldBuckets(e,a-v,a,d,m);let t=Math.floor(c/d);return this.full&&t>=p.fromB&&(e.dropBelow(t),e.reset(e.row(t)),this.foldBuckets(e,0,this.timeIndex((t+1)*d),d,m),p.fromB=t),h>p.fromB&&(e.dropBelow(h),p.fromB=h),p.pushed=this.pushed,_(e)}let y=new cW(i.length,d),b=this.timeIndex(h*d);return this.foldBuckets(y,b,a,d,m),this.timeDec={colsKey:f,bucket:d,store:y,pushed:this.pushed,fromB:b===0?Math.floor(c/d):h},_(y)}lastValue(e){let t=e===this.timeColumn?this.time:this.cols.get(e);return!t||this.size===0?NaN:t[this.full?(this.head-1+this.capacity)%this.capacity:this.count-1]}xTravel(e,t){let n=this.columnArray(e),r=this.size;if(!n||r<2)return NaN;let i=e=>this.full?(this.head+e)%this.capacity:e,a=this.time[i(r-1)],o=0,s=NaN,c=a;for(let e=r-1;e>=0;e--){let r=i(e),l=this.time[r];if(l<a-t)break;let u=n[r];Number.isNaN(u)||(s>u&&(o+=s-u),s=u,c=l)}let l=a-c;return l>0&&l<t?o*t/l:o}latestTime(){return this.lastValue(this.timeColumn)}xAtTime(e,t){let n=this.columnArray(e),r=this.size;if(!n||r===0||!this.timeMonotonic)return NaN;let i=e=>this.full?(this.head+e)%this.capacity:e,a=0,o=r-1;if(t<=this.time[i(0)])return n[i(0)];if(t>=this.time[i(o)])return n[i(o)];for(;o-a>1;){let e=a+o>>1;this.time[i(e)]<=t?a=e:o=e}let s=i(a),c=i(o),l=n[s],u=n[c];if(!(u>=l))return l;let d=this.time[s],f=this.time[c];return f>d?l+(u-l)*(t-d)/(f-d):l}boundsCache=new Map;columnBounds(e){let t=e===this.timeColumn?this.time:this.cols.get(e),n=this.size;if(!t||n===0)return{x0:0,x1:0};if(t===this.time&&this.timeMonotonic)return{x0:this.time[this.full?this.head:0],x1:this.time[this.full?(this.head+n-1)%this.capacity:n-1]};let r=this.pushed-n,i=this.boundsCache.get(e);if(i&&i.version===this.version)return i.b;(!i||i.clears!==this.clears||i.loAbs<r||i.hiAbs<r)&&(i={version:-1,clears:this.clears,done:r,lo:1/0,hi:-1/0,loAbs:1/0,hiAbs:1/0,b:{x0:0,x1:0}},this.boundsCache.set(e,i));for(let e=Math.max(i.done,r);e<this.pushed;e++){let n=t[this.physOf(e)];Number.isNaN(n)||(n<=i.lo&&(i.lo=n,i.loAbs=e),n>=i.hi&&(i.hi=n,i.hiAbs=e))}return i.done=this.pushed,i.version=this.version,i.b=Number.isFinite(i.lo)?{x0:i.lo,x1:i.hi}:{x0:0,x1:0},i.b}toDataset(e){let t=[this.timeColumn,...this.signalOrder],n=[this.timeUnit,...this.signalOrder.map(e=>this.unitByName.get(e)??``)],r=this.size,i=e&&e>0&&r>e?Math.ceil(r/e):1,a=e=>{let t=this.full?(this.head+e)%this.capacity:e,n={[this.timeColumn]:this.time[t]};for(let e of this.signalOrder){let r=this.cols.get(e)[t];n[e]=Number.isNaN(r)?null:r}return n},o=this.pushed-r,s=i>1?(i-o%i)%i:0,c=[];for(let e=s;e<r;e+=i)c.push(a(e));return r>0&&(c.length===0||(r-1-s)%i!=0)&&c.push(a(r-1)),{meta:``,columnNames:t,units:n,rows:c}}}}));function bW(){let e=globalThis.crypto;if(!e?.subtle)throw Error(`WebCrypto SubtleCrypto is not available`);return e.subtle}function xW(e){let t=``;for(let n=0;n<e.length;n++)t+=String.fromCharCode(e[n]);return btoa(t)}function SW(e){let t=atob(e),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n}async function CW(e,t){let n=new TextEncoder,r=await bW().importKey(`raw`,n.encode(e),`PBKDF2`,!1,[`deriveKey`]);return bW().deriveKey({name:`PBKDF2`,salt:SW(t),iterations:LW,hash:`SHA-256`},r,{name:`AES-GCM`,length:256},!1,[`encrypt`,`decrypt`])}async function wW(e,t){let n=SW(t.iv),r=SW(t.ciphertext),i=await bW().decrypt({name:`AES-GCM`,iv:n},e,r);return new Uint8Array(i)}async function TW(e,t,n,r){let i=await bW().decrypt({name:`AES-GCM`,iv:t,additionalData:r},e,n);return new Uint8Array(i)}async function EW(e,t){return JSON.parse(new TextDecoder().decode(await wW(e,t)))}async function DW(e,t){try{return await EW(e,t)===IW}catch{return!1}}function OW(e){let t=RW.exec(e.trim());return t?{auth:t[1],secret:t[2]??null}:{auth:e,secret:null}}function kW(e){return bW().importKey(`raw`,e,{name:`AES-GCM`,length:256},!1,[`encrypt`,`decrypt`])}function AW(e,t,n){return jW(e,t,n)}async function jW(e,t,n,r){let i=r??globalThis.crypto.getRandomValues(new Uint8Array(12)),a=new Uint8Array(await bW().encrypt({name:`AES-GCM`,iv:i,additionalData:new TextEncoder().encode(n)},e,t));return{iv:xW(i),ct:xW(a)}}async function MW(e,t,n){return new Uint8Array(await bW().decrypt({name:`AES-GCM`,iv:SW(t.iv),additionalData:new TextEncoder().encode(n)},e,SW(t.ct)))}function NW(e,t,n){return PW(e,t,n)}async function PW(e,t,n,r,i){let a=xW(r??globalThis.crypto.getRandomValues(new Uint8Array(16))),o=await jW(await CW(e,a),t,n,i);return{kdf:{name:`PBKDF2`,hash:`SHA-256`,iterations:LW,salt:a},...o}}async function FW(e,t,n){let r=t?.kdf;if(r?.name!==`PBKDF2`||r.hash!==`SHA-256`||r.iterations!==LW||typeof r.salt!=`string`)throw Error(`unsupported_kdf`);return MW(await CW(e,r.salt),t,n)}var IW,LW,RW,zW,BW=c((()=>{IW=`kymoscope-live-key-check-v1`,LW=6e5,RW=/^((?:kymoscope|prism)_[A-Za-z0-9_-]+)(?:\.([A-Za-z0-9_-]+))?$/,new TextEncoder().encode(`kymoscope-device-wrap-v1`),new TextEncoder().encode(`kymoscope-sender-bind-v1`),zW=`kymoscope-workbook-export-v2`}));function VW(e){let t=new Uint8Array(e),n=t.length>0&&t[0]&128?2:1;return t.length<n+UW+WW?null:{kind:t[0]&-129,keyId:n===2?t[1]:null,iv:t.subarray(n,n+UW),ciphertext:t.subarray(n+UW),aad:t.subarray(0,n)}}async function HW(e,t){let n=VW(t);if(!n)return null;let r=typeof e==`function`?await e(n.keyId):e;if(!r)return null;let i=await TW(r,n.iv,n.ciphertext,n.aad);return{kind:n.kind,plaintext:i}}var UW,WW,GW=c((()=>{BW(),UW=12,WW=16}));function KW(e){if(e.byteLength<8)throw eG(`block schema`,`short`);let t=new DataView(e.buffer,e.byteOffset,e.byteLength);if(t.getUint8(0)!==YW)throw eG(`block schema`,`version ${t.getUint8(0)}`);let n=t.getUint16(2,!0),r=t.getUint32(4,!0),i=new TextDecoder(`utf-8`,{fatal:!0}),a=[],o=8;try{for(let r=0;r<n;r++){if(o+3>e.byteLength)throw eG(`block schema`,`short channel table`);let n=t.getUint8(o),r=t.getUint8(o+1),s=t.getUint8(o+2);if(o+=3,n!==4&&n!==8)throw eG(`block schema`,`value size ${n}`);if(o+r+s>e.byteLength)throw eG(`block schema`,`short channel table`);a.push({name:i.decode(e.subarray(o,o+r)),unit:i.decode(e.subarray(o+r,o+r+s)),size:n}),o+=r+s}}catch(e){throw e instanceof RangeError?e:eG(`block schema`,`invalid text`)}return{id:r,channels:a}}async function qW(e,t){let n=new Blob([e]).stream().pipeThrough(new DecompressionStream(`deflate`)).getReader(),r=new Uint8Array(t),i=0;try{for(;;){let{done:e,value:a}=await n.read();if(e)break;if(i+a.length>t)throw eG(`block`,`body larger than its header says`);r.set(a,i),i+=a.length}}catch(e){throw await n.cancel().catch(()=>{}),e instanceof RangeError?e:eG(`block`,`body is not valid deflate`)}if(i!==t)throw eG(`block`,`body size mismatch`);return r}async function JW(e,t){if(e.byteLength<QW)throw eG(`block`,`short`);let n=new DataView(e.buffer,e.byteOffset,e.byteLength);if(n.getUint8(0)!==YW)throw eG(`block`,`version ${n.getUint8(0)}`);let r=n.getUint8(1),i=n.getUint16(2,!0),a=n.getUint32(4,!0),o=t.get(n.getUint32(8,!0));if(!o)return null;if(o.channels.length!==i)throw eG(`block`,`channel count differs from its schema`);let s=n.getFloat64(12,!0),c=Math.max(0,a-1),l=4*c+o.channels.reduce((e,t)=>e+t.size*a,0);if(l>$W)throw eG(`block`,`too large`);let u;if(r&XW)u=await qW(e.subarray(QW),l);else if(u=e.subarray(QW),u.byteLength<l)throw eG(`block`,`body size mismatch`);let d=new DataView(u.buffer,u.byteOffset,u.byteLength),f=new Float64Array(a),p=0;a&&(f[0]=s);for(let e=1;e<a;e++)p+=d.getInt32(4*(e-1),!0),f[e]=s+p/1e6;let m=4*c,h={},g={};for(let e of o.channels){let t=new Uint8Array(a*e.size);for(let n=0;n<e.size;n++)for(let r=0;r<a;r++)t[r*e.size+n]=u[m+n*a+r];h[e.name]=e.size===4?new Float32Array(t.buffer):new Float64Array(t.buffer),e.unit&&(g[e.name]=e.unit),m+=a*e.size}return{block:{t:f,columns:h,units:g},historical:(r&ZW)!==0}}var YW,XW,ZW,QW,$W,eG,tG=c((()=>{YW=2,XW=1,ZW=2,QW=20,$W=64*1024*1024,eG=(e,t)=>RangeError(`${e}: ${t}`)}));function nG(e){let t=Array.from(e,e=>e.toString(16).padStart(2,`0`)).join(``);return`${t.slice(0,8)}-${t.slice(8,12)}-${t.slice(12,16)}-${t.slice(16,20)}-${t.slice(20)}`}function rG(e){if(e.length<56||aG.some((t,n)=>e[n]!==t))throw RangeError(`not a KRC1 chunk`);let t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=t.getUint16(4,!0);if(n!==1)throw RangeError(`KRC version ${n}`);let r=t.getUint16(6,!0);if(r<56)throw RangeError(`KRC header too short`);return{recordingId:nG(e.subarray(8,24)),seq:t.getUint32(24,!0),count:t.getUint32(28,!0),bytes:t.getUint32(32,!0),headerBytes:r,t0:t.getFloat64(40,!0),t1:t.getFloat64(48,!0)}}function iG(e){let t=rG(e),n=new DataView(e.buffer,e.byteOffset,e.byteLength),r=Math.min(e.length,t.bytes),i=[],a=t.headerBytes;for(;i.length<t.count&&a+12<=r;){let t=n.getUint32(a+8,!0);if(a+12+t>r)break;i.push({at:n.getFloat64(a,!0),bytes:e.subarray(a+12,a+12+t)}),a+=12+t}return{header:t,messages:i,truncated:i.length<t.count}}var aG,oG=c((()=>{aG=[75,82,67,49]}));function sG(e){let t=new Map;return async n=>{if(n.length===0)return null;let r=n[0]&128?2:1;if(n.length<r+cG+lG)return null;let i=r===2?n[1]:null,a=t.get(i),o=[...a?[a]:[],...e.filter(e=>e.keyId===i&&e.key!==a).map(e=>e.key)];for(let e of o)try{let a=await TW(e,n.subarray(r,r+cG),n.subarray(r+cG),n.subarray(0,r));return t.set(i,e),{kind:n[0]&-129,plaintext:a}}catch{}return null}}var cG,lG,uG=c((()=>{BW(),GW(),cG=12,lG=16}));async function*dG(e){let t=0;for(;t+56<=e.size;){let n=rG(await e.read(t,56));if(yield await e.slice(t,n.bytes),n.bytes<=56)return;t+=n.bytes}}function fG(e){let t=e.filter(e=>e&&typeof e.t==`number`&&Array.isArray(e.signals)),n={},r={};return t.forEach((e,i)=>{for(let a of e.signals){if(!a||typeof a.name!=`string`)continue;let e=n[a.name]??=new Float64Array(t.length).fill(NaN);e[i]=typeof a.value==`number`?a.value:NaN,a.unit&&!r[a.name]&&(r[a.name]=a.unit)}}),{t:t.map(e=>e.t),columns:n,units:r}}function pG(e){let t=2166136261^e.length;for(let n=0,r=Math.min(e.length,64);n<r;n++)t=Math.imul(t^e[n],16777619);return t>>>0}async function*mG(e,t,n,r){let i=sG(e.keys??[]),a=new Map,o=new Map;for await(let e of dG(t)){let{header:t,messages:s}=iG(e);n.t0??=t.t0;for(let e of s){let t=pG(e.bytes),s=o.get(t);if(s&&_G(s,e.bytes))continue;o.set(t,e.bytes),o.size>gG&&o.delete(o.keys().next().value);let c=await i(e.bytes);if(!c){n.lost++;continue}try{if(c.kind===5){let e=KW(c.plaintext);a.set(e.id,e);continue}if(c.kind===4){let t=await JW(c.plaintext,a);if(!t){n.lost++;continue}(r===void 0||r===!!t.historical)&&(yield{at:e.at,t:t.block.t,columns:t.block.columns,units:t.block.units??{},historical:t.historical});continue}if(r)continue;if(c.kind===3){let t=KU(c.plaintext);yield{at:e.at,t:t.t,columns:t.columns,units:t.units??{}}}else if(c.kind===2){let t=UU(c.plaintext);yield{at:e.at,...fG(Array.isArray(t?.frames)?t.frames:[])}}}catch{n.lost++}}}}var hG,gG,_G,vG,yG=c((()=>{GU(),YU(),yW(),GW(),tG(),oG(),uG(),hG=8192,gG=4096,_G=(e,t)=>e.length===t.length&&e.every((e,n)=>e===t[n]),vG={id:`krc`,label:`Kymoscope recording`,extensions:[],sniff:()=>!1,async plan(e,t){let n=[mW],r=new Map([[mW,`s`]]),i={lost:0,t0:null},a=0,o=!1;for await(let s of mG(e,t,i)){a+=s.t.length,s.historical&&(o=!0);for(let e of Object.keys(s.columns))e!==`ElapsedTime`&&(r.has(e)?!r.get(e)&&s.units[e]&&r.set(e,s.units[e]):(n.push(e),r.set(e,s.units[e]??``)))}let s=n.map(e=>({name:e,unit:r.get(e)??``})),c=i.lost?[`${i.lost} ${i.lost===1?`message`:`messages`} couldn't be opened with the keys this browser has.`]:[];return{format:`Kymoscope recording`,startTime:i.t0===null?null:new Date(i.t0).toISOString(),groups:[{name:`Recording`,channels:s,samples:a,time:{kind:`timestamps`},rateHz:null}],meta:{},events:[],notes:c,state:{names:n,backlog:o}}},async*stream(e){let{names:t,backlog:n=!1}=e.plan.state,r=e.selection.find(e=>e.group===0)?.channels??[],i=new Map(r.map((e,n)=>[t[e],n])),a=i.get(mW),o=()=>r.map(()=>new Float64Array(hG).fill(NaN)),s=new Float64Array(hG),c=o(),l=0,u=0,d=0,f=-1/0,p=0,m=null,h=()=>{let e={group:0,time:s.slice(0,l),start:u,length:l,columns:c.map(e=>e.slice(0,l))};return u+=l,l=0,s=new Float64Array(hG),c=o(),e};function*g(e){let t=e.t.length;for(let n=0;n<t;){let r=Math.min(t-n,hG-l);for(let t=0;t<r;t++){let r=+e.t[n+t]+d;m??=r,s[l+t]=r-m}if(a!==void 0)for(let t=0;t<r;t++)c[a][l+t]=+e.t[n+t];for(let[t,a]of Object.entries(e.columns)){let e=t===`ElapsedTime`?void 0:i.get(t);if(e===void 0)continue;let o=c[e];if(a instanceof Float64Array||a instanceof Float32Array)o.set(a.subarray(n,n+r),l);else for(let e=0;e<r;e++)o[l+e]=+a[n+e]}l+=r,n+=r,l===hG&&(yield h())}}let _=n?mG(e.files,e.io,{lost:0,t0:null},!0):null,v=async()=>{for(let e=await _?.next();e&&!e.done;e=await _.next())if(e.value.t.length)return e.value;return null},y=await v();for await(let t of mG(e.files,e.io,{lost:0,t0:null},n?!1:void 0)){if(e.signal?.aborted)return;let n=t.t.length;if(n!==0){for(+t.t[0]+d<f&&(d=f+Math.max(0,(t.at-p)/1e3)-+t.t[0]),p=t.at;y&&+y.t[0]<+t.t[0];y=await v())yield*g(y);yield*g(t),f=+t.t[n-1]+d}}for(;y&&!e.signal?.aborted;y=await v())yield*g(y);l>0&&(yield h())}}})),bG=u({IMPORTERS:()=>SG,importerFor:()=>xG});function xG(e){let t=SG[e];if(!t)throw Error(`No importer for format ${e}.`);return t}var SG,CG=c((()=>{VB(),qB(),sV(),NV(),uH(),zH(),YH(),yG(),SG={mdf:BB,edf:KB,xdf:oV,tdms:MV,hdf5:lH,mat:RH,comtrade:JH,krc:vG}}));nR(),TL();var wG=()=>new jw(`cancelled`);function TG(){let e=Mw(rR);return e.postMessage({type:`init`,h5Url:new URL(iR,location.href).href}),e}var EG=null,DG=e=>{typeof requestIdleCallback==`function`?requestIdleCallback(e,{timeout:5e3}):setTimeout(e,1e3)};function OG(e,t=TG){t===TG&&typeof Worker>`u`||(EG&&EG.make!==t&&(EG.w.terminate(),EG=null),EG??={w:t(),h5:!1,make:t},e&&!EG.h5&&(EG.h5=!0,EG.w.postMessage({type:`warm`})))}function kG(e){if(EG?.make!==e)return{w:e(),rewarm:null};let{w:t,h5:n}=EG;return EG=null,{w:t,rewarm:n}}function AG(e,t,n,r,i){return!r&&typeof Worker>`u`?jG(e,t,n,i):NG(e,t,n,r??TG)}function jG(e,t,n,r=async e=>(await Promise.resolve().then(()=>(CG(),bG))).importerFor(e)){let i=new tR(t.main),a=null,o=null,s=e=>e.catch(e=>{throw n?.aborted?wG():hL(e)});return{plan:()=>s((async()=>(a=await r(e),o=await KL(a,t,i)))()),read:(e,r,c={})=>(i.bytesRead=0,s(ZL(a,t,o,i,e,r,{...c,signal:n}))),close(){}}}var MG=3e4;function NG(e,t,n,r){let{w:i,rewarm:a}=kG(r),o=null,s=Promise.resolve(),c=Date.now(),l=-1,u=0,d=!1,f=e=>{let t=o;o=null,t?.reject(e)},p=e=>{d=!0,i.terminate(),f(e)},m=setInterval(()=>{o&&u===0&&Date.now()-c>MG&&p(Error(gL))},1e3),h=()=>p(wG());n?.addEventListener(`abort`,h,{once:!0}),i.onmessage=e=>{let t=e.data,n=o;n&&((t.type!==`alive`||t.work!==l)&&(c=Date.now()),t.type===`alive`?l=t.work:t.type===`plan`?(o=null,n.resolve(t.plan)):t.type===`progress`?n.on.progress?.(t.fraction):t.type===`chunk`?(u++,s=s.then(()=>n.on.chunk(t.chunk)).then(()=>{u--,c=Date.now(),i.postMessage({type:`ack`})},e=>{u--,p(e instanceof Error?e:Error(String(e)))})):t.type===`done`?s.then(()=>{o===n&&(o=null,n.resolve(t.result))}):f(Error(t.message)))},i.onerror=e=>f(e instanceof Error?e:Error(`The import worker failed.`));let g=(e,t={})=>new Promise((r,a)=>{if(n?.aborted){a(wG());return}if(d){a(Error(gL));return}o={resolve:r,reject:a,on:t},c=Date.now(),i.postMessage(e)});return{plan:()=>g({type:`plan`,importer:e,files:t}),read:(e,t,n)=>g({type:`read`,selection:e,mode:t},n),close:()=>{clearInterval(m),n?.removeEventListener(`abort`,h),i.terminate(),a!==null&&DG(()=>OG(a,r))}}}Ue();var PG=12e3,FG=(e,t)=>t.map(t=>({group:t,channels:e.groups[t].channels.map((e,t)=>t)}));function IG(e,t){let n=null;for(let r of t){let t=e.groups[r.group];!t.irregular&&(!n||t.samples>n.samples)&&(n={samples:t.samples,rate:t.rateHz})}return n?.rate??null}function LG(e,t,n,r){return{format:e.format,importer:t,startTime:e.startTime,groups:e.groups.map(e=>({name:e.name,channels:e.channels.length,samples:e.samples,rateHz:e.rateHz})),selection:n,combined:n.length>1?{groups:n.length,rateHz:IG(e,n)}:null,splitKey:r,channels:n.reduce((e,t)=>e+t.channels.length,0),notes:e.notes,meta:e.meta,events:[]}}async function RG(e,t,n,r,i,a){let o={meta:``,columnNames:n.columns.map(e=>e.name),units:n.columns.map(e=>e.unit),rows:Re(n.table)},s=new Xw(o);return{id:e,name:t,kind:`memory`,source:s,schema:await s.getSchema(),data:o,file:r,companions:i,info:{...a,events:n.events}}}async function zG(e,t,n,r,i,a,o,s,c){let l=YF().then(e=>e.connect());l.catch(()=>void 0);let u=dI(),d=JL(r,i),f=new pL({insertArrowTable:async(e,t)=>(await l).insertArrowTable(e,t)},u,d);try{let r=await n.read(i,`stream`,{progress:c,chunk:e=>f.append(e)});if(await f.flush(),f.rows===0)throw Error(`${t}: the file has no samples.`);let p=await l,m=await _I.attach(p,u,new Map(d.map(e=>[e.name,e.unit]))),h=await m.getSchema(),g=await m.sampleRows(PG);return{id:e,name:t,kind:`duckdb`,source:m,schema:h,data:{meta:``,columnNames:h.map(e=>e.name),units:h.map(e=>e.unit),rows:g},file:a,companions:o,info:{...s,events:r.events}}}catch(e){let t=await l.catch(()=>null);throw await t?.query(`DROP TABLE IF EXISTS ${XF(u)}`).catch(()=>void 0),await t?.close().catch(()=>void 0),e}}async function BG(e,t){let{main:n,companions:r}=e,i=AG(e.format,{main:n,companions:r,keys:e.keys},t.signal,t.createWorker,t.find),a=[];try{t.priorInMemoryValues+n.size/8>1e8&&YF().catch(()=>void 0);let o=await i.plan(),s=t.selection??t.initial??FG(o,o.defaultGroups??o.groups.map((e,t)=>t)),c=s.reduce((e,t)=>e+t.channels.length,0);if(!t.selection&&t.chooseChannels&&(t.pickChannels||o.pick||c>2e3)){let e=await t.chooseChannels({file:n.name,format:o.format,groups:o.groups.map(e=>({name:e.name,rateHz:e.rateHz,samples:e.samples,channels:e.channels.map(e=>({name:e.name,unit:e.unit}))})),selection:s,estimate:e=>XL(o,e,n.size),budget:vI,used:t.priorInMemoryValues,notes:o.notes});if(!e)throw new jw(`cancelled`);s=e.filter(e=>e.channels.length>0)}if(s.length===0)throw Error(`${n.name}: no channels to read.`);let l=!t.split&&(s.length===1||s.every(e=>o.groups[e.group].time.kind!==`index`))?[s]:s.map(e=>[e]),u=l.length>1?crypto.randomUUID():null,d=t.priorInMemoryValues;for(let s of l){let c=XL(o,s,n.size),f=l.length>1?`${n.name} · ${o.groups[s[0].group].name}`:n.name,p=LG(o,e.format,s,u),m=crypto.randomUUID();if(bI(0,c,d)===`memory`){let e=await i.read(s,`memory`,{progress:t.onProgress});a.push(await RG(m,f,e,n,r,p)),d+=c}else a.push(await zG(m,f,i,o,s,n,r,p,t.onProgress))}return a}catch(e){for(let e of a)e.source.dispose().catch(()=>void 0);throw t.signal?.aborted?new jw(`cancelled`):e}finally{i.close()}}function VG(e){return e.filter(e=>e.type===`number`).map(e=>e.name)}function HG(e,t,n=5e5){let r=1/0,i=-1/0,a=Math.max(1,Math.ceil(e.length/n));for(let n=0;n<e.length;n+=a){let a=e[n][t];typeof a==`number`&&(a<r&&(r=a),a>i&&(i=a))}if(!Number.isFinite(r)||!Number.isFinite(i))return{min:0,max:1};if(r===i){let e=Math.abs(r)*.05||1;return{min:r-e,max:i+e}}let o=(i-r)*.04;return{min:r-o,max:i+o}}function UG(e){switch(e.kind){case`multiband`:return e.series.length;case`parallelcoords`:return e.pcColumns.length;case`barchart`:return e.bcValueCols.length;case`radar`:return e.rdAxesCols.length;case`areachart`:return e.acYCols.length;case`cdfchart`:return e.cdValueCols.length;case`losscurve`:return e.lcLeftCols.length+e.lcRightCols.length;case`gauge`:return e.ggGauges.length;case`heatmap`:return e.hmColumns.length;case`xyzmesh`:return e.xyzColumns?.length??0;default:return 0}}function WG(e,t=6){if(!Number.isFinite(e)||e<=0)return 1;let n=e/t,r=10**Math.floor(Math.log10(n)),i=n/r,a=1;return a=i<=1?1:i<=2?2:i<=5?5:10,a*r}function GG(e){return Math.max(2,Math.min(6,Math.floor(e/64)))}function KG(e,t,n,r){let i=Math.max(e,t)-Math.min(e,t),a=n!==void 0&&n>0&&Number.isFinite(n)?n:WG(i,6);(a<=0||!Number.isFinite(a))&&(a=WG(Math.max(i,1),6));let o=r!==void 0&&r>0&&Number.isFinite(r)?r:a/5;return(o<=0||!Number.isFinite(o))&&(o=a/5),{majorStep:a,minorStep:o}}function qG(e,t,n){let r=Math.min(e,t),i=Math.max(e,t);if(n<=0||!Number.isFinite(n))return[];let a=[],o=Math.ceil(r/n-1e-12)*n,s=0;for(;o<=i+n*1e-9&&s++<1e4;)a.push(o),o+=n;return a}function JG(e,t,n,r){let i=Math.min(e,t),a=Math.max(e,t);if(n<=0||!Number.isFinite(n))return[];let o=e=>r.some(t=>Math.abs(e-t)<=(Math.abs(t)+1)*1e-9+1e-9),s=[],c=Math.ceil(i/n-1e-12)*n,l=0;for(;c<=a+n*1e-9&&l++<2e4;)o(c)||s.push(c),c+=n;return s}var YG={[-12]:`p`,[-9]:`n`,[-6]:`µ`,[-3]:`m`,0:``,3:`k`,6:`M`,9:`G`,12:`T`};function XG(e){if(!(e>0)||!Number.isFinite(e))return 0;let t=Math.max(0,-Math.floor(Math.log10(e)+1e-9));for(let n=t;n<=t+2;n++){let t=e*10**n;if(Math.abs(t-Math.round(t))<=1e-6*t)return n}return t+1}function ZG(e,t){if(!Number.isFinite(e))return`—`;if(!(t>0)||!Number.isFinite(t))return QG(e);if(Math.abs(e)<t*1e-6)return`0`;let n=Math.floor(Math.log10(t)+1e-9);if(n>=3||n<-3){let r=3*Math.ceil((n-1)/3);if(r<-12||r>12)return e.toExponential(2);let i=e/10**r;if(r>0||Math.abs(i)<1e3)return i.toFixed(XG(t/10**r))+YG[r]}return e.toFixed(XG(t))}function QG(e){if(!Number.isFinite(e))return`—`;if(e===0)return`0`;let t=Math.abs(e);if(t<1e-12||t>=0x38d7ea4c68000)return e.toExponential(3);let n=0;(t<.001||t>=1e6)&&(n=3*Math.floor(Math.log10(t)/3));let r=e/10**n,i=Math.max(0,3-Math.floor(Math.log10(Math.abs(r))));return n!==0&&Math.abs(+r.toFixed(i))>=1e3&&(n+=3,r/=1e3,i=3),r.toFixed(i)+YG[n]}var $G=[`#fb923c`,`#60a5fa`,`#4ade80`,`#f87171`,`#facc15`,`#22d3ee`,`#f472b6`,`#2dd4bf`,`#94a3b8`,`#a3e635`];function eK(e,t,n,r=$G){let i=r.length>0?r:$G;return e[t]??i[n%i.length]}function tK(e){return[e===`light`?`#000000`:`#ffffff`,...$G.slice(0,9)]}function nK(e,t=`dark`){let n=(e??[]).filter(e=>typeof e==`string`&&/^#[0-9a-f]{3}([0-9a-f]{3})?$/i.test(e));return n.length>0?n:tK(t)}var rK=[`class`,`data-theme`,`data-color-scheme`];function iK(e){return e?.closest(`[data-color-scheme]`)??document.documentElement}function aK(e){return iK(e).getAttribute(`data-color-scheme`)===`light`?`light`:`dark`}function oK(e,t){let n=new MutationObserver(t),r=new Set([document.documentElement,iK(e)]);for(let e of r)n.observe(e,{attributes:!0,attributeFilter:rK});return()=>n.disconnect()}var sK=[{value:`span`,label:`Span (max − min)`},{value:`mean`,label:`Mean`},{value:`max`,label:`Max`},{value:`min`,label:`Min`}];function cK(e,t){let n=[],r=-1,i=0,a=0,o=0;for(let s=0;s<e.length;s++){let c=e[s][t];typeof c==`number`&&(r<0?(r=0,i=a=c):c<o&&o-c>(a-i)/2?(n.push({start:r,end:s}),r=s,i=a=c):(c<i&&(i=c),c>a&&(a=c)),o=c)}return r>=0&&n.push({start:r,end:e.length}),n}function lK(e,t,n,r){let i=0,a=0,o=1/0,s=-1/0;for(let r=t.start;r<t.end;r++){let t=e[r][n];typeof t==`number`&&(i++,a+=t,t<o&&(o=t),t>s&&(s=t))}return i===0?null:r===`mean`?a/i:r===`max`?s:r===`min`?o:s-o}function uK(e){let t=e.filter(e=>e!==null);if(t.length===0)return null;let n=[...t].sort((e,t)=>e-t)[Math.floor(t.length/2)],r=t.filter(e=>e>=n*.8),i=Math.min(...r.length>1?r:t);return e.indexOf(i)}function dK(e,t){return t.trim()===`s`||/time/i.test(e)}function fK(e,t){return`${e}::lap${t}`}BW();var pK=(e,t,n)=>`kymoscope-workbook-export|3|${e}|${t??``}|${n??``}`,mK=e=>new TextEncoder().encode(e);async function hK(e,t){return{format:`kymoscope-workbook`,v:2,...await NW(t,mK(JSON.stringify(e)),zW)}}async function gK(e,t){let n=t.password?JSON.stringify(await hK(e,t.password)):JSON.stringify(e),r=await AW(await kW(t.key),mK(n),pK(t.scope,t.scopeId,t.password?`password`:void 0));return{format:`kymoscope-workbook`,v:3,scope:t.scope,scope_id:t.scopeId,alg:`AES-256-GCM`,...r,...t.password?{inner:`password`}:{}}}function _K(e){return!!e&&typeof e==`object`&&e.format===`kymoscope-workbook`}function vK(e){return _K(e)?e.v===2?{v:2,scope:null,scopeId:null,password:!0}:e.v!==3||e.alg!==`AES-256-GCM`||typeof e.iv!=`string`||typeof e.ct!=`string`||![`user`,`org`,`any`].includes(e.scope)||e.scope===`any`!=(e.scope_id===null)||e.scope_id!==null&&typeof e.scope_id!=`string`||e.inner!==void 0&&e.inner!==`password`?null:{v:3,scope:e.scope,scopeId:e.scope_id,password:e.inner===`password`}:null}var yK=e=>{try{return JSON.parse(new TextDecoder().decode(e))}catch{throw new jw(`bad_file`)}};async function bK(e,t){let n=vK(e);if(!n)throw new jw(`bad_file`);let r=e;if(n.v===3){let i=e;if(!t.key)throw new jw(`scope_key_required`,{scope:n.scope,scopeId:n.scopeId});let a;try{a=await MW(await kW(t.key),i,pK(i.scope,i.scope_id,i.inner))}catch{throw new jw(`bad_file`)}if(r=yK(a),!n.password)return r;if(r?.v!==2||!_K(r))throw new jw(`bad_file`)}if(!t.password)throw new jw(`password_required`);let i;try{i=await FW(t.password,r,zW)}catch{throw new jw(`wrong_password`)}return yK(i)}var xK=new Set(Object.keys(S));function SK(e){return Array.isArray(e)?e.flatMap(e=>{if(!e||typeof e!=`object`)return[];let{id:t,kind:n,rect:r}=e;return typeof t!=`string`||!xK.has(n)||!r||![r.x,r.y,r.w,r.h].every(e=>typeof e==`number`&&Number.isFinite(e))?[]:[{...e,rect:w(n,r,96)}]}):[]}var CK=e=>({name:e.name,xKey:e.xKey,panels:e.panels,panelChartSettings:e.panelChartSettings,panelChartBackgrounds:e.panelChartBackgrounds});function wK(e){return Object.fromEntries(Object.entries(e).map(([e,t])=>{let n=t.beacon;return[e,n?.datasetId?{...t,beacon:{...n,datasetId:null}}:t]}))}function TK(e){return{version:2,worksheets:e.worksheets.map(e=>({...CK(e),panelChartSettings:wK(e.panelChartSettings)})),activeWorksheet:Math.max(0,e.worksheets.findIndex(t=>t.id===e.activeWorksheetId)),mathChannels:e.channels.map(e=>({name:e.name,formula:e.formula,units:e.units,enabled:e.enabled,...e.description?{description:e.description}:{}})),liveWindowSeconds:e.liveWindowSeconds,laps:e.laps?{channel:e.laps.channel,metric:e.laps.metric,stat:e.laps.stat}:null}}function EK(e){return{version:1,kind:`worksheet`,exportedAt:new Date().toISOString(),worksheet:{name:e.name,xKey:e.xKey,panels:e.panels,panelChartSettings:e.panelChartSettings,panelChartBackgrounds:e.panelChartBackgrounds}}}function DK(e,t,n){let r={kind:e.kind,settings:t,background:n},i=e.title?.trim();return i&&(r.title=i),{version:1,kind:`chart`,exportedAt:new Date().toISOString(),chart:r}}function OK(e){return new Promise((t,n)=>{let r=new FileReader;r.onload=()=>t(r.result),r.onerror=()=>n(r.error),r.readAsText(e)})}async function kK(e){let t=await OK(e),n;try{n=JSON.parse(t)}catch{return{worksheets:[],errors:[`Not a valid JSON file.`]}}return FK(n)}var AK=new Set(sK.map(e=>e.value)),jK=/^(#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})|(?:rgba?|hsla?)\([0-9.,%\s/deg+-]+\)|[a-z]{3,24})$/i;function MK(e){return typeof e!=`string`||e.length>64||/[;{}<>\\]|\b(?:var|env|attr|url)\(/i.test(e)?!1:typeof CSS<`u`&&typeof CSS.supports==`function`?CSS.supports(`color`,e):jK.test(e.trim())}function NK(e){if(Array.isArray(e))return e.map(NK);if(!e||typeof e!=`object`)return e??{};let t={};for(let[n,r]of Object.entries(e))/colou?r$/i.test(n)&&typeof r==`string`&&!MK(r)||(t[n]=r&&typeof r==`object`?NK(r):r);return t}function PK(e){return!e||typeof e!=`object`?{}:Object.fromEntries(Object.entries(e).filter(([,e])=>e===null||MK(e)))}function FK(e){let t=e,n=t&&typeof t==`object`?t.version:void 0;if(!t||n!==1&&n!==2||!Array.isArray(t.worksheets))return{worksheets:[],errors:[`Unrecognized format. Is this a Kymoscope workbook file?`],activeIndex:0,mathChannels:[],liveWindowSeconds:void 0,laps:void 0};let r=[],i=[];if(t.worksheets.forEach((e,t)=>{let n=e;if(typeof n?.name!=`string`||typeof n.xKey!=`string`){i.push(`Worksheet #${t+1} skipped: missing name or xKey.`);return}r.push({id:crypto.randomUUID(),name:n.name,xKey:n.xKey,panels:SK(n.panels),panelChartSettings:NK(n.panelChartSettings),panelChartBackgrounds:PK(n.panelChartBackgrounds)})}),n===1)return{worksheets:r,errors:i,activeIndex:0,mathChannels:[],liveWindowSeconds:void 0,laps:void 0};let a=(Array.isArray(t.mathChannels)?t.mathChannels:[]).flatMap(e=>{let t=e;return typeof t?.name!=`string`||!t.name.trim()||typeof t.formula!=`string`?[]:[{name:t.name,formula:t.formula,units:typeof t.units==`string`?t.units:``,enabled:t.enabled!==!1,...typeof t.description==`string`&&t.description?{description:t.description}:{}}]}),o=t.liveWindowSeconds,s=t.laps,c=s&&typeof s.channel==`string`&&typeof s.metric==`string`&&AK.has(s.stat)?{channel:s.channel,metric:s.metric,stat:s.stat}:null,l=typeof t.activeWorksheet==`number`&&Number.isInteger(t.activeWorksheet)?t.activeWorksheet:0;return{worksheets:r,errors:i,mathChannels:a,laps:c,activeIndex:Math.min(Math.max(0,l),Math.max(0,r.length-1)),liveWindowSeconds:o===null||typeof o==`number`&&o>0?o:void 0}}function IK(e){return e.some(e=>e.panels.length>0)}function LK(e){if(!e||typeof e!=`object`)return null;let t=e;return typeof t.name!=`string`||typeof t.xKey!=`string`?null:{id:crypto.randomUUID(),name:t.name,xKey:t.xKey,panels:SK(t.panels),panelChartSettings:NK(t.panelChartSettings),panelChartBackgrounds:PK(t.panelChartBackgrounds)}}function RK(e){if(!e||typeof e!=`object`)return null;let t=e,n=t.kind;if(typeof n!=`string`||!xK.has(n))return null;let r=Me({__chart:t.settings},``,1).__chart;if(!r||r.kind!==n)return null;let i={kind:n,settings:r,background:t.background===null||typeof t.background==`string`&&/^#[0-9a-fA-F]{6}$/.test(t.background)?t.background:null};return typeof t.title==`string`&&t.title.trim()&&(i.title=t.title),i}async function zK(e){let t=await OK(e),n;try{n=JSON.parse(t)}catch{return{type:`error`,errors:[`Not a valid JSON file.`]}}if(!n||typeof n!=`object`)return{type:`error`,errors:[`Unrecognized file.`]};if(n.format===`kymoscope-workbook`){let e=vK(n);return e?{type:`encrypted`,...e}:{type:`error`,errors:[`This file is from a newer version of Kymoscope.`]}}let r=n.kind;if(r===`worksheet`){let e=LK(n.worksheet);return e?{type:`worksheet`,worksheet:e}:{type:`error`,errors:[`Worksheet file is missing a name or X key.`]}}if(r===`chart`){let e=RK(n.chart);return e?{type:`chart`,chart:e}:{type:`error`,errors:[`Chart file is malformed or its settings do not match its type.`]}}let i=await kK(e);return i.worksheets.length===0&&i.errors.length>0?{type:`error`,errors:i.errors}:{type:`workspace`,worksheets:i.worksheets,errors:i.errors}}var BK=uL;function VK(e){let t=e.toLowerCase();return!t.startsWith(`.`)&&BK.some(e=>t.endsWith(e))}function HK(e,t=``){let n={name:t,path:``,dirs:[],files:[],allPaths:[]};for(let t of e){if(!VK(t.file.name))continue;let e=t.path.split(`/`).filter(Boolean),r=n;for(let t of e.slice(0,-1)){let e=r.path?`${r.path}/${t}`:t,n=r.dirs.find(e=>e.name===t);n||(n={name:t,path:e,dirs:[],files:[],allPaths:[]},r.dirs.push(n)),r=n}r.files.push(t)}let r=new Intl.Collator(void 0,{numeric:!0,sensitivity:`base`}).compare,i=e=>(e.dirs.sort((e,t)=>r(e.name,t.name)),e.files.sort((e,t)=>r(e.file.name,t.file.name)),e.allPaths=[...e.dirs.flatMap(i),...e.files.map(e=>e.path)],e.allPaths);return i(n),!n.files.length&&n.dirs.length===1?n.dirs[0]:n}function UK(e){return e.map(e=>({path:e.webkitRelativePath||e.name,file:e}))}async function WK(e){let t=[],n=async(e,r)=>{let i=r?`${r}/${e.name}`:e.name;if(e.isFile){let n=await new Promise((t,n)=>e.file(t,n));t.push({path:i,file:n});return}if(!e.isDirectory)return;let a=e.createReader();for(;;){let e=await new Promise((e,t)=>a.readEntries(e,t));if(!e.length)break;for(let t of e)await n(t,i)}};for(let t of e)await n(t,``);return t}function GK(){return typeof window.showDirectoryPicker==`function`}async function KK(){let e;try{e=await window.showDirectoryPicker({mode:`read`})}catch(e){if(e instanceof DOMException&&e.name===`AbortError`)return null;throw e}let t=[],n=async(e,r)=>{for await(let i of e.values()){let e=`${r}/${i.name}`;i.kind===`file`?t.push({path:e,file:await i.getFile()}):await n(i,e)}};return await n(e,e.name),t}var qK={1:`dohstRIUBeOkkAXOTXhhEkXanWzz-V4M518JBqTehRM`};function JK(e){let t=e.replace(/-/g,`+`).replace(/_/g,`/`)+`===`.slice((e.length+3)%4),n=atob(t),r=new Uint8Array(n.length);for(let e=0;e<n.length;e++)r[e]=n.charCodeAt(e);return r}function YK(e,t){let n=e.toLowerCase(),r=t.toLowerCase();return n.startsWith(`*.`)?r.endsWith(n.slice(1))&&r.length>n.length-1:n===r}function XK(e){try{let t=JSON.parse(new TextDecoder().decode(JK(e)));return typeof t.sub!=`string`||typeof t.exp!=`number`||!Array.isArray(t.domains)||!t.domains.every(e=>typeof e==`string`)||t.kid!==void 0&&typeof t.kid!=`string`?null:t}catch{return null}}async function ZK(e,t,n,r){if(!e)return{ok:!1,reason:`missing`};if(typeof e!=`string`)return{ok:!1,reason:`malformed`};let i=e.trim().split(`.`);if(i.length!==2||!i[0]||!i[1])return{ok:!1,reason:`malformed`};let a=XK(i[0]);if(!a)return{ok:!1,reason:`malformed`};let o=a.kid??`1`,s=typeof n==`string`?n:Object.hasOwn(n,o)?n[o]:void 0;if(!s)return{ok:!1,reason:`bad_signature`};let c;try{let e=await crypto.subtle.importKey(`raw`,JK(s),`Ed25519`,!1,[`verify`]);c=await crypto.subtle.verify(`Ed25519`,e,JK(i[1]),new TextEncoder().encode(i[0]))}catch{return{ok:!1,reason:`unsupported`}}return c?a.exp<r?{ok:!1,reason:`expired`}:a.domains.some(e=>YK(e,t))?{ok:!0,sub:a.sub,exp:a.exp}:{ok:!1,reason:`domain`}:{ok:!1,reason:`bad_signature`}}function QK(e,t){return ZK(e,t,qK,Date.now()/1e3)}var X={sans:`system-ui, sans-serif`,mono:`ui-monospace, monospace`},$K=l((e=>{var t=Symbol.for(`react.transitional.element`),n=Symbol.for(`react.portal`),r=Symbol.for(`react.fragment`),i=Symbol.for(`react.strict_mode`),a=Symbol.for(`react.profiler`),o=Symbol.for(`react.consumer`),s=Symbol.for(`react.context`),c=Symbol.for(`react.forward_ref`),l=Symbol.for(`react.suspense`),u=Symbol.for(`react.memo`),d=Symbol.for(`react.lazy`),f=Symbol.for(`react.activity`),p=Symbol.iterator;function m(e){return typeof e!=`object`||!e?null:(e=p&&e[p]||e[`@@iterator`],typeof e==`function`?e:null)}var h={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},g=Object.assign,_={};function v(e,t,n){this.props=e,this.context=t,this.refs=_,this.updater=n||h}v.prototype.isReactComponent={},v.prototype.setState=function(e,t){if(typeof e!=`object`&&typeof e!=`function`&&e!=null)throw Error(`takes an object of state variables to update or a function which returns an object of state variables.`);this.updater.enqueueSetState(this,e,t,`setState`)},v.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,`forceUpdate`)};function y(){}y.prototype=v.prototype;function b(e,t,n){this.props=e,this.context=t,this.refs=_,this.updater=n||h}var x=b.prototype=new y;x.constructor=b,g(x,v.prototype),x.isPureReactComponent=!0;var S=Array.isArray;function C(){}var w={H:null,A:null,T:null,S:null},T=Object.prototype.hasOwnProperty;function E(e,n,r){var i=r.ref;return{$$typeof:t,type:e,key:n,ref:i===void 0?null:i,props:r}}function D(e,t){return E(e.type,t,e.props)}function O(e){return typeof e==`object`&&!!e&&e.$$typeof===t}function k(e){var t={"=":`=0`,":":`=2`};return`$`+e.replace(/[=:]/g,function(e){return t[e]})}var A=/\/+/g;function j(e,t){return typeof e==`object`&&e&&e.key!=null?k(``+e.key):t.toString(36)}function M(e){switch(e.status){case`fulfilled`:return e.value;case`rejected`:throw e.reason;default:switch(typeof e.status==`string`?e.then(C,C):(e.status=`pending`,e.then(function(t){e.status===`pending`&&(e.status=`fulfilled`,e.value=t)},function(t){e.status===`pending`&&(e.status=`rejected`,e.reason=t)})),e.status){case`fulfilled`:return e.value;case`rejected`:throw e.reason}}throw e}function N(e,r,i,a,o){var s=typeof e;(s===`undefined`||s===`boolean`)&&(e=null);var c=!1;if(e===null)c=!0;else switch(s){case`bigint`:case`string`:case`number`:c=!0;break;case`object`:switch(e.$$typeof){case t:case n:c=!0;break;case d:return c=e._init,N(c(e._payload),r,i,a,o)}}if(c)return o=o(e),c=a===``?`.`+j(e,0):a,S(o)?(i=``,c!=null&&(i=c.replace(A,`$&/`)+`/`),N(o,r,i,``,function(e){return e})):o!=null&&(O(o)&&(o=D(o,i+(o.key==null||e&&e.key===o.key?``:(``+o.key).replace(A,`$&/`)+`/`)+c)),r.push(o)),1;c=0;var l=a===``?`.`:a+`:`;if(S(e))for(var u=0;u<e.length;u++)a=e[u],s=l+j(a,u),c+=N(a,r,i,s,o);else if(u=m(e),typeof u==`function`)for(e=u.call(e),u=0;!(a=e.next()).done;)a=a.value,s=l+j(a,u++),c+=N(a,r,i,s,o);else if(s===`object`){if(typeof e.then==`function`)return N(M(e),r,i,a,o);throw r=String(e),Error(`Objects are not valid as a React child (found: `+(r===`[object Object]`?`object with keys {`+Object.keys(e).join(`, `)+`}`:r)+`). If you meant to render a collection of children, use an array instead.`)}return c}function P(e,t,n){if(e==null)return e;var r=[],i=0;return N(e,r,``,``,function(e){return t.call(n,e,i++)}),r}function F(e){if(e._status===-1){var t=e._result;t=t(),t.then(function(t){(e._status===0||e._status===-1)&&(e._status=1,e._result=t)},function(t){(e._status===0||e._status===-1)&&(e._status=2,e._result=t)}),e._status===-1&&(e._status=0,e._result=t)}if(e._status===1)return e._result.default;throw e._result}var I=typeof reportError==`function`?reportError:function(e){if(typeof window==`object`&&typeof window.ErrorEvent==`function`){var t=new window.ErrorEvent(`error`,{bubbles:!0,cancelable:!0,message:typeof e==`object`&&e&&typeof e.message==`string`?String(e.message):String(e),error:e});if(!window.dispatchEvent(t))return}else if(typeof process==`object`&&typeof process.emit==`function`){process.emit(`uncaughtException`,e);return}console.error(e)},L={map:P,forEach:function(e,t,n){P(e,function(){t.apply(this,arguments)},n)},count:function(e){var t=0;return P(e,function(){t++}),t},toArray:function(e){return P(e,function(e){return e})||[]},only:function(e){if(!O(e))throw Error(`React.Children.only expected to receive a single React element child.`);return e}};e.Activity=f,e.Children=L,e.Component=v,e.Fragment=r,e.Profiler=a,e.PureComponent=b,e.StrictMode=i,e.Suspense=l,e.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=w,e.__COMPILER_RUNTIME={__proto__:null,c:function(e){return w.H.useMemoCache(e)}},e.cache=function(e){return function(){return e.apply(null,arguments)}},e.cacheSignal=function(){return null},e.cloneElement=function(e,t,n){if(e==null)throw Error(`The argument must be a React element, but you passed `+e+`.`);var r=g({},e.props),i=e.key;if(t!=null)for(a in t.key!==void 0&&(i=``+t.key),t)!T.call(t,a)||a===`key`||a===`__self`||a===`__source`||a===`ref`&&t.ref===void 0||(r[a]=t[a]);var a=arguments.length-2;if(a===1)r.children=n;else if(1<a){for(var o=Array(a),s=0;s<a;s++)o[s]=arguments[s+2];r.children=o}return E(e.type,i,r)},e.createContext=function(e){return e={$$typeof:s,_currentValue:e,_currentValue2:e,_threadCount:0,Provider:null,Consumer:null},e.Provider=e,e.Consumer={$$typeof:o,_context:e},e},e.createElement=function(e,t,n){var r,i={},a=null;if(t!=null)for(r in t.key!==void 0&&(a=``+t.key),t)T.call(t,r)&&r!==`key`&&r!==`__self`&&r!==`__source`&&(i[r]=t[r]);var o=arguments.length-2;if(o===1)i.children=n;else if(1<o){for(var s=Array(o),c=0;c<o;c++)s[c]=arguments[c+2];i.children=s}if(e&&e.defaultProps)for(r in o=e.defaultProps,o)i[r]===void 0&&(i[r]=o[r]);return E(e,a,i)},e.createRef=function(){return{current:null}},e.forwardRef=function(e){return{$$typeof:c,render:e}},e.isValidElement=O,e.lazy=function(e){return{$$typeof:d,_payload:{_status:-1,_result:e},_init:F}},e.memo=function(e,t){return{$$typeof:u,type:e,compare:t===void 0?null:t}},e.startTransition=function(e){var t=w.T,n={};w.T=n;try{var r=e(),i=w.S;i!==null&&i(n,r),typeof r==`object`&&r&&typeof r.then==`function`&&r.then(C,I)}catch(e){I(e)}finally{t!==null&&n.types!==null&&(t.types=n.types),w.T=t}},e.unstable_useCacheRefresh=function(){return w.H.useCacheRefresh()},e.use=function(e){return w.H.use(e)},e.useActionState=function(e,t,n){return w.H.useActionState(e,t,n)},e.useCallback=function(e,t){return w.H.useCallback(e,t)},e.useContext=function(e){return w.H.useContext(e)},e.useDebugValue=function(){},e.useDeferredValue=function(e,t){return w.H.useDeferredValue(e,t)},e.useEffect=function(e,t){return w.H.useEffect(e,t)},e.useEffectEvent=function(e){return w.H.useEffectEvent(e)},e.useId=function(){return w.H.useId()},e.useImperativeHandle=function(e,t,n){return w.H.useImperativeHandle(e,t,n)},e.useInsertionEffect=function(e,t){return w.H.useInsertionEffect(e,t)},e.useLayoutEffect=function(e,t){return w.H.useLayoutEffect(e,t)},e.useMemo=function(e,t){return w.H.useMemo(e,t)},e.useOptimistic=function(e,t){return w.H.useOptimistic(e,t)},e.useReducer=function(e,t,n){return w.H.useReducer(e,t,n)},e.useRef=function(e){return w.H.useRef(e)},e.useState=function(e){return w.H.useState(e)},e.useSyncExternalStore=function(e,t,n){return w.H.useSyncExternalStore(e,t,n)},e.useTransition=function(){return w.H.useTransition()},e.version=`19.2.5`})),eq=l(((e,t)=>{t.exports=$K()})),tq=l((e=>{var t=eq();function n(e){var t=`https://react.dev/errors/`+e;if(1<arguments.length){t+=`?args[]=`+encodeURIComponent(arguments[1]);for(var n=2;n<arguments.length;n++)t+=`&args[]=`+encodeURIComponent(arguments[n])}return`Minified React error #`+e+`; visit `+t+` for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`}function r(){}var i={d:{f:r,r:function(){throw Error(n(522))},D:r,C:r,L:r,m:r,X:r,S:r,M:r},p:0,findDOMNode:null},a=Symbol.for(`react.portal`);function o(e,t,n){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:a,key:r==null?null:``+r,children:e,containerInfo:t,implementation:n}}var s=t.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;function c(e,t){if(e===`font`)return``;if(typeof t==`string`)return t===`use-credentials`?t:``}e.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=i,e.createPortal=function(e,t){var r=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!t||t.nodeType!==1&&t.nodeType!==9&&t.nodeType!==11)throw Error(n(299));return o(e,t,null,r)},e.flushSync=function(e){var t=s.T,n=i.p;try{if(s.T=null,i.p=2,e)return e()}finally{s.T=t,i.p=n,i.d.f()}},e.preconnect=function(e,t){typeof e==`string`&&(t?(t=t.crossOrigin,t=typeof t==`string`?t===`use-credentials`?t:``:void 0):t=null,i.d.C(e,t))},e.prefetchDNS=function(e){typeof e==`string`&&i.d.D(e)},e.preinit=function(e,t){if(typeof e==`string`&&t&&typeof t.as==`string`){var n=t.as,r=c(n,t.crossOrigin),a=typeof t.integrity==`string`?t.integrity:void 0,o=typeof t.fetchPriority==`string`?t.fetchPriority:void 0;n===`style`?i.d.S(e,typeof t.precedence==`string`?t.precedence:void 0,{crossOrigin:r,integrity:a,fetchPriority:o}):n===`script`&&i.d.X(e,{crossOrigin:r,integrity:a,fetchPriority:o,nonce:typeof t.nonce==`string`?t.nonce:void 0})}},e.preinitModule=function(e,t){if(typeof e==`string`)if(typeof t==`object`&&t){if(t.as==null||t.as===`script`){var n=c(t.as,t.crossOrigin);i.d.M(e,{crossOrigin:n,integrity:typeof t.integrity==`string`?t.integrity:void 0,nonce:typeof t.nonce==`string`?t.nonce:void 0})}}else t??i.d.M(e)},e.preload=function(e,t){if(typeof e==`string`&&typeof t==`object`&&t&&typeof t.as==`string`){var n=t.as,r=c(n,t.crossOrigin);i.d.L(e,n,{crossOrigin:r,integrity:typeof t.integrity==`string`?t.integrity:void 0,nonce:typeof t.nonce==`string`?t.nonce:void 0,type:typeof t.type==`string`?t.type:void 0,fetchPriority:typeof t.fetchPriority==`string`?t.fetchPriority:void 0,referrerPolicy:typeof t.referrerPolicy==`string`?t.referrerPolicy:void 0,imageSrcSet:typeof t.imageSrcSet==`string`?t.imageSrcSet:void 0,imageSizes:typeof t.imageSizes==`string`?t.imageSizes:void 0,media:typeof t.media==`string`?t.media:void 0})}},e.preloadModule=function(e,t){if(typeof e==`string`)if(t){var n=c(t.as,t.crossOrigin);i.d.m(e,{as:typeof t.as==`string`&&t.as!==`script`?t.as:void 0,crossOrigin:n,integrity:typeof t.integrity==`string`?t.integrity:void 0})}else i.d.m(e)},e.requestFormReset=function(e){i.d.r(e)},e.unstable_batchedUpdates=function(e,t){return e(t)},e.useFormState=function(e,t,n){return s.H.useFormState(e,t,n)},e.useFormStatus=function(){return s.H.useHostTransitionStatus()},e.version=`19.2.5`})),nq=l(((e,t)=>{function n(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>`u`||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!=`function`))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(n)}catch(e){console.error(e)}}n(),t.exports=tq()})),rq=l((e=>{function t(e,t){var n=e.length;e.push(t);a:for(;0<n;){var r=n-1>>>1,a=e[r];if(0<i(a,t))e[r]=t,e[n]=a,n=r;else break a}}function n(e){return e.length===0?null:e[0]}function r(e){if(e.length===0)return null;var t=e[0],n=e.pop();if(n!==t){e[0]=n;a:for(var r=0,a=e.length,o=a>>>1;r<o;){var s=2*(r+1)-1,c=e[s],l=s+1,u=e[l];if(0>i(c,n))l<a&&0>i(u,c)?(e[r]=u,e[l]=n,r=l):(e[r]=c,e[s]=n,r=s);else if(l<a&&0>i(u,n))e[r]=u,e[l]=n,r=l;else break a}}return t}function i(e,t){var n=e.sortIndex-t.sortIndex;return n===0?e.id-t.id:n}if(e.unstable_now=void 0,typeof performance==`object`&&typeof performance.now==`function`){var a=performance;e.unstable_now=function(){return a.now()}}else{var o=Date,s=o.now();e.unstable_now=function(){return o.now()-s}}var c=[],l=[],u=1,d=null,f=3,p=!1,m=!1,h=!1,g=!1,_=typeof setTimeout==`function`?setTimeout:null,v=typeof clearTimeout==`function`?clearTimeout:null,y=typeof setImmediate<`u`?setImmediate:null;function b(e){for(var i=n(l);i!==null;){if(i.callback===null)r(l);else if(i.startTime<=e)r(l),i.sortIndex=i.expirationTime,t(c,i);else break;i=n(l)}}function x(e){if(h=!1,b(e),!m)if(n(c)!==null)m=!0,S||(S=!0,O());else{var t=n(l);t!==null&&j(x,t.startTime-e)}}var S=!1,C=-1,w=5,T=-1;function E(){return g?!0:!(e.unstable_now()-T<w)}function D(){if(g=!1,S){var t=e.unstable_now();T=t;var i=!0;try{a:{m=!1,h&&(h=!1,v(C),C=-1),p=!0;var a=f;try{b:{for(b(t),d=n(c);d!==null&&!(d.expirationTime>t&&E());){var o=d.callback;if(typeof o==`function`){d.callback=null,f=d.priorityLevel;var s=o(d.expirationTime<=t);if(t=e.unstable_now(),typeof s==`function`){d.callback=s,b(t),i=!0;break b}d===n(c)&&r(c),b(t)}else r(c);d=n(c)}if(d!==null)i=!0;else{var u=n(l);u!==null&&j(x,u.startTime-t),i=!1}}break a}finally{d=null,f=a,p=!1}i=void 0}}finally{i?O():S=!1}}}var O;if(typeof y==`function`)O=function(){y(D)};else if(typeof MessageChannel<`u`){var k=new MessageChannel,A=k.port2;k.port1.onmessage=D,O=function(){A.postMessage(null)}}else O=function(){_(D,0)};function j(t,n){C=_(function(){t(e.unstable_now())},n)}e.unstable_IdlePriority=5,e.unstable_ImmediatePriority=1,e.unstable_LowPriority=4,e.unstable_NormalPriority=3,e.unstable_Profiling=null,e.unstable_UserBlockingPriority=2,e.unstable_cancelCallback=function(e){e.callback=null},e.unstable_forceFrameRate=function(e){0>e||125<e?console.error(`forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported`):w=0<e?Math.floor(1e3/e):5},e.unstable_getCurrentPriorityLevel=function(){return f},e.unstable_next=function(e){switch(f){case 1:case 2:case 3:var t=3;break;default:t=f}var n=f;f=t;try{return e()}finally{f=n}},e.unstable_requestPaint=function(){g=!0},e.unstable_runWithPriority=function(e,t){switch(e){case 1:case 2:case 3:case 4:case 5:break;default:e=3}var n=f;f=e;try{return t()}finally{f=n}},e.unstable_scheduleCallback=function(r,i,a){var o=e.unstable_now();switch(typeof a==`object`&&a?(a=a.delay,a=typeof a==`number`&&0<a?o+a:o):a=o,r){case 1:var s=-1;break;case 2:s=250;break;case 5:s=1073741823;break;case 4:s=1e4;break;default:s=5e3}return s=a+s,r={id:u++,callback:i,priorityLevel:r,startTime:a,expirationTime:s,sortIndex:-1},a>o?(r.sortIndex=a,t(l,r),n(c)===null&&r===n(l)&&(h?(v(C),C=-1):h=!0,j(x,a-o))):(r.sortIndex=s,t(c,r),m||p||(m=!0,S||(S=!0,O()))),r},e.unstable_shouldYield=E,e.unstable_wrapCallback=function(e){var t=f;return function(){var n=f;f=t;try{return e.apply(this,arguments)}finally{f=n}}}})),iq=l(((e,t)=>{t.exports=rq()})),aq=l((e=>{var t=iq(),n=eq(),r=nq();function i(e){var t=`https://react.dev/errors/`+e;if(1<arguments.length){t+=`?args[]=`+encodeURIComponent(arguments[1]);for(var n=2;n<arguments.length;n++)t+=`&args[]=`+encodeURIComponent(arguments[n])}return`Minified React error #`+e+`; visit `+t+` for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`}function a(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function o(e){var t=e,n=e;if(e.alternate)for(;t.return;)t=t.return;else{e=t;do t=e,t.flags&4098&&(n=t.return),e=t.return;while(e)}return t.tag===3?n:null}function s(e){if(e.tag===13){var t=e.memoizedState;if(t===null&&(e=e.alternate,e!==null&&(t=e.memoizedState)),t!==null)return t.dehydrated}return null}function c(e){if(e.tag===31){var t=e.memoizedState;if(t===null&&(e=e.alternate,e!==null&&(t=e.memoizedState)),t!==null)return t.dehydrated}return null}function l(e){if(o(e)!==e)throw Error(i(188))}function u(e){var t=e.alternate;if(!t){if(t=o(e),t===null)throw Error(i(188));return t===e?e:null}for(var n=e,r=t;;){var a=n.return;if(a===null)break;var s=a.alternate;if(s===null){if(r=a.return,r!==null){n=r;continue}break}if(a.child===s.child){for(s=a.child;s;){if(s===n)return l(a),e;if(s===r)return l(a),t;s=s.sibling}throw Error(i(188))}if(n.return!==r.return)n=a,r=s;else{for(var c=!1,u=a.child;u;){if(u===n){c=!0,n=a,r=s;break}if(u===r){c=!0,r=a,n=s;break}u=u.sibling}if(!c){for(u=s.child;u;){if(u===n){c=!0,n=s,r=a;break}if(u===r){c=!0,r=s,n=a;break}u=u.sibling}if(!c)throw Error(i(189))}}if(n.alternate!==r)throw Error(i(190))}if(n.tag!==3)throw Error(i(188));return n.stateNode.current===n?e:t}function d(e){var t=e.tag;if(t===5||t===26||t===27||t===6)return e;for(e=e.child;e!==null;){if(t=d(e),t!==null)return t;e=e.sibling}return null}var f=Object.assign,p=Symbol.for(`react.element`),m=Symbol.for(`react.transitional.element`),h=Symbol.for(`react.portal`),g=Symbol.for(`react.fragment`),_=Symbol.for(`react.strict_mode`),v=Symbol.for(`react.profiler`),y=Symbol.for(`react.consumer`),b=Symbol.for(`react.context`),x=Symbol.for(`react.forward_ref`),S=Symbol.for(`react.suspense`),C=Symbol.for(`react.suspense_list`),w=Symbol.for(`react.memo`),T=Symbol.for(`react.lazy`),E=Symbol.for(`react.activity`),D=Symbol.for(`react.memo_cache_sentinel`),O=Symbol.iterator;function k(e){return typeof e!=`object`||!e?null:(e=O&&e[O]||e[`@@iterator`],typeof e==`function`?e:null)}var A=Symbol.for(`react.client.reference`);function j(e){if(e==null)return null;if(typeof e==`function`)return e.$$typeof===A?null:e.displayName||e.name||null;if(typeof e==`string`)return e;switch(e){case g:return`Fragment`;case v:return`Profiler`;case _:return`StrictMode`;case S:return`Suspense`;case C:return`SuspenseList`;case E:return`Activity`}if(typeof e==`object`)switch(e.$$typeof){case h:return`Portal`;case b:return e.displayName||`Context`;case y:return(e._context.displayName||`Context`)+`.Consumer`;case x:var t=e.render;return e=e.displayName,e||=(e=t.displayName||t.name||``,e===``?`ForwardRef`:`ForwardRef(`+e+`)`),e;case w:return t=e.displayName||null,t===null?j(e.type)||`Memo`:t;case T:t=e._payload,e=e._init;try{return j(e(t))}catch{}}return null}var M=Array.isArray,N=n.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,P=r.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,F={pending:!1,data:null,method:null,action:null},I=[],L=-1;function R(e){return{current:e}}function z(e){0>L||(e.current=I[L],I[L]=null,L--)}function B(e,t){L++,I[L]=e.current,e.current=t}var V=R(null),H=R(null),U=R(null),W=R(null);function ee(e,t){switch(B(U,t),B(H,e),B(V,null),t.nodeType){case 9:case 11:e=(e=t.documentElement)&&(e=e.namespaceURI)?Ud(e):0;break;default:if(e=t.tagName,t=t.namespaceURI)t=Ud(t),e=Wd(t,e);else switch(e){case`svg`:e=1;break;case`math`:e=2;break;default:e=0}}z(V),B(V,e)}function te(){z(V),z(H),z(U)}function ne(e){e.memoizedState!==null&&B(W,e);var t=V.current,n=Wd(t,e.type);t!==n&&(B(H,e),B(V,n))}function G(e){H.current===e&&(z(V),z(H)),W.current===e&&(z(W),ep._currentValue=F)}var re,ie;function ae(e){if(re===void 0)try{throw Error()}catch(e){var t=e.stack.trim().match(/\n( *(at )?)/);re=t&&t[1]||``,ie=-1<e.stack.indexOf(`
|
|
80
|
+
`,r))p(t,r,e),r=e+1,f===c&&(yield u(f,l,d),l=new Float64Array(c),d=i.map(()=>new Float64Array(c)),f=0);m=t.slice(r)}m.trim()&&p(m,0,m.length),f&&(yield u(f,l.slice(0,f),d.map(e=>e.slice(0,f))));return}let d=t.recordSize,f=GH[n.ft],p=Math.max(1,Math.floor(Math.min(eR,c*d)/d)),m=t.samples;for await(let s of r.windows(t.offset,Math.min(t.length,t.samples*d),p*d)){e.signal?.throwIfAborted();let t=Math.min(m,Math.floor(s.bytes.length/d));if(t<=0)break;let r=PI(s.bytes),c=new Float64Array(t);if(!o)for(let e=0;e<t;e++)c[e]=r.getUint32(e*d+4,!0);yield u(t,c,i.map(e=>{let i=new Float64Array(t);if(e<a){let{a,b:o}=n.analog[e],s=8+e*f;if(n.ft===`BINARY`)for(let e=0,n=s;e<t;e++,n+=d){let t=r.getInt16(n,!0);i[e]=t===-32768?NaN:a*t+o}else if(n.ft===`BINARY32`)for(let e=0,n=s;e<t;e++,n+=d){let t=r.getInt32(n,!0);i[e]=t===-2147483648?NaN:a*t+o}else for(let e=0,n=s;e<t;e++,n+=d)i[e]=a*r.getFloat32(n,!0)+o}else{let n=e-a,o=8+a*f+2*(n>>4),s=1<<(n&15);for(let e=0,n=o;e<t;e++,n+=d)i[e]=r.getUint16(n,!0)&s?1:0}return i})),m-=t}}var GH,KH,qH,JH,YH=c((()=>{nR(),zI(),oR(),tL(),GH={BINARY:2,BINARY32:4,FLOAT32:4},KH=16<<20,qH=e=>e.companions.find(e=>e.name.toLowerCase().endsWith(`.dat`)),JH={...eL,async plan(e,t){let n=e.main.name.toLowerCase().endsWith(`.cff`),r,i;if(n){let e=await HH(t);r=e.cfg,i={data:`self`,offset:e.offset,length:e.length}}else{let n=qH(e);if(!n)throw Error(`This COMTRADE .cfg needs its .dat file: drop both together.`);if(t.size>KH)throw Error(`This .cfg is too large to be a COMTRADE configuration file.`);r=LI(await t.read(0,t.size)),i={data:`companion`,offset:0,length:n.size}}let a=VH(r);if(a.ft!==`ASCII`&&!GH[a.ft])throw Error(`This COMTRADE file has data file type ${a.ft}, which Kymoscope cannot read.`);let o=Math.ceil(a.digital.length/16),s=a.ft===`ASCII`?0:8+a.analog.length*GH[a.ft]+2*o,c=s?Math.floor(i.length/s):i.length,l=Math.min(a.rates[a.rates.length-1][1]||(s?c:-1),c),u=a.rates.length===1&&a.rates[0][0]>0?a.rates[0][0]:null,d=[`Analog values are shown as recorded (primary or secondary, per the CFG).`];return{format:`COMTRADE ${a.rev} (${a.ft})`,startTime:a.start,meta:{station:a.station,trigger:a.trigger??``},groups:[{name:a.station||`COMTRADE`,channels:[...a.analog.map(e=>({name:e.name,unit:e.unit})),...a.digital.map(e=>({name:e,unit:``}))],samples:l,time:{kind:`timestamps`},rateHz:u}],events:a.start&&a.trigger?[{time:Math.round((a.triggerSec-a.startSec)*1e6)/1e6,text:`Trigger`}]:[],notes:d,state:{...i,cfg:a,samples:l,recordSize:s}}},stream:e=>WH(e)}}));function XH(e,t,n){let r=t,i=r+n,a=[],o=``;for(;r<i;){let t=e[r++];if(!(t&128))a.push(t);else if((t&224)==192){let n=e[r++]&63;a.push((t&31)<<6|n)}else if((t&240)==224){let n=e[r++]&63,i=e[r++]&63;a.push((t&31)<<12|n<<6|i)}else if((t&248)==240){let n=e[r++]&63,i=e[r++]&63,o=e[r++]&63,s=(t&7)<<18|n<<12|i<<6|o;s>65535&&(s-=65536,a.push(s>>>10&1023|55296),s=56320|s&1023),a.push(s)}else a.push(t);a.length>=$H&&(o+=String.fromCharCode(...a),a.length=0)}return a.length>0&&(o+=String.fromCharCode(...a)),o}function ZH(e,t,n){let r=e.subarray(t,t+n);return eU.decode(r)}function QH(e,t,n){return n>tU?ZH(e,t,n):XH(e,t,n)}var $H,eU,tU,nU=c((()=>{new TextEncoder,$H=4096,eU=new TextDecoder,tU=200})),rU,iU=c((()=>{rU=class{type;data;constructor(e,t){this.type=e,this.data=t}}})),aU,oU=c((()=>{aU=class e extends Error{constructor(t){super(t);let n=Object.create(e.prototype);Object.setPrototypeOf(this,n),Object.defineProperty(this,`name`,{configurable:!0,enumerable:!1,value:e.name})}}}));function sU(e,t,n){let r=Math.floor(n/4294967296),i=n;e.setUint32(t,r),e.setUint32(t+4,i)}function cU(e,t){let n=e.getInt32(t),r=e.getUint32(t+4);return n*4294967296+r}function lU(e,t){let n=e.getUint32(t),r=e.getUint32(t+4);return n*4294967296+r}var uU=c((()=>{}));function dU({sec:e,nsec:t}){if(e>=0&&t>=0&&e<=_U)if(t===0&&e<=gU){let t=new Uint8Array(4);return new DataView(t.buffer).setUint32(0,e),t}else{let n=e/4294967296,r=e&4294967295,i=new Uint8Array(8),a=new DataView(i.buffer);return a.setUint32(0,t<<2|n&3),a.setUint32(4,r),i}else{let n=new Uint8Array(12),r=new DataView(n.buffer);return r.setUint32(0,t),sU(r,4,e),n}}function fU(e){let t=e.getTime(),n=Math.floor(t/1e3),r=(t-n*1e3)*1e6,i=Math.floor(r/1e9);return{sec:n+i,nsec:r-i*1e9}}function pU(e){return e instanceof Date?dU(fU(e)):null}function mU(e){let t=new DataView(e.buffer,e.byteOffset,e.byteLength);switch(e.byteLength){case 4:return{sec:t.getUint32(0),nsec:0};case 8:{let e=t.getUint32(0),n=t.getUint32(4);return{sec:(e&3)*4294967296+n,nsec:e>>>2}}case 12:return{sec:cU(t,4),nsec:t.getUint32(0)};default:throw new aU(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${e.length}`)}}function hU(e){let t=mU(e);return new Date(t.sec*1e3+t.nsec/1e6)}var gU,_U,vU,yU=c((()=>{oU(),uU(),gU=4294967295,_U=17179869183,vU={type:-1,encode:pU,decode:hU}})),bU,xU=c((()=>{iU(),yU(),bU=class e{static defaultCodec=new e;__brand;builtInEncoders=[];builtInDecoders=[];encoders=[];decoders=[];constructor(){this.register(vU)}register({type:e,encode:t,decode:n}){if(e>=0)this.encoders[e]=t,this.decoders[e]=n;else{let r=-1-e;this.builtInEncoders[r]=t,this.builtInDecoders[r]=n}}tryToEncode(e,t){for(let n=0;n<this.builtInEncoders.length;n++){let r=this.builtInEncoders[n];if(r!=null){let i=r(e,t);if(i!=null)return new rU(-1-n,i)}}for(let n=0;n<this.encoders.length;n++){let r=this.encoders[n];if(r!=null){let i=r(e,t);if(i!=null)return new rU(n,i)}}return e instanceof rU?e:null}decode(e,t,n){let r=t<0?this.builtInDecoders[-1-t]:this.decoders[t];return r?r(e,t,n):new rU(t,e)}}}));function SU(e){return e instanceof ArrayBuffer||typeof SharedArrayBuffer<`u`&&e instanceof SharedArrayBuffer}function CU(e){return e instanceof Uint8Array?e:ArrayBuffer.isView(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):SU(e)?new Uint8Array(e):Uint8Array.from(e)}var wU=c((()=>{}));function TU(e){return`${e<0?`-`:``}0x${Math.abs(e).toString(16).padStart(2,`0`)}`}var EU=c((()=>{})),DU,OU,kU,AU=c((()=>{nU(),DU=16,OU=16,kU=class{hit=0;miss=0;caches;maxKeyLength;maxLengthPerKey;constructor(e=DU,t=OU){this.maxKeyLength=e,this.maxLengthPerKey=t,this.caches=[];for(let e=0;e<this.maxKeyLength;e++)this.caches.push([])}canBeCached(e){return e>0&&e<=this.maxKeyLength}find(e,t,n){let r=this.caches[n-1];FIND_CHUNK:for(let i of r){let r=i.bytes;for(let i=0;i<n;i++)if(r[i]!==e[t+i])continue FIND_CHUNK;return i.str}return null}store(e,t){let n=this.caches[e.length-1],r={bytes:e,str:t};n.length>=this.maxLengthPerKey?n[Math.random()*n.length|0]=r:n.push(r)}decode(e,t,n){let r=this.find(e,t,n);if(r!=null)return this.hit++,r;this.miss++;let i=XH(e,t,n),a=Uint8Array.prototype.slice.call(e,t,t+n);return this.store(a,i),i}}})),jU,MU,NU,PU,FU,IU,LU,RU,zU,BU,VU,HU=c((()=>{EU(),xU(),uU(),nU(),wU(),AU(),oU(),jU=`array`,MU=`map_key`,NU=`map_value`,PU=e=>{if(typeof e==`string`||typeof e==`number`)return e;throw new aU(`The type of key must be string or number but `+typeof e)},FU=class{stack=[];stackHeadPosition=-1;get length(){return this.stackHeadPosition+1}top(){return this.stack[this.stackHeadPosition]}pushArrayState(e){let t=this.getUninitializedStateFromPool();t.type=jU,t.position=0,t.size=e,t.array=Array(e)}pushMapState(e){let t=this.getUninitializedStateFromPool();t.type=MU,t.readCount=0,t.size=e,t.map={}}getUninitializedStateFromPool(){return this.stackHeadPosition++,this.stackHeadPosition===this.stack.length&&this.stack.push({type:void 0,size:0,array:void 0,position:0,readCount:0,map:void 0,key:null}),this.stack[this.stackHeadPosition]}release(e){if(this.stack[this.stackHeadPosition]!==e)throw Error(`Invalid stack state. Released state is not on top of the stack.`);if(e.type===jU){let t=e;t.size=0,t.array=void 0,t.position=0,t.type=void 0}if(e.type===MU||e.type===NU){let t=e;t.size=0,t.map=void 0,t.readCount=0,t.type=void 0}this.stackHeadPosition--}reset(){this.stack.length=0,this.stackHeadPosition=-1}},IU=-1,LU=new DataView(new ArrayBuffer(0)),RU=new Uint8Array(LU.buffer);try{LU.getInt8(0)}catch(e){if(!(e instanceof RangeError))throw Error(`This module is not supported in the current JavaScript engine because DataView does not throw RangeError on out-of-bounds access`)}zU=RangeError(`Insufficient data`),BU=new kU,VU=class e{extensionCodec;context;useBigInt64;rawStrings;maxStrLength;maxBinLength;maxArrayLength;maxMapLength;maxExtLength;keyDecoder;mapKeyConverter;totalPos=0;pos=0;view=LU;bytes=RU;headByte=IU;stack=new FU;entered=!1;constructor(e){this.extensionCodec=e?.extensionCodec??bU.defaultCodec,this.context=e?.context,this.useBigInt64=e?.useBigInt64??!1,this.rawStrings=e?.rawStrings??!1,this.maxStrLength=e?.maxStrLength??4294967295,this.maxBinLength=e?.maxBinLength??4294967295,this.maxArrayLength=e?.maxArrayLength??4294967295,this.maxMapLength=e?.maxMapLength??4294967295,this.maxExtLength=e?.maxExtLength??4294967295,this.keyDecoder=e?.keyDecoder===void 0?BU:e.keyDecoder,this.mapKeyConverter=e?.mapKeyConverter??PU}clone(){return new e({extensionCodec:this.extensionCodec,context:this.context,useBigInt64:this.useBigInt64,rawStrings:this.rawStrings,maxStrLength:this.maxStrLength,maxBinLength:this.maxBinLength,maxArrayLength:this.maxArrayLength,maxMapLength:this.maxMapLength,maxExtLength:this.maxExtLength,keyDecoder:this.keyDecoder})}reinitializeState(){this.totalPos=0,this.headByte=IU,this.stack.reset()}setBuffer(e){let t=CU(e);this.bytes=t,this.view=new DataView(t.buffer,t.byteOffset,t.byteLength),this.pos=0}appendBuffer(e){if(this.headByte===IU&&!this.hasRemaining(1))this.setBuffer(e);else{let t=this.bytes.subarray(this.pos),n=CU(e),r=new Uint8Array(t.length+n.length);r.set(t),r.set(n,t.length),this.setBuffer(r)}}hasRemaining(e){return this.view.byteLength-this.pos>=e}createExtraByteError(e){let{view:t,pos:n}=this;return RangeError(`Extra ${t.byteLength-n} of ${t.byteLength} byte(s) found at buffer[${e}]`)}decode(e){if(this.entered)return this.clone().decode(e);try{this.entered=!0,this.reinitializeState(),this.setBuffer(e);let t=this.doDecodeSync();if(this.hasRemaining(1))throw this.createExtraByteError(this.pos);return t}finally{this.entered=!1}}*decodeMulti(e){if(this.entered){yield*this.clone().decodeMulti(e);return}try{for(this.entered=!0,this.reinitializeState(),this.setBuffer(e);this.hasRemaining(1);)yield this.doDecodeSync()}finally{this.entered=!1}}async decodeAsync(e){if(this.entered)return this.clone().decodeAsync(e);try{this.entered=!0;let t=!1,n;for await(let r of e){if(t)throw this.entered=!1,this.createExtraByteError(this.totalPos);this.appendBuffer(r);try{n=this.doDecodeSync(),t=!0}catch(e){if(!(e instanceof RangeError))throw e}this.totalPos+=this.pos}if(t){if(this.hasRemaining(1))throw this.createExtraByteError(this.totalPos);return n}let{headByte:r,pos:i,totalPos:a}=this;throw RangeError(`Insufficient data in parsing ${TU(r)} at ${a} (${i} in the current buffer)`)}finally{this.entered=!1}}decodeArrayStream(e){return this.decodeMultiAsync(e,!0)}decodeStream(e){return this.decodeMultiAsync(e,!1)}async*decodeMultiAsync(e,t){if(this.entered){yield*this.clone().decodeMultiAsync(e,t);return}try{this.entered=!0;let n=t,r=-1;for await(let i of e){if(t&&r===0)throw this.createExtraByteError(this.totalPos);this.appendBuffer(i),n&&(r=this.readArraySize(),n=!1,this.complete());try{for(;yield this.doDecodeSync(),--r!==0;);}catch(e){if(!(e instanceof RangeError))throw e}this.totalPos+=this.pos}}finally{this.entered=!1}}doDecodeSync(){DECODE:for(;;){let e=this.readHeadByte(),t;if(e>=224)t=e-256;else if(e<192)if(e<128)t=e;else if(e<144){let n=e-128;if(n!==0){this.pushMapState(n),this.complete();continue DECODE}else t={}}else if(e<160){let n=e-144;if(n!==0){this.pushArrayState(n),this.complete();continue DECODE}else t=[]}else{let n=e-160;t=this.decodeString(n,0)}else if(e===192)t=null;else if(e===194)t=!1;else if(e===195)t=!0;else if(e===202)t=this.readF32();else if(e===203)t=this.readF64();else if(e===204)t=this.readU8();else if(e===205)t=this.readU16();else if(e===206)t=this.readU32();else if(e===207)t=this.useBigInt64?this.readU64AsBigInt():this.readU64();else if(e===208)t=this.readI8();else if(e===209)t=this.readI16();else if(e===210)t=this.readI32();else if(e===211)t=this.useBigInt64?this.readI64AsBigInt():this.readI64();else if(e===217){let e=this.lookU8();t=this.decodeString(e,1)}else if(e===218){let e=this.lookU16();t=this.decodeString(e,2)}else if(e===219){let e=this.lookU32();t=this.decodeString(e,4)}else if(e===220){let e=this.readU16();if(e!==0){this.pushArrayState(e),this.complete();continue DECODE}else t=[]}else if(e===221){let e=this.readU32();if(e!==0){this.pushArrayState(e),this.complete();continue DECODE}else t=[]}else if(e===222){let e=this.readU16();if(e!==0){this.pushMapState(e),this.complete();continue DECODE}else t={}}else if(e===223){let e=this.readU32();if(e!==0){this.pushMapState(e),this.complete();continue DECODE}else t={}}else if(e===196){let e=this.lookU8();t=this.decodeBinary(e,1)}else if(e===197){let e=this.lookU16();t=this.decodeBinary(e,2)}else if(e===198){let e=this.lookU32();t=this.decodeBinary(e,4)}else if(e===212)t=this.decodeExtension(1,0);else if(e===213)t=this.decodeExtension(2,0);else if(e===214)t=this.decodeExtension(4,0);else if(e===215)t=this.decodeExtension(8,0);else if(e===216)t=this.decodeExtension(16,0);else if(e===199){let e=this.lookU8();t=this.decodeExtension(e,1)}else if(e===200){let e=this.lookU16();t=this.decodeExtension(e,2)}else if(e===201){let e=this.lookU32();t=this.decodeExtension(e,4)}else throw new aU(`Unrecognized type byte: ${TU(e)}`);this.complete();let n=this.stack;for(;n.length>0;){let e=n.top();if(e.type===jU)if(e.array[e.position]=t,e.position++,e.position===e.size)t=e.array,n.release(e);else continue DECODE;else if(e.type===MU){if(t===`__proto__`)throw new aU(`The key __proto__ is not allowed`);e.key=this.mapKeyConverter(t),e.type=NU;continue DECODE}else if(e.map[e.key]=t,e.readCount++,e.readCount===e.size)t=e.map,n.release(e);else{e.key=null,e.type=MU;continue DECODE}}return t}}readHeadByte(){return this.headByte===IU&&(this.headByte=this.readU8()),this.headByte}complete(){this.headByte=IU}readArraySize(){let e=this.readHeadByte();switch(e){case 220:return this.readU16();case 221:return this.readU32();default:if(e<160)return e-144;throw new aU(`Unrecognized array type byte: ${TU(e)}`)}}pushMapState(e){if(e>this.maxMapLength)throw new aU(`Max length exceeded: map length (${e}) > maxMapLengthLength (${this.maxMapLength})`);this.stack.pushMapState(e)}pushArrayState(e){if(e>this.maxArrayLength)throw new aU(`Max length exceeded: array length (${e}) > maxArrayLength (${this.maxArrayLength})`);this.stack.pushArrayState(e)}decodeString(e,t){return!this.rawStrings||this.stateIsMapKey()?this.decodeUtf8String(e,t):this.decodeBinary(e,t)}decodeUtf8String(e,t){if(e>this.maxStrLength)throw new aU(`Max length exceeded: UTF-8 byte length (${e}) > maxStrLength (${this.maxStrLength})`);if(this.bytes.byteLength<this.pos+t+e)throw zU;let n=this.pos+t,r;return r=this.stateIsMapKey()&&this.keyDecoder?.canBeCached(e)?this.keyDecoder.decode(this.bytes,n,e):QH(this.bytes,n,e),this.pos+=t+e,r}stateIsMapKey(){return this.stack.length>0?this.stack.top().type===MU:!1}decodeBinary(e,t){if(e>this.maxBinLength)throw new aU(`Max length exceeded: bin length (${e}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining(e+t))throw zU;let n=this.pos+t,r=this.bytes.subarray(n,n+e);return this.pos+=t+e,r}decodeExtension(e,t){if(e>this.maxExtLength)throw new aU(`Max length exceeded: ext length (${e}) > maxExtLength (${this.maxExtLength})`);let n=this.view.getInt8(this.pos+t),r=this.decodeBinary(e,t+1);return this.extensionCodec.decode(r,n,this.context)}lookU8(){return this.view.getUint8(this.pos)}lookU16(){return this.view.getUint16(this.pos)}lookU32(){return this.view.getUint32(this.pos)}readU8(){let e=this.view.getUint8(this.pos);return this.pos++,e}readI8(){let e=this.view.getInt8(this.pos);return this.pos++,e}readU16(){let e=this.view.getUint16(this.pos);return this.pos+=2,e}readI16(){let e=this.view.getInt16(this.pos);return this.pos+=2,e}readU32(){let e=this.view.getUint32(this.pos);return this.pos+=4,e}readI32(){let e=this.view.getInt32(this.pos);return this.pos+=4,e}readU64(){let e=lU(this.view,this.pos);return this.pos+=8,e}readI64(){let e=cU(this.view,this.pos);return this.pos+=8,e}readU64AsBigInt(){let e=this.view.getBigUint64(this.pos);return this.pos+=8,e}readI64AsBigInt(){let e=this.view.getBigInt64(this.pos);return this.pos+=8,e}readF32(){let e=this.view.getFloat32(this.pos);return this.pos+=4,e}readF64(){let e=this.view.getFloat64(this.pos);return this.pos+=8,e}}}));function UU(e,t){return new VU(t).decode(e)}var WU=c((()=>{HU()})),GU=c((()=>{WU()}));function KU(e){let t=e=>RangeError(`columns message: ${e}`);e.byteOffset%8!=0&&(e=e.slice());let n=new DataView(e.buffer,e.byteOffset,e.byteLength);if(e.byteLength<8)throw t(`short`);if(n.getUint8(0)!==qU)throw t(`version ${n.getUint8(0)}`);let r=n.getUint16(2,!0),i=n.getUint32(4,!0),a=new TextDecoder,o=[],s=8;for(let i=0;i<r;i++){if(s+3>e.byteLength)throw t(`short channel table`);let r=n.getUint8(s),i=n.getUint8(s+1),c=n.getUint8(s+2);if(s+=3,r!==4&&r!==8)throw t(`value size ${r}`);if(s+i+c>e.byteLength)throw t(`short channel table`);o.push({name:a.decode(e.subarray(s,s+i)),unit:a.decode(e.subarray(s+i,s+i+c)),size:r}),s+=i+c}if(s=JU(s),s+JU(i*8)+o.reduce((e,t)=>e+JU(i*t.size),0)>e.byteLength)throw t(`short data`);let c=e.byteOffset,l=new Float64Array(e.buffer,c+s,i);s+=JU(i*8);let u={},d={};for(let t of o)u[t.name]=t.size===4?new Float32Array(e.buffer,c+s,i):new Float64Array(e.buffer,c+s,i),t.unit&&(d[t.name]=t.unit),s+=JU(i*t.size);return{t:l,columns:u,units:d}}var qU,JU,YU=c((()=>{qU=1,JU=e=>e+7&-8}));function XU(e,t,n,r){let i=t.length,a=t.map((e,t)=>`y${t}lo`),o=t.map((e,t)=>`y${t}hi`),s=new Uint8Array(e.length),c=0;for(let t=0;t<e.length;t++){let n=e[t];for(let e=0;e<i;e++){let r=n[o[e]];if(r!=null&&Number(r)!==Number(n[a[e]])){s[t]=1;break}}c+=1+s[t]}let l=new Float64Array(c),u=t.map(()=>new Float64Array(c).fill(NaN)),d,f=0,p=null;for(let t=0;t<e.length;t++){let m=e[t],h=n+(Number(m.b)+.5)*r,g=Number(m.pass??0);p!==null&&g!==p&&((d??=new Uint8Array(c))[f]=1),p=g,l[f]=h;for(let e=0;e<i;e++){let t=m[a[e]];t!=null&&(u[e][f]=Number(t))}if(f++,s[t]){l[f]=h;for(let e=0;e<i;e++){let t=m[o[e]];t!=null&&(u[e][f]=Number(t))}f++}}return{length:c,x:l,brk:d,cols:new Map(t.map((e,t)=>[e,u[t]]))}}function ZU(e,t){if(t>=e.length)return e;let n=new Map;for(let[r,i]of e.cols)n.set(r,i.subarray(0,t));return{length:t,x:e.x.subarray(0,t),brk:e.brk?.subarray(0,t),cols:n}}function QU(e,t){if(t===void 0||e.length===0||e.x[e.length-1]<=t)return e;let n=0,r=e.length;for(;n<r;){let i=n+r>>1;e.x[i]<=t?n=i+1:r=i}return ZU(e,n)}function $U(e,t,n){let r=(t,n)=>{let r=0,i=e.length;for(;r<i;){let a=r+i>>1;(n?e.x[a]<=t:e.x[a]<t)?r=a+1:i=a}return r},i=r(t,!1),a=r(n,!0);if(i===0&&a===e.length)return e;let o=new Map;for(let[t,n]of e.cols)o.set(t,n.subarray(i,a));return{length:a-i,x:e.x.subarray(i,a),brk:e.brk?.subarray(i,a),cols:o}}function eW(e,t){let n=[];for(let r=0;r<e.length;r++)t(e.x[r])&&n.push(r);if(n.length===e.length)return e;let r=(e,t)=>{for(let r=0;r<n.length;r++)t[r]=e[n[r]];return t},i=new Map;for(let[t,a]of e.cols)i.set(t,r(a,new Float64Array(n.length)));return{length:n.length,x:r(e.x,new Float64Array(n.length)),brk:e.brk&&r(e.brk,new Uint8Array(n.length)),cols:i}}function tW(e,t,n,r,i=``,a=0){let o=Ie(e),s=Tw(e.length,r),c=t=>{let n=o&&Le(o,t);return n?e=>n[e]:n=>{let r=e[n][t];return typeof r==`number`?r:NaN}},l=c(t),u=[];for(let e of s)Number.isNaN(l(e))||u.push(e);let d=u.length,f=d===e.length&&a===0,p=o&&Le(o,t),m=f&&p?p:Float64Array.from(u,e=>l(e)+a),h=new Map;for(let e of n){let t=o&&Le(o,e);if(o&&!t)continue;if(f&&t){h.set(e+i,t);continue}let n=c(e),r=Float64Array.from(u,n);!t&&!r.some(e=>!Number.isNaN(e))||h.set(e+i,r)}return{length:d,x:m,cols:h}}function nW(e,t,n){if(!t&&n===0)return e;let r=e.x;if(n!==0){r=new Float64Array(e.length);for(let t=0;t<e.length;t++)r[t]=e.x[t]+n}let i=new Map;for(let[n,r]of e.cols)i.set(n+t,r);return{length:e.length,x:r,brk:e.brk,cols:i}}function rW(e){let t=e.filter(e=>e.length>0);if(t.length===0)return aW;if(t.length===1)return t[0];let n=t.reduce((e,t)=>e+t.length,0),r=new Float64Array(n),i=new Set;for(let e of t)for(let t of e.cols.keys())i.add(t);let a=new Map;for(let e of i)a.set(e,new Float64Array(n).fill(NaN));let o,s=0;for(let e of t){r.set(e.x,s),e.brk&&(o??=new Uint8Array(n)).set(e.brk,s);for(let[t,n]of e.cols)a.get(t).set(n,s);s+=e.length}return{length:n,x:r,brk:o,cols:a}}var iW,aW,oW=c((()=>{Aw(),Ue(),Bw(),iW=Lw(new WeakSet),aW={length:0,x:new Float64Array,cols:new Map}})),sW,cW,lW=c((()=>{sW=64,cW=class{nc;bucket;b;lo;hi;start=0;end=0;rowP;px=new Float64Array;pv=[];pStart=0;pEnd=0;mStart=0;mEnd=0;dirty=1/0;dirtyFront=-1;invalid=!0;constructor(e,t,n=1024){this.nc=e,this.bucket=t,this.b=new Float64Array(n),this.rowP=new Float64Array(n),this.lo=Array.from({length:e},()=>new Float64Array(n)),this.hi=Array.from({length:e},()=>new Float64Array(n))}get count(){return this.end-this.start}lowerBound(e){let t=this.start,n=this.end;for(;t<n;){let r=t+n>>>1;this.b[r]<e?t=r+1:n=r}return t}relocate(e,t){let n=this.count,r=n=>{if(t===n.length&&e<=this.start)return n.copyWithin(e,this.start,this.end),n;let r=new Float64Array(t);return r.set(n.subarray(this.start,this.end),e),r};this.b=r(this.b),this.rowP=r(this.rowP),this.lo=this.lo.map(r),this.hi=this.hi.map(r);let i=e-this.start;this.mStart+=i,this.mEnd+=i,this.dirty!==1/0&&(this.dirty+=i),this.dirtyFront>=0&&(this.dirtyFront+=i),this.start=e,this.end=e+n}touch(e){e===this.start&&e+1<this.mEnd?this.dirtyFront=e:e<this.dirty&&(this.dirty=e)}clearRow(e){for(let t=0;t<this.nc;t++)this.lo[t][e]=NaN,this.hi[t][e]=NaN;this.touch(e)}row(e){let t=this.end;if(t>this.start&&this.b[t-1]===e)return t-1;if(t===this.start||e>this.b[t-1])return t===this.b.length&&(this.start>this.count?this.relocate(0,this.b.length):this.relocate(0,Math.max(1024,this.b.length*2))),this.b[this.end]=e,this.clearRow(this.end),this.end++;let n=this.lowerBound(e);if(this.b[n]===e)return n;if(n!==this.start)throw Error(`TimeBuckets: insert inside the rows`);if(this.start===0){let e=Math.max(1024,this.count);this.relocate(e,2*e+this.count)}return this.start--,this.b[this.start]=e,this.clearRow(this.start),this.invalid=!0,this.start}dropBelow(e){this.start=this.lowerBound(e),this.start===this.end&&(this.start=this.end=0,this.invalid=!0)}reset(e){this.clearRow(e)}fold(e,t,n,r){this.touch(e);for(let i=0;i<t.length;i++){let a=t[i],o=1/0,s=-1/0;for(let e=n;e<r;e++){let t=a[e];t<o&&(o=t),t>s&&(s=t)}if(o===1/0)continue;let c=this.lo[i],l=this.hi[i],u=c[e],d=l[e];c[e]=u<=o?u:o,l[e]=d>=s?d:s}}toRows(e,t,n,r,i){let a=[];for(let o=e;o<t;o++){let e={...n,b:this.b[o],pass:0};for(let t=0;t<this.nc;t++){let n=this.lo[t][o];n===n&&(e[r[t]]=n,e[i[t]]=this.hi[t][o])}a.push(e)}return a}pointsOf(e){for(let t=0;t<this.nc;t++){let n=this.hi[t][e];if(n===n&&n!==this.lo[t][e])return 2}return 1}writeRow(e,t,n){let r=(this.b[e]+.5)*this.bucket;this.px[t]=r;for(let n=0;n<this.nc;n++)this.pv[n][t]=this.lo[n][e];if(n===2){this.px[t+1]=r;for(let n=0;n<this.nc;n++)this.pv[n][t+1]=this.hi[n][e]}}reserve(e){if(this.pEnd+e<=this.px.length)return;let t=this.pEnd-this.pStart,n=sW-this.pStart,r=2*(t+e+sW)<=this.px.length,i=r?this.px.length:Math.max(4096,2*(t+e+sW)),a=e=>{if(r)return e.copyWithin(sW,this.pStart,this.pEnd),e;let t=new Float64Array(i);return t.set(e.subarray(this.pStart,this.pEnd),sW),t};this.px=a(this.px),this.pv=this.pv.map(a);for(let e=this.mStart;e<this.mEnd;e++)this.rowP[e]+=n;this.pStart=sW,this.pEnd=sW+t}writeFrom(e){this.mEnd=e;for(let t=e;t<this.end;t++){let e=this.pointsOf(t);this.reserve(e),this.rowP[t]=this.pEnd,this.writeRow(t,this.pEnd,e),this.pEnd+=e,this.mEnd=t+1}}sync(){if(this.pv.length!==this.nc&&(this.pv=Array.from({length:this.nc},()=>new Float64Array)),this.invalid||this.start<this.mStart||this.start>=this.mEnd)this.pStart=this.pEnd=sW,this.mStart=this.mEnd=this.start,this.reserve(0),this.writeFrom(this.start);else{this.start>this.mStart&&(this.mStart=this.start,this.pStart=this.rowP[this.start]);let e=Math.max(this.start,Math.min(this.dirty,this.mEnd)),t=this.dirtyFront;if(t===this.start)if(t+1<e){let e=this.pointsOf(t),n=this.rowP[t+1]-e;if(n<0)return this.invalid=!0,this.sync();this.rowP[t]=n,this.pStart=n,this.writeRow(t,n,e)}else e=t;e<this.end&&(e<this.mEnd&&(this.pEnd=this.rowP[e]),this.writeFrom(e))}this.dirty=1/0,this.dirtyFront=-1,this.invalid=!1}toPoints(e,t,n){this.sync();let r=e<t?this.rowP[e]:0,i=e<t?t<this.mEnd?this.rowP[t]:this.pEnd:0;return{length:i-r,x:this.px.subarray(r,i),cols:new Map(n.map((e,t)=>[e,this.pv[t].subarray(r,i)]))}}}}));function uW(e){if(!(e>0)||!Number.isFinite(e))return e;let t=10**Math.floor(Math.log10(e)),n=e/t;return(n<1.5?1:n<3.5?2:n<7.5?5:10)*t}function dW(e,t,n,r,i){if(n instanceof Float64Array||n instanceof Float32Array)e.set(n.subarray(r,r+i),t);else for(let a=0;a<i;a++)e[t+a]=+n[r+a]}function fW(e,t){let n=e.t.length,r=Object.keys(e.columns).filter(e=>e!==t);for(let t of r)if(e.columns[t].length!==n)throw RangeError(`live column "${t}" has ${e.columns[t].length} values for ${n} times`);return r}function pW(e){let t=hW[e];if(!t){let n=Array.from({length:e},(e,t)=>`y${t}lo`),r=Array.from({length:e},(e,t)=>`y${t}hi`);t={lo:n,hi:r,row:JSON.parse(JSON.stringify(Object.fromEntries([[`b`,0],[`pass`,0],...n.flatMap((e,t)=>[[e,null],[r[t],null]])])))},hW[e]=t}return t}var mW,hW,gW,_W,vW,yW=c((()=>{qw(),oW(),lW(),mW=`ElapsedTime`,hW=[],gW=4096,_W=4,vW=class{time;alloc;maxBytes;cols=new Map;head=0;count=0;full=!1;pushed=0;clears=0;signalOrder=[];unitByName=new Map;capacity;timeColumn;timeUnit;lastBackAbs=-1;get timeMonotonic(){return this.lastBackAbs<=this.pushed-this.size}lastPushT=-1/0;decCache=null;passTrack=null;prevCyclePts=null;curCyclePts=null;trackers=new Map;debugLastScan=0;timeDec=null;mirrors=new Map;historyDec=null;constructor(e,t=mW,n=`s`,r=1/0){this.capacity=Math.max(2,Math.floor(e)),this.timeColumn=t,this.timeUnit=n,this.maxBytes=r,this.alloc=Math.min(this.capacity,gW),this.time=new Float64Array(this.alloc)}get maxSamples(){return this.capacity}newColumn(){return new Float64Array(this.alloc).fill(NaN)}grow(){let e=Math.min(this.capacity,this.alloc*2);if(e*8*(1+this.cols.size)>this.maxBytes){this.capacity=this.alloc;return}let t=t=>{let n=new Float64Array(e);return n.set(t),n};this.time=t(this.time);for(let[e,n]of this.cols)this.cols.set(e,t(n));this.alloc=e}get version(){return this.pushed+this.clears}get size(){return this.full?this.capacity:this.count}push(e){for(let[t,n]of this.trackers){let r=t===this.timeColumn?e.t:e.signals.find(e=>e.name===t)?.value;r!==void 0&&Number.isFinite(r)&&this.advanceCycle(t,n,r,this.pushed)}e.t<this.lastPushT&&this.steppedBack(this.pushed),this.lastPushT=e.t,!this.full&&this.count===this.alloc&&(this.grow(),this.count===this.capacity&&(this.full=!0));let t=this.full?this.head:this.count;this.time[t]=e.t;for(let e of this.signalOrder)this.cols.get(e)[t]=NaN;for(let n of e.signals){if(this.computed.has(n.name))continue;let e=this.cols.get(n.name);e?n.unit&&n.unit!==this.unitByName.get(n.name)&&(this.unitByName.get(n.name)&&this.dropColumnSamples(n.name,e),this.unitByName.set(n.name,n.unit)):(e=this.newColumn(),this.cols.set(n.name,e),this.signalOrder.push(n.name),this.unitByName.set(n.name,n.unit??``)),e[t]=n.value}this.pushed++,this.full?this.head=(this.head+1)%this.capacity:(this.count++,this.count===this.capacity&&(this.full=!0))}pushColumns(e){let t=e.t,n=t.length,r=fW(e,this.timeColumn);if(n===0)return;if(this.trackers.size>0){for(let i=0;i<n;i++)this.push({t:t[i],signals:r.map(t=>({name:t,unit:e.units?.[t],value:e.columns[t][i]}))});return}for(let t of r){if(this.computed.has(t))continue;let n=e.units?.[t],r=this.cols.get(t);r?n&&n!==this.unitByName.get(t)&&(this.unitByName.get(t)&&this.dropColumnSamples(t,r),this.unitByName.set(t,n)):(this.cols.set(t,this.newColumn()),this.signalOrder.push(t),this.unitByName.set(t,n??``))}for(let e=0;e<n;e++){let n=+t[e];n<this.lastPushT&&this.steppedBack(this.pushed+e),this.lastPushT=n}let i=Math.max(0,n-this.capacity);for(this.pushed+=i;i<n;){!this.full&&this.count===this.alloc&&(this.grow(),this.count===this.capacity&&(this.full=!0));let r=this.full?this.head:this.count,a=Math.min(n-i,this.full?this.capacity-this.head:this.alloc-this.count);dW(this.time,r,t,i,a);for(let t of this.signalOrder){let n=this.cols.get(t),o=this.computed.has(t)?void 0:e.columns[t];o?dW(n,r,o,i,a):n.fill(NaN,r,r+a)}this.pushed+=a,i+=a,this.full?this.head=(this.head+a)%this.capacity:(this.count+=a,this.count===this.capacity&&(this.full=!0))}}steppedBack(e){this.lastBackAbs=e,this.timeDec=null}dropColumnSamples(e,t){t.fill(NaN),this.decCache=null,this.timeDec=null;for(let t of this.trackers.values())t.previous?.cols.delete(e);this.clears++}clear(){this.clears++,this.head=0,this.count=0,this.full=!1,this.pushed=0,this.cols.clear(),this.computed.clear(),this.signalOrder.length=0,this.unitByName.clear(),this.decCache=null,this.timeDec=null,this.lastBackAbs=-1,this.lastPushT=-1/0,this.trackers.clear()}columnArray(e){return e===this.timeColumn?this.time:this.cols.get(e)}physOf(e){let t=e-(this.pushed-this.size);return this.full?(this.head+t)%this.capacity:t}copyRange(e,t,n,r=[this.timeColumn,...this.signalOrder]){let i=Math.max(t,this.pushed-this.size),a=Math.max(0,n-i),o=this.columnArray(e),s=new Float64Array(a),c=new Map;for(let e of r)this.columnArray(e)&&c.set(e,new Float64Array(a));for(let e=0;e<a;e++){let t=this.physOf(i+e);s[e]=o?o[t]:NaN;for(let[n,r]of c)r[e]=this.columnArray(n)[t]}return{x:s,cols:c}}advanceCycle(e,t,n,r){Number.isFinite(t.lastX)&&n<t.lastX&&t.lastX-n>(t.hi-t.lo)/2?(t.previous=this.copyRange(e,t.start,r),t.start=r,t.lo=t.hi=n):Number.isFinite(t.lastX)?(n<t.lo&&(t.lo=n),n>t.hi&&(t.hi=n)):t.lo=t.hi=n,n<t.allLo&&(t.allLo=n),n>t.allHi&&(t.allHi=n),t.lastX=n}trackCycles(e){if(this.trackers.has(e))return;let t={start:this.pushed-this.size,lo:0,hi:0,lastX:NaN,allLo:1/0,allHi:-1/0,previous:null},n=this.columnArray(e),r=this.pushed-this.size;if(n)for(let i=r;i<this.pushed;i++){let r=n[this.physOf(i)];Number.isFinite(r)&&this.advanceCycle(e,t,r,i)}this.trackers.set(e,t)}cycleSpan(e){let t=this.trackers.get(e);return t&&t.allHi>t.allLo?[t.allLo,t.allHi]:null}decimateCycle(e,t,n,r,i,a){let o=this.trackers.get(e),s=n.filter(e=>this.cols.has(e));if(!o)return{x0:r,bucket:0,rows:[],columns:s};let c=t===`previous`?o.previous:this.copyRange(e,o.start,this.pushed,s);if(!c)return{x0:r,bucket:0,rows:[],columns:s};let l=s.map(e=>c.cols.get(e)??new Float64Array(c.x.length).fill(NaN));return Vw(c.x,l,s,r,i,a)}decimateCyclePoints(e,t,n,r,i,a){let o=()=>{let o=this.decimateCycle(e,t,n,r,i,a);return XU(o.rows,o.columns,o.x0,o.bucket)},s=this.trackers.get(e),c=Math.floor(a),l=this.columnArray(e);if(!s||!l||!(i>r)||c<1)return o();let u=n.filter(e=>this.cols.has(e)),d=u.join(` `);if(t===`previous`){let e=this.prevCyclePts;if(e&&e.snap===s.previous&&e.x0===r&&e.x1===i&&e.mp===a&&e.colsKey===d)return e.pts;let t=o();return this.prevCyclePts={snap:s.previous,x0:r,x1:i,mp:a,colsKey:d,pts:t},t}if(s.start<this.pushed-this.size)return o();let f=this.curCyclePts;if((!f||f.key!==e||f.start!==s.start||f.x0!==r||f.x1!==i||f.mp!==a||f.colsKey!==d||f.clears!==this.clears)&&(f=this.curCyclePts={key:e,start:s.start,x0:r,x1:i,mp:a,colsKey:d,clears:this.clears,done:s.start,pts:null,seen:new Uint8Array(c),lo:u.map(()=>new Float64Array(c).fill(1/0)),hi:u.map(()=>new Float64Array(c).fill(-1/0))}),f.pts&&f.done===this.pushed)return f.pts;let p=(i-r)/a,m=u.map(e=>this.columnArray(e));for(let e=f.done;e<this.pushed;e++){let t=this.physOf(e),n=l[t];if(!(n>=r&&n<=i))continue;let a=Math.floor((n-r)/p);a>=c&&(a=c-1),f.seen[a]=1;for(let e=0;e<m.length;e++){let n=m[e][t];n===n&&(n<f.lo[e][a]&&(f.lo[e][a]=n),n>f.hi[e][a]&&(f.hi[e][a]=n))}}f.done=this.pushed;let h=0,g=new Uint8Array(c);for(let e=0;e<c;e++)if(f.seen[e]){for(let t=0;t<m.length;t++){let n=f.hi[t][e];if(n!==-1/0&&n!==f.lo[t][e]){g[e]=1;break}}h+=1+g[e]}let _=new Float64Array(h),v=u.map(()=>new Float64Array(h)),y=0;for(let e=0;e<c;e++){if(!f.seen[e])continue;let t=r+(e+.5)*p;_[y]=t;for(let t=0;t<m.length;t++){let n=f.lo[t][e];v[t][y]=n===1/0?NaN:n}if(y++,g[e]){_[y]=t;for(let t=0;t<m.length;t++){let n=f.hi[t][e];v[t][y]=n===-1/0?NaN:n}y++}}return f.pts={length:h,x:_,cols:new Map(u.map((e,t)=>[e,v[t]]))},f.pts}computed=new Set;get firstAbs(){return this.pushed-this.size}get endAbs(){return this.pushed}range(e,t,n){let r=Math.max(t,this.firstAbs),i=new Float64Array(Math.max(0,Math.min(n,this.pushed)-r)),a=this.columnArray(e);if(!a)return i.fill(NaN);for(let e=0;e<i.length;e++)i[e]=a[this.physOf(r+e)];return i}mirrorColumn(e){let t=this.columnArray(e);if(!t)return;let n=this.firstAbs,r=this.pushed,i=this.mirrors.get(e);if((!i||i.clears!==this.clears)&&(i={arr:new Float64Array(Math.max(16,r-n)),first:n,end:n,clears:this.clears,view:null},this.mirrors.set(e,i)),i.first===n&&i.end===r&&i.view)return i.view;if(n>i.first){let e=Math.max(0,i.end-n);e>0&&i.arr.copyWithin(0,n-i.first,i.end-i.first),i.first=n,i.end=n+e}if(i.arr.length<r-n){let e=new Float64Array(Math.max(r-n,i.arr.length*2));e.set(i.arr.subarray(0,i.end-i.first)),i.arr=e}for(let e=i.end;e<r;){let a=this.physOf(e),o=Math.min(r-e,(this.full?this.capacity:this.alloc)-a);i.arr.set(t.subarray(a,a+o),e-n),e+=o}return i.end=r,i.view=i.arr.subarray(0,r-n),i.view}writeComputed(e,t,n,r){let i=this.mirrors.get(e);i&&n<i.end&&(i.end=Math.max(i.first,n),i.view=null);let a=this.cols.get(e);(!a||!this.computed.has(e))&&(a||(a=this.newColumn(),this.cols.set(e,a),this.signalOrder.push(e)),this.computed.add(e)),this.unitByName.set(e,t);for(let e=0;e<r.length;e++){let t=n+e;t<this.firstAbs||t>=this.pushed||(a[this.physOf(t)]=r[e]??NaN)}}clearComputed(){for(let e of this.computed){this.cols.delete(e),this.unitByName.delete(e);for(let t of this.trackers.values())t.previous?.cols.delete(e)}this.signalOrder.splice(0,this.signalOrder.length,...this.signalOrder.filter(e=>!this.computed.has(e))),this.computed.clear(),this.decCache=null,this.timeDec=null,this.clears++}get columnNames(){return[this.timeColumn,...this.signalOrder]}unitOf(e){return e===this.timeColumn?this.timeUnit:this.unitByName.get(e)??``}columnValues(e){let t=this.size,n=new Float64Array(t),r=e===this.timeColumn?this.time:this.cols.get(e);if(!r)return n.fill(NaN),n;for(let e=0;e<t;e++)n[e]=r[this.full?(this.head+e)%this.capacity:e];return n}accumulate(e,t,n,r,i){let a=pW(i.length),o=n[t];if(Number.isNaN(o))return;let s=Math.floor(o/r),c=e.get(s);c||(c={...a.row,b:s},e.set(s,c));for(let e=0;e<i.length;e++){let n=i[e][t];if(Number.isNaN(n))continue;let r=a.lo[e],o=a.hi[e],s=c[r],l=c[o];c[r]=s==null?n:Math.min(s,n),c[o]=l==null?n:Math.max(l,n)}}decimateColumns(e,t,n,r,i){if(e===this.timeColumn&&this.timeMonotonic)return this.decimateTime(t,n,r,i);let a=e===this.timeColumn?this.time:this.cols.get(e),o=a?t.filter(e=>this.cols.has(e)):[],s=(r-n)/i,c=this.size;if(c>1&&e===this.timeColumn&&this.timeMonotonic&&a){let e=a[this.full?this.head:0],t=(a[this.full?(this.head+c-1)%this.capacity:c-1]-e)/(c-1);t>0&&t<s&&(s=.7*Math.max(t,(r-n)/(i*_W)))}let l=uW(s);{let t=this.decCache;t&&t.xKey===e&&t.colsKey===o.join(` `)&&t.bucket>0&&s>=t.bucket*.5&&s<=t.bucket*2&&(l=t.bucket)}if(!a||o.length===0||!(r>n)||!(l>0))return{x0:n,bucket:0,rows:[],columns:o};let u=o.map(e=>this.cols.get(e)),d=this.size,f=o.join(`\0`);this.debugLastScan=0;let p=this.decCache,m=p!==null&&e===this.timeColumn&&this.timeMonotonic&&p.xKey===e&&p.colsKey===f&&p.bucket===l&&this.pushed>=p.pushed&&this.pushed-p.pushed<d&&p.map.size<this.capacity*2,h=p!==null&&p.xKey===e&&p.colsKey===f&&p.bucket===l&&p.pushed===this.pushed,g=this.pushed-d,_=e===this.timeColumn&&this.timeMonotonic?g:Math.max(g,this.passStart(e,a)),v=p!==null&&(_>g||!this.full)&&p.xKey===e&&p.colsKey===f&&p.bucket===l&&p.passStart===_&&p.pushed>=_&&p.pushed<=this.pushed,y;if(h&&p)y=p.map;else if(v&&p){y=p.map;for(let e=p.pushed;e<this.pushed;e++)this.debugLastScan++,this.accumulate(y,this.physOf(e),a,l,u);p.pushed=this.pushed}else if(m&&p){y=p.map;let e=this.pushed-p.pushed;for(let t=d-e;t<d;t++){let e=this.full?(this.head+t)%this.capacity:t;this.debugLastScan++,this.accumulate(y,e,a,l,u)}if(this.full&&d>0){let e=a[this.head];if(!Number.isNaN(e)){let t=Math.floor(e/l);for(let e=p.lowB;e<t;e++)y.delete(e);y.delete(t);for(let e=0;e<d;e++){let n=(this.head+e)%this.capacity,r=a[n];if(!Number.isNaN(r)){if(Math.floor(r/l)>t)break;this.debugLastScan++,this.accumulate(y,n,a,l,u)}}p.lowB=t}}p.pushed=this.pushed}else{y=new Map;let t=1/0;for(let e=_;e<this.pushed;e++){let n=this.physOf(e),r=a[n];if(Number.isNaN(r))continue;this.debugLastScan++,this.accumulate(y,n,a,l,u);let i=Math.floor(r/l);i<t&&(t=i)}this.decCache={xKey:e,colsKey:f,cols:o,bucket:l,map:y,pushed:this.pushed,lowB:Number.isFinite(t)?t:0,passStart:_}}let b=Math.floor(n/l),x=Math.floor(r/l),S=[];for(let e of y.values()){let t=e.b;t>=b&&t<=x&&S.push(e)}return S.sort((e,t)=>Number(e.b)-Number(t.b)),{x0:0,bucket:l,rows:S,columns:o}}passStart(e,t){let n=this.pushed-this.size,r=this.passTrack;(!r||r.key!==e||r.clears!==this.clears)&&(r=this.passTrack={key:e,clears:this.clears,done:n,prevX:NaN,cuts:[]});let{x0:i,x1:a}=this.columnBounds(e),o=(a-i)/2;for(let e=Math.max(r.done,n);e<this.pushed;e++){let n=t[this.physOf(e)];Number.isNaN(n)||(n<r.prevX-o&&(r.cuts.push({abs:e,drop:r.prevX-n}),r.cuts.length>64&&r.cuts.shift()),r.prevX=n)}for(r.done=this.pushed;r.cuts.length>0&&r.cuts[0].abs<n;)r.cuts.shift();for(let e=r.cuts.length-1;e>=0;e--)if(r.cuts[e].drop>o)return r.cuts[e].abs;return n}timeIndex(e){let t=0,n=this.size;for(;t<n;){let r=t+n>>>1;this.time[this.full?(this.head+r)%this.capacity:r]<e?t=r+1:n=r}return t}foldBuckets(e,t,n,r,i){this.eachBucketRun(t,n,r,(t,n,r)=>e.fold(e.row(t),i,n,r))}eachBucketRun(e,t,n,r){if(t<=e)return;this.debugLastScan+=t-e;let i=this.time,a=e=>Math.floor(i[e]/n),o=(e,t)=>{let n=e;for(;n<t;){let e=a(n),i=n,o=1;for(;n+o<t&&a(n+o)===e;)i=n+o,o*=2;let s=i+1,c=Math.min(n+o,t);for(;s<c;){let t=s+c>>>1;a(t)===e?s=t+1:c=t}r(e,n,s),n=s}};if(!this.full)return o(e,t);let s=(this.head+e)%this.capacity,c=s+(t-e);if(c<=this.capacity)return o(s,c);o(s,this.capacity),o(0,c-this.capacity)}decimateTime(e,t,n,r){let i=this.timeBuckets(e,t,n,r);if(!i.store)return{x0:t,bucket:0,rows:[],columns:i.cols};let a=pW(i.cols.length),o=()=>i.store.toRows(i.i0,i.i1,a.row,a.lo,a.hi),s=this.historyDec;return{x0:0,bucket:i.bucket,rows:s?.store===i.store?s.rows??=o():o(),columns:i.cols}}decimatePoints(e,t,n,r,i){if(e===this.timeColumn&&this.timeMonotonic){let e=this.timeBuckets(t,n,r,i);return e.store?e.store.toPoints(e.i0,e.i1,e.cols):{length:0,x:new Float64Array,cols:new Map(e.cols.map(e=>[e,new Float64Array]))}}let a=this.decimateColumns(e,t,n,r,i);return XU(a.rows,a.columns,a.x0,a.bucket)}timeBuckets(e,t,n,r){let i=e.filter(e=>this.cols.has(e)),a=this.size,o={cols:i,bucket:0,store:null,i0:0,i1:0};if(i.length===0||!(n>t)||a===0)return o;let s=e=>this.full?(this.head+e)%this.capacity:e,c=this.time[s(0)],l=this.time[s(a-1)],u=(n-t)/r;if(a>1){let e=(l-c)/(a-1);e>0&&e<u&&(u=.7*Math.max(e,(n-t)/(r*_W)))}let d=uW(u),f=i.join(` `),p=this.timeDec;if(p&&p.colsKey===f&&u>=p.bucket*.5&&u<=p.bucket*2&&(d=p.bucket),!(d>0))return o;let m=i.map(e=>this.cols.get(e)),h=Math.floor(t/d),g=Math.floor(n/d);this.debugLastScan=0;let _=e=>({cols:i,bucket:d,store:e,i0:e.lowerBound(h),i1:e.lowerBound(g+1)});if(n<l-(n-t)){let e=this.timeIndex(h*d),t=this.timeIndex((g+1)*d),n=this.pushed-a,r=`${f}|${d}|${h}|${g}|${n+e}|${n+t}|${this.clears}`;if(this.historyDec?.key!==r){let n=new cW(i.length,d);this.foldBuckets(n,e,t,d,m),this.historyDec={key:r,store:n}}return _(this.historyDec.store)}let v=p?this.pushed-p.pushed:0;if(p&&p.colsKey===f&&p.bucket===d&&v>=0&&v<a){let e=p.store;if(h<p.fromB){let t=new cW(i.length,d);this.foldBuckets(t,this.timeIndex(h*d),this.timeIndex(p.fromB*d),d,m);for(let n=t.end-1;n>=t.start;n--){let r=e.row(t.b[n]);for(let i=0;i<t.nc;i++)e.lo[i][r]=t.lo[i][n],e.hi[i][r]=t.hi[i][n]}p.fromB=h}v>0&&this.foldBuckets(e,a-v,a,d,m);let t=Math.floor(c/d);return this.full&&t>=p.fromB&&(e.dropBelow(t),e.reset(e.row(t)),this.foldBuckets(e,0,this.timeIndex((t+1)*d),d,m),p.fromB=t),h>p.fromB&&(e.dropBelow(h),p.fromB=h),p.pushed=this.pushed,_(e)}let y=new cW(i.length,d),b=this.timeIndex(h*d);return this.foldBuckets(y,b,a,d,m),this.timeDec={colsKey:f,bucket:d,store:y,pushed:this.pushed,fromB:b===0?Math.floor(c/d):h},_(y)}lastValue(e){let t=e===this.timeColumn?this.time:this.cols.get(e);return!t||this.size===0?NaN:t[this.full?(this.head-1+this.capacity)%this.capacity:this.count-1]}xTravel(e,t){let n=this.columnArray(e),r=this.size;if(!n||r<2)return NaN;let i=e=>this.full?(this.head+e)%this.capacity:e,a=this.time[i(r-1)],o=0,s=NaN,c=a;for(let e=r-1;e>=0;e--){let r=i(e),l=this.time[r];if(l<a-t)break;let u=n[r];Number.isNaN(u)||(s>u&&(o+=s-u),s=u,c=l)}let l=a-c;return l>0&&l<t?o*t/l:o}latestTime(){return this.lastValue(this.timeColumn)}xAtTime(e,t,n=!1){let r=this.columnArray(e),i=this.size;if(!r||i===0||!this.timeMonotonic)return NaN;let a=e=>this.full?(this.head+e)%this.capacity:e,o=0,s=i-1;if(t<=this.time[a(0)])return r[a(0)];if(t>=this.time[a(s)])return r[a(s)];for(;s-o>1;){let e=o+s>>1;this.time[a(e)]<=t?o=e:s=e}let c=a(o),l=a(s),u=r[c],d=r[l];if(n||!(d>=u))return u;let f=this.time[c],p=this.time[l];return p>f?u+(d-u)*(t-f)/(p-f):u}boundsCache=new Map;columnBounds(e){let t=e===this.timeColumn?this.time:this.cols.get(e),n=this.size;if(!t||n===0)return{x0:0,x1:0};if(t===this.time&&this.timeMonotonic)return{x0:this.time[this.full?this.head:0],x1:this.time[this.full?(this.head+n-1)%this.capacity:n-1]};let r=this.pushed-n,i=this.boundsCache.get(e);if(i&&i.version===this.version)return i.b;(!i||i.clears!==this.clears||i.loAbs<r||i.hiAbs<r)&&(i={version:-1,clears:this.clears,done:r,lo:1/0,hi:-1/0,loAbs:1/0,hiAbs:1/0,b:{x0:0,x1:0}},this.boundsCache.set(e,i));for(let e=Math.max(i.done,r);e<this.pushed;e++){let n=t[this.physOf(e)];Number.isNaN(n)||(n<=i.lo&&(i.lo=n,i.loAbs=e),n>=i.hi&&(i.hi=n,i.hiAbs=e))}return i.done=this.pushed,i.version=this.version,i.b=Number.isFinite(i.lo)?{x0:i.lo,x1:i.hi}:{x0:0,x1:0},i.b}toDataset(e){let t=[this.timeColumn,...this.signalOrder],n=[this.timeUnit,...this.signalOrder.map(e=>this.unitByName.get(e)??``)],r=this.size,i=e&&e>0&&r>e?Math.ceil(r/e):1,a=e=>{let t=this.full?(this.head+e)%this.capacity:e,n={[this.timeColumn]:this.time[t]};for(let e of this.signalOrder){let r=this.cols.get(e)[t];n[e]=Number.isNaN(r)?null:r}return n},o=this.pushed-r,s=i>1?(i-o%i)%i:0,c=[];for(let e=s;e<r;e+=i)c.push(a(e));return r>0&&(c.length===0||(r-1-s)%i!=0)&&c.push(a(r-1)),{meta:``,columnNames:t,units:n,rows:c}}}}));function bW(){let e=globalThis.crypto;if(!e?.subtle)throw Error(`WebCrypto SubtleCrypto is not available`);return e.subtle}function xW(e){let t=``;for(let n=0;n<e.length;n++)t+=String.fromCharCode(e[n]);return btoa(t)}function SW(e){let t=atob(e),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n}async function CW(e,t){let n=new TextEncoder,r=await bW().importKey(`raw`,n.encode(e),`PBKDF2`,!1,[`deriveKey`]);return bW().deriveKey({name:`PBKDF2`,salt:SW(t),iterations:LW,hash:`SHA-256`},r,{name:`AES-GCM`,length:256},!1,[`encrypt`,`decrypt`])}async function wW(e,t){let n=SW(t.iv),r=SW(t.ciphertext),i=await bW().decrypt({name:`AES-GCM`,iv:n},e,r);return new Uint8Array(i)}async function TW(e,t,n,r){let i=await bW().decrypt({name:`AES-GCM`,iv:t,additionalData:r},e,n);return new Uint8Array(i)}async function EW(e,t){return JSON.parse(new TextDecoder().decode(await wW(e,t)))}async function DW(e,t){try{return await EW(e,t)===IW}catch{return!1}}function OW(e){let t=RW.exec(e.trim());return t?{auth:t[1],secret:t[2]??null}:{auth:e,secret:null}}function kW(e){return bW().importKey(`raw`,e,{name:`AES-GCM`,length:256},!1,[`encrypt`,`decrypt`])}function AW(e,t,n){return jW(e,t,n)}async function jW(e,t,n,r){let i=r??globalThis.crypto.getRandomValues(new Uint8Array(12)),a=new Uint8Array(await bW().encrypt({name:`AES-GCM`,iv:i,additionalData:new TextEncoder().encode(n)},e,t));return{iv:xW(i),ct:xW(a)}}async function MW(e,t,n){return new Uint8Array(await bW().decrypt({name:`AES-GCM`,iv:SW(t.iv),additionalData:new TextEncoder().encode(n)},e,SW(t.ct)))}function NW(e,t,n){return PW(e,t,n)}async function PW(e,t,n,r,i){let a=xW(r??globalThis.crypto.getRandomValues(new Uint8Array(16))),o=await jW(await CW(e,a),t,n,i);return{kdf:{name:`PBKDF2`,hash:`SHA-256`,iterations:LW,salt:a},...o}}async function FW(e,t,n){let r=t?.kdf;if(r?.name!==`PBKDF2`||r.hash!==`SHA-256`||r.iterations!==LW||typeof r.salt!=`string`)throw Error(`unsupported_kdf`);return MW(await CW(e,r.salt),t,n)}var IW,LW,RW,zW,BW=c((()=>{IW=`kymoscope-live-key-check-v1`,LW=6e5,RW=/^((?:kymoscope|prism)_[A-Za-z0-9_-]+)(?:\.([A-Za-z0-9_-]+))?$/,new TextEncoder().encode(`kymoscope-device-wrap-v1`),new TextEncoder().encode(`kymoscope-sender-bind-v1`),zW=`kymoscope-workbook-export-v2`}));function VW(e){let t=new Uint8Array(e),n=t.length>0&&t[0]&128?2:1;return t.length<n+UW+WW?null:{kind:t[0]&-129,keyId:n===2?t[1]:null,iv:t.subarray(n,n+UW),ciphertext:t.subarray(n+UW),aad:t.subarray(0,n)}}async function HW(e,t){let n=VW(t);if(!n)return null;let r=typeof e==`function`?await e(n.keyId):e;if(!r)return null;let i=await TW(r,n.iv,n.ciphertext,n.aad);return{kind:n.kind,plaintext:i}}var UW,WW,GW=c((()=>{BW(),UW=12,WW=16}));function KW(e){if(e.byteLength<8)throw eG(`block schema`,`short`);let t=new DataView(e.buffer,e.byteOffset,e.byteLength);if(t.getUint8(0)!==YW)throw eG(`block schema`,`version ${t.getUint8(0)}`);let n=t.getUint16(2,!0),r=t.getUint32(4,!0),i=new TextDecoder(`utf-8`,{fatal:!0}),a=[],o=8;try{for(let r=0;r<n;r++){if(o+3>e.byteLength)throw eG(`block schema`,`short channel table`);let n=t.getUint8(o),r=t.getUint8(o+1),s=t.getUint8(o+2);if(o+=3,n!==4&&n!==8)throw eG(`block schema`,`value size ${n}`);if(o+r+s>e.byteLength)throw eG(`block schema`,`short channel table`);a.push({name:i.decode(e.subarray(o,o+r)),unit:i.decode(e.subarray(o+r,o+r+s)),size:n}),o+=r+s}}catch(e){throw e instanceof RangeError?e:eG(`block schema`,`invalid text`)}return{id:r,channels:a}}async function qW(e,t){let n=new Blob([e]).stream().pipeThrough(new DecompressionStream(`deflate`)).getReader(),r=new Uint8Array(t),i=0;try{for(;;){let{done:e,value:a}=await n.read();if(e)break;if(i+a.length>t)throw eG(`block`,`body larger than its header says`);r.set(a,i),i+=a.length}}catch(e){throw await n.cancel().catch(()=>{}),e instanceof RangeError?e:eG(`block`,`body is not valid deflate`)}if(i!==t)throw eG(`block`,`body size mismatch`);return r}async function JW(e,t){if(e.byteLength<QW)throw eG(`block`,`short`);let n=new DataView(e.buffer,e.byteOffset,e.byteLength);if(n.getUint8(0)!==YW)throw eG(`block`,`version ${n.getUint8(0)}`);let r=n.getUint8(1),i=n.getUint16(2,!0),a=n.getUint32(4,!0),o=t.get(n.getUint32(8,!0));if(!o)return null;if(o.channels.length!==i)throw eG(`block`,`channel count differs from its schema`);let s=n.getFloat64(12,!0),c=Math.max(0,a-1),l=4*c+o.channels.reduce((e,t)=>e+t.size*a,0);if(l>$W)throw eG(`block`,`too large`);let u;if(r&XW)u=await qW(e.subarray(QW),l);else if(u=e.subarray(QW),u.byteLength<l)throw eG(`block`,`body size mismatch`);let d=new DataView(u.buffer,u.byteOffset,u.byteLength),f=new Float64Array(a),p=0;a&&(f[0]=s);for(let e=1;e<a;e++)p+=d.getInt32(4*(e-1),!0),f[e]=s+p/1e6;let m=4*c,h={},g={};for(let e of o.channels){let t=new Uint8Array(a*e.size);for(let n=0;n<e.size;n++)for(let r=0;r<a;r++)t[r*e.size+n]=u[m+n*a+r];h[e.name]=e.size===4?new Float32Array(t.buffer):new Float64Array(t.buffer),e.unit&&(g[e.name]=e.unit),m+=a*e.size}return{block:{t:f,columns:h,units:g},historical:(r&ZW)!==0}}var YW,XW,ZW,QW,$W,eG,tG=c((()=>{YW=2,XW=1,ZW=2,QW=20,$W=64*1024*1024,eG=(e,t)=>RangeError(`${e}: ${t}`)}));function nG(e){let t=Array.from(e,e=>e.toString(16).padStart(2,`0`)).join(``);return`${t.slice(0,8)}-${t.slice(8,12)}-${t.slice(12,16)}-${t.slice(16,20)}-${t.slice(20)}`}function rG(e){if(e.length<56||aG.some((t,n)=>e[n]!==t))throw RangeError(`not a KRC1 chunk`);let t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=t.getUint16(4,!0);if(n!==1)throw RangeError(`KRC version ${n}`);let r=t.getUint16(6,!0);if(r<56)throw RangeError(`KRC header too short`);return{recordingId:nG(e.subarray(8,24)),seq:t.getUint32(24,!0),count:t.getUint32(28,!0),bytes:t.getUint32(32,!0),headerBytes:r,t0:t.getFloat64(40,!0),t1:t.getFloat64(48,!0)}}function iG(e){let t=rG(e),n=new DataView(e.buffer,e.byteOffset,e.byteLength),r=Math.min(e.length,t.bytes),i=[],a=t.headerBytes;for(;i.length<t.count&&a+12<=r;){let t=n.getUint32(a+8,!0);if(a+12+t>r)break;i.push({at:n.getFloat64(a,!0),bytes:e.subarray(a+12,a+12+t)}),a+=12+t}return{header:t,messages:i,truncated:i.length<t.count}}var aG,oG=c((()=>{aG=[75,82,67,49]}));function sG(e){let t=new Map;return async n=>{if(n.length===0)return null;let r=n[0]&128?2:1;if(n.length<r+cG+lG)return null;let i=r===2?n[1]:null,a=t.get(i),o=[...a?[a]:[],...e.filter(e=>e.keyId===i&&e.key!==a).map(e=>e.key)];for(let e of o)try{let a=await TW(e,n.subarray(r,r+cG),n.subarray(r+cG),n.subarray(0,r));return t.set(i,e),{kind:n[0]&-129,plaintext:a}}catch{}return null}}var cG,lG,uG=c((()=>{BW(),GW(),cG=12,lG=16}));async function*dG(e){let t=0;for(;t+56<=e.size;){let n=rG(await e.read(t,56));if(yield await e.slice(t,n.bytes),n.bytes<=56)return;t+=n.bytes}}function fG(e){let t=e.filter(e=>e&&typeof e.t==`number`&&Array.isArray(e.signals)),n={},r={};return t.forEach((e,i)=>{for(let a of e.signals){if(!a||typeof a.name!=`string`)continue;let e=n[a.name]??=new Float64Array(t.length).fill(NaN);e[i]=typeof a.value==`number`?a.value:NaN,a.unit&&!r[a.name]&&(r[a.name]=a.unit)}}),{t:t.map(e=>e.t),columns:n,units:r}}function pG(e){let t=2166136261^e.length;for(let n=0,r=Math.min(e.length,64);n<r;n++)t=Math.imul(t^e[n],16777619);return t>>>0}async function*mG(e,t,n,r){let i=sG(e.keys??[]),a=new Map,o=new Map;for await(let e of dG(t)){let{header:t,messages:s}=iG(e);n.t0??=t.t0;for(let e of s){let t=pG(e.bytes),s=o.get(t);if(s&&_G(s,e.bytes))continue;o.set(t,e.bytes),o.size>gG&&o.delete(o.keys().next().value);let c=await i(e.bytes);if(!c){n.lost++;continue}try{if(c.kind===5){let e=KW(c.plaintext);a.set(e.id,e);continue}if(c.kind===4){let t=await JW(c.plaintext,a);if(!t){n.lost++;continue}(r===void 0||r===!!t.historical)&&(yield{at:e.at,t:t.block.t,columns:t.block.columns,units:t.block.units??{},historical:t.historical});continue}if(r)continue;if(c.kind===3){let t=KU(c.plaintext);yield{at:e.at,t:t.t,columns:t.columns,units:t.units??{}}}else if(c.kind===2){let t=UU(c.plaintext);yield{at:e.at,...fG(Array.isArray(t?.frames)?t.frames:[])}}}catch{n.lost++}}}}var hG,gG,_G,vG,yG=c((()=>{GU(),YU(),yW(),GW(),tG(),oG(),uG(),hG=8192,gG=4096,_G=(e,t)=>e.length===t.length&&e.every((e,n)=>e===t[n]),vG={id:`krc`,label:`Kymoscope recording`,extensions:[],sniff:()=>!1,async plan(e,t){let n=[mW],r=new Map([[mW,`s`]]),i={lost:0,t0:null},a=0,o=!1;for await(let s of mG(e,t,i)){a+=s.t.length,s.historical&&(o=!0);for(let e of Object.keys(s.columns))e!==`ElapsedTime`&&(r.has(e)?!r.get(e)&&s.units[e]&&r.set(e,s.units[e]):(n.push(e),r.set(e,s.units[e]??``)))}let s=n.map(e=>({name:e,unit:r.get(e)??``})),c=i.lost?[`${i.lost} ${i.lost===1?`message`:`messages`} couldn't be opened with the keys this browser has.`]:[];return{format:`Kymoscope recording`,startTime:i.t0===null?null:new Date(i.t0).toISOString(),groups:[{name:`Recording`,channels:s,samples:a,time:{kind:`timestamps`},rateHz:null}],meta:{},events:[],notes:c,state:{names:n,backlog:o}}},async*stream(e){let{names:t,backlog:n=!1}=e.plan.state,r=e.selection.find(e=>e.group===0)?.channels??[],i=new Map(r.map((e,n)=>[t[e],n])),a=i.get(mW),o=()=>r.map(()=>new Float64Array(hG).fill(NaN)),s=new Float64Array(hG),c=o(),l=0,u=0,d=0,f=-1/0,p=0,m=null,h=()=>{let e={group:0,time:s.slice(0,l),start:u,length:l,columns:c.map(e=>e.slice(0,l))};return u+=l,l=0,s=new Float64Array(hG),c=o(),e};function*g(e){let t=e.t.length;for(let n=0;n<t;){let r=Math.min(t-n,hG-l);for(let t=0;t<r;t++){let r=+e.t[n+t]+d;m??=r,s[l+t]=r-m}if(a!==void 0)for(let t=0;t<r;t++)c[a][l+t]=+e.t[n+t];for(let[t,a]of Object.entries(e.columns)){let e=t===`ElapsedTime`?void 0:i.get(t);if(e===void 0)continue;let o=c[e];if(a instanceof Float64Array||a instanceof Float32Array)o.set(a.subarray(n,n+r),l);else for(let e=0;e<r;e++)o[l+e]=+a[n+e]}l+=r,n+=r,l===hG&&(yield h())}}let _=n?mG(e.files,e.io,{lost:0,t0:null},!0):null,v=async()=>{for(let e=await _?.next();e&&!e.done;e=await _.next())if(e.value.t.length)return e.value;return null},y=await v();for await(let t of mG(e.files,e.io,{lost:0,t0:null},n?!1:void 0)){if(e.signal?.aborted)return;let n=t.t.length;if(n!==0){for(+t.t[0]+d<f&&(d=f+Math.max(0,(t.at-p)/1e3)-+t.t[0]),p=t.at;y&&+y.t[0]<+t.t[0];y=await v())yield*g(y);yield*g(t),f=+t.t[n-1]+d}}for(;y&&!e.signal?.aborted;y=await v())yield*g(y);l>0&&(yield h())}}})),bG=u({IMPORTERS:()=>SG,importerFor:()=>xG});function xG(e){let t=SG[e];if(!t)throw Error(`No importer for format ${e}.`);return t}var SG,CG=c((()=>{VB(),qB(),sV(),NV(),uH(),zH(),YH(),yG(),SG={mdf:BB,edf:KB,xdf:oV,tdms:MV,hdf5:lH,mat:RH,comtrade:JH,krc:vG}}));nR(),TL();var wG=()=>new jw(`cancelled`);function TG(){let e=Mw(rR);return e.postMessage({type:`init`,h5Url:new URL(iR,location.href).href}),e}var EG=null,DG=e=>{typeof requestIdleCallback==`function`?requestIdleCallback(e,{timeout:5e3}):setTimeout(e,1e3)};function OG(e,t=TG){t===TG&&typeof Worker>`u`||(EG&&EG.make!==t&&(EG.w.terminate(),EG=null),EG??={w:t(),h5:!1,make:t},e&&!EG.h5&&(EG.h5=!0,EG.w.postMessage({type:`warm`})))}function kG(e){if(EG?.make!==e)return{w:e(),rewarm:null};let{w:t,h5:n}=EG;return EG=null,{w:t,rewarm:n}}function AG(e,t,n,r,i){return!r&&typeof Worker>`u`?jG(e,t,n,i):NG(e,t,n,r??TG)}function jG(e,t,n,r=async e=>(await Promise.resolve().then(()=>(CG(),bG))).importerFor(e)){let i=new tR(t.main),a=null,o=null,s=e=>e.catch(e=>{throw n?.aborted?wG():hL(e)});return{plan:()=>s((async()=>(a=await r(e),o=await KL(a,t,i)))()),read:(e,r,c={})=>(i.bytesRead=0,s(ZL(a,t,o,i,e,r,{...c,signal:n}))),close(){}}}var MG=3e4;function NG(e,t,n,r){let{w:i,rewarm:a}=kG(r),o=null,s=Promise.resolve(),c=Date.now(),l=-1,u=0,d=!1,f=e=>{let t=o;o=null,t?.reject(e)},p=e=>{d=!0,i.terminate(),f(e)},m=setInterval(()=>{o&&u===0&&Date.now()-c>MG&&p(Error(gL))},1e3),h=()=>p(wG());n?.addEventListener(`abort`,h,{once:!0}),i.onmessage=e=>{let t=e.data,n=o;n&&((t.type!==`alive`||t.work!==l)&&(c=Date.now()),t.type===`alive`?l=t.work:t.type===`plan`?(o=null,n.resolve(t.plan)):t.type===`progress`?n.on.progress?.(t.fraction):t.type===`chunk`?(u++,s=s.then(()=>n.on.chunk(t.chunk)).then(()=>{u--,c=Date.now(),i.postMessage({type:`ack`})},e=>{u--,p(e instanceof Error?e:Error(String(e)))})):t.type===`done`?s.then(()=>{o===n&&(o=null,n.resolve(t.result))}):f(Error(t.message)))},i.onerror=e=>f(e instanceof Error?e:Error(`The import worker failed.`));let g=(e,t={})=>new Promise((r,a)=>{if(n?.aborted){a(wG());return}if(d){a(Error(gL));return}o={resolve:r,reject:a,on:t},c=Date.now(),i.postMessage(e)});return{plan:()=>g({type:`plan`,importer:e,files:t}),read:(e,t,n)=>g({type:`read`,selection:e,mode:t},n),close:()=>{clearInterval(m),n?.removeEventListener(`abort`,h),i.terminate(),a!==null&&DG(()=>OG(a,r))}}}Ue();var PG=12e3,FG=(e,t)=>t.map(t=>({group:t,channels:e.groups[t].channels.map((e,t)=>t)}));function IG(e,t){let n=null;for(let r of t){let t=e.groups[r.group];!t.irregular&&(!n||t.samples>n.samples)&&(n={samples:t.samples,rate:t.rateHz})}return n?.rate??null}function LG(e,t,n,r){return{format:e.format,importer:t,startTime:e.startTime,groups:e.groups.map(e=>({name:e.name,channels:e.channels.length,samples:e.samples,rateHz:e.rateHz})),selection:n,combined:n.length>1?{groups:n.length,rateHz:IG(e,n)}:null,splitKey:r,channels:n.reduce((e,t)=>e+t.channels.length,0),notes:e.notes,meta:e.meta,events:[]}}async function RG(e,t,n,r,i,a){let o={meta:``,columnNames:n.columns.map(e=>e.name),units:n.columns.map(e=>e.unit),rows:Re(n.table)},s=new Xw(o);return{id:e,name:t,kind:`memory`,source:s,schema:await s.getSchema(),data:o,file:r,companions:i,info:{...a,events:n.events}}}async function zG(e,t,n,r,i,a,o,s,c){let l=YF().then(e=>e.connect());l.catch(()=>void 0);let u=dI(),d=JL(r,i),f=new pL({insertArrowTable:async(e,t)=>(await l).insertArrowTable(e,t)},u,d);try{let r=await n.read(i,`stream`,{progress:c,chunk:e=>f.append(e)});if(await f.flush(),f.rows===0)throw Error(`${t}: the file has no samples.`);let p=await l,m=await _I.attach(p,u,new Map(d.map(e=>[e.name,e.unit]))),h=await m.getSchema(),g=await m.sampleRows(PG);return{id:e,name:t,kind:`duckdb`,source:m,schema:h,data:{meta:``,columnNames:h.map(e=>e.name),units:h.map(e=>e.unit),rows:g},file:a,companions:o,info:{...s,events:r.events}}}catch(e){let t=await l.catch(()=>null);throw await t?.query(`DROP TABLE IF EXISTS ${XF(u)}`).catch(()=>void 0),await t?.close().catch(()=>void 0),e}}async function BG(e,t){let{main:n,companions:r}=e,i=AG(e.format,{main:n,companions:r,keys:e.keys},t.signal,t.createWorker,t.find),a=[];try{t.priorInMemoryValues+n.size/8>1e8&&YF().catch(()=>void 0);let o=await i.plan(),s=t.selection??t.initial??FG(o,o.defaultGroups??o.groups.map((e,t)=>t)),c=s.reduce((e,t)=>e+t.channels.length,0);if(!t.selection&&t.chooseChannels&&(t.pickChannels||o.pick||c>2e3)){let e=await t.chooseChannels({file:n.name,format:o.format,groups:o.groups.map(e=>({name:e.name,rateHz:e.rateHz,samples:e.samples,channels:e.channels.map(e=>({name:e.name,unit:e.unit}))})),selection:s,estimate:e=>XL(o,e,n.size),budget:vI,used:t.priorInMemoryValues,notes:o.notes});if(!e)throw new jw(`cancelled`);s=e.filter(e=>e.channels.length>0)}if(s.length===0)throw Error(`${n.name}: no channels to read.`);let l=!t.split&&(s.length===1||s.every(e=>o.groups[e.group].time.kind!==`index`))?[s]:s.map(e=>[e]),u=l.length>1?crypto.randomUUID():null,d=t.priorInMemoryValues;for(let s of l){let c=XL(o,s,n.size),f=l.length>1?`${n.name} · ${o.groups[s[0].group].name}`:n.name,p=LG(o,e.format,s,u),m=crypto.randomUUID();if(bI(0,c,d)===`memory`){let e=await i.read(s,`memory`,{progress:t.onProgress});a.push(await RG(m,f,e,n,r,p)),d+=c}else a.push(await zG(m,f,i,o,s,n,r,p,t.onProgress))}return a}catch(e){for(let e of a)e.source.dispose().catch(()=>void 0);throw t.signal?.aborted?new jw(`cancelled`):e}finally{i.close()}}function VG(e){return e.filter(e=>e.type===`number`).map(e=>e.name)}function HG(e,t,n=5e5){let r=1/0,i=-1/0,a=Math.max(1,Math.ceil(e.length/n));for(let n=0;n<e.length;n+=a){let a=e[n][t];typeof a==`number`&&(a<r&&(r=a),a>i&&(i=a))}if(!Number.isFinite(r)||!Number.isFinite(i))return{min:0,max:1};if(r===i){let e=Math.abs(r)*.05||1;return{min:r-e,max:i+e}}let o=(i-r)*.04;return{min:r-o,max:i+o}}function UG(e){switch(e.kind){case`multiband`:return e.series.length;case`parallelcoords`:return e.pcColumns.length;case`barchart`:return e.bcValueCols.length;case`radar`:return e.rdAxesCols.length;case`areachart`:return e.acYCols.length;case`cdfchart`:return e.cdValueCols.length;case`losscurve`:return e.lcLeftCols.length+e.lcRightCols.length;case`gauge`:return e.ggGauges.length;case`heatmap`:return e.hmColumns.length;case`xyzmesh`:return e.xyzColumns?.length??0;default:return 0}}function WG(e,t=6){if(!Number.isFinite(e)||e<=0)return 1;let n=e/t,r=10**Math.floor(Math.log10(n)),i=n/r,a=1;return a=i<=1?1:i<=2?2:i<=5?5:10,a*r}function GG(e){return Math.max(2,Math.min(6,Math.floor(e/64)))}function KG(e,t,n,r){let i=Math.max(e,t)-Math.min(e,t),a=n!==void 0&&n>0&&Number.isFinite(n)?n:WG(i,6);(a<=0||!Number.isFinite(a))&&(a=WG(Math.max(i,1),6));let o=r!==void 0&&r>0&&Number.isFinite(r)?r:a/5;return(o<=0||!Number.isFinite(o))&&(o=a/5),{majorStep:a,minorStep:o}}function qG(e,t,n){let r=Math.min(e,t),i=Math.max(e,t);if(n<=0||!Number.isFinite(n))return[];let a=[],o=Math.ceil(r/n-1e-12)*n,s=0;for(;o<=i+n*1e-9&&s++<1e4;)a.push(o),o+=n;return a}function JG(e,t,n,r){let i=Math.min(e,t),a=Math.max(e,t);if(n<=0||!Number.isFinite(n))return[];let o=e=>r.some(t=>Math.abs(e-t)<=(Math.abs(t)+1)*1e-9+1e-9),s=[],c=Math.ceil(i/n-1e-12)*n,l=0;for(;c<=a+n*1e-9&&l++<2e4;)o(c)||s.push(c),c+=n;return s}var YG={[-12]:`p`,[-9]:`n`,[-6]:`µ`,[-3]:`m`,0:``,3:`k`,6:`M`,9:`G`,12:`T`};function XG(e){if(!(e>0)||!Number.isFinite(e))return 0;let t=Math.max(0,-Math.floor(Math.log10(e)+1e-9));for(let n=t;n<=t+2;n++){let t=e*10**n;if(Math.abs(t-Math.round(t))<=1e-6*t)return n}return t+1}function ZG(e,t){if(!Number.isFinite(e))return`—`;if(!(t>0)||!Number.isFinite(t))return QG(e);if(Math.abs(e)<t*1e-6)return`0`;let n=Math.floor(Math.log10(t)+1e-9);if(n>=3||n<-3){let r=3*Math.ceil((n-1)/3);if(r<-12||r>12)return e.toExponential(2);let i=e/10**r;if(r>0||Math.abs(i)<1e3)return i.toFixed(XG(t/10**r))+YG[r]}return e.toFixed(XG(t))}function QG(e){if(!Number.isFinite(e))return`—`;if(e===0)return`0`;let t=Math.abs(e);if(t<1e-12||t>=0x38d7ea4c68000)return e.toExponential(3);let n=0;(t<.001||t>=1e6)&&(n=3*Math.floor(Math.log10(t)/3));let r=e/10**n,i=Math.max(0,3-Math.floor(Math.log10(Math.abs(r))));return n!==0&&Math.abs(+r.toFixed(i))>=1e3&&(n+=3,r/=1e3,i=3),r.toFixed(i)+YG[n]}var $G=[`#fb923c`,`#60a5fa`,`#4ade80`,`#f87171`,`#facc15`,`#22d3ee`,`#f472b6`,`#2dd4bf`,`#94a3b8`,`#a3e635`];function eK(e,t,n,r=$G){let i=r.length>0?r:$G;return e[t]??i[n%i.length]}function tK(e){return[e===`light`?`#000000`:`#ffffff`,...$G.slice(0,9)]}function nK(e,t=`dark`){let n=(e??[]).filter(e=>typeof e==`string`&&/^#[0-9a-f]{3}([0-9a-f]{3})?$/i.test(e));return n.length>0?n:tK(t)}var rK=[`class`,`data-theme`,`data-color-scheme`];function iK(e){return e?.closest(`[data-color-scheme]`)??document.documentElement}function aK(e){return iK(e).getAttribute(`data-color-scheme`)===`light`?`light`:`dark`}function oK(e,t){let n=new MutationObserver(t),r=new Set([document.documentElement,iK(e)]);for(let e of r)n.observe(e,{attributes:!0,attributeFilter:rK});return()=>n.disconnect()}var sK=[{value:`span`,label:`Span (max − min)`},{value:`mean`,label:`Mean`},{value:`max`,label:`Max`},{value:`min`,label:`Min`}];function cK(e,t){let n=[],r=-1,i=0,a=0,o=0;for(let s=0;s<e.length;s++){let c=e[s][t];typeof c==`number`&&(r<0?(r=0,i=a=c):c<o&&o-c>(a-i)/2?(n.push({start:r,end:s}),r=s,i=a=c):(c<i&&(i=c),c>a&&(a=c)),o=c)}return r>=0&&n.push({start:r,end:e.length}),n}function lK(e,t,n,r){let i=0,a=0,o=1/0,s=-1/0;for(let r=t.start;r<t.end;r++){let t=e[r][n];typeof t==`number`&&(i++,a+=t,t<o&&(o=t),t>s&&(s=t))}return i===0?null:r===`mean`?a/i:r===`max`?s:r===`min`?o:s-o}function uK(e){let t=e.filter(e=>e!==null);if(t.length===0)return null;let n=[...t].sort((e,t)=>e-t)[Math.floor(t.length/2)],r=t.filter(e=>e>=n*.8),i=Math.min(...r.length>1?r:t);return e.indexOf(i)}function dK(e,t){return t.trim()===`s`||/time/i.test(e)}function fK(e,t){return`${e}::lap${t}`}BW();var pK=(e,t,n)=>`kymoscope-workbook-export|3|${e}|${t??``}|${n??``}`,mK=e=>new TextEncoder().encode(e);async function hK(e,t){return{format:`kymoscope-workbook`,v:2,...await NW(t,mK(JSON.stringify(e)),zW)}}async function gK(e,t){let n=t.password?JSON.stringify(await hK(e,t.password)):JSON.stringify(e),r=await AW(await kW(t.key),mK(n),pK(t.scope,t.scopeId,t.password?`password`:void 0));return{format:`kymoscope-workbook`,v:3,scope:t.scope,scope_id:t.scopeId,alg:`AES-256-GCM`,...r,...t.password?{inner:`password`}:{}}}function _K(e){return!!e&&typeof e==`object`&&e.format===`kymoscope-workbook`}function vK(e){return _K(e)?e.v===2?{v:2,scope:null,scopeId:null,password:!0}:e.v!==3||e.alg!==`AES-256-GCM`||typeof e.iv!=`string`||typeof e.ct!=`string`||![`user`,`org`,`any`].includes(e.scope)||e.scope===`any`!=(e.scope_id===null)||e.scope_id!==null&&typeof e.scope_id!=`string`||e.inner!==void 0&&e.inner!==`password`?null:{v:3,scope:e.scope,scopeId:e.scope_id,password:e.inner===`password`}:null}var yK=e=>{try{return JSON.parse(new TextDecoder().decode(e))}catch{throw new jw(`bad_file`)}};async function bK(e,t){let n=vK(e);if(!n)throw new jw(`bad_file`);let r=e;if(n.v===3){let i=e;if(!t.key)throw new jw(`scope_key_required`,{scope:n.scope,scopeId:n.scopeId});let a;try{a=await MW(await kW(t.key),i,pK(i.scope,i.scope_id,i.inner))}catch{throw new jw(`bad_file`)}if(r=yK(a),!n.password)return r;if(r?.v!==2||!_K(r))throw new jw(`bad_file`)}if(!t.password)throw new jw(`password_required`);let i;try{i=await FW(t.password,r,zW)}catch{throw new jw(`wrong_password`)}return yK(i)}var xK=new Set(Object.keys(S));function SK(e){return Array.isArray(e)?e.flatMap(e=>{if(!e||typeof e!=`object`)return[];let{id:t,kind:n,rect:r}=e;return typeof t!=`string`||!xK.has(n)||!r||![r.x,r.y,r.w,r.h].every(e=>typeof e==`number`&&Number.isFinite(e))?[]:[{...e,rect:w(n,r,96)}]}):[]}var CK=e=>({name:e.name,xKey:e.xKey,panels:e.panels,panelChartSettings:e.panelChartSettings,panelChartBackgrounds:e.panelChartBackgrounds});function wK(e){return Object.fromEntries(Object.entries(e).map(([e,t])=>{let n=t.beacon;return[e,n?.datasetId?{...t,beacon:{...n,datasetId:null}}:t]}))}function TK(e){return{version:2,worksheets:e.worksheets.map(e=>({...CK(e),panelChartSettings:wK(e.panelChartSettings)})),activeWorksheet:Math.max(0,e.worksheets.findIndex(t=>t.id===e.activeWorksheetId)),mathChannels:e.channels.map(e=>({name:e.name,formula:e.formula,units:e.units,enabled:e.enabled,...e.description?{description:e.description}:{}})),liveWindowSeconds:e.liveWindowSeconds,laps:e.laps?{channel:e.laps.channel,metric:e.laps.metric,stat:e.laps.stat}:null}}function EK(e){return{version:1,kind:`worksheet`,exportedAt:new Date().toISOString(),worksheet:{name:e.name,xKey:e.xKey,panels:e.panels,panelChartSettings:e.panelChartSettings,panelChartBackgrounds:e.panelChartBackgrounds}}}function DK(e,t,n){let r={kind:e.kind,settings:t,background:n},i=e.title?.trim();return i&&(r.title=i),{version:1,kind:`chart`,exportedAt:new Date().toISOString(),chart:r}}function OK(e){return new Promise((t,n)=>{let r=new FileReader;r.onload=()=>t(r.result),r.onerror=()=>n(r.error),r.readAsText(e)})}async function kK(e){let t=await OK(e),n;try{n=JSON.parse(t)}catch{return{worksheets:[],errors:[`Not a valid JSON file.`]}}return FK(n)}var AK=new Set(sK.map(e=>e.value)),jK=/^(#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})|(?:rgba?|hsla?)\([0-9.,%\s/deg+-]+\)|[a-z]{3,24})$/i;function MK(e){return typeof e!=`string`||e.length>64||/[;{}<>\\]|\b(?:var|env|attr|url)\(/i.test(e)?!1:typeof CSS<`u`&&typeof CSS.supports==`function`?CSS.supports(`color`,e):jK.test(e.trim())}function NK(e){if(Array.isArray(e))return e.map(NK);if(!e||typeof e!=`object`)return e??{};let t={};for(let[n,r]of Object.entries(e))/colou?r$/i.test(n)&&typeof r==`string`&&!MK(r)||(t[n]=r&&typeof r==`object`?NK(r):r);return t}function PK(e){return!e||typeof e!=`object`?{}:Object.fromEntries(Object.entries(e).filter(([,e])=>e===null||MK(e)))}function FK(e){let t=e,n=t&&typeof t==`object`?t.version:void 0;if(!t||n!==1&&n!==2||!Array.isArray(t.worksheets))return{worksheets:[],errors:[`Unrecognized format. Is this a Kymoscope workbook file?`],activeIndex:0,mathChannels:[],liveWindowSeconds:void 0,laps:void 0};let r=[],i=[];if(t.worksheets.forEach((e,t)=>{let n=e;if(typeof n?.name!=`string`||typeof n.xKey!=`string`){i.push(`Worksheet #${t+1} skipped: missing name or xKey.`);return}r.push({id:crypto.randomUUID(),name:n.name,xKey:n.xKey,panels:SK(n.panels),panelChartSettings:NK(n.panelChartSettings),panelChartBackgrounds:PK(n.panelChartBackgrounds)})}),n===1)return{worksheets:r,errors:i,activeIndex:0,mathChannels:[],liveWindowSeconds:void 0,laps:void 0};let a=(Array.isArray(t.mathChannels)?t.mathChannels:[]).flatMap(e=>{let t=e;return typeof t?.name!=`string`||!t.name.trim()||typeof t.formula!=`string`?[]:[{name:t.name,formula:t.formula,units:typeof t.units==`string`?t.units:``,enabled:t.enabled!==!1,...typeof t.description==`string`&&t.description?{description:t.description}:{}}]}),o=t.liveWindowSeconds,s=t.laps,c=s&&typeof s.channel==`string`&&typeof s.metric==`string`&&AK.has(s.stat)?{channel:s.channel,metric:s.metric,stat:s.stat}:null,l=typeof t.activeWorksheet==`number`&&Number.isInteger(t.activeWorksheet)?t.activeWorksheet:0;return{worksheets:r,errors:i,mathChannels:a,laps:c,activeIndex:Math.min(Math.max(0,l),Math.max(0,r.length-1)),liveWindowSeconds:o===null||typeof o==`number`&&o>0?o:void 0}}function IK(e){return e.some(e=>e.panels.length>0)}function LK(e){if(!e||typeof e!=`object`)return null;let t=e;return typeof t.name!=`string`||typeof t.xKey!=`string`?null:{id:crypto.randomUUID(),name:t.name,xKey:t.xKey,panels:SK(t.panels),panelChartSettings:NK(t.panelChartSettings),panelChartBackgrounds:PK(t.panelChartBackgrounds)}}function RK(e){if(!e||typeof e!=`object`)return null;let t=e,n=t.kind;if(typeof n!=`string`||!xK.has(n))return null;let r=Me({__chart:t.settings},``,1).__chart;if(!r||r.kind!==n)return null;let i={kind:n,settings:r,background:t.background===null||typeof t.background==`string`&&/^#[0-9a-fA-F]{6}$/.test(t.background)?t.background:null};return typeof t.title==`string`&&t.title.trim()&&(i.title=t.title),i}async function zK(e){let t=await OK(e),n;try{n=JSON.parse(t)}catch{return{type:`error`,errors:[`Not a valid JSON file.`]}}if(!n||typeof n!=`object`)return{type:`error`,errors:[`Unrecognized file.`]};if(n.format===`kymoscope-workbook`){let e=vK(n);return e?{type:`encrypted`,...e}:{type:`error`,errors:[`This file is from a newer version of Kymoscope.`]}}let r=n.kind;if(r===`worksheet`){let e=LK(n.worksheet);return e?{type:`worksheet`,worksheet:e}:{type:`error`,errors:[`Worksheet file is missing a name or X key.`]}}if(r===`chart`){let e=RK(n.chart);return e?{type:`chart`,chart:e}:{type:`error`,errors:[`Chart file is malformed or its settings do not match its type.`]}}let i=await kK(e);return i.worksheets.length===0&&i.errors.length>0?{type:`error`,errors:i.errors}:{type:`workspace`,worksheets:i.worksheets,errors:i.errors}}var BK=uL;function VK(e){let t=e.toLowerCase();return!t.startsWith(`.`)&&BK.some(e=>t.endsWith(e))}function HK(e,t=``){let n={name:t,path:``,dirs:[],files:[],allPaths:[]};for(let t of e){if(!VK(t.file.name))continue;let e=t.path.split(`/`).filter(Boolean),r=n;for(let t of e.slice(0,-1)){let e=r.path?`${r.path}/${t}`:t,n=r.dirs.find(e=>e.name===t);n||(n={name:t,path:e,dirs:[],files:[],allPaths:[]},r.dirs.push(n)),r=n}r.files.push(t)}let r=new Intl.Collator(void 0,{numeric:!0,sensitivity:`base`}).compare,i=e=>(e.dirs.sort((e,t)=>r(e.name,t.name)),e.files.sort((e,t)=>r(e.file.name,t.file.name)),e.allPaths=[...e.dirs.flatMap(i),...e.files.map(e=>e.path)],e.allPaths);return i(n),!n.files.length&&n.dirs.length===1?n.dirs[0]:n}function UK(e){return e.map(e=>({path:e.webkitRelativePath||e.name,file:e}))}async function WK(e){let t=[],n=async(e,r)=>{let i=r?`${r}/${e.name}`:e.name;if(e.isFile){let n=await new Promise((t,n)=>e.file(t,n));t.push({path:i,file:n});return}if(!e.isDirectory)return;let a=e.createReader();for(;;){let e=await new Promise((e,t)=>a.readEntries(e,t));if(!e.length)break;for(let t of e)await n(t,i)}};for(let t of e)await n(t,``);return t}function GK(){return typeof window.showDirectoryPicker==`function`}async function KK(){let e;try{e=await window.showDirectoryPicker({mode:`read`})}catch(e){if(e instanceof DOMException&&e.name===`AbortError`)return null;throw e}let t=[],n=async(e,r)=>{for await(let i of e.values()){let e=`${r}/${i.name}`;i.kind===`file`?t.push({path:e,file:await i.getFile()}):await n(i,e)}};return await n(e,e.name),t}var qK={1:`dohstRIUBeOkkAXOTXhhEkXanWzz-V4M518JBqTehRM`};function JK(e){let t=e.replace(/-/g,`+`).replace(/_/g,`/`)+`===`.slice((e.length+3)%4),n=atob(t),r=new Uint8Array(n.length);for(let e=0;e<n.length;e++)r[e]=n.charCodeAt(e);return r}function YK(e,t){let n=e.toLowerCase(),r=t.toLowerCase();return n.startsWith(`*.`)?r.endsWith(n.slice(1))&&r.length>n.length-1:n===r}function XK(e){try{let t=JSON.parse(new TextDecoder().decode(JK(e)));return typeof t.sub!=`string`||typeof t.exp!=`number`||!Array.isArray(t.domains)||!t.domains.every(e=>typeof e==`string`)||t.kid!==void 0&&typeof t.kid!=`string`?null:t}catch{return null}}async function ZK(e,t,n,r){if(!e)return{ok:!1,reason:`missing`};if(typeof e!=`string`)return{ok:!1,reason:`malformed`};let i=e.trim().split(`.`);if(i.length!==2||!i[0]||!i[1])return{ok:!1,reason:`malformed`};let a=XK(i[0]);if(!a)return{ok:!1,reason:`malformed`};let o=a.kid??`1`,s=typeof n==`string`?n:Object.hasOwn(n,o)?n[o]:void 0;if(!s)return{ok:!1,reason:`bad_signature`};let c;try{let e=await crypto.subtle.importKey(`raw`,JK(s),`Ed25519`,!1,[`verify`]);c=await crypto.subtle.verify(`Ed25519`,e,JK(i[1]),new TextEncoder().encode(i[0]))}catch{return{ok:!1,reason:`unsupported`}}return c?a.exp<r?{ok:!1,reason:`expired`}:a.domains.some(e=>YK(e,t))?{ok:!0,sub:a.sub,exp:a.exp}:{ok:!1,reason:`domain`}:{ok:!1,reason:`bad_signature`}}function QK(e,t){return ZK(e,t,qK,Date.now()/1e3)}var X={sans:`system-ui, sans-serif`,mono:`ui-monospace, monospace`},$K=l((e=>{var t=Symbol.for(`react.transitional.element`),n=Symbol.for(`react.portal`),r=Symbol.for(`react.fragment`),i=Symbol.for(`react.strict_mode`),a=Symbol.for(`react.profiler`),o=Symbol.for(`react.consumer`),s=Symbol.for(`react.context`),c=Symbol.for(`react.forward_ref`),l=Symbol.for(`react.suspense`),u=Symbol.for(`react.memo`),d=Symbol.for(`react.lazy`),f=Symbol.for(`react.activity`),p=Symbol.iterator;function m(e){return typeof e!=`object`||!e?null:(e=p&&e[p]||e[`@@iterator`],typeof e==`function`?e:null)}var h={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},g=Object.assign,_={};function v(e,t,n){this.props=e,this.context=t,this.refs=_,this.updater=n||h}v.prototype.isReactComponent={},v.prototype.setState=function(e,t){if(typeof e!=`object`&&typeof e!=`function`&&e!=null)throw Error(`takes an object of state variables to update or a function which returns an object of state variables.`);this.updater.enqueueSetState(this,e,t,`setState`)},v.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,`forceUpdate`)};function y(){}y.prototype=v.prototype;function b(e,t,n){this.props=e,this.context=t,this.refs=_,this.updater=n||h}var x=b.prototype=new y;x.constructor=b,g(x,v.prototype),x.isPureReactComponent=!0;var S=Array.isArray;function C(){}var w={H:null,A:null,T:null,S:null},T=Object.prototype.hasOwnProperty;function E(e,n,r){var i=r.ref;return{$$typeof:t,type:e,key:n,ref:i===void 0?null:i,props:r}}function D(e,t){return E(e.type,t,e.props)}function O(e){return typeof e==`object`&&!!e&&e.$$typeof===t}function k(e){var t={"=":`=0`,":":`=2`};return`$`+e.replace(/[=:]/g,function(e){return t[e]})}var A=/\/+/g;function j(e,t){return typeof e==`object`&&e&&e.key!=null?k(``+e.key):t.toString(36)}function M(e){switch(e.status){case`fulfilled`:return e.value;case`rejected`:throw e.reason;default:switch(typeof e.status==`string`?e.then(C,C):(e.status=`pending`,e.then(function(t){e.status===`pending`&&(e.status=`fulfilled`,e.value=t)},function(t){e.status===`pending`&&(e.status=`rejected`,e.reason=t)})),e.status){case`fulfilled`:return e.value;case`rejected`:throw e.reason}}throw e}function N(e,r,i,a,o){var s=typeof e;(s===`undefined`||s===`boolean`)&&(e=null);var c=!1;if(e===null)c=!0;else switch(s){case`bigint`:case`string`:case`number`:c=!0;break;case`object`:switch(e.$$typeof){case t:case n:c=!0;break;case d:return c=e._init,N(c(e._payload),r,i,a,o)}}if(c)return o=o(e),c=a===``?`.`+j(e,0):a,S(o)?(i=``,c!=null&&(i=c.replace(A,`$&/`)+`/`),N(o,r,i,``,function(e){return e})):o!=null&&(O(o)&&(o=D(o,i+(o.key==null||e&&e.key===o.key?``:(``+o.key).replace(A,`$&/`)+`/`)+c)),r.push(o)),1;c=0;var l=a===``?`.`:a+`:`;if(S(e))for(var u=0;u<e.length;u++)a=e[u],s=l+j(a,u),c+=N(a,r,i,s,o);else if(u=m(e),typeof u==`function`)for(e=u.call(e),u=0;!(a=e.next()).done;)a=a.value,s=l+j(a,u++),c+=N(a,r,i,s,o);else if(s===`object`){if(typeof e.then==`function`)return N(M(e),r,i,a,o);throw r=String(e),Error(`Objects are not valid as a React child (found: `+(r===`[object Object]`?`object with keys {`+Object.keys(e).join(`, `)+`}`:r)+`). If you meant to render a collection of children, use an array instead.`)}return c}function P(e,t,n){if(e==null)return e;var r=[],i=0;return N(e,r,``,``,function(e){return t.call(n,e,i++)}),r}function F(e){if(e._status===-1){var t=e._result;t=t(),t.then(function(t){(e._status===0||e._status===-1)&&(e._status=1,e._result=t)},function(t){(e._status===0||e._status===-1)&&(e._status=2,e._result=t)}),e._status===-1&&(e._status=0,e._result=t)}if(e._status===1)return e._result.default;throw e._result}var I=typeof reportError==`function`?reportError:function(e){if(typeof window==`object`&&typeof window.ErrorEvent==`function`){var t=new window.ErrorEvent(`error`,{bubbles:!0,cancelable:!0,message:typeof e==`object`&&e&&typeof e.message==`string`?String(e.message):String(e),error:e});if(!window.dispatchEvent(t))return}else if(typeof process==`object`&&typeof process.emit==`function`){process.emit(`uncaughtException`,e);return}console.error(e)},L={map:P,forEach:function(e,t,n){P(e,function(){t.apply(this,arguments)},n)},count:function(e){var t=0;return P(e,function(){t++}),t},toArray:function(e){return P(e,function(e){return e})||[]},only:function(e){if(!O(e))throw Error(`React.Children.only expected to receive a single React element child.`);return e}};e.Activity=f,e.Children=L,e.Component=v,e.Fragment=r,e.Profiler=a,e.PureComponent=b,e.StrictMode=i,e.Suspense=l,e.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=w,e.__COMPILER_RUNTIME={__proto__:null,c:function(e){return w.H.useMemoCache(e)}},e.cache=function(e){return function(){return e.apply(null,arguments)}},e.cacheSignal=function(){return null},e.cloneElement=function(e,t,n){if(e==null)throw Error(`The argument must be a React element, but you passed `+e+`.`);var r=g({},e.props),i=e.key;if(t!=null)for(a in t.key!==void 0&&(i=``+t.key),t)!T.call(t,a)||a===`key`||a===`__self`||a===`__source`||a===`ref`&&t.ref===void 0||(r[a]=t[a]);var a=arguments.length-2;if(a===1)r.children=n;else if(1<a){for(var o=Array(a),s=0;s<a;s++)o[s]=arguments[s+2];r.children=o}return E(e.type,i,r)},e.createContext=function(e){return e={$$typeof:s,_currentValue:e,_currentValue2:e,_threadCount:0,Provider:null,Consumer:null},e.Provider=e,e.Consumer={$$typeof:o,_context:e},e},e.createElement=function(e,t,n){var r,i={},a=null;if(t!=null)for(r in t.key!==void 0&&(a=``+t.key),t)T.call(t,r)&&r!==`key`&&r!==`__self`&&r!==`__source`&&(i[r]=t[r]);var o=arguments.length-2;if(o===1)i.children=n;else if(1<o){for(var s=Array(o),c=0;c<o;c++)s[c]=arguments[c+2];i.children=s}if(e&&e.defaultProps)for(r in o=e.defaultProps,o)i[r]===void 0&&(i[r]=o[r]);return E(e,a,i)},e.createRef=function(){return{current:null}},e.forwardRef=function(e){return{$$typeof:c,render:e}},e.isValidElement=O,e.lazy=function(e){return{$$typeof:d,_payload:{_status:-1,_result:e},_init:F}},e.memo=function(e,t){return{$$typeof:u,type:e,compare:t===void 0?null:t}},e.startTransition=function(e){var t=w.T,n={};w.T=n;try{var r=e(),i=w.S;i!==null&&i(n,r),typeof r==`object`&&r&&typeof r.then==`function`&&r.then(C,I)}catch(e){I(e)}finally{t!==null&&n.types!==null&&(t.types=n.types),w.T=t}},e.unstable_useCacheRefresh=function(){return w.H.useCacheRefresh()},e.use=function(e){return w.H.use(e)},e.useActionState=function(e,t,n){return w.H.useActionState(e,t,n)},e.useCallback=function(e,t){return w.H.useCallback(e,t)},e.useContext=function(e){return w.H.useContext(e)},e.useDebugValue=function(){},e.useDeferredValue=function(e,t){return w.H.useDeferredValue(e,t)},e.useEffect=function(e,t){return w.H.useEffect(e,t)},e.useEffectEvent=function(e){return w.H.useEffectEvent(e)},e.useId=function(){return w.H.useId()},e.useImperativeHandle=function(e,t,n){return w.H.useImperativeHandle(e,t,n)},e.useInsertionEffect=function(e,t){return w.H.useInsertionEffect(e,t)},e.useLayoutEffect=function(e,t){return w.H.useLayoutEffect(e,t)},e.useMemo=function(e,t){return w.H.useMemo(e,t)},e.useOptimistic=function(e,t){return w.H.useOptimistic(e,t)},e.useReducer=function(e,t,n){return w.H.useReducer(e,t,n)},e.useRef=function(e){return w.H.useRef(e)},e.useState=function(e){return w.H.useState(e)},e.useSyncExternalStore=function(e,t,n){return w.H.useSyncExternalStore(e,t,n)},e.useTransition=function(){return w.H.useTransition()},e.version=`19.2.5`})),eq=l(((e,t)=>{t.exports=$K()})),tq=l((e=>{var t=eq();function n(e){var t=`https://react.dev/errors/`+e;if(1<arguments.length){t+=`?args[]=`+encodeURIComponent(arguments[1]);for(var n=2;n<arguments.length;n++)t+=`&args[]=`+encodeURIComponent(arguments[n])}return`Minified React error #`+e+`; visit `+t+` for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`}function r(){}var i={d:{f:r,r:function(){throw Error(n(522))},D:r,C:r,L:r,m:r,X:r,S:r,M:r},p:0,findDOMNode:null},a=Symbol.for(`react.portal`);function o(e,t,n){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:a,key:r==null?null:``+r,children:e,containerInfo:t,implementation:n}}var s=t.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;function c(e,t){if(e===`font`)return``;if(typeof t==`string`)return t===`use-credentials`?t:``}e.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=i,e.createPortal=function(e,t){var r=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!t||t.nodeType!==1&&t.nodeType!==9&&t.nodeType!==11)throw Error(n(299));return o(e,t,null,r)},e.flushSync=function(e){var t=s.T,n=i.p;try{if(s.T=null,i.p=2,e)return e()}finally{s.T=t,i.p=n,i.d.f()}},e.preconnect=function(e,t){typeof e==`string`&&(t?(t=t.crossOrigin,t=typeof t==`string`?t===`use-credentials`?t:``:void 0):t=null,i.d.C(e,t))},e.prefetchDNS=function(e){typeof e==`string`&&i.d.D(e)},e.preinit=function(e,t){if(typeof e==`string`&&t&&typeof t.as==`string`){var n=t.as,r=c(n,t.crossOrigin),a=typeof t.integrity==`string`?t.integrity:void 0,o=typeof t.fetchPriority==`string`?t.fetchPriority:void 0;n===`style`?i.d.S(e,typeof t.precedence==`string`?t.precedence:void 0,{crossOrigin:r,integrity:a,fetchPriority:o}):n===`script`&&i.d.X(e,{crossOrigin:r,integrity:a,fetchPriority:o,nonce:typeof t.nonce==`string`?t.nonce:void 0})}},e.preinitModule=function(e,t){if(typeof e==`string`)if(typeof t==`object`&&t){if(t.as==null||t.as===`script`){var n=c(t.as,t.crossOrigin);i.d.M(e,{crossOrigin:n,integrity:typeof t.integrity==`string`?t.integrity:void 0,nonce:typeof t.nonce==`string`?t.nonce:void 0})}}else t??i.d.M(e)},e.preload=function(e,t){if(typeof e==`string`&&typeof t==`object`&&t&&typeof t.as==`string`){var n=t.as,r=c(n,t.crossOrigin);i.d.L(e,n,{crossOrigin:r,integrity:typeof t.integrity==`string`?t.integrity:void 0,nonce:typeof t.nonce==`string`?t.nonce:void 0,type:typeof t.type==`string`?t.type:void 0,fetchPriority:typeof t.fetchPriority==`string`?t.fetchPriority:void 0,referrerPolicy:typeof t.referrerPolicy==`string`?t.referrerPolicy:void 0,imageSrcSet:typeof t.imageSrcSet==`string`?t.imageSrcSet:void 0,imageSizes:typeof t.imageSizes==`string`?t.imageSizes:void 0,media:typeof t.media==`string`?t.media:void 0})}},e.preloadModule=function(e,t){if(typeof e==`string`)if(t){var n=c(t.as,t.crossOrigin);i.d.m(e,{as:typeof t.as==`string`&&t.as!==`script`?t.as:void 0,crossOrigin:n,integrity:typeof t.integrity==`string`?t.integrity:void 0})}else i.d.m(e)},e.requestFormReset=function(e){i.d.r(e)},e.unstable_batchedUpdates=function(e,t){return e(t)},e.useFormState=function(e,t,n){return s.H.useFormState(e,t,n)},e.useFormStatus=function(){return s.H.useHostTransitionStatus()},e.version=`19.2.5`})),nq=l(((e,t)=>{function n(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>`u`||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!=`function`))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(n)}catch(e){console.error(e)}}n(),t.exports=tq()})),rq=l((e=>{function t(e,t){var n=e.length;e.push(t);a:for(;0<n;){var r=n-1>>>1,a=e[r];if(0<i(a,t))e[r]=t,e[n]=a,n=r;else break a}}function n(e){return e.length===0?null:e[0]}function r(e){if(e.length===0)return null;var t=e[0],n=e.pop();if(n!==t){e[0]=n;a:for(var r=0,a=e.length,o=a>>>1;r<o;){var s=2*(r+1)-1,c=e[s],l=s+1,u=e[l];if(0>i(c,n))l<a&&0>i(u,c)?(e[r]=u,e[l]=n,r=l):(e[r]=c,e[s]=n,r=s);else if(l<a&&0>i(u,n))e[r]=u,e[l]=n,r=l;else break a}}return t}function i(e,t){var n=e.sortIndex-t.sortIndex;return n===0?e.id-t.id:n}if(e.unstable_now=void 0,typeof performance==`object`&&typeof performance.now==`function`){var a=performance;e.unstable_now=function(){return a.now()}}else{var o=Date,s=o.now();e.unstable_now=function(){return o.now()-s}}var c=[],l=[],u=1,d=null,f=3,p=!1,m=!1,h=!1,g=!1,_=typeof setTimeout==`function`?setTimeout:null,v=typeof clearTimeout==`function`?clearTimeout:null,y=typeof setImmediate<`u`?setImmediate:null;function b(e){for(var i=n(l);i!==null;){if(i.callback===null)r(l);else if(i.startTime<=e)r(l),i.sortIndex=i.expirationTime,t(c,i);else break;i=n(l)}}function x(e){if(h=!1,b(e),!m)if(n(c)!==null)m=!0,S||(S=!0,O());else{var t=n(l);t!==null&&j(x,t.startTime-e)}}var S=!1,C=-1,w=5,T=-1;function E(){return g?!0:!(e.unstable_now()-T<w)}function D(){if(g=!1,S){var t=e.unstable_now();T=t;var i=!0;try{a:{m=!1,h&&(h=!1,v(C),C=-1),p=!0;var a=f;try{b:{for(b(t),d=n(c);d!==null&&!(d.expirationTime>t&&E());){var o=d.callback;if(typeof o==`function`){d.callback=null,f=d.priorityLevel;var s=o(d.expirationTime<=t);if(t=e.unstable_now(),typeof s==`function`){d.callback=s,b(t),i=!0;break b}d===n(c)&&r(c),b(t)}else r(c);d=n(c)}if(d!==null)i=!0;else{var u=n(l);u!==null&&j(x,u.startTime-t),i=!1}}break a}finally{d=null,f=a,p=!1}i=void 0}}finally{i?O():S=!1}}}var O;if(typeof y==`function`)O=function(){y(D)};else if(typeof MessageChannel<`u`){var k=new MessageChannel,A=k.port2;k.port1.onmessage=D,O=function(){A.postMessage(null)}}else O=function(){_(D,0)};function j(t,n){C=_(function(){t(e.unstable_now())},n)}e.unstable_IdlePriority=5,e.unstable_ImmediatePriority=1,e.unstable_LowPriority=4,e.unstable_NormalPriority=3,e.unstable_Profiling=null,e.unstable_UserBlockingPriority=2,e.unstable_cancelCallback=function(e){e.callback=null},e.unstable_forceFrameRate=function(e){0>e||125<e?console.error(`forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported`):w=0<e?Math.floor(1e3/e):5},e.unstable_getCurrentPriorityLevel=function(){return f},e.unstable_next=function(e){switch(f){case 1:case 2:case 3:var t=3;break;default:t=f}var n=f;f=t;try{return e()}finally{f=n}},e.unstable_requestPaint=function(){g=!0},e.unstable_runWithPriority=function(e,t){switch(e){case 1:case 2:case 3:case 4:case 5:break;default:e=3}var n=f;f=e;try{return t()}finally{f=n}},e.unstable_scheduleCallback=function(r,i,a){var o=e.unstable_now();switch(typeof a==`object`&&a?(a=a.delay,a=typeof a==`number`&&0<a?o+a:o):a=o,r){case 1:var s=-1;break;case 2:s=250;break;case 5:s=1073741823;break;case 4:s=1e4;break;default:s=5e3}return s=a+s,r={id:u++,callback:i,priorityLevel:r,startTime:a,expirationTime:s,sortIndex:-1},a>o?(r.sortIndex=a,t(l,r),n(c)===null&&r===n(l)&&(h?(v(C),C=-1):h=!0,j(x,a-o))):(r.sortIndex=s,t(c,r),m||p||(m=!0,S||(S=!0,O()))),r},e.unstable_shouldYield=E,e.unstable_wrapCallback=function(e){var t=f;return function(){var n=f;f=t;try{return e.apply(this,arguments)}finally{f=n}}}})),iq=l(((e,t)=>{t.exports=rq()})),aq=l((e=>{var t=iq(),n=eq(),r=nq();function i(e){var t=`https://react.dev/errors/`+e;if(1<arguments.length){t+=`?args[]=`+encodeURIComponent(arguments[1]);for(var n=2;n<arguments.length;n++)t+=`&args[]=`+encodeURIComponent(arguments[n])}return`Minified React error #`+e+`; visit `+t+` for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`}function a(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function o(e){var t=e,n=e;if(e.alternate)for(;t.return;)t=t.return;else{e=t;do t=e,t.flags&4098&&(n=t.return),e=t.return;while(e)}return t.tag===3?n:null}function s(e){if(e.tag===13){var t=e.memoizedState;if(t===null&&(e=e.alternate,e!==null&&(t=e.memoizedState)),t!==null)return t.dehydrated}return null}function c(e){if(e.tag===31){var t=e.memoizedState;if(t===null&&(e=e.alternate,e!==null&&(t=e.memoizedState)),t!==null)return t.dehydrated}return null}function l(e){if(o(e)!==e)throw Error(i(188))}function u(e){var t=e.alternate;if(!t){if(t=o(e),t===null)throw Error(i(188));return t===e?e:null}for(var n=e,r=t;;){var a=n.return;if(a===null)break;var s=a.alternate;if(s===null){if(r=a.return,r!==null){n=r;continue}break}if(a.child===s.child){for(s=a.child;s;){if(s===n)return l(a),e;if(s===r)return l(a),t;s=s.sibling}throw Error(i(188))}if(n.return!==r.return)n=a,r=s;else{for(var c=!1,u=a.child;u;){if(u===n){c=!0,n=a,r=s;break}if(u===r){c=!0,r=a,n=s;break}u=u.sibling}if(!c){for(u=s.child;u;){if(u===n){c=!0,n=s,r=a;break}if(u===r){c=!0,r=s,n=a;break}u=u.sibling}if(!c)throw Error(i(189))}}if(n.alternate!==r)throw Error(i(190))}if(n.tag!==3)throw Error(i(188));return n.stateNode.current===n?e:t}function d(e){var t=e.tag;if(t===5||t===26||t===27||t===6)return e;for(e=e.child;e!==null;){if(t=d(e),t!==null)return t;e=e.sibling}return null}var f=Object.assign,p=Symbol.for(`react.element`),m=Symbol.for(`react.transitional.element`),h=Symbol.for(`react.portal`),g=Symbol.for(`react.fragment`),_=Symbol.for(`react.strict_mode`),v=Symbol.for(`react.profiler`),y=Symbol.for(`react.consumer`),b=Symbol.for(`react.context`),x=Symbol.for(`react.forward_ref`),S=Symbol.for(`react.suspense`),C=Symbol.for(`react.suspense_list`),w=Symbol.for(`react.memo`),T=Symbol.for(`react.lazy`),E=Symbol.for(`react.activity`),D=Symbol.for(`react.memo_cache_sentinel`),O=Symbol.iterator;function k(e){return typeof e!=`object`||!e?null:(e=O&&e[O]||e[`@@iterator`],typeof e==`function`?e:null)}var A=Symbol.for(`react.client.reference`);function j(e){if(e==null)return null;if(typeof e==`function`)return e.$$typeof===A?null:e.displayName||e.name||null;if(typeof e==`string`)return e;switch(e){case g:return`Fragment`;case v:return`Profiler`;case _:return`StrictMode`;case S:return`Suspense`;case C:return`SuspenseList`;case E:return`Activity`}if(typeof e==`object`)switch(e.$$typeof){case h:return`Portal`;case b:return e.displayName||`Context`;case y:return(e._context.displayName||`Context`)+`.Consumer`;case x:var t=e.render;return e=e.displayName,e||=(e=t.displayName||t.name||``,e===``?`ForwardRef`:`ForwardRef(`+e+`)`),e;case w:return t=e.displayName||null,t===null?j(e.type)||`Memo`:t;case T:t=e._payload,e=e._init;try{return j(e(t))}catch{}}return null}var M=Array.isArray,N=n.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,P=r.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,F={pending:!1,data:null,method:null,action:null},I=[],L=-1;function R(e){return{current:e}}function z(e){0>L||(e.current=I[L],I[L]=null,L--)}function B(e,t){L++,I[L]=e.current,e.current=t}var V=R(null),H=R(null),U=R(null),W=R(null);function ee(e,t){switch(B(U,t),B(H,e),B(V,null),t.nodeType){case 9:case 11:e=(e=t.documentElement)&&(e=e.namespaceURI)?Ud(e):0;break;default:if(e=t.tagName,t=t.namespaceURI)t=Ud(t),e=Wd(t,e);else switch(e){case`svg`:e=1;break;case`math`:e=2;break;default:e=0}}z(V),B(V,e)}function te(){z(V),z(H),z(U)}function ne(e){e.memoizedState!==null&&B(W,e);var t=V.current,n=Wd(t,e.type);t!==n&&(B(H,e),B(V,n))}function G(e){H.current===e&&(z(V),z(H)),W.current===e&&(z(W),ep._currentValue=F)}var re,ie;function ae(e){if(re===void 0)try{throw Error()}catch(e){var t=e.stack.trim().match(/\n( *(at )?)/);re=t&&t[1]||``,ie=-1<e.stack.indexOf(`
|
|
81
81
|
at`)?` (<anonymous>)`:-1<e.stack.indexOf(`@`)?`@unknown:0:0`:``}return`
|
|
82
82
|
`+re+e+ie}var oe=!1;function se(e,t){if(!e||oe)return``;oe=!0;var n=Error.prepareStackTrace;Error.prepareStackTrace=void 0;try{var r={DetermineComponentFrameRoot:function(){try{if(t){var n=function(){throw Error()};if(Object.defineProperty(n.prototype,`props`,{set:function(){throw Error()}}),typeof Reflect==`object`&&Reflect.construct){try{Reflect.construct(n,[])}catch(e){var r=e}Reflect.construct(e,[],n)}else{try{n.call()}catch(e){r=e}e.call(n.prototype)}}else{try{throw Error()}catch(e){r=e}(n=e())&&typeof n.catch==`function`&&n.catch(function(){})}}catch(e){if(e&&r&&typeof e.stack==`string`)return[e.stack,r.stack]}return[null,null]}};r.DetermineComponentFrameRoot.displayName=`DetermineComponentFrameRoot`;var i=Object.getOwnPropertyDescriptor(r.DetermineComponentFrameRoot,`name`);i&&i.configurable&&Object.defineProperty(r.DetermineComponentFrameRoot,`name`,{value:`DetermineComponentFrameRoot`});var a=r.DetermineComponentFrameRoot(),o=a[0],s=a[1];if(o&&s){var c=o.split(`
|
|
83
83
|
`),l=s.split(`
|
|
@@ -620,14 +620,14 @@ void main() {
|
|
|
620
620
|
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;
|
|
621
621
|
vec4 c = texture(u_palette, vec2((floor(t * 255.0) + 0.5) / 256.0, 0.5));
|
|
622
622
|
outColor = vec4(c.rgb * c.a, c.a);
|
|
623
|
-
}`,qZ=-3e38;function JZ(e){for(let t=0;t<e.length;t++)if(e[t]-e[t]===0)return e[t];return 0}function YZ(e){let t=e.getContext(`webgl2`,{antialias:!1,alpha:!0,premultipliedAlpha:!0});if(!t)return null;let n=(e,n,i,a)=>Iq(t,`glPlot|${e}|${n}`,()=>r(e,n,i,a)),r=(e,n,r,i)=>{let a=vq(t,t.VERTEX_SHADER,e),o=vq(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(zZ,VZ,[`a_xa`,`a_xb`,`a_loa`,`a_lob`,`a_hia`,`a_hib`,`a_bstart`],[`u_color`]),a=n(BZ,HZ,[`a_x0`,`a_x1`,`a_y0`,`a_y1`,`a_k`],[`u_palette`]),o=n(UZ,WZ,[`a_ax`,`a_ay`,`a_bx`,`a_by`,`a_bstart`],[`u_color`,`u_half`,`u_ext`]),s=n(GZ,KZ,[],[`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=JZ(t),o.oy=JZ(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=JZ(n),c.oy=JZ(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=JZ(t),o.oy=JZ(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:qZ}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 XZ(e){let t=(0,Z.useRef)({plot:null,failed:!1,size:``});return(0,Z.useEffect)(()=>()=>{t.current.plot?.dispose(),t.current.plot=null},[]),(0,Z.useCallback)((n,r)=>{let i=t.current,a=e.current;if(!i.plot&&!i.failed&&a&&(i.plot=Lq(a,YZ),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 ZZ(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 QZ=16;function $Z(e,t,n,r){let i=ZZ(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(QZ),m=new Int32Array(QZ);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(QZ-1,Math.floor(a/(2*Math.PI)*QZ));p[o]+=t[e],m[o]++}return{n:a,rMin:c,rMax:l,x:d,y:f,means:Array.from({length:QZ},(e,t)=>m[t]>0?p[t]/m[t]:0)}}function eQ({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=(0,Z.useRef)(null),f=(0,Z.useRef)(null),p=(0,Z.useRef)(null),m=(0,Z.useRef)(u);(0,Z.useLayoutEffect)(()=>{m.current=u},[u]);let h=(0,Z.useRef)({angles:e,radii:t,angleLabel:n,radiusLabel:r,color:i,mode:a,radiusMin:o,radiusMax:s,height:c});(0,Z.useLayoutEffect)(()=>{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=(0,Z.useMemo)(()=>$Z(e,t,o,s),[e,t,o,s]),_=(0,Z.useRef)(g);(0,Z.useLayoutEffect)(()=>{_.current=g},[g]);let v=(0,Z.useRef)(null),y=XZ(v),b=(0,Z.useRef)({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 ${X.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=WG(w,4),k=qG(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 ${X.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(ZG(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,lZ(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/QZ;r.fillStyle=l,r.globalAlpha=.75;for(let i=0;i<QZ;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<QZ;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 ${X.mono}`,r.textAlign=`center`,r.textBaseline=`bottom`,r.fillText(`${s} / ${c}`,E,n-4)}let T=(0,Z.useRef)(w);T.current=w;let E=(0,Z.useRef)(null);E.current??=dJ(()=>T.current(),()=>f.current?.ownerDocument);let D=()=>E.current.schedule();return(0,Z.useEffect)(()=>{E.current.now()}),(0,Z.useEffect)(()=>()=>E.current?.cancel(),[]),(0,Z.useEffect)(()=>{p.current=null,D()},[l]),(0,Z.useLayoutEffect)(()=>{let e=f.current;if(!e)return;let t=new uJ(()=>{p.current=null,D()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{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)},[]),(0,Q.jsxs)(`div`,{ref:f,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:d,className:`chart-canvas`,role:`img`,"aria-label":`Polar chart: ${n} vs ${r}`}),(0,Q.jsx)(`canvas`,{ref:v,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}})]})}function tQ(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 nQ(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 rQ(e,t){let n=new Float64Array(t.length);for(let r=0;r<t.length;r++)n[r]=e[t[r]];return n}function iQ(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 aQ(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 oQ=new Float64Array,sQ=new Float64Array;function cQ(e,t,n){let r=t>>1;oQ.length<r&&(oQ=new Float64Array(r),sQ=new Float64Array(r));let i=oQ.subarray(0,r),a=sQ.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}aQ(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 lQ=new Float64Array,uQ=0;function dQ(e){if(uQ===e)return lQ.subarray(0,e);lQ.length<e&&(lQ=new Float64Array(Math.max(e,lQ.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++){lQ[t]=.5*(1-i);let e=i*n-a*r;a=a*n+i*r,i=e}return uQ=e,lQ.subarray(0,e)}var fQ={top:14,right:24,bottom:40,left:64},pQ=5;function mQ(e){let t=1;for(;t<e;)t<<=1;return t}function hQ(e,t,n,r){let i=e.length,a=Math.max(2,mQ(i)),o=cQ(e,a,n===`hann`?dQ(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 gQ({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=xJ(),f=(0,Z.useRef)(null),p=(0,Z.useRef)(null),m=(0,Z.useRef)(null),h=(0,Z.useRef)(u);(0,Z.useLayoutEffect)(()=>{h.current=u},[u]);let g=(0,Z.useRef)({signal:e,sampleRate:t,label:n,xMode:r,yMode:i,window:a,color:o,logX:s,height:c});(0,Z.useLayoutEffect)(()=>{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 _=(0,Z.useMemo)(()=>e.length>=4?hQ(e,t,a,i):null,[e,t,a,i]),v=(0,Z.useMemo)(()=>_&&s?_.freqs.map(e=>Math.log10(e)):null,[_,s]),y=(0,Z.useRef)(_&&{..._,logFreqs:v});(0,Z.useLayoutEffect)(()=>{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}=fQ,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 ${X.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 ${X.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=WG(I-F,5),V=qG(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 H=T?1:WG(P-N,GG(c)),U=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})():qG(N,P,H);r.strokeStyle=m,r.lineWidth=1,r.setLineDash([3,3]);for(let e of U)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 ${X.mono}`,r.textAlign=`right`,r.textBaseline=`middle`;for(let e of V)r.beginPath(),r.moveTo(s-pQ,z(e)),r.lineTo(s,z(e)),r.stroke(),r.fillText(ZG(e,B),s-4,z(e));r.textAlign=`center`,r.textBaseline=`top`;for(let e of U)r.beginPath(),r.moveTo(R(e),i+l),r.lineTo(R(e),i+l+pQ),r.stroke(),r.fillText(ZG(e,T?e:H),R(e),i+l+pQ+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 W=!1,ee=Math.min(2,window.devicePixelRatio||1),te=Math.max(1,Math.round(c*ee)),ne=A>te*4?T&&k?tQ(k,O,Math.log10(N*M),Math.log10(P*M),te):tQ(D,O,N*M,P*M,te):null;for(let e=+!ne;e<(ne?ne.length:A);e++){let t=ne?ne[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]);W?r.lineTo(i,a):(r.moveTo(i,a),W=!0)}r.stroke(),r.restore(),r.fillStyle=p,r.font=`11px ${X.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=(0,Z.useRef)(C);w.current=C;let T=(0,Z.useRef)(null);T.current??=dJ(()=>w.current(),()=>p.current?.ownerDocument);let E=()=>T.current.schedule();return(0,Z.useEffect)(()=>{T.current.now()}),(0,Z.useEffect)(()=>()=>T.current?.cancel(),[]),(0,Z.useEffect)(()=>{m.current=null,E()},[l]),(0,Z.useLayoutEffect)(()=>{let e=p.current;if(!e)return;let t=new uJ(()=>{m.current=null,E()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{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)},[]),(0,Q.jsx)(`div`,{ref:p,style:{position:`relative`,width:`100%`,height:`100%`},children:(0,Q.jsx)(`canvas`,{ref:f,className:`chart-canvas`,role:`img`,"aria-label":`Spectrum of ${n}`})})}function _Q(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 vQ(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,_Q(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 yQ={top:14,right:24,bottom:48,left:64},bQ=5;function xQ(e,t){let n=e.length;if(n===0)return null;let[r,i,a,o,s]=vQ(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=xJ(),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(null),u=(0,Z.useRef)(a);(0,Z.useLayoutEffect)(()=>{u.current=a},[a]);let d=(0,Z.useRef)({groups:e,color:t,whiskers:n,height:r});(0,Z.useLayoutEffect)(()=>{d.current={groups:e,color:t,whiskers:n,height:r}},[e,t,n,r]);let f=(0,Z.useMemo)(()=>e.filter(e=>e.values.length>0).map(e=>({label:e.label,box:xQ(e.values,n)})),[e,n]),p=(0,Z.useRef)(f);(0,Z.useLayoutEffect)(()=>{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}=yQ,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 ${X.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=WG(C-S,5),D=qG(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 ${X.mono}`,r.textAlign=`right`,r.textBaseline=`middle`;for(let e of D)r.beginPath(),r.moveTo(l-bQ,T(e)),r.lineTo(l,T(e)),r.stroke(),r.fillText(ZG(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 ${X.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+bQ+2,k-4,c-bQ-4),r.clip(),r.fillText(n,t,i+f+bQ+2),r.restore()}}let v=(0,Z.useRef)(_);v.current=_;let y=(0,Z.useRef)(null);y.current??=dJ(()=>v.current(),()=>c.current?.ownerDocument);let b=()=>y.current.schedule();return(0,Z.useEffect)(()=>{y.current.now()}),(0,Z.useEffect)(()=>()=>y.current?.cancel(),[]),(0,Z.useEffect)(()=>{l.current=null,b()},[i]),(0,Z.useLayoutEffect)(()=>{let e=c.current;if(!e)return;let t=new uJ(()=>{l.current=null,b()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{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)},[]),(0,Q.jsx)(`div`,{ref:c,style:{position:`relative`,width:`100%`,height:`100%`},children:(0,Q.jsx)(`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 wQ=e=>e.includes(`.`)&&!e.includes(`e`)?e.replace(/\.?0+$/,``):e;function TQ(e){return e>=1e3?`${wQ((e/1e3).toPrecision(3))}k`:wQ(e.toPrecision(3))}function EQ(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 DQ={top:14,right:24,bottom:40,left:68},OQ=[[8,0,16],[48,0,96],[104,0,144],[160,0,128],[200,32,64],[230,100,16],[250,200,32],[255,255,220]],kQ=-80;function AQ(e){let t=OQ.length-1,n=Math.min(t-1,Math.floor(e*t)),r=e*t-n,[i,a,o]=OQ[n],[s,c,l]=OQ[n+1];return[i+(s-i)*r,a+(c-a)*r,o+(l-o)*r]}var jQ=(()=>{let e=new Uint8Array(256*4);for(let t=0;t<256;t++){let[n,r,i]=AQ(t/255);e.set([n,r,i,255],t*4)}return e})();function MQ(e){let t=1;for(;t<e;)t<<=1;return t}var NQ=(e,t)=>Math.log(1+e/t*9)/Math.log(10),PQ=(e,t)=>t*(10**e-1)/9;function FQ({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=xJ(),d=(0,Z.useRef)(null),f=(0,Z.useRef)(null),p=(0,Z.useRef)(null),m=(0,Z.useRef)(null),h=(0,Z.useRef)(null),g=(0,Z.useRef)(l);(0,Z.useLayoutEffect)(()=>{g.current=l},[l]);let _=MQ(Math.max(4,Math.min(n,4096))),v=Math.max(1,Math.round(_*(1-Math.max(0,Math.min(.95,r))))),y=(0,Z.useMemo)(()=>{if(!o)return null;let e=_>>1,n=t/2;return Int32Array.from({length:e},(t,r)=>Math.min(e-1,Math.floor(PQ((r+.5)/e,n)/n*e)))},[o,_,t]),b=(0,Z.useRef)(null),x=(0,Z.useMemo)(()=>b.current=EQ(e,_,v,i===`hann`,a===`db`,y,b.current),[e,_,v,i,a,y]),S=(0,Z.useMemo)(()=>({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+kQ,C]:[0,C],T=(0,Z.useRef)({grid:S,range:w,sampleRate:t,winSz:_,step:v,yMode:a,logFreq:o,label:s});(0,Z.useLayoutEffect)(()=>{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=(0,Z.useRef)({plot:null,failed:!1,size:``,grid:null,shown:null});(0,Z.useEffect)(()=>()=>{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=Lq(f.current,YZ),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=cX(DQ,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 ${X.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],jQ,P,F),E.current.grid=y,E.current.shown=e,sJ(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]=AQ(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?NQ(e,R):e/R));L.strokeStyle=v,L.lineWidth=.5,L.globalAlpha=.4;let B=qG(0,R,WG(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 ${X.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(TQ(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 H=WG(V,6),U=qG(0,V,H);r.textAlign=`center`,r.textBaseline=`top`;for(let e of U){let t=l+e/V*f;r.beginPath(),r.moveTo(t,o+h),r.lineTo(t,o+h+4),r.stroke(),r.fillText(ZG(e,H),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=(0,Z.useRef)(j);(0,Z.useLayoutEffect)(()=>{M.current=j});let N=(0,Z.useRef)(null);return N.current??=dJ(()=>M.current(),()=>m.current?.ownerDocument),(0,Z.useEffect)(()=>{N.current.now()},[S,w[0],w[1],t,_,v,a,o,s]),(0,Z.useEffect)(()=>()=>N.current?.cancel(),[]),(0,Z.useEffect)(()=>{h.current=null,N.current.schedule()},[c]),(0,Z.useLayoutEffect)(()=>{let e=m.current;if(!e)return;let t=new uJ(()=>{h.current=null,N.current.schedule()});return t.observe(e),()=>t.disconnect()},[]),(0,Z.useLayoutEffect)(()=>{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)},[]),(0,Q.jsxs)(`div`,{ref:m,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:d,className:`chart-canvas`,role:`img`,"aria-label":`Spectrogram`}),(0,Q.jsx)(`canvas`,{ref:f,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),(0,Q.jsx)(`canvas`,{ref:p,className:`chart-canvas chart-overlay`})]})}var IQ=300,LQ=256,RQ=-60,zQ=[];function BQ({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=(0,Z.useMemo)(()=>EQ(e,c,l,i===`hann`,u,null),[e,c,l,i,u]);return(0,Q.jsx)(kZ,{points:zQ,surface:(0,Z.useMemo)(()=>VQ(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 VQ(e,t,n,r,i){let{frames:a,bins:o,values:s}=e;if(a<2||o<2)return;let c=Math.min(a,IQ),l=Math.min(o,LQ),u=i?20*Math.log10(Math.max(e.max,1e-12))+RQ:-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 HQ(e,t,n){return Array.from({length:n},(r,i)=>e+(i+1)/(n+1)*(t-e))}function UQ(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 WQ(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 GQ(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 KQ={top:14,right:32,bottom:80,left:80};function qQ(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 JQ=[[33,102,172],[103,169,207],[209,229,240],[247,247,247],[253,219,199],[239,138,98],[178,24,43]],YQ=[[13,8,135],[84,2,163],[139,10,165],[185,50,137],[219,92,104],[244,136,73],[254,188,43],[240,249,33]],XQ=[[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 ZQ(e,t){let n=e.length-1,r=Math.min(n-1,Math.floor(t*n));return qQ(e[r],e[r+1],t*n-r)}function QQ(e,t){return ZQ(t===`plasma`?YQ:t===`viridis`?XQ:JQ,e)}function $Q(e){let t=new Uint8Array(256*4);for(let n=0;n<256;n++){let[r,i,a]=QQ(n/255,e);t.set([r,i,a,255],n*4)}return t}function e$(e){return Math.abs(e)>=1e4||Math.abs(e)<.01&&e!==0?e.toExponential(1):String(parseFloat(e.toPrecision(3)))}function t$(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 n$(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=WQ(a),i=n[e.w]-n[0];u=Float64Array.from(n,e=>t+(e-n[0])/i*r)}if(l){let t=WQ(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 r$(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 i$(e,t,n,r,i,a){let o=Math.max(1,i),s=Math.max(1,a),c=Int32Array.from({length:o},(e,r)=>r$(t.xB,n+r+.5)),l=new Float32Array(o*s);for(let n=0;n<s;n++){let i=r$(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 a$({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=(0,Z.useRef)(null),m=(0,Z.useRef)(null),h=(0,Z.useRef)(null),g=(0,Z.useRef)(null),_=(0,Z.useRef)(null),v=(0,Z.useRef)(null),y=(0,Z.useRef)(null),b=(0,Z.useRef)(0),x=(0,Z.useRef)(f);(0,Z.useLayoutEffect)(()=>{x.current=f},[f]);let S=(0,Z.useMemo)(()=>r??t$(e??[],t??[],n??[]),[r,e,t,n]),C=(0,Z.useMemo)(()=>{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=(0,Z.useRef)({data:S,range:C,showValues:i,colorScheme:a,xCentres:c,yCentres:l,contours:u});(0,Z.useLayoutEffect)(()=>{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=(0,Z.useRef)({plot:null,failed:!1,size:``,data:null,key:``,shown:null,geo:null}),E=(0,Z.useRef)({key:``,grid:null,segs:[]});(0,Z.useEffect)(()=>()=>{T.current.plot?.dispose(),T.current.plot=null},[]);let D=(0,Z.useRef)({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=Lq(m.current,YZ),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=cX(KQ,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 ${X.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}`},sJ(_.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=n$(z,l,o,S,C,z===m?F:void 0,z===m?I:void 0),V=B.byValue,H=`${R}|${b}|${V?`${S}x${C}`:``}`,U=T.current.shown;if(T.current.data!==m||T.current.key!==H||!U){U=z;let e=V?i$(U,B,l,o,Math.round(S),Math.round(C)):U;x&&x.setGrid(`cells`,e.values,e.w,Math.min(e.h,x.maxTextureSize),[0,e.w,0,e.h],$Q(b),g,v),T.current.data=m,T.current.key=H,T.current.shown=U}T.current.geo=B;let W=V?Math.round(S):U.w,ee=V?Math.round(C):U.h,te=e=>B.xB[e+1]-B.xB[e],ne=e=>B.yB[e+1]-B.yB[e];if(x)x.keep([`cells`]),x.setGridRange(`cells`,g,v),x.setView(0,W,ee,0,{left:l,top:o,width:S,height:C}),x.render();else for(let e=0;e<U.h;e++)for(let t=0;t<U.w;t++){let n=U.values[e*U.w+t];if(Number.isNaN(n))continue;let[i,a,o]=QQ(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],te(t)+.5,ne(e)+.5)}let G=i??r;if(y){for(let e=0;e<U.h;e++)if(!(ne(e)<=16)){G.font=`${Math.min(12,Math.max(8,ne(e)*.4))}px ${X.mono}`,G.textAlign=`center`,G.textBaseline=`middle`;for(let t=0;t<U.w;t++){let n=U.values[e*U.w+t];if(Number.isNaN(n)||te(t)<=28)continue;let[r,i,a]=QQ(Math.max(0,Math.min(1,(n-g)/(v-g))),b);G.fillStyle=.299*r+.587*i+.114*a>128?`#000`:`#fff`,G.fillText(e$(n),(B.xB[t]+B.xB[t+1])/2,(B.yB[e]+B.yB[e+1])/2)}}}if(S/U.w>=4&&C/U.h>=4){G.strokeStyle=u,G.lineWidth=.5;for(let e=0;e<=U.w;e++)G.beginPath(),G.moveTo(B.xB[e],o),G.lineTo(B.xB[e],o+C),G.stroke();for(let e=0;e<=U.h;e++)G.beginPath(),G.moveTo(l,B.yB[e]),G.lineTo(l+S,B.yB[e]),G.stroke()}let re=L>0?HQ(g,v,L):[];if(re.length&&U.w>=2&&U.h>=2&&U.w*U.h<=4e6){let e=`${g}|${v}|${L}`;if(E.current.grid!==U||E.current.key!==e){let t=U;E.current={key:e,grid:t,segs:re.map(e=>UQ(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)};G.save(),G.beginPath(),G.rect(l,o,S,C),G.clip(),G.lineCap=`round`,G.lineJoin=`round`;for(let[e,n]of[[2.6,`rgba(0,0,0,0.38)`],[1.1,`rgba(255,255,255,0.92)`]]){G.lineWidth=e,G.strokeStyle=n,G.beginPath();for(let e of E.current.segs)for(let[n,r,i,a]of e)G.moveTo(t(n,B.xB),t(r,B.yB)),G.lineTo(t(i,B.xB),t(a,B.yB));G.stroke()}G.restore()}r.fillStyle=d,r.font=`10px ${X.mono}`,r.textAlign=`center`,r.textBaseline=`top`;let ie=-1/0;for(let e=0;e<(a.tiny?0:U.w);e++){let t=(B.xB[e]+B.xB[e+1])/2;t-ie<18||(ie=t,r.save(),r.translate(t,o+C+4),r.rotate(-Math.PI/4),r.fillText(M(U.xLabels,e),0,0),r.restore())}r.textAlign=`right`,r.textBaseline=`middle`;let ae=-1/0;for(let e=0;e<(a.tiny?0:U.h);e++){let t=(B.yB[e]+B.yB[e+1])/2;t-ae<12||(ae=t,r.fillText(U.yLabels[e]??``,l-4,t))}if(a.tiny)return;let oe=t-s+4,se=o,ce=C;for(let e=0;e<ce;e++){let[t,n,i]=QQ(1-e/ce,b);r.fillStyle=`rgb(${t|0},${n|0},${i|0})`,r.fillRect(oe,se+e,12,1)}r.strokeStyle=f,r.lineWidth=.5,r.strokeRect(oe,se,12,ce),r.fillStyle=d,r.font=`9px ${X.mono}`,r.textAlign=`left`,r.textBaseline=`middle`,r.fillText(e$(v),oe+12+2,se),r.fillText(e$(g),oe+12+2,se+ce),r.fillText(e$((g+v)/2),oe+12+2,se+ce/2),r.strokeStyle=`rgba(255,255,255,0.92)`,r.lineWidth=1;for(let e of re){let t=se+ce*(1-(e-g)/(v-g));r.beginPath(),r.moveTo(oe-2,t),r.lineTo(oe+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}=cX(KQ,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]}: ${e$(_)}`;r.font=`11px ${X.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=(0,Z.useRef)(N);F.current=N;let I=(0,Z.useRef)(null);I.current??=dJ(()=>F.current(),()=>_.current?.ownerDocument);let L=()=>{b.current||=iJ(()=>{b.current=0,P()})};return(0,Z.useEffect)(()=>{I.current.now()},[S,C,i,a,c,l,u]),(0,Z.useEffect)(()=>()=>{I.current?.cancel(),aJ(b.current)},[]),(0,Z.useEffect)(()=>{v.current=null,I.current.schedule()},[d]),(0,Z.useLayoutEffect)(()=>{let e=_.current;if(!e)return;let t=new uJ(()=>{v.current=null,I.current.schedule(),L()});return t.observe(e),()=>t.disconnect()},[]),(0,Z.useLayoutEffect)(()=>{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=r$(i.xB,t.clientX-n.left),o=r$(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)}},[]),(0,Q.jsxs)(`div`,{ref:_,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:p,className:`chart-canvas`,role:`img`,"aria-label":`Heatmap`}),(0,Q.jsx)(`canvas`,{ref:m,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),(0,Q.jsx)(`canvas`,{ref:h,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),(0,Q.jsx)(`canvas`,{ref:g,className:`chart-canvas chart-overlay`})]})}var o$=2e3,s$=1024;function c$(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<=o$){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(s$),l=(i-r)/s$||1;for(let t=0;t<a;t++)c[Math.max(0,Math.min(s$-1,Math.floor((e[t]-r)/l)))]++;for(let e=0;e<n.length;e++){let i=0;for(let a=0;a<s$;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 l$={top:14,right:24,bottom:48,left:64},u$=120;function d$(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 f$(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]=vQ(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:u$},(e,t)=>r+t/(u$-1)*(i-r));return{shapes:n.map((e,n)=>{let{q1:o,median:c,q3:l}=a[n],u=c$(e.values,t>0?t:d$(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 p$({groups:e,color:t=`#818cf8`,showBox:n=!0,bandwidth:r=0,orientation:i=`vertical`,backgroundToken:a=``,onPlotContextMenu:o}){let s=xJ(),c=(0,Z.useRef)(null),l=(0,Z.useRef)(null),u=(0,Z.useRef)(null),d=(0,Z.useRef)(o);(0,Z.useLayoutEffect)(()=>{d.current=o},[o]);let f=(0,Z.useRef)({groups:e,color:t,showBox:n,bandwidth:r,orientation:i});(0,Z.useLayoutEffect)(()=>{f.current={groups:e,color:t,showBox:n,bandwidth:r,orientation:i}},[e,t,n,r,i]);let p=(0,Z.useMemo)(()=>f$(e,r),[e,r]),m=(0,Z.useRef)(p);(0,Z.useLayoutEffect)(()=>{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}=l$,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 ${X.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=WG(E-T,5),A=qG(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 ${X.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(ZG(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(ZG(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<u$;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=u$-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 ${X.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=(0,Z.useRef)(v);y.current=v;let b=(0,Z.useRef)(null);b.current??=dJ(()=>y.current(),()=>l.current?.ownerDocument);let x=()=>b.current.schedule();return(0,Z.useEffect)(()=>{b.current.now()}),(0,Z.useEffect)(()=>()=>b.current?.cancel(),[]),(0,Z.useEffect)(()=>{u.current=null,x()},[a]),(0,Z.useLayoutEffect)(()=>{let e=l.current;if(!e)return;let t=new uJ(()=>{u.current=null,x()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{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)},[]),(0,Q.jsx)(`div`,{ref:l,style:{position:`relative`,width:`100%`,height:`100%`},children:(0,Q.jsx)(`canvas`,{ref:c,className:`chart-canvas`,role:`img`,"aria-label":`Violin plot`})})}var m$={top:48,right:16,bottom:72,left:80},h$=[8,24,64],g$=[56,189,248];function _$(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 v$(e){return`${(e*100).toFixed(1)}%`}function y$(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 b$({actual:e,predicted:t,normalize:n=!1,backgroundToken:r=``,onPlotContextMenu:i}){let a=(0,Z.useRef)(null),o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(null),u=(0,Z.useRef)(0),d=(0,Z.useRef)(i);(0,Z.useLayoutEffect)(()=>{d.current=i},[i]);let f=(0,Z.useRef)({actual:e,predicted:t,normalize:n});(0,Z.useLayoutEffect)(()=>{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=(0,Z.useMemo)(()=>y$(e,t,n),[e,t,n]),_=(0,Z.useRef)(g);(0,Z.useLayoutEffect)(()=>{_.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}=m$,{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 ${X.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]=_$(h$,g$,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 ${X.mono}`,r.textAlign=`center`,r.textBaseline=`middle`;let l=f.current.normalize;r.fillText(l?v$(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 ${X.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 ${X.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 ${X.mono}`,r.textAlign=`center`,r.textBaseline=`middle`,r.fillText(`Accuracy: ${v$(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}=m$,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?v$(C):C|0}`;r.font=`11px ${X.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=(0,Z.useRef)(y);x.current=y;let S=(0,Z.useRef)(null);S.current??=dJ(()=>x.current(),()=>s.current?.ownerDocument);let C=()=>S.current.schedule(),w=()=>{aJ(u.current),u.current=iJ(b)};return(0,Z.useEffect)(()=>{S.current.now()}),(0,Z.useEffect)(()=>()=>S.current?.cancel(),[]),(0,Z.useEffect)(()=>{c.current=null,C()},[r]),(0,Z.useLayoutEffect)(()=>{let e=s.current;if(!e)return;let t=new uJ(()=>{c.current=null,C(),w()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{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}=m$,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)}},[]),(0,Q.jsxs)(`div`,{ref:s,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:a,className:`chart-canvas`,role:`img`,"aria-label":`Confusion matrix`}),(0,Q.jsx)(`canvas`,{ref:o,className:`chart-canvas chart-overlay`})]})}var x$={top:24,right:24,bottom:48,left:64};function S$(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 C$(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 w$(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 T$(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 E$({scores:e,labels:t,mode:n=`roc`,color:r=`#f472b6`,backgroundToken:i=``,onPlotContextMenu:a}){let o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(a);(0,Z.useLayoutEffect)(()=>{l.current=a},[a]);let u=(0,Z.useRef)({scores:e,labels:t,mode:n,color:r});(0,Z.useLayoutEffect)(()=>{u.current={scores:e,labels:t,mode:n,color:r}},[e,t,n,r]);let d=(0,Z.useMemo)(()=>S$(e,t),[e,t]),f=(0,Z.useMemo)(()=>n===`pr`?{roc:null,pr:w$(d)}:{roc:C$(d),pr:null},[d,n]),p=(0,Z.useRef)(f);(0,Z.useLayoutEffect)(()=>{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}=x$,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 ${X.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=qG(0,1,WG(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(),T$(r,t,n,a),r.strokeStyle=x,r.lineWidth=1,r.stroke(),r.beginPath(),T$(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 ${X.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=tQ(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 ${X.mono}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`AP = ${e.ap.toFixed(3)}`,c+8,i+8)}}r.fillStyle=_,r.font=`11px ${X.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=(0,Z.useRef)(_);v.current=_;let y=(0,Z.useRef)(null);y.current??=dJ(()=>v.current(),()=>s.current?.ownerDocument);let b=()=>y.current.schedule();return(0,Z.useEffect)(()=>{y.current.now()}),(0,Z.useEffect)(()=>()=>y.current?.cancel(),[]),(0,Z.useEffect)(()=>{c.current=null,b()},[i]),(0,Z.useLayoutEffect)(()=>{let e=s.current;if(!e)return;let t=new uJ(()=>{c.current=null,b()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{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)},[]),(0,Q.jsx)(`div`,{ref:s,style:{position:`relative`,width:`100%`,height:`100%`},children:(0,Q.jsx)(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`ROC / PR curve`})})}var D$={top:20,right:64,bottom:48,left:64};function O$({xValues:e,series:t,xLabel:n=`Epoch`,backgroundToken:r=``,onPlotContextMenu:i}){let a=xJ(),o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(null),u=(0,Z.useRef)(null),d=(0,Z.useRef)(0),f=(0,Z.useRef)(i);(0,Z.useLayoutEffect)(()=>{f.current=i},[i]);let p=(0,Z.useRef)({xValues:e,series:t,xLabel:n});(0,Z.useLayoutEffect)(()=>{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 _=(0,Z.useMemo)(()=>{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:iQ(e)}},[e,t]),v=(0,Z.useRef)(_);(0,Z.useLayoutEffect)(()=>{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}=D$,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 ${X.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=WG(C.hi-C.lo,5),N=qG(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=WG(D-E,6),F=qG(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?tQ(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 ${X.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(ZG(e,M),l-6,A(e));if(T){let e=WG(w.hi-w.lo,5),t=qG(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(ZG(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(ZG(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 ${X.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}=D$,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 ${X.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}: ${QG(e.values[D])}`,T+6,O),O+=14);w(0)}let x=(0,Z.useRef)(y);x.current=y;let S=(0,Z.useRef)(null);S.current??=dJ(()=>x.current(),()=>c.current?.ownerDocument);let C=()=>S.current.schedule(),w=()=>{aJ(d.current),d.current=iJ(b)};return(0,Z.useEffect)(()=>{S.current.now()}),(0,Z.useEffect)(()=>()=>S.current?.cancel(),[]),(0,Z.useEffect)(()=>{l.current=null,C()},[r]),(0,Z.useLayoutEffect)(()=>{let e=c.current;if(!e)return;let t=new uJ(()=>{l.current=null,C(),w()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{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)}},[]),(0,Q.jsxs)(`div`,{ref:c,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`Loss curves`}),(0,Q.jsx)(`canvas`,{ref:s,className:`chart-canvas chart-overlay`})]})}var k$={top:40,right:24,bottom:40,left:72},A$=`#ef4444`,j$=`#f97316`,M$=`#22d3ee`;function N$(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 P$({points:e,sigmaLevel:t=3,color:n=`#22d3ee`,backgroundToken:r=``,onPlotContextMenu:i}){let a=xJ(),o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(null),u=(0,Z.useRef)(null),d=(0,Z.useRef)(0),f=(0,Z.useRef)(i);(0,Z.useLayoutEffect)(()=>{f.current=i},[i]);let p=(0,Z.useRef)({points:e,sigmaLevel:t,color:n});(0,Z.useLayoutEffect)(()=>{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 _=(0,Z.useMemo)(()=>N$(e,t),[e,t]),v=(0,Z.useRef)(_);(0,Z.useLayoutEffect)(()=>{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}=k$,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 ${X.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=WG(D-E,5),j=qG(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 ${X.mono}`,r.textAlign=`right`,r.textBaseline=`middle`,r.fillText(`${n} ${QG(e)}`,l+u-2,o-5))};M(w,j$,`UCL`,[5,3]),M(C,M$,`CL`,[]),M(T,j$,`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=nQ(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?A$: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 ${X.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(ZG(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}=k$,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}: `}${QG(D)}`;r.font=`11px ${X.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?A$:_,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(j,N,k-11)}let S=(0,Z.useRef)(b);S.current=b;let C=(0,Z.useRef)(null);C.current??=dJ(()=>S.current(),()=>c.current?.ownerDocument);let w=()=>C.current.schedule(),T=()=>{aJ(d.current),d.current=iJ(x)};return(0,Z.useEffect)(()=>{C.current.now()}),(0,Z.useEffect)(()=>()=>C.current?.cancel(),[]),(0,Z.useEffect)(()=>{l.current=null,w()},[r]),(0,Z.useLayoutEffect)(()=>{let e=c.current;if(!e)return;let t=new uJ(()=>{l.current=null,w(),T()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{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)}},[]),(0,Q.jsxs)(`div`,{ref:c,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`Control chart`}),(0,Q.jsx)(`canvas`,{ref:s,className:`chart-canvas chart-overlay`})]})}var F$={top:32,right:24,bottom:24,left:24},I$=[`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`,`#facc15`,`#60a5fa`],L$=16;function R$(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 z$(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:L$},(e,t)=>R$((t+.5)/L$));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(L$-1,Math.floor(e*L$))):-1}for(let t=0;t<e.length;t++)s[t]<0&&(s[t]=0)}else if(!n&&e.colorIndex){c=I$;for(let t=0;t<e.length;t++)s[t]=Math.max(0,e.colorIndex[t])%I$.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 B$({rows:e,axes:t,color:n=`#64748b`,colorByNumeric:r=!1,backgroundToken:i=``,onPlotContextMenu:a}){let o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(null),u=(0,Z.useRef)(null),d=(0,Z.useRef)(null),f=(0,Z.useRef)(null),p=(0,Z.useRef)(0),m=(0,Z.useRef)(a);(0,Z.useLayoutEffect)(()=>{m.current=a},[a]);let h=(0,Z.useMemo)(()=>z$(e,t.length,r,n),[e,t.length,r,n]),g=(0,Z.useRef)({rows:e,axes:t,colorByNumeric:r,model:h});(0,Z.useLayoutEffect)(()=>{g.current={rows:e,axes:t,colorByNumeric:r,model:h}},[e,t,r,h]);let _=XZ(s),v=(0,Z.useRef)(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}=F$,{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 ${X.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,lZ(e.color,j),1,e.starts)),v.current=w,sJ(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 ${X.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(ZG(r,(t.hi-t.lo)/4),k[e]+(e===O-1?5:-5),i)}a.font=`10px ${X.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 ${X.mono}`,a.textBaseline=`top`,M.forEach((n,r)=>{a.fillStyle=I$[r%I$.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}=F$,{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=(0,Z.useRef)(S);w.current=S;let T=(0,Z.useRef)(null);T.current??=dJ(()=>w.current(),()=>u.current?.ownerDocument);let E=()=>T.current.schedule(),D=()=>{aJ(p.current),p.current=iJ(C)};return(0,Z.useEffect)(()=>{T.current.now()}),(0,Z.useEffect)(()=>()=>T.current?.cancel(),[]),(0,Z.useEffect)(()=>{d.current=null,E()},[i]),(0,Z.useLayoutEffect)(()=>{let e=u.current;if(!e)return;let t=new uJ(()=>{d.current=null,E(),D()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{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-F$.left-F$.right,a=r.length,o=t.clientX-n.left-F$.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)}},[]),(0,Q.jsxs)(`div`,{ref:u,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`Parallel coordinates`}),(0,Q.jsx)(`canvas`,{ref:s,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),(0,Q.jsx)(`canvas`,{ref:c,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),(0,Q.jsx)(`canvas`,{ref:l,className:`chart-canvas chart-overlay`})]})}function V$(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 H$(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 U$={top:16,right:16,bottom:16,left:16},W$=[`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`,`#facc15`,`#60a5fa`];function G$(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 K$(e){let[t,n,r]=G$(e);return`rgb(${t},${n},${r})`}var q$=(()=>{let e=new Uint8Array(1024);for(let t=0;t<256;t++)e.set([...G$(t/255),255],t*4);return e})(),J$=(()=>{let e=new Uint8Array(1024);for(let t=0;t<256;t++){let[n,r,i]=lZ(W$[t%W$.length],1);e.set([n*255,r*255,i*255,255],t*4)}return e});function Y$(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 X$({points:e,color:t=`#64748b`,colorByNumeric:n=!1,pointSize:r=4,backgroundToken:i=``,onPlotContextMenu:a}){let o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(null),u=(0,Z.useRef)(null),d=(0,Z.useRef)(null),f=(0,Z.useRef)(0),p=(0,Z.useRef)(a);(0,Z.useLayoutEffect)(()=>{p.current=a},[a]);let m=(0,Z.useMemo)(()=>Y$(e,n),[e,n]),h=(0,Z.useRef)({points:e,color:t,colorByNumeric:n,pointSize:r,model:m});(0,Z.useLayoutEffect)(()=>{h.current={points:e,color:t,colorByNumeric:n,pointSize:r,model:m}},[e,t,n,r,m]);let g=(0,Z.useRef)({r:null,failed:!1,size:``,model:null,style:``});(0,Z.useEffect)(()=>()=>{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}=U$,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=Lq(s.current,oX),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,sJ(l.current));let f=`${c.mode}|${u}|${d}`;return n.style!==f&&(r.setStyle(c.mode===`single`?{kind:`single`,rgba:lZ(u,1)}:{kind:c.mode,palette:c.mode===`colormap`?q$:J$()},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 ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`No data`,U$.left+8,U$.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:U$.left,top:U$.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`?K$(i):d.mode===`dataset`?W$[i%W$.length]:c,r.globalAlpha=.8,r.fill()}r.globalAlpha=1}if(l){let e=Math.min(120,Math.floor((n-U$.top-U$.bottom)*.4)),i=t-U$.right-12,o=U$.top+8;for(let t=0;t<e;t++)r.fillStyle=K$(1-t/(e-1)),r.fillRect(i,o+t,8,1);r.fillStyle=a,r.font=`9px ${X.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=U$.left,i=n-U$.bottom-10;r.font=`9px ${X.mono}`,r.textBaseline=`top`,E.forEach((n,o)=>{e>t-U$.right-60&&(e=U$.left,i-=14),r.fillStyle=W$[o%W$.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 ${X.mono}`;let C=r.measureText(S).width,w=Math.max(4,Math.min(t-C-8,p+10)),T=m-20<U$.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=(0,Z.useRef)(S);w.current=S;let T=(0,Z.useRef)(null);T.current??=dJ(()=>w.current(),()=>l.current?.ownerDocument);let E=()=>T.current.schedule(),D=()=>{aJ(f.current),f.current=iJ(C)};return(0,Z.useEffect)(()=>{T.current.now()}),(0,Z.useEffect)(()=>()=>T.current?.cancel(),[]),(0,Z.useEffect)(()=>{u.current=null,E()},[i]),(0,Z.useLayoutEffect)(()=>{let e=l.current;if(!e)return;let t=new uJ(()=>{u.current=null,E(),D()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{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])-U$.left,g=e=>u(i.y[e])-U$.top,_=a+8,y=`${s}|${c}|${_}`;(!t||t.model!==o||t.key!==y)&&(t={model:o,key:y,g:V$(i.length,f,p,_,m,g)}),d.current=H$(t.g,n.clientX-r.left-U$.left,n.clientY-r.top-U$.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)}},[]),(0,Q.jsxs)(`div`,{ref:l,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`Embedding / scatter`}),(0,Q.jsx)(`canvas`,{ref:s,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),(0,Q.jsx)(`canvas`,{ref:c,className:`chart-canvas chart-overlay`})]})}var Z$={top:8,right:8,bottom:8,left:8},Q$=20,$$=[`#f97316`,`#fb923c`,`#fdba74`,`#fbbf24`,`#fcd34d`,`#4ade80`,`#34d399`,`#38bdf8`,`#818cf8`,`#a78bfa`];function e1(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 t1(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 n1(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 r1(e){return $$[e%$$.length]}function i1({nodes:e,direction:t=`bottomup`,backgroundToken:n=``,onPlotContextMenu:r}){let i=(0,Z.useRef)(null),a=(0,Z.useRef)(null),o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(0),u=(0,Z.useRef)(r);(0,Z.useLayoutEffect)(()=>{u.current=r},[r]);let d=(0,Z.useRef)({nodes:e,direction:t});(0,Z.useLayoutEffect)(()=>{d.current={nodes:e,direction:t}},[e,t]);let f=(0,Z.useMemo)(()=>{let t=e1(e);return{roots:t,flat:t1(t),numRows:n1(t)+1}},[e]),p=(0,Z.useRef)(f);(0,Z.useLayoutEffect)(()=>{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=Z$.left+e.x0*t,o=(e.x1-e.x0)*t;return{x:a,y:i===`topdown`?Z$.top+e.depth*Q$:Z$.top+n-(e.depth+1)*Q$,w:o,h:Q$-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 ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`No data`,Z$.left+8,Z$.top+8);return}let{flat:l,numRows:u}=p.current,f=t-Z$.left-Z$.right,v=u*Q$;for(let e of l){let t=_(e,f,v,u,c);if(!(t.w<1)&&(r.fillStyle=r1(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,Q$-4)}px ${X.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+Q$/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-Z$.left-Z$.right,l*Q$,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 ${X.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+Q$+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=(0,Z.useRef)(v);b.current=v;let x=(0,Z.useRef)(null);x.current??=dJ(()=>b.current(),()=>o.current?.ownerDocument);let S=()=>x.current.schedule(),C=()=>{aJ(l.current),l.current=iJ(y)};return(0,Z.useEffect)(()=>{x.current.now()}),(0,Z.useEffect)(()=>()=>x.current?.cancel(),[]),(0,Z.useEffect)(()=>{s.current=null,S()},[n]),(0,Z.useLayoutEffect)(()=>{let e=o.current;if(!e)return;let t=new uJ(()=>{s.current=null,S(),C()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{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-Z$.left-Z$.right,f=o*Q$,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)}},[]),(0,Q.jsxs)(`div`,{ref:o,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:i,className:`chart-canvas`,role:`img`,"aria-label":`Flame graph`}),(0,Q.jsx)(`canvas`,{ref:a,className:`chart-canvas chart-overlay`})]})}var a1={top:24,right:24,bottom:52,left:56},o1=[`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`,`#facc15`,`#60a5fa`],s1=.8;function c1(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 l1(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 u1({groups:e,columns:t,seriesNames:n,colors:r,mode:i=`grouped`,horizontal:a=!1,valueRange:o,backgroundToken:s=``,onPlotContextMenu:c}){let l=xJ(),u=(0,Z.useRef)(null),d=(0,Z.useRef)(null),f=(0,Z.useRef)(null),p=(0,Z.useRef)(null),m=(0,Z.useRef)(null),h=(0,Z.useRef)(null),g=(0,Z.useRef)(0),_=(0,Z.useRef)(c);(0,Z.useLayoutEffect)(()=>{_.current=c},[c]);let v=(0,Z.useRef)(null),y=(0,Z.useMemo)(()=>{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=c1(e,t,n.length,i);return v.current={key:r,value:o},o},[e,t,n.length,i]),b=(0,Z.useRef)({bars:y,seriesNames:n,colors:r,mode:i,horizontal:a,valueRange:o});(0,Z.useLayoutEffect)(()=>{b.current={bars:y,seriesNames:n,colors:r,mode:i,horizontal:a,valueRange:o}},[y,n,r,i,a,o]);let x=(0,Z.useRef)({plot:null,failed:!1,key:``,data:null,size:``});(0,Z.useEffect)(()=>()=>{x.current.plot?.dispose(),x.current.plot=null},[]);let S=(0,Z.useRef)({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]??o1[n%o1.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=cX(a1,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=Lq(d.current,YZ),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 ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`No data`,a1.left+8,a1.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 ${X.mono}`,!A&&(f?(r.textAlign=`center`,r.textBaseline=`top`,r.fillText(ZG(t,(g-h)/5),n,_+k+4)):(r.textAlign=`right`,r.textBaseline=`middle`,r.fillText(ZG(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},sJ(p.current));let I=Math.min(2,window.devicePixelRatio||1),L=Math.max(1,Math.round(M*I)),R=j.map(e=>{let t=pq(e);return[t[0],t[1],t[2],s1]}),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=l1(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=l1(s,d,L);r.globalAlpha=s1;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 ${X.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 ${X.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]+` `:``}${QG(e[i])}`).join(` `),v=`${a.label(i)}: ${_}`;r.font=`11px ${X.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=(0,Z.useRef)(k);j.current=k;let M=(0,Z.useRef)(null);M.current??=dJ(()=>j.current(),()=>p.current?.ownerDocument);let N=()=>{g.current||=iJ(()=>{g.current=0,A()})};return(0,Z.useEffect)(()=>{M.current.now()},[y,n,r,i,a,o]),(0,Z.useEffect)(()=>()=>{M.current?.cancel(),aJ(g.current)},[]),(0,Z.useEffect)(()=>{m.current=null,M.current.schedule()},[s]),(0,Z.useLayoutEffect)(()=>{let e=p.current;if(!e)return;let t=new uJ(()=>{m.current=null,M.current.schedule(),N()});return t.observe(e),()=>t.disconnect()},[]),(0,Z.useLayoutEffect)(()=>{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)}},[]),(0,Q.jsxs)(`div`,{ref:p,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:u,className:`chart-canvas`,role:`img`,"aria-label":`Bar chart`}),(0,Q.jsx)(`canvas`,{ref:d,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),(0,Q.jsx)(`canvas`,{ref:f,className:`chart-canvas chart-overlay`})]})}var d1=[`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`];function f1(e,t){if(!t)return d1[e%d1.length];if(e===0)return t;let n=d1.filter(e=>e.toLowerCase()!==t.toLowerCase());return n[(e-1)%n.length]}var p1={top:36,right:36,bottom:36,left:36};function m1({axes:e,series:t,fill:n=!0,color:r,backgroundToken:i=``,onPlotContextMenu:a}){let o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(null),u=(0,Z.useRef)(a);(0,Z.useLayoutEffect)(()=>{u.current=a},[a]);let d=(0,Z.useRef)({axes:e,series:t,fill:n,color:r});(0,Z.useLayoutEffect)(()=>{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 ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`Select ≥ 3 axes`,p1.left+8,p1.top+8);return}let h=c.length,g=t/2,_=n/2,v=Math.min(t-p1.left-p1.right,n-p1.top-p1.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 ${X.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=f1(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=p1.left,i=n-p1.bottom-10;r.font=`9px ${X.mono}`,r.textBaseline=`top`;for(let n=0;n<l.length&&(r.fillStyle=f1(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-p1.right-30));n++);}}let g=(0,Z.useRef)(h);g.current=h;let _=(0,Z.useRef)(null);_.current??=dJ(()=>g.current(),()=>c.current?.ownerDocument);let v=()=>_.current.schedule();return(0,Z.useEffect)(()=>{_.current.now()}),(0,Z.useEffect)(()=>()=>_.current?.cancel(),[]),(0,Z.useEffect)(()=>{l.current=null,v()},[i]),(0,Z.useLayoutEffect)(()=>{let e=c.current;if(!e)return;let t=new uJ(()=>{l.current=null,v()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{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)}},[]),(0,Q.jsxs)(`div`,{ref:c,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`Radar chart`}),(0,Q.jsx)(`canvas`,{ref:s,className:`chart-canvas chart-overlay`})]})}var h1={top:16,right:16,bottom:40,left:52},g1=[`#38bdf8`,`#4ade80`,`#fb7185`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`];function _1(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=>iQ(e)),xLo:c,xHi:l,yLo:u,yHi:d}}function v1({series:e,stacked:t=!1,yRange:n,backgroundToken:r=``,onPlotContextMenu:i}){let a=xJ(),o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(null),u=(0,Z.useRef)(null),d=(0,Z.useRef)(null),f=(0,Z.useRef)(0),p=(0,Z.useRef)(i);(0,Z.useLayoutEffect)(()=>{p.current=i},[i]);let m=(0,Z.useRef)(null),h=(0,Z.useMemo)(()=>{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=_1(e,t);return m.current={series:e,stacked:t,value:r},r},[e,t]),g=(0,Z.useRef)({series:e,prepared:h,yRange:n});(0,Z.useLayoutEffect)(()=>{g.current={series:e,prepared:h,yRange:n}},[e,h,n]);let _=(0,Z.useRef)({plot:null,failed:!1,key:``,size:``});(0,Z.useEffect)(()=>()=>{_.current.plot?.dispose(),_.current.plot=null},[]);let v=(0,Z.useRef)({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=tQ(a,o,n,r,i);return{x:rQ(a,c),hi:rQ(o,c),lo:s?rQ(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 ${X.sans}`,i.textAlign=`left`,i.textBaseline=`top`,i.fillText(`No data`,h1.left+8,h1.top+8);return}let h=cX(h1,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 ${X.mono}`,i.textAlign=`right`,i.textBaseline=`middle`,h.tiny||i.fillText(ZG(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 ${X.mono}`,i.textAlign=`center`,i.textBaseline=`top`,h.tiny||i.fillText(ZG(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},sJ(l.current));let B=E(n,r),V=Math.min(2,window.devicePixelRatio||1),H=Math.max(1,Math.round(A*V)),U=d.map((e,t)=>pq(g1[t%g1.length]));if(B){let e=`${M}|${N}|${H}`;if(_.current.key!==e||T.current!==f){let n=[];for(let e=0;e<d.length;e++){let r=C(f,e,M,N,H),i=U[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,H),r=g1[e%g1.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 ${X.mono}`,i.textBaseline=`top`;for(let n=0;n<d.length&&(i.fillStyle=g1[n%g1.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=(0,Z.useRef)(null);function E(e,t){let n=_.current;if(!n.plot&&!n.failed&&s.current&&(n.plot=Lq(s.current,YZ),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}=cX(h1,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=${QG(m+(i-u)/_*(h-m))}`;r.font=`11px ${X.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=(0,Z.useRef)(w);O.current=w;let k=(0,Z.useRef)(null);k.current??=dJ(()=>O.current(),()=>l.current?.ownerDocument);let A=()=>{f.current||=iJ(()=>{f.current=0,D()})};return(0,Z.useEffect)(()=>{k.current.now()},[e,h,n]),(0,Z.useEffect)(()=>()=>{k.current?.cancel(),aJ(f.current)},[]),(0,Z.useEffect)(()=>{u.current=null,k.current.schedule()},[r]),(0,Z.useLayoutEffect)(()=>{let e=l.current;if(!e)return;let t=new uJ(()=>{u.current=null,k.current.schedule(),A()});return t.observe(e),()=>t.disconnect()},[]),(0,Z.useLayoutEffect)(()=>{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)}},[]),(0,Q.jsxs)(`div`,{ref:l,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`Area chart`}),(0,Q.jsx)(`canvas`,{ref:s,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),(0,Q.jsx)(`canvas`,{ref:c,className:`chart-canvas chart-overlay`})]})}var y1={top:16,right:16,bottom:40,left:52},b1=[`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`];function x1({series:e,complement:t=!1,logX:n=!1,backgroundToken:r=``,onPlotContextMenu:i}){let a=xJ(),o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(null),u=(0,Z.useRef)(null),d=(0,Z.useRef)(0),f=(0,Z.useRef)(i);(0,Z.useLayoutEffect)(()=>{f.current=i},[i]);let p=(0,Z.useRef)({series:e,complement:t,logX:n});(0,Z.useLayoutEffect)(()=>{p.current={series:e,complement:t,logX:n}},[e,t,n]);let m=(0,Z.useMemo)(()=>{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=(0,Z.useRef)(m);(0,Z.useLayoutEffect)(()=>{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 ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`No data`,y1.left+8,y1.top+8);return}let{top:f,right:m,bottom:y,left:b}=y1,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 ${X.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 ${X.mono}`,r.textAlign=`center`,r.textBaseline=`top`,r.fillText(ZG(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=b1[e%b1.length],r.lineWidth=1,r.stroke()}if(l.length>1){let e=b,t=f+S+24;r.font=`9px ${X.mono}`,r.textBaseline=`top`;for(let n=0;n<l.length&&(r.fillStyle=b1[n%b1.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 ${X.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}=y1,l=n-a-y1.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=QG(f+(i-o)/d*(p-f));r.font=`11px ${X.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=(0,Z.useRef)(y);x.current=y;let S=(0,Z.useRef)(null);S.current??=dJ(()=>x.current(),()=>c.current?.ownerDocument);let C=()=>S.current.schedule(),w=()=>{aJ(d.current),d.current=iJ(b)};return(0,Z.useEffect)(()=>{S.current.now()}),(0,Z.useEffect)(()=>()=>S.current?.cancel(),[]),(0,Z.useEffect)(()=>{l.current=null,C()},[r]),(0,Z.useLayoutEffect)(()=>{let e=c.current;if(!e)return;let t=new uJ(()=>{l.current=null,C(),w()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{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)}},[]),(0,Q.jsxs)(`div`,{ref:c,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`CDF chart`}),(0,Q.jsx)(`canvas`,{ref:s,className:`chart-canvas chart-overlay`})]})}var S1={top:16,right:40,bottom:40,left:52},C1=[`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`,`#facc15`,`#60a5fa`];function w1(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 T1(e){let[t,n,r]=w1(e);return`rgb(${t},${n},${r})`}var E1=(()=>{let e=new Uint8Array(1024);for(let t=0;t<256;t++)e.set([...w1(t/255),255],t*4);return e})(),D1=()=>{let e=new Uint8Array(1024);for(let t=0;t<256;t++){let[n,r,i]=lZ(C1[t%C1.length],1);e.set([n*255,r*255,i*255,255],t*4)}return e};function O1(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 k1({points:e,color:t=`#64748b`,colorByNumeric:n=!1,maxRadius:r=24,backgroundToken:i=``,onPlotContextMenu:a}){let o=xJ(),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(null),u=(0,Z.useRef)(null),d=(0,Z.useRef)(null),f=(0,Z.useRef)(null),p=(0,Z.useRef)(0),m=(0,Z.useRef)(a);(0,Z.useLayoutEffect)(()=>{m.current=a},[a]);let h=(0,Z.useMemo)(()=>O1(e,n,r),[e,n,r]),g=(0,Z.useRef)({points:e,color:t,colorByNumeric:n,maxRadius:r,model:h});(0,Z.useLayoutEffect)(()=>{g.current={points:e,color:t,colorByNumeric:n,maxRadius:r,model:h}},[e,t,n,r,h]);let _=(0,Z.useRef)({r:null,failed:!1,size:``,model:null,style:``});(0,Z.useEffect)(()=>()=>{_.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}=S1,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=Lq(c.current,oX),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,sJ(u.current));let l=`${o.mode}|${s}`;return n.style!==l&&(r.setStyle(o.mode===`single`?{kind:`single`,rgba:lZ(s,1)}:{kind:o.mode,palette:o.mode===`colormap`?E1:D1()},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 ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`No data`,S1.left+8,S1.top+8);return}let{xLo:p,xHi:m,yLo:h,yHi:C}=d.ext,{top:w,left:T}=S1,{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 ${X.mono}`,r.textAlign=`center`,r.textBaseline=`top`,r.fillText(ZG(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(ZG(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`?T1(n):d.mode===`dataset`?C1[n%C1.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-S1.bottom-10;r.font=`9px ${X.mono}`,r.textBaseline=`top`;for(let n=0;n<A.length;n++){let i=A[n];if(r.fillStyle=C1[n%C1.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(`(${QG(a.x[i])}, ${QG(a.y[i])})`),m.push(`size=${QG(a.size[i])}`);let _=a.colorIndex?.[i];_!==void 0&&_>=0&&a.colorLabels?m.push(a.colorLabels[_]):a.colorValue&&m.push(QG(a.colorValue[i]));let v=m.join(` · `);r.font=`11px ${X.mono}`;let S=r.measureText(v).width,C=Math.max(4,Math.min(t-S-8,d+u+4)),w=p-20<S1.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=(0,Z.useRef)(C);T.current=C;let E=(0,Z.useRef)(null);E.current??=dJ(()=>T.current(),()=>u.current?.ownerDocument);let D=()=>E.current.schedule(),O=()=>{aJ(p.current),p.current=iJ(w)};return(0,Z.useEffect)(()=>{E.current.now()}),(0,Z.useEffect)(()=>()=>E.current?.cancel(),[]),(0,Z.useEffect)(()=>{d.current=null,D()},[i]),(0,Z.useLayoutEffect)(()=>{let e=u.current;if(!e)return;let t=new uJ(()=>{d.current=null,D(),O()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{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])-S1.left,h=e=>p(i.y[e])-S1.top,_=a+6,v=`${s}|${c}|${_}`;(!t||t.model!==o||t.key!==v)&&(t={model:o,key:v,g:V$(i.length,l,u,_,m,h)}),f.current=H$(t.g,n.clientX-r.left-S1.left,n.clientY-r.top-S1.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)}},[]),(0,Q.jsxs)(`div`,{ref:u,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:s,className:`chart-canvas`,role:`img`,"aria-label":`Bubble chart`}),(0,Q.jsx)(`canvas`,{ref:c,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),(0,Q.jsx)(`canvas`,{ref:l,className:`chart-canvas chart-overlay`})]})}var A1={top:8,right:8,bottom:8,left:8},j1=[`#f97316`,`#38bdf8`,`#4ade80`,`#a78bfa`,`#fbbf24`,`#fb7185`,`#34d399`,`#e879f9`,`#facc15`,`#60a5fa`];function M1(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 N1(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=N1(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 P1({nodes:e,backgroundToken:t=``,onPlotContextMenu:n}){let r=(0,Z.useRef)(null),i=(0,Z.useRef)(null),a=(0,Z.useRef)(null),o=(0,Z.useRef)(null),s=(0,Z.useRef)([]),c=(0,Z.useRef)(null),l=(0,Z.useRef)(0),u=(0,Z.useRef)(n);(0,Z.useLayoutEffect)(()=>{u.current=n},[n]);let d=(0,Z.useRef)({nodes:e});(0,Z.useLayoutEffect)(()=>{d.current={nodes:e}},[e]);let f=(0,Z.useMemo)(()=>M1(e),[e]),p=(0,Z.useRef)(f);(0,Z.useLayoutEffect)(()=>{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 ${X.sans}`,i.textAlign=`left`,i.textBaseline=`top`,i.fillText(`No data`,A1.left+8,A1.top+8);return}let u=p.current,f=t-A1.left-A1.right,_=n-A1.top-A1.bottom,v=N1(u,A1.left,A1.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=j1[l%j1.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 ${X.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 ${X.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=(0,Z.useRef)(_);y.current=_;let b=(0,Z.useRef)(null);b.current??=dJ(()=>y.current(),()=>a.current?.ownerDocument);let x=()=>b.current.schedule(),S=()=>{aJ(l.current),l.current=iJ(v)};return(0,Z.useEffect)(()=>{b.current.now()}),(0,Z.useEffect)(()=>()=>b.current?.cancel(),[]),(0,Z.useEffect)(()=>{o.current=null,x()},[t]),(0,Z.useLayoutEffect)(()=>{let e=a.current;if(!e)return;let t=new uJ(()=>{o.current=null,x(),S()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{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)}},[]),(0,Q.jsxs)(`div`,{ref:a,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:r,className:`chart-canvas`,role:`img`,"aria-label":`Treemap`}),(0,Q.jsx)(`canvas`,{ref:i,className:`chart-canvas chart-overlay`})]})}var F1={top:8,right:8,bottom:8,left:8},I1=14,L1=8,R1=[`#38bdf8`,`#4ade80`,`#fb7185`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`,`#facc15`,`#60a5fa`];function z1(e,t,n,r){if(e.length===0||t.length===0)return{nodes:[],links:[]};let i=n-F1.left-F1.right,a=r-F1.top-F1.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=>F1.left+e/Math.max(1,c)*(i-I1),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)*L1,i=0;for(let e of n)i+=Math.max(8,(d.get(e)??0)/f*r*.8);let o=F1.top+(a-i-(n.length-1)*L1)/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:R1[e.indexOf(a)%R1.length]}),o+=s+L1}}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+I1,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 B1({nodeNames:e,links:t,backgroundToken:n=``,onPlotContextMenu:r}){let i=(0,Z.useRef)(null),a=(0,Z.useRef)(null),o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),c=(0,Z.useRef)({nodes:[],links:[]}),l=(0,Z.useRef)(null),u=(0,Z.useRef)(0),d=(0,Z.useRef)(r);(0,Z.useLayoutEffect)(()=>{d.current=r},[r]);let f=(0,Z.useRef)({nodeNames:e,links:t});(0,Z.useLayoutEffect)(()=>{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 ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`No data — set source/target/value columns`,F1.left+8,F1.top+8);return}let d=z1(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,I1,e.h),r.globalAlpha=1,r.fillStyle=o,r.font=`9px ${X.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+I1+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 ${X.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=(0,Z.useRef)(g);v.current=g;let y=(0,Z.useRef)(null);y.current??=dJ(()=>v.current(),()=>o.current?.ownerDocument);let b=()=>y.current.schedule(),x=()=>{aJ(u.current),u.current=iJ(_)};return(0,Z.useEffect)(()=>{y.current.now()}),(0,Z.useEffect)(()=>()=>y.current?.cancel(),[]),(0,Z.useEffect)(()=>{s.current=null,b()},[n]),(0,Z.useLayoutEffect)(()=>{let e=o.current;if(!e)return;let t=new uJ(()=>{s.current=null,b(),x()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{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)}},[]),(0,Q.jsxs)(`div`,{ref:o,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:i,className:`chart-canvas`,role:`img`,"aria-label":`Sankey diagram`}),(0,Q.jsx)(`canvas`,{ref:a,className:`chart-canvas chart-overlay`})]})}var V1={top:24,right:24,bottom:52,left:52};function H1({bins:e,color:t=`#38bdf8`,backgroundToken:n=``,onPlotContextMenu:r}){let i=(0,Z.useRef)(null),a=(0,Z.useRef)(null),o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(0),u=(0,Z.useRef)(r);(0,Z.useLayoutEffect)(()=>{u.current=r},[r]);let d=(0,Z.useRef)({bins:e,color:t});(0,Z.useLayoutEffect)(()=>{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 ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`No data`,V1.left+8,V1.top+8);return}let{top:h,right:g,bottom:_,left:v}=V1,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 ${X.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 ${X.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}=V1,f=t-u-V1.right,h=n-l-V1.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 ${X.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 _=(0,Z.useRef)(h);_.current=h;let v=(0,Z.useRef)(null);v.current??=dJ(()=>_.current(),()=>o.current?.ownerDocument);let y=()=>v.current.schedule(),b=()=>{aJ(l.current),l.current=iJ(g)};return(0,Z.useEffect)(()=>{v.current.now()}),(0,Z.useEffect)(()=>()=>v.current?.cancel(),[]),(0,Z.useEffect)(()=>{s.current=null,y()},[n]),(0,Z.useLayoutEffect)(()=>{let e=o.current;if(!e)return;let t=new uJ(()=>{s.current=null,y(),b()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{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-V1.left-V1.right,s=-1,l=20;for(let e=0;e<r.length;e++){let t=V1.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)}},[]),(0,Q.jsxs)(`div`,{ref:o,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:i,className:`chart-canvas`,role:`img`,"aria-label":`Calibration curve`}),(0,Q.jsx)(`canvas`,{ref:a,className:`chart-canvas chart-overlay`})]})}var U1={top:24,right:24,bottom:48,left:52};function W1({points:e,color:t=`#a78bfa`,backgroundToken:n=``,onPlotContextMenu:r}){let i=xJ(),a=(0,Z.useRef)(null),o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(null),u=(0,Z.useRef)(0),d=(0,Z.useRef)(r);(0,Z.useLayoutEffect)(()=>{d.current=r},[r]);let f=(0,Z.useRef)({points:e,color:t});(0,Z.useLayoutEffect)(()=>{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 ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`No data`,U1.left+8,U1.top+8);return}let{xLo:_,xHi:v,yLo:y,yHi:b}=g(),{top:x,right:S,bottom:C,left:w}=U1,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 ${X.mono}`,r.textAlign=`center`,r.textBaseline=`top`,r.fillText(ZG(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(ZG(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 ${X.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}=U1,y=t-v-U1.right,b=n-_-U1.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=`(${QG(s.theoretical)}, ${QG(s.sample)})`;r.font=`11px ${X.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=(0,Z.useRef)(_);y.current=_;let b=(0,Z.useRef)(null);b.current??=dJ(()=>y.current(),()=>s.current?.ownerDocument);let x=()=>b.current.schedule(),S=()=>{aJ(u.current),u.current=iJ(v)};return(0,Z.useEffect)(()=>{b.current.now()}),(0,Z.useEffect)(()=>()=>b.current?.cancel(),[]),(0,Z.useEffect)(()=>{c.current=null,x()},[n]),(0,Z.useLayoutEffect)(()=>{let e=s.current;if(!e)return;let t=new uJ(()=>{c.current=null,x(),S()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{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}=U1,p=i-d-U1.right,h=n.height-u-U1.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)}},[]),(0,Q.jsxs)(`div`,{ref:s,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:a,className:`chart-canvas`,role:`img`,"aria-label":`Q-Q plot`}),(0,Q.jsx)(`canvas`,{ref:o,className:`chart-canvas chart-overlay`})]})}var G1={top:8,right:16,bottom:40,left:120},K1=22,q1=3,J1=[`#38bdf8`,`#4ade80`,`#fb7185`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`,`#facc15`,`#60a5fa`];function Y1({tasks:e,backgroundToken:t=``,onPlotContextMenu:n}){let r=xJ(),i=(0,Z.useRef)(null),a=(0,Z.useRef)(null),o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(0),u=(0,Z.useRef)(n);(0,Z.useLayoutEffect)(()=>{u.current=n},[n]);let d=(0,Z.useRef)({tasks:e});(0,Z.useLayoutEffect)(()=>{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 ${X.sans}`,a.textAlign=`left`,a.textBaseline=`top`,a.fillText(`No data`,G1.left+8,G1.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}=G1,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*(K1+q1)+v;a.beginPath(),a.moveTo(n,v),a.lineTo(n,r),a.stroke(),a.fillStyle=s,a.font=`9px ${X.mono}`,a.textAlign=`center`,a.textBaseline=`top`,a.fillText(ZG(t,(g-h)/T),n,r+4)}for(let e=0;e<u.length;e++){let t=u[e],n=v+e*(K1+q1),r=J1[(w.get(t.group??t.label)??0)%J1.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,K1-q1),a.globalAlpha=1,a.fillStyle=s,a.font=`9px ${X.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+(K1-q1)/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}: ${QG(s.start)} → ${QG(s.end)} (${QG(l)})`;r.font=`11px ${X.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-G1.left-G1.right,y=e=>G1.left+(e-h)/(g-h)*v,b=G1.top+i*(K1+q1),x=(y(s.start)+y(s.end))/2,S=Math.max(4,Math.min(t-f-8,x-f/2)),C=b-22<G1.top?b+K1+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 _=(0,Z.useRef)(h);_.current=h;let v=(0,Z.useRef)(null);v.current??=dJ(()=>_.current(),()=>o.current?.ownerDocument);let y=()=>v.current.schedule(),b=()=>{aJ(l.current),l.current=iJ(g)};return(0,Z.useEffect)(()=>{v.current.now()}),(0,Z.useEffect)(()=>()=>v.current?.cancel(),[]),(0,Z.useEffect)(()=>{s.current=null,y()},[t]),(0,Z.useLayoutEffect)(()=>{let e=o.current;if(!e)return;let t=new uJ(()=>{s.current=null,y(),b()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{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-G1.top)/(K1+q1));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)}},[]),(0,Q.jsxs)(`div`,{ref:o,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:i,className:`chart-canvas`,role:`img`,"aria-label":`Gantt chart`}),(0,Q.jsx)(`canvas`,{ref:a,className:`chart-canvas chart-overlay`})]})}var X1=e=>[...e].filter(e=>Number.isFinite(e.at)).sort((e,t)=>e.at-t.at),Z1=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]},Q1=e=>`#${e.map(e=>Math.round(e).toString(16).padStart(2,`0`)).join(``)}`;function $1(e,t,n,r){let i=t?X1(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=Z1(o.color),u=Z1(s.color);return Q1([l[0]+(u[0]-l[0])*c,l[1]+(u[1]-l[1])*c,l[2]+(u[2]-l[2])*c])}function e0(e,t,n,r,i,a=96){let o=i-r||1,s=t?X1(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:$1(`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:$1(`gradient`,s,n,r+(t+.5)/a*o)}))}var t0=.75*Math.PI,n0=1.5*Math.PI;function r0({gauges:e,backgroundToken:t=``,onPlotContextMenu:n}){let r=(0,Z.useRef)(null),i=(0,Z.useRef)(null),a=(0,Z.useRef)(null),o=(0,Z.useRef)(n);(0,Z.useLayoutEffect)(()=>{o.current=n},[n]);let s=(0,Z.useRef)({gauges:e});(0,Z.useLayoutEffect)(()=>{s.current={gauges:e}},[e]);function c(){if(a.current)return a.current;let e=i.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 a.current=n,n}function l(){let e=r.current,t=i.current;if(!e||!t)return;let n=Math.max(1,t.clientWidth),a=Math.max(1,t.clientHeight),o=Math.min(2,window.devicePixelRatio||1),l=Math.floor(n*o),u=Math.floor(a*o);(e.width!==l||e.height!==u)&&(e.width=l,e.height=u),e.style.width=`${n}px`,e.style.height=`${a}px`;let d=e.getContext(`2d`);if(!d)return;d.setTransform(o,0,0,o,0,0);let f=c(),{gauges:p}=s.current;if(d.fillStyle=f.bg,d.fillRect(0,0,n,a),p.length===0){d.fillStyle=f.muted,d.font=`13px ${X.sans}`,d.textAlign=`left`,d.textBaseline=`top`,d.fillText(`No data`,16,16);return}let{cols:m,rows:h}=i0(p.length,n,a,p.some(e=>e.style===`arc`)?1.15:3.2),g=n/m,_=a/h;p.forEach((e,t)=>{let n=t%m*g,r=Math.floor(t/m)*_;e.style===`arc`?p0(d,e,n,r,g,_,e.color,e.alarm??null,f):m0(d,e,n,r,g,_,e.color,e.alarm??null,f)})}let u=(0,Z.useRef)(l);u.current=l;let d=(0,Z.useRef)(null);return d.current??=dJ(()=>u.current(),()=>i.current?.ownerDocument),(0,Z.useEffect)(()=>{d.current.now()}),(0,Z.useEffect)(()=>()=>d.current?.cancel(),[]),(0,Z.useEffect)(()=>{a.current=null,d.current.schedule()},[t]),(0,Z.useLayoutEffect)(()=>{let e=i.current;if(!e)return;let t=new uJ(()=>{a.current=null,d.current.schedule()});return t.observe(e),()=>t.disconnect()},[]),(0,Q.jsx)(`div`,{ref:i,style:{position:`relative`,width:`100%`,height:`100%`},children:(0,Q.jsx)(`canvas`,{ref:r,className:`chart-canvas`,role:`img`,"aria-label":`Gauges: ${e.map(e=>`${e.name} ${Number.isFinite(e.value)?a0(e.value,e.max-e.min):`no value`}${e.unit?` ${e.unit}`:``}`).join(`, `)}`,onContextMenu:e=>{e.preventDefault(),o.current?.({clientX:e.clientX,clientY:e.clientY})}})})}function i0(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 a0=(e,t)=>ZG(e,WG(Math.abs(t),100)),o0=(e,t)=>Math.max(0,Math.min(1,(t-e.min)/(e.max-e.min||1))),s0=(e,t)=>!!t&&Number.isFinite(e.value)&&e.value>=t.value,c0=e=>(e.colorMode===`gradient`||e.colorMode===`zones`)&&!!e.stops?.length,l0=(e,t)=>s0(e,t)?t.color:$1(e.colorMode,e.stops,e.color,e.value);function u0(e,t,n){for(let r of e0(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 d0(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 f0=Math.SQRT1_2;function p0(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=a0(t.min,u),f=a0(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 ${X.mono}`,g=Math.max(e.measureText(d).width,e.measureText(f).width);let t=m(h),n=Math.max(h+t/2,f0*h+g/2),r=h+t/2+f0*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+f0*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=>t0+e*n0;e.lineCap=`round`,e.lineWidth=_,e.strokeStyle=c.grid,e.beginPath(),e.arc(b,x,h,t0,t0+n0),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(o0(t,s.value)),t0+n0),e.stroke(),e.globalAlpha=1,e.lineCap=`round`);let C=Number.isFinite(t.value)?o0(t,t.value):0;if(c0(t)){let n=n0/(2*Math.PI),r=u0(e.createConicGradient(t0,b,x),t,e=>e*n);r.addColorStop(1,$1(t.colorMode,t.stops,t.color,t.min)),e.strokeStyle=r,e.globalAlpha=.24,e.beginPath(),e.arc(b,x,h,t0,t0+n0),e.stroke(),e.globalAlpha=1,Number.isFinite(t.value)&&!s0(t,s)&&(e.beginPath(),e.arc(b,x,h,t0,Math.max(t0+1e-4,S(C))),e.stroke())}if(Number.isFinite(t.value)&&(!c0(t)||s0(t,s))&&(e.strokeStyle=s0(t,s)?s.color:o,e.beginPath(),e.arc(b,x,h,t0,Math.max(t0+1e-4,S(C))),e.stroke()),s&&s.value>=t.min&&s.value<=t.max){let n=S(o0(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 w=Number.isFinite(t.value)?a0(t.value,u):`—`,T=2*(h-_)*.82,E=Math.max(11,h*.42);e.font=`650 ${E}px ${X.sans}`;let D=e.measureText(w).width;D>T&&(E=Math.max(9,E*T/D),e.font=`650 ${E}px ${X.sans}`),e.textAlign=`center`,e.textBaseline=`alphabetic`,e.fillStyle=s0(t,s)||c0(t)?l0(t,s):c.ink,e.fillText(w,b,x+E*.32),e.fillStyle=c.muted,t.unit&&(e.font=`600 ${Math.max(9,h*.13)}px ${X.sans}`,e.fillText(d0(e,t.unit,T),b,x+E*.32+Math.max(11,h*.19)));let O=x+f0*h+_/2+6,k=f0*h;e.textBaseline=`top`,e.font=`${v}px ${X.mono}`,e.fillText(d,b-k,O),e.fillText(f,b+k,O);let A=2*k-g-16,j=Math.max(10,Math.min(26,h*.13));e.font=`600 ${j}px ${X.sans}`;let M=e.measureText(t.name).width;M>A&&j>9&&(j=Math.max(9,j*A/M),e.font=`600 ${j}px ${X.sans}`),e.fillText(d0(e,t.name,A),b,O+(v-j)/2)}function m0(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+o0(t,e)*f;e.textBaseline=`alphabetic`,e.fillStyle=c.muted,e.font=`600 ${Math.max(10,m*.42)}px ${X.sans}`,e.textAlign=`left`,e.fillText(d0(e,t.name,f),u,h-p/2-m-4),e.textAlign=`right`,e.fillStyle=s0(t,s)?s.color:c.ink,e.font=`650 ${m}px ${X.sans}`;let _=t.unit?(e.font=`600 ${Math.max(9,m*.4)}px ${X.sans}`,e.measureText(` ${t.unit}`).width):0;t.unit&&(e.fillStyle=c.muted,e.fillText(` ${t.unit}`,d,h-p/2-8)),e.fillStyle=s0(t,s)||c0(t)?l0(t,s):c.ink,e.font=`650 ${m}px ${X.sans}`,e.fillText(Number.isFinite(t.value)?a0(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)?o0(t,t.value):0,y=e=>u+e*f;c0(t)&&(e.strokeStyle=u0(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)&&!s0(t,s)&&(e.beginPath(),e.moveTo(u,h),e.lineTo(Math.max(u+.5,y(v)),h),e.stroke())),Number.isFinite(t.value)&&(!c0(t)||s0(t,s))&&(e.strokeStyle=s0(t,s)?s.color:o,e.beginPath(),e.moveTo(u,h),e.lineTo(Math.max(u+.5,y(v)),h),e.stroke()),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()),e.fillStyle=c.muted,e.font=`${Math.max(9,m*.34)}px ${X.mono}`,e.textBaseline=`top`,e.textAlign=`left`,e.fillText(a0(t.min,t.max-t.min),u,h+p/2+4),e.textAlign=`right`,e.fillText(a0(t.max,t.max-t.min),d,h+p/2+4)}function h0(e,t){let n=e.filter(e=>e.x.length>=2&&g0(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 g0(e){for(let t=1;t<e.length;t++)if(!(e[t]>=e[t-1]))return!1;return!0}function _0(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)}}Aw();function v0(e,t){return e.filter(e=>Cw(t,e))}qw();var y0=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?Ww(new Float64Array,new Float64Array,e.viewport.x0,e.viewport.x1,e.maxPoints):Ww(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}:Vw(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:Gw(r,i.map(e=>this.#e.get(e)),i,t.x0,t.x1,n)}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 b0(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 x0(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)=>b0(i+(t+.5)*(c/n))),m=Array.from({length:r},(e,t)=>b0(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}}oW(),yW();var S0=8e3,C0=3e3,w0=[];function T0(e){return`live`in e?e.live.source.columns():`source`in e&&e.source instanceof y0?e.source.columnMap:void 0}var E0=4e3,D0=new WeakMap;function O0(e,t,n){let r=D0.get(e);r||D0.set(e,r=new Map);let i=JSON.stringify([n,...t]),a=r.get(i);return a||r.set(i,a=new Xw({meta:``,columnNames:[n,...t],units:[],rows:e})),a}var k0=new WeakMap;function A0(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 j0(e,t){let n=1/0,r=-1/0;for(let{rows:i,offset:a}of e){let e=k0.get(i);e||(e=new Map,k0.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 M0(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 N0=new Map;function P0(e){let t=N0.get(e);return t||(t=Float64Array.from({length:e},(e,t)=>t),N0.clear(),N0.set(e,t)),t}function F0(e){let{worksheet:t,viewXRange:n,selectedIds:r,selectedDatasets:i,mathChannels:a,datasetOffsets:o,datasetColors:s,datasetPalette:c}=e,l=t.panels,u=t.panelChartSettings,d=t.xKey,f={connections:(0,Z.useMemo)(()=>d===`ElapsedTime`?e.liveConnections:e.liveConnections.map(e=>{let t=M0(e.dataset.rows,d);return t===e.dataset.rows?e:{...e,dataset:{...e.dataset,rows:t}}}),[e.liveConnections,d])},[p,m]=(0,Z.useState)({}),h=(0,Z.useMemo)(()=>l.some(e=>e.kind!==`multiband`),[l]),g=(0,Z.useMemo)(()=>f.connections.some(e=>r.includes(e.id)),[f.connections,r]),_=(0,Z.useMemo)(()=>{let e=f.connections.filter(e=>r.includes(e.id));return e.length===1&&i.length===0?e[0]:null},[f.connections,r,i]),v=(0,Z.useMemo)(()=>_0(i.map(e=>{let t=p[e.id];return t?{...e.data,rows:t}:e.data})),[i,p]),y=(0,Z.useMemo)(()=>{let e=f.connections.filter(e=>r.includes(e.id)).map(e=>e.dataset);return e.length===0?v:_0(v?[v,...e]:e)},[v,f.connections,r]),b=(0,Z.useMemo)(()=>rw(a,u,d).map(e=>e.id).join(`
|
|
623
|
+
}`,qZ=-3e38;function JZ(e){for(let t=0;t<e.length;t++)if(e[t]-e[t]===0)return e[t];return 0}function YZ(e){let t=e.getContext(`webgl2`,{antialias:!1,alpha:!0,premultipliedAlpha:!0});if(!t)return null;let n=(e,n,i,a)=>Iq(t,`glPlot|${e}|${n}`,()=>r(e,n,i,a)),r=(e,n,r,i)=>{let a=vq(t,t.VERTEX_SHADER,e),o=vq(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(zZ,VZ,[`a_xa`,`a_xb`,`a_loa`,`a_lob`,`a_hia`,`a_hib`,`a_bstart`],[`u_color`]),a=n(BZ,HZ,[`a_x0`,`a_x1`,`a_y0`,`a_y1`,`a_k`],[`u_palette`]),o=n(UZ,WZ,[`a_ax`,`a_ay`,`a_bx`,`a_by`,`a_bstart`],[`u_color`,`u_half`,`u_ext`]),s=n(GZ,KZ,[],[`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=JZ(t),o.oy=JZ(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=JZ(n),c.oy=JZ(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=JZ(t),o.oy=JZ(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:qZ}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 XZ(e){let t=(0,Z.useRef)({plot:null,failed:!1,size:``});return(0,Z.useEffect)(()=>()=>{t.current.plot?.dispose(),t.current.plot=null},[]),(0,Z.useCallback)((n,r)=>{let i=t.current,a=e.current;if(!i.plot&&!i.failed&&a&&(i.plot=Lq(a,YZ),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 ZZ(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 QZ=16;function $Z(e,t,n,r){let i=ZZ(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(QZ),m=new Int32Array(QZ);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(QZ-1,Math.floor(a/(2*Math.PI)*QZ));p[o]+=t[e],m[o]++}return{n:a,rMin:c,rMax:l,x:d,y:f,means:Array.from({length:QZ},(e,t)=>m[t]>0?p[t]/m[t]:0)}}function eQ({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=(0,Z.useRef)(null),f=(0,Z.useRef)(null),p=(0,Z.useRef)(null),m=(0,Z.useRef)(u);(0,Z.useLayoutEffect)(()=>{m.current=u},[u]);let h=(0,Z.useRef)({angles:e,radii:t,angleLabel:n,radiusLabel:r,color:i,mode:a,radiusMin:o,radiusMax:s,height:c});(0,Z.useLayoutEffect)(()=>{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=(0,Z.useMemo)(()=>$Z(e,t,o,s),[e,t,o,s]),_=(0,Z.useRef)(g);(0,Z.useLayoutEffect)(()=>{_.current=g},[g]);let v=(0,Z.useRef)(null),y=XZ(v),b=(0,Z.useRef)({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 ${X.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=WG(w,4),k=qG(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 ${X.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(ZG(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,lZ(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/QZ;r.fillStyle=l,r.globalAlpha=.75;for(let i=0;i<QZ;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<QZ;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 ${X.mono}`,r.textAlign=`center`,r.textBaseline=`bottom`,r.fillText(`${s} / ${c}`,E,n-4)}let T=(0,Z.useRef)(w);T.current=w;let E=(0,Z.useRef)(null);E.current??=dJ(()=>T.current(),()=>f.current?.ownerDocument);let D=()=>E.current.schedule();return(0,Z.useEffect)(()=>{E.current.now()}),(0,Z.useEffect)(()=>()=>E.current?.cancel(),[]),(0,Z.useEffect)(()=>{p.current=null,D()},[l]),(0,Z.useLayoutEffect)(()=>{let e=f.current;if(!e)return;let t=new uJ(()=>{p.current=null,D()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{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)},[]),(0,Q.jsxs)(`div`,{ref:f,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:d,className:`chart-canvas`,role:`img`,"aria-label":`Polar chart: ${n} vs ${r}`}),(0,Q.jsx)(`canvas`,{ref:v,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}})]})}function tQ(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 nQ(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 rQ(e,t){let n=new Float64Array(t.length);for(let r=0;r<t.length;r++)n[r]=e[t[r]];return n}function iQ(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 aQ(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 oQ=new Float64Array,sQ=new Float64Array;function cQ(e,t,n){let r=t>>1;oQ.length<r&&(oQ=new Float64Array(r),sQ=new Float64Array(r));let i=oQ.subarray(0,r),a=sQ.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}aQ(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 lQ=new Float64Array,uQ=0;function dQ(e){if(uQ===e)return lQ.subarray(0,e);lQ.length<e&&(lQ=new Float64Array(Math.max(e,lQ.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++){lQ[t]=.5*(1-i);let e=i*n-a*r;a=a*n+i*r,i=e}return uQ=e,lQ.subarray(0,e)}var fQ={top:14,right:24,bottom:40,left:64},pQ=5;function mQ(e){let t=1;for(;t<e;)t<<=1;return t}function hQ(e,t,n,r){let i=e.length,a=Math.max(2,mQ(i)),o=cQ(e,a,n===`hann`?dQ(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 gQ({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=xJ(),f=(0,Z.useRef)(null),p=(0,Z.useRef)(null),m=(0,Z.useRef)(null),h=(0,Z.useRef)(u);(0,Z.useLayoutEffect)(()=>{h.current=u},[u]);let g=(0,Z.useRef)({signal:e,sampleRate:t,label:n,xMode:r,yMode:i,window:a,color:o,logX:s,height:c});(0,Z.useLayoutEffect)(()=>{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 _=(0,Z.useMemo)(()=>e.length>=4?hQ(e,t,a,i):null,[e,t,a,i]),v=(0,Z.useMemo)(()=>_&&s?_.freqs.map(e=>Math.log10(e)):null,[_,s]),y=(0,Z.useRef)(_&&{..._,logFreqs:v});(0,Z.useLayoutEffect)(()=>{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}=fQ,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 ${X.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 ${X.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=WG(I-F,5),V=qG(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 H=T?1:WG(P-N,GG(c)),U=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})():qG(N,P,H);r.strokeStyle=m,r.lineWidth=1,r.setLineDash([3,3]);for(let e of U)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 ${X.mono}`,r.textAlign=`right`,r.textBaseline=`middle`;for(let e of V)r.beginPath(),r.moveTo(s-pQ,z(e)),r.lineTo(s,z(e)),r.stroke(),r.fillText(ZG(e,B),s-4,z(e));r.textAlign=`center`,r.textBaseline=`top`;for(let e of U)r.beginPath(),r.moveTo(R(e),i+l),r.lineTo(R(e),i+l+pQ),r.stroke(),r.fillText(ZG(e,T?e:H),R(e),i+l+pQ+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 W=!1,ee=Math.min(2,window.devicePixelRatio||1),te=Math.max(1,Math.round(c*ee)),ne=A>te*4?T&&k?tQ(k,O,Math.log10(N*M),Math.log10(P*M),te):tQ(D,O,N*M,P*M,te):null;for(let e=+!ne;e<(ne?ne.length:A);e++){let t=ne?ne[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]);W?r.lineTo(i,a):(r.moveTo(i,a),W=!0)}r.stroke(),r.restore(),r.fillStyle=p,r.font=`11px ${X.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=(0,Z.useRef)(C);w.current=C;let T=(0,Z.useRef)(null);T.current??=dJ(()=>w.current(),()=>p.current?.ownerDocument);let E=()=>T.current.schedule();return(0,Z.useEffect)(()=>{T.current.now()}),(0,Z.useEffect)(()=>()=>T.current?.cancel(),[]),(0,Z.useEffect)(()=>{m.current=null,E()},[l]),(0,Z.useLayoutEffect)(()=>{let e=p.current;if(!e)return;let t=new uJ(()=>{m.current=null,E()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{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)},[]),(0,Q.jsx)(`div`,{ref:p,style:{position:`relative`,width:`100%`,height:`100%`},children:(0,Q.jsx)(`canvas`,{ref:f,className:`chart-canvas`,role:`img`,"aria-label":`Spectrum of ${n}`})})}function _Q(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 vQ(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,_Q(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 yQ={top:14,right:24,bottom:48,left:64},bQ=5;function xQ(e,t){let n=e.length;if(n===0)return null;let[r,i,a,o,s]=vQ(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=xJ(),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(null),u=(0,Z.useRef)(a);(0,Z.useLayoutEffect)(()=>{u.current=a},[a]);let d=(0,Z.useRef)({groups:e,color:t,whiskers:n,height:r});(0,Z.useLayoutEffect)(()=>{d.current={groups:e,color:t,whiskers:n,height:r}},[e,t,n,r]);let f=(0,Z.useMemo)(()=>e.filter(e=>e.values.length>0).map(e=>({label:e.label,box:xQ(e.values,n)})),[e,n]),p=(0,Z.useRef)(f);(0,Z.useLayoutEffect)(()=>{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}=yQ,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 ${X.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=WG(C-S,5),D=qG(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 ${X.mono}`,r.textAlign=`right`,r.textBaseline=`middle`;for(let e of D)r.beginPath(),r.moveTo(l-bQ,T(e)),r.lineTo(l,T(e)),r.stroke(),r.fillText(ZG(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 ${X.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+bQ+2,k-4,c-bQ-4),r.clip(),r.fillText(n,t,i+f+bQ+2),r.restore()}}let v=(0,Z.useRef)(_);v.current=_;let y=(0,Z.useRef)(null);y.current??=dJ(()=>v.current(),()=>c.current?.ownerDocument);let b=()=>y.current.schedule();return(0,Z.useEffect)(()=>{y.current.now()}),(0,Z.useEffect)(()=>()=>y.current?.cancel(),[]),(0,Z.useEffect)(()=>{l.current=null,b()},[i]),(0,Z.useLayoutEffect)(()=>{let e=c.current;if(!e)return;let t=new uJ(()=>{l.current=null,b()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{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)},[]),(0,Q.jsx)(`div`,{ref:c,style:{position:`relative`,width:`100%`,height:`100%`},children:(0,Q.jsx)(`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 wQ=e=>e.includes(`.`)&&!e.includes(`e`)?e.replace(/\.?0+$/,``):e;function TQ(e){return e>=1e3?`${wQ((e/1e3).toPrecision(3))}k`:wQ(e.toPrecision(3))}function EQ(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 DQ={top:14,right:24,bottom:40,left:68},OQ=[[8,0,16],[48,0,96],[104,0,144],[160,0,128],[200,32,64],[230,100,16],[250,200,32],[255,255,220]],kQ=-80;function AQ(e){let t=OQ.length-1,n=Math.min(t-1,Math.floor(e*t)),r=e*t-n,[i,a,o]=OQ[n],[s,c,l]=OQ[n+1];return[i+(s-i)*r,a+(c-a)*r,o+(l-o)*r]}var jQ=(()=>{let e=new Uint8Array(256*4);for(let t=0;t<256;t++){let[n,r,i]=AQ(t/255);e.set([n,r,i,255],t*4)}return e})();function MQ(e){let t=1;for(;t<e;)t<<=1;return t}var NQ=(e,t)=>Math.log(1+e/t*9)/Math.log(10),PQ=(e,t)=>t*(10**e-1)/9;function FQ({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=xJ(),d=(0,Z.useRef)(null),f=(0,Z.useRef)(null),p=(0,Z.useRef)(null),m=(0,Z.useRef)(null),h=(0,Z.useRef)(null),g=(0,Z.useRef)(l);(0,Z.useLayoutEffect)(()=>{g.current=l},[l]);let _=MQ(Math.max(4,Math.min(n,4096))),v=Math.max(1,Math.round(_*(1-Math.max(0,Math.min(.95,r))))),y=(0,Z.useMemo)(()=>{if(!o)return null;let e=_>>1,n=t/2;return Int32Array.from({length:e},(t,r)=>Math.min(e-1,Math.floor(PQ((r+.5)/e,n)/n*e)))},[o,_,t]),b=(0,Z.useRef)(null),x=(0,Z.useMemo)(()=>b.current=EQ(e,_,v,i===`hann`,a===`db`,y,b.current),[e,_,v,i,a,y]),S=(0,Z.useMemo)(()=>({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+kQ,C]:[0,C],T=(0,Z.useRef)({grid:S,range:w,sampleRate:t,winSz:_,step:v,yMode:a,logFreq:o,label:s});(0,Z.useLayoutEffect)(()=>{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=(0,Z.useRef)({plot:null,failed:!1,size:``,grid:null,shown:null});(0,Z.useEffect)(()=>()=>{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=Lq(f.current,YZ),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=cX(DQ,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 ${X.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],jQ,P,F),E.current.grid=y,E.current.shown=e,sJ(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]=AQ(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?NQ(e,R):e/R));L.strokeStyle=v,L.lineWidth=.5,L.globalAlpha=.4;let B=qG(0,R,WG(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 ${X.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(TQ(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 H=WG(V,6),U=qG(0,V,H);r.textAlign=`center`,r.textBaseline=`top`;for(let e of U){let t=l+e/V*f;r.beginPath(),r.moveTo(t,o+h),r.lineTo(t,o+h+4),r.stroke(),r.fillText(ZG(e,H),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=(0,Z.useRef)(j);(0,Z.useLayoutEffect)(()=>{M.current=j});let N=(0,Z.useRef)(null);return N.current??=dJ(()=>M.current(),()=>m.current?.ownerDocument),(0,Z.useEffect)(()=>{N.current.now()},[S,w[0],w[1],t,_,v,a,o,s]),(0,Z.useEffect)(()=>()=>N.current?.cancel(),[]),(0,Z.useEffect)(()=>{h.current=null,N.current.schedule()},[c]),(0,Z.useLayoutEffect)(()=>{let e=m.current;if(!e)return;let t=new uJ(()=>{h.current=null,N.current.schedule()});return t.observe(e),()=>t.disconnect()},[]),(0,Z.useLayoutEffect)(()=>{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)},[]),(0,Q.jsxs)(`div`,{ref:m,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:d,className:`chart-canvas`,role:`img`,"aria-label":`Spectrogram`}),(0,Q.jsx)(`canvas`,{ref:f,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),(0,Q.jsx)(`canvas`,{ref:p,className:`chart-canvas chart-overlay`})]})}var IQ=300,LQ=256,RQ=-60,zQ=[];function BQ({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=(0,Z.useMemo)(()=>EQ(e,c,l,i===`hann`,u,null),[e,c,l,i,u]);return(0,Q.jsx)(kZ,{points:zQ,surface:(0,Z.useMemo)(()=>VQ(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 VQ(e,t,n,r,i){let{frames:a,bins:o,values:s}=e;if(a<2||o<2)return;let c=Math.min(a,IQ),l=Math.min(o,LQ),u=i?20*Math.log10(Math.max(e.max,1e-12))+RQ:-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 HQ(e,t,n){return Array.from({length:n},(r,i)=>e+(i+1)/(n+1)*(t-e))}function UQ(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 WQ(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 GQ(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 KQ={top:14,right:32,bottom:80,left:80};function qQ(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 JQ=[[33,102,172],[103,169,207],[209,229,240],[247,247,247],[253,219,199],[239,138,98],[178,24,43]],YQ=[[13,8,135],[84,2,163],[139,10,165],[185,50,137],[219,92,104],[244,136,73],[254,188,43],[240,249,33]],XQ=[[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 ZQ(e,t){let n=e.length-1,r=Math.min(n-1,Math.floor(t*n));return qQ(e[r],e[r+1],t*n-r)}function QQ(e,t){return ZQ(t===`plasma`?YQ:t===`viridis`?XQ:JQ,e)}function $Q(e){let t=new Uint8Array(256*4);for(let n=0;n<256;n++){let[r,i,a]=QQ(n/255,e);t.set([r,i,a,255],n*4)}return t}function e$(e){return Math.abs(e)>=1e4||Math.abs(e)<.01&&e!==0?e.toExponential(1):String(parseFloat(e.toPrecision(3)))}function t$(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 n$(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=WQ(a),i=n[e.w]-n[0];u=Float64Array.from(n,e=>t+(e-n[0])/i*r)}if(l){let t=WQ(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 r$(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 i$(e,t,n,r,i,a){let o=Math.max(1,i),s=Math.max(1,a),c=Int32Array.from({length:o},(e,r)=>r$(t.xB,n+r+.5)),l=new Float32Array(o*s);for(let n=0;n<s;n++){let i=r$(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 a$({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=(0,Z.useRef)(null),m=(0,Z.useRef)(null),h=(0,Z.useRef)(null),g=(0,Z.useRef)(null),_=(0,Z.useRef)(null),v=(0,Z.useRef)(null),y=(0,Z.useRef)(null),b=(0,Z.useRef)(0),x=(0,Z.useRef)(f);(0,Z.useLayoutEffect)(()=>{x.current=f},[f]);let S=(0,Z.useMemo)(()=>r??t$(e??[],t??[],n??[]),[r,e,t,n]),C=(0,Z.useMemo)(()=>{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=(0,Z.useRef)({data:S,range:C,showValues:i,colorScheme:a,xCentres:c,yCentres:l,contours:u});(0,Z.useLayoutEffect)(()=>{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=(0,Z.useRef)({plot:null,failed:!1,size:``,data:null,key:``,shown:null,geo:null}),E=(0,Z.useRef)({key:``,grid:null,segs:[]});(0,Z.useEffect)(()=>()=>{T.current.plot?.dispose(),T.current.plot=null},[]);let D=(0,Z.useRef)({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=Lq(m.current,YZ),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=cX(KQ,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 ${X.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}`},sJ(_.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=n$(z,l,o,S,C,z===m?F:void 0,z===m?I:void 0),V=B.byValue,H=`${R}|${b}|${V?`${S}x${C}`:``}`,U=T.current.shown;if(T.current.data!==m||T.current.key!==H||!U){U=z;let e=V?i$(U,B,l,o,Math.round(S),Math.round(C)):U;x&&x.setGrid(`cells`,e.values,e.w,Math.min(e.h,x.maxTextureSize),[0,e.w,0,e.h],$Q(b),g,v),T.current.data=m,T.current.key=H,T.current.shown=U}T.current.geo=B;let W=V?Math.round(S):U.w,ee=V?Math.round(C):U.h,te=e=>B.xB[e+1]-B.xB[e],ne=e=>B.yB[e+1]-B.yB[e];if(x)x.keep([`cells`]),x.setGridRange(`cells`,g,v),x.setView(0,W,ee,0,{left:l,top:o,width:S,height:C}),x.render();else for(let e=0;e<U.h;e++)for(let t=0;t<U.w;t++){let n=U.values[e*U.w+t];if(Number.isNaN(n))continue;let[i,a,o]=QQ(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],te(t)+.5,ne(e)+.5)}let G=i??r;if(y){for(let e=0;e<U.h;e++)if(!(ne(e)<=16)){G.font=`${Math.min(12,Math.max(8,ne(e)*.4))}px ${X.mono}`,G.textAlign=`center`,G.textBaseline=`middle`;for(let t=0;t<U.w;t++){let n=U.values[e*U.w+t];if(Number.isNaN(n)||te(t)<=28)continue;let[r,i,a]=QQ(Math.max(0,Math.min(1,(n-g)/(v-g))),b);G.fillStyle=.299*r+.587*i+.114*a>128?`#000`:`#fff`,G.fillText(e$(n),(B.xB[t]+B.xB[t+1])/2,(B.yB[e]+B.yB[e+1])/2)}}}if(S/U.w>=4&&C/U.h>=4){G.strokeStyle=u,G.lineWidth=.5;for(let e=0;e<=U.w;e++)G.beginPath(),G.moveTo(B.xB[e],o),G.lineTo(B.xB[e],o+C),G.stroke();for(let e=0;e<=U.h;e++)G.beginPath(),G.moveTo(l,B.yB[e]),G.lineTo(l+S,B.yB[e]),G.stroke()}let re=L>0?HQ(g,v,L):[];if(re.length&&U.w>=2&&U.h>=2&&U.w*U.h<=4e6){let e=`${g}|${v}|${L}`;if(E.current.grid!==U||E.current.key!==e){let t=U;E.current={key:e,grid:t,segs:re.map(e=>UQ(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)};G.save(),G.beginPath(),G.rect(l,o,S,C),G.clip(),G.lineCap=`round`,G.lineJoin=`round`;for(let[e,n]of[[2.6,`rgba(0,0,0,0.38)`],[1.1,`rgba(255,255,255,0.92)`]]){G.lineWidth=e,G.strokeStyle=n,G.beginPath();for(let e of E.current.segs)for(let[n,r,i,a]of e)G.moveTo(t(n,B.xB),t(r,B.yB)),G.lineTo(t(i,B.xB),t(a,B.yB));G.stroke()}G.restore()}r.fillStyle=d,r.font=`10px ${X.mono}`,r.textAlign=`center`,r.textBaseline=`top`;let ie=-1/0;for(let e=0;e<(a.tiny?0:U.w);e++){let t=(B.xB[e]+B.xB[e+1])/2;t-ie<18||(ie=t,r.save(),r.translate(t,o+C+4),r.rotate(-Math.PI/4),r.fillText(M(U.xLabels,e),0,0),r.restore())}r.textAlign=`right`,r.textBaseline=`middle`;let ae=-1/0;for(let e=0;e<(a.tiny?0:U.h);e++){let t=(B.yB[e]+B.yB[e+1])/2;t-ae<12||(ae=t,r.fillText(U.yLabels[e]??``,l-4,t))}if(a.tiny)return;let oe=t-s+4,se=o,ce=C;for(let e=0;e<ce;e++){let[t,n,i]=QQ(1-e/ce,b);r.fillStyle=`rgb(${t|0},${n|0},${i|0})`,r.fillRect(oe,se+e,12,1)}r.strokeStyle=f,r.lineWidth=.5,r.strokeRect(oe,se,12,ce),r.fillStyle=d,r.font=`9px ${X.mono}`,r.textAlign=`left`,r.textBaseline=`middle`,r.fillText(e$(v),oe+12+2,se),r.fillText(e$(g),oe+12+2,se+ce),r.fillText(e$((g+v)/2),oe+12+2,se+ce/2),r.strokeStyle=`rgba(255,255,255,0.92)`,r.lineWidth=1;for(let e of re){let t=se+ce*(1-(e-g)/(v-g));r.beginPath(),r.moveTo(oe-2,t),r.lineTo(oe+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}=cX(KQ,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]}: ${e$(_)}`;r.font=`11px ${X.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=(0,Z.useRef)(N);F.current=N;let I=(0,Z.useRef)(null);I.current??=dJ(()=>F.current(),()=>_.current?.ownerDocument);let L=()=>{b.current||=iJ(()=>{b.current=0,P()})};return(0,Z.useEffect)(()=>{I.current.now()},[S,C,i,a,c,l,u]),(0,Z.useEffect)(()=>()=>{I.current?.cancel(),aJ(b.current)},[]),(0,Z.useEffect)(()=>{v.current=null,I.current.schedule()},[d]),(0,Z.useLayoutEffect)(()=>{let e=_.current;if(!e)return;let t=new uJ(()=>{v.current=null,I.current.schedule(),L()});return t.observe(e),()=>t.disconnect()},[]),(0,Z.useLayoutEffect)(()=>{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=r$(i.xB,t.clientX-n.left),o=r$(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)}},[]),(0,Q.jsxs)(`div`,{ref:_,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:p,className:`chart-canvas`,role:`img`,"aria-label":`Heatmap`}),(0,Q.jsx)(`canvas`,{ref:m,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),(0,Q.jsx)(`canvas`,{ref:h,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),(0,Q.jsx)(`canvas`,{ref:g,className:`chart-canvas chart-overlay`})]})}var o$=2e3,s$=1024;function c$(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<=o$){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(s$),l=(i-r)/s$||1;for(let t=0;t<a;t++)c[Math.max(0,Math.min(s$-1,Math.floor((e[t]-r)/l)))]++;for(let e=0;e<n.length;e++){let i=0;for(let a=0;a<s$;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 l$={top:14,right:24,bottom:48,left:64},u$=120;function d$(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 f$(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]=vQ(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:u$},(e,t)=>r+t/(u$-1)*(i-r));return{shapes:n.map((e,n)=>{let{q1:o,median:c,q3:l}=a[n],u=c$(e.values,t>0?t:d$(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 p$({groups:e,color:t=`#818cf8`,showBox:n=!0,bandwidth:r=0,orientation:i=`vertical`,backgroundToken:a=``,onPlotContextMenu:o}){let s=xJ(),c=(0,Z.useRef)(null),l=(0,Z.useRef)(null),u=(0,Z.useRef)(null),d=(0,Z.useRef)(o);(0,Z.useLayoutEffect)(()=>{d.current=o},[o]);let f=(0,Z.useRef)({groups:e,color:t,showBox:n,bandwidth:r,orientation:i});(0,Z.useLayoutEffect)(()=>{f.current={groups:e,color:t,showBox:n,bandwidth:r,orientation:i}},[e,t,n,r,i]);let p=(0,Z.useMemo)(()=>f$(e,r),[e,r]),m=(0,Z.useRef)(p);(0,Z.useLayoutEffect)(()=>{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}=l$,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 ${X.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=WG(E-T,5),A=qG(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 ${X.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(ZG(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(ZG(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<u$;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=u$-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 ${X.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=(0,Z.useRef)(v);y.current=v;let b=(0,Z.useRef)(null);b.current??=dJ(()=>y.current(),()=>l.current?.ownerDocument);let x=()=>b.current.schedule();return(0,Z.useEffect)(()=>{b.current.now()}),(0,Z.useEffect)(()=>()=>b.current?.cancel(),[]),(0,Z.useEffect)(()=>{u.current=null,x()},[a]),(0,Z.useLayoutEffect)(()=>{let e=l.current;if(!e)return;let t=new uJ(()=>{u.current=null,x()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{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)},[]),(0,Q.jsx)(`div`,{ref:l,style:{position:`relative`,width:`100%`,height:`100%`},children:(0,Q.jsx)(`canvas`,{ref:c,className:`chart-canvas`,role:`img`,"aria-label":`Violin plot`})})}var m$={top:48,right:16,bottom:72,left:80},h$=[8,24,64],g$=[56,189,248];function _$(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 v$(e){return`${(e*100).toFixed(1)}%`}function y$(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 b$({actual:e,predicted:t,normalize:n=!1,backgroundToken:r=``,onPlotContextMenu:i}){let a=(0,Z.useRef)(null),o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(null),u=(0,Z.useRef)(0),d=(0,Z.useRef)(i);(0,Z.useLayoutEffect)(()=>{d.current=i},[i]);let f=(0,Z.useRef)({actual:e,predicted:t,normalize:n});(0,Z.useLayoutEffect)(()=>{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=(0,Z.useMemo)(()=>y$(e,t,n),[e,t,n]),_=(0,Z.useRef)(g);(0,Z.useLayoutEffect)(()=>{_.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}=m$,{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 ${X.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]=_$(h$,g$,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 ${X.mono}`,r.textAlign=`center`,r.textBaseline=`middle`;let l=f.current.normalize;r.fillText(l?v$(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 ${X.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 ${X.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 ${X.mono}`,r.textAlign=`center`,r.textBaseline=`middle`,r.fillText(`Accuracy: ${v$(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}=m$,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?v$(C):C|0}`;r.font=`11px ${X.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=(0,Z.useRef)(y);x.current=y;let S=(0,Z.useRef)(null);S.current??=dJ(()=>x.current(),()=>s.current?.ownerDocument);let C=()=>S.current.schedule(),w=()=>{aJ(u.current),u.current=iJ(b)};return(0,Z.useEffect)(()=>{S.current.now()}),(0,Z.useEffect)(()=>()=>S.current?.cancel(),[]),(0,Z.useEffect)(()=>{c.current=null,C()},[r]),(0,Z.useLayoutEffect)(()=>{let e=s.current;if(!e)return;let t=new uJ(()=>{c.current=null,C(),w()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{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}=m$,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)}},[]),(0,Q.jsxs)(`div`,{ref:s,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:a,className:`chart-canvas`,role:`img`,"aria-label":`Confusion matrix`}),(0,Q.jsx)(`canvas`,{ref:o,className:`chart-canvas chart-overlay`})]})}var x$={top:24,right:24,bottom:48,left:64};function S$(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 C$(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 w$(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 T$(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 E$({scores:e,labels:t,mode:n=`roc`,color:r=`#f472b6`,backgroundToken:i=``,onPlotContextMenu:a}){let o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(a);(0,Z.useLayoutEffect)(()=>{l.current=a},[a]);let u=(0,Z.useRef)({scores:e,labels:t,mode:n,color:r});(0,Z.useLayoutEffect)(()=>{u.current={scores:e,labels:t,mode:n,color:r}},[e,t,n,r]);let d=(0,Z.useMemo)(()=>S$(e,t),[e,t]),f=(0,Z.useMemo)(()=>n===`pr`?{roc:null,pr:w$(d)}:{roc:C$(d),pr:null},[d,n]),p=(0,Z.useRef)(f);(0,Z.useLayoutEffect)(()=>{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}=x$,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 ${X.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=qG(0,1,WG(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(),T$(r,t,n,a),r.strokeStyle=x,r.lineWidth=1,r.stroke(),r.beginPath(),T$(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 ${X.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=tQ(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 ${X.mono}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`AP = ${e.ap.toFixed(3)}`,c+8,i+8)}}r.fillStyle=_,r.font=`11px ${X.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=(0,Z.useRef)(_);v.current=_;let y=(0,Z.useRef)(null);y.current??=dJ(()=>v.current(),()=>s.current?.ownerDocument);let b=()=>y.current.schedule();return(0,Z.useEffect)(()=>{y.current.now()}),(0,Z.useEffect)(()=>()=>y.current?.cancel(),[]),(0,Z.useEffect)(()=>{c.current=null,b()},[i]),(0,Z.useLayoutEffect)(()=>{let e=s.current;if(!e)return;let t=new uJ(()=>{c.current=null,b()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{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)},[]),(0,Q.jsx)(`div`,{ref:s,style:{position:`relative`,width:`100%`,height:`100%`},children:(0,Q.jsx)(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`ROC / PR curve`})})}var D$={top:20,right:64,bottom:48,left:64};function O$({xValues:e,series:t,xLabel:n=`Epoch`,backgroundToken:r=``,onPlotContextMenu:i}){let a=xJ(),o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(null),u=(0,Z.useRef)(null),d=(0,Z.useRef)(0),f=(0,Z.useRef)(i);(0,Z.useLayoutEffect)(()=>{f.current=i},[i]);let p=(0,Z.useRef)({xValues:e,series:t,xLabel:n});(0,Z.useLayoutEffect)(()=>{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 _=(0,Z.useMemo)(()=>{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:iQ(e)}},[e,t]),v=(0,Z.useRef)(_);(0,Z.useLayoutEffect)(()=>{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}=D$,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 ${X.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=WG(C.hi-C.lo,5),N=qG(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=WG(D-E,6),F=qG(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?tQ(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 ${X.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(ZG(e,M),l-6,A(e));if(T){let e=WG(w.hi-w.lo,5),t=qG(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(ZG(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(ZG(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 ${X.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}=D$,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 ${X.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}: ${QG(e.values[D])}`,T+6,O),O+=14);w(0)}let x=(0,Z.useRef)(y);x.current=y;let S=(0,Z.useRef)(null);S.current??=dJ(()=>x.current(),()=>c.current?.ownerDocument);let C=()=>S.current.schedule(),w=()=>{aJ(d.current),d.current=iJ(b)};return(0,Z.useEffect)(()=>{S.current.now()}),(0,Z.useEffect)(()=>()=>S.current?.cancel(),[]),(0,Z.useEffect)(()=>{l.current=null,C()},[r]),(0,Z.useLayoutEffect)(()=>{let e=c.current;if(!e)return;let t=new uJ(()=>{l.current=null,C(),w()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{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)}},[]),(0,Q.jsxs)(`div`,{ref:c,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`Loss curves`}),(0,Q.jsx)(`canvas`,{ref:s,className:`chart-canvas chart-overlay`})]})}var k$={top:40,right:24,bottom:40,left:72},A$=`#ef4444`,j$=`#f97316`,M$=`#22d3ee`;function N$(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 P$({points:e,sigmaLevel:t=3,color:n=`#22d3ee`,backgroundToken:r=``,onPlotContextMenu:i}){let a=xJ(),o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(null),u=(0,Z.useRef)(null),d=(0,Z.useRef)(0),f=(0,Z.useRef)(i);(0,Z.useLayoutEffect)(()=>{f.current=i},[i]);let p=(0,Z.useRef)({points:e,sigmaLevel:t,color:n});(0,Z.useLayoutEffect)(()=>{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 _=(0,Z.useMemo)(()=>N$(e,t),[e,t]),v=(0,Z.useRef)(_);(0,Z.useLayoutEffect)(()=>{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}=k$,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 ${X.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=WG(D-E,5),j=qG(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 ${X.mono}`,r.textAlign=`right`,r.textBaseline=`middle`,r.fillText(`${n} ${QG(e)}`,l+u-2,o-5))};M(w,j$,`UCL`,[5,3]),M(C,M$,`CL`,[]),M(T,j$,`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=nQ(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?A$: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 ${X.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(ZG(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}=k$,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}: `}${QG(D)}`;r.font=`11px ${X.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?A$:_,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(j,N,k-11)}let S=(0,Z.useRef)(b);S.current=b;let C=(0,Z.useRef)(null);C.current??=dJ(()=>S.current(),()=>c.current?.ownerDocument);let w=()=>C.current.schedule(),T=()=>{aJ(d.current),d.current=iJ(x)};return(0,Z.useEffect)(()=>{C.current.now()}),(0,Z.useEffect)(()=>()=>C.current?.cancel(),[]),(0,Z.useEffect)(()=>{l.current=null,w()},[r]),(0,Z.useLayoutEffect)(()=>{let e=c.current;if(!e)return;let t=new uJ(()=>{l.current=null,w(),T()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{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)}},[]),(0,Q.jsxs)(`div`,{ref:c,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`Control chart`}),(0,Q.jsx)(`canvas`,{ref:s,className:`chart-canvas chart-overlay`})]})}var F$={top:32,right:24,bottom:24,left:24},I$=[`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`,`#facc15`,`#60a5fa`],L$=16;function R$(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 z$(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:L$},(e,t)=>R$((t+.5)/L$));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(L$-1,Math.floor(e*L$))):-1}for(let t=0;t<e.length;t++)s[t]<0&&(s[t]=0)}else if(!n&&e.colorIndex){c=I$;for(let t=0;t<e.length;t++)s[t]=Math.max(0,e.colorIndex[t])%I$.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 B$({rows:e,axes:t,color:n=`#64748b`,colorByNumeric:r=!1,backgroundToken:i=``,onPlotContextMenu:a}){let o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(null),u=(0,Z.useRef)(null),d=(0,Z.useRef)(null),f=(0,Z.useRef)(null),p=(0,Z.useRef)(0),m=(0,Z.useRef)(a);(0,Z.useLayoutEffect)(()=>{m.current=a},[a]);let h=(0,Z.useMemo)(()=>z$(e,t.length,r,n),[e,t.length,r,n]),g=(0,Z.useRef)({rows:e,axes:t,colorByNumeric:r,model:h});(0,Z.useLayoutEffect)(()=>{g.current={rows:e,axes:t,colorByNumeric:r,model:h}},[e,t,r,h]);let _=XZ(s),v=(0,Z.useRef)(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}=F$,{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 ${X.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,lZ(e.color,j),1,e.starts)),v.current=w,sJ(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 ${X.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(ZG(r,(t.hi-t.lo)/4),k[e]+(e===O-1?5:-5),i)}a.font=`10px ${X.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 ${X.mono}`,a.textBaseline=`top`,M.forEach((n,r)=>{a.fillStyle=I$[r%I$.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}=F$,{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=(0,Z.useRef)(S);w.current=S;let T=(0,Z.useRef)(null);T.current??=dJ(()=>w.current(),()=>u.current?.ownerDocument);let E=()=>T.current.schedule(),D=()=>{aJ(p.current),p.current=iJ(C)};return(0,Z.useEffect)(()=>{T.current.now()}),(0,Z.useEffect)(()=>()=>T.current?.cancel(),[]),(0,Z.useEffect)(()=>{d.current=null,E()},[i]),(0,Z.useLayoutEffect)(()=>{let e=u.current;if(!e)return;let t=new uJ(()=>{d.current=null,E(),D()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{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-F$.left-F$.right,a=r.length,o=t.clientX-n.left-F$.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)}},[]),(0,Q.jsxs)(`div`,{ref:u,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`Parallel coordinates`}),(0,Q.jsx)(`canvas`,{ref:s,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),(0,Q.jsx)(`canvas`,{ref:c,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),(0,Q.jsx)(`canvas`,{ref:l,className:`chart-canvas chart-overlay`})]})}function V$(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 H$(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 U$={top:16,right:16,bottom:16,left:16},W$=[`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`,`#facc15`,`#60a5fa`];function G$(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 K$(e){let[t,n,r]=G$(e);return`rgb(${t},${n},${r})`}var q$=(()=>{let e=new Uint8Array(1024);for(let t=0;t<256;t++)e.set([...G$(t/255),255],t*4);return e})(),J$=(()=>{let e=new Uint8Array(1024);for(let t=0;t<256;t++){let[n,r,i]=lZ(W$[t%W$.length],1);e.set([n*255,r*255,i*255,255],t*4)}return e});function Y$(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 X$({points:e,color:t=`#64748b`,colorByNumeric:n=!1,pointSize:r=4,backgroundToken:i=``,onPlotContextMenu:a}){let o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(null),u=(0,Z.useRef)(null),d=(0,Z.useRef)(null),f=(0,Z.useRef)(0),p=(0,Z.useRef)(a);(0,Z.useLayoutEffect)(()=>{p.current=a},[a]);let m=(0,Z.useMemo)(()=>Y$(e,n),[e,n]),h=(0,Z.useRef)({points:e,color:t,colorByNumeric:n,pointSize:r,model:m});(0,Z.useLayoutEffect)(()=>{h.current={points:e,color:t,colorByNumeric:n,pointSize:r,model:m}},[e,t,n,r,m]);let g=(0,Z.useRef)({r:null,failed:!1,size:``,model:null,style:``});(0,Z.useEffect)(()=>()=>{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}=U$,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=Lq(s.current,oX),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,sJ(l.current));let f=`${c.mode}|${u}|${d}`;return n.style!==f&&(r.setStyle(c.mode===`single`?{kind:`single`,rgba:lZ(u,1)}:{kind:c.mode,palette:c.mode===`colormap`?q$:J$()},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 ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`No data`,U$.left+8,U$.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:U$.left,top:U$.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`?K$(i):d.mode===`dataset`?W$[i%W$.length]:c,r.globalAlpha=.8,r.fill()}r.globalAlpha=1}if(l){let e=Math.min(120,Math.floor((n-U$.top-U$.bottom)*.4)),i=t-U$.right-12,o=U$.top+8;for(let t=0;t<e;t++)r.fillStyle=K$(1-t/(e-1)),r.fillRect(i,o+t,8,1);r.fillStyle=a,r.font=`9px ${X.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=U$.left,i=n-U$.bottom-10;r.font=`9px ${X.mono}`,r.textBaseline=`top`,E.forEach((n,o)=>{e>t-U$.right-60&&(e=U$.left,i-=14),r.fillStyle=W$[o%W$.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 ${X.mono}`;let C=r.measureText(S).width,w=Math.max(4,Math.min(t-C-8,p+10)),T=m-20<U$.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=(0,Z.useRef)(S);w.current=S;let T=(0,Z.useRef)(null);T.current??=dJ(()=>w.current(),()=>l.current?.ownerDocument);let E=()=>T.current.schedule(),D=()=>{aJ(f.current),f.current=iJ(C)};return(0,Z.useEffect)(()=>{T.current.now()}),(0,Z.useEffect)(()=>()=>T.current?.cancel(),[]),(0,Z.useEffect)(()=>{u.current=null,E()},[i]),(0,Z.useLayoutEffect)(()=>{let e=l.current;if(!e)return;let t=new uJ(()=>{u.current=null,E(),D()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{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])-U$.left,g=e=>u(i.y[e])-U$.top,_=a+8,y=`${s}|${c}|${_}`;(!t||t.model!==o||t.key!==y)&&(t={model:o,key:y,g:V$(i.length,f,p,_,m,g)}),d.current=H$(t.g,n.clientX-r.left-U$.left,n.clientY-r.top-U$.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)}},[]),(0,Q.jsxs)(`div`,{ref:l,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`Embedding / scatter`}),(0,Q.jsx)(`canvas`,{ref:s,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),(0,Q.jsx)(`canvas`,{ref:c,className:`chart-canvas chart-overlay`})]})}var Z$={top:8,right:8,bottom:8,left:8},Q$=20,$$=[`#f97316`,`#fb923c`,`#fdba74`,`#fbbf24`,`#fcd34d`,`#4ade80`,`#34d399`,`#38bdf8`,`#818cf8`,`#a78bfa`];function e1(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 t1(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 n1(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 r1(e){return $$[e%$$.length]}function i1({nodes:e,direction:t=`bottomup`,backgroundToken:n=``,onPlotContextMenu:r}){let i=(0,Z.useRef)(null),a=(0,Z.useRef)(null),o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(0),u=(0,Z.useRef)(r);(0,Z.useLayoutEffect)(()=>{u.current=r},[r]);let d=(0,Z.useRef)({nodes:e,direction:t});(0,Z.useLayoutEffect)(()=>{d.current={nodes:e,direction:t}},[e,t]);let f=(0,Z.useMemo)(()=>{let t=e1(e);return{roots:t,flat:t1(t),numRows:n1(t)+1}},[e]),p=(0,Z.useRef)(f);(0,Z.useLayoutEffect)(()=>{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=Z$.left+e.x0*t,o=(e.x1-e.x0)*t;return{x:a,y:i===`topdown`?Z$.top+e.depth*Q$:Z$.top+n-(e.depth+1)*Q$,w:o,h:Q$-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 ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`No data`,Z$.left+8,Z$.top+8);return}let{flat:l,numRows:u}=p.current,f=t-Z$.left-Z$.right,v=u*Q$;for(let e of l){let t=_(e,f,v,u,c);if(!(t.w<1)&&(r.fillStyle=r1(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,Q$-4)}px ${X.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+Q$/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-Z$.left-Z$.right,l*Q$,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 ${X.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+Q$+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=(0,Z.useRef)(v);b.current=v;let x=(0,Z.useRef)(null);x.current??=dJ(()=>b.current(),()=>o.current?.ownerDocument);let S=()=>x.current.schedule(),C=()=>{aJ(l.current),l.current=iJ(y)};return(0,Z.useEffect)(()=>{x.current.now()}),(0,Z.useEffect)(()=>()=>x.current?.cancel(),[]),(0,Z.useEffect)(()=>{s.current=null,S()},[n]),(0,Z.useLayoutEffect)(()=>{let e=o.current;if(!e)return;let t=new uJ(()=>{s.current=null,S(),C()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{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-Z$.left-Z$.right,f=o*Q$,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)}},[]),(0,Q.jsxs)(`div`,{ref:o,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:i,className:`chart-canvas`,role:`img`,"aria-label":`Flame graph`}),(0,Q.jsx)(`canvas`,{ref:a,className:`chart-canvas chart-overlay`})]})}var a1={top:24,right:24,bottom:52,left:56},o1=[`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`,`#facc15`,`#60a5fa`],s1=.8;function c1(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 l1(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 u1({groups:e,columns:t,seriesNames:n,colors:r,mode:i=`grouped`,horizontal:a=!1,valueRange:o,backgroundToken:s=``,onPlotContextMenu:c}){let l=xJ(),u=(0,Z.useRef)(null),d=(0,Z.useRef)(null),f=(0,Z.useRef)(null),p=(0,Z.useRef)(null),m=(0,Z.useRef)(null),h=(0,Z.useRef)(null),g=(0,Z.useRef)(0),_=(0,Z.useRef)(c);(0,Z.useLayoutEffect)(()=>{_.current=c},[c]);let v=(0,Z.useRef)(null),y=(0,Z.useMemo)(()=>{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=c1(e,t,n.length,i);return v.current={key:r,value:o},o},[e,t,n.length,i]),b=(0,Z.useRef)({bars:y,seriesNames:n,colors:r,mode:i,horizontal:a,valueRange:o});(0,Z.useLayoutEffect)(()=>{b.current={bars:y,seriesNames:n,colors:r,mode:i,horizontal:a,valueRange:o}},[y,n,r,i,a,o]);let x=(0,Z.useRef)({plot:null,failed:!1,key:``,data:null,size:``});(0,Z.useEffect)(()=>()=>{x.current.plot?.dispose(),x.current.plot=null},[]);let S=(0,Z.useRef)({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]??o1[n%o1.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=cX(a1,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=Lq(d.current,YZ),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 ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`No data`,a1.left+8,a1.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 ${X.mono}`,!A&&(f?(r.textAlign=`center`,r.textBaseline=`top`,r.fillText(ZG(t,(g-h)/5),n,_+k+4)):(r.textAlign=`right`,r.textBaseline=`middle`,r.fillText(ZG(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},sJ(p.current));let I=Math.min(2,window.devicePixelRatio||1),L=Math.max(1,Math.round(M*I)),R=j.map(e=>{let t=pq(e);return[t[0],t[1],t[2],s1]}),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=l1(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=l1(s,d,L);r.globalAlpha=s1;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 ${X.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 ${X.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]+` `:``}${QG(e[i])}`).join(` `),v=`${a.label(i)}: ${_}`;r.font=`11px ${X.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=(0,Z.useRef)(k);j.current=k;let M=(0,Z.useRef)(null);M.current??=dJ(()=>j.current(),()=>p.current?.ownerDocument);let N=()=>{g.current||=iJ(()=>{g.current=0,A()})};return(0,Z.useEffect)(()=>{M.current.now()},[y,n,r,i,a,o]),(0,Z.useEffect)(()=>()=>{M.current?.cancel(),aJ(g.current)},[]),(0,Z.useEffect)(()=>{m.current=null,M.current.schedule()},[s]),(0,Z.useLayoutEffect)(()=>{let e=p.current;if(!e)return;let t=new uJ(()=>{m.current=null,M.current.schedule(),N()});return t.observe(e),()=>t.disconnect()},[]),(0,Z.useLayoutEffect)(()=>{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)}},[]),(0,Q.jsxs)(`div`,{ref:p,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:u,className:`chart-canvas`,role:`img`,"aria-label":`Bar chart`}),(0,Q.jsx)(`canvas`,{ref:d,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),(0,Q.jsx)(`canvas`,{ref:f,className:`chart-canvas chart-overlay`})]})}var d1=[`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`];function f1(e,t){if(!t)return d1[e%d1.length];if(e===0)return t;let n=d1.filter(e=>e.toLowerCase()!==t.toLowerCase());return n[(e-1)%n.length]}var p1={top:36,right:36,bottom:36,left:36};function m1({axes:e,series:t,fill:n=!0,color:r,backgroundToken:i=``,onPlotContextMenu:a}){let o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(null),u=(0,Z.useRef)(a);(0,Z.useLayoutEffect)(()=>{u.current=a},[a]);let d=(0,Z.useRef)({axes:e,series:t,fill:n,color:r});(0,Z.useLayoutEffect)(()=>{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 ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`Select ≥ 3 axes`,p1.left+8,p1.top+8);return}let h=c.length,g=t/2,_=n/2,v=Math.min(t-p1.left-p1.right,n-p1.top-p1.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 ${X.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=f1(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=p1.left,i=n-p1.bottom-10;r.font=`9px ${X.mono}`,r.textBaseline=`top`;for(let n=0;n<l.length&&(r.fillStyle=f1(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-p1.right-30));n++);}}let g=(0,Z.useRef)(h);g.current=h;let _=(0,Z.useRef)(null);_.current??=dJ(()=>g.current(),()=>c.current?.ownerDocument);let v=()=>_.current.schedule();return(0,Z.useEffect)(()=>{_.current.now()}),(0,Z.useEffect)(()=>()=>_.current?.cancel(),[]),(0,Z.useEffect)(()=>{l.current=null,v()},[i]),(0,Z.useLayoutEffect)(()=>{let e=c.current;if(!e)return;let t=new uJ(()=>{l.current=null,v()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{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)}},[]),(0,Q.jsxs)(`div`,{ref:c,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`Radar chart`}),(0,Q.jsx)(`canvas`,{ref:s,className:`chart-canvas chart-overlay`})]})}var h1={top:16,right:16,bottom:40,left:52},g1=[`#38bdf8`,`#4ade80`,`#fb7185`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`];function _1(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=>iQ(e)),xLo:c,xHi:l,yLo:u,yHi:d}}function v1({series:e,stacked:t=!1,yRange:n,backgroundToken:r=``,onPlotContextMenu:i}){let a=xJ(),o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(null),u=(0,Z.useRef)(null),d=(0,Z.useRef)(null),f=(0,Z.useRef)(0),p=(0,Z.useRef)(i);(0,Z.useLayoutEffect)(()=>{p.current=i},[i]);let m=(0,Z.useRef)(null),h=(0,Z.useMemo)(()=>{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=_1(e,t);return m.current={series:e,stacked:t,value:r},r},[e,t]),g=(0,Z.useRef)({series:e,prepared:h,yRange:n});(0,Z.useLayoutEffect)(()=>{g.current={series:e,prepared:h,yRange:n}},[e,h,n]);let _=(0,Z.useRef)({plot:null,failed:!1,key:``,size:``});(0,Z.useEffect)(()=>()=>{_.current.plot?.dispose(),_.current.plot=null},[]);let v=(0,Z.useRef)({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=tQ(a,o,n,r,i);return{x:rQ(a,c),hi:rQ(o,c),lo:s?rQ(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 ${X.sans}`,i.textAlign=`left`,i.textBaseline=`top`,i.fillText(`No data`,h1.left+8,h1.top+8);return}let h=cX(h1,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 ${X.mono}`,i.textAlign=`right`,i.textBaseline=`middle`,h.tiny||i.fillText(ZG(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 ${X.mono}`,i.textAlign=`center`,i.textBaseline=`top`,h.tiny||i.fillText(ZG(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},sJ(l.current));let B=E(n,r),V=Math.min(2,window.devicePixelRatio||1),H=Math.max(1,Math.round(A*V)),U=d.map((e,t)=>pq(g1[t%g1.length]));if(B){let e=`${M}|${N}|${H}`;if(_.current.key!==e||T.current!==f){let n=[];for(let e=0;e<d.length;e++){let r=C(f,e,M,N,H),i=U[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,H),r=g1[e%g1.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 ${X.mono}`,i.textBaseline=`top`;for(let n=0;n<d.length&&(i.fillStyle=g1[n%g1.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=(0,Z.useRef)(null);function E(e,t){let n=_.current;if(!n.plot&&!n.failed&&s.current&&(n.plot=Lq(s.current,YZ),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}=cX(h1,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=${QG(m+(i-u)/_*(h-m))}`;r.font=`11px ${X.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=(0,Z.useRef)(w);O.current=w;let k=(0,Z.useRef)(null);k.current??=dJ(()=>O.current(),()=>l.current?.ownerDocument);let A=()=>{f.current||=iJ(()=>{f.current=0,D()})};return(0,Z.useEffect)(()=>{k.current.now()},[e,h,n]),(0,Z.useEffect)(()=>()=>{k.current?.cancel(),aJ(f.current)},[]),(0,Z.useEffect)(()=>{u.current=null,k.current.schedule()},[r]),(0,Z.useLayoutEffect)(()=>{let e=l.current;if(!e)return;let t=new uJ(()=>{u.current=null,k.current.schedule(),A()});return t.observe(e),()=>t.disconnect()},[]),(0,Z.useLayoutEffect)(()=>{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)}},[]),(0,Q.jsxs)(`div`,{ref:l,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`Area chart`}),(0,Q.jsx)(`canvas`,{ref:s,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),(0,Q.jsx)(`canvas`,{ref:c,className:`chart-canvas chart-overlay`})]})}var y1={top:16,right:16,bottom:40,left:52},b1=[`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`];function x1({series:e,complement:t=!1,logX:n=!1,backgroundToken:r=``,onPlotContextMenu:i}){let a=xJ(),o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(null),u=(0,Z.useRef)(null),d=(0,Z.useRef)(0),f=(0,Z.useRef)(i);(0,Z.useLayoutEffect)(()=>{f.current=i},[i]);let p=(0,Z.useRef)({series:e,complement:t,logX:n});(0,Z.useLayoutEffect)(()=>{p.current={series:e,complement:t,logX:n}},[e,t,n]);let m=(0,Z.useMemo)(()=>{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=(0,Z.useRef)(m);(0,Z.useLayoutEffect)(()=>{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 ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`No data`,y1.left+8,y1.top+8);return}let{top:f,right:m,bottom:y,left:b}=y1,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 ${X.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 ${X.mono}`,r.textAlign=`center`,r.textBaseline=`top`,r.fillText(ZG(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=b1[e%b1.length],r.lineWidth=1,r.stroke()}if(l.length>1){let e=b,t=f+S+24;r.font=`9px ${X.mono}`,r.textBaseline=`top`;for(let n=0;n<l.length&&(r.fillStyle=b1[n%b1.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 ${X.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}=y1,l=n-a-y1.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=QG(f+(i-o)/d*(p-f));r.font=`11px ${X.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=(0,Z.useRef)(y);x.current=y;let S=(0,Z.useRef)(null);S.current??=dJ(()=>x.current(),()=>c.current?.ownerDocument);let C=()=>S.current.schedule(),w=()=>{aJ(d.current),d.current=iJ(b)};return(0,Z.useEffect)(()=>{S.current.now()}),(0,Z.useEffect)(()=>()=>S.current?.cancel(),[]),(0,Z.useEffect)(()=>{l.current=null,C()},[r]),(0,Z.useLayoutEffect)(()=>{let e=c.current;if(!e)return;let t=new uJ(()=>{l.current=null,C(),w()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{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)}},[]),(0,Q.jsxs)(`div`,{ref:c,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`CDF chart`}),(0,Q.jsx)(`canvas`,{ref:s,className:`chart-canvas chart-overlay`})]})}var S1={top:16,right:40,bottom:40,left:52},C1=[`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`,`#facc15`,`#60a5fa`];function w1(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 T1(e){let[t,n,r]=w1(e);return`rgb(${t},${n},${r})`}var E1=(()=>{let e=new Uint8Array(1024);for(let t=0;t<256;t++)e.set([...w1(t/255),255],t*4);return e})(),D1=()=>{let e=new Uint8Array(1024);for(let t=0;t<256;t++){let[n,r,i]=lZ(C1[t%C1.length],1);e.set([n*255,r*255,i*255,255],t*4)}return e};function O1(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 k1({points:e,color:t=`#64748b`,colorByNumeric:n=!1,maxRadius:r=24,backgroundToken:i=``,onPlotContextMenu:a}){let o=xJ(),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(null),u=(0,Z.useRef)(null),d=(0,Z.useRef)(null),f=(0,Z.useRef)(null),p=(0,Z.useRef)(0),m=(0,Z.useRef)(a);(0,Z.useLayoutEffect)(()=>{m.current=a},[a]);let h=(0,Z.useMemo)(()=>O1(e,n,r),[e,n,r]),g=(0,Z.useRef)({points:e,color:t,colorByNumeric:n,maxRadius:r,model:h});(0,Z.useLayoutEffect)(()=>{g.current={points:e,color:t,colorByNumeric:n,maxRadius:r,model:h}},[e,t,n,r,h]);let _=(0,Z.useRef)({r:null,failed:!1,size:``,model:null,style:``});(0,Z.useEffect)(()=>()=>{_.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}=S1,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=Lq(c.current,oX),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,sJ(u.current));let l=`${o.mode}|${s}`;return n.style!==l&&(r.setStyle(o.mode===`single`?{kind:`single`,rgba:lZ(s,1)}:{kind:o.mode,palette:o.mode===`colormap`?E1:D1()},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 ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`No data`,S1.left+8,S1.top+8);return}let{xLo:p,xHi:m,yLo:h,yHi:C}=d.ext,{top:w,left:T}=S1,{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 ${X.mono}`,r.textAlign=`center`,r.textBaseline=`top`,r.fillText(ZG(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(ZG(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`?T1(n):d.mode===`dataset`?C1[n%C1.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-S1.bottom-10;r.font=`9px ${X.mono}`,r.textBaseline=`top`;for(let n=0;n<A.length;n++){let i=A[n];if(r.fillStyle=C1[n%C1.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(`(${QG(a.x[i])}, ${QG(a.y[i])})`),m.push(`size=${QG(a.size[i])}`);let _=a.colorIndex?.[i];_!==void 0&&_>=0&&a.colorLabels?m.push(a.colorLabels[_]):a.colorValue&&m.push(QG(a.colorValue[i]));let v=m.join(` · `);r.font=`11px ${X.mono}`;let S=r.measureText(v).width,C=Math.max(4,Math.min(t-S-8,d+u+4)),w=p-20<S1.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=(0,Z.useRef)(C);T.current=C;let E=(0,Z.useRef)(null);E.current??=dJ(()=>T.current(),()=>u.current?.ownerDocument);let D=()=>E.current.schedule(),O=()=>{aJ(p.current),p.current=iJ(w)};return(0,Z.useEffect)(()=>{E.current.now()}),(0,Z.useEffect)(()=>()=>E.current?.cancel(),[]),(0,Z.useEffect)(()=>{d.current=null,D()},[i]),(0,Z.useLayoutEffect)(()=>{let e=u.current;if(!e)return;let t=new uJ(()=>{d.current=null,D(),O()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{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])-S1.left,h=e=>p(i.y[e])-S1.top,_=a+6,v=`${s}|${c}|${_}`;(!t||t.model!==o||t.key!==v)&&(t={model:o,key:v,g:V$(i.length,l,u,_,m,h)}),f.current=H$(t.g,n.clientX-r.left-S1.left,n.clientY-r.top-S1.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)}},[]),(0,Q.jsxs)(`div`,{ref:u,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:s,className:`chart-canvas`,role:`img`,"aria-label":`Bubble chart`}),(0,Q.jsx)(`canvas`,{ref:c,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),(0,Q.jsx)(`canvas`,{ref:l,className:`chart-canvas chart-overlay`})]})}var A1={top:8,right:8,bottom:8,left:8},j1=[`#f97316`,`#38bdf8`,`#4ade80`,`#a78bfa`,`#fbbf24`,`#fb7185`,`#34d399`,`#e879f9`,`#facc15`,`#60a5fa`];function M1(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 N1(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=N1(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 P1({nodes:e,backgroundToken:t=``,onPlotContextMenu:n}){let r=(0,Z.useRef)(null),i=(0,Z.useRef)(null),a=(0,Z.useRef)(null),o=(0,Z.useRef)(null),s=(0,Z.useRef)([]),c=(0,Z.useRef)(null),l=(0,Z.useRef)(0),u=(0,Z.useRef)(n);(0,Z.useLayoutEffect)(()=>{u.current=n},[n]);let d=(0,Z.useRef)({nodes:e});(0,Z.useLayoutEffect)(()=>{d.current={nodes:e}},[e]);let f=(0,Z.useMemo)(()=>M1(e),[e]),p=(0,Z.useRef)(f);(0,Z.useLayoutEffect)(()=>{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 ${X.sans}`,i.textAlign=`left`,i.textBaseline=`top`,i.fillText(`No data`,A1.left+8,A1.top+8);return}let u=p.current,f=t-A1.left-A1.right,_=n-A1.top-A1.bottom,v=N1(u,A1.left,A1.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=j1[l%j1.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 ${X.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 ${X.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=(0,Z.useRef)(_);y.current=_;let b=(0,Z.useRef)(null);b.current??=dJ(()=>y.current(),()=>a.current?.ownerDocument);let x=()=>b.current.schedule(),S=()=>{aJ(l.current),l.current=iJ(v)};return(0,Z.useEffect)(()=>{b.current.now()}),(0,Z.useEffect)(()=>()=>b.current?.cancel(),[]),(0,Z.useEffect)(()=>{o.current=null,x()},[t]),(0,Z.useLayoutEffect)(()=>{let e=a.current;if(!e)return;let t=new uJ(()=>{o.current=null,x(),S()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{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)}},[]),(0,Q.jsxs)(`div`,{ref:a,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:r,className:`chart-canvas`,role:`img`,"aria-label":`Treemap`}),(0,Q.jsx)(`canvas`,{ref:i,className:`chart-canvas chart-overlay`})]})}var F1={top:8,right:8,bottom:8,left:8},I1=14,L1=8,R1=[`#38bdf8`,`#4ade80`,`#fb7185`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`,`#facc15`,`#60a5fa`];function z1(e,t,n,r){if(e.length===0||t.length===0)return{nodes:[],links:[]};let i=n-F1.left-F1.right,a=r-F1.top-F1.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=>F1.left+e/Math.max(1,c)*(i-I1),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)*L1,i=0;for(let e of n)i+=Math.max(8,(d.get(e)??0)/f*r*.8);let o=F1.top+(a-i-(n.length-1)*L1)/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:R1[e.indexOf(a)%R1.length]}),o+=s+L1}}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+I1,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 B1({nodeNames:e,links:t,backgroundToken:n=``,onPlotContextMenu:r}){let i=(0,Z.useRef)(null),a=(0,Z.useRef)(null),o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),c=(0,Z.useRef)({nodes:[],links:[]}),l=(0,Z.useRef)(null),u=(0,Z.useRef)(0),d=(0,Z.useRef)(r);(0,Z.useLayoutEffect)(()=>{d.current=r},[r]);let f=(0,Z.useRef)({nodeNames:e,links:t});(0,Z.useLayoutEffect)(()=>{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 ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`No data — set source/target/value columns`,F1.left+8,F1.top+8);return}let d=z1(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,I1,e.h),r.globalAlpha=1,r.fillStyle=o,r.font=`9px ${X.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+I1+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 ${X.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=(0,Z.useRef)(g);v.current=g;let y=(0,Z.useRef)(null);y.current??=dJ(()=>v.current(),()=>o.current?.ownerDocument);let b=()=>y.current.schedule(),x=()=>{aJ(u.current),u.current=iJ(_)};return(0,Z.useEffect)(()=>{y.current.now()}),(0,Z.useEffect)(()=>()=>y.current?.cancel(),[]),(0,Z.useEffect)(()=>{s.current=null,b()},[n]),(0,Z.useLayoutEffect)(()=>{let e=o.current;if(!e)return;let t=new uJ(()=>{s.current=null,b(),x()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{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)}},[]),(0,Q.jsxs)(`div`,{ref:o,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:i,className:`chart-canvas`,role:`img`,"aria-label":`Sankey diagram`}),(0,Q.jsx)(`canvas`,{ref:a,className:`chart-canvas chart-overlay`})]})}var V1={top:24,right:24,bottom:52,left:52};function H1({bins:e,color:t=`#38bdf8`,backgroundToken:n=``,onPlotContextMenu:r}){let i=(0,Z.useRef)(null),a=(0,Z.useRef)(null),o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(0),u=(0,Z.useRef)(r);(0,Z.useLayoutEffect)(()=>{u.current=r},[r]);let d=(0,Z.useRef)({bins:e,color:t});(0,Z.useLayoutEffect)(()=>{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 ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`No data`,V1.left+8,V1.top+8);return}let{top:h,right:g,bottom:_,left:v}=V1,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 ${X.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 ${X.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}=V1,f=t-u-V1.right,h=n-l-V1.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 ${X.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 _=(0,Z.useRef)(h);_.current=h;let v=(0,Z.useRef)(null);v.current??=dJ(()=>_.current(),()=>o.current?.ownerDocument);let y=()=>v.current.schedule(),b=()=>{aJ(l.current),l.current=iJ(g)};return(0,Z.useEffect)(()=>{v.current.now()}),(0,Z.useEffect)(()=>()=>v.current?.cancel(),[]),(0,Z.useEffect)(()=>{s.current=null,y()},[n]),(0,Z.useLayoutEffect)(()=>{let e=o.current;if(!e)return;let t=new uJ(()=>{s.current=null,y(),b()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{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-V1.left-V1.right,s=-1,l=20;for(let e=0;e<r.length;e++){let t=V1.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)}},[]),(0,Q.jsxs)(`div`,{ref:o,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:i,className:`chart-canvas`,role:`img`,"aria-label":`Calibration curve`}),(0,Q.jsx)(`canvas`,{ref:a,className:`chart-canvas chart-overlay`})]})}var U1={top:24,right:24,bottom:48,left:52};function W1({points:e,color:t=`#a78bfa`,backgroundToken:n=``,onPlotContextMenu:r}){let i=xJ(),a=(0,Z.useRef)(null),o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(null),u=(0,Z.useRef)(0),d=(0,Z.useRef)(r);(0,Z.useLayoutEffect)(()=>{d.current=r},[r]);let f=(0,Z.useRef)({points:e,color:t});(0,Z.useLayoutEffect)(()=>{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 ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`No data`,U1.left+8,U1.top+8);return}let{xLo:_,xHi:v,yLo:y,yHi:b}=g(),{top:x,right:S,bottom:C,left:w}=U1,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 ${X.mono}`,r.textAlign=`center`,r.textBaseline=`top`,r.fillText(ZG(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(ZG(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 ${X.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}=U1,y=t-v-U1.right,b=n-_-U1.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=`(${QG(s.theoretical)}, ${QG(s.sample)})`;r.font=`11px ${X.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=(0,Z.useRef)(_);y.current=_;let b=(0,Z.useRef)(null);b.current??=dJ(()=>y.current(),()=>s.current?.ownerDocument);let x=()=>b.current.schedule(),S=()=>{aJ(u.current),u.current=iJ(v)};return(0,Z.useEffect)(()=>{b.current.now()}),(0,Z.useEffect)(()=>()=>b.current?.cancel(),[]),(0,Z.useEffect)(()=>{c.current=null,x()},[n]),(0,Z.useLayoutEffect)(()=>{let e=s.current;if(!e)return;let t=new uJ(()=>{c.current=null,x(),S()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{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}=U1,p=i-d-U1.right,h=n.height-u-U1.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)}},[]),(0,Q.jsxs)(`div`,{ref:s,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:a,className:`chart-canvas`,role:`img`,"aria-label":`Q-Q plot`}),(0,Q.jsx)(`canvas`,{ref:o,className:`chart-canvas chart-overlay`})]})}var G1={top:8,right:16,bottom:40,left:120},K1=22,q1=3,J1=[`#38bdf8`,`#4ade80`,`#fb7185`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`,`#facc15`,`#60a5fa`];function Y1({tasks:e,backgroundToken:t=``,onPlotContextMenu:n}){let r=xJ(),i=(0,Z.useRef)(null),a=(0,Z.useRef)(null),o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(0),u=(0,Z.useRef)(n);(0,Z.useLayoutEffect)(()=>{u.current=n},[n]);let d=(0,Z.useRef)({tasks:e});(0,Z.useLayoutEffect)(()=>{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 ${X.sans}`,a.textAlign=`left`,a.textBaseline=`top`,a.fillText(`No data`,G1.left+8,G1.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}=G1,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*(K1+q1)+v;a.beginPath(),a.moveTo(n,v),a.lineTo(n,r),a.stroke(),a.fillStyle=s,a.font=`9px ${X.mono}`,a.textAlign=`center`,a.textBaseline=`top`,a.fillText(ZG(t,(g-h)/T),n,r+4)}for(let e=0;e<u.length;e++){let t=u[e],n=v+e*(K1+q1),r=J1[(w.get(t.group??t.label)??0)%J1.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,K1-q1),a.globalAlpha=1,a.fillStyle=s,a.font=`9px ${X.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+(K1-q1)/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}: ${QG(s.start)} → ${QG(s.end)} (${QG(l)})`;r.font=`11px ${X.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-G1.left-G1.right,y=e=>G1.left+(e-h)/(g-h)*v,b=G1.top+i*(K1+q1),x=(y(s.start)+y(s.end))/2,S=Math.max(4,Math.min(t-f-8,x-f/2)),C=b-22<G1.top?b+K1+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 _=(0,Z.useRef)(h);_.current=h;let v=(0,Z.useRef)(null);v.current??=dJ(()=>_.current(),()=>o.current?.ownerDocument);let y=()=>v.current.schedule(),b=()=>{aJ(l.current),l.current=iJ(g)};return(0,Z.useEffect)(()=>{v.current.now()}),(0,Z.useEffect)(()=>()=>v.current?.cancel(),[]),(0,Z.useEffect)(()=>{s.current=null,y()},[t]),(0,Z.useLayoutEffect)(()=>{let e=o.current;if(!e)return;let t=new uJ(()=>{s.current=null,y(),b()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{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-G1.top)/(K1+q1));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)}},[]),(0,Q.jsxs)(`div`,{ref:o,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:i,className:`chart-canvas`,role:`img`,"aria-label":`Gantt chart`}),(0,Q.jsx)(`canvas`,{ref:a,className:`chart-canvas chart-overlay`})]})}var X1=e=>[...e].filter(e=>Number.isFinite(e.at)).sort((e,t)=>e.at-t.at),Z1=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]},Q1=e=>`#${e.map(e=>Math.round(e).toString(16).padStart(2,`0`)).join(``)}`;function $1(e,t,n,r){let i=t?X1(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=Z1(o.color),u=Z1(s.color);return Q1([l[0]+(u[0]-l[0])*c,l[1]+(u[1]-l[1])*c,l[2]+(u[2]-l[2])*c])}function e0(e,t,n,r,i,a=96){let o=i-r||1,s=t?X1(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:$1(`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:$1(`gradient`,s,n,r+(t+.5)/a*o)}))}var t0=.75*Math.PI,n0=1.5*Math.PI;function r0({gauges:e,live:t,backgroundToken:n=``,onPlotContextMenu:r}){let i=(0,Z.useRef)(null),a=(0,Z.useRef)(null),o=(0,Z.useRef)(null),s=(0,Z.useRef)(r);(0,Z.useLayoutEffect)(()=>{s.current=r},[r]);let c=(0,Z.useRef)({gauges:e,live:t});(0,Z.useLayoutEffect)(()=>{c.current={gauges:e,live:t}},[e,t]);let l=(0,Z.useRef)(Xq()),u=(0,Z.useRef)(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=Zq(l.current,_.latestT(),Math.min(64,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 ${X.sans}`,p.textAlign=`left`,p.textBaseline=`top`,p.fillText(`No data`,16,16);return}let{cols:y,rows:b}=i0(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`?m0(p,e,n,r,x,S,e.color,e.alarm??null,h):h0(p,e,n,r,x,S,e.color,e.alarm??null,h)})}let p=(0,Z.useRef)(f);p.current=f;let m=(0,Z.useRef)(null);return m.current??=dJ(()=>p.current(),()=>a.current?.ownerDocument),(0,Z.useEffect)(()=>{m.current.now()}),(0,Z.useEffect)(()=>()=>m.current?.cancel(),[]),(0,Z.useEffect)(()=>{o.current=null,m.current.schedule()},[n]),(0,Z.useLayoutEffect)(()=>{let e=a.current;if(!e)return;let t=new uJ(()=>{o.current=null,m.current.schedule()});return t.observe(e),()=>t.disconnect()},[]),(0,Q.jsx)(`div`,{ref:a,style:{position:`relative`,width:`100%`,height:`100%`},children:(0,Q.jsx)(`canvas`,{ref:i,className:`chart-canvas`,role:`img`,"aria-label":`Gauges: ${e.map(e=>`${e.name} ${Number.isFinite(e.value)?a0(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 i0(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 a0=(e,t)=>ZG(e,WG(Math.abs(t),100)),o0=(e,t)=>Math.max(0,Math.min(1,(t-e.min)/(e.max-e.min||1))),s0=(e,t)=>{let n=e.fromZero?o0(e,0):0;return[Math.min(n,t),Math.max(n,t)]},c0=(e,t)=>!!t&&Number.isFinite(e.value)&&e.value>=t.value,l0=e=>(e.colorMode===`gradient`||e.colorMode===`zones`)&&!!e.stops?.length,u0=(e,t)=>c0(e,t)?t.color:$1(e.colorMode,e.stops,e.color,e.value);function d0(e,t,n){for(let r of e0(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 f0(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 p0=Math.SQRT1_2;function m0(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=a0(t.min,u),f=a0(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 ${X.mono}`,g=Math.max(e.measureText(d).width,e.measureText(f).width);let t=m(h),n=Math.max(h+t/2,p0*h+g/2),r=h+t/2+p0*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+p0*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=>t0+e*n0;e.lineCap=`round`,e.lineWidth=_,e.strokeStyle=c.grid,e.beginPath(),e.arc(b,x,h,t0,t0+n0),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(o0(t,s.value)),t0+n0),e.stroke(),e.globalAlpha=1,e.lineCap=`round`);let[C,w]=s0(t,Number.isFinite(t.value)?o0(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(l0(t)){let n=n0/(2*Math.PI),r=d0(e.createConicGradient(t0,b,x),t,e=>e*n);r.addColorStop(1,$1(t.colorMode,t.stops,t.color,t.min)),e.strokeStyle=r,e.globalAlpha=.24,e.beginPath(),e.arc(b,x,h,t0,t0+n0),e.stroke(),e.globalAlpha=1,Number.isFinite(t.value)&&!c0(t,s)&&T()}if(Number.isFinite(t.value)&&(!l0(t)||c0(t,s))&&(e.strokeStyle=c0(t,s)?s.color:o,T()),t.fromZero&&t.min<0&&t.max>0){let n=S(o0(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(o0(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 E=Number.isFinite(t.value)?a0(t.value,u):`—`,D=2*(h-_)*.82,O=Math.max(11,h*.42);e.font=`650 ${O}px ${X.sans}`;let k=e.measureText(E).width;k>D&&(O=Math.max(9,O*D/k),e.font=`650 ${O}px ${X.sans}`),e.textAlign=`center`,e.textBaseline=`alphabetic`,e.fillStyle=c0(t,s)||l0(t)?u0(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 ${X.sans}`,e.fillText(f0(e,t.unit,D),b,x+O*.32+Math.max(11,h*.19)));let A=x+p0*h+_/2+6,j=p0*h;e.textBaseline=`top`,e.font=`${v}px ${X.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 ${X.sans}`;let P=e.measureText(t.name).width;P>M&&N>9&&(N=Math.max(9,N*M/P),e.font=`600 ${N}px ${X.sans}`),e.fillText(f0(e,t.name,M),b,A+(v-N)/2)}function h0(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+o0(t,e)*f;e.textBaseline=`alphabetic`,e.fillStyle=c.muted,e.font=`600 ${Math.max(10,m*.42)}px ${X.sans}`,e.textAlign=`left`,e.fillText(f0(e,t.name,f),u,h-p/2-m-4),e.textAlign=`right`,e.fillStyle=c0(t,s)?s.color:c.ink,e.font=`650 ${m}px ${X.sans}`;let _=t.unit?(e.font=`600 ${Math.max(9,m*.4)}px ${X.sans}`,e.measureText(` ${t.unit}`).width):0;t.unit&&(e.fillStyle=c.muted,e.fillText(` ${t.unit}`,d,h-p/2-8)),e.fillStyle=c0(t,s)||l0(t)?u0(t,s):c.ink,e.font=`650 ${m}px ${X.sans}`,e.fillText(Number.isFinite(t.value)?a0(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)?o0(t,t.value):0,y=e=>u+e*f,[b,x]=s0(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`};l0(t)&&(e.strokeStyle=d0(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)&&!c0(t,s)&&S()),Number.isFinite(t.value)&&(!l0(t)||c0(t,s))&&(e.strokeStyle=c0(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()),e.fillStyle=c.muted,e.font=`${Math.max(9,m*.34)}px ${X.mono}`,e.textBaseline=`top`,e.textAlign=`left`,e.fillText(a0(t.min,t.max-t.min),u,h+p/2+4),e.textAlign=`right`,e.fillText(a0(t.max,t.max-t.min),d,h+p/2+4)}function g0(e,t){let n=e.filter(e=>e.x.length>=2&&_0(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 _0(e){for(let t=1;t<e.length;t++)if(!(e[t]>=e[t-1]))return!1;return!0}function v0(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)}}Aw();function y0(e,t){return e.filter(e=>Cw(t,e))}qw();var b0=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?Ww(new Float64Array,new Float64Array,e.viewport.x0,e.viewport.x1,e.maxPoints):Ww(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}:Vw(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:Gw(r,i.map(e=>this.#e.get(e)),i,t.x0,t.x1,n)}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 x0(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 S0(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)=>x0(i+(t+.5)*(c/n))),m=Array.from({length:r},(e,t)=>x0(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}}oW(),yW();var C0=8e3,w0=3e3,T0=[];function E0(e){return`live`in e?e.live.source.columns():`source`in e&&e.source instanceof b0?e.source.columnMap:void 0}var D0=4e3,O0=new WeakMap;function k0(e,t,n){let r=O0.get(e);r||O0.set(e,r=new Map);let i=JSON.stringify([n,...t]),a=r.get(i);return a||r.set(i,a=new Xw({meta:``,columnNames:[n,...t],units:[],rows:e})),a}var A0=new WeakMap;function j0(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 M0(e,t){let n=1/0,r=-1/0;for(let{rows:i,offset:a}of e){let e=A0.get(i);e||(e=new Map,A0.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 N0(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 P0=new Map;function F0(e){let t=P0.get(e);return t||(t=Float64Array.from({length:e},(e,t)=>t),P0.clear(),P0.set(e,t)),t}function I0(e){let{worksheet:t,viewXRange:n,selectedIds:r,selectedDatasets:i,mathChannels:a,datasetOffsets:o,datasetColors:s,datasetPalette:c}=e,l=t.panels,u=t.panelChartSettings,d=t.xKey,f={connections:(0,Z.useMemo)(()=>d===`ElapsedTime`?e.liveConnections:e.liveConnections.map(e=>{let t=N0(e.dataset.rows,d);return t===e.dataset.rows?e:{...e,dataset:{...e.dataset,rows:t}}}),[e.liveConnections,d])},[p,m]=(0,Z.useState)({}),h=(0,Z.useMemo)(()=>l.some(e=>e.kind!==`multiband`),[l]),g=(0,Z.useMemo)(()=>f.connections.some(e=>r.includes(e.id)),[f.connections,r]),_=(0,Z.useMemo)(()=>{let e=f.connections.filter(e=>r.includes(e.id));return e.length===1&&i.length===0?e[0]:null},[f.connections,r,i]),v=(0,Z.useMemo)(()=>v0(i.map(e=>{let t=p[e.id];return t?{...e.data,rows:t}:e.data})),[i,p]),y=(0,Z.useMemo)(()=>{let e=f.connections.filter(e=>r.includes(e.id)).map(e=>e.dataset);return e.length===0?v:v0(v?[v,...e]:e)},[v,f.connections,r]),b=(0,Z.useMemo)(()=>rw(a,u,d).map(e=>e.id).join(`
|
|
624
624
|
`),[a,u,d]),x=(0,Z.useMemo)(()=>{let e=new Set(b.split(`
|
|
625
|
-
`));return a.filter(t=>e.has(t.id))},[a,b]),S=(0,Z.useMemo)(()=>{if(!y)return null;let e=[...i.map(e=>{let t=p[e.id];return t?{...e.data,rows:t}:e.data}),...f.connections.filter(e=>r.includes(e.id)).map(e=>e.dataset)];if(x.length===0)return{dataset:y,partRows:e.map(e=>e.rows),parts:e};let t=e.map(e=>nw(e,x,d)),n=new Set(t.flatMap(e=>e.ok.map(e=>e.id))),a=x.filter(e=>n.has(e.id)),o=t.map(e=>e.rows),s=t.map(e=>e.ok.map(e=>e.name));if(a.length===0)return{dataset:y,partRows:o,parts:e};let c=a.filter(e=>!y.columnNames.includes(e.name));return{dataset:{meta:y.meta,columnNames:[...y.columnNames,...c.map(e=>e.name)],units:[...y.units,...c.map(e=>e.units)],rows:o.length===1?o[0]:[].concat(...o)},partRows:o,parts:e,okByPart:s}},[y,i,p,f.connections,r,x,d]),C=S?.dataset??null,w=(0,Z.useMemo)(()=>{let e=f.connections.filter(e=>r.includes(e.id));return e.length===0?i:[...i,...e.map(e=>({id:e.id,name:e.name,data:e.dataset,live:e}))]},[i,f.connections,r]),T=w.length>1,E=(0,Z.useMemo)(()=>w.length===1?
|
|
625
|
+
`));return a.filter(t=>e.has(t.id))},[a,b]),S=(0,Z.useMemo)(()=>{if(!y)return null;let e=[...i.map(e=>{let t=p[e.id];return t?{...e.data,rows:t}:e.data}),...f.connections.filter(e=>r.includes(e.id)).map(e=>e.dataset)];if(x.length===0)return{dataset:y,partRows:e.map(e=>e.rows),parts:e};let t=e.map(e=>nw(e,x,d)),n=new Set(t.flatMap(e=>e.ok.map(e=>e.id))),a=x.filter(e=>n.has(e.id)),o=t.map(e=>e.rows),s=t.map(e=>e.ok.map(e=>e.name));if(a.length===0)return{dataset:y,partRows:o,parts:e};let c=a.filter(e=>!y.columnNames.includes(e.name));return{dataset:{meta:y.meta,columnNames:[...y.columnNames,...c.map(e=>e.name)],units:[...y.units,...c.map(e=>e.units)],rows:o.length===1?o[0]:[].concat(...o)},partRows:o,parts:e,okByPart:s}},[y,i,p,f.connections,r,x,d]),C=S?.dataset??null,w=(0,Z.useMemo)(()=>{let e=f.connections.filter(e=>r.includes(e.id));return e.length===0?i:[...i,...e.map(e=>({id:e.id,name:e.name,data:e.dataset,live:e}))]},[i,f.connections,r]),T=w.length>1,E=(0,Z.useMemo)(()=>w.length===1?E0(w[0]):void 0,[w]),D=S?.partRows??T0;(0,Z.useEffect)(()=>{let e=i.filter(e=>e.kind!==`memory`);if(e.length===0)return;if(!n||!h){m(e=>Object.keys(e).length?{}:e);return}let t=!1,r=setTimeout(()=>{(async()=>{let r=await Promise.all(e.map(async e=>{let t={xcol:d,x0:n[0],x1:n[1]};try{let n=e.source,r=await pY(`sampleRows`,()=>n.sampleRows(w0,t));return[e.id,r]}catch{return null}}));if(t)return;let i={};for(let e of r)e&&(i[e[0]]=e[1]);m(i)})()},150);return()=>{t=!0,clearTimeout(r)}},[i,n,d,h]);let O=(0,Z.useMemo)(()=>C?.columnNames.join(`
|
|
626
626
|
`)??``,[C]),k=a.map(e=>e.name).join(`
|
|
627
|
-
`),A=(0,Z.useMemo)(()=>{let e=i.filter(e=>e.kind!==`memory`).flatMap(e=>VG(e.schema));return e.length?e:null},[i]),j=(0,Z.useMemo)(()=>i.some(e=>e.kind!==`memory`)||!g&&i.some(e=>e.data.rows.length>
|
|
628
|
-
`).filter(e=>!i.has(e));return a.length?[...r,...a]:r},[O,k,A]),L=(0,Z.useMemo)(()=>{let e=[];for(let t of l){if(t.kind!==`multiband`)continue;let n=u[t.id],r=n&&n.kind===`multiband`?n.series:[];e.push([t.id,[...new Set(r.map(e=>e.column).filter(e=>e!==d))]])}return JSON.stringify(e)},[l,u,d]),R=(0,Z.useMemo)(()=>{let e={};if(!C||j)return e;for(let[t,n]of JSON.parse(L)){let r=[];if(n.length>0)if(!T)r.push(tW(C.rows,d,n,S0));else{let e=Math.max(1,Math.floor(S0/w.length));for(let t=0;t<w.length;t++){let i=w[t];if(M&&`live`in i&&i.live)continue;let a=D[t]??i.data.rows;r.push(tW(a,d,n,e,`__${t}`,o[i.id]??0))}}e[t]=r}return e},[C,L,d,T,w,o,D,M,j]),z=(0,Z.useMemo)(()=>{let e={};if(!C)return e;for(let t of l){if(t.kind!==`multiband`)continue;let n=u[t.id],r=(n&&n.kind===`multiband`?n.series:[]).filter(e=>e.column!==d),i=n&&n.kind===`multiband`?n.layout:`overlay`,a=e=>A0(e,i),o;if(!T)o=a(r);else{let e=a(r);o=[];for(let t=0;t<w.length;t++){let n=eK(s,w[t].id,t,c);for(let r of e)o.push({...r,id:`${r.id}__${t}`,column:`${r.column}__${t}`,color:n})}}let l=R[t.id]??[],f=T&&n?.kind===`multiband`&&n.envelope?r.flatMap(e=>{let t=h0(l.flatMap((t,n)=>{let r=t.cols.get(`${e.column}__${n}`);return r?[{x:t.x,y:r}]:[]}),E0);return t?[{seriesId:e.id,color:e.color,...t}]:[]}):void 0;e[t.id]={effectiveSeries:o,points:l,envelopes:f}}return e},[C,l,u,d,T,w,s,c,R]),B=(0,Z.useMemo)(()=>{let e={pts:{},colorMeta:{},datasetColors:{}};if(!C)return e;let t={},r={},i={},a=T0,o=w.map((e,t)=>({id:e.id,rows:D[t]??p[e.id]??e.data.rows,full:a(e)})),f={id:`single`,rows:C.rows,full:w.length===1?a(w[0]):void 0};for(let e of l){if(e.kind!==`xyscatter`)continue;let a=u[e.id];if(!a||a.kind!==`xyscatter`)continue;let{xyXCol:l,xyYCol:p}=a;if(!l||!p){t[e.id]={length:0,x:[],y:[]};continue}if(T){let{cols:r,colors:a}=RY(o,l,p,{xKey:d,viewXRange:n,colorOverrides:s,palette:c});t[e.id]=r,i[e.id]=a;continue}let m=LY(f,l,p,{xKey:d,viewXRange:n,colorCol:a.xyColorCol||void 0});t[e.id]=m?.cols??{length:0,x:[],y:[]},m?.color&&(r[e.id]=m.color)}return{pts:t,colorMeta:r,datasetColors:i}},[C,l,u,n,d,T,w,p,s,c,D]),V=(0,Z.useRef)(new Map),H=(0,Z.useMemo)(()=>{let e={};if(!C)return e;let t={length:0,x:[],y:[],z:[]},{rows:r}=C,i=E;for(let a of l){if(a.kind!==`xyzmesh`)continue;let o=u[a.id];if(!o||o.kind!==`xyzmesh`)continue;if(o.xyzMode===`matrix`){let n=(o.xyzColumns??[]).flatMap(e=>{let t=jY(r,e,i);return t?[t]:[]}),s=n[0]?.length??0,c=n.length;if(s<2||c<2){e[a.id]={points:t};continue}let l=V.current.get(a.id);l?.length!==s*c&&V.current.set(a.id,l=new Float32Array(s*c)),n.forEach((e,t)=>l.set(e.length===s?e:e.subarray(0,s),t*s));let u=jY(r,d,i),f=u&&!(o.xyzColumns??[]).includes(d)&&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:f,y:[0,c-1]}};continue}let{xyzXCol:s,xyzYCol:c,xyzZCol:l}=o,f=s?jY(r,s,i):void 0,p=c?jY(r,c,i):void 0,m=l?jY(r,l,i):void 0;if(!f||!p||!m){e[a.id]={points:t};continue}let h=n?jY(r,d,i):void 0;if(!n||!h){e[a.id]={points:{length:Math.min(f.length,p.length,m.length),x:f,y:p,z:m}};continue}let[g,_]=n,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]=f[e],b[t]=p[e],x[t]=m[e],t++);e[a.id]={points:{length:v,x:y,y:b,z:x}}}return e},[C,l,u,n,d,E]),U=(0,Z.useMemo)(()=>{let e={};if(!C)return e;for(let t of l){if(t.kind!==`histogram`)continue;let n=u[t.id];e[t.id]=n?.kind===`histogram`&&n.histColumn&&MY(C.rows,n.histColumn,E)||new Float64Array}return e},[C,l,u,E]),W=(0,Z.useMemo)(()=>{let e={};if(!C)return e;for(let t of l){if(t.kind!==`polar`)continue;let n=u[t.id],r=n?.kind===`polar`&&n.polarAngleCol?jY(C.rows,n.polarAngleCol,E):void 0,i=n?.kind===`polar`&&n.polarRadiusCol?jY(C.rows,n.polarRadiusCol,E):void 0;e[t.id]=r&&i?{angles:r,radii:i}:{angles:[],radii:[]}}return e},[C,l,u,E]),ee=(e,t,n,r)=>{let i=t&&MY(e,t,E)||new Float64Array,a=n?jY(e,n,E):void 0;return{signal:i,rate:a&&PY(a)||parseFloat(r)||1}},te=(0,Z.useMemo)(()=>{let e={};if(!C)return e;for(let t of l){if(t.kind!==`spectrum`)continue;let n=u[t.id];n?.kind===`spectrum`&&(e[t.id]=ee(C.rows,n.specSignalCol,n.specTimeCol,n.specSampleRate))}return e},[C,l,u,E]),ne=(0,Z.useMemo)(()=>{let e={};if(!C)return e;for(let t of l){if(t.kind!==`boxplot`)continue;let n=u[t.id];e[t.id]=n?.kind===`boxplot`&&n.boxValueCol?NY(C.rows,n.boxValueCol,n.boxGroupCol||void 0,E):[]}return e},[C,l,u,E]),G=(0,Z.useMemo)(()=>{let e={};if(!C)return e;for(let t of l){if(t.kind!==`spectrogram`)continue;let n=u[t.id];n?.kind===`spectrogram`&&(e[t.id]=ee(C.rows,n.sgSignalCol,n.sgTimeCol,n.sgSampleRate))}return e},[C,l,u,E]),re=(0,Z.useMemo)(()=>{if(!C)return{};let e={};for(let t of l){if(t.kind!==`heatmap`)continue;let n=u[t.id];if(!n||n.kind!==`heatmap`){e[t.id]={cells:[],xLabels:[],yLabels:[]};continue}if(n.hmMode===`matrix`){let r=C.rows,i=n.hmColumns.flatMap(e=>{let t=jY(r,e,E);return t?[{name:e,v:t}]:[]}),a=i.reduce((e,t)=>Math.min(e,t.v.length),i.length?1/0:0),o=jY(r,d,E),s,c;if(n.hmSpacing===`values`){o&&GQ(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&&GQ(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 f=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:f,yLabels:i.map(e=>e.name)},xCentres:s,yCentres:c}}else if(n.hmMode===`correlation`){let r=n.hmColumns.filter(e=>I.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 C.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]=x0(C.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 C.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);GQ(e)&&(f=e),GQ(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},[C,l,u,I,d,E]),ie=(0,Z.useMemo)(()=>{let e={};if(!C)return e;for(let t of l){if(t.kind!==`violin`)continue;let n=u[t.id];e[t.id]=n?.kind===`violin`&&n.vlValueCol?NY(C.rows,n.vlValueCol,n.vlGroupCol||void 0,E):[]}return e},[C,l,u,E]),ae=(0,Z.useMemo)(()=>{let e={};if(!C)return e;let{rows:t}=C;for(let n of l){if(n.kind!==`confusion`)continue;let r=u[n.id];if(!r||r.kind!==`confusion`||!r.cfActualCol||!r.cfPredictedCol){e[n.id]={actual:[],predicted:[]};continue}let{cfActualCol:i,cfPredictedCol:a}=r,o=E?.get(i),s=E?.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},[C,l,u,E]),oe=(0,Z.useMemo)(()=>{let e={};if(!C)return e;for(let t of l){if(t.kind!==`roc`)continue;let n=u[t.id],r=n?.kind===`roc`&&n.rocScoreCol?jY(C.rows,n.rocScoreCol,E):void 0,i=n?.kind===`roc`&&n.rocLabelCol?jY(C.rows,n.rocLabelCol,E):void 0;e[t.id]=r&&i?{scores:r,labels:i}:{scores:[],labels:[]}}return e},[C,l,u,E]),se=(0,Z.useMemo)(()=>{let e={};if(!C)return e;let{rows:t}=C;for(let n of l){if(n.kind!==`losscurve`)continue;let r=u[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:jY(t,e,E)??new Float64Array,axis:r})),c=s[0]?.values.length??t.length,l=i&&jY(t,i,E)||Float64Array.from({length:c},(e,t)=>t);e[n.id]={xValues:l,series:s}}return e},[C,l,u,E]),ce=(0,Z.useMemo)(()=>{let e={};if(!C)return e;let{rows:t}=C;for(let n of l){if(n.kind!==`controlchart`)continue;let r=u[n.id],i=r?.kind===`controlchart`&&r.ccValueCol?jY(t,r.ccValueCol,E):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?E?.get(c):void 0,d=e=>o?o[e]:e;e[n.id]={length:a,value:s,subgroup:c?e=>String(l?l[d(e)]:t[d(e)]?.[c]??``):void 0}}return e},[C,l,u,E]),le=(0,Z.useMemo)(()=>{let e={};if(!C)return e;let{rows:t}=C;for(let n of l){if(n.kind!==`parallelcoords`)continue;let r=u[n.id];if(!r||r.kind!==`parallelcoords`||r.pcColumns.length<2){e[n.id]={length:0,columns:[]};continue}let i=r.pcColumns.map(e=>jY(t,e,E)??new Float64Array),a=Math.min(...i.map(e=>e.length)),o={length:a,columns:i},s=r.pcColorByCol;if(s)if(I.includes(s))o.colorValue=jY(t,s,E);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},[C,l,u,I,E]),ue=(0,Z.useMemo)(()=>{let e={};if(!C)return e;let{rows:t}=C,n={length:0,x:[],y:[]};for(let r of l){if(r.kind!==`embedding`)continue;let i=u[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,d=jY(t,a,E),f=jY(t,o,E);if(!d||!f){e[r.id]=n;continue}let p=Math.min(d.length,f.length),m={length:p,x:d,y:f};if(s)if(c===`numeric`&&I.includes(s))m.colorValue=jY(t,s,E);else{let e=E?.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=E?.get(l);m.label=e?t=>String(e[t]):e=>String(t[e]?.[l]??``)}e[r.id]=m}return e},[C,l,u,I,E]),de=(0,Z.useMemo)(()=>{if(!C)return{};let e={};for(let t of l){if(t.kind!==`flamegraph`)continue;let n=u[t.id];if(!n||n.kind!==`flamegraph`||!n.fgNameCol||!n.fgValueCol){e[t.id]=[];continue}let r=[];for(let e of C.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},[C,l,u]),fe=(0,Z.useMemo)(()=>{if(!C)return{};let e={};for(let t of l){if(t.kind!==`barchart`)continue;let n=u[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 C.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=C.rows,i=r.map(e=>jY(n,e,E)),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},[C,l,u,E]),pe=(0,Z.useMemo)(()=>{let e={};if(!C)return e;let{rows:t}=C;for(let n of l){if(n.kind!==`radar`)continue;let r=u[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=>jY(t,e,E));if(r.rdGroupCol){let o=r.rdGroupCol,s=E?.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},[C,l,u,E]),me=(0,Z.useMemo)(()=>{if(!C)return{};let e={};for(let t of l){if(t.kind!==`areachart`)continue;let n=u[t.id];if(!n||n.kind!==`areachart`||n.acYCols.length===0){e[t.id]=[];continue}let r=C.rows,i=n.acYCols.map(e=>jY(r,e,E)),a=i[0]?.length??r.length,o=(n.acXCol?jY(r,n.acXCol,E):void 0)??P0(a);e[t.id]=n.acYCols.flatMap((e,t)=>{let n=i[t];return n?[{name:e,x:o,y:n}]:[]})}return e},[C,l,u,E]),he=(0,Z.useMemo)(()=>{let e={};if(!C)return e;for(let t of l){if(t.kind!==`cdfchart`)continue;let n=u[t.id];if(!n||n.kind!==`cdfchart`){e[t.id]=[];continue}e[t.id]=n.cdValueCols.map(e=>({name:e,values:MY(C.rows,e,E)??new Float64Array}))}return e},[C,l,u,E]),ge=(0,Z.useMemo)(()=>{let e={};if(!C)return e;let{rows:t}=C,n={length:0,x:[],y:[],size:[]};for(let r of l){if(r.kind!==`bubblechart`)continue;let i=u[r.id];if(!i||i.kind!==`bubblechart`||!i.bbXCol||!i.bbYCol||!i.bbSizeCol){e[r.id]=n;continue}let a=jY(t,i.bbXCol,E),o=jY(t,i.bbYCol,E),s=jY(t,i.bbSizeCol,E);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 d=new Float64Array(c);for(let e=0;e<c;e++)d[e]=l[e]===l[e]?a[e]:NaN;let f={length:c,x:d,y:o,size:l};if(i.bbColorCol){if(i.bbColorMode===`numeric`)f.colorValue=jY(t,i.bbColorCol,E);else if(i.bbColorMode===`categorical`){let e=E?.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},[C,l,u,E]),_e=(0,Z.useMemo)(()=>{if(!C)return{};let e={};for(let t of l){if(t.kind!==`treemap`)continue;let n=u[t.id];if(!n||n.kind!==`treemap`||!n.tmNameCol||!n.tmValueCol){e[t.id]=[];continue}let r=[];for(let e of C.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},[C,l,u]),ve=(0,Z.useMemo)(()=>{if(!C)return{};let e={};for(let t of l){if(t.kind!==`sankey`)continue;let n=u[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 C.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},[C,l,u]),ye=(0,Z.useMemo)(()=>{let e={};if(!C)return e;for(let t of l){if(t.kind!==`calibration`)continue;let n=u[t.id],r=n?.kind===`calibration`&&n.cbScoreCol?jY(C.rows,n.cbScoreCol,E):void 0,i=n?.kind===`calibration`&&n.cbLabelCol?jY(C.rows,n.cbLabelCol,E):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},[C,l,u,E]),be=(0,Z.useMemo)(()=>{let e={};if(!C)return e;let t={length:0,theoretical:[],sample:[]},n=e=>{let t=MY(C.rows,e,E);return t?Float64Array.from(t).sort():new Float64Array};for(let r of l){if(r.kind!==`qqplot`)continue;let i=u[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},[C,l,u,E]),xe=(0,Z.useMemo)(()=>{if(!C)return{};let e={};for(let t of l){if(t.kind!==`gantt`)continue;let n=u[t.id];if(!n||n.kind!==`gantt`||!n.gtLabelCol||!n.gtStartCol||!n.gtEndCol){e[t.id]=[];continue}let r=[];for(let e of C.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},[C,l,u]),Se=C&&C.columnNames.indexOf(d)>=0?C.units[C.columnNames.indexOf(d)]??``:``,Ce=(0,Z.useMemo)(()=>{if(!C)return{};let e={};for(let t=0;t<C.columnNames.length;t++){let n=C.units[t]?.trim();n&&(e[C.columnNames[t]]=n)}if(T)for(let t=0;t<w.length;t++)for(let[n,r]of Object.entries(e))e[`${n}__${t}`]=r;return e},[C,T,w]);return{dataset:y,datasetWithChannels:C,multiDatasetMode:T,numericCols:I,anyDuckDb:j,duckDbLayers:F,liveConn:_,liveOverlay:M,hasLiveSelected:g,staticXRange:N,xUnit:Se,columnUnits:Ce,multibandDataByPanel:z,xyPointsByPanel:B,xyzPointsByPanel:H,histogramDataByPanel:U,polarDataByPanel:W,spectrumDataByPanel:te,boxplotDataByPanel:ne,spectrogramDataByPanel:G,heatmapDataByPanel:re,violinDataByPanel:ie,confusionDataByPanel:ae,rocDataByPanel:oe,lossCurveDataByPanel:se,controlChartDataByPanel:ce,parallelCoordsDataByPanel:le,embeddingDataByPanel:ue,flameGraphDataByPanel:de,barChartDataByPanel:fe,radarDataByPanel:pe,areaChartDataByPanel:me,cdfChartDataByPanel:he,bubbleChartDataByPanel:ge,treemapDataByPanel:_e,sankeyDataByPanel:ve,calibrationDataByPanel:ye,qqPlotDataByPanel:be,ganttDataByPanel:xe,gaugeDataByPanel:(0,Z.useMemo)(()=>{let e={};if(!C)return e;let t=e=>e.trim()!==``&&Number.isFinite(Number(e))?Number(e):void 0;for(let n of l){if(n.kind!==`gauge`)continue;let r=u[n.id];if(r?.kind!==`gauge`){e[n.id]=[];continue}e[n.id]=r.ggGauges.flatMap(e=>{let n=e.column,r=n?jY(C.rows,n,E):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]=I0(s?i:0,s?a:1,t(e.min),t(e.max));return[{name:n,unit:Ce[n]??``,value:l,min:u,max:d,alarm:e.alarm??null,color:e.color,style:e.style,colorMode:e.colorMode,stops:e.stops}]})}return e},[C,l,u,E,Ce])}}function I0(e,t,n,r){t<=e&&(t=e+1);let i=WG(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]}oW();var L0=`__ref`,R0=8e3;function z0(e,t){return e.map(e=>({...e,id:`${e.id}${L0}`,column:`${e.column}${L0}`,color:t}))}var B0=new WeakMap;function V0(e,t,n){let r=e.data.rows,i=`${t}\n${n.join(`
|
|
629
|
-
`)}`,a=B0.get(r);a||(a=new Map,B0.set(r,a));let o=a.get(i);if(o)return o;let s=H0(tW(r,t,n,R0,L0)),c={points:s,span:s.length>1?[s.x[0],s.x[s.length-1]]:null};return a.set(i,c),c}function H0(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 U0(e,t){return e?t?[Math.min(e[0],t[0]),Math.max(e[1],t[1])]:e:t}function W0(e,t,n,r,i){e.source.trackCycles(t);let a=r.reference===`dataset`&&i?V0(i,t,n):null,o=null;return{pull:(i,s,c,l)=>{let u=e.source.version();if(!o||o.ver!==u||o.x0!==i||o.x1!==s||o.mp!==c){let l=aW;if(r.reference===`previous`){let r=e.source.cyclePointsSync(t,`previous`,n,{x0:i,x1:s},c);l={...r,cols:new Map([...r.cols].map(([e,t])=>[e+L0,t]))}}else a&&(l=$U(a.points,i,s));o={ver:u,x0:i,x1:s,mp:c,live:e.source.cyclePointsSync(t,`current`,n,{x0:i,x1:s},c),ref:l}}return[o.ref,QU(o.live,l)]},latestT:()=>e.source.latestTimeSync(),xAtTime:n=>e.source.xAtTimeSync(t,n),xBounds:()=>U0(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 G0(e,t){return e.reference===`previous`?e.previousColor:e.reference===`dataset`&&t?e.datasetColor:null}oW();function K0(e,t,n,r,i,a,o){let s=null;return{pull:(o,c,l,u)=>{let d=e.source.version();if(!s||s.ver!==d||s.x0!==o||s.x1!==c||s.mp!==l){let a=e.source.getPointsSync(n,{xKey:t,x0:o-i,x1:c-i},l),u=i===0?a.x:a.x.map(e=>e+i);s={ver:d,x0:o,x1:c,mp:l,pts:{...a,x:u,cols:new Map([...a.cols].map(([e,t])=>[e+r,t]))}}}return[...a,QU(s.pts,u)]},xBounds:()=>{let n=e.source.xBoundsSync(t);return n.x1>n.x0?o?[Math.min(o[0],n.x0+i),Math.max(o[1],n.x1+i)]:[n.x0+i,n.x1+i]:o},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}}}oW(),yW();var q0=`#fb7185`,J0=2500;function Y0(e){let{panel:t,data:n,settings:r}=e;if(!n.dataset)return{status:`no-data`,node:null,data:null};let i=`${e.background??`theme`}|${e.styleToken}`,a=t=>e.onContextMenu(t),o=(e,t)=>({status:`ready`,node:e,data:t}),s={status:`empty`,node:null,data:null},c=t.id;switch(t.kind){case`multiband`:{let t=n.multibandDataByPanel[c],l=t?.points??[],u=t?.effectiveSeries??[],d=r?.kind===`multiband`?r:null,f=[...new Set((d?.series??[]).map(e=>e.column).filter(t=>t!==e.xKey))],p={xLabel:n.xUnit?`${e.xKey} (${n.xUnit})`:e.xKey,series:u,columnUnits:n.columnUnits,height:e.height,backgroundToken:i,viewXRange:e.viewXRange,onViewXRangeChange:e.onViewXRangeChange,liveZoom:e.liveZoom,liveZoomId:c,xAxisLine:d?.xAxisLine,yAxisLine:d?.yAxisLine,gridLine:d?.gridLine,lineWidth:d?.lineWidth,onPlotContextMenu:a,shiftMode:e.shiftMode},m=d?.beacon;if(m?.enabled&&e.beaconLive&&f.length>0){let t=A0((d?.series??[]).filter(t=>t.column!==e.xKey),d?.layout??`overlay`),n=m.reference===`dataset`&&m.datasetId?e.findDataset(m.datasetId):void 0,r=G0(m,!!n),i=r?[...z0(t,r),...t]:t;return o((0,Q.jsx)(sY,{...p,series:i,points:[],showLatestValues:!0,liveSource:W0(e.beaconLive,e.xKey,f,m,n),liveZoomMode:`free`}),{series:i,points:[]})}if(n.anyDuckDb)return u.length===0?s:o((0,Q.jsx)(OY,{...p,layers:n.duckDbLayers,xKey:e.xKey,columns:f,maxPoints:J0}),{series:u,columns:f});if(!l.some(e=>e.length>0)||u.length===0)return s;let h=n.liveConn,g=null,_=n.liveOverlay,v=!h&&_&&f.length>0?K0(_.conn,e.xKey,f,_.keySuffix,_.offset,l,n.staticXRange):void 0,y=v??(h&&f.length>0?{pull:(t,n,r,i)=>{let a=h.source.version();return(!g||g.ver!==a||g.x0!==t||g.x1!==n||g.mp!==r)&&(g={ver:a,x0:t,x1:n,mp:r,pts:h.source.getPointsSync(f,{xKey:e.xKey,x0:t,x1:n},r)}),[QU(g.pts,i)]},latestT:()=>h.source.latestTimeSync(),xAtTime:t=>h.source.xAtTimeSync(e.xKey,t),xBounds:()=>{let t=h.source.xBoundsSync(e.xKey);return t.x1>t.x0?[t.x0,t.x1]:null},latestX:()=>{let t=h.source.latestSync(e.xKey);return Number.isFinite(t)?t:null},version:()=>h.source.version(),latestValues:e=>h.source.latestValuesSync(e),...e.xKey===`ElapsedTime`?{}:{spanForSeconds:t=>h.source.xTravelSync(e.xKey,t),bufferedSeconds:()=>{let e=h.source.xBoundsSync(`ElapsedTime`);return e.x1-e.x0}}}:void 0);return o((0,Q.jsx)(sY,{...p,points:l,envelopes:t?.envelopes,showLatestValues:n.hasLiveSelected,fullXRange:n.staticXRange,liveSource:y,liveWindowSeconds:v?null:e.liveWindowSeconds,onLiveWindowChange:v?void 0:e.onLiveWindowChange,liveZoomMode:v?`free`:`follow`}),{series:u,points:l})}case`xyzmesh`:{let t=r?.kind===`xyzmesh`?r:H(4),l=n.xyzPointsByPanel[c];if(!l||l.points.length<1&&!l.surface)return s;let u=!!l.surface;return o((0,Q.jsx)(kZ,{ref:e.xyzRef,points:l.points,surface:l.surface,xLabel:u?(t.xyzColumns??[]).includes(e.xKey)?`Row`:e.xKey:t.xyzXCol,yLabel:u?`Column`:t.xyzYCol,zLabel:u?`Value`:t.xyzZCol,height:e.height,backgroundToken:i,xRange:R(t.xyzXScale.scaleMin,t.xyzXScale.scaleMax),yRange:R(t.xyzYScale.scaleMin,t.xyzYScale.scaleMax),zRange:R(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}),l.surface??l.points)}case`xyscatter`:{let t=r?.kind===`xyscatter`?r:V(q0),l=n.xyPointsByPanel.pts[c]??[];if(l.length===0)return s;let u=n.xyPointsByPanel.colorMeta[c];return o((0,Q.jsx)(_X,{points:l,xLabel:t.xyXCol,yLabel:t.xyYCol,color:t.xyColor,datasetColors:n.xyPointsByPanel.datasetColors[c],colorLabel:u?.label,colorRange:u?[u.min,u.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}),l)}case`histogram`:{if(r?.kind!==`histogram`)return s;let t=n.histogramDataByPanel[c]??[];return t.length===0?s:o((0,Q.jsx)(IZ,{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 s;let t=n.polarDataByPanel[c]??{angles:[],radii:[]};if(t.angles.length===0)return s;let l=parseFloat(r.polarRadiusMin),u=parseFloat(r.polarRadiusMax);return o((0,Q.jsx)(eQ,{angles:t.angles,radii:t.radii,angleLabel:r.polarAngleCol,radiusLabel:r.polarRadiusCol,color:r.polarColor,mode:r.polarMode,radiusMin:Number.isFinite(l)?l:void 0,radiusMax:Number.isFinite(u)?u:void 0,height:e.height,backgroundToken:i,onPlotContextMenu:a}),t)}case`spectrum`:{if(r?.kind!==`spectrum`)return s;let{signal:t,rate:l}=n.spectrumDataByPanel[c]??{signal:[],rate:1};return t.length<4?s:o((0,Q.jsx)(gQ,{signal:t,sampleRate:l,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 s;let t=n.boxplotDataByPanel[c]??[];return t.length===0?s:o((0,Q.jsx)(SQ,{groups:t,color:r.boxColor,whiskers:r.boxWhiskers,height:e.height,backgroundToken:i,onPlotContextMenu:a}),t)}case`spectrogram`:{if(r?.kind!==`spectrogram`)return s;let{signal:e,rate:t}=n.spectrogramDataByPanel[c]??{signal:[],rate:1};return e.length<r.sgWindowSize?s:r.sgView===`waterfall`?o((0,Q.jsx)(BQ,{signal:e,sampleRate:t,windowSize:r.sgWindowSize,overlap:r.sgOverlap,winFunc:r.sgWinFunc,yMode:r.sgYMode,backgroundToken:i,onPlotContextMenu:a}),e):o((0,Q.jsx)(FQ,{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 s;let e=n.heatmapDataByPanel[c]??{cells:[],xLabels:[],yLabels:[]};if(e.cells.length===0&&!(e.grid&&e.grid.w*e.grid.h>0))return s;let t=e=>e!==void 0&&e.trim()!==``&&Number.isFinite(Number(e))?Number(e):void 0;return o((0,Q.jsx)(a$,{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 s;let e=n.violinDataByPanel[c]??[];return e.some(e=>e.values.length>0)?o((0,Q.jsx)(p$,{groups:e,color:r.vlColor,showBox:r.vlShowBox,bandwidth:parseFloat(r.vlBandwidth)||void 0,orientation:r.vlOrientation,backgroundToken:i,onPlotContextMenu:a}),e):s}case`confusion`:{if(r?.kind!==`confusion`)return s;let e=n.confusionDataByPanel[c]??{actual:[],predicted:[]};return e.actual.length===0?s:o((0,Q.jsx)(b$,{actual:e.actual,predicted:e.predicted,normalize:r.cfNormalize,backgroundToken:i,onPlotContextMenu:a}),e)}case`roc`:{if(r?.kind!==`roc`)return s;let e=n.rocDataByPanel[c]??{scores:[],labels:[]};return e.scores.length===0?s:o((0,Q.jsx)(E$,{scores:e.scores,labels:e.labels,mode:r.rocMode,color:r.rocColor,backgroundToken:i,onPlotContextMenu:a}),e)}case`losscurve`:{if(r?.kind!==`losscurve`)return s;let e=n.lossCurveDataByPanel[c]??{xValues:[],series:[]};return e.series.length===0?s:o((0,Q.jsx)(O$,{xValues:e.xValues,series:e.series,xLabel:r.lcXCol||`Step`,backgroundToken:i,onPlotContextMenu:a}),e)}case`controlchart`:{if(r?.kind!==`controlchart`)return s;let e=n.controlChartDataByPanel[c];return!e||e.length<2?s:o((0,Q.jsx)(P$,{points:e,sigmaLevel:r.ccSigmaLevel,color:r.ccColor,backgroundToken:i,onPlotContextMenu:a}),e)}case`parallelcoords`:{if(r?.kind!==`parallelcoords`)return s;let e=n.parallelCoordsDataByPanel[c];if(!e||e.length===0||r.pcColumns.length<2)return s;let t=r.pcColorByCol?n.numericCols.includes(r.pcColorByCol):!1;return o((0,Q.jsx)(B$,{rows:e,axes:r.pcColumns,color:r.pcColor,colorByNumeric:t,backgroundToken:i,onPlotContextMenu:a}),e)}case`embedding`:{if(r?.kind!==`embedding`)return s;let e=n.embeddingDataByPanel[c];return!e||e.length===0?s:o((0,Q.jsx)(X$,{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 s;let e=n.flameGraphDataByPanel[c]??[];return e.length===0?s:o((0,Q.jsx)(i1,{nodes:e,direction:r.fgDirection,backgroundToken:i,onPlotContextMenu:a}),e)}case`barchart`:{if(r?.kind!==`barchart`)return s;let e=n.barChartDataByPanel[c]??{groups:[],seriesNames:[]};if(e.groups.length===0&&!e.columns?.length)return s;let t=e=>e!==void 0&&e.trim()!==``&&Number.isFinite(Number(e))?Number(e):void 0,l=r.bcValueScale?{min:t(r.bcValueScale.scaleMin),max:t(r.bcValueScale.scaleMax)}:void 0;return o((0,Q.jsx)(u1,{groups:e.columns?void 0:e.groups,columns:e.columns,seriesNames:e.seriesNames,mode:r.bcMode,horizontal:r.bcHorizontal,valueRange:l,backgroundToken:i,onPlotContextMenu:a}),e)}case`radar`:{if(r?.kind!==`radar`)return s;let e=n.radarDataByPanel[c]??{axes:[],series:[]};return e.axes.length<3?s:o((0,Q.jsx)(m1,{axes:e.axes,series:e.series,fill:r.rdFill,color:r.rdColor,backgroundToken:i,onPlotContextMenu:a}),e)}case`areachart`:{if(r?.kind!==`areachart`)return s;let e=n.areaChartDataByPanel[c]??[];if(e.length===0)return s;let t=e=>e!==void 0&&e.trim()!==``&&Number.isFinite(Number(e))?Number(e):void 0,l=r.acYScale?{min:t(r.acYScale.scaleMin),max:t(r.acYScale.scaleMax)}:void 0;return o((0,Q.jsx)(v1,{series:e,stacked:r.acStacked,yRange:l,backgroundToken:i,onPlotContextMenu:a}),e)}case`cdfchart`:{if(r?.kind!==`cdfchart`)return s;let e=n.cdfChartDataByPanel[c]??[];return e.length===0?s:o((0,Q.jsx)(x1,{series:e,complement:r.cdComplement,logX:r.cdLogX,backgroundToken:i,onPlotContextMenu:a}),e)}case`bubblechart`:{if(r?.kind!==`bubblechart`)return s;let e=n.bubbleChartDataByPanel[c];return!e||e.length===0?s:o((0,Q.jsx)(k1,{points:e,color:r.bbColor,colorByNumeric:r.bbColorMode===`numeric`,maxRadius:r.bbMaxRadius,backgroundToken:i,onPlotContextMenu:a}),e)}case`treemap`:{let e=n.treemapDataByPanel[c]??[];return e.length===0?s:o((0,Q.jsx)(P1,{nodes:e,backgroundToken:i,onPlotContextMenu:a}),e)}case`sankey`:{let e=n.sankeyDataByPanel[c]??{nodeNames:[],links:[]};return e.links.length===0?s:o((0,Q.jsx)(B1,{nodeNames:e.nodeNames,links:e.links,backgroundToken:i,onPlotContextMenu:a}),e)}case`calibration`:{if(r?.kind!==`calibration`)return s;let e=n.calibrationDataByPanel[c]??[];return e.length===0?s:o((0,Q.jsx)(H1,{bins:e,color:r.cbColor,backgroundToken:i,onPlotContextMenu:a}),e)}case`qqplot`:{if(r?.kind!==`qqplot`)return s;let e=n.qqPlotDataByPanel[c];return!e||e.length===0?s:o((0,Q.jsx)(W1,{points:e,color:r.qqColor,backgroundToken:i,onPlotContextMenu:a}),e)}case`gauge`:{if(r?.kind!==`gauge`)return s;let e=n.gaugeDataByPanel[c]??[];return e.length===0?s:o((0,Q.jsx)(r0,{gauges:e,backgroundToken:i,onPlotContextMenu:a}),e)}case`gantt`:{let e=n.ganttDataByPanel[c]??[];return e.length===0?s:o((0,Q.jsx)(Y1,{tasks:e,backgroundToken:i,onPlotContextMenu:a}),e)}}return s}var X0=500,Z0=1e3;function Q0(e){if(Array.isArray(e))return $0(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,$0(n)));return t<0?null:t}function $0(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 e2(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 t2({stats:e,host:t}){let[n,r]=(0,Z.useState)(null);if((0,Z.useEffect)(()=>{let n=t.current?.ownerDocument.defaultView??window,i=0,a=0,o=0,s=-1,c=-1,l=e.renders,u=t.current?cJ(t.current):0,d=f=>{c>=0&&f-s>Z0&&(c=f,s=f,a=0,o=0,l=e.renders,u=t.current?cJ(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>=X0){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?cJ(i):0;r({fps:a*1e3/p,repaints:(m-u)*1e3/p,worstFrameMs:o,renderMs:e.lastRenderMs,rendersPerSec:(e.renders-l)*1e3/p,points:Q0(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(0,Q.jsx)(`dl`,{className:`kymo-perf-hud`,style:n2,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`,e2(n.points)]],[`DOM nodes`,e2(n.domNodes)],[`Canvas`,`${n.canvasMp.toFixed(2)} MP`],...n.heapMb===null?[]:[[`JS heap`,`${n.heapMb.toFixed(0)} MB`]]].map(([e,t,n])=>(0,Q.jsxs)(`div`,{style:r2,children:[(0,Q.jsx)(`dt`,{style:i2,children:e}),(0,Q.jsx)(`dd`,{style:n?{...a2,color:n}:a2,children:t})]},e))})}var n2={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)`},r2={display:`flex`,justifyContent:`space-between`,gap:12},i2={color:`var(--text-muted, #8a93a6)`},a2={margin:0,fontWeight:600,textAlign:`right`},o2=3;function s2(e,t,n,r){return e.anchor===`x`&&!r?null:e.points.map(([i,a])=>[e.anchor===`x`?mJ(r,i):i*t,a*n])}function c2(e,t,n,r,i){return t.map(([t,a])=>[e.anchor===`x`&&i?hJ(i,t):l2(t/Math.max(1,n)),l2(a/Math.max(1,r))])}var l2=e=>Math.round(e*1e4)/1e4,u2=(0,Z.memo)(function({annotations:e,tool:t,plotFrame:n,onChange:r,onToolEnd:i,onSelect:a}){let o=(0,Z.useRef)(null),s=(0,Z.useSyncExternalStore)(n.subscribe,n.get),c=s?.x?s:null,[l,u]=(0,Z.useState)({w:0,h:0}),[d,f]=(0,Z.useState)(null),[p,m]=(0,Z.useState)(null),[h,g]=(0,Z.useState)(null),_=(0,Z.useRef)({annotations:e,onChange:r,onToolEnd:i,onSelect:a,tool:t,selected:d,editing:p,frame:c,size:l});_.current={annotations:e,onChange:r,onToolEnd:i,onSelect:a,tool:t,selected:d,editing:p,frame:c,size:l};let v=e=>{_.current.selected!==e&&(_.current.selected=e,f(e),_.current.onSelect(e))};(0,Z.useLayoutEffect)(()=>{let e=o.current;if(!e)return;let t=e.ownerDocument.defaultView??window,n=()=>u({w:e.clientWidth,h:e.clientHeight});n();let r=new t.ResizeObserver(n);return r.observe(e),()=>r.disconnect()},[]),(0,Z.useEffect)(()=>{t&&v(null)}),(0,Z.useEffect)(()=>{d&&!e.some(e=>e.id===d)&&v(null)}),(0,Z.useEffect)(()=>()=>{_.current.selected&&_.current.onSelect(null)},[]),(0,Z.useEffect)(()=>{let e=o.current?.ownerDocument;if(!e)return;let t=e=>{let{selected:t,editing:n,tool:r,annotations:i,onChange:a,onToolEnd:o}=_.current;if(!(n||y2(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)),v(null)):e.key===`Escape`&&v(null))}},n=e=>{let t=_.current.selected,n=e.target;t&&!n?.closest?.(`[data-ann-id="${CSS.escape(t)}"], [data-kymo-annotation-controls]`)&&v(null)};return e.addEventListener(`keydown`,t),e.addEventListener(`pointerdown`,n,!0),()=>{e.removeEventListener(`keydown`,t),e.removeEventListener(`pointerdown`,n,!0)}},[]);let{w:y,h:b}=l,x=e=>{let t=o.current.getBoundingClientRect();return[e.clientX-t.left,e.clientY-t.top]},S=(e,t)=>{let n=o.current.ownerDocument,r=t=>e(x(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)},C=e=>r([..._.current.annotations,e]),w=e=>r(_.current.annotations.map(t=>t.id===e.id?e:t)),T=e=>{if(!t||e.button!==0||p)return;e.preventDefault(),e.stopPropagation();let n=x(e),r={id:crypto.randomUUID(),kind:t.kind,color:t.color,width:t.width,...c?{anchor:`x`}:{}},i=e=>c2(r,e,y,b,c);if(t.kind===`text`){g({...r,points:i([n]),text:``}),m(r.id);return}let a=t.kind===`brush`?[n]:[n,n],o={...r,points:i(a)};g(o);let s=!1;S((t,n)=>{if(s||=Math.hypot(n.clientX-e.clientX,n.clientY-e.clientY)>o2,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)},g(o)},()=>{g(null),s&&o.points.length>=2&&C(o)})},E=(e,t,n)=>{let r=s2(t,y,b,c);if(!r)return;let i=x(e),a=null;S((o,s)=>{if(!a&&Math.hypot(s.clientX-e.clientX,s.clientY-e.clientY)<=o2)return;let{size:c,frame:l}=_.current;a={...t,points:c2(t,n(r,[o[0]-i[0],o[1]-i[1]],o),c.w,c.h,l)},g(a)},()=>{g(null),a&&w(a)})},D=(e,n)=>{t||e.button!==0||p===n.id||(e.preventDefault(),e.stopPropagation(),v(n.id),E(e,n,(e,[t,n])=>e.map(([e,r])=>[e+t,r+n])))},O=(e,t,n)=>{e.button===0&&(e.preventDefault(),e.stopPropagation(),E(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}))},k=e=>{t||e.kind!==`text`&&e.kind!==`box`||(v(e.id),m(e.id))},A=e=>{let t=p;m(null);let n=h&&h.id===t?h:null;if(g(null),e===null||!t)return;let i=e.replace(/\s+$/,``),a=_.current.annotations;if(n){i&&C({...n,text:i});return}let o=a.find(e=>e.id===t);o&&(!i&&o.kind===`text`?r(a.filter(e=>e.id!==t)):w(v2(o,i)))},j=e=>{r(_.current.annotations.filter(t=>t.id!==e)),v(null)},M=(h?e.some(e=>e.id===h.id)?e.map(e=>e.id===h.id?h:e):[...e,h]:e).flatMap(e=>{let t=s2(e,y,b,c);return t?[{a:e,px:t}]:[]}),N=d?M.find(e=>e.a.id===d):void 0,P=N&&N.a.kind!==`text`?_2(N.px):null,F=e=>(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`svg`,{className:`kymo-ann-svg`,width:y,height:b,viewBox:`0 0 ${y} ${b}`,"aria-hidden":`true`,children:e.map(({a:e,px:t})=>e.kind===`text`?null:(0,Q.jsx)(`g`,{"data-ann-id":e.id,className:`kymo-ann kymo-ann--${e.kind}`,onPointerDown:t=>D(t,e),onDoubleClick:()=>k(e),children:(0,Q.jsx)(p2,{a:e,px:t})},e.id))}),e.map(({a:e,px:t})=>{if(e.kind!==`text`&&e.kind!==`box`)return null;let n=p===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(0,Q.jsxs)(`div`,{"data-ann-id":e.id,className:`kymo-ann-text kymo-ann-text--${e.kind}${d===e.id&&e.kind===`text`?` is-selected`:``}`,style:{...r,color:e.color,fontSize:e.kind===`text`?e.width:12},onPointerDown:t=>D(t,e),onDoubleClick:()=>k(e),children:[n?(0,Q.jsx)(f2,{initial:e.text??``,onDone:A}):e.text,d===e.id&&e.kind===`text`&&!n?(0,Q.jsx)(d2,{onDelete:()=>j(e.id),style:{right:-11,top:-11}}):null]},`t-${e.id}`)})]});return(0,Q.jsx)(`div`,{ref:o,className:`kymo-annotations${t?` is-drawing is-tool-${t.kind}`:``}`,onPointerDown:T,onContextMenu:t?e=>e.preventDefault():void 0,children:y>0&&b>0?(0,Q.jsxs)(Q.Fragment,{children:[F(M.filter(e=>e.a.anchor!==`x`)),c?(0,Q.jsx)(`div`,{className:`kymo-ann-clip`,style:{clipPath:`inset(0 ${Math.max(0,y-c.left-c.width)}px 0 ${Math.max(0,c.left)}px)`},children:F(M.filter(e=>e.a.anchor===`x`))}):null,(0,Q.jsxs)(`svg`,{className:`kymo-ann-svg`,width:y,height:b,viewBox:`0 0 ${y} ${b}`,"aria-hidden":`true`,children:[P?(0,Q.jsx)(`rect`,{className:`kymo-ann-selection`,x:P.x-6,y:P.y-6,width:P.w+12,height:P.h+12,rx:4}):null,N&&!p&&(N.a.kind===`box`||N.a.kind===`arrow`)?(0,Q.jsx)(`g`,{"data-ann-id":N.a.id,children:m2(N.a,N.px).map(([e,t],n)=>(0,Q.jsx)(`rect`,{className:`kymo-ann-handle kymo-ann-handle--${N.a.kind===`arrow`?`end`:n%2?`nesw`:`nwse`}`,x:e-4.5,y:t-4.5,width:9,height:9,rx:2,onPointerDown:e=>O(e,N.a,n)},n))}):null]}),P&&!p?(0,Q.jsx)(d2,{onDelete:()=>j(N.a.id),id:N.a.id,style:{left:Math.min(y-12,P.x+P.w+6)-10,top:Math.max(10,P.y-6)-10}}):null]}):null})});function d2({onDelete:e,style:t,id:n}){return(0,Q.jsx)(`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:(0,Q.jsx)(`svg`,{viewBox:`0 0 10 10`,width:`8`,height:`8`,"aria-hidden":`true`,children:(0,Q.jsx)(`path`,{d:`M2 2l6 6M8 2l-6 6`})})})}function f2({initial:e,onDone:t}){let n=(0,Z.useRef)(null),r=(0,Z.useRef)(!1),i=e=>{r.current||(r.current=!0,t(e))};return(0,Z.useLayoutEffect)(()=>{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)},[]),(0,Q.jsx)(`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 p2({a:e,px:t}){let n={stroke:e.color,strokeWidth:e.width,fill:`none`,strokeLinecap:`round`,strokeLinejoin:`round`},r=t=>(0,Q.jsx)(`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(0,Q.jsxs)(Q.Fragment,{children:[r(c),(0,Q.jsx)(`path`,{d:c,...n}),(0,Q.jsx)(`path`,{d:c,fill:e.color,fillOpacity:.06,stroke:`none`,pointerEvents:`none`})]})}case`arrow`:{let[[i,a],[o,s]]=t,c=g2(i,a,o,s,e.width);return(0,Q.jsxs)(Q.Fragment,{children:[r(`M${i} ${a}L${o} ${s}`),(0,Q.jsx)(`path`,{d:`M${i} ${a}L${c.base[0]} ${c.base[1]}`,...n}),(0,Q.jsx)(`path`,{d:c.d,fill:e.color,stroke:e.color,strokeWidth:1,strokeLinejoin:`round`})]})}case`brush`:{let e=h2(t);return(0,Q.jsxs)(Q.Fragment,{children:[r(e),(0,Q.jsx)(`path`,{d:e,...n})]})}}return null}function m2(e,t){if(e.kind===`arrow`)return t;let[[n,r],[i,a]]=t;return[[n,r],[i,r],[i,a],[n,a]]}function h2(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 g2(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 _2(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 v2(e,t){if(t)return{...e,text:t};let{text:n,...r}=e;return r}function y2(e){let t=e;return!!t&&(t.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName))}function b2(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=s2(i,n,r,o);t&&(e.save(),i.anchor===`x`&&o&&(e.beginPath(),e.rect(o.left,0,o.width,r),e.clip()),x2(e,i,t,a),e.restore())}e.restore()}function x2(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(h2(n)));else if(t.kind===`arrow`){let r=g2(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(`
|
|
630
|
-
`),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 S2={solid:void 0,dashed:`5 4`,dotted:`1 4`};function C2(e,t,n){if(!e||!(n===`x`?e.x:e.y))return null;if(n===`x`){let n=mJ(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=gJ(e,t.value);return r>=e.top-.5&&r<=e.top+e.height+.5?[e.left,r,e.left+e.width,r]:null}var w2=(0,Z.memo)(function({frame:e,alarm:t,axis:n}){let r=C2((0,Z.useSyncExternalStore)(e.subscribe,e.get),t,n);return r?(0,Q.jsx)(`svg`,{className:`kymo-alarm`,"aria-hidden":`true`,children:(0,Q.jsx)(`line`,{x1:r[0],y1:r[1],x2:r[2],y2:r[3],stroke:t.color,strokeWidth:t.width,strokeDasharray:S2[t.style]})}):null});function T2(e,t,n,r,i){let a=C2(t,n,r);a&&(e.save(),e.scale(i,i),e.strokeStyle=n.color,e.lineWidth=n.width,e.setLineDash(S2[n.style]?.split(` `).map(Number)??[]),e.beginPath(),e.moveTo(a[0],a[1]),e.lineTo(a[2],a[3]),e.stroke(),e.restore())}function E2(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)},onContextMenu:t=>e.emitter.emit(`contextmenu`,t),xyzRef:t=>{e.xyz=t},onAnnotations:n=>t.charts.setAnnotations(e.chartId,n),onAnnotationToolEnd:()=>{e.annotationTool=null,j2(t).bump(),e.emitter.emit(`annotationtool`,null)},onAnnotationSelect:t=>{e.selectedAnnotation=t,e.emitter.emit(`annotationselect`,t)}}}var D2=new WeakMap;function O2(e){let t=D2.get(e);return t||D2.set(e,t=t=>e.view.setLiveWindow(t)),t}var k2=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=(0,cq.createRoot)(document.createElement(`div`)),this.root.render((0,Q.jsx)(L2,{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}},A2=new WeakMap;function j2(e){let t=A2.get(e);return t||(t=new k2(e),A2.set(e,t)),t}function M2(e,t,n,r={}){e.charts.get(t);let i=j2(e),a={key:crypto.randomUUID(),chartId:t,element:n,options:r,shiftDatasetId:null,emitter:fq(),xyz:null,annotationTool:null,selectedAnnotation:null,plotFrame:yJ(),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 jw(`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 jw(`export_failed`,{reason:`canvas unavailable`}));for(let e of r)o.drawImage(e,0,0);let s=e.charts.get(t),c=s.annotations,l=Ae(s.settings);return l&&n.clientWidth>0&&T2(o,a.plotFrame.get(),l.alarm,l.axis,i.width/n.clientWidth),c.length&&n.clientWidth>0&&b2(o,c,n.clientWidth,n.clientHeight,i.width/n.clientWidth,X.sans,a.plotFrame.get()?.x?a.plotFrame.get():null),new Promise((e,t)=>i.toBlob(n=>n?e(n):t(new jw(`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 N2(e){A2.get(e)?.refresh()}function P2(e){A2.get(e)?.dispose(),A2.delete(e)}function F2(e){let t=new MutationObserver(e);return t.observe(document.documentElement,{attributes:!0,attributeFilter:[`data-color-scheme`,`class`,`data-theme`]}),()=>t.disconnect()}var I2=()=>{let e=document.documentElement;return`${e.getAttribute(`data-color-scheme`)??``}|${e.getAttribute(`data-theme`)??``}|${e.className}`};function L2({engine:e,registry:t}){(0,Z.useSyncExternalStore)(t.subscribe,t.getVersion);let n=e3(e),r=(0,Z.useSyncExternalStore)(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(0,Q.jsx)(Q.Fragment,{children:[...i.values()].map(t=>(0,Q.jsx)(V2,{engine:e,worksheet:t.worksheet,mounts:t.mounts},t.worksheet.id))})}var R2=1e3,z2=.25;function B2(e,t,n){let[r,i]=(0,Z.useState)(0),a=(0,Z.useRef)(0),o=(0,Z.useRef)(0);return(0,Z.useEffect)(()=>{a.current&&=(o.current=performance.now()-a.current,0)}),(0,Z.useEffect)(()=>{if(!n)return;let r=0,s=-1,c=0,l=n=>{if(r=iJ(l),a.current||n<c||lJ())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/z2-1),a.current=performance.now(),(0,Z.startTransition)(()=>i(e=>e+1)))};return r=iJ(l),()=>aJ(r)},[n,e,t]),(0,Z.useMemo)(()=>n?e.map(e=>t.includes(e.id)?{...e,dataset:e.source.snapshot(R2)}:e):e,[e,t,n,r])}function V2({engine:e,worksheet:t,mounts:n}){let r=e3(e),i=(0,Z.useSyncExternalStore)(r.store.subscribe,r.store.get),a=r.derived(),o=i.xRanges[t.id]??null,s=i.live.filter(e=>i.selection.includes(e.id)).length,c=e=>{let n=t.panelChartSettings[e];return n?.kind===`multiband`&&n.beacon?.enabled===!0},l=s>0&&t.panels.some(e=>e.kind!==`multiband`||s>1&&!c(e.id)),u=B2(i.live,i.selection,l),d=F0({worksheet:t,viewXRange:o,selectedIds:i.selection,selectedDatasets:a.selectedDatasets,liveConnections:u,mathChannels:a.channels,datasetOffsets:i.offsets,datasetColors:i.colors,datasetPalette:i.palette}),f=(0,Z.useRef)(lq()).current,p=(0,Z.useSyncExternalStore)(F2,I2),m=t.id,h=O2(e),g=i.licensed,_=i.live.find(e=>i.selection.includes(e.id))??null,v=e=>i.datasets.find(t=>t.id===e)??Object.values(a.laps).flatMap(e=>e.laps).find(t=>t.id===e);return(0,Q.jsx)(Q.Fragment,{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=E2(n,e,m);return(0,sq.createPortal)((0,Q.jsx)(K2,{mount:n,annotations:t.panelChartSettings[r.id]?.annotations,alarm:Ae(t.panelChartSettings[r.id]),onAnnotations:c.onAnnotations,onAnnotationToolEnd:c.onAnnotationToolEnd,onAnnotationSelect:c.onAnnotationSelect,render:a=>Y0({panel:r,settings:t.panelChartSettings[r.id],background:n.options.style?.background??t.panelChartBackgrounds[r.id]??null,styleToken:JSON.stringify([p,n.options.theme,n.options.style,X]),data:d,xKey:t.xKey,height:a,viewXRange:o,onViewXRangeChange:c.onViewXRangeChange,liveZoom:f,liveWindowSeconds:i.liveWindowSeconds,onLiveWindowChange:h,beaconLive:_,findDataset:v,shiftMode:s?H2(e,s.id,s.name):void 0,onContextMenu:c.onContextMenu,xyzRef:c.xyzRef}),licensed:g},n.key),n.element,n.key)})})}function H2(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 U2=[];function W2(e,t){e.data=t}function G2(e,t){e.status!==t&&(e.status=t,e.emitter.emit(`status`,t))}function K2({mount:e,render:t,licensed:n,annotations:r,alarm:i,onAnnotations:a,onAnnotationToolEnd:o,onAnnotationSelect:s}){let c=(0,Z.useRef)(null),[l,u]=(0,Z.useState)(0),d=!!e.options.debug,f=(0,Z.useRef)({renderStart:0,lastRenderMs:0,renders:0,data:null}).current;d&&(f.renderStart=performance.now()),(0,Z.useLayoutEffect)(()=>{d&&(f.lastRenderMs=performance.now()-f.renderStart,f.renders++)}),(0,Z.useLayoutEffect)(()=>{let e=c.current;if(!e)return;let t=()=>u(Math.max(120,Math.floor(e.clientHeight)));t();let n=new uJ(t);return n.observe(e),()=>n.disconnect()},[]);let{status:p,node:m,data:h}=t(l||400);f.data=h,(0,Z.useEffect)(()=>{W2(e,h)}),(0,Z.useEffect)(()=>{G2(e,p)});let{theme:g,style:_,className:v}=e.options,y={};return _?.background&&(y[`--chart-bg`]=_.background),_?.muted&&(y[`--chart-muted`]=_.muted),_?.grid&&(y[`--chart-grid`]=_.grid),_?.accent&&(y[`--accent`]=_.accent),(0,Q.jsxs)(`div`,{ref:c,onContextMenu:p===`ready`?void 0:t=>{t.preventDefault(),e.emitter.emit(`contextmenu`,{clientX:t.clientX,clientY:t.clientY})},className:v?`kymo-chart ${v}`:`kymo-chart`,"data-color-scheme":g,"data-status":p,style:y,children:[(0,Q.jsx)(bJ.Provider,{value:e.plotFrame.set,children:m}),p===`ready`&&i?(0,Q.jsx)(w2,{frame:e.plotFrame,alarm:i.alarm,axis:i.axis}):null,p===`ready`&&(r?.length||e.annotationTool)?(0,Q.jsx)(u2,{annotations:r??U2,tool:e.annotationTool,plotFrame:e.plotFrame,onChange:a,onToolEnd:o,onSelect:s}):null,d?(0,Q.jsx)(t2,{stats:f,host:c}):null,n===!1?(0,Q.jsx)(dq,{}):null]})}var q2=new WeakMap;function J2(e,t,n,r={}){let i=q2.get(e)??new Map;q2.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 jw(`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),$q(c);let m=n(p,r.mount),h=fq(),g=!1,_=()=>{g||(g=!0,i.delete(t),eJ(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 Y2(e){for(let t of[...q2.get(e)?.values()??[]])t.close()}Aw(),Ue(),oW(),Bw();var X2=12e3,Z2=100;function Q2(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 iW.add(n),n;for(let e=0;e<n.length;e++){let t=n[e];t-t!==0&&(n[e]=NaN)}return n}function $2(e,t){let n=Object.keys(t.columns);if(n.length===0)throw new jw(`no_columns`);let r=t.columns[n[0]].length;if(n.some(e=>t.columns[e].length!==r))throw new jw(`column_length_mismatch`);let i=new Map(n.map(e=>[e,Q2(t.columns[e],t.transfer)]));return e4(e,t.name,i,t.units??{})}function e4(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,Z2);t++)e.push(o.map(e=>{let r=n.get(e)[t];return r===r?String(r):``}).join(`,`));d=e.join(`
|
|
631
|
-
`),f=_w(d)}let p={id:e,name:t,schema:l,rawText:d,parseConfig:f,fromColumns:!0};if(s>1e6){let e=new
|
|
632
|
-
`))}return r}function
|
|
633
|
-
`}n.push(i)}return n}};function D4(e){let t=/^[=+\-@\t\r]/.test(e)?`'${e}`:e;return/[",\n\r]/.test(t)?`"${t.replace(/"/g,`""`)}"`:t}yW();var O4=512,k4=new WeakMap;function A4(e,t,n){let r=k4.get(e);r||k4.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 j4(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=FC(n.formula);if(!o.ok)continue;let{identifiers:s,functions:c}=IC(o.node);if(!s.every(e=>a.has(e)))continue;let l=c.some(e=>NC.includes(e)),u=Math.max(e.firstAbs,i-(l?O4:0)),d=new Map([mW,...s].map(t=>[t,e.range(t,u,r)])),{carry:f,keep:p}=A4(e,`${n.id}|${n.formula}`,u),m=HC(n,e=>d.get(e),mW,r-u,t,f);m.status===`ok`&&(e.writeComputed(n.name,n.units,i,m.values.subarray(i-u)),p())}}function M4(e,t){e.clearComputed(),k4.delete(e),j4(e,t,e.firstAbs)}GU(),BW(),yW(),GW(),YU(),tG();var N4=1e7,P4=512,F4=400,I4=4e3,L4=1e3;function R4(e,t){let n=new vW(t.capacity??N4,void 0,void 0,(t.maxMemoryMB??P4)*1024*1024);return{meta:e,buffer:n,source:new S4(()=>n),unsub:()=>{},status:`connecting`,error:null,lastFrameAt:Date.now(),lastColCount:0,recorder:null,schemas:new Map}}function z4(e,t,n=()=>({})){let r=new Map,i=e,a=[],o=[],s=``,c=()=>{let e=[];for(let t of r.values())t.lastColCount=t.buffer.columnNames.length,e.push({...t.meta,dataset:t.buffer.toDataset(F4),source:t.source,rowCount:t.buffer.size,status:t.status,error:t.error,recordingSince:t.recorder?.startedAt??null});a=e,t(a)},l=(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&&d(e,r)},u=(e,t)=>{let n=e.buffer.endAbs;e.buffer.pushColumns(t),e.recorder?.addColumns(t),t.t.length>0&&d(e,n)},d=(e,t)=>{j4(e.buffer,o,t),e.lastFrameAt=Date.now();let n=e.status===`stale`||e.status===`connecting`;n&&(e.status=`live`),(n||e.buffer.columnNames.length!==e.lastColCount)&&c()},f=e=>{let t=r.get(e);t&&(t.unsub(),r.delete(e),c())},p=setInterval(()=>{let e=Date.now(),t=!1;for(let n of r.values())n.status===`live`&&e-n.lastFrameAt>I4&&(n.status=`stale`,t=!0);t&&c()},L4);return{connections:()=>a,disconnect:f,startRecording(e){let t=r.get(e);!t||t.recorder||(t.recorder=new E4,c())},stopRecording(e){let t=r.get(e),n=t?.recorder;return!t||!n?null:(t.recorder=null,c(),{csv:n.toCsvParts(),rows:n.rows,name:t.meta.name,startedAt:n.startedAt})},setRelay(e){i=e},setMathChannels(e){let t=JSON.stringify(e.map(e=>[e.id,e.name,e.units,e.formula,e.enabled]));if(t!==s){s=t,o=e;for(let t of r.values())M4(t.buffer,e);r.size>0&&c()}},openLocal(e,t){let i=`local:${crypto.randomUUID()}`,a=R4({id:i,name:e,ownerName:`This page`,visibility:`private`,orgName:null},{...n(),...t});return r.set(i,a),c(),{id:i,push:e=>{r.get(i)===a&&l(a,Array.isArray(e)?e:[e])},pushColumns:e=>{r.get(i)===a&&u(a,e)},close:()=>f(i)}},async connect(e,t,a){if(r.has(e.id))return;let o=i&&e.relay_url?{...i,url:e.relay_url}:i;if(!o)throw new jw(`relay_unavailable`);let s=typeof t==`string`?await CW(OW(t).secret??t,e.salt):`keyFor`in t?e=>t.keyFor(e):t;if(typeof s!=`function`&&!await DW(s,e.key_check))throw new jw(`wrong_password`);let d=R4({id:e.id,name:e.name,ownerName:e.owner_name??``,visibility:e.visibility??`private`,orgName:e.org_name??null,projectName:e.project_name??null},{...n(),...a});r.set(e.id,d);let f=Promise.resolve();d.unsub=x4(o,e.id,t=>{let n=HW(s,t).catch(()=>null);f=f.then(async()=>{try{let t=await n;if(!t||r.get(e.id)!==d)return;if(t.kind===5){let e=KW(t.plaintext);d.schemas.set(e.id,e);return}if(t.kind===4){let e=await JW(t.plaintext,d.schemas);e&&!e.historical&&u(d,e.block);return}if(t.kind===3)return u(d,KU(t.plaintext));if(t.kind!==2)return;let i=UU(t.plaintext);l(d,Array.isArray(i?.frames)?i.frames:[])}catch{}})},e=>{e===`subscribed`?(d.status=`live`,d.lastFrameAt=Date.now()):e===`error`&&(d.status=`error`,d.error=`connection_error`),c()}),c()},dispose(){clearInterval(p);for(let e of r.values())e.unsub();r.clear(),a=[]}}}var B4=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}},V4={maxChartsPerWorksheet:null,maxChannelsPerChart:null,maxWorksheets:null,maxMathChannels:null,canImportExportWorkspaces:!0};Aw(),yW();var H4=[],U4=[`#a78bfa`,`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#94a3b8`];function W4(e=`ET`){return{id:crypto.randomUUID(),name:`Worksheet`,panels:[],panelChartSettings:{},panelChartBackgrounds:{},xKey:e}}function G4(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(Fe({...e,name:a,source:`workbook`}))}return{channels:i,rename:r}}function K4(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 q4(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 J4(e,t,n){if(!e||!t)return A();let{min:r,max:i}=HG(e.rows,t);if(!Number.isFinite(r)||!Number.isFinite(i))return A();let a=Math.max(1,Math.round(WG(i-r||1,6)));return{...n,scaleMin:String(Math.floor(r)),scaleMax:String(Math.ceil(i)),majorStep:String(a),minorStep:``}}function Y4(e,t){let n=t.includes(e.xKey)?e.xKey:t.includes(`ET`)?`ET`: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:B();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:V(U4[2]),a=t.includes(i.xyXCol)?i.xyXCol:t[0],o=t.includes(i.xyYCol)&&i.xyYCol!==t[0]?i.xyYCol:t.length>1?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:H(4),a=t.includes(i.xyzXCol)?i.xyzXCol:t[0],o=t.length>1?t[1]:``,s=t.includes(i.xyzYCol)&&i.xyzYCol!==t[0]?i.xyzYCol:t.length>1?t[1]:t[0],c=t.includes(i.xyzZCol)&&i.xyzZCol!==t[0]&&i.xyzZCol!==o?i.xyzZCol:t.length>2?t[2]:t[0];r[n.id]={...i,kind:`xyzmesh`,xyzXCol:a,xyzYCol:s,xyzZCol:c}}}return{...e,xKey:n,panelChartSettings:r}}function X4(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 Z4(){return typeof document>`u`?`dark`:aK(null)}function Q4(e={}){let t={...e},n=!1,r=W4(),i=o4({datasets:[],selection:[],worksheets:[r],activeWorksheetId:r.id,xRanges:{},offsets:{},colors:{},liveWindowSeconds:15,live:[],mathChannels:[],limits:{...V4,...t.limits},palette:nK(t.palette,Z4()),importing:0,licensed:null,history:{canUndo:!1,canRedo:!1}}),a=fq(),o=()=>{let e=nK(t.palette,Z4());i.set(t=>t.palette.join()===e.join()?t:{...t,palette:e})},s=typeof document>`u`?()=>{}:oK(null,o),c=c4(),l=()=>{if(n)throw new jw(`disposed`)},u=e=>{throw a.emit(`limit`,{reason:e}),new jw(`limit_reached`,{reason:e})},d=()=>i.get(),f=(e,t)=>{let n=d().limits.maxChannelsPerChart,r=UG(t);n!==null&&r>n&&r>UG(e)&&u(`channels-per-chart`)},p=s4((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)),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??H4,layout:t.rect}),g=s4((e,t)=>e.map(e=>({id:e.id,name:e.name,xKey:e.xKey,xRange:t[e.id]??null,charts:e.panels.map(t=>h(e,t))}))),_=s4((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:eK(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,laps:c?c.laps.map((e,i)=>({id:e.id,name:e.name,value:c.values[i],unit:c.unit,isTime:c.isTime,color:eK(n,e.id,s(e.id,i),o),offset:r[e.id]??0,selected:t.includes(e.id)})):null,selected:c?u===0?!1:u===l.length?!0:`partial`:t.includes(e.id)}})}),b=s4((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,status:e.status,error:e.error,rowCount:e.rowCount,selected:t.includes(e.id),color:eK(n,e.id,a.includes(e.id)?r+a.indexOf(e.id):o,i),customColor:e.id in n,recordingSince:e.recordingSince}))}),x=s4(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),activeWorksheetId:e.activeWorksheetId,mathChannels:t.channels,live:b(e.live,e.selection,e.colors,t.selectedDatasets.length,e.palette),liveWindowSeconds:e.liveWindowSeconds,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}}),S=(e,t)=>e===t||e.length===t.length&&e.every((e,n)=>e===t[n]||JSON.stringify(e)===JSON.stringify(t[n])),C=new B4({limit:100,mergeMs:500,now:()=>Date.now(),equals:(e,t)=>e.liveWindowSeconds===t.liveWindowSeconds&&S(e.worksheets,t.worksheets)&&S(e.channels,t.channels)}),w=!0,T=0,E=e=>{T++;try{e()}finally{T--}},O=e=>[e.worksheets,e.mathChannels,e.liveWindowSeconds],A=[],j=()=>{let e=d();return{worksheets:e.worksheets,channels:e.mathChannels.filter(e=>e.source===`workbook`),liveWindowSeconds:e.liveWindowSeconds,activeWorksheetId:e.activeWorksheetId}},M=()=>i.set(e=>e.history.canUndo===C.canUndo&&e.history.canRedo===C.canRedo?e:{...e,history:{canUndo:C.canUndo,canRedo:C.canRedo}}),N=()=>{if(w)return;let e=O(d());e.every((e,t)=>e===A[t])||(A=e,T?C.rebase(j()):C.observe(j()),M())},P=()=>{A=O(d()),C.clear(j()),M()},F=e=>{w=!0;let t;try{t=e()}finally{w=!1}return P(),t},I=()=>x(d());i.subscribe(()=>{N(),a.emit(`change`,I())});let L=e=>{let t=d(),n=t.worksheets.find(n=>n.id===(e??t.activeWorksheetId));if(!n)throw new jw(`not_found`,{worksheetId:e});return n},R=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 jw(`not_found`,{chartId:e})},z=(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}),B=(e,t)=>{let{ws:n}=R(e);z(n.id,n=>({...n,panelChartSettings:{...n.panelChartSettings,[e]:t(n.panelChartSettings[e])}}))},V=e=>i.set(t=>e.length===t.selection.length&&e.every((e,n)=>e===t.selection[n])?t:{...t,selection:e,xRanges:{}}),H=new Set,U=z4(t.live?.relay,e=>{let t=e.map(e=>e.id),n=t.filter(e=>!H.has(e)),r=[...H].filter(e=>!t.includes(e));if(H=new Set(t),i.set(t=>({...t,live:e})),r.length&&V(d().selection.filter(e=>!r.includes(e))),n.length){let e=d().selection,t=n.filter(t=>!e.includes(t));t.length&&V([...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)||E(()=>z(t.id,e=>({...e,xKey:mW})))}},()=>({capacity:t.live?.capacity,maxMemoryMB:t.live?.maxMemoryMB})),W=s4((e,t)=>e.filter(e=>t.some(t=>rw([e],t.panelChartSettings,t.xKey).length>0))),ee=()=>U.setMathChannels(W(p(d().mathChannels,d().limits.maxMathChannels),d().worksheets));ee(),i.subscribe(ee);let te=e=>{i.set(t=>({...t,datasets:[...t.datasets,e]})),V([...d().selection,e.id]);let t=VG(e.schema);t.length&&E(()=>i.set(e=>({...e,worksheets:e.worksheets.map(e=>Y4(e,t))})))},ne=Promise.resolve(),G=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 jw(`import_vetoed`);let{signal:s}=r;i.set(e=>({...e,importing:e.importing+o.length}));let c=ne.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 lL(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 BG({main:t,companions:i.companions,format:i.format.id},{priorInMemoryValues:kI(d().datasets),signal:s,onProgress:e=>a.emit(`import`,{file:t.name,phase:`progress`,fraction:e}),chooseChannels:r.chooseChannels,pickChannels:r.pickChannels}):[await OI(crypto.randomUUID(),t,d().datasets)??await EI(crypto.randomUUID(),t,q4,void 0,kI(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 jw(`cancelled`)}for(let t of o)te(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 jw&&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 ne=c.catch(()=>void 0),c},re=()=>setTimeout(()=>{n||N2(Ke)},0),ie=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}}),V(d().selection.filter(e=>!t(e))),n.length>0&&re()},ae=async(e,t)=>{let[n,...r]=await BG({main:new File(e.chunks,`${e.name}.krc`),companions:[],format:`krc`,keys:e.keys},{priorInMemoryValues:t});for(let e of r)e.source.dispose();return{...n,file:void 0,name:e.name,info:n.info&&{...n.info,startTime:e.startTime??n.info.startTime,meta:{...n.info.meta,recordingId:e.recordingId}}}},oe={importFiles:G,warmImport(e={}){l(),OG(!!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 jw(`not_found`,{datasetId:e});if(!t.info?.combined||!(t.file instanceof File))throw new jw(`invalid_argument`,{reason:`only a combined multi-rate import can be split`});let n=await BG({main:t.file,companions:t.companions??[],format:t.info.importer},{priorInMemoryValues:kI(d().datasets.filter(t=>t.id!==e)),selection:t.info.selection,split:!0});ie([e]);for(let e of n)te(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 jw(`not_found`,{datasetId:e});if(!n.info||!(n.file instanceof File))throw new jw(`invalid_argument`,{reason:`only binary imports have channels to choose`});try{let r=await BG({main:n.file,companions:n.companions??[],format:n.info.importer},{priorInMemoryValues:kI(d().datasets.filter(t=>t.id!==e)),initial:n.info.selection,chooseChannels:t,pickChannels:!0});ie([e]);for(let e of r)te(e);return r.map(e=>e.id)}catch(e){if(e instanceof jw&&e.code===`cancelled`)return null;throw e}},async combine(e){l();let t=d().datasets.find(t=>t.id===e);if(!t)throw new jw(`not_found`,{datasetId:e});let n=t.info?.splitKey;if(!n||!(t.file instanceof File))throw new jw(`invalid_argument`,{reason:`only datasets split from one file can be combined`});let r=d().datasets.filter(e=>e.info?.splitKey===n),i=await BG({main:t.file,companions:t.companions??[],format:t.info.importer},{priorInMemoryValues:kI(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 jw(`invalid_argument`,{reason:`these groups have no common time base`})}return ie(r.map(e=>e.id)),te(i[0]),i[0].id},async openRecording(e){l();let t=await ae(e,kI(d().datasets));return te(t),t.id},async reopenRecording(e,t){l();let n=d().datasets.find(t=>t.id===e);if(!n)throw new jw(`not_found`,{datasetId:e});let r=await ae(t,kI(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),re()},addColumns(e){l();let t=$2(crypto.randomUUID(),e);return te(t),t.id},replaceColumns(e,t,n={}){l();let r=d().datasets.find(t=>t.id===e);if(!r)throw new jw(`not_found`,{datasetId:e});let a=r4(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 jw(`not_found`,{datasetId:e});let a=t4(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 CI(crypto.randomUUID(),t,e);return te(n),n.id},remove(e){l(),ie([e])},clear(){l(),ie(d().datasets.map(e=>e.id))},async configure(e,t){l();let n=d().datasets.find(t=>t.id===e);if(!n)throw new jw(`not_found`,{datasetId:e});if(t.parseConfig&&(n.kind!==`memory`||!n.parseConfig))throw new jw(`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 jw(`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?cK(n.data.rows,r.channel):[],l=r&&t.selectCycles===`best`?uK(c.map(e=>lK(n.data.rows,e,r.metric,r.stat))):null,u=l===null?c.map((t,n)=>fK(e,n)):[fK(e,l)];V(o?c.length>0?[...s,...u]:[...s,e]:s)}let r=t.parseConfig;if(!r)return;let a=(()=>{try{let e=vw(mw(n.rawText??``),r.headerRow);return n.data.columnNames.length===e.length&&n.data.columnNames.every((t,n)=>t===e[n])}catch{return!1}})();if(hw(r,n.parseConfig)&&a)return;let o=n.fromColumns?a4(n):n.rawText??``,s=await Iw(n.file?{file:n.file,config:r}:{rawText:o,config:r}),c=new Xw(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),re();let p=m().selectedDatasets,h=new Set(p.flatMap(e=>e.data.columnNames)),g=s.columnNames.filter(e=>Cw(s.rows,e)),_=g.find(e=>e===`ET`)??g[0];E(()=>i.set(e=>({...e,worksheets:e.worksheets.map(e=>X4(!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(),V([...e])},toggle(e){l();let t=d().selection,n=m().laps[e];if(n){let e=n.laps.map(e=>e.id);V(e.every(e=>t.includes(e))?t.filter(t=>!e.includes(t)):[...t,...e.filter(e=>!t.includes(e))]);return}V(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);V([...d().datasets.flatMap(t=>e[t.id]?e[t.id].laps.map(e=>e.id):[t.id]),...t])},deselectAll(){l(),V([])},raw(e){let t=d().datasets.find(t=>t.id===e);if(!t)throw new jw(`not_found`,{datasetId:e});return{get rawText(){return t.kind===`memory`&&t.fromColumns?a4(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=HG(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.xBoundsSync(e);if(Number.isFinite(t.x0)&&Number.isFinite(t.x1))return{min:t.x0,max:t.x1}}let i=se(e);if(!i)return null;let a=HG(i.rows,e);return Number.isFinite(a.min)&&Number.isFinite(a.max)?a:null}},se=(e,t=L().xKey)=>{let n=m();if(!n.merged)return null;if(!n.channels.find(t=>t.name===e))return n.merged;let r=nw(n.merged,n.channels,t);return{...n.merged,columnNames:[...n.merged.columnNames,...r.ok.map(e=>e.name)],rows:r.rows}},ce=(e,t,n)=>m().selectedLive.length>0?{...n,scaleMin:``,scaleMax:``,majorStep:``,minorStep:``}:J4(se(e,t),e,n),le={fromFileList:e=>UK(Array.from(e)),async fromDataTransfer(e){return WK(Array.from(e.items??[]).map(e=>e.webkitGetAsEntry?.()).filter(e=>!!e))},canPick:GK,pick:KK,tree:(e,t)=>HK(e,t),isImportable:VK},ue={add(e=`Worksheet`){l();let t=d(),n=t.limits.maxWorksheets;n!==null&&t.worksheets.length>=n&&u(`worksheets`);let r={...W4(L().xKey||`ET`),name:e};return i.set(e=>({...e,worksheets:[...e.worksheets,r],activeWorksheetId:r.id})),r.id},rename(e,t){l(),L(e),z(e,e=>e.name===t?e:{...e,name:t})},remove(e){l();let t=d();if(L(e),t.worksheets.length<=1)throw new jw(`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(),L(e),i.set(t=>t.activeWorksheetId===e?t:{...t,activeWorksheetId:e,xRanges:{...t.xRanges,[e]:null}})},setXKey(e,t){l(),L(e),z(e,e=>X4({...e,xKey:t},e=>e!==t)),i.set(t=>({...t,xRanges:{...t.xRanges,[e]:null},offsets:{}}))}},de={mount(e,t,n){return l(),M2(Ke,e,t,n)},openWindow(e,t){return l(),R(e),J2(Ke,e,(t,n)=>M2(Ke,e,t,n),t)},setFonts(e){e.sans&&(X.sans=e.sans),e.mono&&(X.mono=e.mono),N2(Ke)},kinds:()=>l4,label:d4,add(e,t={}){if(l(),!l4.some(t=>t.kind===e))throw new jw(`invalid_argument`,{kind:e});let n=L(t.worksheetId),r=d().limits.maxChartsPerWorksheet;r!==null&&n.panels.length>=r&&u(`charts-per-worksheet`);let i={...D(e,n.panels),...t.title?{title:t.title}:{}};t.layout&&(i.rect={...t.layout});let a=Ne([i],{},U4[2],4)[i.id],o=a,s=m().numericColumns;if(s.length&&(o.kind===`multiband`||o.kind===`xyscatter`||o.kind===`xyzmesh`)&&(o=Y4({...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??ce(o.xyXCol,n.xKey,o.xyXScale),xyYScale:e.xyYScale??ce(o.xyYCol,n.xKey,o.xyYScale)}}return f(a,o),z(n.id,e=>({...e,panels:t.layout?[...e.panels,i]:k([...e.panels,i]),panelChartSettings:{...e.panelChartSettings,[i.id]:o}})),i.id},remove(e){l();let{ws:t}=R(e);z(t.id,t=>{let n={...t.panelChartSettings},r={...t.panelChartBackgrounds};return delete n[e],delete r[e],{...t,panels:k(t.panels.filter(t=>t.id!==e)),panelChartSettings:n,panelChartBackgrounds:r}})},rename(e,t){l();let{ws:n}=R(e),r=t?.trim()||void 0;z(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}=R(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:ce(e.xyXCol,n.xKey,r.xyXScale)}),typeof e.xyYCol==`string`&&e.xyYCol!==r.xyYCol&&!(`xyYScale`in e)&&(i={...i,xyYScale:ce(e.xyYCol,n.xKey,r.xyYScale)})}f(r,i),B(e,()=>i)},replaceSettings(e,t){l();let{ws:n,panel:r}=R(e);if(t.kind!==r.kind)throw new jw(`invalid_argument`,{reason:`settings kind mismatch`});f(n.panelChartSettings[e],t),B(e,()=>t)},setBackground(e,t){l();let{ws:n}=R(e);z(n.id,n=>({...n,panelChartBackgrounds:{...n.panelChartBackgrounds,[e]:t}}))},addAnnotation(e,t){l(),R(e);let n=v({...t,id:t.id||crypto.randomUUID()});if(!n)throw new jw(`invalid_argument`,{reason:`not a valid annotation`});return B(e,e=>({...e,annotations:[...(e.annotations??[]).filter(e=>e.id!==n.id),n]})),n.id},updateAnnotation(e,t,n){l();let r=(R(e).ws.panelChartSettings[e]?.annotations??[]).find(e=>e.id===t);if(!r)throw new jw(`not_found`,{annotationId:t});let i=v({...r,...n,id:r.id,kind:r.kind});if(!i)throw new jw(`invalid_argument`,{reason:`not a valid annotation`});B(e,e=>({...e,annotations:(e.annotations??[]).map(e=>e.id===i.id?i:e)}))},removeAnnotation(e,t){l(),R(e),B(e,e=>({...e,annotations:(e.annotations??[]).filter(e=>e.id!==t)}))},setAnnotations(e,t){l(),R(e);let n=y(t)??[];B(e,e=>({...e,annotations:n}))},setLayout(e,t){l();let{ws:n}=R(e);z(n.id,n=>({...n,panels:n.panels.map(n=>n.id===e?{...n,rect:{...t}}:n)}))},setLayouts(e,t){l(),z(e,e=>({...e,panels:e.panels.map(e=>t[e.id]?{...e,rect:{...t[e.id]}}:e)}))},autoLayout(e){l(),z(L(e).id,e=>({...e,panels:k(e.panels)}))},get(e){let{ws:t,panel:n}=R(e);return h(t,n)},list(e){let t=L(e);return t.panels.map(e=>h(t,e))},async addSeries(e,t){l();let{ws:n}=R(e),r=n.panelChartSettings[e];if(!r||r.kind!==`multiband`)throw new jw(`invalid_argument`,{reason:`not a multiband chart`});let i=d().limits.maxChannelsPerChart;i!==null&&UG(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=Pe(),f={id:c,column:s,color:U4[r.series.length%U4.length],bandFromPct:0,bandToPct:100,scaleMin:0,scaleMax:1,yMajorStep:0,yMinorStep:0};return B(e,e=>e.kind===`multiband`?{...e,series:[...e.series,f]}:e),await de.autoScaleSeries(e,c),c},async updateSeries(e,t,n){l();let{ws:r}=R(e),i=r.panelChartSettings[e],a=i&&i.kind===`multiband`?i.series.find(e=>e.id===t):void 0;if(!a)throw new jw(`not_found`,{seriesId:t});B(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 de.autoScaleSeries(e,t)},removeSeries(e,t){l(),B(e,e=>e.kind===`multiband`?{...e,series:e.series.filter(e=>e.id!==t)}:e)},reorderSeries(e,t){l(),B(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}=R(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 oe.columnBounds(a.column);!o||n||B(e,e=>e.kind===`multiband`?{...e,series:e.series.map(e=>e.id===t?{...e,scaleMin:o.min,scaleMax:o.max}:e)}:e)}},fe={setXRange(e,t){l();let n=L(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){fe.setXRange(null,e)},setLiveWindow(e){l(),i.set(t=>t.liveWindowSeconds===e?t:{...t,liveWindowSeconds:e})}},pe={create(e){l();let n=d(),r=n.limits.maxMathChannels;r!==null&&n.mathChannels.length>=r&&u(`math-channels`);let o=Fe(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 jw(`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 jw(`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 ow(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:()=>iw(d().mathChannels),preview(e,t){let n=m();return n.merged?RC(e,n.merged,L(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}})}},me={openLocal(e,t){return l(),U.openLocal(e,t)},async connect(e,t,n){l(),await U.connect(e,t,n)},startRecording(e){l(),U.startRecording(e)},stopRecording(e){return l(),U.stopRecording(e)},rowCount(e){return U.connections().find(t=>t.id===e)?.source.size()??0},disconnect(e){l(),U.disconnect(e),V(d().selection.filter(t=>t!==e))}},he=()=>{d().limits.canImportExportWorkspaces||u(`workspaces-io`)},ge=async e=>{if(e instanceof Blob)try{return JSON.parse(await e.text())}catch{throw new jw(`bad_file`)}if(typeof e==`string`)try{return JSON.parse(e)}catch{throw new jw(`bad_file`)}return e},_e=async e=>e instanceof File?e:new File([JSON.stringify(await ge(e))],`import.json`,{type:`application/json`}),ve=e=>e.replace(/[^\w.-]+/g,`_`),ye=e=>new Blob([JSON.stringify(e,null,2)],{type:`application/json`}),be=e=>{let t=Me(e.panelChartSettings,U4[2],4),n={};for(let r of e.panels)t[r.id]?.kind===r.kind&&(n[r.id]=t[r.id]);return{...e,panelChartSettings:Ne(e.panels,n,U4[2],4)}},xe=e=>{let t=m().numericColumns;return t.length?Y4(e,t):e},Se=(e,t=0)=>{let n=d().limits.maxWorksheets,r=(n===null?e:e.slice(0,Math.max(1,n))).map(e=>xe(be(e))),a=r[Math.min(t,r.length-1)];i.set(e=>({...e,worksheets:r,activeWorksheetId:a.id,xRanges:{}}))},Ce=(e,t)=>{let n=L(t),r=d().limits.maxChartsPerWorksheet;r!==null&&n.panels.length>=r&&u(`charts-per-worksheet`);let i=d().limits.maxChannelsPerChart;i!==null&&UG(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 z(n.id,t=>({...t,panels:k([...t.panels,o]),panelChartSettings:{...t.panelChartSettings,[a]:e.settings},panelChartBackgrounds:e.background===null?t.panelChartBackgrounds:{...t.panelChartBackgrounds,[a]:e.background}})),a},we=()=>{let e=d();return TK({worksheets:e.worksheets,activeWorksheetId:e.activeWorksheetId,channels:W(p(e.mathChannels,e.limits.maxMathChannels),e.worksheets),liveWindowSeconds:e.liveWindowSeconds,laps:e.datasets.find(e=>e.beacon)?.beacon??null})},Te=e=>{if(e.worksheets.length===0)throw new jw(`bad_workspace`,{errors:e.errors});let{channels:t,rename:n}=G4(d().mathChannels,e.mathChannels);Se(n.size?e.worksheets.map(e=>K4(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}));let r=e.laps;if(r)for(let e of d().datasets)e.kind!==`memory`||e.beacon||!e.data.columnNames.includes(r.channel)||oe.configure(e.id,{beacon:r}).catch(e=>a.emit(`error`,{error:e,context:`io.openWorkbook`}));return{worksheets:e.worksheets.length,errors:e.errors}},Ee=e=>{if(e===null)return;let t=e.worksheets.map(xe);w=!0;try{i.set(n=>{let r=t=>e.worksheets.some(e=>e.id===t);return{...n,worksheets:t,activeWorksheetId:r(n.activeWorksheetId)?n.activeWorksheetId:r(e.activeWorksheetId)?e.activeWorksheetId:e.worksheets[0].id,xRanges:Object.fromEntries(Object.entries(n.xRanges).filter(([e])=>r(e))),mathChannels:[...n.mathChannels.filter(e=>e.source!==`workbook`),...e.channels],liveWindowSeconds:e.liveWindowSeconds}})}finally{w=!1}A=O(d()),C.rebase(j()),M()},De={undo(){l(),Ee(C.undo())},redo(){l(),Ee(C.redo())},clear(){l(),P()}},Oe={hasWork:()=>IK(d().worksheets),exportWorksheet(e){l(),he();let t=L(e),n=EK(t);return{json:n,blob:ye(n),filename:`${ve(t.name||`worksheet`)}.json`}},exportChart(e){l(),he();let{ws:t,panel:n}=R(e),r=DK(n,t.panelChartSettings[e],t.panelChartBackgrounds[e]??null);return{json:r,blob:ye(r),filename:`${ve(n.title?.trim()||n.kind)}.json`}},parseFile:e=>zK(e),exportWorkspace(){l(),he();let e=we();return{json:e,blob:ye(e),filename:`kymoscope-workspace-${new Date().toISOString().slice(0,10)}.json`}},async exportWorkspaceEncrypted(e){l(),he();let t=typeof e==`string`?await hK(we(),e):await gK(we(),e);return{json:t,blob:ye(t),filename:`kymoscope-workbook-${new Date().toISOString().slice(0,10)}.kymo`}},async importWorkspace(e,t={}){l(),he();let n=await ge(e);return _K(n)&&(n=await bK(n,t)),F(()=>Te(FK(n)))},toWorkbook:we,openWorkbook(e){return l(),F(()=>Te(FK(e)))},async importWorksheet(e){l(),he();let t=d();t.limits.maxWorksheets!==null&&t.worksheets.length>=t.limits.maxWorksheets&&u(`worksheets`);let n=await zK(await _e(e));if(n.type!==`worksheet`)throw new jw(`bad_file`,{found:n.type});let r=xe(be(n.worksheet));return i.set(e=>({...e,worksheets:[...e.worksheets,r],activeWorksheetId:r.id})),r.id},async importChart(e,t){l(),he();let n=await zK(await _e(e));if(n.type!==`chart`)throw new jw(`bad_file`,{found:n.type});return Ce(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(be):[W4()];F(()=>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(),F(()=>{ie(d().datasets.map(e=>e.id));let e=W4();i.set(t=>({...t,worksheets:[e],activeWorksheetId:e.id,xRanges:{},offsets:{},colors:{},mathChannels:t.mathChannels.filter(e=>e.source!==`workbook`)}))})}},ke={merged(e){let t=m();if(!t.merged||t.channels.length===0)return t.merged;let n=nw(t.merged,t.channels,L(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}},Ae=typeof location<`u`?location.hostname:``,je=t.license,Ie=t.licenseKey,Le=!1,Re={},ze=e=>{n||i.set(t=>({...t,licensed:e}))},Be=(e,t,n)=>{clearTimeout(Re[e]);let r=Math.max(0,t-Date.now()),i=r>2**31-1;Re[e]=setTimeout(()=>{i?Be(e,t,n):n()},i?2**31-1:r)},Ve=e=>Be(`renew`,e,()=>void Ue()),He=e=>Be(`expiry`,e*1e3+1e3,()=>{QK(Ie,Ae).then(e=>{n||ze(e.ok)})});async function Ue(){let e=36e5,t,r=null,i;try{t=await Promise.race([je.get(),new Promise((e,t)=>{i=setTimeout(()=>t(Error(`timeout`)),3e4)})]),r=await QK(t,Ae)}catch{}finally{clearTimeout(i)}if(n)return!1;if(r?.ok)return Ie=t,Le=!0,ze(!0),He(r.exp),Ve(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 QK(Ie,Ae);return n?!1:(ze(a.ok),Ve(Date.now()+e),a.ok)}let We=!je||t.licenseKey?QK(t.licenseKey,Ae).then(e=>(e.ok||console.warn(`[kymoscope] license ${e.reason}: showing attribution`),!Le&&!n&&(ze(e.ok),e.ok&&je&&He(e.exp)),e.ok)):null,Ge=je?Ue():We;w=!1,P();let Ke={getState:I,subscribe(e){return i.subscribe(e)},on:a.on,licensed:Ge,isLicensed:()=>d().licensed,setOptions(e){if(l(),t={...t,...e},e.live&&U.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:oe,folders:le,worksheets:ue,charts:de,view:fe,mathChannels:pe,live:me,io:Oe,history:De,data:ke,dispose(){if(!n){n=!0,clearTimeout(Re.renew),clearTimeout(Re.expiry),s(),Y2(Ke),P2(Ke),U.dispose();for(let e of d().datasets)e.source.dispose().catch(()=>void 0);a.clear()}}};return $4.set(Ke,{store:i,derived:m,live:U}),Ke}var $4=new WeakMap;function e3(e){let t=$4.get(e);if(!t)throw new jw(`invalid_argument`,{reason:`not a Kymoscope engine`});return t}return t.CHART_KINDS=l4,t.KymoscopeError=jw,t.chartLabel=d4,t.createEngine=Q4,t.verifyLicense=QK,t})({});
|
|
627
|
+
`),A=(0,Z.useMemo)(()=>{let e=i.filter(e=>e.kind!==`memory`).flatMap(e=>VG(e.schema));return e.length?e:null},[i]),j=(0,Z.useMemo)(()=>i.some(e=>e.kind!==`memory`)||!g&&i.some(e=>e.data.rows.length>C0),[i,g]),M=(0,Z.useMemo)(()=>{if(j||i.length===0)return null;let e=f.connections.filter(e=>r.includes(e.id));return e.length===1?{conn:e[0],keySuffix:`__${i.length}`,offset:o[e[0].id]??0}:null},[j,i,f.connections,r,o]),N=(0,Z.useMemo)(()=>{if(!g||i.length===0||j)return null;let e=i.map((e,t)=>{let n=e.data.rows;return{rows:n.length>0&&typeof n[0][d]==`number`?n:D[t]??n,offset:o[e.id]??0}});if(!M)for(let t of f.connections)r.includes(t.id)&&e.push({rows:t.dataset.rows,offset:o[t.id]??0});return M0(e,d)},[g,i,j,D,o,d,f.connections,r,M]),P=S&&`okByPart`in S?S.okByPart:void 0,F=(0,Z.useMemo)(()=>{if(!j)return[];let e=w.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:T?`__${t}`:``,xOffset:o[e.id]??0,key:`${e.id}|${T?t:``}`}));return w.forEach((t,n)=>{let r=P?.[n],i=D[n];`live`in t&&t.live||!r?.length||!i||e.push({...e[n],live:!1,source:k0(i,r,d),columnSet:new Set([d,...r]),key:`${e[n].key}|channels`})}),e},[j,w,T,o,P,D,d]),I=(0,Z.useMemo)(()=>{let e=S?.parts??(C?[C]:[]),t=new Set;for(let n of e)for(let e of y0(n.columnNames,n.rows))t.add(e);let n=C?C.columnNames.filter(e=>t.has(e)):[],r=[...new Set(A?[...n,...A]:n)];if(k===``)return r;let i=new Set(r),a=k.split(`
|
|
628
|
+
`).filter(e=>!i.has(e));return a.length?[...r,...a]:r},[O,k,A]),L=(0,Z.useMemo)(()=>{let e=[];for(let t of l){if(t.kind!==`multiband`)continue;let n=u[t.id],r=n&&n.kind===`multiband`?n.series:[];e.push([t.id,[...new Set(r.map(e=>e.column).filter(e=>e!==d))]])}return JSON.stringify(e)},[l,u,d]),R=(0,Z.useMemo)(()=>{let e={};if(!C||j)return e;for(let[t,n]of JSON.parse(L)){let r=[];if(n.length>0)if(!T)r.push(tW(C.rows,d,n,C0));else{let e=Math.max(1,Math.floor(C0/w.length));for(let t=0;t<w.length;t++){let i=w[t];if(M&&`live`in i&&i.live)continue;let a=D[t]??i.data.rows;r.push(tW(a,d,n,e,`__${t}`,o[i.id]??0))}}e[t]=r}return e},[C,L,d,T,w,o,D,M,j]),z=(0,Z.useMemo)(()=>{let e={};if(!C)return e;for(let t of l){if(t.kind!==`multiband`)continue;let n=u[t.id],r=(n&&n.kind===`multiband`?n.series:[]).filter(e=>e.column!==d),i=n&&n.kind===`multiband`?n.layout:`overlay`,a=e=>j0(e,i),o;if(!T)o=a(r);else{let e=a(r);o=[];for(let t=0;t<w.length;t++){let n=eK(s,w[t].id,t,c);for(let r of e)o.push({...r,id:`${r.id}__${t}`,column:`${r.column}__${t}`,color:n})}}let l=R[t.id]??[],f=T&&n?.kind===`multiband`&&n.envelope?r.flatMap(e=>{let t=g0(l.flatMap((t,n)=>{let r=t.cols.get(`${e.column}__${n}`);return r?[{x:t.x,y:r}]:[]}),D0);return t?[{seriesId:e.id,color:e.color,...t}]:[]}):void 0;e[t.id]={effectiveSeries:o,points:l,envelopes:f}}return e},[C,l,u,d,T,w,s,c,R]),B=(0,Z.useMemo)(()=>{let e={pts:{},colorMeta:{},datasetColors:{}};if(!C)return e;let t={},r={},i={},a=E0,o=w.map((e,t)=>({id:e.id,rows:D[t]??p[e.id]??e.data.rows,full:a(e)})),f={id:`single`,rows:C.rows,full:w.length===1?a(w[0]):void 0};for(let e of l){if(e.kind!==`xyscatter`)continue;let a=u[e.id];if(!a||a.kind!==`xyscatter`)continue;let{xyXCol:l,xyYCol:p}=a;if(!l||!p){t[e.id]={length:0,x:[],y:[]};continue}if(T){let{cols:r,colors:a}=RY(o,l,p,{xKey:d,viewXRange:n,colorOverrides:s,palette:c});t[e.id]=r,i[e.id]=a;continue}let m=LY(f,l,p,{xKey:d,viewXRange:n,colorCol:a.xyColorCol||void 0});t[e.id]=m?.cols??{length:0,x:[],y:[]},m?.color&&(r[e.id]=m.color)}return{pts:t,colorMeta:r,datasetColors:i}},[C,l,u,n,d,T,w,p,s,c,D]),V=(0,Z.useRef)(new Map),H=(0,Z.useMemo)(()=>{let e={};if(!C)return e;let t={length:0,x:[],y:[],z:[]},{rows:r}=C,i=E;for(let a of l){if(a.kind!==`xyzmesh`)continue;let o=u[a.id];if(!o||o.kind!==`xyzmesh`)continue;if(o.xyzMode===`matrix`){let n=(o.xyzColumns??[]).flatMap(e=>{let t=jY(r,e,i);return t?[t]:[]}),s=n[0]?.length??0,c=n.length;if(s<2||c<2){e[a.id]={points:t};continue}let l=V.current.get(a.id);l?.length!==s*c&&V.current.set(a.id,l=new Float32Array(s*c)),n.forEach((e,t)=>l.set(e.length===s?e:e.subarray(0,s),t*s));let u=jY(r,d,i),f=u&&!(o.xyzColumns??[]).includes(d)&&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:f,y:[0,c-1]}};continue}let{xyzXCol:s,xyzYCol:c,xyzZCol:l}=o,f=s?jY(r,s,i):void 0,p=c?jY(r,c,i):void 0,m=l?jY(r,l,i):void 0;if(!f||!p||!m){e[a.id]={points:t};continue}let h=n?jY(r,d,i):void 0;if(!n||!h){e[a.id]={points:{length:Math.min(f.length,p.length,m.length),x:f,y:p,z:m}};continue}let[g,_]=n,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]=f[e],b[t]=p[e],x[t]=m[e],t++);e[a.id]={points:{length:v,x:y,y:b,z:x}}}return e},[C,l,u,n,d,E]),U=(0,Z.useMemo)(()=>{let e={};if(!C)return e;for(let t of l){if(t.kind!==`histogram`)continue;let n=u[t.id];e[t.id]=n?.kind===`histogram`&&n.histColumn&&MY(C.rows,n.histColumn,E)||new Float64Array}return e},[C,l,u,E]),W=(0,Z.useMemo)(()=>{let e={};if(!C)return e;for(let t of l){if(t.kind!==`polar`)continue;let n=u[t.id],r=n?.kind===`polar`&&n.polarAngleCol?jY(C.rows,n.polarAngleCol,E):void 0,i=n?.kind===`polar`&&n.polarRadiusCol?jY(C.rows,n.polarRadiusCol,E):void 0;e[t.id]=r&&i?{angles:r,radii:i}:{angles:[],radii:[]}}return e},[C,l,u,E]),ee=(e,t,n,r)=>{let i=t&&MY(e,t,E)||new Float64Array,a=n?jY(e,n,E):void 0;return{signal:i,rate:a&&PY(a)||parseFloat(r)||1}},te=(0,Z.useMemo)(()=>{let e={};if(!C)return e;for(let t of l){if(t.kind!==`spectrum`)continue;let n=u[t.id];n?.kind===`spectrum`&&(e[t.id]=ee(C.rows,n.specSignalCol,n.specTimeCol,n.specSampleRate))}return e},[C,l,u,E]),ne=(0,Z.useMemo)(()=>{let e={};if(!C)return e;for(let t of l){if(t.kind!==`boxplot`)continue;let n=u[t.id];e[t.id]=n?.kind===`boxplot`&&n.boxValueCol?NY(C.rows,n.boxValueCol,n.boxGroupCol||void 0,E):[]}return e},[C,l,u,E]),G=(0,Z.useMemo)(()=>{let e={};if(!C)return e;for(let t of l){if(t.kind!==`spectrogram`)continue;let n=u[t.id];n?.kind===`spectrogram`&&(e[t.id]=ee(C.rows,n.sgSignalCol,n.sgTimeCol,n.sgSampleRate))}return e},[C,l,u,E]),re=(0,Z.useMemo)(()=>{if(!C)return{};let e={};for(let t of l){if(t.kind!==`heatmap`)continue;let n=u[t.id];if(!n||n.kind!==`heatmap`){e[t.id]={cells:[],xLabels:[],yLabels:[]};continue}if(n.hmMode===`matrix`){let r=C.rows,i=n.hmColumns.flatMap(e=>{let t=jY(r,e,E);return t?[{name:e,v:t}]:[]}),a=i.reduce((e,t)=>Math.min(e,t.v.length),i.length?1/0:0),o=jY(r,d,E),s,c;if(n.hmSpacing===`values`){o&&GQ(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&&GQ(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 f=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:f,yLabels:i.map(e=>e.name)},xCentres:s,yCentres:c}}else if(n.hmMode===`correlation`){let r=n.hmColumns.filter(e=>I.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 C.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]=S0(C.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 C.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);GQ(e)&&(f=e),GQ(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},[C,l,u,I,d,E]),ie=(0,Z.useMemo)(()=>{let e={};if(!C)return e;for(let t of l){if(t.kind!==`violin`)continue;let n=u[t.id];e[t.id]=n?.kind===`violin`&&n.vlValueCol?NY(C.rows,n.vlValueCol,n.vlGroupCol||void 0,E):[]}return e},[C,l,u,E]),ae=(0,Z.useMemo)(()=>{let e={};if(!C)return e;let{rows:t}=C;for(let n of l){if(n.kind!==`confusion`)continue;let r=u[n.id];if(!r||r.kind!==`confusion`||!r.cfActualCol||!r.cfPredictedCol){e[n.id]={actual:[],predicted:[]};continue}let{cfActualCol:i,cfPredictedCol:a}=r,o=E?.get(i),s=E?.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},[C,l,u,E]),oe=(0,Z.useMemo)(()=>{let e={};if(!C)return e;for(let t of l){if(t.kind!==`roc`)continue;let n=u[t.id],r=n?.kind===`roc`&&n.rocScoreCol?jY(C.rows,n.rocScoreCol,E):void 0,i=n?.kind===`roc`&&n.rocLabelCol?jY(C.rows,n.rocLabelCol,E):void 0;e[t.id]=r&&i?{scores:r,labels:i}:{scores:[],labels:[]}}return e},[C,l,u,E]),se=(0,Z.useMemo)(()=>{let e={};if(!C)return e;let{rows:t}=C;for(let n of l){if(n.kind!==`losscurve`)continue;let r=u[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:jY(t,e,E)??new Float64Array,axis:r})),c=s[0]?.values.length??t.length,l=i&&jY(t,i,E)||Float64Array.from({length:c},(e,t)=>t);e[n.id]={xValues:l,series:s}}return e},[C,l,u,E]),ce=(0,Z.useMemo)(()=>{let e={};if(!C)return e;let{rows:t}=C;for(let n of l){if(n.kind!==`controlchart`)continue;let r=u[n.id],i=r?.kind===`controlchart`&&r.ccValueCol?jY(t,r.ccValueCol,E):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?E?.get(c):void 0,d=e=>o?o[e]:e;e[n.id]={length:a,value:s,subgroup:c?e=>String(l?l[d(e)]:t[d(e)]?.[c]??``):void 0}}return e},[C,l,u,E]),le=(0,Z.useMemo)(()=>{let e={};if(!C)return e;let{rows:t}=C;for(let n of l){if(n.kind!==`parallelcoords`)continue;let r=u[n.id];if(!r||r.kind!==`parallelcoords`||r.pcColumns.length<2){e[n.id]={length:0,columns:[]};continue}let i=r.pcColumns.map(e=>jY(t,e,E)??new Float64Array),a=Math.min(...i.map(e=>e.length)),o={length:a,columns:i},s=r.pcColorByCol;if(s)if(I.includes(s))o.colorValue=jY(t,s,E);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},[C,l,u,I,E]),ue=(0,Z.useMemo)(()=>{let e={};if(!C)return e;let{rows:t}=C,n={length:0,x:[],y:[]};for(let r of l){if(r.kind!==`embedding`)continue;let i=u[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,d=jY(t,a,E),f=jY(t,o,E);if(!d||!f){e[r.id]=n;continue}let p=Math.min(d.length,f.length),m={length:p,x:d,y:f};if(s)if(c===`numeric`&&I.includes(s))m.colorValue=jY(t,s,E);else{let e=E?.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=E?.get(l);m.label=e?t=>String(e[t]):e=>String(t[e]?.[l]??``)}e[r.id]=m}return e},[C,l,u,I,E]),de=(0,Z.useMemo)(()=>{if(!C)return{};let e={};for(let t of l){if(t.kind!==`flamegraph`)continue;let n=u[t.id];if(!n||n.kind!==`flamegraph`||!n.fgNameCol||!n.fgValueCol){e[t.id]=[];continue}let r=[];for(let e of C.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},[C,l,u]),fe=(0,Z.useMemo)(()=>{if(!C)return{};let e={};for(let t of l){if(t.kind!==`barchart`)continue;let n=u[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 C.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=C.rows,i=r.map(e=>jY(n,e,E)),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},[C,l,u,E]),pe=(0,Z.useMemo)(()=>{let e={};if(!C)return e;let{rows:t}=C;for(let n of l){if(n.kind!==`radar`)continue;let r=u[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=>jY(t,e,E));if(r.rdGroupCol){let o=r.rdGroupCol,s=E?.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},[C,l,u,E]),me=(0,Z.useMemo)(()=>{if(!C)return{};let e={};for(let t of l){if(t.kind!==`areachart`)continue;let n=u[t.id];if(!n||n.kind!==`areachart`||n.acYCols.length===0){e[t.id]=[];continue}let r=C.rows,i=n.acYCols.map(e=>jY(r,e,E)),a=i[0]?.length??r.length,o=(n.acXCol?jY(r,n.acXCol,E):void 0)??F0(a);e[t.id]=n.acYCols.flatMap((e,t)=>{let n=i[t];return n?[{name:e,x:o,y:n}]:[]})}return e},[C,l,u,E]),he=(0,Z.useMemo)(()=>{let e={};if(!C)return e;for(let t of l){if(t.kind!==`cdfchart`)continue;let n=u[t.id];if(!n||n.kind!==`cdfchart`){e[t.id]=[];continue}e[t.id]=n.cdValueCols.map(e=>({name:e,values:MY(C.rows,e,E)??new Float64Array}))}return e},[C,l,u,E]),ge=(0,Z.useMemo)(()=>{let e={};if(!C)return e;let{rows:t}=C,n={length:0,x:[],y:[],size:[]};for(let r of l){if(r.kind!==`bubblechart`)continue;let i=u[r.id];if(!i||i.kind!==`bubblechart`||!i.bbXCol||!i.bbYCol||!i.bbSizeCol){e[r.id]=n;continue}let a=jY(t,i.bbXCol,E),o=jY(t,i.bbYCol,E),s=jY(t,i.bbSizeCol,E);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 d=new Float64Array(c);for(let e=0;e<c;e++)d[e]=l[e]===l[e]?a[e]:NaN;let f={length:c,x:d,y:o,size:l};if(i.bbColorCol){if(i.bbColorMode===`numeric`)f.colorValue=jY(t,i.bbColorCol,E);else if(i.bbColorMode===`categorical`){let e=E?.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},[C,l,u,E]),_e=(0,Z.useMemo)(()=>{if(!C)return{};let e={};for(let t of l){if(t.kind!==`treemap`)continue;let n=u[t.id];if(!n||n.kind!==`treemap`||!n.tmNameCol||!n.tmValueCol){e[t.id]=[];continue}let r=[];for(let e of C.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},[C,l,u]),ve=(0,Z.useMemo)(()=>{if(!C)return{};let e={};for(let t of l){if(t.kind!==`sankey`)continue;let n=u[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 C.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},[C,l,u]),ye=(0,Z.useMemo)(()=>{let e={};if(!C)return e;for(let t of l){if(t.kind!==`calibration`)continue;let n=u[t.id],r=n?.kind===`calibration`&&n.cbScoreCol?jY(C.rows,n.cbScoreCol,E):void 0,i=n?.kind===`calibration`&&n.cbLabelCol?jY(C.rows,n.cbLabelCol,E):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},[C,l,u,E]),be=(0,Z.useMemo)(()=>{let e={};if(!C)return e;let t={length:0,theoretical:[],sample:[]},n=e=>{let t=MY(C.rows,e,E);return t?Float64Array.from(t).sort():new Float64Array};for(let r of l){if(r.kind!==`qqplot`)continue;let i=u[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},[C,l,u,E]),xe=(0,Z.useMemo)(()=>{if(!C)return{};let e={};for(let t of l){if(t.kind!==`gantt`)continue;let n=u[t.id];if(!n||n.kind!==`gantt`||!n.gtLabelCol||!n.gtStartCol||!n.gtEndCol){e[t.id]=[];continue}let r=[];for(let e of C.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},[C,l,u]),Se=C&&C.columnNames.indexOf(d)>=0?C.units[C.columnNames.indexOf(d)]??``:``,Ce=(0,Z.useMemo)(()=>{if(!C)return{};let e={};for(let t=0;t<C.columnNames.length;t++){let n=C.units[t]?.trim();n&&(e[C.columnNames[t]]=n)}if(T)for(let t=0;t<w.length;t++)for(let[n,r]of Object.entries(e))e[`${n}__${t}`]=r;return e},[C,T,w]);return{dataset:y,datasetWithChannels:C,multiDatasetMode:T,numericCols:I,anyDuckDb:j,duckDbLayers:F,liveConn:_,liveOverlay:M,hasLiveSelected:g,staticXRange:N,xUnit:Se,columnUnits:Ce,multibandDataByPanel:z,xyPointsByPanel:B,xyzPointsByPanel:H,histogramDataByPanel:U,polarDataByPanel:W,spectrumDataByPanel:te,boxplotDataByPanel:ne,spectrogramDataByPanel:G,heatmapDataByPanel:re,violinDataByPanel:ie,confusionDataByPanel:ae,rocDataByPanel:oe,lossCurveDataByPanel:se,controlChartDataByPanel:ce,parallelCoordsDataByPanel:le,embeddingDataByPanel:ue,flameGraphDataByPanel:de,barChartDataByPanel:fe,radarDataByPanel:pe,areaChartDataByPanel:me,cdfChartDataByPanel:he,bubbleChartDataByPanel:ge,treemapDataByPanel:_e,sankeyDataByPanel:ve,calibrationDataByPanel:ye,qqPlotDataByPanel:be,ganttDataByPanel:xe,gaugeDataByPanel:(0,Z.useMemo)(()=>{let e={};if(!C)return e;let t=e=>e.trim()!==``&&Number.isFinite(Number(e))?Number(e):void 0;for(let n of l){if(n.kind!==`gauge`)continue;let r=u[n.id];if(r?.kind!==`gauge`){e[n.id]=[];continue}e[n.id]=r.ggGauges.flatMap(e=>{let n=e.column,r=n?jY(C.rows,n,E):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]=L0(s?i:0,s?a:1,t(e.min),t(e.max));return[{name:n,unit:Ce[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},[C,l,u,E,Ce])}}function L0(e,t,n,r){t<=e&&(t=e+1);let i=WG(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]}oW();var R0=`__ref`,z0=8e3;function B0(e,t){return e.map(e=>({...e,id:`${e.id}${R0}`,column:`${e.column}${R0}`,color:t}))}var V0=new WeakMap;function H0(e,t,n){let r=e.data.rows,i=`${t}\n${n.join(`
|
|
629
|
+
`)}`,a=V0.get(r);a||(a=new Map,V0.set(r,a));let o=a.get(i);if(o)return o;let s=U0(tW(r,t,n,z0,R0)),c={points:s,span:s.length>1?[s.x[0],s.x[s.length-1]]:null};return a.set(i,c),c}function U0(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 W0(e,t){return e?t?[Math.min(e[0],t[0]),Math.max(e[1],t[1])]:e:t}function G0(e,t,n,r,i){e.source.trackCycles(t);let a=r.reference===`dataset`&&i?H0(i,t,n):null,o=null;return{pull:(i,s,c,l)=>{let u=e.source.version();if(!o||o.ver!==u||o.x0!==i||o.x1!==s||o.mp!==c){let l=aW;if(r.reference===`previous`){let r=e.source.cyclePointsSync(t,`previous`,n,{x0:i,x1:s},c);l={...r,cols:new Map([...r.cols].map(([e,t])=>[e+R0,t]))}}else a&&(l=$U(a.points,i,s));o={ver:u,x0:i,x1:s,mp:c,live:e.source.cyclePointsSync(t,`current`,n,{x0:i,x1:s},c),ref:l}}return[o.ref,QU(o.live,l)]},latestT:()=>e.source.latestTimeSync(),xAtTime:n=>e.source.xAtTimeSync(t,n),xBounds:()=>W0(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 K0(e,t){return e.reference===`previous`?e.previousColor:e.reference===`dataset`&&t?e.datasetColor:null}oW();function q0(e,t,n,r,i,a,o){let s=null;return{pull:(o,c,l,u)=>{let d=e.source.version();if(!s||s.ver!==d||s.x0!==o||s.x1!==c||s.mp!==l){let a=e.source.getPointsSync(n,{xKey:t,x0:o-i,x1:c-i},l),u=i===0?a.x:a.x.map(e=>e+i);s={ver:d,x0:o,x1:c,mp:l,pts:{...a,x:u,cols:new Map([...a.cols].map(([e,t])=>[e+r,t]))}}}return[...a,QU(s.pts,u)]},xBounds:()=>{let n=e.source.xBoundsSync(t);return n.x1>n.x0?o?[Math.min(o[0],n.x0+i),Math.max(o[1],n.x1+i)]:[n.x0+i,n.x1+i]:o},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}}}oW(),yW();var J0=`#fb7185`,Y0=2500;function X0(e){let{panel:t,data:n,settings:r}=e;if(!n.dataset)return{status:`no-data`,node:null,data:null};let i=`${e.background??`theme`}|${e.styleToken}`,a=t=>e.onContextMenu(t),o=(e,t)=>({status:`ready`,node:e,data:t}),s={status:`empty`,node:null,data:null},c=t.id;switch(t.kind){case`multiband`:{let t=n.multibandDataByPanel[c],l=t?.points??[],u=t?.effectiveSeries??[],d=r?.kind===`multiband`?r:null,f=[...new Set((d?.series??[]).map(e=>e.column).filter(t=>t!==e.xKey))],p={xLabel:n.xUnit?`${e.xKey} (${n.xUnit})`:e.xKey,series:u,columnUnits:n.columnUnits,height:e.height,backgroundToken:i,viewXRange:e.viewXRange,onViewXRangeChange:e.onViewXRangeChange,liveZoom:e.liveZoom,liveZoomId:c,xAxisLine:d?.xAxisLine,yAxisLine:d?.yAxisLine,gridLine:d?.gridLine,lineWidth:d?.lineWidth,onPlotContextMenu:a,shiftMode:e.shiftMode},m=d?.beacon;if(m?.enabled&&e.beaconLive&&f.length>0){let t=j0((d?.series??[]).filter(t=>t.column!==e.xKey),d?.layout??`overlay`),n=m.reference===`dataset`&&m.datasetId?e.findDataset(m.datasetId):void 0,r=K0(m,!!n),i=r?[...B0(t,r),...t]:t;return o((0,Q.jsx)(sY,{...p,series:i,points:[],showLatestValues:!0,liveSource:G0(e.beaconLive,e.xKey,f,m,n),liveZoomMode:`free`}),{series:i,points:[]})}if(n.anyDuckDb)return u.length===0?s:o((0,Q.jsx)(OY,{...p,layers:n.duckDbLayers,xKey:e.xKey,columns:f,maxPoints:Y0}),{series:u,columns:f});if(!l.some(e=>e.length>0)||u.length===0)return s;let h=n.liveConn,g=null,_=n.liveOverlay,v=!h&&_&&f.length>0?q0(_.conn,e.xKey,f,_.keySuffix,_.offset,l,n.staticXRange):void 0,y=v??(h&&f.length>0?{pull:(t,n,r,i)=>{let a=h.source.version();return(!g||g.ver!==a||g.x0!==t||g.x1!==n||g.mp!==r)&&(g={ver:a,x0:t,x1:n,mp:r,pts:h.source.getPointsSync(f,{xKey:e.xKey,x0:t,x1:n},r)}),[QU(g.pts,i)]},latestT:()=>h.source.latestTimeSync(),xAtTime:t=>h.source.xAtTimeSync(e.xKey,t),xBounds:()=>{let t=h.source.xBoundsSync(e.xKey);return t.x1>t.x0?[t.x0,t.x1]:null},latestX:()=>{let t=h.source.latestSync(e.xKey);return Number.isFinite(t)?t:null},version:()=>h.source.version(),latestValues:e=>h.source.latestValuesSync(e),...e.xKey===`ElapsedTime`?{}:{spanForSeconds:t=>h.source.xTravelSync(e.xKey,t),bufferedSeconds:()=>{let e=h.source.xBoundsSync(`ElapsedTime`);return e.x1-e.x0}}}:void 0);return o((0,Q.jsx)(sY,{...p,points:l,envelopes:t?.envelopes,showLatestValues:n.hasLiveSelected,fullXRange:n.staticXRange,liveSource:y,liveWindowSeconds:v?null:e.liveWindowSeconds,onLiveWindowChange:v?void 0:e.onLiveWindowChange,liveZoomMode:v?`free`:`follow`}),{series:u,points:l})}case`xyzmesh`:{let t=r?.kind===`xyzmesh`?r:H(4),l=n.xyzPointsByPanel[c];if(!l||l.points.length<1&&!l.surface)return s;let u=!!l.surface;return o((0,Q.jsx)(kZ,{ref:e.xyzRef,points:l.points,surface:l.surface,xLabel:u?(t.xyzColumns??[]).includes(e.xKey)?`Row`:e.xKey:t.xyzXCol,yLabel:u?`Column`:t.xyzYCol,zLabel:u?`Value`:t.xyzZCol,height:e.height,backgroundToken:i,xRange:R(t.xyzXScale.scaleMin,t.xyzXScale.scaleMax),yRange:R(t.xyzYScale.scaleMin,t.xyzYScale.scaleMax),zRange:R(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}),l.surface??l.points)}case`xyscatter`:{let t=r?.kind===`xyscatter`?r:V(J0),l=n.xyPointsByPanel.pts[c]??[];if(l.length===0)return s;let u=n.xyPointsByPanel.colorMeta[c];return o((0,Q.jsx)(_X,{points:l,xLabel:t.xyXCol,yLabel:t.xyYCol,color:t.xyColor,datasetColors:n.xyPointsByPanel.datasetColors[c],colorLabel:u?.label,colorRange:u?[u.min,u.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}),l)}case`histogram`:{if(r?.kind!==`histogram`)return s;let t=n.histogramDataByPanel[c]??[];return t.length===0?s:o((0,Q.jsx)(IZ,{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 s;let t=n.polarDataByPanel[c]??{angles:[],radii:[]};if(t.angles.length===0)return s;let l=parseFloat(r.polarRadiusMin),u=parseFloat(r.polarRadiusMax);return o((0,Q.jsx)(eQ,{angles:t.angles,radii:t.radii,angleLabel:r.polarAngleCol,radiusLabel:r.polarRadiusCol,color:r.polarColor,mode:r.polarMode,radiusMin:Number.isFinite(l)?l:void 0,radiusMax:Number.isFinite(u)?u:void 0,height:e.height,backgroundToken:i,onPlotContextMenu:a}),t)}case`spectrum`:{if(r?.kind!==`spectrum`)return s;let{signal:t,rate:l}=n.spectrumDataByPanel[c]??{signal:[],rate:1};return t.length<4?s:o((0,Q.jsx)(gQ,{signal:t,sampleRate:l,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 s;let t=n.boxplotDataByPanel[c]??[];return t.length===0?s:o((0,Q.jsx)(SQ,{groups:t,color:r.boxColor,whiskers:r.boxWhiskers,height:e.height,backgroundToken:i,onPlotContextMenu:a}),t)}case`spectrogram`:{if(r?.kind!==`spectrogram`)return s;let{signal:e,rate:t}=n.spectrogramDataByPanel[c]??{signal:[],rate:1};return e.length<r.sgWindowSize?s:r.sgView===`waterfall`?o((0,Q.jsx)(BQ,{signal:e,sampleRate:t,windowSize:r.sgWindowSize,overlap:r.sgOverlap,winFunc:r.sgWinFunc,yMode:r.sgYMode,backgroundToken:i,onPlotContextMenu:a}),e):o((0,Q.jsx)(FQ,{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 s;let e=n.heatmapDataByPanel[c]??{cells:[],xLabels:[],yLabels:[]};if(e.cells.length===0&&!(e.grid&&e.grid.w*e.grid.h>0))return s;let t=e=>e!==void 0&&e.trim()!==``&&Number.isFinite(Number(e))?Number(e):void 0;return o((0,Q.jsx)(a$,{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 s;let e=n.violinDataByPanel[c]??[];return e.some(e=>e.values.length>0)?o((0,Q.jsx)(p$,{groups:e,color:r.vlColor,showBox:r.vlShowBox,bandwidth:parseFloat(r.vlBandwidth)||void 0,orientation:r.vlOrientation,backgroundToken:i,onPlotContextMenu:a}),e):s}case`confusion`:{if(r?.kind!==`confusion`)return s;let e=n.confusionDataByPanel[c]??{actual:[],predicted:[]};return e.actual.length===0?s:o((0,Q.jsx)(b$,{actual:e.actual,predicted:e.predicted,normalize:r.cfNormalize,backgroundToken:i,onPlotContextMenu:a}),e)}case`roc`:{if(r?.kind!==`roc`)return s;let e=n.rocDataByPanel[c]??{scores:[],labels:[]};return e.scores.length===0?s:o((0,Q.jsx)(E$,{scores:e.scores,labels:e.labels,mode:r.rocMode,color:r.rocColor,backgroundToken:i,onPlotContextMenu:a}),e)}case`losscurve`:{if(r?.kind!==`losscurve`)return s;let e=n.lossCurveDataByPanel[c]??{xValues:[],series:[]};return e.series.length===0?s:o((0,Q.jsx)(O$,{xValues:e.xValues,series:e.series,xLabel:r.lcXCol||`Step`,backgroundToken:i,onPlotContextMenu:a}),e)}case`controlchart`:{if(r?.kind!==`controlchart`)return s;let e=n.controlChartDataByPanel[c];return!e||e.length<2?s:o((0,Q.jsx)(P$,{points:e,sigmaLevel:r.ccSigmaLevel,color:r.ccColor,backgroundToken:i,onPlotContextMenu:a}),e)}case`parallelcoords`:{if(r?.kind!==`parallelcoords`)return s;let e=n.parallelCoordsDataByPanel[c];if(!e||e.length===0||r.pcColumns.length<2)return s;let t=r.pcColorByCol?n.numericCols.includes(r.pcColorByCol):!1;return o((0,Q.jsx)(B$,{rows:e,axes:r.pcColumns,color:r.pcColor,colorByNumeric:t,backgroundToken:i,onPlotContextMenu:a}),e)}case`embedding`:{if(r?.kind!==`embedding`)return s;let e=n.embeddingDataByPanel[c];return!e||e.length===0?s:o((0,Q.jsx)(X$,{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 s;let e=n.flameGraphDataByPanel[c]??[];return e.length===0?s:o((0,Q.jsx)(i1,{nodes:e,direction:r.fgDirection,backgroundToken:i,onPlotContextMenu:a}),e)}case`barchart`:{if(r?.kind!==`barchart`)return s;let e=n.barChartDataByPanel[c]??{groups:[],seriesNames:[]};if(e.groups.length===0&&!e.columns?.length)return s;let t=e=>e!==void 0&&e.trim()!==``&&Number.isFinite(Number(e))?Number(e):void 0,l=r.bcValueScale?{min:t(r.bcValueScale.scaleMin),max:t(r.bcValueScale.scaleMax)}:void 0;return o((0,Q.jsx)(u1,{groups:e.columns?void 0:e.groups,columns:e.columns,seriesNames:e.seriesNames,mode:r.bcMode,horizontal:r.bcHorizontal,valueRange:l,backgroundToken:i,onPlotContextMenu:a}),e)}case`radar`:{if(r?.kind!==`radar`)return s;let e=n.radarDataByPanel[c]??{axes:[],series:[]};return e.axes.length<3?s:o((0,Q.jsx)(m1,{axes:e.axes,series:e.series,fill:r.rdFill,color:r.rdColor,backgroundToken:i,onPlotContextMenu:a}),e)}case`areachart`:{if(r?.kind!==`areachart`)return s;let e=n.areaChartDataByPanel[c]??[];if(e.length===0)return s;let t=e=>e!==void 0&&e.trim()!==``&&Number.isFinite(Number(e))?Number(e):void 0,l=r.acYScale?{min:t(r.acYScale.scaleMin),max:t(r.acYScale.scaleMax)}:void 0;return o((0,Q.jsx)(v1,{series:e,stacked:r.acStacked,yRange:l,backgroundToken:i,onPlotContextMenu:a}),e)}case`cdfchart`:{if(r?.kind!==`cdfchart`)return s;let e=n.cdfChartDataByPanel[c]??[];return e.length===0?s:o((0,Q.jsx)(x1,{series:e,complement:r.cdComplement,logX:r.cdLogX,backgroundToken:i,onPlotContextMenu:a}),e)}case`bubblechart`:{if(r?.kind!==`bubblechart`)return s;let e=n.bubbleChartDataByPanel[c];return!e||e.length===0?s:o((0,Q.jsx)(k1,{points:e,color:r.bbColor,colorByNumeric:r.bbColorMode===`numeric`,maxRadius:r.bbMaxRadius,backgroundToken:i,onPlotContextMenu:a}),e)}case`treemap`:{let e=n.treemapDataByPanel[c]??[];return e.length===0?s:o((0,Q.jsx)(P1,{nodes:e,backgroundToken:i,onPlotContextMenu:a}),e)}case`sankey`:{let e=n.sankeyDataByPanel[c]??{nodeNames:[],links:[]};return e.links.length===0?s:o((0,Q.jsx)(B1,{nodeNames:e.nodeNames,links:e.links,backgroundToken:i,onPlotContextMenu:a}),e)}case`calibration`:{if(r?.kind!==`calibration`)return s;let e=n.calibrationDataByPanel[c]??[];return e.length===0?s:o((0,Q.jsx)(H1,{bins:e,color:r.cbColor,backgroundToken:i,onPlotContextMenu:a}),e)}case`qqplot`:{if(r?.kind!==`qqplot`)return s;let e=n.qqPlotDataByPanel[c];return!e||e.length===0?s:o((0,Q.jsx)(W1,{points:e,color:r.qqColor,backgroundToken:i,onPlotContextMenu:a}),e)}case`gauge`:{if(r?.kind!==`gauge`)return s;let e=n.gaugeDataByPanel[c]??[];if(e.length===0)return s;let t=n.liveConn??n.liveOverlay?.conn;return o((0,Q.jsx)(r0,{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[c]??[];return e.length===0?s:o((0,Q.jsx)(Y1,{tasks:e,backgroundToken:i,onPlotContextMenu:a}),e)}}return s}var Z0=500,Q0=1e3;function $0(e){if(Array.isArray(e))return e2(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,e2(n)));return t<0?null:t}function e2(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 t2(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 n2({stats:e,host:t}){let[n,r]=(0,Z.useState)(null);if((0,Z.useEffect)(()=>{let n=t.current?.ownerDocument.defaultView??window,i=0,a=0,o=0,s=-1,c=-1,l=e.renders,u=t.current?cJ(t.current):0,d=f=>{c>=0&&f-s>Q0&&(c=f,s=f,a=0,o=0,l=e.renders,u=t.current?cJ(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>=Z0){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?cJ(i):0;r({fps:a*1e3/p,repaints:(m-u)*1e3/p,worstFrameMs:o,renderMs:e.lastRenderMs,rendersPerSec:(e.renders-l)*1e3/p,points:$0(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(0,Q.jsx)(`dl`,{className:`kymo-perf-hud`,style:r2,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`,t2(n.points)]],[`DOM nodes`,t2(n.domNodes)],[`Canvas`,`${n.canvasMp.toFixed(2)} MP`],...n.heapMb===null?[]:[[`JS heap`,`${n.heapMb.toFixed(0)} MB`]]].map(([e,t,n])=>(0,Q.jsxs)(`div`,{style:i2,children:[(0,Q.jsx)(`dt`,{style:a2,children:e}),(0,Q.jsx)(`dd`,{style:n?{...o2,color:n}:o2,children:t})]},e))})}var r2={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)`},i2={display:`flex`,justifyContent:`space-between`,gap:12},a2={color:`var(--text-muted, #8a93a6)`},o2={margin:0,fontWeight:600,textAlign:`right`},s2=3;function c2(e,t,n,r){return e.anchor===`x`&&!r?null:e.points.map(([i,a])=>[e.anchor===`x`?mJ(r,i):i*t,a*n])}function l2(e,t,n,r,i){return t.map(([t,a])=>[e.anchor===`x`&&i?hJ(i,t):u2(t/Math.max(1,n)),u2(a/Math.max(1,r))])}var u2=e=>Math.round(e*1e4)/1e4,d2=(0,Z.memo)(function({annotations:e,tool:t,plotFrame:n,onChange:r,onToolEnd:i,onSelect:a}){let o=(0,Z.useRef)(null),s=(0,Z.useSyncExternalStore)(n.subscribe,n.get),c=s?.x?s:null,[l,u]=(0,Z.useState)({w:0,h:0}),[d,f]=(0,Z.useState)(null),[p,m]=(0,Z.useState)(null),[h,g]=(0,Z.useState)(null),_=(0,Z.useRef)({annotations:e,onChange:r,onToolEnd:i,onSelect:a,tool:t,selected:d,editing:p,frame:c,size:l});_.current={annotations:e,onChange:r,onToolEnd:i,onSelect:a,tool:t,selected:d,editing:p,frame:c,size:l};let v=e=>{_.current.selected!==e&&(_.current.selected=e,f(e),_.current.onSelect(e))};(0,Z.useLayoutEffect)(()=>{let e=o.current;if(!e)return;let t=e.ownerDocument.defaultView??window,n=()=>u({w:e.clientWidth,h:e.clientHeight});n();let r=new t.ResizeObserver(n);return r.observe(e),()=>r.disconnect()},[]),(0,Z.useEffect)(()=>{t&&v(null)}),(0,Z.useEffect)(()=>{d&&!e.some(e=>e.id===d)&&v(null)}),(0,Z.useEffect)(()=>()=>{_.current.selected&&_.current.onSelect(null)},[]),(0,Z.useEffect)(()=>{let e=o.current?.ownerDocument;if(!e)return;let t=e=>{let{selected:t,editing:n,tool:r,annotations:i,onChange:a,onToolEnd:o}=_.current;if(!(n||b2(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)),v(null)):e.key===`Escape`&&v(null))}},n=e=>{let t=_.current.selected,n=e.target;t&&!n?.closest?.(`[data-ann-id="${CSS.escape(t)}"], [data-kymo-annotation-controls]`)&&v(null)};return e.addEventListener(`keydown`,t),e.addEventListener(`pointerdown`,n,!0),()=>{e.removeEventListener(`keydown`,t),e.removeEventListener(`pointerdown`,n,!0)}},[]);let{w:y,h:b}=l,x=e=>{let t=o.current.getBoundingClientRect();return[e.clientX-t.left,e.clientY-t.top]},S=(e,t)=>{let n=o.current.ownerDocument,r=t=>e(x(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)},C=e=>r([..._.current.annotations,e]),w=e=>r(_.current.annotations.map(t=>t.id===e.id?e:t)),T=e=>{if(!t||e.button!==0||p)return;e.preventDefault(),e.stopPropagation();let n=x(e),r={id:crypto.randomUUID(),kind:t.kind,color:t.color,width:t.width,...c?{anchor:`x`}:{}},i=e=>l2(r,e,y,b,c);if(t.kind===`text`){g({...r,points:i([n]),text:``}),m(r.id);return}let a=t.kind===`brush`?[n]:[n,n],o={...r,points:i(a)};g(o);let s=!1;S((t,n)=>{if(s||=Math.hypot(n.clientX-e.clientX,n.clientY-e.clientY)>s2,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)},g(o)},()=>{g(null),s&&o.points.length>=2&&C(o)})},E=(e,t,n)=>{let r=c2(t,y,b,c);if(!r)return;let i=x(e),a=null;S((o,s)=>{if(!a&&Math.hypot(s.clientX-e.clientX,s.clientY-e.clientY)<=s2)return;let{size:c,frame:l}=_.current;a={...t,points:l2(t,n(r,[o[0]-i[0],o[1]-i[1]],o),c.w,c.h,l)},g(a)},()=>{g(null),a&&w(a)})},D=(e,n)=>{t||e.button!==0||p===n.id||(e.preventDefault(),e.stopPropagation(),v(n.id),E(e,n,(e,[t,n])=>e.map(([e,r])=>[e+t,r+n])))},O=(e,t,n)=>{e.button===0&&(e.preventDefault(),e.stopPropagation(),E(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}))},k=e=>{t||e.kind!==`text`&&e.kind!==`box`||(v(e.id),m(e.id))},A=e=>{let t=p;m(null);let n=h&&h.id===t?h:null;if(g(null),e===null||!t)return;let i=e.replace(/\s+$/,``),a=_.current.annotations;if(n){i&&C({...n,text:i});return}let o=a.find(e=>e.id===t);o&&(!i&&o.kind===`text`?r(a.filter(e=>e.id!==t)):w(y2(o,i)))},j=e=>{r(_.current.annotations.filter(t=>t.id!==e)),v(null)},M=(h?e.some(e=>e.id===h.id)?e.map(e=>e.id===h.id?h:e):[...e,h]:e).flatMap(e=>{let t=c2(e,y,b,c);return t?[{a:e,px:t}]:[]}),N=d?M.find(e=>e.a.id===d):void 0,P=N&&N.a.kind!==`text`?v2(N.px):null,F=e=>(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`svg`,{className:`kymo-ann-svg`,width:y,height:b,viewBox:`0 0 ${y} ${b}`,"aria-hidden":`true`,children:e.map(({a:e,px:t})=>e.kind===`text`?null:(0,Q.jsx)(`g`,{"data-ann-id":e.id,className:`kymo-ann kymo-ann--${e.kind}`,onPointerDown:t=>D(t,e),onDoubleClick:()=>k(e),children:(0,Q.jsx)(m2,{a:e,px:t})},e.id))}),e.map(({a:e,px:t})=>{if(e.kind!==`text`&&e.kind!==`box`)return null;let n=p===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(0,Q.jsxs)(`div`,{"data-ann-id":e.id,className:`kymo-ann-text kymo-ann-text--${e.kind}${d===e.id&&e.kind===`text`?` is-selected`:``}`,style:{...r,color:e.color,fontSize:e.kind===`text`?e.width:12},onPointerDown:t=>D(t,e),onDoubleClick:()=>k(e),children:[n?(0,Q.jsx)(p2,{initial:e.text??``,onDone:A}):e.text,d===e.id&&e.kind===`text`&&!n?(0,Q.jsx)(f2,{onDelete:()=>j(e.id),style:{right:-11,top:-11}}):null]},`t-${e.id}`)})]});return(0,Q.jsx)(`div`,{ref:o,className:`kymo-annotations${t?` is-drawing is-tool-${t.kind}`:``}`,onPointerDown:T,onContextMenu:t?e=>e.preventDefault():void 0,children:y>0&&b>0?(0,Q.jsxs)(Q.Fragment,{children:[F(M.filter(e=>e.a.anchor!==`x`)),c?(0,Q.jsx)(`div`,{className:`kymo-ann-clip`,style:{clipPath:`inset(0 ${Math.max(0,y-c.left-c.width)}px 0 ${Math.max(0,c.left)}px)`},children:F(M.filter(e=>e.a.anchor===`x`))}):null,(0,Q.jsxs)(`svg`,{className:`kymo-ann-svg`,width:y,height:b,viewBox:`0 0 ${y} ${b}`,"aria-hidden":`true`,children:[P?(0,Q.jsx)(`rect`,{className:`kymo-ann-selection`,x:P.x-6,y:P.y-6,width:P.w+12,height:P.h+12,rx:4}):null,N&&!p&&(N.a.kind===`box`||N.a.kind===`arrow`)?(0,Q.jsx)(`g`,{"data-ann-id":N.a.id,children:h2(N.a,N.px).map(([e,t],n)=>(0,Q.jsx)(`rect`,{className:`kymo-ann-handle kymo-ann-handle--${N.a.kind===`arrow`?`end`:n%2?`nesw`:`nwse`}`,x:e-4.5,y:t-4.5,width:9,height:9,rx:2,onPointerDown:e=>O(e,N.a,n)},n))}):null]}),P&&!p?(0,Q.jsx)(f2,{onDelete:()=>j(N.a.id),id:N.a.id,style:{left:Math.min(y-12,P.x+P.w+6)-10,top:Math.max(10,P.y-6)-10}}):null]}):null})});function f2({onDelete:e,style:t,id:n}){return(0,Q.jsx)(`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:(0,Q.jsx)(`svg`,{viewBox:`0 0 10 10`,width:`8`,height:`8`,"aria-hidden":`true`,children:(0,Q.jsx)(`path`,{d:`M2 2l6 6M8 2l-6 6`})})})}function p2({initial:e,onDone:t}){let n=(0,Z.useRef)(null),r=(0,Z.useRef)(!1),i=e=>{r.current||(r.current=!0,t(e))};return(0,Z.useLayoutEffect)(()=>{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)},[]),(0,Q.jsx)(`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 m2({a:e,px:t}){let n={stroke:e.color,strokeWidth:e.width,fill:`none`,strokeLinecap:`round`,strokeLinejoin:`round`},r=t=>(0,Q.jsx)(`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(0,Q.jsxs)(Q.Fragment,{children:[r(c),(0,Q.jsx)(`path`,{d:c,...n}),(0,Q.jsx)(`path`,{d:c,fill:e.color,fillOpacity:.06,stroke:`none`,pointerEvents:`none`})]})}case`arrow`:{let[[i,a],[o,s]]=t,c=_2(i,a,o,s,e.width);return(0,Q.jsxs)(Q.Fragment,{children:[r(`M${i} ${a}L${o} ${s}`),(0,Q.jsx)(`path`,{d:`M${i} ${a}L${c.base[0]} ${c.base[1]}`,...n}),(0,Q.jsx)(`path`,{d:c.d,fill:e.color,stroke:e.color,strokeWidth:1,strokeLinejoin:`round`})]})}case`brush`:{let e=g2(t);return(0,Q.jsxs)(Q.Fragment,{children:[r(e),(0,Q.jsx)(`path`,{d:e,...n})]})}}return null}function h2(e,t){if(e.kind===`arrow`)return t;let[[n,r],[i,a]]=t;return[[n,r],[i,r],[i,a],[n,a]]}function g2(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 _2(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 v2(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 y2(e,t){if(t)return{...e,text:t};let{text:n,...r}=e;return r}function b2(e){let t=e;return!!t&&(t.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName))}function x2(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=c2(i,n,r,o);t&&(e.save(),i.anchor===`x`&&o&&(e.beginPath(),e.rect(o.left,0,o.width,r),e.clip()),S2(e,i,t,a),e.restore())}e.restore()}function S2(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(g2(n)));else if(t.kind===`arrow`){let r=_2(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(`
|
|
630
|
+
`),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 C2={solid:void 0,dashed:`5 4`,dotted:`1 4`};function w2(e,t,n){if(!e||!(n===`x`?e.x:e.y))return null;if(n===`x`){let n=mJ(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=gJ(e,t.value);return r>=e.top-.5&&r<=e.top+e.height+.5?[e.left,r,e.left+e.width,r]:null}var T2=(0,Z.memo)(function({frame:e,alarm:t,axis:n}){let r=w2((0,Z.useSyncExternalStore)(e.subscribe,e.get),t,n);return r?(0,Q.jsx)(`svg`,{className:`kymo-alarm`,"aria-hidden":`true`,children:(0,Q.jsx)(`line`,{x1:r[0],y1:r[1],x2:r[2],y2:r[3],stroke:t.color,strokeWidth:t.width,strokeDasharray:C2[t.style]})}):null});function E2(e,t,n,r,i){let a=w2(t,n,r);a&&(e.save(),e.scale(i,i),e.strokeStyle=n.color,e.lineWidth=n.width,e.setLineDash(C2[n.style]?.split(` `).map(Number)??[]),e.beginPath(),e.moveTo(a[0],a[1]),e.lineTo(a[2],a[3]),e.stroke(),e.restore())}function D2(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)},onContextMenu:t=>e.emitter.emit(`contextmenu`,t),xyzRef:t=>{e.xyz=t},onAnnotations:n=>t.charts.setAnnotations(e.chartId,n),onAnnotationToolEnd:()=>{e.annotationTool=null,M2(t).bump(),e.emitter.emit(`annotationtool`,null)},onAnnotationSelect:t=>{e.selectedAnnotation=t,e.emitter.emit(`annotationselect`,t)}}}var O2=new WeakMap;function k2(e){let t=O2.get(e);return t||O2.set(e,t=t=>e.view.setLiveWindow(t)),t}var A2=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=(0,cq.createRoot)(document.createElement(`div`)),this.root.render((0,Q.jsx)(R2,{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}},j2=new WeakMap;function M2(e){let t=j2.get(e);return t||(t=new A2(e),j2.set(e,t)),t}function N2(e,t,n,r={}){e.charts.get(t);let i=M2(e),a={key:crypto.randomUUID(),chartId:t,element:n,options:r,shiftDatasetId:null,emitter:fq(),xyz:null,annotationTool:null,selectedAnnotation:null,plotFrame:yJ(),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 jw(`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 jw(`export_failed`,{reason:`canvas unavailable`}));for(let e of r)o.drawImage(e,0,0);let s=e.charts.get(t),c=s.annotations,l=Ae(s.settings);return l&&n.clientWidth>0&&E2(o,a.plotFrame.get(),l.alarm,l.axis,i.width/n.clientWidth),c.length&&n.clientWidth>0&&x2(o,c,n.clientWidth,n.clientHeight,i.width/n.clientWidth,X.sans,a.plotFrame.get()?.x?a.plotFrame.get():null),new Promise((e,t)=>i.toBlob(n=>n?e(n):t(new jw(`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 P2(e){j2.get(e)?.refresh()}function F2(e){j2.get(e)?.dispose(),j2.delete(e)}function I2(e){let t=new MutationObserver(e);return t.observe(document.documentElement,{attributes:!0,attributeFilter:[`data-color-scheme`,`class`,`data-theme`]}),()=>t.disconnect()}var L2=()=>{let e=document.documentElement;return`${e.getAttribute(`data-color-scheme`)??``}|${e.getAttribute(`data-theme`)??``}|${e.className}`};function R2({engine:e,registry:t}){(0,Z.useSyncExternalStore)(t.subscribe,t.getVersion);let n=t3(e),r=(0,Z.useSyncExternalStore)(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(0,Q.jsx)(Q.Fragment,{children:[...i.values()].map(t=>(0,Q.jsx)(H2,{engine:e,worksheet:t.worksheet,mounts:t.mounts},t.worksheet.id))})}var z2=1e3,B2=.25;function V2(e,t,n){let[r,i]=(0,Z.useState)(0),a=(0,Z.useRef)(0),o=(0,Z.useRef)(0);return(0,Z.useEffect)(()=>{a.current&&=(o.current=performance.now()-a.current,0)}),(0,Z.useEffect)(()=>{if(!n)return;let r=0,s=-1,c=0,l=n=>{if(r=iJ(l),a.current||n<c||lJ())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/B2-1),a.current=performance.now(),(0,Z.startTransition)(()=>i(e=>e+1)))};return r=iJ(l),()=>aJ(r)},[n,e,t]),(0,Z.useMemo)(()=>n?e.map(e=>t.includes(e.id)?{...e,dataset:e.source.snapshot(z2)}:e):e,[e,t,n,r])}function H2({engine:e,worksheet:t,mounts:n}){let r=t3(e),i=(0,Z.useSyncExternalStore)(r.store.subscribe,r.store.get),a=r.derived(),o=i.xRanges[t.id]??null,s=i.live.filter(e=>i.selection.includes(e.id)).length,c=e=>{let n=t.panelChartSettings[e];return n?.kind===`multiband`&&n.beacon?.enabled===!0},l=s>0&&t.panels.some(e=>e.kind!==`multiband`||s>1&&!c(e.id)),u=V2(i.live,i.selection,l),d=I0({worksheet:t,viewXRange:o,selectedIds:i.selection,selectedDatasets:a.selectedDatasets,liveConnections:u,mathChannels:a.channels,datasetOffsets:i.offsets,datasetColors:i.colors,datasetPalette:i.palette}),f=(0,Z.useRef)(lq()).current,p=(0,Z.useSyncExternalStore)(I2,L2),m=t.id,h=k2(e),g=i.licensed,_=i.live.find(e=>i.selection.includes(e.id))??null,v=e=>i.datasets.find(t=>t.id===e)??Object.values(a.laps).flatMap(e=>e.laps).find(t=>t.id===e);return(0,Q.jsx)(Q.Fragment,{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=D2(n,e,m);return(0,sq.createPortal)((0,Q.jsx)(q2,{mount:n,annotations:t.panelChartSettings[r.id]?.annotations,alarm:Ae(t.panelChartSettings[r.id]),onAnnotations:c.onAnnotations,onAnnotationToolEnd:c.onAnnotationToolEnd,onAnnotationSelect:c.onAnnotationSelect,render:a=>X0({panel:r,settings:t.panelChartSettings[r.id],background:n.options.style?.background??t.panelChartBackgrounds[r.id]??null,styleToken:JSON.stringify([p,n.options.theme,n.options.style,X]),data:d,xKey:t.xKey,height:a,viewXRange:o,onViewXRangeChange:c.onViewXRangeChange,liveZoom:f,liveWindowSeconds:i.liveWindowSeconds,onLiveWindowChange:h,beaconLive:_,findDataset:v,shiftMode:s?U2(e,s.id,s.name):void 0,onContextMenu:c.onContextMenu,xyzRef:c.xyzRef}),licensed:g},n.key),n.element,n.key)})})}function U2(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 W2=[];function G2(e,t){e.data=t}function K2(e,t){e.status!==t&&(e.status=t,e.emitter.emit(`status`,t))}function q2({mount:e,render:t,licensed:n,annotations:r,alarm:i,onAnnotations:a,onAnnotationToolEnd:o,onAnnotationSelect:s}){let c=(0,Z.useRef)(null),[l,u]=(0,Z.useState)(0),d=!!e.options.debug,f=(0,Z.useRef)({renderStart:0,lastRenderMs:0,renders:0,data:null}).current;d&&(f.renderStart=performance.now()),(0,Z.useLayoutEffect)(()=>{d&&(f.lastRenderMs=performance.now()-f.renderStart,f.renders++)}),(0,Z.useLayoutEffect)(()=>{let e=c.current;if(!e)return;let t=()=>u(Math.max(120,Math.floor(e.clientHeight)));t();let n=new uJ(t);return n.observe(e),()=>n.disconnect()},[]);let{status:p,node:m,data:h}=t(l||400);f.data=h,(0,Z.useEffect)(()=>{G2(e,h)}),(0,Z.useEffect)(()=>{K2(e,p)});let{theme:g,style:_,className:v}=e.options,y={};return _?.background&&(y[`--chart-bg`]=_.background),_?.muted&&(y[`--chart-muted`]=_.muted),_?.grid&&(y[`--chart-grid`]=_.grid),_?.accent&&(y[`--accent`]=_.accent),(0,Q.jsxs)(`div`,{ref:c,onContextMenu:p===`ready`?void 0:t=>{t.preventDefault(),e.emitter.emit(`contextmenu`,{clientX:t.clientX,clientY:t.clientY})},className:v?`kymo-chart ${v}`:`kymo-chart`,"data-color-scheme":g,"data-status":p,style:y,children:[(0,Q.jsx)(bJ.Provider,{value:e.plotFrame.set,children:m}),p===`ready`&&i?(0,Q.jsx)(T2,{frame:e.plotFrame,alarm:i.alarm,axis:i.axis}):null,p===`ready`&&(r?.length||e.annotationTool)?(0,Q.jsx)(d2,{annotations:r??W2,tool:e.annotationTool,plotFrame:e.plotFrame,onChange:a,onToolEnd:o,onSelect:s}):null,d?(0,Q.jsx)(n2,{stats:f,host:c}):null,n===!1?(0,Q.jsx)(dq,{}):null]})}var J2=new WeakMap;function Y2(e,t,n,r={}){let i=J2.get(e)??new Map;J2.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 jw(`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),$q(c);let m=n(p,r.mount),h=fq(),g=!1,_=()=>{g||(g=!0,i.delete(t),eJ(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 X2(e){for(let t of[...J2.get(e)?.values()??[]])t.close()}Aw(),Ue(),oW(),Bw();var Z2=12e3,Q2=100;function $2(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 iW.add(n),n;for(let e=0;e<n.length;e++){let t=n[e];t-t!==0&&(n[e]=NaN)}return n}function e4(e,t){let n=Object.keys(t.columns);if(n.length===0)throw new jw(`no_columns`);let r=t.columns[n[0]].length;if(n.some(e=>t.columns[e].length!==r))throw new jw(`column_length_mismatch`);let i=new Map(n.map(e=>[e,$2(t.columns[e],t.transfer)]));return t4(e,t.name,i,t.units??{})}function t4(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,Q2);t++)e.push(o.map(e=>{let r=n.get(e)[t];return r===r?String(r):``}).join(`,`));d=e.join(`
|
|
631
|
+
`),f=_w(d)}let p={id:e,name:t,schema:l,rawText:d,parseConfig:f,fromColumns:!0};if(s>1e6){let e=new b0(n,r);return{...p,kind:`columnar`,source:e,data:{meta:``,columnNames:o,units:c,rows:e.sampleRowsSync(Z2)}}}let m={meta:``,columnNames:o,units:c,rows:Re({keys:o,length:s,values:o.map(e=>n.get(e)),text:o.map(()=>null)},i)};return{...p,kind:`memory`,source:new Xw(m),data:m}}function n4(e,t,n){let r=e.fromColumns?r4(e):null;if(!r)throw new jw(`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)?(Rw(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{...i4(e,o,!0),columnSpares:s}}function r4(e){if(e.source instanceof b0)return new Map(e.source.columnMap);let t=Ie(e.data.rows);return t?new Map(t.keys.map((e,n)=>[e,t.values[n]])):null}function i4(e,t,n=!1){let r=e.fromColumns?r4(e):null;if(!r)throw new jw(`invalid_argument`,{reason:`only datasets added with addColumns can be replaced`});let i=r;for(let e of Object.keys(t))i.set(e,$2(t[e],n));let a=i.values().next().value.length;for(let e of i.values())if(e.length!==a)throw new jw(`column_length_mismatch`);let o=Object.fromEntries(e.schema.map(e=>[e.name,e.unit])),s=t4(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}}var a4=new WeakMap;function o4(e){let t=e.fromColumns?r4(e):null;if(!t)return e.rawText??``;let n=e.data.rows,r=a4.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(`,`));a4.set(n,r=a.join(`
|
|
632
|
+
`))}return r}function s4(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 c4(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 l4(){let e=c4(e=>{let t={};for(let n of e){if(!n.beacon||n.kind!==`memory`)continue;let{channel:e,metric:r,stat:i}=n.beacon,a=cK(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:fK(n.id,t),name:`${n.name} · Cycle ${t+1}`,data:r,source:new Xw(r)}}),values:a.map(e=>lK(n.data.rows,e,r,i)),unit:o,isTime:i===`span`&&dK(r,o)}}return t}),t=c4((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=c4((e,t)=>e.filter(e=>t.includes(e.id))),r=c4(e=>v0(e.map(e=>e.data))),i=c4((e,t)=>t.length===0?e:v0(e?[e,...t.map(e=>e.dataset)]:t.map(e=>e.dataset))),a=c4((e,t,n)=>{let r=new Set;if(e)for(let t of n.length>0?n:[e])for(let e of y0(t.columnNames,t.rows))r.add(e);let i=e?e.columnNames.filter(e=>r.has(e)):[],a=t.filter(e=>e.kind!==`memory`).flatMap(e=>VG(e.schema));return[...new Set([...i,...a])]});return{lapsByDataset:e,selectedDatasets:t,selectedLive:n,staticDataset:r,mergedDataset:i,mergedParts:c4((e,t)=>[...e.map(e=>e.data),...t.map(e=>e.dataset)]),numericColumns:c4((e,t,n,r=[])=>{let i=a(e,t,r),o=new Set(i);return[...i,...n.map(e=>e.name).filter(e=>!o.has(e))]}),allColumns:c4((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:c4((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 u4=[{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:`qqplot`,label:`Q-Q Plot`},{kind:`gantt`,label:`Gantt Chart`}],d4=new Map(u4.map(e=>[e.kind,e.label]));function f4(e){return d4.get(e)??e}var p4=`kymoscope-live.v1`,m4=2e3,h4=30,g4=1e4,_4=300,v4=90,y4=e=>e.startsWith(`eyJ`);function b4(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 x4(e,t){return`${e.replace(/\/+$/,``)}/v1/streams/${t}/watch`}function S4(e,t,n,r){let i=null,a=null,o=null,s=!1,c=()=>{o&&=(clearTimeout(o),null)},l=(n,r)=>{c();let a=b4(r);if(a===null)return;let u=y4(r),d=u?Math.min(a,Date.now()/1e3+_4):a,f=Math.min(Math.max((d-(u?v4:h4))*1e3-Date.now(),g4),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}l(n,r)}},f)},u=()=>{s||a||(a=setTimeout(()=>{a=null,d()},m4))},d=async()=>{if(s)return;let a=null;try{a=await e.getToken(t)}catch{a=null}if(s)return;if(!a){r?.(`error`),u();return}let o=new WebSocket(x4(e.url,t),[p4,`bearer.${a}`]);o.binaryType=`arraybuffer`,i=o;let d=a;o.onopen=()=>{r?.(`subscribed`),l(o,d)},o.onmessage=e=>{typeof e.data!=`string`&&n(e.data)},o.onclose=()=>{i===o&&(i=null,c(),!s&&(r?.(`error`),u()))}};return d(),()=>{if(s=!0,a&&=(clearTimeout(a),null),c(),i){let e=i;i=null,e.close(1e3)}}}qw();var C4=class{#e;constructor(e){this.#e=typeof e==`function`?e:()=>e}size(){return this.#e().size}version(){return this.#e().version}columns(){let e=this.#e();return new w4(new Set(e.columnNames),t=>e.mirrorColumn(t))}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 Ww(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);Number.isFinite(e)&&n.set(r,e)}return n}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 dispose(){}},w4=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)}};yW();var T4=4096,E4=5e3,D4=class{startedAt=Date.now();n=0;capacity=T4;time=new Float64Array(T4);cols=new Map;order=[];units=new Map;timeColumn;timeUnit;constructor(e=mW,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=fW(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(O4).join(`,`)}\n${t.map(O4).join(`,`)}\n`],r=this.order.map(e=>this.cols.get(e));for(let e=0;e<this.n;e+=E4){let t=Math.min(this.n,e+E4),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+=`
|
|
633
|
+
`}n.push(i)}return n}};function O4(e){let t=/^[=+\-@\t\r]/.test(e)?`'${e}`:e;return/[",\n\r]/.test(t)?`"${t.replace(/"/g,`""`)}"`:t}yW();var k4=512,A4=new WeakMap;function j4(e,t,n){let r=A4.get(e);r||A4.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 M4(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=FC(n.formula);if(!o.ok)continue;let{identifiers:s,functions:c}=IC(o.node);if(!s.every(e=>a.has(e)))continue;let l=c.some(e=>NC.includes(e)),u=Math.max(e.firstAbs,i-(l?k4:0)),d=new Map([mW,...s].map(t=>[t,e.range(t,u,r)])),{carry:f,keep:p}=j4(e,`${n.id}|${n.formula}`,u),m=HC(n,e=>d.get(e),mW,r-u,t,f);m.status===`ok`&&(e.writeComputed(n.name,n.units,i,m.values.subarray(i-u)),p())}}function N4(e,t){e.clearComputed(),A4.delete(e),M4(e,t,e.firstAbs)}GU(),BW(),yW(),GW(),YU(),tG();var P4=1e7,F4=512,I4=400,L4=4e3,R4=1e3;function z4(e,t){let n=new vW(t.capacity??P4,void 0,void 0,(t.maxMemoryMB??F4)*1024*1024);return{meta:e,buffer:n,source:new C4(()=>n),unsub:()=>{},status:`connecting`,error:null,lastFrameAt:Date.now(),lastColCount:0,recorder:null,schemas:new Map}}function B4(e,t,n=()=>({})){let r=new Map,i=e,a=[],o=[],s=``,c=()=>{let e=[];for(let t of r.values())t.lastColCount=t.buffer.columnNames.length,e.push({...t.meta,dataset:t.buffer.toDataset(I4),source:t.source,rowCount:t.buffer.size,status:t.status,error:t.error,recordingSince:t.recorder?.startedAt??null});a=e,t(a)},l=(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&&d(e,r)},u=(e,t)=>{let n=e.buffer.endAbs;e.buffer.pushColumns(t),e.recorder?.addColumns(t),t.t.length>0&&d(e,n)},d=(e,t)=>{M4(e.buffer,o,t),e.lastFrameAt=Date.now();let n=e.status===`stale`||e.status===`connecting`;n&&(e.status=`live`),(n||e.buffer.columnNames.length!==e.lastColCount)&&c()},f=e=>{let t=r.get(e);t&&(t.unsub(),r.delete(e),c())},p=setInterval(()=>{let e=Date.now(),t=!1;for(let n of r.values())n.status===`live`&&e-n.lastFrameAt>L4&&(n.status=`stale`,t=!0);t&&c()},R4);return{connections:()=>a,disconnect:f,startRecording(e){let t=r.get(e);!t||t.recorder||(t.recorder=new D4,c())},stopRecording(e){let t=r.get(e),n=t?.recorder;return!t||!n?null:(t.recorder=null,c(),{csv:n.toCsvParts(),rows:n.rows,name:t.meta.name,startedAt:n.startedAt})},setRelay(e){i=e},setMathChannels(e){let t=JSON.stringify(e.map(e=>[e.id,e.name,e.units,e.formula,e.enabled]));if(t!==s){s=t,o=e;for(let t of r.values())N4(t.buffer,e);r.size>0&&c()}},openLocal(e,t){let i=`local:${crypto.randomUUID()}`,a=z4({id:i,name:e,ownerName:`This page`,visibility:`private`,orgName:null},{...n(),...t});return r.set(i,a),c(),{id:i,push:e=>{r.get(i)===a&&l(a,Array.isArray(e)?e:[e])},pushColumns:e=>{r.get(i)===a&&u(a,e)},close:()=>f(i)}},async connect(e,t,a){if(r.has(e.id))return;let o=i&&e.relay_url?{...i,url:e.relay_url}:i;if(!o)throw new jw(`relay_unavailable`);let s=typeof t==`string`?await CW(OW(t).secret??t,e.salt):`keyFor`in t?e=>t.keyFor(e):t;if(typeof s!=`function`&&!await DW(s,e.key_check))throw new jw(`wrong_password`);let d=z4({id:e.id,name:e.name,ownerName:e.owner_name??``,visibility:e.visibility??`private`,orgName:e.org_name??null,projectName:e.project_name??null},{...n(),...a});r.set(e.id,d);let f=Promise.resolve();d.unsub=S4(o,e.id,t=>{let n=HW(s,t).catch(()=>null);f=f.then(async()=>{try{let t=await n;if(!t||r.get(e.id)!==d)return;if(t.kind===5){let e=KW(t.plaintext);d.schemas.set(e.id,e);return}if(t.kind===4){let e=await JW(t.plaintext,d.schemas);e&&!e.historical&&u(d,e.block);return}if(t.kind===3)return u(d,KU(t.plaintext));if(t.kind!==2)return;let i=UU(t.plaintext);l(d,Array.isArray(i?.frames)?i.frames:[])}catch{}})},e=>{e===`subscribed`?(d.status=`live`,d.lastFrameAt=Date.now()):e===`error`&&(d.status=`error`,d.error=`connection_error`),c()}),c()},dispose(){clearInterval(p);for(let e of r.values())e.unsub();r.clear(),a=[]}}}var V4=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}},H4={maxChartsPerWorksheet:null,maxChannelsPerChart:null,maxWorksheets:null,maxMathChannels:null,canImportExportWorkspaces:!0};Aw(),yW();var U4=[],W4=[`#a78bfa`,`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#94a3b8`];function G4(e=`ET`){return{id:crypto.randomUUID(),name:`Worksheet`,panels:[],panelChartSettings:{},panelChartBackgrounds:{},xKey:e}}function K4(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(Fe({...e,name:a,source:`workbook`}))}return{channels:i,rename:r}}function q4(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 J4(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 Y4(e,t,n){if(!e||!t)return A();let{min:r,max:i}=HG(e.rows,t);if(!Number.isFinite(r)||!Number.isFinite(i))return A();let a=Math.max(1,Math.round(WG(i-r||1,6)));return{...n,scaleMin:String(Math.floor(r)),scaleMax:String(Math.ceil(i)),majorStep:String(a),minorStep:``}}function X4(e,t){let n=t.includes(e.xKey)?e.xKey:t.includes(`ET`)?`ET`: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:B();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:V(W4[2]),a=t.includes(i.xyXCol)?i.xyXCol:t[0],o=t.includes(i.xyYCol)&&i.xyYCol!==t[0]?i.xyYCol:t.length>1?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:H(4),a=t.includes(i.xyzXCol)?i.xyzXCol:t[0],o=t.length>1?t[1]:``,s=t.includes(i.xyzYCol)&&i.xyzYCol!==t[0]?i.xyzYCol:t.length>1?t[1]:t[0],c=t.includes(i.xyzZCol)&&i.xyzZCol!==t[0]&&i.xyzZCol!==o?i.xyzZCol:t.length>2?t[2]:t[0];r[n.id]={...i,kind:`xyzmesh`,xyzXCol:a,xyzYCol:s,xyzZCol:c}}}return{...e,xKey:n,panelChartSettings:r}}function Z4(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 Q4(){return typeof document>`u`?`dark`:aK(null)}function $4(e={}){let t={...e},n=!1,r=G4(),i=s4({datasets:[],selection:[],worksheets:[r],activeWorksheetId:r.id,xRanges:{},offsets:{},colors:{},liveWindowSeconds:15,live:[],mathChannels:[],limits:{...H4,...t.limits},palette:nK(t.palette,Q4()),importing:0,licensed:null,history:{canUndo:!1,canRedo:!1}}),a=fq(),o=()=>{let e=nK(t.palette,Q4());i.set(t=>t.palette.join()===e.join()?t:{...t,palette:e})},s=typeof document>`u`?()=>{}:oK(null,o),c=l4(),l=()=>{if(n)throw new jw(`disposed`)},u=e=>{throw a.emit(`limit`,{reason:e}),new jw(`limit_reached`,{reason:e})},d=()=>i.get(),f=(e,t)=>{let n=d().limits.maxChannelsPerChart,r=UG(t);n!==null&&r>n&&r>UG(e)&&u(`channels-per-chart`)},p=c4((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)),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??U4,layout:t.rect}),g=c4((e,t)=>e.map(e=>({id:e.id,name:e.name,xKey:e.xKey,xRange:t[e.id]??null,charts:e.panels.map(t=>h(e,t))}))),_=c4((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:eK(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,laps:c?c.laps.map((e,i)=>({id:e.id,name:e.name,value:c.values[i],unit:c.unit,isTime:c.isTime,color:eK(n,e.id,s(e.id,i),o),offset:r[e.id]??0,selected:t.includes(e.id)})):null,selected:c?u===0?!1:u===l.length?!0:`partial`:t.includes(e.id)}})}),b=c4((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,status:e.status,error:e.error,rowCount:e.rowCount,selected:t.includes(e.id),color:eK(n,e.id,a.includes(e.id)?r+a.indexOf(e.id):o,i),customColor:e.id in n,recordingSince:e.recordingSince}))}),x=c4(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),activeWorksheetId:e.activeWorksheetId,mathChannels:t.channels,live:b(e.live,e.selection,e.colors,t.selectedDatasets.length,e.palette),liveWindowSeconds:e.liveWindowSeconds,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}}),S=(e,t)=>e===t||e.length===t.length&&e.every((e,n)=>e===t[n]||JSON.stringify(e)===JSON.stringify(t[n])),C=new V4({limit:100,mergeMs:500,now:()=>Date.now(),equals:(e,t)=>e.liveWindowSeconds===t.liveWindowSeconds&&S(e.worksheets,t.worksheets)&&S(e.channels,t.channels)}),w=!0,T=0,E=e=>{T++;try{e()}finally{T--}},O=e=>[e.worksheets,e.mathChannels,e.liveWindowSeconds],A=[],j=()=>{let e=d();return{worksheets:e.worksheets,channels:e.mathChannels.filter(e=>e.source===`workbook`),liveWindowSeconds:e.liveWindowSeconds,activeWorksheetId:e.activeWorksheetId}},M=()=>i.set(e=>e.history.canUndo===C.canUndo&&e.history.canRedo===C.canRedo?e:{...e,history:{canUndo:C.canUndo,canRedo:C.canRedo}}),N=()=>{if(w)return;let e=O(d());e.every((e,t)=>e===A[t])||(A=e,T?C.rebase(j()):C.observe(j()),M())},P=()=>{A=O(d()),C.clear(j()),M()},F=e=>{w=!0;let t;try{t=e()}finally{w=!1}return P(),t},I=()=>x(d());i.subscribe(()=>{N(),a.emit(`change`,I())});let L=e=>{let t=d(),n=t.worksheets.find(n=>n.id===(e??t.activeWorksheetId));if(!n)throw new jw(`not_found`,{worksheetId:e});return n},R=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 jw(`not_found`,{chartId:e})},z=(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}),B=(e,t)=>{let{ws:n}=R(e);z(n.id,n=>({...n,panelChartSettings:{...n.panelChartSettings,[e]:t(n.panelChartSettings[e])}}))},V=e=>i.set(t=>e.length===t.selection.length&&e.every((e,n)=>e===t.selection[n])?t:{...t,selection:e,xRanges:{}}),H=new Set,U=B4(t.live?.relay,e=>{let t=e.map(e=>e.id),n=t.filter(e=>!H.has(e)),r=[...H].filter(e=>!t.includes(e));if(H=new Set(t),i.set(t=>({...t,live:e})),r.length&&V(d().selection.filter(e=>!r.includes(e))),n.length){let e=d().selection,t=n.filter(t=>!e.includes(t));t.length&&V([...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)||E(()=>z(t.id,e=>({...e,xKey:mW})))}},()=>({capacity:t.live?.capacity,maxMemoryMB:t.live?.maxMemoryMB})),W=c4((e,t)=>e.filter(e=>t.some(t=>rw([e],t.panelChartSettings,t.xKey).length>0))),ee=()=>U.setMathChannels(W(p(d().mathChannels,d().limits.maxMathChannels),d().worksheets));ee(),i.subscribe(ee);let te=e=>{i.set(t=>({...t,datasets:[...t.datasets,e]})),V([...d().selection,e.id]);let t=VG(e.schema);t.length&&E(()=>i.set(e=>({...e,worksheets:e.worksheets.map(e=>X4(e,t))})))},ne=Promise.resolve(),G=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 jw(`import_vetoed`);let{signal:s}=r;i.set(e=>({...e,importing:e.importing+o.length}));let c=ne.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 lL(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 BG({main:t,companions:i.companions,format:i.format.id},{priorInMemoryValues:kI(d().datasets),signal:s,onProgress:e=>a.emit(`import`,{file:t.name,phase:`progress`,fraction:e}),chooseChannels:r.chooseChannels,pickChannels:r.pickChannels}):[await OI(crypto.randomUUID(),t,d().datasets)??await EI(crypto.randomUUID(),t,J4,void 0,kI(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 jw(`cancelled`)}for(let t of o)te(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 jw&&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 ne=c.catch(()=>void 0),c},re=()=>setTimeout(()=>{n||P2(Ke)},0),ie=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}}),V(d().selection.filter(e=>!t(e))),n.length>0&&re()},ae=async(e,t)=>{let[n,...r]=await BG({main:new File(e.chunks,`${e.name}.krc`),companions:[],format:`krc`,keys:e.keys},{priorInMemoryValues:t});for(let e of r)e.source.dispose();return{...n,file:void 0,name:e.name,info:n.info&&{...n.info,startTime:e.startTime??n.info.startTime,meta:{...n.info.meta,recordingId:e.recordingId}}}},oe={importFiles:G,warmImport(e={}){l(),OG(!!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 jw(`not_found`,{datasetId:e});if(!t.info?.combined||!(t.file instanceof File))throw new jw(`invalid_argument`,{reason:`only a combined multi-rate import can be split`});let n=await BG({main:t.file,companions:t.companions??[],format:t.info.importer},{priorInMemoryValues:kI(d().datasets.filter(t=>t.id!==e)),selection:t.info.selection,split:!0});ie([e]);for(let e of n)te(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 jw(`not_found`,{datasetId:e});if(!n.info||!(n.file instanceof File))throw new jw(`invalid_argument`,{reason:`only binary imports have channels to choose`});try{let r=await BG({main:n.file,companions:n.companions??[],format:n.info.importer},{priorInMemoryValues:kI(d().datasets.filter(t=>t.id!==e)),initial:n.info.selection,chooseChannels:t,pickChannels:!0});ie([e]);for(let e of r)te(e);return r.map(e=>e.id)}catch(e){if(e instanceof jw&&e.code===`cancelled`)return null;throw e}},async combine(e){l();let t=d().datasets.find(t=>t.id===e);if(!t)throw new jw(`not_found`,{datasetId:e});let n=t.info?.splitKey;if(!n||!(t.file instanceof File))throw new jw(`invalid_argument`,{reason:`only datasets split from one file can be combined`});let r=d().datasets.filter(e=>e.info?.splitKey===n),i=await BG({main:t.file,companions:t.companions??[],format:t.info.importer},{priorInMemoryValues:kI(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 jw(`invalid_argument`,{reason:`these groups have no common time base`})}return ie(r.map(e=>e.id)),te(i[0]),i[0].id},async openRecording(e){l();let t=await ae(e,kI(d().datasets));return te(t),t.id},async reopenRecording(e,t){l();let n=d().datasets.find(t=>t.id===e);if(!n)throw new jw(`not_found`,{datasetId:e});let r=await ae(t,kI(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),re()},addColumns(e){l();let t=e4(crypto.randomUUID(),e);return te(t),t.id},replaceColumns(e,t,n={}){l();let r=d().datasets.find(t=>t.id===e);if(!r)throw new jw(`not_found`,{datasetId:e});let a=i4(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 jw(`not_found`,{datasetId:e});let a=n4(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 CI(crypto.randomUUID(),t,e);return te(n),n.id},remove(e){l(),ie([e])},clear(){l(),ie(d().datasets.map(e=>e.id))},async configure(e,t){l();let n=d().datasets.find(t=>t.id===e);if(!n)throw new jw(`not_found`,{datasetId:e});if(t.parseConfig&&(n.kind!==`memory`||!n.parseConfig))throw new jw(`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 jw(`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?cK(n.data.rows,r.channel):[],l=r&&t.selectCycles===`best`?uK(c.map(e=>lK(n.data.rows,e,r.metric,r.stat))):null,u=l===null?c.map((t,n)=>fK(e,n)):[fK(e,l)];V(o?c.length>0?[...s,...u]:[...s,e]:s)}let r=t.parseConfig;if(!r)return;let a=(()=>{try{let e=vw(mw(n.rawText??``),r.headerRow);return n.data.columnNames.length===e.length&&n.data.columnNames.every((t,n)=>t===e[n])}catch{return!1}})();if(hw(r,n.parseConfig)&&a)return;let o=n.fromColumns?o4(n):n.rawText??``,s=await Iw(n.file?{file:n.file,config:r}:{rawText:o,config:r}),c=new Xw(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),re();let p=m().selectedDatasets,h=new Set(p.flatMap(e=>e.data.columnNames)),g=s.columnNames.filter(e=>Cw(s.rows,e)),_=g.find(e=>e===`ET`)??g[0];E(()=>i.set(e=>({...e,worksheets:e.worksheets.map(e=>Z4(!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(),V([...e])},toggle(e){l();let t=d().selection,n=m().laps[e];if(n){let e=n.laps.map(e=>e.id);V(e.every(e=>t.includes(e))?t.filter(t=>!e.includes(t)):[...t,...e.filter(e=>!t.includes(e))]);return}V(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);V([...d().datasets.flatMap(t=>e[t.id]?e[t.id].laps.map(e=>e.id):[t.id]),...t])},deselectAll(){l(),V([])},raw(e){let t=d().datasets.find(t=>t.id===e);if(!t)throw new jw(`not_found`,{datasetId:e});return{get rawText(){return t.kind===`memory`&&t.fromColumns?o4(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=HG(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.xBoundsSync(e);if(Number.isFinite(t.x0)&&Number.isFinite(t.x1))return{min:t.x0,max:t.x1}}let i=se(e);if(!i)return null;let a=HG(i.rows,e);return Number.isFinite(a.min)&&Number.isFinite(a.max)?a:null}},se=(e,t=L().xKey)=>{let n=m();if(!n.merged)return null;if(!n.channels.find(t=>t.name===e))return n.merged;let r=nw(n.merged,n.channels,t);return{...n.merged,columnNames:[...n.merged.columnNames,...r.ok.map(e=>e.name)],rows:r.rows}},ce=(e,t,n)=>m().selectedLive.length>0?{...n,scaleMin:``,scaleMax:``,majorStep:``,minorStep:``}:Y4(se(e,t),e,n),le={fromFileList:e=>UK(Array.from(e)),async fromDataTransfer(e){return WK(Array.from(e.items??[]).map(e=>e.webkitGetAsEntry?.()).filter(e=>!!e))},canPick:GK,pick:KK,tree:(e,t)=>HK(e,t),isImportable:VK},ue={add(e=`Worksheet`){l();let t=d(),n=t.limits.maxWorksheets;n!==null&&t.worksheets.length>=n&&u(`worksheets`);let r={...G4(L().xKey||`ET`),name:e};return i.set(e=>({...e,worksheets:[...e.worksheets,r],activeWorksheetId:r.id})),r.id},rename(e,t){l(),L(e),z(e,e=>e.name===t?e:{...e,name:t})},remove(e){l();let t=d();if(L(e),t.worksheets.length<=1)throw new jw(`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(),L(e),i.set(t=>t.activeWorksheetId===e?t:{...t,activeWorksheetId:e,xRanges:{...t.xRanges,[e]:null}})},setXKey(e,t){l(),L(e),z(e,e=>Z4({...e,xKey:t},e=>e!==t)),i.set(t=>({...t,xRanges:{...t.xRanges,[e]:null},offsets:{}}))}},de={mount(e,t,n){return l(),N2(Ke,e,t,n)},openWindow(e,t){return l(),R(e),Y2(Ke,e,(t,n)=>N2(Ke,e,t,n),t)},setFonts(e){e.sans&&(X.sans=e.sans),e.mono&&(X.mono=e.mono),P2(Ke)},kinds:()=>u4,label:f4,add(e,t={}){if(l(),!u4.some(t=>t.kind===e))throw new jw(`invalid_argument`,{kind:e});let n=L(t.worksheetId),r=d().limits.maxChartsPerWorksheet;r!==null&&n.panels.length>=r&&u(`charts-per-worksheet`);let i={...D(e,n.panels),...t.title?{title:t.title}:{}};t.layout&&(i.rect={...t.layout});let a=Ne([i],{},W4[2],4)[i.id],o=a,s=m().numericColumns;if(s.length&&(o.kind===`multiband`||o.kind===`xyscatter`||o.kind===`xyzmesh`)&&(o=X4({...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??ce(o.xyXCol,n.xKey,o.xyXScale),xyYScale:e.xyYScale??ce(o.xyYCol,n.xKey,o.xyYScale)}}return f(a,o),z(n.id,e=>({...e,panels:t.layout?[...e.panels,i]:k([...e.panels,i]),panelChartSettings:{...e.panelChartSettings,[i.id]:o}})),i.id},remove(e){l();let{ws:t}=R(e);z(t.id,t=>{let n={...t.panelChartSettings},r={...t.panelChartBackgrounds};return delete n[e],delete r[e],{...t,panels:k(t.panels.filter(t=>t.id!==e)),panelChartSettings:n,panelChartBackgrounds:r}})},rename(e,t){l();let{ws:n}=R(e),r=t?.trim()||void 0;z(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}=R(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:ce(e.xyXCol,n.xKey,r.xyXScale)}),typeof e.xyYCol==`string`&&e.xyYCol!==r.xyYCol&&!(`xyYScale`in e)&&(i={...i,xyYScale:ce(e.xyYCol,n.xKey,r.xyYScale)})}f(r,i),B(e,()=>i)},replaceSettings(e,t){l();let{ws:n,panel:r}=R(e);if(t.kind!==r.kind)throw new jw(`invalid_argument`,{reason:`settings kind mismatch`});f(n.panelChartSettings[e],t),B(e,()=>t)},setBackground(e,t){l();let{ws:n}=R(e);z(n.id,n=>({...n,panelChartBackgrounds:{...n.panelChartBackgrounds,[e]:t}}))},addAnnotation(e,t){l(),R(e);let n=v({...t,id:t.id||crypto.randomUUID()});if(!n)throw new jw(`invalid_argument`,{reason:`not a valid annotation`});return B(e,e=>({...e,annotations:[...(e.annotations??[]).filter(e=>e.id!==n.id),n]})),n.id},updateAnnotation(e,t,n){l();let r=(R(e).ws.panelChartSettings[e]?.annotations??[]).find(e=>e.id===t);if(!r)throw new jw(`not_found`,{annotationId:t});let i=v({...r,...n,id:r.id,kind:r.kind});if(!i)throw new jw(`invalid_argument`,{reason:`not a valid annotation`});B(e,e=>({...e,annotations:(e.annotations??[]).map(e=>e.id===i.id?i:e)}))},removeAnnotation(e,t){l(),R(e),B(e,e=>({...e,annotations:(e.annotations??[]).filter(e=>e.id!==t)}))},setAnnotations(e,t){l(),R(e);let n=y(t)??[];B(e,e=>({...e,annotations:n}))},setLayout(e,t){l();let{ws:n}=R(e);z(n.id,n=>({...n,panels:n.panels.map(n=>n.id===e?{...n,rect:{...t}}:n)}))},setLayouts(e,t){l(),z(e,e=>({...e,panels:e.panels.map(e=>t[e.id]?{...e,rect:{...t[e.id]}}:e)}))},autoLayout(e){l(),z(L(e).id,e=>({...e,panels:k(e.panels)}))},get(e){let{ws:t,panel:n}=R(e);return h(t,n)},list(e){let t=L(e);return t.panels.map(e=>h(t,e))},async addSeries(e,t){l();let{ws:n}=R(e),r=n.panelChartSettings[e];if(!r||r.kind!==`multiband`)throw new jw(`invalid_argument`,{reason:`not a multiband chart`});let i=d().limits.maxChannelsPerChart;i!==null&&UG(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=Pe(),f={id:c,column:s,color:W4[r.series.length%W4.length],bandFromPct:0,bandToPct:100,scaleMin:0,scaleMax:1,yMajorStep:0,yMinorStep:0};return B(e,e=>e.kind===`multiband`?{...e,series:[...e.series,f]}:e),await de.autoScaleSeries(e,c),c},async updateSeries(e,t,n){l();let{ws:r}=R(e),i=r.panelChartSettings[e],a=i&&i.kind===`multiband`?i.series.find(e=>e.id===t):void 0;if(!a)throw new jw(`not_found`,{seriesId:t});B(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 de.autoScaleSeries(e,t)},removeSeries(e,t){l(),B(e,e=>e.kind===`multiband`?{...e,series:e.series.filter(e=>e.id!==t)}:e)},reorderSeries(e,t){l(),B(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}=R(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 oe.columnBounds(a.column);!o||n||B(e,e=>e.kind===`multiband`?{...e,series:e.series.map(e=>e.id===t?{...e,scaleMin:o.min,scaleMax:o.max}:e)}:e)}},fe={setXRange(e,t){l();let n=L(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){fe.setXRange(null,e)},setLiveWindow(e){l(),i.set(t=>t.liveWindowSeconds===e?t:{...t,liveWindowSeconds:e})}},pe={create(e){l();let n=d(),r=n.limits.maxMathChannels;r!==null&&n.mathChannels.length>=r&&u(`math-channels`);let o=Fe(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 jw(`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 jw(`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 ow(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:()=>iw(d().mathChannels),preview(e,t){let n=m();return n.merged?RC(e,n.merged,L(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}})}},me={openLocal(e,t){return l(),U.openLocal(e,t)},async connect(e,t,n){l(),await U.connect(e,t,n)},startRecording(e){l(),U.startRecording(e)},stopRecording(e){return l(),U.stopRecording(e)},rowCount(e){return U.connections().find(t=>t.id===e)?.source.size()??0},disconnect(e){l(),U.disconnect(e),V(d().selection.filter(t=>t!==e))}},he=()=>{d().limits.canImportExportWorkspaces||u(`workspaces-io`)},ge=async e=>{if(e instanceof Blob)try{return JSON.parse(await e.text())}catch{throw new jw(`bad_file`)}if(typeof e==`string`)try{return JSON.parse(e)}catch{throw new jw(`bad_file`)}return e},_e=async e=>e instanceof File?e:new File([JSON.stringify(await ge(e))],`import.json`,{type:`application/json`}),ve=e=>e.replace(/[^\w.-]+/g,`_`),ye=e=>new Blob([JSON.stringify(e,null,2)],{type:`application/json`}),be=e=>{let t=Me(e.panelChartSettings,W4[2],4),n={};for(let r of e.panels)t[r.id]?.kind===r.kind&&(n[r.id]=t[r.id]);return{...e,panelChartSettings:Ne(e.panels,n,W4[2],4)}},xe=e=>{let t=m().numericColumns;return t.length?X4(e,t):e},Se=(e,t=0)=>{let n=d().limits.maxWorksheets,r=(n===null?e:e.slice(0,Math.max(1,n))).map(e=>xe(be(e))),a=r[Math.min(t,r.length-1)];i.set(e=>({...e,worksheets:r,activeWorksheetId:a.id,xRanges:{}}))},Ce=(e,t)=>{let n=L(t),r=d().limits.maxChartsPerWorksheet;r!==null&&n.panels.length>=r&&u(`charts-per-worksheet`);let i=d().limits.maxChannelsPerChart;i!==null&&UG(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 z(n.id,t=>({...t,panels:k([...t.panels,o]),panelChartSettings:{...t.panelChartSettings,[a]:e.settings},panelChartBackgrounds:e.background===null?t.panelChartBackgrounds:{...t.panelChartBackgrounds,[a]:e.background}})),a},we=()=>{let e=d();return TK({worksheets:e.worksheets,activeWorksheetId:e.activeWorksheetId,channels:W(p(e.mathChannels,e.limits.maxMathChannels),e.worksheets),liveWindowSeconds:e.liveWindowSeconds,laps:e.datasets.find(e=>e.beacon)?.beacon??null})},Te=e=>{if(e.worksheets.length===0)throw new jw(`bad_workspace`,{errors:e.errors});let{channels:t,rename:n}=K4(d().mathChannels,e.mathChannels);Se(n.size?e.worksheets.map(e=>q4(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}));let r=e.laps;if(r)for(let e of d().datasets)e.kind!==`memory`||e.beacon||!e.data.columnNames.includes(r.channel)||oe.configure(e.id,{beacon:r}).catch(e=>a.emit(`error`,{error:e,context:`io.openWorkbook`}));return{worksheets:e.worksheets.length,errors:e.errors}},Ee=e=>{if(e===null)return;let t=e.worksheets.map(xe);w=!0;try{i.set(n=>{let r=t=>e.worksheets.some(e=>e.id===t);return{...n,worksheets:t,activeWorksheetId:r(n.activeWorksheetId)?n.activeWorksheetId:r(e.activeWorksheetId)?e.activeWorksheetId:e.worksheets[0].id,xRanges:Object.fromEntries(Object.entries(n.xRanges).filter(([e])=>r(e))),mathChannels:[...n.mathChannels.filter(e=>e.source!==`workbook`),...e.channels],liveWindowSeconds:e.liveWindowSeconds}})}finally{w=!1}A=O(d()),C.rebase(j()),M()},De={undo(){l(),Ee(C.undo())},redo(){l(),Ee(C.redo())},clear(){l(),P()}},Oe={hasWork:()=>IK(d().worksheets),exportWorksheet(e){l(),he();let t=L(e),n=EK(t);return{json:n,blob:ye(n),filename:`${ve(t.name||`worksheet`)}.json`}},exportChart(e){l(),he();let{ws:t,panel:n}=R(e),r=DK(n,t.panelChartSettings[e],t.panelChartBackgrounds[e]??null);return{json:r,blob:ye(r),filename:`${ve(n.title?.trim()||n.kind)}.json`}},parseFile:e=>zK(e),exportWorkspace(){l(),he();let e=we();return{json:e,blob:ye(e),filename:`kymoscope-workspace-${new Date().toISOString().slice(0,10)}.json`}},async exportWorkspaceEncrypted(e){l(),he();let t=typeof e==`string`?await hK(we(),e):await gK(we(),e);return{json:t,blob:ye(t),filename:`kymoscope-workbook-${new Date().toISOString().slice(0,10)}.kymo`}},async importWorkspace(e,t={}){l(),he();let n=await ge(e);return _K(n)&&(n=await bK(n,t)),F(()=>Te(FK(n)))},toWorkbook:we,openWorkbook(e){return l(),F(()=>Te(FK(e)))},async importWorksheet(e){l(),he();let t=d();t.limits.maxWorksheets!==null&&t.worksheets.length>=t.limits.maxWorksheets&&u(`worksheets`);let n=await zK(await _e(e));if(n.type!==`worksheet`)throw new jw(`bad_file`,{found:n.type});let r=xe(be(n.worksheet));return i.set(e=>({...e,worksheets:[...e.worksheets,r],activeWorksheetId:r.id})),r.id},async importChart(e,t){l(),he();let n=await zK(await _e(e));if(n.type!==`chart`)throw new jw(`bad_file`,{found:n.type});return Ce(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(be):[G4()];F(()=>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(),F(()=>{ie(d().datasets.map(e=>e.id));let e=G4();i.set(t=>({...t,worksheets:[e],activeWorksheetId:e.id,xRanges:{},offsets:{},colors:{},mathChannels:t.mathChannels.filter(e=>e.source!==`workbook`)}))})}},ke={merged(e){let t=m();if(!t.merged||t.channels.length===0)return t.merged;let n=nw(t.merged,t.channels,L(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}},Ae=typeof location<`u`?location.hostname:``,je=t.license,Ie=t.licenseKey,Le=!1,Re={},ze=e=>{n||i.set(t=>({...t,licensed:e}))},Be=(e,t,n)=>{clearTimeout(Re[e]);let r=Math.max(0,t-Date.now()),i=r>2**31-1;Re[e]=setTimeout(()=>{i?Be(e,t,n):n()},i?2**31-1:r)},Ve=e=>Be(`renew`,e,()=>void Ue()),He=e=>Be(`expiry`,e*1e3+1e3,()=>{QK(Ie,Ae).then(e=>{n||ze(e.ok)})});async function Ue(){let e=36e5,t,r=null,i;try{t=await Promise.race([je.get(),new Promise((e,t)=>{i=setTimeout(()=>t(Error(`timeout`)),3e4)})]),r=await QK(t,Ae)}catch{}finally{clearTimeout(i)}if(n)return!1;if(r?.ok)return Ie=t,Le=!0,ze(!0),He(r.exp),Ve(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 QK(Ie,Ae);return n?!1:(ze(a.ok),Ve(Date.now()+e),a.ok)}let We=!je||t.licenseKey?QK(t.licenseKey,Ae).then(e=>(e.ok||console.warn(`[kymoscope] license ${e.reason}: showing attribution`),!Le&&!n&&(ze(e.ok),e.ok&&je&&He(e.exp)),e.ok)):null,Ge=je?Ue():We;w=!1,P();let Ke={getState:I,subscribe(e){return i.subscribe(e)},on:a.on,licensed:Ge,isLicensed:()=>d().licensed,setOptions(e){if(l(),t={...t,...e},e.live&&U.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:oe,folders:le,worksheets:ue,charts:de,view:fe,mathChannels:pe,live:me,io:Oe,history:De,data:ke,dispose(){if(!n){n=!0,clearTimeout(Re.renew),clearTimeout(Re.expiry),s(),X2(Ke),F2(Ke),U.dispose();for(let e of d().datasets)e.source.dispose().catch(()=>void 0);a.clear()}}};return e3.set(Ke,{store:i,derived:m,live:U}),Ke}var e3=new WeakMap;function t3(e){let t=e3.get(e);if(!t)throw new jw(`invalid_argument`,{reason:`not a Kymoscope engine`});return t}return t.CHART_KINDS=u4,t.KymoscopeError=jw,t.chartLabel=f4,t.createEngine=$4,t.verifyLicense=QK,t})({});
|