@kymoscope/sdk 0.10.0 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{importer.worker-CLBGjz4d.js → importer.worker-Cgz__4KO.js} +1 -1
- package/dist/assets/liveIngestWorker-BLPTEEc7.js +1 -0
- package/dist/assets/offscreenLineWorker-C-_uNa_H.js +80 -0
- package/dist/{importers-2iwVi4cq.js → importers-D_M42sqZ.js} +1 -1
- package/dist/{keys-DmtCD10T.js → keys-CkI2qrI-.js} +1 -1
- package/dist/kymoscope-embed.js +66 -66
- package/dist/kymoscope-sdk.js +62 -62
- package/dist/types/analysis/ai.d.ts +50 -0
- package/dist/types/analysis/aiCheck.d.ts +54 -0
- package/dist/types/analysis/alertsBefore.d.ts +7 -0
- package/dist/types/analysis/better.d.ts +6 -0
- package/dist/types/analysis/capability.d.ts +10 -0
- package/dist/types/analysis/changes.d.ts +10 -0
- package/dist/types/analysis/containment.d.ts +10 -0
- package/dist/types/analysis/context.d.ts +131 -0
- package/dist/types/analysis/control.d.ts +13 -0
- package/dist/types/analysis/energy.d.ts +4 -0
- package/dist/types/analysis/gap.d.ts +8 -0
- package/dist/types/analysis/golden.d.ts +20 -0
- package/dist/types/analysis/health.d.ts +73 -0
- package/dist/types/analysis/index.d.ts +12 -0
- package/dist/types/analysis/infer.d.ts +68 -0
- package/dist/types/analysis/lines.d.ts +6 -0
- package/dist/types/analysis/losses.d.ts +41 -0
- package/dist/types/analysis/maintenance.d.ts +8 -0
- package/dist/types/analysis/oee.d.ts +30 -0
- package/dist/types/analysis/parts.d.ts +13 -0
- package/dist/types/analysis/presets.d.ts +35 -0
- package/dist/types/analysis/reliability.d.ts +103 -0
- package/dist/types/analysis/report.d.ts +15 -0
- package/dist/types/analysis/shifts.d.ts +7 -0
- package/dist/types/analysis/sinceLast.d.ts +8 -0
- package/dist/types/analysis/stats.d.ts +110 -0
- package/dist/types/analysis/stops.d.ts +34 -0
- package/dist/types/analysis/strip.d.ts +14 -0
- package/dist/types/analysis/text.d.ts +56 -0
- package/dist/types/analysis/types.d.ts +407 -0
- package/dist/types/components/liveWindow.d.ts +6 -2
- package/dist/types/engine/createEngine.d.ts +1 -0
- package/dist/types/engine/liveController.d.ts +7 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/lib/live/liveIngest.d.ts +47 -0
- package/dist/types/lib/live/liveIngestClient.d.ts +9 -0
- package/dist/types/lib/live/liveIngestWorker.d.ts +1 -0
- package/dist/types/lib/live/publisher.d.ts +10 -0
- package/dist/types/lib/live/stream.d.ts +8 -0
- package/dist/types/lib/live/types.d.ts +12 -0
- package/dist/types/lib/render/frames.d.ts +10 -0
- package/dist/types/lib/render/glPoints.d.ts +18 -0
- package/dist/types/lib/render/offscreenLineRenderer.d.ts +15 -1
- package/dist/types/lib/render/sharedGl.d.ts +12 -3
- package/package.json +1 -1
- package/dist/assets/offscreenLineWorker-BQwts3O3.js +0 -80
package/dist/kymoscope-sdk.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*! @kymoscope/sdk (c) 2026 Kymoscope. Proprietary software: use requires a license. See LICENSE.md. */
|
|
2
|
-
import{$ as e,$t as t,A as n,At as r,B as i,Bt as a,C as o,Ct as s,D as c,Dt as l,E as u,Et as d,F as f,G as p,Gt as m,H as h,Ht as g,I as _,J as v,Jt as y,K as b,Kt as x,L as S,M as C,Mt as w,N as T,O as E,Ot as D,P as O,Q as k,Qt as A,R as j,S as M,T as N,U as P,Ut as F,V as I,Vt as L,W as R,Wt as z,X as B,Xt as V,Y as ee,Yt as te,Z as H,Zt as ne,_ as re,_t as ie,a as U,at as ae,b as oe,bt as se,ct as ce,d as le,dt as ue,en as de,et as fe,f as pe,ft as me,g as he,gt as ge,h as _e,ht as ve,i as ye,it as be,j as xe,jt as Se,k as Ce,kt as we,l as Te,lt as Ee,m as De,mt as Oe,n as ke,nn as Ae,nt as je,o as Me,ot as Ne,p as Pe,pt as Fe,q as Ie,qt as Le,r as Re,rn as ze,rt as Be,s as Ve,st as He,tn as Ue,tt as We,u as Ge,ut as Ke,v as qe,vt as Je,w as Ye,wt as Xe,x as Ze,xt as Qe,y as $e,z as et}from"./keys-DmtCD10T.js";import{i as tt,n as nt,r as rt,t as it}from"./threshold-C9it0Y7P.js";import{createContext as at,forwardRef as ot,memo as st,startTransition as ct,useCallback as lt,useContext as ut,useEffect as W,useImperativeHandle as dt,useLayoutEffect as G,useMemo as ft,useRef as K,useState as pt,useSyncExternalStore as mt}from"react";import{createPortal as ht}from"react-dom";import{createRoot as gt}from"react-dom/client";import{Fragment as _t,jsx as q,jsxs as vt}from"react/jsx-runtime";var yt=Object.create,bt=Object.defineProperty,xt=Object.getOwnPropertyDescriptor,St=Object.getOwnPropertyNames,Ct=Object.getPrototypeOf,wt=Object.prototype.hasOwnProperty,Tt=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Et=(e,t)=>{let n={};for(var r in e)bt(n,r,{get:e[r],enumerable:!0});return t||bt(n,Symbol.toStringTag,{value:`Module`}),n},Dt=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=St(t),a=0,o=i.length,s;a<o;a++)s=i[a],!wt.call(e,s)&&s!==n&&bt(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=xt(t,s))||r.enumerable});return e},Ot=(e,t,n)=>(n=e==null?{}:yt(Ct(e)),Dt(t||!e||!e.__esModule?bt(n,`default`,{value:e,enumerable:!0}):n,e)),kt=[`text`,`brush`,`arrow`,`box`],At={text:14,brush:3,arrow:2,box:2},jt=/^#[0-9a-fA-F]{6}$/,Mt={text:[1,1],arrow:[2,2],box:[2,2],brush:[2,1/0]},Nt=e=>typeof e==`number`&&Number.isFinite(e);function Pt(e){if(!e||typeof e!=`object`)return null;let t=e,n=t.kind;if(!kt.includes(n)||typeof t.id!=`string`||!t.id||!Array.isArray(t.points))return null;let r=t.points.filter(e=>Array.isArray(e)&&Nt(e[0])&&Nt(e[1])).map(([e,t])=>[e,t]),[i,a]=Mt[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`&&jt.test(t.color)?t.color:`#f5a524`,width:Nt(t.width)&&t.width>0?Math.min(96,t.width):At[n],...typeof t.text==`string`&&t.text!==``?{text:t.text}:{}}}function Ft(e){return Array.isArray(e)?e.map(Pt).filter(e=>e!==null):null}var It={info:`#8a93a6`,warning:`#f5a524`,critical:`#e5484d`},Lt={info:`var(--text-muted, #8a93a6)`,warning:`var(--accent, #f5a524)`,critical:`var(--danger, #e5484d)`};function Rt(e,t){return{id:`mark:${e.id}`,kind:`box`,anchor:`x`,points:[[e.t0,0],[e.t1??t,1]],color:It[e.severity],width:1,...e.ruleName?{text:e.ruleName}:{}}}var zt=96,Bt=96,Vt=2,Ht={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,camera:6},Ut={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,camera:24},Wt=Ht,Gt=Ut;function Kt(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 qt(e,t,n,r=96){let i=Ht[e],a=Ut[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 Jt(e,t,n,r,i,a,o=96,s=96){let c=Math.round(r/Math.max(1e-6,a.width/o)),l=Math.round(i/Math.max(1e-6,a.height/s));return n===`move`?qt(e,{...t,x:t.x+c,y:t.y+l},o,s):{...t,w:Math.max(Ht[e],Math.min(t.w+c,o-t.x)),h:Math.max(Ut[e],Math.min(t.h+l,s-t.y))}}function Yt(e,t,n){for(let r of t)if(r.id!==n&&Kt(e,r.rect))return!0;return!1}function Xt(e,t,n=96){let r=Ht[e],i=Ut[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=qt(e,{x:s,y:i,w:a,h:o},n);if(!Yt(r,t,``))return r}return qt(e,{x:0,y:0,w:r,h:i},n)}function Zt(e,t){return{id:crypto.randomUUID(),kind:e,rect:Xt(e,t)}}function Qt(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=Qt(e-4).map(e=>({x:e.x*.5,y:e.y,w:e.w*.5,h:e.h})),n=Qt(4).map(e=>({x:.5+e.x*.5,y:e.y,w:e.w*.5,h:e.h}));return[...t,...n]}function $t(e,t=96,n=96){let r=Qt(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 en(){return{scaleMin:``,scaleMax:``,majorStep:``,minorStep:``,alarm:null}}var tn={style:`dashed`,width:1,color:null},nn={style:`solid`,width:1,color:null},rn={enabled:!1,reference:`previous`,datasetId:null,datasetColor:`#94a3b8`,previousColor:`#64748b`},an=/^#[0-9a-f]{6}$/i;function on(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`&&an.test(t.datasetColor)?t.datasetColor:rn.datasetColor,previousColor:typeof t.previousColor==`string`&&an.test(t.previousColor)?t.previousColor:rn.previousColor}}var sn=[`#f5a524`,`#38bdf8`,`#22c55e`,`#f472b6`,`#a78bfa`,`#fb7185`];function cn(e,t){return{id:crypto.randomUUID(),column:e,color:sn[t%sn.length],value:`last`,style:`arc`,min:``,max:``}}function ln(e,t){if(!e||typeof e!=`object`)return null;let n=e;if(typeof n.column!=`string`)return null;let r=Qn(n.alarm);return{id:typeof n.id==`string`&&n.id?n.id:`g${t}`,column:n.column,color:typeof n.color==`string`?n.color:sn[t%sn.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 un(e,t){let n=parseFloat(e),r=parseFloat(t);return Number.isFinite(n)&&Number.isFinite(r)&&n<r?[n,r]:void 0}var dn=1.8,fn=4,pn=1;function mn(){return{kind:`multiband`,series:[],addColumn:``,layout:`overlay`,xAxisLine:{...tn},yAxisLine:{...tn},gridLine:{...nn},lineWidth:1}}function hn(e){return{kind:`xyscatter`,xyXCol:``,xyYCol:``,xyColorCol:null,xyColor:e,xyPointRadius:dn,xyXAxisLine:{...tn},xyYAxisLine:{...tn},xyGridLine:{...nn},xyFit:null,xyXScale:en(),xyYScale:en()}}function gn(e=4){return{kind:`xyzmesh`,xyzXCol:``,xyzYCol:``,xyzZCol:``,xyzViewMode:`3d`,xyzXScale:en(),xyzYScale:en(),xyzZScale:en(),xyzPointRadius:e,showMesh:!1,meshStyle:`filled`,meshOpacity:.85}}function _n(){return{kind:`histogram`,histColumn:``,histBins:0,histColor:`#38bdf8`,histNormal:!1,histLogY:!1}}function vn(){return{kind:`polar`,polarAngleCol:``,polarRadiusCol:``,polarColor:`#a78bfa`,polarMode:`waveform`,polarRadiusMin:``,polarRadiusMax:``}}function yn(){return{kind:`spectrum`,specSignalCol:``,specTimeCol:``,specSampleRate:`1000`,specXMode:`hz`,specYMode:`amplitude`,specWindow:`hann`,specColor:`#34d399`,specLogX:!1}}function bn(){return{kind:`boxplot`,boxValueCol:``,boxGroupCol:``,boxColor:`#fb923c`,boxWhiskers:`1.5iqr`}}function xn(){return{kind:`spectrogram`,sgSignalCol:``,sgTimeCol:``,sgSampleRate:`1000`,sgWindowSize:512,sgOverlap:.5,sgWinFunc:`hann`,sgYMode:`db`,sgLogFreq:!1}}function Sn(){return{kind:`heatmap`,hmMode:`binned`,hmColumns:[],hmXCol:``,hmYCol:``,hmValueCol:``,hmXBins:6,hmYBins:6,hmXMin:``,hmXMax:``,hmYMin:``,hmYMax:``,hmShowValues:!0,hmColorScheme:`diverging`}}function Cn(){return{kind:`violin`,vlValueCol:``,vlGroupCol:``,vlColor:`#818cf8`,vlShowBox:!0,vlBandwidth:``,vlOrientation:`vertical`}}function wn(){return{kind:`confusion`,cfActualCol:``,cfPredictedCol:``,cfNormalize:!1}}function Tn(){return{kind:`roc`,rocScoreCol:``,rocLabelCol:``,rocMode:`roc`,rocColor:`#f472b6`}}function En(){return{kind:`losscurve`,lcXCol:``,lcLeftCols:[],lcRightCols:[]}}function Dn(){return{kind:`controlchart`,ccValueCol:``,ccSubgroupCol:``,ccSigmaLevel:3,ccColor:`#22d3ee`}}function On(){return{kind:`parallelcoords`,pcColumns:[],pcColorByCol:``,pcColor:`#64748b`}}function kn(){return{kind:`embedding`,emXCol:``,emYCol:``,emColorCol:``,emColorMode:`categorical`,emLabelCol:``,emPointSize:3,emColor:`#a78bfa`}}function An(){return{kind:`flamegraph`,fgNameCol:``,fgParentCol:``,fgValueCol:``,fgDirection:`topdown`}}function jn(){return{kind:`barchart`,bcCategoryCol:``,bcValueCols:[],bcMode:`grouped`,bcHorizontal:!1}}function Mn(){return{kind:`radar`,rdAxesCols:[],rdGroupCol:``,rdColor:`#38bdf8`,rdFill:!0}}function Nn(){return{kind:`areachart`,acXCol:``,acYCols:[],acStacked:!1}}function Pn(){return{kind:`cdfchart`,cdValueCols:[],cdComplement:!1,cdLogX:!1}}function Fn(){return{kind:`bubblechart`,bbXCol:``,bbYCol:``,bbSizeCol:``,bbColorCol:``,bbColorMode:`categorical`,bbColor:`#64748b`,bbMaxRadius:24}}function In(){return{kind:`treemap`,tmNameCol:``,tmParentCol:``,tmValueCol:``}}function Ln(){return{kind:`sankey`,skSourceCol:``,skTargetCol:``,skValueCol:``}}function Rn(){return{kind:`gauge`,ggGauges:[]}}function zn(){return{kind:`calibration`,cbScoreCol:``,cbLabelCol:``,cbBins:10,cbColor:`#38bdf8`}}function Bn(){return{kind:`qqplot`,qqValueCol:``,qqMode:`normal`,qqRefCol:``,qqColor:`#a78bfa`}}function Vn(){return{kind:`gantt`,gtLabelCol:``,gtStartCol:``,gtEndCol:``,gtGroupCol:``}}function Hn(e,t){let n=(e.parentId?t.find(t=>t.id===e.parentId)?.name:void 0)??e.parentName;return n?`${n} · ${e.name}`:e.name}var Un=()=>({kind:`camera`,cameraStreamId:``,cameras:[],syncStreamId:``,offsetMs:0,fit:`contain`}),Wn=9;function Gn(e){return e.cameraStreamId?e.cameras?.[0]===e.cameraStreamId?e.cameras.slice(0,9):[e.cameraStreamId]:[]}function Kn(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 qn(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 Jn(e,t){return qn(e)?e:{...t}}function Yn(e){if(!e||typeof e!=`object`)return!1;let t=e;return t.kind===`multiband`&&Array.isArray(t.series)&&t.series.every(Kn)&&typeof t.addColumn==`string`}function Xn(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 Zn(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 Qn(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,...typeof t.ruleId==`string`&&$n.test(t.ruleId)?{ruleId:t.ruleId}:{}}}var $n=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function er(e,t){if(!t.size)return e;let n=!1,r=e=>{let r=e?.ruleId?t.get(e.ruleId):void 0;return!e||!r?e:(n=!0,{...e,value:r.value,linked:r.active?`active`:`idle`})},i=e,a=null,o=(e,t)=>{a??={...i},a[e]=t};if(e.kind===`multiband`){let t=e.series.map(e=>{let t=r(e.alarm);return t===e.alarm?e:{...e,alarm:t}});n&&o(`series`,t)}else if(e.kind===`gauge`){let t=e.ggGauges.map(e=>{let t=r(e.alarm);return t===e.alarm?e:{...e,alarm:t}});n&&o(`ggGauges`,t)}else if(e.kind===`xyscatter`||e.kind===`xyzmesh`){let t=e.kind===`xyscatter`?[`xyXScale`,`xyYScale`]:[`xyzXScale`,`xyzYScale`,`xyzZScale`];for(let e of t){let t=i[e],n=r(t?.alarm);t&&n!==t.alarm&&o(e,{...t,alarm:n})}}else if(e.kind in tr){let t=tr[e.kind],n=r(i[t]);n!==i[t]&&o(t,n)}return a||e}var tr={histogram:`histAlarm`,spectrum:`specAlarm`,areachart:`acAlarm`,losscurve:`lcAlarm`,cdfchart:`cdAlarm`,bubblechart:`bbAlarm`,boxplot:`boxAlarm`,violin:`vlAlarm`,barchart:`bcAlarm`,gantt:`gtAlarm`};function nr(e){if(!e||!(e.kind in tr))return null;let t=e[tr[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 rr(e){let t=en();if(!e||typeof e!=`object`)return t;let n=e,r=Qn(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 ir(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(Yn(n)){let e=n;r[t]={kind:`multiband`,series:Array.isArray(e.series)?e.series.map(e=>e&&e.alarm&&typeof e.alarm==`object`?{...e,alarm:Qn(e.alarm)}:e):e.series,addColumn:e.addColumn,layout:e.layout===`parallel`?`parallel`:`overlay`,xAxisLine:Jn(e.xAxisLine,tn),yAxisLine:Jn(e.yAxisLine,tn),gridLine:Jn(e.gridLine,nn),lineWidth:typeof e.lineWidth==`number`&&Number.isFinite(e.lineWidth)?Math.min(6,Math.max(.5,e.lineWidth)):1,...on(e.beacon)?{beacon:on(e.beacon)}:{},...e.envelope===!0?{envelope:!0}:{}}}else if(Xn(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:Jn(e.xyXAxisLine,tn),xyYAxisLine:Jn(e.xyYAxisLine,tn),xyGridLine:Jn(e.xyGridLine,nn),xyFit:a,xyXScale:rr(e.xyXScale),xyYScale:rr(e.xyYScale)}}else if(Zn(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??rr(n.xyzXScale),xyzYScale:a??rr(n.xyzYScale),xyzZScale:o??rr(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=ln(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:``}}else if(n&&typeof n==`object`&&n.kind===`camera`){let e=n,i=typeof e.offsetMs==`number`&&Number.isFinite(e.offsetMs)?Math.round(e.offsetMs):0,a=Array.isArray(e.cameras)?[...new Set(e.cameras.filter(e=>typeof e==`string`&&e!==``))]:[],o=typeof e.cameraStreamId==`string`&&e.cameraStreamId?e.cameraStreamId:a[0]??``;r[t]={kind:`camera`,cameraStreamId:o,cameras:Gn({cameraStreamId:o,cameras:a.length?a:[o]}),syncStreamId:typeof e.syncStreamId==`string`?e.syncStreamId:``,offsetMs:Math.max(-1e4,Math.min(1e4,i)),fit:e.fit===`cover`?`cover`:`contain`}}let e=r[t]?Ft(n?.annotations):null;e?.length&&(r[t]={...r[t],annotations:e});let i=r[t]?tr[r[t].kind]:void 0,a=i?Qn(n[i]):null;i&&a&&(r[t]={...r[t],[i]:a})}return r}function ar(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]=mn(),a=!0)}else if(t.kind===`xyscatter`){let e=i[t.id];(!e||e.kind!==`xyscatter`)&&(i[t.id]=hn(n),a=!0)}else if(t.kind===`xyzmesh`){let e=i[t.id];(!e||e.kind!==`xyzmesh`)&&(i[t.id]=gn(r),a=!0)}else if(t.kind===`histogram`){let e=i[t.id];(!e||e.kind!==`histogram`)&&(i[t.id]=_n(),a=!0)}else if(t.kind===`polar`){let e=i[t.id];(!e||e.kind!==`polar`)&&(i[t.id]=vn(),a=!0)}else if(t.kind===`spectrum`){let e=i[t.id];(!e||e.kind!==`spectrum`)&&(i[t.id]=yn(),a=!0)}else if(t.kind===`boxplot`){let e=i[t.id];(!e||e.kind!==`boxplot`)&&(i[t.id]=bn(),a=!0)}else t.kind===`spectrogram`?(!i[t.id]||i[t.id].kind!==`spectrogram`)&&(i[t.id]=xn(),a=!0):t.kind===`heatmap`?(!i[t.id]||i[t.id].kind!==`heatmap`)&&(i[t.id]=Sn(),a=!0):t.kind===`violin`?(!i[t.id]||i[t.id].kind!==`violin`)&&(i[t.id]=Cn(),a=!0):t.kind===`confusion`?(!i[t.id]||i[t.id].kind!==`confusion`)&&(i[t.id]=wn(),a=!0):t.kind===`roc`?(!i[t.id]||i[t.id].kind!==`roc`)&&(i[t.id]=Tn(),a=!0):t.kind===`losscurve`?(!i[t.id]||i[t.id].kind!==`losscurve`)&&(i[t.id]=En(),a=!0):t.kind===`controlchart`?(!i[t.id]||i[t.id].kind!==`controlchart`)&&(i[t.id]=Dn(),a=!0):t.kind===`parallelcoords`?(!i[t.id]||i[t.id].kind!==`parallelcoords`)&&(i[t.id]=On(),a=!0):t.kind===`embedding`?(!i[t.id]||i[t.id].kind!==`embedding`)&&(i[t.id]=kn(),a=!0):t.kind===`flamegraph`?(!i[t.id]||i[t.id].kind!==`flamegraph`)&&(i[t.id]=An(),a=!0):t.kind===`barchart`?(!i[t.id]||i[t.id].kind!==`barchart`)&&(i[t.id]=jn(),a=!0):t.kind===`radar`?(!i[t.id]||i[t.id].kind!==`radar`)&&(i[t.id]=Mn(),a=!0):t.kind===`areachart`?(!i[t.id]||i[t.id].kind!==`areachart`)&&(i[t.id]=Nn(),a=!0):t.kind===`cdfchart`?(!i[t.id]||i[t.id].kind!==`cdfchart`)&&(i[t.id]=Pn(),a=!0):t.kind===`bubblechart`?(!i[t.id]||i[t.id].kind!==`bubblechart`)&&(i[t.id]=Fn(),a=!0):t.kind===`treemap`?(!i[t.id]||i[t.id].kind!==`treemap`)&&(i[t.id]=In(),a=!0):t.kind===`sankey`?(!i[t.id]||i[t.id].kind!==`sankey`)&&(i[t.id]=Ln(),a=!0):t.kind===`gauge`?(!i[t.id]||i[t.id].kind!==`gauge`)&&(i[t.id]=Rn(),a=!0):t.kind===`calibration`?(!i[t.id]||i[t.id].kind!==`calibration`)&&(i[t.id]=zn(),a=!0):t.kind===`qqplot`?(!i[t.id]||i[t.id].kind!==`qqplot`)&&(i[t.id]=Bn(),a=!0):t.kind===`gantt`?(!i[t.id]||i[t.id].kind!==`gantt`)&&(i[t.id]=Vn(),a=!0):t.kind===`camera`&&(!i[t.id]||i[t.id].kind!==`camera`)&&(i[t.id]=Un(),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 or(e){return e===null||typeof e==`number`&&e>0?{liveWindowSeconds:e}:{}}function sr(e){return Number.isNaN(e)?0:Math.min(100,Math.max(0,e))}function cr(){return crypto.randomUUID()}function lr(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 ur(){return ur=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},ur.apply(null,arguments)}var dr={relTol:1e-12,absTol:1e-15,matrix:`Matrix`,number:`number`,numberFallback:`number`,precision:64,predictable:!1,randomSeed:null,legacySubset:!1};function fr(e,t){if(mr(e,t)||hr(e,t))return e[t];throw vr(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 pr(e,t,n){if(mr(e,t)||hr(e,t))return e[t]=n,n;throw Error(`No access to property "${t}"`)}function mr(e,t){return yr(e)?!(t in Object.prototype):!1}function hr(e,t){return Array.isArray(e)?typeof t==`number`||typeof t==`string`&&gr(t)||t===`length`:!1}function gr(e){return/^\d+$/.test(e)}function _r(e,t){if(!vr(e,t))throw Error(`No access to method "`+t+`"`);return e[t]}function vr(e,t){return e==null||typeof e[t]!=`function`||Ei(e,t)&&Object.getPrototypeOf&&t in Object.getPrototypeOf(e)?!1:br.has(t)?!0:!(t in Object.prototype||t in Function.prototype)}function yr(e){return typeof e==`object`&&e&&e.constructor===Object}var br=new Set([`toString`,`valueOf`,`toLocaleString`]),xr=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 fr(this.wrappedObject,e)}set(e,t){return pr(this.wrappedObject,e,t),this}has(e){return mr(this.wrappedObject,e)&&e in this.wrappedObject}entries(){return Cr(this.keys(),e=>[e,this.get(e)])}forEach(e){for(var t of this.keys())e(this.get(t),t,this)}delete(e){mr(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}},Sr=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 Cr(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 Cr(e,t){return{next:()=>{var n=e.next();return n.done?n:{value:t(n.value),done:!1}}}}function wr(){return new Map}function Tr(e){if(!e)return wr();if(Jr(e))return e;if(qr(e))return new xr(e);throw Error(`createMap can create maps from objects or Maps`)}function Er(e){if(e instanceof xr)return e.wrappedObject;var t={};for(var n of e.keys())pr(t,n,e.get(n));return t}function Dr(e){return typeof e==`number`}function Or(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 kr(e){return typeof e==`bigint`}function Ar(e){return e&&typeof e==`object`&&Object.getPrototypeOf(e).isComplex===!0||!1}function jr(e){return e&&typeof e==`object`&&Object.getPrototypeOf(e).isFraction===!0||!1}function Mr(e){return e&&e.constructor.prototype.isUnit===!0||!1}function Nr(e){return typeof e==`string`}var Pr=Array.isArray;function Fr(e){return e&&e.constructor.prototype.isMatrix===!0||!1}function Ir(e){return Array.isArray(e)||Fr(e)}function Lr(e){return e&&e.isDenseMatrix&&e.constructor.prototype.isMatrix===!0||!1}function Rr(e){return e&&e.isSparseMatrix&&e.constructor.prototype.isMatrix===!0||!1}function zr(e){return e&&e.constructor.prototype.isRange===!0||!1}function Br(e){return e&&e.constructor.prototype.isIndex===!0||!1}function Vr(e){return typeof e==`boolean`}function Hr(e){return e&&e.constructor.prototype.isResultSet===!0||!1}function Ur(e){return e&&e.constructor.prototype.isHelp===!0||!1}function Wr(e){return typeof e==`function`}function Gr(e){return e instanceof Date}function Kr(e){return e instanceof RegExp}function qr(e){return!!(e&&typeof e==`object`&&e.constructor===Object&&!Ar(e)&&!jr(e))}function Jr(e){return e?e instanceof Map||e instanceof xr||typeof e.set==`function`&&typeof e.get==`function`&&typeof e.keys==`function`&&typeof e.has==`function`:!1}function Yr(e){return Jr(e)&&Jr(e.a)&&Jr(e.b)}function Xr(e){return Jr(e)&&qr(e.wrappedObject)}function Zr(e){return e===null}function Qr(e){return e===void 0}function $r(e){return e&&e.isAccessorNode===!0&&e.constructor.prototype.isNode===!0||!1}function ei(e){return e&&e.isArrayNode===!0&&e.constructor.prototype.isNode===!0||!1}function ti(e){return e&&e.isAssignmentNode===!0&&e.constructor.prototype.isNode===!0||!1}function ni(e){return e&&e.isBlockNode===!0&&e.constructor.prototype.isNode===!0||!1}function ri(e){return e&&e.isConditionalNode===!0&&e.constructor.prototype.isNode===!0||!1}function ii(e){return e&&e.isConstantNode===!0&&e.constructor.prototype.isNode===!0||!1}function ai(e){return ii(e)||di(e)&&e.args.length===1&&ii(e.args[0])&&`-+~`.includes(e.op)}function oi(e){return e&&e.isFunctionAssignmentNode===!0&&e.constructor.prototype.isNode===!0||!1}function si(e){return e&&e.isFunctionNode===!0&&e.constructor.prototype.isNode===!0||!1}function ci(e){return e&&e.isIndexNode===!0&&e.constructor.prototype.isNode===!0||!1}function li(e){return e&&e.isNode===!0&&e.constructor.prototype.isNode===!0||!1}function ui(e){return e&&e.isObjectNode===!0&&e.constructor.prototype.isNode===!0||!1}function di(e){return e&&e.isOperatorNode===!0&&e.constructor.prototype.isNode===!0||!1}function fi(e){return e&&e.isParenthesisNode===!0&&e.constructor.prototype.isNode===!0||!1}function pi(e){return e&&e.isRangeNode===!0&&e.constructor.prototype.isNode===!0||!1}function mi(e){return e&&e.isRelationalNode===!0&&e.constructor.prototype.isNode===!0||!1}function hi(e){return e&&e.isSymbolNode===!0&&e.constructor.prototype.isNode===!0||!1}function gi(e){return e&&e.constructor.prototype.isChain===!0||!1}function _i(e){var t=typeof e;return t===`object`?e===null?`null`:Or(e)?`BigNumber`:e.constructor&&e.constructor.name?e.constructor.name:`Object`:t}function vi(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 vi(e)});if(e instanceof Date)return new Date(e.valueOf());if(Or(e))return e;if(qr(e))return yi(e,vi);if(t===`function`)return e;throw TypeError(`Cannot clone: unknown type of value (value: ${e})`)}function yi(e,t){var n={};for(var r in e)Ei(e,r)&&(n[r]=t(e[r]));return n}function bi(e,t){for(var n in t)Ei(t,n)&&(e[n]=t[n]);return e}function xi(e,t){if(Array.isArray(t))throw TypeError(`Arrays are not supported by deepExtend`);for(var n in t)if(Ei(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?xi(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 Si(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(!Si(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)||!Si(e[n],t[n]))return!1;for(n in t)if(!(n in e))return!1;return!0}else return e===t}function Ci(e){var t={};return wi(e,t),t}function wi(e,t){for(var n in e)if(Ei(e,n)){var r=e[n];typeof r==`object`&&r?wi(r,t):t[n]=r}}function Ti(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 Ei(e,t){return e&&Object.hasOwnProperty.call(e,t)}function Di(e){return e&&typeof e.factory==`function`}function Oi(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 ki=[`Matrix`,`Array`],Ai=[`number`,`BigNumber`,`bigint`,`Fraction`];function ji(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=vi(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=vi(e);Mi(r,`matrix`,ki),Mi(r,`number`,Ai),xi(e,r);var o=vi(e);return t(`config`,o,a,vi(r)),o}else return vi(e)}return n.MATRIX_OPTIONS=ki,n.NUMBER_OPTIONS=Ai,Object.keys(dr).forEach(t=>{Object.defineProperty(n,t,{get:()=>e[t],enumerable:!0,configurable:!0})}),n}function Mi(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 Ni=Tt(((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(){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=oe(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=ae(e).map(D);let n=t.length,r=D(oe(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)?oe(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=oe(n),a=oe(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,se(arguments,0,t).concat([se(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 le(a,function(i){return t(e,n+1,r.concat([i]))})}else return[r]}return t(e,0,[])}function ee(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 te(e){return e.map(e=>me(e)?fe(e.referToSelf.callback):pe(e)?de(e.referTo.references,e.referTo.callback):e)}function H(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 ne(e,t,n){let r=te(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(me(s))r[o]=s.referToSelf.callback(n),r[o].referToSelf=s.referToSelf,i[o]=!0,e=!1;else if(pe(s)){let n=H(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 re(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 ie(e,r){if(d.createCount++,Object.keys(r).length===0)throw SyntaxError(`No signatures provided`);d.warnAgainstDeprecatedThis&&re(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(ee(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=ne(a,o,ve),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 te=m?f[0].implementation:n,H=h?f[1].implementation:n,ie=g?f[2].implementation:n,U=_?f[3].implementation:n,ae=v?f[4].implementation:n,oe=y?f[5].implementation:n,se=m?f[0].params.length:-1,ce=h?f[1].params.length:-1,le=g?f[2].params.length:-1,ue=_?f[3].params.length:-1,de=v?f[4].params.length:-1,fe=y?f[5].params.length:-1,pe=b?6:0,me=f.length,he=f.map(e=>e.test),ge=f.map(e=>e.implementation),_e=function(){for(let e=pe;e<me;e++)if(he[e](arguments))return ge[e].apply(this,arguments);return d.onMismatch(e,arguments,f)};function ve(e,t){return arguments.length===se&&S(e)&&N(t)?te.apply(this,arguments):arguments.length===ce&&w(e)&&P(t)?H.apply(this,arguments):arguments.length===le&&k(e)&&F(t)?ie.apply(this,arguments):arguments.length===ue&&A(e)&&I(t)?U.apply(this,arguments):arguments.length===de&&j(e)&&R(t)?ae.apply(this,arguments):arguments.length===fe&&M(e)&&B(t)?oe.apply(this,arguments):_e.apply(this,arguments)}try{Object.defineProperty(ve,`name`,{value:e})}catch{}return ve.signatures=o,ve._typedFunctionData={signatures:f,signatureMap:p},ve}function U(e,t,n){throw N(e,t,n)}function ae(e){return se(e,0,e.length-1)}function oe(e){return e[e.length-1]}function se(e,t,n){return Array.prototype.slice.call(e,t,n)}function ce(e,t){for(let n=0;n<e.length;n++)if(t(e[n]))return e[n]}function le(e,t){return Array.prototype.concat.apply([],e.map(t))}function ue(){let e=ae(arguments).map(e=>x(T(e))),t=oe(arguments);if(typeof t!=`function`)throw TypeError(`Callback function expected as last argument`);return de(e,t)}function de(e,t){return{referTo:{references:e,callback:t}}}function fe(e){if(typeof e!=`function`)throw TypeError(`Callback function expected as first argument`);return{referToSelf:{callback:e}}}function pe(e){return e&&typeof e.referTo==`object`&&Array.isArray(e.referTo.references)&&typeof e.referTo.callback==`function`}function me(e){return e&&typeof e.referToSelf==`object`&&typeof e.referToSelf.callback==`function`}function he(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 ge(e){let t;for(let n in e)Object.prototype.hasOwnProperty.call(e,n)&&(_(e[n])||typeof e[n].signature==`string`)&&(t=he(t,e[n].name));return t}function _e(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 ve=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=ge(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=he(r,s)),_e(i,o)}return ie(r||``,i)},d.create=i,d.createCount=ve.createCount,d.onMismatch=U,d.throwMismatchError=U,d.createError=N,d.clear=m,d.clearConversions=h,d.addTypes=p,d._findType=f,d.referTo=ue,d.referToSelf=fe,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 ye(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};ye(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){ye(e);let t=f(e.to),n=ce(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 J(e,t,n,r){function i(r){var i=Oi(r,t.map(Li));return Fi(e,t,r),n(i)}return i.isFactory=!0,i.fn=e,i.dependencies=t.slice().sort(),r&&(i.meta=r),i}function Pi(e){return typeof e==`function`&&typeof e.fn==`string`&&Array.isArray(e.dependencies)}function Fi(e,t,n){if(!t.filter(e=>!Ii(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 Ii(e){return e&&e[0]===`?`}function Li(e){return e&&e[0]===`?`?e.slice(1):e}function Ri(e){return typeof e==`boolean`?!0:Number.isFinite(e)?e===Math.round(e):!1}function zi(e,t){if(t.number===`bigint`)try{BigInt(e)}catch{return t.numberFallback}return t.number}var Bi=Math.sign||function(e){return e>0?1:e<0?-1:0},Vi=Math.log2||function(e){return Math.log(e)/Math.LN2},Hi=Math.log10||function(e){return Math.log(e)/Math.LN10},Ui=Math.log1p||function(e){return Math.log(e+1)},Wi=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},Gi=Math.expm1||function(e){return e>=2e-4||e<=-2e-4?Math.exp(e)-1:e+e*e/2+e*e*e/6};function Ki(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(!Ri(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(!Ri(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 qi(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}=Ji(t);switch(n){case`fixed`:return Zi(e,r);case`exponential`:return Qi(e,r);case`engineering`:return Xi(e,r);case`bin`:return Ki(e,2,i);case`oct`:return Ki(e,8,i);case`hex`:return Ki(e,16,i);case`auto`:return $i(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 Ji(e){var t=`auto`,n,r;if(e!==void 0)if(Dr(e))n=e;else if(Or(e))n=e.toNumber();else if(qr(e))e.precision!==void 0&&(n=da(e.precision,()=>{throw Error(`Option "precision" must be a number or BigNumber`)})),e.wordSize!==void 0&&(r=da(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 Yi(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 Xi(e,t){if(isNaN(e)||!Number.isFinite(e))return String(e);var n=ea(Yi(e),t),r=n.exponent,i=n.coefficients,a=r%3==0?r:r<0?r-3-r%3:r-r%3;if(Dr(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=Dr(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 Zi(e,t){if(isNaN(e)||!Number.isFinite(e))return String(e);var n=Yi(e),r=typeof t==`number`?ea(n,n.exponent+1+t):n,i=r.coefficients,a=r.exponent+1,o=a+(t||0);return i.length<o&&(i=i.concat(ta(o-i.length))),a<0&&(i=ta(-a+1).concat(i),a=1),a<i.length&&i.splice(a,0,a===0?`0.`:`.`),r.sign+i.join(``)}function Qi(e,t){if(isNaN(e)||!Number.isFinite(Number(e)))return String(e);var n=Yi(e),r=t?ea(n,t):n,i=r.coefficients,a=r.exponent;i.length<t&&(i=i.concat(ta(t-i.length)));var o=i.shift();return r.sign+o+(i.length>0?`.`+i.join(``):``)+`e`+(a>=0?`+`:``)+a}function $i(e,t,n){if(isNaN(e)||!Number.isFinite(e))return String(e);var r=fa(n?.lowerExp,-3),i=fa(n?.upperExp,5),a=Yi(e),o=t?ea(a,t):a;if(o.exponent<r||o.exponent>=i)return Qi(e,t);var s=o.coefficients,c=o.exponent;s.length<t&&(s=s.concat(ta(t-s.length))),s=s.concat(ta(c-s.length+1+(s.length<t?t-s.length:0))),s=ta(-c).concat(s);var l=c>0?c:0;return l<s.length-1&&s.splice(l+1,0,`.`),o.sign+s.join(``)}function ea(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 ta(e){for(var t=[],n=0;n<e;n++)t.push(0);return t}function na(e){return e.toExponential().replace(/e.*$/,``).replace(/^0\.?0*|\./,``).length}function ra(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 ia=Math.acosh||function(e){return Math.log(Math.sqrt(e*e-1)+e)},aa=Math.asinh||function(e){return Math.log(Math.sqrt(e*e+1)+e)},oa=Math.atanh||function(e){return Math.log((1+e)/(1-e))/2},sa=Math.cosh||function(e){return(Math.exp(e)+Math.exp(-e))/2},ca=Math.sinh||function(e){return(Math.exp(e)-Math.exp(-e))/2},la=Math.tanh||function(e){var t=Math.exp(2*e);return(t-1)/(t+1)};function ua(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 da(e,t){if(Dr(e))return e;if(Or(e))return e.toNumber();t()}function fa(e,t){return Dr(e)?e:Or(e)?e.toNumber():t}var pa=Ot(Ni(),1),ma=function(){return ma=pa.default.create,pa.default},ha=J(`typed`,[`?BigNumber`,`?Complex`,`?DenseMatrix`,`?Fraction`],function(e){var{BigNumber:t,Complex:n,DenseMatrix:r,Fraction:i}=e,a=ma();return a.clear(),a.addTypes([{name:`number`,test:Dr},{name:`Complex`,test:Ar},{name:`BigNumber`,test:Or},{name:`bigint`,test:kr},{name:`Fraction`,test:jr},{name:`Unit`,test:Mr},{name:`identifier`,test:e=>Nr&&/^(?:[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:Nr},{name:`Chain`,test:gi},{name:`Array`,test:Pr},{name:`Matrix`,test:Fr},{name:`DenseMatrix`,test:Lr},{name:`SparseMatrix`,test:Rr},{name:`Range`,test:zr},{name:`Index`,test:Br},{name:`boolean`,test:Vr},{name:`ResultSet`,test:Hr},{name:`Help`,test:Ur},{name:`function`,test:Wr},{name:`Date`,test:Gr},{name:`RegExp`,test:Kr},{name:`null`,test:Zr},{name:`undefined`,test:Qr},{name:`AccessorNode`,test:$r},{name:`ArrayNode`,test:ei},{name:`AssignmentNode`,test:ti},{name:`BlockNode`,test:ni},{name:`ConditionalNode`,test:ri},{name:`ConstantNode`,test:ii},{name:`FunctionNode`,test:si},{name:`FunctionAssignmentNode`,test:oi},{name:`IndexNode`,test:ci},{name:`Node`,test:li},{name:`ObjectNode`,test:ui},{name:`OperatorNode`,test:di},{name:`ParenthesisNode`,test:fi},{name:`RangeNode`,test:pi},{name:`RelationalNode`,test:mi},{name:`SymbolNode`,test:hi},{name:`Map`,test:Jr},{name:`Object`,test:qr}]),a.addConversions([{from:`number`,to:`BigNumber`,convert:function(e){if(t||ga(e),na(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||_a(e),new n(e,0)}},{from:`BigNumber`,to:`Complex`,convert:function(e){return n||_a(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||ga(e),new t(e.toString())}},{from:`bigint`,to:`Fraction`,convert:function(e){return i||ya(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||_a(e),new n(e.valueOf(),0)}},{from:`number`,to:`Fraction`,convert:function(e){i||ya(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||ga(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||ya(e);try{return new i(e)}catch{throw Error(`Cannot convert "`+e+`" to Fraction`)}}},{from:`string`,to:`Complex`,convert:function(e){n||_a(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||ga(e),new t(+e)}},{from:`boolean`,to:`bigint`,convert:function(e){return BigInt(+e)}},{from:`boolean`,to:`Fraction`,convert:function(e){return i||ya(e),new i(+e)}},{from:`boolean`,to:`string`,convert:function(e){return String(e)}},{from:`Array`,to:`Matrix`,convert:function(e){return r||va(),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&&Ir(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&&Ir(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 ga(e){throw Error(`Cannot convert value ${e} into a BigNumber: no class 'BigNumber' provided`)}function _a(e){throw Error(`Cannot convert value ${e} into a Complex number: no class 'Complex' provided`)}function va(){throw Error(`Cannot convert array into a Matrix: no class 'DenseMatrix' provided`)}function ya(e){throw Error(`Cannot convert value ${e} into a Fraction, no class 'Fraction' provided.`)}var ba=J(`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}),xa=9e15,Sa=1e9,Ca=`0123456789abcdef`,wa=`2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058`,Ta=`3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789`,Ea={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-xa,maxE:xa,crypto:!1},Da,Oa,ka=!0,Aa=`[DecimalError] `,ja=Aa+`Invalid argument: `,Ma=Aa+`Precision limit exceeded`,Na=Aa+`crypto unavailable`,Pa=`[object Decimal]`,Fa=Math.floor,Ia=Math.pow,La=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,Ra=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,za=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,Ba=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,Va=1e7,Ha=7,Ua=9007199254740991,Wa=wa.length-1,Ga=Ta.length-1,Y={toStringTag:Pa};Y.absoluteValue=Y.abs=function(){var e=new this.constructor(this);return e.s<0&&(e.s=1),Qa(e)},Y.ceil=function(){return Qa(new this.constructor(this),this.e+1,2)},Y.clampedTo=Y.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(ja+t);return n=r.cmp(e),n<0?e:r.cmp(t)>0?t:new i(r)},Y.comparedTo=Y.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},Y.cosine=Y.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())+Ha,r.rounding=1,n=Xa(r,_o(r,n)),r.precision=e,r.rounding=t,Qa(Oa==2||Oa==3?n.neg():n,e,t,!0)):new r(1):new r(NaN)},Y.cubeRoot=Y.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(ka=!1,a=u.s*Ia(u.s*u,1/3),!a||Math.abs(a)==1/0?(n=Ka(u.d),e=u.e,(a=(e-n.length+1)%3)&&(n+=a==1||a==-2?`0`:`00`),a=Ia(n,1/3),e=Fa((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=Za(l.plus(u).times(s),l.plus(c),o+2,1),Ka(s.d).slice(0,o)===(n=Ka(r.d)).slice(0,o))if(n=n.slice(o-3,o+1),n==`9999`||!i&&n==`4999`){if(!i&&(Qa(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`)&&(Qa(r,e+1,1),t=!r.times(r).times(r).eq(u));break}return ka=!0,Qa(r,e,d.rounding,t)},Y.decimalPlaces=Y.dp=function(){var e,t=this.d,n=NaN;if(t){if(e=t.length-1,n=(e-Fa(this.e/Ha))*Ha,e=t[e],e)for(;e%10==0;e/=10)n--;n<0&&(n=0)}return n},Y.dividedBy=Y.div=function(e){return Za(this,new this.constructor(e))},Y.dividedToIntegerBy=Y.divToInt=function(e){var t=this,n=t.constructor;return Qa(Za(t,new n(e),0,1,1),n.precision,n.rounding)},Y.equals=Y.eq=function(e){return this.cmp(e)===0},Y.floor=function(){return Qa(new this.constructor(this),this.e+1,3)},Y.greaterThan=Y.gt=function(e){return this.cmp(e)>0},Y.greaterThanOrEqualTo=Y.gte=function(e){var t=this.cmp(e);return t==1||t===0},Y.hyperbolicCosine=Y.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/go(4,e)).toString()):(e=16,t=`2.3283064365386962890625e-10`),a=ho(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 Qa(a,o.precision=n,o.rounding=r,!0)},Y.hyperbolicSine=Y.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=ho(a,2,i,i,!0);else{e=1.4*Math.sqrt(r),e=e>16?16:e|0,i=i.times(1/go(5,e)),i=ho(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,Qa(i,t,n,!0)},Y.hyperbolicTangent=Y.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,Za(n.sinh(),n.cosh(),r.precision=e,r.rounding=t)):new r(n.s)},Y.inverseCosine=Y.acos=function(){var e=this,t=e.constructor,n=e.abs().cmp(1),r=t.precision,i=t.rounding;return n===-1?e.isZero()?no(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()?no(t,r,i):new t(0):new t(NaN)},Y.inverseHyperbolicCosine=Y.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,ka=!1,n=n.times(n).minus(1).sqrt().plus(n),ka=!0,r.precision=e,r.rounding=t,n.ln()):new r(n)},Y.inverseHyperbolicSine=Y.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,ka=!1,n=n.times(n).plus(1).sqrt().plus(n),ka=!0,r.precision=e,r.rounding=t,n.ln())},Y.inverseHyperbolicTangent=Y.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?Qa(new a(i),e,t,!0):(a.precision=n=r-i.e,i=Za(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)},Y.inverseSine=Y.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=no(a,n+4,r).times(.5),e.s=i.s,e):new a(NaN))},Y.inverseTangent=Y.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<=Ga)return o=no(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<=Ga)return o=no(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/Ha+2|0),e=n;e;--e)l=l.div(l.times(l).plus(1).sqrt().plus(1));for(ka=!1,t=Math.ceil(s/Ha),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)),ka=!0,Qa(o,u.precision=d,u.rounding=f,!0)},Y.isFinite=function(){return!!this.d},Y.isInteger=Y.isInt=function(){return!!this.d&&Fa(this.e/Ha)>this.d.length-2},Y.isNaN=function(){return!this.s},Y.isNegative=Y.isNeg=function(){return this.s<0},Y.isPositive=Y.isPos=function(){return this.s>0},Y.isZero=function(){return!!this.d&&this.d[0]===0},Y.lessThan=Y.lt=function(e){return this.cmp(e)<0},Y.lessThanOrEqualTo=Y.lte=function(e){return this.cmp(e)<1},Y.logarithm=Y.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(ka=!1,s=d+p,o=lo(l,s),r=t?to(u,s+10):lo(e,s),c=Za(o,r,s,1),Ja(c.d,i=d,f))do if(s+=10,o=lo(l,s),r=t?to(u,s+10):lo(e,s),c=Za(o,r,s,1),!a){+Ka(c.d).slice(i+1,i+15)+1==0x5af3107a4000&&(c=Qa(c,d+1,0));break}while(Ja(c.d,i+=10,f));return ka=!0,Qa(c,d,f)},Y.minus=Y.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 ka?Qa(e,s,c):e}if(n=Fa(e.e/Ha),u=Fa(p.e/Ha),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/Ha),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]=Va-1;--l[i],l[r]+=Va}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=eo(l,n),ka?Qa(e,s,c):e):new m(c===3?-0:0)},Y.modulo=Y.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]?Qa(new r(n),r.precision,r.rounding):(ka=!1,r.modulo==9?(t=Za(n,e.abs(),0,3,1),t.s*=e.s):t=Za(n,e,0,r.modulo,1),t=t.times(e),ka=!0,n.minus(t))},Y.naturalExponential=Y.exp=function(){return co(this)},Y.naturalLogarithm=Y.ln=function(){return lo(this)},Y.negated=Y.neg=function(){var e=new this.constructor(this);return e.s=-e.s,Qa(e)},Y.plus=Y.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)),ka?Qa(e,s,c):e;if(a=Fa(d.e/Ha),r=Fa(e.e/Ha),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/Ha),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)/Va|0,l[i]%=Va;for(t&&(l.unshift(t),++r),o=l.length;l[--o]==0;)l.pop();return e.d=l,e.e=eo(l,r),ka?Qa(e,s,c):e},Y.precision=Y.sd=function(e){var t,n=this;if(e!==void 0&&e!==!!e&&e!==1&&e!==0)throw Error(ja+e);return n.d?(t=ro(n.d),e&&n.e+1>t&&(t=n.e+1)):t=NaN,t},Y.round=function(){var e=this,t=e.constructor;return Qa(new t(e),e.e+1,t.rounding)},Y.sine=Y.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())+Ha,r.rounding=1,n=mo(r,_o(r,n)),r.precision=e,r.rounding=t,Qa(Oa>2?n.neg():n,e,t,!0)):new r(NaN)},Y.squareRoot=Y.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(ka=!1,l=Math.sqrt(+o),l==0||l==1/0?(t=Ka(s),(t.length+c)%2==0&&(t+=`0`),l=Math.sqrt(t),c=Fa((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(Za(o,a,n+2,1)).times(.5),Ka(a.d).slice(0,n)===(t=Ka(r.d)).slice(0,n))if(t=t.slice(n-3,n+1),t==`9999`||!i&&t==`4999`){if(!i&&(Qa(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`)&&(Qa(r,c+1,1),e=!r.times(r).eq(o));break}return ka=!0,Qa(r,c,u.rounding,e)},Y.tangent=Y.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=Za(n,new r(1).minus(n.times(n)).sqrt(),e+10,0),r.precision=e,r.rounding=t,Qa(Oa==2||Oa==4?n.neg():n,e,t,!0)):new r(NaN)},Y.times=Y.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=Fa(u.e/Ha)+Fa(e.e/Ha),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%Va|0,t=s/Va|0;a[i]=(a[i]+t)%Va|0}for(;!a[--o];)a.pop();return t?++n:a.shift(),e.d=a,e.e=eo(a,n),ka?Qa(e,d.precision,d.rounding):e},Y.toBinary=function(e,t){return vo(this,2,e,t)},Y.toDecimalPlaces=Y.toDP=function(e,t){var n=this,r=n.constructor;return n=new r(n),e===void 0?n:(qa(e,0,Sa),t===void 0?t=r.rounding:qa(t,0,8),Qa(n,e+n.e+1,t))},Y.toExponential=function(e,t){var n,r=this,i=r.constructor;return e===void 0?n=$a(r,!0):(qa(e,0,Sa),t===void 0?t=i.rounding:qa(t,0,8),r=Qa(new i(r),e+1,t),n=$a(r,!0,e+1)),r.isNeg()&&!r.isZero()?`-`+n:n},Y.toFixed=function(e,t){var n,r,i=this,a=i.constructor;return e===void 0?n=$a(i):(qa(e,0,Sa),t===void 0?t=a.rounding:qa(t,0,8),r=Qa(new a(i),e+i.e+1,t),n=$a(r,!1,e+r.e+1)),i.isNeg()&&!i.isZero()?`-`+n:n},Y.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=ro(m)-p.e-1,o=a%Ha,t.d[0]=Ia(10,o<0?Ha+o:o),e==null)e=a>0?t:l;else{if(s=new h(e),!s.isInt()||s.lt(l))throw Error(ja+s);e=s.gt(t)?a>0?t:l:s}for(ka=!1,s=new h(Ka(m)),u=h.precision,h.precision=a=m.length*Ha*2;d=Za(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=Za(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=Za(l,r,a,1).minus(p).abs().cmp(Za(c,n,a,1).minus(p).abs())<1?[l,r]:[c,n],h.precision=u,ka=!0,f},Y.toHexadecimal=Y.toHex=function(e,t){return vo(this,16,e,t)},Y.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:qa(t,0,8),!n.d)return e.s?n:e;if(!e.d)return e.s&&=n.s,e}return e.d[0]?(ka=!1,n=Za(n,e,0,t,1).times(e),ka=!0,Qa(n)):(e.s=n.s,n=e),n},Y.toNumber=function(){return+this},Y.toOctal=function(e,t){return vo(this,8,e,t)},Y.toPower=Y.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(Ia(+s,l));if(s=new c(s),s.eq(1))return s;if(r=c.precision,a=c.rounding,e.eq(1))return Qa(s,r,a);if(t=Fa(e.e/Ha),t>=e.d.length-1&&(n=l<0?-l:l)<=Ua)return i=ao(c,s,n,r),e.s<0?new c(1).div(i):Qa(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=Ia(+s,l),t=n==0||!isFinite(n)?Fa(l*(Math.log(`0.`+Ka(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):(ka=!1,c.rounding=s.s=1,n=Math.min(12,(t+``).length),i=co(e.times(lo(s,r+n)),r),i.d&&(i=Qa(i,r+5,1),Ja(i.d,r,a)&&(t=r+10,i=Qa(co(e.times(lo(s,t+n)),t),t+5,1),+Ka(i.d).slice(r+1,r+15)+1==0x5af3107a4000&&(i=Qa(i,r+1,0)))),i.s=o,ka=!0,c.rounding=a,Qa(i,r,a))},Y.toPrecision=function(e,t){var n,r=this,i=r.constructor;return e===void 0?n=$a(r,r.e<=i.toExpNeg||r.e>=i.toExpPos):(qa(e,1,Sa),t===void 0?t=i.rounding:qa(t,0,8),r=Qa(new i(r),e,t),n=$a(r,e<=r.e||r.e<=i.toExpNeg,e)),r.isNeg()&&!r.isZero()?`-`+n:n},Y.toSignificantDigits=Y.toSD=function(e,t){var n=this,r=n.constructor;return e===void 0?(e=r.precision,t=r.rounding):(qa(e,1,Sa),t===void 0?t=r.rounding:qa(t,0,8)),Qa(new r(n),e,t)},Y.toString=function(){var e=this,t=e.constructor,n=$a(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()&&!e.isZero()?`-`+n:n},Y.truncated=Y.trunc=function(){return Qa(new this.constructor(this),this.e+1,1)},Y.valueOf=Y.toJSON=function(){var e=this,t=e.constructor,n=$a(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()?`-`+n:n};function Ka(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=Ha-r.length,n&&(a+=io(n)),a+=r;o=e[t],r=o+``,n=Ha-r.length,n&&(a+=io(n))}else if(o===0)return`0`;for(;o%10==0;)o/=10;return a+o}function qa(e,t,n){if(e!==~~e||e<t||e>n)throw Error(ja+e)}function Ja(e,t,n,r){var i,a,o,s;for(a=e[0];a>=10;a/=10)--t;return--t<0?(t+=Ha,i=0):(i=Math.ceil((t+1)/Ha),t%=Ha),a=Ia(10,Ha-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)==Ia(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)==Ia(10,t-3)-1,o}function Ya(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]+=Ca.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 Xa(e,t){var n,r,i;if(t.isZero())return t;r=t.d.length,r<32?(n=Math.ceil(r/3),i=(1/go(4,n)).toString()):(n=16,i=`2.3283064365386962890625e-10`),e.precision+=n,t=ho(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 Za=(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=Va,p=Ha,u=Fa(r.e/p)-Fa(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,Da=m;else{for(d=1,f=v[0];f>=10;f/=10)d++;_.e=d+u*p-1,Qa(_,s?a+_.e+1:a,o,m)}return _}})();function Qa(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+=Ha,o=t,u=d[f=0],c=u/Ia(10,i-o-1)%10|0;else if(f=Math.ceil((a+1)/Ha),s=d.length,f>=s)if(r){for(;s++<=f;)d.push(0);u=c=0,i=1,a%=Ha,o=a-Ha+1}else break out;else{for(u=s=d[f],i=1;s>=10;s/=10)i++;a%=Ha,o=a-Ha+i,c=o<0?0:u/Ia(10,i-o-1)%10|0}if(r=r||t<0||d[f+1]!==void 0||(o<0?u:u%Ia(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/Ia(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]=Ia(10,(Ha-t%Ha)%Ha),e.e=-t||0):d[0]=e.e=0,e;if(a==0?(d.length=f,s=1,f--):(d.length=f+1,s=Ia(10,Ha-a),d[f]=o>0?(u/Ia(10,i-o)%Ia(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]==Va&&(d[0]=1));break}else{if(d[f]+=s,d[f]!=Va)break;d[f--]=0,s=1}for(a=d.length;d[--a]===0;)d.pop()}return ka&&(e.e>p.maxE?(e.d=null,e.e=NaN):e.e<p.minE&&(e.e=0,e.d=[0])),e}function $a(e,t,n){if(!e.isFinite())return uo(e);var r,i=e.e,a=Ka(e.d),o=a.length;return t?(n&&(r=n-o)>0?a=a.charAt(0)+`.`+a.slice(1)+io(r):o>1&&(a=a.charAt(0)+`.`+a.slice(1)),a=a+(e.e<0?`e`:`e+`)+e.e):i<0?(a=`0.`+io(-i-1)+a,n&&(r=n-o)>0&&(a+=io(r))):i>=o?(a+=io(i+1-o),n&&(r=n-i-1)>0&&(a=a+`.`+io(r))):((r=i+1)<o&&(a=a.slice(0,r)+`.`+a.slice(r)),n&&(r=n-o)>0&&(i+1===o&&(a+=`.`),a+=io(r))),a}function eo(e,t){var n=e[0];for(t*=Ha;n>=10;n/=10)t++;return t}function to(e,t,n){if(t>Wa)throw ka=!0,n&&(e.precision=n),Error(Ma);return Qa(new e(wa),t,1,!0)}function no(e,t,n){if(t>Ga)throw Error(Ma);return Qa(new e(Ta),t,n,!0)}function ro(e){var t=e.length-1,n=t*Ha+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 io(e){for(var t=``;e--;)t+=`0`;return t}function ao(e,t,n,r){var i,a=new e(1),o=Math.ceil(r/Ha+4);for(ka=!1;;){if(n%2&&(a=a.times(t),yo(a.d,o)&&(i=!0)),n=Fa(n/2),n===0){n=a.d.length-1,i&&a.d[n]===0&&++a.d[n];break}t=t.times(t),yo(t.d,o)}return ka=!0,a}function oo(e){return e.d[e.d.length-1]&1}function so(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 co(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?(ka=!1,c=m):c=t,s=new f(.03125);e.e>-2;)e=e.times(s),d+=5;for(r=Math.log(Ia(2,d))/Math.LN10*2+5|0,c+=r,n=a=o=new f(1),f.precision=c;;){if(a=Qa(a.times(e),c,1),n=n.times(++u),s=o.plus(Za(a,n,c,1)),Ka(s.d).slice(0,c)===Ka(o.d).slice(0,c)){for(i=d;i--;)o=Qa(o.times(o),c,1);if(t==null)if(l<3&&Ja(o.d,c-r,p,l))f.precision=c+=10,n=a=s=new f(1),u=0,l++;else return Qa(o,f.precision=m,p,ka=!0);else return f.precision=m,o}o=s}}function lo(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?(ka=!1,u=y):u=t,_.precision=u+=m,n=Ka(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=Ka(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=to(_,u+2,y).times(a+``),h=lo(new _(r+`.`+n.slice(1)),u-m).plus(l),_.precision=y,t==null?Qa(h,y,v,ka=!0):h;for(d=h,c=o=h=Za(h.minus(1),h.plus(1),u,1),f=Qa(h.times(h),u,1),i=3;;){if(o=Qa(o.times(f),u,1),l=c.plus(Za(o,new _(i),u,1)),Ka(l.d).slice(0,u)===Ka(c.d).slice(0,u))if(c=c.times(2),a!==0&&(c=c.plus(to(_,u+2,y).times(a+``))),c=Za(c,new _(p),u,1),t==null)if(Ja(c.d,u-m,v,s))_.precision=u+=m,l=o=h=Za(d.minus(1),d.plus(1),u,1),f=Qa(h.times(h),u,1),i=s=1;else return Qa(c,_.precision=y,v,ka=!0);else return _.precision=y,c;c=l,i+=2}}function uo(e){return String(e.s*e.s/0)}function fo(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)%Ha,n<0&&(r+=Ha),r<i){for(r&&e.d.push(+t.slice(0,r)),i-=Ha;r<i;)e.d.push(+t.slice(r,r+=Ha));t=t.slice(r),r=Ha-t.length}else r-=i;for(;r--;)t+=`0`;e.d.push(+t),ka&&(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 po(e,t){var n,r,i,a,o,s,c,l,u;if(t.indexOf(`_`)>-1){if(t=t.replace(/(\d)_(?=\d)/g,`$1`),Ba.test(t))return fo(e,t)}else if(t===`Infinity`||t===`NaN`)return+t||(e.s=NaN),e.e=NaN,e.d=null,e;if(Ra.test(t))n=16,t=t.toLowerCase();else if(La.test(t))n=2;else if(za.test(t))n=8;else throw Error(ja+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=ao(r,new r(n),a,a*2)),l=Ya(t,n,Va),u=l.length-1,a=u;l[a]===0;--a)l.pop();return a<0?new r(e.s*0):(e.e=eo(l,u),e.d=l,ka=!1,o&&(e=Za(e,i,s*4)),c&&(e=e.times(Math.abs(c)<54?Ia(2,c):ss.pow(2,c))),ka=!0,e)}function mo(e,t){var n,r=t.d.length;if(r<3)return t.isZero()?t:ho(e,2,t,t);n=1.4*Math.sqrt(r),n=n>16?16:n|0,t=t.times(1/go(5,n)),t=ho(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 ho(e,t,n,r,i){var a,o,s,c,l=1,u=e.precision,d=Math.ceil(u/Ha);for(ka=!1,c=n.times(n),s=new e(r);;){if(o=Za(s.times(c),new e(t++*t++),u,1),s=i?r.plus(o):r.minus(o),r=Za(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 ka=!0,o.d.length=d+1,o}function go(e,t){for(var n=e;--t;)n*=e;return n}function _o(e,t){var n,r=t.s<0,i=no(e,e.precision,1),a=i.times(.5);if(t=t.abs(),t.lte(a))return Oa=r?4:1,t;if(n=t.divToInt(i),n.isZero())Oa=r?3:2;else{if(t=t.minus(n.times(i)),t.lte(a))return Oa=oo(n)?r?2:3:r?4:1,t;Oa=oo(n)?r?1:4:r?3:2}return t.minus(i).abs()}function vo(e,t,n,r){var i,a,o,s,c,l,u,d,f,p=e.constructor,m=n!==void 0;if(m?(qa(n,1,Sa),r===void 0?r=p.rounding:qa(r,0,8)):(n=p.precision,r=p.rounding),!e.isFinite())u=uo(e);else{for(u=$a(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=Ya($a(f),10,i),f.e=f.d.length),d=Ya(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=Za(e,f,n,r,0,i),d=e.d,a=e.e,l=Da),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+=Ca.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=Ya(u,i,t),c=d.length;!d[c-1];--c);for(o=1,u=`1.`;o<c;o++)u+=Ca.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 yo(e,t){if(e.length>t)return e.length=t,!0}function bo(e){return new this(e).abs()}function xo(e){return new this(e).acos()}function So(e){return new this(e).acosh()}function Co(e,t){return new this(e).plus(t)}function wo(e){return new this(e).asin()}function To(e){return new this(e).asinh()}function Eo(e){return new this(e).atan()}function Do(e){return new this(e).atanh()}function Oo(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=no(this,a,1).times(t.s>0?.25:.75),n.s=e.s):!t.d||e.isZero()?(n=t.s<0?no(this,r,i):new this(0),n.s=e.s):!e.d||t.isZero()?(n=no(this,a,1).times(.5),n.s=e.s):t.s<0?(this.precision=a,this.rounding=1,n=this.atan(Za(e,t,a,1)),t=no(this,a,1),this.precision=r,this.rounding=i,n=e.s<0?n.minus(t):n.plus(t)):n=this.atan(Za(e,t,a,1)),n}function ko(e){return new this(e).cbrt()}function Ao(e){return Qa(e=new this(e),e.e+1,2)}function jo(e,t,n){return new this(e).clamp(t,n)}function Mo(e){if(!e||typeof e!=`object`)throw Error(Aa+`Object expected`);var t,n,r,i=e.defaults===!0,a=[`precision`,1,Sa,`rounding`,0,8,`toExpNeg`,-xa,0,`toExpPos`,0,xa,`maxE`,0,xa,`minE`,-xa,0,`modulo`,0,9];for(t=0;t<a.length;t+=3)if(n=a[t],i&&(this[n]=Ea[n]),(r=e[n])!==void 0)if(Fa(r)===r&&r>=a[t+1]&&r<=a[t+2])this[n]=r;else throw Error(ja+n+`: `+r);if(n=`crypto`,i&&(this[n]=Ea[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(Na);else this[n]=!1;else throw Error(ja+n+`: `+r);return this}function No(e){return new this(e).cos()}function Po(e){return new this(e).cosh()}function Fo(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,Bo(e)){a.s=e.s,ka?!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++;ka?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 fo(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),Ba.test(e)?fo(a,e):po(a,e);if(r===`bigint`)return e<0?(e=-e,a.s=-1):a.s=1,fo(a,e.toString());throw Error(ja+e)}if(i.prototype=Y,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=Mo,i.clone=Fo,i.isDecimal=Bo,i.abs=bo,i.acos=xo,i.acosh=So,i.add=Co,i.asin=wo,i.asinh=To,i.atan=Eo,i.atanh=Do,i.atan2=Oo,i.cbrt=ko,i.ceil=Ao,i.clamp=jo,i.cos=No,i.cosh=Po,i.div=Io,i.exp=Lo,i.floor=Ro,i.hypot=zo,i.ln=Vo,i.log=Ho,i.log10=Wo,i.log2=Uo,i.max=Go,i.min=Ko,i.mod=qo,i.mul=Jo,i.pow=Yo,i.random=Xo,i.round=Zo,i.sign=Qo,i.sin=$o,i.sinh=es,i.sqrt=ts,i.sub=ns,i.sum=rs,i.tan=is,i.tanh=as,i.trunc=os,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 Io(e,t){return new this(e).div(t)}function Lo(e){return new this(e).exp()}function Ro(e){return Qa(e=new this(e),e.e+1,3)}function zo(){var e,t,n=new this(0);for(ka=!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 ka=!0,new this(1/0);n=t}return ka=!0,n.sqrt()}function Bo(e){return e instanceof ss||e&&e.toStringTag===Pa||!1}function Vo(e){return new this(e).ln()}function Ho(e,t){return new this(e).log(t)}function Uo(e){return new this(e).log(2)}function Wo(e){return new this(e).log(10)}function Go(){return so(this,arguments,-1)}function Ko(){return so(this,arguments,1)}function qo(e,t){return new this(e).mod(t)}function Jo(e,t){return new this(e).mul(t)}function Yo(e,t){return new this(e).pow(t)}function Xo(e){var t,n,r,i,a=0,o=new this(1),s=[];if(e===void 0?e=this.precision:qa(e,1,Sa),r=Math.ceil(e/Ha),!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(Na);for(r=s[--a],e%=Ha,r&&e&&(i=Ia(10,Ha-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-=Ha)s.shift();for(r=1,i=s[0];i>=10;i/=10)r++;r<Ha&&(n-=Ha-r)}return o.e=n,o.d=s,o}function Zo(e){return Qa(e=new this(e),e.e+1,this.rounding)}function Qo(e){return e=new this(e),e.d?e.d[0]?e.s:0*e.s:e.s||NaN}function $o(e){return new this(e).sin()}function es(e){return new this(e).sinh()}function ts(e){return new this(e).sqrt()}function ns(e,t){return new this(e).sub(t)}function rs(){var e=0,t=arguments,n=new this(t[e]);for(ka=!1;n.s&&++e<t.length;)n=n.plus(t[e]);return ka=!0,Qa(n,this.precision,this.rounding)}function is(e){return new this(e).tan()}function as(e){return new this(e).tanh()}function os(e){return Qa(e=new this(e),e.e+1,1)}Y[Symbol.for(`nodejs.util.inspect.custom`)]=Y.toString,Y[Symbol.toStringTag]=`Decimal`;var ss=Y.constructor=Fo(Ea);wa=new ss(wa),Ta=new ss(Ta);var cs=J(`BigNumber`,[`?on`,`config`],e=>{var{on:t,config:n}=e,r=ss.clone({precision:n.precision,modulo:ss.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}),ls=Math.cosh||function(e){return Math.abs(e)<1e-9?1-e:(Math.exp(e)+Math.exp(-e))*.5},us=Math.sinh||function(e){return Math.abs(e)<1e-9?e:(Math.exp(e)-Math.exp(-e))*.5},ds=e=>{let t=Math.sin(.5*e);return-2*t*t},fs=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))},ps=function(){throw SyntaxError(`Invalid Param`)};function ms(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 hs={re:0,im:0},gs=function(e,t){let n=hs;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 X.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 X.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]):ps();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&&ps();for(let e=0;e<t.length;e++){let a=t[e];a===` `||a===` `||a===`
|
|
2
|
+
import{$ as e,$t as t,A as n,At as r,B as i,Bt as a,C as o,Ct as s,D as c,Dt as l,E as u,Et as d,F as f,G as p,Gt as m,H as h,Ht as g,I as _,J as v,Jt as y,K as b,Kt as x,L as S,M as C,Mt as w,N as T,O as E,Ot as D,P as O,Q as k,Qt as A,R as j,S as M,T as N,U as P,Ut as F,V as I,Vt as L,W as R,Wt as z,X as B,Xt as V,Y as ee,Yt as te,Z as H,Zt as ne,_ as re,_t as ie,a as U,at as ae,b as oe,bt as se,ct as ce,d as le,dt as ue,en as de,et as fe,f as pe,ft as me,g as he,gt as ge,h as _e,ht as ve,i as ye,it as be,j as xe,jt as Se,k as Ce,kt as we,l as Te,lt as Ee,m as De,mt as Oe,n as ke,nn as Ae,nt as je,o as Me,ot as Ne,p as Pe,pt as Fe,q as Ie,qt as Le,r as Re,rn as ze,rt as Be,s as Ve,st as He,tn as Ue,tt as We,u as Ge,ut as Ke,v as qe,vt as Je,w as Ye,wt as Xe,x as Ze,xt as Qe,y as $e,z as et}from"./keys-CkI2qrI-.js";import{i as tt,n as nt,r as rt,t as it}from"./threshold-C9it0Y7P.js";import{createContext as at,forwardRef as ot,memo as st,startTransition as ct,useCallback as lt,useContext as ut,useEffect as W,useImperativeHandle as dt,useLayoutEffect as G,useMemo as ft,useRef as K,useState as pt,useSyncExternalStore as mt}from"react";import{createPortal as ht}from"react-dom";import{createRoot as gt}from"react-dom/client";import{Fragment as _t,jsx as q,jsxs as vt}from"react/jsx-runtime";var yt=Object.create,bt=Object.defineProperty,xt=Object.getOwnPropertyDescriptor,St=Object.getOwnPropertyNames,Ct=Object.getPrototypeOf,wt=Object.prototype.hasOwnProperty,Tt=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Et=(e,t)=>{let n={};for(var r in e)bt(n,r,{get:e[r],enumerable:!0});return t||bt(n,Symbol.toStringTag,{value:`Module`}),n},Dt=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=St(t),a=0,o=i.length,s;a<o;a++)s=i[a],!wt.call(e,s)&&s!==n&&bt(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=xt(t,s))||r.enumerable});return e},Ot=(e,t,n)=>(n=e==null?{}:yt(Ct(e)),Dt(t||!e||!e.__esModule?bt(n,`default`,{value:e,enumerable:!0}):n,e)),kt=[`text`,`brush`,`arrow`,`box`],At={text:14,brush:3,arrow:2,box:2},jt=/^#[0-9a-fA-F]{6}$/,Mt={text:[1,1],arrow:[2,2],box:[2,2],brush:[2,1/0]},Nt=e=>typeof e==`number`&&Number.isFinite(e);function Pt(e){if(!e||typeof e!=`object`)return null;let t=e,n=t.kind;if(!kt.includes(n)||typeof t.id!=`string`||!t.id||!Array.isArray(t.points))return null;let r=t.points.filter(e=>Array.isArray(e)&&Nt(e[0])&&Nt(e[1])).map(([e,t])=>[e,t]),[i,a]=Mt[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`&&jt.test(t.color)?t.color:`#f5a524`,width:Nt(t.width)&&t.width>0?Math.min(96,t.width):At[n],...typeof t.text==`string`&&t.text!==``?{text:t.text}:{}}}function Ft(e){return Array.isArray(e)?e.map(Pt).filter(e=>e!==null):null}var It={info:`#8a93a6`,warning:`#f5a524`,critical:`#e5484d`},Lt={info:`var(--text-muted, #8a93a6)`,warning:`var(--accent, #f5a524)`,critical:`var(--danger, #e5484d)`};function Rt(e,t){return{id:`mark:${e.id}`,kind:`box`,anchor:`x`,points:[[e.t0,0],[e.t1??t,1]],color:It[e.severity],width:1,...e.ruleName?{text:e.ruleName}:{}}}var zt=96,Bt=96,Vt=2,Ht={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,camera:6},Ut={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,camera:24},Wt=Ht,Gt=Ut;function Kt(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 qt(e,t,n,r=96){let i=Ht[e],a=Ut[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 Jt(e,t,n,r,i,a,o=96,s=96){let c=Math.round(r/Math.max(1e-6,a.width/o)),l=Math.round(i/Math.max(1e-6,a.height/s));return n===`move`?qt(e,{...t,x:t.x+c,y:t.y+l},o,s):{...t,w:Math.max(Ht[e],Math.min(t.w+c,o-t.x)),h:Math.max(Ut[e],Math.min(t.h+l,s-t.y))}}function Yt(e,t,n){for(let r of t)if(r.id!==n&&Kt(e,r.rect))return!0;return!1}function Xt(e,t,n=96){let r=Ht[e],i=Ut[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=qt(e,{x:s,y:i,w:a,h:o},n);if(!Yt(r,t,``))return r}return qt(e,{x:0,y:0,w:r,h:i},n)}function Zt(e,t){return{id:crypto.randomUUID(),kind:e,rect:Xt(e,t)}}function Qt(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=Qt(e-4).map(e=>({x:e.x*.5,y:e.y,w:e.w*.5,h:e.h})),n=Qt(4).map(e=>({x:.5+e.x*.5,y:e.y,w:e.w*.5,h:e.h}));return[...t,...n]}function $t(e,t=96,n=96){let r=Qt(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 en(){return{scaleMin:``,scaleMax:``,majorStep:``,minorStep:``,alarm:null}}var tn={style:`dashed`,width:1,color:null},nn={style:`solid`,width:1,color:null},rn={enabled:!1,reference:`previous`,datasetId:null,datasetColor:`#94a3b8`,previousColor:`#64748b`},an=/^#[0-9a-f]{6}$/i;function on(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`&&an.test(t.datasetColor)?t.datasetColor:rn.datasetColor,previousColor:typeof t.previousColor==`string`&&an.test(t.previousColor)?t.previousColor:rn.previousColor}}var sn=[`#f5a524`,`#38bdf8`,`#22c55e`,`#f472b6`,`#a78bfa`,`#fb7185`];function cn(e,t){return{id:crypto.randomUUID(),column:e,color:sn[t%sn.length],value:`last`,style:`arc`,min:``,max:``}}function ln(e,t){if(!e||typeof e!=`object`)return null;let n=e;if(typeof n.column!=`string`)return null;let r=Qn(n.alarm);return{id:typeof n.id==`string`&&n.id?n.id:`g${t}`,column:n.column,color:typeof n.color==`string`?n.color:sn[t%sn.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 un(e,t){let n=parseFloat(e),r=parseFloat(t);return Number.isFinite(n)&&Number.isFinite(r)&&n<r?[n,r]:void 0}var dn=1.8,fn=4,pn=1;function mn(){return{kind:`multiband`,series:[],addColumn:``,layout:`overlay`,xAxisLine:{...tn},yAxisLine:{...tn},gridLine:{...nn},lineWidth:1}}function hn(e){return{kind:`xyscatter`,xyXCol:``,xyYCol:``,xyColorCol:null,xyColor:e,xyPointRadius:dn,xyXAxisLine:{...tn},xyYAxisLine:{...tn},xyGridLine:{...nn},xyFit:null,xyXScale:en(),xyYScale:en()}}function gn(e=4){return{kind:`xyzmesh`,xyzXCol:``,xyzYCol:``,xyzZCol:``,xyzViewMode:`3d`,xyzXScale:en(),xyzYScale:en(),xyzZScale:en(),xyzPointRadius:e,showMesh:!1,meshStyle:`filled`,meshOpacity:.85}}function _n(){return{kind:`histogram`,histColumn:``,histBins:0,histColor:`#38bdf8`,histNormal:!1,histLogY:!1}}function vn(){return{kind:`polar`,polarAngleCol:``,polarRadiusCol:``,polarColor:`#a78bfa`,polarMode:`waveform`,polarRadiusMin:``,polarRadiusMax:``}}function yn(){return{kind:`spectrum`,specSignalCol:``,specTimeCol:``,specSampleRate:`1000`,specXMode:`hz`,specYMode:`amplitude`,specWindow:`hann`,specColor:`#34d399`,specLogX:!1}}function bn(){return{kind:`boxplot`,boxValueCol:``,boxGroupCol:``,boxColor:`#fb923c`,boxWhiskers:`1.5iqr`}}function xn(){return{kind:`spectrogram`,sgSignalCol:``,sgTimeCol:``,sgSampleRate:`1000`,sgWindowSize:512,sgOverlap:.5,sgWinFunc:`hann`,sgYMode:`db`,sgLogFreq:!1}}function Sn(){return{kind:`heatmap`,hmMode:`binned`,hmColumns:[],hmXCol:``,hmYCol:``,hmValueCol:``,hmXBins:6,hmYBins:6,hmXMin:``,hmXMax:``,hmYMin:``,hmYMax:``,hmShowValues:!0,hmColorScheme:`diverging`}}function Cn(){return{kind:`violin`,vlValueCol:``,vlGroupCol:``,vlColor:`#818cf8`,vlShowBox:!0,vlBandwidth:``,vlOrientation:`vertical`}}function wn(){return{kind:`confusion`,cfActualCol:``,cfPredictedCol:``,cfNormalize:!1}}function Tn(){return{kind:`roc`,rocScoreCol:``,rocLabelCol:``,rocMode:`roc`,rocColor:`#f472b6`}}function En(){return{kind:`losscurve`,lcXCol:``,lcLeftCols:[],lcRightCols:[]}}function Dn(){return{kind:`controlchart`,ccValueCol:``,ccSubgroupCol:``,ccSigmaLevel:3,ccColor:`#22d3ee`}}function On(){return{kind:`parallelcoords`,pcColumns:[],pcColorByCol:``,pcColor:`#64748b`}}function kn(){return{kind:`embedding`,emXCol:``,emYCol:``,emColorCol:``,emColorMode:`categorical`,emLabelCol:``,emPointSize:3,emColor:`#a78bfa`}}function An(){return{kind:`flamegraph`,fgNameCol:``,fgParentCol:``,fgValueCol:``,fgDirection:`topdown`}}function jn(){return{kind:`barchart`,bcCategoryCol:``,bcValueCols:[],bcMode:`grouped`,bcHorizontal:!1}}function Mn(){return{kind:`radar`,rdAxesCols:[],rdGroupCol:``,rdColor:`#38bdf8`,rdFill:!0}}function Nn(){return{kind:`areachart`,acXCol:``,acYCols:[],acStacked:!1}}function Pn(){return{kind:`cdfchart`,cdValueCols:[],cdComplement:!1,cdLogX:!1}}function Fn(){return{kind:`bubblechart`,bbXCol:``,bbYCol:``,bbSizeCol:``,bbColorCol:``,bbColorMode:`categorical`,bbColor:`#64748b`,bbMaxRadius:24}}function In(){return{kind:`treemap`,tmNameCol:``,tmParentCol:``,tmValueCol:``}}function Ln(){return{kind:`sankey`,skSourceCol:``,skTargetCol:``,skValueCol:``}}function Rn(){return{kind:`gauge`,ggGauges:[]}}function zn(){return{kind:`calibration`,cbScoreCol:``,cbLabelCol:``,cbBins:10,cbColor:`#38bdf8`}}function Bn(){return{kind:`qqplot`,qqValueCol:``,qqMode:`normal`,qqRefCol:``,qqColor:`#a78bfa`}}function Vn(){return{kind:`gantt`,gtLabelCol:``,gtStartCol:``,gtEndCol:``,gtGroupCol:``}}function Hn(e,t){let n=(e.parentId?t.find(t=>t.id===e.parentId)?.name:void 0)??e.parentName;return n?`${n} · ${e.name}`:e.name}var Un=()=>({kind:`camera`,cameraStreamId:``,cameras:[],syncStreamId:``,offsetMs:0,fit:`contain`}),Wn=9;function Gn(e){return e.cameraStreamId?e.cameras?.[0]===e.cameraStreamId?e.cameras.slice(0,9):[e.cameraStreamId]:[]}function Kn(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 qn(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 Jn(e,t){return qn(e)?e:{...t}}function Yn(e){if(!e||typeof e!=`object`)return!1;let t=e;return t.kind===`multiband`&&Array.isArray(t.series)&&t.series.every(Kn)&&typeof t.addColumn==`string`}function Xn(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 Zn(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 Qn(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,...typeof t.ruleId==`string`&&$n.test(t.ruleId)?{ruleId:t.ruleId}:{}}}var $n=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function er(e,t){if(!t.size)return e;let n=!1,r=e=>{let r=e?.ruleId?t.get(e.ruleId):void 0;return!e||!r?e:(n=!0,{...e,value:r.value,linked:r.active?`active`:`idle`})},i=e,a=null,o=(e,t)=>{a??={...i},a[e]=t};if(e.kind===`multiband`){let t=e.series.map(e=>{let t=r(e.alarm);return t===e.alarm?e:{...e,alarm:t}});n&&o(`series`,t)}else if(e.kind===`gauge`){let t=e.ggGauges.map(e=>{let t=r(e.alarm);return t===e.alarm?e:{...e,alarm:t}});n&&o(`ggGauges`,t)}else if(e.kind===`xyscatter`||e.kind===`xyzmesh`){let t=e.kind===`xyscatter`?[`xyXScale`,`xyYScale`]:[`xyzXScale`,`xyzYScale`,`xyzZScale`];for(let e of t){let t=i[e],n=r(t?.alarm);t&&n!==t.alarm&&o(e,{...t,alarm:n})}}else if(e.kind in tr){let t=tr[e.kind],n=r(i[t]);n!==i[t]&&o(t,n)}return a||e}var tr={histogram:`histAlarm`,spectrum:`specAlarm`,areachart:`acAlarm`,losscurve:`lcAlarm`,cdfchart:`cdAlarm`,bubblechart:`bbAlarm`,boxplot:`boxAlarm`,violin:`vlAlarm`,barchart:`bcAlarm`,gantt:`gtAlarm`};function nr(e){if(!e||!(e.kind in tr))return null;let t=e[tr[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 rr(e){let t=en();if(!e||typeof e!=`object`)return t;let n=e,r=Qn(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 ir(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(Yn(n)){let e=n;r[t]={kind:`multiband`,series:Array.isArray(e.series)?e.series.map(e=>e&&e.alarm&&typeof e.alarm==`object`?{...e,alarm:Qn(e.alarm)}:e):e.series,addColumn:e.addColumn,layout:e.layout===`parallel`?`parallel`:`overlay`,xAxisLine:Jn(e.xAxisLine,tn),yAxisLine:Jn(e.yAxisLine,tn),gridLine:Jn(e.gridLine,nn),lineWidth:typeof e.lineWidth==`number`&&Number.isFinite(e.lineWidth)?Math.min(6,Math.max(.5,e.lineWidth)):1,...on(e.beacon)?{beacon:on(e.beacon)}:{},...e.envelope===!0?{envelope:!0}:{}}}else if(Xn(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:Jn(e.xyXAxisLine,tn),xyYAxisLine:Jn(e.xyYAxisLine,tn),xyGridLine:Jn(e.xyGridLine,nn),xyFit:a,xyXScale:rr(e.xyXScale),xyYScale:rr(e.xyYScale)}}else if(Zn(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??rr(n.xyzXScale),xyzYScale:a??rr(n.xyzYScale),xyzZScale:o??rr(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=ln(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:``}}else if(n&&typeof n==`object`&&n.kind===`camera`){let e=n,i=typeof e.offsetMs==`number`&&Number.isFinite(e.offsetMs)?Math.round(e.offsetMs):0,a=Array.isArray(e.cameras)?[...new Set(e.cameras.filter(e=>typeof e==`string`&&e!==``))]:[],o=typeof e.cameraStreamId==`string`&&e.cameraStreamId?e.cameraStreamId:a[0]??``;r[t]={kind:`camera`,cameraStreamId:o,cameras:Gn({cameraStreamId:o,cameras:a.length?a:[o]}),syncStreamId:typeof e.syncStreamId==`string`?e.syncStreamId:``,offsetMs:Math.max(-1e4,Math.min(1e4,i)),fit:e.fit===`cover`?`cover`:`contain`}}let e=r[t]?Ft(n?.annotations):null;e?.length&&(r[t]={...r[t],annotations:e});let i=r[t]?tr[r[t].kind]:void 0,a=i?Qn(n[i]):null;i&&a&&(r[t]={...r[t],[i]:a})}return r}function ar(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]=mn(),a=!0)}else if(t.kind===`xyscatter`){let e=i[t.id];(!e||e.kind!==`xyscatter`)&&(i[t.id]=hn(n),a=!0)}else if(t.kind===`xyzmesh`){let e=i[t.id];(!e||e.kind!==`xyzmesh`)&&(i[t.id]=gn(r),a=!0)}else if(t.kind===`histogram`){let e=i[t.id];(!e||e.kind!==`histogram`)&&(i[t.id]=_n(),a=!0)}else if(t.kind===`polar`){let e=i[t.id];(!e||e.kind!==`polar`)&&(i[t.id]=vn(),a=!0)}else if(t.kind===`spectrum`){let e=i[t.id];(!e||e.kind!==`spectrum`)&&(i[t.id]=yn(),a=!0)}else if(t.kind===`boxplot`){let e=i[t.id];(!e||e.kind!==`boxplot`)&&(i[t.id]=bn(),a=!0)}else t.kind===`spectrogram`?(!i[t.id]||i[t.id].kind!==`spectrogram`)&&(i[t.id]=xn(),a=!0):t.kind===`heatmap`?(!i[t.id]||i[t.id].kind!==`heatmap`)&&(i[t.id]=Sn(),a=!0):t.kind===`violin`?(!i[t.id]||i[t.id].kind!==`violin`)&&(i[t.id]=Cn(),a=!0):t.kind===`confusion`?(!i[t.id]||i[t.id].kind!==`confusion`)&&(i[t.id]=wn(),a=!0):t.kind===`roc`?(!i[t.id]||i[t.id].kind!==`roc`)&&(i[t.id]=Tn(),a=!0):t.kind===`losscurve`?(!i[t.id]||i[t.id].kind!==`losscurve`)&&(i[t.id]=En(),a=!0):t.kind===`controlchart`?(!i[t.id]||i[t.id].kind!==`controlchart`)&&(i[t.id]=Dn(),a=!0):t.kind===`parallelcoords`?(!i[t.id]||i[t.id].kind!==`parallelcoords`)&&(i[t.id]=On(),a=!0):t.kind===`embedding`?(!i[t.id]||i[t.id].kind!==`embedding`)&&(i[t.id]=kn(),a=!0):t.kind===`flamegraph`?(!i[t.id]||i[t.id].kind!==`flamegraph`)&&(i[t.id]=An(),a=!0):t.kind===`barchart`?(!i[t.id]||i[t.id].kind!==`barchart`)&&(i[t.id]=jn(),a=!0):t.kind===`radar`?(!i[t.id]||i[t.id].kind!==`radar`)&&(i[t.id]=Mn(),a=!0):t.kind===`areachart`?(!i[t.id]||i[t.id].kind!==`areachart`)&&(i[t.id]=Nn(),a=!0):t.kind===`cdfchart`?(!i[t.id]||i[t.id].kind!==`cdfchart`)&&(i[t.id]=Pn(),a=!0):t.kind===`bubblechart`?(!i[t.id]||i[t.id].kind!==`bubblechart`)&&(i[t.id]=Fn(),a=!0):t.kind===`treemap`?(!i[t.id]||i[t.id].kind!==`treemap`)&&(i[t.id]=In(),a=!0):t.kind===`sankey`?(!i[t.id]||i[t.id].kind!==`sankey`)&&(i[t.id]=Ln(),a=!0):t.kind===`gauge`?(!i[t.id]||i[t.id].kind!==`gauge`)&&(i[t.id]=Rn(),a=!0):t.kind===`calibration`?(!i[t.id]||i[t.id].kind!==`calibration`)&&(i[t.id]=zn(),a=!0):t.kind===`qqplot`?(!i[t.id]||i[t.id].kind!==`qqplot`)&&(i[t.id]=Bn(),a=!0):t.kind===`gantt`?(!i[t.id]||i[t.id].kind!==`gantt`)&&(i[t.id]=Vn(),a=!0):t.kind===`camera`&&(!i[t.id]||i[t.id].kind!==`camera`)&&(i[t.id]=Un(),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 or(e){return e===null||typeof e==`number`&&e>0?{liveWindowSeconds:e}:{}}function sr(e){return Number.isNaN(e)?0:Math.min(100,Math.max(0,e))}function cr(){return crypto.randomUUID()}function lr(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 ur(){return ur=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},ur.apply(null,arguments)}var dr={relTol:1e-12,absTol:1e-15,matrix:`Matrix`,number:`number`,numberFallback:`number`,precision:64,predictable:!1,randomSeed:null,legacySubset:!1};function fr(e,t){if(mr(e,t)||hr(e,t))return e[t];throw vr(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 pr(e,t,n){if(mr(e,t)||hr(e,t))return e[t]=n,n;throw Error(`No access to property "${t}"`)}function mr(e,t){return yr(e)?!(t in Object.prototype):!1}function hr(e,t){return Array.isArray(e)?typeof t==`number`||typeof t==`string`&&gr(t)||t===`length`:!1}function gr(e){return/^\d+$/.test(e)}function _r(e,t){if(!vr(e,t))throw Error(`No access to method "`+t+`"`);return e[t]}function vr(e,t){return e==null||typeof e[t]!=`function`||Ei(e,t)&&Object.getPrototypeOf&&t in Object.getPrototypeOf(e)?!1:br.has(t)?!0:!(t in Object.prototype||t in Function.prototype)}function yr(e){return typeof e==`object`&&e&&e.constructor===Object}var br=new Set([`toString`,`valueOf`,`toLocaleString`]),xr=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 fr(this.wrappedObject,e)}set(e,t){return pr(this.wrappedObject,e,t),this}has(e){return mr(this.wrappedObject,e)&&e in this.wrappedObject}entries(){return Cr(this.keys(),e=>[e,this.get(e)])}forEach(e){for(var t of this.keys())e(this.get(t),t,this)}delete(e){mr(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}},Sr=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 Cr(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 Cr(e,t){return{next:()=>{var n=e.next();return n.done?n:{value:t(n.value),done:!1}}}}function wr(){return new Map}function Tr(e){if(!e)return wr();if(Jr(e))return e;if(qr(e))return new xr(e);throw Error(`createMap can create maps from objects or Maps`)}function Er(e){if(e instanceof xr)return e.wrappedObject;var t={};for(var n of e.keys())pr(t,n,e.get(n));return t}function Dr(e){return typeof e==`number`}function Or(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 kr(e){return typeof e==`bigint`}function Ar(e){return e&&typeof e==`object`&&Object.getPrototypeOf(e).isComplex===!0||!1}function jr(e){return e&&typeof e==`object`&&Object.getPrototypeOf(e).isFraction===!0||!1}function Mr(e){return e&&e.constructor.prototype.isUnit===!0||!1}function Nr(e){return typeof e==`string`}var Pr=Array.isArray;function Fr(e){return e&&e.constructor.prototype.isMatrix===!0||!1}function Ir(e){return Array.isArray(e)||Fr(e)}function Lr(e){return e&&e.isDenseMatrix&&e.constructor.prototype.isMatrix===!0||!1}function Rr(e){return e&&e.isSparseMatrix&&e.constructor.prototype.isMatrix===!0||!1}function zr(e){return e&&e.constructor.prototype.isRange===!0||!1}function Br(e){return e&&e.constructor.prototype.isIndex===!0||!1}function Vr(e){return typeof e==`boolean`}function Hr(e){return e&&e.constructor.prototype.isResultSet===!0||!1}function Ur(e){return e&&e.constructor.prototype.isHelp===!0||!1}function Wr(e){return typeof e==`function`}function Gr(e){return e instanceof Date}function Kr(e){return e instanceof RegExp}function qr(e){return!!(e&&typeof e==`object`&&e.constructor===Object&&!Ar(e)&&!jr(e))}function Jr(e){return e?e instanceof Map||e instanceof xr||typeof e.set==`function`&&typeof e.get==`function`&&typeof e.keys==`function`&&typeof e.has==`function`:!1}function Yr(e){return Jr(e)&&Jr(e.a)&&Jr(e.b)}function Xr(e){return Jr(e)&&qr(e.wrappedObject)}function Zr(e){return e===null}function Qr(e){return e===void 0}function $r(e){return e&&e.isAccessorNode===!0&&e.constructor.prototype.isNode===!0||!1}function ei(e){return e&&e.isArrayNode===!0&&e.constructor.prototype.isNode===!0||!1}function ti(e){return e&&e.isAssignmentNode===!0&&e.constructor.prototype.isNode===!0||!1}function ni(e){return e&&e.isBlockNode===!0&&e.constructor.prototype.isNode===!0||!1}function ri(e){return e&&e.isConditionalNode===!0&&e.constructor.prototype.isNode===!0||!1}function ii(e){return e&&e.isConstantNode===!0&&e.constructor.prototype.isNode===!0||!1}function ai(e){return ii(e)||di(e)&&e.args.length===1&&ii(e.args[0])&&`-+~`.includes(e.op)}function oi(e){return e&&e.isFunctionAssignmentNode===!0&&e.constructor.prototype.isNode===!0||!1}function si(e){return e&&e.isFunctionNode===!0&&e.constructor.prototype.isNode===!0||!1}function ci(e){return e&&e.isIndexNode===!0&&e.constructor.prototype.isNode===!0||!1}function li(e){return e&&e.isNode===!0&&e.constructor.prototype.isNode===!0||!1}function ui(e){return e&&e.isObjectNode===!0&&e.constructor.prototype.isNode===!0||!1}function di(e){return e&&e.isOperatorNode===!0&&e.constructor.prototype.isNode===!0||!1}function fi(e){return e&&e.isParenthesisNode===!0&&e.constructor.prototype.isNode===!0||!1}function pi(e){return e&&e.isRangeNode===!0&&e.constructor.prototype.isNode===!0||!1}function mi(e){return e&&e.isRelationalNode===!0&&e.constructor.prototype.isNode===!0||!1}function hi(e){return e&&e.isSymbolNode===!0&&e.constructor.prototype.isNode===!0||!1}function gi(e){return e&&e.constructor.prototype.isChain===!0||!1}function _i(e){var t=typeof e;return t===`object`?e===null?`null`:Or(e)?`BigNumber`:e.constructor&&e.constructor.name?e.constructor.name:`Object`:t}function vi(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 vi(e)});if(e instanceof Date)return new Date(e.valueOf());if(Or(e))return e;if(qr(e))return yi(e,vi);if(t===`function`)return e;throw TypeError(`Cannot clone: unknown type of value (value: ${e})`)}function yi(e,t){var n={};for(var r in e)Ei(e,r)&&(n[r]=t(e[r]));return n}function bi(e,t){for(var n in t)Ei(t,n)&&(e[n]=t[n]);return e}function xi(e,t){if(Array.isArray(t))throw TypeError(`Arrays are not supported by deepExtend`);for(var n in t)if(Ei(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?xi(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 Si(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(!Si(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)||!Si(e[n],t[n]))return!1;for(n in t)if(!(n in e))return!1;return!0}else return e===t}function Ci(e){var t={};return wi(e,t),t}function wi(e,t){for(var n in e)if(Ei(e,n)){var r=e[n];typeof r==`object`&&r?wi(r,t):t[n]=r}}function Ti(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 Ei(e,t){return e&&Object.hasOwnProperty.call(e,t)}function Di(e){return e&&typeof e.factory==`function`}function Oi(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 ki=[`Matrix`,`Array`],Ai=[`number`,`BigNumber`,`bigint`,`Fraction`];function ji(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=vi(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=vi(e);Mi(r,`matrix`,ki),Mi(r,`number`,Ai),xi(e,r);var o=vi(e);return t(`config`,o,a,vi(r)),o}else return vi(e)}return n.MATRIX_OPTIONS=ki,n.NUMBER_OPTIONS=Ai,Object.keys(dr).forEach(t=>{Object.defineProperty(n,t,{get:()=>e[t],enumerable:!0,configurable:!0})}),n}function Mi(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 Ni=Tt(((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(){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=oe(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=ae(e).map(D);let n=t.length,r=D(oe(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)?oe(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=oe(n),a=oe(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,se(arguments,0,t).concat([se(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 le(a,function(i){return t(e,n+1,r.concat([i]))})}else return[r]}return t(e,0,[])}function ee(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 te(e){return e.map(e=>me(e)?fe(e.referToSelf.callback):pe(e)?de(e.referTo.references,e.referTo.callback):e)}function H(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 ne(e,t,n){let r=te(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(me(s))r[o]=s.referToSelf.callback(n),r[o].referToSelf=s.referToSelf,i[o]=!0,e=!1;else if(pe(s)){let n=H(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 re(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 ie(e,r){if(d.createCount++,Object.keys(r).length===0)throw SyntaxError(`No signatures provided`);d.warnAgainstDeprecatedThis&&re(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(ee(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=ne(a,o,ve),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 te=m?f[0].implementation:n,H=h?f[1].implementation:n,ie=g?f[2].implementation:n,U=_?f[3].implementation:n,ae=v?f[4].implementation:n,oe=y?f[5].implementation:n,se=m?f[0].params.length:-1,ce=h?f[1].params.length:-1,le=g?f[2].params.length:-1,ue=_?f[3].params.length:-1,de=v?f[4].params.length:-1,fe=y?f[5].params.length:-1,pe=b?6:0,me=f.length,he=f.map(e=>e.test),ge=f.map(e=>e.implementation),_e=function(){for(let e=pe;e<me;e++)if(he[e](arguments))return ge[e].apply(this,arguments);return d.onMismatch(e,arguments,f)};function ve(e,t){return arguments.length===se&&S(e)&&N(t)?te.apply(this,arguments):arguments.length===ce&&w(e)&&P(t)?H.apply(this,arguments):arguments.length===le&&k(e)&&F(t)?ie.apply(this,arguments):arguments.length===ue&&A(e)&&I(t)?U.apply(this,arguments):arguments.length===de&&j(e)&&R(t)?ae.apply(this,arguments):arguments.length===fe&&M(e)&&B(t)?oe.apply(this,arguments):_e.apply(this,arguments)}try{Object.defineProperty(ve,`name`,{value:e})}catch{}return ve.signatures=o,ve._typedFunctionData={signatures:f,signatureMap:p},ve}function U(e,t,n){throw N(e,t,n)}function ae(e){return se(e,0,e.length-1)}function oe(e){return e[e.length-1]}function se(e,t,n){return Array.prototype.slice.call(e,t,n)}function ce(e,t){for(let n=0;n<e.length;n++)if(t(e[n]))return e[n]}function le(e,t){return Array.prototype.concat.apply([],e.map(t))}function ue(){let e=ae(arguments).map(e=>x(T(e))),t=oe(arguments);if(typeof t!=`function`)throw TypeError(`Callback function expected as last argument`);return de(e,t)}function de(e,t){return{referTo:{references:e,callback:t}}}function fe(e){if(typeof e!=`function`)throw TypeError(`Callback function expected as first argument`);return{referToSelf:{callback:e}}}function pe(e){return e&&typeof e.referTo==`object`&&Array.isArray(e.referTo.references)&&typeof e.referTo.callback==`function`}function me(e){return e&&typeof e.referToSelf==`object`&&typeof e.referToSelf.callback==`function`}function he(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 ge(e){let t;for(let n in e)Object.prototype.hasOwnProperty.call(e,n)&&(_(e[n])||typeof e[n].signature==`string`)&&(t=he(t,e[n].name));return t}function _e(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 ve=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=ge(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=he(r,s)),_e(i,o)}return ie(r||``,i)},d.create=i,d.createCount=ve.createCount,d.onMismatch=U,d.throwMismatchError=U,d.createError=N,d.clear=m,d.clearConversions=h,d.addTypes=p,d._findType=f,d.referTo=ue,d.referToSelf=fe,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 ye(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};ye(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){ye(e);let t=f(e.to),n=ce(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 J(e,t,n,r){function i(r){var i=Oi(r,t.map(Li));return Fi(e,t,r),n(i)}return i.isFactory=!0,i.fn=e,i.dependencies=t.slice().sort(),r&&(i.meta=r),i}function Pi(e){return typeof e==`function`&&typeof e.fn==`string`&&Array.isArray(e.dependencies)}function Fi(e,t,n){if(!t.filter(e=>!Ii(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 Ii(e){return e&&e[0]===`?`}function Li(e){return e&&e[0]===`?`?e.slice(1):e}function Ri(e){return typeof e==`boolean`?!0:Number.isFinite(e)?e===Math.round(e):!1}function zi(e,t){if(t.number===`bigint`)try{BigInt(e)}catch{return t.numberFallback}return t.number}var Bi=Math.sign||function(e){return e>0?1:e<0?-1:0},Vi=Math.log2||function(e){return Math.log(e)/Math.LN2},Hi=Math.log10||function(e){return Math.log(e)/Math.LN10},Ui=Math.log1p||function(e){return Math.log(e+1)},Wi=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},Gi=Math.expm1||function(e){return e>=2e-4||e<=-2e-4?Math.exp(e)-1:e+e*e/2+e*e*e/6};function Ki(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(!Ri(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(!Ri(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 qi(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}=Ji(t);switch(n){case`fixed`:return Zi(e,r);case`exponential`:return Qi(e,r);case`engineering`:return Xi(e,r);case`bin`:return Ki(e,2,i);case`oct`:return Ki(e,8,i);case`hex`:return Ki(e,16,i);case`auto`:return $i(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 Ji(e){var t=`auto`,n,r;if(e!==void 0)if(Dr(e))n=e;else if(Or(e))n=e.toNumber();else if(qr(e))e.precision!==void 0&&(n=da(e.precision,()=>{throw Error(`Option "precision" must be a number or BigNumber`)})),e.wordSize!==void 0&&(r=da(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 Yi(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 Xi(e,t){if(isNaN(e)||!Number.isFinite(e))return String(e);var n=ea(Yi(e),t),r=n.exponent,i=n.coefficients,a=r%3==0?r:r<0?r-3-r%3:r-r%3;if(Dr(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=Dr(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 Zi(e,t){if(isNaN(e)||!Number.isFinite(e))return String(e);var n=Yi(e),r=typeof t==`number`?ea(n,n.exponent+1+t):n,i=r.coefficients,a=r.exponent+1,o=a+(t||0);return i.length<o&&(i=i.concat(ta(o-i.length))),a<0&&(i=ta(-a+1).concat(i),a=1),a<i.length&&i.splice(a,0,a===0?`0.`:`.`),r.sign+i.join(``)}function Qi(e,t){if(isNaN(e)||!Number.isFinite(Number(e)))return String(e);var n=Yi(e),r=t?ea(n,t):n,i=r.coefficients,a=r.exponent;i.length<t&&(i=i.concat(ta(t-i.length)));var o=i.shift();return r.sign+o+(i.length>0?`.`+i.join(``):``)+`e`+(a>=0?`+`:``)+a}function $i(e,t,n){if(isNaN(e)||!Number.isFinite(e))return String(e);var r=fa(n?.lowerExp,-3),i=fa(n?.upperExp,5),a=Yi(e),o=t?ea(a,t):a;if(o.exponent<r||o.exponent>=i)return Qi(e,t);var s=o.coefficients,c=o.exponent;s.length<t&&(s=s.concat(ta(t-s.length))),s=s.concat(ta(c-s.length+1+(s.length<t?t-s.length:0))),s=ta(-c).concat(s);var l=c>0?c:0;return l<s.length-1&&s.splice(l+1,0,`.`),o.sign+s.join(``)}function ea(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 ta(e){for(var t=[],n=0;n<e;n++)t.push(0);return t}function na(e){return e.toExponential().replace(/e.*$/,``).replace(/^0\.?0*|\./,``).length}function ra(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 ia=Math.acosh||function(e){return Math.log(Math.sqrt(e*e-1)+e)},aa=Math.asinh||function(e){return Math.log(Math.sqrt(e*e+1)+e)},oa=Math.atanh||function(e){return Math.log((1+e)/(1-e))/2},sa=Math.cosh||function(e){return(Math.exp(e)+Math.exp(-e))/2},ca=Math.sinh||function(e){return(Math.exp(e)-Math.exp(-e))/2},la=Math.tanh||function(e){var t=Math.exp(2*e);return(t-1)/(t+1)};function ua(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 da(e,t){if(Dr(e))return e;if(Or(e))return e.toNumber();t()}function fa(e,t){return Dr(e)?e:Or(e)?e.toNumber():t}var pa=Ot(Ni(),1),ma=function(){return ma=pa.default.create,pa.default},ha=J(`typed`,[`?BigNumber`,`?Complex`,`?DenseMatrix`,`?Fraction`],function(e){var{BigNumber:t,Complex:n,DenseMatrix:r,Fraction:i}=e,a=ma();return a.clear(),a.addTypes([{name:`number`,test:Dr},{name:`Complex`,test:Ar},{name:`BigNumber`,test:Or},{name:`bigint`,test:kr},{name:`Fraction`,test:jr},{name:`Unit`,test:Mr},{name:`identifier`,test:e=>Nr&&/^(?:[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:Nr},{name:`Chain`,test:gi},{name:`Array`,test:Pr},{name:`Matrix`,test:Fr},{name:`DenseMatrix`,test:Lr},{name:`SparseMatrix`,test:Rr},{name:`Range`,test:zr},{name:`Index`,test:Br},{name:`boolean`,test:Vr},{name:`ResultSet`,test:Hr},{name:`Help`,test:Ur},{name:`function`,test:Wr},{name:`Date`,test:Gr},{name:`RegExp`,test:Kr},{name:`null`,test:Zr},{name:`undefined`,test:Qr},{name:`AccessorNode`,test:$r},{name:`ArrayNode`,test:ei},{name:`AssignmentNode`,test:ti},{name:`BlockNode`,test:ni},{name:`ConditionalNode`,test:ri},{name:`ConstantNode`,test:ii},{name:`FunctionNode`,test:si},{name:`FunctionAssignmentNode`,test:oi},{name:`IndexNode`,test:ci},{name:`Node`,test:li},{name:`ObjectNode`,test:ui},{name:`OperatorNode`,test:di},{name:`ParenthesisNode`,test:fi},{name:`RangeNode`,test:pi},{name:`RelationalNode`,test:mi},{name:`SymbolNode`,test:hi},{name:`Map`,test:Jr},{name:`Object`,test:qr}]),a.addConversions([{from:`number`,to:`BigNumber`,convert:function(e){if(t||ga(e),na(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||_a(e),new n(e,0)}},{from:`BigNumber`,to:`Complex`,convert:function(e){return n||_a(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||ga(e),new t(e.toString())}},{from:`bigint`,to:`Fraction`,convert:function(e){return i||ya(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||_a(e),new n(e.valueOf(),0)}},{from:`number`,to:`Fraction`,convert:function(e){i||ya(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||ga(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||ya(e);try{return new i(e)}catch{throw Error(`Cannot convert "`+e+`" to Fraction`)}}},{from:`string`,to:`Complex`,convert:function(e){n||_a(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||ga(e),new t(+e)}},{from:`boolean`,to:`bigint`,convert:function(e){return BigInt(+e)}},{from:`boolean`,to:`Fraction`,convert:function(e){return i||ya(e),new i(+e)}},{from:`boolean`,to:`string`,convert:function(e){return String(e)}},{from:`Array`,to:`Matrix`,convert:function(e){return r||va(),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&&Ir(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&&Ir(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 ga(e){throw Error(`Cannot convert value ${e} into a BigNumber: no class 'BigNumber' provided`)}function _a(e){throw Error(`Cannot convert value ${e} into a Complex number: no class 'Complex' provided`)}function va(){throw Error(`Cannot convert array into a Matrix: no class 'DenseMatrix' provided`)}function ya(e){throw Error(`Cannot convert value ${e} into a Fraction, no class 'Fraction' provided.`)}var ba=J(`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}),xa=9e15,Sa=1e9,Ca=`0123456789abcdef`,wa=`2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058`,Ta=`3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789`,Ea={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-xa,maxE:xa,crypto:!1},Da,Oa,ka=!0,Aa=`[DecimalError] `,ja=Aa+`Invalid argument: `,Ma=Aa+`Precision limit exceeded`,Na=Aa+`crypto unavailable`,Pa=`[object Decimal]`,Fa=Math.floor,Ia=Math.pow,La=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,Ra=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,za=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,Ba=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,Va=1e7,Ha=7,Ua=9007199254740991,Wa=wa.length-1,Ga=Ta.length-1,Y={toStringTag:Pa};Y.absoluteValue=Y.abs=function(){var e=new this.constructor(this);return e.s<0&&(e.s=1),Qa(e)},Y.ceil=function(){return Qa(new this.constructor(this),this.e+1,2)},Y.clampedTo=Y.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(ja+t);return n=r.cmp(e),n<0?e:r.cmp(t)>0?t:new i(r)},Y.comparedTo=Y.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},Y.cosine=Y.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())+Ha,r.rounding=1,n=Xa(r,_o(r,n)),r.precision=e,r.rounding=t,Qa(Oa==2||Oa==3?n.neg():n,e,t,!0)):new r(1):new r(NaN)},Y.cubeRoot=Y.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(ka=!1,a=u.s*Ia(u.s*u,1/3),!a||Math.abs(a)==1/0?(n=Ka(u.d),e=u.e,(a=(e-n.length+1)%3)&&(n+=a==1||a==-2?`0`:`00`),a=Ia(n,1/3),e=Fa((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=Za(l.plus(u).times(s),l.plus(c),o+2,1),Ka(s.d).slice(0,o)===(n=Ka(r.d)).slice(0,o))if(n=n.slice(o-3,o+1),n==`9999`||!i&&n==`4999`){if(!i&&(Qa(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`)&&(Qa(r,e+1,1),t=!r.times(r).times(r).eq(u));break}return ka=!0,Qa(r,e,d.rounding,t)},Y.decimalPlaces=Y.dp=function(){var e,t=this.d,n=NaN;if(t){if(e=t.length-1,n=(e-Fa(this.e/Ha))*Ha,e=t[e],e)for(;e%10==0;e/=10)n--;n<0&&(n=0)}return n},Y.dividedBy=Y.div=function(e){return Za(this,new this.constructor(e))},Y.dividedToIntegerBy=Y.divToInt=function(e){var t=this,n=t.constructor;return Qa(Za(t,new n(e),0,1,1),n.precision,n.rounding)},Y.equals=Y.eq=function(e){return this.cmp(e)===0},Y.floor=function(){return Qa(new this.constructor(this),this.e+1,3)},Y.greaterThan=Y.gt=function(e){return this.cmp(e)>0},Y.greaterThanOrEqualTo=Y.gte=function(e){var t=this.cmp(e);return t==1||t===0},Y.hyperbolicCosine=Y.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/go(4,e)).toString()):(e=16,t=`2.3283064365386962890625e-10`),a=ho(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 Qa(a,o.precision=n,o.rounding=r,!0)},Y.hyperbolicSine=Y.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=ho(a,2,i,i,!0);else{e=1.4*Math.sqrt(r),e=e>16?16:e|0,i=i.times(1/go(5,e)),i=ho(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,Qa(i,t,n,!0)},Y.hyperbolicTangent=Y.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,Za(n.sinh(),n.cosh(),r.precision=e,r.rounding=t)):new r(n.s)},Y.inverseCosine=Y.acos=function(){var e=this,t=e.constructor,n=e.abs().cmp(1),r=t.precision,i=t.rounding;return n===-1?e.isZero()?no(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()?no(t,r,i):new t(0):new t(NaN)},Y.inverseHyperbolicCosine=Y.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,ka=!1,n=n.times(n).minus(1).sqrt().plus(n),ka=!0,r.precision=e,r.rounding=t,n.ln()):new r(n)},Y.inverseHyperbolicSine=Y.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,ka=!1,n=n.times(n).plus(1).sqrt().plus(n),ka=!0,r.precision=e,r.rounding=t,n.ln())},Y.inverseHyperbolicTangent=Y.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?Qa(new a(i),e,t,!0):(a.precision=n=r-i.e,i=Za(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)},Y.inverseSine=Y.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=no(a,n+4,r).times(.5),e.s=i.s,e):new a(NaN))},Y.inverseTangent=Y.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<=Ga)return o=no(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<=Ga)return o=no(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/Ha+2|0),e=n;e;--e)l=l.div(l.times(l).plus(1).sqrt().plus(1));for(ka=!1,t=Math.ceil(s/Ha),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)),ka=!0,Qa(o,u.precision=d,u.rounding=f,!0)},Y.isFinite=function(){return!!this.d},Y.isInteger=Y.isInt=function(){return!!this.d&&Fa(this.e/Ha)>this.d.length-2},Y.isNaN=function(){return!this.s},Y.isNegative=Y.isNeg=function(){return this.s<0},Y.isPositive=Y.isPos=function(){return this.s>0},Y.isZero=function(){return!!this.d&&this.d[0]===0},Y.lessThan=Y.lt=function(e){return this.cmp(e)<0},Y.lessThanOrEqualTo=Y.lte=function(e){return this.cmp(e)<1},Y.logarithm=Y.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(ka=!1,s=d+p,o=lo(l,s),r=t?to(u,s+10):lo(e,s),c=Za(o,r,s,1),Ja(c.d,i=d,f))do if(s+=10,o=lo(l,s),r=t?to(u,s+10):lo(e,s),c=Za(o,r,s,1),!a){+Ka(c.d).slice(i+1,i+15)+1==0x5af3107a4000&&(c=Qa(c,d+1,0));break}while(Ja(c.d,i+=10,f));return ka=!0,Qa(c,d,f)},Y.minus=Y.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 ka?Qa(e,s,c):e}if(n=Fa(e.e/Ha),u=Fa(p.e/Ha),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/Ha),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]=Va-1;--l[i],l[r]+=Va}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=eo(l,n),ka?Qa(e,s,c):e):new m(c===3?-0:0)},Y.modulo=Y.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]?Qa(new r(n),r.precision,r.rounding):(ka=!1,r.modulo==9?(t=Za(n,e.abs(),0,3,1),t.s*=e.s):t=Za(n,e,0,r.modulo,1),t=t.times(e),ka=!0,n.minus(t))},Y.naturalExponential=Y.exp=function(){return co(this)},Y.naturalLogarithm=Y.ln=function(){return lo(this)},Y.negated=Y.neg=function(){var e=new this.constructor(this);return e.s=-e.s,Qa(e)},Y.plus=Y.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)),ka?Qa(e,s,c):e;if(a=Fa(d.e/Ha),r=Fa(e.e/Ha),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/Ha),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)/Va|0,l[i]%=Va;for(t&&(l.unshift(t),++r),o=l.length;l[--o]==0;)l.pop();return e.d=l,e.e=eo(l,r),ka?Qa(e,s,c):e},Y.precision=Y.sd=function(e){var t,n=this;if(e!==void 0&&e!==!!e&&e!==1&&e!==0)throw Error(ja+e);return n.d?(t=ro(n.d),e&&n.e+1>t&&(t=n.e+1)):t=NaN,t},Y.round=function(){var e=this,t=e.constructor;return Qa(new t(e),e.e+1,t.rounding)},Y.sine=Y.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())+Ha,r.rounding=1,n=mo(r,_o(r,n)),r.precision=e,r.rounding=t,Qa(Oa>2?n.neg():n,e,t,!0)):new r(NaN)},Y.squareRoot=Y.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(ka=!1,l=Math.sqrt(+o),l==0||l==1/0?(t=Ka(s),(t.length+c)%2==0&&(t+=`0`),l=Math.sqrt(t),c=Fa((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(Za(o,a,n+2,1)).times(.5),Ka(a.d).slice(0,n)===(t=Ka(r.d)).slice(0,n))if(t=t.slice(n-3,n+1),t==`9999`||!i&&t==`4999`){if(!i&&(Qa(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`)&&(Qa(r,c+1,1),e=!r.times(r).eq(o));break}return ka=!0,Qa(r,c,u.rounding,e)},Y.tangent=Y.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=Za(n,new r(1).minus(n.times(n)).sqrt(),e+10,0),r.precision=e,r.rounding=t,Qa(Oa==2||Oa==4?n.neg():n,e,t,!0)):new r(NaN)},Y.times=Y.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=Fa(u.e/Ha)+Fa(e.e/Ha),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%Va|0,t=s/Va|0;a[i]=(a[i]+t)%Va|0}for(;!a[--o];)a.pop();return t?++n:a.shift(),e.d=a,e.e=eo(a,n),ka?Qa(e,d.precision,d.rounding):e},Y.toBinary=function(e,t){return vo(this,2,e,t)},Y.toDecimalPlaces=Y.toDP=function(e,t){var n=this,r=n.constructor;return n=new r(n),e===void 0?n:(qa(e,0,Sa),t===void 0?t=r.rounding:qa(t,0,8),Qa(n,e+n.e+1,t))},Y.toExponential=function(e,t){var n,r=this,i=r.constructor;return e===void 0?n=$a(r,!0):(qa(e,0,Sa),t===void 0?t=i.rounding:qa(t,0,8),r=Qa(new i(r),e+1,t),n=$a(r,!0,e+1)),r.isNeg()&&!r.isZero()?`-`+n:n},Y.toFixed=function(e,t){var n,r,i=this,a=i.constructor;return e===void 0?n=$a(i):(qa(e,0,Sa),t===void 0?t=a.rounding:qa(t,0,8),r=Qa(new a(i),e+i.e+1,t),n=$a(r,!1,e+r.e+1)),i.isNeg()&&!i.isZero()?`-`+n:n},Y.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=ro(m)-p.e-1,o=a%Ha,t.d[0]=Ia(10,o<0?Ha+o:o),e==null)e=a>0?t:l;else{if(s=new h(e),!s.isInt()||s.lt(l))throw Error(ja+s);e=s.gt(t)?a>0?t:l:s}for(ka=!1,s=new h(Ka(m)),u=h.precision,h.precision=a=m.length*Ha*2;d=Za(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=Za(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=Za(l,r,a,1).minus(p).abs().cmp(Za(c,n,a,1).minus(p).abs())<1?[l,r]:[c,n],h.precision=u,ka=!0,f},Y.toHexadecimal=Y.toHex=function(e,t){return vo(this,16,e,t)},Y.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:qa(t,0,8),!n.d)return e.s?n:e;if(!e.d)return e.s&&=n.s,e}return e.d[0]?(ka=!1,n=Za(n,e,0,t,1).times(e),ka=!0,Qa(n)):(e.s=n.s,n=e),n},Y.toNumber=function(){return+this},Y.toOctal=function(e,t){return vo(this,8,e,t)},Y.toPower=Y.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(Ia(+s,l));if(s=new c(s),s.eq(1))return s;if(r=c.precision,a=c.rounding,e.eq(1))return Qa(s,r,a);if(t=Fa(e.e/Ha),t>=e.d.length-1&&(n=l<0?-l:l)<=Ua)return i=ao(c,s,n,r),e.s<0?new c(1).div(i):Qa(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=Ia(+s,l),t=n==0||!isFinite(n)?Fa(l*(Math.log(`0.`+Ka(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):(ka=!1,c.rounding=s.s=1,n=Math.min(12,(t+``).length),i=co(e.times(lo(s,r+n)),r),i.d&&(i=Qa(i,r+5,1),Ja(i.d,r,a)&&(t=r+10,i=Qa(co(e.times(lo(s,t+n)),t),t+5,1),+Ka(i.d).slice(r+1,r+15)+1==0x5af3107a4000&&(i=Qa(i,r+1,0)))),i.s=o,ka=!0,c.rounding=a,Qa(i,r,a))},Y.toPrecision=function(e,t){var n,r=this,i=r.constructor;return e===void 0?n=$a(r,r.e<=i.toExpNeg||r.e>=i.toExpPos):(qa(e,1,Sa),t===void 0?t=i.rounding:qa(t,0,8),r=Qa(new i(r),e,t),n=$a(r,e<=r.e||r.e<=i.toExpNeg,e)),r.isNeg()&&!r.isZero()?`-`+n:n},Y.toSignificantDigits=Y.toSD=function(e,t){var n=this,r=n.constructor;return e===void 0?(e=r.precision,t=r.rounding):(qa(e,1,Sa),t===void 0?t=r.rounding:qa(t,0,8)),Qa(new r(n),e,t)},Y.toString=function(){var e=this,t=e.constructor,n=$a(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()&&!e.isZero()?`-`+n:n},Y.truncated=Y.trunc=function(){return Qa(new this.constructor(this),this.e+1,1)},Y.valueOf=Y.toJSON=function(){var e=this,t=e.constructor,n=$a(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()?`-`+n:n};function Ka(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=Ha-r.length,n&&(a+=io(n)),a+=r;o=e[t],r=o+``,n=Ha-r.length,n&&(a+=io(n))}else if(o===0)return`0`;for(;o%10==0;)o/=10;return a+o}function qa(e,t,n){if(e!==~~e||e<t||e>n)throw Error(ja+e)}function Ja(e,t,n,r){var i,a,o,s;for(a=e[0];a>=10;a/=10)--t;return--t<0?(t+=Ha,i=0):(i=Math.ceil((t+1)/Ha),t%=Ha),a=Ia(10,Ha-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)==Ia(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)==Ia(10,t-3)-1,o}function Ya(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]+=Ca.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 Xa(e,t){var n,r,i;if(t.isZero())return t;r=t.d.length,r<32?(n=Math.ceil(r/3),i=(1/go(4,n)).toString()):(n=16,i=`2.3283064365386962890625e-10`),e.precision+=n,t=ho(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 Za=(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=Va,p=Ha,u=Fa(r.e/p)-Fa(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,Da=m;else{for(d=1,f=v[0];f>=10;f/=10)d++;_.e=d+u*p-1,Qa(_,s?a+_.e+1:a,o,m)}return _}})();function Qa(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+=Ha,o=t,u=d[f=0],c=u/Ia(10,i-o-1)%10|0;else if(f=Math.ceil((a+1)/Ha),s=d.length,f>=s)if(r){for(;s++<=f;)d.push(0);u=c=0,i=1,a%=Ha,o=a-Ha+1}else break out;else{for(u=s=d[f],i=1;s>=10;s/=10)i++;a%=Ha,o=a-Ha+i,c=o<0?0:u/Ia(10,i-o-1)%10|0}if(r=r||t<0||d[f+1]!==void 0||(o<0?u:u%Ia(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/Ia(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]=Ia(10,(Ha-t%Ha)%Ha),e.e=-t||0):d[0]=e.e=0,e;if(a==0?(d.length=f,s=1,f--):(d.length=f+1,s=Ia(10,Ha-a),d[f]=o>0?(u/Ia(10,i-o)%Ia(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]==Va&&(d[0]=1));break}else{if(d[f]+=s,d[f]!=Va)break;d[f--]=0,s=1}for(a=d.length;d[--a]===0;)d.pop()}return ka&&(e.e>p.maxE?(e.d=null,e.e=NaN):e.e<p.minE&&(e.e=0,e.d=[0])),e}function $a(e,t,n){if(!e.isFinite())return uo(e);var r,i=e.e,a=Ka(e.d),o=a.length;return t?(n&&(r=n-o)>0?a=a.charAt(0)+`.`+a.slice(1)+io(r):o>1&&(a=a.charAt(0)+`.`+a.slice(1)),a=a+(e.e<0?`e`:`e+`)+e.e):i<0?(a=`0.`+io(-i-1)+a,n&&(r=n-o)>0&&(a+=io(r))):i>=o?(a+=io(i+1-o),n&&(r=n-i-1)>0&&(a=a+`.`+io(r))):((r=i+1)<o&&(a=a.slice(0,r)+`.`+a.slice(r)),n&&(r=n-o)>0&&(i+1===o&&(a+=`.`),a+=io(r))),a}function eo(e,t){var n=e[0];for(t*=Ha;n>=10;n/=10)t++;return t}function to(e,t,n){if(t>Wa)throw ka=!0,n&&(e.precision=n),Error(Ma);return Qa(new e(wa),t,1,!0)}function no(e,t,n){if(t>Ga)throw Error(Ma);return Qa(new e(Ta),t,n,!0)}function ro(e){var t=e.length-1,n=t*Ha+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 io(e){for(var t=``;e--;)t+=`0`;return t}function ao(e,t,n,r){var i,a=new e(1),o=Math.ceil(r/Ha+4);for(ka=!1;;){if(n%2&&(a=a.times(t),yo(a.d,o)&&(i=!0)),n=Fa(n/2),n===0){n=a.d.length-1,i&&a.d[n]===0&&++a.d[n];break}t=t.times(t),yo(t.d,o)}return ka=!0,a}function oo(e){return e.d[e.d.length-1]&1}function so(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 co(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?(ka=!1,c=m):c=t,s=new f(.03125);e.e>-2;)e=e.times(s),d+=5;for(r=Math.log(Ia(2,d))/Math.LN10*2+5|0,c+=r,n=a=o=new f(1),f.precision=c;;){if(a=Qa(a.times(e),c,1),n=n.times(++u),s=o.plus(Za(a,n,c,1)),Ka(s.d).slice(0,c)===Ka(o.d).slice(0,c)){for(i=d;i--;)o=Qa(o.times(o),c,1);if(t==null)if(l<3&&Ja(o.d,c-r,p,l))f.precision=c+=10,n=a=s=new f(1),u=0,l++;else return Qa(o,f.precision=m,p,ka=!0);else return f.precision=m,o}o=s}}function lo(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?(ka=!1,u=y):u=t,_.precision=u+=m,n=Ka(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=Ka(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=to(_,u+2,y).times(a+``),h=lo(new _(r+`.`+n.slice(1)),u-m).plus(l),_.precision=y,t==null?Qa(h,y,v,ka=!0):h;for(d=h,c=o=h=Za(h.minus(1),h.plus(1),u,1),f=Qa(h.times(h),u,1),i=3;;){if(o=Qa(o.times(f),u,1),l=c.plus(Za(o,new _(i),u,1)),Ka(l.d).slice(0,u)===Ka(c.d).slice(0,u))if(c=c.times(2),a!==0&&(c=c.plus(to(_,u+2,y).times(a+``))),c=Za(c,new _(p),u,1),t==null)if(Ja(c.d,u-m,v,s))_.precision=u+=m,l=o=h=Za(d.minus(1),d.plus(1),u,1),f=Qa(h.times(h),u,1),i=s=1;else return Qa(c,_.precision=y,v,ka=!0);else return _.precision=y,c;c=l,i+=2}}function uo(e){return String(e.s*e.s/0)}function fo(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)%Ha,n<0&&(r+=Ha),r<i){for(r&&e.d.push(+t.slice(0,r)),i-=Ha;r<i;)e.d.push(+t.slice(r,r+=Ha));t=t.slice(r),r=Ha-t.length}else r-=i;for(;r--;)t+=`0`;e.d.push(+t),ka&&(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 po(e,t){var n,r,i,a,o,s,c,l,u;if(t.indexOf(`_`)>-1){if(t=t.replace(/(\d)_(?=\d)/g,`$1`),Ba.test(t))return fo(e,t)}else if(t===`Infinity`||t===`NaN`)return+t||(e.s=NaN),e.e=NaN,e.d=null,e;if(Ra.test(t))n=16,t=t.toLowerCase();else if(La.test(t))n=2;else if(za.test(t))n=8;else throw Error(ja+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=ao(r,new r(n),a,a*2)),l=Ya(t,n,Va),u=l.length-1,a=u;l[a]===0;--a)l.pop();return a<0?new r(e.s*0):(e.e=eo(l,u),e.d=l,ka=!1,o&&(e=Za(e,i,s*4)),c&&(e=e.times(Math.abs(c)<54?Ia(2,c):ss.pow(2,c))),ka=!0,e)}function mo(e,t){var n,r=t.d.length;if(r<3)return t.isZero()?t:ho(e,2,t,t);n=1.4*Math.sqrt(r),n=n>16?16:n|0,t=t.times(1/go(5,n)),t=ho(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 ho(e,t,n,r,i){var a,o,s,c,l=1,u=e.precision,d=Math.ceil(u/Ha);for(ka=!1,c=n.times(n),s=new e(r);;){if(o=Za(s.times(c),new e(t++*t++),u,1),s=i?r.plus(o):r.minus(o),r=Za(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 ka=!0,o.d.length=d+1,o}function go(e,t){for(var n=e;--t;)n*=e;return n}function _o(e,t){var n,r=t.s<0,i=no(e,e.precision,1),a=i.times(.5);if(t=t.abs(),t.lte(a))return Oa=r?4:1,t;if(n=t.divToInt(i),n.isZero())Oa=r?3:2;else{if(t=t.minus(n.times(i)),t.lte(a))return Oa=oo(n)?r?2:3:r?4:1,t;Oa=oo(n)?r?1:4:r?3:2}return t.minus(i).abs()}function vo(e,t,n,r){var i,a,o,s,c,l,u,d,f,p=e.constructor,m=n!==void 0;if(m?(qa(n,1,Sa),r===void 0?r=p.rounding:qa(r,0,8)):(n=p.precision,r=p.rounding),!e.isFinite())u=uo(e);else{for(u=$a(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=Ya($a(f),10,i),f.e=f.d.length),d=Ya(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=Za(e,f,n,r,0,i),d=e.d,a=e.e,l=Da),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+=Ca.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=Ya(u,i,t),c=d.length;!d[c-1];--c);for(o=1,u=`1.`;o<c;o++)u+=Ca.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 yo(e,t){if(e.length>t)return e.length=t,!0}function bo(e){return new this(e).abs()}function xo(e){return new this(e).acos()}function So(e){return new this(e).acosh()}function Co(e,t){return new this(e).plus(t)}function wo(e){return new this(e).asin()}function To(e){return new this(e).asinh()}function Eo(e){return new this(e).atan()}function Do(e){return new this(e).atanh()}function Oo(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=no(this,a,1).times(t.s>0?.25:.75),n.s=e.s):!t.d||e.isZero()?(n=t.s<0?no(this,r,i):new this(0),n.s=e.s):!e.d||t.isZero()?(n=no(this,a,1).times(.5),n.s=e.s):t.s<0?(this.precision=a,this.rounding=1,n=this.atan(Za(e,t,a,1)),t=no(this,a,1),this.precision=r,this.rounding=i,n=e.s<0?n.minus(t):n.plus(t)):n=this.atan(Za(e,t,a,1)),n}function ko(e){return new this(e).cbrt()}function Ao(e){return Qa(e=new this(e),e.e+1,2)}function jo(e,t,n){return new this(e).clamp(t,n)}function Mo(e){if(!e||typeof e!=`object`)throw Error(Aa+`Object expected`);var t,n,r,i=e.defaults===!0,a=[`precision`,1,Sa,`rounding`,0,8,`toExpNeg`,-xa,0,`toExpPos`,0,xa,`maxE`,0,xa,`minE`,-xa,0,`modulo`,0,9];for(t=0;t<a.length;t+=3)if(n=a[t],i&&(this[n]=Ea[n]),(r=e[n])!==void 0)if(Fa(r)===r&&r>=a[t+1]&&r<=a[t+2])this[n]=r;else throw Error(ja+n+`: `+r);if(n=`crypto`,i&&(this[n]=Ea[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(Na);else this[n]=!1;else throw Error(ja+n+`: `+r);return this}function No(e){return new this(e).cos()}function Po(e){return new this(e).cosh()}function Fo(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,Bo(e)){a.s=e.s,ka?!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++;ka?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 fo(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),Ba.test(e)?fo(a,e):po(a,e);if(r===`bigint`)return e<0?(e=-e,a.s=-1):a.s=1,fo(a,e.toString());throw Error(ja+e)}if(i.prototype=Y,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=Mo,i.clone=Fo,i.isDecimal=Bo,i.abs=bo,i.acos=xo,i.acosh=So,i.add=Co,i.asin=wo,i.asinh=To,i.atan=Eo,i.atanh=Do,i.atan2=Oo,i.cbrt=ko,i.ceil=Ao,i.clamp=jo,i.cos=No,i.cosh=Po,i.div=Io,i.exp=Lo,i.floor=Ro,i.hypot=zo,i.ln=Vo,i.log=Ho,i.log10=Wo,i.log2=Uo,i.max=Go,i.min=Ko,i.mod=qo,i.mul=Jo,i.pow=Yo,i.random=Xo,i.round=Zo,i.sign=Qo,i.sin=$o,i.sinh=es,i.sqrt=ts,i.sub=ns,i.sum=rs,i.tan=is,i.tanh=as,i.trunc=os,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 Io(e,t){return new this(e).div(t)}function Lo(e){return new this(e).exp()}function Ro(e){return Qa(e=new this(e),e.e+1,3)}function zo(){var e,t,n=new this(0);for(ka=!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 ka=!0,new this(1/0);n=t}return ka=!0,n.sqrt()}function Bo(e){return e instanceof ss||e&&e.toStringTag===Pa||!1}function Vo(e){return new this(e).ln()}function Ho(e,t){return new this(e).log(t)}function Uo(e){return new this(e).log(2)}function Wo(e){return new this(e).log(10)}function Go(){return so(this,arguments,-1)}function Ko(){return so(this,arguments,1)}function qo(e,t){return new this(e).mod(t)}function Jo(e,t){return new this(e).mul(t)}function Yo(e,t){return new this(e).pow(t)}function Xo(e){var t,n,r,i,a=0,o=new this(1),s=[];if(e===void 0?e=this.precision:qa(e,1,Sa),r=Math.ceil(e/Ha),!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(Na);for(r=s[--a],e%=Ha,r&&e&&(i=Ia(10,Ha-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-=Ha)s.shift();for(r=1,i=s[0];i>=10;i/=10)r++;r<Ha&&(n-=Ha-r)}return o.e=n,o.d=s,o}function Zo(e){return Qa(e=new this(e),e.e+1,this.rounding)}function Qo(e){return e=new this(e),e.d?e.d[0]?e.s:0*e.s:e.s||NaN}function $o(e){return new this(e).sin()}function es(e){return new this(e).sinh()}function ts(e){return new this(e).sqrt()}function ns(e,t){return new this(e).sub(t)}function rs(){var e=0,t=arguments,n=new this(t[e]);for(ka=!1;n.s&&++e<t.length;)n=n.plus(t[e]);return ka=!0,Qa(n,this.precision,this.rounding)}function is(e){return new this(e).tan()}function as(e){return new this(e).tanh()}function os(e){return Qa(e=new this(e),e.e+1,1)}Y[Symbol.for(`nodejs.util.inspect.custom`)]=Y.toString,Y[Symbol.toStringTag]=`Decimal`;var ss=Y.constructor=Fo(Ea);wa=new ss(wa),Ta=new ss(Ta);var cs=J(`BigNumber`,[`?on`,`config`],e=>{var{on:t,config:n}=e,r=ss.clone({precision:n.precision,modulo:ss.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}),ls=Math.cosh||function(e){return Math.abs(e)<1e-9?1-e:(Math.exp(e)+Math.exp(-e))*.5},us=Math.sinh||function(e){return Math.abs(e)<1e-9?e:(Math.exp(e)-Math.exp(-e))*.5},ds=e=>{let t=Math.sin(.5*e);return-2*t*t},fs=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))},ps=function(){throw SyntaxError(`Invalid Param`)};function ms(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 hs={re:0,im:0},gs=function(e,t){let n=hs;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 X.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 X.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]):ps();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&&ps();for(let e=0;e<t.length;e++){let a=t[e];a===` `||a===` `||a===`
|
|
3
3
|
`||(a===`+`?r++:a===`-`?i++:a===`i`||a===`I`?(r+i===0&&ps(),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))&&ps(),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&&ps();break;case`number`:n.im=0,n.re=e;break;default:ps()}return isNaN(n.re)||isNaN(n.im),n};function X(e,t){if(!(this instanceof X))return new X(e,t);let n=gs(e,t);this.re=n.re,this.im=n.im}X.prototype={re:0,im:0,sign:function(){let e=fs(this.re,this.im);return new X(this.re/e,this.im/e)},add:function(e,t){let n=gs(e,t),r=this.isInfinite(),i=!(isFinite(n.re)&&isFinite(n.im));return r||i?r&&i?X.NAN:X.INFINITY:new X(this.re+n.re,this.im+n.im)},sub:function(e,t){let n=gs(e,t),r=this.isInfinite(),i=!(isFinite(n.re)&&isFinite(n.im));return r||i?r&&i?X.NAN:X.INFINITY:new X(this.re-n.re,this.im-n.im)},mul:function(e,t){let n=gs(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?X.NAN:r||i?X.INFINITY:n.im===0&&this.im===0?new X(this.re*n.re,0):new X(this.re*n.re-this.im*n.im,this.re*n.im+this.im*n.re)},div:function(e,t){let n=gs(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 X.NAN;if(o||r)return X.INFINITY;if(a||i)return X.ZERO;if(n.im===0)return new X(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 X((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 X((this.re+this.im*e)/t,(this.im-this.re*e)/t)}},pow:function(e,t){let n=gs(e,t),r=this.re===0&&this.im===0;if(n.re===0&&n.im===0)return X.ONE;if(n.im===0){if(this.im===0&&this.re>0)return new X(this.re**+n.re,0);if(this.re===0)switch((n.re%4+4)%4){case 0:return new X(this.im**+n.re,0);case 1:return new X(0,this.im**+n.re);case 2:return new X(-(this.im**+n.re),0);case 3:return new X(0,-(this.im**+n.re))}}if(r&&n.re>0)return X.ZERO;let i=Math.atan2(this.im,this.re),a=ms(this.re,this.im),o=Math.exp(n.re*a-n.im*i),s=n.im*a+n.re*i;return new X(o*Math.cos(s),o*Math.sin(s))},sqrt:function(){let e=this.re,t=this.im;if(t===0)return e>=0?new X(Math.sqrt(e),0):new X(0,Math.sqrt(-e));let n=fs(e,t),r=Math.sqrt(.5*(n+Math.abs(e))),i=Math.abs(t)/(2*r);return e>=0?new X(r,t<0?-i:i):new X(i,t<0?-r:r)},exp:function(){let e=Math.exp(this.re);return this.im===0?new X(e,0):new X(e*Math.cos(this.im),e*Math.sin(this.im))},expm1:function(){let e=this.re,t=this.im;return new X(Math.expm1(e)*Math.cos(t)+ds(t),Math.exp(e)*Math.sin(t))},log:function(){let e=this.re,t=this.im;return t===0&&e>0?new X(Math.log(e),0):new X(ms(e,t),Math.atan2(t,e))},abs:function(){return fs(this.re,this.im)},arg:function(){return Math.atan2(this.im,this.re)},sin:function(){let e=this.re,t=this.im;return new X(Math.sin(e)*ls(t),Math.cos(e)*us(t))},cos:function(){let e=this.re,t=this.im;return new X(Math.cos(e)*ls(t),-Math.sin(e)*us(t))},tan:function(){let e=2*this.re,t=2*this.im,n=Math.cos(e)+ls(t);return new X(Math.sin(e)/n,us(t)/n)},cot:function(){let e=2*this.re,t=2*this.im,n=Math.cos(e)-ls(t);return new X(-Math.sin(e)/n,us(t)/n)},sec:function(){let e=this.re,t=this.im,n=.5*ls(2*t)+.5*Math.cos(2*e);return new X(Math.cos(e)*ls(t)/n,Math.sin(e)*us(t)/n)},csc:function(){let e=this.re,t=this.im,n=.5*ls(2*t)-.5*Math.cos(2*e);return new X(Math.sin(e)*ls(t)/n,-Math.cos(e)*us(t)/n)},asin:function(){let e=this.re,t=this.im,n=new X(t*t-e*e+1,-2*e*t).sqrt(),r=new X(n.re-t,n.im+e).log();return new X(r.im,-r.re)},acos:function(){let e=this.re,t=this.im,n=new X(t*t-e*e+1,-2*e*t).sqrt(),r=new X(n.re-t,n.im+e).log();return new X(Math.PI/2-r.im,r.re)},atan:function(){let e=this.re,t=this.im;if(e===0){if(t===1)return new X(0,1/0);if(t===-1)return new X(0,-1/0)}let n=e*e+(1-t)*(1-t),r=new X((1-t*t-e*e)/n,-2*e/n).log();return new X(-.5*r.im,.5*r.re)},acot:function(){let e=this.re,t=this.im;if(t===0)return new X(Math.atan2(1,e),0);let n=e*e+t*t;return n===0?new X(e===0?0:e/0,t===0?0:-t/0).atan():new X(e/n,-t/n).atan()},asec:function(){let e=this.re,t=this.im;if(e===0&&t===0)return new X(0,1/0);let n=e*e+t*t;return n===0?new X(e===0?0:e/0,t===0?0:-t/0).acos():new X(e/n,-t/n).acos()},acsc:function(){let e=this.re,t=this.im;if(e===0&&t===0)return new X(Math.PI/2,1/0);let n=e*e+t*t;return n===0?new X(e===0?0:e/0,t===0?0:-t/0).asin():new X(e/n,-t/n).asin()},sinh:function(){let e=this.re,t=this.im;return new X(us(e)*Math.cos(t),ls(e)*Math.sin(t))},cosh:function(){let e=this.re,t=this.im;return new X(ls(e)*Math.cos(t),us(e)*Math.sin(t))},tanh:function(){let e=2*this.re,t=2*this.im,n=ls(e)+Math.cos(t);return new X(us(e)/n,Math.sin(t)/n)},coth:function(){let e=2*this.re,t=2*this.im,n=ls(e)-Math.cos(t);return new X(us(e)/n,-Math.sin(t)/n)},csch:function(){let e=this.re,t=this.im,n=Math.cos(2*t)-ls(2*e);return new X(-2*us(e)*Math.cos(t)/n,2*ls(e)*Math.sin(t)/n)},sech:function(){let e=this.re,t=this.im,n=Math.cos(2*t)+ls(2*e);return new X(2*ls(e)*Math.cos(t)/n,-2*us(e)*Math.sin(t)/n)},asinh:function(){let e=this.re,t=this.im;if(t===0){if(e===0)return new X(0,0);let t=Math.abs(e),n=Math.log(t+Math.sqrt(t*t+1));return new X(e<0?-n:n,0)}let n=new X(e*e-t*t+1,2*e*t).sqrt();return new X(e+n.re,t+n.im).log()},acosh:function(){let e=this.re,t=this.im;if(t===0){if(e>1)return new X(Math.log(e+Math.sqrt(e-1)*Math.sqrt(e+1)),0);if(e<-1){let t=Math.sqrt(e*e-1);return new X(Math.log(-e+t),Math.PI)}return new X(0,Math.acos(e))}let n=new X(e-1,t).sqrt(),r=new X(e+1,t).sqrt();return new X(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 X(0,0);if(e===1)return new X(1/0,0);if(e===-1)return new X(-1/0,0);if(-1<e&&e<1)return new X(.5*Math.log((1+e)/(1-e)),0);if(e>1){let t=(e+1)/(e-1);return new X(.5*Math.log(t),-Math.PI/2)}let t=(1+e)/(1-e);return new X(.5*Math.log(-t),Math.PI/2)}let n=1-e,r=1+e,i=n*n+t*t;if(i===0)return new X(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 X(ms(a,o)/2,Math.atan2(o,a)/2)},acoth:function(){let e=this.re,t=this.im;if(e===0&&t===0)return new X(0,Math.PI/2);let n=e*e+t*t;return n===0?new X(e===0?0:e/0,t===0?0:-t/0).atanh():new X(e/n,-t/n).atanh()},acsch:function(){let e=this.re,t=this.im;if(t===0){if(e===0)return new X(1/0,0);let t=1/e;return new X(Math.log(t+Math.sqrt(t*t+1)),0)}let n=e*e+t*t;return n===0?new X(e===0?0:e/0,t===0?0:-t/0).asinh():new X(e/n,-t/n).asinh()},asech:function(){let e=this.re,t=this.im;if(this.isZero())return X.INFINITY;let n=e*e+t*t;return n===0?new X(e===0?0:e/0,t===0?0:-t/0).acosh():new X(e/n,-t/n).acosh()},inverse:function(){if(this.isZero())return X.INFINITY;if(this.isInfinite())return X.ZERO;let e=this.re,t=this.im,n=e*e+t*t;return new X(e/n,-t/n)},conjugate:function(){return new X(this.re,-this.im)},neg:function(){return new X(-this.re,-this.im)},ceil:function(e){return e=10**(e||0),new X(Math.ceil(this.re*e)/e,Math.ceil(this.im*e)/e)},floor:function(e){return e=10**(e||0),new X(Math.floor(this.re*e)/e,Math.floor(this.im*e)/e)},round:function(e){return e=10**(e||0),new X(Math.round(this.re*e)/e,Math.round(this.im*e)/e)},equals:function(e,t){let n=gs(e,t);return Math.abs(n.re-this.re)<=X.EPSILON&&Math.abs(n.im-this.im)<=X.EPSILON},clone:function(){return new X(this.re,this.im)},toString:function(){let e=this.re,t=this.im,n=``;return this.isNaN()?`NaN`:this.isInfinite()?`Infinity`:(Math.abs(e)<X.EPSILON&&(e=0),Math.abs(t)<X.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()}},X.ZERO=new X(0,0),X.ONE=new X(1,0),X.I=new X(0,1),X.PI=new X(Math.PI,0),X.E=new X(Math.E,0),X.INFINITY=new X(1/0,1/0),X.NAN=new X(NaN,NaN),X.EPSILON=1e-15;var _s=J(`Complex`,[],()=>(Object.defineProperty(X,`name`,{value:`Complex`}),X.prototype.constructor=X,X.prototype.type=`Complex`,X.prototype.isComplex=!0,X.prototype.toJSON=function(){return{mathjs:`Complex`,re:this.re,im:this.im}},X.prototype.toPolar=function(){return{r:this.abs(),phi:this.arg()}},X.prototype.format=function(e){var t=``,n=this.im,r=this.re,i=qi(this.re,e),a=qi(this.im,e),o=Dr(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},X.fromPolar=function(e){switch(arguments.length){case 1:var t=arguments[0];if(typeof t==`object`)return X(t);throw TypeError(`Input has to be an object with r and phi keys.`);case 2:var n=arguments[0],r=arguments[1];if(Dr(n)){if(Mr(r)&&r.hasBase(`ANGLE`)&&(r=r.toNumber(`rad`)),Dr(r))return new X({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`)}},X.prototype.valueOf=X.prototype.toString,X.fromJSON=function(e){return new X(e)},X.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},X),{isClass:!0});typeof BigInt>`u`&&(BigInt=function(e){if(isNaN(e))throw Error(``);return e});var vs=BigInt(0),ys=BigInt(1),bs=BigInt(2),xs=BigInt(3),Ss=BigInt(5),Cs=BigInt(10);BigInt(2**53-1);var ws=2e3,Ts={s:ys,n:vs,d:ys};function Es(e,t){try{e=BigInt(e)}catch{throw Rs()}return e*t}function Ds(e){return typeof e==`bigint`?e:Math.floor(e)}function Os(e,t){if(t===vs)throw Ls();let n=Object.create(Is.prototype);n.s=e<vs?-ys:ys,e=e<vs?-e:e;let r=Fs(e,t);return n.n=e/r,n.d=t/r,n}var ks=[bs*bs,bs,bs*bs,bs,bs*bs,bs*xs,bs,bs*xs];function As(e){let t=Object.create(null);if(e<=ys)return t[e]=ys,t;let n=e=>{t[e]=(t[e]||vs)+ys};for(;e%bs===vs;)n(bs),e/=bs;for(;e%xs===vs;)n(xs),e/=xs;for(;e%Ss===vs;)n(Ss),e/=Ss;for(let t=0,r=bs+Ss;r*r<=e;){for(;e%r===vs;)n(r),e/=r;r+=ks[t],t=t+1&7}return e>ys&&n(e),t}var js=function(e,t){let n=vs,r=ys,i=ys;if(e!=null)if(t!==void 0){if(typeof e==`bigint`)n=e;else if(isNaN(e))throw Rs();else if(e%1!=0)throw zs();else n=BigInt(e);if(typeof t==`bigint`)r=t;else if(isNaN(t))throw Rs();else if(t%1!=0)throw zs();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 Rs();i=n*r}else if(typeof e==`number`){if(isNaN(e))throw Rs();if(e<0&&(i=-ys,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=vs,o=vs,s=vs,c=ys,l=ys,u=e.replace(/_/g,``).match(/\d+|./g);if(u===null)throw Rs();if(u[t]===`-`?(i=-ys,t++):u[t]===`+`&&t++,u.length===t+1?o=Es(u[t++],i):u[t+1]===`.`||u[t]===`.`?(u[t]!==`.`&&(a=Es(u[t++],i)),t++,(t+1===u.length||u[t+1]===`(`&&u[t+3]===`)`||u[t+1]===`'`&&u[t+3]===`'`)&&(o=Es(u[t],i),c=Cs**BigInt(u[t].length),t++),(u[t]===`(`&&u[t+2]===`)`||u[t]===`'`&&u[t+2]===`'`)&&(s=Es(u[t+1],i),l=Cs**BigInt(u[t+1].length)-ys,t+=3)):u[t+1]===`/`||u[t+1]===`:`?(o=Es(u[t],i),c=Es(u[t+2],ys),t+=3):u[t+3]===`/`&&u[t+1]===` `&&(a=Es(u[t],i),o=Es(u[t+2],i),c=Es(u[t+4],ys),t+=5),u.length<=t)r=c*l,i=n=s+r*a+l*o;else throw Rs()}else if(typeof e==`bigint`)n=e,i=e,r=ys;else throw Rs();if(r===vs)throw Ls();Ts.s=i<vs?-ys:ys,Ts.n=n<vs?-n:n,Ts.d=r<vs?-r:r};function Ms(e,t,n){let r=ys;for(;t>vs;e=e*e%n,t>>=ys)t&ys&&(r=r*e%n);return r}function Ns(e,t){for(;t%bs===vs;t/=bs);for(;t%Ss===vs;t/=Ss);if(t===ys)return vs;let n=Cs%t,r=1;for(;n!==ys;r++)if(n=n*Cs%t,r>ws)return vs;return BigInt(r)}function Ps(e,t,n){let r=ys,i=Ms(Cs,n,t);for(let e=0;e<300;e++){if(r===i)return BigInt(e);r=r*Cs%t,i=i*Cs%t}return 0}function Fs(e,t){if(!e)return t;if(!t)return e;for(;;){if(e%=t,!e)return t;if(t%=e,!t)return e}}function Is(e,t){if(js(e,t),this instanceof Is)e=Fs(Ts.d,Ts.n),this.s=Ts.s,this.n=Ts.n/e,this.d=Ts.d/e;else return Os(Ts.s*Ts.n,Ts.d)}var Ls=function(){return Error(`Division by Zero`)},Rs=function(){return Error(`Invalid argument`)},zs=function(){return Error(`Parameters must be integer`)};Is.prototype={s:ys,n:vs,d:ys,abs:function(){return Os(this.n,this.d)},neg:function(){return Os(-this.s*this.n,this.d)},add:function(e,t){return js(e,t),Os(this.s*this.n*Ts.d+Ts.s*this.d*Ts.n,this.d*Ts.d)},sub:function(e,t){return js(e,t),Os(this.s*this.n*Ts.d-Ts.s*this.d*Ts.n,this.d*Ts.d)},mul:function(e,t){return js(e,t),Os(this.s*Ts.s*this.n*Ts.n,this.d*Ts.d)},div:function(e,t){return js(e,t),Os(this.s*Ts.s*this.n*Ts.d,this.d*Ts.n)},clone:function(){return Os(this.s*this.n,this.d)},mod:function(e,t){if(e===void 0)return Os(this.s*this.n%this.d,ys);if(js(e,t),vs===Ts.n*this.d)throw Ls();return Os(this.s*(Ts.d*this.n)%(Ts.n*this.d),Ts.d*this.d)},gcd:function(e,t){return js(e,t),Os(Fs(Ts.n,this.n)*Fs(Ts.d,this.d),Ts.d*this.d)},lcm:function(e,t){return js(e,t),Ts.n===vs&&this.n===vs?Os(vs,ys):Os(Ts.n*this.n,Fs(Ts.n,this.n)*Fs(Ts.d,this.d))},inverse:function(){return Os(this.s*this.d,this.n)},pow:function(e,t){if(js(e,t),Ts.d===ys)return Ts.s<vs?Os((this.s*this.d)**Ts.n,this.n**Ts.n):Os((this.s*this.n)**Ts.n,this.d**Ts.n);if(this.s<vs)return null;let n=As(this.n),r=As(this.d),i=ys,a=ys;for(let e in n)if(e!==`1`){if(e===`0`){i=vs;break}if(n[e]*=Ts.n,n[e]%Ts.d===vs)n[e]/=Ts.d;else return null;i*=BigInt(e)**n[e]}for(let e in r)if(e!==`1`){if(r[e]*=Ts.n,r[e]%Ts.d===vs)r[e]/=Ts.d;else return null;a*=BigInt(e)**r[e]}return Ts.s<vs?Os(a,i):Os(i,a)},log:function(e,t){if(js(e,t),this.s<=vs||Ts.s<=vs)return null;let n=Object.create(null),r=As(Ts.n),i=As(Ts.d),a=As(this.n),o=As(this.d);for(let e in i)r[e]=(r[e]||vs)-i[e];for(let e in o)a[e]=(a[e]||vs)-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]||vs,n=a[e]||vs;if(t===vs){if(n!==vs)return null;continue}let i=n,o=t,l=Fs(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?Os(s,c):null},equals:function(e,t){return js(e,t),this.s*this.n*Ts.d===Ts.s*Ts.n*this.d},lt:function(e,t){return js(e,t),this.s*this.n*Ts.d<Ts.s*Ts.n*this.d},lte:function(e,t){return js(e,t),this.s*this.n*Ts.d<=Ts.s*Ts.n*this.d},gt:function(e,t){return js(e,t),this.s*this.n*Ts.d>Ts.s*Ts.n*this.d},gte:function(e,t){return js(e,t),this.s*this.n*Ts.d>=Ts.s*Ts.n*this.d},compare:function(e,t){js(e,t);let n=this.s*this.n*Ts.d-Ts.s*Ts.n*this.d;return(vs<n)-(n<vs)},ceil:function(e){return e=Cs**BigInt(e||0),Os(Ds(this.s*e*this.n/this.d)+(e*this.n%this.d>vs&&this.s>=vs?ys:vs),e)},floor:function(e){return e=Cs**BigInt(e||0),Os(Ds(this.s*e*this.n/this.d)-(e*this.n%this.d>vs&&this.s<vs?ys:vs),e)},round:function(e){return e=Cs**BigInt(e||0),Os(Ds(this.s*e*this.n/this.d)+this.s*((this.s>=vs?ys:vs)+bs*(e*this.n%this.d)>this.d?ys:vs),e)},roundTo:function(e,t){js(e,t);let n=this.n*Ts.d,r=this.d*Ts.n,i=n%r,a=Ds(n/r);return i+i>=r&&a++,Os(this.s*a*Ts.n,Ts.d)},divisible:function(e,t){return js(e,t),Ts.n===vs?!1:this.n*Ts.d%(Ts.n*this.d)===vs},valueOf:function(){return Number(this.s*this.n)/Number(this.d)},toString:function(e=15){let t=this.n,n=this.d,r=Ns(t,n),i=Ps(t,n,r),a=this.s<vs?`-`:``;if(a+=Ds(t/n),t%=n,t*=Cs,t&&(a+=`.`),r){for(let e=i;e--;)a+=Ds(t/n),t%=n,t*=Cs;a+=`(`;for(let e=r;e--;)a+=Ds(t/n),t%=n,t*=Cs;a+=`)`}else for(let r=e;t&&r--;)a+=Ds(t/n),t%=n,t*=Cs;return a},toFraction:function(e=!1){let t=this.n,n=this.d,r=this.s<vs?`-`:``;if(n===ys)r+=t;else{let i=Ds(t/n);e&&i>vs&&(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<vs?`-`:``;if(n===ys)r+=t;else{let i=Ds(t/n);e&&i>vs&&(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(Ds(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=Os(r[e-1],ys);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 Bs=J(`Fraction`,[],()=>(Object.defineProperty(Is,`name`,{value:`Fraction`}),Is.prototype.constructor=Is,Is.prototype.type=`Fraction`,Is.prototype.isFraction=!0,Is.prototype.toJSON=function(){return{mathjs:`Fraction`,n:String(this.s*this.n),d:String(this.d)}},Is.fromJSON=function(e){return new Is(e)},Is),{isClass:!0}),Vs=J(`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(Or(t))t=t.toNumber();else if(typeof t!=`number`&&!kr(t))throw TypeError(`Parameter start must be a number or bigint`)}if(a){if(Or(n))n=n.toNumber();else if(typeof n!=`number`&&!kr(n))throw TypeError(`Parameter end must be a number or bigint`)}if(o){if(Or(r))r=r.toNumber();else if(typeof r!=`number`&&!kr(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&&ra(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 Bi(n)===Bi(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=qi(this.start,e);return this.step!==1&&(t+=`:`+qi(this.step,e)),t+=`:`+qi(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}),Hs=J(`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 Us(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(!Ri(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 Ws(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}=Ji(t);switch(n){case`fixed`:return qs(e,r);case`exponential`:return Ks(e,r);case`engineering`:return Gs(e,r);case`bin`:return Us(e,2,i);case`oct`:return Us(e,8,i);case`hex`:return Us(e,16,i);case`auto`:var a=Js(t?.lowerExp,-3),o=Js(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():Ks(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 Gs(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 Ks(e,t){return t===void 0?e.toExponential():e.toExponential(t-1)}function qs(e,t){return e.toFixed(t)}function Js(e,t){return Dr(e)?e:Or(e)?e.toNumber():t}function Ys(e,t){var n=e.length-t.length,r=e.length;return e.substring(n,r)===t}function Xs(e,t){var n=Zs(e,t);return t&&typeof t==`object`&&`truncate`in t&&n.length>t.truncate?n.substring(0,t.truncate-3)+`...`:n}function Zs(e,t){return typeof e==`number`?qi(e,t):Or(e)?Ws(e,t):nc(e)?!t||t.fraction!==`decimal`?`${e.s*e.n}/${e.d}`:e.toString():Array.isArray(e)?tc(e,t):Nr(e)?Qs(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=>Qs(n)+`: `+Xs(e[n],t)).join(`, `)+`}`:String(e)}function Qs(e){for(var t=String(e),n=``,r=0;r<t.length;){var i=t.charAt(r);n+=i in $s?$s[i]:i,r++}return`"`+n+`"`}var $s={'"':`\\"`,"\\":`\\\\`,"\b":`\\b`,"\f":`\\f`,"\n":`\\n`,"\r":`\\r`," ":`\\t`};function ec(e){var t=String(e);return t=t.replace(/&/g,`&`).replace(/"/g,`"`).replace(/'/g,`'`).replace(/</g,`<`).replace(/>/g,`>`),t}function tc(e,t){if(Array.isArray(e)){for(var n=`[`,r=e.length,i=0;i<r;i++)i!==0&&(n+=`, `),n+=tc(e[i],t);return n+=`]`,n}else return Xs(e,t)}function nc(e){return e&&typeof e==`object`&&typeof e.s==`bigint`&&typeof e.n==`bigint`&&typeof e.d==`bigint`||!1}function rc(e,t){if(!Nr(e))throw TypeError(`Unexpected type of argument in function compareText (expected: string or Array or Matrix, actual: `+_i(e)+`, index: 0)`);if(!Nr(t))throw TypeError(`Unexpected type of argument in function compareText (expected: string or Array or Matrix, actual: `+_i(t)+`, index: 1)`);return e===t?0:e>t?1:-1}function ic(e,t,n){if(!(this instanceof ic))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}ic.prototype=RangeError(),ic.prototype.constructor=RangeError,ic.prototype.name=`DimensionError`,ic.prototype.isDimensionError=!0;function ac(e,t,n){if(!(this instanceof ac))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}ac.prototype=RangeError(),ac.prototype.constructor=RangeError,ac.prototype.name=`IndexError`,ac.prototype.isIndexError=!0;function oc(e){for(var t=[];Array.isArray(e);)t.push(e.length),e=e[0];return t}function sc(e,t,n){var r,i=e.length;if(i!==t[n])throw new ic(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 ic(t.length-1,t.length,`<`);sc(e[r],t,a)}}else for(r=0;r<i;r++)if(Array.isArray(e[r]))throw new ic(t.length+1,t.length,`>`)}function cc(e,t){if(t.length===0){if(Array.isArray(e))throw new ic(e.length,0)}else sc(e,t,0)}function lc(e,t){var n=e.isMatrix?e._size:oc(e);t._sourceSize.forEach((e,t)=>{if(e!==null&&e!==n[t])throw new ic(e,n[t])})}function uc(e,t){if(e!==void 0){if(!Dr(e)||!Ri(e))throw TypeError(`Index must be an integer (value: `+e+`)`);if(e<0||typeof t==`number`&&e>=t)throw new ac(e,t)}}function dc(e){for(var t=0;t<e._dimensions.length;++t){var n=e._dimensions[t];if(n._data&&Pr(n._data)){if(n._size[0]===0)return!0}else if(n.isRange){if(n.start===n.end)return!0}else if(Nr(n)&&n.length===0)return!0}return!1}function fc(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(!Dr(e)||!Ri(e)||e<0)throw TypeError(`Invalid size, must contain positive integers (size: `+Xs(t)+`)`)}),(Dr(e)||Or(e))&&(e=[e]),pc(e,t,0,n===void 0?0:n),e}function pc(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),pc(a,t,l,r);for(i=c;i<s;i++)a=[],e[i]=a,pc(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 mc(e,t){var n=Sc(e,!0),r=n.length;if(!Array.isArray(e)||!Array.isArray(t))throw TypeError(`Array expected`);if(t.length===0)throw new ic(0,r,`!=`);t=hc(t,r);var i=gc(t);if(r!==i)throw new ic(i,r,`!=`);try{return _c(n,t)}catch(e){throw e instanceof ic?new ic(i,r,`!=`):e}}function hc(e,t){var n=gc(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 gc(e){return e.reduce((e,t)=>e*t,1)}function _c(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 vc(e,t){for(var n=t||oc(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=yc(e,r,0),n.length=r),e}function yc(e,t,n){var r,i;if(n<t){var a=n+1;for(r=0,i=e.length;r<i;r++)e[r]=yc(e[r],t,a)}else for(;Array.isArray(e);)e=e[0];return e}function bc(e,t,n,r){var i=r||oc(e);if(n)for(var a=0;a<n;a++)e=[e],i.unshift(1);for(e=xc(e,t,0);i.length<t;)i.push(1);return e}function xc(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]=xc(e[r],t,a)}else for(var o=n;o<t;o++)e=[e];return e}function Sc(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 Cc(e,t){return Array.prototype.map.call(e,t)}function wc(e,t){Array.prototype.forEach.call(e,t)}function Tc(e,t){if(oc(e).length!==1)throw Error(`Only one dimensional matrices supported`);return Array.prototype.filter.call(e,t)}function Ec(e,t){if(oc(e).length!==1)throw Error(`Only one dimensional matrices supported`);return Array.prototype.filter.call(e,e=>t.test(e))}function Dc(e,t){return Array.prototype.join.call(e,t)}function Oc(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 kc(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 Ac(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?Ac(a,t):t(a);if(n===void 0)n=s;else if(n!==s)return`mixed`}return n}function jc(e,t,n,r){if(r<n){if(e.length!==t.length)throw new ic(e.length,t.length);for(var i=[],a=0;a<e.length;a++)i[a]=jc(e[a],t[a],n,r+1);return i}else return e.concat(t)}function Mc(){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 jc(e,n,t,0)},e[0]);throw Error(`Wrong number of arguments in function concat`)}function Nc(){for(var e=[...arguments],t=e.map(e=>e.length),n=Math.max(...t),r=Array(n).fill(null),i=0;i<e.length;i++)for(var a=e[i],o=t[i],s=0;s<o;s++){var c=n-o+s;a[s]>r[c]&&(r[c]=a[s])}for(var l=0;l<e.length;l++)Pc(e[l],r);return r}function Pc(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 Fc(e,t){var n=oc(e);if(Si(n,t))return e;Pc(n,t);var r=Nc(n,t),i=r.length,a=[...Array(i-n.length).fill(1),...n],o=Bc(e);n.length<i&&(o=mc(o,a),n=oc(o));for(var s=0;s<i;s++)n[s]<r[s]&&(o=Ic(o,r[s],s),n=oc(o));return o}function Ic(e,t,n){return Mc(...Array(t).fill(e),n)}function Lc(e,t){if(!Array.isArray(e))throw Error(`Array expected`);if(!Array.isArray(t))throw Error(`Array expected for index`);var n=oc(e);if(t.length!==n.length)throw new ic(t.length,n.length);for(var r=0;r<t.length;r++)uc(t[r],n[r]);return t.reduce((e,t)=>e[t],e)}function Rc(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 zc(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 Bc(e){return ur([],e)}function Vc(e,t,n,r){if(pa.default.isTypedFunction(e)){var i;if(r)i=1;else{var a=t.isMatrix?t.size():oc(t);if(!a.length||a[a.length-1]===0)return{isUnary:r,fn:e};var o=a.map(()=>0);i=Wc(e,t.isMatrix?t.get(o):Lc(t,o),o,t)}var s;if(t.isMatrix&&t.dataType!==`mixed`&&t.dataType!==void 0){var c=Hc(e,i);s=c===void 0?e:c}else s=e;return i>=1&&i<=3?{isUnary:i===1,fn:function(){return Gc(s,[...arguments].slice(0,i),n,e.name)}}:{isUnary:!1,fn:function(){return Gc(s,[...arguments],n,e.name)}}}return r===void 0?{isUnary:Uc(e),fn:e}:{isUnary:r,fn:e}}function Hc(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 Uc(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 Wc(e,t,n,r){for(var i=[t,n,r],a=3;a>0;a--){var o=i.slice(0,a);if(pa.default.resolve(e,o)!==null)return a}}function Gc(e,t,n,r){try{return e(...t)}catch(e){Kc(e,t,n,r)}}function Kc(e,t,n,r){if(e instanceof TypeError&&e.data?.category===`wrongType`){var i=[];throw i.push(`value: ${_i(t[0])}`),t.length>=2&&i.push(`index: ${_i(t[1])}`),t.length>=3&&i.push(`array: ${_i(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 qc=J(`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&&!Nr(t))throw Error(`Invalid datatype: `+t);if(Fr(e))e.type===`DenseMatrix`?(this._data=vi(e._data),this._size=vi(e._size),this._datatype=t||e._datatype):(this._data=e.toArray(),this._size=e.size(),this._datatype=t||e._datatype);else if(e&&Pr(e.data)&&Pr(e.size))this._data=e.data,this._size=e.size,cc(this._data,this._size),this._datatype=t||e.datatype;else if(Pr(e))this._data=u(e),this._size=oc(this._data),cc(this._data,this._size),this._datatype=t;else if(e)throw TypeError(`Unsupported type of data (`+_i(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 Ac(this._data,_i)},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 Lc(this._data,e)},r.prototype.set=function(e,t,n){if(!Pr(e))throw TypeError(`Array expected`);if(e.length<this._size.length)throw new ic(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],uc(a,s.length),s=s[a];return a=e[e.length-1],uc(a,s.length),s[a]=t,this};function i(e,t){if(!Br(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 ic(i.length,e._size.length);for(var o=t.min(),s=t.max(),c=0,l=e._size.length;c<l;c++)uc(o[c],e._size[c]),uc(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 Dr(e)?t(e):e.map(t).valueOf()}return Dr(o)?r[a]=null:r[a]=o.size()[0],a<n?s(o,t=>(uc(t,e.length),i(e[t],a+1))):s(o,t=>(uc(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(Fr(n)?(o=n.size(),n=n.valueOf()):o=oc(n),a){if(o.length!==0)throw TypeError(`Scalar expected`);e.set(t.min(),n,r)}else{if(!Si(o,i)){if(o.length===0)n=Fc([n],i);else try{n=Fc(n,i)}catch{}o=oc(n)}if(i.length<e._size.length)throw new ic(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=bc(n,i.length,u,o)}if(!Si(i,o))throw new ic(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)=>{uc(t,e.length),i(e[t],n[r[0]],a+1)},c=(t,r)=>{uc(t,e.length),e[t]=n[r[0]]};a<r?Dr(o)?s(o,[0]):o.forEach(s):Dr(o)?c(o,[0]):o.forEach(c)}}r.prototype.resize=function(e,t,n){if(!Ir(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;Pr(r);)r=r[0];return r}return e._size=t.slice(0),e._data=fc(e._data,e._size,n),e}r.prototype.reshape=function(e,t){var n=t?this.clone():this;return n._data=mc(n._data,e),n._size=hc(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:vi(this._data),size:vi(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=Vc(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=Vc(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 vi(this._data)},r.prototype.valueOf=function(){return this._data},r.prototype.format=function(e){return Xs(this._data,e)},r.prototype.toString=function(){return Xs(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(Or(e)&&(e=e.toNumber()),!Dr(e)||!Ri(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(!Pr(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(Or(e)&&(e=e.toNumber()),!Dr(e)||!Ri(e)||e<1)throw Error(`Size values must be positive integers`);return e}),n){if(Or(n)&&(n=n.toNumber()),!Dr(n)||!Ri(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(Pr(t)){if(t.length!==l)throw Error(`Invalid value array length`);u=function(e){return t[e]}}else if(Fr(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||=Or(u(0))?u(0).mul(0):0;var f=[];if(e.length>0){f=fc(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(!Dr(e)||!Ri(e)||!Dr(t)||!Ri(t))throw Error(`Row index must be positive integers`);if(this._size.length!==2)throw Error(`Only two dimensional matrix is supported`);return uc(e,this._size[0]),uc(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 Fr(e)?u(e.valueOf()):Pr(e)?e.map(u):e}return r},{isClass:!0}),Jc=`clone`,Yc=J(Jc,[`typed`],e=>{var{typed:t}=e;return t(Jc,{any:vi})});function Xc(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 Zc(e){for(var t=0;t<e.length;t++)if(Ir(e[t]))return!0;return!1}function Qc(e,t){Fr(e)?e.forEach(e=>t(e),!1,!0):zc(e,t,!0)}function $c(e,t,n){if(!n)return Fr(e)?e.map(e=>t(e),!1,!0):Rc(e,t,!0);var r=e=>e===0?e:t(e);return Fr(e)?e.map(e=>r(e),!1,!0):Rc(e,r,!0)}function el(e,t,n){var r=Array.isArray(e)?oc(e):e.size();if(t<0||t>=r.length)throw new ac(t,r.length);return Fr(e)?e.create(tl(e.valueOf(),t,n),e.datatype()):tl(e,t,n)}function tl(e,t,n){var r,i,a,o;if(t<=0)if(Array.isArray(e[0])){for(o=Xc(e),i=[],r=0;r<o.length;r++)i[r]=tl(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]=tl(e[r],t-1,n);return i}}function nl(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 rl=`isInteger`,il=J(rl,[`typed`,`equal`],e=>{var{typed:t,equal:n}=e;return t(rl,{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=>$c(t,e))})}),al=`number`,ol=`number, number`;function sl(e){return Math.abs(e)}sl.signature=al;function cl(e,t){return e+t}cl.signature=ol;function ll(e,t){return e-t}ll.signature=ol;function ul(e,t){return e*t}ul.signature=ol;function dl(e,t){return e/t}dl.signature=ol;function fl(e){return-e}fl.signature=al;function pl(e){return e}pl.signature=al;function ml(e){return Wi(e)}ml.signature=al;function hl(e){return e*e*e}hl.signature=al;function gl(e){return Math.exp(e)}gl.signature=al;function _l(e){return Gi(e)}_l.signature=al;function vl(e,t){if(!Ri(e)||!Ri(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}vl.signature=ol;function yl(e,t){if(!Ri(e)||!Ri(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)}yl.signature=ol;function bl(e,t){return t?Math.log(e)/Math.log(t):Math.log(e)}function xl(e){return Hi(e)}xl.signature=al;function Sl(e){return Vi(e)}Sl.signature=al;function Cl(e){return Ui(e)}Cl.signature=al;function wl(e,t){return t===0?e:e-t*Math.floor(e/t)}wl.signature=ol;function Tl(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 El(e){return Bi(e)}El.signature=al;function Dl(e){return Math.sqrt(e)}Dl.signature=al;function Ol(e){return e*e}Ol.signature=al;function kl(e,t){var n,r,i,a=0,o=1,s=1,c=0;if(!Ri(e)||!Ri(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]}kl.signature=ol;function Al(e,t){return e*e<1&&t===1/0||e*e>1&&t===-1/0?0:e**+t}Al.signature=ol;function jl(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0;if(!Ri(t)||t<0||t>15)throw Error(`Number of decimals in function round must be an integer from 0 to 15 inclusive`);return parseFloat(Zi(e,t))}function Ml(e){return Math.abs(e)}Ml.signature=al;var Nl=`number`,Pl=`number, number`;function Fl(e,t){if(!Ri(e)||!Ri(t))throw Error(`Integers expected in function bitAnd`);return e&t}Fl.signature=Pl;function Il(e){if(!Ri(e))throw Error(`Integer expected in function bitNot`);return~e}Il.signature=Nl;function Ll(e,t){if(!Ri(e)||!Ri(t))throw Error(`Integers expected in function bitOr`);return e|t}Ll.signature=Pl;function Rl(e,t){if(!Ri(e)||!Ri(t))throw Error(`Integers expected in function bitXor`);return e^t}Rl.signature=Pl;function zl(e,t){if(!Ri(e)||!Ri(t))throw Error(`Integers expected in function leftShift`);return e<<t}zl.signature=Pl;function Bl(e,t){if(!Ri(e)||!Ri(t))throw Error(`Integers expected in function rightArithShift`);return e>>t}Bl.signature=Pl;function Vl(e,t){if(!Ri(e)||!Ri(t))throw Error(`Integers expected in function rightLogShift`);return e>>>t}Vl.signature=Pl;function Hl(e,t){if(t<e)return 1;if(t===e)return t;var n=t+e>>1;return Hl(e,n)*Hl(n+1,t)}function Ul(e,t){if(!Ri(e)||e<0||!Ri(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/=Hl(a,o)),r}Ul.signature=`number, number`;var Wl=Math.PI,Gl=2*Math.PI,Kl=Math.E,ql=1.618033988749895,Jl=`number`,Yl=`number, number`;function Xl(e){return!e}Xl.signature=Jl;function Zl(e,t){return!!(e||t)}Zl.signature=Yl;function Ql(e,t){return!!e!=!!t}Ql.signature=Yl;function $l(e,t){return!!(e&&t)}$l.signature=Yl;function eu(e){var t;if(Ri(e))return e<=0?Number.isFinite(e)?1/0:NaN:e>171?1/0:Hl(1,e-1);if(e<.5)return Math.PI/(Math.sin(Math.PI*e)*eu(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=nu[0];for(var o=1;o<nu.length;++o)t+=nu[o]/(e+o);var s=e+tu+.5;return Math.sqrt(2*Math.PI)*s**+(e+.5)*Math.exp(-s)*t}eu.signature=`number`;var tu=4.7421875,nu=[.9999999999999971,57.15623566586292,-59.59796035547549,14.136097974741746,-.4919138160976202,3399464998481189e-20,4652362892704858e-20,-9837447530487956e-20,.0001580887032249125,-.00021026444172410488,.00021743961811521265,-.0001643181065367639,8441822398385275e-20,-26190838401581408e-21,36899182659531625e-22],ru=.9189385332046728,iu=[1.000000000190015,76.18009172947146,-86.50532032941678,24.01409824083091,-1.231739572450155,.001208650973866179,-5395239384953e-18];function au(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))-au(1-e);--e;for(var t=e+5+.5,n=iu[0],r=6;r>=1;r--)n+=iu[r]/(e+r);return ru+(e+.5)*Math.log(t)-t+Math.log(n)}au.signature=`number`;var ou=`number`,su=`number, number`;function cu(e){return Math.acos(e)}cu.signature=ou;function lu(e){return ia(e)}lu.signature=ou;function uu(e){return Math.atan(1/e)}uu.signature=ou;function du(e){return Number.isFinite(e)?(Math.log((e+1)/e)+Math.log(e/(e-1)))/2:0}du.signature=ou;function fu(e){return Math.asin(1/e)}fu.signature=ou;function pu(e){var t=1/e;return Math.log(t+Math.sqrt(t*t+1))}pu.signature=ou;function mu(e){return Math.acos(1/e)}mu.signature=ou;function hu(e){var t=1/e,n=Math.sqrt(t*t-1);return Math.log(n+t)}hu.signature=ou;function gu(e){return Math.asin(e)}gu.signature=ou;function _u(e){return aa(e)}_u.signature=ou;function vu(e){return Math.atan(e)}vu.signature=ou;function yu(e,t){return Math.atan2(e,t)}yu.signature=su;function bu(e){return oa(e)}bu.signature=ou;function xu(e){return Math.cos(e)}xu.signature=ou;function Su(e){return sa(e)}Su.signature=ou;function Cu(e){return 1/Math.tan(e)}Cu.signature=ou;function wu(e){var t=Math.exp(2*e);return(t+1)/(t-1)}wu.signature=ou;function Tu(e){return 1/Math.sin(e)}Tu.signature=ou;function Eu(e){return e===0?1/0:Math.abs(2/(Math.exp(e)-Math.exp(-e)))*Bi(e)}Eu.signature=ou;function Du(e){return 1/Math.cos(e)}Du.signature=ou;function Ou(e){return 2/(Math.exp(e)+Math.exp(-e))}Ou.signature=ou;function ku(e){return Math.sin(e)}ku.signature=ou;function Au(e){return ca(e)}Au.signature=ou;function ju(e){return Math.tan(e)}ju.signature=ou;function Mu(e){return la(e)}Mu.signature=ou;var Nu=`number`;function Pu(e){return Ri(e)}Pu.signature=Nu;function Fu(e){return e<0}Fu.signature=Nu;function Iu(e){return e>0}Iu.signature=Nu;function Lu(e){return e===0}Lu.signature=Nu;function Ru(e){return Number.isNaN(e)}Ru.signature=Nu;function zu(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 Bu=`isNegative`,Vu=J(Bu,[`typed`,`config`],e=>{var{typed:t,config:n}=e;return t(Bu,{number:e=>ra(e,0,n.relTol,n.absTol)?!1:Fu(e),BigNumber:e=>zu(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=>$c(t,e))})}),Hu=`isNumeric`,Uu=J(Hu,[`typed`],e=>{var{typed:t}=e;return t(Hu,{"number | BigNumber | bigint | Fraction | boolean":()=>!0,"Complex | Unit | string | null | undefined | Node":()=>!1,"Array | Matrix":t.referToSelf(e=>t=>$c(t,e))})}),Wu=`hasNumericValue`,Gu=J(Wu,[`typed`,`isNumeric`],e=>{var{typed:t,isNumeric:n}=e;return t(Wu,{boolean:()=>!0,string:function(e){return e.trim().length>0&&!isNaN(Number(e))},any:function(e){return n(e)}})}),Ku=`isPositive`,qu=J(Ku,[`typed`,`config`],e=>{var{typed:t,config:n}=e;return t(Ku,{number:e=>ra(e,0,n.relTol,n.absTol)?!1:Iu(e),BigNumber:e=>zu(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=>$c(t,e))})}),Ju=`isZero`,Yu=J(Ju,[`typed`,`equalScalar`],e=>{var{typed:t,equalScalar:n}=e;return t(Ju,{"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=>$c(t,e))})}),Xu=`isNaN`,Zu=J(Xu,[`typed`],e=>{var{typed:t}=e;return t(Xu,{number:Ru,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=>$c(t,e))})}),Qu=`isBounded`,$u=J(Qu,[`typed`],e=>{var{typed:t}=e;return t(Qu,{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))))})}),ed=`isFinite`,td=J(ed,[`typed`,`isBounded`,`map`],e=>{var{typed:t,isBounded:n,map:r}=e;return t(ed,{"Array | Matrix":e=>r(e,n),any:e=>n(e)})}),nd=`typeOf`,rd=J(nd,[`typed`],e=>{var{typed:t}=e;return t(nd,{any:_i})});function id(e,t,n,r){return ra(e.re,t.re,n,r)&&ra(e.im,t.im,n,r)}var ad=J(`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)})}}),od=`equalScalar`,sd=J(od,[`typed`,`config`],e=>{var{typed:t,config:n}=e;return t(od,{"boolean, boolean":function(e,t){return e===t},"number, number":function(e,t){return ra(e,t,n.relTol,n.absTol)},"BigNumber, BigNumber":function(e,t){return e.eq(t)||zu(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 id(e,t,n.relTol,n.absTol)}},ad({typed:t}))});J(od,[`typed`,`config`],e=>{var{typed:t,config:n}=e;return t(od,{"number, number":function(e,t){return ra(e,t,n.relTol,n.absTol)}})});var cd=J(`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&&!Nr(t))throw Error(`Invalid datatype: `+t);if(Fr(e))a(this,e,t);else if(e&&Pr(e.index)&&Pr(e.ptr)&&Pr(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(Pr(e))o(this,e,t);else if(e)throw TypeError(`Unsupported type of data (`+_i(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?vi(t._values):void 0,e._index=vi(t._index),e._ptr=vi(t._ptr),e._size=vi(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(Nr(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(Pr(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 Ac(this._values,_i)},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(!Br(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 ic(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++)uc(c[r],e._size[r]),uc(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(Fr(n)?(o=n.size(),n=n.toArray()):o=oc(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 ic(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=bc(n,i.length,c,o)}if(!Si(i,o))throw new ic(i,o,`>`);if(i.length===1)d(t.dimension(0),(t,i)=>{uc(t),e.set([t,0],n[i[0]],r)});else{var l=t.dimension(0),u=t.dimension(1);d(l,(t,i)=>{uc(t),d(u,(a,o)=>{uc(a),e.set([t,a],n[i[0]][o[0]],r)})})}}return e;function d(e,t){Dr(e)?t(e,[0]):e.forEach(t)}}i.prototype.get=function(e){if(!Pr(e))throw TypeError(`Array expected`);if(e.length!==this._size.length)throw new ic(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];uc(t,this._size[0]),uc(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(!Pr(e))throw TypeError(`Array expected`);if(e.length!==this._size.length)throw new ic(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;Nr(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]),uc(a,s),uc(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(!Ir(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(!Dr(e)||!Ri(e)||e<0)throw TypeError(`Invalid size, must contain positive integers (size: `+Xs(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;Nr(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(!Pr(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(!Dr(t)||!Ri(t)||t<=-2||t===0)throw TypeError(`Invalid size, must contain positive integers or -1 (size: `+Xs(e)+`)`)});var n=this._size[0]*this._size[1];if(e=hc(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?vi(this._values):void 0,index:vi(this._index),ptr:vi(this._ptr),size:vi(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=Vc(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;Nr(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=Vc(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?vi(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 [`+Xs(t,e)+` x `+Xs(n,e)+`] density: `+Xs(r,e)+`
|
|
4
4
|
`,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+=`
|
|
5
5
|
(`+Xs(l,e)+`, `+Xs(a,e)+`) ==> `+(this._values?Xs(this._values[c],e):`X`)}return i},i.prototype.toString=function(){return Xs(this.toArray())},i.prototype.toJSON=function(){return{mathjs:`SparseMatrix`,values:this._values,index:this._index,ptr:this._ptr,size:this._size,datatype:this._datatype}},i.prototype.diagonal=function(e){if(e){if(Or(e)&&(e=e.toNumber()),!Dr(e)||!Ri(e))throw TypeError(`The parameter k must be an integer number`)}else e=0;var t=e>0?e:0,n=e<0?-e:0,r=this._size[0],a=this._size[1],o=Math.min(r-n,a-t),s=[],c=[],l=[];l[0]=0;for(var u=t;u<a&&s.length<o;u++)for(var d=this._ptr[u],f=this._ptr[u+1],p=d;p<f;p++){var m=this._index[p];if(m===u-t+n){s.push(this._values[p]),c[s.length-1]=m-n;break}}return l.push(s.length),new i({values:s,index:c,ptr:l,size:[o,1]})},i.fromJSON=function(e){return new i(e)},i.diagonal=function(e,r,a,o,s){if(!Pr(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(Or(e)&&(e=e.toNumber()),!Dr(e)||!Ri(e)||e<1)throw Error(`Size values must be positive integers`);return e}),a){if(Or(a)&&(a=a.toNumber()),!Dr(a)||!Ri(a))throw TypeError(`The parameter k must be an integer number`)}else a=0;var c=n,l=0;Nr(s)&&(c=t.find(n,[s,s])||n,l=t.convert(0,s));var u=a>0?a:0,d=a<0?-a:0,f=e[0],p=e[1],m=Math.min(f-d,p-u),h;if(Pr(r)){if(r.length!==m)throw Error(`Invalid value array length`);h=function(e){return r[e]}}else if(Fr(r)){var g=r.size();if(g.length!==1||g[0]!==m)throw Error(`Invalid matrix length`);h=function(e){return r.get([e])}}else h=function(){return r};for(var _=[],v=[],y=[],b=0;b<p;b++){y.push(_.length);var x=b-u;if(x>=0&&x<m){var S=h(x);c(S,l)||(v.push(x+d),_.push(S))}}return y.push(_.length),new i({values:_,index:v,ptr:y,size:[f,p]})},i.prototype.swapRows=function(e,t){if(!Dr(e)||!Ri(e)||!Dr(t)||!Ri(t))throw Error(`Row index must be positive integers`);if(this._size.length!==2)throw Error(`Only two dimensional matrix is supported`);return uc(e,this._size[0]),uc(t,this._size[0]),i._swapRows(e,t,this._size[1],this._values,this._index,this._ptr),this},i._forEachRow=function(e,t,n,r,i){for(var a=r[e],o=r[e+1],s=a;s<o;s++)i(n[s],t[s])},i._swapRows=function(e,t,n,r,i,a){for(var o=0;o<n;o++){var s=a[o],c=a[o+1],u=l(e,s,c,i),d=l(t,s,c,i);if(u<c&&d<c&&i[u]===e&&i[d]===t){if(r){var f=r[u];r[u]=r[d],r[d]=f}continue}if(u<c&&i[u]===e&&(d>=c||i[d]!==t)){var p=r?r[u]:void 0;i.splice(d,0,t),r&&r.splice(d,0,p),i.splice(d<=u?u+1:u,1),r&&r.splice(d<=u?u+1:u,1);continue}if(d<c&&i[d]===t&&(u>=c||i[u]!==e)){var m=r?r[d]:void 0;i.splice(u,0,e),r&&r.splice(u,0,m),i.splice(u<=d?d+1:d,1),r&&r.splice(u<=d?d+1:d,1)}}},i},{isClass:!0}),ld=`number`,ud=[`typed`];function dd(e){var t=e.match(/(0[box])([0-9a-fA-F]*)\.([0-9a-fA-F]*)/);return t?{input:e,radix:{"0b":2,"0o":8,"0x":16}[t[1]],integerPart:t[2],fractionalPart:t[3]}:null}function fd(e){for(var t=parseInt(e.integerPart,e.radix),n=0,r=0;r<e.fractionalPart.length;r++){var i=parseInt(e.fractionalPart[r],e.radix);n+=i/e.radix**+(r+1)}var a=t+n;if(isNaN(a))throw SyntaxError(`String "`+e.input+`" is not a valid number`);return a}var pd=J(ld,ud,e=>{var{typed:t}=e,n=t(`number`,{"":function(){return 0},number:function(e){return e},string:function(e){if(e===`NaN`)return NaN;var t=dd(e);if(t)return fd(t);var n=0,r=e.match(/(0[box][0-9a-fA-F]*)i([0-9]*)/);r&&(n=Number(r[2]),e=r[1]);var i=Number(e);if(isNaN(i))throw SyntaxError(`String "`+e+`" is not a valid number`);if(r){if(i>2**n-1)throw SyntaxError(`String "${e}" is out of range`);i>=2**(n-1)&&(i-=2**n)}return i},BigNumber:function(e){return e.toNumber()},bigint:function(e){return Number(e)},Fraction:function(e){return e.valueOf()},Unit:t.referToSelf(e=>t=>{var n=t.clone();return n.value=e(t.value),n}),null:function(e){return 0},"Unit, string | Unit":function(e,t){return e.toNumber(t)},"Array | Matrix":t.referToSelf(e=>t=>$c(t,e))});return n.fromJSON=function(e){return parseFloat(e.value)},n}),md=J(`bigint`,[`typed`],e=>{var{typed:t}=e,n=t(`bigint`,{"":function(){return 0n},bigint:function(e){return e},number:function(e){return BigInt(e.toFixed())},BigNumber:function(e){return BigInt(e.round().toString())},Fraction:function(e){return BigInt(e.valueOf().toFixed())},"string | boolean":function(e){return BigInt(e)},null:function(e){return 0n},"Array | Matrix":t.referToSelf(e=>t=>$c(t,e))});return n.fromJSON=function(e){return BigInt(e.value)},n}),hd=`string`,gd=J(hd,[`typed`],e=>{var{typed:t}=e;return t(hd,{"":function(){return``},number:qi,null:function(e){return`null`},boolean:function(e){return e+``},string:function(e){return e},"Array | Matrix":t.referToSelf(e=>t=>$c(t,e)),any:function(e){return String(e)}})}),_d=`boolean`,vd=J(_d,[`typed`],e=>{var{typed:t}=e;return t(_d,{"":function(){return!1},boolean:function(e){return e},number:function(e){return!!e},null:function(e){return!1},BigNumber:function(e){return!e.isZero()},string:function(e){var t=e.toLowerCase();if(t===`true`)return!0;if(t===`false`)return!1;var n=Number(e);if(e!==``&&!isNaN(n))return!!n;throw Error(`Cannot convert "`+e+`" to a boolean`)},"Array | Matrix":t.referToSelf(e=>t=>$c(t,e))})}),yd=J(`bignumber`,[`typed`,`BigNumber`],e=>{var{typed:t,BigNumber:n}=e;return t(`bignumber`,{"":function(){return new n(0)},number:function(e){return new n(e+``)},string:function(e){var t=e.match(/(0[box][0-9a-fA-F]*)i([0-9]*)/);if(t){var r=t[2],i=n(t[1]),a=new n(2).pow(Number(r));if(i.gt(a.sub(1)))throw SyntaxError(`String "${e}" is out of range`);var o=new n(2).pow(Number(r)-1);return i.gte(o)?i.sub(a):i}return new n(e)},BigNumber:function(e){return e},bigint:function(e){return new n(e.toString())},Unit:t.referToSelf(e=>t=>{var n=t.clone();return n.value=e(t.value),n}),Fraction:function(e){return new n(String(e.n)).div(String(e.d)).times(String(e.s))},null:function(e){return new n(0)},"Array | Matrix":t.referToSelf(e=>t=>$c(t,e))})}),bd=J(`complex`,[`typed`,`Complex`],e=>{var{typed:t,Complex:n}=e;return t(`complex`,{"":function(){return n.ZERO},number:function(e){return new n(e,0)},"number, number":function(e,t){return new n(e,t)},"BigNumber, BigNumber":function(e,t){return new n(e.toNumber(),t.toNumber())},Fraction:function(e){return new n(e.valueOf(),0)},Complex:function(e){return e.clone()},string:function(e){return n(e)},null:function(e){return n(0)},Object:function(e){if(`re`in e&&`im`in e)return new n(e.re,e.im);if(`r`in e&&`phi`in e||`abs`in e&&`arg`in e)return new n(e);throw Error(`Expected object with properties (re and im) or (r and phi) or (abs and arg)`)},"Array | Matrix":t.referToSelf(e=>t=>$c(t,e))})}),xd=J(`fraction`,[`typed`,`Fraction`],e=>{var{typed:t,Fraction:n}=e;return t(`fraction`,{number:function(e){if(!Number.isFinite(e)||isNaN(e))throw Error(e+` cannot be represented as a fraction`);return new n(e)},string:function(e){return new n(e)},"number, number":function(e,t){return new n(e,t)},"bigint, bigint":function(e,t){return new n(e,t)},null:function(e){return new n(0)},BigNumber:function(e){return new n(e.toString())},bigint:function(e){return new n(e.toString())},Fraction:function(e){return e},Unit:t.referToSelf(e=>t=>{var n=t.clone();return n.value=e(t.value),n}),Object:function(e){return new n(e)},"Array | Matrix":t.referToSelf(e=>t=>$c(t,e))})}),Sd=`matrix`,Cd=J(Sd,[`typed`,`Matrix`,`DenseMatrix`,`SparseMatrix`],e=>{var{typed:t,Matrix:n,DenseMatrix:r,SparseMatrix:i}=e;return t(Sd,{"":function(){return a([])},string:function(e){return a([],e)},"string, string":function(e,t){return a([],e,t)},Array:function(e){return a(e)},Matrix:function(e){return a(e,e.storage())},"Array | Matrix, string":a,"Array | Matrix, string, string":a});function a(e,t,n){if(t===`dense`||t===`default`||t===void 0)return new r(e,n);if(t===`sparse`)return new i(e,n);throw TypeError(`Unknown matrix type `+JSON.stringify(t)+`.`)}}),wd=`matrixFromFunction`,Td=J(wd,[`typed`,`matrix`,`isZero`],e=>{var{typed:t,matrix:n,isZero:r}=e;return t(wd,{"Array | Matrix, function, string, string":function(e,t,n,r){return i(e,t,n,r)},"Array | Matrix, function, string":function(e,t,n){return i(e,t,n)},"Matrix, function":function(e,t){return i(e,t,`dense`)},"Array, function":function(e,t){return i(e,t,`dense`).toArray()},"Array | Matrix, string, function":function(e,t,n){return i(e,n,t)},"Array | Matrix, string, string, function":function(e,t,n,r){return i(e,r,t,n)}});function i(e,t,i,a){var o=a===void 0?n(i):n(i,a);return o.resize(e),o.forEach(function(e,n){var i=t(n);r(i)||o.set(n,i)}),o}}),Ed=`matrixFromRows`,Dd=J(Ed,[`typed`,`matrix`,`flatten`,`size`],e=>{var{typed:t,matrix:n,flatten:r,size:i}=e;return t(Ed,{"...Array":function(e){return a(e)},"...Matrix":function(e){return n(a(e.map(e=>e.toArray())))}});function a(e){if(e.length===0)throw TypeError(`At least one row is needed to construct a matrix.`);var t=o(e[0]),n=[];for(var i of e){var a=o(i);if(a!==t)throw TypeError(`The vectors had different length: `+(t|0)+` ≠ `+(a|0));n.push(r(i))}return n}function o(e){var t=i(e);if(t.length===1)return t[0];if(t.length===2){if(t[0]===1)return t[1];if(t[1]===1)return t[0];throw TypeError(`At least one of the arguments is not a vector.`)}else throw TypeError(`Only one- or two-dimensional vectors are supported.`)}}),Od=`matrixFromColumns`,kd=J(Od,[`typed`,`matrix`,`flatten`,`size`],e=>{var{typed:t,matrix:n,flatten:r,size:i}=e;return t(Od,{"...Array":function(e){return a(e)},"...Matrix":function(e){return n(a(e.map(e=>e.toArray())))}});function a(e){if(e.length===0)throw TypeError(`At least one column is needed to construct a matrix.`);for(var t=o(e[0]),n=[],i=0;i<t;i++)n[i]=[];for(var a of e){var s=o(a);if(s!==t)throw TypeError(`The vectors had different length: `+(t|0)+` ≠ `+(s|0));for(var c=r(a),l=0;l<t;l++)n[l].push(c[l])}return n}function o(e){var t=i(e);if(t.length===1)return t[0];if(t.length===2){if(t[0]===1)return t[1];if(t[1]===1)return t[0];throw TypeError(`At least one of the arguments is not a vector.`)}else throw TypeError(`Only one- or two-dimensional vectors are supported.`)}}),Ad=`splitUnit`,jd=J(Ad,[`typed`],e=>{var{typed:t}=e;return t(Ad,{"Unit, Array":function(e,t){return e.splitUnit(t)}})}),Md=`unaryMinus`,Nd=J(Md,[`typed`],e=>{var{typed:t}=e;return t(Md,{number:fl,"Complex | BigNumber | Fraction":e=>e.neg(),bigint:e=>-e,Unit:t.referToSelf(e=>n=>{var r=n.clone();return r.value=t.find(e,r.valueType())(n.value),r}),"Array | Matrix":t.referToSelf(e=>t=>$c(t,e,!0))})}),Pd=`unaryPlus`,Fd=J(Pd,[`typed`,`config`,`numeric`],e=>{var{typed:t,config:n,numeric:r}=e;return t(Pd,{number:pl,Complex:function(e){return e},BigNumber:function(e){return e},bigint:function(e){return e},Fraction:function(e){return e},Unit:function(e){return e.clone()},"Array | Matrix":t.referToSelf(e=>t=>$c(t,e,!0)),boolean:function(e){return r(+!!e,n.number)},string:function(e){return r(e,zi(e,n))}})}),Id=`abs`,Ld=J(Id,[`typed`],e=>{var{typed:t}=e;return t(Id,{number:sl,"Complex | BigNumber | Fraction | Unit":e=>e.abs(),bigint:e=>e<0n?-e:e,"Array | Matrix":t.referToSelf(e=>t=>$c(t,e,!0))})}),Rd=`mapSlices`,zd=J(Rd,[`typed`,`isInteger`],e=>{var{typed:t,isInteger:n}=e;return t(Rd,{"Array | Matrix, number | BigNumber, function":function(e,t,r){if(!n(t))throw TypeError(`Integer number expected for dimension`);var i=Array.isArray(e)?oc(e):e.size();if(t<0||t>=i.length)throw new ac(t,i.length);return Fr(e)?e.create(Bd(e.valueOf(),t,r),e.datatype()):Bd(e,t,r)}})},{formerly:`apply`});function Bd(e,t,n){var r,i,a;if(t<=0)if(Array.isArray(e[0])){for(a=Vd(e),i=[],r=0;r<a.length;r++)i[r]=Bd(a[r],t-1,n);return i}else return n(e);else{for(i=[],r=0;r<e.length;r++)i[r]=Bd(e[r],t-1,n);return i}}function Vd(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}var Hd=`addScalar`,Ud=J(Hd,[`typed`],e=>{var{typed:t}=e;return t(Hd,{"number, number":cl,"Complex, Complex":function(e,t){return e.add(t)},"BigNumber, BigNumber":function(e,t){return e.plus(t)},"bigint, bigint":function(e,t){return e+t},"Fraction, Fraction":function(e,t){return e.add(t)},"Unit, Unit":t.referToSelf(e=>(n,r)=>{if(n.value===null||n.value===void 0)throw Error(`Parameter x contains a unit with undefined value`);if(r.value===null||r.value===void 0)throw Error(`Parameter y contains a unit with undefined value`);if(!n.equalBase(r))throw Error(`Units do not match`);var i=n.clone();return i.value=t.find(e,[i.valueType(),r.valueType()])(i.value,r.value),i.fixPrefix=!1,i})})}),Wd=`subtractScalar`,Gd=J(Wd,[`typed`],e=>{var{typed:t}=e;return t(Wd,{"number, number":ll,"Complex, Complex":function(e,t){return e.sub(t)},"BigNumber, BigNumber":function(e,t){return e.minus(t)},"bigint, bigint":function(e,t){return e-t},"Fraction, Fraction":function(e,t){return e.sub(t)},"Unit, Unit":t.referToSelf(e=>(n,r)=>{if(n.value===null||n.value===void 0)throw Error(`Parameter x contains a unit with undefined value`);if(r.value===null||r.value===void 0)throw Error(`Parameter y contains a unit with undefined value`);if(!n.equalBase(r))throw Error(`Units do not match`);var i=n.clone();return i.value=t.find(e,[i.valueType(),r.valueType()])(i.value,r.value),i.fixPrefix=!1,i})})}),Kd=`cbrt`,qd=J(Kd,[`config`,`typed`,`isNegative`,`unaryMinus`,`matrix`,`Complex`,`BigNumber`,`Fraction`],e=>{var{config:t,typed:n,isNegative:r,unaryMinus:i,matrix:a,Complex:o,BigNumber:s,Fraction:c}=e;return n(Kd,{number:ml,Complex:l,"Complex, boolean":l,BigNumber:function(e){return e.cbrt()},Unit:u});function l(e,n){var r=e.arg()/3,i=e.abs(),s=new o(ml(i),0).mul(new o(0,r).exp());if(n){var c=[s,new o(ml(i),0).mul(new o(0,r+Math.PI*2/3).exp()),new o(ml(i),0).mul(new o(0,r-Math.PI*2/3).exp())];return t.matrix===`Array`?c:a(c)}else return s}function u(e){if(e.value&&Ar(e.value)){var t=e.clone();return t.value=1,t=t.pow(1/3),t.value=l(e.value),t}else{var n=r(e.value);n&&(e.value=i(e.value));var a=Or(e.value)?new s(1).div(3):jr(e.value)?new c(1,3):1/3,o=e.pow(a);return n&&(o.value=i(o.value)),o}}}),Jd=J(`matAlgo11xS0s`,[`typed`,`equalScalar`],e=>{var{typed:t,equalScalar:n}=e;return function(e,r,i,a){var o=e._values,s=e._index,c=e._ptr,l=e._size,u=e._datatype;if(!o)throw Error(`Cannot perform operation on Pattern Sparse Matrix and Scalar value`);var d=l[0],f=l[1],p,m=n,h=0,g=i;typeof u==`string`&&(p=u,m=t.find(n,[p,p]),h=t.convert(0,p),r=t.convert(r,p),g=t.find(i,[p,p]));for(var _=[],v=[],y=[],b=0;b<f;b++){y[b]=v.length;for(var x=c[b],S=c[b+1],C=x;C<S;C++){var w=s[C],T=a?g(r,o[C]):g(o[C],r);m(T,h)||(v.push(w),_.push(T))}}return y[f]=v.length,e.createSparseMatrix({values:_,index:v,ptr:y,size:[d,f],datatype:p})}}),Yd=J(`matAlgo12xSfs`,[`typed`,`DenseMatrix`],e=>{var{typed:t,DenseMatrix:n}=e;return function(e,r,i,a){var o=e._values,s=e._index,c=e._ptr,l=e._size,u=e._datatype;if(!o)throw Error(`Cannot perform operation on Pattern Sparse Matrix and Scalar value`);var d=l[0],f=l[1],p,m=i;typeof u==`string`&&(p=u,r=t.convert(r,p),m=t.find(i,[p,p]));for(var h=[],g=[],_=[],v=0;v<f;v++){for(var y=v+1,b=c[v],x=c[v+1],S=b;S<x;S++){var C=s[S];g[C]=o[S],_[C]=y}for(var w=0;w<d;w++)v===0&&(h[w]=[]),_[w]===y?h[w][v]=a?m(r,g[w]):m(g[w],r):h[w][v]=a?m(r,0):m(0,r)}return new n({data:h,size:[d,f],datatype:p})}}),Xd=J(`matAlgo14xDs`,[`typed`],e=>{var{typed:t}=e;return function(e,r,i,a){var o=e._data,s=e._size,c=e._datatype,l,u=i;typeof c==`string`&&(l=c,r=t.convert(r,l),u=t.find(i,[l,l]));var d=s.length>0?n(u,0,s,s[0],o,r,a):[];return e.createDenseMatrix({data:d,size:vi(s),datatype:l})};function n(e,t,r,i,a,o,s){var c=[];if(t===r.length-1)for(var l=0;l<i;l++)c[l]=s?e(o,a[l]):e(a[l],o);else for(var u=0;u<i;u++)c[u]=n(e,t+1,r,r[t+1],a[u],o,s);return c}}),Zd=`ceil`,Qd=[`typed`,`config`,`round`,`matrix`,`equalScalar`,`zeros`,`DenseMatrix`],$d=new ss(10),ef=J(Zd,[`typed`,`config`,`round`],e=>{var{typed:t,config:n,round:r}=e;function i(e){var t=Math.ceil(e),i=r(e);return t===i?t:ra(e,i,n.relTol,n.absTol)&&!ra(e,t,n.relTol,n.absTol)?i:t}return t(Zd,{number:i,"number, number":function(e,t){if(!Ri(t))throw RangeError(`number of decimals in function ceil must be an integer`);if(t<0||t>15)throw RangeError(`number of decimals in ceil number must be in range 0-15`);var n=10**t;return i(e*n)/n}})}),tf=J(Zd,Qd,e=>{var{typed:t,config:n,round:r,matrix:i,equalScalar:a,zeros:o,DenseMatrix:s}=e,c=Jd({typed:t,equalScalar:a}),l=Yd({typed:t,DenseMatrix:s}),u=Xd({typed:t}),d=ef({typed:t,config:n,round:r});function f(e){var t=(e,t)=>zu(e,t,n.relTol,n.absTol),i=e.ceil(),a=r(e);return i.eq(a)?i:t(e,a)&&!t(e,i)?a:i}return t(`ceil`,{number:d.signatures.number,"number,number":d.signatures[`number,number`],Complex:function(e){return e.ceil()},"Complex, number":function(e,t){return e.ceil(t)},"Complex, BigNumber":function(e,t){return e.ceil(t.toNumber())},BigNumber:f,"BigNumber, BigNumber":function(e,t){var n=$d.pow(t);return f(e.mul(n)).div(n)},bigint:e=>e,"bigint, number":(e,t)=>e,"bigint, BigNumber":(e,t)=>e,Fraction:function(e){return e.ceil()},"Fraction, number":function(e,t){return e.ceil(t)},"Fraction, BigNumber":function(e,t){return e.ceil(t.toNumber())},"Unit, number, Unit":t.referToSelf(e=>function(t,n,r){var i=t.toNumeric(r);return r.multiply(e(i,n))}),"Unit, BigNumber, Unit":t.referToSelf(e=>(t,n,r)=>e(t,n.toNumber(),r)),"Array | Matrix, number | BigNumber, Unit":t.referToSelf(e=>(t,n,r)=>$c(t,t=>e(t,n,r),!0)),"Array | Matrix | Unit, Unit":t.referToSelf(e=>(t,n)=>e(t,0,n)),"Array | Matrix":t.referToSelf(e=>t=>$c(t,e,!0)),"Array, number | BigNumber":t.referToSelf(e=>(t,n)=>$c(t,t=>e(t,n),!0)),"SparseMatrix, number | BigNumber":t.referToSelf(e=>(t,n)=>c(t,n,e,!1)),"DenseMatrix, number | BigNumber":t.referToSelf(e=>(t,n)=>u(t,n,e,!1)),"number | Complex | Fraction | BigNumber, Array":t.referToSelf(e=>(t,n)=>u(i(n),t,e,!0).valueOf()),"number | Complex | Fraction | BigNumber, Matrix":t.referToSelf(e=>(t,n)=>a(t,0)?o(n.size(),n.storage()):n.storage()===`dense`?u(n,t,e,!0):l(n,t,e,!0))})}),nf=`cube`,rf=J(nf,[`typed`],e=>{var{typed:t}=e;return t(nf,{number:hl,Complex:function(e){return e.mul(e).mul(e)},BigNumber:function(e){return e.times(e).times(e)},bigint:function(e){return e*e*e},Fraction:function(e){return e.pow(3)},Unit:function(e){return e.pow(3)}})}),af=`exp`,of=J(af,[`typed`],e=>{var{typed:t}=e;return t(af,{number:gl,Complex:function(e){return e.exp()},BigNumber:function(e){return e.exp()}})}),sf=`expm1`,cf=J(sf,[`typed`,`Complex`],e=>{var{typed:t,Complex:n}=e;return t(sf,{number:_l,Complex:function(e){var t=Math.exp(e.re);return new n(t*Math.cos(e.im)-1,t*Math.sin(e.im))},BigNumber:function(e){return e.exp().minus(1)}})}),lf=`fix`,uf=[`typed`,`Complex`,`matrix`,`ceil`,`floor`,`equalScalar`,`zeros`,`DenseMatrix`],df=J(lf,[`typed`,`ceil`,`floor`],e=>{var{typed:t,ceil:n,floor:r}=e;return t(lf,{number:function(e){return e>0?r(e):n(e)},"number, number":function(e,t){return e>0?r(e,t):n(e,t)}})}),ff=J(lf,uf,e=>{var{typed:t,Complex:n,matrix:r,ceil:i,floor:a,equalScalar:o,zeros:s,DenseMatrix:c}=e,l=Yd({typed:t,DenseMatrix:c}),u=Xd({typed:t}),d=df({typed:t,ceil:i,floor:a});return t(`fix`,{number:d.signatures.number,"number, number | BigNumber":d.signatures[`number,number`],Complex:function(e){return new n(e.re>0?Math.floor(e.re):Math.ceil(e.re),e.im>0?Math.floor(e.im):Math.ceil(e.im))},"Complex, number":function(e,t){return new n(e.re>0?a(e.re,t):i(e.re,t),e.im>0?a(e.im,t):i(e.im,t))},"Complex, BigNumber":function(e,t){var r=t.toNumber();return new n(e.re>0?a(e.re,r):i(e.re,r),e.im>0?a(e.im,r):i(e.im,r))},BigNumber:function(e){return e.isNegative()?i(e):a(e)},"BigNumber, number | BigNumber":function(e,t){return e.isNegative()?i(e,t):a(e,t)},bigint:e=>e,"bigint, number":(e,t)=>e,"bigint, BigNumber":(e,t)=>e,Fraction:function(e){return e.s<0n?e.ceil():e.floor()},"Fraction, number | BigNumber":function(e,t){return e.s<0n?i(e,t):a(e,t)},"Unit, number, Unit":t.referToSelf(e=>function(t,n,r){var i=t.toNumeric(r);return r.multiply(e(i,n))}),"Unit, BigNumber, Unit":t.referToSelf(e=>(t,n,r)=>e(t,n.toNumber(),r)),"Array | Matrix, number | BigNumber, Unit":t.referToSelf(e=>(t,n,r)=>$c(t,t=>e(t,n,r),!0)),"Array | Matrix | Unit, Unit":t.referToSelf(e=>(t,n)=>e(t,0,n)),"Array | Matrix":t.referToSelf(e=>t=>$c(t,e,!0)),"Array | Matrix, number | BigNumber":t.referToSelf(e=>(t,n)=>$c(t,t=>e(t,n),!0)),"number | Complex | Fraction | BigNumber, Array":t.referToSelf(e=>(t,n)=>u(r(n),t,e,!0).valueOf()),"number | Complex | Fraction | BigNumber, Matrix":t.referToSelf(e=>(t,n)=>o(t,0)?s(n.size(),n.storage()):n.storage()===`dense`?u(n,t,e,!0):l(n,t,e,!0))})}),pf=`floor`,mf=[`typed`,`config`,`round`,`matrix`,`equalScalar`,`zeros`,`DenseMatrix`],hf=new ss(10),gf=J(pf,[`typed`,`config`,`round`],e=>{var{typed:t,config:n,round:r}=e;function i(e){var t=Math.floor(e),i=r(e);return t===i?t:ra(e,i,n.relTol,n.absTol)&&!ra(e,t,n.relTol,n.absTol)?i:t}return t(pf,{number:i,"number, number":function(e,t){if(!Ri(t))throw RangeError(`number of decimals in function floor must be an integer`);if(t<0||t>15)throw RangeError(`number of decimals in floor number must be in range 0 - 15`);var n=10**t;return i(e*n)/n}})}),_f=J(pf,mf,e=>{var{typed:t,config:n,round:r,matrix:i,equalScalar:a,zeros:o,DenseMatrix:s}=e,c=Jd({typed:t,equalScalar:a}),l=Yd({typed:t,DenseMatrix:s}),u=Xd({typed:t}),d=gf({typed:t,config:n,round:r});function f(e){var t=(e,t)=>zu(e,t,n.relTol,n.absTol),i=e.floor(),a=r(e);return i.eq(a)?i:t(e,a)&&!t(e,i)?a:i}return t(`floor`,{number:d.signatures.number,"number,number":d.signatures[`number,number`],Complex:function(e){return e.floor()},"Complex, number":function(e,t){return e.floor(t)},"Complex, BigNumber":function(e,t){return e.floor(t.toNumber())},BigNumber:f,"BigNumber, BigNumber":function(e,t){var n=hf.pow(t);return f(e.mul(n)).div(n)},bigint:e=>e,"bigint, number":(e,t)=>e,"bigint, BigNumber":(e,t)=>e,Fraction:function(e){return e.floor()},"Fraction, number":function(e,t){return e.floor(t)},"Fraction, BigNumber":function(e,t){return e.floor(t.toNumber())},"Unit, number, Unit":t.referToSelf(e=>function(t,n,r){var i=t.toNumeric(r);return r.multiply(e(i,n))}),"Unit, BigNumber, Unit":t.referToSelf(e=>(t,n,r)=>e(t,n.toNumber(),r)),"Array | Matrix, number | BigNumber, Unit":t.referToSelf(e=>(t,n,r)=>$c(t,t=>e(t,n,r),!0)),"Array | Matrix | Unit, Unit":t.referToSelf(e=>(t,n)=>e(t,0,n)),"Array | Matrix":t.referToSelf(e=>t=>$c(t,e,!0)),"Array, number | BigNumber":t.referToSelf(e=>(t,n)=>$c(t,t=>e(t,n),!0)),"SparseMatrix, number | BigNumber":t.referToSelf(e=>(t,n)=>c(t,n,e,!1)),"DenseMatrix, number | BigNumber":t.referToSelf(e=>(t,n)=>u(t,n,e,!1)),"number | Complex | Fraction | BigNumber, Array":t.referToSelf(e=>(t,n)=>u(i(n),t,e,!0).valueOf()),"number | Complex | Fraction | BigNumber, Matrix":t.referToSelf(e=>(t,n)=>a(t,0)?o(n.size(),n.storage()):n.storage()===`dense`?u(n,t,e,!0):l(n,t,e,!0))})}),vf=J(`matAlgo02xDS0`,[`typed`,`equalScalar`],e=>{var{typed:t,equalScalar:n}=e;return function(e,r,i,a){var o=e._data,s=e._size,c=e._datatype||e.getDataType(),l=r._values,u=r._index,d=r._ptr,f=r._size,p=r._datatype||r._data===void 0?r._datatype:r.getDataType();if(s.length!==f.length)throw new ic(s.length,f.length);if(s[0]!==f[0]||s[1]!==f[1])throw RangeError(`Dimension mismatch. Matrix A (`+s+`) must match Matrix B (`+f+`)`);if(!l)throw Error(`Cannot perform operation on Dense Matrix and Pattern Sparse Matrix`);var m=s[0],h=s[1],g,_=n,v=0,y=i;typeof c==`string`&&c===p&&c!==`mixed`&&(g=c,_=t.find(n,[g,g]),v=t.convert(0,g),y=t.find(i,[g,g]));for(var b=[],x=[],S=[],C=0;C<h;C++){S[C]=x.length;for(var w=d[C],T=d[C+1],E=w;E<T;E++){var D=u[E],O=a?y(l[E],o[D][C]):y(o[D][C],l[E]);_(O,v)||(x.push(D),b.push(O))}}return S[h]=x.length,r.createSparseMatrix({values:b,index:x,ptr:S,size:[m,h],datatype:c===e._datatype&&p===r._datatype?g:void 0})}}),yf=J(`matAlgo03xDSf`,[`typed`],e=>{var{typed:t}=e;return function(e,n,r,i){var a=e._data,o=e._size,s=e._datatype||e.getDataType(),c=n._values,l=n._index,u=n._ptr,d=n._size,f=n._datatype||n._data===void 0?n._datatype:n.getDataType();if(o.length!==d.length)throw new ic(o.length,d.length);if(o[0]!==d[0]||o[1]!==d[1])throw RangeError(`Dimension mismatch. Matrix A (`+o+`) must match Matrix B (`+d+`)`);if(!c)throw Error(`Cannot perform operation on Dense Matrix and Pattern Sparse Matrix`);var p=o[0],m=o[1],h,g=0,_=r;typeof s==`string`&&s===f&&s!==`mixed`&&(h=s,g=t.convert(0,h),_=t.find(r,[h,h]));for(var v=[],y=0;y<p;y++)v[y]=[];for(var b=[],x=[],S=0;S<m;S++){for(var C=S+1,w=u[S],T=u[S+1],E=w;E<T;E++){var D=l[E];b[D]=i?_(c[E],a[D][S]):_(a[D][S],c[E]),x[D]=C}for(var O=0;O<p;O++)x[O]===C?v[O][S]=b[O]:v[O][S]=i?_(g,a[O][S]):_(a[O][S],g)}return e.createDenseMatrix({data:v,size:[p,m],datatype:s===e._datatype&&f===n._datatype?h:void 0})}}),bf=J(`matAlgo05xSfSf`,[`typed`,`equalScalar`],e=>{var{typed:t,equalScalar:n}=e;return function(e,r,i){var a=e._values,o=e._index,s=e._ptr,c=e._size,l=e._datatype||e._data===void 0?e._datatype:e.getDataType(),u=r._values,d=r._index,f=r._ptr,p=r._size,m=r._datatype||r._data===void 0?r._datatype:r.getDataType();if(c.length!==p.length)throw new ic(c.length,p.length);if(c[0]!==p[0]||c[1]!==p[1])throw RangeError(`Dimension mismatch. Matrix A (`+c+`) must match Matrix B (`+p+`)`);var h=c[0],g=c[1],_,v=n,y=0,b=i;typeof l==`string`&&l===m&&l!==`mixed`&&(_=l,v=t.find(n,[_,_]),y=t.convert(0,_),b=t.find(i,[_,_]));var x=a&&u?[]:void 0,S=[],C=[],w=x?[]:void 0,T=x?[]:void 0,E=[],D=[],O,k,A,j;for(k=0;k<g;k++){C[k]=S.length;var M=k+1;for(A=s[k],j=s[k+1];A<j;A++)O=o[A],S.push(O),E[O]=M,w&&(w[O]=a[A]);for(A=f[k],j=f[k+1];A<j;A++)O=d[A],E[O]!==M&&S.push(O),D[O]=M,T&&(T[O]=u[A]);if(x)for(A=C[k];A<S.length;){O=S[A];var N=E[O],P=D[O];if(N===M||P===M){var F=N===M?w[O]:y,I=P===M?T[O]:y,L=b(F,I);v(L,y)?S.splice(A,1):(x.push(L),A++)}}}return C[g]=S.length,e.createSparseMatrix({values:x,index:S,ptr:C,size:[h,g],datatype:l===e._datatype&&m===r._datatype?_:void 0})}}),xf=J(`matAlgo13xDD`,[`typed`],e=>{var{typed:t}=e;return function(e,r,i){var a=e._data,o=e._size,s=e._datatype,c=r._data,l=r._size,u=r._datatype,d=[];if(o.length!==l.length)throw new ic(o.length,l.length);for(var f=0;f<o.length;f++){if(o[f]!==l[f])throw RangeError(`Dimension mismatch. Matrix A (`+o+`) must match Matrix B (`+l+`)`);d[f]=o[f]}var p,m=i;typeof s==`string`&&s===u&&(p=s,m=t.find(i,[p,p]));var h=d.length>0?n(m,0,d,d[0],a,c):[];return e.createDenseMatrix({data:h,size:d,datatype:p})};function n(e,t,r,i,a,o){var s=[];if(t===r.length-1)for(var c=0;c<i;c++)s[c]=e(a[c],o[c]);else for(var l=0;l<i;l++)s[l]=n(e,t+1,r,r[t+1],a[l],o[l]);return s}});function Sf(e,t){if(Si(e.size(),t.size()))return[e,t];var n=Nc(e.size(),t.size());return[e,t].map(e=>Cf(e,n))}function Cf(e,t){return Si(e.size(),t)?e:e.create(Fc(e.valueOf(),t),e.datatype())}var wf=J(`matrixAlgorithmSuite`,[`typed`,`matrix`],e=>{var{typed:t,matrix:n}=e,r=xf({typed:t}),i=Xd({typed:t});return function(e){var a=e.elop,o=e.SD||e.DS,s;a?(s={"DenseMatrix, DenseMatrix":(e,t)=>r(...Sf(e,t),a),"Array, Array":(e,t)=>r(...Sf(n(e),n(t)),a).valueOf(),"Array, DenseMatrix":(e,t)=>r(...Sf(n(e),t),a),"DenseMatrix, Array":(e,t)=>r(...Sf(e,n(t)),a)},e.SS&&(s[`SparseMatrix, SparseMatrix`]=(t,n)=>e.SS(...Sf(t,n),a,!1)),e.DS&&(s[`DenseMatrix, SparseMatrix`]=(t,n)=>e.DS(...Sf(t,n),a,!1),s[`Array, SparseMatrix`]=(t,r)=>e.DS(...Sf(n(t),r),a,!1)),o&&(s[`SparseMatrix, DenseMatrix`]=(e,t)=>o(...Sf(t,e),a,!0),s[`SparseMatrix, Array`]=(e,t)=>o(...Sf(n(t),e),a,!0))):(s={"DenseMatrix, DenseMatrix":t.referToSelf(e=>(t,n)=>r(...Sf(t,n),e)),"Array, Array":t.referToSelf(e=>(t,i)=>r(...Sf(n(t),n(i)),e).valueOf()),"Array, DenseMatrix":t.referToSelf(e=>(t,i)=>r(...Sf(n(t),i),e)),"DenseMatrix, Array":t.referToSelf(e=>(t,i)=>r(...Sf(t,n(i)),e))},e.SS&&(s[`SparseMatrix, SparseMatrix`]=t.referToSelf(t=>(n,r)=>e.SS(...Sf(n,r),t,!1))),e.DS&&(s[`DenseMatrix, SparseMatrix`]=t.referToSelf(t=>(n,r)=>e.DS(...Sf(n,r),t,!1)),s[`Array, SparseMatrix`]=t.referToSelf(t=>(r,i)=>e.DS(...Sf(n(r),i),t,!1))),o&&(s[`SparseMatrix, DenseMatrix`]=t.referToSelf(e=>(t,n)=>o(...Sf(n,t),e,!0)),s[`SparseMatrix, Array`]=t.referToSelf(e=>(t,r)=>o(...Sf(n(r),t),e,!0))));var c=e.scalar||`any`;(e.Ds||e.Ss)&&(a?(s[`DenseMatrix,`+c]=(e,t)=>i(e,t,a,!1),s[c+`, DenseMatrix`]=(e,t)=>i(t,e,a,!0),s[`Array,`+c]=(e,t)=>i(n(e),t,a,!1).valueOf(),s[c+`, Array`]=(e,t)=>i(n(t),e,a,!0).valueOf()):(s[`DenseMatrix,`+c]=t.referToSelf(e=>(t,n)=>i(t,n,e,!1)),s[c+`, DenseMatrix`]=t.referToSelf(e=>(t,n)=>i(n,t,e,!0)),s[`Array,`+c]=t.referToSelf(e=>(t,r)=>i(n(t),r,e,!1).valueOf()),s[c+`, Array`]=t.referToSelf(e=>(t,r)=>i(n(r),t,e,!0).valueOf())));var l=e.sS===void 0?e.Ss:e.sS;return a?(e.Ss&&(s[`SparseMatrix,`+c]=(t,n)=>e.Ss(t,n,a,!1)),l&&(s[c+`, SparseMatrix`]=(e,t)=>l(t,e,a,!0))):(e.Ss&&(s[`SparseMatrix,`+c]=t.referToSelf(t=>(n,r)=>e.Ss(n,r,t,!1))),l&&(s[c+`, SparseMatrix`]=t.referToSelf(e=>(t,n)=>l(n,t,e,!0)))),a&&a.signatures&&bi(s,a.signatures),s}}),Tf=`mod`,Ef=J(Tf,[`typed`,`config`,`round`,`matrix`,`equalScalar`,`zeros`,`DenseMatrix`,`concat`],e=>{var{typed:t,config:n,round:r,matrix:i,equalScalar:a,zeros:o,DenseMatrix:s,concat:c}=e,l=_f({typed:t,config:n,round:r,matrix:i,equalScalar:a,zeros:o,DenseMatrix:s}),u=vf({typed:t,equalScalar:a}),d=yf({typed:t}),f=bf({typed:t,equalScalar:a}),p=Jd({typed:t,equalScalar:a}),m=Yd({typed:t,DenseMatrix:s}),h=wf({typed:t,matrix:i,concat:c});return t(Tf,{"number, number":g,"BigNumber, BigNumber":function(e,t){return t.isZero()?e:e.sub(t.mul(l(e.div(t))))},"bigint, bigint":function(e,t){if(t===0n)return e;if(e<0){var n=e%t;return n===0n?n:n+t}return e%t},"Fraction, Fraction":function(e,t){return t.equals(0)?e:e.sub(t.mul(l(e.div(t))))}},h({SS:f,DS:d,SD:u,Ss:p,sS:m}));function g(e,t){return t===0?e:e-t*l(e/t)}}),Df=J(`matAlgo01xDSid`,[`typed`],e=>{var{typed:t}=e;return function(e,n,r,i){var a=e._data,o=e._size,s=e._datatype||e.getDataType(),c=n._values,l=n._index,u=n._ptr,d=n._size,f=n._datatype||n._data===void 0?n._datatype:n.getDataType();if(o.length!==d.length)throw new ic(o.length,d.length);if(o[0]!==d[0]||o[1]!==d[1])throw RangeError(`Dimension mismatch. Matrix A (`+o+`) must match Matrix B (`+d+`)`);if(!c)throw Error(`Cannot perform operation on Dense Matrix and Pattern Sparse Matrix`);var p=o[0],m=o[1],h=typeof s==`string`&&s!==`mixed`&&s===f?s:void 0,g=h?t.find(r,[h,h]):r,_,v,y=[];for(_=0;_<p;_++)y[_]=[];var b=[],x=[];for(v=0;v<m;v++){for(var S=v+1,C=u[v],w=u[v+1],T=C;T<w;T++)_=l[T],b[_]=i?g(c[T],a[_][v]):g(a[_][v],c[T]),x[_]=S;for(_=0;_<p;_++)x[_]===S?y[_][v]=b[_]:y[_][v]=a[_][v]}return e.createDenseMatrix({data:y,size:[p,m],datatype:s===e._datatype&&f===n._datatype?h:void 0})}}),Of=J(`matAlgo04xSidSid`,[`typed`,`equalScalar`],e=>{var{typed:t,equalScalar:n}=e;return function(e,r,i){var a=e._values,o=e._index,s=e._ptr,c=e._size,l=e._datatype||e._data===void 0?e._datatype:e.getDataType(),u=r._values,d=r._index,f=r._ptr,p=r._size,m=r._datatype||r._data===void 0?r._datatype:r.getDataType();if(c.length!==p.length)throw new ic(c.length,p.length);if(c[0]!==p[0]||c[1]!==p[1])throw RangeError(`Dimension mismatch. Matrix A (`+c+`) must match Matrix B (`+p+`)`);var h=c[0],g=c[1],_,v=n,y=0,b=i;typeof l==`string`&&l===m&&l!==`mixed`&&(_=l,v=t.find(n,[_,_]),y=t.convert(0,_),b=t.find(i,[_,_]));var x=a&&u?[]:void 0,S=[],C=[],w=a&&u?[]:void 0,T=a&&u?[]:void 0,E=[],D=[],O,k,A,j,M;for(k=0;k<g;k++){C[k]=S.length;var N=k+1;for(j=s[k],M=s[k+1],A=j;A<M;A++)O=o[A],S.push(O),E[O]=N,w&&(w[O]=a[A]);for(j=f[k],M=f[k+1],A=j;A<M;A++)if(O=d[A],E[O]===N){if(w){var P=b(w[O],u[A]);v(P,y)?E[O]=null:w[O]=P}}else S.push(O),D[O]=N,T&&(T[O]=u[A]);if(w&&T)for(A=C[k];A<S.length;)O=S[A],E[O]===N?(x[A]=w[O],A++):D[O]===N?(x[A]=T[O],A++):S.splice(A,1)}return C[g]=S.length,e.createSparseMatrix({values:x,index:S,ptr:C,size:[h,g],datatype:l===e._datatype&&m===r._datatype?_:void 0})}}),kf=J(`matAlgo10xSids`,[`typed`,`DenseMatrix`],e=>{var{typed:t,DenseMatrix:n}=e;return function(e,r,i,a){var o=e._values,s=e._index,c=e._ptr,l=e._size,u=e._datatype;if(!o)throw Error(`Cannot perform operation on Pattern Sparse Matrix and Scalar value`);var d=l[0],f=l[1],p,m=i;typeof u==`string`&&(p=u,r=t.convert(r,p),m=t.find(i,[p,p]));for(var h=[],g=[],_=[],v=0;v<f;v++){for(var y=v+1,b=c[v],x=c[v+1],S=b;S<x;S++){var C=s[S];g[C]=o[S],_[C]=y}for(var w=0;w<d;w++)v===0&&(h[w]=[]),_[w]===y?h[w][v]=a?m(r,g[w]):m(g[w],r):h[w][v]=r}return new n({data:h,size:[d,f],datatype:p})}});function Af(e,t,n,r){if(!(this instanceof Af))throw SyntaxError(`Constructor must be called with the new operator`);this.fn=e,this.count=t,this.min=n,this.max=r,this.message=`Wrong number of arguments in function `+e+` (`+t+` provided, `+n+(r==null?``:`-`+r)+` expected)`,this.stack=Error().stack}Af.prototype=Error(),Af.prototype.constructor=Error,Af.prototype.name=`ArgumentsError`,Af.prototype.isArgumentsError=!0;var jf=`gcd`,Mf=[`typed`,`config`,`round`,`matrix`,`equalScalar`,`zeros`,`BigNumber`,`DenseMatrix`,`concat`],Nf=`number | BigNumber | Fraction | Matrix | Array`,Pf=`${Nf}, ${Nf}, ...${Nf}`;function Ff(e){return!e.some(e=>Array.isArray(e))}var If=J(jf,Mf,e=>{var{typed:t,matrix:n,config:r,round:i,equalScalar:a,zeros:o,BigNumber:s,DenseMatrix:c,concat:l}=e,u=Ef({typed:t,config:r,round:i,matrix:n,equalScalar:a,zeros:o,DenseMatrix:c,concat:l}),d=Df({typed:t}),f=Of({typed:t,equalScalar:a}),p=kf({typed:t,DenseMatrix:c}),m=wf({typed:t,matrix:n,concat:l});return t(jf,{"number, number":h,"BigNumber, BigNumber":g,"Fraction, Fraction":(e,t)=>e.gcd(t)},m({SS:f,DS:d,Ss:p}),{[Pf]:t.referToSelf(e=>(t,n,r)=>{for(var i=e(t,n),a=0;a<r.length;a++)i=e(i,r[a]);return i}),Array:t.referToSelf(e=>t=>{if(t.length===1&&Array.isArray(t[0])&&Ff(t[0]))return e(...t[0]);if(Ff(t))return e(...t);throw new Af(`gcd() supports only 1d matrices!`)}),Matrix:t.referToSelf(e=>t=>e(t.toArray()))});function h(e,t){if(!Ri(e)||!Ri(t))throw Error(`Parameters in function gcd must be integer numbers`);for(var n;t!==0;)n=u(e,t),e=t,t=n;return e<0?-e:e}function g(e,t){if(!e.isInt()||!t.isInt())throw Error(`Parameters in function gcd must be integer numbers`);for(var n=new s(0);!t.isZero();){var r=u(e,t);e=t,t=r}return e.lt(n)?e.neg():e}}),Lf=J(`matAlgo06xS0S0`,[`typed`,`equalScalar`],e=>{var{typed:t,equalScalar:n}=e;return function(e,r,i){var a=e._values,o=e._size,s=e._datatype||e._data===void 0?e._datatype:e.getDataType(),c=r._values,l=r._size,u=r._datatype||r._data===void 0?r._datatype:r.getDataType();if(o.length!==l.length)throw new ic(o.length,l.length);if(o[0]!==l[0]||o[1]!==l[1])throw RangeError(`Dimension mismatch. Matrix A (`+o+`) must match Matrix B (`+l+`)`);var d=o[0],f=o[1],p,m=n,h=0,g=i;typeof s==`string`&&s===u&&s!==`mixed`&&(p=s,m=t.find(n,[p,p]),h=t.convert(0,p),g=t.find(i,[p,p]));for(var _=a&&c?[]:void 0,v=[],y=[],b=_?[]:void 0,x=[],S=[],C=0;C<f;C++){y[C]=v.length;var w=C+1;if(nl(e,C,x,b,S,w,v,g),nl(r,C,x,b,S,w,v,g),b)for(var T=y[C];T<v.length;){var E=v[T];if(S[E]===w){var D=b[E];m(D,h)?v.splice(T,1):(_.push(D),T++)}else v.splice(T,1)}else for(var O=y[C];O<v.length;)S[v[O]]===w?O++:v.splice(O,1)}return y[f]=v.length,e.createSparseMatrix({values:_,index:v,ptr:y,size:[d,f],datatype:s===e._datatype&&u===r._datatype?p:void 0})}}),Rf=`lcm`,zf=J(Rf,[`typed`,`matrix`,`equalScalar`,`concat`],e=>{var{typed:t,matrix:n,equalScalar:r,concat:i}=e,a=vf({typed:t,equalScalar:r}),o=Lf({typed:t,equalScalar:r}),s=Jd({typed:t,equalScalar:r}),c=wf({typed:t,matrix:n,concat:i}),l=`number | BigNumber | Fraction | Matrix | Array`,u={};return u[`${l}, ${l}, ...${l}`]=t.referToSelf(e=>(t,n,r)=>{for(var i=e(t,n),a=0;a<r.length;a++)i=e(i,r[a]);return i}),t(Rf,{"number, number":yl,"BigNumber, BigNumber":d,"Fraction, Fraction":(e,t)=>e.lcm(t)},c({SS:o,DS:a,Ss:s}),u);function d(e,t){if(!e.isInt()||!t.isInt())throw Error(`Parameters in function lcm must be integer numbers`);if(e.isZero())return e;if(t.isZero())return t;for(var n=e.times(t);!t.isZero();){var r=t;t=e.mod(r),e=r}return n.div(e).abs()}});function Bf(e,t,n,r){return function(i){if(i>0||n.predictable){if(i<=0)return NaN;var a=i.toString(16),o=a.substring(0,15);return e*(a.length-o.length)+t(Number(`0x`+o))}return r(i.toNumber())}}var Vf=`log10`,Hf=[`typed`,`config`,`Complex`],Uf=xl(16),Wf=J(Vf,Hf,e=>{var{typed:t,config:n,Complex:r}=e;function i(e){return e.log().div(Math.LN10)}function a(e){return i(new r(e,0))}return t(Vf,{number:function(e){return e>=0||n.predictable?xl(e):a(e)},bigint:Bf(Uf,xl,n,a),Complex:i,BigNumber:function(e){return!e.isNegative()||n.predictable?e.log():a(e.toNumber())},"Array | Matrix":t.referToSelf(e=>t=>$c(t,e))})}),Gf=`log2`,Kf=J(Gf,[`typed`,`config`,`Complex`],e=>{var{typed:t,config:n,Complex:r}=e;function i(e){return a(new r(e,0))}return t(Gf,{number:function(e){return e>=0||n.predictable?Sl(e):i(e)},bigint:Bf(4,Sl,n,i),Complex:a,BigNumber:function(e){return!e.isNegative()||n.predictable?e.log(2):i(e.toNumber())},"Array | Matrix":t.referToSelf(e=>t=>$c(t,e))});function a(e){var t=Math.sqrt(e.re*e.re+e.im*e.im);return new r(Math.log2?Math.log2(t):Math.log(t)/Math.LN2,Math.atan2(e.im,e.re)/Math.LN2)}}),qf=J(`multiplyScalar`,[`typed`],e=>{var{typed:t}=e;return t(`multiplyScalar`,{"number, number":ul,"Complex, Complex":function(e,t){return e.mul(t)},"BigNumber, BigNumber":function(e,t){return e.times(t)},"bigint, bigint":function(e,t){return e*t},"Fraction, Fraction":function(e,t){return e.mul(t)},"number | Fraction | BigNumber | Complex, Unit":(e,t)=>t.multiply(e),"Unit, number | Fraction | BigNumber | Complex | Unit":(e,t)=>e.multiply(t)})}),Jf=`multiply`,Yf=J(Jf,[`typed`,`matrix`,`addScalar`,`multiplyScalar`,`equalScalar`,`dot`],e=>{var{typed:t,matrix:n,addScalar:r,multiplyScalar:i,equalScalar:a,dot:o}=e,s=Jd({typed:t,equalScalar:a}),c=Xd({typed:t});function l(e,t){switch(e.length){case 1:switch(t.length){case 1:if(e[0]!==t[0])throw RangeError(`Dimension mismatch in multiplication. Vectors must have the same length`);break;case 2:if(e[0]!==t[0])throw RangeError(`Dimension mismatch in multiplication. Vector length (`+e[0]+`) must match Matrix rows (`+t[0]+`)`);break;default:throw Error(`Can only multiply a 1 or 2 dimensional matrix (Matrix B has `+t.length+` dimensions)`)}break;case 2:switch(t.length){case 1:if(e[1]!==t[0])throw RangeError(`Dimension mismatch in multiplication. Matrix columns (`+e[1]+`) must match Vector length (`+t[0]+`)`);break;case 2:if(e[1]!==t[0])throw RangeError(`Dimension mismatch in multiplication. Matrix A columns (`+e[1]+`) must match Matrix B rows (`+t[0]+`)`);break;default:throw Error(`Can only multiply a 1 or 2 dimensional matrix (Matrix B has `+t.length+` dimensions)`)}break;default:throw Error(`Can only multiply a 1 or 2 dimensional matrix (Matrix A has `+e.length+` dimensions)`)}}function u(e,t,n){if(n===0)throw Error(`Cannot multiply two empty vectors`);return o(e,t)}function d(e,t){if(t.storage()!==`dense`)throw Error(`Support for SparseMatrix not implemented`);return f(e,t)}function f(e,n){var a=e._data,o=e._size,s=e._datatype||e.getDataType(),c=n._data,l=n._size,u=n._datatype||n.getDataType(),d=o[0],f=l[1],p,m=r,h=i;s&&u&&s===u&&typeof s==`string`&&s!==`mixed`&&(p=s,m=t.find(r,[p,p]),h=t.find(i,[p,p]));for(var g=[],_=0;_<f;_++){for(var v=h(a[0],c[0][_]),y=1;y<d;y++)v=m(v,h(a[y],c[y][_]));g[_]=v}return e.createDenseMatrix({data:g,size:[f],datatype:s===e._datatype&&u===n._datatype?p:void 0})}var p=t(`_multiplyMatrixVector`,{"DenseMatrix, any":h,"SparseMatrix, any":v}),m=t(`_multiplyMatrixMatrix`,{"DenseMatrix, DenseMatrix":g,"DenseMatrix, SparseMatrix":_,"SparseMatrix, DenseMatrix":y,"SparseMatrix, SparseMatrix":b});function h(e,n){var a=e._data,o=e._size,s=e._datatype||e.getDataType(),c=n._data,l=n._datatype||n.getDataType(),u=o[0],d=o[1],f,p=r,m=i;s&&l&&s===l&&typeof s==`string`&&s!==`mixed`&&(f=s,p=t.find(r,[f,f]),m=t.find(i,[f,f]));for(var h=[],g=0;g<u;g++){for(var _=a[g],v=m(_[0],c[0]),y=1;y<d;y++)v=p(v,m(_[y],c[y]));h[g]=v}return e.createDenseMatrix({data:h,size:[u],datatype:s===e._datatype&&l===n._datatype?f:void 0})}function g(e,n){var a=e._data,o=e._size,s=e._datatype||e.getDataType(),c=n._data,l=n._size,u=n._datatype||n.getDataType(),d=o[0],f=o[1],p=l[1],m,h=r,g=i;s&&u&&s===u&&typeof s==`string`&&s!==`mixed`&&s!==`mixed`&&(m=s,h=t.find(r,[m,m]),g=t.find(i,[m,m]));for(var _=[],v=0;v<d;v++){var y=a[v];_[v]=[];for(var b=0;b<p;b++){for(var x=g(y[0],c[0][b]),S=1;S<f;S++)x=h(x,g(y[S],c[S][b]));_[v][b]=x}}return e.createDenseMatrix({data:_,size:[d,p],datatype:s===e._datatype&&u===n._datatype?m:void 0})}function _(e,n){var o=e._data,s=e._size,c=e._datatype||e.getDataType(),l=n._values,u=n._index,d=n._ptr,f=n._size,p=n._datatype||n._data===void 0?n._datatype:n.getDataType();if(!l)throw Error(`Cannot multiply Dense Matrix times Pattern only Matrix`);var m=s[0],h=f[1],g,_=r,v=i,y=a,b=0;c&&p&&c===p&&typeof c==`string`&&c!==`mixed`&&(g=c,_=t.find(r,[g,g]),v=t.find(i,[g,g]),y=t.find(a,[g,g]),b=t.convert(0,g));for(var x=[],S=[],C=[],w=n.createSparseMatrix({values:x,index:S,ptr:C,size:[m,h],datatype:c===e._datatype&&p===n._datatype?g:void 0}),T=0;T<h;T++){C[T]=S.length;var E=d[T],D=d[T+1];if(D>E)for(var O=0,k=0;k<m;k++){for(var A=k+1,j=void 0,M=E;M<D;M++){var N=u[M];O===A?j=_(j,v(o[k][N],l[M])):(j=v(o[k][N],l[M]),O=A)}O===A&&!y(j,b)&&(S.push(k),x.push(j))}}return C[h]=S.length,w}function v(e,n){var o=e._values,s=e._index,c=e._ptr,l=e._datatype||e._data===void 0?e._datatype:e.getDataType();if(!o)throw Error(`Cannot multiply Pattern only Matrix times Dense Matrix`);var u=n._data,d=n._datatype||n.getDataType(),f=e._size[0],p=n._size[0],m=[],h=[],g=[],_,v=r,y=i,b=a,x=0;l&&d&&l===d&&typeof l==`string`&&l!==`mixed`&&(_=l,v=t.find(r,[_,_]),y=t.find(i,[_,_]),b=t.find(a,[_,_]),x=t.convert(0,_));var S=[],C=[];g[0]=0;for(var w=0;w<p;w++){var T=u[w];if(!b(T,x))for(var E=c[w],D=c[w+1],O=E;O<D;O++){var k=s[O];C[k]?S[k]=v(S[k],y(T,o[O])):(C[k]=!0,h.push(k),S[k]=y(T,o[O]))}}for(var A=h.length,j=0;j<A;j++)m[j]=S[h[j]];return g[1]=h.length,e.createSparseMatrix({values:m,index:h,ptr:g,size:[f,1],datatype:l===e._datatype&&d===n._datatype?_:void 0})}function y(e,n){var o=e._values,s=e._index,c=e._ptr,l=e._datatype||e._data===void 0?e._datatype:e.getDataType();if(!o)throw Error(`Cannot multiply Pattern only Matrix times Dense Matrix`);var u=n._data,d=n._datatype||n.getDataType(),f=e._size[0],p=n._size[0],m=n._size[1],h,g=r,_=i,v=a,y=0;l&&d&&l===d&&typeof l==`string`&&l!==`mixed`&&(h=l,g=t.find(r,[h,h]),_=t.find(i,[h,h]),v=t.find(a,[h,h]),y=t.convert(0,h));for(var b=[],x=[],S=[],C=e.createSparseMatrix({values:b,index:x,ptr:S,size:[f,m],datatype:l===e._datatype&&d===n._datatype?h:void 0}),w=[],T=[],E=0;E<m;E++){S[E]=x.length;for(var D=E+1,O=0;O<p;O++){var k=u[O][E];if(!v(k,y))for(var A=c[O],j=c[O+1],M=A;M<j;M++){var N=s[M];T[N]===D?w[N]=g(w[N],_(k,o[M])):(T[N]=D,x.push(N),w[N]=_(k,o[M]))}}for(var P=S[E],F=x.length,I=P;I<F;I++)b[I]=w[x[I]]}return S[m]=x.length,C}function b(e,n){var a=e._values,o=e._index,s=e._ptr,c=e._datatype||e._data===void 0?e._datatype:e.getDataType(),l=n._values,u=n._index,d=n._ptr,f=n._datatype||n._data===void 0?n._datatype:n.getDataType(),p=e._size[0],m=n._size[1],h=a&&l,g,_=r,v=i;c&&f&&c===f&&typeof c==`string`&&c!==`mixed`&&(g=c,_=t.find(r,[g,g]),v=t.find(i,[g,g]));for(var y=h?[]:void 0,b=[],x=[],S=e.createSparseMatrix({values:y,index:b,ptr:x,size:[p,m],datatype:c===e._datatype&&f===n._datatype?g:void 0}),C=h?[]:void 0,w=[],T,E,D,O,k,A,j,M,N=0;N<m;N++){x[N]=b.length;var P=N+1;for(k=d[N],A=d[N+1],O=k;O<A;O++)if(M=u[O],h)for(E=s[M],D=s[M+1],T=E;T<D;T++)j=o[T],w[j]===P?C[j]=_(C[j],v(l[O],a[T])):(w[j]=P,b.push(j),C[j]=v(l[O],a[T]));else for(E=s[M],D=s[M+1],T=E;T<D;T++)j=o[T],w[j]!==P&&(w[j]=P,b.push(j));if(h)for(var F=x[N],I=b.length,L=F;L<I;L++)y[L]=C[b[L]]}return x[m]=b.length,S}return t(Jf,i,{"Array, Array":t.referTo(`Matrix, Matrix`,e=>(t,r)=>{l(oc(t),oc(r));var i=e(n(t),n(r));return Fr(i)?i.valueOf():i}),"Matrix, Matrix":function(e,t){var n=e.size(),r=t.size();return l(n,r),n.length===1?r.length===1?u(e,t,n[0]):d(e,t):r.length===1?p(e,t):m(e,t)},"Matrix, Array":t.referTo(`Matrix,Matrix`,e=>(t,r)=>e(t,n(r))),"Array, Matrix":t.referToSelf(e=>(t,r)=>e(n(t,r.storage()),r)),"SparseMatrix, any":function(e,t){return s(e,t,i,!1)},"DenseMatrix, any":function(e,t){return c(e,t,i,!1)},"any, SparseMatrix":function(e,t){return s(t,e,i,!0)},"any, DenseMatrix":function(e,t){return c(t,e,i,!0)},"Array, any":function(e,t){return c(n(e),t,i,!1).valueOf()},"any, Array":function(e,t){return c(n(t),e,i,!0).valueOf()},"any, any":i,"any, any, ...any":t.referToSelf(e=>(t,n,r)=>{for(var i=e(t,n),a=0;a<r.length;a++)i=e(i,r[a]);return i})})}),Xf=`nthRoot`,Zf=J(Xf,[`typed`,`matrix`,`equalScalar`,`BigNumber`,`concat`],e=>{var{typed:t,matrix:n,equalScalar:r,BigNumber:i,concat:a}=e,o=Df({typed:t}),s=vf({typed:t,equalScalar:r}),c=Lf({typed:t,equalScalar:r}),l=Jd({typed:t,equalScalar:r}),u=wf({typed:t,matrix:n,concat:a});function d(){throw Error(`Complex number not supported in function nthRoot. Use nthRoots instead.`)}return t(Xf,{number:Tl,"number, number":Tl,BigNumber:e=>f(e,new i(2)),"BigNumber, BigNumber":f,Complex:d,"Complex, number":d,Array:t.referTo(`DenseMatrix,number`,e=>t=>e(n(t),2).valueOf()),DenseMatrix:t.referTo(`DenseMatrix,number`,e=>t=>e(t,2)),SparseMatrix:t.referTo(`SparseMatrix,number`,e=>t=>e(t,2)),"SparseMatrix, SparseMatrix":t.referToSelf(e=>(t,n)=>{if(n.density()===1)return c(t,n,e);throw Error(`Root must be non-zero`)}),"DenseMatrix, SparseMatrix":t.referToSelf(e=>(t,n)=>{if(n.density()===1)return o(t,n,e,!1);throw Error(`Root must be non-zero`)}),"Array, SparseMatrix":t.referTo(`DenseMatrix,SparseMatrix`,e=>(t,r)=>e(n(t),r)),"number | BigNumber, SparseMatrix":t.referToSelf(e=>(t,n)=>{if(n.density()===1)return l(n,t,e,!0);throw Error(`Root must be non-zero`)})},u({scalar:`number | BigNumber`,SD:s,Ss:l,sS:!1}));function f(e,t){var n=i.precision,r=i.clone({precision:n+2}),a=new i(0),o=new r(1),s=t.isNegative();if(s&&(t=t.neg()),t.isZero())throw Error(`Root must be non-zero`);if(e.isNegative()&&!t.abs().mod(2).equals(1))throw Error(`Root must be odd when a is negative.`);if(e.isZero())return s?new r(1/0):0;if(!e.isFinite())return s?a:e;var c=e.abs().pow(o.div(t));return c=e.isNeg()?c.neg():c,new i((s?o.div(c):c).toPrecision(n))}}),Qf=`sign`,$f=J(Qf,[`typed`,`BigNumber`,`Fraction`,`complex`],e=>{var{typed:t,BigNumber:n,complex:r,Fraction:i}=e;return t(Qf,{number:El,Complex:function(e){return e.im===0?r(El(e.re)):e.sign()},BigNumber:function(e){return new n(e.cmp(0))},bigint:function(e){return e>0n?1n:e<0n?-1n:0n},Fraction:function(e){return e.n===0n?new i(0):new i(e.s)},"Array | Matrix":t.referToSelf(e=>t=>$c(t,e,!0)),Unit:t.referToSelf(e=>n=>{if(!n._isDerived()&&n.units[0].unit.offset!==0)throw TypeError(`sign is ambiguous for units with offset`);return t.find(e,n.valueType())(n.value)})})}),ep=J(`sqrt`,[`config`,`typed`,`Complex`],e=>{var{config:t,typed:n,Complex:r}=e;return n(`sqrt`,{number:i,Complex:function(e){return e.sqrt()},BigNumber:function(e){return!e.isNegative()||t.predictable?e.sqrt():i(e.toNumber())},Unit:function(e){return e.pow(.5)}});function i(e){return isNaN(e)?NaN:e>=0||t.predictable?Math.sqrt(e):new r(e,0).sqrt()}}),tp=`square`,np=J(tp,[`typed`],e=>{var{typed:t}=e;return t(tp,{number:Ol,Complex:function(e){return e.mul(e)},BigNumber:function(e){return e.times(e)},bigint:function(e){return e*e},Fraction:function(e){return e.mul(e)},Unit:function(e){return e.pow(2)}})}),rp=`subtract`,ip=J(rp,[`typed`,`matrix`,`equalScalar`,`subtractScalar`,`unaryMinus`,`DenseMatrix`,`concat`],e=>{var{typed:t,matrix:n,equalScalar:r,subtractScalar:i,unaryMinus:a,DenseMatrix:o,concat:s}=e,c=Df({typed:t}),l=yf({typed:t}),u=bf({typed:t,equalScalar:r}),d=kf({typed:t,DenseMatrix:o}),f=Yd({typed:t,DenseMatrix:o}),p=wf({typed:t,matrix:n,concat:s});return t(rp,{"any, any":i},p({elop:i,SS:u,DS:c,SD:l,Ss:f,sS:d}))}),ap=`xgcd`,op=J(ap,[`typed`,`config`,`matrix`,`BigNumber`],e=>{var{typed:t,config:n,matrix:r,BigNumber:i}=e;return t(ap,{"number, number":function(e,t){var i=kl(e,t);return n.matrix===`Array`?i:r(i)},"BigNumber, BigNumber":a});function a(e,t){var a,o,s,c=new i(0),l=new i(1),u=c,d=l,f=l,p=c;if(!e.isInt()||!t.isInt())throw Error(`Parameters in function xgcd must be integer numbers`);for(;!t.isZero();)o=e.div(t).floor(),s=e.mod(t),a=u,u=d.minus(o.times(u)),d=a,a=f,f=p.minus(o.times(f)),p=a,e=t,t=s;var m=e.lt(c)?[e.neg(),d.neg(),p.neg()]:[e,e.isZero()?0:d,p];return n.matrix===`Array`?m:r(m)}}),sp=`invmod`,cp=J(sp,[`typed`,`config`,`BigNumber`,`xgcd`,`equal`,`smaller`,`mod`,`add`,`isInteger`],e=>{var{typed:t,config:n,BigNumber:r,xgcd:i,equal:a,smaller:o,mod:s,add:c,isInteger:l}=e;return t(sp,{"number, number":u,"BigNumber, BigNumber":u});function u(e,t){if(!l(e)||!l(t))throw Error(`Parameters in function invmod must be integer numbers`);if(e=s(e,t),a(t,0))throw Error(`Divisor must be non zero`);var n=i(e,t);n=n.valueOf();var[u,d]=n;return a(u,r(1))?(d=s(d,t),o(d,r(0))&&(d=c(d,t)),d):NaN}}),lp=J(`matAlgo09xS0Sf`,[`typed`,`equalScalar`],e=>{var{typed:t,equalScalar:n}=e;return function(e,r,i){var a=e._values,o=e._index,s=e._ptr,c=e._size,l=e._datatype||e._data===void 0?e._datatype:e.getDataType(),u=r._values,d=r._index,f=r._ptr,p=r._size,m=r._datatype||r._data===void 0?r._datatype:r.getDataType();if(c.length!==p.length)throw new ic(c.length,p.length);if(c[0]!==p[0]||c[1]!==p[1])throw RangeError(`Dimension mismatch. Matrix A (`+c+`) must match Matrix B (`+p+`)`);var h=c[0],g=c[1],_,v=n,y=0,b=i;typeof l==`string`&&l===m&&l!==`mixed`&&(_=l,v=t.find(n,[_,_]),y=t.convert(0,_),b=t.find(i,[_,_]));var x=a&&u?[]:void 0,S=[],C=[],w=x?[]:void 0,T=[],E,D,O,k,A;for(D=0;D<g;D++){C[D]=S.length;var j=D+1;if(w)for(k=f[D],A=f[D+1],O=k;O<A;O++)E=d[O],T[E]=j,w[E]=u[O];for(k=s[D],A=s[D+1],O=k;O<A;O++)if(E=o[O],w){var M=T[E]===j?w[E]:y,N=b(a[O],M);v(N,y)||(S.push(E),x.push(N))}else S.push(E)}return C[g]=S.length,e.createSparseMatrix({values:x,index:S,ptr:C,size:[h,g],datatype:l===e._datatype&&m===r._datatype?_:void 0})}}),up=`dotMultiply`,dp=J(up,[`typed`,`matrix`,`equalScalar`,`multiplyScalar`,`concat`],e=>{var{typed:t,matrix:n,equalScalar:r,multiplyScalar:i,concat:a}=e,o=vf({typed:t,equalScalar:r}),s=lp({typed:t,equalScalar:r}),c=Jd({typed:t,equalScalar:r});return t(up,wf({typed:t,matrix:n,concat:a})({elop:i,SS:s,DS:o,Ss:c}))});function fp(e,t){if(e.isFinite()&&!e.isInteger()||t.isFinite()&&!t.isInteger())throw Error(`Integers expected in function bitAnd`);var n=e.constructor;if(e.isNaN()||t.isNaN())return new n(NaN);if(e.isZero()||t.eq(-1)||e.eq(t))return e;if(t.isZero()||e.eq(-1))return t;if(!e.isFinite()||!t.isFinite()){if(!e.isFinite()&&!t.isFinite())return e.isNegative()===t.isNegative()?e:new n(0);if(!e.isFinite())return t.isNegative()?e:e.isNegative()?new n(0):t;if(!t.isFinite())return e.isNegative()?t:t.isNegative()?new n(0):e}return hp(e,t,function(e,t){return e&t})}function pp(e){if(e.isFinite()&&!e.isInteger())throw Error(`Integer expected in function bitNot`);var t=e.constructor,n=t.precision;t.config({precision:1e9});var r=e.plus(new t(1));return r.s=-r.s||null,t.config({precision:n}),r}function mp(e,t){if(e.isFinite()&&!e.isInteger()||t.isFinite()&&!t.isInteger())throw Error(`Integers expected in function bitOr`);var n=e.constructor;if(e.isNaN()||t.isNaN())return new n(NaN);var r=new n(-1);return e.isZero()||t.eq(r)||e.eq(t)?t:t.isZero()||e.eq(r)?e:!e.isFinite()||!t.isFinite()?!e.isFinite()&&!e.isNegative()&&t.isNegative()||e.isNegative()&&!t.isNegative()&&!t.isFinite()?r:e.isNegative()&&t.isNegative()?e.isFinite()?e:t:e.isFinite()?t:e:hp(e,t,function(e,t){return e|t})}function hp(e,t,n){var r=e.constructor,i,a,o=+(e.s<0),s=+(t.s<0);if(o){i=gp(pp(e));for(var c=0;c<i.length;++c)i[c]^=1}else i=gp(e);if(s){a=gp(pp(t));for(var l=0;l<a.length;++l)a[l]^=1}else a=gp(t);var u,d,f;i.length<=a.length?(u=i,d=a,f=o):(u=a,d=i,f=s);var p=u.length,m=d.length,h=n(o,s)^1,g=new r(h^1),_=new r(1),v=new r(2),y=r.precision;for(r.config({precision:1e9});p>0;)n(u[--p],d[--m])===h&&(g=g.plus(_)),_=_.times(v);for(;m>0;)n(f,d[--m])===h&&(g=g.plus(_)),_=_.times(v);return r.config({precision:y}),h===0&&(g.s=-g.s),g}function gp(e){for(var t=e.d,n=t[0]+``,r=1;r<t.length;++r){for(var i=t[r]+``,a=7-i.length;a--;)i=`0`+i;n+=i}for(var o=n.length;n.charAt(o)===`0`;)o--;var s=e.e,c=n.slice(0,o+1||1),l=c.length;if(s>0)if(++s>l)for(s-=l;s--;)c+=`0`;else s<l&&(c=c.slice(0,s)+`.`+c.slice(s));for(var u=[0],d=0;d<c.length;){for(var f=u.length;f--;)u[f]*=10;u[0]+=parseInt(c.charAt(d++));for(var p=0;p<u.length;++p)u[p]>1&&((u[p+1]===null||u[p+1]===void 0)&&(u[p+1]=0),u[p+1]+=u[p]>>1,u[p]&=1)}return u.reverse()}function _p(e,t){if(e.isFinite()&&!e.isInteger()||t.isFinite()&&!t.isInteger())throw Error(`Integers expected in function bitXor`);var n=e.constructor;if(e.isNaN()||t.isNaN())return new n(NaN);if(e.isZero())return t;if(t.isZero())return e;if(e.eq(t))return new n(0);var r=new n(-1);return e.eq(r)?pp(t):t.eq(r)?pp(e):!e.isFinite()||!t.isFinite()?!e.isFinite()&&!t.isFinite()?r:new n(e.isNegative()===t.isNegative()?1/0:-1/0):hp(e,t,function(e,t){return e^t})}function vp(e,t){if(e.isFinite()&&!e.isInteger()||t.isFinite()&&!t.isInteger())throw Error(`Integers expected in function leftShift`);var n=e.constructor;return e.isNaN()||t.isNaN()||t.isNegative()&&!t.isZero()?new n(NaN):e.isZero()||t.isZero()?e:!e.isFinite()&&!t.isFinite()?new n(NaN):t.lt(55)?e.times(2**t.toNumber()+``):e.times(new n(2).pow(t))}function yp(e,t){if(e.isFinite()&&!e.isInteger()||t.isFinite()&&!t.isInteger())throw Error(`Integers expected in function rightArithShift`);var n=e.constructor;return e.isNaN()||t.isNaN()||t.isNegative()&&!t.isZero()?new n(NaN):e.isZero()||t.isZero()?e:t.isFinite()?t.lt(55)?e.div(2**t.toNumber()+``).floor():e.div(new n(2).pow(t)).floor():e.isNegative()?new n(-1):e.isFinite()?new n(0):new n(NaN)}var bp=`bitAnd`,xp=J(bp,[`typed`,`matrix`,`equalScalar`,`concat`],e=>{var{typed:t,matrix:n,equalScalar:r,concat:i}=e,a=vf({typed:t,equalScalar:r}),o=Lf({typed:t,equalScalar:r}),s=Jd({typed:t,equalScalar:r}),c=wf({typed:t,matrix:n,concat:i});return t(bp,{"number, number":Fl,"BigNumber, BigNumber":fp,"bigint, bigint":(e,t)=>e&t},c({SS:o,DS:a,Ss:s}))}),Sp=`bitNot`,Cp=J(Sp,[`typed`],e=>{var{typed:t}=e;return t(Sp,{number:Il,BigNumber:pp,bigint:e=>~e,"Array | Matrix":t.referToSelf(e=>t=>$c(t,e))})}),wp=`bitOr`,Tp=J(wp,[`typed`,`matrix`,`equalScalar`,`DenseMatrix`,`concat`],e=>{var{typed:t,matrix:n,equalScalar:r,DenseMatrix:i,concat:a}=e,o=Df({typed:t}),s=Of({typed:t,equalScalar:r}),c=kf({typed:t,DenseMatrix:i}),l=wf({typed:t,matrix:n,concat:a});return t(wp,{"number, number":Ll,"BigNumber, BigNumber":mp,"bigint, bigint":(e,t)=>e|t},l({SS:s,DS:o,Ss:c}))}),Ep=J(`matAlgo07xSSf`,[`typed`,`SparseMatrix`],e=>{var{typed:t,SparseMatrix:n}=e;return function(e,i,a){var o=e._size,s=e._datatype||e._data===void 0?e._datatype:e.getDataType(),c=i._size,l=i._datatype||i._data===void 0?i._datatype:i.getDataType();if(o.length!==c.length)throw new ic(o.length,c.length);if(o[0]!==c[0]||o[1]!==c[1])throw RangeError(`Dimension mismatch. Matrix A (`+o+`) must match Matrix B (`+c+`)`);var u=o[0],d=o[1],f,p=0,m=a;typeof s==`string`&&s===l&&s!==`mixed`&&(f=s,p=t.convert(0,f),m=t.find(a,[f,f]));for(var h=[],g=[],_=Array(d+1).fill(0),v=[],y=[],b=[],x=[],S=0;S<d;S++){var C=S+1,w=0;r(e,S,b,v,C),r(i,S,x,y,C);for(var T=0;T<u;T++){var E=b[T]===C?v[T]:p,D=x[T]===C?y[T]:p,O=m(E,D);O!==0&&O!==!1&&(g.push(T),h.push(O),w++)}_[S+1]=_[S]+w}return new n({values:h,index:g,ptr:_,size:[u,d],datatype:s===e._datatype&&l===i._datatype?f:void 0})};function r(e,t,n,r,i){for(var a=e._values,o=e._index,s=e._ptr,c=s[t],l=s[t+1];c<l;c++){var u=o[c];n[u]=i,r[u]=a[c]}}}),Dp=`bitXor`,Op=J(Dp,[`typed`,`matrix`,`DenseMatrix`,`concat`,`SparseMatrix`],e=>{var{typed:t,matrix:n,DenseMatrix:r,concat:i,SparseMatrix:a}=e,o=yf({typed:t}),s=Ep({typed:t,SparseMatrix:a}),c=Yd({typed:t,DenseMatrix:r}),l=wf({typed:t,matrix:n,concat:i});return t(Dp,{"number, number":Rl,"BigNumber, BigNumber":_p,"bigint, bigint":(e,t)=>e^t},l({SS:s,DS:o,Ss:c}))}),kp=`arg`,Ap=J(kp,[`typed`],e=>{var{typed:t}=e;return t(kp,{number:function(e){return Math.atan2(0,e)},BigNumber:function(e){return e.constructor.atan2(0,e)},Complex:function(e){return e.arg()},"Array | Matrix":t.referToSelf(e=>t=>$c(t,e))})}),jp=`conj`,Mp=J(jp,[`typed`],e=>{var{typed:t}=e;return t(jp,{"number | BigNumber | Fraction":e=>e,Complex:e=>e.conjugate(),Unit:t.referToSelf(e=>t=>new t.constructor(e(t.toNumeric()),t.formatUnits())),"Array | Matrix":t.referToSelf(e=>t=>$c(t,e))})}),Np=`im`,Pp=J(Np,[`typed`],e=>{var{typed:t}=e;return t(Np,{number:()=>0,"BigNumber | Fraction":e=>e.mul(0),Complex:e=>e.im,"Array | Matrix":t.referToSelf(e=>t=>$c(t,e))})}),Fp=`re`,Ip=J(Fp,[`typed`],e=>{var{typed:t}=e;return t(Fp,{"number | BigNumber | Fraction":e=>e,Complex:e=>e.re,"Array | Matrix":t.referToSelf(e=>t=>$c(t,e))})}),Lp=`not`,Rp=J(Lp,[`typed`],e=>{var{typed:t}=e;return t(Lp,{"null | undefined":()=>!0,number:Xl,Complex:function(e){return e.re===0&&e.im===0},BigNumber:function(e){return e.isZero()||e.isNaN()},bigint:e=>!e,Unit:t.referToSelf(e=>n=>t.find(e,n.valueType())(n.value)),"Array | Matrix":t.referToSelf(e=>t=>$c(t,e))})}),zp=`nullish`,Bp=J(zp,[`typed`,`matrix`,`size`,`flatten`,`deepEqual`],e=>{var{typed:t,matrix:n,size:r,flatten:i,deepEqual:a}=e,o=yf({typed:t}),s=Xd({typed:t}),c=xf({typed:t});return t(zp,{"number|bigint|Complex|BigNumber|Fraction|Unit|string|boolean|SparseMatrix, any":(e,t)=>e,"null, any":(e,t)=>t,"undefined, any":(e,t)=>t,"SparseMatrix, Array | Matrix":(e,t)=>{var n=r(e),i=r(t);if(a(n,i))return e;throw new ic(n,i)},"DenseMatrix, DenseMatrix":t.referToSelf(e=>(t,n)=>c(t,n,e)),"DenseMatrix, SparseMatrix":t.referToSelf(e=>(t,n)=>o(t,n,e,!1)),"DenseMatrix, Array":t.referToSelf(e=>(t,r)=>c(t,n(r),e)),"DenseMatrix, any":t.referToSelf(e=>(t,n)=>s(t,n,e,!1)),"Array, Array":t.referToSelf(e=>(t,r)=>c(n(t),n(r),e).valueOf()),"Array, DenseMatrix":t.referToSelf(e=>(t,r)=>c(n(t),r,e)),"Array, SparseMatrix":t.referToSelf(e=>(t,r)=>o(n(t),r,e,!1)),"Array, any":t.referToSelf(e=>(t,r)=>s(n(t),r,e,!1).valueOf())})}),Vp=`or`,Hp=J(Vp,[`typed`,`matrix`,`equalScalar`,`DenseMatrix`,`concat`],e=>{var{typed:t,matrix:n,equalScalar:r,DenseMatrix:i,concat:a}=e,o=yf({typed:t}),s=bf({typed:t,equalScalar:r}),c=Yd({typed:t,DenseMatrix:i}),l=wf({typed:t,matrix:n,concat:a});return t(Vp,{"number, number":Zl,"Complex, Complex":function(e,t){return e.re!==0||e.im!==0||t.re!==0||t.im!==0},"BigNumber, BigNumber":function(e,t){return!e.isZero()&&!e.isNaN()||!t.isZero()&&!t.isNaN()},"bigint, bigint":Zl,"Unit, Unit":t.referToSelf(e=>(t,n)=>e(t.value||0,n.value||0))},l({SS:s,DS:o,Ss:c}))}),Up=`xor`,Wp=J(Up,[`typed`,`matrix`,`DenseMatrix`,`concat`,`SparseMatrix`],e=>{var{typed:t,matrix:n,DenseMatrix:r,concat:i,SparseMatrix:a}=e,o=yf({typed:t}),s=Ep({typed:t,SparseMatrix:a}),c=Yd({typed:t,DenseMatrix:r}),l=wf({typed:t,matrix:n,concat:i});return t(Up,{"number, number":Ql,"Complex, Complex":function(e,t){return(e.re!==0||e.im!==0)!=(t.re!==0||t.im!==0)},"bigint, bigint":Ql,"BigNumber, BigNumber":function(e,t){return(!e.isZero()&&!e.isNaN())!=(!t.isZero()&&!t.isNaN())},"Unit, Unit":t.referToSelf(e=>(t,n)=>e(t.value||0,n.value||0))},l({SS:s,DS:o,Ss:c}))}),Gp=`concat`,Kp=J(Gp,[`typed`,`matrix`,`isInteger`],e=>{var{typed:t,matrix:n,isInteger:r}=e;return t(Gp,{"...Array | Matrix | number | BigNumber":function(e){var t,i=e.length,a=-1,o,s=!1,c=[];for(t=0;t<i;t++){var l=e[t];if(Fr(l)&&(s=!0),Dr(l)||Or(l)){if(t!==i-1)throw Error(`Dimension must be specified as last argument`);if(o=a,a=l.valueOf(),!r(a))throw TypeError(`Integer number expected for dimension`);if(a<0||t>0&&a>o)throw new ac(a,o+1)}else{var u=vi(l).valueOf(),d=oc(u);if(c[t]=u,o=a,a=d.length-1,t>0&&a!==o)throw new ic(o+1,a+1)}}if(c.length===0)throw SyntaxError(`At least one matrix expected`);for(var f=c.shift();c.length;)f=Mc(f,c.shift(),a);return s?n(f):f},"...string":function(e){return e.join(``)}})}),qp=`column`,Jp=J(qp,[`typed`,`Index`,`matrix`,`range`],e=>{var{typed:t,Index:n,matrix:r,range:i}=e;return t(qp,{"Matrix, number":a,"Array, number":function(e,t){return a(r(vi(e)),t).valueOf()}});function a(e,t){if(e.size().length!==2)throw Error(`Only two dimensional matrix is supported`);uc(t,e.size()[1]);var a=new n(i(0,e.size()[0]),[t]),o=e.subset(a);return Fr(o)?o:r([[o]])}}),Yp=`count`,Xp=J(Yp,[`typed`,`size`,`prod`],e=>{var{typed:t,size:n,prod:r}=e;return t(Yp,{string:function(e){return e.length},"Matrix | Array":function(e){return r(n(e))}})}),Zp=`cross`,Qp=J(Zp,[`typed`,`matrix`,`subtract`,`multiply`],e=>{var{typed:t,matrix:n,subtract:r,multiply:i}=e;return t(Zp,{"Matrix, Matrix":function(e,t){return n(a(e.toArray(),t.toArray()))},"Matrix, Array":function(e,t){return n(a(e.toArray(),t))},"Array, Matrix":function(e,t){return n(a(e,t.toArray()))},"Array, Array":a});function a(e,t){var n=Math.max(oc(e).length,oc(t).length);e=vc(e),t=vc(t);var a=oc(e),o=oc(t);if(a.length!==1||o.length!==1||a[0]!==3||o[0]!==3)throw RangeError(`Vectors with length 3 expected (Size A = [`+a.join(`, `)+`], B = [`+o.join(`, `)+`])`);var s=[r(i(e[1],t[2]),i(e[2],t[1])),r(i(e[2],t[0]),i(e[0],t[2])),r(i(e[0],t[1]),i(e[1],t[0]))];return n>1?[s]:s}}),$p=`diag`,em=J($p,[`typed`,`matrix`,`DenseMatrix`,`SparseMatrix`],e=>{var{typed:t,matrix:n,DenseMatrix:r,SparseMatrix:i}=e;return t($p,{Array:function(e){return a(e,0,oc(e),null)},"Array, number":function(e,t){return a(e,t,oc(e),null)},"Array, BigNumber":function(e,t){return a(e,t.toNumber(),oc(e),null)},"Array, string":function(e,t){return a(e,0,oc(e),t)},"Array, number, string":function(e,t,n){return a(e,t,oc(e),n)},"Array, BigNumber, string":function(e,t,n){return a(e,t.toNumber(),oc(e),n)},Matrix:function(e){return a(e,0,e.size(),e.storage())},"Matrix, number":function(e,t){return a(e,t,e.size(),e.storage())},"Matrix, BigNumber":function(e,t){return a(e,t.toNumber(),e.size(),e.storage())},"Matrix, string":function(e,t){return a(e,0,e.size(),t)},"Matrix, number, string":function(e,t,n){return a(e,t,e.size(),n)},"Matrix, BigNumber, string":function(e,t,n){return a(e,t.toNumber(),e.size(),n)}});function a(e,t,n,r){if(!Ri(t))throw TypeError(`Second parameter in function diag must be an integer`);var i=t>0?t:0,a=t<0?-t:0;switch(n.length){case 1:return o(e,t,r,n[0],a,i);case 2:return s(e,t,r,n,a,i)}throw RangeError(`Matrix for function diag must be 2 dimensional`)}function o(e,t,n,a,o,s){var c=[a+o,a+s];if(n&&n!==`sparse`&&n!==`dense`)throw TypeError(`Unknown matrix type ${n}"`);var l=n===`sparse`?i.diagonal(c,e,t):r.diagonal(c,e,t);return n===null?l.valueOf():l}function s(e,t,r,i,a,o){if(Fr(e)){var s=e.diagonal(t);return r===null?s.valueOf():r===s.storage()?s:n(s,r)}for(var c=Math.min(i[0]-a,i[1]-o),l=[],u=0;u<c;u++)l[u]=e[u+a][u+o];return r===null?l:n(l)}}),tm=J(`filter`,[`typed`],e=>{var{typed:t}=e;return t(`filter`,{"Array, function":nm,"Matrix, function":function(e,t){return e.create(nm(e.valueOf(),t),e.datatype())},"Array, RegExp":Ec,"Matrix, RegExp":function(e,t){return e.create(Ec(e.valueOf(),t),e.datatype())}})});function nm(e,t){var n=Vc(t,e,`filter`);return n.isUnary?Tc(e,n.fn):Tc(e,function(e,t,r){return n.fn(e,[t],r)})}var rm=`flatten`,im=J(rm,[`typed`],e=>{var{typed:t}=e;return t(rm,{Array:function(e){return Sc(e)},DenseMatrix:function(e){return e.create(Sc(e.valueOf(),!0),e.datatype())},SparseMatrix:function(e){throw TypeError(`SparseMatrix is not supported by function flatten because it does not support 1D vectors. Convert to a DenseMatrix or Array first. Example: flatten(x.toArray())`)}})}),am=`forEach`,om=J(am,[`typed`],e=>{var{typed:t}=e;return t(am,{"Array, function":sm,"Matrix, function":function(e,t){e.forEach(t)}})});function sm(e,t){var n=Vc(t,e,am);zc(e,n.fn,n.isUnary)}var cm=`getMatrixDataType`,lm=J(cm,[`typed`],e=>{var{typed:t}=e;return t(cm,{Array:function(e){return Ac(e,_i)},Matrix:function(e){return e.getDataType()}})}),um=`identity`,dm=J(um,[`typed`,`config`,`matrix`,`BigNumber`,`DenseMatrix`,`SparseMatrix`],e=>{var{typed:t,config:n,matrix:r,BigNumber:i,DenseMatrix:a,SparseMatrix:o}=e;return t(um,{"":function(){return n.matrix===`Matrix`?r([]):[]},string:function(e){return r(e)},"number | BigNumber":function(e){return c(e,e,n.matrix===`Matrix`?`dense`:void 0)},"number | BigNumber, string":function(e,t){return c(e,e,t)},"number | BigNumber, number | BigNumber":function(e,t){return c(e,t,n.matrix===`Matrix`?`dense`:void 0)},"number | BigNumber, number | BigNumber, string":function(e,t,n){return c(e,t,n)},Array:function(e){return s(e)},"Array, string":function(e,t){return s(e,t)},Matrix:function(e){return s(e.valueOf(),e.storage())},"Matrix, string":function(e,t){return s(e.valueOf(),t)}});function s(e,t){switch(e.length){case 0:return t?r(t):[];case 1:return c(e[0],e[0],t);case 2:return c(e[0],e[1],t);default:throw Error(`Vector containing two values expected`)}}function c(e,t,n){var r=Or(e)||Or(t)?i:null;if(Or(e)&&(e=e.toNumber()),Or(t)&&(t=t.toNumber()),!Ri(e)||e<1||!Ri(t)||t<1)throw Error(`Parameters in function identity must be positive integers`);var s=r?new i(1):1,c=r?new r(0):0,l=[e,t];if(n){if(n===`sparse`)return o.diagonal(l,s,0,c);if(n===`dense`)return a.diagonal(l,s,0,c);throw TypeError(`Unknown matrix type "${n}"`)}for(var u=fc([],l,c),d=e<t?e:t,f=0;f<d;f++)u[f][f]=s;return u}}),fm=`kron`,pm=J(fm,[`typed`,`matrix`,`multiplyScalar`],e=>{var{typed:t,matrix:n,multiplyScalar:r}=e;return t(fm,{"Matrix, Matrix":function(e,t){return n(a(e.toArray(),t.toArray()))},"Matrix, Array":function(e,t){return n(a(e.toArray(),t))},"Array, Matrix":function(e,t){return n(a(e,t.toArray()))},"Array, Array":a});function i(e,t){return e.flatMap(e=>t.map(t=>r(e,t)))}function a(e,t){var n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:-1;if(n<0){var r=oc(e).length,o=oc(t).length;for(n=Math.max(r,o);r++<n;)e=[e];for(;o++<n;)t=[t]}return n===1?i(e,t):e.flatMap(e=>t.map(t=>a(e,t,n-1)))}}),mm=`map`,hm=J(mm,[`typed`],e=>{var{typed:t}=e;return t(mm,{"Array, function":s,"Matrix, function":function(e,t){return e.map(t)},"Array|Matrix, Array|Matrix, ...Array|Matrix|function":(e,t,r)=>n([e,t,...r.slice(0,r.length-1)],r[r.length-1])});function n(e,n){if(typeof n!=`function`)throw Error(`Last argument must be a callback function`);var c=e[0].isMatrix,l=e.map(e=>e.isMatrix?e.size():oc(e)),u=Nc(...l),d=e.length,f=c?(e,t)=>e.get(t):Lc,p=e.map((e,t)=>{var n=l[t].map(()=>0);return e.isMatrix?e.get(n):Lc(e,n)}),m=t.isTypedFunction(n)?o(n,p,u.map(()=>0),e):a(n,d);if(m<2)return r(e,i(m,n,null));var h=c?e.map(t=>t.isMatrix?t.create(Fc(t.toArray(),u),t.datatype()):e[0].create(Fc(t.valueOf(),u))):e.map(e=>e.isMatrix?Fc(e.toArray(),u):Fc(e,u)),g=i(m,n,h),_=(e,t)=>g([e,...h.slice(1).map(e=>f(e,t))],t);return c?h[0].map(_):s(h[0],_)}function r(e,t){var n=e[0],r=e.map(e=>e.isMatrix?e.valueOf():e),i=e.map(e=>e.isMatrix?e.size():oc(e)),a=Nc(...i),o=i.map(e=>a.length-e.length),s=a.length-1,c=t.length>1?[]:null,l=d(r,0);if(n.isMatrix){var u=n.create();return u._data=l,u._size=a,u}else return l;function d(e){var n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,r=a[n],i=Array(r);if(n<s)for(var l=function(t){c&&(c[n]=t),i[t]=d(e.map((e,r)=>o[r]>n?e:e.length===1?e[0]:e[t]),n+1)},u=0;u<r;u++)l(u);else for(var f=function(r){c&&(c[n]=r),i[r]=t(e.map(e=>e.length===1?e[0]:e[r]),c?c.slice():void 0)},p=0;p<r;p++)f(p);return i}}function i(e,t,n){switch(e){case 0:return e=>t(...e);case 1:return(e,n)=>t(...e,n);case 2:return(e,r)=>t(...e,r,...n)}}function a(e,t){var n=e.toString();if(/arguments/.test(n))return 2;var r=n.match(/\(.*?\)/);return/\.\.\./.test(r)||e.length>t+1?2:+(e.length===t+1)}function o(e,n,r,i){return t.resolve(e,[...n,r,...i])===null?t.resolve(e,[...n,r])===null?(t.resolve(e,n),0):1:2}function s(e,t){var n=Vc(t,e,mm);return Rc(e,n.fn,n.isUnary)}}),gm=`diff`,_m=J(gm,[`typed`,`matrix`,`subtract`,`number`],e=>{var{typed:t,matrix:n,subtract:r,number:i}=e;return t(gm,{"Array | Matrix":function(e){return Fr(e)?n(o(e.toArray())):o(e)},"Array | Matrix, number":function(e,t){if(!Ri(t))throw RangeError(`Dimension must be a whole number`);return Fr(e)?n(a(e.toArray(),t)):a(e,t)},"Array, BigNumber":t.referTo(`Array,number`,e=>(t,n)=>e(t,i(n))),"Matrix, BigNumber":t.referTo(`Matrix,number`,e=>(t,n)=>e(t,i(n)))});function a(e,t){if(Fr(e)&&(e=e.toArray()),!Array.isArray(e))throw RangeError(`Array/Matrix does not have that many dimensions`);if(t>0){var n=[];return e.forEach(e=>{n.push(a(e,t-1))}),n}else if(t===0)return o(e);else throw RangeError(`Cannot have negative dimension`)}function o(e){for(var t=[],n=e.length,r=1;r<n;r++)t.push(s(e[r-1],e[r]));return t}function s(e,t){Fr(e)&&(e=e.toArray()),Fr(t)&&(t=t.toArray());var n=Array.isArray(e),i=Array.isArray(t);if(n&&i)return c(e,t);if(!n&&!i)return r(t,e);throw TypeError(`Cannot calculate difference between 1 array and 1 non-array`)}function c(e,t){if(e.length!==t.length)throw RangeError(`Not all sub-arrays have the same length`);for(var n=[],r=e.length,i=0;i<r;i++)n.push(s(e[i],t[i]));return n}}),vm=J(`ones`,[`typed`,`config`,`matrix`,`BigNumber`],e=>{var{typed:t,config:n,matrix:r,BigNumber:i}=e;return t(`ones`,{"":function(){return n.matrix===`Array`?a([]):a([],`default`)},"...number | BigNumber | string":function(e){return typeof e[e.length-1]==`string`?a(e,e.pop()):n.matrix===`Array`?a(e):a(e,`default`)},Array:a,Matrix:function(e){var t=e.storage();return a(e.valueOf(),t)},"Array | Matrix, string":function(e,t){return a(e.valueOf(),t)}});function a(e,t){var n=o(e)?new i(1):1;if(s(e),t){var a=r(t);return e.length>0?a.resize(e,n):a}else{var c=[];return e.length>0?fc(c,e,n):c}}function o(e){var t=!1;return e.forEach(function(e,n,r){Or(e)&&(t=!0,r[n]=e.toNumber())}),t}function s(e){e.forEach(function(e){if(typeof e!=`number`||!Ri(e)||e<0)throw Error(`Parameters in function ones must be positive integers`)})}});function ym(){throw Error(`No "bignumber" implementation available`)}function bm(){throw Error(`No "fraction" implementation available`)}function xm(){throw Error(`No "matrix" implementation available`)}var Sm=`range`,Cm=J(Sm,[`typed`,`config`,`?matrix`,`?bignumber`,`equal`,`smaller`,`smallerEq`,`larger`,`largerEq`,`add`,`isZero`,`isPositive`],e=>{var{typed:t,config:n,matrix:r,bignumber:i,smaller:a,smallerEq:o,larger:s,largerEq:c,add:l,isZero:u,isPositive:d}=e;return t(Sm,{string:p,"string, boolean":p,number:function(e){throw TypeError(`Too few arguments to function range(): ${e}`)},boolean:function(e){throw TypeError(`Unexpected type of argument 1 to function range(): ${e}, number|bigint|BigNumber|Fraction`)},"number, number":function(e,t){return f(m(e,t,1,!1))},"number, number, number":function(e,t,n){return f(m(e,t,n,!1))},"number, number, boolean":function(e,t,n){return f(m(e,t,1,n))},"number, number, number, boolean":function(e,t,n,r){return f(m(e,t,n,r))},"bigint, bigint|number":function(e,t){return f(m(e,t,1n,!1))},"number, bigint":function(e,t){return f(m(BigInt(e),t,1n,!1))},"bigint, bigint|number, bigint|number":function(e,t,n){return f(m(e,t,BigInt(n),!1))},"number, bigint, bigint|number":function(e,t,n){return f(m(BigInt(e),t,BigInt(n),!1))},"bigint, bigint|number, boolean":function(e,t,n){return f(m(e,t,1n,n))},"number, bigint, boolean":function(e,t,n){return f(m(BigInt(e),t,1n,n))},"bigint, bigint|number, bigint|number, boolean":function(e,t,n,r){return f(m(e,t,BigInt(n),r))},"number, bigint, bigint|number, boolean":function(e,t,n,r){return f(m(BigInt(e),t,BigInt(n),r))},"BigNumber, BigNumber":function(e,t){var n=e.constructor;return f(m(e,t,new n(1),!1))},"BigNumber, BigNumber, BigNumber":function(e,t,n){return f(m(e,t,n,!1))},"BigNumber, BigNumber, boolean":function(e,t,n){var r=e.constructor;return f(m(e,t,new r(1),n))},"BigNumber, BigNumber, BigNumber, boolean":function(e,t,n,r){return f(m(e,t,n,r))},"Fraction, Fraction":function(e,t){return f(m(e,t,1,!1))},"Fraction, Fraction, Fraction":function(e,t,n){return f(m(e,t,n,!1))},"Fraction, Fraction, boolean":function(e,t,n){return f(m(e,t,1,n))},"Fraction, Fraction, Fraction, boolean":function(e,t,n,r){return f(m(e,t,n,r))},"Unit, Unit, Unit":function(e,t,n){return f(m(e,t,n,!1))},"Unit, Unit, Unit, boolean":function(e,t,n,r){return f(m(e,t,n,r))}});function f(e){return n.matrix===`Matrix`?r?r(e):xm():e}function p(e,t){var r=h(e);if(!r)throw SyntaxError(`String "`+e+`" is no valid range`);return n.number===`BigNumber`?(i===void 0&&ym(),f(m(i(r.start),i(r.end),i(r.step)),t)):f(m(r.start,r.end,r.step,t))}function m(e,t,n,r){var i=[];if(u(n))throw Error(`Step must be non-zero`);for(var f=d(n)?r?o:a:r?c:s,p=e;f(p,t);)i.push(p),p=l(p,n);return i}function h(e){var t=e.split(`:`).map(function(e){return Number(e)});if(t.some(function(e){return isNaN(e)}))return null;switch(t.length){case 2:return{start:t[0],end:t[1],step:1};case 3:return{start:t[0],end:t[2],step:t[1]};default:return null}}}),wm=`reshape`,Tm=J(wm,[`typed`,`isInteger`,`matrix`],e=>{var{typed:t,isInteger:n}=e;return t(wm,{"Matrix, Array":function(e,t){return e.reshape(t,!0)},"Array, Array":function(e,t){return t.forEach(function(e){if(!n(e))throw TypeError(`Invalid size for dimension: `+e)}),mc(e,t)}})}),Em=J(`resize`,[`config`,`matrix`],e=>{var{config:t,matrix:n}=e;return function(e,i,a){if(arguments.length!==2&&arguments.length!==3)throw new Af(`resize`,arguments.length,2,3);if(Fr(i)&&(i=i.valueOf()),Or(i[0])&&(i=i.map(function(e){return Or(e)?e.toNumber():e})),Fr(e))return e.resize(i,a,!0);if(typeof e==`string`)return r(e,i,a);var o=Array.isArray(e)?!1:t.matrix!==`Array`;if(i.length===0){for(;Array.isArray(e);)e=e[0];return vi(e)}else{Array.isArray(e)||(e=[e]),e=vi(e);var s=fc(e,i,a);return o?n(s):s}};function r(e,t,n){if(n!==void 0){if(typeof n!=`string`||n.length!==1)throw TypeError(`Single character expected as defaultValue`)}else n=` `;if(t.length!==1)throw new ic(t.length,1);var r=t[0];if(typeof r!=`number`||!Ri(r))throw TypeError(`Invalid size, must contain positive integers (size: `+Xs(t)+`)`);if(e.length>r)return e.substring(0,r);if(e.length<r){for(var i=e,a=0,o=r-e.length;a<o;a++)i+=n;return i}else return e}}),Dm=`rotate`,Om=J(Dm,[`typed`,`multiply`,`rotationMatrix`],e=>{var{typed:t,multiply:n,rotationMatrix:r}=e;return t(Dm,{"Array , number | BigNumber | Complex | Unit":function(e,t){return i(e,2),n(r(t),e).toArray()},"Matrix , number | BigNumber | Complex | Unit":function(e,t){return i(e,2),n(r(t),e)},"Array, number | BigNumber | Complex | Unit, Array | Matrix":function(e,t,a){return i(e,3),n(r(t,a),e)},"Matrix, number | BigNumber | Complex | Unit, Array | Matrix":function(e,t,a){return i(e,3),n(r(t,a),e)}});function i(e,t){var n=Array.isArray(e)?oc(e):e.size();if(n.length>2||n.length===2&&n[1]!==1||n[0]!==t)throw RangeError(`Vector must be of dimensions 1x${t}`)}}),km=`rotationMatrix`,Am=J(km,[`typed`,`config`,`multiplyScalar`,`addScalar`,`unaryMinus`,`norm`,`matrix`,`BigNumber`,`DenseMatrix`,`SparseMatrix`,`cos`,`sin`],e=>{var{typed:t,config:n,multiplyScalar:r,addScalar:i,unaryMinus:a,norm:o,BigNumber:s,matrix:c,DenseMatrix:l,SparseMatrix:u,cos:d,sin:f}=e;return t(km,{"":function(){return n.matrix===`Matrix`?c([]):[]},string:function(e){return c(e)},"number | BigNumber | Complex | Unit":function(e){return p(e,n.matrix===`Matrix`?`dense`:void 0)},"number | BigNumber | Complex | Unit, string":function(e,t){return p(e,t)},"number | BigNumber | Complex | Unit, Array":function(e,t){var n=c(t);return m(n),_(e,n,void 0)},"number | BigNumber | Complex | Unit, Matrix":function(e,t){return m(t),_(e,t,t.storage()||(n.matrix===`Matrix`?`dense`:void 0))},"number | BigNumber | Complex | Unit, Array, string":function(e,t,n){var r=c(t);return m(r),_(e,r,n)},"number | BigNumber | Complex | Unit, Matrix, string":function(e,t,n){return m(t),_(e,t,n)}});function p(e,t){var n=Or(e)?new s(-1):-1,i=d(e),a=f(e);return g([[i,r(n,a)],[a,i]],t)}function m(e){var t=e.size();if(t.length<1||t[0]!==3)throw RangeError(`Vector must be of dimensions 1x3`)}function h(e){return e.reduce((e,t)=>r(e,t))}function g(e,t){if(t){if(t===`sparse`)return new u(e);if(t===`dense`)return new l(e);throw TypeError(`Unknown matrix type "${t}"`)}return e}function _(e,t,n){var r=o(t);if(r===0)throw RangeError(`Rotation around zero vector`);var c=Or(e)?s:null,l=c?new c(1):1,u=c?new c(-1):-1,p=c?new c(t.get([0])/r):t.get([0])/r,m=c?new c(t.get([1])/r):t.get([1])/r,_=c?new c(t.get([2])/r):t.get([2])/r,v=d(e),y=i(l,a(v)),b=f(e),x=i(v,h([p,p,y])),S=i(h([p,m,y]),h([u,_,b])),C=i(h([p,_,y]),h([m,b])),w=i(h([p,m,y]),h([_,b])),T=i(v,h([m,m,y])),E=i(h([m,_,y]),h([u,p,b])),D=i(h([p,_,y]),h([u,m,b])),O=i(h([m,_,y]),h([p,b])),k=i(v,h([_,_,y]));return g([[x,S,C],[w,T,E],[D,O,k]],n)}}),jm=`row`,Mm=J(jm,[`typed`,`Index`,`matrix`,`range`],e=>{var{typed:t,Index:n,matrix:r,range:i}=e;return t(jm,{"Matrix, number":a,"Array, number":function(e,t){return a(r(vi(e)),t).valueOf()}});function a(e,t){if(e.size().length!==2)throw Error(`Only two dimensional matrix is supported`);uc(t,e.size()[0]);var a=i(0,e.size()[1]),o=new n([t],a),s=e.subset(o);return Fr(s)?s:r([[s]])}}),Nm=`size`,Pm=J(Nm,[`typed`],e=>{var{typed:t}=e;return t(Nm,{Matrix:e=>e.size(),Array:oc,string:e=>[e.length],"number | Complex | BigNumber | Unit | boolean | null":e=>[]})}),Fm=`squeeze`,Im=J(Fm,[`typed`],e=>{var{typed:t}=e;return t(Fm,{Array:function(e){return vc(vi(e))},Matrix:function(e){var t=vc(e.toArray());return Array.isArray(t)?e.create(t,e.datatype()):t},any:function(e){return vi(e)}})}),Lm=`subset`,Rm=J(Lm,[`typed`,`matrix`,`zeros`,`add`],e=>{var{typed:t,matrix:n,zeros:r,add:i}=e;return t(Lm,{"Matrix, Index":function(e,t){return dc(t)?n():(lc(e,t),e.subset(t))},"Array, Index":t.referTo(`Matrix, Index`,function(e){return function(t,r){var i=e(n(t),r);return r.isScalar()?i:i.valueOf()}}),"Object, Index":Vm,"string, Index":zm,"Matrix, Index, any, any":function(e,t,n,r){return dc(t)?e:(lc(e,t),e.clone().subset(t,a(n,t),r))},"Array, Index, any, any":t.referTo(`Matrix, Index, any, any`,function(e){return function(t,r,i,a){var o=e(n(t),r,i,a);return o.isMatrix?o.valueOf():o}}),"Array, Index, any":t.referTo(`Matrix, Index, any, any`,function(e){return function(t,r,i){return e(n(t),r,i,void 0).valueOf()}}),"Matrix, Index, any":t.referTo(`Matrix, Index, any, any`,function(e){return function(t,n,r){return e(t,n,r,void 0)}}),"string, Index, string":Bm,"string, Index, string, string":Bm,"Object, Index, any":Hm});function a(e,t){if(typeof e==`string`)throw Error(`can't boradcast a string`);if(t.isScalar())return e;var n=t.size();if(n.every(e=>e>0))try{return i(e,r(n))}catch{return e}else return e}});function zm(e,t){if(!Br(t))throw TypeError(`Index expected`);if(dc(t))return``;if(lc(Array.from(e),t),t.size().length!==1)throw new ic(t.size().length,1);var n=e.length;uc(t.min()[0],n),uc(t.max()[0],n);var r=t.dimension(0),i=``;function a(t){i+=e.charAt(t)}return Number.isInteger(r)?a(r):r.forEach(a),i}function Bm(e,t,n,r){if(!t||t.isIndex!==!0)throw TypeError(`Index expected`);if(dc(t))return e;if(lc(Array.from(e),t),t.size().length!==1)throw new ic(t.size().length,1);if(r!==void 0){if(typeof r!=`string`||r.length!==1)throw TypeError(`Single character expected as defaultValue`)}else r=` `;var i=t.dimension(0);if((Number.isInteger(i)?1:i.size()[0])!==n.length)throw new ic(i.size()[0],n.length);var a=e.length;uc(t.min()[0]),uc(t.max()[0]);for(var o=[],s=0;s<a;s++)o[s]=e.charAt(s);function c(e,t){o[e]=n.charAt(t[0])}if(Number.isInteger(i)?c(i,[0]):i.forEach(c),o.length>a)for(var l=a-1,u=o.length;l<u;l++)o[l]||(o[l]=r);return o.join(``)}function Vm(e,t){if(!dc(t)){if(t.size().length!==1)throw new ic(t.size(),1);var n=t.dimension(0);if(typeof n!=`string`)throw TypeError(`String expected as index to retrieve an object property`);return fr(e,n)}}function Hm(e,t,n){if(dc(t))return e;if(t.size().length!==1)throw new ic(t.size(),1);var r=t.dimension(0);if(typeof r!=`string`)throw TypeError(`String expected as index to retrieve an object property`);var i=vi(e);return pr(i,r,n),i}var Um=`transpose`,Wm=J(Um,[`typed`,`matrix`],e=>{var{typed:t,matrix:n}=e;return t(Um,{Array:e=>r(n(e)).valueOf(),Matrix:r,any:vi});function r(e){var t=e.size(),n;switch(t.length){case 1:n=e.clone();break;case 2:var r=t[0],o=t[1];if(o===0)throw RangeError(`Cannot transpose a 2D matrix with no columns (size: `+Xs(t)+`)`);switch(e.storage()){case`dense`:n=i(e,r,o);break;case`sparse`:n=a(e,r,o);break}break;default:throw RangeError(`Matrix must be a vector or two dimensional (size: `+Xs(t)+`)`)}return n}function i(e,t,n){for(var r=e._data,i=[],a,o=0;o<n;o++){a=i[o]=[];for(var s=0;s<t;s++)a[s]=vi(r[s][o])}return e.createDenseMatrix({data:i,size:[n,t],datatype:e._datatype})}function a(e,t,n){for(var r=e._values,i=e._index,a=e._ptr,o=r?[]:void 0,s=[],c=[],l=[],u=0;u<t;u++)l[u]=0;var d,f,p;for(d=0,f=i.length;d<f;d++)l[i[d]]++;for(var m=0,h=0;h<t;h++)c.push(m),m+=l[h],l[h]=c[h];for(c.push(m),p=0;p<n;p++)for(var g=a[p],_=a[p+1],v=g;v<_;v++){var y=l[i[v]]++;s[y]=p,r&&(o[y]=vi(r[v]))}return e.createSparseMatrix({values:o,index:s,ptr:c,size:[n,t],datatype:e._datatype})}}),Gm=`ctranspose`,Km=J(Gm,[`typed`,`transpose`,`conj`],e=>{var{typed:t,transpose:n,conj:r}=e;return t(Gm,{any:function(e){return r(n(e))}})}),qm=`zeros`,Jm=J(qm,[`typed`,`config`,`matrix`,`BigNumber`],e=>{var{typed:t,config:n,matrix:r,BigNumber:i}=e;return t(qm,{"":function(){return n.matrix===`Array`?a([]):a([],`default`)},"...number | BigNumber | string":function(e){return typeof e[e.length-1]==`string`?a(e,e.pop()):n.matrix===`Array`?a(e):a(e,`default`)},Array:a,Matrix:function(e){var t=e.storage();return a(e.valueOf(),t)},"Array | Matrix, string":function(e,t){return a(e.valueOf(),t)}});function a(e,t){var n=o(e)?new i(0):0;if(s(e),t){var a=r(t);return e.length>0?a.resize(e,n):a}else{var c=[];return e.length>0?fc(c,e,n):c}}function o(e){var t=!1;return e.forEach(function(e,n,r){Or(e)&&(t=!0,r[n]=e.toNumber())}),t}function s(e){e.forEach(function(e){if(typeof e!=`number`||!Ri(e)||e<0)throw Error(`Parameters in function zeros must be positive integers`)})}}),Ym=`fft`,Xm=J(Ym,[`typed`,`matrix`,`addScalar`,`multiplyScalar`,`divideScalar`,`exp`,`tau`,`i`,`dotDivide`,`conj`,`pow`,`ceil`,`log2`],e=>{var{typed:t,matrix:n,addScalar:r,multiplyScalar:i,divideScalar:a,exp:o,tau:s,i:c,dotDivide:l,conj:u,pow:d,ceil:f,log2:p}=e;return t(Ym,{Array:m,Matrix:function(e){return e.create(m(e.valueOf()),e.datatype())}});function m(e){var t=oc(e);return t.length===1?_(e,t[0]):h(e.map(e=>m(e,t.slice(1))),0)}function h(e,t){var n=oc(e);if(t!==0)return Array(n[0]).fill(0).map((n,r)=>h(e[r],t-1));if(n.length===1)return _(e);function r(e){var t=oc(e);return Array(t[1]).fill(0).map((n,r)=>Array(t[0]).fill(0).map((t,n)=>e[n][r]))}return r(h(r(e),1))}function g(e){for(var t=e.length,n=o(a(i(-1,i(c,s)),t)),r=[],h=1-t;h<t;h++)r.push(d(n,a(d(h,2),2)));for(var g=d(2,f(p(t+t-1))),v=[...Array(t).fill(0).map((n,a)=>i(e[a],r[t-1+a])),...Array(g-t).fill(0)],y=[...Array(t+t-1).fill(0).map((e,t)=>a(1,r[t])),...Array(g-(t+t-1)).fill(0)],b=_(v),x=_(y),S=l(u(m(u(Array(g).fill(0).map((e,t)=>i(b[t],x[t]))))),g),C=[],w=t-1;w<t+t-1;w++)C.push(i(S[w],r[w]));return C}function _(e){var t=e.length;if(t===1)return[e[0]];if(t%2==0){for(var n=[..._(e.filter((e,t)=>t%2==0),t/2),..._(e.filter((e,t)=>t%2==1),t/2)],l=0;l<t/2;l++){var u=n[l],d=i(n[l+t/2],o(i(i(s,c),a(-l,t))));n[l]=r(u,d),n[l+t/2]=r(u,i(-1,d))}return n}else return g(e)}}),Zm=`ifft`,Qm=J(Zm,[`typed`,`fft`,`dotDivide`,`conj`],e=>{var{typed:t,fft:n,dotDivide:r,conj:i}=e;return t(Zm,{"Array | Matrix":function(e){var t=Fr(e)?e.size():oc(e);return r(i(n(i(e))),t.reduce((e,t)=>e*t,1))}})});function $m(e){"@babel/helpers - typeof";return $m=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},$m(e)}function eh(e,t){if($m(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if($m(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function th(e){var t=eh(e,`string`);return $m(t)==`symbol`?t:t+``}function nh(e,t,n){return(t=th(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function rh(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function ih(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?rh(Object(n),!0).forEach(function(t){nh(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):rh(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}var ah=J(`solveODE`,[`typed`,`add`,`subtract`,`multiply`,`divide`,`max`,`map`,`abs`,`isPositive`,`isNegative`,`larger`,`smaller`,`matrix`,`bignumber`,`unaryMinus`],e=>{var{typed:t,add:n,subtract:r,multiply:i,divide:a,max:o,map:s,abs:c,isPositive:l,isNegative:u,larger:d,smaller:f,matrix:p,bignumber:m,unaryMinus:h}=e;function g(e){return function(t,p,g,_){if(!(p.length===2&&(p.every(S)||p.every(Mr))))throw Error(`"tspan" must be an Array of two numeric values or two units [tStart, tEnd]`);var v=p[0],y=p[1],C=d(y,v),w=_.firstStep;if(w!==void 0&&!l(w))throw Error(`"firstStep" must be positive`);var T=_.maxStep;if(T!==void 0&&!l(T))throw Error(`"maxStep" must be positive`);var E=_.minStep;if(E&&u(E))throw Error(`"minStep" must be positive or zero`);var D=[v,y,w,E,T].filter(e=>e!==void 0);if(!(D.every(S)||D.every(Mr)))throw Error(`Inconsistent type of "t" dependant variables`);for(var O=1,k=_.tol?_.tol:1e-4,A=_.minDelta?_.minDelta:.2,j=_.maxDelta?_.maxDelta:5,M=_.maxIter?_.maxIter:1e4,N=[v,y,...g,T,E].some(Or),[P,F,I,L]=N?[m(e.a),m(e.c),m(e.b),m(e.bp)]:[e.a,e.c,e.b,e.bp],R=w?C?w:h(w):a(r(y,v),O),z=[v],B=[g],V=r(I,L),ee=0,te=0,H=b(C),ne=x(C);H(z[ee],y);){var re=[];R=ne(z[ee],y,R),re.push(t(z[ee],B[ee]));for(var ie=1;ie<F.length;++ie)re.push(t(n(z[ee],i(F[ie],R)),n(B[ee],i(R,P[ie],re))));var U=o(c(s(i(V,re),e=>Mr(e)?e.value:e)));U<k&&k/U>1/4&&(z.push(n(z[ee],R)),B.push(n(B[ee],i(R,I,re))),ee++);var ae=.84*(k/U)**(1/5);if(f(ae,A)?ae=A:d(ae,j)&&(ae=j),ae=N?m(ae):ae,R=i(R,ae),T&&d(c(R),T)?R=C?T:h(T):E&&f(c(R),E)&&(R=C?E:h(E)),te++,te>M)throw Error(`Maximum number of iterations reached, try changing options`)}return{t:z,y:B}}}function _(e,t,n,r){return g({a:[[],[1/2],[0,3/4],[2/9,1/3,4/9]],c:[null,1/2,3/4,1],b:[2/9,1/3,4/9,0],bp:[7/24,1/4,1/3,1/8]})(e,t,n,r)}function v(e,t,n,r){return g({a:[[],[1/5],[3/40,9/40],[44/45,-56/15,32/9],[19372/6561,-25360/2187,64448/6561,-212/729],[9017/3168,-355/33,46732/5247,49/176,-5103/18656],[35/384,0,500/1113,125/192,-2187/6784,11/84]],c:[null,1/5,3/10,4/5,8/9,1,1],b:[35/384,0,500/1113,125/192,-2187/6784,11/84,0],bp:[5179/57600,0,7571/16695,393/640,-92097/339200,187/2100,1/40]})(e,t,n,r)}function y(e,t,n,r){var i=r.method?r.method:`RK45`,a={RK23:_,RK45:v};if(i.toUpperCase()in a){var o=ih({},r);return delete o.method,a[i.toUpperCase()](e,t,n,o)}else{var s=Object.keys(a).map(e=>`"${e}"`),c=`${s.slice(0,-1).join(`, `)} and ${s.slice(-1)}`;throw Error(`Unavailable method "${i}". Available methods are ${c}`)}}function b(e){return e?f:d}function x(e){var t=e?d:f;return function(e,i,a){return t(n(e,a),i)?r(i,e):a}}function S(e){return Or(e)||Dr(e)}function C(e,t,n,r){var i=y(e,t.toArray(),n.toArray(),r);return{t:p(i.t),y:p(i.y)}}return t(`solveODE`,{"function, Array, Array, Object":y,"function, Matrix, Matrix, Object":C,"function, Array, Array":(e,t,n)=>y(e,t,n,{}),"function, Matrix, Matrix":(e,t,n)=>C(e,t,n,{}),"function, Array, number | BigNumber | Unit":(e,t,n)=>{var r=y(e,t,[n],{});return{t:r.t,y:r.y.map(e=>e[0])}},"function, Matrix, number | BigNumber | Unit":(e,t,n)=>{var r=y(e,t.toArray(),[n],{});return{t:p(r.t),y:p(r.y.map(e=>e[0]))}},"function, Array, number | BigNumber | Unit, Object":(e,t,n,r)=>{var i=y(e,t,[n],r);return{t:i.t,y:i.y.map(e=>e[0])}},"function, Matrix, number | BigNumber | Unit, Object":(e,t,n,r)=>{var i=y(e,t.toArray(),[n],r);return{t:p(i.t),y:p(i.y.map(e=>e[0]))}}})}),oh=J(`erf`,[`typed`],e=>{var{typed:t}=e;return t(`name`,{number:function(e){var t=Math.abs(e);return t>=dh?Bi(e):t<=sh?Bi(e)*n(t):t<=4?Bi(e)*(1-r(t)):Bi(e)*(1-i(t))},"Array | Matrix":t.referToSelf(e=>t=>$c(t,e))});function n(e){var t=e*e,n=lh[0][4]*t,r=t,i;for(i=0;i<3;i+=1)n=(n+lh[0][i])*t,r=(r+uh[0][i])*t;return e*(n+lh[0][3])/(r+uh[0][3])}function r(e){var t=lh[1][8]*e,n=e,r;for(r=0;r<7;r+=1)t=(t+lh[1][r])*e,n=(n+uh[1][r])*e;var i=(t+lh[1][7])/(n+uh[1][7]),a=parseInt(e*16)/16,o=(e-a)*(e+a);return Math.exp(-a*a)*Math.exp(-o)*i}function i(e){var t=1/(e*e),n=lh[2][5]*t,r=t,i;for(i=0;i<4;i+=1)n=(n+lh[2][i])*t,r=(r+uh[2][i])*t;var a=t*(n+lh[2][4])/(r+uh[2][4]);a=(ch-a)/e,t=parseInt(e*16)/16;var o=(e-t)*(e+t);return Math.exp(-t*t)*Math.exp(-o)*a}}),sh=.46875,ch=.5641895835477563,lh=[[3.1611237438705655,113.86415415105016,377.485237685302,3209.3775891384694,.18577770618460315],[.5641884969886701,8.883149794388377,66.11919063714163,298.6351381974001,881.952221241769,1712.0476126340707,2051.0783778260716,1230.3393547979972,2.1531153547440383e-8],[.30532663496123236,.36034489994980445,.12578172611122926,.016083785148742275,.0006587491615298378,.016315387137302097]],uh=[[23.601290952344122,244.02463793444417,1282.6165260773723,2844.236833439171],[15.744926110709835,117.6939508913125,537.1811018620099,1621.3895745666903,3290.7992357334597,4362.619090143247,3439.3676741437216,1230.3393548037495],[2.568520192289822,1.8729528499234604,.5279051029514285,.06051834131244132,.0023352049762686918]],dh=2**53,fh=`zeta`,ph=J(fh,[`typed`,`config`,`multiply`,`pow`,`divide`,`factorial`,`equal`,`smallerEq`,`isBounded`,`isNegative`,`gamma`,`sin`,`subtract`,`add`,`?Complex`,`?BigNumber`,`pi`],e=>{var{typed:t,config:n,multiply:r,pow:i,divide:a,factorial:o,equal:s,smallerEq:c,isBounded:l,isNegative:u,gamma:d,sin:f,subtract:p,add:m,Complex:h,BigNumber:g,pi:_}=e;return t(fh,{number:e=>v(e,e=>e,()=>20),BigNumber:e=>v(e,e=>new g(e),()=>Math.abs(Math.log10(n.relTol))),Complex:y});function v(e,t,n){return s(e,0)?t(-.5):s(e,1)?t(NaN):l(e)?b(e,t,n,e=>e):u(e)?t(NaN):t(1)}function y(e){return e.re===0&&e.im===0?new h(-.5):e.re===1?new h(NaN,NaN):e.re===1/0&&e.im===0?new h(1):e.im===1/0||e.re===-1/0?new h(NaN,NaN):b(e,e=>e,e=>Math.round(1.3*15+.9*Math.abs(e.im)),e=>e.re)}function b(e,t,n,o){var s=n(e);if(o(e)>-(s-1)/2)return S(e,t(s),t);var c=r(i(2,e),i(t(_),p(e,1)));return c=r(c,f(r(a(t(_),2),e))),c=r(c,d(p(1,e))),r(c,b(p(1,e),t,n,o))}function x(e,t){for(var n=e,s=e;c(s,t);s=m(s,1)){var l=a(r(o(m(t,p(s,1))),i(4,s)),r(o(p(t,s)),o(r(2,s))));n=m(n,l)}return r(t,n)}function S(e,t,n){for(var o=a(1,r(x(n(0),t),p(1,i(2,p(1,e))))),s=n(0),l=n(1);c(l,t);l=m(l,1))s=m(s,a(r((-1)**(l-1),x(l,t)),i(l,e)));return r(o,s)}}),mh=`mode`,hh=J(mh,[`typed`,`isNaN`,`isNumeric`],e=>{var{typed:t,isNaN:n,isNumeric:r}=e;return t(mh,{"Array | Matrix":i,"...":function(e){return i(e)}});function i(e){if(e=Sc(e.valueOf()),e.length===0)throw Error(`Cannot calculate mode of an empty array`);for(var t={},i=[],a=0,o=0;o<e.length;o++){var s=e[o];if(r(s)&&n(s))throw Error(`Cannot calculate mode of an array containing NaN values`);s in t||(t[s]=0),t[s]++,t[s]===a?i.push(s):t[s]>a&&(a=t[s],i=[s])}return i}});function gh(e,t,n){var r;return String(e).includes(`Unexpected type`)?(r=arguments.length>2?` (type: `+_i(n)+`, value: `+JSON.stringify(n)+`)`:` (type: `+e.data.actual+`)`,TypeError(`Cannot calculate `+t+`, unexpected type of argument`+r)):String(e).includes(`complex numbers`)?(r=arguments.length>2?` (type: `+_i(n)+`, value: `+JSON.stringify(n)+`)`:``,TypeError(`Cannot calculate `+t+`, no ordering relation is defined for complex numbers`+r)):e}var _h=`prod`,vh=J(_h,[`typed`,`config`,`multiplyScalar`,`numeric`],e=>{var{typed:t,config:n,multiplyScalar:r,numeric:i}=e;return t(_h,{"Array | Matrix":a,"Array | Matrix, number | BigNumber":function(e,t){throw Error(`prod(A, dim) is not yet supported`)},"...":function(e){return a(e)}});function a(e){var t;if(Qc(e,function(e){try{t=t===void 0?e:r(t,e)}catch(t){throw gh(t,`prod`,e)}}),typeof t==`string`&&(t=i(t,zi(t,n))),t===void 0)throw Error(`Cannot calculate prod of an empty array`);return t}}),yh=`format`,bh=J(yh,[`typed`],e=>{var{typed:t}=e;return t(yh,{any:Xs,"any, Object | function | number | BigNumber":Xs})}),xh=`bin`,Sh=J(xh,[`typed`,`format`],e=>{var{typed:t,format:n}=e;return t(xh,{"number | BigNumber":function(e){return n(e,{notation:`bin`})},"number | BigNumber, number | BigNumber":function(e,t){return n(e,{notation:`bin`,wordSize:t})}})}),Ch=`oct`,wh=J(Ch,[`typed`,`format`],e=>{var{typed:t,format:n}=e;return t(Ch,{"number | BigNumber":function(e){return n(e,{notation:`oct`})},"number | BigNumber, number | BigNumber":function(e,t){return n(e,{notation:`oct`,wordSize:t})}})}),Th=`hex`,Eh=J(Th,[`typed`,`format`],e=>{var{typed:t,format:n}=e;return t(Th,{"number | BigNumber":function(e){return n(e,{notation:`hex`})},"number | BigNumber, number | BigNumber":function(e,t){return n(e,{notation:`hex`,wordSize:t})}})}),Dh=/\$([\w.]+)/g,Oh=`print`,kh=J(Oh,[`typed`],e=>{var{typed:t}=e;return t(Oh,{"string, Object | Array":Ah,"string, Object | Array, number | Object":Ah})});function Ah(e,t,n){return e.replace(Dh,function(e,r){var i=r.split(`.`),a=t[i.shift()];for(a!==void 0&&a.isMatrix&&(a=a.toArray());i.length&&a!==void 0;){var o=i.shift();a=o?a[o]:a+`.`}return a===void 0?e:Nr(a)?a:Xs(a,n)})}var jh=`to`,Mh=J(jh,[`typed`,`matrix`,`concat`],e=>{var{typed:t,matrix:n,concat:r}=e;return t(jh,{"Unit, Unit | string":(e,t)=>e.to(t)},wf({typed:t,matrix:n,concat:r})({Ds:!0}))}),Nh=`toBest`,Ph=J(Nh,[`typed`],e=>{var{typed:t}=e;return t(Nh,{Unit:e=>e.toBest(),"Unit, string":(e,t)=>e.toBest(t.split(`,`)),"Unit, string, Object":(e,t,n)=>e.toBest(t.split(`,`),n),"Unit, Array":(e,t)=>e.toBest(t),"Unit, Array, Object":(e,t,n)=>e.toBest(t,n)})}),Fh=`isPrime`,Ih=J(Fh,[`typed`],e=>{var{typed:t}=e;return t(Fh,{number:function(e){if(e<=3)return e>1;if(e%2==0||e%3==0)return!1;for(var t=5;t*t<=e;t+=6)if(e%t===0||e%(t+2)===0)return!1;return!0},bigint:function(e){if(e<=3n)return e>1n;if(e%2n==0n||e%3n==0n)return!1;for(var t=5n;t*t<=e;t+=6n)if(e%t===0n||e%(t+2n)===0n)return!1;return!0},BigNumber:function(e){if(e.lte(3))return e.gt(1);if(e.mod(2).eq(0)||e.mod(3).eq(0))return!1;if(e.lt(2**32)){for(var t=e.toNumber(),n=5;n*n<=t;n+=6)if(t%n===0||t%(n+2)===0)return!1;return!0}function r(e,t,n){for(var r=1;!t.eq(0);)t.mod(2).eq(0)?(t=t.div(2),e=e.mul(e).mod(n)):(t=t.sub(1),r=e.mul(r).mod(n));return r}e=new(e.constructor.clone({precision:e.toFixed(0).length*2}))(e);for(var i=0,a=e.sub(1);a.mod(2).eq(0);)a=a.div(2),i+=1;var o=null;if(e.lt(`3317044064679887385961981`))o=[2,3,5,7,11,13,17,19,23,29,31,37,41].filter(t=>t<e);else{var s=Math.min(e.toNumber()-2,Math.floor(2*(e.toFixed(0).length*Math.log(10))**2));o=[];for(var c=2;c<=s;c+=1)o.push(s)}for(var l=0;l<o.length;l+=1){var u=o[l],d=r(e.sub(e).add(u),a,e);if(!d.eq(1)){for(var f=0,p=d;!p.eq(e.sub(1));f+=1,p=p.mul(p).mod(e))if(f===i-1)return!1}}return!0},"Array | Matrix":t.referToSelf(e=>t=>$c(t,e))})}),Lh=J(`numeric`,[`number`,`?bignumber`,`?fraction`],e=>{var{number:t,bignumber:n,fraction:r}=e,i={string:!0,number:!0,BigNumber:!0,Fraction:!0},a={number:e=>t(e),BigNumber:n?e=>n(e):ym,bigint:e=>BigInt(e),Fraction:r?e=>r(e):bm};return function(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:`number`;if((arguments.length>2?arguments[2]:void 0)!==void 0)throw SyntaxError(`numeric() takes one or two arguments`);var n=_i(e);if(!(n in i))throw TypeError(`Cannot convert `+e+` of type "`+n+`"; valid input types are `+Object.keys(i).join(`, `));if(!(t in a))throw TypeError(`Cannot convert `+e+` to type "`+t+`"; valid output types are `+Object.keys(a).join(`, `));return t===n?e:a[t](e)}}),Rh=`divideScalar`,zh=J(Rh,[`typed`,`numeric`],e=>{var{typed:t,numeric:n}=e;return t(Rh,{"number, number":function(e,t){return e/t},"Complex, Complex":function(e,t){return e.div(t)},"BigNumber, BigNumber":function(e,t){return e.div(t)},"bigint, bigint":function(e,t){return e/t},"Fraction, Fraction":function(e,t){return e.div(t)},"Unit, number | Complex | Fraction | BigNumber | Unit":(e,t)=>e.divide(t),"number | Fraction | Complex | BigNumber, Unit":(e,t)=>t.divideInto(e)})}),Bh=`pow`,Vh=J(Bh,[`typed`,`config`,`identity`,`multiply`,`matrix`,`inv`,`fraction`,`number`,`Complex`],e=>{var{typed:t,config:n,identity:r,multiply:i,matrix:a,inv:o,number:s,fraction:c,Complex:l}=e;return t(Bh,{"number, number":u,"Complex, Complex":function(e,t){return e.pow(t)},"BigNumber, BigNumber":function(e,t){return t.isInteger()||e>=0||n.predictable?e.pow(t):new l(e.toNumber(),0).pow(t.toNumber(),0)},"bigint, bigint":(e,t)=>e**t,"Fraction, Fraction":function(e,t){var r=e.pow(t);if(r!=null)return r;if(n.predictable)throw Error(`Result of pow is non-rational and cannot be expressed as a fraction`);return u(e.valueOf(),t.valueOf())},"Array, number":d,"Array, BigNumber":function(e,t){return d(e,t.toNumber())},"Matrix, number":f,"Matrix, BigNumber":function(e,t){return f(e,t.toNumber())},"Unit, number | BigNumber":function(e,t){return e.pow(t)}});function u(e,t){if(n.predictable&&!Ri(t)&&e<0)try{var r=c(t),i=s(r);if((t===i||Math.abs((t-i)/t)<1e-14)&&r.d%2n==1n)return(r.n%2n==0n?1:-1)*(-e)**+t}catch{}return n.predictable&&(e<-1&&t===1/0||e>-1&&e<0&&t===-1/0)?NaN:Ri(t)||e>=0||n.predictable?Al(e,t):e*e<1&&t===1/0||e*e>1&&t===-1/0?0:new l(e,0).pow(t,0)}function d(e,t){if(!Ri(t))throw TypeError(`For A^b, b must be an integer (value is `+t+`)`);var n=oc(e);if(n.length!==2)throw Error(`For A^b, A must be 2 dimensional (A has `+n.length+` dimensions)`);if(n[0]!==n[1])throw Error(`For A^b, A must be square (size is `+n[0]+`x`+n[1]+`)`);if(t<0)try{return d(o(e),-t)}catch(e){throw e.message===`Cannot calculate inverse, determinant is zero`?TypeError(`For A^b, when A is not invertible, b must be a positive integer (value is `+t+`)`):e}for(var a=r(n[0]).valueOf(),s=e;t>=1;)(t&1)==1&&(a=i(s,a)),t>>=1,s=i(s,s);return a}function f(e,t){return a(d(e.valueOf(),t))}}),Hh=`Number of decimals in function round must be an integer`,Uh=`round`,Wh=J(Uh,[`typed`,`config`,`matrix`,`equalScalar`,`zeros`,`BigNumber`,`DenseMatrix`],e=>{var{typed:t,config:n,matrix:r,equalScalar:i,zeros:a,BigNumber:o,DenseMatrix:s}=e,c=Jd({typed:t,equalScalar:i}),l=Yd({typed:t,DenseMatrix:s}),u=Xd({typed:t});function d(e){return Math.abs(Yi(e).exponent)}return t(Uh,{number:function(e){var t=jl(e,d(n.relTol));return jl(ra(e,t,n.relTol,n.absTol)?t:e)},"number, number":function(e,t){var r=d(n.relTol);if(t>=r)return jl(e,t);var i=jl(e,r);return jl(ra(e,i,n.relTol,n.absTol)?i:e,t)},"number, BigNumber":function(e,t){if(!t.isInteger())throw TypeError(Hh);return new o(e).toDecimalPlaces(t.toNumber())},Complex:function(e){return e.round()},"Complex, number":function(e,t){if(t%1)throw TypeError(Hh);return e.round(t)},"Complex, BigNumber":function(e,t){if(!t.isInteger())throw TypeError(Hh);var n=t.toNumber();return e.round(n)},BigNumber:function(e){var t=new o(e).toDecimalPlaces(d(n.relTol));return(zu(e,t,n.relTol,n.absTol)?t:e).toDecimalPlaces(0)},"BigNumber, BigNumber":function(e,t){if(!t.isInteger())throw TypeError(Hh);var r=d(n.relTol);if(t>=r)return e.toDecimalPlaces(t.toNumber());var i=e.toDecimalPlaces(r);return(zu(e,i,n.relTol,n.absTol)?i:e).toDecimalPlaces(t.toNumber())},bigint:e=>e,"bigint, number":(e,t)=>e,"bigint, BigNumber":(e,t)=>e,Fraction:function(e){return e.round()},"Fraction, number":function(e,t){if(t%1)throw TypeError(Hh);return e.round(t)},"Fraction, BigNumber":function(e,t){if(!t.isInteger())throw TypeError(Hh);return e.round(t.toNumber())},"Unit, number, Unit":t.referToSelf(e=>function(t,n,r){var i=t.toNumeric(r);return r.multiply(e(i,n))}),"Unit, BigNumber, Unit":t.referToSelf(e=>(t,n,r)=>e(t,n.toNumber(),r)),"Array | Matrix, number | BigNumber, Unit":t.referToSelf(e=>(t,n,r)=>$c(t,t=>e(t,n,r),!0)),"Array | Matrix | Unit, Unit":t.referToSelf(e=>(t,n)=>e(t,0,n)),"Array | Matrix":t.referToSelf(e=>t=>$c(t,e,!0)),"SparseMatrix, number | BigNumber":t.referToSelf(e=>(t,n)=>c(t,n,e,!1)),"DenseMatrix, number | BigNumber":t.referToSelf(e=>(t,n)=>u(t,n,e,!1)),"Array, number | BigNumber":t.referToSelf(e=>(t,n)=>u(r(t),n,e,!1).valueOf()),"number | Complex | BigNumber | Fraction, SparseMatrix":t.referToSelf(e=>(t,n)=>i(t,0)?a(n.size(),n.storage()):l(n,t,e,!0)),"number | Complex | BigNumber | Fraction, DenseMatrix":t.referToSelf(e=>(t,n)=>i(t,0)?a(n.size(),n.storage()):u(n,t,e,!0)),"number | Complex | BigNumber | Fraction, Array":t.referToSelf(e=>(t,n)=>u(r(n),t,e,!0).valueOf())})}),Gh=`log`,Kh=[`config`,`typed`,`typeOf`,`divideScalar`,`Complex`],qh=Math.log(16),Jh=J(Gh,Kh,e=>{var{typed:t,typeOf:n,config:r,divideScalar:i,Complex:a}=e;function o(e){return e.log()}function s(e){return o(new a(e,0))}return t(Gh,{number:function(e){return e>=0||r.predictable?bl(e):s(e)},bigint:Bf(qh,bl,r,s),Complex:o,BigNumber:function(e){return!e.isNegative()||r.predictable?e.ln():s(e.toNumber())},"any, any":t.referToSelf(e=>(t,r)=>{if(n(t)===`Fraction`&&n(r)===`Fraction`){var a=t.log(r);if(a!==null)return a}return i(e(t),e(r))})})}),Yh=`log1p`,Xh=J(Yh,[`typed`,`config`,`divideScalar`,`log`,`Complex`],e=>{var{typed:t,config:n,divideScalar:r,log:i,Complex:a}=e;return t(Yh,{number:function(e){return e>=-1||n.predictable?Ui(e):o(new a(e,0))},Complex:o,BigNumber:function(e){var t=e.plus(1);return!t.isNegative()||n.predictable?t.ln():o(new a(e.toNumber(),0))},"Array | Matrix":t.referToSelf(e=>t=>$c(t,e)),"any, any":t.referToSelf(e=>(t,n)=>r(e(t),i(n)))});function o(e){var t=e.re+1;return new a(Math.log(Math.sqrt(t*t+e.im*e.im)),Math.atan2(e.im,t))}}),Zh=`nthRoots`,Qh=J(Zh,[`config`,`typed`,`divideScalar`,`Complex`],e=>{var{typed:t,config:n,divideScalar:r,Complex:i}=e,a=[function(e){return new i(e,0)},function(e){return new i(0,e)},function(e){return new i(-e,0)},function(e){return new i(0,-e)}];function o(e,t){if(t<0)throw Error(`Root must be greater than zero`);if(t===0)throw Error(`Root must be non-zero`);if(t%1!=0)throw Error(`Root must be an integer`);if(e===0||e.abs()===0)return[new i(0,0)];var n=typeof e==`number`,r;(n||e.re===0||e.im===0)&&(r=n?2*(e<0):e.im===0?2*(e.re<0):2*(e.im<0)+1);for(var o=e.arg(),s=e.abs(),c=[],l=s**(1/t),u=0;u<t;u++){var d=(r+4*u)/t;if(d===Math.round(d)){c.push(a[d%4](l));continue}c.push(new i({r:l,phi:(o+2*Math.PI*u)/t}))}return c}return t(Zh,{Complex:function(e){return o(e,2)},"Complex, number":o})}),$h=`dotPow`,eg=J($h,[`typed`,`equalScalar`,`matrix`,`pow`,`DenseMatrix`,`concat`,`SparseMatrix`],e=>{var{typed:t,equalScalar:n,matrix:r,pow:i,DenseMatrix:a,concat:o,SparseMatrix:s}=e,c=yf({typed:t}),l=Ep({typed:t,SparseMatrix:s}),u=Jd({typed:t,equalScalar:n}),d=Yd({typed:t,DenseMatrix:a}),f=wf({typed:t,matrix:r,concat:o}),p={};for(var m in i.signatures)Object.prototype.hasOwnProperty.call(i.signatures,m)&&!m.includes(`Matrix`)&&!m.includes(`Array`)&&(p[m]=i.signatures[m]);return t($h,f({elop:t(p),SS:l,DS:c,Ss:u,sS:d}))}),tg=`dotDivide`,ng=J(tg,[`typed`,`matrix`,`equalScalar`,`divideScalar`,`DenseMatrix`,`concat`,`SparseMatrix`],e=>{var{typed:t,matrix:n,equalScalar:r,divideScalar:i,DenseMatrix:a,concat:o,SparseMatrix:s}=e,c=vf({typed:t,equalScalar:r}),l=yf({typed:t}),u=Ep({typed:t,SparseMatrix:s}),d=Jd({typed:t,equalScalar:r}),f=Yd({typed:t,DenseMatrix:a});return t(tg,wf({typed:t,matrix:n,concat:o})({elop:i,SS:u,DS:l,SD:c,Ss:d,sS:f}))});function rg(e){var{DenseMatrix:t}=e;return function(e,n,r){var i=e.size();if(i.length!==2)throw RangeError(`Matrix must be two dimensional (size: `+Xs(i)+`)`);var a=i[0];if(a!==i[1])throw RangeError(`Matrix must be square (size: `+Xs(i)+`)`);var o=[];if(Fr(n)){var s=n.size(),c=n._data;if(s.length===1){if(s[0]!==a)throw RangeError(`Dimension mismatch. Matrix columns must match vector length.`);for(var l=0;l<a;l++)o[l]=[c[l]];return new t({data:o,size:[a,1],datatype:n._datatype})}if(s.length===2){if(s[0]!==a||s[1]!==1)throw RangeError(`Dimension mismatch. Matrix columns must match vector length.`);if(Lr(n)){if(r){o=[];for(var u=0;u<a;u++)o[u]=[c[u][0]];return new t({data:o,size:[a,1],datatype:n._datatype})}return n}if(Rr(n)){for(var d=0;d<a;d++)o[d]=[0];for(var f=n._values,p=n._index,m=n._ptr,h=m[1],g=m[0];g<h;g++){var _=p[g];o[_][0]=f[g]}return new t({data:o,size:[a,1],datatype:n._datatype})}}throw RangeError(`Dimension mismatch. The right side has to be either 1- or 2-dimensional vector.`)}if(Pr(n)){var v=oc(n);if(v.length===1){if(v[0]!==a)throw RangeError(`Dimension mismatch. Matrix columns must match vector length.`);for(var y=0;y<a;y++)o[y]=[n[y]];return new t({data:o,size:[a,1]})}if(v.length===2){if(v[0]!==a||v[1]!==1)throw RangeError(`Dimension mismatch. Matrix columns must match vector length.`);for(var b=0;b<a;b++)o[b]=[n[b][0]];return new t({data:o,size:[a,1]})}throw RangeError(`Dimension mismatch. The right side has to be either 1- or 2-dimensional vector.`)}}}var ig=`lsolve`,ag=J(ig,[`typed`,`matrix`,`divideScalar`,`multiplyScalar`,`subtractScalar`,`equalScalar`,`DenseMatrix`],e=>{var{typed:t,matrix:n,divideScalar:r,multiplyScalar:i,subtractScalar:a,equalScalar:o,DenseMatrix:s}=e,c=rg({DenseMatrix:s});return t(ig,{"SparseMatrix, Array | Matrix":function(e,t){return u(e,t)},"DenseMatrix, Array | Matrix":function(e,t){return l(e,t)},"Array, Array | Matrix":function(e,t){return l(n(e),t).valueOf()}});function l(e,t){t=c(e,t,!0);for(var n=t._data,l=e._size[0],u=e._size[1],d=[],f=e._data,p=0;p<u;p++){var m=n[p][0]||0,h=void 0;if(o(m,0))h=0;else{var g=f[p][p];if(o(g,0))throw Error(`Linear system cannot be solved since matrix is singular`);h=r(m,g);for(var _=p+1;_<l;_++)n[_]=[a(n[_][0]||0,i(h,f[_][p]))]}d[p]=[h]}return new s({data:d,size:[l,1]})}function u(e,t){t=c(e,t,!0);for(var n=t._data,l=e._size[0],u=e._size[1],d=e._values,f=e._index,p=e._ptr,m=[],h=0;h<u;h++){var g=n[h][0]||0;if(o(g,0))m[h]=[0];else{for(var _=0,v=[],y=[],b=p[h],x=p[h+1],S=b;S<x;S++){var C=f[S];C===h?_=d[S]:C>h&&(v.push(d[S]),y.push(C))}if(o(_,0))throw Error(`Linear system cannot be solved since matrix is singular`);for(var w=r(g,_),T=0,E=y.length;T<E;T++){var D=y[T];n[D]=[a(n[D][0]||0,i(w,v[T]))]}m[h]=[w]}}return new s({data:m,size:[l,1]})}}),og=`usolve`,sg=J(og,[`typed`,`matrix`,`divideScalar`,`multiplyScalar`,`subtractScalar`,`equalScalar`,`DenseMatrix`],e=>{var{typed:t,matrix:n,divideScalar:r,multiplyScalar:i,subtractScalar:a,equalScalar:o,DenseMatrix:s}=e,c=rg({DenseMatrix:s});return t(og,{"SparseMatrix, Array | Matrix":function(e,t){return u(e,t)},"DenseMatrix, Array | Matrix":function(e,t){return l(e,t)},"Array, Array | Matrix":function(e,t){return l(n(e),t).valueOf()}});function l(e,t){t=c(e,t,!0);for(var n=t._data,l=e._size[0],u=e._size[1],d=[],f=e._data,p=u-1;p>=0;p--){var m=n[p][0]||0,h=void 0;if(o(m,0))h=0;else{var g=f[p][p];if(o(g,0))throw Error(`Linear system cannot be solved since matrix is singular`);h=r(m,g);for(var _=p-1;_>=0;_--)n[_]=[a(n[_][0]||0,i(h,f[_][p]))]}d[p]=[h]}return new s({data:d,size:[l,1]})}function u(e,t){t=c(e,t,!0);for(var n=t._data,l=e._size[0],u=e._size[1],d=e._values,f=e._index,p=e._ptr,m=[],h=u-1;h>=0;h--){var g=n[h][0]||0;if(o(g,0))m[h]=[0];else{for(var _=0,v=[],y=[],b=p[h],x=p[h+1]-1;x>=b;x--){var S=f[x];S===h?_=d[x]:S<h&&(v.push(d[x]),y.push(S))}if(o(_,0))throw Error(`Linear system cannot be solved since matrix is singular`);for(var C=r(g,_),w=0,T=y.length;w<T;w++){var E=y[w];n[E]=[a(n[E][0],i(C,v[w]))]}m[h]=[C]}}return new s({data:m,size:[l,1]})}}),cg=`lsolveAll`,lg=J(cg,[`typed`,`matrix`,`divideScalar`,`multiplyScalar`,`subtractScalar`,`equalScalar`,`DenseMatrix`],e=>{var{typed:t,matrix:n,divideScalar:r,multiplyScalar:i,subtractScalar:a,equalScalar:o,DenseMatrix:s}=e,c=rg({DenseMatrix:s});return t(cg,{"SparseMatrix, Array | Matrix":function(e,t){return u(e,t)},"DenseMatrix, Array | Matrix":function(e,t){return l(e,t)},"Array, Array | Matrix":function(e,t){return l(n(e),t).map(e=>e.valueOf())}});function l(e,t){for(var n=[c(e,t,!0)._data.map(e=>e[0])],l=e._data,u=e._size[0],d=e._size[1],f=0;f<d;f++)for(var p=n.length,m=0;m<p;m++){var h=n[m];if(!o(l[f][f],0)){h[f]=r(h[f],l[f][f]);for(var g=f+1;g<d;g++)h[g]=a(h[g],i(h[f],l[g][f]))}else if(!o(h[f],0)){if(m===0)return[];n.splice(m,1),--m,--p}else if(m===0){var _=[...h];_[f]=1;for(var v=f+1;v<d;v++)_[v]=a(_[v],l[v][f]);n.push(_)}}return n.map(e=>new s({data:e.map(e=>[e]),size:[u,1]}))}function u(e,t){for(var n=[c(e,t,!0)._data.map(e=>e[0])],l=e._size[0],u=e._size[1],d=e._values,f=e._index,p=e._ptr,m=0;m<u;m++)for(var h=n.length,g=0;g<h;g++){for(var _=n[g],v=[],y=[],b=p[m],x=p[m+1],S=0,C=b;C<x;C++){var w=f[C];w===m?S=d[C]:w>m&&(v.push(d[C]),y.push(w))}if(!o(S,0)){_[m]=r(_[m],S);for(var T=0,E=y.length;T<E;T++){var D=y[T];_[D]=a(_[D],i(_[m],v[T]))}}else if(!o(_[m],0)){if(g===0)return[];n.splice(g,1),--g,--h}else if(g===0){var O=[..._];O[m]=1;for(var k=0,A=y.length;k<A;k++){var j=y[k];O[j]=a(O[j],v[k])}n.push(O)}}return n.map(e=>new s({data:e.map(e=>[e]),size:[l,1]}))}}),ug=`usolveAll`,dg=J(ug,[`typed`,`matrix`,`divideScalar`,`multiplyScalar`,`subtractScalar`,`equalScalar`,`DenseMatrix`],e=>{var{typed:t,matrix:n,divideScalar:r,multiplyScalar:i,subtractScalar:a,equalScalar:o,DenseMatrix:s}=e,c=rg({DenseMatrix:s});return t(ug,{"SparseMatrix, Array | Matrix":function(e,t){return u(e,t)},"DenseMatrix, Array | Matrix":function(e,t){return l(e,t)},"Array, Array | Matrix":function(e,t){return l(n(e),t).map(e=>e.valueOf())}});function l(e,t){for(var n=[c(e,t,!0)._data.map(e=>e[0])],l=e._data,u=e._size[0],d=e._size[1]-1;d>=0;d--)for(var f=n.length,p=0;p<f;p++){var m=n[p];if(!o(l[d][d],0)){m[d]=r(m[d],l[d][d]);for(var h=d-1;h>=0;h--)m[h]=a(m[h],i(m[d],l[h][d]))}else if(!o(m[d],0)){if(p===0)return[];n.splice(p,1),--p,--f}else if(p===0){var g=[...m];g[d]=1;for(var _=d-1;_>=0;_--)g[_]=a(g[_],l[_][d]);n.push(g)}}return n.map(e=>new s({data:e.map(e=>[e]),size:[u,1]}))}function u(e,t){for(var n=[c(e,t,!0)._data.map(e=>e[0])],l=e._size[0],u=e._size[1],d=e._values,f=e._index,p=e._ptr,m=u-1;m>=0;m--)for(var h=n.length,g=0;g<h;g++){for(var _=n[g],v=[],y=[],b=p[m],x=p[m+1],S=0,C=x-1;C>=b;C--){var w=f[C];w===m?S=d[C]:w<m&&(v.push(d[C]),y.push(w))}if(!o(S,0)){_[m]=r(_[m],S);for(var T=0,E=y.length;T<E;T++){var D=y[T];_[D]=a(_[D],i(_[m],v[T]))}}else if(!o(_[m],0)){if(g===0)return[];n.splice(g,1),--g,--h}else if(g===0){var O=[..._];O[m]=1;for(var k=0,A=y.length;k<A;k++){var j=y[k];O[j]=a(O[j],v[k])}n.push(O)}}return n.map(e=>new s({data:e.map(e=>[e]),size:[l,1]}))}}),fg=J(`matAlgo08xS0Sid`,[`typed`,`equalScalar`],e=>{var{typed:t,equalScalar:n}=e;return function(e,r,i){var a=e._values,o=e._index,s=e._ptr,c=e._size,l=e._datatype||e._data===void 0?e._datatype:e.getDataType(),u=r._values,d=r._index,f=r._ptr,p=r._size,m=r._datatype||r._data===void 0?r._datatype:r.getDataType();if(c.length!==p.length)throw new ic(c.length,p.length);if(c[0]!==p[0]||c[1]!==p[1])throw RangeError(`Dimension mismatch. Matrix A (`+c+`) must match Matrix B (`+p+`)`);if(!a||!u)throw Error(`Cannot perform operation on Pattern Sparse Matrices`);var h=c[0],g=c[1],_,v=n,y=0,b=i;typeof l==`string`&&l===m&&l!==`mixed`&&(_=l,v=t.find(n,[_,_]),y=t.convert(0,_),b=t.find(i,[_,_]));for(var x=[],S=[],C=[],w=[],T=[],E,D,O,k,A=0;A<g;A++){C[A]=S.length;var j=A+1;for(D=s[A],O=s[A+1],E=D;E<O;E++)k=o[E],T[k]=j,w[k]=a[E],S.push(k);for(D=f[A],O=f[A+1],E=D;E<O;E++)k=d[E],T[k]===j&&(w[k]=b(w[k],u[E]));for(E=C[A];E<S.length;){k=S[E];var M=w[k];v(M,y)?S.splice(E,1):(x.push(M),E++)}}return C[g]=S.length,e.createSparseMatrix({values:x,index:S,ptr:C,size:[h,g],datatype:l===e._datatype&&m===r._datatype?_:void 0})}}),pg=J(`useMatrixForArrayScalar`,[`typed`,`matrix`],e=>{var{typed:t,matrix:n}=e;return{"Array, number":t.referTo(`DenseMatrix, number`,e=>(t,r)=>e(n(t),r).valueOf()),"Array, BigNumber":t.referTo(`DenseMatrix, BigNumber`,e=>(t,r)=>e(n(t),r).valueOf()),"number, Array":t.referTo(`number, DenseMatrix`,e=>(t,r)=>e(t,n(r)).valueOf()),"BigNumber, Array":t.referTo(`BigNumber, DenseMatrix`,e=>(t,r)=>e(t,n(r)).valueOf())}}),mg=`leftShift`,hg=J(mg,[`typed`,`matrix`,`equalScalar`,`zeros`,`DenseMatrix`,`concat`],e=>{var{typed:t,matrix:n,equalScalar:r,zeros:i,DenseMatrix:a,concat:o}=e,s=Df({typed:t}),c=vf({typed:t,equalScalar:r}),l=fg({typed:t,equalScalar:r}),u=kf({typed:t,DenseMatrix:a}),d=Jd({typed:t,equalScalar:r}),f=Xd({typed:t}),p=wf({typed:t,matrix:n,concat:o}),m=pg({typed:t,matrix:n});return t(mg,{"number, number":zl,"BigNumber, BigNumber":vp,"bigint, bigint":(e,t)=>e<<t,"SparseMatrix, number | BigNumber":t.referToSelf(e=>(t,n)=>r(n,0)?t.clone():d(t,n,e,!1)),"DenseMatrix, number | BigNumber":t.referToSelf(e=>(t,n)=>r(n,0)?t.clone():f(t,n,e,!1)),"number | BigNumber, SparseMatrix":t.referToSelf(e=>(t,n)=>r(t,0)?i(n.size(),n.storage()):u(n,t,e,!0)),"number | BigNumber, DenseMatrix":t.referToSelf(e=>(t,n)=>r(t,0)?i(n.size(),n.storage()):f(n,t,e,!0))},m,p({SS:l,DS:s,SD:c}))}),gg=`rightArithShift`,_g=J(gg,[`typed`,`matrix`,`equalScalar`,`zeros`,`DenseMatrix`,`concat`],e=>{var{typed:t,matrix:n,equalScalar:r,zeros:i,DenseMatrix:a,concat:o}=e,s=Df({typed:t}),c=vf({typed:t,equalScalar:r}),l=fg({typed:t,equalScalar:r}),u=kf({typed:t,DenseMatrix:a}),d=Jd({typed:t,equalScalar:r}),f=Xd({typed:t}),p=wf({typed:t,matrix:n,concat:o}),m=pg({typed:t,matrix:n});return t(gg,{"number, number":Bl,"BigNumber, BigNumber":yp,"bigint, bigint":(e,t)=>e>>t,"SparseMatrix, number | BigNumber":t.referToSelf(e=>(t,n)=>r(n,0)?t.clone():d(t,n,e,!1)),"DenseMatrix, number | BigNumber":t.referToSelf(e=>(t,n)=>r(n,0)?t.clone():f(t,n,e,!1)),"number | BigNumber, SparseMatrix":t.referToSelf(e=>(t,n)=>r(t,0)?i(n.size(),n.storage()):u(n,t,e,!0)),"number | BigNumber, DenseMatrix":t.referToSelf(e=>(t,n)=>r(t,0)?i(n.size(),n.storage()):f(n,t,e,!0))},m,p({SS:l,DS:s,SD:c}))}),vg=`rightLogShift`,yg=J(vg,[`typed`,`matrix`,`equalScalar`,`zeros`,`DenseMatrix`,`concat`],e=>{var{typed:t,matrix:n,equalScalar:r,zeros:i,DenseMatrix:a,concat:o}=e,s=Df({typed:t}),c=vf({typed:t,equalScalar:r}),l=fg({typed:t,equalScalar:r}),u=kf({typed:t,DenseMatrix:a}),d=Jd({typed:t,equalScalar:r}),f=Xd({typed:t}),p=wf({typed:t,matrix:n,concat:o}),m=pg({typed:t,matrix:n});return t(vg,{"number, number":Vl,"SparseMatrix, number | BigNumber":t.referToSelf(e=>(t,n)=>r(n,0)?t.clone():d(t,n,e,!1)),"DenseMatrix, number | BigNumber":t.referToSelf(e=>(t,n)=>r(n,0)?t.clone():f(t,n,e,!1)),"number | BigNumber, SparseMatrix":t.referToSelf(e=>(t,n)=>r(t,0)?i(n.size(),n.storage()):u(n,t,e,!0)),"number | BigNumber, DenseMatrix":t.referToSelf(e=>(t,n)=>r(t,0)?i(n.size(),n.storage()):f(n,t,e,!0))},m,p({SS:l,DS:s,SD:c}))}),bg=`and`,xg=J(bg,[`typed`,`matrix`,`equalScalar`,`zeros`,`not`,`concat`],e=>{var{typed:t,matrix:n,equalScalar:r,zeros:i,not:a,concat:o}=e,s=vf({typed:t,equalScalar:r}),c=Lf({typed:t,equalScalar:r}),l=Jd({typed:t,equalScalar:r}),u=Xd({typed:t}),d=wf({typed:t,matrix:n,concat:o});return t(bg,{"number, number":$l,"Complex, Complex":function(e,t){return(e.re!==0||e.im!==0)&&(t.re!==0||t.im!==0)},"BigNumber, BigNumber":function(e,t){return!e.isZero()&&!t.isZero()&&!e.isNaN()&&!t.isNaN()},"bigint, bigint":$l,"Unit, Unit":t.referToSelf(e=>(t,n)=>e(t.value||0,n.value||0)),"SparseMatrix, any":t.referToSelf(e=>(t,n)=>a(n)?i(t.size(),t.storage()):l(t,n,e,!1)),"DenseMatrix, any":t.referToSelf(e=>(t,n)=>a(n)?i(t.size(),t.storage()):u(t,n,e,!1)),"any, SparseMatrix":t.referToSelf(e=>(t,n)=>a(t)?i(t.size(),t.storage()):l(n,t,e,!0)),"any, DenseMatrix":t.referToSelf(e=>(t,n)=>a(t)?i(t.size(),t.storage()):u(n,t,e,!0)),"Array, any":t.referToSelf(e=>(t,r)=>e(n(t),r).valueOf()),"any, Array":t.referToSelf(e=>(t,r)=>e(t,n(r)).valueOf())},d({SS:c,DS:s}))}),Sg=`compare`,Cg=J(Sg,[`typed`,`config`,`matrix`,`equalScalar`,`BigNumber`,`Fraction`,`DenseMatrix`,`concat`],e=>{var{typed:t,config:n,equalScalar:r,matrix:i,BigNumber:a,Fraction:o,DenseMatrix:s,concat:c}=e,l=yf({typed:t}),u=bf({typed:t,equalScalar:r}),d=Yd({typed:t,DenseMatrix:s}),f=wf({typed:t,matrix:i,concat:c}),p=ad({typed:t});return t(Sg,wg({typed:t,config:n}),{"boolean, boolean":function(e,t){return e===t?0:e>t?1:-1},"BigNumber, BigNumber":function(e,t){return zu(e,t,n.relTol,n.absTol)?new a(0):new a(e.cmp(t))},"bigint, bigint":function(e,t){return e===t?0n:e>t?1n:-1n},"Fraction, Fraction":function(e,t){return new o(e.compare(t))},"Complex, Complex":function(){throw TypeError(`No ordering relation is defined for complex numbers`)}},p,f({SS:u,DS:l,Ss:d}))}),wg=J(Sg,[`typed`,`config`],e=>{var{typed:t,config:n}=e;return t(Sg,{"number, number":function(e,t){return ra(e,t,n.relTol,n.absTol)?0:e>t?1:-1}})}),Tg=Ot(Tt(((e,t)=>{t.exports=function e(t,n){var r=/(^([+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?)?$|^0x[0-9a-f]+$|\d+)/gi,i=/(^[ ]*|[ ]*$)/g,a=/(^([\w ]+,?[\w ]+)?[\w ]+,?[\w ]+\d+:\d+(:\d+)?[\w ]?|^\d{1,4}[\/\-]\d{1,4}[\/\-]\d{1,4}|^\w+, \w+ \d+, \d{4})/,o=/^0x[0-9a-f]+$/i,s=/^0/,c=function(t){return e.insensitive&&(``+t).toLowerCase()||``+t},l=c(t).replace(i,``)||``,u=c(n).replace(i,``)||``,d=l.replace(r,`\0$1\0`).replace(/\0$/,``).replace(/^\0/,``).split(`\0`),f=u.replace(r,`\0$1\0`).replace(/\0$/,``).replace(/^\0/,``).split(`\0`),p=parseInt(l.match(o),16)||d.length!==1&&l.match(a)&&Date.parse(l),m=parseInt(u.match(o),16)||p&&u.match(a)&&Date.parse(u)||null,h,g;if(m){if(p<m)return-1;if(p>m)return 1}for(var _=0,v=Math.max(d.length,f.length);_<v;_++){if(h=!(d[_]||``).match(s)&&parseFloat(d[_])||d[_]||0,g=!(f[_]||``).match(s)&&parseFloat(f[_])||f[_]||0,isNaN(h)!==isNaN(g))return isNaN(h)?1:-1;if(typeof h!=typeof g&&(h+=``,g+=``),h<g)return-1;if(h>g)return 1}return 0}}))(),1),Eg=`compareNatural`,Dg=J(Eg,[`typed`,`compare`],e=>{var{typed:t,compare:n}=e,r=n.signatures[`boolean,boolean`];return t(Eg,{"any, any":i});function i(e,t){var c=_i(e),l=_i(t),u;if((c===`number`||c===`BigNumber`||c===`Fraction`||c===`bigint`)&&(l===`number`||l===`BigNumber`||l===`Fraction`||l===`bigint`))return u=n(e,t),u.toString()===`0`?(0,Tg.default)(c,l):u>0?1:-1;var d=[`Array`,`DenseMatrix`,`SparseMatrix`];if(d.includes(c)||d.includes(l))return u=a(i,e,t),u===0?(0,Tg.default)(c,l):u;if(c!==l)return(0,Tg.default)(c,l);if(c===`Complex`)return Og(e,t);if(c===`Unit`)return e.equalBase(t)?i(e.value,t.value):o(i,e.formatUnits(),t.formatUnits());if(c===`boolean`)return r(e,t);if(c===`string`)return(0,Tg.default)(e,t);if(c===`Object`)return s(i,e,t);if(c===`null`||c===`undefined`)return 0;throw TypeError(`Unsupported type of value "`+c+`"`)}function a(e,t,n){return Rr(t)&&Rr(n)?o(e,t.toJSON().values,n.toJSON().values):Rr(t)?a(e,t.toArray(),n):Rr(n)?a(e,t,n.toArray()):Lr(t)?a(e,t.toJSON().data,n):Lr(n)?a(e,t,n.toJSON().data):Array.isArray(t)?Array.isArray(n)?o(e,t,n):a(e,t,[n]):a(e,[t],n)}function o(e,t,n){for(var r=0,i=Math.min(t.length,n.length);r<i;r++){var a=e(t[r],n[r]);if(a!==0)return a}return t.length>n.length?1:t.length<n.length?-1:0}function s(e,t,n){var r=Object.keys(t),i=Object.keys(n);r.sort(Tg.default),i.sort(Tg.default);var a=o(e,r,i);if(a!==0)return a;for(var s=0;s<r.length;s++){var c=e(t[r[s]],n[i[s]]);if(c!==0)return c}return 0}});function Og(e,t){return e.re>t.re?1:e.re<t.re?-1:e.im>t.im?1:e.im<t.im?-1:0}var kg=`compareText`,Ag=[`typed`,`matrix`,`concat`];rc.signature=`any, any`;var jg=J(kg,Ag,e=>{var{typed:t,matrix:n,concat:r}=e;return t(kg,rc,wf({typed:t,matrix:n,concat:r})({elop:rc,Ds:!0}))}),Mg=`equal`,Ng=J(Mg,[`typed`,`matrix`,`equalScalar`,`DenseMatrix`,`SparseMatrix`],e=>{var{typed:t,matrix:n,equalScalar:r,DenseMatrix:i,concat:a,SparseMatrix:o}=e,s=yf({typed:t}),c=Ep({typed:t,SparseMatrix:o}),l=Yd({typed:t,DenseMatrix:i}),u=wf({typed:t,matrix:n});return t(Mg,Pg({typed:t,equalScalar:r}),u({elop:r,SS:c,DS:s,Ss:l}))}),Pg=J(Mg,[`typed`,`equalScalar`],e=>{var{typed:t,equalScalar:n}=e;return t(Mg,{"any, any":function(e,t){return e===null?t===null:t===null?e===null:e===void 0?t===void 0:t===void 0?e===void 0:n(e,t)}})}),Fg=`equalText`,Ig=J(Fg,[`typed`,`compareText`,`isZero`],e=>{var{typed:t,compareText:n,isZero:r}=e;return t(Fg,{"any, any":function(e,t){return r(n(e,t))}})}),Lg=`smaller`,Rg=J(Lg,[`typed`,`config`,`bignumber`,`matrix`,`DenseMatrix`,`concat`,`SparseMatrix`],e=>{var{typed:t,config:n,bignumber:r,matrix:i,DenseMatrix:a,concat:o,SparseMatrix:s}=e,c=yf({typed:t}),l=Ep({typed:t,SparseMatrix:s}),u=Yd({typed:t,DenseMatrix:a}),d=wf({typed:t,matrix:i,concat:o}),f=ad({typed:t});function p(e,t){return e.lt(t)&&!zu(e,t,n.relTol,n.absTol)}return t(Lg,zg({typed:t,config:n}),{"boolean, boolean":(e,t)=>e<t,"BigNumber, BigNumber":p,"bigint, bigint":(e,t)=>e<t,"Fraction, Fraction":(e,t)=>e.compare(t)===-1,"Fraction, BigNumber":function(e,t){return p(r(e),t)},"BigNumber, Fraction":function(e,t){return p(e,r(t))},"Complex, Complex":function(e,t){throw TypeError(`No ordering relation is defined for complex numbers`)}},f,d({SS:l,DS:c,Ss:u}))}),zg=J(Lg,[`typed`,`config`],e=>{var{typed:t,config:n}=e;return t(Lg,{"number, number":function(e,t){return e<t&&!ra(e,t,n.relTol,n.absTol)}})}),Bg=`smallerEq`,Vg=J(Bg,[`typed`,`config`,`matrix`,`DenseMatrix`,`concat`,`SparseMatrix`],e=>{var{typed:t,config:n,matrix:r,DenseMatrix:i,concat:a,SparseMatrix:o}=e,s=yf({typed:t}),c=Ep({typed:t,SparseMatrix:o}),l=Yd({typed:t,DenseMatrix:i}),u=wf({typed:t,matrix:r,concat:a}),d=ad({typed:t});return t(Bg,Hg({typed:t,config:n}),{"boolean, boolean":(e,t)=>e<=t,"BigNumber, BigNumber":function(e,t){return e.lte(t)||zu(e,t,n.relTol,n.absTol)},"bigint, bigint":(e,t)=>e<=t,"Fraction, Fraction":(e,t)=>e.compare(t)!==1,"Complex, Complex":function(){throw TypeError(`No ordering relation is defined for complex numbers`)}},d,u({SS:c,DS:s,Ss:l}))}),Hg=J(Bg,[`typed`,`config`],e=>{var{typed:t,config:n}=e;return t(Bg,{"number, number":function(e,t){return e<=t||ra(e,t,n.relTol,n.absTol)}})}),Ug=`larger`,Wg=J(Ug,[`typed`,`config`,`bignumber`,`matrix`,`DenseMatrix`,`concat`,`SparseMatrix`],e=>{var{typed:t,config:n,bignumber:r,matrix:i,DenseMatrix:a,concat:o,SparseMatrix:s}=e,c=yf({typed:t}),l=Ep({typed:t,SparseMatrix:s}),u=Yd({typed:t,DenseMatrix:a}),d=wf({typed:t,matrix:i,concat:o}),f=ad({typed:t});function p(e,t){return e.gt(t)&&!zu(e,t,n.relTol,n.absTol)}return t(Ug,Gg({typed:t,config:n}),{"boolean, boolean":(e,t)=>e>t,"BigNumber, BigNumber":p,"bigint, bigint":(e,t)=>e>t,"Fraction, Fraction":(e,t)=>e.compare(t)===1,"Fraction, BigNumber":function(e,t){return p(r(e),t)},"BigNumber, Fraction":function(e,t){return p(e,r(t))},"Complex, Complex":function(){throw TypeError(`No ordering relation is defined for complex numbers`)}},f,d({SS:l,DS:c,Ss:u}))}),Gg=J(Ug,[`typed`,`config`],e=>{var{typed:t,config:n}=e;return t(Ug,{"number, number":function(e,t){return e>t&&!ra(e,t,n.relTol,n.absTol)}})}),Kg=`largerEq`,qg=J(Kg,[`typed`,`config`,`matrix`,`DenseMatrix`,`concat`,`SparseMatrix`],e=>{var{typed:t,config:n,matrix:r,DenseMatrix:i,concat:a,SparseMatrix:o}=e,s=yf({typed:t}),c=Ep({typed:t,SparseMatrix:o}),l=Yd({typed:t,DenseMatrix:i}),u=wf({typed:t,matrix:r,concat:a}),d=ad({typed:t});return t(Kg,Jg({typed:t,config:n}),{"boolean, boolean":(e,t)=>e>=t,"BigNumber, BigNumber":function(e,t){return e.gte(t)||zu(e,t,n.relTol,n.absTol)},"bigint, bigint":function(e,t){return e>=t},"Fraction, Fraction":(e,t)=>e.compare(t)!==-1,"Complex, Complex":function(){throw TypeError(`No ordering relation is defined for complex numbers`)}},d,u({SS:c,DS:s,Ss:l}))}),Jg=J(Kg,[`typed`,`config`],e=>{var{typed:t,config:n}=e;return t(Kg,{"number, number":function(e,t){return e>=t||ra(e,t,n.relTol,n.absTol)}})}),Yg=`deepEqual`,Xg=J(Yg,[`typed`,`equal`],e=>{var{typed:t,equal:n}=e;return t(Yg,{"any, any":function(e,t){return r(e.valueOf(),t.valueOf())}});function r(e,t){if(Array.isArray(e))if(Array.isArray(t)){var i=e.length;if(i!==t.length)return!1;for(var a=0;a<i;a++)if(!r(e[a],t[a]))return!1;return!0}else return!1;else if(Array.isArray(t))return!1;else return n(e,t)}}),Zg=`unequal`,Qg=J(Zg,[`typed`,`config`,`equalScalar`,`matrix`,`DenseMatrix`,`concat`,`SparseMatrix`],e=>{var{typed:t,config:n,equalScalar:r,matrix:i,DenseMatrix:a,concat:o,SparseMatrix:s}=e,c=yf({typed:t}),l=Ep({typed:t,SparseMatrix:s}),u=Yd({typed:t,DenseMatrix:a}),d=wf({typed:t,matrix:i,concat:o});return t(Zg,$g({typed:t,equalScalar:r}),d({elop:f,SS:l,DS:c,Ss:u}));function f(e,t){return!r(e,t)}}),$g=J(Zg,[`typed`,`equalScalar`],e=>{var{typed:t,equalScalar:n}=e;return t(Zg,{"any, any":function(e,t){return e===null?t!==null:t===null?e!==null:e===void 0?t!==void 0:t===void 0?e!==void 0:!n(e,t)}})}),e_=`partitionSelect`,t_=J(e_,[`typed`,`isNumeric`,`isNaN`,`compare`],e=>{var{typed:t,isNumeric:n,isNaN:r,compare:i}=e,a=i,o=(e,t)=>-i(e,t);return t(e_,{"Array | Matrix, number":function(e,t){return s(e,t,a)},"Array | Matrix, number, string":function(e,t,n){if(n===`asc`)return s(e,t,a);if(n===`desc`)return s(e,t,o);throw Error(`Compare string must be "asc" or "desc"`)},"Array | Matrix, number, function":s});function s(e,t,n){if(!Ri(t)||t<0)throw Error(`k must be a non-negative integer`);if(Fr(e)){if(e.size().length>1)throw Error(`Only one dimensional matrices supported`);return c(e.valueOf(),t,n)}if(Array.isArray(e))return c(e,t,n)}function c(e,t,i){if(t>=e.length)throw Error(`k out of bounds`);for(var a=0;a<e.length;a++)if(n(e[a])&&r(e[a]))return e[a];for(var o=0,s=e.length-1;o<s;){for(var c=o,l=s,u=e[Math.floor(Math.random()*(s-o+1))+o];c<l;)if(i(e[c],u)>=0){var d=e[l];e[l]=e[c],e[c]=d,--l}else ++c;i(e[c],u)>0&&--c,t<=c?s=c:o=c+1}return e[t]}}),n_=`sort`,r_=J(n_,[`typed`,`matrix`,`compare`,`compareNatural`],e=>{var{typed:t,matrix:n,compare:r,compareNatural:i}=e,a=r,o=(e,t)=>-r(e,t);return t(n_,{Array:function(e){return c(e),e.sort(a)},Matrix:function(e){return l(e),n(e.toArray().sort(a),e.storage())},"Array, function":function(e,t){return c(e),e.sort(t)},"Matrix, function":function(e,t){return l(e),n(e.toArray().sort(t),e.storage())},"Array, string":function(e,t){return c(e),e.sort(s(t))},"Matrix, string":function(e,t){return l(e),n(e.toArray().sort(s(t)),e.storage())}});function s(e){if(e===`asc`)return a;if(e===`desc`)return o;if(e===`natural`)return i;throw Error(`String "asc", "desc", or "natural" expected`)}function c(e){if(oc(e).length!==1)throw Error(`One dimensional array expected`)}function l(e){if(e.size().length!==1)throw Error(`One dimensional matrix expected`)}}),i_=`max`,a_=J(i_,[`typed`,`config`,`numeric`,`larger`,`isNaN`],e=>{var{typed:t,config:n,numeric:r,larger:i,isNaN:a}=e;return t(i_,{"Array | Matrix":s,"Array | Matrix, number | BigNumber":function(e,t){return el(e,t.valueOf(),o)},"...":function(e){if(Zc(e))throw TypeError(`Scalar values expected in function max`);return s(e)}});function o(e,t){try{return i(e,t)?e:t}catch(e){throw gh(e,`max`,t)}}function s(e){var t;if(Qc(e,function(e){try{(a(e)||t===void 0||i(e,t))&&(t=e)}catch(t){throw gh(t,`max`,e)}}),t===void 0)throw Error(`Cannot calculate max of an empty array`);return typeof t==`string`&&(t=r(t,zi(t,n))),t}}),o_=`min`,s_=J(o_,[`typed`,`config`,`numeric`,`smaller`,`isNaN`],e=>{var{typed:t,config:n,numeric:r,smaller:i,isNaN:a}=e;return t(o_,{"Array | Matrix":s,"Array | Matrix, number | BigNumber":function(e,t){return el(e,t.valueOf(),o)},"...":function(e){if(Zc(e))throw TypeError(`Scalar values expected in function min`);return s(e)}});function o(e,t){try{return i(e,t)?e:t}catch(e){throw gh(e,`min`,t)}}function s(e){var t;if(Qc(e,function(e){try{(a(e)||t===void 0||i(e,t))&&(t=e)}catch(t){throw gh(t,`min`,e)}}),t===void 0)throw Error(`Cannot calculate min of an empty array`);return typeof t==`string`&&(t=r(t,zi(t,n))),t}}),c_=J(`ImmutableDenseMatrix`,[`smaller`,`DenseMatrix`],e=>{var{smaller:t,DenseMatrix:n}=e;function r(e,t){if(!(this instanceof r))throw SyntaxError(`Constructor must be called with the new operator`);if(t&&!Nr(t))throw Error(`Invalid datatype: `+t);if(Fr(e)||Pr(e)){var i=new n(e,t);this._data=i._data,this._size=i._size,this._datatype=i._datatype,this._min=null,this._max=null}else if(e&&Pr(e.data)&&Pr(e.size))this._data=e.data,this._size=e.size,this._datatype=e.datatype,this._min=e.min===void 0?null:e.min,this._max=e.max===void 0?null:e.max;else if(e)throw TypeError(`Unsupported type of data (`+_i(e)+`)`);else this._data=[],this._size=[0],this._datatype=t,this._min=null,this._max=null}return r.prototype=new n,r.prototype.type=`ImmutableDenseMatrix`,r.prototype.isImmutableDenseMatrix=!0,r.prototype.subset=function(e){switch(arguments.length){case 1:var t=n.prototype.subset.call(this,e);return Fr(t)?new r({data:t._data,size:t._size,datatype:t._datatype}):t;case 2:case 3:throw Error(`Cannot invoke set subset on an Immutable Matrix instance`);default:throw SyntaxError(`Wrong number of arguments`)}},r.prototype.set=function(){throw Error(`Cannot invoke set on an Immutable Matrix instance`)},r.prototype.resize=function(){throw Error(`Cannot invoke resize on an Immutable Matrix instance`)},r.prototype.reshape=function(){throw Error(`Cannot invoke reshape on an Immutable Matrix instance`)},r.prototype.clone=function(){return new r({data:vi(this._data),size:vi(this._size),datatype:this._datatype})},r.prototype.toJSON=function(){return{mathjs:`ImmutableDenseMatrix`,data:this._data,size:this._size,datatype:this._datatype}},r.fromJSON=function(e){return new r(e)},r.prototype.swapRows=function(){throw Error(`Cannot invoke swapRows on an Immutable Matrix instance`)},r.prototype.min=function(){if(this._min===null){var e=null;this.forEach(function(n){(e===null||t(n,e))&&(e=n)}),this._min=e===null?void 0:e}return this._min},r.prototype.max=function(){if(this._max===null){var e=null;this.forEach(function(n){(e===null||t(e,n))&&(e=n)}),this._max=e===null?void 0:e}return this._max},r},{isClass:!0}),l_=J(`Index`,[`ImmutableDenseMatrix`,`getMatrixDataType`],e=>{var{ImmutableDenseMatrix:t,getMatrixDataType:n}=e;function r(){if(!(this instanceof r))throw SyntaxError(`Constructor must be called with the new operator`);this._dimensions=[],this._sourceSize=[],this._isScalar=!0;for(var e=0,t=arguments.length;e<t;e++){var a=e<0||arguments.length<=e?void 0:arguments[e],o=Pr(a),s=Fr(a),c=typeof a,l=null;if(zr(a))this._dimensions.push(a),this._isScalar=!1;else if(o||s){var u=void 0;this._isScalar=!1,n(a)===`boolean`?(o&&(u=i(u_(a).valueOf())),s&&(u=i(u_(a._data).valueOf())),l=a.valueOf().length):u=i(a.valueOf()),this._dimensions.push(u)}else if(c===`number`)this._dimensions.push(a);else if(c===`bigint`)this._dimensions.push(Number(a));else if(c===`string`)this._dimensions.push(a);else throw TypeError(`Dimension must be an Array, Matrix, number, bigint, string, or Range`);this._sourceSize.push(l)}}r.prototype.type=`Index`,r.prototype.isIndex=!0;function i(e){for(var n=0,r=e.length;n<r;n++)if(!Dr(e[n])||!Ri(e[n]))throw TypeError(`Index parameters must be positive integer numbers`);var i=new t;return i._data=e,i._size=[e.length],i}return r.prototype.clone=function(){var e=new r;return e._dimensions=vi(this._dimensions),e._isScalar=this._isScalar,e._sourceSize=this._sourceSize,e},r.create=function(e){var t=new r;return r.apply(t,e),t},r.prototype.size=function(){for(var e=[],t=0,n=this._dimensions.length;t<n;t++){var r=this._dimensions[t];e[t]=Nr(r)||Dr(r)?1:r.size()[0]}return e},r.prototype.max=function(){for(var e=[],t=0,n=this._dimensions.length;t<n;t++){var r=this._dimensions[t];e[t]=Nr(r)||Dr(r)?r:r.max()}return e},r.prototype.min=function(){for(var e=[],t=0,n=this._dimensions.length;t<n;t++){var r=this._dimensions[t];e[t]=Nr(r)||Dr(r)?r:r.min()}return e},r.prototype.forEach=function(e){for(var t=0,n=this._dimensions.length;t<n;t++)e(this._dimensions[t],t,this)},r.prototype.dimension=function(e){return Dr(e)?this._dimensions[e]??null:null},r.prototype.isObjectProperty=function(){return this._dimensions.length===1&&Nr(this._dimensions[0])},r.prototype.getObjectProperty=function(){return this.isObjectProperty()?this._dimensions[0]:null},r.prototype.isScalar=function(){return this._isScalar},r.prototype.toArray=function(){for(var e=[],t=0,n=this._dimensions.length;t<n;t++){var r=this._dimensions[t];e.push(Nr(r)||Dr(r)?r:r.toArray())}return e},r.prototype.valueOf=r.prototype.toArray,r.prototype.toString=function(){for(var e=[],t=0,n=this._dimensions.length;t<n;t++){var r=this._dimensions[t];Nr(r)?e.push(JSON.stringify(r)):e.push(r.toString())}return`[`+e.join(`, `)+`]`},r.prototype.toJSON=function(){return{mathjs:`Index`,dimensions:this._dimensions}},r.fromJSON=function(e){return r.create(e.dimensions)},r},{isClass:!0});function u_(e){var t=[];return e.forEach((e,n)=>{e&&t.push(n)}),t}var d_=J(`FibonacciHeap`,[`smaller`,`larger`],e=>{var{smaller:t,larger:n}=e,r=1/Math.log((1+Math.sqrt(5))/2);function i(){if(!(this instanceof i))throw SyntaxError(`Constructor must be called with the new operator`);this._minimum=null,this._size=0}i.prototype.type=`FibonacciHeap`,i.prototype.isFibonacciHeap=!0,i.prototype.insert=function(e,n){var r={key:e,value:n,degree:0};if(this._minimum){var i=this._minimum;r.left=i,r.right=i.right,i.right=r,r.right.left=r,t(e,i.key)&&(this._minimum=r)}else r.left=r,r.right=r,this._minimum=r;return this._size++,r},i.prototype.size=function(){return this._size},i.prototype.clear=function(){this._minimum=null,this._size=0},i.prototype.isEmpty=function(){return this._size===0},i.prototype.extractMinimum=function(){var e=this._minimum;if(e===null)return e;for(var t=this._minimum,n=e.degree,r=e.child;n>0;){var i=r.right;r.left.right=r.right,r.right.left=r.left,r.left=t,r.right=t.right,t.right=r,r.right.left=r,r.parent=null,r=i,n--}return e.left.right=e.right,e.right.left=e.left,e===e.right?t=null:(t=e.right,t=l(t,this._size)),this._size--,this._minimum=t,e},i.prototype.remove=function(e){this._minimum=a(this._minimum,e,-1),this.extractMinimum()};function a(e,n,r){n.key=r;var i=n.parent;return i&&t(n.key,i.key)&&(o(e,n,i),s(e,i)),t(n.key,e.key)&&(e=n),e}function o(e,t,n){t.left.right=t.right,t.right.left=t.left,n.degree--,n.child===t&&(n.child=t.right),n.degree===0&&(n.child=null),t.left=e,t.right=e.right,e.right=t,t.right.left=t,t.parent=null,t.mark=!1}function s(e,t){var n=t.parent;n&&(t.mark?(o(e,t,n),s(n)):t.mark=!0)}var c=function(e,t){e.left.right=e.right,e.right.left=e.left,e.parent=t,t.child?(e.left=t.child,e.right=t.child.right,t.child.right=e,e.right.left=e):(t.child=e,e.right=e,e.left=e),t.degree++,e.mark=!1};function l(e,i){var a=Math.floor(Math.log(i)*r)+1,o=Array(a),s=0,l=e;if(l)for(s++,l=l.right;l!==e;)s++,l=l.right;for(var u;s>0;){for(var d=l.degree,f=l.right;u=o[d],u;){if(n(l.key,u.key)){var p=u;u=l,l=p}c(u,l),o[d]=null,d++}o[d]=l,l=f,s--}e=null;for(var m=0;m<a;m++)u=o[m],u&&(e?(u.left.right=u.right,u.right.left=u.left,u.left=e,u.right=e.right,e.right=u,u.right.left=u,t(u.key,e.key)&&(e=u)):e=u);return e}return i},{isClass:!0}),f_=J(`Spa`,[`addScalar`,`equalScalar`,`FibonacciHeap`],e=>{var{addScalar:t,equalScalar:n,FibonacciHeap:r}=e;function i(){if(!(this instanceof i))throw SyntaxError(`Constructor must be called with the new operator`);this._values=[],this._heap=new r}return i.prototype.type=`Spa`,i.prototype.isSpa=!0,i.prototype.set=function(e,t){if(this._values[e])this._values[e].value=t;else{var n=this._heap.insert(e,t);this._values[e]=n}},i.prototype.get=function(e){var t=this._values[e];return t?t.value:0},i.prototype.accumulate=function(e,n){var r=this._values[e];r?r.value=t(r.value,n):(r=this._heap.insert(e,n),this._values[e]=r)},i.prototype.forEach=function(e,t,r){var i=this._heap,a=this._values,o=[],s=i.extractMinimum();for(s&&o.push(s);s&&s.key<=t;)s.key>=e&&(n(s.value,0)||r(s.key,s.value,this)),s=i.extractMinimum(),s&&o.push(s);for(var c=0;c<o.length;c++){var l=o[c];s=i.insert(l.key,l.value),a[s.key]=s}},i.prototype.swap=function(e,t){var n=this._values[e],r=this._values[t];if(!n&&r)n=this._heap.insert(e,r.value),this._heap.remove(r),this._values[e]=n,this._values[t]=void 0;else if(n&&!r)r=this._heap.insert(t,n.value),this._heap.remove(n),this._values[t]=r,this._values[e]=void 0;else if(n&&r){var i=n.value;n.value=r.value,r.value=i}},i},{isClass:!0});function p_(e){var t=0,n=1,r=Object.create(null),i=Object.create(null),a=0,o=function(e){var o=i[e];if(o&&(delete r[o],delete i[e],--t,n===o)){if(!t){a=0,n=1;return}for(;!Object.prototype.hasOwnProperty.call(r,++n););}};return e=Math.abs(e),{hit:function(s){var c=i[s],l=++a;if(r[l]=s,i[s]=l,!c)return++t,t<=e?void 0:(s=r[n],o(s),s);if(delete r[c],n===c)for(;!Object.prototype.hasOwnProperty.call(r,++n););},delete:o,clear:function(){t=a=0,n=1,r=Object.create(null),i=Object.create(null)}}}function m_(e){var{hasher:t,limit:n}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return n??=1/0,t??=JSON.stringify,function r(){typeof r.cache!=`object`&&(r.cache={values:new Map,lru:p_(n||1/0)});var i=[...arguments],a=t(i);if(r.cache.values.has(a))return r.cache.lru.hit(a),r.cache.values.get(a);var o=e.apply(e,i);return r.cache.values.set(a,o),r.cache.values.delete(r.cache.lru.hit(a)),o}}var h_=m_(function(e){return new e(1).exp()},{hasher:y_}),g_=m_(function(e){return new e(1).plus(new e(5).sqrt()).div(2)},{hasher:y_}),__=m_(function(e){return e.acos(-1)},{hasher:y_}),v_=m_(function(e){return __(e).times(2)},{hasher:y_});function y_(e){return e[0].precision}function b_(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function x_(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?b_(Object(n),!0).forEach(function(t){nh(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):b_(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}var S_=J(`Unit`,[`?on`,`config`,`addScalar`,`subtractScalar`,`multiplyScalar`,`divideScalar`,`pow`,`abs`,`fix`,`round`,`equal`,`isNumeric`,`format`,`number`,`Complex`,`BigNumber`,`Fraction`],e=>{var{on:t,config:n,addScalar:r,subtractScalar:i,multiplyScalar:a,divideScalar:o,pow:s,abs:c,fix:l,round:u,equal:d,isNumeric:f,format:p,number:m,Complex:h,BigNumber:g,Fraction:_}=e,v=m,y=!1,b=!0;function x(e,t){if(!(this instanceof x))throw Error(`Constructor must be called with the new operator`);if(!(e==null||f(e)||Ar(e)))throw TypeError(`First parameter in Unit constructor must be number, BigNumber, Fraction, Complex, or undefined`);if(this.fixPrefix=y,this.skipAutomaticSimplification=b,t===void 0)this.units=[],this.dimensions=B.map(e=>0);else if(typeof t==`string`){var n=x.parse(t);this.units=n.units,this.dimensions=n.dimensions}else if(Mr(t)&&t.value===null)this.fixPrefix=t.fixPrefix,this.skipAutomaticSimplification=t.skipAutomaticSimplification,this.dimensions=t.dimensions.slice(0),this.units=t.units.map(e=>ur({},e));else throw TypeError(`Second parameter in Unit constructor must be a string or valueless Unit`);this.value=this._normalize(e)}Object.defineProperty(x,`name`,{value:`Unit`}),x.prototype.constructor=x,x.prototype.type=`Unit`,x.prototype.isUnit=!0;var S,C,w;function T(){for(;w===` `||w===` `;)O()}function E(e){return e>=`0`&&e<=`9`||e===`.`}function D(e){return e>=`0`&&e<=`9`}function O(){C++,w=S.charAt(C)}function k(e){C=e,w=S.charAt(C)}function A(){var e=``,t=C;if(w===`+`?O():w===`-`&&(e+=w,O()),!E(w))return k(t),null;if(w===`.`){if(e+=w,O(),!D(w))return k(t),null}else{for(;D(w);)e+=w,O();w===`.`&&(e+=w,O())}for(;D(w);)e+=w,O();if(w===`E`||w===`e`){var n=``,r=C;if(n+=w,O(),(w===`+`||w===`-`)&&(n+=w,O()),!D(w))return k(r),e;for(e+=n;D(w);)e+=w,O()}return e}function j(){for(var e=``;D(w)||x.isValidAlpha(w);)e+=w,O();var t=e.charAt(0);return x.isValidAlpha(t)?e:null}function M(e){return w===e?(O(),e):null}x.parse=function(e,t){if(t||={},S=e,C=-1,w=``,typeof S!=`string`)throw TypeError(`Invalid argument in Unit.parse, string expected`);var r=new x;r.units=[];var i=1,a=!1;O(),T();var o=A(),s=null;if(o){if(n.number===`BigNumber`)s=new g(o);else if(n.number===`Fraction`)try{s=new _(o)}catch{s=parseFloat(o)}else s=parseFloat(o);T(),M(`*`)?(i=1,a=!0):M(`/`)&&(i=-1,a=!0)}for(var c=[],l=1;;){for(T();w===`(`;)c.push(i),l*=i,i=1,O(),T();var u=void 0;if(w){var d=w;if(u=j(),u===null)throw SyntaxError(`Unexpected "`+d+`" in "`+S+`" at index `+C.toString())}else break;var f=N(u);if(f===null)throw SyntaxError(`Unit "`+u+`" not found.`);var p=i*l;if(T(),M(`^`)){T();var m=A();if(m===null)throw SyntaxError(`In "`+e+`", "^" must be followed by a floating-point number`);p*=m}r.units.push({unit:f.unit,prefix:f.prefix,power:p});for(var h=0;h<B.length;h++)r.dimensions[h]+=(f.unit.dimensions[h]||0)*p;for(T();w===`)`;){if(c.length===0)throw SyntaxError(`Unmatched ")" in "`+S+`" at index `+C.toString());l/=c.pop(),O(),T()}if(a=!1,M(`*`)?(i=1,a=!0):M(`/`)?(i=-1,a=!0):i=1,f.unit.base){var v=f.unit.base.key;ie.auto[v]={unit:f.unit,prefix:f.prefix}}}if(T(),w)throw SyntaxError(`Could not parse: "`+e+`"`);if(a)throw SyntaxError(`Trailing characters: "`+e+`"`);if(c.length!==0)throw SyntaxError(`Unmatched "(" in "`+S+`"`);if(r.units.length===0&&!t.allowNoUnits)throw SyntaxError(`"`+e+`" contains no units`);return r.value=s===void 0?null:r._normalize(s),r},x.prototype.clone=function(){var e=new x;e.fixPrefix=this.fixPrefix,e.skipAutomaticSimplification=this.skipAutomaticSimplification,e.value=vi(this.value),e.dimensions=this.dimensions.slice(0),e.units=[];for(var t=0;t<this.units.length;t++)for(var n in e.units[t]={},this.units[t])Ei(this.units[t],n)&&(e.units[t][n]=this.units[t][n]);return e},x.prototype.valueType=function(){return _i(this.value)},x.prototype._isDerived=function(){return this.units.length===0?!1:this.units.length>1||Math.abs(this.units[0].power-1)>1e-15},x.prototype._normalize=function(e){if(e==null||this.units.length===0)return e;for(var t=e,n=x._getNumberConverter(_i(e)),r=0;r<this.units.length;r++){var i=n(this.units[r].unit.value),o=n(this.units[r].prefix.value),c=n(this.units[r].power);t=a(t,s(a(i,o),c))}return t},x.prototype._denormalize=function(e,t){if(e==null||this.units.length===0)return e;for(var n=e,r=x._getNumberConverter(_i(e)),i=0;i<this.units.length;i++){var c=r(this.units[i].unit.value),l=r(this.units[i].prefix.value),u=r(this.units[i].power);n=o(n,s(a(c,l),u))}return n};var N=m_(e=>{if(Ei(H,e)){var t=H[e];return{unit:t,prefix:t.prefixes[``]}}for(var n in H)if(Ei(H,n)&&Ys(e,n)){var r=H[n],i=e.length-n.length,a=e.substring(0,i),o=Ei(r.prefixes,a)?r.prefixes[a]:void 0;if(o!==void 0)return{unit:r,prefix:o}}return null},{hasher:e=>e[0],limit:100});x.isValuelessUnit=function(e){return N(e)!==null},x.prototype.hasBase=function(e){if(typeof e==`string`&&(e=V[e]),!e)return!1;for(var t=0;t<B.length;t++)if(Math.abs((this.dimensions[t]||0)-(e.dimensions[t]||0))>1e-12)return!1;return!0},x.prototype.equalBase=function(e){for(var t=0;t<B.length;t++)if(Math.abs((this.dimensions[t]||0)-(e.dimensions[t]||0))>1e-12)return!1;return!0},x.prototype.equals=function(e){return this.equalBase(e)&&d(this.value,e.value)},x.prototype.multiply=function(e){for(var t=this.clone(),n=Mr(e)?e:new x(e),r=0;r<B.length;r++)t.dimensions[r]=(this.dimensions[r]||0)+(n.dimensions[r]||0);for(var i=0;i<n.units.length;i++){var o=x_({},n.units[i]);t.units.push(o)}return this.value!==null||n.value!==null?t.value=a(this.value===null?this._normalize(F(n.value)):this.value,n.value===null?n._normalize(F(this.value)):n.value):t.value=null,Mr(e)&&(t.skipAutomaticSimplification=!1),P(t)},x.prototype.divideInto=function(e){return new x(e).divide(this)},x.prototype.divide=function(e){for(var t=this.clone(),n=Mr(e)?e:new x(e),r=0;r<B.length;r++)t.dimensions[r]=(this.dimensions[r]||0)-(n.dimensions[r]||0);for(var i=0;i<n.units.length;i++){var a=x_(x_({},n.units[i]),{},{power:-n.units[i].power});t.units.push(a)}return this.value!==null||n.value!==null?t.value=o(this.value===null?this._normalize(F(n.value)):this.value,n.value===null?n._normalize(F(this.value)):n.value):t.value=null,Mr(e)&&(t.skipAutomaticSimplification=!1),P(t)},x.prototype.pow=function(e){for(var t=this.clone(),n=0;n<B.length;n++)t.dimensions[n]=(this.dimensions[n]||0)*e;for(var r=0;r<t.units.length;r++)t.units[r].power*=e;return t.value===null?t.value=null:t.value=s(t.value,e),t.skipAutomaticSimplification=!1,P(t)};function P(e){return e.equalBase(V.NONE)&&e.value!==null&&!n.predictable?e.value:e}function F(e){return x._getNumberConverter(_i(e))(1)}x.prototype.abs=function(){var e=this.clone();if(e.value!==null)if(e._isDerived()||e.units.length===0||e.units[0].unit.offset===0)e.value=c(e.value);else{var t=e._numberConverter(),n=a(t(e.units[0].unit.value),t(e.units[0].unit.offset));e.value=i(c(r(e.value,n)),n)}for(var o in e.units)(e.units[o].unit.name===`VA`||e.units[o].unit.name===`VAR`)&&(e.units[o].unit=H.W);return e},x.prototype.to=function(e){var t=this.value===null?this._normalize(1):this.value,n;if(typeof e==`string`)n=x.parse(e);else if(Mr(e))n=e.clone();else throw Error(`String or Unit expected as parameter`);if(!this.equalBase(n))throw Error(`Units do not match ('${n.toString()}' != '${this.toString()}')`);if(n.value!==null)throw Error(`Cannot convert to a unit with a value`);if(this.value===null||this._isDerived()||this.units.length===0||n.units.length===0||this.units[0].unit.offset===n.units[0].unit.offset)n.value=vi(t);else{var o=x._getNumberConverter(_i(t)),s=this.units[0].unit.value,c=this.units[0].unit.offset,l=a(s,c),u=n.units[0].unit.value,d=n.units[0].unit.offset,f=a(u,d);n.value=r(t,o(i(l,f)))}return n.fixPrefix=!0,n.skipAutomaticSimplification=!0,n},x.prototype.toNumber=function(e){return v(this.toNumeric(e))},x.prototype.toNumeric=function(e){var t=e?this.to(e):this.clone();return t._isDerived()||t.units.length===0?t._denormalize(t.value):t._denormalize(t.value,t.units[0].prefix.value)},x.prototype.toString=function(){return this.format()},x.prototype.toJSON=function(){return{mathjs:`Unit`,value:this._denormalize(this.value),unit:this.units.length>0?this.formatUnits():null,fixPrefix:this.fixPrefix,skipSimp:this.skipAutomaticSimplification}},x.fromJSON=function(e){var t=new x(e.value,e.unit??void 0);return t.fixPrefix=e.fixPrefix??y,t.skipAutomaticSimplification=e.skipSimp??b,t},x.prototype.valueOf=x.prototype.toString,x.prototype.simplify=function(){var e=this.clone(),t=[],n;for(var r in U)if(Ei(U,r)&&e.hasBase(V[r])){n=r;break}if(n===`NONE`)e.units=[];else{var i;if(n&&Ei(U,n)&&(i=U[n]),i)e.units=[{unit:i.unit,prefix:i.prefix,power:1}];else{for(var a=!1,o=0;o<B.length;o++){var s=B[o];Math.abs(e.dimensions[o]||0)>1e-12&&(Ei(U,s)?t.push({unit:U[s].unit,prefix:U[s].prefix,power:e.dimensions[o]||0}):a=!0)}t.length<e.units.length&&!a&&(e.units=t)}}return e},x.prototype.toSI=function(){for(var e=this.clone(),t=[],n=0;n<B.length;n++){var r=B[n];if(Math.abs(e.dimensions[n]||0)>1e-12)if(Ei(ie.si,r))t.push({unit:ie.si[r].unit,prefix:ie.si[r].prefix,power:e.dimensions[n]||0});else throw Error(`Cannot express custom unit `+r+` in SI units`)}return e.units=t,e.fixPrefix=!0,e.skipAutomaticSimplification=!0,this.value===null?e:(e.value=null,this.to(e))},x.prototype.formatUnits=function(){for(var e=``,t=``,n=0,r=0,i=0;i<this.units.length;i++)this.units[i].power>0?(n++,e+=` `+this.units[i].prefix.name+this.units[i].unit.name,Math.abs(this.units[i].power-1)>1e-15&&(e+=`^`+this.units[i].power)):this.units[i].power<0&&r++;if(r>0)for(var a=0;a<this.units.length;a++)this.units[a].power<0&&(n>0?(t+=` `+this.units[a].prefix.name+this.units[a].unit.name,Math.abs(this.units[a].power+1)>1e-15&&(t+=`^`+-this.units[a].power)):(t+=` `+this.units[a].prefix.name+this.units[a].unit.name,t+=`^`+this.units[a].power));e=e.substr(1),t=t.substr(1),n>1&&r>0&&(e=`(`+e+`)`),r>1&&n>0&&(t=`(`+t+`)`);var o=e;return n>0&&r>0&&(o+=` / `),o+=t,o},x.prototype.toBest=function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(e&&!Array.isArray(e))throw Error(`Invalid unit type. Expected string or Unit.`);var n=this.units[0].unit.prefixes;if(e&&e.length>0){var r=e.map(e=>{var t=null;if(typeof e==`string`){if(t=x.parse(e),!t)throw Error(`Invalid unit type. Expected compatible string or Unit.`)}else if(!Mr(e))throw Error(`Invalid unit type. Expected compatible string or Unit.`);t===null&&(t=e.clone());try{return this.to(t.formatUnits()),t}catch{throw Error(`Invalid unit type. Expected compatible string or Unit.`)}}).map(e=>e.units[0].prefix);this.units[0].unit.prefixes=r.reduce((e,t)=>(e[t.name]=t,e),{}),this.units[0].prefix=r[0]}var i=I(this,t).simp;return this.units[0].unit.prefixes=n,i.fixPrefix=!0,i},x.prototype.format=function(e){var{simp:t,valueStr:n,unitStr:r}=I(this,e),i=n;return t.value&&Ar(t.value)&&(i=`(`+i+`)`),r.length>0&&i.length>0&&(i+=` `),i+=r,i};function I(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},n=e.skipAutomaticSimplification||e.value===null?e.clone():e.simplify();L(n),R(n,t.offset);var r=n._denormalize(n.value);return{simp:n,valueStr:n.value===null?``:p(r,t||{}),unitStr:n.formatUnits()}}function L(e){var t=!1;for(var n in e.value!==void 0&&e.value!==null&&Ar(e.value)&&(t=Math.abs(e.value.re)<1e-14),e.units)Ei(e.units,n)&&e.units[n].unit&&(e.units[n].unit.name===`VA`&&t?e.units[n].unit=H.VAR:e.units[n].unit.name===`VAR`&&!t&&(e.units[n].unit=H.VA))}function R(e,t){e.units.length===1&&!e.fixPrefix&&Math.abs(e.units[0].power-Math.round(e.units[0].power))<1e-14&&(e.units[0].prefix=e._bestPrefix(t))}x.prototype._bestPrefix=function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:1.2;if(this.units.length!==1||Math.abs(this.units[0].power-Math.round(this.units[0].power))>=1e-14)throw Error(`Can only compute the best prefix for single units with integer powers, like kg, s^2, N^-1, and so forth!`);var t=this.value===null?0:c(this.value),n=c(this.units[0].unit.value),r=this.units[0].prefix;if(t===0)return r;var i=this.units[0].power,a=Math.log(t/(r.value*n)**+i)/Math.LN10-e;if(a>-2.200001&&a<1.800001)return r;a=Math.abs(a);var o=this.units[0].unit.prefixes;for(var s in o)if(Ei(o,s)){var l=o[s];if(l.scientific){var u=Math.abs(Math.log(t/(l.value*n)**+i)/Math.LN10-e);(u<a||u===a&&l.name.length<r.name.length)&&(r=l,a=u)}}return r},x.prototype.splitUnit=function(e){for(var t=this.clone(),n=[],a=0;a<e.length&&(t=t.to(e[a]),a!==e.length-1);a++){var o=t.toNumeric(),s=u(o),c=void 0;c=d(s,o)?s:l(t.toNumeric());var f=new x(c,e[a].toString());n.push(f),t=i(t,f)}for(var p=0,m=0;m<n.length;m++)p=r(p,n[m].value);return d(p,this.value)&&(t.value=0),n.push(t),n};var z={NONE:{"":{name:``,value:1,scientific:!0}},SHORT:{"":{name:``,value:1,scientific:!0},da:{name:`da`,value:10,scientific:!1},h:{name:`h`,value:100,scientific:!1},k:{name:`k`,value:1e3,scientific:!0},M:{name:`M`,value:1e6,scientific:!0},G:{name:`G`,value:1e9,scientific:!0},T:{name:`T`,value:0xe8d4a51000,scientific:!0},P:{name:`P`,value:0x38d7ea4c68000,scientific:!0},E:{name:`E`,value:0xde0b6b3a7640000,scientific:!0},Z:{name:`Z`,value:1e21,scientific:!0},Y:{name:`Y`,value:1e24,scientific:!0},R:{name:`R`,value:1e27,scientific:!0},Q:{name:`Q`,value:1e30,scientific:!0},d:{name:`d`,value:.1,scientific:!1},c:{name:`c`,value:.01,scientific:!1},m:{name:`m`,value:.001,scientific:!0},u:{name:`u`,value:1e-6,scientific:!0},n:{name:`n`,value:1e-9,scientific:!0},p:{name:`p`,value:1e-12,scientific:!0},f:{name:`f`,value:1e-15,scientific:!0},a:{name:`a`,value:1e-18,scientific:!0},z:{name:`z`,value:1e-21,scientific:!0},y:{name:`y`,value:1e-24,scientific:!0},r:{name:`r`,value:1e-27,scientific:!0},q:{name:`q`,value:1e-30,scientific:!0}},LONG:{"":{name:``,value:1,scientific:!0},deca:{name:`deca`,value:10,scientific:!1},hecto:{name:`hecto`,value:100,scientific:!1},kilo:{name:`kilo`,value:1e3,scientific:!0},mega:{name:`mega`,value:1e6,scientific:!0},giga:{name:`giga`,value:1e9,scientific:!0},tera:{name:`tera`,value:0xe8d4a51000,scientific:!0},peta:{name:`peta`,value:0x38d7ea4c68000,scientific:!0},exa:{name:`exa`,value:0xde0b6b3a7640000,scientific:!0},zetta:{name:`zetta`,value:1e21,scientific:!0},yotta:{name:`yotta`,value:1e24,scientific:!0},ronna:{name:`ronna`,value:1e27,scientific:!0},quetta:{name:`quetta`,value:1e30,scientific:!0},deci:{name:`deci`,value:.1,scientific:!1},centi:{name:`centi`,value:.01,scientific:!1},milli:{name:`milli`,value:.001,scientific:!0},micro:{name:`micro`,value:1e-6,scientific:!0},nano:{name:`nano`,value:1e-9,scientific:!0},pico:{name:`pico`,value:1e-12,scientific:!0},femto:{name:`femto`,value:1e-15,scientific:!0},atto:{name:`atto`,value:1e-18,scientific:!0},zepto:{name:`zepto`,value:1e-21,scientific:!0},yocto:{name:`yocto`,value:1e-24,scientific:!0},ronto:{name:`ronto`,value:1e-27,scientific:!0},quecto:{name:`quecto`,value:1e-30,scientific:!0}},SQUARED:{"":{name:``,value:1,scientific:!0},da:{name:`da`,value:100,scientific:!1},h:{name:`h`,value:1e4,scientific:!1},k:{name:`k`,value:1e6,scientific:!0},M:{name:`M`,value:0xe8d4a51000,scientific:!0},G:{name:`G`,value:0xde0b6b3a7640000,scientific:!0},T:{name:`T`,value:1e24,scientific:!0},P:{name:`P`,value:1e30,scientific:!0},E:{name:`E`,value:1e36,scientific:!0},Z:{name:`Z`,value:1e42,scientific:!0},Y:{name:`Y`,value:1e48,scientific:!0},R:{name:`R`,value:1e54,scientific:!0},Q:{name:`Q`,value:1e60,scientific:!0},d:{name:`d`,value:.01,scientific:!1},c:{name:`c`,value:1e-4,scientific:!1},m:{name:`m`,value:1e-6,scientific:!0},u:{name:`u`,value:1e-12,scientific:!0},n:{name:`n`,value:1e-18,scientific:!0},p:{name:`p`,value:1e-24,scientific:!0},f:{name:`f`,value:1e-30,scientific:!0},a:{name:`a`,value:1e-36,scientific:!0},z:{name:`z`,value:1e-42,scientific:!0},y:{name:`y`,value:1e-48,scientific:!0},r:{name:`r`,value:1e-54,scientific:!0},q:{name:`q`,value:1e-60,scientific:!0}},CUBIC:{"":{name:``,value:1,scientific:!0},da:{name:`da`,value:1e3,scientific:!1},h:{name:`h`,value:1e6,scientific:!1},k:{name:`k`,value:1e9,scientific:!0},M:{name:`M`,value:0xde0b6b3a7640000,scientific:!0},G:{name:`G`,value:1e27,scientific:!0},T:{name:`T`,value:1e36,scientific:!0},P:{name:`P`,value:1e45,scientific:!0},E:{name:`E`,value:1e54,scientific:!0},Z:{name:`Z`,value:1e63,scientific:!0},Y:{name:`Y`,value:1e72,scientific:!0},R:{name:`R`,value:1e81,scientific:!0},Q:{name:`Q`,value:1e90,scientific:!0},d:{name:`d`,value:.001,scientific:!1},c:{name:`c`,value:1e-6,scientific:!1},m:{name:`m`,value:1e-9,scientific:!0},u:{name:`u`,value:1e-18,scientific:!0},n:{name:`n`,value:1e-27,scientific:!0},p:{name:`p`,value:1e-36,scientific:!0},f:{name:`f`,value:1e-45,scientific:!0},a:{name:`a`,value:1e-54,scientific:!0},z:{name:`z`,value:1e-63,scientific:!0},y:{name:`y`,value:1e-72,scientific:!0},r:{name:`r`,value:1e-81,scientific:!0},q:{name:`q`,value:1e-90,scientific:!0}},BINARY_SHORT_SI:{"":{name:``,value:1,scientific:!0},k:{name:`k`,value:1e3,scientific:!0},M:{name:`M`,value:1e6,scientific:!0},G:{name:`G`,value:1e9,scientific:!0},T:{name:`T`,value:0xe8d4a51000,scientific:!0},P:{name:`P`,value:0x38d7ea4c68000,scientific:!0},E:{name:`E`,value:0xde0b6b3a7640000,scientific:!0},Z:{name:`Z`,value:1e21,scientific:!0},Y:{name:`Y`,value:1e24,scientific:!0}},BINARY_SHORT_IEC:{"":{name:``,value:1,scientific:!0},Ki:{name:`Ki`,value:1024,scientific:!0},Mi:{name:`Mi`,value:1024**2,scientific:!0},Gi:{name:`Gi`,value:1024**3,scientific:!0},Ti:{name:`Ti`,value:1024**4,scientific:!0},Pi:{name:`Pi`,value:1024**5,scientific:!0},Ei:{name:`Ei`,value:1024**6,scientific:!0},Zi:{name:`Zi`,value:1024**7,scientific:!0},Yi:{name:`Yi`,value:1024**8,scientific:!0}},BINARY_LONG_SI:{"":{name:``,value:1,scientific:!0},kilo:{name:`kilo`,value:1e3,scientific:!0},mega:{name:`mega`,value:1e6,scientific:!0},giga:{name:`giga`,value:1e9,scientific:!0},tera:{name:`tera`,value:0xe8d4a51000,scientific:!0},peta:{name:`peta`,value:0x38d7ea4c68000,scientific:!0},exa:{name:`exa`,value:0xde0b6b3a7640000,scientific:!0},zetta:{name:`zetta`,value:1e21,scientific:!0},yotta:{name:`yotta`,value:1e24,scientific:!0}},BINARY_LONG_IEC:{"":{name:``,value:1,scientific:!0},kibi:{name:`kibi`,value:1024,scientific:!0},mebi:{name:`mebi`,value:1024**2,scientific:!0},gibi:{name:`gibi`,value:1024**3,scientific:!0},tebi:{name:`tebi`,value:1024**4,scientific:!0},pebi:{name:`pebi`,value:1024**5,scientific:!0},exi:{name:`exi`,value:1024**6,scientific:!0},zebi:{name:`zebi`,value:1024**7,scientific:!0},yobi:{name:`yobi`,value:1024**8,scientific:!0}},BTU:{"":{name:``,value:1,scientific:!0},MM:{name:`MM`,value:1e6,scientific:!0}}};z.SHORTLONG=ur({},z.SHORT,z.LONG),z.BINARY_SHORT=ur({},z.BINARY_SHORT_SI,z.BINARY_SHORT_IEC),z.BINARY_LONG=ur({},z.BINARY_LONG_SI,z.BINARY_LONG_IEC);var B=[`MASS`,`LENGTH`,`TIME`,`CURRENT`,`TEMPERATURE`,`LUMINOUS_INTENSITY`,`AMOUNT_OF_SUBSTANCE`,`ANGLE`,`BIT`],V={NONE:{dimensions:[0,0,0,0,0,0,0,0,0]},MASS:{dimensions:[1,0,0,0,0,0,0,0,0]},LENGTH:{dimensions:[0,1,0,0,0,0,0,0,0]},TIME:{dimensions:[0,0,1,0,0,0,0,0,0]},CURRENT:{dimensions:[0,0,0,1,0,0,0,0,0]},TEMPERATURE:{dimensions:[0,0,0,0,1,0,0,0,0]},LUMINOUS_INTENSITY:{dimensions:[0,0,0,0,0,1,0,0,0]},AMOUNT_OF_SUBSTANCE:{dimensions:[0,0,0,0,0,0,1,0,0]},FORCE:{dimensions:[1,1,-2,0,0,0,0,0,0]},SURFACE:{dimensions:[0,2,0,0,0,0,0,0,0]},VOLUME:{dimensions:[0,3,0,0,0,0,0,0,0]},ENERGY:{dimensions:[1,2,-2,0,0,0,0,0,0]},POWER:{dimensions:[1,2,-3,0,0,0,0,0,0]},PRESSURE:{dimensions:[1,-1,-2,0,0,0,0,0,0]},ELECTRIC_CHARGE:{dimensions:[0,0,1,1,0,0,0,0,0]},ELECTRIC_CAPACITANCE:{dimensions:[-1,-2,4,2,0,0,0,0,0]},ELECTRIC_POTENTIAL:{dimensions:[1,2,-3,-1,0,0,0,0,0]},ELECTRIC_RESISTANCE:{dimensions:[1,2,-3,-2,0,0,0,0,0]},ELECTRIC_INDUCTANCE:{dimensions:[1,2,-2,-2,0,0,0,0,0]},ELECTRIC_CONDUCTANCE:{dimensions:[-1,-2,3,2,0,0,0,0,0]},MAGNETIC_FLUX:{dimensions:[1,2,-2,-1,0,0,0,0,0]},MAGNETIC_FLUX_DENSITY:{dimensions:[1,0,-2,-1,0,0,0,0,0]},FREQUENCY:{dimensions:[0,0,-1,0,0,0,0,0,0]},ANGLE:{dimensions:[0,0,0,0,0,0,0,1,0]},BIT:{dimensions:[0,0,0,0,0,0,0,0,1]}};for(var ee in V)Ei(V,ee)&&(V[ee].key=ee);var te={name:``,base:{},value:1,offset:0,dimensions:B.map(e=>0)},H={meter:{name:`meter`,base:V.LENGTH,prefixes:z.LONG,value:1,offset:0},inch:{name:`inch`,base:V.LENGTH,prefixes:z.NONE,value:.0254,offset:0},foot:{name:`foot`,base:V.LENGTH,prefixes:z.NONE,value:.3048,offset:0},yard:{name:`yard`,base:V.LENGTH,prefixes:z.NONE,value:.9144,offset:0},mile:{name:`mile`,base:V.LENGTH,prefixes:z.NONE,value:1609.344,offset:0},link:{name:`link`,base:V.LENGTH,prefixes:z.NONE,value:.201168,offset:0},rod:{name:`rod`,base:V.LENGTH,prefixes:z.NONE,value:5.0292,offset:0},chain:{name:`chain`,base:V.LENGTH,prefixes:z.NONE,value:20.1168,offset:0},angstrom:{name:`angstrom`,base:V.LENGTH,prefixes:z.NONE,value:1e-10,offset:0},m:{name:`m`,base:V.LENGTH,prefixes:z.SHORT,value:1,offset:0},in:{name:`in`,base:V.LENGTH,prefixes:z.NONE,value:.0254,offset:0},ft:{name:`ft`,base:V.LENGTH,prefixes:z.NONE,value:.3048,offset:0},yd:{name:`yd`,base:V.LENGTH,prefixes:z.NONE,value:.9144,offset:0},mi:{name:`mi`,base:V.LENGTH,prefixes:z.NONE,value:1609.344,offset:0},li:{name:`li`,base:V.LENGTH,prefixes:z.NONE,value:.201168,offset:0},rd:{name:`rd`,base:V.LENGTH,prefixes:z.NONE,value:5.02921,offset:0},ch:{name:`ch`,base:V.LENGTH,prefixes:z.NONE,value:20.1168,offset:0},mil:{name:`mil`,base:V.LENGTH,prefixes:z.NONE,value:254e-7,offset:0},m2:{name:`m2`,base:V.SURFACE,prefixes:z.SQUARED,value:1,offset:0},sqin:{name:`sqin`,base:V.SURFACE,prefixes:z.NONE,value:64516e-8,offset:0},sqft:{name:`sqft`,base:V.SURFACE,prefixes:z.NONE,value:.09290304,offset:0},sqyd:{name:`sqyd`,base:V.SURFACE,prefixes:z.NONE,value:.83612736,offset:0},sqmi:{name:`sqmi`,base:V.SURFACE,prefixes:z.NONE,value:2589988.110336,offset:0},sqrd:{name:`sqrd`,base:V.SURFACE,prefixes:z.NONE,value:25.29295,offset:0},sqch:{name:`sqch`,base:V.SURFACE,prefixes:z.NONE,value:404.6873,offset:0},sqmil:{name:`sqmil`,base:V.SURFACE,prefixes:z.NONE,value:64516e-14,offset:0},acre:{name:`acre`,base:V.SURFACE,prefixes:z.NONE,value:4046.86,offset:0},hectare:{name:`hectare`,base:V.SURFACE,prefixes:z.NONE,value:1e4,offset:0},m3:{name:`m3`,base:V.VOLUME,prefixes:z.CUBIC,value:1,offset:0},L:{name:`L`,base:V.VOLUME,prefixes:z.SHORT,value:.001,offset:0},l:{name:`l`,base:V.VOLUME,prefixes:z.SHORT,value:.001,offset:0},litre:{name:`litre`,base:V.VOLUME,prefixes:z.LONG,value:.001,offset:0},cuin:{name:`cuin`,base:V.VOLUME,prefixes:z.NONE,value:16387064e-12,offset:0},cuft:{name:`cuft`,base:V.VOLUME,prefixes:z.NONE,value:.028316846592,offset:0},cuyd:{name:`cuyd`,base:V.VOLUME,prefixes:z.NONE,value:.764554857984,offset:0},teaspoon:{name:`teaspoon`,base:V.VOLUME,prefixes:z.NONE,value:5e-6,offset:0},tablespoon:{name:`tablespoon`,base:V.VOLUME,prefixes:z.NONE,value:15e-6,offset:0},drop:{name:`drop`,base:V.VOLUME,prefixes:z.NONE,value:5e-8,offset:0},gtt:{name:`gtt`,base:V.VOLUME,prefixes:z.NONE,value:5e-8,offset:0},minim:{name:`minim`,base:V.VOLUME,prefixes:z.NONE,value:6.1611519921875e-8,offset:0},fluiddram:{name:`fluiddram`,base:V.VOLUME,prefixes:z.NONE,value:36966911953125e-19,offset:0},fluidounce:{name:`fluidounce`,base:V.VOLUME,prefixes:z.NONE,value:295735295625e-16,offset:0},gill:{name:`gill`,base:V.VOLUME,prefixes:z.NONE,value:.00011829411825,offset:0},cc:{name:`cc`,base:V.VOLUME,prefixes:z.NONE,value:1e-6,offset:0},cup:{name:`cup`,base:V.VOLUME,prefixes:z.NONE,value:.0002365882365,offset:0},pint:{name:`pint`,base:V.VOLUME,prefixes:z.NONE,value:.000473176473,offset:0},quart:{name:`quart`,base:V.VOLUME,prefixes:z.NONE,value:.000946352946,offset:0},gallon:{name:`gallon`,base:V.VOLUME,prefixes:z.NONE,value:.003785411784,offset:0},beerbarrel:{name:`beerbarrel`,base:V.VOLUME,prefixes:z.NONE,value:.117347765304,offset:0},oilbarrel:{name:`oilbarrel`,base:V.VOLUME,prefixes:z.NONE,value:.158987294928,offset:0},hogshead:{name:`hogshead`,base:V.VOLUME,prefixes:z.NONE,value:.238480942392,offset:0},g:{name:`g`,base:V.MASS,prefixes:z.SHORT,value:.001,offset:0},gram:{name:`gram`,base:V.MASS,prefixes:z.LONG,value:.001,offset:0},ton:{name:`ton`,base:V.MASS,prefixes:z.SHORT,value:907.18474,offset:0},t:{name:`t`,base:V.MASS,prefixes:z.SHORT,value:1e3,offset:0},tonne:{name:`tonne`,base:V.MASS,prefixes:z.LONG,value:1e3,offset:0},grain:{name:`grain`,base:V.MASS,prefixes:z.NONE,value:6479891e-11,offset:0},dram:{name:`dram`,base:V.MASS,prefixes:z.NONE,value:.0017718451953125,offset:0},ounce:{name:`ounce`,base:V.MASS,prefixes:z.NONE,value:.028349523125,offset:0},poundmass:{name:`poundmass`,base:V.MASS,prefixes:z.NONE,value:.45359237,offset:0},hundredweight:{name:`hundredweight`,base:V.MASS,prefixes:z.NONE,value:45.359237,offset:0},stick:{name:`stick`,base:V.MASS,prefixes:z.NONE,value:.115,offset:0},stone:{name:`stone`,base:V.MASS,prefixes:z.NONE,value:6.35029318,offset:0},gr:{name:`gr`,base:V.MASS,prefixes:z.NONE,value:6479891e-11,offset:0},dr:{name:`dr`,base:V.MASS,prefixes:z.NONE,value:.0017718451953125,offset:0},oz:{name:`oz`,base:V.MASS,prefixes:z.NONE,value:.028349523125,offset:0},lbm:{name:`lbm`,base:V.MASS,prefixes:z.NONE,value:.45359237,offset:0},cwt:{name:`cwt`,base:V.MASS,prefixes:z.NONE,value:45.359237,offset:0},s:{name:`s`,base:V.TIME,prefixes:z.SHORT,value:1,offset:0},min:{name:`min`,base:V.TIME,prefixes:z.NONE,value:60,offset:0},h:{name:`h`,base:V.TIME,prefixes:z.NONE,value:3600,offset:0},second:{name:`second`,base:V.TIME,prefixes:z.LONG,value:1,offset:0},sec:{name:`sec`,base:V.TIME,prefixes:z.LONG,value:1,offset:0},minute:{name:`minute`,base:V.TIME,prefixes:z.NONE,value:60,offset:0},hour:{name:`hour`,base:V.TIME,prefixes:z.NONE,value:3600,offset:0},day:{name:`day`,base:V.TIME,prefixes:z.NONE,value:86400,offset:0},week:{name:`week`,base:V.TIME,prefixes:z.NONE,value:7*86400,offset:0},month:{name:`month`,base:V.TIME,prefixes:z.NONE,value:2629800,offset:0},year:{name:`year`,base:V.TIME,prefixes:z.NONE,value:31557600,offset:0},decade:{name:`decade`,base:V.TIME,prefixes:z.NONE,value:315576e3,offset:0},century:{name:`century`,base:V.TIME,prefixes:z.NONE,value:315576e4,offset:0},millennium:{name:`millennium`,base:V.TIME,prefixes:z.NONE,value:315576e5,offset:0},hertz:{name:`Hertz`,base:V.FREQUENCY,prefixes:z.LONG,value:1,offset:0,reciprocal:!0},Hz:{name:`Hz`,base:V.FREQUENCY,prefixes:z.SHORT,value:1,offset:0,reciprocal:!0},rad:{name:`rad`,base:V.ANGLE,prefixes:z.SHORT,value:1,offset:0},radian:{name:`radian`,base:V.ANGLE,prefixes:z.LONG,value:1,offset:0},deg:{name:`deg`,base:V.ANGLE,prefixes:z.SHORT,value:null,offset:0},degree:{name:`degree`,base:V.ANGLE,prefixes:z.LONG,value:null,offset:0},grad:{name:`grad`,base:V.ANGLE,prefixes:z.SHORT,value:null,offset:0},gradian:{name:`gradian`,base:V.ANGLE,prefixes:z.LONG,value:null,offset:0},cycle:{name:`cycle`,base:V.ANGLE,prefixes:z.NONE,value:null,offset:0},arcsec:{name:`arcsec`,base:V.ANGLE,prefixes:z.NONE,value:null,offset:0},arcmin:{name:`arcmin`,base:V.ANGLE,prefixes:z.NONE,value:null,offset:0},A:{name:`A`,base:V.CURRENT,prefixes:z.SHORT,value:1,offset:0},ampere:{name:`ampere`,base:V.CURRENT,prefixes:z.LONG,value:1,offset:0},K:{name:`K`,base:V.TEMPERATURE,prefixes:z.SHORT,value:1,offset:0},degC:{name:`degC`,base:V.TEMPERATURE,prefixes:z.SHORT,value:1,offset:273.15},degF:{name:`degF`,base:V.TEMPERATURE,prefixes:z.SHORT,value:new _(5,9),offset:459.67},degR:{name:`degR`,base:V.TEMPERATURE,prefixes:z.SHORT,value:new _(5,9),offset:0},kelvin:{name:`kelvin`,base:V.TEMPERATURE,prefixes:z.LONG,value:1,offset:0},celsius:{name:`celsius`,base:V.TEMPERATURE,prefixes:z.LONG,value:1,offset:273.15},fahrenheit:{name:`fahrenheit`,base:V.TEMPERATURE,prefixes:z.LONG,value:new _(5,9),offset:459.67},rankine:{name:`rankine`,base:V.TEMPERATURE,prefixes:z.LONG,value:new _(5,9),offset:0},mol:{name:`mol`,base:V.AMOUNT_OF_SUBSTANCE,prefixes:z.SHORT,value:1,offset:0},mole:{name:`mole`,base:V.AMOUNT_OF_SUBSTANCE,prefixes:z.LONG,value:1,offset:0},cd:{name:`cd`,base:V.LUMINOUS_INTENSITY,prefixes:z.SHORT,value:1,offset:0},candela:{name:`candela`,base:V.LUMINOUS_INTENSITY,prefixes:z.LONG,value:1,offset:0},N:{name:`N`,base:V.FORCE,prefixes:z.SHORT,value:1,offset:0},newton:{name:`newton`,base:V.FORCE,prefixes:z.LONG,value:1,offset:0},dyn:{name:`dyn`,base:V.FORCE,prefixes:z.SHORT,value:1e-5,offset:0},dyne:{name:`dyne`,base:V.FORCE,prefixes:z.LONG,value:1e-5,offset:0},lbf:{name:`lbf`,base:V.FORCE,prefixes:z.NONE,value:4.4482216152605,offset:0},poundforce:{name:`poundforce`,base:V.FORCE,prefixes:z.NONE,value:4.4482216152605,offset:0},kip:{name:`kip`,base:V.FORCE,prefixes:z.LONG,value:4448.2216,offset:0},kilogramforce:{name:`kilogramforce`,base:V.FORCE,prefixes:z.NONE,value:9.80665,offset:0},J:{name:`J`,base:V.ENERGY,prefixes:z.SHORT,value:1,offset:0},joule:{name:`joule`,base:V.ENERGY,prefixes:z.LONG,value:1,offset:0},erg:{name:`erg`,base:V.ENERGY,prefixes:z.SHORTLONG,value:1e-7,offset:0},Wh:{name:`Wh`,base:V.ENERGY,prefixes:z.SHORT,value:3600,offset:0},BTU:{name:`BTU`,base:V.ENERGY,prefixes:z.BTU,value:1055.05585262,offset:0},eV:{name:`eV`,base:V.ENERGY,prefixes:z.SHORT,value:1602176565e-28,offset:0},electronvolt:{name:`electronvolt`,base:V.ENERGY,prefixes:z.LONG,value:1602176565e-28,offset:0},W:{name:`W`,base:V.POWER,prefixes:z.SHORT,value:1,offset:0},watt:{name:`watt`,base:V.POWER,prefixes:z.LONG,value:1,offset:0},hp:{name:`hp`,base:V.POWER,prefixes:z.NONE,value:745.6998715386,offset:0},VAR:{name:`VAR`,base:V.POWER,prefixes:z.SHORT,value:h.I,offset:0},VA:{name:`VA`,base:V.POWER,prefixes:z.SHORT,value:1,offset:0},Pa:{name:`Pa`,base:V.PRESSURE,prefixes:z.SHORT,value:1,offset:0},psi:{name:`psi`,base:V.PRESSURE,prefixes:z.NONE,value:6894.75729276459,offset:0},atm:{name:`atm`,base:V.PRESSURE,prefixes:z.NONE,value:101325,offset:0},bar:{name:`bar`,base:V.PRESSURE,prefixes:z.SHORTLONG,value:1e5,offset:0},torr:{name:`torr`,base:V.PRESSURE,prefixes:z.NONE,value:133.322,offset:0},mmHg:{name:`mmHg`,base:V.PRESSURE,prefixes:z.NONE,value:133.322,offset:0},mmH2O:{name:`mmH2O`,base:V.PRESSURE,prefixes:z.NONE,value:9.80665,offset:0},cmH2O:{name:`cmH2O`,base:V.PRESSURE,prefixes:z.NONE,value:98.0665,offset:0},coulomb:{name:`coulomb`,base:V.ELECTRIC_CHARGE,prefixes:z.LONG,value:1,offset:0},C:{name:`C`,base:V.ELECTRIC_CHARGE,prefixes:z.SHORT,value:1,offset:0},Ah:{name:`Ah`,base:V.ELECTRIC_CHARGE,prefixes:z.SHORT,value:3600,offset:0},farad:{name:`farad`,base:V.ELECTRIC_CAPACITANCE,prefixes:z.LONG,value:1,offset:0},F:{name:`F`,base:V.ELECTRIC_CAPACITANCE,prefixes:z.SHORT,value:1,offset:0},volt:{name:`volt`,base:V.ELECTRIC_POTENTIAL,prefixes:z.LONG,value:1,offset:0},V:{name:`V`,base:V.ELECTRIC_POTENTIAL,prefixes:z.SHORT,value:1,offset:0},ohm:{name:`ohm`,base:V.ELECTRIC_RESISTANCE,prefixes:z.SHORTLONG,value:1,offset:0},henry:{name:`henry`,base:V.ELECTRIC_INDUCTANCE,prefixes:z.LONG,value:1,offset:0},H:{name:`H`,base:V.ELECTRIC_INDUCTANCE,prefixes:z.SHORT,value:1,offset:0},siemens:{name:`siemens`,base:V.ELECTRIC_CONDUCTANCE,prefixes:z.LONG,value:1,offset:0},S:{name:`S`,base:V.ELECTRIC_CONDUCTANCE,prefixes:z.SHORT,value:1,offset:0},weber:{name:`weber`,base:V.MAGNETIC_FLUX,prefixes:z.LONG,value:1,offset:0},Wb:{name:`Wb`,base:V.MAGNETIC_FLUX,prefixes:z.SHORT,value:1,offset:0},tesla:{name:`tesla`,base:V.MAGNETIC_FLUX_DENSITY,prefixes:z.LONG,value:1,offset:0},T:{name:`T`,base:V.MAGNETIC_FLUX_DENSITY,prefixes:z.SHORT,value:1,offset:0},b:{name:`b`,base:V.BIT,prefixes:z.BINARY_SHORT,value:1,offset:0},bits:{name:`bits`,base:V.BIT,prefixes:z.BINARY_LONG,value:1,offset:0},B:{name:`B`,base:V.BIT,prefixes:z.BINARY_SHORT,value:8,offset:0},bytes:{name:`bytes`,base:V.BIT,prefixes:z.BINARY_LONG,value:8,offset:0}},ne={meters:`meter`,inches:`inch`,feet:`foot`,yards:`yard`,miles:`mile`,links:`link`,rods:`rod`,chains:`chain`,angstroms:`angstrom`,lt:`l`,litres:`litre`,liter:`litre`,liters:`litre`,teaspoons:`teaspoon`,tablespoons:`tablespoon`,minims:`minim`,fldr:`fluiddram`,fluiddrams:`fluiddram`,floz:`fluidounce`,fluidounces:`fluidounce`,gi:`gill`,gills:`gill`,cp:`cup`,cups:`cup`,pt:`pint`,pints:`pint`,qt:`quart`,quarts:`quart`,gal:`gallon`,gallons:`gallon`,bbl:`beerbarrel`,beerbarrels:`beerbarrel`,obl:`oilbarrel`,oilbarrels:`oilbarrel`,hogsheads:`hogshead`,gtts:`gtt`,grams:`gram`,tons:`ton`,tonnes:`tonne`,grains:`grain`,drams:`dram`,ounces:`ounce`,poundmasses:`poundmass`,hundredweights:`hundredweight`,sticks:`stick`,lb:`lbm`,lbs:`lbm`,kips:`kip`,kgf:`kilogramforce`,acres:`acre`,hectares:`hectare`,sqfeet:`sqft`,sqyard:`sqyd`,sqmile:`sqmi`,sqmiles:`sqmi`,mmhg:`mmHg`,mmh2o:`mmH2O`,cmh2o:`cmH2O`,seconds:`second`,secs:`second`,minutes:`minute`,mins:`minute`,hours:`hour`,hr:`hour`,hrs:`hour`,days:`day`,weeks:`week`,months:`month`,years:`year`,decades:`decade`,centuries:`century`,millennia:`millennium`,hertz:`hertz`,radians:`radian`,degrees:`degree`,gradians:`gradian`,cycles:`cycle`,arcsecond:`arcsec`,arcseconds:`arcsec`,arcminute:`arcmin`,arcminutes:`arcmin`,BTUs:`BTU`,watts:`watt`,joules:`joule`,amperes:`ampere`,amps:`ampere`,amp:`ampere`,coulombs:`coulomb`,volts:`volt`,ohms:`ohm`,farads:`farad`,webers:`weber`,teslas:`tesla`,electronvolts:`electronvolt`,moles:`mole`,bit:`bits`,byte:`bytes`};function re(e){if(e.number===`BigNumber`){var t=__(g);H.rad.value=new g(1),H.deg.value=t.div(180),H.grad.value=t.div(200),H.cycle.value=t.times(2),H.arcsec.value=t.div(648e3),H.arcmin.value=t.div(10800)}else H.rad.value=1,H.deg.value=Math.PI/180,H.grad.value=Math.PI/200,H.cycle.value=Math.PI*2,H.arcsec.value=Math.PI/648e3,H.arcmin.value=Math.PI/10800;H.radian.value=H.rad.value,H.degree.value=H.deg.value,H.gradian.value=H.grad.value}re(n),t&&t(`config`,function(e,t){e.number!==t.number&&re(e)});var ie={si:{NONE:{unit:te,prefix:z.NONE[``]},LENGTH:{unit:H.m,prefix:z.SHORT[``]},MASS:{unit:H.g,prefix:z.SHORT.k},TIME:{unit:H.s,prefix:z.SHORT[``]},CURRENT:{unit:H.A,prefix:z.SHORT[``]},TEMPERATURE:{unit:H.K,prefix:z.SHORT[``]},LUMINOUS_INTENSITY:{unit:H.cd,prefix:z.SHORT[``]},AMOUNT_OF_SUBSTANCE:{unit:H.mol,prefix:z.SHORT[``]},ANGLE:{unit:H.rad,prefix:z.SHORT[``]},BIT:{unit:H.bits,prefix:z.SHORT[``]},FORCE:{unit:H.N,prefix:z.SHORT[``]},ENERGY:{unit:H.J,prefix:z.SHORT[``]},POWER:{unit:H.W,prefix:z.SHORT[``]},PRESSURE:{unit:H.Pa,prefix:z.SHORT[``]},ELECTRIC_CHARGE:{unit:H.C,prefix:z.SHORT[``]},ELECTRIC_CAPACITANCE:{unit:H.F,prefix:z.SHORT[``]},ELECTRIC_POTENTIAL:{unit:H.V,prefix:z.SHORT[``]},ELECTRIC_RESISTANCE:{unit:H.ohm,prefix:z.SHORT[``]},ELECTRIC_INDUCTANCE:{unit:H.H,prefix:z.SHORT[``]},ELECTRIC_CONDUCTANCE:{unit:H.S,prefix:z.SHORT[``]},MAGNETIC_FLUX:{unit:H.Wb,prefix:z.SHORT[``]},MAGNETIC_FLUX_DENSITY:{unit:H.T,prefix:z.SHORT[``]},FREQUENCY:{unit:H.Hz,prefix:z.SHORT[``]}}};ie.cgs=JSON.parse(JSON.stringify(ie.si)),ie.cgs.LENGTH={unit:H.m,prefix:z.SHORT.c},ie.cgs.MASS={unit:H.g,prefix:z.SHORT[``]},ie.cgs.FORCE={unit:H.dyn,prefix:z.SHORT[``]},ie.cgs.ENERGY={unit:H.erg,prefix:z.NONE[``]},ie.us=JSON.parse(JSON.stringify(ie.si)),ie.us.LENGTH={unit:H.ft,prefix:z.NONE[``]},ie.us.MASS={unit:H.lbm,prefix:z.NONE[``]},ie.us.TEMPERATURE={unit:H.degF,prefix:z.NONE[``]},ie.us.FORCE={unit:H.lbf,prefix:z.NONE[``]},ie.us.ENERGY={unit:H.BTU,prefix:z.BTU[``]},ie.us.POWER={unit:H.hp,prefix:z.NONE[``]},ie.us.PRESSURE={unit:H.psi,prefix:z.NONE[``]},ie.auto=JSON.parse(JSON.stringify(ie.si));var U=ie.auto;for(var ae in x.setUnitSystem=function(e){if(Ei(ie,e))U=ie[e];else throw Error(`Unit system `+e+` does not exist. Choices are: `+Object.keys(ie).join(`, `))},x.getUnitSystem=function(){for(var e in ie)if(Ei(ie,e)&&ie[e]===U)return e},x.typeConverters={BigNumber:function(e){return e!=null&&e.isFraction?new g(String(e.n)).div(String(e.d)).times(String(e.s)):new g(e+``)},Fraction:function(e){return new _(e)},Complex:function(e){return e},number:function(e){return e!=null&&e.isFraction?m(e):e}},x.prototype._numberConverter=function(){var e=x.typeConverters[this.valueType()];if(e)return e;throw TypeError(`Unsupported Unit value type "`+this.valueType()+`"`)},x._getNumberConverter=function(e){if(!x.typeConverters[e])throw TypeError(`Unsupported type "`+e+`"`);return x.typeConverters[e]},H)if(Ei(H,ae)){var oe=H[ae];oe.dimensions=oe.base.dimensions}for(var se in ne)if(Ei(ne,se)){var ce=H[ne[se]],le={};for(var ue in ce)Ei(ce,ue)&&(le[ue]=ce[ue]);le.name=se,H[se]=le}x.isValidAlpha=function(e){return/^[a-zA-Z]$/.test(e)};function de(e){for(var t=0;t<e.length;t++){if(w=e.charAt(t),t===0&&!x.isValidAlpha(w))throw Error(`Invalid unit name (must begin with alpha character): "`+e+`"`);if(t>0&&!(x.isValidAlpha(w)||D(w)))throw Error(`Invalid unit name (only alphanumeric characters are allowed): "`+e+`"`)}}return x.createUnit=function(e,t){if(typeof e!=`object`)throw TypeError(`createUnit expects first parameter to be of type 'Object'`);if(t&&t.override){for(var n in e)if(Ei(e,n)&&x.deleteUnit(n),e[n].aliases)for(var r=0;r<e[n].aliases.length;r++)x.deleteUnit(e[n].aliases[r])}var i;for(var a in e)Ei(e,a)&&(i=x.createUnitSingle(a,e[a]));return i},x.createUnitSingle=function(e,t){if(t??={},typeof e!=`string`)throw TypeError(`createUnitSingle expects first parameter to be of type 'string'`);if(Ei(H,e))throw Error(`Cannot create unit "`+e+`": a unit with that name already exists`);de(e);var n=null,r=[],i=0,a,o,s;if(t&&t.type===`Unit`)n=t.clone();else if(typeof t==`string`)t!==``&&(a=t);else if(typeof t==`object`)a=t.definition,o=t.prefixes,i=t.offset,s=t.baseName,t.aliases&&(r=t.aliases.valueOf());else throw TypeError(`Cannot create unit "`+e+`" from "`+t.toString()+`": expecting "string" or "Unit" or "Object"`);if(r){for(var c=0;c<r.length;c++)if(Ei(H,r[c]))throw Error(`Cannot create alias "`+r[c]+`": a unit with that name already exists`)}if(a&&typeof a==`string`&&!n)try{n=x.parse(a,{allowNoUnits:!0})}catch(t){throw t.message=`Could not create unit "`+e+`" from "`+a+`": `+t.message,t}else a&&a.type===`Unit`&&(n=a.clone());r||=[],i||=0,o=o&&o.toUpperCase&&z[o.toUpperCase()]||z.NONE;var l={};if(n){l={name:e,value:n.value,dimensions:n.dimensions.slice(0),prefixes:o,offset:i};var u=!1;for(var d in V)if(Ei(V,d)){for(var f=!0,p=0;p<B.length;p++)if(Math.abs((l.dimensions[p]||0)-(V[d].dimensions[p]||0))>1e-12){f=!1;break}if(f){u=!0,l.base=V[d];break}}if(!u){s||=e+`_STUFF`;var m={dimensions:n.dimensions.slice(0)};m.key=s,V[s]=m,U[s]={unit:l,prefix:z.NONE[``]},l.base=V[s]}}else{if(s||=e+`_STUFF`,B.indexOf(s)>=0)throw Error(`Cannot create new base unit "`+e+`": a base unit with that name already exists (and cannot be overridden)`);for(var h in B.push(s),V)Ei(V,h)&&(V[h].dimensions[B.length-1]=0);for(var g={dimensions:[]},_=0;_<B.length;_++)g.dimensions[_]=0;g.dimensions[B.length-1]=1,g.key=s,V[s]=g,l={name:e,value:1,dimensions:V[s].dimensions.slice(0),prefixes:o,offset:i,base:V[s]},U[s]={unit:l,prefix:z.NONE[``]}}x.UNITS[e]=l;for(var v=0;v<r.length;v++){var y=r[v],b={};for(var S in l)Ei(l,S)&&(b[S]=l[S]);b.name=y,x.UNITS[y]=b}return delete N.cache,new x(null,e)},x.deleteUnit=function(e){delete x.UNITS[e],delete N.cache},x.PREFIXES=z,x.BASE_DIMENSIONS=B,x.BASE_UNITS=V,x.UNIT_SYSTEMS=ie,x.UNITS=H,x},{isClass:!0}),C_=`unit`,w_=J(C_,[`typed`,`Unit`],e=>{var{typed:t,Unit:n}=e;return t(C_,{Unit:function(e){return e.clone()},string:function(e){return n.isValuelessUnit(e)?new n(null,e):n.parse(e,{allowNoUnits:!0})},"number | BigNumber | Fraction | Complex, string | Unit":function(e,t){return new n(e,t)},"number | BigNumber | Fraction":function(e){return new n(e)},"Array | Matrix":t.referToSelf(e=>t=>$c(t,e))})}),T_=`sparse`,E_=J(T_,[`typed`,`SparseMatrix`],e=>{var{typed:t,SparseMatrix:n}=e;return t(T_,{"":function(){return new n([])},string:function(e){return new n([],e)},"Array | Matrix":function(e){return new n(e)},"Array | Matrix, string":function(e,t){return new n(e,t)}})}),D_=`createUnit`,O_=J(D_,[`typed`,`Unit`],e=>{var{typed:t,Unit:n}=e;return t(D_,{"Object, Object":function(e,t){return n.createUnit(e,t)},Object:function(e){return n.createUnit(e,{})},"string, Unit | string | Object, Object":function(e,t,r){var i={};return i[e]=t,n.createUnit(i,r)},"string, Unit | string | Object":function(e,t){var r={};return r[e]=t,n.createUnit(r,{})},string:function(e){var t={};return t[e]={},n.createUnit(t,{})}})}),k_=`acos`,A_=J(k_,[`typed`,`config`,`Complex`],e=>{var{typed:t,config:n,Complex:r}=e;return t(k_,{number:function(e){return e>=-1&&e<=1||n.predictable?Math.acos(e):new r(e,0).acos()},Complex:function(e){return e.acos()},BigNumber:function(e){return e.acos()}})}),j_=`acosh`,M_=J(j_,[`typed`,`config`,`Complex`],e=>{var{typed:t,config:n,Complex:r}=e;return t(j_,{number:function(e){return e>=1||n.predictable?lu(e):e<=-1?new r(Math.log(Math.sqrt(e*e-1)-e),Math.PI):new r(e,0).acosh()},Complex:function(e){return e.acosh()},BigNumber:function(e){return e.acosh()}})}),N_=`acot`,P_=J(N_,[`typed`,`BigNumber`],e=>{var{typed:t,BigNumber:n}=e;return t(N_,{number:uu,Complex:function(e){return e.acot()},BigNumber:function(e){return new n(1).div(e).atan()}})}),F_=`acoth`,I_=J(F_,[`typed`,`config`,`Complex`,`BigNumber`],e=>{var{typed:t,config:n,Complex:r,BigNumber:i}=e;return t(F_,{number:function(e){return e>=1||e<=-1||n.predictable?du(e):new r(e,0).acoth()},Complex:function(e){return e.acoth()},BigNumber:function(e){return new i(1).div(e).atanh()}})}),L_=`acsc`,R_=J(L_,[`typed`,`config`,`Complex`,`BigNumber`],e=>{var{typed:t,config:n,Complex:r,BigNumber:i}=e;return t(L_,{number:function(e){return e<=-1||e>=1||n.predictable?fu(e):new r(e,0).acsc()},Complex:function(e){return e.acsc()},BigNumber:function(e){return new i(1).div(e).asin()}})}),z_=`acsch`,B_=J(z_,[`typed`,`BigNumber`],e=>{var{typed:t,BigNumber:n}=e;return t(z_,{number:pu,Complex:function(e){return e.acsch()},BigNumber:function(e){return new n(1).div(e).asinh()}})}),V_=`asec`,H_=J(V_,[`typed`,`config`,`Complex`,`BigNumber`],e=>{var{typed:t,config:n,Complex:r,BigNumber:i}=e;return t(V_,{number:function(e){return e<=-1||e>=1||n.predictable?mu(e):new r(e,0).asec()},Complex:function(e){return e.asec()},BigNumber:function(e){return new i(1).div(e).acos()}})}),U_=`asech`,W_=J(U_,[`typed`,`config`,`Complex`,`BigNumber`],e=>{var{typed:t,config:n,Complex:r,BigNumber:i}=e;return t(U_,{number:function(e){if(e<=1&&e>=-1||n.predictable){var t=1/e;if(t>0||n.predictable)return hu(e);var i=Math.sqrt(t*t-1);return new r(Math.log(i-t),Math.PI)}return new r(e,0).asech()},Complex:function(e){return e.asech()},BigNumber:function(e){return new i(1).div(e).acosh()}})}),G_=`asin`,K_=J(G_,[`typed`,`config`,`Complex`],e=>{var{typed:t,config:n,Complex:r}=e;return t(G_,{number:function(e){return e>=-1&&e<=1||n.predictable?Math.asin(e):new r(e,0).asin()},Complex:function(e){return e.asin()},BigNumber:function(e){return e.asin()}})}),q_=J(`asinh`,[`typed`],e=>{var{typed:t}=e;return t(`asinh`,{number:_u,Complex:function(e){return e.asinh()},BigNumber:function(e){return e.asinh()}})}),J_=J(`atan`,[`typed`],e=>{var{typed:t}=e;return t(`atan`,{number:function(e){return Math.atan(e)},Complex:function(e){return e.atan()},BigNumber:function(e){return e.atan()}})}),Y_=`atan2`,X_=J(Y_,[`typed`,`matrix`,`equalScalar`,`BigNumber`,`DenseMatrix`,`concat`],e=>{var{typed:t,matrix:n,equalScalar:r,BigNumber:i,DenseMatrix:a,concat:o}=e,s=vf({typed:t,equalScalar:r}),c=yf({typed:t}),l=lp({typed:t,equalScalar:r}),u=Jd({typed:t,equalScalar:r}),d=Yd({typed:t,DenseMatrix:a}),f=wf({typed:t,matrix:n,concat:o});return t(Y_,{"number, number":Math.atan2,"BigNumber, BigNumber":(e,t)=>i.atan2(e,t)},f({scalar:`number | BigNumber`,SS:l,DS:c,SD:s,Ss:u,sS:d}))}),Z_=`atanh`,Q_=J(Z_,[`typed`,`config`,`Complex`],e=>{var{typed:t,config:n,Complex:r}=e;return t(Z_,{number:function(e){return e<=1&&e>=-1||n.predictable?bu(e):new r(e,0).atanh()},Complex:function(e){return e.atanh()},BigNumber:function(e){return e.atanh()}})}),$_=J(`trigUnit`,[`typed`],e=>{var{typed:t}=e;return{Unit:t.referToSelf(e=>n=>{if(!n.hasBase(n.constructor.BASE_UNITS.ANGLE))throw TypeError(`Unit in function cot is no angle`);return t.find(e,n.valueType())(n.value)})}}),ev=`cos`,tv=J(ev,[`typed`],e=>{var{typed:t}=e,n=$_({typed:t});return t(ev,{number:Math.cos,"Complex | BigNumber":e=>e.cos()},n)}),nv=`cosh`,rv=J(nv,[`typed`],e=>{var{typed:t}=e;return t(nv,{number:sa,"Complex | BigNumber":e=>e.cosh()})}),iv=`cot`,av=J(iv,[`typed`,`BigNumber`],e=>{var{typed:t,BigNumber:n}=e,r=$_({typed:t});return t(iv,{number:Cu,Complex:e=>e.cot(),BigNumber:e=>new n(1).div(e.tan())},r)}),ov=`coth`,sv=J(ov,[`typed`,`BigNumber`],e=>{var{typed:t,BigNumber:n}=e;return t(ov,{number:wu,Complex:e=>e.coth(),BigNumber:e=>new n(1).div(e.tanh())})}),cv=`csc`,lv=J(cv,[`typed`,`BigNumber`],e=>{var{typed:t,BigNumber:n}=e,r=$_({typed:t});return t(cv,{number:Tu,Complex:e=>e.csc(),BigNumber:e=>new n(1).div(e.sin())},r)}),uv=`csch`,dv=J(uv,[`typed`,`BigNumber`],e=>{var{typed:t,BigNumber:n}=e;return t(uv,{number:Eu,Complex:e=>e.csch(),BigNumber:e=>new n(1).div(e.sinh())})}),fv=`sec`,pv=J(fv,[`typed`,`BigNumber`],e=>{var{typed:t,BigNumber:n}=e,r=$_({typed:t});return t(fv,{number:Du,Complex:e=>e.sec(),BigNumber:e=>new n(1).div(e.cos())},r)}),mv=`sech`,hv=J(mv,[`typed`,`BigNumber`],e=>{var{typed:t,BigNumber:n}=e;return t(mv,{number:Ou,Complex:e=>e.sech(),BigNumber:e=>new n(1).div(e.cosh())})}),gv=`sin`,_v=J(gv,[`typed`],e=>{var{typed:t}=e,n=$_({typed:t});return t(gv,{number:Math.sin,"Complex | BigNumber":e=>e.sin()},n)}),vv=`sinh`,yv=J(vv,[`typed`],e=>{var{typed:t}=e;return t(vv,{number:Au,"Complex | BigNumber":e=>e.sinh()})}),bv=`tan`,xv=J(bv,[`typed`],e=>{var{typed:t}=e,n=$_({typed:t});return t(bv,{number:Math.tan,"Complex | BigNumber":e=>e.tan()},n)}),Sv=J(`tanh`,[`typed`],e=>{var{typed:t}=e;return t(`tanh`,{number:la,"Complex | BigNumber":e=>e.tanh()})}),Cv=`setCartesian`,wv=J(Cv,[`typed`,`size`,`subset`,`compareNatural`,`Index`,`DenseMatrix`],e=>{var{typed:t,size:n,subset:r,compareNatural:i,Index:a,DenseMatrix:o}=e;return t(Cv,{"Array | Matrix, Array | Matrix":function(e,t){var s=[];if(r(n(e),new a(0))!==0&&r(n(t),new a(0))!==0){var c=Sc(Array.isArray(e)?e:e.toArray()).sort(i),l=Sc(Array.isArray(t)?t:t.toArray()).sort(i);s=[];for(var u=0;u<c.length;u++)for(var d=0;d<l.length;d++)s.push([c[u],l[d]])}return Array.isArray(e)&&Array.isArray(t)?s:new o(s)}})}),Tv=`setDifference`,Ev=J(Tv,[`typed`,`size`,`subset`,`compareNatural`,`Index`,`DenseMatrix`],e=>{var{typed:t,size:n,subset:r,compareNatural:i,Index:a,DenseMatrix:o}=e;return t(Tv,{"Array | Matrix, Array | Matrix":function(e,t){var s;if(r(n(e),new a(0))===0)s=[];else if(r(n(t),new a(0))===0)return Sc(e.toArray());else{var c=Oc(Sc(Array.isArray(e)?e:e.toArray()).sort(i)),l=Oc(Sc(Array.isArray(t)?t:t.toArray()).sort(i));s=[];for(var u,d=0;d<c.length;d++){u=!1;for(var f=0;f<l.length;f++)if(i(c[d].value,l[f].value)===0&&c[d].identifier===l[f].identifier){u=!0;break}u||s.push(c[d])}}return Array.isArray(e)&&Array.isArray(t)?kc(s):new o(kc(s))}})}),Dv=`setDistinct`,Ov=J(Dv,[`typed`,`size`,`subset`,`compareNatural`,`Index`,`DenseMatrix`],e=>{var{typed:t,size:n,subset:r,compareNatural:i,Index:a,DenseMatrix:o}=e;return t(Dv,{"Array | Matrix":function(e){var t;if(r(n(e),new a(0))===0)t=[];else{var s=Sc(Array.isArray(e)?e:e.toArray()).sort(i);t=[],t.push(s[0]);for(var c=1;c<s.length;c++)i(s[c],s[c-1])!==0&&t.push(s[c])}return Array.isArray(e)?t:new o(t)}})}),kv=`setIntersect`,Av=J(kv,[`typed`,`size`,`subset`,`compareNatural`,`Index`,`DenseMatrix`],e=>{var{typed:t,size:n,subset:r,compareNatural:i,Index:a,DenseMatrix:o}=e;return t(kv,{"Array | Matrix, Array | Matrix":function(e,t){var s;if(r(n(e),new a(0))===0||r(n(t),new a(0))===0)s=[];else{var c=Oc(Sc(Array.isArray(e)?e:e.toArray()).sort(i)),l=Oc(Sc(Array.isArray(t)?t:t.toArray()).sort(i));s=[];for(var u=0;u<c.length;u++)for(var d=0;d<l.length;d++)if(i(c[u].value,l[d].value)===0&&c[u].identifier===l[d].identifier){s.push(c[u]);break}}return Array.isArray(e)&&Array.isArray(t)?kc(s):new o(kc(s))}})}),jv=`setIsSubset`,Mv=J(jv,[`typed`,`size`,`subset`,`compareNatural`,`Index`],e=>{var{typed:t,size:n,subset:r,compareNatural:i,Index:a}=e;return t(jv,{"Array | Matrix, Array | Matrix":function(e,t){if(r(n(e),new a(0))===0)return!0;if(r(n(t),new a(0))===0)return!1;for(var o=Oc(Sc(Array.isArray(e)?e:e.toArray()).sort(i)),s=Oc(Sc(Array.isArray(t)?t:t.toArray()).sort(i)),c,l=0;l<o.length;l++){c=!1;for(var u=0;u<s.length;u++)if(i(o[l].value,s[u].value)===0&&o[l].identifier===s[u].identifier){c=!0;break}if(c===!1)return!1}return!0}})}),Nv=`setMultiplicity`,Pv=J(Nv,[`typed`,`size`,`subset`,`compareNatural`,`Index`],e=>{var{typed:t,size:n,subset:r,compareNatural:i,Index:a}=e;return t(Nv,{"number | BigNumber | Fraction | Complex, Array | Matrix":function(e,t){if(r(n(t),new a(0))===0)return 0;for(var o=Sc(Array.isArray(t)?t:t.toArray()),s=0,c=0;c<o.length;c++)i(o[c],e)===0&&s++;return s}})}),Fv=`setPowerset`,Iv=J(Fv,[`typed`,`size`,`subset`,`compareNatural`,`Index`],e=>{var{typed:t,size:n,subset:r,compareNatural:i,Index:a}=e;return t(Fv,{"Array | Matrix":function(e){if(r(n(e),new a(0))===0)return[];for(var t=Sc(Array.isArray(e)?e:e.toArray()).sort(i),c=[],l=0;l.toString(2).length<=t.length;)c.push(o(t,l.toString(2).split(``).reverse())),l++;return s(c)}});function o(e,t){for(var n=[],r=0;r<t.length;r++)t[r]===`1`&&n.push(e[r]);return n}function s(e){for(var t=[],n=e.length-1;n>0;n--)for(var r=0;r<n;r++)e[r].length>e[r+1].length&&(t=e[r],e[r]=e[r+1],e[r+1]=t);return e}}),Lv=`setSize`,Rv=J(Lv,[`typed`,`compareNatural`],e=>{var{typed:t,compareNatural:n}=e;return t(Lv,{"Array | Matrix":function(e){return Array.isArray(e)?Sc(e).length:Sc(e.toArray()).length},"Array | Matrix, boolean":function(e,t){if(t===!1||e.length===0)return Array.isArray(e)?Sc(e).length:Sc(e.toArray()).length;for(var r=Sc(Array.isArray(e)?e:e.toArray()).sort(n),i=1,a=1;a<r.length;a++)n(r[a],r[a-1])!==0&&i++;return i}})}),zv=`setSymDifference`,Bv=J(zv,[`typed`,`size`,`concat`,`subset`,`setDifference`,`Index`],e=>{var{typed:t,size:n,concat:r,subset:i,setDifference:a,Index:o}=e;return t(zv,{"Array | Matrix, Array | Matrix":function(e,t){if(i(n(e),new o(0))===0)return Sc(t);if(i(n(t),new o(0))===0)return Sc(e);var s=Sc(e),c=Sc(t);return r(a(s,c),a(c,s))}})}),Vv=`setUnion`,Hv=J(Vv,[`typed`,`size`,`concat`,`subset`,`setIntersect`,`setSymDifference`,`Index`],e=>{var{typed:t,size:n,concat:r,subset:i,setIntersect:a,setSymDifference:o,Index:s}=e;return t(Vv,{"Array | Matrix, Array | Matrix":function(e,t){if(i(n(e),new s(0))===0)return Sc(t);if(i(n(t),new s(0))===0)return Sc(e);var c=Sc(e),l=Sc(t);return r(o(c,l),a(c,l))}})}),Uv=`add`,Wv=J(Uv,[`typed`,`matrix`,`addScalar`,`equalScalar`,`DenseMatrix`,`SparseMatrix`,`concat`],e=>{var{typed:t,matrix:n,addScalar:r,equalScalar:i,DenseMatrix:a,SparseMatrix:o,concat:s}=e,c=Df({typed:t}),l=Of({typed:t,equalScalar:i}),u=kf({typed:t,DenseMatrix:a}),d=wf({typed:t,matrix:n,concat:s});return t(Uv,{"any, any":r,"any, any, ...any":t.referToSelf(e=>(t,n,r)=>{for(var i=e(t,n),a=0;a<r.length;a++)i=e(i,r[a]);return i})},d({elop:r,DS:c,SS:l,Ss:u}))}),Gv=`hypot`,Kv=J(Gv,[`typed`,`abs`,`addScalar`,`divideScalar`,`multiplyScalar`,`sqrt`,`smaller`,`isPositive`],e=>{var{typed:t,abs:n,addScalar:r,divideScalar:i,multiplyScalar:a,sqrt:o,smaller:s,isPositive:c}=e;return t(Gv,{"... number | BigNumber":l,Array:l,Matrix:e=>l(Sc(e.toArray(),!0))});function l(e){for(var t=0,l=0,u=0;u<e.length;u++){if(Ar(e[u]))throw TypeError(`Unexpected type of argument to hypot`);var d=n(e[u]);s(l,d)?(t=a(t,a(i(l,d),i(l,d))),t=r(t,1),l=d):t=r(t,c(d)?a(i(d,l),i(d,l)):d)}return a(l,o(t))}}),qv=`norm`,Jv=J(qv,[`typed`,`abs`,`add`,`pow`,`conj`,`sqrt`,`multiply`,`equalScalar`,`larger`,`smaller`,`matrix`,`ctranspose`,`eigs`],e=>{var{typed:t,abs:n,add:r,pow:i,conj:a,sqrt:o,multiply:s,equalScalar:c,larger:l,smaller:u,matrix:d,ctranspose:f,eigs:p}=e;return t(qv,{number:Math.abs,Complex:function(e){return e.abs()},BigNumber:function(e){return e.abs()},boolean:function(e){return Math.abs(e)},Array:function(e){return S(d(e),2)},Matrix:function(e){return S(e,2)},"Array, number | BigNumber | string":function(e,t){return S(d(e),t)},"Matrix, number | BigNumber | string":function(e,t){return S(e,t)}});function m(e){var t=0;return e.forEach(function(e){var r=n(e);l(r,t)&&(t=r)},!0),t}function h(e){var t;return e.forEach(function(e){var r=n(e);(!t||u(r,t))&&(t=r)},!0),t||0}function g(e,t){if(t===1/0||t===`inf`)return m(e);if(t===-1/0||t===`-inf`)return h(e);if(t===`fro`)return S(e,2);if(typeof t==`number`&&!isNaN(t)){if(!c(t,0)){var a=0;return e.forEach(function(e){a=r(i(n(e),t),a)},!0),i(a,1/t)}return 1/0}throw Error(`Unsupported parameter value`)}function _(e){var t=0;return e.forEach(function(e,n){t=r(t,s(e,a(e)))}),n(o(t))}function v(e){var t=[],i=0;return e.forEach(function(e,a){var o=a[1],s=r(t[o]||0,n(e));l(s,i)&&(i=s),t[o]=s},!0),i}function y(e){var t=e.size();if(t[0]!==t[1])throw RangeError(`Invalid matrix dimensions`);var r=p(s(f(e),e)).values.toArray(),i=r[r.length-1];return n(o(i))}function b(e){var t=[],i=0;return e.forEach(function(e,a){var o=a[0],s=r(t[o]||0,n(e));l(s,i)&&(i=s),t[o]=s},!0),i}function x(e,t){if(t===1)return v(e);if(t===1/0||t===`inf`)return b(e);if(t===`fro`)return _(e);if(t===2)return y(e);throw Error(`Unsupported parameter value `+t)}function S(e,t){var n=e.size();if(n.length===1)return g(e,t);if(n.length===2){if(n[0]&&n[1])return x(e,t);throw RangeError(`Invalid matrix dimensions`)}}}),Yv=`dot`,Xv=J(Yv,[`typed`,`addScalar`,`multiplyScalar`,`conj`,`size`],e=>{var{typed:t,addScalar:n,multiplyScalar:r,conj:i,size:a}=e;return t(Yv,{"Array | DenseMatrix, Array | DenseMatrix":s,"SparseMatrix, SparseMatrix":c});function o(e,t){var n=a(e),r=a(t),i,o;if(n.length===1)i=n[0];else if(n.length===2&&n[1]===1)i=n[0];else throw RangeError(`Expected a column vector, instead got a matrix of size (`+n.join(`, `)+`)`);if(r.length===1)o=r[0];else if(r.length===2&&r[1]===1)o=r[0];else throw RangeError(`Expected a column vector, instead got a matrix of size (`+r.join(`, `)+`)`);if(i!==o)throw RangeError(`Vectors must have equal length (`+i+` != `+o+`)`);if(i===0)throw RangeError(`Cannot calculate the dot product of empty vectors`);return i}function s(e,s){var c=o(e,s),l=Fr(e)?e._data:e,u=Fr(e)?e._datatype||e.getDataType():void 0,d=Fr(s)?s._data:s,f=Fr(s)?s._datatype||s.getDataType():void 0,p=a(e).length===2,m=a(s).length===2,h=n,g=r;if(u&&f&&u===f&&typeof u==`string`&&u!==`mixed`){var _=u;h=t.find(n,[_,_]),g=t.find(r,[_,_])}if(!p&&!m){for(var v=g(i(l[0]),d[0]),y=1;y<c;y++)v=h(v,g(i(l[y]),d[y]));return v}if(!p&&m){for(var b=g(i(l[0]),d[0][0]),x=1;x<c;x++)b=h(b,g(i(l[x]),d[x][0]));return b}if(p&&!m){for(var S=g(i(l[0][0]),d[0]),C=1;C<c;C++)S=h(S,g(i(l[C][0]),d[C]));return S}if(p&&m){for(var w=g(i(l[0][0]),d[0][0]),T=1;T<c;T++)w=h(w,g(i(l[T][0]),d[T][0]));return w}}function c(e,t){o(e,t);for(var i=e._index,a=e._values,s=t._index,c=t._values,l=0,u=n,d=r,f=0,p=0;f<i.length&&p<s.length;){var m=i[f],h=s[p];if(m<h){f++;continue}if(m>h){p++;continue}m===h&&(l=u(l,d(a[f],c[p])),f++,p++)}return l}}),Zv=J(`trace`,[`typed`,`matrix`,`add`],e=>{var{typed:t,matrix:n,add:r}=e;return t(`trace`,{Array:function(e){return i(n(e))},SparseMatrix:a,DenseMatrix:i,any:vi});function i(e){var t=e._size,n=e._data;switch(t.length){case 1:if(t[0]===1)return vi(n[0]);throw RangeError(`Matrix must be square (size: `+Xs(t)+`)`);case 2:var i=t[0];if(i===t[1]){for(var a=0,o=0;o<i;o++)a=r(a,n[o][o]);return a}else throw RangeError(`Matrix must be square (size: `+Xs(t)+`)`);default:throw RangeError(`Matrix must be two dimensional (size: `+Xs(t)+`)`)}}function a(e){var t=e._values,n=e._index,i=e._ptr,a=e._size,o=a[0],s=a[1];if(o===s){var c=0;if(t.length>0)for(var l=0;l<s;l++)for(var u=i[l],d=i[l+1],f=u;f<d;f++){var p=n[f];if(p===l){c=r(c,t[f]);break}if(p>l)break}return c}throw RangeError(`Matrix must be square (size: `+Xs(a)+`)`)}}),Qv=`index`,$v=J(Qv,[`typed`,`Index`],e=>{var{typed:t,Index:n}=e;return t(Qv,{"...number | string | BigNumber | Range | Array | Matrix":function(e){var t=e.map(function(e){return Or(e)?e.toNumber():Pr(e)||Fr(e)?e.map(function(e){return Or(e)?e.toNumber():e}):e}),r=new n;return n.apply(r,t),r}})}),ey=new Set([`end`]),ty=J(`Node`,[`mathWithTransform`],e=>{var{mathWithTransform:t}=e;function n(e){for(var t of[...ey])if(e.has(t))throw Error(`Scope contains an illegal symbol, "`+t+`" is a reserved keyword`)}class r{get type(){return`Node`}get isNode(){return!0}evaluate(e){return this.compile().evaluate(e)}compile(){var e=this._compile(t,{}),r={},i=null;function a(t){var a=Tr(t);return n(a),e(a,r,i)}return{evaluate:a}}_compile(e,t){throw Error(`Method _compile must be implemented by type `+this.type)}forEach(e){throw Error(`Cannot run forEach on a Node interface`)}map(e){throw Error(`Cannot run map on a Node interface`)}_ifNode(e){if(!li(e))throw TypeError(`Callback function must return a Node`);return e}traverse(e){e(this,null,null);function t(e,n){e.forEach(function(e,r,i){n(e,r,i),t(e,n)})}t(this,e)}transform(e){function t(n,r,i){var a=e(n,r,i);return a===n?n.map(t):a}return t(this,null,null)}filter(e){var t=[];return this.traverse(function(n,r,i){e(n,r,i)&&t.push(n)}),t}clone(){throw Error(`Cannot clone a Node interface`)}cloneDeep(){return this.map(function(e){return e.cloneDeep()})}equals(e){return e?this.type===e.type&&Si(this,e):!1}toString(e){var t=this._getCustomString(e);return t===void 0?this._toString(e):t}_toString(){throw Error(`_toString not implemented for `+this.type)}toJSON(){throw Error(`Cannot serialize object: toJSON not implemented by `+this.type)}toHTML(e){var t=this._getCustomString(e);return t===void 0?this._toHTML(e):t}_toHTML(){throw Error(`_toHTML not implemented for `+this.type)}toTex(e){var t=this._getCustomString(e);return t===void 0?this._toTex(e):t}_toTex(e){throw Error(`_toTex not implemented for `+this.type)}_getCustomString(e){if(e&&typeof e==`object`)switch(typeof e.handler){case`object`:case`undefined`:return;case`function`:return e.handler(this,e);default:throw TypeError(`Object or function expected as callback`)}}getIdentifier(){return this.type}getContent(){return this}}return r},{isClass:!0,isNode:!0});function ny(e){return e&&e.isIndexError?new ac(e.index+1,e.min+1,e.max===void 0?void 0:e.max+1):e}function ry(e){var{subset:t}=e;return function(e,n){try{if(Array.isArray(e))return t(e,n);if(e&&typeof e.subset==`function`)return e.subset(n);if(typeof e==`string`)return t(e,n);if(typeof e==`object`){if(!n.isObjectProperty())throw TypeError(`Cannot apply a numeric index as object property`);return fr(e,n.getObjectProperty())}else throw TypeError(`Cannot apply index: unsupported type of object`)}catch(e){throw ny(e)}}}var iy=`AccessorNode`,ay=J(iy,[`subset`,`Node`],e=>{var{subset:t,Node:n}=e,r=ry({subset:t});function i(e){return!($r(e)||ei(e)||ii(e)||si(e)||ui(e)||fi(e)||hi(e))}class a extends n{constructor(e,t){var n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:!1;if(super(),!li(e))throw TypeError(`Node expected for parameter "object"`);if(!ci(t))throw TypeError(`IndexNode expected for parameter "index"`);this.object=e,this.index=t,this.optionalChaining=n}get name(){return this.index?this.index.isObjectProperty()?this.index.getObjectProperty():``:this.object.name||``}get type(){return iy}get isAccessorNode(){return!0}_compile(e,t){var n=this.object._compile(e,t),i=this.index._compile(e,t),a=this.optionalChaining,o=$r(this.object)&&this.object.optionalChaining;if(this.index.isObjectProperty()){var s=this.index.getObjectProperty();return function(e,t,r){var i=r||{},c=n(e,t,i);if(a&&c==null){i.optionalShortCircuit=!0;return}if(!(o&&i!=null&&i.optionalShortCircuit))return fr(c,s)}}else return function(e,t,s){var c=s||{},l=n(e,t,c);if(a&&l==null){c.optionalShortCircuit=!0;return}if(!(o&&c!=null&&c.optionalShortCircuit))return r(l,i(e,t,l))}}forEach(e){e(this.object,`object`,this),e(this.index,`index`,this)}map(e){return new a(this._ifNode(e(this.object,`object`,this)),this._ifNode(e(this.index,`index`,this)),this.optionalChaining)}clone(){return new a(this.object,this.index,this.optionalChaining)}_toString(e){var t=this.object.toString(e);i(this.object)&&(t=`(`+t+`)`);var n=this.optionalChaining?this.index.dotNotation?`?`:`?.`:``;return t+n+this.index.toString(e)}_toHTML(e){var t=this.object.toHTML(e);return i(this.object)&&(t=`<span class="math-parenthesis math-round-parenthesis">(</span>`+t+`<span class="math-parenthesis math-round-parenthesis">)</span>`),t+this.index.toHTML(e)}_toTex(e){var t=this.object.toTex(e);return i(this.object)&&(t=`\\left(' + object + '\\right)`),t+this.index.toTex(e)}toJSON(){return{mathjs:iy,object:this.object,index:this.index,optionalChaining:this.optionalChaining}}static fromJSON(e){return new a(e.object,e.index,e.optionalChaining)}}return nh(a,`name`,iy),a},{isClass:!0,isNode:!0}),oy=`ArrayNode`,sy=J(oy,[`Node`],e=>{var{Node:t}=e;class n extends t{constructor(e){if(super(),this.items=e||[],!Array.isArray(this.items)||!this.items.every(li))throw TypeError(`Array containing Nodes expected`)}get type(){return oy}get isArrayNode(){return!0}_compile(e,t){var n=Cc(this.items,function(n){return n._compile(e,t)});if(e.config.matrix!==`Array`){var r=e.matrix;return function(e,t,i){return r(Cc(n,function(n){return n(e,t,i)}))}}else return function(e,t,r){return Cc(n,function(n){return n(e,t,r)})}}forEach(e){for(var t=0;t<this.items.length;t++){var n=this.items[t];e(n,`items[`+t+`]`,this)}}map(e){for(var t=[],r=0;r<this.items.length;r++)t[r]=this._ifNode(e(this.items[r],`items[`+r+`]`,this));return new n(t)}clone(){return new n(this.items.slice(0))}_toString(e){return`[`+this.items.map(function(t){return t.toString(e)}).join(`, `)+`]`}toJSON(){return{mathjs:oy,items:this.items}}static fromJSON(e){return new n(e.items)}_toHTML(e){return`<span class="math-parenthesis math-square-parenthesis">[</span>`+this.items.map(function(t){return t.toHTML(e)}).join(`<span class="math-separator">,</span>`)+`<span class="math-parenthesis math-square-parenthesis">]</span>`}_toTex(e){function t(n,r){var i=n.some(ei)&&!n.every(ei),a=r||i,o=a?`&`:`\\\\`,s=n.map(function(n){return n.items?t(n.items,!r):n.toTex(e)}).join(o);return i||!a||a&&!r?`\\begin{bmatrix}`+s+`\\end{bmatrix}`:s}return t(this.items,!1)}}return nh(n,`name`,oy),n},{isClass:!0,isNode:!0});function cy(e){var{subset:t,matrix:n}=e;return function(e,r,i){try{if(Array.isArray(e))return n(e).subset(r,i).valueOf().forEach((t,n)=>{e[n]=t}),e;if(e&&typeof e.subset==`function`)return e.subset(r,i);if(typeof e==`string`)return t(e,r,i);if(typeof e==`object`){if(!r.isObjectProperty())throw TypeError(`Cannot apply a numeric index as object property`);return pr(e,r.getObjectProperty(),i),e}else throw TypeError(`Cannot apply index: unsupported type of object`)}catch(e){throw ny(e)}}}var ly=[{AssignmentNode:{},FunctionAssignmentNode:{}},{ConditionalNode:{latexLeftParens:!1,latexRightParens:!1,latexParens:!1}},{"OperatorNode:or":{op:`or`,associativity:`left`,associativeWith:[]}},{"OperatorNode:xor":{op:`xor`,associativity:`left`,associativeWith:[]}},{"OperatorNode:and":{op:`and`,associativity:`left`,associativeWith:[]}},{"OperatorNode:bitOr":{op:`|`,associativity:`left`,associativeWith:[]}},{"OperatorNode:bitXor":{op:`^|`,associativity:`left`,associativeWith:[]}},{"OperatorNode:bitAnd":{op:`&`,associativity:`left`,associativeWith:[]}},{"OperatorNode:equal":{op:`==`,associativity:`left`,associativeWith:[]},"OperatorNode:unequal":{op:`!=`,associativity:`left`,associativeWith:[]},"OperatorNode:smaller":{op:`<`,associativity:`left`,associativeWith:[]},"OperatorNode:larger":{op:`>`,associativity:`left`,associativeWith:[]},"OperatorNode:smallerEq":{op:`<=`,associativity:`left`,associativeWith:[]},"OperatorNode:largerEq":{op:`>=`,associativity:`left`,associativeWith:[]},RelationalNode:{associativity:`left`,associativeWith:[]}},{"OperatorNode:leftShift":{op:`<<`,associativity:`left`,associativeWith:[]},"OperatorNode:rightArithShift":{op:`>>`,associativity:`left`,associativeWith:[]},"OperatorNode:rightLogShift":{op:`>>>`,associativity:`left`,associativeWith:[]}},{"OperatorNode:to":{op:`to`,associativity:`left`,associativeWith:[]}},{RangeNode:{}},{"OperatorNode:add":{op:`+`,associativity:`left`,associativeWith:[`OperatorNode:add`,`OperatorNode:subtract`]},"OperatorNode:subtract":{op:`-`,associativity:`left`,associativeWith:[]}},{"OperatorNode:multiply":{op:`*`,associativity:`left`,associativeWith:[`OperatorNode:multiply`,`OperatorNode:divide`,`Operator:dotMultiply`,`Operator:dotDivide`]},"OperatorNode:divide":{op:`/`,associativity:`left`,associativeWith:[],latexLeftParens:!1,latexRightParens:!1,latexParens:!1},"OperatorNode:dotMultiply":{op:`.*`,associativity:`left`,associativeWith:[`OperatorNode:multiply`,`OperatorNode:divide`,`OperatorNode:dotMultiply`,`OperatorNode:doDivide`]},"OperatorNode:dotDivide":{op:`./`,associativity:`left`,associativeWith:[]},"OperatorNode:mod":{op:`mod`,associativity:`left`,associativeWith:[]}},{"OperatorNode:multiply":{associativity:`left`,associativeWith:[`OperatorNode:multiply`,`OperatorNode:divide`,`Operator:dotMultiply`,`Operator:dotDivide`]}},{"OperatorNode:unaryPlus":{op:`+`,associativity:`right`},"OperatorNode:unaryMinus":{op:`-`,associativity:`right`},"OperatorNode:bitNot":{op:`~`,associativity:`right`},"OperatorNode:not":{op:`not`,associativity:`right`}},{"OperatorNode:pow":{op:`^`,associativity:`right`,associativeWith:[],latexRightParens:!1},"OperatorNode:dotPow":{op:`.^`,associativity:`right`,associativeWith:[]}},{"OperatorNode:nullish":{op:`??`,associativity:`left`,associativeWith:[]}},{"OperatorNode:factorial":{op:`!`,associativity:`left`}},{"OperatorNode:ctranspose":{op:`'`,associativity:`left`}}];function uy(e,t){if(!t||t!==`auto`)return e;for(var n=e;fi(n);)n=n.content;return n}function dy(e,t,n,r){var i=e;t!==`keep`&&(i=e.getContent());for(var a=i.getIdentifier(),o=null,s=0;s<ly.length;s++)if(a in ly[s]){o=s;break}if(a===`OperatorNode:multiply`&&i.implicit&&n!==`show`){var c=uy(i.args[0],t);!(ii(c)&&r&&r.getIdentifier()===`OperatorNode:divide`&&ai(uy(r.args[0],t)))&&!(c.getIdentifier()===`OperatorNode:divide`&&ai(uy(c.args[0],t))&&ii(uy(c.args[1])))&&(o+=1)}return o}function fy(e,t){var n=e;t!==`keep`&&(n=e.getContent());var r=n.getIdentifier(),i=dy(n,t);if(i===null)return null;var a=ly[i][r];if(Ei(a,`associativity`)){if(a.associativity===`left`)return`left`;if(a.associativity===`right`)return`right`;throw Error(`'`+r+`' has the invalid associativity '`+a.associativity+`'.`)}return null}function py(e,t,n){var r=n===`keep`?e:e.getContent(),i=n===`keep`?t:e.getContent(),a=r.getIdentifier(),o=i.getIdentifier(),s=dy(r,n);if(s===null)return null;var c=ly[s][a];if(Ei(c,`associativeWith`)&&c.associativeWith instanceof Array){for(var l=0;l<c.associativeWith.length;l++)if(c.associativeWith[l]===o)return!0;return!1}return null}function my(e){var t=`OperatorNode:`+e;for(var n of ly)if(t in n)return n[t].op;return null}var hy=`AssignmentNode`,gy=J(hy,[`subset`,`?matrix`,`Node`],e=>{var{subset:t,matrix:n,Node:r}=e,i=ry({subset:t}),a=cy({subset:t,matrix:n});function o(e,t,n){t||=`keep`;var r=dy(e,t,n),i=dy(e.value,t,n);return t===`all`||i!==null&&i<=r}class s extends r{constructor(e,t,n){if(super(),this.object=e,this.index=n?t:null,this.value=n||t,!hi(e)&&!$r(e))throw TypeError(`SymbolNode or AccessorNode expected as "object"`);if(hi(e)&&e.name===`end`)throw Error(`Cannot assign to symbol "end"`);if(this.index&&!ci(this.index))throw TypeError(`IndexNode expected as "index"`);if(!li(this.value))throw TypeError(`Node expected as "value"`)}get name(){return this.index?this.index.isObjectProperty()?this.index.getObjectProperty():``:this.object.name||``}get type(){return hy}get isAssignmentNode(){return!0}_compile(e,t){var n=this.object._compile(e,t),r=this.index?this.index._compile(e,t):null,o=this.value._compile(e,t),s=this.object.name;if(!this.index){if(!hi(this.object))throw TypeError(`SymbolNode expected as object`);return function(e,t,n){var r=o(e,t,n);return e.set(s,r),r}}else if(this.index.isObjectProperty()){var c=this.index.getObjectProperty();return function(e,t,r){var i=n(e,t,r),a=o(e,t,r);return pr(i,c,a),a}}else if(hi(this.object))return function(e,t,i){var c=n(e,t,i),l=o(e,t,i),u=r(e,t,c);return e.set(s,a(c,u,l)),l};else{var l=this.object.object._compile(e,t);if(this.object.index.isObjectProperty()){var u=this.object.index.getObjectProperty();return function(e,t,n){var i=l(e,t,n),s=fr(i,u),c=r(e,t,s),d=o(e,t,n);return pr(i,u,a(s,c,d)),d}}else{var d=this.object.index._compile(e,t);return function(e,t,n){var s=l(e,t,n),c=d(e,t,s),u=i(s,c),f=r(e,t,u),p=o(e,t,n);return a(s,c,a(u,f,p)),p}}}}forEach(e){e(this.object,`object`,this),this.index&&e(this.index,`index`,this),e(this.value,`value`,this)}map(e){return new s(this._ifNode(e(this.object,`object`,this)),this.index?this._ifNode(e(this.index,`index`,this)):null,this._ifNode(e(this.value,`value`,this)))}clone(){return new s(this.object,this.index,this.value)}_toString(e){var t=this.object.toString(e),n=this.index?this.index.toString(e):``,r=this.value.toString(e);return o(this,e&&e.parenthesis,e&&e.implicit)&&(r=`(`+r+`)`),t+n+` = `+r}toJSON(){return{mathjs:hy,object:this.object,index:this.index,value:this.value}}static fromJSON(e){return new s(e.object,e.index,e.value)}_toHTML(e){var t=this.object.toHTML(e),n=this.index?this.index.toHTML(e):``,r=this.value.toHTML(e);return o(this,e&&e.parenthesis,e&&e.implicit)&&(r=`<span class="math-paranthesis math-round-parenthesis">(</span>`+r+`<span class="math-paranthesis math-round-parenthesis">)</span>`),t+n+`<span class="math-operator math-assignment-operator math-variable-assignment-operator math-binary-operator">=</span>`+r}_toTex(e){var t=this.object.toTex(e),n=this.index?this.index.toTex(e):``,r=this.value.toTex(e);return o(this,e&&e.parenthesis,e&&e.implicit)&&(r=`\\left(${r}\\right)`),t+n+`=`+r}}return nh(s,`name`,hy),s},{isClass:!0,isNode:!0}),_y=`BlockNode`,vy=J(_y,[`ResultSet`,`Node`],e=>{var{ResultSet:t,Node:n}=e;class r extends n{constructor(e){if(super(),!Array.isArray(e))throw Error(`Array expected`);this.blocks=e.map(function(e){var t=e&&e.node,n=e&&e.visible!==void 0?e.visible:!0;if(!li(t))throw TypeError(`Property "node" must be a Node`);if(typeof n!=`boolean`)throw TypeError(`Property "visible" must be a boolean`);return{node:t,visible:n}})}get type(){return _y}get isBlockNode(){return!0}_compile(e,n){var r=Cc(this.blocks,function(t){return{evaluate:t.node._compile(e,n),visible:t.visible}});return function(e,n,i){var a=[];return wc(r,function(t){var r=t.evaluate(e,n,i);t.visible&&a.push(r)}),new t(a)}}forEach(e){for(var t=0;t<this.blocks.length;t++)e(this.blocks[t].node,`blocks[`+t+`].node`,this)}map(e){for(var t=[],n=0;n<this.blocks.length;n++){var i=this.blocks[n];t[n]={node:this._ifNode(e(i.node,`blocks[`+n+`].node`,this)),visible:i.visible}}return new r(t)}clone(){return new r(this.blocks.map(function(e){return{node:e.node,visible:e.visible}}))}_toString(e){return this.blocks.map(function(t){return t.node.toString(e)+(t.visible?``:`;`)}).join(`
|
|
@@ -67,7 +67,7 @@ In case of a (multi dimensional) array or matrix, the prob order quantile of all
|
|
|
67
67
|
return false;
|
|
68
68
|
}`),e.length!==n.length&&(t=`if (x !== x) return false;\n${t}`),Function(`x`,`${t}\nreturn true;`)}function $M(e){return typeof e==`bigint`?`${NO(e)}n`:NO(e)}function eN(e,t){let n=Math.ceil(e)*t-1;return(n-n%64+64||64)/t}function tN(e,t=0){return e.length>=t?e.subarray(0,t):gD(new e.constructor(t),e,0)}var nN=class{constructor(e,t=0,n=1){this.length=Math.ceil(t/n),this.buffer=new e(this.length),this.stride=n,this.BYTES_PER_ELEMENT=e.BYTES_PER_ELEMENT,this.ArrayType=e}get byteLength(){return Math.ceil(this.length*this.stride)*this.BYTES_PER_ELEMENT}get reservedLength(){return this.buffer.length/this.stride}get reservedByteLength(){return this.buffer.byteLength}set(e,t){return this}append(e){return this.set(this.length,e)}reserve(e){if(e>0){this.length+=e;let t=this.stride,n=this.length*t,r=this.buffer.length;n>=r&&this._resize(eN(r===0?n*1:n*2,this.BYTES_PER_ELEMENT))}return this}flush(e=this.length){e=eN(e*this.stride,this.BYTES_PER_ELEMENT);let t=tN(this.buffer,e);return this.clear(),t}clear(){return this.length=0,this.buffer=new this.ArrayType,this}_resize(e){return this.buffer=tN(this.buffer,e)}},rN=class extends nN{last(){return this.get(this.length-1)}get(e){return this.buffer[e]}set(e,t){return this.reserve(e-this.length+1),this.buffer[e*this.stride]=t,this}},iN=class extends rN{constructor(){super(Uint8Array,0,1/8),this.numValid=0}get numInvalid(){return this.length-this.numValid}get(e){return this.buffer[e>>3]>>e%8&1}set(e,t){let{buffer:n}=this.reserve(e-this.length+1),r=e>>3,i=e%8,a=n[r]>>i&1;return t?a===0&&(n[r]|=1<<i,++this.numValid):a===1&&(n[r]&=~(1<<i),--this.numValid),this}clear(){return this.numValid=0,super.clear()}},aN=class extends rN{constructor(e){super(e.OffsetArrayType,1,1)}append(e){return this.set(this.length-1,e)}set(e,t){let n=this.length-1,r=this.reserve(e-n+1).buffer;return n<e++&&n>=0&&r.fill(r[n],n,e),r[e]=r[e-1]+t,this}flush(e=this.length-1){return e>this.length&&this.set(e-1,this.BYTES_PER_ELEMENT>4?BigInt(0):0),super.flush(e+1)}},oN=class{static throughNode(e){throw Error(`"throughNode" not available in this environment`)}static throughDOM(e){throw Error(`"throughDOM" not available in this environment`)}constructor({type:e,nullValues:t}){this.length=0,this.finished=!1,this.type=e,this.children=[],this.nullValues=t,this.stride=Xk(e),this._nulls=new iN,t&&t.length>0&&(this._isValid=QM(t))}toVector(){return new JM([this.flush()])}get ArrayType(){return this.type.ArrayType}get nullCount(){return this._nulls.numInvalid}get numChildren(){return this.children.length}get byteLength(){let e=0,{_offsets:t,_values:n,_nulls:r,_typeIds:i,children:a}=this;return t&&(e+=t.byteLength),n&&(e+=n.byteLength),r&&(e+=r.byteLength),i&&(e+=i.byteLength),a.reduce((e,t)=>e+t.byteLength,e)}get reservedLength(){return this._nulls.reservedLength}get reservedByteLength(){let e=0;return this._offsets&&(e+=this._offsets.reservedByteLength),this._values&&(e+=this._values.reservedByteLength),this._nulls&&(e+=this._nulls.reservedByteLength),this._typeIds&&(e+=this._typeIds.reservedByteLength),this.children.reduce((e,t)=>e+t.reservedByteLength,e)}get valueOffsets(){return this._offsets?this._offsets.buffer:null}get values(){return this._values?this._values.buffer:null}get nullBitmap(){return this._nulls?this._nulls.buffer:null}get typeIds(){return this._typeIds?this._typeIds.buffer:null}append(e){return this.set(this.length,e)}isValid(e){return this._isValid(e)}set(e,t){return this.setValid(e,this.isValid(t))&&this.setValue(e,t),this}setValue(e,t){this._setValue(this,e,t)}setValid(e,t){return this.length=this._nulls.set(e,+t).length,t}addChild(e,t=`${this.numChildren}`){throw Error(`Cannot append children to non-nested type "${this.type}"`)}getChildAt(e){return this.children[e]||null}flush(){let e,t,n,r,{type:i,length:a,nullCount:o,_typeIds:s,_offsets:c,_values:l,_nulls:u}=this;(t=s?.flush(a))?r=c?.flush(a):e=(r=c?.flush(a))?l?.flush(c.last()):l?.flush(a),o>0&&(n=u?.flush(a));let d=this.children.map(e=>e.flush());return this.clear(),wM({type:i,length:a,nullCount:o,children:d,child:d[0],data:e,typeIds:t,nullBitmap:n,valueOffsets:r})}finish(){this.finished=!0;for(let e of this.children)e.finish();return this}clear(){var e,t,n,r;this.length=0,(e=this._nulls)==null||e.clear(),(t=this._values)==null||t.clear(),(n=this._offsets)==null||n.clear(),(r=this._typeIds)==null||r.clear();for(let e of this.children)e.clear();return this}};oN.prototype.length=1,oN.prototype.stride=1,oN.prototype.children=null,oN.prototype.finished=!1,oN.prototype.nullValues=null,oN.prototype._isValid=()=>!0;var sN=class extends oN{constructor(e){super(e),this._values=new rN(this.ArrayType,0,this.stride)}setValue(e,t){let n=this._values;return n.reserve(e-n.length+1),super.setValue(e,t)}},cN=class extends oN{constructor(e){super(e),this._pendingLength=0,this._offsets=new aN(e.type)}setValue(e,t){let n=this._pending||=new Map,r=n.get(e);r&&(this._pendingLength-=r.length),this._pendingLength+=t instanceof Qj?t[Jj].length:t.length,n.set(e,t)}setValid(e,t){return super.setValid(e,t)?!0:((this._pending||=new Map).set(e,void 0),!1)}clear(){return this._pendingLength=0,this._pending=void 0,super.clear()}flush(){return this._flush(),super.flush()}finish(){return this._flush(),super.finish()}_flush(){let e=this._pending,t=this._pendingLength;return this._pendingLength=0,this._pending=void 0,e&&e.size>0&&this._flushPending(e,t),this}},lN=class{constructor(){this.bb=null,this.bb_pos=0}__init(e,t){return this.bb_pos=e,this.bb=t,this}offset(){return this.bb.readInt64(this.bb_pos)}metaDataLength(){return this.bb.readInt32(this.bb_pos+8)}bodyLength(){return this.bb.readInt64(this.bb_pos+16)}static sizeOf(){return 24}static createBlock(e,t,n,r){return e.prep(8,24),e.writeInt64(BigInt(r??0)),e.pad(4),e.writeInt32(n),e.writeInt64(BigInt(t??0)),e.offset()}},uN=class e{constructor(){this.bb=null,this.bb_pos=0}__init(e,t){return this.bb_pos=e,this.bb=t,this}static getRootAsFooter(t,n){return(n||new e).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsFooter(t,n){return t.setPosition(t.position()+4),(n||new e).__init(t.readInt32(t.position())+t.position(),t)}version(){let e=this.bb.__offset(this.bb_pos,4);return e?this.bb.readInt16(this.bb_pos+e):LD.V1}schema(e){let t=this.bb.__offset(this.bb_pos,6);return t?(e||new kO).__init(this.bb.__indirect(this.bb_pos+t),this.bb):null}dictionaries(e,t){let n=this.bb.__offset(this.bb_pos,8);return n?(t||new lN).__init(this.bb.__vector(this.bb_pos+n)+e*24,this.bb):null}dictionariesLength(){let e=this.bb.__offset(this.bb_pos,8);return e?this.bb.__vector_len(this.bb_pos+e):0}recordBatches(e,t){let n=this.bb.__offset(this.bb_pos,10);return n?(t||new lN).__init(this.bb.__vector(this.bb_pos+n)+e*24,this.bb):null}recordBatchesLength(){let e=this.bb.__offset(this.bb_pos,10);return e?this.bb.__vector_len(this.bb_pos+e):0}customMetadata(e,t){let n=this.bb.__offset(this.bb_pos,12);return n?(t||new sO).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+n)+e*4),this.bb):null}customMetadataLength(){let e=this.bb.__offset(this.bb_pos,12);return e?this.bb.__vector_len(this.bb_pos+e):0}static startFooter(e){e.startObject(5)}static addVersion(e,t){e.addFieldInt16(0,t,LD.V1)}static addSchema(e,t){e.addFieldOffset(1,t,0)}static addDictionaries(e,t){e.addFieldOffset(2,t,0)}static startDictionariesVector(e,t){e.startVector(24,t,8)}static addRecordBatches(e,t){e.addFieldOffset(3,t,0)}static startRecordBatchesVector(e,t){e.startVector(24,t,8)}static addCustomMetadata(e,t){e.addFieldOffset(4,t,0)}static createCustomMetadataVector(e,t){e.startVector(4,t.length,4);for(let n=t.length-1;n>=0;n--)e.addOffset(t[n]);return e.endVector()}static startCustomMetadataVector(e,t){e.startVector(4,t,4)}static endFooter(e){return e.endObject()}static finishFooterBuffer(e,t){e.finish(t)}static finishSizePrefixedFooterBuffer(e,t){e.finish(t,void 0,!0)}},dN=class e{constructor(e=[],t,n,r=LD.V5){this.fields=e||[],this.metadata=t||new Map,n||=mN(this.fields),this.dictionaries=n,this.metadataVersion=r}get[Symbol.toStringTag](){return`Schema`}get names(){return this.fields.map(e=>e.name)}toString(){return`Schema<{ ${this.fields.map((e,t)=>`${t}: ${e}`).join(`, `)} }>`}select(t){let n=new Set(t);return new e(this.fields.filter(e=>n.has(e.name)),this.metadata)}selectAt(t){return new e(t.map(e=>this.fields[e]).filter(Boolean),this.metadata)}assign(...t){let n=t[0]instanceof e?t[0]:Array.isArray(t[0])?new e(t[0]):new e(t),r=[...this.fields],i=pN(pN(new Map,this.metadata),n.metadata),a=n.fields.filter(e=>{let t=r.findIndex(t=>t.name===e.name);return~t?(r[t]=e.clone({metadata:pN(pN(new Map,r[t].metadata),e.metadata)}))&&!1:!0}),o=mN(a,new Map);return new e([...r,...a],i,new Map([...this.dictionaries,...o]))}};dN.prototype.fields=null,dN.prototype.metadata=null,dN.prototype.dictionaries=null;var fN=class e{static new(...t){let[n,r,i,a]=t;return t[0]&&typeof t[0]==`object`&&({name:n}=t[0],r===void 0&&(r=t[0].type),i===void 0&&(i=t[0].nullable),a===void 0&&(a=t[0].metadata)),new e(`${n}`,r,i,a)}constructor(e,t,n=!1,r){this.name=e,this.type=t,this.nullable=n,this.metadata=r||new Map}get typeId(){return this.type.typeId}get[Symbol.toStringTag](){return`Field`}toString(){return`${this.name}: ${this.type}`}clone(...t){let[n,r,i,a]=t;return!t[0]||typeof t[0]!=`object`?[n=this.name,r=this.type,i=this.nullable,a=this.metadata]=t:{name:n=this.name,type:r=this.type,nullable:i=this.nullable,metadata:a=this.metadata}=t[0],e.new(n,r,i,a)}};fN.prototype.type=null,fN.prototype.name=null,fN.prototype.nullable=null,fN.prototype.metadata=null;function pN(e,t){return new Map([...e||new Map,...t||new Map])}function mN(e,t=new Map){for(let n=-1,r=e.length;++n<r;){let r=e[n].type;if(hk.isDictionary(r)){if(!t.has(r.id))t.set(r.id,r.dictionary);else if(t.get(r.id)!==r.dictionary)throw Error(`Cannot create Schema containing two different dictionaries with the same Id`)}r.children&&r.children.length>0&&mN(r.children,t)}return t}var hN=YD,gN=JD,_N=class{static decode(e){e=new gN(xD(e));let t=uN.getRootAsFooter(e);return new vN(dN.decode(t.schema(),new Map,t.version()),t)}static encode(e){let t=new hN,n=dN.encode(t,e.schema);uN.startRecordBatchesVector(t,e.numRecordBatches);for(let n of[...e.recordBatches()].slice().reverse())yN.encode(t,n);let r=t.endVector();uN.startDictionariesVector(t,e.numDictionaries);for(let n of[...e.dictionaryBatches()].slice().reverse())yN.encode(t,n);let i=t.endVector();return uN.startFooter(t),uN.addSchema(t,n),uN.addVersion(t,LD.V5),uN.addRecordBatches(t,r),uN.addDictionaries(t,i),uN.finishFooterBuffer(t,uN.endFooter(t)),t.asUint8Array()}get numRecordBatches(){return this._recordBatches.length}get numDictionaries(){return this._dictionaryBatches.length}constructor(e,t=LD.V5,n,r){this.schema=e,this.version=t,n&&(this._recordBatches=n),r&&(this._dictionaryBatches=r)}*recordBatches(){for(let e,t=-1,n=this.numRecordBatches;++t<n;)(e=this.getRecordBatch(t))&&(yield e)}*dictionaryBatches(){for(let e,t=-1,n=this.numDictionaries;++t<n;)(e=this.getDictionaryBatch(t))&&(yield e)}getRecordBatch(e){return e>=0&&e<this.numRecordBatches&&this._recordBatches[e]||null}getDictionaryBatch(e){return e>=0&&e<this.numDictionaries&&this._dictionaryBatches[e]||null}},vN=class extends _N{get numRecordBatches(){return this._footer.recordBatchesLength()}get numDictionaries(){return this._footer.dictionariesLength()}constructor(e,t){super(e,t.version()),this._footer=t}getRecordBatch(e){if(e>=0&&e<this.numRecordBatches){let t=this._footer.recordBatches(e);if(t)return yN.decode(t)}return null}getDictionaryBatch(e){if(e>=0&&e<this.numDictionaries){let t=this._footer.dictionaries(e);if(t)return yN.decode(t)}return null}},yN=class e{static decode(t){return new e(t.metaDataLength(),t.bodyLength(),t.offset())}static encode(e,t){let{metaDataLength:n}=t,r=BigInt(t.offset),i=BigInt(t.bodyLength);return lN.createBlock(e,r,n,i)}constructor(e,t,n){this.metaDataLength=e,this.offset=PO(n),this.bodyLength=PO(t)}},bN=Object.freeze({done:!0,value:void 0}),xN=class{constructor(e){this._json=e}get schema(){return this._json.schema}get batches(){return this._json.batches||[]}get dictionaries(){return this._json.dictionaries||[]}},SN=class{tee(){return this._getDOMStream().tee()}pipe(e,t){return this._getNodeStream().pipe(e,t)}pipeTo(e,t){return this._getDOMStream().pipeTo(e,t)}pipeThrough(e,t){return this._getDOMStream().pipeThrough(e,t)}_getDOMStream(){return this._DOMStream||=this.toDOMStream()}_getNodeStream(){return this._nodeStream||=this.toNodeStream()}},CN=class extends SN{constructor(){super(),this._values=[],this.resolvers=[],this._closedPromise=new Promise(e=>this._closedPromiseResolve=e)}get closed(){return this._closedPromise}cancel(e){return VE(this,void 0,void 0,function*(){yield this.return(e)})}write(e){this._ensureOpen()&&(this.resolvers.length<=0?this._values.push(e):this.resolvers.shift().resolve({done:!1,value:e}))}abort(e){this._closedPromiseResolve&&(this.resolvers.length<=0?this._error={error:e}:this.resolvers.shift().reject({done:!0,value:e}))}close(){if(this._closedPromiseResolve){let{resolvers:e}=this;for(;e.length>0;)e.shift().resolve(bN);this._closedPromiseResolve(),this._closedPromiseResolve=void 0}}[Symbol.asyncIterator](){return this}toDOMStream(e){return kD.toDOMStream(this._closedPromiseResolve||this._error?this:this._values,e)}toNodeStream(e){return kD.toNodeStream(this._closedPromiseResolve||this._error?this:this._values,e)}throw(e){return VE(this,void 0,void 0,function*(){return yield this.abort(e),bN})}return(e){return VE(this,void 0,void 0,function*(){return yield this.close(),bN})}read(e){return VE(this,void 0,void 0,function*(){return(yield this.next(e,`read`)).value})}peek(e){return VE(this,void 0,void 0,function*(){return(yield this.next(e,`peek`)).value})}next(...e){return this._values.length>0?Promise.resolve({done:!1,value:this._values.shift()}):this._error?Promise.reject({done:!0,value:this._error.error}):this._closedPromiseResolve?new Promise((e,t)=>{this.resolvers.push({resolve:e,reject:t})}):Promise.resolve(bN)}_ensureOpen(){if(this._closedPromiseResolve)return!0;throw Error(`AsyncQueue is closed`)}},wN=class extends CN{write(e){if((e=xD(e)).byteLength>0)return super.write(e)}toString(e=!1){return e?JE(this.toUint8Array(!0)):this.toUint8Array(!1).then(JE)}toUint8Array(e=!1){return e?_D(this._values)[0]:VE(this,void 0,void 0,function*(){var e,t,n,r;let i=[],a=0;try{for(var o=!0,s=KE(this),c;c=yield s.next(),e=c.done,!e;o=!0){r=c.value,o=!1;let e=r;i.push(e),a+=e.byteLength}}catch(e){t={error:e}}finally{try{!o&&!e&&(n=s.return)&&(yield n.call(s))}finally{if(t)throw t.error}}return _D(i,a)[0]})}},TN=class{constructor(e){e&&(this.source=new DN(kD.fromIterable(e)))}[Symbol.iterator](){return this}next(e){return this.source.next(e)}throw(e){return this.source.throw(e)}return(e){return this.source.return(e)}peek(e){return this.source.peek(e)}read(e){return this.source.read(e)}},EN=class e{constructor(t){t instanceof e?this.source=t.source:t instanceof wN?this.source=new ON(kD.fromAsyncIterable(t)):fD(t)?this.source=new ON(kD.fromNodeStream(t)):uD(t)?this.source=new ON(kD.fromDOMStream(t)):sD(t)?this.source=new ON(kD.fromDOMStream(t.body)):nD(t)?this.source=new ON(kD.fromIterable(t)):(tD(t)||rD(t))&&(this.source=new ON(kD.fromAsyncIterable(t)))}[Symbol.asyncIterator](){return this}next(e){return this.source.next(e)}throw(e){return this.source.throw(e)}return(e){return this.source.return(e)}get closed(){return this.source.closed}cancel(e){return this.source.cancel(e)}peek(e){return this.source.peek(e)}read(e){return this.source.read(e)}},DN=class{constructor(e){this.source=e}cancel(e){this.return(e)}peek(e){return this.next(e,`peek`).value}read(e){return this.next(e,`read`).value}next(e,t=`read`){return this.source.next({cmd:t,size:e})}throw(e){return Object.create(this.source.throw&&this.source.throw(e)||bN)}return(e){return Object.create(this.source.return&&this.source.return(e)||bN)}},ON=class{constructor(e){this.source=e,this._closedPromise=new Promise(e=>this._closedPromiseResolve=e)}cancel(e){return VE(this,void 0,void 0,function*(){yield this.return(e)})}get closed(){return this._closedPromise}read(e){return VE(this,void 0,void 0,function*(){return(yield this.next(e,`read`)).value})}peek(e){return VE(this,void 0,void 0,function*(){return(yield this.next(e,`peek`)).value})}next(e){return VE(this,arguments,void 0,function*(e,t=`read`){return yield this.source.next({cmd:t,size:e})})}throw(e){return VE(this,void 0,void 0,function*(){let t=this.source.throw&&(yield this.source.throw(e))||bN;return this._closedPromiseResolve&&this._closedPromiseResolve(),this._closedPromiseResolve=void 0,Object.create(t)})}return(e){return VE(this,void 0,void 0,function*(){let t=this.source.return&&(yield this.source.return(e))||bN;return this._closedPromiseResolve&&this._closedPromiseResolve(),this._closedPromiseResolve=void 0,Object.create(t)})}},kN=class extends TN{constructor(e,t){super(),this.position=0,this.buffer=xD(e),this.size=t===void 0?this.buffer.byteLength:t}readInt32(e){let{buffer:t,byteOffset:n}=this.readAt(e,4);return new DataView(t,n).getInt32(0,!0)}seek(e){return this.position=Math.min(e,this.size),e<this.size}read(e){let{buffer:t,size:n,position:r}=this;return t&&r<n?(typeof e!=`number`&&(e=1/0),this.position=Math.min(n,r+Math.min(n-r,e)),t.subarray(r,this.position)):null}readAt(e,t){let n=this.buffer,r=Math.min(this.size,e+t);return n?n.subarray(e,r):new Uint8Array(t)}close(){this.buffer&&=null}throw(e){return this.close(),{done:!0,value:e}}return(e){return this.close(),{done:!0,value:e}}},AN=class extends EN{constructor(e,t){super(),this.position=0,this._handle=e,typeof t==`number`?this.size=t:this._pending=VE(this,void 0,void 0,function*(){this.size=(yield e.stat()).size,delete this._pending})}readInt32(e){return VE(this,void 0,void 0,function*(){let{buffer:t,byteOffset:n}=yield this.readAt(e,4);return new DataView(t,n).getInt32(0,!0)})}seek(e){return VE(this,void 0,void 0,function*(){return this._pending&&(yield this._pending),this.position=Math.min(e,this.size),e<this.size})}read(e){return VE(this,void 0,void 0,function*(){this._pending&&(yield this._pending);let{_handle:t,size:n,position:r}=this;if(t&&r<n){typeof e!=`number`&&(e=1/0);let i=r,a=0,o=0,s=Math.min(n,i+Math.min(n-i,e)),c=new Uint8Array(Math.max(0,(this.position=s)-i));for(;(i+=o)<s&&(a+=o)<c.byteLength;)({bytesRead:o}=yield t.read(c,a,c.byteLength-a,i));return c}return null})}readAt(e,t){return VE(this,void 0,void 0,function*(){this._pending&&(yield this._pending);let{_handle:n,size:r}=this;if(n&&e+t<r){let i=Math.min(r,e+t),a=new Uint8Array(i-e);return(yield n.read(a,0,t,e)).buffer}return new Uint8Array(t)})}close(){return VE(this,void 0,void 0,function*(){let e=this._handle;this._handle=null,e&&(yield e.close())})}throw(e){return VE(this,void 0,void 0,function*(){return yield this.close(),{done:!0,value:e}})}return(e){return VE(this,void 0,void 0,function*(){return yield this.close(),{done:!0,value:e}})}},jN=65536;function MN(e){return e<0&&(e=4294967295+e+1),`0x${e.toString(16)}`}var NN=8,PN=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8],FN=class{constructor(e){this.buffer=e}high(){return this.buffer[1]}low(){return this.buffer[0]}_times(e){let t=new Uint32Array([this.buffer[1]>>>16,this.buffer[1]&65535,this.buffer[0]>>>16,this.buffer[0]&65535]),n=new Uint32Array([e.buffer[1]>>>16,e.buffer[1]&65535,e.buffer[0]>>>16,e.buffer[0]&65535]),r=t[3]*n[3];this.buffer[0]=r&65535;let i=r>>>16;return r=t[2]*n[3],i+=r,r=t[3]*n[2]>>>0,i+=r,this.buffer[0]+=i<<16,this.buffer[1]=i>>>0<r?jN:0,this.buffer[1]+=i>>>16,this.buffer[1]+=t[1]*n[3]+t[2]*n[2]+t[3]*n[1],this.buffer[1]+=t[0]*n[3]+t[1]*n[2]+t[2]*n[1]+t[3]*n[0]<<16,this}_plus(e){let t=this.buffer[0]+e.buffer[0]>>>0;this.buffer[1]+=e.buffer[1],t<this.buffer[0]>>>0&&++this.buffer[1],this.buffer[0]=t}lessThan(e){return this.buffer[1]<e.buffer[1]||this.buffer[1]===e.buffer[1]&&this.buffer[0]<e.buffer[0]}equals(e){return this.buffer[1]===e.buffer[1]&&this.buffer[0]==e.buffer[0]}greaterThan(e){return e.lessThan(this)}hex(){return`${MN(this.buffer[1])} ${MN(this.buffer[0])}`}},IN=class e extends FN{times(e){return this._times(e),this}plus(e){return this._plus(e),this}static from(t,n=new Uint32Array(2)){return e.fromString(typeof t==`string`?t:t.toString(),n)}static fromNumber(t,n=new Uint32Array(2)){return e.fromString(t.toString(),n)}static fromString(t,n=new Uint32Array(2)){let r=t.length,i=new e(n);for(let n=0;n<r;){let a=NN<r-n?NN:r-n,o=new e(new Uint32Array([Number.parseInt(t.slice(n,n+a),10),0])),s=new e(new Uint32Array([PN[a],0]));i.times(s),i.plus(o),n+=a}return i}static convertArray(t){let n=new Uint32Array(t.length*2);for(let r=-1,i=t.length;++r<i;)e.from(t[r],new Uint32Array(n.buffer,n.byteOffset+2*r*4,2));return n}static multiply(t,n){return new e(new Uint32Array(t.buffer)).times(n)}static add(t,n){return new e(new Uint32Array(t.buffer)).plus(n)}},LN=class e extends FN{negate(){return this.buffer[0]=~this.buffer[0]+1,this.buffer[1]=~this.buffer[1],this.buffer[0]==0&&++this.buffer[1],this}times(e){return this._times(e),this}plus(e){return this._plus(e),this}lessThan(e){let t=this.buffer[1]<<0,n=e.buffer[1]<<0;return t<n||t===n&&this.buffer[0]<e.buffer[0]}static from(t,n=new Uint32Array(2)){return e.fromString(typeof t==`string`?t:t.toString(),n)}static fromNumber(t,n=new Uint32Array(2)){return e.fromString(t.toString(),n)}static fromString(t,n=new Uint32Array(2)){let r=t.startsWith(`-`),i=t.length,a=new e(n);for(let n=+!!r;n<i;){let r=NN<i-n?NN:i-n,o=new e(new Uint32Array([Number.parseInt(t.slice(n,n+r),10),0])),s=new e(new Uint32Array([PN[r],0]));a.times(s),a.plus(o),n+=r}return r?a.negate():a}static convertArray(t){let n=new Uint32Array(t.length*2);for(let r=-1,i=t.length;++r<i;)e.from(t[r],new Uint32Array(n.buffer,n.byteOffset+2*r*4,2));return n}static multiply(t,n){return new e(new Uint32Array(t.buffer)).times(n)}static add(t,n){return new e(new Uint32Array(t.buffer)).plus(n)}},RN=class e{constructor(e){this.buffer=e}high(){return new LN(new Uint32Array(this.buffer.buffer,this.buffer.byteOffset+8,2))}low(){return new LN(new Uint32Array(this.buffer.buffer,this.buffer.byteOffset,2))}negate(){return this.buffer[0]=~this.buffer[0]+1,this.buffer[1]=~this.buffer[1],this.buffer[2]=~this.buffer[2],this.buffer[3]=~this.buffer[3],this.buffer[0]==0&&++this.buffer[1],this.buffer[1]==0&&++this.buffer[2],this.buffer[2]==0&&++this.buffer[3],this}times(e){let t=new IN(new Uint32Array([this.buffer[3],0])),n=new IN(new Uint32Array([this.buffer[2],0])),r=new IN(new Uint32Array([this.buffer[1],0])),i=new IN(new Uint32Array([this.buffer[0],0])),a=new IN(new Uint32Array([e.buffer[3],0])),o=new IN(new Uint32Array([e.buffer[2],0])),s=new IN(new Uint32Array([e.buffer[1],0])),c=new IN(new Uint32Array([e.buffer[0],0])),l=IN.multiply(i,c);this.buffer[0]=l.low();let u=new IN(new Uint32Array([l.high(),0]));return l=IN.multiply(r,c),u.plus(l),l=IN.multiply(i,s),u.plus(l),this.buffer[1]=u.low(),this.buffer[3]=+!!u.lessThan(l),this.buffer[2]=u.high(),new IN(new Uint32Array(this.buffer.buffer,this.buffer.byteOffset+8,2)).plus(IN.multiply(n,c)).plus(IN.multiply(r,s)).plus(IN.multiply(i,o)),this.buffer[3]+=IN.multiply(t,c).plus(IN.multiply(n,s)).plus(IN.multiply(r,o)).plus(IN.multiply(i,a)).low(),this}plus(e){let t=new Uint32Array(4);return t[3]=this.buffer[3]+e.buffer[3]>>>0,t[2]=this.buffer[2]+e.buffer[2]>>>0,t[1]=this.buffer[1]+e.buffer[1]>>>0,t[0]=this.buffer[0]+e.buffer[0]>>>0,t[0]<this.buffer[0]>>>0&&++t[1],t[1]<this.buffer[1]>>>0&&++t[2],t[2]<this.buffer[2]>>>0&&++t[3],this.buffer[3]=t[3],this.buffer[2]=t[2],this.buffer[1]=t[1],this.buffer[0]=t[0],this}hex(){return`${MN(this.buffer[3])} ${MN(this.buffer[2])} ${MN(this.buffer[1])} ${MN(this.buffer[0])}`}static multiply(t,n){return new e(new Uint32Array(t.buffer)).times(n)}static add(t,n){return new e(new Uint32Array(t.buffer)).plus(n)}static from(t,n=new Uint32Array(4)){return e.fromString(typeof t==`string`?t:t.toString(),n)}static fromNumber(t,n=new Uint32Array(4)){return e.fromString(t.toString(),n)}static fromString(t,n=new Uint32Array(4)){let r=t.startsWith(`-`),i=t.length,a=new e(n);for(let n=+!!r;n<i;){let r=NN<i-n?NN:i-n,o=new e(new Uint32Array([Number.parseInt(t.slice(n,n+r),10),0,0,0])),s=new e(new Uint32Array([PN[r],0,0,0]));a.times(s),a.plus(o),n+=r}return r?a.negate():a}static convertArray(t){let n=new Uint32Array(t.length*4);for(let r=-1,i=t.length;++r<i;)e.from(t[r],new Uint32Array(n.buffer,n.byteOffset+16*r,4));return n}},zN=class extends Zk{constructor(e,t,n,r,i=LD.V5){super(),this.nodesIndex=-1,this.buffersIndex=-1,this.bytes=e,this.nodes=t,this.buffers=n,this.dictionaries=r,this.metadataVersion=i}visit(e){return super.visit(e instanceof fN?e.type:e)}visitNull(e,{length:t}=this.nextFieldNode()){return wM({type:e,length:t})}visitBool(e,{length:t,nullCount:n}=this.nextFieldNode()){return wM({type:e,length:t,nullCount:n,nullBitmap:this.readNullBitmap(e,n),data:this.readData(e)})}visitInt(e,{length:t,nullCount:n}=this.nextFieldNode()){return wM({type:e,length:t,nullCount:n,nullBitmap:this.readNullBitmap(e,n),data:this.readData(e)})}visitFloat(e,{length:t,nullCount:n}=this.nextFieldNode()){return wM({type:e,length:t,nullCount:n,nullBitmap:this.readNullBitmap(e,n),data:this.readData(e)})}visitUtf8(e,{length:t,nullCount:n}=this.nextFieldNode()){return wM({type:e,length:t,nullCount:n,nullBitmap:this.readNullBitmap(e,n),valueOffsets:this.readOffsets(e),data:this.readData(e)})}visitLargeUtf8(e,{length:t,nullCount:n}=this.nextFieldNode()){return wM({type:e,length:t,nullCount:n,nullBitmap:this.readNullBitmap(e,n),valueOffsets:this.readOffsets(e),data:this.readData(e)})}visitBinary(e,{length:t,nullCount:n}=this.nextFieldNode()){return wM({type:e,length:t,nullCount:n,nullBitmap:this.readNullBitmap(e,n),valueOffsets:this.readOffsets(e),data:this.readData(e)})}visitLargeBinary(e,{length:t,nullCount:n}=this.nextFieldNode()){return wM({type:e,length:t,nullCount:n,nullBitmap:this.readNullBitmap(e,n),valueOffsets:this.readOffsets(e),data:this.readData(e)})}visitFixedSizeBinary(e,{length:t,nullCount:n}=this.nextFieldNode()){return wM({type:e,length:t,nullCount:n,nullBitmap:this.readNullBitmap(e,n),data:this.readData(e)})}visitDate(e,{length:t,nullCount:n}=this.nextFieldNode()){return wM({type:e,length:t,nullCount:n,nullBitmap:this.readNullBitmap(e,n),data:this.readData(e)})}visitTimestamp(e,{length:t,nullCount:n}=this.nextFieldNode()){return wM({type:e,length:t,nullCount:n,nullBitmap:this.readNullBitmap(e,n),data:this.readData(e)})}visitTime(e,{length:t,nullCount:n}=this.nextFieldNode()){return wM({type:e,length:t,nullCount:n,nullBitmap:this.readNullBitmap(e,n),data:this.readData(e)})}visitDecimal(e,{length:t,nullCount:n}=this.nextFieldNode()){return wM({type:e,length:t,nullCount:n,nullBitmap:this.readNullBitmap(e,n),data:this.readData(e)})}visitList(e,{length:t,nullCount:n}=this.nextFieldNode()){return wM({type:e,length:t,nullCount:n,nullBitmap:this.readNullBitmap(e,n),valueOffsets:this.readOffsets(e),child:this.visit(e.children[0])})}visitStruct(e,{length:t,nullCount:n}=this.nextFieldNode()){return wM({type:e,length:t,nullCount:n,nullBitmap:this.readNullBitmap(e,n),children:this.visitMany(e.children)})}visitUnion(e,{length:t,nullCount:n}=this.nextFieldNode()){return this.metadataVersion<LD.V5&&this.readNullBitmap(e,n),e.mode===RD.Sparse?this.visitSparseUnion(e,{length:t,nullCount:n}):this.visitDenseUnion(e,{length:t,nullCount:n})}visitDenseUnion(e,{length:t,nullCount:n}=this.nextFieldNode()){return wM({type:e,length:t,nullCount:n,typeIds:this.readTypeIds(e),valueOffsets:this.readOffsets(e),children:this.visitMany(e.children)})}visitSparseUnion(e,{length:t,nullCount:n}=this.nextFieldNode()){return wM({type:e,length:t,nullCount:n,typeIds:this.readTypeIds(e),children:this.visitMany(e.children)})}visitDictionary(e,{length:t,nullCount:n}=this.nextFieldNode()){return wM({type:e,length:t,nullCount:n,nullBitmap:this.readNullBitmap(e,n),data:this.readData(e.indices),dictionary:this.readDictionary(e)})}visitInterval(e,{length:t,nullCount:n}=this.nextFieldNode()){return wM({type:e,length:t,nullCount:n,nullBitmap:this.readNullBitmap(e,n),data:this.readData(e)})}visitDuration(e,{length:t,nullCount:n}=this.nextFieldNode()){return wM({type:e,length:t,nullCount:n,nullBitmap:this.readNullBitmap(e,n),data:this.readData(e)})}visitFixedSizeList(e,{length:t,nullCount:n}=this.nextFieldNode()){return wM({type:e,length:t,nullCount:n,nullBitmap:this.readNullBitmap(e,n),child:this.visit(e.children[0])})}visitMap(e,{length:t,nullCount:n}=this.nextFieldNode()){return wM({type:e,length:t,nullCount:n,nullBitmap:this.readNullBitmap(e,n),valueOffsets:this.readOffsets(e),child:this.visit(e.children[0])})}nextFieldNode(){return this.nodes[++this.nodesIndex]}nextBufferRange(){return this.buffers[++this.buffersIndex]}readNullBitmap(e,t,n=this.nextBufferRange()){return t>0&&this.readData(e,n)||new Uint8Array}readOffsets(e,t){return this.readData(e,t)}readTypeIds(e,t){return this.readData(e,t)}readData(e,{length:t,offset:n}=this.nextBufferRange()){return this.bytes.subarray(n,n+t)}readDictionary(e){return this.dictionaries.get(e.id)}},BN=class extends zN{constructor(e,t,n,r,i){super(new Uint8Array,t,n,r,i),this.sources=e}readNullBitmap(e,t,{offset:n}=this.nextBufferRange()){return t<=0?new Uint8Array:_M(this.sources[n])}readOffsets(e,{offset:t}=this.nextBufferRange()){return vD(Uint8Array,vD(e.OffsetArrayType,this.sources[t]))}readTypeIds(e,{offset:t}=this.nextBufferRange()){return vD(Uint8Array,vD(e.ArrayType,this.sources[t]))}readData(e,{offset:t}=this.nextBufferRange()){let{sources:n}=this;return hk.isTimestamp(e)||(hk.isInt(e)||hk.isTime(e))&&e.bitWidth===64||hk.isDuration(e)||hk.isDate(e)&&e.unit===BD.MILLISECOND?vD(Uint8Array,LN.convertArray(n[t])):hk.isDecimal(e)?vD(Uint8Array,RN.convertArray(n[t])):hk.isBinary(e)||hk.isLargeBinary(e)||hk.isFixedSizeBinary(e)?VN(n[t]):hk.isBool(e)?_M(n[t]):hk.isUtf8(e)||hk.isLargeUtf8(e)?XE(n[t].join(``)):vD(Uint8Array,vD(e.ArrayType,n[t].map(e=>+e)))}};function VN(e){let t=e.join(``),n=new Uint8Array(t.length/2);for(let e=0;e<t.length;e+=2)n[e>>1]=Number.parseInt(t.slice(e,e+2),16);return n}var HN=class extends cN{constructor(e){super(e),this._values=new nN(Uint8Array)}get byteLength(){let e=this._pendingLength+this.length*4;return this._offsets&&(e+=this._offsets.byteLength),this._values&&(e+=this._values.byteLength),this._nulls&&(e+=this._nulls.byteLength),e}setValue(e,t){return super.setValue(e,xD(t))}_flushPending(e,t){let n=this._offsets,r=this._values.reserve(t).buffer,i=0;for(let[t,a]of e)if(a===void 0)n.set(t,0);else{let e=a.length;r.set(a,i),n.set(t,e),i+=e}}},UN=class extends cN{constructor(e){super(e),this._values=new nN(Uint8Array)}get byteLength(){let e=this._pendingLength+this.length*4;return this._offsets&&(e+=this._offsets.byteLength),this._values&&(e+=this._values.byteLength),this._nulls&&(e+=this._nulls.byteLength),e}setValue(e,t){return super.setValue(e,xD(t))}_flushPending(e,t){let n=this._offsets,r=this._values.reserve(t).buffer,i=0;for(let[t,a]of e)if(a===void 0)n.set(t,BigInt(0));else{let e=a.length;r.set(a,i),n.set(t,BigInt(e)),i+=e}}},WN=class extends oN{constructor(e){super(e),this._values=new iN}setValue(e,t){this._values.set(e,+t)}},GN=class extends sN{};GN.prototype._setValue=yA;var KN=class extends GN{};KN.prototype._setValue=mA;var qN=class extends GN{};qN.prototype._setValue=hA;var JN=class extends sN{};JN.prototype._setValue=AA;var YN=class extends oN{constructor({type:e,nullValues:t,dictionaryHashFunction:n}){super({type:new Yk(e.dictionary,e.indices,e.id,e.isOrdered)}),this._nulls=null,this._dictionaryOffset=0,this._keysToIndices=Object.create(null),this.indices=aF({type:this.type.indices,nullValues:t}),this.dictionary=aF({type:this.type.dictionary,nullValues:null}),typeof n==`function`&&(this.valueToKey=n)}get values(){return this.indices.values}get nullCount(){return this.indices.nullCount}get nullBitmap(){return this.indices.nullBitmap}get byteLength(){return this.indices.byteLength+this.dictionary.byteLength}get reservedLength(){return this.indices.reservedLength+this.dictionary.reservedLength}get reservedByteLength(){return this.indices.reservedByteLength+this.dictionary.reservedByteLength}isValid(e){return this.indices.isValid(e)}setValid(e,t){let n=this.indices;return t=n.setValid(e,t),this.length=n.length,t}setValue(e,t){let n=this._keysToIndices,r=this.valueToKey(t),i=n[r];return i===void 0&&(n[r]=i=this._dictionaryOffset+this.dictionary.append(t).length-1),this.indices.setValue(e,i)}flush(){let e=this.type,t=this._dictionary,n=this.dictionary.toVector(),r=this.indices.flush().clone(e);return r.dictionary=t?t.concat(n):n,this.finished||(this._dictionaryOffset+=n.length),this._dictionary=r.dictionary,this.clear(),r}finish(){return this.indices.finish(),this.dictionary.finish(),this._dictionaryOffset=0,this._keysToIndices=Object.create(null),super.finish()}clear(){return this.indices.clear(),this.dictionary.clear(),super.clear()}valueToKey(e){return typeof e==`string`?e:`${e}`}},XN=class extends sN{};XN.prototype._setValue=gA;var ZN=class extends oN{setValue(e,t){let[n]=this.children,r=e*this.stride;for(let e=-1,i=t.length;++e<i;)n.set(r+e,t[e])}addChild(e,t=`0`){if(this.numChildren>0)throw Error(`FixedSizeListBuilder can only have one child.`);let n=this.children.push(e);return this.type=new Kk(this.type.listSize,new fN(t,e.type,!0)),n}},QN=class extends sN{setValue(e,t){this._values.set(e,t)}},$N=class extends QN{setValue(e,t){super.setValue(e,iA(t))}},eP=class extends QN{},tP=class extends QN{},nP=class extends sN{};nP.prototype._setValue=HA;var rP=class extends nP{};rP.prototype._setValue=UA;var iP=class extends nP{};iP.prototype._setValue=WA;var aP=class extends sN{};aP.prototype._setValue=YA;var oP=class extends aP{};oP.prototype._setValue=GA;var sP=class extends aP{};sP.prototype._setValue=KA;var cP=class extends aP{};cP.prototype._setValue=qA;var lP=class extends aP{};lP.prototype._setValue=JA;var uP=class extends sN{setValue(e,t){this._values.set(e,t)}},dP=class extends uP{},fP=class extends uP{},pP=class extends uP{},mP=class extends uP{},hP=class extends uP{},gP=class extends uP{},_P=class extends uP{},vP=class extends uP{},yP=class extends cN{constructor(e){super(e),this._offsets=new aN(e.type)}addChild(e,t=`0`){if(this.numChildren>0)throw Error(`ListBuilder can only have one child.`);return this.children[this.numChildren]=e,this.type=new Hk(new fN(t,e.type,!0)),this.numChildren-1}_flushPending(e){let t=this._offsets,[n]=this.children;for(let[r,i]of e)if(i===void 0)t.set(r,0);else{let e=i,a=e.length,o=t.set(r,a).buffer[r];for(let t=-1;++t<a;)n.set(o+t,e[t])}}},bP=class extends cN{set(e,t){return super.set(e,t)}setValue(e,t){let n=t instanceof Map?t:new Map(Object.entries(t)),r=this._pending||=new Map,i=r.get(e);i&&(this._pendingLength-=i.size),this._pendingLength+=n.size,r.set(e,n)}addChild(e,t=`${this.numChildren}`){if(this.numChildren>0)throw Error(`ListBuilder can only have one child.`);return this.children[this.numChildren]=e,this.type=new qk(new fN(t,e.type,!0),this.type.keysSorted),this.numChildren-1}_flushPending(e){let t=this._offsets,[n]=this.children;for(let[r,i]of e)if(i===void 0)t.set(r,0);else{let{[r]:e,[r+1]:a}=t.set(r,i.size).buffer;for(let t of i.entries())if(n.set(e,t),++e>=a)break}}},xP=class extends oN{setValue(e,t){}setValid(e,t){return this.length=Math.max(e+1,this.length),t}},SP=class extends oN{setValue(e,t){let{children:n,type:r}=this;switch(Array.isArray(t)||t.constructor){case!0:return r.children.forEach((r,i)=>n[i].set(e,t[i]));case Map:return r.children.forEach((r,i)=>n[i].set(e,t.get(r.name)));default:return r.children.forEach((r,i)=>n[i].set(e,t[r.name]))}}setValid(e,t){return super.setValid(e,t)||this.children.forEach(n=>n.setValid(e,t)),t}addChild(e,t=`${this.numChildren}`){let n=this.children.push(e);return this.type=new Uk([...this.type.children,new fN(t,e.type,!0)]),n}},CP=class extends sN{};CP.prototype._setValue=wA;var wP=class extends CP{};wP.prototype._setValue=bA;var TP=class extends CP{};TP.prototype._setValue=xA;var EP=class extends CP{};EP.prototype._setValue=SA;var DP=class extends CP{};DP.prototype._setValue=CA;var OP=class extends sN{};OP.prototype._setValue=kA;var kP=class extends OP{};kP.prototype._setValue=TA;var AP=class extends OP{};AP.prototype._setValue=EA;var jP=class extends OP{};jP.prototype._setValue=DA;var MP=class extends OP{};MP.prototype._setValue=OA;var NP=class extends oN{constructor(e){super(e),this._typeIds=new rN(Int8Array,0,1),typeof e.valueToChildTypeId==`function`&&(this._valueToChildTypeId=e.valueToChildTypeId)}get typeIdToChildIndex(){return this.type.typeIdToChildIndex}append(e,t){return this.set(this.length,e,t)}set(e,t,n){return n===void 0&&(n=this._valueToChildTypeId(this,t,e)),this.setValue(e,t,n),this}setValue(e,t,n){this._typeIds.set(e,n);let r=this.type.typeIdToChildIndex[n];this.children[r]?.set(e,t)}addChild(e,t=`${this.children.length}`){let n=this.children.push(e),{type:{children:r,mode:i,typeIds:a}}=this,o=[...r,new fN(t,e.type)];return this.type=new Wk(i,[...a,n],o),n}_valueToChildTypeId(e,t,n){throw Error("Cannot map UnionBuilder value to child typeId. Pass the `childTypeId` as the second argument to unionBuilder.append(), or supply a `valueToChildTypeId` function as part of the UnionBuilder constructor options.")}},PP=class extends NP{},FP=class extends NP{constructor(e){super(e),this._offsets=new rN(Int32Array)}setValue(e,t,n){let r=this._typeIds.set(e,n).buffer[e],i=this.getChildAt(this.type.typeIdToChildIndex[r]),a=this._offsets.set(e,i.length).buffer[e];i?.set(a,t)}},IP=class extends cN{constructor(e){super(e),this._values=new nN(Uint8Array)}get byteLength(){let e=this._pendingLength+this.length*4;return this._offsets&&(e+=this._offsets.byteLength),this._values&&(e+=this._values.byteLength),this._nulls&&(e+=this._nulls.byteLength),e}setValue(e,t){return super.setValue(e,XE(t))}_flushPending(e,t){}};IP.prototype._flushPending=HN.prototype._flushPending;var LP=class extends cN{constructor(e){super(e),this._values=new nN(Uint8Array)}get byteLength(){let e=this._pendingLength+this.length*4;return this._offsets&&(e+=this._offsets.byteLength),this._values&&(e+=this._values.byteLength),this._nulls&&(e+=this._nulls.byteLength),e}setValue(e,t){return super.setValue(e,XE(t))}_flushPending(e,t){}};LP.prototype._flushPending=UN.prototype._flushPending;var RP=new class extends Zk{visitNull(){return xP}visitBool(){return WN}visitInt(){return uP}visitInt8(){return dP}visitInt16(){return fP}visitInt32(){return pP}visitInt64(){return mP}visitUint8(){return hP}visitUint16(){return gP}visitUint32(){return _P}visitUint64(){return vP}visitFloat(){return QN}visitFloat16(){return $N}visitFloat32(){return eP}visitFloat64(){return tP}visitUtf8(){return IP}visitLargeUtf8(){return LP}visitBinary(){return HN}visitLargeBinary(){return UN}visitFixedSizeBinary(){return XN}visitDate(){return GN}visitDateDay(){return KN}visitDateMillisecond(){return qN}visitTimestamp(){return CP}visitTimestampSecond(){return wP}visitTimestampMillisecond(){return TP}visitTimestampMicrosecond(){return EP}visitTimestampNanosecond(){return DP}visitTime(){return OP}visitTimeSecond(){return kP}visitTimeMillisecond(){return AP}visitTimeMicrosecond(){return jP}visitTimeNanosecond(){return MP}visitDecimal(){return JN}visitList(){return yP}visitStruct(){return SP}visitUnion(){return NP}visitDenseUnion(){return FP}visitSparseUnion(){return PP}visitDictionary(){return YN}visitInterval(){return nP}visitIntervalDayTime(){return rP}visitIntervalYearMonth(){return iP}visitDuration(){return aP}visitDurationSecond(){return oP}visitDurationMillisecond(){return sP}visitDurationMicrosecond(){return cP}visitDurationNanosecond(){return lP}visitFixedSizeList(){return ZN}visitMap(){return bP}},zP=class extends Zk{compareSchemas(e,t){return e===t||t instanceof e.constructor&&this.compareManyFields(e.fields,t.fields)}compareManyFields(e,t){return e===t||Array.isArray(e)&&Array.isArray(t)&&e.length===t.length&&e.every((e,n)=>this.compareFields(e,t[n]))}compareFields(e,t){return e===t||t instanceof e.constructor&&e.name===t.name&&e.nullable===t.nullable&&this.visit(e.type,t.type)}};function BP(e,t){return t instanceof e.constructor}function VP(e,t){return e===t||BP(e,t)}function HP(e,t){return e===t||BP(e,t)&&e.bitWidth===t.bitWidth&&e.isSigned===t.isSigned}function UP(e,t){return e===t||BP(e,t)&&e.precision===t.precision}function WP(e,t){return e===t||BP(e,t)&&e.byteWidth===t.byteWidth}function GP(e,t){return e===t||BP(e,t)&&e.unit===t.unit}function KP(e,t){return e===t||BP(e,t)&&e.unit===t.unit&&e.timezone===t.timezone}function qP(e,t){return e===t||BP(e,t)&&e.unit===t.unit&&e.bitWidth===t.bitWidth}function JP(e,t){return e===t||BP(e,t)&&e.children.length===t.children.length&&nF.compareManyFields(e.children,t.children)}function YP(e,t){return e===t||BP(e,t)&&e.children.length===t.children.length&&nF.compareManyFields(e.children,t.children)}function XP(e,t){return e===t||BP(e,t)&&e.mode===t.mode&&e.typeIds.every((e,n)=>e===t.typeIds[n])&&nF.compareManyFields(e.children,t.children)}function ZP(e,t){return e===t||BP(e,t)&&e.id===t.id&&e.isOrdered===t.isOrdered&&nF.visit(e.indices,t.indices)&&nF.visit(e.dictionary,t.dictionary)}function QP(e,t){return e===t||BP(e,t)&&e.unit===t.unit}function $P(e,t){return e===t||BP(e,t)&&e.unit===t.unit}function eF(e,t){return e===t||BP(e,t)&&e.listSize===t.listSize&&e.children.length===t.children.length&&nF.compareManyFields(e.children,t.children)}function tF(e,t){return e===t||BP(e,t)&&e.keysSorted===t.keysSorted&&e.children.length===t.children.length&&nF.compareManyFields(e.children,t.children)}zP.prototype.visitNull=VP,zP.prototype.visitBool=VP,zP.prototype.visitInt=HP,zP.prototype.visitInt8=HP,zP.prototype.visitInt16=HP,zP.prototype.visitInt32=HP,zP.prototype.visitInt64=HP,zP.prototype.visitUint8=HP,zP.prototype.visitUint16=HP,zP.prototype.visitUint32=HP,zP.prototype.visitUint64=HP,zP.prototype.visitFloat=UP,zP.prototype.visitFloat16=UP,zP.prototype.visitFloat32=UP,zP.prototype.visitFloat64=UP,zP.prototype.visitUtf8=VP,zP.prototype.visitLargeUtf8=VP,zP.prototype.visitBinary=VP,zP.prototype.visitLargeBinary=VP,zP.prototype.visitFixedSizeBinary=WP,zP.prototype.visitDate=GP,zP.prototype.visitDateDay=GP,zP.prototype.visitDateMillisecond=GP,zP.prototype.visitTimestamp=KP,zP.prototype.visitTimestampSecond=KP,zP.prototype.visitTimestampMillisecond=KP,zP.prototype.visitTimestampMicrosecond=KP,zP.prototype.visitTimestampNanosecond=KP,zP.prototype.visitTime=qP,zP.prototype.visitTimeSecond=qP,zP.prototype.visitTimeMillisecond=qP,zP.prototype.visitTimeMicrosecond=qP,zP.prototype.visitTimeNanosecond=qP,zP.prototype.visitDecimal=VP,zP.prototype.visitList=JP,zP.prototype.visitStruct=YP,zP.prototype.visitUnion=XP,zP.prototype.visitDenseUnion=XP,zP.prototype.visitSparseUnion=XP,zP.prototype.visitDictionary=ZP,zP.prototype.visitInterval=QP,zP.prototype.visitIntervalDayTime=QP,zP.prototype.visitIntervalYearMonth=QP,zP.prototype.visitDuration=$P,zP.prototype.visitDurationSecond=$P,zP.prototype.visitDurationMillisecond=$P,zP.prototype.visitDurationMicrosecond=$P,zP.prototype.visitDurationNanosecond=$P,zP.prototype.visitFixedSizeList=eF,zP.prototype.visitMap=tF;var nF=new zP;function rF(e,t){return nF.compareSchemas(e,t)}function iF(e,t){return nF.visit(e,t)}function aF(e){let t=e.type,n=new(RP.getVisitFn(t)())(e);if(t.children&&t.children.length>0){let r=e.children||[],i={nullValues:e.nullValues},a=Array.isArray(r)?((e,t)=>r[t]||i):(({name:e})=>r[e]||i);for(let[e,r]of t.children.entries()){let{type:t}=r,i=a(r,e);n.children.push(aF(Object.assign(Object.assign({},i),{type:t})))}}return n}function oF(e,t){if(e instanceof SM||e instanceof JM||e.type instanceof hk||ArrayBuffer.isView(e))return XM(e);let n=[...cF({type:t??sF(e),nullValues:[null]})(e)],r=n.length===1?n[0]:n.reduce((e,t)=>e.concat(t));return hk.isDictionary(r.type)?r.memoize():r}function sF(e){if(e.length===0)return new gk;let t=0,n=0,r=0,i=0,a=0,o=0,s=0,c=0;for(let l of e){if(l==null){++t;continue}switch(typeof l){case`bigint`:++o;continue;case`boolean`:++s;continue;case`number`:++i;continue;case`string`:++a;continue;case`object`:Array.isArray(l)?++n:Object.prototype.toString.call(l)===`[object Date]`?++c:++r;continue}throw TypeError(`Unable to infer Vector type from input values, explicit type declaration expected.`)}if(i+t===e.length)return new kk;if(a+t===e.length)return new Yk(new Mk,new bk);if(o+t===e.length)return new xk;if(s+t===e.length)return new Pk;if(c+t===e.length)return new zk;if(n+t===e.length){let t=e,n=sF(t[t.findIndex(e=>e!=null)]);if(t.every(e=>e==null||iF(n,sF(e))))return new Hk(new fN(``,n,!0))}else if(r+t===e.length){let t=new Map;for(let n of e)for(let e of Object.keys(n))!t.has(e)&&n[e]!=null&&t.set(e,new fN(e,sF([n[e]]),!0));return new Uk([...t.values()])}throw TypeError(`Unable to infer Vector type from input values, explicit type declaration expected.`)}function cF(e){let{queueingStrategy:t=`count`}=e,{highWaterMark:n=t===`bytes`?2**14:1/0}=e,r=t===`bytes`?`byteLength`:`length`;return function*(t){let i=0,a=aF(e);for(let e of t)a.append(e)[r]>=n&&++i&&(yield a.toVector());(a.finish().length>0||i===0)&&(yield a.toVector())}}function lF(e,t){return uF(e,t.map(e=>e.data.concat()))}function uF(e,t){let n=[...e.fields],r=[],i={numBatches:t.reduce((e,t)=>Math.max(e,t.length),0)},a=0,o=0,s=-1,c=t.length,l,u=[];for(;i.numBatches-- >0;){for(o=1/0,s=-1;++s<c;)u[s]=l=t[s].shift(),o=Math.min(o,l?l.length:o);Number.isFinite(o)&&(u=dF(n,o,u,t,i),o>0&&(r[a++]=wM({type:new Uk(n),length:o,nullCount:0,children:u.slice()})))}return[e=e.assign(n),r.map(t=>new gF(e,t))]}function dF(e,t,n,r,i){let a=(t+63&-64)>>3;for(let o=-1,s=r.length;++o<s;){let s=n[o],c=s?.length;if(c>=t)c===t?n[o]=s:(n[o]=s.slice(0,t),i.numBatches=Math.max(i.numBatches,r[o].unshift(s.slice(t,c-t))));else{let r=e[o];e[o]=r.clone({nullable:!0}),n[o]=s?._changeLengthAndBackfillNullBitmap(t)??wM({type:r.type,length:t,nullCount:t,nullBitmap:new Uint8Array(a)})}}return n}var fF,pF=class e{constructor(...t){if(t.length===0)return this.batches=[],this.schema=new dN([]),this._offsets=[0],this;let n,r;t[0]instanceof dN&&(n=t.shift()),t.at(-1)instanceof Uint32Array&&(r=t.pop());let i=t=>{if(t){if(t instanceof gF)return[t];if(t instanceof e)return t.batches;if(t instanceof SM){if(t.type instanceof Uk)return[new gF(new dN(t.type.children),t)]}else if(Array.isArray(t))return t.flatMap(e=>i(e));else if(typeof t[Symbol.iterator]==`function`)return[...t].flatMap(e=>i(e));else if(typeof t==`object`){let e=Object.keys(t),r=e.map(e=>new JM([t[e]])),[,i]=lF(n??new dN(e.map((e,t)=>new fN(String(e),r[t].type,r[t].nullable))),r);return i.length===0?[new gF(t)]:i}}return[]},a=t.flatMap(e=>i(e));if(n=n??a[0]?.schema??new dN([]),!(n instanceof dN))throw TypeError(`Table constructor expects a [Schema, RecordBatch[]] pair.`);for(let e of a){if(!(e instanceof gF))throw TypeError(`Table constructor expects a [Schema, RecordBatch[]] pair.`);if(!rF(n,e.schema))throw TypeError(`Table and inner RecordBatch schemas must be equivalent.`)}this.schema=n,this.batches=a,this._offsets=r??OM(this.data)}get data(){return this.batches.map(({data:e})=>e)}get numCols(){return this.schema.fields.length}get numRows(){return this.data.reduce((e,t)=>e+t.length,0)}get nullCount(){return this._nullCount===-1&&(this._nullCount=DM(this.data)),this._nullCount}isValid(e){return!1}get(e){return null}at(e){return this.get(rM(e,this.numRows))}set(e,t){}indexOf(e,t){return-1}[Symbol.iterator](){return this.batches.length>0?WM.visit(new JM(this.data)):[][Symbol.iterator]()}toArray(){return[...this]}toString(){return`[\n ${this.toArray().join(`,
|
|
69
69
|
`)}\n]`}concat(...t){let n=this.schema;return new e(n,this.data.concat(t.flatMap(({data:e})=>e)).map(e=>new gF(n,e)))}slice(t,n){let r=this.schema;return[t,n]=nM({length:this.numRows},t,n),new e(r,kM(this.data,this._offsets,t,n).map(e=>new gF(r,e)))}getChild(e){return this.getChildAt(this.schema.fields.findIndex(t=>t.name===e))}getChildAt(e){if(e>-1&&e<this.schema.fields.length){let t=this.data.map(t=>t.children[e]);if(t.length===0){let{type:n}=this.schema.fields[e],r=wM({type:n,length:0,nullCount:0});t.push(r._changeLengthAndBackfillNullBitmap(this.numRows))}return new JM(t)}return null}setChild(e,t){return this.setChildAt(this.schema.fields?.findIndex(t=>t.name===e),t)}setChildAt(t,n){let r=this.schema,i=[...this.batches];if(t>-1&&t<this.numCols){n||=new JM([wM({type:new gk,length:this.numRows})]);let e=r.fields.slice(),a=e[t].clone({type:n.type}),o=this.schema.fields.map((e,t)=>this.getChildAt(t));[e[t],o[t]]=[a,n],[r,i]=lF(r,o)}return new e(r,i)}select(e){let t=this.schema.fields.reduce((e,t,n)=>e.set(t.name,n),new Map);return this.selectAt(e.map(e=>t.get(e)).filter(e=>e>-1))}selectAt(t){return new e(this.schema.selectAt(t),this.batches.map(e=>e.selectAt(t)))}assign(t){let n=this.schema.fields,[r,i]=t.schema.fields.reduce((e,t,r)=>{let[i,a]=e,o=n.findIndex(e=>e.name===t.name);return~o?a[o]=r:i.push(r),e},[[],[]]);return new e(...lF(this.schema.assign(t.schema),[...n.map((e,t)=>[t,i[t]]).map(([e,n])=>n===void 0?this.getChildAt(e):t.getChildAt(n)),...r.map(e=>t.getChildAt(e))].filter(Boolean)))}};fF=Symbol.toStringTag,pF[fF]=(e=>(e.schema=null,e.batches=[],e._offsets=new Uint32Array([0]),e._nullCount=-1,e[Symbol.isConcatSpreadable]=!0,e.isValid=MM(jM),e.get=MM(qj.getVisitFn(Z.Struct)),e.set=NM(ZA.getVisitFn(Z.Struct)),e.indexOf=PM(BM.getVisitFn(Z.Struct)),`Table`))(pF.prototype);function mF(e){let t={},n=Object.entries(e);for(let[e,r]of n)t[e]=oF(r);return new pF(t)}var hF,gF=class e{constructor(...e){switch(e.length){case 2:if([this.schema]=e,!(this.schema instanceof dN)||([,this.data=wM({nullCount:0,type:new Uk(this.schema.fields),children:this.schema.fields.map(e=>wM({type:e.type,nullCount:0}))})]=e,!(this.data instanceof SM)))throw TypeError(`RecordBatch constructor expects a [Schema, Data] pair.`);[this.schema,this.data]=_F(this.schema,this.data.children);break;case 1:{let[t]=e,{fields:n,children:r,length:i}=Object.keys(t).reduce((e,n,r)=>(e.children[r]=t[n],e.length=Math.max(e.length,t[n].length),e.fields[r]=fN.new({name:n,type:t[n].type,nullable:!0}),e),{length:0,fields:[],children:[]}),a=new dN(n),o=wM({type:new Uk(n),length:i,children:r,nullCount:0});[this.schema,this.data]=_F(a,o.children,i);break}default:throw TypeError(`RecordBatch constructor expects an Object mapping names to child Data, or a [Schema, Data] pair.`)}}get dictionaries(){return this._dictionaries||=vF(this.schema.fields,this.data.children)}get numCols(){return this.schema.fields.length}get numRows(){return this.data.length}get nullCount(){return this.data.nullCount}isValid(e){return this.data.getValid(e)}get(e){return qj.visit(this.data,e)}at(e){return this.get(rM(e,this.numRows))}set(e,t){return ZA.visit(this.data,e,t)}indexOf(e,t){return BM.visit(this.data,e,t)}[Symbol.iterator](){return WM.visit(new JM([this.data]))}toArray(){return[...this]}concat(...e){return new pF(this.schema,[this,...e])}slice(t,n){let[r]=new JM([this.data]).slice(t,n).data;return new e(this.schema,r)}getChild(e){return this.getChildAt(this.schema.fields?.findIndex(t=>t.name===e))}getChildAt(e){return e>-1&&e<this.schema.fields.length?new JM([this.data.children[e]]):null}setChild(e,t){return this.setChildAt(this.schema.fields?.findIndex(t=>t.name===e),t)}setChildAt(t,n){let r=this.schema,i=this.data;if(t>-1&&t<this.numCols){n||=new JM([wM({type:new gk,length:this.numRows})]);let e=r.fields.slice(),a=i.children.slice(),o=e[t].clone({type:n.type});[e[t],a[t]]=[o,n.data[0]],r=new dN(e,new Map(this.schema.metadata)),i=wM({type:new Uk(e),children:a})}return new e(r,i)}select(t){let n=this.schema.select(t),r=new Uk(n.fields),i=[];for(let e of t){let t=this.schema.fields.findIndex(t=>t.name===e);~t&&(i[t]=this.data.children[t])}return new e(n,wM({type:r,length:this.numRows,children:i}))}selectAt(t){let n=this.schema.selectAt(t),r=t.map(e=>this.data.children[e]).filter(Boolean);return new e(n,wM({type:new Uk(n.fields),length:this.numRows,children:r}))}};hF=Symbol.toStringTag,gF[hF]=(e=>(e._nullCount=-1,e[Symbol.isConcatSpreadable]=!0,`RecordBatch`))(gF.prototype);function _F(e,t,n=t.reduce((e,t)=>Math.max(e,t.length),0)){let r=[...e.fields],i=[...t],a=(n+63&-64)>>3;for(let[o,s]of e.fields.entries()){let e=t[o];(!e||e.length!==n)&&(r[o]=s.clone({nullable:!0}),i[o]=e?._changeLengthAndBackfillNullBitmap(n)??wM({type:s.type,length:n,nullCount:n,nullBitmap:new Uint8Array(a)}))}return[e.assign(r),wM({type:new Uk(r),length:n,children:i})]}function vF(e,t,n=new Map){if((e?.length??0)>0&&e?.length===t?.length)for(let r=-1,i=e.length;++r<i;){let{type:i}=e[r],a=t[r];for(let e of[a,...a?.dictionary?.data||[]])vF(i.children,e?.children,n);if(hk.isDictionary(i)){let{id:e}=i;if(!n.has(e))a?.dictionary&&n.set(e,a.dictionary);else if(n.get(e)!==a.dictionary)throw Error(`Cannot create Schema containing two different dictionaries with the same Id`)}}return n}var yF=class extends gF{constructor(e){let t=e.fields.map(e=>wM({type:e.type})),n=wM({type:new Uk(e.fields),nullCount:0,children:t});super(e,n)}},bF=class e{constructor(){this.bb=null,this.bb_pos=0}__init(e,t){return this.bb_pos=e,this.bb=t,this}static getRootAsMessage(t,n){return(n||new e).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsMessage(t,n){return t.setPosition(t.position()+4),(n||new e).__init(t.readInt32(t.position())+t.position(),t)}version(){let e=this.bb.__offset(this.bb_pos,4);return e?this.bb.readInt16(this.bb_pos+e):LD.V1}headerType(){let e=this.bb.__offset(this.bb_pos,6);return e?this.bb.readUint8(this.bb_pos+e):AO.NONE}header(e){let t=this.bb.__offset(this.bb_pos,8);return t?this.bb.__union(e,this.bb_pos+t):null}bodyLength(){let e=this.bb.__offset(this.bb_pos,10);return e?this.bb.readInt64(this.bb_pos+e):BigInt(`0`)}customMetadata(e,t){let n=this.bb.__offset(this.bb_pos,12);return n?(t||new sO).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+n)+e*4),this.bb):null}customMetadataLength(){let e=this.bb.__offset(this.bb_pos,12);return e?this.bb.__vector_len(this.bb_pos+e):0}static startMessage(e){e.startObject(5)}static addVersion(e,t){e.addFieldInt16(0,t,LD.V1)}static addHeaderType(e,t){e.addFieldInt8(1,t,AO.NONE)}static addHeader(e,t){e.addFieldOffset(2,t,0)}static addBodyLength(e,t){e.addFieldInt64(3,t,BigInt(`0`))}static addCustomMetadata(e,t){e.addFieldOffset(4,t,0)}static createCustomMetadataVector(e,t){e.startVector(4,t.length,4);for(let n=t.length-1;n>=0;n--)e.addOffset(t[n]);return e.endVector()}static startCustomMetadataVector(e,t){e.startVector(4,t,4)}static endMessage(e){return e.endObject()}static finishMessageBuffer(e,t){e.finish(t)}static finishSizePrefixedMessageBuffer(e,t){e.finish(t,void 0,!0)}static createMessage(t,n,r,i,a,o){return e.startMessage(t),e.addVersion(t,n),e.addHeaderType(t,r),e.addHeader(t,i),e.addBodyLength(t,a),e.addCustomMetadata(t,o),e.endMessage(t)}},xF=new class extends Zk{visit(e,t){return e==null||t==null?void 0:super.visit(e,t)}visitNull(e,t){return xO.startNull(t),xO.endNull(t)}visitInt(e,t){return aO.startInt(t),aO.addBitWidth(t,e.bitWidth),aO.addIsSigned(t,e.isSigned),aO.endInt(t)}visitFloat(e,t){return hO.startFloatingPoint(t),hO.addPrecision(t,e.precision),hO.endFloatingPoint(t)}visitBinary(e,t){return cO.startBinary(t),cO.endBinary(t)}visitLargeBinary(e,t){return _O.startLargeBinary(t),_O.endLargeBinary(t)}visitBool(e,t){return lO.startBool(t),lO.endBool(t)}visitUtf8(e,t){return EO.startUtf8(t),EO.endUtf8(t)}visitLargeUtf8(e,t){return vO.startLargeUtf8(t),vO.endLargeUtf8(t)}visitDecimal(e,t){return dO.startDecimal(t),dO.addScale(t,e.scale),dO.addPrecision(t,e.precision),dO.addBitWidth(t,e.bitWidth),dO.endDecimal(t)}visitDate(e,t){return uO.startDate(t),uO.addUnit(t,e.unit),uO.endDate(t)}visitTime(e,t){return CO.startTime(t),CO.addUnit(t,e.unit),CO.addBitWidth(t,e.bitWidth),CO.endTime(t)}visitTimestamp(e,t){let n=e.timezone&&t.createString(e.timezone)||void 0;return wO.startTimestamp(t),wO.addUnit(t,e.unit),n!==void 0&&wO.addTimezone(t,n),wO.endTimestamp(t)}visitInterval(e,t){return gO.startInterval(t),gO.addUnit(t,e.unit),gO.endInterval(t)}visitDuration(e,t){return fO.startDuration(t),fO.addUnit(t,e.unit),fO.endDuration(t)}visitList(e,t){return yO.startList(t),yO.endList(t)}visitStruct(e,t){return SO.startStruct_(t),SO.endStruct_(t)}visitUnion(e,t){TO.startTypeIdsVector(t,e.typeIds.length);let n=TO.createTypeIdsVector(t,e.typeIds);return TO.startUnion(t),TO.addMode(t,e.mode),TO.addTypeIds(t,n),TO.endUnion(t)}visitDictionary(e,t){let n=this.visit(e.indices,t);return oO.startDictionaryEncoding(t),oO.addId(t,BigInt(e.id)),oO.addIsOrdered(t,e.isOrdered),n!==void 0&&oO.addIndexType(t,n),oO.endDictionaryEncoding(t)}visitFixedSizeBinary(e,t){return pO.startFixedSizeBinary(t),pO.addByteWidth(t,e.byteWidth),pO.endFixedSizeBinary(t)}visitFixedSizeList(e,t){return mO.startFixedSizeList(t),mO.addListSize(t,e.listSize),mO.endFixedSizeList(t)}visitMap(e,t){return bO.startMap(t),bO.addKeysSorted(t,e.keysSorted),bO.endMap(t)}};function SF(e,t=new Map){return new dN(TF(e,t),jF(e.metadata),t)}function CF(e){return new LF(e.count,DF(e.columns),OF(e.columns))}function wF(e){return new RF(CF(e.data),e.id,e.isDelta)}function TF(e,t){return(e.fields||[]).filter(Boolean).map(e=>fN.fromJSON(e,t))}function EF(e,t){return(e.children||[]).filter(Boolean).map(e=>fN.fromJSON(e,t))}function DF(e){return(e||[]).reduce((e,t)=>[...e,new BF(t.count,kF(t.VALIDITY)),...DF(t.children)],[])}function OF(e,t=[]){for(let n=-1,r=(e||[]).length;++n<r;){let r=e[n];r.VALIDITY&&t.push(new zF(t.length,r.VALIDITY.length)),r.TYPE_ID&&t.push(new zF(t.length,r.TYPE_ID.length)),r.OFFSET&&t.push(new zF(t.length,r.OFFSET.length)),r.DATA&&t.push(new zF(t.length,r.DATA.length)),t=OF(r.children,t)}return t}function kF(e){return(e||[]).reduce((e,t)=>e+ +(t===0),0)}function AF(e,t){let n,r,i,a,o,s;return!t||!(a=e.dictionary)?(o=NF(e,EF(e,t)),i=new fN(e.name,o,e.nullable,jF(e.metadata))):t.has(n=a.id)?(r=(r=a.indexType)?MF(r):new bk,s=new Yk(t.get(n),r,n,a.isOrdered),i=new fN(e.name,s,e.nullable,jF(e.metadata))):(r=(r=a.indexType)?MF(r):new bk,t.set(n,o=NF(e,EF(e,t))),s=new Yk(o,r,n,a.isOrdered),i=new fN(e.name,s,e.nullable,jF(e.metadata))),i||null}function jF(e=[]){return new Map(e.map(({key:e,value:t})=>[e,t]))}function MF(e){return new _k(e.isSigned,e.bitWidth)}function NF(e,t){let n=e.type.name;switch(n){case`NONE`:return new gk;case`null`:return new gk;case`binary`:return new Ak;case`largebinary`:return new jk;case`utf8`:return new Mk;case`largeutf8`:return new Nk;case`bool`:return new Pk;case`list`:return new Hk((t||[])[0]);case`struct`:return new Uk(t||[]);case`struct_`:return new Uk(t||[])}switch(n){case`int`:{let t=e.type;return new _k(t.isSigned,t.bitWidth)}case`floatingpoint`:{let t=e.type;return new Ek(zD[t.precision])}case`decimal`:{let t=e.type;return new Fk(t.scale,t.precision,t.bitWidth)}case`date`:{let t=e.type;return new Ik(BD[t.unit])}case`time`:{let t=e.type;return new Lk(VD[t.unit],t.bitWidth)}case`timestamp`:{let t=e.type;return new Rk(VD[t.unit],t.timezone)}case`interval`:{let t=e.type;return new Bk(HD[t.unit])}case`duration`:{let t=e.type;return new Vk(VD[t.unit])}case`union`:{let n=e.type,[r,...i]=(n.mode+``).toLowerCase();return new Wk(RD[r.toUpperCase()+i.join(``)],n.typeIds||[],t||[])}case`fixedsizebinary`:{let t=e.type;return new Gk(t.byteWidth)}case`fixedsizelist`:{let n=e.type;return new Kk(n.listSize,(t||[])[0])}case`map`:{let n=e.type;return new qk((t||[])[0],n.keysSorted)}}throw Error(`Unrecognized type: "${n}"`)}var PF=YD,FF=JD,IF=class e{static fromJSON(t,n){let r=new e(0,LD.V5,n);return r._createHeader=VF(t,n),r}static decode(t){t=new FF(xD(t));let n=bF.getRootAsMessage(t),r=n.bodyLength(),i=n.version(),a=n.headerType(),o=new e(r,i,a);return o._createHeader=HF(n,a),o}static encode(e){let t=new PF,n=-1;return e.isSchema()?n=dN.encode(t,e.header()):e.isRecordBatch()?n=LF.encode(t,e.header()):e.isDictionaryBatch()&&(n=RF.encode(t,e.header())),bF.startMessage(t),bF.addVersion(t,LD.V5),bF.addHeader(t,n),bF.addHeaderType(t,e.headerType),bF.addBodyLength(t,BigInt(e.bodyLength)),bF.finishMessageBuffer(t,bF.endMessage(t)),t.asUint8Array()}static from(t,n=0){if(t instanceof dN)return new e(0,LD.V5,AO.Schema,t);if(t instanceof LF)return new e(n,LD.V5,AO.RecordBatch,t);if(t instanceof RF)return new e(n,LD.V5,AO.DictionaryBatch,t);throw Error(`Unrecognized Message header: ${t}`)}get type(){return this.headerType}get version(){return this._version}get headerType(){return this._headerType}get bodyLength(){return this._bodyLength}header(){return this._createHeader()}isSchema(){return this.headerType===AO.Schema}isRecordBatch(){return this.headerType===AO.RecordBatch}isDictionaryBatch(){return this.headerType===AO.DictionaryBatch}constructor(e,t,n,r){this._version=t,this._headerType=n,this.body=new Uint8Array,r&&(this._createHeader=()=>r),this._bodyLength=PO(e)}},LF=class{get nodes(){return this._nodes}get length(){return this._length}get buffers(){return this._buffers}constructor(e,t,n){this._nodes=t,this._buffers=n,this._length=PO(e)}},RF=class{get id(){return this._id}get data(){return this._data}get isDelta(){return this._isDelta}get length(){return this.data.length}get nodes(){return this.data.nodes}get buffers(){return this.data.buffers}constructor(e,t,n=!1){this._data=e,this._isDelta=n,this._id=PO(t)}},zF=class{constructor(e,t){this.offset=PO(e),this.length=PO(t)}},BF=class{constructor(e,t){this.length=PO(e),this.nullCount=PO(t)}};function VF(e,t){return(()=>{switch(t){case AO.Schema:return dN.fromJSON(e);case AO.RecordBatch:return LF.fromJSON(e);case AO.DictionaryBatch:return RF.fromJSON(e)}throw Error(`Unrecognized Message type: { name: ${AO[t]}, type: ${t} }`)})}function HF(e,t){return(()=>{switch(t){case AO.Schema:return dN.decode(e.header(new kO),new Map,e.version());case AO.RecordBatch:return LF.decode(e.header(new tO),e.version());case AO.DictionaryBatch:return RF.decode(e.header(new nO),e.version())}throw Error(`Unrecognized Message type: { name: ${AO[t]}, type: ${t} }`)})}fN.encode=rI,fN.decode=QF,fN.fromJSON=AF,dN.encode=nI,dN.decode=UF,dN.fromJSON=SF,LF.encode=iI,LF.decode=WF,LF.fromJSON=CF,RF.encode=aI,RF.decode=GF,RF.fromJSON=wF,BF.encode=oI,BF.decode=qF,zF.encode=sI,zF.decode=KF;function UF(e,t=new Map,n=LD.V5){return new dN(XF(e,t),$F(e),t,n)}function WF(e,t=LD.V5){if(e.compression()!==null)throw Error(`Record batch compression not implemented`);return new LF(e.length(),JF(e),YF(e,t))}function GF(e,t=LD.V5){return new RF(LF.decode(e.data(),t),e.id(),e.isDelta())}function KF(e){return new zF(e.offset(),e.length())}function qF(e){return new BF(e.length(),e.nullCount())}function JF(e){let t=[];for(let n,r=-1,i=-1,a=e.nodesLength();++r<a;)(n=e.nodes(r))&&(t[++i]=BF.decode(n));return t}function YF(e,t){let n=[];for(let r,i=-1,a=-1,o=e.buffersLength();++i<o;)(r=e.buffers(i))&&(t<LD.V4&&(r.bb_pos+=8*(i+1)),n[++a]=zF.decode(r));return n}function XF(e,t){let n=[];for(let r,i=-1,a=-1,o=e.fieldsLength();++i<o;)(r=e.fields(i))&&(n[++a]=fN.decode(r,t));return n}function ZF(e,t){let n=[];for(let r,i=-1,a=-1,o=e.childrenLength();++i<o;)(r=e.children(i))&&(n[++a]=fN.decode(r,t));return n}function QF(e,t){let n,r,i,a,o,s;return!t||!(s=e.dictionary())?(i=tI(e,ZF(e,t)),r=new fN(e.name(),i,e.nullable(),$F(e))):t.has(n=PO(s.id()))?(a=(a=s.indexType())?eI(a):new bk,o=new Yk(t.get(n),a,n,s.isOrdered()),r=new fN(e.name(),o,e.nullable(),$F(e))):(a=(a=s.indexType())?eI(a):new bk,t.set(n,i=tI(e,ZF(e,t))),o=new Yk(i,a,n,s.isOrdered()),r=new fN(e.name(),o,e.nullable(),$F(e))),r||null}function $F(e){let t=new Map;if(e)for(let n,r,i=-1,a=Math.trunc(e.customMetadataLength());++i<a;)(n=e.customMetadata(i))&&(r=n.key())!=null&&t.set(r,n.value());return t}function eI(e){return new _k(e.isSigned(),e.bitWidth())}function tI(e,t){let n=e.typeType();switch(n){case DO.NONE:return new gk;case DO.Null:return new gk;case DO.Binary:return new Ak;case DO.LargeBinary:return new jk;case DO.Utf8:return new Mk;case DO.LargeUtf8:return new Nk;case DO.Bool:return new Pk;case DO.List:return new Hk((t||[])[0]);case DO.Struct_:return new Uk(t||[])}switch(n){case DO.Int:{let t=e.type(new aO);return new _k(t.isSigned(),t.bitWidth())}case DO.FloatingPoint:return new Ek(e.type(new hO).precision());case DO.Decimal:{let t=e.type(new dO);return new Fk(t.scale(),t.precision(),t.bitWidth())}case DO.Date:return new Ik(e.type(new uO).unit());case DO.Time:{let t=e.type(new CO);return new Lk(t.unit(),t.bitWidth())}case DO.Timestamp:{let t=e.type(new wO);return new Rk(t.unit(),t.timezone())}case DO.Interval:return new Bk(e.type(new gO).unit());case DO.Duration:return new Vk(e.type(new fO).unit());case DO.Union:{let n=e.type(new TO);return new Wk(n.mode(),n.typeIdsArray()||[],t||[])}case DO.FixedSizeBinary:return new Gk(e.type(new pO).byteWidth());case DO.FixedSizeList:return new Kk(e.type(new mO).listSize(),(t||[])[0]);case DO.Map:{let n=e.type(new bO);return new qk((t||[])[0],n.keysSorted())}}throw Error(`Unrecognized type: "${DO[n]}" (${n})`)}function nI(e,t){let n=t.fields.map(t=>fN.encode(e,t));kO.startFieldsVector(e,n.length);let r=kO.createFieldsVector(e,n),i=t.metadata&&t.metadata.size>0?kO.createCustomMetadataVector(e,[...t.metadata].map(([t,n])=>{let r=e.createString(`${t}`),i=e.createString(`${n}`);return sO.startKeyValue(e),sO.addKey(e,r),sO.addValue(e,i),sO.endKeyValue(e)})):-1;return kO.startSchema(e),kO.addFields(e,r),kO.addEndianness(e,cI?rO.Little:rO.Big),i!==-1&&kO.addCustomMetadata(e,i),kO.endSchema(e)}function rI(e,t){let n=-1,r=-1,i=-1,a=t.type,o=t.typeId;hk.isDictionary(a)?(o=a.dictionary.typeId,i=xF.visit(a,e),r=xF.visit(a.dictionary,e)):r=xF.visit(a,e);let s=(a.children||[]).map(t=>fN.encode(e,t)),c=OO.createChildrenVector(e,s),l=t.metadata&&t.metadata.size>0?OO.createCustomMetadataVector(e,[...t.metadata].map(([t,n])=>{let r=e.createString(`${t}`),i=e.createString(`${n}`);return sO.startKeyValue(e),sO.addKey(e,r),sO.addValue(e,i),sO.endKeyValue(e)})):-1;return t.name&&(n=e.createString(t.name)),OO.startField(e),OO.addType(e,r),OO.addTypeType(e,o),OO.addChildren(e,c),OO.addNullable(e,!!t.nullable),n!==-1&&OO.addName(e,n),i!==-1&&OO.addDictionary(e,i),l!==-1&&OO.addCustomMetadata(e,l),OO.endField(e)}function iI(e,t){let n=t.nodes||[],r=t.buffers||[];tO.startNodesVector(e,n.length);for(let t of n.slice().reverse())BF.encode(e,t);let i=e.endVector();tO.startBuffersVector(e,r.length);for(let t of r.slice().reverse())zF.encode(e,t);let a=e.endVector();return tO.startRecordBatch(e),tO.addLength(e,BigInt(t.length)),tO.addNodes(e,i),tO.addBuffers(e,a),tO.endRecordBatch(e)}function aI(e,t){let n=LF.encode(e,t.data);return nO.startDictionaryBatch(e),nO.addId(e,BigInt(t.id)),nO.addIsDelta(e,t.isDelta),nO.addData(e,n),nO.endDictionaryBatch(e)}function oI(e,t){return eO.createFieldNode(e,BigInt(t.length),BigInt(t.nullCount))}function sI(e,t){return $D.createBuffer(e,BigInt(t.offset),BigInt(t.length))}var cI=(()=>{let e=new ArrayBuffer(2);return new DataView(e).setInt16(0,256,!0),new Int16Array(e)[0]===256})(),lI=e=>`Expected ${AO[e]} Message in stream, but was null or length 0.`,uI=e=>`Header pointer of flatbuffer-encoded ${AO[e]} Message is null or length 0.`,dI=(e,t)=>`Expected to read ${e} metadata bytes, but only read ${t}.`,fI=(e,t)=>`Expected to read ${e} bytes for message body, but only read ${t}.`,pI=class{constructor(e){this.source=e instanceof TN?e:new TN(e)}[Symbol.iterator](){return this}next(){let e;return(e=this.readMetadataLength()).done||e.value===-1&&(e=this.readMetadataLength()).done||(e=this.readMetadata(e.value)).done?bN:e}throw(e){return this.source.throw(e)}return(e){return this.source.return(e)}readMessage(e){let t;if((t=this.next()).done)return null;if(e!=null&&t.value.headerType!==e)throw Error(lI(e));return t.value}readMessageBody(e){if(e<=0)return new Uint8Array;let t=xD(this.source.read(e));if(t.byteLength<e)throw Error(fI(e,t.byteLength));return t.byteOffset%8==0&&t.byteOffset+t.byteLength<=t.buffer.byteLength?t:t.slice()}readSchema(e=!1){let t=AO.Schema,n=this.readMessage(t)?.header();if(e&&!n)throw Error(uI(t));return n}readMetadataLength(){let e=this.source.read(4),t=(e&&new JD(e))?.readInt32(0)||0;return{done:t===0,value:t}}readMetadata(e){let t=this.source.read(e);if(!t)return bN;if(t.byteLength<e)throw Error(dI(e,t.byteLength));return{done:!1,value:IF.decode(t)}}},mI=class{constructor(e,t){this.source=e instanceof EN?e:oD(e)?new AN(e,t):new EN(e)}[Symbol.asyncIterator](){return this}next(){return VE(this,void 0,void 0,function*(){let e;return(e=yield this.readMetadataLength()).done||e.value===-1&&(e=yield this.readMetadataLength()).done||(e=yield this.readMetadata(e.value)).done?bN:e})}throw(e){return VE(this,void 0,void 0,function*(){return yield this.source.throw(e)})}return(e){return VE(this,void 0,void 0,function*(){return yield this.source.return(e)})}readMessage(e){return VE(this,void 0,void 0,function*(){let t;if((t=yield this.next()).done)return null;if(e!=null&&t.value.headerType!==e)throw Error(lI(e));return t.value})}readMessageBody(e){return VE(this,void 0,void 0,function*(){if(e<=0)return new Uint8Array;let t=xD(yield this.source.read(e));if(t.byteLength<e)throw Error(fI(e,t.byteLength));return t.byteOffset%8==0&&t.byteOffset+t.byteLength<=t.buffer.byteLength?t:t.slice()})}readSchema(){return VE(this,arguments,void 0,function*(e=!1){let t=AO.Schema,n=(yield this.readMessage(t))?.header();if(e&&!n)throw Error(uI(t));return n})}readMetadataLength(){return VE(this,void 0,void 0,function*(){let e=yield this.source.read(4),t=(e&&new JD(e))?.readInt32(0)||0;return{done:t===0,value:t}})}readMetadata(e){return VE(this,void 0,void 0,function*(){let t=yield this.source.read(e);if(!t)return bN;if(t.byteLength<e)throw Error(dI(e,t.byteLength));return{done:!1,value:IF.decode(t)}})}},hI=class extends pI{constructor(e){super(new Uint8Array),this._schema=!1,this._body=[],this._batchIndex=0,this._dictionaryIndex=0,this._json=e instanceof xN?e:new xN(e)}next(){let{_json:e}=this;if(!this._schema)return this._schema=!0,{done:!1,value:IF.fromJSON(e.schema,AO.Schema)};if(this._dictionaryIndex<e.dictionaries.length){let t=e.dictionaries[this._dictionaryIndex++];return this._body=t.data.columns,{done:!1,value:IF.fromJSON(t,AO.DictionaryBatch)}}if(this._batchIndex<e.batches.length){let t=e.batches[this._batchIndex++];return this._body=t.columns,{done:!1,value:IF.fromJSON(t,AO.RecordBatch)}}return this._body=[],bN}readMessageBody(e){return t(this._body);function t(e){return(e||[]).reduce((e,n)=>[...e,...n.VALIDITY&&[n.VALIDITY]||[],...n.TYPE_ID&&[n.TYPE_ID]||[],...n.OFFSET&&[n.OFFSET]||[],...n.DATA&&[n.DATA]||[],...t(n.children)],[])}}readMessage(e){let t;if((t=this.next()).done)return null;if(e!=null&&t.value.headerType!==e)throw Error(lI(e));return t.value}readSchema(){let e=AO.Schema,t=this.readMessage(e),n=t?.header();if(!t||!n)throw Error(uI(e));return n}},gI=`ARROW1`,_I=new Uint8Array(6);for(let e=0;e<6;e+=1)_I[e]=gI.codePointAt(e);function vI(e,t=0){for(let n=-1,r=_I.length;++n<r;)if(_I[n]!==e[t+n])return!1;return!0}var yI=_I.length,bI=yI+4,xI=yI*2+4,SI=class e extends SN{constructor(e){super(),this._impl=e}get closed(){return this._impl.closed}get schema(){return this._impl.schema}get autoDestroy(){return this._impl.autoDestroy}get dictionaries(){return this._impl.dictionaries}get numDictionaries(){return this._impl.numDictionaries}get numRecordBatches(){return this._impl.numRecordBatches}get footer(){return this._impl.isFile()?this._impl.footer:null}isSync(){return this._impl.isSync()}isAsync(){return this._impl.isAsync()}isFile(){return this._impl.isFile()}isStream(){return this._impl.isStream()}next(){return this._impl.next()}throw(e){return this._impl.throw(e)}return(e){return this._impl.return(e)}cancel(){return this._impl.cancel()}reset(e){return this._impl.reset(e),this._DOMStream=void 0,this._nodeStream=void 0,this}open(e){let t=this._impl.open(e);return tD(t)?t.then(()=>this):this}readRecordBatch(e){return this._impl.isFile()?this._impl.readRecordBatch(e):null}[Symbol.iterator](){return this._impl[Symbol.iterator]()}[Symbol.asyncIterator](){return this._impl[Symbol.asyncIterator]()}toDOMStream(){return kD.toDOMStream(this.isSync()?{[Symbol.iterator]:()=>this}:{[Symbol.asyncIterator]:()=>this})}toNodeStream(){return kD.toNodeStream(this.isSync()?{[Symbol.iterator]:()=>this}:{[Symbol.asyncIterator]:()=>this},{objectMode:!0})}static throughNode(e){throw Error(`"throughNode" not available in this environment`)}static throughDOM(e,t){throw Error(`"throughDOM" not available in this environment`)}static from(t){return t instanceof e?t:iD(t)?II(t):oD(t)?zI(t):tD(t)?VE(this,void 0,void 0,function*(){return yield e.from(yield t)}):sD(t)||uD(t)||fD(t)||rD(t)?RI(new EN(t)):LI(new TN(t))}static readAll(t){return t instanceof e?t.isSync()?PI(t):FI(t):iD(t)||ArrayBuffer.isView(t)||nD(t)||aD(t)?PI(t):FI(t)}},CI=class extends SI{constructor(e){super(e),this._impl=e}readAll(){return[...this]}[Symbol.iterator](){return this._impl[Symbol.iterator]()}[Symbol.asyncIterator](){return WE(this,arguments,function*(){yield UE(yield*GE(KE(this[Symbol.iterator]())))})}},wI=class extends SI{constructor(e){super(e),this._impl=e}readAll(){return VE(this,void 0,void 0,function*(){var e,t,n,r;let i=[];try{for(var a=!0,o=KE(this),s;s=yield o.next(),e=s.done,!e;a=!0){r=s.value,a=!1;let e=r;i.push(e)}}catch(e){t={error:e}}finally{try{!a&&!e&&(n=o.return)&&(yield n.call(o))}finally{if(t)throw t.error}}return i})}[Symbol.iterator](){throw Error(`AsyncRecordBatchStreamReader is not Iterable`)}[Symbol.asyncIterator](){return this._impl[Symbol.asyncIterator]()}},TI=class extends CI{constructor(e){super(e),this._impl=e}},EI=class extends wI{constructor(e){super(e),this._impl=e}},DI=class{get numDictionaries(){return this._dictionaryIndex}get numRecordBatches(){return this._recordBatchIndex}constructor(e=new Map){this.closed=!1,this.autoDestroy=!0,this._dictionaryIndex=0,this._recordBatchIndex=0,this.dictionaries=e}isSync(){return!1}isAsync(){return!1}isFile(){return!1}isStream(){return!1}reset(e){return this._dictionaryIndex=0,this._recordBatchIndex=0,this.schema=e,this.dictionaries=new Map,this}_loadRecordBatch(e,t){let n=this._loadVectors(e,t,this.schema.fields),r=wM({type:new Uk(this.schema.fields),length:e.length,children:n});return new gF(this.schema,r)}_loadDictionaryBatch(e,t){let{id:n,isDelta:r}=e,{dictionaries:i,schema:a}=this,o=i.get(n),s=a.dictionaries.get(n),c=this._loadVectors(e.data,t,[s]);return(o&&r?o.concat(new JM(c)):new JM(c)).memoize()}_loadVectors(e,t,n){return new zN(t,e.nodes,e.buffers,this.dictionaries,this.schema.metadataVersion).visitMany(n)}},OI=class extends DI{constructor(e,t){super(t),this._reader=iD(e)?new hI(this._handle=e):new pI(this._handle=e)}isSync(){return!0}isStream(){return!0}[Symbol.iterator](){return this}cancel(){!this.closed&&(this.closed=!0)&&(this.reset()._reader.return(),this._reader=null,this.dictionaries=null)}open(e){return this.closed||(this.autoDestroy=NI(this,e),(this.schema||=this._reader.readSchema())||this.cancel()),this}throw(e){return!this.closed&&this.autoDestroy&&(this.closed=!0)?this.reset()._reader.throw(e):bN}return(e){return!this.closed&&this.autoDestroy&&(this.closed=!0)?this.reset()._reader.return(e):bN}next(){if(this.closed)return bN;let e,{_reader:t}=this;for(;e=this._readNextMessageAndValidate();)if(e.isSchema())this.reset(e.header());else if(e.isRecordBatch()){this._recordBatchIndex++;let n=e.header(),r=t.readMessageBody(e.bodyLength);return{done:!1,value:this._loadRecordBatch(n,r)}}else if(e.isDictionaryBatch()){this._dictionaryIndex++;let n=e.header(),r=t.readMessageBody(e.bodyLength),i=this._loadDictionaryBatch(n,r);this.dictionaries.set(n.id,i)}return this.schema&&this._recordBatchIndex===0?(this._recordBatchIndex++,{done:!1,value:new yF(this.schema)}):this.return()}_readNextMessageAndValidate(e){return this._reader.readMessage(e)}},kI=class extends DI{constructor(e,t){super(t),this._reader=new mI(this._handle=e)}isAsync(){return!0}isStream(){return!0}[Symbol.asyncIterator](){return this}cancel(){return VE(this,void 0,void 0,function*(){!this.closed&&(this.closed=!0)&&(yield this.reset()._reader.return(),this._reader=null,this.dictionaries=null)})}open(e){return VE(this,void 0,void 0,function*(){return this.closed||(this.autoDestroy=NI(this,e),(this.schema||=yield this._reader.readSchema())||(yield this.cancel())),this})}throw(e){return VE(this,void 0,void 0,function*(){return!this.closed&&this.autoDestroy&&(this.closed=!0)?yield this.reset()._reader.throw(e):bN})}return(e){return VE(this,void 0,void 0,function*(){return!this.closed&&this.autoDestroy&&(this.closed=!0)?yield this.reset()._reader.return(e):bN})}next(){return VE(this,void 0,void 0,function*(){if(this.closed)return bN;let e,{_reader:t}=this;for(;e=yield this._readNextMessageAndValidate();)if(e.isSchema())yield this.reset(e.header());else if(e.isRecordBatch()){this._recordBatchIndex++;let n=e.header(),r=yield t.readMessageBody(e.bodyLength);return{done:!1,value:this._loadRecordBatch(n,r)}}else if(e.isDictionaryBatch()){this._dictionaryIndex++;let n=e.header(),r=yield t.readMessageBody(e.bodyLength),i=this._loadDictionaryBatch(n,r);this.dictionaries.set(n.id,i)}return this.schema&&this._recordBatchIndex===0?(this._recordBatchIndex++,{done:!1,value:new yF(this.schema)}):yield this.return()})}_readNextMessageAndValidate(e){return VE(this,void 0,void 0,function*(){return yield this._reader.readMessage(e)})}},AI=class extends OI{get footer(){return this._footer}get numDictionaries(){return this._footer?this._footer.numDictionaries:0}get numRecordBatches(){return this._footer?this._footer.numRecordBatches:0}constructor(e,t){super(e instanceof kN?e:new kN(e),t)}isSync(){return!0}isFile(){return!0}open(e){if(!this.closed&&!this._footer){this.schema=(this._footer=this._readFooter()).schema;for(let e of this._footer.dictionaryBatches())e&&this._readDictionaryBatch(this._dictionaryIndex++)}return super.open(e)}readRecordBatch(e){if(this.closed)return null;this._footer||this.open();let t=this._footer?.getRecordBatch(e);if(t&&this._handle.seek(t.offset)){let e=this._reader.readMessage(AO.RecordBatch);if(e?.isRecordBatch()){let t=e.header(),n=this._reader.readMessageBody(e.bodyLength);return this._loadRecordBatch(t,n)}}return null}_readDictionaryBatch(e){let t=this._footer?.getDictionaryBatch(e);if(t&&this._handle.seek(t.offset)){let e=this._reader.readMessage(AO.DictionaryBatch);if(e?.isDictionaryBatch()){let t=e.header(),n=this._reader.readMessageBody(e.bodyLength),r=this._loadDictionaryBatch(t,n);this.dictionaries.set(t.id,r)}}}_readFooter(){let{_handle:e}=this,t=e.size-bI,n=e.readInt32(t),r=e.readAt(t-n,n);return _N.decode(r)}_readNextMessageAndValidate(e){if(this._footer||this.open(),this._footer&&this._recordBatchIndex<this.numRecordBatches){let t=this._footer?.getRecordBatch(this._recordBatchIndex);if(t&&this._handle.seek(t.offset))return this._reader.readMessage(e)}return null}},jI=class extends kI{get footer(){return this._footer}get numDictionaries(){return this._footer?this._footer.numDictionaries:0}get numRecordBatches(){return this._footer?this._footer.numRecordBatches:0}constructor(e,...t){let n=typeof t[0]==`number`?void 0:t.shift(),r=t[0]instanceof Map?t.shift():void 0;super(e instanceof AN?e:new AN(e,n),r)}isFile(){return!0}isAsync(){return!0}open(e){let t=Object.create(null,{open:{get:()=>super.open}});return VE(this,void 0,void 0,function*(){if(!this.closed&&!this._footer){this.schema=(this._footer=yield this._readFooter()).schema;for(let e of this._footer.dictionaryBatches())e&&(yield this._readDictionaryBatch(this._dictionaryIndex++))}return yield t.open.call(this,e)})}readRecordBatch(e){return VE(this,void 0,void 0,function*(){if(this.closed)return null;this._footer||(yield this.open());let t=this._footer?.getRecordBatch(e);if(t&&(yield this._handle.seek(t.offset))){let e=yield this._reader.readMessage(AO.RecordBatch);if(e?.isRecordBatch()){let t=e.header(),n=yield this._reader.readMessageBody(e.bodyLength);return this._loadRecordBatch(t,n)}}return null})}_readDictionaryBatch(e){return VE(this,void 0,void 0,function*(){let t=this._footer?.getDictionaryBatch(e);if(t&&(yield this._handle.seek(t.offset))){let e=yield this._reader.readMessage(AO.DictionaryBatch);if(e?.isDictionaryBatch()){let t=e.header(),n=yield this._reader.readMessageBody(e.bodyLength),r=this._loadDictionaryBatch(t,n);this.dictionaries.set(t.id,r)}}})}_readFooter(){return VE(this,void 0,void 0,function*(){let{_handle:e}=this;e._pending&&(yield e._pending);let t=e.size-bI,n=yield e.readInt32(t),r=yield e.readAt(t-n,n);return _N.decode(r)})}_readNextMessageAndValidate(e){return VE(this,void 0,void 0,function*(){if(this._footer||(yield this.open()),this._footer&&this._recordBatchIndex<this.numRecordBatches){let t=this._footer.getRecordBatch(this._recordBatchIndex);if(t&&(yield this._handle.seek(t.offset)))return yield this._reader.readMessage(e)}return null})}},MI=class extends OI{constructor(e,t){super(e,t)}_loadVectors(e,t,n){return new BN(t,e.nodes,e.buffers,this.dictionaries,this.schema.metadataVersion).visitMany(n)}};function NI(e,t){return t&&typeof t.autoDestroy==`boolean`?t.autoDestroy:e.autoDestroy}function*PI(e){let t=SI.from(e);try{if(!t.open({autoDestroy:!1}).closed)do yield t;while(!t.reset().open().closed)}finally{t.cancel()}}function FI(e){return WE(this,arguments,function*(){let t=yield UE(SI.from(e));try{if(!(yield UE(t.open({autoDestroy:!1}))).closed)do yield yield UE(t);while(!(yield UE(t.reset().open())).closed)}finally{yield UE(t.cancel())}})}function II(e){return new CI(new MI(e))}function LI(e){let t=e.peek(yI+7&-8);return t&&t.byteLength>=4?vI(t)?new TI(new AI(e.read())):new CI(new OI(e)):new CI(new OI(function*(){}()))}function RI(e){return VE(this,void 0,void 0,function*(){let t=yield e.peek(yI+7&-8);return t&&t.byteLength>=4?vI(t)?new TI(new AI(yield e.read())):new wI(new kI(e)):new wI(new kI(function(){return WE(this,arguments,function*(){})}()))})}function zI(e){return VE(this,void 0,void 0,function*(){let{size:t}=yield e.stat(),n=new AN(e,t);return t>=xI&&vI(yield n.readAt(0,yI+7&-8))?new EI(new jI(n)):new wI(new kI(n))})}var BI=class e extends Zk{static assemble(...t){let n=e=>e.flatMap(e=>Array.isArray(e)?n(e):e instanceof gF?e.data.children:e.data),r=new e;return r.visitMany(n(t)),r}constructor(){super(),this._byteLength=0,this._nodes=[],this._buffers=[],this._bufferRegions=[]}visit(e){if(e instanceof JM)return this.visitMany(e.data),this;let{type:t}=e;if(!hk.isDictionary(t)){let{length:n}=e;if(n>2147483647)throw RangeError(`Cannot write arrays larger than 2^31 - 1 in length`);if(hk.isUnion(t))this.nodes.push(new BF(n,0));else{let{nullCount:r}=e;hk.isNull(t)||VI.call(this,r<=0?new Uint8Array:gM(e.offset,n,e.nullBitmap)),this.nodes.push(new BF(n,r))}}return super.visit(e)}visitNull(e){return this}visitDictionary(e){return this.visit(e.clone(e.type.indices))}get nodes(){return this._nodes}get buffers(){return this._buffers}get byteLength(){return this._byteLength}get bufferRegions(){return this._bufferRegions}};function VI(e){let t=e.byteLength+7&-8;return this.buffers.push(e),this.bufferRegions.push(new zF(this._byteLength,t)),this._byteLength+=t,this}function HI(e){let{type:t,length:n,typeIds:r,valueOffsets:i}=e;if(VI.call(this,r),t.mode===RD.Sparse)return qI.call(this,e);if(t.mode===RD.Dense){if(e.offset<=0)return VI.call(this,i),qI.call(this,e);{let a=new Int32Array(n),o=Object.create(null),s=Object.create(null);for(let e,t,c=-1;++c<n;)(e=r[c])!==void 0&&((t=o[e])===void 0&&(t=o[e]=i[c]),a[c]=i[c]-t,s[e]=(s[e]??0)+1);VI.call(this,a),this.visitMany(e.children.map((e,r)=>{let i=t.typeIds[r],a=o[i],c=s[i];return e.slice(a,Math.min(n,c))}))}}return this}function UI(e){let t;return e.nullCount>=e.length?VI.call(this,new Uint8Array):(t=e.values)instanceof Uint8Array?VI.call(this,gM(e.offset,e.length,t)):VI.call(this,_M(e.values))}function WI(e){return VI.call(this,e.values.subarray(0,e.length*e.stride))}function GI(e){let{length:t,values:n,valueOffsets:r}=e,i=PO(r[0]),a=PO(r[t]),o=Math.min(a-i,n.byteLength-i);return VI.call(this,DD(-i,t+1,r)),VI.call(this,n.subarray(i,i+o)),this}function KI(e){let{length:t,valueOffsets:n}=e;if(n){let{0:r,[t]:i}=n;return VI.call(this,DD(-r,t+1,n)),this.visit(e.children[0].slice(r,i-r))}return this.visit(e.children[0])}function qI(e){return this.visitMany(e.type.children.map((t,n)=>e.children[n]).filter(Boolean))[0]}BI.prototype.visitBool=UI,BI.prototype.visitInt=WI,BI.prototype.visitFloat=WI,BI.prototype.visitUtf8=GI,BI.prototype.visitLargeUtf8=GI,BI.prototype.visitBinary=GI,BI.prototype.visitLargeBinary=GI,BI.prototype.visitFixedSizeBinary=WI,BI.prototype.visitDate=WI,BI.prototype.visitTimestamp=WI,BI.prototype.visitTime=WI,BI.prototype.visitDecimal=WI,BI.prototype.visitList=KI,BI.prototype.visitStruct=qI,BI.prototype.visitUnion=HI,BI.prototype.visitInterval=WI,BI.prototype.visitDuration=WI,BI.prototype.visitFixedSizeList=KI,BI.prototype.visitMap=KI;var JI=class extends SN{static throughNode(e){throw Error(`"throughNode" not available in this environment`)}static throughDOM(e,t){throw Error(`"throughDOM" not available in this environment`)}constructor(e){super(),this._position=0,this._started=!1,this._sink=new wN,this._schema=null,this._dictionaryBlocks=[],this._recordBatchBlocks=[],this._seenDictionaries=new Map,this._dictionaryDeltaOffsets=new Map,eD(e)||(e={autoDestroy:!0,writeLegacyIpcFormat:!1}),this._autoDestroy=typeof e.autoDestroy==`boolean`?e.autoDestroy:!0,this._writeLegacyIpcFormat=typeof e.writeLegacyIpcFormat==`boolean`?e.writeLegacyIpcFormat:!1}toString(e=!1){return this._sink.toString(e)}toUint8Array(e=!1){return this._sink.toUint8Array(e)}writeAll(e){return tD(e)?e.then(e=>this.writeAll(e)):rD(e)?QI(this,e):ZI(this,e)}get closed(){return this._sink.closed}[Symbol.asyncIterator](){return this._sink[Symbol.asyncIterator]()}toDOMStream(e){return this._sink.toDOMStream(e)}toNodeStream(e){return this._sink.toNodeStream(e)}close(){return this.reset()._sink.close()}abort(e){return this.reset()._sink.abort(e)}finish(){return this._autoDestroy?this.close():this.reset(this._sink,this._schema),this}reset(e=this._sink,t=null){return e===this._sink||e instanceof wN?this._sink=e:(this._sink=new wN,e&&lD(e)?this.toDOMStream({type:`bytes`}).pipeTo(e):e&&dD(e)&&this.toNodeStream({objectMode:!1}).pipe(e)),this._started&&this._schema&&this._writeFooter(this._schema),this._started=!1,this._dictionaryBlocks=[],this._recordBatchBlocks=[],this._seenDictionaries=new Map,this._dictionaryDeltaOffsets=new Map,(!t||!rF(t,this._schema))&&(t==null?(this._position=0,this._schema=null):(this._started=!0,this._schema=t,this._writeSchema(t))),this}write(e){let t=null;if(!this._sink)throw Error(`RecordBatchWriter is closed`);if(e==null||e instanceof pF&&!(t=e.schema)||e instanceof gF&&!(t=e.schema))return this.finish()&&void 0;if(t&&!rF(t,this._schema)){if(this._started&&this._autoDestroy)return this.close();this.reset(this._sink,t)}e instanceof gF?e instanceof yF||this._writeRecordBatch(e):e instanceof pF?this.writeAll(e.batches):nD(e)&&this.writeAll(e)}_writeMessage(e,t=8){let n=t-1,r=IF.encode(e),i=r.byteLength,a=this._writeLegacyIpcFormat?4:8,o=i+a+n&~n,s=o-i-a;return e.headerType===AO.RecordBatch?this._recordBatchBlocks.push(new yN(o,e.bodyLength,this._position)):e.headerType===AO.DictionaryBatch&&this._dictionaryBlocks.push(new yN(o,e.bodyLength,this._position)),this._writeLegacyIpcFormat||this._write(Int32Array.of(-1)),this._write(Int32Array.of(o-a)),i>0&&this._write(r),this._writePadding(s)}_write(e){if(this._started){let t=xD(e);t&&t.byteLength>0&&(this._sink.write(t),this._position+=t.byteLength)}return this}_writeSchema(e){return this._writeMessage(IF.from(e))}_writeFooter(e){return this._writeLegacyIpcFormat?this._write(Int32Array.of(0)):this._write(Int32Array.of(-1,0))}_writeMagic(){return this._write(_I)}_writePadding(e){return e>0?this._write(new Uint8Array(e)):this}_writeRecordBatch(e){let{byteLength:t,nodes:n,bufferRegions:r,buffers:i}=BI.assemble(e),a=new LF(e.numRows,n,r),o=IF.from(a,t);return this._writeDictionaries(e)._writeMessage(o)._writeBodyBuffers(i)}_writeDictionaryBatch(e,t,n=!1){let{byteLength:r,nodes:i,bufferRegions:a,buffers:o}=BI.assemble(new JM([e])),s=new RF(new LF(e.length,i,a),t,n),c=IF.from(s,r);return this._writeMessage(c)._writeBodyBuffers(o)}_writeBodyBuffers(e){let t,n,r;for(let i=-1,a=e.length;++i<a;)(t=e[i])&&(n=t.byteLength)>0&&(this._write(t),(r=(n+7&-8)-n)>0&&this._writePadding(r));return this}_writeDictionaries(e){for(let[t,n]of e.dictionaries){let e=n?.data??[],r=this._seenDictionaries.get(t),i=this._dictionaryDeltaOffsets.get(t)??0;if(!r||r.data[0]!==e[0])for(let[n,r]of e.entries())this._writeDictionaryBatch(r,t,n>0);else if(i<e.length)for(let n of e.slice(i))this._writeDictionaryBatch(n,t,!0);this._seenDictionaries.set(t,n),this._dictionaryDeltaOffsets.set(t,e.length)}return this}},YI=class e extends JI{static writeAll(t,n){let r=new e(n);return tD(t)?t.then(e=>r.writeAll(e)):rD(t)?QI(r,t):ZI(r,t)}},XI=class e extends JI{static writeAll(t){let n=new e;return tD(t)?t.then(e=>n.writeAll(e)):rD(t)?QI(n,t):ZI(n,t)}constructor(){super(),this._autoDestroy=!0}_writeSchema(e){return this._writeMagic()._writePadding(2)}_writeDictionaryBatch(e,t,n=!1){if(!n&&this._seenDictionaries.has(t))throw Error(`The Arrow File format does not support replacement dictionaries. `);return super._writeDictionaryBatch(e,t,n)}_writeFooter(e){let t=_N.encode(new _N(e,LD.V5,this._recordBatchBlocks,this._dictionaryBlocks));return super._writeFooter(e)._write(t)._write(Int32Array.of(t.byteLength))._writeMagic()}};function ZI(e,t){let n=t;t instanceof pF&&(n=t.batches,e.reset(void 0,t.schema));for(let t of n)e.write(t);return e.finish()}function QI(e,t){return VE(this,void 0,void 0,function*(){var n,r,i,a,o,s,c;try{for(n=!0,r=KE(t);i=yield r.next(),a=i.done,!a;n=!0){c=i.value,n=!1;let t=c;e.write(t)}}catch(e){o={error:e}}finally{try{!n&&!a&&(s=r.return)&&(yield s.call(r))}finally{if(o)throw o.error}}return e.finish()})}function $I(e,t=`stream`){return(t===`stream`?YI:XI).writeAll(e).toUint8Array(!0)}var eL=Object.create,tL=Object.defineProperty,nL=Object.getOwnPropertyDescriptor,rL=Object.getOwnPropertyNames,iL=Object.getPrototypeOf,aL=Object.prototype.hasOwnProperty,oL=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),sL=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(let i of rL(t))!aL.call(e,i)&&i!==n&&tL(e,i,{get:()=>t[i],enumerable:!(r=nL(t,i))||r.enumerable});return e},cL=(e,t,n)=>(n=e==null?{}:eL(iL(e)),sL(t||!e||!e.__esModule?tL(n,`default`,{value:e,enumerable:!0}):n,e)),lL=oL((e,t)=>{t.exports=Worker}),uL=(e=>(e[e.UNDEFINED=0]=`UNDEFINED`,e[e.AUTOMATIC=1]=`AUTOMATIC`,e[e.READ_ONLY=2]=`READ_ONLY`,e[e.READ_WRITE=3]=`READ_WRITE`,e))(uL||{}),dL=(e=>(e[e.IDENTIFIER=0]=`IDENTIFIER`,e[e.NUMERIC_CONSTANT=1]=`NUMERIC_CONSTANT`,e[e.STRING_CONSTANT=2]=`STRING_CONSTANT`,e[e.OPERATOR=3]=`OPERATOR`,e[e.KEYWORD=4]=`KEYWORD`,e[e.COMMENT=5]=`COMMENT`,e))(dL||{}),fL=(e=>(e[e.NONE=0]=`NONE`,e[e.DEBUG=1]=`DEBUG`,e[e.INFO=2]=`INFO`,e[e.WARNING=3]=`WARNING`,e[e.ERROR=4]=`ERROR`,e))(fL||{}),pL=(e=>(e[e.NONE=0]=`NONE`,e[e.CONNECT=1]=`CONNECT`,e[e.DISCONNECT=2]=`DISCONNECT`,e[e.OPEN=3]=`OPEN`,e[e.QUERY=4]=`QUERY`,e[e.INSTANTIATE=5]=`INSTANTIATE`,e))(pL||{}),mL=(e=>(e[e.NONE=0]=`NONE`,e[e.OK=1]=`OK`,e[e.ERROR=2]=`ERROR`,e[e.START=3]=`START`,e[e.RUN=4]=`RUN`,e[e.CAPTURE=5]=`CAPTURE`,e))(mL||{}),hL=(e=>(e[e.NONE=0]=`NONE`,e[e.WEB_WORKER=1]=`WEB_WORKER`,e[e.NODE_WORKER=2]=`NODE_WORKER`,e[e.BINDINGS=3]=`BINDINGS`,e[e.ASYNC_DUCKDB=4]=`ASYNC_DUCKDB`,e))(hL||{}),gL=class{constructor(e=2){this.level=e}log(e){e.level>=this.level&&console.log(e)}},_L=(e=>(e[e.SUCCESS=0]=`SUCCESS`,e[e.MAX_ARROW_ERROR=255]=`MAX_ARROW_ERROR`,e[e.DUCKDB_WASM_RETRY=256]=`DUCKDB_WASM_RETRY`,e))(_L||{}),vL=class{constructor(e,t){this._bindings=e,this._conn=t}get bindings(){return this._bindings}async close(){return this._bindings.disconnect(this._conn)}useUnsafe(e){return e(this._bindings,this._conn)}async query(e){this._bindings.logger.log({timestamp:new Date,level:2,origin:4,topic:4,event:4,value:e});let t=await this._bindings.runQuery(this._conn,e),n=SI.from(t);return console.assert(n.isSync(),`Reader is not sync`),console.assert(n.isFile(),`Reader is not file`),new pF(n)}async send(e,t=!1){this._bindings.logger.log({timestamp:new Date,level:2,origin:4,topic:4,event:4,value:e});let n=await this._bindings.startPendingQuery(this._conn,e,t);for(;n==null;){if(this._bindings.isDetached()){console.error(`cannot send a message since the worker is not set!`);return}n=await this._bindings.pollPendingQuery(this._conn)}let r=new yL(this._bindings,this._conn,n),i=await SI.from(r);return console.assert(i.isAsync()),console.assert(i.isStream()),i}async cancelSent(){return await this._bindings.cancelPendingQuery(this._conn)}async getTableNames(e){return await this._bindings.getTableNames(this._conn,e)}async prepare(e){let t=await this._bindings.createPrepared(this._conn,e);return new bL(this._bindings,this._conn,t)}async insertArrowTable(e,t){let n=$I(e,`stream`);await this.insertArrowFromIPCStream(n,t)}async insertArrowFromIPCStream(e,t){await this._bindings.insertArrowFromIPCStream(this._conn,e,t)}async insertCSVFromPath(e,t){await this._bindings.insertCSVFromPath(this._conn,e,t)}async insertJSONFromPath(e,t){await this._bindings.insertJSONFromPath(this._conn,e,t)}},yL=class{constructor(e,t,n){this.db=e,this.conn=t,this.header=n,this._first=!0,this._depleted=!1,this._inFlight=null}async next(){if(this._first)return this._first=!1,{done:!1,value:this.header};if(this._depleted)return{done:!0,value:null};let e=null;for(this._inFlight!=null&&(e=await this._inFlight,this._inFlight=null);e==null;)e=await this.db.fetchQueryResults(this.conn);return this._depleted=e.length==0,this._depleted||(this._inFlight=this.db.fetchQueryResults(this.conn)),{done:this._depleted,value:e}}[Symbol.asyncIterator](){return this}},bL=class{constructor(e,t,n){this.bindings=e,this.connectionId=t,this.statementId=n}async close(){await this.bindings.closePrepared(this.connectionId,this.statementId)}async query(...e){let t=await this.bindings.runPrepared(this.connectionId,this.statementId,e),n=SI.from(t);return console.assert(n.isSync()),console.assert(n.isFile()),new pF(n)}async send(...e){let t=await this.bindings.sendPrepared(this.connectionId,this.statementId,e),n=new yL(this.bindings,this.connectionId,t),r=await SI.from(n);return console.assert(r.isAsync()),console.assert(r.isStream()),r}},xL=(e=>(e.CANCEL_PENDING_QUERY=`CANCEL_PENDING_QUERY`,e.CLOSE_PREPARED=`CLOSE_PREPARED`,e.COLLECT_FILE_STATISTICS=`COLLECT_FILE_STATISTICS`,e.REGISTER_OPFS_FILE_NAME=`REGISTER_OPFS_FILE_NAME`,e.CONNECT=`CONNECT`,e.COPY_FILE_TO_BUFFER=`COPY_FILE_TO_BUFFER`,e.COPY_FILE_TO_PATH=`COPY_FILE_TO_PATH`,e.CREATE_PREPARED=`CREATE_PREPARED`,e.DISCONNECT=`DISCONNECT`,e.DROP_FILE=`DROP_FILE`,e.DROP_FILES=`DROP_FILES`,e.EXPORT_FILE_STATISTICS=`EXPORT_FILE_STATISTICS`,e.FETCH_QUERY_RESULTS=`FETCH_QUERY_RESULTS`,e.FLUSH_FILES=`FLUSH_FILES`,e.GET_FEATURE_FLAGS=`GET_FEATURE_FLAGS`,e.GET_TABLE_NAMES=`GET_TABLE_NAMES`,e.GET_VERSION=`GET_VERSION`,e.GLOB_FILE_INFOS=`GLOB_FILE_INFOS`,e.INSERT_ARROW_FROM_IPC_STREAM=`INSERT_ARROW_FROM_IPC_STREAM`,e.INSERT_CSV_FROM_PATH=`IMPORT_CSV_FROM_PATH`,e.INSERT_JSON_FROM_PATH=`IMPORT_JSON_FROM_PATH`,e.INSTANTIATE=`INSTANTIATE`,e.OPEN=`OPEN`,e.PING=`PING`,e.POLL_PENDING_QUERY=`POLL_PENDING_QUERY`,e.REGISTER_FILE_BUFFER=`REGISTER_FILE_BUFFER`,e.REGISTER_FILE_HANDLE=`REGISTER_FILE_HANDLE`,e.REGISTER_FILE_URL=`REGISTER_FILE_URL`,e.RESET=`RESET`,e.RUN_PREPARED=`RUN_PREPARED`,e.RUN_QUERY=`RUN_QUERY`,e.SEND_PREPARED=`SEND_PREPARED`,e.START_PENDING_QUERY=`START_PENDING_QUERY`,e.TOKENIZE=`TOKENIZE`,e))(xL||{}),SL=(e=>(e.CONNECTION_INFO=`CONNECTION_INFO`,e.ERROR=`ERROR`,e.FEATURE_FLAGS=`FEATURE_FLAGS`,e.FILE_BUFFER=`FILE_BUFFER`,e.FILE_INFOS=`FILE_INFOS`,e.FILE_SIZE=`FILE_SIZE`,e.FILE_STATISTICS=`FILE_STATISTICS`,e.INSTANTIATE_PROGRESS=`INSTANTIATE_PROGRESS`,e.LOG=`LOG`,e.PROGRESS_UPDATE=`PROGRESS_UPDATE`,e.OK=`OK`,e.PREPARED_STATEMENT_ID=`PREPARED_STATEMENT_ID`,e.QUERY_PLAN=`QUERY_PLAN`,e.QUERY_RESULT=`QUERY_RESULT`,e.QUERY_RESULT_CHUNK=`QUERY_RESULT_CHUNK`,e.QUERY_RESULT_HEADER=`QUERY_RESULT_HEADER`,e.QUERY_RESULT_HEADER_OR_NULL=`QUERY_RESULT_HEADER_OR_NULL`,e.REGISTERED_FILE=`REGISTERED_FILE`,e.SCRIPT_TOKENS=`SCRIPT_TOKENS`,e.SUCCESS=`SUCCESS`,e.TABLE_NAMES=`TABLE_NAMES`,e.VERSION_STRING=`VERSION_STRING`,e))(SL||{}),CL=class{constructor(e,t){this.promiseResolver=()=>{},this.promiseRejecter=()=>{},this.type=e,this.data=t,this.promise=new Promise((e,t)=>{this.promiseResolver=e,this.promiseRejecter=t})}};function wL(e){switch(e.typeId){case Z.Binary:return{sqlType:`binary`};case Z.Bool:return{sqlType:`bool`};case Z.Date:return{sqlType:`date`};case Z.DateDay:return{sqlType:`date32[d]`};case Z.DateMillisecond:return{sqlType:`date64[ms]`};case Z.Decimal:{let t=e;return{sqlType:`decimal`,precision:t.precision,scale:t.scale}}case Z.Float:return{sqlType:`float`};case Z.Float16:return{sqlType:`float16`};case Z.Float32:return{sqlType:`float32`};case Z.Float64:return{sqlType:`float64`};case Z.Int:return{sqlType:`int32`};case Z.Int16:return{sqlType:`int16`};case Z.Int32:return{sqlType:`int32`};case Z.Int64:return{sqlType:`int64`};case Z.Uint16:return{sqlType:`uint16`};case Z.Uint32:return{sqlType:`uint32`};case Z.Uint64:return{sqlType:`uint64`};case Z.Uint8:return{sqlType:`uint8`};case Z.IntervalDayTime:return{sqlType:`interval[dt]`};case Z.IntervalYearMonth:return{sqlType:`interval[m]`};case Z.List:return{sqlType:`list`,valueType:wL(e.valueType)};case Z.FixedSizeBinary:return{sqlType:`fixedsizebinary`,byteWidth:e.byteWidth};case Z.Null:return{sqlType:`null`};case Z.Utf8:return{sqlType:`utf8`};case Z.Struct:return{sqlType:`struct`,fields:e.children.map(e=>TL(e.name,e.type))};case Z.Map:{let t=e;return{sqlType:`map`,keyType:wL(t.keyType),valueType:wL(t.valueType)}}case Z.Time:return{sqlType:`time[s]`};case Z.TimeMicrosecond:return{sqlType:`time[us]`};case Z.TimeMillisecond:return{sqlType:`time[ms]`};case Z.TimeNanosecond:return{sqlType:`time[ns]`};case Z.TimeSecond:return{sqlType:`time[s]`};case Z.Timestamp:return{sqlType:`timestamp`,timezone:e.timezone||void 0};case Z.TimestampSecond:return{sqlType:`timestamp[s]`,timezone:e.timezone||void 0};case Z.TimestampMicrosecond:return{sqlType:`timestamp[us]`,timezone:e.timezone||void 0};case Z.TimestampNanosecond:return{sqlType:`timestamp[ns]`,timezone:e.timezone||void 0};case Z.TimestampMillisecond:return{sqlType:`timestamp[ms]`,timezone:e.timezone||void 0}}throw Error(`unsupported arrow type: ${e.toString()}`)}function TL(e,t){let n=wL(t);return n.name=e,n}var EL=/'(opfs:\/\/\S*?)'/g,DL=/(opfs:\/\/\S*?)/g;function OL(e){return e.search(DL)>-1}function kL(e){return[...e.matchAll(EL)].map(e=>e[1])}var AL=new TextEncoder,jL=class{constructor(e,t=null){this._onInstantiationProgress=[],this._onExecutionProgress=[],this._worker=null,this._workerShutdownPromise=null,this._workerShutdownResolver=()=>{},this._nextMessageId=0,this._pendingRequests=new Map,this._config={},this._logger=e,this._onMessageHandler=this.onMessage.bind(this),this._onErrorHandler=this.onError.bind(this),this._onCloseHandler=this.onClose.bind(this),t!=null&&this.attach(t)}get logger(){return this._logger}get config(){return this._config}attach(e){this._worker=e,this._worker.addEventListener(`message`,this._onMessageHandler),this._worker.addEventListener(`error`,this._onErrorHandler),this._worker.addEventListener(`close`,this._onCloseHandler),this._workerShutdownPromise=new Promise((e,t)=>{this._workerShutdownResolver=e})}detach(){this._worker&&(this._worker.removeEventListener(`message`,this._onMessageHandler),this._worker.removeEventListener(`error`,this._onErrorHandler),this._worker.removeEventListener(`close`,this._onCloseHandler),this._worker=null,this._workerShutdownResolver(null),this._workerShutdownPromise=null,this._workerShutdownResolver=()=>{})}async terminate(){this._worker&&(this._worker.terminate(),this._worker=null,this._workerShutdownPromise=null,this._workerShutdownResolver=()=>{})}async postTask(e,t=[]){if(!this._worker){console.error(`cannot send a message since the worker is not set!:`+e.type+`,`+e.data);return}let n=this._nextMessageId++;return this._pendingRequests.set(n,e),this._worker.postMessage({messageId:n,type:e.type,data:e.data},t),await e.promise}onMessage(e){var t;let n=e.data;switch(n.type){case`PROGRESS_UPDATE`:for(let e of this._onExecutionProgress)e(n.data);return;case`LOG`:this._logger.log(n.data);return;case`INSTANTIATE_PROGRESS`:for(let e of this._onInstantiationProgress)e(n.data);return}let r=this._pendingRequests.get(n.requestId);if(!r){console.warn(`unassociated response: [${n.requestId}, ${n.type.toString()}]`);return}if(this._pendingRequests.delete(n.requestId),n.type==`ERROR`){let e=Error(n.data.message);e.name=n.data.name,(t=Object.getOwnPropertyDescriptor(e,`stack`))!=null&&t.writable&&(e.stack=n.data.stack),r.promiseRejecter(e);return}switch(r.type){case`CLOSE_PREPARED`:case`COLLECT_FILE_STATISTICS`:case`REGISTER_OPFS_FILE_NAME`:case`COPY_FILE_TO_PATH`:case`DISCONNECT`:case`DROP_FILE`:case`DROP_FILES`:case`FLUSH_FILES`:case`INSERT_ARROW_FROM_IPC_STREAM`:case`IMPORT_CSV_FROM_PATH`:case`IMPORT_JSON_FROM_PATH`:case`OPEN`:case`PING`:case`REGISTER_FILE_BUFFER`:case`REGISTER_FILE_HANDLE`:case`REGISTER_FILE_URL`:case`RESET`:if(n.type==`OK`){r.promiseResolver(n.data);return}break;case`INSTANTIATE`:if(this._onInstantiationProgress=[],n.type==`OK`){r.promiseResolver(n.data);return}break;case`GLOB_FILE_INFOS`:if(n.type==`FILE_INFOS`){r.promiseResolver(n.data);return}break;case`GET_VERSION`:if(n.type==`VERSION_STRING`){r.promiseResolver(n.data);return}break;case`GET_FEATURE_FLAGS`:if(n.type==`FEATURE_FLAGS`){r.promiseResolver(n.data);return}break;case`GET_TABLE_NAMES`:if(n.type==`TABLE_NAMES`){r.promiseResolver(n.data);return}break;case`TOKENIZE`:if(n.type==`SCRIPT_TOKENS`){r.promiseResolver(n.data);return}break;case`COPY_FILE_TO_BUFFER`:if(n.type==`FILE_BUFFER`){r.promiseResolver(n.data);return}break;case`EXPORT_FILE_STATISTICS`:if(n.type==`FILE_STATISTICS`){r.promiseResolver(n.data);return}break;case`CONNECT`:if(n.type==`CONNECTION_INFO`){r.promiseResolver(n.data);return}break;case`RUN_PREPARED`:case`RUN_QUERY`:if(n.type==`QUERY_RESULT`){r.promiseResolver(n.data);return}break;case`SEND_PREPARED`:if(n.type==`QUERY_RESULT_HEADER`){r.promiseResolver(n.data);return}break;case`START_PENDING_QUERY`:if(n.type==`QUERY_RESULT_HEADER_OR_NULL`){r.promiseResolver(n.data);return}break;case`POLL_PENDING_QUERY`:if(n.type==`QUERY_RESULT_HEADER_OR_NULL`){r.promiseResolver(n.data);return}break;case`CANCEL_PENDING_QUERY`:if(this._onInstantiationProgress=[],n.type==`SUCCESS`){r.promiseResolver(n.data);return}break;case`FETCH_QUERY_RESULTS`:if(n.type==`QUERY_RESULT_CHUNK`){r.promiseResolver(n.data);return}break;case`CREATE_PREPARED`:if(n.type==`PREPARED_STATEMENT_ID`){r.promiseResolver(n.data);return}break}r.promiseRejecter(Error(`unexpected response type: ${n.type.toString()}`))}onError(e){console.error(e),console.error(`error in duckdb worker: ${e.message}`),this._pendingRequests.clear()}onClose(){if(this._workerShutdownResolver(null),this._pendingRequests.size!=0){console.warn(`worker terminated with ${this._pendingRequests.size} pending requests`);return}this._pendingRequests.clear()}isDetached(){return!this._worker}async reset(){let e=new CL(`RESET`,null);return await this.postTask(e)}async ping(){let e=new CL(`PING`,null);await this.postTask(e)}async dropFile(e){let t=new CL(`DROP_FILE`,e);return await this.postTask(t)}async dropFiles(e){let t=new CL(`DROP_FILES`,e);return await this.postTask(t)}async flushFiles(){let e=new CL(`FLUSH_FILES`,null);return await this.postTask(e)}async instantiate(e,t=null,n=e=>{}){this._onInstantiationProgress.push(n);let r=new CL(`INSTANTIATE`,[e,t]);return await this.postTask(r)}async getVersion(){let e=new CL(`GET_VERSION`,null);return await this.postTask(e)}async getFeatureFlags(){let e=new CL(`GET_FEATURE_FLAGS`,null);return await this.postTask(e)}async open(e){this._config=e;let t=new CL(`OPEN`,e);await this.postTask(t)}async tokenize(e){let t=new CL(`TOKENIZE`,e);return await this.postTask(t)}async connectInternal(){let e=new CL(`CONNECT`,null);return await this.postTask(e)}async connect(){let e=await this.connectInternal();return new vL(this,e)}async disconnect(e){let t=new CL(`DISCONNECT`,e);await this.postTask(t)}async runQuery(e,t){if(this.shouldOPFSFileHandling()){let n=await this.registerOPFSFileFromSQL(t);try{return await this._runQueryAsync(e,t)}finally{n.length>0&&await this.dropFiles(n)}}else return await this._runQueryAsync(e,t)}async _runQueryAsync(e,t){let n=new CL(`RUN_QUERY`,[e,t]);return await this.postTask(n)}async startPendingQuery(e,t,n=!1){if(this.shouldOPFSFileHandling()){let r=await this.registerOPFSFileFromSQL(t);try{return await this._startPendingQueryAsync(e,t,n)}finally{r.length>0&&await this.dropFiles(r)}}else return await this._startPendingQueryAsync(e,t,n)}async _startPendingQueryAsync(e,t,n=!1){let r=new CL(`START_PENDING_QUERY`,[e,t,n]);return await this.postTask(r)}async pollPendingQuery(e){let t=new CL(`POLL_PENDING_QUERY`,e);return await this.postTask(t)}async cancelPendingQuery(e){let t=new CL(`CANCEL_PENDING_QUERY`,e);return await this.postTask(t)}async fetchQueryResults(e){let t=new CL(`FETCH_QUERY_RESULTS`,e);return await this.postTask(t)}async getTableNames(e,t){let n=new CL(`GET_TABLE_NAMES`,[e,t]);return await this.postTask(n)}async createPrepared(e,t){let n=new CL(`CREATE_PREPARED`,[e,t]);return await this.postTask(n)}async closePrepared(e,t){let n=new CL(`CLOSE_PREPARED`,[e,t]);await this.postTask(n)}async runPrepared(e,t,n){let r=new CL(`RUN_PREPARED`,[e,t,n]);return await this.postTask(r)}async sendPrepared(e,t,n){let r=new CL(`SEND_PREPARED`,[e,t,n]);return await this.postTask(r)}async globFiles(e){let t=new CL(`GLOB_FILE_INFOS`,e);return await this.postTask(t)}async registerFileText(e,t){let n=AL.encode(t);await this.registerFileBuffer(e,n)}async registerFileURL(e,t,n,r){t===void 0&&(t=e);let i=new CL(`REGISTER_FILE_URL`,[e,t,n,r]);await this.postTask(i)}async registerEmptyFileBuffer(e){}async registerFileBuffer(e,t){let n=new CL(`REGISTER_FILE_BUFFER`,[e,t]);await this.postTask(n,[t.buffer])}async registerFileHandle(e,t,n,r){let i=new CL(`REGISTER_FILE_HANDLE`,[e,t,n,r]);await this.postTask(i,[])}async registerOPFSFileName(e){let t=new CL(`REGISTER_OPFS_FILE_NAME`,[e]);await this.postTask(t,[])}async collectFileStatistics(e,t){let n=new CL(`COLLECT_FILE_STATISTICS`,[e,t]);await this.postTask(n,[])}async exportFileStatistics(e){let t=new CL(`EXPORT_FILE_STATISTICS`,e);return await this.postTask(t,[])}async copyFileToBuffer(e){let t=new CL(`COPY_FILE_TO_BUFFER`,e);return await this.postTask(t)}async copyFileToPath(e,t){let n=new CL(`COPY_FILE_TO_PATH`,[e,t]);await this.postTask(n)}async insertArrowFromIPCStream(e,t,n){if(t.length==0)return;let r=new CL(`INSERT_ARROW_FROM_IPC_STREAM`,[e,t,n]);await this.postTask(r,[t.buffer])}async insertCSVFromPath(e,t,n){if(n.columns!==void 0){let e=[];for(let t in n.columns){let r=n.columns[t];e.push(TL(t,r))}n.columnsFlat=e,delete n.columns}let r=new CL(`IMPORT_CSV_FROM_PATH`,[e,t,n]);await this.postTask(r)}async insertJSONFromPath(e,t,n){if(n.columns!==void 0){let e=[];for(let t in n.columns){let r=n.columns[t];e.push(TL(t,r))}n.columnsFlat=e,delete n.columns}let r=new CL(`IMPORT_JSON_FROM_PATH`,[e,t,n]);await this.postTask(r)}shouldOPFSFileHandling(){return OL(this.config.path??``)?this.config.opfs?.fileHandling==`auto`:!1}async registerOPFSFileFromSQL(e){let t=kL(e),n=[];for(let e of t)try{await this.registerOPFSFileName(e),n.push(e)}catch(t){throw console.error(t),Error(`File Not found:`+e)}return n}};function ML(){let e=new TextDecoder;return t=>(typeof SharedArrayBuffer<`u`&&t.buffer instanceof SharedArrayBuffer&&(t=new Uint8Array(t)),e.decode(t))}ML();var NL=(e=>(e[e.BUFFER=0]=`BUFFER`,e[e.NODE_FS=1]=`NODE_FS`,e[e.BROWSER_FILEREADER=2]=`BROWSER_FILEREADER`,e[e.BROWSER_FSACCESS=3]=`BROWSER_FSACCESS`,e[e.HTTP=4]=`HTTP`,e[e.S3=5]=`S3`,e))(NL||{}),PL={name:`@duckdb/duckdb-wasm`,version:`1.33.1-dev45.0`,description:`DuckDB powered by WebAssembly`,license:`MIT`,repository:{type:`git`,url:`https://github.com/duckdb/duckdb-wasm.git`},keywords:[`sql`,`duckdb`,`relational`,`database`,`data`,`query`,`wasm`,`analytics`,`olap`,`arrow`,`parquet`,`json`,`csv`],dependencies:{"apache-arrow":`^17.0.0`,qs:`^6.14.1`},devDependencies:{"@types/emscripten":`^1.39.10`,"@types/jasmine":`^5.1.13`,"@typescript-eslint/eslint-plugin":`^6.21.0`,"@typescript-eslint/parser":`^6.21.0`,esbuild:`^0.20.2`,eslint:`^8.57.0`,"eslint-plugin-jasmine":`^4.1.3`,"eslint-plugin-react":`^7.37.5`,"fast-glob":`^3.3.2`,jasmine:`^5.13.0`,"jasmine-core":`^5.1.2`,"jasmine-spec-reporter":`^7.0.0`,"js-sha256":`^0.11.1`,karma:`^6.4.2`,"karma-chrome-launcher":`^3.2.0`,"karma-coverage":`^2.2.1`,"karma-firefox-launcher":`^2.1.3`,"karma-jasmine":`^5.1.0`,"karma-jasmine-html-reporter":`^2.1.0`,"karma-sourcemap-loader":`^0.4.0`,"karma-spec-reporter":`^0.0.36`,"make-dir":`^4.0.0`,nyc:`^15.1.0`,prettier:`^3.2.5`,puppeteer:`^22.8.0`,rimraf:`^5.0.5`,s3rver:`^3.7.1`,typedoc:`^0.28.15`,typescript:`^5.3.3`,"wasm-feature-detect":`^1.6.1`,"web-worker":`^1.2.0`},scripts:{"build:debug":`node bundle.mjs debug && tsc --emitDeclarationOnly`,"build:release":`node bundle.mjs release && tsc --emitDeclarationOnly`,docs:`typedoc`,format:`prettier --write "**/*.+(js|ts)"`,report:`node ./coverage.mjs`,"test:node":`node --enable-source-maps ../../node_modules/jasmine/bin/jasmine ./dist/tests-node.cjs`,"test:node:debug":`node --inspect-brk --enable-source-maps ../../node_modules/jasmine/bin/jasmine ./dist/tests-node.cjs`,"test:node:coverage":`nyc -r json --report-dir ./coverage/node node ../../node_modules/jasmine/bin/jasmine ./dist/tests-node.cjs`,"test:firefox":`karma start ./karma/tests-firefox.cjs`,"test:chrome":`karma start ./karma/tests-chrome.cjs`,"test:chrome:eh":`karma start ./karma/tests-chrome-eh.cjs`,"test:chrome:coverage":`karma start ./karma/tests-chrome-coverage.cjs`,"test:browser":`karma start ./karma/tests-all.cjs`,"test:browser:debug":`karma start ./karma/tests-debug.cjs`,test:`npm run test:chrome && npm run test:node`,"test:coverage":`npm run test:chrome:coverage && npm run test:node:coverage && npm run report`,lint:`eslint src test`},files:[`dist`,`!dist/tests-*`,`!dist/duckdb-browser-mvp.worker.js.map`,`!dist/types/test`],main:`dist/duckdb-browser.cjs`,module:`dist/duckdb-browser.mjs`,types:`dist/duckdb-browser.d.ts`,jsdelivr:`dist/duckdb-browser.cjs`,unpkg:`dist/duckdb-browser.mjs`,sideEffects:!1,browser:{fs:!1,path:!1,perf_hooks:!1,os:!1,worker_threads:!1},exports:{"./dist/duckdb-mvp.wasm":`./dist/duckdb-mvp.wasm`,"./dist/duckdb-eh.wasm":`./dist/duckdb-eh.wasm`,"./dist/duckdb-coi.wasm":`./dist/duckdb-coi.wasm`,"./dist/duckdb-browser":`./dist/duckdb-browser.mjs`,"./dist/duckdb-browser.cjs":`./dist/duckdb-browser.cjs`,"./dist/duckdb-browser.mjs":`./dist/duckdb-browser.mjs`,"./dist/duckdb-browser-coi.pthread.worker.js":`./dist/duckdb-browser-coi.pthread.worker.js`,"./dist/duckdb-browser-coi.worker.js":`./dist/duckdb-browser-coi.worker.js`,"./dist/duckdb-browser-eh.worker.js":`./dist/duckdb-browser-eh.worker.js`,"./dist/duckdb-browser-mvp.worker.js":`./dist/duckdb-browser-mvp.worker.js`,"./dist/duckdb-node":`./dist/duckdb-node.cjs`,"./dist/duckdb-node.cjs":`./dist/duckdb-node.cjs`,"./dist/duckdb-node-blocking":`./dist/duckdb-node-blocking.cjs`,"./dist/duckdb-node-blocking.cjs":`./dist/duckdb-node-blocking.cjs`,"./dist/duckdb-node-eh.worker.cjs":`./dist/duckdb-node-eh.worker.cjs`,"./dist/duckdb-node-mvp.worker.cjs":`./dist/duckdb-node-mvp.worker.cjs`,"./blocking":{node:{types:`./dist/duckdb-node-blocking.d.ts`,require:`./dist/duckdb-node-blocking.cjs`,import:`./dist/duckdb-node-blocking.cjs`},types:`./dist/duckdb-node-blocking.d.ts`,import:`./dist/duckdb-node-blocking.mjs`,require:`./dist/duckdb-node-blocking.cjs`},".":{browser:{types:`./dist/duckdb-browser.d.ts`,import:`./dist/duckdb-browser.mjs`,require:`./dist/duckdb-browser.cjs`},node:{types:`./dist/duckdb-node.d.ts`,import:`./dist/duckdb-node.cjs`,require:`./dist/duckdb-node.cjs`},types:`./dist/duckdb-browser.d.ts`,import:`./dist/duckdb-browser.mjs`,require:`./dist/duckdb-browser.cjs`}}};PL.name,PL.version;var FL=PL.version.split(`.`);FL[0],FL[1],FL[2],cL(lL());var IL=``+new URL(`assets/duckdb-browser-eh.worker--3HUwN9R.js`,import.meta.url).href,LL=``+new URL(`assets/duckdb-eh-D-nnNw7L.wasm.gz`,import.meta.url).href;async function RL(e){if(!e.endsWith(`.gz`))return e;let t=await fetch(e);if(!t.ok)throw Error(`DuckDB-WASM did not load (${t.status})`);let n=new Uint8Array(await t.arrayBuffer());return n[0]===31&&n[1]===139&&(n=new Uint8Array(await new Response(new Blob([n]).stream().pipeThrough(new DecompressionStream(`gzip`))).arrayBuffer())),URL.createObjectURL(new Blob([n],{type:`application/wasm`}))}var zL=null;function BL(){return zL||(zL=(async()=>{let e=e=>new URL(e,location.href).href,t=URL.createObjectURL(new Blob([`importScripts(${JSON.stringify(e(IL))});`],{type:`text/javascript`})),n=new Worker(t),r=new jL(new gL(fL.WARNING),n),i=await RL(e(LL));await r.instantiate(i,null),URL.revokeObjectURL(t),i.startsWith(`blob:`)&&URL.revokeObjectURL(i);let a=await r.connect();return await a.query(`SET checkpoint_threshold = '1TB'`),await a.query(`SET autoinstall_known_extensions = false`),await a.query(`SET autoload_known_extensions = false`),await a.close(),r})(),zL)}var VL=null;function HL(){return VL??=(async()=>{let e=await BL(),t=await e.connect();try{await t.query(`SET custom_extension_repository = '${new URL(`/duckdb-ext`,location.href).href}'`),await t.query(`LOAD parquet`)}finally{await t.close()}return e})().catch(e=>{throw VL=null,e}),VL}function UL(e){return`"`+e.replace(/"/g,`""`)+`"`}function WL(e){if(!(e.x1>e.x0))throw Error(`buildDecimationSql: x1 must be greater than x0`);if(e.maxPoints<1)throw Error(`buildDecimationSql: maxPoints must be >= 1`);if(!e.table||!e.xcol||!e.ycol)throw Error(`buildDecimationSql: table, xcol and ycol are required`);let t=(e.x1-e.x0)/e.maxPoints,n=UL(e.xcol),r=UL(e.ycol);return{sql:`SELECT least(floor((${n} - ?) / ?), ? - 1) AS b, min(${r}) AS lo, max(${r}) AS hi, arg_min(${r}, ${n}) AS first, arg_max(${r}, ${n}) AS last FROM ${UL(e.table)} WHERE ${n} BETWEEN ? AND ? GROUP BY 1 ORDER BY 1`,params:[e.x0,t,e.maxPoints,e.x0,e.x1]}}function GL(e){if(!(e.x1>e.x0))throw Error(`buildMultiDecimationSql: x1 must be greater than x0`);if(e.maxPoints<1)throw Error(`buildMultiDecimationSql: maxPoints must be >= 1`);if(!e.table||!e.xcol||e.ycols.length===0)throw Error(`buildMultiDecimationSql: table, xcol and at least one ycol are required`);let t=(e.x1-e.x0)/e.maxPoints,n=UL(e.xcol),r=UL(e.table);return{sql:`SELECT least(floor((${n} - ?) / ?), ? - 1) AS b, ${e.ycols.map((e,t)=>`min(${UL(e)}) AS y${t}lo, max(${UL(e)}) AS y${t}hi`).join(`, `)} FROM ${r} WHERE ${n} BETWEEN ? AND ? GROUP BY 1 ORDER BY 1`,params:[e.x0,t,e.maxPoints,e.x0,e.x1]}}var KL=`__kym_bin`;function qL(e){if(!(e.binWidth>0))throw Error(`buildPyramidBuildL0Sql: binWidth must be > 0`);if(e.ycols.length===0)throw Error(`buildPyramidBuildL0Sql: at least one ycol is required`);let t=UL(e.xcol),n=UL(e.srcTable);return`CREATE OR REPLACE TABLE ${UL(e.dstTable)} AS SELECT ${`CAST(floor((${t} - ${XL(e.x0base)}) / ${XL(e.binWidth)}) AS BIGINT)`} AS ${KL}, ${e.ycols.map(e=>`min(${UL(e)}) AS ${UL(e+`__lo`)}, max(${UL(e)}) AS ${UL(e+`__hi`)}`).join(`, `)} FROM ${n} WHERE ${t} IS NOT NULL GROUP BY 1`}function JL(e){let t=UL(e.srcTable);return`CREATE OR REPLACE TABLE ${UL(e.dstTable)} AS SELECT CAST(floor(${KL} / 2.0) AS BIGINT) AS ${KL}, ${e.ycols.map(e=>`min(${UL(e+`__lo`)}) AS ${UL(e+`__lo`)}, max(${UL(e+`__hi`)}) AS ${UL(e+`__hi`)}`).join(`, `)} FROM ${t} GROUP BY 1`}function YL(e){if(!(e.x1>e.x0))throw Error(`buildPyramidQuerySql: x1 must be greater than x0`);if(e.maxPoints<1)throw Error(`buildPyramidQuerySql: maxPoints must be >= 1`);if(e.ycols.length===0)throw Error(`buildPyramidQuerySql: at least one ycol is required`);let t=(e.x1-e.x0)/e.maxPoints,n=e.binWidth/t,r=(e.x0base-e.x0)/t+.5*n,i=Math.max(0,Math.floor((e.x0-e.x0base)/e.binWidth)),a=Math.floor((e.x1-e.x0base)/e.binWidth),o=UL(e.levelTable);return{sql:`SELECT least(greatest(CAST(floor(? + ${KL} * ?) AS BIGINT), 0), ?) AS b, ${e.ycols.map((e,t)=>`min(${UL(e+`__lo`)}) AS y${t}lo, max(${UL(e+`__hi`)}) AS y${t}hi`).join(`, `)} FROM ${o} WHERE ${KL} BETWEEN ? AND ? GROUP BY 1 ORDER BY 1`,params:[r,n,e.maxPoints-1,i,a]}}function XL(e){if(!Number.isFinite(e))throw Error(`num: value must be finite`);return Number.isInteger(e)?String(e):e.toExponential(17)}function ZL(e){let t=UL(e.table);return e.range?{sql:`SELECT count(*) AS n FROM ${t} WHERE ${UL(e.range.xcol)} BETWEEN ? AND ?`,params:[e.range.x0,e.range.x1]}:{sql:`SELECT count(*) AS n FROM ${t}`,params:[]}}function QL(e){if(!Number.isInteger(e.stride)||e.stride<1)throw Error(`buildSampleRowsSql: stride must be a positive integer`);let t=UL(e.table),n=e.range?` WHERE ${UL(e.range.xcol)} BETWEEN ? AND ?`:``,r=e.range?[e.range.x0,e.range.x1]:[];return e.stride===1?{sql:`SELECT * FROM ${t}${n}`,params:r}:{sql:`SELECT * EXCLUDE(__kym_rn) FROM (SELECT *, row_number() OVER () - 1 AS __kym_rn FROM ${t}${n}) WHERE __kym_rn % ${e.stride} = 0`,params:r}}function $L(e){return`'`+e.replace(/'/g,`''`)+`'`}function eR(e){let t=e.columnNames.map($L).join(`, `),n=e.delim===` `?`'\\t'`:$L(e.delim),r=e.decimalComma?`decimal_separator=',', `:``;return`SELECT * FROM read_csv(${$L(e.handle)}, header=false, skip=${e.dataStartRow}, delim=${n}, `+r+`names=[${t}], auto_type_candidates=['DOUBLE', 'VARCHAR'])`}function tR(e,t,n){let r=e.length,i={x:new Float64Array(r),min:new Float64Array(r),max:new Float64Array(r),first:new Float64Array(r),last:new Float64Array(r)};for(let a=0;a<r;a++){let r=e[a],o=Number(r.b);i.x[a]=t+(o+.5)*n,i.min[a]=Number(r.lo),i.max[a]=Number(r.hi),i.first[a]=Number(r.first),i.last[a]=Number(r.last)}return i}var nR=class{#e;#t=new Map;constructor(e){this.#e=Math.max(1,e)}get(e){let t=this.#t.get(e);return t!==void 0&&(this.#t.delete(e),this.#t.set(e,t)),t}set(e,t){if(this.#t.has(e)&&this.#t.delete(e),this.#t.set(e,t),this.#t.size>this.#e){let e=this.#t.keys().next().value;this.#t.delete(e)}}get size(){return this.#t.size}},rR=0,iR=()=>`t_${++rR}`,aR=5e4,oR=65536,sR=512,cR=2;function lR(e){return e<1?1:2**Math.floor(Math.log2(e))}var uR=class e{#e;#t;#n;#r;#i=new nR(96);#a=new Map;#o=new Map;#s=[];#c=0;constructor(e,t,n){this.#e=e,this.#t=t,this.#n=n,this.#r=new Set(t.map(e=>e.name))}static async open(t,n){let r=await BL(),i=await r.connect(),a=await t.slice(0,256*1024).text(),o=y(a),s=te(a),c=V(o,s.headerRow),l=s.unitsRow===null?``:o[s.unitsRow]??``,u=Le(o[s.headerRow]??``),d=x(o.slice(s.dataStartRow,s.dataStartRow+10),u);n?.({phase:`reading`,message:`Reading file…`});let f=new Uint8Array(await t.arrayBuffer());await r.dropFile(`input.csv`).catch(()=>{}),await r.registerFileBuffer(`input.csv`,f),n?.({phase:`parsing`,message:`Parsing CSV…`});let p=iR(),m=eR({handle:`input.csv`,columnNames:c,delim:u,dataStartRow:s.dataStartRow,decimalComma:d});await i.query(`CREATE OR REPLACE TABLE ${UL(p)} AS ${m}`),await r.dropFile(`input.csv`).catch(()=>{});let h=l?l.split(u).map(e=>e.trim()):[],g=new Map;c.forEach((e,t)=>g.set(e,h[t]??``));let _=await e.attach(i,p,g);return n?.({phase:`done`,message:`Ready.`}),_}static async attach(t,n,r){return new e(t,(await t.query(`DESCRIBE ${UL(n)}`)).toArray().map(e=>{let t=String(e.column_type??``),n=/INT|DECIMAL|DOUBLE|FLOAT|REAL|HUGEINT|BIGINT/i.test(t),i=String(e.column_name);return{name:i,type:n?`number`:`string`,unit:r.get(i)??``}}),n)}async getSchema(){return this.#t}async getSeries(e){if(!Number.isFinite(e.viewport.x0)||!Number.isFinite(e.viewport.x1)||e.viewport.x1<=e.viewport.x0){let e=new Float64Array;return{x:e,min:e,max:e,first:e,last:e}}let t=(e.viewport.x1-e.viewport.x0)/e.maxPoints,{sql:n,params:r}=WL({table:this.#n,xcol:e.viewport.xKey,ycol:e.column,x0:e.viewport.x0,x1:e.viewport.x1,maxPoints:e.maxPoints}),i=await this.#e.prepare(n);try{return tR((await i.query(...r)).toArray(),e.viewport.x0,t)}finally{await i.close()}}async getSeriesMulti(e,t,n){let r=(t.x1-t.x0)/n,i=this.#r.has(t.xKey)?e.filter(e=>this.#r.has(e)):[];if(i.length===0||!Number.isFinite(t.x0)||!Number.isFinite(t.x1)||t.x1<=t.x0)return{x0:t.x0,bucket:r,rows:[],columns:i};let a=`${t.xKey}|${i.join(`,`)}|${t.x0}|${t.x1}|${n}`,o=this.#i.get(a);if(o)return o;let s=this.#o.get(t.xKey);s===void 0&&this.#l(t.xKey);let{sql:c,params:l}=this.#u(s??null,i,t,n)??GL({table:this.#n,xcol:t.xKey,ycols:i,x0:t.x0,x1:t.x1,maxPoints:n}),u=await this.#e.prepare(c);try{let e=(await u.query(...l)).toArray(),n={x0:t.x0,bucket:r,rows:e,columns:i};return this.#i.set(a,n),n}finally{await u.close()}}#l(e){let t=this.#a.get(e);if(t)return t;let n=this.#d(e).then(t=>(this.#o.set(e,t),t)).catch(()=>(this.#o.set(e,null),null));return this.#a.set(e,n),n}#u(e,t,n,r){if(!e)return null;for(let n of t)if(!e.cols.has(n))return null;let i=(n.x1-n.x0)/r/cR,a=null;for(let t of e.levels)t.binWidth<=i&&(a=t);return a?YL({levelTable:a.table,ycols:t,x0base:e.x0base,binWidth:a.binWidth,x0:n.x0,x1:n.x1,maxPoints:r}):null}async#d(e){if(!this.#r.has(e))return null;let t=await(await BL()).connect();try{let n=ZL({table:this.#n}),r=await t.query(n.sql),i=Number(r.getChild(`n`)?.get(0)??0);if(i<aR)return null;let a=await t.query(`SELECT min(${UL(e)}) AS lo, max(${UL(e)}) AS hi FROM ${UL(this.#n)}`),o=Number(a.getChild(`lo`)?.get(0)),s=Number(a.getChild(`hi`)?.get(0));if(!Number.isFinite(o)||!Number.isFinite(s)||!(s>o))return null;let c=this.#t.filter(t=>t.type===`number`&&t.name!==e).map(e=>e.name);if(c.length===0)return null;let l=s-o,u=Math.min(oR,lR(i));if(u<sR*2)return null;let d=++this.#c,f=[],p=u,m=0,h=`${this.#n}_p${d}_0`;await t.query(qL({srcTable:this.#n,dstTable:h,xcol:e,ycols:c,x0base:o,binWidth:l/u})),this.#s.push(h),f.push({table:h,binWidth:l/u,nbins:p});let g=h;for(;p/2>=sR;){p/=2,m+=1;let e=`${this.#n}_p${d}_${m}`;await t.query(JL({srcTable:g,dstTable:e,ycols:c})),this.#s.push(e),f.push({table:e,binWidth:l/p,nbins:p}),g=e}return{x0base:o,cols:new Set(c),levels:f}}finally{await t.close()}}async sampleRows(e,t){let n=t&&this.#r.has(t.xcol)?t:void 0,r=ZL({table:this.#n,range:n}),i=await this.#e.prepare(r.sql),a;try{let e=await i.query(...r.params);a=Number(e.getChild(`n`)?.get(0)??0)}finally{await i.close()}if(a===0)return[];let o=Math.max(1,Math.ceil(a/e)),{sql:s,params:c}=QL({table:this.#n,stride:o,range:n}),l=await this.#e.prepare(s),u=this.#t.map(e=>e.name),d=[];try{let e=await l.query(...c);for(let t=0;t<e.numRows;t++)d.push({});for(let t of u){let n=e.getChild(t);if(!n){for(let e of d)e[t]=null;continue}let r=n.toArray(),i=ArrayBuffer.isView(r),a=n.nullCount>0;for(let e=0;e<d.length;e++){let o=a&&!n.isValid(e)?null:i?r[e]:n.get(e);d[e][t]=typeof o==`bigint`?Number(o):o}}}finally{await l.close()}return d}async readColumns(e,t,n){let r=[...new Set(e)].filter(e=>this.#r.has(e));if(!r.length)return{};let i=r.map((e,t)=>`coalesce(TRY_CAST(${UL(e)} AS DOUBLE), 'NaN'::DOUBLE) AS "c${t}"`).join(`, `),a=await this.#e.prepare(`SELECT ${i} FROM ${UL(this.#n)} ORDER BY rowid LIMIT ? OFFSET ?`);try{let e=await a.query(n,t),i={};return r.forEach((t,n)=>{let r=e.getChild(`c${n}`)?.toArray();i[t]=r instanceof Float64Array?r:Float64Array.from(r??[],Number)}),i}finally{await a.close()}}async xBounds(e){if(!this.#r.has(e))return{x0:0,x1:0};let t=await this.#e.query(`SELECT min(${UL(e)}) AS lo, max(${UL(e)}) AS hi FROM ${UL(this.#n)}`);return{x0:Number(t.getChild(`lo`)?.get(0)),x1:Number(t.getChild(`hi`)?.get(0))}}async dispose(){for(let e of this.#s)try{await this.#e.query(`DROP TABLE IF EXISTS ${UL(e)}`)}catch{}try{await this.#e.query(`DROP TABLE IF EXISTS ${UL(this.#n)}`)}catch{}await this.#e.close()}},dR=1e8,fR=256*1024;function pR(e,t,n=0,r=dR){return e>314572800||n+t>r?`duckdb`:`memory`}function mR(e,t){let n=y(t);t.length<e&&n.length>1&&(n=n.slice(0,-1));try{let t=te(n.join(`
|
|
70
|
-
`)),r=V(n,t.headerRow).length,i=n.slice(t.dataStartRow);if(i.length===0)return Math.ceil(e/8);let a=n.slice(0,t.dataStartRow).reduce((e,t)=>e+t.length+1,0),o=i.reduce((e,t)=>e+t.length+1,0)/i.length;return Math.ceil(Math.max(0,e-a)/o)*r}catch{return Math.ceil(e/8)}}var hR=12e3;async function gR(e,n,r){let i=te(r),a=typeof Worker>`u`?t(r,i):await IE({rawText:r,config:i}),o=new BE(a);return{id:e,name:n,kind:`memory`,source:o,schema:await o.getSchema(),data:a,rawText:r,parseConfig:i}}async function _R(e,t,n,r,i=e=>e.text(),a){let o=te(r),s=typeof Worker>`u`?await LE({rawText:await i(n),config:o},a):await LE({file:n,config:o},a),c=new BE(s);return{id:e,name:t,kind:`memory`,source:c,schema:await c.getSchema(),data:s,rawText:r,file:n,parseConfig:o}}async function vR(e,t,n){let r=await uR.open(t,n),i=await r.getSchema(),a=await r.sampleRows(hR),o={meta:``,columnNames:i.map(e=>e.name),units:i.map(e=>e.unit),rows:a},s=await t.slice(0,fR).text();return{id:e,name:t.name,kind:`duckdb`,source:r,schema:i,data:o,rawText:s,parseConfig:te(s)}}async function yR(e,t,n,r,i=0,a){let o=await t.slice(0,fR).text();return pR(t.size,mR(t.size,o),i)===`memory`?_R(e,t.name,t,o,e=>n(e),a):vR(e,t,r)}function bR(e,t){return e instanceof File&&e.name===t.name&&e.size===t.size&&e.lastModified===t.lastModified}async function xR(e,t,n){let r=n.find(e=>e.kind===`memory`&&e.parseConfig&&bR(e.file,t)&&Ae(e.data.rows));if(!r)return null;let i=await t.slice(0,fR).text();if(!ne(r.parseConfig,te(i)))return null;let a={...r.data,rows:ze(Ae(r.data.rows))};return{id:e,name:t.name,kind:`memory`,source:new BE(a),schema:r.schema,data:a,rawText:r.rawText,file:t,parseConfig:r.parseConfig}}function SR(e){let t=new Set,n=0;for(let r of e){if(r.kind!==`memory`)continue;let e=Ae(r.data.rows)??r.data.rows;t.has(e)||(t.add(e),n+=r.data.rows.length*r.data.columnNames.length)}return n}var CR=4096,wR=[`.dat`,`.txt`,`.csv`,`.tsv`],TR=[w,Se,r,we,D,l,d],ER=e=>{let t=e.lastIndexOf(`.`);return t<=0?``:e.slice(t).toLowerCase()},DR=e=>{let t=e.lastIndexOf(`.`);return(t<=0?e:e.slice(0,t)).toLowerCase()};async function OR(e){let t=new Uint8Array(await e.slice(0,CR).arrayBuffer()),n=ER(e.name),r=TR.filter(e=>e.extensions.includes(n));for(let n of[...r,...TR.filter(e=>!r.includes(e))])if(n.sniff(t,e.name))return n;return null}async function kR(e){return new Uint8Array(await e.slice(0,CR).arrayBuffer()).includes(0)}async function AR(e){let t=await Promise.all(e.map(OR)),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]&&ER(e.name)===n.ext),o=a.find(e=>DR(e.name)===DR(i.main.name))??(n.anyName&&a.length===1?a[0]:void 0);o&&(i.companions.push(o),r.add(o))}let i=new Set(TR.flatMap(e=>(e.companions??[]).map(e=>e.ext))),a=[];for(let t of e){if(r.has(t))continue;let e=ER(t.name);e===`.dat`&&await kR(t)?a.push({file:t.name,error:Error(`This COMTRADE .dat needs its .cfg file — drop both together.`)}):wR.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 jR=[...new Set([...wR,...TR.flatMap(e=>[...e.extensions,...(e.companions??[]).map(e=>e.ext)])])];function MR(e){let t=0;for(let n=0;n<e.length;n++)e[n]!==e[n]&&t++;if(t===0)return XM(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 XM(wM({type:new kk,data:e,nullBitmap:n,length:e.length,nullCount:t}))}var NR=122880,PR=class{#e;#t;#n;#r=!1;#i=[];#a=0;#o;rows=0;constructor(e,t,n,r=NR){this.#e=e,this.#t=t,this.#n=new dN(n.map(e=>new fN(e.name,e.text?new Mk:new kk,!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?MR(i.subarray(0,t)):oF(i.slice(0,t),new Mk)).data[0]});this.#i.push(new gF(this.#n,wM({type:new Uk(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 pF(this.#n,this.#i);this.#i=[],this.#a=0,await this.#e.insertArrowTable(e,{name:this.#t,create:!this.#r}),this.#r=!0}},FR=`This file's groups do not interleave in time: reading them together would hold too much in memory. Choose fewer groups, or split them.`,IR=e=>e.length*(1+e.columns.length);function LR(e){let t=e[Symbol.asyncIterator]();return{pull:async()=>{let e=await t.next();return e.done?null:e.value}}}function RR(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-=IR(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+=IR(o.value))>128e6))throw Error(FR)}};return n.map((e,t)=>({pull:()=>a(t)}))}function zR(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 BR=new Int32Array,VR={t:new Float64Array,cols:[],from:0};function HR(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 UR=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=WR(zR(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(FR)}};function WR(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 GR(e,t){let n=e.length,r=e.map(e=>e.t),i=Int32Array.from(e,e=>e.from),a=Int32Array.from(e,e=>HR(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 KR(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 qR(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];KR(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}KR(e,d,u,p,l-1,c[p]),o=c[l-1],t=d[u+l-1]}e.fill(t,o,e.length)}function JR(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 YR(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):BR}function XR(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=HR(i,e,r.from,i.length),o=new Int32Array(a-r.from);if(c.push(YR(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 JR(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),qR(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 ZR(e,t,n,r,i,a=!1){let o=e.map((e,r)=>new UR(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=GR(l.map(e=>e.pending[0]??VR),e),n=[t];for(let e=0;e<o.length;e++)n.push(...XR(o[e],t,c[e],u&&c[e],a));d+=t.length,t.length&&await r({length:t.length,columns:n})}return d}var QR=class{#e;#t;#n;#r=0;constructor(e,t){let n=Math.max(1024,t);this.#e=e.map(e=>e.name),this.#t=e.map(()=>new Float64Array(n)),this.#n=e.map(()=>null)}append(e){let t=this.#r,n=t+e.length;if(n>this.#t[0].length){let e=Math.max(n,Math.ceil(this.#t[0].length*1.5));this.#t=this.#t.map(n=>{let r=new Float64Array(e);return r.set(n.subarray(0,t)),r})}e.columns.forEach((n,r)=>{let i=this.#t[r];if(n instanceof Float64Array){i.set(n.subarray(0,e.length),t);return}let a=this.#n[r];for(let o=0;o<e.length;o++){i[t+o]=NaN;let e=n[o];e!=null&&((a??=this.#n[r]=[])[t+o]=e)}}),this.#r=n}table(){let e=this.#r,t=this.#t.map(t=>t.length-e>t.length/100?t.slice(0,e):t.subarray(0,e));return{keys:this.#e,length:e,values:t,text:this.#n}}};async function $R(e,t,n){return s(await e.plan(t,n))}var ez=(e,t,n)=>Math.max(0,Math.min(e,Math.max(1<<20,n),Math.floor(1e8/t)));function tz(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=se(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 nz(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 rz(e,t,n){let r=nz(e,t);return r<0?Math.ceil(n/4):r*(1+t.reduce((e,t)=>e+t.channels.length,0))}async function iz(e,t,n,r,i,a,o={}){let s=tz(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=>LR(d(e.streamGroup({...f,selection:[t]},t.group)))):RR(d(e.stream(f)),new Map(i.map((e,t)=>[e.group,t]))),m=nz(n,i),h=a===`memory`?new QR(s,ez(m,s.length,r.size)):null,g=0,_=await ZR(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 az=``+new URL(`assets/importer.worker-CLBGjz4d.js`,import.meta.url).href,oz=``+new URL(`assets/h5wasmModule-BCQWU2Gw.js`,import.meta.url).href,sz=()=>new ME(`cancelled`);function cz(){let e=NE(az);return e.postMessage({type:`init`,h5Url:new URL(oz,location.href).href}),e}var lz=null,uz=e=>{typeof requestIdleCallback==`function`?requestIdleCallback(e,{timeout:5e3}):setTimeout(e,1e3)};function dz(e,t=cz){t===cz&&typeof Worker>`u`||(lz&&lz.make!==t&&(lz.w.terminate(),lz=null),lz??={w:t(),h5:!1,make:t},e&&!lz.h5&&(lz.h5=!0,lz.w.postMessage({type:`warm`})))}function fz(e){if(lz?.make!==e)return{w:e(),rewarm:null};let{w:t,h5:n}=lz;return lz=null,{w:t,rewarm:n}}function pz(e,t,n,r,i){return!r&&typeof Worker>`u`?mz(e,t,n,i):gz(e,t,n,r??cz)}function mz(e,t,n,r=async e=>(await import(`./importers-2iwVi4cq.js`)).importerFor(e)){let i=new Je(t.main),a=null,o=null,s=e=>e.catch(e=>{throw n?.aborted?sz():Xe(e)});return{plan:()=>s((async()=>(a=await r(e),o=await $R(a,t,i)))()),read:(e,r,c={})=>(i.bytesRead=0,s(iz(a,t,o,i,e,r,{...c,signal:n}))),close(){}}}var hz=3e4;function gz(e,t,n,r){let{w:i,rewarm:a}=fz(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>hz&&p(Error(Qe))},1e3),h=()=>p(sz());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(sz());return}if(d){a(Error(Qe));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&&uz(()=>dz(a,r))}}}var _z=12e3,vz=(e,t)=>t.map(t=>({group:t,channels:e.groups[t].channels.map((e,t)=>t)}));function yz(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 bz(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:yz(e,n)}:null,splitKey:r,channels:n.reduce((e,t)=>e+t.channels.length,0),notes:e.notes,meta:e.meta,events:[]}}async function xz(e,t,n,r,i,a){let o={meta:``,columnNames:n.columns.map(e=>e.name),units:n.columns.map(e=>e.unit),rows:ze(n.table)},s=new BE(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 Sz(e,t,n,r,i,a,o,s,c){let l=BL().then(e=>e.connect());l.catch(()=>void 0);let u=iR(),d=tz(r,i),f=new PR({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 uR.attach(p,u,new Map(d.map(e=>[e.name,e.unit]))),h=await m.getSchema(),g=await m.sampleRows(_z);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 ${UL(u)}`).catch(()=>void 0),await t?.close().catch(()=>void 0),e}}async function Cz(e,t){let{main:n,companions:r}=e,i=pz(e.format,{main:n,companions:r,keys:e.keys},t.signal,t.createWorker,t.find),a=[];try{t.priorInMemoryValues+n.size/8>1e8&&BL().catch(()=>void 0);let o=await i.plan(),s=t.selection??t.initial??vz(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=>rz(o,e,n.size),budget:dR,used:t.priorInMemoryValues,notes:o.notes});if(!e)throw new ME(`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=rz(o,s,n.size),f=l.length>1?`${n.name} · ${o.groups[s[0].group].name}`:n.name,p=bz(o,e.format,s,u),m=crypto.randomUUID();if(pR(0,c,d)===`memory`){let e=await i.read(s,`memory`,{progress:t.onProgress});a.push(await xz(m,f,e,n,r,p)),d+=c}else a.push(await Sz(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 ME(`cancelled`):e}finally{i.close()}}function wz(e){return e.filter(e=>e.type===`number`).map(e=>e.name)}function Tz(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 Ez(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`camera`:return 0;case`heatmap`:return e.hmColumns.length;case`xyzmesh`:return e.xyzColumns?.length??0;default:return 0}}function Dz(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 Oz(e){return Math.max(2,Math.min(6,Math.floor(e/64)))}function kz(e,t,n,r){let i=Math.max(e,t)-Math.min(e,t),a=n!==void 0&&n>0&&Number.isFinite(n)?n:Dz(i,6);(a<=0||!Number.isFinite(a))&&(a=Dz(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 Az(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 jz(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 Mz={[-12]:`p`,[-9]:`n`,[-6]:`µ`,[-3]:`m`,0:``,3:`k`,6:`M`,9:`G`,12:`T`};function Nz(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 Pz(e,t){if(!Number.isFinite(e))return`—`;if(!(t>0)||!Number.isFinite(t))return Fz(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(Nz(t/10**r))+Mz[r]}return e.toFixed(Nz(t))}function Fz(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)+Mz[n]}var Iz=946684800,Lz=4102444800;function Rz(e,t,n){return/\(([^)]*)\)\s*$/.exec(e)?.[1].trim()===`s`&&n>t&&t>=Iz&&n<=Lz}var zz=new Map;function Bz(e){let t=zz.get(e);if(!t){let n={day:`numeric`,month:`short`,year:`numeric`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`,hourCycle:`h23`};try{t=new Intl.DateTimeFormat(`en-GB`,{...n,timeZone:e})}catch{t=Bz(void 0)}zz.set(e,t)}return t}var Vz=new Map,Hz=(e,t)=>{let n=Math.round(e*1e3),r=Math.floor(n/1e3),i=`${t??``}|${r}`,a=Vz.get(i);if(!a){let e={};for(let{type:n,value:i}of Bz(t).formatToParts(r*1e3))e[n]=i;let n=`${e.hour}:${e.minute}`;a={date:`${e.day} ${e.month}`,year:e.year,hm:n,hms:`${n}:${e.second}`},Vz.size>=1024&&Vz.clear(),Vz.set(i,a)}return{...a,ms:String(n-r*1e3).padStart(3,`0`)}},Uz,Wz=new Set;function Gz(e){if(e!==void 0)try{new Intl.DateTimeFormat(void 0,{timeZone:e})}catch{e=void 0}if(e!==Uz){Uz=e;for(let e of Wz)e()}}var Kz=()=>Uz;function qz(e){return Wz.add(e),()=>{Wz.delete(e)}}function Jz(e,t,n,r=Uz){let i=Hz(e,r);return t>=86400?i.date:n>86400?`${i.date} ${i.hm}`:t>=60?i.hm:t>=1?i.hms:`${i.hms}.${i.ms}`}function Yz(e,t=Uz){let n=Hz(e,t);return`${n.date} ${n.year} ${n.hms}.${n.ms}`}var Xz=[`#fb923c`,`#60a5fa`,`#4ade80`,`#f87171`,`#facc15`,`#22d3ee`,`#f472b6`,`#2dd4bf`,`#94a3b8`,`#a3e635`];function Zz(e,t,n,r=Xz){let i=r.length>0?r:Xz;return e[t]??i[n%i.length]}function Qz(e){return[e===`light`?`#000000`:`#ffffff`,...Xz.slice(0,9)]}function $z(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:Qz(t)}var eB=[`class`,`data-theme`,`data-color-scheme`];function tB(e){return e?.closest(`[data-color-scheme]`)??document.documentElement}function nB(e){return tB(e).getAttribute(`data-color-scheme`)===`light`?`light`:`dark`}function rB(e,t){let n=new MutationObserver(t),r=new Set([document.documentElement,tB(e)]);for(let e of r)n.observe(e,{attributes:!0,attributeFilter:eB});return()=>n.disconnect()}function iB(e,t){return!!t&&e.composedPath().includes(t)}var aB=[`min`,`max`,`mean`,`integral`,`first`,`last`,`delta`],oB=e=>`${e.channel}:${e.stat}`,sB=e=>`channel`in e?[e.channel]:[];function cB(e,t,n){switch(e){case`>`:return t>n;case`>=`:return t>=n;case`<`:return t<n;case`<=`:return t<=n;case`==`:return t===n;default:return t!==n}}function lB(e,t,n,r){switch(e){case`>`:case`>=`:return t<n-r;case`<`:case`<=`:return t>n+r;case`==`:return t!==n;default:return t===n}}var uB=()=>({prev:NaN,lo:0,hi:0});function dB(e,t){if(e.prev!==e.prev)return e.prev=e.lo=e.hi=t,!1;let n=t<e.prev&&e.prev-t>(e.hi-e.lo)/2;return n?e.lo=e.hi=t:(t<e.lo&&(e.lo=t),t>e.hi&&(e.hi=t)),e.prev=t,n}var fB=new Map,pB=e=>{let t=fB.get(e);return t||(t=new Intl.DateTimeFormat(`en-US`,{timeZone:e,hourCycle:`h23`,year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`}),fB.set(e,t)),t};function mB(e,t){let n={};for(let r of pB(t).formatToParts(new Date(Math.floor(e)*1e3)))n[r.type]=r.value;return(Date.UTC(+n.year,n.month-1,+n.day,+n.hour,+n.minute,+n.second)-Math.floor(e)*1e3)/1e3}function hB(e,t){let n=e+mB(e,t);return new Date(Math.floor(n)*1e3).toISOString().slice(0,10)}function gB(e,t,n){let[r,i,a]=e.split(`-`).map(Number),[o,s]=t.split(`:`).map(Number),c=Date.UTC(r,i-1,a,o,s)/1e3;return c-mB(c-mB(c,n),n)}var _B=(e,t)=>{let[n,r,i]=e.split(`-`).map(Number);return new Date(Date.UTC(n,r-1,i+t)).toISOString().slice(0,10)},vB=class{n=0;sum=0;min=1/0;max=-1/0;first=NaN;last=NaN;integral=0;lastT=NaN;add(e,t){t===t&&(this.n>0?this.integral+=(t+this.last)/2*(e-this.lastT):this.first=t,this.n++,this.sum+=t,t<this.min&&(this.min=t),t>this.max&&(this.max=t),this.last=t,this.lastT=e)}value(e){if(this.n===0)return null;switch(e){case`min`:return this.min;case`max`:return this.max;case`mean`:return this.sum/this.n;case`integral`:return this.integral;case`first`:return this.first;case`last`:return this.last;default:return this.last-this.first}}},yB=class{rule;kpis;#e;#t=null;#n=NaN;#r=uB();#i=!1;#a=NaN;#o=NaN;#s=NaN;#c=new Map;constructor(e,t=[]){this.rule=e,this.kpis=t,this.#e=[...new Set(t.map(e=>e.channel))]}#l(e){this.#t={tstart:e,acc:new Map(this.#e.map(e=>[e,new vB]))}}#u(e,t,n){let r={duration:(t??n)-e.tstart};for(let t of this.kpis)r[oB(t)]=e.acc.get(t.channel).value(t.stat);return{tstart:e.tstart,tend:t,kpis:r}}#d(e){let t=this.#t;return this.#t=null,t?this.#u(t,e,e):null}assumeOpen(e){this.#t||(this.#l(e),this.rule.kind===`condition`&&(this.#i=!0))}#f(e){let t=this.#c.get(e);if(!t){let n=this.rule;t=n.starts.map(t=>gB(e,t,n.tz)).sort((e,t)=>e-t),this.#c.set(e,t)}return t}#p(e){let t=this.rule.tz,n=hB(e,t),r=-1/0;for(let t of this.#f(n))t<=e&&(r=t);if(r>-1/0)return r;let i=this.#f(_B(n,-1));return i[i.length-1]}#m(e){let t=this.rule.tz,n=hB(e,t);for(let t of this.#f(n))if(t>e)return t;return this.#f(_B(n,1))[0]}feed(e,t,n){let r=[],i=this.rule,a=i.kind===`edge`||i.kind===`condition`?t(i.channel):void 0,o=this.#e.map(e=>[e,t(e)]);for(let t=0;t<e.length;t++){let s=e[t];if(i.kind===`window`){if(!(s>=this.#a&&s<this.#o)){let e=this.#p(s);if(this.#t){let t=this.#d(this.#o<=e?this.#o:e);t&&r.push(t)}this.#a=e,this.#o=this.#m(e),this.#l(e)}}else if(a&&i.kind!==`manual`){let e=a[t];if(e===e){if(i.kind===`edge`){let t=!1;if(i.on===`reset`){let n=this.#r.prev!==this.#r.prev;t=dB(this.#r,e),n&&!this.#t&&this.#l(s)}else if(this.#n===this.#n){let n=i.value??0;t=i.on===`change`?e!==this.#n:i.on===`rise`?this.#n<n&&e>=n:this.#n>n&&e<=n}if(this.#n=e,t){let e=this.#d(s);e&&r.push(e),this.#l(s)}}else if(!this.#i)cB(i.op,e,i.value)&&(this.#i=!0,this.#l(s));else if(lB(i.op,e,i.value,i.hysteresis??0)){this.#i=!1;let e=this.#d(s);e&&s-e.tstart>=(i.min_s??0)&&r.push(e)}}}let c=this.#t;if(c)for(let[e,n]of o)n&&c.acc.get(e).add(s,n[t]);this.#s=s,n?.(t,c?c.tstart:null)}return r}open(){let e=this.#t;return!e||this.rule.kind===`condition`&&this.#s-e.tstart<(this.rule.min_s??0)?null:this.#u(e,null,this.#s)}},bB=[{value:`span`,label:`Span (max − min)`},{value:`mean`,label:`Mean`},{value:`max`,label:`Max`},{value:`min`,label:`Min`}];function xB(e,t){let n=[],r=uB(),i=-1;for(let a=0;a<e.length;a++){let o=e[a][t];if(typeof o!=`number`)continue;let s=dB(r,o);i<0?i=0:s&&(n.push({start:i,end:a}),i=a)}return i>=0&&n.push({start:i,end:e.length}),n}function SB(e,t){let n=[],r=e.length-1,i=Math.max(1,Math.floor(e.length/256)),a=t=>{let n=0,r=0,a=0;for(let o=0;o+1<e.length;o+=i){let i=e[o][t],s=e[o+1][t];typeof i!=`number`||typeof s!=`number`||(n++,s<i?r++:s===i&&a++)}return n<32||r<=.3*n&&a<=.9*n};for(let o of t){if(i>1&&!a(o))continue;let t=0,s=0,c=0,l=null,u=!1;for(let n of e){let e=n[o];if(typeof e==`number`){if(l!==null&&(c++,e>l?t++:e===l&&s++,c-t-s>.1*r||s>.5*r)){u=!0;break}l=e}}if(u||c===0||(t+s)/c<.9||t/c<.5)continue;let d=xB(e,o).length;d>1&&n.push({col:o,laps:d})}return n.sort((e,t)=>t.laps-e.laps).map(e=>e.col)}function CB(e,t){return SB(e,t)[0]??t[0]??``}function wB(e,t,n){if(n&&t.includes(n.channel)&&xB(e,n.channel).length>1)return{...n,metric:t.includes(n.metric)?n.metric:n.channel};let r=SB(e,t);if(r.length===0)return null;let i=r.find(e=>/time/i.test(e));return{channel:r[0],metric:i??r[0],stat:`span`}}function TB(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 EB(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 DB(e,t){return t.trim()===`s`||/time/i.test(e)}function OB(e,t,n){if(e===null)return`—`;if(n&&e>=0){let t=Math.round(e*1e3),n=Math.floor(t/6e4);return`${n}:${((t-n*6e4)/1e3).toFixed(3).padStart(6,`0`)}`}let r=Math.abs(e),i=r!==0&&r<.01?Fz(e):e.toFixed(r>=1e3?0:r>=100?1:3);return t.trim()?`${i} ${t.trim()}`:i}function kB(e,t){return`${e}::lap${t}`}function AB(e){let t=new Map,n=n=>{let r=t.get(n);return r||t.set(n,r=e.at.map(t=>gB(n,t,e.tz)).sort((e,t)=>e-t)),r},r=t=>{let r=hB(t,e.tz),i=-1/0;for(let e of n(r))e<=t&&(i=e);if(i>-1/0)return i;let a=n(_B(r,-1));return a[a.length-1]},i=t=>{let r=hB(t,e.tz);for(let e of n(r))if(e>t)return e;return n(_B(r,1))[0]},a=NaN,o=NaN,s={on:!1,edge:!1,at:NaN,event:!0,step(e){if(s.edge=s.on=!(e.t>=a&&e.t<o),!s.edge)return;let t=r(e.t);s.closeAt=o<=t?o:t,s.at=a=t,o=i(t)}};return s}function jB(e){switch(e.kind){case`compare`:{let t={on:!1,edge:!1,at:NaN,event:!1,step(n){let r=n.v(e.channel);r===r&&(t.on=cB(e.op,r,e.value)),t.at=n.t}};return t}case`elapsed`:{let t={on:!1,edge:!1,at:NaN,event:!1,step(n){let r=n.t-(e.from===`start`?n.start:n.ps);t.on=r===r&&(e.op===`>=`?r>=e.seconds:r<=e.seconds),t.at=n.t}};return t}case`change`:case`cross`:{let t=NaN,n={on:!1,edge:!1,at:NaN,event:!0,step(r){let i=r.v(e.channel);n.edge=!1,i===i&&(t===t&&(n.edge=e.kind===`change`?i!==t:e.dir===`rise`?t<e.value&&i>=e.value:t>e.value&&i<=e.value),t=i),n.on=n.edge,n.at=r.t}};return n}case`reset`:{let t=uB(),n={on:!1,edge:!1,at:NaN,event:!0,step(r){let i=r.v(e.channel);n.edge=i===i&&(t.prev===t.prev?dB(t,i):(dB(t,i),!0)),n.on=n.edge,n.at=r.t}};return n}case`clock`:return AB(e);case`parent-start`:{let e=!1,t={on:!1,edge:!1,at:NaN,event:!0,step(n){t.on=t.edge=!e,e=!0,t.at=n.ps}};return t}case`all`:case`any`:{let t=e.of.map(jB),n={on:!1,edge:!1,at:NaN,event:t.some(e=>e.event),step(r){for(let e of t)e.step(r);n.on=e.kind===`all`?t.every(e=>e.on):t.some(e=>e.on),n.edge=n.on&&t.some(e=>e.edge),n.at=r.t}};return n}default:return{on:!1,edge:!1,at:NaN,event:!0,step(){}}}}var MB=(e,t)=>e.kind===t||(e.kind===`all`||e.kind===`any`)&&e.of.some(e=>MB(e,t));function NB(e){let t=new Set,n=e=>{`channel`in e&&t.add(e.channel),(e.kind===`all`||e.kind===`any`)&&e.of.forEach(n)};return n(e.start),n(e.end),[...t]}var PB=class{rule;#e;#t;#n=NaN;#r=!1;#i=NaN;#a=NaN;#o=NaN;#s=NaN;#c;#l;constructor(e){this.rule=e,this.#c=MB(e.end,`parent-end`),this.#l=e.end.kind===`next-start`,this.#u()}#u(){this.#e=jB(this.rule.start),this.#t=jB(this.rule.end),this.#r=!1}#d(e,t,n){let r=this.rule.limits;if(!r)return[];let i=[],a=r.from===`start`?e:this.#n;return r.expectedWithin_s!=null&&t-a>r.expectedWithin_s&&i.push(`late`),r.max_s!=null&&t-e>r.max_s&&i.push(`too-long`),n&&r.min_s!=null&&t-e<r.min_s&&i.push(`too-short`),i}#f(e,t,n=!1){let r={tstart:this.#i,tend:e,flags:this.#d(this.#i,e,!0)};n&&(r.incomplete=!0),t.push(r),this.#i=this.#o=NaN}parentStart(e){this.#n=e,this.#i=this.#a=this.#o=NaN,this.#u()}parentEnd(e,t){this.#i===this.#i&&this.#f(e,t,!this.#c),this.#a=NaN,this.#n=NaN}step(e,t,n){this.#n!==this.#n&&(this.#n=e);let r={t:e,v:t,ps:this.#n,start:this.#i},i=this.#e,a=this.#t;i.step(r),a.step(r);let o=i.on&&(!this.#r||i.edge);this.#r=i.on;let s=i.event&&!(this.rule.start.kind===`all`||this.rule.start.kind===`any`)?i.at:e;if(this.#i===this.#i&&!this.#l&&e>this.#i){let t=this.rule.ignoreDips_s??0;a.on?t>0&&!a.event?(this.#o!==this.#o&&(this.#o=e),e-this.#o>=t&&this.#f(this.#o,n)):this.#f(e,n):this.#o=NaN}let c=e=>{this.#i===this.#i&&this.#f(this.#l&&i.closeAt!==void 0?i.closeAt:e,n),this.#i=e},l=this.#i!==this.#i||this.#l,u=this.rule.minHold_s??0;this.#a===this.#a?i.on?e-this.#a>=u&&(l&&c(this.#a),this.#a=NaN):this.#a=NaN:o&&l&&(u>0&&!i.event?this.#a=s:c(s)),this.#s=e}open(){return this.#i===this.#i?{tstart:this.#i,tend:null,flags:this.#d(this.#i,this.#s,!1)}:null}},FB=class{#e;constructor(e){let t=[],n=r=>{for(let i of e)i.parentId===r&&(t.push(i),n(i.id))};n(null),this.#e=t.map(e=>({...e,runner:new PB(e.rule),count:0,current:0,kids:[]})),this.#e.forEach((e,t)=>{e.parentId&&this.#e.find(t=>t.id===e.parentId).kids.push(t)})}#t(e,t,n,r){let i=this.#e[e];for(let e of t)n.push({...e,definitionId:i.id,index:i.current,...r?{parentIndex:r}:{}})}#n(e){let t=this.#e[e].parentId;return t?this.#e.find(e=>e.id===t).current:void 0}#r(e,t,n){for(let r of this.#e[e].kids){this.#r(r,t,n);let i=[];this.#e[r].runner.parentEnd(t,i),this.#t(r,i,n,this.#e[e].current)}}#i(e,t,n,r){let i=this.#e[e],a=i.runner.open()?.tstart,o=[];i.runner.step(t,n,o);let s=i.runner.open()?.tstart;if(o.length)for(let t of o)this.#r(e,t.tend,r),r.push({...t,definitionId:i.id,index:i.current,...this.#n(e)?{parentIndex:this.#n(e)}:{}});if(s!==void 0&&s!==a){i.current=++i.count;for(let e of i.kids)this.#e[e].current=this.#e[e].count=0,this.#e[e].runner.parentStart(s)}if(s!==void 0)for(let e of i.kids)this.#i(e,t,n,r)}feed(e,t){let n=new Map,r=e=>(n.has(e)||n.set(e,t(e)),n.get(e)),i=[],a=0,o=e=>{let t=r(e);return t?t[a]:NaN};for(;a<e.length;a++)for(let t=0;t<this.#e.length;t++)this.#e[t].parentId||this.#i(t,e[a],o,i);return i}open(){let e=[];return this.#e.forEach((t,n)=>{let r=t.runner.open(),i=this.#n(n);r&&(!t.parentId||this.#e.find(e=>e.id===t.parentId).runner.open())&&e.push({...r,definitionId:t.id,index:t.current,...i?{parentIndex:i}:{}})}),e}},IB=new Set([`>`,`>=`,`<`,`<=`,`==`,`!=`]),LB=e=>typeof e==`number`&&Number.isFinite(e),RB=e=>typeof e==`string`&&e.length>0;function zB(e,t){let n=e;if(!n||typeof n!=`object`)return!1;switch(n.kind){case`parent-start`:case`parent-end`:case`next-start`:case`manual`:return!0;case`all`:case`any`:return t<3&&Array.isArray(n.of)&&n.of.length>0&&n.of.every(e=>zB(e,t+1));case`compare`:return RB(n.channel)&&IB.has(n.op)&&LB(n.value);case`change`:case`reset`:return RB(n.channel);case`cross`:return RB(n.channel)&&(n.dir===`rise`||n.dir===`fall`)&&LB(n.value);case`elapsed`:return(n.from===`parent-start`||n.from===`start`)&&(n.op===`>=`||n.op===`<=`)&&LB(n.seconds);case`clock`:return Array.isArray(n.at)&&n.at.length>0&&n.at.every(e=>typeof e==`string`&&/^\d\d:\d\d$/.test(e))&&RB(n.tz);default:return!1}}function BB(e){if(!Array.isArray(e))return[];let t=e.filter(e=>{let t=e?.rule,n=t?.limits;return RB(e?.id)&&RB(e?.name)&&(e.parentId===null||RB(e.parentId))&&!!t&&zB(t.start,1)&&zB(t.end,1)&&(t.minHold_s===void 0||LB(t.minHold_s))&&(t.ignoreDips_s===void 0||LB(t.ignoreDips_s))&&(n===void 0||typeof n==`object`&&[`expectedWithin_s`,`min_s`,`max_s`].every(e=>n[e]===void 0||LB(n[e])))}),n=new Set(t.map(e=>e.id));return t.filter(e=>e.parentId===null||n.has(e.parentId)).map(e=>{let t=Array.isArray(e.kpis)?e.kpis.filter(e=>RB(e?.channel)&&aB.includes(e.stat)).slice(0,50):[],n=RB(e.show?.channel)&&aB.includes(e.show.stat)?{channel:e.show.channel,stat:e.show.stat}:void 0;return{id:e.id,name:e.name,parentId:e.parentId,rule:e.rule,...t.length?{kpis:t}:{},...n?{show:n}:{}}})}var VB=`Cycle time`,HB=65536;async function UB(e,t,n){let r=[...new Set([t,...n])],i=[];for(let n=0;;n+=HB){let a=await e.readColumns(r,n,HB),o=a[t]?.length??0;if(o>0&&i.push(a),o<HB)break}let a=e=>{if(!i.some(t=>t[e]))return;let n=new Float64Array(i.reduce((e,n)=>e+n[t].length,0)).fill(NaN),r=0;for(let a of i)a[e]&&n.set(a[e],r),r+=a[t].length;return n},o=new Map;for(let e of r){let n=e===t?void 0:a(e);n&&o.set(e,n)}return{t:a(t)??new Float64Array,cols:o}}function WB(e,t){let n=new FB(t);return[...n.feed(e.t,t=>e.cols.get(t)),...n.open()]}var GB=e=>[...new Set(e.flatMap(e=>[...NB(e.rule),...(e.kpis??[]).map(e=>e.channel)]))],KB=e=>`${e.channel} ${e.stat}`;function qB(e,t,n){let r=JB(e.t,t.tstart),i=t.tend===null?e.t.length:JB(e.t,t.tend),a={};for(let t of n){let n=e.cols.get(t.channel),o=new vB;if(n)for(let t=r;t<i;t++)o.add(e.t[t],n[t]);a[KB(t)]=o.value(t.stat)}return a}function JB(e,t){let n=0,r=e.length;for(;n<r;){let i=n+r>>1;e[i]<t?n=i+1:r=i}return n}function YB(e,t,n){let r=JB(e.t,n.tstart),i=n.tend===null?e.t.length:JB(e.t,n.tend),a=e.t.subarray(r,i),o={[VB]:a.map(e=>e-n.tstart),[t]:a};for(let[t,n]of e.cols)o[t]=n.subarray(r,i);return o}var XB=e=>e.replace(`-`,` `);function ZB(e,t,n,r){let i=Object.fromEntries(n.map(e=>[e.id,e.name])),a=e=>n.find(t=>t.id===e)?.kpis??[],o=e=>r?qB(r,e,a(e.definitionId)):{},s=n.filter(e=>e.parentId===t).map(e=>e.id),c=e=>e.tend===null?null:e.tend-e.tstart,l=e.filter(e=>s.includes(e.definitionId)).sort((e,t)=>e.tstart-t.tstart);return{cycles:e.filter(e=>e.definitionId===t).sort((e,t)=>e.index-t.index).map(e=>{let t=l.filter(t=>t.parentIndex===e.index),n={Cycle:e.index,Start:e.tstart,End:e.tend,Duration:c(e)};for(let e of s){let r=t.filter(t=>t.definitionId===e);n[`${i[e]??e} duration`]=r.length&&r.every(e=>e.tend!==null)?r.reduce((e,t)=>e+t.tend-t.tstart,0):null}return Object.assign(n,o(e)),n.Flags=[...e.flags.map(XB),...t.flatMap(e=>e.flags.map(t=>`${i[e.definitionId]??e.definitionId} ${XB(t)}`))].join(`, `),n}),phases:l.map(e=>({Cycle:e.parentIndex,Phase:i[e.definitionId]??e.definitionId,Start:e.tstart,End:e.tend,Duration:c(e),...o(e),Flags:e.flags.map(XB).join(`, `)}))}}function QB(e){if(e.length===0)return``;let t=Object.keys(e[0]),n=e=>e===null?``:typeof e==`number`?String(e):/[",\n]/.test(e)?`"${e.replace(/"/g,`""`)}"`:e;return[t.map(n).join(`,`),...e.map(e=>t.map(t=>n(e[t]??null)).join(`,`))].join(`
|
|
70
|
+
`)),r=V(n,t.headerRow).length,i=n.slice(t.dataStartRow);if(i.length===0)return Math.ceil(e/8);let a=n.slice(0,t.dataStartRow).reduce((e,t)=>e+t.length+1,0),o=i.reduce((e,t)=>e+t.length+1,0)/i.length;return Math.ceil(Math.max(0,e-a)/o)*r}catch{return Math.ceil(e/8)}}var hR=12e3;async function gR(e,n,r){let i=te(r),a=typeof Worker>`u`?t(r,i):await IE({rawText:r,config:i}),o=new BE(a);return{id:e,name:n,kind:`memory`,source:o,schema:await o.getSchema(),data:a,rawText:r,parseConfig:i}}async function _R(e,t,n,r,i=e=>e.text(),a){let o=te(r),s=typeof Worker>`u`?await LE({rawText:await i(n),config:o},a):await LE({file:n,config:o},a),c=new BE(s);return{id:e,name:t,kind:`memory`,source:c,schema:await c.getSchema(),data:s,rawText:r,file:n,parseConfig:o}}async function vR(e,t,n){let r=await uR.open(t,n),i=await r.getSchema(),a=await r.sampleRows(hR),o={meta:``,columnNames:i.map(e=>e.name),units:i.map(e=>e.unit),rows:a},s=await t.slice(0,fR).text();return{id:e,name:t.name,kind:`duckdb`,source:r,schema:i,data:o,rawText:s,parseConfig:te(s)}}async function yR(e,t,n,r,i=0,a){let o=await t.slice(0,fR).text();return pR(t.size,mR(t.size,o),i)===`memory`?_R(e,t.name,t,o,e=>n(e),a):vR(e,t,r)}function bR(e,t){return e instanceof File&&e.name===t.name&&e.size===t.size&&e.lastModified===t.lastModified}async function xR(e,t,n){let r=n.find(e=>e.kind===`memory`&&e.parseConfig&&bR(e.file,t)&&Ae(e.data.rows));if(!r)return null;let i=await t.slice(0,fR).text();if(!ne(r.parseConfig,te(i)))return null;let a={...r.data,rows:ze(Ae(r.data.rows))};return{id:e,name:t.name,kind:`memory`,source:new BE(a),schema:r.schema,data:a,rawText:r.rawText,file:t,parseConfig:r.parseConfig}}function SR(e){let t=new Set,n=0;for(let r of e){if(r.kind!==`memory`)continue;let e=Ae(r.data.rows)??r.data.rows;t.has(e)||(t.add(e),n+=r.data.rows.length*r.data.columnNames.length)}return n}var CR=4096,wR=[`.dat`,`.txt`,`.csv`,`.tsv`],TR=[w,Se,r,we,D,l,d],ER=e=>{let t=e.lastIndexOf(`.`);return t<=0?``:e.slice(t).toLowerCase()},DR=e=>{let t=e.lastIndexOf(`.`);return(t<=0?e:e.slice(0,t)).toLowerCase()};async function OR(e){let t=new Uint8Array(await e.slice(0,CR).arrayBuffer()),n=ER(e.name),r=TR.filter(e=>e.extensions.includes(n));for(let n of[...r,...TR.filter(e=>!r.includes(e))])if(n.sniff(t,e.name))return n;return null}async function kR(e){return new Uint8Array(await e.slice(0,CR).arrayBuffer()).includes(0)}async function AR(e){let t=await Promise.all(e.map(OR)),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]&&ER(e.name)===n.ext),o=a.find(e=>DR(e.name)===DR(i.main.name))??(n.anyName&&a.length===1?a[0]:void 0);o&&(i.companions.push(o),r.add(o))}let i=new Set(TR.flatMap(e=>(e.companions??[]).map(e=>e.ext))),a=[];for(let t of e){if(r.has(t))continue;let e=ER(t.name);e===`.dat`&&await kR(t)?a.push({file:t.name,error:Error(`This COMTRADE .dat needs its .cfg file — drop both together.`)}):wR.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 jR=[...new Set([...wR,...TR.flatMap(e=>[...e.extensions,...(e.companions??[]).map(e=>e.ext)])])];function MR(e){let t=0;for(let n=0;n<e.length;n++)e[n]!==e[n]&&t++;if(t===0)return XM(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 XM(wM({type:new kk,data:e,nullBitmap:n,length:e.length,nullCount:t}))}var NR=122880,PR=class{#e;#t;#n;#r=!1;#i=[];#a=0;#o;rows=0;constructor(e,t,n,r=NR){this.#e=e,this.#t=t,this.#n=new dN(n.map(e=>new fN(e.name,e.text?new Mk:new kk,!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?MR(i.subarray(0,t)):oF(i.slice(0,t),new Mk)).data[0]});this.#i.push(new gF(this.#n,wM({type:new Uk(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 pF(this.#n,this.#i);this.#i=[],this.#a=0,await this.#e.insertArrowTable(e,{name:this.#t,create:!this.#r}),this.#r=!0}},FR=`This file's groups do not interleave in time: reading them together would hold too much in memory. Choose fewer groups, or split them.`,IR=e=>e.length*(1+e.columns.length);function LR(e){let t=e[Symbol.asyncIterator]();return{pull:async()=>{let e=await t.next();return e.done?null:e.value}}}function RR(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-=IR(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+=IR(o.value))>128e6))throw Error(FR)}};return n.map((e,t)=>({pull:()=>a(t)}))}function zR(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 BR=new Int32Array,VR={t:new Float64Array,cols:[],from:0};function HR(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 UR=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=WR(zR(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(FR)}};function WR(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 GR(e,t){let n=e.length,r=e.map(e=>e.t),i=Int32Array.from(e,e=>e.from),a=Int32Array.from(e,e=>HR(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 KR(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 qR(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];KR(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}KR(e,d,u,p,l-1,c[p]),o=c[l-1],t=d[u+l-1]}e.fill(t,o,e.length)}function JR(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 YR(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):BR}function XR(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=HR(i,e,r.from,i.length),o=new Int32Array(a-r.from);if(c.push(YR(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 JR(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),qR(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 ZR(e,t,n,r,i,a=!1){let o=e.map((e,r)=>new UR(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=GR(l.map(e=>e.pending[0]??VR),e),n=[t];for(let e=0;e<o.length;e++)n.push(...XR(o[e],t,c[e],u&&c[e],a));d+=t.length,t.length&&await r({length:t.length,columns:n})}return d}var QR=class{#e;#t;#n;#r=0;constructor(e,t){let n=Math.max(1024,t);this.#e=e.map(e=>e.name),this.#t=e.map(()=>new Float64Array(n)),this.#n=e.map(()=>null)}append(e){let t=this.#r,n=t+e.length;if(n>this.#t[0].length){let e=Math.max(n,Math.ceil(this.#t[0].length*1.5));this.#t=this.#t.map(n=>{let r=new Float64Array(e);return r.set(n.subarray(0,t)),r})}e.columns.forEach((n,r)=>{let i=this.#t[r];if(n instanceof Float64Array){i.set(n.subarray(0,e.length),t);return}let a=this.#n[r];for(let o=0;o<e.length;o++){i[t+o]=NaN;let e=n[o];e!=null&&((a??=this.#n[r]=[])[t+o]=e)}}),this.#r=n}table(){let e=this.#r,t=this.#t.map(t=>t.length-e>t.length/100?t.slice(0,e):t.subarray(0,e));return{keys:this.#e,length:e,values:t,text:this.#n}}};async function $R(e,t,n){return s(await e.plan(t,n))}var ez=(e,t,n)=>Math.max(0,Math.min(e,Math.max(1<<20,n),Math.floor(1e8/t)));function tz(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=se(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 nz(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 rz(e,t,n){let r=nz(e,t);return r<0?Math.ceil(n/4):r*(1+t.reduce((e,t)=>e+t.channels.length,0))}async function iz(e,t,n,r,i,a,o={}){let s=tz(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=>LR(d(e.streamGroup({...f,selection:[t]},t.group)))):RR(d(e.stream(f)),new Map(i.map((e,t)=>[e.group,t]))),m=nz(n,i),h=a===`memory`?new QR(s,ez(m,s.length,r.size)):null,g=0,_=await ZR(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 az=``+new URL(`assets/importer.worker-Cgz__4KO.js`,import.meta.url).href,oz=``+new URL(`assets/h5wasmModule-BCQWU2Gw.js`,import.meta.url).href,sz=()=>new ME(`cancelled`);function cz(){let e=NE(az);return e.postMessage({type:`init`,h5Url:new URL(oz,location.href).href}),e}var lz=null,uz=e=>{typeof requestIdleCallback==`function`?requestIdleCallback(e,{timeout:5e3}):setTimeout(e,1e3)};function dz(e,t=cz){t===cz&&typeof Worker>`u`||(lz&&lz.make!==t&&(lz.w.terminate(),lz=null),lz??={w:t(),h5:!1,make:t},e&&!lz.h5&&(lz.h5=!0,lz.w.postMessage({type:`warm`})))}function fz(e){if(lz?.make!==e)return{w:e(),rewarm:null};let{w:t,h5:n}=lz;return lz=null,{w:t,rewarm:n}}function pz(e,t,n,r,i){return!r&&typeof Worker>`u`?mz(e,t,n,i):gz(e,t,n,r??cz)}function mz(e,t,n,r=async e=>(await import(`./importers-D_M42sqZ.js`)).importerFor(e)){let i=new Je(t.main),a=null,o=null,s=e=>e.catch(e=>{throw n?.aborted?sz():Xe(e)});return{plan:()=>s((async()=>(a=await r(e),o=await $R(a,t,i)))()),read:(e,r,c={})=>(i.bytesRead=0,s(iz(a,t,o,i,e,r,{...c,signal:n}))),close(){}}}var hz=3e4;function gz(e,t,n,r){let{w:i,rewarm:a}=fz(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>hz&&p(Error(Qe))},1e3),h=()=>p(sz());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(sz());return}if(d){a(Error(Qe));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&&uz(()=>dz(a,r))}}}var _z=12e3,vz=(e,t)=>t.map(t=>({group:t,channels:e.groups[t].channels.map((e,t)=>t)}));function yz(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 bz(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:yz(e,n)}:null,splitKey:r,channels:n.reduce((e,t)=>e+t.channels.length,0),notes:e.notes,meta:e.meta,events:[]}}async function xz(e,t,n,r,i,a){let o={meta:``,columnNames:n.columns.map(e=>e.name),units:n.columns.map(e=>e.unit),rows:ze(n.table)},s=new BE(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 Sz(e,t,n,r,i,a,o,s,c){let l=BL().then(e=>e.connect());l.catch(()=>void 0);let u=iR(),d=tz(r,i),f=new PR({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 uR.attach(p,u,new Map(d.map(e=>[e.name,e.unit]))),h=await m.getSchema(),g=await m.sampleRows(_z);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 ${UL(u)}`).catch(()=>void 0),await t?.close().catch(()=>void 0),e}}async function Cz(e,t){let{main:n,companions:r}=e,i=pz(e.format,{main:n,companions:r,keys:e.keys},t.signal,t.createWorker,t.find),a=[];try{t.priorInMemoryValues+n.size/8>1e8&&BL().catch(()=>void 0);let o=await i.plan(),s=t.selection??t.initial??vz(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=>rz(o,e,n.size),budget:dR,used:t.priorInMemoryValues,notes:o.notes});if(!e)throw new ME(`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=rz(o,s,n.size),f=l.length>1?`${n.name} · ${o.groups[s[0].group].name}`:n.name,p=bz(o,e.format,s,u),m=crypto.randomUUID();if(pR(0,c,d)===`memory`){let e=await i.read(s,`memory`,{progress:t.onProgress});a.push(await xz(m,f,e,n,r,p)),d+=c}else a.push(await Sz(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 ME(`cancelled`):e}finally{i.close()}}function wz(e){return e.filter(e=>e.type===`number`).map(e=>e.name)}function Tz(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 Ez(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`camera`:return 0;case`heatmap`:return e.hmColumns.length;case`xyzmesh`:return e.xyzColumns?.length??0;default:return 0}}function Dz(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 Oz(e){return Math.max(2,Math.min(6,Math.floor(e/64)))}function kz(e,t,n,r){let i=Math.max(e,t)-Math.min(e,t),a=n!==void 0&&n>0&&Number.isFinite(n)?n:Dz(i,6);(a<=0||!Number.isFinite(a))&&(a=Dz(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 Az(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 jz(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 Mz={[-12]:`p`,[-9]:`n`,[-6]:`µ`,[-3]:`m`,0:``,3:`k`,6:`M`,9:`G`,12:`T`};function Nz(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 Pz(e,t){if(!Number.isFinite(e))return`—`;if(!(t>0)||!Number.isFinite(t))return Fz(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(Nz(t/10**r))+Mz[r]}return e.toFixed(Nz(t))}function Fz(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)+Mz[n]}var Iz=946684800,Lz=4102444800;function Rz(e,t,n){return/\(([^)]*)\)\s*$/.exec(e)?.[1].trim()===`s`&&n>t&&t>=Iz&&n<=Lz}var zz=new Map;function Bz(e){let t=zz.get(e);if(!t){let n={day:`numeric`,month:`short`,year:`numeric`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`,hourCycle:`h23`};try{t=new Intl.DateTimeFormat(`en-GB`,{...n,timeZone:e})}catch{t=Bz(void 0)}zz.set(e,t)}return t}var Vz=new Map,Hz=(e,t)=>{let n=Math.round(e*1e3),r=Math.floor(n/1e3),i=`${t??``}|${r}`,a=Vz.get(i);if(!a){let e={};for(let{type:n,value:i}of Bz(t).formatToParts(r*1e3))e[n]=i;let n=`${e.hour}:${e.minute}`;a={date:`${e.day} ${e.month}`,year:e.year,hm:n,hms:`${n}:${e.second}`},Vz.size>=1024&&Vz.clear(),Vz.set(i,a)}return{...a,ms:String(n-r*1e3).padStart(3,`0`)}},Uz,Wz=new Set;function Gz(e){if(e!==void 0)try{new Intl.DateTimeFormat(void 0,{timeZone:e})}catch{e=void 0}if(e!==Uz){Uz=e;for(let e of Wz)e()}}var Kz=()=>Uz;function qz(e){return Wz.add(e),()=>{Wz.delete(e)}}function Jz(e,t,n,r=Uz){let i=Hz(e,r);return t>=86400?i.date:n>86400?`${i.date} ${i.hm}`:t>=60?i.hm:t>=1?i.hms:`${i.hms}.${i.ms}`}function Yz(e,t=Uz){let n=Hz(e,t);return`${n.date} ${n.year} ${n.hms}.${n.ms}`}var Xz=[`#fb923c`,`#60a5fa`,`#4ade80`,`#f87171`,`#facc15`,`#22d3ee`,`#f472b6`,`#2dd4bf`,`#94a3b8`,`#a3e635`];function Zz(e,t,n,r=Xz){let i=r.length>0?r:Xz;return e[t]??i[n%i.length]}function Qz(e){return[e===`light`?`#000000`:`#ffffff`,...Xz.slice(0,9)]}function $z(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:Qz(t)}var eB=[`class`,`data-theme`,`data-color-scheme`];function tB(e){return e?.closest(`[data-color-scheme]`)??document.documentElement}function nB(e){return tB(e).getAttribute(`data-color-scheme`)===`light`?`light`:`dark`}function rB(e,t){let n=new MutationObserver(t),r=new Set([document.documentElement,tB(e)]);for(let e of r)n.observe(e,{attributes:!0,attributeFilter:eB});return()=>n.disconnect()}function iB(e,t){return!!t&&e.composedPath().includes(t)}var aB=[`min`,`max`,`mean`,`integral`,`first`,`last`,`delta`],oB=e=>`${e.channel}:${e.stat}`,sB=e=>`channel`in e?[e.channel]:[];function cB(e,t,n){switch(e){case`>`:return t>n;case`>=`:return t>=n;case`<`:return t<n;case`<=`:return t<=n;case`==`:return t===n;default:return t!==n}}function lB(e,t,n,r){switch(e){case`>`:case`>=`:return t<n-r;case`<`:case`<=`:return t>n+r;case`==`:return t!==n;default:return t===n}}var uB=()=>({prev:NaN,lo:0,hi:0});function dB(e,t){if(e.prev!==e.prev)return e.prev=e.lo=e.hi=t,!1;let n=t<e.prev&&e.prev-t>(e.hi-e.lo)/2;return n?e.lo=e.hi=t:(t<e.lo&&(e.lo=t),t>e.hi&&(e.hi=t)),e.prev=t,n}var fB=new Map,pB=e=>{let t=fB.get(e);return t||(t=new Intl.DateTimeFormat(`en-US`,{timeZone:e,hourCycle:`h23`,year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`}),fB.set(e,t)),t};function mB(e,t){let n={};for(let r of pB(t).formatToParts(new Date(Math.floor(e)*1e3)))n[r.type]=r.value;return(Date.UTC(+n.year,n.month-1,+n.day,+n.hour,+n.minute,+n.second)-Math.floor(e)*1e3)/1e3}function hB(e,t){let n=e+mB(e,t);return new Date(Math.floor(n)*1e3).toISOString().slice(0,10)}function gB(e,t,n){let[r,i,a]=e.split(`-`).map(Number),[o,s]=t.split(`:`).map(Number),c=Date.UTC(r,i-1,a,o,s)/1e3;return c-mB(c-mB(c,n),n)}var _B=(e,t)=>{let[n,r,i]=e.split(`-`).map(Number);return new Date(Date.UTC(n,r-1,i+t)).toISOString().slice(0,10)},vB=class{n=0;sum=0;min=1/0;max=-1/0;first=NaN;last=NaN;integral=0;lastT=NaN;add(e,t){t===t&&(this.n>0?this.integral+=(t+this.last)/2*(e-this.lastT):this.first=t,this.n++,this.sum+=t,t<this.min&&(this.min=t),t>this.max&&(this.max=t),this.last=t,this.lastT=e)}value(e){if(this.n===0)return null;switch(e){case`min`:return this.min;case`max`:return this.max;case`mean`:return this.sum/this.n;case`integral`:return this.integral;case`first`:return this.first;case`last`:return this.last;default:return this.last-this.first}}},yB=class{rule;kpis;#e;#t=null;#n=NaN;#r=uB();#i=!1;#a=NaN;#o=NaN;#s=NaN;#c=new Map;constructor(e,t=[]){this.rule=e,this.kpis=t,this.#e=[...new Set(t.map(e=>e.channel))]}#l(e){this.#t={tstart:e,acc:new Map(this.#e.map(e=>[e,new vB]))}}#u(e,t,n){let r={duration:(t??n)-e.tstart};for(let t of this.kpis)r[oB(t)]=e.acc.get(t.channel).value(t.stat);return{tstart:e.tstart,tend:t,kpis:r}}#d(e){let t=this.#t;return this.#t=null,t?this.#u(t,e,e):null}assumeOpen(e){this.#t||(this.#l(e),this.rule.kind===`condition`&&(this.#i=!0))}#f(e){let t=this.#c.get(e);if(!t){let n=this.rule;t=n.starts.map(t=>gB(e,t,n.tz)).sort((e,t)=>e-t),this.#c.set(e,t)}return t}#p(e){let t=this.rule.tz,n=hB(e,t),r=-1/0;for(let t of this.#f(n))t<=e&&(r=t);if(r>-1/0)return r;let i=this.#f(_B(n,-1));return i[i.length-1]}#m(e){let t=this.rule.tz,n=hB(e,t);for(let t of this.#f(n))if(t>e)return t;return this.#f(_B(n,1))[0]}feed(e,t,n){let r=[],i=this.rule,a=i.kind===`edge`||i.kind===`condition`?t(i.channel):void 0,o=this.#e.map(e=>[e,t(e)]);for(let t=0;t<e.length;t++){let s=e[t];if(i.kind===`window`){if(!(s>=this.#a&&s<this.#o)){let e=this.#p(s);if(this.#t){let t=this.#d(this.#o<=e?this.#o:e);t&&r.push(t)}this.#a=e,this.#o=this.#m(e),this.#l(e)}}else if(a&&i.kind!==`manual`){let e=a[t];if(e===e){if(i.kind===`edge`){let t=!1;if(i.on===`reset`){let n=this.#r.prev!==this.#r.prev;t=dB(this.#r,e),n&&!this.#t&&this.#l(s)}else if(this.#n===this.#n){let n=i.value??0;t=i.on===`change`?e!==this.#n:i.on===`rise`?this.#n<n&&e>=n:this.#n>n&&e<=n}if(this.#n=e,t){let e=this.#d(s);e&&r.push(e),this.#l(s)}}else if(!this.#i)cB(i.op,e,i.value)&&(this.#i=!0,this.#l(s));else if(lB(i.op,e,i.value,i.hysteresis??0)){this.#i=!1;let e=this.#d(s);e&&s-e.tstart>=(i.min_s??0)&&r.push(e)}}}let c=this.#t;if(c)for(let[e,n]of o)n&&c.acc.get(e).add(s,n[t]);this.#s=s,n?.(t,c?c.tstart:null)}return r}open(){let e=this.#t;return!e||this.rule.kind===`condition`&&this.#s-e.tstart<(this.rule.min_s??0)?null:this.#u(e,null,this.#s)}},bB=[{value:`span`,label:`Span (max − min)`},{value:`mean`,label:`Mean`},{value:`max`,label:`Max`},{value:`min`,label:`Min`}];function xB(e,t){let n=[],r=uB(),i=-1;for(let a=0;a<e.length;a++){let o=e[a][t];if(typeof o!=`number`)continue;let s=dB(r,o);i<0?i=0:s&&(n.push({start:i,end:a}),i=a)}return i>=0&&n.push({start:i,end:e.length}),n}function SB(e,t){let n=[],r=e.length-1,i=Math.max(1,Math.floor(e.length/256)),a=t=>{let n=0,r=0,a=0;for(let o=0;o+1<e.length;o+=i){let i=e[o][t],s=e[o+1][t];typeof i!=`number`||typeof s!=`number`||(n++,s<i?r++:s===i&&a++)}return n<32||r<=.3*n&&a<=.9*n};for(let o of t){if(i>1&&!a(o))continue;let t=0,s=0,c=0,l=null,u=!1;for(let n of e){let e=n[o];if(typeof e==`number`){if(l!==null&&(c++,e>l?t++:e===l&&s++,c-t-s>.1*r||s>.5*r)){u=!0;break}l=e}}if(u||c===0||(t+s)/c<.9||t/c<.5)continue;let d=xB(e,o).length;d>1&&n.push({col:o,laps:d})}return n.sort((e,t)=>t.laps-e.laps).map(e=>e.col)}function CB(e,t){return SB(e,t)[0]??t[0]??``}function wB(e,t,n){if(n&&t.includes(n.channel)&&xB(e,n.channel).length>1)return{...n,metric:t.includes(n.metric)?n.metric:n.channel};let r=SB(e,t);if(r.length===0)return null;let i=r.find(e=>/time/i.test(e));return{channel:r[0],metric:i??r[0],stat:`span`}}function TB(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 EB(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 DB(e,t){return t.trim()===`s`||/time/i.test(e)}function OB(e,t,n){if(e===null)return`—`;if(n&&e>=0){let t=Math.round(e*1e3),n=Math.floor(t/6e4);return`${n}:${((t-n*6e4)/1e3).toFixed(3).padStart(6,`0`)}`}let r=Math.abs(e),i=r!==0&&r<.01?Fz(e):e.toFixed(r>=1e3?0:r>=100?1:3);return t.trim()?`${i} ${t.trim()}`:i}function kB(e,t){return`${e}::lap${t}`}function AB(e){let t=new Map,n=n=>{let r=t.get(n);return r||t.set(n,r=e.at.map(t=>gB(n,t,e.tz)).sort((e,t)=>e-t)),r},r=t=>{let r=hB(t,e.tz),i=-1/0;for(let e of n(r))e<=t&&(i=e);if(i>-1/0)return i;let a=n(_B(r,-1));return a[a.length-1]},i=t=>{let r=hB(t,e.tz);for(let e of n(r))if(e>t)return e;return n(_B(r,1))[0]},a=NaN,o=NaN,s={on:!1,edge:!1,at:NaN,event:!0,step(e){if(s.edge=s.on=!(e.t>=a&&e.t<o),!s.edge)return;let t=r(e.t);s.closeAt=o<=t?o:t,s.at=a=t,o=i(t)}};return s}function jB(e){switch(e.kind){case`compare`:{let t={on:!1,edge:!1,at:NaN,event:!1,step(n){let r=n.v(e.channel);r===r&&(t.on=cB(e.op,r,e.value)),t.at=n.t}};return t}case`elapsed`:{let t={on:!1,edge:!1,at:NaN,event:!1,step(n){let r=n.t-(e.from===`start`?n.start:n.ps);t.on=r===r&&(e.op===`>=`?r>=e.seconds:r<=e.seconds),t.at=n.t}};return t}case`change`:case`cross`:{let t=NaN,n={on:!1,edge:!1,at:NaN,event:!0,step(r){let i=r.v(e.channel);n.edge=!1,i===i&&(t===t&&(n.edge=e.kind===`change`?i!==t:e.dir===`rise`?t<e.value&&i>=e.value:t>e.value&&i<=e.value),t=i),n.on=n.edge,n.at=r.t}};return n}case`reset`:{let t=uB(),n={on:!1,edge:!1,at:NaN,event:!0,step(r){let i=r.v(e.channel);n.edge=i===i&&(t.prev===t.prev?dB(t,i):(dB(t,i),!0)),n.on=n.edge,n.at=r.t}};return n}case`clock`:return AB(e);case`parent-start`:{let e=!1,t={on:!1,edge:!1,at:NaN,event:!0,step(n){t.on=t.edge=!e,e=!0,t.at=n.ps}};return t}case`all`:case`any`:{let t=e.of.map(jB),n={on:!1,edge:!1,at:NaN,event:t.some(e=>e.event),step(r){for(let e of t)e.step(r);n.on=e.kind===`all`?t.every(e=>e.on):t.some(e=>e.on),n.edge=n.on&&t.some(e=>e.edge),n.at=r.t}};return n}default:return{on:!1,edge:!1,at:NaN,event:!0,step(){}}}}var MB=(e,t)=>e.kind===t||(e.kind===`all`||e.kind===`any`)&&e.of.some(e=>MB(e,t));function NB(e){let t=new Set,n=e=>{`channel`in e&&t.add(e.channel),(e.kind===`all`||e.kind===`any`)&&e.of.forEach(n)};return n(e.start),n(e.end),[...t]}var PB=class{rule;#e;#t;#n=NaN;#r=!1;#i=NaN;#a=NaN;#o=NaN;#s=NaN;#c;#l;constructor(e){this.rule=e,this.#c=MB(e.end,`parent-end`),this.#l=e.end.kind===`next-start`,this.#u()}#u(){this.#e=jB(this.rule.start),this.#t=jB(this.rule.end),this.#r=!1}#d(e,t,n){let r=this.rule.limits;if(!r)return[];let i=[],a=r.from===`start`?e:this.#n;return r.expectedWithin_s!=null&&t-a>r.expectedWithin_s&&i.push(`late`),r.max_s!=null&&t-e>r.max_s&&i.push(`too-long`),n&&r.min_s!=null&&t-e<r.min_s&&i.push(`too-short`),i}#f(e,t,n=!1){let r={tstart:this.#i,tend:e,flags:this.#d(this.#i,e,!0)};n&&(r.incomplete=!0),t.push(r),this.#i=this.#o=NaN}parentStart(e){this.#n=e,this.#i=this.#a=this.#o=NaN,this.#u()}parentEnd(e,t){this.#i===this.#i&&this.#f(e,t,!this.#c),this.#a=NaN,this.#n=NaN}step(e,t,n){this.#n!==this.#n&&(this.#n=e);let r={t:e,v:t,ps:this.#n,start:this.#i},i=this.#e,a=this.#t;i.step(r),a.step(r);let o=i.on&&(!this.#r||i.edge);this.#r=i.on;let s=i.event&&!(this.rule.start.kind===`all`||this.rule.start.kind===`any`)?i.at:e;if(this.#i===this.#i&&!this.#l&&e>this.#i){let t=this.rule.ignoreDips_s??0;a.on?t>0&&!a.event?(this.#o!==this.#o&&(this.#o=e),e-this.#o>=t&&this.#f(this.#o,n)):this.#f(e,n):this.#o=NaN}let c=e=>{this.#i===this.#i&&this.#f(this.#l&&i.closeAt!==void 0?i.closeAt:e,n),this.#i=e},l=this.#i!==this.#i||this.#l,u=this.rule.minHold_s??0;this.#a===this.#a?i.on?e-this.#a>=u&&(l&&c(this.#a),this.#a=NaN):this.#a=NaN:o&&l&&(u>0&&!i.event?this.#a=s:c(s)),this.#s=e}open(){return this.#i===this.#i?{tstart:this.#i,tend:null,flags:this.#d(this.#i,this.#s,!1)}:null}},FB=class{#e;constructor(e){let t=[],n=r=>{for(let i of e)i.parentId===r&&(t.push(i),n(i.id))};n(null),this.#e=t.map(e=>({...e,runner:new PB(e.rule),count:0,current:0,kids:[]})),this.#e.forEach((e,t)=>{e.parentId&&this.#e.find(t=>t.id===e.parentId).kids.push(t)})}#t(e,t,n,r){let i=this.#e[e];for(let e of t)n.push({...e,definitionId:i.id,index:i.current,...r?{parentIndex:r}:{}})}#n(e){let t=this.#e[e].parentId;return t?this.#e.find(e=>e.id===t).current:void 0}#r(e,t,n){for(let r of this.#e[e].kids){this.#r(r,t,n);let i=[];this.#e[r].runner.parentEnd(t,i),this.#t(r,i,n,this.#e[e].current)}}#i(e,t,n,r){let i=this.#e[e],a=i.runner.open()?.tstart,o=[];i.runner.step(t,n,o);let s=i.runner.open()?.tstart;if(o.length)for(let t of o)this.#r(e,t.tend,r),r.push({...t,definitionId:i.id,index:i.current,...this.#n(e)?{parentIndex:this.#n(e)}:{}});if(s!==void 0&&s!==a){i.current=++i.count;for(let e of i.kids)this.#e[e].current=this.#e[e].count=0,this.#e[e].runner.parentStart(s)}if(s!==void 0)for(let e of i.kids)this.#i(e,t,n,r)}feed(e,t){let n=new Map,r=e=>(n.has(e)||n.set(e,t(e)),n.get(e)),i=[],a=0,o=e=>{let t=r(e);return t?t[a]:NaN};for(;a<e.length;a++)for(let t=0;t<this.#e.length;t++)this.#e[t].parentId||this.#i(t,e[a],o,i);return i}open(){let e=[];return this.#e.forEach((t,n)=>{let r=t.runner.open(),i=this.#n(n);r&&(!t.parentId||this.#e.find(e=>e.id===t.parentId).runner.open())&&e.push({...r,definitionId:t.id,index:t.current,...i?{parentIndex:i}:{}})}),e}},IB=new Set([`>`,`>=`,`<`,`<=`,`==`,`!=`]),LB=e=>typeof e==`number`&&Number.isFinite(e),RB=e=>typeof e==`string`&&e.length>0;function zB(e,t){let n=e;if(!n||typeof n!=`object`)return!1;switch(n.kind){case`parent-start`:case`parent-end`:case`next-start`:case`manual`:return!0;case`all`:case`any`:return t<3&&Array.isArray(n.of)&&n.of.length>0&&n.of.every(e=>zB(e,t+1));case`compare`:return RB(n.channel)&&IB.has(n.op)&&LB(n.value);case`change`:case`reset`:return RB(n.channel);case`cross`:return RB(n.channel)&&(n.dir===`rise`||n.dir===`fall`)&&LB(n.value);case`elapsed`:return(n.from===`parent-start`||n.from===`start`)&&(n.op===`>=`||n.op===`<=`)&&LB(n.seconds);case`clock`:return Array.isArray(n.at)&&n.at.length>0&&n.at.every(e=>typeof e==`string`&&/^\d\d:\d\d$/.test(e))&&RB(n.tz);default:return!1}}function BB(e){if(!Array.isArray(e))return[];let t=e.filter(e=>{let t=e?.rule,n=t?.limits;return RB(e?.id)&&RB(e?.name)&&(e.parentId===null||RB(e.parentId))&&!!t&&zB(t.start,1)&&zB(t.end,1)&&(t.minHold_s===void 0||LB(t.minHold_s))&&(t.ignoreDips_s===void 0||LB(t.ignoreDips_s))&&(n===void 0||typeof n==`object`&&[`expectedWithin_s`,`min_s`,`max_s`].every(e=>n[e]===void 0||LB(n[e])))}),n=new Set(t.map(e=>e.id));return t.filter(e=>e.parentId===null||n.has(e.parentId)).map(e=>{let t=Array.isArray(e.kpis)?e.kpis.filter(e=>RB(e?.channel)&&aB.includes(e.stat)).slice(0,50):[],n=RB(e.show?.channel)&&aB.includes(e.show.stat)?{channel:e.show.channel,stat:e.show.stat}:void 0;return{id:e.id,name:e.name,parentId:e.parentId,rule:e.rule,...t.length?{kpis:t}:{},...n?{show:n}:{}}})}var VB=`Cycle time`,HB=65536;async function UB(e,t,n){let r=[...new Set([t,...n])],i=[];for(let n=0;;n+=HB){let a=await e.readColumns(r,n,HB),o=a[t]?.length??0;if(o>0&&i.push(a),o<HB)break}let a=e=>{if(!i.some(t=>t[e]))return;let n=new Float64Array(i.reduce((e,n)=>e+n[t].length,0)).fill(NaN),r=0;for(let a of i)a[e]&&n.set(a[e],r),r+=a[t].length;return n},o=new Map;for(let e of r){let n=e===t?void 0:a(e);n&&o.set(e,n)}return{t:a(t)??new Float64Array,cols:o}}function WB(e,t){let n=new FB(t);return[...n.feed(e.t,t=>e.cols.get(t)),...n.open()]}var GB=e=>[...new Set(e.flatMap(e=>[...NB(e.rule),...(e.kpis??[]).map(e=>e.channel)]))],KB=e=>`${e.channel} ${e.stat}`;function qB(e,t,n){let r=JB(e.t,t.tstart),i=t.tend===null?e.t.length:JB(e.t,t.tend),a={};for(let t of n){let n=e.cols.get(t.channel),o=new vB;if(n)for(let t=r;t<i;t++)o.add(e.t[t],n[t]);a[KB(t)]=o.value(t.stat)}return a}function JB(e,t){let n=0,r=e.length;for(;n<r;){let i=n+r>>1;e[i]<t?n=i+1:r=i}return n}function YB(e,t,n){let r=JB(e.t,n.tstart),i=n.tend===null?e.t.length:JB(e.t,n.tend),a=e.t.subarray(r,i),o={[VB]:a.map(e=>e-n.tstart),[t]:a};for(let[t,n]of e.cols)o[t]=n.subarray(r,i);return o}var XB=e=>e.replace(`-`,` `);function ZB(e,t,n,r){let i=Object.fromEntries(n.map(e=>[e.id,e.name])),a=e=>n.find(t=>t.id===e)?.kpis??[],o=e=>r?qB(r,e,a(e.definitionId)):{},s=n.filter(e=>e.parentId===t).map(e=>e.id),c=e=>e.tend===null?null:e.tend-e.tstart,l=e.filter(e=>s.includes(e.definitionId)).sort((e,t)=>e.tstart-t.tstart);return{cycles:e.filter(e=>e.definitionId===t).sort((e,t)=>e.index-t.index).map(e=>{let t=l.filter(t=>t.parentIndex===e.index),n={Cycle:e.index,Start:e.tstart,End:e.tend,Duration:c(e)};for(let e of s){let r=t.filter(t=>t.definitionId===e);n[`${i[e]??e} duration`]=r.length&&r.every(e=>e.tend!==null)?r.reduce((e,t)=>e+t.tend-t.tstart,0):null}return Object.assign(n,o(e)),n.Flags=[...e.flags.map(XB),...t.flatMap(e=>e.flags.map(t=>`${i[e.definitionId]??e.definitionId} ${XB(t)}`))].join(`, `),n}),phases:l.map(e=>({Cycle:e.parentIndex,Phase:i[e.definitionId]??e.definitionId,Start:e.tstart,End:e.tend,Duration:c(e),...o(e),Flags:e.flags.map(XB).join(`, `)}))}}function QB(e){if(e.length===0)return``;let t=Object.keys(e[0]),n=e=>e===null?``:typeof e==`number`?String(e):/[",\n]/.test(e)?`"${e.replace(/"/g,`""`)}"`:e;return[t.map(n).join(`,`),...e.map(e=>t.map(t=>n(e[t]??null)).join(`,`))].join(`
|
|
71
71
|
`)}var $B=(e,t,n)=>`kymoscope-workbook-export|3|${e}|${t??``}|${n??``}`,eV=e=>new TextEncoder().encode(e);async function tV(e,t){return{format:`kymoscope-workbook`,v:2,...await Ne(t,eV(JSON.stringify(e)),T)}}async function nV(e,t){let n=t.password?JSON.stringify(await tV(e,t.password)):JSON.stringify(e),r=await ae(await p(t.key),eV(n),$B(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 rV(e){return!!e&&typeof e==`object`&&e.format===`kymoscope-workbook`}function iV(e){return rV(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 aV=e=>{try{return JSON.parse(new TextDecoder().decode(e))}catch{throw new ME(`bad_file`)}};async function oV(e,t){let n=iV(e);if(!n)throw new ME(`bad_file`);let r=e;if(n.v===3){let i=e;if(!t.key)throw new ME(`scope_key_required`,{scope:n.scope,scopeId:n.scopeId});let a;try{a=await v(await p(t.key),i,$B(i.scope,i.scope_id,i.inner))}catch{throw new ME(`bad_file`)}if(r=aV(a),!n.password)return r;if(r?.v!==2||!rV(r))throw new ME(`bad_file`)}if(!t.password)throw new ME(`password_required`);let i;try{i=await ee(t.password,r,T)}catch{throw new ME(`wrong_password`)}return aV(i)}var sV=new Set(Object.keys(Wt));function cV(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`||!sV.has(n)||!r||![r.x,r.y,r.w,r.h].every(e=>typeof e==`number`&&Number.isFinite(e))?[]:[{...e,rect:qt(n,r,96)}]}):[]}var lV=e=>({name:e.name,xKey:e.xKey,panels:e.panels,panelChartSettings:e.panelChartSettings,panelChartBackgrounds:e.panelChartBackgrounds,...e.liveWindowSeconds===void 0?{}:{liveWindowSeconds:e.liveWindowSeconds}});function uV(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 dV(e){return{version:2,worksheets:e.worksheets.map(e=>({...lV(e),panelChartSettings:uV(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,segments:e.segments??null,...e.cycles?.length?{cycles:e.cycles}:{}}}function fV(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,...e.liveWindowSeconds===void 0?{}:{liveWindowSeconds:e.liveWindowSeconds}}}}function pV(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 mV(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 hV(e){let t=await mV(e),n;try{n=JSON.parse(t)}catch{return{worksheets:[],errors:[`Not a valid JSON file.`]}}return xV(n)}var gV=new Set(bB.map(e=>e.value)),_V=/^(#(?:[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 vV(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):_V.test(e.trim())}function yV(e){if(Array.isArray(e))return e.map(yV);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`&&!vV(r)||(t[n]=r&&typeof r==`object`?yV(r):r);return t}function bV(e){return!e||typeof e!=`object`?{}:Object.fromEntries(Object.entries(e).filter(([,e])=>e===null||vV(e)))}function xV(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,segments:void 0,cycles:[]};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:cV(n.panels),panelChartSettings:yV(n.panelChartSettings),panelChartBackgrounds:bV(n.panelChartBackgrounds),...or(n.liveWindowSeconds)})}),n===1)return{worksheets:r,errors:i,activeIndex:0,mathChannels:[],liveWindowSeconds:void 0,laps:void 0,segments:void 0,cycles:[]};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`&&gV.has(s.stat)?{channel:s.channel,metric:s.metric,stat:s.stat}:null,l=t.segments,u=e=>typeof e==`string`&&/^[0-9a-f-]{36}$/i.test(e),d=l===void 0?void 0:l&&u(l.historyId)&&(l.definitionId==null||u(l.definitionId))&&(l.referenceId==null||u(l.referenceId))?{historyId:l.historyId,definitionId:l.definitionId??null,referenceId:l.referenceId??null}:null,f=typeof t.activeWorksheet==`number`&&Number.isInteger(t.activeWorksheet)?t.activeWorksheet:0;return{worksheets:r,errors:i,mathChannels:a,laps:c,segments:d,cycles:BB(t.cycles),activeIndex:Math.min(Math.max(0,f),Math.max(0,r.length-1)),liveWindowSeconds:o===null||typeof o==`number`&&o>0?o:void 0}}function SV(e){return e.some(e=>e.panels.length>0)}function CV(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:cV(t.panels),panelChartSettings:yV(t.panelChartSettings),panelChartBackgrounds:bV(t.panelChartBackgrounds),...or(t.liveWindowSeconds)}}function wV(e){if(!e||typeof e!=`object`)return null;let t=e,n=t.kind;if(typeof n!=`string`||!sV.has(n))return null;let r=ir({__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 TV(e){let t=await mV(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=iV(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=CV(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=wV(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 hV(e);return i.worksheets.length===0&&i.errors.length>0?{type:`error`,errors:i.errors}:{type:`workspace`,worksheets:i.worksheets,errors:i.errors}}var EV=jR;function DV(e){let t=e.toLowerCase();return!t.startsWith(`.`)&&EV.some(e=>t.endsWith(e))}function OV(e,t=``){let n={name:t,path:``,dirs:[],files:[],allPaths:[]};for(let t of e){if(!DV(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 kV(e){return e.map(e=>({path:e.webkitRelativePath||e.name,file:e}))}async function AV(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 jV(){return typeof window.showDirectoryPicker==`function`}async function MV(){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 NV={1:`dohstRIUBeOkkAXOTXhhEkXanWzz-V4M518JBqTehRM`};function PV(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 FV(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 IV(e){try{let t=JSON.parse(new TextDecoder().decode(PV(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 LV(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=IV(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`,PV(s),`Ed25519`,!1,[`verify`]);c=await crypto.subtle.verify(`Ed25519`,e,PV(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=>FV(e,t))?{ok:!0,sub:a.sub,exp:a.exp}:{ok:!1,reason:`domain`}:{ok:!1,reason:`bad_signature`}}function RV(e,t){return LV(e,t,NV,Date.now()/1e3)}var Q={sans:`system-ui, sans-serif`,mono:`ui-monospace, monospace`};function zV(e){let t=e.getTransform().a||1;e.font=`13px ${Q.sans}`,e.textAlign=`center`,e.textBaseline=`middle`,e.fillText(`No data to plot`,e.canvas.width/t/2,e.canvas.height/t/2)}function BV(){let e=new Set;return{publish(t,n){for(let r of e)r(t,n)},subscribe(t){return e.add(t),()=>{e.delete(t)}}}}function VV(){return vt(`span`,{className:`kymoscope-attribution`,role:`note`,style:{position:`absolute`,right:10,bottom:8,zIndex:50,pointerEvents:`none`,font:`500 11px/1.2 var(--font-sans, system-ui)`,letterSpacing:`0.02em`,padding:`4px 8px`,borderRadius:999,color:`var(--text-muted, #8a93a6)`,background:`color-mix(in oklch, var(--bg-elevated, #1b2130) 88%, transparent)`,border:`1px solid var(--border, #33405a)`},children:[`Powered by `,q(`strong`,{style:{color:`var(--accent, #f5a524)`,fontWeight:700},children:`Kymoscope`})]})}function HV(){let e=new Map;return{on(t,n){let r=e.get(t);return r||e.set(t,r=new Set),r.add(n),()=>{r.delete(n)}},emit(t,n){for(let r of e.get(t)??[])try{r(n)}catch(e){console.error(`[kymoscope] listener failed`,e)}},clear(){e.clear()}}}function UV(e,t=1){let n=e.trim().replace(/^#/,``);n.length===3&&(n=n[0]+n[0]+n[1]+n[1]+n[2]+n[2]);let r=n.length===8?parseInt(n.slice(6),16)/255:1;n.length===8&&(n=n.slice(0,6));let i=parseInt(n,16);return n.length!==6||Number.isNaN(i)||Number.isNaN(r)?[0,0,0,t]:[(i>>16&255)/255,(i>>8&255)/255,(i&255)/255,r*t]}function WV(e){return Math.max(0,(e>>1)-1)}var GV=2.5,KV=`#version 300 es
|
|
72
72
|
in vec2 a_corner; // static quad corner: (±1, ±1)
|
|
73
73
|
in vec2 a_a; // per-instance: segment start (CSS px)
|
|
@@ -124,7 +124,7 @@ void main() {
|
|
|
124
124
|
// correct on premultiplied colour — straight alpha would darken the AA fringe.
|
|
125
125
|
float a = u_color.a * cov;
|
|
126
126
|
outColor = vec4(u_color.rgb * a, a);
|
|
127
|
-
}`;function JV(e,t,n){let r=e.createShader(t);return r?(e.shaderSource(r,n),e.compileShader(r),e.getShaderParameter(r,e.COMPILE_STATUS)?r:(console.error(`glLines shader compile failed:`,e.getShaderInfoLog(r)),e.deleteShader(r),null)):null}function YV(e,t=1){let n=e.getContext(`webgl2`,{antialias:!1,alpha:!0,premultipliedAlpha:!0});if(!n)return null;let r=JV(n,n.VERTEX_SHADER,KV),i=JV(n,n.FRAGMENT_SHADER,qV);if(!r||!i)return null;let a=n.createProgram();if(!a||(n.attachShader(a,r),n.attachShader(a,i),n.linkProgram(a),!n.getProgramParameter(a,n.LINK_STATUS)))return null;let o=n.getAttribLocation(a,`a_corner`),s=n.getAttribLocation(a,`a_a`),c=n.getAttribLocation(a,`a_b`),l=n.getUniformLocation(a,`u_resolution`),u=n.getUniformLocation(a,`u_color`),d=n.getUniformLocation(a,`u_ext`),f=n.getUniformLocation(a,`u_halfWidth`),p=n.createBuffer();n.bindBuffer(n.ARRAY_BUFFER,p),n.bufferData(n.ARRAY_BUFFER,Float32Array.from([-1,-1,1,-1,-1,1,1,1]),n.STATIC_DRAW);let m=n.createBuffer(),h=n.createFramebuffer(),g=n.createRenderbuffer(),_=1,v=1,y=(`clientWidth`in e?e.clientWidth:0)||1,b=(`clientHeight`in e?e.clientHeight:0)||1,x=1;return{resize(t,r,i){y=Math.max(1,t),b=Math.max(1,r),x=i*2,e.width=Math.round(y*i),e.height=Math.round(b*i),_=e.width*2,v=e.height*2,h&&g&&(n.bindRenderbuffer(n.RENDERBUFFER,g),n.renderbufferStorage(n.RENDERBUFFER,n.RGBA8,_,v),n.bindFramebuffer(n.FRAMEBUFFER,h),n.framebufferRenderbuffer(n.FRAMEBUFFER,n.COLOR_ATTACHMENT0,n.RENDERBUFFER,g),n.bindFramebuffer(n.FRAMEBUFFER,null))},draw(r){n.bindFramebuffer(n.FRAMEBUFFER,h),n.viewport(0,0,h?_:e.width,h?v:e.height),n.disable(n.SCISSOR_TEST),n.clearColor(0,0,0,0),n.clear(n.COLOR_BUFFER_BIT),n.useProgram(a),n.uniform2f(l,y,b),n.enable(n.BLEND),n.blendFunc(n.ONE,n.ONE_MINUS_SRC_ALPHA),n.bindBuffer(n.ARRAY_BUFFER,p),n.enableVertexAttribArray(o),n.vertexAttribPointer(o,2,n.FLOAT,!1,0,0),n.vertexAttribDivisor(o,0),n.bindBuffer(n.ARRAY_BUFFER,m),n.enableVertexAttribArray(s),n.vertexAttribPointer(s,2,n.FLOAT,!1,8,0),n.vertexAttribDivisor(s,1),n.enableVertexAttribArray(c),n.vertexAttribPointer(c,2,n.FLOAT,!1,8,8),n.vertexAttribDivisor(c,1);for(let e of r){let r=WV(e.points.length);if(r<1)continue;e.clip?(n.enable(n.SCISSOR_TEST),n.scissor(Math.round(e.clip.x*x),Math.round((b-e.clip.y-e.clip.h)*x),Math.round(e.clip.w*x),Math.round(e.clip.h*x))):n.disable(n.SCISSOR_TEST),n.bufferData(n.ARRAY_BUFFER,e.points,n.DYNAMIC_DRAW),n.uniform4fv(u,e.color);let i=e.width??t;n.uniform1f(d,i/2+GV),n.uniform1f(f,i/2),n.drawArraysInstanced(n.TRIANGLE_STRIP,0,4,r)}n.disable(n.SCISSOR_TEST),n.vertexAttribDivisor(s,0),n.vertexAttribDivisor(c,0),h&&(n.bindFramebuffer(n.READ_FRAMEBUFFER,h),n.bindFramebuffer(n.DRAW_FRAMEBUFFER,null),n.blitFramebuffer(0,0,_,v,0,0,e.width,e.height,n.COLOR_BUFFER_BIT,n.LINEAR),n.bindFramebuffer(n.FRAMEBUFFER,null))},dispose(){n.deleteBuffer(p),n.deleteBuffer(m),n.deleteFramebuffer(h),n.deleteRenderbuffer(g),n.deleteProgram(a),n.deleteShader(r),n.deleteShader(i),n.getExtension(`WEBGL_lose_context`)?.loseContext()}}}var XV=1024,
|
|
127
|
+
}`;function JV(e,t,n){let r=e.createShader(t);return r?(e.shaderSource(r,n),e.compileShader(r),e.getShaderParameter(r,e.COMPILE_STATUS)?r:(console.error(`glLines shader compile failed:`,e.getShaderInfoLog(r)),e.deleteShader(r),null)):null}function YV(e,t=1){let n=e.getContext(`webgl2`,{antialias:!1,alpha:!0,premultipliedAlpha:!0});if(!n)return null;let r=JV(n,n.VERTEX_SHADER,KV),i=JV(n,n.FRAGMENT_SHADER,qV);if(!r||!i)return null;let a=n.createProgram();if(!a||(n.attachShader(a,r),n.attachShader(a,i),n.linkProgram(a),!n.getProgramParameter(a,n.LINK_STATUS)))return null;let o=n.getAttribLocation(a,`a_corner`),s=n.getAttribLocation(a,`a_a`),c=n.getAttribLocation(a,`a_b`),l=n.getUniformLocation(a,`u_resolution`),u=n.getUniformLocation(a,`u_color`),d=n.getUniformLocation(a,`u_ext`),f=n.getUniformLocation(a,`u_halfWidth`),p=n.createBuffer();n.bindBuffer(n.ARRAY_BUFFER,p),n.bufferData(n.ARRAY_BUFFER,Float32Array.from([-1,-1,1,-1,-1,1,1,1]),n.STATIC_DRAW);let m=n.createBuffer(),h=n.createFramebuffer(),g=n.createRenderbuffer(),_=1,v=1,y=(`clientWidth`in e?e.clientWidth:0)||1,b=(`clientHeight`in e?e.clientHeight:0)||1,x=1;return{resize(t,r,i){y=Math.max(1,t),b=Math.max(1,r),x=i*2,e.width=Math.round(y*i),e.height=Math.round(b*i),_=e.width*2,v=e.height*2,h&&g&&(n.bindRenderbuffer(n.RENDERBUFFER,g),n.renderbufferStorage(n.RENDERBUFFER,n.RGBA8,_,v),n.bindFramebuffer(n.FRAMEBUFFER,h),n.framebufferRenderbuffer(n.FRAMEBUFFER,n.COLOR_ATTACHMENT0,n.RENDERBUFFER,g),n.bindFramebuffer(n.FRAMEBUFFER,null))},draw(r){n.bindFramebuffer(n.FRAMEBUFFER,h),n.viewport(0,0,h?_:e.width,h?v:e.height),n.disable(n.SCISSOR_TEST),n.clearColor(0,0,0,0),n.clear(n.COLOR_BUFFER_BIT),n.useProgram(a),n.uniform2f(l,y,b),n.enable(n.BLEND),n.blendFunc(n.ONE,n.ONE_MINUS_SRC_ALPHA),n.bindBuffer(n.ARRAY_BUFFER,p),n.enableVertexAttribArray(o),n.vertexAttribPointer(o,2,n.FLOAT,!1,0,0),n.vertexAttribDivisor(o,0),n.bindBuffer(n.ARRAY_BUFFER,m),n.enableVertexAttribArray(s),n.vertexAttribPointer(s,2,n.FLOAT,!1,8,0),n.vertexAttribDivisor(s,1),n.enableVertexAttribArray(c),n.vertexAttribPointer(c,2,n.FLOAT,!1,8,8),n.vertexAttribDivisor(c,1);for(let e of r){let r=WV(e.points.length);if(r<1)continue;e.clip?(n.enable(n.SCISSOR_TEST),n.scissor(Math.round(e.clip.x*x),Math.round((b-e.clip.y-e.clip.h)*x),Math.round(e.clip.w*x),Math.round(e.clip.h*x))):n.disable(n.SCISSOR_TEST),n.bufferData(n.ARRAY_BUFFER,e.points,n.DYNAMIC_DRAW),n.uniform4fv(u,e.color);let i=e.width??t;n.uniform1f(d,i/2+GV),n.uniform1f(f,i/2),n.drawArraysInstanced(n.TRIANGLE_STRIP,0,4,r)}n.disable(n.SCISSOR_TEST),n.vertexAttribDivisor(s,0),n.vertexAttribDivisor(c,0),h&&(n.bindFramebuffer(n.READ_FRAMEBUFFER,h),n.bindFramebuffer(n.DRAW_FRAMEBUFFER,null),n.blitFramebuffer(0,0,_,v,0,0,e.width,e.height,n.COLOR_BUFFER_BIT,n.LINEAR),n.bindFramebuffer(n.FRAMEBUFFER,null))},dispose(){n.deleteBuffer(p),n.deleteBuffer(m),n.deleteFramebuffer(h),n.deleteRenderbuffer(g),n.deleteProgram(a),n.deleteShader(r),n.deleteShader(i),n.getExtension(`WEBGL_lose_context`)?.loseContext()}}}var XV=12,ZV=0,QV=null,$V=new Set;function eH(){if(ZV<XV)return!0;for(let e of[...$V]){if(ZV<XV)break;e.hidden()&&e.evict()}return ZV<XV}function tH(e){ZV++,e&&$V.add(e);let t=!1;return()=>{t||(t=!0,ZV--,e&&$V.delete(e))}}var nH=new Set;function rH(){if(QV&&!QV.gl.isContextLost())return QV;let e=document.createElement(`canvas`);e.width=1,e.height=1;let t=e.getContext(`webgl2`,{antialias:!1,alpha:!0,premultipliedAlpha:!0,preserveDrawingBuffer:!1});return QV=t?{canvas:e,gl:t}:null,e.addEventListener(`webglcontextlost`,e=>{e.preventDefault(),setTimeout(()=>{for(let e of[...nH])e()},0)}),QV}function iH(e,t=!1){if(t&&ZV<XV){let t=tH();return{canvas:e,shared:!1,present(){},lost:()=>!1,release(){t();try{e.getContext(`webgl2`)?.getExtension(`WEBGL_lose_context`)?.loseContext()}catch{}}}}let n=rH();if(!n)return{canvas:e,shared:!1,present(){},lost:()=>!1,release(){}};let r=1,i=1,a={get width(){return r},set width(e){r=Math.max(1,Math.round(e)),n.canvas.width<r&&(n.canvas.width=r)},get height(){return i},set height(e){i=Math.max(1,Math.round(e)),n.canvas.height<i&&(n.canvas.height=i)},getContext(e){return e===`webgl2`?n.gl:null}},o=null;return{canvas:a,shared:!0,present(){e.width!==r&&(e.width=r),e.height!==i&&(e.height=i),o??=e.getContext(`2d`),o&&(o.globalCompositeOperation=`copy`,o.drawImage(n.canvas,0,n.canvas.height-i,r,i,0,0,r,i),o.globalCompositeOperation=`source-over`)},lost:()=>n.gl.isContextLost(),release(){}}}var aH=new WeakMap;function oH(e,t,n){let r=aH.get(e);return r||aH.set(e,r=new Map),r.has(t)||r.set(t,n()),r.get(t)}function sH(e,t){let n=iH(e),r=t(n.canvas);if(!r)return n.release(),null;let i=new Map,a=(e,t)=>{let n=t[0];return typeof n==`string`||typeof n==`number`&&(e===`setData`||e===`setStyles`)?`${e}:${n}`:e},o=(e,t)=>{let n=e=>{for(let t of[...i.keys()]){let n=t.indexOf(`:`);n>0&&!e(t.slice(n+1))&&i.delete(t)}};if(e===`remove`||e===`clearLayer`)n(e=>e!==String(t[0]));else if(e===`keep`&&Array.isArray(t[0])){let e=new Set(t[0].map(String));n(t=>e.has(t))}},s=()=>{try{r.dispose()}catch{}n.release(),n=iH(e);let a=t(n.canvas);if(!a)return!1;r=a;let o=[...i.values()];for(let e of o.filter(e=>e.name===`resize`).concat(o.filter(e=>e.name!==`resize`)))r[e.name](...e.args);return!0},c=()=>(n.lost()&&s(),r),l=()=>{n.lost()&&s()&&(r.render(),n.present())};return nH.add(l),new Proxy({},{get(e,t){if(t===`dispose`)return()=>{nH.delete(l),i.clear(),r.dispose(),n.release()};if(t===`render`)return()=>{c().render(),n.present()};let s=c()[t];return typeof s!=`function`||typeof t!=`string`?s:(...e)=>{if(o(t,e),t.startsWith(`set`)||t===`resize`){let n=a(t,e),r=i.get(n),o=t===`setData`&&typeof e[0]==`number`&&e[1]===null&&r?[e[0],r.args[1],r.args[2],...e.slice(3)]:e;i.delete(n),i.set(n,{name:t,args:o})}return s.apply(c(),e)}}})}var cH=1024,lH=`#version 300 es
|
|
128
128
|
in vec2 a_corner; // static quad corner: (±1, ±1)
|
|
129
129
|
in float a_ax; // per instance: segment start/end X (relative to the layer origin)
|
|
130
130
|
in float a_bx;
|
|
@@ -148,7 +148,7 @@ flat out float v_halfWidth;
|
|
|
148
148
|
flat out vec4 v_clip; // left, top, right, bottom (CSS px)
|
|
149
149
|
out vec2 v_pos;
|
|
150
150
|
vec4 style(int sid, int k) {
|
|
151
|
-
return texelFetch(u_styles, ivec2((sid % ${
|
|
151
|
+
return texelFetch(u_styles, ivec2((sid % ${cH}) * 3 + k, sid / ${cH}), 0);
|
|
152
152
|
}
|
|
153
153
|
void main() {
|
|
154
154
|
int sid = int(a_sid + 0.5);
|
|
@@ -183,7 +183,7 @@ void main() {
|
|
|
183
183
|
v_clip = vec4(u_left, top, min(u_left + u_plotW, u_cutPx), bottom);
|
|
184
184
|
vec2 clip = pos / u_resolution * 2.0 - 1.0;
|
|
185
185
|
gl_Position = vec4(clip.x, -clip.y, 0.0, 1.0);
|
|
186
|
-
}`,
|
|
186
|
+
}`,uH=`#version 300 es
|
|
187
187
|
precision highp float;
|
|
188
188
|
flat in vec2 v_a;
|
|
189
189
|
flat in vec2 v_b;
|
|
@@ -203,8 +203,8 @@ void main() {
|
|
|
203
203
|
if (cov <= 0.0) discard;
|
|
204
204
|
float alpha = v_color.a * cov;
|
|
205
205
|
outColor = vec4(v_color.rgb * alpha, alpha);
|
|
206
|
-
}`;function $V(e,t,n,r){let i=e.length,a=0;for(let t=0;t<i;t++)Number.isFinite(r[t])&&Number.isFinite(e[t])&&a++;if(a===i)return null;let o=new Float32Array(a),s=new Float32Array(a),c=new Uint8Array(a),l=0,u=!1;for(let a=0;a<i;a++)n[a]&&(u=!0),Number.isFinite(r[a])&&Number.isFinite(e[a])&&(o[l]=t[a],s[l]=r[a],u&&=(c[l]=255,!1),l++);return{x:o,y:s,starts:c}}function eH(e,t,n){let r=e.length,i=0;for(let t=0;t<r;t++)if(Number.isFinite(e[t])){i=e[t];break}let a=new Float32Array(r);for(let t=0;t<r;t++)a[t]=e[t]-i;let o=new Uint8Array(r);if(t)for(let e=0;e<r;e++)t[e]&&(o[e]=255);let s=n.map(t=>$V(e,a,o,t)??{x:a,y:t,starts:o}),c=s.map(e=>e.y.length),l=c.reduce((e,t)=>e+t,0),u=new Float32Array(l),d=new Float32Array(l),f=new Uint8Array(l),p=new Float32Array(l),m=0;return s.forEach((e,t)=>{u.set(e.x,m),d.set(e.y,m),f.set(e.starts,m),e.y.length>0&&(f[m]=255),p.fill(t,m,m+e.y.length),m+=e.y.length}),{origin:i,x:u,y:d,starts:f,sid:p,counts:c}}function tH(e,t,n,r,i,a){let o=(i-r)/a,s=(t,n)=>{let r=0,i=e.length;for(;r<i;){let a=r+i>>>1;(n?e[a]<=t:e[a]<t)?r=a+1:i=a}return r},c=s(r,!1),l=s(i,!0),u=t.length*(2*a+2),d=new Float32Array(u),f=new Float32Array(u),p=new Uint8Array(u),m=new Float32Array(u),h=0,g=(e,t,r)=>{d[h]=e-n,f[h]=t,m[h]=r,h++};return t.forEach((t,n)=>{let i=h;for(let r=c-1;r>=Math.max(0,c-64);r--)if(t[r]===t[r]){g(e[r],t[r],n);break}let s=c;for(let i=0;i<a&&s<l;i++){let c=i===a-1?1/0:r+(i+1)*o,u=1/0,d=-1/0,f=-1,p=-1;for(;s<l&&e[s]<c;s++){let e=t[s];e<u&&(u=e,f=s),e>d&&(d=e,p=s)}f<0||(f===p?g(e[f],u,n):f<p?(g(e[f],u,n),g(e[p],d,n)):(g(e[p],d,n),g(e[f],u,n)))}for(let r=l;r<Math.min(e.length,l+64);r++)if(t[r]===t[r]){g(e[r],t[r],n);break}h>i&&(p[i]=255)}),{x:d.subarray(0,h),y:f.subarray(0,h),starts:p.subarray(0,h),sid:m.subarray(0,h),bucket:o}}function nH(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 rH(e,t=1){let n=e.getContext(`webgl2`,{antialias:!1,alpha:!0,premultipliedAlpha:!0}),r=typeof HTMLCanvasElement<`u`&&e instanceof HTMLCanvasElement||typeof OffscreenCanvas<`u`&&e instanceof OffscreenCanvas;if(!n)return null;let i=JV(n,n.VERTEX_SHADER,ZV),a=JV(n,n.FRAGMENT_SHADER,QV);if(!i||!a)return null;let o=n.createProgram();if(!o)return null;if(n.attachShader(o,i),n.attachShader(o,a),n.linkProgram(o),!n.getProgramParameter(o,n.LINK_STATUS))return console.error(`glSeries program link failed:`,n.getProgramInfoLog(o)),null;let s=e=>n.getAttribLocation(o,e),c=s(`a_corner`),l=s(`a_ax`),u=s(`a_bx`),d=s(`a_ay`),f=s(`a_by`),p=s(`a_bstart`),m=s(`a_sid`),h=[l,u,d,f,p,m],g=e=>n.getUniformLocation(o,e),_={res:g(`u_resolution`),styles:g(`u_styles`),left:g(`u_left`),plotW:g(`u_plotW`),xoff:g(`u_xoff`),xscale:g(`u_xscale`),xR:g(`u_xR`),minGap:g(`u_minGap`),cutPx:g(`u_cutPx`)},v=n.createBuffer();n.bindBuffer(n.ARRAY_BUFFER,v),n.bufferData(n.ARRAY_BUFFER,Float32Array.from([-1,-1,1,-1,-1,1,1,1]),n.STATIC_DRAW);let y=n.createFramebuffer(),b=n.createRenderbuffer(),x=1,S=1,C=(`clientWidth`in e?e.clientWidth:0)||1,w=(`clientHeight`in e?e.clientHeight:0)||1,T=[],E=0,D=1,O=1/0,k=e=>{let t=n.createBuffer();return n.bindBuffer(n.ARRAY_BUFFER,t),n.bufferData(n.ARRAY_BUFFER,e,n.STATIC_DRAW),t},A=e=>{if(e)for(let t of[e.x,e.y,e.starts,e.sid])n.deleteBuffer(t)},j=e=>{e&&(A(e.full),A(e.res),n.deleteTexture(e.styles))},M=e=>({x:k(e.x),y:k(e.y),starts:k(e.starts),sid:k(e.sid),total:e.x.length}),N=e=>{let t=e.full;if(t&&t.version===e.version)return t;if(t&&e.valuesOnly&&t.whole&&e.counts.every(t=>t===e.xs.length)){let r=e.xs.length,i=e.columns.length===1?e.columns[0]:new Float32Array(r*e.columns.length);return e.columns.length>1&&e.columns.forEach((e,t)=>i.set(e,t*r)),n.bindBuffer(n.ARRAY_BUFFER,t.y),n.bufferSubData(n.ARRAY_BUFFER,0,i),t.version=e.version,t}A(t);let r=eH(e.xs,e.breaks,e.columns);return e.full={...M(r),version:e.version,whole:r.counts.every(t=>t===e.xs.length)},e.full},P=t=>{let n=Math.max(1,Math.round(t.plotW*(e.width/C)));if(t.resamplable&&D>E){let e=t.xs,r=0,i=e.length;for(;r<i;){let t=r+i>>>1;e[t]<E?r=t+1:i=t}let a=r;for(i=e.length;r<i;){let t=r+i>>>1;e[t]<=D?r=t+1:i=t}if(r-a>n*4){let r=`${t.version}|${E}|${D}|${n}`;if(t.res?.key!==r){A(t.res);let i=tH(e,t.columns,t.origin,E,D,n);t.res={...M(i),key:r,bucket:i.bucket}}return{d:t.res,minGap:t.res.bucket*2.5}}}return{d:N(t),minGap:0}},F=(e,r)=>{let i=e.counts.length,a=Math.max(1,Math.ceil(i/XV)),o=3*Math.min(Math.max(i,1),XV),s=new Float32Array(o*a*4);for(let n=0;n<i;n++){let i=r[n],a=(Math.floor(n/XV)*o+n%XV*3)*4;if(!i)continue;let c=i.width??t;s.set([Math.min(i.scaleMin,i.scaleMax),Math.max(i.scaleMin,i.scaleMax),i.bandTop,i.bandBottom],a),s.set(i.color,a+4),s.set([i.gapMedian,c/2,c/2+GV,+(e.counts[n]>=2)],a+8)}n.bindTexture(n.TEXTURE_2D,e.styles),n.texImage2D(n.TEXTURE_2D,0,n.RGBA32F,o,a,0,n.RGBA,n.FLOAT,s),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.NEAREST)};return{resize(t,r,i){C=Math.max(1,t),w=Math.max(1,r),e.width=Math.round(C*i),e.height=Math.round(w*i),x=e.width*2,S=e.height*2,y&&b&&(n.bindRenderbuffer(n.RENDERBUFFER,b),n.renderbufferStorage(n.RENDERBUFFER,n.RGBA8,x,S),n.bindFramebuffer(n.FRAMEBUFFER,y),n.framebufferRenderbuffer(n.FRAMEBUFFER,n.COLOR_ATTACHMENT0,n.RENDERBUFFER,b),n.bindFramebuffer(n.FRAMEBUFFER,null))},setData(e,t,r,i){let a=T[e],o=!t&&!!a&&i.length===a.columns.length;if(!t){if(!a)return;t=a.xs,r=a.breaks}let s=0;for(let e=0;e<t.length;e++)if(Number.isFinite(t[e])){s=t[e];break}let c=i.map(e=>{let t=0;for(let n=0;n<e.length;n++)e[n]===e[n]&&t++;return t});if(a&&(o||a.xs===t)){a.columns=i,a.counts=c,a.valuesOnly=o,a.version++,o||(A(a.full),a.full=null);return}let l={xs:t,breaks:r,columns:i,origin:s,counts:c,resamplable:!r?.some(e=>e)&&nH(t),version:0,valuesOnly:!1,full:null,res:null,styles:n.createTexture(),left:a?.left??0,plotW:a?.plotW??0};F(l,[]),T[e]=l,j(a)},setStyles(e,t,n,r){let i=T[e];i&&(F(i,t),i.left=n,i.plotW=r)},clearLayer(e){j(T[e]),T[e]=null},setView(e,t,n=1/0){E=e,D=t,O=n},render(){n.bindFramebuffer(n.FRAMEBUFFER,y),n.viewport(0,0,y?x:e.width,y?S:e.height),n.disable(n.SCISSOR_TEST),n.clearColor(0,0,0,0),n.clear(n.COLOR_BUFFER_BIT),n.useProgram(o),n.uniform2f(_.res,C,w),n.uniform1i(_.styles,0),n.activeTexture(n.TEXTURE0),n.enable(n.BLEND),n.blendFunc(n.ONE,n.ONE_MINUS_SRC_ALPHA),n.bindBuffer(n.ARRAY_BUFFER,v),n.enableVertexAttribArray(c),n.vertexAttribPointer(c,2,n.FLOAT,!1,0,0),n.vertexAttribDivisor(c,0);for(let e of h)n.enableVertexAttribArray(e),n.vertexAttribDivisor(e,1);let t=D-E||1;for(let e of T){if(!e)continue;n.uniform1f(_.left,e.left),n.uniform1f(_.plotW,e.plotW),n.uniform1f(_.xoff,E-e.origin),n.uniform1f(_.xscale,e.plotW/t),n.uniform1f(_.xR,t),n.uniform1f(_.cutPx,Number.isFinite(O)?e.left+(O-E)*(e.plotW/t):1e9);let{d:r,minGap:i}=P(e);r.total<2||(n.uniform1f(_.minGap,i),n.bindTexture(n.TEXTURE_2D,e.styles),n.bindBuffer(n.ARRAY_BUFFER,r.x),n.vertexAttribPointer(l,1,n.FLOAT,!1,4,0),n.vertexAttribPointer(u,1,n.FLOAT,!1,4,4),n.bindBuffer(n.ARRAY_BUFFER,r.y),n.vertexAttribPointer(d,1,n.FLOAT,!1,4,0),n.vertexAttribPointer(f,1,n.FLOAT,!1,4,4),n.bindBuffer(n.ARRAY_BUFFER,r.starts),n.vertexAttribPointer(p,1,n.UNSIGNED_BYTE,!0,1,1),n.bindBuffer(n.ARRAY_BUFFER,r.sid),n.vertexAttribPointer(m,1,n.FLOAT,!1,4,0),n.drawArraysInstanced(n.TRIANGLE_STRIP,0,4,r.total-1))}for(let e of h)n.vertexAttribDivisor(e,0);y&&(n.bindFramebuffer(n.READ_FRAMEBUFFER,y),n.bindFramebuffer(n.DRAW_FRAMEBUFFER,null),n.blitFramebuffer(0,0,x,S,0,0,e.width,e.height,n.COLOR_BUFFER_BIT,n.LINEAR),n.bindFramebuffer(n.FRAMEBUFFER,null))},dispose(){for(let e of T)j(e);T.length=0,n.deleteBuffer(v),n.deleteFramebuffer(y),n.deleteRenderbuffer(b),n.deleteProgram(o),n.deleteShader(i),n.deleteShader(a),r&&n.getExtension(`WEBGL_lose_context`)?.loseContext()}}}var iH=12,aH=0,oH=null;function sH(){return aH<iH}function cH(){aH++;let e=!1;return()=>{e||(e=!0,aH--)}}var lH=new Set;function uH(){if(oH&&!oH.gl.isContextLost())return oH;let e=document.createElement(`canvas`);e.width=1,e.height=1;let t=e.getContext(`webgl2`,{antialias:!1,alpha:!0,premultipliedAlpha:!0,preserveDrawingBuffer:!1});return oH=t?{canvas:e,gl:t}:null,e.addEventListener(`webglcontextlost`,e=>{e.preventDefault(),setTimeout(()=>{for(let e of[...lH])e()},0)}),oH}function dH(e,t=!1){if(t&&aH<iH){let t=cH();return{canvas:e,shared:!1,present(){},lost:()=>!1,release(){t();try{e.getContext(`webgl2`)?.getExtension(`WEBGL_lose_context`)?.loseContext()}catch{}}}}let n=uH();if(!n)return{canvas:e,shared:!1,present(){},lost:()=>!1,release(){}};let r=1,i=1,a={get width(){return r},set width(e){r=Math.max(1,Math.round(e)),n.canvas.width<r&&(n.canvas.width=r)},get height(){return i},set height(e){i=Math.max(1,Math.round(e)),n.canvas.height<i&&(n.canvas.height=i)},getContext(e){return e===`webgl2`?n.gl:null}},o=null;return{canvas:a,shared:!0,present(){e.width!==r&&(e.width=r),e.height!==i&&(e.height=i),o??=e.getContext(`2d`),o&&(o.globalCompositeOperation=`copy`,o.drawImage(n.canvas,0,n.canvas.height-i,r,i,0,0,r,i),o.globalCompositeOperation=`source-over`)},lost:()=>n.gl.isContextLost(),release(){}}}var fH=new WeakMap;function pH(e,t,n){let r=fH.get(e);return r||fH.set(e,r=new Map),r.has(t)||r.set(t,n()),r.get(t)}function mH(e,t){let n=dH(e),r=t(n.canvas);if(!r)return n.release(),null;let i=new Map,a=(e,t)=>{let n=t[0];return typeof n==`string`||typeof n==`number`&&(e===`setData`||e===`setStyles`)?`${e}:${n}`:e},o=(e,t)=>{let n=e=>{for(let t of[...i.keys()]){let n=t.indexOf(`:`);n>0&&!e(t.slice(n+1))&&i.delete(t)}};if(e===`remove`||e===`clearLayer`)n(e=>e!==String(t[0]));else if(e===`keep`&&Array.isArray(t[0])){let e=new Set(t[0].map(String));n(t=>e.has(t))}},s=()=>{try{r.dispose()}catch{}n.release(),n=dH(e);let a=t(n.canvas);if(!a)return!1;r=a;let o=[...i.values()];for(let e of o.filter(e=>e.name===`resize`).concat(o.filter(e=>e.name!==`resize`)))r[e.name](...e.args);return!0},c=()=>(n.lost()&&s(),r),l=()=>{n.lost()&&s()&&(r.render(),n.present())};return lH.add(l),new Proxy({},{get(e,t){if(t===`dispose`)return()=>{lH.delete(l),i.clear(),r.dispose(),n.release()};if(t===`render`)return()=>{c().render(),n.present()};let s=c()[t];return typeof s!=`function`||typeof t!=`string`?s:(...e)=>{if(o(t,e),t.startsWith(`set`)||t===`resize`){let n=a(t,e),r=i.get(n),o=t===`setData`&&typeof e[0]==`number`&&e[1]===null&&r?[e[0],r.args[1],r.args[2],...e.slice(3)]:e;i.delete(n),i.set(n,{name:t,args:o})}return s.apply(c(),e)}}})}var hH=``+new URL(`assets/offscreenLineWorker-BQwts3O3.js`,import.meta.url).href;function gH(e,t=1,n){if(typeof e.transferControlToOffscreen!=`function`||typeof Worker>`u`)return null;let r;try{r=NE(hH)}catch{return null}let i;try{i=e.transferControlToOffscreen()}catch{return r.terminate(),null}r.postMessage({type:`init`,canvas:i,lineWidth:t},[i]),r.onmessage=e=>{e.data?.type===`lost`&&n?.()};let a=cH(),o=-1,s=-1,c=-1;return{resize(e,t,n){e===o&&t===s&&n===c||(o=e,s=t,c=n,r.postMessage({type:`resize`,w:e,h:t,dpr:n}))},setData(e,t){let n=[];t.xs&&n.push(t.xs.buffer),t.breaks&&n.push(t.breaks.buffer);for(let e of t.columns)n.push(e.buffer);r.postMessage({type:`data`,layer:e,...t},n)},setStyle(e,t){r.postMessage({type:`style`,layer:e,...t})},clear(e){r.postMessage({type:`clear`,layer:e})},setView(e,t,n){r.postMessage({type:`view`,xmin:e,xmax:t,cut:n})},dispose(){try{r.postMessage({type:`dispose`})}catch{}r.terminate(),a()}}}function _H(e,t=1){let n=mH(e,e=>rH(e,t));if(!n)return null;let r=0,i=1,a,o=``,s=(e,t)=>{n.setStyles(e,t.styles,t.left,t.plotW),r=t.xmin,i=t.xmax,a=t.cut,n.setView(r,i,a),n.render()};return{resize(e,t,r){let i=`${e}|${t}|${r}`;i!==o&&(o=i,n.resize(e,t,r),n.render())},setData(e,t){n.setData(e,t.xs,t.breaks,t.columns),s(e,t)},setStyle(e,t){s(e,t)},clear(e){n.clearLayer(e),n.render()},setView(e,t,o){e===r&&t===i&&o===a||(r=e,i=t,a=o,n.setView(e,t,o),n.render())},dispose(){n.dispose()}}}var vH=new Set;function yH(e){vH.add(e)}function bH(e){vH.delete(e)}function xH(){let e=typeof window>`u`?[]:[window];for(let t of vH)t.closed||e.push(t);return e}var SH=1,CH=new Map;function wH(e){let t=SH++,n=xH();if(n.length===1){let r=n[0].requestAnimationFrame(n=>{CH.delete(t),e(n)});return CH.set(t,[{w:n[0],id:r}]),t}let r=[],i=n=>{CH.has(t)&&(TH(t),e(n))};for(let e of n)r.push({w:e,id:e.requestAnimationFrame(i)});return CH.set(t,r),t}function TH(e){if(e==null)return;let t=CH.get(e);if(t){CH.delete(e);for(let{w:e,id:n}of t)e.closed||e.cancelAnimationFrame(n)}}var EH=new WeakMap;function DH(e){e&&EH.set(e,(EH.get(e)??0)+1)}function OH(e){let t=EH.get(e)??0;for(let n of e.querySelectorAll(`*`))t+=EH.get(n)??0;return t}function kH(){return xH().every(e=>e.document.hidden)}var AH=class{#e;#t=new Map;constructor(e){this.#e=e}observe(e,t){let n=e.ownerDocument.defaultView??window,r=this.#t.get(n);r||(r=new(n.ResizeObserver??ResizeObserver)(e=>this.#e(e,this)),this.#t.set(n,r)),r.observe(e,t)}unobserve(e){for(let t of this.#t.values())t.unobserve(e)}disconnect(){for(let e of this.#t.values())e.disconnect();this.#t.clear()}};function jH(e,t){let n=0,r=null,i=()=>{let e=t();return!!e&&e.isConnected&&typeof e.checkVisibility==`function`&&!e.checkVisibility()},a=t=>{n=0,!i()&&(r=t,e())};return{schedule(){n||=wH(a)},now(){if(i())return;let o=t()?.ownerDocument?.timeline?.currentTime;if(typeof o!=`number`||o===r){n||=wH(a);return}n&&=(TH(n),0),r=o,e()},cancel(){n&&TH(n),n=0}}}function MH(e,t=typeof window>`u`?null:e=>{wH(e)}){let n=!1,r=null;return{set(i){if(r=i,!t){e(i);return}n||(n=!0,t(()=>{n=!1,e(r)}))}}}function NH(e,t,n,r,i){return r+(e-t)/n*(i-r)}function PH(e,t,n,r){let i=new Map,a=n.length;if(a===0)return i;let o=new Float64Array(a),s=new Float64Array(a).fill(1/0);for(let r of e){let e=r.x;for(let i=0;i<a;i++){let a=r.cols.get(n[i]);if(!a)continue;let c=s[i],l=o[i];for(let n=0;n<r.length;n++){let r=e[n],i=r<t?t-r:r-t;if(i>=c)continue;let o=a[n];Number.isFinite(o)&&(c=i,l=o)}s[i]=c,o[i]=l}}for(let e=0;e<a;e++)s[e]!==1/0&&(r&&s[e]>(r.get(n[e])??1/0)||i.set(n[e],o[e]));return i}function FH(e,t,n,r=64){let i=new Map;if(t.length===0||!Number.isFinite(n))return i;let a=new Map;for(let o of e){if(o.length===0)continue;let e=0,s=o.length-1;for(;e<s;){let t=e+s>>1;o.x[t]<n?e=t+1:s=t}for(let s of t){let t=o.cols.get(s);if(t)for(let c=0;c<=r;c++){let r=e-c,l=e+c,u=r>=0&&Number.isFinite(t[r])?r:l<o.length&&Number.isFinite(t[l])?l:-1;if(u<0)continue;let d=Math.abs(o.x[u]-n);d<(a.get(s)??1/0)&&(a.set(s,d),i.set(s,t[u]));break}}}return i}function IH(e,t){let n=new Map;if(t.length===0)return n;for(let r=e.length-1;r>=0&&n.size<t.length;r--){let i=e[r];for(let e of t){if(n.has(e))continue;let t=i.cols.get(e);if(t){for(let r=i.length-1;r>=0;r--)if(Number.isFinite(t[r])){n.set(e,t[r]);break}}}}return n}function LH(e,t){return!(e>0)||!(t>0)?1:1-Math.exp(-e/t)}function RH(e,t,n,r=t){if(!(t>e)||n==null||!(n>0))return[e,t];let i=Number.isFinite(r)?Math.min(t,Math.max(e,r)):t;return i-n<e?[e,Math.min(t,e+n)]:[i-n,i]}function zH(e,t){let n=Math.round(e*t*2);return Math.min(8e3,Math.max(2e3,n))}var BH=.5;function VH(e,t,n,r=BH){if(!(t>0))return e;let i=e!=null&&e>0?Math.min(e,t):t,a=n?i*.88:i/.88;return a>=t*.999?null:Math.max(r,a)}function HH(e=0){return{d:null,lastT:NaN,wall:0,base:NaN,wait:e,waitAge:0}}var UH=new Map;function WH(e,t,n){let r=UH.get(e);if(r||UH.set(e,r={p:HH(),at:NaN,d:NaN}),n-r.at<2&&Number.isFinite(r.d))return r.d;let i=Number.isNaN(r.at)?16:n-r.at;return r.at=n,r.d=XH(r.p,t,i),r.d}var GH=250,KH=3,qH=90,JH=30,YH=.001;function XH(e,t,n){if(!Number.isFinite(t))return t;let r=n/1e3;e.wall+=r;let i=n>GH&&e.d!==null;if(t<e.lastT&&Object.assign(e,HH(),{wall:e.wall}),t<=e.lastT)e.base+=r*YH;else{let n=e.wall-t;e.base=Number.isNaN(e.base)?n:Math.min(e.base+r*YH,n)}e.lastT=t;let a=e.wall-t-e.base;i||(e.waitAge+=r),i||(a>e.wait?(e.wait=Math.min(KH,a),e.waitAge=0):a>e.wait*.8?e.waitAge=0:e.waitAge>qH&&(e.wait*=Math.exp(-r/JH)));let o=e.wall-e.base-Math.min(KH,e.wait*1.2+.05);if(e.d===null)e.d=e.wait>0?Math.min(t,o):t;else if(i||e.d<o-2)e.d=Math.min(t,o);else{let t=Math.min(n,64);e.d+=t/1e3,e.d+=(o-e.d)*Math.min(1,t/500)}return e.d>t&&(e.d=t),e.d}var ZH=(e,t)=>e.log?(Math.log10(Math.max(t,Number.MIN_VALUE))-Math.log10(e.v0))/(Math.log10(e.v1)-Math.log10(e.v0)||1):(t-e.v0)/(e.v1-e.v0||1),QH=(e,t)=>e.log?10**(Math.log10(e.v0)+t*(Math.log10(e.v1)-Math.log10(e.v0))):e.v0+t*(e.v1-e.v0),$H=(e,t)=>e.left+ZH(e.x,t)*e.width,eU=(e,t)=>QH(e.x,(t-e.left)/(e.width||1)),tU=(e,t)=>e.top+(1-ZH(e.y,t))*e.height,nU=e=>!e||Number.isFinite(e.v0)&&Number.isFinite(e.v1)&&e.v0!==e.v1&&(!e.log||e.v0>0&&e.v1>0),rU=(e,t)=>e===t||!!e&&!!t&&e.v0===t.v0&&e.v1===t.v1&&!!e.log==!!t.log;function iU(){let e=null,t=new Set;return{get:()=>e,set:n=>{if(n&&(n.width>0&&n.height>0?(!nU(n.x)||!nU(n.y))&&(n={...n,x:nU(n.x)?n.x:void 0,y:nU(n.y)?n.y:void 0}):n=null),!(n===e||n&&e&&n.left===e.left&&n.top===e.top&&n.width===e.width&&n.height===e.height&&rU(n.x,e.x)&&rU(n.y,e.y))){e=n;for(let e of[...t])e()}},subscribe:e=>(t.add(e),()=>{t.delete(e)})}}var aU=at(()=>{}),oU=()=>ut(aU),sU=`M5 .8a3.1 3.1 0 0 0-3.1 3.1v2.3L.8 7.6h8.4L8.1 6.2V3.9A3.1 3.1 0 0 0 5 .8zM3.9 8.4a1.1 1.1 0 0 0 2.2 0z`,cU=[5,4],lU=null;function uU(e,t,n,r){typeof Path2D>`u`||(lU??=new Path2D(sU),e.save(),e.setLineDash([]),e.translate(t,n),e.fillStyle=r,e.fill(lU),e.restore())}var dU=(()=>{try{return localStorage.getItem(`glLines`)!==`0`}catch{return!0}})(),fU=(()=>{try{return localStorage.getItem(`offscreenGl`)!==`0`}catch{return!0}})(),pU=70;function mU(e){return e===`dashed`?[5,4]:e===`dotted`?[1,4]:[]}var hU={top:14,right:160,bottom:40,left:110},gU={top:14,right:100,bottom:40,left:70},_U=640,vU={top:3,right:3,bottom:3,left:3},yU=260;function bU(e){return e<yU?vU:e<_U?gU:hU}var xU=220,SU=2e3,CU=4,wU=1e3/120,TU=`11.25px ${Q.mono}`,EU=11*1.125,DU=24*1.125,OU=DU-EU+26,kU=.6,AU=13,jU=10,MU=5,NU=14,PU=4;function FU(e,t,n){return Math.min(n,Math.max(t,e))}function IU(e,t,n,r,i){let a=Math.min(r,i),o=Math.max(r,i);return t+(1-FU(o===a?.5:(e-a)/(o-a),0,1))*(n-t)}function LU(e,t,n,r){let i=e+t;return{bandTop:i-r/100*t,bandBottom:i-n/100*t}}function RU(e){return e.replace(/__(\d+|ref)$/,``)}function zU(e,t,n){let r=Math.floor((n-t-EU)/AU)+1;return Math.max(0,Math.min(e,r))}function BU(e){let t=0;for(let n of e)t+=n.length;return t}function VU(e,t){let n=e.cols.get(t);return n?Float32Array.from(n):new Float32Array(e.length).fill(NaN)}function HU(e){let t=new Map;for(let n of e){let e=RU(n.column),r=t.get(e)??[];r.push(n),t.set(e,r)}let n=new Set,r=[];for(let i of e){let e=RU(i.column);if(n.has(e))continue;n.add(e);let a=t.get(e);r.push({base:e,leader:a[0],members:a})}return r}function UU(e,t,n){let r=new Map,i=e.map((e,r)=>{let{bandTop:i}=LU(t,n,e.leader.bandFromPct,e.leader.bandToPct);return{g:e,i:r,bandTop:i,blockDY:e.members.length>1?EU+(e.members.length+1)*AU:OU}});i.sort((e,t)=>e.bandTop-t.bandTop||e.i-t.i);let a=-1/0;for(let{g:e,bandTop:t,blockDY:n}of i){let i=t+EU,o=Math.max(i,a),s=o-EU;r.set(e.leader.id,s),a=o+n}return r}function WU(e,t){let n=e.cols.get(t);if(!n)return 0;let r=e.x;return n.length===e.length&&c.has(n)?GU(r,e.length):qU(r,e.length,e=>Number.isFinite(n[e]))}function GU(e,t){let n=KU.get(e);return n===void 0&&(n=qU(e,t,()=>!0),KU.set(e,n)),n}var KU=F(new WeakMap);function qU(e,t,n){let r=null,i=0,a=0;for(let o=0;o<t;o++)n(o)&&(r!==null&&e[o]!==r&&(i+=Math.abs(e[o]-r),a++),r=e[o]);return a===0?0:i/a}function JU(e,t){return e>0?Math.max(e*4,t*1e-9):Math.max(t*1e-6,1e-12)}var YU=1e30,XU=250;function ZU({xLabel:e,series:t,points:n,columnUnits:r={},height:i=440,onPlotContextMenu:a,backgroundToken:o=``,viewXRange:s=null,onViewXRangeChange:c,liveZoom:l,liveZoomId:u,fullXRange:d=null,shiftMode:f,xAxisLine:p,yAxisLine:m,gridLine:h,lineWidth:g=1,envelopes:_,showLatestValues:v=!1,liveSource:y,liveWindowSeconds:b=null,onLiveWindowChange:x,liveZoomMode:S,onPlotWidthCss:C,onCursorX:w}){let T=oU(),E=K(null),D=K(null),O=K(null),k=K(null),A=K(C);A.current=C;let j=K(-1),M=K(null),N=K(!1),P=K(null),F=K(!1),I=K(!1),L=K(null),R=K(null),z=K({pts:null,layers:[]}),B=K(new Map),V=K([]),ee=K(null),te=K(null),H=K(null),ne=K(null),re=K(0),ie=K(0),U=K(!1),ae=K(0),oe=K(SU),se=K(y),ce=K(null),le=K(HH()),ue=K(0),de=K(void 0),fe=K(0),pe=K(0),me=K(16),he=K(!0),ge=K(!1),[_e,ve]=pt(0);function ye(){P.current?.dispose(),P.current=null,I.current=!1,F.current=!1,V.current=[],ve(e=>e+1)}W(()=>{_e&&St()},[_e]),G(()=>{se.current=y,ce.current=null,z.current={pts:null,layers:[]},B.current.clear()},[y]);let be=K(b);G(()=>{be.current=b},[b]);let xe=K(x);xe.current=x;let Se=S??(x?`follow`:`free`),Ce=K(Se);Ce.current=Se;let we=K(null);G(()=>{we.current=null},[Se,e]);let Te=K([]),Ee=K(!1),De=K(0),Oe=K(0),ke=K(0),Ae=K(0),je=K(`none`),Me=K(0),Ne=K(0),Pe=K(0),Fe=K(null),Ie=K(null),Le=K(f),Re=K(null),ze=K({pts:null,x0:NaN,x1:NaN,ser:null}),Be=K(0),Ve=K(0),He=K(null),Ue=K(null),We=K(null),Ge=K(null);G(()=>{Le.current=f},[f]),W(()=>(L.current&&=(clearTimeout(L.current),null),()=>{M.current?.dispose(),M.current=null;let e=P.current;e&&(L.current=setTimeout(()=>{e.dispose(),P.current===e&&(P.current=null),L.current=null},0))}),[]);let Ke=mt(qz,Kz),qe=K({xLabel:e,series:t,points:n,height:i,columnUnits:r,shiftMode:f,xAxisLine:p,yAxisLine:m,gridLine:h,lineWidth:g,showLatestValues:v,envelopes:_}),Je=K(null),Ye=K(null);G(()=>{qe.current={xLabel:e,series:t,points:n,height:i,columnUnits:r,shiftMode:f,xAxisLine:p,yAxisLine:m,gridLine:h,lineWidth:g,showLatestValues:v,envelopes:_}},[e,t,n,i,r,f,p,m,h,g,v,_]);let Xe=K(c),Ze=K(w);Ze.current=w,G(()=>{Xe.current=c},[c]);let Qe=K(l),$e=K(u);G(()=>{Qe.current=l,$e.current=u},[l,u]),W(()=>{if(!(!l||!u))return l.subscribe((e,t)=>{e!==u&&(ee.current=t?.[0]??null,te.current=t?.[1]??null,St())})},[l,u]);let et=K(a);G(()=>{et.current=a},[a]);let tt=ft(()=>{if(d&&d[1]>d[0])return{xmin:d[0],xmax:d[1]};let e=1/0,t=-1/0;for(let r of n)for(let n=0;n<r.length;n++){let i=r.x[n];i<e&&(e=i),i>t&&(t=i)}return(!Number.isFinite(e)||e===t)&&(--e,t+=1),{xmin:e,xmax:t}},[n,d]),nt=K(tt);G(()=>{nt.current=tt},[tt]);function rt(){return se.current!=null&&ee.current===null&&te.current===null&&!Ee.current&&Re.current===null}function it(){let{xmin:e,xmax:t}=nt.current,n=ee.current,r=te.current;if(n!==null&&r!==null&&r>n&&Number.isFinite(n)&&Number.isFinite(r))return{xmin:n,xmax:r};let i=H.current,a=ne.current;return rt()&&i!==null&&a!==null&&a>i&&Number.isFinite(i)&&Number.isFinite(a)?{xmin:i,xmax:a}:{xmin:e,xmax:t}}function at(e,t){let n=se.current;if(!n?.latestValues)return IH(e,t);let r=n.latestValues(t),i=t.filter(e=>!r.has(e)),a=n.latestX?.();if(i.length>0&&a!=null)for(let[t,n]of FH(e,i,a))r.set(t,n);return r}function ot(){return se.current?Te.current:qe.current.points}function st(e,t,n){let r=new Map;for(let i of t)r.set(i,JU(ht(e,i),n));return r}function ct(e){if(z.current.pts===e)return z.current.layers;let t=z.current.layers,n=se.current?.version?.(),r=e.map((e,r)=>({pts:e,key:t[r]?.pts===e?t[r].key:n??e}));return z.current={pts:e,layers:r},r}function lt(e,t){let n=B.current.get(e),r=performance.now(),i=n&&(n.key===t.key||typeof t.key==`number`&&typeof n.key==`number`&&r-n.at<XU);return(!n||!i)&&(n={key:t.key,at:r,has:new Map,median:new Map},B.current.set(e,n)),n}function ut(e,t,n){let r=lt(e,t),i=r.has.get(n);if(i===void 0){let e=t.pts.cols.get(n);i=!!e&&e.some(Number.isFinite),r.has.set(n,i)}return i}function dt(e,t){return ct(e).some((e,n)=>ut(n,e,t))}function ht(e,t){let n=ct(e);for(let e=0;e<n.length;e++){if(!ut(e,n[e],t))continue;let r=lt(e,n[e]),i=r.median.get(t);return i===void 0&&(i=WU(n[e].pts,t),r.median.set(t,i)),i}return 0}function gt(){if(Ge.current)return Ge.current;let e=k.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return Ge.current=n,n}function _t(){let e=k.current,t=Math.max(1,e?.clientWidth||200),n=e?.clientHeight??0;return{w:t,h:Math.max(1,n>0?n:qe.current.height)}}function yt(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function bt(){let e=E.current;if(!e)return;let{w:t,h:n}=_t(),r=yt(e,t,n);if(!r)return;{let e=ot(),t=it(),n=qe.current.series,r=ze.current;(r.pts!==e||r.x0!==t.xmin||r.x1!==t.xmax||r.ser!==n)&&(ze.current={pts:e,x0:t.xmin,x1:t.xmax,ser:n},DH(k.current))}let i=bU(t),a=i===vU,{top:o,right:s,bottom:c}=i,l=i.left,u=t-l-s,d=n-o-c,{bg:f,muted:p,grid:m}=gt(),{xLabel:h,series:g,xAxisLine:_,yAxisLine:v,gridLine:y,lineWidth:b,columnUnits:x,showLatestValues:S}=qe.current,C=ot();if(r.fillStyle=f,r.fillRect(0,0,t,n),BU(C)<2||u<=0||d<=0){if(r.fillStyle=p,r.font=`13px ${Q.sans}`,zV(r),M.current&&(M.current.resize(t,n,window.devicePixelRatio||1),M.current.draw([])),P.current){P.current.resize(t,n,window.devicePixelRatio||1);for(let e=0;e<V.current.length;e++)P.current.clear(e);V.current=[]}return}let{xmin:w,xmax:O}=it(),A=O-w,j=e=>l+(e-w)/A*u;T({left:l,top:o,width:u,height:d,x:{v0:w,v1:O}});let R=g.filter(e=>e.bandToPct>e.bandFromPct&&e.scaleMin!==e.scaleMax&&dt(C,e.column)),z=HU(R),B=UU(z,o,d),ee=new Map;for(let e of z){let t=B.get(e.leader.id);t!==void 0&&e.members.forEach(e=>ee.set(e.id,t))}let te=new Set,H=new Set;for(let e of z)e.members.length>1&&e.members.forEach(e=>te.add(e.id)),H.add(e.leader.id);let ne=`11px ${Q.mono}`,re=R.map(e=>{let{bandTop:t,bandBottom:n}=LU(o,d,e.bandFromPct,e.bandToPct),r=Math.min(e.scaleMin,e.scaleMax),i=Math.max(e.scaleMin,e.scaleMax),{majorStep:a,minorStep:s}=kz(e.scaleMin,e.scaleMax,e.yMajorStep??0,e.yMinorStep??0),c=a,l=Az(r,i,c);l.length>120&&(l=Az(r,i,c=kz(e.scaleMin,e.scaleMax,0,0).majorStep));let u=jz(r,i,s,l);return u.length>400&&(u=[]),{s:e,bandTop:t,bandBottom:n,majors:l,minors:u,step:c}}),ie=new Map,U=0;{r.save(),r.font=ne;let e=re.filter(e=>H.has(e.s.id));e.sort((e,t)=>{let n=Math.abs(e.s.bandToPct-e.s.bandFromPct),r=Math.abs(t.s.bandToPct-t.s.bandFromPct);return n===r?re.indexOf(e)-re.indexOf(t):r-n});let n=new Map,a=[];for(let t of e){let r=0;for(;r<e.length;r++){let e=a[r];if(!e||e.length===0||!e.some(e=>t.bandTop<e.bandBottom&&t.bandBottom>e.bandTop))break}n.set(t.s.id,r),a[r]||(a[r]=[]),a[r].push(t)}let o=new Map,c=new Map;for(let t of e){let e=0;for(let n of t.majors){let i=Pz(n,t.step),a=c.get(i);a===void 0&&c.set(i,a=r.measureText(i).width),a>e&&(e=a)}o.set(t.s.id,e)}let u=[],d=[],f=0;for(let e=0;e<a.length;e++){u[e]=f;let t=0;for(let n of a[e]??[]){let e=o.get(n.s.id)??0;e>t&&(t=e)}d[e]=t,f+=t+22}for(let e of re){let t=n.get(e.s.id)??0;ie.set(e.s.id,u[t]??0)}let p=i.left;for(let e=0;e<a.length;e++){let t=a[e];if(!t||t.length===0)continue;let n=(u[e]??0)+PU+NU+(d[e]??0)+6;n>p&&(p=n)}let m=Math.max(i.left,t-s-Math.max(120,t*.4)),h=Math.min(Math.ceil(p),m);h>l&&(U=h-l),r.restore()}U>0&&(l+=U,u=Math.max(1,t-l-s)),oe.current=zH(u,window.devicePixelRatio||1);let ae=(e,t)=>1-(1-e)**t,se=new Map,ce=new Map;for(let e of re){let t=`${e.bandTop}|${e.bandBottom}|${e.s.scaleMin}|${e.s.scaleMax}|${e.majors.join(`,`)}`,n=se.get(t);n?n.k++:se.set(t,{c:e,k:1});let r=te.has(e.s.id)?p:e.s.color,i=`${e.bandTop}|${e.bandBottom}|${r}`,a=ce.get(i);a?a.k++:ce.set(i,{c:e,color:r,k:1})}if((v?.style??`dashed`)!==`none`)for(let{c:{s:e,bandTop:t,bandBottom:n,majors:i},k:a}of se.values()){r.save(),r.strokeStyle=v?.color??m,r.globalAlpha=ae(.1,a),r.lineWidth=v?.width??1,r.lineCap=`round`,r.setLineDash(mU(v?.style??`dashed`));for(let a of i){let i=IU(a,t,n,e.scaleMin,e.scaleMax);r.beginPath(),r.moveTo(l,i),r.lineTo(l+u,i),r.stroke()}r.restore()}for(let{c:{bandTop:e,bandBottom:t},color:n,k:i}of ce.values())r.strokeStyle=n,r.lineWidth=1,r.setLineDash([]),r.globalAlpha=ae(.45,i),r.beginPath(),r.moveTo(l,e),r.lineTo(l,t),r.stroke(),r.globalAlpha=1;for(let{s:e,bandTop:t,bandBottom:n,majors:i,minors:o,step:s}of a?[]:re){let a=te.has(e.id)?p:e.color;if(H.has(e.id)){let c=ie.get(e.id)??0,u=l-c-PU;r.strokeStyle=a,r.lineWidth=1;for(let i of o){let a=IU(i,t,n,e.scaleMin,e.scaleMax);r.beginPath(),r.moveTo(u-MU,a),r.lineTo(u,a),r.stroke()}r.font=ne,r.textAlign=`right`,r.textBaseline=`middle`,r.strokeStyle=a,r.fillStyle=a;for(let a of i){let i=IU(a,t,n,e.scaleMin,e.scaleMax);r.beginPath(),r.moveTo(u-jU,i),r.lineTo(u,i),r.stroke(),r.fillText(Pz(a,s),u-NU,i)}}}if((y?.style??`solid`)!==`none`&&(r.strokeStyle=y?.color??m,r.lineWidth=y?.width??1,r.setLineDash(mU(y?.style??`solid`)),r.strokeRect(l,o,u,d),r.setLineDash([])),(_?.style??`dashed`)!==`none`){r.strokeStyle=_?.color??m,r.lineWidth=_?.width??1,r.setLineDash(mU(_?.style??`dashed`));for(let e=1;e<6;e++){let t=l+e/6*u;r.beginPath(),r.moveTo(t,o),r.lineTo(t,o+d),r.stroke()}r.setLineDash([])}let le=o+d+10;r.fillStyle=p,r.font=`11px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`top`;let ue=Rz(h,w,w+A);for(let e=0;e<=(a?-1:6);e++){let t=w+e/6*A;r.fillText(ue?Jz(t,A/6,A):Pz(t,A/6),l+e/6*u,le)}r.textBaseline=`bottom`,a||r.fillText(h,l+u/2,n-5);let{shiftMode:fe}=qe.current;fe&&(r.globalAlpha=.8,r.font=`10px ${Q.sans}`,r.fillStyle=p,r.textAlign=`center`,r.textBaseline=`top`,r.fillText(`⇄ shifting: ${fe.label}`,l+u/2,o+3),r.globalAlpha=1);let pe=qe.current.envelopes;if(pe?.length){r.save(),r.beginPath(),r.rect(l,o,u,d),r.clip();for(let e of pe){let t=R.find(t=>t.id===e.seriesId||t.id.startsWith(`${e.seriesId}__`));if(!t)continue;let{bandTop:n,bandBottom:i}=LU(o,d,t.bandFromPct,t.bandToPct),a=e=>IU(e,n,i,t.scaleMin,t.scaleMax);r.fillStyle=e.color,r.globalAlpha=.2;let s=0;for(;s<e.x.length;){for(;s<e.x.length&&e.lo[s]!==e.lo[s];)s++;let t=s;for(;s<e.x.length&&e.lo[s]===e.lo[s];)s++;if(!(s-t<2)){r.beginPath(),r.moveTo(j(e.x[t]),a(e.hi[t]));for(let n=t+1;n<s;n++)r.lineTo(j(e.x[n]),a(e.hi[n]));for(let n=s-1;n>=t;n--)r.lineTo(j(e.x[n]),a(e.lo[n]));r.closePath(),r.fill()}}}r.restore()}L.current&&=(clearTimeout(L.current),null);let me=fU&&!F.current?P.current:null;if(fU&&!me&&!F.current&&D.current&&!I.current&&(me=sH()?gH(D.current,1,ye):_H(D.current),me?(P.current=me,I.current=!0):F.current=!0),me){me.resize(t,n,window.devicePixelRatio||1);let e=`${l.toFixed(2)}|${u.toFixed(2)}|${o}|${d}|${b}|`+R.map(e=>`${e.id}:${e.column}:${e.bandFromPct}:${e.bandToPct}:${e.scaleMin}:${e.scaleMax}:${e.color}`).join(`,`),r=ct(C),i=V.current;for(let t=0;t<Math.max(r.length,i.length);t++){let n=r[t];if(!n){i[t]&&me.clear(t),i[t]=null;continue}let a=R.filter(e=>ut(t,n,e.column)),s=a.map(e=>e.column).join(`
|
|
207
|
-
`),c=i[t];if(c&&c.pts===n.pts&&c.sig===e&&c.cols===s)continue;i[t]={pts:n.pts,sig:e,cols:s};let f={styles:a.map(e=>{let{bandTop:t,bandBottom:r}=LU(o,d,e.bandFromPct,e.bandToPct);return{color:UV(e.color),bandTop:t,bandBottom:r,scaleMin:e.scaleMin,scaleMax:e.scaleMax,gapMedian:n.pts.hold?YU:ht(C,e.column),width:b}}),left:l,plotW:u,xmin:w,xmax:O,cut:de.current};if(c&&c.pts===n.pts&&c.cols===s){me.setStyle(t,f);continue}let p=n.pts,m=!!c&&c.pts.x===p.x&&c.pts.brk===p.brk&&c.cols===s;me.setData(t,{...f,xs:m?null:p.x.slice(),breaks:m?void 0:p.brk?.slice(),columns:a.map(e=>VU(p,e.column))})}i.length=r.length,me.setView(w,O,de.current)}else{let e=M.current;dU&&!e&&!N.current&&D.current&&!I.current&&(e=YV(D.current),e?M.current=e:N.current=!0);let i=!!e;i&&e&&e.resize(t,n,window.devicePixelRatio||1);let a=[],s=st(C,R.map(e=>e.column),A);for(let e of R){let{bandTop:t,bandBottom:n}=LU(o,d,e.bandFromPct,e.bandToPct),c=s.get(e.column);if(i){let r={x:l,y:t,w:u,h:n-t},i=UV(e.color),o=[],s=null,d=()=>{o.length>=4&&a.push({points:Float32Array.from(o),color:i,clip:r,width:b}),o=[]};for(let r of C){let i=r.cols.get(e.column);if(i){s=null;for(let a=0;a<r.length;a++){r.brk?.[a]&&d();let l=i[a];if(!Number.isFinite(l))continue;let u=r.x[a];s!==null&&!r.hold&&Math.abs(u-s)>c&&d(),o.push(j(u),IU(l,t,n,e.scaleMin,e.scaleMax)),s=u}d()}}d();continue}r.strokeStyle=e.color,r.lineWidth=b,r.lineJoin=`round`,r.lineCap=`round`,r.save(),r.beginPath(),r.rect(l,t,u,n-t),r.clip(),r.beginPath();let f=!1,p=null,m=!1;for(let i of C){let a=i.cols.get(e.column);if(a){m=!0;for(let o=0;o<i.length;o++){i.brk?.[o]&&(m=!0);let s=a[o];if(!Number.isFinite(s))continue;let l=i.x[o],u=j(l),d=IU(s,t,n,e.scaleMin,e.scaleMax);f?m||p!==null&&!i.hold&&Math.abs(l-p)>c?(r.stroke(),r.beginPath(),r.moveTo(u,d),p=l,m=!1):(r.lineTo(u,d),p=l):(r.moveTo(u,d),f=!0,p=l,m=!1)}}}f&&r.stroke(),r.restore()}i&&e&&e.draw(a)}for(let e of R){if(!e.alarm)continue;let{bandTop:t,bandBottom:n}=LU(o,d,e.bandFromPct,e.bandToPct),i=IU(e.alarm.value,t,n,e.scaleMin,e.scaleMax);r.save(),r.beginPath(),r.rect(l,t,u,n-t),r.clip(),r.strokeStyle=e.alarm.color,r.lineWidth=e.alarm.width,r.setLineDash(e.alarm.linked===`active`?cU:mU(e.alarm.style)),r.beginPath(),r.moveTo(l,i),r.lineTo(l+u,i),r.stroke(),r.setLineDash([]),e.alarm.linked&&uU(r,l+u-10-3,i-10-2,e.alarm.color),r.restore()}if(a)return;let he=S?at(C,R.map(e=>e.column)):null,ge=e=>{let t=he?.get(e.column);if(typeof t!=`number`)return`-`;let n=x[e.column]?.trim()??``;return`${Fz(t)}${n?` ${n}`:``}`},_e=l+u+8;r.font=TU,r.textAlign=`left`;for(let e of z){let t=B.get(e.leader.id);if(t===void 0)continue;let i=e.members.length>1;if(r.fillStyle=i?p:e.leader.color,r.globalAlpha=1,r.fillText(e.base,_e,t+EU),i){let i=zU(e.members.length,t,n);for(let n=0;n<i;n++)r.fillStyle=e.members[n].color,r.globalAlpha=kU,r.fillText(ge(e.members[n]),_e,t+EU+(n+1)*AU)}else r.fillStyle=e.leader.color,r.globalAlpha=kU,r.fillText(ge(e.leader),_e,t+DU);r.globalAlpha=1}}function xt(){let e=O.current;if(!e)return;let{w:t,h:n}=_t(),r=yt(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let{top:i,right:a,bottom:o,left:s}=bU(t),c=t-s-a,l=n-i-o,{series:u,columnUnits:d,xLabel:f}=qe.current,p=ot();if(Ee.current&&c>0&&l>0){let e=De.current,t=Oe.current,n=ke.current,i=Ae.current,a=Math.min(e,n),o=Math.min(t,i),s=Math.abs(n-e),c=Math.abs(i-t);r.fillStyle=`rgba(59, 130, 246, 0.12)`,r.fillRect(a,o,s,c),r.strokeStyle=`rgba(59, 130, 246, 0.85)`,r.setLineDash([4,3]),r.lineWidth=1,r.strokeRect(a,o,s,c),r.setLineDash([])}let m=R.current;if(m===null||BU(p)<2||c<=0||l<=0)return;let{xmin:h,xmax:g}=it(),_=u.filter(e=>e.bandToPct>e.bandFromPct&&e.scaleMin!==e.scaleMax&&dt(p,e.column)),v=[...new Set(_.map(e=>e.column))],y=st(p,v,g-h),{bg:b,muted:x}=gt();r.strokeStyle=x,r.globalAlpha=.5,r.lineWidth=1,r.beginPath(),r.moveTo(m,i),r.lineTo(m,i+l),r.stroke(),r.globalAlpha=1;let S=HU(_),C=UU(S,i,l),w=s+c+8;r.font=TU,r.textAlign=`left`;let T=NH(m,s,c,h,g),E=PH(p,T,v,y),D=e=>{let t=E.get(e.column);if(typeof t!=`number`)return`-`;let n=d[e.column]?.trim()??``;return`${Fz(t)}${n?` ${n}`:``}`};for(let e of S){let t=C.get(e.leader.id)??LU(i,l,e.leader.bandFromPct,e.leader.bandToPct).bandTop;if(e.members.length>1){let i=e.members.length*AU+4;r.fillStyle=b,r.fillRect(s+c+6,t+EU+2,a-8,i);let o=zU(e.members.length,t,n);for(let n=0;n<o;n++){let i=e.members[n];r.fillStyle=i.color,r.globalAlpha=kU,r.fillText(D(i),w,t+EU+(n+1)*AU)}}else{let n=e.leader;r.fillStyle=b,r.fillRect(s+c+6,t+EU+2,a-8,DU-EU+6),r.fillStyle=n.color,r.globalAlpha=kU,r.fillText(D(n),w,t+DU)}r.globalAlpha=1}let k=/^(.*?)\s*\(([^)]*)\)\s*$/.exec(f),A=k?k[1]:f,j=k?k[2].trim():``,M=Rz(f,h,g)?Yz(T):``,N=M.lastIndexOf(` `),P=M?[`${A} ${M.slice(0,N)}`,M.slice(N+1)]:[`${A} ${Math.round(T)}${j}`];r.font=TU,r.textAlign=`left`,r.textBaseline=`alphabetic`,P.forEach((e,t)=>{let n=r.measureText(e).width,a=i+l-(P.length-1-t)*15;r.fillStyle=b,r.fillRect(w-2,a-11,n+6,15),r.fillStyle=x,r.globalAlpha=1,r.fillText(e,w,a)})}function St(){if(se.current){U.current=!0;return}He.current=()=>{bt(),xt()},!Be.current&&(Be.current=wH(e=>{Be.current=0;let t=k.current;t&&t.isConnected&&typeof t.checkVisibility==`function`&&!t.checkVisibility()||(Ue.current=e,He.current?.())}))}function Ct(){if(se.current){U.current=!0;return}let e=k.current?.ownerDocument.timeline?.currentTime;if(typeof e!=`number`||e===Ue.current){St();return}Ue.current=e,TH(Be.current),Be.current=0,bt(),xt()}function wt(){We.current=xt,!Ve.current&&(Ve.current=wH(()=>{Ve.current=0,We.current?.()}))}function Tt(e){re.current=wH(Tt);let t=se.current;if(!t)return;me.current+=(Math.min(50,pe.current?e-pe.current:16)-me.current)*.1,pe.current=e;let n=k.current;if(!(he.current&&(!n||typeof n.checkVisibility!=`function`||n.checkVisibility()))){if(!ge.current){ge.current=!0;let e=P.current;e&&(V.current.forEach((t,n)=>{t&&e.clear(n)}),V.current=[],e.resize(1,1,1))}return}if(ge.current=!1,fe.current&&e-fe.current<wU-me.current/2)return;fe.current=e;let r=t.xBounds();r&&r[1]>r[0]&&(nt.current={xmin:r[0],xmax:r[1]});let i=ue.current?e-ue.current:16;ue.current=e,i>250&&(H.current=null,ne.current=null);let a=t.latestT?.(),o;if(a!==void 0&&t.xAtTime&&Number.isFinite(a)){let e=t.id?WH(t.id,a,performance.now()):XH(le.current,a,i),n=t.xAtTime(e);Number.isFinite(n)&&(o=n)}if(rt()){let n=o??t.latestX?.()??nt.current.xmax,r=be.current,i=r!=null&&t.spanForSeconds?t.spanForSeconds(r):r??we.current,[a,s]=RH(nt.current.xmin,nt.current.xmax,i,n??void 0);if(!t.spanForSeconds&&o!==void 0&&o>a&&(s=Math.min(s,o)),Number.isFinite(a)&&Number.isFinite(s)&&s>a){let t=s-a,n=ne.current!==null&&s<ne.current-t;if(H.current===null||ne.current===null||n)H.current=a,ne.current=s,ie.current=e;else{let n=ie.current;ie.current=e;let r=LH(n?Math.min(64,e-n):16,xU);H.current+=(a-H.current)*r,ne.current+=(s-ne.current)*r,Math.abs(a-H.current)<t*1e-6&&(H.current=a),Math.abs(s-ne.current)<t*1e-6&&(ne.current=s)}}}else H.current=null,ne.current=null,ie.current=0;let s=it(),c=t.version?.(),l=oe.current,u=ce.current,d=u!==null&&c!==void 0&&u.ver===c&&u.x0===s.xmin&&u.x1===s.xmax&&u.mp===l&&u.cut===o;(BU(Te.current)===0||!d&&e-ae.current>=CU)&&(ae.current=e,de.current=t.cutOnGpu&&P.current?o:void 0,Te.current=t.pull(s.xmin,s.xmax,l,o,de.current!==void 0),ce.current=c===void 0?null:{ver:c,x0:s.xmin,x1:s.xmax,mp:l,cut:o}),U.current=!1,bt(),xt()}function Et(){re.current||=(ie.current=0,wH(Tt))}function Dt(){re.current&&(TH(re.current),re.current=0,ue.current=0,H.current=null,ne.current=null,Te.current=[],de.current=void 0)}W(()=>{let e=k.current,t=e?.ownerDocument.defaultView?.IntersectionObserver;if(!e||!t)return;let n=new t(e=>{let t=e[e.length-1];(t.isIntersecting||t.boundingClientRect.width>0)&&(he.current=t.isIntersecting)});return n.observe(e),()=>{n.disconnect(),he.current=!0}},[]),W(()=>(y?Et():(Dt(),St()),Dt),[!!y]),W(()=>rB(k.current,()=>{Ge.current=null,St()}),[]),W(()=>{Ge.current=null,St()},[o]);let Ot=!!f;W(()=>{let e=O.current;e&&(e.style.cursor=Ot?`ew-resize`:``),St()},[Ot,f?.label??``]);let kt=s?.[0]??null,At=s?.[1]??null;return G(()=>{ee.current===kt&&te.current===At||(ee.current=kt,te.current=At,St())},[kt,At]),W(()=>{Ct()},[t,n,i,e,p,m,h,g,v,Ke]),W(()=>()=>{TH(Be.current),TH(Ve.current),Be.current=0,Ve.current=0},[]),W(()=>{let e=O.current,t=k.current;if(!e||!t)return;let n=()=>{let e=Math.round(t.clientWidth);e>0&&e!==j.current&&(j.current=e,A.current?.(e))};n();let r=new AH(()=>{Ge.current=null,n(),St()});r.observe(t);let i=MH(e=>Ze.current?.(e)),a=t=>{if(Ee.current||Re.current!==null)return;if(BU(ot())<2){R.current!==null&&(R.current=null,wt(),i.set(null));return}let n=e.getBoundingClientRect(),r=t.clientX-n.left,a=t.clientY-n.top,{left:o,top:s,right:c,bottom:l}=bU(n.width),u=Math.max(1,n.width-o-c),d=n.height-s-l;if(r<o||r>o+u||a<s||a>s+d){R.current!==null&&(R.current=null,wt(),i.set(null));return}R.current!==r&&(R.current=r,wt());let{xmin:f,xmax:p}=it();i.set(NH(r,o,u,f,p))},o=()=>{R.current!==null&&(R.current=null,wt()),i.set(null)},s=e=>{Je.current&&clearTimeout(Je.current),Je.current=setTimeout(()=>{Je.current=null,Xe.current?.(e)},pU)},c=t=>{if(je.current!==`none`||t.buttons&2||Date.now()-Pe.current<300||BU(ot())<2)return;let n=e.getBoundingClientRect(),r=t.clientX-n.left,i=t.clientY-n.top,{top:a,left:o,right:c,bottom:l}=bU(n.width),u=Math.max(1,n.width-o-c),d=Math.max(1,n.height-a-l);if(r<o||r>o+u||i<a||i>a+d)return;t.preventDefault();let f=nt.current,p=f.xmax-f.xmin;if(!(p>0))return;if(Ce.current===`follow`&&rt()&&!xe.current){we.current=VH(we.current,p,t.deltaY<0,p*.001);return}if(Ce.current===`follow`&&rt()){let e=VH(be.current,se.current?.bufferedSeconds?.()??p,t.deltaY<0);be.current=e,Ye.current&&clearTimeout(Ye.current),Ye.current=setTimeout(()=>{Ye.current=null,xe.current?.(e)},pU);return}let m=ee.current??f.xmin,h=(te.current??f.xmax)-m;if(!(h>0))return;let g=Date.now();g-Ne.current>300&&(Fe.current=ee.current,Ie.current=te.current),Ne.current=g;let _=m+(r-o)/u*h,v=t.deltaY<0,y=.88,b=v?h*y:h/y,x=Math.max(p*1e-7,1e-12);if(v)b=Math.max(b,x);else{if(b>=p*.999){ee.current=null,te.current=null,s(null),Qe.current?.publish($e.current??``,null),St();return}b=Math.min(b,p)}let S=(_-m)/h,C=_-S*b,w=_+(1-S)*b;C<f.xmin&&(w+=f.xmin-C,C=f.xmin),w>f.xmax&&(C-=w-f.xmax,w=f.xmax),w-C<b-1e-12&&(C=Math.max(f.xmin,_-b/2),w=C+b,w>f.xmax&&(w=f.xmax,C=w-b)),w-C>=p*.999?(ee.current=null,te.current=null,s(null),Qe.current?.publish($e.current??``,null)):(ee.current=C,te.current=w,s([C,w]),Qe.current?.publish($e.current??``,[C,w])),St()},l=e=>{if(e.preventDefault(),Pe.current=Date.now(),Date.now()-Ne.current<300){ee.current=Fe.current,te.current=Ie.current;let e=Fe.current,t=Ie.current;Je.current&&=(clearTimeout(Je.current),null),Xe.current?.(e===null&&t===null?null:[e,t]),Ne.current=0,St()}},u=t=>{if(t.button===0&&Le.current){let n=e.getBoundingClientRect(),{left:r,top:i,right:a,bottom:o}=bU(n.width),s=Math.max(1,n.width-r-a),c=n.height-i-o,l=t.clientX-n.left,u=t.clientY-n.top;if(l>=r&&l<=r+s&&u>=i&&u<=i+c){Re.current=t.clientX,Le.current.onDragStart();try{e.setPointerCapture(t.pointerId)}catch{}}return}if(t.button!==2)return;if(t.preventDefault(),t.buttons===0){et.current?.({clientX:t.clientX,clientY:t.clientY});return}if(je.current!==`none`){Ee.current=!1,je.current=`none`;try{e.releasePointerCapture(t.pointerId)}catch{}}let n=e.getBoundingClientRect(),r=t.clientX-n.left,i=t.clientY-n.top;Me.current=Date.now(),je.current=`menuOnly`,Ee.current=!1,De.current=r,Oe.current=i,ke.current=r,Ae.current=i;try{e.setPointerCapture(t.pointerId)}catch{}},d=t=>{if(Re.current!==null){let n=t.clientX-Re.current,r=e.getBoundingClientRect(),{left:i,right:a}=bU(r.width),o=Math.max(1,r.width-i-a),{xmin:s,xmax:c}=it(),l=c-s;l>0&&o>0&&Le.current?.onDragOffset(n/o*l);return}if(je.current===`none`)return;let n=e.getBoundingClientRect(),r=t.clientX-n.left,i=t.clientY-n.top;if(je.current===`menuOnly`){if(Date.now()-Me.current<150)return;let e=r-De.current,t=i-Oe.current;if(Math.sqrt(e*e+t*t)<12)return;let a=ot(),{top:o,left:s,right:c,bottom:l}=bU(n.width),u=n.width-s-c,d=n.height-o-l,f=u>0&&d>0&&De.current>=s&&De.current<=s+u&&Oe.current>=o&&Oe.current<=o+d;if(BU(a)<2||!f)return;je.current=`rubber`,Ee.current=!0,R.current=null}je.current===`rubber`&&(t.preventDefault(),ke.current=r,Ae.current=i,wt())},f=t=>{if(t.button!==2)return;t.preventDefault();let n=je.current;je.current=`none`;try{e.releasePointerCapture(t.pointerId)}catch{}if(n===`menuOnly`){Ee.current=!1,wt(),et.current?.({clientX:t.clientX,clientY:t.clientY});return}if(n!==`rubber`||!Ee.current){Ee.current=!1,wt();return}Ee.current=!1;let r=ot(),i=e.getBoundingClientRect(),{left:a,right:o}=bU(i.width),s=Math.max(1,i.width-a-o),c=De.current,l=ke.current,u=Math.abs(l-c);if(BU(r)<2||u<12){et.current?.({clientX:t.clientX,clientY:t.clientY}),wt();return}let d=FU(Math.min(c,l),a,a+s),f=FU(Math.max(c,l),a,a+s),{xmin:p,xmax:m}=it(),h=m-p;if(!(h>0)){et.current?.({clientX:t.clientX,clientY:t.clientY}),wt();return}let g=p+(d-a)/s*h,_=p+(f-a)/s*h;if(g>_){let e=g;g=_,_=e}let v=nt.current,y=Math.min(v.xmin,v.xmax),b=Math.max(v.xmin,v.xmax);g=FU(g,y,b),_=FU(_,y,b);let x=_-g;if(x<=(b-y)*1e-12||x<=0){et.current?.({clientX:t.clientX,clientY:t.clientY}),wt();return}et.current?.({clientX:t.clientX,clientY:t.clientY,zoomXRange:[g,_]}),wt()},p=t=>{if(t.button===0&&Re.current!==null){Re.current=null;try{e.releasePointerCapture(t.pointerId)}catch{}return}if(t.button===2){f(t);return}if(t.buttons===0&&je.current!==`none`){je.current=`none`,Ee.current=!1;try{e.releasePointerCapture(t.pointerId)}catch{}et.current?.({clientX:t.clientX,clientY:t.clientY}),wt()}},m=t=>{Re.current!==null&&(Re.current=null),je.current!==`none`&&(Ee.current=!1,je.current=`none`);try{e.releasePointerCapture(t.pointerId)}catch{}wt()},h=t=>{if(t.button!==0||BU(ot())<2)return;let n=e.getBoundingClientRect(),r=t.clientX-n.left,i=t.clientY-n.top,{top:a,left:o,right:s,bottom:c}=bU(n.width),l=Math.max(1,n.width-o-s),u=Math.max(1,n.height-a-c);r<o||r>o+l||i<a||i>a+u||ee.current===null&&te.current===null||(ee.current=null,te.current=null,Je.current&&=(clearTimeout(Je.current),null),Xe.current?.(null),Qe.current?.publish($e.current??``,null),St(),wt())},g=e=>{if(e.key!==`Escape`)return;let t=!1;je.current!==`none`&&(je.current=`none`,Ee.current=!1,t=!0),Re.current!==null&&(Re.current=null,t=!0),t&&wt()};e.addEventListener(`mousemove`,a),e.addEventListener(`mouseleave`,o),e.addEventListener(`wheel`,c,{passive:!1}),e.addEventListener(`contextmenu`,l),e.addEventListener(`pointerdown`,u),e.addEventListener(`pointermove`,d),e.addEventListener(`pointerup`,p),e.addEventListener(`pointercancel`,m),e.addEventListener(`dblclick`,h);let _=e.ownerDocument.defaultView??window;return _.addEventListener(`keydown`,g),()=>{r.disconnect(),e.removeEventListener(`mousemove`,a),e.removeEventListener(`mouseleave`,o),e.removeEventListener(`wheel`,c),e.removeEventListener(`contextmenu`,l),e.removeEventListener(`pointerdown`,u),e.removeEventListener(`pointermove`,d),e.removeEventListener(`pointerup`,p),e.removeEventListener(`pointercancel`,m),e.removeEventListener(`dblclick`,h),_.removeEventListener(`keydown`,g),Je.current&&clearTimeout(Je.current),Ye.current&&clearTimeout(Ye.current)}},[]),vt(`div`,{ref:k,className:`chart-canvas-wrap`,children:[q(`canvas`,{ref:E,className:`chart-canvas`,role:`img`,"aria-label":`Chart of ${e}`}),q(`canvas`,{ref:D,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}},_e),q(`canvas`,{ref:O,className:`chart-canvas chart-overlay`})]})}function QU(){try{if(localStorage.getItem(`perfLog`)===`1`)return!0;if(localStorage.getItem(`perfLog`)===`0`)return!1}catch{}return!1}var $U=!1;function eW(){let e=QU();return e&&!$U&&($U=!0,console.log(`[perf] logging enabled — zoom an out-of-core chart to see decimate()/sampleRows timings`)),e}eW();var tW=new Map;function nW(e,t){let n=(tW.get(e)??0)+1;tW.set(e,n),console.log(`[perf] ${e} #${n} ${t.toFixed(1)}ms`)}async function rW(e,t){if(!eW())return t();let n=performance.now();try{return await t()}finally{nW(e,performance.now()-n)}}var iW=20;async function aW(e,t,n,r){let{x0:i,bucket:a,rows:o,columns:s}=await rW(`decimate(${t.length}col)`,()=>e.getSeriesMulti(t,n,r));return Ce(o,s,i,a)}function oW(e,t,n,r,i=0,a=!1,o=0){let[s,c]=pt({points:M,fetchedViewport:null}),[l,u]=pt(!1),d=`${t.join(`,`)}|${n?`${n.xKey}:${n.x0}:${n.x1}`:`none`}|${r}|${i}`,f=ft(()=>{if(!a||!e?.getSeriesMultiSync||!n||t.length===0)return null;let i=o>0?e.getColumnsSync?.(t,n,o):null;if(i)return{points:i,loading:!1,fetchedViewport:n,full:!0};let s=e.getSeriesMultiSync(t,n,r);return{points:Ce(s.rows,s.columns,s.x0,s.bucket),loading:!1,fetchedViewport:n}},[a,e,d,o]);return W(()=>{if(a)return;if(!e||!n||t.length===0){c({points:M,fetchedViewport:null});return}let i=!0;u(!0);let o=setTimeout(()=>{aW(e,t,n,r).then(t=>{i&&(c({points:t,fetchedViewport:n,source:e}),u(!1))}).catch(()=>{i&&u(!1)})},iW);return()=>{i=!1,clearTimeout(o)}},[e,d,a]),f||(s.source!==void 0&&s.source!==e?{points:M,loading:l,fetchedViewport:null}:{points:s.points,loading:l,fetchedViewport:s.fetchedViewport})}var sW=250,cW=2,lW=6e3,uW=2e6,dW=[];function fW(e,t,r,i,a,o){let s=!!e&&e.columnSet.has(r),c=ft(()=>e&&s?t.filter(t=>e.columnSet.has(t)):dW,[e,s,t]),l=e&&s&&c.length>0?e.source:null,d=!!l&&!e?.live&&!!l.getSeriesMultiSync&&!!l.xBoundsSync,f=ft(()=>d&&l?l.xBoundsSync(r):null,[d,l,r]),[p,m]=pt(null),h=!!e?.live;W(()=>{if(!l||d)return;let e=!0,t=()=>l.xBounds(r).then(t=>{let n=l.version?.()??0;e&&m(e=>e&&e.source===l&&e.xKey===r&&e.ver===n?e:{source:l,xKey:r,b:t,ver:n})}).catch(()=>{});t();let n=h?setInterval(t,sW):void 0;return()=>{e=!1,clearInterval(n)}},[l,r,h,d]);let g=p&&p.source===l&&p.xKey===r?p:null,_=f??g?.b??null,v=g?.ver??0,{points:y,loading:b,full:x}=oW(l,c,l&&_&&_.x1>_.x0?{xKey:r,x0:_.x0,x1:_.x1}:null,Math.min(lW,a*cW),v,d,o),S=e?.xOffset??0,C=i&&i[1]>i[0]?i[0]-S:null,w=i&&i[1]>i[0]?i[1]-S:null,T=x||!!_&&C!==null&&w!==null&&C<=_.x0&&w>=_.x1,{points:E,fetchedViewport:D}=oW(l,c,l&&C!==null&&w!==null&&!T?{xKey:r,x0:C,x1:w}:null,a,v,d,o),O=ft(()=>!D||E.length===0?y:N([u(y,e=>e<D.x0),E,u(y,e=>e>D.x1)]),[y,E,D]),k=!!l&&(_===null||b);return ft(()=>e?{points:n(O,e.keySuffix,e.xOffset),bounds:_?{x0:_.x0+e.xOffset,x1:_.x1+e.xOffset}:null,loading:k}:{points:M,bounds:null,loading:!1},[e,O,_,k])}var pW=new WeakMap,mW=0;function hW(e){if(e.key!==void 0)return e.key;let t=pW.get(e.source);return t===void 0&&pW.set(e.source,t=mW++),`${t}${e.keySuffix}`}function gW(){let[e,t]=pt(()=>new Map);return[e,lt((e,n)=>t(t=>{if(n?t.get(e)===n:!t.has(e))return t;let r=new Map(t);return n?r.set(e,n):r.delete(e),r}),[])]}var _W=st(function({id:e,layer:t,columns:n,xKey:r,view:i,mp:a,rawLimit:o,report:s}){let c=fW(t,n,r,i,a,o);return G(()=>{s(e,c)},[e,c,s]),G(()=>()=>s(e,null),[e,s]),null});function vW({layers:e,xKey:t,columns:n,maxPoints:r,...i}){let a=i.viewXRange??null,[o,s]=pt(null),c=typeof window<`u`?Math.min(3,Math.max(1,window.devicePixelRatio||1)):1,l=o==null?r:Math.min(r,Math.round(o*c/50)*50),u=Math.max(1e3,Math.round(l/Math.sqrt(Math.max(1,e.length)))),d=Math.floor(uW/Math.max(1,e.length)),[f,p]=gW(),m=ft(()=>e.map(hW),[e]),h=ft(()=>m.map(e=>f.get(e)),[m,f]),g=ft(()=>h.flatMap(e=>e&&e.points.length>0?[e.points]:[]),[h]),_=ft(()=>{let e=1/0,t=-1/0;for(let n of h){let r=n?.bounds;r&&(e=Math.min(e,r.x0),t=Math.max(t,r.x1))}return Number.isFinite(e)&&t>e?[e,t]:null},[h]),v=h.some(e=>!e||e.loading);return vt(_t,{children:[e.map((e,r)=>q(_W,{id:m[r],layer:e,columns:n,xKey:t,view:a,mp:u,rawLimit:d,report:p},m[r])),g.length===0?vt(`div`,{className:`chart-placeholder chart-placeholder--no-data`,onContextMenu:e=>{e.preventDefault(),i.onPlotContextMenu?.({clientX:e.clientX,clientY:e.clientY})},children:[q(`span`,{className:`content-empty-icon`,"aria-hidden":!0}),q(`h2`,{children:v?`Loading…`:`No data to plot`}),v?null:q(`p`,{children:`None of the selected datasets has this X column together with a plotted channel.`})]}):q(ZU,{points:g,fullXRange:_,...i,onPlotWidthCss:s})]})}function yW(e){return!!e&&!Array.isArray(e)&&typeof e.length==`number`&&`x`in e&&`y`in e}function bW(e){let t=e.length,n=new Float64Array(t),r=new Float64Array(t),i=t>0&&e[0].c!==void 0?new Float32Array(t):void 0,a=e.some(e=>e.d!==void 0)?new Uint8Array(t):void 0;for(let o=0;o<t;o++){let t=e[o];n[o]=t.x,r[o]=t.y,i&&(i[o]=t.c??0),a&&(a[o]=t.d??0)}return{length:t,x:n,y:r,c:i,d:a}}function xW(e,t,n){let r=n?.get(t);if(r)return r;let i=Ae(e);if(i)return Ue(i,t);if(e.length===0||!(t in e[0]))return;let a=new Float64Array(e.length);for(let n=0;n<e.length;n++){let r=e[n][t];a[n]=typeof r==`number`?r:NaN}return a}function SW(e,t,n){let r=xW(e,t,n);if(!r||c.has(r))return r;let i=0;for(let e=0;e<r.length;e++)r[e]-r[e]===0&&i++;if(i===r.length)return r;let a=new Float64Array(i);for(let e=0,t=0;e<r.length;e++)r[e]-r[e]===0&&(a[t++]=r[e]);return a}function CW(e,t,n,r){if(!n){let n=SW(e,t,r);return n?[{label:t,values:n}]:[]}let i=xW(e,t,r);if(!i)return[];let a=i.length,o=r?.has(n)||e.length>0&&typeof e[0][n]==`number`?xW(e,n,r):void 0,s=t=>{if(o){let e=o[t];return e===e?String(e):`unknown`}return String(e[t]?.[n]??`unknown`)},c=new Map,l=[],u=new Int32Array(a),d=[];for(let e=0;e<a;e++){if(i[e]-i[e]!==0){u[e]=-1;continue}let t=s(e),n=c.get(t);n===void 0&&(c.set(t,n=l.length),l.push(t),d.push(0)),u[e]=n,d[n]++}let f=l.map((e,t)=>({label:e,values:new Float64Array(d[t])})),p=new Int32Array(l.length);for(let e=0;e<a;e++){let t=u[e];t>=0&&(f[t].values[p[t]++]=i[e])}return f}function wW(e){let t=NaN,n=NaN,r=0;for(let i=0;i<e.length;i++){let a=e[i];a-a===0&&(r===0&&(t=a),n=a,r++)}let i=n-t;return r>1&&i>0?(r-1)/i:null}function TW(e,t,n){let r=0;for(let i=0;i<e.length;i++)e[i]>=t&&e[i]<=n&&r++;let i=new Uint32Array(r),a=0;for(let r=0;r<e.length;r++)e[r]>=t&&e[r]<=n&&(i[a++]=r);return i}function EW(e,t){let n=new Float64Array(t.length);for(let r=0;r<t.length;r++)n[r]=e[t[r]];return n}function DW(e,t,n,r){let i=xW(e.rows,t,e.full),a=xW(e.rows,n,e.full);if(!i||!a)return null;let o=r.colorCol?xW(e.rows,r.colorCol,e.full):void 0;if(r.viewXRange){let t=xW(e.rows,r.xKey,e.full);if(t){let e=TW(t,r.viewXRange[0],r.viewXRange[1]);i=EW(i,e),a=EW(a,e),o&&=EW(o,e)}}let s=Math.min(i.length,a.length);if(!o)return{cols:{length:s,x:i,y:a}};let c=1/0,l=-1/0;for(let e=0;e<s;e++){let t=o[e];t<c&&(c=t),t>l&&(l=t)}if(!(l>c))return{cols:{length:s,x:i,y:a}};let u=new Float32Array(s),d=l-c;for(let e=0;e<s;e++){let t=o[e];u[e]=t===t?(t-c)/d:0}return{cols:{length:s,x:i,y:a,c:u},color:{label:r.colorCol,min:c,max:l}}}function OW(e,t,n,r){let i=[],a=[];e.forEach((e,o)=>{a.push(Zz(r.colorOverrides,e.id,o,r.palette));let s=DW(e,t,n,{xKey:r.xKey,viewXRange:r.viewXRange});i.push(s?.cols??{length:0,x:[],y:[]})});let o=i.reduce((e,t)=>e+t.length,0),s=new Float64Array(o),c=new Float64Array(o),l=new Uint8Array(o),u=0;return i.forEach((e,t)=>{for(let t=0;t<e.length;t++)s[u+t]=e.x[t],c[u+t]=e.y[t];l.fill(Math.min(t,255),u,u+e.length),u+=e.length}),{cols:{length:o,x:s,y:c,d:l},colors:a}}var kW=e=>yW(e)?e:bW(e),AW=(e,t,n)=>t===t&&n===n&&(!e||t>=e.xmin&&t<=e.xmax&&n>=e.ymin&&n<=e.ymax);function jW(e,t,n){let r=t+1,i=Array.from({length:r},()=>Array(r).fill(0)),a=Array(r).fill(0),o=new Float64Array(2*r-1),s=0;for(let t=0;t<e.length;t++){let c=e.x[t],l=e.y[t];if(AW(n,c,l)){s++,o[0]=1;for(let e=1;e<o.length;e++)o[e]=o[e-1]*c;for(let e=0;e<r;e++){for(let t=0;t<r;t++)i[e][t]+=o[e+t];a[e]+=o[e]*l}}}if(s<r)return null;let c=i.map((e,t)=>[...e,a[t]]);for(let e=0;e<r;e++){let t=e;for(let n=e+1;n<r;n++)Math.abs(c[n][e])>Math.abs(c[t][e])&&(t=n);if([c[e],c[t]]=[c[t],c[e]],Math.abs(c[e][e])<1e-10)return null;let n=c[e][e];for(let t=e;t<=r;t++)c[e][t]/=n;for(let t=0;t<r;t++){if(t===e)continue;let n=c[t][e];for(let i=e;i<=r;i++)c[t][i]-=n*c[e][i]}}return c.map(e=>e[r])}function MW(e,t,n){return jW(kW(e),t,n)}function NW(e,t){let n=kW(e),r=0,i=0;for(let e=0;e<n.length;e++)AW(void 0,n.x[e],n.y[e])&&(r++,i+=n.y[e]);if(r===0)return 0;let a=i/r,o=0,s=0;for(let e=0;e<n.length;e++){let r=n.x[e],i=n.y[e];if(!AW(void 0,r,i))continue;let c=0;for(let e=t.length-1;e>=0;e--)c=c*r+t[e];o+=(i-a)**2,s+=(i-c)**2}return o<1e-15?1:Math.max(0,1-s/o)}function PW(e,t=4){if(!Number.isFinite(e))return`?`;let n=Math.abs(e);return n===0?`0`:n>=1e5||n>0&&n<.001?e.toExponential(2):e.toPrecision(t).replace(/\.?0+$/,``)}function FW(e,t,n){let r=[];for(let n=e.length-1;n>=0;n--){let i=e[n];n===0?r.push(PW(i)):n===1?r.push(`${PW(i)}·${t}`):r.push(`${PW(i)}·${t}${n>1?`^${n}`:``}`)}return`${n} = ${r.join(` + `).replace(/\+ -/g,`− `)}`}var IW=[[0,45,80,160],[.25,40,145,175],[.5,60,180,110],[.75,220,175,55],[1,210,75,55]];function LW(e){let t=0;for(let n=1;n<IW.length;n++){if(e<=IW[n][0]){t=n-1;break}n===IW.length-1&&(t=n-1)}let n=t+1,r=(e-IW[t][0])/(IW[n][0]-IW[t][0]);return{r:Math.round(IW[t][1]+r*(IW[n][1]-IW[t][1])),g:Math.round(IW[t][2]+r*(IW[n][2]-IW[t][2])),b:Math.round(IW[t][3]+r*(IW[n][3]-IW[t][3]))}}function RW(e){let{r:t,g:n,b:r}=LW(e);return`rgb(${t},${n},${r})`}function zW(e,t){if(!Number.isFinite(e))return 0;let n=Math.floor(e*t);return n<0?0:n>=t?t-1:n}var BW=`#version 300 es
|
|
206
|
+
}`;function dH(e,t,n,r){let i=e.length,a=0;for(let t=0;t<i;t++)Number.isFinite(r[t])&&Number.isFinite(e[t])&&a++;if(a===i)return null;let o=new Float32Array(a),s=new Float32Array(a),c=new Uint8Array(a),l=0,u=!1;for(let a=0;a<i;a++)n[a]&&(u=!0),Number.isFinite(r[a])&&Number.isFinite(e[a])&&(o[l]=t[a],s[l]=r[a],u&&=(c[l]=255,!1),l++);return{x:o,y:s,starts:c}}function fH(e,t,n){let r=e.length,i=0;for(let t=0;t<r;t++)if(Number.isFinite(e[t])){i=e[t];break}let a=new Float32Array(r);for(let t=0;t<r;t++)a[t]=e[t]-i;let o=new Uint8Array(r);if(t)for(let e=0;e<r;e++)t[e]&&(o[e]=255);let s=n.map(t=>dH(e,a,o,t)??{x:a,y:t,starts:o}),c=s.map(e=>e.y.length),l=c.reduce((e,t)=>e+t,0),u=new Float32Array(l),d=new Float32Array(l),f=new Uint8Array(l),p=new Float32Array(l),m=0;return s.forEach((e,t)=>{u.set(e.x,m),d.set(e.y,m),f.set(e.starts,m),e.y.length>0&&(f[m]=255),p.fill(t,m,m+e.y.length),m+=e.y.length}),{origin:i,x:u,y:d,starts:f,sid:p,counts:c}}function pH(e,t,n,r,i,a){let o=(i-r)/a,s=(t,n)=>{let r=0,i=e.length;for(;r<i;){let a=r+i>>>1;(n?e[a]<=t:e[a]<t)?r=a+1:i=a}return r},c=s(r,!1),l=s(i,!0),u=t.length*(2*a+2),d=new Float32Array(u),f=new Float32Array(u),p=new Uint8Array(u),m=new Float32Array(u),h=0,g=(e,t,r)=>{d[h]=e-n,f[h]=t,m[h]=r,h++};return t.forEach((t,n)=>{let i=h;for(let r=c-1;r>=Math.max(0,c-64);r--)if(t[r]===t[r]){g(e[r],t[r],n);break}let s=c;for(let i=0;i<a&&s<l;i++){let c=i===a-1?1/0:r+(i+1)*o,u=1/0,d=-1/0,f=-1,p=-1;for(;s<l&&e[s]<c;s++){let e=t[s];e<u&&(u=e,f=s),e>d&&(d=e,p=s)}f<0||(f===p?g(e[f],u,n):f<p?(g(e[f],u,n),g(e[p],d,n)):(g(e[p],d,n),g(e[f],u,n)))}for(let r=l;r<Math.min(e.length,l+64);r++)if(t[r]===t[r]){g(e[r],t[r],n);break}h>i&&(p[i]=255)}),{x:d.subarray(0,h),y:f.subarray(0,h),starts:p.subarray(0,h),sid:m.subarray(0,h),bucket:o}}function mH(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 hH(e,t=1){let n=e.getContext(`webgl2`,{antialias:!1,alpha:!0,premultipliedAlpha:!0}),r=typeof HTMLCanvasElement<`u`&&e instanceof HTMLCanvasElement||typeof OffscreenCanvas<`u`&&e instanceof OffscreenCanvas;if(!n)return null;let i=()=>{let e=JV(n,n.VERTEX_SHADER,lH),t=JV(n,n.FRAGMENT_SHADER,uH);if(!e||!t)return null;let r=n.createProgram();return r?(n.attachShader(r,e),n.attachShader(r,t),n.linkProgram(r),n.getProgramParameter(r,n.LINK_STATUS)?{prog:r,vs:e,fs:t}:(console.error(`glSeries program link failed:`,n.getProgramInfoLog(r)),null)):null},a=r?i():oH(n,`glSeries`,i);if(!a)return null;let{prog:o,vs:s,fs:c}=a,l=e=>n.getAttribLocation(o,e),u=l(`a_corner`),d=l(`a_ax`),f=l(`a_bx`),p=l(`a_ay`),m=l(`a_by`),h=l(`a_bstart`),g=l(`a_sid`),_=[d,f,p,m,h,g],v=e=>n.getUniformLocation(o,e),y={res:v(`u_resolution`),styles:v(`u_styles`),left:v(`u_left`),plotW:v(`u_plotW`),xoff:v(`u_xoff`),xscale:v(`u_xscale`),xR:v(`u_xR`),minGap:v(`u_minGap`),cutPx:v(`u_cutPx`)},b=n.createBuffer();n.bindBuffer(n.ARRAY_BUFFER,b),n.bufferData(n.ARRAY_BUFFER,Float32Array.from([-1,-1,1,-1,-1,1,1,1]),n.STATIC_DRAW);let x=n.createFramebuffer(),S=n.createRenderbuffer(),C=1,w=1,T=(`clientWidth`in e?e.clientWidth:0)||1,E=(`clientHeight`in e?e.clientHeight:0)||1,D=[],O=0,k=1,A=1/0,j=e=>{let t=n.createBuffer();return n.bindBuffer(n.ARRAY_BUFFER,t),n.bufferData(n.ARRAY_BUFFER,e,n.STATIC_DRAW),t},M=e=>{if(e)for(let t of[e.x,e.y,e.starts,e.sid])n.deleteBuffer(t)},N=e=>{e&&(M(e.full),M(e.res),n.deleteTexture(e.styles))},P=e=>({x:j(e.x),y:j(e.y),starts:j(e.starts),sid:j(e.sid),total:e.x.length}),F=e=>{let t=e.full;if(t&&t.version===e.version)return t;if(t&&e.valuesOnly&&t.whole&&e.counts.every(t=>t===e.xs.length)){let r=e.xs.length,i=e.columns.length===1?e.columns[0]:new Float32Array(r*e.columns.length);return e.columns.length>1&&e.columns.forEach((e,t)=>i.set(e,t*r)),n.bindBuffer(n.ARRAY_BUFFER,t.y),n.bufferSubData(n.ARRAY_BUFFER,0,i),t.version=e.version,t}M(t);let r=fH(e.xs,e.breaks,e.columns);return e.full={...P(r),version:e.version,whole:r.counts.every(t=>t===e.xs.length)},e.full},I=t=>{let n=Math.max(1,Math.round(t.plotW*(e.width/T)));if(t.resamplable&&k>O){let e=t.xs,r=0,i=e.length;for(;r<i;){let t=r+i>>>1;e[t]<O?r=t+1:i=t}let a=r;for(i=e.length;r<i;){let t=r+i>>>1;e[t]<=k?r=t+1:i=t}if(r-a>n*4){let r=`${t.version}|${O}|${k}|${n}`;if(t.res?.key!==r){M(t.res);let i=pH(e,t.columns,t.origin,O,k,n);t.res={...P(i),key:r,bucket:i.bucket}}return{d:t.res,minGap:t.res.bucket*2.5}}}return{d:F(t),minGap:0}},L=(e,r)=>{let i=e.counts.length,a=Math.max(1,Math.ceil(i/cH)),o=3*Math.min(Math.max(i,1),cH),s=new Float32Array(o*a*4);for(let n=0;n<i;n++){let i=r[n],a=(Math.floor(n/cH)*o+n%cH*3)*4;if(!i)continue;let c=i.width??t;s.set([Math.min(i.scaleMin,i.scaleMax),Math.max(i.scaleMin,i.scaleMax),i.bandTop,i.bandBottom],a),s.set(i.color,a+4),s.set([i.gapMedian,c/2,c/2+GV,+(e.counts[n]>=2)],a+8)}n.bindTexture(n.TEXTURE_2D,e.styles),n.texImage2D(n.TEXTURE_2D,0,n.RGBA32F,o,a,0,n.RGBA,n.FLOAT,s),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.NEAREST)};return{resize(t,r,i){T=Math.max(1,t),E=Math.max(1,r),e.width=Math.round(T*i),e.height=Math.round(E*i),C=e.width*2,w=e.height*2,x&&S&&(n.bindRenderbuffer(n.RENDERBUFFER,S),n.renderbufferStorage(n.RENDERBUFFER,n.RGBA8,C,w),n.bindFramebuffer(n.FRAMEBUFFER,x),n.framebufferRenderbuffer(n.FRAMEBUFFER,n.COLOR_ATTACHMENT0,n.RENDERBUFFER,S),n.bindFramebuffer(n.FRAMEBUFFER,null))},setData(e,t,r,i){let a=D[e],o=!t&&!!a&&i.length===a.columns.length;if(!t){if(!a)return;t=a.xs,r=a.breaks}let s=0;for(let e=0;e<t.length;e++)if(Number.isFinite(t[e])){s=t[e];break}let c=i.map(e=>{let t=0;for(let n=0;n<e.length;n++)e[n]===e[n]&&t++;return t});if(a&&(o||a.xs===t)){a.columns=i,a.counts=c,a.valuesOnly=o,a.version++,o||(M(a.full),a.full=null);return}let l={xs:t,breaks:r,columns:i,origin:s,counts:c,resamplable:!r?.some(e=>e)&&mH(t),version:0,valuesOnly:!1,full:null,res:null,styles:n.createTexture(),left:a?.left??0,plotW:a?.plotW??0};L(l,[]),D[e]=l,N(a)},setStyles(e,t,n,r){let i=D[e];i&&(L(i,t),i.left=n,i.plotW=r)},clearLayer(e){N(D[e]),D[e]=null},setView(e,t,n=1/0){O=e,k=t,A=n},render(){n.bindFramebuffer(n.FRAMEBUFFER,x),n.viewport(0,0,x?C:e.width,x?w:e.height),n.disable(n.SCISSOR_TEST),n.clearColor(0,0,0,0),n.clear(n.COLOR_BUFFER_BIT),n.useProgram(o),n.uniform2f(y.res,T,E),n.uniform1i(y.styles,0),n.activeTexture(n.TEXTURE0),n.enable(n.BLEND),n.blendFunc(n.ONE,n.ONE_MINUS_SRC_ALPHA),n.bindBuffer(n.ARRAY_BUFFER,b),n.enableVertexAttribArray(u),n.vertexAttribPointer(u,2,n.FLOAT,!1,0,0),n.vertexAttribDivisor(u,0);for(let e of _)n.enableVertexAttribArray(e),n.vertexAttribDivisor(e,1);let t=k-O||1;for(let e of D){if(!e)continue;n.uniform1f(y.left,e.left),n.uniform1f(y.plotW,e.plotW),n.uniform1f(y.xoff,O-e.origin),n.uniform1f(y.xscale,e.plotW/t),n.uniform1f(y.xR,t),n.uniform1f(y.cutPx,Number.isFinite(A)?e.left+(A-O)*(e.plotW/t):1e9);let{d:r,minGap:i}=I(e);r.total<2||(n.uniform1f(y.minGap,i),n.bindTexture(n.TEXTURE_2D,e.styles),n.bindBuffer(n.ARRAY_BUFFER,r.x),n.vertexAttribPointer(d,1,n.FLOAT,!1,4,0),n.vertexAttribPointer(f,1,n.FLOAT,!1,4,4),n.bindBuffer(n.ARRAY_BUFFER,r.y),n.vertexAttribPointer(p,1,n.FLOAT,!1,4,0),n.vertexAttribPointer(m,1,n.FLOAT,!1,4,4),n.bindBuffer(n.ARRAY_BUFFER,r.starts),n.vertexAttribPointer(h,1,n.UNSIGNED_BYTE,!0,1,1),n.bindBuffer(n.ARRAY_BUFFER,r.sid),n.vertexAttribPointer(g,1,n.FLOAT,!1,4,0),n.drawArraysInstanced(n.TRIANGLE_STRIP,0,4,r.total-1))}for(let e of _)n.vertexAttribDivisor(e,0);x&&(n.bindFramebuffer(n.READ_FRAMEBUFFER,x),n.bindFramebuffer(n.DRAW_FRAMEBUFFER,null),n.blitFramebuffer(0,0,C,w,0,0,e.width,e.height,n.COLOR_BUFFER_BIT,n.LINEAR),n.bindFramebuffer(n.FRAMEBUFFER,null))},dispose(){for(let e of D)N(e);D.length=0,n.deleteBuffer(b),n.deleteFramebuffer(x),n.deleteRenderbuffer(S),r&&(n.deleteProgram(o),n.deleteShader(s),n.deleteShader(c)),r&&n.getExtension(`WEBGL_lose_context`)?.loseContext()}}}``+new URL(`assets/offscreenLineWorker-C-_uNa_H.js`,import.meta.url).href;var gH=[],_H=12,vH=!1,yH=!1,bH=0,xH=3,SH=1;function CH(){return!vH&&typeof Worker<`u`&&typeof HTMLCanvasElement<`u`&&typeof HTMLCanvasElement.prototype.transferControlToOffscreen==`function`}var wH=`kymoscope-gl-first-frame`;function TH(e,t=1,n,r,i){if(typeof e.transferControlToOffscreen!=`function`||typeof Worker>`u`)return null;let a,o=gH.pop();try{a=o??NE(``+new URL(`assets/offscreenLineWorker-C-_uNa_H.js`,import.meta.url).href)}catch{return vH=!0,null}let s;try{s=e.transferControlToOffscreen()}catch{return o?gH.push(o):a.terminate(),null}let c=()=>{},l=SH++,u=!1;a.postMessage({type:`init`,canvas:s,lineWidth:t,gen:l},[s]),a.onmessage=e=>{e.data?.gen===l&&(e.data.type===`lost`?n?.():e.data.type===`first`&&(yH=!0,performance.mark?.(wH),c()))},a.onerror=()=>{u=!0,(!yH||++bH>=xH)&&(vH=!0),n?.()};let d=tH(r),f=-1,p=-1,m=-1,h={own:!0,resize(e,t,n){e===f&&t===p&&n===m||(f=e,p=t,m=n,a.postMessage({type:`resize`,w:e,h:t,dpr:n}))},setData(e,t){let n=[];t.xs&&n.push(t.xs.buffer),t.breaks&&n.push(t.breaks.buffer);for(let e of t.columns)n.push(e.buffer);a.postMessage({type:`data`,layer:e,...t},n)},setStyle(e,t){a.postMessage({type:`style`,layer:e,...t})},clear(e){a.postMessage({type:`clear`,layer:e})},setView(e,t,n){a.postMessage({type:`view`,xmin:e,xmax:t,cut:n})},dispose(){a.onmessage=null,a.onerror=null;let e=!u&&!vH&&gH.length<_H;try{a.postMessage({type:`dispose`})}catch{e=!1}e?gH.push(a):a.terminate(),d()}},g=i?EH(i,t):null;if(!g||!i)return h;let _=()=>{g&&(g.dispose(),g=null,i.getContext(`2d`)?.clearRect(0,0,i.width,i.height))};return c=()=>{(typeof requestAnimationFrame==`function`?requestAnimationFrame:setTimeout)(_)},{own:!0,resize(e,t,n){g?.resize(e,t,n),h.resize(e,t,n)},setData(e,t){g?.setData(e,{...t,xs:t.xs?t.xs.slice():null,breaks:t.breaks?.slice(),columns:t.columns.map(e=>e.slice())}),h.setData(e,t)},setStyle(e,t){g?.setStyle(e,t),h.setStyle(e,t)},clear(e){g?.clear(e),h.clear(e)},setView(e,t,n){g?.setView(e,t,n),h.setView(e,t,n)},dispose(){_(),h.dispose()}}}function EH(e,t=1){let n=sH(e,e=>hH(e,t));if(!n)return null;let r=0,i=1,a,o=``,s=(e,t)=>{n.setStyles(e,t.styles,t.left,t.plotW),r=t.xmin,i=t.xmax,a=t.cut,n.setView(r,i,a),n.render()};return{resize(e,t,r){let i=`${e}|${t}|${r}`;i!==o&&(o=i,n.resize(e,t,r),n.render())},setData(e,t){n.setData(e,t.xs,t.breaks,t.columns),s(e,t)},setStyle(e,t){s(e,t)},clear(e){n.clearLayer(e),n.render()},setView(e,t,o){e===r&&t===i&&o===a||(r=e,i=t,a=o,n.setView(e,t,o),n.render())},dispose(){n.dispose()}}}var DH=new Set;function OH(e){DH.add(e)}function kH(e){DH.delete(e)}function AH(){let e=typeof window>`u`?[]:[window];for(let t of DH)t.closed||e.push(t);return e}var jH=1,MH=new Map;function NH(e){let t=jH++,n=AH();if(n.length===1){let r=n[0].requestAnimationFrame(n=>{MH.delete(t),e(n)});return MH.set(t,[{w:n[0],id:r}]),t}let r=[],i=n=>{MH.has(t)&&(PH(t),e(n))};for(let e of n)r.push({w:e,id:e.requestAnimationFrame(i)});return MH.set(t,r),t}function PH(e){if(e==null)return;let t=MH.get(e);if(t){MH.delete(e);for(let{w:e,id:n}of t)e.closed||e.cancelAnimationFrame(n)}}var FH=new WeakMap;function IH(e){e&&FH.set(e,(FH.get(e)??0)+1)}function LH(e){let t=FH.get(e)??0;for(let n of e.querySelectorAll(`*`))t+=FH.get(n)??0;return t}function RH(){return AH().every(e=>e.document.hidden)}var zH=class{#e;#t=new Map;constructor(e){this.#e=e}observe(e,t){let n=e.ownerDocument.defaultView??window,r=this.#t.get(n);r||(r=new(n.ResizeObserver??ResizeObserver)(e=>this.#e(e,this)),this.#t.set(n,r)),r.observe(e,t)}unobserve(e){for(let t of this.#t.values())t.unobserve(e)}disconnect(){for(let e of this.#t.values())e.disconnect();this.#t.clear()}};function BH(e){return!!e&&e.isConnected&&typeof e.checkVisibility==`function`&&!e.checkVisibility()}function VH(e,t){let n=0,r=null,i=()=>BH(t()),a=t=>{n=0,!i()&&(r=t,e())};return{schedule(){n||=NH(a)},now(){if(i())return;let o=t()?.ownerDocument?.timeline?.currentTime;if(typeof o!=`number`||o===r){n||=NH(a);return}n&&=(PH(n),0),r=o,e()},cancel(){n&&PH(n),n=0}}}var HH=.6,UH=16,WH={ts:-1,work:0,floor:1/0},GH=1/0;function KH(e,t=-1/0){if(e!==WH.ts){if(e>WH.ts&&e<WH.ts+WH.work/HH)return!1;WH={ts:e,work:0,floor:GH},GH=1/0}return WH.work>=UH||t>WH.floor?(GH=Math.min(GH,t),!1):!0}function qH(e,t){e===WH.ts&&(WH.work+=t)}function JH(e,t=typeof window>`u`?null:e=>{NH(e)}){let n=!1,r=null;return{set(i){if(r=i,!t){e(i);return}n||(n=!0,t(()=>{n=!1,e(r)}))}}}function YH(e,t,n,r,i){return r+(e-t)/n*(i-r)}function XH(e,t,n,r){let i=new Map,a=n.length;if(a===0)return i;let o=new Float64Array(a),s=new Float64Array(a).fill(1/0);for(let r of e){let e=r.x;for(let i=0;i<a;i++){let a=r.cols.get(n[i]);if(!a)continue;let c=s[i],l=o[i];for(let n=0;n<r.length;n++){let r=e[n],i=r<t?t-r:r-t;if(i>=c)continue;let o=a[n];Number.isFinite(o)&&(c=i,l=o)}s[i]=c,o[i]=l}}for(let e=0;e<a;e++)s[e]!==1/0&&(r&&s[e]>(r.get(n[e])??1/0)||i.set(n[e],o[e]));return i}function ZH(e,t,n,r=64){let i=new Map;if(t.length===0||!Number.isFinite(n))return i;let a=new Map;for(let o of e){if(o.length===0)continue;let e=0,s=o.length-1;for(;e<s;){let t=e+s>>1;o.x[t]<n?e=t+1:s=t}for(let s of t){let t=o.cols.get(s);if(t)for(let c=0;c<=r;c++){let r=e-c,l=e+c,u=r>=0&&Number.isFinite(t[r])?r:l<o.length&&Number.isFinite(t[l])?l:-1;if(u<0)continue;let d=Math.abs(o.x[u]-n);d<(a.get(s)??1/0)&&(a.set(s,d),i.set(s,t[u]));break}}}return i}function QH(e,t){let n=new Map;if(t.length===0)return n;for(let r=e.length-1;r>=0&&n.size<t.length;r--){let i=e[r];for(let e of t){if(n.has(e))continue;let t=i.cols.get(e);if(t){for(let r=i.length-1;r>=0;r--)if(Number.isFinite(t[r])){n.set(e,t[r]);break}}}}return n}function $H(e,t){return!(e>0)||!(t>0)?1:1-Math.exp(-e/t)}function eU(e,t,n,r=t){if(!(t>e)||n==null||!(n>0))return[e,t];let i=Number.isFinite(r)?Math.min(t,Math.max(e,r)):t;return i-n<e?[e,Math.min(t,e+n)]:[i-n,i]}function tU(e,t){return e>0?Math.min(8e3,Math.max(400,Math.round(e*t*2))):2e3}var nU=.5;function rU(e,t,n,r=nU){if(!(t>0))return e;let i=e!=null&&e>0?Math.min(e,t):t,a=n?i*.88:i/.88;return a>=t*.999?null:Math.max(r,a)}function iU(e=0){return{d:null,lastT:NaN,wall:0,base:NaN,wait:e,waitAge:0}}var aU=new Map;function oU(e,t,n){let r=aU.get(e);if(r||aU.set(e,r={p:iU(),at:NaN,d:NaN}),n-r.at<2&&Number.isFinite(r.d))return r.d;let i=Number.isNaN(r.at)?16:n-r.at;return r.at=n,r.d=fU(r.p,t,i),r.d}var sU=250,cU=3,lU=90,uU=30,dU=.001;function fU(e,t,n){if(!Number.isFinite(t))return t;let r=n/1e3;e.wall+=r;let i=n>sU&&e.d!==null;if(t<e.lastT&&Object.assign(e,iU(),{wall:e.wall}),t<=e.lastT)e.base+=r*dU;else{let n=e.wall-t;e.base=Number.isNaN(e.base)?n:Math.min(e.base+r*dU,n)}e.lastT=t;let a=e.wall-t-e.base;i||(e.waitAge+=r),i||(a>e.wait?(e.wait=Math.min(cU,a),e.waitAge=0):a>e.wait*.8?e.waitAge=0:e.waitAge>lU&&(e.wait*=Math.exp(-r/uU)));let o=e.wall-e.base-Math.min(cU,e.wait*1.2+.05);if(e.d===null)e.d=e.wait>0?Math.min(t,o):t;else if(i||e.d<o-2)e.d=Math.min(t,o);else{let t=Math.min(n,64);e.d+=t/1e3,e.d+=(o-e.d)*Math.min(1,t/500)}return e.d>t&&(e.d=t),e.d}var pU=(e,t)=>e.log?(Math.log10(Math.max(t,Number.MIN_VALUE))-Math.log10(e.v0))/(Math.log10(e.v1)-Math.log10(e.v0)||1):(t-e.v0)/(e.v1-e.v0||1),mU=(e,t)=>e.log?10**(Math.log10(e.v0)+t*(Math.log10(e.v1)-Math.log10(e.v0))):e.v0+t*(e.v1-e.v0),hU=(e,t)=>e.left+pU(e.x,t)*e.width,gU=(e,t)=>mU(e.x,(t-e.left)/(e.width||1)),_U=(e,t)=>e.top+(1-pU(e.y,t))*e.height,vU=e=>!e||Number.isFinite(e.v0)&&Number.isFinite(e.v1)&&e.v0!==e.v1&&(!e.log||e.v0>0&&e.v1>0),yU=(e,t)=>e===t||!!e&&!!t&&e.v0===t.v0&&e.v1===t.v1&&!!e.log==!!t.log;function bU(){let e=null,t=new Set;return{get:()=>e,set:n=>{if(n&&(n.width>0&&n.height>0?(!vU(n.x)||!vU(n.y))&&(n={...n,x:vU(n.x)?n.x:void 0,y:vU(n.y)?n.y:void 0}):n=null),!(n===e||n&&e&&n.left===e.left&&n.top===e.top&&n.width===e.width&&n.height===e.height&&yU(n.x,e.x)&&yU(n.y,e.y))){e=n;for(let e of[...t])e()}},subscribe:e=>(t.add(e),()=>{t.delete(e)})}}var xU=at(()=>{}),SU=()=>ut(xU),CU=`M5 .8a3.1 3.1 0 0 0-3.1 3.1v2.3L.8 7.6h8.4L8.1 6.2V3.9A3.1 3.1 0 0 0 5 .8zM3.9 8.4a1.1 1.1 0 0 0 2.2 0z`,wU=[5,4],TU=null;function EU(e,t,n,r){typeof Path2D>`u`||(TU??=new Path2D(CU),e.save(),e.setLineDash([]),e.translate(t,n),e.fillStyle=r,e.fill(TU),e.restore())}var DU=(()=>{try{return localStorage.getItem(`glLines`)!==`0`}catch{return!0}})(),OU=(()=>{try{return localStorage.getItem(`offscreenGl`)!==`0`}catch{return!0}})(),kU=70;function AU(e){return e===`dashed`?[5,4]:e===`dotted`?[1,4]:[]}var jU={top:14,right:160,bottom:40,left:110},MU={top:14,right:100,bottom:40,left:70},NU=640,PU={top:3,right:3,bottom:3,left:3},FU=260;function IU(e){return e<FU?PU:e<NU?MU:jU}var LU=220,RU=2e3,zU=4,BU=1e3/120,VU=`11.25px ${Q.mono}`,HU=11*1.125,UU=24*1.125,WU=UU-HU+26,GU=.6,KU=13,qU=10,JU=5,YU=14,XU=4;function ZU(e,t,n){return Math.min(n,Math.max(t,e))}function QU(e,t,n,r,i){let a=Math.min(r,i),o=Math.max(r,i);return t+(1-ZU(o===a?.5:(e-a)/(o-a),0,1))*(n-t)}function $U(e,t,n,r){let i=e+t;return{bandTop:i-r/100*t,bandBottom:i-n/100*t}}function eW(e){return e.replace(/__(\d+|ref)$/,``)}function tW(e,t,n){let r=Math.floor((n-t-HU)/KU)+1;return Math.max(0,Math.min(e,r))}function nW(e){let t=0;for(let n of e)t+=n.length;return t}function rW(e,t){let n=e.cols.get(t);return n?new Float32Array(n):new Float32Array(e.length).fill(NaN)}function iW(e){let t=new Map;for(let n of e){let e=eW(n.column),r=t.get(e)??[];r.push(n),t.set(e,r)}let n=new Set,r=[];for(let i of e){let e=eW(i.column);if(n.has(e))continue;n.add(e);let a=t.get(e);r.push({base:e,leader:a[0],members:a})}return r}function aW(e,t,n){let r=new Map,i=e.map((e,r)=>{let{bandTop:i}=$U(t,n,e.leader.bandFromPct,e.leader.bandToPct);return{g:e,i:r,bandTop:i,blockDY:e.members.length>1?HU+(e.members.length+1)*KU:WU}});i.sort((e,t)=>e.bandTop-t.bandTop||e.i-t.i);let a=-1/0;for(let{g:e,bandTop:t,blockDY:n}of i){let i=t+HU,o=Math.max(i,a),s=o-HU;r.set(e.leader.id,s),a=o+n}return r}function oW(e,t){let n=e.cols.get(t);if(!n)return 0;let r=e.x;return n.length===e.length&&c.has(n)?sW(r,e.length):lW(r,e.length,e=>Number.isFinite(n[e]))}function sW(e,t){let n=cW.get(e);return n===void 0&&(n=lW(e,t,()=>!0),cW.set(e,n)),n}var cW=F(new WeakMap);function lW(e,t,n){let r=null,i=0,a=0;for(let o=0;o<t;o++)n(o)&&(r!==null&&e[o]!==r&&(i+=Math.abs(e[o]-r),a++),r=e[o]);return a===0?0:i/a}function uW(e,t){return e>0?Math.max(e*4,t*1e-9):Math.max(t*1e-6,1e-12)}var dW=1e30,fW=250;function pW({xLabel:e,series:t,points:n,columnUnits:r={},height:i=440,onPlotContextMenu:a,backgroundToken:o=``,viewXRange:s=null,onViewXRangeChange:c,liveZoom:l,liveZoomId:u,fullXRange:d=null,shiftMode:f,xAxisLine:p,yAxisLine:m,gridLine:h,lineWidth:g=1,envelopes:_,showLatestValues:v=!1,liveSource:y,liveWindowSeconds:b=null,onLiveWindowChange:x,liveZoomMode:S,onPlotWidthCss:C,onCursorX:w}){let T=SU(),E=K(null),D=K(null),O=K(null),k=K(null),A=K(null),j=K(C);j.current=C;let M=K(-1),N=K(null),P=K(!1),F=K(null),I=K(!1),L=K(!1),R=K(null),z=K(null),B=K({pts:null,layers:[]}),V=K(new Map),ee=K([]),te=K(null),H=K(null),ne=K(null),re=K(null),ie=K(0),U=K(0),ae=K(!1),oe=K(0),se=K(RU),ce=K(y),le=K(null),ue=K(iU()),de=K(0),fe=K(void 0),pe=K(0),me=K(0),he=K(16),ge=K(!0),_e=K(!1),[ve,ye]=pt(0),be=()=>BH(A.current);function xe(){F.current?.dispose(),F.current=null,L.current=!1,I.current=!1,ee.current=[],ye(e=>e+1)}W(()=>{ve&&wt()},[ve]),G(()=>{ce.current=y,le.current=null,B.current={pts:null,layers:[]},V.current.clear()},[y]);let Se=K(b);G(()=>{Se.current=b},[b]);let Ce=K(x);Ce.current=x;let we=S??(x?`follow`:`free`),Te=K(we);Te.current=we;let Ee=K(null);G(()=>{Ee.current=null},[we,e]);let De=K([]),Oe=K(!1),ke=K(0),Ae=K(0),je=K(0),Me=K(0),Ne=K(`none`),Pe=K(0),Fe=K(0),Ie=K(0),Le=K(null),Re=K(null),ze=K(f),Be=K(null),Ve=K({pts:null,x0:NaN,x1:NaN,ser:null}),He=K(0),Ue=K(0),We=K(null),Ge=K(null),Ke=K(null),qe=K(null);G(()=>{ze.current=f},[f]),W(()=>(R.current&&=(clearTimeout(R.current),null),()=>{N.current?.dispose(),N.current=null;let e=F.current;e&&(R.current=setTimeout(()=>{e.dispose(),F.current===e&&(F.current=null),R.current=null},0))}),[]);let Je=mt(qz,Kz),Ye=K({xLabel:e,series:t,points:n,height:i,columnUnits:r,shiftMode:f,xAxisLine:p,yAxisLine:m,gridLine:h,lineWidth:g,showLatestValues:v,envelopes:_}),Xe=K(null),Ze=K(null);G(()=>{Ye.current={xLabel:e,series:t,points:n,height:i,columnUnits:r,shiftMode:f,xAxisLine:p,yAxisLine:m,gridLine:h,lineWidth:g,showLatestValues:v,envelopes:_}},[e,t,n,i,r,f,p,m,h,g,v,_]);let Qe=K(c),$e=K(w);$e.current=w,G(()=>{Qe.current=c},[c]);let et=K(l),tt=K(u);G(()=>{et.current=l,tt.current=u},[l,u]),W(()=>{if(!(!l||!u))return l.subscribe((e,t)=>{e!==u&&(te.current=t?.[0]??null,H.current=t?.[1]??null,wt())})},[l,u]);let nt=K(a);G(()=>{nt.current=a},[a]);let rt=ft(()=>{if(d&&d[1]>d[0])return{xmin:d[0],xmax:d[1]};let e=1/0,t=-1/0;for(let r of n)for(let n=0;n<r.length;n++){let i=r.x[n];i<e&&(e=i),i>t&&(t=i)}return(!Number.isFinite(e)||e===t)&&(--e,t+=1),{xmin:e,xmax:t}},[n,d]),it=K(rt);G(()=>{it.current=rt},[rt]);function at(){return ce.current!=null&&te.current===null&&H.current===null&&!Oe.current&&Be.current===null}function ot(){let{xmin:e,xmax:t}=it.current,n=te.current,r=H.current;if(n!==null&&r!==null&&r>n&&Number.isFinite(n)&&Number.isFinite(r))return{xmin:n,xmax:r};let i=ne.current,a=re.current;return at()&&i!==null&&a!==null&&a>i&&Number.isFinite(i)&&Number.isFinite(a)?{xmin:i,xmax:a}:{xmin:e,xmax:t}}function st(e,t){let n=ce.current;if(!n?.latestValues)return QH(e,t);let r=n.latestValues(t),i=t.filter(e=>!r.has(e)),a=n.latestX?.();if(i.length>0&&a!=null)for(let[t,n]of ZH(e,i,a))r.set(t,n);return r}function ct(){return ce.current?De.current:Ye.current.points}function lt(e,t,n){let r=new Map;for(let i of t)r.set(i,uW(_t(e,i),n));return r}function ut(e){if(B.current.pts===e)return B.current.layers;let t=B.current.layers,n=ce.current?.version?.(),r=e.map((e,r)=>({pts:e,key:t[r]?.pts===e?t[r].key:n??e}));return B.current={pts:e,layers:r},r}function dt(e,t){let n=V.current.get(e),r=performance.now(),i=n&&(n.key===t.key||typeof t.key==`number`&&typeof n.key==`number`&&r-n.at<fW);return(!n||!i)&&(n={key:t.key,at:r,has:new Map,median:new Map},V.current.set(e,n)),n}function ht(e,t,n){let r=dt(e,t),i=r.has.get(n);if(i===void 0){let e=t.pts.cols.get(n);i=!!e&&e.some(Number.isFinite),r.has.set(n,i)}return i}function gt(e,t){return ut(e).some((e,n)=>ht(n,e,t))}function _t(e,t){let n=ut(e);for(let e=0;e<n.length;e++){if(!ht(e,n[e],t))continue;let r=dt(e,n[e]),i=r.median.get(t);return i===void 0&&(i=oW(n[e].pts,t),r.median.set(t,i)),i}return 0}function yt(){if(qe.current)return qe.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 qe.current=n,n}function bt(){let e=A.current,t=Math.max(1,e?.clientWidth||200),n=e?.clientHeight??0;return{w:t,h:Math.max(1,n>0?n:Ye.current.height)}}function xt(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 St(){let e=E.current;if(!e)return;let{w:t,h:n}=bt(),r=xt(e,t,n);if(!r)return;{let e=ct(),t=ot(),n=Ye.current.series,r=Ve.current;(r.pts!==e||r.x0!==t.xmin||r.x1!==t.xmax||r.ser!==n)&&(Ve.current={pts:e,x0:t.xmin,x1:t.xmax,ser:n},IH(A.current))}let i=IU(t),a=i===PU,{top:o,right:s,bottom:c}=i,l=i.left,u=t-l-s,d=n-o-c,{bg:f,muted:p,grid:m}=yt(),{xLabel:h,series:g,xAxisLine:_,yAxisLine:v,gridLine:y,lineWidth:b,columnUnits:x,showLatestValues:S}=Ye.current,C=ct();if(r.fillStyle=f,r.fillRect(0,0,t,n),nW(C)<2||u<=0||d<=0){if(r.fillStyle=p,r.font=`13px ${Q.sans}`,zV(r),N.current&&(N.current.resize(t,n,window.devicePixelRatio||1),N.current.draw([])),F.current){F.current.resize(t,n,window.devicePixelRatio||1);for(let e=0;e<ee.current.length;e++)F.current.clear(e);ee.current=[]}return}let{xmin:w,xmax:k}=ot(),j=k-w,M=e=>l+(e-w)/j*u;T({left:l,top:o,width:u,height:d,x:{v0:w,v1:k}});let z=g.filter(e=>e.bandToPct>e.bandFromPct&&e.scaleMin!==e.scaleMax&>(C,e.column)),B=iW(z),V=aW(B,o,d),te=new Map;for(let e of B){let t=V.get(e.leader.id);t!==void 0&&e.members.forEach(e=>te.set(e.id,t))}let H=new Set,ne=new Set;for(let e of B)e.members.length>1&&e.members.forEach(e=>H.add(e.id)),ne.add(e.leader.id);let re=`11px ${Q.mono}`,ie=z.map(e=>{let{bandTop:t,bandBottom:n}=$U(o,d,e.bandFromPct,e.bandToPct),r=Math.min(e.scaleMin,e.scaleMax),i=Math.max(e.scaleMin,e.scaleMax),{majorStep:a,minorStep:s}=kz(e.scaleMin,e.scaleMax,e.yMajorStep??0,e.yMinorStep??0),c=a,l=Az(r,i,c);l.length>120&&(l=Az(r,i,c=kz(e.scaleMin,e.scaleMax,0,0).majorStep));let u=jz(r,i,s,l);return u.length>400&&(u=[]),{s:e,bandTop:t,bandBottom:n,majors:l,minors:u,step:c}}),U=new Map,ae=0;{r.save(),r.font=re;let e=ie.filter(e=>ne.has(e.s.id));e.sort((e,t)=>{let n=Math.abs(e.s.bandToPct-e.s.bandFromPct),r=Math.abs(t.s.bandToPct-t.s.bandFromPct);return n===r?ie.indexOf(e)-ie.indexOf(t):r-n});let n=new Map,a=[];for(let t of e){let r=0;for(;r<e.length;r++){let e=a[r];if(!e||e.length===0||!e.some(e=>t.bandTop<e.bandBottom&&t.bandBottom>e.bandTop))break}n.set(t.s.id,r),a[r]||(a[r]=[]),a[r].push(t)}let o=new Map,c=new Map;for(let t of e){let e=0;for(let n of t.majors){let i=Pz(n,t.step),a=c.get(i);a===void 0&&c.set(i,a=r.measureText(i).width),a>e&&(e=a)}o.set(t.s.id,e)}let u=[],d=[],f=0;for(let e=0;e<a.length;e++){u[e]=f;let t=0;for(let n of a[e]??[]){let e=o.get(n.s.id)??0;e>t&&(t=e)}d[e]=t,f+=t+22}for(let e of ie){let t=n.get(e.s.id)??0;U.set(e.s.id,u[t]??0)}let p=i.left;for(let e=0;e<a.length;e++){let t=a[e];if(!t||t.length===0)continue;let n=(u[e]??0)+XU+YU+(d[e]??0)+6;n>p&&(p=n)}let m=Math.max(i.left,t-s-Math.max(120,t*.4)),h=Math.min(Math.ceil(p),m);h>l&&(ae=h-l),r.restore()}ae>0&&(l+=ae,u=Math.max(1,t-l-s)),se.current=tU(u,window.devicePixelRatio||1);let oe=(e,t)=>1-(1-e)**t,ce=new Map,le=new Map;for(let e of ie){let t=`${e.bandTop}|${e.bandBottom}|${e.s.scaleMin}|${e.s.scaleMax}|${e.majors.join(`,`)}`,n=ce.get(t);n?n.k++:ce.set(t,{c:e,k:1});let r=H.has(e.s.id)?p:e.s.color,i=`${e.bandTop}|${e.bandBottom}|${r}`,a=le.get(i);a?a.k++:le.set(i,{c:e,color:r,k:1})}if((v?.style??`dashed`)!==`none`)for(let{c:{s:e,bandTop:t,bandBottom:n,majors:i},k:a}of ce.values()){r.save(),r.strokeStyle=v?.color??m,r.globalAlpha=oe(.1,a),r.lineWidth=v?.width??1,r.lineCap=`round`,r.setLineDash(AU(v?.style??`dashed`));for(let a of i){let i=QU(a,t,n,e.scaleMin,e.scaleMax);r.beginPath(),r.moveTo(l,i),r.lineTo(l+u,i),r.stroke()}r.restore()}for(let{c:{bandTop:e,bandBottom:t},color:n,k:i}of le.values())r.strokeStyle=n,r.lineWidth=1,r.setLineDash([]),r.globalAlpha=oe(.45,i),r.beginPath(),r.moveTo(l,e),r.lineTo(l,t),r.stroke(),r.globalAlpha=1;for(let{s:e,bandTop:t,bandBottom:n,majors:i,minors:o,step:s}of a?[]:ie){let a=H.has(e.id)?p:e.color;if(ne.has(e.id)){let c=U.get(e.id)??0,u=l-c-XU;r.strokeStyle=a,r.lineWidth=1;for(let i of o){let a=QU(i,t,n,e.scaleMin,e.scaleMax);r.beginPath(),r.moveTo(u-JU,a),r.lineTo(u,a),r.stroke()}r.font=re,r.textAlign=`right`,r.textBaseline=`middle`,r.strokeStyle=a,r.fillStyle=a;for(let a of i){let i=QU(a,t,n,e.scaleMin,e.scaleMax);r.beginPath(),r.moveTo(u-qU,i),r.lineTo(u,i),r.stroke(),r.fillText(Pz(a,s),u-YU,i)}}}if((y?.style??`solid`)!==`none`&&(r.strokeStyle=y?.color??m,r.lineWidth=y?.width??1,r.setLineDash(AU(y?.style??`solid`)),r.strokeRect(l,o,u,d),r.setLineDash([])),(_?.style??`dashed`)!==`none`){r.strokeStyle=_?.color??m,r.lineWidth=_?.width??1,r.setLineDash(AU(_?.style??`dashed`));for(let e=1;e<6;e++){let t=l+e/6*u;r.beginPath(),r.moveTo(t,o),r.lineTo(t,o+d),r.stroke()}r.setLineDash([])}let ue=o+d+10;r.fillStyle=p,r.font=`11px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`top`;let de=Rz(h,w,w+j);for(let e=0;e<=(a?-1:6);e++){let t=w+e/6*j;r.fillText(de?Jz(t,j/6,j):Pz(t,j/6),l+e/6*u,ue)}r.textBaseline=`bottom`,a||r.fillText(h,l+u/2,n-5);let{shiftMode:pe}=Ye.current;pe&&(r.globalAlpha=.8,r.font=`10px ${Q.sans}`,r.fillStyle=p,r.textAlign=`center`,r.textBaseline=`top`,r.fillText(`⇄ shifting: ${pe.label}`,l+u/2,o+3),r.globalAlpha=1);let me=Ye.current.envelopes;if(me?.length){r.save(),r.beginPath(),r.rect(l,o,u,d),r.clip();for(let e of me){let t=z.find(t=>t.id===e.seriesId||t.id.startsWith(`${e.seriesId}__`));if(!t)continue;let{bandTop:n,bandBottom:i}=$U(o,d,t.bandFromPct,t.bandToPct),a=e=>QU(e,n,i,t.scaleMin,t.scaleMax);r.fillStyle=e.color,r.globalAlpha=.2;let s=0;for(;s<e.x.length;){for(;s<e.x.length&&e.lo[s]!==e.lo[s];)s++;let t=s;for(;s<e.x.length&&e.lo[s]===e.lo[s];)s++;if(!(s-t<2)){r.beginPath(),r.moveTo(M(e.x[t]),a(e.hi[t]));for(let n=t+1;n<s;n++)r.lineTo(M(e.x[n]),a(e.hi[n]));for(let n=s-1;n>=t;n--)r.lineTo(M(e.x[n]),a(e.lo[n]));r.closePath(),r.fill()}}}r.restore()}R.current&&=(clearTimeout(R.current),null);let he=OU&&!I.current?F.current:null;if(OU&&!he&&!I.current&&D.current&&!L.current&&(he=CH()&&eH()?TH(D.current,1,xe,{hidden:be,evict:xe},O.current??void 0):EH(D.current),he?(F.current=he,L.current=!0):I.current=!0),he){he.resize(t,n,window.devicePixelRatio||1);let e=`${l.toFixed(2)}|${u.toFixed(2)}|${o}|${d}|${b}|`+z.map(e=>`${e.id}:${e.column}:${e.bandFromPct}:${e.bandToPct}:${e.scaleMin}:${e.scaleMax}:${e.color}`).join(`,`),r=ut(C),i=ee.current;for(let t=0;t<Math.max(r.length,i.length);t++){let n=r[t];if(!n){i[t]&&he.clear(t),i[t]=null;continue}let a=z.filter(e=>ht(t,n,e.column)),s=a.map(e=>e.column).join(`
|
|
207
|
+
`),c=i[t];if(c&&c.pts===n.pts&&c.sig===e&&c.cols===s)continue;i[t]={pts:n.pts,sig:e,cols:s};let f={styles:a.map(e=>{let{bandTop:t,bandBottom:r}=$U(o,d,e.bandFromPct,e.bandToPct);return{color:UV(e.color),bandTop:t,bandBottom:r,scaleMin:e.scaleMin,scaleMax:e.scaleMax,gapMedian:n.pts.hold?dW:_t(C,e.column),width:b}}),left:l,plotW:u,xmin:w,xmax:k,cut:fe.current};if(c&&c.pts===n.pts&&c.cols===s){he.setStyle(t,f);continue}let p=n.pts,m=!!c&&c.pts.x===p.x&&c.pts.brk===p.brk&&c.cols===s;he.setData(t,{...f,xs:m?null:p.x.slice(),breaks:m?void 0:p.brk?.slice(),columns:a.map(e=>rW(p,e.column))})}i.length=r.length,he.setView(w,k,fe.current)}else{let e=N.current;DU&&!e&&!P.current&&D.current&&!L.current&&(e=YV(D.current),e?N.current=e:P.current=!0);let i=!!e;i&&e&&e.resize(t,n,window.devicePixelRatio||1);let a=[],s=lt(C,z.map(e=>e.column),j);for(let e of z){let{bandTop:t,bandBottom:n}=$U(o,d,e.bandFromPct,e.bandToPct),c=s.get(e.column);if(i){let r={x:l,y:t,w:u,h:n-t},i=UV(e.color),o=[],s=null,d=()=>{o.length>=4&&a.push({points:Float32Array.from(o),color:i,clip:r,width:b}),o=[]};for(let r of C){let i=r.cols.get(e.column);if(i){s=null;for(let a=0;a<r.length;a++){r.brk?.[a]&&d();let l=i[a];if(!Number.isFinite(l))continue;let u=r.x[a];s!==null&&!r.hold&&Math.abs(u-s)>c&&d(),o.push(M(u),QU(l,t,n,e.scaleMin,e.scaleMax)),s=u}d()}}d();continue}r.strokeStyle=e.color,r.lineWidth=b,r.lineJoin=`round`,r.lineCap=`round`,r.save(),r.beginPath(),r.rect(l,t,u,n-t),r.clip(),r.beginPath();let f=!1,p=null,m=!1;for(let i of C){let a=i.cols.get(e.column);if(a){m=!0;for(let o=0;o<i.length;o++){i.brk?.[o]&&(m=!0);let s=a[o];if(!Number.isFinite(s))continue;let l=i.x[o],u=M(l),d=QU(s,t,n,e.scaleMin,e.scaleMax);f?m||p!==null&&!i.hold&&Math.abs(l-p)>c?(r.stroke(),r.beginPath(),r.moveTo(u,d),p=l,m=!1):(r.lineTo(u,d),p=l):(r.moveTo(u,d),f=!0,p=l,m=!1)}}}f&&r.stroke(),r.restore()}i&&e&&e.draw(a)}for(let e of z){if(!e.alarm)continue;let{bandTop:t,bandBottom:n}=$U(o,d,e.bandFromPct,e.bandToPct),i=QU(e.alarm.value,t,n,e.scaleMin,e.scaleMax);r.save(),r.beginPath(),r.rect(l,t,u,n-t),r.clip(),r.strokeStyle=e.alarm.color,r.lineWidth=e.alarm.width,r.setLineDash(e.alarm.linked===`active`?wU:AU(e.alarm.style)),r.beginPath(),r.moveTo(l,i),r.lineTo(l+u,i),r.stroke(),r.setLineDash([]),e.alarm.linked&&EU(r,l+u-10-3,i-10-2,e.alarm.color),r.restore()}if(a)return;let ge=S?st(C,z.map(e=>e.column)):null,_e=e=>{let t=ge?.get(e.column);if(typeof t!=`number`)return`-`;let n=x[e.column]?.trim()??``;return`${Fz(t)}${n?` ${n}`:``}`},ve=l+u+8;r.font=VU,r.textAlign=`left`;for(let e of B){let t=V.get(e.leader.id);if(t===void 0)continue;let i=e.members.length>1;if(r.fillStyle=i?p:e.leader.color,r.globalAlpha=1,r.fillText(e.base,ve,t+HU),i){let i=tW(e.members.length,t,n);for(let n=0;n<i;n++)r.fillStyle=e.members[n].color,r.globalAlpha=GU,r.fillText(_e(e.members[n]),ve,t+HU+(n+1)*KU)}else r.fillStyle=e.leader.color,r.globalAlpha=GU,r.fillText(_e(e.leader),ve,t+UU);r.globalAlpha=1}}function Ct(){let e=k.current;if(!e)return;let{w:t,h:n}=bt(),r=xt(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let{top:i,right:a,bottom:o,left:s}=IU(t),c=t-s-a,l=n-i-o,{series:u,columnUnits:d,xLabel:f}=Ye.current,p=ct();if(Oe.current&&c>0&&l>0){let e=ke.current,t=Ae.current,n=je.current,i=Me.current,a=Math.min(e,n),o=Math.min(t,i),s=Math.abs(n-e),c=Math.abs(i-t);r.fillStyle=`rgba(59, 130, 246, 0.12)`,r.fillRect(a,o,s,c),r.strokeStyle=`rgba(59, 130, 246, 0.85)`,r.setLineDash([4,3]),r.lineWidth=1,r.strokeRect(a,o,s,c),r.setLineDash([])}let m=z.current;if(m===null||nW(p)<2||c<=0||l<=0)return;let{xmin:h,xmax:g}=ot(),_=u.filter(e=>e.bandToPct>e.bandFromPct&&e.scaleMin!==e.scaleMax&>(p,e.column)),v=[...new Set(_.map(e=>e.column))],y=lt(p,v,g-h),{bg:b,muted:x}=yt();r.strokeStyle=x,r.globalAlpha=.5,r.lineWidth=1,r.beginPath(),r.moveTo(m,i),r.lineTo(m,i+l),r.stroke(),r.globalAlpha=1;let S=iW(_),C=aW(S,i,l),w=s+c+8;r.font=VU,r.textAlign=`left`;let T=YH(m,s,c,h,g),E=XH(p,T,v,y),D=e=>{let t=E.get(e.column);if(typeof t!=`number`)return`-`;let n=d[e.column]?.trim()??``;return`${Fz(t)}${n?` ${n}`:``}`};for(let e of S){let t=C.get(e.leader.id)??$U(i,l,e.leader.bandFromPct,e.leader.bandToPct).bandTop;if(e.members.length>1){let i=e.members.length*KU+4;r.fillStyle=b,r.fillRect(s+c+6,t+HU+2,a-8,i);let o=tW(e.members.length,t,n);for(let n=0;n<o;n++){let i=e.members[n];r.fillStyle=i.color,r.globalAlpha=GU,r.fillText(D(i),w,t+HU+(n+1)*KU)}}else{let n=e.leader;r.fillStyle=b,r.fillRect(s+c+6,t+HU+2,a-8,UU-HU+6),r.fillStyle=n.color,r.globalAlpha=GU,r.fillText(D(n),w,t+UU)}r.globalAlpha=1}let O=/^(.*?)\s*\(([^)]*)\)\s*$/.exec(f),A=O?O[1]:f,j=O?O[2].trim():``,M=Rz(f,h,g)?Yz(T):``,N=M.lastIndexOf(` `),P=M?[`${A} ${M.slice(0,N)}`,M.slice(N+1)]:[`${A} ${Math.round(T)}${j}`];r.font=VU,r.textAlign=`left`,r.textBaseline=`alphabetic`,P.forEach((e,t)=>{let n=r.measureText(e).width,a=i+l-(P.length-1-t)*15;r.fillStyle=b,r.fillRect(w-2,a-11,n+6,15),r.fillStyle=x,r.globalAlpha=1,r.fillText(e,w,a)})}function wt(){if(ce.current){ae.current=!0;return}We.current=()=>{St(),Ct()},!He.current&&(He.current=NH(e=>{He.current=0,!be()&&(Ge.current=e,We.current?.())}))}function Tt(){if(ce.current){ae.current=!0;return}let e=A.current?.ownerDocument.timeline?.currentTime;if(typeof e!=`number`||e===Ge.current){wt();return}Ge.current=e,PH(He.current),He.current=0,St(),Ct()}function Et(){Ke.current=Ct,!Ue.current&&(Ue.current=NH(()=>{Ue.current=0,Ke.current?.()}))}function Dt(e){ie.current=NH(Dt);let t=ce.current;if(!t)return;he.current+=(Math.min(50,me.current?e-me.current:16)-he.current)*.1,me.current=e;let n=A.current;if(!(ge.current&&!BH(n))){if(!_e.current){_e.current=!0;let e=F.current;e&&(ee.current.forEach((t,n)=>{t&&e.clear(n)}),ee.current=[],e.resize(1,1,1))}return}if(_e.current&&(_e.current=!1,F.current&&!F.current.own&&CH()&&eH())){xe();return}if(pe.current&&e-pe.current<BU-he.current/2||!KH(e,pe.current||-1/0))return;pe.current=e;let r=performance.now(),i=t.xBounds();i&&i[1]>i[0]&&(it.current={xmin:i[0],xmax:i[1]});let a=de.current?e-de.current:16;de.current=e,a>250&&(ne.current=null,re.current=null);let o=t.latestT?.(),s;if(o!==void 0&&t.xAtTime&&Number.isFinite(o)){let e=t.id?oU(t.id,o,performance.now()):fU(ue.current,o,a),n=t.xAtTime(e);Number.isFinite(n)&&(s=n)}if(at()){let n=s??t.latestX?.()??it.current.xmax,r=Se.current,i=r!=null&&t.spanForSeconds?t.spanForSeconds(r):r??Ee.current,[a,o]=eU(it.current.xmin,it.current.xmax,i,n??void 0);if(!t.spanForSeconds&&s!==void 0&&s>a&&(o=Math.min(o,s)),Number.isFinite(a)&&Number.isFinite(o)&&o>a){let t=o-a,n=re.current!==null&&o<re.current-t;if(ne.current===null||re.current===null||n)ne.current=a,re.current=o,U.current=e;else{let n=U.current;U.current=e;let r=$H(n?Math.min(64,e-n):16,LU);ne.current+=(a-ne.current)*r,re.current+=(o-re.current)*r,Math.abs(a-ne.current)<t*1e-6&&(ne.current=a),Math.abs(o-re.current)<t*1e-6&&(re.current=o)}}}else ne.current=null,re.current=null,U.current=0;let c=ot(),l=t.version?.(),u=se.current,d=le.current,f=d!==null&&l!==void 0&&d.ver===l&&d.x0===c.xmin&&d.x1===c.xmax&&d.mp===u&&d.cut===s;(nW(De.current)===0||!f&&e-oe.current>=zU)&&(oe.current=e,fe.current=t.cutOnGpu&&F.current?s:void 0,De.current=t.pull(c.xmin,c.xmax,u,s,fe.current!==void 0),le.current=l===void 0?null:{ver:l,x0:c.xmin,x1:c.xmax,mp:u,cut:s}),ae.current=!1,St(),Ct(),qH(e,performance.now()-r)}function Ot(){ie.current||=(U.current=0,NH(Dt))}function kt(){ie.current&&(PH(ie.current),ie.current=0,de.current=0,ne.current=null,re.current=null,De.current=[],fe.current=void 0)}W(()=>{let e=A.current,t=e?.ownerDocument.defaultView?.IntersectionObserver;if(!e||!t)return;let n=new t(e=>{let t=e[e.length-1];(t.isIntersecting||t.boundingClientRect.width>0)&&(ge.current=t.isIntersecting)});return n.observe(e),()=>{n.disconnect(),ge.current=!0}},[]),W(()=>(y?Ot():(kt(),wt()),kt),[!!y]),W(()=>rB(A.current,()=>{qe.current=null,wt()}),[]),W(()=>{qe.current=null,wt()},[o]);let At=!!f;W(()=>{let e=k.current;e&&(e.style.cursor=At?`ew-resize`:``),wt()},[At,f?.label??``]);let jt=s?.[0]??null,Mt=s?.[1]??null;return G(()=>{te.current===jt&&H.current===Mt||(te.current=jt,H.current=Mt,wt())},[jt,Mt]),W(()=>{Tt()},[t,n,i,e,p,m,h,g,v,Je]),W(()=>()=>{PH(He.current),PH(Ue.current),He.current=0,Ue.current=0},[]),W(()=>{let e=k.current,t=A.current;if(!e||!t)return;let n=()=>{let e=Math.round(t.clientWidth);e>0&&e!==M.current&&(M.current=e,j.current?.(e))};n();let r=new zH(()=>{qe.current=null,n(),wt()});r.observe(t);let i=JH(e=>$e.current?.(e)),a=t=>{if(Oe.current||Be.current!==null)return;if(nW(ct())<2){z.current!==null&&(z.current=null,Et(),i.set(null));return}let n=e.getBoundingClientRect(),r=t.clientX-n.left,a=t.clientY-n.top,{left:o,top:s,right:c,bottom:l}=IU(n.width),u=Math.max(1,n.width-o-c),d=n.height-s-l;if(r<o||r>o+u||a<s||a>s+d){z.current!==null&&(z.current=null,Et(),i.set(null));return}z.current!==r&&(z.current=r,Et());let{xmin:f,xmax:p}=ot();i.set(YH(r,o,u,f,p))},o=()=>{z.current!==null&&(z.current=null,Et()),i.set(null)},s=e=>{Xe.current&&clearTimeout(Xe.current),Xe.current=setTimeout(()=>{Xe.current=null,Qe.current?.(e)},kU)},c=t=>{if(Ne.current!==`none`||t.buttons&2||Date.now()-Ie.current<300||nW(ct())<2)return;let n=e.getBoundingClientRect(),r=t.clientX-n.left,i=t.clientY-n.top,{top:a,left:o,right:c,bottom:l}=IU(n.width),u=Math.max(1,n.width-o-c),d=Math.max(1,n.height-a-l);if(r<o||r>o+u||i<a||i>a+d)return;t.preventDefault();let f=it.current,p=f.xmax-f.xmin;if(!(p>0))return;if(Te.current===`follow`&&at()&&!Ce.current){Ee.current=rU(Ee.current,p,t.deltaY<0,p*.001);return}if(Te.current===`follow`&&at()){let e=rU(Se.current,ce.current?.bufferedSeconds?.()??p,t.deltaY<0);Se.current=e,Ze.current&&clearTimeout(Ze.current),Ze.current=setTimeout(()=>{Ze.current=null,Ce.current?.(e)},kU);return}let m=te.current??f.xmin,h=(H.current??f.xmax)-m;if(!(h>0))return;let g=Date.now();g-Fe.current>300&&(Le.current=te.current,Re.current=H.current),Fe.current=g;let _=m+(r-o)/u*h,v=t.deltaY<0,y=.88,b=v?h*y:h/y,x=Math.max(p*1e-7,1e-12);if(v)b=Math.max(b,x);else{if(b>=p*.999){te.current=null,H.current=null,s(null),et.current?.publish(tt.current??``,null),wt();return}b=Math.min(b,p)}let S=(_-m)/h,C=_-S*b,w=_+(1-S)*b;C<f.xmin&&(w+=f.xmin-C,C=f.xmin),w>f.xmax&&(C-=w-f.xmax,w=f.xmax),w-C<b-1e-12&&(C=Math.max(f.xmin,_-b/2),w=C+b,w>f.xmax&&(w=f.xmax,C=w-b)),w-C>=p*.999?(te.current=null,H.current=null,s(null),et.current?.publish(tt.current??``,null)):(te.current=C,H.current=w,s([C,w]),et.current?.publish(tt.current??``,[C,w])),wt()},l=e=>{if(e.preventDefault(),Ie.current=Date.now(),Date.now()-Fe.current<300){te.current=Le.current,H.current=Re.current;let e=Le.current,t=Re.current;Xe.current&&=(clearTimeout(Xe.current),null),Qe.current?.(e===null&&t===null?null:[e,t]),Fe.current=0,wt()}},u=t=>{if(t.button===0&&ze.current){let n=e.getBoundingClientRect(),{left:r,top:i,right:a,bottom:o}=IU(n.width),s=Math.max(1,n.width-r-a),c=n.height-i-o,l=t.clientX-n.left,u=t.clientY-n.top;if(l>=r&&l<=r+s&&u>=i&&u<=i+c){Be.current=t.clientX,ze.current.onDragStart();try{e.setPointerCapture(t.pointerId)}catch{}}return}if(t.button!==2)return;if(t.preventDefault(),t.buttons===0){nt.current?.({clientX:t.clientX,clientY:t.clientY});return}if(Ne.current!==`none`){Oe.current=!1,Ne.current=`none`;try{e.releasePointerCapture(t.pointerId)}catch{}}let n=e.getBoundingClientRect(),r=t.clientX-n.left,i=t.clientY-n.top;Pe.current=Date.now(),Ne.current=`menuOnly`,Oe.current=!1,ke.current=r,Ae.current=i,je.current=r,Me.current=i;try{e.setPointerCapture(t.pointerId)}catch{}},d=t=>{if(Be.current!==null){let n=t.clientX-Be.current,r=e.getBoundingClientRect(),{left:i,right:a}=IU(r.width),o=Math.max(1,r.width-i-a),{xmin:s,xmax:c}=ot(),l=c-s;l>0&&o>0&&ze.current?.onDragOffset(n/o*l);return}if(Ne.current===`none`)return;let n=e.getBoundingClientRect(),r=t.clientX-n.left,i=t.clientY-n.top;if(Ne.current===`menuOnly`){if(Date.now()-Pe.current<150)return;let e=r-ke.current,t=i-Ae.current;if(Math.sqrt(e*e+t*t)<12)return;let a=ct(),{top:o,left:s,right:c,bottom:l}=IU(n.width),u=n.width-s-c,d=n.height-o-l,f=u>0&&d>0&&ke.current>=s&&ke.current<=s+u&&Ae.current>=o&&Ae.current<=o+d;if(nW(a)<2||!f)return;Ne.current=`rubber`,Oe.current=!0,z.current=null}Ne.current===`rubber`&&(t.preventDefault(),je.current=r,Me.current=i,Et())},f=t=>{if(t.button!==2)return;t.preventDefault();let n=Ne.current;Ne.current=`none`;try{e.releasePointerCapture(t.pointerId)}catch{}if(n===`menuOnly`){Oe.current=!1,Et(),nt.current?.({clientX:t.clientX,clientY:t.clientY});return}if(n!==`rubber`||!Oe.current){Oe.current=!1,Et();return}Oe.current=!1;let r=ct(),i=e.getBoundingClientRect(),{left:a,right:o}=IU(i.width),s=Math.max(1,i.width-a-o),c=ke.current,l=je.current,u=Math.abs(l-c);if(nW(r)<2||u<12){nt.current?.({clientX:t.clientX,clientY:t.clientY}),Et();return}let d=ZU(Math.min(c,l),a,a+s),f=ZU(Math.max(c,l),a,a+s),{xmin:p,xmax:m}=ot(),h=m-p;if(!(h>0)){nt.current?.({clientX:t.clientX,clientY:t.clientY}),Et();return}let g=p+(d-a)/s*h,_=p+(f-a)/s*h;if(g>_){let e=g;g=_,_=e}let v=it.current,y=Math.min(v.xmin,v.xmax),b=Math.max(v.xmin,v.xmax);g=ZU(g,y,b),_=ZU(_,y,b);let x=_-g;if(x<=(b-y)*1e-12||x<=0){nt.current?.({clientX:t.clientX,clientY:t.clientY}),Et();return}nt.current?.({clientX:t.clientX,clientY:t.clientY,zoomXRange:[g,_]}),Et()},p=t=>{if(t.button===0&&Be.current!==null){Be.current=null;try{e.releasePointerCapture(t.pointerId)}catch{}return}if(t.button===2){f(t);return}if(t.buttons===0&&Ne.current!==`none`){Ne.current=`none`,Oe.current=!1;try{e.releasePointerCapture(t.pointerId)}catch{}nt.current?.({clientX:t.clientX,clientY:t.clientY}),Et()}},m=t=>{Be.current!==null&&(Be.current=null),Ne.current!==`none`&&(Oe.current=!1,Ne.current=`none`);try{e.releasePointerCapture(t.pointerId)}catch{}Et()},h=t=>{if(t.button!==0||nW(ct())<2)return;let n=e.getBoundingClientRect(),r=t.clientX-n.left,i=t.clientY-n.top,{top:a,left:o,right:s,bottom:c}=IU(n.width),l=Math.max(1,n.width-o-s),u=Math.max(1,n.height-a-c);r<o||r>o+l||i<a||i>a+u||te.current===null&&H.current===null||(te.current=null,H.current=null,Xe.current&&=(clearTimeout(Xe.current),null),Qe.current?.(null),et.current?.publish(tt.current??``,null),wt(),Et())},g=e=>{if(e.key!==`Escape`)return;let t=!1;Ne.current!==`none`&&(Ne.current=`none`,Oe.current=!1,t=!0),Be.current!==null&&(Be.current=null,t=!0),t&&Et()};e.addEventListener(`mousemove`,a),e.addEventListener(`mouseleave`,o),e.addEventListener(`wheel`,c,{passive:!1}),e.addEventListener(`contextmenu`,l),e.addEventListener(`pointerdown`,u),e.addEventListener(`pointermove`,d),e.addEventListener(`pointerup`,p),e.addEventListener(`pointercancel`,m),e.addEventListener(`dblclick`,h);let _=e.ownerDocument.defaultView??window;return _.addEventListener(`keydown`,g),()=>{r.disconnect(),e.removeEventListener(`mousemove`,a),e.removeEventListener(`mouseleave`,o),e.removeEventListener(`wheel`,c),e.removeEventListener(`contextmenu`,l),e.removeEventListener(`pointerdown`,u),e.removeEventListener(`pointermove`,d),e.removeEventListener(`pointerup`,p),e.removeEventListener(`pointercancel`,m),e.removeEventListener(`dblclick`,h),_.removeEventListener(`keydown`,g),Xe.current&&clearTimeout(Xe.current),Ze.current&&clearTimeout(Ze.current)}},[]),vt(`div`,{ref:A,className:`chart-canvas-wrap`,children:[q(`canvas`,{ref:E,className:`chart-canvas`,role:`img`,"aria-label":`Chart of ${e}`}),q(`canvas`,{ref:O,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),q(`canvas`,{ref:D,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}},ve),q(`canvas`,{ref:k,className:`chart-canvas chart-overlay`})]})}function mW(){try{if(localStorage.getItem(`perfLog`)===`1`)return!0;if(localStorage.getItem(`perfLog`)===`0`)return!1}catch{}return!1}var hW=!1;function gW(){let e=mW();return e&&!hW&&(hW=!0,console.log(`[perf] logging enabled — zoom an out-of-core chart to see decimate()/sampleRows timings`)),e}gW();var _W=new Map;function vW(e,t){let n=(_W.get(e)??0)+1;_W.set(e,n),console.log(`[perf] ${e} #${n} ${t.toFixed(1)}ms`)}async function yW(e,t){if(!gW())return t();let n=performance.now();try{return await t()}finally{vW(e,performance.now()-n)}}var bW=20;async function xW(e,t,n,r){let{x0:i,bucket:a,rows:o,columns:s}=await yW(`decimate(${t.length}col)`,()=>e.getSeriesMulti(t,n,r));return Ce(o,s,i,a)}function SW(e,t,n,r,i=0,a=!1,o=0){let[s,c]=pt({points:M,fetchedViewport:null}),[l,u]=pt(!1),d=`${t.join(`,`)}|${n?`${n.xKey}:${n.x0}:${n.x1}`:`none`}|${r}|${i}`,f=ft(()=>{if(!a||!e?.getSeriesMultiSync||!n||t.length===0)return null;let i=o>0?e.getColumnsSync?.(t,n,o):null;if(i)return{points:i,loading:!1,fetchedViewport:n,full:!0};let s=e.getSeriesMultiSync(t,n,r);return{points:Ce(s.rows,s.columns,s.x0,s.bucket),loading:!1,fetchedViewport:n}},[a,e,d,o]);return W(()=>{if(a)return;if(!e||!n||t.length===0){c({points:M,fetchedViewport:null});return}let i=!0;u(!0);let o=setTimeout(()=>{xW(e,t,n,r).then(t=>{i&&(c({points:t,fetchedViewport:n,source:e}),u(!1))}).catch(()=>{i&&u(!1)})},bW);return()=>{i=!1,clearTimeout(o)}},[e,d,a]),f||(s.source!==void 0&&s.source!==e?{points:M,loading:l,fetchedViewport:null}:{points:s.points,loading:l,fetchedViewport:s.fetchedViewport})}var CW=250,wW=2,TW=6e3,EW=2e6,DW=[];function OW(e,t,r,i,a,o){let s=!!e&&e.columnSet.has(r),c=ft(()=>e&&s?t.filter(t=>e.columnSet.has(t)):DW,[e,s,t]),l=e&&s&&c.length>0?e.source:null,d=!!l&&!e?.live&&!!l.getSeriesMultiSync&&!!l.xBoundsSync,f=ft(()=>d&&l?l.xBoundsSync(r):null,[d,l,r]),[p,m]=pt(null),h=!!e?.live;W(()=>{if(!l||d)return;let e=!0,t=()=>l.xBounds(r).then(t=>{let n=l.version?.()??0;e&&m(e=>e&&e.source===l&&e.xKey===r&&e.ver===n?e:{source:l,xKey:r,b:t,ver:n})}).catch(()=>{});t();let n=h?setInterval(t,CW):void 0;return()=>{e=!1,clearInterval(n)}},[l,r,h,d]);let g=p&&p.source===l&&p.xKey===r?p:null,_=f??g?.b??null,v=g?.ver??0,{points:y,loading:b,full:x}=SW(l,c,l&&_&&_.x1>_.x0?{xKey:r,x0:_.x0,x1:_.x1}:null,Math.min(TW,a*wW),v,d,o),S=e?.xOffset??0,C=i&&i[1]>i[0]?i[0]-S:null,w=i&&i[1]>i[0]?i[1]-S:null,T=x||!!_&&C!==null&&w!==null&&C<=_.x0&&w>=_.x1,{points:E,fetchedViewport:D}=SW(l,c,l&&C!==null&&w!==null&&!T?{xKey:r,x0:C,x1:w}:null,a,v,d,o),O=ft(()=>!D||E.length===0?y:N([u(y,e=>e<D.x0),E,u(y,e=>e>D.x1)]),[y,E,D]),k=!!l&&(_===null||b);return ft(()=>e?{points:n(O,e.keySuffix,e.xOffset),bounds:_?{x0:_.x0+e.xOffset,x1:_.x1+e.xOffset}:null,loading:k}:{points:M,bounds:null,loading:!1},[e,O,_,k])}var kW=new WeakMap,AW=0;function jW(e){if(e.key!==void 0)return e.key;let t=kW.get(e.source);return t===void 0&&kW.set(e.source,t=AW++),`${t}${e.keySuffix}`}function MW(){let[e,t]=pt(()=>new Map);return[e,lt((e,n)=>t(t=>{if(n?t.get(e)===n:!t.has(e))return t;let r=new Map(t);return n?r.set(e,n):r.delete(e),r}),[])]}var NW=st(function({id:e,layer:t,columns:n,xKey:r,view:i,mp:a,rawLimit:o,report:s}){let c=OW(t,n,r,i,a,o);return G(()=>{s(e,c)},[e,c,s]),G(()=>()=>s(e,null),[e,s]),null});function PW({layers:e,xKey:t,columns:n,maxPoints:r,...i}){let a=i.viewXRange??null,[o,s]=pt(null),c=typeof window<`u`?Math.min(3,Math.max(1,window.devicePixelRatio||1)):1,l=o==null?r:Math.min(r,Math.round(o*c/50)*50),u=Math.max(1e3,Math.round(l/Math.sqrt(Math.max(1,e.length)))),d=Math.floor(EW/Math.max(1,e.length)),[f,p]=MW(),m=ft(()=>e.map(jW),[e]),h=ft(()=>m.map(e=>f.get(e)),[m,f]),g=ft(()=>h.flatMap(e=>e&&e.points.length>0?[e.points]:[]),[h]),_=ft(()=>{let e=1/0,t=-1/0;for(let n of h){let r=n?.bounds;r&&(e=Math.min(e,r.x0),t=Math.max(t,r.x1))}return Number.isFinite(e)&&t>e?[e,t]:null},[h]),v=h.some(e=>!e||e.loading);return vt(_t,{children:[e.map((e,r)=>q(NW,{id:m[r],layer:e,columns:n,xKey:t,view:a,mp:u,rawLimit:d,report:p},m[r])),g.length===0?vt(`div`,{className:`chart-placeholder chart-placeholder--no-data`,onContextMenu:e=>{e.preventDefault(),i.onPlotContextMenu?.({clientX:e.clientX,clientY:e.clientY})},children:[q(`span`,{className:`content-empty-icon`,"aria-hidden":!0}),q(`h2`,{children:v?`Loading…`:`No data to plot`}),v?null:q(`p`,{children:`None of the selected datasets has this X column together with a plotted channel.`})]}):q(pW,{points:g,fullXRange:_,...i,onPlotWidthCss:s})]})}function FW(e){return!!e&&!Array.isArray(e)&&typeof e.length==`number`&&`x`in e&&`y`in e}function IW(e){let t=e.length,n=new Float64Array(t),r=new Float64Array(t),i=t>0&&e[0].c!==void 0?new Float32Array(t):void 0,a=e.some(e=>e.d!==void 0)?new Uint8Array(t):void 0;for(let o=0;o<t;o++){let t=e[o];n[o]=t.x,r[o]=t.y,i&&(i[o]=t.c??0),a&&(a[o]=t.d??0)}return{length:t,x:n,y:r,c:i,d:a}}function LW(e,t,n){let r=n?.get(t);if(r)return r;let i=Ae(e);if(i)return Ue(i,t);if(e.length===0||!(t in e[0]))return;let a=new Float64Array(e.length);for(let n=0;n<e.length;n++){let r=e[n][t];a[n]=typeof r==`number`?r:NaN}return a}function RW(e,t,n){let r=LW(e,t,n);if(!r||c.has(r))return r;let i=0;for(let e=0;e<r.length;e++)r[e]-r[e]===0&&i++;if(i===r.length)return r;let a=new Float64Array(i);for(let e=0,t=0;e<r.length;e++)r[e]-r[e]===0&&(a[t++]=r[e]);return a}function zW(e,t,n,r){if(!n){let n=RW(e,t,r);return n?[{label:t,values:n}]:[]}let i=LW(e,t,r);if(!i)return[];let a=i.length,o=r?.has(n)||e.length>0&&typeof e[0][n]==`number`?LW(e,n,r):void 0,s=t=>{if(o){let e=o[t];return e===e?String(e):`unknown`}return String(e[t]?.[n]??`unknown`)},c=new Map,l=[],u=new Int32Array(a),d=[];for(let e=0;e<a;e++){if(i[e]-i[e]!==0){u[e]=-1;continue}let t=s(e),n=c.get(t);n===void 0&&(c.set(t,n=l.length),l.push(t),d.push(0)),u[e]=n,d[n]++}let f=l.map((e,t)=>({label:e,values:new Float64Array(d[t])})),p=new Int32Array(l.length);for(let e=0;e<a;e++){let t=u[e];t>=0&&(f[t].values[p[t]++]=i[e])}return f}function BW(e){let t=NaN,n=NaN,r=0;for(let i=0;i<e.length;i++){let a=e[i];a-a===0&&(r===0&&(t=a),n=a,r++)}let i=n-t;return r>1&&i>0?(r-1)/i:null}function VW(e,t,n){let r=0;for(let i=0;i<e.length;i++)e[i]>=t&&e[i]<=n&&r++;let i=new Uint32Array(r),a=0;for(let r=0;r<e.length;r++)e[r]>=t&&e[r]<=n&&(i[a++]=r);return i}function HW(e,t){let n=new Float64Array(t.length);for(let r=0;r<t.length;r++)n[r]=e[t[r]];return n}function UW(e,t,n,r){let i=LW(e.rows,t,e.full),a=LW(e.rows,n,e.full);if(!i||!a)return null;let o=r.colorCol?LW(e.rows,r.colorCol,e.full):void 0;if(r.viewXRange){let t=LW(e.rows,r.xKey,e.full);if(t){let e=VW(t,r.viewXRange[0],r.viewXRange[1]);i=HW(i,e),a=HW(a,e),o&&=HW(o,e)}}let s=Math.min(i.length,a.length);if(!o)return{cols:{length:s,x:i,y:a}};let c=1/0,l=-1/0;for(let e=0;e<s;e++){let t=o[e];t<c&&(c=t),t>l&&(l=t)}if(!(l>c))return{cols:{length:s,x:i,y:a}};let u=new Float32Array(s),d=l-c;for(let e=0;e<s;e++){let t=o[e];u[e]=t===t?(t-c)/d:0}return{cols:{length:s,x:i,y:a,c:u},color:{label:r.colorCol,min:c,max:l}}}function WW(e,t,n,r){let i=[],a=[];e.forEach((e,o)=>{a.push(Zz(r.colorOverrides,e.id,o,r.palette));let s=UW(e,t,n,{xKey:r.xKey,viewXRange:r.viewXRange});i.push(s?.cols??{length:0,x:[],y:[]})});let o=i.reduce((e,t)=>e+t.length,0),s=new Float64Array(o),c=new Float64Array(o),l=new Uint8Array(o),u=0;return i.forEach((e,t)=>{for(let t=0;t<e.length;t++)s[u+t]=e.x[t],c[u+t]=e.y[t];l.fill(Math.min(t,255),u,u+e.length),u+=e.length}),{cols:{length:o,x:s,y:c,d:l},colors:a}}var GW=e=>FW(e)?e:IW(e),KW=(e,t,n)=>t===t&&n===n&&(!e||t>=e.xmin&&t<=e.xmax&&n>=e.ymin&&n<=e.ymax);function qW(e,t,n){let r=t+1,i=Array.from({length:r},()=>Array(r).fill(0)),a=Array(r).fill(0),o=new Float64Array(2*r-1),s=0;for(let t=0;t<e.length;t++){let c=e.x[t],l=e.y[t];if(KW(n,c,l)){s++,o[0]=1;for(let e=1;e<o.length;e++)o[e]=o[e-1]*c;for(let e=0;e<r;e++){for(let t=0;t<r;t++)i[e][t]+=o[e+t];a[e]+=o[e]*l}}}if(s<r)return null;let c=i.map((e,t)=>[...e,a[t]]);for(let e=0;e<r;e++){let t=e;for(let n=e+1;n<r;n++)Math.abs(c[n][e])>Math.abs(c[t][e])&&(t=n);if([c[e],c[t]]=[c[t],c[e]],Math.abs(c[e][e])<1e-10)return null;let n=c[e][e];for(let t=e;t<=r;t++)c[e][t]/=n;for(let t=0;t<r;t++){if(t===e)continue;let n=c[t][e];for(let i=e;i<=r;i++)c[t][i]-=n*c[e][i]}}return c.map(e=>e[r])}function JW(e,t,n){return qW(GW(e),t,n)}function YW(e,t){let n=GW(e),r=0,i=0;for(let e=0;e<n.length;e++)KW(void 0,n.x[e],n.y[e])&&(r++,i+=n.y[e]);if(r===0)return 0;let a=i/r,o=0,s=0;for(let e=0;e<n.length;e++){let r=n.x[e],i=n.y[e];if(!KW(void 0,r,i))continue;let c=0;for(let e=t.length-1;e>=0;e--)c=c*r+t[e];o+=(i-a)**2,s+=(i-c)**2}return o<1e-15?1:Math.max(0,1-s/o)}function XW(e,t=4){if(!Number.isFinite(e))return`?`;let n=Math.abs(e);return n===0?`0`:n>=1e5||n>0&&n<.001?e.toExponential(2):e.toPrecision(t).replace(/\.?0+$/,``)}function ZW(e,t,n){let r=[];for(let n=e.length-1;n>=0;n--){let i=e[n];n===0?r.push(XW(i)):n===1?r.push(`${XW(i)}·${t}`):r.push(`${XW(i)}·${t}${n>1?`^${n}`:``}`)}return`${n} = ${r.join(` + `).replace(/\+ -/g,`− `)}`}var QW=[[0,45,80,160],[.25,40,145,175],[.5,60,180,110],[.75,220,175,55],[1,210,75,55]];function $W(e){let t=0;for(let n=1;n<QW.length;n++){if(e<=QW[n][0]){t=n-1;break}n===QW.length-1&&(t=n-1)}let n=t+1,r=(e-QW[t][0])/(QW[n][0]-QW[t][0]);return{r:Math.round(QW[t][1]+r*(QW[n][1]-QW[t][1])),g:Math.round(QW[t][2]+r*(QW[n][2]-QW[t][2])),b:Math.round(QW[t][3]+r*(QW[n][3]-QW[t][3]))}}function eG(e){let{r:t,g:n,b:r}=$W(e);return`rgb(${t},${n},${r})`}function tG(e,t){if(!Number.isFinite(e))return 0;let n=Math.floor(e*t);return n<0?0:n>=t?t-1:n}var nG=`#version 300 es
|
|
208
208
|
in vec2 a_corner;
|
|
209
209
|
in float a_x;
|
|
210
210
|
in float a_y;
|
|
@@ -229,7 +229,7 @@ void main() {
|
|
|
229
229
|
v_tex = (clamp(floor(a_k * u_kScale + 0.5), 0.0, 255.0) + 0.5) / 256.0;
|
|
230
230
|
vec2 clip = pos / u_resolution * 2.0 - 1.0;
|
|
231
231
|
gl_Position = vec4(clip.x, -clip.y, 0.0, 1.0);
|
|
232
|
-
}`,
|
|
232
|
+
}`,rG=`#version 300 es
|
|
233
233
|
precision highp float;
|
|
234
234
|
in vec2 v_local;
|
|
235
235
|
in float v_tex;
|
|
@@ -249,7 +249,7 @@ void main() {
|
|
|
249
249
|
vec4 c = texture(u_palette, vec2(v_tex, 0.5));
|
|
250
250
|
float a = c.a * u_alpha * cov;
|
|
251
251
|
outColor = vec4(c.rgb * a, a);
|
|
252
|
-
}`,
|
|
252
|
+
}`,iG=`#version 300 es
|
|
253
253
|
in float a_x;
|
|
254
254
|
in float a_y;
|
|
255
255
|
in float a_k;
|
|
@@ -268,7 +268,7 @@ void main() {
|
|
|
268
268
|
v_tex = (clamp(floor(a_k * u_kScale + 0.5), 0.0, 255.0) + 0.5) / 256.0;
|
|
269
269
|
vec2 clip = p / u_resolution * 2.0 - 1.0;
|
|
270
270
|
gl_Position = vec4(clip.x, -clip.y, 0.0, 1.0);
|
|
271
|
-
}`,
|
|
271
|
+
}`,aG=`#version 300 es
|
|
272
272
|
precision highp float;
|
|
273
273
|
in float v_tex;
|
|
274
274
|
uniform sampler2D u_palette;
|
|
@@ -287,7 +287,7 @@ void main() {
|
|
|
287
287
|
vec4 c = texture(u_palette, vec2(v_tex, 0.5));
|
|
288
288
|
float a = c.a * u_alpha * cov;
|
|
289
289
|
outColor = vec4(c.rgb * a, a);
|
|
290
|
-
}`,
|
|
290
|
+
}`,oG=`#version 300 es
|
|
291
291
|
in vec2 a_corner;
|
|
292
292
|
in float a_ax;
|
|
293
293
|
in float a_ay;
|
|
@@ -322,7 +322,7 @@ void main() {
|
|
|
322
322
|
v_tex = (clamp(floor(a_k * u_kScale + 0.5), 0.0, 255.0) + 0.5) / 256.0;
|
|
323
323
|
vec2 clip = pos / u_resolution * 2.0 - 1.0;
|
|
324
324
|
gl_Position = vec4(clip.x, -clip.y, 0.0, 1.0);
|
|
325
|
-
}`,
|
|
325
|
+
}`,sG=`#version 300 es
|
|
326
326
|
precision highp float;
|
|
327
327
|
flat in vec2 v_a;
|
|
328
328
|
flat in vec2 v_b;
|
|
@@ -343,7 +343,7 @@ void main() {
|
|
|
343
343
|
vec4 c = texture(u_palette, vec2(v_tex, 0.5));
|
|
344
344
|
float a = c.a * cov;
|
|
345
345
|
outColor = vec4(c.rgb * a, a);
|
|
346
|
-
}`,
|
|
346
|
+
}`,cG=`
|
|
347
347
|
uniform vec2 u_ox;
|
|
348
348
|
uniform vec2 u_oy;
|
|
349
349
|
float dbl(uvec2 b, vec2 o) {
|
|
@@ -357,21 +357,21 @@ float dbl(uvec2 b, vec2 o) {
|
|
|
357
357
|
float l = float(b.x & 0x1FFFFFFFu) * exp2(float(int(e) - 1075));
|
|
358
358
|
return (h - o.x) + ((sgn != 0u ? -l : l) - o.y);
|
|
359
359
|
}
|
|
360
|
-
`;function
|
|
361
|
-
`)}${c}`)}var
|
|
360
|
+
`;function lG(e,t,n,r){let i=cG,a=e,o=[];for(let[e,r]of[[t,`u_ox`],[n,`u_oy`]])for(let t of e)a=a.replace(`in float ${t};`,`in uvec2 ${t}_bits;`),o.push(` float ${t} = dbl(${t}_bits, ${r});`);let s=[...t,...n].map(e=>`${e} != ${e}`).join(` || `),c=r?`\n if (${s}) { gl_Position = vec4(2.0, 2.0, 2.0, 1.0); return; }`:``;return a.replace(`void main() {`,`${i}void main() {\n${o.join(`
|
|
361
|
+
`)}${c}`)}var uG=`#version 300 es
|
|
362
362
|
in uvec2 a_x_bits;
|
|
363
363
|
in uvec2 a_y_bits;
|
|
364
364
|
out float v_x;
|
|
365
365
|
out float v_y;
|
|
366
|
-
${
|
|
366
|
+
${cG}
|
|
367
367
|
void main() {
|
|
368
368
|
v_x = dbl(a_x_bits, u_ox);
|
|
369
369
|
v_y = dbl(a_y_bits, u_oy);
|
|
370
370
|
gl_Position = vec4(0.0);
|
|
371
|
-
}`,
|
|
371
|
+
}`,dG=`#version 300 es
|
|
372
372
|
precision mediump float;
|
|
373
373
|
out vec4 o;
|
|
374
|
-
void main() { o = vec4(0.0); }`;function XW(e,t,n,r){let i=JV(e,e.VERTEX_SHADER,t),a=JV(e,e.FRAGMENT_SHADER,n);if(!i||!a)return null;let o=e.createProgram();return e.attachShader(o,i),e.attachShader(o,a),r&&e.transformFeedbackVaryings(o,r,e.SEPARATE_ATTRIBS),e.linkProgram(o),e.getProgramParameter(o,e.LINK_STATUS)?{prog:o,shaders:[i,a]}:(console.error(`glPoints program link failed:`,e.getProgramInfoLog(o)),null)}function ZW(e){let t=e.getContext(`webgl2`,{antialias:!1,alpha:!0,premultipliedAlpha:!0});if(!t)return null;let n=pH(t,`glPoints|points`,()=>XW(t,BW,VW)),r=pH(t,`glPoints|lines`,()=>XW(t,WW,GW)),i=pH(t,`glPoints|points64`,()=>XW(t,qW(BW,[`a_x`],[`a_y`],!0),VW)),a=pH(t,`glPoints|sprites`,()=>XW(t,HW,UW)),o=pH(t,`glPoints|sprites64`,()=>XW(t,qW(HW,[`a_x`],[`a_y`],!0),UW)),s=t.getParameter(t.ALIASED_POINT_SIZE_RANGE)[1],l=pH(t,`glPoints|decode`,()=>XW(t,JW,YW,[`v_x`,`v_y`])),u=t.createVertexArray();if(!n||!r)return null;let d=(e,n)=>Object.fromEntries(n.map(n=>[n,t.getAttribLocation(e,n)])),f=(e,n)=>Object.fromEntries(n.map(n=>[n,t.getUniformLocation(e,n)])),p=d(n.prog,[`a_corner`,`a_x`,`a_y`,`a_k`,`a_r`]),m=f(n.prog,[`u_resolution`,`u_plot`,`u_view`,`u_radius`,`u_kScale`,`u_palette`,`u_alpha`,`u_clip`,`u_dpr`,`u_height`]),h=d(r.prog,[`a_corner`,`a_ax`,`a_ay`,`a_bx`,`a_by`,`a_bstart`,`a_k`]),g=f(r.prog,[`u_resolution`,`u_plot`,`u_view`,`u_ext`,`u_kScale`,`u_palette`,`u_half`,`u_clip`]),_=i&&d(i.prog,[`a_corner`,`a_x_bits`,`a_y_bits`,`a_k`,`a_r`]),v=i&&f(i.prog,[`u_resolution`,`u_plot`,`u_view`,`u_radius`,`u_kScale`,`u_palette`,`u_alpha`,`u_clip`,`u_dpr`,`u_height`,`u_ox`,`u_oy`]),y=[`u_resolution`,`u_plot`,`u_view`,`u_radius`,`u_kScale`,`u_palette`,`u_alpha`,`u_clip`,`u_dpr`,`u_height`],b=a&&d(a.prog,[`a_x`,`a_y`,`a_k`]),x=a&&f(a.prog,y),S=o&&d(o.prog,[`a_x_bits`,`a_y_bits`,`a_k`]),C=o&&f(o.prog,[...y,`u_ox`,`u_oy`]),w=l&&d(l.prog,[`a_x_bits`,`a_y_bits`]),T=l&&f(l.prog,[`u_ox`,`u_oy`]),E=t.createTransformFeedback(),D=t.createVertexArray(),O=t.createBuffer(),k=t.createBuffer(),A=!1,j=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,j),t.bufferData(t.ARRAY_BUFFER,Float32Array.from([-1,-1,1,-1,-1,1,1,1]),t.STATIC_DRAW);let M=t.createBuffer(),N=t.createBuffer(),P=t.createBuffer(),F=t.createBuffer(),I=t.createBuffer(),L=t.createTexture(),R=0,z=!1,B=!1,V=!1,ee=0,te=0,H=1,ne=1,re=1,ie=1.8,U=.8,ae=255,oe=!0,se=!1,ce=1,le={xmin:0,xmax:1,ymin:0,ymax:1},ue={left:0,top:0,width:1,height:1},de=new Float32Array,fe=new Float32Array,pe=new Float32Array,me=new Uint8Array,he=new Float32Array,ge=new Map,_e=(e,n,r)=>{t.bindBuffer(t.ARRAY_BUFFER,e);let i=r*n.BYTES_PER_ELEMENT;i<=(ge.get(e)??0)?t.bufferSubData(t.ARRAY_BUFFER,0,n,0,r):(t.bufferData(t.ARRAY_BUFFER,n.subarray(0,r),t.DYNAMIC_DRAW),ge.set(e,i))},ve=(e,n,r=0,i=t.FLOAT)=>{t.bindBuffer(t.ARRAY_BUFFER,n),t.enableVertexAttribArray(e);let a=i===t.FLOAT?4:1;t.vertexAttribPointer(e,1,i,i!==t.FLOAT,a,r*a),t.vertexAttribDivisor(e,1)},ye=(e,n,r=0)=>{t.bindBuffer(t.ARRAY_BUFFER,n),t.enableVertexAttribArray(e),t.vertexAttribIPointer(e,2,t.UNSIGNED_INT,8,r*8),t.vertexAttribDivisor(e,1)},be=e=>{t.bindBuffer(t.ARRAY_BUFFER,j),t.enableVertexAttribArray(e),t.vertexAttribPointer(e,2,t.FLOAT,!1,0,0),t.vertexAttribDivisor(e,0)};return{resize(t,n,r){H=Math.max(1,t),ne=Math.max(1,n),re=r,e.width=Math.round(H*re),e.height=Math.round(ne*re)},setData(e,t,n,r=!1,i){let a=Math.min(e.length,t.length);de.length<a&&(de=new Float32Array(a),fe=new Float32Array(a)),z=!!n,B=!!i,n&&pe.length<a&&(pe=new Float32Array(a)),i&&he.length<a&&(he=new Float32Array(a)),se&&me.length<a&&(me=new Uint8Array(a)),ee=0,te=0;for(let n=0;n<a;n++)if(e[n]-e[n]===0&&t[n]-t[n]===0){ee=e[n],te=t[n];break}let o=c.has(e)&&c.has(t);if(V=!!_&&!!l&&e instanceof Float64Array&&t instanceof Float64Array&&(o||!se),A=!1,V){if(_e(M,e,a),_e(N,t,a),n){for(let e=0;e<a;e++)pe[e]=n[e];_e(P,pe,a)}if(i){for(let e=0;e<a;e++)he[e]=i[e];_e(I,he,a)}if(se){if(me.fill(0,0,a),a&&(me[0]=255),n&&r)for(let e=1;e<a;e++)n[e]!==n[e-1]&&(me[e]=255);_e(F,me,a)}R=a;return}let s=0;if(c.has(e)&&c.has(t)){for(let t=0;t<a;t++)de[t]=e[t]-ee;for(let e=0;e<a;e++)fe[e]=t[e]-te;if(n)for(let e=0;e<a;e++)pe[e]=n[e];if(i)for(let e=0;e<a;e++)he[e]=i[e];if(se&&(me.fill(0,0,a),a&&(me[0]=255),n&&r))for(let e=1;e<a;e++)n[e]!==n[e-1]&&(me[e]=255);s=a}else{let o=!0;for(let c=0;c<a;c++){let a=e[c],l=t[c];if(a-a!==0||l-l!==0){o=!0;continue}de[s]=a-ee,fe[s]=l-te,n&&(pe[s]=n[c]),i&&(he[s]=i[c]),se&&(me[s]=o||r&&n&&s>0&&n[c]!==pe[s-1]?255:0),o=!1,s++}}R=s,_e(M,de,s),_e(N,fe,s),n&&_e(P,pe,s),i&&_e(I,he,s),se&&_e(F,me,s)},setStyle(e,n,r){ie=n,U=r;let i=new Uint8Array(256*4);if(e.kind===`single`){let t=e.rgba.map(e=>Math.round(e*255));for(let e=0;e<256;e++)i.set(t,e*4);ae=0}else i.set(e.palette.subarray(0,256*4)),ae=e.kind===`colormap`?255:1;t.bindTexture(t.TEXTURE_2D,L),t.texImage2D(t.TEXTURE_2D,0,t.RGBA8,256,1,0,t.RGBA,t.UNSIGNED_BYTE,i),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE)},setDraw(e,t,n){oe=e,se=t,ce=n},setView(e,t,n,r,i){le={xmin:e,xmax:t,ymin:n,ymax:r},ue=i},render(){if(t.bindFramebuffer(t.FRAMEBUFFER,null),t.viewport(0,0,e.width,e.height),t.disable(t.SCISSOR_TEST),t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT),R===0)return;t.bindVertexArray(u),t.enable(t.BLEND),t.blendFunc(t.ONE,t.ONE_MINUS_SRC_ALPHA),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,L);let c=z?ae:0,d=[le.xmin-ee,le.xmax-ee,le.ymin-te,le.ymax-te],f=[ue.left,ue.top,ue.left+ue.width,ue.top+ue.height],y=e=>{let t=Math.fround(e);return[t,e-t]},j=V,de=M,fe=N;if(V&&se&&R>1){if(!A){for(let e of[O,k])t.bindBuffer(t.ARRAY_BUFFER,e),(ge.get(e)??0)<R*4&&(t.bufferData(t.ARRAY_BUFFER,R*4,t.DYNAMIC_COPY),ge.set(e,R*4));t.bindBuffer(t.ARRAY_BUFFER,null),t.bindVertexArray(D),t.useProgram(l.prog),t.uniform2f(T.u_ox,...y(ee)),t.uniform2f(T.u_oy,...y(te)),ye(w.a_x_bits,M),ye(w.a_y_bits,N),t.vertexAttribDivisor(w.a_x_bits,0),t.vertexAttribDivisor(w.a_y_bits,0),t.enable(t.RASTERIZER_DISCARD),t.bindTransformFeedback(t.TRANSFORM_FEEDBACK,E),t.bindBufferBase(t.TRANSFORM_FEEDBACK_BUFFER,0,O),t.bindBufferBase(t.TRANSFORM_FEEDBACK_BUFFER,1,k),t.beginTransformFeedback(t.POINTS),t.drawArrays(t.POINTS,0,R),t.endTransformFeedback(),t.bindBufferBase(t.TRANSFORM_FEEDBACK_BUFFER,0,null),t.bindBufferBase(t.TRANSFORM_FEEDBACK_BUFFER,1,null),t.bindTransformFeedback(t.TRANSFORM_FEEDBACK,null),t.disable(t.RASTERIZER_DISCARD),t.bindVertexArray(u),A=!0}j=!1,de=O,fe=k}if(se&&R>1){let e=g,n=h;t.useProgram(r.prog),t.uniform2f(e.u_resolution,H,ne),t.uniform4f(e.u_plot,ue.left,ue.top,ue.width,ue.height),t.uniform4f(e.u_view,...d),t.uniform1f(e.u_half,ce/2),t.uniform1f(e.u_ext,ce/2+1),t.uniform1f(e.u_kScale,c),t.uniform4f(e.u_clip,...f),t.uniform1i(e.u_palette,0),be(n.a_corner),ve(n.a_ax,de,0),ve(n.a_bx,de,1),ve(n.a_ay,fe,0),ve(n.a_by,fe,1),ve(n.a_bstart,F,1,t.UNSIGNED_BYTE),z?ve(n.a_k,P,0):(t.disableVertexAttribArray(n.a_k),t.vertexAttrib1f(n.a_k,0)),t.drawArraysInstanced(t.TRIANGLE_STRIP,0,4,R-1);for(let e of Object.values(n))t.vertexAttribDivisor(e,0)}if(oe&&!B&&2*(ie+.5)*re<=s&&(j?o:a)){let n=j?C:x,r=j?S:b;t.useProgram((j?o:a).prog),j&&(t.uniform2f(n.u_ox,...y(ee)),t.uniform2f(n.u_oy,...y(te))),t.uniform2f(n.u_resolution,H,ne),t.uniform4f(n.u_plot,ue.left,ue.top,ue.width,ue.height),t.uniform4f(n.u_view,...d),t.uniform1f(n.u_radius,ie),t.uniform1f(n.u_kScale,c),t.uniform1f(n.u_alpha,U),t.uniform4f(n.u_clip,...f),t.uniform1f(n.u_dpr,re),t.uniform1f(n.u_height,e.height),t.uniform1i(n.u_palette,0),j?(ye(r.a_x_bits,M),ye(r.a_y_bits,N)):(ve(r.a_x,de),ve(r.a_y,fe)),z?ve(r.a_k,P):(t.disableVertexAttribArray(r.a_k),t.vertexAttrib1f(r.a_k,0));for(let e of Object.values(r))t.vertexAttribDivisor(e,0);t.drawArrays(t.POINTS,0,R)}else if(oe){let r=j?v:m,a=j?_:p;t.useProgram(j?i.prog:n.prog),j&&(t.uniform2f(r.u_ox,...y(ee)),t.uniform2f(r.u_oy,...y(te))),t.uniform2f(r.u_resolution,H,ne),t.uniform4f(r.u_plot,ue.left,ue.top,ue.width,ue.height),t.uniform4f(r.u_view,...d),t.uniform1f(r.u_radius,ie),t.uniform1f(r.u_kScale,c),t.uniform1f(r.u_alpha,U),t.uniform4f(r.u_clip,...f),t.uniform1f(r.u_dpr,re),t.uniform1f(r.u_height,e.height),t.uniform1i(r.u_palette,0),be(a.a_corner),j?(ye(a.a_x_bits,M),ye(a.a_y_bits,N)):(ve(a.a_x,de),ve(a.a_y,fe)),z?ve(a.a_k,P):(t.disableVertexAttribArray(a.a_k),t.vertexAttrib1f(a.a_k,0)),B?ve(a.a_r,I):(t.disableVertexAttribArray(a.a_r),t.vertexAttrib1f(a.a_r,0)),t.drawArraysInstanced(t.TRIANGLE_STRIP,0,4,R);for(let e of Object.values(a))t.vertexAttribDivisor(e,0)}t.bindVertexArray(null)},dispose(){for(let e of[j,M,N,P,F,I,O,k])t.deleteBuffer(e);t.deleteTransformFeedback(E),t.deleteVertexArray(D),t.deleteTexture(L),t.deleteVertexArray(u)}}}var QW={top:3,right:3,bottom:3,left:3};function $W(e,t,n){return t<200||n<120?{...QW,tiny:!0}:{...e,tiny:!1}}var eG={top:14,right:24,bottom:40,left:78},tG=70,nG=6,rG=8,iG=1.8;function aG(e,t,n){return Math.min(n,Math.max(t,e))}function oG(e,t){let n=e[t],r=1/0,i=-1/0;for(let t=0;t<e.length;t++){let e=n[t];e<r&&(r=e),e>i&&(i=e)}(!Number.isFinite(r)||r===i)&&(--r,i+=1);let a=(i-r)*.04;return{min:r-a,max:i+a}}function sG(e){return e===`dashed`?[5,4]:e===`dotted`?[1,4]:[]}function cG({points:e,xLabel:t,yLabel:n,color:r=`#38bdf8`,datasetColors:i,colorLabel:a,colorRange:o,height:s=400,pointRadius:c=iG,drawMode:l=`points`,lineWidth:u=1,backgroundToken:d=``,onPlotContextMenu:f,xAxisLine:p,yAxisLine:m,gridLine:h,fitSettings:g,xScale:_,yScale:v}){let y=oU(),b=K(null),x=K(null),S=K(null),C=K(f);G(()=>{C.current=f},[f]);let w=K(null),T=K(null),E=K(null),D=K(null),O=K(null),k=K(0),A=K(null),j=ft(()=>yW(e)?e:bW(e),[e]),M=K({cols:j,xLabel:t,yLabel:n,color:r,datasetColors:i,colorLabel:a,colorRange:o,height:s,pointRadius:c,drawMode:l,lineWidth:u,xAxisLine:p,yAxisLine:m,gridLine:h,fitSettings:g,xScale:_,yScale:v});G(()=>{M.current={cols:j,xLabel:t,yLabel:n,color:r,datasetColors:i,colorLabel:a,colorRange:o,height:s,pointRadius:c,drawMode:l,lineWidth:u,xAxisLine:p,yAxisLine:m,gridLine:h,fitSettings:g,xScale:_,yScale:v}},[j,t,n,r,i,a,o,s,c,l,u,p,m,h,g,_,v]);let N=K({cols:null,value:{x:{min:0,max:1},y:{min:0,max:1}}});function P(){let e=M.current.cols,t=N.current;return t.cols!==e&&(t.value={x:oG(e,`x`),y:oG(e,`y`)},t.cols=e),t.value}W(()=>{T.current=null,E.current=null,D.current=null,O.current=null},[t,n]);function F(){let e=P(),t=T.current,n=E.current,r=D.current,i=O.current;return{xmin:t!==null&&n!==null&&n>t?t:e.x.min,xmax:t!==null&&n!==null&&n>t?n:e.x.max,ymin:r!==null&&i!==null&&i>r?r:e.y.min,ymax:r!==null&&i!==null&&i>r?i:e.y.max}}function I(){if(T.current!==null||D.current!==null)return F();let{xScale:e,yScale:t}=M.current,n=e=>{if(!e)return null;let t=parseFloat(e.scaleMin),n=parseFloat(e.scaleMax);return Number.isFinite(t)&&Number.isFinite(n)&&t<n?{min:t,max:n}:null},r=n(e)??P().x,i=n(t)??P().y;return{xmin:r.min,xmax:r.max,ymin:i.min,ymax:i.max}}function L(){if(A.current)return A.current;let e=S.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`,accent:`#f97316`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`,accent:t.getPropertyValue(`--accent`).trim()||`#f97316`};return A.current=n,n}function R(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function z(){let e=S.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||M.current.height)}}let B=K(null),V=K(null),ee=K({r:null,failed:!1,data:null,mode:``,style:``,size:``});function te(e,t){let n=ee.current;!n.r&&!n.failed&&V.current&&(n.r=mH(V.current,ZW),n.failed=!n.r);let r=n.r;if(!r||!V.current)return null;let{cols:i,color:a,datasetColors:o,pointRadius:s,drawMode:c,lineWidth:l}=M.current,u=Math.min(2,window.devicePixelRatio||1),d=`${e}x${t}@${u}`;n.size!==d&&(r.resize(e,t,u),V.current.style.width=`${e}px`,V.current.style.height=`${t}px`,n.size=d);let f=o&&o.length>0&&i.d?`dataset`:i.c?`colormap`:`single`,p=c!==`points`;r.setDraw(c!==`lines`,p,l),(n.data!==i||n.mode!==`${f}|${p}`)&&(r.setData(i.x,i.y,f===`dataset`?i.d:f===`colormap`?i.c:void 0,f===`dataset`),n.data=i,n.mode=`${f}|${p}`);let m=`${f}|${a}|${f===`dataset`?o.join(`,`):``}|${s}`;return n.style!==m&&(r.setStyle(uG(f,a,o),Math.max(.25,s),.8),n.style=m),r}W(()=>()=>{ee.current.r?.dispose(),ee.current.r=null},[]);let H=K({cols:null,key:``,coeffs:null});function ne(e,t,n){let r=`${t}|${n.xmin}|${n.xmax}|${n.ymin}|${n.ymax}`,i=H.current;return(i.cols!==e||i.key!==r)&&(H.current={cols:e,key:r,coeffs:MW(e,t,n)}),H.current.coeffs}let re=K({pts:null,view:``}),ie=K(``);function U(){let e=b.current;if(!e)return;let{w:t,h:n}=z(),r=R(e,t,n);if(!r)return;let{cols:i,xLabel:a,yLabel:o,color:s,datasetColors:c,colorLabel:l,colorRange:u,pointRadius:d,xAxisLine:f,yAxisLine:p,gridLine:m,fitSettings:h,xScale:g,yScale:_}=M.current,v=!!c&&c.length>0&&!!i.d,x=!v&&i.length>0&&!!i.c,C=$W(eG,t,n),w=C.tiny?C.right:x?tG:C.right,{top:T,bottom:E,left:D}=C,O=t-D-w,k=n-T-E,{bg:A,muted:j,grid:N,accent:P}=L(),F=Math.max(.25,d),V=te(t,n),ee=i.length>=1&&O>0&&k>0?I():null,H=[t,n,e.width,ee&&`${ee.xmin}|${ee.xmax}|${ee.ymin}|${ee.ymax}`,a,o,x,v,l,u?.join(),JSON.stringify([f,p,m,g,_]),A,j,N,P].join(`§`);if(V&&ee&&!h&&ie.current===H){let e=re.current;e.pts!==i&&(re.current={pts:i,view:e.view},DH(S.current)),V.setView(ee.xmin,ee.xmax,ee.ymin,ee.ymax,{left:D,top:T,width:O,height:k}),V.render();return}ie.current=H,r.fillStyle=A,r.fillRect(0,0,t,n);let U=B.current?R(B.current,t,n):null;U?.clearRect(0,0,t,n);let ae=V;if(i.length<1||O<=0||k<=0){ae?.render(),r.fillStyle=j,r.font=`13px ${Q.sans}`,zV(r);return}let{xmin:oe,xmax:se,ymin:ce,ymax:le}=I(),ue=se-oe,de=le-ce,fe=e=>D+(e-oe)/ue*O;y({left:D,top:T,width:O,height:k,x:{v0:oe,v1:se}});let pe=e=>T+(le-e)/de*k,me=(()=>{if(_?.majorStep){let e=parseFloat(_.majorStep);if(Number.isFinite(e)&&e>0)return e}return Dz(de,6)})(),he=Az(ce,le,me);if((p?.style??`dashed`)!==`none`){r.strokeStyle=p?.color??N,r.lineWidth=p?.width??1,r.setLineDash(sG(p?.style??`dashed`));for(let e of he){let t=pe(e);r.beginPath(),r.moveTo(D,t),r.lineTo(D+O,t),r.stroke()}r.setLineDash([])}r.strokeStyle=j,r.lineWidth=1,r.fillStyle=j,r.font=`11px ${Q.mono}`,r.textAlign=`right`,r.textBaseline=`middle`;for(let e of C.tiny?[]:he){let t=pe(e);r.beginPath(),r.moveTo(D-nG,t),r.lineTo(D,t),r.stroke(),r.fillText(Pz(e,me),D-rG,t)}let ge=(()=>{if(g?.majorStep){let e=parseFloat(g.majorStep);if(Number.isFinite(e)&&e>0)return e}return Dz(ue,Oz(O))})(),_e=Az(oe,se,ge);if((f?.style??`dashed`)!==`none`){r.strokeStyle=f?.color??N,r.lineWidth=f?.width??1,r.setLineDash(sG(f?.style??`dashed`));for(let e of _e){let t=fe(e);r.beginPath(),r.moveTo(t,T),r.lineTo(t,T+k),r.stroke()}r.setLineDash([])}r.strokeStyle=j,r.lineWidth=1,r.fillStyle=j,r.textAlign=`center`,r.textBaseline=`top`;for(let e of C.tiny?[]:_e){let t=fe(e);r.beginPath(),r.moveTo(t,T+k),r.lineTo(t,T+k+nG),r.stroke(),r.fillText(Pz(e,ge),t,T+k+nG+2)}(m?.style??`solid`)!==`none`&&(r.strokeStyle=m?.color??N,r.lineWidth=m?.width??1,r.setLineDash(sG(m?.style??`solid`)),r.strokeRect(D,T,O,k),r.setLineDash([])),r.fillStyle=j,r.font=`11px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`bottom`,C.tiny||(r.fillText(a,D+O/2,n-4),r.save(),r.translate(14,T+k/2),r.rotate(-Math.PI/2),r.fillText(o,0,0),r.restore());let ve=re.current;if((ve.pts!==i||ve.view!==`${oe}|${se}|${ce}|${le}`)&&(re.current={pts:i,view:`${oe}|${se}|${ce}|${le}`},DH(S.current)),ae)ae.setView(oe,se,ce,le,{left:D,top:T,width:O,height:k}),ae.render();else{let e={xToPx:fe,yToPx:pe,left:D,top:T,plotW:O,plotH:k,dotR:F,col:s,dsColors:v?c:null,hasColormap:x};M.current.drawMode!==`points`&&fG(r,i,e,M.current.lineWidth),M.current.drawMode!==`lines`&&dG(r,i,e)}if(x&&!C.tiny){let e=D+O+10,n=k;for(let t=0;t<64;t++)r.fillStyle=RW(1-t/64),r.fillRect(e,T+t/64*n,10,n/64+1);r.strokeStyle=j,r.lineWidth=.5,r.strokeRect(e,T,10,n),r.fillStyle=j,r.font=`10px ${Q.mono}`,r.textAlign=`left`,r.textBaseline=`top`;let i=u?String(u[1].toPrecision(3)):`1`,a=u?String(u[0].toPrecision(3)):`0`;r.fillText(i,e+10+3,T),r.textBaseline=`bottom`,r.fillText(a,e+10+3,T+n),l&&(r.save(),r.textBaseline=`middle`,r.translate(t-6,T+n/2),r.rotate(Math.PI/2),r.fillText(l,0,0),r.restore())}if(h&&U){let e=ne(i,h.degree,{xmin:oe,xmax:se,ymin:ce,ymax:le});if(e){U.save(),U.beginPath(),U.rect(D,T,O,k),U.clip(),U.strokeStyle=h.color,U.lineWidth=h.width,U.setLineDash(sG(h.lineStyle)),U.beginPath();for(let t=0;t<=300;t++){let n=oe+t/300*ue,r=e.reduce((e,t,r)=>e+t*n**+r,0),i=fe(n),a=pe(r);t===0?U.moveTo(i,a):U.lineTo(i,a)}U.stroke(),U.setLineDash([]);let t=FW(e,`x`,`y`);U.fillStyle=P,U.font=`10px ${Q.mono}`,U.textAlign=`right`,U.textBaseline=`top`,U.fillText(t,D+O-8,T+8),U.restore()}}if((g?.alarm||_?.alarm)&&U){if(U.save(),U.beginPath(),U.rect(D,T,O,k),U.clip(),g?.alarm){let e=g.alarm;U.strokeStyle=e.color,U.lineWidth=e.width,U.setLineDash(e.linked===`active`?cU:sG(e.style));let t=fe(e.value);U.beginPath(),U.moveTo(t,T),U.lineTo(t,T+k),U.stroke(),U.setLineDash([]),e.linked&&uU(U,t+3,T+2,e.color)}if(_?.alarm){let e=_.alarm;U.strokeStyle=e.color,U.lineWidth=e.width,U.setLineDash(e.linked===`active`?cU:sG(e.style));let t=pe(e.value);U.beginPath(),U.moveTo(D,t),U.lineTo(D+O,t),U.stroke(),U.setLineDash([]),e.linked&&uU(U,D+O-10-3,t-10-2,e.color)}U.restore()}}let ae=K(``);function oe(){let e=x.current;if(!e)return;let{w:t,h:n}=z(),r=`${t}x${n}`;if(w.current===null&&ae.current===r)return;let i=R(e,t,n);if(!i)return;i.clearRect(0,0,t,n),ae.current=w.current===null?r:``;let a=w.current,{cols:o,color:s,datasetColors:c,pointRadius:l}=M.current;if(a===null||a>=o.length||o.length<1)return;let u=Math.max(4,l*2),d=o.d?.[a],f=c&&c.length>0&&d!==void 0?c[d]??s:s,{top:p,right:m,bottom:h,left:g}=$W(eG,t,n),_=t-g-m,v=n-p-h;if(_<=0||v<=0)return;let{xmin:y,xmax:b,ymin:S,ymax:C}=I(),T=b-y,E=C-S,D={x:o.x[a],y:o.y[a]},O=g+(D.x-y)/T*_,k=p+(C-D.y)/E*v,{bg:A,muted:j}=L();i.strokeStyle=j,i.globalAlpha=.4,i.lineWidth=1,i.setLineDash([3,3]),i.beginPath(),i.moveTo(O,p),i.lineTo(O,p+v),i.stroke(),i.beginPath(),i.moveTo(g,k),i.lineTo(g+_,k),i.stroke(),i.setLineDash([]),i.globalAlpha=1,i.fillStyle=f,i.beginPath(),i.arc(O,k,u,0,Math.PI*2),i.fill(),i.strokeStyle=A,i.lineWidth=1.5,i.beginPath(),i.arc(O,k,u,0,Math.PI*2),i.stroke();let N=`(${Fz(D.x)}, ${Fz(D.y)})`;i.font=`11px ${Q.mono}`;let P=i.measureText(N).width+12,F=O+10,B=k-24;F+P>g+_&&(F=O-P-10),B<p&&(B=k+10),i.fillStyle=A,i.globalAlpha=.85,i.beginPath(),lG(i,F,B,P,20,4),i.fill(),i.globalAlpha=1,i.strokeStyle=j,i.lineWidth=.5,i.beginPath(),lG(i,F,B,P,20,4),i.stroke(),i.fillStyle=j,i.textAlign=`left`,i.textBaseline=`middle`,i.fillText(N,F+6,B+20/2)}let se=K(U),ce=K(oe);G(()=>{se.current=U,ce.current=oe});let le=K(null);le.current??=jH(()=>{se.current(),ce.current()},()=>S.current);function ue(){le.current.schedule()}function de(){k.current||=wH(()=>{k.current=0,ce.current()})}W(()=>()=>{le.current?.cancel(),TH(k.current),k.current=0},[]);let fe=K(ue),pe=K(de);return G(()=>{fe.current=ue,pe.current=de}),W(()=>rB(S.current,()=>{A.current=null,fe.current()}),[]),W(()=>{A.current=null,fe.current()},[d]),W(()=>{le.current.now()},[e,t,n,r,i,s,c,l,u,p,m,h,g,_,v]),W(()=>{let e=x.current,t=S.current;if(!e||!t)return;let n=new AH(()=>{A.current=null,fe.current()});n.observe(t);let r=null;function i(e,t){let n=M.current.cols;if(n.length===0)return null;let{w:i,h:a}=z(),{top:o,right:s,bottom:c,left:l}=$W(eG,i,a),u=i-l-s,d=a-o-c,{xmin:f,xmax:p,ymin:m,ymax:h}=I(),g=p-f,_=h-m,v=Math.max(12,M.current.pointRadius*10),y=`${i}|${a}|${f}|${p}|${m}|${h}|${v}`;if(!r||r.cols!==n||r.key!==y){let e=Math.max(1,Math.ceil(u/v)),t=Math.max(1,Math.ceil(d/v)),i=t=>{let r=(n.x[t]-f)/g*u,i=(h-n.y[t])/_*d;return r>=0&&r<u&&i>=0&&i<d?Math.floor(i/v)*e+Math.floor(r/v):-1},a=new Uint32Array(e*t+1);for(let e=0;e<n.length;e++){let t=i(e);t>=0&&a[t+1]++}for(let n=0;n<e*t;n++)a[n+1]+=a[n];let o=a.slice(0,e*t),s=new Uint32Array(a[e*t]);for(let e=0;e<n.length;e++){let t=i(e);t>=0&&(s[o[t]++]=e)}r={cols:n,key:y,cell:v,nx:e,start:a,ix:s}}let b=r,x=Math.floor((e-l)/b.cell),S=Math.floor((t-o)/b.cell),C=(b.start.length-1)/b.nx,w=-1,T=v*v;for(let r=S-1;r<=S+1;r++)if(!(r<0||r>=C))for(let i=x-1;i<=x+1;i++){if(i<0||i>=b.nx)continue;let a=r*b.nx+i;for(let r=b.start[a];r<b.start[a+1];r++){let i=b.ix[r],a=l+(n.x[i]-f)/g*u,s=o+(h-n.y[i])/_*d,c=(a-e)**2+(s-t)**2;c<T&&(T=c,w=i)}}return w<0?null:w}let a=t=>{if(M.current.cols.length<1){w.current!==null&&(w.current=null,pe.current());return}let n=e.getBoundingClientRect(),r=t.clientX-n.left,a=t.clientY-n.top,{left:o,top:s,right:c,bottom:l}=$W(eG,n.width,n.height),u=Math.max(1,n.width-o-c),d=n.height-s-l;if(r<o||r>o+u||a<s||a>s+d){w.current!==null&&(w.current=null,pe.current());return}let f=i(r,a);w.current!==f&&(w.current=f,pe.current())},o=()=>{w.current!==null&&(w.current=null,pe.current())},s=t=>{if(M.current.cols.length<1)return;let n=e.getBoundingClientRect(),r=t.clientX-n.left,i=t.clientY-n.top,{top:a,left:o,right:s,bottom:c}=$W(eG,n.width,n.height),l=Math.max(1,n.width-o-s),u=Math.max(1,n.height-a-c);if(r<o||r>o+l||i<a||i>a+u)return;t.preventDefault();let d=P(),f=d.x.max-d.x.min,p=d.y.max-d.y.min,m=I(),h=m.xmin,g=m.xmax,_=m.ymin,v=m.ymax,y=g-h,b=v-_,x=(r-o)/l,S=(i-a)/u,C=h+x*y,w=v-S*b,k=t.deltaY<0,A=.88,j=k?A:1/A,N=y*j,F=b*j;if(!k&&N>=f*.999&&F>=p*.999){T.current=null,E.current=null,D.current=null,O.current=null,fe.current();return}N=aG(N,Math.max(f*1e-7,1e-12),f),F=aG(F,Math.max(p*1e-7,1e-12),p);let L=C-x*N,R=C+(1-x)*N;L<d.x.min&&(R+=d.x.min-L,L=d.x.min),R>d.x.max&&(L-=R-d.x.max,R=d.x.max);let z=w-(1-S)*F,B=w+S*F;z<d.y.min&&(B+=d.y.min-z,z=d.y.min),B>d.y.max&&(z-=B-d.y.max,B=d.y.max),T.current=L,E.current=R,D.current=z,O.current=B,fe.current()},c=e=>{e.button===0&&(T.current===null&&D.current===null||(T.current=null,E.current=null,D.current=null,O.current=null,fe.current(),pe.current()))},l=e=>{e.preventDefault(),C.current?.({clientX:e.clientX,clientY:e.clientY})};return e.addEventListener(`mousemove`,a),e.addEventListener(`mouseleave`,o),e.addEventListener(`wheel`,s,{passive:!1}),e.addEventListener(`contextmenu`,l),e.addEventListener(`dblclick`,c),()=>{n.disconnect(),e.removeEventListener(`mousemove`,a),e.removeEventListener(`mouseleave`,o),e.removeEventListener(`wheel`,s),e.removeEventListener(`contextmenu`,l),e.removeEventListener(`dblclick`,c)}},[]),vt(`div`,{ref:S,className:`chart-canvas-wrap`,children:[q(`canvas`,{ref:b,className:`chart-canvas`,role:`img`,"aria-label":`Scatter ${t} vs ${n}`}),q(`canvas`,{ref:V,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),q(`canvas`,{ref:B,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),q(`canvas`,{ref:x,className:`chart-canvas chart-overlay`})]})}function lG(e,t,n,r,i,a){e.moveTo(t+a,n),e.lineTo(t+r-a,n),e.arcTo(t+r,n,t+r,n+a,a),e.lineTo(t+r,n+i-a),e.arcTo(t+r,n+i,t+r-a,n+i,a),e.lineTo(t+a,n+i),e.arcTo(t,n+i,t,n+i-a,a),e.lineTo(t,n+a),e.arcTo(t,n,t+a,n,a)}function uG(e,t,n){if(e===`single`)return{kind:`single`,rgba:UV(t)};let r=new Uint8Array(256*4);for(let t=0;t<256;t++)if(e===`colormap`){let{r:e,g:n,b:i}=LW(t/255);r.set([e,n,i,255],t*4)}else{let e=UV(n[Math.min(t,n.length-1)]);r.set([e[0]*255,e[1]*255,e[2]*255,e[3]*255],t*4)}return{kind:e===`colormap`?`colormap`:`dataset`,palette:r}}function dG(e,t,n){let r=Math.PI*2,i=n.dsColors?n.dsColors.length:n.hasColormap?24:1,a=Array.from({length:i},()=>new Path2D);for(let e=0;e<t.length;e++){let o=n.xToPx(t.x[e]),s=n.yToPx(t.y[e]);if(!(o>=n.left&&o<=n.left+n.plotW&&s>=n.top&&s<=n.top+n.plotH))continue;let c=n.dsColors?Math.min(t.d?.[e]??0,i-1):n.hasColormap?zW(t.c?.[e]??0,24):0;a[c].moveTo(o+n.dotR,s),a[c].arc(o,s,n.dotR,0,r)}e.globalAlpha=.8;for(let t=0;t<i;t++)e.fillStyle=n.dsColors?n.dsColors[t]:n.hasColormap?RW((t+.5)/24):n.col,e.fill(a[t]);e.globalAlpha=1}function fG(e,t,n,r){e.save(),e.beginPath(),e.rect(n.left,n.top,n.plotW,n.plotH),e.clip(),e.lineWidth=r;let i=n.dsColors?n.dsColors.length:1;for(let r=0;r<i;r++){e.beginPath();let i=!1;for(let a=0;a<t.length;a++){if(n.dsColors&&(t.d?.[a]??0)!==r){i=!1;continue}let o=t.x[a],s=t.y[a];if(o-o!==0||s-s!==0){i=!1;continue}i?e.lineTo(n.xToPx(o),n.yToPx(s)):(e.moveTo(n.xToPx(o),n.yToPx(s)),i=!0)}e.strokeStyle=n.dsColors?n.dsColors[r]:n.col,e.stroke()}e.restore()}var pG=11102230246251565e-32,mG=134217729,hG=(3+8*pG)*pG;function gG(e,t,n,r,i){let a,o,s,c,l=t[0],u=r[0],d=0,f=0;u>l==u>-l?(a=l,l=t[++d]):(a=u,u=r[++f]);let p=0;if(d<e&&f<n)for(u>l==u>-l?(o=l+a,s=a-(o-l),l=t[++d]):(o=u+a,s=a-(o-u),u=r[++f]),a=o,s!==0&&(i[p++]=s);d<e&&f<n;)u>l==u>-l?(o=a+l,c=o-a,s=a-(o-c)+(l-c),l=t[++d]):(o=a+u,c=o-a,s=a-(o-c)+(u-c),u=r[++f]),a=o,s!==0&&(i[p++]=s);for(;d<e;)o=a+l,c=o-a,s=a-(o-c)+(l-c),l=t[++d],a=o,s!==0&&(i[p++]=s);for(;f<n;)o=a+u,c=o-a,s=a-(o-c)+(u-c),u=r[++f],a=o,s!==0&&(i[p++]=s);return(a!==0||p===0)&&(i[p++]=a),p}function _G(e,t){let n=t[0];for(let r=1;r<e;r++)n+=t[r];return n}function $(e){return new Float64Array(e)}var vG=(3+16*pG)*pG,yG=(2+12*pG)*pG,bG=(9+64*pG)*pG*pG,xG=$(4),SG=$(8),CG=$(12),wG=$(16),TG=$(4);function EG(e,t,n,r,i,a,o){let s,c,l,u,d,f,p,m,h,g,_,v,y,b,x,S,C,w,T=e-i,E=n-i,D=t-a,O=r-a;b=T*O,f=mG*T,p=f-(f-T),m=T-p,f=mG*O,h=f-(f-O),g=O-h,x=m*g-(b-p*h-m*h-p*g),S=D*E,f=mG*D,p=f-(f-D),m=D-p,f=mG*E,h=f-(f-E),g=E-h,C=m*g-(S-p*h-m*h-p*g),_=x-C,d=x-_,xG[0]=x-(_+d)+(d-C),v=b+_,d=v-b,y=b-(v-d)+(_-d),_=y-S,d=y-_,xG[1]=y-(_+d)+(d-S),w=v+_,d=w-v,xG[2]=v-(w-d)+(_-d),xG[3]=w;let k=_G(4,xG),A=yG*o;if(k>=A||-k>=A||(d=e-T,s=e-(T+d)+(d-i),d=n-E,l=n-(E+d)+(d-i),d=t-D,c=t-(D+d)+(d-a),d=r-O,u=r-(O+d)+(d-a),s===0&&c===0&&l===0&&u===0)||(A=bG*o+hG*Math.abs(k),k+=T*u+O*s-(D*l+E*c),k>=A||-k>=A))return k;b=s*O,f=mG*s,p=f-(f-s),m=s-p,f=mG*O,h=f-(f-O),g=O-h,x=m*g-(b-p*h-m*h-p*g),S=c*E,f=mG*c,p=f-(f-c),m=c-p,f=mG*E,h=f-(f-E),g=E-h,C=m*g-(S-p*h-m*h-p*g),_=x-C,d=x-_,TG[0]=x-(_+d)+(d-C),v=b+_,d=v-b,y=b-(v-d)+(_-d),_=y-S,d=y-_,TG[1]=y-(_+d)+(d-S),w=v+_,d=w-v,TG[2]=v-(w-d)+(_-d),TG[3]=w;let j=gG(4,xG,4,TG,SG);b=T*u,f=mG*T,p=f-(f-T),m=T-p,f=mG*u,h=f-(f-u),g=u-h,x=m*g-(b-p*h-m*h-p*g),S=D*l,f=mG*D,p=f-(f-D),m=D-p,f=mG*l,h=f-(f-l),g=l-h,C=m*g-(S-p*h-m*h-p*g),_=x-C,d=x-_,TG[0]=x-(_+d)+(d-C),v=b+_,d=v-b,y=b-(v-d)+(_-d),_=y-S,d=y-_,TG[1]=y-(_+d)+(d-S),w=v+_,d=w-v,TG[2]=v-(w-d)+(_-d),TG[3]=w;let M=gG(j,SG,4,TG,CG);return b=s*u,f=mG*s,p=f-(f-s),m=s-p,f=mG*u,h=f-(f-u),g=u-h,x=m*g-(b-p*h-m*h-p*g),S=c*l,f=mG*c,p=f-(f-c),m=c-p,f=mG*l,h=f-(f-l),g=l-h,C=m*g-(S-p*h-m*h-p*g),_=x-C,d=x-_,TG[0]=x-(_+d)+(d-C),v=b+_,d=v-b,y=b-(v-d)+(_-d),_=y-S,d=y-_,TG[1]=y-(_+d)+(d-S),w=v+_,d=w-v,TG[2]=v-(w-d)+(_-d),TG[3]=w,wG[gG(M,CG,4,TG,wG)-1]}function DG(e,t,n,r,i,a){let o=(t-a)*(n-i),s=(e-i)*(r-a),c=o-s,l=Math.abs(o+s);return Math.abs(c)>=vG*l?c:-EG(e,t,n,r,i,a,l)}(7+56*pG)*pG,(3+28*pG)*pG,(26+288*pG)*pG*pG,$(4),$(4),$(4),$(4),$(4),$(4),$(4),$(4),$(4),$(8),$(8),$(8),$(4),$(8),$(8),$(16),$(12),$(192),$(192),(10+96*pG)*pG,(4+48*pG)*pG,(44+576*pG)*pG*pG,$(4),$(4),$(4),$(4),$(4),$(4),$(4),$(4),$(8),$(8),$(8),$(8),$(8),$(8),$(8),$(8),$(8),$(4),$(4),$(4),$(8),$(16),$(16),$(16),$(32),$(32),$(48),$(64),$(1152),$(1152),(16+224*pG)*pG,(5+72*pG)*pG,(71+1408*pG)*pG*pG,$(4),$(4),$(4),$(4),$(4),$(4),$(4),$(4),$(4),$(4),$(24),$(24),$(24),$(24),$(24),$(24),$(24),$(24),$(24),$(24),$(1152),$(1152),$(1152),$(1152),$(1152),$(2304),$(2304),$(3456),$(5760),$(8),$(8),$(8),$(16),$(24),$(48),$(48),$(96),$(192),$(384),$(384),$(384),$(768),$(96),$(96),$(96),$(1152);var OG=2**-52,kG=new Uint32Array(512),AG=class e{static from(t,n=RG,r=zG){let i=t.length,a=new Float64Array(i*2);for(let e=0;e<i;e++){let i=t[e];a[2*e]=n(i),a[2*e+1]=r(i)}return new e(a)}constructor(e){let t=e.length>>1;if(t>0&&typeof e[0]!=`number`)throw Error(`Expected coords to contain numbers.`);this.coords=e;let n=Math.max(2*t-5,0);this._triangles=new Uint32Array(n*3),this._halfedges=new Int32Array(n*3),this._hashSize=Math.ceil(Math.sqrt(t)),this._hullPrev=new Uint32Array(t),this._hullNext=new Uint32Array(t),this._hullTri=new Uint32Array(t),this._hullHash=new Int32Array(this._hashSize),this._ids=new Uint32Array(t),this._dists=new Float64Array(t),this.trianglesLen=0,this._cx=0,this._cy=0,this._hullStart=0,this.hull=this._triangles,this.triangles=this._triangles,this.halfedges=this._halfedges,this.update()}update(){let{coords:e,_hullPrev:t,_hullNext:n,_hullTri:r,_hullHash:i}=this,a=e.length>>1,o=1/0,s=1/0,c=-1/0,l=-1/0;for(let t=0;t<a;t++){let n=e[2*t],r=e[2*t+1];n<o&&(o=n),r<s&&(s=r),n>c&&(c=n),r>l&&(l=r),this._ids[t]=t}let u=(o+c)/2,d=(s+l)/2,f=0,p=0,m=0;for(let t=0,n=1/0;t<a;t++){let r=MG(u,d,e[2*t],e[2*t+1]);r<n&&(f=t,n=r)}let h=e[2*f],g=e[2*f+1];for(let t=0,n=1/0;t<a;t++){if(t===f)continue;let r=MG(h,g,e[2*t],e[2*t+1]);r<n&&r>0&&(p=t,n=r)}let _=e[2*p],v=e[2*p+1],y=1/0;for(let t=0;t<a;t++){if(t===f||t===p)continue;let n=PG(h,g,_,v,e[2*t],e[2*t+1]);n<y&&(m=t,y=n)}let b=e[2*m],x=e[2*m+1];if(y===1/0){for(let t=0;t<a;t++)this._dists[t]=e[2*t]-e[0]||e[2*t+1]-e[1];IG(this._ids,this._dists,0,a-1);let t=new Uint32Array(a),n=0;for(let e=0,r=-1/0;e<a;e++){let i=this._ids[e],a=this._dists[i];a>r&&(t[n++]=i,r=a)}this.hull=t.subarray(0,n),this.triangles=new Uint32Array,this.halfedges=new Int32Array;return}if(DG(h,g,_,v,b,x)<0){let e=p,t=_,n=v;p=m,_=b,v=x,m=e,b=t,x=n}let S=FG(h,g,_,v,b,x);this._cx=S.x,this._cy=S.y;for(let t=0;t<a;t++)this._dists[t]=MG(e[2*t],e[2*t+1],S.x,S.y);IG(this._ids,this._dists,0,a-1),this._hullStart=f;let C=3;n[f]=t[m]=p,n[p]=t[f]=m,n[m]=t[p]=f,r[f]=0,r[p]=1,r[m]=2,i.fill(-1),i[this._hashKey(h,g)]=f,i[this._hashKey(_,v)]=p,i[this._hashKey(b,x)]=m,this.trianglesLen=0,this._addTriangle(f,p,m,-1,-1,-1);for(let a=0,o=0,s=0;a<this._ids.length;a++){let c=this._ids[a],l=e[2*c],u=e[2*c+1];if(a>0&&Math.abs(l-o)<=OG&&Math.abs(u-s)<=OG||(o=l,s=u,c===f||c===p||c===m))continue;let d=0;for(let e=0,t=this._hashKey(l,u);e<this._hashSize&&(d=i[(t+e)%this._hashSize],!(d!==-1&&d!==n[d]));e++);d=t[d];let h=d,g;for(;g=n[h],DG(l,u,e[2*h],e[2*h+1],e[2*g],e[2*g+1])>=0;)if(h=g,h===d){h=-1;break}if(h===-1)continue;let _=this._addTriangle(h,c,n[h],-1,-1,r[h]);r[c]=this._legalize(_+2),r[h]=_,C++;let v=n[h];for(;g=n[v],DG(l,u,e[2*v],e[2*v+1],e[2*g],e[2*g+1])<0;)_=this._addTriangle(v,c,g,r[c],-1,r[v]),r[c]=this._legalize(_+2),n[v]=v,C--,v=g;if(h===d)for(;g=t[h],DG(l,u,e[2*g],e[2*g+1],e[2*h],e[2*h+1])<0;)_=this._addTriangle(g,c,h,-1,r[h],r[g]),this._legalize(_+2),r[g]=_,n[h]=h,C--,h=g;this._hullStart=t[c]=h,n[h]=t[v]=c,n[c]=v,i[this._hashKey(l,u)]=c,i[this._hashKey(e[2*h],e[2*h+1])]=h}this.hull=new Uint32Array(C);for(let e=0,t=this._hullStart;e<C;e++)this.hull[e]=t,t=n[t];this.triangles=this._triangles.subarray(0,this.trianglesLen),this.halfedges=this._halfedges.subarray(0,this.trianglesLen)}_hashKey(e,t){return Math.floor(jG(e-this._cx,t-this._cy)*this._hashSize)%this._hashSize}_legalize(e){let{_triangles:t,_halfedges:n,coords:r}=this,i=0,a=0;for(;;){let o=n[e],s=e-e%3;if(a=s+(e+2)%3,o===-1){if(i===0)break;e=kG[--i];continue}let c=o-o%3,l=s+(e+1)%3,u=c+(o+2)%3,d=t[a],f=t[e],p=t[l],m=t[u];if(NG(r[2*d],r[2*d+1],r[2*f],r[2*f+1],r[2*p],r[2*p+1],r[2*m],r[2*m+1])){t[e]=m,t[o]=d;let r=n[u];if(r===-1){let t=this._hullStart;do{if(this._hullTri[t]===u){this._hullTri[t]=e;break}t=this._hullPrev[t]}while(t!==this._hullStart)}this._link(e,r),this._link(o,n[a]),this._link(a,u);let s=c+(o+1)%3;i<kG.length&&(kG[i++]=s)}else{if(i===0)break;e=kG[--i]}}return a}_link(e,t){this._halfedges[e]=t,t!==-1&&(this._halfedges[t]=e)}_addTriangle(e,t,n,r,i,a){let o=this.trianglesLen;return this._triangles[o]=e,this._triangles[o+1]=t,this._triangles[o+2]=n,this._link(o,r),this._link(o+1,i),this._link(o+2,a),this.trianglesLen+=3,o}};function jG(e,t){let n=e/(Math.abs(e)+Math.abs(t));return(t>0?3-n:1+n)/4}function MG(e,t,n,r){let i=e-n,a=t-r;return i*i+a*a}function NG(e,t,n,r,i,a,o,s){let c=e-o,l=t-s,u=n-o,d=r-s,f=i-o,p=a-s,m=c*c+l*l,h=u*u+d*d,g=f*f+p*p;return c*(d*g-h*p)-l*(u*g-h*f)+m*(u*p-d*f)<0}function PG(e,t,n,r,i,a){let o=n-e,s=r-t,c=i-e,l=a-t,u=o*o+s*s,d=c*c+l*l,f=.5/(o*l-s*c),p=(l*u-s*d)*f,m=(o*d-c*u)*f;return p*p+m*m}function FG(e,t,n,r,i,a){let o=n-e,s=r-t,c=i-e,l=a-t,u=o*o+s*s,d=c*c+l*l,f=.5/(o*l-s*c);return{x:e+(l*u-s*d)*f,y:t+(o*d-c*u)*f}}function IG(e,t,n,r){if(r-n<=20)for(let i=n+1;i<=r;i++){let r=e[i],a=t[r],o=i-1;for(;o>=n&&t[e[o]]>a;)e[o+1]=e[o--];e[o+1]=r}else{let i=n+r>>1,a=n+1,o=r;LG(e,i,a),t[e[n]]>t[e[r]]&&LG(e,n,r),t[e[a]]>t[e[r]]&&LG(e,a,r),t[e[n]]>t[e[a]]&&LG(e,n,a);let s=e[a],c=t[s];for(;;){do a++;while(t[e[a]]<c);do o--;while(t[e[o]]>c);if(o<a)break;LG(e,a,o)}e[n+1]=e[o],e[o]=s,r-a+1>=o-n?(IG(e,t,a,r),IG(e,t,n,o-1)):(IG(e,t,n,o-1),IG(e,t,a,r))}}function LG(e,t,n){let r=e[t];e[t]=e[n],e[n]=r}function RG(e){return e[0]}function zG(e){return e[1]}var BG=`
|
|
374
|
+
void main() { o = vec4(0.0); }`;function fG(e,t,n,r){let i=JV(e,e.VERTEX_SHADER,t),a=JV(e,e.FRAGMENT_SHADER,n);if(!i||!a)return null;let o=e.createProgram();return e.attachShader(o,i),e.attachShader(o,a),r&&e.transformFeedbackVaryings(o,r,e.SEPARATE_ATTRIBS),e.linkProgram(o),e.getProgramParameter(o,e.LINK_STATUS)?{prog:o,shaders:[i,a]}:(console.error(`glPoints program link failed:`,e.getProgramInfoLog(o)),null)}function pG(e,t){if(!e)return[{v:0,a:0,b:t}];let n=[];for(let r=0;r<t;r++)r===0||e[r]!==e[r-1]?n.push({v:e[r],a:r,b:r+1}):n[n.length-1].b=r+1;return n}function mG(e,t,n,r,i,a){let o=[],s=0;for(let c of a){let a=n.filter(e=>e.v===c.v);if(a.length>1)return null;let l=-1;if(a.length===1){for(let n=a[0].a;n<a[0].b;n++)if(e[n]===r[c.a]&&t[n]===i[c.a]){l=n;break}}if(l<0){o.push({src:0,len:0});continue}let u=Math.min(a[0].b-l,c.b-c.a);for(let n=0;n<u;n++)if(e[l+n]!==r[c.a+n]||t[l+n]!==i[c.a+n])return null;o.push({src:l,len:u}),s+=u}return s>0?o:null}function hG(e){let t=e.getContext(`webgl2`,{antialias:!1,alpha:!0,premultipliedAlpha:!0});if(!t)return null;let n=oH(t,`glPoints|points`,()=>fG(t,nG,rG)),r=oH(t,`glPoints|lines`,()=>fG(t,oG,sG)),i=oH(t,`glPoints|points64`,()=>fG(t,lG(nG,[`a_x`],[`a_y`],!0),rG)),a=oH(t,`glPoints|sprites`,()=>fG(t,iG,aG)),o=oH(t,`glPoints|sprites64`,()=>fG(t,lG(iG,[`a_x`],[`a_y`],!0),aG)),s=oH(t,`glPoints|maxSprite`,()=>t.getParameter(t.ALIASED_POINT_SIZE_RANGE)[1]),l=oH(t,`glPoints|decode`,()=>fG(t,uG,dG,[`v_x`,`v_y`])),u=t.createVertexArray();if(!n||!r)return null;let d=(e,n)=>Object.fromEntries(n.map(n=>[n,t.getAttribLocation(e,n)])),f=(e,n)=>Object.fromEntries(n.map(n=>[n,t.getUniformLocation(e,n)])),p=d(n.prog,[`a_corner`,`a_x`,`a_y`,`a_k`,`a_r`]),m=f(n.prog,[`u_resolution`,`u_plot`,`u_view`,`u_radius`,`u_kScale`,`u_palette`,`u_alpha`,`u_clip`,`u_dpr`,`u_height`]),h=d(r.prog,[`a_corner`,`a_ax`,`a_ay`,`a_bx`,`a_by`,`a_bstart`,`a_k`]),g=f(r.prog,[`u_resolution`,`u_plot`,`u_view`,`u_ext`,`u_kScale`,`u_palette`,`u_half`,`u_clip`]),_=i&&d(i.prog,[`a_corner`,`a_x_bits`,`a_y_bits`,`a_k`,`a_r`]),v=i&&f(i.prog,[`u_resolution`,`u_plot`,`u_view`,`u_radius`,`u_kScale`,`u_palette`,`u_alpha`,`u_clip`,`u_dpr`,`u_height`,`u_ox`,`u_oy`]),y=[`u_resolution`,`u_plot`,`u_view`,`u_radius`,`u_kScale`,`u_palette`,`u_alpha`,`u_clip`,`u_dpr`,`u_height`],b=a&&d(a.prog,[`a_x`,`a_y`,`a_k`]),x=a&&f(a.prog,y),S=o&&d(o.prog,[`a_x_bits`,`a_y_bits`,`a_k`]),C=o&&f(o.prog,[...y,`u_ox`,`u_oy`]),w=l&&d(l.prog,[`a_x_bits`,`a_y_bits`]),T=l&&f(l.prog,[`u_ox`,`u_oy`]),E=t.createTransformFeedback(),D=t.createVertexArray(),O=t.createBuffer(),k=t.createBuffer(),A=!1,j=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,j),t.bufferData(t.ARRAY_BUFFER,Float32Array.from([-1,-1,1,-1,-1,1,1,1]),t.STATIC_DRAW);let M=t.createBuffer(),N=t.createBuffer(),P=t.createBuffer(),F=t.createBuffer(),I=t.createBuffer(),L=t.createBuffer(),R=t.createBuffer(),z=t.createBuffer(),B=null,V=t.createTexture(),ee=0,te=!1,H=!1,ne=!1,re=0,ie=0,U=1,ae=1,oe=1,se=1.8,ce=.8,le=255,ue=!0,de=!1,fe=1,pe={xmin:0,xmax:1,ymin:0,ymax:1},me={left:0,top:0,width:1,height:1},he=new Float32Array,ge=new Float32Array,_e=new Float32Array,ve=new Uint8Array,ye=new Float32Array,be=new Map,xe=(e,n,r)=>{t.bindBuffer(t.ARRAY_BUFFER,e);let i=r*n.BYTES_PER_ELEMENT;i<=(be.get(e)??0)?t.bufferSubData(t.ARRAY_BUFFER,0,n,0,r):(t.bufferData(t.ARRAY_BUFFER,n.subarray(0,r),t.DYNAMIC_DRAW),be.set(e,i))},Se=(e,n,r,i,a,o)=>{let s=r.BYTES_PER_ELEMENT;if(t.bindBuffer(t.ARRAY_BUFFER,n),(be.get(n)??0)<o*s){let e=Math.ceil(o*1.25)*s;t.bufferData(t.ARRAY_BUFFER,e,t.DYNAMIC_DRAW),be.set(n,e)}t.bindBuffer(t.COPY_READ_BUFFER,e),t.bindBuffer(t.COPY_WRITE_BUFFER,n),i.forEach((e,n)=>{a[n].len&&t.copyBufferSubData(t.COPY_READ_BUFFER,t.COPY_WRITE_BUFFER,a[n].src*s,e.a*s,a[n].len*s)}),t.bindBuffer(t.COPY_READ_BUFFER,null),t.bindBuffer(t.COPY_WRITE_BUFFER,null),i.forEach((e,n)=>{let i=e.a+a[n].len;e.b>i&&t.bufferSubData(t.ARRAY_BUFFER,i*s,r,i,e.b-i)})},Ce=(e,n,r=0,i=t.FLOAT)=>{t.bindBuffer(t.ARRAY_BUFFER,n),t.enableVertexAttribArray(e);let a=i===t.FLOAT?4:1;t.vertexAttribPointer(e,1,i,i!==t.FLOAT,a,r*a),t.vertexAttribDivisor(e,1)},we=(e,n,r=0)=>{t.bindBuffer(t.ARRAY_BUFFER,n),t.enableVertexAttribArray(e),t.vertexAttribIPointer(e,2,t.UNSIGNED_INT,8,r*8),t.vertexAttribDivisor(e,1)},Te=e=>{t.bindBuffer(t.ARRAY_BUFFER,j),t.enableVertexAttribArray(e),t.vertexAttribPointer(e,2,t.FLOAT,!1,0,0),t.vertexAttribDivisor(e,0)};return{resize(t,n,r){U=Math.max(1,t),ae=Math.max(1,n),oe=r,e.width=Math.round(U*oe),e.height=Math.round(ae*oe)},setData(e,t,n,r=!1,i){let a=Math.min(e.length,t.length);he.length<a&&(he=new Float32Array(a),ge=new Float32Array(a)),te=!!n,H=!!i,n&&_e.length<a&&(_e=new Float32Array(a)),i&&ye.length<a&&(ye=new Float32Array(a)),de&&ve.length<a&&(ve=new Uint8Array(a)),re=0,ie=0;for(let n=0;n<a;n++)if(e[n]-e[n]===0&&t[n]-t[n]===0){re=e[n],ie=t[n];break}let o=c.has(e)&&c.has(t);if(ne=!!_&&!!l&&e instanceof Float64Array&&t instanceof Float64Array&&(o||!de),A=!1,ne){let o=e,s=t;if(n)for(let e=0;e<a;e++)_e[e]=n[e];let c=pG(n&&r?n:void 0,a),l=B&&(!n||r)?mG(B.x,B.y,B.runs,o,s,c):null;if(l?(Se(M,L,o,c,l,a),[M,L]=[L,M],Se(N,R,s,c,l,a),[N,R]=[R,N],n&&(Se(P,z,_e,c,l,a),[P,z]=[z,P])):(xe(M,o,a),xe(N,s,a),n&&xe(P,_e,a)),(!B||B.x.length<a)&&(B={x:new Float64Array(Math.ceil(a*1.25)),y:new Float64Array(Math.ceil(a*1.25)),runs:c,n:a}),B.x.set(o.subarray(0,a)),B.y.set(s.subarray(0,a)),B.runs=c,B.n=a,i){for(let e=0;e<a;e++)ye[e]=i[e];xe(I,ye,a)}if(de){if(ve.fill(0,0,a),a&&(ve[0]=255),n&&r)for(let e=1;e<a;e++)n[e]!==n[e-1]&&(ve[e]=255);xe(F,ve,a)}ee=a;return}B=null;let s=0;if(c.has(e)&&c.has(t)){for(let t=0;t<a;t++)he[t]=e[t]-re;for(let e=0;e<a;e++)ge[e]=t[e]-ie;if(n)for(let e=0;e<a;e++)_e[e]=n[e];if(i)for(let e=0;e<a;e++)ye[e]=i[e];if(de&&(ve.fill(0,0,a),a&&(ve[0]=255),n&&r))for(let e=1;e<a;e++)n[e]!==n[e-1]&&(ve[e]=255);s=a}else{let o=!0;for(let c=0;c<a;c++){let a=e[c],l=t[c];if(a-a!==0||l-l!==0){o=!0;continue}he[s]=a-re,ge[s]=l-ie,n&&(_e[s]=n[c]),i&&(ye[s]=i[c]),de&&(ve[s]=o||r&&n&&s>0&&n[c]!==_e[s-1]?255:0),o=!1,s++}}ee=s,xe(M,he,s),xe(N,ge,s),n&&xe(P,_e,s),i&&xe(I,ye,s),de&&xe(F,ve,s)},setStyle(e,n,r){se=n,ce=r;let i=new Uint8Array(256*4);if(e.kind===`single`){let t=e.rgba.map(e=>Math.round(e*255));for(let e=0;e<256;e++)i.set(t,e*4);le=0}else i.set(e.palette.subarray(0,256*4)),le=e.kind===`colormap`?255:1;t.bindTexture(t.TEXTURE_2D,V),t.texImage2D(t.TEXTURE_2D,0,t.RGBA8,256,1,0,t.RGBA,t.UNSIGNED_BYTE,i),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE)},setDraw(e,t,n){ue=e,de=t,fe=n},setView(e,t,n,r,i){pe={xmin:e,xmax:t,ymin:n,ymax:r},me=i},render(){if(t.bindFramebuffer(t.FRAMEBUFFER,null),t.viewport(0,0,e.width,e.height),t.disable(t.SCISSOR_TEST),t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT),ee===0)return;t.bindVertexArray(u),t.enable(t.BLEND),t.blendFunc(t.ONE,t.ONE_MINUS_SRC_ALPHA),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,V);let c=te?le:0,d=[pe.xmin-re,pe.xmax-re,pe.ymin-ie,pe.ymax-ie],f=[me.left,me.top,me.left+me.width,me.top+me.height],y=e=>{let t=Math.fround(e);return[t,e-t]},j=ne,L=M,R=N;if(ne&&de&&ee>1){if(!A){for(let e of[O,k])t.bindBuffer(t.ARRAY_BUFFER,e),(be.get(e)??0)<ee*4&&(t.bufferData(t.ARRAY_BUFFER,ee*4,t.DYNAMIC_COPY),be.set(e,ee*4));t.bindBuffer(t.ARRAY_BUFFER,null),t.bindVertexArray(D),t.useProgram(l.prog),t.uniform2f(T.u_ox,...y(re)),t.uniform2f(T.u_oy,...y(ie)),we(w.a_x_bits,M),we(w.a_y_bits,N),t.vertexAttribDivisor(w.a_x_bits,0),t.vertexAttribDivisor(w.a_y_bits,0),t.enable(t.RASTERIZER_DISCARD),t.bindTransformFeedback(t.TRANSFORM_FEEDBACK,E),t.bindBufferBase(t.TRANSFORM_FEEDBACK_BUFFER,0,O),t.bindBufferBase(t.TRANSFORM_FEEDBACK_BUFFER,1,k),t.beginTransformFeedback(t.POINTS),t.drawArrays(t.POINTS,0,ee),t.endTransformFeedback(),t.bindBufferBase(t.TRANSFORM_FEEDBACK_BUFFER,0,null),t.bindBufferBase(t.TRANSFORM_FEEDBACK_BUFFER,1,null),t.bindTransformFeedback(t.TRANSFORM_FEEDBACK,null),t.disable(t.RASTERIZER_DISCARD),t.bindVertexArray(u),A=!0}j=!1,L=O,R=k}if(de&&ee>1){let e=g,n=h;t.useProgram(r.prog),t.uniform2f(e.u_resolution,U,ae),t.uniform4f(e.u_plot,me.left,me.top,me.width,me.height),t.uniform4f(e.u_view,...d),t.uniform1f(e.u_half,fe/2),t.uniform1f(e.u_ext,fe/2+1),t.uniform1f(e.u_kScale,c),t.uniform4f(e.u_clip,...f),t.uniform1i(e.u_palette,0),Te(n.a_corner),Ce(n.a_ax,L,0),Ce(n.a_bx,L,1),Ce(n.a_ay,R,0),Ce(n.a_by,R,1),Ce(n.a_bstart,F,1,t.UNSIGNED_BYTE),te?Ce(n.a_k,P,0):(t.disableVertexAttribArray(n.a_k),t.vertexAttrib1f(n.a_k,0)),t.drawArraysInstanced(t.TRIANGLE_STRIP,0,4,ee-1);for(let e of Object.values(n))t.vertexAttribDivisor(e,0)}if(ue&&!H&&2*(se+.5)*oe<=s&&(j?o:a)){let n=j?C:x,r=j?S:b;t.useProgram((j?o:a).prog),j&&(t.uniform2f(n.u_ox,...y(re)),t.uniform2f(n.u_oy,...y(ie))),t.uniform2f(n.u_resolution,U,ae),t.uniform4f(n.u_plot,me.left,me.top,me.width,me.height),t.uniform4f(n.u_view,...d),t.uniform1f(n.u_radius,se),t.uniform1f(n.u_kScale,c),t.uniform1f(n.u_alpha,ce),t.uniform4f(n.u_clip,...f),t.uniform1f(n.u_dpr,oe),t.uniform1f(n.u_height,e.height),t.uniform1i(n.u_palette,0),j?(we(r.a_x_bits,M),we(r.a_y_bits,N)):(Ce(r.a_x,L),Ce(r.a_y,R)),te?Ce(r.a_k,P):(t.disableVertexAttribArray(r.a_k),t.vertexAttrib1f(r.a_k,0));for(let e of Object.values(r))t.vertexAttribDivisor(e,0);t.drawArrays(t.POINTS,0,ee)}else if(ue){let r=j?v:m,a=j?_:p;t.useProgram(j?i.prog:n.prog),j&&(t.uniform2f(r.u_ox,...y(re)),t.uniform2f(r.u_oy,...y(ie))),t.uniform2f(r.u_resolution,U,ae),t.uniform4f(r.u_plot,me.left,me.top,me.width,me.height),t.uniform4f(r.u_view,...d),t.uniform1f(r.u_radius,se),t.uniform1f(r.u_kScale,c),t.uniform1f(r.u_alpha,ce),t.uniform4f(r.u_clip,...f),t.uniform1f(r.u_dpr,oe),t.uniform1f(r.u_height,e.height),t.uniform1i(r.u_palette,0),Te(a.a_corner),j?(we(a.a_x_bits,M),we(a.a_y_bits,N)):(Ce(a.a_x,L),Ce(a.a_y,R)),te?Ce(a.a_k,P):(t.disableVertexAttribArray(a.a_k),t.vertexAttrib1f(a.a_k,0)),H?Ce(a.a_r,I):(t.disableVertexAttribArray(a.a_r),t.vertexAttrib1f(a.a_r,0)),t.drawArraysInstanced(t.TRIANGLE_STRIP,0,4,ee);for(let e of Object.values(a))t.vertexAttribDivisor(e,0)}t.bindVertexArray(null)},dispose(){for(let e of[j,M,N,P,F,I,O,k,L,R,z])t.deleteBuffer(e);t.deleteTransformFeedback(E),t.deleteVertexArray(D),t.deleteTexture(V),t.deleteVertexArray(u)}}}var gG={top:3,right:3,bottom:3,left:3};function _G(e,t,n){return t<200||n<120?{...gG,tiny:!0}:{...e,tiny:!1}}var vG={top:14,right:24,bottom:40,left:78},yG=70,bG=6,xG=8,SG=1.8;function CG(e,t,n){return Math.min(n,Math.max(t,e))}function wG(e,t){let n=e[t],r=1/0,i=-1/0;for(let t=0;t<e.length;t++){let e=n[t];e<r&&(r=e),e>i&&(i=e)}(!Number.isFinite(r)||r===i)&&(--r,i+=1);let a=(i-r)*.04;return{min:r-a,max:i+a}}function TG(e){return e===`dashed`?[5,4]:e===`dotted`?[1,4]:[]}function EG({points:e,xLabel:t,yLabel:n,color:r=`#38bdf8`,datasetColors:i,colorLabel:a,colorRange:o,height:s=400,pointRadius:c=SG,drawMode:l=`points`,lineWidth:u=1,backgroundToken:d=``,onPlotContextMenu:f,xAxisLine:p,yAxisLine:m,gridLine:h,fitSettings:g,xScale:_,yScale:v}){let y=SU(),b=K(null),x=K(null),S=K(null),C=K(f);G(()=>{C.current=f},[f]);let w=K(null),T=K(null),E=K(null),D=K(null),O=K(null),k=K(0),A=K(null),j=ft(()=>FW(e)?e:IW(e),[e]),M=K({cols:j,xLabel:t,yLabel:n,color:r,datasetColors:i,colorLabel:a,colorRange:o,height:s,pointRadius:c,drawMode:l,lineWidth:u,xAxisLine:p,yAxisLine:m,gridLine:h,fitSettings:g,xScale:_,yScale:v});G(()=>{M.current={cols:j,xLabel:t,yLabel:n,color:r,datasetColors:i,colorLabel:a,colorRange:o,height:s,pointRadius:c,drawMode:l,lineWidth:u,xAxisLine:p,yAxisLine:m,gridLine:h,fitSettings:g,xScale:_,yScale:v}},[j,t,n,r,i,a,o,s,c,l,u,p,m,h,g,_,v]);let N=K({cols:null,value:{x:{min:0,max:1},y:{min:0,max:1}}});function P(){let e=M.current.cols,t=N.current;return t.cols!==e&&(t.value={x:wG(e,`x`),y:wG(e,`y`)},t.cols=e),t.value}W(()=>{T.current=null,E.current=null,D.current=null,O.current=null},[t,n]);function F(){let e=P(),t=T.current,n=E.current,r=D.current,i=O.current;return{xmin:t!==null&&n!==null&&n>t?t:e.x.min,xmax:t!==null&&n!==null&&n>t?n:e.x.max,ymin:r!==null&&i!==null&&i>r?r:e.y.min,ymax:r!==null&&i!==null&&i>r?i:e.y.max}}function I(){if(T.current!==null||D.current!==null)return F();let{xScale:e,yScale:t}=M.current,n=e=>{if(!e)return null;let t=parseFloat(e.scaleMin),n=parseFloat(e.scaleMax);return Number.isFinite(t)&&Number.isFinite(n)&&t<n?{min:t,max:n}:null},r=n(e)??P().x,i=n(t)??P().y;return{xmin:r.min,xmax:r.max,ymin:i.min,ymax:i.max}}function L(){if(A.current)return A.current;let e=S.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`,accent:`#f97316`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`,accent:t.getPropertyValue(`--accent`).trim()||`#f97316`};return A.current=n,n}function R(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function z(){let e=S.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||M.current.height)}}let B=K(null),V=K(null),ee=K({r:null,failed:!1,data:null,mode:``,style:``,size:``});function te(e,t){let n=ee.current;!n.r&&!n.failed&&V.current&&(n.r=sH(V.current,hG),n.failed=!n.r);let r=n.r;if(!r||!V.current)return null;let{cols:i,color:a,datasetColors:o,pointRadius:s,drawMode:c,lineWidth:l}=M.current,u=Math.min(2,window.devicePixelRatio||1),d=`${e}x${t}@${u}`;n.size!==d&&(r.resize(e,t,u),V.current.style.width=`${e}px`,V.current.style.height=`${t}px`,n.size=d);let f=o&&o.length>0&&i.d?`dataset`:i.c?`colormap`:`single`,p=c!==`points`;r.setDraw(c!==`lines`,p,l),(n.data!==i||n.mode!==`${f}|${p}`)&&(r.setData(i.x,i.y,f===`dataset`?i.d:f===`colormap`?i.c:void 0,f===`dataset`),n.data=i,n.mode=`${f}|${p}`);let m=`${f}|${a}|${f===`dataset`?o.join(`,`):``}|${s}`;return n.style!==m&&(r.setStyle(OG(f,a,o),Math.max(.25,s),.8),n.style=m),r}W(()=>()=>{ee.current.r?.dispose(),ee.current.r=null},[]);let H=K({cols:null,key:``,coeffs:null});function ne(e,t,n){let r=`${t}|${n.xmin}|${n.xmax}|${n.ymin}|${n.ymax}`,i=H.current;return(i.cols!==e||i.key!==r)&&(H.current={cols:e,key:r,coeffs:JW(e,t,n)}),H.current.coeffs}let re=K({pts:null,view:``}),ie=K(``);function U(){let e=b.current;if(!e)return;let{w:t,h:n}=z(),r=R(e,t,n);if(!r)return;let{cols:i,xLabel:a,yLabel:o,color:s,datasetColors:c,colorLabel:l,colorRange:u,pointRadius:d,xAxisLine:f,yAxisLine:p,gridLine:m,fitSettings:h,xScale:g,yScale:_}=M.current,v=!!c&&c.length>0&&!!i.d,x=!v&&i.length>0&&!!i.c,C=_G(vG,t,n),w=C.tiny?C.right:x?yG:C.right,{top:T,bottom:E,left:D}=C,O=t-D-w,k=n-T-E,{bg:A,muted:j,grid:N,accent:P}=L(),F=Math.max(.25,d),V=te(t,n),ee=i.length>=1&&O>0&&k>0?I():null,H=[t,n,e.width,ee&&`${ee.xmin}|${ee.xmax}|${ee.ymin}|${ee.ymax}`,a,o,x,v,l,u?.join(),JSON.stringify([f,p,m,g,_]),A,j,N,P].join(`§`);if(V&&ee&&!h&&ie.current===H){let e=re.current;e.pts!==i&&(re.current={pts:i,view:e.view},IH(S.current)),V.setView(ee.xmin,ee.xmax,ee.ymin,ee.ymax,{left:D,top:T,width:O,height:k}),V.render();return}ie.current=H,r.fillStyle=A,r.fillRect(0,0,t,n);let U=B.current?R(B.current,t,n):null;U?.clearRect(0,0,t,n);let ae=V;if(i.length<1||O<=0||k<=0){ae?.render(),r.fillStyle=j,r.font=`13px ${Q.sans}`,zV(r);return}let{xmin:oe,xmax:se,ymin:ce,ymax:le}=I(),ue=se-oe,de=le-ce,fe=e=>D+(e-oe)/ue*O;y({left:D,top:T,width:O,height:k,x:{v0:oe,v1:se}});let pe=e=>T+(le-e)/de*k,me=(()=>{if(_?.majorStep){let e=parseFloat(_.majorStep);if(Number.isFinite(e)&&e>0)return e}return Dz(de,6)})(),he=Az(ce,le,me);if((p?.style??`dashed`)!==`none`){r.strokeStyle=p?.color??N,r.lineWidth=p?.width??1,r.setLineDash(TG(p?.style??`dashed`));for(let e of he){let t=pe(e);r.beginPath(),r.moveTo(D,t),r.lineTo(D+O,t),r.stroke()}r.setLineDash([])}r.strokeStyle=j,r.lineWidth=1,r.fillStyle=j,r.font=`11px ${Q.mono}`,r.textAlign=`right`,r.textBaseline=`middle`;for(let e of C.tiny?[]:he){let t=pe(e);r.beginPath(),r.moveTo(D-bG,t),r.lineTo(D,t),r.stroke(),r.fillText(Pz(e,me),D-xG,t)}let ge=(()=>{if(g?.majorStep){let e=parseFloat(g.majorStep);if(Number.isFinite(e)&&e>0)return e}return Dz(ue,Oz(O))})(),_e=Az(oe,se,ge);if((f?.style??`dashed`)!==`none`){r.strokeStyle=f?.color??N,r.lineWidth=f?.width??1,r.setLineDash(TG(f?.style??`dashed`));for(let e of _e){let t=fe(e);r.beginPath(),r.moveTo(t,T),r.lineTo(t,T+k),r.stroke()}r.setLineDash([])}r.strokeStyle=j,r.lineWidth=1,r.fillStyle=j,r.textAlign=`center`,r.textBaseline=`top`;for(let e of C.tiny?[]:_e){let t=fe(e);r.beginPath(),r.moveTo(t,T+k),r.lineTo(t,T+k+bG),r.stroke(),r.fillText(Pz(e,ge),t,T+k+bG+2)}(m?.style??`solid`)!==`none`&&(r.strokeStyle=m?.color??N,r.lineWidth=m?.width??1,r.setLineDash(TG(m?.style??`solid`)),r.strokeRect(D,T,O,k),r.setLineDash([])),r.fillStyle=j,r.font=`11px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`bottom`,C.tiny||(r.fillText(a,D+O/2,n-4),r.save(),r.translate(14,T+k/2),r.rotate(-Math.PI/2),r.fillText(o,0,0),r.restore());let ve=re.current;if((ve.pts!==i||ve.view!==`${oe}|${se}|${ce}|${le}`)&&(re.current={pts:i,view:`${oe}|${se}|${ce}|${le}`},IH(S.current)),ae)ae.setView(oe,se,ce,le,{left:D,top:T,width:O,height:k}),ae.render();else{let e={xToPx:fe,yToPx:pe,left:D,top:T,plotW:O,plotH:k,dotR:F,col:s,dsColors:v?c:null,hasColormap:x};M.current.drawMode!==`points`&&AG(r,i,e,M.current.lineWidth),M.current.drawMode!==`lines`&&kG(r,i,e)}if(x&&!C.tiny){let e=D+O+10,n=k;for(let t=0;t<64;t++)r.fillStyle=eG(1-t/64),r.fillRect(e,T+t/64*n,10,n/64+1);r.strokeStyle=j,r.lineWidth=.5,r.strokeRect(e,T,10,n),r.fillStyle=j,r.font=`10px ${Q.mono}`,r.textAlign=`left`,r.textBaseline=`top`;let i=u?String(u[1].toPrecision(3)):`1`,a=u?String(u[0].toPrecision(3)):`0`;r.fillText(i,e+10+3,T),r.textBaseline=`bottom`,r.fillText(a,e+10+3,T+n),l&&(r.save(),r.textBaseline=`middle`,r.translate(t-6,T+n/2),r.rotate(Math.PI/2),r.fillText(l,0,0),r.restore())}if(h&&U){let e=ne(i,h.degree,{xmin:oe,xmax:se,ymin:ce,ymax:le});if(e){U.save(),U.beginPath(),U.rect(D,T,O,k),U.clip(),U.strokeStyle=h.color,U.lineWidth=h.width,U.setLineDash(TG(h.lineStyle)),U.beginPath();for(let t=0;t<=300;t++){let n=oe+t/300*ue,r=e.reduce((e,t,r)=>e+t*n**+r,0),i=fe(n),a=pe(r);t===0?U.moveTo(i,a):U.lineTo(i,a)}U.stroke(),U.setLineDash([]);let t=ZW(e,`x`,`y`);U.fillStyle=P,U.font=`10px ${Q.mono}`,U.textAlign=`right`,U.textBaseline=`top`,U.fillText(t,D+O-8,T+8),U.restore()}}if((g?.alarm||_?.alarm)&&U){if(U.save(),U.beginPath(),U.rect(D,T,O,k),U.clip(),g?.alarm){let e=g.alarm;U.strokeStyle=e.color,U.lineWidth=e.width,U.setLineDash(e.linked===`active`?wU:TG(e.style));let t=fe(e.value);U.beginPath(),U.moveTo(t,T),U.lineTo(t,T+k),U.stroke(),U.setLineDash([]),e.linked&&EU(U,t+3,T+2,e.color)}if(_?.alarm){let e=_.alarm;U.strokeStyle=e.color,U.lineWidth=e.width,U.setLineDash(e.linked===`active`?wU:TG(e.style));let t=pe(e.value);U.beginPath(),U.moveTo(D,t),U.lineTo(D+O,t),U.stroke(),U.setLineDash([]),e.linked&&EU(U,D+O-10-3,t-10-2,e.color)}U.restore()}}let ae=K(``);function oe(){let e=x.current;if(!e)return;let{w:t,h:n}=z(),r=`${t}x${n}`;if(w.current===null&&ae.current===r)return;let i=R(e,t,n);if(!i)return;i.clearRect(0,0,t,n),ae.current=w.current===null?r:``;let a=w.current,{cols:o,color:s,datasetColors:c,pointRadius:l}=M.current;if(a===null||a>=o.length||o.length<1)return;let u=Math.max(4,l*2),d=o.d?.[a],f=c&&c.length>0&&d!==void 0?c[d]??s:s,{top:p,right:m,bottom:h,left:g}=_G(vG,t,n),_=t-g-m,v=n-p-h;if(_<=0||v<=0)return;let{xmin:y,xmax:b,ymin:S,ymax:C}=I(),T=b-y,E=C-S,D={x:o.x[a],y:o.y[a]},O=g+(D.x-y)/T*_,k=p+(C-D.y)/E*v,{bg:A,muted:j}=L();i.strokeStyle=j,i.globalAlpha=.4,i.lineWidth=1,i.setLineDash([3,3]),i.beginPath(),i.moveTo(O,p),i.lineTo(O,p+v),i.stroke(),i.beginPath(),i.moveTo(g,k),i.lineTo(g+_,k),i.stroke(),i.setLineDash([]),i.globalAlpha=1,i.fillStyle=f,i.beginPath(),i.arc(O,k,u,0,Math.PI*2),i.fill(),i.strokeStyle=A,i.lineWidth=1.5,i.beginPath(),i.arc(O,k,u,0,Math.PI*2),i.stroke();let N=`(${Fz(D.x)}, ${Fz(D.y)})`;i.font=`11px ${Q.mono}`;let P=i.measureText(N).width+12,F=O+10,B=k-24;F+P>g+_&&(F=O-P-10),B<p&&(B=k+10),i.fillStyle=A,i.globalAlpha=.85,i.beginPath(),DG(i,F,B,P,20,4),i.fill(),i.globalAlpha=1,i.strokeStyle=j,i.lineWidth=.5,i.beginPath(),DG(i,F,B,P,20,4),i.stroke(),i.fillStyle=j,i.textAlign=`left`,i.textBaseline=`middle`,i.fillText(N,F+6,B+20/2)}let se=K(U),ce=K(oe);G(()=>{se.current=U,ce.current=oe});let le=K(null);le.current??=VH(()=>{se.current(),ce.current()},()=>S.current);function ue(){le.current.schedule()}function de(){k.current||=NH(()=>{k.current=0,ce.current()})}W(()=>()=>{le.current?.cancel(),PH(k.current),k.current=0},[]);let fe=K(ue),pe=K(de);return G(()=>{fe.current=ue,pe.current=de}),W(()=>rB(S.current,()=>{A.current=null,fe.current()}),[]),W(()=>{A.current=null,fe.current()},[d]),W(()=>{le.current.now()},[e,t,n,r,i,s,c,l,u,p,m,h,g,_,v]),W(()=>{let e=x.current,t=S.current;if(!e||!t)return;let n=new zH(()=>{A.current=null,fe.current()});n.observe(t);let r=null;function i(e,t){let n=M.current.cols;if(n.length===0)return null;let{w:i,h:a}=z(),{top:o,right:s,bottom:c,left:l}=_G(vG,i,a),u=i-l-s,d=a-o-c,{xmin:f,xmax:p,ymin:m,ymax:h}=I(),g=p-f,_=h-m,v=Math.max(12,M.current.pointRadius*10),y=`${i}|${a}|${f}|${p}|${m}|${h}|${v}`;if(!r||r.cols!==n||r.key!==y){let e=Math.max(1,Math.ceil(u/v)),t=Math.max(1,Math.ceil(d/v)),i=t=>{let r=(n.x[t]-f)/g*u,i=(h-n.y[t])/_*d;return r>=0&&r<u&&i>=0&&i<d?Math.floor(i/v)*e+Math.floor(r/v):-1},a=new Uint32Array(e*t+1);for(let e=0;e<n.length;e++){let t=i(e);t>=0&&a[t+1]++}for(let n=0;n<e*t;n++)a[n+1]+=a[n];let o=a.slice(0,e*t),s=new Uint32Array(a[e*t]);for(let e=0;e<n.length;e++){let t=i(e);t>=0&&(s[o[t]++]=e)}r={cols:n,key:y,cell:v,nx:e,start:a,ix:s}}let b=r,x=Math.floor((e-l)/b.cell),S=Math.floor((t-o)/b.cell),C=(b.start.length-1)/b.nx,w=-1,T=v*v;for(let r=S-1;r<=S+1;r++)if(!(r<0||r>=C))for(let i=x-1;i<=x+1;i++){if(i<0||i>=b.nx)continue;let a=r*b.nx+i;for(let r=b.start[a];r<b.start[a+1];r++){let i=b.ix[r],a=l+(n.x[i]-f)/g*u,s=o+(h-n.y[i])/_*d,c=(a-e)**2+(s-t)**2;c<T&&(T=c,w=i)}}return w<0?null:w}let a=t=>{if(M.current.cols.length<1){w.current!==null&&(w.current=null,pe.current());return}let n=e.getBoundingClientRect(),r=t.clientX-n.left,a=t.clientY-n.top,{left:o,top:s,right:c,bottom:l}=_G(vG,n.width,n.height),u=Math.max(1,n.width-o-c),d=n.height-s-l;if(r<o||r>o+u||a<s||a>s+d){w.current!==null&&(w.current=null,pe.current());return}let f=i(r,a);w.current!==f&&(w.current=f,pe.current())},o=()=>{w.current!==null&&(w.current=null,pe.current())},s=t=>{if(M.current.cols.length<1)return;let n=e.getBoundingClientRect(),r=t.clientX-n.left,i=t.clientY-n.top,{top:a,left:o,right:s,bottom:c}=_G(vG,n.width,n.height),l=Math.max(1,n.width-o-s),u=Math.max(1,n.height-a-c);if(r<o||r>o+l||i<a||i>a+u)return;t.preventDefault();let d=P(),f=d.x.max-d.x.min,p=d.y.max-d.y.min,m=I(),h=m.xmin,g=m.xmax,_=m.ymin,v=m.ymax,y=g-h,b=v-_,x=(r-o)/l,S=(i-a)/u,C=h+x*y,w=v-S*b,k=t.deltaY<0,A=.88,j=k?A:1/A,N=y*j,F=b*j;if(!k&&N>=f*.999&&F>=p*.999){T.current=null,E.current=null,D.current=null,O.current=null,fe.current();return}N=CG(N,Math.max(f*1e-7,1e-12),f),F=CG(F,Math.max(p*1e-7,1e-12),p);let L=C-x*N,R=C+(1-x)*N;L<d.x.min&&(R+=d.x.min-L,L=d.x.min),R>d.x.max&&(L-=R-d.x.max,R=d.x.max);let z=w-(1-S)*F,B=w+S*F;z<d.y.min&&(B+=d.y.min-z,z=d.y.min),B>d.y.max&&(z-=B-d.y.max,B=d.y.max),T.current=L,E.current=R,D.current=z,O.current=B,fe.current()},c=e=>{e.button===0&&(T.current===null&&D.current===null||(T.current=null,E.current=null,D.current=null,O.current=null,fe.current(),pe.current()))},l=e=>{e.preventDefault(),C.current?.({clientX:e.clientX,clientY:e.clientY})};return e.addEventListener(`mousemove`,a),e.addEventListener(`mouseleave`,o),e.addEventListener(`wheel`,s,{passive:!1}),e.addEventListener(`contextmenu`,l),e.addEventListener(`dblclick`,c),()=>{n.disconnect(),e.removeEventListener(`mousemove`,a),e.removeEventListener(`mouseleave`,o),e.removeEventListener(`wheel`,s),e.removeEventListener(`contextmenu`,l),e.removeEventListener(`dblclick`,c)}},[]),vt(`div`,{ref:S,className:`chart-canvas-wrap`,children:[q(`canvas`,{ref:b,className:`chart-canvas`,role:`img`,"aria-label":`Scatter ${t} vs ${n}`}),q(`canvas`,{ref:V,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),q(`canvas`,{ref:B,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),q(`canvas`,{ref:x,className:`chart-canvas chart-overlay`})]})}function DG(e,t,n,r,i,a){e.moveTo(t+a,n),e.lineTo(t+r-a,n),e.arcTo(t+r,n,t+r,n+a,a),e.lineTo(t+r,n+i-a),e.arcTo(t+r,n+i,t+r-a,n+i,a),e.lineTo(t+a,n+i),e.arcTo(t,n+i,t,n+i-a,a),e.lineTo(t,n+a),e.arcTo(t,n,t+a,n,a)}function OG(e,t,n){if(e===`single`)return{kind:`single`,rgba:UV(t)};let r=new Uint8Array(256*4);for(let t=0;t<256;t++)if(e===`colormap`){let{r:e,g:n,b:i}=$W(t/255);r.set([e,n,i,255],t*4)}else{let e=UV(n[Math.min(t,n.length-1)]);r.set([e[0]*255,e[1]*255,e[2]*255,e[3]*255],t*4)}return{kind:e===`colormap`?`colormap`:`dataset`,palette:r}}function kG(e,t,n){let r=Math.PI*2,i=n.dsColors?n.dsColors.length:n.hasColormap?24:1,a=Array.from({length:i},()=>new Path2D);for(let e=0;e<t.length;e++){let o=n.xToPx(t.x[e]),s=n.yToPx(t.y[e]);if(!(o>=n.left&&o<=n.left+n.plotW&&s>=n.top&&s<=n.top+n.plotH))continue;let c=n.dsColors?Math.min(t.d?.[e]??0,i-1):n.hasColormap?tG(t.c?.[e]??0,24):0;a[c].moveTo(o+n.dotR,s),a[c].arc(o,s,n.dotR,0,r)}e.globalAlpha=.8;for(let t=0;t<i;t++)e.fillStyle=n.dsColors?n.dsColors[t]:n.hasColormap?eG((t+.5)/24):n.col,e.fill(a[t]);e.globalAlpha=1}function AG(e,t,n,r){e.save(),e.beginPath(),e.rect(n.left,n.top,n.plotW,n.plotH),e.clip(),e.lineWidth=r;let i=n.dsColors?n.dsColors.length:1;for(let r=0;r<i;r++){e.beginPath();let i=!1;for(let a=0;a<t.length;a++){if(n.dsColors&&(t.d?.[a]??0)!==r){i=!1;continue}let o=t.x[a],s=t.y[a];if(o-o!==0||s-s!==0){i=!1;continue}i?e.lineTo(n.xToPx(o),n.yToPx(s)):(e.moveTo(n.xToPx(o),n.yToPx(s)),i=!0)}e.strokeStyle=n.dsColors?n.dsColors[r]:n.col,e.stroke()}e.restore()}var jG=11102230246251565e-32,MG=134217729,NG=(3+8*jG)*jG;function PG(e,t,n,r,i){let a,o,s,c,l=t[0],u=r[0],d=0,f=0;u>l==u>-l?(a=l,l=t[++d]):(a=u,u=r[++f]);let p=0;if(d<e&&f<n)for(u>l==u>-l?(o=l+a,s=a-(o-l),l=t[++d]):(o=u+a,s=a-(o-u),u=r[++f]),a=o,s!==0&&(i[p++]=s);d<e&&f<n;)u>l==u>-l?(o=a+l,c=o-a,s=a-(o-c)+(l-c),l=t[++d]):(o=a+u,c=o-a,s=a-(o-c)+(u-c),u=r[++f]),a=o,s!==0&&(i[p++]=s);for(;d<e;)o=a+l,c=o-a,s=a-(o-c)+(l-c),l=t[++d],a=o,s!==0&&(i[p++]=s);for(;f<n;)o=a+u,c=o-a,s=a-(o-c)+(u-c),u=r[++f],a=o,s!==0&&(i[p++]=s);return(a!==0||p===0)&&(i[p++]=a),p}function FG(e,t){let n=t[0];for(let r=1;r<e;r++)n+=t[r];return n}function $(e){return new Float64Array(e)}var IG=(3+16*jG)*jG,LG=(2+12*jG)*jG,RG=(9+64*jG)*jG*jG,zG=$(4),BG=$(8),VG=$(12),HG=$(16),UG=$(4);function WG(e,t,n,r,i,a,o){let s,c,l,u,d,f,p,m,h,g,_,v,y,b,x,S,C,w,T=e-i,E=n-i,D=t-a,O=r-a;b=T*O,f=MG*T,p=f-(f-T),m=T-p,f=MG*O,h=f-(f-O),g=O-h,x=m*g-(b-p*h-m*h-p*g),S=D*E,f=MG*D,p=f-(f-D),m=D-p,f=MG*E,h=f-(f-E),g=E-h,C=m*g-(S-p*h-m*h-p*g),_=x-C,d=x-_,zG[0]=x-(_+d)+(d-C),v=b+_,d=v-b,y=b-(v-d)+(_-d),_=y-S,d=y-_,zG[1]=y-(_+d)+(d-S),w=v+_,d=w-v,zG[2]=v-(w-d)+(_-d),zG[3]=w;let k=FG(4,zG),A=LG*o;if(k>=A||-k>=A||(d=e-T,s=e-(T+d)+(d-i),d=n-E,l=n-(E+d)+(d-i),d=t-D,c=t-(D+d)+(d-a),d=r-O,u=r-(O+d)+(d-a),s===0&&c===0&&l===0&&u===0)||(A=RG*o+NG*Math.abs(k),k+=T*u+O*s-(D*l+E*c),k>=A||-k>=A))return k;b=s*O,f=MG*s,p=f-(f-s),m=s-p,f=MG*O,h=f-(f-O),g=O-h,x=m*g-(b-p*h-m*h-p*g),S=c*E,f=MG*c,p=f-(f-c),m=c-p,f=MG*E,h=f-(f-E),g=E-h,C=m*g-(S-p*h-m*h-p*g),_=x-C,d=x-_,UG[0]=x-(_+d)+(d-C),v=b+_,d=v-b,y=b-(v-d)+(_-d),_=y-S,d=y-_,UG[1]=y-(_+d)+(d-S),w=v+_,d=w-v,UG[2]=v-(w-d)+(_-d),UG[3]=w;let j=PG(4,zG,4,UG,BG);b=T*u,f=MG*T,p=f-(f-T),m=T-p,f=MG*u,h=f-(f-u),g=u-h,x=m*g-(b-p*h-m*h-p*g),S=D*l,f=MG*D,p=f-(f-D),m=D-p,f=MG*l,h=f-(f-l),g=l-h,C=m*g-(S-p*h-m*h-p*g),_=x-C,d=x-_,UG[0]=x-(_+d)+(d-C),v=b+_,d=v-b,y=b-(v-d)+(_-d),_=y-S,d=y-_,UG[1]=y-(_+d)+(d-S),w=v+_,d=w-v,UG[2]=v-(w-d)+(_-d),UG[3]=w;let M=PG(j,BG,4,UG,VG);return b=s*u,f=MG*s,p=f-(f-s),m=s-p,f=MG*u,h=f-(f-u),g=u-h,x=m*g-(b-p*h-m*h-p*g),S=c*l,f=MG*c,p=f-(f-c),m=c-p,f=MG*l,h=f-(f-l),g=l-h,C=m*g-(S-p*h-m*h-p*g),_=x-C,d=x-_,UG[0]=x-(_+d)+(d-C),v=b+_,d=v-b,y=b-(v-d)+(_-d),_=y-S,d=y-_,UG[1]=y-(_+d)+(d-S),w=v+_,d=w-v,UG[2]=v-(w-d)+(_-d),UG[3]=w,HG[PG(M,VG,4,UG,HG)-1]}function GG(e,t,n,r,i,a){let o=(t-a)*(n-i),s=(e-i)*(r-a),c=o-s,l=Math.abs(o+s);return Math.abs(c)>=IG*l?c:-WG(e,t,n,r,i,a,l)}(7+56*jG)*jG,(3+28*jG)*jG,(26+288*jG)*jG*jG,$(4),$(4),$(4),$(4),$(4),$(4),$(4),$(4),$(4),$(8),$(8),$(8),$(4),$(8),$(8),$(16),$(12),$(192),$(192),(10+96*jG)*jG,(4+48*jG)*jG,(44+576*jG)*jG*jG,$(4),$(4),$(4),$(4),$(4),$(4),$(4),$(4),$(8),$(8),$(8),$(8),$(8),$(8),$(8),$(8),$(8),$(4),$(4),$(4),$(8),$(16),$(16),$(16),$(32),$(32),$(48),$(64),$(1152),$(1152),(16+224*jG)*jG,(5+72*jG)*jG,(71+1408*jG)*jG*jG,$(4),$(4),$(4),$(4),$(4),$(4),$(4),$(4),$(4),$(4),$(24),$(24),$(24),$(24),$(24),$(24),$(24),$(24),$(24),$(24),$(1152),$(1152),$(1152),$(1152),$(1152),$(2304),$(2304),$(3456),$(5760),$(8),$(8),$(8),$(16),$(24),$(48),$(48),$(96),$(192),$(384),$(384),$(384),$(768),$(96),$(96),$(96),$(1152);var KG=2**-52,qG=new Uint32Array(512),JG=class e{static from(t,n=nK,r=rK){let i=t.length,a=new Float64Array(i*2);for(let e=0;e<i;e++){let i=t[e];a[2*e]=n(i),a[2*e+1]=r(i)}return new e(a)}constructor(e){let t=e.length>>1;if(t>0&&typeof e[0]!=`number`)throw Error(`Expected coords to contain numbers.`);this.coords=e;let n=Math.max(2*t-5,0);this._triangles=new Uint32Array(n*3),this._halfedges=new Int32Array(n*3),this._hashSize=Math.ceil(Math.sqrt(t)),this._hullPrev=new Uint32Array(t),this._hullNext=new Uint32Array(t),this._hullTri=new Uint32Array(t),this._hullHash=new Int32Array(this._hashSize),this._ids=new Uint32Array(t),this._dists=new Float64Array(t),this.trianglesLen=0,this._cx=0,this._cy=0,this._hullStart=0,this.hull=this._triangles,this.triangles=this._triangles,this.halfedges=this._halfedges,this.update()}update(){let{coords:e,_hullPrev:t,_hullNext:n,_hullTri:r,_hullHash:i}=this,a=e.length>>1,o=1/0,s=1/0,c=-1/0,l=-1/0;for(let t=0;t<a;t++){let n=e[2*t],r=e[2*t+1];n<o&&(o=n),r<s&&(s=r),n>c&&(c=n),r>l&&(l=r),this._ids[t]=t}let u=(o+c)/2,d=(s+l)/2,f=0,p=0,m=0;for(let t=0,n=1/0;t<a;t++){let r=XG(u,d,e[2*t],e[2*t+1]);r<n&&(f=t,n=r)}let h=e[2*f],g=e[2*f+1];for(let t=0,n=1/0;t<a;t++){if(t===f)continue;let r=XG(h,g,e[2*t],e[2*t+1]);r<n&&r>0&&(p=t,n=r)}let _=e[2*p],v=e[2*p+1],y=1/0;for(let t=0;t<a;t++){if(t===f||t===p)continue;let n=QG(h,g,_,v,e[2*t],e[2*t+1]);n<y&&(m=t,y=n)}let b=e[2*m],x=e[2*m+1];if(y===1/0){for(let t=0;t<a;t++)this._dists[t]=e[2*t]-e[0]||e[2*t+1]-e[1];eK(this._ids,this._dists,0,a-1);let t=new Uint32Array(a),n=0;for(let e=0,r=-1/0;e<a;e++){let i=this._ids[e],a=this._dists[i];a>r&&(t[n++]=i,r=a)}this.hull=t.subarray(0,n),this.triangles=new Uint32Array,this.halfedges=new Int32Array;return}if(GG(h,g,_,v,b,x)<0){let e=p,t=_,n=v;p=m,_=b,v=x,m=e,b=t,x=n}let S=$G(h,g,_,v,b,x);this._cx=S.x,this._cy=S.y;for(let t=0;t<a;t++)this._dists[t]=XG(e[2*t],e[2*t+1],S.x,S.y);eK(this._ids,this._dists,0,a-1),this._hullStart=f;let C=3;n[f]=t[m]=p,n[p]=t[f]=m,n[m]=t[p]=f,r[f]=0,r[p]=1,r[m]=2,i.fill(-1),i[this._hashKey(h,g)]=f,i[this._hashKey(_,v)]=p,i[this._hashKey(b,x)]=m,this.trianglesLen=0,this._addTriangle(f,p,m,-1,-1,-1);for(let a=0,o=0,s=0;a<this._ids.length;a++){let c=this._ids[a],l=e[2*c],u=e[2*c+1];if(a>0&&Math.abs(l-o)<=KG&&Math.abs(u-s)<=KG||(o=l,s=u,c===f||c===p||c===m))continue;let d=0;for(let e=0,t=this._hashKey(l,u);e<this._hashSize&&(d=i[(t+e)%this._hashSize],!(d!==-1&&d!==n[d]));e++);d=t[d];let h=d,g;for(;g=n[h],GG(l,u,e[2*h],e[2*h+1],e[2*g],e[2*g+1])>=0;)if(h=g,h===d){h=-1;break}if(h===-1)continue;let _=this._addTriangle(h,c,n[h],-1,-1,r[h]);r[c]=this._legalize(_+2),r[h]=_,C++;let v=n[h];for(;g=n[v],GG(l,u,e[2*v],e[2*v+1],e[2*g],e[2*g+1])<0;)_=this._addTriangle(v,c,g,r[c],-1,r[v]),r[c]=this._legalize(_+2),n[v]=v,C--,v=g;if(h===d)for(;g=t[h],GG(l,u,e[2*g],e[2*g+1],e[2*h],e[2*h+1])<0;)_=this._addTriangle(g,c,h,-1,r[h],r[g]),this._legalize(_+2),r[g]=_,n[h]=h,C--,h=g;this._hullStart=t[c]=h,n[h]=t[v]=c,n[c]=v,i[this._hashKey(l,u)]=c,i[this._hashKey(e[2*h],e[2*h+1])]=h}this.hull=new Uint32Array(C);for(let e=0,t=this._hullStart;e<C;e++)this.hull[e]=t,t=n[t];this.triangles=this._triangles.subarray(0,this.trianglesLen),this.halfedges=this._halfedges.subarray(0,this.trianglesLen)}_hashKey(e,t){return Math.floor(YG(e-this._cx,t-this._cy)*this._hashSize)%this._hashSize}_legalize(e){let{_triangles:t,_halfedges:n,coords:r}=this,i=0,a=0;for(;;){let o=n[e],s=e-e%3;if(a=s+(e+2)%3,o===-1){if(i===0)break;e=qG[--i];continue}let c=o-o%3,l=s+(e+1)%3,u=c+(o+2)%3,d=t[a],f=t[e],p=t[l],m=t[u];if(ZG(r[2*d],r[2*d+1],r[2*f],r[2*f+1],r[2*p],r[2*p+1],r[2*m],r[2*m+1])){t[e]=m,t[o]=d;let r=n[u];if(r===-1){let t=this._hullStart;do{if(this._hullTri[t]===u){this._hullTri[t]=e;break}t=this._hullPrev[t]}while(t!==this._hullStart)}this._link(e,r),this._link(o,n[a]),this._link(a,u);let s=c+(o+1)%3;i<qG.length&&(qG[i++]=s)}else{if(i===0)break;e=qG[--i]}}return a}_link(e,t){this._halfedges[e]=t,t!==-1&&(this._halfedges[t]=e)}_addTriangle(e,t,n,r,i,a){let o=this.trianglesLen;return this._triangles[o]=e,this._triangles[o+1]=t,this._triangles[o+2]=n,this._link(o,r),this._link(o+1,i),this._link(o+2,a),this.trianglesLen+=3,o}};function YG(e,t){let n=e/(Math.abs(e)+Math.abs(t));return(t>0?3-n:1+n)/4}function XG(e,t,n,r){let i=e-n,a=t-r;return i*i+a*a}function ZG(e,t,n,r,i,a,o,s){let c=e-o,l=t-s,u=n-o,d=r-s,f=i-o,p=a-s,m=c*c+l*l,h=u*u+d*d,g=f*f+p*p;return c*(d*g-h*p)-l*(u*g-h*f)+m*(u*p-d*f)<0}function QG(e,t,n,r,i,a){let o=n-e,s=r-t,c=i-e,l=a-t,u=o*o+s*s,d=c*c+l*l,f=.5/(o*l-s*c),p=(l*u-s*d)*f,m=(o*d-c*u)*f;return p*p+m*m}function $G(e,t,n,r,i,a){let o=n-e,s=r-t,c=i-e,l=a-t,u=o*o+s*s,d=c*c+l*l,f=.5/(o*l-s*c);return{x:e+(l*u-s*d)*f,y:t+(o*d-c*u)*f}}function eK(e,t,n,r){if(r-n<=20)for(let i=n+1;i<=r;i++){let r=e[i],a=t[r],o=i-1;for(;o>=n&&t[e[o]]>a;)e[o+1]=e[o--];e[o+1]=r}else{let i=n+r>>1,a=n+1,o=r;tK(e,i,a),t[e[n]]>t[e[r]]&&tK(e,n,r),t[e[a]]>t[e[r]]&&tK(e,a,r),t[e[n]]>t[e[a]]&&tK(e,n,a);let s=e[a],c=t[s];for(;;){do a++;while(t[e[a]]<c);do o--;while(t[e[o]]>c);if(o<a)break;tK(e,a,o)}e[n+1]=e[o],e[o]=s,r-a+1>=o-n?(eK(e,t,a,r),eK(e,t,n,o-1)):(eK(e,t,n,o-1),eK(e,t,a,r))}}function tK(e,t,n){let r=e[t];e[t]=e[n],e[n]=r}function nK(e){return e[0]}function rK(e){return e[1]}var iK=`
|
|
375
375
|
uniform vec3 u_lo; // the box minimum, relative to the data origin
|
|
376
376
|
uniform vec3 u_span; // the box size (0: a flat axis)
|
|
377
377
|
uniform int u_flat; // 0: 3D camera, 1: a 2D view
|
|
@@ -407,17 +407,17 @@ vec4 place(vec3 d) {
|
|
|
407
407
|
float z = clamp(cz / 16.0, 0.0, 1.0) * 2.0 - 1.0;
|
|
408
408
|
return vec4(c.x * cz, -c.y * cz, z * cz, cz);
|
|
409
409
|
}
|
|
410
|
-
`,
|
|
410
|
+
`,aK=`bool outside(vec3 n) { return any(greaterThan(abs(n), vec3(1.0001))); }`,oK=`#version 300 es
|
|
411
411
|
in float a_x; in float a_y; in float a_z;
|
|
412
412
|
uniform float u_size;
|
|
413
|
-
${
|
|
414
|
-
${
|
|
413
|
+
${iK}
|
|
414
|
+
${aK}
|
|
415
415
|
void main() {
|
|
416
416
|
vec3 d = vec3(a_x, a_y, a_z);
|
|
417
417
|
gl_Position = place(d);
|
|
418
418
|
gl_PointSize = u_size;
|
|
419
419
|
if (a_x != a_x || a_y != a_y || a_z != a_z || outside(v_n)) gl_Position = vec4(2.0, 2.0, 2.0, 1.0);
|
|
420
|
-
}`,
|
|
420
|
+
}`,sK=`#version 300 es
|
|
421
421
|
precision highp float;
|
|
422
422
|
in vec3 v_n; in vec4 v_color;
|
|
423
423
|
uniform float u_size; // device px
|
|
@@ -428,10 +428,10 @@ void main() {
|
|
|
428
428
|
if (u_size >= 3.0 && r > u_size * 0.5) discard;
|
|
429
429
|
vec4 c = r > u_size * 0.5 - u_rim ? vec4(0.0588, 0.0627, 0.0784, 0.85) : v_color;
|
|
430
430
|
o = vec4(c.rgb * c.a, c.a);
|
|
431
|
-
}`,
|
|
431
|
+
}`,cK=`#version 300 es
|
|
432
432
|
in float a_x; in float a_y; in float a_z;
|
|
433
|
-
${
|
|
434
|
-
void main() { gl_Position = place(vec3(a_x, a_y, a_z)); }`,
|
|
433
|
+
${iK}
|
|
434
|
+
void main() { gl_Position = place(vec3(a_x, a_y, a_z)); }`,lK=`#version 300 es
|
|
435
435
|
precision highp int;
|
|
436
436
|
uniform highp sampler2D u_z;
|
|
437
437
|
uniform ivec2 u_n; // grid size
|
|
@@ -440,7 +440,7 @@ uniform int u_wstep; // grid cells between wire lines
|
|
|
440
440
|
uniform int u_wire;
|
|
441
441
|
uniform vec4 u_ext; // x0, x1, y0, y1 (relative to the origin)
|
|
442
442
|
out float v_hole;
|
|
443
|
-
${
|
|
443
|
+
${iK}
|
|
444
444
|
void main() {
|
|
445
445
|
int cx = (u_n.x - 2) / u_step + 1, cy = (u_n.y - 2) / u_step + 1;
|
|
446
446
|
int id = gl_VertexID, gx, gy;
|
|
@@ -459,29 +459,29 @@ void main() {
|
|
|
459
459
|
v_hole = z != z ? 1.0 : 0.0;
|
|
460
460
|
float fx = u_n.x > 1 ? float(gx) / float(u_n.x - 1) : 0.0, fy = u_n.y > 1 ? float(gy) / float(u_n.y - 1) : 0.0;
|
|
461
461
|
gl_Position = place(vec3(mix(u_ext.x, u_ext.y, fx), mix(u_ext.z, u_ext.w, fy), z == z ? z : 0.0));
|
|
462
|
-
}`,
|
|
462
|
+
}`,uK=`#version 300 es
|
|
463
463
|
precision highp float;
|
|
464
464
|
in vec3 v_n; in vec4 v_color;
|
|
465
465
|
uniform float u_alpha;
|
|
466
466
|
uniform vec4 u_solid; // a colour of its own (wire) when its alpha is set
|
|
467
|
-
${
|
|
467
|
+
${aK}
|
|
468
468
|
out vec4 o;
|
|
469
469
|
void main() {
|
|
470
470
|
if (outside(v_n)) discard;
|
|
471
471
|
vec4 c = u_solid.a > 0.0 ? u_solid : vec4(v_color.rgb, u_alpha);
|
|
472
472
|
o = vec4(c.rgb * c.a, c.a);
|
|
473
|
-
}`,
|
|
473
|
+
}`,dK=`#version 300 es
|
|
474
474
|
precision highp float;
|
|
475
475
|
in vec3 v_n; in vec4 v_color; in float v_hole;
|
|
476
476
|
uniform float u_alpha;
|
|
477
477
|
uniform vec4 u_solid;
|
|
478
|
-
${
|
|
478
|
+
${aK}
|
|
479
479
|
out vec4 o;
|
|
480
480
|
void main() {
|
|
481
481
|
if (v_hole > 0.0 || outside(v_n)) discard;
|
|
482
482
|
vec4 c = u_solid.a > 0.0 ? u_solid : vec4(v_color.rgb, u_alpha);
|
|
483
483
|
o = vec4(c.rgb * c.a, c.a);
|
|
484
|
-
}`,JG=16e6,YG=128,XG=[`u_lo`,`u_span`,`u_flat`,`u_eye`,`u_right`,`u_up`,`u_fwd`,`u_f`,`u_h`,`u_v`,`u_c`,`u_plot`,`u_resolution`,`u_palette`];function ZG(e){for(let t=0;t<e.length;t++)if(e[t]===e[t]&&Math.abs(e[t])!==1/0)return e[t];return 0}function QG(e){let t=e.getContext(`webgl2`,{antialias:!0,alpha:!0,premultipliedAlpha:!0,depth:!0});if(!t)return null;let n=(e,n,r,i)=>pH(t,`gl3d|${e}|${n}`,()=>{let a=JV(t,t.VERTEX_SHADER,e),o=JV(t,t.FRAGMENT_SHADER,n);if(!a||!o)return null;let s=t.createProgram();return t.attachShader(s,a),t.attachShader(s,o),t.linkProgram(s),t.getProgramParameter(s,t.LINK_STATUS)?{prog:s,a:Object.fromEntries(r.map(e=>[e,t.getAttribLocation(s,e)])),u:Object.fromEntries([...XG,...i].map(e=>[e,t.getUniformLocation(s,e)]))}:(console.error(`gl3d program link failed:`,t.getProgramInfoLog(s)),null)}),r=[`a_x`,`a_y`,`a_z`],i=n(HG,UG,r,[`u_size`,`u_rim`]),a=n(WG,KG,r,[`u_alpha`,`u_solid`]),o=n(GG,qG,[],[`u_alpha`,`u_solid`,`u_z`,`u_n`,`u_step`,`u_wstep`,`u_wire`,`u_ext`]);if(!i||!a||!o)return null;let s=t.getParameter(t.MAX_TEXTURE_SIZE),c=t.createVertexArray(),l={x:t.createBuffer(),y:t.createBuffer(),z:t.createBuffer()},u=t.createBuffer(),d=t.createBuffer(),f=new Map,p=t.createTexture(),m=t.createTexture(),h=1,g=1,_=1,v={minX:0,maxX:1,minY:0,maxY:1,minZ:0,maxZ:1},y={kind:`2d`,h:0,v:1},b={left:0,top:0,width:1,height:1},x=null,S=0,C=[0,0,0],w=0,T=0,E=null,D={w:0,h:0},O=new Float32Array,k=(e,n,r)=>{t.bindBuffer(e,n),r.byteLength<=(f.get(n)??0)?t.bufferSubData(e,0,r):(t.bufferData(e,r,t.DYNAMIC_DRAW),f.set(n,r.byteLength))},A=(e,t)=>{let n=e.length;O.length<n&&(O=new Float32Array(n));for(let r=0;r<n;r++)O[r]=e[r]-t;return O.subarray(0,n)},j=(e,n)=>{let r=e.u,i=v;t.uniform3f(r.u_lo,i.minX-n[0],i.minY-n[1],i.minZ-n[2]);let a=(e,t)=>t-e>1e-12*Math.max(1,Math.abs(e))?t-e:0;t.uniform3f(r.u_span,a(i.minX,i.maxX),a(i.minY,i.maxY),a(i.minZ,i.maxZ));let o=e=>[+(e===0),+(e===1),+(e===2)];y.kind===`3d`?(t.uniform1i(r.u_flat,0),t.uniform3f(r.u_eye,...y.eye),t.uniform3f(r.u_right,...y.right),t.uniform3f(r.u_up,...y.up),t.uniform3f(r.u_fwd,...y.fwd),t.uniform1f(r.u_f,y.f)):(t.uniform1i(r.u_flat,1),t.uniform3f(r.u_h,...o(y.h)),t.uniform3f(r.u_v,...o(y.v))),t.uniform3f(r.u_c,...o(x.colorAxis)),t.uniform4f(r.u_plot,b.left,b.top,b.width,b.height),t.uniform2f(r.u_resolution,h,g),t.uniform1i(r.u_palette,0)},M=e=>{for(let n of[`x`,`y`,`z`]){let r=e.a[`a_${n}`];t.bindBuffer(t.ARRAY_BUFFER,l[n]),t.enableVertexAttribArray(r),t.vertexAttribPointer(r,1,t.FLOAT,!1,0,0)}};return{maxTextureSize:s,resize(t,n,r){h=Math.max(1,t),g=Math.max(1,n),_=r,e.width=Math.max(1,Math.round(h*_)),e.height=Math.max(1,Math.round(g*_))},setBounds(e){v=e},setView(e,t){y=e,b=t},setPoints(e,n,r){if(!e||!n||!r){S=0;return}S=Math.min(e.length,n.length,r.length),C=[ZG(e),ZG(n),ZG(r)],k(t.ARRAY_BUFFER,l.x,A(e,C[0]).subarray(0,S)),k(t.ARRAY_BUFFER,l.y,A(n,C[1]).subarray(0,S)),k(t.ARRAY_BUFFER,l.z,A(r,C[2]).subarray(0,S))},setTriangles(e){if(!e||e.length<3){w=T=0;return}w=e.length-e.length%3,k(t.ELEMENT_ARRAY_BUFFER,u,e.subarray(0,w));let n=new Uint32Array(w*2);for(let t=0;t<w;t+=3){let r=e[t],i=e[t+1],a=e[t+2],o=t*2;n[o]=r,n[o+1]=i,n[o+2]=i,n[o+3]=a,n[o+4]=a,n[o+5]=r}T=n.length,k(t.ELEMENT_ARRAY_BUFFER,d,n)},setSurface(e,n=0,r=0,i=[0,1],a=[0,1]){if(!e||n<2||r<2||n>s||r>s){E=null;return}let o=ZG(e),c=A(e,o).subarray(0,n*r);t.bindTexture(t.TEXTURE_2D,m),t.pixelStorei(t.UNPACK_ALIGNMENT,4),D.w===n&&D.h===r?t.texSubImage2D(t.TEXTURE_2D,0,0,0,n,r,t.RED,t.FLOAT,c):(t.texImage2D(t.TEXTURE_2D,0,t.R32F,n,r,0,t.RED,t.FLOAT,c),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),D={w:n,h:r}),E={w:n,h:r,origin:o,ext:[i[0],i[1],a[0],a[1]]}},setStyle(e){x?.palette!==e.palette&&(t.bindTexture(t.TEXTURE_2D,p),t.texImage2D(t.TEXTURE_2D,0,t.RGBA8,256,1,0,t.RGBA,t.UNSIGNED_BYTE,e.palette),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE)),x=e},render(){t.viewport(0,0,e.width,e.height),t.clearColor(0,0,0,0),t.clearDepth(1),t.clear(t.COLOR_BUFFER_BIT|t.DEPTH_BUFFER_BIT);let n=x;if(!n)return;t.bindVertexArray(c),t.enable(t.BLEND),t.blendFunc(t.ONE,t.ONE_MINUS_SRC_ALPHA),t.enable(t.DEPTH_TEST),t.depthFunc(t.LEQUAL),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,p),t.enable(t.POLYGON_OFFSET_FILL),t.polygonOffset(1,1);let r=n.wireColor;if(E){let e=o;t.useProgram(e.prog);let[i,a,s,c]=E.ext;j(e,[i,s,E.origin]),t.uniform4f(e.u.u_ext,0,a-i,0,c-s),t.activeTexture(t.TEXTURE1),t.bindTexture(t.TEXTURE_2D,m),t.uniform1i(e.u.u_z,1),t.uniform2i(e.u.u_n,E.w,E.h);let l=(E.w-1)*(E.h-1),u=Math.max(1,Math.ceil(Math.sqrt(l/JG))),d=Math.floor((E.w-2)/u)+1,f=Math.floor((E.h-2)/u)+1;if(t.uniform1i(e.u.u_step,u),t.uniform1f(e.u.u_alpha,n.fillAlpha),n.fill&&(t.uniform1i(e.u.u_wire,0),t.uniform4f(e.u.u_solid,0,0,0,0),t.drawArrays(t.TRIANGLES,0,d*f*6)),n.wire){let n=u*Math.max(1,Math.ceil(Math.max(d,f)/YG)),i=Math.floor((E.h-1)/n)+1,a=Math.floor((E.w-1)/n)+1;t.uniform1i(e.u.u_wire,1),t.uniform1i(e.u.u_wstep,n),t.uniform4f(e.u.u_solid,...r),t.drawArrays(t.LINES,0,(i*d+a*f)*2)}t.activeTexture(t.TEXTURE0)}if(S>0){if(w>0&&(n.fill||n.wire)){let e=a;t.useProgram(e.prog),j(e,C),M(e),t.uniform1f(e.u.u_alpha,n.fillAlpha),n.fill&&(t.uniform4f(e.u.u_solid,0,0,0,0),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,u),t.drawElements(t.TRIANGLES,w,t.UNSIGNED_INT,0)),n.wire&&(t.uniform4f(e.u.u_solid,...r),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,d),t.drawElements(t.LINES,T,t.UNSIGNED_INT,0))}let e=i;t.useProgram(e.prog),j(e,C),M(e);let o=Math.max(1,2*n.pointRadius*_);t.uniform1f(e.u.u_size,o),t.uniform1f(e.u.u_rim,o>=3?Math.max(.9,n.pointRadius*.3)*_:0),t.drawArrays(t.POINTS,0,S)}t.disable(t.POLYGON_OFFSET_FILL),t.disable(t.DEPTH_TEST),t.bindVertexArray(null)},dispose(){for(let e of[l.x,l.y,l.z,u,d])t.deleteBuffer(e);t.deleteTexture(p),t.deleteTexture(m),t.deleteVertexArray(c)}}}var $G=new Map;function eK(e,t){let n=$G.get(e);if(!n){let r=typeof OffscreenCanvas>`u`?null:new OffscreenCanvas(1,1).getContext(`2d`,{willReadFrequently:!0});if(!r)return[0,0,0,t];r.fillStyle=e,r.fillRect(0,0,1,1);let i=r.getImageData(0,0,1,1).data;$G.set(e,n=[i[0]/255,i[1]/255,i[2]/255,i[3]/255])}return[n[0],n[1],n[2],n[3]*t]}function tK(e,t){return{x:e.x-t.x,y:e.y-t.y,z:e.z-t.z}}function nK(e,t){return{x:e.y*t.z-e.z*t.y,y:e.z*t.x-e.x*t.z,z:e.x*t.y-e.y*t.x}}function rK(e,t){return e.x*t.x+e.y*t.y+e.z*t.z}function iK(e){return Math.sqrt(e.x*e.x+e.y*e.y+e.z*e.z)}function aK(e){let t=iK(e);return t>1e-12?{x:e.x/t,y:e.y/t,z:e.z/t}:{x:0,y:0,z:1}}function oK(e,t,n,r){let i=Math.cos(n),a=Math.sin(n),o=Math.cos(r),s=Math.sin(r);return{x:e.x+t*o*a,y:e.y+t*s,z:e.z+t*o*i}}function sK(e,t,n){let r=aK(tK(t,e)),i=aK(nK(r,n));return{right:i,up:nK(i,r),fwd:r,eye:e}}function cK(e,t,n,r,i){let a=tK(e,t.eye),o=rK(a,t.right),s=rK(a,t.up),c=rK(a,t.fwd);if(c<.01)return{sx:-9999,sy:-9999,depth:c};let l=1/Math.tan(n/2);return{sx:r/2+o/c*l*(i/2),sy:i/2-s/c*l*(i/2),depth:c}}function lK(e,t,n,r){let i=(e,t,n)=>{let r=n-t;return r<1e-12?0:(e-t)/r*2-1};return{x:i(e,r.minX,r.maxX),y:i(n,r.minZ,r.maxZ),z:i(t,r.minY,r.maxY)}}var uK=16,dK=.1,fK=Math.PI/4,pK=Math.PI/5,mK=3.2,hK=2e4,gK=(()=>{let e=new Uint8Array(256*4);for(let t=0;t<256;t++){let{r:n,g:r,b:i}=LW(t/255);e.set([n,r,i,255],t*4)}return e})();function _K(e){if(!Array.isArray(e))return e;let t=e.length,n=new Float64Array(t),r=new Float64Array(t),i=new Float64Array(t);for(let a=0;a<t;a++)n[a]=e[a].x,r[a]=e[a].y,i[a]=e[a].z;return{length:t,x:n,y:r,z:i}}var vK=(e,t)=>!t||e>=t[0]&&e<=t[1];function yK(e,t,n,r){let i=new Uint32Array(e.length),a=0;for(let o=0;o<e.length;o++){let s=e.x[o],c=e.y[o],l=e.z[o];s-s===0&&c-c===0&&l-l===0&&vK(s,t)&&vK(c,n)&&vK(l,r)&&(i[a++]=o)}if(a<3)return null;let o=new Float64Array(a*2);for(let t=0;t<a;t++)o[2*t]=e.x[i[t]],o[2*t+1]=e.y[i[t]];try{let e=new AG(o).triangles;for(let t=0;t<e.length;t++)e[t]=i[e[t]];return e.length>=3?e:null}catch{return null}}var bK=ot(function({points:e,surface:t,xLabel:n,yLabel:r,zLabel:i,height:a=500,backgroundToken:o=``,xRange:s,yRange:c,zRange:l,viewMode:u,pointRadius:d=4,alarms:f,showMesh:p=!1,meshStyle:m=`filled`,meshOpacity:h=.85,onPlotContextMenu:g},_){let v=K(g);G(()=>{v.current=g},[g]);let y=K(null),b=K(null),x=K(null),S=K(fK),C=K(pK),w=K(mK),T=K(null),E=K({xLabel:n,yLabel:r,zLabel:i,height:a,viewMode:u,pointRadius:d,alarms:f??[],showMesh:p,meshStyle:m,meshOpacity:h});G(()=>{E.current={xLabel:n,yLabel:r,zLabel:i,height:a,viewMode:u,pointRadius:d,alarms:f??[],showMesh:p,meshStyle:m,meshOpacity:h}},[n,r,i,a,u,d,f,p,m,h]);let D=ft(()=>{let n=_K(e),r=1/0,i=-1/0,a=1/0,o=-1/0,u=1/0,d=-1/0,f=0,p=0,m=0,h=0;for(let e=0;e<n.length;e++){let t=n.x[e],g=n.y[e],_=n.z[e];t-t!==0||g-g!==0||_-_!==0||!vK(t,s)||!vK(g,c)||!vK(_,l)||(t<r&&(r=t),t>i&&(i=t),g<a&&(a=g),g>o&&(o=g),_<u&&(u=_),_>d&&(d=_),f+=t,p+=g,m+=_,h++)}let g=null;if(t&&t.w>=2&&t.h>=2){let e=t.values,n=!1;for(let r=0;r<t.w*t.h;r++){let t=e[r];t-t===0&&(n=!0,t<u&&(u=t),t>d&&(d=t))}n&&(g=t,r=Math.min(r,t.x[0],t.x[1]),i=Math.max(i,t.x[0],t.x[1]),a=Math.min(a,t.y[0],t.y[1]),o=Math.max(o,t.y[0],t.y[1]))}if(h===0&&!g)return null;s&&(r=s[0],i=s[1]),c&&(a=c[0],o=c[1]),l&&(u=l[0],d=l[1]);let _={minX:r,maxX:i,minY:a,maxY:o,minZ:u,maxZ:d},v=h>0?lK(f/h,p/h,m/h,_):{x:0,y:0,z:0};return{cols:h>0?n:null,surface:g,bounds:_,center:v}},[e,t,s,c,l]),O=u??`3d`,k=p&&(O===`3d`||O===`xy`),A=ft(()=>k&&D?.cols?yK(D.cols,s,c,l):null,[k,D,s,c,l]),j=K({model:D,triangles:A});G(()=>{j.current={model:D,triangles:A}},[D,A]);let M=K({r:null,failed:!1,cols:null,surface:null,tris:null,size:``});function N(e,t,n){let r=M.current;!r.r&&!r.failed&&b.current&&(r.r=mH(b.current,QG),r.failed=!r.r);let i=r.r;if(!i||!b.current)return null;let a=`${e}x${t}@${n}`;r.size!==a&&(i.resize(e,t,n),b.current.style.width=`${e}px`,b.current.style.height=`${t}px`,r.size=a);let{model:o,triangles:s}=j.current,c=o?.cols??null;r.cols!==c&&(i.setPoints(c?.x??null,c?.y,c?.z),r.cols=c);let l=o?.surface??null;return r.surface!==l&&(i.setSurface(l?.values??null,l?.w,l?.h,l?.x,l?.y),r.surface=l),r.tris!==s&&(i.setTriangles(s),r.tris=s),i}W(()=>()=>{M.current.r?.dispose(),M.current.r=null},[]);let P=K(null);function F(){let e=y.current,t=x.current;if(!e||!t)return;let n=Math.max(1,t.clientWidth),r=Math.max(1,t.clientHeight),i=Math.min(2,window.devicePixelRatio||1),a=Math.floor(n*i),o=Math.floor(r*i);(e.width!==a||e.height!==o)&&(e.width=a,e.height=o);let s=e.getContext(`2d`);if(!s)return;s.setTransform(i,0,0,i,0,0);let{bg:c,muted:l,grid:u}=I(),{xLabel:d,yLabel:f,zLabel:p}=E.current,m=Math.max(.25,E.current.pointRadius??4),h=$W({top:0,right:0,bottom:0,left:0},n,r).tiny;s.fillStyle=c,s.fillRect(0,0,n,r);let g=j.current.model,_=N(n,r,i);if(!g){if(_?.setStyle({palette:gK,colorAxis:2,pointRadius:m,fill:!1,wire:!1,fillAlpha:1,wireColor:[0,0,0,0]}),_?.setPoints(null),M.current.cols=null,_?.render(),h)return;s.fillStyle=l,s.font=`13px ${Q.sans}`,zV(s);return}let v=g.bounds,b=E.current.viewMode??`3d`,T=b===`xz`?1:b===`yz`?0:2,D=[v.minX,v.minY,v.minZ][T],O=[v.maxX,v.maxY,v.maxZ][T],k=(e,t,n)=>{let r=T===0?e:T===1?t:n,i=O-D;return i>1e-12?(r-D)/i:.5},A,F,L,R=(e,t,r)=>{let i=n-28,a=t/32;for(let t=0;t<32;t++)s.fillStyle=RW(1-t/32),s.fillRect(i,e+t*a,14,a+1);s.strokeStyle=u,s.lineWidth=1,s.strokeRect(i,e,14,t),s.fillStyle=l,s.font=`9px ${Q.mono}`,s.textAlign=`right`,s.fillText(Fz(O),i-4,e+4),s.fillText(Fz(D),i-4,e+t),s.fillText(r,i-4,e-6)},z=e=>{s.fillStyle=l,s.font=`10px ${Q.sans}`,s.textAlign=`left`,s.globalAlpha=.7,s.fillText(e,uK,r-6),s.globalAlpha=1};if(b!==`3d`){let e,t,i,a,o,c,m,g,_;b===`xy`?(e=d,t=f,i=p,a=v.minX,o=v.maxX,c=v.minY,m=v.maxY,g=0,_=1):b===`xz`?(e=d,t=p,i=f,a=v.minX,o=v.maxX,c=v.minZ,m=v.maxZ,g=0,_=2):(e=f,t=p,i=d,a=v.minY,o=v.maxY,c=v.minZ,m=v.maxZ,g=1,_=2);let y=$W({left:72,right:48,top:24,bottom:52},n,r),x=Math.max(1,n-y.left-y.right),S=Math.max(1,r-y.top-y.bottom),C=o-a||1,w=m-c||1,T=e=>y.left+(e-a)/C*x,D=e=>y.top+S-(e-c)/w*S;A={left:y.left,top:y.top,width:x,height:S},L={kind:`2d`,h:g,v:_},F=(e,t,n)=>{let r=[e,t,n];return[T(r[g]),D(r[_])]};let O=Dz(C,8),k=Dz(w,8),j=Az(a,o,O),M=Az(c,m,k);s.strokeStyle=u,s.lineWidth=.5,s.globalAlpha=.3;for(let e of j){let t=T(e);s.beginPath(),s.moveTo(t,y.top),s.lineTo(t,y.top+S),s.stroke()}for(let e of M){let t=D(e);s.beginPath(),s.moveTo(y.left,t),s.lineTo(y.left+x,t),s.stroke()}s.globalAlpha=1,s.strokeStyle=u,s.lineWidth=1,s.strokeRect(y.left,y.top,x,S),s.save(),s.beginPath(),s.rect(y.left,y.top,x,S),s.clip();for(let e of E.current.alarms){let{axis:t,value:n,color:r,style:i,width:a}=e,o=null,c=null;b===`xy`?t===`x`?o=T(n):t===`y`&&(c=D(n)):b===`xz`?t===`x`?o=T(n):t===`z`&&(c=D(n)):t===`y`?o=T(n):t===`z`&&(c=D(n)),!(o===null&&c===null)&&(i===`dashed`?s.setLineDash([7,4]):i===`dotted`?s.setLineDash([2,4]):s.setLineDash([]),s.strokeStyle=r,s.lineWidth=a,s.globalAlpha=.9,s.beginPath(),o===null?c!==null&&(s.moveTo(y.left,c),s.lineTo(y.left+x,c)):(s.moveTo(o,y.top),s.lineTo(o,y.top+S)),s.stroke(),s.setLineDash([]),s.globalAlpha=1,s.fillStyle=r,s.font=`bold 10px ${Q.mono}`,s.globalAlpha=.95,o===null?c!==null&&(s.textAlign=`left`,s.textBaseline=`bottom`,s.fillText(Fz(n),y.left+3,c-2)):(s.textAlign=`left`,s.textBaseline=`top`,s.fillText(Fz(n),o+3,y.top+2)),s.globalAlpha=1,s.textBaseline=`alphabetic`)}if(s.restore(),!h){s.fillStyle=l,s.font=`10px ${Q.mono}`,s.textAlign=`center`,s.textBaseline=`top`;for(let e of j)s.fillText(Pz(e,O),T(e),y.top+S+6);s.textAlign=`right`,s.textBaseline=`middle`;for(let e of M)s.fillText(Pz(e,k),y.left-8,D(e));s.textBaseline=`alphabetic`,s.font=`bold 11px ${Q.mono}`,s.textAlign=`center`,s.fillStyle=`#fb7185`,s.fillText(e,y.left+x/2,r-8),s.save(),s.translate(14,y.top+S/2),s.rotate(-Math.PI/2),s.fillStyle=`#38bdf8`,s.textAlign=`center`,s.fillText(t,0,0),s.restore(),R(y.top+8,Math.min(S-20,180),i),z(`2D projection: ${b.toUpperCase()} plane · Color = ${i}`)}}else{let e=S.current,t=C.current,i=w.current,a=sK(oK(g.center,i,e,t),g.center,{x:0,y:1,z:0}),o=Math.PI/3,c=h?3:uK,m=Math.max(1,n-c*2),_=Math.max(1,r-c*2-(h?0:24));A={left:c,top:c,width:m,height:_};let y=e=>[e.x,e.y,e.z];L={kind:`3d`,eye:y(a.eye),right:y(a.right),up:y(a.up),fwd:y(a.fwd),f:1/Math.tan(o/2)};let b=e=>{let t=cK(e,a,o,m,_);return{sx:t.sx+c,sy:t.sy+c,depth:t.depth}};F=(e,t,n)=>{let r=b(lK(e,t,n,v));return r.depth<.02?null:[r.sx,r.sy]};let x=(e,t,n)=>{let r=b(e),i=b(t);r.depth<.02||i.depth<.02||(s.strokeStyle=n.color,s.lineWidth=n.width,s.globalAlpha=n.alpha??1,s.beginPath(),s.moveTo(r.sx,r.sy),s.lineTo(i.sx,i.sy),s.stroke(),s.globalAlpha=1)},T=Dz(v.maxX-v.minX,6),D=Dz(v.maxY-v.minY,6),O=Dz(v.maxZ-v.minZ,6),k=Az(v.minX,v.maxX,T),j=Az(v.minY,v.maxY,D),M=Az(v.minZ,v.maxZ,O),N=jz(v.minX,v.maxX,T/5,k),P=jz(v.minY,v.maxY,D/5,j),I=jz(v.minZ,v.maxZ,O/5,M);for(let[e,t]of[[{x:-1,y:-1,z:-1},{x:1,y:-1,z:-1}],[{x:1,y:-1,z:-1},{x:1,y:-1,z:1}],[{x:1,y:-1,z:1},{x:-1,y:-1,z:1}],[{x:-1,y:-1,z:1},{x:-1,y:-1,z:-1}],[{x:-1,y:1,z:-1},{x:1,y:1,z:-1}],[{x:1,y:1,z:-1},{x:1,y:1,z:1}],[{x:1,y:1,z:1},{x:-1,y:1,z:1}],[{x:-1,y:1,z:1},{x:-1,y:1,z:-1}],[{x:-1,y:-1,z:-1},{x:-1,y:1,z:-1}],[{x:1,y:-1,z:-1},{x:1,y:1,z:-1}],[{x:1,y:-1,z:1},{x:1,y:1,z:1}],[{x:-1,y:-1,z:1},{x:-1,y:1,z:1}]])x(e,t,{color:u,width:1,alpha:.65});if(!h){for(let e of k){let t=lK(e,v.minY,v.minZ,v).x;x({x:t,y:-1,z:-1},{x:t,y:-1,z:1},{color:u,width:.75,alpha:.45})}for(let e of j){let t=lK(v.minX,e,v.minZ,v).z;x({x:-1,y:-1,z:t},{x:1,y:-1,z:t},{color:u,width:.75,alpha:.45})}for(let e of P){let t=lK(v.minX,e,v.minZ,v).z;x({x:-1,y:-1,z:t},{x:1,y:-1,z:t},{color:u,width:.5,alpha:.22})}for(let e of N){let t=lK(e,v.minY,v.minZ,v).x;x({x:t,y:-1,z:-1},{x:t,y:-1,z:1},{color:u,width:.5,alpha:.22})}let e=(e,t)=>{let n=dK*(t?1:.55);x({x:e,y:-1,z:-1},{x:e,y:-1+n,z:-1},{color:`#fb7185`,width:t?1.25:.75,alpha:.95})},t=(e,t)=>{let n=dK*(t?1:.55);x({x:-1,y:-1,z:e},{x:-1+n,y:-1,z:e},{color:`#38bdf8`,width:t?1.25:.75,alpha:.95})},n=(e,t)=>{let n=dK*(t?1:.55);x({x:-1,y:e,z:-1},{x:-1+n,y:e,z:-1},{color:`#4ade80`,width:t?1.25:.75,alpha:.95})};for(let t of N)e(lK(t,v.minY,v.minZ,v).x,!1);for(let t of k)e(lK(t,v.minY,v.minZ,v).x,!0);for(let e of P)t(lK(v.minX,e,v.minZ,v).z,!1);for(let e of j)t(lK(v.minX,e,v.minZ,v).z,!0);for(let e of I)n(lK(v.minX,v.minY,e,v).y,!1);for(let e of M)n(lK(v.minX,v.minY,e,v).y,!0)}let B=(e,t,n)=>{let r=n-t;return r<1e-12?0:(e-t)/r*2-1};for(let e of E.current.alarms){let{axis:t,value:n,color:r,style:i,width:a}=e,o;if(t===`z`){let e=B(n,v.minZ,v.maxZ);o=[{x:-1,y:e,z:-1},{x:1,y:e,z:-1},{x:1,y:e,z:1},{x:-1,y:e,z:1}]}else if(t===`x`){let e=B(n,v.minX,v.maxX);o=[{x:e,y:-1,z:-1},{x:e,y:1,z:-1},{x:e,y:1,z:1},{x:e,y:-1,z:1}]}else{let e=B(n,v.minY,v.maxY);o=[{x:-1,y:-1,z:e},{x:1,y:-1,z:e},{x:1,y:1,z:e},{x:-1,y:1,z:e}]}let c=o.map(e=>b(e));if(c.every(e=>e.depth>=.02)){s.beginPath(),s.moveTo(c[0].sx,c[0].sy);for(let e=1;e<c.length;e++)s.lineTo(c[e].sx,c[e].sy);s.closePath(),s.fillStyle=r,s.globalAlpha=.18,s.fill(),i===`dashed`?s.setLineDash([7,4]):i===`dotted`?s.setLineDash([2,4]):s.setLineDash([]),s.strokeStyle=r,s.lineWidth=a,s.globalAlpha=.9,s.beginPath(),s.moveTo(c[0].sx,c[0].sy);for(let e=1;e<c.length;e++)s.lineTo(c[e].sx,c[e].sy);s.closePath(),s.stroke(),s.setLineDash([]),s.globalAlpha=1;let e=c.reduce((e,t)=>t.sy>e.sy?t:e);s.fillStyle=r,s.font=`bold 10px ${Q.mono}`,s.textAlign=`center`,s.globalAlpha=.95,s.fillText(`${t.toUpperCase()}=${Fz(n)}`,e.sx,e.sy-6),s.globalAlpha=1}}if(!h){s.font=`10px ${Q.mono}`,s.textBaseline=`middle`;for(let e of k){let t=lK(e,v.minY,v.minZ,v).x,n=b({x:t,y:-1.2,z:-1.2});n.depth<.02||(s.fillStyle=l,s.textAlign=`center`,s.fillText(Pz(e,T),n.sx,n.sy+12))}for(let e of j){let t=lK(v.minX,e,v.minZ,v).z,n=b({x:-1.22,y:-1,z:t});n.depth<.02||(s.textAlign=`right`,s.fillText(Pz(e,D),n.sx-4,n.sy))}for(let e of M){let t=lK(v.minX,v.minY,e,v).y,n=b({x:-1.22,y:t,z:-1.2});n.depth<.02||(s.textAlign=`right`,s.fillText(Pz(e,O),n.sx-4,n.sy))}s.textBaseline=`alphabetic`,s.font=`bold 11px ${Q.mono}`;let e=b({x:1.15,y:-1,z:-1.15});e.depth>=.02&&(s.fillStyle=`#fb7185`,s.textAlign=`center`,s.fillText(d,e.sx,e.sy+16)),e=b({x:-1.18,y:-1,z:1.15}),e.depth>=.02&&(s.fillStyle=`#38bdf8`,s.textAlign=`center`,s.fillText(f,e.sx-10,e.sy)),e=b({x:-1.18,y:1.15,z:-1.18}),e.depth>=.02&&(s.fillStyle=`#4ade80`,s.textAlign=`center`,s.fillText(p,e.sx-10,e.sy)),R(uK+8,Math.min(r-80,180),p),z(`Drag: rotate | Wheel: zoom | Dbl‑click: reset · ${g.surface?`Surface`:E.current.showMesh?`Mesh: ${E.current.meshStyle}`:`Scatter`} · color = Z`)}}let{showMesh:B,meshStyle:V,meshOpacity:ee}=E.current,te=!!g.surface||B;if(_)_.setBounds(v),_.setView(L,A),_.setStyle({palette:gK,colorAxis:T,pointRadius:m,fill:te&&(V===`filled`||V===`both`),wire:te&&(V===`wireframe`||V===`both`),fillAlpha:ee,wireColor:eK(u,.5)}),_.render(),P.current!==g&&(P.current=g,DH(t));else if(g.cols){let e=g.cols,t=Math.max(1,Math.ceil(e.length/hK));for(let n=0;n<e.length;n+=t){let t=e.x[n],r=e.y[n],i=e.z[n];if(!(t>=v.minX&&t<=v.maxX&&r>=v.minY&&r<=v.maxY&&i>=v.minZ&&i<=v.maxZ))continue;let a=F(t,r,i);a&&(s.fillStyle=RW(k(t,r,i)),s.beginPath(),s.arc(a[0],a[1],m,0,Math.PI*2),s.fill())}}}function I(){if(T.current)return T.current;let e=x.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return T.current=n,n}let L=K(F);G(()=>{L.current=F});let R=K(null);R.current??=jH(()=>L.current(),()=>x.current),W(()=>()=>R.current?.cancel(),[]);let z=()=>{S.current=fK,C.current=pK,w.current=mK,R.current.schedule()};return dt(_,()=>({autoscale:z}),[]),W(()=>rB(x.current,()=>{T.current=null,R.current.schedule()}),[]),W(()=>{T.current=null,R.current.schedule()},[o]),W(()=>{R.current.now()},[D,A,n,r,i,a,u,d,f,p,m,h]),W(()=>{let e=y.current,t=x.current;if(!e||!t)return;let n=()=>R.current.schedule(),r=new AH(()=>{T.current=null,n()});r.observe(t);let i=!1,a=0,o=0,s=t=>{t.button===0&&(i=!0,a=t.clientX,o=t.clientY,e.setPointerCapture(t.pointerId))},c=e=>{if(!i)return;let t=e.clientX-a,r=e.clientY-o;a=e.clientX,o=e.clientY,S.current-=t*.008,C.current+=r*.008,C.current=Math.max(-Math.PI/2+.05,Math.min(Math.PI/2-.05,C.current)),n()},l=()=>{i=!1},u=e=>{e.preventDefault();let t=e.deltaY>0?1.08:.92;w.current=Math.max(1.2,Math.min(12,w.current*t)),n()},d=()=>{S.current=fK,C.current=pK,w.current=mK,n()},f=e=>{e.preventDefault(),v.current?.({clientX:e.clientX,clientY:e.clientY})};return e.addEventListener(`pointerdown`,s),e.addEventListener(`pointermove`,c),e.addEventListener(`pointerup`,l),e.addEventListener(`pointercancel`,l),e.addEventListener(`wheel`,u,{passive:!1}),e.addEventListener(`contextmenu`,f),e.addEventListener(`dblclick`,d),()=>{r.disconnect(),e.removeEventListener(`pointerdown`,s),e.removeEventListener(`pointermove`,c),e.removeEventListener(`pointerup`,l),e.removeEventListener(`pointercancel`,l),e.removeEventListener(`wheel`,u),e.removeEventListener(`contextmenu`,f),e.removeEventListener(`dblclick`,d)}},[]),vt(`div`,{ref:x,className:`chart-canvas-wrap`,children:[q(`canvas`,{ref:y,className:`chart-canvas`,role:`img`,"aria-label":`3D scatter: ${n} vs ${r} vs ${i}`,style:{display:`block`,width:`100%`,height:`100%`,cursor:`grab`}}),q(`canvas`,{ref:b,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}})]})}),xK={top:14,right:24,bottom:40,left:64},SK=5;function CK(e){return e===`dashed`?[5,4]:e===`dotted`?[1,4]:[]}function wK(e){return Math.max(10,Math.min(200,Math.ceil(Math.sqrt(e))))}function TK(e,t,n){let r=(e-t)/n;return Math.exp(-.5*r*r)/(n*Math.sqrt(2*Math.PI))}function EK(e,t){let n=e.length;if(n===0)return null;let r=1/0,i=-1/0,a=0;for(let t=0;t<n;t++){let n=e[t];n<r&&(r=n),n>i&&(i=n),a+=n}r===i&&(--r,i+=1);let o=t>0?t:wK(n),s=(i-r)/o,c=Array(o).fill(0),l=a/n,u=0;for(let t=0;t<n;t++){let n=e[t];c[Math.min(o-1,Math.floor((n-r)/s))]++,u+=(n-l)**2}return{lo:r,hi:i,nBins:o,width:s,counts:c,mean:l,sd:Math.sqrt(u/n),total:n}}function DK({values:e,label:t,bins:n=0,color:r=`#38bdf8`,showNormal:i=!1,logY:a=!1,height:o=400,backgroundToken:s=``,onPlotContextMenu:c}){let l=oU(),u=K(null),d=K(null),f=K(null),p=K(null),m=K(0),h=K(null),g=K(c);G(()=>{g.current=c},[c]);let _=K({values:e,label:t,bins:n,color:r,showNormal:i,logY:a,height:o});G(()=>{_.current={values:e,label:t,bins:n,color:r,showNormal:i,logY:a,height:o}},[e,t,n,r,i,a,o]);function v(){if(h.current)return h.current;let e=f.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return h.current=n,n}function y(){let e=f.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||_.current.height)}}function b(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}let x=ft(()=>EK(e,n),[e,n]),S=K(x);G(()=>{S.current=x},[x]);let C=()=>S.current;function w(){let e=u.current;if(!e)return;let{w:t,h:n}=y(),r=b(e,t,n);if(!r)return;let{top:i,right:a,bottom:o,left:s}=xK,c=t-s-a,d=n-i-o,{bg:f,muted:p,grid:m}=v(),{label:h,color:g,showNormal:x,logY:S}=_.current;r.fillStyle=f,r.fillRect(0,0,t,n);let w=C();if(!w||c<=0||d<=0){r.fillStyle=p,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,zV(r);return}let{lo:T,hi:E,nBins:D,width:O,counts:k,mean:A,sd:j,total:M}=w,N=Math.max(...k),P=S?Math.log10(N+1)+.1:N*1.08,F=e=>s+(e-T)/(E-T)*c;l({left:s,top:i,width:c,height:d,x:{v0:T,v1:E}});let I=e=>i+(P-(S?e>0?Math.log10(e):0:e))/(P-0)*d,L=S?1:Dz(P,5),R=Az(0,S?P:N,L);r.strokeStyle=m,r.lineWidth=1,r.setLineDash(CK(`dashed`));for(let e of R){let t=I(e);r.beginPath(),r.moveTo(s,t),r.lineTo(s+c,t),r.stroke()}r.setLineDash([]);let z=Math.max(.5,c/D*.04);for(let e=0;e<D;e++){let t=F(T+e*O)+z/2,n=F(T+(e+1)*O)-z/2,i=I(0),a=I(k[e]);r.fillStyle=g,r.globalAlpha=.75,r.fillRect(t,a,n-t,i-a),r.globalAlpha=1}if(x&&j>0){r.beginPath();for(let e=0;e<=200;e++){let t=T+e/200*(E-T),n=TK(t,A,j)*M*O,i=F(t),a=I(n);e===0?r.moveTo(i,a):r.lineTo(i,a)}r.strokeStyle=`#f97316`,r.lineWidth=1,r.stroke()}r.strokeStyle=p,r.lineWidth=1,r.fillStyle=p,r.font=`11px ${Q.mono}`,r.textAlign=`right`,r.textBaseline=`middle`;for(let e of R){let t=I(e);r.beginPath(),r.moveTo(s-SK,t),r.lineTo(s,t),r.stroke(),r.fillText(S?`10^${e.toFixed(0)}`:Pz(e,L),s-4,t)}let B=Dz(E-T,Oz(c)),V=Az(T,E,B);r.fillStyle=p,r.textAlign=`center`,r.textBaseline=`top`;for(let e of V){let t=F(e);r.beginPath(),r.moveTo(t,i+d),r.lineTo(t,i+d+SK),r.stroke(),r.fillText(Pz(e,B),t,i+d+SK+2)}r.strokeStyle=m,r.lineWidth=1,r.strokeRect(s,i,c,d),r.fillStyle=p,r.font=`11px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`bottom`,r.fillText(h,s+c/2,n-4),r.save(),r.translate(14,i+d/2),r.rotate(-Math.PI/2),r.textAlign=`center`,r.textBaseline=`middle`,r.fillText(S?`log₁₀(count)`:`count`,0,0),r.restore()}let T=K(w);T.current=w;let E=K(null);E.current??=jH(()=>T.current(),()=>f.current);let D=()=>E.current.schedule();function O(e){let t=d.current;if(!t)return;let{w:n,h:r}=y(),i=b(t,n,r);if(!i||(i.clearRect(0,0,n,r),e===null))return;let{top:a,right:o,bottom:s,left:c}=xK,l=n-c-o,u=r-a-s,{muted:f}=v(),p=C();if(!p)return;let{lo:m,hi:h,width:g,counts:_}=p,x=e=>c+(e-m)/(h-m)*l,S=x(m+e*g),w=x(m+(e+1)*g);i.fillStyle=`rgba(255,255,255,0.12)`,i.fillRect(S,a,w-S,u);let T=(S+w)/2,E=_[e],D=(E/p.total*100).toFixed(1),O=`${Fz(m+e*g)} – ${Fz(m+(e+1)*g)}`,k=`n = ${E} (${D}%)`;i.font=`11px ${Q.mono}`;let A=i.measureText(k).width,j=i.measureText(O).width,M=Math.max(A,j),N=Math.min(T+8,c+l-M-8);i.fillStyle=f,i.textAlign=`left`,i.textBaseline=`top`,i.fillText(O,N,a+8),i.fillText(k,N,a+22)}function k(){TH(m.current),m.current=wH(()=>O(p.current))}return W(()=>{E.current.now()}),W(()=>()=>E.current?.cancel(),[]),W(()=>{h.current=null,D()},[s]),G(()=>{let e=f.current;if(!e)return;let t=new AH(()=>{h.current=null,D(),k()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=d.current;if(!e)return;function t(t){let n=e.getBoundingClientRect(),{left:r}=xK,i=n.width-xK.left-xK.right,a=C();if(!a||i<=0){p.current=null,k();return}let o=t.clientX-n.left-r,s=Math.floor(o/i*a.nBins);p.current=s>=0&&s<a.nBins?s:null,k()}function n(){p.current=null,k()}function r(e){e.preventDefault(),g.current?.({clientX:e.clientX,clientY:e.clientY})}return e.addEventListener(`mousemove`,t),e.addEventListener(`mouseleave`,n),e.addEventListener(`contextmenu`,r),()=>{e.removeEventListener(`mousemove`,t),e.removeEventListener(`mouseleave`,n),e.removeEventListener(`contextmenu`,r)}},[]),vt(`div`,{ref:f,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:u,className:`chart-canvas`,role:`img`,"aria-label":`Histogram of ${t}`}),q(`canvas`,{ref:d,className:`chart-canvas chart-overlay`})]})}var OK=`
|
|
484
|
+
}`,fK=16e6,pK=128,mK=[`u_lo`,`u_span`,`u_flat`,`u_eye`,`u_right`,`u_up`,`u_fwd`,`u_f`,`u_h`,`u_v`,`u_c`,`u_plot`,`u_resolution`,`u_palette`];function hK(e){for(let t=0;t<e.length;t++)if(e[t]===e[t]&&Math.abs(e[t])!==1/0)return e[t];return 0}function gK(e){let t=e.getContext(`webgl2`,{antialias:!0,alpha:!0,premultipliedAlpha:!0,depth:!0});if(!t)return null;let n=(e,n,r,i)=>oH(t,`gl3d|${e}|${n}`,()=>{let a=JV(t,t.VERTEX_SHADER,e),o=JV(t,t.FRAGMENT_SHADER,n);if(!a||!o)return null;let s=t.createProgram();return t.attachShader(s,a),t.attachShader(s,o),t.linkProgram(s),t.getProgramParameter(s,t.LINK_STATUS)?{prog:s,a:Object.fromEntries(r.map(e=>[e,t.getAttribLocation(s,e)])),u:Object.fromEntries([...mK,...i].map(e=>[e,t.getUniformLocation(s,e)]))}:(console.error(`gl3d program link failed:`,t.getProgramInfoLog(s)),null)}),r=[`a_x`,`a_y`,`a_z`],i=n(oK,sK,r,[`u_size`,`u_rim`]),a=n(cK,uK,r,[`u_alpha`,`u_solid`]),o=n(lK,dK,[],[`u_alpha`,`u_solid`,`u_z`,`u_n`,`u_step`,`u_wstep`,`u_wire`,`u_ext`]);if(!i||!a||!o)return null;let s=t.getParameter(t.MAX_TEXTURE_SIZE),c=t.createVertexArray(),l={x:t.createBuffer(),y:t.createBuffer(),z:t.createBuffer()},u=t.createBuffer(),d=t.createBuffer(),f=new Map,p=t.createTexture(),m=t.createTexture(),h=1,g=1,_=1,v={minX:0,maxX:1,minY:0,maxY:1,minZ:0,maxZ:1},y={kind:`2d`,h:0,v:1},b={left:0,top:0,width:1,height:1},x=null,S=0,C=[0,0,0],w=0,T=0,E=null,D={w:0,h:0},O=new Float32Array,k=(e,n,r)=>{t.bindBuffer(e,n),r.byteLength<=(f.get(n)??0)?t.bufferSubData(e,0,r):(t.bufferData(e,r,t.DYNAMIC_DRAW),f.set(n,r.byteLength))},A=(e,t)=>{let n=e.length;O.length<n&&(O=new Float32Array(n));for(let r=0;r<n;r++)O[r]=e[r]-t;return O.subarray(0,n)},j=(e,n)=>{let r=e.u,i=v;t.uniform3f(r.u_lo,i.minX-n[0],i.minY-n[1],i.minZ-n[2]);let a=(e,t)=>t-e>1e-12*Math.max(1,Math.abs(e))?t-e:0;t.uniform3f(r.u_span,a(i.minX,i.maxX),a(i.minY,i.maxY),a(i.minZ,i.maxZ));let o=e=>[+(e===0),+(e===1),+(e===2)];y.kind===`3d`?(t.uniform1i(r.u_flat,0),t.uniform3f(r.u_eye,...y.eye),t.uniform3f(r.u_right,...y.right),t.uniform3f(r.u_up,...y.up),t.uniform3f(r.u_fwd,...y.fwd),t.uniform1f(r.u_f,y.f)):(t.uniform1i(r.u_flat,1),t.uniform3f(r.u_h,...o(y.h)),t.uniform3f(r.u_v,...o(y.v))),t.uniform3f(r.u_c,...o(x.colorAxis)),t.uniform4f(r.u_plot,b.left,b.top,b.width,b.height),t.uniform2f(r.u_resolution,h,g),t.uniform1i(r.u_palette,0)},M=e=>{for(let n of[`x`,`y`,`z`]){let r=e.a[`a_${n}`];t.bindBuffer(t.ARRAY_BUFFER,l[n]),t.enableVertexAttribArray(r),t.vertexAttribPointer(r,1,t.FLOAT,!1,0,0)}};return{maxTextureSize:s,resize(t,n,r){h=Math.max(1,t),g=Math.max(1,n),_=r,e.width=Math.max(1,Math.round(h*_)),e.height=Math.max(1,Math.round(g*_))},setBounds(e){v=e},setView(e,t){y=e,b=t},setPoints(e,n,r){if(!e||!n||!r){S=0;return}S=Math.min(e.length,n.length,r.length),C=[hK(e),hK(n),hK(r)],k(t.ARRAY_BUFFER,l.x,A(e,C[0]).subarray(0,S)),k(t.ARRAY_BUFFER,l.y,A(n,C[1]).subarray(0,S)),k(t.ARRAY_BUFFER,l.z,A(r,C[2]).subarray(0,S))},setTriangles(e){if(!e||e.length<3){w=T=0;return}w=e.length-e.length%3,k(t.ELEMENT_ARRAY_BUFFER,u,e.subarray(0,w));let n=new Uint32Array(w*2);for(let t=0;t<w;t+=3){let r=e[t],i=e[t+1],a=e[t+2],o=t*2;n[o]=r,n[o+1]=i,n[o+2]=i,n[o+3]=a,n[o+4]=a,n[o+5]=r}T=n.length,k(t.ELEMENT_ARRAY_BUFFER,d,n)},setSurface(e,n=0,r=0,i=[0,1],a=[0,1]){if(!e||n<2||r<2||n>s||r>s){E=null;return}let o=hK(e),c=A(e,o).subarray(0,n*r);t.bindTexture(t.TEXTURE_2D,m),t.pixelStorei(t.UNPACK_ALIGNMENT,4),D.w===n&&D.h===r?t.texSubImage2D(t.TEXTURE_2D,0,0,0,n,r,t.RED,t.FLOAT,c):(t.texImage2D(t.TEXTURE_2D,0,t.R32F,n,r,0,t.RED,t.FLOAT,c),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),D={w:n,h:r}),E={w:n,h:r,origin:o,ext:[i[0],i[1],a[0],a[1]]}},setStyle(e){x?.palette!==e.palette&&(t.bindTexture(t.TEXTURE_2D,p),t.texImage2D(t.TEXTURE_2D,0,t.RGBA8,256,1,0,t.RGBA,t.UNSIGNED_BYTE,e.palette),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE)),x=e},render(){t.viewport(0,0,e.width,e.height),t.clearColor(0,0,0,0),t.clearDepth(1),t.clear(t.COLOR_BUFFER_BIT|t.DEPTH_BUFFER_BIT);let n=x;if(!n)return;t.bindVertexArray(c),t.enable(t.BLEND),t.blendFunc(t.ONE,t.ONE_MINUS_SRC_ALPHA),t.enable(t.DEPTH_TEST),t.depthFunc(t.LEQUAL),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,p),t.enable(t.POLYGON_OFFSET_FILL),t.polygonOffset(1,1);let r=n.wireColor;if(E){let e=o;t.useProgram(e.prog);let[i,a,s,c]=E.ext;j(e,[i,s,E.origin]),t.uniform4f(e.u.u_ext,0,a-i,0,c-s),t.activeTexture(t.TEXTURE1),t.bindTexture(t.TEXTURE_2D,m),t.uniform1i(e.u.u_z,1),t.uniform2i(e.u.u_n,E.w,E.h);let l=(E.w-1)*(E.h-1),u=Math.max(1,Math.ceil(Math.sqrt(l/fK))),d=Math.floor((E.w-2)/u)+1,f=Math.floor((E.h-2)/u)+1;if(t.uniform1i(e.u.u_step,u),t.uniform1f(e.u.u_alpha,n.fillAlpha),n.fill&&(t.uniform1i(e.u.u_wire,0),t.uniform4f(e.u.u_solid,0,0,0,0),t.drawArrays(t.TRIANGLES,0,d*f*6)),n.wire){let n=u*Math.max(1,Math.ceil(Math.max(d,f)/pK)),i=Math.floor((E.h-1)/n)+1,a=Math.floor((E.w-1)/n)+1;t.uniform1i(e.u.u_wire,1),t.uniform1i(e.u.u_wstep,n),t.uniform4f(e.u.u_solid,...r),t.drawArrays(t.LINES,0,(i*d+a*f)*2)}t.activeTexture(t.TEXTURE0)}if(S>0){if(w>0&&(n.fill||n.wire)){let e=a;t.useProgram(e.prog),j(e,C),M(e),t.uniform1f(e.u.u_alpha,n.fillAlpha),n.fill&&(t.uniform4f(e.u.u_solid,0,0,0,0),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,u),t.drawElements(t.TRIANGLES,w,t.UNSIGNED_INT,0)),n.wire&&(t.uniform4f(e.u.u_solid,...r),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,d),t.drawElements(t.LINES,T,t.UNSIGNED_INT,0))}let e=i;t.useProgram(e.prog),j(e,C),M(e);let o=Math.max(1,2*n.pointRadius*_);t.uniform1f(e.u.u_size,o),t.uniform1f(e.u.u_rim,o>=3?Math.max(.9,n.pointRadius*.3)*_:0),t.drawArrays(t.POINTS,0,S)}t.disable(t.POLYGON_OFFSET_FILL),t.disable(t.DEPTH_TEST),t.bindVertexArray(null)},dispose(){for(let e of[l.x,l.y,l.z,u,d])t.deleteBuffer(e);t.deleteTexture(p),t.deleteTexture(m),t.deleteVertexArray(c)}}}var _K=new Map;function vK(e,t){let n=_K.get(e);if(!n){let r=typeof OffscreenCanvas>`u`?null:new OffscreenCanvas(1,1).getContext(`2d`,{willReadFrequently:!0});if(!r)return[0,0,0,t];r.fillStyle=e,r.fillRect(0,0,1,1);let i=r.getImageData(0,0,1,1).data;_K.set(e,n=[i[0]/255,i[1]/255,i[2]/255,i[3]/255])}return[n[0],n[1],n[2],n[3]*t]}function yK(e,t){return{x:e.x-t.x,y:e.y-t.y,z:e.z-t.z}}function bK(e,t){return{x:e.y*t.z-e.z*t.y,y:e.z*t.x-e.x*t.z,z:e.x*t.y-e.y*t.x}}function xK(e,t){return e.x*t.x+e.y*t.y+e.z*t.z}function SK(e){return Math.sqrt(e.x*e.x+e.y*e.y+e.z*e.z)}function CK(e){let t=SK(e);return t>1e-12?{x:e.x/t,y:e.y/t,z:e.z/t}:{x:0,y:0,z:1}}function wK(e,t,n,r){let i=Math.cos(n),a=Math.sin(n),o=Math.cos(r),s=Math.sin(r);return{x:e.x+t*o*a,y:e.y+t*s,z:e.z+t*o*i}}function TK(e,t,n){let r=CK(yK(t,e)),i=CK(bK(r,n));return{right:i,up:bK(i,r),fwd:r,eye:e}}function EK(e,t,n,r,i){let a=yK(e,t.eye),o=xK(a,t.right),s=xK(a,t.up),c=xK(a,t.fwd);if(c<.01)return{sx:-9999,sy:-9999,depth:c};let l=1/Math.tan(n/2);return{sx:r/2+o/c*l*(i/2),sy:i/2-s/c*l*(i/2),depth:c}}function DK(e,t,n,r){let i=(e,t,n)=>{let r=n-t;return r<1e-12?0:(e-t)/r*2-1};return{x:i(e,r.minX,r.maxX),y:i(n,r.minZ,r.maxZ),z:i(t,r.minY,r.maxY)}}var OK=16,kK=.1,AK=Math.PI/4,jK=Math.PI/5,MK=3.2,NK=2e4,PK=(()=>{let e=new Uint8Array(256*4);for(let t=0;t<256;t++){let{r:n,g:r,b:i}=$W(t/255);e.set([n,r,i,255],t*4)}return e})();function FK(e){if(!Array.isArray(e))return e;let t=e.length,n=new Float64Array(t),r=new Float64Array(t),i=new Float64Array(t);for(let a=0;a<t;a++)n[a]=e[a].x,r[a]=e[a].y,i[a]=e[a].z;return{length:t,x:n,y:r,z:i}}var IK=(e,t)=>!t||e>=t[0]&&e<=t[1];function LK(e,t,n,r){let i=new Uint32Array(e.length),a=0;for(let o=0;o<e.length;o++){let s=e.x[o],c=e.y[o],l=e.z[o];s-s===0&&c-c===0&&l-l===0&&IK(s,t)&&IK(c,n)&&IK(l,r)&&(i[a++]=o)}if(a<3)return null;let o=new Float64Array(a*2);for(let t=0;t<a;t++)o[2*t]=e.x[i[t]],o[2*t+1]=e.y[i[t]];try{let e=new JG(o).triangles;for(let t=0;t<e.length;t++)e[t]=i[e[t]];return e.length>=3?e:null}catch{return null}}var RK=ot(function({points:e,surface:t,xLabel:n,yLabel:r,zLabel:i,height:a=500,backgroundToken:o=``,xRange:s,yRange:c,zRange:l,viewMode:u,pointRadius:d=4,alarms:f,showMesh:p=!1,meshStyle:m=`filled`,meshOpacity:h=.85,onPlotContextMenu:g},_){let v=K(g);G(()=>{v.current=g},[g]);let y=K(null),b=K(null),x=K(null),S=K(AK),C=K(jK),w=K(MK),T=K(null),E=K({xLabel:n,yLabel:r,zLabel:i,height:a,viewMode:u,pointRadius:d,alarms:f??[],showMesh:p,meshStyle:m,meshOpacity:h});G(()=>{E.current={xLabel:n,yLabel:r,zLabel:i,height:a,viewMode:u,pointRadius:d,alarms:f??[],showMesh:p,meshStyle:m,meshOpacity:h}},[n,r,i,a,u,d,f,p,m,h]);let D=ft(()=>{let n=FK(e),r=1/0,i=-1/0,a=1/0,o=-1/0,u=1/0,d=-1/0,f=0,p=0,m=0,h=0;for(let e=0;e<n.length;e++){let t=n.x[e],g=n.y[e],_=n.z[e];t-t!==0||g-g!==0||_-_!==0||!IK(t,s)||!IK(g,c)||!IK(_,l)||(t<r&&(r=t),t>i&&(i=t),g<a&&(a=g),g>o&&(o=g),_<u&&(u=_),_>d&&(d=_),f+=t,p+=g,m+=_,h++)}let g=null;if(t&&t.w>=2&&t.h>=2){let e=t.values,n=!1;for(let r=0;r<t.w*t.h;r++){let t=e[r];t-t===0&&(n=!0,t<u&&(u=t),t>d&&(d=t))}n&&(g=t,r=Math.min(r,t.x[0],t.x[1]),i=Math.max(i,t.x[0],t.x[1]),a=Math.min(a,t.y[0],t.y[1]),o=Math.max(o,t.y[0],t.y[1]))}if(h===0&&!g)return null;s&&(r=s[0],i=s[1]),c&&(a=c[0],o=c[1]),l&&(u=l[0],d=l[1]);let _={minX:r,maxX:i,minY:a,maxY:o,minZ:u,maxZ:d},v=h>0?DK(f/h,p/h,m/h,_):{x:0,y:0,z:0};return{cols:h>0?n:null,surface:g,bounds:_,center:v}},[e,t,s,c,l]),O=u??`3d`,k=p&&(O===`3d`||O===`xy`),A=ft(()=>k&&D?.cols?LK(D.cols,s,c,l):null,[k,D,s,c,l]),j=K({model:D,triangles:A});G(()=>{j.current={model:D,triangles:A}},[D,A]);let M=K({r:null,failed:!1,cols:null,surface:null,tris:null,size:``});function N(e,t,n){let r=M.current;!r.r&&!r.failed&&b.current&&(r.r=sH(b.current,gK),r.failed=!r.r);let i=r.r;if(!i||!b.current)return null;let a=`${e}x${t}@${n}`;r.size!==a&&(i.resize(e,t,n),b.current.style.width=`${e}px`,b.current.style.height=`${t}px`,r.size=a);let{model:o,triangles:s}=j.current,c=o?.cols??null;r.cols!==c&&(i.setPoints(c?.x??null,c?.y,c?.z),r.cols=c);let l=o?.surface??null;return r.surface!==l&&(i.setSurface(l?.values??null,l?.w,l?.h,l?.x,l?.y),r.surface=l),r.tris!==s&&(i.setTriangles(s),r.tris=s),i}W(()=>()=>{M.current.r?.dispose(),M.current.r=null},[]);let P=K(null);function F(){let e=y.current,t=x.current;if(!e||!t)return;let n=Math.max(1,t.clientWidth),r=Math.max(1,t.clientHeight),i=Math.min(2,window.devicePixelRatio||1),a=Math.floor(n*i),o=Math.floor(r*i);(e.width!==a||e.height!==o)&&(e.width=a,e.height=o);let s=e.getContext(`2d`);if(!s)return;s.setTransform(i,0,0,i,0,0);let{bg:c,muted:l,grid:u}=I(),{xLabel:d,yLabel:f,zLabel:p}=E.current,m=Math.max(.25,E.current.pointRadius??4),h=_G({top:0,right:0,bottom:0,left:0},n,r).tiny;s.fillStyle=c,s.fillRect(0,0,n,r);let g=j.current.model,_=N(n,r,i);if(!g){if(_?.setStyle({palette:PK,colorAxis:2,pointRadius:m,fill:!1,wire:!1,fillAlpha:1,wireColor:[0,0,0,0]}),_?.setPoints(null),M.current.cols=null,_?.render(),h)return;s.fillStyle=l,s.font=`13px ${Q.sans}`,zV(s);return}let v=g.bounds,b=E.current.viewMode??`3d`,T=b===`xz`?1:b===`yz`?0:2,D=[v.minX,v.minY,v.minZ][T],O=[v.maxX,v.maxY,v.maxZ][T],k=(e,t,n)=>{let r=T===0?e:T===1?t:n,i=O-D;return i>1e-12?(r-D)/i:.5},A,F,L,R=(e,t,r)=>{let i=n-28,a=t/32;for(let t=0;t<32;t++)s.fillStyle=eG(1-t/32),s.fillRect(i,e+t*a,14,a+1);s.strokeStyle=u,s.lineWidth=1,s.strokeRect(i,e,14,t),s.fillStyle=l,s.font=`9px ${Q.mono}`,s.textAlign=`right`,s.fillText(Fz(O),i-4,e+4),s.fillText(Fz(D),i-4,e+t),s.fillText(r,i-4,e-6)},z=e=>{s.fillStyle=l,s.font=`10px ${Q.sans}`,s.textAlign=`left`,s.globalAlpha=.7,s.fillText(e,OK,r-6),s.globalAlpha=1};if(b!==`3d`){let e,t,i,a,o,c,m,g,_;b===`xy`?(e=d,t=f,i=p,a=v.minX,o=v.maxX,c=v.minY,m=v.maxY,g=0,_=1):b===`xz`?(e=d,t=p,i=f,a=v.minX,o=v.maxX,c=v.minZ,m=v.maxZ,g=0,_=2):(e=f,t=p,i=d,a=v.minY,o=v.maxY,c=v.minZ,m=v.maxZ,g=1,_=2);let y=_G({left:72,right:48,top:24,bottom:52},n,r),x=Math.max(1,n-y.left-y.right),S=Math.max(1,r-y.top-y.bottom),C=o-a||1,w=m-c||1,T=e=>y.left+(e-a)/C*x,D=e=>y.top+S-(e-c)/w*S;A={left:y.left,top:y.top,width:x,height:S},L={kind:`2d`,h:g,v:_},F=(e,t,n)=>{let r=[e,t,n];return[T(r[g]),D(r[_])]};let O=Dz(C,8),k=Dz(w,8),j=Az(a,o,O),M=Az(c,m,k);s.strokeStyle=u,s.lineWidth=.5,s.globalAlpha=.3;for(let e of j){let t=T(e);s.beginPath(),s.moveTo(t,y.top),s.lineTo(t,y.top+S),s.stroke()}for(let e of M){let t=D(e);s.beginPath(),s.moveTo(y.left,t),s.lineTo(y.left+x,t),s.stroke()}s.globalAlpha=1,s.strokeStyle=u,s.lineWidth=1,s.strokeRect(y.left,y.top,x,S),s.save(),s.beginPath(),s.rect(y.left,y.top,x,S),s.clip();for(let e of E.current.alarms){let{axis:t,value:n,color:r,style:i,width:a}=e,o=null,c=null;b===`xy`?t===`x`?o=T(n):t===`y`&&(c=D(n)):b===`xz`?t===`x`?o=T(n):t===`z`&&(c=D(n)):t===`y`?o=T(n):t===`z`&&(c=D(n)),!(o===null&&c===null)&&(i===`dashed`?s.setLineDash([7,4]):i===`dotted`?s.setLineDash([2,4]):s.setLineDash([]),s.strokeStyle=r,s.lineWidth=a,s.globalAlpha=.9,s.beginPath(),o===null?c!==null&&(s.moveTo(y.left,c),s.lineTo(y.left+x,c)):(s.moveTo(o,y.top),s.lineTo(o,y.top+S)),s.stroke(),s.setLineDash([]),s.globalAlpha=1,s.fillStyle=r,s.font=`bold 10px ${Q.mono}`,s.globalAlpha=.95,o===null?c!==null&&(s.textAlign=`left`,s.textBaseline=`bottom`,s.fillText(Fz(n),y.left+3,c-2)):(s.textAlign=`left`,s.textBaseline=`top`,s.fillText(Fz(n),o+3,y.top+2)),s.globalAlpha=1,s.textBaseline=`alphabetic`)}if(s.restore(),!h){s.fillStyle=l,s.font=`10px ${Q.mono}`,s.textAlign=`center`,s.textBaseline=`top`;for(let e of j)s.fillText(Pz(e,O),T(e),y.top+S+6);s.textAlign=`right`,s.textBaseline=`middle`;for(let e of M)s.fillText(Pz(e,k),y.left-8,D(e));s.textBaseline=`alphabetic`,s.font=`bold 11px ${Q.mono}`,s.textAlign=`center`,s.fillStyle=`#fb7185`,s.fillText(e,y.left+x/2,r-8),s.save(),s.translate(14,y.top+S/2),s.rotate(-Math.PI/2),s.fillStyle=`#38bdf8`,s.textAlign=`center`,s.fillText(t,0,0),s.restore(),R(y.top+8,Math.min(S-20,180),i),z(`2D projection: ${b.toUpperCase()} plane · Color = ${i}`)}}else{let e=S.current,t=C.current,i=w.current,a=TK(wK(g.center,i,e,t),g.center,{x:0,y:1,z:0}),o=Math.PI/3,c=h?3:OK,m=Math.max(1,n-c*2),_=Math.max(1,r-c*2-(h?0:24));A={left:c,top:c,width:m,height:_};let y=e=>[e.x,e.y,e.z];L={kind:`3d`,eye:y(a.eye),right:y(a.right),up:y(a.up),fwd:y(a.fwd),f:1/Math.tan(o/2)};let b=e=>{let t=EK(e,a,o,m,_);return{sx:t.sx+c,sy:t.sy+c,depth:t.depth}};F=(e,t,n)=>{let r=b(DK(e,t,n,v));return r.depth<.02?null:[r.sx,r.sy]};let x=(e,t,n)=>{let r=b(e),i=b(t);r.depth<.02||i.depth<.02||(s.strokeStyle=n.color,s.lineWidth=n.width,s.globalAlpha=n.alpha??1,s.beginPath(),s.moveTo(r.sx,r.sy),s.lineTo(i.sx,i.sy),s.stroke(),s.globalAlpha=1)},T=Dz(v.maxX-v.minX,6),D=Dz(v.maxY-v.minY,6),O=Dz(v.maxZ-v.minZ,6),k=Az(v.minX,v.maxX,T),j=Az(v.minY,v.maxY,D),M=Az(v.minZ,v.maxZ,O),N=jz(v.minX,v.maxX,T/5,k),P=jz(v.minY,v.maxY,D/5,j),I=jz(v.minZ,v.maxZ,O/5,M);for(let[e,t]of[[{x:-1,y:-1,z:-1},{x:1,y:-1,z:-1}],[{x:1,y:-1,z:-1},{x:1,y:-1,z:1}],[{x:1,y:-1,z:1},{x:-1,y:-1,z:1}],[{x:-1,y:-1,z:1},{x:-1,y:-1,z:-1}],[{x:-1,y:1,z:-1},{x:1,y:1,z:-1}],[{x:1,y:1,z:-1},{x:1,y:1,z:1}],[{x:1,y:1,z:1},{x:-1,y:1,z:1}],[{x:-1,y:1,z:1},{x:-1,y:1,z:-1}],[{x:-1,y:-1,z:-1},{x:-1,y:1,z:-1}],[{x:1,y:-1,z:-1},{x:1,y:1,z:-1}],[{x:1,y:-1,z:1},{x:1,y:1,z:1}],[{x:-1,y:-1,z:1},{x:-1,y:1,z:1}]])x(e,t,{color:u,width:1,alpha:.65});if(!h){for(let e of k){let t=DK(e,v.minY,v.minZ,v).x;x({x:t,y:-1,z:-1},{x:t,y:-1,z:1},{color:u,width:.75,alpha:.45})}for(let e of j){let t=DK(v.minX,e,v.minZ,v).z;x({x:-1,y:-1,z:t},{x:1,y:-1,z:t},{color:u,width:.75,alpha:.45})}for(let e of P){let t=DK(v.minX,e,v.minZ,v).z;x({x:-1,y:-1,z:t},{x:1,y:-1,z:t},{color:u,width:.5,alpha:.22})}for(let e of N){let t=DK(e,v.minY,v.minZ,v).x;x({x:t,y:-1,z:-1},{x:t,y:-1,z:1},{color:u,width:.5,alpha:.22})}let e=(e,t)=>{let n=kK*(t?1:.55);x({x:e,y:-1,z:-1},{x:e,y:-1+n,z:-1},{color:`#fb7185`,width:t?1.25:.75,alpha:.95})},t=(e,t)=>{let n=kK*(t?1:.55);x({x:-1,y:-1,z:e},{x:-1+n,y:-1,z:e},{color:`#38bdf8`,width:t?1.25:.75,alpha:.95})},n=(e,t)=>{let n=kK*(t?1:.55);x({x:-1,y:e,z:-1},{x:-1+n,y:e,z:-1},{color:`#4ade80`,width:t?1.25:.75,alpha:.95})};for(let t of N)e(DK(t,v.minY,v.minZ,v).x,!1);for(let t of k)e(DK(t,v.minY,v.minZ,v).x,!0);for(let e of P)t(DK(v.minX,e,v.minZ,v).z,!1);for(let e of j)t(DK(v.minX,e,v.minZ,v).z,!0);for(let e of I)n(DK(v.minX,v.minY,e,v).y,!1);for(let e of M)n(DK(v.minX,v.minY,e,v).y,!0)}let B=(e,t,n)=>{let r=n-t;return r<1e-12?0:(e-t)/r*2-1};for(let e of E.current.alarms){let{axis:t,value:n,color:r,style:i,width:a}=e,o;if(t===`z`){let e=B(n,v.minZ,v.maxZ);o=[{x:-1,y:e,z:-1},{x:1,y:e,z:-1},{x:1,y:e,z:1},{x:-1,y:e,z:1}]}else if(t===`x`){let e=B(n,v.minX,v.maxX);o=[{x:e,y:-1,z:-1},{x:e,y:1,z:-1},{x:e,y:1,z:1},{x:e,y:-1,z:1}]}else{let e=B(n,v.minY,v.maxY);o=[{x:-1,y:-1,z:e},{x:1,y:-1,z:e},{x:1,y:1,z:e},{x:-1,y:1,z:e}]}let c=o.map(e=>b(e));if(c.every(e=>e.depth>=.02)){s.beginPath(),s.moveTo(c[0].sx,c[0].sy);for(let e=1;e<c.length;e++)s.lineTo(c[e].sx,c[e].sy);s.closePath(),s.fillStyle=r,s.globalAlpha=.18,s.fill(),i===`dashed`?s.setLineDash([7,4]):i===`dotted`?s.setLineDash([2,4]):s.setLineDash([]),s.strokeStyle=r,s.lineWidth=a,s.globalAlpha=.9,s.beginPath(),s.moveTo(c[0].sx,c[0].sy);for(let e=1;e<c.length;e++)s.lineTo(c[e].sx,c[e].sy);s.closePath(),s.stroke(),s.setLineDash([]),s.globalAlpha=1;let e=c.reduce((e,t)=>t.sy>e.sy?t:e);s.fillStyle=r,s.font=`bold 10px ${Q.mono}`,s.textAlign=`center`,s.globalAlpha=.95,s.fillText(`${t.toUpperCase()}=${Fz(n)}`,e.sx,e.sy-6),s.globalAlpha=1}}if(!h){s.font=`10px ${Q.mono}`,s.textBaseline=`middle`;for(let e of k){let t=DK(e,v.minY,v.minZ,v).x,n=b({x:t,y:-1.2,z:-1.2});n.depth<.02||(s.fillStyle=l,s.textAlign=`center`,s.fillText(Pz(e,T),n.sx,n.sy+12))}for(let e of j){let t=DK(v.minX,e,v.minZ,v).z,n=b({x:-1.22,y:-1,z:t});n.depth<.02||(s.textAlign=`right`,s.fillText(Pz(e,D),n.sx-4,n.sy))}for(let e of M){let t=DK(v.minX,v.minY,e,v).y,n=b({x:-1.22,y:t,z:-1.2});n.depth<.02||(s.textAlign=`right`,s.fillText(Pz(e,O),n.sx-4,n.sy))}s.textBaseline=`alphabetic`,s.font=`bold 11px ${Q.mono}`;let e=b({x:1.15,y:-1,z:-1.15});e.depth>=.02&&(s.fillStyle=`#fb7185`,s.textAlign=`center`,s.fillText(d,e.sx,e.sy+16)),e=b({x:-1.18,y:-1,z:1.15}),e.depth>=.02&&(s.fillStyle=`#38bdf8`,s.textAlign=`center`,s.fillText(f,e.sx-10,e.sy)),e=b({x:-1.18,y:1.15,z:-1.18}),e.depth>=.02&&(s.fillStyle=`#4ade80`,s.textAlign=`center`,s.fillText(p,e.sx-10,e.sy)),R(OK+8,Math.min(r-80,180),p),z(`Drag: rotate | Wheel: zoom | Dbl‑click: reset · ${g.surface?`Surface`:E.current.showMesh?`Mesh: ${E.current.meshStyle}`:`Scatter`} · color = Z`)}}let{showMesh:B,meshStyle:V,meshOpacity:ee}=E.current,te=!!g.surface||B;if(_)_.setBounds(v),_.setView(L,A),_.setStyle({palette:PK,colorAxis:T,pointRadius:m,fill:te&&(V===`filled`||V===`both`),wire:te&&(V===`wireframe`||V===`both`),fillAlpha:ee,wireColor:vK(u,.5)}),_.render(),P.current!==g&&(P.current=g,IH(t));else if(g.cols){let e=g.cols,t=Math.max(1,Math.ceil(e.length/NK));for(let n=0;n<e.length;n+=t){let t=e.x[n],r=e.y[n],i=e.z[n];if(!(t>=v.minX&&t<=v.maxX&&r>=v.minY&&r<=v.maxY&&i>=v.minZ&&i<=v.maxZ))continue;let a=F(t,r,i);a&&(s.fillStyle=eG(k(t,r,i)),s.beginPath(),s.arc(a[0],a[1],m,0,Math.PI*2),s.fill())}}}function I(){if(T.current)return T.current;let e=x.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return T.current=n,n}let L=K(F);G(()=>{L.current=F});let R=K(null);R.current??=VH(()=>L.current(),()=>x.current),W(()=>()=>R.current?.cancel(),[]);let z=()=>{S.current=AK,C.current=jK,w.current=MK,R.current.schedule()};return dt(_,()=>({autoscale:z}),[]),W(()=>rB(x.current,()=>{T.current=null,R.current.schedule()}),[]),W(()=>{T.current=null,R.current.schedule()},[o]),W(()=>{R.current.now()},[D,A,n,r,i,a,u,d,f,p,m,h]),W(()=>{let e=y.current,t=x.current;if(!e||!t)return;let n=()=>R.current.schedule(),r=new zH(()=>{T.current=null,n()});r.observe(t);let i=!1,a=0,o=0,s=t=>{t.button===0&&(i=!0,a=t.clientX,o=t.clientY,e.setPointerCapture(t.pointerId))},c=e=>{if(!i)return;let t=e.clientX-a,r=e.clientY-o;a=e.clientX,o=e.clientY,S.current-=t*.008,C.current+=r*.008,C.current=Math.max(-Math.PI/2+.05,Math.min(Math.PI/2-.05,C.current)),n()},l=()=>{i=!1},u=e=>{e.preventDefault();let t=e.deltaY>0?1.08:.92;w.current=Math.max(1.2,Math.min(12,w.current*t)),n()},d=()=>{S.current=AK,C.current=jK,w.current=MK,n()},f=e=>{e.preventDefault(),v.current?.({clientX:e.clientX,clientY:e.clientY})};return e.addEventListener(`pointerdown`,s),e.addEventListener(`pointermove`,c),e.addEventListener(`pointerup`,l),e.addEventListener(`pointercancel`,l),e.addEventListener(`wheel`,u,{passive:!1}),e.addEventListener(`contextmenu`,f),e.addEventListener(`dblclick`,d),()=>{r.disconnect(),e.removeEventListener(`pointerdown`,s),e.removeEventListener(`pointermove`,c),e.removeEventListener(`pointerup`,l),e.removeEventListener(`pointercancel`,l),e.removeEventListener(`wheel`,u),e.removeEventListener(`contextmenu`,f),e.removeEventListener(`dblclick`,d)}},[]),vt(`div`,{ref:x,className:`chart-canvas-wrap`,children:[q(`canvas`,{ref:y,className:`chart-canvas`,role:`img`,"aria-label":`3D scatter: ${n} vs ${r} vs ${i}`,style:{display:`block`,width:`100%`,height:`100%`,cursor:`grab`}}),q(`canvas`,{ref:b,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}})]})}),zK={top:14,right:24,bottom:40,left:64},BK=5;function VK(e){return e===`dashed`?[5,4]:e===`dotted`?[1,4]:[]}function HK(e){return Math.max(10,Math.min(200,Math.ceil(Math.sqrt(e))))}function UK(e,t,n){let r=(e-t)/n;return Math.exp(-.5*r*r)/(n*Math.sqrt(2*Math.PI))}function WK(e,t){let n=e.length;if(n===0)return null;let r=1/0,i=-1/0,a=0;for(let t=0;t<n;t++){let n=e[t];n<r&&(r=n),n>i&&(i=n),a+=n}r===i&&(--r,i+=1);let o=t>0?t:HK(n),s=(i-r)/o,c=Array(o).fill(0),l=a/n,u=0;for(let t=0;t<n;t++){let n=e[t];c[Math.min(o-1,Math.floor((n-r)/s))]++,u+=(n-l)**2}return{lo:r,hi:i,nBins:o,width:s,counts:c,mean:l,sd:Math.sqrt(u/n),total:n}}function GK({values:e,label:t,bins:n=0,color:r=`#38bdf8`,showNormal:i=!1,logY:a=!1,height:o=400,backgroundToken:s=``,onPlotContextMenu:c}){let l=SU(),u=K(null),d=K(null),f=K(null),p=K(null),m=K(0),h=K(null),g=K(c);G(()=>{g.current=c},[c]);let _=K({values:e,label:t,bins:n,color:r,showNormal:i,logY:a,height:o});G(()=>{_.current={values:e,label:t,bins:n,color:r,showNormal:i,logY:a,height:o}},[e,t,n,r,i,a,o]);function v(){if(h.current)return h.current;let e=f.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return h.current=n,n}function y(){let e=f.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||_.current.height)}}function b(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}let x=ft(()=>WK(e,n),[e,n]),S=K(x);G(()=>{S.current=x},[x]);let C=()=>S.current;function w(){let e=u.current;if(!e)return;let{w:t,h:n}=y(),r=b(e,t,n);if(!r)return;let{top:i,right:a,bottom:o,left:s}=zK,c=t-s-a,d=n-i-o,{bg:f,muted:p,grid:m}=v(),{label:h,color:g,showNormal:x,logY:S}=_.current;r.fillStyle=f,r.fillRect(0,0,t,n);let w=C();if(!w||c<=0||d<=0){r.fillStyle=p,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,zV(r);return}let{lo:T,hi:E,nBins:D,width:O,counts:k,mean:A,sd:j,total:M}=w,N=Math.max(...k),P=S?Math.log10(N+1)+.1:N*1.08,F=e=>s+(e-T)/(E-T)*c;l({left:s,top:i,width:c,height:d,x:{v0:T,v1:E}});let I=e=>i+(P-(S?e>0?Math.log10(e):0:e))/(P-0)*d,L=S?1:Dz(P,5),R=Az(0,S?P:N,L);r.strokeStyle=m,r.lineWidth=1,r.setLineDash(VK(`dashed`));for(let e of R){let t=I(e);r.beginPath(),r.moveTo(s,t),r.lineTo(s+c,t),r.stroke()}r.setLineDash([]);let z=Math.max(.5,c/D*.04);for(let e=0;e<D;e++){let t=F(T+e*O)+z/2,n=F(T+(e+1)*O)-z/2,i=I(0),a=I(k[e]);r.fillStyle=g,r.globalAlpha=.75,r.fillRect(t,a,n-t,i-a),r.globalAlpha=1}if(x&&j>0){r.beginPath();for(let e=0;e<=200;e++){let t=T+e/200*(E-T),n=UK(t,A,j)*M*O,i=F(t),a=I(n);e===0?r.moveTo(i,a):r.lineTo(i,a)}r.strokeStyle=`#f97316`,r.lineWidth=1,r.stroke()}r.strokeStyle=p,r.lineWidth=1,r.fillStyle=p,r.font=`11px ${Q.mono}`,r.textAlign=`right`,r.textBaseline=`middle`;for(let e of R){let t=I(e);r.beginPath(),r.moveTo(s-BK,t),r.lineTo(s,t),r.stroke(),r.fillText(S?`10^${e.toFixed(0)}`:Pz(e,L),s-4,t)}let B=Dz(E-T,Oz(c)),V=Az(T,E,B);r.fillStyle=p,r.textAlign=`center`,r.textBaseline=`top`;for(let e of V){let t=F(e);r.beginPath(),r.moveTo(t,i+d),r.lineTo(t,i+d+BK),r.stroke(),r.fillText(Pz(e,B),t,i+d+BK+2)}r.strokeStyle=m,r.lineWidth=1,r.strokeRect(s,i,c,d),r.fillStyle=p,r.font=`11px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`bottom`,r.fillText(h,s+c/2,n-4),r.save(),r.translate(14,i+d/2),r.rotate(-Math.PI/2),r.textAlign=`center`,r.textBaseline=`middle`,r.fillText(S?`log₁₀(count)`:`count`,0,0),r.restore()}let T=K(w);T.current=w;let E=K(null);E.current??=VH(()=>T.current(),()=>f.current);let D=()=>E.current.schedule();function O(e){let t=d.current;if(!t)return;let{w:n,h:r}=y(),i=b(t,n,r);if(!i||(i.clearRect(0,0,n,r),e===null))return;let{top:a,right:o,bottom:s,left:c}=zK,l=n-c-o,u=r-a-s,{muted:f}=v(),p=C();if(!p)return;let{lo:m,hi:h,width:g,counts:_}=p,x=e=>c+(e-m)/(h-m)*l,S=x(m+e*g),w=x(m+(e+1)*g);i.fillStyle=`rgba(255,255,255,0.12)`,i.fillRect(S,a,w-S,u);let T=(S+w)/2,E=_[e],D=(E/p.total*100).toFixed(1),O=`${Fz(m+e*g)} – ${Fz(m+(e+1)*g)}`,k=`n = ${E} (${D}%)`;i.font=`11px ${Q.mono}`;let A=i.measureText(k).width,j=i.measureText(O).width,M=Math.max(A,j),N=Math.min(T+8,c+l-M-8);i.fillStyle=f,i.textAlign=`left`,i.textBaseline=`top`,i.fillText(O,N,a+8),i.fillText(k,N,a+22)}function k(){PH(m.current),m.current=NH(()=>O(p.current))}return W(()=>{E.current.now()}),W(()=>()=>E.current?.cancel(),[]),W(()=>{h.current=null,D()},[s]),G(()=>{let e=f.current;if(!e)return;let t=new zH(()=>{h.current=null,D(),k()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=d.current;if(!e)return;function t(t){let n=e.getBoundingClientRect(),{left:r}=zK,i=n.width-zK.left-zK.right,a=C();if(!a||i<=0){p.current=null,k();return}let o=t.clientX-n.left-r,s=Math.floor(o/i*a.nBins);p.current=s>=0&&s<a.nBins?s:null,k()}function n(){p.current=null,k()}function r(e){e.preventDefault(),g.current?.({clientX:e.clientX,clientY:e.clientY})}return e.addEventListener(`mousemove`,t),e.addEventListener(`mouseleave`,n),e.addEventListener(`contextmenu`,r),()=>{e.removeEventListener(`mousemove`,t),e.removeEventListener(`mouseleave`,n),e.removeEventListener(`contextmenu`,r)}},[]),vt(`div`,{ref:f,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:u,className:`chart-canvas`,role:`img`,"aria-label":`Histogram of ${t}`}),q(`canvas`,{ref:d,className:`chart-canvas chart-overlay`})]})}var KK=`
|
|
485
485
|
uniform vec2 u_resolution;
|
|
486
486
|
uniform vec4 u_plot; // left, top, width, height (CSS px)
|
|
487
487
|
uniform vec4 u_view; // xmin, xmax, ymin, ymax (relative to the layer origin)
|
|
@@ -490,7 +490,7 @@ vec2 project(float x, float y) {
|
|
|
490
490
|
u_plot.y + (u_view.w - y) / (u_view.w - u_view.z) * u_plot.w);
|
|
491
491
|
}
|
|
492
492
|
vec4 toClip(vec2 p) { vec2 c = p / u_resolution * 2.0 - 1.0; return vec4(c.x, -c.y, 0.0, 1.0); }
|
|
493
|
-
`,
|
|
493
|
+
`,qK=`
|
|
494
494
|
uniform vec4 u_clip; // left, top, right, bottom (CSS px)
|
|
495
495
|
uniform float u_dpr;
|
|
496
496
|
uniform float u_height; // canvas height (device px)
|
|
@@ -498,23 +498,23 @@ bool outside() {
|
|
|
498
498
|
vec2 f = vec2(gl_FragCoord.x, u_height - gl_FragCoord.y) / u_dpr;
|
|
499
499
|
return f.x < u_clip.x || f.x > u_clip.z || f.y < u_clip.y || f.y > u_clip.w;
|
|
500
500
|
}
|
|
501
|
-
`,
|
|
501
|
+
`,JK=`#version 300 es
|
|
502
502
|
in vec2 a_corner; // (0|1 along x, 0 = lo | 1 = hi)
|
|
503
503
|
in float a_xa; in float a_xb;
|
|
504
504
|
in float a_loa; in float a_lob;
|
|
505
505
|
in float a_hia; in float a_hib;
|
|
506
506
|
in float a_bstart;
|
|
507
|
-
${
|
|
507
|
+
${KK}
|
|
508
508
|
void main() {
|
|
509
509
|
if (a_bstart > 0.5) { gl_Position = vec4(2.0, 2.0, 2.0, 1.0); return; }
|
|
510
510
|
float x = a_corner.x < 0.5 ? a_xa : a_xb;
|
|
511
511
|
float lo = a_corner.x < 0.5 ? a_loa : a_lob;
|
|
512
512
|
float hi = a_corner.x < 0.5 ? a_hia : a_hib;
|
|
513
513
|
gl_Position = toClip(project(x, a_corner.y < 0.5 ? lo : hi));
|
|
514
|
-
}`,
|
|
514
|
+
}`,YK=`#version 300 es
|
|
515
515
|
in vec2 a_corner; // (0|1, 0|1)
|
|
516
516
|
in float a_x0; in float a_x1; in float a_y0; in float a_y1; in float a_k;
|
|
517
|
-
${
|
|
517
|
+
${KK}
|
|
518
518
|
flat out float v_k;
|
|
519
519
|
void main() {
|
|
520
520
|
vec2 p0 = project(a_x0, a_y0), p1 = project(a_x1, a_y1);
|
|
@@ -524,29 +524,29 @@ void main() {
|
|
|
524
524
|
vec2 half_ = max((hi - lo) * 0.5, vec2(0.5));
|
|
525
525
|
v_k = a_k;
|
|
526
526
|
gl_Position = toClip(c + (a_corner * 2.0 - 1.0) * half_);
|
|
527
|
-
}`,
|
|
527
|
+
}`,XK=`#version 300 es
|
|
528
528
|
precision highp float;
|
|
529
529
|
uniform vec4 u_color;
|
|
530
|
-
${
|
|
530
|
+
${qK}
|
|
531
531
|
out vec4 outColor;
|
|
532
532
|
void main() {
|
|
533
533
|
if (outside()) discard;
|
|
534
534
|
outColor = vec4(u_color.rgb * u_color.a, u_color.a);
|
|
535
|
-
}`,
|
|
535
|
+
}`,ZK=`#version 300 es
|
|
536
536
|
precision highp float;
|
|
537
537
|
flat in float v_k;
|
|
538
538
|
uniform sampler2D u_palette;
|
|
539
|
-
${
|
|
539
|
+
${qK}
|
|
540
540
|
out vec4 outColor;
|
|
541
541
|
void main() {
|
|
542
542
|
if (outside()) discard;
|
|
543
543
|
vec4 c = texture(u_palette, vec2((v_k + 0.5) / 256.0, 0.5));
|
|
544
544
|
outColor = vec4(c.rgb * c.a, c.a);
|
|
545
|
-
}`,
|
|
545
|
+
}`,QK=`#version 300 es
|
|
546
546
|
in vec2 a_corner;
|
|
547
547
|
in float a_ax; in float a_ay; in float a_bx; in float a_by;
|
|
548
548
|
in float a_bstart;
|
|
549
|
-
${
|
|
549
|
+
${KK}
|
|
550
550
|
uniform float u_ext;
|
|
551
551
|
flat out vec2 v_a;
|
|
552
552
|
flat out vec2 v_b;
|
|
@@ -562,14 +562,14 @@ void main() {
|
|
|
562
562
|
vec2 pos = base + dir * (a_corner.x * u_ext) + n * (a_corner.y * u_ext);
|
|
563
563
|
v_a = a; v_b = b; v_pos = pos;
|
|
564
564
|
gl_Position = toClip(pos);
|
|
565
|
-
}
|
|
565
|
+
}`,$K=`#version 300 es
|
|
566
566
|
precision highp float;
|
|
567
567
|
flat in vec2 v_a;
|
|
568
568
|
flat in vec2 v_b;
|
|
569
569
|
in vec2 v_pos;
|
|
570
570
|
uniform vec4 u_color;
|
|
571
571
|
uniform float u_half;
|
|
572
|
-
${
|
|
572
|
+
${qK}
|
|
573
573
|
out vec4 outColor;
|
|
574
574
|
void main() {
|
|
575
575
|
if (outside()) discard;
|
|
@@ -581,21 +581,21 @@ void main() {
|
|
|
581
581
|
if (cov <= 0.0) discard;
|
|
582
582
|
float a = u_color.a * cov;
|
|
583
583
|
outColor = vec4(u_color.rgb * a, a);
|
|
584
|
-
}`,
|
|
584
|
+
}`,eq=`#version 300 es
|
|
585
585
|
in vec2 a_corner; // (0|1, 0|1)
|
|
586
586
|
uniform vec4 u_extent; // x0, x1, y0, y1 (relative to the layer origin)
|
|
587
|
-
${
|
|
587
|
+
${KK}
|
|
588
588
|
out vec2 v_uv;
|
|
589
589
|
void main() {
|
|
590
590
|
v_uv = a_corner;
|
|
591
591
|
gl_Position = toClip(project(mix(u_extent.x, u_extent.y, a_corner.x), mix(u_extent.z, u_extent.w, a_corner.y)));
|
|
592
|
-
}`,
|
|
592
|
+
}`,tq=`#version 300 es
|
|
593
593
|
precision highp float;
|
|
594
594
|
in vec2 v_uv;
|
|
595
595
|
uniform highp sampler2D u_values;
|
|
596
596
|
uniform sampler2D u_palette;
|
|
597
597
|
uniform vec2 u_range; // vmin, vmax
|
|
598
|
-
${
|
|
598
|
+
${qK}
|
|
599
599
|
out vec4 outColor;
|
|
600
600
|
void main() {
|
|
601
601
|
if (outside()) discard;
|
|
@@ -604,21 +604,21 @@ void main() {
|
|
|
604
604
|
float t = u_range.y > u_range.x ? clamp((v - u_range.x) / (u_range.y - u_range.x), 0.0, 1.0) : 0.5;
|
|
605
605
|
vec4 c = texture(u_palette, vec2((floor(t * 255.0) + 0.5) / 256.0, 0.5));
|
|
606
606
|
outColor = vec4(c.rgb * c.a, c.a);
|
|
607
|
-
}`,RK=-3e38;function zK(e){for(let t=0;t<e.length;t++)if(e[t]-e[t]===0)return e[t];return 0}function BK(e){let t=e.getContext(`webgl2`,{antialias:!1,alpha:!0,premultipliedAlpha:!0});if(!t)return null;let n=(e,n,i,a)=>pH(t,`glPlot|${e}|${n}`,()=>r(e,n,i,a)),r=(e,n,r,i)=>{let a=JV(t,t.VERTEX_SHADER,e),o=JV(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(AK,MK,[`a_xa`,`a_xb`,`a_loa`,`a_lob`,`a_hia`,`a_hib`,`a_bstart`],[`u_color`]),a=n(jK,NK,[`a_x0`,`a_x1`,`a_y0`,`a_y1`,`a_k`],[`u_palette`]),o=n(PK,FK,[`a_ax`,`a_ay`,`a_bx`,`a_by`,`a_bstart`],[`u_color`,`u_half`,`u_ext`]),s=n(IK,LK,[],[`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=zK(t),o.oy=zK(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=zK(n),c.oy=zK(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=zK(t),o.oy=zK(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:RK}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 VK(e){let t=K({plot:null,failed:!1,size:``});return W(()=>()=>{t.current.plot?.dispose(),t.current.plot=null},[]),lt((n,r)=>{let i=t.current,a=e.current;if(!i.plot&&!i.failed&&a&&(i.plot=mH(a,BK),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 HK(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 UK=16;function WK(e,t,n,r){let i=HK(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(UK),m=new Int32Array(UK);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(UK-1,Math.floor(a/(2*Math.PI)*UK));p[o]+=t[e],m[o]++}return{n:a,rMin:c,rMax:l,x:d,y:f,means:Array.from({length:UK},(e,t)=>m[t]>0?p[t]/m[t]:0)}}function GK({angles:e,radii:t,angleLabel:n,radiusLabel:r,color:i=`#a78bfa`,mode:a=`waveform`,radiusMin:o,radiusMax:s,height:c=400,backgroundToken:l=``,onPlotContextMenu:u}){let d=K(null),f=K(null),p=K(null),m=K(u);G(()=>{m.current=u},[u]);let h=K({angles:e,radii:t,angleLabel:n,radiusLabel:r,color:i,mode:a,radiusMin:o,radiusMax:s,height:c});G(()=>{h.current={angles:e,radii:t,angleLabel:n,radiusLabel:r,color:i,mode:a,radiusMin:o,radiusMax:s,height:c}},[e,t,n,r,i,a,o,s,c]);let g=ft(()=>WK(e,t,o,s),[e,t,o,s]),_=K(g);G(()=>{_.current=g},[g]);let v=K(null),y=VK(v),b=K({geo:null,color:``});function x(){if(p.current)return p.current;let e=f.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return p.current=n,n}function S(){let e=f.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||h.current.height)}}function C(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function w(){let e=d.current;if(!e)return;let{w:t,h:n}=S(),r=C(e,t,n);if(!r)return;let{bg:i,muted:a,grid:o}=x(),{angleLabel:s,radiusLabel:c,color:l,mode:u}=h.current,f=_.current,{n:p,rMin:m,rMax:g}=f;r.fillStyle=i,r.fillRect(0,0,t,n);let v=y(t,n);if(p===0){v?.keep([]),v?.render(),r.fillStyle=a,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,zV(r);return}let w=g-m||1,T=(Math.min(t-64,n-32-24)-4)/2,E=t/2,D=32+T,O=Dz(w,4),k=Az(m,g,O);r.strokeStyle=o,r.lineWidth=1,r.setLineDash([3,3]);for(let e of k){let t=(e-m)/w*T;t<0||(r.beginPath(),r.arc(E,D,t,0,Math.PI*2),r.stroke())}r.setLineDash([]),r.strokeStyle=o,r.lineWidth=1;for(let e=0;e<360;e+=30){let t=e*Math.PI/180;r.beginPath(),r.moveTo(E,D),r.lineTo(E+Math.cos(-t+Math.PI/2)*T,D+Math.sin(-t+Math.PI/2)*T),r.stroke()}r.fillStyle=a,r.font=`10px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`middle`;for(let e=0;e<360;e+=30){let t=e*Math.PI/180,n=E+Math.sin(t)*(T+14),i=D-Math.cos(t)*(T+14);r.fillText(`${e}°`,n,i)}r.textAlign=`left`,r.textBaseline=`middle`;for(let e of k){let t=(e-m)/w*T;t<4||r.fillText(Pz(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,eK(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/UK;r.fillStyle=l,r.globalAlpha=.75;for(let i=0;i<UK;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<UK;i++){let a=e[i]/t*T,o=i*n-Math.PI/2-n/2;r.beginPath(),r.moveTo(E,D),r.arc(E,D,a,o,o+n),r.closePath(),r.stroke()}r.globalAlpha=1}r.restore(),r.fillStyle=a,r.font=`11px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`bottom`,r.fillText(`${s} / ${c}`,E,n-4)}let T=K(w);T.current=w;let E=K(null);E.current??=jH(()=>T.current(),()=>f.current);let D=()=>E.current.schedule();return W(()=>{E.current.now()}),W(()=>()=>E.current?.cancel(),[]),W(()=>{p.current=null,D()},[l]),G(()=>{let e=f.current;if(!e)return;let t=new AH(()=>{p.current=null,D()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=d.current;if(!e)return;let t=e=>{e.preventDefault(),m.current?.({clientX:e.clientX,clientY:e.clientY})};return e.addEventListener(`contextmenu`,t),()=>e.removeEventListener(`contextmenu`,t)},[]),vt(`div`,{ref:f,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:d,className:`chart-canvas`,role:`img`,"aria-label":`Polar chart: ${n} vs ${r}`}),q(`canvas`,{ref:v,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}})]})}function KK(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 qK(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 JK(e,t){let n=new Float64Array(t.length);for(let r=0;r<t.length;r++)n[r]=e[t[r]];return n}function YK(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 XK(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 ZK=new Float64Array,QK=new Float64Array;function $K(e,t,n){let r=t>>1;ZK.length<r&&(ZK=new Float64Array(r),QK=new Float64Array(r));let i=ZK.subarray(0,r),a=QK.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}XK(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 eq=new Float64Array,tq=0;function nq(e){if(tq===e)return eq.subarray(0,e);eq.length<e&&(eq=new Float64Array(Math.max(e,eq.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++){eq[t]=.5*(1-i);let e=i*n-a*r;a=a*n+i*r,i=e}return tq=e,eq.subarray(0,e)}var rq={top:14,right:24,bottom:40,left:64},iq=5;function aq(e){let t=1;for(;t<e;)t<<=1;return t}function oq(e,t,n,r){let i=e.length,a=Math.max(2,aq(i)),o=$K(e,a,n===`hann`?nq(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 sq({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=oU(),f=K(null),p=K(null),m=K(null),h=K(u);G(()=>{h.current=u},[u]);let g=K({signal:e,sampleRate:t,label:n,xMode:r,yMode:i,window:a,color:o,logX:s,height:c});G(()=>{g.current={signal:e,sampleRate:t,label:n,xMode:r,yMode:i,window:a,color:o,logX:s,height:c}},[e,t,n,r,i,a,o,s,c]);let _=ft(()=>e.length>=4?oq(e,t,a,i):null,[e,t,a,i]),v=ft(()=>_&&s?_.freqs.map(e=>Math.log10(e)):null,[_,s]),y=K(_&&{..._,logFreqs:v});G(()=>{y.current=_&&{..._,logFreqs:v}},[_,v]);function b(){if(m.current)return m.current;let e=p.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return m.current=n,n}function x(){let e=p.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||g.current.height)}}function S(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function C(){let e=f.current;if(!e)return;let{w:t,h:n}=x(),r=S(e,t,n);if(!r)return;let{top:i,right:a,bottom:o,left:s}=rq,c=t-s-a,l=n-i-o,{bg:u,muted:p,grid:m}=b(),{sampleRate:h,label:_,xMode:v,yMode:C,color:w,logX:T}=g.current,E=y.current;if(r.fillStyle=u,r.fillRect(0,0,t,n),!E||c<=0||l<=0){r.fillStyle=p,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,zV(r);return}let{freqs:D,amps:O,logFreqs:k}=E,A=D.length,j=v===`hz`?`${_} (Hz)`:`${_} (order)`,M=v===`order`&&h>0?h:1,N=D[1]/M,P=D[A-1]/M,F=1/0,I=-1/0;for(let e=1;e<A;e++)O[e]<F&&(F=O[e]),O[e]>I&&(I=O[e]);if(!Number.isFinite(F)||!Number.isFinite(I)){r.fillStyle=p,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,zV(r);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=Dz(I-F,5),V=Az(F,I,B);r.strokeStyle=m,r.lineWidth=1,r.setLineDash([3,3]);for(let e of V)r.beginPath(),r.moveTo(s,z(e)),r.lineTo(s+c,z(e)),r.stroke();r.setLineDash([]);let ee=T?1:Dz(P-N,Oz(c)),te=T?(()=>{let e=[],t=Math.ceil(Math.log10(Math.max(N,1e-12))),n=Math.floor(Math.log10(P));for(let r=t;r<=n;r++)for(let t of[1,2,5]){let n=t*10**r;n>=N&&n<=P&&e.push(n)}return e})():Az(N,P,ee);r.strokeStyle=m,r.lineWidth=1,r.setLineDash([3,3]);for(let e of te)r.beginPath(),r.moveTo(R(e),i),r.lineTo(R(e),i+l),r.stroke();r.setLineDash([]),r.strokeStyle=p,r.lineWidth=1,r.fillStyle=p,r.font=`11px ${Q.mono}`,r.textAlign=`right`,r.textBaseline=`middle`;for(let e of V)r.beginPath(),r.moveTo(s-iq,z(e)),r.lineTo(s,z(e)),r.stroke(),r.fillText(Pz(e,B),s-4,z(e));r.textAlign=`center`,r.textBaseline=`top`;for(let e of te)r.beginPath(),r.moveTo(R(e),i+l),r.lineTo(R(e),i+l+iq),r.stroke(),r.fillText(Pz(e,T?e:ee),R(e),i+l+iq+2);r.strokeStyle=m,r.lineWidth=1,r.strokeRect(s,i,c,l),r.save(),r.beginPath(),r.rect(s,i,c,l),r.clip(),r.strokeStyle=w,r.lineWidth=1,r.beginPath();let H=!1,ne=Math.min(2,window.devicePixelRatio||1),re=Math.max(1,Math.round(c*ne)),ie=A>re*4?T&&k?KK(k,O,Math.log10(N*M),Math.log10(P*M),re):KK(D,O,N*M,P*M,re):null;for(let e=+!ie;e<(ie?ie.length:A);e++){let t=ie?ie[e]:e;if(t<1)continue;let n=D[t]/M;if(n<N||n>P)continue;let i=R(n),a=z(O[t]);H?r.lineTo(i,a):(r.moveTo(i,a),H=!0)}r.stroke(),r.restore(),r.fillStyle=p,r.font=`11px ${Q.mono}`,r.save(),r.translate(14,i+l/2),r.rotate(-Math.PI/2),r.textAlign=`center`,r.textBaseline=`middle`,r.fillText(C===`db`?`dB`:`Amplitude`,0,0),r.restore(),r.textAlign=`center`,r.textBaseline=`bottom`,r.fillText(j,s+c/2,n-4)}let w=K(C);w.current=C;let T=K(null);T.current??=jH(()=>w.current(),()=>p.current);let E=()=>T.current.schedule();return W(()=>{T.current.now()}),W(()=>()=>T.current?.cancel(),[]),W(()=>{m.current=null,E()},[l]),G(()=>{let e=p.current;if(!e)return;let t=new AH(()=>{m.current=null,E()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=f.current;if(!e)return;let t=e=>{e.preventDefault(),h.current?.({clientX:e.clientX,clientY:e.clientY})};return e.addEventListener(`contextmenu`,t),()=>e.removeEventListener(`contextmenu`,t)},[]),q(`div`,{ref:p,style:{position:`relative`,width:`100%`,height:`100%`},children:q(`canvas`,{ref:f,className:`chart-canvas`,role:`img`,"aria-label":`Spectrum of ${n}`})})}function cq(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 lq(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,cq(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 uq={top:14,right:24,bottom:48,left:64},dq=5;function fq(e,t){let n=e.length;if(n===0)return null;let[r,i,a,o,s]=lq(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 pq({groups:e,color:t=`#fb923c`,whiskers:n=`1.5iqr`,height:r=400,backgroundToken:i=``,onPlotContextMenu:a}){let o=oU(),s=K(null),c=K(null),l=K(null),u=K(a);G(()=>{u.current=a},[a]);let d=K({groups:e,color:t,whiskers:n,height:r});G(()=>{d.current={groups:e,color:t,whiskers:n,height:r}},[e,t,n,r]);let f=ft(()=>e.filter(e=>e.values.length>0).map(e=>({label:e.label,box:fq(e.values,n)})),[e,n]),p=K(f);G(()=>{p.current=f},[f]);function m(){if(l.current)return l.current;let e=c.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return l.current=n,n}function h(){let e=c.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||d.current.height)}}function g(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function _(){let e=s.current;if(!e)return;let{w:t,h:n}=h(),r=g(e,t,n);if(!r)return;let{top:i,right:a,bottom:c,left:l}=uq,u=t-l-a,f=n-i-c,{bg:_,muted:v,grid:y}=m(),{color:b}=d.current;r.fillStyle=_,r.fillRect(0,0,t,n);let x=p.current;if(x.length===0||u<=0||f<=0){r.fillStyle=v,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,zV(r);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=Dz(C-S,5),D=Az(S,C,E);r.strokeStyle=y,r.lineWidth=1,r.setLineDash([3,3]);for(let e of D)r.beginPath(),r.moveTo(l,T(e)),r.lineTo(l+u,T(e)),r.stroke();r.setLineDash([]),r.strokeStyle=v,r.lineWidth=1,r.fillStyle=v,r.font=`11px ${Q.mono}`,r.textAlign=`right`,r.textBaseline=`middle`;for(let e of D)r.beginPath(),r.moveTo(l-dq,T(e)),r.lineTo(l,T(e)),r.stroke(),r.fillText(Pz(e,E),l-4,T(e));r.strokeStyle=y,r.lineWidth=1,r.strokeRect(l,i,u,f),r.save(),r.beginPath(),r.rect(l,i,u,f),r.clip();let O=x.length,k=u/O,A=Math.min(k*.55,60);for(let e=0;e<O;e++){let{box:t}=x[e],n=l+k*e+k/2;r.strokeStyle=b,r.lineWidth=1.5,r.beginPath(),r.moveTo(n,T(t.whiskerLo)),r.lineTo(n,T(t.whiskerHi)),r.stroke();let i=A*.35;r.beginPath(),r.moveTo(n-i,T(t.whiskerLo)),r.lineTo(n+i,T(t.whiskerLo)),r.moveTo(n-i,T(t.whiskerHi)),r.lineTo(n+i,T(t.whiskerHi)),r.stroke();let a=n-A/2,o=T(t.q3),s=Math.max(1,T(t.q1)-o);r.fillStyle=b,r.globalAlpha=.25,r.fillRect(a,o,A,s),r.globalAlpha=1,r.strokeStyle=b,r.lineWidth=1.5,r.strokeRect(a,o,A,s),r.strokeStyle=b,r.lineWidth=2.5,r.beginPath(),r.moveTo(a,T(t.median)),r.lineTo(a+A,T(t.median)),r.stroke();let c=T(t.mean);r.fillStyle=b,r.beginPath(),r.moveTo(n,c-5),r.lineTo(n+5,c),r.lineTo(n,c+5),r.lineTo(n-5,c),r.closePath(),r.fill(),r.fillStyle=b,r.globalAlpha=.6;let u=NaN;for(let e of t.outliers){let t=T(e);Math.abs(t-u)<.5||(u=t,r.beginPath(),r.arc(n,t,2.5,0,Math.PI*2),r.fill())}r.globalAlpha=1}r.restore(),r.fillStyle=v,r.font=`11px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`top`;for(let e=0;e<O;e++){let t=l+k*e+k/2,n=x[e].label;r.save(),r.rect(l+k*e+2,i+f+dq+2,k-4,c-dq-4),r.clip(),r.fillText(n,t,i+f+dq+2),r.restore()}}let v=K(_);v.current=_;let y=K(null);y.current??=jH(()=>v.current(),()=>c.current);let b=()=>y.current.schedule();return W(()=>{y.current.now()}),W(()=>()=>y.current?.cancel(),[]),W(()=>{l.current=null,b()},[i]),G(()=>{let e=c.current;if(!e)return;let t=new AH(()=>{l.current=null,b()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=s.current;if(!e)return;let t=e=>{e.preventDefault(),u.current?.({clientX:e.clientX,clientY:e.clientY})};return e.addEventListener(`contextmenu`,t),()=>e.removeEventListener(`contextmenu`,t)},[]),q(`div`,{ref:c,style:{position:`relative`,width:`100%`,height:`100%`},children:q(`canvas`,{ref:s,className:`chart-canvas`,role:`img`,"aria-label":`Box plot`})})}function mq(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 hq=e=>e.includes(`.`)&&!e.includes(`e`)?e.replace(/\.?0+$/,``):e;function gq(e){return e>=1e3?`${hq((e/1e3).toPrecision(3))}k`:hq(e.toPrecision(3))}function _q(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 vq={top:14,right:24,bottom:40,left:68},yq=[[8,0,16],[48,0,96],[104,0,144],[160,0,128],[200,32,64],[230,100,16],[250,200,32],[255,255,220]],bq=-80;function xq(e){let t=yq.length-1,n=Math.min(t-1,Math.floor(e*t)),r=e*t-n,[i,a,o]=yq[n],[s,c,l]=yq[n+1];return[i+(s-i)*r,a+(c-a)*r,o+(l-o)*r]}var Sq=(()=>{let e=new Uint8Array(256*4);for(let t=0;t<256;t++){let[n,r,i]=xq(t/255);e.set([n,r,i,255],t*4)}return e})();function Cq(e){let t=1;for(;t<e;)t<<=1;return t}var wq=(e,t)=>Math.log(1+e/t*9)/Math.log(10),Tq=(e,t)=>t*(10**e-1)/9;function Eq({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=oU(),d=K(null),f=K(null),p=K(null),m=K(null),h=K(null),g=K(l);G(()=>{g.current=l},[l]);let _=Cq(Math.max(4,Math.min(n,4096))),v=Math.max(1,Math.round(_*(1-Math.max(0,Math.min(.95,r))))),y=ft(()=>{if(!o)return null;let e=_>>1,n=t/2;return Int32Array.from({length:e},(t,r)=>Math.min(e-1,Math.floor(Tq((r+.5)/e,n)/n*e)))},[o,_,t]),b=K(null),x=ft(()=>b.current=_q(e,_,v,i===`hann`,a===`db`,y,b.current),[e,_,v,i,a,y]),S=ft(()=>({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+bq,C]:[0,C],T=K({grid:S,range:w,sampleRate:t,winSz:_,step:v,yMode:a,logFreq:o,label:s});G(()=>{T.current={grid:S,range:w,sampleRate:t,winSz:_,step:v,yMode:a,logFreq:o,label:s}},[S,w[0],w[1],t,_,v,a,o,s]);let E=K({plot:null,failed:!1,size:``,grid:null,shown:null});W(()=>()=>{E.current.plot?.dispose(),E.current.plot=null},[]);function D(){if(h.current)return h.current;let e=m.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return h.current=n,n}function O(){let e=m.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function k(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function A(e,t){let n=E.current;if(!n.plot&&!n.failed&&f.current&&(n.plot=mH(f.current,BK),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=$W(vq,t,n),{top:o,right:s,bottom:c,left:l}=a,f=t-l-s,h=n-o-c,{bg:g,muted:_,grid:v}=D(),{grid:y,sampleRate:b,winSz:x,step:S,logFreq:C,label:w}=T.current;r.fillStyle=g,r.fillRect(0,0,t,n);let j=A(t,n);if(y.w===0||f<=0||h<=0){if(j?.keep([]),j?.render(),a.tiny)return;r.fillStyle=_,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,zV(r);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=mq(y,N).grid;j&&j.setGrid(`cells`,e.values,e.w,Math.min(e.h,j.maxTextureSize),[0,e.w,0,e.h],Sq,P,F),E.current.grid=y,E.current.shown=e,DH(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]=xq(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?wq(e,R):e/R));L.strokeStyle=v,L.lineWidth=.5,L.globalAlpha=.4;let B=Az(0,R,Dz(R,5));L.setLineDash([3,4]);for(let e of B){let t=z(e);L.beginPath(),L.moveTo(l,t),L.lineTo(l+f,t),L.stroke()}L.setLineDash([]),L.globalAlpha=1,L.strokeStyle=v,L.strokeRect(l,o,f,h),r.fillStyle=_,r.font=`10px ${Q.mono}`,r.textAlign=`right`,r.textBaseline=`middle`,r.strokeStyle=_,r.lineWidth=1;for(let e of B){let t=z(e);r.beginPath(),r.moveTo(l-4,t),r.lineTo(l,t),r.stroke(),r.fillText(gq(e),l-6,t)}let V=(y.w*S+x)/b;u({left:l,top:o,width:f,height:h,x:{v0:0,v1:V}});let ee=Dz(V,6),te=Az(0,V,ee);r.textAlign=`center`,r.textBaseline=`top`;for(let e of te){let t=l+e/V*f;r.beginPath(),r.moveTo(t,o+h),r.lineTo(t,o+h+4),r.stroke(),r.fillText(Pz(e,ee),t,o+h+6)}r.fillStyle=_,r.textAlign=`center`,r.textBaseline=`bottom`,r.fillText(w||`Time (s)`,l+f/2,n-4),r.save(),r.translate(12,o+h/2),r.rotate(-Math.PI/2),r.textAlign=`center`,r.fillText(`Frequency (Hz)`,0,0),r.restore()}let M=K(j);G(()=>{M.current=j});let N=K(null);return N.current??=jH(()=>M.current(),()=>m.current),W(()=>{N.current.now()},[S,w[0],w[1],t,_,v,a,o,s]),W(()=>()=>N.current?.cancel(),[]),W(()=>{h.current=null,N.current.schedule()},[c]),G(()=>{let e=m.current;if(!e)return;let t=new AH(()=>{h.current=null,N.current.schedule()});return t.observe(e),()=>t.disconnect()},[]),G(()=>{let e=p.current;if(!e)return;let t=e=>{e.preventDefault(),g.current?.({clientX:e.clientX,clientY:e.clientY})};return e.addEventListener(`contextmenu`,t),()=>e.removeEventListener(`contextmenu`,t)},[]),vt(`div`,{ref:m,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:d,className:`chart-canvas`,role:`img`,"aria-label":`Spectrogram`}),q(`canvas`,{ref:f,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),q(`canvas`,{ref:p,className:`chart-canvas chart-overlay`})]})}var Dq=300,Oq=256,kq=-60,Aq=[];function jq({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=ft(()=>_q(e,c,l,i===`hann`,u,null),[e,c,l,i,u]);return q(bK,{points:Aq,surface:ft(()=>Mq(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 Mq(e,t,n,r,i){let{frames:a,bins:o,values:s}=e;if(a<2||o<2)return;let c=Math.min(a,Dq),l=Math.min(o,Oq),u=i?20*Math.log10(Math.max(e.max,1e-12))+kq:-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 Nq(e,t,n){return Array.from({length:n},(r,i)=>e+(i+1)/(n+1)*(t-e))}function Pq(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 Fq(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 Iq(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 Lq={top:14,right:32,bottom:80,left:80};function Rq(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 zq=[[33,102,172],[103,169,207],[209,229,240],[247,247,247],[253,219,199],[239,138,98],[178,24,43]],Bq=[[13,8,135],[84,2,163],[139,10,165],[185,50,137],[219,92,104],[244,136,73],[254,188,43],[240,249,33]],Vq=[[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 Hq(e,t){let n=e.length-1,r=Math.min(n-1,Math.floor(t*n));return Rq(e[r],e[r+1],t*n-r)}function Uq(e,t){return Hq(t===`plasma`?Bq:t===`viridis`?Vq:zq,e)}function Wq(e){let t=new Uint8Array(256*4);for(let n=0;n<256;n++){let[r,i,a]=Uq(n/255,e);t.set([r,i,a,255],n*4)}return t}function Gq(e){return Math.abs(e)>=1e4||Math.abs(e)<.01&&e!==0?e.toExponential(1):String(parseFloat(e.toPrecision(3)))}function Kq(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 qq(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=Fq(a),i=n[e.w]-n[0];u=Float64Array.from(n,e=>t+(e-n[0])/i*r)}if(l){let t=Fq(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 Jq(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 Yq(e,t,n,r,i,a){let o=Math.max(1,i),s=Math.max(1,a),c=Int32Array.from({length:o},(e,r)=>Jq(t.xB,n+r+.5)),l=new Float32Array(o*s);for(let n=0;n<s;n++){let i=Jq(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 Xq({cells:e,xLabels:t,yLabels:n,grid:r,showValues:i=!0,colorScheme:a=`diverging`,vMin:o,vMax:s,xCentres:c,yCentres:l,contours:u=0,backgroundToken:d=``,onPlotContextMenu:f}){let p=K(null),m=K(null),h=K(null),g=K(null),_=K(null),v=K(null),y=K(null),b=K(0),x=K(f);G(()=>{x.current=f},[f]);let S=ft(()=>r??Kq(e??[],t??[],n??[]),[r,e,t,n]),C=ft(()=>{let e=o??1/0,t=s??-1/0;if(o===void 0||s===void 0){let n=1/0,r=-1/0;for(let e=0;e<S.w*S.h;e++){let t=S.values[e];t<n&&(n=t),t>r&&(r=t)}o===void 0&&(e=n),s===void 0&&(t=r)}return t>e||(e=Number.isFinite(e)?e-1:0,t=e+2),{lo:e,hi:t}},[S,o,s]),w=K({data:S,range:C,showValues:i,colorScheme:a,xCentres:c,yCentres:l,contours:u});G(()=>{w.current={data:S,range:C,showValues:i,colorScheme:a,xCentres:c,yCentres:l,contours:u}},[S,C,i,a,c,l,u]);let T=K({plot:null,failed:!1,size:``,data:null,key:``,shown:null,geo:null}),E=K({key:``,grid:null,segs:[]});W(()=>()=>{T.current.plot?.dispose(),T.current.plot=null},[]);let D=K({data:null,range:``});function O(){if(v.current)return v.current;let e=_.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return v.current=n,n}function k(){let e=_.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function A(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function j(e,t){let n=T.current;if(!n.plot&&!n.failed&&m.current&&(n.plot=mH(m.current,BK),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=$W(Lq,t,n),{top:o,right:s,bottom:c,left:l}=a,{bg:u,muted:d,grid:f}=O(),{data:m,range:{lo:g,hi:v},showValues:y,colorScheme:b}=w.current;r.fillStyle=u,r.fillRect(0,0,t,n);let x=j(t,n);if(m.w===0||m.h===0){x?.keep([]),x?.render(),r.fillStyle=d,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,zV(r);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}`},DH(_.current));let{xCentres:F,yCentres:I,contours:L}=w.current,R=x?x.maxTextureSize:Math.max(1,Math.round(S*N)),z=mq(m,R).grid,B=qq(z,l,o,S,C,z===m?F:void 0,z===m?I:void 0),V=B.byValue,ee=`${R}|${b}|${V?`${S}x${C}`:``}`,te=T.current.shown;if(T.current.data!==m||T.current.key!==ee||!te){te=z;let e=V?Yq(te,B,l,o,Math.round(S),Math.round(C)):te;x&&x.setGrid(`cells`,e.values,e.w,Math.min(e.h,x.maxTextureSize),[0,e.w,0,e.h],Wq(b),g,v),T.current.data=m,T.current.key=ee,T.current.shown=te}T.current.geo=B;let H=V?Math.round(S):te.w,ne=V?Math.round(C):te.h,re=e=>B.xB[e+1]-B.xB[e],ie=e=>B.yB[e+1]-B.yB[e];if(x)x.keep([`cells`]),x.setGridRange(`cells`,g,v),x.setView(0,H,ne,0,{left:l,top:o,width:S,height:C}),x.render();else for(let e=0;e<te.h;e++)for(let t=0;t<te.w;t++){let n=te.values[e*te.w+t];if(Number.isNaN(n))continue;let[i,a,o]=Uq(Math.max(0,Math.min(1,(n-g)/(v-g))),b);r.fillStyle=`rgb(${i|0},${a|0},${o|0})`,r.fillRect(B.xB[t],B.yB[e],re(t)+.5,ie(e)+.5)}let U=i??r;if(y){for(let e=0;e<te.h;e++)if(!(ie(e)<=16)){U.font=`${Math.min(12,Math.max(8,ie(e)*.4))}px ${Q.mono}`,U.textAlign=`center`,U.textBaseline=`middle`;for(let t=0;t<te.w;t++){let n=te.values[e*te.w+t];if(Number.isNaN(n)||re(t)<=28)continue;let[r,i,a]=Uq(Math.max(0,Math.min(1,(n-g)/(v-g))),b);U.fillStyle=.299*r+.587*i+.114*a>128?`#000`:`#fff`,U.fillText(Gq(n),(B.xB[t]+B.xB[t+1])/2,(B.yB[e]+B.yB[e+1])/2)}}}if(S/te.w>=4&&C/te.h>=4){U.strokeStyle=u,U.lineWidth=.5;for(let e=0;e<=te.w;e++)U.beginPath(),U.moveTo(B.xB[e],o),U.lineTo(B.xB[e],o+C),U.stroke();for(let e=0;e<=te.h;e++)U.beginPath(),U.moveTo(l,B.yB[e]),U.lineTo(l+S,B.yB[e]),U.stroke()}let ae=L>0?Nq(g,v,L):[];if(ae.length&&te.w>=2&&te.h>=2&&te.w*te.h<=4e6){let e=`${g}|${v}|${L}`;if(E.current.grid!==te||E.current.key!==e){let t=te;E.current={key:e,grid:t,segs:ae.map(e=>Pq(t.values,t.w,t.h,e))}}let t=(e,t)=>{let n=Math.min(t.length-3,Math.max(0,Math.floor(e))),r=(t[n]+t[n+1])/2;return r+((t[n+1]+t[n+2])/2-r)*(e-n)};U.save(),U.beginPath(),U.rect(l,o,S,C),U.clip(),U.lineCap=`round`,U.lineJoin=`round`;for(let[e,n]of[[2.6,`rgba(0,0,0,0.38)`],[1.1,`rgba(255,255,255,0.92)`]]){U.lineWidth=e,U.strokeStyle=n,U.beginPath();for(let e of E.current.segs)for(let[n,r,i,a]of e)U.moveTo(t(n,B.xB),t(r,B.yB)),U.lineTo(t(i,B.xB),t(a,B.yB));U.stroke()}U.restore()}r.fillStyle=d,r.font=`10px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`top`;let oe=-1/0;for(let e=0;e<(a.tiny?0:te.w);e++){let t=(B.xB[e]+B.xB[e+1])/2;t-oe<18||(oe=t,r.save(),r.translate(t,o+C+4),r.rotate(-Math.PI/4),r.fillText(M(te.xLabels,e),0,0),r.restore())}r.textAlign=`right`,r.textBaseline=`middle`;let se=-1/0;for(let e=0;e<(a.tiny?0:te.h);e++){let t=(B.yB[e]+B.yB[e+1])/2;t-se<12||(se=t,r.fillText(te.yLabels[e]??``,l-4,t))}if(a.tiny)return;let ce=t-s+4,le=o,ue=C;for(let e=0;e<ue;e++){let[t,n,i]=Uq(1-e/ue,b);r.fillStyle=`rgb(${t|0},${n|0},${i|0})`,r.fillRect(ce,le+e,12,1)}r.strokeStyle=f,r.lineWidth=.5,r.strokeRect(ce,le,12,ue),r.fillStyle=d,r.font=`9px ${Q.mono}`,r.textAlign=`left`,r.textBaseline=`middle`,r.fillText(Gq(v),ce+12+2,le),r.fillText(Gq(g),ce+12+2,le+ue),r.fillText(Gq((g+v)/2),ce+12+2,le+ue/2),r.strokeStyle=`rgba(255,255,255,0.92)`,r.lineWidth=1;for(let e of ae){let t=le+ue*(1-(e-g)/(v-g));r.beginPath(),r.moveTo(ce-2,t),r.lineTo(ce+12+2,t),r.stroke()}}function P(){let e=g.current;if(!e)return;let{w:t,h:n}=k(),r=A(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=y.current,a=T.current.shown,o=T.current.geo;if(!i||!a||!o)return;let{top:s,right:c,bottom:l}=$W(Lq,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]}: ${Gq(_)}`;r.font=`11px ${Q.mono}`;let n=r.measureText(e).width,i=Math.min(p+.1*(p-f),t-c-n-6),o=Math.max(s+4,m-.3*(h-m));r.fillStyle=`rgba(0,0,0,0.7)`,r.fillRect(i-3,o-3,n+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(e,i,o)}}let F=K(N);F.current=N;let I=K(null);I.current??=jH(()=>F.current(),()=>_.current);let L=()=>{b.current||=wH(()=>{b.current=0,P()})};return W(()=>{I.current.now()},[S,C,i,a,c,l,u]),W(()=>()=>{I.current?.cancel(),TH(b.current)},[]),W(()=>{v.current=null,I.current.schedule()},[d]),G(()=>{let e=_.current;if(!e)return;let t=new AH(()=>{v.current=null,I.current.schedule(),L()});return t.observe(e),()=>t.disconnect()},[]),G(()=>{let e=g.current;if(!e)return;let t=e=>{e.preventDefault(),x.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),{shown:r,geo:i}=T.current;if(!r||!i)return;let a=Jq(i.xB,t.clientX-n.left),o=Jq(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)}},[]),vt(`div`,{ref:_,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:p,className:`chart-canvas`,role:`img`,"aria-label":`Heatmap`}),q(`canvas`,{ref:m,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),q(`canvas`,{ref:h,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),q(`canvas`,{ref:g,className:`chart-canvas chart-overlay`})]})}var Zq=2e3,Qq=1024;function $q(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<=Zq){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(Qq),l=(i-r)/Qq||1;for(let t=0;t<a;t++)c[Math.max(0,Math.min(Qq-1,Math.floor((e[t]-r)/l)))]++;for(let e=0;e<n.length;e++){let i=0;for(let a=0;a<Qq;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 eJ={top:14,right:24,bottom:48,left:64},tJ=120;function nJ(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 rJ(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]=lq(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:tJ},(e,t)=>r+t/(tJ-1)*(i-r));return{shapes:n.map((e,n)=>{let{q1:o,median:c,q3:l}=a[n],u=$q(e.values,t>0?t:nJ(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 iJ({groups:e,color:t=`#818cf8`,showBox:n=!0,bandwidth:r=0,orientation:i=`vertical`,backgroundToken:a=``,onPlotContextMenu:o}){let s=oU(),c=K(null),l=K(null),u=K(null),d=K(o);G(()=>{d.current=o},[o]);let f=K({groups:e,color:t,showBox:n,bandwidth:r,orientation:i});G(()=>{f.current={groups:e,color:t,showBox:n,bandwidth:r,orientation:i}},[e,t,n,r,i]);let p=ft(()=>rJ(e,r),[e,r]),m=K(p);G(()=>{m.current=p},[p]);function h(){if(u.current)return u.current;let e=l.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return u.current=n,n}function g(){let e=l.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function _(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function v(){let e=c.current;if(!e)return;let{w:t,h:n}=g(),r=_(e,t,n);if(!r)return;let{top:i,right:a,bottom:o,left:l}=eJ,u=t-l-a,d=n-i-o,{bg:p,muted:v,grid:y}=h(),{color:b,showBox:x,orientation:S}=f.current;r.fillStyle=p,r.fillRect(0,0,t,n);let{shapes:C,pts:w,yMin:T,yMax:E}=m.current;if(C.length===0||u<=0||d<=0){r.fillStyle=v,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,zV(r);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=Dz(E-T,5),A=Az(T,E,k);r.strokeStyle=y,r.lineWidth=1,r.setLineDash([3,3]);for(let e of A)D?(r.beginPath(),r.moveTo(l,O(e)),r.lineTo(l+u,O(e)),r.stroke()):(r.beginPath(),r.moveTo(O(e),i),r.lineTo(O(e),i+d),r.stroke());if(r.setLineDash([]),r.fillStyle=v,r.font=`11px ${Q.mono}`,r.strokeStyle=v,r.lineWidth=1,D){r.textAlign=`right`,r.textBaseline=`middle`;for(let e of A)r.beginPath(),r.moveTo(l-4,O(e)),r.lineTo(l,O(e)),r.stroke(),r.fillText(Pz(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(Pz(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<tJ;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=tJ-1;e>=0;e--){let i=t[e]/n*u,a=O(w[e]);D?r.lineTo(c+i,a):r.lineTo(a,c+i)}if(r.closePath(),r.fillStyle=b,r.globalAlpha=.35,r.fill(),r.strokeStyle=b,r.lineWidth=1,r.globalAlpha=.9,r.stroke(),r.globalAlpha=1,x){let e=u*.22;D?(r.fillStyle=b,r.globalAlpha=.7,r.fillRect(c-e,O(s),e*2,O(a)-O(s)),r.globalAlpha=1,r.strokeStyle=b,r.lineWidth=2,r.beginPath(),r.moveTo(c-e,O(o)),r.lineTo(c+e,O(o)),r.stroke()):(r.fillStyle=b,r.globalAlpha=.7,r.fillRect(O(a),c-e,O(s)-O(a),e*2),r.globalAlpha=1,r.strokeStyle=b,r.lineWidth=2,r.beginPath(),r.moveTo(O(o),c-e),r.lineTo(O(o),c+e),r.stroke())}}if(r.restore(),r.fillStyle=v,r.font=`11px ${Q.mono}`,D){r.textAlign=`center`,r.textBaseline=`top`;for(let e=0;e<j;e++)r.fillText(C[e].label,l+M*e+M/2,i+d+6)}else{r.textAlign=`right`,r.textBaseline=`middle`;for(let e=0;e<j;e++)r.fillText(C[e].label,l-6,i+M*e+M/2)}}let y=K(v);y.current=v;let b=K(null);b.current??=jH(()=>y.current(),()=>l.current);let x=()=>b.current.schedule();return W(()=>{b.current.now()}),W(()=>()=>b.current?.cancel(),[]),W(()=>{u.current=null,x()},[a]),G(()=>{let e=l.current;if(!e)return;let t=new AH(()=>{u.current=null,x()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=c.current;if(!e)return;let t=e=>{e.preventDefault(),d.current?.({clientX:e.clientX,clientY:e.clientY})};return e.addEventListener(`contextmenu`,t),()=>e.removeEventListener(`contextmenu`,t)},[]),q(`div`,{ref:l,style:{position:`relative`,width:`100%`,height:`100%`},children:q(`canvas`,{ref:c,className:`chart-canvas`,role:`img`,"aria-label":`Violin plot`})})}var aJ={top:48,right:16,bottom:72,left:80},oJ=[8,24,64],sJ=[56,189,248];function cJ(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 lJ(e){return`${(e*100).toFixed(1)}%`}function uJ(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 dJ({actual:e,predicted:t,normalize:n=!1,backgroundToken:r=``,onPlotContextMenu:i}){let a=K(null),o=K(null),s=K(null),c=K(null),l=K(null),u=K(0),d=K(i);G(()=>{d.current=i},[i]);let f=K({actual:e,predicted:t,normalize:n});G(()=>{f.current={actual:e,predicted:t,normalize:n}},[e,t,n]);function p(){if(c.current)return c.current;let e=s.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return c.current=n,n}function m(){let e=s.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function h(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}let g=ft(()=>uJ(e,t,n),[e,t,n]),_=K(g);G(()=>{_.current=g},[g]);let v=()=>_.current;function y(){let e=a.current;if(!e)return;let{w:t,h:n}=m(),r=h(e,t,n);if(!r)return;let{top:i,right:o,bottom:s,left:c}=aJ,{bg:l,muted:u,grid:d}=p();r.fillStyle=l,r.fillRect(0,0,t,n);let g=v();if(!g){r.fillStyle=u,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,zV(r);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]=cJ(oJ,sJ,E>0?n/E:0);if(r.fillStyle=`rgb(${a|0},${o|0},${s|0})`,r.fillRect(c+t*w,i+e*T,w,T),w>24&&T>14){r.fillStyle=.299*a+.587*o+.114*s>100?`#000`:`#fff`,r.font=`${Math.min(12,Math.max(8,T*.38))}px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`middle`;let l=f.current.normalize;r.fillText(l?lJ(n):String(n|0),c+(t+.5)*w,i+(e+.5)*T)}}r.strokeStyle=l,r.lineWidth=.5;for(let e=0;e<=x;e++)r.beginPath(),r.moveTo(c+e*w,i),r.lineTo(c+e*w,i+C),r.stroke(),r.beginPath(),r.moveTo(c,i+e*T),r.lineTo(c+S,i+e*T),r.stroke();r.strokeStyle=d,r.strokeRect(c,i,S,C),r.fillStyle=u,r.font=`10px ${Q.mono}`,r.textAlign=`right`,r.textBaseline=`middle`;for(let e=0;e<x;e++)r.fillText(_[e],c-4,i+(e+.5)*T);r.textAlign=`center`,r.textBaseline=`top`;for(let e=0;e<x;e++)r.save(),r.translate(c+(e+.5)*w,i+C+4),r.rotate(-Math.PI/4),r.fillText(_[e],0,0),r.restore();r.fillStyle=u,r.font=`11px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`bottom`,r.fillText(`Predicted`,c+S/2,n-4),r.save(),r.translate(12,i+C/2),r.rotate(-Math.PI/2),r.textAlign=`center`,r.fillText(`Actual`,0,0),r.restore(),r.fillStyle=u,r.font=`11px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`middle`,r.fillText(`Accuracy: ${lJ(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}=aJ,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?lJ(C):C|0}`;r.font=`11px ${Q.mono}`;let E=r.measureText(T).width,D=Math.min(u+(i.c+1.1)*x,t-E-6),O=Math.max(6,a+(i.r-.3)*S);r.fillStyle=`rgba(0,0,0,0.75)`,r.fillRect(D-3,O-3,E+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(T,D,O)}let x=K(y);x.current=y;let S=K(null);S.current??=jH(()=>x.current(),()=>s.current);let C=()=>S.current.schedule(),w=()=>{TH(u.current),u.current=wH(b)};return W(()=>{S.current.now()}),W(()=>()=>S.current?.cancel(),[]),W(()=>{c.current=null,C()},[r]),G(()=>{let e=s.current;if(!e)return;let t=new AH(()=>{c.current=null,C(),w()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=o.current;if(!e)return;let t=e=>{e.preventDefault(),d.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),{top:r,right:i,bottom:a,left:o}=aJ,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)}},[]),vt(`div`,{ref:s,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:a,className:`chart-canvas`,role:`img`,"aria-label":`Confusion matrix`}),q(`canvas`,{ref:o,className:`chart-canvas chart-overlay`})]})}var fJ={top:24,right:24,bottom:48,left:64};function pJ(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 mJ(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 hJ(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 gJ(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 _J({scores:e,labels:t,mode:n=`roc`,color:r=`#f472b6`,backgroundToken:i=``,onPlotContextMenu:a}){let o=K(null),s=K(null),c=K(null),l=K(a);G(()=>{l.current=a},[a]);let u=K({scores:e,labels:t,mode:n,color:r});G(()=>{u.current={scores:e,labels:t,mode:n,color:r}},[e,t,n,r]);let d=ft(()=>pJ(e,t),[e,t]),f=ft(()=>n===`pr`?{roc:null,pr:hJ(d)}:{roc:mJ(d),pr:null},[d,n]),p=K(f);G(()=>{p.current=f},[f]);function m(){if(c.current)return c.current;let e=s.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return c.current=n,n}function h(){let e=s.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function g(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function _(){let e=o.current;if(!e)return;let{w:t,h:n}=h(),r=g(e,t,n);if(!r)return;let{top:i,right:a,bottom:s,left:c}=fJ,l=t-c-a,d=n-i-s,{bg:f,muted:_,grid:v}=m(),{scores:y,mode:b,color:x}=u.current;if(r.fillStyle=f,r.fillRect(0,0,t,n),y.length===0){r.fillStyle=_,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,zV(r);return}let S=e=>c+e*l,C=e=>i+(1-e)*d,w=Az(0,1,Dz(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(),gJ(r,t,n,a),r.strokeStyle=x,r.lineWidth=1,r.stroke(),r.beginPath(),gJ(r,t,n,a),r.lineTo(S(1),C(0)),r.lineTo(S(0),C(0)),r.closePath(),r.fillStyle=x,r.globalAlpha=.15,r.fill(),r.globalAlpha=1,r.fillStyle=x,r.font=`bold 13px ${Q.mono}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`AUC = ${e.auc.toFixed(3)}`,c+8,i+8)}}else{let e=p.current.pr;if(e){let t=KK(e.recall,e.precision,0,1,Math.max(1,Math.round(l*Math.min(2,window.devicePixelRatio||1))));r.beginPath();for(let n=0;n<t.length;n++){let i=S(e.recall[t[n]]),a=C(e.precision[t[n]]);n===0?r.moveTo(i,a):r.lineTo(i,a)}r.strokeStyle=x,r.lineWidth=1,r.stroke(),r.fillStyle=x,r.font=`bold 13px ${Q.mono}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`AP = ${e.ap.toFixed(3)}`,c+8,i+8)}}r.fillStyle=_,r.font=`11px ${Q.mono}`,r.strokeStyle=_,r.lineWidth=1,r.textAlign=`right`,r.textBaseline=`middle`;for(let e of w)r.beginPath(),r.moveTo(c-4,C(e)),r.lineTo(c,C(e)),r.stroke(),r.fillText(e.toFixed(1),c-6,C(e));r.textAlign=`center`,r.textBaseline=`top`;for(let e of w)r.beginPath(),r.moveTo(S(e),i+d),r.lineTo(S(e),i+d+4),r.stroke(),r.fillText(e.toFixed(1),S(e),i+d+6);r.strokeStyle=v,r.strokeRect(c,i,l,d),r.fillStyle=_,r.textAlign=`center`,r.textBaseline=`bottom`,r.fillText(b===`roc`?`False Positive Rate`:`Recall`,c+l/2,n-4),r.save(),r.translate(12,i+d/2),r.rotate(-Math.PI/2),r.textAlign=`center`,r.fillText(b===`roc`?`True Positive Rate`:`Precision`,0,0),r.restore()}let v=K(_);v.current=_;let y=K(null);y.current??=jH(()=>v.current(),()=>s.current);let b=()=>y.current.schedule();return W(()=>{y.current.now()}),W(()=>()=>y.current?.cancel(),[]),W(()=>{c.current=null,b()},[i]),G(()=>{let e=s.current;if(!e)return;let t=new AH(()=>{c.current=null,b()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=o.current;if(!e)return;let t=e=>{e.preventDefault(),l.current?.({clientX:e.clientX,clientY:e.clientY})};return e.addEventListener(`contextmenu`,t),()=>e.removeEventListener(`contextmenu`,t)},[]),q(`div`,{ref:s,style:{position:`relative`,width:`100%`,height:`100%`},children:q(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`ROC / PR curve`})})}var vJ={top:20,right:64,bottom:48,left:64};function yJ({xValues:e,series:t,xLabel:n=`Epoch`,backgroundToken:r=``,onPlotContextMenu:i}){let a=oU(),o=K(null),s=K(null),c=K(null),l=K(null),u=K(null),d=K(0),f=K(i);G(()=>{f.current=i},[i]);let p=K({xValues:e,series:t,xLabel:n});G(()=>{p.current={xValues:e,series:t,xLabel:n}},[e,t,n]);function m(){if(l.current)return l.current;let e=c.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return l.current=n,n}function h(){let e=c.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function g(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}let _=ft(()=>{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:YK(e)}},[e,t]),v=K(_);G(()=>{v.current=_},[_]);function y(){let e=o.current;if(!e)return;let{w:t,h:n}=h(),r=g(e,t,n);if(!r)return;let{top:i,right:s,bottom:c,left:l}=vJ,u=t-l-s,d=n-i-c,{bg:f,muted:_,grid:y}=m(),{xValues:b,series:x,xLabel:S}=p.current;if(r.fillStyle=f,r.fillRect(0,0,t,n),b.length===0||x.length===0){r.fillStyle=_,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,zV(r);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=Dz(C.hi-C.lo,5),N=Az(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=Dz(D-E,6),F=Az(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?KK(b,e.values,E,D,L):null;r.beginPath();let a=!1;for(let o=0;o<(i?i.length:n);o++){let n=i?i[o]:o,s=b[n],c=e.values[n];if(s-s!==0||c-c!==0){a=!1;continue}let l=k(s),u=t(c);a?r.lineTo(l,u):(r.moveTo(l,u),a=!0)}r.strokeStyle=e.color,r.lineWidth=1,r.stroke()}r.fillStyle=_,r.font=`11px ${Q.mono}`,r.strokeStyle=_,r.lineWidth=1,r.textAlign=`right`,r.textBaseline=`middle`;for(let e of N)r.beginPath(),r.moveTo(l-4,A(e)),r.lineTo(l,A(e)),r.stroke(),r.fillText(Pz(e,M),l-6,A(e));if(T){let e=Dz(w.hi-w.lo,5),t=Az(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(Pz(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(Pz(e,P),k(e),i+d+6);r.strokeStyle=y,r.strokeRect(l,i,u,d),r.fillStyle=_,r.textAlign=`center`,r.textBaseline=`bottom`,r.fillText(S,l+u/2,n-4);let R=l+8,z=i+6;r.font=`10px ${Q.mono}`,r.textBaseline=`middle`;for(let e of x)r.fillStyle=e.color,r.fillRect(R,z-4,16,3),r.fillStyle=_,r.textAlign=`left`,r.fillText(e.label,R+20,z),R+=r.measureText(e.label).width+36,R>l+u-60&&(R=l+8,z+=14)}function b(){let e=s.current;if(!e)return;let{w:t,h:n}=h(),r=g(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=u.current;if(i===null)return;let{top:a,right:o,bottom:c,left:l}=vJ,d=t-l-o,f=n-a-c,{muted:_}=m(),{xValues:y,series:b}=p.current;if(y.length===0)return;let{xMin:x,xMax:S,ascending:C}=v.current,w=e=>l+(e-x)/(S-x||1)*d,T=Math.max(l,Math.min(l+d,i));r.strokeStyle=_,r.lineWidth=1,r.setLineDash([3,3]),r.beginPath(),r.moveTo(T,a),r.lineTo(T,a+f),r.stroke(),r.setLineDash([]);let E=(T-l)/d,D=Math.round(E*(y.length-1));if(C){let e=x+E*(S-x),t=0,n=y.length;for(;t<n;){let r=t+n>>>1;y[r]<e?t=r+1:n=r}D=t>0&&(t>=y.length||e-y[t-1]<y[t]-e)?t-1:t}if(D<0||D>=y.length)return;let O=a+8;r.font=`10px ${Q.mono}`,r.textBaseline=`top`;for(let e of b)D<e.values.length&&Number.isFinite(e.values[D])&&(r.fillStyle=e.color,r.textAlign=`left`,r.fillText(`${e.label}: ${Fz(e.values[D])}`,T+6,O),O+=14);w(0)}let x=K(y);x.current=y;let S=K(null);S.current??=jH(()=>x.current(),()=>c.current);let C=()=>S.current.schedule(),w=()=>{TH(d.current),d.current=wH(b)};return W(()=>{S.current.now()}),W(()=>()=>S.current?.cancel(),[]),W(()=>{l.current=null,C()},[r]),G(()=>{let e=c.current;if(!e)return;let t=new AH(()=>{l.current=null,C(),w()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=s.current;if(!e)return;let t=e=>{e.preventDefault(),f.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect();u.current=t.clientX-n.left,w()},r=()=>{u.current=null,w()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),vt(`div`,{ref:c,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`Loss curves`}),q(`canvas`,{ref:s,className:`chart-canvas chart-overlay`})]})}var bJ={top:40,right:24,bottom:40,left:72},xJ=`#ef4444`,SJ=`#f97316`,CJ=`#22d3ee`;function wJ(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 TJ({points:e,sigmaLevel:t=3,color:n=`#22d3ee`,backgroundToken:r=``,onPlotContextMenu:i}){let a=oU(),o=K(null),s=K(null),c=K(null),l=K(null),u=K(null),d=K(0),f=K(i);G(()=>{f.current=i},[i]);let p=K({points:e,sigmaLevel:t,color:n});G(()=>{p.current={points:e,sigmaLevel:t,color:n}},[e,t,n]);function m(){if(l.current)return l.current;let e=c.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return l.current=n,n}function h(){let e=c.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function g(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}let _=ft(()=>wJ(e,t),[e,t]),v=K(_);G(()=>{v.current=_},[_]);let y=()=>v.current;function b(){let e=o.current;if(!e)return;let{w:t,h:n}=h(),r=g(e,t,n);if(!r)return;let{top:i,right:s,bottom:c,left:l}=bJ,u=t-l-s,d=n-i-c,{bg:f,muted:_,grid:v}=m(),{points:b,color:x}=p.current;if(r.fillStyle=f,r.fillRect(0,0,t,n),b.length===0){r.fillStyle=_,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,zV(r);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=Dz(D-E,5),j=Az(E,D,A);r.strokeStyle=v,r.lineWidth=1,r.setLineDash([3,3]);for(let e of j)r.beginPath(),r.moveTo(l,k(e)),r.lineTo(l+u,k(e)),r.stroke();r.setLineDash([]);let M=(e,t,n,a=[])=>{let o=k(e);o<i||o>i+d||(r.strokeStyle=t,r.lineWidth=1.2,r.setLineDash(a),r.beginPath(),r.moveTo(l,o),r.lineTo(l+u,o),r.stroke(),r.setLineDash([]),r.fillStyle=t,r.font=`9px ${Q.mono}`,r.textAlign=`right`,r.textBaseline=`middle`,r.fillText(`${n} ${Fz(e)}`,l+u-2,o-5))};M(w,SJ,`UCL`,[5,3]),M(C,CJ,`CL`,[]),M(T,SJ,`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=qK(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?xJ:x,r.fill()};if(F<=u/4)for(let e=0;e<F;e++)R(e,I[e]>w||I[e]<T);else{let e=NaN,t=NaN;for(let n of S.ooc){let r=Math.round(O(n)),i=Math.round(k(I[n]));r===e&&i===t||(e=r,t=i,R(n,!0))}}r.fillStyle=_,r.font=`11px ${Q.mono}`,r.strokeStyle=_,r.lineWidth=1,r.textAlign=`right`,r.textBaseline=`middle`;for(let e of j)r.beginPath(),r.moveTo(l-4,k(e)),r.lineTo(l,k(e)),r.stroke(),r.fillText(Pz(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}=bJ,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}: `}${Fz(D)}`;r.font=`11px ${Q.mono}`;let M=r.measureText(j).width,N=O+8+M>l+d?O-M-10:O+8;r.fillStyle=`rgba(0,0,0,0.75)`,r.fillRect(N-3,k-12,M+6,18),r.fillStyle=D>b||D<x?xJ:_,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(j,N,k-11)}let S=K(b);S.current=b;let C=K(null);C.current??=jH(()=>S.current(),()=>c.current);let w=()=>C.current.schedule(),T=()=>{TH(d.current),d.current=wH(x)};return W(()=>{C.current.now()}),W(()=>()=>C.current?.cancel(),[]),W(()=>{l.current=null,w()},[r]),G(()=>{let e=c.current;if(!e)return;let t=new AH(()=>{l.current=null,w(),T()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=s.current;if(!e)return;let t=e=>{e.preventDefault(),f.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect();u.current=t.clientX-n.left,T()},r=()=>{u.current=null,T()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),vt(`div`,{ref:c,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`Control chart`}),q(`canvas`,{ref:s,className:`chart-canvas chart-overlay`})]})}var EJ={top:32,right:24,bottom:24,left:24},DJ=[`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`,`#facc15`,`#60a5fa`],OJ=16;function kJ(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 AJ(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:OJ},(e,t)=>kJ((t+.5)/OJ));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(OJ-1,Math.floor(e*OJ))):-1}for(let t=0;t<e.length;t++)s[t]<0&&(s[t]=0)}else if(!n&&e.colorIndex){c=DJ;for(let t=0;t<e.length;t++)s[t]=Math.max(0,e.colorIndex[t])%DJ.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 jJ({rows:e,axes:t,color:n=`#64748b`,colorByNumeric:r=!1,backgroundToken:i=``,onPlotContextMenu:a}){let o=K(null),s=K(null),c=K(null),l=K(null),u=K(null),d=K(null),f=K(null),p=K(0),m=K(a);G(()=>{m.current=a},[a]);let h=ft(()=>AJ(e,t.length,r,n),[e,t.length,r,n]),g=K({rows:e,axes:t,colorByNumeric:r,model:h});G(()=>{g.current={rows:e,axes:t,colorByNumeric:r,model:h}},[e,t,r,h]);let _=VK(s),v=K(null);function y(){if(d.current)return d.current;let e=u.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return d.current=n,n}function b(){let e=u.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function x(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function S(){let e=o.current;if(!e)return;let{w:t,h:n}=b(),r=x(e,t,n);if(!r)return;let i=c.current?x(c.current,t,n):null;i?.clearRect(0,0,t,n);let a=i??r,{top:s,right:l,bottom:d,left:f}=EJ,{bg:p,muted:m}=y(),{rows:h,axes:S,colorByNumeric:C,model:w}=g.current;r.fillStyle=p,r.fillRect(0,0,t,n);let T=_(t,n);if(S.length<2||h.length===0||w.k<2){T?.keep([]),T?.render(),r.fillStyle=m,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`Select ≥ 2 axes`,f+8,s+8);return}let E=t-f-l,D=n-s-d,O=w.k,k=Array.from({length:O},(e,t)=>f+t/(O-1)*E),A=(e,t)=>{let n=w.extents[t];return s+(1-(e-n.lo)/(n.hi-n.lo))*D},j=Math.max(.05,Math.min(.7,60/h.length));if(T)v.current!==w&&(w.groups.forEach((e,t)=>T.setLine(`c${t}`,e.x,e.y,eK(e.color,j),1,e.starts)),v.current=w,DH(u.current)),T.keep(w.groups.map((e,t)=>`c${t}`)),T.setView(0,O-1,0,1,{left:f,top:s,width:E,height:D}),T.render();else{r.globalAlpha=j;for(let e of w.groups){r.beginPath();let t=!1;for(let n=0;n<e.x.length;n++){let i=e.y[n];if(e.starts[n]&&(t=!1),i!==i){t=!1;continue}let a=f+e.x[n]/(O-1)*E,o=s+(1-i)*D;t?r.lineTo(a,o):(r.moveTo(a,o),t=!0)}r.strokeStyle=e.color,r.lineWidth=1,r.stroke()}r.globalAlpha=1}a.strokeStyle=m,a.lineWidth=1.5;for(let e=0;e<O;e++)a.beginPath(),a.moveTo(k[e],s),a.lineTo(k[e],s+D),a.stroke();a.fillStyle=m,a.font=`9px ${Q.mono}`;for(let e=0;e<O;e++){let t=w.extents[e];for(let n of[0,.25,.5,.75,1]){let r=t.lo+n*(t.hi-t.lo),i=A(r,e);a.beginPath(),a.moveTo(k[e]-3,i),a.lineTo(k[e]+3,i),a.stroke(),a.textAlign=e===O-1?`left`:`right`,a.textBaseline=`middle`,a.fillText(Pz(r,(t.hi-t.lo)/4),k[e]+(e===O-1?5:-5),i)}a.font=`10px ${Q.mono}`,a.textAlign=`center`,a.textBaseline=`bottom`,a.fillText(S[e],k[e],s-4)}let M=h.colorLabels??[];if(!C&&M.length>0&&M.length<=10){let e=f,t=s+D+8;a.font=`9px ${Q.mono}`,a.textBaseline=`top`,M.forEach((n,r)=>{a.fillStyle=DJ[r%DJ.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}=EJ,{axes:u}=g.current;if(u.length<2)return;let d=t-c-o,p=c+i/(u.length-1)*d;r.strokeStyle=`rgba(255,255,255,0.6)`,r.lineWidth=2,r.beginPath(),r.moveTo(p,a-4),r.lineTo(p,a+(n-a-s)+4),r.stroke()}let w=K(S);w.current=S;let T=K(null);T.current??=jH(()=>w.current(),()=>u.current);let E=()=>T.current.schedule(),D=()=>{TH(p.current),p.current=wH(C)};return W(()=>{T.current.now()}),W(()=>()=>T.current?.cancel(),[]),W(()=>{d.current=null,E()},[i]),G(()=>{let e=u.current;if(!e)return;let t=new AH(()=>{d.current=null,E(),D()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=l.current;if(!e)return;let t=e=>{e.preventDefault(),m.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),{axes:r}=g.current;if(r.length<2)return;let i=n.width-EJ.left-EJ.right,a=r.length,o=t.clientX-n.left-EJ.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)}},[]),vt(`div`,{ref:u,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`Parallel coordinates`}),q(`canvas`,{ref:s,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),q(`canvas`,{ref:c,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),q(`canvas`,{ref:l,className:`chart-canvas chart-overlay`})]})}function MJ(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 NJ(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 PJ={top:16,right:16,bottom:16,left:16},FJ=[`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`,`#facc15`,`#60a5fa`];function IJ(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 LJ(e){let[t,n,r]=IJ(e);return`rgb(${t},${n},${r})`}var RJ=(()=>{let e=new Uint8Array(1024);for(let t=0;t<256;t++)e.set([...IJ(t/255),255],t*4);return e})(),zJ=(()=>{let e=new Uint8Array(1024);for(let t=0;t<256;t++){let[n,r,i]=eK(FJ[t%FJ.length],1);e.set([n*255,r*255,i*255,255],t*4)}return e});function BJ(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 VJ({points:e,color:t=`#64748b`,colorByNumeric:n=!1,pointSize:r=4,backgroundToken:i=``,onPlotContextMenu:a}){let o=K(null),s=K(null),c=K(null),l=K(null),u=K(null),d=K(null),f=K(0),p=K(a);G(()=>{p.current=a},[a]);let m=ft(()=>BJ(e,n),[e,n]),h=K({points:e,color:t,colorByNumeric:n,pointSize:r,model:m});G(()=>{h.current={points:e,color:t,colorByNumeric:n,pointSize:r,model:m}},[e,t,n,r,m]);let g=K({r:null,failed:!1,size:``,model:null,style:``});W(()=>()=>{g.current.r?.dispose(),g.current.r=null},[]);function _(){if(u.current)return u.current;let e=l.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return u.current=n,n}function v(){let e=l.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function y(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function b(e,t){let{top:n,right:r,bottom:i,left:a}=PJ,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=mH(s.current,ZW),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,DH(l.current));let f=`${c.mode}|${u}|${d}`;return n.style!==f&&(r.setStyle(c.mode===`single`?{kind:`single`,rgba:eK(u,1)}:{kind:c.mode,palette:c.mode===`colormap`?RJ:zJ()},d,.8),r.setDraw(!0,!1,0),n.style=f),r}function S(){let e=o.current;if(!e)return;let{w:t,h:n}=v(),r=y(e,t,n);if(!r)return;let{bg:i,muted:a}=_(),{points:s,color:c,colorByNumeric:l,pointSize:u,model:d}=h.current;r.fillStyle=i,r.fillRect(0,0,t,n);let f=x(t,n);if(s.length===0){f?.setData([],[]),g.current.model=null,f?.render(),r.fillStyle=a,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,zV(r);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:PJ.left,top:PJ.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`?LJ(i):d.mode===`dataset`?FJ[i%FJ.length]:c,r.globalAlpha=.8,r.fill()}r.globalAlpha=1}if(l){let e=Math.min(120,Math.floor((n-PJ.top-PJ.bottom)*.4)),i=t-PJ.right-12,o=PJ.top+8;for(let t=0;t<e;t++)r.fillStyle=LJ(1-t/(e-1)),r.fillRect(i,o+t,8,1);r.fillStyle=a,r.font=`9px ${Q.mono}`,r.textAlign=`left`,r.textBaseline=`middle`;let s=e=>Math.abs(e)>=1e4||Math.abs(e)<.001&&e!==0?e.toExponential(1):String(parseFloat(e.toPrecision(3)));r.fillText(s(p.hi),i+10,o),r.fillText(s(p.lo),i+10,o+e)}let E=s.colorLabels??[];if(!l&&E.length>0&&E.length<=10){let e=PJ.left,i=n-PJ.bottom-10;r.font=`9px ${Q.mono}`,r.textBaseline=`top`,E.forEach((n,o)=>{e>t-PJ.right-60&&(e=PJ.left,i-=14),r.fillStyle=FJ[o%FJ.length],r.beginPath(),r.arc(e+4,i+4,4,0,Math.PI*2),r.fill(),r.fillStyle=a,r.textAlign=`left`,r.fillText(n,e+10,i),e+=r.measureText(n).width+20})}}function C(){let e=c.current;if(!e)return;let{w:t,h:n}=v(),r=y(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=d.current;if(i===null)return;let{points:a,pointSize:o}=h.current;if(i<0||i>=a.length)return;let{xToPx:s,yToPx:l}=b(t,n),u=a.x[i],f=a.y[i],p=s(u),m=l(f);r.beginPath(),r.arc(p,m,o+3,0,Math.PI*2),r.strokeStyle=`rgba(255,255,255,0.9)`,r.lineWidth=2,r.stroke();let g=[],_=a.label?.(i);_&&g.push(_);let x=a.colorIndex?.[i];x!==void 0&&x>=0&&a.colorLabels?g.push(a.colorLabels[x]):a.colorValue&&g.push(a.colorValue[i].toFixed(3)),g.push(`(${u.toFixed(3)}, ${f.toFixed(3)})`);let S=g.join(` · `);r.font=`11px ${Q.mono}`;let C=r.measureText(S).width,w=Math.max(4,Math.min(t-C-8,p+10)),T=m-20<PJ.top?m+10:m-20;r.fillStyle=`rgba(0,0,0,0.75)`,r.fillRect(w-3,T-3,C+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(S,w,T)}let w=K(S);w.current=S;let T=K(null);T.current??=jH(()=>w.current(),()=>l.current);let E=()=>T.current.schedule(),D=()=>{TH(f.current),f.current=wH(C)};return W(()=>{T.current.now()}),W(()=>()=>T.current?.cancel(),[]),W(()=>{u.current=null,E()},[i]),G(()=>{let e=l.current;if(!e)return;let t=new AH(()=>{u.current=null,E(),D()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=c.current;if(!e)return;let t=null,n=e=>{e.preventDefault(),p.current?.({clientX:e.clientX,clientY:e.clientY})},r=n=>{let r=e.getBoundingClientRect(),{points:i,pointSize:a,model:o}=h.current,{w:s,h:c}=v(),{xToPx:l,yToPx:u,plotW:f,plotH:p}=b(s,c),m=e=>l(i.x[e])-PJ.left,g=e=>u(i.y[e])-PJ.top,_=a+8,y=`${s}|${c}|${_}`;(!t||t.model!==o||t.key!==y)&&(t={model:o,key:y,g:MJ(i.length,f,p,_,m,g)}),d.current=NJ(t.g,n.clientX-r.left-PJ.left,n.clientY-r.top-PJ.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)}},[]),vt(`div`,{ref:l,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`Embedding / scatter`}),q(`canvas`,{ref:s,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),q(`canvas`,{ref:c,className:`chart-canvas chart-overlay`})]})}var HJ={top:8,right:8,bottom:8,left:8},UJ=20,WJ=[`#f97316`,`#fb923c`,`#fdba74`,`#fbbf24`,`#fcd34d`,`#4ade80`,`#34d399`,`#38bdf8`,`#818cf8`,`#a78bfa`];function GJ(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 KJ(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 qJ(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 JJ(e){return WJ[e%WJ.length]}function YJ({nodes:e,direction:t=`bottomup`,backgroundToken:n=``,onPlotContextMenu:r}){let i=K(null),a=K(null),o=K(null),s=K(null),c=K(null),l=K(0),u=K(r);G(()=>{u.current=r},[r]);let d=K({nodes:e,direction:t});G(()=>{d.current={nodes:e,direction:t}},[e,t]);let f=ft(()=>{let t=GJ(e);return{roots:t,flat:KJ(t),numRows:qJ(t)+1}},[e]),p=K(f);G(()=>{p.current=f},[f]);function m(){if(s.current)return s.current;let e=o.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return s.current=n,n}function h(){let e=o.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function g(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function _(e,t,n,r,i){let a=HJ.left+e.x0*t,o=(e.x1-e.x0)*t;return{x:a,y:i===`topdown`?HJ.top+e.depth*UJ:HJ.top+n-(e.depth+1)*UJ,w:o,h:UJ-1}}function v(){let e=i.current;if(!e)return;let{w:t,h:n}=h(),r=g(e,t,n);if(!r)return;let{bg:a,muted:o}=m(),{nodes:s,direction:c}=d.current;if(r.fillStyle=a,r.fillRect(0,0,t,n),s.length===0){r.fillStyle=o,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,zV(r);return}let{flat:l,numRows:u}=p.current,f=t-HJ.left-HJ.right,v=u*UJ;for(let e of l){let t=_(e,f,v,u,c);if(!(t.w<1)&&(r.fillStyle=JJ(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,UJ-4)}px ${Q.mono}`,r.textAlign=`left`,r.textBaseline=`middle`;let n=e.name,i=Math.floor((t.w-4)/7),a=n.length>i?n.slice(0,i-1)+`…`:n;r.fillText(a,t.x+3,t.y+UJ/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-HJ.left-HJ.right,l*UJ,l,o);r.strokeStyle=`rgba(255,255,255,0.9)`,r.lineWidth=2,r.strokeRect(u.x+1,u.y+1,u.w-2,u.h-2);let f=`${i.name} (${i.value.toLocaleString()})`;r.font=`11px ${Q.mono}`;let m=r.measureText(f).width,v=Math.max(4,Math.min(t-m-8,u.x+u.w/2-m/2)),y=u.y<30?u.y+UJ+4:u.y-20;r.fillStyle=`rgba(0,0,0,0.8)`,r.fillRect(v-3,y-3,m+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(f,v,y)}let b=K(v);b.current=v;let x=K(null);x.current??=jH(()=>b.current(),()=>o.current);let S=()=>x.current.schedule(),C=()=>{TH(l.current),l.current=wH(y)};return W(()=>{x.current.now()}),W(()=>()=>x.current?.cancel(),[]),W(()=>{s.current=null,S()},[n]),G(()=>{let e=o.current;if(!e)return;let t=new AH(()=>{s.current=null,S(),C()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=a.current;if(!e)return;let t=e=>{e.preventDefault(),u.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),{direction:r}=d.current,{roots:i,flat:a,numRows:o}=p.current;if(i.length===0){c.current=null,C();return}let s=t.clientX-n.left,l=t.clientY-n.top,u=n.width-HJ.left-HJ.right,f=o*UJ,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)}},[]),vt(`div`,{ref:o,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:i,className:`chart-canvas`,role:`img`,"aria-label":`Flame graph`}),q(`canvas`,{ref:a,className:`chart-canvas chart-overlay`})]})}var XJ={top:24,right:24,bottom:52,left:56},ZJ=[`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`,`#facc15`,`#60a5fa`],QJ=.8;function $J(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 eY(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 tY({groups:e,columns:t,seriesNames:n,colors:r,mode:i=`grouped`,horizontal:a=!1,valueRange:o,backgroundToken:s=``,onPlotContextMenu:c}){let l=oU(),u=K(null),d=K(null),f=K(null),p=K(null),m=K(null),h=K(null),g=K(0),_=K(c);G(()=>{_.current=c},[c]);let v=K(null),y=ft(()=>{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=$J(e,t,n.length,i);return v.current={key:r,value:o},o},[e,t,n.length,i]),b=K({bars:y,seriesNames:n,colors:r,mode:i,horizontal:a,valueRange:o});G(()=>{b.current={bars:y,seriesNames:n,colors:r,mode:i,horizontal:a,valueRange:o}},[y,n,r,i,a,o]);let x=K({plot:null,failed:!1,key:``,data:null,size:``});W(()=>()=>{x.current.plot?.dispose(),x.current.plot=null},[]);let S=K({bars:null,view:``});function C(){if(m.current)return m.current;let e=p.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return m.current=n,n}function w(){let e=p.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||300)}}function T(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function E(e){let t=b.current.colors??[];return Array.from({length:e},(e,n)=>t[n]??ZJ[n%ZJ.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=$W(XJ,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=mH(d.current,BK),n.failed=!n.plot),!n.plot||!d.current)return null;let r=Math.min(2,window.devicePixelRatio||1),i=`${e}x${t}@${r}`;return n.size!==i&&(n.plot.resize(e,t,r),d.current.style.width=`${e}px`,d.current.style.height=`${t}px`,n.size=i),n.plot}function k(){let e=u.current;if(!e)return;let{w:t,h:n}=w(),r=T(e,t,n);if(!r)return;let{bg:i,muted:a,grid:o}=C(),{bars:s,seriesNames:c,mode:d,horizontal:f}=b.current;r.fillStyle=i,r.fillRect(0,0,t,n);let m=O(t,n);if(s.n===0||c.length===0){m?.keep([]),m?.render(),r.fillStyle=a,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,zV(r);return}let{lo:h,hi:g,top:_,left:v,plotW:y,plotH:k,tiny:A}=D(t,n),j=E(c.length),M=f?k:y,N=e=>f?v+(e-h)/(g-h)*y:_+k-(e-h)/(g-h)*k,P=e=>(f?_:v)+(e+.5)/s.n*M;l({left:v,top:_,width:y,height:k,...f?{x:{v0:h,v1:g}}:{y:{v0:h,v1:g}}}),r.strokeStyle=o,r.lineWidth=1;for(let e=0;e<=5;e++){let t=h+e/5*(g-h),n=N(t);r.beginPath(),f?(r.moveTo(n,_),r.lineTo(n,_+k)):(r.moveTo(v,n),r.lineTo(v+y,n)),r.stroke(),r.fillStyle=a,r.font=`9px ${Q.mono}`,!A&&(f?(r.textAlign=`center`,r.textBaseline=`top`,r.fillText(Pz(t,(g-h)/5),n,_+k+4)):(r.textAlign=`right`,r.textBaseline=`middle`,r.fillText(Pz(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},DH(p.current));let I=Math.min(2,window.devicePixelRatio||1),L=Math.max(1,Math.round(M*I)),R=j.map(e=>{let t=UV(e);return[t[0],t[1],t[2],QJ]}),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=eY(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=eY(s,d,L);r.globalAlpha=QJ;for(let t=0;t<e.x0.length;t++){r.fillStyle=j[e.k[t]];let n=P(e.x0[t]-.5),i=P(e.x1[t]-.5),a=N(e.y0[t]),o=N(e.y1[t]);f?r.fillRect(Math.min(a,o),n,Math.max(1,Math.abs(o-a)),Math.max(1,i-n)):r.fillRect(n,Math.min(a,o),Math.max(1,i-n),Math.max(1,Math.abs(o-a)))}r.globalAlpha=1}if(h<0&&g>0){let e=N(0);r.strokeStyle=a,r.lineWidth=1.5,r.beginPath(),f?(r.moveTo(e,_),r.lineTo(e,_+k)):(r.moveTo(v,e),r.lineTo(v+y,e)),r.stroke()}r.fillStyle=a,r.font=`9px ${Q.mono}`;let B=Math.max(1,Math.ceil(s.n/Math.max(1,Math.floor(M/(f?14:48)))));for(let e=0;e<(A?0:s.n);e+=B){let t=P(e),n=s.label(e),i=n.length>14?n.slice(0,13)+`…`:n;f?(r.textAlign=`right`,r.textBaseline=`middle`,r.fillText(i,v-4,t)):(r.textAlign=`center`,r.textBaseline=`top`,r.fillText(i,t,_+k+4))}if(c.length>1&&!A){let e=f?_-14:_+k+32,t=v;r.font=`9px ${Q.mono}`,r.textBaseline=`top`;for(let n=0;n<c.length&&(r.fillStyle=j[n],r.fillRect(t,e,10,8),r.fillStyle=a,r.textAlign=`left`,r.fillText(c[n],t+13,e),t+=r.measureText(c[n]).width+26,!(t>v+y-30));n++);}}function A(){let e=f.current;if(!e)return;let{w:t,h:n}=w(),r=T(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=h.current,{bars:a,seriesNames:o,horizontal:s}=b.current;if(i===null||i>=a.n)return;let{top:c,left:l,plotW:u,plotH:d}=D(t,n),p=s?d:u,m=(s?c:l)+(i+.5)/a.n*p,g=Math.max(1,p/a.n);r.fillStyle=`rgba(255,255,255,0.08)`,s?r.fillRect(l,m-g/2,u,g):r.fillRect(m-g/2,c,g,d);let _=a.values.map((e,t)=>`${o.length>1?o[t]+` `:``}${Fz(e[i])}`).join(` `),v=`${a.label(i)}: ${_}`;r.font=`11px ${Q.mono}`;let y=r.measureText(v).width,x=s?l+u/2:m,S=s?m:c+d/2,C=Math.max(4,Math.min(t-y-8,x-y/2)),E=S-28<c?S+10:S-24;r.fillStyle=`rgba(0,0,0,0.8)`,r.fillRect(C-3,E-3,y+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(v,C,E)}let j=K(k);j.current=k;let M=K(null);M.current??=jH(()=>j.current(),()=>p.current);let N=()=>{g.current||=wH(()=>{g.current=0,A()})};return W(()=>{M.current.now()},[y,n,r,i,a,o]),W(()=>()=>{M.current?.cancel(),TH(g.current)},[]),W(()=>{m.current=null,M.current.schedule()},[s]),G(()=>{let e=p.current;if(!e)return;let t=new AH(()=>{m.current=null,M.current.schedule(),N()});return t.observe(e),()=>t.disconnect()},[]),G(()=>{let e=f.current;if(!e)return;let t=e=>{e.preventDefault(),_.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),{bars:r,horizontal:i}=b.current,{w:a,h:o}=w(),{top:s,left:c,plotW:l,plotH:u}=D(a,o),d=i?t.clientY-n.top-s:t.clientX-n.left-c,f=i?u:l,p=d>=0&&d<f&&r.n>0?Math.min(r.n-1,Math.floor(d/f*r.n)):null;p!==h.current&&(h.current=p,N())},r=()=>{h.current=null,N()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),vt(`div`,{ref:p,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:u,className:`chart-canvas`,role:`img`,"aria-label":`Bar chart`}),q(`canvas`,{ref:d,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),q(`canvas`,{ref:f,className:`chart-canvas chart-overlay`})]})}var nY=[`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`];function rY(e,t){if(!t)return nY[e%nY.length];if(e===0)return t;let n=nY.filter(e=>e.toLowerCase()!==t.toLowerCase());return n[(e-1)%n.length]}var iY={top:36,right:36,bottom:36,left:36};function aY({axes:e,series:t,fill:n=!0,color:r,backgroundToken:i=``,onPlotContextMenu:a}){let o=K(null),s=K(null),c=K(null),l=K(null),u=K(a);G(()=>{u.current=a},[a]);let d=K({axes:e,series:t,fill:n,color:r});G(()=>{d.current={axes:e,series:t,fill:n,color:r}},[e,t,n,r]);function f(){if(l.current)return l.current;let e=c.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return l.current=n,n}function p(){let e=c.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||300)}}function m(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function h(){let e=o.current;if(!e)return;let{w:t,h:n}=p(),r=m(e,t,n);if(!r)return;let{bg:i,muted:a,grid:s}=f(),{axes:c,series:l,fill:u}=d.current;if(r.fillStyle=i,r.fillRect(0,0,t,n),c.length<3||l.length===0){r.fillStyle=a,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`Select ≥ 3 axes`,iY.left+8,iY.top+8);return}let h=c.length,g=t/2,_=n/2,v=Math.min(t-iY.left-iY.right,n-iY.top-iY.bottom)/2,y=c.map((e,t)=>{let n=0;for(let e of l){let r=e.values[t]??0;r>n&&(n=r)}return n||1});function b(e){return Math.PI*2*e/h-Math.PI/2}function x(e,t){let n=b(e);return{x:g+Math.cos(n)*v*t,y:_+Math.sin(n)*v*t}}for(let e=1;e<=4;e++){let t=e/4;r.beginPath();for(let e=0;e<h;e++){let n=x(e,t);e===0?r.moveTo(n.x,n.y):r.lineTo(n.x,n.y)}r.closePath(),r.strokeStyle=s,r.lineWidth=1,r.stroke()}r.strokeStyle=a,r.lineWidth=1;for(let e=0;e<h;e++){let t=x(e,1);r.beginPath(),r.moveTo(g,_),r.lineTo(t.x,t.y),r.stroke(),r.fillStyle=a,r.font=`10px ${Q.mono}`;let n=b(e),i=x(e,1+10/v);r.textAlign=Math.abs(Math.cos(n))<.1?`center`:Math.cos(n)<0?`right`:`left`,r.textBaseline=Math.abs(Math.sin(n))<.1?`middle`:Math.sin(n)<0?`bottom`:`top`;let o=c[e].length>12?c[e].slice(0,11)+`…`:c[e];r.fillText(o,i.x,i.y)}for(let e=0;e<l.length;e++){let t=l[e],n=rY(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=iY.left,i=n-iY.bottom-10;r.font=`9px ${Q.mono}`,r.textBaseline=`top`;for(let n=0;n<l.length&&(r.fillStyle=rY(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-iY.right-30));n++);}}let g=K(h);g.current=h;let _=K(null);_.current??=jH(()=>g.current(),()=>c.current);let v=()=>_.current.schedule();return W(()=>{_.current.now()}),W(()=>()=>_.current?.cancel(),[]),W(()=>{l.current=null,v()},[i]),G(()=>{let e=c.current;if(!e)return;let t=new AH(()=>{l.current=null,v()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=s.current;if(!e)return;let t=e=>{e.preventDefault(),u.current?.({clientX:e.clientX,clientY:e.clientY})};return e.addEventListener(`contextmenu`,t),()=>{e.removeEventListener(`contextmenu`,t)}},[]),vt(`div`,{ref:c,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`Radar chart`}),q(`canvas`,{ref:s,className:`chart-canvas chart-overlay`})]})}var oY={top:16,right:16,bottom:40,left:52},sY=[`#38bdf8`,`#4ade80`,`#fb7185`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`];function cY(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=>YK(e)),xLo:c,xHi:l,yLo:u,yHi:d}}function lY({series:e,stacked:t=!1,yRange:n,backgroundToken:r=``,onPlotContextMenu:i}){let a=oU(),o=K(null),s=K(null),c=K(null),l=K(null),u=K(null),d=K(null),f=K(0),p=K(i);G(()=>{p.current=i},[i]);let m=K(null),h=ft(()=>{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=cY(e,t);return m.current={series:e,stacked:t,value:r},r},[e,t]),g=K({series:e,prepared:h,yRange:n});G(()=>{g.current={series:e,prepared:h,yRange:n}},[e,h,n]);let _=K({plot:null,failed:!1,key:``,size:``});W(()=>()=>{_.current.plot?.dispose(),_.current.plot=null},[]);let v=K({prepared:null,view:``});function y(){if(u.current)return u.current;let e=l.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return u.current=n,n}function b(){let e=l.current;return{w:Math.max(1,e?.clientWidth||600),h:Math.max(1,e?.clientHeight||300)}}function x(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function S(e,t){let n=(e.xHi-e.xLo)*.01||.5,r=e.yLo,i=e.yHi;return i===r&&(i=r+1),i+=(i-r)*.05,t?.min!==void 0&&Number.isFinite(t.min)&&(r=t.min),t?.max!==void 0&&Number.isFinite(t.max)&&(i=t.max),{xLo:e.xLo-n,xHi:e.xHi+n,yLo:r,yHi:i}}function C(e,t,n,r,i){let a=e.x[t],o=e.hi[t],s=e.lo[t];if(!e.ascending[t]||a.length<=2*i)return{x:a,hi:o,lo:s??new Float64Array(a.length)};let c=KK(a,o,n,r,i);return{x:JK(a,c),hi:JK(o,c),lo:s?JK(s,c):new Float64Array(c.length)}}function w(){let e=o.current;if(!e)return;let{w:n,h:r}=b(),i=x(e,n,r);if(!i)return;let{bg:s,muted:c,grid:u}=y(),{series:d,prepared:f,yRange:p}=g.current;i.fillStyle=s,i.fillRect(0,0,n,r);let m=_.current.plot;if(d.length===0){m?.keep([]),m?.render(),i.fillStyle=c,i.font=`13px ${Q.sans}`,i.textAlign=`left`,i.textBaseline=`top`,zV(i);return}let h=$W(oY,n,r),{top:w,right:D,bottom:O,left:k}=h,A=n-k-D,j=r-w-O,{xLo:M,xHi:N,yLo:P,yHi:F}=S(f,p),I=e=>k+(e-M)/(N-M)*A,L=e=>w+j-(e-P)/(F-P)*j;a({left:k,top:w,width:A,height:j,x:{v0:M,v1:N},y:{v0:P,v1:F}}),i.strokeStyle=u,i.lineWidth=1;for(let e=0;e<=5;e++){let t=P+e/5*(F-P),n=L(t);i.beginPath(),i.moveTo(k,n),i.lineTo(k+A,n),i.stroke(),i.fillStyle=c,i.font=`9px ${Q.mono}`,i.textAlign=`right`,i.textBaseline=`middle`,h.tiny||i.fillText(Pz(t,(F-P)/5),k-4,n)}let R=Math.min(8,f.x[0]?.length??5);for(let e=0;e<=R;e++){let t=M+e/R*(N-M),n=I(t);i.beginPath(),i.moveTo(n,w),i.lineTo(n,w+j),i.stroke(),i.fillStyle=c,i.font=`9px ${Q.mono}`,i.textAlign=`center`,i.textBaseline=`top`,h.tiny||i.fillText(Pz(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},DH(l.current));let B=E(n,r),V=Math.min(2,window.devicePixelRatio||1),ee=Math.max(1,Math.round(A*V)),te=d.map((e,t)=>UV(sY[t%sY.length]));if(B){let e=`${M}|${N}|${ee}`;if(_.current.key!==e||T.current!==f){let n=[];for(let e=0;e<d.length;e++){let r=C(f,e,M,N,ee),i=te[e],a=[i[0],i[1],i[2],f.lo[e]||t?.7:.25];B.setBands(`b${e}`,r.x,r.lo,r.hi,a),B.setLine(`l${e}`,r.x,r.hi,i,1),n.push(`b${e}`,`l${e}`)}B.keep(n),_.current.key=e,T.current=f}B.setView(M,N,P,F,{left:k,top:w,width:A,height:j}),B.render()}else for(let e=0;e<d.length;e++){let n=C(f,e,M,N,ee),r=sY[e%sY.length];i.save(),i.beginPath(),i.rect(k,w,A,j),i.clip(),i.beginPath();for(let e=0;e<n.x.length;e++){let t=I(n.x[e]);e===0?i.moveTo(t,L(n.lo[e])):i.lineTo(t,L(n.lo[e]))}for(let e=n.x.length-1;e>=0;e--)i.lineTo(I(n.x[e]),L(n.hi[e]));i.closePath(),i.fillStyle=r,i.globalAlpha=f.lo[e]||t?.7:.25,i.fill(),i.beginPath();for(let e=0;e<n.x.length;e++){let t=I(n.x[e]),r=L(n.hi[e]);e===0?i.moveTo(t,r):i.lineTo(t,r)}i.globalAlpha=1,i.strokeStyle=r,i.lineWidth=1,i.stroke(),i.restore()}if(d.length>1&&!h.tiny){let e=k,t=w+j+24;i.font=`9px ${Q.mono}`,i.textBaseline=`top`;for(let n=0;n<d.length&&(i.fillStyle=sY[n%sY.length],i.fillRect(e,t,10,8),i.fillStyle=c,i.textAlign=`left`,i.fillText(d[n].name,e+13,t),e+=i.measureText(d[n].name).width+26,!(e>k+A-30));n++);}}let T=K(null);function E(e,t){let n=_.current;if(!n.plot&&!n.failed&&s.current&&(n.plot=mH(s.current,BK),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}=$W(oY,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=${Fz(m+(i-u)/_*(h-m))}`;r.font=`11px ${Q.mono}`;let y=r.measureText(v).width,C=Math.max(4,Math.min(t-y-8,i-y/2));r.fillStyle=`rgba(0,0,0,0.7)`,r.fillRect(C-3,s-3,y+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(v,C,s)}let O=K(w);O.current=w;let k=K(null);k.current??=jH(()=>O.current(),()=>l.current);let A=()=>{f.current||=wH(()=>{f.current=0,D()})};return W(()=>{k.current.now()},[e,h,n]),W(()=>()=>{k.current?.cancel(),TH(f.current)},[]),W(()=>{u.current=null,k.current.schedule()},[r]),G(()=>{let e=l.current;if(!e)return;let t=new AH(()=>{u.current=null,k.current.schedule(),A()});return t.observe(e),()=>t.disconnect()},[]),G(()=>{let e=c.current;if(!e)return;let t=e=>{e.preventDefault(),p.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect();d.current=t.clientX-n.left,A()},r=()=>{d.current=null,A()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),vt(`div`,{ref:l,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`Area chart`}),q(`canvas`,{ref:s,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),q(`canvas`,{ref:c,className:`chart-canvas chart-overlay`})]})}var uY={top:16,right:16,bottom:40,left:52},dY=[`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`];function fY({series:e,complement:t=!1,logX:n=!1,backgroundToken:r=``,onPlotContextMenu:i}){let a=oU(),o=K(null),s=K(null),c=K(null),l=K(null),u=K(null),d=K(0),f=K(i);G(()=>{f.current=i},[i]);let p=K({series:e,complement:t,logX:n});G(()=>{p.current={series:e,complement:t,logX:n}},[e,t,n]);let m=ft(()=>{let t=e.map(e=>Float64Array.from(e.values).sort()),n=1/0,r=-1/0;for(let e of t)e.length&&(n=Math.min(n,e[0]),r=Math.max(r,e[e.length-1]));return{all:t,xLo:n,xHi:r}},[e]),h=K(m);G(()=>{h.current=m},[m]);function g(){if(l.current)return l.current;let e=c.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return l.current=n,n}function _(){let e=c.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||300)}}function v(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function y(){let e=o.current;if(!e)return;let{w:t,h:n}=_(),r=v(e,t,n);if(!r)return;let{bg:i,muted:s,grid:c}=g(),{series:l,complement:u,logX:d}=p.current;if(r.fillStyle=i,r.fillRect(0,0,t,n),l.length===0){r.fillStyle=s,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,zV(r);return}let{top:f,right:m,bottom:y,left:b}=uY,x=t-b-m,S=n-f-y,{xLo:C,xHi:w}=h.current;Number.isFinite(C)||(C=0,w=1);let T=e=>Math.log10(Math.max(1e-10,e)),E=d?T(C):C,D=d?T(w):w,O=e=>b+((d?T(e):e)-E)/(D-E||1)*x,k=e=>f+S-e*S;a({left:b,top:f,width:x,height:S,x:{v0:C,v1:w,log:d}});for(let e=0;e<=5;e++){let t=e/5,n=k(t);r.strokeStyle=c,r.lineWidth=1,r.beginPath(),r.moveTo(b,n),r.lineTo(b+x,n),r.stroke(),r.fillStyle=s,r.font=`9px ${Q.mono}`,r.textAlign=`right`,r.textBaseline=`middle`,r.fillText(String(t.toFixed(2)),b-4,n)}for(let e=0;e<=6;e++){let t=C+e/6*(w-C),n=O(t);r.strokeStyle=c,r.lineWidth=1,r.beginPath(),r.moveTo(n,f),r.lineTo(n,f+S),r.stroke(),r.fillStyle=s,r.font=`9px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`top`,r.fillText(Pz(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=dY[e%dY.length],r.lineWidth=1,r.stroke()}if(l.length>1){let e=b,t=f+S+24;r.font=`9px ${Q.mono}`,r.textBaseline=`top`;for(let n=0;n<l.length&&(r.fillStyle=dY[n%dY.length],r.fillRect(e,t,16,2),r.fillStyle=s,r.textAlign=`left`,r.fillText(l[n].name,e+20,t-3),e+=r.measureText(l[n].name).width+30,!(e>b+x-30));n++);}r.save(),r.translate(12,f+S/2),r.rotate(-Math.PI/2),r.fillStyle=s,r.font=`9px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`middle`,r.fillText(u?`CCDF`:`CDF`,0,0),r.restore()}function b(){let e=s.current;if(!e)return;let{w:t,h:n}=_(),r=v(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=u.current;if(i===null)return;let{top:a,left:o,right:c}=uY,l=n-a-uY.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=Fz(f+(i-o)/d*(p-f));r.font=`11px ${Q.mono}`;let g=r.measureText(m).width,y=Math.max(4,Math.min(t-g-8,i-g/2));r.fillStyle=`rgba(0,0,0,0.7)`,r.fillRect(y-3,a+l+2,g+6,16),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(m,y,a+l+4)}let x=K(y);x.current=y;let S=K(null);S.current??=jH(()=>x.current(),()=>c.current);let C=()=>S.current.schedule(),w=()=>{TH(d.current),d.current=wH(b)};return W(()=>{S.current.now()}),W(()=>()=>S.current?.cancel(),[]),W(()=>{l.current=null,C()},[r]),G(()=>{let e=c.current;if(!e)return;let t=new AH(()=>{l.current=null,C(),w()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=s.current;if(!e)return;let t=e=>{e.preventDefault(),f.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect();u.current=t.clientX-n.left,w()},r=()=>{u.current=null,w()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),vt(`div`,{ref:c,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`CDF chart`}),q(`canvas`,{ref:s,className:`chart-canvas chart-overlay`})]})}var pY={top:16,right:40,bottom:40,left:52},mY=[`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`,`#facc15`,`#60a5fa`];function hY(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 gY(e){let[t,n,r]=hY(e);return`rgb(${t},${n},${r})`}var _Y=(()=>{let e=new Uint8Array(1024);for(let t=0;t<256;t++)e.set([...hY(t/255),255],t*4);return e})(),vY=()=>{let e=new Uint8Array(1024);for(let t=0;t<256;t++){let[n,r,i]=eK(mY[t%mY.length],1);e.set([n*255,r*255,i*255,255],t*4)}return e};function yY(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 bY({points:e,color:t=`#64748b`,colorByNumeric:n=!1,maxRadius:r=24,backgroundToken:i=``,onPlotContextMenu:a}){let o=oU(),s=K(null),c=K(null),l=K(null),u=K(null),d=K(null),f=K(null),p=K(0),m=K(a);G(()=>{m.current=a},[a]);let h=ft(()=>yY(e,n,r),[e,n,r]),g=K({points:e,color:t,colorByNumeric:n,maxRadius:r,model:h});G(()=>{g.current={points:e,color:t,colorByNumeric:n,maxRadius:r,model:h}},[e,t,n,r,h]);let _=K({r:null,failed:!1,size:``,model:null,style:``});W(()=>()=>{_.current.r?.dispose(),_.current.r=null},[]);function v(){if(d.current)return d.current;let e=u.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return d.current=n,n}function y(){let e=u.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||300)}}function b(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function x(e,t){let{xLo:n,xHi:r,yLo:i,yHi:a}=g.current.model.ext,{top:s,right:c,bottom:l,left:u}=pY,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=mH(c.current,ZW),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,DH(u.current));let l=`${o.mode}|${s}`;return n.style!==l&&(r.setStyle(o.mode===`single`?{kind:`single`,rgba:eK(s,1)}:{kind:o.mode,palette:o.mode===`colormap`?_Y:vY()},3,.65),r.setDraw(!0,!1,0),n.style=l),r}function C(){let e=s.current;if(!e)return;let{w:t,h:n}=y(),r=b(e,t,n);if(!r)return;let{bg:i,muted:a,grid:o}=v(),{points:c,color:l,colorByNumeric:u,model:d}=g.current;r.fillStyle=i,r.fillRect(0,0,t,n);let f=S(t,n);if(c.length===0){f?.setData([],[]),_.current.model=null,f?.render(),r.fillStyle=a,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,zV(r);return}let{xLo:p,xHi:m,yLo:h,yHi:C}=d.ext,{top:w,left:T}=pY,{plotW:E,plotH:D,xToPx:O,yToPx:k}=x(t,n);r.strokeStyle=o,r.lineWidth=1;for(let e=0;e<=5;e++){let t=p+e/5*(m-p),n=O(t);r.beginPath(),r.moveTo(n,w),r.lineTo(n,w+D),r.stroke(),r.fillStyle=a,r.font=`9px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`top`,r.fillText(Pz(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(Pz(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`?gY(n):d.mode===`dataset`?mY[n%mY.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-pY.bottom-10;r.font=`9px ${Q.mono}`,r.textBaseline=`top`;for(let n=0;n<A.length;n++){let i=A[n];if(r.fillStyle=mY[n%mY.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(`(${Fz(a.x[i])}, ${Fz(a.y[i])})`),m.push(`size=${Fz(a.size[i])}`);let _=a.colorIndex?.[i];_!==void 0&&_>=0&&a.colorLabels?m.push(a.colorLabels[_]):a.colorValue&&m.push(Fz(a.colorValue[i]));let v=m.join(` · `);r.font=`11px ${Q.mono}`;let S=r.measureText(v).width,C=Math.max(4,Math.min(t-S-8,d+u+4)),w=p-20<pY.top?p+u+4:p-20;r.fillStyle=`rgba(0,0,0,0.8)`,r.fillRect(C-3,w-3,S+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(v,C,w)}let T=K(C);T.current=C;let E=K(null);E.current??=jH(()=>T.current(),()=>u.current);let D=()=>E.current.schedule(),O=()=>{TH(p.current),p.current=wH(w)};return W(()=>{E.current.now()}),W(()=>()=>E.current?.cancel(),[]),W(()=>{d.current=null,D()},[i]),G(()=>{let e=u.current;if(!e)return;let t=new AH(()=>{d.current=null,D(),O()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=l.current;if(!e)return;let t=null,n=e=>{e.preventDefault(),m.current?.({clientX:e.clientX,clientY:e.clientY})},r=n=>{let r=e.getBoundingClientRect(),{points:i,maxRadius:a,model:o}=g.current,{w:s,h:c}=y(),{plotW:l,plotH:u,xToPx:d,yToPx:p}=x(s,c),m=e=>d(i.x[e])-pY.left,h=e=>p(i.y[e])-pY.top,_=a+6,v=`${s}|${c}|${_}`;(!t||t.model!==o||t.key!==v)&&(t={model:o,key:v,g:MJ(i.length,l,u,_,m,h)}),f.current=NJ(t.g,n.clientX-r.left-pY.left,n.clientY-r.top-pY.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)}},[]),vt(`div`,{ref:u,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:s,className:`chart-canvas`,role:`img`,"aria-label":`Bubble chart`}),q(`canvas`,{ref:c,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),q(`canvas`,{ref:l,className:`chart-canvas chart-overlay`})]})}var xY={top:8,right:8,bottom:8,left:8},SY=[`#f97316`,`#38bdf8`,`#4ade80`,`#a78bfa`,`#fbbf24`,`#fb7185`,`#34d399`,`#e879f9`,`#facc15`,`#60a5fa`];function CY(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 wY(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?u:d),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?u:d),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=wY(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 TY({nodes:e,backgroundToken:t=``,onPlotContextMenu:n}){let r=K(null),i=K(null),a=K(null),o=K(null),s=K([]),c=K(null),l=K(0),u=K(n);G(()=>{u.current=n},[n]);let d=K({nodes:e});G(()=>{d.current={nodes:e}},[e]);let f=ft(()=>CY(e),[e]),p=K(f);G(()=>{p.current=f},[f]);function m(){if(o.current)return o.current;let e=a.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return o.current=n,n}function h(){let e=a.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||300)}}function g(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function _(){let e=r.current;if(!e)return;let{w:t,h:n}=h(),i=g(e,t,n);if(!i)return;let{bg:a,muted:o}=m(),{nodes:l}=d.current;if(i.fillStyle=a,i.fillRect(0,0,t,n),l.length===0){i.fillStyle=o,i.font=`13px ${Q.sans}`,i.textAlign=`left`,i.textBaseline=`top`,zV(i);return}let u=p.current,f=t-xY.left-xY.right,_=n-xY.top-xY.bottom,v=wY(u,xY.left,xY.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=SY[l%SY.length],d=c.current===e;if(i.fillStyle=u,i.globalAlpha=d?.95:.75,i.fillRect(n,r,o,s),i.globalAlpha=1,i.strokeStyle=a,i.lineWidth=1,i.strokeRect(n,r,o,s),o>20&&s>14){i.fillStyle=`rgba(0,0,0,0.75)`,i.font=`${Math.min(11,s-4)}px ${Q.mono}`,i.textAlign=`left`,i.textBaseline=`top`;let e=Math.floor((o-4)/6),a=t.name.length>e?t.name.slice(0,e-1)+`…`:t.name;i.fillText(a,n+3,r+3)}}i.globalAlpha=1}function v(){let e=i.current;if(!e)return;let{w:t,h:n}=h(),r=g(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let a=c.current;if(a===null)return;let o=s.current;if(a<0||a>=o.length)return;let{node:l,x:u,y:d,w:f,h:p}=o[a];r.strokeStyle=`rgba(255,255,255,0.9)`,r.lineWidth=2,r.strokeRect(u+1,d+1,f-2,p-2);let m=`${l.name}: ${l.value.toLocaleString()}`;r.font=`11px ${Q.mono}`;let _=r.measureText(m).width,v=Math.max(4,Math.min(t-_-8,u+f/2-_/2)),y=d<30?d+p+4:d-20;r.fillStyle=`rgba(0,0,0,0.8)`,r.fillRect(v-3,y-3,_+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(m,v,y)}let y=K(_);y.current=_;let b=K(null);b.current??=jH(()=>y.current(),()=>a.current);let x=()=>b.current.schedule(),S=()=>{TH(l.current),l.current=wH(v)};return W(()=>{b.current.now()}),W(()=>()=>b.current?.cancel(),[]),W(()=>{o.current=null,x()},[t]),G(()=>{let e=a.current;if(!e)return;let t=new AH(()=>{o.current=null,x(),S()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=i.current;if(!e)return;let t=e=>{e.preventDefault(),u.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),r=t.clientX-n.left,i=t.clientY-n.top,a=s.current,o=null;for(let e=0;e<a.length;e++){let t=a[e];r>=t.x&&r<=t.x+t.w&&i>=t.y&&i<=t.y+t.h&&(o=e)}c.current=o,S()},r=()=>{c.current=null,S()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),vt(`div`,{ref:a,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:r,className:`chart-canvas`,role:`img`,"aria-label":`Treemap`}),q(`canvas`,{ref:i,className:`chart-canvas chart-overlay`})]})}var EY={top:8,right:8,bottom:8,left:8},DY=14,OY=8,kY=[`#38bdf8`,`#4ade80`,`#fb7185`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`,`#facc15`,`#60a5fa`];function AY(e,t,n,r){if(e.length===0||t.length===0)return{nodes:[],links:[]};let i=n-EY.left-EY.right,a=r-EY.top-EY.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=>EY.left+e/Math.max(1,c)*(i-DY),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)*OY,i=0;for(let e of n)i+=Math.max(8,(d.get(e)??0)/f*r*.8);let o=EY.top+(a-i-(n.length-1)*OY)/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:kY[e.indexOf(a)%kY.length]}),o+=s+OY}}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+DY,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 jY({nodeNames:e,links:t,backgroundToken:n=``,onPlotContextMenu:r}){let i=K(null),a=K(null),o=K(null),s=K(null),c=K({nodes:[],links:[]}),l=K(null),u=K(0),d=K(r);G(()=>{d.current=r},[r]);let f=K({nodeNames:e,links:t});G(()=>{f.current={nodeNames:e,links:t}},[e,t]);function p(){if(s.current)return s.current;let e=o.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return s.current=n,n}function m(){let e=o.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||300)}}function h(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function g(){let e=i.current;if(!e)return;let{w:t,h:n}=m(),r=h(e,t,n);if(!r)return;let{bg:a,muted:o}=p(),{nodeNames:s,links:u}=f.current;if(r.fillStyle=a,r.fillRect(0,0,t,n),s.length===0||u.length===0){r.fillStyle=o,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,zV(r);return}let d=AY(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,DY,e.h),r.globalAlpha=1,r.fillStyle=o,r.font=`9px ${Q.mono}`,r.textBaseline=`middle`,e.x>t/2?(r.textAlign=`right`,r.fillText(e.name,e.x-3,e.y+e.h/2)):(r.textAlign=`left`,r.fillText(e.name,e.x+DY+3,e.y+e.h/2));r.globalAlpha=1}function _(){let e=a.current;if(!e)return;let{w:t,h:n}=m(),r=h(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=l.current;if(i===null)return;let o=c.current;if(i<0||i>=o.links.length)return;let s=o.links[i],u=s.label;r.font=`11px ${Q.mono}`;let d=r.measureText(u).width,f=Math.max(4,Math.min(t-d-8,(s.sx+s.tx)/2-d/2)),p=Math.max(4,(s.sy+s.ty)/2-10);r.fillStyle=`rgba(0,0,0,0.8)`,r.fillRect(f-3,p-3,d+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(u,f,p)}let v=K(g);v.current=g;let y=K(null);y.current??=jH(()=>v.current(),()=>o.current);let b=()=>y.current.schedule(),x=()=>{TH(u.current),u.current=wH(_)};return W(()=>{y.current.now()}),W(()=>()=>y.current?.cancel(),[]),W(()=>{s.current=null,b()},[n]),G(()=>{let e=o.current;if(!e)return;let t=new AH(()=>{s.current=null,b(),x()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=a.current;if(!e)return;let t=e=>{e.preventDefault(),d.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),r=t.clientX-n.left,i=t.clientY-n.top,a=c.current,o=null;for(let e=0;e<a.links.length;e++){let t=a.links[e];if(r>=t.sx&&r<=t.tx&&Math.abs(i-(t.sy+t.ty)/2)<t.h/2+6){o=e;break}}l.current=o,x()},r=()=>{l.current=null,x()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),vt(`div`,{ref:o,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:i,className:`chart-canvas`,role:`img`,"aria-label":`Sankey diagram`}),q(`canvas`,{ref:a,className:`chart-canvas chart-overlay`})]})}var MY={top:24,right:24,bottom:52,left:52};function NY({bins:e,color:t=`#38bdf8`,backgroundToken:n=``,onPlotContextMenu:r}){let i=K(null),a=K(null),o=K(null),s=K(null),c=K(null),l=K(0),u=K(r);G(()=>{u.current=r},[r]);let d=K({bins:e,color:t});G(()=>{d.current={bins:e,color:t}},[e,t]);function f(){if(s.current)return s.current;let e=o.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return s.current=n,n}function p(){let e=o.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||300)}}function m(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function h(){let e=i.current;if(!e)return;let{w:t,h:n}=p(),r=m(e,t,n);if(!r)return;let{bg:a,muted:o,grid:s}=f(),{bins:l,color:u}=d.current;if(r.fillStyle=a,r.fillRect(0,0,t,n),l.length===0){r.fillStyle=o,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,zV(r);return}let{top:h,right:g,bottom:_,left:v}=MY,y=t-v-g,b=n-h-_,x=e=>v+e*y,S=e=>h+(1-e)*b;for(let e=0;e<=5;e++){let t=e/5;r.strokeStyle=s,r.lineWidth=1,r.beginPath(),r.moveTo(v,S(t)),r.lineTo(v+y,S(t)),r.stroke(),r.beginPath(),r.moveTo(x(t),h),r.lineTo(x(t),h+b),r.stroke(),r.fillStyle=o,r.font=`9px ${Q.mono}`,r.textAlign=`right`,r.textBaseline=`middle`,r.fillText(t.toFixed(2),v-4,S(t)),r.textAlign=`center`,r.textBaseline=`top`,r.fillText(t.toFixed(2),x(t),h+b+4)}r.strokeStyle=o,r.lineWidth=1.5,r.setLineDash([6,4]),r.beginPath(),r.moveTo(x(0),S(0)),r.lineTo(x(1),S(1)),r.stroke(),r.setLineDash([]);let C=Math.max(1,...l.map(e=>e.count)),w=b*.15;for(let e of l){let t=Math.max(1,y/l.length*.7),n=x(e.center)-t/2,i=e.count/C*w;r.fillStyle=u,r.globalAlpha=.3,r.fillRect(n,h+b-i,t,i)}r.globalAlpha=1,r.beginPath();for(let e=0;e<l.length;e++){let t=x(l[e].center),n=S(l[e].actual);e===0?r.moveTo(t,n):r.lineTo(t,n)}r.strokeStyle=u,r.lineWidth=1,r.stroke();for(let e=0;e<l.length;e++){let t=c.current===e;r.beginPath(),r.arc(x(l[e].center),S(l[e].actual),t?6:4,0,Math.PI*2),r.fillStyle=u,r.globalAlpha=t?1:.85,r.fill()}r.globalAlpha=1,r.fillStyle=o,r.font=`10px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`bottom`,r.fillText(`Predicted probability`,v+y/2,n-4),r.save(),r.translate(12,h+b/2),r.rotate(-Math.PI/2),r.textAlign=`center`,r.textBaseline=`middle`,r.fillText(`Actual rate`,0,0),r.restore()}function g(){let e=a.current;if(!e)return;let{w:t,h:n}=p(),r=m(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=c.current;if(i===null)return;let{bins:o}=d.current;if(i<0||i>=o.length)return;let s=o[i],{top:l,left:u}=MY,f=t-u-MY.right,h=n-l-MY.bottom,g=u+s.center*f,_=l+(1-s.actual)*h,v=`pred=${s.center.toFixed(2)} actual=${s.actual.toFixed(3)} n=${s.count}`;r.font=`11px ${Q.mono}`;let y=r.measureText(v).width,b=Math.max(4,Math.min(t-y-8,g-y/2)),x=_-28<l?_+12:_-24;r.fillStyle=`rgba(0,0,0,0.8)`,r.fillRect(b-3,x-3,y+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(v,b,x)}let _=K(h);_.current=h;let v=K(null);v.current??=jH(()=>_.current(),()=>o.current);let y=()=>v.current.schedule(),b=()=>{TH(l.current),l.current=wH(g)};return W(()=>{v.current.now()}),W(()=>()=>v.current?.cancel(),[]),W(()=>{s.current=null,y()},[n]),G(()=>{let e=o.current;if(!e)return;let t=new AH(()=>{s.current=null,y(),b()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=a.current;if(!e)return;let t=e=>{e.preventDefault(),u.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),{bins:r}=d.current,{w:i}=p(),a=t.clientX-n.left,o=i-MY.left-MY.right,s=-1,l=20;for(let e=0;e<r.length;e++){let t=MY.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)}},[]),vt(`div`,{ref:o,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:i,className:`chart-canvas`,role:`img`,"aria-label":`Calibration curve`}),q(`canvas`,{ref:a,className:`chart-canvas chart-overlay`})]})}var PY={top:24,right:24,bottom:48,left:52};function FY({points:e,color:t=`#a78bfa`,backgroundToken:n=``,onPlotContextMenu:r}){let i=oU(),a=K(null),o=K(null),s=K(null),c=K(null),l=K(null),u=K(0),d=K(r);G(()=>{d.current=r},[r]);let f=K({points:e,color:t});G(()=>{f.current={points:e,color:t}},[e,t]);function p(){if(c.current)return c.current;let e=s.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return c.current=n,n}function m(){let e=s.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||300)}}function h(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function g(){let{points:e}=f.current,t=1/0,n=-1/0,r=1/0,i=-1/0;if(e.length>0&&(t=e.theoretical[0],n=e.theoretical[e.length-1],r=e.sample[0],i=e.sample[e.length-1]),!Number.isFinite(t))return{xLo:-3,xHi:3,yLo:-3,yHi:3};let a=(n-t)*.05||.5,o=(i-r)*.05||.5;return{xLo:t-a,xHi:n+a,yLo:r-o,yHi:i+o}}function _(){let e=a.current;if(!e)return;let{w:t,h:n}=m(),r=h(e,t,n);if(!r)return;let{bg:o,muted:s,grid:c}=p(),{points:u,color:d}=f.current;if(r.fillStyle=o,r.fillRect(0,0,t,n),u.length===0){r.fillStyle=s,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,zV(r);return}let{xLo:_,xHi:v,yLo:y,yHi:b}=g(),{top:x,right:S,bottom:C,left:w}=PY,T=t-w-S,E=n-x-C,D=e=>w+(e-_)/(v-_)*T,O=e=>x+(1-(e-y)/(b-y))*E;i({left:w,top:x,width:T,height:E,x:{v0:_,v1:v}}),r.strokeStyle=c,r.lineWidth=1;for(let e=0;e<=5;e++){let t=_+e/5*(v-_),n=D(t);r.beginPath(),r.moveTo(n,x),r.lineTo(n,x+E),r.stroke(),r.fillStyle=s,r.font=`9px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`top`,r.fillText(Pz(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(Pz(i,(b-y)/5),w-4,a)}let k=Math.max(_,y),A=Math.min(v,b);k<A&&(r.strokeStyle=s,r.lineWidth=1.5,r.setLineDash([6,4]),r.beginPath(),r.moveTo(D(k),O(k)),r.lineTo(D(A),O(A)),r.stroke(),r.setLineDash([])),r.fillStyle=d,r.globalAlpha=.75;let j=NaN,M=NaN;for(let e=0;e<u.length;e++){let t=Math.round(D(u.theoretical[e])),n=Math.round(O(u.sample[e]));t===j&&n===M||(j=t,M=n,r.beginPath(),r.arc(t,n,3,0,Math.PI*2),r.fill())}let N=l.current;N!==null&&N<u.length&&(r.globalAlpha=1,r.beginPath(),r.arc(D(u.theoretical[N]),O(u.sample[N]),5,0,Math.PI*2),r.fill()),r.globalAlpha=1,r.fillStyle=s,r.font=`10px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`bottom`,r.fillText(`Theoretical quantiles`,w+T/2,n-4),r.save(),r.translate(12,x+E/2),r.rotate(-Math.PI/2),r.textAlign=`center`,r.textBaseline=`middle`,r.fillText(`Sample quantiles`,0,0),r.restore()}function v(){let e=o.current;if(!e)return;let{w:t,h:n}=m(),r=h(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=l.current;if(i===null)return;let{points:a}=f.current;if(i<0||i>=a.length)return;let s={theoretical:a.theoretical[i],sample:a.sample[i]},{xLo:c,xHi:u,yLo:d,yHi:p}=g(),{top:_,left:v}=PY,y=t-v-PY.right,b=n-_-PY.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=`(${Fz(s.theoretical)}, ${Fz(s.sample)})`;r.font=`11px ${Q.mono}`;let w=r.measureText(C).width,T=Math.max(4,Math.min(t-w-8,x+10)),E=S-20<_?S+10:S-20;r.fillStyle=`rgba(0,0,0,0.8)`,r.fillRect(T-3,E-3,w+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(C,T,E)}let y=K(_);y.current=_;let b=K(null);b.current??=jH(()=>y.current(),()=>s.current);let x=()=>b.current.schedule(),S=()=>{TH(u.current),u.current=wH(v)};return W(()=>{b.current.now()}),W(()=>()=>b.current?.cancel(),[]),W(()=>{c.current=null,x()},[n]),G(()=>{let e=s.current;if(!e)return;let t=new AH(()=>{c.current=null,x(),S()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=o.current;if(!e)return;let t=e=>{e.preventDefault(),d.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),{points:r}=f.current,{w:i}=m(),{xLo:a,xHi:o,yLo:s,yHi:c}=g(),{top:u,left:d}=PY,p=i-d-PY.right,h=n.height-u-PY.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)}},[]),vt(`div`,{ref:s,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:a,className:`chart-canvas`,role:`img`,"aria-label":`Q-Q plot`}),q(`canvas`,{ref:o,className:`chart-canvas chart-overlay`})]})}var IY={top:8,right:16,bottom:40,left:120},LY=22,RY=3,zY=[`#38bdf8`,`#4ade80`,`#fb7185`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`,`#facc15`,`#60a5fa`];function BY({tasks:e,backgroundToken:t=``,onPlotContextMenu:n}){let r=oU(),i=K(null),a=K(null),o=K(null),s=K(null),c=K(null),l=K(0),u=K(n);G(()=>{u.current=n},[n]);let d=K({tasks:e});G(()=>{d.current={tasks:e}},[e]);function f(){if(s.current)return s.current;let e=o.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return s.current=n,n}function p(){let e=o.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||300)}}function m(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function h(){let e=i.current;if(!e)return;let{w:t,h:n}=p(),a=m(e,t,n);if(!a)return;let{bg:o,muted:s,grid:l}=f(),{tasks:u}=d.current;if(a.fillStyle=o,a.fillRect(0,0,t,n),u.length===0){a.fillStyle=s,a.font=`13px ${Q.sans}`,a.textAlign=`left`,a.textBaseline=`top`,zV(a);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}=IY,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*(LY+RY)+v;a.beginPath(),a.moveTo(n,v),a.lineTo(n,r),a.stroke(),a.fillStyle=s,a.font=`9px ${Q.mono}`,a.textAlign=`center`,a.textBaseline=`top`,a.fillText(Pz(t,(g-h)/T),n,r+4)}for(let e=0;e<u.length;e++){let t=u[e],n=v+e*(LY+RY),r=zY[(w.get(t.group??t.label)??0)%zY.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,LY-RY),a.globalAlpha=1,a.fillStyle=s,a.font=`9px ${Q.mono}`,a.textAlign=`right`,a.textBaseline=`middle`;let f=t.label.length>16?t.label.slice(0,15)+`…`:t.label;a.fillText(f,x-4,n+(LY-RY)/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}: ${Fz(s.start)} → ${Fz(s.end)} (${Fz(l)})`;r.font=`11px ${Q.mono}`;let f=r.measureText(u).width,h=1/0,g=-1/0;for(let e of o)e.start<h&&(h=e.start),e.end>g&&(g=e.end);let _=(g-h)*.02||1;h-=_,g+=_;let v=t-IY.left-IY.right,y=e=>IY.left+(e-h)/(g-h)*v,b=IY.top+i*(LY+RY),x=(y(s.start)+y(s.end))/2,S=Math.max(4,Math.min(t-f-8,x-f/2)),C=b-22<IY.top?b+LY+4:b-20;r.fillStyle=`rgba(0,0,0,0.8)`,r.fillRect(S-3,C-3,f+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(u,S,C)}let _=K(h);_.current=h;let v=K(null);v.current??=jH(()=>_.current(),()=>o.current);let y=()=>v.current.schedule(),b=()=>{TH(l.current),l.current=wH(g)};return W(()=>{v.current.now()}),W(()=>()=>v.current?.cancel(),[]),W(()=>{s.current=null,y()},[t]),G(()=>{let e=o.current;if(!e)return;let t=new AH(()=>{s.current=null,y(),b()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=a.current;if(!e)return;let t=e=>{e.preventDefault(),u.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),{tasks:r}=d.current,i=t.clientY-n.top,a=Math.floor((i-IY.top)/(LY+RY));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)}},[]),vt(`div`,{ref:o,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:i,className:`chart-canvas`,role:`img`,"aria-label":`Gantt chart`}),q(`canvas`,{ref:a,className:`chart-canvas chart-overlay`})]})}var VY=e=>[...e].filter(e=>Number.isFinite(e.at)).sort((e,t)=>e.at-t.at),HY=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]},UY=e=>`#${e.map(e=>Math.round(e).toString(16).padStart(2,`0`)).join(``)}`;function WY(e,t,n,r){let i=t?VY(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=HY(o.color),u=HY(s.color);return UY([l[0]+(u[0]-l[0])*c,l[1]+(u[1]-l[1])*c,l[2]+(u[2]-l[2])*c])}function GY(e,t,n,r,i,a=96){let o=i-r||1,s=t?VY(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:WY(`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:WY(`gradient`,s,n,r+(t+.5)/a*o)}))}function KY(e,t,n){let r=e=>+(t+e*(n-t)).toPrecision(6),i=`#22c55e`,a=`#ef4444`;if(e===`traffic`)return{mode:`zones`,stops:[{at:r(0),color:i},{at:r(.7),color:`#f5a524`},{at:r(.9),color:a}]};let o=[{at:r(0),color:i},{at:r(.5),color:`#eab308`},{at:r(1),color:a}];return{mode:`gradient`,stops:e===`green-red`?o:o.map((e,t)=>({...e,color:o[o.length-1-t].color}))}}function qY(e,t,n){let r=t?VY(t):[];if(!e||e===`solid`||r.length===0)return n;let i=r[0].at,a=r[r.length-1].at,o=e=>`${((e-i)/(a-i||1)*100).toFixed(1)}%`;if(e===`gradient`)return`linear-gradient(90deg, ${r.map(e=>`${e.color} ${o(e.at)}`).join(`, `)})`;let s=100/r.length;return`linear-gradient(90deg, ${r.map((e,t)=>`${e.color} ${(t*s).toFixed(1)}% ${((t+1)*s).toFixed(1)}%`).join(`, `)})`}var JY=.75*Math.PI,YY=1.5*Math.PI;function XY({gauges:e,live:t,backgroundToken:n=``,onPlotContextMenu:r}){let i=K(null),a=K(null),o=K(null),s=K(r);G(()=>{s.current=r},[r]);let c=K({gauges:e,live:t});G(()=>{c.current={gauges:e,live:t}},[e,t]);let l=K(HH()),u=K(0);function d(){if(o.current)return o.current;let e=a.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`,ink:`#e4e4e7`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`,ink:t.getPropertyValue(`--chart-fg`).trim()||`#e4e4e7`};return o.current=n,n}function f(){let e=i.current,t=a.current;if(!e||!t)return;let n=Math.max(1,t.clientWidth),r=Math.max(1,t.clientHeight),o=Math.min(2,window.devicePixelRatio||1),s=Math.floor(n*o),f=Math.floor(r*o);(e.width!==s||e.height!==f)&&(e.width=s,e.height=f),e.style.width=`${n}px`,e.style.height=`${r}px`;let p=e.getContext(`2d`);if(!p)return;p.setTransform(o,0,0,o,0,0);let h=d(),{gauges:g,live:_}=c.current,v=g;if(_){let e=performance.now(),t=XH(l.current,_.latestT(),e-u.current);u.current=e,v=g.map(e=>{if((e.stat??`last`)!==`last`)return e;let n=_.valueAt(e.name,t);return Number.isFinite(n)?{...e,value:n}:e}),m.current.schedule()}if(p.fillStyle=h.bg,p.fillRect(0,0,n,r),v.length===0){p.fillStyle=h.muted,p.font=`13px ${Q.sans}`,p.textAlign=`left`,p.textBaseline=`top`,zV(p);return}let{cols:y,rows:b}=ZY(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`?sX(p,e,n,r,x,S,e.color,e.alarm??null,h):cX(p,e,n,r,x,S,e.color,e.alarm??null,h)})}let p=K(f);p.current=f;let m=K(null);return m.current??=jH(()=>p.current(),()=>a.current),W(()=>{m.current.now()}),W(()=>()=>m.current?.cancel(),[]),W(()=>{o.current=null,m.current.schedule()},[n]),G(()=>{let e=a.current;if(!e)return;let t=new AH(()=>{o.current=null,m.current.schedule()});return t.observe(e),()=>t.disconnect()},[]),q(`div`,{ref:a,style:{position:`relative`,width:`100%`,height:`100%`},children:q(`canvas`,{ref:i,className:`chart-canvas`,role:`img`,"aria-label":`Gauges: ${e.map(e=>`${e.name} ${Number.isFinite(e.value)?QY(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 ZY(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 QY=(e,t)=>Pz(e,Dz(Math.abs(t),100)),$Y=(e,t)=>Math.max(0,Math.min(1,(t-e.min)/(e.max-e.min||1))),eX=(e,t)=>{let n=e.fromZero?$Y(e,0):0;return[Math.min(n,t),Math.max(n,t)]},tX=(e,t)=>!!t&&(t.linked?t.linked===`active`:Number.isFinite(e.value)&&e.value>=t.value),nX=e=>(e.colorMode===`gradient`||e.colorMode===`zones`)&&!!e.stops?.length,rX=(e,t)=>tX(e,t)?t.color:WY(e.colorMode,e.stops,e.color,e.value);function iX(e,t,n){for(let r of GY(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 aX(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 oX=Math.SQRT1_2;function sX(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=QY(t.min,u),f=QY(t.max,u),p=e=>Math.max(9,Math.min(22,e*.1)),m=e=>Math.max(4,e*.13),h=Math.max(8,Math.min((i-2*l)/2,(a-2*l)/1.9)),g=0;for(let t=0;t<2;t++){e.font=`${p(h)}px ${Q.mono}`,g=Math.max(e.measureText(d).width,e.measureText(f).width);let t=m(h),n=Math.max(h+t/2,oX*h+g/2),r=h+t/2+oX*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+oX*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=>JY+e*YY;e.lineCap=`round`,e.lineWidth=_,e.strokeStyle=c.grid,e.beginPath(),e.arc(b,x,h,JY,JY+YY),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($Y(t,s.value)),JY+YY),e.stroke(),e.globalAlpha=1,e.lineCap=`round`);let[C,w]=eX(t,Number.isFinite(t.value)?$Y(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(nX(t)){let n=YY/(2*Math.PI),r=iX(e.createConicGradient(JY,b,x),t,e=>e*n);r.addColorStop(1,WY(t.colorMode,t.stops,t.color,t.min)),e.strokeStyle=r,e.globalAlpha=.24,e.beginPath(),e.arc(b,x,h,JY,JY+YY),e.stroke(),e.globalAlpha=1,Number.isFinite(t.value)&&!tX(t,s)&&T()}if(Number.isFinite(t.value)&&(!nX(t)||tX(t,s))&&(e.strokeStyle=tX(t,s)?s.color:o,T()),t.fromZero&&t.min<0&&t.max>0){let n=S($Y(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($Y(t,s.value));e.strokeStyle=s.color,e.lineWidth=Math.max(1.5,s.width),e.lineCap=`butt`,e.beginPath(),e.moveTo(b+Math.cos(n)*(h-_*.9),x+Math.sin(n)*(h-_*.9)),e.lineTo(b+Math.cos(n)*(h+_*.9),x+Math.sin(n)*(h+_*.9)),e.stroke();let r=h+_*.9+10*.7;s.linked&&uU(e,b+Math.cos(n)*r-10/2,x+Math.sin(n)*r-10/2,s.color)}let E=Number.isFinite(t.value)?QY(t.value,u):`—`,D=2*(h-_)*.82,O=Math.max(11,h*.42);e.font=`650 ${O}px ${Q.sans}`;let k=e.measureText(E).width;k>D&&(O=Math.max(9,O*D/k),e.font=`650 ${O}px ${Q.sans}`),e.textAlign=`center`,e.textBaseline=`alphabetic`,e.fillStyle=tX(t,s)||nX(t)?rX(t,s):c.ink,e.fillText(E,b,x+O*.32),e.fillStyle=c.muted,t.unit&&(e.font=`600 ${Math.max(9,h*.13)}px ${Q.sans}`,e.fillText(aX(e,t.unit,D),b,x+O*.32+Math.max(11,h*.19)));let A=x+oX*h+_/2+6,j=oX*h;e.textBaseline=`top`,e.font=`${v}px ${Q.mono}`,e.fillText(d,b-j,A),e.fillText(f,b+j,A);let M=2*j-g-16,N=Math.max(10,Math.min(26,h*.13));e.font=`600 ${N}px ${Q.sans}`;let P=e.measureText(t.name).width;P>M&&N>9&&(N=Math.max(9,N*M/P),e.font=`600 ${N}px ${Q.sans}`),e.fillText(aX(e,t.name,M),b,A+(v-N)/2)}function cX(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+$Y(t,e)*f;e.textBaseline=`alphabetic`,e.fillStyle=c.muted,e.font=`600 ${Math.max(10,m*.42)}px ${Q.sans}`,e.textAlign=`left`,e.fillText(aX(e,t.name,f),u,h-p/2-m-4),e.textAlign=`right`,e.fillStyle=tX(t,s)?s.color:c.ink,e.font=`650 ${m}px ${Q.sans}`;let _=t.unit?(e.font=`600 ${Math.max(9,m*.4)}px ${Q.sans}`,e.measureText(` ${t.unit}`).width):0;t.unit&&(e.fillStyle=c.muted,e.fillText(` ${t.unit}`,d,h-p/2-8)),e.fillStyle=tX(t,s)||nX(t)?rX(t,s):c.ink,e.font=`650 ${m}px ${Q.sans}`,e.fillText(Number.isFinite(t.value)?QY(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)?$Y(t,t.value):0,y=e=>u+e*f,[b,x]=eX(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`};nX(t)&&(e.strokeStyle=iX(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)&&!tX(t,s)&&S()),Number.isFinite(t.value)&&(!nX(t)||tX(t,s))&&(e.strokeStyle=tX(t,s)?s.color:o,S()),t.fromZero&&t.min<0&&t.max>0&&(e.strokeStyle=c.muted,e.lineWidth=1.5,e.lineCap=`butt`,e.beginPath(),e.moveTo(g(0),h-p*.75),e.lineTo(g(0),h+p*.75),e.stroke(),e.lineWidth=p,e.lineCap=`round`),s&&s.value>=t.min&&s.value<=t.max&&(e.strokeStyle=s.color,e.lineWidth=Math.max(1.5,s.width),e.lineCap=`butt`,e.beginPath(),e.moveTo(g(s.value),h-p),e.lineTo(g(s.value),h+p),e.stroke(),s.linked&&uU(e,g(s.value)-10/2,h-p-10-2,s.color)),e.fillStyle=c.muted,e.font=`${Math.max(9,m*.34)}px ${Q.mono}`,e.textBaseline=`top`,e.textAlign=`left`,e.fillText(QY(t.min,t.max-t.min),u,h+p/2+4),e.textAlign=`right`,e.fillText(QY(t.max,t.max-t.min),d,h+p/2+4)}var lX=`Video limit reached this month`,uX=720;function dX(e,t){return t?e<uX:e<640}function fX(e){return e<=1?{cols:1,rows:1}:e===2?{cols:2,rows:1}:e<=4?{cols:2,rows:2}:{cols:3,rows:3}}function pX(e,t){return e.flatMap(e=>{let n=e.info?.meta;if(!n?.recordingId)return[];let r=n.wallOrigin?Number(n.wallOrigin):NaN,i=n.wallQuality;return[{recordingId:n.recordingId,wallOrigin:Number.isFinite(r)?r:null,wallQuality:i===`exact`||i===`approx`?i:null,xOffset:t[e.id]??0}]})}var mX={get:()=>null,subscribe:()=>()=>{}};function hX(e){let[t,n]=pt(null);return G(()=>{let t=e.current;if(!t)return;let r=e=>n(t=>dX(e,t??!1));if(r(t.clientWidth),typeof ResizeObserver>`u`)return;let i=new ResizeObserver(e=>{for(let t of e)r(t.contentRect.width)});return i.observe(t),()=>i.disconnect()},[e]),t}function gX(e){let t=Gn(e.settings),[n,r]=pt(null),[i,a]=pt(null),o=K(null);W(()=>{i&&o.current?.querySelector(`[data-camera="${CSS.escape(i)}"]`)?.focus()},[i]);let s=e.recordings??[],c=e=>s.findIndex(t=>t.recordingId===e.recordingId),l=(e.video??[]).filter(e=>e.kind===`recorded`&&c(e)>=0).sort((e,t)=>c(e)-c(t)),u=e.onContextMenu?t=>{t.preventDefault(),e.onContextMenu({clientX:t.clientX,clientY:t.clientY})}:void 0;if(!t.length){let t=[...new Set([...e.live.filter(e=>e.kind===`camera`&&!e.lowOf),...l].map(t=>Hn(t,e.live)))].sort();return q(vX,{onContextMenu:u,title:`Choose a camera in this panel's settings`,detail:t.length?t.join(`, `):void 0})}let d={panel:e,recorded:l,recIndex:c};if(t.length===1)return q(_X,{...d,id:t[0],onMenu:u});let f=n&&t.includes(n)?n:null,p=f?[f]:t,{cols:m,rows:h}=fX(p.length),g=()=>{a(f),r(null)};return vt(`div`,{ref:o,className:`kymo-camera-wall`,style:{gridTemplateColumns:`repeat(${m}, minmax(0, 1fr))`,gridTemplateRows:`repeat(${h}, minmax(0, 1fr))`},onContextMenu:u,onKeyDown:e=>{e.key===`Escape`&&f&&(e.stopPropagation(),g())},children:[p.map(e=>q(_X,{...d,id:e,multi:!0,wall:!f,onPick:f?void 0:()=>{a(null),r(e)}},e)),f?vt(`button`,{type:`button`,className:`kymo-camera__all`,onClick:g,autoFocus:!0,children:[vt(`svg`,{viewBox:`0 0 16 16`,"aria-hidden":`true`,children:[q(`rect`,{x:`2`,y:`2`,width:`5`,height:`5`,rx:`1`}),q(`rect`,{x:`9`,y:`2`,width:`5`,height:`5`,rx:`1`}),q(`rect`,{x:`2`,y:`9`,width:`5`,height:`5`,rx:`1`}),q(`rect`,{x:`9`,y:`9`,width:`5`,height:`5`,rx:`1`})]}),`All cameras`]}):null]})}function _X({panel:e,recorded:t,recIndex:n,id:r,multi:i,wall:a,onPick:o,onMenu:s}){let c=e.recordings??[],l={onMenu:s,wall:a,onPick:o},u=t.find(e=>e.id===r);if(u)return q(yX,{...e,...l,source:u,name:i?Hn(u,e.live):u.name,rec:c[n(u)]},`rec:${u.recordingId}:${u.id}`);let d=e.live.find(e=>e.id===r&&e.kind===`camera`);if(d?.limitNotice&&(d.limitNotice===`Video limit reached this month`||!d.video))return q(vX,{onContextMenu:s,title:d.limitNotice,detail:Hn(d,e.live)});if(!d?.video||d.status===`error`)return q(vX,{onContextMenu:s,title:`Camera offline`,detail:d?Hn(d,e.live):void 0});let f=e.live.find(e=>e.kind===`camera`&&e.lowOf===d.id&&e.video&&e.status!==`error`),p=f?.video?AE({...f,video:f.video}):void 0;return q(yX,{...e,...l,source:AE({...d,video:d.video}),low:p,name:i?Hn(d,e.live):d.name,conn:d},d.id)}function vX({title:e,detail:t,onContextMenu:n}){return q(`div`,{className:`kymo-camera`,onContextMenu:n,children:vt(`div`,{className:`kymo-camera__empty`,children:[vt(`svg`,{className:`kymo-camera__empty-icon`,viewBox:`0 0 24 24`,"aria-hidden":`true`,children:[q(`rect`,{x:`2.5`,y:`6`,width:`13`,height:`12`,rx:`2.5`}),q(`path`,{d:`M15.5 10.5 21.5 7v10l-6-3.5`})]}),q(`p`,{className:`kymo-camera__empty-title`,children:e}),t?q(`p`,{className:`kymo-camera__empty-detail`,children:t}):null]})})}function yX(e){let{settings:t,source:n}=e,r=e.cursor??mX,i=mt(r.subscribe,r.get),a=e=>e.kind===`data`,o=e.rec?void 0:t.syncStreamId?e.live.find(e=>e.id===t.syncStreamId&&a(e)):e.live.find(t=>t.id===e.conn.parentId&&a(t))??e.live.find(t=>a(t)&&e.selection.includes(t.id))??e.live.find(a),s=i??e.viewXRange?.[1]??null,c=null,l=null,u=o?.clock?.quality()??`none`;if(e.rec){let{wallOrigin:r,wallQuality:i,xOffset:a}=e.rec;u=i??`none`;let o=n.range()?.[0]??null;s===null?c=o:r===null?(c=o,l=`This recording has no wall clock`):e.xKey===`Time`?c=r+s-a+t.offsetMs/1e3:e.xKey===`ElapsedTime`&&i===`exact`?c=s-a+t.offsetMs/1e3:(c=o,l=`Sync needs a time X axis`)}else s!==null&&(e.xIsTime?(c=o?.clock?.toWall(s,t.offsetMs)??null,c===null&&(l=`No data stream to sync with`)):l=`Sync needs a time X axis`);let d=K(null),f=K(null),p=hX(d),m=p===null?null:e.low&&(p||e.wall)?e.low:n,h=K(t.fit),g=K(c);G(()=>{h.current=t.fit,g.current=c});let _=K(null),v=K(null),[y,b]=pt(null),x=y??m??n,[S,C]=pt(!1),[w,T]=pt(!0);W(()=>{if(!m||_.current?.source===m)return;let e=!_.current,t=null,n=!1,r=()=>t?_.current===t:e,i=t=CX(m,f.current,()=>h.current,g.current,{unsupported:()=>{r()&&C(!0)},buffered:e=>{r()&&T(e)},frame:()=>{if(_.current===t){n||(n=!0,b(m));return}_.current?.dispose(),_.current=i,v.current=null,i.show(),n=!0,b(m),T(i.buffered())}},e);if(e){_.current=i;return}return v.current=i,()=>{_.current!==i&&(i.dispose(),v.current===i&&(v.current=null))}},[m]),W(()=>()=>{_.current?.dispose(),_.current=null},[]),W(()=>{_.current?.setTarget(c),v.current?.setTarget(c)},[c]);let E=bX(e.rec||c!==null?null:x),D=!!x.lowOf,O=x.info().latestT,k=!e.rec&&c!==null&&O!==null?c-O:null,A=e.rec?`No video at this time`:`Not buffered`;return vt(`div`,{ref:d,className:`kymo-camera${e.onPick?` is-tile`:``}`,onContextMenu:e.onMenu,...e.onPick?{role:`button`,tabIndex:0,"data-camera":n.id,"aria-label":`Show ${e.name} alone`,onClick:e.onPick,onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),e.onPick())}}:{},children:[q(`canvas`,{ref:f,className:`kymo-camera__video`,role:`img`,"aria-label":`Video from ${e.name}`}),S?q(`div`,{className:`kymo-camera__empty`,children:q(`p`,{className:`kymo-camera__empty-title`,children:`This browser can't decode this camera`})}):E===null?vt(`div`,{className:`kymo-camera__overlay`,children:[q(`span`,{className:`kymo-camera__name`,children:e.name}),e.rec?q(`span`,{className:`kymo-camera__rec`,children:`Recording`}):c===null?q(`span`,{className:`kymo-camera__live`,children:`LIVE`}):q(`span`,{className:`kymo-camera__ago`,children:k===null?``:SX(k)}),D?q(`span`,{className:`kymo-camera__badge`,title:`Low-quality copy (small panel)`,children:`LQ`}):null,c!==null&&u!==`none`?q(`span`,{className:`kymo-camera__badge${u===`exact`?` is-exact`:``}`,children:u===`exact`?`Exact`:`Approx.`}):null,l??(c!==null&&!w?A:null)?q(`span`,{className:`kymo-camera__note`,children:l??A}):null,e.conn?.limitNotice?q(`span`,{className:`kymo-camera__note`,role:`status`,children:e.conn.limitNotice}):null]}):vt(`div`,{className:`kymo-camera__empty kymo-camera__empty--cover`,role:`status`,children:[q(`p`,{className:`kymo-camera__empty-title`,children:`No signal`}),vt(`p`,{className:`kymo-camera__empty-detail`,children:[e.name,` · no video for `,xX(E)]})]})]})}function bX(e){let[t]=pt(()=>Date.now()),[n,r]=pt(null);return W(()=>{if(!e){r(null);return}let n=()=>{let{arrivedAt:n,gapMs:i}=e.info(),a=Date.now()-Math.max(n??0,t);r(a>OE(i)?Math.floor(a/1e3):null)};n();let i=setInterval(n,500);return()=>clearInterval(i)},[e,t]),n}function xX(e){return e<60?`${e} s`:e<3600?`${Math.floor(e/60)} min`:`${Math.floor(e/3600)} h`}function SX(e){let t=Math.abs(e).toFixed(1);return t===`0.0`?`0.0 s`:`${e<0?`−`:`+`}${t} s`}function CX(e,t,n,r,i,a=!0){let o=e.acquire?.(),s=!1,c=!0,l=e=>{c=e,i.buffered(e)},u=null,d=null,f=r,p=`live`,m=!0,h=!1,g=!1,_=null,v=null,y=null,b=[],x=e=>{if(s){e.close();return}p===`seek`?(_?.close(),_=e):(v?.close(),v=e,i.frame?.())},S=()=>{!d||d.state===`closed`?d=new VideoDecoder({output:x,error:()=>{}}):d.reset(),d.configure(u),m=!0},C=e=>{d?.state===`closed`&&e.key&&S(),!(d?.state!==`configured`||m&&!e.key)&&(m=!1,d.decode(new EncodedVideoChunk({type:e.key?`key`:`delta`,timestamp:Math.round(e.t*1e6),data:e.data})))},w=()=>{p=`live`,l(!0),S();for(let t of e.livePlan?.()??[])C(t)},T=async()=>{if(!h){h=!0;try{for(;!s&&p===`seek`&&g;){g=!1;let t=[];try{t=await e.seekPlan(f)}catch{}if(!(s||p!==`seek`||g)&&(l(t.length>0),t.length)){S();for(let e of t)C(e);try{await d.flush()}catch{}p===`seek`&&_&&(v?.close(),v=_,_=null,i.frame?.())}}}finally{h=!1,_?.close(),_=null}}},E=()=>{f===null?p!==`live`&&w():(p=`seek`,g=!0,T())};e.onUnit&&b.push(e.onUnit(e=>{u&&p===`live`&&C(e)})),(async()=>{if(typeof VideoDecoder>`u`){i.unsupported();return}if(e.info().codec||(e.ready?await e.ready():e.onUnit&&await new Promise(t=>{let n=e.onUnit(()=>{e.info().codec&&(n(),t())});b.push(n)})),s)return;if(!e.info().codec){l(!1);return}let t={codec:e.info().codec,optimizeForLatency:!0,hardwareAcceleration:`no-preference`},n=!1;try{n=(await VideoDecoder.isConfigSupported(t)).supported===!0}catch{}if(!s){if(!n){i.unsupported();return}u=t,f===null?w():E()}})();let D=n(),O=()=>{if(!a)return;let e=window.devicePixelRatio||1,r=Math.max(1,Math.round(t.clientWidth*e)),i=Math.max(1,Math.round(t.clientHeight*e)),o=!1;if((t.width!==r||t.height!==i)&&(t.width=r,t.height=i,o=!0),v&&(y?.close(),y=v,v=null,o=!0),n()!==D&&(D=n(),o=!0),!o||!y)return;let s=t.getContext(`2d`);if(!s)return;let c=y.displayWidth,l=y.displayHeight,u=D===`cover`?Math.max(r/c,i/l):Math.min(r/c,i/l),d=c*u,f=l*u;s.clearRect(0,0,r,i),s.drawImage(y,(r-d)/2,(i-f)/2,d,f)},k=0,A=()=>{k=wH(A),O()};return k=wH(A),{source:e,show(){a=!0},buffered:()=>c,setTarget(e){e!==f&&(f=e,u&&E())},dispose(){s=!0,TH(k),b.forEach(e=>e()),d&&d.state!==`closed`&&d.close();for(let e of[_,v,y])e?.close();_=v=y=null,o?.()}}}function wX(e,t){let n=e.filter(e=>e.x.length>=2&&TX(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 TX(e){for(let t=1;t<e.length;t++)if(!(e[t]>=e[t-1]))return!1;return!0}function EX(e){if(e.length===0)return null;if(e.length===1)return e[0];let t=new Set,n={};for(let r of e)for(let e=0;e<r.columnNames.length;e++){let i=r.columnNames[e];t.add(i),r.units[e]?.trim()&&(n[i]=r.units[e])}let r=[...t];return{meta:``,columnNames:r,units:r.map(e=>n[e]??``),rows:e.flatMap(e=>e.rows)}}function DX(e,t,n,r,i){return n||e.length===0||(t>0?e.length!==1:e.length<2||r!==`ElapsedTime`)?null:e.map((e,n)=>({conn:e,keySuffix:`__${t+n}`,offset:i[e.id]??0}))}function OX(e,t,n,r,i){if(e.length===1){let a=e[0];return kX(a.conn,t,n,a.keySuffix,a.offset,r,i)}let a=e.map(e=>kX(e.conn,t,n,e.keySuffix,e.offset,[],null)),o=()=>a.reduce((e,t)=>t.latestT()>e.latestT()?t:e);return{pull:(e,t,n,i)=>[...r,...a.flatMap(r=>r.pull(e,t,n,i))],xBounds:()=>{let e=i;for(let t of a){let n=t.xBounds();n&&(e=e?[Math.min(e[0],n[0]),Math.max(e[1],n[1])]:n)}return e},latestX:()=>o().latestX(),version:()=>a.reduce((e,t)=>e+t.version(),0),latestT:()=>o().latestT(),xAtTime:e=>o().xAtTime(e),latestValues:e=>new Map(a.flatMap(t=>[...t.latestValues(e)]))}}function kX(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]))}}}let f=Ye(s.pts,u);if(t!==`ElapsedTime`)return[...a,f];let p=Math.min(e.source.latestTimeSync(),u===void 0?1/0:u-i),m=E(n,t=>e.source.lastKnownSync(t),o-i,c-i,p);if(!m)return[...a,f];let h=i===0?m.x:m.x.map(e=>e+i);return[...a,f,{...m,x:h,cols:new Map([...m.cols].map(([e,t])=>[e+r,t]))}]},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(),id:e.id,latestT:()=>e.source.latestTimeSync(),xAtTime:n=>e.source.xAtTimeSync(t,n)+i,latestValues:t=>{let n=new Map,i=t.filter(e=>e.endsWith(r)),a=e.source.latestValuesSync(i.map(e=>e.slice(0,-r.length)));for(let e of i){let t=a.get(e.slice(0,-r.length));t!==void 0&&n.set(e,t)}return n}}}function AX(e,t){return e.filter(e=>m(t,e))}var jX=`__ref`,MX=8e3;function NX(e,t){return e.map(e=>({...e,id:`${e.id}${jX}`,column:`${e.column}${jX}`,color:t}))}var PX=new WeakMap;function FX(e,t,n){let r=e.data.rows,i=`${t}\n${n.join(`
|
|
608
|
-
`)}`,a=
|
|
607
|
+
}`,nq=-3e38;function rq(e){for(let t=0;t<e.length;t++)if(e[t]-e[t]===0)return e[t];return 0}function iq(e){let t=e.getContext(`webgl2`,{antialias:!1,alpha:!0,premultipliedAlpha:!0});if(!t)return null;let n=(e,n,i,a)=>oH(t,`glPlot|${e}|${n}`,()=>r(e,n,i,a)),r=(e,n,r,i)=>{let a=JV(t,t.VERTEX_SHADER,e),o=JV(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(JK,XK,[`a_xa`,`a_xb`,`a_loa`,`a_lob`,`a_hia`,`a_hib`,`a_bstart`],[`u_color`]),a=n(YK,ZK,[`a_x0`,`a_x1`,`a_y0`,`a_y1`,`a_k`],[`u_palette`]),o=n(QK,$K,[`a_ax`,`a_ay`,`a_bx`,`a_by`,`a_bstart`],[`u_color`,`u_half`,`u_ext`]),s=n(eq,tq,[],[`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=rq(t),o.oy=rq(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=rq(n),c.oy=rq(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=rq(t),o.oy=rq(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:nq}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 aq(e){let t=K({plot:null,failed:!1,size:``});return W(()=>()=>{t.current.plot?.dispose(),t.current.plot=null},[]),lt((n,r)=>{let i=t.current,a=e.current;if(!i.plot&&!i.failed&&a&&(i.plot=sH(a,iq),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 oq(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 sq=16;function cq(e,t,n,r){let i=oq(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(sq),m=new Int32Array(sq);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(sq-1,Math.floor(a/(2*Math.PI)*sq));p[o]+=t[e],m[o]++}return{n:a,rMin:c,rMax:l,x:d,y:f,means:Array.from({length:sq},(e,t)=>m[t]>0?p[t]/m[t]:0)}}function lq({angles:e,radii:t,angleLabel:n,radiusLabel:r,color:i=`#a78bfa`,mode:a=`waveform`,radiusMin:o,radiusMax:s,height:c=400,backgroundToken:l=``,onPlotContextMenu:u}){let d=K(null),f=K(null),p=K(null),m=K(u);G(()=>{m.current=u},[u]);let h=K({angles:e,radii:t,angleLabel:n,radiusLabel:r,color:i,mode:a,radiusMin:o,radiusMax:s,height:c});G(()=>{h.current={angles:e,radii:t,angleLabel:n,radiusLabel:r,color:i,mode:a,radiusMin:o,radiusMax:s,height:c}},[e,t,n,r,i,a,o,s,c]);let g=ft(()=>cq(e,t,o,s),[e,t,o,s]),_=K(g);G(()=>{_.current=g},[g]);let v=K(null),y=aq(v),b=K({geo:null,color:``});function x(){if(p.current)return p.current;let e=f.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return p.current=n,n}function S(){let e=f.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||h.current.height)}}function C(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function w(){let e=d.current;if(!e)return;let{w:t,h:n}=S(),r=C(e,t,n);if(!r)return;let{bg:i,muted:a,grid:o}=x(),{angleLabel:s,radiusLabel:c,color:l,mode:u}=h.current,f=_.current,{n:p,rMin:m,rMax:g}=f;r.fillStyle=i,r.fillRect(0,0,t,n);let v=y(t,n);if(p===0){v?.keep([]),v?.render(),r.fillStyle=a,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,zV(r);return}let w=g-m||1,T=(Math.min(t-64,n-32-24)-4)/2,E=t/2,D=32+T,O=Dz(w,4),k=Az(m,g,O);r.strokeStyle=o,r.lineWidth=1,r.setLineDash([3,3]);for(let e of k){let t=(e-m)/w*T;t<0||(r.beginPath(),r.arc(E,D,t,0,Math.PI*2),r.stroke())}r.setLineDash([]),r.strokeStyle=o,r.lineWidth=1;for(let e=0;e<360;e+=30){let t=e*Math.PI/180;r.beginPath(),r.moveTo(E,D),r.lineTo(E+Math.cos(-t+Math.PI/2)*T,D+Math.sin(-t+Math.PI/2)*T),r.stroke()}r.fillStyle=a,r.font=`10px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`middle`;for(let e=0;e<360;e+=30){let t=e*Math.PI/180,n=E+Math.sin(t)*(T+14),i=D-Math.cos(t)*(T+14);r.fillText(`${e}°`,n,i)}r.textAlign=`left`,r.textBaseline=`middle`;for(let e of k){let t=(e-m)/w*T;t<4||r.fillText(Pz(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,vK(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/sq;r.fillStyle=l,r.globalAlpha=.75;for(let i=0;i<sq;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<sq;i++){let a=e[i]/t*T,o=i*n-Math.PI/2-n/2;r.beginPath(),r.moveTo(E,D),r.arc(E,D,a,o,o+n),r.closePath(),r.stroke()}r.globalAlpha=1}r.restore(),r.fillStyle=a,r.font=`11px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`bottom`,r.fillText(`${s} / ${c}`,E,n-4)}let T=K(w);T.current=w;let E=K(null);E.current??=VH(()=>T.current(),()=>f.current);let D=()=>E.current.schedule();return W(()=>{E.current.now()}),W(()=>()=>E.current?.cancel(),[]),W(()=>{p.current=null,D()},[l]),G(()=>{let e=f.current;if(!e)return;let t=new zH(()=>{p.current=null,D()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=d.current;if(!e)return;let t=e=>{e.preventDefault(),m.current?.({clientX:e.clientX,clientY:e.clientY})};return e.addEventListener(`contextmenu`,t),()=>e.removeEventListener(`contextmenu`,t)},[]),vt(`div`,{ref:f,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:d,className:`chart-canvas`,role:`img`,"aria-label":`Polar chart: ${n} vs ${r}`}),q(`canvas`,{ref:v,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}})]})}function uq(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 dq(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 fq(e,t){let n=new Float64Array(t.length);for(let r=0;r<t.length;r++)n[r]=e[t[r]];return n}function pq(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 mq(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 hq=new Float64Array,gq=new Float64Array;function _q(e,t,n){let r=t>>1;hq.length<r&&(hq=new Float64Array(r),gq=new Float64Array(r));let i=hq.subarray(0,r),a=gq.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}mq(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 vq=new Float64Array,yq=0;function bq(e){if(yq===e)return vq.subarray(0,e);vq.length<e&&(vq=new Float64Array(Math.max(e,vq.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++){vq[t]=.5*(1-i);let e=i*n-a*r;a=a*n+i*r,i=e}return yq=e,vq.subarray(0,e)}var xq={top:14,right:24,bottom:40,left:64},Sq=5;function Cq(e){let t=1;for(;t<e;)t<<=1;return t}function wq(e,t,n,r){let i=e.length,a=Math.max(2,Cq(i)),o=_q(e,a,n===`hann`?bq(i):void 0),s=a/2,c=new Float64Array(s),l=2/a;for(let e=0;e<s;e++){c[e]=e*t/a;let n=o[e]*l;o[e]=r===`db`?20*Math.log10(Math.max(n,1e-12)):n}return{freqs:c,amps:o}}function Tq({signal:e,sampleRate:t=1,label:n,xMode:r=`hz`,yMode:i=`amplitude`,window:a=`hann`,color:o=`#34d399`,logX:s=!1,height:c=400,backgroundToken:l=``,onPlotContextMenu:u}){let d=SU(),f=K(null),p=K(null),m=K(null),h=K(u);G(()=>{h.current=u},[u]);let g=K({signal:e,sampleRate:t,label:n,xMode:r,yMode:i,window:a,color:o,logX:s,height:c});G(()=>{g.current={signal:e,sampleRate:t,label:n,xMode:r,yMode:i,window:a,color:o,logX:s,height:c}},[e,t,n,r,i,a,o,s,c]);let _=ft(()=>e.length>=4?wq(e,t,a,i):null,[e,t,a,i]),v=ft(()=>_&&s?_.freqs.map(e=>Math.log10(e)):null,[_,s]),y=K(_&&{..._,logFreqs:v});G(()=>{y.current=_&&{..._,logFreqs:v}},[_,v]);function b(){if(m.current)return m.current;let e=p.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return m.current=n,n}function x(){let e=p.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||g.current.height)}}function S(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function C(){let e=f.current;if(!e)return;let{w:t,h:n}=x(),r=S(e,t,n);if(!r)return;let{top:i,right:a,bottom:o,left:s}=xq,c=t-s-a,l=n-i-o,{bg:u,muted:p,grid:m}=b(),{sampleRate:h,label:_,xMode:v,yMode:C,color:w,logX:T}=g.current,E=y.current;if(r.fillStyle=u,r.fillRect(0,0,t,n),!E||c<=0||l<=0){r.fillStyle=p,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,zV(r);return}let{freqs:D,amps:O,logFreqs:k}=E,A=D.length,j=v===`hz`?`${_} (Hz)`:`${_} (order)`,M=v===`order`&&h>0?h:1,N=D[1]/M,P=D[A-1]/M,F=1/0,I=-1/0;for(let e=1;e<A;e++)O[e]<F&&(F=O[e]),O[e]>I&&(I=O[e]);if(!Number.isFinite(F)||!Number.isFinite(I)){r.fillStyle=p,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,zV(r);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=Dz(I-F,5),V=Az(F,I,B);r.strokeStyle=m,r.lineWidth=1,r.setLineDash([3,3]);for(let e of V)r.beginPath(),r.moveTo(s,z(e)),r.lineTo(s+c,z(e)),r.stroke();r.setLineDash([]);let ee=T?1:Dz(P-N,Oz(c)),te=T?(()=>{let e=[],t=Math.ceil(Math.log10(Math.max(N,1e-12))),n=Math.floor(Math.log10(P));for(let r=t;r<=n;r++)for(let t of[1,2,5]){let n=t*10**r;n>=N&&n<=P&&e.push(n)}return e})():Az(N,P,ee);r.strokeStyle=m,r.lineWidth=1,r.setLineDash([3,3]);for(let e of te)r.beginPath(),r.moveTo(R(e),i),r.lineTo(R(e),i+l),r.stroke();r.setLineDash([]),r.strokeStyle=p,r.lineWidth=1,r.fillStyle=p,r.font=`11px ${Q.mono}`,r.textAlign=`right`,r.textBaseline=`middle`;for(let e of V)r.beginPath(),r.moveTo(s-Sq,z(e)),r.lineTo(s,z(e)),r.stroke(),r.fillText(Pz(e,B),s-4,z(e));r.textAlign=`center`,r.textBaseline=`top`;for(let e of te)r.beginPath(),r.moveTo(R(e),i+l),r.lineTo(R(e),i+l+Sq),r.stroke(),r.fillText(Pz(e,T?e:ee),R(e),i+l+Sq+2);r.strokeStyle=m,r.lineWidth=1,r.strokeRect(s,i,c,l),r.save(),r.beginPath(),r.rect(s,i,c,l),r.clip(),r.strokeStyle=w,r.lineWidth=1,r.beginPath();let H=!1,ne=Math.min(2,window.devicePixelRatio||1),re=Math.max(1,Math.round(c*ne)),ie=A>re*4?T&&k?uq(k,O,Math.log10(N*M),Math.log10(P*M),re):uq(D,O,N*M,P*M,re):null;for(let e=+!ie;e<(ie?ie.length:A);e++){let t=ie?ie[e]:e;if(t<1)continue;let n=D[t]/M;if(n<N||n>P)continue;let i=R(n),a=z(O[t]);H?r.lineTo(i,a):(r.moveTo(i,a),H=!0)}r.stroke(),r.restore(),r.fillStyle=p,r.font=`11px ${Q.mono}`,r.save(),r.translate(14,i+l/2),r.rotate(-Math.PI/2),r.textAlign=`center`,r.textBaseline=`middle`,r.fillText(C===`db`?`dB`:`Amplitude`,0,0),r.restore(),r.textAlign=`center`,r.textBaseline=`bottom`,r.fillText(j,s+c/2,n-4)}let w=K(C);w.current=C;let T=K(null);T.current??=VH(()=>w.current(),()=>p.current);let E=()=>T.current.schedule();return W(()=>{T.current.now()}),W(()=>()=>T.current?.cancel(),[]),W(()=>{m.current=null,E()},[l]),G(()=>{let e=p.current;if(!e)return;let t=new zH(()=>{m.current=null,E()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=f.current;if(!e)return;let t=e=>{e.preventDefault(),h.current?.({clientX:e.clientX,clientY:e.clientY})};return e.addEventListener(`contextmenu`,t),()=>e.removeEventListener(`contextmenu`,t)},[]),q(`div`,{ref:p,style:{position:`relative`,width:`100%`,height:`100%`},children:q(`canvas`,{ref:f,className:`chart-canvas`,role:`img`,"aria-label":`Spectrum of ${n}`})})}function Eq(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 Dq(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,Eq(e,t,a)),a=t;return t.map(e=>{let t=e/100*(n-1),r=Math.floor(t);return i.get(r)+(i.get(Math.ceil(t))-i.get(r))*(t-r)})}var Oq={top:14,right:24,bottom:48,left:64},kq=5;function Aq(e,t){let n=e.length;if(n===0)return null;let[r,i,a,o,s]=Dq(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 jq({groups:e,color:t=`#fb923c`,whiskers:n=`1.5iqr`,height:r=400,backgroundToken:i=``,onPlotContextMenu:a}){let o=SU(),s=K(null),c=K(null),l=K(null),u=K(a);G(()=>{u.current=a},[a]);let d=K({groups:e,color:t,whiskers:n,height:r});G(()=>{d.current={groups:e,color:t,whiskers:n,height:r}},[e,t,n,r]);let f=ft(()=>e.filter(e=>e.values.length>0).map(e=>({label:e.label,box:Aq(e.values,n)})),[e,n]),p=K(f);G(()=>{p.current=f},[f]);function m(){if(l.current)return l.current;let e=c.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return l.current=n,n}function h(){let e=c.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||d.current.height)}}function g(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function _(){let e=s.current;if(!e)return;let{w:t,h:n}=h(),r=g(e,t,n);if(!r)return;let{top:i,right:a,bottom:c,left:l}=Oq,u=t-l-a,f=n-i-c,{bg:_,muted:v,grid:y}=m(),{color:b}=d.current;r.fillStyle=_,r.fillRect(0,0,t,n);let x=p.current;if(x.length===0||u<=0||f<=0){r.fillStyle=v,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,zV(r);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=Dz(C-S,5),D=Az(S,C,E);r.strokeStyle=y,r.lineWidth=1,r.setLineDash([3,3]);for(let e of D)r.beginPath(),r.moveTo(l,T(e)),r.lineTo(l+u,T(e)),r.stroke();r.setLineDash([]),r.strokeStyle=v,r.lineWidth=1,r.fillStyle=v,r.font=`11px ${Q.mono}`,r.textAlign=`right`,r.textBaseline=`middle`;for(let e of D)r.beginPath(),r.moveTo(l-kq,T(e)),r.lineTo(l,T(e)),r.stroke(),r.fillText(Pz(e,E),l-4,T(e));r.strokeStyle=y,r.lineWidth=1,r.strokeRect(l,i,u,f),r.save(),r.beginPath(),r.rect(l,i,u,f),r.clip();let O=x.length,k=u/O,A=Math.min(k*.55,60);for(let e=0;e<O;e++){let{box:t}=x[e],n=l+k*e+k/2;r.strokeStyle=b,r.lineWidth=1.5,r.beginPath(),r.moveTo(n,T(t.whiskerLo)),r.lineTo(n,T(t.whiskerHi)),r.stroke();let i=A*.35;r.beginPath(),r.moveTo(n-i,T(t.whiskerLo)),r.lineTo(n+i,T(t.whiskerLo)),r.moveTo(n-i,T(t.whiskerHi)),r.lineTo(n+i,T(t.whiskerHi)),r.stroke();let a=n-A/2,o=T(t.q3),s=Math.max(1,T(t.q1)-o);r.fillStyle=b,r.globalAlpha=.25,r.fillRect(a,o,A,s),r.globalAlpha=1,r.strokeStyle=b,r.lineWidth=1.5,r.strokeRect(a,o,A,s),r.strokeStyle=b,r.lineWidth=2.5,r.beginPath(),r.moveTo(a,T(t.median)),r.lineTo(a+A,T(t.median)),r.stroke();let c=T(t.mean);r.fillStyle=b,r.beginPath(),r.moveTo(n,c-5),r.lineTo(n+5,c),r.lineTo(n,c+5),r.lineTo(n-5,c),r.closePath(),r.fill(),r.fillStyle=b,r.globalAlpha=.6;let u=NaN;for(let e of t.outliers){let t=T(e);Math.abs(t-u)<.5||(u=t,r.beginPath(),r.arc(n,t,2.5,0,Math.PI*2),r.fill())}r.globalAlpha=1}r.restore(),r.fillStyle=v,r.font=`11px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`top`;for(let e=0;e<O;e++){let t=l+k*e+k/2,n=x[e].label;r.save(),r.rect(l+k*e+2,i+f+kq+2,k-4,c-kq-4),r.clip(),r.fillText(n,t,i+f+kq+2),r.restore()}}let v=K(_);v.current=_;let y=K(null);y.current??=VH(()=>v.current(),()=>c.current);let b=()=>y.current.schedule();return W(()=>{y.current.now()}),W(()=>()=>y.current?.cancel(),[]),W(()=>{l.current=null,b()},[i]),G(()=>{let e=c.current;if(!e)return;let t=new zH(()=>{l.current=null,b()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=s.current;if(!e)return;let t=e=>{e.preventDefault(),u.current?.({clientX:e.clientX,clientY:e.clientY})};return e.addEventListener(`contextmenu`,t),()=>e.removeEventListener(`contextmenu`,t)},[]),q(`div`,{ref:c,style:{position:`relative`,width:`100%`,height:`100%`},children:q(`canvas`,{ref:s,className:`chart-canvas`,role:`img`,"aria-label":`Box plot`})})}function Mq(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 Nq=e=>e.includes(`.`)&&!e.includes(`e`)?e.replace(/\.?0+$/,``):e;function Pq(e){return e>=1e3?`${Nq((e/1e3).toPrecision(3))}k`:Nq(e.toPrecision(3))}function Fq(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 Iq={top:14,right:24,bottom:40,left:68},Lq=[[8,0,16],[48,0,96],[104,0,144],[160,0,128],[200,32,64],[230,100,16],[250,200,32],[255,255,220]],Rq=-80;function zq(e){let t=Lq.length-1,n=Math.min(t-1,Math.floor(e*t)),r=e*t-n,[i,a,o]=Lq[n],[s,c,l]=Lq[n+1];return[i+(s-i)*r,a+(c-a)*r,o+(l-o)*r]}var Bq=(()=>{let e=new Uint8Array(256*4);for(let t=0;t<256;t++){let[n,r,i]=zq(t/255);e.set([n,r,i,255],t*4)}return e})();function Vq(e){let t=1;for(;t<e;)t<<=1;return t}var Hq=(e,t)=>Math.log(1+e/t*9)/Math.log(10),Uq=(e,t)=>t*(10**e-1)/9;function Wq({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=SU(),d=K(null),f=K(null),p=K(null),m=K(null),h=K(null),g=K(l);G(()=>{g.current=l},[l]);let _=Vq(Math.max(4,Math.min(n,4096))),v=Math.max(1,Math.round(_*(1-Math.max(0,Math.min(.95,r))))),y=ft(()=>{if(!o)return null;let e=_>>1,n=t/2;return Int32Array.from({length:e},(t,r)=>Math.min(e-1,Math.floor(Uq((r+.5)/e,n)/n*e)))},[o,_,t]),b=K(null),x=ft(()=>b.current=Fq(e,_,v,i===`hann`,a===`db`,y,b.current),[e,_,v,i,a,y]),S=ft(()=>({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+Rq,C]:[0,C],T=K({grid:S,range:w,sampleRate:t,winSz:_,step:v,yMode:a,logFreq:o,label:s});G(()=>{T.current={grid:S,range:w,sampleRate:t,winSz:_,step:v,yMode:a,logFreq:o,label:s}},[S,w[0],w[1],t,_,v,a,o,s]);let E=K({plot:null,failed:!1,size:``,grid:null,shown:null});W(()=>()=>{E.current.plot?.dispose(),E.current.plot=null},[]);function D(){if(h.current)return h.current;let e=m.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return h.current=n,n}function O(){let e=m.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function k(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function A(e,t){let n=E.current;if(!n.plot&&!n.failed&&f.current&&(n.plot=sH(f.current,iq),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=_G(Iq,t,n),{top:o,right:s,bottom:c,left:l}=a,f=t-l-s,h=n-o-c,{bg:g,muted:_,grid:v}=D(),{grid:y,sampleRate:b,winSz:x,step:S,logFreq:C,label:w}=T.current;r.fillStyle=g,r.fillRect(0,0,t,n);let j=A(t,n);if(y.w===0||f<=0||h<=0){if(j?.keep([]),j?.render(),a.tiny)return;r.fillStyle=_,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,zV(r);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=Mq(y,N).grid;j&&j.setGrid(`cells`,e.values,e.w,Math.min(e.h,j.maxTextureSize),[0,e.w,0,e.h],Bq,P,F),E.current.grid=y,E.current.shown=e,IH(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]=zq(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?Hq(e,R):e/R));L.strokeStyle=v,L.lineWidth=.5,L.globalAlpha=.4;let B=Az(0,R,Dz(R,5));L.setLineDash([3,4]);for(let e of B){let t=z(e);L.beginPath(),L.moveTo(l,t),L.lineTo(l+f,t),L.stroke()}L.setLineDash([]),L.globalAlpha=1,L.strokeStyle=v,L.strokeRect(l,o,f,h),r.fillStyle=_,r.font=`10px ${Q.mono}`,r.textAlign=`right`,r.textBaseline=`middle`,r.strokeStyle=_,r.lineWidth=1;for(let e of B){let t=z(e);r.beginPath(),r.moveTo(l-4,t),r.lineTo(l,t),r.stroke(),r.fillText(Pq(e),l-6,t)}let V=(y.w*S+x)/b;u({left:l,top:o,width:f,height:h,x:{v0:0,v1:V}});let ee=Dz(V,6),te=Az(0,V,ee);r.textAlign=`center`,r.textBaseline=`top`;for(let e of te){let t=l+e/V*f;r.beginPath(),r.moveTo(t,o+h),r.lineTo(t,o+h+4),r.stroke(),r.fillText(Pz(e,ee),t,o+h+6)}r.fillStyle=_,r.textAlign=`center`,r.textBaseline=`bottom`,r.fillText(w||`Time (s)`,l+f/2,n-4),r.save(),r.translate(12,o+h/2),r.rotate(-Math.PI/2),r.textAlign=`center`,r.fillText(`Frequency (Hz)`,0,0),r.restore()}let M=K(j);G(()=>{M.current=j});let N=K(null);return N.current??=VH(()=>M.current(),()=>m.current),W(()=>{N.current.now()},[S,w[0],w[1],t,_,v,a,o,s]),W(()=>()=>N.current?.cancel(),[]),W(()=>{h.current=null,N.current.schedule()},[c]),G(()=>{let e=m.current;if(!e)return;let t=new zH(()=>{h.current=null,N.current.schedule()});return t.observe(e),()=>t.disconnect()},[]),G(()=>{let e=p.current;if(!e)return;let t=e=>{e.preventDefault(),g.current?.({clientX:e.clientX,clientY:e.clientY})};return e.addEventListener(`contextmenu`,t),()=>e.removeEventListener(`contextmenu`,t)},[]),vt(`div`,{ref:m,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:d,className:`chart-canvas`,role:`img`,"aria-label":`Spectrogram`}),q(`canvas`,{ref:f,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),q(`canvas`,{ref:p,className:`chart-canvas chart-overlay`})]})}var Gq=300,Kq=256,qq=-60,Jq=[];function Yq({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=ft(()=>Fq(e,c,l,i===`hann`,u,null),[e,c,l,i,u]);return q(RK,{points:Jq,surface:ft(()=>Xq(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 Xq(e,t,n,r,i){let{frames:a,bins:o,values:s}=e;if(a<2||o<2)return;let c=Math.min(a,Gq),l=Math.min(o,Kq),u=i?20*Math.log10(Math.max(e.max,1e-12))+qq:-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 Zq(e,t,n){return Array.from({length:n},(r,i)=>e+(i+1)/(n+1)*(t-e))}function Qq(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 $q(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 eJ(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 tJ={top:14,right:32,bottom:80,left:80};function nJ(e,t,n){return[e[0]+(t[0]-e[0])*n,e[1]+(t[1]-e[1])*n,e[2]+(t[2]-e[2])*n]}var rJ=[[33,102,172],[103,169,207],[209,229,240],[247,247,247],[253,219,199],[239,138,98],[178,24,43]],iJ=[[13,8,135],[84,2,163],[139,10,165],[185,50,137],[219,92,104],[244,136,73],[254,188,43],[240,249,33]],aJ=[[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 oJ(e,t){let n=e.length-1,r=Math.min(n-1,Math.floor(t*n));return nJ(e[r],e[r+1],t*n-r)}function sJ(e,t){return oJ(t===`plasma`?iJ:t===`viridis`?aJ:rJ,e)}function cJ(e){let t=new Uint8Array(256*4);for(let n=0;n<256;n++){let[r,i,a]=sJ(n/255,e);t.set([r,i,a,255],n*4)}return t}function lJ(e){return Math.abs(e)>=1e4||Math.abs(e)<.01&&e!==0?e.toExponential(1):String(parseFloat(e.toPrecision(3)))}function uJ(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 dJ(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=$q(a),i=n[e.w]-n[0];u=Float64Array.from(n,e=>t+(e-n[0])/i*r)}if(l){let t=$q(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 fJ(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 pJ(e,t,n,r,i,a){let o=Math.max(1,i),s=Math.max(1,a),c=Int32Array.from({length:o},(e,r)=>fJ(t.xB,n+r+.5)),l=new Float32Array(o*s);for(let n=0;n<s;n++){let i=fJ(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 mJ({cells:e,xLabels:t,yLabels:n,grid:r,showValues:i=!0,colorScheme:a=`diverging`,vMin:o,vMax:s,xCentres:c,yCentres:l,contours:u=0,backgroundToken:d=``,onPlotContextMenu:f}){let p=K(null),m=K(null),h=K(null),g=K(null),_=K(null),v=K(null),y=K(null),b=K(0),x=K(f);G(()=>{x.current=f},[f]);let S=ft(()=>r??uJ(e??[],t??[],n??[]),[r,e,t,n]),C=ft(()=>{let e=o??1/0,t=s??-1/0;if(o===void 0||s===void 0){let n=1/0,r=-1/0;for(let e=0;e<S.w*S.h;e++){let t=S.values[e];t<n&&(n=t),t>r&&(r=t)}o===void 0&&(e=n),s===void 0&&(t=r)}return t>e||(e=Number.isFinite(e)?e-1:0,t=e+2),{lo:e,hi:t}},[S,o,s]),w=K({data:S,range:C,showValues:i,colorScheme:a,xCentres:c,yCentres:l,contours:u});G(()=>{w.current={data:S,range:C,showValues:i,colorScheme:a,xCentres:c,yCentres:l,contours:u}},[S,C,i,a,c,l,u]);let T=K({plot:null,failed:!1,size:``,data:null,key:``,shown:null,geo:null}),E=K({key:``,grid:null,segs:[]});W(()=>()=>{T.current.plot?.dispose(),T.current.plot=null},[]);let D=K({data:null,range:``});function O(){if(v.current)return v.current;let e=_.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return v.current=n,n}function k(){let e=_.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function A(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function j(e,t){let n=T.current;if(!n.plot&&!n.failed&&m.current&&(n.plot=sH(m.current,iq),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=_G(tJ,t,n),{top:o,right:s,bottom:c,left:l}=a,{bg:u,muted:d,grid:f}=O(),{data:m,range:{lo:g,hi:v},showValues:y,colorScheme:b}=w.current;r.fillStyle=u,r.fillRect(0,0,t,n);let x=j(t,n);if(m.w===0||m.h===0){x?.keep([]),x?.render(),r.fillStyle=d,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,zV(r);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}`},IH(_.current));let{xCentres:F,yCentres:I,contours:L}=w.current,R=x?x.maxTextureSize:Math.max(1,Math.round(S*N)),z=Mq(m,R).grid,B=dJ(z,l,o,S,C,z===m?F:void 0,z===m?I:void 0),V=B.byValue,ee=`${R}|${b}|${V?`${S}x${C}`:``}`,te=T.current.shown;if(T.current.data!==m||T.current.key!==ee||!te){te=z;let e=V?pJ(te,B,l,o,Math.round(S),Math.round(C)):te;x&&x.setGrid(`cells`,e.values,e.w,Math.min(e.h,x.maxTextureSize),[0,e.w,0,e.h],cJ(b),g,v),T.current.data=m,T.current.key=ee,T.current.shown=te}T.current.geo=B;let H=V?Math.round(S):te.w,ne=V?Math.round(C):te.h,re=e=>B.xB[e+1]-B.xB[e],ie=e=>B.yB[e+1]-B.yB[e];if(x)x.keep([`cells`]),x.setGridRange(`cells`,g,v),x.setView(0,H,ne,0,{left:l,top:o,width:S,height:C}),x.render();else for(let e=0;e<te.h;e++)for(let t=0;t<te.w;t++){let n=te.values[e*te.w+t];if(Number.isNaN(n))continue;let[i,a,o]=sJ(Math.max(0,Math.min(1,(n-g)/(v-g))),b);r.fillStyle=`rgb(${i|0},${a|0},${o|0})`,r.fillRect(B.xB[t],B.yB[e],re(t)+.5,ie(e)+.5)}let U=i??r;if(y){for(let e=0;e<te.h;e++)if(!(ie(e)<=16)){U.font=`${Math.min(12,Math.max(8,ie(e)*.4))}px ${Q.mono}`,U.textAlign=`center`,U.textBaseline=`middle`;for(let t=0;t<te.w;t++){let n=te.values[e*te.w+t];if(Number.isNaN(n)||re(t)<=28)continue;let[r,i,a]=sJ(Math.max(0,Math.min(1,(n-g)/(v-g))),b);U.fillStyle=.299*r+.587*i+.114*a>128?`#000`:`#fff`,U.fillText(lJ(n),(B.xB[t]+B.xB[t+1])/2,(B.yB[e]+B.yB[e+1])/2)}}}if(S/te.w>=4&&C/te.h>=4){U.strokeStyle=u,U.lineWidth=.5;for(let e=0;e<=te.w;e++)U.beginPath(),U.moveTo(B.xB[e],o),U.lineTo(B.xB[e],o+C),U.stroke();for(let e=0;e<=te.h;e++)U.beginPath(),U.moveTo(l,B.yB[e]),U.lineTo(l+S,B.yB[e]),U.stroke()}let ae=L>0?Zq(g,v,L):[];if(ae.length&&te.w>=2&&te.h>=2&&te.w*te.h<=4e6){let e=`${g}|${v}|${L}`;if(E.current.grid!==te||E.current.key!==e){let t=te;E.current={key:e,grid:t,segs:ae.map(e=>Qq(t.values,t.w,t.h,e))}}let t=(e,t)=>{let n=Math.min(t.length-3,Math.max(0,Math.floor(e))),r=(t[n]+t[n+1])/2;return r+((t[n+1]+t[n+2])/2-r)*(e-n)};U.save(),U.beginPath(),U.rect(l,o,S,C),U.clip(),U.lineCap=`round`,U.lineJoin=`round`;for(let[e,n]of[[2.6,`rgba(0,0,0,0.38)`],[1.1,`rgba(255,255,255,0.92)`]]){U.lineWidth=e,U.strokeStyle=n,U.beginPath();for(let e of E.current.segs)for(let[n,r,i,a]of e)U.moveTo(t(n,B.xB),t(r,B.yB)),U.lineTo(t(i,B.xB),t(a,B.yB));U.stroke()}U.restore()}r.fillStyle=d,r.font=`10px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`top`;let oe=-1/0;for(let e=0;e<(a.tiny?0:te.w);e++){let t=(B.xB[e]+B.xB[e+1])/2;t-oe<18||(oe=t,r.save(),r.translate(t,o+C+4),r.rotate(-Math.PI/4),r.fillText(M(te.xLabels,e),0,0),r.restore())}r.textAlign=`right`,r.textBaseline=`middle`;let se=-1/0;for(let e=0;e<(a.tiny?0:te.h);e++){let t=(B.yB[e]+B.yB[e+1])/2;t-se<12||(se=t,r.fillText(te.yLabels[e]??``,l-4,t))}if(a.tiny)return;let ce=t-s+4,le=o,ue=C;for(let e=0;e<ue;e++){let[t,n,i]=sJ(1-e/ue,b);r.fillStyle=`rgb(${t|0},${n|0},${i|0})`,r.fillRect(ce,le+e,12,1)}r.strokeStyle=f,r.lineWidth=.5,r.strokeRect(ce,le,12,ue),r.fillStyle=d,r.font=`9px ${Q.mono}`,r.textAlign=`left`,r.textBaseline=`middle`,r.fillText(lJ(v),ce+12+2,le),r.fillText(lJ(g),ce+12+2,le+ue),r.fillText(lJ((g+v)/2),ce+12+2,le+ue/2),r.strokeStyle=`rgba(255,255,255,0.92)`,r.lineWidth=1;for(let e of ae){let t=le+ue*(1-(e-g)/(v-g));r.beginPath(),r.moveTo(ce-2,t),r.lineTo(ce+12+2,t),r.stroke()}}function P(){let e=g.current;if(!e)return;let{w:t,h:n}=k(),r=A(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=y.current,a=T.current.shown,o=T.current.geo;if(!i||!a||!o)return;let{top:s,right:c,bottom:l}=_G(tJ,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]}: ${lJ(_)}`;r.font=`11px ${Q.mono}`;let n=r.measureText(e).width,i=Math.min(p+.1*(p-f),t-c-n-6),o=Math.max(s+4,m-.3*(h-m));r.fillStyle=`rgba(0,0,0,0.7)`,r.fillRect(i-3,o-3,n+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(e,i,o)}}let F=K(N);F.current=N;let I=K(null);I.current??=VH(()=>F.current(),()=>_.current);let L=()=>{b.current||=NH(()=>{b.current=0,P()})};return W(()=>{I.current.now()},[S,C,i,a,c,l,u]),W(()=>()=>{I.current?.cancel(),PH(b.current)},[]),W(()=>{v.current=null,I.current.schedule()},[d]),G(()=>{let e=_.current;if(!e)return;let t=new zH(()=>{v.current=null,I.current.schedule(),L()});return t.observe(e),()=>t.disconnect()},[]),G(()=>{let e=g.current;if(!e)return;let t=e=>{e.preventDefault(),x.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),{shown:r,geo:i}=T.current;if(!r||!i)return;let a=fJ(i.xB,t.clientX-n.left),o=fJ(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)}},[]),vt(`div`,{ref:_,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:p,className:`chart-canvas`,role:`img`,"aria-label":`Heatmap`}),q(`canvas`,{ref:m,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),q(`canvas`,{ref:h,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),q(`canvas`,{ref:g,className:`chart-canvas chart-overlay`})]})}var hJ=2e3,gJ=1024;function _J(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<=hJ){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(gJ),l=(i-r)/gJ||1;for(let t=0;t<a;t++)c[Math.max(0,Math.min(gJ-1,Math.floor((e[t]-r)/l)))]++;for(let e=0;e<n.length;e++){let i=0;for(let a=0;a<gJ;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 vJ={top:14,right:24,bottom:48,left:64},yJ=120;function bJ(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 xJ(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]=Dq(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:yJ},(e,t)=>r+t/(yJ-1)*(i-r));return{shapes:n.map((e,n)=>{let{q1:o,median:c,q3:l}=a[n],u=_J(e.values,t>0?t:bJ(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 SJ({groups:e,color:t=`#818cf8`,showBox:n=!0,bandwidth:r=0,orientation:i=`vertical`,backgroundToken:a=``,onPlotContextMenu:o}){let s=SU(),c=K(null),l=K(null),u=K(null),d=K(o);G(()=>{d.current=o},[o]);let f=K({groups:e,color:t,showBox:n,bandwidth:r,orientation:i});G(()=>{f.current={groups:e,color:t,showBox:n,bandwidth:r,orientation:i}},[e,t,n,r,i]);let p=ft(()=>xJ(e,r),[e,r]),m=K(p);G(()=>{m.current=p},[p]);function h(){if(u.current)return u.current;let e=l.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return u.current=n,n}function g(){let e=l.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function _(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function v(){let e=c.current;if(!e)return;let{w:t,h:n}=g(),r=_(e,t,n);if(!r)return;let{top:i,right:a,bottom:o,left:l}=vJ,u=t-l-a,d=n-i-o,{bg:p,muted:v,grid:y}=h(),{color:b,showBox:x,orientation:S}=f.current;r.fillStyle=p,r.fillRect(0,0,t,n);let{shapes:C,pts:w,yMin:T,yMax:E}=m.current;if(C.length===0||u<=0||d<=0){r.fillStyle=v,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,zV(r);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=Dz(E-T,5),A=Az(T,E,k);r.strokeStyle=y,r.lineWidth=1,r.setLineDash([3,3]);for(let e of A)D?(r.beginPath(),r.moveTo(l,O(e)),r.lineTo(l+u,O(e)),r.stroke()):(r.beginPath(),r.moveTo(O(e),i),r.lineTo(O(e),i+d),r.stroke());if(r.setLineDash([]),r.fillStyle=v,r.font=`11px ${Q.mono}`,r.strokeStyle=v,r.lineWidth=1,D){r.textAlign=`right`,r.textBaseline=`middle`;for(let e of A)r.beginPath(),r.moveTo(l-4,O(e)),r.lineTo(l,O(e)),r.stroke(),r.fillText(Pz(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(Pz(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<yJ;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=yJ-1;e>=0;e--){let i=t[e]/n*u,a=O(w[e]);D?r.lineTo(c+i,a):r.lineTo(a,c+i)}if(r.closePath(),r.fillStyle=b,r.globalAlpha=.35,r.fill(),r.strokeStyle=b,r.lineWidth=1,r.globalAlpha=.9,r.stroke(),r.globalAlpha=1,x){let e=u*.22;D?(r.fillStyle=b,r.globalAlpha=.7,r.fillRect(c-e,O(s),e*2,O(a)-O(s)),r.globalAlpha=1,r.strokeStyle=b,r.lineWidth=2,r.beginPath(),r.moveTo(c-e,O(o)),r.lineTo(c+e,O(o)),r.stroke()):(r.fillStyle=b,r.globalAlpha=.7,r.fillRect(O(a),c-e,O(s)-O(a),e*2),r.globalAlpha=1,r.strokeStyle=b,r.lineWidth=2,r.beginPath(),r.moveTo(O(o),c-e),r.lineTo(O(o),c+e),r.stroke())}}if(r.restore(),r.fillStyle=v,r.font=`11px ${Q.mono}`,D){r.textAlign=`center`,r.textBaseline=`top`;for(let e=0;e<j;e++)r.fillText(C[e].label,l+M*e+M/2,i+d+6)}else{r.textAlign=`right`,r.textBaseline=`middle`;for(let e=0;e<j;e++)r.fillText(C[e].label,l-6,i+M*e+M/2)}}let y=K(v);y.current=v;let b=K(null);b.current??=VH(()=>y.current(),()=>l.current);let x=()=>b.current.schedule();return W(()=>{b.current.now()}),W(()=>()=>b.current?.cancel(),[]),W(()=>{u.current=null,x()},[a]),G(()=>{let e=l.current;if(!e)return;let t=new zH(()=>{u.current=null,x()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=c.current;if(!e)return;let t=e=>{e.preventDefault(),d.current?.({clientX:e.clientX,clientY:e.clientY})};return e.addEventListener(`contextmenu`,t),()=>e.removeEventListener(`contextmenu`,t)},[]),q(`div`,{ref:l,style:{position:`relative`,width:`100%`,height:`100%`},children:q(`canvas`,{ref:c,className:`chart-canvas`,role:`img`,"aria-label":`Violin plot`})})}var CJ={top:48,right:16,bottom:72,left:80},wJ=[8,24,64],TJ=[56,189,248];function EJ(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 DJ(e){return`${(e*100).toFixed(1)}%`}function OJ(e,t,n){if(e.length===0)return null;let r=Math.min(e.length,t.length),i=Array(r),a=Array(r),o=new Set,s=0;for(let n=0;n<r;n++)i[n]=String(e[n]),a[n]=String(t[n]),o.add(i[n]),o.add(a[n]),i[n]===a[n]&&s++;let c=[...o].sort(),l=c.length,u=new Map(c.map((e,t)=>[e,t])),d=Array.from({length:l},()=>Array(l).fill(0));for(let e=0;e<r;e++)d[u.get(i[e])][u.get(a[e])]++;let f=d.map(e=>e.reduce((e,t)=>e+t,0));return{classes:c,matrix:n?d.map((e,t)=>e.map(e=>f[t]>0?e/f[t]:0)):d,raw:d,accuracy:s/e.length}}function kJ({actual:e,predicted:t,normalize:n=!1,backgroundToken:r=``,onPlotContextMenu:i}){let a=K(null),o=K(null),s=K(null),c=K(null),l=K(null),u=K(0),d=K(i);G(()=>{d.current=i},[i]);let f=K({actual:e,predicted:t,normalize:n});G(()=>{f.current={actual:e,predicted:t,normalize:n}},[e,t,n]);function p(){if(c.current)return c.current;let e=s.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return c.current=n,n}function m(){let e=s.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function h(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}let g=ft(()=>OJ(e,t,n),[e,t,n]),_=K(g);G(()=>{_.current=g},[g]);let v=()=>_.current;function y(){let e=a.current;if(!e)return;let{w:t,h:n}=m(),r=h(e,t,n);if(!r)return;let{top:i,right:o,bottom:s,left:c}=CJ,{bg:l,muted:u,grid:d}=p();r.fillStyle=l,r.fillRect(0,0,t,n);let g=v();if(!g){r.fillStyle=u,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,zV(r);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]=EJ(wJ,TJ,E>0?n/E:0);if(r.fillStyle=`rgb(${a|0},${o|0},${s|0})`,r.fillRect(c+t*w,i+e*T,w,T),w>24&&T>14){r.fillStyle=.299*a+.587*o+.114*s>100?`#000`:`#fff`,r.font=`${Math.min(12,Math.max(8,T*.38))}px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`middle`;let l=f.current.normalize;r.fillText(l?DJ(n):String(n|0),c+(t+.5)*w,i+(e+.5)*T)}}r.strokeStyle=l,r.lineWidth=.5;for(let e=0;e<=x;e++)r.beginPath(),r.moveTo(c+e*w,i),r.lineTo(c+e*w,i+C),r.stroke(),r.beginPath(),r.moveTo(c,i+e*T),r.lineTo(c+S,i+e*T),r.stroke();r.strokeStyle=d,r.strokeRect(c,i,S,C),r.fillStyle=u,r.font=`10px ${Q.mono}`,r.textAlign=`right`,r.textBaseline=`middle`;for(let e=0;e<x;e++)r.fillText(_[e],c-4,i+(e+.5)*T);r.textAlign=`center`,r.textBaseline=`top`;for(let e=0;e<x;e++)r.save(),r.translate(c+(e+.5)*w,i+C+4),r.rotate(-Math.PI/4),r.fillText(_[e],0,0),r.restore();r.fillStyle=u,r.font=`11px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`bottom`,r.fillText(`Predicted`,c+S/2,n-4),r.save(),r.translate(12,i+C/2),r.rotate(-Math.PI/2),r.textAlign=`center`,r.fillText(`Actual`,0,0),r.restore(),r.fillStyle=u,r.font=`11px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`middle`,r.fillText(`Accuracy: ${DJ(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}=CJ,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?DJ(C):C|0}`;r.font=`11px ${Q.mono}`;let E=r.measureText(T).width,D=Math.min(u+(i.c+1.1)*x,t-E-6),O=Math.max(6,a+(i.r-.3)*S);r.fillStyle=`rgba(0,0,0,0.75)`,r.fillRect(D-3,O-3,E+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(T,D,O)}let x=K(y);x.current=y;let S=K(null);S.current??=VH(()=>x.current(),()=>s.current);let C=()=>S.current.schedule(),w=()=>{PH(u.current),u.current=NH(b)};return W(()=>{S.current.now()}),W(()=>()=>S.current?.cancel(),[]),W(()=>{c.current=null,C()},[r]),G(()=>{let e=s.current;if(!e)return;let t=new zH(()=>{c.current=null,C(),w()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=o.current;if(!e)return;let t=e=>{e.preventDefault(),d.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),{top:r,right:i,bottom:a,left:o}=CJ,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)}},[]),vt(`div`,{ref:s,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:a,className:`chart-canvas`,role:`img`,"aria-label":`Confusion matrix`}),q(`canvas`,{ref:o,className:`chart-canvas chart-overlay`})]})}var AJ={top:24,right:24,bottom:48,left:64};function jJ(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 MJ(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 NJ(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 PJ(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 FJ({scores:e,labels:t,mode:n=`roc`,color:r=`#f472b6`,backgroundToken:i=``,onPlotContextMenu:a}){let o=K(null),s=K(null),c=K(null),l=K(a);G(()=>{l.current=a},[a]);let u=K({scores:e,labels:t,mode:n,color:r});G(()=>{u.current={scores:e,labels:t,mode:n,color:r}},[e,t,n,r]);let d=ft(()=>jJ(e,t),[e,t]),f=ft(()=>n===`pr`?{roc:null,pr:NJ(d)}:{roc:MJ(d),pr:null},[d,n]),p=K(f);G(()=>{p.current=f},[f]);function m(){if(c.current)return c.current;let e=s.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return c.current=n,n}function h(){let e=s.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function g(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function _(){let e=o.current;if(!e)return;let{w:t,h:n}=h(),r=g(e,t,n);if(!r)return;let{top:i,right:a,bottom:s,left:c}=AJ,l=t-c-a,d=n-i-s,{bg:f,muted:_,grid:v}=m(),{scores:y,mode:b,color:x}=u.current;if(r.fillStyle=f,r.fillRect(0,0,t,n),y.length===0){r.fillStyle=_,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,zV(r);return}let S=e=>c+e*l,C=e=>i+(1-e)*d,w=Az(0,1,Dz(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(),PJ(r,t,n,a),r.strokeStyle=x,r.lineWidth=1,r.stroke(),r.beginPath(),PJ(r,t,n,a),r.lineTo(S(1),C(0)),r.lineTo(S(0),C(0)),r.closePath(),r.fillStyle=x,r.globalAlpha=.15,r.fill(),r.globalAlpha=1,r.fillStyle=x,r.font=`bold 13px ${Q.mono}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`AUC = ${e.auc.toFixed(3)}`,c+8,i+8)}}else{let e=p.current.pr;if(e){let t=uq(e.recall,e.precision,0,1,Math.max(1,Math.round(l*Math.min(2,window.devicePixelRatio||1))));r.beginPath();for(let n=0;n<t.length;n++){let i=S(e.recall[t[n]]),a=C(e.precision[t[n]]);n===0?r.moveTo(i,a):r.lineTo(i,a)}r.strokeStyle=x,r.lineWidth=1,r.stroke(),r.fillStyle=x,r.font=`bold 13px ${Q.mono}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`AP = ${e.ap.toFixed(3)}`,c+8,i+8)}}r.fillStyle=_,r.font=`11px ${Q.mono}`,r.strokeStyle=_,r.lineWidth=1,r.textAlign=`right`,r.textBaseline=`middle`;for(let e of w)r.beginPath(),r.moveTo(c-4,C(e)),r.lineTo(c,C(e)),r.stroke(),r.fillText(e.toFixed(1),c-6,C(e));r.textAlign=`center`,r.textBaseline=`top`;for(let e of w)r.beginPath(),r.moveTo(S(e),i+d),r.lineTo(S(e),i+d+4),r.stroke(),r.fillText(e.toFixed(1),S(e),i+d+6);r.strokeStyle=v,r.strokeRect(c,i,l,d),r.fillStyle=_,r.textAlign=`center`,r.textBaseline=`bottom`,r.fillText(b===`roc`?`False Positive Rate`:`Recall`,c+l/2,n-4),r.save(),r.translate(12,i+d/2),r.rotate(-Math.PI/2),r.textAlign=`center`,r.fillText(b===`roc`?`True Positive Rate`:`Precision`,0,0),r.restore()}let v=K(_);v.current=_;let y=K(null);y.current??=VH(()=>v.current(),()=>s.current);let b=()=>y.current.schedule();return W(()=>{y.current.now()}),W(()=>()=>y.current?.cancel(),[]),W(()=>{c.current=null,b()},[i]),G(()=>{let e=s.current;if(!e)return;let t=new zH(()=>{c.current=null,b()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=o.current;if(!e)return;let t=e=>{e.preventDefault(),l.current?.({clientX:e.clientX,clientY:e.clientY})};return e.addEventListener(`contextmenu`,t),()=>e.removeEventListener(`contextmenu`,t)},[]),q(`div`,{ref:s,style:{position:`relative`,width:`100%`,height:`100%`},children:q(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`ROC / PR curve`})})}var IJ={top:20,right:64,bottom:48,left:64};function LJ({xValues:e,series:t,xLabel:n=`Epoch`,backgroundToken:r=``,onPlotContextMenu:i}){let a=SU(),o=K(null),s=K(null),c=K(null),l=K(null),u=K(null),d=K(0),f=K(i);G(()=>{f.current=i},[i]);let p=K({xValues:e,series:t,xLabel:n});G(()=>{p.current={xValues:e,series:t,xLabel:n}},[e,t,n]);function m(){if(l.current)return l.current;let e=c.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return l.current=n,n}function h(){let e=c.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function g(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}let _=ft(()=>{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:pq(e)}},[e,t]),v=K(_);G(()=>{v.current=_},[_]);function y(){let e=o.current;if(!e)return;let{w:t,h:n}=h(),r=g(e,t,n);if(!r)return;let{top:i,right:s,bottom:c,left:l}=IJ,u=t-l-s,d=n-i-c,{bg:f,muted:_,grid:y}=m(),{xValues:b,series:x,xLabel:S}=p.current;if(r.fillStyle=f,r.fillRect(0,0,t,n),b.length===0||x.length===0){r.fillStyle=_,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,zV(r);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=Dz(C.hi-C.lo,5),N=Az(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=Dz(D-E,6),F=Az(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?uq(b,e.values,E,D,L):null;r.beginPath();let a=!1;for(let o=0;o<(i?i.length:n);o++){let n=i?i[o]:o,s=b[n],c=e.values[n];if(s-s!==0||c-c!==0){a=!1;continue}let l=k(s),u=t(c);a?r.lineTo(l,u):(r.moveTo(l,u),a=!0)}r.strokeStyle=e.color,r.lineWidth=1,r.stroke()}r.fillStyle=_,r.font=`11px ${Q.mono}`,r.strokeStyle=_,r.lineWidth=1,r.textAlign=`right`,r.textBaseline=`middle`;for(let e of N)r.beginPath(),r.moveTo(l-4,A(e)),r.lineTo(l,A(e)),r.stroke(),r.fillText(Pz(e,M),l-6,A(e));if(T){let e=Dz(w.hi-w.lo,5),t=Az(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(Pz(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(Pz(e,P),k(e),i+d+6);r.strokeStyle=y,r.strokeRect(l,i,u,d),r.fillStyle=_,r.textAlign=`center`,r.textBaseline=`bottom`,r.fillText(S,l+u/2,n-4);let R=l+8,z=i+6;r.font=`10px ${Q.mono}`,r.textBaseline=`middle`;for(let e of x)r.fillStyle=e.color,r.fillRect(R,z-4,16,3),r.fillStyle=_,r.textAlign=`left`,r.fillText(e.label,R+20,z),R+=r.measureText(e.label).width+36,R>l+u-60&&(R=l+8,z+=14)}function b(){let e=s.current;if(!e)return;let{w:t,h:n}=h(),r=g(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=u.current;if(i===null)return;let{top:a,right:o,bottom:c,left:l}=IJ,d=t-l-o,f=n-a-c,{muted:_}=m(),{xValues:y,series:b}=p.current;if(y.length===0)return;let{xMin:x,xMax:S,ascending:C}=v.current,w=e=>l+(e-x)/(S-x||1)*d,T=Math.max(l,Math.min(l+d,i));r.strokeStyle=_,r.lineWidth=1,r.setLineDash([3,3]),r.beginPath(),r.moveTo(T,a),r.lineTo(T,a+f),r.stroke(),r.setLineDash([]);let E=(T-l)/d,D=Math.round(E*(y.length-1));if(C){let e=x+E*(S-x),t=0,n=y.length;for(;t<n;){let r=t+n>>>1;y[r]<e?t=r+1:n=r}D=t>0&&(t>=y.length||e-y[t-1]<y[t]-e)?t-1:t}if(D<0||D>=y.length)return;let O=a+8;r.font=`10px ${Q.mono}`,r.textBaseline=`top`;for(let e of b)D<e.values.length&&Number.isFinite(e.values[D])&&(r.fillStyle=e.color,r.textAlign=`left`,r.fillText(`${e.label}: ${Fz(e.values[D])}`,T+6,O),O+=14);w(0)}let x=K(y);x.current=y;let S=K(null);S.current??=VH(()=>x.current(),()=>c.current);let C=()=>S.current.schedule(),w=()=>{PH(d.current),d.current=NH(b)};return W(()=>{S.current.now()}),W(()=>()=>S.current?.cancel(),[]),W(()=>{l.current=null,C()},[r]),G(()=>{let e=c.current;if(!e)return;let t=new zH(()=>{l.current=null,C(),w()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=s.current;if(!e)return;let t=e=>{e.preventDefault(),f.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect();u.current=t.clientX-n.left,w()},r=()=>{u.current=null,w()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),vt(`div`,{ref:c,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`Loss curves`}),q(`canvas`,{ref:s,className:`chart-canvas chart-overlay`})]})}var RJ={top:40,right:24,bottom:40,left:72},zJ=`#ef4444`,BJ=`#f97316`,VJ=`#22d3ee`;function HJ(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 UJ({points:e,sigmaLevel:t=3,color:n=`#22d3ee`,backgroundToken:r=``,onPlotContextMenu:i}){let a=SU(),o=K(null),s=K(null),c=K(null),l=K(null),u=K(null),d=K(0),f=K(i);G(()=>{f.current=i},[i]);let p=K({points:e,sigmaLevel:t,color:n});G(()=>{p.current={points:e,sigmaLevel:t,color:n}},[e,t,n]);function m(){if(l.current)return l.current;let e=c.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return l.current=n,n}function h(){let e=c.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function g(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}let _=ft(()=>HJ(e,t),[e,t]),v=K(_);G(()=>{v.current=_},[_]);let y=()=>v.current;function b(){let e=o.current;if(!e)return;let{w:t,h:n}=h(),r=g(e,t,n);if(!r)return;let{top:i,right:s,bottom:c,left:l}=RJ,u=t-l-s,d=n-i-c,{bg:f,muted:_,grid:v}=m(),{points:b,color:x}=p.current;if(r.fillStyle=f,r.fillRect(0,0,t,n),b.length===0){r.fillStyle=_,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,zV(r);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=Dz(D-E,5),j=Az(E,D,A);r.strokeStyle=v,r.lineWidth=1,r.setLineDash([3,3]);for(let e of j)r.beginPath(),r.moveTo(l,k(e)),r.lineTo(l+u,k(e)),r.stroke();r.setLineDash([]);let M=(e,t,n,a=[])=>{let o=k(e);o<i||o>i+d||(r.strokeStyle=t,r.lineWidth=1.2,r.setLineDash(a),r.beginPath(),r.moveTo(l,o),r.lineTo(l+u,o),r.stroke(),r.setLineDash([]),r.fillStyle=t,r.font=`9px ${Q.mono}`,r.textAlign=`right`,r.textBaseline=`middle`,r.fillText(`${n} ${Fz(e)}`,l+u-2,o-5))};M(w,BJ,`UCL`,[5,3]),M(C,VJ,`CL`,[]),M(T,BJ,`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=dq(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?zJ:x,r.fill()};if(F<=u/4)for(let e=0;e<F;e++)R(e,I[e]>w||I[e]<T);else{let e=NaN,t=NaN;for(let n of S.ooc){let r=Math.round(O(n)),i=Math.round(k(I[n]));r===e&&i===t||(e=r,t=i,R(n,!0))}}r.fillStyle=_,r.font=`11px ${Q.mono}`,r.strokeStyle=_,r.lineWidth=1,r.textAlign=`right`,r.textBaseline=`middle`;for(let e of j)r.beginPath(),r.moveTo(l-4,k(e)),r.lineTo(l,k(e)),r.stroke(),r.fillText(Pz(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}=RJ,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}: `}${Fz(D)}`;r.font=`11px ${Q.mono}`;let M=r.measureText(j).width,N=O+8+M>l+d?O-M-10:O+8;r.fillStyle=`rgba(0,0,0,0.75)`,r.fillRect(N-3,k-12,M+6,18),r.fillStyle=D>b||D<x?zJ:_,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(j,N,k-11)}let S=K(b);S.current=b;let C=K(null);C.current??=VH(()=>S.current(),()=>c.current);let w=()=>C.current.schedule(),T=()=>{PH(d.current),d.current=NH(x)};return W(()=>{C.current.now()}),W(()=>()=>C.current?.cancel(),[]),W(()=>{l.current=null,w()},[r]),G(()=>{let e=c.current;if(!e)return;let t=new zH(()=>{l.current=null,w(),T()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=s.current;if(!e)return;let t=e=>{e.preventDefault(),f.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect();u.current=t.clientX-n.left,T()},r=()=>{u.current=null,T()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),vt(`div`,{ref:c,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`Control chart`}),q(`canvas`,{ref:s,className:`chart-canvas chart-overlay`})]})}var WJ={top:32,right:24,bottom:24,left:24},GJ=[`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`,`#facc15`,`#60a5fa`],KJ=16;function qJ(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 JJ(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:KJ},(e,t)=>qJ((t+.5)/KJ));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(KJ-1,Math.floor(e*KJ))):-1}for(let t=0;t<e.length;t++)s[t]<0&&(s[t]=0)}else if(!n&&e.colorIndex){c=GJ;for(let t=0;t<e.length;t++)s[t]=Math.max(0,e.colorIndex[t])%GJ.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 YJ({rows:e,axes:t,color:n=`#64748b`,colorByNumeric:r=!1,backgroundToken:i=``,onPlotContextMenu:a}){let o=K(null),s=K(null),c=K(null),l=K(null),u=K(null),d=K(null),f=K(null),p=K(0),m=K(a);G(()=>{m.current=a},[a]);let h=ft(()=>JJ(e,t.length,r,n),[e,t.length,r,n]),g=K({rows:e,axes:t,colorByNumeric:r,model:h});G(()=>{g.current={rows:e,axes:t,colorByNumeric:r,model:h}},[e,t,r,h]);let _=aq(s),v=K(null);function y(){if(d.current)return d.current;let e=u.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return d.current=n,n}function b(){let e=u.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function x(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function S(){let e=o.current;if(!e)return;let{w:t,h:n}=b(),r=x(e,t,n);if(!r)return;let i=c.current?x(c.current,t,n):null;i?.clearRect(0,0,t,n);let a=i??r,{top:s,right:l,bottom:d,left:f}=WJ,{bg:p,muted:m}=y(),{rows:h,axes:S,colorByNumeric:C,model:w}=g.current;r.fillStyle=p,r.fillRect(0,0,t,n);let T=_(t,n);if(S.length<2||h.length===0||w.k<2){T?.keep([]),T?.render(),r.fillStyle=m,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`Select ≥ 2 axes`,f+8,s+8);return}let E=t-f-l,D=n-s-d,O=w.k,k=Array.from({length:O},(e,t)=>f+t/(O-1)*E),A=(e,t)=>{let n=w.extents[t];return s+(1-(e-n.lo)/(n.hi-n.lo))*D},j=Math.max(.05,Math.min(.7,60/h.length));if(T)v.current!==w&&(w.groups.forEach((e,t)=>T.setLine(`c${t}`,e.x,e.y,vK(e.color,j),1,e.starts)),v.current=w,IH(u.current)),T.keep(w.groups.map((e,t)=>`c${t}`)),T.setView(0,O-1,0,1,{left:f,top:s,width:E,height:D}),T.render();else{r.globalAlpha=j;for(let e of w.groups){r.beginPath();let t=!1;for(let n=0;n<e.x.length;n++){let i=e.y[n];if(e.starts[n]&&(t=!1),i!==i){t=!1;continue}let a=f+e.x[n]/(O-1)*E,o=s+(1-i)*D;t?r.lineTo(a,o):(r.moveTo(a,o),t=!0)}r.strokeStyle=e.color,r.lineWidth=1,r.stroke()}r.globalAlpha=1}a.strokeStyle=m,a.lineWidth=1.5;for(let e=0;e<O;e++)a.beginPath(),a.moveTo(k[e],s),a.lineTo(k[e],s+D),a.stroke();a.fillStyle=m,a.font=`9px ${Q.mono}`;for(let e=0;e<O;e++){let t=w.extents[e];for(let n of[0,.25,.5,.75,1]){let r=t.lo+n*(t.hi-t.lo),i=A(r,e);a.beginPath(),a.moveTo(k[e]-3,i),a.lineTo(k[e]+3,i),a.stroke(),a.textAlign=e===O-1?`left`:`right`,a.textBaseline=`middle`,a.fillText(Pz(r,(t.hi-t.lo)/4),k[e]+(e===O-1?5:-5),i)}a.font=`10px ${Q.mono}`,a.textAlign=`center`,a.textBaseline=`bottom`,a.fillText(S[e],k[e],s-4)}let M=h.colorLabels??[];if(!C&&M.length>0&&M.length<=10){let e=f,t=s+D+8;a.font=`9px ${Q.mono}`,a.textBaseline=`top`,M.forEach((n,r)=>{a.fillStyle=GJ[r%GJ.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}=WJ,{axes:u}=g.current;if(u.length<2)return;let d=t-c-o,p=c+i/(u.length-1)*d;r.strokeStyle=`rgba(255,255,255,0.6)`,r.lineWidth=2,r.beginPath(),r.moveTo(p,a-4),r.lineTo(p,a+(n-a-s)+4),r.stroke()}let w=K(S);w.current=S;let T=K(null);T.current??=VH(()=>w.current(),()=>u.current);let E=()=>T.current.schedule(),D=()=>{PH(p.current),p.current=NH(C)};return W(()=>{T.current.now()}),W(()=>()=>T.current?.cancel(),[]),W(()=>{d.current=null,E()},[i]),G(()=>{let e=u.current;if(!e)return;let t=new zH(()=>{d.current=null,E(),D()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=l.current;if(!e)return;let t=e=>{e.preventDefault(),m.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),{axes:r}=g.current;if(r.length<2)return;let i=n.width-WJ.left-WJ.right,a=r.length,o=t.clientX-n.left-WJ.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)}},[]),vt(`div`,{ref:u,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`Parallel coordinates`}),q(`canvas`,{ref:s,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),q(`canvas`,{ref:c,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),q(`canvas`,{ref:l,className:`chart-canvas chart-overlay`})]})}function XJ(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 ZJ(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 QJ={top:16,right:16,bottom:16,left:16},$J=[`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`,`#facc15`,`#60a5fa`];function eY(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 tY(e){let[t,n,r]=eY(e);return`rgb(${t},${n},${r})`}var nY=(()=>{let e=new Uint8Array(1024);for(let t=0;t<256;t++)e.set([...eY(t/255),255],t*4);return e})(),rY=(()=>{let e=new Uint8Array(1024);for(let t=0;t<256;t++){let[n,r,i]=vK($J[t%$J.length],1);e.set([n*255,r*255,i*255,255],t*4)}return e});function iY(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 aY({points:e,color:t=`#64748b`,colorByNumeric:n=!1,pointSize:r=4,backgroundToken:i=``,onPlotContextMenu:a}){let o=K(null),s=K(null),c=K(null),l=K(null),u=K(null),d=K(null),f=K(0),p=K(a);G(()=>{p.current=a},[a]);let m=ft(()=>iY(e,n),[e,n]),h=K({points:e,color:t,colorByNumeric:n,pointSize:r,model:m});G(()=>{h.current={points:e,color:t,colorByNumeric:n,pointSize:r,model:m}},[e,t,n,r,m]);let g=K({r:null,failed:!1,size:``,model:null,style:``});W(()=>()=>{g.current.r?.dispose(),g.current.r=null},[]);function _(){if(u.current)return u.current;let e=l.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return u.current=n,n}function v(){let e=l.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function y(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function b(e,t){let{top:n,right:r,bottom:i,left:a}=QJ,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=sH(s.current,hG),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,IH(l.current));let f=`${c.mode}|${u}|${d}`;return n.style!==f&&(r.setStyle(c.mode===`single`?{kind:`single`,rgba:vK(u,1)}:{kind:c.mode,palette:c.mode===`colormap`?nY:rY()},d,.8),r.setDraw(!0,!1,0),n.style=f),r}function S(){let e=o.current;if(!e)return;let{w:t,h:n}=v(),r=y(e,t,n);if(!r)return;let{bg:i,muted:a}=_(),{points:s,color:c,colorByNumeric:l,pointSize:u,model:d}=h.current;r.fillStyle=i,r.fillRect(0,0,t,n);let f=x(t,n);if(s.length===0){f?.setData([],[]),g.current.model=null,f?.render(),r.fillStyle=a,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,zV(r);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:QJ.left,top:QJ.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`?tY(i):d.mode===`dataset`?$J[i%$J.length]:c,r.globalAlpha=.8,r.fill()}r.globalAlpha=1}if(l){let e=Math.min(120,Math.floor((n-QJ.top-QJ.bottom)*.4)),i=t-QJ.right-12,o=QJ.top+8;for(let t=0;t<e;t++)r.fillStyle=tY(1-t/(e-1)),r.fillRect(i,o+t,8,1);r.fillStyle=a,r.font=`9px ${Q.mono}`,r.textAlign=`left`,r.textBaseline=`middle`;let s=e=>Math.abs(e)>=1e4||Math.abs(e)<.001&&e!==0?e.toExponential(1):String(parseFloat(e.toPrecision(3)));r.fillText(s(p.hi),i+10,o),r.fillText(s(p.lo),i+10,o+e)}let E=s.colorLabels??[];if(!l&&E.length>0&&E.length<=10){let e=QJ.left,i=n-QJ.bottom-10;r.font=`9px ${Q.mono}`,r.textBaseline=`top`,E.forEach((n,o)=>{e>t-QJ.right-60&&(e=QJ.left,i-=14),r.fillStyle=$J[o%$J.length],r.beginPath(),r.arc(e+4,i+4,4,0,Math.PI*2),r.fill(),r.fillStyle=a,r.textAlign=`left`,r.fillText(n,e+10,i),e+=r.measureText(n).width+20})}}function C(){let e=c.current;if(!e)return;let{w:t,h:n}=v(),r=y(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=d.current;if(i===null)return;let{points:a,pointSize:o}=h.current;if(i<0||i>=a.length)return;let{xToPx:s,yToPx:l}=b(t,n),u=a.x[i],f=a.y[i],p=s(u),m=l(f);r.beginPath(),r.arc(p,m,o+3,0,Math.PI*2),r.strokeStyle=`rgba(255,255,255,0.9)`,r.lineWidth=2,r.stroke();let g=[],_=a.label?.(i);_&&g.push(_);let x=a.colorIndex?.[i];x!==void 0&&x>=0&&a.colorLabels?g.push(a.colorLabels[x]):a.colorValue&&g.push(a.colorValue[i].toFixed(3)),g.push(`(${u.toFixed(3)}, ${f.toFixed(3)})`);let S=g.join(` · `);r.font=`11px ${Q.mono}`;let C=r.measureText(S).width,w=Math.max(4,Math.min(t-C-8,p+10)),T=m-20<QJ.top?m+10:m-20;r.fillStyle=`rgba(0,0,0,0.75)`,r.fillRect(w-3,T-3,C+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(S,w,T)}let w=K(S);w.current=S;let T=K(null);T.current??=VH(()=>w.current(),()=>l.current);let E=()=>T.current.schedule(),D=()=>{PH(f.current),f.current=NH(C)};return W(()=>{T.current.now()}),W(()=>()=>T.current?.cancel(),[]),W(()=>{u.current=null,E()},[i]),G(()=>{let e=l.current;if(!e)return;let t=new zH(()=>{u.current=null,E(),D()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=c.current;if(!e)return;let t=null,n=e=>{e.preventDefault(),p.current?.({clientX:e.clientX,clientY:e.clientY})},r=n=>{let r=e.getBoundingClientRect(),{points:i,pointSize:a,model:o}=h.current,{w:s,h:c}=v(),{xToPx:l,yToPx:u,plotW:f,plotH:p}=b(s,c),m=e=>l(i.x[e])-QJ.left,g=e=>u(i.y[e])-QJ.top,_=a+8,y=`${s}|${c}|${_}`;(!t||t.model!==o||t.key!==y)&&(t={model:o,key:y,g:XJ(i.length,f,p,_,m,g)}),d.current=ZJ(t.g,n.clientX-r.left-QJ.left,n.clientY-r.top-QJ.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)}},[]),vt(`div`,{ref:l,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`Embedding / scatter`}),q(`canvas`,{ref:s,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),q(`canvas`,{ref:c,className:`chart-canvas chart-overlay`})]})}var oY={top:8,right:8,bottom:8,left:8},sY=20,cY=[`#f97316`,`#fb923c`,`#fdba74`,`#fbbf24`,`#fcd34d`,`#4ade80`,`#34d399`,`#38bdf8`,`#818cf8`,`#a78bfa`];function lY(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 uY(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 dY(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 fY(e){return cY[e%cY.length]}function pY({nodes:e,direction:t=`bottomup`,backgroundToken:n=``,onPlotContextMenu:r}){let i=K(null),a=K(null),o=K(null),s=K(null),c=K(null),l=K(0),u=K(r);G(()=>{u.current=r},[r]);let d=K({nodes:e,direction:t});G(()=>{d.current={nodes:e,direction:t}},[e,t]);let f=ft(()=>{let t=lY(e);return{roots:t,flat:uY(t),numRows:dY(t)+1}},[e]),p=K(f);G(()=>{p.current=f},[f]);function m(){if(s.current)return s.current;let e=o.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return s.current=n,n}function h(){let e=o.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function g(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function _(e,t,n,r,i){let a=oY.left+e.x0*t,o=(e.x1-e.x0)*t;return{x:a,y:i===`topdown`?oY.top+e.depth*sY:oY.top+n-(e.depth+1)*sY,w:o,h:sY-1}}function v(){let e=i.current;if(!e)return;let{w:t,h:n}=h(),r=g(e,t,n);if(!r)return;let{bg:a,muted:o}=m(),{nodes:s,direction:c}=d.current;if(r.fillStyle=a,r.fillRect(0,0,t,n),s.length===0){r.fillStyle=o,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,zV(r);return}let{flat:l,numRows:u}=p.current,f=t-oY.left-oY.right,v=u*sY;for(let e of l){let t=_(e,f,v,u,c);if(!(t.w<1)&&(r.fillStyle=fY(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,sY-4)}px ${Q.mono}`,r.textAlign=`left`,r.textBaseline=`middle`;let n=e.name,i=Math.floor((t.w-4)/7),a=n.length>i?n.slice(0,i-1)+`…`:n;r.fillText(a,t.x+3,t.y+sY/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-oY.left-oY.right,l*sY,l,o);r.strokeStyle=`rgba(255,255,255,0.9)`,r.lineWidth=2,r.strokeRect(u.x+1,u.y+1,u.w-2,u.h-2);let f=`${i.name} (${i.value.toLocaleString()})`;r.font=`11px ${Q.mono}`;let m=r.measureText(f).width,v=Math.max(4,Math.min(t-m-8,u.x+u.w/2-m/2)),y=u.y<30?u.y+sY+4:u.y-20;r.fillStyle=`rgba(0,0,0,0.8)`,r.fillRect(v-3,y-3,m+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(f,v,y)}let b=K(v);b.current=v;let x=K(null);x.current??=VH(()=>b.current(),()=>o.current);let S=()=>x.current.schedule(),C=()=>{PH(l.current),l.current=NH(y)};return W(()=>{x.current.now()}),W(()=>()=>x.current?.cancel(),[]),W(()=>{s.current=null,S()},[n]),G(()=>{let e=o.current;if(!e)return;let t=new zH(()=>{s.current=null,S(),C()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=a.current;if(!e)return;let t=e=>{e.preventDefault(),u.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),{direction:r}=d.current,{roots:i,flat:a,numRows:o}=p.current;if(i.length===0){c.current=null,C();return}let s=t.clientX-n.left,l=t.clientY-n.top,u=n.width-oY.left-oY.right,f=o*sY,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)}},[]),vt(`div`,{ref:o,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:i,className:`chart-canvas`,role:`img`,"aria-label":`Flame graph`}),q(`canvas`,{ref:a,className:`chart-canvas chart-overlay`})]})}var mY={top:24,right:24,bottom:52,left:56},hY=[`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`,`#facc15`,`#60a5fa`],gY=.8;function _Y(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 vY(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 yY({groups:e,columns:t,seriesNames:n,colors:r,mode:i=`grouped`,horizontal:a=!1,valueRange:o,backgroundToken:s=``,onPlotContextMenu:c}){let l=SU(),u=K(null),d=K(null),f=K(null),p=K(null),m=K(null),h=K(null),g=K(0),_=K(c);G(()=>{_.current=c},[c]);let v=K(null),y=ft(()=>{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=_Y(e,t,n.length,i);return v.current={key:r,value:o},o},[e,t,n.length,i]),b=K({bars:y,seriesNames:n,colors:r,mode:i,horizontal:a,valueRange:o});G(()=>{b.current={bars:y,seriesNames:n,colors:r,mode:i,horizontal:a,valueRange:o}},[y,n,r,i,a,o]);let x=K({plot:null,failed:!1,key:``,data:null,size:``});W(()=>()=>{x.current.plot?.dispose(),x.current.plot=null},[]);let S=K({bars:null,view:``});function C(){if(m.current)return m.current;let e=p.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return m.current=n,n}function w(){let e=p.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||300)}}function T(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function E(e){let t=b.current.colors??[];return Array.from({length:e},(e,n)=>t[n]??hY[n%hY.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=_G(mY,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=sH(d.current,iq),n.failed=!n.plot),!n.plot||!d.current)return null;let r=Math.min(2,window.devicePixelRatio||1),i=`${e}x${t}@${r}`;return n.size!==i&&(n.plot.resize(e,t,r),d.current.style.width=`${e}px`,d.current.style.height=`${t}px`,n.size=i),n.plot}function k(){let e=u.current;if(!e)return;let{w:t,h:n}=w(),r=T(e,t,n);if(!r)return;let{bg:i,muted:a,grid:o}=C(),{bars:s,seriesNames:c,mode:d,horizontal:f}=b.current;r.fillStyle=i,r.fillRect(0,0,t,n);let m=O(t,n);if(s.n===0||c.length===0){m?.keep([]),m?.render(),r.fillStyle=a,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,zV(r);return}let{lo:h,hi:g,top:_,left:v,plotW:y,plotH:k,tiny:A}=D(t,n),j=E(c.length),M=f?k:y,N=e=>f?v+(e-h)/(g-h)*y:_+k-(e-h)/(g-h)*k,P=e=>(f?_:v)+(e+.5)/s.n*M;l({left:v,top:_,width:y,height:k,...f?{x:{v0:h,v1:g}}:{y:{v0:h,v1:g}}}),r.strokeStyle=o,r.lineWidth=1;for(let e=0;e<=5;e++){let t=h+e/5*(g-h),n=N(t);r.beginPath(),f?(r.moveTo(n,_),r.lineTo(n,_+k)):(r.moveTo(v,n),r.lineTo(v+y,n)),r.stroke(),r.fillStyle=a,r.font=`9px ${Q.mono}`,!A&&(f?(r.textAlign=`center`,r.textBaseline=`top`,r.fillText(Pz(t,(g-h)/5),n,_+k+4)):(r.textAlign=`right`,r.textBaseline=`middle`,r.fillText(Pz(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},IH(p.current));let I=Math.min(2,window.devicePixelRatio||1),L=Math.max(1,Math.round(M*I)),R=j.map(e=>{let t=UV(e);return[t[0],t[1],t[2],gY]}),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=vY(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=vY(s,d,L);r.globalAlpha=gY;for(let t=0;t<e.x0.length;t++){r.fillStyle=j[e.k[t]];let n=P(e.x0[t]-.5),i=P(e.x1[t]-.5),a=N(e.y0[t]),o=N(e.y1[t]);f?r.fillRect(Math.min(a,o),n,Math.max(1,Math.abs(o-a)),Math.max(1,i-n)):r.fillRect(n,Math.min(a,o),Math.max(1,i-n),Math.max(1,Math.abs(o-a)))}r.globalAlpha=1}if(h<0&&g>0){let e=N(0);r.strokeStyle=a,r.lineWidth=1.5,r.beginPath(),f?(r.moveTo(e,_),r.lineTo(e,_+k)):(r.moveTo(v,e),r.lineTo(v+y,e)),r.stroke()}r.fillStyle=a,r.font=`9px ${Q.mono}`;let B=Math.max(1,Math.ceil(s.n/Math.max(1,Math.floor(M/(f?14:48)))));for(let e=0;e<(A?0:s.n);e+=B){let t=P(e),n=s.label(e),i=n.length>14?n.slice(0,13)+`…`:n;f?(r.textAlign=`right`,r.textBaseline=`middle`,r.fillText(i,v-4,t)):(r.textAlign=`center`,r.textBaseline=`top`,r.fillText(i,t,_+k+4))}if(c.length>1&&!A){let e=f?_-14:_+k+32,t=v;r.font=`9px ${Q.mono}`,r.textBaseline=`top`;for(let n=0;n<c.length&&(r.fillStyle=j[n],r.fillRect(t,e,10,8),r.fillStyle=a,r.textAlign=`left`,r.fillText(c[n],t+13,e),t+=r.measureText(c[n]).width+26,!(t>v+y-30));n++);}}function A(){let e=f.current;if(!e)return;let{w:t,h:n}=w(),r=T(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=h.current,{bars:a,seriesNames:o,horizontal:s}=b.current;if(i===null||i>=a.n)return;let{top:c,left:l,plotW:u,plotH:d}=D(t,n),p=s?d:u,m=(s?c:l)+(i+.5)/a.n*p,g=Math.max(1,p/a.n);r.fillStyle=`rgba(255,255,255,0.08)`,s?r.fillRect(l,m-g/2,u,g):r.fillRect(m-g/2,c,g,d);let _=a.values.map((e,t)=>`${o.length>1?o[t]+` `:``}${Fz(e[i])}`).join(` `),v=`${a.label(i)}: ${_}`;r.font=`11px ${Q.mono}`;let y=r.measureText(v).width,x=s?l+u/2:m,S=s?m:c+d/2,C=Math.max(4,Math.min(t-y-8,x-y/2)),E=S-28<c?S+10:S-24;r.fillStyle=`rgba(0,0,0,0.8)`,r.fillRect(C-3,E-3,y+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(v,C,E)}let j=K(k);j.current=k;let M=K(null);M.current??=VH(()=>j.current(),()=>p.current);let N=()=>{g.current||=NH(()=>{g.current=0,A()})};return W(()=>{M.current.now()},[y,n,r,i,a,o]),W(()=>()=>{M.current?.cancel(),PH(g.current)},[]),W(()=>{m.current=null,M.current.schedule()},[s]),G(()=>{let e=p.current;if(!e)return;let t=new zH(()=>{m.current=null,M.current.schedule(),N()});return t.observe(e),()=>t.disconnect()},[]),G(()=>{let e=f.current;if(!e)return;let t=e=>{e.preventDefault(),_.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),{bars:r,horizontal:i}=b.current,{w:a,h:o}=w(),{top:s,left:c,plotW:l,plotH:u}=D(a,o),d=i?t.clientY-n.top-s:t.clientX-n.left-c,f=i?u:l,p=d>=0&&d<f&&r.n>0?Math.min(r.n-1,Math.floor(d/f*r.n)):null;p!==h.current&&(h.current=p,N())},r=()=>{h.current=null,N()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),vt(`div`,{ref:p,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:u,className:`chart-canvas`,role:`img`,"aria-label":`Bar chart`}),q(`canvas`,{ref:d,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),q(`canvas`,{ref:f,className:`chart-canvas chart-overlay`})]})}var bY=[`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`];function xY(e,t){if(!t)return bY[e%bY.length];if(e===0)return t;let n=bY.filter(e=>e.toLowerCase()!==t.toLowerCase());return n[(e-1)%n.length]}var SY={top:36,right:36,bottom:36,left:36};function CY({axes:e,series:t,fill:n=!0,color:r,backgroundToken:i=``,onPlotContextMenu:a}){let o=K(null),s=K(null),c=K(null),l=K(null),u=K(a);G(()=>{u.current=a},[a]);let d=K({axes:e,series:t,fill:n,color:r});G(()=>{d.current={axes:e,series:t,fill:n,color:r}},[e,t,n,r]);function f(){if(l.current)return l.current;let e=c.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return l.current=n,n}function p(){let e=c.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||300)}}function m(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function h(){let e=o.current;if(!e)return;let{w:t,h:n}=p(),r=m(e,t,n);if(!r)return;let{bg:i,muted:a,grid:s}=f(),{axes:c,series:l,fill:u}=d.current;if(r.fillStyle=i,r.fillRect(0,0,t,n),c.length<3||l.length===0){r.fillStyle=a,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`Select ≥ 3 axes`,SY.left+8,SY.top+8);return}let h=c.length,g=t/2,_=n/2,v=Math.min(t-SY.left-SY.right,n-SY.top-SY.bottom)/2,y=c.map((e,t)=>{let n=0;for(let e of l){let r=e.values[t]??0;r>n&&(n=r)}return n||1});function b(e){return Math.PI*2*e/h-Math.PI/2}function x(e,t){let n=b(e);return{x:g+Math.cos(n)*v*t,y:_+Math.sin(n)*v*t}}for(let e=1;e<=4;e++){let t=e/4;r.beginPath();for(let e=0;e<h;e++){let n=x(e,t);e===0?r.moveTo(n.x,n.y):r.lineTo(n.x,n.y)}r.closePath(),r.strokeStyle=s,r.lineWidth=1,r.stroke()}r.strokeStyle=a,r.lineWidth=1;for(let e=0;e<h;e++){let t=x(e,1);r.beginPath(),r.moveTo(g,_),r.lineTo(t.x,t.y),r.stroke(),r.fillStyle=a,r.font=`10px ${Q.mono}`;let n=b(e),i=x(e,1+10/v);r.textAlign=Math.abs(Math.cos(n))<.1?`center`:Math.cos(n)<0?`right`:`left`,r.textBaseline=Math.abs(Math.sin(n))<.1?`middle`:Math.sin(n)<0?`bottom`:`top`;let o=c[e].length>12?c[e].slice(0,11)+`…`:c[e];r.fillText(o,i.x,i.y)}for(let e=0;e<l.length;e++){let t=l[e],n=xY(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=SY.left,i=n-SY.bottom-10;r.font=`9px ${Q.mono}`,r.textBaseline=`top`;for(let n=0;n<l.length&&(r.fillStyle=xY(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-SY.right-30));n++);}}let g=K(h);g.current=h;let _=K(null);_.current??=VH(()=>g.current(),()=>c.current);let v=()=>_.current.schedule();return W(()=>{_.current.now()}),W(()=>()=>_.current?.cancel(),[]),W(()=>{l.current=null,v()},[i]),G(()=>{let e=c.current;if(!e)return;let t=new zH(()=>{l.current=null,v()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=s.current;if(!e)return;let t=e=>{e.preventDefault(),u.current?.({clientX:e.clientX,clientY:e.clientY})};return e.addEventListener(`contextmenu`,t),()=>{e.removeEventListener(`contextmenu`,t)}},[]),vt(`div`,{ref:c,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`Radar chart`}),q(`canvas`,{ref:s,className:`chart-canvas chart-overlay`})]})}var wY={top:16,right:16,bottom:40,left:52},TY=[`#38bdf8`,`#4ade80`,`#fb7185`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`];function EY(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=>pq(e)),xLo:c,xHi:l,yLo:u,yHi:d}}function DY({series:e,stacked:t=!1,yRange:n,backgroundToken:r=``,onPlotContextMenu:i}){let a=SU(),o=K(null),s=K(null),c=K(null),l=K(null),u=K(null),d=K(null),f=K(0),p=K(i);G(()=>{p.current=i},[i]);let m=K(null),h=ft(()=>{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=EY(e,t);return m.current={series:e,stacked:t,value:r},r},[e,t]),g=K({series:e,prepared:h,yRange:n});G(()=>{g.current={series:e,prepared:h,yRange:n}},[e,h,n]);let _=K({plot:null,failed:!1,key:``,size:``});W(()=>()=>{_.current.plot?.dispose(),_.current.plot=null},[]);let v=K({prepared:null,view:``});function y(){if(u.current)return u.current;let e=l.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return u.current=n,n}function b(){let e=l.current;return{w:Math.max(1,e?.clientWidth||600),h:Math.max(1,e?.clientHeight||300)}}function x(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function S(e,t){let n=(e.xHi-e.xLo)*.01||.5,r=e.yLo,i=e.yHi;return i===r&&(i=r+1),i+=(i-r)*.05,t?.min!==void 0&&Number.isFinite(t.min)&&(r=t.min),t?.max!==void 0&&Number.isFinite(t.max)&&(i=t.max),{xLo:e.xLo-n,xHi:e.xHi+n,yLo:r,yHi:i}}function C(e,t,n,r,i){let a=e.x[t],o=e.hi[t],s=e.lo[t];if(!e.ascending[t]||a.length<=2*i)return{x:a,hi:o,lo:s??new Float64Array(a.length)};let c=uq(a,o,n,r,i);return{x:fq(a,c),hi:fq(o,c),lo:s?fq(s,c):new Float64Array(c.length)}}function w(){let e=o.current;if(!e)return;let{w:n,h:r}=b(),i=x(e,n,r);if(!i)return;let{bg:s,muted:c,grid:u}=y(),{series:d,prepared:f,yRange:p}=g.current;i.fillStyle=s,i.fillRect(0,0,n,r);let m=_.current.plot;if(d.length===0){m?.keep([]),m?.render(),i.fillStyle=c,i.font=`13px ${Q.sans}`,i.textAlign=`left`,i.textBaseline=`top`,zV(i);return}let h=_G(wY,n,r),{top:w,right:D,bottom:O,left:k}=h,A=n-k-D,j=r-w-O,{xLo:M,xHi:N,yLo:P,yHi:F}=S(f,p),I=e=>k+(e-M)/(N-M)*A,L=e=>w+j-(e-P)/(F-P)*j;a({left:k,top:w,width:A,height:j,x:{v0:M,v1:N},y:{v0:P,v1:F}}),i.strokeStyle=u,i.lineWidth=1;for(let e=0;e<=5;e++){let t=P+e/5*(F-P),n=L(t);i.beginPath(),i.moveTo(k,n),i.lineTo(k+A,n),i.stroke(),i.fillStyle=c,i.font=`9px ${Q.mono}`,i.textAlign=`right`,i.textBaseline=`middle`,h.tiny||i.fillText(Pz(t,(F-P)/5),k-4,n)}let R=Math.min(8,f.x[0]?.length??5);for(let e=0;e<=R;e++){let t=M+e/R*(N-M),n=I(t);i.beginPath(),i.moveTo(n,w),i.lineTo(n,w+j),i.stroke(),i.fillStyle=c,i.font=`9px ${Q.mono}`,i.textAlign=`center`,i.textBaseline=`top`,h.tiny||i.fillText(Pz(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},IH(l.current));let B=E(n,r),V=Math.min(2,window.devicePixelRatio||1),ee=Math.max(1,Math.round(A*V)),te=d.map((e,t)=>UV(TY[t%TY.length]));if(B){let e=`${M}|${N}|${ee}`;if(_.current.key!==e||T.current!==f){let n=[];for(let e=0;e<d.length;e++){let r=C(f,e,M,N,ee),i=te[e],a=[i[0],i[1],i[2],f.lo[e]||t?.7:.25];B.setBands(`b${e}`,r.x,r.lo,r.hi,a),B.setLine(`l${e}`,r.x,r.hi,i,1),n.push(`b${e}`,`l${e}`)}B.keep(n),_.current.key=e,T.current=f}B.setView(M,N,P,F,{left:k,top:w,width:A,height:j}),B.render()}else for(let e=0;e<d.length;e++){let n=C(f,e,M,N,ee),r=TY[e%TY.length];i.save(),i.beginPath(),i.rect(k,w,A,j),i.clip(),i.beginPath();for(let e=0;e<n.x.length;e++){let t=I(n.x[e]);e===0?i.moveTo(t,L(n.lo[e])):i.lineTo(t,L(n.lo[e]))}for(let e=n.x.length-1;e>=0;e--)i.lineTo(I(n.x[e]),L(n.hi[e]));i.closePath(),i.fillStyle=r,i.globalAlpha=f.lo[e]||t?.7:.25,i.fill(),i.beginPath();for(let e=0;e<n.x.length;e++){let t=I(n.x[e]),r=L(n.hi[e]);e===0?i.moveTo(t,r):i.lineTo(t,r)}i.globalAlpha=1,i.strokeStyle=r,i.lineWidth=1,i.stroke(),i.restore()}if(d.length>1&&!h.tiny){let e=k,t=w+j+24;i.font=`9px ${Q.mono}`,i.textBaseline=`top`;for(let n=0;n<d.length&&(i.fillStyle=TY[n%TY.length],i.fillRect(e,t,10,8),i.fillStyle=c,i.textAlign=`left`,i.fillText(d[n].name,e+13,t),e+=i.measureText(d[n].name).width+26,!(e>k+A-30));n++);}}let T=K(null);function E(e,t){let n=_.current;if(!n.plot&&!n.failed&&s.current&&(n.plot=sH(s.current,iq),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}=_G(wY,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=${Fz(m+(i-u)/_*(h-m))}`;r.font=`11px ${Q.mono}`;let y=r.measureText(v).width,C=Math.max(4,Math.min(t-y-8,i-y/2));r.fillStyle=`rgba(0,0,0,0.7)`,r.fillRect(C-3,s-3,y+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(v,C,s)}let O=K(w);O.current=w;let k=K(null);k.current??=VH(()=>O.current(),()=>l.current);let A=()=>{f.current||=NH(()=>{f.current=0,D()})};return W(()=>{k.current.now()},[e,h,n]),W(()=>()=>{k.current?.cancel(),PH(f.current)},[]),W(()=>{u.current=null,k.current.schedule()},[r]),G(()=>{let e=l.current;if(!e)return;let t=new zH(()=>{u.current=null,k.current.schedule(),A()});return t.observe(e),()=>t.disconnect()},[]),G(()=>{let e=c.current;if(!e)return;let t=e=>{e.preventDefault(),p.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect();d.current=t.clientX-n.left,A()},r=()=>{d.current=null,A()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),vt(`div`,{ref:l,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`Area chart`}),q(`canvas`,{ref:s,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),q(`canvas`,{ref:c,className:`chart-canvas chart-overlay`})]})}var OY={top:16,right:16,bottom:40,left:52},kY=[`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`];function AY({series:e,complement:t=!1,logX:n=!1,backgroundToken:r=``,onPlotContextMenu:i}){let a=SU(),o=K(null),s=K(null),c=K(null),l=K(null),u=K(null),d=K(0),f=K(i);G(()=>{f.current=i},[i]);let p=K({series:e,complement:t,logX:n});G(()=>{p.current={series:e,complement:t,logX:n}},[e,t,n]);let m=ft(()=>{let t=e.map(e=>Float64Array.from(e.values).sort()),n=1/0,r=-1/0;for(let e of t)e.length&&(n=Math.min(n,e[0]),r=Math.max(r,e[e.length-1]));return{all:t,xLo:n,xHi:r}},[e]),h=K(m);G(()=>{h.current=m},[m]);function g(){if(l.current)return l.current;let e=c.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return l.current=n,n}function _(){let e=c.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||300)}}function v(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function y(){let e=o.current;if(!e)return;let{w:t,h:n}=_(),r=v(e,t,n);if(!r)return;let{bg:i,muted:s,grid:c}=g(),{series:l,complement:u,logX:d}=p.current;if(r.fillStyle=i,r.fillRect(0,0,t,n),l.length===0){r.fillStyle=s,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,zV(r);return}let{top:f,right:m,bottom:y,left:b}=OY,x=t-b-m,S=n-f-y,{xLo:C,xHi:w}=h.current;Number.isFinite(C)||(C=0,w=1);let T=e=>Math.log10(Math.max(1e-10,e)),E=d?T(C):C,D=d?T(w):w,O=e=>b+((d?T(e):e)-E)/(D-E||1)*x,k=e=>f+S-e*S;a({left:b,top:f,width:x,height:S,x:{v0:C,v1:w,log:d}});for(let e=0;e<=5;e++){let t=e/5,n=k(t);r.strokeStyle=c,r.lineWidth=1,r.beginPath(),r.moveTo(b,n),r.lineTo(b+x,n),r.stroke(),r.fillStyle=s,r.font=`9px ${Q.mono}`,r.textAlign=`right`,r.textBaseline=`middle`,r.fillText(String(t.toFixed(2)),b-4,n)}for(let e=0;e<=6;e++){let t=C+e/6*(w-C),n=O(t);r.strokeStyle=c,r.lineWidth=1,r.beginPath(),r.moveTo(n,f),r.lineTo(n,f+S),r.stroke(),r.fillStyle=s,r.font=`9px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`top`,r.fillText(Pz(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=kY[e%kY.length],r.lineWidth=1,r.stroke()}if(l.length>1){let e=b,t=f+S+24;r.font=`9px ${Q.mono}`,r.textBaseline=`top`;for(let n=0;n<l.length&&(r.fillStyle=kY[n%kY.length],r.fillRect(e,t,16,2),r.fillStyle=s,r.textAlign=`left`,r.fillText(l[n].name,e+20,t-3),e+=r.measureText(l[n].name).width+30,!(e>b+x-30));n++);}r.save(),r.translate(12,f+S/2),r.rotate(-Math.PI/2),r.fillStyle=s,r.font=`9px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`middle`,r.fillText(u?`CCDF`:`CDF`,0,0),r.restore()}function b(){let e=s.current;if(!e)return;let{w:t,h:n}=_(),r=v(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=u.current;if(i===null)return;let{top:a,left:o,right:c}=OY,l=n-a-OY.bottom,d=t-o-c;r.strokeStyle=`rgba(255,255,255,0.4)`,r.lineWidth=1,r.setLineDash([4,4]),r.beginPath(),r.moveTo(i,a),r.lineTo(i,a+l),r.stroke(),r.setLineDash([]);let{xLo:f,xHi:p}=h.current;if(!Number.isFinite(f))return;let m=Fz(f+(i-o)/d*(p-f));r.font=`11px ${Q.mono}`;let g=r.measureText(m).width,y=Math.max(4,Math.min(t-g-8,i-g/2));r.fillStyle=`rgba(0,0,0,0.7)`,r.fillRect(y-3,a+l+2,g+6,16),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(m,y,a+l+4)}let x=K(y);x.current=y;let S=K(null);S.current??=VH(()=>x.current(),()=>c.current);let C=()=>S.current.schedule(),w=()=>{PH(d.current),d.current=NH(b)};return W(()=>{S.current.now()}),W(()=>()=>S.current?.cancel(),[]),W(()=>{l.current=null,C()},[r]),G(()=>{let e=c.current;if(!e)return;let t=new zH(()=>{l.current=null,C(),w()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=s.current;if(!e)return;let t=e=>{e.preventDefault(),f.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect();u.current=t.clientX-n.left,w()},r=()=>{u.current=null,w()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),vt(`div`,{ref:c,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`CDF chart`}),q(`canvas`,{ref:s,className:`chart-canvas chart-overlay`})]})}var jY={top:16,right:40,bottom:40,left:52},MY=[`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`,`#facc15`,`#60a5fa`];function NY(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 PY(e){let[t,n,r]=NY(e);return`rgb(${t},${n},${r})`}var FY=(()=>{let e=new Uint8Array(1024);for(let t=0;t<256;t++)e.set([...NY(t/255),255],t*4);return e})(),IY=()=>{let e=new Uint8Array(1024);for(let t=0;t<256;t++){let[n,r,i]=vK(MY[t%MY.length],1);e.set([n*255,r*255,i*255,255],t*4)}return e};function LY(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 RY({points:e,color:t=`#64748b`,colorByNumeric:n=!1,maxRadius:r=24,backgroundToken:i=``,onPlotContextMenu:a}){let o=SU(),s=K(null),c=K(null),l=K(null),u=K(null),d=K(null),f=K(null),p=K(0),m=K(a);G(()=>{m.current=a},[a]);let h=ft(()=>LY(e,n,r),[e,n,r]),g=K({points:e,color:t,colorByNumeric:n,maxRadius:r,model:h});G(()=>{g.current={points:e,color:t,colorByNumeric:n,maxRadius:r,model:h}},[e,t,n,r,h]);let _=K({r:null,failed:!1,size:``,model:null,style:``});W(()=>()=>{_.current.r?.dispose(),_.current.r=null},[]);function v(){if(d.current)return d.current;let e=u.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return d.current=n,n}function y(){let e=u.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||300)}}function b(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function x(e,t){let{xLo:n,xHi:r,yLo:i,yHi:a}=g.current.model.ext,{top:s,right:c,bottom:l,left:u}=jY,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=sH(c.current,hG),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,IH(u.current));let l=`${o.mode}|${s}`;return n.style!==l&&(r.setStyle(o.mode===`single`?{kind:`single`,rgba:vK(s,1)}:{kind:o.mode,palette:o.mode===`colormap`?FY:IY()},3,.65),r.setDraw(!0,!1,0),n.style=l),r}function C(){let e=s.current;if(!e)return;let{w:t,h:n}=y(),r=b(e,t,n);if(!r)return;let{bg:i,muted:a,grid:o}=v(),{points:c,color:l,colorByNumeric:u,model:d}=g.current;r.fillStyle=i,r.fillRect(0,0,t,n);let f=S(t,n);if(c.length===0){f?.setData([],[]),_.current.model=null,f?.render(),r.fillStyle=a,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,zV(r);return}let{xLo:p,xHi:m,yLo:h,yHi:C}=d.ext,{top:w,left:T}=jY,{plotW:E,plotH:D,xToPx:O,yToPx:k}=x(t,n);r.strokeStyle=o,r.lineWidth=1;for(let e=0;e<=5;e++){let t=p+e/5*(m-p),n=O(t);r.beginPath(),r.moveTo(n,w),r.lineTo(n,w+D),r.stroke(),r.fillStyle=a,r.font=`9px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`top`,r.fillText(Pz(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(Pz(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`?PY(n):d.mode===`dataset`?MY[n%MY.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-jY.bottom-10;r.font=`9px ${Q.mono}`,r.textBaseline=`top`;for(let n=0;n<A.length;n++){let i=A[n];if(r.fillStyle=MY[n%MY.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(`(${Fz(a.x[i])}, ${Fz(a.y[i])})`),m.push(`size=${Fz(a.size[i])}`);let _=a.colorIndex?.[i];_!==void 0&&_>=0&&a.colorLabels?m.push(a.colorLabels[_]):a.colorValue&&m.push(Fz(a.colorValue[i]));let v=m.join(` · `);r.font=`11px ${Q.mono}`;let S=r.measureText(v).width,C=Math.max(4,Math.min(t-S-8,d+u+4)),w=p-20<jY.top?p+u+4:p-20;r.fillStyle=`rgba(0,0,0,0.8)`,r.fillRect(C-3,w-3,S+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(v,C,w)}let T=K(C);T.current=C;let E=K(null);E.current??=VH(()=>T.current(),()=>u.current);let D=()=>E.current.schedule(),O=()=>{PH(p.current),p.current=NH(w)};return W(()=>{E.current.now()}),W(()=>()=>E.current?.cancel(),[]),W(()=>{d.current=null,D()},[i]),G(()=>{let e=u.current;if(!e)return;let t=new zH(()=>{d.current=null,D(),O()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=l.current;if(!e)return;let t=null,n=e=>{e.preventDefault(),m.current?.({clientX:e.clientX,clientY:e.clientY})},r=n=>{let r=e.getBoundingClientRect(),{points:i,maxRadius:a,model:o}=g.current,{w:s,h:c}=y(),{plotW:l,plotH:u,xToPx:d,yToPx:p}=x(s,c),m=e=>d(i.x[e])-jY.left,h=e=>p(i.y[e])-jY.top,_=a+6,v=`${s}|${c}|${_}`;(!t||t.model!==o||t.key!==v)&&(t={model:o,key:v,g:XJ(i.length,l,u,_,m,h)}),f.current=ZJ(t.g,n.clientX-r.left-jY.left,n.clientY-r.top-jY.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)}},[]),vt(`div`,{ref:u,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:s,className:`chart-canvas`,role:`img`,"aria-label":`Bubble chart`}),q(`canvas`,{ref:c,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),q(`canvas`,{ref:l,className:`chart-canvas chart-overlay`})]})}var zY={top:8,right:8,bottom:8,left:8},BY=[`#f97316`,`#38bdf8`,`#4ade80`,`#a78bfa`,`#fbbf24`,`#fb7185`,`#34d399`,`#e879f9`,`#facc15`,`#60a5fa`];function VY(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 HY(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?u:d),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?u:d),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=HY(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 UY({nodes:e,backgroundToken:t=``,onPlotContextMenu:n}){let r=K(null),i=K(null),a=K(null),o=K(null),s=K([]),c=K(null),l=K(0),u=K(n);G(()=>{u.current=n},[n]);let d=K({nodes:e});G(()=>{d.current={nodes:e}},[e]);let f=ft(()=>VY(e),[e]),p=K(f);G(()=>{p.current=f},[f]);function m(){if(o.current)return o.current;let e=a.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return o.current=n,n}function h(){let e=a.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||300)}}function g(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function _(){let e=r.current;if(!e)return;let{w:t,h:n}=h(),i=g(e,t,n);if(!i)return;let{bg:a,muted:o}=m(),{nodes:l}=d.current;if(i.fillStyle=a,i.fillRect(0,0,t,n),l.length===0){i.fillStyle=o,i.font=`13px ${Q.sans}`,i.textAlign=`left`,i.textBaseline=`top`,zV(i);return}let u=p.current,f=t-zY.left-zY.right,_=n-zY.top-zY.bottom,v=HY(u,zY.left,zY.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=BY[l%BY.length],d=c.current===e;if(i.fillStyle=u,i.globalAlpha=d?.95:.75,i.fillRect(n,r,o,s),i.globalAlpha=1,i.strokeStyle=a,i.lineWidth=1,i.strokeRect(n,r,o,s),o>20&&s>14){i.fillStyle=`rgba(0,0,0,0.75)`,i.font=`${Math.min(11,s-4)}px ${Q.mono}`,i.textAlign=`left`,i.textBaseline=`top`;let e=Math.floor((o-4)/6),a=t.name.length>e?t.name.slice(0,e-1)+`…`:t.name;i.fillText(a,n+3,r+3)}}i.globalAlpha=1}function v(){let e=i.current;if(!e)return;let{w:t,h:n}=h(),r=g(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let a=c.current;if(a===null)return;let o=s.current;if(a<0||a>=o.length)return;let{node:l,x:u,y:d,w:f,h:p}=o[a];r.strokeStyle=`rgba(255,255,255,0.9)`,r.lineWidth=2,r.strokeRect(u+1,d+1,f-2,p-2);let m=`${l.name}: ${l.value.toLocaleString()}`;r.font=`11px ${Q.mono}`;let _=r.measureText(m).width,v=Math.max(4,Math.min(t-_-8,u+f/2-_/2)),y=d<30?d+p+4:d-20;r.fillStyle=`rgba(0,0,0,0.8)`,r.fillRect(v-3,y-3,_+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(m,v,y)}let y=K(_);y.current=_;let b=K(null);b.current??=VH(()=>y.current(),()=>a.current);let x=()=>b.current.schedule(),S=()=>{PH(l.current),l.current=NH(v)};return W(()=>{b.current.now()}),W(()=>()=>b.current?.cancel(),[]),W(()=>{o.current=null,x()},[t]),G(()=>{let e=a.current;if(!e)return;let t=new zH(()=>{o.current=null,x(),S()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=i.current;if(!e)return;let t=e=>{e.preventDefault(),u.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),r=t.clientX-n.left,i=t.clientY-n.top,a=s.current,o=null;for(let e=0;e<a.length;e++){let t=a[e];r>=t.x&&r<=t.x+t.w&&i>=t.y&&i<=t.y+t.h&&(o=e)}c.current=o,S()},r=()=>{c.current=null,S()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),vt(`div`,{ref:a,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:r,className:`chart-canvas`,role:`img`,"aria-label":`Treemap`}),q(`canvas`,{ref:i,className:`chart-canvas chart-overlay`})]})}var WY={top:8,right:8,bottom:8,left:8},GY=14,KY=8,qY=[`#38bdf8`,`#4ade80`,`#fb7185`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`,`#facc15`,`#60a5fa`];function JY(e,t,n,r){if(e.length===0||t.length===0)return{nodes:[],links:[]};let i=n-WY.left-WY.right,a=r-WY.top-WY.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=>WY.left+e/Math.max(1,c)*(i-GY),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)*KY,i=0;for(let e of n)i+=Math.max(8,(d.get(e)??0)/f*r*.8);let o=WY.top+(a-i-(n.length-1)*KY)/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:qY[e.indexOf(a)%qY.length]}),o+=s+KY}}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+GY,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 YY({nodeNames:e,links:t,backgroundToken:n=``,onPlotContextMenu:r}){let i=K(null),a=K(null),o=K(null),s=K(null),c=K({nodes:[],links:[]}),l=K(null),u=K(0),d=K(r);G(()=>{d.current=r},[r]);let f=K({nodeNames:e,links:t});G(()=>{f.current={nodeNames:e,links:t}},[e,t]);function p(){if(s.current)return s.current;let e=o.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return s.current=n,n}function m(){let e=o.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||300)}}function h(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function g(){let e=i.current;if(!e)return;let{w:t,h:n}=m(),r=h(e,t,n);if(!r)return;let{bg:a,muted:o}=p(),{nodeNames:s,links:u}=f.current;if(r.fillStyle=a,r.fillRect(0,0,t,n),s.length===0||u.length===0){r.fillStyle=o,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,zV(r);return}let d=JY(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,GY,e.h),r.globalAlpha=1,r.fillStyle=o,r.font=`9px ${Q.mono}`,r.textBaseline=`middle`,e.x>t/2?(r.textAlign=`right`,r.fillText(e.name,e.x-3,e.y+e.h/2)):(r.textAlign=`left`,r.fillText(e.name,e.x+GY+3,e.y+e.h/2));r.globalAlpha=1}function _(){let e=a.current;if(!e)return;let{w:t,h:n}=m(),r=h(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=l.current;if(i===null)return;let o=c.current;if(i<0||i>=o.links.length)return;let s=o.links[i],u=s.label;r.font=`11px ${Q.mono}`;let d=r.measureText(u).width,f=Math.max(4,Math.min(t-d-8,(s.sx+s.tx)/2-d/2)),p=Math.max(4,(s.sy+s.ty)/2-10);r.fillStyle=`rgba(0,0,0,0.8)`,r.fillRect(f-3,p-3,d+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(u,f,p)}let v=K(g);v.current=g;let y=K(null);y.current??=VH(()=>v.current(),()=>o.current);let b=()=>y.current.schedule(),x=()=>{PH(u.current),u.current=NH(_)};return W(()=>{y.current.now()}),W(()=>()=>y.current?.cancel(),[]),W(()=>{s.current=null,b()},[n]),G(()=>{let e=o.current;if(!e)return;let t=new zH(()=>{s.current=null,b(),x()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=a.current;if(!e)return;let t=e=>{e.preventDefault(),d.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),r=t.clientX-n.left,i=t.clientY-n.top,a=c.current,o=null;for(let e=0;e<a.links.length;e++){let t=a.links[e];if(r>=t.sx&&r<=t.tx&&Math.abs(i-(t.sy+t.ty)/2)<t.h/2+6){o=e;break}}l.current=o,x()},r=()=>{l.current=null,x()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),vt(`div`,{ref:o,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:i,className:`chart-canvas`,role:`img`,"aria-label":`Sankey diagram`}),q(`canvas`,{ref:a,className:`chart-canvas chart-overlay`})]})}var XY={top:24,right:24,bottom:52,left:52};function ZY({bins:e,color:t=`#38bdf8`,backgroundToken:n=``,onPlotContextMenu:r}){let i=K(null),a=K(null),o=K(null),s=K(null),c=K(null),l=K(0),u=K(r);G(()=>{u.current=r},[r]);let d=K({bins:e,color:t});G(()=>{d.current={bins:e,color:t}},[e,t]);function f(){if(s.current)return s.current;let e=o.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return s.current=n,n}function p(){let e=o.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||300)}}function m(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function h(){let e=i.current;if(!e)return;let{w:t,h:n}=p(),r=m(e,t,n);if(!r)return;let{bg:a,muted:o,grid:s}=f(),{bins:l,color:u}=d.current;if(r.fillStyle=a,r.fillRect(0,0,t,n),l.length===0){r.fillStyle=o,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,zV(r);return}let{top:h,right:g,bottom:_,left:v}=XY,y=t-v-g,b=n-h-_,x=e=>v+e*y,S=e=>h+(1-e)*b;for(let e=0;e<=5;e++){let t=e/5;r.strokeStyle=s,r.lineWidth=1,r.beginPath(),r.moveTo(v,S(t)),r.lineTo(v+y,S(t)),r.stroke(),r.beginPath(),r.moveTo(x(t),h),r.lineTo(x(t),h+b),r.stroke(),r.fillStyle=o,r.font=`9px ${Q.mono}`,r.textAlign=`right`,r.textBaseline=`middle`,r.fillText(t.toFixed(2),v-4,S(t)),r.textAlign=`center`,r.textBaseline=`top`,r.fillText(t.toFixed(2),x(t),h+b+4)}r.strokeStyle=o,r.lineWidth=1.5,r.setLineDash([6,4]),r.beginPath(),r.moveTo(x(0),S(0)),r.lineTo(x(1),S(1)),r.stroke(),r.setLineDash([]);let C=Math.max(1,...l.map(e=>e.count)),w=b*.15;for(let e of l){let t=Math.max(1,y/l.length*.7),n=x(e.center)-t/2,i=e.count/C*w;r.fillStyle=u,r.globalAlpha=.3,r.fillRect(n,h+b-i,t,i)}r.globalAlpha=1,r.beginPath();for(let e=0;e<l.length;e++){let t=x(l[e].center),n=S(l[e].actual);e===0?r.moveTo(t,n):r.lineTo(t,n)}r.strokeStyle=u,r.lineWidth=1,r.stroke();for(let e=0;e<l.length;e++){let t=c.current===e;r.beginPath(),r.arc(x(l[e].center),S(l[e].actual),t?6:4,0,Math.PI*2),r.fillStyle=u,r.globalAlpha=t?1:.85,r.fill()}r.globalAlpha=1,r.fillStyle=o,r.font=`10px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`bottom`,r.fillText(`Predicted probability`,v+y/2,n-4),r.save(),r.translate(12,h+b/2),r.rotate(-Math.PI/2),r.textAlign=`center`,r.textBaseline=`middle`,r.fillText(`Actual rate`,0,0),r.restore()}function g(){let e=a.current;if(!e)return;let{w:t,h:n}=p(),r=m(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=c.current;if(i===null)return;let{bins:o}=d.current;if(i<0||i>=o.length)return;let s=o[i],{top:l,left:u}=XY,f=t-u-XY.right,h=n-l-XY.bottom,g=u+s.center*f,_=l+(1-s.actual)*h,v=`pred=${s.center.toFixed(2)} actual=${s.actual.toFixed(3)} n=${s.count}`;r.font=`11px ${Q.mono}`;let y=r.measureText(v).width,b=Math.max(4,Math.min(t-y-8,g-y/2)),x=_-28<l?_+12:_-24;r.fillStyle=`rgba(0,0,0,0.8)`,r.fillRect(b-3,x-3,y+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(v,b,x)}let _=K(h);_.current=h;let v=K(null);v.current??=VH(()=>_.current(),()=>o.current);let y=()=>v.current.schedule(),b=()=>{PH(l.current),l.current=NH(g)};return W(()=>{v.current.now()}),W(()=>()=>v.current?.cancel(),[]),W(()=>{s.current=null,y()},[n]),G(()=>{let e=o.current;if(!e)return;let t=new zH(()=>{s.current=null,y(),b()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=a.current;if(!e)return;let t=e=>{e.preventDefault(),u.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),{bins:r}=d.current,{w:i}=p(),a=t.clientX-n.left,o=i-XY.left-XY.right,s=-1,l=20;for(let e=0;e<r.length;e++){let t=XY.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)}},[]),vt(`div`,{ref:o,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:i,className:`chart-canvas`,role:`img`,"aria-label":`Calibration curve`}),q(`canvas`,{ref:a,className:`chart-canvas chart-overlay`})]})}var QY={top:24,right:24,bottom:48,left:52};function $Y({points:e,color:t=`#a78bfa`,backgroundToken:n=``,onPlotContextMenu:r}){let i=SU(),a=K(null),o=K(null),s=K(null),c=K(null),l=K(null),u=K(0),d=K(r);G(()=>{d.current=r},[r]);let f=K({points:e,color:t});G(()=>{f.current={points:e,color:t}},[e,t]);function p(){if(c.current)return c.current;let e=s.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return c.current=n,n}function m(){let e=s.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||300)}}function h(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function g(){let{points:e}=f.current,t=1/0,n=-1/0,r=1/0,i=-1/0;if(e.length>0&&(t=e.theoretical[0],n=e.theoretical[e.length-1],r=e.sample[0],i=e.sample[e.length-1]),!Number.isFinite(t))return{xLo:-3,xHi:3,yLo:-3,yHi:3};let a=(n-t)*.05||.5,o=(i-r)*.05||.5;return{xLo:t-a,xHi:n+a,yLo:r-o,yHi:i+o}}function _(){let e=a.current;if(!e)return;let{w:t,h:n}=m(),r=h(e,t,n);if(!r)return;let{bg:o,muted:s,grid:c}=p(),{points:u,color:d}=f.current;if(r.fillStyle=o,r.fillRect(0,0,t,n),u.length===0){r.fillStyle=s,r.font=`13px ${Q.sans}`,r.textAlign=`left`,r.textBaseline=`top`,zV(r);return}let{xLo:_,xHi:v,yLo:y,yHi:b}=g(),{top:x,right:S,bottom:C,left:w}=QY,T=t-w-S,E=n-x-C,D=e=>w+(e-_)/(v-_)*T,O=e=>x+(1-(e-y)/(b-y))*E;i({left:w,top:x,width:T,height:E,x:{v0:_,v1:v}}),r.strokeStyle=c,r.lineWidth=1;for(let e=0;e<=5;e++){let t=_+e/5*(v-_),n=D(t);r.beginPath(),r.moveTo(n,x),r.lineTo(n,x+E),r.stroke(),r.fillStyle=s,r.font=`9px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`top`,r.fillText(Pz(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(Pz(i,(b-y)/5),w-4,a)}let k=Math.max(_,y),A=Math.min(v,b);k<A&&(r.strokeStyle=s,r.lineWidth=1.5,r.setLineDash([6,4]),r.beginPath(),r.moveTo(D(k),O(k)),r.lineTo(D(A),O(A)),r.stroke(),r.setLineDash([])),r.fillStyle=d,r.globalAlpha=.75;let j=NaN,M=NaN;for(let e=0;e<u.length;e++){let t=Math.round(D(u.theoretical[e])),n=Math.round(O(u.sample[e]));t===j&&n===M||(j=t,M=n,r.beginPath(),r.arc(t,n,3,0,Math.PI*2),r.fill())}let N=l.current;N!==null&&N<u.length&&(r.globalAlpha=1,r.beginPath(),r.arc(D(u.theoretical[N]),O(u.sample[N]),5,0,Math.PI*2),r.fill()),r.globalAlpha=1,r.fillStyle=s,r.font=`10px ${Q.mono}`,r.textAlign=`center`,r.textBaseline=`bottom`,r.fillText(`Theoretical quantiles`,w+T/2,n-4),r.save(),r.translate(12,x+E/2),r.rotate(-Math.PI/2),r.textAlign=`center`,r.textBaseline=`middle`,r.fillText(`Sample quantiles`,0,0),r.restore()}function v(){let e=o.current;if(!e)return;let{w:t,h:n}=m(),r=h(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=l.current;if(i===null)return;let{points:a}=f.current;if(i<0||i>=a.length)return;let s={theoretical:a.theoretical[i],sample:a.sample[i]},{xLo:c,xHi:u,yLo:d,yHi:p}=g(),{top:_,left:v}=QY,y=t-v-QY.right,b=n-_-QY.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=`(${Fz(s.theoretical)}, ${Fz(s.sample)})`;r.font=`11px ${Q.mono}`;let w=r.measureText(C).width,T=Math.max(4,Math.min(t-w-8,x+10)),E=S-20<_?S+10:S-20;r.fillStyle=`rgba(0,0,0,0.8)`,r.fillRect(T-3,E-3,w+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(C,T,E)}let y=K(_);y.current=_;let b=K(null);b.current??=VH(()=>y.current(),()=>s.current);let x=()=>b.current.schedule(),S=()=>{PH(u.current),u.current=NH(v)};return W(()=>{b.current.now()}),W(()=>()=>b.current?.cancel(),[]),W(()=>{c.current=null,x()},[n]),G(()=>{let e=s.current;if(!e)return;let t=new zH(()=>{c.current=null,x(),S()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=o.current;if(!e)return;let t=e=>{e.preventDefault(),d.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),{points:r}=f.current,{w:i}=m(),{xLo:a,xHi:o,yLo:s,yHi:c}=g(),{top:u,left:d}=QY,p=i-d-QY.right,h=n.height-u-QY.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)}},[]),vt(`div`,{ref:s,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:a,className:`chart-canvas`,role:`img`,"aria-label":`Q-Q plot`}),q(`canvas`,{ref:o,className:`chart-canvas chart-overlay`})]})}var eX={top:8,right:16,bottom:40,left:120},tX=22,nX=3,rX=[`#38bdf8`,`#4ade80`,`#fb7185`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`,`#facc15`,`#60a5fa`];function iX({tasks:e,backgroundToken:t=``,onPlotContextMenu:n}){let r=SU(),i=K(null),a=K(null),o=K(null),s=K(null),c=K(null),l=K(0),u=K(n);G(()=>{u.current=n},[n]);let d=K({tasks:e});G(()=>{d.current={tasks:e}},[e]);function f(){if(s.current)return s.current;let e=o.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return s.current=n,n}function p(){let e=o.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||300)}}function m(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function h(){let e=i.current;if(!e)return;let{w:t,h:n}=p(),a=m(e,t,n);if(!a)return;let{bg:o,muted:s,grid:l}=f(),{tasks:u}=d.current;if(a.fillStyle=o,a.fillRect(0,0,t,n),u.length===0){a.fillStyle=s,a.font=`13px ${Q.sans}`,a.textAlign=`left`,a.textBaseline=`top`,zV(a);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}=eX,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*(tX+nX)+v;a.beginPath(),a.moveTo(n,v),a.lineTo(n,r),a.stroke(),a.fillStyle=s,a.font=`9px ${Q.mono}`,a.textAlign=`center`,a.textBaseline=`top`,a.fillText(Pz(t,(g-h)/T),n,r+4)}for(let e=0;e<u.length;e++){let t=u[e],n=v+e*(tX+nX),r=rX[(w.get(t.group??t.label)??0)%rX.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,tX-nX),a.globalAlpha=1,a.fillStyle=s,a.font=`9px ${Q.mono}`,a.textAlign=`right`,a.textBaseline=`middle`;let f=t.label.length>16?t.label.slice(0,15)+`…`:t.label;a.fillText(f,x-4,n+(tX-nX)/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}: ${Fz(s.start)} → ${Fz(s.end)} (${Fz(l)})`;r.font=`11px ${Q.mono}`;let f=r.measureText(u).width,h=1/0,g=-1/0;for(let e of o)e.start<h&&(h=e.start),e.end>g&&(g=e.end);let _=(g-h)*.02||1;h-=_,g+=_;let v=t-eX.left-eX.right,y=e=>eX.left+(e-h)/(g-h)*v,b=eX.top+i*(tX+nX),x=(y(s.start)+y(s.end))/2,S=Math.max(4,Math.min(t-f-8,x-f/2)),C=b-22<eX.top?b+tX+4:b-20;r.fillStyle=`rgba(0,0,0,0.8)`,r.fillRect(S-3,C-3,f+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(u,S,C)}let _=K(h);_.current=h;let v=K(null);v.current??=VH(()=>_.current(),()=>o.current);let y=()=>v.current.schedule(),b=()=>{PH(l.current),l.current=NH(g)};return W(()=>{v.current.now()}),W(()=>()=>v.current?.cancel(),[]),W(()=>{s.current=null,y()},[t]),G(()=>{let e=o.current;if(!e)return;let t=new zH(()=>{s.current=null,y(),b()});return t.observe(e),()=>t.disconnect()}),G(()=>{let e=a.current;if(!e)return;let t=e=>{e.preventDefault(),u.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),{tasks:r}=d.current,i=t.clientY-n.top,a=Math.floor((i-eX.top)/(tX+nX));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)}},[]),vt(`div`,{ref:o,style:{position:`relative`,width:`100%`,height:`100%`},children:[q(`canvas`,{ref:i,className:`chart-canvas`,role:`img`,"aria-label":`Gantt chart`}),q(`canvas`,{ref:a,className:`chart-canvas chart-overlay`})]})}var aX=e=>[...e].filter(e=>Number.isFinite(e.at)).sort((e,t)=>e.at-t.at),oX=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]},sX=e=>`#${e.map(e=>Math.round(e).toString(16).padStart(2,`0`)).join(``)}`;function cX(e,t,n,r){let i=t?aX(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=oX(o.color),u=oX(s.color);return sX([l[0]+(u[0]-l[0])*c,l[1]+(u[1]-l[1])*c,l[2]+(u[2]-l[2])*c])}function lX(e,t,n,r,i,a=96){let o=i-r||1,s=t?aX(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:cX(`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:cX(`gradient`,s,n,r+(t+.5)/a*o)}))}function uX(e,t,n){let r=e=>+(t+e*(n-t)).toPrecision(6),i=`#22c55e`,a=`#ef4444`;if(e===`traffic`)return{mode:`zones`,stops:[{at:r(0),color:i},{at:r(.7),color:`#f5a524`},{at:r(.9),color:a}]};let o=[{at:r(0),color:i},{at:r(.5),color:`#eab308`},{at:r(1),color:a}];return{mode:`gradient`,stops:e===`green-red`?o:o.map((e,t)=>({...e,color:o[o.length-1-t].color}))}}function dX(e,t,n){let r=t?aX(t):[];if(!e||e===`solid`||r.length===0)return n;let i=r[0].at,a=r[r.length-1].at,o=e=>`${((e-i)/(a-i||1)*100).toFixed(1)}%`;if(e===`gradient`)return`linear-gradient(90deg, ${r.map(e=>`${e.color} ${o(e.at)}`).join(`, `)})`;let s=100/r.length;return`linear-gradient(90deg, ${r.map((e,t)=>`${e.color} ${(t*s).toFixed(1)}% ${((t+1)*s).toFixed(1)}%`).join(`, `)})`}var fX=.75*Math.PI,pX=1.5*Math.PI;function mX({gauges:e,live:t,backgroundToken:n=``,onPlotContextMenu:r}){let i=K(null),a=K(null),o=K(null),s=K(r);G(()=>{s.current=r},[r]);let c=K({gauges:e,live:t});G(()=>{c.current={gauges:e,live:t}},[e,t]);let l=K(iU()),u=K(0);function d(){if(o.current)return o.current;let e=a.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`,ink:`#e4e4e7`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`,ink:t.getPropertyValue(`--chart-fg`).trim()||`#e4e4e7`};return o.current=n,n}function f(){let e=i.current,t=a.current;if(!e||!t)return;let n=Math.max(1,t.clientWidth),r=Math.max(1,t.clientHeight),o=Math.min(2,window.devicePixelRatio||1),s=Math.floor(n*o),f=Math.floor(r*o);(e.width!==s||e.height!==f)&&(e.width=s,e.height=f),e.style.width=`${n}px`,e.style.height=`${r}px`;let p=e.getContext(`2d`);if(!p)return;p.setTransform(o,0,0,o,0,0);let h=d(),{gauges:g,live:_}=c.current,v=g;if(_){let e=performance.now(),t=fU(l.current,_.latestT(),e-u.current);u.current=e,v=g.map(e=>{if((e.stat??`last`)!==`last`)return e;let n=_.valueAt(e.name,t);return Number.isFinite(n)?{...e,value:n}:e}),m.current.schedule()}if(p.fillStyle=h.bg,p.fillRect(0,0,n,r),v.length===0){p.fillStyle=h.muted,p.font=`13px ${Q.sans}`,p.textAlign=`left`,p.textBaseline=`top`,zV(p);return}let{cols:y,rows:b}=hX(v.length,n,r,v.some(e=>e.style===`arc`)?1.15:3.2),x=n/y,S=r/b;v.forEach((e,t)=>{let n=t%y*x,r=Math.floor(t/y)*S;e.style===`arc`?TX(p,e,n,r,x,S,e.color,e.alarm??null,h):EX(p,e,n,r,x,S,e.color,e.alarm??null,h)})}let p=K(f);p.current=f;let m=K(null);return m.current??=VH(()=>p.current(),()=>a.current),W(()=>{m.current.now()}),W(()=>()=>m.current?.cancel(),[]),W(()=>{o.current=null,m.current.schedule()},[n]),G(()=>{let e=a.current;if(!e)return;let t=new zH(()=>{o.current=null,m.current.schedule()});return t.observe(e),()=>t.disconnect()},[]),q(`div`,{ref:a,style:{position:`relative`,width:`100%`,height:`100%`},children:q(`canvas`,{ref:i,className:`chart-canvas`,role:`img`,"aria-label":`Gauges: ${e.map(e=>`${e.name} ${Number.isFinite(e.value)?gX(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 hX(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 gX=(e,t)=>Pz(e,Dz(Math.abs(t),100)),_X=(e,t)=>Math.max(0,Math.min(1,(t-e.min)/(e.max-e.min||1))),vX=(e,t)=>{let n=e.fromZero?_X(e,0):0;return[Math.min(n,t),Math.max(n,t)]},yX=(e,t)=>!!t&&(t.linked?t.linked===`active`:Number.isFinite(e.value)&&e.value>=t.value),bX=e=>(e.colorMode===`gradient`||e.colorMode===`zones`)&&!!e.stops?.length,xX=(e,t)=>yX(e,t)?t.color:cX(e.colorMode,e.stops,e.color,e.value);function SX(e,t,n){for(let r of lX(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 CX(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 wX=Math.SQRT1_2;function TX(e,t,n,r,i,a,o,s,c){let l=Math.max(6,Math.min(i,a)*.06),u=t.max-t.min,d=gX(t.min,u),f=gX(t.max,u),p=e=>Math.max(9,Math.min(22,e*.1)),m=e=>Math.max(4,e*.13),h=Math.max(8,Math.min((i-2*l)/2,(a-2*l)/1.9)),g=0;for(let t=0;t<2;t++){e.font=`${p(h)}px ${Q.mono}`,g=Math.max(e.measureText(d).width,e.measureText(f).width);let t=m(h),n=Math.max(h+t/2,wX*h+g/2),r=h+t/2+wX*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+wX*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=>fX+e*pX;e.lineCap=`round`,e.lineWidth=_,e.strokeStyle=c.grid,e.beginPath(),e.arc(b,x,h,fX,fX+pX),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(_X(t,s.value)),fX+pX),e.stroke(),e.globalAlpha=1,e.lineCap=`round`);let[C,w]=vX(t,Number.isFinite(t.value)?_X(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(bX(t)){let n=pX/(2*Math.PI),r=SX(e.createConicGradient(fX,b,x),t,e=>e*n);r.addColorStop(1,cX(t.colorMode,t.stops,t.color,t.min)),e.strokeStyle=r,e.globalAlpha=.24,e.beginPath(),e.arc(b,x,h,fX,fX+pX),e.stroke(),e.globalAlpha=1,Number.isFinite(t.value)&&!yX(t,s)&&T()}if(Number.isFinite(t.value)&&(!bX(t)||yX(t,s))&&(e.strokeStyle=yX(t,s)?s.color:o,T()),t.fromZero&&t.min<0&&t.max>0){let n=S(_X(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(_X(t,s.value));e.strokeStyle=s.color,e.lineWidth=Math.max(1.5,s.width),e.lineCap=`butt`,e.beginPath(),e.moveTo(b+Math.cos(n)*(h-_*.9),x+Math.sin(n)*(h-_*.9)),e.lineTo(b+Math.cos(n)*(h+_*.9),x+Math.sin(n)*(h+_*.9)),e.stroke();let r=h+_*.9+10*.7;s.linked&&EU(e,b+Math.cos(n)*r-10/2,x+Math.sin(n)*r-10/2,s.color)}let E=Number.isFinite(t.value)?gX(t.value,u):`—`,D=2*(h-_)*.82,O=Math.max(11,h*.42);e.font=`650 ${O}px ${Q.sans}`;let k=e.measureText(E).width;k>D&&(O=Math.max(9,O*D/k),e.font=`650 ${O}px ${Q.sans}`),e.textAlign=`center`,e.textBaseline=`alphabetic`,e.fillStyle=yX(t,s)||bX(t)?xX(t,s):c.ink,e.fillText(E,b,x+O*.32),e.fillStyle=c.muted,t.unit&&(e.font=`600 ${Math.max(9,h*.13)}px ${Q.sans}`,e.fillText(CX(e,t.unit,D),b,x+O*.32+Math.max(11,h*.19)));let A=x+wX*h+_/2+6,j=wX*h;e.textBaseline=`top`,e.font=`${v}px ${Q.mono}`,e.fillText(d,b-j,A),e.fillText(f,b+j,A);let M=2*j-g-16,N=Math.max(10,Math.min(26,h*.13));e.font=`600 ${N}px ${Q.sans}`;let P=e.measureText(t.name).width;P>M&&N>9&&(N=Math.max(9,N*M/P),e.font=`600 ${N}px ${Q.sans}`),e.fillText(CX(e,t.name,M),b,A+(v-N)/2)}function EX(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+_X(t,e)*f;e.textBaseline=`alphabetic`,e.fillStyle=c.muted,e.font=`600 ${Math.max(10,m*.42)}px ${Q.sans}`,e.textAlign=`left`,e.fillText(CX(e,t.name,f),u,h-p/2-m-4),e.textAlign=`right`,e.fillStyle=yX(t,s)?s.color:c.ink,e.font=`650 ${m}px ${Q.sans}`;let _=t.unit?(e.font=`600 ${Math.max(9,m*.4)}px ${Q.sans}`,e.measureText(` ${t.unit}`).width):0;t.unit&&(e.fillStyle=c.muted,e.fillText(` ${t.unit}`,d,h-p/2-8)),e.fillStyle=yX(t,s)||bX(t)?xX(t,s):c.ink,e.font=`650 ${m}px ${Q.sans}`,e.fillText(Number.isFinite(t.value)?gX(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)?_X(t,t.value):0,y=e=>u+e*f,[b,x]=vX(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`};bX(t)&&(e.strokeStyle=SX(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)&&!yX(t,s)&&S()),Number.isFinite(t.value)&&(!bX(t)||yX(t,s))&&(e.strokeStyle=yX(t,s)?s.color:o,S()),t.fromZero&&t.min<0&&t.max>0&&(e.strokeStyle=c.muted,e.lineWidth=1.5,e.lineCap=`butt`,e.beginPath(),e.moveTo(g(0),h-p*.75),e.lineTo(g(0),h+p*.75),e.stroke(),e.lineWidth=p,e.lineCap=`round`),s&&s.value>=t.min&&s.value<=t.max&&(e.strokeStyle=s.color,e.lineWidth=Math.max(1.5,s.width),e.lineCap=`butt`,e.beginPath(),e.moveTo(g(s.value),h-p),e.lineTo(g(s.value),h+p),e.stroke(),s.linked&&EU(e,g(s.value)-10/2,h-p-10-2,s.color)),e.fillStyle=c.muted,e.font=`${Math.max(9,m*.34)}px ${Q.mono}`,e.textBaseline=`top`,e.textAlign=`left`,e.fillText(gX(t.min,t.max-t.min),u,h+p/2+4),e.textAlign=`right`,e.fillText(gX(t.max,t.max-t.min),d,h+p/2+4)}var DX=`Video limit reached this month`,OX=720;function kX(e,t){return t?e<OX:e<640}function AX(e){return e<=1?{cols:1,rows:1}:e===2?{cols:2,rows:1}:e<=4?{cols:2,rows:2}:{cols:3,rows:3}}function jX(e,t){return e.flatMap(e=>{let n=e.info?.meta;if(!n?.recordingId)return[];let r=n.wallOrigin?Number(n.wallOrigin):NaN,i=n.wallQuality;return[{recordingId:n.recordingId,wallOrigin:Number.isFinite(r)?r:null,wallQuality:i===`exact`||i===`approx`?i:null,xOffset:t[e.id]??0}]})}var MX={get:()=>null,subscribe:()=>()=>{}};function NX(e){let[t,n]=pt(null);return G(()=>{let t=e.current;if(!t)return;let r=e=>n(t=>kX(e,t??!1));if(r(t.clientWidth),typeof ResizeObserver>`u`)return;let i=new ResizeObserver(e=>{for(let t of e)r(t.contentRect.width)});return i.observe(t),()=>i.disconnect()},[e]),t}function PX(e){let t=Gn(e.settings),[n,r]=pt(null),[i,a]=pt(null),o=K(null);W(()=>{i&&o.current?.querySelector(`[data-camera="${CSS.escape(i)}"]`)?.focus()},[i]);let s=e.recordings??[],c=e=>s.findIndex(t=>t.recordingId===e.recordingId),l=(e.video??[]).filter(e=>e.kind===`recorded`&&c(e)>=0).sort((e,t)=>c(e)-c(t)),u=e.onContextMenu?t=>{t.preventDefault(),e.onContextMenu({clientX:t.clientX,clientY:t.clientY})}:void 0;if(!t.length){let t=[...new Set([...e.live.filter(e=>e.kind===`camera`&&!e.lowOf),...l].map(t=>Hn(t,e.live)))].sort();return q(IX,{onContextMenu:u,title:`Choose a camera in this panel's settings`,detail:t.length?t.join(`, `):void 0})}let d={panel:e,recorded:l,recIndex:c};if(t.length===1)return q(FX,{...d,id:t[0],onMenu:u});let f=n&&t.includes(n)?n:null,p=f?[f]:t,{cols:m,rows:h}=AX(p.length),g=()=>{a(f),r(null)};return vt(`div`,{ref:o,className:`kymo-camera-wall`,style:{gridTemplateColumns:`repeat(${m}, minmax(0, 1fr))`,gridTemplateRows:`repeat(${h}, minmax(0, 1fr))`},onContextMenu:u,onKeyDown:e=>{e.key===`Escape`&&f&&(e.stopPropagation(),g())},children:[p.map(e=>q(FX,{...d,id:e,multi:!0,wall:!f,onPick:f?void 0:()=>{a(null),r(e)}},e)),f?vt(`button`,{type:`button`,className:`kymo-camera__all`,onClick:g,autoFocus:!0,children:[vt(`svg`,{viewBox:`0 0 16 16`,"aria-hidden":`true`,children:[q(`rect`,{x:`2`,y:`2`,width:`5`,height:`5`,rx:`1`}),q(`rect`,{x:`9`,y:`2`,width:`5`,height:`5`,rx:`1`}),q(`rect`,{x:`2`,y:`9`,width:`5`,height:`5`,rx:`1`}),q(`rect`,{x:`9`,y:`9`,width:`5`,height:`5`,rx:`1`})]}),`All cameras`]}):null]})}function FX({panel:e,recorded:t,recIndex:n,id:r,multi:i,wall:a,onPick:o,onMenu:s}){let c=e.recordings??[],l={onMenu:s,wall:a,onPick:o},u=t.find(e=>e.id===r);if(u)return q(LX,{...e,...l,source:u,name:i?Hn(u,e.live):u.name,rec:c[n(u)]},`rec:${u.recordingId}:${u.id}`);let d=e.live.find(e=>e.id===r&&e.kind===`camera`);if(d?.limitNotice&&(d.limitNotice===`Video limit reached this month`||!d.video))return q(IX,{onContextMenu:s,title:d.limitNotice,detail:Hn(d,e.live)});if(!d?.video||d.status===`error`)return q(IX,{onContextMenu:s,title:`Camera offline`,detail:d?Hn(d,e.live):void 0});let f=e.live.find(e=>e.kind===`camera`&&e.lowOf===d.id&&e.video&&e.status!==`error`),p=f?.video?AE({...f,video:f.video}):void 0;return q(LX,{...e,...l,source:AE({...d,video:d.video}),low:p,name:i?Hn(d,e.live):d.name,conn:d},d.id)}function IX({title:e,detail:t,onContextMenu:n}){return q(`div`,{className:`kymo-camera`,onContextMenu:n,children:vt(`div`,{className:`kymo-camera__empty`,children:[vt(`svg`,{className:`kymo-camera__empty-icon`,viewBox:`0 0 24 24`,"aria-hidden":`true`,children:[q(`rect`,{x:`2.5`,y:`6`,width:`13`,height:`12`,rx:`2.5`}),q(`path`,{d:`M15.5 10.5 21.5 7v10l-6-3.5`})]}),q(`p`,{className:`kymo-camera__empty-title`,children:e}),t?q(`p`,{className:`kymo-camera__empty-detail`,children:t}):null]})})}function LX(e){let{settings:t,source:n}=e,r=e.cursor??MX,i=mt(r.subscribe,r.get),a=e=>e.kind===`data`,o=e.rec?void 0:t.syncStreamId?e.live.find(e=>e.id===t.syncStreamId&&a(e)):e.live.find(t=>t.id===e.conn.parentId&&a(t))??e.live.find(t=>a(t)&&e.selection.includes(t.id))??e.live.find(a),s=i??e.viewXRange?.[1]??null,c=null,l=null,u=o?.clock?.quality()??`none`;if(e.rec){let{wallOrigin:r,wallQuality:i,xOffset:a}=e.rec;u=i??`none`;let o=n.range()?.[0]??null;s===null?c=o:r===null?(c=o,l=`This recording has no wall clock`):e.xKey===`Time`?c=r+s-a+t.offsetMs/1e3:e.xKey===`ElapsedTime`&&i===`exact`?c=s-a+t.offsetMs/1e3:(c=o,l=`Sync needs a time X axis`)}else s!==null&&(e.xIsTime?(c=o?.clock?.toWall(s,t.offsetMs)??null,c===null&&(l=`No data stream to sync with`)):l=`Sync needs a time X axis`);let d=K(null),f=K(null),p=NX(d),m=p===null?null:e.low&&(p||e.wall)?e.low:n,h=K(t.fit),g=K(c);G(()=>{h.current=t.fit,g.current=c});let _=K(null),v=K(null),[y,b]=pt(null),x=y??m??n,[S,C]=pt(!1),[w,T]=pt(!0);W(()=>{if(!m||_.current?.source===m)return;let e=!_.current,t=null,n=!1,r=()=>t?_.current===t:e,i=t=VX(m,f.current,()=>h.current,g.current,{unsupported:()=>{r()&&C(!0)},buffered:e=>{r()&&T(e)},frame:()=>{if(_.current===t){n||(n=!0,b(m));return}_.current?.dispose(),_.current=i,v.current=null,i.show(),n=!0,b(m),T(i.buffered())}},e);if(e){_.current=i;return}return v.current=i,()=>{_.current!==i&&(i.dispose(),v.current===i&&(v.current=null))}},[m]),W(()=>()=>{_.current?.dispose(),_.current=null},[]),W(()=>{_.current?.setTarget(c),v.current?.setTarget(c)},[c]);let E=RX(e.rec||c!==null?null:x),D=!!x.lowOf,O=x.info().latestT,k=!e.rec&&c!==null&&O!==null?c-O:null,A=e.rec?`No video at this time`:`Not buffered`;return vt(`div`,{ref:d,className:`kymo-camera${e.onPick?` is-tile`:``}`,onContextMenu:e.onMenu,...e.onPick?{role:`button`,tabIndex:0,"data-camera":n.id,"aria-label":`Show ${e.name} alone`,onClick:e.onPick,onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),e.onPick())}}:{},children:[q(`canvas`,{ref:f,className:`kymo-camera__video`,role:`img`,"aria-label":`Video from ${e.name}`}),S?q(`div`,{className:`kymo-camera__empty`,children:q(`p`,{className:`kymo-camera__empty-title`,children:`This browser can't decode this camera`})}):E===null?vt(`div`,{className:`kymo-camera__overlay`,children:[q(`span`,{className:`kymo-camera__name`,children:e.name}),e.rec?q(`span`,{className:`kymo-camera__rec`,children:`Recording`}):c===null?q(`span`,{className:`kymo-camera__live`,children:`LIVE`}):q(`span`,{className:`kymo-camera__ago`,children:k===null?``:BX(k)}),D?q(`span`,{className:`kymo-camera__badge`,title:`Low-quality copy (small panel)`,children:`LQ`}):null,c!==null&&u!==`none`?q(`span`,{className:`kymo-camera__badge${u===`exact`?` is-exact`:``}`,children:u===`exact`?`Exact`:`Approx.`}):null,l??(c!==null&&!w?A:null)?q(`span`,{className:`kymo-camera__note`,children:l??A}):null,e.conn?.limitNotice?q(`span`,{className:`kymo-camera__note`,role:`status`,children:e.conn.limitNotice}):null]}):vt(`div`,{className:`kymo-camera__empty kymo-camera__empty--cover`,role:`status`,children:[q(`p`,{className:`kymo-camera__empty-title`,children:`No signal`}),vt(`p`,{className:`kymo-camera__empty-detail`,children:[e.name,` · no video for `,zX(E)]})]})]})}function RX(e){let[t]=pt(()=>Date.now()),[n,r]=pt(null);return W(()=>{if(!e){r(null);return}let n=()=>{let{arrivedAt:n,gapMs:i}=e.info(),a=Date.now()-Math.max(n??0,t);r(a>OE(i)?Math.floor(a/1e3):null)};n();let i=setInterval(n,500);return()=>clearInterval(i)},[e,t]),n}function zX(e){return e<60?`${e} s`:e<3600?`${Math.floor(e/60)} min`:`${Math.floor(e/3600)} h`}function BX(e){let t=Math.abs(e).toFixed(1);return t===`0.0`?`0.0 s`:`${e<0?`−`:`+`}${t} s`}function VX(e,t,n,r,i,a=!0){let o=e.acquire?.(),s=!1,c=!0,l=e=>{c=e,i.buffered(e)},u=null,d=null,f=r,p=`live`,m=!0,h=!1,g=!1,_=null,v=null,y=null,b=[],x=e=>{if(s){e.close();return}p===`seek`?(_?.close(),_=e):(v?.close(),v=e,i.frame?.())},S=()=>{!d||d.state===`closed`?d=new VideoDecoder({output:x,error:()=>{}}):d.reset(),d.configure(u),m=!0},C=e=>{d?.state===`closed`&&e.key&&S(),!(d?.state!==`configured`||m&&!e.key)&&(m=!1,d.decode(new EncodedVideoChunk({type:e.key?`key`:`delta`,timestamp:Math.round(e.t*1e6),data:e.data})))},w=()=>{p=`live`,l(!0),S();for(let t of e.livePlan?.()??[])C(t)},T=async()=>{if(!h){h=!0;try{for(;!s&&p===`seek`&&g;){g=!1;let t=[];try{t=await e.seekPlan(f)}catch{}if(!(s||p!==`seek`||g)&&(l(t.length>0),t.length)){S();for(let e of t)C(e);try{await d.flush()}catch{}p===`seek`&&_&&(v?.close(),v=_,_=null,i.frame?.())}}}finally{h=!1,_?.close(),_=null}}},E=()=>{f===null?p!==`live`&&w():(p=`seek`,g=!0,T())};e.onUnit&&b.push(e.onUnit(e=>{u&&p===`live`&&C(e)})),(async()=>{if(typeof VideoDecoder>`u`){i.unsupported();return}if(e.info().codec||(e.ready?await e.ready():e.onUnit&&await new Promise(t=>{let n=e.onUnit(()=>{e.info().codec&&(n(),t())});b.push(n)})),s)return;if(!e.info().codec){l(!1);return}let t={codec:e.info().codec,optimizeForLatency:!0,hardwareAcceleration:`no-preference`},n=!1;try{n=(await VideoDecoder.isConfigSupported(t)).supported===!0}catch{}if(!s){if(!n){i.unsupported();return}u=t,f===null?w():E()}})();let D=n(),O=()=>{if(!a)return;let e=window.devicePixelRatio||1,r=Math.max(1,Math.round(t.clientWidth*e)),i=Math.max(1,Math.round(t.clientHeight*e)),o=!1;if((t.width!==r||t.height!==i)&&(t.width=r,t.height=i,o=!0),v&&(y?.close(),y=v,v=null,o=!0),n()!==D&&(D=n(),o=!0),!o||!y)return;let s=t.getContext(`2d`);if(!s)return;let c=y.displayWidth,l=y.displayHeight,u=D===`cover`?Math.max(r/c,i/l):Math.min(r/c,i/l),d=c*u,f=l*u;s.clearRect(0,0,r,i),s.drawImage(y,(r-d)/2,(i-f)/2,d,f)},k=0,A=()=>{k=NH(A),O()};return k=NH(A),{source:e,show(){a=!0},buffered:()=>c,setTarget(e){e!==f&&(f=e,u&&E())},dispose(){s=!0,PH(k),b.forEach(e=>e()),d&&d.state!==`closed`&&d.close();for(let e of[_,v,y])e?.close();_=v=y=null,o?.()}}}function HX(e,t){let n=e.filter(e=>e.x.length>=2&&UX(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 UX(e){for(let t=1;t<e.length;t++)if(!(e[t]>=e[t-1]))return!1;return!0}function WX(e){if(e.length===0)return null;if(e.length===1)return e[0];let t=new Set,n={};for(let r of e)for(let e=0;e<r.columnNames.length;e++){let i=r.columnNames[e];t.add(i),r.units[e]?.trim()&&(n[i]=r.units[e])}let r=[...t];return{meta:``,columnNames:r,units:r.map(e=>n[e]??``),rows:e.flatMap(e=>e.rows)}}function GX(e,t,n,r,i){return n||e.length===0||(t>0?e.length!==1:e.length<2||r!==`ElapsedTime`)?null:e.map((e,n)=>({conn:e,keySuffix:`__${t+n}`,offset:i[e.id]??0}))}function KX(e,t,n,r,i){if(e.length===1){let a=e[0];return qX(a.conn,t,n,a.keySuffix,a.offset,r,i)}let a=e.map(e=>qX(e.conn,t,n,e.keySuffix,e.offset,[],null)),o=()=>a.reduce((e,t)=>t.latestT()>e.latestT()?t:e);return{pull:(e,t,n,i)=>[...r,...a.flatMap(r=>r.pull(e,t,n,i))],xBounds:()=>{let e=i;for(let t of a){let n=t.xBounds();n&&(e=e?[Math.min(e[0],n[0]),Math.max(e[1],n[1])]:n)}return e},latestX:()=>o().latestX(),version:()=>a.reduce((e,t)=>e+t.version(),0),latestT:()=>o().latestT(),xAtTime:e=>o().xAtTime(e),latestValues:e=>new Map(a.flatMap(t=>[...t.latestValues(e)]))}}function qX(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]))}}}let f=Ye(s.pts,u);if(t!==`ElapsedTime`)return[...a,f];let p=Math.min(e.source.latestTimeSync(),u===void 0?1/0:u-i),m=E(n,t=>e.source.lastKnownSync(t),o-i,c-i,p);if(!m)return[...a,f];let h=i===0?m.x:m.x.map(e=>e+i);return[...a,f,{...m,x:h,cols:new Map([...m.cols].map(([e,t])=>[e+r,t]))}]},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(),id:e.id,latestT:()=>e.source.latestTimeSync(),xAtTime:n=>e.source.xAtTimeSync(t,n)+i,latestValues:t=>{let n=new Map,i=t.filter(e=>e.endsWith(r)),a=e.source.latestValuesSync(i.map(e=>e.slice(0,-r.length)));for(let e of i){let t=a.get(e.slice(0,-r.length));t!==void 0&&n.set(e,t)}return n}}}function JX(e,t){return e.filter(e=>m(t,e))}var YX=`__ref`,XX=8e3;function ZX(e,t){return e.map(e=>({...e,id:`${e.id}${YX}`,column:`${e.column}${YX}`,color:t}))}var QX=new WeakMap;function $X(e,t,n){let r=e.data.rows,i=`${t}\n${n.join(`
|
|
608
|
+
`)}`,a=QX.get(r);a||(a=new Map,QX.set(r,a));let o=a.get(i);if(o)return o;let s=eZ(xe(r,t,n,XX,YX)),c={points:s,span:s.length>1?[s.x[0],s.x[s.length-1]]:null};return a.set(i,c),c}function eZ(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 tZ(e,t){return e?t?[Math.min(e[0],t[0]),Math.max(e[1],t[1])]:e:t}function nZ(e,t,n,r,i){e.source.trackCycles(t);let a=r.reference===`dataset`&&i?$X(i,t,n):null,s=null;return{pull:(i,c,l,u)=>{let d=e.source.version();if(!s||s.ver!==d||s.x0!==i||s.x1!==c||s.mp!==l){let u=M;if(r.reference===`previous`){let r=e.source.cyclePointsSync(t,`previous`,n,{x0:i,x1:c},l);u={...r,cols:new Map([...r.cols].map(([e,t])=>[e+YX,t]))}}else a&&(u=o(a.points,i,c));s={ver:d,x0:i,x1:c,mp:l,live:e.source.cyclePointsSync(t,`current`,n,{x0:i,x1:c},l),ref:u}}return[s.ref,Ye(s.live,u)]},id:e.id,latestT:()=>e.source.latestTimeSync(),xAtTime:n=>e.source.xAtTimeSync(t,n),xBounds:()=>tZ(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 rZ(e,t){return e.reference===`previous`?e.previousColor:e.reference===`dataset`&&t?e.datasetColor:null}function iZ(e,t,n,r,i=0){let a=e.bands;if(!a)return[];let o=n.filter(e=>a[e.column]);if(o.length===0||e.data.rows.length!==a[o[0].column].lo.length)return[];let s=Float64Array.from(e.data.rows,e=>{let n=e[t];return typeof n==`number`?n+i:NaN});return o.map(e=>({seriesId:e.id,color:r??e.color,x:s,lo:a[e.column].lo,hi:a[e.column].hi}))}var aZ=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?a(new Float64Array,new Float64Array,e.viewport.x0,e.viewport.x1,e.maxPoints):a(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}:L(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:g(r,i.map(e=>this.#e.get(e)),i,t.x0,t.x1,n)}async readColumns(e,t,n){let r={};for(let i of e){let e=this.#e.get(i);e&&(r[i]=e.slice(t,t+n))}return r}async xBounds(e){return this.xBoundsSync(e)}xBoundsSync(e){let t=this.#r.get(e);if(!t){let n=this.#e.get(e),r=1/0,i=-1/0;if(n)for(let e=0;e<n.length;e++){let t=n[e];t<r&&(r=t),t>i&&(i=t)}t=r<=i?{x0:r,x1:i}:{x0:0,x1:0},this.#r.set(e,t)}return t}sampleRowsSync(e,t){let n=t?this.#e.get(t.xcol):void 0,r=null;if(t&&n){r=[];for(let e=0;e<n.length;e++)n[e]>=t.x0&&n[e]<=t.x1&&r.push(e)}let i=r?r.length:this.#n,a=Math.max(1,Math.ceil(i/e)),o=[...this.#e.keys()],s=o.map(e=>this.#e.get(e)),c=[];for(let e=0;e<i;e+=a){let t=r?r[e]:e,n={};for(let e=0;e<o.length;e++){let r=s[e][t];n[o[e]]=Number.isNaN(r)?null:r}c.push(n)}return c}async sampleRows(e,t){return this.sampleRowsSync(e,t)}async dispose(){}};function oZ(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 sZ(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)=>oZ(i+(t+.5)*(c/n))),m=Array.from({length:r},(e,t)=>oZ(o+(r-1-t+.5)*(l/r))),h=[];for(let e=0;e<r;e++){let t=r-1-e;for(let r=0;r<n;r++){let i=e*n+r,a=d[i],o=f?a:a>0?u[i]/a:NaN;h.push({x:p[r],y:m[t],value:o})}}return{cells:h,xLabels:p,yLabels:m}}function cZ(e,t){return t.some(t=>t.name===e)}function lZ(e,t){return cZ(e,t)?`ƒ ${e}`:e}var uZ=8e3,dZ=3e3,fZ=[];function pZ(e){return`live`in e?e.live.source.columns():`source`in e&&e.source instanceof aZ?e.source.columnMap:void 0}var mZ=4e3,hZ=new WeakMap;function gZ(e,t,n){let r=hZ.get(e);r||hZ.set(e,r=new Map);let i=JSON.stringify([n,...t]),a=r.get(i);return a||r.set(i,a=new BE({meta:``,columnNames:[n,...t],units:[],rows:e})),a}var _Z=new WeakMap;function vZ(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 yZ(e,t){let n=1/0,r=-1/0;for(let{rows:i,offset:a}of e){let e=_Z.get(i);e||(e=new Map,_Z.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 bZ(e,t){let n={};for(let t=0;t<e.columnNames.length;t++){let r=e.units[t]?.trim();r&&(n[e.columnNames[t]]=r)}let r=Object.entries(n);for(let e=0;e<t;e++)for(let[t,i]of r)n[`${t}__${e}`]=i;return n}function xZ(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 SZ=new Map;function CZ(e){let t=SZ.get(e);return t||(t=Float64Array.from({length:e},(e,t)=>t),SZ.clear(),SZ.set(e,t)),t}function wZ(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:ft(()=>d===`ElapsedTime`?e.liveConnections:e.liveConnections.map(e=>{let t=xZ(e.dataset.rows,d);return t===e.dataset.rows?e:{...e,dataset:{...e.dataset,rows:t}}}),[e.liveConnections,d])},[p,m]=pt({}),h=ft(()=>l.some(e=>e.kind!==`multiband`),[l]),g=ft(()=>f.connections.some(e=>r.includes(e.id)),[f.connections,r]),_=ft(()=>{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=ft(()=>WX(i.map(e=>{let t=p[e.id];return t?{...e.data,rows:t}:e.data})),[i,p]),y=ft(()=>{let e=f.connections.filter(e=>r.includes(e.id)).map(e=>e.dataset);return e.length===0?v:WX(v?[v,...e]:e)},[v,f.connections,r]),b=ft(()=>CE(a,u,d).map(e=>e.id).join(`
|
|
609
609
|
`),[a,u,d]),x=ft(()=>{let e=new Set(b.split(`
|
|
610
|
-
`));return a.filter(t=>e.has(t.id))},[a,b]),S=ft(()=>{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=>SE(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=ft(()=>{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=ft(()=>w.length===1?
|
|
610
|
+
`));return a.filter(t=>e.has(t.id))},[a,b]),S=ft(()=>{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=>SE(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=ft(()=>{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=ft(()=>w.length===1?pZ(w[0]):void 0,[w]),D=S?.partRows??fZ;W(()=>{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 yW(`sampleRows`,()=>n.sampleRows(dZ,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=ft(()=>C?.columnNames.join(`
|
|
611
611
|
`)??``,[C]),k=a.map(e=>e.name).join(`
|
|
612
|
-
`),A=ft(()=>{let e=i.filter(e=>e.kind!==`memory`).flatMap(e=>wz(e.schema));return e.length?e:null},[i]),j=ft(()=>i.some(e=>e.kind!==`memory`)||!g&&i.some(e=>e.data.rows.length>
|
|
613
|
-
`).filter(e=>!i.has(e));return a.length?[...r,...a]:r},[O,k,A]),L=ft(()=>{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=ft(()=>{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(xe(C.rows,d,n,KX));else{let e=Math.max(1,Math.floor(KX/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(xe(a,d,n,e,`__${t}`,o[i.id]??0))}}e[t]=r}return e},[C,L,d,T,w,o,D,M,j]),z=ft(()=>{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=>eZ(e,i),l;if(!T)l=a(r);else{let e=a(r);l=[];for(let t=0;t<w.length;t++){let n=Zz(s,w[t].id,t,c);for(let r of e)l.push({...r,id:`${r.id}__${t}`,column:`${r.column}__${t}`,color:n})}}let f=R[t.id]??[],p=T&&n?.kind===`multiband`&&n.envelope?r.flatMap(e=>{let t=wX(f.flatMap((t,n)=>{let r=t.cols.get(`${e.column}__${n}`);return r?[{x:t.x,y:r}]:[]}),XX);return t?[{seriesId:e.id,color:e.color,...t}]:[]}):void 0,m=w.flatMap((e,t)=>`bands`in e&&e.bands?BX(e,d,r,T?Zz(s,e.id,t,c):void 0,o[e.id]??0):[]),h=[...p??[],...m];e[t.id]={effectiveSeries:l,points:f,envelopes:h.length?h:void 0}}return e},[C,l,u,d,T,w,s,c,o,R]),B=ft(()=>{let e={pts:{},colorMeta:{},datasetColors:{}};if(!C)return e;let t={},r={},i={},a=YX,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}=OW(o,l,p,{xKey:d,viewXRange:n,colorOverrides:s,palette:c});t[e.id]=r,i[e.id]=a;continue}let m=DW(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=K(new Map),ee=ft(()=>{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=xW(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=xW(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?xW(r,s,i):void 0,p=c?xW(r,c,i):void 0,m=l?xW(r,l,i):void 0;if(!f||!p||!m){e[a.id]={points:t};continue}let h=n?xW(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]),te=ft(()=>{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&&SW(C.rows,n.histColumn,E)||new Float64Array}return e},[C,l,u,E]),H=ft(()=>{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?xW(C.rows,n.polarAngleCol,E):void 0,i=n?.kind===`polar`&&n.polarRadiusCol?xW(C.rows,n.polarRadiusCol,E):void 0;e[t.id]=r&&i?{angles:r,radii:i}:{angles:[],radii:[]}}return e},[C,l,u,E]),ne=(e,t,n,r)=>{let i=t&&SW(e,t,E)||new Float64Array,a=n?xW(e,n,E):void 0;return{signal:i,rate:a&&wW(a)||parseFloat(r)||1}},re=ft(()=>{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]=ne(C.rows,n.specSignalCol,n.specTimeCol,n.specSampleRate))}return e},[C,l,u,E]),ie=ft(()=>{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?CW(C.rows,n.boxValueCol,n.boxGroupCol||void 0,E):[]}return e},[C,l,u,E]),U=ft(()=>{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]=ne(C.rows,n.sgSignalCol,n.sgTimeCol,n.sgSampleRate))}return e},[C,l,u,E]),ae=ft(()=>{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=xW(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=xW(r,d,E),s,c;if(n.hmSpacing===`values`){o&&Iq(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&&Iq(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]=UX(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);Iq(e)&&(f=e),Iq(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]),oe=ft(()=>{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?CW(C.rows,n.vlValueCol,n.vlGroupCol||void 0,E):[]}return e},[C,l,u,E]),se=ft(()=>{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]),ce=ft(()=>{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?xW(C.rows,n.rocScoreCol,E):void 0,i=n?.kind===`roc`&&n.rocLabelCol?xW(C.rows,n.rocLabelCol,E):void 0;e[t.id]=r&&i?{scores:r,labels:i}:{scores:[],labels:[]}}return e},[C,l,u,E]),le=ft(()=>{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:xW(t,e,E)??new Float64Array,axis:r})),c=s[0]?.values.length??t.length,l=i&&xW(t,i,E)||Float64Array.from({length:c},(e,t)=>t);e[n.id]={xValues:l,series:s}}return e},[C,l,u,E]),ue=ft(()=>{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?xW(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]),de=ft(()=>{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=>xW(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=xW(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]),fe=ft(()=>{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=xW(t,a,E),f=xW(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=xW(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]),pe=ft(()=>{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]),me=ft(()=>{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=>xW(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]),he=ft(()=>{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=>xW(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]),ge=ft(()=>{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=>xW(r,e,E)),a=i[0]?.length??r.length,o=(n.acXCol?xW(r,n.acXCol,E):void 0)??aZ(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]),_e=ft(()=>{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:SW(C.rows,e,E)??new Float64Array}))}return e},[C,l,u,E]),ve=ft(()=>{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=xW(t,i.bbXCol,E),o=xW(t,i.bbYCol,E),s=xW(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=xW(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]),ye=ft(()=>{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]),be=ft(()=>{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]),Se=ft(()=>{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?xW(C.rows,n.cbScoreCol,E):void 0,i=n?.kind===`calibration`&&n.cbLabelCol?xW(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]),Ce=ft(()=>{let e={};if(!C)return e;let t={length:0,theoretical:[],sample:[]},n=e=>{let t=SW(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]),we=ft(()=>{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]),Te=C&&C.columnNames.indexOf(d)>=0?C.units[C.columnNames.indexOf(d)]??``:``,Ee=ft(()=>C?nZ(C,T?w.length:0):{},[C,T,w]);return{dataset:y,datasetWithChannels:C,multiDatasetMode:T,numericCols:I,anyDuckDb:j,duckDbLayers:F,liveConn:_,liveOverlays:M,hasLiveSelected:g,staticXRange:N,xUnit:Te,columnUnits:Ee,multibandDataByPanel:z,xyPointsByPanel:B,xyzPointsByPanel:ee,histogramDataByPanel:te,polarDataByPanel:H,spectrumDataByPanel:re,boxplotDataByPanel:ie,spectrogramDataByPanel:U,heatmapDataByPanel:ae,violinDataByPanel:oe,confusionDataByPanel:se,rocDataByPanel:ce,lossCurveDataByPanel:le,controlChartDataByPanel:ue,parallelCoordsDataByPanel:de,embeddingDataByPanel:fe,flameGraphDataByPanel:pe,barChartDataByPanel:me,radarDataByPanel:he,areaChartDataByPanel:ge,cdfChartDataByPanel:_e,bubbleChartDataByPanel:ve,treemapDataByPanel:ye,sankeyDataByPanel:be,calibrationDataByPanel:Se,qqPlotDataByPanel:Ce,ganttDataByPanel:we,gaugeDataByPanel:ft(()=>{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?xW(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]=sZ(s?i:0,s?a:1,t(e.min),t(e.max));return[{name:n,unit:Ee[n]??``,value:l,min:u,max:d,alarm:e.alarm??null,color:e.color,style:e.style,fromZero:e.fill===`zero`,colorMode:e.colorMode,stops:e.stops,stat:e.value}]})}return e},[C,l,u,E,Ee])}}function sZ(e,t,n,r){t<=e&&(t=e+1);let i=Dz(t-e,5),a=n??Math.floor(e/i)*i,o=r??Math.ceil(t/i)*i;return o>a?[a,o]:[a,a+1]}var cZ=`#fb7185`,lZ=2500;function uZ(e){let t=[],n=(e,r)=>{if(typeof e==`string`){e&&(r===`column`||/(Col|Cols|Column|Columns)$/.test(r))&&t.push(e);return}if(Array.isArray(e)){for(let t of e)n(t,r);return}if(e&&typeof e==`object`)for(let[t,r]of Object.entries(e))t!==`addColumn`&&n(r,t)};return n(e,``),[...new Set(t)]}function dZ(e){let t=fZ(e);if(t.status!==`empty`||!e.data.dataset)return t;let n=new Set([...e.data.datasetWithChannels?.columnNames??[],...e.data.numericCols]);return uZ(e.settings).some(e=>!n.has(e))?{...t,status:`missing`}:t}function fZ(e){let{panel:t,data:n,settings:r}=e;if(t.kind===`camera`)return{status:`ready`,data:null,node:q(gX,{settings:r?.kind===`camera`?r:Un(),live:e.live??[],selection:e.selection??[],viewXRange:e.viewXRange,xIsTime:e.xKey===$e,xKey:e.xKey,video:e.video,recordings:e.recordings,cursor:e.cursor,onContextMenu:t=>e.onContextMenu(t)})};if(!n.dataset)return{status:`no-data`,node:null,data:null};let i=`${e.background??`theme`}|${e.styleToken}`,a=t=>e.onContextMenu(t),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=e.xKey===`ElapsedTime`&&!n.numericCols.includes(`Time`)?`Time`:e.xKey,m={xLabel:n.xUnit?`${p} (${n.xUnit})`:p,series:u,columnUnits:n.columnUnits,height:e.height,backgroundToken:i,viewXRange:e.viewXRange,onViewXRangeChange:e.onViewXRangeChange,onCursorX:e.onCursorX,liveZoom:e.liveZoom,liveZoomId:c,xAxisLine:d?.xAxisLine,yAxisLine:d?.yAxisLine,gridLine:d?.gridLine,lineWidth:d?.lineWidth,onPlotContextMenu:a,shiftMode:e.shiftMode},h=d?.beacon;if(h?.enabled&&e.beaconLive&&f.length>0){let t=eZ((d?.series??[]).filter(t=>t.column!==e.xKey),d?.layout??`overlay`),n=h.reference===`dataset`&&h.datasetId?e.findDataset(h.datasetId):void 0,r=zX(h,!!n),i=r?[...NX(t,r),...t]:t;return o(q(ZU,{...m,series:i,points:[],showLatestValues:!0,liveSource:RX(e.beaconLive,e.xKey,f,h,n),envelopes:n?BX(n,e.xKey,t,r??void 0):void 0,liveZoomMode:`free`}),{series:i,points:[]})}if(n.anyDuckDb)return u.length===0?s:o(q(vW,{...m,layers:n.duckDbLayers,xKey:e.xKey,columns:f,maxPoints:lZ}),{series:u,columns:f});if(!l.some(e=>e.length>0)&&!n.liveOverlays||u.length===0||!f.some(e=>n.numericCols.includes(e)))return s;let g=n.liveConn,_=null,v=n.liveOverlays,y=!g&&v&&f.length>0?OX(v,e.xKey,f,l,n.staticXRange):void 0,b=!!y&&l.length>0,x=y??(g&&f.length>0?{pull:(t,n,r,i,a)=>{let o=g.source.version();if(a){let i=2**Math.ceil(Math.log2((n-t)/8)),a=Math.floor(t/i)*i,s=Math.ceil(n/i)*i,c=Math.round(r*(s-a)/(n-t));return(!_||_.ver!==o||_.x0!==a||_.x1!==s||Math.abs(_.mp-c)>c*.25)&&(_={ver:o,x0:a,x1:s,mp:c,pts:g.source.getPointsSync(f,{xKey:e.xKey,x0:a,x1:s},c),held:E(f,e=>g.source.lastKnownSync(e),a,s,g.source.latestTimeSync())}),_.held?[_.pts,_.held]:[_.pts]}(!_||_.ver!==o||_.x0!==t||_.x1!==n||_.mp!==r)&&(_={ver:o,x0:t,x1:n,mp:r,pts:g.source.getPointsSync(f,{xKey:e.xKey,x0:t,x1:n},r)});let s=Ye(_.pts,i);if(e.xKey!==`ElapsedTime`)return[s];let c=E(f,e=>g.source.lastKnownSync(e),t,n,Math.min(g.source.latestTimeSync(),i??1/0));return c?[s,c]:[s]},cutOnGpu:e.xKey===`ElapsedTime`,id:g.id,latestT:()=>g.source.latestTimeSync(),xAtTime:t=>g.source.xAtTimeSync(e.xKey,t),xBounds:()=>{let t=g.source.xBoundsSync(e.xKey);return t.x1>t.x0?[t.x0,t.x1]:null},latestX:()=>{let t=g.source.latestSync(e.xKey);return Number.isFinite(t)?t:null},version:()=>g.source.version(),latestValues:e=>g.source.latestValuesSync(e),...e.xKey===`ElapsedTime`?{}:{spanForSeconds:t=>g.source.xTravelSync(e.xKey,t),bufferedSeconds:()=>{let e=g.source.xBoundsSync(`ElapsedTime`);return e.x1-e.x0}}}:void 0);return o(q(ZU,{...m,points:l,envelopes:t?.envelopes,showLatestValues:n.hasLiveSelected,fullXRange:n.staticXRange,liveSource:x,liveWindowSeconds:b?null:e.liveWindowSeconds,onLiveWindowChange:b?void 0:e.onLiveWindowChange,liveZoomMode:b?`free`:`follow`}),{series:u,points:l})}case`xyzmesh`:{let t=r?.kind===`xyzmesh`?r:gn(4),l=n.xyzPointsByPanel[c];if(!l||l.points.length<1&&!l.surface)return s;let u=!!l.surface;return o(q(bK,{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:un(t.xyzXScale.scaleMin,t.xyzXScale.scaleMax),yRange:un(t.xyzYScale.scaleMin,t.xyzYScale.scaleMax),zRange:un(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:hn(cZ),l=n.xyPointsByPanel.pts[c]??[];if(l.length===0)return s;let u=n.xyPointsByPanel.colorMeta[c];return o(q(cG,{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(q(DK,{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(q(GK,{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(q(sq,{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(q(pq,{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(q(jq,{signal:e,sampleRate:t,windowSize:r.sgWindowSize,overlap:r.sgOverlap,winFunc:r.sgWinFunc,yMode:r.sgYMode,backgroundToken:i,onPlotContextMenu:a}),e):o(q(Eq,{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(q(Xq,{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(q(iJ,{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(q(dJ,{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(q(_J,{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(q(yJ,{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(q(TJ,{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(q(jJ,{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(q(VJ,{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(q(YJ,{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(q(tY,{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(q(aY,{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(q(lY,{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(q(fY,{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(q(bY,{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(q(TY,{nodes:e,backgroundToken:i,onPlotContextMenu:a}),e)}case`sankey`:{let e=n.sankeyDataByPanel[c]??{nodeNames:[],links:[]};return e.links.length===0?s:o(q(jY,{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(q(NY,{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(q(FY,{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.liveOverlays?.length===1?n.liveOverlays[0].conn:void 0);return o(q(XY,{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(q(BY,{tasks:e,backgroundToken:i,onPlotContextMenu:a}),e)}}return s}var pZ=500,mZ=1e3;function hZ(e){if(Array.isArray(e))return gZ(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,gZ(n)));return t<0?null:t}function gZ(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 _Z(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 vZ({stats:e,host:t}){let[n,r]=pt(null);if(W(()=>{let n=t.current?.ownerDocument.defaultView??window,i=0,a=0,o=0,s=-1,c=-1,l=e.renders,u=t.current?OH(t.current):0,d=f=>{c>=0&&f-s>mZ&&(c=f,s=f,a=0,o=0,l=e.renders,u=t.current?OH(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>=pZ){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?OH(i):0;r({fps:a*1e3/p,repaints:(m-u)*1e3/p,worstFrameMs:o,renderMs:e.lastRenderMs,rendersPerSec:(e.renders-l)*1e3/p,points:hZ(e.data),domNodes:i?i.getElementsByTagName(`*`).length:0,canvasMp:s/1e6,heapMb:d?d.usedJSHeapSize/1048576:null}),a=0,o=0,c=f,l=e.renders,u=m}i=n.requestAnimationFrame(d)};return i=n.requestAnimationFrame(d),()=>n.cancelAnimationFrame(i)},[e,t]),!n)return null;let i=n.fps<20?`var(--danger, #e5484d)`:n.fps<45?`var(--accent, #f5a524)`:void 0;return q(`dl`,{className:`kymo-perf-hud`,style:yZ,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`,_Z(n.points)]],[`DOM nodes`,_Z(n.domNodes)],[`Canvas`,`${n.canvasMp.toFixed(2)} MP`],...n.heapMb===null?[]:[[`JS heap`,`${n.heapMb.toFixed(0)} MB`]]].map(([e,t,n])=>vt(`div`,{style:bZ,children:[q(`dt`,{style:xZ,children:e}),q(`dd`,{style:n?{...SZ,color:n}:SZ,children:t})]},e))})}var yZ={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)`},bZ={display:`flex`,justifyContent:`space-between`,gap:12},xZ={color:`var(--text-muted, #8a93a6)`},SZ={margin:0,fontWeight:600,textAlign:`right`},CZ=[],wZ=3,TZ=`data-kymo-annotation-controls`;function EZ(e,t,n,r){return e.anchor===`x`&&!r?null:e.points.map(([i,a])=>[e.anchor===`x`?$H(r,i):i*t,a*n])}function DZ(e,t,n,r,i){return t.map(([t,a])=>[e.anchor===`x`&&i?eU(i,t):OZ(t/Math.max(1,n)),OZ(a/Math.max(1,r))])}var OZ=e=>Math.round(e*1e4)/1e4,kZ=st(function({annotations:e,tool:t,plotFrame:n,onChange:r,onToolEnd:i,onSelect:a,marks:o=CZ,onMarkSelect:s}){let c=K(null),l=mt(n.subscribe,n.get),u=l?.x?l:null,[d,f]=pt({w:0,h:0}),[p,m]=pt(null),[h,g]=pt(null),[_,v]=pt(null),y=K({annotations:e,onChange:r,onToolEnd:i,onSelect:a,tool:t,selected:p,editing:h,frame:u,size:d});y.current={annotations:e,onChange:r,onToolEnd:i,onSelect:a,tool:t,selected:p,editing:h,frame:u,size:d};let b=e=>{y.current.selected!==e&&(y.current.selected=e,m(e),y.current.onSelect(e))};G(()=>{let e=c.current;if(!e)return;let t=e.ownerDocument.defaultView??window,n=()=>f({w:e.clientWidth,h:e.clientHeight});n();let r=new t.ResizeObserver(n);return r.observe(e),()=>r.disconnect()},[]),W(()=>{t&&b(null)}),W(()=>{p&&!e.some(e=>e.id===p)&&b(null)}),W(()=>()=>{y.current.selected&&y.current.onSelect(null)},[]),W(()=>{let e=c.current?.ownerDocument;if(!e)return;let t=e=>{let{selected:t,editing:n,tool:r,annotations:i,onChange:a,onToolEnd:o}=y.current;if(!(n||RZ(e.target))){if(e.key===`Escape`&&r){o();return}t&&(e.key===`Delete`||e.key===`Backspace`?(e.preventDefault(),a(i.filter(e=>e.id!==t)),b(null)):e.key===`Escape`&&b(null))}},n=e=>{let t=y.current.selected,n=e.target;t&&!n?.closest?.(`[data-ann-id="${CSS.escape(t)}"], [data-kymo-annotation-controls]`)&&b(null)};return e.addEventListener(`keydown`,t),e.addEventListener(`pointerdown`,n,!0),()=>{e.removeEventListener(`keydown`,t),e.removeEventListener(`pointerdown`,n,!0)}},[]);let{w:x,h:S}=d,C=e=>{let t=c.current.getBoundingClientRect();return[e.clientX-t.left,e.clientY-t.top]},w=(e,t)=>{let n=c.current.ownerDocument,r=t=>e(C(t),t),i=()=>{n.removeEventListener(`pointermove`,r),n.removeEventListener(`pointerup`,i),n.removeEventListener(`pointercancel`,i),t()};n.addEventListener(`pointermove`,r),n.addEventListener(`pointerup`,i),n.addEventListener(`pointercancel`,i)},T=e=>r([...y.current.annotations,e]),E=e=>r(y.current.annotations.map(t=>t.id===e.id?e:t)),D=e=>{if(!t||e.button!==0||h)return;e.preventDefault(),e.stopPropagation();let n=C(e),r={id:crypto.randomUUID(),kind:t.kind,color:t.color,width:t.width,...u?{anchor:`x`}:{}},i=e=>DZ(r,e,x,S,u);if(t.kind===`text`){v({...r,points:i([n]),text:``}),g(r.id);return}let a=t.kind===`brush`?[n]:[n,n],o={...r,points:i(a)};v(o);let s=!1;w((t,n)=>{if(s||=Math.hypot(n.clientX-e.clientX,n.clientY-e.clientY)>wZ,r.kind===`brush`){let e=a[a.length-1];if(Math.hypot(t[0]-e[0],t[1]-e[1])<2)return;a=[...a,t]}else a=[a[0],t];o={...o,points:i(a)},v(o)},()=>{v(null),s&&o.points.length>=2&&T(o)})},O=(e,t,n)=>{let r=EZ(t,x,S,u);if(!r)return;let i=C(e),a=null;w((o,s)=>{if(!a&&Math.hypot(s.clientX-e.clientX,s.clientY-e.clientY)<=wZ)return;let{size:c,frame:l}=y.current;a={...t,points:DZ(t,n(r,[o[0]-i[0],o[1]-i[1]],o),c.w,c.h,l)},v(a)},()=>{v(null),a&&E(a)})},k=(e,n)=>{t||e.button!==0||h===n.id||(e.preventDefault(),e.stopPropagation(),b(n.id),O(e,n,(e,[t,n])=>e.map(([e,r])=>[e+t,r+n])))},A=(e,t,n)=>{e.button===0&&(e.preventDefault(),e.stopPropagation(),O(e,t,(e,r,i)=>{let a=e.map(e=>[...e]);return t.kind===`arrow`?a[n]=i:(a[+(n===1||n===2)][0]=i[0],a[+(n===2||n===3)][1]=i[1]),a}))},j=e=>{t||e.kind!==`text`&&e.kind!==`box`||(b(e.id),g(e.id))},M=e=>{let t=h;g(null);let n=_&&_.id===t?_:null;if(v(null),e===null||!t)return;let i=e.replace(/\s+$/,``),a=y.current.annotations;if(n){i&&T({...n,text:i});return}let o=a.find(e=>e.id===t);o&&(!i&&o.kind===`text`?r(a.filter(e=>e.id!==t)):E(LZ(o,i)))},N=e=>{r(y.current.annotations.filter(t=>t.id!==e)),b(null)},P=(_?e.some(e=>e.id===_.id)?e.map(e=>e.id===_.id?_:e):[...e,_]:e).flatMap(e=>{let t=EZ(e,x,S,u);return t?[{a:e,px:t}]:[]}),F=p?P.find(e=>e.a.id===p):void 0,I=u?o.map(e=>{let t=EZ(Rt(e,u.x.v1),x,S,u);return{m:e,x0:Math.min(t[0][0],t[1][0]),x1:Math.max(t[0][0],t[1][0])}}):[],L=F&&F.a.kind!==`text`?IZ(F.px):null,R=e=>vt(_t,{children:[q(`svg`,{className:`kymo-ann-svg`,width:x,height:S,viewBox:`0 0 ${x} ${S}`,"aria-hidden":`true`,children:e.map(({a:e,px:t})=>e.kind===`text`?null:q(`g`,{"data-ann-id":e.id,className:`kymo-ann kymo-ann--${e.kind}`,onPointerDown:t=>k(t,e),onDoubleClick:()=>j(e),children:q(MZ,{a:e,px:t})},e.id))}),e.map(({a:e,px:t})=>{if(e.kind!==`text`&&e.kind!==`box`)return null;let n=h===e.id;if(!n&&!e.text)return null;let r=e.kind===`text`?{left:t[0][0],top:t[0][1]}:{left:Math.min(t[0][0],t[1][0]),top:Math.min(t[0][1],t[1][1]),transform:`translateY(calc(-100% - 3px))`};return vt(`div`,{"data-ann-id":e.id,className:`kymo-ann-text kymo-ann-text--${e.kind}${p===e.id&&e.kind===`text`?` is-selected`:``}`,style:{...r,color:e.color,fontSize:e.kind===`text`?e.width:12},onPointerDown:t=>k(t,e),onDoubleClick:()=>j(e),children:[n?q(jZ,{initial:e.text??``,onDone:M}):e.text,p===e.id&&e.kind===`text`&&!n?q(AZ,{onDelete:()=>N(e.id),style:{right:-11,top:-11}}):null]},`t-${e.id}`)})]});return q(`div`,{ref:c,className:`kymo-annotations${t?` is-drawing is-tool-${t.kind}`:``}`,onPointerDown:D,onContextMenu:t?e=>e.preventDefault():void 0,children:x>0&&S>0?vt(_t,{children:[u&&I.length?q(`div`,{className:`kymo-ann-clip`,style:{clipPath:`inset(0 ${Math.max(0,x-u.left-u.width)}px 0 ${Math.max(0,u.left)}px)`},children:q(`svg`,{className:`kymo-ann-svg kymo-marks`,width:x,height:S,viewBox:`0 0 ${x} ${S}`,children:I.map(({m:e,x0:t,x1:n})=>vt(`g`,{"data-mark":e.ruleId,role:`img`,"aria-label":`${e.ruleName}, ${e.severity}`,className:`kymo-mark kymo-mark--${e.severity}`,style:{color:Lt[e.severity]},children:[q(`rect`,{x:t,y:u.top,width:Math.max(1,n-t),height:u.height,fill:`currentColor`,fillOpacity:.12}),q(`rect`,{x:t,y:u.top,width:Math.max(1,n-t),height:2,fill:`currentColor`}),q(`rect`,{className:`kymo-mark-hit`,x:t,y:u.top,width:Math.max(6,n-t),height:8,onPointerDown:t=>{t.stopPropagation(),s?.(e.ruleId)}})]},e.id))})}):null,R(P.filter(e=>e.a.anchor!==`x`)),u?q(`div`,{className:`kymo-ann-clip`,style:{clipPath:`inset(0 ${Math.max(0,x-u.left-u.width)}px 0 ${Math.max(0,u.left)}px)`},children:R(P.filter(e=>e.a.anchor===`x`))}):null,vt(`svg`,{className:`kymo-ann-svg`,width:x,height:S,viewBox:`0 0 ${x} ${S}`,"aria-hidden":`true`,children:[L?q(`rect`,{className:`kymo-ann-selection`,x:L.x-6,y:L.y-6,width:L.w+12,height:L.h+12,rx:4}):null,F&&!h&&(F.a.kind===`box`||F.a.kind===`arrow`)?q(`g`,{"data-ann-id":F.a.id,children:NZ(F.a,F.px).map(([e,t],n)=>q(`rect`,{className:`kymo-ann-handle kymo-ann-handle--${F.a.kind===`arrow`?`end`:n%2?`nesw`:`nwse`}`,x:e-4.5,y:t-4.5,width:9,height:9,rx:2,onPointerDown:e=>A(e,F.a,n)},n))}):null]}),L&&!h?q(AZ,{onDelete:()=>N(F.a.id),id:F.a.id,style:{left:Math.min(x-12,L.x+L.w+6)-10,top:Math.max(10,L.y-6)-10}}):null]}):null})});function AZ({onDelete:e,style:t,id:n}){return q(`button`,{type:`button`,className:`kymo-ann-delete`,style:t,"data-ann-id":n,"aria-label":`Delete annotation`,title:`Delete (Del)`,onPointerDown:e=>e.stopPropagation(),onClick:e,children:q(`svg`,{viewBox:`0 0 10 10`,width:`8`,height:`8`,"aria-hidden":`true`,children:q(`path`,{d:`M2 2l6 6M8 2l-6 6`})})})}function jZ({initial:e,onDone:t}){let n=K(null),r=K(!1),i=e=>{r.current||(r.current=!0,t(e))};return G(()=>{let t=n.current;if(!t)return;t.textContent=e,t.focus();let r=t.ownerDocument.createRange();r.selectNodeContents(t);let i=t.ownerDocument.defaultView?.getSelection();i?.removeAllRanges(),i?.addRange(r)},[]),q(`div`,{ref:n,className:`kymo-ann-editor`,contentEditable:`plaintext-only`,suppressContentEditableWarning:!0,role:`textbox`,"aria-label":`Annotation text`,"aria-multiline":`true`,onPointerDown:e=>e.stopPropagation(),onKeyDown:e=>{e.stopPropagation(),e.key===`Enter`&&!e.shiftKey?(e.preventDefault(),i(n.current?.innerText??``)):e.key===`Escape`&&(e.preventDefault(),i(null))},onBlur:()=>i(n.current?.innerText??``)})}function MZ({a:e,px:t}){let n={stroke:e.color,strokeWidth:e.width,fill:`none`,strokeLinecap:`round`,strokeLinejoin:`round`},r=t=>q(`path`,{className:`kymo-ann-hit`,d:t,strokeWidth:Math.max(12,e.width+10)});switch(e.kind){case`box`:{let[[i,a],[o,s]]=t,c=`M${i} ${a}H${o}V${s}H${i}Z`;return vt(_t,{children:[r(c),q(`path`,{d:c,...n}),q(`path`,{d:c,fill:e.color,fillOpacity:.06,stroke:`none`,pointerEvents:`none`})]})}case`arrow`:{let[[i,a],[o,s]]=t,c=FZ(i,a,o,s,e.width);return vt(_t,{children:[r(`M${i} ${a}L${o} ${s}`),q(`path`,{d:`M${i} ${a}L${c.base[0]} ${c.base[1]}`,...n}),q(`path`,{d:c.d,fill:e.color,stroke:e.color,strokeWidth:1,strokeLinejoin:`round`})]})}case`brush`:{let e=PZ(t);return vt(_t,{children:[r(e),q(`path`,{d:e,...n})]})}}return null}function NZ(e,t){if(e.kind===`arrow`)return t;let[[n,r],[i,a]]=t;return[[n,r],[i,r],[i,a],[n,a]]}function PZ(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 FZ(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 IZ(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 LZ(e,t){if(t)return{...e,text:t};let{text:n,...r}=e;return r}function RZ(e){let t=e;return!!t&&(t.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName))}function zZ(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=EZ(i,n,r,o);t&&(e.save(),i.anchor===`x`&&o&&(e.beginPath(),e.rect(o.left,0,o.width,r),e.clip()),BZ(e,i,t,a),e.restore())}e.restore()}function BZ(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(PZ(n)));else if(t.kind===`arrow`){let r=FZ(n[0][0],n[0][1],n[1][0],n[1][1],t.width);e.beginPath(),e.moveTo(n[0][0],n[0][1]),e.lineTo(r.base[0],r.base[1]),e.stroke(),e.beginPath(),e.moveTo(n[1][0],n[1][1]),e.lineTo(r.l[0],r.l[1]),e.lineTo(r.r[0],r.r[1]),e.closePath(),e.fill()}if(!t.text)return;let i=t.kind===`text`?t.width:12;e.font=`600 ${i}px ${r}`,e.textBaseline=`top`;let a=t.text.split(`
|
|
614
|
-
`),o=i*1.25,s=n[0][0],c=n[0][1];t.kind===`box`&&(s=Math.min(n[0][0],n[1][0]),c=Math.min(n[0][1],n[1][1])-a.length*o-7),a.forEach((t,n)=>e.fillText(t,s+6,c+2+n*o))}var VZ={solid:void 0,dashed:`5 4`,dotted:`1 4`};function HZ(e,t,n){if(!e||!(n===`x`?e.x:e.y))return null;if(n===`x`){let n=$H(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=tU(e,t.value);return r>=e.top-.5&&r<=e.top+e.height+.5?[e.left,r,e.left+e.width,r]:null}var UZ=st(function({frame:e,alarm:t,axis:n}){let r=HZ(mt(e.subscribe,e.get),t,n);if(!r)return null;let i=t.linked?WZ(r,n):null;return vt(`svg`,{className:`kymo-alarm`,"aria-hidden":`true`,children:[q(`line`,{x1:r[0],y1:r[1],x2:r[2],y2:r[3],stroke:t.color,strokeWidth:t.width,strokeDasharray:t.linked===`active`?cU.join(` `):VZ[t.style]}),i?q(`path`,{"data-alert-glyph":``,d:sU,transform:`translate(${i[0]} ${i[1]})`,fill:t.color}):null]})});function WZ(e,t){return t===`y`?[e[2]-10-3,e[1]-10-2]:[e[0]+3,e[1]+2]}function GZ(e,t,n,r,i){let a=HZ(t,n,r);if(a){if(e.save(),e.scale(i,i),e.strokeStyle=n.color,e.lineWidth=n.width,e.setLineDash(n.linked===`active`?cU:VZ[n.style]?.split(` `).map(Number)??[]),e.beginPath(),e.moveTo(a[0],a[1]),e.lineTo(a[2],a[3]),e.stroke(),n.linked){let t=WZ(a,r);uU(e,t[0],t[1],n.color)}e.restore()}}function KZ(e,t,n){return e.handlers?.wsId===n?e.handlers:e.handlers={wsId:n,onViewXRangeChange:r=>{t.view.setXRange(r,n),e.emitter.emit(`viewchange`,r)},onCursorX:e=>{try{t.view.setCursorX(e,n)}catch{}},cursor:{get:()=>{try{return t.view.cursorX(n)}catch{return null}},subscribe:e=>t.on(`cursorchange`,t=>{t.worksheetId===n&&e(t.x)})},onContextMenu:t=>e.emitter.emit(`contextmenu`,t),xyzRef:t=>{e.xyz=t},onAnnotations:n=>t.charts.setAnnotations(e.chartId,n),onAnnotationToolEnd:()=>{e.annotationTool=null,ZZ(t).bump(),e.emitter.emit(`annotationtool`,null)},onAnnotationSelect:t=>{e.selectedAnnotation=t,e.emitter.emit(`annotationselect`,t)},onMarkSelect:t=>e.emitter.emit(`markselect`,t)}}var qZ=new WeakMap;function JZ(e,t){let n=qZ.get(e);n||qZ.set(e,n=new Map);let r=n.get(t);return r||n.set(t,r=n=>e.view.setLiveWindow(n,t)),r}var YZ=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=gt(document.createElement(`div`)),this.root.render(q(rQ,{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}},XZ=new WeakMap;function ZZ(e){let t=XZ.get(e);return t||(t=new YZ(e),XZ.set(e,t)),t}function QZ(e,t,n,r={}){e.charts.get(t);let i=ZZ(e),a={key:crypto.randomUUID(),chartId:t,element:n,options:r,shiftDatasetId:null,emitter:HV(),xyz:null,annotationTool:null,selectedAnnotation:null,plotFrame:iU(),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 ME(`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 ME(`export_failed`,{reason:`canvas unavailable`}));for(let e of r)o.drawImage(e,0,0);let s=e.charts.get(t),c=pQ(s.settings,h1(e).alertLines()),l=a.plotFrame.get()?.x?a.plotFrame.get():null,u=e.getState(),d=u.worksheets.find(e=>e.charts.some(e=>e.id===t)),f=gQ(s.annotations,d?mQ(u.marks,u.selection,d.xKey):[],l),p=nr(c);return p&&n.clientWidth>0&&GZ(o,a.plotFrame.get(),p.alarm,p.axis,i.width/n.clientWidth),f.length&&n.clientWidth>0&&zZ(o,f,n.clientWidth,n.clientHeight,i.width/n.clientWidth,Q.sans,l),new Promise((e,t)=>i.toBlob(n=>n?e(n):t(new ME(`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 $Z(e){XZ.get(e)?.refresh()}function eQ(e){XZ.get(e)?.dispose(),XZ.delete(e)}function tQ(e){let t=new MutationObserver(e);return t.observe(document.documentElement,{attributes:!0,attributeFilter:[`data-color-scheme`,`class`,`data-theme`]}),()=>t.disconnect()}var nQ=()=>{let e=document.documentElement;return`${e.getAttribute(`data-color-scheme`)??``}|${e.getAttribute(`data-theme`)??``}|${e.className}`};function rQ({engine:e,registry:t}){mt(t.subscribe,t.getVersion);let n=h1(e),r=mt(n.store.subscribe,n.store.get),i=new Map;for(let e of t.mounts.values()){let t=r.worksheets.find(t=>t.panels.some(t=>t.id===e.chartId));if(!t)continue;let n=i.get(t.id)??{worksheet:t,mounts:[]};n.mounts.push(e),i.set(t.id,n)}return q(_t,{children:[...i.values()].map(t=>q(sQ,{engine:e,worksheet:t.worksheet,mounts:t.mounts},t.worksheet.id))})}var iQ=1e3,aQ=.25;function oQ(e,t,n,r){let[i,a]=pt(0),o=K(0),s=K(0);return W(()=>{o.current&&=(s.current=performance.now()-o.current,0)}),W(()=>{if(!n)return;let i=0,c=-1,l=0,u=n=>{if(i=wH(u),o.current||n<l||kH()||!r())return;let d=0;for(let n of e)t.includes(n.id)&&(d+=n.source.version());d!==c&&(c=d,l=n+s.current*(1/aQ-1),o.current=performance.now(),ct(()=>a(e=>e+1)))};return i=wH(u),()=>TH(i)},[n,e,t]),ft(()=>n?e.map(e=>t.includes(e.id)?{...e,dataset:e.source.snapshot(iQ)}:e):e,[e,t,n,i])}function sQ({engine:e,worksheet:t,mounts:n}){let r=h1(e),i=mt(r.store.subscribe,r.store.get),a=r.derived(),o=i.xRanges[t.id]??null,s=ft(()=>i.live.filter(e=>e.kind===`data`),[i.live]),c=a.selectedLive.length,l=e=>{let n=t.panelChartSettings[e];return n?.kind===`multiband`&&n.beacon?.enabled===!0},u=c>0&&t.panels.some(e=>e.kind!==`multiband`&&e.kind!==`camera`||c>1&&!l(e.id)),d=K(n);d.current=n;let f=K(()=>d.current.some(e=>e.element.isConnected&&(typeof e.element.checkVisibility!=`function`||e.element.checkVisibility()))).current,p=oQ(s,i.selection,u,f),m=r.alertLines(),h=oZ({worksheet:dQ(t,m),viewXRange:o,selectedIds:i.selection,selectedDatasets:a.selectedDatasets,liveConnections:p,mathChannels:a.channels,datasetOffsets:i.offsets,datasetColors:i.colors,datasetPalette:i.palette}),g=K(BV()).current,_=mt(tQ,nQ),v=t.id,y=JZ(e,v),b=i.licensed,x=a.selectedLive[0]??null,S=e=>i.datasets.find(t=>t.id===e)??Object.values(a.laps).flatMap(e=>e.laps).find(t=>t.id===e);return q(_t,{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=KZ(n,e,v),l=pQ(t.panelChartSettings[r.id],m);return ht(q(bQ,{mount:n,annotations:t.panelChartSettings[r.id]?.annotations,marks:mQ(i.marks,i.selection,t.xKey),onMarkSelect:c.onMarkSelect,alarm:nr(l),onAnnotations:c.onAnnotations,onAnnotationToolEnd:c.onAnnotationToolEnd,onAnnotationSelect:c.onAnnotationSelect,render:u=>dZ({panel:r,settings:l,background:n.options.style?.background??t.panelChartBackgrounds[r.id]??null,styleToken:JSON.stringify([_,n.options.theme,n.options.style,Q]),data:h,xKey:t.xKey,height:u,viewXRange:o,onViewXRangeChange:c.onViewXRangeChange,onCursorX:c.onCursorX,liveZoom:g,liveWindowSeconds:t.liveWindowSeconds===void 0?i.liveWindowSeconds:t.liveWindowSeconds,onLiveWindowChange:y,beaconLive:x,findDataset:S,live:i.live,selection:i.selection,cursor:c.cursor,video:e.video.sources(),recordings:pX(a.selectedDatasets,i.offsets),shiftMode:s?cQ(e,s.id,s.name):void 0,onContextMenu:c.onContextMenu,xyzRef:c.xyzRef}),licensed:b},n.key),n.element,n.key)})})}function cQ(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 lQ=[],uQ=new WeakMap;function dQ(e,t){if(!t.size)return e;let n=uQ.get(e);if(n&&n.lines===t)return n.out;let r=!1,i={};for(let[n,a]of Object.entries(e.panelChartSettings))i[n]=pQ(a,t),i[n]!==a&&(r=!0);let a=r?{...e,panelChartSettings:i}:e;return uQ.set(e,{lines:t,out:a}),a}var fQ=new WeakMap;function pQ(e,t){if(!e||!t.size)return e;let n=fQ.get(e);if(n&&n.lines===t)return n.out;let r=er(e,t);return fQ.set(e,{lines:t,out:r}),r}var mQ=_Q((e,t,n)=>{let r=e.filter(e=>e.timeColumn===n&&t.includes(e.targetId));return r.length?r:hQ}),hQ=[];function gQ(e,t,n){return!t.length||!n?.x?e:[...t.map(e=>Rt(e,n.x.v1)),...e]}function _Q(e){let t=null,n;return(r,i,a)=>t&&t[0]===r&&t[1]===i&&t[2]===a?n:(t=[r,i,a],n=e(r,i,a),n)}function vQ(e,t){e.data=t}function yQ(e,t){e.status!==t&&(e.status=t,e.emitter.emit(`status`,t))}function bQ({mount:e,render:t,licensed:n,annotations:r,marks:i,alarm:a,onAnnotations:o,onAnnotationToolEnd:s,onAnnotationSelect:c,onMarkSelect:l}){let u=K(null),[d,f]=pt(0),p=!!e.options.debug,m=K({renderStart:0,lastRenderMs:0,renders:0,data:null}).current;p&&(m.renderStart=performance.now()),G(()=>{p&&(m.lastRenderMs=performance.now()-m.renderStart,m.renders++)}),G(()=>{let e=u.current;if(!e)return;let t=()=>f(Math.max(120,Math.floor(e.clientHeight)));t();let n=new AH(t);return n.observe(e),()=>n.disconnect()},[]);let{status:h,node:g,data:_}=t(d||400);m.data=_,W(()=>{vQ(e,_)}),W(()=>{yQ(e,h)});let{theme:v,style:y,className:b}=e.options,x={};return y?.background&&(x[`--chart-bg`]=y.background),y?.muted&&(x[`--chart-muted`]=y.muted),y?.grid&&(x[`--chart-grid`]=y.grid),y?.accent&&(x[`--accent`]=y.accent),vt(`div`,{ref:u,onContextMenu:h===`ready`?void 0:t=>{t.preventDefault(),e.emitter.emit(`contextmenu`,{clientX:t.clientX,clientY:t.clientY})},className:b?`kymo-chart ${b}`:`kymo-chart`,"data-color-scheme":v,"data-status":h,style:x,children:[q(aU.Provider,{value:e.plotFrame.set,children:g}),h===`ready`&&a?q(UZ,{frame:e.plotFrame,alarm:a.alarm,axis:a.axis}):null,h===`ready`&&(r?.length||e.annotationTool||i.length)?q(kZ,{annotations:r??lQ,tool:e.annotationTool,plotFrame:e.plotFrame,onChange:o,onToolEnd:s,onSelect:c,marks:i,onMarkSelect:l}):null,p?q(vZ,{stats:m,host:u}):null,n===!1?q(VV,{}):null]})}var xQ=new WeakMap;function SQ(e,t,n,r={}){let i=xQ.get(e)??new Map;xQ.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 ME(`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),yH(c);let m=n(p,r.mount),h=HV(),g=!1,_=()=>{g||(g=!0,i.delete(t),bH(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 CQ(e){for(let t of[...xQ.get(e)?.values()??[]])t.close()}function wQ(e,t,n=!1){let r=0,i=e.length;for(;r<i;){let a=r+i>>>1;(n?e[a]<=t:e[a]<t)?r=a+1:i=a}return r}function TQ(e,t,n){if(n<=t)return null;if(t===0&&n===e.t.length)return e;let r=e=>new Map([...e].map(([e,r])=>[e,r.subarray(t,n)])),i=r(e.lo);return{t:e.t.subarray(t,n),lo:i,hi:e.hi===e.lo?i:r(e.hi),level:e.level}}var EQ=(e,t,n)=>TQ(e,wQ(e.t,t),wQ(e.t,n,!0));function DQ(e,t,n,r){let i=[];for(let t of e){let e=TQ(t,0,wQ(t.t,n)),a=TQ(t,wQ(t.t,r,!0),t.t.length);e&&i.push(e),a&&i.push(a)}return[...i,...t]}var OQ=class{pieces;#e;#t;#n=new Map;#r=new Map;constructor(e,t={}){this.pieces=e.filter(e=>e.t.length>0).sort((e,t)=>e.t[0]-t.t[0]),this.#e=t;for(let e of this.pieces)for(let[t,n]of e.lo){let r=e.hi===e.lo?n:e.hi.get(t);if(!r)continue;let i=this.#n.get(t);i||this.#n.set(t,i=[]),i.push({t:e.t,L:n,H:r})}this.#t=[...this.#n.keys()].sort((e,t)=>e.localeCompare(t))}schemaSync(){return[{name:$e,type:`number`,unit:`s`},...this.#t.map(e=>({name:e,type:`number`,unit:this.#e[e]??``}))]}async getSchema(){return this.schemaSync()}async readColumns(e,t,n){let r=e.filter(e=>e===`ElapsedTime`||this.#n.has(e)),i=this.pieces.reduce((e,t)=>e+t.t.length,0),a=Math.max(0,Math.min(n,i-t)),o=Object.fromEntries(r.map(e=>[e,new Float64Array(a).fill(NaN)])),s=0;for(let e of this.pieces){let n=Math.max(0,t-s),i=Math.min(e.t.length,t+a-s);for(let a of r){let r=a===`ElapsedTime`?e.t:e.lo.get(a);r&&i>n&&o[a].set(r.subarray(n,i),s+n-t)}if(s+=e.t.length,s>=t+a)break}return o}getSeriesMultiSync(e,t,n){let{x0:r,x1:i}=t,a=t.xKey===`ElapsedTime`?e.filter(e=>this.#n.has(e)):[];if(!(i>r)||n<1||a.length===0)return{x0:r,bucket:0,rows:[],columns:a};let o=Math.floor(n),s=(i-r)/n,c=a.map(()=>new Float64Array(o).fill(1/0)),l=a.map(()=>new Float64Array(o).fill(-1/0));for(let e=0;e<a.length;e++){let t=c[e],n=l[e];for(let{t:c,L:l,H:u}of this.#n.get(a[e])){if(c[c.length-1]<r||c[0]>i)continue;let e=wQ(c,i,!0);for(let i=wQ(c,r);i<e;i++){let e=l[i];if(e!==e)continue;let a=Math.floor((c[i]-r)/s);a>=o&&(a=o-1),e<t[a]&&(t[a]=e),u[i]>n[a]&&(n[a]=u[i])}}}let u=[];for(let e=0;e<o;e++){let t=null;for(let n=0;n<a.length;n++)c[n][e]!==1/0&&(t??={b:e},t[`y${n}lo`]=c[n][e],t[`y${n}hi`]=l[n][e]);t&&u.push(t)}return{x0:r,bucket:s,rows:u,columns:a}}async getSeriesMulti(e,t,n){return this.getSeriesMultiSync(e,t,n)}async getSeries(e){let t=this.getSeriesMultiSync([e.column],e.viewport,e.maxPoints),n=t.rows.length,r={x:new Float64Array(n),min:new Float64Array(n),max:new Float64Array(n),first:new Float64Array(n),last:new Float64Array(n)};return t.rows.forEach((e,n)=>{r.x[n]=t.x0+(e.b+.5)*t.bucket,r.min[n]=r.first[n]=e.y0lo,r.max[n]=r.last[n]=e.y0hi}),r}xBoundsSync(e){let t=this.#r.get(e);if(t)return t;let n=1/0,r=-1/0;if(e===`ElapsedTime`)for(let e of this.pieces)n=Math.min(n,e.t[0]),r=Math.max(r,e.t[e.t.length-1]);for(let{L:t,H:i}of this.#n.get(e)??[])for(let e=0;e<t.length;e++)t[e]<n&&(n=t[e]),i[e]>r&&(r=i[e]);return t=n<=r?{x0:n,x1:r}:{x0:0,x1:0},this.#r.set(e,t),t}async xBounds(e){return this.xBoundsSync(e)}sampleRowsSync(e){let t=this.pieces.reduce((e,t)=>e+t.t.length,0),n=Math.max(1,Math.ceil(t/Math.max(1,e))),r=[],i=0,a=0;for(let e of this.pieces){let t=i-a;if(a+=e.t.length,!(t>=e.t.length))for(let a=t;a<e.t.length;a+=n,i+=n){let t={[$e]:e.t[a]};for(let[n,r]of e.lo){let e=r[a];t[n]=e===e?e:null}r.push(t)}}return r.sort((e,t)=>e[$e]-t[$e])}async dispose(){}},kQ=12e3,AQ=100;function jQ(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 c.add(n),n;for(let e=0;e<n.length;e++){let t=n[e];t-t!==0&&(n[e]=NaN)}return n}function MQ(e,t){let n=Object.keys(t.columns);if(n.length===0)throw new ME(`no_columns`);let r=t.columns[n[0]].length;if(n.some(e=>t.columns[e].length!==r))throw new ME(`column_length_mismatch`);let i=new Map(n.map(e=>[e,jQ(t.columns[e],t.transfer)])),a=NQ(e,t.name,i,t.units??{});if(t.bands){for(let e of Object.values(t.bands))if(e.lo.length!==r||e.hi.length!==r)throw new ME(`column_length_mismatch`);a.bands=Object.fromEntries(Object.entries(t.bands).map(([e,t])=>[e,{lo:Float64Array.from(t.lo),hi:Float64Array.from(t.hi)}]))}return a}function NQ(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,AQ);t++)e.push(o.map(e=>{let r=n.get(e)[t];return r===r?String(r):``}).join(`,`));d=e.join(`
|
|
615
|
-
`),f=te(d)}let p={id:e,name:t,schema:l,rawText:d,parseConfig:f,fromColumns:!0};if(s>1e6){let e=new
|
|
616
|
-
`))}return r}function zQ(e,t){let n=new OQ(t.pieces,t.units),r=n.schemaSync();return{id:e,name:t.name,kind:`columnar`,source:n,schema:r,data:{meta:``,columnNames:r.map(e=>e.name),units:r.map(e=>e.unit),rows:n.sampleRowsSync(kQ)}}}function BQ(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 VQ(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 HQ(){let e=VQ(e=>{let t={};for(let n of e){if(n.cut){let e=n.cut.defs.find(e=>e.id===n.cut.cycleId)?.show,r=e&&e.channel!==n.cut.timeKey?KB(e):null;t[n.id]=r?{laps:n.cut.parts,values:n.cut.found.map(e=>e.kpis?.[r]??null),unit:n.schema.find(t=>t.name===e.channel)?.unit??``,isTime:!1}:{laps:n.cut.parts,values:n.cut.found.map(e=>e.tend===null?null:e.tend-e.tstart),unit:`s`,isTime:!0};continue}if(!n.beacon||n.kind!==`memory`)continue;let{channel:e,metric:r,stat:i}=n.beacon,a=xB(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:kB(n.id,t),name:`${n.name} · Cycle ${t+1}`,data:r,source:new BE(r)}}),values:a.map(e=>TB(n.data.rows,e,r,i)),unit:o,isTime:i===`span`&&DB(r,o)}}return t}),t=VQ((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=VQ((e,t)=>e.filter(e=>e.kind===`data`&&t.includes(e.id))),r=VQ(e=>EX(e.map(e=>e.data))),i=VQ((e,t)=>t.length===0?e:EX(e?[e,...t.map(e=>e.dataset)]:t.map(e=>e.dataset))),a=VQ((e,t,n,r)=>{let i=new Set;if(e)for(let t of n.length>0?n:[e])for(let e of AX(t.columnNames,t.rows))i.add(e);for(let e of r)for(let t of e.dataset.columnNames)(t===`ElapsedTime`||e.source.hasValues(t))&&i.add(t);let a=e?e.columnNames.filter(e=>i.has(e)):[],o=t.filter(e=>e.kind!==`memory`).flatMap(e=>wz(e.schema));return[...new Set([...a,...o])]});return{lapsByDataset:e,selectedDatasets:t,selectedLive:n,staticDataset:r,mergedDataset:i,mergedParts:VQ((e,t)=>[...e.map(e=>e.data),...t.map(e=>e.dataset)]),numericColumns:VQ((e,t,n,r=[],i=[])=>{let o=a(e,t,r,i),s=new Set(o);return[...o,...n.map(e=>e.name).filter(e=>!s.has(e))]}),allColumns:VQ((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:VQ((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 UQ=[{kind:`multiband`,label:`Multi-band`},{kind:`xyscatter`,label:`X-Y scatter`},{kind:`xyzmesh`,label:`X-Y-Z mesh`},{kind:`histogram`,label:`Histogram`},{kind:`polar`,label:`Polar`},{kind:`spectrum`,label:`Spectrum`},{kind:`boxplot`,label:`Box Plot`},{kind:`spectrogram`,label:`Spectrogram`},{kind:`heatmap`,label:`Heatmap`},{kind:`violin`,label:`Violin`},{kind:`confusion`,label:`Confusion Matrix`},{kind:`roc`,label:`ROC Curve`},{kind:`losscurve`,label:`Loss Curves`},{kind:`controlchart`,label:`Control Chart`},{kind:`parallelcoords`,label:`Parallel Coords`},{kind:`embedding`,label:`Embedding`},{kind:`flamegraph`,label:`Flame Graph`},{kind:`barchart`,label:`Bar Chart`},{kind:`radar`,label:`Radar`},{kind:`areachart`,label:`Area Chart`},{kind:`cdfchart`,label:`CDF / ECDF`},{kind:`bubblechart`,label:`Bubble Chart`},{kind:`treemap`,label:`Treemap`},{kind:`sankey`,label:`Sankey`},{kind:`calibration`,label:`Calibration Curve`},{kind:`gauge`,label:`Gauges`},{kind:`camera`,label:`Camera`},{kind:`qqplot`,label:`Q-Q Plot`},{kind:`gantt`,label:`Gantt Chart`}],WQ=new Map(UQ.map(e=>[e.kind,e.label]));function GQ(e){return WQ.get(e)??e}var KQ=`kymoscope-live.v1`,qQ=2e3,JQ=3e4,YQ=30,XQ=1e4,ZQ=300,QQ=90,$Q=e=>e.startsWith(`eyJ`);function e$(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 t$(e,t){return`${e.replace(/\/+$/,``)}/v1/streams/${t}/watch`}function n$(e,t,n,r){let i=null,a=null,o=null,s=!1,c=0,l=()=>{o&&=(clearTimeout(o),null)},u=(n,r)=>{l();let a=e$(r);if(a===null)return;let c=$Q(r),d=c?Math.min(a,Date.now()/1e3+ZQ):a,f=Math.min(Math.max((d-(c?QQ:YQ))*1e3-Date.now(),XQ),2**31-1);o=setTimeout(async()=>{o=null;let r=null;try{r=await e.getToken(t)}catch{r=null}if(!(s||i!==n||!r)){try{n.send(JSON.stringify({type:`auth`,token:r}))}catch{return}u(n,r)}},f)},d=()=>{if(s||a)return;let e=Math.min(JQ,qQ*2**c++)*(.75+Math.random()/2);a=setTimeout(()=>{a=null,f()},e)},f=async()=>{if(s)return;let a=null;try{a=await e.getToken(t)}catch{a=null}if(s)return;if(!a){r?.(`error`),d();return}let o=new WebSocket(t$(e.url,t),[KQ,`bearer.${a}`]);o.binaryType=`arraybuffer`,i=o;let f=a;o.onopen=()=>{r?.(`subscribed`),u(o,f)},o.onmessage=e=>{c=0,typeof e.data!=`string`&&n(e.data)},o.onclose=()=>{i===o&&(i=null,l(),!s&&(r?.(`error`),d()))}};return f(),()=>{if(s=!0,a&&=(clearTimeout(a),null),l(),i){let e=i;i=null,e.close(1e3)}}}var r$=960*1024,i$=24;function a$(e){let t=e.key&&e.fragIndex===0?new TextEncoder().encode(e.codec):new Uint8Array;if(t.length>255)throw Error(`codec string too long`);let n=e.key&&e.fragIndex===0?1+t.length:0,r=new Uint8Array(i$+n+e.payload.length),i=new DataView(r.buffer);i.setUint8(0,1),i.setUint8(1,!!e.key|(e.last?2:0)),i.setUint8(2,1),i.setUint8(3,0),i.setFloat64(4,e.t,!0),i.setUint32(12,e.seq>>>0,!0),i.setUint16(16,e.fragIndex,!0),i.setUint16(18,e.fragCount,!0),i.setUint16(20,e.width,!0),i.setUint16(22,e.height,!0);let a=i$;return n&&(r[a++]=t.length,r.set(t,a),a+=t.length),r.set(e.payload,a),r}function o$(e){if(e.length<i$||e[0]!==1||e[2]!==1)return null;let t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=(e[1]&1)!=0,r=t.getUint16(16,!0),i=t.getUint16(18,!0);if(i===0||r>=i)return null;let a=i$,o=``;if(n&&r===0){if(e.length<a+1||e.length<a+1+e[a])return null;o=new TextDecoder().decode(e.subarray(a+1,a+1+e[a])),a+=1+e[a]}return{key:n,last:(e[1]&2)!=0,t:t.getFloat64(4,!0),seq:t.getUint32(12,!0),fragIndex:r,fragCount:i,width:t.getUint16(20,!0),height:t.getUint16(22,!0),codec:o,payload:e.subarray(a)}}function s$(e){let t=Math.max(1,Math.ceil(e.data.length/r$)),n=[];for(let r=0;r<t;r++)n.push(a$({key:e.key,last:r===t-1,t:e.t,seq:e.seq,fragIndex:r,fragCount:t,width:e.width,height:e.height,codec:e.codec,payload:e.data.subarray(r*r$,Math.min(e.data.length,(r+1)*r$))}));return n}var c$=class{samples=[];exact=!1;windowS;constructor(e=30){this.windowS=e}observe(e,t){if(e>1e9){this.samples=[],this.exact=!0;return}this.exact=!1;let n=t-e,r=this.samples[this.samples.length-1];for(r&&Math.abs(n-r.off)>1&&(this.samples=[]),this.samples.push({at:t,off:n});this.samples.length&&this.samples[0].at<t-this.windowS;)this.samples.shift()}quality(){return this.exact?`exact`:this.samples.length?`approx`:`none`}toWall(e,t=0){if(this.exact)return e+t/1e3;if(!this.samples.length)return null;let n=1/0;for(let e of this.samples)n=Math.min(n,e.off);return e+n+t/1e3}toStream(e,t=0){let n=this.toWall(0,t);return n===null?null:e-n}},l$=class{#e;constructor(e){this.#e=typeof e==`function`?e:()=>e}size(){return this.#e().size}get columnNames(){return this.#e().columnNames}version(){return this.#e().version}columns(){let e=this.#e();return new u$(new Set(e.columnNames),t=>e.mirrorColumn(t))}hasValues(e){return this.#e().hasValues(e)}snapshot(e){return this.#e().toDataset(e)}async getSchema(){let e=this.#e();return e.columnNames.map(t=>({name:t,type:`number`,unit:e.unitOf(t)}))}async getSeries(e){let t=this.#e();return a(t.columnValues(e.viewport.xKey),t.columnValues(e.column),e.viewport.x0,e.viewport.x1,e.maxPoints)}async getSeriesMulti(e,t,n){return this.getSeriesMultiSync(e,t,n)}getSeriesMultiSync(e,t,n){return this.#e().decimateColumns(t.xKey,e,t.x0,t.x1,n)}getPointsSync(e,t,n){return this.#e().decimatePoints(t.xKey,e,t.x0,t.x1,n)}async xBounds(e){return this.xBoundsSync(e)}xBoundsSync(e){return this.#e().columnBounds(e)}xTravelSync(e,t){return this.#e().xTravel(e,t)}latestTimeSync(){return this.#e().latestTime()}xAtTimeSync(e,t,n=!1){return this.#e().xAtTime(e,t,n)}latestSync(e){return this.#e().lastValue(e)}latestValuesSync(e){let t=this.#e(),n=new Map;for(let r of e){let e=t.lastValue(r),i=t.lastKnown(r);Number.isFinite(e)?n.set(r,e):i&&n.set(r,i.v)}return n}valueBoundsSync(e){let t=this.#e().valueBounds(e),n=this.#e().lastKnown(e);if(!t&&!n)return null;let r=Math.min(t?.x0??1/0,n?.v??1/0),i=Math.max(t?.x1??-1/0,n?.v??-1/0);if(r!==i)return{min:r,max:i};let a=Math.max(.5,Math.abs(r)*.05);return{min:r-a,max:i+a}}lastKnownSync(e){return this.#e().lastKnown(e)}trackCycles(e){this.#e().trackCycles(e)}cycleSpanSync(e){return this.#e().cycleSpan(e)}decimateCycleSync(e,t,n,r,i){return this.#e().decimateCycle(e,t,n,r.x0,r.x1,i)}cyclePointsSync(e,t,n,r,i){return this.#e().decimateCyclePoints(e,t,n,r.x0,r.x1,i)}async readColumns(e,t,n){let r=this.#e(),i=new Set(r.columnNames),a={};for(let o of e)i.has(o)&&(a[o]=r.columnValues(o).slice(t,t+n));return a}async dispose(){}},u$=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)}},d$=4096,f$=5e3,p$=class{startedAt=Date.now();n=0;capacity=d$;time=new Float64Array(d$);cols=new Map;order=[];units=new Map;timeColumn;timeUnit;constructor(e=$e,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=Ze(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(m$).join(`,`)}\n${t.map(m$).join(`,`)}\n`],r=this.order.map(e=>this.cols.get(e));for(let e=0;e<this.n;e+=f$){let t=Math.min(this.n,e+f$),i=``;for(let n=e;n<t;n++){i+=String(this.time[n]);for(let e of r){let t=e[n];i+=Number.isNaN(t)?`,`:`,${t}`}i+=`
|
|
617
|
-
`}n.push(i)}return n}};function m$(e){let t=/^[=+\-@\t\r]/.test(e)?`'${e}`:e;return/[",\n\r]/.test(t)?`"${t.replace(/"/g,`""`)}"`:t}var h$=512,g$=new WeakMap;function _$(e,t,n){let r=g$.get(e);r||g$.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 v$(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=tE(n.formula);if(!o.ok)continue;let{identifiers:s,functions:c}=nE(o.node);if(!s.every(e=>a.has(e)))continue;let l=c.some(e=>$T.includes(e)),u=Math.max(e.firstAbs,i-(l?h$:0)),d=new Map([$e,...s].map(t=>[t,e.range(t,u,r)])),{carry:f,keep:p}=_$(e,`${n.id}|${n.formula}`,u),m=cE(n,e=>d.get(e),$e,r-u,t,f);m.status===`ok`&&(e.writeComputed(n.name,n.units,i,m.values.subarray(i-u)),p())}}function y$(e,t){e.clearComputed(),g$.delete(e),v$(e,t,e.firstAbs)}var b$=8e3,x$=131072;function S$(e,t={}){switch(e.kind){case`elapsed`:return{name:`Elapsed`,unit:`s`};case`event`:return{name:`Since ${e.channel} ${e.op} ${e.value}`,unit:`s`};case`clock`:return{name:`Time of day`,unit:`s`};default:{let n=t[e.channel]??``;return e.integral?{name:`∫${e.channel}`,unit:n?`${n}·s`:`s`}:{name:`${e.channel} since start`,unit:n}}}}var C$=new Map;function w$(e,t){let n=`${t}|${Math.floor(e/900)}`,r=C$.get(n);r===void 0&&(r=mB(e,t),C$.size>1e4&&C$.clear(),C$.set(n,r));let i=(e+r)%86400;return i<0?i+86400:i}var T$=class{axis;#e=NaN;#t=NaN;#n=NaN;#r=0;#i=NaN;#a=NaN;constructor(e){this.axis=e}begin(e){this.#e=e,this.#t=NaN,this.#n=NaN,this.#r=0,this.#i=NaN,this.#a=NaN}x(e,t){let n=this.axis;return n.kind===`clock`?w$(e,n.tz):n.kind===`elapsed`?e-this.#e:e<this.#e?NaN:n.kind===`event`?(this.#t!==this.#t&&t===t&&cB(n.op,t,n.value)&&(this.#t=e),e-this.#t):n.integral?(t===t&&(this.#i===this.#i&&(this.#r+=(t+this.#i)/2*(e-this.#a)),this.#i=t,this.#a=e),this.#i===this.#i?this.#r:NaN):(t===t&&(this.#n!==this.#n&&(this.#n=t),this.#i=t),this.#i===this.#i?this.#i-this.#n:NaN)}};function E$(e,t,n,r){let i=`channel`in r?t.get(r.channel):void 0;if(r.kind===`event`){let a=NaN;for(let t=0;t<e.length&&a!==a;t++){let o=i?i[t]:NaN;e[t]>=n&&o===o&&cB(r.op,o,r.value)&&(a=e[t])}return{x:e.map(e=>e-a),t:e,cols:t}}let a=new T$(r);a.begin(n);let o=new Float64Array(e.length);for(let t=0;t<e.length;t++)o[t]=a.x(e[t],i?i[t]:NaN);return{x:o,t:e,cols:t}}function D$(e,t,n){let r=[];for(let n=0;n<e.length;n++)e[n]===e[n]&&t[n]===t[n]&&r.push(n);let i=!0;for(let t=1;t<r.length&&i;t++)i=e[r[t-1]]<=e[r[t]];i||r.sort((t,n)=>e[t]-e[n]);let a=r.length,o=new Float64Array(n.length).fill(NaN);if(a<2)return o;let s=Float64Array.from(r,t=>e[t]),c=Float64Array.from(r,e=>t[e]),l=Float64Array.from({length:a-1},(e,t)=>s[t+1]-s[t]).sort(),u=l[l.length>>1],d=u>0?4*u:1/0,f=0;for(let e=0;e<n.length;e++){let t=n[e];if(!(t>=s[0]&&t<=s[a-1]))continue;for(;f<a-2&&s[f+1]<t;)f++;let r=s[f],i=s[f+1];i-r>d||(o[e]=i===r?c[f]:c[f]+(c[f+1]-c[f])*(t-r)/(i-r))}return o}function O$(e,t,n){let r=e.length;if(r===0||!(n>=e[0]&&n<=e[r-1]))return NaN;if(r===1)return t[0];let i=(n-e[0])/(e[r-1]-e[0])*(r-1),a=Math.min(r-2,Math.floor(i));return t[a]+(t[a+1]-t[a])*(i-a)}function k$(e,t,n){let r=Math.max(2,Math.min(b$,Math.floor(n)));if(r*t.length>131072)throw Error(`too_many_cells`);let i=1/0,a=-1/0;for(let t of e)for(let e of t.x)e===e&&(e<i&&(i=e),e>a&&(a=e));if(!(a>i))throw Error(`empty`);let o=Float64Array.from({length:r},(e,t)=>i+t*(a-i)/(r-1)),s=new Map;for(let n of t){let t=new Uint16Array(r),i=new Float64Array(r),a=new Float64Array(r),c=new Float32Array(r).fill(1/0),l=new Float32Array(r).fill(-1/0);for(let s of e){let e=s.cols.get(n);if(!e)continue;let u=D$(s.x,e,o);for(let e=0;e<r;e++){let n=u[e];if(n!==n)continue;let r=++t[e],o=n-i[e];i[e]+=o/r,a[e]+=o*(n-i[e]),n<c[e]&&(c[e]=n),n>l[e]&&(l[e]=n)}}let u={mean:new Float32Array(r),sd:new Float32Array(r),min:c,max:l,n:t};for(let e=0;e<r;e++){if(t[e]===0){u.mean[e]=u.sd[e]=u.min[e]=u.max[e]=NaN;continue}u.mean[e]=i[e],u.sd[e]=t[e]>1?Math.sqrt(a[e]/(t[e]-1)):0}s.set(n,u)}return{x:o,channels:s}}function A$(e,t){if(e.unit===`abs`)return e.tolerance;let n=1/0,r=-1/0;for(let e of t.mean)e===e&&(e<n&&(n=e),e>r&&(r=e));return r>=n?Math.max(r-n,Math.abs(r),Math.abs(n))*e.tolerance/100:0}var j$=new WeakMap;function M$(e){let t=j$.get(e);if(t)return t;let n=e.sd.length,r=Math.max(2,Math.round(n/100));t=new Float32Array(n).fill(NaN);for(let i=0;i<n;i++){if(e.n[i]<2)continue;let a=0,o=0;for(let t=Math.max(0,i-r);t<=Math.min(n-1,i+r);t++)e.n[t]>=2&&e.sd[t]===e.sd[t]&&(a+=e.sd[t]**2,o++);t[i]=o?Math.sqrt(a/o):NaN}return j$.set(e,t),t}function N$(e,t,n){if(n===`minmax`)return{lo:e.min,hi:e.max};if(n===`sigma`){let n=M$(e);return{lo:e.mean.map((e,r)=>e-t*n[r]),hi:e.mean.map((e,r)=>e+t*n[r])}}let r=A$(n,e);return{lo:e.mean.map(e=>e-r),hi:e.mean.map(e=>e+r)}}function P$(e,t,n,r=`sigma`,i=0){let a=typeof r==`function`?r:()=>({band:r,k:n}),o=[...t.channels.keys()],s=new Map,c=new Map,l=[],u=new Uint8Array(e.t.length),d=o.map(()=>new Uint8Array(e.t.length)),f=t.x.length;o.forEach((n,r)=>{let i=t.channels.get(n),o=e.cols.get(n);if(!o)return;let{band:p,k:m}=a(n),h=typeof p==`object`?p:null,{lo:g,hi:_}=N$(i,m,p),v=0,y=0,b=0;for(let e of i.mean)if(e===e){v++;let t=e-y;y+=t/v,b+=t*(e-y)}let x=v>1?Math.max(Math.sqrt(b/(v-1)),1e-9):1e-9,S=h?Math.max(A$(h,i),1e-9):0,C=M$(i),w=new Float64Array(e.t.length).fill(NaN),T=new Float64Array(e.t.length).fill(NaN),E=0,D=0;for(let n=0;n<e.t.length;n++){let a=o[n],s=e.x[n];if(a!==a||s!==s)continue;let c=O$(t.x,i.mean,s);if(c!==c)continue;w[n]=a-c;let l=Math.round((s-t.x[0])/(t.x[f-1]-t.x[0])*(f-1));T[n]=Math.abs(a-c)/(h?S:i.n[l]>=2&&C[l]===C[l]?Math.max(C[l],1e-9):x),E+=T[n],D++,(h||i.n[l]>=2)&&(a<O$(t.x,g,s)||a>O$(t.x,_,s))&&(u[n]=1,d[r][n]=1)}s.set(n,w),c.set(n,T),l.push({channel:n,z:D?E/D:0})}),l.sort((e,t)=>t.z-e.z);let p=[];for(let t=0;t<u.length;t++){if(!u[t])continue;let n=t;for(;n<u.length&&u[n];)n++;let r=p[p.length-1];r&&e.t[t]-e.t[Math.min(r[1],u.length-1)]<i?r[1]=n:p.push([t,n]),t=n}let m=[];for(let[t,n]of p){let r=e.t[t],a=e.t[Math.min(n,u.length-1)];a-r>=i&&m.push({t0:r,t1:a,channels:o.filter((e,r)=>d[r].subarray(t,n).includes(1))})}return{delta:s,score:l,deviations:m,z:c}}function F$(e,t){let n=e.x.length,r=t.length,i=new DataView(new ArrayBuffer(12+8*n+r*n*18));[75,82,66,49].forEach((e,t)=>i.setUint8(t,e)),i.setUint32(4,n,!0),i.setUint32(8,r,!0);let a=12;for(let t=0;t<n;t++,a+=8)i.setFloat64(a,e.x[t],!0);for(let r of t){let t=e.channels.get(r);if(!t)throw Error(`The reference has no channel ${r}`);for(let e of[t.mean,t.sd,t.min,t.max])for(let t=0;t<n;t++,a+=4)i.setFloat32(a,e[t],!0);for(let e=0;e<n;e++,a+=2)i.setUint16(a,t.n[e],!0)}return Ge(new Uint8Array(i.buffer))}function I$(e,t){let n=Te(e),r=new DataView(n.buffer,n.byteOffset,n.byteLength);if(n.length<12||String.fromCharCode(n[0],n[1],n[2],n[3])!==`KRB1`)throw Error(`Not a reference band`);let i=r.getUint32(4,!0),a=r.getUint32(8,!0);if(a!==t.length||n.length!==12+8*i+a*i*18)throw Error(`This reference band does not match its channels`);let o=12,s=new Float64Array(i);for(let e=0;e<i;e++,o+=8)s[e]=r.getFloat64(o,!0);let c=new Map;for(let e of t){let t=()=>{let e=new Float32Array(i);for(let t=0;t<i;t++,o+=4)e[t]=r.getFloat32(o,!0);return e},n=t(),a=t(),s=t(),l=t(),u=new Uint16Array(i);for(let e=0;e<i;e++,o+=2)u[e]=r.getUint16(o,!0);c.set(e,{mean:n,sd:a,min:s,max:l,n:u})}return{x:s,channels:c}}var L$=` Δ`,R$=class{#e;constructor(e){this.#e=new PB(e)}assumeOpen(e){}feed(e,t,n){let r=[];for(let i=0;i<e.length;i++)this.#e.step(e[i],e=>{let n=t(e);return n?n[i]:NaN},r),n?.(i,this.#e.open()?.tstart??null);return r.map(e=>({tstart:e.tstart,tend:e.tend,kpis:{duration:(e.tend??e.tstart)-e.tstart},...e.flags.length?{flags:e.flags}:{}}))}};function z$(e){if(!e.cycle&&!e.rule)throw Error(`a live segment axis needs a rule or a cycle rule`);let t=e.cycle?new R$(e.cycle):new yB(e.rule,e.kpis??[]),n=new T$(e.axis),r=NaN;e.start!=null&&(t.assumeOpen(e.start),n.begin(e.start),r=e.start);let i=e.reference??null,a=i?[...i.channels]:[],o=i?i.grid.length:0,s=`channel`in e.axis?e.axis.channel:null,c=[...new Set([...e.cycle?NB(e.cycle):sB(e.rule),...(e.kpis??[]).map(e=>e.channel),...s?[s]:[],...a.map(([e])=>e)])],l=e.minDeviationS??5,u=NaN,d=NaN,f=NaN,p=new Set,m=!1,h=e=>{m&&e({type:`deviation-end`,t0:u,t1:d,channels:[...p]}),u=d=f=NaN,p=new Set,m=!1};return{feed(g,_,v=!1){let y=Math.max(_,g.firstAbs),b=g.endAbs;if(y>=b)return;let x=t=>{v||e.onEvent?.(t)},S=g.range($e,y,b),C=new Map(c.map(e=>[e,g.range(e,y,b)])),w=new Float64Array(S.length).fill(NaN),T=a.map(([e,t])=>({name:e,b:t,v:C.get(e),d:new Float64Array(S.length).fill(NaN)})),E=s?C.get(s):null,D=t.feed(S,e=>C.get(e),(e,t)=>{if(t===null)return;t!==r&&(h(x),r=t,n.begin(t),x({type:`open`,tstart:t}));let a=n.x(S[e],E?E[e]:NaN);if(w[e]=a,!i||a!==a)return;let s=o>1?Math.round((a-i.grid[0])/(i.grid[o-1]-i.grid[0])*(o-1)):0,c=!1;for(let t of T){let n=t.v[e],r=O$(i.grid,t.b.mean,a);n!==n||r!==r||(t.d[e]=n-r,t.b.n[s]>=2&&(n<O$(i.grid,t.b.lo,a)||n>O$(i.grid,t.b.hi,a))&&(c=!0,p.add(t.name)))}c?(u!==u&&(u=S[e]),d=S[e],f=NaN,!m&&S[e]-u>=l&&(m=!0,x({type:`deviation`,t0:u,channels:[...p]}))):u===u&&(f!==f&&(f=S[e]),S[e]-f>=l&&h(x))});for(let e of D)x({type:`close`,segment:e});g.writeComputed(e.column,e.unit,y,w);for(let e of T)g.writeComputed(`${e.name} Δ`,g.unitOf(e.name),y,e.d)}}}var B$=1e7;function V$(e=globalThis.navigator?.deviceMemory){return Math.max(512,Math.round(((e??0)>0?e:16)*1024/8))}var H$=400,U$=4e3,W$=1e3,G$=3e3,K$=2,q$=5e3,J$=1e4;function Y$(e,t,n=`data`){let r=new oe(t.capacity??B$,void 0,void 0,(t.maxMemoryMB??V$())*1024*1024);return{meta:e,buffer:r,source:new l$(()=>r),unsub:()=>{},status:`connecting`,error:null,lastFrameAt:Date.now(),lastColCount:0,lastValued:0,recorder:null,schemas:new Map,video:n===`camera`?new jE:null,clock:n===`camera`?null:new c$,lagTicks:0,lastRejoinAt:0,rejoin:()=>{},subscribed:!1,releaseTimer:void 0}}function X$(e,t,n=()=>({}),r){let i=new Map,a=e,o=[],s=[],c=``,l=()=>{let e=[];for(let t of i.values())t.lastColCount=t.buffer.columnNames.length,t.lastValued=t.buffer.valuedCount,e.push({...t.meta,kind:t.video?`camera`:`data`,video:t.video,clock:t.clock,dataset:t.buffer.toDataset(H$),source:t.source,rowCount:t.buffer.size,status:t.status,error:t.error,recordingSince:t.recorder?.startedAt??null});o=e,t(o)},u=(e,t)=>{let n=!1,r=e.buffer.endAbs;for(let r of t)r&&typeof r.t==`number`&&Array.isArray(r.signals)&&(e.buffer.push(r),e.recorder?.add(r),n=!0);n&&f(e,r,t[t.length-1]?.t)},d=(e,t)=>{let n=e.buffer.endAbs;e.buffer.pushColumns(t),e.recorder?.addColumns(t),t.t.length>0&&f(e,n,t.t[t.t.length-1])},f=(e,t,n)=>{v$(e.buffer,s,t),e.segAxis?.tracker.feed(e.buffer,t),r?.rows(e.meta.id,e.buffer,t),typeof n==`number`&&e.clock?.observe(n,Date.now()/1e3),p(e,t===0||e.buffer.columnNames.length!==e.lastColCount||e.buffer.valuedCount!==e.lastValued)},p=(e,t)=>{e.lastFrameAt=Date.now();let n=e.status===`stale`||e.status===`connecting`;n&&(e.status=`live`),(n||t)&&l()},m=e=>{let t=i.get(e);t&&(clearTimeout(t.releaseTimer),t.unsub(),i.delete(e),l())},h=setInterval(()=>{let e=Date.now(),t=!1;for(let n of i.values()){n.status===`live`&&e-n.lastFrameAt>U$&&(n.status=`stale`,t=!0);let i=n.video&&n.subscribed&&n.status===`live`?n.video.info().lagMs:null;n.lagTicks=i!==null&&i>G$?n.lagTicks+1:0,n.video&&n.lagTicks>=K$&&e-n.lastRejoinAt>=q$&&(n.lagTicks=0,n.lastRejoinAt=e,n.video.resync(),n.unsub(),n.rejoin()),n.buffer.size&&r?.tick(n.meta.id,n.buffer,n.lastFrameAt)}t&&l()},W$);return{connections:()=>o,disconnect:m,startRecording(e){let t=i.get(e);!t||t.recorder||(t.recorder=new p$,l())},stopRecording(e){let t=i.get(e),n=t?.recorder;return!t||!n?null:(t.recorder=null,l(),{csv:n.toCsvParts(),rows:n.rows,name:t.meta.name,startedAt:n.startedAt})},setRelay(e){a=e},setSegmentAxis(e,t){let n=i.get(e);n&&(n.segAxis=t?{cfg:t,tracker:z$(t)}:void 0,t&&n.segAxis.tracker.feed(n.buffer,n.buffer.firstAbs,!t.replay),l())},setMathChannels(e){let t=JSON.stringify(e.map(e=>[e.id,e.name,e.units,e.formula,e.enabled]));if(t!==c){c=t,s=e;for(let t of i.values())t.video||(y$(t.buffer,e),t.segAxis&&(t.segAxis.tracker=z$(t.segAxis.cfg),t.segAxis.tracker.feed(t.buffer,t.buffer.firstAbs,!0)));i.size>0&&l()}},openLocal(e,t){let r=`local:${crypto.randomUUID()}`,a=Y$({id:r,name:e,ownerName:`This page`,visibility:`private`,orgName:null,parentId:null,lowOf:null},{...n(),...t});return i.set(r,a),l(),{id:r,push:e=>{i.get(r)===a&&u(a,Array.isArray(e)?e:[e])},pushColumns:e=>{i.get(r)===a&&d(a,e)},close:()=>m(r)}},async connect(e,t,r){if(i.has(e.id))return;let o=a&&e.relay_url?{...a,url:e.relay_url}:a;if(!o)throw new ME(`relay_unavailable`);let s=typeof t==`string`?await _(Ee(t).secret??t,e.salt):`keyFor`in t?e=>t.keyFor(e):t;if(typeof s!=`function`&&!await Fe(s,e.key_check))throw new ME(`wrong_password`);let c=Y$({id:e.id,name:e.name,ownerName:e.owner_name??``,visibility:e.visibility??`private`,orgName:e.org_name??null,projectName:e.project_name??null,parentId:e.parent_stream_id??null,lowOf:e.low_of_stream_id??null,limitNotice:e.limit_notice??null},{...n(),...r},e.kind);i.set(e.id,c);let f=Promise.resolve();c.rejoin=()=>{c.unsub=n$(o,e.id,t=>{let n=he(s,t).catch(()=>null);f=f.then(async()=>{try{let t=await n;if(!t||i.get(e.id)!==c)return;if(t.kind===6){let e=o$(t.plaintext);e&&c.video&&(c.video.push(e),p(c,!1));return}if(t.kind===5){let e=pe(t.plaintext);c.schemas.set(e.id,e);return}if(t.kind===7){let e=Pe(t.plaintext,c.schemas);if(!e)return;let n=c.buffer;for(let t of e)n.setLastKnown(t.name,t.unit,t.t,t.v);(n.columnNames.length!==c.lastColCount||n.valuedCount!==c.lastValued)&&l();return}if(t.kind===4){let e=await le(t.plaintext,c.schemas);e&&!e.historical&&d(c,e.block);return}if(t.kind===3)return d(c,De(t.plaintext));if(t.kind!==2)return;let r=qe(t.plaintext);u(c,Array.isArray(r?.frames)?r.frames:[])}catch{}})},t=>{!c.subscribed||i.get(e.id)!==c||(t===`subscribed`?(c.status=`live`,c.lastFrameAt=Date.now()):t===`error`&&(c.status=`error`,c.error=`connection_error`),l())})};let m=c.video;m?(c.status=`idle`,m.onDemandChange(t=>{i.get(e.id)===c&&(clearTimeout(c.releaseTimer),t?c.subscribed||(c.subscribed=!0,m.resync(),c.status=`connecting`,c.lastFrameAt=Date.now(),c.rejoin(),l()):c.releaseTimer=setTimeout(()=>{c.subscribed=!1,c.unsub(),c.unsub=()=>{},c.status=`idle`,c.error=null,c.lagTicks=0,l()},J$))})):(c.subscribed=!0,c.rejoin()),l()},dispose(){clearInterval(h);for(let e of i.values())clearTimeout(e.releaseTimer),e.unsub();i.clear(),o=[]}}}var Z$=500,Q$=1<<20;function $$(e){let t=[],n=new Map,r=[],i=``,a=(e,t)=>`${e}|${t}`,o=(e,t)=>{let n=t.kind===`stream`?e.targets?.streams:t.kind===`history`?e.targets?.histories:e.targets?.datasets;return!n||n.includes(t.kind===`dataset`?t.name??t.id:t.id)},s=()=>[...n.values()].map(e=>{let{state:t,missing:n,since:r}=e.state();return{ruleId:e.rule.id,target:e.target,state:t,...n?{missing:n}:{},...r===void 0?{}:{since:r}}}),c=()=>{let t=s(),n=JSON.stringify(t);n!==i&&(i=n,e.setStates(t))};function l(n,i){let a=t.find(e=>e.id===n.ruleId);if(n.kind===`raised`){r=[...r,{id:`${n.ruleId}|${n.target.id}|${n.t}`,ruleId:n.ruleId,ruleName:a?.name??``,severity:a?.severity??`info`,targetId:n.target.id,timeColumn:i,t0:n.t,t1:null}];let e=r.filter(e=>e.targetId===n.target.id);e.length>Z$&&(r=r.filter(t=>t!==e[0]))}else{let e=r.find(e=>e.ruleId===n.ruleId&&e.targetId===n.target.id&&e.t1===null);e&&(r=r.map(t=>t===e?{...t,t1:n.t}:t))}e.setMarks(r),e.emit(n)}function u(){let r=new Set;for(let i of e.targets())for(let e of t){if(!o(e,i))continue;let t=a(e.id,i.id);r.add(t);let s=n.get(t),{channels:c,...u}=i;(!s||s.rule!==e)&&(s=tt(e,u),n.set(t,s));for(let e of s.bind(c))l(e,i.kind===`stream`?$e:``)}for(let e of n.keys())r.has(e)||n.delete(e);c()}return{setRules(n){let r=[],i=n.filter(e=>{let t=nt(e);return r.push(...t.map(t=>({ruleId:String(e?.id??``),...t}))),!t.length}),a=e.maxRules();a!==null&&i.length>a&&e.limit();let o=new Map(t.map(e=>[e.id,e]));return t=(a===null?i:i.slice(0,a)).map(e=>{let t=o.get(e.id);return t&&t.version===e.version?t:e}),u(),r},rules:()=>t,state:s,async evaluate(n,i){let a=e.targets().find(e=>e.id===n&&e.kind===`dataset`);if(!a)return[];let{channels:s,...c}=a,u=[],d=t.filter(e=>(!i.ruleIds||i.ruleIds.includes(e.id))&&o(e,c)),f=d.map(e=>{let t=tt(e,c);return t.bind(s),t}),p=[...new Set(d.flatMap(e=>Object.values(e.signals).map(e=>`formula`in e?e.formula:e.channel)))];for(let t=0;;t+=Q$){let r=await e.readDataset(n,[i.timeColumn,...p],t,Q$),a=r[i.timeColumn];if(!a||!a.length)break;for(let e of f)u.push(...e.push({t:a,columns:r}));if(a.length<Q$)break}r=r.filter(e=>!(e.targetId===n&&(!i.ruleIds||i.ruleIds.includes(e.ruleId)))),e.setMarks(r);for(let e of u)l(e,i.timeColumn);return u},pushLive(e,t){let r=!1;for(let i of n.values()){if(i.target.id!==e)continue;let n=i.push(t);n.length&&(r=!0);for(let e of n)l(e,$e)}r&&c()},tickLive(e,t){let r=!1;for(let i of n.values()){if(i.target.id!==e)continue;let n=i.tick(t);n.length&&(r=!0);for(let e of n)l(e,$e)}r&&c()},liveColumns(e){let t=new Set;for(let r of n.values())if(r.target.id===e)for(let e of Object.values(r.rule.signals))t.add(`formula`in e?e.formula:e.channel);return[...t]},sync:u,clearMarks(t){r=t?r.filter(e=>e.targetId!==t):[],e.setMarks(r)}}}var e1=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}},t1={maxChartsPerWorksheet:null,maxChannelsPerChart:null,maxWorksheets:null,maxMathChannels:null,maxAlertRules:null,canImportExportWorkspaces:!0},n1=[];function r1(e,t){let n=e.found[t];return{definitionId:n.definitionId,rule:e.defs.find(e=>e.id===n.definitionId)?.name??n.definitionId,index:n.index,parentIndex:n.parentIndex??null,tstart:n.tstart,tend:n.tend,flags:n.flags,kpis:n.kpis??{},incomplete:!!n.incomplete}}var i1=[`#a78bfa`,`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#94a3b8`];function a1(e=`ET`){return{id:crypto.randomUUID(),name:`Worksheet`,panels:[],panelChartSettings:{},panelChartBackgrounds:{},xKey:e}}function o1(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(lr({...e,name:a,source:`workbook`}))}return{channels:i,rename:r}}function s1(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 c1(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 l1(e,t,n){if(!e||!t)return en();let{min:r,max:i}=Tz(e.rows,t);if(!Number.isFinite(r)||!Number.isFinite(i))return en();let a=Dz(i-r||1,6),o=a>=1?Math.round(a):a,s=o>=1?1:o/10,c=Math.max(0,Math.ceil(-Math.log10(s))),l=e=>String(Number(e.toFixed(c)));return{...n,scaleMin:l(Math.floor(r/s)*s),scaleMax:l(Math.ceil(i/s)*s),majorStep:l(o),minorStep:``}}function u1(e,t){let n=t.includes(e.xKey)?e.xKey:t.includes(`ET`)?`ET`:t.includes(`ElapsedTime`)?$e: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:mn();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:hn(i1[2]),a=i.xyXCol||t[0],o=i.xyYCol||(t.length>1&&t[1]!==a?t[1]:t[0]);r[n.id]={...i,kind:`xyscatter`,xyXCol:a,xyYCol:o}}else if(n.kind===`xyzmesh`){let i=e&&e.kind===`xyzmesh`?e:gn(4),a=i.xyzXCol||t[0],o=i.xyzYCol||(t.length>1?t[1]:t[0]),s=i.xyzZCol||(t.length>2?t[2]:t[0]);r[n.id]={...i,kind:`xyzmesh`,xyzXCol:a,xyzYCol:o,xyzZCol:s}}}return{...e,xKey:n,panelChartSettings:r}}function d1(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 f1(){return typeof document>`u`?`dark`:nB(null)}function p1(e={}){let t={...e},n=!1,r=a1(),i=BQ({datasets:[],selection:[],worksheets:[r],activeWorksheetId:r.id,xRanges:{},offsets:{},colors:{},liveWindowSeconds:15,segmentContext:null,cycleRules:[],live:[],video:[],mathChannels:[],limits:{...t1,...t.limits},palette:$z(t.palette,f1()),importing:0,licensed:null,history:{canUndo:!1,canRedo:!1},marks:[],alerts:[],alertRules:[]}),a=HV(),o=()=>{let e=$z(t.palette,f1());i.set(t=>t.palette.join()===e.join()?t:{...t,palette:e})},s=typeof document>`u`?()=>{}:rB(null,o),c=HQ(),l=()=>{if(n)throw new ME(`disposed`)},u=e=>{throw a.emit(`limit`,{reason:e}),new ME(`limit_reached`,{reason:e})},d=()=>i.get(),f=(e,t)=>{let n=d().limits.maxChannelsPerChart,r=Ez(t);n!==null&&r>n&&r>Ez(e)&&u(`channels-per-chart`)},p=VQ((e,t)=>t===null?e:e.slice(0,t)),h=()=>{let e=d(),t=c.lapsByDataset(e.datasets),n=c.selectedDatasets(e.datasets,t,e.selection),r=c.selectedLive(e.live,e.selection),i=c.staticDataset(n),a=c.mergedDataset(i,r),o=p(e.mathChannels,e.limits.maxMathChannels);return{laps:t,selectedDatasets:n,selectedLive:r,staticDataset:i,merged:a,channels:o,numericColumns:c.numericColumns(a,n,o,c.mergedParts(n,r),r),allColumns:c.allColumns(a,n,o),columnUnits:c.columnUnits(a,o)}},g=(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??n1,layout:t.rect}),_=VQ((e,t,n)=>e.map(e=>({id:e.id,name:e.name,xKey:e.xKey,xRange:t[e.id]??null,liveWindowSeconds:e.liveWindowSeconds===void 0?n:e.liveWindowSeconds,charts:e.panels.map(t=>g(e,t))}))),v=VQ((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:Zz(n,e.id,s(e.id,a),o),customColor:e.id in n,offset:r[e.id]??0,parseConfig:e.parseConfig??null,fileInfo:e.info??null,beacon:e.beacon??null,cut:e.cut?{cycleId:e.cut.cycleId,timeKey:e.cut.timeKey,defs:e.cut.defs}:null,laps:c?c.laps.map((i,a)=>({id:i.id,name:i.name,value:c.values[a],unit:c.unit,isTime:c.isTime,color:Zz(n,i.id,s(i.id,a),o),offset:r[i.id]??0,selected:t.includes(i.id),...e.cut?{cycle:r1(e.cut,a)}:{}})):null,selected:c?u===0?!1:u===l.length?!0:`partial`:t.includes(e.id)}})}),b=VQ((e,t,n,r,i)=>{let a=e.filter(e=>t.includes(e.id)).map(e=>e.id);return e.map((e,o)=>({id:e.id,name:e.name,ownerName:e.ownerName,visibility:e.visibility,orgName:e.orgName,kind:e.kind,parentId:e.parentId,lowOf:e.lowOf,status:e.status,error:e.error,rowCount:e.rowCount,selected:t.includes(e.id),color:Zz(n,e.id,a.includes(e.id)?r+a.indexOf(e.id):o,i),customColor:e.id in n,recordingSince:e.recordingSince,limitNotice:e.limitNotice??null,channels:e.dataset.columnNames}))}),x=VQ(e=>{let t=h();return{datasets:v(e.datasets,e.selection,e.colors,e.offsets,t.laps,t.selectedDatasets,e.palette),selection:e.selection,worksheets:_(e.worksheets,e.xRanges,e.liveWindowSeconds),activeWorksheetId:e.activeWorksheetId,mathChannels:t.channels,live:b(e.live,e.selection,e.colors,t.selectedDatasets.length,e.palette),liveWindowSeconds:(()=>{let t=e.worksheets.find(t=>t.id===e.activeWorksheetId);return t?.liveWindowSeconds===void 0?e.liveWindowSeconds:t.liveWindowSeconds})(),segmentContext:e.segmentContext,cycleRules:e.cycleRules,limits:e.limits,palette:e.palette,importing:e.importing,licensed:e.licensed,hasData:t.merged!==null,multiDataset:t.selectedDatasets.length+t.selectedLive.length>1,numericColumns:t.numericColumns,allColumns:t.allColumns,columnUnits:t.columnUnits,history:e.history,marks:e.marks,alerts:e.alerts}}),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 e1({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--}},D=e=>[e.worksheets,e.mathChannels,e.liveWindowSeconds],O=[],k=()=>{let e=d();return{worksheets:e.worksheets,channels:e.mathChannels.filter(e=>e.source===`workbook`),liveWindowSeconds:e.liveWindowSeconds,activeWorksheetId:e.activeWorksheetId}},A=()=>i.set(e=>e.history.canUndo===C.canUndo&&e.history.canRedo===C.canRedo?e:{...e,history:{canUndo:C.canUndo,canRedo:C.canRedo}}),j=()=>{if(w)return;let e=D(d());e.every((e,t)=>e===O[t])||(O=e,T?C.rebase(k()):C.observe(k()),A())},M=()=>{O=D(d()),C.clear(k()),A()},N=e=>{w=!0;let t;try{t=e()}finally{w=!1}return M(),t},P=()=>x(d());i.subscribe(()=>{j(),a.emit(`change`,P())});let F=e=>{let t=d(),n=t.worksheets.find(n=>n.id===(e??t.activeWorksheetId));if(!n)throw new ME(`not_found`,{worksheetId:e});return n},I=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 ME(`not_found`,{chartId:e})},L=(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}),R=(e,t)=>{let{ws:n}=I(e);L(n.id,n=>({...n,panelChartSettings:{...n.panelChartSettings,[e]:t(n.panelChartSettings[e])}}))},z=e=>i.set(t=>e.length===t.selection.length&&e.every((e,n)=>e===t.selection[n])?t:{...t,selection:e,xRanges:{}}),B=new Set,ee=X$(t.live?.relay,e=>{let t=e.map(e=>e.id),n=e.filter(e=>e.kind===`data`&&!B.has(e.id)).map(e=>e.id),r=[...B].filter(e=>!t.includes(e));if(B=new Set(t),i.set(t=>({...t,live:e})),r.length&&z(d().selection.filter(e=>!r.includes(e))),n.length){let e=d().selection,t=n.filter(t=>!e.includes(t));t.length&&z([...e,...t])}let a=h();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(()=>L(t.id,e=>({...e,xKey:$e})))}},()=>({capacity:t.live?.capacity,maxMemoryMB:t.live?.maxMemoryMB}),{rows:(e,t,n)=>{if(!le.rules().length)return;t.columnNames.length!==te.get(e)&&(te.set(e,t.columnNames.length),le.sync());let r=le.liveColumns(e);if(!r.length)return;let i=t.endAbs,a=Math.max(n,t.firstAbs);if(i<=a)return;let o={};for(let e of r)o[e]=t.range(e,a,i);le.pushLive(e,{t:t.range($e,a,i),columns:o,scan:new Map})},tick:(e,t,n)=>{if(!le.rules().length)return;let r=t.range($e,t.endAbs-1,t.endAbs)[0];r===r&&le.tickLive(e,r+(Date.now()-n)/1e3)}}),te=new Map,H=VQ((e,t)=>e.filter(e=>t.some(t=>CE([e],t.panelChartSettings,t.xKey).length>0))),re=()=>ee.setMathChannels(H(p(d().mathChannels,d().limits.maxMathChannels),d().worksheets));re(),i.subscribe(re);let ie=e=>{i.set(t=>({...t,datasets:[...t.datasets,e]})),z([...d().selection,e.id]);let t=wz(e.schema);t.length&&E(()=>i.set(e=>({...e,worksheets:e.worksheets.map(e=>u1(e,t))})))},U=Promise.resolve(),ae=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 ME(`import_vetoed`);let{signal:s}=r;i.set(e=>({...e,importing:e.importing+o.length}));let c=U.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 AR(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 Cz({main:t,companions:i.companions,format:i.format.id},{priorInMemoryValues:SR(d().datasets),signal:s,onProgress:e=>a.emit(`import`,{file:t.name,phase:`progress`,fraction:e}),chooseChannels:r.chooseChannels,pickChannels:r.pickChannels}):[await xR(crypto.randomUUID(),t,d().datasets)??await yR(crypto.randomUUID(),t,c1,void 0,SR(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 ME(`cancelled`)}for(let t of o)ie(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 ME&&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 U=c.catch(()=>void 0),c},oe=()=>setTimeout(()=>{n||$Z(nt)},0),se=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}}),z(d().selection.filter(e=>!t(e))),n.length>0&&oe()},ce=async(e,t,n={})=>{let[r,...i]=await Cz({main:new File(e.chunks,`${e.name}.krc`),companions:[],format:`krc`,keys:e.keys},{priorInMemoryValues:t,...n});for(let e of i)e.source.dispose();return{...r,file:void 0,name:e.name,info:r.info&&{...r.info,startTime:e.startTime??r.info.startTime,meta:{...r.info.meta,recordingId:e.recordingId}}}},le=$$({targets:()=>[...d().datasets.map(e=>({kind:`dataset`,id:e.id,name:e.name,channels:e.schema.map(e=>e.name)})),...d().live.filter(e=>e.kind===`data`).map(e=>({kind:`stream`,id:e.id,name:e.name,channels:e.source.columnNames}))],maxRules:()=>d().limits.maxAlertRules,emit:e=>a.emit(`alert`,e),limit:()=>a.emit(`limit`,{reason:`alert-rules`}),setMarks:e=>i.set(t=>({...t,marks:e})),setStates:e=>i.set(t=>({...t,alerts:e})),readDataset:(e,t,n,r)=>{let i=d().datasets.find(t=>t.id===e);return i?i.source.readColumns(t,n,r):Promise.resolve({})}}),ue=VQ((e,t)=>{let n=new Map;for(let r of e){let e=it(r);e!==null&&n.set(r.id,{value:e,active:t.some(e=>e.ruleId===r.id&&(e.state===`active`||e.state===`clearing`))})}return n}),de=null;i.subscribe(()=>{let e=d();de&&de[0]===e.datasets&&de[1]===e.live||(de=[e.datasets,e.live],le.rules().length&&le.sync())});let fe={importFiles:ae,warmImport(e={}){l(),dz(!!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 ME(`not_found`,{datasetId:e});if(!t.info?.combined||!(t.file instanceof File))throw new ME(`invalid_argument`,{reason:`only a combined multi-rate import can be split`});let n=await Cz({main:t.file,companions:t.companions??[],format:t.info.importer},{priorInMemoryValues:SR(d().datasets.filter(t=>t.id!==e)),selection:t.info.selection,split:!0});se([e]);for(let e of n)ie(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 ME(`not_found`,{datasetId:e});if(!n.info||!(n.file instanceof File))throw new ME(`invalid_argument`,{reason:`only binary imports have channels to choose`});try{let r=await Cz({main:n.file,companions:n.companions??[],format:n.info.importer},{priorInMemoryValues:SR(d().datasets.filter(t=>t.id!==e)),initial:n.info.selection,chooseChannels:t,pickChannels:!0});se([e]);for(let e of r)ie(e);return r.map(e=>e.id)}catch(e){if(e instanceof ME&&e.code===`cancelled`)return null;throw e}},async combine(e){l();let t=d().datasets.find(t=>t.id===e);if(!t)throw new ME(`not_found`,{datasetId:e});let n=t.info?.splitKey;if(!n||!(t.file instanceof File))throw new ME(`invalid_argument`,{reason:`only datasets split from one file can be combined`});let r=d().datasets.filter(e=>e.info?.splitKey===n),i=await Cz({main:t.file,companions:t.companions??[],format:t.info.importer},{priorInMemoryValues:SR(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 ME(`invalid_argument`,{reason:`these groups have no common time base`})}return se(r.map(e=>e.id)),ie(i[0]),i[0].id},async openRecording(e,t={}){l();let n=await ce(e,SR(d().datasets),t);return ie(n),n.id},async reopenRecording(e,t){l();let n=d().datasets.find(t=>t.id===e);if(!n)throw new ME(`not_found`,{datasetId:e});let r=await ce(t,SR(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),oe()},openHistoryRange(e){l();let t=zQ(crypto.randomUUID(),e);return ie(t),t.id},updateHistoryRange(e,t){l();let n=d().datasets.find(t=>t.id===e);if(!n)throw new ME(`not_found`,{datasetId:e});if(!(n.source instanceof OQ)){let t=`dataset ${e} is not a history range: only datasets opened with openHistoryRange can be updated`;throw Object.assign(new ME(`invalid_argument`,{datasetId:e,reason:t}),{message:t})}let r=zQ(e,t);i.set(t=>({...t,datasets:t.datasets.map(t=>t.id===e?{...r,beacon:n.beacon}:t)})),oe()},addColumns(e){l();let t=MQ(crypto.randomUUID(),e);return ie(t),t.id},replaceColumns(e,t,n={}){l();let r=d().datasets.find(t=>t.id===e);if(!r)throw new ME(`not_found`,{datasetId:e});let a=IQ(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 ME(`not_found`,{datasetId:e});let a=PQ(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 gR(crypto.randomUUID(),t,e);return ie(n),n.id},async findCycles(e,t,n){l();let r=d().datasets.find(t=>t.id===e);if(!r)throw new ME(`not_found`,{datasetId:e});let i=await UB(r.source,n,GB(t)),a=new Map(t.filter(e=>e.kpis?.length).map(e=>[e.id,e.kpis]));return WB(i,t).map(e=>a.has(e.definitionId)?{...e,kpis:qB(i,e,a.get(e.definitionId))}:e)},async addCycles(e,t){l();let n=d().datasets.find(t=>t.id===e);if(!n)throw new ME(`not_found`,{datasetId:e});let r=n.schema.filter(e=>e.type===`number`&&e.name!==t.timeKey).map(e=>e.name),i=await UB(n.source,t.timeKey,r),a={...Object.fromEntries(n.schema.map(e=>[e.name,e.unit])),[VB]:`s`},o=e=>t.defs.find(t=>t.id===e)?.name??e,s=[];for(let e of t.pick){let r=t.found.find(t=>t.definitionId===e.definitionId&&t.index===e.index&&t.parentIndex===e.parentIndex);if(!r)throw new ME(`not_found`,{reason:`no ${o(e.definitionId)} ${e.index} in the cycles found`});let c=r.parentIndex?`${o(t.cycleId)} ${r.parentIndex} · ${o(r.definitionId)}`:`${o(r.definitionId)} ${r.index}`;s.push(fe.addColumns({name:`${n.name} · ${c}`,columns:YB(i,t.timeKey,r),units:a}))}if(t.tables!==!1){let e=ZB(t.found,t.cycleId,t.defs,i);s.push(await fe.addText(QB(e.cycles),`${n.name} · ${o(t.cycleId)}s.csv`)),e.phases.length&&s.push(await fe.addText(QB(e.phases),`${n.name} · Phases.csv`))}return s},async cut(e,t){l();let n=d().datasets.find(t=>t.id===e);if(!n)throw new ME(`not_found`,{datasetId:e});let r;if(t){if(!t.defs.some(e=>e.id===t.cycleId))throw new ME(`invalid_argument`,{reason:`cycleId is not one of defs`});let i=n.schema.filter(e=>e.type===`number`&&e.name!==t.timeKey).map(e=>e.name),a=await UB(n.source,t.timeKey,i),o=t.defs.find(e=>e.id===t.cycleId)?.show,s=e=>[...e.kpis??[],...o&&o.channel!==t.timeKey?[o]:[]],c=new Map(t.defs.filter(e=>s(e).length).map(e=>[e.id,s(e)])),l=WB(a,t.defs).sort((e,t)=>e.tstart-t.tstart||!!e.parentIndex-+!!t.parentIndex).map(e=>c.has(e.definitionId)?{...e,kpis:qB(a,e,c.get(e.definitionId))}:e),u={...Object.fromEntries(n.schema.map(e=>[e.name,e.unit])),[VB]:`s`},d=e=>t.defs.find(t=>t.id===e)?.name??e,f=l.map(r=>MQ(`${e}::${r.definitionId}:${r.parentIndex??0}:${r.index}`,{name:r.parentIndex?`${n.name} · ${d(t.cycleId)} ${r.parentIndex} · ${d(r.definitionId)}`:`${n.name} · ${d(r.definitionId)} ${r.index}`,columns:YB(a,t.timeKey,r),units:u})),p=a.t.length?a.t[a.t.length-1]:NaN,m=l.map(e=>e.tend===null&&p===p?{...e,tend:p,incomplete:!0}:e);r={defs:t.defs,cycleId:t.cycleId,timeKey:t.timeKey,found:m,parts:f}}else if(!n.cut)return 0;if(!d().datasets.some(t=>t.id===e))return 0;i.set(t=>({...t,datasets:t.datasets.map(t=>t.id===e?{...t,cut:r}:t)}));let a=d().selection,o=a.some(t=>t===e||t.startsWith(`${e}::`)),s=a.filter(t=>t!==e&&!t.startsWith(`${e}::`)),c=r?r.parts.filter((e,t)=>!r.found[t].parentIndex).map(e=>e.id):[];return z(o?c.length>0?[...s,...c]:[...s,e]:s),c.length},remove(e){l(),se([e])},clear(){l(),se(d().datasets.map(e=>e.id))},async configure(e,t){l();let n=d().datasets.find(t=>t.id===e);if(!n)throw new ME(`not_found`,{datasetId:e});if(t.parseConfig&&(n.kind!==`memory`||!n.parseConfig))throw new ME(`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 ME(`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?xB(n.data.rows,r.channel):[],l=r&&t.selectCycles===`best`?EB(c.map(e=>TB(n.data.rows,e,r.metric,r.stat))):null,u=l===null?c.map((t,n)=>kB(e,n)):[kB(e,l)];z(o?c.length>0?[...s,...u]:[...s,e]:s)}let r=t.parseConfig;if(!r)return;let a=(()=>{try{let e=V(y(n.rawText??``),r.headerRow);return n.data.columnNames.length===e.length&&n.data.columnNames.every((t,n)=>t===e[n])}catch{return!1}})();if(ne(r,n.parseConfig)&&a)return;let o=n.fromColumns?RQ(n):n.rawText??``,s=await LE(n.file?{file:n.file,config:r}:{rawText:o,config:r}),c=new BE(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),oe(),n.cut&&await fe.cut(e,n.cut);let p=h().selectedDatasets,g=new Set(p.flatMap(e=>e.data.columnNames)),_=s.columnNames.filter(e=>m(s.rows,e)),v=_.find(e=>e===`ET`)??_[0];E(()=>i.set(e=>({...e,worksheets:e.worksheets.map(e=>d1(!g.has(e.xKey)&&v?{...e,xKey:v}:e,e=>g.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(),z([...e])},toggle(e){l();let t=d().selection,n=h().laps[e];if(n){let e=n.laps.map(e=>e.id);z(e.every(e=>t.includes(e))?t.filter(t=>!e.includes(t)):[...t,...e.filter(e=>!t.includes(e))]);return}z(t.includes(e)?t.filter(t=>t!==e):[...t,e])},selectAll(){l();let e=h().laps,t=d().live.filter(e=>d().selection.includes(e.id)).map(e=>e.id);z([...d().datasets.flatMap(t=>e[t.id]?e[t.id].laps.map(e=>e.id):[t.id]),...t])},deselectAll(){l(),z([])},raw(e){let t=d().datasets.find(t=>t.id===e);if(!t)throw new ME(`not_found`,{datasetId:e});return{get rawText(){return t.kind===`memory`&&t.fromColumns?RQ(t):t.rawText??``},data:t.data,parseConfig:t.parseConfig??null,kind:t.kind,beacon:t.beacon??null}},async columnBounds(e){l();let t=h(),n=t.selectedDatasets.find(t=>t.schema.some(t=>t.name===e));if(n&&n.kind===`memory`){let t=Tz(n.data.rows,e);if(Number.isFinite(t.min)&&Number.isFinite(t.max))return t}else if(n){let t=await n.source.xBounds(e).catch(()=>null);if(t&&Number.isFinite(t.x0)&&Number.isFinite(t.x1)&&t.x1>=t.x0)return{min:t.x0,max:t.x1}}let r=t.selectedLive.find(t=>t.dataset.columnNames.includes(e));if(r){let t=r.source.valueBoundsSync(e);if(t)return t}let i=pe(e);if(!i)return null;let a=Tz(i.rows,e);return Number.isFinite(a.min)&&Number.isFinite(a.max)?a:null}},pe=(e,t=F().xKey)=>{let n=h();if(!n.merged)return null;if(!n.channels.find(t=>t.name===e))return n.merged;let r=SE(n.merged,n.channels,t);return{...n.merged,columnNames:[...n.merged.columnNames,...r.ok.map(e=>e.name)],rows:r.rows}},me=(e,t,n)=>h().selectedLive.length>0?{...n,scaleMin:``,scaleMax:``,majorStep:``,minorStep:``}:l1(pe(e,t),e,n),he={fromFileList:e=>kV(Array.from(e)),async fromDataTransfer(e){return AV(Array.from(e.items??[]).map(e=>e.webkitGetAsEntry?.()).filter(e=>!!e))},canPick:jV,pick:MV,tree:(e,t)=>OV(e,t),isImportable:DV},ge={add(e=`Worksheet`){l();let t=d(),n=t.limits.maxWorksheets;n!==null&&t.worksheets.length>=n&&u(`worksheets`);let r={...a1(F().xKey||`ET`),name:e};return i.set(e=>({...e,worksheets:[...e.worksheets,r],activeWorksheetId:r.id})),r.id},rename(e,t){l(),F(e),L(e,e=>e.name===t?e:{...e,name:t})},remove(e){l();let t=d();if(F(e),t.worksheets.length<=1)throw new ME(`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(),F(e),i.set(t=>t.activeWorksheetId===e?t:{...t,activeWorksheetId:e,xRanges:{...t.xRanges,[e]:null}})},setXKey(e,t){l(),F(e),L(e,e=>d1({...e,xKey:t},e=>e!==t)),i.set(t=>({...t,xRanges:{...t.xRanges,[e]:null},offsets:{}}))}},_e={mount(e,t,n){return l(),QZ(nt,e,t,n)},openWindow(e,t){return l(),I(e),SQ(nt,e,(t,n)=>QZ(nt,e,t,n),t)},setFonts(e){e.sans&&(Q.sans=e.sans),e.mono&&(Q.mono=e.mono),$Z(nt)},kinds:()=>UQ,label:GQ,add(e,t={}){if(l(),!UQ.some(t=>t.kind===e))throw new ME(`invalid_argument`,{kind:e});let n=F(t.worksheetId),r=d().limits.maxChartsPerWorksheet;r!==null&&n.panels.length>=r&&u(`charts-per-worksheet`);let i={...Zt(e,n.panels),...t.title?{title:t.title}:{}};t.layout&&(i.rect={...t.layout});let a=ar([i],{},i1[2],4)[i.id],o=a,s=h().numericColumns;if(s.length&&(o.kind===`multiband`||o.kind===`xyscatter`||o.kind===`xyzmesh`)&&(o=u1({...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??me(o.xyXCol,n.xKey,o.xyXScale),xyYScale:e.xyYScale??me(o.xyYCol,n.xKey,o.xyYScale)}}return f(a,o),L(n.id,e=>({...e,panels:t.layout?[...e.panels,i]:$t([...e.panels,i]),panelChartSettings:{...e.panelChartSettings,[i.id]:o}})),i.id},remove(e){l();let{ws:t}=I(e);L(t.id,t=>{let n={...t.panelChartSettings},r={...t.panelChartBackgrounds};return delete n[e],delete r[e],{...t,panels:$t(t.panels.filter(t=>t.id!==e)),panelChartSettings:n,panelChartBackgrounds:r}})},rename(e,t){l();let{ws:n}=I(e),r=t?.trim()||void 0;L(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}=I(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:me(e.xyXCol,n.xKey,r.xyXScale)}),typeof e.xyYCol==`string`&&e.xyYCol!==r.xyYCol&&!(`xyYScale`in e)&&(i={...i,xyYScale:me(e.xyYCol,n.xKey,r.xyYScale)})}f(r,i),R(e,()=>i)},replaceSettings(e,t){l();let{ws:n,panel:r}=I(e);if(t.kind!==r.kind)throw new ME(`invalid_argument`,{reason:`settings kind mismatch`});f(n.panelChartSettings[e],t),R(e,()=>t)},setBackground(e,t){l();let{ws:n}=I(e);L(n.id,n=>({...n,panelChartBackgrounds:{...n.panelChartBackgrounds,[e]:t}}))},addAnnotation(e,t){l(),I(e);let n=Pt({...t,id:t.id||crypto.randomUUID()});if(!n)throw new ME(`invalid_argument`,{reason:`not a valid annotation`});return R(e,e=>({...e,annotations:[...(e.annotations??[]).filter(e=>e.id!==n.id),n]})),n.id},updateAnnotation(e,t,n){l();let r=(I(e).ws.panelChartSettings[e]?.annotations??[]).find(e=>e.id===t);if(!r)throw new ME(`not_found`,{annotationId:t});let i=Pt({...r,...n,id:r.id,kind:r.kind});if(!i)throw new ME(`invalid_argument`,{reason:`not a valid annotation`});R(e,e=>({...e,annotations:(e.annotations??[]).map(e=>e.id===i.id?i:e)}))},removeAnnotation(e,t){l(),I(e),R(e,e=>({...e,annotations:(e.annotations??[]).filter(e=>e.id!==t)}))},setAnnotations(e,t){l(),I(e);let n=Ft(t)??[];R(e,e=>({...e,annotations:n}))},setLayout(e,t){l();let{ws:n}=I(e);L(n.id,n=>({...n,panels:n.panels.map(n=>n.id===e?{...n,rect:{...t}}:n)}))},setLayouts(e,t){l(),L(e,e=>({...e,panels:e.panels.map(e=>t[e.id]?{...e,rect:{...t[e.id]}}:e)}))},autoLayout(e){l(),L(F(e).id,e=>({...e,panels:$t(e.panels)}))},get(e){let{ws:t,panel:n}=I(e);return g(t,n)},list(e){let t=F(e);return t.panels.map(e=>g(t,e))},async addSeries(e,t){l();let{ws:n}=I(e),r=n.panelChartSettings[e];if(!r||r.kind!==`multiband`)throw new ME(`invalid_argument`,{reason:`not a multiband chart`});let i=d().limits.maxChannelsPerChart;i!==null&&Ez(r)>=i&&u(`channels-per-chart`);let a=h().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=cr(),f={id:c,column:s,color:i1[r.series.length%i1.length],bandFromPct:0,bandToPct:100,scaleMin:0,scaleMax:1,yMajorStep:0,yMinorStep:0};return R(e,e=>e.kind===`multiband`?{...e,series:[...e.series,f]}:e),await _e.autoScaleSeries(e,c),c},async updateSeries(e,t,n){l();let{ws:r}=I(e),i=r.panelChartSettings[e],a=i&&i.kind===`multiband`?i.series.find(e=>e.id===t):void 0;if(!a)throw new ME(`not_found`,{seriesId:t});R(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 _e.autoScaleSeries(e,t)},removeSeries(e,t){l(),R(e,e=>e.kind===`multiband`?{...e,series:e.series.filter(e=>e.id!==t)}:e)},reorderSeries(e,t){l(),R(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}=I(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 fe.columnBounds(a.column);!o||n||R(e,e=>e.kind===`multiband`?{...e,series:e.series.map(e=>e.id===t?{...e,scaleMin:o.min,scaleMax:o.max}:e)}:e)}},ve=new Map,ye={setXRange(e,t){l();let n=F(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){ye.setXRange(null,e)},setCursorX(e,t){l();let n=F(t).id;(ve.get(n)??null)!==e&&(ve.set(n,e),a.emit(`cursorchange`,{worksheetId:n,x:e}))},cursorX(e){return ve.get(F(e).id)??null},setLiveWindow(e,t){l();let n=F(t);n.liveWindowSeconds!==e&&L(n.id,t=>({...t,liveWindowSeconds:e}))},setSegmentContext(e){l(),i.set(t=>JSON.stringify(t.segmentContext)===JSON.stringify(e)?t:{...t,segmentContext:e})}},be={save(e){l();let t=e.id??crypto.randomUUID(),[n]=BB([{...e,id:t,parentId:e.parentId??null}].concat(d().cycleRules.filter(e=>e.id!==t))).filter(e=>e.id===t);if(!n)throw new ME(`invalid_argument`,{reason:`not a valid cycle rule (or its parent is missing)`});return i.set(e=>({...e,cycleRules:e.cycleRules.some(e=>e.id===t)?e.cycleRules.map(e=>e.id===t?n:e):[...e.cycleRules,n]})),t},remove(e){l();let t=new Set([e]);for(let e=!0;e;){e=!1;for(let n of d().cycleRules)n.parentId&&t.has(n.parentId)&&!t.has(n.id)&&(t.add(n.id),e=!0)}i.set(e=>({...e,cycleRules:e.cycleRules.filter(e=>!t.has(e.id))}))}},xe={create(e){l();let n=d(),r=n.limits.maxMathChannels;r!==null&&n.mathChannels.length>=r&&u(`math-channels`);let o=lr(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 ME(`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 ME(`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 EE(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:()=>wE(d().mathChannels),preview(e,t){let n=h();return n.merged?iE(e,n.merged,F(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}})}},Se=VQ((e,t)=>[...e.flatMap(e=>e.kind===`camera`&&e.video?[AE({...e,video:e.video})]:[]),...t]),Ce=``;i.subscribe(()=>{let e=Se(d().live,d().video),t=e.map(e=>`${e.kind}:${e.id}:${e.recordingId??``}:${e.name}`).join(`|`);t!==Ce&&(Ce=t,a.emit(`videochange`,{sources:e}))});let we=(e,t,n)=>e.id===t&&(n===void 0||(e.recordingId??null)===n),Te={sources:()=>Se(d().live,d().video),register(e){l(),i.set(t=>({...t,video:[...t.video.filter(t=>!we(t,e.id,e.recordingId??null)),e]}))},unregister(e,t){l(),i.set(n=>n.video.some(n=>we(n,e,t))?{...n,video:n.video.filter(n=>!we(n,e,t))}:n)}},Ee={openLocal(e,t){return l(),ee.openLocal(e,t)},async connect(e,t,n){l(),await ee.connect(e,t,n)},startRecording(e){l(),ee.startRecording(e)},stopRecording(e){return l(),ee.stopRecording(e)},setSegmentAxis(e,t){l(),ee.setSegmentAxis(e,t)},rowCount(e){return ee.connections().find(t=>t.id===e)?.source.size()??0},disconnect(e){l(),ee.disconnect(e),z(d().selection.filter(t=>t!==e))}},De=()=>{d().limits.canImportExportWorkspaces||u(`workspaces-io`)},Oe=async e=>{if(e instanceof Blob)try{return JSON.parse(await e.text())}catch{throw new ME(`bad_file`)}if(typeof e==`string`)try{return JSON.parse(e)}catch{throw new ME(`bad_file`)}return e},ke=async e=>e instanceof File?e:new File([JSON.stringify(await Oe(e))],`import.json`,{type:`application/json`}),Ae=e=>e.replace(/[^\w.-]+/g,`_`),je=e=>new Blob([JSON.stringify(e,null,2)],{type:`application/json`}),Me=e=>{let t=ir(e.panelChartSettings,i1[2],4),n={};for(let r of e.panels)t[r.id]?.kind===r.kind&&(n[r.id]=t[r.id]);return{...e,panelChartSettings:ar(e.panels,n,i1[2],4)}},Ne=(e,t)=>e.map(e=>{let n=e=>{let n=t.has(e)?crypto.randomUUID():e;return t.add(n),n},r=new Map(e.panels.map(e=>[e.id,n(e.id)])),i=e=>Object.fromEntries(Object.entries(e).map(([e,t])=>[r.get(e)??e,t]));return{...e,id:n(e.id),panels:e.panels.map(e=>({...e,id:r.get(e.id)})),panelChartSettings:i(e.panelChartSettings),panelChartBackgrounds:i(e.panelChartBackgrounds??{})}}),Pe=()=>new Set(d().worksheets.flatMap(e=>[e.id,...e.panels.map(e=>e.id)])),Fe=(e,t=0)=>{let n=d().limits.maxWorksheets,r=Ne((n===null?e:e.slice(0,Math.max(1,n))).map(Me),new Set),a=r[Math.min(t,r.length-1)];i.set(e=>({...e,worksheets:r,activeWorksheetId:a.id,xRanges:{}}))},Ie=(e,t)=>{let n=F(t),r=d().limits.maxChartsPerWorksheet;r!==null&&n.panels.length>=r&&u(`charts-per-worksheet`);let i=d().limits.maxChannelsPerChart;i!==null&&Ez(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 L(n.id,t=>({...t,panels:$t([...t.panels,o]),panelChartSettings:{...t.panelChartSettings,[a]:e.settings},panelChartBackgrounds:e.background===null?t.panelChartBackgrounds:{...t.panelChartBackgrounds,[a]:e.background}})),a},Le=()=>{let e=d();return dV({worksheets:e.worksheets,activeWorksheetId:e.activeWorksheetId,channels:H(p(e.mathChannels,e.limits.maxMathChannels),e.worksheets),liveWindowSeconds:e.liveWindowSeconds,laps:e.datasets.find(e=>e.beacon)?.beacon??null,segments:e.segmentContext,cycles:e.cycleRules})},Re=e=>{if(e.worksheets.length===0)throw new ME(`bad_workspace`,{errors:e.errors});let{channels:t,rename:n}=o1(d().mathChannels,e.mathChannels);Fe(n.size?e.worksheets.map(e=>s1(e,n)):e.worksheets,e.activeIndex),i.set(n=>({...n,mathChannels:[...n.mathChannels.filter(e=>e.source!==`workbook`),...t],liveWindowSeconds:e.liveWindowSeconds===void 0?n.liveWindowSeconds:e.liveWindowSeconds,segmentContext:e.segments??null,cycleRules:e.cycles}));let r=e.laps;if(r)for(let e of d().datasets)e.kind!==`memory`||e.beacon||!e.data.columnNames.includes(r.channel)||fe.configure(e.id,{beacon:r}).catch(e=>a.emit(`error`,{error:e,context:`io.openWorkbook`}));return{worksheets:e.worksheets.length,errors:e.errors}},ze=e=>{if(e===null)return;let t=h().numericColumns,n=t.length?e.worksheets.map(e=>u1(e,t)):e.worksheets;w=!0;try{i.set(t=>{let r=t=>e.worksheets.some(e=>e.id===t);return{...t,worksheets:n,activeWorksheetId:r(t.activeWorksheetId)?t.activeWorksheetId:r(e.activeWorksheetId)?e.activeWorksheetId:e.worksheets[0].id,xRanges:Object.fromEntries(Object.entries(t.xRanges).filter(([e])=>r(e))),mathChannels:[...t.mathChannels.filter(e=>e.source!==`workbook`),...e.channels],liveWindowSeconds:e.liveWindowSeconds}})}finally{w=!1}O=D(d()),C.rebase(k()),A()},Be={undo(){l(),ze(C.undo())},redo(){l(),ze(C.redo())},clear(){l(),M()}},Ve={hasWork:()=>SV(d().worksheets),exportWorksheet(e){l(),De();let t=F(e),n=fV(t);return{json:n,blob:je(n),filename:`${Ae(t.name||`worksheet`)}.kymosh`}},exportChart(e){l(),De();let{ws:t,panel:n}=I(e),r=pV(n,t.panelChartSettings[e],t.panelChartBackgrounds[e]??null);return{json:r,blob:je(r),filename:`${Ae(n.title?.trim()||n.kind)}.json`}},parseFile:e=>TV(e),exportWorkspace(){l(),De();let e=Le();return{json:e,blob:je(e),filename:`kymoscope-workspace-${new Date().toISOString().slice(0,10)}.json`}},async exportWorkspaceEncrypted(e){l(),De();let t=typeof e==`string`?await tV(Le(),e):await nV(Le(),e);return{json:t,blob:je(t),filename:`kymoscope-workbook-${new Date().toISOString().slice(0,10)}.kymo`}},async importWorkspace(e,t={}){l(),De();let n=await Oe(e);return rV(n)&&(n=await oV(n,t)),N(()=>Re(xV(n)))},toWorkbook:Le,openWorkbook(e){return l(),N(()=>Re(xV(e)))},async importWorksheet(e){l(),De();let t=d();t.limits.maxWorksheets!==null&&t.worksheets.length>=t.limits.maxWorksheets&&u(`worksheets`);let n=await TV(await ke(e));if(n.type!==`worksheet`)throw new ME(`bad_file`,{found:n.type});let[r]=Ne([Me(n.worksheet)],Pe());return i.set(e=>({...e,worksheets:[...e.worksheets,r],activeWorksheetId:r.id})),r.id},async importChart(e,t){l(),De();let n=await TV(await ke(e));if(n.type!==`chart`)throw new ME(`bad_file`,{found:n.type});return Ie(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(Me):[a1()];N(()=>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(),N(()=>{se(d().datasets.map(e=>e.id));let e=a1();i.set(t=>({...t,worksheets:[e],activeWorksheetId:e.id,xRanges:{},offsets:{},colors:{},mathChannels:t.mathChannels.filter(e=>e.source!==`workbook`)}))})}},He={merged(e){let t=h();if(!t.merged||t.channels.length===0)return t.merged;let n=SE(t.merged,t.channels,F(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 h().merged}},Ue=typeof location<`u`?location.hostname:``,We=t.license,Ge=t.licenseKey,Ke=!1,qe={},Je=e=>{n||i.set(t=>({...t,licensed:e}))},Ye=(e,t,n)=>{clearTimeout(qe[e]);let r=Math.max(0,t-Date.now()),i=r>2**31-1;qe[e]=setTimeout(()=>{i?Ye(e,t,n):n()},i?2**31-1:r)},Xe=e=>Ye(`renew`,e,()=>void Qe()),Ze=e=>Ye(`expiry`,e*1e3+1e3,()=>{RV(Ge,Ue).then(e=>{n||Je(e.ok)})});async function Qe(){let e=36e5,t,r=null,i;try{t=await Promise.race([We.get(),new Promise((e,t)=>{i=setTimeout(()=>t(Error(`timeout`)),3e4)})]),r=await RV(t,Ue)}catch{}finally{clearTimeout(i)}if(n)return!1;if(r?.ok)return Ge=t,Ke=!0,Je(!0),Ze(r.exp),Xe(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 RV(Ge,Ue);return n?!1:(Je(a.ok),Xe(Date.now()+e),a.ok)}let et=!We||t.licenseKey?RV(t.licenseKey,Ue).then(e=>(e.ok||console.warn(`[kymoscope] license ${e.reason}: showing attribution`),!Ke&&!n&&(Je(e.ok),e.ok&&We&&Ze(e.exp)),e.ok)):null,tt=We?Qe():et;w=!1,M();let nt={getState:P,subscribe(e){return i.subscribe(e)},on:a.on,licensed:tt,isLicensed:()=>d().licensed,setOptions(e){if(l(),t={...t,...e},e.live&&ee.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:fe,folders:he,worksheets:ge,charts:_e,view:ye,mathChannels:xe,cycles:be,live:Ee,video:Te,io:Ve,history:Be,data:He,alerts:{setRules:e=>{l();let t=le.setRules(e);return i.set(e=>({...e,alertRules:le.rules()})),t},rules:le.rules,state:le.state,evaluate:(e,t)=>(l(),le.evaluate(e,t)),clearMarks:le.clearMarks},marks:{list:()=>d().marks},dispose(){if(!n){n=!0,clearTimeout(qe.renew),clearTimeout(qe.expiry),s(),CQ(nt),eQ(nt),ee.dispose();for(let e of d().datasets)e.source.dispose().catch(()=>void 0);a.emit(`dispose`,void 0),a.clear()}}};return m1.set(nt,{store:i,derived:h,live:ee,alertLines:()=>ue(d().alertRules,d().alerts)}),nt}var m1=new WeakMap;function h1(e){let t=m1.get(e);if(!t)throw new ME(`invalid_argument`,{reason:`not a Kymoscope engine`});return t}var g1=2e3,_1=3;function v1(e){let t=e[0].v.fragCount,n=new Map;for(let r of e)r.v.fragCount===t&&!n.has(r.v.fragIndex)&&n.set(r.v.fragIndex,r);let r=[];for(let e=0;e<t;e++){let t=n.get(e);if(!t)return null;r.push(t.v.payload)}let i=n.get(0),a=r[0];if(t>1){a=new Uint8Array(r.reduce((e,t)=>e+t.length,0));for(let e=0,n=0;e<t;e++)a.set(r[e],n),n+=r[e].length}return{t:i.v.t,seq:i.v.seq,key:i.v.key,data:a,arrivedAt:i.at}}function y1(e){let t=[],n=0;for(;n<e.length&&e[n].v.fragIndex>0&&e[n].v.seq===e[0].v.seq;)t.push(e[n++]);let r=[],i=[],a=[];for(;n<=e.length;n++){let t=e[n];if(a.length&&(!t||t.v.seq!==a[0].v.seq)){let e=v1(a);e?r.push(e):t||(i=a),a=[]}t&&a.push(t)}return{head:t,units:r,tail:i}}var b1=class{kind=`recorded`;id;name;parentId;parentName;recordingId;chunks;fetch;open;maxBytes;cache=new Map;sizes=new Map;bytes=0;width=0;height=0;codec=``;waiting=null;constructor(e){this.id=e.id,this.name=e.name,this.parentId=e.parentId,this.parentName=e.parentName??null,this.recordingId=e.recordingId,this.chunks=[...e.chunks].sort((e,t)=>e.seq-t.seq),this.fetch=e.fetchChunk,this.open=e.open,this.maxBytes=e.maxBytes??256*1024*1024}async parse(e){let t=new Uint8Array(await this.fetch(this.chunks[e].seq)),n=[];for(let e of Me(t).messages){let t=null;try{t=await he(this.open,e.bytes.slice().buffer)}catch{}if(t?.kind!==6)continue;let r=o$(t.plaintext);r&&(r.key&&r.fragIndex===0&&!this.codec&&(this.codec=r.codec,this.width=r.width,this.height=r.height),n.push({v:r,at:e.at}))}let r=y1(n),i=e=>e.reduce((e,t)=>e+t.v.payload.length,0);return{...r,bytes:r.units.reduce((e,t)=>e+t.data.length,0)+i(r.head)+i(r.tail)}}parsed(e){let t=this.cache.get(e);if(t)return this.cache.delete(e),this.cache.set(e,t),t;let n=this.parse(e);return this.cache.set(e,n),n.then(t=>{this.cache.get(e)===n&&(this.sizes.set(e,[t.bytes,t.units.length]),this.bytes+=t.bytes,this.evict(e))},()=>{this.cache.get(e)===n&&this.cache.delete(e)}),n}evict(e){for(let t of this.cache.keys()){if(this.bytes<=this.maxBytes)return;let n=this.sizes.get(t);t===e||!n||(this.bytes-=n[0],this.sizes.delete(t),this.cache.delete(t))}}async units(e){let t;try{t=await this.parsed(e)}catch{return[]}if(t.full)return t.full;if(!t.tail.length||e+1>=this.chunks.length)return t.full=t.units;let n=await this.parsed(e+1).catch(()=>null);if(!n)return t.units;let r=null;try{r=v1([...t.tail,...n.head.filter(e=>e.v.seq===t.tail[0].v.seq)])}catch{}return t.full=r?[...t.units,r]:t.units}async seekPlan(e){let t=this.chunks.length;if(!t)return[];let n=e*1e3,r=0;for(;r+1<t&&this.chunks[r+1].t0<=n;)r++;let i=r,a=r+1<t&&this.chunks[r+1].t0-n<g1?r+1:r,o=(await Promise.all(Array.from({length:a-i+1},(e,t)=>this.units(i+t)))).flat(),s=()=>{let t=o.length-1;for(;t>=0&&o[t].t>e;)t--;let n=t;for(;n>=0&&!o[n].key;)n--;return[n,t]},[c,l]=s();for(let e=0;c<0&&i>0&&e<_1;e++)o=[...await this.units(--i),...o],[c,l]=s();return a+1<t&&this.units(a+1),c<0?[]:o.slice(c,l+1)}ready(){return this.waiting??=(async()=>{for(let e=0;e<Math.min(this.chunks.length,_1+1)&&!this.codec;e++)await this.units(e);this.codec||(this.waiting=null)})()}info(){let e=0;for(let[,t]of this.sizes.values())e+=t;return{width:this.width,height:this.height,codec:this.codec,latestT:this.range()?.[1]??null,lagMs:null,units:e,bytes:this.bytes}}range(){let e=this.chunks.length;return e?[this.chunks[0].t0/1e3,this.chunks[e-1].t1/1e3]:null}},x1=[60,300,900,1800,3600,7200,14400,28800,43200,86400],S1={60:`1m`,300:`5m`,900:`15m`,1800:`30m`,3600:`1h`,7200:`2h`,14400:`4h`,28800:`8h`,43200:`12h`,86400:`24h`};function C1(e){if(typeof e==`number`)return x1.includes(e)?e:null;if(typeof e!=`string`)return null;let t=Object.entries(S1).find(([,t])=>t===e.trim().toLowerCase());return t?Number(t[0]):null}var w1=e=>S1[e]??`${e}s`;function T1(e){for(let t=x1.length-1;t>=0;t--)if(x1[t]*e<=157286400)return x1[t];return x1[0]}function E1(e,t,n){let r=t*1e3,i=n*1e3;return Math.floor((e+i)/r)*r+r-i}var D1=1e4,O1=72e4,k1=3e5,A1=3e4,j1=1e4,M1=1e4,N1=64*1024,P1=50,F1=[`360p`,`480p`,`720p`,`1080p`],I1=e=>e+6+(e>=126?2:0)+(e>65535?6:0);function L1(e,t){return t*I1(e+30)}var R1=e=>typeof e==`number`&&Number.isFinite(e)&&e>0,z1=e=>Number.isInteger(e)&&e>=1;function B1(e,t){if(!e||e.mode!==`live`&&e.mode!==`record`)return null;if(t===`camera`)return F1.includes(e.quality)&&Number.isInteger(e.fps)&&e.fps>=1&&e.fps<=60?{mode:e.mode,quality:e.quality,fps:e.fps}:null;if(!R1(e.bytes_per_sec))return null;let n=e.bytes_per_sec,r={};if(e.mode===`record`){let t=e.splitEvery===void 0?T1(n):C1(e.splitEvery);if(t===null)return null;r={split_every:t}}return e.sources===void 0?R1(e.hz)&&z1(e.channels)?{mode:e.mode,hz:e.hz,channels:e.channels,bytes_per_sec:n,...r}:null:Array.isArray(e.sources)&&e.sources.length>0&&e.sources.every(e=>R1(e?.hz)&&z1(e?.channels))?{mode:e.mode,sources:e.sources.map(({hz:e,channels:t})=>Object.freeze({hz:e,channels:t})),bytes_per_sec:n,...r}:null}var V1=class extends Error{status;code;detail;constructor(e,t,n){super(`${n} (${t})`),this.status=e,this.code=t,this.detail=n}};async function H1(e,t,n,r,i){let a;try{a=await e(`${t.replace(/\/+$/,``)}/functions/v1/${n}`,{method:`POST`,headers:r,body:i===void 0?void 0:JSON.stringify(i)})}catch(e){throw new V1(0,`network`,e?.message??String(e))}let o=await a.text(),s=null;try{s=JSON.parse(o)}catch{}if(a.status!==200)throw new V1(a.status,s?.error??`error`,s?.message??s?.error??o);return s}async function U1(e,t,n=fetch){let{auth:r}=Ee(t),{token:i}=await H1(n,e,`stream-token`,{"x-api-key":r}),a=await H1(n,e,`stream-publisher`,{Authorization:`Bearer ${i}`,"Content-Type":`application/json`},{action:`usage`});return{limits:a.limits??{},usage:a.usage}}var W1=e=>Uint8Array.from(atob(e),e=>e.charCodeAt(0)),G1=class{opts;deps;auth;secret;password;token=``;ticket=``;relayUrl=null;apiKeyId=null;projectId=null;e2ee=!1;sid=null;salt=``;key=null;raw=null;epoch=0;haveKey=!1;sealed=null;device=null;senderDeviceId=null;deviceRetried=!1;maxBytesPerSec=0;maxMessageBytes=N1;ws=null;open=!1;everOpen=!1;connectedAt=0;authAt=0;delay=1e3;lastToken=0;viewerCount=0;busy=!1;stopped=!1;refusal=null;heartbeatTimer=null;pingTimer=null;retryTimer=null;statusFns=new Set;viewerFns=new Set;lastStatus=``;wire;usage=null;bitrate=null;noticeCode=null;constructor(e,t){let{auth:n,secret:r}=Ee(e.apiKey);if(!r)throw Error(`This API key has no encryption secret (created before keys carried one). Create a new API key in Kymoscope.`);if(e.kind===`camera`&&!e.parentStreamId)throw Error(`A camera is added to one of your live streams: choose its stream (parentStreamId).`);if(!!e.layer!=!!e.lowOf)throw Error(`A low layer needs both layer: 'low' and lowOf (its high camera's stream id).`);if(e.layer&&e.kind!==`camera`)throw Error(`Only a camera has a low layer.`);let i=B1(e.profile,e.kind);if(!i)throw Error(`profile is required: mode plus hz/channels (or sources) and bytes_per_sec, or quality/fps for a camera`);if(this.wire=Object.freeze(i),e.visibility===`open`&&e.password)throw Error(`An open stream has no password: anyone may watch it. Remove the password, or use visibility 'private'.`);this.opts=e,this.deps=t,this.auth=n,this.secret=r,this.password=e.visibility===`open`?C:e.password||r}get streamId(){return this.sid}get viewers(){return this.viewerCount}get limits(){return{maxBytesPerSec:this.maxBytesPerSec,maxMessageBytes:this.maxMessageBytes}}get usageMessage(){return this.usage}get bitrateKbps(){return this.bitrate}get profile(){return this.wire}onStatus(e){return this.statusFns.add(e),()=>{this.statusFns.delete(e)}}onViewers(e){return this.viewerFns.add(e),()=>{this.viewerFns.delete(e)}}async start(){this.emit();try{let t=await this.deps.store.load();this.salt=t?.salt??h();let n=await this.mint();this.token=n.token,this.relayUrl=n.relayUrl??null,this.maxBytesPerSec=n.maxBytesPerSec||0,this.maxMessageBytes=n.maxMessageBytes||N1,this.apiKeyId=n.apiKeyId??null;let r=n.project;this.e2ee=!!r?.e2ee;let a={};if(this.e2ee){this.projectId=r?.id??null;let n=t?.apiKeyId===this.apiKeyId;this.device=n&&t?.device||await i(),n&&t?.streamKey?{key:this.key,epoch:this.epoch,sealed:this.sealed}=t.streamKey:this.key=await p(e()),a.sender_device=await this.senderDevice()}else this.raw=W1(await S(this.password,this.salt)),this.key=await p(this.raw);let o=await this.register(t?.streamId??null,a);if(this.sid=o.stream.id,this.ticket=o.ticket,this.admitted(o),this.e2ee?(this.senderDeviceId=o.sender_device_id??null,this.projectId=o.project?.id??this.projectId,await this.save(),await this.applyProject(o.project)):(await this.save(),await this.wrapFor(o.devices)),!this.relayUrl)throw Error(`stream-token returned no relayUrl`)}catch(e){throw e instanceof V1&&e.status>=400&&e.status<500&&this.refuse(e),e}this.stopped||(this.lastToken=this.deps.now(),this.connect(),this.heartbeatTimer=setInterval(()=>{this.housekeeping()},D1),this.emit())}async send(e,t){if(this.stopped||!this.open)return!1;let n=await this.seal(e,t);return!!n&&this.sendSealed(n)}async seal(e,t){let n=this.key,r=this.e2ee?this.epoch&255:void 0;return this.stopped||!n||this.e2ee&&!this.haveKey?null:new Uint8Array(await re(n,e,t,r))}sendSealed(e){let t=this.ws;if(!this.open||!t)return!1;try{return t.send(e),!0}catch{return!1}}recordingUpload(e){return this.post(`recording-upload`,{Authorization:`Bearer ${this.token}`,"Content-Type":`application/json`},e)}stop(){!this.stopped&&this.sid&&this.call({action:`offline`,stream_id:this.sid}).catch(()=>{}),this.stopped=!0,this.heartbeatTimer&&clearInterval(this.heartbeatTimer),this.retryTimer&&clearTimeout(this.retryTimer),this.heartbeatTimer=this.retryTimer=null;let e=this.ws;if(this.disconnect(),e){e.onopen=e.onmessage=e.onclose=null;try{e.close(1e3)}catch{}}}post(e,t,n){return H1(this.deps.fetch,this.opts.supabaseUrl,e,t,n)}mint(){return this.post(`stream-token`,{"x-api-key":this.auth})}call(e){return this.post(`stream-publisher`,{Authorization:`Bearer ${this.token}`,"Content-Type":`application/json`},e)}async register(e,t){let n={action:`register`,name:this.opts.name,salt:this.salt,key_check:await b(this.key),visibility:this.opts.visibility??`private`,kind:this.opts.kind,profile:this.wire,...t};return this.opts.kind===`camera`&&(n.parent_stream_id=this.opts.parentStreamId),this.opts.layer&&(n.layer=this.opts.layer,n.low_of=this.opts.lowOf),e&&(n.stream_id=e),this.call(n)}admitted(e){this.usage=typeof e.usage?.message==`string`?e.usage.message:null,this.bitrate=typeof e.bitrate_kbps==`number`?e.bitrate_kbps:null}notice(e){let t=e?.notice,n=typeof t?.code==`string`?t.code:null;if(n&&n!==this.noticeCode)try{this.opts.onNotice?.({code:n,message:String(t.message??n)})}catch{}this.noticeCode=n}async senderDevice(){let e=this.device.publicKey;return{public_key:e,binding:await ce(await He(this.secret),this.apiKeyId??``,e)}}async housekeeping(){if(!(this.busy||this.stopped)){this.busy=!0;try{let e=this.deps.now();if(e-this.lastToken>=O1){this.lastToken=e;try{this.token=(await this.mint()).token}catch{return}}if(this.e2ee){let e=await this.call({action:`heartbeat`,stream_id:this.sid,sender_device_id:this.senderDeviceId,epoch:this.haveKey?this.epoch:0});this.setTicket(e.ticket),this.notice(e),await this.applyProject(e.project)}else{let e=await this.call({action:`heartbeat`,stream_id:this.sid});this.setTicket(e.ticket),this.notice(e),await this.wrapFor(e.devices)}}catch(e){e instanceof V1&&(e.status===401||e.status===403)&&this.refuse(e)}finally{this.busy=!1}}}async wrapFor(e){let t=[];for(let n of e??[])try{t.push({device_id:n.id,wrapped:await ie(n.public_key,this.raw,`${this.sid}|${n.id}`)})}catch{}if(t.length)try{await this.call({action:`wrap_keys`,stream_id:this.sid,keys:t.slice(0,P1)})}catch{}}async applyProject(t){if(!this.e2ee||!t)return;let n=t.key;if(!n){this.emit();return}let r=Number(n.epoch);if(this.haveKey&&r<=this.epoch)return;let a;try{a=await ue(this.device.privateKey,n.wrapped,k(this.projectId,r,this.senderDeviceId))}catch{if(this.deviceRetried)return;this.deviceRetried=!0,this.device=await i(),await this.reregister();return}let o=Ke(this.sid,this.projectId,r),s=this.key,c=r===this.epoch?this.sealed:null;if(c)try{await Ie(a,c,o)}catch{c=null}if(!c){let t=e();s=await p(t),c=await be(a,t,o),t.fill(0)}try{await this.call({action:`wrap_keys`,stream_id:this.sid,sender_device_id:this.senderDeviceId,project_wrap:{epoch:r,iv:c.iv,ct:c.ct}})}catch{return}this.stopped||(this.key=s,this.sealed=c,this.epoch=r,this.haveKey=!0,await this.save(),this.emit())}async reregister(){let e;try{e=await this.register(this.sid,{sender_device:await this.senderDevice()})}catch{return}this.ticket=e.ticket,this.admitted(e),this.senderDeviceId=e.sender_device_id??null;let t=e.stream.id;if(t!==this.sid){this.sid=t;let e=this.ws;if(e){this.disconnect(),e.onopen=e.onmessage=e.onclose=null;try{e.close(1e3)}catch{}this.connect()}}await this.save(),await this.applyProject(e.project),this.deviceRetried=!1}async save(){try{await this.deps.store.save({apiKeyId:this.apiKeyId,streamId:this.sid,salt:this.salt,device:this.e2ee?this.device:null,streamKey:this.e2ee&&this.haveKey?{epoch:this.epoch,key:this.key,sealed:this.sealed}:null})}catch{}}connect(){if(this.retryTimer=null,this.stopped)return;let e=this.relayUrl.replace(/\/+$/,``).replace(/^http(s?):\/\//,`ws$1://`),t;try{t=new this.deps.WebSocket(`${e}/v1/streams/${this.sid}/publish`,[KQ,`bearer.${this.ticket}`])}catch{this.dropped();return}t.binaryType=`arraybuffer`,this.ws=t,t.onopen=()=>{t===this.ws&&(this.open=this.everOpen=!0,this.connectedAt=this.authAt=this.deps.now(),this.pingTimer=setInterval(()=>{try{t.send(`ping`)}catch{}},A1),this.emit())},t.onmessage=e=>{if(!(t!==this.ws||typeof e.data!=`string`||!e.data.startsWith(`{`)))try{let t=JSON.parse(e.data);t?.type===`viewers`&&this.setViewers(Number(t.count)||0)}catch{}},t.onclose=()=>{t===this.ws&&this.dropped()}}disconnect(){this.ws=null,this.open=!1,this.pingTimer&&clearInterval(this.pingTimer),this.pingTimer=null,this.setViewers(0)}dropped(){let e=this.open&&this.deps.now()-this.connectedAt>=M1;if(this.disconnect(),this.stopped)return;let t=0;e?this.delay=1e3:(t=this.delay,this.delay=Math.min(this.delay*2,j1)),this.retryTimer=setTimeout(()=>this.connect(),t),this.emit()}setTicket(e){this.ticket=e;let t=this.deps.now();if(!(!this.open||!this.ws||t-this.authAt<k1))try{this.ws.send(JSON.stringify({type:`auth`,token:e})),this.authAt=t}catch{}}setViewers(e){if(e!==this.viewerCount){this.viewerCount=e;for(let t of this.viewerFns)t(e);this.emit()}}refuse(e){this.refusal={code:e.code,message:e.detail},this.emit(),this.stop()}status(){return this.refusal?{phase:`refused`,...this.refusal}:this.sid?this.e2ee&&!this.haveKey?{phase:`waiting_approval`}:this.open?{phase:`live`,viewers:this.viewerCount}:this.everOpen?{phase:`reconnecting`}:{phase:`registering`}:{phase:`registering`}}emit(){let e=this.status(),t=JSON.stringify(e);if(t!==this.lastStatus){this.lastStatus=t;for(let t of this.statusFns)t(e)}}},K1={"360p":{width:640,height:360},"480p":{width:854,height:480},"720p":{width:1280,height:720},"1080p":{width:1920,height:1080}},q1={width:640,height:360,fps:15,kbps:400},J1=[`avc1.640028`,`avc1.4d0028`,`avc1.42e028`],Y1=[`avc1.64001f`,`avc1.4d001f`,`avc1.42e01f`],X1=2,Z1=1e3,Q1=1e3;async function*$1(e){if(typeof MediaStreamTrackProcessor<`u`){let t=new MediaStreamTrackProcessor({track:e}).readable.getReader();try{for(;;){let{value:e,done:n}=await t.read();if(n)return;yield e}}finally{t.cancel().catch(()=>{})}}let t=document.createElement(`video`);t.muted=!0,t.playsInline=!0,t.srcObject=new MediaStream([e]),await t.play();try{for(;e.readyState===`live`;)await new Promise(e=>t.requestVideoFrameCallback(()=>e())),yield new VideoFrame(t,{timestamp:Math.round(performance.now()*1e3)})}finally{t.pause(),t.srcObject=null}}function e0(){let e=null;return(t,n,r)=>(e??=new OffscreenCanvas(n,r).getContext(`2d`),e.drawImage(t,0,0,n,r),new VideoFrame(e.canvas,{timestamp:t.timestamp}))}var t0=class{encoder=null;codec=``;error=null;unsubscribe=null;lastKey=-1/0;keyPending=!1;resume=!0;lastViewers=0;encoding=!1;dropped=0;seq=0;times=new Map;window=[];sending=Promise.resolve();publisher;preset;keyframeMs;Encoder;now;recorder;constructor(e,t,n,r,i,a=null){if(a&&!(e.seal&&e.sendSealed))throw Error(`A recording camera needs a LivePublisher (seal, sendSealed).`);this.recorder=a,this.publisher=e,this.preset=t,this.keyframeMs=n,this.Encoder=r,this.now=i}async configure(e){let{width:t,height:n,fps:r}=this.preset,i=e*1e3,a=null;for(let e of n>720?J1:Y1){let o={codec:e,width:t,height:n,bitrate:i,framerate:r,avc:{format:`annexb`},latencyMode:`realtime`,bitrateMode:`constant`};if((await this.Encoder.isConfigSupported(o)).supported===!0){a=o;break}}return a?(this.codec=a.codec,this.encoder=new this.Encoder({output:e=>this.onChunk(e),error:e=>{this.error=e.message||String(e),this.closeEncoder()}}),this.encoder.configure(a),this.lastViewers=this.publisher.viewers,this.unsubscribe=this.publisher.onViewers(e=>{e>this.lastViewers&&(this.keyPending=!0),this.lastViewers=e}),!0):!1}ready(){let e=this.encoder;return this.encoding=!!e&&!this.error&&(this.publisher.viewers>0||!!this.recorder?.wants()),!e||!this.encoding?(this.resume=!0,!1):e.encodeQueueSize>X1?(this.dropped++,!1):!0}encode(e){let t=this.now(),n=t-this.lastKey,r=this.resume||n>=this.keyframeMs||this.keyPending&&n>=Z1;r&&(this.lastKey=t,this.keyPending=this.resume=!1);let i=(performance.timeOrigin+e.timestamp/1e3)/1e3;Math.abs(i-Date.now()/1e3)>60&&(i=Date.now()/1e3),this.times.set(e.timestamp,i),this.encoder.encode(e,{keyFrame:r})}onChunk(e){let t=new Uint8Array(e.byteLength);e.copyTo(t);let n=this.times.get(e.timestamp)??Date.now()/1e3;this.times.delete(e.timestamp);let{width:r,height:i}=this.preset,a=e.type===`key`,o=s$({key:a,t:n,seq:this.seq++,width:r,height:i,codec:this.codec,data:t}),s=this.recorder,c=this.publisher;o.forEach((e,t)=>{this.sending=this.sending.then(async()=>{if(!s)return c.send(6,e);let r=await c.seal(6,e);return r?(s.add(r,n*1e3,a&&t===0),c.viewers>0&&c.sendSealed(r)):!1}).catch(()=>!1)}),this.window.push({at:this.now(),bytes:t.length})}get queue(){return this.encoder?.state===`configured`?this.encoder.encodeQueueSize:0}stats(){let e=this.now();for(;this.window.length&&e-this.window[0].at>=Q1;)this.window.shift();let t=this.window.reduce((e,t)=>e+t.bytes,0);return{fps:this.window.length,kbps:t*8/1e3,viewers:this.publisher.viewers,encoding:this.encoding}}stop(){this.encoding=!1,this.closeEncoder(),this.unsubscribe?.(),this.unsubscribe=null}closeEncoder(){this.encoder&&this.encoder.state!==`closed`&&this.encoder.close()}},n0=class{high;lowOpt;low=null;lowAt=-1/0;keyframeMs;Encoder;now;frames;scale;stopped=!1;statsFns=new Set;lastStats=-1/0;constructor(e,t={},n={}){let{quality:r,fps:i}=e.profile,a=r?K1[r]:void 0;if(!a||!i)throw Error(`A CameraSender needs a camera publisher (profile quality and fps).`);this.keyframeMs=(t.keyframeS??2)*1e3,this.Encoder=n.VideoEncoder??VideoEncoder,this.now=n.now??Date.now,this.frames=n.frames??$1,this.scale=n.scale??e0(),this.high=new t0(e,{...a,fps:i},this.keyframeMs,this.Encoder,this.now,t.recorder??null),this.lowOpt=t.low?{publisher:t.low.publisher,preset:t.low.preset??q1}:null}async start(e){let t=this.high.publisher.bitrateKbps;if(t==null)throw Error(`The camera has no bitrate: start its LivePublisher first (register answers it).`);if(!await this.high.configure(t))throw new ME(`camera_codec_unsupported`);if(this.lowOpt){let e=new t0(this.lowOpt.publisher,this.lowOpt.preset,this.keyframeMs,this.Encoder,this.now);await e.configure(this.lowOpt.publisher.bitrateKbps??this.lowOpt.preset.kbps)&&(this.low=e)}this.loop(e)}async loop(e){for await(let t of this.frames(e)){if(this.stopped){t.close();break}try{this.onFrame(t)}finally{t.close()}this.emitStats()}}onFrame(e){this.high.ready()&&this.high.encode(e);let t=this.low;if(!t)return;let n=this.now();if(n-this.lowAt<750/t.preset.fps||!t.ready())return;this.lowAt=n;let r=this.scale(e,t.preset.width,t.preset.height);try{t.encode(r)}finally{r.close()}}stats(){return{...this.high.stats(),dropped:this.high.dropped,queue:this.high.queue,error:this.high.error,low:this.low?this.low.stats():null}}onStats(e){return this.statsFns.add(e),()=>{this.statsFns.delete(e)}}emitStats(){let e=this.now();if(e-this.lastStats<Q1||!this.statsFns.size)return;this.lastStats=e;let t=this.stats();for(let e of this.statsFns)e(t)}stop(){this.stopped=!0,this.high.stop(),this.low?.stop()}},r0=new TextEncoder,i0={appstream2:`appstream`,cloudhsmv2:`cloudhsm`,email:`ses`,marketplace:`aws-marketplace`,mobile:`AWSMobileHubService`,pinpoint:`mobiletargeting`,queue:`sqs`,"git-codecommit":`codecommit`,"mturk-requester-sandbox":`mturk-requester`,"personalize-runtime":`personalize`},a0=new Set([`authorization`,`content-type`,`content-length`,`user-agent`,`presigned-expires`,`expect`,`x-amzn-trace-id`,`range`,`connection`]),o0=class{constructor({accessKeyId:e,secretAccessKey:t,sessionToken:n,service:r,region:i,cache:a,retries:o,initRetryMs:s}){if(e==null)throw TypeError(`accessKeyId is a required option`);if(t==null)throw TypeError(`secretAccessKey is a required option`);this.accessKeyId=e,this.secretAccessKey=t,this.sessionToken=n,this.service=r,this.region=i,this.cache=a||new Map,this.retries=o??10,this.initRetryMs=s||50}async sign(e,t){if(e instanceof Request){let{method:n,url:r,headers:i,body:a}=e;t=Object.assign({method:n,url:r,headers:i},t),t.body==null&&i.has(`Content-Type`)&&(t.body=a!=null&&i.has(`X-Amz-Content-Sha256`)?a:await e.clone().arrayBuffer()),e=r}let n=new s0(Object.assign({url:e.toString()},t,this,t&&t.aws)),r=Object.assign({},t,await n.sign());delete r.aws;try{return new Request(r.url.toString(),r)}catch(e){if(e instanceof TypeError)return new Request(r.url.toString(),Object.assign({duplex:`half`},r));throw e}}async fetch(e,t){for(let n=0;n<=this.retries;n++){let r=fetch(await this.sign(e,t));if(n===this.retries)return r;let i=await r;if(i.status<500&&i.status!==429)return i;await new Promise(e=>setTimeout(e,Math.random()*this.initRetryMs*2**n))}throw Error(`An unknown error occurred, ensure retries is not negative`)}},s0=class{constructor({method:e,url:t,headers:n,body:r,accessKeyId:i,secretAccessKey:a,sessionToken:o,service:s,region:c,cache:l,datetime:u,signQuery:d,appendSessionToken:f,allHeaders:p,singleEncode:m}){if(t==null)throw TypeError(`url is a required option`);if(i==null)throw TypeError(`accessKeyId is a required option`);if(a==null)throw TypeError(`secretAccessKey is a required option`);this.method=e||(r?`POST`:`GET`),this.url=new URL(t),this.headers=new Headers(n||{}),this.body=r,this.accessKeyId=i,this.secretAccessKey=a,this.sessionToken=o;let h,g;(!s||!c)&&([h,g]=p0(this.url,this.headers)),this.service=s||h||``,this.region=c||g||`us-east-1`,this.cache=l||new Map,this.datetime=u||new Date().toISOString().replace(/[:-]|\.\d{3}/g,``),this.signQuery=d,this.appendSessionToken=f||this.service===`iotdevicegateway`,this.headers.delete(`Host`),this.service===`s3`&&!this.signQuery&&!this.headers.has(`X-Amz-Content-Sha256`)&&this.headers.set(`X-Amz-Content-Sha256`,`UNSIGNED-PAYLOAD`);let _=this.signQuery?this.url.searchParams:this.headers;if(_.set(`X-Amz-Date`,this.datetime),this.sessionToken&&!this.appendSessionToken&&_.set(`X-Amz-Security-Token`,this.sessionToken),this.signableHeaders=[`host`,...this.headers.keys()].filter(e=>p||!a0.has(e)).sort(),this.signedHeaders=this.signableHeaders.join(`;`),this.canonicalHeaders=this.signableHeaders.map(e=>e+`:`+(e===`host`?this.url.host:(this.headers.get(e)||``).replace(/\s+/g,` `))).join(`
|
|
618
|
-
`),this.credentialString=[this.datetime.slice(0,8),this.region,this.service,`aws4_request`].join(`/`),this.signQuery&&(this.service===`s3`&&!_.has(`X-Amz-Expires`)&&_.set(`X-Amz-Expires`,`86400`),_.set(`X-Amz-Algorithm`,`AWS4-HMAC-SHA256`),_.set(`X-Amz-Credential`,this.accessKeyId+`/`+this.credentialString),_.set(`X-Amz-SignedHeaders`,this.signedHeaders)),this.service===`s3`)try{this.encodedPath=decodeURIComponent(this.url.pathname.replace(/\+/g,` `))}catch{this.encodedPath=this.url.pathname}else this.encodedPath=this.url.pathname.replace(/\/+/g,`/`);m||(this.encodedPath=encodeURIComponent(this.encodedPath).replace(/%2F/g,`/`)),this.encodedPath=
|
|
612
|
+
`),A=ft(()=>{let e=i.filter(e=>e.kind!==`memory`).flatMap(e=>wz(e.schema));return e.length?e:null},[i]),j=ft(()=>i.some(e=>e.kind!==`memory`)||!g&&i.some(e=>e.data.rows.length>uZ),[i,g]),M=ft(()=>GX(f.connections.filter(e=>r.includes(e.id)),i.length,j,d,o),[j,i,f.connections,r,o,d]),N=ft(()=>{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 yZ(e,d)},[g,i,j,D,o,d,f.connections,r,M]),P=S&&`okByPart`in S?S.okByPart:void 0,F=ft(()=>{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:gZ(i,r,d),columnSet:new Set([d,...r]),key:`${e[n].key}|channels`})}),e},[j,w,T,o,P,D,d]),I=ft(()=>{let e=S?.parts??(C?[C]:[]),t=new Set;for(let n of e)for(let e of JX(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(`
|
|
613
|
+
`).filter(e=>!i.has(e));return a.length?[...r,...a]:r},[O,k,A]),L=ft(()=>{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=ft(()=>{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(xe(C.rows,d,n,uZ));else{let e=Math.max(1,Math.floor(uZ/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(xe(a,d,n,e,`__${t}`,o[i.id]??0))}}e[t]=r}return e},[C,L,d,T,w,o,D,M,j]),z=ft(()=>{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=>vZ(e,i),l;if(!T)l=a(r);else{let e=a(r);l=[];for(let t=0;t<w.length;t++){let n=Zz(s,w[t].id,t,c);for(let r of e)l.push({...r,id:`${r.id}__${t}`,column:`${r.column}__${t}`,color:n})}}let f=R[t.id]??[],p=T&&n?.kind===`multiband`&&n.envelope?r.flatMap(e=>{let t=HX(f.flatMap((t,n)=>{let r=t.cols.get(`${e.column}__${n}`);return r?[{x:t.x,y:r}]:[]}),mZ);return t?[{seriesId:e.id,color:e.color,...t}]:[]}):void 0,m=w.flatMap((e,t)=>`bands`in e&&e.bands?iZ(e,d,r,T?Zz(s,e.id,t,c):void 0,o[e.id]??0):[]),h=[...p??[],...m];e[t.id]={effectiveSeries:l,points:f,envelopes:h.length?h:void 0}}return e},[C,l,u,d,T,w,s,c,o,R]),B=ft(()=>{let e={pts:{},colorMeta:{},datasetColors:{}};if(!C)return e;let t={},r={},i={},a=pZ,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}=WW(o,l,p,{xKey:d,viewXRange:n,colorOverrides:s,palette:c});t[e.id]=r,i[e.id]=a;continue}let m=UW(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=K(new Map),ee=ft(()=>{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=LW(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=LW(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?LW(r,s,i):void 0,p=c?LW(r,c,i):void 0,m=l?LW(r,l,i):void 0;if(!f||!p||!m){e[a.id]={points:t};continue}let h=n?LW(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]),te=ft(()=>{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&&RW(C.rows,n.histColumn,E)||new Float64Array}return e},[C,l,u,E]),H=ft(()=>{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?LW(C.rows,n.polarAngleCol,E):void 0,i=n?.kind===`polar`&&n.polarRadiusCol?LW(C.rows,n.polarRadiusCol,E):void 0;e[t.id]=r&&i?{angles:r,radii:i}:{angles:[],radii:[]}}return e},[C,l,u,E]),ne=(e,t,n,r)=>{let i=t&&RW(e,t,E)||new Float64Array,a=n?LW(e,n,E):void 0;return{signal:i,rate:a&&BW(a)||parseFloat(r)||1}},re=ft(()=>{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]=ne(C.rows,n.specSignalCol,n.specTimeCol,n.specSampleRate))}return e},[C,l,u,E]),ie=ft(()=>{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?zW(C.rows,n.boxValueCol,n.boxGroupCol||void 0,E):[]}return e},[C,l,u,E]),U=ft(()=>{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]=ne(C.rows,n.sgSignalCol,n.sgTimeCol,n.sgSampleRate))}return e},[C,l,u,E]),ae=ft(()=>{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=LW(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=LW(r,d,E),s,c;if(n.hmSpacing===`values`){o&&eJ(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&&eJ(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]=sZ(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);eJ(e)&&(f=e),eJ(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]),oe=ft(()=>{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?zW(C.rows,n.vlValueCol,n.vlGroupCol||void 0,E):[]}return e},[C,l,u,E]),se=ft(()=>{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]),ce=ft(()=>{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?LW(C.rows,n.rocScoreCol,E):void 0,i=n?.kind===`roc`&&n.rocLabelCol?LW(C.rows,n.rocLabelCol,E):void 0;e[t.id]=r&&i?{scores:r,labels:i}:{scores:[],labels:[]}}return e},[C,l,u,E]),le=ft(()=>{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:LW(t,e,E)??new Float64Array,axis:r})),c=s[0]?.values.length??t.length,l=i&&LW(t,i,E)||Float64Array.from({length:c},(e,t)=>t);e[n.id]={xValues:l,series:s}}return e},[C,l,u,E]),ue=ft(()=>{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?LW(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]),de=ft(()=>{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=>LW(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=LW(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]),fe=ft(()=>{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=LW(t,a,E),f=LW(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=LW(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]),pe=ft(()=>{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]),me=ft(()=>{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=>LW(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]),he=ft(()=>{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=>LW(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]),ge=ft(()=>{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=>LW(r,e,E)),a=i[0]?.length??r.length,o=(n.acXCol?LW(r,n.acXCol,E):void 0)??CZ(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]),_e=ft(()=>{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:RW(C.rows,e,E)??new Float64Array}))}return e},[C,l,u,E]),ve=ft(()=>{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=LW(t,i.bbXCol,E),o=LW(t,i.bbYCol,E),s=LW(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=LW(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]),ye=ft(()=>{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]),be=ft(()=>{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]),Se=ft(()=>{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?LW(C.rows,n.cbScoreCol,E):void 0,i=n?.kind===`calibration`&&n.cbLabelCol?LW(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]),Ce=ft(()=>{let e={};if(!C)return e;let t={length:0,theoretical:[],sample:[]},n=e=>{let t=RW(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]),we=ft(()=>{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]),Te=C&&C.columnNames.indexOf(d)>=0?C.units[C.columnNames.indexOf(d)]??``:``,Ee=ft(()=>C?bZ(C,T?w.length:0):{},[C,T,w]);return{dataset:y,datasetWithChannels:C,multiDatasetMode:T,numericCols:I,anyDuckDb:j,duckDbLayers:F,liveConn:_,liveOverlays:M,hasLiveSelected:g,staticXRange:N,xUnit:Te,columnUnits:Ee,multibandDataByPanel:z,xyPointsByPanel:B,xyzPointsByPanel:ee,histogramDataByPanel:te,polarDataByPanel:H,spectrumDataByPanel:re,boxplotDataByPanel:ie,spectrogramDataByPanel:U,heatmapDataByPanel:ae,violinDataByPanel:oe,confusionDataByPanel:se,rocDataByPanel:ce,lossCurveDataByPanel:le,controlChartDataByPanel:ue,parallelCoordsDataByPanel:de,embeddingDataByPanel:fe,flameGraphDataByPanel:pe,barChartDataByPanel:me,radarDataByPanel:he,areaChartDataByPanel:ge,cdfChartDataByPanel:_e,bubbleChartDataByPanel:ve,treemapDataByPanel:ye,sankeyDataByPanel:be,calibrationDataByPanel:Se,qqPlotDataByPanel:Ce,ganttDataByPanel:we,gaugeDataByPanel:ft(()=>{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?LW(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]=TZ(s?i:0,s?a:1,t(e.min),t(e.max));return[{name:n,unit:Ee[n]??``,value:l,min:u,max:d,alarm:e.alarm??null,color:e.color,style:e.style,fromZero:e.fill===`zero`,colorMode:e.colorMode,stops:e.stops,stat:e.value}]})}return e},[C,l,u,E,Ee])}}function TZ(e,t,n,r){t<=e&&(t=e+1);let i=Dz(t-e,5),a=n??Math.floor(e/i)*i,o=r??Math.ceil(t/i)*i;return o>a?[a,o]:[a,a+1]}var EZ=`#fb7185`,DZ=2500;function OZ(e){let t=[],n=(e,r)=>{if(typeof e==`string`){e&&(r===`column`||/(Col|Cols|Column|Columns)$/.test(r))&&t.push(e);return}if(Array.isArray(e)){for(let t of e)n(t,r);return}if(e&&typeof e==`object`)for(let[t,r]of Object.entries(e))t!==`addColumn`&&n(r,t)};return n(e,``),[...new Set(t)]}function kZ(e){let t=AZ(e);if(t.status!==`empty`||!e.data.dataset)return t;let n=new Set([...e.data.datasetWithChannels?.columnNames??[],...e.data.numericCols]);return OZ(e.settings).some(e=>!n.has(e))?{...t,status:`missing`}:t}function AZ(e){let{panel:t,data:n,settings:r}=e;if(t.kind===`camera`)return{status:`ready`,data:null,node:q(PX,{settings:r?.kind===`camera`?r:Un(),live:e.live??[],selection:e.selection??[],viewXRange:e.viewXRange,xIsTime:e.xKey===$e,xKey:e.xKey,video:e.video,recordings:e.recordings,cursor:e.cursor,onContextMenu:t=>e.onContextMenu(t)})};if(!n.dataset)return{status:`no-data`,node:null,data:null};let i=`${e.background??`theme`}|${e.styleToken}`,a=t=>e.onContextMenu(t),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=e.xKey===`ElapsedTime`&&!n.numericCols.includes(`Time`)?`Time`:e.xKey,m={xLabel:n.xUnit?`${p} (${n.xUnit})`:p,series:u,columnUnits:n.columnUnits,height:e.height,backgroundToken:i,viewXRange:e.viewXRange,onViewXRangeChange:e.onViewXRangeChange,onCursorX:e.onCursorX,liveZoom:e.liveZoom,liveZoomId:c,xAxisLine:d?.xAxisLine,yAxisLine:d?.yAxisLine,gridLine:d?.gridLine,lineWidth:d?.lineWidth,onPlotContextMenu:a,shiftMode:e.shiftMode},h=d?.beacon;if(h?.enabled&&e.beaconLive&&f.length>0){let t=vZ((d?.series??[]).filter(t=>t.column!==e.xKey),d?.layout??`overlay`),n=h.reference===`dataset`&&h.datasetId?e.findDataset(h.datasetId):void 0,r=rZ(h,!!n),i=r?[...ZX(t,r),...t]:t;return o(q(pW,{...m,series:i,points:[],showLatestValues:!0,liveSource:nZ(e.beaconLive,e.xKey,f,h,n),envelopes:n?iZ(n,e.xKey,t,r??void 0):void 0,liveZoomMode:`free`}),{series:i,points:[]})}if(n.anyDuckDb)return u.length===0?s:o(q(PW,{...m,layers:n.duckDbLayers,xKey:e.xKey,columns:f,maxPoints:DZ}),{series:u,columns:f});if(!l.some(e=>e.length>0)&&!n.liveOverlays||u.length===0||!f.some(e=>n.numericCols.includes(e)))return s;let g=n.liveConn,_=null,v=n.liveOverlays,y=!g&&v&&f.length>0?KX(v,e.xKey,f,l,n.staticXRange):void 0,b=!!y&&l.length>0,x=y??(g&&f.length>0?{pull:(t,n,r,i,a)=>{let o=g.source.version();if(a){let i=2**Math.ceil(Math.log2((n-t)/8)),a=Math.floor(t/i)*i,s=Math.ceil(n/i)*i,c=Math.round(r*(s-a)/(n-t));return(!_||_.ver!==o||_.x0!==a||_.x1!==s||Math.abs(_.mp-c)>c*.25)&&(_={ver:o,x0:a,x1:s,mp:c,pts:g.source.getPointsSync(f,{xKey:e.xKey,x0:a,x1:s},c),held:E(f,e=>g.source.lastKnownSync(e),a,s,g.source.latestTimeSync())}),_.held?[_.pts,_.held]:[_.pts]}(!_||_.ver!==o||_.x0!==t||_.x1!==n||_.mp!==r)&&(_={ver:o,x0:t,x1:n,mp:r,pts:g.source.getPointsSync(f,{xKey:e.xKey,x0:t,x1:n},r)});let s=Ye(_.pts,i);if(e.xKey!==`ElapsedTime`)return[s];let c=E(f,e=>g.source.lastKnownSync(e),t,n,Math.min(g.source.latestTimeSync(),i??1/0));return c?[s,c]:[s]},cutOnGpu:e.xKey===`ElapsedTime`,id:g.id,latestT:()=>g.source.latestTimeSync(),xAtTime:t=>g.source.xAtTimeSync(e.xKey,t),xBounds:()=>{let t=g.source.xBoundsSync(e.xKey);return t.x1>t.x0?[t.x0,t.x1]:null},latestX:()=>{let t=g.source.latestSync(e.xKey);return Number.isFinite(t)?t:null},version:()=>g.source.version(),latestValues:e=>g.source.latestValuesSync(e),...e.xKey===`ElapsedTime`?{}:{spanForSeconds:t=>g.source.xTravelSync(e.xKey,t),bufferedSeconds:()=>{let e=g.source.xBoundsSync(`ElapsedTime`);return e.x1-e.x0}}}:void 0);return o(q(pW,{...m,points:l,envelopes:t?.envelopes,showLatestValues:n.hasLiveSelected,fullXRange:n.staticXRange,liveSource:x,liveWindowSeconds:b?null:e.liveWindowSeconds,onLiveWindowChange:b?void 0:e.onLiveWindowChange,liveZoomMode:b?`free`:`follow`}),{series:u,points:l})}case`xyzmesh`:{let t=r?.kind===`xyzmesh`?r:gn(4),l=n.xyzPointsByPanel[c];if(!l||l.points.length<1&&!l.surface)return s;let u=!!l.surface;return o(q(RK,{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:un(t.xyzXScale.scaleMin,t.xyzXScale.scaleMax),yRange:un(t.xyzYScale.scaleMin,t.xyzYScale.scaleMax),zRange:un(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:hn(EZ),l=n.xyPointsByPanel.pts[c]??[];if(l.length===0)return s;let u=n.xyPointsByPanel.colorMeta[c];return o(q(EG,{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(q(GK,{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(q(lq,{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(q(Tq,{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(q(jq,{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(q(Yq,{signal:e,sampleRate:t,windowSize:r.sgWindowSize,overlap:r.sgOverlap,winFunc:r.sgWinFunc,yMode:r.sgYMode,backgroundToken:i,onPlotContextMenu:a}),e):o(q(Wq,{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(q(mJ,{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(q(SJ,{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(q(kJ,{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(q(FJ,{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(q(LJ,{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(q(UJ,{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(q(YJ,{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(q(aY,{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(q(pY,{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(q(yY,{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(q(CY,{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(q(DY,{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(q(AY,{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(q(RY,{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(q(UY,{nodes:e,backgroundToken:i,onPlotContextMenu:a}),e)}case`sankey`:{let e=n.sankeyDataByPanel[c]??{nodeNames:[],links:[]};return e.links.length===0?s:o(q(YY,{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(q(ZY,{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(q($Y,{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.liveOverlays?.length===1?n.liveOverlays[0].conn:void 0);return o(q(mX,{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(q(iX,{tasks:e,backgroundToken:i,onPlotContextMenu:a}),e)}}return s}var jZ=500,MZ=1e3;function NZ(e){if(Array.isArray(e))return PZ(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,PZ(n)));return t<0?null:t}function PZ(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 FZ(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 IZ({stats:e,host:t}){let[n,r]=pt(null);if(W(()=>{let n=t.current?.ownerDocument.defaultView??window,i=0,a=0,o=0,s=-1,c=-1,l=e.renders,u=t.current?LH(t.current):0,d=f=>{c>=0&&f-s>MZ&&(c=f,s=f,a=0,o=0,l=e.renders,u=t.current?LH(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>=jZ){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?LH(i):0;r({fps:a*1e3/p,repaints:(m-u)*1e3/p,worstFrameMs:o,renderMs:e.lastRenderMs,rendersPerSec:(e.renders-l)*1e3/p,points:NZ(e.data),domNodes:i?i.getElementsByTagName(`*`).length:0,canvasMp:s/1e6,heapMb:d?d.usedJSHeapSize/1048576:null}),a=0,o=0,c=f,l=e.renders,u=m}i=n.requestAnimationFrame(d)};return i=n.requestAnimationFrame(d),()=>n.cancelAnimationFrame(i)},[e,t]),!n)return null;let i=n.fps<20?`var(--danger, #e5484d)`:n.fps<45?`var(--accent, #f5a524)`:void 0;return q(`dl`,{className:`kymo-perf-hud`,style:LZ,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`,FZ(n.points)]],[`DOM nodes`,FZ(n.domNodes)],[`Canvas`,`${n.canvasMp.toFixed(2)} MP`],...n.heapMb===null?[]:[[`JS heap`,`${n.heapMb.toFixed(0)} MB`]]].map(([e,t,n])=>vt(`div`,{style:RZ,children:[q(`dt`,{style:zZ,children:e}),q(`dd`,{style:n?{...BZ,color:n}:BZ,children:t})]},e))})}var LZ={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)`},RZ={display:`flex`,justifyContent:`space-between`,gap:12},zZ={color:`var(--text-muted, #8a93a6)`},BZ={margin:0,fontWeight:600,textAlign:`right`},VZ=[],HZ=3,UZ=`data-kymo-annotation-controls`;function WZ(e,t,n,r){return e.anchor===`x`&&!r?null:e.points.map(([i,a])=>[e.anchor===`x`?hU(r,i):i*t,a*n])}function GZ(e,t,n,r,i){return t.map(([t,a])=>[e.anchor===`x`&&i?gU(i,t):KZ(t/Math.max(1,n)),KZ(a/Math.max(1,r))])}var KZ=e=>Math.round(e*1e4)/1e4,qZ=st(function({annotations:e,tool:t,plotFrame:n,onChange:r,onToolEnd:i,onSelect:a,marks:o=VZ,onMarkSelect:s}){let c=K(null),l=mt(n.subscribe,n.get),u=l?.x?l:null,[d,f]=pt({w:0,h:0}),[p,m]=pt(null),[h,g]=pt(null),[_,v]=pt(null),y=K({annotations:e,onChange:r,onToolEnd:i,onSelect:a,tool:t,selected:p,editing:h,frame:u,size:d});y.current={annotations:e,onChange:r,onToolEnd:i,onSelect:a,tool:t,selected:p,editing:h,frame:u,size:d};let b=e=>{y.current.selected!==e&&(y.current.selected=e,m(e),y.current.onSelect(e))};G(()=>{let e=c.current;if(!e)return;let t=e.ownerDocument.defaultView??window,n=()=>f({w:e.clientWidth,h:e.clientHeight});n();let r=new t.ResizeObserver(n);return r.observe(e),()=>r.disconnect()},[]),W(()=>{t&&b(null)}),W(()=>{p&&!e.some(e=>e.id===p)&&b(null)}),W(()=>()=>{y.current.selected&&y.current.onSelect(null)},[]),W(()=>{let e=c.current?.ownerDocument;if(!e)return;let t=e=>{let{selected:t,editing:n,tool:r,annotations:i,onChange:a,onToolEnd:o}=y.current;if(!(n||nQ(e.target))){if(e.key===`Escape`&&r){o();return}t&&(e.key===`Delete`||e.key===`Backspace`?(e.preventDefault(),a(i.filter(e=>e.id!==t)),b(null)):e.key===`Escape`&&b(null))}},n=e=>{let t=y.current.selected,n=e.target;t&&!n?.closest?.(`[data-ann-id="${CSS.escape(t)}"], [data-kymo-annotation-controls]`)&&b(null)};return e.addEventListener(`keydown`,t),e.addEventListener(`pointerdown`,n,!0),()=>{e.removeEventListener(`keydown`,t),e.removeEventListener(`pointerdown`,n,!0)}},[]);let{w:x,h:S}=d,C=e=>{let t=c.current.getBoundingClientRect();return[e.clientX-t.left,e.clientY-t.top]},w=(e,t)=>{let n=c.current.ownerDocument,r=t=>e(C(t),t),i=()=>{n.removeEventListener(`pointermove`,r),n.removeEventListener(`pointerup`,i),n.removeEventListener(`pointercancel`,i),t()};n.addEventListener(`pointermove`,r),n.addEventListener(`pointerup`,i),n.addEventListener(`pointercancel`,i)},T=e=>r([...y.current.annotations,e]),E=e=>r(y.current.annotations.map(t=>t.id===e.id?e:t)),D=e=>{if(!t||e.button!==0||h)return;e.preventDefault(),e.stopPropagation();let n=C(e),r={id:crypto.randomUUID(),kind:t.kind,color:t.color,width:t.width,...u?{anchor:`x`}:{}},i=e=>GZ(r,e,x,S,u);if(t.kind===`text`){v({...r,points:i([n]),text:``}),g(r.id);return}let a=t.kind===`brush`?[n]:[n,n],o={...r,points:i(a)};v(o);let s=!1;w((t,n)=>{if(s||=Math.hypot(n.clientX-e.clientX,n.clientY-e.clientY)>HZ,r.kind===`brush`){let e=a[a.length-1];if(Math.hypot(t[0]-e[0],t[1]-e[1])<2)return;a=[...a,t]}else a=[a[0],t];o={...o,points:i(a)},v(o)},()=>{v(null),s&&o.points.length>=2&&T(o)})},O=(e,t,n)=>{let r=WZ(t,x,S,u);if(!r)return;let i=C(e),a=null;w((o,s)=>{if(!a&&Math.hypot(s.clientX-e.clientX,s.clientY-e.clientY)<=HZ)return;let{size:c,frame:l}=y.current;a={...t,points:GZ(t,n(r,[o[0]-i[0],o[1]-i[1]],o),c.w,c.h,l)},v(a)},()=>{v(null),a&&E(a)})},k=(e,n)=>{t||e.button!==0||h===n.id||(e.preventDefault(),e.stopPropagation(),b(n.id),O(e,n,(e,[t,n])=>e.map(([e,r])=>[e+t,r+n])))},A=(e,t,n)=>{e.button===0&&(e.preventDefault(),e.stopPropagation(),O(e,t,(e,r,i)=>{let a=e.map(e=>[...e]);return t.kind===`arrow`?a[n]=i:(a[+(n===1||n===2)][0]=i[0],a[+(n===2||n===3)][1]=i[1]),a}))},j=e=>{t||e.kind!==`text`&&e.kind!==`box`||(b(e.id),g(e.id))},M=e=>{let t=h;g(null);let n=_&&_.id===t?_:null;if(v(null),e===null||!t)return;let i=e.replace(/\s+$/,``),a=y.current.annotations;if(n){i&&T({...n,text:i});return}let o=a.find(e=>e.id===t);o&&(!i&&o.kind===`text`?r(a.filter(e=>e.id!==t)):E(tQ(o,i)))},N=e=>{r(y.current.annotations.filter(t=>t.id!==e)),b(null)},P=(_?e.some(e=>e.id===_.id)?e.map(e=>e.id===_.id?_:e):[...e,_]:e).flatMap(e=>{let t=WZ(e,x,S,u);return t?[{a:e,px:t}]:[]}),F=p?P.find(e=>e.a.id===p):void 0,I=u?o.map(e=>{let t=WZ(Rt(e,u.x.v1),x,S,u);return{m:e,x0:Math.min(t[0][0],t[1][0]),x1:Math.max(t[0][0],t[1][0])}}):[],L=F&&F.a.kind!==`text`?eQ(F.px):null,R=e=>vt(_t,{children:[q(`svg`,{className:`kymo-ann-svg`,width:x,height:S,viewBox:`0 0 ${x} ${S}`,"aria-hidden":`true`,children:e.map(({a:e,px:t})=>e.kind===`text`?null:q(`g`,{"data-ann-id":e.id,className:`kymo-ann kymo-ann--${e.kind}`,onPointerDown:t=>k(t,e),onDoubleClick:()=>j(e),children:q(XZ,{a:e,px:t})},e.id))}),e.map(({a:e,px:t})=>{if(e.kind!==`text`&&e.kind!==`box`)return null;let n=h===e.id;if(!n&&!e.text)return null;let r=e.kind===`text`?{left:t[0][0],top:t[0][1]}:{left:Math.min(t[0][0],t[1][0]),top:Math.min(t[0][1],t[1][1]),transform:`translateY(calc(-100% - 3px))`};return vt(`div`,{"data-ann-id":e.id,className:`kymo-ann-text kymo-ann-text--${e.kind}${p===e.id&&e.kind===`text`?` is-selected`:``}`,style:{...r,color:e.color,fontSize:e.kind===`text`?e.width:12},onPointerDown:t=>k(t,e),onDoubleClick:()=>j(e),children:[n?q(YZ,{initial:e.text??``,onDone:M}):e.text,p===e.id&&e.kind===`text`&&!n?q(JZ,{onDelete:()=>N(e.id),style:{right:-11,top:-11}}):null]},`t-${e.id}`)})]});return q(`div`,{ref:c,className:`kymo-annotations${t?` is-drawing is-tool-${t.kind}`:``}`,onPointerDown:D,onContextMenu:t?e=>e.preventDefault():void 0,children:x>0&&S>0?vt(_t,{children:[u&&I.length?q(`div`,{className:`kymo-ann-clip`,style:{clipPath:`inset(0 ${Math.max(0,x-u.left-u.width)}px 0 ${Math.max(0,u.left)}px)`},children:q(`svg`,{className:`kymo-ann-svg kymo-marks`,width:x,height:S,viewBox:`0 0 ${x} ${S}`,children:I.map(({m:e,x0:t,x1:n})=>vt(`g`,{"data-mark":e.ruleId,role:`img`,"aria-label":`${e.ruleName}, ${e.severity}`,className:`kymo-mark kymo-mark--${e.severity}`,style:{color:Lt[e.severity]},children:[q(`rect`,{x:t,y:u.top,width:Math.max(1,n-t),height:u.height,fill:`currentColor`,fillOpacity:.12}),q(`rect`,{x:t,y:u.top,width:Math.max(1,n-t),height:2,fill:`currentColor`}),q(`rect`,{className:`kymo-mark-hit`,x:t,y:u.top,width:Math.max(6,n-t),height:8,onPointerDown:t=>{t.stopPropagation(),s?.(e.ruleId)}})]},e.id))})}):null,R(P.filter(e=>e.a.anchor!==`x`)),u?q(`div`,{className:`kymo-ann-clip`,style:{clipPath:`inset(0 ${Math.max(0,x-u.left-u.width)}px 0 ${Math.max(0,u.left)}px)`},children:R(P.filter(e=>e.a.anchor===`x`))}):null,vt(`svg`,{className:`kymo-ann-svg`,width:x,height:S,viewBox:`0 0 ${x} ${S}`,"aria-hidden":`true`,children:[L?q(`rect`,{className:`kymo-ann-selection`,x:L.x-6,y:L.y-6,width:L.w+12,height:L.h+12,rx:4}):null,F&&!h&&(F.a.kind===`box`||F.a.kind===`arrow`)?q(`g`,{"data-ann-id":F.a.id,children:ZZ(F.a,F.px).map(([e,t],n)=>q(`rect`,{className:`kymo-ann-handle kymo-ann-handle--${F.a.kind===`arrow`?`end`:n%2?`nesw`:`nwse`}`,x:e-4.5,y:t-4.5,width:9,height:9,rx:2,onPointerDown:e=>A(e,F.a,n)},n))}):null]}),L&&!h?q(JZ,{onDelete:()=>N(F.a.id),id:F.a.id,style:{left:Math.min(x-12,L.x+L.w+6)-10,top:Math.max(10,L.y-6)-10}}):null]}):null})});function JZ({onDelete:e,style:t,id:n}){return q(`button`,{type:`button`,className:`kymo-ann-delete`,style:t,"data-ann-id":n,"aria-label":`Delete annotation`,title:`Delete (Del)`,onPointerDown:e=>e.stopPropagation(),onClick:e,children:q(`svg`,{viewBox:`0 0 10 10`,width:`8`,height:`8`,"aria-hidden":`true`,children:q(`path`,{d:`M2 2l6 6M8 2l-6 6`})})})}function YZ({initial:e,onDone:t}){let n=K(null),r=K(!1),i=e=>{r.current||(r.current=!0,t(e))};return G(()=>{let t=n.current;if(!t)return;t.textContent=e,t.focus();let r=t.ownerDocument.createRange();r.selectNodeContents(t);let i=t.ownerDocument.defaultView?.getSelection();i?.removeAllRanges(),i?.addRange(r)},[]),q(`div`,{ref:n,className:`kymo-ann-editor`,contentEditable:`plaintext-only`,suppressContentEditableWarning:!0,role:`textbox`,"aria-label":`Annotation text`,"aria-multiline":`true`,onPointerDown:e=>e.stopPropagation(),onKeyDown:e=>{e.stopPropagation(),e.key===`Enter`&&!e.shiftKey?(e.preventDefault(),i(n.current?.innerText??``)):e.key===`Escape`&&(e.preventDefault(),i(null))},onBlur:()=>i(n.current?.innerText??``)})}function XZ({a:e,px:t}){let n={stroke:e.color,strokeWidth:e.width,fill:`none`,strokeLinecap:`round`,strokeLinejoin:`round`},r=t=>q(`path`,{className:`kymo-ann-hit`,d:t,strokeWidth:Math.max(12,e.width+10)});switch(e.kind){case`box`:{let[[i,a],[o,s]]=t,c=`M${i} ${a}H${o}V${s}H${i}Z`;return vt(_t,{children:[r(c),q(`path`,{d:c,...n}),q(`path`,{d:c,fill:e.color,fillOpacity:.06,stroke:`none`,pointerEvents:`none`})]})}case`arrow`:{let[[i,a],[o,s]]=t,c=$Z(i,a,o,s,e.width);return vt(_t,{children:[r(`M${i} ${a}L${o} ${s}`),q(`path`,{d:`M${i} ${a}L${c.base[0]} ${c.base[1]}`,...n}),q(`path`,{d:c.d,fill:e.color,stroke:e.color,strokeWidth:1,strokeLinejoin:`round`})]})}case`brush`:{let e=QZ(t);return vt(_t,{children:[r(e),q(`path`,{d:e,...n})]})}}return null}function ZZ(e,t){if(e.kind===`arrow`)return t;let[[n,r],[i,a]]=t;return[[n,r],[i,r],[i,a],[n,a]]}function QZ(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 $Z(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 eQ(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 tQ(e,t){if(t)return{...e,text:t};let{text:n,...r}=e;return r}function nQ(e){let t=e;return!!t&&(t.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName))}function rQ(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=WZ(i,n,r,o);t&&(e.save(),i.anchor===`x`&&o&&(e.beginPath(),e.rect(o.left,0,o.width,r),e.clip()),iQ(e,i,t,a),e.restore())}e.restore()}function iQ(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(QZ(n)));else if(t.kind===`arrow`){let r=$Z(n[0][0],n[0][1],n[1][0],n[1][1],t.width);e.beginPath(),e.moveTo(n[0][0],n[0][1]),e.lineTo(r.base[0],r.base[1]),e.stroke(),e.beginPath(),e.moveTo(n[1][0],n[1][1]),e.lineTo(r.l[0],r.l[1]),e.lineTo(r.r[0],r.r[1]),e.closePath(),e.fill()}if(!t.text)return;let i=t.kind===`text`?t.width:12;e.font=`600 ${i}px ${r}`,e.textBaseline=`top`;let a=t.text.split(`
|
|
614
|
+
`),o=i*1.25,s=n[0][0],c=n[0][1];t.kind===`box`&&(s=Math.min(n[0][0],n[1][0]),c=Math.min(n[0][1],n[1][1])-a.length*o-7),a.forEach((t,n)=>e.fillText(t,s+6,c+2+n*o))}var aQ={solid:void 0,dashed:`5 4`,dotted:`1 4`};function oQ(e,t,n){if(!e||!(n===`x`?e.x:e.y))return null;if(n===`x`){let n=hU(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=_U(e,t.value);return r>=e.top-.5&&r<=e.top+e.height+.5?[e.left,r,e.left+e.width,r]:null}var sQ=st(function({frame:e,alarm:t,axis:n}){let r=oQ(mt(e.subscribe,e.get),t,n);if(!r)return null;let i=t.linked?cQ(r,n):null;return vt(`svg`,{className:`kymo-alarm`,"aria-hidden":`true`,children:[q(`line`,{x1:r[0],y1:r[1],x2:r[2],y2:r[3],stroke:t.color,strokeWidth:t.width,strokeDasharray:t.linked===`active`?wU.join(` `):aQ[t.style]}),i?q(`path`,{"data-alert-glyph":``,d:CU,transform:`translate(${i[0]} ${i[1]})`,fill:t.color}):null]})});function cQ(e,t){return t===`y`?[e[2]-10-3,e[1]-10-2]:[e[0]+3,e[1]+2]}function lQ(e,t,n,r,i){let a=oQ(t,n,r);if(a){if(e.save(),e.scale(i,i),e.strokeStyle=n.color,e.lineWidth=n.width,e.setLineDash(n.linked===`active`?wU:aQ[n.style]?.split(` `).map(Number)??[]),e.beginPath(),e.moveTo(a[0],a[1]),e.lineTo(a[2],a[3]),e.stroke(),n.linked){let t=cQ(a,r);EU(e,t[0],t[1],n.color)}e.restore()}}function uQ(e,t,n){return e.handlers?.wsId===n?e.handlers:e.handlers={wsId:n,onViewXRangeChange:r=>{t.view.setXRange(r,n),e.emitter.emit(`viewchange`,r)},onCursorX:e=>{try{t.view.setCursorX(e,n)}catch{}},cursor:{get:()=>{try{return t.view.cursorX(n)}catch{return null}},subscribe:e=>t.on(`cursorchange`,t=>{t.worksheetId===n&&e(t.x)})},onContextMenu:t=>e.emitter.emit(`contextmenu`,t),xyzRef:t=>{e.xyz=t},onAnnotations:n=>t.charts.setAnnotations(e.chartId,n),onAnnotationToolEnd:()=>{e.annotationTool=null,hQ(t).bump(),e.emitter.emit(`annotationtool`,null)},onAnnotationSelect:t=>{e.selectedAnnotation=t,e.emitter.emit(`annotationselect`,t)},onMarkSelect:t=>e.emitter.emit(`markselect`,t)}}var dQ=new WeakMap;function fQ(e,t){let n=dQ.get(e);n||dQ.set(e,n=new Map);let r=n.get(t);return r||n.set(t,r=n=>e.view.setLiveWindow(n,t)),r}var pQ=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=gt(document.createElement(`div`)),this.root.render(q(xQ,{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}},mQ=new WeakMap;function hQ(e){let t=mQ.get(e);return t||(t=new pQ(e),mQ.set(e,t)),t}function gQ(e,t,n,r={}){e.charts.get(t);let i=hQ(e),a={key:crypto.randomUUID(),chartId:t,element:n,options:r,shiftDatasetId:null,emitter:HV(),xyz:null,annotationTool:null,selectedAnnotation:null,plotFrame:bU(),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 ME(`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 ME(`export_failed`,{reason:`canvas unavailable`}));for(let e of r)o.drawImage(e,0,0);let s=e.charts.get(t),c=jQ(s.settings,z1(e).alertLines()),l=a.plotFrame.get()?.x?a.plotFrame.get():null,u=e.getState(),d=u.worksheets.find(e=>e.charts.some(e=>e.id===t)),f=PQ(s.annotations,d?MQ(u.marks,u.selection,d.xKey):[],l),p=nr(c);return p&&n.clientWidth>0&&lQ(o,a.plotFrame.get(),p.alarm,p.axis,i.width/n.clientWidth),f.length&&n.clientWidth>0&&rQ(o,f,n.clientWidth,n.clientHeight,i.width/n.clientWidth,Q.sans,l),new Promise((e,t)=>i.toBlob(n=>n?e(n):t(new ME(`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 _Q(e){mQ.get(e)?.refresh()}function vQ(e){mQ.get(e)?.dispose(),mQ.delete(e)}function yQ(e){let t=new MutationObserver(e);return t.observe(document.documentElement,{attributes:!0,attributeFilter:[`data-color-scheme`,`class`,`data-theme`]}),()=>t.disconnect()}var bQ=()=>{let e=document.documentElement;return`${e.getAttribute(`data-color-scheme`)??``}|${e.getAttribute(`data-theme`)??``}|${e.className}`};function xQ({engine:e,registry:t}){mt(t.subscribe,t.getVersion);let n=z1(e),r=mt(n.store.subscribe,n.store.get),i=new Map;for(let e of t.mounts.values()){let t=r.worksheets.find(t=>t.panels.some(t=>t.id===e.chartId));if(!t)continue;let n=i.get(t.id)??{worksheet:t,mounts:[]};n.mounts.push(e),i.set(t.id,n)}return q(_t,{children:[...i.values()].map(t=>q(TQ,{engine:e,worksheet:t.worksheet,mounts:t.mounts},t.worksheet.id))})}var SQ=1e3,CQ=.25;function wQ(e,t,n,r){let[i,a]=pt(0),o=K(0),s=K(0);return W(()=>{o.current&&=(s.current=performance.now()-o.current,0)}),W(()=>{if(!n)return;let i=0,c=-1,l=0,u=n=>{if(i=NH(u),o.current||n<l||RH()||!r())return;let d=0;for(let n of e)t.includes(n.id)&&(d+=n.source.version());d!==c&&(c=d,l=n+s.current*(1/CQ-1),o.current=performance.now(),ct(()=>a(e=>e+1)))};return i=NH(u),()=>PH(i)},[n,e,t]),ft(()=>n?e.map(e=>t.includes(e.id)?{...e,dataset:e.source.snapshot(SQ)}:e):e,[e,t,n,i])}function TQ({engine:e,worksheet:t,mounts:n}){let r=z1(e),i=mt(r.store.subscribe,r.store.get),a=r.derived(),o=i.xRanges[t.id]??null,s=ft(()=>i.live.filter(e=>e.kind===`data`),[i.live]),c=a.selectedLive.length,l=e=>{let n=t.panelChartSettings[e];return n?.kind===`multiband`&&n.beacon?.enabled===!0},u=c>0&&t.panels.some(e=>e.kind!==`multiband`&&e.kind!==`camera`||c>1&&!l(e.id)),d=K(n);d.current=n;let f=K(()=>d.current.some(e=>e.element.isConnected&&(typeof e.element.checkVisibility!=`function`||e.element.checkVisibility()))).current,p=wQ(s,i.selection,u,f),m=r.alertLines(),h=wZ({worksheet:kQ(t,m),viewXRange:o,selectedIds:i.selection,selectedDatasets:a.selectedDatasets,liveConnections:p,mathChannels:a.channels,datasetOffsets:i.offsets,datasetColors:i.colors,datasetPalette:i.palette}),g=K(BV()).current,_=mt(yQ,bQ),v=t.id,y=fQ(e,v),b=i.licensed,x=a.selectedLive[0]??null,S=e=>i.datasets.find(t=>t.id===e)??Object.values(a.laps).flatMap(e=>e.laps).find(t=>t.id===e);return q(_t,{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=uQ(n,e,v),l=jQ(t.panelChartSettings[r.id],m);return ht(q(RQ,{mount:n,annotations:t.panelChartSettings[r.id]?.annotations,marks:MQ(i.marks,i.selection,t.xKey),onMarkSelect:c.onMarkSelect,alarm:nr(l),onAnnotations:c.onAnnotations,onAnnotationToolEnd:c.onAnnotationToolEnd,onAnnotationSelect:c.onAnnotationSelect,render:u=>kZ({panel:r,settings:l,background:n.options.style?.background??t.panelChartBackgrounds[r.id]??null,styleToken:JSON.stringify([_,n.options.theme,n.options.style,Q]),data:h,xKey:t.xKey,height:u,viewXRange:o,onViewXRangeChange:c.onViewXRangeChange,onCursorX:c.onCursorX,liveZoom:g,liveWindowSeconds:t.liveWindowSeconds===void 0?i.liveWindowSeconds:t.liveWindowSeconds,onLiveWindowChange:y,beaconLive:x,findDataset:S,live:i.live,selection:i.selection,cursor:c.cursor,video:e.video.sources(),recordings:jX(a.selectedDatasets,i.offsets),shiftMode:s?EQ(e,s.id,s.name):void 0,onContextMenu:c.onContextMenu,xyzRef:c.xyzRef}),licensed:b},n.key),n.element,n.key)})})}function EQ(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 DQ=[],OQ=new WeakMap;function kQ(e,t){if(!t.size)return e;let n=OQ.get(e);if(n&&n.lines===t)return n.out;let r=!1,i={};for(let[n,a]of Object.entries(e.panelChartSettings))i[n]=jQ(a,t),i[n]!==a&&(r=!0);let a=r?{...e,panelChartSettings:i}:e;return OQ.set(e,{lines:t,out:a}),a}var AQ=new WeakMap;function jQ(e,t){if(!e||!t.size)return e;let n=AQ.get(e);if(n&&n.lines===t)return n.out;let r=er(e,t);return AQ.set(e,{lines:t,out:r}),r}var MQ=FQ((e,t,n)=>{let r=e.filter(e=>e.timeColumn===n&&t.includes(e.targetId));return r.length?r:NQ}),NQ=[];function PQ(e,t,n){return!t.length||!n?.x?e:[...t.map(e=>Rt(e,n.x.v1)),...e]}function FQ(e){let t=null,n;return(r,i,a)=>t&&t[0]===r&&t[1]===i&&t[2]===a?n:(t=[r,i,a],n=e(r,i,a),n)}function IQ(e,t){e.data=t}function LQ(e,t){e.status!==t&&(e.status=t,e.emitter.emit(`status`,t))}function RQ({mount:e,render:t,licensed:n,annotations:r,marks:i,alarm:a,onAnnotations:o,onAnnotationToolEnd:s,onAnnotationSelect:c,onMarkSelect:l}){let u=K(null),[d,f]=pt(0),p=!!e.options.debug,m=K({renderStart:0,lastRenderMs:0,renders:0,data:null}).current;p&&(m.renderStart=performance.now()),G(()=>{p&&(m.lastRenderMs=performance.now()-m.renderStart,m.renders++)}),G(()=>{let e=u.current;if(!e)return;let t=()=>f(Math.max(120,Math.floor(e.clientHeight)));t();let n=new zH(t);return n.observe(e),()=>n.disconnect()},[]);let{status:h,node:g,data:_}=t(d||400);m.data=_,W(()=>{IQ(e,_)}),W(()=>{LQ(e,h)});let{theme:v,style:y,className:b}=e.options,x={};return y?.background&&(x[`--chart-bg`]=y.background),y?.muted&&(x[`--chart-muted`]=y.muted),y?.grid&&(x[`--chart-grid`]=y.grid),y?.accent&&(x[`--accent`]=y.accent),vt(`div`,{ref:u,onContextMenu:h===`ready`?void 0:t=>{t.preventDefault(),e.emitter.emit(`contextmenu`,{clientX:t.clientX,clientY:t.clientY})},className:b?`kymo-chart ${b}`:`kymo-chart`,"data-color-scheme":v,"data-status":h,style:x,children:[q(xU.Provider,{value:e.plotFrame.set,children:g}),h===`ready`&&a?q(sQ,{frame:e.plotFrame,alarm:a.alarm,axis:a.axis}):null,h===`ready`&&(r?.length||e.annotationTool||i.length)?q(qZ,{annotations:r??DQ,tool:e.annotationTool,plotFrame:e.plotFrame,onChange:o,onToolEnd:s,onSelect:c,marks:i,onMarkSelect:l}):null,p?q(IZ,{stats:m,host:u}):null,n===!1?q(VV,{}):null]})}var zQ=new WeakMap;function BQ(e,t,n,r={}){let i=zQ.get(e)??new Map;zQ.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 ME(`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),OH(c);let m=n(p,r.mount),h=HV(),g=!1,_=()=>{g||(g=!0,i.delete(t),kH(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 VQ(e){for(let t of[...zQ.get(e)?.values()??[]])t.close()}function HQ(e,t,n=!1){let r=0,i=e.length;for(;r<i;){let a=r+i>>>1;(n?e[a]<=t:e[a]<t)?r=a+1:i=a}return r}function UQ(e,t,n){if(n<=t)return null;if(t===0&&n===e.t.length)return e;let r=e=>new Map([...e].map(([e,r])=>[e,r.subarray(t,n)])),i=r(e.lo);return{t:e.t.subarray(t,n),lo:i,hi:e.hi===e.lo?i:r(e.hi),level:e.level}}var WQ=(e,t,n)=>UQ(e,HQ(e.t,t),HQ(e.t,n,!0));function GQ(e,t,n,r){let i=[];for(let t of e){let e=UQ(t,0,HQ(t.t,n)),a=UQ(t,HQ(t.t,r,!0),t.t.length);e&&i.push(e),a&&i.push(a)}return[...i,...t]}var KQ=class{pieces;#e;#t;#n=new Map;#r=new Map;constructor(e,t={}){this.pieces=e.filter(e=>e.t.length>0).sort((e,t)=>e.t[0]-t.t[0]),this.#e=t;for(let e of this.pieces)for(let[t,n]of e.lo){let r=e.hi===e.lo?n:e.hi.get(t);if(!r)continue;let i=this.#n.get(t);i||this.#n.set(t,i=[]),i.push({t:e.t,L:n,H:r})}this.#t=[...this.#n.keys()].sort((e,t)=>e.localeCompare(t))}schemaSync(){return[{name:$e,type:`number`,unit:`s`},...this.#t.map(e=>({name:e,type:`number`,unit:this.#e[e]??``}))]}async getSchema(){return this.schemaSync()}async readColumns(e,t,n){let r=e.filter(e=>e===`ElapsedTime`||this.#n.has(e)),i=this.pieces.reduce((e,t)=>e+t.t.length,0),a=Math.max(0,Math.min(n,i-t)),o=Object.fromEntries(r.map(e=>[e,new Float64Array(a).fill(NaN)])),s=0;for(let e of this.pieces){let n=Math.max(0,t-s),i=Math.min(e.t.length,t+a-s);for(let a of r){let r=a===`ElapsedTime`?e.t:e.lo.get(a);r&&i>n&&o[a].set(r.subarray(n,i),s+n-t)}if(s+=e.t.length,s>=t+a)break}return o}getSeriesMultiSync(e,t,n){let{x0:r,x1:i}=t,a=t.xKey===`ElapsedTime`?e.filter(e=>this.#n.has(e)):[];if(!(i>r)||n<1||a.length===0)return{x0:r,bucket:0,rows:[],columns:a};let o=Math.floor(n),s=(i-r)/n,c=a.map(()=>new Float64Array(o).fill(1/0)),l=a.map(()=>new Float64Array(o).fill(-1/0));for(let e=0;e<a.length;e++){let t=c[e],n=l[e];for(let{t:c,L:l,H:u}of this.#n.get(a[e])){if(c[c.length-1]<r||c[0]>i)continue;let e=HQ(c,i,!0);for(let i=HQ(c,r);i<e;i++){let e=l[i];if(e!==e)continue;let a=Math.floor((c[i]-r)/s);a>=o&&(a=o-1),e<t[a]&&(t[a]=e),u[i]>n[a]&&(n[a]=u[i])}}}let u=[];for(let e=0;e<o;e++){let t=null;for(let n=0;n<a.length;n++)c[n][e]!==1/0&&(t??={b:e},t[`y${n}lo`]=c[n][e],t[`y${n}hi`]=l[n][e]);t&&u.push(t)}return{x0:r,bucket:s,rows:u,columns:a}}async getSeriesMulti(e,t,n){return this.getSeriesMultiSync(e,t,n)}async getSeries(e){let t=this.getSeriesMultiSync([e.column],e.viewport,e.maxPoints),n=t.rows.length,r={x:new Float64Array(n),min:new Float64Array(n),max:new Float64Array(n),first:new Float64Array(n),last:new Float64Array(n)};return t.rows.forEach((e,n)=>{r.x[n]=t.x0+(e.b+.5)*t.bucket,r.min[n]=r.first[n]=e.y0lo,r.max[n]=r.last[n]=e.y0hi}),r}xBoundsSync(e){let t=this.#r.get(e);if(t)return t;let n=1/0,r=-1/0;if(e===`ElapsedTime`)for(let e of this.pieces)n=Math.min(n,e.t[0]),r=Math.max(r,e.t[e.t.length-1]);for(let{L:t,H:i}of this.#n.get(e)??[])for(let e=0;e<t.length;e++)t[e]<n&&(n=t[e]),i[e]>r&&(r=i[e]);return t=n<=r?{x0:n,x1:r}:{x0:0,x1:0},this.#r.set(e,t),t}async xBounds(e){return this.xBoundsSync(e)}sampleRowsSync(e){let t=this.pieces.reduce((e,t)=>e+t.t.length,0),n=Math.max(1,Math.ceil(t/Math.max(1,e))),r=[],i=0,a=0;for(let e of this.pieces){let t=i-a;if(a+=e.t.length,!(t>=e.t.length))for(let a=t;a<e.t.length;a+=n,i+=n){let t={[$e]:e.t[a]};for(let[n,r]of e.lo){let e=r[a];t[n]=e===e?e:null}r.push(t)}}return r.sort((e,t)=>e[$e]-t[$e])}async dispose(){}},qQ=12e3,JQ=100;function YQ(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 c.add(n),n;for(let e=0;e<n.length;e++){let t=n[e];t-t!==0&&(n[e]=NaN)}return n}function XQ(e,t){let n=Object.keys(t.columns);if(n.length===0)throw new ME(`no_columns`);let r=t.columns[n[0]].length;if(n.some(e=>t.columns[e].length!==r))throw new ME(`column_length_mismatch`);let i=new Map(n.map(e=>[e,YQ(t.columns[e],t.transfer)])),a=ZQ(e,t.name,i,t.units??{});if(t.bands){for(let e of Object.values(t.bands))if(e.lo.length!==r||e.hi.length!==r)throw new ME(`column_length_mismatch`);a.bands=Object.fromEntries(Object.entries(t.bands).map(([e,t])=>[e,{lo:Float64Array.from(t.lo),hi:Float64Array.from(t.hi)}]))}return a}function ZQ(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,JQ);t++)e.push(o.map(e=>{let r=n.get(e)[t];return r===r?String(r):``}).join(`,`));d=e.join(`
|
|
615
|
+
`),f=te(d)}let p={id:e,name:t,schema:l,rawText:d,parseConfig:f,fromColumns:!0};if(s>1e6){let e=new aZ(n,r);return{...p,kind:`columnar`,source:e,data:{meta:``,columnNames:o,units:c,rows:e.sampleRowsSync(qQ)}}}let m={meta:``,columnNames:o,units:c,rows:ze({keys:o,length:s,values:o.map(e=>n.get(e)),text:o.map(()=>null)},i)};return{...p,kind:`memory`,source:new BE(m),data:m}}function QQ(e,t,n){let r=e.fromColumns?$Q(e):null;if(!r)throw new ME(`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)?(z(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{...e$(e,o,!0),columnSpares:s}}function $Q(e){if(e.source instanceof aZ)return new Map(e.source.columnMap);let t=Ae(e.data.rows);return t?new Map(t.keys.map((e,n)=>[e,t.values[n]])):null}function e$(e,t,n=!1){let r=e.fromColumns?$Q(e):null;if(!r)throw new ME(`invalid_argument`,{reason:`only datasets added with addColumns can be replaced`});let i=r;for(let e of Object.keys(t))i.set(e,YQ(t[e],n));let a=i.values().next().value.length;for(let e of i.values())if(e.length!==a)throw new ME(`column_length_mismatch`);let o=Object.fromEntries(e.schema.map(e=>[e.name,e.unit])),s=ZQ(e.id,e.name,i,o,e.kind===`memory`?e.data.rows:void 0,e),c=s.schema.length===e.schema.length&&s.schema.every((t,n)=>t.name===e.schema[n].name);return{...s,schema:c?e.schema:s.schema,beacon:e.beacon,bands:e.bands}}var t$=new WeakMap;function n$(e){let t=e.fromColumns?$Q(e):null;if(!t)return e.rawText??``;let n=e.data.rows,r=t$.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(`,`));t$.set(n,r=a.join(`
|
|
616
|
+
`))}return r}function r$(e,t){let n=new KQ(t.pieces,t.units),r=n.schemaSync();return{id:e,name:t.name,kind:`columnar`,source:n,schema:r,data:{meta:``,columnNames:r.map(e=>e.name),units:r.map(e=>e.unit),rows:n.sampleRowsSync(qQ)}}}function i$(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 a$(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 o$(){let e=a$(e=>{let t={};for(let n of e){if(n.cut){let e=n.cut.defs.find(e=>e.id===n.cut.cycleId)?.show,r=e&&e.channel!==n.cut.timeKey?KB(e):null;t[n.id]=r?{laps:n.cut.parts,values:n.cut.found.map(e=>e.kpis?.[r]??null),unit:n.schema.find(t=>t.name===e.channel)?.unit??``,isTime:!1}:{laps:n.cut.parts,values:n.cut.found.map(e=>e.tend===null?null:e.tend-e.tstart),unit:`s`,isTime:!0};continue}if(!n.beacon||n.kind!==`memory`)continue;let{channel:e,metric:r,stat:i}=n.beacon,a=xB(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:kB(n.id,t),name:`${n.name} · Cycle ${t+1}`,data:r,source:new BE(r)}}),values:a.map(e=>TB(n.data.rows,e,r,i)),unit:o,isTime:i===`span`&&DB(r,o)}}return t}),t=a$((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=a$((e,t)=>e.filter(e=>e.kind===`data`&&t.includes(e.id))),r=a$(e=>WX(e.map(e=>e.data))),i=a$((e,t)=>t.length===0?e:WX(e?[e,...t.map(e=>e.dataset)]:t.map(e=>e.dataset))),a=a$((e,t,n,r)=>{let i=new Set;if(e)for(let t of n.length>0?n:[e])for(let e of JX(t.columnNames,t.rows))i.add(e);for(let e of r)for(let t of e.dataset.columnNames)(t===`ElapsedTime`||e.source.hasValues(t))&&i.add(t);let a=e?e.columnNames.filter(e=>i.has(e)):[],o=t.filter(e=>e.kind!==`memory`).flatMap(e=>wz(e.schema));return[...new Set([...a,...o])]});return{lapsByDataset:e,selectedDatasets:t,selectedLive:n,staticDataset:r,mergedDataset:i,mergedParts:a$((e,t)=>[...e.map(e=>e.data),...t.map(e=>e.dataset)]),numericColumns:a$((e,t,n,r=[],i=[])=>{let o=a(e,t,r,i),s=new Set(o);return[...o,...n.map(e=>e.name).filter(e=>!s.has(e))]}),allColumns:a$((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:a$((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 s$=[{kind:`multiband`,label:`Multi-band`},{kind:`xyscatter`,label:`X-Y scatter`},{kind:`xyzmesh`,label:`X-Y-Z mesh`},{kind:`histogram`,label:`Histogram`},{kind:`polar`,label:`Polar`},{kind:`spectrum`,label:`Spectrum`},{kind:`boxplot`,label:`Box Plot`},{kind:`spectrogram`,label:`Spectrogram`},{kind:`heatmap`,label:`Heatmap`},{kind:`violin`,label:`Violin`},{kind:`confusion`,label:`Confusion Matrix`},{kind:`roc`,label:`ROC Curve`},{kind:`losscurve`,label:`Loss Curves`},{kind:`controlchart`,label:`Control Chart`},{kind:`parallelcoords`,label:`Parallel Coords`},{kind:`embedding`,label:`Embedding`},{kind:`flamegraph`,label:`Flame Graph`},{kind:`barchart`,label:`Bar Chart`},{kind:`radar`,label:`Radar`},{kind:`areachart`,label:`Area Chart`},{kind:`cdfchart`,label:`CDF / ECDF`},{kind:`bubblechart`,label:`Bubble Chart`},{kind:`treemap`,label:`Treemap`},{kind:`sankey`,label:`Sankey`},{kind:`calibration`,label:`Calibration Curve`},{kind:`gauge`,label:`Gauges`},{kind:`camera`,label:`Camera`},{kind:`qqplot`,label:`Q-Q Plot`},{kind:`gantt`,label:`Gantt Chart`}],c$=new Map(s$.map(e=>[e.kind,e.label]));function l$(e){return c$.get(e)??e}var u$=`kymoscope-live.v1`,d$=`kymoscope-live.ack1`,f$=1e3,p$=2e3,m$=3e4,h$=30,g$=1e4,_$=300,v$=90,y$=e=>e.startsWith(`eyJ`);function b$(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 x$(e,t){return`${e.replace(/\/+$/,``)}/v1/streams/${t}/watch`}function S$(e,t,n,r){let i=null,a=null,o=null,s=!1,c=0,l=()=>{o&&=(clearTimeout(o),null)},u=(n,r)=>{l();let a=b$(r);if(a===null)return;let c=y$(r),d=c?Math.min(a,Date.now()/1e3+_$):a,f=Math.min(Math.max((d-(c?v$:h$))*1e3-Date.now(),g$),2**31-1);o=setTimeout(async()=>{o=null;let r=null;try{r=await e.getToken(t)}catch{r=null}if(!(s||i!==n||!r)){try{n.send(JSON.stringify({type:`auth`,token:r}))}catch{return}u(n,r)}},f)},d=()=>{if(s||a)return;let e=Math.min(m$,p$*2**c++)*(.75+Math.random()/2);a=setTimeout(()=>{a=null,f()},e)},f=async()=>{if(s)return;let a=null;try{a=await e.getToken(t)}catch{a=null}if(s)return;if(!a){r?.(`error`),d();return}let o=new WebSocket(x$(e.url,t),[u$,d$,`bearer.${a}`]);o.binaryType=`arraybuffer`,i=o;let f=a,p=0,m=setInterval(()=>{if(!(p===0||o.readyState!==1)){try{o.send(JSON.stringify({type:`ack`,b:p}))}catch{return}p=0}},f$);o.onopen=()=>{r?.(`subscribed`),u(o,f)},o.onmessage=e=>{c=0,typeof e.data!=`string`&&(p+=e.data.byteLength,n(e.data))},o.onclose=()=>{clearInterval(m),i===o&&(i=null,l(),!s&&(r?.(`error`),d()))}};return f(),()=>{if(s=!0,a&&=(clearTimeout(a),null),l(),i){let e=i;i=null,e.close(1e3)}}}var C$=960*1024,w$=24;function T$(e){let t=e.key&&e.fragIndex===0?new TextEncoder().encode(e.codec):new Uint8Array;if(t.length>255)throw Error(`codec string too long`);let n=e.key&&e.fragIndex===0?1+t.length:0,r=new Uint8Array(w$+n+e.payload.length),i=new DataView(r.buffer);i.setUint8(0,1),i.setUint8(1,!!e.key|(e.last?2:0)),i.setUint8(2,1),i.setUint8(3,0),i.setFloat64(4,e.t,!0),i.setUint32(12,e.seq>>>0,!0),i.setUint16(16,e.fragIndex,!0),i.setUint16(18,e.fragCount,!0),i.setUint16(20,e.width,!0),i.setUint16(22,e.height,!0);let a=w$;return n&&(r[a++]=t.length,r.set(t,a),a+=t.length),r.set(e.payload,a),r}function E$(e){if(e.length<w$||e[0]!==1||e[2]!==1)return null;let t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=(e[1]&1)!=0,r=t.getUint16(16,!0),i=t.getUint16(18,!0);if(i===0||r>=i)return null;let a=w$,o=``;if(n&&r===0){if(e.length<a+1||e.length<a+1+e[a])return null;o=new TextDecoder().decode(e.subarray(a+1,a+1+e[a])),a+=1+e[a]}return{key:n,last:(e[1]&2)!=0,t:t.getFloat64(4,!0),seq:t.getUint32(12,!0),fragIndex:r,fragCount:i,width:t.getUint16(20,!0),height:t.getUint16(22,!0),codec:o,payload:e.subarray(a)}}function D$(e){let t=Math.max(1,Math.ceil(e.data.length/C$)),n=[];for(let r=0;r<t;r++)n.push(T$({key:e.key,last:r===t-1,t:e.t,seq:e.seq,fragIndex:r,fragCount:t,width:e.width,height:e.height,codec:e.codec,payload:e.data.subarray(r*C$,Math.min(e.data.length,(r+1)*C$))}));return n}function O$(e,t){let n=new Map,r=Promise.resolve();return i=>{let a=he(e,i).catch(()=>null);r=r.then(async()=>{try{let e=await a;if(!e)return;if(e.kind===6){let n=E$(e.plaintext);n&&t({type:`video`,m:n})}else if(e.kind===5){let t=pe(e.plaintext);n.set(t.id,t)}else if(e.kind===7){let r=Pe(e.plaintext,n);r&&t({type:`last`,values:r})}else if(e.kind===4){let r=await le(e.plaintext,n);r&&!r.historical&&t({type:`columns`,block:r.block})}else if(e.kind===3)t({type:`columns`,block:De(e.plaintext)});else if(e.kind===2){let n=qe(e.plaintext);t({type:`frames`,frames:Array.isArray(n?.frames)?n.frames:[]})}}catch{}})}}var k$=``+new URL(`assets/liveIngestWorker-BLPTEEc7.js`,import.meta.url).href;function A$(e,t,n,r,i){let a=()=>S$(e,t,O$(n,r),i),o;try{if(typeof Worker>`u`)return a();o=NE(k$)}catch{return a()}let s=!1,c=()=>{try{o.postMessage({type:`stop`})}catch{o.terminate()}};return o.onmessage=a=>{let s=a.data;if(s.type===`decoded`){if(r(s.d),s.bytes)try{o.postMessage({type:`ack`,bytes:s.bytes})}catch{}}else if(s.type===`status`)i?.(s.status);else if(s.type===`ask`){let r=s.what===`token`?e.getToken(t):typeof n==`function`?n(s.arg):n;Promise.resolve(r).catch(()=>null).then(e=>{try{o.postMessage({type:`reply`,id:s.id,value:e})}catch{}})}},o.onerror=()=>{o.terminate(),!s&&(c=a())},o.postMessage({type:`start`,url:e.url,streamId:t,key:typeof n==`function`?null:n}),()=>{s=!0,c()}}var j$=class{samples=[];exact=!1;windowS;constructor(e=30){this.windowS=e}observe(e,t){if(e>1e9){this.samples=[],this.exact=!0;return}this.exact=!1;let n=t-e,r=this.samples[this.samples.length-1];for(r&&Math.abs(n-r.off)>1&&(this.samples=[]),this.samples.push({at:t,off:n});this.samples.length&&this.samples[0].at<t-this.windowS;)this.samples.shift()}quality(){return this.exact?`exact`:this.samples.length?`approx`:`none`}toWall(e,t=0){if(this.exact)return e+t/1e3;if(!this.samples.length)return null;let n=1/0;for(let e of this.samples)n=Math.min(n,e.off);return e+n+t/1e3}toStream(e,t=0){let n=this.toWall(0,t);return n===null?null:e-n}},M$=class{#e;constructor(e){this.#e=typeof e==`function`?e:()=>e}size(){return this.#e().size}get columnNames(){return this.#e().columnNames}version(){return this.#e().version}columns(){let e=this.#e();return new N$(new Set(e.columnNames),t=>e.mirrorColumn(t))}hasValues(e){return this.#e().hasValues(e)}snapshot(e){return this.#e().toDataset(e)}async getSchema(){let e=this.#e();return e.columnNames.map(t=>({name:t,type:`number`,unit:e.unitOf(t)}))}async getSeries(e){let t=this.#e();return a(t.columnValues(e.viewport.xKey),t.columnValues(e.column),e.viewport.x0,e.viewport.x1,e.maxPoints)}async getSeriesMulti(e,t,n){return this.getSeriesMultiSync(e,t,n)}getSeriesMultiSync(e,t,n){return this.#e().decimateColumns(t.xKey,e,t.x0,t.x1,n)}getPointsSync(e,t,n){return this.#e().decimatePoints(t.xKey,e,t.x0,t.x1,n)}async xBounds(e){return this.xBoundsSync(e)}xBoundsSync(e){return this.#e().columnBounds(e)}xTravelSync(e,t){return this.#e().xTravel(e,t)}latestTimeSync(){return this.#e().latestTime()}xAtTimeSync(e,t,n=!1){return this.#e().xAtTime(e,t,n)}latestSync(e){return this.#e().lastValue(e)}latestValuesSync(e){let t=this.#e(),n=new Map;for(let r of e){let e=t.lastValue(r),i=t.lastKnown(r);Number.isFinite(e)?n.set(r,e):i&&n.set(r,i.v)}return n}valueBoundsSync(e){let t=this.#e().valueBounds(e),n=this.#e().lastKnown(e);if(!t&&!n)return null;let r=Math.min(t?.x0??1/0,n?.v??1/0),i=Math.max(t?.x1??-1/0,n?.v??-1/0);if(r!==i)return{min:r,max:i};let a=Math.max(.5,Math.abs(r)*.05);return{min:r-a,max:i+a}}lastKnownSync(e){return this.#e().lastKnown(e)}trackCycles(e){this.#e().trackCycles(e)}cycleSpanSync(e){return this.#e().cycleSpan(e)}decimateCycleSync(e,t,n,r,i){return this.#e().decimateCycle(e,t,n,r.x0,r.x1,i)}cyclePointsSync(e,t,n,r,i){return this.#e().decimateCyclePoints(e,t,n,r.x0,r.x1,i)}async readColumns(e,t,n){let r=this.#e(),i=new Set(r.columnNames),a={};for(let o of e)i.has(o)&&(a[o]=r.columnValues(o).slice(t,t+n));return a}async dispose(){}},N$=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)}},P$=4096,F$=5e3,I$=class{startedAt=Date.now();n=0;capacity=P$;time=new Float64Array(P$);cols=new Map;order=[];units=new Map;timeColumn;timeUnit;constructor(e=$e,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=Ze(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(L$).join(`,`)}\n${t.map(L$).join(`,`)}\n`],r=this.order.map(e=>this.cols.get(e));for(let e=0;e<this.n;e+=F$){let t=Math.min(this.n,e+F$),i=``;for(let n=e;n<t;n++){i+=String(this.time[n]);for(let e of r){let t=e[n];i+=Number.isNaN(t)?`,`:`,${t}`}i+=`
|
|
617
|
+
`}n.push(i)}return n}};function L$(e){let t=/^[=+\-@\t\r]/.test(e)?`'${e}`:e;return/[",\n\r]/.test(t)?`"${t.replace(/"/g,`""`)}"`:t}var R$=512,z$=new WeakMap;function B$(e,t,n){let r=z$.get(e);r||z$.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 V$(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=tE(n.formula);if(!o.ok)continue;let{identifiers:s,functions:c}=nE(o.node);if(!s.every(e=>a.has(e)))continue;let l=c.some(e=>$T.includes(e)),u=Math.max(e.firstAbs,i-(l?R$:0)),d=new Map([$e,...s].map(t=>[t,e.range(t,u,r)])),{carry:f,keep:p}=B$(e,`${n.id}|${n.formula}`,u),m=cE(n,e=>d.get(e),$e,r-u,t,f);m.status===`ok`&&(e.writeComputed(n.name,n.units,i,m.values.subarray(i-u)),p())}}function H$(e,t){e.clearComputed(),z$.delete(e),V$(e,t,e.firstAbs)}var U$=8e3,W$=131072;function G$(e,t={}){switch(e.kind){case`elapsed`:return{name:`Elapsed`,unit:`s`};case`event`:return{name:`Since ${e.channel} ${e.op} ${e.value}`,unit:`s`};case`clock`:return{name:`Time of day`,unit:`s`};default:{let n=t[e.channel]??``;return e.integral?{name:`∫${e.channel}`,unit:n?`${n}·s`:`s`}:{name:`${e.channel} since start`,unit:n}}}}var K$=new Map;function q$(e,t){let n=`${t}|${Math.floor(e/900)}`,r=K$.get(n);r===void 0&&(r=mB(e,t),K$.size>1e4&&K$.clear(),K$.set(n,r));let i=(e+r)%86400;return i<0?i+86400:i}var J$=class{axis;#e=NaN;#t=NaN;#n=NaN;#r=0;#i=NaN;#a=NaN;constructor(e){this.axis=e}begin(e){this.#e=e,this.#t=NaN,this.#n=NaN,this.#r=0,this.#i=NaN,this.#a=NaN}x(e,t){let n=this.axis;return n.kind===`clock`?q$(e,n.tz):n.kind===`elapsed`?e-this.#e:e<this.#e?NaN:n.kind===`event`?(this.#t!==this.#t&&t===t&&cB(n.op,t,n.value)&&(this.#t=e),e-this.#t):n.integral?(t===t&&(this.#i===this.#i&&(this.#r+=(t+this.#i)/2*(e-this.#a)),this.#i=t,this.#a=e),this.#i===this.#i?this.#r:NaN):(t===t&&(this.#n!==this.#n&&(this.#n=t),this.#i=t),this.#i===this.#i?this.#i-this.#n:NaN)}};function Y$(e,t,n,r){let i=`channel`in r?t.get(r.channel):void 0;if(r.kind===`event`){let a=NaN;for(let t=0;t<e.length&&a!==a;t++){let o=i?i[t]:NaN;e[t]>=n&&o===o&&cB(r.op,o,r.value)&&(a=e[t])}return{x:e.map(e=>e-a),t:e,cols:t}}let a=new J$(r);a.begin(n);let o=new Float64Array(e.length);for(let t=0;t<e.length;t++)o[t]=a.x(e[t],i?i[t]:NaN);return{x:o,t:e,cols:t}}function X$(e,t,n){let r=[];for(let n=0;n<e.length;n++)e[n]===e[n]&&t[n]===t[n]&&r.push(n);let i=!0;for(let t=1;t<r.length&&i;t++)i=e[r[t-1]]<=e[r[t]];i||r.sort((t,n)=>e[t]-e[n]);let a=r.length,o=new Float64Array(n.length).fill(NaN);if(a<2)return o;let s=Float64Array.from(r,t=>e[t]),c=Float64Array.from(r,e=>t[e]),l=Float64Array.from({length:a-1},(e,t)=>s[t+1]-s[t]).sort(),u=l[l.length>>1],d=u>0?4*u:1/0,f=0;for(let e=0;e<n.length;e++){let t=n[e];if(!(t>=s[0]&&t<=s[a-1]))continue;for(;f<a-2&&s[f+1]<t;)f++;let r=s[f],i=s[f+1];i-r>d||(o[e]=i===r?c[f]:c[f]+(c[f+1]-c[f])*(t-r)/(i-r))}return o}function Z$(e,t,n){let r=e.length;if(r===0||!(n>=e[0]&&n<=e[r-1]))return NaN;if(r===1)return t[0];let i=(n-e[0])/(e[r-1]-e[0])*(r-1),a=Math.min(r-2,Math.floor(i));return t[a]+(t[a+1]-t[a])*(i-a)}function Q$(e,t,n){let r=Math.max(2,Math.min(U$,Math.floor(n)));if(r*t.length>131072)throw Error(`too_many_cells`);let i=1/0,a=-1/0;for(let t of e)for(let e of t.x)e===e&&(e<i&&(i=e),e>a&&(a=e));if(!(a>i))throw Error(`empty`);let o=Float64Array.from({length:r},(e,t)=>i+t*(a-i)/(r-1)),s=new Map;for(let n of t){let t=new Uint16Array(r),i=new Float64Array(r),a=new Float64Array(r),c=new Float32Array(r).fill(1/0),l=new Float32Array(r).fill(-1/0);for(let s of e){let e=s.cols.get(n);if(!e)continue;let u=X$(s.x,e,o);for(let e=0;e<r;e++){let n=u[e];if(n!==n)continue;let r=++t[e],o=n-i[e];i[e]+=o/r,a[e]+=o*(n-i[e]),n<c[e]&&(c[e]=n),n>l[e]&&(l[e]=n)}}let u={mean:new Float32Array(r),sd:new Float32Array(r),min:c,max:l,n:t};for(let e=0;e<r;e++){if(t[e]===0){u.mean[e]=u.sd[e]=u.min[e]=u.max[e]=NaN;continue}u.mean[e]=i[e],u.sd[e]=t[e]>1?Math.sqrt(a[e]/(t[e]-1)):0}s.set(n,u)}return{x:o,channels:s}}function $$(e,t){if(e.unit===`abs`)return e.tolerance;let n=1/0,r=-1/0;for(let e of t.mean)e===e&&(e<n&&(n=e),e>r&&(r=e));return r>=n?Math.max(r-n,Math.abs(r),Math.abs(n))*e.tolerance/100:0}var e1=new WeakMap;function t1(e){let t=e1.get(e);if(t)return t;let n=e.sd.length,r=Math.max(2,Math.round(n/100));t=new Float32Array(n).fill(NaN);for(let i=0;i<n;i++){if(e.n[i]<2)continue;let a=0,o=0;for(let t=Math.max(0,i-r);t<=Math.min(n-1,i+r);t++)e.n[t]>=2&&e.sd[t]===e.sd[t]&&(a+=e.sd[t]**2,o++);t[i]=o?Math.sqrt(a/o):NaN}return e1.set(e,t),t}function n1(e,t,n){if(n===`minmax`)return{lo:e.min,hi:e.max};if(n===`sigma`){let n=t1(e);return{lo:e.mean.map((e,r)=>e-t*n[r]),hi:e.mean.map((e,r)=>e+t*n[r])}}let r=$$(n,e);return{lo:e.mean.map(e=>e-r),hi:e.mean.map(e=>e+r)}}function r1(e,t,n,r=`sigma`,i=0){let a=typeof r==`function`?r:()=>({band:r,k:n}),o=[...t.channels.keys()],s=new Map,c=new Map,l=[],u=new Uint8Array(e.t.length),d=o.map(()=>new Uint8Array(e.t.length)),f=t.x.length;o.forEach((n,r)=>{let i=t.channels.get(n),o=e.cols.get(n);if(!o)return;let{band:p,k:m}=a(n),h=typeof p==`object`?p:null,{lo:g,hi:_}=n1(i,m,p),v=0,y=0,b=0;for(let e of i.mean)if(e===e){v++;let t=e-y;y+=t/v,b+=t*(e-y)}let x=v>1?Math.max(Math.sqrt(b/(v-1)),1e-9):1e-9,S=h?Math.max($$(h,i),1e-9):0,C=t1(i),w=new Float64Array(e.t.length).fill(NaN),T=new Float64Array(e.t.length).fill(NaN),E=0,D=0;for(let n=0;n<e.t.length;n++){let a=o[n],s=e.x[n];if(a!==a||s!==s)continue;let c=Z$(t.x,i.mean,s);if(c!==c)continue;w[n]=a-c;let l=Math.round((s-t.x[0])/(t.x[f-1]-t.x[0])*(f-1));T[n]=Math.abs(a-c)/(h?S:i.n[l]>=2&&C[l]===C[l]?Math.max(C[l],1e-9):x),E+=T[n],D++,(h||i.n[l]>=2)&&(a<Z$(t.x,g,s)||a>Z$(t.x,_,s))&&(u[n]=1,d[r][n]=1)}s.set(n,w),c.set(n,T),l.push({channel:n,z:D?E/D:0})}),l.sort((e,t)=>t.z-e.z);let p=[];for(let t=0;t<u.length;t++){if(!u[t])continue;let n=t;for(;n<u.length&&u[n];)n++;let r=p[p.length-1];r&&e.t[t]-e.t[Math.min(r[1],u.length-1)]<i?r[1]=n:p.push([t,n]),t=n}let m=[];for(let[t,n]of p){let r=e.t[t],a=e.t[Math.min(n,u.length-1)];a-r>=i&&m.push({t0:r,t1:a,channels:o.filter((e,r)=>d[r].subarray(t,n).includes(1))})}return{delta:s,score:l,deviations:m,z:c}}function i1(e,t){let n=e.x.length,r=t.length,i=new DataView(new ArrayBuffer(12+8*n+r*n*18));[75,82,66,49].forEach((e,t)=>i.setUint8(t,e)),i.setUint32(4,n,!0),i.setUint32(8,r,!0);let a=12;for(let t=0;t<n;t++,a+=8)i.setFloat64(a,e.x[t],!0);for(let r of t){let t=e.channels.get(r);if(!t)throw Error(`The reference has no channel ${r}`);for(let e of[t.mean,t.sd,t.min,t.max])for(let t=0;t<n;t++,a+=4)i.setFloat32(a,e[t],!0);for(let e=0;e<n;e++,a+=2)i.setUint16(a,t.n[e],!0)}return Ge(new Uint8Array(i.buffer))}function a1(e,t){let n=Te(e),r=new DataView(n.buffer,n.byteOffset,n.byteLength);if(n.length<12||String.fromCharCode(n[0],n[1],n[2],n[3])!==`KRB1`)throw Error(`Not a reference band`);let i=r.getUint32(4,!0),a=r.getUint32(8,!0);if(a!==t.length||n.length!==12+8*i+a*i*18)throw Error(`This reference band does not match its channels`);let o=12,s=new Float64Array(i);for(let e=0;e<i;e++,o+=8)s[e]=r.getFloat64(o,!0);let c=new Map;for(let e of t){let t=()=>{let e=new Float32Array(i);for(let t=0;t<i;t++,o+=4)e[t]=r.getFloat32(o,!0);return e},n=t(),a=t(),s=t(),l=t(),u=new Uint16Array(i);for(let e=0;e<i;e++,o+=2)u[e]=r.getUint16(o,!0);c.set(e,{mean:n,sd:a,min:s,max:l,n:u})}return{x:s,channels:c}}var o1=` Δ`,s1=class{#e;constructor(e){this.#e=new PB(e)}assumeOpen(e){}feed(e,t,n){let r=[];for(let i=0;i<e.length;i++)this.#e.step(e[i],e=>{let n=t(e);return n?n[i]:NaN},r),n?.(i,this.#e.open()?.tstart??null);return r.map(e=>({tstart:e.tstart,tend:e.tend,kpis:{duration:(e.tend??e.tstart)-e.tstart},...e.flags.length?{flags:e.flags}:{}}))}};function c1(e){if(!e.cycle&&!e.rule)throw Error(`a live segment axis needs a rule or a cycle rule`);let t=e.cycle?new s1(e.cycle):new yB(e.rule,e.kpis??[]),n=new J$(e.axis),r=NaN;e.start!=null&&(t.assumeOpen(e.start),n.begin(e.start),r=e.start);let i=e.reference??null,a=i?[...i.channels]:[],o=i?i.grid.length:0,s=`channel`in e.axis?e.axis.channel:null,c=[...new Set([...e.cycle?NB(e.cycle):sB(e.rule),...(e.kpis??[]).map(e=>e.channel),...s?[s]:[],...a.map(([e])=>e)])],l=e.minDeviationS??5,u=NaN,d=NaN,f=NaN,p=new Set,m=!1,h=e=>{m&&e({type:`deviation-end`,t0:u,t1:d,channels:[...p]}),u=d=f=NaN,p=new Set,m=!1};return{feed(g,_,v=!1){let y=Math.max(_,g.firstAbs),b=g.endAbs;if(y>=b)return;let x=t=>{v||e.onEvent?.(t)},S=g.range($e,y,b),C=new Map(c.map(e=>[e,g.range(e,y,b)])),w=new Float64Array(S.length).fill(NaN),T=a.map(([e,t])=>({name:e,b:t,v:C.get(e),d:new Float64Array(S.length).fill(NaN)})),E=s?C.get(s):null,D=t.feed(S,e=>C.get(e),(e,t)=>{if(t===null)return;t!==r&&(h(x),r=t,n.begin(t),x({type:`open`,tstart:t}));let a=n.x(S[e],E?E[e]:NaN);if(w[e]=a,!i||a!==a)return;let s=o>1?Math.round((a-i.grid[0])/(i.grid[o-1]-i.grid[0])*(o-1)):0,c=!1;for(let t of T){let n=t.v[e],r=Z$(i.grid,t.b.mean,a);n!==n||r!==r||(t.d[e]=n-r,t.b.n[s]>=2&&(n<Z$(i.grid,t.b.lo,a)||n>Z$(i.grid,t.b.hi,a))&&(c=!0,p.add(t.name)))}c?(u!==u&&(u=S[e]),d=S[e],f=NaN,!m&&S[e]-u>=l&&(m=!0,x({type:`deviation`,t0:u,channels:[...p]}))):u===u&&(f!==f&&(f=S[e]),S[e]-f>=l&&h(x))});for(let e of D)x({type:`close`,segment:e});g.writeComputed(e.column,e.unit,y,w);for(let e of T)g.writeComputed(`${e.name} Δ`,g.unitOf(e.name),y,e.d)}}}var l1=1e7;function u1(e=globalThis.navigator?.deviceMemory){return Math.max(512,Math.round(((e??0)>0?e:16)*1024/8))}var d1=400,f1=4e3,p1=1e3,m1=3e3,h1=2,g1=5e3,_1=1e4;function v1(e,t,n=`data`){let r=new oe(t.capacity??l1,void 0,void 0,(t.maxMemoryMB??u1())*1024*1024);return{meta:e,buffer:r,source:new M$(()=>r),unsub:()=>{},status:`connecting`,error:null,lastFrameAt:Date.now(),lastColCount:0,lastValued:0,recorder:null,dropped:0,recDropped:0,video:n===`camera`?new jE:null,clock:n===`camera`?null:new j$,lagTicks:0,lastRejoinAt:0,rejoin:()=>{},subscribed:!1,releaseTimer:void 0}}function y1(e,t,n,r){let i,a=-1/0,o=new Map;return async s=>{if(i===void 0&&(i=s,o.set(t,s)),s===i)return e;if(Date.now()-a<2e3)return null;a=Date.now();let c=await r().catch(()=>null);if(!c||o.has(c.salt)&&o.get(c.salt)!==s)return null;let l=c.key??(n===null?null:await _(n,c.salt));return!l||!await Fe(l,c.key_check).catch(()=>!1)?null:(o.set(c.salt,s),l)}}function b1(e,t,n=()=>({}),r){let i=new Map,a=e,o=[],s=[],c=``,l=()=>{let e=[];for(let t of i.values())t.lastColCount=t.buffer.columnNames.length,t.lastValued=t.buffer.valuedCount,e.push({...t.meta,kind:t.video?`camera`:`data`,video:t.video,clock:t.clock,dataset:t.buffer.toDataset(d1),source:t.source,rowCount:t.buffer.size,status:t.status,error:t.error,recordingSince:t.recorder?.startedAt??null,droppedSamples:t.dropped});o=e,t(o)},u=(e,t)=>{let n=!1,r=e.buffer.endAbs;for(let r of t)r&&typeof r.t==`number`&&Array.isArray(r.signals)&&(e.buffer.push(r),e.recorder?.add(r),n=!0);n&&f(e,r,t[t.length-1]?.t)},d=(e,t)=>{let n=e.buffer.endAbs;e.buffer.pushColumns(t),e.recorder?.addColumns(t),t.t.length>0&&f(e,n,t.t[t.t.length-1])},f=(e,t,n)=>{V$(e.buffer,s,t),e.segAxis?.tracker.feed(e.buffer,t),r?.rows(e.meta.id,e.buffer,t),typeof n==`number`&&e.clock?.observe(n,Date.now()/1e3),p(e,t===0||e.buffer.columnNames.length!==e.lastColCount||e.buffer.valuedCount!==e.lastValued)},p=(e,t)=>{e.lastFrameAt=Date.now();let n=e.status===`stale`||e.status===`connecting`;n&&(e.status=`live`),(n||t)&&l()},m=e=>{let t=i.get(e);t&&(clearTimeout(t.releaseTimer),t.unsub(),i.delete(e),l())},h=setInterval(()=>{let e=Date.now(),t=!1;for(let n of i.values()){n.status===`live`&&e-n.lastFrameAt>f1&&(n.status=`stale`,t=!0);let i=n.video&&n.subscribed&&n.status===`live`?n.video.info().lagMs:null;n.lagTicks=i!==null&&i>m1?n.lagTicks+1:0,n.video&&n.lagTicks>=h1&&e-n.lastRejoinAt>=g1&&(n.lagTicks=0,n.lastRejoinAt=e,n.video.resync(),n.unsub(),n.rejoin()),n.buffer.size&&r?.tick(n.meta.id,n.buffer,n.lastFrameAt)}t&&l()},p1);return{connections:()=>o,disconnect:m,startRecording(e){let t=i.get(e);!t||t.recorder||(t.recorder=new I$,t.recDropped=0,l())},stopRecording(e){let t=i.get(e),n=t?.recorder;return!t||!n?null:(t.recorder=null,l(),{csv:n.toCsvParts(),rows:n.rows,name:t.meta.name,startedAt:n.startedAt,droppedSamples:t.recDropped})},setRelay(e){a=e},setSegmentAxis(e,t){let n=i.get(e);n&&(n.segAxis=t?{cfg:t,tracker:c1(t)}:void 0,t&&n.segAxis.tracker.feed(n.buffer,n.buffer.firstAbs,!t.replay),l())},setMathChannels(e){let t=JSON.stringify(e.map(e=>[e.id,e.name,e.units,e.formula,e.enabled]));if(t!==c){c=t,s=e;for(let t of i.values())t.video||(H$(t.buffer,e),t.segAxis&&(t.segAxis.tracker=c1(t.segAxis.cfg),t.segAxis.tracker.feed(t.buffer,t.buffer.firstAbs,!0)));i.size>0&&l()}},openLocal(e,t){let r=`local:${crypto.randomUUID()}`,a=v1({id:r,name:e,ownerName:`This page`,visibility:`private`,orgName:null,parentId:null,lowOf:null},{...n(),...t});return i.set(r,a),l(),{id:r,push:e=>{i.get(r)===a&&u(a,Array.isArray(e)?e:[e])},pushColumns:e=>{i.get(r)===a&&d(a,e)},close:()=>m(r)}},async connect(e,t,r){if(i.has(e.id))return;let o=a&&e.relay_url?{...a,url:e.relay_url,getToken:async e=>{let t=await a.getToken(e);return t&&!y$(t)?t:null}}:a;if(!o)throw new ME(`relay_unavailable`);let s;if(typeof t==`string`){let n=Ee(t).secret??t,i=await _(n,e.salt);if(!await Fe(i,e.key_check))throw new ME(`wrong_password`);s=r?.reload?y1(i,e.salt,n,r.reload):i}else if(s=`keyFor`in t?e=>t.keyFor(e):t,typeof s!=`function`){if(!await Fe(s,e.key_check))throw new ME(`wrong_password`);r?.reload&&(s=y1(s,e.salt,null,r.reload))}let c=v1({id:e.id,name:e.name,ownerName:e.owner_name??``,visibility:e.visibility??`private`,orgName:e.org_name??null,projectName:e.project_name??null,parentId:e.parent_stream_id??null,lowOf:e.low_of_stream_id??null,limitNotice:e.limit_notice??null},{...n(),...r},e.kind);i.set(e.id,c);let f=t=>{if(i.get(e.id)===c)if(t.type===`video`)c.video&&(c.video.push(t.m),p(c,!1));else if(t.type===`last`){let e=c.buffer;for(let n of t.values)e.setLastKnown(n.name,n.unit,n.t,n.v);(e.columnNames.length!==c.lastColCount||e.valuedCount!==c.lastValued)&&l()}else t.type===`gap`?(c.dropped+=t.samples,c.recorder&&(c.recDropped+=t.samples),l()):t.type===`columns`?d(c,t.block):u(c,t.frames)},m=t=>{!c.subscribed||i.get(e.id)!==c||(t===`subscribed`?(c.status=`live`,c.lastFrameAt=Date.now()):t===`error`&&(c.status=`error`,c.error=`connection_error`),l())};c.rejoin=()=>{c.unsub=c.video?S$(o,e.id,O$(s,f),m):A$(o,e.id,s,f,m)};let h=c.video;h?(c.status=`idle`,h.onDemandChange(t=>{i.get(e.id)===c&&(clearTimeout(c.releaseTimer),t?c.subscribed||(c.subscribed=!0,h.resync(),c.status=`connecting`,c.lastFrameAt=Date.now(),c.rejoin(),l()):c.releaseTimer=setTimeout(()=>{c.subscribed=!1,c.unsub(),c.unsub=()=>{},c.status=`idle`,c.error=null,c.lagTicks=0,l()},_1))})):(c.subscribed=!0,c.rejoin()),l()},dispose(){clearInterval(h);for(let e of i.values())clearTimeout(e.releaseTimer),e.unsub();i.clear(),o=[]}}}var x1=500,S1=1<<20;function C1(e){let t=[],n=new Map,r=[],i=``,a=(e,t)=>`${e}|${t}`,o=(e,t)=>{let n=t.kind===`stream`?e.targets?.streams:t.kind===`history`?e.targets?.histories:e.targets?.datasets;return!n||n.includes(t.kind===`dataset`?t.name??t.id:t.id)},s=()=>[...n.values()].map(e=>{let{state:t,missing:n,since:r}=e.state();return{ruleId:e.rule.id,target:e.target,state:t,...n?{missing:n}:{},...r===void 0?{}:{since:r}}}),c=()=>{let t=s(),n=JSON.stringify(t);n!==i&&(i=n,e.setStates(t))};function l(n,i){let a=t.find(e=>e.id===n.ruleId);if(n.kind===`raised`){r=[...r,{id:`${n.ruleId}|${n.target.id}|${n.t}`,ruleId:n.ruleId,ruleName:a?.name??``,severity:a?.severity??`info`,targetId:n.target.id,timeColumn:i,t0:n.t,t1:null}];let e=r.filter(e=>e.targetId===n.target.id);e.length>x1&&(r=r.filter(t=>t!==e[0]))}else{let e=r.find(e=>e.ruleId===n.ruleId&&e.targetId===n.target.id&&e.t1===null);e&&(r=r.map(t=>t===e?{...t,t1:n.t}:t))}e.setMarks(r),e.emit(n)}function u(){let r=new Set;for(let i of e.targets())for(let e of t){if(!o(e,i))continue;let t=a(e.id,i.id);r.add(t);let s=n.get(t),{channels:c,...u}=i;(!s||s.rule!==e)&&(s=tt(e,u),n.set(t,s));for(let e of s.bind(c))l(e,i.kind===`stream`?$e:``)}for(let e of n.keys())r.has(e)||n.delete(e);c()}return{setRules(n){let r=[],i=n.filter(e=>{let t=nt(e);return r.push(...t.map(t=>({ruleId:String(e?.id??``),...t}))),!t.length}),a=e.maxRules();a!==null&&i.length>a&&e.limit();let o=new Map(t.map(e=>[e.id,e]));return t=(a===null?i:i.slice(0,a)).map(e=>{let t=o.get(e.id);return t&&t.version===e.version?t:e}),u(),r},rules:()=>t,state:s,async evaluate(n,i){let a=e.targets().find(e=>e.id===n&&e.kind===`dataset`);if(!a)return[];let{channels:s,...c}=a,u=[],d=t.filter(e=>(!i.ruleIds||i.ruleIds.includes(e.id))&&o(e,c)),f=d.map(e=>{let t=tt(e,c);return t.bind(s),t}),p=[...new Set(d.flatMap(e=>Object.values(e.signals).map(e=>`formula`in e?e.formula:e.channel)))];for(let t=0;;t+=S1){let r=await e.readDataset(n,[i.timeColumn,...p],t,S1),a=r[i.timeColumn];if(!a||!a.length)break;for(let e of f)u.push(...e.push({t:a,columns:r}));if(a.length<S1)break}r=r.filter(e=>!(e.targetId===n&&(!i.ruleIds||i.ruleIds.includes(e.ruleId)))),e.setMarks(r);for(let e of u)l(e,i.timeColumn);return u},pushLive(e,t){let r=!1;for(let i of n.values()){if(i.target.id!==e)continue;let n=i.push(t);n.length&&(r=!0);for(let e of n)l(e,$e)}r&&c()},tickLive(e,t){let r=!1;for(let i of n.values()){if(i.target.id!==e)continue;let n=i.tick(t);n.length&&(r=!0);for(let e of n)l(e,$e)}r&&c()},liveColumns(e){let t=new Set;for(let r of n.values())if(r.target.id===e)for(let e of Object.values(r.rule.signals))t.add(`formula`in e?e.formula:e.channel);return[...t]},sync:u,clearMarks(t){r=t?r.filter(e=>e.targetId!==t):[],e.setMarks(r)}}}var w1=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}},T1={maxChartsPerWorksheet:null,maxChannelsPerChart:null,maxWorksheets:null,maxMathChannels:null,maxAlertRules:null,canImportExportWorkspaces:!0},E1=[];function D1(e,t){let n=e.found[t];return{definitionId:n.definitionId,rule:e.defs.find(e=>e.id===n.definitionId)?.name??n.definitionId,index:n.index,parentIndex:n.parentIndex??null,tstart:n.tstart,tend:n.tend,flags:n.flags,kpis:n.kpis??{},incomplete:!!n.incomplete}}var O1=[`#a78bfa`,`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#94a3b8`];function k1(e=`ET`){return{id:crypto.randomUUID(),name:`Worksheet`,panels:[],panelChartSettings:{},panelChartBackgrounds:{},xKey:e}}function A1(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(lr({...e,name:a,source:`workbook`}))}return{channels:i,rename:r}}function j1(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 M1(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 N1(e,t,n){if(!e||!t)return en();let{min:r,max:i}=Tz(e.rows,t);if(!Number.isFinite(r)||!Number.isFinite(i))return en();let a=Dz(i-r||1,6),o=a>=1?Math.round(a):a,s=o>=1?1:o/10,c=Math.max(0,Math.ceil(-Math.log10(s))),l=e=>String(Number(e.toFixed(c)));return{...n,scaleMin:l(Math.floor(r/s)*s),scaleMax:l(Math.ceil(i/s)*s),majorStep:l(o),minorStep:``}}function P1(e,t){let n=t.includes(e.xKey)?e.xKey:t.includes(`ET`)?`ET`:t.includes(`ElapsedTime`)?$e: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:mn();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:hn(O1[2]),a=i.xyXCol||t[0],o=i.xyYCol||(t.length>1&&t[1]!==a?t[1]:t[0]);r[n.id]={...i,kind:`xyscatter`,xyXCol:a,xyYCol:o}}else if(n.kind===`xyzmesh`){let i=e&&e.kind===`xyzmesh`?e:gn(4),a=i.xyzXCol||t[0],o=i.xyzYCol||(t.length>1?t[1]:t[0]),s=i.xyzZCol||(t.length>2?t[2]:t[0]);r[n.id]={...i,kind:`xyzmesh`,xyzXCol:a,xyzYCol:o,xyzZCol:s}}}return{...e,xKey:n,panelChartSettings:r}}function F1(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 I1(){return typeof document>`u`?`dark`:nB(null)}function L1(e={}){let t={...e},n=!1,r=k1(),i=i$({datasets:[],selection:[],worksheets:[r],activeWorksheetId:r.id,xRanges:{},offsets:{},colors:{},liveWindowSeconds:15,segmentContext:null,cycleRules:[],live:[],video:[],mathChannels:[],limits:{...T1,...t.limits},palette:$z(t.palette,I1()),importing:0,licensed:null,history:{canUndo:!1,canRedo:!1},marks:[],alerts:[],alertRules:[]}),a=HV(),o=()=>{let e=$z(t.palette,I1());i.set(t=>t.palette.join()===e.join()?t:{...t,palette:e})},s=typeof document>`u`?()=>{}:rB(null,o),c=o$(),l=()=>{if(n)throw new ME(`disposed`)},u=e=>{throw a.emit(`limit`,{reason:e}),new ME(`limit_reached`,{reason:e})},d=()=>i.get(),f=(e,t)=>{let n=d().limits.maxChannelsPerChart,r=Ez(t);n!==null&&r>n&&r>Ez(e)&&u(`channels-per-chart`)},p=a$((e,t)=>t===null?e:e.slice(0,t)),h=()=>{let e=d(),t=c.lapsByDataset(e.datasets),n=c.selectedDatasets(e.datasets,t,e.selection),r=c.selectedLive(e.live,e.selection),i=c.staticDataset(n),a=c.mergedDataset(i,r),o=p(e.mathChannels,e.limits.maxMathChannels);return{laps:t,selectedDatasets:n,selectedLive:r,staticDataset:i,merged:a,channels:o,numericColumns:c.numericColumns(a,n,o,c.mergedParts(n,r),r),allColumns:c.allColumns(a,n,o),columnUnits:c.columnUnits(a,o)}},g=(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??E1,layout:t.rect}),_=a$((e,t,n)=>e.map(e=>({id:e.id,name:e.name,xKey:e.xKey,xRange:t[e.id]??null,liveWindowSeconds:e.liveWindowSeconds===void 0?n:e.liveWindowSeconds,charts:e.panels.map(t=>g(e,t))}))),v=a$((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:Zz(n,e.id,s(e.id,a),o),customColor:e.id in n,offset:r[e.id]??0,parseConfig:e.parseConfig??null,fileInfo:e.info??null,beacon:e.beacon??null,cut:e.cut?{cycleId:e.cut.cycleId,timeKey:e.cut.timeKey,defs:e.cut.defs}:null,laps:c?c.laps.map((i,a)=>({id:i.id,name:i.name,value:c.values[a],unit:c.unit,isTime:c.isTime,color:Zz(n,i.id,s(i.id,a),o),offset:r[i.id]??0,selected:t.includes(i.id),...e.cut?{cycle:D1(e.cut,a)}:{}})):null,selected:c?u===0?!1:u===l.length?!0:`partial`:t.includes(e.id)}})}),b=a$((e,t,n,r,i)=>{let a=e.filter(e=>t.includes(e.id)).map(e=>e.id);return e.map((e,o)=>({id:e.id,name:e.name,ownerName:e.ownerName,visibility:e.visibility,orgName:e.orgName,kind:e.kind,parentId:e.parentId,lowOf:e.lowOf,status:e.status,error:e.error,rowCount:e.rowCount,selected:t.includes(e.id),color:Zz(n,e.id,a.includes(e.id)?r+a.indexOf(e.id):o,i),customColor:e.id in n,recordingSince:e.recordingSince,limitNotice:e.limitNotice??null,channels:e.dataset.columnNames}))}),x=a$(e=>{let t=h();return{datasets:v(e.datasets,e.selection,e.colors,e.offsets,t.laps,t.selectedDatasets,e.palette),selection:e.selection,worksheets:_(e.worksheets,e.xRanges,e.liveWindowSeconds),activeWorksheetId:e.activeWorksheetId,mathChannels:t.channels,live:b(e.live,e.selection,e.colors,t.selectedDatasets.length,e.palette),liveWindowSeconds:(()=>{let t=e.worksheets.find(t=>t.id===e.activeWorksheetId);return t?.liveWindowSeconds===void 0?e.liveWindowSeconds:t.liveWindowSeconds})(),segmentContext:e.segmentContext,cycleRules:e.cycleRules,limits:e.limits,palette:e.palette,importing:e.importing,licensed:e.licensed,hasData:t.merged!==null,multiDataset:t.selectedDatasets.length+t.selectedLive.length>1,numericColumns:t.numericColumns,allColumns:t.allColumns,columnUnits:t.columnUnits,history:e.history,marks:e.marks,alerts:e.alerts}}),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 w1({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--}},D=e=>[e.worksheets,e.mathChannels,e.liveWindowSeconds],O=[],k=()=>{let e=d();return{worksheets:e.worksheets,channels:e.mathChannels.filter(e=>e.source===`workbook`),liveWindowSeconds:e.liveWindowSeconds,activeWorksheetId:e.activeWorksheetId}},A=()=>i.set(e=>e.history.canUndo===C.canUndo&&e.history.canRedo===C.canRedo?e:{...e,history:{canUndo:C.canUndo,canRedo:C.canRedo}}),j=()=>{if(w)return;let e=D(d());e.every((e,t)=>e===O[t])||(O=e,T?C.rebase(k()):C.observe(k()),A())},M=()=>{O=D(d()),C.clear(k()),A()},N=e=>{w=!0;let t;try{t=e()}finally{w=!1}return M(),t},P=()=>x(d());i.subscribe(()=>{j(),a.emit(`change`,P())});let F=e=>{let t=d(),n=t.worksheets.find(n=>n.id===(e??t.activeWorksheetId));if(!n)throw new ME(`not_found`,{worksheetId:e});return n},I=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 ME(`not_found`,{chartId:e})},L=(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}),R=(e,t)=>{let{ws:n}=I(e);L(n.id,n=>({...n,panelChartSettings:{...n.panelChartSettings,[e]:t(n.panelChartSettings[e])}}))},z=e=>i.set(t=>e.length===t.selection.length&&e.every((e,n)=>e===t.selection[n])?t:{...t,selection:e,xRanges:{}}),B=new Set,ee=b1(t.live?.relay,e=>{let t=e.map(e=>e.id),n=e.filter(e=>e.kind===`data`&&!B.has(e.id)).map(e=>e.id),r=[...B].filter(e=>!t.includes(e));if(B=new Set(t),i.set(t=>({...t,live:e})),r.length&&z(d().selection.filter(e=>!r.includes(e))),n.length){let e=d().selection,t=n.filter(t=>!e.includes(t));t.length&&z([...e,...t])}let a=h();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(()=>L(t.id,e=>({...e,xKey:$e})))}},()=>({capacity:t.live?.capacity,maxMemoryMB:t.live?.maxMemoryMB}),{rows:(e,t,n)=>{if(!le.rules().length)return;t.columnNames.length!==te.get(e)&&(te.set(e,t.columnNames.length),le.sync());let r=le.liveColumns(e);if(!r.length)return;let i=t.endAbs,a=Math.max(n,t.firstAbs);if(i<=a)return;let o={};for(let e of r)o[e]=t.range(e,a,i);le.pushLive(e,{t:t.range($e,a,i),columns:o,scan:new Map})},tick:(e,t,n)=>{if(!le.rules().length)return;let r=t.range($e,t.endAbs-1,t.endAbs)[0];r===r&&le.tickLive(e,r+(Date.now()-n)/1e3)}}),te=new Map,H=a$((e,t)=>e.filter(e=>t.some(t=>CE([e],t.panelChartSettings,t.xKey).length>0))),re=()=>ee.setMathChannels(H(p(d().mathChannels,d().limits.maxMathChannels),d().worksheets));re(),i.subscribe(re);let ie=e=>{i.set(t=>({...t,datasets:[...t.datasets,e]})),z([...d().selection,e.id]);let t=wz(e.schema);t.length&&E(()=>i.set(e=>({...e,worksheets:e.worksheets.map(e=>P1(e,t))})))},U=Promise.resolve(),ae=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 ME(`import_vetoed`);let{signal:s}=r;i.set(e=>({...e,importing:e.importing+o.length}));let c=U.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 AR(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 Cz({main:t,companions:i.companions,format:i.format.id},{priorInMemoryValues:SR(d().datasets),signal:s,onProgress:e=>a.emit(`import`,{file:t.name,phase:`progress`,fraction:e}),chooseChannels:r.chooseChannels,pickChannels:r.pickChannels}):[await xR(crypto.randomUUID(),t,d().datasets)??await yR(crypto.randomUUID(),t,M1,void 0,SR(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 ME(`cancelled`)}for(let t of o)ie(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 ME&&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 U=c.catch(()=>void 0),c},oe=()=>setTimeout(()=>{n||_Q(nt)},0),se=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}}),z(d().selection.filter(e=>!t(e))),n.length>0&&oe()},ce=async(e,t,n={})=>{let[r,...i]=await Cz({main:new File(e.chunks,`${e.name}.krc`),companions:[],format:`krc`,keys:e.keys},{priorInMemoryValues:t,...n});for(let e of i)e.source.dispose();return{...r,file:void 0,name:e.name,info:r.info&&{...r.info,startTime:e.startTime??r.info.startTime,meta:{...r.info.meta,recordingId:e.recordingId}}}},le=C1({targets:()=>[...d().datasets.map(e=>({kind:`dataset`,id:e.id,name:e.name,channels:e.schema.map(e=>e.name)})),...d().live.filter(e=>e.kind===`data`).map(e=>({kind:`stream`,id:e.id,name:e.name,channels:e.source.columnNames}))],maxRules:()=>d().limits.maxAlertRules,emit:e=>a.emit(`alert`,e),limit:()=>a.emit(`limit`,{reason:`alert-rules`}),setMarks:e=>i.set(t=>({...t,marks:e})),setStates:e=>i.set(t=>({...t,alerts:e})),readDataset:(e,t,n,r)=>{let i=d().datasets.find(t=>t.id===e);return i?i.source.readColumns(t,n,r):Promise.resolve({})}}),ue=a$((e,t)=>{let n=new Map;for(let r of e){let e=it(r);e!==null&&n.set(r.id,{value:e,active:t.some(e=>e.ruleId===r.id&&(e.state===`active`||e.state===`clearing`))})}return n}),de=null;i.subscribe(()=>{let e=d();de&&de[0]===e.datasets&&de[1]===e.live||(de=[e.datasets,e.live],le.rules().length&&le.sync())});let fe={importFiles:ae,warmImport(e={}){l(),dz(!!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 ME(`not_found`,{datasetId:e});if(!t.info?.combined||!(t.file instanceof File))throw new ME(`invalid_argument`,{reason:`only a combined multi-rate import can be split`});let n=await Cz({main:t.file,companions:t.companions??[],format:t.info.importer},{priorInMemoryValues:SR(d().datasets.filter(t=>t.id!==e)),selection:t.info.selection,split:!0});se([e]);for(let e of n)ie(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 ME(`not_found`,{datasetId:e});if(!n.info||!(n.file instanceof File))throw new ME(`invalid_argument`,{reason:`only binary imports have channels to choose`});try{let r=await Cz({main:n.file,companions:n.companions??[],format:n.info.importer},{priorInMemoryValues:SR(d().datasets.filter(t=>t.id!==e)),initial:n.info.selection,chooseChannels:t,pickChannels:!0});se([e]);for(let e of r)ie(e);return r.map(e=>e.id)}catch(e){if(e instanceof ME&&e.code===`cancelled`)return null;throw e}},async combine(e){l();let t=d().datasets.find(t=>t.id===e);if(!t)throw new ME(`not_found`,{datasetId:e});let n=t.info?.splitKey;if(!n||!(t.file instanceof File))throw new ME(`invalid_argument`,{reason:`only datasets split from one file can be combined`});let r=d().datasets.filter(e=>e.info?.splitKey===n),i=await Cz({main:t.file,companions:t.companions??[],format:t.info.importer},{priorInMemoryValues:SR(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 ME(`invalid_argument`,{reason:`these groups have no common time base`})}return se(r.map(e=>e.id)),ie(i[0]),i[0].id},async openRecording(e,t={}){l();let n=await ce(e,SR(d().datasets),t);return ie(n),n.id},async reopenRecording(e,t){l();let n=d().datasets.find(t=>t.id===e);if(!n)throw new ME(`not_found`,{datasetId:e});let r=await ce(t,SR(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),oe()},openHistoryRange(e){l();let t=r$(crypto.randomUUID(),e);return ie(t),t.id},updateHistoryRange(e,t){l();let n=d().datasets.find(t=>t.id===e);if(!n)throw new ME(`not_found`,{datasetId:e});if(!(n.source instanceof KQ)){let t=`dataset ${e} is not a history range: only datasets opened with openHistoryRange can be updated`;throw Object.assign(new ME(`invalid_argument`,{datasetId:e,reason:t}),{message:t})}let r=r$(e,t);i.set(t=>({...t,datasets:t.datasets.map(t=>t.id===e?{...r,beacon:n.beacon}:t)})),oe()},addColumns(e){l();let t=XQ(crypto.randomUUID(),e);return ie(t),t.id},replaceColumns(e,t,n={}){l();let r=d().datasets.find(t=>t.id===e);if(!r)throw new ME(`not_found`,{datasetId:e});let a=e$(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 ME(`not_found`,{datasetId:e});let a=QQ(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 gR(crypto.randomUUID(),t,e);return ie(n),n.id},async findCycles(e,t,n){l();let r=d().datasets.find(t=>t.id===e);if(!r)throw new ME(`not_found`,{datasetId:e});let i=await UB(r.source,n,GB(t)),a=new Map(t.filter(e=>e.kpis?.length).map(e=>[e.id,e.kpis]));return WB(i,t).map(e=>a.has(e.definitionId)?{...e,kpis:qB(i,e,a.get(e.definitionId))}:e)},async addCycles(e,t){l();let n=d().datasets.find(t=>t.id===e);if(!n)throw new ME(`not_found`,{datasetId:e});let r=n.schema.filter(e=>e.type===`number`&&e.name!==t.timeKey).map(e=>e.name),i=await UB(n.source,t.timeKey,r),a={...Object.fromEntries(n.schema.map(e=>[e.name,e.unit])),[VB]:`s`},o=e=>t.defs.find(t=>t.id===e)?.name??e,s=[];for(let e of t.pick){let r=t.found.find(t=>t.definitionId===e.definitionId&&t.index===e.index&&t.parentIndex===e.parentIndex);if(!r)throw new ME(`not_found`,{reason:`no ${o(e.definitionId)} ${e.index} in the cycles found`});let c=r.parentIndex?`${o(t.cycleId)} ${r.parentIndex} · ${o(r.definitionId)}`:`${o(r.definitionId)} ${r.index}`;s.push(fe.addColumns({name:`${n.name} · ${c}`,columns:YB(i,t.timeKey,r),units:a}))}if(t.tables!==!1){let e=ZB(t.found,t.cycleId,t.defs,i);s.push(await fe.addText(QB(e.cycles),`${n.name} · ${o(t.cycleId)}s.csv`)),e.phases.length&&s.push(await fe.addText(QB(e.phases),`${n.name} · Phases.csv`))}return s},async cut(e,t){l();let n=d().datasets.find(t=>t.id===e);if(!n)throw new ME(`not_found`,{datasetId:e});let r;if(t){if(!t.defs.some(e=>e.id===t.cycleId))throw new ME(`invalid_argument`,{reason:`cycleId is not one of defs`});let i=n.schema.filter(e=>e.type===`number`&&e.name!==t.timeKey).map(e=>e.name),a=await UB(n.source,t.timeKey,i),o=t.defs.find(e=>e.id===t.cycleId)?.show,s=e=>[...e.kpis??[],...o&&o.channel!==t.timeKey?[o]:[]],c=new Map(t.defs.filter(e=>s(e).length).map(e=>[e.id,s(e)])),l=WB(a,t.defs).sort((e,t)=>e.tstart-t.tstart||!!e.parentIndex-+!!t.parentIndex).map(e=>c.has(e.definitionId)?{...e,kpis:qB(a,e,c.get(e.definitionId))}:e),u={...Object.fromEntries(n.schema.map(e=>[e.name,e.unit])),[VB]:`s`},d=e=>t.defs.find(t=>t.id===e)?.name??e,f=l.map(r=>XQ(`${e}::${r.definitionId}:${r.parentIndex??0}:${r.index}`,{name:r.parentIndex?`${n.name} · ${d(t.cycleId)} ${r.parentIndex} · ${d(r.definitionId)}`:`${n.name} · ${d(r.definitionId)} ${r.index}`,columns:YB(a,t.timeKey,r),units:u})),p=a.t.length?a.t[a.t.length-1]:NaN,m=l.map(e=>e.tend===null&&p===p?{...e,tend:p,incomplete:!0}:e);r={defs:t.defs,cycleId:t.cycleId,timeKey:t.timeKey,found:m,parts:f}}else if(!n.cut)return 0;if(!d().datasets.some(t=>t.id===e))return 0;i.set(t=>({...t,datasets:t.datasets.map(t=>t.id===e?{...t,cut:r}:t)}));let a=d().selection,o=a.some(t=>t===e||t.startsWith(`${e}::`)),s=a.filter(t=>t!==e&&!t.startsWith(`${e}::`)),c=r?r.parts.filter((e,t)=>!r.found[t].parentIndex).map(e=>e.id):[];return z(o?c.length>0?[...s,...c]:[...s,e]:s),c.length},remove(e){l(),se([e])},clear(){l(),se(d().datasets.map(e=>e.id))},async configure(e,t){l();let n=d().datasets.find(t=>t.id===e);if(!n)throw new ME(`not_found`,{datasetId:e});if(t.parseConfig&&(n.kind!==`memory`||!n.parseConfig))throw new ME(`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 ME(`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?xB(n.data.rows,r.channel):[],l=r&&t.selectCycles===`best`?EB(c.map(e=>TB(n.data.rows,e,r.metric,r.stat))):null,u=l===null?c.map((t,n)=>kB(e,n)):[kB(e,l)];z(o?c.length>0?[...s,...u]:[...s,e]:s)}let r=t.parseConfig;if(!r)return;let a=(()=>{try{let e=V(y(n.rawText??``),r.headerRow);return n.data.columnNames.length===e.length&&n.data.columnNames.every((t,n)=>t===e[n])}catch{return!1}})();if(ne(r,n.parseConfig)&&a)return;let o=n.fromColumns?n$(n):n.rawText??``,s=await LE(n.file?{file:n.file,config:r}:{rawText:o,config:r}),c=new BE(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),oe(),n.cut&&await fe.cut(e,n.cut);let p=h().selectedDatasets,g=new Set(p.flatMap(e=>e.data.columnNames)),_=s.columnNames.filter(e=>m(s.rows,e)),v=_.find(e=>e===`ET`)??_[0];E(()=>i.set(e=>({...e,worksheets:e.worksheets.map(e=>F1(!g.has(e.xKey)&&v?{...e,xKey:v}:e,e=>g.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(),z([...e])},toggle(e){l();let t=d().selection,n=h().laps[e];if(n){let e=n.laps.map(e=>e.id);z(e.every(e=>t.includes(e))?t.filter(t=>!e.includes(t)):[...t,...e.filter(e=>!t.includes(e))]);return}z(t.includes(e)?t.filter(t=>t!==e):[...t,e])},selectAll(){l();let e=h().laps,t=d().live.filter(e=>d().selection.includes(e.id)).map(e=>e.id);z([...d().datasets.flatMap(t=>e[t.id]?e[t.id].laps.map(e=>e.id):[t.id]),...t])},deselectAll(){l(),z([])},raw(e){let t=d().datasets.find(t=>t.id===e);if(!t)throw new ME(`not_found`,{datasetId:e});return{get rawText(){return t.kind===`memory`&&t.fromColumns?n$(t):t.rawText??``},data:t.data,parseConfig:t.parseConfig??null,kind:t.kind,beacon:t.beacon??null}},async columnBounds(e){l();let t=h(),n=t.selectedDatasets.find(t=>t.schema.some(t=>t.name===e));if(n&&n.kind===`memory`){let t=Tz(n.data.rows,e);if(Number.isFinite(t.min)&&Number.isFinite(t.max))return t}else if(n){let t=await n.source.xBounds(e).catch(()=>null);if(t&&Number.isFinite(t.x0)&&Number.isFinite(t.x1)&&t.x1>=t.x0)return{min:t.x0,max:t.x1}}let r=t.selectedLive.find(t=>t.dataset.columnNames.includes(e));if(r){let t=r.source.valueBoundsSync(e);if(t)return t}let i=pe(e);if(!i)return null;let a=Tz(i.rows,e);return Number.isFinite(a.min)&&Number.isFinite(a.max)?a:null}},pe=(e,t=F().xKey)=>{let n=h();if(!n.merged)return null;if(!n.channels.find(t=>t.name===e))return n.merged;let r=SE(n.merged,n.channels,t);return{...n.merged,columnNames:[...n.merged.columnNames,...r.ok.map(e=>e.name)],rows:r.rows}},me=(e,t,n)=>h().selectedLive.length>0?{...n,scaleMin:``,scaleMax:``,majorStep:``,minorStep:``}:N1(pe(e,t),e,n),he={fromFileList:e=>kV(Array.from(e)),async fromDataTransfer(e){return AV(Array.from(e.items??[]).map(e=>e.webkitGetAsEntry?.()).filter(e=>!!e))},canPick:jV,pick:MV,tree:(e,t)=>OV(e,t),isImportable:DV},ge={add(e=`Worksheet`){l();let t=d(),n=t.limits.maxWorksheets;n!==null&&t.worksheets.length>=n&&u(`worksheets`);let r={...k1(F().xKey||`ET`),name:e};return i.set(e=>({...e,worksheets:[...e.worksheets,r],activeWorksheetId:r.id})),r.id},rename(e,t){l(),F(e),L(e,e=>e.name===t?e:{...e,name:t})},remove(e){l();let t=d();if(F(e),t.worksheets.length<=1)throw new ME(`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(),F(e),i.set(t=>t.activeWorksheetId===e?t:{...t,activeWorksheetId:e,xRanges:{...t.xRanges,[e]:null}})},setXKey(e,t){l(),F(e),L(e,e=>F1({...e,xKey:t},e=>e!==t)),i.set(t=>({...t,xRanges:{...t.xRanges,[e]:null},offsets:{}}))}},_e={mount(e,t,n){return l(),gQ(nt,e,t,n)},openWindow(e,t){return l(),I(e),BQ(nt,e,(t,n)=>gQ(nt,e,t,n),t)},setFonts(e){e.sans&&(Q.sans=e.sans),e.mono&&(Q.mono=e.mono),_Q(nt)},kinds:()=>s$,label:l$,add(e,t={}){if(l(),!s$.some(t=>t.kind===e))throw new ME(`invalid_argument`,{kind:e});let n=F(t.worksheetId),r=d().limits.maxChartsPerWorksheet;r!==null&&n.panels.length>=r&&u(`charts-per-worksheet`);let i={...Zt(e,n.panels),...t.title?{title:t.title}:{}};t.layout&&(i.rect={...t.layout});let a=ar([i],{},O1[2],4)[i.id],o=a,s=h().numericColumns;if(s.length&&(o.kind===`multiband`||o.kind===`xyscatter`||o.kind===`xyzmesh`)&&(o=P1({...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??me(o.xyXCol,n.xKey,o.xyXScale),xyYScale:e.xyYScale??me(o.xyYCol,n.xKey,o.xyYScale)}}return f(a,o),L(n.id,e=>({...e,panels:t.layout?[...e.panels,i]:$t([...e.panels,i]),panelChartSettings:{...e.panelChartSettings,[i.id]:o}})),i.id},remove(e){l();let{ws:t}=I(e);L(t.id,t=>{let n={...t.panelChartSettings},r={...t.panelChartBackgrounds};return delete n[e],delete r[e],{...t,panels:$t(t.panels.filter(t=>t.id!==e)),panelChartSettings:n,panelChartBackgrounds:r}})},rename(e,t){l();let{ws:n}=I(e),r=t?.trim()||void 0;L(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}=I(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:me(e.xyXCol,n.xKey,r.xyXScale)}),typeof e.xyYCol==`string`&&e.xyYCol!==r.xyYCol&&!(`xyYScale`in e)&&(i={...i,xyYScale:me(e.xyYCol,n.xKey,r.xyYScale)})}f(r,i),R(e,()=>i)},replaceSettings(e,t){l();let{ws:n,panel:r}=I(e);if(t.kind!==r.kind)throw new ME(`invalid_argument`,{reason:`settings kind mismatch`});f(n.panelChartSettings[e],t),R(e,()=>t)},setBackground(e,t){l();let{ws:n}=I(e);L(n.id,n=>({...n,panelChartBackgrounds:{...n.panelChartBackgrounds,[e]:t}}))},addAnnotation(e,t){l(),I(e);let n=Pt({...t,id:t.id||crypto.randomUUID()});if(!n)throw new ME(`invalid_argument`,{reason:`not a valid annotation`});return R(e,e=>({...e,annotations:[...(e.annotations??[]).filter(e=>e.id!==n.id),n]})),n.id},updateAnnotation(e,t,n){l();let r=(I(e).ws.panelChartSettings[e]?.annotations??[]).find(e=>e.id===t);if(!r)throw new ME(`not_found`,{annotationId:t});let i=Pt({...r,...n,id:r.id,kind:r.kind});if(!i)throw new ME(`invalid_argument`,{reason:`not a valid annotation`});R(e,e=>({...e,annotations:(e.annotations??[]).map(e=>e.id===i.id?i:e)}))},removeAnnotation(e,t){l(),I(e),R(e,e=>({...e,annotations:(e.annotations??[]).filter(e=>e.id!==t)}))},setAnnotations(e,t){l(),I(e);let n=Ft(t)??[];R(e,e=>({...e,annotations:n}))},setLayout(e,t){l();let{ws:n}=I(e);L(n.id,n=>({...n,panels:n.panels.map(n=>n.id===e?{...n,rect:{...t}}:n)}))},setLayouts(e,t){l(),L(e,e=>({...e,panels:e.panels.map(e=>t[e.id]?{...e,rect:{...t[e.id]}}:e)}))},autoLayout(e){l(),L(F(e).id,e=>({...e,panels:$t(e.panels)}))},get(e){let{ws:t,panel:n}=I(e);return g(t,n)},list(e){let t=F(e);return t.panels.map(e=>g(t,e))},async addSeries(e,t){l();let{ws:n}=I(e),r=n.panelChartSettings[e];if(!r||r.kind!==`multiband`)throw new ME(`invalid_argument`,{reason:`not a multiband chart`});let i=d().limits.maxChannelsPerChart;i!==null&&Ez(r)>=i&&u(`channels-per-chart`);let a=h().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=cr(),f={id:c,column:s,color:O1[r.series.length%O1.length],bandFromPct:0,bandToPct:100,scaleMin:0,scaleMax:1,yMajorStep:0,yMinorStep:0};return R(e,e=>e.kind===`multiband`?{...e,series:[...e.series,f]}:e),await _e.autoScaleSeries(e,c),c},async updateSeries(e,t,n){l();let{ws:r}=I(e),i=r.panelChartSettings[e],a=i&&i.kind===`multiband`?i.series.find(e=>e.id===t):void 0;if(!a)throw new ME(`not_found`,{seriesId:t});R(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 _e.autoScaleSeries(e,t)},removeSeries(e,t){l(),R(e,e=>e.kind===`multiband`?{...e,series:e.series.filter(e=>e.id!==t)}:e)},reorderSeries(e,t){l(),R(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}=I(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 fe.columnBounds(a.column);!o||n||R(e,e=>e.kind===`multiband`?{...e,series:e.series.map(e=>e.id===t?{...e,scaleMin:o.min,scaleMax:o.max}:e)}:e)}},ve=new Map,ye={setXRange(e,t){l();let n=F(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){ye.setXRange(null,e)},setCursorX(e,t){l();let n=F(t).id;(ve.get(n)??null)!==e&&(ve.set(n,e),a.emit(`cursorchange`,{worksheetId:n,x:e}))},cursorX(e){return ve.get(F(e).id)??null},setLiveWindow(e,t){l();let n=F(t);n.liveWindowSeconds!==e&&L(n.id,t=>({...t,liveWindowSeconds:e}))},setSegmentContext(e){l(),i.set(t=>JSON.stringify(t.segmentContext)===JSON.stringify(e)?t:{...t,segmentContext:e})}},be={save(e){l();let t=e.id??crypto.randomUUID(),[n]=BB([{...e,id:t,parentId:e.parentId??null}].concat(d().cycleRules.filter(e=>e.id!==t))).filter(e=>e.id===t);if(!n)throw new ME(`invalid_argument`,{reason:`not a valid cycle rule (or its parent is missing)`});return i.set(e=>({...e,cycleRules:e.cycleRules.some(e=>e.id===t)?e.cycleRules.map(e=>e.id===t?n:e):[...e.cycleRules,n]})),t},remove(e){l();let t=new Set([e]);for(let e=!0;e;){e=!1;for(let n of d().cycleRules)n.parentId&&t.has(n.parentId)&&!t.has(n.id)&&(t.add(n.id),e=!0)}i.set(e=>({...e,cycleRules:e.cycleRules.filter(e=>!t.has(e.id))}))}},xe={create(e){l();let n=d(),r=n.limits.maxMathChannels;r!==null&&n.mathChannels.length>=r&&u(`math-channels`);let o=lr(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 ME(`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 ME(`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 EE(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:()=>wE(d().mathChannels),preview(e,t){let n=h();return n.merged?iE(e,n.merged,F(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}})}},Se=a$((e,t)=>[...e.flatMap(e=>e.kind===`camera`&&e.video?[AE({...e,video:e.video})]:[]),...t]),Ce=``;i.subscribe(()=>{let e=Se(d().live,d().video),t=e.map(e=>`${e.kind}:${e.id}:${e.recordingId??``}:${e.name}`).join(`|`);t!==Ce&&(Ce=t,a.emit(`videochange`,{sources:e}))});let we=(e,t,n)=>e.id===t&&(n===void 0||(e.recordingId??null)===n),Te={sources:()=>Se(d().live,d().video),register(e){l(),i.set(t=>({...t,video:[...t.video.filter(t=>!we(t,e.id,e.recordingId??null)),e]}))},unregister(e,t){l(),i.set(n=>n.video.some(n=>we(n,e,t))?{...n,video:n.video.filter(n=>!we(n,e,t))}:n)}},Ee={openLocal(e,t){return l(),ee.openLocal(e,t)},async connect(e,t,n){l(),await ee.connect(e,t,n)},startRecording(e){l(),ee.startRecording(e)},stopRecording(e){return l(),ee.stopRecording(e)},setSegmentAxis(e,t){l(),ee.setSegmentAxis(e,t)},rowCount(e){return ee.connections().find(t=>t.id===e)?.source.size()??0},disconnect(e){l(),ee.disconnect(e),z(d().selection.filter(t=>t!==e))}},De=()=>{d().limits.canImportExportWorkspaces||u(`workspaces-io`)},Oe=async e=>{if(e instanceof Blob)try{return JSON.parse(await e.text())}catch{throw new ME(`bad_file`)}if(typeof e==`string`)try{return JSON.parse(e)}catch{throw new ME(`bad_file`)}return e},ke=async e=>e instanceof File?e:new File([JSON.stringify(await Oe(e))],`import.json`,{type:`application/json`}),Ae=e=>e.replace(/[^\w.-]+/g,`_`),je=e=>new Blob([JSON.stringify(e,null,2)],{type:`application/json`}),Me=e=>{let t=ir(e.panelChartSettings,O1[2],4),n={};for(let r of e.panels)t[r.id]?.kind===r.kind&&(n[r.id]=t[r.id]);return{...e,panelChartSettings:ar(e.panels,n,O1[2],4)}},Ne=(e,t)=>e.map(e=>{let n=e=>{let n=t.has(e)?crypto.randomUUID():e;return t.add(n),n},r=new Map(e.panels.map(e=>[e.id,n(e.id)])),i=e=>Object.fromEntries(Object.entries(e).map(([e,t])=>[r.get(e)??e,t]));return{...e,id:n(e.id),panels:e.panels.map(e=>({...e,id:r.get(e.id)})),panelChartSettings:i(e.panelChartSettings),panelChartBackgrounds:i(e.panelChartBackgrounds??{})}}),Pe=()=>new Set(d().worksheets.flatMap(e=>[e.id,...e.panels.map(e=>e.id)])),Fe=(e,t=0)=>{let n=d().limits.maxWorksheets,r=Ne((n===null?e:e.slice(0,Math.max(1,n))).map(Me),new Set),a=r[Math.min(t,r.length-1)];i.set(e=>({...e,worksheets:r,activeWorksheetId:a.id,xRanges:{}}))},Ie=(e,t)=>{let n=F(t),r=d().limits.maxChartsPerWorksheet;r!==null&&n.panels.length>=r&&u(`charts-per-worksheet`);let i=d().limits.maxChannelsPerChart;i!==null&&Ez(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 L(n.id,t=>({...t,panels:$t([...t.panels,o]),panelChartSettings:{...t.panelChartSettings,[a]:e.settings},panelChartBackgrounds:e.background===null?t.panelChartBackgrounds:{...t.panelChartBackgrounds,[a]:e.background}})),a},Le=()=>{let e=d();return dV({worksheets:e.worksheets,activeWorksheetId:e.activeWorksheetId,channels:H(p(e.mathChannels,e.limits.maxMathChannels),e.worksheets),liveWindowSeconds:e.liveWindowSeconds,laps:e.datasets.find(e=>e.beacon)?.beacon??null,segments:e.segmentContext,cycles:e.cycleRules})},Re=e=>{if(e.worksheets.length===0)throw new ME(`bad_workspace`,{errors:e.errors});let{channels:t,rename:n}=A1(d().mathChannels,e.mathChannels);Fe(n.size?e.worksheets.map(e=>j1(e,n)):e.worksheets,e.activeIndex),i.set(n=>({...n,mathChannels:[...n.mathChannels.filter(e=>e.source!==`workbook`),...t],liveWindowSeconds:e.liveWindowSeconds===void 0?n.liveWindowSeconds:e.liveWindowSeconds,segmentContext:e.segments??null,cycleRules:e.cycles}));let r=e.laps;if(r)for(let e of d().datasets)e.kind!==`memory`||e.beacon||!e.data.columnNames.includes(r.channel)||fe.configure(e.id,{beacon:r}).catch(e=>a.emit(`error`,{error:e,context:`io.openWorkbook`}));return{worksheets:e.worksheets.length,errors:e.errors}},ze=e=>{if(e===null)return;let t=h().numericColumns,n=t.length?e.worksheets.map(e=>P1(e,t)):e.worksheets;w=!0;try{i.set(t=>{let r=t=>e.worksheets.some(e=>e.id===t);return{...t,worksheets:n,activeWorksheetId:r(t.activeWorksheetId)?t.activeWorksheetId:r(e.activeWorksheetId)?e.activeWorksheetId:e.worksheets[0].id,xRanges:Object.fromEntries(Object.entries(t.xRanges).filter(([e])=>r(e))),mathChannels:[...t.mathChannels.filter(e=>e.source!==`workbook`),...e.channels],liveWindowSeconds:e.liveWindowSeconds}})}finally{w=!1}O=D(d()),C.rebase(k()),A()},Be={undo(){l(),ze(C.undo())},redo(){l(),ze(C.redo())},clear(){l(),M()}},Ve={hasWork:()=>SV(d().worksheets),exportWorksheet(e){l(),De();let t=F(e),n=fV(t);return{json:n,blob:je(n),filename:`${Ae(t.name||`worksheet`)}.kymosh`}},exportChart(e){l(),De();let{ws:t,panel:n}=I(e),r=pV(n,t.panelChartSettings[e],t.panelChartBackgrounds[e]??null);return{json:r,blob:je(r),filename:`${Ae(n.title?.trim()||n.kind)}.json`}},parseFile:e=>TV(e),exportWorkspace(){l(),De();let e=Le();return{json:e,blob:je(e),filename:`kymoscope-workspace-${new Date().toISOString().slice(0,10)}.json`}},async exportWorkspaceEncrypted(e){l(),De();let t=typeof e==`string`?await tV(Le(),e):await nV(Le(),e);return{json:t,blob:je(t),filename:`kymoscope-workbook-${new Date().toISOString().slice(0,10)}.kymo`}},async importWorkspace(e,t={}){l(),De();let n=await Oe(e);return rV(n)&&(n=await oV(n,t)),N(()=>Re(xV(n)))},toWorkbook:Le,openWorkbook(e){return l(),N(()=>Re(xV(e)))},async importWorksheet(e){l(),De();let t=d();t.limits.maxWorksheets!==null&&t.worksheets.length>=t.limits.maxWorksheets&&u(`worksheets`);let n=await TV(await ke(e));if(n.type!==`worksheet`)throw new ME(`bad_file`,{found:n.type});let[r]=Ne([Me(n.worksheet)],Pe());return i.set(e=>({...e,worksheets:[...e.worksheets,r],activeWorksheetId:r.id})),r.id},async importChart(e,t){l(),De();let n=await TV(await ke(e));if(n.type!==`chart`)throw new ME(`bad_file`,{found:n.type});return Ie(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(Me):[k1()];N(()=>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(),N(()=>{se(d().datasets.map(e=>e.id));let e=k1();i.set(t=>({...t,worksheets:[e],activeWorksheetId:e.id,xRanges:{},offsets:{},colors:{},mathChannels:t.mathChannels.filter(e=>e.source!==`workbook`)}))})}},He={merged(e){let t=h();if(!t.merged||t.channels.length===0)return t.merged;let n=SE(t.merged,t.channels,F(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 h().merged}},Ue=typeof location<`u`?location.hostname:``,We=t.license,Ge=t.licenseKey,Ke=!1,qe={},Je=e=>{n||i.set(t=>({...t,licensed:e}))},Ye=(e,t,n)=>{clearTimeout(qe[e]);let r=Math.max(0,t-Date.now()),i=r>2**31-1;qe[e]=setTimeout(()=>{i?Ye(e,t,n):n()},i?2**31-1:r)},Xe=e=>Ye(`renew`,e,()=>void Qe()),Ze=e=>Ye(`expiry`,e*1e3+1e3,()=>{RV(Ge,Ue).then(e=>{n||Je(e.ok)})});async function Qe(){let e=36e5,t,r=null,i;try{t=await Promise.race([We.get(),new Promise((e,t)=>{i=setTimeout(()=>t(Error(`timeout`)),3e4)})]),r=await RV(t,Ue)}catch{}finally{clearTimeout(i)}if(n)return!1;if(r?.ok)return Ge=t,Ke=!0,Je(!0),Ze(r.exp),Xe(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 RV(Ge,Ue);return n?!1:(Je(a.ok),Xe(Date.now()+e),a.ok)}let et=!We||t.licenseKey?RV(t.licenseKey,Ue).then(e=>(e.ok||console.warn(`[kymoscope] license ${e.reason}: showing attribution`),!Ke&&!n&&(Je(e.ok),e.ok&&We&&Ze(e.exp)),e.ok)):null,tt=We?Qe():et;w=!1,M();let nt={getState:P,subscribe(e){return i.subscribe(e)},on:a.on,licensed:tt,isLicensed:()=>d().licensed,setOptions(e){if(l(),t={...t,...e},e.live&&ee.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:fe,folders:he,worksheets:ge,charts:_e,view:ye,mathChannels:xe,cycles:be,live:Ee,video:Te,io:Ve,history:Be,data:He,alerts:{setRules:e=>{l();let t=le.setRules(e);return i.set(e=>({...e,alertRules:le.rules()})),t},rules:le.rules,state:le.state,evaluate:(e,t)=>(l(),le.evaluate(e,t)),clearMarks:le.clearMarks},marks:{list:()=>d().marks},dispose(){if(!n){n=!0,clearTimeout(qe.renew),clearTimeout(qe.expiry),s(),VQ(nt),vQ(nt),ee.dispose();for(let e of d().datasets)e.source.dispose().catch(()=>void 0);a.emit(`dispose`,void 0),a.clear()}}};return R1.set(nt,{store:i,derived:h,live:ee,alertLines:()=>ue(d().alertRules,d().alerts)}),nt}var R1=new WeakMap;function z1(e){let t=R1.get(e);if(!t)throw new ME(`invalid_argument`,{reason:`not a Kymoscope engine`});return t}var B1=2e3,V1=3;function H1(e){let t=e[0].v.fragCount,n=new Map;for(let r of e)r.v.fragCount===t&&!n.has(r.v.fragIndex)&&n.set(r.v.fragIndex,r);let r=[];for(let e=0;e<t;e++){let t=n.get(e);if(!t)return null;r.push(t.v.payload)}let i=n.get(0),a=r[0];if(t>1){a=new Uint8Array(r.reduce((e,t)=>e+t.length,0));for(let e=0,n=0;e<t;e++)a.set(r[e],n),n+=r[e].length}return{t:i.v.t,seq:i.v.seq,key:i.v.key,data:a,arrivedAt:i.at}}function U1(e){let t=[],n=0;for(;n<e.length&&e[n].v.fragIndex>0&&e[n].v.seq===e[0].v.seq;)t.push(e[n++]);let r=[],i=[],a=[];for(;n<=e.length;n++){let t=e[n];if(a.length&&(!t||t.v.seq!==a[0].v.seq)){let e=H1(a);e?r.push(e):t||(i=a),a=[]}t&&a.push(t)}return{head:t,units:r,tail:i}}var W1=class{kind=`recorded`;id;name;parentId;parentName;recordingId;chunks;fetch;open;maxBytes;cache=new Map;sizes=new Map;bytes=0;width=0;height=0;codec=``;waiting=null;constructor(e){this.id=e.id,this.name=e.name,this.parentId=e.parentId,this.parentName=e.parentName??null,this.recordingId=e.recordingId,this.chunks=[...e.chunks].sort((e,t)=>e.seq-t.seq),this.fetch=e.fetchChunk,this.open=e.open,this.maxBytes=e.maxBytes??256*1024*1024}async parse(e){let t=new Uint8Array(await this.fetch(this.chunks[e].seq)),n=[];for(let e of Me(t).messages){let t=null;try{t=await he(this.open,e.bytes.slice().buffer)}catch{}if(t?.kind!==6)continue;let r=E$(t.plaintext);r&&(r.key&&r.fragIndex===0&&!this.codec&&(this.codec=r.codec,this.width=r.width,this.height=r.height),n.push({v:r,at:e.at}))}let r=U1(n),i=e=>e.reduce((e,t)=>e+t.v.payload.length,0);return{...r,bytes:r.units.reduce((e,t)=>e+t.data.length,0)+i(r.head)+i(r.tail)}}parsed(e){let t=this.cache.get(e);if(t)return this.cache.delete(e),this.cache.set(e,t),t;let n=this.parse(e);return this.cache.set(e,n),n.then(t=>{this.cache.get(e)===n&&(this.sizes.set(e,[t.bytes,t.units.length]),this.bytes+=t.bytes,this.evict(e))},()=>{this.cache.get(e)===n&&this.cache.delete(e)}),n}evict(e){for(let t of this.cache.keys()){if(this.bytes<=this.maxBytes)return;let n=this.sizes.get(t);t===e||!n||(this.bytes-=n[0],this.sizes.delete(t),this.cache.delete(t))}}async units(e){let t;try{t=await this.parsed(e)}catch{return[]}if(t.full)return t.full;if(!t.tail.length||e+1>=this.chunks.length)return t.full=t.units;let n=await this.parsed(e+1).catch(()=>null);if(!n)return t.units;let r=null;try{r=H1([...t.tail,...n.head.filter(e=>e.v.seq===t.tail[0].v.seq)])}catch{}return t.full=r?[...t.units,r]:t.units}async seekPlan(e){let t=this.chunks.length;if(!t)return[];let n=e*1e3,r=0;for(;r+1<t&&this.chunks[r+1].t0<=n;)r++;let i=r,a=r+1<t&&this.chunks[r+1].t0-n<B1?r+1:r,o=(await Promise.all(Array.from({length:a-i+1},(e,t)=>this.units(i+t)))).flat(),s=()=>{let t=o.length-1;for(;t>=0&&o[t].t>e;)t--;let n=t;for(;n>=0&&!o[n].key;)n--;return[n,t]},[c,l]=s();for(let e=0;c<0&&i>0&&e<V1;e++)o=[...await this.units(--i),...o],[c,l]=s();return a+1<t&&this.units(a+1),c<0?[]:o.slice(c,l+1)}ready(){return this.waiting??=(async()=>{for(let e=0;e<Math.min(this.chunks.length,V1+1)&&!this.codec;e++)await this.units(e);this.codec||(this.waiting=null)})()}info(){let e=0;for(let[,t]of this.sizes.values())e+=t;return{width:this.width,height:this.height,codec:this.codec,latestT:this.range()?.[1]??null,lagMs:null,units:e,bytes:this.bytes}}range(){let e=this.chunks.length;return e?[this.chunks[0].t0/1e3,this.chunks[e-1].t1/1e3]:null}},G1=[60,300,900,1800,3600,7200,14400,28800,43200,86400],K1={60:`1m`,300:`5m`,900:`15m`,1800:`30m`,3600:`1h`,7200:`2h`,14400:`4h`,28800:`8h`,43200:`12h`,86400:`24h`};function q1(e){if(typeof e==`number`)return G1.includes(e)?e:null;if(typeof e!=`string`)return null;let t=Object.entries(K1).find(([,t])=>t===e.trim().toLowerCase());return t?Number(t[0]):null}var J1=e=>K1[e]??`${e}s`;function Y1(e){for(let t=G1.length-1;t>=0;t--)if(G1[t]*e<=157286400)return G1[t];return G1[0]}function X1(e,t,n){let r=t*1e3,i=n*1e3;return Math.floor((e+i)/r)*r+r-i}var Z1=1e4,Q1=72e4,$1=3e5,e0=3e4,t0=1e4,n0=1e4,r0=64*1024,i0=50,a0=[`360p`,`480p`,`720p`,`1080p`],o0=e=>e+6+(e>=126?2:0)+(e>65535?6:0);function s0(e,t){return t*o0(e+30)}var c0=e=>typeof e==`number`&&Number.isFinite(e)&&e>0,l0=e=>Number.isInteger(e)&&e>=1;function u0(e,t){if(!e||e.mode!==`live`&&e.mode!==`record`)return null;if(t===`camera`)return a0.includes(e.quality)&&Number.isInteger(e.fps)&&e.fps>=1&&e.fps<=60?{mode:e.mode,quality:e.quality,fps:e.fps}:null;if(!c0(e.bytes_per_sec))return null;let n=e.bytes_per_sec,r={};if(e.mode===`record`){let t=e.splitEvery===void 0?Y1(n):q1(e.splitEvery);if(t===null)return null;r={split_every:t}}return e.sources===void 0?c0(e.hz)&&l0(e.channels)?{mode:e.mode,hz:e.hz,channels:e.channels,bytes_per_sec:n,...r}:null:Array.isArray(e.sources)&&e.sources.length>0&&e.sources.every(e=>c0(e?.hz)&&l0(e?.channels))?{mode:e.mode,sources:e.sources.map(({hz:e,channels:t})=>Object.freeze({hz:e,channels:t})),bytes_per_sec:n,...r}:null}var d0=class extends Error{status;code;detail;constructor(e,t,n){super(`${n} (${t})`),this.status=e,this.code=t,this.detail=n}};async function f0(e,t,n,r,i){let a;try{a=await e(`${t.replace(/\/+$/,``)}/functions/v1/${n}`,{method:`POST`,headers:r,body:i===void 0?void 0:JSON.stringify(i)})}catch(e){throw new d0(0,`network`,e?.message??String(e))}let o=await a.text(),s=null;try{s=JSON.parse(o)}catch{}if(a.status!==200)throw new d0(a.status,s?.error??`error`,s?.message??s?.error??o);return s}async function p0(e,t,n=fetch){let{auth:r}=Ee(t),{token:i}=await f0(n,e,`stream-token`,{"x-api-key":r}),a=await f0(n,e,`stream-publisher`,{Authorization:`Bearer ${i}`,"Content-Type":`application/json`},{action:`usage`});return{limits:a.limits??{},usage:a.usage}}var m0=e=>Uint8Array.from(atob(e),e=>e.charCodeAt(0)),h0=class{opts;deps;auth;secret;password;token=``;ticket=``;relayUrl=null;apiKeyId=null;projectId=null;e2ee=!1;sid=null;salt=``;key=null;raw=null;gen=0;epoch=0;haveKey=!1;sealed=null;device=null;senderDeviceId=null;deviceRetried=!1;maxBytesPerSec=0;maxMessageBytes=r0;ws=null;open=!1;everOpen=!1;connectedAt=0;authAt=0;delay=1e3;lastToken=0;viewerCount=0;busy=!1;stopped=!1;refusal=null;heartbeatTimer=null;pingTimer=null;retryTimer=null;statusFns=new Set;viewerFns=new Set;lastStatus=``;wire;usage=null;bitrate=null;noticeCode=null;constructor(e,t){let{auth:n,secret:r}=Ee(e.apiKey);if(!r)throw Error(`This API key has no encryption secret (created before keys carried one). Create a new API key in Kymoscope.`);if(e.kind===`camera`&&!e.parentStreamId)throw Error(`A camera is added to one of your live streams: choose its stream (parentStreamId).`);if(!!e.layer!=!!e.lowOf)throw Error(`A low layer needs both layer: 'low' and lowOf (its high camera's stream id).`);if(e.layer&&e.kind!==`camera`)throw Error(`Only a camera has a low layer.`);let i=u0(e.profile,e.kind);if(!i)throw Error(`profile is required: mode plus hz/channels (or sources) and bytes_per_sec, or quality/fps for a camera`);if(this.wire=Object.freeze(e.kind===`data`?{...i,sender:`browser`}:i),e.visibility===`open`&&e.password)throw Error(`An open stream has no password: anyone may watch it. Remove the password, or use visibility 'private'.`);this.opts=e,this.deps=t,this.auth=n,this.secret=r,this.password=e.visibility===`open`?C:e.password||r}get streamId(){return this.sid}get viewers(){return this.viewerCount}get limits(){return{maxBytesPerSec:this.maxBytesPerSec,maxMessageBytes:this.maxMessageBytes}}get usageMessage(){return this.usage}get bitrateKbps(){return this.bitrate}get profile(){return this.wire}onStatus(e){return this.statusFns.add(e),()=>{this.statusFns.delete(e)}}onViewers(e){return this.viewerFns.add(e),()=>{this.viewerFns.delete(e)}}async start(){this.emit();try{let t=await this.deps.store.load();this.salt=t?.salt??h();let n=await this.mint();this.token=n.token,this.relayUrl=n.relayUrl??null,this.maxBytesPerSec=n.maxBytesPerSec||0,this.maxMessageBytes=n.maxMessageBytes||r0,this.apiKeyId=n.apiKeyId??null;let r=n.project;this.e2ee=!!r?.e2ee;let a={};if(this.e2ee){this.projectId=r?.id??null;let n=t?.apiKeyId===this.apiKeyId;this.device=n&&t?.device||await i(),n&&t?.streamKey?{key:this.key,epoch:this.epoch,sealed:this.sealed}=t.streamKey:this.key=await p(e()),a.sender_device=await this.senderDevice()}else this.raw=m0(await S(this.password,this.salt)),this.key=await p(this.raw),this.gen=t?.keyGen??0;let o=await this.register(t?.streamId??null,a);if(this.sid=o.stream.id,this.ticket=o.ticket,this.admitted(o),this.e2ee?(this.senderDeviceId=o.sender_device_id??null,this.projectId=o.project?.id??this.projectId,await this.save(),await this.applyProject(o.project)):(await this.save(),await this.wrapFor(o.devices)),!this.relayUrl)throw Error(`stream-token returned no relayUrl`)}catch(e){throw e instanceof d0&&e.status>=400&&e.status<500&&this.refuse(e),e}this.stopped||(this.lastToken=this.deps.now(),this.connect(),this.heartbeatTimer=setInterval(()=>{this.housekeeping()},Z1),this.emit())}async send(e,t){if(this.stopped||!this.open)return!1;let n=await this.seal(e,t);return!!n&&this.sendSealed(n)}async seal(e,t){let n=this.key,r=this.e2ee?this.epoch&255:this.gen||void 0;return this.stopped||!n||this.e2ee&&!this.haveKey?null:new Uint8Array(await re(n,e,t,r))}sendSealed(e){let t=this.ws;if(!this.open||!t)return!1;try{return t.send(e),!0}catch{return!1}}recordingUpload(e){return this.post(`recording-upload`,{Authorization:`Bearer ${this.token}`,"Content-Type":`application/json`},e)}stop(){!this.stopped&&this.sid&&this.call({action:`offline`,stream_id:this.sid}).catch(()=>{}),this.stopped=!0,this.heartbeatTimer&&clearInterval(this.heartbeatTimer),this.retryTimer&&clearTimeout(this.retryTimer),this.heartbeatTimer=this.retryTimer=null;let e=this.ws;if(this.disconnect(),e){e.onopen=e.onmessage=e.onclose=null;try{e.close(1e3)}catch{}}}post(e,t,n){return f0(this.deps.fetch,this.opts.supabaseUrl,e,t,n)}mint(){return this.post(`stream-token`,{"x-api-key":this.auth})}call(e){return this.post(`stream-publisher`,{Authorization:`Bearer ${this.token}`,"Content-Type":`application/json`},e)}async register(e,t,n=this.salt,r=this.key){let i={action:`register`,name:this.opts.name,salt:n,key_check:await b(r),visibility:this.opts.visibility??`private`,kind:this.opts.kind,profile:this.wire,...t};return this.opts.kind===`camera`&&(i.parent_stream_id=this.opts.parentStreamId),this.opts.layer&&(i.layer=this.opts.layer,i.low_of=this.opts.lowOf),e&&(i.stream_id=e),this.call(i)}admitted(e){this.usage=typeof e.usage?.message==`string`?e.usage.message:null,this.bitrate=typeof e.bitrate_kbps==`number`?e.bitrate_kbps:null}notice(e){let t=e?.notice,n=typeof t?.code==`string`?t.code:null;if(n&&n!==this.noticeCode)try{this.opts.onNotice?.({code:n,message:String(t.message??n)})}catch{}this.noticeCode=n}async senderDevice(){let e=this.device.publicKey;return{public_key:e,binding:await ce(await He(this.secret),this.apiKeyId??``,e)}}async housekeeping(){if(!(this.busy||this.stopped)){this.busy=!0;try{let e=this.deps.now();if(e-this.lastToken>=Q1){this.lastToken=e;try{this.token=(await this.mint()).token}catch{return}}if(this.e2ee){let e=await this.call({action:`heartbeat`,stream_id:this.sid,sender_device_id:this.senderDeviceId,epoch:this.haveKey?this.epoch:0});this.setTicket(e.ticket),this.notice(e),await this.applyProject(e.project)}else{let e=await this.call({action:`heartbeat`,stream_id:this.sid});this.setTicket(e.ticket),this.notice(e),await this.wrapFor(e.devices),e.rekey===!0&&await this.rekey()}}catch(e){e instanceof d0&&(e.status===401||e.status===403)&&this.refuse(e)}finally{this.busy=!1}}}async rekey(){let e=h(),t=m0(await S(this.password,e)),n=await p(t),r;try{r=await this.register(this.sid,{},e,n)}catch{return}this.salt=e,this.key=n,this.raw=t,this.gen=this.gen%255+1,await this.save(),await this.wrapFor(r.devices)}async wrapFor(e){let t=[];for(let n of e??[])try{t.push({device_id:n.id,wrapped:await ie(n.public_key,this.raw,`${this.sid}|${n.id}`)})}catch{}if(t.length)try{await this.call({action:`wrap_keys`,stream_id:this.sid,keys:t.slice(0,i0)})}catch{}}async applyProject(t){if(!this.e2ee||!t)return;let n=t.key;if(!n){this.emit();return}let r=Number(n.epoch);if(this.haveKey&&r<=this.epoch)return;let a;try{a=await ue(this.device.privateKey,n.wrapped,k(this.projectId,r,this.senderDeviceId))}catch{if(this.deviceRetried)return;this.deviceRetried=!0,this.device=await i(),await this.reregister();return}let o=Ke(this.sid,this.projectId,r),s=this.key,c=r===this.epoch?this.sealed:null;if(c)try{await Ie(a,c,o)}catch{c=null}if(!c){let t=e();s=await p(t),c=await be(a,t,o),t.fill(0)}try{await this.call({action:`wrap_keys`,stream_id:this.sid,sender_device_id:this.senderDeviceId,project_wrap:{epoch:r,iv:c.iv,ct:c.ct}})}catch{return}this.stopped||(this.key=s,this.sealed=c,this.epoch=r,this.haveKey=!0,await this.save(),this.emit())}async reregister(){let e;try{e=await this.register(this.sid,{sender_device:await this.senderDevice()})}catch{return}this.ticket=e.ticket,this.admitted(e),this.senderDeviceId=e.sender_device_id??null;let t=e.stream.id;if(t!==this.sid){this.sid=t;let e=this.ws;if(e){this.disconnect(),e.onopen=e.onmessage=e.onclose=null;try{e.close(1e3)}catch{}this.connect()}}await this.save(),await this.applyProject(e.project),this.deviceRetried=!1}async save(){try{await this.deps.store.save({apiKeyId:this.apiKeyId,streamId:this.sid,salt:this.salt,device:this.e2ee?this.device:null,streamKey:this.e2ee&&this.haveKey?{epoch:this.epoch,key:this.key,sealed:this.sealed}:null,...this.gen?{keyGen:this.gen}:{}})}catch{}}connect(){if(this.retryTimer=null,this.stopped)return;let e=this.relayUrl.replace(/\/+$/,``).replace(/^http(s?):\/\//,`ws$1://`),t;try{t=new this.deps.WebSocket(`${e}/v1/streams/${this.sid}/publish`,[u$,`bearer.${this.ticket}`])}catch{this.dropped();return}t.binaryType=`arraybuffer`,this.ws=t,t.onopen=()=>{t===this.ws&&(this.open=this.everOpen=!0,this.connectedAt=this.authAt=this.deps.now(),this.pingTimer=setInterval(()=>{try{t.send(`ping`)}catch{}},e0),this.emit())},t.onmessage=e=>{if(!(t!==this.ws||typeof e.data!=`string`||!e.data.startsWith(`{`)))try{let t=JSON.parse(e.data);t?.type===`viewers`&&this.setViewers(Number(t.count)||0)}catch{}},t.onclose=()=>{t===this.ws&&this.dropped()}}disconnect(){this.ws=null,this.open=!1,this.pingTimer&&clearInterval(this.pingTimer),this.pingTimer=null,this.setViewers(0)}dropped(){let e=this.open&&this.deps.now()-this.connectedAt>=n0;if(this.disconnect(),this.stopped)return;let t=0;e?this.delay=1e3:(t=this.delay,this.delay=Math.min(this.delay*2,t0)),this.retryTimer=setTimeout(()=>this.connect(),t),this.emit()}setTicket(e){this.ticket=e;let t=this.deps.now();if(!(!this.open||!this.ws||t-this.authAt<$1))try{this.ws.send(JSON.stringify({type:`auth`,token:e})),this.authAt=t}catch{}}setViewers(e){if(e!==this.viewerCount){this.viewerCount=e;for(let t of this.viewerFns)t(e);this.emit()}}refuse(e){this.refusal={code:e.code,message:e.detail},this.emit(),this.stop()}status(){return this.refusal?{phase:`refused`,...this.refusal}:this.sid?this.e2ee&&!this.haveKey?{phase:`waiting_approval`}:this.open?{phase:`live`,viewers:this.viewerCount}:this.everOpen?{phase:`reconnecting`}:{phase:`registering`}:{phase:`registering`}}emit(){let e=this.status(),t=JSON.stringify(e);if(t!==this.lastStatus){this.lastStatus=t;for(let t of this.statusFns)t(e)}}},g0={"360p":{width:640,height:360},"480p":{width:854,height:480},"720p":{width:1280,height:720},"1080p":{width:1920,height:1080}},_0={width:640,height:360,fps:15,kbps:400},v0=[`avc1.640028`,`avc1.4d0028`,`avc1.42e028`],y0=[`avc1.64001f`,`avc1.4d001f`,`avc1.42e01f`],b0=2,x0=1e3,S0=1e3;async function*C0(e){if(typeof MediaStreamTrackProcessor<`u`){let t=new MediaStreamTrackProcessor({track:e}).readable.getReader();try{for(;;){let{value:e,done:n}=await t.read();if(n)return;yield e}}finally{t.cancel().catch(()=>{})}}let t=document.createElement(`video`);t.muted=!0,t.playsInline=!0,t.srcObject=new MediaStream([e]),await t.play();try{for(;e.readyState===`live`;)await new Promise(e=>t.requestVideoFrameCallback(()=>e())),yield new VideoFrame(t,{timestamp:Math.round(performance.now()*1e3)})}finally{t.pause(),t.srcObject=null}}function w0(){let e=null;return(t,n,r)=>(e??=new OffscreenCanvas(n,r).getContext(`2d`),e.drawImage(t,0,0,n,r),new VideoFrame(e.canvas,{timestamp:t.timestamp}))}var T0=class{encoder=null;codec=``;error=null;unsubscribe=null;lastKey=-1/0;keyPending=!1;resume=!0;lastViewers=0;encoding=!1;dropped=0;seq=0;times=new Map;window=[];sending=Promise.resolve();publisher;preset;keyframeMs;Encoder;now;recorder;constructor(e,t,n,r,i,a=null){if(a&&!(e.seal&&e.sendSealed))throw Error(`A recording camera needs a LivePublisher (seal, sendSealed).`);this.recorder=a,this.publisher=e,this.preset=t,this.keyframeMs=n,this.Encoder=r,this.now=i}async configure(e){let{width:t,height:n,fps:r}=this.preset,i=e*1e3,a=null;for(let e of n>720?v0:y0){let o={codec:e,width:t,height:n,bitrate:i,framerate:r,avc:{format:`annexb`},latencyMode:`realtime`,bitrateMode:`constant`};if((await this.Encoder.isConfigSupported(o)).supported===!0){a=o;break}}return a?(this.codec=a.codec,this.encoder=new this.Encoder({output:e=>this.onChunk(e),error:e=>{this.error=e.message||String(e),this.closeEncoder()}}),this.encoder.configure(a),this.lastViewers=this.publisher.viewers,this.unsubscribe=this.publisher.onViewers(e=>{e>this.lastViewers&&(this.keyPending=!0),this.lastViewers=e}),!0):!1}ready(){let e=this.encoder;return this.encoding=!!e&&!this.error&&(this.publisher.viewers>0||!!this.recorder?.wants()),!e||!this.encoding?(this.resume=!0,!1):e.encodeQueueSize>b0?(this.dropped++,!1):!0}encode(e){let t=this.now(),n=t-this.lastKey,r=this.resume||n>=this.keyframeMs||this.keyPending&&n>=x0;r&&(this.lastKey=t,this.keyPending=this.resume=!1);let i=(performance.timeOrigin+e.timestamp/1e3)/1e3;Math.abs(i-Date.now()/1e3)>60&&(i=Date.now()/1e3),this.times.set(e.timestamp,i),this.encoder.encode(e,{keyFrame:r})}onChunk(e){let t=new Uint8Array(e.byteLength);e.copyTo(t);let n=this.times.get(e.timestamp)??Date.now()/1e3;this.times.delete(e.timestamp);let{width:r,height:i}=this.preset,a=e.type===`key`,o=D$({key:a,t:n,seq:this.seq++,width:r,height:i,codec:this.codec,data:t}),s=this.recorder,c=this.publisher;o.forEach((e,t)=>{this.sending=this.sending.then(async()=>{if(!s)return c.send(6,e);let r=await c.seal(6,e);return r?(s.add(r,n*1e3,a&&t===0),c.viewers>0&&c.sendSealed(r)):!1}).catch(()=>!1)}),this.window.push({at:this.now(),bytes:t.length})}get queue(){return this.encoder?.state===`configured`?this.encoder.encodeQueueSize:0}stats(){let e=this.now();for(;this.window.length&&e-this.window[0].at>=S0;)this.window.shift();let t=this.window.reduce((e,t)=>e+t.bytes,0);return{fps:this.window.length,kbps:t*8/1e3,viewers:this.publisher.viewers,encoding:this.encoding}}stop(){this.encoding=!1,this.closeEncoder(),this.unsubscribe?.(),this.unsubscribe=null}closeEncoder(){this.encoder&&this.encoder.state!==`closed`&&this.encoder.close()}},E0=class{high;lowOpt;low=null;lowAt=-1/0;keyframeMs;Encoder;now;frames;scale;stopped=!1;statsFns=new Set;lastStats=-1/0;constructor(e,t={},n={}){let{quality:r,fps:i}=e.profile,a=r?g0[r]:void 0;if(!a||!i)throw Error(`A CameraSender needs a camera publisher (profile quality and fps).`);this.keyframeMs=(t.keyframeS??2)*1e3,this.Encoder=n.VideoEncoder??VideoEncoder,this.now=n.now??Date.now,this.frames=n.frames??C0,this.scale=n.scale??w0(),this.high=new T0(e,{...a,fps:i},this.keyframeMs,this.Encoder,this.now,t.recorder??null),this.lowOpt=t.low?{publisher:t.low.publisher,preset:t.low.preset??_0}:null}async start(e){let t=this.high.publisher.bitrateKbps;if(t==null)throw Error(`The camera has no bitrate: start its LivePublisher first (register answers it).`);if(!await this.high.configure(t))throw new ME(`camera_codec_unsupported`);if(this.lowOpt){let e=new T0(this.lowOpt.publisher,this.lowOpt.preset,this.keyframeMs,this.Encoder,this.now);await e.configure(this.lowOpt.publisher.bitrateKbps??this.lowOpt.preset.kbps)&&(this.low=e)}this.loop(e)}async loop(e){for await(let t of this.frames(e)){if(this.stopped){t.close();break}try{this.onFrame(t)}finally{t.close()}this.emitStats()}}onFrame(e){this.high.ready()&&this.high.encode(e);let t=this.low;if(!t)return;let n=this.now();if(n-this.lowAt<750/t.preset.fps||!t.ready())return;this.lowAt=n;let r=this.scale(e,t.preset.width,t.preset.height);try{t.encode(r)}finally{r.close()}}stats(){return{...this.high.stats(),dropped:this.high.dropped,queue:this.high.queue,error:this.high.error,low:this.low?this.low.stats():null}}onStats(e){return this.statsFns.add(e),()=>{this.statsFns.delete(e)}}emitStats(){let e=this.now();if(e-this.lastStats<S0||!this.statsFns.size)return;this.lastStats=e;let t=this.stats();for(let e of this.statsFns)e(t)}stop(){this.stopped=!0,this.high.stop(),this.low?.stop()}},D0=new TextEncoder,O0={appstream2:`appstream`,cloudhsmv2:`cloudhsm`,email:`ses`,marketplace:`aws-marketplace`,mobile:`AWSMobileHubService`,pinpoint:`mobiletargeting`,queue:`sqs`,"git-codecommit":`codecommit`,"mturk-requester-sandbox":`mturk-requester`,"personalize-runtime":`personalize`},k0=new Set([`authorization`,`content-type`,`content-length`,`user-agent`,`presigned-expires`,`expect`,`x-amzn-trace-id`,`range`,`connection`]),A0=class{constructor({accessKeyId:e,secretAccessKey:t,sessionToken:n,service:r,region:i,cache:a,retries:o,initRetryMs:s}){if(e==null)throw TypeError(`accessKeyId is a required option`);if(t==null)throw TypeError(`secretAccessKey is a required option`);this.accessKeyId=e,this.secretAccessKey=t,this.sessionToken=n,this.service=r,this.region=i,this.cache=a||new Map,this.retries=o??10,this.initRetryMs=s||50}async sign(e,t){if(e instanceof Request){let{method:n,url:r,headers:i,body:a}=e;t=Object.assign({method:n,url:r,headers:i},t),t.body==null&&i.has(`Content-Type`)&&(t.body=a!=null&&i.has(`X-Amz-Content-Sha256`)?a:await e.clone().arrayBuffer()),e=r}let n=new j0(Object.assign({url:e.toString()},t,this,t&&t.aws)),r=Object.assign({},t,await n.sign());delete r.aws;try{return new Request(r.url.toString(),r)}catch(e){if(e instanceof TypeError)return new Request(r.url.toString(),Object.assign({duplex:`half`},r));throw e}}async fetch(e,t){for(let n=0;n<=this.retries;n++){let r=fetch(await this.sign(e,t));if(n===this.retries)return r;let i=await r;if(i.status<500&&i.status!==429)return i;await new Promise(e=>setTimeout(e,Math.random()*this.initRetryMs*2**n))}throw Error(`An unknown error occurred, ensure retries is not negative`)}},j0=class{constructor({method:e,url:t,headers:n,body:r,accessKeyId:i,secretAccessKey:a,sessionToken:o,service:s,region:c,cache:l,datetime:u,signQuery:d,appendSessionToken:f,allHeaders:p,singleEncode:m}){if(t==null)throw TypeError(`url is a required option`);if(i==null)throw TypeError(`accessKeyId is a required option`);if(a==null)throw TypeError(`secretAccessKey is a required option`);this.method=e||(r?`POST`:`GET`),this.url=new URL(t),this.headers=new Headers(n||{}),this.body=r,this.accessKeyId=i,this.secretAccessKey=a,this.sessionToken=o;let h,g;(!s||!c)&&([h,g]=L0(this.url,this.headers)),this.service=s||h||``,this.region=c||g||`us-east-1`,this.cache=l||new Map,this.datetime=u||new Date().toISOString().replace(/[:-]|\.\d{3}/g,``),this.signQuery=d,this.appendSessionToken=f||this.service===`iotdevicegateway`,this.headers.delete(`Host`),this.service===`s3`&&!this.signQuery&&!this.headers.has(`X-Amz-Content-Sha256`)&&this.headers.set(`X-Amz-Content-Sha256`,`UNSIGNED-PAYLOAD`);let _=this.signQuery?this.url.searchParams:this.headers;if(_.set(`X-Amz-Date`,this.datetime),this.sessionToken&&!this.appendSessionToken&&_.set(`X-Amz-Security-Token`,this.sessionToken),this.signableHeaders=[`host`,...this.headers.keys()].filter(e=>p||!k0.has(e)).sort(),this.signedHeaders=this.signableHeaders.join(`;`),this.canonicalHeaders=this.signableHeaders.map(e=>e+`:`+(e===`host`?this.url.host:(this.headers.get(e)||``).replace(/\s+/g,` `))).join(`
|
|
618
|
+
`),this.credentialString=[this.datetime.slice(0,8),this.region,this.service,`aws4_request`].join(`/`),this.signQuery&&(this.service===`s3`&&!_.has(`X-Amz-Expires`)&&_.set(`X-Amz-Expires`,`86400`),_.set(`X-Amz-Algorithm`,`AWS4-HMAC-SHA256`),_.set(`X-Amz-Credential`,this.accessKeyId+`/`+this.credentialString),_.set(`X-Amz-SignedHeaders`,this.signedHeaders)),this.service===`s3`)try{this.encodedPath=decodeURIComponent(this.url.pathname.replace(/\+/g,` `))}catch{this.encodedPath=this.url.pathname}else this.encodedPath=this.url.pathname.replace(/\/+/g,`/`);m||(this.encodedPath=encodeURIComponent(this.encodedPath).replace(/%2F/g,`/`)),this.encodedPath=I0(this.encodedPath);let v=new Set;this.encodedSearch=[...this.url.searchParams].filter(([e])=>{if(!e)return!1;if(this.service===`s3`){if(v.has(e))return!1;v.add(e)}return!0}).map(e=>e.map(e=>I0(encodeURIComponent(e)))).sort(([e,t],[n,r])=>e<n?-1:e>n?1:t<r?-1:+(t>r)).map(e=>e.join(`=`)).join(`&`)}async sign(){return this.signQuery?(this.url.searchParams.set(`X-Amz-Signature`,await this.signature()),this.sessionToken&&this.appendSessionToken&&this.url.searchParams.set(`X-Amz-Security-Token`,this.sessionToken)):this.headers.set(`Authorization`,await this.authHeader()),{method:this.method,url:this.url,headers:this.headers,body:this.body}}async authHeader(){return[`AWS4-HMAC-SHA256 Credential=`+this.accessKeyId+`/`+this.credentialString,`SignedHeaders=`+this.signedHeaders,`Signature=`+await this.signature()].join(`, `)}async signature(){let e=this.datetime.slice(0,8),t=[this.secretAccessKey,e,this.region,this.service].join(),n=this.cache.get(t);return n||(n=await M0(await M0(await M0(await M0(`AWS4`+this.secretAccessKey,e),this.region),this.service),`aws4_request`),this.cache.set(t,n)),F0(await M0(n,await this.stringToSign()))}async stringToSign(){return[`AWS4-HMAC-SHA256`,this.datetime,this.credentialString,F0(await N0(await this.canonicalString()))].join(`
|
|
619
619
|
`)}async canonicalString(){return[this.method.toUpperCase(),this.encodedPath,this.encodedSearch,this.canonicalHeaders+`
|
|
620
620
|
`,this.signedHeaders,await this.hexBodyHash()].join(`
|
|
621
|
-
`)}async hexBodyHash(){let e=this.headers.get(`X-Amz-Content-Sha256`)||(this.service===`s3`&&this.signQuery?`UNSIGNED-PAYLOAD`:null);if(e==null){if(this.body&&typeof this.body!=`string`&&!(`byteLength`in this.body))throw Error(`body must be a string, ArrayBuffer or ArrayBufferView, unless you include the X-Amz-Content-Sha256 header`);e=d0(await l0(this.body||``))}return e}};async function c0(e,t){let n=await crypto.subtle.importKey(`raw`,typeof e==`string`?r0.encode(e):e,{name:`HMAC`,hash:{name:`SHA-256`}},!1,[`sign`]);return crypto.subtle.sign(`HMAC`,n,r0.encode(t))}async function l0(e){return crypto.subtle.digest(`SHA-256`,typeof e==`string`?r0.encode(e):e)}var u0=[`0`,`1`,`2`,`3`,`4`,`5`,`6`,`7`,`8`,`9`,`a`,`b`,`c`,`d`,`e`,`f`];function d0(e){let t=new Uint8Array(e),n=``;for(let e=0;e<t.length;e++){let r=t[e];n+=u0[r>>>4&15],n+=u0[r&15]}return n}function f0(e){return e.replace(/[!'()*]/g,e=>`%`+e.charCodeAt(0).toString(16).toUpperCase())}function p0(e,t){let{hostname:n,pathname:r}=e;if(n.endsWith(`.on.aws`)){let e=n.match(/^[^.]{1,63}\.lambda-url\.([^.]{1,63})\.on\.aws$/);return e==null?[``,``]:[`lambda`,e[1]||``]}if(n.endsWith(`.r2.cloudflarestorage.com`))return[`s3`,`auto`];if(n.endsWith(`.backblazeb2.com`)){let e=n.match(/^(?:[^.]{1,63}\.)?s3\.([^.]{1,63})\.backblazeb2\.com$/);return e==null?[``,``]:[`s3`,e[1]||``]}let i=n.replace(`dualstack.`,``).match(/([^.]{1,63})\.(?:([^.]{0,63})\.)?amazonaws\.com(?:\.cn)?$/),a=i&&i[1]||``,o=i&&i[2];if(o===`us-gov`)o=`us-gov-west-1`;else if(o===`s3`||o===`s3-accelerate`)o=`us-east-1`,a=`s3`;else if(a===`iot`)a=n.startsWith(`iot.`)?`execute-api`:n.startsWith(`data.jobs.iot.`)?`iot-jobs-data`:r===`/mqtt`?`iotdevicegateway`:`iotdata`;else if(a===`autoscaling`){let e=(t.get(`X-Amz-Target`)||``).split(`.`)[0];e===`AnyScaleFrontendService`?a=`application-autoscaling`:e===`AnyScaleScalingPlannerFrontendService`&&(a=`autoscaling-plans`)}else o==null&&a.startsWith(`s3-`)?(o=a.slice(3).replace(/^fips-|^external-1/,``),a=`s3`):a.endsWith(`-fips`)?a=a.slice(0,-5):o&&/-\d$/.test(a)&&!/-\d$/.test(o)&&([a,o]=[o,a]);return[i0[a]||a,o||``]}var m0=1e4,h0=2e3,g0=1e4,_0=6e4,v0=2e3,y0=6e4,b0=`rec`,x0=`meta.json`,S0=e=>Math.min(y0,Math.max(v0,e*2)),C0=e=>e>=1024?`${+(e/1024).toFixed(2)} GB`:`${e} MB`,w0=e=>e.replace(/(https?:\/\/[^\s?#'"]*)\?[^\s#'"]*/g,`$1`),T0=class extends Error{status;constructor(e,t){super(w0(e)),this.status=t}},E0=e=>e instanceof T0?void 0:e?.status,D0=e=>e?.code??String(E0(e)??`error`),O0=e=>`${String(e).padStart(8,`0`)}.krc`,k0=e=>Array.from(new Uint8Array(e),e=>e.toString(16).padStart(2,`0`)).join(``);async function A0(e,t,n){let r=await(await e.getFileHandle(t,{create:!0})).createWritable();await r.write(n),await r.close()}async function j0(e,t){try{return JSON.parse(await(await(await e.getFileHandle(t)).getFile()).text())}catch{return null}}function M0(e,t){return new Promise(n=>{e.request(t,{ifAvailable:!0},e=>{if(!e){n(null);return}return new Promise(e=>n(e))}).catch(()=>n(null))})}var N0=class{streamId;parentStreamId;bufferMaxMB;dropped=0;usedBytes=0;storage;opts;now;fetch;locks;rootDir=null;parent=void 0;polledAt=-1/0;polling=!1;cutAt=1/0;noneSince=null;file=null;chunk=null;continues=!1;prev=null;lost=new Set;io=Promise.resolve();writing=new Set;held=new Map;opened=new Map;blocked=new Set;wait=new Map;said=new Set;fullSaid=!1;refusedUntil=0;closing=!1;stopped=!1;wake=null;loop=null;constructor(e){this.opts=e,this.streamId=e.streamId,this.parentStreamId=e.parentStreamId,this.bufferMaxMB=e.bufferMaxMB??2048,this.storage=e.storage??null,this.now=e.now??Date.now,this.fetch=e.fetch??((...e)=>fetch(...e)),this.locks=e.locks===void 0?typeof navigator<`u`&&navigator.locks||null:e.locks,e.autostart!==!1&&(this.loop=this.run())}wants(){return!!this.file||!!this.parent}splitEvery=null;get currentId(){return this.file?.id??null}setStorage(e){this.storage=e,this.blocked.clear();for(let e of[...this.said])e.startsWith(`storage:`)&&this.said.delete(e);this.wake?.()}add(e,t,n){if(this.closing)return;this.pollDue()&&this.pollParent();let r=this.parent??null,i=this.file;if(i&&r===null&&this.noneSince!==null&&this.now()-this.noneSince>=3e4?this.endFile(!1,`stopped`):i&&r!==null&&n&&i.meta.parent!==r&&this.endFile(!0,`stopped`),!this.file){if(!r||!n||this.now()<this.refusedUntil)return;this.openFile(t,r)}let a=this.chunk;a&&(a.bytes+12+e.length>4194304||Math.abs(t-a.records[0].at)>=6e4)&&(this.flush(),a=null),a??=this.chunk={records:[],bytes:56,opened:this.now()},a.records.push({at:t,bytes:e}),a.bytes+=12+e.length}tick(){this.chunk&&this.now()-this.chunk.opened>=6e4&&this.flush()}stop(){this.file&&this.endFile(!1,`stopped`),this.continues=!1}async pollParent(){if(!this.polling){this.polling=!0,this.polledAt=this.now();try{let e=await this.opts.call({action:`current`,stream_id:this.parentStreamId}),t=typeof e.recording_id==`string`?e.recording_id:null,n=typeof e.split_every==`number`&&e.split_every>0?e.split_every:null,r=this.now();this.noneSince=t===null?this.noneSince??r:null,t!==null&&(t!==this.parent||n!==this.splitEvery)&&(this.splitEvery=n,this.cutAt=n?E1(r,n,-new Date(r).getTimezoneOffset()*60):1/0),this.parent=t}catch{}finally{this.polling=!1}}}pollDue(){let e=this.now();if(e>=this.cutAt&&this.polledAt<this.cutAt)return!0;let t=e>=this.cutAt&&e<this.cutAt+6e4||!!this.file&&this.parent===null;return e-this.polledAt>=(t?h0:m0)}root(){return this.rootDir??=(async()=>(this.opts.root?await this.opts.root():await navigator.storage.getDirectory()).getDirectoryHandle(b0,{create:!0}))().catch(e=>{throw this.rootDir=null,e})}queue(e){this.io=this.io.then(e).catch(e=>{e?.name!==`NotFoundError`&&this.say(`disk`,`disk_error`,`Can't write the recording buffer: ${e?.message??e}`)})}openFile(e,t){let n=crypto.randomUUID(),r={stream_id:this.streamId,kind:`camera`,parent:t,continues:this.continues,prev:this.continues?this.prev:null,t0:e,closed:!1};this.file={id:n,seq:0,meta:r},this.writing.add(n),this.queue(async()=>{if(this.locks){let e=await M0(this.locks,`kymoscope-rec-${n}`);e&&this.held.set(n,e)}await A0(await(await this.root()).getDirectoryHandle(n,{create:!0}),x0,JSON.stringify(r))})}endFile(e,t){let n=this.file;this.flush(),this.file=this.chunk=null,this.continues=e,this.prev=n.id,n.meta={...n.meta,closed:!0,reason:t};let r=JSON.stringify(n.meta);this.queue(async()=>{try{await A0(await(await this.root()).getDirectoryHandle(n.id),x0,r)}finally{this.writing.delete(n.id)}})}flush(){let e=this.chunk,t=this.file;if(this.chunk=null,!e?.records.length||!t)return;let n=t.seq++,r=U(t.id,n,e.records),i=new DataView(r.buffer);i.setFloat64(40,Math.min(...e.records.map(e=>e.at)),!0),i.setFloat64(48,Math.max(...e.records.map(e=>e.at)),!0),this.queue(async()=>{await A0(await(await this.root()).getDirectoryHandle(t.id),O0(n),r),await this.enforceMax()})}async enforceMax(){let e=await this.root(),t=0,n=[];for await(let[r,i]of e.entries()){if(i.kind!==`directory`)continue;let e=(await j0(i,x0))?.t0??0;try{for await(let[a,o]of i.entries()){if(o.kind!==`file`)continue;let s=(await o.getFile()).size;t+=s,a.endsWith(`.krc`)&&n.push({t0:e,seq:parseInt(a,10),dir:i,id:r,name:a,size:s})}}catch{}}n.sort((e,t)=>e.t0-t.t0||e.seq-t.seq);let r=this.bufferMaxMB*1024*1024,i=0,a=new Map;for(let e of n){if(t<=r)break;try{await e.dir.removeEntry(e.name)}catch{continue}t-=e.size,i++,a.set(e.id,e.dir)}for(let[e,t]of a){if(e===this.file?.id)continue;let n=!1;try{for await(let[e]of t.entries())n||=e.endsWith(`.krc`)}catch{}n||this.lost.add(e)}this.usedBytes=t,i&&(this.dropped+=i,this.fullSaid||(this.fullSaid=!0,this.status({type:`buffer_full`,message:`Recording buffer full: dropped the oldest ${i} chunks`})))}status(e){try{this.opts.onStatus?.(e)}catch{}}say(e,t,n,r){this.said.has(e)||(this.said.add(e),this.status({type:t,message:n,...r?{reason:r}:{}}))}async claim(e,t){if(this.held.has(t)||this.writing.has(t))return!0;if(this.locks){let e=await M0(this.locks,`kymoscope-rec-${t}`);if(!e)return!1;this.held.set(t,e)}let n=await e.getDirectoryHandle(t).catch(()=>null);return!n||!await j0(n,x0)?(this.release(t),await e.removeEntry(t,{recursive:!0}).catch(()=>{}),!1):(this.locks||this.held.set(t,()=>{}),!0)}release(e){this.held.get(e)?.(),this.held.delete(e)}async files(){let e=await this.root(),t=[];for await(let[n,r]of e.entries())r.kind===`directory`&&t.push(n);let n=[];for(let r of t){if(!await this.claim(e,r))continue;let t=await e.getDirectoryHandle(r).catch(()=>null),i=t&&await j0(t,x0);t&&i?.stream_id&&n.push({id:r,meta:i,dir:t})}return n.sort((e,t)=>e.meta.t0-t.meta.t0||(e.id<t.id?-1:1))}async forget(e,t=!0){this.opened.delete(e),t&&this.lost.add(e),this.file?.id===e&&(this.file=this.chunk=null,this.writing.delete(e),this.continues=!1),this.release(e),await(await this.root()).removeEntry(e,{recursive:!0}).catch(()=>{})}async open(e,t){let n={action:`open`,recording_id:t.id??e,stream_id:t.stream_id,kind:t.kind,continues:!!t.continues&&!this.lost.has(t.prev??``),t0:t.t0,parent_recording_id:t.parent};this.opts.retentionDays!==void 0&&(n.retention_days=this.opts.retentionDays);let r=await this.opts.call(n);if(r.record===!1){let t=String(r.reason??`refused`);return t===`parent_not_found`?(this.wait.set(e,this.now()+g0),null):(this.say(`refused:${t}`,`refused`,String(r.message??`Recording refused (${t})`),t),e===this.file?.id&&(this.refusedUntil=this.now()+_0),await this.forget(e),null)}let i=r.destination??`kymoscope`;if(i!==`kymoscope`&&!this.storage?.[i.kind]){this.blocked.add(e);let t=`storage:${i.id}`;return this.said.has(t)||(this.said.add(t),this.status({type:`storage_needed`,destination:i,message:i.kind===`folder`?`This project records to ${i.name}: choose its folder to store the camera's files`:`This project records to ${i.name}: this sender needs its S3 keys (storage)`})),null}let a=i===`kymoscope`?`Kymoscope`:i.name;if(!this.said.has(`destination:${a}`)){this.said.add(`destination:${a}`);let e=this.splitEvery?`every ${w1(this.splitEvery)}`:`cut with its data stream's`;this.status({type:`destination`,name:a,splitEvery:this.splitEvery,message:`Recording files: ${e} → ${a} (buffer ${C0(this.bufferMaxMB)})`})}return this.opened.set(e,i),i}async put(e,t,n){let r;try{r=await this.fetch(e,t?{method:`PUT`,body:t,headers:n}:void 0)}catch(e){throw new T0(`chunk upload failed: ${e?.message??e}`)}if(!r.ok)throw new T0(`chunk upload failed: HTTP ${r.status}`,r.status)}async writeOwn(e,t,n,r){let{folder:i,s3:a}=this.storage??{};if(i){try{await A0(await(await i.getDirectoryHandle(e.stream_id,{create:!0})).getDirectoryHandle(t,{create:!0}),O0(n),r)}catch(e){throw new T0(`can't write to the folder: ${e?.message??e}`)}return}let o=(a.prefix??``).replace(/^\/+|\/+$/g,``),s=`${o?`${o}/`:``}${e.stream_id}/${t}/${O0(n)}`,c=`${a.endpoint.replace(/\/+$/,``)}/${a.bucket?`${a.bucket}/`:``}${s}`,l=new o0({accessKeyId:a.accessKeyId,secretAccessKey:a.secretAccessKey,service:`s3`,region:a.region||`us-east-1`});await this.put(await l.sign(c,{method:`PUT`,body:r}))}dropChunk(e,t,n){return this.say(`chunk:${n}`,`chunk_dropped`,`A recording chunk was dropped (${n})`),e.removeEntry(t).catch(()=>{})}async uploadChunk(e,t,n,r){let i=t.id??e,a;try{a=new Uint8Array(await(await(await n.getFileHandle(r)).getFile()).arrayBuffer())}catch{return}let o;try{o=Ve(a)}catch{o=null}if(!o||o.bytes!==a.length)return this.dropChunk(n,r,`unreadable on disk`);let s=parseInt(r,10),c=k0(await crypto.subtle.digest(`SHA-256`,a));try{let e=await this.opts.call({action:`chunk`,recording_id:i,seq:s,bytes:a.length,sha256:c});e.own?await this.writeOwn(t,i,s,a):await this.put(String(e.url),a,{Authorization:`Bearer ${e.ticket}`}),await this.opts.call({action:`confirm`,recording_id:i,seq:s,bytes:a.length,messages:o.count,t0:o.t0,t1:o.t1,sha256:c})}catch(e){if(E0(e)===400)return this.dropChunk(n,r,`refused: ${D0(e)}`);if(E0(e)!==409||D0(e)!==`chunk_exists`)throw e}await n.removeEntry(r).catch(()=>{}),this.usedBytes=Math.max(0,this.usedBytes-a.length),this.fullSaid=!1,this.said.delete(`put`)}async reopen(e,t){let n=!1;for await(let[e]of t.entries())n||=e.endsWith(`.krc`);if(!n&&this.file?.id!==e)return!1;this.file?.id===e&&this.endFile(!1,`stopped`),await this.io;let r=await j0(t,x0);return r?(await A0(t,x0,JSON.stringify({...r,id:crypto.randomUUID(),continues:!1,prev:null})),this.opened.delete(e),!0):!1}async uploadPending(){let e=!0;for(let{id:t,meta:n,dir:r}of await this.files()){if(this.blocked.has(t))continue;if(this.now()<(this.wait.get(t)??0)){e=!1;continue}let i=n.closed||!this.writing.has(t);try{if(!(this.opened.get(t)??await this.open(t,n))){!this.blocked.has(t)&&(this.held.has(t)||this.writing.has(t))&&(e=!1);continue}let a=[];for await(let[e,t]of r.entries())t.kind===`file`&&e.endsWith(`.krc`)&&a.push(e);for(let e of a.sort())await this.uploadChunk(t,n,r,e);i?(await this.opts.call({action:`close`,recording_id:n.id??t,reason:n.reason??`stopped`}),await this.forget(t,!1)):e=!1}catch(n){let i=E0(n);if(i===404&&this.opened.has(t)&&await this.reopen(t,r)){e=!1;continue}if(i===403||i===404||i===410||i===400){this.say(`gone:${t}`,`refused`,`A recording file was refused (${D0(n)}): its chunks were dropped`,D0(n)),await this.forget(t);continue}throw n instanceof T0&&n.status!==401&&this.say(`put`,`storage_error`,`Can't store recording chunks (${n.message}); retrying`),n}}return e}async run(){let e=0;for(;!this.stopped;){let t=!1;try{this.tick(),this.pollDue()&&await this.pollParent(),t=await this.uploadPending(),e=0}catch{e=S0(e)}if(this.closing&&(t||e))break;await new Promise(t=>{this.wake=t,setTimeout(t,e||1e3)}),this.wake=null}}async close(e=3e3){this.stop(),this.closing=!0,this.wake?.(),this.loop?await Promise.race([this.loop,new Promise(t=>setTimeout(t,e))]):await this.io,this.stopped=!0,this.wake?.();for(let e of[...this.held.keys()])this.release(e)}},P0=class{#e;constructor(e){this.#e=e}head(){let e=this.#e;return`${e.map(e=>m$(e.name)).join(`,`)}\n${e.map(e=>m$(e.unit)).join(`,`)}\n`}append(e){let t=e.columns,n=``;for(let r=0;r<e.length;r++){for(let e=0;e<t.length;e++){let i=t[e][r];n+=(e?`,`:``)+(Number.isNaN(i)?``:String(i))}n+=`
|
|
622
|
-
`}return n}end(){}},F0=new TextEncoder,I0=e=>e+7&-8,L0=104,R0=64,z0=104,B0=160,V0=4;function H0(e,t,n){let r=24+t.length*8+n.length,i=new Uint8Array(I0(r)),a=new DataView(i.buffer);return i.set(F0.encode(e),0),a.setBigUint64(8,BigInt(r),!0),a.setBigUint64(16,BigInt(t.length),!0),t.forEach((e,t)=>a.setBigUint64(24+t*8,BigInt(e),!0)),i.set(n,24+t.length*8),i}var U0=(e,t)=>H0(e,[],F0.encode(`${t}\0`)),W0=e=>BigInt(Math.round(e))*1000000n,G0=class{#e;#t;#n;#r=0;constructor(e,t,n){this.#e=e,this.#t=t?Date.parse(t):Date.now(),this.#n=n}append(e){let t=e.columns,n=t.length,r=new Float64Array(e.length*n);for(let i=0;i<e.length;i++)for(let e=0;e<n;e++)r[i*n+e]=t[e][i];return this.#r+=e.length,new Uint8Array(r.buffer)}end(){if(this.#r!==this.#n)throw Error(`The recording changed while it was exported (${this.#r} of ${this.#n} rows).`)}head(){let e=this.#e.length,t=[],n=64+L0,r=e=>{let r=n;return t.push(e),n+=e.length,r},i=r(U0(`##MD`,`<FHcomment><TX>Kymoscope cloud recording</TX><tool_id>Kymoscope</tool_id><tool_vendor>Kymoscope</tool_vendor><tool_version>1</tool_version></FHcomment>`)),a=new Uint8Array(16);new DataView(a.buffer).setBigUint64(0,W0(this.#t),!0);let o=r(H0(`##FH`,[0,i],a)),s=this.#e.map(e=>r(U0(`##TX`,e.name))),c=this.#e.map(e=>e.unit?r(U0(`##TX`,e.unit)):0),l=n,u=l+R0,d=this.#e.map((e,t)=>u+z0+t*B0),f=H0(`##DG`,[0,u,u+z0+e*B0,0],new Uint8Array(8)),p=new Uint8Array(32),m=new DataView(p.buffer);m.setBigUint64(8,BigInt(this.#n),!0),m.setUint32(24,e*8,!0);let h=H0(`##CG`,[0,d[0],0,0,0,0],p),g=this.#e.map((t,n)=>{let r=new Uint8Array(72),i=new DataView(r.buffer);return i.setUint8(0,n===0?2:0),i.setUint8(1,+(n===0)),i.setUint8(2,V0),i.setUint32(4,n*8,!0),i.setUint32(8,64,!0),i.setUint8(20,255),H0(`##CN`,[n+1<e?d[n+1]:0,0,s[n],0,0,0,c[n],0],r)}),_=new Uint8Array(24);_.set(F0.encode(`##DT`),0),new DataView(_.buffer).setBigUint64(8,BigInt(24+this.#n*e*8),!0);let v=new Uint8Array(64);v.set(F0.encode(`MDF 4.10 Kymoscop`),0),new DataView(v.buffer).setUint16(28,410,!0);let y=new Uint8Array(32);new DataView(y.buffer).setBigUint64(0,W0(this.#t),!0);let b=[v,H0(`##HD`,[l,o,0,0,0,0],y),...t,f,h,...g,_],x=new Uint8Array(b.reduce((e,t)=>e+t.length,0));return b.reduce((e,t)=>(x.set(t,e),e+t.length),0),x}},K0={csv:`text/csv`,mf4:`application/octet-stream`,parquet:`application/vnd.apache.parquet`};async function q0(e,t,n,r={}){let i=pz(`krc`,{main:new File(e.chunks,`${e.name}.krc`),companions:[],keys:e.keys},r.signal,r.createWorker);try{let e=await i.plan(),a=[{group:0,channels:e.groups[0].channels.map((e,t)=>t)}],o=t===`csv`?new P0(tz(e,a)):new G0(tz(e,a),e.startTime,e.groups[0].samples);await n(o.head()),await i.read(a,`stream`,{chunk:async e=>{await n(o.append(e))},progress:r.onProgress}),o.end()}finally{i.close()}}async function J0(e,t,n={}){let r=[];return await q0(e,t,e=>{r.push(e)},n),new Blob(r,{type:K0[t]})}var Y0=(e,t)=>`khd1|${e.stream}|${e.day}|${e.kind}|${e.level}|${t}`;function X0(e){if(e.length<9)throw Error(`Not a Kymoscope day file (too short)`);let t=e.subarray(e.length-9);if(String.fromCharCode(t[5],t[6],t[7],t[8])!==`KHD1`)throw Error(`Not a Kymoscope day file`);if(t[4]!==1)throw Error(`Unknown Kymoscope day file format ${t[4]}`);return new DataView(t.buffer,t.byteOffset,4).getUint32(0,!0)}var Z0=new TextEncoder;async function Q0(e,t,n,r){let i=await crypto.subtle.decrypt({name:`AES-GCM`,iv:t.subarray(0,12),additionalData:Z0.encode(Y0(n,r))},e,t.subarray(12));return new Uint8Array(i)}async function $0(e,t,n){let r=JSON.parse(new TextDecoder().decode(Te(await Q0(e,t,n,`footer`))));if(r.format!==1||r.stream!==n.stream||r.day!==n.day||r.kind!==n.kind||r.level!==n.level)throw Error(`This day file belongs to another history or day`);return r}var e2=0;async function t2(e,t){let n=await HL(),r=e.map(()=>`khd_${++e2}.parquet`),i=[];try{for(let t=0;t<e.length;t++)await n.registerFileBuffer(r[t],e[t]),i.push(r[t]);let a=await n.connect();try{return await t(r,e=>a.query(e))}finally{await a.close()}}finally{for(let e of i)await n.dropFile(e).catch(()=>void 0)}}var n2=(e,t)=>e.getChild(t).toArray();function r2(){t2([],async(e,t)=>{await t(`COPY (SELECT 1::BIGINT AS t) TO 'khd_warm.parquet' (FORMAT parquet)`),await t(`SELECT t FROM read_parquet('khd_warm.parquet')`)}).catch(()=>void 0)}async function i2(e,t){return t2([e],async([e],n)=>{let r=await n(`SELECT (t::DOUBLE / 1e6) AS t${t.map(e=>`, coalesce("c${e}", 'NaN'::FLOAT) AS "c${e}"`).join(``)} FROM read_parquet('${e}') ORDER BY t`);return{t:Float64Array.from(n2(r,`t`)),cols:t.map(e=>Float32Array.from(n2(r,`c${e}`)))}})}async function a2(e){return e.some(e=>e.channels.length)?t2(e.map(e=>e.bytes),async(t,n)=>{let r=await n(`SELECT k, (t::DOUBLE / 1e6) AS t, ch, "min", "max" FROM (${t.flatMap((t,n)=>e[n].channels.length?[`SELECT ${n} AS k, t, ch, "min", "max" FROM read_parquet('${t}') WHERE ch IN (${e[n].channels.join(`,`)})`]:[]).join(` UNION ALL `)}) ORDER BY k, ch, t`),i=n2(r,`k`),a=n2(r,`t`),o=n2(r,`ch`),s=n2(r,`min`),c=n2(r,`max`),l=[];for(let t=0,n=0;t<e.length;t++){let e=n;for(;e<i.length&&i[e]===t;)e++;l.push({t:Float64Array.from({length:e-n},(e,t)=>a[n+t]),ch:Int32Array.from({length:e-n},(e,t)=>o[n+t]),min:Float32Array.from({length:e-n},(e,t)=>s[n+t]),max:Float32Array.from({length:e-n},(e,t)=>c[n+t])}),n=e}return l}):e.map(()=>({t:new Float64Array,ch:new Int32Array,min:new Float32Array,max:new Float32Array}))}var o2=2*1024**3;async function s2(){try{return await(await navigator.storage.getDirectory()).getDirectoryHandle(`kymoscope-history`,{create:!0})}catch{return null}}async function c2(){try{let e=(await navigator.storage.estimate()).quota??0;return e>0?Math.min(o2,e*.2):o2}catch{return o2}}function l2(e=s2,t=c2){let n=null,r=null,i=0,a=()=>n??=e().catch(()=>null),o=e=>e.replace(/[^A-Za-z0-9._-]/g,`_`),s=()=>r??=(async()=>{let e=new Map,t=await a();if(i=0,t)for await(let[n,r]of t.entries()){if(r.kind!==`file`||!r.getFile)continue;let t=await r.getFile();e.set(n,{size:t.size,at:t.lastModified}),i+=t.size}return e})().catch(e=>{throw r=null,e});return{async get(e){try{let t=await a();return t?new Uint8Array(await(await(await t.getFileHandle(o(e))).getFile()).arrayBuffer()):null}catch{return null}},async put(e,n){try{let r=await a();if(!r)return;let c=await s(),l=o(e),u=await(await r.getFileHandle(l,{create:!0})).createWritable();try{await u.write(n),await u.close()}catch(e){throw await u.abort?.().catch(()=>void 0),e}i+=n.length-(c.get(l)?.size??0),c.set(l,{size:n.length,at:Date.now()});let d=await t();if(i<=d)return;for(let[e,t]of[...c].sort((e,t)=>e[1].at-t[1].at)){if(i<=d*.9)break;try{await r.removeEntry(e)}catch{continue}c.delete(e),i-=t.size}}catch{}}}}var u2=16,d2=2e3,f2=512*1024,p2=64*1024,m2=64*1024,h2=8*1024*1024;function g2(e,t=d2){for(let n of[3600,60])if(e/n>=t/2)return n;return 0}var _2={0:[0,60,3600],60:[60,3600,0],3600:[3600,60,0]};function v2(e,t){let n=new Map;for(let t of e)n.set(t.day,[...n.get(t.day)??[],t]);let r=[];for(let[,e]of[...n].sort((e,t)=>e[0].localeCompare(t[0]))){let n=_2[t].map(t=>e.find(e=>e.level===t)).find(Boolean);n&&r.push(n)}return r}async function y2(e,t,n){let r=Array(e.length),i=0;return await Promise.all(Array.from({length:Math.min(t,e.length)},async()=>{for(;i<e.length;){let t=i++;r[t]=await n(e[t])}})),r}function b2(e){let t=[];for(let n of[...e].sort((e,t)=>e.off-t.off)){let e=t[t.length-1];e&&n.off-e.end<=m2&&n.off+n.len-e.start<=h2?e.end=Math.max(e.end,n.off+n.len):t.push({start:n.off,end:n.off+n.len})}return t}var x2=(e,t)=>({stream:e.historyStreamId,day:t.day,kind:t.kind,level:t.level}),S2=(e,t)=>async(n,r,i)=>{let a=t.get(n.id);return a?a.subarray(r,i):(e.signal?.throwIfAborted(),e.fetchRange(n.id,r,i,e.signal))};async function C2(e,t,n=new Map){let r=e.footers?.get(t.id);if(r)return r;let i=await e.cache?.get(`${t.id}/footer`)??null;if(!i){t.bytes<=f2&&n.set(t.id,await e.fetchRange(t.id,0,t.bytes,e.signal));let r=S2(e,n),a=await r(t,Math.max(0,t.bytes-p2),t.bytes),o=X0(a);i=o+9<=a.length?a.slice(a.length-9-o,a.length-9):(await r(t,t.bytes-9-o,t.bytes-9)).slice(),await e.cache?.put(`${t.id}/footer`,i)}let a=await $0(await e.key(t.keyId),i,x2(e,t));return e.footers?.set(t.id,a),a}var w2=e=>e?.code===`missing`;async function T2(e){let t=async()=>{let t=v2(e.segments,e.level).map(e=>e.id).join(),n=await e.relist();return v2(n,e.level).map(e=>e.id).join()===t?null:n},n,r;try{n=await E2(e)}catch(n){if(!e.relist||e.signal?.aborted||!(r=await t()))throw n;return E2({...e,segments:r})}return!n.missingDays.length||!e.relist||e.signal?.aborted||!(r=await t())?n:E2({...e,segments:r})}async function E2(e){let t=v2(e.segments,e.level),n=new Set(e.channels),r=new Map,i=S2(e,r),a=new Set,o=async(t,n)=>{try{return await n()}catch(n){if(e.onMissing!==`gap`||!w2(n))throw n;return a.add(t.id),null}},s=await y2(t,16,t=>o(t,()=>C2(e,t,r))),c={},l={},u=[];t.forEach((t,r)=>{let i=s[r];if(i){l[t.day]=t.level;for(let e of i.channels)n.has(e.n)&&e.u&&!c[e.n]&&(c[e.n]=e.u);i.blocks.forEach((r,a)=>{if(r.t1<e.t0||r.t0>e.t1)return;let o=r.ch.filter(e=>n.has(i.channels[e].n));o.length&&u.push({s:t,f:i,i:a,chs:o})})}});let d=new Map;await y2(u,16,async t=>{let n=await e.cache?.get(`${t.s.id}/${t.i}`);n&&d.set(t,n)});let f=new Map;for(let e of u)d.has(e)||f.set(e.s.id,[...f.get(e.s.id)??[],e]);await y2([...f.values()].flatMap(e=>b2(e.map(e=>e.f.blocks[e.i])).map(t=>({js:e,r:t}))),16,async({js:t,r:n})=>{let r=await o(t[0].s,()=>i(t[0].s,n.start,n.end));if(r)for(let i of t){let t=i.f.blocks[i.i];if(t.off<n.start||t.off+t.len>n.end)continue;let a=r.slice(t.off-n.start,t.off-n.start+t.len);d.set(i,a),e.cacheWrite!==!1&&await e.cache?.put(`${i.s.id}/${i.i}`,a)}});let p=[],m=[];return await y2(u.filter(e=>!a.has(e.s.id)),16,async t=>{let n=await Q0(await e.key(t.s.keyId),d.get(t),x2(e,t.s),t.i);if(t.s.kind===`rollup`){m.push({j:t,plain:n});return}let r=await i2(n,t.chs),i=new Map(t.chs.map((e,n)=>[t.f.channels[e].n,r.cols[n]])),a=EQ({t:r.t,lo:i,hi:i,level:0},e.t0,e.t1);a&&p.push(a)}),(await a2(m.map(e=>({bytes:e.plain,channels:e.j.chs})))).forEach((t,n)=>{let{j:r}=m[n],i=r.s.level/2;for(let n=0;n<t.ch.length;){let a=n;for(;a<t.ch.length&&t.ch[a]===t.ch[n];)a++;let o=r.f.channels[t.ch[n]].n,s=EQ({t:t.t.slice(n,a).map(e=>e+i),lo:new Map([[o,t.min.slice(n,a)]]),hi:new Map([[o,t.max.slice(n,a)]]),level:r.s.level},e.t0,e.t1);s&&p.push(s),n=a}}),{pieces:p.sort((e,t)=>e.t[0]-t.t[0]),units:c,levels:l,missingDays:t.filter(e=>a.has(e.id)).map(e=>e.day)}}var D2=25e6,O2=3e7,k2=1<<20,A2=8192,j2=65536;function M2(e){for(let t=1;t<10;t++){let n=+e.toPrecision(t);if(Math.fround(n)===e)return String(n)}return String(e)}function N2(e){let t=Math.round(e*1e6),n=Math.floor(t/1e6);return`${new Date(n*1e3).toISOString().slice(0,19)}.${String(t-n*1e6).padStart(6,`0`)}Z`}function P2(e,t){let n=e.filter(e=>t.some(t=>e.lo.has(t))).map(e=>e.t),r=new Float64Array(n.reduce((e,t)=>e+t.length,0)),i=0;for(let e of n)r.set(e,i),i+=e.length;r.sort();let a=0;for(let e=0;e<r.length;e++)(a===0||r[e]!==r[a-1])&&(r[a++]=r[e]);let o=r.slice(0,a);if(o.length*t.length>25e6)throw Error(`too_wide`);let s=t.map(()=>new Float32Array(o.length).fill(NaN));for(let n of e)t.forEach((e,t)=>{let r=n.lo.get(e);if(r){for(let e=0,i=wQ(o,n.t[0]);e<n.t.length;e++)if(r[e]===r[e]){for(;o[i]<n.t[e];)i++;s[t][i]=r[e]}}});return{t:o,cols:s}}async function F2(e,t,n,r={}){if(!e.channels.length)throw Error(`Pick at least one channel to export.`);let i=[...new Set(e.segments.map(e=>e.day))].sort(),a=i.map(t=>e.segments.find(e=>e.day===t&&e.kind===`raw`)).filter(e=>!!e),o=i.filter(e=>!a.some(t=>t.day===e)),s=new Set,c=()=>({skippedDays:[...o,...s].sort(),missingDays:[...s].sort()}),l=async t=>{let n=await T2({...e,segments:[t],level:0,cacheWrite:!1,relist:e.relist&&(async()=>(await e.relist()).filter(e=>e.day===t.day&&e.kind===`raw`))});for(let e of n.missingDays)s.add(e);return n},u=e=>r.onProgress?.((e+1)/a.length);if(t===`parquet`)return await L2(a,l,e.channels,n,u),c();if(t===`csv`){let t=!1;for(let[r,i]of a.entries()){let a=await l(i);!t&&!a.missingDays.length&&(await n(`time,${e.channels.map(m$).join(`,`)}\nUTC,${e.channels.map(e=>m$(a.units[e]??``)).join(`,`)}\n`),t=!0);let o=P2(a.pieces,e.channels);for(let e=0;e<o.t.length;e+=A2){let t=``;for(let n=e;n<Math.min(o.t.length,e+A2);n++){t+=N2(o.t[n]);for(let e of o.cols)t+=e[n]===e[n]?`,${M2(e[n])}`:`,`;t+=`
|
|
623
|
-
`}await n(t)}u(r)}return t||await n(`time,${e.channels.map(
|
|
624
|
-
ORDER BY v.time, n.channel) TO '${d}' (FORMAT parquet, COMPRESSION zstd)`),await r(await o.copyFileToBuffer(d))}finally{await s.query(`DROP TABLE IF EXISTS ${l}; DROP TABLE IF EXISTS ${u}`).catch(()=>void 0),await s.close(),await o.dropFile(d).catch(()=>void 0)}}export{TZ as ANNOTATION_CONTROLS_ATTR,kt as ANNOTATION_KINDS,T$ as AxisState,bB as BEACON_STATS,N0 as BrowserRecorder,K1 as CAMERA_QUALITIES,tr as CHART_ALARM_FIELDS,UQ as CHART_KINDS,VB as CYCLE_TIME,n0 as CameraSender,PB as CycleRunner,FB as CycleSet,zt as DASHBOARD_GRID_COLS,Vt as DASHBOARD_GRID_GAP_PX,Bt as DASHBOARD_GRID_ROWS,Xz as DATASET_PALETTE,At as DEFAULT_ANNOTATION_WIDTH,tn as DEFAULT_AXIS_LINE,rn as DEFAULT_BEACON,nn as DEFAULT_GRID_LINE,pn as DEFAULT_TRACE_WIDTH,fn as DEFAULT_XYZ_POINT_RADIUS,dn as DEFAULT_XY_POINT_RADIUS,L$ as DELTA_SUFFIX,K0 as EXPORT_TYPES,CT as FUNCTION_REFERENCE,d2 as HISTORY_PIXELS,OQ as HistoryDataSource,EV as IMPORTABLE_EXT,_e as KIND_VIDEO,aB as KPI_STATS,ye as KRC_HEADER_BYTES,vB as KpiAcc,ME as KymoscopeError,rt as LEAF_KEYS,$e as LIVE_TIME_COLUMN,q1 as LOW_PRESET,G1 as LivePublisher,x$ as MAX_BAND_CELLS,b$ as MAX_GRID,Wn as MAX_PANEL_CAMERAS,O2 as MAX_PARQUET_VALUES,D2 as MAX_WIDE_CELLS,Gt as MIN_PANEL_H,Wt as MIN_PANEL_W,C as OPEN_STREAM_PASSWORD,u2 as RANGE_PARALLEL,b1 as RecordedVideoSource,V1 as RegistryError,yB as RuleRunner,It as SEVERITY_HEX,x1 as SPLIT_STEPS,t1 as UNLIMITED,lX as VIDEO_LIMIT_NOTICE,r$ as VIDEO_MAX_FRAGMENT,$T as WINDOW_FN_NAMES,T as WORKBOOK_EXPORT_AAD,O as alertRuleAad,E$ as alignSegment,$t as arrangeAutoLayout,S$ as axisColumn,N$ as bandEdges,EB as bestCycleIndex,f as bindKeyAad,Y0 as blockAad,l2 as blockCache,C0 as bufferLabel,FW as buildEquation,wE as buildMathChannelsBlob,k$ as buildReference,OV as buildTree,Hn as cameraLabel,nr as chartAlarm,Ez as chartChannelCount,GQ as chartLabel,g2 as chooseLevel,sr as clampPct,qt as clampRectForKind,EQ as clipPiece,b2 as coalesce,Qn as coerceAlarmLine,Pt as coerceAnnotation,WY as colorAt,Zz as colorForDataset,nB as colorSchemeOf,qY as colorsCss,m as columnIsNumeric,cB as compareOp,P$ as compareToReference,MW as computePolyFit,NW as computeR2,p1 as createEngine,tt as createRuleEvaluator,YB as cutCycle,NB as cycleRuleChannels,ZB as cycleTables,SB as cyclicChannels,I$ as decodeBand,o$ as decodeVideo,GX as decorateColumnLabel,Nn as defaultAreaChartPanelSettings,jn as defaultBarChartPanelSettings,bn as defaultBoxPlotPanelSettings,Fn as defaultBubbleChartPanelSettings,zn as defaultCalibrationPanelSettings,Un as defaultCameraPanelSettings,Pn as defaultCdfChartPanelSettings,wn as defaultConfusionPanelSettings,Dn as defaultControlChartPanelSettings,Qz as defaultDatasetPalette,kn as defaultEmbeddingPanelSettings,An as defaultFlameGraphPanelSettings,Vn as defaultGanttPanelSettings,Rn as defaultGaugePanelSettings,Sn as defaultHeatmapPanelSettings,_n as defaultHistogramPanelSettings,En as defaultLossCurvePanelSettings,mn as defaultMultibandPanelSettings,On as defaultParallelCoordsPanelSettings,vn as defaultPolarPanelSettings,Bn as defaultQQPlotPanelSettings,Mn as defaultRadarPanelSettings,Tn as defaultRocPanelSettings,Ln as defaultSankeyPanelSettings,xn as defaultSpectrogramPanelSettings,yn as defaultSpectrumPanelSettings,T1 as defaultSplit,In as defaultTreemapPanelSettings,Cn as defaultViolinPanelSettings,en as defaultXyAxisScaleSettings,hn as defaultXyPanelSettings,gn as defaultXyzPanelSettings,GB as definitionChannels,_ as deriveKey,S as deriveRawKeyBase64,j as deviceFingerprint,Jt as dragLayout,F$ as encodeBand,a$ as encodeVideo,nV as encryptWorkbookFile,ar as ensurePanelSettingsForPanels,iE as evalChannel,iB as eventWithin,F2 as exportHistoryTo,J0 as exportRecording,q0 as exportRecordingTo,nE as extractFreeIdentifiers,M2 as f32text,U1 as fetchUsage,WB as findCycles,X0 as footerLength,Jz as formatClockTick,Yz as formatClockValue,OB as formatLapValue,w1 as formatSplit,s$ as fragmentVideo,et as generateApiToken,i as generateDeviceKeyPair,I as generateRecoveryKeyPair,h as generateSalt,Kz as getClockTimeZone,y as getRawNonEmptyLines,O$ as gridAt,CB as guessBeaconChannel,P as hashToken,R as historyKeyAad,p as importStreamKey,te as inferParseConfig,Rz as isClockAxis,DV as isImportable,WX as isMathChannelName,N2 as isoMicros,KB as kpiColumn,oB as kpiKey,qB as kpisOf,L1 as liveBytesPerSec,z$ as liveSegmentTracker,hB as localDay,w$ as localSeconds,b as makeKeyCheck,Rt as markToAnnotation,cn as newGaugeItem,lr as newMathChannel,Zt as newPanel,uB as newResetState,cr as newSeriesId,Dz as niceMajorStep,rB as observeColorScheme,gR as openDatasetFromText,$0 as openFooter,he as openMessage,Q0 as openSealed,Ie as openUnderProjectKey,v as openWithKey,ee as openWithPassword,Gn as panelCameras,V as parseColumnNames,ne as parseConfigsEqual,BB as parseCycleDefinitions,t as parseDatasetWithConfig,tE as parseFormula,Me as parseKrc,Ve as parseKrcHeader,EE as parseMathChannelsFile,un as parseOptionalAxisRange,ir as parsePanelChartSettingsMap,B as parseRecoveryCode,C1 as parseSplit,v2 as pickSegments,y2 as pool,M$ as pooledSd,KY as presetStops,H as projectConfigKeyAad,k as projectWrapAad,e as randomKey,C2 as readFooter,T2 as readHistoryRange,UB as readSource,ke as recordingKeyAad,Re as recordingKeySealAad,fe as recoveryAttestationAad,We as recoveryCode,je as recoveryKeyAad,Be as recoveryPrivateKey,BX as referenceBands,D$ as resample,dB as resetStep,er as resolveLinkedAlarms,QB as rowsCsv,sB as ruleChannels,re as sealMessage,be as sealUnderProjectKey,ae as sealWithKey,Ne as sealWithPassword,He as senderBindKey,ce as senderBinding,Gz as setClockTimeZone,_B as shiftDay,TQ as slicePiece,DQ as splicePieces,Ee as splitApiKey,xB as splitLaps,Ke as streamKeyAad,de as subsampleIndices,qz as subscribeClockTimeZone,wB as suggestBeacon,it as thresholdOf,mB as tzOffsetS,ue as unwrapForDevice,me as unwrapStreamKey,nt as validateRule,Fe as verifyKeyCheck,RV as verifyLicense,Oe as verifySenderBinding,r2 as warmHistoryDecoder,P2 as wideDay,ve as workbookBodyAad,$B as workbookExportAad,iV as workbookFileInfo,ge as workbookKeyAad,ie as wrapForDevice,gB as zonedInstant};
|
|
621
|
+
`)}async hexBodyHash(){let e=this.headers.get(`X-Amz-Content-Sha256`)||(this.service===`s3`&&this.signQuery?`UNSIGNED-PAYLOAD`:null);if(e==null){if(this.body&&typeof this.body!=`string`&&!(`byteLength`in this.body))throw Error(`body must be a string, ArrayBuffer or ArrayBufferView, unless you include the X-Amz-Content-Sha256 header`);e=F0(await N0(this.body||``))}return e}};async function M0(e,t){let n=await crypto.subtle.importKey(`raw`,typeof e==`string`?D0.encode(e):e,{name:`HMAC`,hash:{name:`SHA-256`}},!1,[`sign`]);return crypto.subtle.sign(`HMAC`,n,D0.encode(t))}async function N0(e){return crypto.subtle.digest(`SHA-256`,typeof e==`string`?D0.encode(e):e)}var P0=[`0`,`1`,`2`,`3`,`4`,`5`,`6`,`7`,`8`,`9`,`a`,`b`,`c`,`d`,`e`,`f`];function F0(e){let t=new Uint8Array(e),n=``;for(let e=0;e<t.length;e++){let r=t[e];n+=P0[r>>>4&15],n+=P0[r&15]}return n}function I0(e){return e.replace(/[!'()*]/g,e=>`%`+e.charCodeAt(0).toString(16).toUpperCase())}function L0(e,t){let{hostname:n,pathname:r}=e;if(n.endsWith(`.on.aws`)){let e=n.match(/^[^.]{1,63}\.lambda-url\.([^.]{1,63})\.on\.aws$/);return e==null?[``,``]:[`lambda`,e[1]||``]}if(n.endsWith(`.r2.cloudflarestorage.com`))return[`s3`,`auto`];if(n.endsWith(`.backblazeb2.com`)){let e=n.match(/^(?:[^.]{1,63}\.)?s3\.([^.]{1,63})\.backblazeb2\.com$/);return e==null?[``,``]:[`s3`,e[1]||``]}let i=n.replace(`dualstack.`,``).match(/([^.]{1,63})\.(?:([^.]{0,63})\.)?amazonaws\.com(?:\.cn)?$/),a=i&&i[1]||``,o=i&&i[2];if(o===`us-gov`)o=`us-gov-west-1`;else if(o===`s3`||o===`s3-accelerate`)o=`us-east-1`,a=`s3`;else if(a===`iot`)a=n.startsWith(`iot.`)?`execute-api`:n.startsWith(`data.jobs.iot.`)?`iot-jobs-data`:r===`/mqtt`?`iotdevicegateway`:`iotdata`;else if(a===`autoscaling`){let e=(t.get(`X-Amz-Target`)||``).split(`.`)[0];e===`AnyScaleFrontendService`?a=`application-autoscaling`:e===`AnyScaleScalingPlannerFrontendService`&&(a=`autoscaling-plans`)}else o==null&&a.startsWith(`s3-`)?(o=a.slice(3).replace(/^fips-|^external-1/,``),a=`s3`):a.endsWith(`-fips`)?a=a.slice(0,-5):o&&/-\d$/.test(a)&&!/-\d$/.test(o)&&([a,o]=[o,a]);return[O0[a]||a,o||``]}var R0=1e4,z0=2e3,B0=1e4,V0=6e4,H0=2e3,U0=6e4,W0=`rec`,G0=`meta.json`,K0=e=>Math.min(U0,Math.max(H0,e*2)),q0=e=>e>=1024?`${+(e/1024).toFixed(2)} GB`:`${e} MB`,J0=e=>e.replace(/(https?:\/\/[^\s?#'"]*)\?[^\s#'"]*/g,`$1`),Y0=class extends Error{status;constructor(e,t){super(J0(e)),this.status=t}},X0=e=>e instanceof Y0?void 0:e?.status,Z0=e=>e?.code??String(X0(e)??`error`),Q0=e=>`${String(e).padStart(8,`0`)}.krc`,$0=e=>Array.from(new Uint8Array(e),e=>e.toString(16).padStart(2,`0`)).join(``);async function e2(e,t,n){let r=await(await e.getFileHandle(t,{create:!0})).createWritable();await r.write(n),await r.close()}async function t2(e,t){try{return JSON.parse(await(await(await e.getFileHandle(t)).getFile()).text())}catch{return null}}function n2(e,t){return new Promise(n=>{e.request(t,{ifAvailable:!0},e=>{if(!e){n(null);return}return new Promise(e=>n(e))}).catch(()=>n(null))})}var r2=class{streamId;parentStreamId;bufferMaxMB;dropped=0;usedBytes=0;storage;opts;now;fetch;locks;rootDir=null;parent=void 0;polledAt=-1/0;polling=!1;cutAt=1/0;noneSince=null;file=null;chunk=null;continues=!1;prev=null;lost=new Set;io=Promise.resolve();writing=new Set;held=new Map;opened=new Map;blocked=new Set;wait=new Map;said=new Set;fullSaid=!1;refusedUntil=0;closing=!1;stopped=!1;wake=null;loop=null;constructor(e){this.opts=e,this.streamId=e.streamId,this.parentStreamId=e.parentStreamId,this.bufferMaxMB=e.bufferMaxMB??2048,this.storage=e.storage??null,this.now=e.now??Date.now,this.fetch=e.fetch??((...e)=>fetch(...e)),this.locks=e.locks===void 0?typeof navigator<`u`&&navigator.locks||null:e.locks,e.autostart!==!1&&(this.loop=this.run())}wants(){return!!this.file||!!this.parent}splitEvery=null;get currentId(){return this.file?.id??null}setStorage(e){this.storage=e,this.blocked.clear();for(let e of[...this.said])e.startsWith(`storage:`)&&this.said.delete(e);this.wake?.()}add(e,t,n){if(this.closing)return;this.pollDue()&&this.pollParent();let r=this.parent??null,i=this.file;if(i&&r===null&&this.noneSince!==null&&this.now()-this.noneSince>=3e4?this.endFile(!1,`stopped`):i&&r!==null&&n&&i.meta.parent!==r&&this.endFile(!0,`stopped`),!this.file){if(!r||!n||this.now()<this.refusedUntil)return;this.openFile(t,r)}let a=this.chunk;a&&(a.bytes+12+e.length>4194304||Math.abs(t-a.records[0].at)>=6e4)&&(this.flush(),a=null),a??=this.chunk={records:[],bytes:56,opened:this.now()},a.records.push({at:t,bytes:e}),a.bytes+=12+e.length}tick(){this.chunk&&this.now()-this.chunk.opened>=6e4&&this.flush()}stop(){this.file&&this.endFile(!1,`stopped`),this.continues=!1}async pollParent(){if(!this.polling){this.polling=!0,this.polledAt=this.now();try{let e=await this.opts.call({action:`current`,stream_id:this.parentStreamId}),t=typeof e.recording_id==`string`?e.recording_id:null,n=typeof e.split_every==`number`&&e.split_every>0?e.split_every:null,r=this.now();this.noneSince=t===null?this.noneSince??r:null,t!==null&&(t!==this.parent||n!==this.splitEvery)&&(this.splitEvery=n,this.cutAt=n?X1(r,n,-new Date(r).getTimezoneOffset()*60):1/0),this.parent=t}catch{}finally{this.polling=!1}}}pollDue(){let e=this.now();if(e>=this.cutAt&&this.polledAt<this.cutAt)return!0;let t=e>=this.cutAt&&e<this.cutAt+6e4||!!this.file&&this.parent===null;return e-this.polledAt>=(t?z0:R0)}root(){return this.rootDir??=(async()=>(this.opts.root?await this.opts.root():await navigator.storage.getDirectory()).getDirectoryHandle(W0,{create:!0}))().catch(e=>{throw this.rootDir=null,e})}queue(e){this.io=this.io.then(e).catch(e=>{e?.name!==`NotFoundError`&&this.say(`disk`,`disk_error`,`Can't write the recording buffer: ${e?.message??e}`)})}openFile(e,t){let n=crypto.randomUUID(),r={stream_id:this.streamId,kind:`camera`,parent:t,continues:this.continues,prev:this.continues?this.prev:null,t0:e,closed:!1};this.file={id:n,seq:0,meta:r},this.writing.add(n),this.queue(async()=>{if(this.locks){let e=await n2(this.locks,`kymoscope-rec-${n}`);e&&this.held.set(n,e)}await e2(await(await this.root()).getDirectoryHandle(n,{create:!0}),G0,JSON.stringify(r))})}endFile(e,t){let n=this.file;this.flush(),this.file=this.chunk=null,this.continues=e,this.prev=n.id,n.meta={...n.meta,closed:!0,reason:t};let r=JSON.stringify(n.meta);this.queue(async()=>{try{await e2(await(await this.root()).getDirectoryHandle(n.id),G0,r)}finally{this.writing.delete(n.id)}})}flush(){let e=this.chunk,t=this.file;if(this.chunk=null,!e?.records.length||!t)return;let n=t.seq++,r=U(t.id,n,e.records),i=new DataView(r.buffer);i.setFloat64(40,Math.min(...e.records.map(e=>e.at)),!0),i.setFloat64(48,Math.max(...e.records.map(e=>e.at)),!0),this.queue(async()=>{await e2(await(await this.root()).getDirectoryHandle(t.id),Q0(n),r),await this.enforceMax()})}async enforceMax(){let e=await this.root(),t=0,n=[];for await(let[r,i]of e.entries()){if(i.kind!==`directory`)continue;let e=(await t2(i,G0))?.t0??0;try{for await(let[a,o]of i.entries()){if(o.kind!==`file`)continue;let s=(await o.getFile()).size;t+=s,a.endsWith(`.krc`)&&n.push({t0:e,seq:parseInt(a,10),dir:i,id:r,name:a,size:s})}}catch{}}n.sort((e,t)=>e.t0-t.t0||e.seq-t.seq);let r=this.bufferMaxMB*1024*1024,i=0,a=new Map;for(let e of n){if(t<=r)break;try{await e.dir.removeEntry(e.name)}catch{continue}t-=e.size,i++,a.set(e.id,e.dir)}for(let[e,t]of a){if(e===this.file?.id)continue;let n=!1;try{for await(let[e]of t.entries())n||=e.endsWith(`.krc`)}catch{}n||this.lost.add(e)}this.usedBytes=t,i&&(this.dropped+=i,this.fullSaid||(this.fullSaid=!0,this.status({type:`buffer_full`,message:`Recording buffer full: dropped the oldest ${i} chunks`})))}status(e){try{this.opts.onStatus?.(e)}catch{}}say(e,t,n,r){this.said.has(e)||(this.said.add(e),this.status({type:t,message:n,...r?{reason:r}:{}}))}async claim(e,t){if(this.held.has(t)||this.writing.has(t))return!0;if(this.locks){let e=await n2(this.locks,`kymoscope-rec-${t}`);if(!e)return!1;this.held.set(t,e)}let n=await e.getDirectoryHandle(t).catch(()=>null);return!n||!await t2(n,G0)?(this.release(t),await e.removeEntry(t,{recursive:!0}).catch(()=>{}),!1):(this.locks||this.held.set(t,()=>{}),!0)}release(e){this.held.get(e)?.(),this.held.delete(e)}async files(){let e=await this.root(),t=[];for await(let[n,r]of e.entries())r.kind===`directory`&&t.push(n);let n=[];for(let r of t){if(!await this.claim(e,r))continue;let t=await e.getDirectoryHandle(r).catch(()=>null),i=t&&await t2(t,G0);t&&i?.stream_id&&n.push({id:r,meta:i,dir:t})}return n.sort((e,t)=>e.meta.t0-t.meta.t0||(e.id<t.id?-1:1))}async forget(e,t=!0){this.opened.delete(e),t&&this.lost.add(e),this.file?.id===e&&(this.file=this.chunk=null,this.writing.delete(e),this.continues=!1),this.release(e),await(await this.root()).removeEntry(e,{recursive:!0}).catch(()=>{})}async open(e,t){let n={action:`open`,recording_id:t.id??e,stream_id:t.stream_id,kind:t.kind,continues:!!t.continues&&!this.lost.has(t.prev??``),t0:t.t0,parent_recording_id:t.parent};this.opts.retentionDays!==void 0&&(n.retention_days=this.opts.retentionDays);let r=await this.opts.call(n);if(r.record===!1){let t=String(r.reason??`refused`);return t===`parent_not_found`?(this.wait.set(e,this.now()+B0),null):(this.say(`refused:${t}`,`refused`,String(r.message??`Recording refused (${t})`),t),e===this.file?.id&&(this.refusedUntil=this.now()+V0),await this.forget(e),null)}let i=r.destination??`kymoscope`;if(i!==`kymoscope`&&!this.storage?.[i.kind]){this.blocked.add(e);let t=`storage:${i.id}`;return this.said.has(t)||(this.said.add(t),this.status({type:`storage_needed`,destination:i,message:i.kind===`folder`?`This project records to ${i.name}: choose its folder to store the camera's files`:`This project records to ${i.name}: this sender needs its S3 keys (storage)`})),null}let a=i===`kymoscope`?`Kymoscope`:i.name;if(!this.said.has(`destination:${a}`)){this.said.add(`destination:${a}`);let e=this.splitEvery?`every ${J1(this.splitEvery)}`:`cut with its data stream's`;this.status({type:`destination`,name:a,splitEvery:this.splitEvery,message:`Recording files: ${e} → ${a} (buffer ${q0(this.bufferMaxMB)})`})}return this.opened.set(e,i),i}async put(e,t,n){let r;try{r=await this.fetch(e,t?{method:`PUT`,body:t,headers:n}:void 0)}catch(e){throw new Y0(`chunk upload failed: ${e?.message??e}`)}if(!r.ok)throw new Y0(`chunk upload failed: HTTP ${r.status}`,r.status)}async writeOwn(e,t,n,r){let{folder:i,s3:a}=this.storage??{};if(i){try{await e2(await(await i.getDirectoryHandle(e.stream_id,{create:!0})).getDirectoryHandle(t,{create:!0}),Q0(n),r)}catch(e){throw new Y0(`can't write to the folder: ${e?.message??e}`)}return}let o=(a.prefix??``).replace(/^\/+|\/+$/g,``),s=`${o?`${o}/`:``}${e.stream_id}/${t}/${Q0(n)}`,c=`${a.endpoint.replace(/\/+$/,``)}/${a.bucket?`${a.bucket}/`:``}${s}`,l=new A0({accessKeyId:a.accessKeyId,secretAccessKey:a.secretAccessKey,service:`s3`,region:a.region||`us-east-1`});await this.put(await l.sign(c,{method:`PUT`,body:r}))}dropChunk(e,t,n){return this.say(`chunk:${n}`,`chunk_dropped`,`A recording chunk was dropped (${n})`),e.removeEntry(t).catch(()=>{})}async uploadChunk(e,t,n,r){let i=t.id??e,a;try{a=new Uint8Array(await(await(await n.getFileHandle(r)).getFile()).arrayBuffer())}catch{return}let o;try{o=Ve(a)}catch{o=null}if(!o||o.bytes!==a.length)return this.dropChunk(n,r,`unreadable on disk`);let s=parseInt(r,10),c=$0(await crypto.subtle.digest(`SHA-256`,a));try{let e=await this.opts.call({action:`chunk`,recording_id:i,seq:s,bytes:a.length,sha256:c});e.own?await this.writeOwn(t,i,s,a):await this.put(String(e.url),a,{Authorization:`Bearer ${e.ticket}`}),await this.opts.call({action:`confirm`,recording_id:i,seq:s,bytes:a.length,messages:o.count,t0:o.t0,t1:o.t1,sha256:c})}catch(e){if(X0(e)===400)return this.dropChunk(n,r,`refused: ${Z0(e)}`);if(X0(e)!==409||Z0(e)!==`chunk_exists`)throw e}await n.removeEntry(r).catch(()=>{}),this.usedBytes=Math.max(0,this.usedBytes-a.length),this.fullSaid=!1,this.said.delete(`put`)}async reopen(e,t){let n=!1;for await(let[e]of t.entries())n||=e.endsWith(`.krc`);if(!n&&this.file?.id!==e)return!1;this.file?.id===e&&this.endFile(!1,`stopped`),await this.io;let r=await t2(t,G0);return r?(await e2(t,G0,JSON.stringify({...r,id:crypto.randomUUID(),continues:!1,prev:null})),this.opened.delete(e),!0):!1}async uploadPending(){let e=!0;for(let{id:t,meta:n,dir:r}of await this.files()){if(this.blocked.has(t))continue;if(this.now()<(this.wait.get(t)??0)){e=!1;continue}let i=n.closed||!this.writing.has(t);try{if(!(this.opened.get(t)??await this.open(t,n))){!this.blocked.has(t)&&(this.held.has(t)||this.writing.has(t))&&(e=!1);continue}let a=[];for await(let[e,t]of r.entries())t.kind===`file`&&e.endsWith(`.krc`)&&a.push(e);for(let e of a.sort())await this.uploadChunk(t,n,r,e);i?(await this.opts.call({action:`close`,recording_id:n.id??t,reason:n.reason??`stopped`}),await this.forget(t,!1)):e=!1}catch(n){let i=X0(n);if(i===404&&this.opened.has(t)&&await this.reopen(t,r)){e=!1;continue}if(i===403||i===404||i===410||i===400){this.say(`gone:${t}`,`refused`,`A recording file was refused (${Z0(n)}): its chunks were dropped`,Z0(n)),await this.forget(t);continue}throw n instanceof Y0&&n.status!==401&&this.say(`put`,`storage_error`,`Can't store recording chunks (${n.message}); retrying`),n}}return e}async run(){let e=0;for(;!this.stopped;){let t=!1;try{this.tick(),this.pollDue()&&await this.pollParent(),t=await this.uploadPending(),e=0}catch{e=K0(e)}if(this.closing&&(t||e))break;await new Promise(t=>{this.wake=t,setTimeout(t,e||1e3)}),this.wake=null}}async close(e=3e3){this.stop(),this.closing=!0,this.wake?.(),this.loop?await Promise.race([this.loop,new Promise(t=>setTimeout(t,e))]):await this.io,this.stopped=!0,this.wake?.();for(let e of[...this.held.keys()])this.release(e)}},i2=class{#e;constructor(e){this.#e=e}head(){let e=this.#e;return`${e.map(e=>L$(e.name)).join(`,`)}\n${e.map(e=>L$(e.unit)).join(`,`)}\n`}append(e){let t=e.columns,n=``;for(let r=0;r<e.length;r++){for(let e=0;e<t.length;e++){let i=t[e][r];n+=(e?`,`:``)+(Number.isNaN(i)?``:String(i))}n+=`
|
|
622
|
+
`}return n}end(){}},a2=new TextEncoder,o2=e=>e+7&-8,s2=104,c2=64,l2=104,u2=160,d2=4;function f2(e,t,n){let r=24+t.length*8+n.length,i=new Uint8Array(o2(r)),a=new DataView(i.buffer);return i.set(a2.encode(e),0),a.setBigUint64(8,BigInt(r),!0),a.setBigUint64(16,BigInt(t.length),!0),t.forEach((e,t)=>a.setBigUint64(24+t*8,BigInt(e),!0)),i.set(n,24+t.length*8),i}var p2=(e,t)=>f2(e,[],a2.encode(`${t}\0`)),m2=e=>BigInt(Math.round(e))*1000000n,h2=class{#e;#t;#n;#r=0;constructor(e,t,n){this.#e=e,this.#t=t?Date.parse(t):Date.now(),this.#n=n}append(e){let t=e.columns,n=t.length,r=new Float64Array(e.length*n);for(let i=0;i<e.length;i++)for(let e=0;e<n;e++)r[i*n+e]=t[e][i];return this.#r+=e.length,new Uint8Array(r.buffer)}end(){if(this.#r!==this.#n)throw Error(`The recording changed while it was exported (${this.#r} of ${this.#n} rows).`)}head(){let e=this.#e.length,t=[],n=64+s2,r=e=>{let r=n;return t.push(e),n+=e.length,r},i=r(p2(`##MD`,`<FHcomment><TX>Kymoscope cloud recording</TX><tool_id>Kymoscope</tool_id><tool_vendor>Kymoscope</tool_vendor><tool_version>1</tool_version></FHcomment>`)),a=new Uint8Array(16);new DataView(a.buffer).setBigUint64(0,m2(this.#t),!0);let o=r(f2(`##FH`,[0,i],a)),s=this.#e.map(e=>r(p2(`##TX`,e.name))),c=this.#e.map(e=>e.unit?r(p2(`##TX`,e.unit)):0),l=n,u=l+c2,d=this.#e.map((e,t)=>u+l2+t*u2),f=f2(`##DG`,[0,u,u+l2+e*u2,0],new Uint8Array(8)),p=new Uint8Array(32),m=new DataView(p.buffer);m.setBigUint64(8,BigInt(this.#n),!0),m.setUint32(24,e*8,!0);let h=f2(`##CG`,[0,d[0],0,0,0,0],p),g=this.#e.map((t,n)=>{let r=new Uint8Array(72),i=new DataView(r.buffer);return i.setUint8(0,n===0?2:0),i.setUint8(1,+(n===0)),i.setUint8(2,d2),i.setUint32(4,n*8,!0),i.setUint32(8,64,!0),i.setUint8(20,255),f2(`##CN`,[n+1<e?d[n+1]:0,0,s[n],0,0,0,c[n],0],r)}),_=new Uint8Array(24);_.set(a2.encode(`##DT`),0),new DataView(_.buffer).setBigUint64(8,BigInt(24+this.#n*e*8),!0);let v=new Uint8Array(64);v.set(a2.encode(`MDF 4.10 Kymoscop`),0),new DataView(v.buffer).setUint16(28,410,!0);let y=new Uint8Array(32);new DataView(y.buffer).setBigUint64(0,m2(this.#t),!0);let b=[v,f2(`##HD`,[l,o,0,0,0,0],y),...t,f,h,...g,_],x=new Uint8Array(b.reduce((e,t)=>e+t.length,0));return b.reduce((e,t)=>(x.set(t,e),e+t.length),0),x}},g2={csv:`text/csv`,mf4:`application/octet-stream`,parquet:`application/vnd.apache.parquet`};async function _2(e,t,n,r={}){let i=pz(`krc`,{main:new File(e.chunks,`${e.name}.krc`),companions:[],keys:e.keys},r.signal,r.createWorker);try{let e=await i.plan(),a=[{group:0,channels:e.groups[0].channels.map((e,t)=>t)}],o=t===`csv`?new i2(tz(e,a)):new h2(tz(e,a),e.startTime,e.groups[0].samples);await n(o.head()),await i.read(a,`stream`,{chunk:async e=>{await n(o.append(e))},progress:r.onProgress}),o.end()}finally{i.close()}}async function v2(e,t,n={}){let r=[];return await _2(e,t,e=>{r.push(e)},n),new Blob(r,{type:g2[t]})}var y2=(e,t)=>`khd1|${e.stream}|${e.day}|${e.kind}|${e.level}|${t}`;function b2(e){if(e.length<9)throw Error(`Not a Kymoscope day file (too short)`);let t=e.subarray(e.length-9);if(String.fromCharCode(t[5],t[6],t[7],t[8])!==`KHD1`)throw Error(`Not a Kymoscope day file`);if(t[4]!==1)throw Error(`Unknown Kymoscope day file format ${t[4]}`);return new DataView(t.buffer,t.byteOffset,4).getUint32(0,!0)}var x2=new TextEncoder;async function S2(e,t,n,r){let i=await crypto.subtle.decrypt({name:`AES-GCM`,iv:t.subarray(0,12),additionalData:x2.encode(y2(n,r))},e,t.subarray(12));return new Uint8Array(i)}async function C2(e,t,n){let r=JSON.parse(new TextDecoder().decode(Te(await S2(e,t,n,`footer`))));if(r.format!==1||r.stream!==n.stream||r.day!==n.day||r.kind!==n.kind||r.level!==n.level)throw Error(`This day file belongs to another history or day`);return r}var w2=0;async function T2(e,t){let n=await HL(),r=e.map(()=>`khd_${++w2}.parquet`),i=[];try{for(let t=0;t<e.length;t++)await n.registerFileBuffer(r[t],e[t]),i.push(r[t]);let a=await n.connect();try{return await t(r,e=>a.query(e))}finally{await a.close()}}finally{for(let e of i)await n.dropFile(e).catch(()=>void 0)}}var E2=(e,t)=>e.getChild(t).toArray();function D2(){T2([],async(e,t)=>{await t(`COPY (SELECT 1::BIGINT AS t) TO 'khd_warm.parquet' (FORMAT parquet)`),await t(`SELECT t FROM read_parquet('khd_warm.parquet')`)}).catch(()=>void 0)}async function O2(e,t){return T2([e],async([e],n)=>{let r=await n(`SELECT (t::DOUBLE / 1e6) AS t${t.map(e=>`, coalesce("c${e}", 'NaN'::FLOAT) AS "c${e}"`).join(``)} FROM read_parquet('${e}') ORDER BY t`);return{t:Float64Array.from(E2(r,`t`)),cols:t.map(e=>Float32Array.from(E2(r,`c${e}`)))}})}async function k2(e){return e.some(e=>e.channels.length)?T2(e.map(e=>e.bytes),async(t,n)=>{let r=await n(`SELECT k, (t::DOUBLE / 1e6) AS t, ch, "min", "max" FROM (${t.flatMap((t,n)=>e[n].channels.length?[`SELECT ${n} AS k, t, ch, "min", "max" FROM read_parquet('${t}') WHERE ch IN (${e[n].channels.join(`,`)})`]:[]).join(` UNION ALL `)}) ORDER BY k, ch, t`),i=E2(r,`k`),a=E2(r,`t`),o=E2(r,`ch`),s=E2(r,`min`),c=E2(r,`max`),l=[];for(let t=0,n=0;t<e.length;t++){let e=n;for(;e<i.length&&i[e]===t;)e++;l.push({t:Float64Array.from({length:e-n},(e,t)=>a[n+t]),ch:Int32Array.from({length:e-n},(e,t)=>o[n+t]),min:Float32Array.from({length:e-n},(e,t)=>s[n+t]),max:Float32Array.from({length:e-n},(e,t)=>c[n+t])}),n=e}return l}):e.map(()=>({t:new Float64Array,ch:new Int32Array,min:new Float32Array,max:new Float32Array}))}var A2=2*1024**3;async function j2(){try{return await(await navigator.storage.getDirectory()).getDirectoryHandle(`kymoscope-history`,{create:!0})}catch{return null}}async function M2(){try{let e=(await navigator.storage.estimate()).quota??0;return e>0?Math.min(A2,e*.2):A2}catch{return A2}}function N2(e=j2,t=M2){let n=null,r=null,i=0,a=()=>n??=e().catch(()=>null),o=e=>e.replace(/[^A-Za-z0-9._-]/g,`_`),s=()=>r??=(async()=>{let e=new Map,t=await a();if(i=0,t)for await(let[n,r]of t.entries()){if(r.kind!==`file`||!r.getFile)continue;let t=await r.getFile();e.set(n,{size:t.size,at:t.lastModified}),i+=t.size}return e})().catch(e=>{throw r=null,e});return{async get(e){try{let t=await a();return t?new Uint8Array(await(await(await t.getFileHandle(o(e))).getFile()).arrayBuffer()):null}catch{return null}},async put(e,n){try{let r=await a();if(!r)return;let c=await s(),l=o(e),u=await(await r.getFileHandle(l,{create:!0})).createWritable();try{await u.write(n),await u.close()}catch(e){throw await u.abort?.().catch(()=>void 0),e}i+=n.length-(c.get(l)?.size??0),c.set(l,{size:n.length,at:Date.now()});let d=await t();if(i<=d)return;for(let[e,t]of[...c].sort((e,t)=>e[1].at-t[1].at)){if(i<=d*.9)break;try{await r.removeEntry(e)}catch{continue}c.delete(e),i-=t.size}}catch{}}}}var P2=16,F2=2e3,I2=512*1024,L2=64*1024,R2=64*1024,z2=8*1024*1024;function B2(e,t=F2){for(let n of[3600,60])if(e/n>=t/2)return n;return 0}var V2={0:[0,60,3600],60:[60,3600,0],3600:[3600,60,0]};function H2(e,t){let n=new Map;for(let t of e)n.set(t.day,[...n.get(t.day)??[],t]);let r=[];for(let[,e]of[...n].sort((e,t)=>e[0].localeCompare(t[0]))){let n=V2[t].map(t=>e.find(e=>e.level===t)).find(Boolean);n&&r.push(n)}return r}async function U2(e,t,n){let r=Array(e.length),i=0;return await Promise.all(Array.from({length:Math.min(t,e.length)},async()=>{for(;i<e.length;){let t=i++;r[t]=await n(e[t])}})),r}function W2(e){let t=[];for(let n of[...e].sort((e,t)=>e.off-t.off)){let e=t[t.length-1];e&&n.off-e.end<=R2&&n.off+n.len-e.start<=z2?e.end=Math.max(e.end,n.off+n.len):t.push({start:n.off,end:n.off+n.len})}return t}var G2=(e,t)=>({stream:e.historyStreamId,day:t.day,kind:t.kind,level:t.level}),K2=(e,t)=>async(n,r,i)=>{let a=t.get(n.id);return a?a.subarray(r,i):(e.signal?.throwIfAborted(),e.fetchRange(n.id,r,i,e.signal))};async function q2(e,t,n=new Map){let r=e.footers?.get(t.id);if(r)return r;let i=await e.cache?.get(`${t.id}/footer`)??null;if(!i){t.bytes<=I2&&n.set(t.id,await e.fetchRange(t.id,0,t.bytes,e.signal));let r=K2(e,n),a=await r(t,Math.max(0,t.bytes-L2),t.bytes),o=b2(a);i=o+9<=a.length?a.slice(a.length-9-o,a.length-9):(await r(t,t.bytes-9-o,t.bytes-9)).slice(),await e.cache?.put(`${t.id}/footer`,i)}let a=await C2(await e.key(t.keyId),i,G2(e,t));return e.footers?.set(t.id,a),a}var J2=e=>e?.code===`missing`;async function Y2(e){let t=async()=>{let t=H2(e.segments,e.level).map(e=>e.id).join(),n=await e.relist();return H2(n,e.level).map(e=>e.id).join()===t?null:n},n,r;try{n=await X2(e)}catch(n){if(!e.relist||e.signal?.aborted||!(r=await t()))throw n;return X2({...e,segments:r})}return!n.missingDays.length||!e.relist||e.signal?.aborted||!(r=await t())?n:X2({...e,segments:r})}async function X2(e){let t=H2(e.segments,e.level),n=new Set(e.channels),r=new Map,i=K2(e,r),a=new Set,o=async(t,n)=>{try{return await n()}catch(n){if(e.onMissing!==`gap`||!J2(n))throw n;return a.add(t.id),null}},s=await U2(t,16,t=>o(t,()=>q2(e,t,r))),c={},l={},u=[];t.forEach((t,r)=>{let i=s[r];if(i){l[t.day]=t.level;for(let e of i.channels)n.has(e.n)&&e.u&&!c[e.n]&&(c[e.n]=e.u);i.blocks.forEach((r,a)=>{if(r.t1<e.t0||r.t0>e.t1)return;let o=r.ch.filter(e=>n.has(i.channels[e].n));o.length&&u.push({s:t,f:i,i:a,chs:o})})}});let d=new Map;await U2(u,16,async t=>{let n=await e.cache?.get(`${t.s.id}/${t.i}`);n&&d.set(t,n)});let f=new Map;for(let e of u)d.has(e)||f.set(e.s.id,[...f.get(e.s.id)??[],e]);await U2([...f.values()].flatMap(e=>W2(e.map(e=>e.f.blocks[e.i])).map(t=>({js:e,r:t}))),16,async({js:t,r:n})=>{let r=await o(t[0].s,()=>i(t[0].s,n.start,n.end));if(r)for(let i of t){let t=i.f.blocks[i.i];if(t.off<n.start||t.off+t.len>n.end)continue;let a=r.slice(t.off-n.start,t.off-n.start+t.len);d.set(i,a),e.cacheWrite!==!1&&await e.cache?.put(`${i.s.id}/${i.i}`,a)}});let p=[],m=[];return await U2(u.filter(e=>!a.has(e.s.id)),16,async t=>{let n=await S2(await e.key(t.s.keyId),d.get(t),G2(e,t.s),t.i);if(t.s.kind===`rollup`){m.push({j:t,plain:n});return}let r=await O2(n,t.chs),i=new Map(t.chs.map((e,n)=>[t.f.channels[e].n,r.cols[n]])),a=WQ({t:r.t,lo:i,hi:i,level:0},e.t0,e.t1);a&&p.push(a)}),(await k2(m.map(e=>({bytes:e.plain,channels:e.j.chs})))).forEach((t,n)=>{let{j:r}=m[n],i=r.s.level/2;for(let n=0;n<t.ch.length;){let a=n;for(;a<t.ch.length&&t.ch[a]===t.ch[n];)a++;let o=r.f.channels[t.ch[n]].n,s=WQ({t:t.t.slice(n,a).map(e=>e+i),lo:new Map([[o,t.min.slice(n,a)]]),hi:new Map([[o,t.max.slice(n,a)]]),level:r.s.level},e.t0,e.t1);s&&p.push(s),n=a}}),{pieces:p.sort((e,t)=>e.t[0]-t.t[0]),units:c,levels:l,missingDays:t.filter(e=>a.has(e.id)).map(e=>e.day)}}var Z2=25e6,Q2=3e7,$2=1<<20,e4=8192,t4=65536;function n4(e){for(let t=1;t<10;t++){let n=+e.toPrecision(t);if(Math.fround(n)===e)return String(n)}return String(e)}function r4(e){let t=Math.round(e*1e6),n=Math.floor(t/1e6);return`${new Date(n*1e3).toISOString().slice(0,19)}.${String(t-n*1e6).padStart(6,`0`)}Z`}function i4(e,t){let n=e.filter(e=>t.some(t=>e.lo.has(t))).map(e=>e.t),r=new Float64Array(n.reduce((e,t)=>e+t.length,0)),i=0;for(let e of n)r.set(e,i),i+=e.length;r.sort();let a=0;for(let e=0;e<r.length;e++)(a===0||r[e]!==r[a-1])&&(r[a++]=r[e]);let o=r.slice(0,a);if(o.length*t.length>25e6)throw Error(`too_wide`);let s=t.map(()=>new Float32Array(o.length).fill(NaN));for(let n of e)t.forEach((e,t)=>{let r=n.lo.get(e);if(r){for(let e=0,i=HQ(o,n.t[0]);e<n.t.length;e++)if(r[e]===r[e]){for(;o[i]<n.t[e];)i++;s[t][i]=r[e]}}});return{t:o,cols:s}}async function a4(e,t,n,r={}){if(!e.channels.length)throw Error(`Pick at least one channel to export.`);let i=[...new Set(e.segments.map(e=>e.day))].sort(),a=i.map(t=>e.segments.find(e=>e.day===t&&e.kind===`raw`)).filter(e=>!!e),o=i.filter(e=>!a.some(t=>t.day===e)),s=new Set,c=()=>({skippedDays:[...o,...s].sort(),missingDays:[...s].sort()}),l=async t=>{let n=await Y2({...e,segments:[t],level:0,cacheWrite:!1,relist:e.relist&&(async()=>(await e.relist()).filter(e=>e.day===t.day&&e.kind===`raw`))});for(let e of n.missingDays)s.add(e);return n},u=e=>r.onProgress?.((e+1)/a.length);if(t===`parquet`)return await s4(a,l,e.channels,n,u),c();if(t===`csv`){let t=!1;for(let[r,i]of a.entries()){let a=await l(i);!t&&!a.missingDays.length&&(await n(`time,${e.channels.map(L$).join(`,`)}\nUTC,${e.channels.map(e=>L$(a.units[e]??``)).join(`,`)}\n`),t=!0);let o=i4(a.pieces,e.channels);for(let e=0;e<o.t.length;e+=e4){let t=``;for(let n=e;n<Math.min(o.t.length,e+e4);n++){t+=r4(o.t[n]);for(let e of o.cols)t+=e[n]===e[n]?`,${n4(e[n])}`:`,`;t+=`
|
|
623
|
+
`}await n(t)}u(r)}return t||await n(`time,${e.channels.map(L$).join(`,`)}\n`),c()}let d=0,f=NaN,p={};for(let t of a){let n=await l(t),r=i4(n.pieces,e.channels);d+=r.t.length,Number.isNaN(f)&&r.t.length&&(f=r.t[0]),p={...n.units,...p}}let m=new h2([{name:`time`,unit:`s`,text:!1},...e.channels.map(e=>({name:e,unit:p[e]??``,text:!1}))],Number.isNaN(f)?null:new Date(f*1e3).toISOString(),d);await n(m.head());for(let[t,r]of a.entries()){let i=i4((await l(r)).pieces,e.channels),a=i.t.map(e=>e-f);for(let e=0;e<i.t.length;e+=t4){let t=Math.min(i.t.length,e+t4);await n(m.append({length:t-e,columns:[a.subarray(e,t),...i.cols.map(n=>Float64Array.from(n.subarray(e,t)))]}))}u(t)}return m.end(),c()}var o4=0;async function s4(e,t,n,r,i,a={max:Q2,chunk:$2}){let o=await HL(),s=await o.connect(),c=++o4,l=`khd_values_${c}`,u=`khd_names_${c}`,d=`khd_export_${c}.parquet`,f=new Float64Array(a.chunk),p=new Int32Array(a.chunk),m=new Float32Array(a.chunk),h=0,g=0,_=async()=>{h&&await s.insertArrowTable(mF({time:f.slice(0,h),ch:p.slice(0,h),value:m.slice(0,h)}),{name:l,create:!1}),h=0};try{await s.query(`CREATE TABLE ${u} (ch INTEGER, channel VARCHAR)`),await s.query(`INSERT INTO ${u} VALUES ${n.map((e,t)=>`(${t}, '${e.replace(/'/g,`''`)}')`).join(`, `)}`),await s.query(`CREATE TABLE ${l} (time DOUBLE, ch INTEGER, value FLOAT)`);for(let[r,o]of e.entries()){for(let e of(await t(o)).pieces)for(let[t,r]of n.entries()){let n=e.lo.get(r);if(n){for(let r=0;r<n.length;r++)if(n[r]===n[r]){if(++g>a.max)throw Object.assign(Error(`This export has more than ${(a.max/1e6).toLocaleString(`en-US`)} million values, too many for Parquet in the browser: export a shorter range or fewer channels.`),{code:`too_large`});f[h]=e.t[r],p[h]=t,m[h]=n[r],++h===a.chunk&&await _()}}}await _(),i(r)}await o.registerEmptyFileBuffer(d),await s.query(`COPY (SELECT to_timestamp(v.time) AS time, n.channel, v.value FROM ${l} v JOIN ${u} n USING (ch)
|
|
624
|
+
ORDER BY v.time, n.channel) TO '${d}' (FORMAT parquet, COMPRESSION zstd)`),await r(await o.copyFileToBuffer(d))}finally{await s.query(`DROP TABLE IF EXISTS ${l}; DROP TABLE IF EXISTS ${u}`).catch(()=>void 0),await s.close(),await o.dropFile(d).catch(()=>void 0)}}var c4=.01,l4=.05,u4=e=>Math.max(5,Math.ceil(e*l4)),d4=e=>Math.max(Math.abs(e.value)*2/100,2*e.spread);function f4(e){let t=new Map(e.goldens.map(e=>[e.streamId,e])),n=[];for(let r of e.cycles){let i=t.get(r.streamId);if(!i||r.value===null||!Number.isFinite(r.value)||r.tend===null||r.flag===`excluded`)continue;let a=e.value.better===`min`?r.value-i.value:i.value-r.value,o=d4(i);n.push({c:r,g:i,gap:a,level:a>o?`off`:a<-o?`better`:`golden`})}return n.sort((e,t)=>e.c.tstart-t.c.tstart)}var p4=e=>Object.fromEntries(Object.entries(e).filter(([,e])=>Number.isFinite(e)));function m4(e,t){let n=new Map;for(let r of e){let e=t(r),i=n.get(e);i?i.push(r):n.set(e,[r])}return n}var h4=(e,t)=>g4(e,e=>Math.floor((e.t-t)/86400)),g4=(e,t)=>[...m4(e,t).values()].map(e=>({t:v4(e.map(e=>e.t)),v:v4(e.map(e=>e.v))})),_4=e=>typeof e==`number`&&Number.isFinite(e);function v4(e){let t=0;for(let n=0;n<e.length;n++)t+=e[n];return e.length?t/e.length:NaN}function y4(e){if(e.length<2)return 0;let t=v4(e),n=0;for(let r=0;r<e.length;r++)n+=(e[r]-t)**2;return Math.sqrt(n/(e.length-1))}function b4(e,t){let n=Array.from(e).filter(Number.isFinite).sort((e,t)=>e-t);if(!n.length)return NaN;let r=(n.length-1)*t,i=Math.floor(r);return i+1<n.length?n[i]+(r-i)*(n[i+1]-n[i]):n[i]}var x4=e=>b4(e,.5);function S4(e){let t=x4(e);return 1.4826*x4(Array.from(e,e=>Math.abs(e-t)))}function C4(e,t){return(e-x4(t))/Math.max(S4(t),1e-12)}function w4(e){let t=Math.abs(e)/Math.SQRT2,n=1/(1+.3275911*t),r=1-((((1.061405429*n-1.453152027)*n+1.421413741)*n-.284496736)*n+.254829592)*n*Math.exp(-t*t);return e>=0?(1+r)/2:(1-r)/2}var T4=e=>Math.min(1,2*(1-w4(Math.abs(e))));function E4(e,t){let n=e.length,r=t.length;if(n<2||r<2)return{u:NaN,p:1,effect:.5};let i=[...e.map(e=>({v:e,g:0})),...t.map(e=>({v:e,g:1}))].sort((e,t)=>e.v-t.v),a=i.length,o=0,s=0;for(let e=0;e<a;){let t=e;for(;t<a&&i[t].v===i[e].v;)t++;let n=(e+1+t)/2;for(let r=e;r<t;r++)i[r].g===0&&(o+=n);s+=(t-e)**3-(t-e),e=t}let c=o-n*(n+1)/2,l=Math.sqrt(n*r/12*(a+1-s/(a*(a-1))));return{u:c,p:l>0?T4((c-n*r/2)/l):1,effect:c/(n*r)}}function D4(e){if(e<.5)return Math.log(Math.PI/Math.sin(Math.PI*e))-D4(1-e);let t=[.9999999999998099,676.5203681218851,-1259.1392167224028,771.3234287776531,-176.6150291621406,12.507343278686905,-.13857109526572012,9984369578019572e-21,1.5056327351493116e-7];--e;let n=t[0],r=e+7.5;for(let r=1;r<9;r++)n+=t[r]/(e+r);return .5*Math.log(2*Math.PI)+(e+.5)*Math.log(r)-r+Math.log(n)}function O4(e,t,n){let r=1e-300,i=e=>Math.abs(e)<r?r:e,a=1,o=1/i(1-(t+n)*e/(t+1)),s=o;for(let r=1;r<=300;r++){let c=2*r,l=r*(n-r)*e/((t-1+c)*(t+c));o=1/i(1+l*o),a=i(1+l/a),s*=o*a,l=-(t+r)*(t+n+r)*e/((t+c)*(t+1+c)),o=1/i(1+l*o),a=i(1+l/a);let u=o*a;if(s*=u,Math.abs(u-1)<1e-14)break}return s}function k4(e,t,n){if(e<=0)return 0;if(e>=1)return 1;let r=Math.exp(D4(t+n)-D4(t)-D4(n)+t*Math.log(e)+n*Math.log(1-e));return e<(t+1)/(t+n+2)?r*O4(e,t,n)/t:1-r*O4(1-e,n,t)/n}function A4(e,t){let n=.5*k4(t/(t+e*e),t/2,.5);return e>0?1-n:n}var j4=(e,t)=>k4(t/(t+e*e),t/2,.5);function M4(e,t){let n=-1e7,r=1e7;for(let i=0;i<120;i++){let i=(n+r)/2;A4(i,t)<e?n=i:r=i}return(n+r)/2}function N4(e,t,n,r){let i=e+n,a=t+r,o=(e,t)=>D4(e+1)-D4(t+1)-D4(e-t+1),s=e=>o(t,e)+o(r,i-e)-o(a,i),c=s(e),l=0;for(let e=Math.max(0,i-r);e<=Math.min(i,t);e++){let t=s(e);t<=c+1e-7&&(l+=Math.exp(t))}return Math.min(1,l)}function P4(e,t,n,r){let i=t?e/t:NaN,a=r?n/r:NaN;if(!t||!r)return{p1:i,p2:a,p:1};let o=t+r,s=e+n;if(Math.min(t,r)*Math.min(s,o-s)/o<5)return{p1:i,p2:a,p:N4(e,t,n,r)};let c=s/o,l=Math.sqrt(c*(1-c)*(1/t+1/r));return{p1:i,p2:a,p:l>0?T4((i-a)/l):1}}function F4(e,t){let n=e.map((e,t)=>t).sort((t,n)=>e[t]-e[n]),r=e.length,i=0;n.forEach((n,a)=>{e[n]<=(a+1)/r*t&&(i=a+1)});let a=e.map(()=>!1);for(let e=0;e<i;e++)a[n[e]]=!0;return a}function I4(e,t){let n=v4(e),r=v4(t),i=0,a=0,o=0;for(let s=0;s<e.length;s++)i+=(e[s]-n)*(t[s]-r),a+=(e[s]-n)**2,o+=(t[s]-r)**2;return a>0&&o>0?i/Math.sqrt(a*o):0}function L4(e,t){let n=e.length;if(n<3)return null;let r=v4(e),i=v4(t),a=0,o=0,s=0;for(let c=0;c<n;c++)a+=(e[c]-r)**2,o+=(e[c]-r)*(t[c]-i),s+=(t[c]-i)**2;if(!(a>0))return null;let c=o/a,l=i-c*r,u=Math.max(0,s-c*o),d=Math.sqrt(u/(n-2)),f=d/Math.sqrt(a);return{a:l,b:c,se:f,p:f>0?j4(c/f,n-2):0,r2:s>0?1-u/s:0,n,s:d,mx:r,sxx:a}}function R4(e,t){let n=t.length,r=e[0]?.length??0;if(n<=r+1)return null;let i=Array.from({length:r},(t,r)=>{let i=0;for(let t=0;t<n;t++)i+=e[t][r];return i/n}),a=v4(t),o=Array.from({length:r},()=>new Float64Array(r+1)),s=0;for(let c=0;c<n;c++){let n=t[c]-a;s+=n*n;for(let t=0;t<r;t++){let a=e[c][t]-i[t];for(let n=0;n<r;n++)o[t][n]+=a*(e[c][n]-i[n]);o[t][r]+=a*n}}let c=Math.max(...o.map((e,t)=>e[t]));for(let e=0;e<r;e++){let t=e;for(let n=e+1;n<r;n++)Math.abs(o[n][e])>Math.abs(o[t][e])&&(t=n);if(!(Math.abs(o[t][e])>1e-12*c))return null;[o[e],o[t]]=[o[t],o[e]];for(let t=0;t<r;t++){if(t===e)continue;let n=o[t][e]/o[e][e];for(let i=e;i<=r;i++)o[t][i]-=n*o[e][i]}}let l=o.map((e,t)=>e[r]/e[t]),u=0;for(let o=0;o<n;o++){let n=a;for(let t=0;t<r;t++)n+=l[t]*(e[o][t]-i[t]);u+=(t[o]-n)**2}let d=y4(t);return{beta:l,std:l.map((t,n)=>d>0?t*y4(e.map(e=>e[n]))/d:0),r2:s>0?1-u/s:0}}function z4(e,t){let n=R4(e,t);return n?{shares:n.std.map((n,r)=>n*I4(e.map(e=>e[r]),t)),r2:n.r2}:null}function B4(e){let t=e>>>0;return()=>{t=t+1831565813>>>0;let e=t;return e=Math.imul(e^e>>>15,e|1),e^=e+Math.imul(e^e>>>7,e|61),((e^e>>>14)>>>0)/4294967296}}var V4=2e3;function H4(e,t,{B:n=1e3,seed:r=1,alpha:i=.05}={}){let a=B4(r),o=[],s=Math.min(e,V4);for(let r=0;r<n;r++)o.push(t(Array.from({length:s},()=>Math.floor(a()*e))));let c=b4(o,i/2),l=b4(o,1-i/2);if(s<e){let n=t(Array.from({length:e},(e,t)=>t)),r=Math.sqrt(s/e);c=n+(c-n)*r,l=n+(l-n)*r}return{lo:c,hi:l}}var U4=[`management`,`quality`,`maintenance`,`production`],W4={measured:{label:`Measured`,meaning:`Read directly from the data. No model involved.`},trial:{label:`Confirmed by trial`,meaning:`A deliberate change with a before/after comparison.`},statistical:{label:`Statistical`,meaning:`A difference between groups of batches, with its p-value: the chance of a difference this large if there were none.`},correlation:{label:`Correlation`,meaning:`Two signals move together. A lead to test, not a proven cause.`},engineer:{label:`Confirmed by engineer`,meaning:`An engineer checked the finding and signed it in the report.`}},G4={"00":`Executive summary`,"01":`Since the last period`,"02":`Why batches miss the golden`,"03":`Better than the golden`,"04":`Quality: capability and containment`,"05":`Reliability and maintenance`,"06":`OEE and where time is lost`,"07":`Alerts that come before bad batches`,"08":`Changes detected`,"09":`Energy, cost and CO₂`,10:`Compared with the other lines`,11:`Shifts compared`,12:`Recommended actions`,13:`Next analyses to run`,14:`Method, evidence and approval`},K4=[...U4],q4={"00":K4,"01":[`management`],"02":[`quality`,`production`],"03":[`quality`,`production`],"04":[`quality`],"05":[`maintenance`],"06":[`management`,`maintenance`,`production`],"07":[`quality`,`production`],"08":[`quality`,`maintenance`],"09":[`management`],10:[`management`],11:[`quality`,`production`],12:K4,13:[`quality`,`production`],14:[`quality`]},J4=e=>`${e}. Supports your review; does not certify.`,Y4=(e,t,n,r,i=[])=>({id:e,title:G4[e],verdict:t,roles:q4[e],findings:n,charts:r,notes:i,...n.length>3?{shown:3}:{}}),X4=e=>`${Math.round(e*100)}%`,Z4=e=>`${Math.abs(e)>=10?Math.round(e):+e.toFixed(1)}%`;function Q4(e,t){let n=Math.abs(e)<100?2:0;return new Intl.NumberFormat(`en-GB`,{style:`currency`,currency:t,minimumFractionDigits:n,maximumFractionDigits:n}).format(e)}var $4=e=>Number.isFinite(e)?Math.abs(e)>=1e3?Math.round(e).toLocaleString(`en-GB`):String(+e.toPrecision(Math.abs(e)<1?2:3)):`—`,e3=e=>Number.isFinite(e)?String(+e.toPrecision(4)):`—`,t3=(...e)=>r3(e=>Math.abs(e)<1?2:3,e),n3=(...e)=>r3(()=>4,e);function r3(e,t){let n=n=>t.map(t=>Number.isFinite(t)?String(+t.toPrecision(Math.min(17,e(t)+n))):`—`);for(let e=0;e<14;e++){let r=n(e);if(t.every((e,n)=>t.every((t,i)=>Object.is(e,t)||r[n]!==r[i])))return r}return n(14)}var i3=e=>`${e>0?`+`:e<0?`−`:``}${$4(Math.abs(e))}`;function a3(e){return e>=3600?`${$4(e/3600)} h`:e>=60?`${Math.round(e/60)} min`:`${Math.round(e)} s`}function o3(e){let t=e.value.key,n=t.lastIndexOf(`:`);return t===`duration`?`s`:e.units[t]??(n>0&&/^(mean|min|max|first|last|median|std|range)$/.test(t.slice(n+1))?e.units[t.slice(0,n)]??``:``)}var s3=e=>e===1?`once`:e===2?`twice`:`${e} times`,c3=(e,t,n=`${t}s`)=>`${e.toLocaleString(`en-GB`)} ${e===1?t:n}`,l3=e=>e.length<=1?e.join(``):`${e.slice(0,-1).join(`, `)} and ${e[e.length-1]}`,u3=e=>e.charAt(0).toUpperCase()+e.slice(1),d3=e=>e.charAt(0).toLowerCase()+e.slice(1);function f3(e){try{return new Intl.DateTimeFormat(`en-GB`,{timeZone:e}),!0}catch{return!1}}var p3=new Map,m3=(e,t)=>{let n=`${e}|${JSON.stringify(t)}`,r=p3.get(n);return r||p3.set(n,r=new Intl.DateTimeFormat(`en-GB`,{timeZone:f3(e)?e:`UTC`,...t})),r},h3=(e,t)=>m3(t,{day:`numeric`,month:`short`}).format(new Date(e*1e3)),g3=(e,t)=>m3(t,{day:`numeric`,month:`short`,hour:`2-digit`,minute:`2-digit`,hourCycle:`h23`}).format(new Date(e*1e3)),_3=(e,t)=>m3(t,{hour:`2-digit`,minute:`2-digit`,hourCycle:`h23`}).format(new Date(e*1e3)),v3=(e,t,n,r=`–`)=>`${g3(e,n)}${r}${h3(e,n)===h3(t,n)?_3(t,n):g3(t,n)}`,y3=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`];function b3(e,t){let n=m3(t,{weekday:`short`,hour:`2-digit`,hourCycle:`h23`}).formatToParts(new Date(e*1e3));return{day:y3.indexOf(n.find(e=>e.type===`weekday`).value),hour:Number(n.find(e=>e.type===`hour`).value)%24}}var x3=(e,t)=>`${y3[b3(e,t).day]} ${g3(e,t)}`,S3={min:`minimum`,max:`maximum`,mean:`mean`,integral:`integral`,first:`at start`,last:`at end`,delta:`change`};function C3(e){if(e===`duration`)return`Cycle duration`;let t=e.lastIndexOf(`:`);return t<0?e:`${e.slice(0,t)} ${S3[e.slice(t+1)]??e.slice(t+1)}`}var w3=e=>e<.01?`p < 0.01`:`p = ${e.toFixed(2)}`;function T3(e){let t=e.numbers.r,n=e.evidence===`correlation`&&Number.isFinite(t)?`r = ${t.toFixed(2)}`:e.p===null?``:w3(e.p);return n?`${W4[e.evidence].label} · ${n}`:W4[e.evidence].label}var E3=3600,D3=(e,t)=>{let n=0,r=e.length;for(;n<r;){let i=n+r>>1;e[i]<t?n=i+1:r=i}return n};function O3(e,t){let n=e.alertRules??[];if(!n.length)return null;let r=e.alerts??[],i=new Map,a=new Map,o=new Set;for(let e of r){let t=`${e.rule}|${e.streamId}`;if(o.has(`${t}|${e.t}`))continue;o.add(`${t}|${e.t}`);let n=i.get(t);n||i.set(t,n=[]),n.push(e.t),a.set(e.rule,(a.get(e.rule)??0)+1)}for(let e of i.values())e.sort((e,t)=>e-t);let s=(e,t)=>{let n=i.get(`${t}|${e.c.streamId}`);if(!n)return!1;let r=D3(n,e.c.tstart-E3);return r<n.length&&n[r]<=(e.c.tend??e.c.tstart)},c=e=>({section:Y4(`07`,e,[],[]),actions:[],next:[],numbers:{}}),l=n.filter(e=>a.has(e.id));if(!l.length)return c(`No alert fired in this period.`);let u=t.filter(e=>e.level===`off`),d=t.filter(e=>e.level!==`off`);if(!u.length)return c(`No batch missed the golden, so no alert can be linked to one.`);if(u.length<5||d.length<5)return c(`${c3(u.length,`off-golden batch`,`off-golden batches`)} in this period: 5 are needed to link alerts to them.`);let f=l.map(e=>{let t=u.filter(t=>s(t,e.id)).length,n=d.filter(t=>s(t,e.id)).length;return{r:e,k1:t,t:P4(t,u.length,n,d.length)}}),p=F4(f.map(e=>e.t.p),c4),m=f.filter((e,t)=>p[t]&&e.t.p1>e.t.p2).sort((e,t)=>t.t.p1-t.t.p2-(e.t.p1-e.t.p2)),h=[],g=[],_=new Map;for(let e of m){let n=`F07-${h.length+1}`;_.set(e.r.id,n),h.push({id:n,section:`07`,refs:[`07`],evidence:`statistical`,p:e.t.p,numbers:p4({before:e.t.p1,rest:e.t.p2,p:e.t.p,fired:a.get(e.r.id)}),text:`“${e.r.name}” came before ${e.k1} of ${u.length} off-golden batches (${X4(e.t.p1)}) against ${X4(e.t.p2)} of the rest.`}),g.push({text:`Act on “${e.r.name}” when it fires: it came before ${X4(e.t.p1)} of off-golden batches.`,owner:`production`,urgent:!1,rank:(e.t.p1-e.t.p2)*(u.length/t.length),refs:[n]})}let v=m.length?[{kind:`table`,title:`07.1 · Alerts linked to off-golden batches: the share of batches each came before (in the hour before, or during)`,columns:[`Alert`,`Fired`,`Off-golden batches`,`The rest`],rows:m.map(e=>({cells:[e.r.name,a.get(e.r.id).toLocaleString(`en-GB`),X4(e.t.p1),X4(e.t.p2)],finding:_.get(e.r.id),status:`watch`}))}]:[],y=m.slice(0,2).map(e=>`“${e.r.name}”`),b=m.length?`${l3(y)} came before off-golden batches more often than before the rest${m.length>2?`, and ${c3(m.length-2,`more alert`)}`:``}.`:`No alert came before off-golden batches more often than before the rest.`,x=m.length?[]:[`Make an alert rule on the channel that goes with the gap (see 02) to warn before off-golden batches.`];return{section:Y4(`07`,b,h,v),actions:g,next:x,numbers:{linked:m.length}}}var k3=(e,t)=>t===`duration`?e.c.tend===null?null:e.c.tend-e.c.tstart:e.c.kpis[t]??null,A3=e=>{let t=v4(e.map(e=>-e.gap));if(e.some(e=>e.g.value===0))return{text:$4(t),pct:null,abs:t};let n=v4(e.map(e=>-e.gap/Math.abs(e.g.value)*100));return{text:Z4(n),pct:n,abs:t}},j3=e=>`${e<0?`−`:`+`}${Z4(Math.abs(e))}`;function M3(e,t){let n=t.filter(e=>e.level===`better`),r=[],i=[],a=[],o=[];if(n.length<5)return{section:Y4(`03`,n.length?`${c3(n.length,`batch`,`batches`)} beat the golden; 5 are needed to call it repeatable.`:`No batch beat the golden in this period.`,r,a),actions:i,next:o,numbers:{better:n.length}};let s=t.filter(e=>e.level===`golden`),c=s.length>=5?s:t.filter(e=>e.level!==`better`),l=e.value.label,u=A3(n),d=e=>{let t=`F03-${r.length+1}`;return r.push({id:t,section:`03`,refs:[`03`],...e}),t},f=e.streams.length>1;for(let[r,a]of m4(n,e=>e.c.streamId)){if(a.length<5)continue;let n=[...a].sort((e,t)=>e.gap-t.gap)[4],o=A3(a),s=e.streams.find(e=>e.id===r)?.name??`a stream`,c=d({evidence:`measured`,p:null,golden:{streamId:r,cycleId:n.c.id},numbers:p4({repeats:a.length,value:n.c.value,pct:o.pct??NaN,by:o.abs}),text:`Proposed new golden${f?` for ${s}`:``}: the batch of ${n.c.label}, the best ${l} that 5 batches reach (${$4(n.c.value)}). ${c3(a.length,`batch`,`batches`)} beat the golden by ${o.text} on ${l}, so this machine can reach it. Make it the golden to measure the next report against it.`});i.push({text:`Make the batch of ${n.c.label} the golden${f?` of ${s}`:``}: ${c3(a.length,`batch`,`batches`)} beat the current one by ${o.text}.`,owner:`quality`,urgent:!1,rank:a.length/t.length,refs:[c]})}r.length&&o.push(`Measure the next report against the new golden once it is set in Cycles.`);let p=[`duration`,...new Set(t.flatMap(e=>Object.keys(e.c.kpis)))].filter((t,n,r)=>t!==e.value.key&&r.indexOf(t)===n).flatMap(e=>{let t=n.map(t=>k3(t,e)).filter(_4),r=c.map(t=>k3(t,e)).filter(_4);return t.length<5||r.length<5?[]:[{k:e,ma:x4(t),mb:x4(r),p:E4(t,r).p}]}),m=F4(p.map(e=>e.p),c4),h=p.filter((e,t)=>m[t]&&e.ma!==e.mb).map(e=>({...e,label:C3(e.k),pct:e.mb===0?NaN:(e.ma-e.mb)/Math.abs(e.mb)*100})).sort((e,t)=>(Math.abs(t.pct)||1/0)-(Math.abs(e.pct)||1/0)).slice(0,5);for(let e of h)d({evidence:`correlation`,p:e.p,numbers:p4({better:e.ma,golden:e.mb,pct:e.pct,p:e.p}),text:`Batches that beat the golden go with ${e.ma<e.mb?`a lower`:`a higher`} ${e.label}: ${$4(e.ma)} against ${$4(e.mb)} at golden level${Number.isFinite(e.pct)?` (${j3(e.pct)})`:``}.`});let g=h.filter(e=>Number.isFinite(e.pct)).map(e=>({label:e.label,pct:e.pct,text:`${$4(e.ma)} / ${$4(e.mb)}`}));g.length&&a.push({kind:`diverging`,rows:g,title:`03.1 · The ${c3(n.length,`better batch`,`better batches`)} against those at golden level, % difference. Values: better / at golden level.`});let _=h.slice(0,3).map(e=>`${e.ma<e.mb?`a lower`:`a higher`} ${e.label}`);return{section:Y4(`03`,`${c3(n.length,`batch`,`batches`)} beat the golden by ${u.text} on ${l}${_.length?` with ${l3(_)}`:``}.`,r,a),actions:i,next:o,numbers:{better:n.length}}}var N3=`Ppk is indicative: it assumes the values are normally distributed and the process stable, which this report does not test.`,P3=new Set([`mean`,`min`,`max`,`first`,`last`]),F3=e=>Number.isFinite(e)?e.toFixed(2):`–`;function I3(e,t){let n=Object.entries(e.context?.channels??{}).filter(([,e])=>e.lsl!==null||e.usl!==null);if(!n.length)return null;let r=e.context?.ppkMin??1.33,i=[...new Set(t.flatMap(e=>Object.keys(e.c.kpis)))],a=[];for(let[e,r]of n)for(let n of i){let i=n.lastIndexOf(`:`);if(n.slice(0,i)!==e||!P3.has(n.slice(i+1)))continue;let o=t.map(e=>e.c.kpis[n]).filter(_4),s=y4(o);if(o.length<30)continue;let c=v4(o),l=o.filter(e=>r.usl!==null&&e>r.usl||r.lsl!==null&&e<r.lsl).length/o.length,u=s>0?Math.min(r.usl===null?1/0:(r.usl-c)/(3*s),r.lsl===null?1/0:(c-r.lsl)/(3*s)):l>0?-1/0:1/0;a.push({key:n,label:C3(n),lsl:r.lsl,usl:r.usl,n:o.length,m:c,cpk:u,out:l})}if(!a.length)return{section:`04`,needs:`04.1 · Add the mean, minimum or maximum of ${l3(n.map(([e])=>e))} to the cycle rule’s KPIs (30 batches or more) to see capability.`};a.sort((e,t)=>e.cpk-t.cpk);let o=e=>{let[t,n,r]=n3(e.lsl??NaN,e.usl??NaN,e.m);return{m:r,limits:`${e.lsl===null?`–`:t} to ${e.usl===null?`–`:n}`}},s=e=>e.out>0&&e.out<.005?`${Math.round(e.out*e.n)} of ${e.n}`:null,c=e=>`${s(e)??X4(e.out)} ${s(e)?`batches`:`of batches`} outside`,l=[],u=[],d=new Map,f=a.filter(e=>e.cpk<r);for(let e of f){let t=`F04-${l.length+1}`,n=o(e);d.set(e.key,t),l.push({id:t,section:`04`,refs:[`04`],evidence:`measured`,p:null,numbers:p4({cpk:e.cpk,n:e.n,mean:e.m,outside:e.out}),text:`${e.label}: Ppk ${F3(e.cpk)} over ${c3(e.n,`batch`,`batches`)} (mean ${n.m}, limits ${n.limits}); ${c(e)}.`}),e.cpk<1&&u.push({text:`Bring ${e.label} inside its limits: Ppk ${F3(e.cpk)}, ${c(e)}.`,owner:`quality`,urgent:e.out>0,rank:e.out+(1-Math.max(e.cpk,-10))/10,refs:[t]})}let p=[{kind:`table`,title:`04.1 · Capability per feature (indicative Ppk, capable from ${r})`,columns:[`Feature`,`Limits`,`Mean`,`Ppk (indicative)`,`Outside`],rows:a.map(e=>{let t=o(e),n=d.get(e.key);return{cells:[e.label,t.limits,t.m,F3(e.cpk),s(e)??X4(e.out)],status:e.cpk<1?`crit`:e.cpk<r?`watch`:`ok`,...n?{finding:n}:{}}})}];return{section:{...Y4(`04`,f.length?`${c3(f.length,`feature`)} below Ppk ${r}${f.length>1?`; ${f[0].label} the lowest`:``}.`:`Every feature with limits is capable (Ppk ${r} or more).`,l,p),subtitle:J4(`Capability (AIAG SPC)`),fold:!0},actions:u,next:[],numbers:{low:f.length}}}var L3=[`generic`,`discrete`,`process`,`regulated`],R3={generic:{id:`generic`,label:`Generic`,first:[],collapsed:[],roles:{},terms:{}},discrete:{id:`discrete`,label:`Discrete manufacturing (stamping, machining, assembly)`,first:[`06`,`05`,`04`,`02`],collapsed:[`03`,`13`],roles:{"06":[`management`,`maintenance`,`production`,`quality`],"04":[`quality`,`production`]},terms:{"slow batches":`slow cycles`,batches:`parts`,batch:`part`}},process:{id:`process`,label:`Process (chemical, food, batch plants)`,first:[`02`,`04`,`09`,`03`],collapsed:[`10`,`13`],roles:{"09":[`management`,`production`],"04":[`quality`,`production`]},terms:{"bad parts":`bad batches`}},regulated:{id:`regulated`,label:`Regulated (pharma, food: quality and batch review first)`,regulated:!0,first:[`04`,`02`,`05`,`07`,`08`],collapsed:[`10`,`13`],roles:{"04":[`quality`,`production`],"05":[`maintenance`,`quality`],"06":[`management`,`maintenance`,`production`,`quality`],"09":[`management`,`production`]},terms:{"bad parts":`bad batches`}}},z3=e=>R3[L3.find(t=>t===e)??`generic`],B3=e=>e===`quality`?`discrete`:e===`plants`?`process`:e===`pharma`?`regulated`:`generic`,V3=e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),H3=e=>[...e].sort((e,t)=>t.length-e.length).map(V3).join(`|`),U3=new Map;function W3(e,t,n=[]){if(!e||!Object.keys(t.terms).length)return e;let r=U3.get(t.id);if(!r){let e=`(?<![\\w.])(${H3(Object.keys(t.terms))})(?!\\w)(?!\\.\\w)`;U3.set(t.id,r={all:new RegExp(e,`gi`),has:new RegExp(e,`i`)})}let{all:i,has:a}=r,o=e=>e.replace(i,e=>{let n=t.terms[e.toLowerCase()];return e[0]===e[0].toLowerCase()?n:n[0].toUpperCase()+n.slice(1)}),s=n.filter(e=>e&&a.test(e));return s.length?e.split(RegExp(`(${H3(s)})`)).map((e,t)=>t%2?e:o(e)).join(``):o(e)}function G3(e){let t=e.context;return[...new Set([e.project,e.rule.name,e.value.label,...e.streams.map(e=>e.name),...Object.keys(e.units),...e.recordings.map(e=>e.name),...e.goldens.map(e=>e.label),...(e.alertRules??[]).map(e=>e.name),...(e.goldenChanges??[]).map(e=>e.label),...t?[...Object.keys(t.channels),...t.shifts.map(e=>e.name),...t.stops.map(e=>e.name),...t.lines.map(e=>e.name),...t.units.map(e=>e.name)]:[]])]}var K3=new Set([`id`,`section`,`kind`,`evidence`,`ref`,`refs`,`finding`,`day`,`status`,`unit`,`tone`,`roles`,`cites`,`owner`,`alert`,`batch`,`golden`]);function q3(e,t){return typeof e==`string`?t(e):Array.isArray(e)?e.map(e=>q3(e,t)):e&&typeof e==`object`?Object.fromEntries(Object.entries(e).map(([e,n])=>[e,K3.has(e)?n:q3(n,t)])):e}function J3(e,t,n=[]){if(t.id===`generic`)return e;let r=e=>W3(e,t,n),i=e=>e===`00`?-1:t.first.includes(e)?t.first.indexOf(e):t.first.length,a=e.sections.map((e,t)=>({s:e,i:t})).sort((e,t)=>i(e.s.id)-i(t.s.id)||e.i-t.i).map(({s:e})=>({...q3(e,r),roles:t.roles[e.id]??e.roles,...t.collapsed.includes(e.id)&&(e.findings.length||e.charts.length)?{collapsed:!0}:{}}));return{...e,preset:t.id,sections:a,actions:q3(e.actions,r),missing:q3(e.missing,r)}}var Y3=[`setting`,`measurement`,`quality`,`outside`,`energy`,`ignore`],X3={setting:`Adjustable setting`,measurement:`Measurement`,quality:`Quality result`,outside:`Outside influence`,energy:`Energy`,ignore:`Ignore`},Z3=4e3,Q3=(e=``)=>({role:null,unit:e,lo:null,hi:null,lsl:null,usl:null,target:null,calibration:null,suggested:!1}),$3=()=>({v:1,process:``,channels:{},lines:[],units:[],shifts:[],stops:[],costs:{currency:`EUR`,kwh:null,lineHour:null,scrap:null,rework:null,co2:null,licence:null}}),e6=e=>e&&!e.suggested?e.role:null,t6=e=>Object.keys(e?.channels??{}).filter(t=>e6(e.channels[t])===`energy`).sort()[0]??null,n6=e=>e&&typeof e==`object`&&!Array.isArray(e)?e:{},r6=e=>Array.isArray(e)?e:[],i6=(e,t)=>typeof e==`string`?e.slice(0,t):``,a6=e=>typeof e==`number`&&Number.isFinite(e)?e:null,o6=e=>r6(e).filter(e=>typeof e==`string`).slice(0,500),s6=(e,t)=>e!==null&&t!==null&&e>=t?[null,null]:[e,t],c6=/^([01]\d|2[0-3]):[0-5]\d$/,l6=/^\d{4}-\d{2}-\d{2}T([01]\d|2[0-3]):[0-5]\d$/,u6=e=>e.suggested===!0?{suggested:!0}:{};function d6(e){let t=n6(e),n=i6(t.name,80),r=i6(t.from,16),i=i6(t.to,16);if(l6.test(r)&&l6.test(i)&&r<i)return[{name:n,from:r,to:i,...u6(t)}];if(!c6.test(r)||!c6.test(i))return[];let a=t.days===void 0?void 0:[...new Set(r6(t.days).filter(e=>Number.isInteger(e)&&e>=0&&e<=6))].sort();return a&&!a.length?[]:[{name:n,from:r,to:i,...a?{days:a}:{},...u6(t)}]}function f6(e){let t=new Set,n=new Set;return r6(e).slice(0,50).map(e=>({name:i6(n6(e).name,80),streams:o6(n6(e).streams),...u6(n6(e))})).filter(e=>e.name&&!t.has(e.name)&&t.add(e.name)).map(e=>({...e,streams:e.streams.filter(e=>!n.has(e)&&n.add(e))}))}function p6(e){let t=n6(e),n=n6(t.costs),r=$3(),i=Object.create(null);for(let[e,n]of Object.entries(n6(t.channels)).slice(0,2e3)){let t=n6(n),r=Y3.find(e=>e===t.role)??null,[a,o]=s6(a6(t.lo),a6(t.hi)),[s,c]=s6(a6(t.lsl),a6(t.usl));i[e.slice(0,200)]={role:r,unit:i6(t.unit,40),lo:a,hi:o,lsl:s,usl:c,target:a6(t.target),calibration:a6(t.calibration),suggested:t.suggested===!0&&r!==null,...t.unitSuggested===!0?{unitSuggested:!0}:{},...t.rangeSuggested===!0&&a!==null&&o!==null?{rangeSuggested:!0}:{}}}return{v:1,process:i6(t.process,Z3),...t.processSuggested===!0&&i6(t.process,1)?{processSuggested:!0}:{},channels:i,lines:f6(t.lines),units:r6(t.units).slice(0,100).map(e=>({name:i6(n6(e).name,80),channels:o6(n6(e).channels),...u6(n6(e))})).filter(e=>e.name),shifts:r6(t.shifts).slice(0,12).map(e=>({name:i6(n6(e).name,40),start:i6(n6(e).start,5),end:i6(n6(e).end,5),...u6(n6(e))})).filter(e=>e.name&&c6.test(e.start)&&c6.test(e.end)),stops:r6(t.stops).slice(0,500).flatMap(d6),costs:{currency:/^[A-Z]{3}$/.test(String(n.currency))?String(n.currency):r.costs.currency,kwh:a6(n.kwh),lineHour:a6(n.lineHour),scrap:a6(n.scrap),rework:a6(n.rework),co2:a6(n.co2),licence:a6(n.licence)},...(a6(t.idealCycleS)??0)>0?{idealCycleS:t.idealCycleS}:{},...t.hideShifts===!0?{hideShifts:!0}:{},...L3.some(e=>e===t.preset)?{preset:t.preset}:{},...(a6(t.ppkMin)??0)>=1&&t.ppkMin<=3?{ppkMin:t.ppkMin}:{}}}var m6=(e,t)=>{let n=e+mB(e,t);return Math.floor((n%86400+86400)%86400/60)},h6=e=>e.slice(0,2)*60+ +e.slice(3,5);function g6(e,t,n){if(!t.length)return null;let r=m6(e,n);for(let e of t){let t=h6(e.start),n=h6(e.end);if(t<n?r>=t&&r<n:r>=t||r<n)return e.name}return null}var _6=e=>(new Date(`${e}T00:00:00Z`).getUTCDay()+6)%7;function v6(e,t,n,r){let i=[];for(let a of e.stops){if(a.from.length>5){i.push({t0:gB(a.from.slice(0,10),a.from.slice(11),t),t1:gB(a.to.slice(0,10),a.to.slice(11),t)});continue}for(let e=_B(hB(n,t),-1),o=hB(r,t);e<=o;e=_B(e,1)){if(a.days&&!a.days.includes(_6(e)))continue;let o=gB(e,a.from,t),s=gB(a.to>a.from?e:_B(e,1),a.to,t);s>n&&o<r&&i.push({t0:o,t1:s})}}return i}function y6(e){let t=e=>e.filter(e=>!e.suggested),n=Object.create(null);for(let[t,r]of Object.entries(e.channels)){let{unitSuggested:e,rangeSuggested:i,...a}=r;n[t]={...a,role:e6(r),suggested:!1,unit:e?``:r.unit,lo:i?null:r.lo,hi:i?null:r.hi}}let{processSuggested:r,...i}=e;return{...i,process:r?``:e.process,channels:n,shifts:t(e.shifts),stops:t(e.stops),lines:t(e.lines),units:t(e.units)}}function b6(e){let t=e=>Number(!!e);return t(e.processSuggested)+Object.values(e.channels).reduce((e,n)=>e+t(n.suggested)+t(n.unitSuggested)+t(n.rangeSuggested),0)+[...e.shifts,...e.stops,...e.lines,...e.units].filter(e=>e.suggested).length}function x6(e){let t=e=>e.map(e=>{let t={...e};return delete t.suggested,t}),n=Object.create(null);for(let[t,r]of Object.entries(e.channels)){let e={...r,suggested:!1};delete e.unitSuggested,delete e.rangeSuggested,n[t]=e}let r={...e,channels:n,shifts:t(e.shifts),stops:t(e.stops),lines:t(e.lines),units:t(e.units)};return delete r.processSuggested,r}function S6(e,t){let n=y6(e??$3()),r=Object.values(n.channels),i=r.some(e=>e6(e)===`energy`),a=n.costs.kwh!==null,o=[];return!n.shifts.length&&!n.hideShifts&&o.push({section:`02`,add:null,needs:`02.4 · Add shifts in Process context to split the batches that miss the golden by shift.`}),r.some(e=>e.lsl!==null||e.usl!==null)||o.push({section:`04`,add:`add specification limits`,needs:`Add specification limits (LSL, USL) to the channels in Process context to see capability (Ppk).`}),n.shifts.length?n.costs.lineHour===null&&o.push({section:`06`,add:null,needs:`06.1 · Add the cost of an hour of line time in Process context to see what the lost time costs.`}):o.push({section:`06`,add:`add shifts`,needs:`Add shifts and the cost of an hour of line time in Process context to see OEE and where time is lost.`}),t||o.push({section:`07`,add:`make alert rules`,needs:`Make alert rules in this project to see which alerts come before off-golden batches.`}),r.some(e=>e6(e)===`setting`)||o.push({section:`08`,add:`mark the adjustable settings`,needs:`Mark which channels are adjustable settings in Process context to see their changes.`}),i?(a||o.push({section:`09`,add:null,needs:`09 · Add the price per kWh in Process context to see what the energy costs.`}),n.costs.co2===null&&o.push({section:`09`,add:null,needs:`09 · Add the grid CO₂ factor (kg per kWh) in Process context to see CO₂ per batch.`})):o.push({section:`09`,add:`mark the energy channel`,needs:`Mark the energy channel in Process context to see energy per batch; the price per kWh adds its cost and the grid CO₂ factor its CO₂.`}),n.lines.filter(e=>e.streams.length).length<2&&o.push({section:`10`,add:`name two or more lines`,needs:`Say which streams are comparable lines in Process context (two or more) to compare lines.`}),!n.shifts.length&&!n.hideShifts&&o.push({section:`11`,add:`add shifts`,needs:`Add the shifts in Process context to compare them.`}),o}function C6(e){let t=y6(e??$3()),n=Object.values(t.channels),r=[];return t.costs.lineHour===null&&r.push({add:`the cost of an hour of line time`,shows:`losses in money`}),t.costs.kwh===null&&n.some(e=>e6(e)===`energy`)&&r.push({add:`the price per kWh`,shows:`what the energy costs`}),t.costs.scrap===null&&n.some(e=>e.lsl!==null||e.usl!==null)&&r.push({add:`the cost of a scrapped batch`,shows:`what the batches off specification cost`}),r}function w6(e,t){let n=S6(e,t).filter(e=>e.add!==null),r=new Map;for(let e of n)r.set(e.add,[...r.get(e.add)??[],e.section]);return{ready:15-n.length,total:15,adds:[...r].map(([e,t])=>({add:e,sections:t}))}}var T6=.2,E6=20,D6=1e5,O6=2e4,k6=1e3,A6=class{values=[];#e;#t=0;#n=B4(1);constructor(e){this.#e=e}push(e){let t=this.#t++;if(t<this.#e)this.values.push(e);else{let n=Math.floor(this.#n()*(t+1));n<this.#e&&(this.values[n]=e)}}},j6=11,M6=class{#e=0;#t=1/0;#n=-1/0;#r=!1;#i=!0;#a=NaN;#o=NaN;#s=NaN;#c=NaN;#l=[];#u=NaN;#d=NaN;#f=0;#p=0;#m=NaN;#h=NaN;#g=0;#_=0;#v=0;#y=0;#b=[];#x=new Float64Array(64);#S=0;#C=new Float64Array(63);#w=new A6(O6);#T=0;#E=0;#D=new Float64Array(j6);#O=new Float64Array(j6);#k=new Float64Array(j6);#A=0;#j=0;#M=0;#N=[];#P=new A6(D6);push(e,t){for(let n=0;n<e.length;n++){let r=t[n],i=e[n];if(!(r!==r||i!==i)){if(this.#e++,r<this.#t&&(this.#t=r),r>this.#n&&(this.#n=r),this.#P.push(r),this.#s===this.#s){let e=i-this.#s,t=!1;this.#l.length<k6?(this.#l.push(e),this.#l.length===k6&&this.#F()):e>this.#d&&(t=!0,this.#f+=e-this.#u,this.#p++),r!==this.#c&&(this.#r=!0),r<this.#c&&(this.#i=!1),Math.abs(r-this.#m)<=this.#_&&!t?this.#g++:(this.#L(this.#s),this.#I(i,r))}else this.#o=i,this.#a=r,this.#I(i,r);this.#R(r),this.#z(i,r),this.#s=i,this.#c=r}}}#F(){this.#u=x4(this.#l.filter(e=>e>0)),this.#d=this.#u>0?4*this.#u:1/0;for(let e of this.#l)e>this.#d&&(this.#f+=e-this.#u,this.#p++)}#I(e,t){this.#m=t,this.#h=e,this.#g=1,this.#_=T6*this.#E}#L(e){let t=e-this.#h;this.#g>=20&&t>=300&&(this.#v+=t,this.#y++,this.#b.length<E6&&this.#b.push({t0:this.#h,t1:e,value:this.#m}))}#R(e){let t=this.#x,n=this.#C;if(t[this.#S++]=e,this.#S<64)return;for(let e=1;e<64;e++)n[e-1]=t[e]-t[e-1];n.sort();let r=n[31];for(let e=0;e<n.length;e++)n[e]=Math.abs(n[e]-r);n.sort(),this.#T=1.4826*n[31]/Math.SQRT2,this.#w.push(this.#T),this.#T>0&&(this.#E=this.#E?.9*this.#E+.1*this.#T:this.#T),t[0]=e,this.#S=1}#z(e,t){let n=this.#k,r=this.#A===j6,i=this.#A;if(r){let e=this.#O[this.#j],t=0;for(;n[t]!==e;)t++;for(;t<i-1;t++)n[t]=n[t+1];i--}let a=i;for(;a>0&&n[a-1]>t;)n[a]=n[a-1],a--;if(n[a]=t,this.#A=i+1,this.#D[this.#j]=e,this.#O[this.#j]=t,this.#j=(this.#j+1)%j6,this.#A<j6)return;let o=e=>(this.#j+e)%j6,s=n[5],c=this.#O[o(5)],l=Math.abs(c-s),u=Math.max(this.#T,1e-9*Math.max(1,Math.abs(s)));if(l<=6*u)return;let d=Array.from(n,e=>Math.abs(e-s)).sort((e,t)=>e-t);l<=6*Math.max(1.4826*d[5],u)||Math.abs(this.#O[o(4)]-s)>l/2||Math.abs(this.#O[o(6)]-s)>l/2||(this.#M++,this.#N.length<E6&&this.#N.push(this.#D[o(5)]))}result(){this.#g&&this.#L(this.#s),this.#l.length<k6&&this.#l.length>=2&&this.#F();let e=this.#s-this.#o-this.#f,t=this.#P.values,n=this.#w.values.filter(e=>e>0),r=this.#s-this.#o;return{n:this.#e,rateHz:this.#e>1&&e>0?(this.#e-1)/e:0,gapS:this.#f,gaps:this.#p,flatS:this.#v,flatRuns:this.#y,flats:this.#b,noise:n.length?x4(n):0,spikes:this.#M,spikeAt:this.#N,min:this.#t,max:this.#n,lo:b4(t,.005),hi:b4(t,.995),median:x4(t),p01:b4(t,.01),p99:b4(t,.99),moves:this.#r,clock:this.#i&&r>0&&Math.abs(this.#c-this.#a-r)<=.01*r,counter:this.#i&&this.#r}}};function N6(e){let t=e.slice(0,Math.max(3,Math.ceil(e.length/3)));if(!t.length)return null;let n=x4(t.map(e=>e.lo)),r=x4(t.map(e=>e.hi)),i=(r-n)/2;return r>n?{lo:n-i,hi:r+i,n:t.length}:null}var P6=3600,F6=86400;function I6(e,t){let n=e.filter(e=>_4(e.c.d?.[t])).map(e=>({t:e.c.tstart,v:e.c.d[t],edge:e.g.edges[t],rec:e.c.recordingId}));if(n.length<20)return null;let r=n[0].t,i=h4(n,r),a=i,o=`day`;if(i.length<7&&(a=g4(n,e=>e.rec),o=`recording`,a.length<6&&(a=g4(n,e=>Math.floor((e.t-r)/3600)),o=`hour`)),a.length<6)return null;a.sort((e,t)=>e.t-t.t);let s=L4(a.map(e=>(e.t-r)/F6),a.map(e=>e.v)),c=x4(n.map(e=>e.edge).filter(_4));return s&&c>0&&s.b!==0?{t0:r,means:a,per:o,days:i.length,fit:s,edge:c,step:L6(a,s)}:null}function L6(e,t){let n=e.length,r=t.s*t.s*(t.n-2);if(n<4)return null;let i=e.reduce((e,t)=>e+t.v,0),a=e.reduce((e,t)=>e+t.v*t.v,0),o=1/0,s=0,c=0;for(let t=1;t<n;t++){c+=e[t-1].v;let r=a-c*c/t-(i-c)**2/(n-t);r<o&&(o=r,s=t)}if(!(o<.5*r))return null;let l=e.slice(0,s),u=e.slice(s);return{t:e[s].t,d:u.reduce((e,t)=>e+t.v,0)/u.length-l.reduce((e,t)=>e+t.v,0)/l.length}}function R6(e,t,n,r){let{t0:i,fit:a,edge:o}=n,{a:s,b:c,s:l,n:u,mx:d,sxx:f}=a,p=Math.sign(c)*o,m=i+(p-s)/c*F6,h=s+c*((r-i)/F6),g=Math.abs(h)>=o;if(!g&&(m-r)/F6>365)return null;let _=(M4(1-c4/2,u-2)*l)**2,v=s+c*d-p,y=c*c-_/f,b=(c*v)**2-y*(v*v-_/u),x=y>0&&b>=0?[(-c*v-Math.sqrt(b))/y,(-c*v+Math.sqrt(b))/y].map(e=>i+(d+e)*F6).sort((e,t)=>e-t):null,S=g?r:m;return{ch:e,key:t,b:c,p:a.p,days:n.days,n:u,per:n.per,edge:o,cross:m,lo:x?x[0]:m,hi:x?x[1]:null,past:g,vNow:h,points:n.means,line:{t0:i,v0:s,t1:S,v1:s+c*((S-i)/F6)}}}function z6(e,t,n,r,i,a,o,s=[],c=null){let l={ch:e,sid:t,key:n,drift:a,stuck:[]},u=r.flatMap(e=>e.health.channels[n]?[{r:e,h:e.health.channels[n]}]:[]);if(!u.length&&!a)return null;let d=i?` ${i}`:``,f=e=>{let t=0,n=s.length;for(;t<n;){let r=t+n>>1;s[r]<e.t0?t=r+1:n=r}return t<s.length&&s[t]<=e.t1},p=u.flatMap(e=>e.h.flats).filter(e=>!s.length||f(e)).sort((e,t)=>e.t0-t.t0),m=s.length?p.reduce((e,t)=>e+t.t1-t.t0,0):u.reduce((e,t)=>e+t.h.flatS,0),h=s.length?p.length:u.reduce((e,t)=>e+t.h.flatRuns,0);if(u.some(e=>e.h.moves)&&u.some(e=>e.h.noise>0)&&m>=600&&p.length){let e=T6*x4(u.map(e=>e.h.noise).filter(e=>e>0)),t=[];for(let n of p){let r=t[t.length-1];r&&n.t0-r.t1<=3600&&Math.abs(n.value-r.value)<=e?(r.t1=Math.max(r.t1,n.t1),r.rec+=n.t1-n.t0):t.push({...n,rec:n.t1-n.t0})}let n=t.reduce((e,t)=>t.t1-t.t0>e.t1-e.t0?t:e),r=t.length+h-p.length;return{...l,status:`Replace`,since:p[0].t0,stuck:t.map(({t0:e,t1:t})=>({t0:e,t1:t})),found:`Stuck at ${e3(n.value)}${d} from ${v3(n.t0,n.t1,o,` to `)}, ${a3(n.rec)} of it recorded${r>1?`; ${s3(r)} in all, ${a3(m)} recorded`:``}.`}}if(a){let e=a.per===`day`?`${i3(a.b*7)}${d} a week`:`${i3(a.b)}${d} a day`,t=`over ${c3(a.days,`day`)}${a.per===`day`?``:`, ${c3(a.n,a.per)}`}`;return{...l,status:`Drifting`,since:a.points[0]?.t??null,found:`${a.past?`Offset ${i3(a.vNow)}${d} against the golden, past the band edge (${$4(a.edge)}${d}); drifting ${e} ${t}.`:`Offset drifting ${e} against the golden ${t}; reaches the band edge (${$4(a.edge)}${d}) around ${h3(a.cross,o)}.`} Check calibration or the process.`}}let g=[];c&&g.push({since:c.t,text:`Offset against the golden moved by ${i3(c.d)}${d} on ${h3(c.t,o)} and stayed there: a change, not a drift.`});let _=x4(u.map(e=>e.h.rateHz).filter(e=>e>0));if(u.length>=4){let e=u[u.length-1],t=u.slice(0,-1).map(e=>e.h.noise).filter(e=>e>0),n=x4(t);t.length>=3&&n>0&&e.h.noise/n>=1.3&&C4(e.h.noise,t)>=3&&g.push({text:`Noise up ${X4(e.h.noise/n-1)}. Check the cable and its shielding.`,since:e.r.t0})}let v=u.reduce((e,t)=>e+t.h.n,0),y=u.reduce((e,t)=>e+t.h.spikes,0);v&&y/v>=1e-4&&g.push({text:`${c3(y,`spike`)}.`,since:Math.min(...u.flatMap(e=>e.h.spikeAt))});let b=u.reduce((e,t)=>e+(t.r.t1-t.r.t0),0),x=u.reduce((e,t)=>e+t.h.gapS,0),S=u.reduce((e,t)=>e+t.h.gaps,0);b>0&&x/b>=.01&&g.push({text:`${a3(x)} of gaps in ${c3(S,`place`)}.`,since:u.find(e=>e.h.gaps).r.t0});let C=u.find(e=>e.h.rateHz>0&&e.h.rateHz<.9*_);if(C&&g.push({text:`Rate dropped from ${$4(_)} Hz to ${$4(C.h.rateHz)} Hz on ${h3(C.r.t0,o)}.`,since:C.r.t0}),u.length>=3){let e=N6(u.map(e=>e.h)),t=e?.lo??0,n=e?.hi??0,r=1e-9*Math.max(1,Math.abs(t),Math.abs(n)),i=e?u.find(e=>e.h.min<t-r||e.h.max>n+r):void 0;if(i){let[a,o,s]=n3(i.h.max>n+r?i.h.max:i.h.min,t,n);g.push({since:i.r.t0,text:`Read ${a}${d}, outside the usual ${o} to ${s}${d} learned from the first ${c3(e.n,`recording`)}.`})}}return g.length?{...l,status:`Watch`,found:g.map(e=>e.text).join(` `),since:Math.min(...g.map(e=>e.since)),...c&&g.length===1?{step:c}:{}}:{...l,status:`Healthy`,found:`No gaps or spikes worth a look, rate steady at ${$4(_)} Hz.`,since:null}}function B6(e,t){let n=e.streams.length>1;return[...m4(t,e=>e.c.streamId)].flatMap(([t,r])=>{let i=V6(e,r);return i?[{...i,text:n?`${e.streams.find(e=>e.id===t)?.name??t}: ${d3(i.text)}`:i.text}]:[]}).sort((e,t)=>(e.p??1)-(t.p??1))[0]??null}function V6(e,t){let n=t.filter(e=>e.c.tend!==null).map(e=>({t:e.c.tstart,v:e.c.tend-e.c.tstart}));if(n.length<30)return null;let r=x4(n.map(e=>e.v)),i=n[0].t,a=h4(n.map(e=>({t:e.t,v:e.v/r*100})),i),o=r>0&&a.length>=7?L4(a.map(e=>(e.t-i)/(7*F6)),a.map(e=>e.v)):null,s=o&&o.p<.01&&o.b>0&&!L6(a,o)?o.b:null,c=t.map(e=>e.c.value),l=Math.floor(c.length/3),u=c.slice(0,l),d=c.slice(c.length-l),f=S4(u),p=f>0?S4(d)/f:NaN,m=null;if(Number.isFinite(p)&&p>=1.15){let e=B4(1),t=Math.min(l,V4),n=Math.sqrt(t/l),r=n=>S4(Array.from({length:t},()=>n[Math.floor(e()*n.length)])),i=0,a=0;for(let e=0;e<1e3;e++){let e=r(u),t=r(d);e>0&&(a++,p+(t/e-p)*n<=1&&i++)}m=a?(i+1)/(a+1):1}let h=m!==null&&m<.01?p-1:null;if(s===null&&h===null)return null;let g=[...s===null?[]:[`cycle time grows ${$4(s)}% a week since ${h3(i,e.tz)}`],...h===null?[]:[`the spread of ${e.value.label} is up ${X4(h)}`]];return{text:`${u3(g.join(` and `))}.${g.length===2?` Together they are consistent with wear.`:` Consistent with wear.`}`,p:Math.min(s===null?1:o.p,h===null?1:m),grow:s,spread:h}}var H6=e=>new Set(e.recordings.flatMap(e=>Object.entries(e.health?.channels??{}).filter(([,e])=>e.clock).map(([e])=>e)));function U6(e){let t=new Map;for(let n of e.recordings)for(let[e,r]of Object.entries(n.health?.channels??{}))r.moves&&t.set(e,(t.get(e)??!0)&&r.counter===!0);return new Set([...t].filter(([,e])=>e).map(([e])=>e))}function W6(e,t){let n=e.recordings.filter(e=>e.health).sort((e,t)=>e.t0-t.t0),r=new Map,i=y6(e.context??$3()),a=H6(e);for(let e of Object.keys(i.channels))[`setting`,`ignore`].includes(e6(i.channels[e])??``)&&a.add(e);for(let t of U6(e))a.add(t);let o=new Map([...m4(e.cycles,e=>e.streamId)].map(([e,t])=>[e,t.map(e=>e.tstart).sort((e,t)=>e-t)]));for(let e of n)for(let t of Object.keys(e.health.channels))a.has(t)||r.set(`${e.streamId}\u0000${t}`,{sid:e.streamId,key:t});for(let e of t)for(let t of Object.keys(e.c.d??{}))a.has(t)||r.set(`${e.c.streamId}\u0000${t}`,{sid:e.c.streamId,key:t});let s=e.streams.length>1,c=m4(t,e=>e.c.streamId),l=(t,n)=>s?`${e.streams.find(e=>e.id===t)?.name??t} · ${n}`:n,u={Replace:0,Drifting:1,Watch:2,Healthy:3},d=[...r.values()].map(({sid:e,key:t})=>I6(c.get(e)??[],t)),f=F4(d.flatMap(e=>e?[e.fit.p]:[]),c4),p=0,m=d.map(e=>!!e&&f[p++]);return[...r.values()].map(({sid:t,key:r},i)=>{let a=l(t,r),s=d[i],c=s&&m[i]?s.step:null;return z6(a,t,r,n.filter(e=>e.streamId===t),e.units[r]??``,s&&m[i]&&!c?R6(a,r,s,e.period.to):null,e.tz,o.get(t),c)}).filter(e=>!!e).sort((e,t)=>u[e.status]-u[t.status]||(e.drift&&t.drift?e.drift.cross-t.drift.cross:0)||e.ch.localeCompare(t.ch))}function G6(e,t){let n=W6(e,t),r=[],i=[],a=[],o=[],s=new Map,c=e.streams.length>1,l=t=>e.streams.find(e=>e.id===t)?.name??t,u=[...m4(n.filter(e=>e.status===`Drifting`),e=>e.sid).values()].filter(e=>e.length>1),d=new Set(u.flat()),f=[...m4(n.filter(e=>e.step),t=>`${t.sid}\u0000${h3(t.step.t,e.tz)}`).values()].filter(e=>e.length>1),p=new Set(f.flat());for(let t of n){let n=`F05-${r.length+1}`;if((t.status===`Replace`||t.status===`Drifting`)&&s.set(t,n),t.status===`Replace`)r.push({id:n,section:`05`,refs:[`05`],evidence:`measured`,p:null,numbers:{},text:`${t.ch}: ${t.found}`}),i.push({text:`Replace or repair ${t.ch}: ${d3(t.found)}`,owner:`maintenance`,urgent:!0,rank:1,refs:[n]});else if(t.status===`Drifting`){let a=t.drift;r.push({id:n,section:`05`,refs:[`05`],evidence:`statistical`,p:a.p,text:`${t.ch}: ${t.found}`,numbers:p4({perWeek:a.b*7,edge:a.edge,cross:a.cross,lo:a.lo,hi:a.hi??NaN,days:a.days,points:a.n,p:a.p})}),d.has(t)||i.push({text:`${t.ch} offset drifting: check calibration or the process ${a.past?`now`:`before ${h3(a.cross,e.tz)}`}.`,owner:`maintenance`,urgent:a.past||a.cross-e.period.to<30*F6,rank:.5,refs:[n]})}}let m=e=>e.map(e=>e.drift).sort((e,t)=>t.past-+e.past||e.cross-t.cross)[0];for(let t of u){let n=m(t);i.push({text:`${c?`${l(t[0].sid)}: `:``}${l3(t.map(e=>e.key))} drift together against the golden, which points to the process (wear, a setting) rather than to ${t.length} sensors. Check it ${n.past?`now`:`before ${h3(n.cross,e.tz)}`}.`,owner:`maintenance`,urgent:n.past||n.cross-e.period.to<30*F6,rank:.5,refs:t.map(e=>s.get(e))})}let h=n.filter(e=>e.status===`Drifting`).map(e=>e.ch);h.length&&a.push(`Run the report again after checking ${l3(h)} to confirm the ${h.length===1?`offset is`:`offsets are`} gone.`);let g=t=>({cells:[t.ch,t.status,t.found,t.since===null?`–`:h3(t.since,e.tz)],status:t.status===`Replace`?`crit`:`watch`,...s.has(t)?{finding:s.get(t)}:{}}),_=t=>{let n=t=>e.units[t.key]?` ${e.units[t.key]}`:``,r=h3(t[0].step.t,e.tz);return{cells:[`${c?`${l(t[0].sid)} · `:``}${c3(t.length,`channel`)}`,`Watch`,`Offsets against the golden moved on ${r} and stayed there (${t.map(e=>`${e.key} ${i3(e.step.d)}${n(e)}`).join(`, `)}): one change of the process, not ${t.length} sensors.`,r],status:`watch`}},v=n.filter(e=>e.status!==`Healthy`),y=n.length-v.length;v.length&&o.push({kind:`table`,columns:[`Sensor`,`Status`,`What was found`,`Since`],rows:[...v.filter(e=>!p.has(e)).map(g),...f.map(_)],title:`05.1 · Sensors that need a look${y?`; the other ${y} ${y===1?`is`:`are`} healthy`:``}`});let b=n.flatMap(e=>e.drift?[e.drift]:[]).sort((e,t)=>e.cross-t.cross)[0];b&&o.push({kind:`trend`,title:`05.2 · Drift forecast, ${b.ch}: its offset against the golden per ${b.per}, forecast to the band edge`,unit:e.units[b.key]??``,points:b.points,line:b.line,limit:Math.sign(b.b)*b.edge,crossing:b.past?null:{t:b.cross,lo:b.lo,hi:b.hi}});let x=B6(e,t);if(x){let e=`F05-${r.length+1}`;r.push({id:e,section:`05`,refs:[`05`],evidence:`statistical`,p:x.p,text:x.text,numbers:p4({growPerWeek:x.grow??NaN,spreadUp:x.spread??NaN})}),i.push({text:`Inspect the machine for wear: ${d3(x.text)}`,owner:`maintenance`,urgent:!1,rank:.3,refs:[e]})}let S=e=>n.filter(t=>t.status===e).length,C=S(`Watch`)-p.size+f.length,w=u.length===1&&u[0].length===S(`Drifting`),T=[S(`Replace`)?`${c3(S(`Replace`),`sensor`)} to replace`:``,S(`Drifting`)?`${S(`Drifting`)} drifting${w?` together${c?` on ${l(u[0][0].sid)}`:``}`:``}`:``,C?`${C} to watch`:``].filter(Boolean);return{out:{section:{...Y4(`05`,n.length?`${T.length?u3(l3(T)):`All ${c3(n.length,`sensor`)} healthy`}${x?`, and signs of machine wear`:``}.`:`No sensor health was measured in this period.`,r,o),subtitle:J4(`Reliability data (ISO 14224 style)`),fold:!0},actions:i,next:a,numbers:{replace:S(`Replace`),drifting:S(`Drifting`),watch:C}},sensors:n,drifts:[...n.filter(e=>e.status===`Drifting`&&!d.has(e)).map(e=>e.drift),...u.map(e=>({...m(e),work:`Check the process${c?` on ${l(e[0].sid)}`:``} (${c3(e.length,`channel`)} drifting together)`}))],wear:x}}var K6=.0027,q6=240,J6=60,Y6=new Set([`mean`,`min`,`max`,`first`,`last`]),X6=(e,t)=>e.length<=t?e:Array.from({length:t},(n,r)=>e[Math.round(r*(e.length-1)/(t-1))]);function Z6(e,t){let n=e.context,r=new Set([...U6(e),...H6(e)]),i=e=>{let t=e.lastIndexOf(`:`),i=e.slice(0,t),a=e6(n?.channels[i]);return t>0&&Y6.has(e.slice(t+1))&&!r.has(i)&&a!==`setting`&&a!==`ignore`&&a!==`energy`},a=e.streams.length>1,o=[];for(let[e,n]of m4(t,e=>e.c.streamId)){let t=n.map(e=>e.c).sort((e,t)=>e.tstart-t.tstart);for(let n of[...new Set(t.flatMap(e=>Object.keys(e.kpis)))].filter(i)){let r=t.flatMap(e=>{let t=e.kpis[n];return _4(t)?[{t:e.tstart,v:t}]:[]});if(r.length<30)continue;let i=r.reduce((e,t)=>e+t.v,0)/r.length,a=r.slice(1).reduce((e,t,n)=>e+Math.abs(t.v-r[n].v),0)/(r.length-1)/1.128;if(!(a>0))continue;let s=i+3*a,c=i-3*a,l=r.map(e=>({...e,out:e.v>s||e.v<c})),u=l.filter(e=>e.out).length;u>=1&&u>2*.0027*r.length&&o.push({key:n,sid:e,n:r.length,out:u,mean:i,ucl:s,lcl:c,pts:l})}}if(!o.length)return null;o.sort((e,t)=>t.out/t.n-e.out/e.n||t.out-e.out);let s=t=>`${C3(t.key)}${a?` on ${e.streams.find(e=>e.id===t.sid)?.name??`one stream`}`:``}`,c=t=>{let n=e.units[t.key.slice(0,t.key.lastIndexOf(`:`))];return n?` ${n}`:``},l=o[0],u=o.slice(0,3),d=e=>`F04-S${e+1}`,f=l.pts.length<=q6?l.pts:X6(l.pts,q6-J6),p=new Set(f),m=l.pts.length<=q6?[]:X6(l.pts.filter(e=>e.out&&!p.has(e)),J6);return{charts:[{kind:`control`,title:`04.3 · Control chart, ${s(l)}: each batch against the limits of its own variation (mean ± 3σ)`,unit:c(l).trim(),mean:l.mean,ucl:l.ucl,lcl:l.lcl,n:l.n,outside:l.out,points:[...f,...m].sort((e,t)=>e.t-t.t).map(e=>({t:e.t,v:e.v,...e.out?{out:!0}:{}}))}],findings:u.map((t,n)=>({id:d(n),section:`04`,refs:[`04`],evidence:`measured`,p:null,numbers:{outside:t.out,n:t.n,mean:t.mean,ucl:t.ucl,lcl:t.lcl},text:`${s(t)}: ${c3(t.out,`batch`,`batches`)} of ${t.n.toLocaleString(`en-GB`)} (${Z4(100*t.out/t.n)}) outside its control limits, ${$4(t.lcl)} to ${$4(t.ucl)}${c(t)}, the first on ${h3(t.pts.find(e=>e.out).t,e.tz)}. The process moved; with no specification limits, nothing says these batches are bad.`})),actions:[{text:`Find what moved ${s(l)}: ${c3(l.out,`batch`,`batches`)} outside its control limits. Add its specification limits in Process context to know which batches are bad.`,owner:`quality`,urgent:!1,rank:Math.min(1,l.out/l.n),refs:[d(0)]}],notes:[],next:[]}}function Q6(e,t){let n=0,r=e.length;for(;n<r;){let i=n+r>>1;e[i].c.tstart<t?n=i+1:r=i}return n}function $6(e,t){let n=y6(e.context??$3()),r=e.tz,{from:i,to:a}=e.period,o=Object.keys(n.channels).filter(e=>e6(n.channels[e])===`setting`),s=(e.goldenChanges??[]).filter(e=>e.t>=i&&e.t<a);if(!o.length&&!s.length)return{section:`08`,needs:`Mark which channels are adjustable settings in Process context to see their changes.`};let c=e.streams.length>1,l=t=>e.streams.find(e=>e.id===t)?.name??t,u=(e,t)=>c?`${l(e)} · ${t}`:t,d=[];for(let[t,n]of m4(e.recordings.filter(e=>e.health).sort((e,t)=>e.t0-t.t0),e=>e.streamId))for(let e of o){let r=n.flatMap(t=>t.health.channels[e]?[t.health.channels[e]]:[]),o=r.flatMap(e=>e.flats).sort((e,t)=>e.t0-t.t0),s=Math.max(3*x4(r.map(e=>e.noise)),1e-9);o.forEach((n,r)=>{let c=o[r-1];c&&Math.abs(n.value-c.value)>s&&n.t0>=i&&n.t0<a&&d.push({sid:t,ch:u(t,e),t:n.t0,a:c.value,b:n.value})})}if(!d.length&&!s.length)return null;let f=new Map([...m4(t,e=>e.c.streamId)].map(([e,t])=>[e,t.slice().sort((e,t)=>e.c.tstart-t.c.tstart)])),p=d.map(t=>{let n=f.get(t.sid)??[],r=Q6(n,t.t),i=n.slice(Math.max(0,r-20),r).map(e=>e.c.value),a=n.slice(r,r+20).map(e=>e.c.value),o=i.length>=5&&a.length>=5,s=x4(i),c=x4(a),l=o?E4(a,i):{p:1,effect:.5};return{...t,enough:o,mb:s,ma:c,p:l.p,worse:e.value.better===`min`?l.effect>.5:l.effect<.5}}),m=F4(p.map(e=>e.enough?e.p:1),c4),h=[],g=[],_=new Map,v=e.value.label;p.forEach((e,t)=>{if(!e.enough||!m[t])return;let n=`F08-${h.length+1}`,i=g3(e.t,r),[a,o]=t3(e.a,e.b),[s,c]=t3(e.mb,e.ma);_.set(t,n),h.push({id:n,section:`08`,refs:[`08`],evidence:`statistical`,p:e.p,numbers:p4({from:e.a,to:e.b,before:e.mb,after:e.ma,p:e.p}),text:`${e.ch} was changed from ${a} to ${o} on ${i}; ${s===c?`${v} moved ${e.worse?`worse`:`better`} afterwards (median ${s} both times)`:`${v} went from ${s} to ${c} afterwards (${e.worse?`worse`:`better`})`}.`}),e.worse&&g.push({text:`Review the ${e.ch} change of ${i}: ${v} has been worse since.`,owner:`production`,urgent:!1,rank:Math.min(1,Math.abs(e.ma-e.mb)/(Math.abs(e.mb)||1)),refs:[n]})});let y=[...p.map((e,t)=>{let[n,i]=t3(e.a,e.b);return{t:e.t,row:{cells:[g3(e.t,r),e.ch,n,i,e.enough?`${i3(e.ma-e.mb)} (${w3(e.p)})`:`Too few batches to tell`],..._.has(t)?{finding:_.get(t),...e.worse?{status:`watch`}:{}}:{}}}}),...s.map(e=>({t:e.t,row:{cells:[g3(e.t,r),c?`${l(e.streamId)} · Golden`:`Golden`,`–`,e.label,`–`]}}))].sort((e,t)=>e.t-t.t).map(e=>e.row),b=s.map(e=>`The golden changed on ${g3(e.t,r)}; every batch in this report is judged against the current one.`);return{section:Y4(`08`,h.length?`${c3(d.length,`setting change`)} in the period; ${h.length} ${h.length===1?`was`:`were`} followed by a different ${v}.`:d.length?`${c3(d.length,`setting change`)} in the period, none followed by a clear difference in ${v}.`:b[0],h,[{kind:`table`,title:`08.1 · Changes of settings`,columns:[`When`,`Setting`,`From`,`To`,`Effect on ${v}`],rows:y}],b),actions:g,next:[],numbers:{changes:d.length,goldens:s.length}}}function e8(e,t,n=W6(e,t)){let r=new Map([...m4(t,e=>e.c.streamId)].map(([e,t])=>[e,t.slice().sort((e,t)=>e.c.tstart-t.c.tstart)])),i=(e,t,n)=>{let i=r.get(e)??[],a=Q6(i,n);for(;a<i.length&&i[a].c.tstart===n;)a++;return i.slice(Q6(i,t),a)},a=m4(n.filter(e=>e.status===`Drifting`),e=>e.sid),o=e=>e.status===`Drifting`&&(a.get(e.sid)?.length??0)>1,s=n.filter(t=>e.goldens.some(e=>e.streamId===t.sid&&t.key in e.edges)&&!o(t)).flatMap(t=>(t.status===`Replace`?t.stuck.map(e=>({...e,stuck:!0})):t.drift?.past?[{t0:Math.max(t.drift.cross,e.period.from),t1:e.period.to,stuck:!1}]:[]).map(e=>({s:t,...e,xs:i(t.sid,e.t0,e.t1)}))).filter(e=>e.xs.length).sort((e,t)=>t.xs.length-e.xs.length||e.t0-t.t0).slice(0,10);if(!s.length)return null;let c=e.tz,l=e=>`F04-C${e+1}`;return{charts:[{kind:`table`,title:`04.2 · Batches made while a sensor was failing`,columns:[`Sensor`,`From`,`To`,`Batches`,`Of them off-golden`],rows:s.map((e,t)=>({cells:[e.s.ch,g3(e.t0,c),g3(e.xs[e.xs.length-1].c.tstart,c),String(e.xs.length),String(e.xs.filter(e=>e.level===`off`).length)],status:e.stuck?`crit`:`watch`,finding:l(t)}))}],findings:s.map((e,t)=>({id:l(t),section:`04`,refs:[`04`,`05`],evidence:`measured`,p:null,numbers:{batches:e.xs.length,off:e.xs.filter(e=>e.level===`off`).length,seconds:e.xs.reduce((e,t)=>e+Math.max(0,(t.c.tend??t.c.tstart)-t.c.tstart),0)},text:`${c3(e.xs.length,`batch`,`batches`)} ${e.xs.length===1?`was`:`were`} made while ${e.s.ch} `+(e.stuck?`was stuck (from ${v3(e.t0,e.t1,c,` to `)}): their ${e.s.ch} readings can't be trusted. Check them before they ship.`:`read beyond its band (the sensor or the process), from ${v3(e.t0,e.t1,c,` to `)}. Check them before they ship.`)})),actions:s.map((e,t)=>({text:`Check the ${c3(e.xs.length,`batch`,`batches`)} made while ${e.s.ch} ${e.stuck?`was stuck`:`read beyond its band`} before they ship.`,owner:`quality`,urgent:e.stuck,rank:1,refs:[l(t)]})),notes:[],next:[]}}var t8={Wh:.001,kWh:1,MWh:1e3},n8=`Scope 2, location-based, factor entered by you`;function r8(e,t){let n=t8[(e.context?.channels[t]?.unit??``).trim()],r=n?e.recordings.flatMap(e=>{let n=e.health?.channels[t];return n?.counter?[n]:[]}):[];return r.length?r.reduce((e,t)=>e+(t.max-t.min)*n,0):null}function i8(e,t){let n=e.context,r=t6(n);if(!n||!r)return null;let i=t.filter(e=>_4(e.c.kwh)&&e.c.kwh>=0);if(i.length<5)return{section:`09`,needs:`09 · ${r} has ${i.length?`energy in only ${i.length} of`:`no energy in`} this period’s batches: check it is recorded and its unit in Process context is kW, W, MW, kWh, Wh or MWh.`};let a=n.costs.kwh,o=n.costs.currency,s=n.costs.co2,c=i.map(e=>e.c.kwh),l=x4(c),u=c.reduce((e,t)=>e+t,0),d=r8(e,r),f=d!==null&&d>=u?d:u,p=[],m=[],h=(e.previous?.cycles??[]).map(e=>e.kwh).filter(e=>_4(e)&&e>=0),g=h.length>=5?x4(h):NaN,[_,v]=t3(l,g),y=(l-g)/g*100,b=Math.abs(y)>=10?Math.round(y):+y.toFixed(1),x=Number.isFinite(g)?_===v||!b?`, as the period before`:`, against ${v} the period before (${i3(b)}%)`:``,S=[...a===null?[]:[Q4(l*a,o)],...s===null?[]:[`${$4(l*s)} kg CO₂ (${n8})`]];p.push({id:`F09-1`,section:`09`,refs:[`09`],evidence:`measured`,p:null,numbers:p4({kwh:l,before:g,cost:a===null?NaN:l*a,co2:s===null?NaN:l*s,total:f,inBatches:u}),text:`A batch uses ${_} kWh (median)${x}${S.length?`: ${S.join(` and `)}`:``}; ${$4(f)} kWh in the period${f>u?`, ${$4(u)} of them while a batch ran`:``}.`});let C=i.filter(e=>e.level===`off`).map(e=>e.c.kwh),w=i.filter(e=>e.level!==`off`).map(e=>e.c.kwh),T=!1,E=[],D=e=>a===null?``:` (${Q4(e*a,o)})`;if(f>u&&E.push({kind:`bars`,title:`09.1 · Where the period’s energy goes${a===null?``:`, and what it costs`}`,max:Math.max(u,f-u),rows:[{label:`While a batch runs`,kwh:u},{label:`Between batches, in stops and breaks`,kwh:f-u}].sort((e,t)=>t.kwh-e.kwh).map(e=>({label:e.label,value:e.kwh,text:`${$4(e.kwh)} kWh${D(e.kwh)}`,tip:`${e.label}: ${X4(e.kwh/f)} of the period’s energy`}))}),C.length>=5&&w.length>=5){let e=x4(C),t=x4(w),n=E4(C,w);if(n.p<.01&&e>t&&t>0){T=!0;let r=(e-t)*C.length,[s,c]=t3(e,t);E.push({kind:`bars`,title:`09.2 · Energy per batch: off-golden batches against the rest (median)`,max:e,rows:[{label:`Off-golden batches`,value:e,text:`${s} kWh`,tip:`Off-golden batches: ${s} kWh a batch (median of ${C.length.toLocaleString(`en-GB`)})`},{label:`At golden level or better`,value:t,text:`${c} kWh`,muted:!0,tip:`At golden level or better: ${c} kWh a batch (median of ${w.length.toLocaleString(`en-GB`)})`}]}),p.push({id:`F09-2`,section:`09`,refs:[`09`],evidence:`statistical`,p:n.p,numbers:p4({off:e,rest:t,extra:r,p:n.p}),text:`Off-golden batches use ${Z4((e-t)/t*100)} more energy than the rest: ${$4(r)} kWh${a===null?``:`, up to ${Q4(r*a,o)}`}, in the period.`}),m.push({text:`Bring off-golden batches to golden level (see 02) to save up to ${$4(r)} kWh${a===null?``:` (${Q4(r*a,o)})`} in a period like this one.`,owner:`production`,urgent:!1,rank:(e-t)/t*(C.length/i.length),refs:[`F09-2`]})}}return{section:{...Y4(`09`,`${a===null?`${$4(f)} kWh`:`${Q4(f*a,o)} of energy`} in the period${T?`; off-golden batches use more`:``}.`,p,E),subtitle:J4(`Energy review inputs (ISO 50001)`),fold:!0},actions:m,next:[],numbers:{kwh:l}}}var a8=1800,o8=2400,s8=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`],c8=[`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`,`Sunday`],l8=e=>`${String(e%24).padStart(2,`0`)}:00`,u8=(e,t)=>e.c.z?.[t.ch]?.[t.piece];function d8(e){let t=new Map;for(let n of e)for(let[e,r]of Object.entries(n.c.z))for(let n of Object.keys(r)){let r=`${e}\u0000${n}`;t.set(r,(t.get(r)??0)+1)}let n=[...t].filter(([,t])=>t>=.8*e.length).map(([e])=>e.split(`\0`)).sort(),r=new Set(n.filter(([,e])=>e!==`Cycle`).map(([e])=>e));return n.filter(([e,t])=>t!==`Cycle`||!r.has(e)).map(([e,t])=>({ch:e,piece:t,label:t===`Cycle`?e:`${e} · ${t}`}))}function f8(e,t){let n=z4(e,t);if(!n)return null;let r=n.shares.map(e=>Math.max(0,e)),i=r.reduce((e,t)=>e+t,0);return{shares:r.map(e=>i>0?e/i*n.r2:0),r2:n.r2}}function p8(e,t){let n=[],r=[],i=[],a=[],o=new Map,s=(e,t)=>{let r=`F02-${n.length+1}`;return n.push({id:r,section:`02`,refs:[`02`],...e}),o.set(r,t),r},c=t.filter(e=>e.level===`off`),l=e=>e.filter(e=>e.level===`off`).length,u=t.filter(e=>e.c.z),d=u.filter(e=>e.level===`off`),f=u.filter(e=>e.level!==`off`),p=null;if(d.length>=5&&f.length>=5){let e=d8(u).map(e=>{let t=u.filter(t=>_4(u8(t,e)));return{f:e,mw:E4(d.map(t=>u8(t,e)).filter(_4),f.map(t=>u8(t,e)).filter(_4)),r:I4(t.map(t=>u8(t,e)),t.map(e=>e.gap))}}),t=F4(e.map(e=>e.mw.p),c4),n=e.filter((e,n)=>t[n]&&e.mw.effect>.5&&e.r>0).sort((e,t)=>t.r-e.r).slice(0,8),o=u.filter(e=>n.every(t=>_4(u8(e,t.f)))),c=o.map(e=>n.map(t=>u8(e,t.f))),l=o.map(e=>e.gap),m=n.length?f8(c,l):null;if(m){let e=m.shares.map((e,t)=>t).sort((e,t)=>m.shares[t]-m.shares[e]),t=e[0],u=n[t],f=H4(o.length,e=>f8(e.map(e=>c[e]),e.map(e=>l[e]))?.shares[t]??NaN),h=e.filter(e=>m.shares[e]>=.01),g=Math.max(0,1-m.r2);p={label:u.f.label,share:m.shares[t]},a.push({kind:`bars`,title:`02.1 · What goes with batches missing the golden: how much of the difference between batches each one explains (${c3(o.length,`batch`,`batches`)} measured, ${d.length.toLocaleString(`en-GB`)} off-golden)`,max:Math.max(g,...h.map(e=>m.shares[e]))*1.1,rows:[...h.map(e=>({label:n[e].f.label,value:m.shares[e],text:X4(m.shares[e]),tip:`${n[e].f.label} goes with ${X4(m.shares[e])} of the difference in how far batches are from the golden`})),{label:`Not explained by the recorded channels`,value:g,text:X4(g),muted:!0,tip:`Goes with none of the channels recorded: something else changes between batches.`}]});let _=d.reduce((e,t)=>t.gap>e.gap?t:e,d[0]),v=s({focus:{ch:u.f.ch,piece:u.f.piece},..._?{batch:{streamId:_.c.streamId,cycleId:_.c.id}}:{},text:`${u.f.label} goes with ${X4(p.share)} of the difference in how far batches are from the golden${h.length>1?`; the ${h.length} differences together go with ${X4(m.r2)}`:``}.`,evidence:`correlation`,p:u.mw.p,numbers:p4({share:p.share,lo:f.lo,hi:f.hi,r2:m.r2,r:u.r,p:u.mw.p})},p.share);for(let e of h.slice(0,3)){let t=n[e].f;r.push({text:`Test bringing ${t.ch}${t.piece===`Cycle`?``:` in ${t.piece}`} back to the golden: it goes with ${X4(m.shares[e])} of the difference in how far batches are from the golden.`,owner:`production`,urgent:!1,rank:m.shares[e],refs:[v]})}g>=.2&&i.push(`${X4(g)} of the difference in how far batches are from the golden goes with none of the recorded channels. Record what else changes between batches (material lot, ambient temperature, settings) as channels.`)}else i.push(`No recorded channel goes with the batches that miss the golden. Record what else changes between batches (material lot, ambient temperature, settings) as channels.`)}let m=new Set;for(let e of m4(t,e=>e.c.streamId).values()){let t=-1/0;e.forEach((n,r)=>{let i=e[r-1];i&&n.c.tstart-(i.c.tend??i.c.tstart)>1800&&(t=n.c.tstart),n.c.tstart-t<2400&&m.add(n.c.id)})}let h=t.filter(e=>m.has(e.c.id)),g=t.filter(e=>!m.has(e.c.id));if(h.length>=5&&g.length>=5){let e=P4(l(h),h.length,l(g),g.length);if(e.p<.01&&e.p1>e.p2){let n=s({text:`Off-golden share is ${X4(e.p1)} in the first ${o8/60} minutes after a stop of more than ${a8/60} minutes, against ${X4(e.p2)} the rest of the time.`,evidence:`statistical`,p:e.p,numbers:p4({warm:e.p1,rest:e.p2,p:e.p,batches:h.length})},(e.p1-e.p2)*(h.length/t.length));r.push({text:`Warm the line up after stops longer than ${a8/60} minutes: the first ${o8/60} minutes after a stop run ${X4(e.p1)} off-golden against ${X4(e.p2)}.`,owner:`production`,urgent:!1,rank:(e.p1-e.p2)*(h.length/t.length),refs:[n]})}}let _=(e,n,r=t)=>{let i=m4(r,e),a=l(r);if(i.size<2)return null;let o=[...i].filter(([,e])=>e.length>=n&&r.length-e.length>=5).map(([e,t])=>({k:e,n:t.length,t:P4(l(t),t.length,a-l(t),r.length-t.length)})),s=F4(o.map(e=>e.t.p),c4),c=null;return o.forEach((e,t)=>{s[t]&&e.t.p1-e.t.p2>=.05&&(!c||e.t.p1-e.t.p2>c.t.p1-c.t.p2)&&(c=e)}),c},v=_(e=>e.c.streamId,5);v&&s({text:`${e.streams.find(e=>e.id===v.k)?.name??`One stream`} runs ${X4(v.t.p1)} off-golden against ${X4(v.t.p2)} on the other streams.`,evidence:`statistical`,p:v.t.p,numbers:p4({share:v.t.p1,others:v.t.p2,p:v.t.p})},(v.t.p1-v.t.p2)*(v.n/t.length));let y=_(e=>e.c.recordingId,10);y&&s({text:`Recording ${e.recordings.find(e=>e.id===y.k)?.name??`one file`} runs ${X4(y.t.p1)} off-golden against ${X4(y.t.p2)} in the rest of the period.`,evidence:`statistical`,p:y.t.p,numbers:p4({share:y.t.p1,others:y.t.p2,p:y.t.p})},(y.t.p1-y.t.p2)*(y.n/t.length));let b=null;if(t.length>=5){let n=t[0].c.tstart,r=h4(t.map(e=>({t:e.c.tstart,v:e.gap})),n),i=r.length>=7?L4(r.map(e=>(e.t-n)/86400),r.map(e=>e.v)):null;if(i&&i.p<.01&&i.b!==0){let a=o3(e),o=a?` ${a}`:``,c=r[r.length-1].t;s({text:`The gap to the golden ${i.b>0?`grows`:`shrinks`} by ${$4(Math.abs(i.b)*7)}${o} a week since ${h3(n,e.tz)}.`,evidence:`statistical`,p:i.p,numbers:p4({perWeek:i.b*7,days:i.n,p:i.p})},Math.min(1,Math.abs(i.b*(c-n)/86400)/(t.reduce((e,t)=>e+Math.abs(t.gap),0)/t.length||1))),b={kind:`trend`,title:`02.3 · Gap to the golden per day, with its trend`,unit:o.trim(),points:r,line:{t0:n,v0:i.a,t1:c,v1:i.a+i.b*(c-n)/86400},limit:null,crossing:null}}}let x=new Map,S=new Map(t.map(t=>{let n=Math.floor(t.c.tstart/900),r=x.get(n);return r||x.set(n,r=b3(n*900,e.tz)),[t.c.id,r]})),C=_(e=>String(S.get(e.c.id).hour),5),w=_(e=>String(S.get(e.c.id).day),5),T=e.context?.hideShifts?[]:e.context?.shifts??[],E=new Map(T.length?t.map(t=>[t.c.id,g6(t.c.tstart,T,e.tz)]):[]),D=T.length?_(e=>E.get(e.c.id),5,t.filter(e=>E.get(e.c.id)!==null)):null,O=[...C?[{w:C,when:`started between ${l8(+C.k)} and ${l8(+C.k+1)}`,other:`at other hours`,look:`Find what changes around ${l8(+C.k)} (a shift change, a start-up, a material change)`}]:[],...w?[{w,when:`on ${c8[+w.k]}s`,other:`on other days`,look:`Find what is different on ${c8[+w.k]}s (crew, material, maintenance)`}]:[],...D?[{w:D,when:`on the ${D.k} shift`,other:`on the other shifts`,look:`Find what the ${D.k} shift does differently (crew, set-up, material)`}]:[]];for(let{w:e,when:n,other:i,look:a}of O){let o=(e.t.p1-e.t.p2)*(e.n/t.length),c=s({text:`Batches ${n} run ${X4(e.t.p1)} off-golden against ${X4(e.t.p2)} ${i}.`,evidence:`statistical`,p:e.t.p,numbers:p4({share:e.t.p1,others:e.t.p2,p:e.t.p})},o);r.push({text:`${a}: batches then run ${X4(e.t.p1)} off-golden against ${X4(e.t.p2)}.`,owner:`production`,urgent:!1,rank:o,refs:[c]})}if(O.length){let e=s8.map(()=>Array(24).fill(0)),n=s8.map(()=>Array(24).fill(0));for(let r of t){let{day:t,hour:i}=S.get(r.c.id);e[t][i]++,r.level===`off`&&n[t][i]++}a.push({kind:`heat`,title:`02.2 · Off-golden share by hour and weekday. Stronger colour is worse; hours with fewer than 5 batches are left empty.`,rows:s8,cols:Array.from({length:24},(e,t)=>String(t).padStart(2,`0`)),cells:e.map((e,t)=>e.map((e,r)=>e>=5?n[t][r]/e:null)),legend:`off-golden`})}b&&a.push(b);let k=t.length?c.length/t.length:0,A=t.length?c.length?p?`${X4(k)} of batches miss the golden. ${p.label} goes with most of the difference between them and the golden.`:`${X4(k)} of batches miss the golden; no recorded channel goes with the gap yet.`:`Every batch is at golden level or better.`:`No batches with a value to compare against a golden in this period.`;return n.sort((e,t)=>o.get(t.id)-o.get(e.id)),{section:{...Y4(`02`,A,n,a),fold:!0},actions:r,next:i,numbers:{off:c.length,share:k}}}function m8(e,t){let n=(e.context?.lines??[]).filter(e=>e.streams.length);if(n.length<2)return null;let r=new Map(n.flatMap(e=>e.streams.map(t=>[t,e.name]))),i=m4(t.filter(e=>r.has(e.c.streamId)),e=>r.get(e.c.streamId)),a=e=>({section:Y4(`10`,e,[],[]),actions:[],next:[],numbers:{}});if(i.size<2)return a(`${i.size?`Only one line has`:`No line has`} batches in this report: tick the files of the other lines to compare them.`);let o=[...i.values()].flat(),s=o.filter(e=>e.level===`off`).length,c=[...i].map(([e,t])=>{let n=t.filter(e=>e.level===`off`).length;return{name:e,xs:t,better:t.filter(e=>e.level===`better`).length,t:P4(n,t.length,s-n,o.length-t.length)}}),l=F4(c.map(e=>e.t.p),c4),u=e=>e.t.p1>e.t.p2,d=c.filter((e,t)=>l[t]&&e.t.p1!==e.t.p2&&e.xs.length>=5&&o.length-e.xs.length>=5).sort((e,t)=>Number(u(t))-Number(u(e))||Math.abs(t.t.p1-t.t.p2)-Math.abs(e.t.p1-e.t.p2)).slice(0,i.size===2?1:void 0);if(!d.length)return a(`The lines run alike: none misses the golden more often than the others.`);let f=[],p=[],m=new Map;for(let e of d){let t=`F10-${f.length+1}`;m.set(e.name,t),f.push({id:t,section:`10`,refs:[`10`],evidence:`statistical`,p:e.t.p,numbers:p4({share:e.t.p1,others:e.t.p2,p:e.t.p,batches:e.xs.length}),text:`${e.name} runs ${X4(e.t.p1)} off-golden against ${X4(e.t.p2)} on the other lines.`}),u(e)&&p.push({text:`Find what ${e.name} does differently from the other lines: it runs ${X4(e.t.p1)} off-golden against ${X4(e.t.p2)}.`,owner:`production`,urgent:!1,rank:(e.t.p1-e.t.p2)*(e.xs.length/o.length),refs:[t]})}let h=[{kind:`table`,title:`10.1 · The lines side by side`,columns:[`Line`,`Batches`,`At golden level or better`,`Better than the golden`],rows:c.map(e=>{let t=m.get(e.name);return{cells:[e.name,e.xs.length.toLocaleString(`en-GB`),X4(1-e.t.p1),X4(e.better/e.xs.length)],...t?{finding:t,status:u(e)?`crit`:`ok`}:{}}})}],g=d.filter(u),_=e=>l3(e.slice(0,2).map(e=>e.name))+(e.length>2?` and ${c3(e.length-2,`more line`)}`:``);return{section:Y4(`10`,g.length?`${_(g)} ${g.length>1?`miss`:`misses`} the golden more often than the other lines.`:`${_(d)} ${d.length>1?`miss`:`misses`} the golden less often than the other lines.`,f,h),actions:p,next:[],numbers:{lines:i.size}}}function h8(e,t){let n=y6(e.context??$3()).costs,r=n.lineHour,i=n.currency,a=r!==null,o=e=>a?e/3600*r:e/3600,s=e=>e.s>=60&&(!a||o(e.s)>=1),c=new Map,l=t.time.filter(e=>!e.bad&&s(e)).map(e=>{let t={label:e.label,value:o(e.s),owner:e.owner,ref:e.ref,amount:a?Q4(o(e.s),i):a3(e.s),detail:a?`${a3(e.s)} of line time`:`of line time`};return c.set(t,e.s),t}),u=t.energyKwh!==null&&t.energyKwh>0&&n.kwh!==null?t.energyKwh*n.kwh:0;u>=1&&l.push({label:`Extra energy of off-golden batches`,value:a?u:null,owner:`Production`,ref:`09`,amount:Q4(u,i),detail:`${$4(t.energyKwh)} kWh more than batches at golden level`});let d=n.scrap,f=d===null?``:`${Q4(d,i)} a scrapped batch`,p=t.scrap&&d!==null&&t.scrap.batches*d>=1?{...t.scrap,money:t.scrap.batches*d}:null,m=t.time.filter(e=>e.bad&&s(e)).reduce((e,t)=>e+t.s,0),h=p&&!p.assumed?p.money:0;if(m||h){let e=t.scrap&&!t.scrap.assumed?c3(t.scrap.batches,`batch`,`batches`):`Batches`,n={label:`Bad parts`,value:a?o(m)+h:m?o(m):null,owner:`Quality`,ref:`04`,amount:a?Q4(o(m)+h,i):m?a3(m):Q4(h,i),detail:`${e} outside their limits or flagged bad: ${[m?`${a3(m)} of line time`:``,h?`${Q4(h,i)} scrapped material`:``].filter(Boolean).join(` + `)}`};l.push(n),c.set(n,m)}let g=l.reduce((e,t)=>e+(t.value??0),0),_=l.filter(e=>!a||e.value>=.005*g).sort((e,t)=>(t.value??-1)-(e.value??-1)),v=_.reduce((e,t)=>e+(c.get(t)??0),0);if(p?.assumed&&_.push({label:`Off-golden batches, if scrapped`,value:null,owner:`Quality`,ref:`02`,assumed:!0,amount:`up to ${Q4(p.money,i)}`,detail:`${c3(p.batches,`off-golden batch`,`off-golden batches`)} at ${f}; no specification limits say which are scrap`}),t.review&&t.review.batches>0){let e=c3(t.review.batches,`batch`,`batches`);_.push(d===null?{label:`Batches to check before they ship`,value:o(t.review.s),owner:`Quality`,ref:`04`,atRisk:!0,amount:a?`up to ${Q4(o(t.review.s),i)}`:e,detail:`${a?`${e}, `:``}${a3(t.review.s)} of production at risk: made while a sensor was failing`}:{label:`Batches to check before they ship`,value:a?t.review.batches*d:null,owner:`Quality`,ref:`04`,atRisk:!0,amount:`up to ${Q4(t.review.batches*d,i)}`,detail:`${e} at ${f}, at risk: made while a sensor was failing`})}if(!_.length)return null;let y=_.reduce((e,t)=>e+(t.atRisk||t.assumed?0:t.value??0),0),b=_.some(e=>!e.atRisk&&!e.assumed),x=d===null&&t.scrap&&!t.scrap.assumed?t.scrap.batches:0,S=a?x?`Add the cost of a scrapped batch to see what the ${c3(x,`batch`,`batches`)} off specification cost`:null:`Add the cost of an hour of line time to see this in money`;return{kind:`losses`,unit:a?`money`:`hours`,title:`00.1 · Where the ${a?`money`:`time`} goes`,rows:_,total:b?a?`Up to ${Q4(y,i)}`:v?a3(v):_[0].amount:`Nothing lost`,totalNote:b?a?`to recover in this period${v?`: ${a3(v)} of line time`:``}`:`of line time to recover in this period`:`against the golden in this period`,...S?{hint:S}:{}}}var g8=86400;function _8(e,t,n){if(!t.length&&!n)return null;let r=y6(e.context??$3()),i=e.tz,a=e.period.to,o=r.stops.length?v6(r,i,a,a+90*g8).map(e=>e.t0).filter(e=>e>a).sort((e,t)=>e-t):null,s=e=>{if(!o)return`No planned stop set`;let t=e===null?o[0]:o.filter(t=>t<e).pop();return t===void 0?`None before it`:x3(t,i)},c=[...t.map(e=>{let t=e.past||e.lo<=a;return{work:e.work??`Recalibrate ${e.ch}`,by:t?null:e.lo,now:t}}),...n?[{work:`Inspect the machine for wear (${n.grow===null?`spread of ${e.value.label} up ${X4(n.spread)}`:`cycle time ${i3(n.grow)}% a week`})`,by:null,now:!1}]:[]].sort((e,t)=>t.now-+e.now||(e.by??1/0)-(t.by??1/0)),l=c[0],u=c.find(e=>e.by!==null);return{charts:[{kind:`table`,title:`05.5 · Maintenance to plan`,columns:[`Work`,`By`,`Next planned stop before it`],rows:c.map(e=>({cells:[e.work,e.now?`Now`:e.by===null?`–`:h3(e.by,i),s(e.by)],...e.now?{status:`crit`}:{}}))}],findings:[{id:`F05-M1`,section:`05`,refs:[`05`],evidence:`measured`,p:null,numbers:{jobs:c.length,...u&&!l.now?{first:u.by}:{}},text:`Plan ${c3(c.length,`maintenance job`)}${l.now?`: the first now`:u?`: the first by ${h3(u.by,i)}`:``}.`}],actions:[],notes:[],next:o?[]:[`Add planned stops in Process context to place maintenance in them.`]}}var v8=()=>({findings:[],charts:[],notes:[],actions:[],next:[]});function y8(e,t){let n=[...e.charts,...t.flatMap(e=>e.charts)],r=[...e.findings,...t.flatMap(e=>e.findings)],i=e=>`title`in e?e.title:``;return{...e,findings:r,notes:[...e.notes,...t.flatMap(e=>e.notes)],...r.length>3?{shown:e.shown??3}:{},charts:n.map((e,t)=>({c:e,i:t})).sort((e,t)=>i(e.c).localeCompare(i(t.c))||e.i-t.i).map(e=>e.c)}}var b8=7200,x8=e=>e.reduce((e,t)=>e+t.t1-t.t0,0),S8=(e,t)=>e.flatMap(e=>t.map(t=>({t0:Math.max(e.t0,t.t0),t1:Math.min(e.t1,t.t1)}))).filter(e=>e.t1>e.t0);function C8(e){let t=[];for(let n of[...e].sort((e,t)=>e.t0-t.t0)){let e=t[t.length-1];e&&n.t0<=e.t1?e.t1=Math.max(e.t1,n.t1):t.push({t0:n.t0,t1:n.t1})}return t}function w8(e,t){for(let n of t)e=e.flatMap(e=>[{t0:e.t0,t1:Math.min(e.t1,n.t0)},{t0:Math.max(e.t0,n.t1),t1:e.t1}]).filter(e=>e.t1>e.t0);return e}function T8(e,t,n,r){let i=S8([{t0:n,t1:r}],[{t0:e.period.from,t1:e.period.to}]);return i.length?(t.shifts.length&&(i=S8(i,C8(v6({...t,stops:t.shifts.map(e=>({name:e.name,from:e.start,to:e.end}))},e.tz,n,r)))),t.stops.length?w8(i,v6(t,e.tz,n,r)):i):i}function E8(e){let t=[...e].sort((e,t)=>e.tstart-t.tstart),n=t.slice(1).map((e,n)=>e.tstart-(t[n].tend??t[n].tstart)).filter(e=>e>=0);return Math.max(300,n.length?5*x4(n):0)}function D8(e){return O8(e).stops}function O8(e){let t=y6(e.context??$3()),n=[],r=0,i=m4(e.cycles,e=>e.recordingId),a=m4(e.covered??[],e=>e.streamId);for(let[o,s]of m4([...e.recordings].sort((e,t)=>e.t0-t.t0),e=>e.streamId)){let c=E8(s.flatMap(e=>i.get(e.id)??[])),l=[],u=-1/0;for(let n of[...s,...a.get(o)??[]].sort((e,t)=>e.t0-t.t0))!n.continues&&n.t0-u>=300&&u>-1/0&&(!t.shifts.length&&n.t0-u>7200?x8(T8(e,t,u,n.t0))>=300&&r++:l.push({streamId:o,t0:u,t1:n.t0,kind:`no_data`,unit:null})),u=Math.max(u,n.t1);if(s.some(e=>i.has(e.id))){let e=s.filter(e=>i.has(e.id)||!(e.unread||e.failed)),t=e.flatMap(e=>i.get(e.id)??[]).sort((e,t)=>e.tstart-t.tstart),n=0,r=-1/0,a=[];for(let t of[...e].sort((e,t)=>e.t0-t.t0)){let e=a[a.length-1];e&&t.t0-e.t1<300?e.t1=Math.max(e.t1,t.t1):a.push({t0:t.t0,t1:t.t1})}for(let e of a){let i=Math.max(e.t0,Math.min(r,e.t1));for(;n<t.length&&t[n].tstart<e.t1;n++){let e=t[n];e.tstart-i>c&&l.push({streamId:o,t0:i,t1:e.tstart,kind:`no_batches`,unit:null}),i=Math.max(i,e.tend??e.tstart),r=Math.max(r,e.tend??e.tstart)}e.t1-i>c&&l.push({streamId:o,t0:i,t1:e.t1,kind:`no_batches`,unit:null})}}for(let r of l){let i=t.units.find(e=>e.channels.some(e=>s.some(t=>t.health?.channels[e]?.flats.some(e=>Math.abs(e.t0-r.t0)<=60))))?.name??null,a=T8(e,t,r.t0,r.t1),o=x8(a);o>=300&&(r.kind!==`no_batches`||o>c)&&a.forEach((e,t)=>n.push({...r,...e,unit:i,...t?{part:t}:{}}))}}return{stops:n.sort((e,t)=>e.t0-t.t0||e.streamId.localeCompare(t.streamId)),offGaps:r}}function k8(e,t,n=0){let r=n?[`Add the shifts in Process context to count longer gaps as stops.`]:[];if(!t.length)return r.length?{...v8(),next:r}:null;let i=y6(e.context??$3()),a=t=>e.streams.find(e=>e.id===t)?.name??`A stream`,o=n=>e.recordings.filter(e=>e.streamId===n).reduce((t,n)=>t+x8(T8(e,i,n.t0,n.t1)),0)+x8(t.filter(e=>e.streamId===n&&e.kind===`no_data`)),s=e=>{let t=[...new Set(e.map(e=>e.streamId))].reduce((e,t)=>e+o(t),0),n=x8(e),r=Math.max(1,e.filter(e=>!e.part).length);return{n:r,stopped:n,mtbf:(t-n)/r,mttr:n/r,share:t>0?n/t:0}},c=[],l=[...m4(t,e=>e.streamId)].map(([e,t])=>({sid:e,xs:t,...s(t)})).sort((e,t)=>t.stopped-e.stopped);for(let e of l){let t=[...m4(e.xs.filter(e=>e.unit),e=>e.unit)].sort((e,t)=>t[1].length-e[1].length);c.push({id:`F05-S${c.length+1}`,section:`05`,refs:[`05`],evidence:t.length?`correlation`:`measured`,p:null,numbers:{stops:e.n,stoppedS:e.stopped,mtbfS:e.mtbf,mttrS:e.mttr},text:(e.n===1?`${a(e.sid)} stopped once, for ${a3(e.stopped)}.`:`${a(e.sid)} stopped ${s3(e.n)} for ${a3(e.stopped)} in total; it ran ${a3(e.mtbf)} between stops on average and took ${a3(e.mttr)} to restart.`)+(t.length?` ${t[0][1].length} of the stops began when a ${t[0][0]} channel went flat.`:``)})}let u=new Map(l.map((e,t)=>[e.sid,c[t].id])),d=t.some(e=>e.unit),f=d?[...m4(t,e=>e.unit??`No unit found`)].map(([e,t])=>({label:e,xs:t,...s(t)})).sort((e,t)=>t.stopped-e.stopped):l.map(e=>({...e,label:a(e.sid)})),p=[],m=f[0];return m.share>=.2&&p.push({text:`Find why ${m.label} stops: ${c3(m.n,`stop`)} cost ${a3(m.stopped)} this period.`,owner:`maintenance`,urgent:!1,rank:m.share,refs:[...new Set(m.xs.map(e=>u.get(e.streamId)))]}),{findings:c,notes:[],actions:p,charts:[{kind:`table`,title:`05.4 · Stops by ${d?`machine unit`:`stream`}`,columns:[d?`Unit`:`Stream`,`Stops`,`Stopped`,`MTBF`,`MTTR`],rows:f.map(e=>({cells:[e.label,String(e.n),a3(e.stopped),a3(e.mtbf),a3(e.mttr)],...e.share>=.2?{status:`crit`}:{},...d?{}:{finding:u.get(e.xs[0].streamId)}}))}],next:[...!i.units.length&&t.length>=3?[`Add the machine units in Process context to see which unit each stop starts in.`]:[],...r]}}var A8=new Set([`mean`,`min`,`max`,`first`,`last`]),j8=()=>({plan:0,stop:0,ideal:0,n:0,good:0,badIdeal:0}),M8=e=>Math.max(0,e.plan-e.stop),N8=e=>{let t=M8(e),n=e.plan>0?t/e.plan:0,r=t>0?Math.min(1,e.ideal/t):0,i=e.n?e.good/e.n:0;return{A:n,P:r,Q:i,oee:n*r*i}};function P8(e,t){let n=e.context?.idealCycleS;if(n)return new Map(e.streams.map(e=>[e.id,n]));let r=new Map(e.value.key===`duration`?e.goldens.map(e=>[e.streamId,e.value]):[]);for(let[e,n]of m4(t,e=>e.c.streamId)){if(!r.has(e)){let t=n.filter(e=>e.level!==`off`).map(e=>e.c.tend-e.c.tstart);r.set(e,t.length?x4(t):NaN)}let t=n.map(e=>e.c).sort((e,t)=>e.tstart-t.tstart),i=E8(t),a=t.slice(1).map((e,n)=>e.tstart-t[n].tend).filter(e=>e>=0&&e<=i);a.length&&r.set(e,r.get(e)+b4(a,l4))}return r}function F8(e){let t=Object.entries(e?.channels??{}).filter(([,e])=>e.lsl!==null||e.usl!==null);return{limits:t,outside:e=>t.some(([t,n])=>Object.entries(e).some(([e,r])=>{let i=e.lastIndexOf(`:`);return r!==null&&e.slice(0,i)===t&&A8.has(e.slice(i+1))&&(n.usl!==null&&r>n.usl||n.lsl!==null&&r<n.lsl)}))}}var I8=J4(`OEE as ISO 22400-2`),L8={stops:`Stops`,slow:`Slow batches and short waits`,bad:`Bad parts`,off:`Off-golden batches`};function R8(e,t,n=[]){let r=e.context;if(!r?.shifts.length)return null;let i=e.tz,a=e.recordings,o=a.length?v6(r,i,Math.min(...a.map(e=>e.t0)),Math.max(...a.map(e=>e.t1))):[],s=P8(e,t),c=j8(),l=new Map,u=new Map,d=(e,t)=>e.get(t)??e.set(t,j8()).get(t),f=(e,t)=>{let n=g6(e,r.shifts,i);if(n!==null)for(let r of[c,d(l,n),d(u,hB(e,i))])t(r)},p=e=>({section:Y4(`06`,e,[],[]),actions:[],next:[],numbers:{}});if(![...s.values()].some(Number.isFinite))return p(`No stream has a cycle time to compare, so OEE could not be measured.`);let m=new Set(e.recordings.filter(e=>e.failed).map(e=>e.id)),h=new Set(t.filter(e=>!m.has(e.c.recordingId)).map(e=>e.c.streamId));for(let t of e.recordings)if(!(t.failed||!Number.isFinite(s.get(t.streamId))))for(let e=Math.floor(t.t0/900)*900;e<t.t1;e+=900){let n=Math.max(e,t.t0),r=Math.min(e+900,t.t1),i=Math.max(0,r-n-o.reduce((e,t)=>e+Math.max(0,Math.min(r,t.t1)-Math.max(n,t.t0)),0));f(n,e=>{e.plan+=i,h.has(t.streamId)||(e.stop+=i)})}for(let e of n)if(Number.isFinite(s.get(e.streamId)))for(let t=Math.floor(e.t0/900)*900;t<e.t1;t+=900){let n=Math.max(t,e.t0),r=Math.min(t+900,e.t1);f(n,t=>{t.stop+=r-n,e.kind===`no_data`&&(t.plan+=r-n)})}let g=e.value.key===`duration`,{limits:_,outside:v}=F8(r),y=!1;for(let e of t){let t=s.get(e.c.streamId)??NaN;if(!Number.isFinite(t)||m.has(e.c.recordingId))continue;let n=e.c.flag===`bad`||v(e.c.kpis)||!g&&e.level===`off`;y||=n||e.c.flag===`good`,f(e.c.tstart,e=>{e.ideal+=t,e.n++,n?e.badIdeal+=t:e.good++})}if(!c.plan)return p(`No recorded time falls in the shifts, so OEE could not be measured.`);let b=N8(c),x=r.costs.currency,S=r.costs.lineHour,C=[...new Set(t.map(e=>s.get(e.c.streamId)??NaN).filter(Number.isFinite))].sort((e,t)=>e-t),w=e=>e<60?`${$4(+e.toFixed(1))} s`:a3(e),T=C.length?r.idealCycleS?`Ideal cycle ${w(C[0])}, set in Process context.`:`Ideal cycle ${w(C[0])}${C.length>1&&w(C[0])!==w(C[C.length-1])?` to ${w(C[C.length-1])}`:``}, inferred from the data.`:``,E=e=>S===null?``:` (up to ${Q4(e/3600*S,x)})`,D=[{label:L8.stops,s:c.plan-M8(c),owner:`maintenance`,act:e=>`Find what stops the line (see 05.4): ${e} of planned time stopped.`},{label:L8.slow,s:Math.max(0,M8(c)-c.ideal),owner:`production`,act:e=>`Bring the pace to the ideal cycle: slow batches and short waits cost ${e}.`},g?{label:L8.bad,s:c.badIdeal,owner:`quality`,act:e=>`Bring the bad parts inside their limits (see 04): they cost ${e}.`}:{label:L8.off,s:c.badIdeal,owner:`quality`,act:e=>`Bring off-golden batches to golden level (see 02): they cost ${e}.`}];D.sort((e,t)=>t.s-e.s);let O=D.reduce((e,t)=>e+t.s,0),k=D[0],A=[],j=[],M=[],N=e=>{let t=`F06-${A.length+1}`;return A.push({id:t,section:`06`,refs:[`06`],...e}),t};if(N({evidence:`measured`,p:null,numbers:p4({oee:b.oee,availability:b.A,performance:b.P,quality:b.Q,plannedH:c.plan/3600}),text:`OEE ${X4(b.oee)}: availability ${X4(b.A)}, performance ${X4(b.P)}, quality ${X4(b.Q)}, over ${a3(c.plan)} of planned time.${T?` ${T}`:``}`}),k.s>0){let e=N({evidence:`measured`,p:null,numbers:p4({hours:k.s/3600,share:k.s/O,cost:S===null?NaN:k.s/3600*S}),text:`${k.label} lose the most: ${a3(k.s)}${E(k.s)}, ${X4(k.s/O)} of the ${a3(O)} lost.`});j.push({text:k.act(`${a3(k.s)}${E(k.s)}`),owner:k.owner,urgent:!1,rank:k.s/c.plan,refs:[e]})}let P=r.shifts.filter(e=>l.has(e.name)).map(e=>{let t=l.get(e.name),n=N8(t);return{cells:[e.name,X4(n.A),t.n?X4(n.P):`–`,t.n?X4(n.Q):`–`,X4(n.oee)]}});O>0&&M.push({kind:`bars`,title:`06.1 · Where planned time is lost${S===null?``:`, and what it costs`}`,max:k.s/3600,rows:D.filter(e=>e.s>=60).map(e=>({label:e.label,value:e.s/3600,text:`${a3(e.s)}${E(e.s)}`,tip:`${e.label}: ${X4(e.s/O)} of the time lost`}))}),P.length>1&&!r.hideShifts&&M.push({kind:`table`,title:`06.2 · OEE by shift`,columns:[`Shift`,`Availability`,`Performance`,`Quality`,`OEE`],rows:P});let F=[...u].filter(([,e])=>e.plan>0).map(([e,t])=>({t:gB(e,`00:00`,i),v:N8(t).oee})).sort((e,t)=>e.t-t.t),I=F.length>=7?L4(F.map(e=>(e.t-F[0].t)/86400),F.map(e=>e.v)):null;if(I&&I.p<.01&&Math.abs(I.b*700)>=1){N({evidence:`statistical`,p:I.p,numbers:p4({perWeek:I.b*7,days:I.n,p:I.p}),text:`OEE ${I.b<0?`falls`:`rises`} by ${Math.round(Math.abs(I.b*700))} points a week since ${h3(F[0].t,i)}.`});let e=F[0].t,t=F[F.length-1].t;M.push({kind:`trend`,title:`06.3 · OEE per day, with its trend`,unit:`%`,points:F.map(e=>({t:e.t,v:e.v*100})),line:{t0:e,v0:I.a*100,t1:t,v1:(I.a+I.b*(t-e)/86400)*100},limit:null,crossing:null})}let L=k.s>0?`${k.label} lose the most time.`:`No planned time is lost.`,R=g&&c.n&&!y&&!_.length?[`Add specification limits to the quality channels in Process context: OEE counts every batch as good until something says which are bad.`]:[];return{section:{...Y4(`06`,L,A,M),subtitle:I8,fold:!0},actions:j,next:R,numbers:{oee:b.oee,stopsS:c.plan-M8(c),slowS:Math.max(0,M8(c)-c.ideal),offS:c.badIdeal}}}function z8(e,t,n,r=[]){let i=y6(e.context??$3()).shifts,a=e.tz;if(!i.length)return{section:`11`,needs:`Add the shifts in Process context to compare them.`};let o=new Map(i.map(e=>[e.name,{n:0,good:0,stopped:0,alerts:0}])),s=e=>{let t=g6(e,i,a);return t===null?void 0:o.get(t)};for(let e of t){let t=s(e.c.tstart);t&&(t.n++,e.level!==`off`&&t.good++)}for(let t of e.alerts??[]){let e=s(t.t);e&&e.alerts++}for(let e of n)for(let t=Math.floor(e.t0/900)*900;t<e.t1;t+=900){let n=Math.max(t,e.t0),r=Math.min(t+900,e.t1),i=s(n);i&&(i.stopped+=r-n)}let c=[...o].map(([e,t])=>({name:e,...t,share:t.n?t.good/t.n:NaN})),l=c.filter(e=>e.n>=5),u=l.reduce((e,t)=>!e||t.share<e.share?t:e,null),d=u&&l.filter(e=>e!==u),f=d?.reduce((e,t)=>e+t.n,0)??0,p=d?.reduce((e,t)=>e+t.good,0)??0,m=f?p/f:NaN,h=!!u&&r.some(e=>e.text.includes(`on the ${u.name} shift`)),g=!!u&&m-u.share>=.05&&(h||P4(u.good,u.n,p,f).p<.01),_=[];if(g){let e=`The ${u.name} shift has the lowest share of batches at golden level (${X4(u.share)} against ${X4(m)}).`,t=[`11`,...h?[`02`]:[]];_.push({id:`F11-1`,section:`11`,refs:t,evidence:`measured`,p:null,text:e,numbers:{share:u.share,others:m,batches:u.n}})}let v=c.filter(e=>e.n);return{section:Y4(`11`,g?_[0].text:l.length>=2?`The shifts perform alike.`:v.length===1?`Only the ${v[0].name} shift made batches in this period.`:`Too few batches in the shifts to compare them.`,_,[{kind:`table`,title:`11.1 · Shifts`,columns:[`Shift`,`Batches`,`At golden level or better`,`Stopped`,`Alerts`],rows:c.map(e=>({cells:[e.name,e.n.toLocaleString(`en-GB`),e.n?X4(e.share):`–`,a3(e.stopped),String(e.alerts)],...g&&e===u?{status:`watch`,finding:`F11-1`}:{}}))}]),actions:[],next:[],numbers:g?{share:u.share,others:m}:{}}}function B8(e,t,n=[],r,i=D8(e)){let a=e.previous,o=a?{...e,period:a.period,recordings:a.recordings,cycles:a.cycles,previous:null}:null,s=o?f4(o):[];if(!o||s.length<5)return{section:`01`,needs:`The period before this one has too few stored batches to compare with. It fills in once the cycles of that period are found.`};if(t.length<5)return{section:`01`,needs:`This period has too few batches to compare with the one before.`};let c=e=>e.filter(e=>e.level!==`off`).length,l=P4(c(t),t.length,c(s),s.length),u=e=>e.map(e=>e.c.value),d=x4(u(t)),f=x4(u(s)),p=E4(u(t),u(s)),[m,h]=F4([l.p,p.p],c4),g=e.value.label,[_,v]=t3(d,f),y=e.value.better===`min`?p.effect<.5:p.effect>.5,b=_===v?y?`better`:`worse`:null,x=[],S=[],C=[],w=[];if(m){let e=l.p1>l.p2;x.push({id:`F01-1`,section:`01`,refs:[`01`],evidence:`statistical`,p:l.p,numbers:p4({share:l.p1,before:l.p2,p:l.p}),text:`${X4(l.p1)} of batches at golden level or better, ${e?`up`:`down`} from ${X4(l.p2)} the period before.`}),w.push({better:e,text:`${X4(l.p1)} of batches at golden level, ${e?`up`:`down`} from ${X4(l.p2)}.`}),e||(S.push(`the share at golden level`),C.push(`F01-1`))}h&&(x.push({id:`F01-2`,section:`01`,refs:[`01`],evidence:`statistical`,p:p.p,numbers:p4({median:d,before:f,p:p.p}),text:b?`${g} moved ${b} since the period before (median ${_} both times).`:`The median ${g} is ${_}, ${y?`better`:`worse`} than ${v} the period before.`}),w.push({better:y,text:b?`${g} moved ${b} (median ${_} both times).`:`the median ${g} is ${_}, against ${v}.`}),y||(S.push(g),C.push(`F01-2`)));let T=[],E=e.tz,D=`${h3(a.period.from,E)} – ${h3(a.period.to-1,E)}`;S.length&&T.push({text:`Find what changed since the period before (${D}): ${S.join(` and `)} ${S.length>1?`are`:`is`} worse.`,owner:`management`,urgent:!1,rank:Math.max(0,l.p2-l.p1),refs:[...C,...n.map(e=>e.id)]});let O=w.find(e=>!e.better)??w[0],k=O?`${O.better?`Better`:`Worse`} than the period before: ${O.text}`:`About the same as the period before.`,A=e=>e.reduce((e,t)=>e+t.t1-t.t0,0),j=(e,t,n=W6(e,t))=>n.filter(e=>e.status===`Replace`||e.status===`Drifting`).length,M=A(i),N=A(D8(o));return{section:Y4(`01`,k,x,[{kind:`tiles`,tiles:[{label:`At golden level or better`,value:X4(l.p1),note:`${X4(l.p2)} before`},{label:`${g} median`,value:_,note:`${v} before`},{label:`Stopped`,value:a3(M),note:`${a3(N)} before`},{label:`Sensors to replace or drifting`,value:String(j(e,t,r)),note:`${j(o,s)} before`}]}]),actions:T,next:[],numbers:p4({share:l.p1,before:l.p2,median:d,medianBefore:f,stoppedS:M,stoppedBeforeS:N})}}function V8(e,t,n,r){let{tz:i}=e,a=hB(e.period.from,i),o=hB(e.period.to-1,i),s=[];for(let e=a;e<=o&&s.length<=400;e=_B(e,1))s.push(e);if(s.length<2||s.length>400||!t.length)return null;let c=e=>s.indexOf(hB(e,i)),l=s.map(()=>0),u=s.map(()=>0),d=s.map(()=>0),f=s.map(()=>!1);for(let e of t){let t=c(e.c.tstart);t>=0&&(l[t]++,e.level===`off`&&u[t]++)}let p=s.map(e=>[gB(e,`00:00`,i),gB(_B(e,1),`00:00`,i)]);for(let e of n)p.forEach(([t,n],r)=>{d[r]+=Math.max(0,Math.min(n,e.t1)-Math.max(t,e.t0))});let m=r??e.recordings.flatMap(e=>Object.values(e.health?.channels??{}).filter(e=>!e.clock).flatMap(e=>e.flats));for(let e of m)p.forEach(([t,n],r)=>{e.t1>t&&e.t0<n&&(f[r]=!0)});return s.every((e,t)=>!u[t]&&d[t]<60&&!f[t])?null:{kind:`strip`,title:`00.3 · The period day by day: the share of batches off the golden, with stops and failing sensors marked`,legend:`off the golden`,days:s.map((e,t)=>{let n=new Date(`${e}T00:00:00Z`),r=`${y3[(n.getUTCDay()+6)%7]} ${n.getUTCDate()} ${n.toLocaleString(`en-GB`,{month:`short`,timeZone:`UTC`})}`,i=[l[t]?`${c3(l[t],`batch`,`batches`)}, ${X4(u[t]/l[t])} off the golden`:`no batches`,...d[t]>=60?[`stopped ${a3(d[t])}`]:[],...f[t]?[`a sensor stuck`]:[]];return{day:e,label:r,n:l[t],off:l[t]?u[t]/l[t]:null,stopS:d[t],sensor:f[t],text:`${r}: ${i.join(`, `)}`}})}}var H8={management:`Management`,quality:`Quality`,maintenance:`Maintenance`,production:`Production`},U8=e=>e.findings.length||e.id===`01`?e:{...e,charts:[],notes:[]},W8=(e,t)=>{let n=t.filter(e=>!!e);return{...e,section:y8(U8(e.section),n),actions:[...e.actions,...n.flatMap(e=>e.actions)],next:[...e.next,...n.flatMap(e=>e.next)]}},G8=e=>({cells:[e.id,e.text,H8[e.owner]],...e.urgent?{status:`crit`}:{}});function K8(e){let t=U6(e);if(!t.size)return e;let n=e=>e&&Object.fromEntries(Object.entries(e).filter(([e])=>!t.has(e)));return{...e,cycles:e.cycles.map(e=>({...e,z:n(e.z),d:n(e.d)})),goldens:e.goldens.map(e=>({...e,edges:n(e.edges)}))}}function q8(e){let t=f3(e.tz)?e:{...e,tz:`UTC`},n=K8(t.context?{...t,context:y6(t.context)}:t),r=f4(n),i=p8(n,r),a=M3(n,r),o=G6(n,r),{stops:s,offGaps:c}=O8(n),l=k8(n,s,c),u=W8(o.out,[l,_8(n,o.drifts,o.wear)]),d=o.out.numbers.replace+o.out.numbers.drifting+o.out.numbers.watch,f=!o.out.section.findings.length&&l?.findings.length?{...u,section:{...u.section,verdict:`${l.findings[0].text}${d?` ${o.out.section.verdict}`:``}`}}:u,p=U8(i.section),m=U8(a.section),h=U8(f.section),g=I3(n,r),_=e8(n,r,o.sensors),v=g===null?Z6(n,r):null,y=_?`${c3(_.findings.reduce((e,t)=>e+t.numbers.batches,0),`batch`,`batches`)} to check before they ship: made while a sensor was failing.`:v?`${c3(v.findings.length,`feature`)} left ${v.findings.length===1?`its`:`their`} control limits; no specification limits say which batches are bad.`:``,b=!_&&!v?g:g&&!(`needs`in g)?W8(g,[_]):[g,W8({section:{...Y4(`04`,y,[],[]),fold:!0,subtitle:J4(_?`Containment: batches made while a sensor was failing`:`Control chart (Shewhart individuals, 3σ)`)},actions:[],next:[],numbers:{}},[_,v])],x=$6(n,r),S=[B8(n,r,x&&!(`needs`in x)?x.section.findings:[],o.sensors,s),b,R8(n,r,s),O3(n,r),x,i8(n,r),m8(n,r),n.context?.hideShifts?null:z8(n,r,s,i.section.findings)].flat(),C=S.filter(e=>!!e&&!(`needs`in e)),w=S.filter(e=>!!e&&`needs`in e),T=C.map(e=>U8(e.section)),E=new Set(T.map(e=>e.id)),D=[...i.actions,...a.actions,...f.actions,...C.flatMap(e=>e.actions)].sort((e,t)=>Number(t.urgent)-Number(e.urgent)||t.rank-e.rank).map((e,t)=>({id:`A${t+1}`,text:e.text,owner:e.owner,urgent:e.urgent,refs:e.refs})),O=D.slice(0,3),k=Y4(`12`,D.length?`Start with ${l3(O.map(e=>e.id))}: ${O.some(e=>e.urgent)?`urgent items`:`the largest effect`} first.`:`Nothing to act on in this period.`,[],D.length?[{kind:`table`,title:`12.1 · Actions, most urgent first`,columns:[`#`,`Action`,`Owner`],rows:D.map(G8),...D.length>5?{shown:5,more:c3(D.length-5,`more action`)}:{}}]:[]),A=[...new Set([...i.next,...a.next,...f.next,...C.flatMap(e=>e.next)])],j=Y4(`13`,A[0]??`Nothing left unexplained that more data would answer.`,[],[],A.slice(1)),M=r.filter(e=>e.level!==`off`).length,N=D.filter(e=>e.urgent).length,P=e=>{let t=new Set(e.findings.map(e=>e.id)),n=D.findIndex(e=>e.refs.some(e=>t.has(e)));return n<0?1/0:n},F=[p,h,m,...T].filter(e=>e.findings.length).map(e=>({s:e,i:P(e)})).sort((e,t)=>e.i-t.i||0).map(e=>e.s),I=n.value.key===`duration`?r.reduce((e,t)=>e+Math.max(0,t.gap),0):0,L=F8(n.context),R=C.find(e=>e.section.id===`06`)?.numbers,z=C.find(e=>e.section.id===`09`)?.section.findings.find(e=>e.id===`F09-2`)?.numbers.extra,B=h8(n,{time:R&&`slowS`in R?[{label:L8.stops,s:R.stopsS,owner:H8.maintenance,ref:`06`},{label:L8.slow,s:R.slowS,owner:H8.production,ref:`06`},n.value.key===`duration`?{label:L8.bad,s:R.offS,owner:H8.quality,ref:`06`,bad:!0}:{label:L8.off,s:R.offS,owner:H8.quality,ref:`06`}]:[{label:`Stops`,s:s.reduce((e,t)=>e+t.t1-t.t0,0),owner:H8.maintenance,ref:`05`},{label:`Batches slower than the golden`,s:I,owner:H8.production,ref:`02`}],energyKwh:z??null,review:_&&E.has(`04`)?{batches:_.findings.reduce((e,t)=>e+t.numbers.batches,0),s:_.findings.reduce((e,t)=>e+t.numbers.seconds,0)}:null,scrap:L.limits.length||r.some(e=>e.c.flag===`bad`||e.c.flag===`good`)?{batches:r.filter(e=>e.c.flag===`bad`||L.outside(e.c.kpis)).length,assumed:!1}:n.value.key===`duration`?null:{batches:r.length-M,assumed:!0}}),V=V8(n,r,s,o.sensors.flatMap(e=>e.stuck)),ee=o.sensors.filter(e=>e.status===`Drifting`),te=new Set(ee.map(e=>e.sid)),H=Y4(`00`,r.length?`${X4(M/r.length)} of batches at golden level or better${N?`, and ${c3(N,`urgent item`)}`:``}.`:`No batches could be compared with a golden in this period.`,F.map((e,t)=>({id:`F00-${t+1}`,section:`00`,text:e.verdict,evidence:e.findings[0].evidence,p:e.findings[0].p,refs:[e.id],numbers:e.findings[0].numbers})),[...B?[B]:[],...O.length?[{kind:`table`,title:`00.2 · What to do first`,columns:[`#`,`Action`,`Owner`],rows:O.map(G8),ref:`12`}]:[],...V?[V]:[],{kind:`tiles`,tiles:[{label:`Batches`,value:r.length.toLocaleString(`en-GB`),note:c3(n.recordings.length,`file`)},{label:`At golden level or better`,value:r.length?X4(M/r.length):`–`},...a.numbers.better?[{label:`Better than the golden`,value:a.numbers.better.toLocaleString(`en-GB`)}]:[],...f.numbers.replace?[{label:f.numbers.replace===1?`Sensor to replace`:`Sensors to replace`,value:String(f.numbers.replace)}]:[],...ee.length?[{value:String(ee.length),label:`${ee.length===1?`Channel`:`Channels`} drifting${te.size>1?` on ${te.size} streams`:n.streams.length>1?`${ee.length>1?`, all`:``} on ${n.streams.find(e=>e.id===ee[0].sid)?.name??`one stream`}`:``}`}]:[]]}]),ne=n.recordings.filter(e=>!e.failed&&!e.unread),re=n.recordings.filter(e=>e.failed),ie=n.recordings.filter(e=>e.unread).length,U=e=>n.streams.find(t=>t.id===e)?.name??`A stream`,ae=Y4(`14`,`How the findings were made and how sure each one is.`,[],[],[`Cycles found with “${n.rule.name}” v${n.rule.version} in ${c3(n.recordings.length,`recording`)} of ${c3(n.streams.length,`stream`)}, ${X4(n.recordings.length?ne.length/n.recordings.length:0)} read${ie?`; ${ie} not read, counted through ${ie===1?`its`:`their`} stored cycles and measures`:``}${re.length?` (could not be read: ${re.map(e=>`${e.name}, ${e.failed}`).join(`; `)})`:``}.`,...n.goldens.map(e=>`${U(e.streamId)}: compared with ${e.label}${e.proposed?`, proposed because no golden is set`:e.auto?`, set by this report because none was set (the best ${n.value.label} that 1 batch in 20 reaches, and at least 5); change it with Make it the golden or in Batches`:``}, on ${c3(Object.keys(e.edges).length,`channel`)}.`),`A batch is at golden level when its ${n.value.label} is within 2% of the golden’s (or twice the spread of the golden’s own batches), and better than the golden beyond that on the good side.`,`Shares of the batch-to-batch variation in the gap: a least-squares fit, over all measured batches, of each batch’s gap on its deviation from the golden by channel and phase, split with Pratt’s measure; only deviations that differ between off-golden batches and the rest enter (Mann–Whitney, Benjamini–Hochberg at q = 0.01 across channel × phase). Shares and what better batches do differently are correlations: leads to test, not proven causes.`,`Patterns: two-proportion tests (Fisher’s exact test with small counts), Benjamini–Hochberg at q = 0.01 across streams and across files; a group is named only when it runs at least 5 points more off-golden than the rest. What better batches do differently: Mann–Whitney per measure, Benjamini–Hochberg at q = 0.01 across measures. The proposed golden of a stream: the best value at least 5 of its batches reach. Intervals: bootstrap over batches (1,000 resamples; over 2,000 batches, resamples of 2,000 scaled to the period). p-values are shown as they are, never as a confidence.`,...s.length||c?[`Stops (05.4): no data for ${300/60} minutes or more, or no batch for ${300/60} minutes or more and at least 5× the usual wait between two batches; planned stops and time outside the shifts left out${n.context?.shifts.length?``:`; without shifts, no data for more than ${b8/3600} h is time off, not a stop`}; a stop is given a machine unit when one of its channels went flat within 60 s of the stop’s start.`]:[],`Sensor health per recording: gaps (steps over 4× the usual), flat runs (${300/60} minutes or more of one repeated value; runs at the same value with up to ${P6/3600} h between them, a stop or a file boundary, are one; a sensor is stuck only where batches were made meanwhile, not while the line stood still), noise (median absolute deviation of sample-to-sample changes), spikes (Hampel filter, 6 robust σ), rate drops, and values outside the range learned from the first third of the period’s recordings. Drift: a straight-line trend of each channel’s offset from the golden, forecast to the golden’s band edge; an offset that stepped once and stayed is a change, not a drift. Counters (an energy meter, a part count) are not compared with the golden.`,...t===e?[]:[`Times in UTC: the time zone “${e.tz}” is not known.`],`Drifts and wear are fitted on daily means (batches of one day are not independent), with Student’s t. Over fewer than 7 days a drift is fitted on means per recording (per hour with fewer than 6 recordings), at least 6 of them, and says so: those means are not independent either, so a short drift is a lead to confirm over more days. Drifts are kept at Benjamini–Hochberg q = 0.01 across sensors; the day a drift reaches the band edge has a 99 % interval by inverse prediction (Fieller).`,...g&&!(`needs`in g)?[`Capability (04.1): Ppk = min(USL − mean, mean − LSL) / 3σ of each cycle KPI (mean, minimum, maximum, at start, at end) whose channel has specification limits in Process context, over at least 30 batches; capable from ${n.context?.ppkMin??1.33}. ${N3}`]:[],...v?[`Control chart (04.3): per stream, each level KPI of the batches in time order; centre line = the mean, σ = the average moving range / 1.128, limits = mean ± 3σ, from 30 batches; a KPI is named when more than ${(2*K6*100).toFixed(2)}% of its batches are outside (twice what a stable process leaves by chance). It says the process moved, not that a batch is bad.`]:[],...h.charts.some(e=>`title`in e&&e.title.startsWith(`05.5`))?[`Maintenance (05.5): each recalibration by the lower end of its crossing’s 99 % interval, placed in the latest planned stop before it.`]:[],..._&&E.has(`04`)?[`Batches made while a sensor was failing (04.2): the flat runs (05.1) and the drift past the band edge (05.2) of the sensors a golden compares; a batch counts when it starts inside one.`]:[],...E.has(`06`)?[`OEE (06), with the ratios of ISO 22400-2: planned time is the recorded time inside the shifts less planned stops, plus the stops with no data (05.4); availability = the time not stopped (planned time less 05.4’s stops) / planned time; performance = the ideal cycle × batches / the time not stopped, the ideal cycle being ${n.context?.idealCycleS?`the one set in Process context`:`inferred from the data: the golden’s cycle time plus the shortest wait between two batches that 1 wait in 20 reaches`}; quality = good batches / batches: not flagged bad and inside the specification limits${n.value.key===`duration`?``:`, and at golden level or better`}. The daily trend is a straight line over 7 days or more, kept at p < 0.01.`]:[],...E.has(`07`)?[`Alerts (07): the project’s alert rules run over the period’s recordings; an alert comes before a batch when raised in the ${E3/3600} h before it starts or while it runs; two-proportion tests (Fisher’s exact test with small counts), Benjamini–Hochberg at q = 0.01 across rules.`]:[],...E.has(`08`)?[`Changes (08): consecutive flat runs of a setting at values more than 3 noise σ apart; the effect by Mann–Whitney on the 20 batches each side, Benjamini–Hochberg at q = 0.01 across the changes.`]:[],...E.has(`09`)?[`Energy (09): per batch, a power channel (W, kW, MW) integrated over the batch, or an energy meter (Wh, kWh, MWh) by its change; the period’s energy is what a meter counted over the recordings (the batches’ energy with a power channel); off-golden batches against the rest by Mann–Whitney. CO₂ is the energy times the grid factor entered in Process context: Scope 2, location-based.`]:[],...E.has(`10`)?[`Lines (10): each line’s batches against its own streams’ goldens; each line against the other lines by two-proportion tests, Benjamini–Hochberg at q = 0.01 across lines.`]:[],...E.has(`11`)?[`Shifts (11): measured counts per shift (batches, the share at golden level or better, stopped time in 15-minute blocks, alerts); the weakest shift is named when its share differs from the other shifts’ by a two-proportion test at p < 0.01, or when 02.4 named it.`]:[],...E.has(`01`)?[`Since the last period (01): the previous period’s stored batches judged against the current goldens; the share at golden level by a two-proportion test and the value by Mann–Whitney, Benjamini–Hochberg at q = 0.01 across the two.`]:[],`Findings computed by Kymoscope, worded from fixed templates; no AI was used.`]),oe=n.goldens,se=H6(n),ce=Object.keys(n.units).filter(e=>!se.has(e)).length;return{v:1,cover:{title:`Report ${h3(n.period.from,n.tz)} – ${h3(n.period.to-1,n.tz)}`,project:n.project,period:n.period,cycle:`${n.rule.name} v${n.rule.version}`,value:`${n.value.label}, ${n.value.better===`min`?`lower`:`higher`} is better`,golden:oe.length===1?`${oe[0].label}${oe[0].proposed?` (proposed: no golden set)`:oe[0].auto?` (set automatically: none was set)`:``}`:oe.length?`${oe.length} goldens, one per stream`:`None`,data:`${c3(n.streams.length,`stream`)} · ${c3(n.recordings.length,`file`)}${ce||!ie?` · ${c3(ce,`channel`)}`:``}`,madeBy:n.madeBy,madeAt:n.madeAt,tz:n.tz,context:n.contextVersion?`Process context v${n.contextVersion}`:`None set`},actions:D,sections:[H,p,m,...T,h,k,j,ae].sort((e,t)=>e.id.localeCompare(t.id)),missing:[...new Map([...S6(n.context??null,n.alertRules?.length??0),...w].map(e=>[`${e.section} ${e.needs}`,e])).values()].map(e=>({section:e.section,title:G4[e.section],needs:e.needs})).sort((e,t)=>e.section.localeCompare(t.section))}}function J8(e){let t=new Set((e.fold?e.charts.slice(0,1):e.charts).flatMap(e=>e.kind===`table`?e.rows.flatMap(e=>e.finding?[e.finding]:[]):[])),n=e.shown??e.findings.length,r=e=>!t.has(e.id);if(e.fold){let t=e.findings.filter(r);return{full:t.slice(0,n),rest:t.slice(n)}}return{full:e.findings.slice(0,n).filter(r),rest:e.findings.slice(n).filter(r)}}function Y8(e,t){return t===`full`?e.sections:e.sections.filter(e=>e.roles.includes(t))}var X8={verdict:30,sentence:35,action:30},Z8={verdict:250,sentence:300,action:250},Q8=/\b(zero|one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve|thirteen|fourteen|fifteen|sixteen|seventeen|eighteen|nineteen|twenty|hundred|thousand|million|dozen|half|twice|double|triple)\b/i,$8=/\b(\d{1,2})\s+(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)[a-z]*\.?/gi,e5=e=>e.normalize(`NFKC`).replace(/−/g,`-`),t5=e=>Q8.test(e5(e))||/(?![0-9])\p{Nd}/u.test(e5(e)),n5=e=>{let t=e5(e),n=[];return t=t.replace($8,(e,t,r)=>(n.push(`${+t} ${r.toLowerCase()}`),` `)),[...n,...(t.match(/[-+]?(?:\d[\d,]*)?\.?\d+%?/gu)??[]).map(e=>e.replace(/,/g,``))]},r5=e=>!!e&&typeof e==`object`&&!Array.isArray(e),i5=e=>Array.isArray(e)?e.filter(r5):[];function a5(e,t){let n=new Map(e.sections.flatMap(e=>e.findings.map(e=>[e.id,e.text]))),r=(e,t,r,i,a=!0)=>{if(!r5(e))return null;let o=typeof e.text==`string`?e.text.trim():``,s=Array.isArray(e.cites)?[...new Set(e.cites)]:[];if(!o||!s.length||!s.every(e=>typeof e==`string`&&n.has(e)&&i.has(e))||o.length>t.chars||o.split(/\s+/).length>t.words||t5(o))return null;let c=new Set([...r,...a?s.map(e=>n.get(e)):[]].flatMap(n5));return n5(o).every(e=>c.has(e))?{text:o,cites:s}:null},i=e=>({words:X8[e],chars:Z8[e]}),a=r5(t)?t:{},o=new Map(i5(a.actions).map(e=>[e.id,e])),s=e.actions.flatMap(e=>{let t=r(o.get(e.id),i(`action`),[e.text],new Set(e.refs));return t?[{id:e.id,text:t.text,cites:t.cites}]:[]}),c=new Map(i5(a.sections).map(e=>[e.id,e])),l=new Map(e.sections.map(e=>[e.id,e.findings.map(e=>e.id)])),u=t=>new Set(t.id===`12`?e.actions.flatMap(e=>e.refs):[...l.get(t.id),...t.id===`00`?t.findings.flatMap(e=>e.refs.flatMap(e=>l.get(e)??[])):[]]);return{sections:e.sections.flatMap(e=>{let t=e.id===`14`?void 0:c.get(e.id);if(!t)return[];let n=u(e),a=r(t.verdict,i(`verdict`),[e.verdict],n,!1),o=(Array.isArray(t.sentences)?t.sentences:[]).map(e=>r(e,i(`sentence`),[],n)).filter(e=>!!e).slice(0,2);return a||o.length?[{id:e.id,verdict:a,sentences:o}]:[]}),actions:s}}var o5=e=>`Findings computed by Kymoscope. Text written by Kymoscope’s AI (${e}) from the findings and the Process context only, never from the data; every sentence names the findings it rests on.`;function s5(e,t){let n=t?y6(t):null;return{process:n?.process??``,channels:Object.entries(n?.channels??{}).flatMap(([e,t])=>{let n=e6(t);return n&&n!==`ignore`?[{name:e,role:X3[n],unit:t.unit}]:[]}).slice(0,200),sections:e.sections.filter(e=>e.id!==`14`).map(e=>({id:e.id,title:e.title,verdict:e.verdict,findings:e.findings.map(e=>({id:e.id,text:e.text,evidence:T3(e),refs:e.refs}))})),actions:e.actions.map(e=>({id:e.id,text:e.text,owner:e.owner,refs:e.refs}))}}function c5(e,t,n){let r=a5({sections:e.sections.map(e=>({id:e.id,verdict:e.verdict,findings:e.findings})),actions:e.actions},t),i=new Map(r.actions.map(e=>[e.id,e.text])),a=e.actions.map(e=>i.has(e.id)?{...e,text:i.get(e.id)}:e),o=new Map(a.map(e=>[e.id,e.text])),s=new Map(r.sections.map(e=>[e.id,e])),c=e.sections.map(e=>{let t=e.charts.map(e=>e.kind===`table`&&e.columns[0]===`#`?{...e,rows:e.rows.map(e=>o.has(e.cells[0])?{...e,cells:[e.cells[0],o.get(e.cells[0]),...e.cells.slice(2)]}:e)}:e),n=s.get(e.id);if(!n)return{...e,charts:t};let r=new Set(e.charts.flatMap(e=>e.kind===`table`?e.rows.flatMap(e=>e.finding?[e.finding]:[]):[])),i=e.findings.length===1&&r.has(e.findings[0].id)?[]:n.sentences;return{...e,charts:t,...n.verdict?{verdict:n.verdict.text}:{},...i.length?{ai:i}:{}}}),l=new Map(c.map(e=>[e.id,e.verdict])),u=c.map(e=>e.id===`00`?{...e,findings:e.findings.map(e=>({...e,text:l.get(e.refs[0])??e.text}))}:e.id===`14`?{...e,notes:[...e.notes.slice(0,-1),o5(n)]}:e);return{...e,cover:{...e.cover,ai:n},sections:u,actions:a}}var l5=.5,u5=5400,d5=/^[kM]?Wh?$/,f5=86400/300,p5=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`],m5=e=>{let t=Math.round((e%86400+86400)%86400/60)%1440;return`${String(Math.floor(t/60)).padStart(2,`0`)}:${String(t%60).padStart(2,`0`)}`},h5=(e,t)=>Math.round(e/t)*t;function g5(e){if(!e.length)return null;let t=x4(e.map(e=>e.p01??e.lo)),n=x4(e.map(e=>e.p99??e.hi));if(!(n>t))return null;let r=Math.floor(Math.log10(n-t)),i=10**(r-1),a=Math.max(0,1-r);return{lo:+(Math.floor(t/i)*i).toFixed(a),hi:+(Math.ceil(n/i)*i).toFixed(a)}}function _5(e){let t=new Set(e.filter(e=>e.batches.length).map(e=>e.streamId)),n=e.flatMap(e=>t.has(e.streamId)?e.batches:[[e.t0,e.t1]]).filter(([e,t])=>t>e).sort((e,t)=>e[0]-t[0]),r=[];for(let[e,t]of n){let n=r[r.length-1];n&&e-n[1]<600?n[1]=Math.max(n[1],t):r.push([e,t])}return r}function v5(e,t){let n=new Map,r=e=>{let r=Math.floor(e/3600),i=n.get(r);return i===void 0&&n.set(r,i=mB(e,t)),e+i},i=new Map;for(let[t,n]of e)for(let e=Math.ceil((t-300/2)/300)*300+300/2;e<n;e+=300){let t=r(e),n=Math.floor(t/86400),a=Math.floor((t-n*86400)/300),o=i.get(n);o||i.set(n,o=new Set),o.add(a)}return i}function y5(e){let t=[...e.keys()].sort((e,t)=>e-t);if(t.length<3||t[t.length-1]-t[0]<13)return null;let n=Array(7).fill(0),r=Array(7).fill(0);for(let i=t[0];i<=t[t.length-1];i++){let t=(i+3)%7;n[t]++,e.has(i)&&r[t]++}let i=[0,1,2,3,4,5,6].filter(e=>n[e]>=2&&r[e]===0),a=[0,1,2,3,4,5,6].filter(e=>!i.includes(e));return!i.length||!a.length||a.some(e=>r[e]/n[e]<.6)?null:{name:i.join()===`5,6`?`Weekend`:`No work on ${i.map(e=>p5[e]).join(`, `)}`,from:`00:00`,to:`00:00`,days:i}}function b5(e){let t={shifts:[],stops:[]};if(e.size<3)return t;let n=Array.from({length:f5},(t,n)=>[...e.values()].filter(e=>e.has(n)).length/e.size),r=n.map(e=>e>=l5),i=[],a=r.indexOf(!0);if(a<0)return t;for(let e=0;e<f5;e++){let t=(a+e)%f5;if(r[t])continue;let n=i[i.length-1];n&&(n.a+n.n)%f5===t?n.n++:i.push({a:t,n:1})}let o=i.filter(e=>e.n*300>=600&&e.n*300<=5400),s=i.filter(e=>e.n*300>u5);for(let e of i.filter(e=>e.n*300<600))for(let t=0;t<e.n;t++)r[(e.a+t)%f5]=!0;let c=i.filter(e=>e.n*300>=600).flatMap(e=>Array.from({length:e.n},(t,r)=>n[(e.a+r)%f5])),l=n.filter((e,t)=>r[t]),u=e=>e.reduce((e,t)=>e+t,0)/e.length;if(!c.length||u(l)<.7||u(c)>.25)return t;let d=[];if(!s.length)d.push({a:0,b:86400,pauses:[]});else for(let e=0;e<s.length;e++){let t=(s[e].a+s[e].n)%f5*300,n=s[(e+1)%s.length].a*300;d.push({a:t,b:n>t?n:n+86400,pauses:[]})}let f=!s.length;for(let e of o){let t=e.a*300,n=t+e.n*300,r=d.find(e=>f||t>=e.a&&n<=e.b||t+86400>=e.a&&n+86400<=e.b);r&&r.pauses.push(f||t>=r.a?{a:t,b:n}:{a:t+86400,b:n+86400})}let p=[],m=[];for(let e of d){e.pauses.sort((e,t)=>e.a-t.a);let n=[...e.pauses],r=e=>(e.a+e.b)/2;for(;;){if(f&&n.length<2){n.length=0;break}let t=-1,i=1/0;if(n.forEach((a,o)=>{let s=o>0?r(n[o-1]):f?r(n[n.length-1])-86400:e.a,c=o<n.length-1?r(n[o+1]):f?r(n[0])+86400:e.b,l=Math.min(r(a)-s,c-r(a));l<i&&(i=l,t=o)}),t<0||i>=21600)break;n.splice(t,1)}for(let t of e.pauses.filter(e=>!n.includes(e))){let e=h5(t.a,900),n=h5(t.b,900);n>e&&m.push({name:`Break`,from:m5(e),to:m5(n)})}let i=n.map(e=>h5(r(e),1800)),a=f?i:[h5(e.a,1800),...i,h5(e.b,1800)],o=f?i.map((e,t)=>({a:e,b:t<i.length-1?i[t+1]:i[0]+86400})):a.slice(0,-1).map((e,t)=>({a:e,b:a[t+1]}));if(f&&!o.length)return t;for(let e of o){let t=e.b-e.a,n=Math.round(t/(8*3600));if(n>=2&&Math.abs(t-n*8*3600)<=3600)for(let r=0;r<n;r++)p.push({a:h5(e.a+r*t/n,1800),b:h5(e.a+(r+1)*t/n,1800)});else t>=3600&&p.push(e)}}let h=e=>(e%86400+86400)%86400;return{shifts:p.sort((e,t)=>h(e.a)-h(t.a)).map((e,t)=>({name:`Shift ${t+1}`,start:m5(e.a),end:m5(e.b)})),stops:m}}function x5(e){let t=new Map;for(let n of e){if(!n.rule||!n.channels.length)continue;let e=`${n.rule}|${n.channels.map(e=>e.name).sort().join(`\0`)}`;t.set(e,[...t.get(e)??[],n])}return([...t.values()].filter(e=>e.length>=2).sort((e,t)=>t.length-e.length)[0]??[]).map(e=>({name:e.name,streams:[e.id]})).sort((e,t)=>e.name.localeCompare(t.name))}function S5(e){let t=new Map;for(let n of e){let e=n.includes(`.`)?n.indexOf(`.`):n.indexOf(`_`);e>0&&t.set(n.slice(0,e),[...t.get(n.slice(0,e))??[],n])}return[...t].filter(([,t])=>t.length>=2&&t.length<e.length).map(([e,t])=>({name:e,channels:t.sort()})).sort((e,t)=>e.name.localeCompare(t.name))}function C5(e,t){return Object.keys(e).filter(n=>{let r=e[n].filter(e=>!e.clock&&e.noise!==void 0&&e.flatS!==void 0&&e.n&&e.rateHz),i=r.reduce((e,t)=>e+t.n/t.rateHz,0),a=r.reduce((e,t)=>e+(t.flatRuns??0),0);return r.length>0&&r.every(e=>e.noise===0)&&i>0&&r.reduce((e,t)=>e+t.flatS,0)>=.9*i&&!(t>=10&&a>=.5*t)}).sort()}function w5(e){let t={};for(let n of e.streams)for(let e of n.channels)t[e.name]||(t[e.name]=e.unit);let n={};for(let[t,r]of Object.entries(e.health)){if(r.some(e=>e.clock))continue;let e=g5(r.filter(e=>e.moves!==!1));e&&(n[t]=e)}let r=v5(_5(e.recordings),e.tz),i=b5(r),a=y5(r);return{units:t,ranges:n,energy:Object.keys(t).filter(e=>d5.test(t[e].trim())).sort(),settings:C5(e.health,e.recordings.reduce((e,t)=>e+t.batches.length,0)),shifts:i.shifts,stops:[...i.stops,...a?[a]:[]],lines:x5(e.streams),machines:S5(Object.keys(t))}}function T5(e,t){let n=Object.create(null);for(let[t,r]of Object.entries(e.channels))n[t]=r;for(let e of[...Object.keys(t.units),...Object.keys(t.ranges),...t.settings])n[e]||(n[e]=Q3(t.units[e]??``));for(let[e,r]of Object.entries(n)){let i=r;!i.unit&&t.units[e]&&(i={...i,unit:t.units[e],unitSuggested:!0});let a=t.ranges[e];a&&i.lo===null&&i.hi===null&&(i={...i,lo:a.lo,hi:a.hi,rangeSuggested:!0}),t.energy.includes(e)&&i.role===null?i={...i,role:`energy`,suggested:!0}:t.settings.includes(e)&&i.role===null&&(i={...i,role:`setting`,suggested:!0}),n[e]=i}let r=e=>e.map(e=>({...e,suggested:!0})),i=new Set(Object.keys(n));return{...e,channels:n,shifts:e.shifts.length?e.shifts:r(t.shifts),stops:e.stops.length?e.stops:r(t.stops),lines:e.lines.length?e.lines:r(t.lines),units:e.units.length?e.units:r(t.machines.map(e=>({...e,channels:e.channels.filter(e=>i.has(e))})).filter(e=>e.channels.length))}}function E5(e){let t=new Map,n=(e,n)=>{for(let r of n)t.set(r,[...t.get(r)??[],e])},r=e=>e.filter(e=>e.suggested).length,i=(e,t)=>`${e} ${t}${e===1?``:`s`}`;r(e.shifts)&&n(i(r(e.shifts),`shift`),[`02`,`05`,`06`,`11`]),r(e.stops)&&n(i(r(e.stops),`planned stop`),[`05`,`06`]),r(e.lines)&&n(i(r(e.lines),`line`),[`10`]),r(e.units)&&n(i(r(e.units),`machine unit`),[`05`]);let a=Object.keys(e.channels).filter(t=>e.channels[t].role===`energy`&&e.channels[t].suggested);a.length&&n(`the energy channel ${a.sort()[0]}`,[`09`]);let o=Object.keys(e.channels).filter(t=>e.channels[t].role===`setting`&&e.channels[t].suggested);return o.length&&n(i(o.length,`adjustable setting`),[`08`]),t}var D5=Et({AI_NOTE:()=>o5,AI_SENTENCES:()=>2,AI_WORDS:()=>X8,ALPHA:()=>c4,CHANNEL_ROLES:()=>Y3,CHANNEL_ROLE_TEXT:()=>X3,EVIDENCE_TEXT:()=>W4,GOLDEN_SHARE:()=>l4,HealthAcc:()=>M6,MIN_GROUP:()=>5,OFF_GOLDEN_PCT:()=>2,PRESETS:()=>R3,PRESET_IDS:()=>L3,PROCESS_MAX:()=>Z3,REPORT_ROLES:()=>U4,SECTION_ROLES:()=>q4,SECTION_TITLES:()=>G4,aiInput:()=>s5,applyAi:()=>c5,applyInferred:()=>T5,applyPreset:()=>J3,assumedSections:()=>E5,buildReport:()=>q8,classify:()=>f4,completeness:()=>w6,confirmAll:()=>x6,confirmed:()=>y6,contextGaps:()=>S6,dateText:()=>h3,dateTimeText:()=>g3,emptyChannel:()=>Q3,emptyContext:()=>$3,energyChannel:()=>t6,evidenceLabel:()=>T3,exact:()=>e3,goldenRank:()=>u4,inferContext:()=>w5,listedFindings:()=>J8,moneyGaps:()=>C6,namesOf:()=>G3,num:()=>$4,pText:()=>w3,parseContext:()=>p6,pct1:()=>Z4,presetForIndustry:()=>B3,presetOf:()=>z3,roleOf:()=>e6,shiftOf:()=>g6,spanText:()=>v3,stopSpans:()=>v6,suggestedCount:()=>b6,term:()=>W3,usualRange:()=>N6,viewSections:()=>Y8});export{UZ as ANNOTATION_CONTROLS_ATTR,kt as ANNOTATION_KINDS,J$ as AxisState,bB as BEACON_STATS,r2 as BrowserRecorder,g0 as CAMERA_QUALITIES,Y3 as CHANNEL_ROLES,X3 as CHANNEL_ROLE_TEXT,tr as CHART_ALARM_FIELDS,s$ as CHART_KINDS,VB as CYCLE_TIME,E0 as CameraSender,PB as CycleRunner,FB as CycleSet,zt as DASHBOARD_GRID_COLS,Vt as DASHBOARD_GRID_GAP_PX,Bt as DASHBOARD_GRID_ROWS,Xz as DATASET_PALETTE,At as DEFAULT_ANNOTATION_WIDTH,tn as DEFAULT_AXIS_LINE,rn as DEFAULT_BEACON,nn as DEFAULT_GRID_LINE,pn as DEFAULT_TRACE_WIDTH,fn as DEFAULT_XYZ_POINT_RADIUS,dn as DEFAULT_XY_POINT_RADIUS,o1 as DELTA_SUFFIX,W4 as EVIDENCE_TEXT,g2 as EXPORT_TYPES,CT as FUNCTION_REFERENCE,F2 as HISTORY_PIXELS,M6 as HealthAcc,KQ as HistoryDataSource,EV as IMPORTABLE_EXT,_e as KIND_VIDEO,aB as KPI_STATS,ye as KRC_HEADER_BYTES,vB as KpiAcc,ME as KymoscopeError,rt as LEAF_KEYS,$e as LIVE_TIME_COLUMN,_0 as LOW_PRESET,h0 as LivePublisher,W$ as MAX_BAND_CELLS,U$ as MAX_GRID,Wn as MAX_PANEL_CAMERAS,Q2 as MAX_PARQUET_VALUES,Z2 as MAX_WIDE_CELLS,Gt as MIN_PANEL_H,Wt as MIN_PANEL_W,C as OPEN_STREAM_PASSWORD,R3 as PRESETS,L3 as PRESET_IDS,Z3 as PROCESS_MAX,P2 as RANGE_PARALLEL,U4 as REPORT_ROLES,W1 as RecordedVideoSource,d0 as RegistryError,yB as RuleRunner,G4 as SECTION_TITLES,It as SEVERITY_HEX,G1 as SPLIT_STEPS,T1 as UNLIMITED,DX as VIDEO_LIMIT_NOTICE,C$ as VIDEO_MAX_FRAGMENT,$T as WINDOW_FN_NAMES,T as WORKBOOK_EXPORT_AAD,s5 as aiInput,O as alertRuleAad,Y$ as alignSegment,D5 as analysis,c5 as applyAi,T5 as applyInferred,J3 as applyPreset,$t as arrangeAutoLayout,G$ as axisColumn,n1 as bandEdges,EB as bestCycleIndex,f as bindKeyAad,y2 as blockAad,N2 as blockCache,q0 as bufferLabel,ZW as buildEquation,wE as buildMathChannelsBlob,Q$ as buildReference,q8 as buildReport,OV as buildTree,Hn as cameraLabel,nr as chartAlarm,Ez as chartChannelCount,l$ as chartLabel,B2 as chooseLevel,sr as clampPct,qt as clampRectForKind,WQ as clipPiece,W2 as coalesce,Qn as coerceAlarmLine,Pt as coerceAnnotation,cX as colorAt,Zz as colorForDataset,nB as colorSchemeOf,dX as colorsCss,m as columnIsNumeric,cB as compareOp,r1 as compareToReference,w6 as completeness,JW as computePolyFit,YW as computeR2,x6 as confirmAll,y6 as confirmed,L1 as createEngine,tt as createRuleEvaluator,YB as cutCycle,NB as cycleRuleChannels,ZB as cycleTables,SB as cyclicChannels,a1 as decodeBand,E$ as decodeVideo,lZ as decorateColumnLabel,Nn as defaultAreaChartPanelSettings,jn as defaultBarChartPanelSettings,bn as defaultBoxPlotPanelSettings,Fn as defaultBubbleChartPanelSettings,zn as defaultCalibrationPanelSettings,Un as defaultCameraPanelSettings,Pn as defaultCdfChartPanelSettings,wn as defaultConfusionPanelSettings,Dn as defaultControlChartPanelSettings,Qz as defaultDatasetPalette,kn as defaultEmbeddingPanelSettings,An as defaultFlameGraphPanelSettings,Vn as defaultGanttPanelSettings,Rn as defaultGaugePanelSettings,Sn as defaultHeatmapPanelSettings,_n as defaultHistogramPanelSettings,En as defaultLossCurvePanelSettings,mn as defaultMultibandPanelSettings,On as defaultParallelCoordsPanelSettings,vn as defaultPolarPanelSettings,Bn as defaultQQPlotPanelSettings,Mn as defaultRadarPanelSettings,Tn as defaultRocPanelSettings,Ln as defaultSankeyPanelSettings,xn as defaultSpectrogramPanelSettings,yn as defaultSpectrumPanelSettings,Y1 as defaultSplit,In as defaultTreemapPanelSettings,Cn as defaultViolinPanelSettings,en as defaultXyAxisScaleSettings,hn as defaultXyPanelSettings,gn as defaultXyzPanelSettings,GB as definitionChannels,_ as deriveKey,S as deriveRawKeyBase64,j as deviceFingerprint,Jt as dragLayout,Q3 as emptyChannel,$3 as emptyContext,i1 as encodeBand,T$ as encodeVideo,nV as encryptWorkbookFile,t6 as energyChannel,ar as ensurePanelSettingsForPanels,iE as evalChannel,iB as eventWithin,T3 as evidenceLabel,a4 as exportHistoryTo,v2 as exportRecording,_2 as exportRecordingTo,nE as extractFreeIdentifiers,n4 as f32text,p0 as fetchUsage,WB as findCycles,b2 as footerLength,Jz as formatClockTick,Yz as formatClockValue,OB as formatLapValue,J1 as formatSplit,D$ as fragmentVideo,et as generateApiToken,i as generateDeviceKeyPair,I as generateRecoveryKeyPair,h as generateSalt,Kz as getClockTimeZone,y as getRawNonEmptyLines,Z$ as gridAt,CB as guessBeaconChannel,P as hashToken,R as historyKeyAad,p as importStreamKey,w5 as inferContext,te as inferParseConfig,Rz as isClockAxis,DV as isImportable,cZ as isMathChannelName,r4 as isoMicros,KB as kpiColumn,oB as kpiKey,qB as kpisOf,J8 as listedFindings,s0 as liveBytesPerSec,c1 as liveSegmentTracker,hB as localDay,q$ as localSeconds,b as makeKeyCheck,Rt as markToAnnotation,C6 as moneyGaps,G3 as namesOf,cn as newGaugeItem,lr as newMathChannel,Zt as newPanel,uB as newResetState,cr as newSeriesId,Dz as niceMajorStep,rB as observeColorScheme,gR as openDatasetFromText,C2 as openFooter,he as openMessage,S2 as openSealed,pz as openSession,Ie as openUnderProjectKey,v as openWithKey,ee as openWithPassword,Gn as panelCameras,V as parseColumnNames,ne as parseConfigsEqual,p6 as parseContext,BB as parseCycleDefinitions,t as parseDatasetWithConfig,tE as parseFormula,Me as parseKrc,Ve as parseKrcHeader,EE as parseMathChannelsFile,un as parseOptionalAxisRange,ir as parsePanelChartSettingsMap,B as parseRecoveryCode,q1 as parseSplit,H2 as pickSegments,U2 as pool,t1 as pooledSd,B3 as presetForIndustry,z3 as presetOf,uX as presetStops,H as projectConfigKeyAad,k as projectWrapAad,e as randomKey,q2 as readFooter,Y2 as readHistoryRange,UB as readSource,ke as recordingKeyAad,Re as recordingKeySealAad,fe as recoveryAttestationAad,We as recoveryCode,je as recoveryKeyAad,Be as recoveryPrivateKey,iZ as referenceBands,X$ as resample,dB as resetStep,er as resolveLinkedAlarms,e6 as roleOf,QB as rowsCsv,sB as ruleChannels,re as sealMessage,be as sealUnderProjectKey,ae as sealWithKey,Ne as sealWithPassword,He as senderBindKey,ce as senderBinding,Gz as setClockTimeZone,_B as shiftDay,UQ as slicePiece,GQ as splicePieces,Ee as splitApiKey,xB as splitLaps,Ke as streamKeyAad,de as subsampleIndices,qz as subscribeClockTimeZone,wB as suggestBeacon,b6 as suggestedCount,W3 as term,it as thresholdOf,mB as tzOffsetS,ue as unwrapForDevice,me as unwrapStreamKey,nt as validateRule,Fe as verifyKeyCheck,RV as verifyLicense,Oe as verifySenderBinding,Y8 as viewSections,D2 as warmHistoryDecoder,i4 as wideDay,ve as workbookBodyAad,$B as workbookExportAad,iV as workbookFileInfo,ge as workbookKeyAad,ie as wrapForDevice,gB as zonedInstant};
|