@kymoscope/sdk 0.26.0 → 0.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  /*! @kymoscope/sdk (c) 2026 Kymoscope. Proprietary software: use requires a license. See LICENSE.md. */
2
- import{$ as e,$n as t,A as n,B as r,Bn as i,C as a,Cn as o,D as s,E as c,Et as l,F as u,Fn as d,G as f,Gn as p,Gt as m,H as h,Hn as g,Ht as _,I as v,In as y,J as b,Jn as x,K as S,Kn as C,L as w,Ln as T,M as E,N as D,Nn as O,O as k,Ot as A,P as j,Pn as M,Q as N,Qn as P,R as F,Rn as I,S as L,Sn as R,St as z,T as B,Tn as V,Tt as ee,U as te,Un as H,Ut as ne,V as re,Vn as U,Vt as W,W as ie,Wn as ae,Wt as oe,X as se,Xn as ce,Y as le,Yn as ue,Z as de,Zn as fe,Zt as pe,_ as me,_n as he,_t as ge,a as _e,ar as ve,at as ye,b as be,bn as xe,bt as Se,c as Ce,cr as we,ct as Te,dr as Ee,dt as De,er as Oe,et as ke,fr as Ae,ft as je,g as Me,gt as Ne,h as Pe,hn as Fe,ht as Ie,i as Le,ir as Re,it as ze,j as Be,k as Ve,l as He,lr as Ue,lt as We,m as Ge,mt as Ke,nr as qe,nt as Je,o as Ye,or as Xe,ot as Ze,p as Qe,pt as $e,q as et,qn as tt,qt as nt,r as rt,rr as it,rt as at,s as ot,sr as st,st as ct,t as lt,tr as ut,tt as dt,u as ft,un as pt,ur as mt,ut as ht,v as gt,vt as _t,w as vt,wn as yt,x as bt,xn as xt,xt as St,y as Ct,yn as wt,yt as Tt,z as Et,zn as Dt}from"./importer-DXGqA1PR.js";import{i as Ot,n as kt,r as At,t as jt}from"./threshold-CEM3Svgm.js";import{createContext as Mt,forwardRef as Nt,memo as Pt,startTransition as Ft,useCallback as It,useContext as Lt,useEffect as G,useImperativeHandle as Rt,useLayoutEffect as K,useMemo as zt,useRef as q,useState as Bt,useSyncExternalStore as Vt}from"react";import{createPortal as Ht}from"react-dom";import{createRoot as Ut}from"react-dom/client";import{Fragment as Wt,jsx as J,jsxs as Gt}from"react/jsx-runtime";var Kt=[`text`,`brush`,`arrow`,`box`],qt={text:14,brush:3,arrow:2,box:2},Jt=/^#[0-9a-fA-F]{6}$/,Yt={text:[1,1],arrow:[2,2],box:[2,2],brush:[2,1/0]},Xt=e=>typeof e==`number`&&Number.isFinite(e);function Zt(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)&&Xt(e[0])&&Xt(e[1])).map(([e,t])=>[e,t]),[i,a]=Yt[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:Xt(t.width)&&t.width>0?Math.min(96,t.width):qt[n],...typeof t.text==`string`&&t.text!==``?{text:t.text}:{}}}function Qt(e){return Array.isArray(e)?e.map(Zt).filter(e=>e!==null):null}var $t={info:`#8a93a6`,warning:`#f5a524`,critical:`#e5484d`},en={info:`var(--text-muted, #8a93a6)`,warning:`var(--accent, #f5a524)`,critical:`var(--danger, #e5484d)`};function tn(e,t){return{id:`mark:${e.id}`,kind:`box`,anchor:`x`,points:[[e.t0,0],[e.t1??t,1]],color:$t[e.severity],width:1,...e.ruleName?{text:`${e.late?`Late · `:``}${e.ruleName}`}:{}}}var nn=96,rn=96,an=2,on={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},sn={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},cn=on,ln=sn;function un(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 dn(e,t,n,r=96){let i=on[e],a=sn[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 fn(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));if(n===`move`)return dn(e,{...t,x:t.x+c,y:t.y+l},o,s);let u=n===`resize`?`se`:n,{x:d,y:f,w:p,h:m}=t;if(u.includes(`e`)&&(p=Math.max(on[e],Math.min(t.w+c,o-t.x))),u.includes(`s`)&&(m=Math.max(sn[e],Math.min(t.h+l,s-t.y))),u.includes(`w`)){let n=t.x+t.w;d=Math.max(0,Math.min(t.x+c,n-on[e])),p=n-d}if(u.includes(`n`)){let n=t.y+t.h;f=Math.max(0,Math.min(t.y+l,n-sn[e])),m=n-f}return{x:d,y:f,w:p,h:m}}function pn(e,t,n){for(let r of t)if(r.id!==n&&un(e,r.rect))return!0;return!1}function mn(e,t,n=96){let r=on[e],i=sn[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=dn(e,{x:s,y:i,w:a,h:o},n);if(!pn(r,t,``))return r}return dn(e,{x:0,y:0,w:r,h:i},n)}function hn(e,t){return{id:crypto.randomUUID(),kind:e,rect:mn(e,t)}}function gn(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=gn(e-4).map(e=>({x:e.x*.5,y:e.y,w:e.w*.5,h:e.h})),n=gn(4).map(e=>({x:.5+e.x*.5,y:e.y,w:e.w*.5,h:e.h}));return[...t,...n]}function _n(e,t=96,n=96){let r=gn(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 vn(){return{scaleMin:``,scaleMax:``,majorStep:``,minorStep:``,alarm:null}}var yn={style:`dashed`,width:1,color:null},bn={style:`solid`,width:1,color:null},xn={enabled:!1,reference:`previous`,datasetId:null,datasetColor:`#94a3b8`,previousColor:`#64748b`},Sn=/^#[0-9a-f]{6}$/i;function Cn(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`&&Sn.test(t.datasetColor)?t.datasetColor:xn.datasetColor,previousColor:typeof t.previousColor==`string`&&Sn.test(t.previousColor)?t.previousColor:xn.previousColor}}var wn=[`#f5a524`,`#38bdf8`,`#22c55e`,`#f472b6`,`#a78bfa`,`#fb7185`];function Tn(e,t){return{id:crypto.randomUUID(),column:e,color:wn[t%wn.length],value:`last`,style:`arc`,min:``,max:``}}function En(e,t){if(!e||typeof e!=`object`)return null;let n=e;if(typeof n.column!=`string`)return null;let r=hr(n.alarm);return{id:typeof n.id==`string`&&n.id?n.id:`g${t}`,column:n.column,color:typeof n.color==`string`?n.color:wn[t%wn.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 Dn(e,t){let n=parseFloat(e),r=parseFloat(t);return Number.isFinite(n)&&Number.isFinite(r)&&n<r?[n,r]:void 0}var On=1.8,kn=4,An=1;function jn(){return{kind:`multiband`,series:[],addColumn:``,layout:`overlay`,xAxisLine:{...yn},yAxisLine:{...yn},gridLine:{...bn},lineWidth:1}}function Mn(e){return{kind:`xyscatter`,xyXCol:``,xyYCol:``,xyColorCol:null,xyColor:e,xyPointRadius:On,xyXAxisLine:{...yn},xyYAxisLine:{...yn},xyGridLine:{...bn},xyFit:null,xyXScale:vn(),xyYScale:vn()}}function Nn(e=4){return{kind:`xyzmesh`,xyzXCol:``,xyzYCol:``,xyzZCol:``,xyzViewMode:`3d`,xyzXScale:vn(),xyzYScale:vn(),xyzZScale:vn(),xyzPointRadius:e,showMesh:!1,meshStyle:`filled`,meshOpacity:.85}}function Pn(){return{kind:`histogram`,histColumn:``,histBins:0,histColor:`#38bdf8`,histNormal:!1,histLogY:!1}}function Fn(){return{kind:`polar`,polarAngleCol:``,polarRadiusCol:``,polarColor:`#a78bfa`,polarMode:`waveform`,polarRadiusMin:``,polarRadiusMax:``}}function In(){return{kind:`spectrum`,specSignalCol:``,specTimeCol:``,specSampleRate:`1000`,specXMode:`hz`,specYMode:`amplitude`,specWindow:`hann`,specColor:`#34d399`,specLogX:!1}}function Ln(){return{kind:`boxplot`,boxValueCol:``,boxGroupCol:``,boxColor:`#fb923c`,boxWhiskers:`1.5iqr`}}function Rn(){return{kind:`spectrogram`,sgSignalCol:``,sgTimeCol:``,sgSampleRate:`1000`,sgWindowSize:512,sgOverlap:.5,sgWinFunc:`hann`,sgYMode:`db`,sgLogFreq:!1}}function zn(){return{kind:`heatmap`,hmMode:`binned`,hmColumns:[],hmXCol:``,hmYCol:``,hmValueCol:``,hmXBins:6,hmYBins:6,hmXMin:``,hmXMax:``,hmYMin:``,hmYMax:``,hmShowValues:!0,hmColorScheme:`diverging`}}function Bn(){return{kind:`violin`,vlValueCol:``,vlGroupCol:``,vlColor:`#818cf8`,vlShowBox:!0,vlBandwidth:``,vlOrientation:`vertical`}}function Vn(){return{kind:`confusion`,cfActualCol:``,cfPredictedCol:``,cfNormalize:!1}}function Hn(){return{kind:`roc`,rocScoreCol:``,rocLabelCol:``,rocMode:`roc`,rocColor:`#f472b6`}}function Un(){return{kind:`losscurve`,lcXCol:``,lcLeftCols:[],lcRightCols:[]}}function Wn(){return{kind:`controlchart`,ccValueCol:``,ccSubgroupCol:``,ccSigmaLevel:3,ccColor:`#22d3ee`}}function Gn(){return{kind:`parallelcoords`,pcColumns:[],pcColorByCol:``,pcColor:`#64748b`}}function Kn(){return{kind:`embedding`,emXCol:``,emYCol:``,emColorCol:``,emColorMode:`categorical`,emLabelCol:``,emPointSize:3,emColor:`#a78bfa`}}function qn(){return{kind:`flamegraph`,fgNameCol:``,fgParentCol:``,fgValueCol:``,fgDirection:`topdown`}}function Jn(){return{kind:`barchart`,bcCategoryCol:``,bcValueCols:[],bcMode:`grouped`,bcHorizontal:!1}}function Yn(){return{kind:`radar`,rdAxesCols:[],rdGroupCol:``,rdColor:`#38bdf8`,rdFill:!0}}function Xn(){return{kind:`areachart`,acXCol:``,acYCols:[],acStacked:!1}}function Zn(){return{kind:`cdfchart`,cdValueCols:[],cdComplement:!1,cdLogX:!1}}function Qn(){return{kind:`bubblechart`,bbXCol:``,bbYCol:``,bbSizeCol:``,bbColorCol:``,bbColorMode:`categorical`,bbColor:`#64748b`,bbMaxRadius:24}}function $n(){return{kind:`treemap`,tmNameCol:``,tmParentCol:``,tmValueCol:``}}function er(){return{kind:`sankey`,skSourceCol:``,skTargetCol:``,skValueCol:``}}function tr(){return{kind:`gauge`,ggGauges:[]}}function nr(){return{kind:`calibration`,cbScoreCol:``,cbLabelCol:``,cbBins:10,cbColor:`#38bdf8`}}function rr(){return{kind:`qqplot`,qqValueCol:``,qqMode:`normal`,qqRefCol:``,qqColor:`#a78bfa`}}function ir(){return{kind:`gantt`,gtLabelCol:``,gtStartCol:``,gtEndCol:``,gtGroupCol:``}}function ar(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 or=()=>({kind:`camera`,cameraStreamId:``,cameras:[],syncStreamId:``,offsetMs:0,fit:`contain`}),sr=9;function cr(e){return e.cameraStreamId?e.cameras?.[0]===e.cameraStreamId?e.cameras.slice(0,9):[e.cameraStreamId]:[]}function lr(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 ur(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 dr(e,t){return ur(e)?e:{...t}}function fr(e){if(!e||typeof e!=`object`)return!1;let t=e;return t.kind===`multiband`&&Array.isArray(t.series)&&t.series.every(lr)&&typeof t.addColumn==`string`}function pr(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 mr(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 hr(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`&&gr.test(t.ruleId)?{ruleId:t.ruleId}:{}}}var gr=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function _r(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 vr){let t=vr[e.kind],n=r(i[t]);n!==i[t]&&o(t,n)}return a||e}var vr={histogram:`histAlarm`,spectrum:`specAlarm`,areachart:`acAlarm`,losscurve:`lcAlarm`,cdfchart:`cdAlarm`,bubblechart:`bbAlarm`,boxplot:`boxAlarm`,violin:`vlAlarm`,barchart:`bcAlarm`,gantt:`gtAlarm`};function yr(e){if(!e||!(e.kind in vr))return null;let t=e[vr[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 br(e){let t=vn();if(!e||typeof e!=`object`)return t;let n=e,r=hr(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 xr(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(fr(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:hr(e.alarm)}:e):e.series,addColumn:e.addColumn,layout:e.layout===`parallel`?`parallel`:`overlay`,xAxisLine:dr(e.xAxisLine,yn),yAxisLine:dr(e.yAxisLine,yn),gridLine:dr(e.gridLine,bn),lineWidth:typeof e.lineWidth==`number`&&Number.isFinite(e.lineWidth)?Math.min(6,Math.max(.5,e.lineWidth)):1,...Cn(e.beacon)?{beacon:Cn(e.beacon)}:{},...e.envelope===!0?{envelope:!0}:{}}}else if(pr(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:dr(e.xyXAxisLine,yn),xyYAxisLine:dr(e.xyYAxisLine,yn),xyGridLine:dr(e.xyGridLine,bn),xyFit:a,xyXScale:br(e.xyXScale),xyYScale:br(e.xyYScale)}}else if(mr(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??br(n.xyzXScale),xyzYScale:a??br(n.xyzYScale),xyzZScale:o??br(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=En(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:cr({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]?Qt(n?.annotations):null;e?.length&&(r[t]={...r[t],annotations:e});let i=r[t]?vr[r[t].kind]:void 0,a=i?hr(n[i]):null;i&&a&&(r[t]={...r[t],[i]:a})}return r}function Sr(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]=jn(),a=!0)}else if(t.kind===`xyscatter`){let e=i[t.id];(!e||e.kind!==`xyscatter`)&&(i[t.id]=Mn(n),a=!0)}else if(t.kind===`xyzmesh`){let e=i[t.id];(!e||e.kind!==`xyzmesh`)&&(i[t.id]=Nn(r),a=!0)}else if(t.kind===`histogram`){let e=i[t.id];(!e||e.kind!==`histogram`)&&(i[t.id]=Pn(),a=!0)}else if(t.kind===`polar`){let e=i[t.id];(!e||e.kind!==`polar`)&&(i[t.id]=Fn(),a=!0)}else if(t.kind===`spectrum`){let e=i[t.id];(!e||e.kind!==`spectrum`)&&(i[t.id]=In(),a=!0)}else if(t.kind===`boxplot`){let e=i[t.id];(!e||e.kind!==`boxplot`)&&(i[t.id]=Ln(),a=!0)}else t.kind===`spectrogram`?(!i[t.id]||i[t.id].kind!==`spectrogram`)&&(i[t.id]=Rn(),a=!0):t.kind===`heatmap`?(!i[t.id]||i[t.id].kind!==`heatmap`)&&(i[t.id]=zn(),a=!0):t.kind===`violin`?(!i[t.id]||i[t.id].kind!==`violin`)&&(i[t.id]=Bn(),a=!0):t.kind===`confusion`?(!i[t.id]||i[t.id].kind!==`confusion`)&&(i[t.id]=Vn(),a=!0):t.kind===`roc`?(!i[t.id]||i[t.id].kind!==`roc`)&&(i[t.id]=Hn(),a=!0):t.kind===`losscurve`?(!i[t.id]||i[t.id].kind!==`losscurve`)&&(i[t.id]=Un(),a=!0):t.kind===`controlchart`?(!i[t.id]||i[t.id].kind!==`controlchart`)&&(i[t.id]=Wn(),a=!0):t.kind===`parallelcoords`?(!i[t.id]||i[t.id].kind!==`parallelcoords`)&&(i[t.id]=Gn(),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]=qn(),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]=Yn(),a=!0):t.kind===`areachart`?(!i[t.id]||i[t.id].kind!==`areachart`)&&(i[t.id]=Xn(),a=!0):t.kind===`cdfchart`?(!i[t.id]||i[t.id].kind!==`cdfchart`)&&(i[t.id]=Zn(),a=!0):t.kind===`bubblechart`?(!i[t.id]||i[t.id].kind!==`bubblechart`)&&(i[t.id]=Qn(),a=!0):t.kind===`treemap`?(!i[t.id]||i[t.id].kind!==`treemap`)&&(i[t.id]=$n(),a=!0):t.kind===`sankey`?(!i[t.id]||i[t.id].kind!==`sankey`)&&(i[t.id]=er(),a=!0):t.kind===`gauge`?(!i[t.id]||i[t.id].kind!==`gauge`)&&(i[t.id]=tr(),a=!0):t.kind===`calibration`?(!i[t.id]||i[t.id].kind!==`calibration`)&&(i[t.id]=nr(),a=!0):t.kind===`qqplot`?(!i[t.id]||i[t.id].kind!==`qqplot`)&&(i[t.id]=rr(),a=!0):t.kind===`gantt`?(!i[t.id]||i[t.id].kind!==`gantt`)&&(i[t.id]=ir(),a=!0):t.kind===`camera`&&(!i[t.id]||i[t.id].kind!==`camera`)&&(i[t.id]=or(),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 Cr(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 wr(e){return e===null||typeof e==`number`&&e>0?{liveWindowSeconds:e}:{}}var Tr=new WeakMap;function Er(e){return Number.isNaN(e)?0:Math.min(100,Math.max(0,e))}function Dr(){return crypto.randomUUID()}function Or(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 kr(){return kr=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},kr.apply(null,arguments)}var Ar={relTol:1e-12,absTol:1e-15,matrix:`Matrix`,number:`number`,numberFallback:`number`,precision:64,predictable:!1,randomSeed:null,legacySubset:!1};function jr(e,t){if(Nr(e,t)||Pr(e,t))return e[t];throw Lr(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 Mr(e,t,n){if(Nr(e,t)||Pr(e,t))return e[t]=n,n;throw Error(`No access to property "${t}"`)}function Nr(e,t){return Rr(e)?!(t in Object.prototype):!1}function Pr(e,t){return Array.isArray(e)?typeof t==`number`||typeof t==`string`&&Fr(t)||t===`length`:!1}function Fr(e){return/^\d+$/.test(e)}function Ir(e,t){if(!Lr(e,t))throw Error(`No access to method "`+t+`"`);return e[t]}function Lr(e,t){return e==null||typeof e[t]!=`function`||Gi(e,t)&&Object.getPrototypeOf&&t in Object.getPrototypeOf(e)?!1:zr.has(t)?!0:!(t in Object.prototype||t in Function.prototype)}function Rr(e){return typeof e==`object`&&e&&e.constructor===Object}var zr=new Set([`toString`,`valueOf`,`toLocaleString`]),Br=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 jr(this.wrappedObject,e)}set(e,t){return Mr(this.wrappedObject,e,t),this}has(e){return Nr(this.wrappedObject,e)&&e in this.wrappedObject}entries(){return Hr(this.keys(),e=>[e,this.get(e)])}forEach(e){for(var t of this.keys())e(this.get(t),t,this)}delete(e){Nr(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}},Vr=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 Hr(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 Hr(e,t){return{next:()=>{var n=e.next();return n.done?n:{value:t(n.value),done:!1}}}}function Ur(){return new Map}function Wr(e){if(!e)return Ur();if(pi(e))return e;if(fi(e))return new Br(e);throw Error(`createMap can create maps from objects or Maps`)}function Gr(e){if(e instanceof Br)return e.wrappedObject;var t={};for(var n of e.keys())Mr(t,n,e.get(n));return t}function Kr(e){return typeof e==`number`}function qr(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 Jr(e){return typeof e==`bigint`}function Yr(e){return e&&typeof e==`object`&&Object.getPrototypeOf(e).isComplex===!0||!1}function Xr(e){return e&&typeof e==`object`&&Object.getPrototypeOf(e).isFraction===!0||!1}function Zr(e){return e&&e.constructor.prototype.isUnit===!0||!1}function Qr(e){return typeof e==`string`}var $r=Array.isArray;function ei(e){return e&&e.constructor.prototype.isMatrix===!0||!1}function ti(e){return Array.isArray(e)||ei(e)}function ni(e){return e&&e.isDenseMatrix&&e.constructor.prototype.isMatrix===!0||!1}function ri(e){return e&&e.isSparseMatrix&&e.constructor.prototype.isMatrix===!0||!1}function ii(e){return e&&e.constructor.prototype.isRange===!0||!1}function ai(e){return e&&e.constructor.prototype.isIndex===!0||!1}function oi(e){return typeof e==`boolean`}function si(e){return e&&e.constructor.prototype.isResultSet===!0||!1}function ci(e){return e&&e.constructor.prototype.isHelp===!0||!1}function li(e){return typeof e==`function`}function ui(e){return e instanceof Date}function di(e){return e instanceof RegExp}function fi(e){return!!(e&&typeof e==`object`&&e.constructor===Object&&!Yr(e)&&!Xr(e))}function pi(e){return e?e instanceof Map||e instanceof Br||typeof e.set==`function`&&typeof e.get==`function`&&typeof e.keys==`function`&&typeof e.has==`function`:!1}function mi(e){return pi(e)&&pi(e.a)&&pi(e.b)}function hi(e){return pi(e)&&fi(e.wrappedObject)}function gi(e){return e===null}function _i(e){return e===void 0}function vi(e){return e&&e.isAccessorNode===!0&&e.constructor.prototype.isNode===!0||!1}function yi(e){return e&&e.isArrayNode===!0&&e.constructor.prototype.isNode===!0||!1}function bi(e){return e&&e.isAssignmentNode===!0&&e.constructor.prototype.isNode===!0||!1}function xi(e){return e&&e.isBlockNode===!0&&e.constructor.prototype.isNode===!0||!1}function Si(e){return e&&e.isConditionalNode===!0&&e.constructor.prototype.isNode===!0||!1}function Ci(e){return e&&e.isConstantNode===!0&&e.constructor.prototype.isNode===!0||!1}function wi(e){return Ci(e)||Ai(e)&&e.args.length===1&&Ci(e.args[0])&&`-+~`.includes(e.op)}function Ti(e){return e&&e.isFunctionAssignmentNode===!0&&e.constructor.prototype.isNode===!0||!1}function Ei(e){return e&&e.isFunctionNode===!0&&e.constructor.prototype.isNode===!0||!1}function Di(e){return e&&e.isIndexNode===!0&&e.constructor.prototype.isNode===!0||!1}function Oi(e){return e&&e.isNode===!0&&e.constructor.prototype.isNode===!0||!1}function ki(e){return e&&e.isObjectNode===!0&&e.constructor.prototype.isNode===!0||!1}function Ai(e){return e&&e.isOperatorNode===!0&&e.constructor.prototype.isNode===!0||!1}function ji(e){return e&&e.isParenthesisNode===!0&&e.constructor.prototype.isNode===!0||!1}function Mi(e){return e&&e.isRangeNode===!0&&e.constructor.prototype.isNode===!0||!1}function Ni(e){return e&&e.isRelationalNode===!0&&e.constructor.prototype.isNode===!0||!1}function Pi(e){return e&&e.isSymbolNode===!0&&e.constructor.prototype.isNode===!0||!1}function Fi(e){return e&&e.constructor.prototype.isChain===!0||!1}function Ii(e){var t=typeof e;return t===`object`?e===null?`null`:qr(e)?`BigNumber`:e.constructor&&e.constructor.name?e.constructor.name:`Object`:t}function Li(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 Li(e)});if(e instanceof Date)return new Date(e.valueOf());if(qr(e))return e;if(fi(e))return Ri(e,Li);if(t===`function`)return e;throw TypeError(`Cannot clone: unknown type of value (value: ${e})`)}function Ri(e,t){var n={};for(var r in e)Gi(e,r)&&(n[r]=t(e[r]));return n}function zi(e,t){for(var n in t)Gi(t,n)&&(e[n]=t[n]);return e}function Bi(e,t){if(Array.isArray(t))throw TypeError(`Arrays are not supported by deepExtend`);for(var n in t)if(Gi(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?Bi(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 Vi(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(!Vi(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)||!Vi(e[n],t[n]))return!1;for(n in t)if(!(n in e))return!1;return!0}else return e===t}function Hi(e){var t={};return Ui(e,t),t}function Ui(e,t){for(var n in e)if(Gi(e,n)){var r=e[n];typeof r==`object`&&r?Ui(r,t):t[n]=r}}function Wi(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 Gi(e,t){return e&&Object.hasOwnProperty.call(e,t)}function Ki(e){return e&&typeof e.factory==`function`}function qi(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 Ji=[`Matrix`,`Array`],Yi=[`number`,`BigNumber`,`bigint`,`Fraction`];function Xi(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=Li(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=Li(e);Zi(r,`matrix`,Ji),Zi(r,`number`,Yi),Bi(e,r);var o=Li(e);return t(`config`,o,a,Li(r)),o}else return Li(e)}return n.MATRIX_OPTIONS=Ji,n.NUMBER_OPTIONS=Yi,Object.keys(Ar).forEach(t=>{Object.defineProperty(n,t,{get:()=>e[t],enumerable:!0,configurable:!0})}),n}function Zi(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 Qi=mt(((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=ae(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=ie(e).map(D);let n=t.length,r=D(ae(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)?ae(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=ae(n),a=ae(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,oe(arguments,0,t).concat([oe(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 ce(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=>pe(e)?de(e.referToSelf.callback):fe(e)?ue(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(pe(s))r[o]=s.referToSelf.callback(n),r[o].referToSelf=s.referToSelf,i[o]=!0,e=!1;else if(fe(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 U(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,_e),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,U=g?f[2].implementation:n,W=_?f[3].implementation:n,ie=v?f[4].implementation:n,ae=y?f[5].implementation:n,oe=m?f[0].params.length:-1,se=h?f[1].params.length:-1,ce=g?f[2].params.length:-1,le=_?f[3].params.length:-1,ue=v?f[4].params.length:-1,de=y?f[5].params.length:-1,fe=b?6:0,pe=f.length,me=f.map(e=>e.test),he=f.map(e=>e.implementation),ge=function(){for(let e=fe;e<pe;e++)if(me[e](arguments))return he[e].apply(this,arguments);return d.onMismatch(e,arguments,f)};function _e(e,t){return arguments.length===oe&&S(e)&&N(t)?te.apply(this,arguments):arguments.length===se&&w(e)&&P(t)?H.apply(this,arguments):arguments.length===ce&&k(e)&&F(t)?U.apply(this,arguments):arguments.length===le&&A(e)&&I(t)?W.apply(this,arguments):arguments.length===ue&&j(e)&&R(t)?ie.apply(this,arguments):arguments.length===de&&M(e)&&B(t)?ae.apply(this,arguments):ge.apply(this,arguments)}try{Object.defineProperty(_e,`name`,{value:e})}catch{}return _e.signatures=o,_e._typedFunctionData={signatures:f,signatureMap:p},_e}function W(e,t,n){throw N(e,t,n)}function ie(e){return oe(e,0,e.length-1)}function ae(e){return e[e.length-1]}function oe(e,t,n){return Array.prototype.slice.call(e,t,n)}function se(e,t){for(let n=0;n<e.length;n++)if(t(e[n]))return e[n]}function ce(e,t){return Array.prototype.concat.apply([],e.map(t))}function le(){let e=ie(arguments).map(e=>x(T(e))),t=ae(arguments);if(typeof t!=`function`)throw TypeError(`Callback function expected as last argument`);return ue(e,t)}function ue(e,t){return{referTo:{references:e,callback:t}}}function de(e){if(typeof e!=`function`)throw TypeError(`Callback function expected as first argument`);return{referToSelf:{callback:e}}}function fe(e){return e&&typeof e.referTo==`object`&&Array.isArray(e.referTo.references)&&typeof e.referTo.callback==`function`}function pe(e){return e&&typeof e.referToSelf==`object`&&typeof e.referToSelf.callback==`function`}function me(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 he(e){let t;for(let n in e)Object.prototype.hasOwnProperty.call(e,n)&&(_(e[n])||typeof e[n].signature==`string`)&&(t=me(t,e[n].name));return t}function ge(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 _e=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=he(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=me(r,s)),ge(i,o)}return U(r||``,i)},d.create=i,d.createCount=_e.createCount,d.onMismatch=W,d.throwMismatchError=W,d.createError=N,d.clear=m,d.clearConversions=h,d.addTypes=p,d._findType=f,d.referTo=le,d.referToSelf=de,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 ve(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};ve(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){ve(e);let t=f(e.to),n=se(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 Y(e,t,n,r){function i(r){var i=qi(r,t.map(na));return ea(e,t,r),n(i)}return i.isFactory=!0,i.fn=e,i.dependencies=t.slice().sort(),r&&(i.meta=r),i}function $i(e){return typeof e==`function`&&typeof e.fn==`string`&&Array.isArray(e.dependencies)}function ea(e,t,n){if(!t.filter(e=>!ta(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 ta(e){return e&&e[0]===`?`}function na(e){return e&&e[0]===`?`?e.slice(1):e}function ra(e){return typeof e==`boolean`?!0:Number.isFinite(e)?e===Math.round(e):!1}function ia(e,t){if(t.number===`bigint`)try{BigInt(e)}catch{return t.numberFallback}return t.number}var aa=Math.sign||function(e){return e>0?1:e<0?-1:0},oa=Math.log2||function(e){return Math.log(e)/Math.LN2},sa=Math.log10||function(e){return Math.log(e)/Math.LN10},ca=Math.log1p||function(e){return Math.log(e+1)},la=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},ua=Math.expm1||function(e){return e>=2e-4||e<=-2e-4?Math.exp(e)-1:e+e*e/2+e*e*e/6};function da(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(!ra(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(!ra(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 fa(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}=pa(t);switch(n){case`fixed`:return ga(e,r);case`exponential`:return _a(e,r);case`engineering`:return ha(e,r);case`bin`:return da(e,2,i);case`oct`:return da(e,8,i);case`hex`:return da(e,16,i);case`auto`:return va(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 pa(e){var t=`auto`,n,r;if(e!==void 0)if(Kr(e))n=e;else if(qr(e))n=e.toNumber();else if(fi(e))e.precision!==void 0&&(n=Aa(e.precision,()=>{throw Error(`Option "precision" must be a number or BigNumber`)})),e.wordSize!==void 0&&(r=Aa(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 ma(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 ha(e,t){if(isNaN(e)||!Number.isFinite(e))return String(e);var n=ya(ma(e),t),r=n.exponent,i=n.coefficients,a=r%3==0?r:r<0?r-3-r%3:r-r%3;if(Kr(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=Kr(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 ga(e,t){if(isNaN(e)||!Number.isFinite(e))return String(e);var n=ma(e),r=typeof t==`number`?ya(n,n.exponent+1+t):n,i=r.coefficients,a=r.exponent+1,o=a+(t||0);return i.length<o&&(i=i.concat(ba(o-i.length))),a<0&&(i=ba(-a+1).concat(i),a=1),a<i.length&&i.splice(a,0,a===0?`0.`:`.`),r.sign+i.join(``)}function _a(e,t){if(isNaN(e)||!Number.isFinite(Number(e)))return String(e);var n=ma(e),r=t?ya(n,t):n,i=r.coefficients,a=r.exponent;i.length<t&&(i=i.concat(ba(t-i.length)));var o=i.shift();return r.sign+o+(i.length>0?`.`+i.join(``):``)+`e`+(a>=0?`+`:``)+a}function va(e,t,n){if(isNaN(e)||!Number.isFinite(e))return String(e);var r=ja(n?.lowerExp,-3),i=ja(n?.upperExp,5),a=ma(e),o=t?ya(a,t):a;if(o.exponent<r||o.exponent>=i)return _a(e,t);var s=o.coefficients,c=o.exponent;s.length<t&&(s=s.concat(ba(t-s.length))),s=s.concat(ba(c-s.length+1+(s.length<t?t-s.length:0))),s=ba(-c).concat(s);var l=c>0?c:0;return l<s.length-1&&s.splice(l+1,0,`.`),o.sign+s.join(``)}function ya(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 ba(e){for(var t=[],n=0;n<e;n++)t.push(0);return t}function xa(e){return e.toExponential().replace(/e.*$/,``).replace(/^0\.?0*|\./,``).length}function Sa(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 Ca=Math.acosh||function(e){return Math.log(Math.sqrt(e*e-1)+e)},wa=Math.asinh||function(e){return Math.log(Math.sqrt(e*e+1)+e)},Ta=Math.atanh||function(e){return Math.log((1+e)/(1-e))/2},Ea=Math.cosh||function(e){return(Math.exp(e)+Math.exp(-e))/2},Da=Math.sinh||function(e){return(Math.exp(e)-Math.exp(-e))/2},Oa=Math.tanh||function(e){var t=Math.exp(2*e);return(t-1)/(t+1)};function ka(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 Aa(e,t){if(Kr(e))return e;if(qr(e))return e.toNumber();t()}function ja(e,t){return Kr(e)?e:qr(e)?e.toNumber():t}var Ma=Ae(Qi(),1),Na=function(){return Na=Ma.default.create,Ma.default},Pa=Y(`typed`,[`?BigNumber`,`?Complex`,`?DenseMatrix`,`?Fraction`],function(e){var{BigNumber:t,Complex:n,DenseMatrix:r,Fraction:i}=e,a=Na();return a.clear(),a.addTypes([{name:`number`,test:Kr},{name:`Complex`,test:Yr},{name:`BigNumber`,test:qr},{name:`bigint`,test:Jr},{name:`Fraction`,test:Xr},{name:`Unit`,test:Zr},{name:`identifier`,test:e=>Qr&&/^(?:[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:Qr},{name:`Chain`,test:Fi},{name:`Array`,test:$r},{name:`Matrix`,test:ei},{name:`DenseMatrix`,test:ni},{name:`SparseMatrix`,test:ri},{name:`Range`,test:ii},{name:`Index`,test:ai},{name:`boolean`,test:oi},{name:`ResultSet`,test:si},{name:`Help`,test:ci},{name:`function`,test:li},{name:`Date`,test:ui},{name:`RegExp`,test:di},{name:`null`,test:gi},{name:`undefined`,test:_i},{name:`AccessorNode`,test:vi},{name:`ArrayNode`,test:yi},{name:`AssignmentNode`,test:bi},{name:`BlockNode`,test:xi},{name:`ConditionalNode`,test:Si},{name:`ConstantNode`,test:Ci},{name:`FunctionNode`,test:Ei},{name:`FunctionAssignmentNode`,test:Ti},{name:`IndexNode`,test:Di},{name:`Node`,test:Oi},{name:`ObjectNode`,test:ki},{name:`OperatorNode`,test:Ai},{name:`ParenthesisNode`,test:ji},{name:`RangeNode`,test:Mi},{name:`RelationalNode`,test:Ni},{name:`SymbolNode`,test:Pi},{name:`Map`,test:pi},{name:`Object`,test:fi}]),a.addConversions([{from:`number`,to:`BigNumber`,convert:function(e){if(t||Fa(e),xa(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||Ia(e),new n(e,0)}},{from:`BigNumber`,to:`Complex`,convert:function(e){return n||Ia(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||Fa(e),new t(e.toString())}},{from:`bigint`,to:`Fraction`,convert:function(e){return i||Ra(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||Ia(e),new n(e.valueOf(),0)}},{from:`number`,to:`Fraction`,convert:function(e){i||Ra(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||Fa(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||Ra(e);try{return new i(e)}catch{throw Error(`Cannot convert "`+e+`" to Fraction`)}}},{from:`string`,to:`Complex`,convert:function(e){n||Ia(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||Fa(e),new t(+e)}},{from:`boolean`,to:`bigint`,convert:function(e){return BigInt(+e)}},{from:`boolean`,to:`Fraction`,convert:function(e){return i||Ra(e),new i(+e)}},{from:`boolean`,to:`string`,convert:function(e){return String(e)}},{from:`Array`,to:`Matrix`,convert:function(e){return r||La(),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&&ti(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&&ti(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 Fa(e){throw Error(`Cannot convert value ${e} into a BigNumber: no class 'BigNumber' provided`)}function Ia(e){throw Error(`Cannot convert value ${e} into a Complex number: no class 'Complex' provided`)}function La(){throw Error(`Cannot convert array into a Matrix: no class 'DenseMatrix' provided`)}function Ra(e){throw Error(`Cannot convert value ${e} into a Fraction, no class 'Fraction' provided.`)}var za=Y(`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}),Ba=9e15,Va=1e9,Ha=`0123456789abcdef`,Ua=`2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058`,Wa=`3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789`,Ga={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-Ba,maxE:Ba,crypto:!1},Ka,qa,Ja=!0,Ya=`[DecimalError] `,Xa=Ya+`Invalid argument: `,Za=Ya+`Precision limit exceeded`,Qa=Ya+`crypto unavailable`,$a=`[object Decimal]`,eo=Math.floor,to=Math.pow,no=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,ro=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,io=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,ao=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,oo=1e7,so=7,co=9007199254740991,lo=Ua.length-1,uo=Wa.length-1,X={toStringTag:$a};X.absoluteValue=X.abs=function(){var e=new this.constructor(this);return e.s<0&&(e.s=1),vo(e)},X.ceil=function(){return vo(new this.constructor(this),this.e+1,2)},X.clampedTo=X.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(Xa+t);return n=r.cmp(e),n<0?e:r.cmp(t)>0?t:new i(r)},X.comparedTo=X.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},X.cosine=X.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())+so,r.rounding=1,n=go(r,Io(r,n)),r.precision=e,r.rounding=t,vo(qa==2||qa==3?n.neg():n,e,t,!0)):new r(1):new r(NaN)},X.cubeRoot=X.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(Ja=!1,a=u.s*to(u.s*u,1/3),!a||Math.abs(a)==1/0?(n=fo(u.d),e=u.e,(a=(e-n.length+1)%3)&&(n+=a==1||a==-2?`0`:`00`),a=to(n,1/3),e=eo((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=_o(l.plus(u).times(s),l.plus(c),o+2,1),fo(s.d).slice(0,o)===(n=fo(r.d)).slice(0,o))if(n=n.slice(o-3,o+1),n==`9999`||!i&&n==`4999`){if(!i&&(vo(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`)&&(vo(r,e+1,1),t=!r.times(r).times(r).eq(u));break}return Ja=!0,vo(r,e,d.rounding,t)},X.decimalPlaces=X.dp=function(){var e,t=this.d,n=NaN;if(t){if(e=t.length-1,n=(e-eo(this.e/so))*so,e=t[e],e)for(;e%10==0;e/=10)n--;n<0&&(n=0)}return n},X.dividedBy=X.div=function(e){return _o(this,new this.constructor(e))},X.dividedToIntegerBy=X.divToInt=function(e){var t=this,n=t.constructor;return vo(_o(t,new n(e),0,1,1),n.precision,n.rounding)},X.equals=X.eq=function(e){return this.cmp(e)===0},X.floor=function(){return vo(new this.constructor(this),this.e+1,3)},X.greaterThan=X.gt=function(e){return this.cmp(e)>0},X.greaterThanOrEqualTo=X.gte=function(e){var t=this.cmp(e);return t==1||t===0},X.hyperbolicCosine=X.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/Fo(4,e)).toString()):(e=16,t=`2.3283064365386962890625e-10`),a=Po(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 vo(a,o.precision=n,o.rounding=r,!0)},X.hyperbolicSine=X.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=Po(a,2,i,i,!0);else{e=1.4*Math.sqrt(r),e=e>16?16:e|0,i=i.times(1/Fo(5,e)),i=Po(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,vo(i,t,n,!0)},X.hyperbolicTangent=X.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,_o(n.sinh(),n.cosh(),r.precision=e,r.rounding=t)):new r(n.s)},X.inverseCosine=X.acos=function(){var e=this,t=e.constructor,n=e.abs().cmp(1),r=t.precision,i=t.rounding;return n===-1?e.isZero()?So(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()?So(t,r,i):new t(0):new t(NaN)},X.inverseHyperbolicCosine=X.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,Ja=!1,n=n.times(n).minus(1).sqrt().plus(n),Ja=!0,r.precision=e,r.rounding=t,n.ln()):new r(n)},X.inverseHyperbolicSine=X.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,Ja=!1,n=n.times(n).plus(1).sqrt().plus(n),Ja=!0,r.precision=e,r.rounding=t,n.ln())},X.inverseHyperbolicTangent=X.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?vo(new a(i),e,t,!0):(a.precision=n=r-i.e,i=_o(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)},X.inverseSine=X.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=So(a,n+4,r).times(.5),e.s=i.s,e):new a(NaN))},X.inverseTangent=X.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<=uo)return o=So(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<=uo)return o=So(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/so+2|0),e=n;e;--e)l=l.div(l.times(l).plus(1).sqrt().plus(1));for(Ja=!1,t=Math.ceil(s/so),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)),Ja=!0,vo(o,u.precision=d,u.rounding=f,!0)},X.isFinite=function(){return!!this.d},X.isInteger=X.isInt=function(){return!!this.d&&eo(this.e/so)>this.d.length-2},X.isNaN=function(){return!this.s},X.isNegative=X.isNeg=function(){return this.s<0},X.isPositive=X.isPos=function(){return this.s>0},X.isZero=function(){return!!this.d&&this.d[0]===0},X.lessThan=X.lt=function(e){return this.cmp(e)<0},X.lessThanOrEqualTo=X.lte=function(e){return this.cmp(e)<1},X.logarithm=X.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(Ja=!1,s=d+p,o=ko(l,s),r=t?xo(u,s+10):ko(e,s),c=_o(o,r,s,1),mo(c.d,i=d,f))do if(s+=10,o=ko(l,s),r=t?xo(u,s+10):ko(e,s),c=_o(o,r,s,1),!a){+fo(c.d).slice(i+1,i+15)+1==0x5af3107a4000&&(c=vo(c,d+1,0));break}while(mo(c.d,i+=10,f));return Ja=!0,vo(c,d,f)},X.minus=X.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 Ja?vo(e,s,c):e}if(n=eo(e.e/so),u=eo(p.e/so),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/so),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]=oo-1;--l[i],l[r]+=oo}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=bo(l,n),Ja?vo(e,s,c):e):new m(c===3?-0:0)},X.modulo=X.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]?vo(new r(n),r.precision,r.rounding):(Ja=!1,r.modulo==9?(t=_o(n,e.abs(),0,3,1),t.s*=e.s):t=_o(n,e,0,r.modulo,1),t=t.times(e),Ja=!0,n.minus(t))},X.naturalExponential=X.exp=function(){return Oo(this)},X.naturalLogarithm=X.ln=function(){return ko(this)},X.negated=X.neg=function(){var e=new this.constructor(this);return e.s=-e.s,vo(e)},X.plus=X.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)),Ja?vo(e,s,c):e;if(a=eo(d.e/so),r=eo(e.e/so),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/so),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)/oo|0,l[i]%=oo;for(t&&(l.unshift(t),++r),o=l.length;l[--o]==0;)l.pop();return e.d=l,e.e=bo(l,r),Ja?vo(e,s,c):e},X.precision=X.sd=function(e){var t,n=this;if(e!==void 0&&e!==!!e&&e!==1&&e!==0)throw Error(Xa+e);return n.d?(t=Co(n.d),e&&n.e+1>t&&(t=n.e+1)):t=NaN,t},X.round=function(){var e=this,t=e.constructor;return vo(new t(e),e.e+1,t.rounding)},X.sine=X.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())+so,r.rounding=1,n=No(r,Io(r,n)),r.precision=e,r.rounding=t,vo(qa>2?n.neg():n,e,t,!0)):new r(NaN)},X.squareRoot=X.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(Ja=!1,l=Math.sqrt(+o),l==0||l==1/0?(t=fo(s),(t.length+c)%2==0&&(t+=`0`),l=Math.sqrt(t),c=eo((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(_o(o,a,n+2,1)).times(.5),fo(a.d).slice(0,n)===(t=fo(r.d)).slice(0,n))if(t=t.slice(n-3,n+1),t==`9999`||!i&&t==`4999`){if(!i&&(vo(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`)&&(vo(r,c+1,1),e=!r.times(r).eq(o));break}return Ja=!0,vo(r,c,u.rounding,e)},X.tangent=X.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=_o(n,new r(1).minus(n.times(n)).sqrt(),e+10,0),r.precision=e,r.rounding=t,vo(qa==2||qa==4?n.neg():n,e,t,!0)):new r(NaN)},X.times=X.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=eo(u.e/so)+eo(e.e/so),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%oo|0,t=s/oo|0;a[i]=(a[i]+t)%oo|0}for(;!a[--o];)a.pop();return t?++n:a.shift(),e.d=a,e.e=bo(a,n),Ja?vo(e,d.precision,d.rounding):e},X.toBinary=function(e,t){return Lo(this,2,e,t)},X.toDecimalPlaces=X.toDP=function(e,t){var n=this,r=n.constructor;return n=new r(n),e===void 0?n:(po(e,0,Va),t===void 0?t=r.rounding:po(t,0,8),vo(n,e+n.e+1,t))},X.toExponential=function(e,t){var n,r=this,i=r.constructor;return e===void 0?n=yo(r,!0):(po(e,0,Va),t===void 0?t=i.rounding:po(t,0,8),r=vo(new i(r),e+1,t),n=yo(r,!0,e+1)),r.isNeg()&&!r.isZero()?`-`+n:n},X.toFixed=function(e,t){var n,r,i=this,a=i.constructor;return e===void 0?n=yo(i):(po(e,0,Va),t===void 0?t=a.rounding:po(t,0,8),r=vo(new a(i),e+i.e+1,t),n=yo(r,!1,e+r.e+1)),i.isNeg()&&!i.isZero()?`-`+n:n},X.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=Co(m)-p.e-1,o=a%so,t.d[0]=to(10,o<0?so+o:o),e==null)e=a>0?t:l;else{if(s=new h(e),!s.isInt()||s.lt(l))throw Error(Xa+s);e=s.gt(t)?a>0?t:l:s}for(Ja=!1,s=new h(fo(m)),u=h.precision,h.precision=a=m.length*so*2;d=_o(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=_o(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=_o(l,r,a,1).minus(p).abs().cmp(_o(c,n,a,1).minus(p).abs())<1?[l,r]:[c,n],h.precision=u,Ja=!0,f},X.toHexadecimal=X.toHex=function(e,t){return Lo(this,16,e,t)},X.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:po(t,0,8),!n.d)return e.s?n:e;if(!e.d)return e.s&&=n.s,e}return e.d[0]?(Ja=!1,n=_o(n,e,0,t,1).times(e),Ja=!0,vo(n)):(e.s=n.s,n=e),n},X.toNumber=function(){return+this},X.toOctal=function(e,t){return Lo(this,8,e,t)},X.toPower=X.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(to(+s,l));if(s=new c(s),s.eq(1))return s;if(r=c.precision,a=c.rounding,e.eq(1))return vo(s,r,a);if(t=eo(e.e/so),t>=e.d.length-1&&(n=l<0?-l:l)<=co)return i=To(c,s,n,r),e.s<0?new c(1).div(i):vo(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=to(+s,l),t=n==0||!isFinite(n)?eo(l*(Math.log(`0.`+fo(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):(Ja=!1,c.rounding=s.s=1,n=Math.min(12,(t+``).length),i=Oo(e.times(ko(s,r+n)),r),i.d&&(i=vo(i,r+5,1),mo(i.d,r,a)&&(t=r+10,i=vo(Oo(e.times(ko(s,t+n)),t),t+5,1),+fo(i.d).slice(r+1,r+15)+1==0x5af3107a4000&&(i=vo(i,r+1,0)))),i.s=o,Ja=!0,c.rounding=a,vo(i,r,a))},X.toPrecision=function(e,t){var n,r=this,i=r.constructor;return e===void 0?n=yo(r,r.e<=i.toExpNeg||r.e>=i.toExpPos):(po(e,1,Va),t===void 0?t=i.rounding:po(t,0,8),r=vo(new i(r),e,t),n=yo(r,e<=r.e||r.e<=i.toExpNeg,e)),r.isNeg()&&!r.isZero()?`-`+n:n},X.toSignificantDigits=X.toSD=function(e,t){var n=this,r=n.constructor;return e===void 0?(e=r.precision,t=r.rounding):(po(e,1,Va),t===void 0?t=r.rounding:po(t,0,8)),vo(new r(n),e,t)},X.toString=function(){var e=this,t=e.constructor,n=yo(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()&&!e.isZero()?`-`+n:n},X.truncated=X.trunc=function(){return vo(new this.constructor(this),this.e+1,1)},X.valueOf=X.toJSON=function(){var e=this,t=e.constructor,n=yo(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()?`-`+n:n};function fo(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=so-r.length,n&&(a+=wo(n)),a+=r;o=e[t],r=o+``,n=so-r.length,n&&(a+=wo(n))}else if(o===0)return`0`;for(;o%10==0;)o/=10;return a+o}function po(e,t,n){if(e!==~~e||e<t||e>n)throw Error(Xa+e)}function mo(e,t,n,r){var i,a,o,s;for(a=e[0];a>=10;a/=10)--t;return--t<0?(t+=so,i=0):(i=Math.ceil((t+1)/so),t%=so),a=to(10,so-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)==to(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)==to(10,t-3)-1,o}function ho(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]+=Ha.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 go(e,t){var n,r,i;if(t.isZero())return t;r=t.d.length,r<32?(n=Math.ceil(r/3),i=(1/Fo(4,n)).toString()):(n=16,i=`2.3283064365386962890625e-10`),e.precision+=n,t=Po(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 _o=(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=oo,p=so,u=eo(r.e/p)-eo(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,Ka=m;else{for(d=1,f=v[0];f>=10;f/=10)d++;_.e=d+u*p-1,vo(_,s?a+_.e+1:a,o,m)}return _}})();function vo(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+=so,o=t,u=d[f=0],c=u/to(10,i-o-1)%10|0;else if(f=Math.ceil((a+1)/so),s=d.length,f>=s)if(r){for(;s++<=f;)d.push(0);u=c=0,i=1,a%=so,o=a-so+1}else break out;else{for(u=s=d[f],i=1;s>=10;s/=10)i++;a%=so,o=a-so+i,c=o<0?0:u/to(10,i-o-1)%10|0}if(r=r||t<0||d[f+1]!==void 0||(o<0?u:u%to(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/to(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]=to(10,(so-t%so)%so),e.e=-t||0):d[0]=e.e=0,e;if(a==0?(d.length=f,s=1,f--):(d.length=f+1,s=to(10,so-a),d[f]=o>0?(u/to(10,i-o)%to(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]==oo&&(d[0]=1));break}else{if(d[f]+=s,d[f]!=oo)break;d[f--]=0,s=1}for(a=d.length;d[--a]===0;)d.pop()}return Ja&&(e.e>p.maxE?(e.d=null,e.e=NaN):e.e<p.minE&&(e.e=0,e.d=[0])),e}function yo(e,t,n){if(!e.isFinite())return Ao(e);var r,i=e.e,a=fo(e.d),o=a.length;return t?(n&&(r=n-o)>0?a=a.charAt(0)+`.`+a.slice(1)+wo(r):o>1&&(a=a.charAt(0)+`.`+a.slice(1)),a=a+(e.e<0?`e`:`e+`)+e.e):i<0?(a=`0.`+wo(-i-1)+a,n&&(r=n-o)>0&&(a+=wo(r))):i>=o?(a+=wo(i+1-o),n&&(r=n-i-1)>0&&(a=a+`.`+wo(r))):((r=i+1)<o&&(a=a.slice(0,r)+`.`+a.slice(r)),n&&(r=n-o)>0&&(i+1===o&&(a+=`.`),a+=wo(r))),a}function bo(e,t){var n=e[0];for(t*=so;n>=10;n/=10)t++;return t}function xo(e,t,n){if(t>lo)throw Ja=!0,n&&(e.precision=n),Error(Za);return vo(new e(Ua),t,1,!0)}function So(e,t,n){if(t>uo)throw Error(Za);return vo(new e(Wa),t,n,!0)}function Co(e){var t=e.length-1,n=t*so+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 wo(e){for(var t=``;e--;)t+=`0`;return t}function To(e,t,n,r){var i,a=new e(1),o=Math.ceil(r/so+4);for(Ja=!1;;){if(n%2&&(a=a.times(t),Ro(a.d,o)&&(i=!0)),n=eo(n/2),n===0){n=a.d.length-1,i&&a.d[n]===0&&++a.d[n];break}t=t.times(t),Ro(t.d,o)}return Ja=!0,a}function Eo(e){return e.d[e.d.length-1]&1}function Do(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 Oo(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?(Ja=!1,c=m):c=t,s=new f(.03125);e.e>-2;)e=e.times(s),d+=5;for(r=Math.log(to(2,d))/Math.LN10*2+5|0,c+=r,n=a=o=new f(1),f.precision=c;;){if(a=vo(a.times(e),c,1),n=n.times(++u),s=o.plus(_o(a,n,c,1)),fo(s.d).slice(0,c)===fo(o.d).slice(0,c)){for(i=d;i--;)o=vo(o.times(o),c,1);if(t==null)if(l<3&&mo(o.d,c-r,p,l))f.precision=c+=10,n=a=s=new f(1),u=0,l++;else return vo(o,f.precision=m,p,Ja=!0);else return f.precision=m,o}o=s}}function ko(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?(Ja=!1,u=y):u=t,_.precision=u+=m,n=fo(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=fo(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=xo(_,u+2,y).times(a+``),h=ko(new _(r+`.`+n.slice(1)),u-m).plus(l),_.precision=y,t==null?vo(h,y,v,Ja=!0):h;for(d=h,c=o=h=_o(h.minus(1),h.plus(1),u,1),f=vo(h.times(h),u,1),i=3;;){if(o=vo(o.times(f),u,1),l=c.plus(_o(o,new _(i),u,1)),fo(l.d).slice(0,u)===fo(c.d).slice(0,u))if(c=c.times(2),a!==0&&(c=c.plus(xo(_,u+2,y).times(a+``))),c=_o(c,new _(p),u,1),t==null)if(mo(c.d,u-m,v,s))_.precision=u+=m,l=o=h=_o(d.minus(1),d.plus(1),u,1),f=vo(h.times(h),u,1),i=s=1;else return vo(c,_.precision=y,v,Ja=!0);else return _.precision=y,c;c=l,i+=2}}function Ao(e){return String(e.s*e.s/0)}function jo(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)%so,n<0&&(r+=so),r<i){for(r&&e.d.push(+t.slice(0,r)),i-=so;r<i;)e.d.push(+t.slice(r,r+=so));t=t.slice(r),r=so-t.length}else r-=i;for(;r--;)t+=`0`;e.d.push(+t),Ja&&(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 Mo(e,t){var n,r,i,a,o,s,c,l,u;if(t.indexOf(`_`)>-1){if(t=t.replace(/(\d)_(?=\d)/g,`$1`),ao.test(t))return jo(e,t)}else if(t===`Infinity`||t===`NaN`)return+t||(e.s=NaN),e.e=NaN,e.d=null,e;if(ro.test(t))n=16,t=t.toLowerCase();else if(no.test(t))n=2;else if(io.test(t))n=8;else throw Error(Xa+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=To(r,new r(n),a,a*2)),l=ho(t,n,oo),u=l.length-1,a=u;l[a]===0;--a)l.pop();return a<0?new r(e.s*0):(e.e=bo(l,u),e.d=l,Ja=!1,o&&(e=_o(e,i,s*4)),c&&(e=e.times(Math.abs(c)<54?to(2,c):Es.pow(2,c))),Ja=!0,e)}function No(e,t){var n,r=t.d.length;if(r<3)return t.isZero()?t:Po(e,2,t,t);n=1.4*Math.sqrt(r),n=n>16?16:n|0,t=t.times(1/Fo(5,n)),t=Po(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 Po(e,t,n,r,i){var a,o,s,c,l=1,u=e.precision,d=Math.ceil(u/so);for(Ja=!1,c=n.times(n),s=new e(r);;){if(o=_o(s.times(c),new e(t++*t++),u,1),s=i?r.plus(o):r.minus(o),r=_o(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 Ja=!0,o.d.length=d+1,o}function Fo(e,t){for(var n=e;--t;)n*=e;return n}function Io(e,t){var n,r=t.s<0,i=So(e,e.precision,1),a=i.times(.5);if(t=t.abs(),t.lte(a))return qa=r?4:1,t;if(n=t.divToInt(i),n.isZero())qa=r?3:2;else{if(t=t.minus(n.times(i)),t.lte(a))return qa=Eo(n)?r?2:3:r?4:1,t;qa=Eo(n)?r?1:4:r?3:2}return t.minus(i).abs()}function Lo(e,t,n,r){var i,a,o,s,c,l,u,d,f,p=e.constructor,m=n!==void 0;if(m?(po(n,1,Va),r===void 0?r=p.rounding:po(r,0,8)):(n=p.precision,r=p.rounding),!e.isFinite())u=Ao(e);else{for(u=yo(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=ho(yo(f),10,i),f.e=f.d.length),d=ho(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=_o(e,f,n,r,0,i),d=e.d,a=e.e,l=Ka),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+=Ha.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=ho(u,i,t),c=d.length;!d[c-1];--c);for(o=1,u=`1.`;o<c;o++)u+=Ha.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 Ro(e,t){if(e.length>t)return e.length=t,!0}function zo(e){return new this(e).abs()}function Bo(e){return new this(e).acos()}function Vo(e){return new this(e).acosh()}function Ho(e,t){return new this(e).plus(t)}function Uo(e){return new this(e).asin()}function Wo(e){return new this(e).asinh()}function Go(e){return new this(e).atan()}function Ko(e){return new this(e).atanh()}function qo(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=So(this,a,1).times(t.s>0?.25:.75),n.s=e.s):!t.d||e.isZero()?(n=t.s<0?So(this,r,i):new this(0),n.s=e.s):!e.d||t.isZero()?(n=So(this,a,1).times(.5),n.s=e.s):t.s<0?(this.precision=a,this.rounding=1,n=this.atan(_o(e,t,a,1)),t=So(this,a,1),this.precision=r,this.rounding=i,n=e.s<0?n.minus(t):n.plus(t)):n=this.atan(_o(e,t,a,1)),n}function Jo(e){return new this(e).cbrt()}function Yo(e){return vo(e=new this(e),e.e+1,2)}function Xo(e,t,n){return new this(e).clamp(t,n)}function Zo(e){if(!e||typeof e!=`object`)throw Error(Ya+`Object expected`);var t,n,r,i=e.defaults===!0,a=[`precision`,1,Va,`rounding`,0,8,`toExpNeg`,-Ba,0,`toExpPos`,0,Ba,`maxE`,0,Ba,`minE`,-Ba,0,`modulo`,0,9];for(t=0;t<a.length;t+=3)if(n=a[t],i&&(this[n]=Ga[n]),(r=e[n])!==void 0)if(eo(r)===r&&r>=a[t+1]&&r<=a[t+2])this[n]=r;else throw Error(Xa+n+`: `+r);if(n=`crypto`,i&&(this[n]=Ga[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(Qa);else this[n]=!1;else throw Error(Xa+n+`: `+r);return this}function Qo(e){return new this(e).cos()}function $o(e){return new this(e).cosh()}function es(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,as(e)){a.s=e.s,Ja?!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++;Ja?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 jo(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),ao.test(e)?jo(a,e):Mo(a,e);if(r===`bigint`)return e<0?(e=-e,a.s=-1):a.s=1,jo(a,e.toString());throw Error(Xa+e)}if(i.prototype=X,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=Zo,i.clone=es,i.isDecimal=as,i.abs=zo,i.acos=Bo,i.acosh=Vo,i.add=Ho,i.asin=Uo,i.asinh=Wo,i.atan=Go,i.atanh=Ko,i.atan2=qo,i.cbrt=Jo,i.ceil=Yo,i.clamp=Xo,i.cos=Qo,i.cosh=$o,i.div=ts,i.exp=ns,i.floor=rs,i.hypot=is,i.ln=os,i.log=ss,i.log10=ls,i.log2=cs,i.max=us,i.min=ds,i.mod=fs,i.mul=ps,i.pow=ms,i.random=hs,i.round=gs,i.sign=_s,i.sin=vs,i.sinh=ys,i.sqrt=bs,i.sub=xs,i.sum=Ss,i.tan=Cs,i.tanh=ws,i.trunc=Ts,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 ts(e,t){return new this(e).div(t)}function ns(e){return new this(e).exp()}function rs(e){return vo(e=new this(e),e.e+1,3)}function is(){var e,t,n=new this(0);for(Ja=!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 Ja=!0,new this(1/0);n=t}return Ja=!0,n.sqrt()}function as(e){return e instanceof Es||e&&e.toStringTag===$a||!1}function os(e){return new this(e).ln()}function ss(e,t){return new this(e).log(t)}function cs(e){return new this(e).log(2)}function ls(e){return new this(e).log(10)}function us(){return Do(this,arguments,-1)}function ds(){return Do(this,arguments,1)}function fs(e,t){return new this(e).mod(t)}function ps(e,t){return new this(e).mul(t)}function ms(e,t){return new this(e).pow(t)}function hs(e){var t,n,r,i,a=0,o=new this(1),s=[];if(e===void 0?e=this.precision:po(e,1,Va),r=Math.ceil(e/so),!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(Qa);for(r=s[--a],e%=so,r&&e&&(i=to(10,so-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-=so)s.shift();for(r=1,i=s[0];i>=10;i/=10)r++;r<so&&(n-=so-r)}return o.e=n,o.d=s,o}function gs(e){return vo(e=new this(e),e.e+1,this.rounding)}function _s(e){return e=new this(e),e.d?e.d[0]?e.s:0*e.s:e.s||NaN}function vs(e){return new this(e).sin()}function ys(e){return new this(e).sinh()}function bs(e){return new this(e).sqrt()}function xs(e,t){return new this(e).sub(t)}function Ss(){var e=0,t=arguments,n=new this(t[e]);for(Ja=!1;n.s&&++e<t.length;)n=n.plus(t[e]);return Ja=!0,vo(n,this.precision,this.rounding)}function Cs(e){return new this(e).tan()}function ws(e){return new this(e).tanh()}function Ts(e){return vo(e=new this(e),e.e+1,1)}X[Symbol.for(`nodejs.util.inspect.custom`)]=X.toString,X[Symbol.toStringTag]=`Decimal`;var Es=X.constructor=es(Ga);Ua=new Es(Ua),Wa=new Es(Wa);var Ds=Y(`BigNumber`,[`?on`,`config`],e=>{var{on:t,config:n}=e,r=Es.clone({precision:n.precision,modulo:Es.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}),Os=Math.cosh||function(e){return Math.abs(e)<1e-9?1-e:(Math.exp(e)+Math.exp(-e))*.5},ks=Math.sinh||function(e){return Math.abs(e)<1e-9?e:(Math.exp(e)-Math.exp(-e))*.5},As=e=>{let t=Math.sin(.5*e);return-2*t*t},js=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))},Ms=function(){throw SyntaxError(`Invalid Param`)};function Ns(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 Ps={re:0,im:0},Fs=function(e,t){let n=Ps;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 Z.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 Z.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]):Ms();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&&Ms();for(let e=0;e<t.length;e++){let a=t[e];a===` `||a===` `||a===`
2
+ import{$ as e,$n as t,A as n,B as r,Bn as i,C as a,Cn as o,D as s,E as c,Et as l,F as u,Fn as d,G as f,Gn as p,Gt as m,H as h,Hn as g,Ht as _,I as v,In as y,J as b,Jn as x,K as S,Kn as C,L as w,Ln as T,M as E,N as D,Nn as O,O as k,Ot as A,P as j,Pn as M,Q as N,Qn as P,R as F,Rn as I,S as L,Sn as R,St as z,T as B,Tn as V,Tt as ee,U as te,Un as H,Ut as ne,V as re,Vn as U,Vt as W,W as ie,Wn as ae,Wt as oe,X as se,Xn as ce,Y as le,Yn as ue,Z as de,Zn as fe,Zt as pe,_ as me,_n as he,_t as ge,a as _e,ar as ve,at as ye,b as be,bn as xe,bt as Se,c as Ce,cr as we,ct as Te,dr as Ee,dt as De,er as Oe,et as ke,fr as Ae,ft as je,g as Me,gt as Ne,h as Pe,hn as Fe,ht as Ie,i as Le,ir as Re,it as ze,j as Be,k as Ve,l as He,lr as Ue,lt as We,m as Ge,mt as Ke,nr as qe,nt as Je,o as Ye,or as Xe,ot as Ze,p as Qe,pt as $e,q as et,qn as tt,qt as nt,r as rt,rr as it,rt as at,s as ot,sr as st,st as ct,t as lt,tr as ut,tt as dt,u as ft,un as pt,ur as mt,ut as ht,v as gt,vt as _t,w as vt,wn as yt,x as bt,xn as xt,xt as St,y as Ct,yn as wt,yt as Tt,z as Et,zn as Dt}from"./importer-CPnENBqt.js";import{i as Ot,n as kt,r as At,t as jt}from"./threshold-CEM3Svgm.js";import{createContext as Mt,forwardRef as Nt,memo as Pt,startTransition as Ft,useCallback as It,useContext as Lt,useEffect as G,useImperativeHandle as Rt,useLayoutEffect as K,useMemo as zt,useRef as q,useState as Bt,useSyncExternalStore as Vt}from"react";import{createPortal as Ht}from"react-dom";import{createRoot as Ut}from"react-dom/client";import{Fragment as Wt,jsx as J,jsxs as Gt}from"react/jsx-runtime";var Kt=[`text`,`brush`,`arrow`,`box`],qt={text:14,brush:3,arrow:2,box:2},Jt=/^#[0-9a-fA-F]{6}$/,Yt={text:[1,1],arrow:[2,2],box:[2,2],brush:[2,1/0]},Xt=e=>typeof e==`number`&&Number.isFinite(e);function Zt(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)&&Xt(e[0])&&Xt(e[1])).map(([e,t])=>[e,t]),[i,a]=Yt[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:Xt(t.width)&&t.width>0?Math.min(96,t.width):qt[n],...typeof t.text==`string`&&t.text!==``?{text:t.text}:{}}}function Qt(e){return Array.isArray(e)?e.map(Zt).filter(e=>e!==null):null}var $t={info:`#8a93a6`,warning:`#f5a524`,critical:`#e5484d`},en={info:`var(--text-muted, #8a93a6)`,warning:`var(--accent, #f5a524)`,critical:`var(--danger, #e5484d)`};function tn(e,t){return{id:`mark:${e.id}`,kind:`box`,anchor:`x`,points:[[e.t0,0],[e.t1??t,1]],color:$t[e.severity],width:1,...e.ruleName?{text:`${e.late?`Late · `:``}${e.ruleName}`}:{}}}var nn=96,rn=96,an=2,on={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},sn={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},cn=on,ln=sn;function un(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 dn(e,t,n,r=96){let i=on[e],a=sn[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 fn(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));if(n===`move`)return dn(e,{...t,x:t.x+c,y:t.y+l},o,s);let u=n===`resize`?`se`:n,{x:d,y:f,w:p,h:m}=t;if(u.includes(`e`)&&(p=Math.max(on[e],Math.min(t.w+c,o-t.x))),u.includes(`s`)&&(m=Math.max(sn[e],Math.min(t.h+l,s-t.y))),u.includes(`w`)){let n=t.x+t.w;d=Math.max(0,Math.min(t.x+c,n-on[e])),p=n-d}if(u.includes(`n`)){let n=t.y+t.h;f=Math.max(0,Math.min(t.y+l,n-sn[e])),m=n-f}return{x:d,y:f,w:p,h:m}}function pn(e,t,n){for(let r of t)if(r.id!==n&&un(e,r.rect))return!0;return!1}function mn(e,t,n=96){let r=on[e],i=sn[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=dn(e,{x:s,y:i,w:a,h:o},n);if(!pn(r,t,``))return r}return dn(e,{x:0,y:0,w:r,h:i},n)}function hn(e,t){return{id:crypto.randomUUID(),kind:e,rect:mn(e,t)}}function gn(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=gn(e-4).map(e=>({x:e.x*.5,y:e.y,w:e.w*.5,h:e.h})),n=gn(4).map(e=>({x:.5+e.x*.5,y:e.y,w:e.w*.5,h:e.h}));return[...t,...n]}function _n(e,t=96,n=96){let r=gn(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 vn(){return{scaleMin:``,scaleMax:``,majorStep:``,minorStep:``,alarm:null}}var yn={style:`dashed`,width:1,color:null},bn={style:`solid`,width:1,color:null},xn={enabled:!1,reference:`previous`,datasetId:null,datasetColor:`#94a3b8`,previousColor:`#64748b`},Sn=/^#[0-9a-f]{6}$/i;function Cn(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`&&Sn.test(t.datasetColor)?t.datasetColor:xn.datasetColor,previousColor:typeof t.previousColor==`string`&&Sn.test(t.previousColor)?t.previousColor:xn.previousColor}}var wn=[`#f5a524`,`#38bdf8`,`#22c55e`,`#f472b6`,`#a78bfa`,`#fb7185`];function Tn(e,t){return{id:crypto.randomUUID(),column:e,color:wn[t%wn.length],value:`last`,style:`arc`,min:``,max:``}}function En(e,t){if(!e||typeof e!=`object`)return null;let n=e;if(typeof n.column!=`string`)return null;let r=hr(n.alarm);return{id:typeof n.id==`string`&&n.id?n.id:`g${t}`,column:n.column,color:typeof n.color==`string`?n.color:wn[t%wn.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 Dn(e,t){let n=parseFloat(e),r=parseFloat(t);return Number.isFinite(n)&&Number.isFinite(r)&&n<r?[n,r]:void 0}var On=1.8,kn=4,An=1;function jn(){return{kind:`multiband`,series:[],addColumn:``,layout:`overlay`,xAxisLine:{...yn},yAxisLine:{...yn},gridLine:{...bn},lineWidth:1}}function Mn(e){return{kind:`xyscatter`,xyXCol:``,xyYCol:``,xyColorCol:null,xyColor:e,xyPointRadius:On,xyXAxisLine:{...yn},xyYAxisLine:{...yn},xyGridLine:{...bn},xyFit:null,xyXScale:vn(),xyYScale:vn()}}function Nn(e=4){return{kind:`xyzmesh`,xyzXCol:``,xyzYCol:``,xyzZCol:``,xyzViewMode:`3d`,xyzXScale:vn(),xyzYScale:vn(),xyzZScale:vn(),xyzPointRadius:e,showMesh:!1,meshStyle:`filled`,meshOpacity:.85}}function Pn(){return{kind:`histogram`,histColumn:``,histBins:0,histColor:`#38bdf8`,histNormal:!1,histLogY:!1}}function Fn(){return{kind:`polar`,polarAngleCol:``,polarRadiusCol:``,polarColor:`#a78bfa`,polarMode:`waveform`,polarRadiusMin:``,polarRadiusMax:``}}function In(){return{kind:`spectrum`,specSignalCol:``,specTimeCol:``,specSampleRate:`1000`,specXMode:`hz`,specYMode:`amplitude`,specWindow:`hann`,specColor:`#34d399`,specLogX:!1}}function Ln(){return{kind:`boxplot`,boxValueCol:``,boxGroupCol:``,boxColor:`#fb923c`,boxWhiskers:`1.5iqr`}}function Rn(){return{kind:`spectrogram`,sgSignalCol:``,sgTimeCol:``,sgSampleRate:`1000`,sgWindowSize:512,sgOverlap:.5,sgWinFunc:`hann`,sgYMode:`db`,sgLogFreq:!1}}function zn(){return{kind:`heatmap`,hmMode:`binned`,hmColumns:[],hmXCol:``,hmYCol:``,hmValueCol:``,hmXBins:6,hmYBins:6,hmXMin:``,hmXMax:``,hmYMin:``,hmYMax:``,hmShowValues:!0,hmColorScheme:`diverging`}}function Bn(){return{kind:`violin`,vlValueCol:``,vlGroupCol:``,vlColor:`#818cf8`,vlShowBox:!0,vlBandwidth:``,vlOrientation:`vertical`}}function Vn(){return{kind:`confusion`,cfActualCol:``,cfPredictedCol:``,cfNormalize:!1}}function Hn(){return{kind:`roc`,rocScoreCol:``,rocLabelCol:``,rocMode:`roc`,rocColor:`#f472b6`}}function Un(){return{kind:`losscurve`,lcXCol:``,lcLeftCols:[],lcRightCols:[]}}function Wn(){return{kind:`controlchart`,ccValueCol:``,ccSubgroupCol:``,ccSigmaLevel:3,ccColor:`#22d3ee`}}function Gn(){return{kind:`parallelcoords`,pcColumns:[],pcColorByCol:``,pcColor:`#64748b`}}function Kn(){return{kind:`embedding`,emXCol:``,emYCol:``,emColorCol:``,emColorMode:`categorical`,emLabelCol:``,emPointSize:3,emColor:`#a78bfa`}}function qn(){return{kind:`flamegraph`,fgNameCol:``,fgParentCol:``,fgValueCol:``,fgDirection:`topdown`}}function Jn(){return{kind:`barchart`,bcCategoryCol:``,bcValueCols:[],bcMode:`grouped`,bcHorizontal:!1}}function Yn(){return{kind:`radar`,rdAxesCols:[],rdGroupCol:``,rdColor:`#38bdf8`,rdFill:!0}}function Xn(){return{kind:`areachart`,acXCol:``,acYCols:[],acStacked:!1}}function Zn(){return{kind:`cdfchart`,cdValueCols:[],cdComplement:!1,cdLogX:!1}}function Qn(){return{kind:`bubblechart`,bbXCol:``,bbYCol:``,bbSizeCol:``,bbColorCol:``,bbColorMode:`categorical`,bbColor:`#64748b`,bbMaxRadius:24}}function $n(){return{kind:`treemap`,tmNameCol:``,tmParentCol:``,tmValueCol:``}}function er(){return{kind:`sankey`,skSourceCol:``,skTargetCol:``,skValueCol:``}}function tr(){return{kind:`gauge`,ggGauges:[]}}function nr(){return{kind:`calibration`,cbScoreCol:``,cbLabelCol:``,cbBins:10,cbColor:`#38bdf8`}}function rr(){return{kind:`qqplot`,qqValueCol:``,qqMode:`normal`,qqRefCol:``,qqColor:`#a78bfa`}}function ir(){return{kind:`gantt`,gtLabelCol:``,gtStartCol:``,gtEndCol:``,gtGroupCol:``}}function ar(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 or=()=>({kind:`camera`,cameraStreamId:``,cameras:[],syncStreamId:``,offsetMs:0,fit:`contain`}),sr=9;function cr(e){return e.cameraStreamId?e.cameras?.[0]===e.cameraStreamId?e.cameras.slice(0,9):[e.cameraStreamId]:[]}function lr(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 ur(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 dr(e,t){return ur(e)?e:{...t}}function fr(e){if(!e||typeof e!=`object`)return!1;let t=e;return t.kind===`multiband`&&Array.isArray(t.series)&&t.series.every(lr)&&typeof t.addColumn==`string`}function pr(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 mr(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 hr(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`&&gr.test(t.ruleId)?{ruleId:t.ruleId}:{}}}var gr=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function _r(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 vr){let t=vr[e.kind],n=r(i[t]);n!==i[t]&&o(t,n)}return a||e}var vr={histogram:`histAlarm`,spectrum:`specAlarm`,areachart:`acAlarm`,losscurve:`lcAlarm`,cdfchart:`cdAlarm`,bubblechart:`bbAlarm`,boxplot:`boxAlarm`,violin:`vlAlarm`,barchart:`bcAlarm`,gantt:`gtAlarm`};function yr(e){if(!e||!(e.kind in vr))return null;let t=e[vr[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 br(e){let t=vn();if(!e||typeof e!=`object`)return t;let n=e,r=hr(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 xr(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(fr(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:hr(e.alarm)}:e):e.series,addColumn:e.addColumn,layout:e.layout===`parallel`?`parallel`:`overlay`,xAxisLine:dr(e.xAxisLine,yn),yAxisLine:dr(e.yAxisLine,yn),gridLine:dr(e.gridLine,bn),lineWidth:typeof e.lineWidth==`number`&&Number.isFinite(e.lineWidth)?Math.min(6,Math.max(.5,e.lineWidth)):1,...Cn(e.beacon)?{beacon:Cn(e.beacon)}:{},...e.envelope===!0?{envelope:!0}:{}}}else if(pr(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:dr(e.xyXAxisLine,yn),xyYAxisLine:dr(e.xyYAxisLine,yn),xyGridLine:dr(e.xyGridLine,bn),xyFit:a,xyXScale:br(e.xyXScale),xyYScale:br(e.xyYScale)}}else if(mr(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??br(n.xyzXScale),xyzYScale:a??br(n.xyzYScale),xyzZScale:o??br(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=En(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:cr({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]?Qt(n?.annotations):null;e?.length&&(r[t]={...r[t],annotations:e});let i=r[t]?vr[r[t].kind]:void 0,a=i?hr(n[i]):null;i&&a&&(r[t]={...r[t],[i]:a})}return r}function Sr(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]=jn(),a=!0)}else if(t.kind===`xyscatter`){let e=i[t.id];(!e||e.kind!==`xyscatter`)&&(i[t.id]=Mn(n),a=!0)}else if(t.kind===`xyzmesh`){let e=i[t.id];(!e||e.kind!==`xyzmesh`)&&(i[t.id]=Nn(r),a=!0)}else if(t.kind===`histogram`){let e=i[t.id];(!e||e.kind!==`histogram`)&&(i[t.id]=Pn(),a=!0)}else if(t.kind===`polar`){let e=i[t.id];(!e||e.kind!==`polar`)&&(i[t.id]=Fn(),a=!0)}else if(t.kind===`spectrum`){let e=i[t.id];(!e||e.kind!==`spectrum`)&&(i[t.id]=In(),a=!0)}else if(t.kind===`boxplot`){let e=i[t.id];(!e||e.kind!==`boxplot`)&&(i[t.id]=Ln(),a=!0)}else t.kind===`spectrogram`?(!i[t.id]||i[t.id].kind!==`spectrogram`)&&(i[t.id]=Rn(),a=!0):t.kind===`heatmap`?(!i[t.id]||i[t.id].kind!==`heatmap`)&&(i[t.id]=zn(),a=!0):t.kind===`violin`?(!i[t.id]||i[t.id].kind!==`violin`)&&(i[t.id]=Bn(),a=!0):t.kind===`confusion`?(!i[t.id]||i[t.id].kind!==`confusion`)&&(i[t.id]=Vn(),a=!0):t.kind===`roc`?(!i[t.id]||i[t.id].kind!==`roc`)&&(i[t.id]=Hn(),a=!0):t.kind===`losscurve`?(!i[t.id]||i[t.id].kind!==`losscurve`)&&(i[t.id]=Un(),a=!0):t.kind===`controlchart`?(!i[t.id]||i[t.id].kind!==`controlchart`)&&(i[t.id]=Wn(),a=!0):t.kind===`parallelcoords`?(!i[t.id]||i[t.id].kind!==`parallelcoords`)&&(i[t.id]=Gn(),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]=qn(),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]=Yn(),a=!0):t.kind===`areachart`?(!i[t.id]||i[t.id].kind!==`areachart`)&&(i[t.id]=Xn(),a=!0):t.kind===`cdfchart`?(!i[t.id]||i[t.id].kind!==`cdfchart`)&&(i[t.id]=Zn(),a=!0):t.kind===`bubblechart`?(!i[t.id]||i[t.id].kind!==`bubblechart`)&&(i[t.id]=Qn(),a=!0):t.kind===`treemap`?(!i[t.id]||i[t.id].kind!==`treemap`)&&(i[t.id]=$n(),a=!0):t.kind===`sankey`?(!i[t.id]||i[t.id].kind!==`sankey`)&&(i[t.id]=er(),a=!0):t.kind===`gauge`?(!i[t.id]||i[t.id].kind!==`gauge`)&&(i[t.id]=tr(),a=!0):t.kind===`calibration`?(!i[t.id]||i[t.id].kind!==`calibration`)&&(i[t.id]=nr(),a=!0):t.kind===`qqplot`?(!i[t.id]||i[t.id].kind!==`qqplot`)&&(i[t.id]=rr(),a=!0):t.kind===`gantt`?(!i[t.id]||i[t.id].kind!==`gantt`)&&(i[t.id]=ir(),a=!0):t.kind===`camera`&&(!i[t.id]||i[t.id].kind!==`camera`)&&(i[t.id]=or(),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 Cr(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 wr(e){return e===null||typeof e==`number`&&e>0?{liveWindowSeconds:e}:{}}var Tr=new WeakMap;function Er(e){return Number.isNaN(e)?0:Math.min(100,Math.max(0,e))}function Dr(){return crypto.randomUUID()}function Or(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 kr(){return kr=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},kr.apply(null,arguments)}var Ar={relTol:1e-12,absTol:1e-15,matrix:`Matrix`,number:`number`,numberFallback:`number`,precision:64,predictable:!1,randomSeed:null,legacySubset:!1};function jr(e,t){if(Nr(e,t)||Pr(e,t))return e[t];throw Lr(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 Mr(e,t,n){if(Nr(e,t)||Pr(e,t))return e[t]=n,n;throw Error(`No access to property "${t}"`)}function Nr(e,t){return Rr(e)?!(t in Object.prototype):!1}function Pr(e,t){return Array.isArray(e)?typeof t==`number`||typeof t==`string`&&Fr(t)||t===`length`:!1}function Fr(e){return/^\d+$/.test(e)}function Ir(e,t){if(!Lr(e,t))throw Error(`No access to method "`+t+`"`);return e[t]}function Lr(e,t){return e==null||typeof e[t]!=`function`||Gi(e,t)&&Object.getPrototypeOf&&t in Object.getPrototypeOf(e)?!1:zr.has(t)?!0:!(t in Object.prototype||t in Function.prototype)}function Rr(e){return typeof e==`object`&&e&&e.constructor===Object}var zr=new Set([`toString`,`valueOf`,`toLocaleString`]),Br=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 jr(this.wrappedObject,e)}set(e,t){return Mr(this.wrappedObject,e,t),this}has(e){return Nr(this.wrappedObject,e)&&e in this.wrappedObject}entries(){return Hr(this.keys(),e=>[e,this.get(e)])}forEach(e){for(var t of this.keys())e(this.get(t),t,this)}delete(e){Nr(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}},Vr=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 Hr(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 Hr(e,t){return{next:()=>{var n=e.next();return n.done?n:{value:t(n.value),done:!1}}}}function Ur(){return new Map}function Wr(e){if(!e)return Ur();if(pi(e))return e;if(fi(e))return new Br(e);throw Error(`createMap can create maps from objects or Maps`)}function Gr(e){if(e instanceof Br)return e.wrappedObject;var t={};for(var n of e.keys())Mr(t,n,e.get(n));return t}function Kr(e){return typeof e==`number`}function qr(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 Jr(e){return typeof e==`bigint`}function Yr(e){return e&&typeof e==`object`&&Object.getPrototypeOf(e).isComplex===!0||!1}function Xr(e){return e&&typeof e==`object`&&Object.getPrototypeOf(e).isFraction===!0||!1}function Zr(e){return e&&e.constructor.prototype.isUnit===!0||!1}function Qr(e){return typeof e==`string`}var $r=Array.isArray;function ei(e){return e&&e.constructor.prototype.isMatrix===!0||!1}function ti(e){return Array.isArray(e)||ei(e)}function ni(e){return e&&e.isDenseMatrix&&e.constructor.prototype.isMatrix===!0||!1}function ri(e){return e&&e.isSparseMatrix&&e.constructor.prototype.isMatrix===!0||!1}function ii(e){return e&&e.constructor.prototype.isRange===!0||!1}function ai(e){return e&&e.constructor.prototype.isIndex===!0||!1}function oi(e){return typeof e==`boolean`}function si(e){return e&&e.constructor.prototype.isResultSet===!0||!1}function ci(e){return e&&e.constructor.prototype.isHelp===!0||!1}function li(e){return typeof e==`function`}function ui(e){return e instanceof Date}function di(e){return e instanceof RegExp}function fi(e){return!!(e&&typeof e==`object`&&e.constructor===Object&&!Yr(e)&&!Xr(e))}function pi(e){return e?e instanceof Map||e instanceof Br||typeof e.set==`function`&&typeof e.get==`function`&&typeof e.keys==`function`&&typeof e.has==`function`:!1}function mi(e){return pi(e)&&pi(e.a)&&pi(e.b)}function hi(e){return pi(e)&&fi(e.wrappedObject)}function gi(e){return e===null}function _i(e){return e===void 0}function vi(e){return e&&e.isAccessorNode===!0&&e.constructor.prototype.isNode===!0||!1}function yi(e){return e&&e.isArrayNode===!0&&e.constructor.prototype.isNode===!0||!1}function bi(e){return e&&e.isAssignmentNode===!0&&e.constructor.prototype.isNode===!0||!1}function xi(e){return e&&e.isBlockNode===!0&&e.constructor.prototype.isNode===!0||!1}function Si(e){return e&&e.isConditionalNode===!0&&e.constructor.prototype.isNode===!0||!1}function Ci(e){return e&&e.isConstantNode===!0&&e.constructor.prototype.isNode===!0||!1}function wi(e){return Ci(e)||Ai(e)&&e.args.length===1&&Ci(e.args[0])&&`-+~`.includes(e.op)}function Ti(e){return e&&e.isFunctionAssignmentNode===!0&&e.constructor.prototype.isNode===!0||!1}function Ei(e){return e&&e.isFunctionNode===!0&&e.constructor.prototype.isNode===!0||!1}function Di(e){return e&&e.isIndexNode===!0&&e.constructor.prototype.isNode===!0||!1}function Oi(e){return e&&e.isNode===!0&&e.constructor.prototype.isNode===!0||!1}function ki(e){return e&&e.isObjectNode===!0&&e.constructor.prototype.isNode===!0||!1}function Ai(e){return e&&e.isOperatorNode===!0&&e.constructor.prototype.isNode===!0||!1}function ji(e){return e&&e.isParenthesisNode===!0&&e.constructor.prototype.isNode===!0||!1}function Mi(e){return e&&e.isRangeNode===!0&&e.constructor.prototype.isNode===!0||!1}function Ni(e){return e&&e.isRelationalNode===!0&&e.constructor.prototype.isNode===!0||!1}function Pi(e){return e&&e.isSymbolNode===!0&&e.constructor.prototype.isNode===!0||!1}function Fi(e){return e&&e.constructor.prototype.isChain===!0||!1}function Ii(e){var t=typeof e;return t===`object`?e===null?`null`:qr(e)?`BigNumber`:e.constructor&&e.constructor.name?e.constructor.name:`Object`:t}function Li(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 Li(e)});if(e instanceof Date)return new Date(e.valueOf());if(qr(e))return e;if(fi(e))return Ri(e,Li);if(t===`function`)return e;throw TypeError(`Cannot clone: unknown type of value (value: ${e})`)}function Ri(e,t){var n={};for(var r in e)Gi(e,r)&&(n[r]=t(e[r]));return n}function zi(e,t){for(var n in t)Gi(t,n)&&(e[n]=t[n]);return e}function Bi(e,t){if(Array.isArray(t))throw TypeError(`Arrays are not supported by deepExtend`);for(var n in t)if(Gi(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?Bi(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 Vi(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(!Vi(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)||!Vi(e[n],t[n]))return!1;for(n in t)if(!(n in e))return!1;return!0}else return e===t}function Hi(e){var t={};return Ui(e,t),t}function Ui(e,t){for(var n in e)if(Gi(e,n)){var r=e[n];typeof r==`object`&&r?Ui(r,t):t[n]=r}}function Wi(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 Gi(e,t){return e&&Object.hasOwnProperty.call(e,t)}function Ki(e){return e&&typeof e.factory==`function`}function qi(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 Ji=[`Matrix`,`Array`],Yi=[`number`,`BigNumber`,`bigint`,`Fraction`];function Xi(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=Li(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=Li(e);Zi(r,`matrix`,Ji),Zi(r,`number`,Yi),Bi(e,r);var o=Li(e);return t(`config`,o,a,Li(r)),o}else return Li(e)}return n.MATRIX_OPTIONS=Ji,n.NUMBER_OPTIONS=Yi,Object.keys(Ar).forEach(t=>{Object.defineProperty(n,t,{get:()=>e[t],enumerable:!0,configurable:!0})}),n}function Zi(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 Qi=mt(((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=ae(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=ie(e).map(D);let n=t.length,r=D(ae(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)?ae(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=ae(n),a=ae(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,oe(arguments,0,t).concat([oe(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 ce(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=>pe(e)?de(e.referToSelf.callback):fe(e)?ue(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(pe(s))r[o]=s.referToSelf.callback(n),r[o].referToSelf=s.referToSelf,i[o]=!0,e=!1;else if(fe(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 U(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,_e),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,U=g?f[2].implementation:n,W=_?f[3].implementation:n,ie=v?f[4].implementation:n,ae=y?f[5].implementation:n,oe=m?f[0].params.length:-1,se=h?f[1].params.length:-1,ce=g?f[2].params.length:-1,le=_?f[3].params.length:-1,ue=v?f[4].params.length:-1,de=y?f[5].params.length:-1,fe=b?6:0,pe=f.length,me=f.map(e=>e.test),he=f.map(e=>e.implementation),ge=function(){for(let e=fe;e<pe;e++)if(me[e](arguments))return he[e].apply(this,arguments);return d.onMismatch(e,arguments,f)};function _e(e,t){return arguments.length===oe&&S(e)&&N(t)?te.apply(this,arguments):arguments.length===se&&w(e)&&P(t)?H.apply(this,arguments):arguments.length===ce&&k(e)&&F(t)?U.apply(this,arguments):arguments.length===le&&A(e)&&I(t)?W.apply(this,arguments):arguments.length===ue&&j(e)&&R(t)?ie.apply(this,arguments):arguments.length===de&&M(e)&&B(t)?ae.apply(this,arguments):ge.apply(this,arguments)}try{Object.defineProperty(_e,`name`,{value:e})}catch{}return _e.signatures=o,_e._typedFunctionData={signatures:f,signatureMap:p},_e}function W(e,t,n){throw N(e,t,n)}function ie(e){return oe(e,0,e.length-1)}function ae(e){return e[e.length-1]}function oe(e,t,n){return Array.prototype.slice.call(e,t,n)}function se(e,t){for(let n=0;n<e.length;n++)if(t(e[n]))return e[n]}function ce(e,t){return Array.prototype.concat.apply([],e.map(t))}function le(){let e=ie(arguments).map(e=>x(T(e))),t=ae(arguments);if(typeof t!=`function`)throw TypeError(`Callback function expected as last argument`);return ue(e,t)}function ue(e,t){return{referTo:{references:e,callback:t}}}function de(e){if(typeof e!=`function`)throw TypeError(`Callback function expected as first argument`);return{referToSelf:{callback:e}}}function fe(e){return e&&typeof e.referTo==`object`&&Array.isArray(e.referTo.references)&&typeof e.referTo.callback==`function`}function pe(e){return e&&typeof e.referToSelf==`object`&&typeof e.referToSelf.callback==`function`}function me(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 he(e){let t;for(let n in e)Object.prototype.hasOwnProperty.call(e,n)&&(_(e[n])||typeof e[n].signature==`string`)&&(t=me(t,e[n].name));return t}function ge(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 _e=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=he(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=me(r,s)),ge(i,o)}return U(r||``,i)},d.create=i,d.createCount=_e.createCount,d.onMismatch=W,d.throwMismatchError=W,d.createError=N,d.clear=m,d.clearConversions=h,d.addTypes=p,d._findType=f,d.referTo=le,d.referToSelf=de,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 ve(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};ve(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){ve(e);let t=f(e.to),n=se(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 Y(e,t,n,r){function i(r){var i=qi(r,t.map(na));return ea(e,t,r),n(i)}return i.isFactory=!0,i.fn=e,i.dependencies=t.slice().sort(),r&&(i.meta=r),i}function $i(e){return typeof e==`function`&&typeof e.fn==`string`&&Array.isArray(e.dependencies)}function ea(e,t,n){if(!t.filter(e=>!ta(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 ta(e){return e&&e[0]===`?`}function na(e){return e&&e[0]===`?`?e.slice(1):e}function ra(e){return typeof e==`boolean`?!0:Number.isFinite(e)?e===Math.round(e):!1}function ia(e,t){if(t.number===`bigint`)try{BigInt(e)}catch{return t.numberFallback}return t.number}var aa=Math.sign||function(e){return e>0?1:e<0?-1:0},oa=Math.log2||function(e){return Math.log(e)/Math.LN2},sa=Math.log10||function(e){return Math.log(e)/Math.LN10},ca=Math.log1p||function(e){return Math.log(e+1)},la=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},ua=Math.expm1||function(e){return e>=2e-4||e<=-2e-4?Math.exp(e)-1:e+e*e/2+e*e*e/6};function da(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(!ra(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(!ra(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 fa(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}=pa(t);switch(n){case`fixed`:return ga(e,r);case`exponential`:return _a(e,r);case`engineering`:return ha(e,r);case`bin`:return da(e,2,i);case`oct`:return da(e,8,i);case`hex`:return da(e,16,i);case`auto`:return va(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 pa(e){var t=`auto`,n,r;if(e!==void 0)if(Kr(e))n=e;else if(qr(e))n=e.toNumber();else if(fi(e))e.precision!==void 0&&(n=Aa(e.precision,()=>{throw Error(`Option "precision" must be a number or BigNumber`)})),e.wordSize!==void 0&&(r=Aa(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 ma(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 ha(e,t){if(isNaN(e)||!Number.isFinite(e))return String(e);var n=ya(ma(e),t),r=n.exponent,i=n.coefficients,a=r%3==0?r:r<0?r-3-r%3:r-r%3;if(Kr(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=Kr(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 ga(e,t){if(isNaN(e)||!Number.isFinite(e))return String(e);var n=ma(e),r=typeof t==`number`?ya(n,n.exponent+1+t):n,i=r.coefficients,a=r.exponent+1,o=a+(t||0);return i.length<o&&(i=i.concat(ba(o-i.length))),a<0&&(i=ba(-a+1).concat(i),a=1),a<i.length&&i.splice(a,0,a===0?`0.`:`.`),r.sign+i.join(``)}function _a(e,t){if(isNaN(e)||!Number.isFinite(Number(e)))return String(e);var n=ma(e),r=t?ya(n,t):n,i=r.coefficients,a=r.exponent;i.length<t&&(i=i.concat(ba(t-i.length)));var o=i.shift();return r.sign+o+(i.length>0?`.`+i.join(``):``)+`e`+(a>=0?`+`:``)+a}function va(e,t,n){if(isNaN(e)||!Number.isFinite(e))return String(e);var r=ja(n?.lowerExp,-3),i=ja(n?.upperExp,5),a=ma(e),o=t?ya(a,t):a;if(o.exponent<r||o.exponent>=i)return _a(e,t);var s=o.coefficients,c=o.exponent;s.length<t&&(s=s.concat(ba(t-s.length))),s=s.concat(ba(c-s.length+1+(s.length<t?t-s.length:0))),s=ba(-c).concat(s);var l=c>0?c:0;return l<s.length-1&&s.splice(l+1,0,`.`),o.sign+s.join(``)}function ya(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 ba(e){for(var t=[],n=0;n<e;n++)t.push(0);return t}function xa(e){return e.toExponential().replace(/e.*$/,``).replace(/^0\.?0*|\./,``).length}function Sa(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 Ca=Math.acosh||function(e){return Math.log(Math.sqrt(e*e-1)+e)},wa=Math.asinh||function(e){return Math.log(Math.sqrt(e*e+1)+e)},Ta=Math.atanh||function(e){return Math.log((1+e)/(1-e))/2},Ea=Math.cosh||function(e){return(Math.exp(e)+Math.exp(-e))/2},Da=Math.sinh||function(e){return(Math.exp(e)-Math.exp(-e))/2},Oa=Math.tanh||function(e){var t=Math.exp(2*e);return(t-1)/(t+1)};function ka(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 Aa(e,t){if(Kr(e))return e;if(qr(e))return e.toNumber();t()}function ja(e,t){return Kr(e)?e:qr(e)?e.toNumber():t}var Ma=Ae(Qi(),1),Na=function(){return Na=Ma.default.create,Ma.default},Pa=Y(`typed`,[`?BigNumber`,`?Complex`,`?DenseMatrix`,`?Fraction`],function(e){var{BigNumber:t,Complex:n,DenseMatrix:r,Fraction:i}=e,a=Na();return a.clear(),a.addTypes([{name:`number`,test:Kr},{name:`Complex`,test:Yr},{name:`BigNumber`,test:qr},{name:`bigint`,test:Jr},{name:`Fraction`,test:Xr},{name:`Unit`,test:Zr},{name:`identifier`,test:e=>Qr&&/^(?:[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:Qr},{name:`Chain`,test:Fi},{name:`Array`,test:$r},{name:`Matrix`,test:ei},{name:`DenseMatrix`,test:ni},{name:`SparseMatrix`,test:ri},{name:`Range`,test:ii},{name:`Index`,test:ai},{name:`boolean`,test:oi},{name:`ResultSet`,test:si},{name:`Help`,test:ci},{name:`function`,test:li},{name:`Date`,test:ui},{name:`RegExp`,test:di},{name:`null`,test:gi},{name:`undefined`,test:_i},{name:`AccessorNode`,test:vi},{name:`ArrayNode`,test:yi},{name:`AssignmentNode`,test:bi},{name:`BlockNode`,test:xi},{name:`ConditionalNode`,test:Si},{name:`ConstantNode`,test:Ci},{name:`FunctionNode`,test:Ei},{name:`FunctionAssignmentNode`,test:Ti},{name:`IndexNode`,test:Di},{name:`Node`,test:Oi},{name:`ObjectNode`,test:ki},{name:`OperatorNode`,test:Ai},{name:`ParenthesisNode`,test:ji},{name:`RangeNode`,test:Mi},{name:`RelationalNode`,test:Ni},{name:`SymbolNode`,test:Pi},{name:`Map`,test:pi},{name:`Object`,test:fi}]),a.addConversions([{from:`number`,to:`BigNumber`,convert:function(e){if(t||Fa(e),xa(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||Ia(e),new n(e,0)}},{from:`BigNumber`,to:`Complex`,convert:function(e){return n||Ia(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||Fa(e),new t(e.toString())}},{from:`bigint`,to:`Fraction`,convert:function(e){return i||Ra(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||Ia(e),new n(e.valueOf(),0)}},{from:`number`,to:`Fraction`,convert:function(e){i||Ra(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||Fa(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||Ra(e);try{return new i(e)}catch{throw Error(`Cannot convert "`+e+`" to Fraction`)}}},{from:`string`,to:`Complex`,convert:function(e){n||Ia(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||Fa(e),new t(+e)}},{from:`boolean`,to:`bigint`,convert:function(e){return BigInt(+e)}},{from:`boolean`,to:`Fraction`,convert:function(e){return i||Ra(e),new i(+e)}},{from:`boolean`,to:`string`,convert:function(e){return String(e)}},{from:`Array`,to:`Matrix`,convert:function(e){return r||La(),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&&ti(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&&ti(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 Fa(e){throw Error(`Cannot convert value ${e} into a BigNumber: no class 'BigNumber' provided`)}function Ia(e){throw Error(`Cannot convert value ${e} into a Complex number: no class 'Complex' provided`)}function La(){throw Error(`Cannot convert array into a Matrix: no class 'DenseMatrix' provided`)}function Ra(e){throw Error(`Cannot convert value ${e} into a Fraction, no class 'Fraction' provided.`)}var za=Y(`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}),Ba=9e15,Va=1e9,Ha=`0123456789abcdef`,Ua=`2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058`,Wa=`3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789`,Ga={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-Ba,maxE:Ba,crypto:!1},Ka,qa,Ja=!0,Ya=`[DecimalError] `,Xa=Ya+`Invalid argument: `,Za=Ya+`Precision limit exceeded`,Qa=Ya+`crypto unavailable`,$a=`[object Decimal]`,eo=Math.floor,to=Math.pow,no=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,ro=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,io=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,ao=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,oo=1e7,so=7,co=9007199254740991,lo=Ua.length-1,uo=Wa.length-1,X={toStringTag:$a};X.absoluteValue=X.abs=function(){var e=new this.constructor(this);return e.s<0&&(e.s=1),vo(e)},X.ceil=function(){return vo(new this.constructor(this),this.e+1,2)},X.clampedTo=X.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(Xa+t);return n=r.cmp(e),n<0?e:r.cmp(t)>0?t:new i(r)},X.comparedTo=X.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},X.cosine=X.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())+so,r.rounding=1,n=go(r,Io(r,n)),r.precision=e,r.rounding=t,vo(qa==2||qa==3?n.neg():n,e,t,!0)):new r(1):new r(NaN)},X.cubeRoot=X.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(Ja=!1,a=u.s*to(u.s*u,1/3),!a||Math.abs(a)==1/0?(n=fo(u.d),e=u.e,(a=(e-n.length+1)%3)&&(n+=a==1||a==-2?`0`:`00`),a=to(n,1/3),e=eo((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=_o(l.plus(u).times(s),l.plus(c),o+2,1),fo(s.d).slice(0,o)===(n=fo(r.d)).slice(0,o))if(n=n.slice(o-3,o+1),n==`9999`||!i&&n==`4999`){if(!i&&(vo(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`)&&(vo(r,e+1,1),t=!r.times(r).times(r).eq(u));break}return Ja=!0,vo(r,e,d.rounding,t)},X.decimalPlaces=X.dp=function(){var e,t=this.d,n=NaN;if(t){if(e=t.length-1,n=(e-eo(this.e/so))*so,e=t[e],e)for(;e%10==0;e/=10)n--;n<0&&(n=0)}return n},X.dividedBy=X.div=function(e){return _o(this,new this.constructor(e))},X.dividedToIntegerBy=X.divToInt=function(e){var t=this,n=t.constructor;return vo(_o(t,new n(e),0,1,1),n.precision,n.rounding)},X.equals=X.eq=function(e){return this.cmp(e)===0},X.floor=function(){return vo(new this.constructor(this),this.e+1,3)},X.greaterThan=X.gt=function(e){return this.cmp(e)>0},X.greaterThanOrEqualTo=X.gte=function(e){var t=this.cmp(e);return t==1||t===0},X.hyperbolicCosine=X.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/Fo(4,e)).toString()):(e=16,t=`2.3283064365386962890625e-10`),a=Po(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 vo(a,o.precision=n,o.rounding=r,!0)},X.hyperbolicSine=X.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=Po(a,2,i,i,!0);else{e=1.4*Math.sqrt(r),e=e>16?16:e|0,i=i.times(1/Fo(5,e)),i=Po(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,vo(i,t,n,!0)},X.hyperbolicTangent=X.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,_o(n.sinh(),n.cosh(),r.precision=e,r.rounding=t)):new r(n.s)},X.inverseCosine=X.acos=function(){var e=this,t=e.constructor,n=e.abs().cmp(1),r=t.precision,i=t.rounding;return n===-1?e.isZero()?So(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()?So(t,r,i):new t(0):new t(NaN)},X.inverseHyperbolicCosine=X.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,Ja=!1,n=n.times(n).minus(1).sqrt().plus(n),Ja=!0,r.precision=e,r.rounding=t,n.ln()):new r(n)},X.inverseHyperbolicSine=X.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,Ja=!1,n=n.times(n).plus(1).sqrt().plus(n),Ja=!0,r.precision=e,r.rounding=t,n.ln())},X.inverseHyperbolicTangent=X.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?vo(new a(i),e,t,!0):(a.precision=n=r-i.e,i=_o(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)},X.inverseSine=X.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=So(a,n+4,r).times(.5),e.s=i.s,e):new a(NaN))},X.inverseTangent=X.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<=uo)return o=So(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<=uo)return o=So(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/so+2|0),e=n;e;--e)l=l.div(l.times(l).plus(1).sqrt().plus(1));for(Ja=!1,t=Math.ceil(s/so),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)),Ja=!0,vo(o,u.precision=d,u.rounding=f,!0)},X.isFinite=function(){return!!this.d},X.isInteger=X.isInt=function(){return!!this.d&&eo(this.e/so)>this.d.length-2},X.isNaN=function(){return!this.s},X.isNegative=X.isNeg=function(){return this.s<0},X.isPositive=X.isPos=function(){return this.s>0},X.isZero=function(){return!!this.d&&this.d[0]===0},X.lessThan=X.lt=function(e){return this.cmp(e)<0},X.lessThanOrEqualTo=X.lte=function(e){return this.cmp(e)<1},X.logarithm=X.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(Ja=!1,s=d+p,o=ko(l,s),r=t?xo(u,s+10):ko(e,s),c=_o(o,r,s,1),mo(c.d,i=d,f))do if(s+=10,o=ko(l,s),r=t?xo(u,s+10):ko(e,s),c=_o(o,r,s,1),!a){+fo(c.d).slice(i+1,i+15)+1==0x5af3107a4000&&(c=vo(c,d+1,0));break}while(mo(c.d,i+=10,f));return Ja=!0,vo(c,d,f)},X.minus=X.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 Ja?vo(e,s,c):e}if(n=eo(e.e/so),u=eo(p.e/so),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/so),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]=oo-1;--l[i],l[r]+=oo}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=bo(l,n),Ja?vo(e,s,c):e):new m(c===3?-0:0)},X.modulo=X.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]?vo(new r(n),r.precision,r.rounding):(Ja=!1,r.modulo==9?(t=_o(n,e.abs(),0,3,1),t.s*=e.s):t=_o(n,e,0,r.modulo,1),t=t.times(e),Ja=!0,n.minus(t))},X.naturalExponential=X.exp=function(){return Oo(this)},X.naturalLogarithm=X.ln=function(){return ko(this)},X.negated=X.neg=function(){var e=new this.constructor(this);return e.s=-e.s,vo(e)},X.plus=X.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)),Ja?vo(e,s,c):e;if(a=eo(d.e/so),r=eo(e.e/so),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/so),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)/oo|0,l[i]%=oo;for(t&&(l.unshift(t),++r),o=l.length;l[--o]==0;)l.pop();return e.d=l,e.e=bo(l,r),Ja?vo(e,s,c):e},X.precision=X.sd=function(e){var t,n=this;if(e!==void 0&&e!==!!e&&e!==1&&e!==0)throw Error(Xa+e);return n.d?(t=Co(n.d),e&&n.e+1>t&&(t=n.e+1)):t=NaN,t},X.round=function(){var e=this,t=e.constructor;return vo(new t(e),e.e+1,t.rounding)},X.sine=X.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())+so,r.rounding=1,n=No(r,Io(r,n)),r.precision=e,r.rounding=t,vo(qa>2?n.neg():n,e,t,!0)):new r(NaN)},X.squareRoot=X.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(Ja=!1,l=Math.sqrt(+o),l==0||l==1/0?(t=fo(s),(t.length+c)%2==0&&(t+=`0`),l=Math.sqrt(t),c=eo((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(_o(o,a,n+2,1)).times(.5),fo(a.d).slice(0,n)===(t=fo(r.d)).slice(0,n))if(t=t.slice(n-3,n+1),t==`9999`||!i&&t==`4999`){if(!i&&(vo(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`)&&(vo(r,c+1,1),e=!r.times(r).eq(o));break}return Ja=!0,vo(r,c,u.rounding,e)},X.tangent=X.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=_o(n,new r(1).minus(n.times(n)).sqrt(),e+10,0),r.precision=e,r.rounding=t,vo(qa==2||qa==4?n.neg():n,e,t,!0)):new r(NaN)},X.times=X.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=eo(u.e/so)+eo(e.e/so),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%oo|0,t=s/oo|0;a[i]=(a[i]+t)%oo|0}for(;!a[--o];)a.pop();return t?++n:a.shift(),e.d=a,e.e=bo(a,n),Ja?vo(e,d.precision,d.rounding):e},X.toBinary=function(e,t){return Lo(this,2,e,t)},X.toDecimalPlaces=X.toDP=function(e,t){var n=this,r=n.constructor;return n=new r(n),e===void 0?n:(po(e,0,Va),t===void 0?t=r.rounding:po(t,0,8),vo(n,e+n.e+1,t))},X.toExponential=function(e,t){var n,r=this,i=r.constructor;return e===void 0?n=yo(r,!0):(po(e,0,Va),t===void 0?t=i.rounding:po(t,0,8),r=vo(new i(r),e+1,t),n=yo(r,!0,e+1)),r.isNeg()&&!r.isZero()?`-`+n:n},X.toFixed=function(e,t){var n,r,i=this,a=i.constructor;return e===void 0?n=yo(i):(po(e,0,Va),t===void 0?t=a.rounding:po(t,0,8),r=vo(new a(i),e+i.e+1,t),n=yo(r,!1,e+r.e+1)),i.isNeg()&&!i.isZero()?`-`+n:n},X.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=Co(m)-p.e-1,o=a%so,t.d[0]=to(10,o<0?so+o:o),e==null)e=a>0?t:l;else{if(s=new h(e),!s.isInt()||s.lt(l))throw Error(Xa+s);e=s.gt(t)?a>0?t:l:s}for(Ja=!1,s=new h(fo(m)),u=h.precision,h.precision=a=m.length*so*2;d=_o(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=_o(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=_o(l,r,a,1).minus(p).abs().cmp(_o(c,n,a,1).minus(p).abs())<1?[l,r]:[c,n],h.precision=u,Ja=!0,f},X.toHexadecimal=X.toHex=function(e,t){return Lo(this,16,e,t)},X.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:po(t,0,8),!n.d)return e.s?n:e;if(!e.d)return e.s&&=n.s,e}return e.d[0]?(Ja=!1,n=_o(n,e,0,t,1).times(e),Ja=!0,vo(n)):(e.s=n.s,n=e),n},X.toNumber=function(){return+this},X.toOctal=function(e,t){return Lo(this,8,e,t)},X.toPower=X.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(to(+s,l));if(s=new c(s),s.eq(1))return s;if(r=c.precision,a=c.rounding,e.eq(1))return vo(s,r,a);if(t=eo(e.e/so),t>=e.d.length-1&&(n=l<0?-l:l)<=co)return i=To(c,s,n,r),e.s<0?new c(1).div(i):vo(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=to(+s,l),t=n==0||!isFinite(n)?eo(l*(Math.log(`0.`+fo(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):(Ja=!1,c.rounding=s.s=1,n=Math.min(12,(t+``).length),i=Oo(e.times(ko(s,r+n)),r),i.d&&(i=vo(i,r+5,1),mo(i.d,r,a)&&(t=r+10,i=vo(Oo(e.times(ko(s,t+n)),t),t+5,1),+fo(i.d).slice(r+1,r+15)+1==0x5af3107a4000&&(i=vo(i,r+1,0)))),i.s=o,Ja=!0,c.rounding=a,vo(i,r,a))},X.toPrecision=function(e,t){var n,r=this,i=r.constructor;return e===void 0?n=yo(r,r.e<=i.toExpNeg||r.e>=i.toExpPos):(po(e,1,Va),t===void 0?t=i.rounding:po(t,0,8),r=vo(new i(r),e,t),n=yo(r,e<=r.e||r.e<=i.toExpNeg,e)),r.isNeg()&&!r.isZero()?`-`+n:n},X.toSignificantDigits=X.toSD=function(e,t){var n=this,r=n.constructor;return e===void 0?(e=r.precision,t=r.rounding):(po(e,1,Va),t===void 0?t=r.rounding:po(t,0,8)),vo(new r(n),e,t)},X.toString=function(){var e=this,t=e.constructor,n=yo(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()&&!e.isZero()?`-`+n:n},X.truncated=X.trunc=function(){return vo(new this.constructor(this),this.e+1,1)},X.valueOf=X.toJSON=function(){var e=this,t=e.constructor,n=yo(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()?`-`+n:n};function fo(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=so-r.length,n&&(a+=wo(n)),a+=r;o=e[t],r=o+``,n=so-r.length,n&&(a+=wo(n))}else if(o===0)return`0`;for(;o%10==0;)o/=10;return a+o}function po(e,t,n){if(e!==~~e||e<t||e>n)throw Error(Xa+e)}function mo(e,t,n,r){var i,a,o,s;for(a=e[0];a>=10;a/=10)--t;return--t<0?(t+=so,i=0):(i=Math.ceil((t+1)/so),t%=so),a=to(10,so-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)==to(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)==to(10,t-3)-1,o}function ho(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]+=Ha.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 go(e,t){var n,r,i;if(t.isZero())return t;r=t.d.length,r<32?(n=Math.ceil(r/3),i=(1/Fo(4,n)).toString()):(n=16,i=`2.3283064365386962890625e-10`),e.precision+=n,t=Po(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 _o=(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=oo,p=so,u=eo(r.e/p)-eo(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,Ka=m;else{for(d=1,f=v[0];f>=10;f/=10)d++;_.e=d+u*p-1,vo(_,s?a+_.e+1:a,o,m)}return _}})();function vo(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+=so,o=t,u=d[f=0],c=u/to(10,i-o-1)%10|0;else if(f=Math.ceil((a+1)/so),s=d.length,f>=s)if(r){for(;s++<=f;)d.push(0);u=c=0,i=1,a%=so,o=a-so+1}else break out;else{for(u=s=d[f],i=1;s>=10;s/=10)i++;a%=so,o=a-so+i,c=o<0?0:u/to(10,i-o-1)%10|0}if(r=r||t<0||d[f+1]!==void 0||(o<0?u:u%to(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/to(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]=to(10,(so-t%so)%so),e.e=-t||0):d[0]=e.e=0,e;if(a==0?(d.length=f,s=1,f--):(d.length=f+1,s=to(10,so-a),d[f]=o>0?(u/to(10,i-o)%to(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]==oo&&(d[0]=1));break}else{if(d[f]+=s,d[f]!=oo)break;d[f--]=0,s=1}for(a=d.length;d[--a]===0;)d.pop()}return Ja&&(e.e>p.maxE?(e.d=null,e.e=NaN):e.e<p.minE&&(e.e=0,e.d=[0])),e}function yo(e,t,n){if(!e.isFinite())return Ao(e);var r,i=e.e,a=fo(e.d),o=a.length;return t?(n&&(r=n-o)>0?a=a.charAt(0)+`.`+a.slice(1)+wo(r):o>1&&(a=a.charAt(0)+`.`+a.slice(1)),a=a+(e.e<0?`e`:`e+`)+e.e):i<0?(a=`0.`+wo(-i-1)+a,n&&(r=n-o)>0&&(a+=wo(r))):i>=o?(a+=wo(i+1-o),n&&(r=n-i-1)>0&&(a=a+`.`+wo(r))):((r=i+1)<o&&(a=a.slice(0,r)+`.`+a.slice(r)),n&&(r=n-o)>0&&(i+1===o&&(a+=`.`),a+=wo(r))),a}function bo(e,t){var n=e[0];for(t*=so;n>=10;n/=10)t++;return t}function xo(e,t,n){if(t>lo)throw Ja=!0,n&&(e.precision=n),Error(Za);return vo(new e(Ua),t,1,!0)}function So(e,t,n){if(t>uo)throw Error(Za);return vo(new e(Wa),t,n,!0)}function Co(e){var t=e.length-1,n=t*so+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 wo(e){for(var t=``;e--;)t+=`0`;return t}function To(e,t,n,r){var i,a=new e(1),o=Math.ceil(r/so+4);for(Ja=!1;;){if(n%2&&(a=a.times(t),Ro(a.d,o)&&(i=!0)),n=eo(n/2),n===0){n=a.d.length-1,i&&a.d[n]===0&&++a.d[n];break}t=t.times(t),Ro(t.d,o)}return Ja=!0,a}function Eo(e){return e.d[e.d.length-1]&1}function Do(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 Oo(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?(Ja=!1,c=m):c=t,s=new f(.03125);e.e>-2;)e=e.times(s),d+=5;for(r=Math.log(to(2,d))/Math.LN10*2+5|0,c+=r,n=a=o=new f(1),f.precision=c;;){if(a=vo(a.times(e),c,1),n=n.times(++u),s=o.plus(_o(a,n,c,1)),fo(s.d).slice(0,c)===fo(o.d).slice(0,c)){for(i=d;i--;)o=vo(o.times(o),c,1);if(t==null)if(l<3&&mo(o.d,c-r,p,l))f.precision=c+=10,n=a=s=new f(1),u=0,l++;else return vo(o,f.precision=m,p,Ja=!0);else return f.precision=m,o}o=s}}function ko(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?(Ja=!1,u=y):u=t,_.precision=u+=m,n=fo(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=fo(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=xo(_,u+2,y).times(a+``),h=ko(new _(r+`.`+n.slice(1)),u-m).plus(l),_.precision=y,t==null?vo(h,y,v,Ja=!0):h;for(d=h,c=o=h=_o(h.minus(1),h.plus(1),u,1),f=vo(h.times(h),u,1),i=3;;){if(o=vo(o.times(f),u,1),l=c.plus(_o(o,new _(i),u,1)),fo(l.d).slice(0,u)===fo(c.d).slice(0,u))if(c=c.times(2),a!==0&&(c=c.plus(xo(_,u+2,y).times(a+``))),c=_o(c,new _(p),u,1),t==null)if(mo(c.d,u-m,v,s))_.precision=u+=m,l=o=h=_o(d.minus(1),d.plus(1),u,1),f=vo(h.times(h),u,1),i=s=1;else return vo(c,_.precision=y,v,Ja=!0);else return _.precision=y,c;c=l,i+=2}}function Ao(e){return String(e.s*e.s/0)}function jo(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)%so,n<0&&(r+=so),r<i){for(r&&e.d.push(+t.slice(0,r)),i-=so;r<i;)e.d.push(+t.slice(r,r+=so));t=t.slice(r),r=so-t.length}else r-=i;for(;r--;)t+=`0`;e.d.push(+t),Ja&&(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 Mo(e,t){var n,r,i,a,o,s,c,l,u;if(t.indexOf(`_`)>-1){if(t=t.replace(/(\d)_(?=\d)/g,`$1`),ao.test(t))return jo(e,t)}else if(t===`Infinity`||t===`NaN`)return+t||(e.s=NaN),e.e=NaN,e.d=null,e;if(ro.test(t))n=16,t=t.toLowerCase();else if(no.test(t))n=2;else if(io.test(t))n=8;else throw Error(Xa+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=To(r,new r(n),a,a*2)),l=ho(t,n,oo),u=l.length-1,a=u;l[a]===0;--a)l.pop();return a<0?new r(e.s*0):(e.e=bo(l,u),e.d=l,Ja=!1,o&&(e=_o(e,i,s*4)),c&&(e=e.times(Math.abs(c)<54?to(2,c):Es.pow(2,c))),Ja=!0,e)}function No(e,t){var n,r=t.d.length;if(r<3)return t.isZero()?t:Po(e,2,t,t);n=1.4*Math.sqrt(r),n=n>16?16:n|0,t=t.times(1/Fo(5,n)),t=Po(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 Po(e,t,n,r,i){var a,o,s,c,l=1,u=e.precision,d=Math.ceil(u/so);for(Ja=!1,c=n.times(n),s=new e(r);;){if(o=_o(s.times(c),new e(t++*t++),u,1),s=i?r.plus(o):r.minus(o),r=_o(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 Ja=!0,o.d.length=d+1,o}function Fo(e,t){for(var n=e;--t;)n*=e;return n}function Io(e,t){var n,r=t.s<0,i=So(e,e.precision,1),a=i.times(.5);if(t=t.abs(),t.lte(a))return qa=r?4:1,t;if(n=t.divToInt(i),n.isZero())qa=r?3:2;else{if(t=t.minus(n.times(i)),t.lte(a))return qa=Eo(n)?r?2:3:r?4:1,t;qa=Eo(n)?r?1:4:r?3:2}return t.minus(i).abs()}function Lo(e,t,n,r){var i,a,o,s,c,l,u,d,f,p=e.constructor,m=n!==void 0;if(m?(po(n,1,Va),r===void 0?r=p.rounding:po(r,0,8)):(n=p.precision,r=p.rounding),!e.isFinite())u=Ao(e);else{for(u=yo(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=ho(yo(f),10,i),f.e=f.d.length),d=ho(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=_o(e,f,n,r,0,i),d=e.d,a=e.e,l=Ka),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+=Ha.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=ho(u,i,t),c=d.length;!d[c-1];--c);for(o=1,u=`1.`;o<c;o++)u+=Ha.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 Ro(e,t){if(e.length>t)return e.length=t,!0}function zo(e){return new this(e).abs()}function Bo(e){return new this(e).acos()}function Vo(e){return new this(e).acosh()}function Ho(e,t){return new this(e).plus(t)}function Uo(e){return new this(e).asin()}function Wo(e){return new this(e).asinh()}function Go(e){return new this(e).atan()}function Ko(e){return new this(e).atanh()}function qo(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=So(this,a,1).times(t.s>0?.25:.75),n.s=e.s):!t.d||e.isZero()?(n=t.s<0?So(this,r,i):new this(0),n.s=e.s):!e.d||t.isZero()?(n=So(this,a,1).times(.5),n.s=e.s):t.s<0?(this.precision=a,this.rounding=1,n=this.atan(_o(e,t,a,1)),t=So(this,a,1),this.precision=r,this.rounding=i,n=e.s<0?n.minus(t):n.plus(t)):n=this.atan(_o(e,t,a,1)),n}function Jo(e){return new this(e).cbrt()}function Yo(e){return vo(e=new this(e),e.e+1,2)}function Xo(e,t,n){return new this(e).clamp(t,n)}function Zo(e){if(!e||typeof e!=`object`)throw Error(Ya+`Object expected`);var t,n,r,i=e.defaults===!0,a=[`precision`,1,Va,`rounding`,0,8,`toExpNeg`,-Ba,0,`toExpPos`,0,Ba,`maxE`,0,Ba,`minE`,-Ba,0,`modulo`,0,9];for(t=0;t<a.length;t+=3)if(n=a[t],i&&(this[n]=Ga[n]),(r=e[n])!==void 0)if(eo(r)===r&&r>=a[t+1]&&r<=a[t+2])this[n]=r;else throw Error(Xa+n+`: `+r);if(n=`crypto`,i&&(this[n]=Ga[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(Qa);else this[n]=!1;else throw Error(Xa+n+`: `+r);return this}function Qo(e){return new this(e).cos()}function $o(e){return new this(e).cosh()}function es(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,as(e)){a.s=e.s,Ja?!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++;Ja?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 jo(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),ao.test(e)?jo(a,e):Mo(a,e);if(r===`bigint`)return e<0?(e=-e,a.s=-1):a.s=1,jo(a,e.toString());throw Error(Xa+e)}if(i.prototype=X,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=Zo,i.clone=es,i.isDecimal=as,i.abs=zo,i.acos=Bo,i.acosh=Vo,i.add=Ho,i.asin=Uo,i.asinh=Wo,i.atan=Go,i.atanh=Ko,i.atan2=qo,i.cbrt=Jo,i.ceil=Yo,i.clamp=Xo,i.cos=Qo,i.cosh=$o,i.div=ts,i.exp=ns,i.floor=rs,i.hypot=is,i.ln=os,i.log=ss,i.log10=ls,i.log2=cs,i.max=us,i.min=ds,i.mod=fs,i.mul=ps,i.pow=ms,i.random=hs,i.round=gs,i.sign=_s,i.sin=vs,i.sinh=ys,i.sqrt=bs,i.sub=xs,i.sum=Ss,i.tan=Cs,i.tanh=ws,i.trunc=Ts,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 ts(e,t){return new this(e).div(t)}function ns(e){return new this(e).exp()}function rs(e){return vo(e=new this(e),e.e+1,3)}function is(){var e,t,n=new this(0);for(Ja=!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 Ja=!0,new this(1/0);n=t}return Ja=!0,n.sqrt()}function as(e){return e instanceof Es||e&&e.toStringTag===$a||!1}function os(e){return new this(e).ln()}function ss(e,t){return new this(e).log(t)}function cs(e){return new this(e).log(2)}function ls(e){return new this(e).log(10)}function us(){return Do(this,arguments,-1)}function ds(){return Do(this,arguments,1)}function fs(e,t){return new this(e).mod(t)}function ps(e,t){return new this(e).mul(t)}function ms(e,t){return new this(e).pow(t)}function hs(e){var t,n,r,i,a=0,o=new this(1),s=[];if(e===void 0?e=this.precision:po(e,1,Va),r=Math.ceil(e/so),!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(Qa);for(r=s[--a],e%=so,r&&e&&(i=to(10,so-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-=so)s.shift();for(r=1,i=s[0];i>=10;i/=10)r++;r<so&&(n-=so-r)}return o.e=n,o.d=s,o}function gs(e){return vo(e=new this(e),e.e+1,this.rounding)}function _s(e){return e=new this(e),e.d?e.d[0]?e.s:0*e.s:e.s||NaN}function vs(e){return new this(e).sin()}function ys(e){return new this(e).sinh()}function bs(e){return new this(e).sqrt()}function xs(e,t){return new this(e).sub(t)}function Ss(){var e=0,t=arguments,n=new this(t[e]);for(Ja=!1;n.s&&++e<t.length;)n=n.plus(t[e]);return Ja=!0,vo(n,this.precision,this.rounding)}function Cs(e){return new this(e).tan()}function ws(e){return new this(e).tanh()}function Ts(e){return vo(e=new this(e),e.e+1,1)}X[Symbol.for(`nodejs.util.inspect.custom`)]=X.toString,X[Symbol.toStringTag]=`Decimal`;var Es=X.constructor=es(Ga);Ua=new Es(Ua),Wa=new Es(Wa);var Ds=Y(`BigNumber`,[`?on`,`config`],e=>{var{on:t,config:n}=e,r=Es.clone({precision:n.precision,modulo:Es.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}),Os=Math.cosh||function(e){return Math.abs(e)<1e-9?1-e:(Math.exp(e)+Math.exp(-e))*.5},ks=Math.sinh||function(e){return Math.abs(e)<1e-9?e:(Math.exp(e)-Math.exp(-e))*.5},As=e=>{let t=Math.sin(.5*e);return-2*t*t},js=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))},Ms=function(){throw SyntaxError(`Invalid Param`)};function Ns(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 Ps={re:0,im:0},Fs=function(e,t){let n=Ps;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 Z.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 Z.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]):Ms();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&&Ms();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&&Ms(),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))&&Ms(),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&&Ms();break;case`number`:n.im=0,n.re=e;break;default:Ms()}return isNaN(n.re)||isNaN(n.im),n};function Z(e,t){if(!(this instanceof Z))return new Z(e,t);let n=Fs(e,t);this.re=n.re,this.im=n.im}Z.prototype={re:0,im:0,sign:function(){let e=js(this.re,this.im);return new Z(this.re/e,this.im/e)},add:function(e,t){let n=Fs(e,t),r=this.isInfinite(),i=!(isFinite(n.re)&&isFinite(n.im));return r||i?r&&i?Z.NAN:Z.INFINITY:new Z(this.re+n.re,this.im+n.im)},sub:function(e,t){let n=Fs(e,t),r=this.isInfinite(),i=!(isFinite(n.re)&&isFinite(n.im));return r||i?r&&i?Z.NAN:Z.INFINITY:new Z(this.re-n.re,this.im-n.im)},mul:function(e,t){let n=Fs(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?Z.NAN:r||i?Z.INFINITY:n.im===0&&this.im===0?new Z(this.re*n.re,0):new Z(this.re*n.re-this.im*n.im,this.re*n.im+this.im*n.re)},div:function(e,t){let n=Fs(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 Z.NAN;if(o||r)return Z.INFINITY;if(a||i)return Z.ZERO;if(n.im===0)return new Z(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 Z((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 Z((this.re+this.im*e)/t,(this.im-this.re*e)/t)}},pow:function(e,t){let n=Fs(e,t),r=this.re===0&&this.im===0;if(n.re===0&&n.im===0)return Z.ONE;if(n.im===0){if(this.im===0&&this.re>0)return new Z(this.re**+n.re,0);if(this.re===0)switch((n.re%4+4)%4){case 0:return new Z(this.im**+n.re,0);case 1:return new Z(0,this.im**+n.re);case 2:return new Z(-(this.im**+n.re),0);case 3:return new Z(0,-(this.im**+n.re))}}if(r&&n.re>0)return Z.ZERO;let i=Math.atan2(this.im,this.re),a=Ns(this.re,this.im),o=Math.exp(n.re*a-n.im*i),s=n.im*a+n.re*i;return new Z(o*Math.cos(s),o*Math.sin(s))},sqrt:function(){let e=this.re,t=this.im;if(t===0)return e>=0?new Z(Math.sqrt(e),0):new Z(0,Math.sqrt(-e));let n=js(e,t),r=Math.sqrt(.5*(n+Math.abs(e))),i=Math.abs(t)/(2*r);return e>=0?new Z(r,t<0?-i:i):new Z(i,t<0?-r:r)},exp:function(){let e=Math.exp(this.re);return this.im===0?new Z(e,0):new Z(e*Math.cos(this.im),e*Math.sin(this.im))},expm1:function(){let e=this.re,t=this.im;return new Z(Math.expm1(e)*Math.cos(t)+As(t),Math.exp(e)*Math.sin(t))},log:function(){let e=this.re,t=this.im;return t===0&&e>0?new Z(Math.log(e),0):new Z(Ns(e,t),Math.atan2(t,e))},abs:function(){return js(this.re,this.im)},arg:function(){return Math.atan2(this.im,this.re)},sin:function(){let e=this.re,t=this.im;return new Z(Math.sin(e)*Os(t),Math.cos(e)*ks(t))},cos:function(){let e=this.re,t=this.im;return new Z(Math.cos(e)*Os(t),-Math.sin(e)*ks(t))},tan:function(){let e=2*this.re,t=2*this.im,n=Math.cos(e)+Os(t);return new Z(Math.sin(e)/n,ks(t)/n)},cot:function(){let e=2*this.re,t=2*this.im,n=Math.cos(e)-Os(t);return new Z(-Math.sin(e)/n,ks(t)/n)},sec:function(){let e=this.re,t=this.im,n=.5*Os(2*t)+.5*Math.cos(2*e);return new Z(Math.cos(e)*Os(t)/n,Math.sin(e)*ks(t)/n)},csc:function(){let e=this.re,t=this.im,n=.5*Os(2*t)-.5*Math.cos(2*e);return new Z(Math.sin(e)*Os(t)/n,-Math.cos(e)*ks(t)/n)},asin:function(){let e=this.re,t=this.im,n=new Z(t*t-e*e+1,-2*e*t).sqrt(),r=new Z(n.re-t,n.im+e).log();return new Z(r.im,-r.re)},acos:function(){let e=this.re,t=this.im,n=new Z(t*t-e*e+1,-2*e*t).sqrt(),r=new Z(n.re-t,n.im+e).log();return new Z(Math.PI/2-r.im,r.re)},atan:function(){let e=this.re,t=this.im;if(e===0){if(t===1)return new Z(0,1/0);if(t===-1)return new Z(0,-1/0)}let n=e*e+(1-t)*(1-t),r=new Z((1-t*t-e*e)/n,-2*e/n).log();return new Z(-.5*r.im,.5*r.re)},acot:function(){let e=this.re,t=this.im;if(t===0)return new Z(Math.atan2(1,e),0);let n=e*e+t*t;return n===0?new Z(e===0?0:e/0,t===0?0:-t/0).atan():new Z(e/n,-t/n).atan()},asec:function(){let e=this.re,t=this.im;if(e===0&&t===0)return new Z(0,1/0);let n=e*e+t*t;return n===0?new Z(e===0?0:e/0,t===0?0:-t/0).acos():new Z(e/n,-t/n).acos()},acsc:function(){let e=this.re,t=this.im;if(e===0&&t===0)return new Z(Math.PI/2,1/0);let n=e*e+t*t;return n===0?new Z(e===0?0:e/0,t===0?0:-t/0).asin():new Z(e/n,-t/n).asin()},sinh:function(){let e=this.re,t=this.im;return new Z(ks(e)*Math.cos(t),Os(e)*Math.sin(t))},cosh:function(){let e=this.re,t=this.im;return new Z(Os(e)*Math.cos(t),ks(e)*Math.sin(t))},tanh:function(){let e=2*this.re,t=2*this.im,n=Os(e)+Math.cos(t);return new Z(ks(e)/n,Math.sin(t)/n)},coth:function(){let e=2*this.re,t=2*this.im,n=Os(e)-Math.cos(t);return new Z(ks(e)/n,-Math.sin(t)/n)},csch:function(){let e=this.re,t=this.im,n=Math.cos(2*t)-Os(2*e);return new Z(-2*ks(e)*Math.cos(t)/n,2*Os(e)*Math.sin(t)/n)},sech:function(){let e=this.re,t=this.im,n=Math.cos(2*t)+Os(2*e);return new Z(2*Os(e)*Math.cos(t)/n,-2*ks(e)*Math.sin(t)/n)},asinh:function(){let e=this.re,t=this.im;if(t===0){if(e===0)return new Z(0,0);let t=Math.abs(e),n=Math.log(t+Math.sqrt(t*t+1));return new Z(e<0?-n:n,0)}let n=new Z(e*e-t*t+1,2*e*t).sqrt();return new Z(e+n.re,t+n.im).log()},acosh:function(){let e=this.re,t=this.im;if(t===0){if(e>1)return new Z(Math.log(e+Math.sqrt(e-1)*Math.sqrt(e+1)),0);if(e<-1){let t=Math.sqrt(e*e-1);return new Z(Math.log(-e+t),Math.PI)}return new Z(0,Math.acos(e))}let n=new Z(e-1,t).sqrt(),r=new Z(e+1,t).sqrt();return new Z(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 Z(0,0);if(e===1)return new Z(1/0,0);if(e===-1)return new Z(-1/0,0);if(-1<e&&e<1)return new Z(.5*Math.log((1+e)/(1-e)),0);if(e>1){let t=(e+1)/(e-1);return new Z(.5*Math.log(t),-Math.PI/2)}let t=(1+e)/(1-e);return new Z(.5*Math.log(-t),Math.PI/2)}let n=1-e,r=1+e,i=n*n+t*t;if(i===0)return new Z(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 Z(Ns(a,o)/2,Math.atan2(o,a)/2)},acoth:function(){let e=this.re,t=this.im;if(e===0&&t===0)return new Z(0,Math.PI/2);let n=e*e+t*t;return n===0?new Z(e===0?0:e/0,t===0?0:-t/0).atanh():new Z(e/n,-t/n).atanh()},acsch:function(){let e=this.re,t=this.im;if(t===0){if(e===0)return new Z(1/0,0);let t=1/e;return new Z(Math.log(t+Math.sqrt(t*t+1)),0)}let n=e*e+t*t;return n===0?new Z(e===0?0:e/0,t===0?0:-t/0).asinh():new Z(e/n,-t/n).asinh()},asech:function(){let e=this.re,t=this.im;if(this.isZero())return Z.INFINITY;let n=e*e+t*t;return n===0?new Z(e===0?0:e/0,t===0?0:-t/0).acosh():new Z(e/n,-t/n).acosh()},inverse:function(){if(this.isZero())return Z.INFINITY;if(this.isInfinite())return Z.ZERO;let e=this.re,t=this.im,n=e*e+t*t;return new Z(e/n,-t/n)},conjugate:function(){return new Z(this.re,-this.im)},neg:function(){return new Z(-this.re,-this.im)},ceil:function(e){return e=10**(e||0),new Z(Math.ceil(this.re*e)/e,Math.ceil(this.im*e)/e)},floor:function(e){return e=10**(e||0),new Z(Math.floor(this.re*e)/e,Math.floor(this.im*e)/e)},round:function(e){return e=10**(e||0),new Z(Math.round(this.re*e)/e,Math.round(this.im*e)/e)},equals:function(e,t){let n=Fs(e,t);return Math.abs(n.re-this.re)<=Z.EPSILON&&Math.abs(n.im-this.im)<=Z.EPSILON},clone:function(){return new Z(this.re,this.im)},toString:function(){let e=this.re,t=this.im,n=``;return this.isNaN()?`NaN`:this.isInfinite()?`Infinity`:(Math.abs(e)<Z.EPSILON&&(e=0),Math.abs(t)<Z.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()}},Z.ZERO=new Z(0,0),Z.ONE=new Z(1,0),Z.I=new Z(0,1),Z.PI=new Z(Math.PI,0),Z.E=new Z(Math.E,0),Z.INFINITY=new Z(1/0,1/0),Z.NAN=new Z(NaN,NaN),Z.EPSILON=1e-15;var Is=Y(`Complex`,[],()=>(Object.defineProperty(Z,`name`,{value:`Complex`}),Z.prototype.constructor=Z,Z.prototype.type=`Complex`,Z.prototype.isComplex=!0,Z.prototype.toJSON=function(){return{mathjs:`Complex`,re:this.re,im:this.im}},Z.prototype.toPolar=function(){return{r:this.abs(),phi:this.arg()}},Z.prototype.format=function(e){var t=``,n=this.im,r=this.re,i=fa(this.re,e),a=fa(this.im,e),o=Kr(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},Z.fromPolar=function(e){switch(arguments.length){case 1:var t=arguments[0];if(typeof t==`object`)return Z(t);throw TypeError(`Input has to be an object with r and phi keys.`);case 2:var n=arguments[0],r=arguments[1];if(Kr(n)){if(Zr(r)&&r.hasBase(`ANGLE`)&&(r=r.toNumber(`rad`)),Kr(r))return new Z({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`)}},Z.prototype.valueOf=Z.prototype.toString,Z.fromJSON=function(e){return new Z(e)},Z.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},Z),{isClass:!0});typeof BigInt>`u`&&(BigInt=function(e){if(isNaN(e))throw Error(``);return e});var Ls=BigInt(0),Rs=BigInt(1),zs=BigInt(2),Bs=BigInt(3),Vs=BigInt(5),Hs=BigInt(10);BigInt(2**53-1);var Us=2e3,Ws={s:Rs,n:Ls,d:Rs};function Gs(e,t){try{e=BigInt(e)}catch{throw rc()}return e*t}function Ks(e){return typeof e==`bigint`?e:Math.floor(e)}function qs(e,t){if(t===Ls)throw nc();let n=Object.create(tc.prototype);n.s=e<Ls?-Rs:Rs,e=e<Ls?-e:e;let r=ec(e,t);return n.n=e/r,n.d=t/r,n}var Js=[zs*zs,zs,zs*zs,zs,zs*zs,zs*Bs,zs,zs*Bs];function Ys(e){let t=Object.create(null);if(e<=Rs)return t[e]=Rs,t;let n=e=>{t[e]=(t[e]||Ls)+Rs};for(;e%zs===Ls;)n(zs),e/=zs;for(;e%Bs===Ls;)n(Bs),e/=Bs;for(;e%Vs===Ls;)n(Vs),e/=Vs;for(let t=0,r=zs+Vs;r*r<=e;){for(;e%r===Ls;)n(r),e/=r;r+=Js[t],t=t+1&7}return e>Rs&&n(e),t}var Xs=function(e,t){let n=Ls,r=Rs,i=Rs;if(e!=null)if(t!==void 0){if(typeof e==`bigint`)n=e;else if(isNaN(e))throw rc();else if(e%1!=0)throw ic();else n=BigInt(e);if(typeof t==`bigint`)r=t;else if(isNaN(t))throw rc();else if(t%1!=0)throw ic();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 rc();i=n*r}else if(typeof e==`number`){if(isNaN(e))throw rc();if(e<0&&(i=-Rs,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=Ls,o=Ls,s=Ls,c=Rs,l=Rs,u=e.replace(/_/g,``).match(/\d+|./g);if(u===null)throw rc();if(u[t]===`-`?(i=-Rs,t++):u[t]===`+`&&t++,u.length===t+1?o=Gs(u[t++],i):u[t+1]===`.`||u[t]===`.`?(u[t]!==`.`&&(a=Gs(u[t++],i)),t++,(t+1===u.length||u[t+1]===`(`&&u[t+3]===`)`||u[t+1]===`'`&&u[t+3]===`'`)&&(o=Gs(u[t],i),c=Hs**BigInt(u[t].length),t++),(u[t]===`(`&&u[t+2]===`)`||u[t]===`'`&&u[t+2]===`'`)&&(s=Gs(u[t+1],i),l=Hs**BigInt(u[t+1].length)-Rs,t+=3)):u[t+1]===`/`||u[t+1]===`:`?(o=Gs(u[t],i),c=Gs(u[t+2],Rs),t+=3):u[t+3]===`/`&&u[t+1]===` `&&(a=Gs(u[t],i),o=Gs(u[t+2],i),c=Gs(u[t+4],Rs),t+=5),u.length<=t)r=c*l,i=n=s+r*a+l*o;else throw rc()}else if(typeof e==`bigint`)n=e,i=e,r=Rs;else throw rc();if(r===Ls)throw nc();Ws.s=i<Ls?-Rs:Rs,Ws.n=n<Ls?-n:n,Ws.d=r<Ls?-r:r};function Zs(e,t,n){let r=Rs;for(;t>Ls;e=e*e%n,t>>=Rs)t&Rs&&(r=r*e%n);return r}function Qs(e,t){for(;t%zs===Ls;t/=zs);for(;t%Vs===Ls;t/=Vs);if(t===Rs)return Ls;let n=Hs%t,r=1;for(;n!==Rs;r++)if(n=n*Hs%t,r>Us)return Ls;return BigInt(r)}function $s(e,t,n){let r=Rs,i=Zs(Hs,n,t);for(let e=0;e<300;e++){if(r===i)return BigInt(e);r=r*Hs%t,i=i*Hs%t}return 0}function ec(e,t){if(!e)return t;if(!t)return e;for(;;){if(e%=t,!e)return t;if(t%=e,!t)return e}}function tc(e,t){if(Xs(e,t),this instanceof tc)e=ec(Ws.d,Ws.n),this.s=Ws.s,this.n=Ws.n/e,this.d=Ws.d/e;else return qs(Ws.s*Ws.n,Ws.d)}var nc=function(){return Error(`Division by Zero`)},rc=function(){return Error(`Invalid argument`)},ic=function(){return Error(`Parameters must be integer`)};tc.prototype={s:Rs,n:Ls,d:Rs,abs:function(){return qs(this.n,this.d)},neg:function(){return qs(-this.s*this.n,this.d)},add:function(e,t){return Xs(e,t),qs(this.s*this.n*Ws.d+Ws.s*this.d*Ws.n,this.d*Ws.d)},sub:function(e,t){return Xs(e,t),qs(this.s*this.n*Ws.d-Ws.s*this.d*Ws.n,this.d*Ws.d)},mul:function(e,t){return Xs(e,t),qs(this.s*Ws.s*this.n*Ws.n,this.d*Ws.d)},div:function(e,t){return Xs(e,t),qs(this.s*Ws.s*this.n*Ws.d,this.d*Ws.n)},clone:function(){return qs(this.s*this.n,this.d)},mod:function(e,t){if(e===void 0)return qs(this.s*this.n%this.d,Rs);if(Xs(e,t),Ls===Ws.n*this.d)throw nc();return qs(this.s*(Ws.d*this.n)%(Ws.n*this.d),Ws.d*this.d)},gcd:function(e,t){return Xs(e,t),qs(ec(Ws.n,this.n)*ec(Ws.d,this.d),Ws.d*this.d)},lcm:function(e,t){return Xs(e,t),Ws.n===Ls&&this.n===Ls?qs(Ls,Rs):qs(Ws.n*this.n,ec(Ws.n,this.n)*ec(Ws.d,this.d))},inverse:function(){return qs(this.s*this.d,this.n)},pow:function(e,t){if(Xs(e,t),Ws.d===Rs)return Ws.s<Ls?qs((this.s*this.d)**Ws.n,this.n**Ws.n):qs((this.s*this.n)**Ws.n,this.d**Ws.n);if(this.s<Ls)return null;let n=Ys(this.n),r=Ys(this.d),i=Rs,a=Rs;for(let e in n)if(e!==`1`){if(e===`0`){i=Ls;break}if(n[e]*=Ws.n,n[e]%Ws.d===Ls)n[e]/=Ws.d;else return null;i*=BigInt(e)**n[e]}for(let e in r)if(e!==`1`){if(r[e]*=Ws.n,r[e]%Ws.d===Ls)r[e]/=Ws.d;else return null;a*=BigInt(e)**r[e]}return Ws.s<Ls?qs(a,i):qs(i,a)},log:function(e,t){if(Xs(e,t),this.s<=Ls||Ws.s<=Ls)return null;let n=Object.create(null),r=Ys(Ws.n),i=Ys(Ws.d),a=Ys(this.n),o=Ys(this.d);for(let e in i)r[e]=(r[e]||Ls)-i[e];for(let e in o)a[e]=(a[e]||Ls)-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]||Ls,n=a[e]||Ls;if(t===Ls){if(n!==Ls)return null;continue}let i=n,o=t,l=ec(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?qs(s,c):null},equals:function(e,t){return Xs(e,t),this.s*this.n*Ws.d===Ws.s*Ws.n*this.d},lt:function(e,t){return Xs(e,t),this.s*this.n*Ws.d<Ws.s*Ws.n*this.d},lte:function(e,t){return Xs(e,t),this.s*this.n*Ws.d<=Ws.s*Ws.n*this.d},gt:function(e,t){return Xs(e,t),this.s*this.n*Ws.d>Ws.s*Ws.n*this.d},gte:function(e,t){return Xs(e,t),this.s*this.n*Ws.d>=Ws.s*Ws.n*this.d},compare:function(e,t){Xs(e,t);let n=this.s*this.n*Ws.d-Ws.s*Ws.n*this.d;return(Ls<n)-(n<Ls)},ceil:function(e){return e=Hs**BigInt(e||0),qs(Ks(this.s*e*this.n/this.d)+(e*this.n%this.d>Ls&&this.s>=Ls?Rs:Ls),e)},floor:function(e){return e=Hs**BigInt(e||0),qs(Ks(this.s*e*this.n/this.d)-(e*this.n%this.d>Ls&&this.s<Ls?Rs:Ls),e)},round:function(e){return e=Hs**BigInt(e||0),qs(Ks(this.s*e*this.n/this.d)+this.s*((this.s>=Ls?Rs:Ls)+zs*(e*this.n%this.d)>this.d?Rs:Ls),e)},roundTo:function(e,t){Xs(e,t);let n=this.n*Ws.d,r=this.d*Ws.n,i=n%r,a=Ks(n/r);return i+i>=r&&a++,qs(this.s*a*Ws.n,Ws.d)},divisible:function(e,t){return Xs(e,t),Ws.n===Ls?!1:this.n*Ws.d%(Ws.n*this.d)===Ls},valueOf:function(){return Number(this.s*this.n)/Number(this.d)},toString:function(e=15){let t=this.n,n=this.d,r=Qs(t,n),i=$s(t,n,r),a=this.s<Ls?`-`:``;if(a+=Ks(t/n),t%=n,t*=Hs,t&&(a+=`.`),r){for(let e=i;e--;)a+=Ks(t/n),t%=n,t*=Hs;a+=`(`;for(let e=r;e--;)a+=Ks(t/n),t%=n,t*=Hs;a+=`)`}else for(let r=e;t&&r--;)a+=Ks(t/n),t%=n,t*=Hs;return a},toFraction:function(e=!1){let t=this.n,n=this.d,r=this.s<Ls?`-`:``;if(n===Rs)r+=t;else{let i=Ks(t/n);e&&i>Ls&&(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<Ls?`-`:``;if(n===Rs)r+=t;else{let i=Ks(t/n);e&&i>Ls&&(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(Ks(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=qs(r[e-1],Rs);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 ac=Y(`Fraction`,[],()=>(Object.defineProperty(tc,`name`,{value:`Fraction`}),tc.prototype.constructor=tc,tc.prototype.type=`Fraction`,tc.prototype.isFraction=!0,tc.prototype.toJSON=function(){return{mathjs:`Fraction`,n:String(this.s*this.n),d:String(this.d)}},tc.fromJSON=function(e){return new tc(e)},tc),{isClass:!0}),oc=Y(`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(qr(t))t=t.toNumber();else if(typeof t!=`number`&&!Jr(t))throw TypeError(`Parameter start must be a number or bigint`)}if(a){if(qr(n))n=n.toNumber();else if(typeof n!=`number`&&!Jr(n))throw TypeError(`Parameter end must be a number or bigint`)}if(o){if(qr(r))r=r.toNumber();else if(typeof r!=`number`&&!Jr(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&&Sa(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 aa(n)===aa(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=fa(this.start,e);return this.step!==1&&(t+=`:`+fa(this.step,e)),t+=`:`+fa(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}),sc=Y(`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 cc(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(!ra(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 lc(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}=pa(t);switch(n){case`fixed`:return fc(e,r);case`exponential`:return dc(e,r);case`engineering`:return uc(e,r);case`bin`:return cc(e,2,i);case`oct`:return cc(e,8,i);case`hex`:return cc(e,16,i);case`auto`:var a=pc(t?.lowerExp,-3),o=pc(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():dc(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 uc(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 dc(e,t){return t===void 0?e.toExponential():e.toExponential(t-1)}function fc(e,t){return e.toFixed(t)}function pc(e,t){return Kr(e)?e:qr(e)?e.toNumber():t}function mc(e,t){var n=e.length-t.length,r=e.length;return e.substring(n,r)===t}function hc(e,t){var n=gc(e,t);return t&&typeof t==`object`&&`truncate`in t&&n.length>t.truncate?n.substring(0,t.truncate-3)+`...`:n}function gc(e,t){return typeof e==`number`?fa(e,t):qr(e)?lc(e,t):xc(e)?!t||t.fraction!==`decimal`?`${e.s*e.n}/${e.d}`:e.toString():Array.isArray(e)?bc(e,t):Qr(e)?_c(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=>_c(n)+`: `+hc(e[n],t)).join(`, `)+`}`:String(e)}function _c(e){for(var t=String(e),n=``,r=0;r<t.length;){var i=t.charAt(r);n+=i in vc?vc[i]:i,r++}return`"`+n+`"`}var vc={'"':`\\"`,"\\":`\\\\`,"\b":`\\b`,"\f":`\\f`,"\n":`\\n`,"\r":`\\r`," ":`\\t`};function yc(e){var t=String(e);return t=t.replace(/&/g,`&amp;`).replace(/"/g,`&quot;`).replace(/'/g,`&#39;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`),t}function bc(e,t){if(Array.isArray(e)){for(var n=`[`,r=e.length,i=0;i<r;i++)i!==0&&(n+=`, `),n+=bc(e[i],t);return n+=`]`,n}else return hc(e,t)}function xc(e){return e&&typeof e==`object`&&typeof e.s==`bigint`&&typeof e.n==`bigint`&&typeof e.d==`bigint`||!1}function Sc(e,t){if(!Qr(e))throw TypeError(`Unexpected type of argument in function compareText (expected: string or Array or Matrix, actual: `+Ii(e)+`, index: 0)`);if(!Qr(t))throw TypeError(`Unexpected type of argument in function compareText (expected: string or Array or Matrix, actual: `+Ii(t)+`, index: 1)`);return e===t?0:e>t?1:-1}function Cc(e,t,n){if(!(this instanceof Cc))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}Cc.prototype=RangeError(),Cc.prototype.constructor=RangeError,Cc.prototype.name=`DimensionError`,Cc.prototype.isDimensionError=!0;function wc(e,t,n){if(!(this instanceof wc))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}wc.prototype=RangeError(),wc.prototype.constructor=RangeError,wc.prototype.name=`IndexError`,wc.prototype.isIndexError=!0;function Tc(e){for(var t=[];Array.isArray(e);)t.push(e.length),e=e[0];return t}function Ec(e,t,n){var r,i=e.length;if(i!==t[n])throw new Cc(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 Cc(t.length-1,t.length,`<`);Ec(e[r],t,a)}}else for(r=0;r<i;r++)if(Array.isArray(e[r]))throw new Cc(t.length+1,t.length,`>`)}function Dc(e,t){if(t.length===0){if(Array.isArray(e))throw new Cc(e.length,0)}else Ec(e,t,0)}function Oc(e,t){var n=e.isMatrix?e._size:Tc(e);t._sourceSize.forEach((e,t)=>{if(e!==null&&e!==n[t])throw new Cc(e,n[t])})}function kc(e,t){if(e!==void 0){if(!Kr(e)||!ra(e))throw TypeError(`Index must be an integer (value: `+e+`)`);if(e<0||typeof t==`number`&&e>=t)throw new wc(e,t)}}function Ac(e){for(var t=0;t<e._dimensions.length;++t){var n=e._dimensions[t];if(n._data&&$r(n._data)){if(n._size[0]===0)return!0}else if(n.isRange){if(n.start===n.end)return!0}else if(Qr(n)&&n.length===0)return!0}return!1}function jc(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(!Kr(e)||!ra(e)||e<0)throw TypeError(`Invalid size, must contain positive integers (size: `+hc(t)+`)`)}),(Kr(e)||qr(e))&&(e=[e]),Mc(e,t,0,n===void 0?0:n),e}function Mc(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),Mc(a,t,l,r);for(i=c;i<s;i++)a=[],e[i]=a,Mc(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 Nc(e,t){var n=Vc(e,!0),r=n.length;if(!Array.isArray(e)||!Array.isArray(t))throw TypeError(`Array expected`);if(t.length===0)throw new Cc(0,r,`!=`);t=Pc(t,r);var i=Fc(t);if(r!==i)throw new Cc(i,r,`!=`);try{return Ic(n,t)}catch(e){throw e instanceof Cc?new Cc(i,r,`!=`):e}}function Pc(e,t){var n=Fc(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 Fc(e){return e.reduce((e,t)=>e*t,1)}function Ic(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 Lc(e,t){for(var n=t||Tc(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=Rc(e,r,0),n.length=r),e}function Rc(e,t,n){var r,i;if(n<t){var a=n+1;for(r=0,i=e.length;r<i;r++)e[r]=Rc(e[r],t,a)}else for(;Array.isArray(e);)e=e[0];return e}function zc(e,t,n,r){var i=r||Tc(e);if(n)for(var a=0;a<n;a++)e=[e],i.unshift(1);for(e=Bc(e,t,0);i.length<t;)i.push(1);return e}function Bc(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]=Bc(e[r],t,a)}else for(var o=n;o<t;o++)e=[e];return e}function Vc(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 Hc(e,t){return Array.prototype.map.call(e,t)}function Uc(e,t){Array.prototype.forEach.call(e,t)}function Wc(e,t){if(Tc(e).length!==1)throw Error(`Only one dimensional matrices supported`);return Array.prototype.filter.call(e,t)}function Gc(e,t){if(Tc(e).length!==1)throw Error(`Only one dimensional matrices supported`);return Array.prototype.filter.call(e,e=>t.test(e))}function Kc(e,t){return Array.prototype.join.call(e,t)}function qc(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 Jc(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 Yc(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?Yc(a,t):t(a);if(n===void 0)n=s;else if(n!==s)return`mixed`}return n}function Xc(e,t,n,r){if(r<n){if(e.length!==t.length)throw new Cc(e.length,t.length);for(var i=[],a=0;a<e.length;a++)i[a]=Xc(e[a],t[a],n,r+1);return i}else return e.concat(t)}function Zc(){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 Xc(e,n,t,0)},e[0]);throw Error(`Wrong number of arguments in function concat`)}function Qc(){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++)$c(e[l],r);return r}function $c(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 el(e,t){var n=Tc(e);if(Vi(n,t))return e;$c(n,t);var r=Qc(n,t),i=r.length,a=[...Array(i-n.length).fill(1),...n],o=al(e);n.length<i&&(o=Nc(o,a),n=Tc(o));for(var s=0;s<i;s++)n[s]<r[s]&&(o=tl(o,r[s],s),n=Tc(o));return o}function tl(e,t,n){return Zc(...Array(t).fill(e),n)}function nl(e,t){if(!Array.isArray(e))throw Error(`Array expected`);if(!Array.isArray(t))throw Error(`Array expected for index`);var n=Tc(e);if(t.length!==n.length)throw new Cc(t.length,n.length);for(var r=0;r<t.length;r++)kc(t[r],n[r]);return t.reduce((e,t)=>e[t],e)}function rl(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 il(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 al(e){return kr([],e)}function ol(e,t,n,r){if(Ma.default.isTypedFunction(e)){var i;if(r)i=1;else{var a=t.isMatrix?t.size():Tc(t);if(!a.length||a[a.length-1]===0)return{isUnary:r,fn:e};var o=a.map(()=>0);i=ll(e,t.isMatrix?t.get(o):nl(t,o),o,t)}var s;if(t.isMatrix&&t.dataType!==`mixed`&&t.dataType!==void 0){var c=sl(e,i);s=c===void 0?e:c}else s=e;return i>=1&&i<=3?{isUnary:i===1,fn:function(){return ul(s,[...arguments].slice(0,i),n,e.name)}}:{isUnary:!1,fn:function(){return ul(s,[...arguments],n,e.name)}}}return r===void 0?{isUnary:cl(e),fn:e}:{isUnary:r,fn:e}}function sl(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 cl(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 ll(e,t,n,r){for(var i=[t,n,r],a=3;a>0;a--){var o=i.slice(0,a);if(Ma.default.resolve(e,o)!==null)return a}}function ul(e,t,n,r){try{return e(...t)}catch(e){dl(e,t,n,r)}}function dl(e,t,n,r){if(e instanceof TypeError&&e.data?.category===`wrongType`){var i=[];throw i.push(`value: ${Ii(t[0])}`),t.length>=2&&i.push(`index: ${Ii(t[1])}`),t.length>=3&&i.push(`array: ${Ii(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 fl=Y(`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&&!Qr(t))throw Error(`Invalid datatype: `+t);if(ei(e))e.type===`DenseMatrix`?(this._data=Li(e._data),this._size=Li(e._size),this._datatype=t||e._datatype):(this._data=e.toArray(),this._size=e.size(),this._datatype=t||e._datatype);else if(e&&$r(e.data)&&$r(e.size))this._data=e.data,this._size=e.size,Dc(this._data,this._size),this._datatype=t||e.datatype;else if($r(e))this._data=u(e),this._size=Tc(this._data),Dc(this._data,this._size),this._datatype=t;else if(e)throw TypeError(`Unsupported type of data (`+Ii(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 Yc(this._data,Ii)},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 nl(this._data,e)},r.prototype.set=function(e,t,n){if(!$r(e))throw TypeError(`Array expected`);if(e.length<this._size.length)throw new Cc(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],kc(a,s.length),s=s[a];return a=e[e.length-1],kc(a,s.length),s[a]=t,this};function i(e,t){if(!ai(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 Cc(i.length,e._size.length);for(var o=t.min(),s=t.max(),c=0,l=e._size.length;c<l;c++)kc(o[c],e._size[c]),kc(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 Kr(e)?t(e):e.map(t).valueOf()}return Kr(o)?r[a]=null:r[a]=o.size()[0],a<n?s(o,t=>(kc(t,e.length),i(e[t],a+1))):s(o,t=>(kc(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(ei(n)?(o=n.size(),n=n.valueOf()):o=Tc(n),a){if(o.length!==0)throw TypeError(`Scalar expected`);e.set(t.min(),n,r)}else{if(!Vi(o,i)){if(o.length===0)n=el([n],i);else try{n=el(n,i)}catch{}o=Tc(n)}if(i.length<e._size.length)throw new Cc(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=zc(n,i.length,u,o)}if(!Vi(i,o))throw new Cc(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)=>{kc(t,e.length),i(e[t],n[r[0]],a+1)},c=(t,r)=>{kc(t,e.length),e[t]=n[r[0]]};a<r?Kr(o)?s(o,[0]):o.forEach(s):Kr(o)?c(o,[0]):o.forEach(c)}}r.prototype.resize=function(e,t,n){if(!ti(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;$r(r);)r=r[0];return r}return e._size=t.slice(0),e._data=jc(e._data,e._size,n),e}r.prototype.reshape=function(e,t){var n=t?this.clone():this;return n._data=Nc(n._data,e),n._size=Pc(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:Li(this._data),size:Li(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=ol(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=ol(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 Li(this._data)},r.prototype.valueOf=function(){return this._data},r.prototype.format=function(e){return hc(this._data,e)},r.prototype.toString=function(){return hc(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(qr(e)&&(e=e.toNumber()),!Kr(e)||!ra(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(!$r(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(qr(e)&&(e=e.toNumber()),!Kr(e)||!ra(e)||e<1)throw Error(`Size values must be positive integers`);return e}),n){if(qr(n)&&(n=n.toNumber()),!Kr(n)||!ra(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($r(t)){if(t.length!==l)throw Error(`Invalid value array length`);u=function(e){return t[e]}}else if(ei(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||=qr(u(0))?u(0).mul(0):0;var f=[];if(e.length>0){f=jc(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(!Kr(e)||!ra(e)||!Kr(t)||!ra(t))throw Error(`Row index must be positive integers`);if(this._size.length!==2)throw Error(`Only two dimensional matrix is supported`);return kc(e,this._size[0]),kc(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 ei(e)?u(e.valueOf()):$r(e)?e.map(u):e}return r},{isClass:!0}),pl=`clone`,ml=Y(pl,[`typed`],e=>{var{typed:t}=e;return t(pl,{any:Li})});function hl(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 gl(e){for(var t=0;t<e.length;t++)if(ti(e[t]))return!0;return!1}function _l(e,t){ei(e)?e.forEach(e=>t(e),!1,!0):il(e,t,!0)}function vl(e,t,n){if(!n)return ei(e)?e.map(e=>t(e),!1,!0):rl(e,t,!0);var r=e=>e===0?e:t(e);return ei(e)?e.map(e=>r(e),!1,!0):rl(e,r,!0)}function yl(e,t,n){var r=Array.isArray(e)?Tc(e):e.size();if(t<0||t>=r.length)throw new wc(t,r.length);return ei(e)?e.create(bl(e.valueOf(),t,n),e.datatype()):bl(e,t,n)}function bl(e,t,n){var r,i,a,o;if(t<=0)if(Array.isArray(e[0])){for(o=hl(e),i=[],r=0;r<o.length;r++)i[r]=bl(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]=bl(e[r],t-1,n);return i}}function xl(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 Sl=`isInteger`,Cl=Y(Sl,[`typed`,`equal`],e=>{var{typed:t,equal:n}=e;return t(Sl,{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=>vl(t,e))})}),wl=`number`,Tl=`number, number`;function El(e){return Math.abs(e)}El.signature=wl;function Dl(e,t){return e+t}Dl.signature=Tl;function Ol(e,t){return e-t}Ol.signature=Tl;function kl(e,t){return e*t}kl.signature=Tl;function Al(e,t){return e/t}Al.signature=Tl;function jl(e){return-e}jl.signature=wl;function Ml(e){return e}Ml.signature=wl;function Nl(e){return la(e)}Nl.signature=wl;function Pl(e){return e*e*e}Pl.signature=wl;function Fl(e){return Math.exp(e)}Fl.signature=wl;function Il(e){return ua(e)}Il.signature=wl;function Ll(e,t){if(!ra(e)||!ra(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}Ll.signature=Tl;function Rl(e,t){if(!ra(e)||!ra(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)}Rl.signature=Tl;function zl(e,t){return t?Math.log(e)/Math.log(t):Math.log(e)}function Bl(e){return sa(e)}Bl.signature=wl;function Vl(e){return oa(e)}Vl.signature=wl;function Hl(e){return ca(e)}Hl.signature=wl;function Ul(e,t){return t===0?e:e-t*Math.floor(e/t)}Ul.signature=Tl;function Wl(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 Gl(e){return aa(e)}Gl.signature=wl;function Kl(e){return Math.sqrt(e)}Kl.signature=wl;function ql(e){return e*e}ql.signature=wl;function Jl(e,t){var n,r,i,a=0,o=1,s=1,c=0;if(!ra(e)||!ra(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]}Jl.signature=Tl;function Yl(e,t){return e*e<1&&t===1/0||e*e>1&&t===-1/0?0:e**+t}Yl.signature=Tl;function Xl(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0;if(!ra(t)||t<0||t>15)throw Error(`Number of decimals in function round must be an integer from 0 to 15 inclusive`);return parseFloat(ga(e,t))}function Zl(e){return Math.abs(e)}Zl.signature=wl;var Ql=`number`,$l=`number, number`;function eu(e,t){if(!ra(e)||!ra(t))throw Error(`Integers expected in function bitAnd`);return e&t}eu.signature=$l;function tu(e){if(!ra(e))throw Error(`Integer expected in function bitNot`);return~e}tu.signature=Ql;function nu(e,t){if(!ra(e)||!ra(t))throw Error(`Integers expected in function bitOr`);return e|t}nu.signature=$l;function ru(e,t){if(!ra(e)||!ra(t))throw Error(`Integers expected in function bitXor`);return e^t}ru.signature=$l;function iu(e,t){if(!ra(e)||!ra(t))throw Error(`Integers expected in function leftShift`);return e<<t}iu.signature=$l;function au(e,t){if(!ra(e)||!ra(t))throw Error(`Integers expected in function rightArithShift`);return e>>t}au.signature=$l;function ou(e,t){if(!ra(e)||!ra(t))throw Error(`Integers expected in function rightLogShift`);return e>>>t}ou.signature=$l;function su(e,t){if(t<e)return 1;if(t===e)return t;var n=t+e>>1;return su(e,n)*su(n+1,t)}function cu(e,t){if(!ra(e)||e<0||!ra(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/=su(a,o)),r}cu.signature=`number, number`;var lu=Math.PI,uu=2*Math.PI,du=Math.E,fu=1.618033988749895,pu=`number`,mu=`number, number`;function hu(e){return!e}hu.signature=pu;function gu(e,t){return!!(e||t)}gu.signature=mu;function _u(e,t){return!!e!=!!t}_u.signature=mu;function vu(e,t){return!!(e&&t)}vu.signature=mu;function yu(e){var t;if(ra(e))return e<=0?Number.isFinite(e)?1/0:NaN:e>171?1/0:su(1,e-1);if(e<.5)return Math.PI/(Math.sin(Math.PI*e)*yu(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=xu[0];for(var o=1;o<xu.length;++o)t+=xu[o]/(e+o);var s=e+bu+.5;return Math.sqrt(2*Math.PI)*s**+(e+.5)*Math.exp(-s)*t}yu.signature=`number`;var bu=4.7421875,xu=[.9999999999999971,57.15623566586292,-59.59796035547549,14.136097974741746,-.4919138160976202,3399464998481189e-20,4652362892704858e-20,-9837447530487956e-20,.0001580887032249125,-.00021026444172410488,.00021743961811521265,-.0001643181065367639,8441822398385275e-20,-26190838401581408e-21,36899182659531625e-22],Su=.9189385332046728,Cu=[1.000000000190015,76.18009172947146,-86.50532032941678,24.01409824083091,-1.231739572450155,.001208650973866179,-5395239384953e-18];function wu(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))-wu(1-e);--e;for(var t=e+5+.5,n=Cu[0],r=6;r>=1;r--)n+=Cu[r]/(e+r);return Su+(e+.5)*Math.log(t)-t+Math.log(n)}wu.signature=`number`;var Tu=`number`,Eu=`number, number`;function Du(e){return Math.acos(e)}Du.signature=Tu;function Ou(e){return Ca(e)}Ou.signature=Tu;function ku(e){return Math.atan(1/e)}ku.signature=Tu;function Au(e){return Number.isFinite(e)?(Math.log((e+1)/e)+Math.log(e/(e-1)))/2:0}Au.signature=Tu;function ju(e){return Math.asin(1/e)}ju.signature=Tu;function Mu(e){var t=1/e;return Math.log(t+Math.sqrt(t*t+1))}Mu.signature=Tu;function Nu(e){return Math.acos(1/e)}Nu.signature=Tu;function Pu(e){var t=1/e,n=Math.sqrt(t*t-1);return Math.log(n+t)}Pu.signature=Tu;function Fu(e){return Math.asin(e)}Fu.signature=Tu;function Iu(e){return wa(e)}Iu.signature=Tu;function Lu(e){return Math.atan(e)}Lu.signature=Tu;function Ru(e,t){return Math.atan2(e,t)}Ru.signature=Eu;function zu(e){return Ta(e)}zu.signature=Tu;function Bu(e){return Math.cos(e)}Bu.signature=Tu;function Vu(e){return Ea(e)}Vu.signature=Tu;function Hu(e){return 1/Math.tan(e)}Hu.signature=Tu;function Uu(e){var t=Math.exp(2*e);return(t+1)/(t-1)}Uu.signature=Tu;function Wu(e){return 1/Math.sin(e)}Wu.signature=Tu;function Gu(e){return e===0?1/0:Math.abs(2/(Math.exp(e)-Math.exp(-e)))*aa(e)}Gu.signature=Tu;function Ku(e){return 1/Math.cos(e)}Ku.signature=Tu;function qu(e){return 2/(Math.exp(e)+Math.exp(-e))}qu.signature=Tu;function Ju(e){return Math.sin(e)}Ju.signature=Tu;function Yu(e){return Da(e)}Yu.signature=Tu;function Xu(e){return Math.tan(e)}Xu.signature=Tu;function Zu(e){return Oa(e)}Zu.signature=Tu;var Qu=`number`;function $u(e){return ra(e)}$u.signature=Qu;function ed(e){return e<0}ed.signature=Qu;function td(e){return e>0}td.signature=Qu;function nd(e){return e===0}nd.signature=Qu;function rd(e){return Number.isNaN(e)}rd.signature=Qu;function id(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 ad=`isNegative`,od=Y(ad,[`typed`,`config`],e=>{var{typed:t,config:n}=e;return t(ad,{number:e=>Sa(e,0,n.relTol,n.absTol)?!1:ed(e),BigNumber:e=>id(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=>vl(t,e))})}),sd=`isNumeric`,cd=Y(sd,[`typed`],e=>{var{typed:t}=e;return t(sd,{"number | BigNumber | bigint | Fraction | boolean":()=>!0,"Complex | Unit | string | null | undefined | Node":()=>!1,"Array | Matrix":t.referToSelf(e=>t=>vl(t,e))})}),ld=`hasNumericValue`,ud=Y(ld,[`typed`,`isNumeric`],e=>{var{typed:t,isNumeric:n}=e;return t(ld,{boolean:()=>!0,string:function(e){return e.trim().length>0&&!isNaN(Number(e))},any:function(e){return n(e)}})}),dd=`isPositive`,fd=Y(dd,[`typed`,`config`],e=>{var{typed:t,config:n}=e;return t(dd,{number:e=>Sa(e,0,n.relTol,n.absTol)?!1:td(e),BigNumber:e=>id(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=>vl(t,e))})}),pd=`isZero`,md=Y(pd,[`typed`,`equalScalar`],e=>{var{typed:t,equalScalar:n}=e;return t(pd,{"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=>vl(t,e))})}),hd=`isNaN`,gd=Y(hd,[`typed`],e=>{var{typed:t}=e;return t(hd,{number:rd,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=>vl(t,e))})}),_d=`isBounded`,vd=Y(_d,[`typed`],e=>{var{typed:t}=e;return t(_d,{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))))})}),yd=`isFinite`,bd=Y(yd,[`typed`,`isBounded`,`map`],e=>{var{typed:t,isBounded:n,map:r}=e;return t(yd,{"Array | Matrix":e=>r(e,n),any:e=>n(e)})}),xd=`typeOf`,Sd=Y(xd,[`typed`],e=>{var{typed:t}=e;return t(xd,{any:Ii})});function Cd(e,t,n,r){return Sa(e.re,t.re,n,r)&&Sa(e.im,t.im,n,r)}var wd=Y(`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)})}}),Td=`equalScalar`,Ed=Y(Td,[`typed`,`config`],e=>{var{typed:t,config:n}=e;return t(Td,{"boolean, boolean":function(e,t){return e===t},"number, number":function(e,t){return Sa(e,t,n.relTol,n.absTol)},"BigNumber, BigNumber":function(e,t){return e.eq(t)||id(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 Cd(e,t,n.relTol,n.absTol)}},wd({typed:t}))});Y(Td,[`typed`,`config`],e=>{var{typed:t,config:n}=e;return t(Td,{"number, number":function(e,t){return Sa(e,t,n.relTol,n.absTol)}})});var Dd=Y(`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&&!Qr(t))throw Error(`Invalid datatype: `+t);if(ei(e))a(this,e,t);else if(e&&$r(e.index)&&$r(e.ptr)&&$r(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($r(e))o(this,e,t);else if(e)throw TypeError(`Unsupported type of data (`+Ii(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?Li(t._values):void 0,e._index=Li(t._index),e._ptr=Li(t._ptr),e._size=Li(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(Qr(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($r(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 Yc(this._values,Ii)},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(!ai(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 Cc(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++)kc(c[r],e._size[r]),kc(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(ei(n)?(o=n.size(),n=n.toArray()):o=Tc(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 Cc(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=zc(n,i.length,c,o)}if(!Vi(i,o))throw new Cc(i,o,`>`);if(i.length===1)d(t.dimension(0),(t,i)=>{kc(t),e.set([t,0],n[i[0]],r)});else{var l=t.dimension(0),u=t.dimension(1);d(l,(t,i)=>{kc(t),d(u,(a,o)=>{kc(a),e.set([t,a],n[i[0]][o[0]],r)})})}}return e;function d(e,t){Kr(e)?t(e,[0]):e.forEach(t)}}i.prototype.get=function(e){if(!$r(e))throw TypeError(`Array expected`);if(e.length!==this._size.length)throw new Cc(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];kc(t,this._size[0]),kc(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(!$r(e))throw TypeError(`Array expected`);if(e.length!==this._size.length)throw new Cc(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;Qr(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]),kc(a,s),kc(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(!ti(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(!Kr(e)||!ra(e)||e<0)throw TypeError(`Invalid size, must contain positive integers (size: `+hc(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;Qr(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(!$r(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(!Kr(t)||!ra(t)||t<=-2||t===0)throw TypeError(`Invalid size, must contain positive integers or -1 (size: `+hc(e)+`)`)});var n=this._size[0]*this._size[1];if(e=Pc(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?Li(this._values):void 0,index:Li(this._index),ptr:Li(this._ptr),size:Li(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=ol(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;Qr(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=ol(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?Li(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 [`+hc(t,e)+` x `+hc(n,e)+`] density: `+hc(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
  (`+hc(l,e)+`, `+hc(a,e)+`) ==> `+(this._values?hc(this._values[c],e):`X`)}return i},i.prototype.toString=function(){return hc(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(qr(e)&&(e=e.toNumber()),!Kr(e)||!ra(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(!$r(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(qr(e)&&(e=e.toNumber()),!Kr(e)||!ra(e)||e<1)throw Error(`Size values must be positive integers`);return e}),a){if(qr(a)&&(a=a.toNumber()),!Kr(a)||!ra(a))throw TypeError(`The parameter k must be an integer number`)}else a=0;var c=n,l=0;Qr(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($r(r)){if(r.length!==m)throw Error(`Invalid value array length`);h=function(e){return r[e]}}else if(ei(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(!Kr(e)||!ra(e)||!Kr(t)||!ra(t))throw Error(`Row index must be positive integers`);if(this._size.length!==2)throw Error(`Only two dimensional matrix is supported`);return kc(e,this._size[0]),kc(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}),Od=`number`,kd=[`typed`];function Ad(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 jd(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 Md=Y(Od,kd,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=Ad(e);if(t)return jd(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=>vl(t,e))});return n.fromJSON=function(e){return parseFloat(e.value)},n}),Nd=Y(`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=>vl(t,e))});return n.fromJSON=function(e){return BigInt(e.value)},n}),Pd=`string`,Fd=Y(Pd,[`typed`],e=>{var{typed:t}=e;return t(Pd,{"":function(){return``},number:fa,null:function(e){return`null`},boolean:function(e){return e+``},string:function(e){return e},"Array | Matrix":t.referToSelf(e=>t=>vl(t,e)),any:function(e){return String(e)}})}),Id=`boolean`,Ld=Y(Id,[`typed`],e=>{var{typed:t}=e;return t(Id,{"":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=>vl(t,e))})}),Rd=Y(`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=>vl(t,e))})}),zd=Y(`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=>vl(t,e))})}),Bd=Y(`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=>vl(t,e))})}),Vd=`matrix`,Hd=Y(Vd,[`typed`,`Matrix`,`DenseMatrix`,`SparseMatrix`],e=>{var{typed:t,Matrix:n,DenseMatrix:r,SparseMatrix:i}=e;return t(Vd,{"":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)+`.`)}}),Ud=`matrixFromFunction`,Wd=Y(Ud,[`typed`,`matrix`,`isZero`],e=>{var{typed:t,matrix:n,isZero:r}=e;return t(Ud,{"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}}),Gd=`matrixFromRows`,Kd=Y(Gd,[`typed`,`matrix`,`flatten`,`size`],e=>{var{typed:t,matrix:n,flatten:r,size:i}=e;return t(Gd,{"...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.`)}}),qd=`matrixFromColumns`,Jd=Y(qd,[`typed`,`matrix`,`flatten`,`size`],e=>{var{typed:t,matrix:n,flatten:r,size:i}=e;return t(qd,{"...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.`)}}),Yd=`splitUnit`,Xd=Y(Yd,[`typed`],e=>{var{typed:t}=e;return t(Yd,{"Unit, Array":function(e,t){return e.splitUnit(t)}})}),Zd=`unaryMinus`,Qd=Y(Zd,[`typed`],e=>{var{typed:t}=e;return t(Zd,{number:jl,"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=>vl(t,e,!0))})}),$d=`unaryPlus`,ef=Y($d,[`typed`,`config`,`numeric`],e=>{var{typed:t,config:n,numeric:r}=e;return t($d,{number:Ml,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=>vl(t,e,!0)),boolean:function(e){return r(+!!e,n.number)},string:function(e){return r(e,ia(e,n))}})}),tf=`abs`,nf=Y(tf,[`typed`],e=>{var{typed:t}=e;return t(tf,{number:El,"Complex | BigNumber | Fraction | Unit":e=>e.abs(),bigint:e=>e<0n?-e:e,"Array | Matrix":t.referToSelf(e=>t=>vl(t,e,!0))})}),rf=`mapSlices`,af=Y(rf,[`typed`,`isInteger`],e=>{var{typed:t,isInteger:n}=e;return t(rf,{"Array | Matrix, number | BigNumber, function":function(e,t,r){if(!n(t))throw TypeError(`Integer number expected for dimension`);var i=Array.isArray(e)?Tc(e):e.size();if(t<0||t>=i.length)throw new wc(t,i.length);return ei(e)?e.create(of(e.valueOf(),t,r),e.datatype()):of(e,t,r)}})},{formerly:`apply`});function of(e,t,n){var r,i,a;if(t<=0)if(Array.isArray(e[0])){for(a=sf(e),i=[],r=0;r<a.length;r++)i[r]=of(a[r],t-1,n);return i}else return n(e);else{for(i=[],r=0;r<e.length;r++)i[r]=of(e[r],t-1,n);return i}}function sf(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 cf=`addScalar`,lf=Y(cf,[`typed`],e=>{var{typed:t}=e;return t(cf,{"number, number":Dl,"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})})}),uf=`subtractScalar`,df=Y(uf,[`typed`],e=>{var{typed:t}=e;return t(uf,{"number, number":Ol,"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})})}),ff=`cbrt`,pf=Y(ff,[`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(ff,{number:Nl,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(Nl(i),0).mul(new o(0,r).exp());if(n){var c=[s,new o(Nl(i),0).mul(new o(0,r+Math.PI*2/3).exp()),new o(Nl(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&&Yr(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=qr(e.value)?new s(1).div(3):Xr(e.value)?new c(1,3):1/3,o=e.pow(a);return n&&(o.value=i(o.value)),o}}}),mf=Y(`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})}}),hf=Y(`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})}}),gf=Y(`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:Li(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}}),_f=`ceil`,vf=[`typed`,`config`,`round`,`matrix`,`equalScalar`,`zeros`,`DenseMatrix`],yf=new Es(10),bf=Y(_f,[`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:Sa(e,i,n.relTol,n.absTol)&&!Sa(e,t,n.relTol,n.absTol)?i:t}return t(_f,{number:i,"number, number":function(e,t){if(!ra(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}})}),xf=Y(_f,vf,e=>{var{typed:t,config:n,round:r,matrix:i,equalScalar:a,zeros:o,DenseMatrix:s}=e,c=mf({typed:t,equalScalar:a}),l=hf({typed:t,DenseMatrix:s}),u=gf({typed:t}),d=bf({typed:t,config:n,round:r});function f(e){var t=(e,t)=>id(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=yf.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)=>vl(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=>vl(t,e,!0)),"Array, number | BigNumber":t.referToSelf(e=>(t,n)=>vl(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))})}),Sf=`cube`,Cf=Y(Sf,[`typed`],e=>{var{typed:t}=e;return t(Sf,{number:Pl,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)}})}),wf=`exp`,Tf=Y(wf,[`typed`],e=>{var{typed:t}=e;return t(wf,{number:Fl,Complex:function(e){return e.exp()},BigNumber:function(e){return e.exp()}})}),Ef=`expm1`,Df=Y(Ef,[`typed`,`Complex`],e=>{var{typed:t,Complex:n}=e;return t(Ef,{number:Il,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)}})}),Of=`fix`,kf=[`typed`,`Complex`,`matrix`,`ceil`,`floor`,`equalScalar`,`zeros`,`DenseMatrix`],Af=Y(Of,[`typed`,`ceil`,`floor`],e=>{var{typed:t,ceil:n,floor:r}=e;return t(Of,{number:function(e){return e>0?r(e):n(e)},"number, number":function(e,t){return e>0?r(e,t):n(e,t)}})}),jf=Y(Of,kf,e=>{var{typed:t,Complex:n,matrix:r,ceil:i,floor:a,equalScalar:o,zeros:s,DenseMatrix:c}=e,l=hf({typed:t,DenseMatrix:c}),u=gf({typed:t}),d=Af({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)=>vl(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=>vl(t,e,!0)),"Array | Matrix, number | BigNumber":t.referToSelf(e=>(t,n)=>vl(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))})}),Mf=`floor`,Nf=[`typed`,`config`,`round`,`matrix`,`equalScalar`,`zeros`,`DenseMatrix`],Pf=new Es(10),Ff=Y(Mf,[`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:Sa(e,i,n.relTol,n.absTol)&&!Sa(e,t,n.relTol,n.absTol)?i:t}return t(Mf,{number:i,"number, number":function(e,t){if(!ra(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}})}),If=Y(Mf,Nf,e=>{var{typed:t,config:n,round:r,matrix:i,equalScalar:a,zeros:o,DenseMatrix:s}=e,c=mf({typed:t,equalScalar:a}),l=hf({typed:t,DenseMatrix:s}),u=gf({typed:t}),d=Ff({typed:t,config:n,round:r});function f(e){var t=(e,t)=>id(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=Pf.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)=>vl(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=>vl(t,e,!0)),"Array, number | BigNumber":t.referToSelf(e=>(t,n)=>vl(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))})}),Lf=Y(`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 Cc(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})}}),Rf=Y(`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 Cc(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})}}),zf=Y(`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 Cc(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})}}),Bf=Y(`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 Cc(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 Vf(e,t){if(Vi(e.size(),t.size()))return[e,t];var n=Qc(e.size(),t.size());return[e,t].map(e=>Hf(e,n))}function Hf(e,t){return Vi(e.size(),t)?e:e.create(el(e.valueOf(),t),e.datatype())}var Uf=Y(`matrixAlgorithmSuite`,[`typed`,`matrix`],e=>{var{typed:t,matrix:n}=e,r=Bf({typed:t}),i=gf({typed:t});return function(e){var a=e.elop,o=e.SD||e.DS,s;a?(s={"DenseMatrix, DenseMatrix":(e,t)=>r(...Vf(e,t),a),"Array, Array":(e,t)=>r(...Vf(n(e),n(t)),a).valueOf(),"Array, DenseMatrix":(e,t)=>r(...Vf(n(e),t),a),"DenseMatrix, Array":(e,t)=>r(...Vf(e,n(t)),a)},e.SS&&(s[`SparseMatrix, SparseMatrix`]=(t,n)=>e.SS(...Vf(t,n),a,!1)),e.DS&&(s[`DenseMatrix, SparseMatrix`]=(t,n)=>e.DS(...Vf(t,n),a,!1),s[`Array, SparseMatrix`]=(t,r)=>e.DS(...Vf(n(t),r),a,!1)),o&&(s[`SparseMatrix, DenseMatrix`]=(e,t)=>o(...Vf(t,e),a,!0),s[`SparseMatrix, Array`]=(e,t)=>o(...Vf(n(t),e),a,!0))):(s={"DenseMatrix, DenseMatrix":t.referToSelf(e=>(t,n)=>r(...Vf(t,n),e)),"Array, Array":t.referToSelf(e=>(t,i)=>r(...Vf(n(t),n(i)),e).valueOf()),"Array, DenseMatrix":t.referToSelf(e=>(t,i)=>r(...Vf(n(t),i),e)),"DenseMatrix, Array":t.referToSelf(e=>(t,i)=>r(...Vf(t,n(i)),e))},e.SS&&(s[`SparseMatrix, SparseMatrix`]=t.referToSelf(t=>(n,r)=>e.SS(...Vf(n,r),t,!1))),e.DS&&(s[`DenseMatrix, SparseMatrix`]=t.referToSelf(t=>(n,r)=>e.DS(...Vf(n,r),t,!1)),s[`Array, SparseMatrix`]=t.referToSelf(t=>(r,i)=>e.DS(...Vf(n(r),i),t,!1))),o&&(s[`SparseMatrix, DenseMatrix`]=t.referToSelf(e=>(t,n)=>o(...Vf(n,t),e,!0)),s[`SparseMatrix, Array`]=t.referToSelf(e=>(t,r)=>o(...Vf(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&&zi(s,a.signatures),s}}),Wf=`mod`,Gf=Y(Wf,[`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=If({typed:t,config:n,round:r,matrix:i,equalScalar:a,zeros:o,DenseMatrix:s}),u=Lf({typed:t,equalScalar:a}),d=Rf({typed:t}),f=zf({typed:t,equalScalar:a}),p=mf({typed:t,equalScalar:a}),m=hf({typed:t,DenseMatrix:s}),h=Uf({typed:t,matrix:i,concat:c});return t(Wf,{"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)}}),Kf=Y(`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 Cc(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})}}),qf=Y(`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 Cc(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})}}),Jf=Y(`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 Yf(e,t,n,r){if(!(this instanceof Yf))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}Yf.prototype=Error(),Yf.prototype.constructor=Error,Yf.prototype.name=`ArgumentsError`,Yf.prototype.isArgumentsError=!0;var Xf=`gcd`,Zf=[`typed`,`config`,`round`,`matrix`,`equalScalar`,`zeros`,`BigNumber`,`DenseMatrix`,`concat`],Qf=`number | BigNumber | Fraction | Matrix | Array`,$f=`${Qf}, ${Qf}, ...${Qf}`;function ep(e){return!e.some(e=>Array.isArray(e))}var tp=Y(Xf,Zf,e=>{var{typed:t,matrix:n,config:r,round:i,equalScalar:a,zeros:o,BigNumber:s,DenseMatrix:c,concat:l}=e,u=Gf({typed:t,config:r,round:i,matrix:n,equalScalar:a,zeros:o,DenseMatrix:c,concat:l}),d=Kf({typed:t}),f=qf({typed:t,equalScalar:a}),p=Jf({typed:t,DenseMatrix:c}),m=Uf({typed:t,matrix:n,concat:l});return t(Xf,{"number, number":h,"BigNumber, BigNumber":g,"Fraction, Fraction":(e,t)=>e.gcd(t)},m({SS:f,DS:d,Ss:p}),{[$f]: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])&&ep(t[0]))return e(...t[0]);if(ep(t))return e(...t);throw new Yf(`gcd() supports only 1d matrices!`)}),Matrix:t.referToSelf(e=>t=>e(t.toArray()))});function h(e,t){if(!ra(e)||!ra(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}}),np=Y(`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 Cc(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(xl(e,C,x,b,S,w,v,g),xl(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})}}),rp=`lcm`,ip=Y(rp,[`typed`,`matrix`,`equalScalar`,`concat`],e=>{var{typed:t,matrix:n,equalScalar:r,concat:i}=e,a=Lf({typed:t,equalScalar:r}),o=np({typed:t,equalScalar:r}),s=mf({typed:t,equalScalar:r}),c=Uf({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(rp,{"number, number":Rl,"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 ap(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 op=`log10`,sp=[`typed`,`config`,`Complex`],cp=Bl(16),lp=Y(op,sp,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(op,{number:function(e){return e>=0||n.predictable?Bl(e):a(e)},bigint:ap(cp,Bl,n,a),Complex:i,BigNumber:function(e){return!e.isNegative()||n.predictable?e.log():a(e.toNumber())},"Array | Matrix":t.referToSelf(e=>t=>vl(t,e))})}),up=`log2`,dp=Y(up,[`typed`,`config`,`Complex`],e=>{var{typed:t,config:n,Complex:r}=e;function i(e){return a(new r(e,0))}return t(up,{number:function(e){return e>=0||n.predictable?Vl(e):i(e)},bigint:ap(4,Vl,n,i),Complex:a,BigNumber:function(e){return!e.isNegative()||n.predictable?e.log(2):i(e.toNumber())},"Array | Matrix":t.referToSelf(e=>t=>vl(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)}}),fp=Y(`multiplyScalar`,[`typed`],e=>{var{typed:t}=e;return t(`multiplyScalar`,{"number, number":kl,"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)})}),pp=`multiply`,mp=Y(pp,[`typed`,`matrix`,`addScalar`,`multiplyScalar`,`equalScalar`,`dot`],e=>{var{typed:t,matrix:n,addScalar:r,multiplyScalar:i,equalScalar:a,dot:o}=e,s=mf({typed:t,equalScalar:a}),c=gf({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(pp,i,{"Array, Array":t.referTo(`Matrix, Matrix`,e=>(t,r)=>{l(Tc(t),Tc(r));var i=e(n(t),n(r));return ei(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})})}),hp=`nthRoot`,gp=Y(hp,[`typed`,`matrix`,`equalScalar`,`BigNumber`,`concat`],e=>{var{typed:t,matrix:n,equalScalar:r,BigNumber:i,concat:a}=e,o=Kf({typed:t}),s=Lf({typed:t,equalScalar:r}),c=np({typed:t,equalScalar:r}),l=mf({typed:t,equalScalar:r}),u=Uf({typed:t,matrix:n,concat:a});function d(){throw Error(`Complex number not supported in function nthRoot. Use nthRoots instead.`)}return t(hp,{number:Wl,"number, number":Wl,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))}}),_p=`sign`,vp=Y(_p,[`typed`,`BigNumber`,`Fraction`,`complex`],e=>{var{typed:t,BigNumber:n,complex:r,Fraction:i}=e;return t(_p,{number:Gl,Complex:function(e){return e.im===0?r(Gl(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=>vl(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)})})}),yp=Y(`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()}}),bp=`square`,xp=Y(bp,[`typed`],e=>{var{typed:t}=e;return t(bp,{number:ql,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)}})}),Sp=`subtract`,Cp=Y(Sp,[`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=Kf({typed:t}),l=Rf({typed:t}),u=zf({typed:t,equalScalar:r}),d=Jf({typed:t,DenseMatrix:o}),f=hf({typed:t,DenseMatrix:o}),p=Uf({typed:t,matrix:n,concat:s});return t(Sp,{"any, any":i},p({elop:i,SS:u,DS:c,SD:l,Ss:f,sS:d}))}),wp=`xgcd`,Tp=Y(wp,[`typed`,`config`,`matrix`,`BigNumber`],e=>{var{typed:t,config:n,matrix:r,BigNumber:i}=e;return t(wp,{"number, number":function(e,t){var i=Jl(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)}}),Ep=`invmod`,Dp=Y(Ep,[`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(Ep,{"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}}),Op=Y(`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 Cc(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})}}),kp=`dotMultiply`,Ap=Y(kp,[`typed`,`matrix`,`equalScalar`,`multiplyScalar`,`concat`],e=>{var{typed:t,matrix:n,equalScalar:r,multiplyScalar:i,concat:a}=e,o=Lf({typed:t,equalScalar:r}),s=Op({typed:t,equalScalar:r}),c=mf({typed:t,equalScalar:r});return t(kp,Uf({typed:t,matrix:n,concat:a})({elop:i,SS:s,DS:o,Ss:c}))});function jp(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 Pp(e,t,function(e,t){return e&t})}function Mp(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 Np(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:Pp(e,t,function(e,t){return e|t})}function Pp(e,t,n){var r=e.constructor,i,a,o=+(e.s<0),s=+(t.s<0);if(o){i=Fp(Mp(e));for(var c=0;c<i.length;++c)i[c]^=1}else i=Fp(e);if(s){a=Fp(Mp(t));for(var l=0;l<a.length;++l)a[l]^=1}else a=Fp(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 Fp(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 Ip(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)?Mp(t):t.eq(r)?Mp(e):!e.isFinite()||!t.isFinite()?!e.isFinite()&&!t.isFinite()?r:new n(e.isNegative()===t.isNegative()?1/0:-1/0):Pp(e,t,function(e,t){return e^t})}function Lp(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 Rp(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 zp=`bitAnd`,Bp=Y(zp,[`typed`,`matrix`,`equalScalar`,`concat`],e=>{var{typed:t,matrix:n,equalScalar:r,concat:i}=e,a=Lf({typed:t,equalScalar:r}),o=np({typed:t,equalScalar:r}),s=mf({typed:t,equalScalar:r}),c=Uf({typed:t,matrix:n,concat:i});return t(zp,{"number, number":eu,"BigNumber, BigNumber":jp,"bigint, bigint":(e,t)=>e&t},c({SS:o,DS:a,Ss:s}))}),Vp=`bitNot`,Hp=Y(Vp,[`typed`],e=>{var{typed:t}=e;return t(Vp,{number:tu,BigNumber:Mp,bigint:e=>~e,"Array | Matrix":t.referToSelf(e=>t=>vl(t,e))})}),Up=`bitOr`,Wp=Y(Up,[`typed`,`matrix`,`equalScalar`,`DenseMatrix`,`concat`],e=>{var{typed:t,matrix:n,equalScalar:r,DenseMatrix:i,concat:a}=e,o=Kf({typed:t}),s=qf({typed:t,equalScalar:r}),c=Jf({typed:t,DenseMatrix:i}),l=Uf({typed:t,matrix:n,concat:a});return t(Up,{"number, number":nu,"BigNumber, BigNumber":Np,"bigint, bigint":(e,t)=>e|t},l({SS:s,DS:o,Ss:c}))}),Gp=Y(`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 Cc(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]}}}),Kp=`bitXor`,qp=Y(Kp,[`typed`,`matrix`,`DenseMatrix`,`concat`,`SparseMatrix`],e=>{var{typed:t,matrix:n,DenseMatrix:r,concat:i,SparseMatrix:a}=e,o=Rf({typed:t}),s=Gp({typed:t,SparseMatrix:a}),c=hf({typed:t,DenseMatrix:r}),l=Uf({typed:t,matrix:n,concat:i});return t(Kp,{"number, number":ru,"BigNumber, BigNumber":Ip,"bigint, bigint":(e,t)=>e^t},l({SS:s,DS:o,Ss:c}))}),Jp=`arg`,Yp=Y(Jp,[`typed`],e=>{var{typed:t}=e;return t(Jp,{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=>vl(t,e))})}),Xp=`conj`,Zp=Y(Xp,[`typed`],e=>{var{typed:t}=e;return t(Xp,{"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=>vl(t,e))})}),Qp=`im`,$p=Y(Qp,[`typed`],e=>{var{typed:t}=e;return t(Qp,{number:()=>0,"BigNumber | Fraction":e=>e.mul(0),Complex:e=>e.im,"Array | Matrix":t.referToSelf(e=>t=>vl(t,e))})}),em=`re`,tm=Y(em,[`typed`],e=>{var{typed:t}=e;return t(em,{"number | BigNumber | Fraction":e=>e,Complex:e=>e.re,"Array | Matrix":t.referToSelf(e=>t=>vl(t,e))})}),nm=`not`,rm=Y(nm,[`typed`],e=>{var{typed:t}=e;return t(nm,{"null | undefined":()=>!0,number:hu,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=>vl(t,e))})}),im=`nullish`,am=Y(im,[`typed`,`matrix`,`size`,`flatten`,`deepEqual`],e=>{var{typed:t,matrix:n,size:r,flatten:i,deepEqual:a}=e,o=Rf({typed:t}),s=gf({typed:t}),c=Bf({typed:t});return t(im,{"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 Cc(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())})}),om=`or`,sm=Y(om,[`typed`,`matrix`,`equalScalar`,`DenseMatrix`,`concat`],e=>{var{typed:t,matrix:n,equalScalar:r,DenseMatrix:i,concat:a}=e,o=Rf({typed:t}),s=zf({typed:t,equalScalar:r}),c=hf({typed:t,DenseMatrix:i}),l=Uf({typed:t,matrix:n,concat:a});return t(om,{"number, number":gu,"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":gu,"Unit, Unit":t.referToSelf(e=>(t,n)=>e(t.value||0,n.value||0))},l({SS:s,DS:o,Ss:c}))}),cm=`xor`,lm=Y(cm,[`typed`,`matrix`,`DenseMatrix`,`concat`,`SparseMatrix`],e=>{var{typed:t,matrix:n,DenseMatrix:r,concat:i,SparseMatrix:a}=e,o=Rf({typed:t}),s=Gp({typed:t,SparseMatrix:a}),c=hf({typed:t,DenseMatrix:r}),l=Uf({typed:t,matrix:n,concat:i});return t(cm,{"number, number":_u,"Complex, Complex":function(e,t){return(e.re!==0||e.im!==0)!=(t.re!==0||t.im!==0)},"bigint, bigint":_u,"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}))}),um=`concat`,dm=Y(um,[`typed`,`matrix`,`isInteger`],e=>{var{typed:t,matrix:n,isInteger:r}=e;return t(um,{"...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(ei(l)&&(s=!0),Kr(l)||qr(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 wc(a,o+1)}else{var u=Li(l).valueOf(),d=Tc(u);if(c[t]=u,o=a,a=d.length-1,t>0&&a!==o)throw new Cc(o+1,a+1)}}if(c.length===0)throw SyntaxError(`At least one matrix expected`);for(var f=c.shift();c.length;)f=Zc(f,c.shift(),a);return s?n(f):f},"...string":function(e){return e.join(``)}})}),fm=`column`,pm=Y(fm,[`typed`,`Index`,`matrix`,`range`],e=>{var{typed:t,Index:n,matrix:r,range:i}=e;return t(fm,{"Matrix, number":a,"Array, number":function(e,t){return a(r(Li(e)),t).valueOf()}});function a(e,t){if(e.size().length!==2)throw Error(`Only two dimensional matrix is supported`);kc(t,e.size()[1]);var a=new n(i(0,e.size()[0]),[t]),o=e.subset(a);return ei(o)?o:r([[o]])}}),mm=`count`,hm=Y(mm,[`typed`,`size`,`prod`],e=>{var{typed:t,size:n,prod:r}=e;return t(mm,{string:function(e){return e.length},"Matrix | Array":function(e){return r(n(e))}})}),gm=`cross`,_m=Y(gm,[`typed`,`matrix`,`subtract`,`multiply`],e=>{var{typed:t,matrix:n,subtract:r,multiply:i}=e;return t(gm,{"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(Tc(e).length,Tc(t).length);e=Lc(e),t=Lc(t);var a=Tc(e),o=Tc(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}}),vm=`diag`,ym=Y(vm,[`typed`,`matrix`,`DenseMatrix`,`SparseMatrix`],e=>{var{typed:t,matrix:n,DenseMatrix:r,SparseMatrix:i}=e;return t(vm,{Array:function(e){return a(e,0,Tc(e),null)},"Array, number":function(e,t){return a(e,t,Tc(e),null)},"Array, BigNumber":function(e,t){return a(e,t.toNumber(),Tc(e),null)},"Array, string":function(e,t){return a(e,0,Tc(e),t)},"Array, number, string":function(e,t,n){return a(e,t,Tc(e),n)},"Array, BigNumber, string":function(e,t,n){return a(e,t.toNumber(),Tc(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(!ra(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(ei(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)}}),bm=Y(`filter`,[`typed`],e=>{var{typed:t}=e;return t(`filter`,{"Array, function":xm,"Matrix, function":function(e,t){return e.create(xm(e.valueOf(),t),e.datatype())},"Array, RegExp":Gc,"Matrix, RegExp":function(e,t){return e.create(Gc(e.valueOf(),t),e.datatype())}})});function xm(e,t){var n=ol(t,e,`filter`);return n.isUnary?Wc(e,n.fn):Wc(e,function(e,t,r){return n.fn(e,[t],r)})}var Sm=`flatten`,Cm=Y(Sm,[`typed`],e=>{var{typed:t}=e;return t(Sm,{Array:function(e){return Vc(e)},DenseMatrix:function(e){return e.create(Vc(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())`)}})}),wm=`forEach`,Tm=Y(wm,[`typed`],e=>{var{typed:t}=e;return t(wm,{"Array, function":Em,"Matrix, function":function(e,t){e.forEach(t)}})});function Em(e,t){var n=ol(t,e,wm);il(e,n.fn,n.isUnary)}var Dm=`getMatrixDataType`,Om=Y(Dm,[`typed`],e=>{var{typed:t}=e;return t(Dm,{Array:function(e){return Yc(e,Ii)},Matrix:function(e){return e.getDataType()}})}),km=`identity`,Am=Y(km,[`typed`,`config`,`matrix`,`BigNumber`,`DenseMatrix`,`SparseMatrix`],e=>{var{typed:t,config:n,matrix:r,BigNumber:i,DenseMatrix:a,SparseMatrix:o}=e;return t(km,{"":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=qr(e)||qr(t)?i:null;if(qr(e)&&(e=e.toNumber()),qr(t)&&(t=t.toNumber()),!ra(e)||e<1||!ra(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=jc([],l,c),d=e<t?e:t,f=0;f<d;f++)u[f][f]=s;return u}}),jm=`kron`,Mm=Y(jm,[`typed`,`matrix`,`multiplyScalar`],e=>{var{typed:t,matrix:n,multiplyScalar:r}=e;return t(jm,{"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=Tc(e).length,o=Tc(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)))}}),Nm=`map`,Pm=Y(Nm,[`typed`],e=>{var{typed:t}=e;return t(Nm,{"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():Tc(e)),u=Qc(...l),d=e.length,f=c?(e,t)=>e.get(t):nl,p=e.map((e,t)=>{var n=l[t].map(()=>0);return e.isMatrix?e.get(n):nl(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(el(t.toArray(),u),t.datatype()):e[0].create(el(t.valueOf(),u))):e.map(e=>e.isMatrix?el(e.toArray(),u):el(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():Tc(e)),a=Qc(...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=ol(t,e,Nm);return rl(e,n.fn,n.isUnary)}}),Fm=`diff`,Im=Y(Fm,[`typed`,`matrix`,`subtract`,`number`],e=>{var{typed:t,matrix:n,subtract:r,number:i}=e;return t(Fm,{"Array | Matrix":function(e){return ei(e)?n(o(e.toArray())):o(e)},"Array | Matrix, number":function(e,t){if(!ra(t))throw RangeError(`Dimension must be a whole number`);return ei(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(ei(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){ei(e)&&(e=e.toArray()),ei(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}}),Lm=Y(`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?jc(c,e,n):c}}function o(e){var t=!1;return e.forEach(function(e,n,r){qr(e)&&(t=!0,r[n]=e.toNumber())}),t}function s(e){e.forEach(function(e){if(typeof e!=`number`||!ra(e)||e<0)throw Error(`Parameters in function ones must be positive integers`)})}});function Rm(){throw Error(`No "bignumber" implementation available`)}function zm(){throw Error(`No "fraction" implementation available`)}function Bm(){throw Error(`No "matrix" implementation available`)}var Vm=`range`,Hm=Y(Vm,[`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(Vm,{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):Bm():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&&Rm(),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}}}),Um=`reshape`,Wm=Y(Um,[`typed`,`isInteger`,`matrix`],e=>{var{typed:t,isInteger:n}=e;return t(Um,{"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)}),Nc(e,t)}})}),Gm=Y(`resize`,[`config`,`matrix`],e=>{var{config:t,matrix:n}=e;return function(e,i,a){if(arguments.length!==2&&arguments.length!==3)throw new Yf(`resize`,arguments.length,2,3);if(ei(i)&&(i=i.valueOf()),qr(i[0])&&(i=i.map(function(e){return qr(e)?e.toNumber():e})),ei(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 Li(e)}else{Array.isArray(e)||(e=[e]),e=Li(e);var s=jc(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 Cc(t.length,1);var r=t[0];if(typeof r!=`number`||!ra(r))throw TypeError(`Invalid size, must contain positive integers (size: `+hc(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}}),Km=`rotate`,qm=Y(Km,[`typed`,`multiply`,`rotationMatrix`],e=>{var{typed:t,multiply:n,rotationMatrix:r}=e;return t(Km,{"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)?Tc(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}`)}}),Jm=`rotationMatrix`,Ym=Y(Jm,[`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(Jm,{"":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=qr(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=qr(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)}}),Xm=`row`,Zm=Y(Xm,[`typed`,`Index`,`matrix`,`range`],e=>{var{typed:t,Index:n,matrix:r,range:i}=e;return t(Xm,{"Matrix, number":a,"Array, number":function(e,t){return a(r(Li(e)),t).valueOf()}});function a(e,t){if(e.size().length!==2)throw Error(`Only two dimensional matrix is supported`);kc(t,e.size()[0]);var a=i(0,e.size()[1]),o=new n([t],a),s=e.subset(o);return ei(s)?s:r([[s]])}}),Qm=`size`,$m=Y(Qm,[`typed`],e=>{var{typed:t}=e;return t(Qm,{Matrix:e=>e.size(),Array:Tc,string:e=>[e.length],"number | Complex | BigNumber | Unit | boolean | null":e=>[]})}),eh=`squeeze`,th=Y(eh,[`typed`],e=>{var{typed:t}=e;return t(eh,{Array:function(e){return Lc(Li(e))},Matrix:function(e){var t=Lc(e.toArray());return Array.isArray(t)?e.create(t,e.datatype()):t},any:function(e){return Li(e)}})}),nh=`subset`,rh=Y(nh,[`typed`,`matrix`,`zeros`,`add`],e=>{var{typed:t,matrix:n,zeros:r,add:i}=e;return t(nh,{"Matrix, Index":function(e,t){return Ac(t)?n():(Oc(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":oh,"string, Index":ih,"Matrix, Index, any, any":function(e,t,n,r){return Ac(t)?e:(Oc(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":ah,"string, Index, string, string":ah,"Object, Index, any":sh});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 ih(e,t){if(!ai(t))throw TypeError(`Index expected`);if(Ac(t))return``;if(Oc(Array.from(e),t),t.size().length!==1)throw new Cc(t.size().length,1);var n=e.length;kc(t.min()[0],n),kc(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 ah(e,t,n,r){if(!t||t.isIndex!==!0)throw TypeError(`Index expected`);if(Ac(t))return e;if(Oc(Array.from(e),t),t.size().length!==1)throw new Cc(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 Cc(i.size()[0],n.length);var a=e.length;kc(t.min()[0]),kc(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 oh(e,t){if(!Ac(t)){if(t.size().length!==1)throw new Cc(t.size(),1);var n=t.dimension(0);if(typeof n!=`string`)throw TypeError(`String expected as index to retrieve an object property`);return jr(e,n)}}function sh(e,t,n){if(Ac(t))return e;if(t.size().length!==1)throw new Cc(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=Li(e);return Mr(i,r,n),i}var ch=`transpose`,lh=Y(ch,[`typed`,`matrix`],e=>{var{typed:t,matrix:n}=e;return t(ch,{Array:e=>r(n(e)).valueOf(),Matrix:r,any:Li});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: `+hc(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: `+hc(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]=Li(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]=Li(r[v]))}return e.createSparseMatrix({values:o,index:s,ptr:c,size:[n,t],datatype:e._datatype})}}),uh=`ctranspose`,dh=Y(uh,[`typed`,`transpose`,`conj`],e=>{var{typed:t,transpose:n,conj:r}=e;return t(uh,{any:function(e){return r(n(e))}})}),fh=`zeros`,ph=Y(fh,[`typed`,`config`,`matrix`,`BigNumber`],e=>{var{typed:t,config:n,matrix:r,BigNumber:i}=e;return t(fh,{"":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?jc(c,e,n):c}}function o(e){var t=!1;return e.forEach(function(e,n,r){qr(e)&&(t=!0,r[n]=e.toNumber())}),t}function s(e){e.forEach(function(e){if(typeof e!=`number`||!ra(e)||e<0)throw Error(`Parameters in function zeros must be positive integers`)})}}),mh=`fft`,hh=Y(mh,[`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(mh,{Array:m,Matrix:function(e){return e.create(m(e.valueOf()),e.datatype())}});function m(e){var t=Tc(e);return t.length===1?_(e,t[0]):h(e.map(e=>m(e,t.slice(1))),0)}function h(e,t){var n=Tc(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=Tc(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)}}),gh=`ifft`,_h=Y(gh,[`typed`,`fft`,`dotDivide`,`conj`],e=>{var{typed:t,fft:n,dotDivide:r,conj:i}=e;return t(gh,{"Array | Matrix":function(e){var t=ei(e)?e.size():Tc(e);return r(i(n(i(e))),t.reduce((e,t)=>e*t,1))}})});function vh(e){"@babel/helpers - typeof";return vh=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},vh(e)}function yh(e,t){if(vh(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(vh(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function bh(e){var t=yh(e,`string`);return vh(t)==`symbol`?t:t+``}function xh(e,t,n){return(t=bh(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Sh(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 Ch(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?Sh(Object(n),!0).forEach(function(t){xh(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Sh(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}var wh=Y(`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(Zr))))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(Zr)))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(qr),[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 U=1;U<F.length;++U)re.push(t(n(z[ee],i(F[U],R)),n(B[ee],i(R,P[U],re))));var W=o(c(s(i(V,re),e=>Zr(e)?e.value:e)));W<k&&k/W>1/4&&(z.push(n(z[ee],R)),B.push(n(B[ee],i(R,I,re))),ee++);var ie=.84*(k/W)**(1/5);if(f(ie,A)?ie=A:d(ie,j)&&(ie=j),ie=N?m(ie):ie,R=i(R,ie),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=Ch({},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 qr(e)||Kr(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]))}}})}),Th=Y(`erf`,[`typed`],e=>{var{typed:t}=e;return t(`name`,{number:function(e){var t=Math.abs(e);return t>=Ah?aa(e):t<=Eh?aa(e)*n(t):t<=4?aa(e)*(1-r(t)):aa(e)*(1-i(t))},"Array | Matrix":t.referToSelf(e=>t=>vl(t,e))});function n(e){var t=e*e,n=Oh[0][4]*t,r=t,i;for(i=0;i<3;i+=1)n=(n+Oh[0][i])*t,r=(r+kh[0][i])*t;return e*(n+Oh[0][3])/(r+kh[0][3])}function r(e){var t=Oh[1][8]*e,n=e,r;for(r=0;r<7;r+=1)t=(t+Oh[1][r])*e,n=(n+kh[1][r])*e;var i=(t+Oh[1][7])/(n+kh[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=Oh[2][5]*t,r=t,i;for(i=0;i<4;i+=1)n=(n+Oh[2][i])*t,r=(r+kh[2][i])*t;var a=t*(n+Oh[2][4])/(r+kh[2][4]);a=(Dh-a)/e,t=parseInt(e*16)/16;var o=(e-t)*(e+t);return Math.exp(-t*t)*Math.exp(-o)*a}}),Eh=.46875,Dh=.5641895835477563,Oh=[[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]],kh=[[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]],Ah=2**53,jh=`zeta`,Mh=Y(jh,[`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(jh,{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)}}),Nh=`mode`,Ph=Y(Nh,[`typed`,`isNaN`,`isNumeric`],e=>{var{typed:t,isNaN:n,isNumeric:r}=e;return t(Nh,{"Array | Matrix":i,"...":function(e){return i(e)}});function i(e){if(e=Vc(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 Fh(e,t,n){var r;return String(e).includes(`Unexpected type`)?(r=arguments.length>2?` (type: `+Ii(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: `+Ii(n)+`, value: `+JSON.stringify(n)+`)`:``,TypeError(`Cannot calculate `+t+`, no ordering relation is defined for complex numbers`+r)):e}var Ih=`prod`,Lh=Y(Ih,[`typed`,`config`,`multiplyScalar`,`numeric`],e=>{var{typed:t,config:n,multiplyScalar:r,numeric:i}=e;return t(Ih,{"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(_l(e,function(e){try{t=t===void 0?e:r(t,e)}catch(t){throw Fh(t,`prod`,e)}}),typeof t==`string`&&(t=i(t,ia(t,n))),t===void 0)throw Error(`Cannot calculate prod of an empty array`);return t}}),Rh=`format`,zh=Y(Rh,[`typed`],e=>{var{typed:t}=e;return t(Rh,{any:hc,"any, Object | function | number | BigNumber":hc})}),Bh=`bin`,Vh=Y(Bh,[`typed`,`format`],e=>{var{typed:t,format:n}=e;return t(Bh,{"number | BigNumber":function(e){return n(e,{notation:`bin`})},"number | BigNumber, number | BigNumber":function(e,t){return n(e,{notation:`bin`,wordSize:t})}})}),Hh=`oct`,Uh=Y(Hh,[`typed`,`format`],e=>{var{typed:t,format:n}=e;return t(Hh,{"number | BigNumber":function(e){return n(e,{notation:`oct`})},"number | BigNumber, number | BigNumber":function(e,t){return n(e,{notation:`oct`,wordSize:t})}})}),Wh=`hex`,Gh=Y(Wh,[`typed`,`format`],e=>{var{typed:t,format:n}=e;return t(Wh,{"number | BigNumber":function(e){return n(e,{notation:`hex`})},"number | BigNumber, number | BigNumber":function(e,t){return n(e,{notation:`hex`,wordSize:t})}})}),Kh=/\$([\w.]+)/g,qh=`print`,Jh=Y(qh,[`typed`],e=>{var{typed:t}=e;return t(qh,{"string, Object | Array":Yh,"string, Object | Array, number | Object":Yh})});function Yh(e,t,n){return e.replace(Kh,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:Qr(a)?a:hc(a,n)})}var Xh=`to`,Zh=Y(Xh,[`typed`,`matrix`,`concat`],e=>{var{typed:t,matrix:n,concat:r}=e;return t(Xh,{"Unit, Unit | string":(e,t)=>e.to(t)},Uf({typed:t,matrix:n,concat:r})({Ds:!0}))}),Qh=`toBest`,$h=Y(Qh,[`typed`],e=>{var{typed:t}=e;return t(Qh,{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)})}),eg=`isPrime`,tg=Y(eg,[`typed`],e=>{var{typed:t}=e;return t(eg,{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=>vl(t,e))})}),ng=Y(`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):Rm,bigint:e=>BigInt(e),Fraction:r?e=>r(e):zm};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=Ii(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)}}),rg=`divideScalar`,ig=Y(rg,[`typed`,`numeric`],e=>{var{typed:t,numeric:n}=e;return t(rg,{"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)})}),ag=`pow`,og=Y(ag,[`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(ag,{"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&&!ra(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:ra(t)||e>=0||n.predictable?Yl(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(!ra(t))throw TypeError(`For A^b, b must be an integer (value is `+t+`)`);var n=Tc(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))}}),sg=`Number of decimals in function round must be an integer`,cg=`round`,lg=Y(cg,[`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=mf({typed:t,equalScalar:i}),l=hf({typed:t,DenseMatrix:s}),u=gf({typed:t});function d(e){return Math.abs(ma(e).exponent)}return t(cg,{number:function(e){var t=Xl(e,d(n.relTol));return Xl(Sa(e,t,n.relTol,n.absTol)?t:e)},"number, number":function(e,t){var r=d(n.relTol);if(t>=r)return Xl(e,t);var i=Xl(e,r);return Xl(Sa(e,i,n.relTol,n.absTol)?i:e,t)},"number, BigNumber":function(e,t){if(!t.isInteger())throw TypeError(sg);return new o(e).toDecimalPlaces(t.toNumber())},Complex:function(e){return e.round()},"Complex, number":function(e,t){if(t%1)throw TypeError(sg);return e.round(t)},"Complex, BigNumber":function(e,t){if(!t.isInteger())throw TypeError(sg);var n=t.toNumber();return e.round(n)},BigNumber:function(e){var t=new o(e).toDecimalPlaces(d(n.relTol));return(id(e,t,n.relTol,n.absTol)?t:e).toDecimalPlaces(0)},"BigNumber, BigNumber":function(e,t){if(!t.isInteger())throw TypeError(sg);var r=d(n.relTol);if(t>=r)return e.toDecimalPlaces(t.toNumber());var i=e.toDecimalPlaces(r);return(id(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(sg);return e.round(t)},"Fraction, BigNumber":function(e,t){if(!t.isInteger())throw TypeError(sg);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)=>vl(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=>vl(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())})}),ug=`log`,dg=[`config`,`typed`,`typeOf`,`divideScalar`,`Complex`],fg=Math.log(16),pg=Y(ug,dg,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(ug,{number:function(e){return e>=0||r.predictable?zl(e):s(e)},bigint:ap(fg,zl,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))})})}),mg=`log1p`,hg=Y(mg,[`typed`,`config`,`divideScalar`,`log`,`Complex`],e=>{var{typed:t,config:n,divideScalar:r,log:i,Complex:a}=e;return t(mg,{number:function(e){return e>=-1||n.predictable?ca(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=>vl(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))}}),gg=`nthRoots`,_g=Y(gg,[`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(gg,{Complex:function(e){return o(e,2)},"Complex, number":o})}),vg=`dotPow`,yg=Y(vg,[`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=Rf({typed:t}),l=Gp({typed:t,SparseMatrix:s}),u=mf({typed:t,equalScalar:n}),d=hf({typed:t,DenseMatrix:a}),f=Uf({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(vg,f({elop:t(p),SS:l,DS:c,Ss:u,sS:d}))}),bg=`dotDivide`,xg=Y(bg,[`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=Lf({typed:t,equalScalar:r}),l=Rf({typed:t}),u=Gp({typed:t,SparseMatrix:s}),d=mf({typed:t,equalScalar:r}),f=hf({typed:t,DenseMatrix:a});return t(bg,Uf({typed:t,matrix:n,concat:o})({elop:i,SS:u,DS:l,SD:c,Ss:d,sS:f}))});function Sg(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: `+hc(i)+`)`);var a=i[0];if(a!==i[1])throw RangeError(`Matrix must be square (size: `+hc(i)+`)`);var o=[];if(ei(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(ni(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(ri(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($r(n)){var v=Tc(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 Cg=`lsolve`,wg=Y(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=Sg({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).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]})}}),Tg=`usolve`,Eg=Y(Tg,[`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=Sg({DenseMatrix:s});return t(Tg,{"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]})}}),Dg=`lsolveAll`,Og=Y(Dg,[`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=Sg({DenseMatrix:s});return t(Dg,{"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]}))}}),kg=`usolveAll`,Ag=Y(kg,[`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=Sg({DenseMatrix:s});return t(kg,{"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]}))}}),jg=Y(`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 Cc(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})}}),Mg=Y(`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())}}),Ng=`leftShift`,Pg=Y(Ng,[`typed`,`matrix`,`equalScalar`,`zeros`,`DenseMatrix`,`concat`],e=>{var{typed:t,matrix:n,equalScalar:r,zeros:i,DenseMatrix:a,concat:o}=e,s=Kf({typed:t}),c=Lf({typed:t,equalScalar:r}),l=jg({typed:t,equalScalar:r}),u=Jf({typed:t,DenseMatrix:a}),d=mf({typed:t,equalScalar:r}),f=gf({typed:t}),p=Uf({typed:t,matrix:n,concat:o}),m=Mg({typed:t,matrix:n});return t(Ng,{"number, number":iu,"BigNumber, BigNumber":Lp,"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}))}),Fg=`rightArithShift`,Ig=Y(Fg,[`typed`,`matrix`,`equalScalar`,`zeros`,`DenseMatrix`,`concat`],e=>{var{typed:t,matrix:n,equalScalar:r,zeros:i,DenseMatrix:a,concat:o}=e,s=Kf({typed:t}),c=Lf({typed:t,equalScalar:r}),l=jg({typed:t,equalScalar:r}),u=Jf({typed:t,DenseMatrix:a}),d=mf({typed:t,equalScalar:r}),f=gf({typed:t}),p=Uf({typed:t,matrix:n,concat:o}),m=Mg({typed:t,matrix:n});return t(Fg,{"number, number":au,"BigNumber, BigNumber":Rp,"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}))}),Lg=`rightLogShift`,Rg=Y(Lg,[`typed`,`matrix`,`equalScalar`,`zeros`,`DenseMatrix`,`concat`],e=>{var{typed:t,matrix:n,equalScalar:r,zeros:i,DenseMatrix:a,concat:o}=e,s=Kf({typed:t}),c=Lf({typed:t,equalScalar:r}),l=jg({typed:t,equalScalar:r}),u=Jf({typed:t,DenseMatrix:a}),d=mf({typed:t,equalScalar:r}),f=gf({typed:t}),p=Uf({typed:t,matrix:n,concat:o}),m=Mg({typed:t,matrix:n});return t(Lg,{"number, number":ou,"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}))}),zg=`and`,Bg=Y(zg,[`typed`,`matrix`,`equalScalar`,`zeros`,`not`,`concat`],e=>{var{typed:t,matrix:n,equalScalar:r,zeros:i,not:a,concat:o}=e,s=Lf({typed:t,equalScalar:r}),c=np({typed:t,equalScalar:r}),l=mf({typed:t,equalScalar:r}),u=gf({typed:t}),d=Uf({typed:t,matrix:n,concat:o});return t(zg,{"number, number":vu,"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":vu,"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}))}),Vg=`compare`,Hg=Y(Vg,[`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=Rf({typed:t}),u=zf({typed:t,equalScalar:r}),d=hf({typed:t,DenseMatrix:s}),f=Uf({typed:t,matrix:i,concat:c}),p=wd({typed:t});return t(Vg,Ug({typed:t,config:n}),{"boolean, boolean":function(e,t){return e===t?0:e>t?1:-1},"BigNumber, BigNumber":function(e,t){return id(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}))}),Ug=Y(Vg,[`typed`,`config`],e=>{var{typed:t,config:n}=e;return t(Vg,{"number, number":function(e,t){return Sa(e,t,n.relTol,n.absTol)?0:e>t?1:-1}})}),Wg=Ae(mt(((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),Gg=`compareNatural`,Kg=Y(Gg,[`typed`,`compare`],e=>{var{typed:t,compare:n}=e,r=n.signatures[`boolean,boolean`];return t(Gg,{"any, any":i});function i(e,t){var c=Ii(e),l=Ii(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,Wg.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,Wg.default)(c,l):u;if(c!==l)return(0,Wg.default)(c,l);if(c===`Complex`)return qg(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,Wg.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 ri(t)&&ri(n)?o(e,t.toJSON().values,n.toJSON().values):ri(t)?a(e,t.toArray(),n):ri(n)?a(e,t,n.toArray()):ni(t)?a(e,t.toJSON().data,n):ni(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(Wg.default),i.sort(Wg.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 qg(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 Jg=`compareText`,Yg=[`typed`,`matrix`,`concat`];Sc.signature=`any, any`;var Xg=Y(Jg,Yg,e=>{var{typed:t,matrix:n,concat:r}=e;return t(Jg,Sc,Uf({typed:t,matrix:n,concat:r})({elop:Sc,Ds:!0}))}),Zg=`equal`,Qg=Y(Zg,[`typed`,`matrix`,`equalScalar`,`DenseMatrix`,`SparseMatrix`],e=>{var{typed:t,matrix:n,equalScalar:r,DenseMatrix:i,concat:a,SparseMatrix:o}=e,s=Rf({typed:t}),c=Gp({typed:t,SparseMatrix:o}),l=hf({typed:t,DenseMatrix:i}),u=Uf({typed:t,matrix:n});return t(Zg,$g({typed:t,equalScalar:r}),u({elop:r,SS:c,DS:s,Ss:l}))}),$g=Y(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_=`equalText`,t_=Y(e_,[`typed`,`compareText`,`isZero`],e=>{var{typed:t,compareText:n,isZero:r}=e;return t(e_,{"any, any":function(e,t){return r(n(e,t))}})}),n_=`smaller`,r_=Y(n_,[`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=Rf({typed:t}),l=Gp({typed:t,SparseMatrix:s}),u=hf({typed:t,DenseMatrix:a}),d=Uf({typed:t,matrix:i,concat:o}),f=wd({typed:t});function p(e,t){return e.lt(t)&&!id(e,t,n.relTol,n.absTol)}return t(n_,i_({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}))}),i_=Y(n_,[`typed`,`config`],e=>{var{typed:t,config:n}=e;return t(n_,{"number, number":function(e,t){return e<t&&!Sa(e,t,n.relTol,n.absTol)}})}),a_=`smallerEq`,o_=Y(a_,[`typed`,`config`,`matrix`,`DenseMatrix`,`concat`,`SparseMatrix`],e=>{var{typed:t,config:n,matrix:r,DenseMatrix:i,concat:a,SparseMatrix:o}=e,s=Rf({typed:t}),c=Gp({typed:t,SparseMatrix:o}),l=hf({typed:t,DenseMatrix:i}),u=Uf({typed:t,matrix:r,concat:a}),d=wd({typed:t});return t(a_,s_({typed:t,config:n}),{"boolean, boolean":(e,t)=>e<=t,"BigNumber, BigNumber":function(e,t){return e.lte(t)||id(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}))}),s_=Y(a_,[`typed`,`config`],e=>{var{typed:t,config:n}=e;return t(a_,{"number, number":function(e,t){return e<=t||Sa(e,t,n.relTol,n.absTol)}})}),c_=`larger`,l_=Y(c_,[`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=Rf({typed:t}),l=Gp({typed:t,SparseMatrix:s}),u=hf({typed:t,DenseMatrix:a}),d=Uf({typed:t,matrix:i,concat:o}),f=wd({typed:t});function p(e,t){return e.gt(t)&&!id(e,t,n.relTol,n.absTol)}return t(c_,u_({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}))}),u_=Y(c_,[`typed`,`config`],e=>{var{typed:t,config:n}=e;return t(c_,{"number, number":function(e,t){return e>t&&!Sa(e,t,n.relTol,n.absTol)}})}),d_=`largerEq`,f_=Y(d_,[`typed`,`config`,`matrix`,`DenseMatrix`,`concat`,`SparseMatrix`],e=>{var{typed:t,config:n,matrix:r,DenseMatrix:i,concat:a,SparseMatrix:o}=e,s=Rf({typed:t}),c=Gp({typed:t,SparseMatrix:o}),l=hf({typed:t,DenseMatrix:i}),u=Uf({typed:t,matrix:r,concat:a}),d=wd({typed:t});return t(d_,p_({typed:t,config:n}),{"boolean, boolean":(e,t)=>e>=t,"BigNumber, BigNumber":function(e,t){return e.gte(t)||id(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}))}),p_=Y(d_,[`typed`,`config`],e=>{var{typed:t,config:n}=e;return t(d_,{"number, number":function(e,t){return e>=t||Sa(e,t,n.relTol,n.absTol)}})}),m_=`deepEqual`,h_=Y(m_,[`typed`,`equal`],e=>{var{typed:t,equal:n}=e;return t(m_,{"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)}}),g_=`unequal`,__=Y(g_,[`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=Rf({typed:t}),l=Gp({typed:t,SparseMatrix:s}),u=hf({typed:t,DenseMatrix:a}),d=Uf({typed:t,matrix:i,concat:o});return t(g_,v_({typed:t,equalScalar:r}),d({elop:f,SS:l,DS:c,Ss:u}));function f(e,t){return!r(e,t)}}),v_=Y(g_,[`typed`,`equalScalar`],e=>{var{typed:t,equalScalar:n}=e;return t(g_,{"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)}})}),y_=`partitionSelect`,b_=Y(y_,[`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(y_,{"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(!ra(t)||t<0)throw Error(`k must be a non-negative integer`);if(ei(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]}}),x_=`sort`,S_=Y(x_,[`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(x_,{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(Tc(e).length!==1)throw Error(`One dimensional array expected`)}function l(e){if(e.size().length!==1)throw Error(`One dimensional matrix expected`)}}),C_=`max`,w_=Y(C_,[`typed`,`config`,`numeric`,`larger`,`isNaN`],e=>{var{typed:t,config:n,numeric:r,larger:i,isNaN:a}=e;return t(C_,{"Array | Matrix":s,"Array | Matrix, number | BigNumber":function(e,t){return yl(e,t.valueOf(),o)},"...":function(e){if(gl(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 Fh(e,`max`,t)}}function s(e){var t;if(_l(e,function(e){try{(a(e)||t===void 0||i(e,t))&&(t=e)}catch(t){throw Fh(t,`max`,e)}}),t===void 0)throw Error(`Cannot calculate max of an empty array`);return typeof t==`string`&&(t=r(t,ia(t,n))),t}}),T_=`min`,E_=Y(T_,[`typed`,`config`,`numeric`,`smaller`,`isNaN`],e=>{var{typed:t,config:n,numeric:r,smaller:i,isNaN:a}=e;return t(T_,{"Array | Matrix":s,"Array | Matrix, number | BigNumber":function(e,t){return yl(e,t.valueOf(),o)},"...":function(e){if(gl(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 Fh(e,`min`,t)}}function s(e){var t;if(_l(e,function(e){try{(a(e)||t===void 0||i(e,t))&&(t=e)}catch(t){throw Fh(t,`min`,e)}}),t===void 0)throw Error(`Cannot calculate min of an empty array`);return typeof t==`string`&&(t=r(t,ia(t,n))),t}}),D_=Y(`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&&!Qr(t))throw Error(`Invalid datatype: `+t);if(ei(e)||$r(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&&$r(e.data)&&$r(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 (`+Ii(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 ei(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:Li(this._data),size:Li(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}),O_=Y(`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=$r(a),s=ei(a),c=typeof a,l=null;if(ii(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(k_(a).valueOf())),s&&(u=i(k_(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(!Kr(e[n])||!ra(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=Li(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]=Qr(r)||Kr(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]=Qr(r)||Kr(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]=Qr(r)||Kr(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 Kr(e)?this._dimensions[e]??null:null},r.prototype.isObjectProperty=function(){return this._dimensions.length===1&&Qr(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(Qr(r)||Kr(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];Qr(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 k_(e){var t=[];return e.forEach((e,n)=>{e&&t.push(n)}),t}var A_=Y(`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}),j_=Y(`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 M_(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 N_(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:M_(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 P_=N_(function(e){return new e(1).exp()},{hasher:R_}),F_=N_(function(e){return new e(1).plus(new e(5).sqrt()).div(2)},{hasher:R_}),I_=N_(function(e){return e.acos(-1)},{hasher:R_}),L_=N_(function(e){return I_(e).times(2)},{hasher:R_});function R_(e){return e[0].precision}function z_(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 B_(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?z_(Object(n),!0).forEach(function(t){xh(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):z_(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}var V_=Y(`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)||Yr(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(Zr(t)&&t.value===null)this.fixPrefix=t.fixPrefix,this.skipAutomaticSimplification=t.skipAutomaticSimplification,this.dimensions=t.dimensions.slice(0),this.units=t.units.map(e=>kr({},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;U.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=Li(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])Gi(this.units[t],n)&&(e.units[t][n]=this.units[t][n]);return e},x.prototype.valueType=function(){return Ii(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(Ii(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(Ii(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=N_(e=>{if(Gi(H,e)){var t=H[e];return{unit:t,prefix:t.prefixes[``]}}for(var n in H)if(Gi(H,n)&&mc(e,n)){var r=H[n],i=e.length-n.length,a=e.substring(0,i),o=Gi(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=Zr(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=B_({},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,Zr(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=Zr(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=B_(B_({},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,Zr(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(Ii(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(Zr(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=Li(t);else{var o=x._getNumberConverter(Ii(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 W)if(Gi(W,r)&&e.hasBase(V[r])){n=r;break}if(n===`NONE`)e.units=[];else{var i;if(n&&Gi(W,n)&&(i=W[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&&(Gi(W,s)?t.push({unit:W[s].unit,prefix:W[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(Gi(U.si,r))t.push({unit:U.si[r].unit,prefix:U.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(!Zr(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&&Yr(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&&Yr(e.value)&&(t=Math.abs(e.value.re)<1e-14),e.units)Gi(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(Gi(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=kr({},z.SHORT,z.LONG),z.BINARY_SHORT=kr({},z.BINARY_SHORT_SI,z.BINARY_SHORT_IEC),z.BINARY_LONG=kr({},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)Gi(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=I_(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 U={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[``]}}};U.cgs=JSON.parse(JSON.stringify(U.si)),U.cgs.LENGTH={unit:H.m,prefix:z.SHORT.c},U.cgs.MASS={unit:H.g,prefix:z.SHORT[``]},U.cgs.FORCE={unit:H.dyn,prefix:z.SHORT[``]},U.cgs.ENERGY={unit:H.erg,prefix:z.NONE[``]},U.us=JSON.parse(JSON.stringify(U.si)),U.us.LENGTH={unit:H.ft,prefix:z.NONE[``]},U.us.MASS={unit:H.lbm,prefix:z.NONE[``]},U.us.TEMPERATURE={unit:H.degF,prefix:z.NONE[``]},U.us.FORCE={unit:H.lbf,prefix:z.NONE[``]},U.us.ENERGY={unit:H.BTU,prefix:z.BTU[``]},U.us.POWER={unit:H.hp,prefix:z.NONE[``]},U.us.PRESSURE={unit:H.psi,prefix:z.NONE[``]},U.auto=JSON.parse(JSON.stringify(U.si));var W=U.auto;for(var ie in x.setUnitSystem=function(e){if(Gi(U,e))W=U[e];else throw Error(`Unit system `+e+` does not exist. Choices are: `+Object.keys(U).join(`, `))},x.getUnitSystem=function(){for(var e in U)if(Gi(U,e)&&U[e]===W)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(Gi(H,ie)){var ae=H[ie];ae.dimensions=ae.base.dimensions}for(var oe in ne)if(Gi(ne,oe)){var se=H[ne[oe]],ce={};for(var le in se)Gi(se,le)&&(ce[le]=se[le]);ce.name=oe,H[oe]=ce}x.isValidAlpha=function(e){return/^[a-zA-Z]$/.test(e)};function ue(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(Gi(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)Gi(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(Gi(H,e))throw Error(`Cannot create unit "`+e+`": a unit with that name already exists`);ue(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(Gi(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(Gi(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,W[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)Gi(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]},W[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)Gi(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=U,x.UNITS=H,x},{isClass:!0}),H_=`unit`,U_=Y(H_,[`typed`,`Unit`],e=>{var{typed:t,Unit:n}=e;return t(H_,{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=>vl(t,e))})}),W_=`sparse`,G_=Y(W_,[`typed`,`SparseMatrix`],e=>{var{typed:t,SparseMatrix:n}=e;return t(W_,{"":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)}})}),K_=`createUnit`,q_=Y(K_,[`typed`,`Unit`],e=>{var{typed:t,Unit:n}=e;return t(K_,{"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,{})}})}),J_=`acos`,Y_=Y(J_,[`typed`,`config`,`Complex`],e=>{var{typed:t,config:n,Complex:r}=e;return t(J_,{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()}})}),X_=`acosh`,Z_=Y(X_,[`typed`,`config`,`Complex`],e=>{var{typed:t,config:n,Complex:r}=e;return t(X_,{number:function(e){return e>=1||n.predictable?Ou(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()}})}),Q_=`acot`,$_=Y(Q_,[`typed`,`BigNumber`],e=>{var{typed:t,BigNumber:n}=e;return t(Q_,{number:ku,Complex:function(e){return e.acot()},BigNumber:function(e){return new n(1).div(e).atan()}})}),ev=`acoth`,tv=Y(ev,[`typed`,`config`,`Complex`,`BigNumber`],e=>{var{typed:t,config:n,Complex:r,BigNumber:i}=e;return t(ev,{number:function(e){return e>=1||e<=-1||n.predictable?Au(e):new r(e,0).acoth()},Complex:function(e){return e.acoth()},BigNumber:function(e){return new i(1).div(e).atanh()}})}),nv=`acsc`,rv=Y(nv,[`typed`,`config`,`Complex`,`BigNumber`],e=>{var{typed:t,config:n,Complex:r,BigNumber:i}=e;return t(nv,{number:function(e){return e<=-1||e>=1||n.predictable?ju(e):new r(e,0).acsc()},Complex:function(e){return e.acsc()},BigNumber:function(e){return new i(1).div(e).asin()}})}),iv=`acsch`,av=Y(iv,[`typed`,`BigNumber`],e=>{var{typed:t,BigNumber:n}=e;return t(iv,{number:Mu,Complex:function(e){return e.acsch()},BigNumber:function(e){return new n(1).div(e).asinh()}})}),ov=`asec`,sv=Y(ov,[`typed`,`config`,`Complex`,`BigNumber`],e=>{var{typed:t,config:n,Complex:r,BigNumber:i}=e;return t(ov,{number:function(e){return e<=-1||e>=1||n.predictable?Nu(e):new r(e,0).asec()},Complex:function(e){return e.asec()},BigNumber:function(e){return new i(1).div(e).acos()}})}),cv=`asech`,lv=Y(cv,[`typed`,`config`,`Complex`,`BigNumber`],e=>{var{typed:t,config:n,Complex:r,BigNumber:i}=e;return t(cv,{number:function(e){if(e<=1&&e>=-1||n.predictable){var t=1/e;if(t>0||n.predictable)return Pu(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()}})}),uv=`asin`,dv=Y(uv,[`typed`,`config`,`Complex`],e=>{var{typed:t,config:n,Complex:r}=e;return t(uv,{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()}})}),fv=Y(`asinh`,[`typed`],e=>{var{typed:t}=e;return t(`asinh`,{number:Iu,Complex:function(e){return e.asinh()},BigNumber:function(e){return e.asinh()}})}),pv=Y(`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()}})}),mv=`atan2`,hv=Y(mv,[`typed`,`matrix`,`equalScalar`,`BigNumber`,`DenseMatrix`,`concat`],e=>{var{typed:t,matrix:n,equalScalar:r,BigNumber:i,DenseMatrix:a,concat:o}=e,s=Lf({typed:t,equalScalar:r}),c=Rf({typed:t}),l=Op({typed:t,equalScalar:r}),u=mf({typed:t,equalScalar:r}),d=hf({typed:t,DenseMatrix:a}),f=Uf({typed:t,matrix:n,concat:o});return t(mv,{"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}))}),gv=`atanh`,_v=Y(gv,[`typed`,`config`,`Complex`],e=>{var{typed:t,config:n,Complex:r}=e;return t(gv,{number:function(e){return e<=1&&e>=-1||n.predictable?zu(e):new r(e,0).atanh()},Complex:function(e){return e.atanh()},BigNumber:function(e){return e.atanh()}})}),vv=Y(`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)})}}),yv=`cos`,bv=Y(yv,[`typed`],e=>{var{typed:t}=e,n=vv({typed:t});return t(yv,{number:Math.cos,"Complex | BigNumber":e=>e.cos()},n)}),xv=`cosh`,Sv=Y(xv,[`typed`],e=>{var{typed:t}=e;return t(xv,{number:Ea,"Complex | BigNumber":e=>e.cosh()})}),Cv=`cot`,wv=Y(Cv,[`typed`,`BigNumber`],e=>{var{typed:t,BigNumber:n}=e,r=vv({typed:t});return t(Cv,{number:Hu,Complex:e=>e.cot(),BigNumber:e=>new n(1).div(e.tan())},r)}),Tv=`coth`,Ev=Y(Tv,[`typed`,`BigNumber`],e=>{var{typed:t,BigNumber:n}=e;return t(Tv,{number:Uu,Complex:e=>e.coth(),BigNumber:e=>new n(1).div(e.tanh())})}),Dv=`csc`,Ov=Y(Dv,[`typed`,`BigNumber`],e=>{var{typed:t,BigNumber:n}=e,r=vv({typed:t});return t(Dv,{number:Wu,Complex:e=>e.csc(),BigNumber:e=>new n(1).div(e.sin())},r)}),kv=`csch`,Av=Y(kv,[`typed`,`BigNumber`],e=>{var{typed:t,BigNumber:n}=e;return t(kv,{number:Gu,Complex:e=>e.csch(),BigNumber:e=>new n(1).div(e.sinh())})}),jv=`sec`,Mv=Y(jv,[`typed`,`BigNumber`],e=>{var{typed:t,BigNumber:n}=e,r=vv({typed:t});return t(jv,{number:Ku,Complex:e=>e.sec(),BigNumber:e=>new n(1).div(e.cos())},r)}),Nv=`sech`,Pv=Y(Nv,[`typed`,`BigNumber`],e=>{var{typed:t,BigNumber:n}=e;return t(Nv,{number:qu,Complex:e=>e.sech(),BigNumber:e=>new n(1).div(e.cosh())})}),Fv=`sin`,Iv=Y(Fv,[`typed`],e=>{var{typed:t}=e,n=vv({typed:t});return t(Fv,{number:Math.sin,"Complex | BigNumber":e=>e.sin()},n)}),Lv=`sinh`,Rv=Y(Lv,[`typed`],e=>{var{typed:t}=e;return t(Lv,{number:Yu,"Complex | BigNumber":e=>e.sinh()})}),zv=`tan`,eee=Y(zv,[`typed`],e=>{var{typed:t}=e,n=vv({typed:t});return t(zv,{number:Math.tan,"Complex | BigNumber":e=>e.tan()},n)}),tee=Y(`tanh`,[`typed`],e=>{var{typed:t}=e;return t(`tanh`,{number:Oa,"Complex | BigNumber":e=>e.tanh()})}),Bv=`setCartesian`,Vv=Y(Bv,[`typed`,`size`,`subset`,`compareNatural`,`Index`,`DenseMatrix`],e=>{var{typed:t,size:n,subset:r,compareNatural:i,Index:a,DenseMatrix:o}=e;return t(Bv,{"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=Vc(Array.isArray(e)?e:e.toArray()).sort(i),l=Vc(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)}})}),Hv=`setDifference`,Uv=Y(Hv,[`typed`,`size`,`subset`,`compareNatural`,`Index`,`DenseMatrix`],e=>{var{typed:t,size:n,subset:r,compareNatural:i,Index:a,DenseMatrix:o}=e;return t(Hv,{"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 Vc(e.toArray());else{var c=qc(Vc(Array.isArray(e)?e:e.toArray()).sort(i)),l=qc(Vc(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)?Jc(s):new o(Jc(s))}})}),Wv=`setDistinct`,Gv=Y(Wv,[`typed`,`size`,`subset`,`compareNatural`,`Index`,`DenseMatrix`],e=>{var{typed:t,size:n,subset:r,compareNatural:i,Index:a,DenseMatrix:o}=e;return t(Wv,{"Array | Matrix":function(e){var t;if(r(n(e),new a(0))===0)t=[];else{var s=Vc(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`,qv=Y(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=qc(Vc(Array.isArray(e)?e:e.toArray()).sort(i)),l=qc(Vc(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)?Jc(s):new o(Jc(s))}})}),Jv=`setIsSubset`,Yv=Y(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=qc(Vc(Array.isArray(e)?e:e.toArray()).sort(i)),s=qc(Vc(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}})}),Xv=`setMultiplicity`,Zv=Y(Xv,[`typed`,`size`,`subset`,`compareNatural`,`Index`],e=>{var{typed:t,size:n,subset:r,compareNatural:i,Index:a}=e;return t(Xv,{"number | BigNumber | Fraction | Complex, Array | Matrix":function(e,t){if(r(n(t),new a(0))===0)return 0;for(var o=Vc(Array.isArray(t)?t:t.toArray()),s=0,c=0;c<o.length;c++)i(o[c],e)===0&&s++;return s}})}),Qv=`setPowerset`,$v=Y(Qv,[`typed`,`size`,`subset`,`compareNatural`,`Index`],e=>{var{typed:t,size:n,subset:r,compareNatural:i,Index:a}=e;return t(Qv,{"Array | Matrix":function(e){if(r(n(e),new a(0))===0)return[];for(var t=Vc(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}}),ey=`setSize`,ty=Y(ey,[`typed`,`compareNatural`],e=>{var{typed:t,compareNatural:n}=e;return t(ey,{"Array | Matrix":function(e){return Array.isArray(e)?Vc(e).length:Vc(e.toArray()).length},"Array | Matrix, boolean":function(e,t){if(t===!1||e.length===0)return Array.isArray(e)?Vc(e).length:Vc(e.toArray()).length;for(var r=Vc(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}})}),ny=`setSymDifference`,ry=Y(ny,[`typed`,`size`,`concat`,`subset`,`setDifference`,`Index`],e=>{var{typed:t,size:n,concat:r,subset:i,setDifference:a,Index:o}=e;return t(ny,{"Array | Matrix, Array | Matrix":function(e,t){if(i(n(e),new o(0))===0)return Vc(t);if(i(n(t),new o(0))===0)return Vc(e);var s=Vc(e),c=Vc(t);return r(a(s,c),a(c,s))}})}),iy=`setUnion`,ay=Y(iy,[`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(iy,{"Array | Matrix, Array | Matrix":function(e,t){if(i(n(e),new s(0))===0)return Vc(t);if(i(n(t),new s(0))===0)return Vc(e);var c=Vc(e),l=Vc(t);return r(o(c,l),a(c,l))}})}),oy=`add`,sy=Y(oy,[`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=Kf({typed:t}),l=qf({typed:t,equalScalar:i}),u=Jf({typed:t,DenseMatrix:a}),d=Uf({typed:t,matrix:n,concat:s});return t(oy,{"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}))}),cy=`hypot`,ly=Y(cy,[`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(cy,{"... number | BigNumber":l,Array:l,Matrix:e=>l(Vc(e.toArray(),!0))});function l(e){for(var t=0,l=0,u=0;u<e.length;u++){if(Yr(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))}}),uy=`norm`,dy=Y(uy,[`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(uy,{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`)}}}),fy=`dot`,py=Y(fy,[`typed`,`addScalar`,`multiplyScalar`,`conj`,`size`],e=>{var{typed:t,addScalar:n,multiplyScalar:r,conj:i,size:a}=e;return t(fy,{"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=ei(e)?e._data:e,u=ei(e)?e._datatype||e.getDataType():void 0,d=ei(s)?s._data:s,f=ei(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}}),my=Y(`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:Li});function i(e){var t=e._size,n=e._data;switch(t.length){case 1:if(t[0]===1)return Li(n[0]);throw RangeError(`Matrix must be square (size: `+hc(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: `+hc(t)+`)`);default:throw RangeError(`Matrix must be two dimensional (size: `+hc(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: `+hc(a)+`)`)}}),hy=`index`,gy=Y(hy,[`typed`,`Index`],e=>{var{typed:t,Index:n}=e;return t(hy,{"...number | string | BigNumber | Range | Array | Matrix":function(e){var t=e.map(function(e){return qr(e)?e.toNumber():$r(e)||ei(e)?e.map(function(e){return qr(e)?e.toNumber():e}):e}),r=new n;return n.apply(r,t),r}})}),_y=new Set([`end`]),vy=Y(`Node`,[`mathWithTransform`],e=>{var{mathWithTransform:t}=e;function n(e){for(var t of[..._y])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=Wr(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(!Oi(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&&Vi(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 yy(e){return e&&e.isIndexError?new wc(e.index+1,e.min+1,e.max===void 0?void 0:e.max+1):e}function by(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 jr(e,n.getObjectProperty())}else throw TypeError(`Cannot apply index: unsupported type of object`)}catch(e){throw yy(e)}}}var xy=`AccessorNode`,Sy=Y(xy,[`subset`,`Node`],e=>{var{subset:t,Node:n}=e,r=by({subset:t});function i(e){return!(vi(e)||yi(e)||Ci(e)||Ei(e)||ki(e)||ji(e)||Pi(e))}class a extends n{constructor(e,t){var n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:!1;if(super(),!Oi(e))throw TypeError(`Node expected for parameter "object"`);if(!Di(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 xy}get isAccessorNode(){return!0}_compile(e,t){var n=this.object._compile(e,t),i=this.index._compile(e,t),a=this.optionalChaining,o=vi(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 jr(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:xy,object:this.object,index:this.index,optionalChaining:this.optionalChaining}}static fromJSON(e){return new a(e.object,e.index,e.optionalChaining)}}return xh(a,`name`,xy),a},{isClass:!0,isNode:!0}),Cy=`ArrayNode`,wy=Y(Cy,[`Node`],e=>{var{Node:t}=e;class n extends t{constructor(e){if(super(),this.items=e||[],!Array.isArray(this.items)||!this.items.every(Oi))throw TypeError(`Array containing Nodes expected`)}get type(){return Cy}get isArrayNode(){return!0}_compile(e,t){var n=Hc(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(Hc(n,function(n){return n(e,t,i)}))}}else return function(e,t,r){return Hc(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:Cy,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(yi)&&!n.every(yi),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 xh(n,`name`,Cy),n},{isClass:!0,isNode:!0});function Ty(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 Mr(e,r.getObjectProperty(),i),e}else throw TypeError(`Cannot apply index: unsupported type of object`)}catch(e){throw yy(e)}}}var Ey=[{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 Dy(e,t){if(!t||t!==`auto`)return e;for(var n=e;ji(n);)n=n.content;return n}function Oy(e,t,n,r){var i=e;t!==`keep`&&(i=e.getContent());for(var a=i.getIdentifier(),o=null,s=0;s<Ey.length;s++)if(a in Ey[s]){o=s;break}if(a===`OperatorNode:multiply`&&i.implicit&&n!==`show`){var c=Dy(i.args[0],t);!(Ci(c)&&r&&r.getIdentifier()===`OperatorNode:divide`&&wi(Dy(r.args[0],t)))&&!(c.getIdentifier()===`OperatorNode:divide`&&wi(Dy(c.args[0],t))&&Ci(Dy(c.args[1])))&&(o+=1)}return o}function ky(e,t){var n=e;t!==`keep`&&(n=e.getContent());var r=n.getIdentifier(),i=Oy(n,t);if(i===null)return null;var a=Ey[i][r];if(Gi(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 Ay(e,t,n){var r=n===`keep`?e:e.getContent(),i=n===`keep`?t:e.getContent(),a=r.getIdentifier(),o=i.getIdentifier(),s=Oy(r,n);if(s===null)return null;var c=Ey[s][a];if(Gi(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 jy(e){var t=`OperatorNode:`+e;for(var n of Ey)if(t in n)return n[t].op;return null}var My=`AssignmentNode`,Ny=Y(My,[`subset`,`?matrix`,`Node`],e=>{var{subset:t,matrix:n,Node:r}=e,i=by({subset:t}),a=Ty({subset:t,matrix:n});function o(e,t,n){t||=`keep`;var r=Oy(e,t,n),i=Oy(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,!Pi(e)&&!vi(e))throw TypeError(`SymbolNode or AccessorNode expected as "object"`);if(Pi(e)&&e.name===`end`)throw Error(`Cannot assign to symbol "end"`);if(this.index&&!Di(this.index))throw TypeError(`IndexNode expected as "index"`);if(!Oi(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 My}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(!Pi(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 Mr(i,c,a),a}}else if(Pi(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=jr(i,u),c=r(e,t,s),d=o(e,t,n);return Mr(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:My,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 xh(s,`name`,My),s},{isClass:!0,isNode:!0}),Py=`BlockNode`,Fy=Y(Py,[`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(!Oi(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 Py}get isBlockNode(){return!0}_compile(e,n){var r=Hc(this.blocks,function(t){return{evaluate:t.node._compile(e,n),visible:t.visible}});return function(e,n,i){var a=[];return Uc(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(`
@@ -69,7 +69,7 @@ In case of a (multi dimensional) array or matrix, the prob order quantile of all
69
69
  return false;
70
70
  }`),e.length!==n.length&&(t=`if (x !== x) return false;\n${t}`),Function(`x`,`${t}\nreturn true;`)}function aF(e){return typeof e==`bigint`?`${zA(e)}n`:zA(e)}function oF(e,t){let n=Math.ceil(e)*t-1;return(n-n%64+64||64)/t}function sF(e,t=0){return e.length>=t?e.subarray(0,t):Sk(new e.constructor(t),e,0)}var cF=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(oF(r===0?n*1:n*2,this.BYTES_PER_ELEMENT))}return this}flush(e=this.length){e=oF(e*this.stride,this.BYTES_PER_ELEMENT);let t=sF(this.buffer,e);return this.clear(),t}clear(){return this.length=0,this.buffer=new this.ArrayType,this}_resize(e){return this.buffer=sF(this.buffer,e)}},lF=class extends cF{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}},uF=class extends lF{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()}},dF=class extends lF{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)}},fF=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=nM(e),this._nulls=new uF,t&&t.length>0&&(this._isValid=iF(t))}toVector(){return new eF([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(),AP({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}};fF.prototype.length=1,fF.prototype.stride=1,fF.prototype.children=null,fF.prototype.finished=!1,fF.prototype.nullValues=null,fF.prototype._isValid=()=>!0;var pF=class extends fF{constructor(e){super(e),this._values=new lF(this.ArrayType,0,this.stride)}setValue(e,t){let n=this._values;return n.reserve(e-n.length+1),super.setValue(e,t)}},mF=class extends fF{constructor(e){super(e),this._pendingLength=0,this._offsets=new dF(e.type)}setValue(e,t){let n=this._pending||=new Map,r=n.get(e);r&&(this._pendingLength-=r.length),this._pendingLength+=t instanceof iP?t[eP].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}},hF=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()}},gF=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):Uk.V1}schema(e){let t=this.bb.__offset(this.bb_pos,6);return t?(e||new FA).__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 hF).__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 hF).__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 pA).__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,Uk.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)}},_F=class e{constructor(e=[],t,n,r=Uk.V5){this.fields=e||[],this.metadata=t||new Map,n||=bF(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=yF(yF(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:yF(yF(new Map,r[t].metadata),e.metadata)}))&&!1:!0}),o=bF(a,new Map);return new e([...r,...a],i,new Map([...this.dictionaries,...o]))}};_F.prototype.fields=null,_F.prototype.metadata=null,_F.prototype.dictionaries=null;var vF=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)}};vF.prototype.type=null,vF.prototype.name=null,vF.prototype.nullable=null,vF.prototype.metadata=null;function yF(e,t){return new Map([...e||new Map,...t||new Map])}function bF(e,t=new Map){for(let n=-1,r=e.length;++n<r;){let r=e[n].type;if(xj.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&&bF(r.children,t)}return t}var xF=tA,SF=eA,CF=class{static decode(e){e=new SF(Dk(e));let t=gF.getRootAsFooter(e);return new wF(_F.decode(t.schema(),new Map,t.version()),t)}static encode(e){let t=new xF,n=_F.encode(t,e.schema);gF.startRecordBatchesVector(t,e.numRecordBatches);for(let n of[...e.recordBatches()].slice().reverse())TF.encode(t,n);let r=t.endVector();gF.startDictionariesVector(t,e.numDictionaries);for(let n of[...e.dictionaryBatches()].slice().reverse())TF.encode(t,n);let i=t.endVector();return gF.startFooter(t),gF.addSchema(t,n),gF.addVersion(t,Uk.V5),gF.addRecordBatches(t,r),gF.addDictionaries(t,i),gF.finishFooterBuffer(t,gF.endFooter(t)),t.asUint8Array()}get numRecordBatches(){return this._recordBatches.length}get numDictionaries(){return this._dictionaryBatches.length}constructor(e,t=Uk.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}},wF=class extends CF{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 TF.decode(t)}return null}getDictionaryBatch(e){if(e>=0&&e<this.numDictionaries){let t=this._footer.dictionaries(e);if(t)return TF.decode(t)}return null}},TF=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 hF.createBlock(e,r,n,i)}constructor(e,t,n){this.metaDataLength=e,this.offset=BA(n),this.bodyLength=BA(t)}},EF=Object.freeze({done:!0,value:void 0}),DF=class{constructor(e){this._json=e}get schema(){return this._json.schema}get batches(){return this._json.batches||[]}get dictionaries(){return this._json.dictionaries||[]}},OF=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()}},kF=class extends OF{constructor(){super(),this._values=[],this.resolvers=[],this._closedPromise=new Promise(e=>this._closedPromiseResolve=e)}get closed(){return this._closedPromise}cancel(e){return qO(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(EF);this._closedPromiseResolve(),this._closedPromiseResolve=void 0}}[Symbol.asyncIterator](){return this}toDOMStream(e){return Fk.toDOMStream(this._closedPromiseResolve||this._error?this:this._values,e)}toNodeStream(e){return Fk.toNodeStream(this._closedPromiseResolve||this._error?this:this._values,e)}throw(e){return qO(this,void 0,void 0,function*(){return yield this.abort(e),EF})}return(e){return qO(this,void 0,void 0,function*(){return yield this.close(),EF})}read(e){return qO(this,void 0,void 0,function*(){return(yield this.next(e,`read`)).value})}peek(e){return qO(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(EF)}_ensureOpen(){if(this._closedPromiseResolve)return!0;throw Error(`AsyncQueue is closed`)}},AF=class extends kF{write(e){if((e=Dk(e)).byteLength>0)return super.write(e)}toString(e=!1){return e?ek(this.toUint8Array(!0)):this.toUint8Array(!1).then(ek)}toUint8Array(e=!1){return e?Ck(this._values)[0]:qO(this,void 0,void 0,function*(){var e,t,n,r;let i=[],a=0;try{for(var o=!0,s=QO(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 Ck(i,a)[0]})}},jF=class{constructor(e){e&&(this.source=new NF(Fk.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)}},MF=class e{constructor(t){t instanceof e?this.source=t.source:t instanceof AF?this.source=new PF(Fk.fromAsyncIterable(t)):vk(t)?this.source=new PF(Fk.fromNodeStream(t)):gk(t)?this.source=new PF(Fk.fromDOMStream(t)):pk(t)?this.source=new PF(Fk.fromDOMStream(t.body)):ck(t)?this.source=new PF(Fk.fromIterable(t)):(sk(t)||lk(t))&&(this.source=new PF(Fk.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)}},NF=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)||EF)}return(e){return Object.create(this.source.return&&this.source.return(e)||EF)}},PF=class{constructor(e){this.source=e,this._closedPromise=new Promise(e=>this._closedPromiseResolve=e)}cancel(e){return qO(this,void 0,void 0,function*(){yield this.return(e)})}get closed(){return this._closedPromise}read(e){return qO(this,void 0,void 0,function*(){return(yield this.next(e,`read`)).value})}peek(e){return qO(this,void 0,void 0,function*(){return(yield this.next(e,`peek`)).value})}next(e){return qO(this,arguments,void 0,function*(e,t=`read`){return yield this.source.next({cmd:t,size:e})})}throw(e){return qO(this,void 0,void 0,function*(){let t=this.source.throw&&(yield this.source.throw(e))||EF;return this._closedPromiseResolve&&this._closedPromiseResolve(),this._closedPromiseResolve=void 0,Object.create(t)})}return(e){return qO(this,void 0,void 0,function*(){let t=this.source.return&&(yield this.source.return(e))||EF;return this._closedPromiseResolve&&this._closedPromiseResolve(),this._closedPromiseResolve=void 0,Object.create(t)})}},FF=class extends jF{constructor(e,t){super(),this.position=0,this.buffer=Dk(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}}},IF=class extends MF{constructor(e,t){super(),this.position=0,this._handle=e,typeof t==`number`?this.size=t:this._pending=qO(this,void 0,void 0,function*(){this.size=(yield e.stat()).size,delete this._pending})}readInt32(e){return qO(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 qO(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 qO(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 qO(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 qO(this,void 0,void 0,function*(){let e=this._handle;this._handle=null,e&&(yield e.close())})}throw(e){return qO(this,void 0,void 0,function*(){return yield this.close(),{done:!0,value:e}})}return(e){return qO(this,void 0,void 0,function*(){return yield this.close(),{done:!0,value:e}})}},LF=65536;function RF(e){return e<0&&(e=4294967295+e+1),`0x${e.toString(16)}`}var zF=8,BF=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8],VF=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?LF: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`${RF(this.buffer[1])} ${RF(this.buffer[0])}`}},HF=class e extends VF{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=zF<r-n?zF:r-n,o=new e(new Uint32Array([Number.parseInt(t.slice(n,n+a),10),0])),s=new e(new Uint32Array([BF[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)}},UF=class e extends VF{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=zF<i-n?zF:i-n,o=new e(new Uint32Array([Number.parseInt(t.slice(n,n+r),10),0])),s=new e(new Uint32Array([BF[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)}},WF=class e{constructor(e){this.buffer=e}high(){return new UF(new Uint32Array(this.buffer.buffer,this.buffer.byteOffset+8,2))}low(){return new UF(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 HF(new Uint32Array([this.buffer[3],0])),n=new HF(new Uint32Array([this.buffer[2],0])),r=new HF(new Uint32Array([this.buffer[1],0])),i=new HF(new Uint32Array([this.buffer[0],0])),a=new HF(new Uint32Array([e.buffer[3],0])),o=new HF(new Uint32Array([e.buffer[2],0])),s=new HF(new Uint32Array([e.buffer[1],0])),c=new HF(new Uint32Array([e.buffer[0],0])),l=HF.multiply(i,c);this.buffer[0]=l.low();let u=new HF(new Uint32Array([l.high(),0]));return l=HF.multiply(r,c),u.plus(l),l=HF.multiply(i,s),u.plus(l),this.buffer[1]=u.low(),this.buffer[3]=+!!u.lessThan(l),this.buffer[2]=u.high(),new HF(new Uint32Array(this.buffer.buffer,this.buffer.byteOffset+8,2)).plus(HF.multiply(n,c)).plus(HF.multiply(r,s)).plus(HF.multiply(i,o)),this.buffer[3]+=HF.multiply(t,c).plus(HF.multiply(n,s)).plus(HF.multiply(r,o)).plus(HF.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`${RF(this.buffer[3])} ${RF(this.buffer[2])} ${RF(this.buffer[1])} ${RF(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=zF<i-n?zF:i-n,o=new e(new Uint32Array([Number.parseInt(t.slice(n,n+r),10),0,0,0])),s=new e(new Uint32Array([BF[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}},GF=class extends rM{constructor(e,t,n,r,i=Uk.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 vF?e.type:e)}visitNull(e,{length:t}=this.nextFieldNode()){return AP({type:e,length:t})}visitBool(e,{length:t,nullCount:n}=this.nextFieldNode()){return AP({type:e,length:t,nullCount:n,nullBitmap:this.readNullBitmap(e,n),data:this.readData(e)})}visitInt(e,{length:t,nullCount:n}=this.nextFieldNode()){return AP({type:e,length:t,nullCount:n,nullBitmap:this.readNullBitmap(e,n),data:this.readData(e)})}visitFloat(e,{length:t,nullCount:n}=this.nextFieldNode()){return AP({type:e,length:t,nullCount:n,nullBitmap:this.readNullBitmap(e,n),data:this.readData(e)})}visitUtf8(e,{length:t,nullCount:n}=this.nextFieldNode()){return AP({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 AP({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 AP({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 AP({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 AP({type:e,length:t,nullCount:n,nullBitmap:this.readNullBitmap(e,n),data:this.readData(e)})}visitDate(e,{length:t,nullCount:n}=this.nextFieldNode()){return AP({type:e,length:t,nullCount:n,nullBitmap:this.readNullBitmap(e,n),data:this.readData(e)})}visitTimestamp(e,{length:t,nullCount:n}=this.nextFieldNode()){return AP({type:e,length:t,nullCount:n,nullBitmap:this.readNullBitmap(e,n),data:this.readData(e)})}visitTime(e,{length:t,nullCount:n}=this.nextFieldNode()){return AP({type:e,length:t,nullCount:n,nullBitmap:this.readNullBitmap(e,n),data:this.readData(e)})}visitDecimal(e,{length:t,nullCount:n}=this.nextFieldNode()){return AP({type:e,length:t,nullCount:n,nullBitmap:this.readNullBitmap(e,n),data:this.readData(e)})}visitList(e,{length:t,nullCount:n}=this.nextFieldNode()){return AP({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 AP({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<Uk.V5&&this.readNullBitmap(e,n),e.mode===Wk.Sparse?this.visitSparseUnion(e,{length:t,nullCount:n}):this.visitDenseUnion(e,{length:t,nullCount:n})}visitDenseUnion(e,{length:t,nullCount:n}=this.nextFieldNode()){return AP({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 AP({type:e,length:t,nullCount:n,typeIds:this.readTypeIds(e),children:this.visitMany(e.children)})}visitDictionary(e,{length:t,nullCount:n}=this.nextFieldNode()){return AP({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 AP({type:e,length:t,nullCount:n,nullBitmap:this.readNullBitmap(e,n),data:this.readData(e)})}visitDuration(e,{length:t,nullCount:n}=this.nextFieldNode()){return AP({type:e,length:t,nullCount:n,nullBitmap:this.readNullBitmap(e,n),data:this.readData(e)})}visitFixedSizeList(e,{length:t,nullCount:n}=this.nextFieldNode()){return AP({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 AP({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)}},KF=class extends GF{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:CP(this.sources[n])}readOffsets(e,{offset:t}=this.nextBufferRange()){return wk(Uint8Array,wk(e.OffsetArrayType,this.sources[t]))}readTypeIds(e,{offset:t}=this.nextBufferRange()){return wk(Uint8Array,wk(e.ArrayType,this.sources[t]))}readData(e,{offset:t}=this.nextBufferRange()){let{sources:n}=this;return xj.isTimestamp(e)||(xj.isInt(e)||xj.isTime(e))&&e.bitWidth===64||xj.isDuration(e)||xj.isDate(e)&&e.unit===Kk.MILLISECOND?wk(Uint8Array,UF.convertArray(n[t])):xj.isDecimal(e)?wk(Uint8Array,WF.convertArray(n[t])):xj.isBinary(e)||xj.isLargeBinary(e)||xj.isFixedSizeBinary(e)?qF(n[t]):xj.isBool(e)?CP(n[t]):xj.isUtf8(e)||xj.isLargeUtf8(e)?nk(n[t].join(``)):wk(Uint8Array,wk(e.ArrayType,n[t].map(e=>+e)))}};function qF(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 JF=class extends mF{constructor(e){super(e),this._values=new cF(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,Dk(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}}},YF=class extends mF{constructor(e){super(e),this._values=new cF(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,Dk(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}}},XF=class extends fF{constructor(e){super(e),this._values=new uF}setValue(e,t){this._values.set(e,+t)}},ZF=class extends pF{};ZF.prototype._setValue=TM;var QF=class extends ZF{};QF.prototype._setValue=bM;var $F=class extends ZF{};$F.prototype._setValue=xM;var eI=class extends pF{};eI.prototype._setValue=IM;var tI=class extends fF{constructor({type:e,nullValues:t,dictionaryHashFunction:n}){super({type:new tM(e.dictionary,e.indices,e.id,e.isOrdered)}),this._nulls=null,this._dictionaryOffset=0,this._keysToIndices=Object.create(null),this.indices=lL({type:this.type.indices,nullValues:t}),this.dictionary=lL({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}`}},nI=class extends pF{};nI.prototype._setValue=SM;var rI=class extends fF{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 Qj(this.type.listSize,new vF(t,e.type,!0)),n}},iI=class extends pF{setValue(e,t){this._values.set(e,t)}},aI=class extends iI{setValue(e,t){super.setValue(e,uM(t))}},oI=class extends iI{},sI=class extends iI{},cI=class extends pF{};cI.prototype._setValue=JM;var lI=class extends cI{};lI.prototype._setValue=YM;var uI=class extends cI{};uI.prototype._setValue=XM;var dI=class extends pF{};dI.prototype._setValue=tN;var fI=class extends dI{};fI.prototype._setValue=ZM;var pI=class extends dI{};pI.prototype._setValue=QM;var mI=class extends dI{};mI.prototype._setValue=$M;var hI=class extends dI{};hI.prototype._setValue=eN;var gI=class extends pF{setValue(e,t){this._values.set(e,t)}},_I=class extends gI{},vI=class extends gI{},yI=class extends gI{},bI=class extends gI{},xI=class extends gI{},SI=class extends gI{},CI=class extends gI{},wI=class extends gI{},TI=class extends mF{constructor(e){super(e),this._offsets=new dF(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 Jj(new vF(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])}}},nee=class extends mF{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 $j(new vF(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}}},ree=class extends fF{setValue(e,t){}setValid(e,t){return this.length=Math.max(e+1,this.length),t}},EI=class extends fF{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 Yj([...this.type.children,new vF(t,e.type,!0)]),n}},DI=class extends pF{};DI.prototype._setValue=AM;var OI=class extends DI{};OI.prototype._setValue=EM;var kI=class extends DI{};kI.prototype._setValue=DM;var AI=class extends DI{};AI.prototype._setValue=OM;var jI=class extends DI{};jI.prototype._setValue=kM;var MI=class extends pF{};MI.prototype._setValue=FM;var NI=class extends MI{};NI.prototype._setValue=jM;var PI=class extends MI{};PI.prototype._setValue=MM;var FI=class extends MI{};FI.prototype._setValue=NM;var II=class extends MI{};II.prototype._setValue=PM;var LI=class extends fF{constructor(e){super(e),this._typeIds=new lF(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 vF(t,e.type)];return this.type=new Xj(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.")}},RI=class extends LI{},zI=class extends LI{constructor(e){super(e),this._offsets=new lF(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)}},BI=class extends mF{constructor(e){super(e),this._values=new cF(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,nk(t))}_flushPending(e,t){}};BI.prototype._flushPending=JF.prototype._flushPending;var VI=class extends mF{constructor(e){super(e),this._values=new cF(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,nk(t))}_flushPending(e,t){}};VI.prototype._flushPending=YF.prototype._flushPending;var HI=new class extends rM{visitNull(){return ree}visitBool(){return XF}visitInt(){return gI}visitInt8(){return _I}visitInt16(){return vI}visitInt32(){return yI}visitInt64(){return bI}visitUint8(){return xI}visitUint16(){return SI}visitUint32(){return CI}visitUint64(){return wI}visitFloat(){return iI}visitFloat16(){return aI}visitFloat32(){return oI}visitFloat64(){return sI}visitUtf8(){return BI}visitLargeUtf8(){return VI}visitBinary(){return JF}visitLargeBinary(){return YF}visitFixedSizeBinary(){return nI}visitDate(){return ZF}visitDateDay(){return QF}visitDateMillisecond(){return $F}visitTimestamp(){return DI}visitTimestampSecond(){return OI}visitTimestampMillisecond(){return kI}visitTimestampMicrosecond(){return AI}visitTimestampNanosecond(){return jI}visitTime(){return MI}visitTimeSecond(){return NI}visitTimeMillisecond(){return PI}visitTimeMicrosecond(){return FI}visitTimeNanosecond(){return II}visitDecimal(){return eI}visitList(){return TI}visitStruct(){return EI}visitUnion(){return LI}visitDenseUnion(){return zI}visitSparseUnion(){return RI}visitDictionary(){return tI}visitInterval(){return cI}visitIntervalDayTime(){return lI}visitIntervalYearMonth(){return uI}visitDuration(){return dI}visitDurationSecond(){return fI}visitDurationMillisecond(){return pI}visitDurationMicrosecond(){return mI}visitDurationNanosecond(){return hI}visitFixedSizeList(){return rI}visitMap(){return nee}},UI=class extends rM{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 WI(e,t){return t instanceof e.constructor}function GI(e,t){return e===t||WI(e,t)}function KI(e,t){return e===t||WI(e,t)&&e.bitWidth===t.bitWidth&&e.isSigned===t.isSigned}function qI(e,t){return e===t||WI(e,t)&&e.precision===t.precision}function JI(e,t){return e===t||WI(e,t)&&e.byteWidth===t.byteWidth}function YI(e,t){return e===t||WI(e,t)&&e.unit===t.unit}function XI(e,t){return e===t||WI(e,t)&&e.unit===t.unit&&e.timezone===t.timezone}function ZI(e,t){return e===t||WI(e,t)&&e.unit===t.unit&&e.bitWidth===t.bitWidth}function QI(e,t){return e===t||WI(e,t)&&e.children.length===t.children.length&&oL.compareManyFields(e.children,t.children)}function $I(e,t){return e===t||WI(e,t)&&e.children.length===t.children.length&&oL.compareManyFields(e.children,t.children)}function eL(e,t){return e===t||WI(e,t)&&e.mode===t.mode&&e.typeIds.every((e,n)=>e===t.typeIds[n])&&oL.compareManyFields(e.children,t.children)}function tL(e,t){return e===t||WI(e,t)&&e.id===t.id&&e.isOrdered===t.isOrdered&&oL.visit(e.indices,t.indices)&&oL.visit(e.dictionary,t.dictionary)}function nL(e,t){return e===t||WI(e,t)&&e.unit===t.unit}function rL(e,t){return e===t||WI(e,t)&&e.unit===t.unit}function iL(e,t){return e===t||WI(e,t)&&e.listSize===t.listSize&&e.children.length===t.children.length&&oL.compareManyFields(e.children,t.children)}function aL(e,t){return e===t||WI(e,t)&&e.keysSorted===t.keysSorted&&e.children.length===t.children.length&&oL.compareManyFields(e.children,t.children)}UI.prototype.visitNull=GI,UI.prototype.visitBool=GI,UI.prototype.visitInt=KI,UI.prototype.visitInt8=KI,UI.prototype.visitInt16=KI,UI.prototype.visitInt32=KI,UI.prototype.visitInt64=KI,UI.prototype.visitUint8=KI,UI.prototype.visitUint16=KI,UI.prototype.visitUint32=KI,UI.prototype.visitUint64=KI,UI.prototype.visitFloat=qI,UI.prototype.visitFloat16=qI,UI.prototype.visitFloat32=qI,UI.prototype.visitFloat64=qI,UI.prototype.visitUtf8=GI,UI.prototype.visitLargeUtf8=GI,UI.prototype.visitBinary=GI,UI.prototype.visitLargeBinary=GI,UI.prototype.visitFixedSizeBinary=JI,UI.prototype.visitDate=YI,UI.prototype.visitDateDay=YI,UI.prototype.visitDateMillisecond=YI,UI.prototype.visitTimestamp=XI,UI.prototype.visitTimestampSecond=XI,UI.prototype.visitTimestampMillisecond=XI,UI.prototype.visitTimestampMicrosecond=XI,UI.prototype.visitTimestampNanosecond=XI,UI.prototype.visitTime=ZI,UI.prototype.visitTimeSecond=ZI,UI.prototype.visitTimeMillisecond=ZI,UI.prototype.visitTimeMicrosecond=ZI,UI.prototype.visitTimeNanosecond=ZI,UI.prototype.visitDecimal=GI,UI.prototype.visitList=QI,UI.prototype.visitStruct=$I,UI.prototype.visitUnion=eL,UI.prototype.visitDenseUnion=eL,UI.prototype.visitSparseUnion=eL,UI.prototype.visitDictionary=tL,UI.prototype.visitInterval=nL,UI.prototype.visitIntervalDayTime=nL,UI.prototype.visitIntervalYearMonth=nL,UI.prototype.visitDuration=rL,UI.prototype.visitDurationSecond=rL,UI.prototype.visitDurationMillisecond=rL,UI.prototype.visitDurationMicrosecond=rL,UI.prototype.visitDurationNanosecond=rL,UI.prototype.visitFixedSizeList=iL,UI.prototype.visitMap=aL;var oL=new UI;function sL(e,t){return oL.compareSchemas(e,t)}function cL(e,t){return oL.visit(e,t)}function lL(e){let t=e.type,n=new(HI.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(lL(Object.assign(Object.assign({},i),{type:t})))}}return n}function uL(e,t){if(e instanceof OP||e instanceof eF||e.type instanceof xj||ArrayBuffer.isView(e))return nF(e);let n=[...fL({type:t??dL(e),nullValues:[null]})(e)],r=n.length===1?n[0]:n.reduce((e,t)=>e.concat(t));return xj.isDictionary(r.type)?r.memoize():r}function dL(e){if(e.length===0)return new Sj;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 Fj;if(a+t===e.length)return new tM(new Rj,new Ej);if(o+t===e.length)return new Dj;if(s+t===e.length)return new Bj;if(c+t===e.length)return new Gj;if(n+t===e.length){let t=e,n=dL(t[t.findIndex(e=>e!=null)]);if(t.every(e=>e==null||cL(n,dL(e))))return new Jj(new vF(``,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 vF(e,dL([n[e]]),!0));return new Yj([...t.values()])}throw TypeError(`Unable to infer Vector type from input values, explicit type declaration expected.`)}function fL(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=lL(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 pL(e,t){return mL(e,t.map(e=>e.data.concat()))}function mL(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=hL(n,o,u,t,i),o>0&&(r[a++]=AP({type:new Yj(n),length:o,nullCount:0,children:u.slice()})))}return[e=e.assign(n),r.map(t=>new yL(e,t))]}function hL(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)??AP({type:r.type,length:t,nullCount:t,nullBitmap:new Uint8Array(a)})}}return n}var gL,_L=class e{constructor(...t){if(t.length===0)return this.batches=[],this.schema=new _F([]),this._offsets=[0],this;let n,r;t[0]instanceof _F&&(n=t.shift()),t.at(-1)instanceof Uint32Array&&(r=t.pop());let i=t=>{if(t){if(t instanceof yL)return[t];if(t instanceof e)return t.batches;if(t instanceof OP){if(t.type instanceof Yj)return[new yL(new _F(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 eF([t[e]])),[,i]=pL(n??new _F(e.map((e,t)=>new vF(String(e),r[t].type,r[t].nullable))),r);return i.length===0?[new yL(t)]:i}}return[]},a=t.flatMap(e=>i(e));if(n=n??a[0]?.schema??new _F([]),!(n instanceof _F))throw TypeError(`Table constructor expects a [Schema, RecordBatch[]] pair.`);for(let e of a){if(!(e instanceof yL))throw TypeError(`Table constructor expects a [Schema, RecordBatch[]] pair.`);if(!sL(n,e.schema))throw TypeError(`Table and inner RecordBatch schemas must be equivalent.`)}this.schema=n,this.batches=a,this._offsets=r??PP(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=NP(this.data)),this._nullCount}isValid(e){return!1}get(e){return null}at(e){return this.get(lP(e,this.numRows))}set(e,t){}indexOf(e,t){return-1}[Symbol.iterator](){return this.batches.length>0?XP.visit(new eF(this.data)):[][Symbol.iterator]()}toArray(){return[...this]}toString(){return`[\n ${this.toArray().join(`,
71
71
  `)}\n]`}concat(...t){let n=this.schema;return new e(n,this.data.concat(t.flatMap(({data:e})=>e)).map(e=>new yL(n,e)))}slice(t,n){let r=this.schema;return[t,n]=cP({length:this.numRows},t,n),new e(r,FP(this.data,this._offsets,t,n).map(e=>new yL(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=AP({type:n,length:0,nullCount:0});t.push(r._changeLengthAndBackfillNullBitmap(this.numRows))}return new eF(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 eF([AP({type:new Sj,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]=pL(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(...pL(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)))}};gL=Symbol.toStringTag,_L[gL]=(e=>(e.schema=null,e.batches=[],e._offsets=new Uint32Array([0]),e._nullCount=-1,e[Symbol.isConcatSpreadable]=!0,e.isValid=RP(LP),e.get=RP($N.getVisitFn(Q.Struct)),e.set=zP(rN.getVisitFn(Q.Struct)),e.indexOf=BP(KP.getVisitFn(Q.Struct)),`Table`))(_L.prototype);var vL,yL=class e{constructor(...e){switch(e.length){case 2:if([this.schema]=e,!(this.schema instanceof _F)||([,this.data=AP({nullCount:0,type:new Yj(this.schema.fields),children:this.schema.fields.map(e=>AP({type:e.type,nullCount:0}))})]=e,!(this.data instanceof OP)))throw TypeError(`RecordBatch constructor expects a [Schema, Data] pair.`);[this.schema,this.data]=bL(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]=vF.new({name:n,type:t[n].type,nullable:!0}),e),{length:0,fields:[],children:[]}),a=new _F(n),o=AP({type:new Yj(n),length:i,children:r,nullCount:0});[this.schema,this.data]=bL(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||=xL(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 $N.visit(this.data,e)}at(e){return this.get(lP(e,this.numRows))}set(e,t){return rN.visit(this.data,e,t)}indexOf(e,t){return KP.visit(this.data,e,t)}[Symbol.iterator](){return XP.visit(new eF([this.data]))}toArray(){return[...this]}concat(...e){return new _L(this.schema,[this,...e])}slice(t,n){let[r]=new eF([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 eF([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 eF([AP({type:new Sj,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 _F(e,new Map(this.schema.metadata)),i=AP({type:new Yj(e),children:a})}return new e(r,i)}select(t){let n=this.schema.select(t),r=new Yj(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,AP({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,AP({type:new Yj(n.fields),length:this.numRows,children:r}))}};vL=Symbol.toStringTag,yL[vL]=(e=>(e._nullCount=-1,e[Symbol.isConcatSpreadable]=!0,`RecordBatch`))(yL.prototype);function bL(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)??AP({type:s.type,length:n,nullCount:n,nullBitmap:new Uint8Array(a)}))}return[e.assign(r),AP({type:new Yj(r),length:n,children:i})]}function xL(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||[]])xL(i.children,e?.children,n);if(xj.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 SL=class extends yL{constructor(e){let t=e.fields.map(e=>AP({type:e.type})),n=AP({type:new Yj(e.fields),nullCount:0,children:t});super(e,n)}},CL=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):Uk.V1}headerType(){let e=this.bb.__offset(this.bb_pos,6);return e?this.bb.readUint8(this.bb_pos+e):IA.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 pA).__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,Uk.V1)}static addHeaderType(e,t){e.addFieldInt8(1,t,IA.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)}},wL=new class extends rM{visit(e,t){return e==null||t==null?void 0:super.visit(e,t)}visitNull(e,t){return DA.startNull(t),DA.endNull(t)}visitInt(e,t){return dA.startInt(t),dA.addBitWidth(t,e.bitWidth),dA.addIsSigned(t,e.isSigned),dA.endInt(t)}visitFloat(e,t){return xA.startFloatingPoint(t),xA.addPrecision(t,e.precision),xA.endFloatingPoint(t)}visitBinary(e,t){return mA.startBinary(t),mA.endBinary(t)}visitLargeBinary(e,t){return CA.startLargeBinary(t),CA.endLargeBinary(t)}visitBool(e,t){return hA.startBool(t),hA.endBool(t)}visitUtf8(e,t){return MA.startUtf8(t),MA.endUtf8(t)}visitLargeUtf8(e,t){return wA.startLargeUtf8(t),wA.endLargeUtf8(t)}visitDecimal(e,t){return _A.startDecimal(t),_A.addScale(t,e.scale),_A.addPrecision(t,e.precision),_A.addBitWidth(t,e.bitWidth),_A.endDecimal(t)}visitDate(e,t){return gA.startDate(t),gA.addUnit(t,e.unit),gA.endDate(t)}visitTime(e,t){return kA.startTime(t),kA.addUnit(t,e.unit),kA.addBitWidth(t,e.bitWidth),kA.endTime(t)}visitTimestamp(e,t){let n=e.timezone&&t.createString(e.timezone)||void 0;return AA.startTimestamp(t),AA.addUnit(t,e.unit),n!==void 0&&AA.addTimezone(t,n),AA.endTimestamp(t)}visitInterval(e,t){return SA.startInterval(t),SA.addUnit(t,e.unit),SA.endInterval(t)}visitDuration(e,t){return vA.startDuration(t),vA.addUnit(t,e.unit),vA.endDuration(t)}visitList(e,t){return TA.startList(t),TA.endList(t)}visitStruct(e,t){return OA.startStruct_(t),OA.endStruct_(t)}visitUnion(e,t){jA.startTypeIdsVector(t,e.typeIds.length);let n=jA.createTypeIdsVector(t,e.typeIds);return jA.startUnion(t),jA.addMode(t,e.mode),jA.addTypeIds(t,n),jA.endUnion(t)}visitDictionary(e,t){let n=this.visit(e.indices,t);return fA.startDictionaryEncoding(t),fA.addId(t,BigInt(e.id)),fA.addIsOrdered(t,e.isOrdered),n!==void 0&&fA.addIndexType(t,n),fA.endDictionaryEncoding(t)}visitFixedSizeBinary(e,t){return yA.startFixedSizeBinary(t),yA.addByteWidth(t,e.byteWidth),yA.endFixedSizeBinary(t)}visitFixedSizeList(e,t){return bA.startFixedSizeList(t),bA.addListSize(t,e.listSize),bA.endFixedSizeList(t)}visitMap(e,t){return EA.startMap(t),EA.addKeysSorted(t,e.keysSorted),EA.endMap(t)}};function TL(e,t=new Map){return new _F(OL(e,t),PL(e.metadata),t)}function EL(e){return new BL(e.count,AL(e.columns),jL(e.columns))}function DL(e){return new VL(EL(e.data),e.id,e.isDelta)}function OL(e,t){return(e.fields||[]).filter(Boolean).map(e=>vF.fromJSON(e,t))}function kL(e,t){return(e.children||[]).filter(Boolean).map(e=>vF.fromJSON(e,t))}function AL(e){return(e||[]).reduce((e,t)=>[...e,new UL(t.count,ML(t.VALIDITY)),...AL(t.children)],[])}function jL(e,t=[]){for(let n=-1,r=(e||[]).length;++n<r;){let r=e[n];r.VALIDITY&&t.push(new HL(t.length,r.VALIDITY.length)),r.TYPE_ID&&t.push(new HL(t.length,r.TYPE_ID.length)),r.OFFSET&&t.push(new HL(t.length,r.OFFSET.length)),r.DATA&&t.push(new HL(t.length,r.DATA.length)),t=jL(r.children,t)}return t}function ML(e){return(e||[]).reduce((e,t)=>e+ +(t===0),0)}function NL(e,t){let n,r,i,a,o,s;return!t||!(a=e.dictionary)?(o=IL(e,kL(e,t)),i=new vF(e.name,o,e.nullable,PL(e.metadata))):t.has(n=a.id)?(r=(r=a.indexType)?FL(r):new Ej,s=new tM(t.get(n),r,n,a.isOrdered),i=new vF(e.name,s,e.nullable,PL(e.metadata))):(r=(r=a.indexType)?FL(r):new Ej,t.set(n,o=IL(e,kL(e,t))),s=new tM(o,r,n,a.isOrdered),i=new vF(e.name,s,e.nullable,PL(e.metadata))),i||null}function PL(e=[]){return new Map(e.map(({key:e,value:t})=>[e,t]))}function FL(e){return new Cj(e.isSigned,e.bitWidth)}function IL(e,t){let n=e.type.name;switch(n){case`NONE`:return new Sj;case`null`:return new Sj;case`binary`:return new Ij;case`largebinary`:return new Lj;case`utf8`:return new Rj;case`largeutf8`:return new zj;case`bool`:return new Bj;case`list`:return new Jj((t||[])[0]);case`struct`:return new Yj(t||[]);case`struct_`:return new Yj(t||[])}switch(n){case`int`:{let t=e.type;return new Cj(t.isSigned,t.bitWidth)}case`floatingpoint`:{let t=e.type;return new Mj(Gk[t.precision])}case`decimal`:{let t=e.type;return new Vj(t.scale,t.precision,t.bitWidth)}case`date`:{let t=e.type;return new Hj(Kk[t.unit])}case`time`:{let t=e.type;return new Uj(qk[t.unit],t.bitWidth)}case`timestamp`:{let t=e.type;return new Wj(qk[t.unit],t.timezone)}case`interval`:{let t=e.type;return new Kj(Jk[t.unit])}case`duration`:{let t=e.type;return new qj(qk[t.unit])}case`union`:{let n=e.type,[r,...i]=(n.mode+``).toLowerCase();return new Xj(Wk[r.toUpperCase()+i.join(``)],n.typeIds||[],t||[])}case`fixedsizebinary`:{let t=e.type;return new Zj(t.byteWidth)}case`fixedsizelist`:{let n=e.type;return new Qj(n.listSize,(t||[])[0])}case`map`:{let n=e.type;return new $j((t||[])[0],n.keysSorted)}}throw Error(`Unrecognized type: "${n}"`)}var LL=tA,RL=eA,zL=class e{static fromJSON(t,n){let r=new e(0,Uk.V5,n);return r._createHeader=WL(t,n),r}static decode(t){t=new RL(Dk(t));let n=CL.getRootAsMessage(t),r=n.bodyLength(),i=n.version(),a=n.headerType(),o=new e(r,i,a);return o._createHeader=GL(n,a),o}static encode(e){let t=new LL,n=-1;return e.isSchema()?n=_F.encode(t,e.header()):e.isRecordBatch()?n=BL.encode(t,e.header()):e.isDictionaryBatch()&&(n=VL.encode(t,e.header())),CL.startMessage(t),CL.addVersion(t,Uk.V5),CL.addHeader(t,n),CL.addHeaderType(t,e.headerType),CL.addBodyLength(t,BigInt(e.bodyLength)),CL.finishMessageBuffer(t,CL.endMessage(t)),t.asUint8Array()}static from(t,n=0){if(t instanceof _F)return new e(0,Uk.V5,IA.Schema,t);if(t instanceof BL)return new e(n,Uk.V5,IA.RecordBatch,t);if(t instanceof VL)return new e(n,Uk.V5,IA.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===IA.Schema}isRecordBatch(){return this.headerType===IA.RecordBatch}isDictionaryBatch(){return this.headerType===IA.DictionaryBatch}constructor(e,t,n,r){this._version=t,this._headerType=n,this.body=new Uint8Array,r&&(this._createHeader=()=>r),this._bodyLength=BA(e)}},BL=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=BA(e)}},VL=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=BA(t)}},HL=class{constructor(e,t){this.offset=BA(e),this.length=BA(t)}},UL=class{constructor(e,t){this.length=BA(e),this.nullCount=BA(t)}};function WL(e,t){return(()=>{switch(t){case IA.Schema:return _F.fromJSON(e);case IA.RecordBatch:return BL.fromJSON(e);case IA.DictionaryBatch:return VL.fromJSON(e)}throw Error(`Unrecognized Message type: { name: ${IA[t]}, type: ${t} }`)})}function GL(e,t){return(()=>{switch(t){case IA.Schema:return _F.decode(e.header(new FA),new Map,e.version());case IA.RecordBatch:return BL.decode(e.header(new sA),e.version());case IA.DictionaryBatch:return VL.decode(e.header(new cA),e.version())}throw Error(`Unrecognized Message type: { name: ${IA[t]}, type: ${t} }`)})}vF.encode=oR,vF.decode=tR,vF.fromJSON=NL,_F.encode=aR,_F.decode=KL,_F.fromJSON=TL,BL.encode=sR,BL.decode=qL,BL.fromJSON=EL,VL.encode=cR,VL.decode=JL,VL.fromJSON=DL,UL.encode=lR,UL.decode=XL,HL.encode=uR,HL.decode=YL;function KL(e,t=new Map,n=Uk.V5){return new _F($L(e,t),nR(e),t,n)}function qL(e,t=Uk.V5){if(e.compression()!==null)throw Error(`Record batch compression not implemented`);return new BL(e.length(),ZL(e),QL(e,t))}function JL(e,t=Uk.V5){return new VL(BL.decode(e.data(),t),e.id(),e.isDelta())}function YL(e){return new HL(e.offset(),e.length())}function XL(e){return new UL(e.length(),e.nullCount())}function ZL(e){let t=[];for(let n,r=-1,i=-1,a=e.nodesLength();++r<a;)(n=e.nodes(r))&&(t[++i]=UL.decode(n));return t}function QL(e,t){let n=[];for(let r,i=-1,a=-1,o=e.buffersLength();++i<o;)(r=e.buffers(i))&&(t<Uk.V4&&(r.bb_pos+=8*(i+1)),n[++a]=HL.decode(r));return n}function $L(e,t){let n=[];for(let r,i=-1,a=-1,o=e.fieldsLength();++i<o;)(r=e.fields(i))&&(n[++a]=vF.decode(r,t));return n}function eR(e,t){let n=[];for(let r,i=-1,a=-1,o=e.childrenLength();++i<o;)(r=e.children(i))&&(n[++a]=vF.decode(r,t));return n}function tR(e,t){let n,r,i,a,o,s;return!t||!(s=e.dictionary())?(i=iR(e,eR(e,t)),r=new vF(e.name(),i,e.nullable(),nR(e))):t.has(n=BA(s.id()))?(a=(a=s.indexType())?rR(a):new Ej,o=new tM(t.get(n),a,n,s.isOrdered()),r=new vF(e.name(),o,e.nullable(),nR(e))):(a=(a=s.indexType())?rR(a):new Ej,t.set(n,i=iR(e,eR(e,t))),o=new tM(i,a,n,s.isOrdered()),r=new vF(e.name(),o,e.nullable(),nR(e))),r||null}function nR(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 rR(e){return new Cj(e.isSigned(),e.bitWidth())}function iR(e,t){let n=e.typeType();switch(n){case NA.NONE:return new Sj;case NA.Null:return new Sj;case NA.Binary:return new Ij;case NA.LargeBinary:return new Lj;case NA.Utf8:return new Rj;case NA.LargeUtf8:return new zj;case NA.Bool:return new Bj;case NA.List:return new Jj((t||[])[0]);case NA.Struct_:return new Yj(t||[])}switch(n){case NA.Int:{let t=e.type(new dA);return new Cj(t.isSigned(),t.bitWidth())}case NA.FloatingPoint:return new Mj(e.type(new xA).precision());case NA.Decimal:{let t=e.type(new _A);return new Vj(t.scale(),t.precision(),t.bitWidth())}case NA.Date:return new Hj(e.type(new gA).unit());case NA.Time:{let t=e.type(new kA);return new Uj(t.unit(),t.bitWidth())}case NA.Timestamp:{let t=e.type(new AA);return new Wj(t.unit(),t.timezone())}case NA.Interval:return new Kj(e.type(new SA).unit());case NA.Duration:return new qj(e.type(new vA).unit());case NA.Union:{let n=e.type(new jA);return new Xj(n.mode(),n.typeIdsArray()||[],t||[])}case NA.FixedSizeBinary:return new Zj(e.type(new yA).byteWidth());case NA.FixedSizeList:return new Qj(e.type(new bA).listSize(),(t||[])[0]);case NA.Map:{let n=e.type(new EA);return new $j((t||[])[0],n.keysSorted())}}throw Error(`Unrecognized type: "${NA[n]}" (${n})`)}function aR(e,t){let n=t.fields.map(t=>vF.encode(e,t));FA.startFieldsVector(e,n.length);let r=FA.createFieldsVector(e,n),i=t.metadata&&t.metadata.size>0?FA.createCustomMetadataVector(e,[...t.metadata].map(([t,n])=>{let r=e.createString(`${t}`),i=e.createString(`${n}`);return pA.startKeyValue(e),pA.addKey(e,r),pA.addValue(e,i),pA.endKeyValue(e)})):-1;return FA.startSchema(e),FA.addFields(e,r),FA.addEndianness(e,dR?lA.Little:lA.Big),i!==-1&&FA.addCustomMetadata(e,i),FA.endSchema(e)}function oR(e,t){let n=-1,r=-1,i=-1,a=t.type,o=t.typeId;xj.isDictionary(a)?(o=a.dictionary.typeId,i=wL.visit(a,e),r=wL.visit(a.dictionary,e)):r=wL.visit(a,e);let s=(a.children||[]).map(t=>vF.encode(e,t)),c=PA.createChildrenVector(e,s),l=t.metadata&&t.metadata.size>0?PA.createCustomMetadataVector(e,[...t.metadata].map(([t,n])=>{let r=e.createString(`${t}`),i=e.createString(`${n}`);return pA.startKeyValue(e),pA.addKey(e,r),pA.addValue(e,i),pA.endKeyValue(e)})):-1;return t.name&&(n=e.createString(t.name)),PA.startField(e),PA.addType(e,r),PA.addTypeType(e,o),PA.addChildren(e,c),PA.addNullable(e,!!t.nullable),n!==-1&&PA.addName(e,n),i!==-1&&PA.addDictionary(e,i),l!==-1&&PA.addCustomMetadata(e,l),PA.endField(e)}function sR(e,t){let n=t.nodes||[],r=t.buffers||[];sA.startNodesVector(e,n.length);for(let t of n.slice().reverse())UL.encode(e,t);let i=e.endVector();sA.startBuffersVector(e,r.length);for(let t of r.slice().reverse())HL.encode(e,t);let a=e.endVector();return sA.startRecordBatch(e),sA.addLength(e,BigInt(t.length)),sA.addNodes(e,i),sA.addBuffers(e,a),sA.endRecordBatch(e)}function cR(e,t){let n=BL.encode(e,t.data);return cA.startDictionaryBatch(e),cA.addId(e,BigInt(t.id)),cA.addIsDelta(e,t.isDelta),cA.addData(e,n),cA.endDictionaryBatch(e)}function lR(e,t){return oA.createFieldNode(e,BigInt(t.length),BigInt(t.nullCount))}function uR(e,t){return aA.createBuffer(e,BigInt(t.offset),BigInt(t.length))}var dR=(()=>{let e=new ArrayBuffer(2);return new DataView(e).setInt16(0,256,!0),new Int16Array(e)[0]===256})(),fR=e=>`Expected ${IA[e]} Message in stream, but was null or length 0.`,pR=e=>`Header pointer of flatbuffer-encoded ${IA[e]} Message is null or length 0.`,mR=(e,t)=>`Expected to read ${e} metadata bytes, but only read ${t}.`,hR=(e,t)=>`Expected to read ${e} bytes for message body, but only read ${t}.`,gR=class{constructor(e){this.source=e instanceof jF?e:new jF(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?EF: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(fR(e));return t.value}readMessageBody(e){if(e<=0)return new Uint8Array;let t=Dk(this.source.read(e));if(t.byteLength<e)throw Error(hR(e,t.byteLength));return t.byteOffset%8==0&&t.byteOffset+t.byteLength<=t.buffer.byteLength?t:t.slice()}readSchema(e=!1){let t=IA.Schema,n=this.readMessage(t)?.header();if(e&&!n)throw Error(pR(t));return n}readMetadataLength(){let e=this.source.read(4),t=(e&&new eA(e))?.readInt32(0)||0;return{done:t===0,value:t}}readMetadata(e){let t=this.source.read(e);if(!t)return EF;if(t.byteLength<e)throw Error(mR(e,t.byteLength));return{done:!1,value:zL.decode(t)}}},_R=class{constructor(e,t){this.source=e instanceof MF?e:fk(e)?new IF(e,t):new MF(e)}[Symbol.asyncIterator](){return this}next(){return qO(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?EF:e})}throw(e){return qO(this,void 0,void 0,function*(){return yield this.source.throw(e)})}return(e){return qO(this,void 0,void 0,function*(){return yield this.source.return(e)})}readMessage(e){return qO(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(fR(e));return t.value})}readMessageBody(e){return qO(this,void 0,void 0,function*(){if(e<=0)return new Uint8Array;let t=Dk(yield this.source.read(e));if(t.byteLength<e)throw Error(hR(e,t.byteLength));return t.byteOffset%8==0&&t.byteOffset+t.byteLength<=t.buffer.byteLength?t:t.slice()})}readSchema(){return qO(this,arguments,void 0,function*(e=!1){let t=IA.Schema,n=(yield this.readMessage(t))?.header();if(e&&!n)throw Error(pR(t));return n})}readMetadataLength(){return qO(this,void 0,void 0,function*(){let e=yield this.source.read(4),t=(e&&new eA(e))?.readInt32(0)||0;return{done:t===0,value:t}})}readMetadata(e){return qO(this,void 0,void 0,function*(){let t=yield this.source.read(e);if(!t)return EF;if(t.byteLength<e)throw Error(mR(e,t.byteLength));return{done:!1,value:zL.decode(t)}})}},vR=class extends gR{constructor(e){super(new Uint8Array),this._schema=!1,this._body=[],this._batchIndex=0,this._dictionaryIndex=0,this._json=e instanceof DF?e:new DF(e)}next(){let{_json:e}=this;if(!this._schema)return this._schema=!0,{done:!1,value:zL.fromJSON(e.schema,IA.Schema)};if(this._dictionaryIndex<e.dictionaries.length){let t=e.dictionaries[this._dictionaryIndex++];return this._body=t.data.columns,{done:!1,value:zL.fromJSON(t,IA.DictionaryBatch)}}if(this._batchIndex<e.batches.length){let t=e.batches[this._batchIndex++];return this._body=t.columns,{done:!1,value:zL.fromJSON(t,IA.RecordBatch)}}return this._body=[],EF}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(fR(e));return t.value}readSchema(){let e=IA.Schema,t=this.readMessage(e),n=t?.header();if(!t||!n)throw Error(pR(e));return n}},yR=`ARROW1`,bR=new Uint8Array(6);for(let e=0;e<6;e+=1)bR[e]=yR.codePointAt(e);function xR(e,t=0){for(let n=-1,r=bR.length;++n<r;)if(bR[n]!==e[t+n])return!1;return!0}var SR=bR.length,CR=SR+4,wR=SR*2+4,TR=class e extends OF{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 sk(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 Fk.toDOMStream(this.isSync()?{[Symbol.iterator]:()=>this}:{[Symbol.asyncIterator]:()=>this})}toNodeStream(){return Fk.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:uk(t)?zR(t):fk(t)?HR(t):sk(t)?qO(this,void 0,void 0,function*(){return yield e.from(yield t)}):pk(t)||gk(t)||vk(t)||lk(t)?VR(new MF(t)):BR(new jF(t))}static readAll(t){return t instanceof e?t.isSync()?LR(t):RR(t):uk(t)||ArrayBuffer.isView(t)||ck(t)||dk(t)?LR(t):RR(t)}},ER=class extends TR{constructor(e){super(e),this._impl=e}readAll(){return[...this]}[Symbol.iterator](){return this._impl[Symbol.iterator]()}[Symbol.asyncIterator](){return XO(this,arguments,function*(){yield YO(yield*ZO(QO(this[Symbol.iterator]())))})}},DR=class extends TR{constructor(e){super(e),this._impl=e}readAll(){return qO(this,void 0,void 0,function*(){var e,t,n,r;let i=[];try{for(var a=!0,o=QO(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]()}},OR=class extends ER{constructor(e){super(e),this._impl=e}},kR=class extends DR{constructor(e){super(e),this._impl=e}},AR=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=AP({type:new Yj(this.schema.fields),length:e.length,children:n});return new yL(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 eF(c)):new eF(c)).memoize()}_loadVectors(e,t,n){return new GF(t,e.nodes,e.buffers,this.dictionaries,this.schema.metadataVersion).visitMany(n)}},jR=class extends AR{constructor(e,t){super(t),this._reader=uk(e)?new vR(this._handle=e):new gR(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=IR(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):EF}return(e){return!this.closed&&this.autoDestroy&&(this.closed=!0)?this.reset()._reader.return(e):EF}next(){if(this.closed)return EF;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 SL(this.schema)}):this.return()}_readNextMessageAndValidate(e){return this._reader.readMessage(e)}},MR=class extends AR{constructor(e,t){super(t),this._reader=new _R(this._handle=e)}isAsync(){return!0}isStream(){return!0}[Symbol.asyncIterator](){return this}cancel(){return qO(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 qO(this,void 0,void 0,function*(){return this.closed||(this.autoDestroy=IR(this,e),(this.schema||=yield this._reader.readSchema())||(yield this.cancel())),this})}throw(e){return qO(this,void 0,void 0,function*(){return!this.closed&&this.autoDestroy&&(this.closed=!0)?yield this.reset()._reader.throw(e):EF})}return(e){return qO(this,void 0,void 0,function*(){return!this.closed&&this.autoDestroy&&(this.closed=!0)?yield this.reset()._reader.return(e):EF})}next(){return qO(this,void 0,void 0,function*(){if(this.closed)return EF;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 SL(this.schema)}):yield this.return()})}_readNextMessageAndValidate(e){return qO(this,void 0,void 0,function*(){return yield this._reader.readMessage(e)})}},NR=class extends jR{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 FF?e:new FF(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(IA.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(IA.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-CR,n=e.readInt32(t),r=e.readAt(t-n,n);return CF.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}},PR=class extends MR{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 IF?e:new IF(e,n),r)}isFile(){return!0}isAsync(){return!0}open(e){let t=Object.create(null,{open:{get:()=>super.open}});return qO(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 qO(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(IA.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 qO(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(IA.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 qO(this,void 0,void 0,function*(){let{_handle:e}=this;e._pending&&(yield e._pending);let t=e.size-CR,n=yield e.readInt32(t),r=yield e.readAt(t-n,n);return CF.decode(r)})}_readNextMessageAndValidate(e){return qO(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})}},FR=class extends jR{constructor(e,t){super(e,t)}_loadVectors(e,t,n){return new KF(t,e.nodes,e.buffers,this.dictionaries,this.schema.metadataVersion).visitMany(n)}};function IR(e,t){return t&&typeof t.autoDestroy==`boolean`?t.autoDestroy:e.autoDestroy}function*LR(e){let t=TR.from(e);try{if(!t.open({autoDestroy:!1}).closed)do yield t;while(!t.reset().open().closed)}finally{t.cancel()}}function RR(e){return XO(this,arguments,function*(){let t=yield YO(TR.from(e));try{if(!(yield YO(t.open({autoDestroy:!1}))).closed)do yield yield YO(t);while(!(yield YO(t.reset().open())).closed)}finally{yield YO(t.cancel())}})}function zR(e){return new ER(new FR(e))}function BR(e){let t=e.peek(SR+7&-8);return t&&t.byteLength>=4?xR(t)?new OR(new NR(e.read())):new ER(new jR(e)):new ER(new jR(function*(){}()))}function VR(e){return qO(this,void 0,void 0,function*(){let t=yield e.peek(SR+7&-8);return t&&t.byteLength>=4?xR(t)?new OR(new NR(yield e.read())):new DR(new MR(e)):new DR(new MR(function(){return XO(this,arguments,function*(){})}()))})}function HR(e){return qO(this,void 0,void 0,function*(){let{size:t}=yield e.stat(),n=new IF(e,t);return t>=wR&&xR(yield n.readAt(0,SR+7&-8))?new kR(new PR(n)):new DR(new MR(n))})}var UR=class e extends rM{static assemble(...t){let n=e=>e.flatMap(e=>Array.isArray(e)?n(e):e instanceof yL?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 eF)return this.visitMany(e.data),this;let{type:t}=e;if(!xj.isDictionary(t)){let{length:n}=e;if(n>2147483647)throw RangeError(`Cannot write arrays larger than 2^31 - 1 in length`);if(xj.isUnion(t))this.nodes.push(new UL(n,0));else{let{nullCount:r}=e;xj.isNull(t)||WR.call(this,r<=0?new Uint8Array:SP(e.offset,n,e.nullBitmap)),this.nodes.push(new UL(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 WR(e){let t=e.byteLength+7&-8;return this.buffers.push(e),this.bufferRegions.push(new HL(this._byteLength,t)),this._byteLength+=t,this}function GR(e){let{type:t,length:n,typeIds:r,valueOffsets:i}=e;if(WR.call(this,r),t.mode===Wk.Sparse)return XR.call(this,e);if(t.mode===Wk.Dense){if(e.offset<=0)return WR.call(this,i),XR.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);WR.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 KR(e){let t;return e.nullCount>=e.length?WR.call(this,new Uint8Array):(t=e.values)instanceof Uint8Array?WR.call(this,SP(e.offset,e.length,t)):WR.call(this,CP(e.values))}function qR(e){return WR.call(this,e.values.subarray(0,e.length*e.stride))}function JR(e){let{length:t,values:n,valueOffsets:r}=e,i=BA(r[0]),a=BA(r[t]),o=Math.min(a-i,n.byteLength-i);return WR.call(this,Nk(-i,t+1,r)),WR.call(this,n.subarray(i,i+o)),this}function YR(e){let{length:t,valueOffsets:n}=e;if(n){let{0:r,[t]:i}=n;return WR.call(this,Nk(-r,t+1,n)),this.visit(e.children[0].slice(r,i-r))}return this.visit(e.children[0])}function XR(e){return this.visitMany(e.type.children.map((t,n)=>e.children[n]).filter(Boolean))[0]}UR.prototype.visitBool=KR,UR.prototype.visitInt=qR,UR.prototype.visitFloat=qR,UR.prototype.visitUtf8=JR,UR.prototype.visitLargeUtf8=JR,UR.prototype.visitBinary=JR,UR.prototype.visitLargeBinary=JR,UR.prototype.visitFixedSizeBinary=qR,UR.prototype.visitDate=qR,UR.prototype.visitTimestamp=qR,UR.prototype.visitTime=qR,UR.prototype.visitDecimal=qR,UR.prototype.visitList=YR,UR.prototype.visitStruct=XR,UR.prototype.visitUnion=GR,UR.prototype.visitInterval=qR,UR.prototype.visitDuration=qR,UR.prototype.visitFixedSizeList=YR,UR.prototype.visitMap=YR;var ZR=class extends OF{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 AF,this._schema=null,this._dictionaryBlocks=[],this._recordBatchBlocks=[],this._seenDictionaries=new Map,this._dictionaryDeltaOffsets=new Map,ok(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 sk(e)?e.then(e=>this.writeAll(e)):lk(e)?tz(this,e):ez(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 AF?this._sink=e:(this._sink=new AF,e&&hk(e)?this.toDOMStream({type:`bytes`}).pipeTo(e):e&&_k(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||!sL(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 _L&&!(t=e.schema)||e instanceof yL&&!(t=e.schema))return this.finish()&&void 0;if(t&&!sL(t,this._schema)){if(this._started&&this._autoDestroy)return this.close();this.reset(this._sink,t)}e instanceof yL?e instanceof SL||this._writeRecordBatch(e):e instanceof _L?this.writeAll(e.batches):ck(e)&&this.writeAll(e)}_writeMessage(e,t=8){let n=t-1,r=zL.encode(e),i=r.byteLength,a=this._writeLegacyIpcFormat?4:8,o=i+a+n&~n,s=o-i-a;return e.headerType===IA.RecordBatch?this._recordBatchBlocks.push(new TF(o,e.bodyLength,this._position)):e.headerType===IA.DictionaryBatch&&this._dictionaryBlocks.push(new TF(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=Dk(e);t&&t.byteLength>0&&(this._sink.write(t),this._position+=t.byteLength)}return this}_writeSchema(e){return this._writeMessage(zL.from(e))}_writeFooter(e){return this._writeLegacyIpcFormat?this._write(Int32Array.of(0)):this._write(Int32Array.of(-1,0))}_writeMagic(){return this._write(bR)}_writePadding(e){return e>0?this._write(new Uint8Array(e)):this}_writeRecordBatch(e){let{byteLength:t,nodes:n,bufferRegions:r,buffers:i}=UR.assemble(e),a=new BL(e.numRows,n,r),o=zL.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}=UR.assemble(new eF([e])),s=new VL(new BL(e.length,i,a),t,n),c=zL.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}},QR=class e extends ZR{static writeAll(t,n){let r=new e(n);return sk(t)?t.then(e=>r.writeAll(e)):lk(t)?tz(r,t):ez(r,t)}},$R=class e extends ZR{static writeAll(t){let n=new e;return sk(t)?t.then(e=>n.writeAll(e)):lk(t)?tz(n,t):ez(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=CF.encode(new CF(e,Uk.V5,this._recordBatchBlocks,this._dictionaryBlocks));return super._writeFooter(e)._write(t)._write(Int32Array.of(t.byteLength))._writeMagic()}};function ez(e,t){let n=t;t instanceof _L&&(n=t.batches,e.reset(void 0,t.schema));for(let t of n)e.write(t);return e.finish()}function tz(e,t){return qO(this,void 0,void 0,function*(){var n,r,i,a,o,s,c;try{for(n=!0,r=QO(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 nz(e,t=`stream`){return(t===`stream`?QR:$R).writeAll(e).toUint8Array(!0)}var rz=Object.create,iz=Object.defineProperty,az=Object.getOwnPropertyDescriptor,oz=Object.getOwnPropertyNames,sz=Object.getPrototypeOf,cz=Object.prototype.hasOwnProperty,lz=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),uz=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(let i of oz(t))!cz.call(e,i)&&i!==n&&iz(e,i,{get:()=>t[i],enumerable:!(r=az(t,i))||r.enumerable});return e},dz=(e,t,n)=>(n=e==null?{}:rz(sz(e)),uz(t||!e||!e.__esModule?iz(n,`default`,{value:e,enumerable:!0}):n,e)),fz=lz((e,t)=>{t.exports=Worker}),pz=(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))(pz||{}),mz=(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))(mz||{}),hz=(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))(hz||{}),gz=(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))(gz||{}),_z=(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))(_z||{}),vz=(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))(vz||{}),yz=class{constructor(e=2){this.level=e}log(e){e.level>=this.level&&console.log(e)}},bz=(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))(bz||{}),xz=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=TR.from(t);return console.assert(n.isSync(),`Reader is not sync`),console.assert(n.isFile(),`Reader is not file`),new _L(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 Sz(this._bindings,this._conn,n),i=await TR.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 Cz(this._bindings,this._conn,t)}async insertArrowTable(e,t){let n=nz(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)}},Sz=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}},Cz=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=TR.from(t);return console.assert(n.isSync()),console.assert(n.isFile()),new _L(n)}async send(...e){let t=await this.bindings.sendPrepared(this.connectionId,this.statementId,e),n=new Sz(this.bindings,this.connectionId,t),r=await TR.from(n);return console.assert(r.isAsync()),console.assert(r.isStream()),r}},wz=(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))(wz||{}),Tz=(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))(Tz||{}),Ez=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 Dz(e){switch(e.typeId){case Q.Binary:return{sqlType:`binary`};case Q.Bool:return{sqlType:`bool`};case Q.Date:return{sqlType:`date`};case Q.DateDay:return{sqlType:`date32[d]`};case Q.DateMillisecond:return{sqlType:`date64[ms]`};case Q.Decimal:{let t=e;return{sqlType:`decimal`,precision:t.precision,scale:t.scale}}case Q.Float:return{sqlType:`float`};case Q.Float16:return{sqlType:`float16`};case Q.Float32:return{sqlType:`float32`};case Q.Float64:return{sqlType:`float64`};case Q.Int:return{sqlType:`int32`};case Q.Int16:return{sqlType:`int16`};case Q.Int32:return{sqlType:`int32`};case Q.Int64:return{sqlType:`int64`};case Q.Uint16:return{sqlType:`uint16`};case Q.Uint32:return{sqlType:`uint32`};case Q.Uint64:return{sqlType:`uint64`};case Q.Uint8:return{sqlType:`uint8`};case Q.IntervalDayTime:return{sqlType:`interval[dt]`};case Q.IntervalYearMonth:return{sqlType:`interval[m]`};case Q.List:return{sqlType:`list`,valueType:Dz(e.valueType)};case Q.FixedSizeBinary:return{sqlType:`fixedsizebinary`,byteWidth:e.byteWidth};case Q.Null:return{sqlType:`null`};case Q.Utf8:return{sqlType:`utf8`};case Q.Struct:return{sqlType:`struct`,fields:e.children.map(e=>Oz(e.name,e.type))};case Q.Map:{let t=e;return{sqlType:`map`,keyType:Dz(t.keyType),valueType:Dz(t.valueType)}}case Q.Time:return{sqlType:`time[s]`};case Q.TimeMicrosecond:return{sqlType:`time[us]`};case Q.TimeMillisecond:return{sqlType:`time[ms]`};case Q.TimeNanosecond:return{sqlType:`time[ns]`};case Q.TimeSecond:return{sqlType:`time[s]`};case Q.Timestamp:return{sqlType:`timestamp`,timezone:e.timezone||void 0};case Q.TimestampSecond:return{sqlType:`timestamp[s]`,timezone:e.timezone||void 0};case Q.TimestampMicrosecond:return{sqlType:`timestamp[us]`,timezone:e.timezone||void 0};case Q.TimestampNanosecond:return{sqlType:`timestamp[ns]`,timezone:e.timezone||void 0};case Q.TimestampMillisecond:return{sqlType:`timestamp[ms]`,timezone:e.timezone||void 0}}throw Error(`unsupported arrow type: ${e.toString()}`)}function Oz(e,t){let n=Dz(t);return n.name=e,n}var kz=/'(opfs:\/\/\S*?)'/g,Az=/(opfs:\/\/\S*?)/g;function jz(e){return e.search(Az)>-1}function Mz(e){return[...e.matchAll(kz)].map(e=>e[1])}var Nz=new TextEncoder,Pz=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 Ez(`RESET`,null);return await this.postTask(e)}async ping(){let e=new Ez(`PING`,null);await this.postTask(e)}async dropFile(e){let t=new Ez(`DROP_FILE`,e);return await this.postTask(t)}async dropFiles(e){let t=new Ez(`DROP_FILES`,e);return await this.postTask(t)}async flushFiles(){let e=new Ez(`FLUSH_FILES`,null);return await this.postTask(e)}async instantiate(e,t=null,n=e=>{}){this._onInstantiationProgress.push(n);let r=new Ez(`INSTANTIATE`,[e,t]);return await this.postTask(r)}async getVersion(){let e=new Ez(`GET_VERSION`,null);return await this.postTask(e)}async getFeatureFlags(){let e=new Ez(`GET_FEATURE_FLAGS`,null);return await this.postTask(e)}async open(e){this._config=e;let t=new Ez(`OPEN`,e);await this.postTask(t)}async tokenize(e){let t=new Ez(`TOKENIZE`,e);return await this.postTask(t)}async connectInternal(){let e=new Ez(`CONNECT`,null);return await this.postTask(e)}async connect(){let e=await this.connectInternal();return new xz(this,e)}async disconnect(e){let t=new Ez(`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 Ez(`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 Ez(`START_PENDING_QUERY`,[e,t,n]);return await this.postTask(r)}async pollPendingQuery(e){let t=new Ez(`POLL_PENDING_QUERY`,e);return await this.postTask(t)}async cancelPendingQuery(e){let t=new Ez(`CANCEL_PENDING_QUERY`,e);return await this.postTask(t)}async fetchQueryResults(e){let t=new Ez(`FETCH_QUERY_RESULTS`,e);return await this.postTask(t)}async getTableNames(e,t){let n=new Ez(`GET_TABLE_NAMES`,[e,t]);return await this.postTask(n)}async createPrepared(e,t){let n=new Ez(`CREATE_PREPARED`,[e,t]);return await this.postTask(n)}async closePrepared(e,t){let n=new Ez(`CLOSE_PREPARED`,[e,t]);await this.postTask(n)}async runPrepared(e,t,n){let r=new Ez(`RUN_PREPARED`,[e,t,n]);return await this.postTask(r)}async sendPrepared(e,t,n){let r=new Ez(`SEND_PREPARED`,[e,t,n]);return await this.postTask(r)}async globFiles(e){let t=new Ez(`GLOB_FILE_INFOS`,e);return await this.postTask(t)}async registerFileText(e,t){let n=Nz.encode(t);await this.registerFileBuffer(e,n)}async registerFileURL(e,t,n,r){t===void 0&&(t=e);let i=new Ez(`REGISTER_FILE_URL`,[e,t,n,r]);await this.postTask(i)}async registerEmptyFileBuffer(e){}async registerFileBuffer(e,t){let n=new Ez(`REGISTER_FILE_BUFFER`,[e,t]);await this.postTask(n,[t.buffer])}async registerFileHandle(e,t,n,r){let i=new Ez(`REGISTER_FILE_HANDLE`,[e,t,n,r]);await this.postTask(i,[])}async registerOPFSFileName(e){let t=new Ez(`REGISTER_OPFS_FILE_NAME`,[e]);await this.postTask(t,[])}async collectFileStatistics(e,t){let n=new Ez(`COLLECT_FILE_STATISTICS`,[e,t]);await this.postTask(n,[])}async exportFileStatistics(e){let t=new Ez(`EXPORT_FILE_STATISTICS`,e);return await this.postTask(t,[])}async copyFileToBuffer(e){let t=new Ez(`COPY_FILE_TO_BUFFER`,e);return await this.postTask(t)}async copyFileToPath(e,t){let n=new Ez(`COPY_FILE_TO_PATH`,[e,t]);await this.postTask(n)}async insertArrowFromIPCStream(e,t,n){if(t.length==0)return;let r=new Ez(`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(Oz(t,r))}n.columnsFlat=e,delete n.columns}let r=new Ez(`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(Oz(t,r))}n.columnsFlat=e,delete n.columns}let r=new Ez(`IMPORT_JSON_FROM_PATH`,[e,t,n]);await this.postTask(r)}shouldOPFSFileHandling(){return jz(this.config.path??``)?this.config.opfs?.fileHandling==`auto`:!1}async registerOPFSFileFromSQL(e){let t=Mz(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 Fz(){let e=new TextDecoder;return t=>(typeof SharedArrayBuffer<`u`&&t.buffer instanceof SharedArrayBuffer&&(t=new Uint8Array(t)),e.decode(t))}Fz();var Iz=(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))(Iz||{}),Lz={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`}}};Lz.name,Lz.version;var Rz=Lz.version.split(`.`);Rz[0],Rz[1],Rz[2],dz(fz());var zz=``+new URL(`assets/duckdb-browser-eh.worker--3HUwN9R.js`,import.meta.url).href,Bz=``+new URL(`assets/duckdb-eh-D-nnNw7L.wasm.gz`,import.meta.url).href;async function Vz(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 Hz=null;function Uz(){return Hz||(Hz=(async()=>{let e=e=>new URL(e,location.href).href,t=URL.createObjectURL(new Blob([`importScripts(${JSON.stringify(e(zz))});`],{type:`text/javascript`})),n=new Worker(t),r=new Pz(new yz(hz.WARNING),n),i=await Vz(e(Bz));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})(),Hz)}function Wz(e){return`"`+e.replace(/"/g,`""`)+`"`}function Gz(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=Wz(e.xcol),r=Wz(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 ${Wz(e.table)} WHERE ${n} BETWEEN ? AND ? GROUP BY 1 ORDER BY 1`,params:[e.x0,t,e.maxPoints,e.x0,e.x1]}}function Kz(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=Wz(e.xcol),r=Wz(e.table);return{sql:`SELECT least(floor((${n} - ?) / ?), ? - 1) AS b, ${e.ycols.map((e,t)=>`min(${Wz(e)}) AS y${t}lo, max(${Wz(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 qz=`__kym_bin`;function Jz(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=Wz(e.xcol),n=Wz(e.srcTable);return`CREATE OR REPLACE TABLE ${Wz(e.dstTable)} AS SELECT ${`CAST(floor((${t} - ${Zz(e.x0base)}) / ${Zz(e.binWidth)}) AS BIGINT)`} AS ${qz}, ${e.ycols.map(e=>`min(${Wz(e)}) AS ${Wz(e+`__lo`)}, max(${Wz(e)}) AS ${Wz(e+`__hi`)}`).join(`, `)} FROM ${n} WHERE ${t} IS NOT NULL GROUP BY 1`}function Yz(e){let t=Wz(e.srcTable);return`CREATE OR REPLACE TABLE ${Wz(e.dstTable)} AS SELECT CAST(floor(${qz} / 2.0) AS BIGINT) AS ${qz}, ${e.ycols.map(e=>`min(${Wz(e+`__lo`)}) AS ${Wz(e+`__lo`)}, max(${Wz(e+`__hi`)}) AS ${Wz(e+`__hi`)}`).join(`, `)} FROM ${t} GROUP BY 1`}function Xz(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=Wz(e.levelTable);return{sql:`SELECT least(greatest(CAST(floor(? + ${qz} * ?) AS BIGINT), 0), ?) AS b, ${e.ycols.map((e,t)=>`min(${Wz(e+`__lo`)}) AS y${t}lo, max(${Wz(e+`__hi`)}) AS y${t}hi`).join(`, `)} FROM ${o} WHERE ${qz} BETWEEN ? AND ? GROUP BY 1 ORDER BY 1`,params:[r,n,e.maxPoints-1,i,a]}}function Zz(e){if(!Number.isFinite(e))throw Error(`num: value must be finite`);return Number.isInteger(e)?String(e):e.toExponential(17)}function Qz(e){let t=Wz(e.table);return e.range?{sql:`SELECT count(*) AS n FROM ${t} WHERE ${Wz(e.range.xcol)} BETWEEN ? AND ?`,params:[e.range.x0,e.range.x1]}:{sql:`SELECT count(*) AS n FROM ${t}`,params:[]}}function $z(e){if(!Number.isInteger(e.stride)||e.stride<1)throw Error(`buildSampleRowsSql: stride must be a positive integer`);let t=Wz(e.table),n=e.range?` WHERE ${Wz(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 eB(e){return`'`+e.replace(/'/g,`''`)+`'`}function tB(e){let t=e.columnNames.map(eB).join(`, `),n=e.delim===` `?`'\\t'`:eB(e.delim),r=e.decimalComma?`decimal_separator=',', `:``;return`SELECT * FROM read_csv(${eB(e.handle)}, header=false, skip=${e.dataStartRow}, delim=${n}, `+r+`names=[${t}], auto_type_candidates=['DOUBLE', 'VARCHAR'])`}function nB(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 rB=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}},iB=0,aB=()=>`t_${++iB}`,oB=5e4,sB=65536,cB=512,lB=2;function uB(e){return e<1?1:2**Math.floor(Math.log2(e))}var dB=class e{#e;#t;#n;#r;#i=new rB(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 Uz(),i=await r.connect(),a=await t.slice(0,256*1024).text(),o=ue(a),s=ce(a),c=fe(o,s.headerRow),l=s.unitsRow===null?``:o[s.unitsRow]??``,u=x(o[s.headerRow]??``),d=tt(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=aB(),m=tB({handle:`input.csv`,columnNames:c,delim:u,dataStartRow:s.dataStartRow,decimalComma:d});await i.query(`CREATE OR REPLACE TABLE ${Wz(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 ${Wz(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}=Gz({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 nB((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)??Kz({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/lB,a=null;for(let t of e.levels)t.binWidth<=i&&(a=t);return a?Xz({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 Uz()).connect();try{let n=Qz({table:this.#n}),r=await t.query(n.sql),i=Number(r.getChild(`n`)?.get(0)??0);if(i<oB)return null;let a=await t.query(`SELECT min(${Wz(e)}) AS lo, max(${Wz(e)}) AS hi FROM ${Wz(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(sB,uB(i));if(u<cB*2)return null;let d=++this.#c,f=[],p=u,m=0,h=`${this.#n}_p${d}_0`;await t.query(Jz({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>=cB;){p/=2,m+=1;let e=`${this.#n}_p${d}_${m}`;await t.query(Yz({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=Qz({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}=$z({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(${Wz(e)} AS DOUBLE), 'NaN'::DOUBLE) AS "c${t}"`).join(`, `),a=await this.#e.prepare(`SELECT ${i} FROM ${Wz(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(${Wz(e)}) AS lo, max(${Wz(e)}) AS hi FROM ${Wz(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 ${Wz(e)}`)}catch{}try{await this.#e.query(`DROP TABLE IF EXISTS ${Wz(this.#n)}`)}catch{}await this.#e.close()}},fB=1e8,pB=256*1024;function mB(e,t,n=0,r=fB){return e>314572800||n+t>r?`duckdb`:`memory`}function hB(e,t){let n=ue(t);t.length<e&&n.length>1&&(n=n.slice(0,-1));try{let t=ce(n.join(`
72
- `)),r=fe(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 gB=12e3;async function _B(e,t,n){let r=ce(n),i=typeof Worker>`u`?Oe(n,r):await HO({rawText:n,config:r}),a=new KO(i);return{id:e,name:t,kind:`memory`,source:a,schema:await a.getSchema(),data:i,rawText:n,parseConfig:r}}async function vB(e,t,n,r,i=e=>e.text(),a){let o=ce(r),s=typeof Worker>`u`?await UO({rawText:await i(n),config:o},a):await UO({file:n,config:o},a),c=new KO(s);return{id:e,name:t,kind:`memory`,source:c,schema:await c.getSchema(),data:s,rawText:r,file:n,parseConfig:o}}async function yB(e,t,n){let r=await dB.open(t,n),i=await r.getSchema(),a=await r.sampleRows(gB),o={meta:``,columnNames:i.map(e=>e.name),units:i.map(e=>e.unit),rows:a},s=await t.slice(0,pB).text();return{id:e,name:t.name,kind:`duckdb`,source:r,schema:i,data:o,rawText:s,parseConfig:ce(s)}}async function bB(e,t,n,r,i=0,a){let o=await t.slice(0,pB).text();return mB(t.size,hB(t.size,o),i)===`memory`?vB(e,t.name,t,o,e=>n(e),a):yB(e,t,r)}function xB(e,t){return e instanceof File&&e.name===t.name&&e.size===t.size&&e.lastModified===t.lastModified}async function SB(e,t,n){let r=n.find(e=>e.kind===`memory`&&e.parseConfig&&xB(e.file,t)&&we(e.data.rows));if(!r)return null;let i=await t.slice(0,pB).text();if(!P(r.parseConfig,ce(i)))return null;let a={...r.data,rows:Ue(we(r.data.rows))};return{id:e,name:t.name,kind:`memory`,source:new KO(a),schema:r.schema,data:a,rawText:r.rawText,file:t,parseConfig:r.parseConfig}}function CB(e){let t=new Set,n=0;for(let r of e){if(r.kind!==`memory`)continue;let e=we(r.data.rows)??r.data.rows;t.has(e)||(t.add(e),n+=r.data.rows.length*r.data.columnNames.length)}return n}var wB=4096,TB=[`.dat`,`.txt`,`.csv`,`.tsv`],EB=[V,yt,o,R,xt,xe,m,oe,ne,he,pt,nt,_,W,A,wt,pe],DB=e=>{let t=e.lastIndexOf(`.`);return t<=0?``:e.slice(t).toLowerCase()},OB=e=>{let t=e.lastIndexOf(`.`);return(t<=0?e:e.slice(0,t)).toLowerCase()};async function kB(e){let t=new Uint8Array(await e.slice(0,wB).arrayBuffer()),n=DB(e.name),r=EB.filter(e=>e.extensions.includes(n));for(let n of[...r,...EB.filter(e=>!r.includes(e))]){let r=Math.min(n.sniffBytes?.(t)??0,e.size),i=r>t.length?new Uint8Array(await e.slice(0,r).arrayBuffer()):t;if(n.sniff(i,e.name))return n}return null}async function AB(e){return new Uint8Array(await e.slice(0,wB).arrayBuffer()).includes(0)}async function jB(e){let t=await Promise.all(e.map(kB)),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]&&DB(e.name)===n.ext),o=a.find(e=>OB(e.name)===OB(i.main.name))??(n.anyName&&a.length===1?a[0]:void 0);o&&(i.companions.push(o),r.add(o))}let i=new Set(EB.flatMap(e=>(e.companions??[]).map(e=>e.ext))),a=[];for(let t of e){if(r.has(t))continue;let e=DB(t.name);e===`.xls`?a.push({file:t.name,error:Error(`${t.name}: Kymoscope reads .xlsx, not the older .xls. Save it as .xlsx in Excel and open that.`)}):e===`.dat`&&await AB(t)?a.push({file:t.name,error:Error(`This COMTRADE .dat needs its .cfg file — drop both together.`)}):TB.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 MB=[...new Set([...TB,...EB.flatMap(e=>[...e.extensions,...(e.companions??[]).map(e=>e.ext)])])];function NB(e){let t=0;for(let n=0;n<e.length;n++)e[n]!==e[n]&&t++;if(t===0)return nF(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 nF(AP({type:new Fj,data:e,nullBitmap:n,length:e.length,nullCount:t}))}var PB=122880,FB=class{#e;#t;#n;#r=!1;#i=[];#a=0;#o;rows=0;constructor(e,t,n,r=PB){this.#e=e,this.#t=t,this.#n=new _F(n.map(e=>new vF(e.name,e.text?new Rj:new Fj,!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?NB(i.subarray(0,t)):uL(i.slice(0,t),new Rj)).data[0]});this.#i.push(new yL(this.#n,AP({type:new Yj(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 _L(this.#n,this.#i);this.#i=[],this.#a=0,await this.#e.insertArrowTable(e,{name:this.#t,create:!this.#r}),this.#r=!0}},IB=`This file's groups do not interleave in time: reading them together would hold too much in memory. Choose fewer groups, or split them.`,LB=e=>e.length*(1+e.columns.length);function RB(e){let t=e[Symbol.asyncIterator]();return{pull:async()=>{let e=await t.next();return e.done?null:e.value}}}function zB(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-=LB(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+=LB(o.value))>128e6))throw Error(IB)}};return n.map((e,t)=>({pull:()=>a(t)}))}function BB(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 VB=new Int32Array,HB={t:new Float64Array,cols:[],from:0};function UB(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 WB=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=GB(BB(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(IB)}};function GB(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 KB(e,t){let n=e.length,r=e.map(e=>e.t),i=Int32Array.from(e,e=>e.from),a=Int32Array.from(e,e=>UB(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 qB(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 JB(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];qB(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}qB(e,d,u,p,l-1,c[p]),o=c[l-1],t=d[u+l-1]}e.fill(t,o,e.length)}function YB(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 XB(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):VB}function ZB(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=UB(i,e,r.from,i.length),o=new Int32Array(a-r.from);if(c.push(XB(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 YB(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),JB(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 QB(e,t,n,r,i,a=!1){let o=e.map((e,r)=>new WB(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)){let e=o.filter((e,t)=>!c[t]&&(!e.done||e.rows()>0));if(!e.length)break;for(let t of e)c[o.indexOf(t)]=!0,l.push(t);u=!1;continue}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=KB(l.map(e=>e.pending[0]??HB),e),n=[t];for(let e=0;e<o.length;e++)n.push(...ZB(o[e],t,c[e],u&&c[e],a));d+=t.length,t.length&&await r({length:t.length,columns:n})}return d}var $B=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 eV(e,t,n){return ee(await e.plan(t,n))}var tV=(e,t,n)=>Math.max(0,Math.min(e,Math.max(1<<20,n),Math.floor(1e8/t)));function nV(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=St(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 rV(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 iV(e,t,n){let r=rV(e,t);return r<0?Math.ceil(n/4):r*(1+t.reduce((e,t)=>e+t.channels.length,0))}async function aV(e,t,n,r,i,a,o={}){let s=nV(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=>RB(d(e.streamGroup({...f,selection:[t]},t.group)))):zB(d(e.stream(f)),new Map(i.map((e,t)=>[e.group,t]))),m=rV(n,i),h=a===`memory`?new $B(s,tV(m,s.length,r.size)):null,g=0,_=await QB(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 oV=!1,sV=1,cV=new Set,lV=new Map,uV=()=>oV;function dV(e){return cV.add(e),()=>{cV.delete(e)}}function fV(e){return lV.set(e,sV++),()=>{lV.delete(e)}}var pV=null;function mV(e){pV?.(e)}var hV=``+new URL(`assets/importer.worker-q_b4_xbW.js`,import.meta.url).href,gV=``+new URL(`assets/h5wasmModule-BCQWU2Gw.js`,import.meta.url).href,_V=()=>new RO(`cancelled`);function vV(){let e=zO(hV);return e.postMessage({type:`init`,h5Url:new URL(gV,location.href).href}),e}var yV=null,bV=e=>{typeof requestIdleCallback==`function`?requestIdleCallback(e,{timeout:5e3}):setTimeout(e,1e3)};function xV(e,t=vV){t===vV&&typeof Worker>`u`||(yV&&yV.make!==t&&(yV.w.terminate(),yV=null),yV??={w:t(),h5:!1,make:t},e&&!yV.h5&&(yV.h5=!0,yV.w.postMessage({type:`warm`})))}function SV(e){if(yV?.make!==e)return{w:e(),rewarm:null};let{w:t,h5:n}=yV;return yV=null,{w:t,rewarm:n}}function CV(e,t,n,r,i){return!r&&typeof Worker>`u`?wV(e,t,n,i):EV(e,t,n,r??vV)}function wV(e,t,n,r=async e=>(await import(`./importers-HtqEQxrK.js`)).importerFor(e)){let i=new Fe(t.main),a=null,o=null,s=e=>e.catch(e=>{throw n?.aborted?_V():l(e)});return{plan:()=>s((async()=>(a=await r(e),o=await eV(a,t,i)))()),read:(e,r,c={})=>(i.bytesRead=0,s(aV(a,t,o,i,e,r,{...c,signal:n}))),close(){}}}var TV=3e4;function EV(e,t,n,r){let{w:i,rewarm:a}=SV(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>TV&&(mV(Error(`The import worker stalled.`)),p(Error(z)))},1e3),h=()=>p(_V());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=>{let t=e instanceof Error?e:Error(`The import worker failed.`);mV(t),f(t)};let g=(e,t={})=>new Promise((r,a)=>{if(n?.aborted){a(_V());return}if(d){a(Error(z));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&&bV(()=>xV(a,r))}}}var DV=12e3,OV=(e,t)=>t.map(t=>({group:t,channels:e.groups[t].channels.map((e,t)=>t)}));function kV(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 AV(e,t){let n=t.filter(t=>e.groups[t.group].irregular).length;return n+ +(n<t.length)>1}function jV(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:kV(e,n),merged:AV(e,n)}:null,splitKey:r,channels:n.reduce((e,t)=>e+t.channels.length,0),notes:e.notes,meta:e.meta,events:[]}}async function MV(e,t,n,r,i,a){let o={meta:``,columnNames:n.columns.map(e=>e.name),units:n.columns.map(e=>e.unit),rows:Ue(n.table)},s=new KO(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}}}var NV=5;async function PV(e,t,n,r,i,a,o,s,c){let l=Uz().then(e=>e.connect());l.catch(()=>void 0);let u=aB(),d=nV(r,i),f=new FB({insertArrowTable:async(e,t)=>(await l).insertArrowTable(e,t)},u,d);try{let r=[],p=await n.read(i,`stream`,{progress:c,chunk:e=>{for(let t=0;t<e.length&&r.length<NV;t++)r.push(Object.fromEntries(d.map((n,r)=>{let i=e.columns[r][t];return[n.name,i===void 0||typeof i==`number`&&Number.isNaN(i)?null:i]})));return f.append(e)}});if(await f.flush(),f.rows===0)throw Error(`${t}: the file has no samples.`);let m=await l,h=await dB.attach(m,u,new Map(d.map(e=>[e.name,e.unit]))),g=await h.getSchema(),_=await h.sampleRows(DV);return{id:e,name:t,kind:`duckdb`,source:h,schema:g,data:{meta:``,columnNames:g.map(e=>e.name),units:g.map(e=>e.unit),rows:_},file:a,companions:o,info:{...s,events:p.events,preview:r}}}catch(e){let t=await l.catch(()=>null);throw await t?.query(`DROP TABLE IF EXISTS ${Wz(u)}`).catch(()=>void 0),await t?.close().catch(()=>void 0),e}}async function FV(e,t){let{main:n,companions:r}=e,i=CV(e.format,{main:n,companions:r,keys:e.keys,asTable:e.asTable},t.signal,t.createWorker,t.find),a=[];try{t.priorInMemoryValues+n.size/8>1e8&&Uz().catch(()=>void 0);let o=await i.plan(),s=t.selection??t.initial??o.defaultSelection??OV(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=>iV(o,e,n.size),budget:fB,used:t.priorInMemoryValues,notes:o.notes});if(!e)throw new RO(`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=iV(o,s,n.size),f=l.length>1?`${n.name} · ${o.groups[s[0].group].name}`:n.name,p=jV(o,e.format,s,u),m=crypto.randomUUID();if(mB(0,c,d)===`memory`){let e=await i.read(s,`memory`,{progress:t.onProgress});a.push(await MV(m,f,e,n,r,p)),d+=c}else a.push(await PV(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 RO(`cancelled`):e}finally{i.close()}}function IV(e){return e.filter(e=>e.type===`number`).map(e=>e.name)}function LV(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 RV(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 zV(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 BV(e){return Math.max(2,Math.min(6,Math.floor(e/64)))}function VV(e,t,n,r){let i=Math.max(e,t)-Math.min(e,t),a=n!==void 0&&n>0&&Number.isFinite(n)?n:zV(i,6);(a<=0||!Number.isFinite(a))&&(a=zV(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 HV(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 UV(e,t,n,r,i=120){let a=HV(e,t,n);return a.length<=i?{step:n,ticks:a}:{step:r,ticks:HV(e,t,r)}}function WV(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 GV={[-12]:`p`,[-9]:`n`,[-6]:`µ`,[-3]:`m`,0:``,3:`k`,6:`M`,9:`G`,12:`T`};function KV(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 qV(e,t){if(!Number.isFinite(e))return`—`;if(!(t>0)||!Number.isFinite(t))return JV(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(KV(t/10**r))+GV[r]}return e.toFixed(KV(t))}function JV(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)+GV[n]}var YV=946684800,XV=4102444800;function ZV(e,t,n){return/\(([^)]*)\)\s*$/.exec(e)?.[1].trim()===`s`&&n>t&&t>=YV&&n<=XV}var QV=new Map;function $V(e){let t=QV.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=$V(void 0)}QV.set(e,t)}return t}var eH=new Map,tH=(e,t)=>{let n=Math.round(e*1e3),r=Math.floor(n/1e3),i=`${t??``}|${r}`,a=eH.get(i);if(!a){let e={};for(let{type:n,value:i}of $V(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}`},eH.size>=1024&&eH.clear(),eH.set(i,a)}return{...a,ms:String(n-r*1e3).padStart(3,`0`)}},nH,rH=new Set;function iH(e){if(e!==void 0)try{new Intl.DateTimeFormat(void 0,{timeZone:e})}catch{e=void 0}if(e!==nH){nH=e;for(let e of rH)e()}}var aH=()=>nH;function oH(e){return rH.add(e),()=>{rH.delete(e)}}function sH(e,t,n,r=nH){let i=tH(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 cH(e,t=nH){let n=tH(e,t);return`${n.date} ${n.year} ${n.hms}.${n.ms}`}var lH=[`#fb923c`,`#60a5fa`,`#4ade80`,`#f87171`,`#facc15`,`#22d3ee`,`#f472b6`,`#2dd4bf`,`#94a3b8`,`#a3e635`];function uH(e,t,n,r=lH){let i=r.length>0?r:lH;return e[t]??i[n%i.length]}function dH(e){return[e===`light`?`#000000`:`#ffffff`,...lH.slice(0,9)]}function fH(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:dH(t)}var pH=[`class`,`data-theme`,`data-color-scheme`];function mH(e){return e?.closest(`[data-color-scheme]`)??document.documentElement}function hH(e){return mH(e).getAttribute(`data-color-scheme`)===`light`?`light`:`dark`}function gH(e,t){let n=new MutationObserver(t),r=new Set([document.documentElement,mH(e)]);for(let e of r)n.observe(e,{attributes:!0,attributeFilter:pH});return()=>n.disconnect()}function _H(e,t){return!!t&&e.composedPath().includes(t)}var vH=[{value:`span`,label:`Span (max − min)`},{value:`mean`,label:`Mean`},{value:`max`,label:`Max`},{value:`min`,label:`Min`}];function yH(e,t){let n=[],r=aD(),i=-1;for(let a=0;a<e.length;a++){let o=e[a][t];if(typeof o!=`number`)continue;let s=oD(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 bH(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=yH(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 xH(e,t){return bH(e,t)[0]??t[0]??``}function SH(e,t,n){if(n&&t.includes(n.channel)&&yH(e,n.channel).length>1)return{...n,metric:t.includes(n.metric)?n.metric:n.channel};let r=t.find(t=>CH.test(t)&&yH(e,t).length>1);if(r)return{channel:r,metric:t.find(e=>wH.test(e))??r,stat:`span`};let i=bH(e,t.filter(e=>!EH(e))).filter(t=>!DH(e,t));if(i.length===0)return null;let a=i.find(e=>/time/i.test(e));return{channel:i[0],metric:a??i[0],stat:`span`}}var CH=/^step[ _]?(index|number|no|id)?$/i,wH=/^(test[ _]?time|time)\b/i,TH=new Set([`seq`,`sequence`,`count`,`counter`,`cnt`,`stamp`,`nanosec`,`nanosecs`,`nsec`,`nsecs`]);function EH(e){let t=e.replace(/([a-z\d])([A-Z])/g,`$1 $2`).toLowerCase().split(/[^a-z\d]+/).filter(Boolean),n=t[t.length-1]??``;return t.some(e=>TH.has(e))||n===`sec`||n===`secs`||/^[bw]\d+$/.test(n)||t.includes(`raw`)&&t.some(e=>/^[bw]\d*$/.test(e))}function DH(e,t){let n=new Set(yH(e,t).slice(1).map(e=>e.start)),r=null,i=!/lap|dist/i.test(t),a=!0,o=null;for(let s=0;s<e.length;s++){let c=e[s][t];if(typeof c==`number`){if(n.has(s)?(o===null||!OH(o,c))&&(a=!1):i&&o!==null&&c>o&&((!Number.isInteger(c)||r!==null&&c-o!==r)&&(i=!1),r=c-o),!i&&!a)return!1;o=c}}return i&&r!==null||a}function OH(e,t){if(e<250)return!1;let n=e>=98e7&&e<=1e9?1e9:e>=98e4&&e<=1e6?1e6:2**Math.ceil(Math.log2(e+1));return e>=.98*n&&Math.abs(t)<=.02*n}function kH(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 AH(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 jH(e,t){return t.trim()===`s`||/time/i.test(e)}function MH(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?JV(e):e.toFixed(r>=1e3?0:r>=100?1:3);return t.trim()?`${i} ${t.trim()}`:i}function NH(e,t){return`${e}::lap${t}`}var PH=(e,t,n)=>`kymoscope-workbook-export|3|${e}|${t??``}|${n??``}`,FH=e=>new TextEncoder().encode(e);async function IH(e,t){return{format:`kymoscope-workbook`,v:2,...await We(t,FH(JSON.stringify(e)),v)}}async function LH(e,t){let n=t.password?JSON.stringify(await IH(e,t.password)):JSON.stringify(e),r=await Te(await b(t.key),FH(n),PH(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 RH(e){return!!e&&typeof e==`object`&&e.format===`kymoscope-workbook`}function zH(e){return RH(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 BH=e=>{try{return JSON.parse(new TextDecoder().decode(e))}catch{throw new RO(`bad_file`)}};async function VH(e,t){let n=zH(e);if(!n)throw new RO(`bad_file`);let r=e;if(n.v===3){let i=e;if(!t.key)throw new RO(`scope_key_required`,{scope:n.scope,scopeId:n.scopeId});let a;try{a=await de(await b(t.key),i,PH(i.scope,i.scope_id,i.inner))}catch{throw new RO(`bad_file`)}if(r=BH(a),!n.password)return r;if(r?.v!==2||!RH(r))throw new RO(`bad_file`)}if(!t.password)throw new RO(`password_required`);let i;try{i=await N(t.password,r,v)}catch{throw new RO(`wrong_password`)}return BH(i)}var HH=new Set(Object.keys(cn));function UH(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`||!HH.has(n)||!r||![r.x,r.y,r.w,r.h].every(e=>typeof e==`number`&&Number.isFinite(e))?[]:[{...e,rect:dn(n,r,96)}]}):[]}var WH=e=>({name:e.name,xKey:e.xKey,panels:e.panels,panelChartSettings:e.panelChartSettings,panelChartBackgrounds:e.panelChartBackgrounds,...e.liveWindowSeconds===void 0?{}:{liveWindowSeconds:e.liveWindowSeconds}});function GH(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 KH(e){return{version:2,worksheets:e.worksheets.map(e=>({...WH(e),panelChartSettings:GH(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,...e.cycles?.length?{cycles:e.cycles}:{}}}function qH(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 JH(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 YH(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 XH(e){let t=await YH(e),n;try{n=JSON.parse(t)}catch{return{worksheets:[],errors:[`Not a valid JSON file.`]}}return nU(n)}var ZH=new Set(vH.map(e=>e.value)),QH=/^(#(?:[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 $H(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):QH.test(e.trim())}function eU(e){if(Array.isArray(e))return e.map(eU);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`&&!$H(r)||(t[n]=r&&typeof r==`object`?eU(r):r);return t}function tU(e){return!e||typeof e!=`object`?{}:Object.fromEntries(Object.entries(e).filter(([,e])=>e===null||$H(e)))}function nU(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,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:UH(n.panels),panelChartSettings:eU(n.panelChartSettings),panelChartBackgrounds:tU(n.panelChartBackgrounds),...wr(n.liveWindowSeconds)})}),n===1)return{worksheets:r,errors:i,activeIndex:0,mathChannels:[],liveWindowSeconds:void 0,laps: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`&&ZH.has(s.stat)?{channel:s.channel,metric:s.metric,stat:s.stat}:null,l=typeof t.activeWorksheet==`number`&&Number.isInteger(t.activeWorksheet)?t.activeWorksheet:0;return{worksheets:r,errors:i,mathChannels:a,laps:c,cycles:wD(t.cycles),activeIndex:Math.min(Math.max(0,l),Math.max(0,r.length-1)),liveWindowSeconds:o===null||typeof o==`number`&&o>0?o:void 0}}function rU(e){return e.some(e=>e.panels.length>0)}function iU(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:UH(t.panels),panelChartSettings:eU(t.panelChartSettings),panelChartBackgrounds:tU(t.panelChartBackgrounds),...wr(t.liveWindowSeconds)}}function aU(e){if(!e||typeof e!=`object`)return null;let t=e,n=t.kind;if(typeof n!=`string`||!HH.has(n))return null;let r=xr({__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 oU(e){let t=await YH(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=zH(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=iU(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=aU(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 XH(e);return i.worksheets.length===0&&i.errors.length>0?{type:`error`,errors:i.errors}:{type:`workspace`,worksheets:i.worksheets,errors:i.errors}}var sU=MB;function cU(e){let t=e.toLowerCase();return!t.startsWith(`.`)&&sU.some(e=>t.endsWith(e))}function lU(e,t=``){let n={name:t,path:``,dirs:[],files:[],allPaths:[]};for(let t of e){if(!cU(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 uU(e){return e.map(e=>({path:e.webkitRelativePath||e.name,file:e}))}async function dU(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 fU(){return typeof window.showDirectoryPicker==`function`}async function pU(){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 mU={1:`dohstRIUBeOkkAXOTXhhEkXanWzz-V4M518JBqTehRM`},hU={r1:`lWen4RopUWVWch58Omp3llhyAituoKAVtk6Fbt-4n1M`},gU=Object.freeze({...hU});Object.freeze(hU);var _U=Object.freeze([]);function vU(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}var yU=e=>e.toLowerCase().replace(/\.$/,``).replace(/^\[(.*)\]$/,`$1`);function bU(e,t){let n=yU(e),r=yU(t);return n.startsWith(`*.`)?r.endsWith(n.slice(1))&&r.length>n.length-1:n===r}function xU(e,t){let n=yU(e),r=yU(t);return r.startsWith(`*.`)?n.startsWith(`*.`)&&r.slice(1).endsWith(n.slice(1)):bU(n,r)}function SU(e,t){return(e.mod[`embed.license`]===!0?[...e.hosts,...e.sdk_domains??[]]:e.hosts).some(e=>xU(e,t))}function CU(e){try{let t=JSON.parse(new TextDecoder().decode(vU(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`||t.chain!==void 0&&typeof t.chain!=`string`?null:t}catch{return null}}async function wU(e,t,n,r,i=gU){if(!e)return{ok:!1,reason:`missing`};if(typeof e!=`string`)return{ok:!1,reason:`malformed`};let a=e.trim().split(`.`);if(a.length!==2||!a[0]||!a[1])return{ok:!1,reason:`malformed`};let o=CU(a[0]);if(!o)return{ok:!1,reason:`malformed`};let s,c;if(o.chain!==void 0){let e=await NU(o.chain,r,i,{ignoreExp:!0});if(!e.ok)return{ok:!1,reason:`bad_signature`};if(e.licence.exp+2592e3<r)return{ok:!1,reason:`expired`};c=e.licence,s=c.site_pub}else{let e=o.kid??`1`;s=typeof n==`string`?n:Object.hasOwn(n,e)?n[e]:void 0}if(!s)return{ok:!1,reason:`bad_signature`};let l;try{let e=await crypto.subtle.importKey(`raw`,vU(s),`Ed25519`,!1,[`verify`]);l=await crypto.subtle.verify(`Ed25519`,e,vU(a[1]),new TextEncoder().encode(a[0]))}catch{return{ok:!1,reason:`unsupported`}}if(!l)return{ok:!1,reason:`bad_signature`};if(o.exp<r)return{ok:!1,reason:`expired`};if(!o.domains.some(e=>bU(e,t)))return{ok:!1,reason:`domain`};let u=c;return u&&!o.domains.every(e=>SU(u,e))?{ok:!1,reason:`domain`}:{ok:!0,sub:o.sub,exp:o.exp}}function TU(e,t){return wU(e,t,mU,Date.now()/1e3)}var EU=/^[A-Za-z0-9_-]{43}$/,DU=[`free`,`start`,`pro`,`team`,`enterprise`],OU=e=>!!e&&typeof e==`object`&&!Array.isArray(e),kU=e=>Array.isArray(e)&&e.length>0&&e.every(e=>typeof e==`string`&&e);function AU(e){try{let t=JSON.parse(new TextDecoder().decode(vU(e.trim().split(`.`)[0])));return OU(t)?t:null}catch{return null}}async function jU(e,t){if(typeof e!=`string`)return`malformed`;let n=e.trim().split(`.`);if(n.length!==2||!n[0]||!n[1])return`malformed`;let r=AU(e);if(!r)return`malformed`;if(!t||!EU.test(t))return null;try{let e=await crypto.subtle.importKey(`raw`,vU(t),`Ed25519`,!1,[`verify`]);return await crypto.subtle.verify(`Ed25519`,e,vU(n[1]),new TextEncoder().encode(n[0]))?r:null}catch{return null}}function MU(e,t){return typeof e==`boolean`?e===!1||t===!0:e===null?t===null:typeof e==`number`?t===null||typeof t==`number`&&e<=t:typeof e==`string`?e===t:!1}async function NU(e,t,n=gU,r={}){if(typeof e!=`string`)return{ok:!1,reason:`malformed`};let i=AU(e);if(!i)return{ok:!1,reason:`malformed`};let a=e=>typeof e==`string`&&Object.hasOwn(n,e)?n[e]:void 0,o=null;if(i.iss!==void 0){let e=await jU(i.iss,a(typeof i.iss==`string`?AU(i.iss)?.kid:void 0));if(e===`malformed`)return{ok:!1,reason:`malformed`};if(!e)return{ok:!1,reason:`bad_signature`};if(e.typ!==`issuer`||typeof e.pub!=`string`||!OU(e.max_mod)||typeof e.max_seats!=`number`||typeof e.exp!=`number`||!DU.includes(e.max_plan)||!kU(e.max_hosts))return{ok:!1,reason:`malformed`};if((r.revoked??_U).includes(e.pub))return{ok:!1,reason:`revoked`};o=e}let s=await jU(e,o?o.pub:a(i.kid));if(s===`malformed`)return{ok:!1,reason:`malformed`};if(!s)return{ok:!1,reason:`bad_signature`};if(s.typ!==`site`||typeof s.lic!=`string`||typeof s.org!=`string`||s.plan!==`team`&&s.plan!==`enterprise`||!OU(s.mod)||!Number.isInteger(s.seats)||s.seats<1||typeof s.site_pub!=`string`||!EU.test(s.site_pub)||typeof s.exp!=`number`||!kU(s.hosts)||s.sdk_domains!==void 0&&!kU(s.sdk_domains))return{ok:!1,reason:`malformed`};if(o){let e=o.max_mod;if(s.exp>o.exp||s.seats>o.max_seats||DU.indexOf(s.plan)>DU.indexOf(o.max_plan)||!Object.entries(s.mod).every(([t,n])=>Object.hasOwn(e,t)&&MU(n,e[t]))||![...s.hosts,...s.sdk_domains??[]].every(e=>o.max_hosts.some(t=>xU(t,e))))return{ok:!1,reason:`issuer_scope`}}if(!r.ignoreExp&&s.exp<t)return{ok:!1,reason:`expired`};let{lic:c,org:l,plan:u,mod:d,seats:f,site_pub:p,exp:m,hosts:h,sdk_domains:g}=s;return{ok:!0,licence:{lic:c,org:l,plan:u,mod:d,seats:f,site_pub:p,exp:m,hosts:h,...g?{sdk_domains:g}:{}}}}var $={sans:`system-ui, sans-serif`,mono:`ui-monospace, monospace`};function PU(e){let t=e.getTransform().a||1;e.font=`13px ${$.sans}`,e.textAlign=`center`,e.textBaseline=`middle`,e.fillText(`No data to plot`,e.canvas.width/t/2,e.canvas.height/t/2)}function FU(){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 IU(){return Gt(`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 `,J(`strong`,{style:{color:`var(--accent, #f5a524)`,fontWeight:700},children:`Kymoscope`})]})}function LU(){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 RU(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 zU(e){return Math.max(0,(e>>1)-1)}var BU=2.5,VU=`#version 300 es
72
+ `)),r=fe(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 gB=12e3;async function _B(e,t,n){let r=ce(n),i=typeof Worker>`u`?Oe(n,r):await HO({rawText:n,config:r}),a=new KO(i);return{id:e,name:t,kind:`memory`,source:a,schema:await a.getSchema(),data:i,rawText:n,parseConfig:r}}async function vB(e,t,n,r,i=e=>e.text(),a){let o=ce(r),s=typeof Worker>`u`?await UO({rawText:await i(n),config:o},a):await UO({file:n,config:o},a),c=new KO(s);return{id:e,name:t,kind:`memory`,source:c,schema:await c.getSchema(),data:s,rawText:r,file:n,parseConfig:o}}async function yB(e,t,n){let r=await dB.open(t,n),i=await r.getSchema(),a=await r.sampleRows(gB),o={meta:``,columnNames:i.map(e=>e.name),units:i.map(e=>e.unit),rows:a},s=await t.slice(0,pB).text();return{id:e,name:t.name,kind:`duckdb`,source:r,schema:i,data:o,rawText:s,parseConfig:ce(s)}}async function bB(e,t,n,r,i=0,a){let o=await t.slice(0,pB).text();return mB(t.size,hB(t.size,o),i)===`memory`?vB(e,t.name,t,o,e=>n(e),a):yB(e,t,r)}function xB(e,t){return e instanceof File&&e.name===t.name&&e.size===t.size&&e.lastModified===t.lastModified}async function SB(e,t,n){let r=n.find(e=>e.kind===`memory`&&e.parseConfig&&xB(e.file,t)&&we(e.data.rows));if(!r)return null;let i=await t.slice(0,pB).text();if(!P(r.parseConfig,ce(i)))return null;let a={...r.data,rows:Ue(we(r.data.rows))};return{id:e,name:t.name,kind:`memory`,source:new KO(a),schema:r.schema,data:a,rawText:r.rawText,file:t,parseConfig:r.parseConfig}}function CB(e){let t=new Set,n=0;for(let r of e){if(r.kind!==`memory`)continue;let e=we(r.data.rows)??r.data.rows;t.has(e)||(t.add(e),n+=r.data.rows.length*r.data.columnNames.length)}return n}var wB=4096,TB=[`.dat`,`.txt`,`.csv`,`.tsv`],EB=[V,yt,o,R,xt,xe,m,oe,ne,he,pt,nt,_,W,A,wt,pe],DB=e=>{let t=e.lastIndexOf(`.`);return t<=0?``:e.slice(t).toLowerCase()},OB=e=>{let t=e.lastIndexOf(`.`);return(t<=0?e:e.slice(0,t)).toLowerCase()};async function kB(e){let t=new Uint8Array(await e.slice(0,wB).arrayBuffer()),n=DB(e.name),r=EB.filter(e=>e.extensions.includes(n));for(let n of[...r,...EB.filter(e=>!r.includes(e))]){let r=Math.min(n.sniffBytes?.(t)??0,e.size),i=r>t.length?new Uint8Array(await e.slice(0,r).arrayBuffer()):t;if(n.sniff(i,e.name))return n}return null}async function AB(e){return new Uint8Array(await e.slice(0,wB).arrayBuffer()).includes(0)}async function jB(e){let t=await Promise.all(e.map(kB)),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]&&DB(e.name)===n.ext),o=a.find(e=>OB(e.name)===OB(i.main.name))??(n.anyName&&a.length===1?a[0]:void 0);o&&(i.companions.push(o),r.add(o))}let i=new Set(EB.flatMap(e=>(e.companions??[]).map(e=>e.ext))),a=[];for(let t of e){if(r.has(t))continue;let e=DB(t.name);e===`.xls`?a.push({file:t.name,error:Error(`${t.name}: Kymoscope reads .xlsx, not the older .xls. Save it as .xlsx in Excel and open that.`)}):e===`.dat`&&await AB(t)?a.push({file:t.name,error:Error(`This COMTRADE .dat needs its .cfg file — drop both together.`)}):TB.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 MB=[...new Set([...TB,...EB.flatMap(e=>[...e.extensions,...(e.companions??[]).map(e=>e.ext)])])];function NB(e){let t=0;for(let n=0;n<e.length;n++)e[n]!==e[n]&&t++;if(t===0)return nF(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 nF(AP({type:new Fj,data:e,nullBitmap:n,length:e.length,nullCount:t}))}var PB=122880,FB=class{#e;#t;#n;#r=!1;#i=[];#a=0;#o;rows=0;constructor(e,t,n,r=PB){this.#e=e,this.#t=t,this.#n=new _F(n.map(e=>new vF(e.name,e.text?new Rj:new Fj,!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?NB(i.subarray(0,t)):uL(i.slice(0,t),new Rj)).data[0]});this.#i.push(new yL(this.#n,AP({type:new Yj(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 _L(this.#n,this.#i);this.#i=[],this.#a=0,await this.#e.insertArrowTable(e,{name:this.#t,create:!this.#r}),this.#r=!0}},IB=`This file's groups do not interleave in time: reading them together would hold too much in memory. Choose fewer groups, or split them.`,LB=e=>e.length*(1+e.columns.length);function RB(e){let t=e[Symbol.asyncIterator]();return{pull:async()=>{let e=await t.next();return e.done?null:e.value}}}function zB(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-=LB(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+=LB(o.value))>128e6))throw Error(IB)}};return n.map((e,t)=>({pull:()=>a(t)}))}function BB(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 VB=new Int32Array,HB={t:new Float64Array,cols:[],from:0};function UB(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 WB=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=GB(BB(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(IB)}};function GB(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 KB(e,t){let n=e.length,r=e.map(e=>e.t),i=Int32Array.from(e,e=>e.from),a=Int32Array.from(e,e=>UB(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 qB(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 JB(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];qB(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}qB(e,d,u,p,l-1,c[p]),o=c[l-1],t=d[u+l-1]}e.fill(t,o,e.length)}function YB(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 XB(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):VB}function ZB(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=UB(i,e,r.from,i.length),o=new Int32Array(a-r.from);if(c.push(XB(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 YB(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),JB(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 QB(e,t,n,r,i,a=!1){let o=e.map((e,r)=>new WB(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)){let e=o.filter((e,t)=>!c[t]&&(!e.done||e.rows()>0));if(!e.length)break;for(let t of e)c[o.indexOf(t)]=!0,l.push(t);u=!1;continue}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=KB(l.map(e=>e.pending[0]??HB),e),n=[t];for(let e=0;e<o.length;e++)n.push(...ZB(o[e],t,c[e],u&&c[e],a));d+=t.length,t.length&&await r({length:t.length,columns:n})}return d}var $B=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 eV(e,t,n){return ee(await e.plan(t,n))}var tV=(e,t,n)=>Math.max(0,Math.min(e,Math.max(1<<20,n),Math.floor(1e8/t)));function nV(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=St(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 rV(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 iV(e,t,n){let r=rV(e,t);return r<0?Math.ceil(n/4):r*(1+t.reduce((e,t)=>e+t.channels.length,0))}async function aV(e,t,n,r,i,a,o={}){let s=nV(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=>RB(d(e.streamGroup({...f,selection:[t]},t.group)))):zB(d(e.stream(f)),new Map(i.map((e,t)=>[e.group,t]))),m=rV(n,i),h=a===`memory`?new $B(s,tV(m,s.length,r.size)):null,g=0,_=await QB(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 oV=!1,sV=1,cV=new Set,lV=new Map,uV=()=>oV;function dV(e){return cV.add(e),()=>{cV.delete(e)}}function fV(e){return lV.set(e,sV++),()=>{lV.delete(e)}}var pV=null;function mV(e){pV?.(e)}var hV=``+new URL(`assets/importer.worker-CR894E2t.js`,import.meta.url).href,gV=``+new URL(`assets/h5wasmModule-BCQWU2Gw.js`,import.meta.url).href,_V=()=>new RO(`cancelled`);function vV(){let e=zO(hV);return e.postMessage({type:`init`,h5Url:new URL(gV,location.href).href}),e}var yV=null,bV=e=>{typeof requestIdleCallback==`function`?requestIdleCallback(e,{timeout:5e3}):setTimeout(e,1e3)};function xV(e,t=vV){t===vV&&typeof Worker>`u`||(yV&&yV.make!==t&&(yV.w.terminate(),yV=null),yV??={w:t(),h5:!1,make:t},e&&!yV.h5&&(yV.h5=!0,yV.w.postMessage({type:`warm`})))}function SV(e){if(yV?.make!==e)return{w:e(),rewarm:null};let{w:t,h5:n}=yV;return yV=null,{w:t,rewarm:n}}function CV(e,t,n,r,i){return!r&&typeof Worker>`u`?wV(e,t,n,i):EV(e,t,n,r??vV)}function wV(e,t,n,r=async e=>(await import(`./importers-C-91tcBn.js`)).importerFor(e)){let i=new Fe(t.main),a=null,o=null,s=e=>e.catch(e=>{throw n?.aborted?_V():l(e)});return{plan:()=>s((async()=>(a=await r(e),o=await eV(a,t,i)))()),read:(e,r,c={})=>(i.bytesRead=0,s(aV(a,t,o,i,e,r,{...c,signal:n}))),close(){}}}var TV=3e4;function EV(e,t,n,r){let{w:i,rewarm:a}=SV(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>TV&&(mV(Error(`The import worker stalled.`)),p(Error(z)))},1e3),h=()=>p(_V());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=>{let t=e instanceof Error?e:Error(`The import worker failed.`);mV(t),f(t)};let g=(e,t={})=>new Promise((r,a)=>{if(n?.aborted){a(_V());return}if(d){a(Error(z));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&&bV(()=>xV(a,r))}}}var DV=12e3,OV=(e,t)=>t.map(t=>({group:t,channels:e.groups[t].channels.map((e,t)=>t)}));function kV(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 AV(e,t){let n=t.filter(t=>e.groups[t.group].irregular).length;return n+ +(n<t.length)>1}function jV(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:kV(e,n),merged:AV(e,n)}:null,splitKey:r,channels:n.reduce((e,t)=>e+t.channels.length,0),notes:e.notes,meta:e.meta,events:[]}}async function MV(e,t,n,r,i,a){let o={meta:``,columnNames:n.columns.map(e=>e.name),units:n.columns.map(e=>e.unit),rows:Ue(n.table)},s=new KO(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}}}var NV=5;async function PV(e,t,n,r,i,a,o,s,c){let l=Uz().then(e=>e.connect());l.catch(()=>void 0);let u=aB(),d=nV(r,i),f=new FB({insertArrowTable:async(e,t)=>(await l).insertArrowTable(e,t)},u,d);try{let r=[],p=await n.read(i,`stream`,{progress:c,chunk:e=>{for(let t=0;t<e.length&&r.length<NV;t++)r.push(Object.fromEntries(d.map((n,r)=>{let i=e.columns[r][t];return[n.name,i===void 0||typeof i==`number`&&Number.isNaN(i)?null:i]})));return f.append(e)}});if(await f.flush(),f.rows===0)throw Error(`${t}: the file has no samples.`);let m=await l,h=await dB.attach(m,u,new Map(d.map(e=>[e.name,e.unit]))),g=await h.getSchema(),_=await h.sampleRows(DV);return{id:e,name:t,kind:`duckdb`,source:h,schema:g,data:{meta:``,columnNames:g.map(e=>e.name),units:g.map(e=>e.unit),rows:_},file:a,companions:o,info:{...s,events:p.events,preview:r}}}catch(e){let t=await l.catch(()=>null);throw await t?.query(`DROP TABLE IF EXISTS ${Wz(u)}`).catch(()=>void 0),await t?.close().catch(()=>void 0),e}}async function FV(e,t){let{main:n,companions:r}=e,i=CV(e.format,{main:n,companions:r,keys:e.keys,asTable:e.asTable},t.signal,t.createWorker,t.find),a=[];try{t.priorInMemoryValues+n.size/8>1e8&&Uz().catch(()=>void 0);let o=await i.plan(),s=t.selection??t.initial??o.defaultSelection??OV(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=>iV(o,e,n.size),budget:fB,used:t.priorInMemoryValues,notes:o.notes});if(!e)throw new RO(`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=iV(o,s,n.size),f=l.length>1?`${n.name} · ${o.groups[s[0].group].name}`:n.name,p=jV(o,e.format,s,u),m=crypto.randomUUID();if(mB(0,c,d)===`memory`){let e=await i.read(s,`memory`,{progress:t.onProgress});a.push(await MV(m,f,e,n,r,p)),d+=c}else a.push(await PV(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 RO(`cancelled`):e}finally{i.close()}}function IV(e){return e.filter(e=>e.type===`number`).map(e=>e.name)}function LV(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 RV(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 zV(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 BV(e){return Math.max(2,Math.min(6,Math.floor(e/64)))}function VV(e,t,n,r){let i=Math.max(e,t)-Math.min(e,t),a=n!==void 0&&n>0&&Number.isFinite(n)?n:zV(i,6);(a<=0||!Number.isFinite(a))&&(a=zV(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 HV(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 UV(e,t,n,r,i=120){let a=HV(e,t,n);return a.length<=i?{step:n,ticks:a}:{step:r,ticks:HV(e,t,r)}}function WV(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 GV={[-12]:`p`,[-9]:`n`,[-6]:`µ`,[-3]:`m`,0:``,3:`k`,6:`M`,9:`G`,12:`T`};function KV(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 qV(e,t){if(!Number.isFinite(e))return`—`;if(!(t>0)||!Number.isFinite(t))return JV(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(KV(t/10**r))+GV[r]}return e.toFixed(KV(t))}function JV(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)+GV[n]}var YV=946684800,XV=4102444800;function ZV(e,t,n){return/\(([^)]*)\)\s*$/.exec(e)?.[1].trim()===`s`&&n>t&&t>=YV&&n<=XV}var QV=new Map;function $V(e){let t=QV.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=$V(void 0)}QV.set(e,t)}return t}var eH=new Map,tH=(e,t)=>{let n=Math.round(e*1e3),r=Math.floor(n/1e3),i=`${t??``}|${r}`,a=eH.get(i);if(!a){let e={};for(let{type:n,value:i}of $V(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}`},eH.size>=1024&&eH.clear(),eH.set(i,a)}return{...a,ms:String(n-r*1e3).padStart(3,`0`)}},nH,rH=new Set;function iH(e){if(e!==void 0)try{new Intl.DateTimeFormat(void 0,{timeZone:e})}catch{e=void 0}if(e!==nH){nH=e;for(let e of rH)e()}}var aH=()=>nH;function oH(e){return rH.add(e),()=>{rH.delete(e)}}function sH(e,t,n,r=nH){let i=tH(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 cH(e,t=nH){let n=tH(e,t);return`${n.date} ${n.year} ${n.hms}.${n.ms}`}var lH=[`#fb923c`,`#60a5fa`,`#4ade80`,`#f87171`,`#facc15`,`#22d3ee`,`#f472b6`,`#2dd4bf`,`#94a3b8`,`#a3e635`];function uH(e,t,n,r=lH){let i=r.length>0?r:lH;return e[t]??i[n%i.length]}function dH(e){return[e===`light`?`#000000`:`#ffffff`,...lH.slice(0,9)]}function fH(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:dH(t)}var pH=[`class`,`data-theme`,`data-color-scheme`];function mH(e){return e?.closest(`[data-color-scheme]`)??document.documentElement}function hH(e){return mH(e).getAttribute(`data-color-scheme`)===`light`?`light`:`dark`}function gH(e,t){let n=new MutationObserver(t),r=new Set([document.documentElement,mH(e)]);for(let e of r)n.observe(e,{attributes:!0,attributeFilter:pH});return()=>n.disconnect()}function _H(e,t){return!!t&&e.composedPath().includes(t)}var vH=[{value:`span`,label:`Span (max − min)`},{value:`mean`,label:`Mean`},{value:`max`,label:`Max`},{value:`min`,label:`Min`}];function yH(e,t){let n=[],r=aD(),i=-1;for(let a=0;a<e.length;a++){let o=e[a][t];if(typeof o!=`number`)continue;let s=oD(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 bH(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=yH(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 xH(e,t){return bH(e,t)[0]??t[0]??``}function SH(e,t,n){if(n&&t.includes(n.channel)&&yH(e,n.channel).length>1)return{...n,metric:t.includes(n.metric)?n.metric:n.channel};let r=t.find(t=>CH.test(t)&&yH(e,t).length>1);if(r)return{channel:r,metric:t.find(e=>wH.test(e))??r,stat:`span`};let i=bH(e,t.filter(e=>!EH(e))).filter(t=>!DH(e,t));if(i.length===0)return null;let a=i.find(e=>/time/i.test(e));return{channel:i[0],metric:a??i[0],stat:`span`}}var CH=/^step[ _]?(index|number|no|id)?$/i,wH=/^(test[ _]?time|time)\b/i,TH=new Set([`seq`,`sequence`,`count`,`counter`,`cnt`,`stamp`,`nanosec`,`nanosecs`,`nsec`,`nsecs`]);function EH(e){let t=e.replace(/([a-z\d])([A-Z])/g,`$1 $2`).toLowerCase().split(/[^a-z\d]+/).filter(Boolean),n=t[t.length-1]??``;return t.some(e=>TH.has(e))||n===`sec`||n===`secs`||/^[bw]\d+$/.test(n)||t.includes(`raw`)&&t.some(e=>/^[bw]\d*$/.test(e))}function DH(e,t){let n=new Set(yH(e,t).slice(1).map(e=>e.start)),r=null,i=!/lap|dist/i.test(t),a=!0,o=null;for(let s=0;s<e.length;s++){let c=e[s][t];if(typeof c==`number`){if(n.has(s)?(o===null||!OH(o,c))&&(a=!1):i&&o!==null&&c>o&&((!Number.isInteger(c)||r!==null&&c-o!==r)&&(i=!1),r=c-o),!i&&!a)return!1;o=c}}return i&&r!==null||a}function OH(e,t){if(e<250)return!1;let n=e>=98e7&&e<=1e9?1e9:e>=98e4&&e<=1e6?1e6:2**Math.ceil(Math.log2(e+1));return e>=.98*n&&Math.abs(t)<=.02*n}function kH(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 AH(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 jH(e,t){return t.trim()===`s`||/time/i.test(e)}function MH(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?JV(e):e.toFixed(r>=1e3?0:r>=100?1:3);return t.trim()?`${i} ${t.trim()}`:i}function NH(e,t){return`${e}::lap${t}`}var PH=(e,t,n)=>`kymoscope-workbook-export|3|${e}|${t??``}|${n??``}`,FH=e=>new TextEncoder().encode(e);async function IH(e,t){return{format:`kymoscope-workbook`,v:2,...await We(t,FH(JSON.stringify(e)),v)}}async function LH(e,t){let n=t.password?JSON.stringify(await IH(e,t.password)):JSON.stringify(e),r=await Te(await b(t.key),FH(n),PH(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 RH(e){return!!e&&typeof e==`object`&&e.format===`kymoscope-workbook`}function zH(e){return RH(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 BH=e=>{try{return JSON.parse(new TextDecoder().decode(e))}catch{throw new RO(`bad_file`)}};async function VH(e,t){let n=zH(e);if(!n)throw new RO(`bad_file`);let r=e;if(n.v===3){let i=e;if(!t.key)throw new RO(`scope_key_required`,{scope:n.scope,scopeId:n.scopeId});let a;try{a=await de(await b(t.key),i,PH(i.scope,i.scope_id,i.inner))}catch{throw new RO(`bad_file`)}if(r=BH(a),!n.password)return r;if(r?.v!==2||!RH(r))throw new RO(`bad_file`)}if(!t.password)throw new RO(`password_required`);let i;try{i=await N(t.password,r,v)}catch{throw new RO(`wrong_password`)}return BH(i)}var HH=new Set(Object.keys(cn));function UH(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`||!HH.has(n)||!r||![r.x,r.y,r.w,r.h].every(e=>typeof e==`number`&&Number.isFinite(e))?[]:[{...e,rect:dn(n,r,96)}]}):[]}var WH=e=>({name:e.name,xKey:e.xKey,panels:e.panels,panelChartSettings:e.panelChartSettings,panelChartBackgrounds:e.panelChartBackgrounds,...e.liveWindowSeconds===void 0?{}:{liveWindowSeconds:e.liveWindowSeconds}});function GH(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 KH(e){return{version:2,worksheets:e.worksheets.map(e=>({...WH(e),panelChartSettings:GH(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,...e.cycles?.length?{cycles:e.cycles}:{}}}function qH(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 JH(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 YH(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 XH(e){let t=await YH(e),n;try{n=JSON.parse(t)}catch{return{worksheets:[],errors:[`Not a valid JSON file.`]}}return nU(n)}var ZH=new Set(vH.map(e=>e.value)),QH=/^(#(?:[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 $H(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):QH.test(e.trim())}function eU(e){if(Array.isArray(e))return e.map(eU);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`&&!$H(r)||(t[n]=r&&typeof r==`object`?eU(r):r);return t}function tU(e){return!e||typeof e!=`object`?{}:Object.fromEntries(Object.entries(e).filter(([,e])=>e===null||$H(e)))}function nU(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,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:UH(n.panels),panelChartSettings:eU(n.panelChartSettings),panelChartBackgrounds:tU(n.panelChartBackgrounds),...wr(n.liveWindowSeconds)})}),n===1)return{worksheets:r,errors:i,activeIndex:0,mathChannels:[],liveWindowSeconds:void 0,laps: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`&&ZH.has(s.stat)?{channel:s.channel,metric:s.metric,stat:s.stat}:null,l=typeof t.activeWorksheet==`number`&&Number.isInteger(t.activeWorksheet)?t.activeWorksheet:0;return{worksheets:r,errors:i,mathChannels:a,laps:c,cycles:wD(t.cycles),activeIndex:Math.min(Math.max(0,l),Math.max(0,r.length-1)),liveWindowSeconds:o===null||typeof o==`number`&&o>0?o:void 0}}function rU(e){return e.some(e=>e.panels.length>0)}function iU(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:UH(t.panels),panelChartSettings:eU(t.panelChartSettings),panelChartBackgrounds:tU(t.panelChartBackgrounds),...wr(t.liveWindowSeconds)}}function aU(e){if(!e||typeof e!=`object`)return null;let t=e,n=t.kind;if(typeof n!=`string`||!HH.has(n))return null;let r=xr({__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 oU(e){let t=await YH(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=zH(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=iU(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=aU(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 XH(e);return i.worksheets.length===0&&i.errors.length>0?{type:`error`,errors:i.errors}:{type:`workspace`,worksheets:i.worksheets,errors:i.errors}}var sU=MB;function cU(e){let t=e.toLowerCase();return!t.startsWith(`.`)&&sU.some(e=>t.endsWith(e))}function lU(e,t=``){let n={name:t,path:``,dirs:[],files:[],allPaths:[]};for(let t of e){if(!cU(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 uU(e){return e.map(e=>({path:e.webkitRelativePath||e.name,file:e}))}async function dU(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 fU(){return typeof window.showDirectoryPicker==`function`}async function pU(){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 mU={1:`dohstRIUBeOkkAXOTXhhEkXanWzz-V4M518JBqTehRM`},hU={r1:`lWen4RopUWVWch58Omp3llhyAituoKAVtk6Fbt-4n1M`},gU=Object.freeze({...hU});Object.freeze(hU);var _U=Object.freeze([]);function vU(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}var yU=e=>e.toLowerCase().replace(/\.$/,``).replace(/^\[(.*)\]$/,`$1`);function bU(e,t){let n=yU(e),r=yU(t);return n.startsWith(`*.`)?r.endsWith(n.slice(1))&&r.length>n.length-1:n===r}function xU(e,t){let n=yU(e),r=yU(t);return r.startsWith(`*.`)?n.startsWith(`*.`)&&r.slice(1).endsWith(n.slice(1)):bU(n,r)}function SU(e,t){return(e.mod[`embed.license`]===!0?[...e.hosts,...e.sdk_domains??[]]:e.hosts).some(e=>xU(e,t))}function CU(e){try{let t=JSON.parse(new TextDecoder().decode(vU(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`||t.chain!==void 0&&typeof t.chain!=`string`?null:t}catch{return null}}async function wU(e,t,n,r,i=gU){if(!e)return{ok:!1,reason:`missing`};if(typeof e!=`string`)return{ok:!1,reason:`malformed`};let a=e.trim().split(`.`);if(a.length!==2||!a[0]||!a[1])return{ok:!1,reason:`malformed`};let o=CU(a[0]);if(!o)return{ok:!1,reason:`malformed`};let s,c;if(o.chain!==void 0){let e=await NU(o.chain,r,i,{ignoreExp:!0});if(!e.ok)return{ok:!1,reason:`bad_signature`};if(e.licence.exp+2592e3<r)return{ok:!1,reason:`expired`};c=e.licence,s=c.site_pub}else{let e=o.kid??`1`;s=typeof n==`string`?n:Object.hasOwn(n,e)?n[e]:void 0}if(!s)return{ok:!1,reason:`bad_signature`};let l;try{let e=await crypto.subtle.importKey(`raw`,vU(s),`Ed25519`,!1,[`verify`]);l=await crypto.subtle.verify(`Ed25519`,e,vU(a[1]),new TextEncoder().encode(a[0]))}catch{return{ok:!1,reason:`unsupported`}}if(!l)return{ok:!1,reason:`bad_signature`};if(o.exp<r)return{ok:!1,reason:`expired`};if(!o.domains.some(e=>bU(e,t)))return{ok:!1,reason:`domain`};let u=c;return u&&!o.domains.every(e=>SU(u,e))?{ok:!1,reason:`domain`}:{ok:!0,sub:o.sub,exp:o.exp}}function TU(e,t){return wU(e,t,mU,Date.now()/1e3)}var EU=/^[A-Za-z0-9_-]{43}$/,DU=[`free`,`start`,`pro`,`team`,`enterprise`],OU=e=>!!e&&typeof e==`object`&&!Array.isArray(e),kU=e=>Array.isArray(e)&&e.length>0&&e.every(e=>typeof e==`string`&&e);function AU(e){try{let t=JSON.parse(new TextDecoder().decode(vU(e.trim().split(`.`)[0])));return OU(t)?t:null}catch{return null}}async function jU(e,t){if(typeof e!=`string`)return`malformed`;let n=e.trim().split(`.`);if(n.length!==2||!n[0]||!n[1])return`malformed`;let r=AU(e);if(!r)return`malformed`;if(!t||!EU.test(t))return null;try{let e=await crypto.subtle.importKey(`raw`,vU(t),`Ed25519`,!1,[`verify`]);return await crypto.subtle.verify(`Ed25519`,e,vU(n[1]),new TextEncoder().encode(n[0]))?r:null}catch{return null}}function MU(e,t){return typeof e==`boolean`?e===!1||t===!0:e===null?t===null:typeof e==`number`?t===null||typeof t==`number`&&e<=t:typeof e==`string`?e===t:!1}async function NU(e,t,n=gU,r={}){if(typeof e!=`string`)return{ok:!1,reason:`malformed`};let i=AU(e);if(!i)return{ok:!1,reason:`malformed`};let a=e=>typeof e==`string`&&Object.hasOwn(n,e)?n[e]:void 0,o=null;if(i.iss!==void 0){let e=await jU(i.iss,a(typeof i.iss==`string`?AU(i.iss)?.kid:void 0));if(e===`malformed`)return{ok:!1,reason:`malformed`};if(!e)return{ok:!1,reason:`bad_signature`};if(e.typ!==`issuer`||typeof e.pub!=`string`||!OU(e.max_mod)||typeof e.max_seats!=`number`||typeof e.exp!=`number`||!DU.includes(e.max_plan)||!kU(e.max_hosts))return{ok:!1,reason:`malformed`};if((r.revoked??_U).includes(e.pub))return{ok:!1,reason:`revoked`};o=e}let s=await jU(e,o?o.pub:a(i.kid));if(s===`malformed`)return{ok:!1,reason:`malformed`};if(!s)return{ok:!1,reason:`bad_signature`};if(s.typ!==`site`||typeof s.lic!=`string`||typeof s.org!=`string`||s.plan!==`team`&&s.plan!==`enterprise`||!OU(s.mod)||!Number.isInteger(s.seats)||s.seats<1||typeof s.site_pub!=`string`||!EU.test(s.site_pub)||typeof s.exp!=`number`||!kU(s.hosts)||s.sdk_domains!==void 0&&!kU(s.sdk_domains))return{ok:!1,reason:`malformed`};if(o){let e=o.max_mod;if(s.exp>o.exp||s.seats>o.max_seats||DU.indexOf(s.plan)>DU.indexOf(o.max_plan)||!Object.entries(s.mod).every(([t,n])=>Object.hasOwn(e,t)&&MU(n,e[t]))||![...s.hosts,...s.sdk_domains??[]].every(e=>o.max_hosts.some(t=>xU(t,e))))return{ok:!1,reason:`issuer_scope`}}if(!r.ignoreExp&&s.exp<t)return{ok:!1,reason:`expired`};let{lic:c,org:l,plan:u,mod:d,seats:f,site_pub:p,exp:m,hosts:h,sdk_domains:g}=s;return{ok:!0,licence:{lic:c,org:l,plan:u,mod:d,seats:f,site_pub:p,exp:m,hosts:h,...g?{sdk_domains:g}:{}}}}var $={sans:`system-ui, sans-serif`,mono:`ui-monospace, monospace`};function PU(e){let t=e.getTransform().a||1;e.font=`13px ${$.sans}`,e.textAlign=`center`,e.textBaseline=`middle`,e.fillText(`No data to plot`,e.canvas.width/t/2,e.canvas.height/t/2)}function FU(){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 IU(){return Gt(`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 `,J(`strong`,{style:{color:`var(--accent, #f5a524)`,fontWeight:700},children:`Kymoscope`})]})}function LU(){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 RU(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 zU(e){return Math.max(0,(e>>1)-1)}var BU=2.5,VU=`#version 300 es
73
73
  in vec2 a_corner; // static quad corner: (±1, ±1)
74
74
  in vec2 a_a; // per-instance: segment start (CSS px)
75
75
  in vec2 a_b; // per-instance: segment end (CSS px)
@@ -611,7 +611,7 @@ void main() {
611
611
  `));return a.filter(t=>e.has(t.id))},[a,x]),C=zt(()=>{if(!b)return null;let e=[...i.map(e=>{let t=m[e.id];return t?{...e.data,rows:t}:e.data}),...f.connections.filter(e=>r.includes(e.id)).map(e=>e.dataset)];if(S.length===0)return{dataset:b,partRows:e.map(e=>e.rows),parts:e};let t=e.map(e=>zE(e,S,d)),n=new Set(t.flatMap(e=>e.ok.map(e=>e.id))),a=S.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:b,partRows:o,parts:e};let c=a.filter(e=>!b.columnNames.includes(e.name));return{dataset:{meta:b.meta,columnNames:[...b.columnNames,...c.map(e=>e.name)],units:[...b.units,...c.map(e=>e.units)],rows:o.length===1?o[0]:[].concat(...o)},partRows:o,parts:e,okByPart:s}},[b,i,m,f.connections,r,S,d]),w=C?.dataset??null,T=zt(()=>{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]),E=T.length>1,D=zt(()=>T.length===1?G$(T[0]):void 0,[T]),O=zt(()=>T.length===1?G$(T[0],!0):void 0,[T]),k=C?.partRows??H$;G(()=>{let e=i.filter(e=>e.kind!==`memory`);if(e.length===0)return;if(!n||!g){h(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 NK(`sampleRows`,()=>n.sampleRows(V$,t));return[e.id,r]}catch{return null}}));if(t)return;let i={};for(let e of r)e&&(i[e[0]]=e[1]);h(i)})()},150);return()=>{t=!0,clearTimeout(r)}},[i,n,d,g]);let A=zt(()=>w?.columnNames.join(`
612
612
  `)??``,[w]),j=a.map(e=>e.name).join(`
613
613
  `),M=zt(()=>{let e=i.filter(e=>e.kind!==`memory`).flatMap(e=>IV(e.schema));return e.length?e:null},[i]),N=zt(()=>i.some(e=>e.kind!==`memory`)||!_&&i.some(e=>e.data.rows.length>B$),[i,_]),P=zt(()=>x$(f.connections.filter(e=>r.includes(e.id)),i.length,N,d,o),[N,i,f.connections,r,o,d]),F=zt(()=>{if(!_||i.length===0||N)return null;let e=i.map((e,t)=>{let n=e.data.rows;return{rows:n.length>0&&typeof n[0][d]==`number`?n:k[t]??n,offset:o[e.id]??0}});if(!P)for(let t of f.connections)r.includes(t.id)&&e.push({rows:t.dataset.rows,offset:o[t.id]??0});return Q$(e,d)},[_,i,N,k,o,d,f.connections,r,P]),I=C&&`okByPart`in C?C.okByPart:void 0,L=zt(()=>{if(!N)return[];let e=T.map((e,t)=>({live:`live`in e&&!!e.live,source:`live`in e&&e.live?e.live.source:e.source,columnSet:new Set(`live`in e&&e.live?e.data.columnNames:e.schema.map(e=>e.name)),keySuffix:E?`__${t}`:``,xOffset:o[e.id]??0,key:`${e.id}|${E?t:``}`}));return T.forEach((t,n)=>{let r=I?.[n],i=k[n];`live`in t&&t.live||!r?.length||!i||e.push({...e[n],live:!1,source:Y$(i,r,d),columnSet:new Set([d,...r]),key:`${e[n].key}|channels`})}),e},[N,T,E,o,I,k,d]),R=zt(()=>{let e=C?.parts??(w?[w]:[]),t=new Set;for(let n of e)for(let e of w$(n.columnNames,n.rows))t.add(e);let n=w?w.columnNames.filter(e=>t.has(e)):[],r=[...new Set(M?[...n,...M]:n)];if(j===``)return r;let i=new Set(r),a=j.split(`
614
- `).filter(e=>!i.has(e));return a.length?[...r,...a]:r},[A,j,M]),z=zt(()=>{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]),B=zt(()=>{let e={};if(!w||N)return e;for(let[t,n]of JSON.parse(z)){let r=[];if(n.length>0)if(!E)r.push(p(w.rows,d,n,B$));else{let e=Math.max(1,Math.floor(B$/T.length));for(let t=0;t<T.length;t++){let i=T[t];if(P&&`live`in i&&i.live)continue;let a=k[t]??i.data.rows;r.push(p(a,d,n,e,`__${t}`,o[i.id]??0))}}e[t]=r}return e},[w,z,d,E,T,o,k,P,N]),V=zt(()=>{let e={};if(!w)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=>Z$(e,i),l;if(!E)l=a(r);else{let e=a(r);l=[];for(let t=0;t<T.length;t++){let n=uH(s,T[t].id,t,c);for(let r of e)l.push({...r,id:`${r.id}__${t}`,column:`${r.column}__${t}`,color:n})}}let f=B[t.id]??[],p=E&&n?.kind===`multiband`&&n.envelope?r.flatMap(e=>{let t=v$(f.flatMap((t,n)=>{let r=t.cols.get(`${e.column}__${n}`);return r?[{x:t.x,y:r}]:[]}),q$);return t?[{seriesId:e.id,color:e.color,...t}]:[]}):void 0,m=T.flatMap((e,t)=>`bands`in e&&e.bands?P$(e,d,r,E?uH(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},[w,l,u,d,E,T,s,c,o,B]),ee=zt(()=>{let e={pts:{},colorMeta:{},datasetColors:{}};if(!w)return e;let t={},r={},i={},a=G$,o=T.map((e,t)=>({id:e.id,rows:k[t]??m[e.id]??e.data.rows,full:a(e)})),f={id:`single`,rows:w.rows,full:T.length===1?a(T[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(E){let{cols:r,colors:a}=aq(o,l,p,{xKey:d,viewXRange:n,colorOverrides:s,palette:c});t[e.id]=r,i[e.id]=a;continue}let m=iq(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}},[w,l,u,n,d,E,T,m,s,c,k]),te=q(new Map),H=zt(()=>{let e={};if(!w)return e;let t={length:0,x:[],y:[],z:[]},{rows:r}=w,i=D;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=ZK(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=te.current.get(a.id);l?.length!==s*c&&te.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=ZK(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?ZK(r,s,i):void 0,p=c?ZK(r,c,i):void 0,m=l?ZK(r,l,i):void 0;if(!f||!p||!m){e[a.id]={points:t};continue}let h=n?ZK(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},[w,l,u,n,d,D]),ne=zt(()=>{let e={};if(!w)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&&QK(w.rows,n.histColumn,D)||new Float64Array}return e},[w,l,u,D]),re=zt(()=>{let e={};if(!w)return e;for(let t of l){if(t.kind!==`polar`)continue;let n=u[t.id],r=n?.kind===`polar`&&n.polarAngleCol?ZK(w.rows,n.polarAngleCol,D):void 0,i=n?.kind===`polar`&&n.polarRadiusCol?ZK(w.rows,n.polarRadiusCol,D):void 0;e[t.id]=r&&i?{angles:r,radii:i}:{angles:[],radii:[]}}return e},[w,l,u,D]),U=(e,t)=>{if(!E)return{rows:e,full:O};let n=K$(T,I,t);if(n<0)return{rows:[]};let r=T[n];return{rows:k[n]??m[r.id]??r.data.rows,full:G$(r,!0)}},W=(e,t,n,r)=>{let{rows:i,full:a}=U(e,t),o=t&&QK(i,t,a)||new Float64Array,s=n?ZK(i,n,a):void 0;return{signal:o,rate:s&&tq(s)||parseFloat(r)||1}},ie=zt(()=>{let e={};if(!w)return e;for(let t of l){if(t.kind!==`spectrum`)continue;let n=u[t.id];n?.kind===`spectrum`&&(e[t.id]=W(w.rows,n.specSignalCol,n.specTimeCol,n.specSampleRate))}return e},[w,l,u,O,E,T,k,m,I]),ae=zt(()=>{let e={};if(!w)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?eq(w.rows,n.boxValueCol,n.boxGroupCol||void 0,D):[]}return e},[w,l,u,D]),oe=zt(()=>{let e={};if(!w)return e;for(let t of l){if(t.kind!==`spectrogram`)continue;let n=u[t.id];if(n?.kind!==`spectrogram`)continue;let r=w.rows,i=U(r,n.sgSignalCol),a=n.sgSignalCol?$K(i.rows,n.sgSignalCol,n.sgTimeCol||d,i.full):void 0;e[t.id]={...W(r,n.sgSignalCol,n.sgTimeCol,n.sgSampleRate),...a}}return e},[w,l,u,O,d,E,T,k,m,I]),se=zt(()=>{if(!w)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=w.rows,i=n.hmColumns.flatMap(e=>{let t=ZK(r,e,D);return t?[{name:e,v:t}]:[]}),a=i.reduce((e,t)=>Math.min(e,t.v.length),i.length?1/0:0),o=ZK(r,d,D),s,c;if(n.hmSpacing===`values`){o&&DX(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&&DX(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=>R.includes(e));if(r.length<2){e[t.id]={cells:[],xLabels:r,yLabels:r};continue}let i=r.map(e=>{let t=[];for(let n of w.rows){let r=n[e];typeof r==`number`&&Number.isFinite(r)&&t.push(r)}return t}),a=i.map(e=>e.reduce((e,t)=>e+t,0)/(e.length||1)),o=[];for(let e=0;e<r.length;e++)for(let t=0;t<r.length;t++){let n=i[e],s=i[t],c=a[e],l=a[t],u=Math.min(n.length,s.length),d=0,f=0,p=0;for(let e=0;e<u;e++){let t=n[e]-c,r=s[e]-l;d+=t*r,f+=t*t,p+=r*r}let m=f>0&&p>0?d/Math.sqrt(f*p):+(e===t);o.push({x:r[t],y:r[e],value:m})}e[t.id]={cells:o,xLabels:r,yLabels:r}}else if(n.hmMode===`binned`||n.hmMode===`count`){let{hmXCol:r,hmYCol:i}=n,a=n.hmMode===`count`?``:n.hmValueCol;if(!r||!i||n.hmMode===`binned`&&!a){e[t.id]={cells:[],xLabels:[],yLabels:[]};continue}let o=e=>{let t=parseFloat(e);return Number.isFinite(t)?t:void 0};e[t.id]=L$(w.rows,{xCol:r,yCol:i,valueCol:a,xBins:n.hmXBins,yBins:n.hmYBins,xMin:o(n.hmXMin),xMax:o(n.hmXMax),yMin:o(n.hmYMin),yMax:o(n.hmYMax)})}else{let{hmXCol:r,hmYCol:i,hmValueCol:a}=n;if(!r||!i||!a){e[t.id]={cells:[],xLabels:[],yLabels:[]};continue}let o=new Map,s=new Set,c=new Set;for(let e of w.rows){let t=String(e[r]??``),n=String(e[i]??``),l=e[a];if(typeof l!=`number`||!Number.isFinite(l))continue;s.add(t),c.add(n);let u=`${t}\0${n}`,d=o.get(u)??{sum:0,count:0};o.set(u,{sum:d.sum+l,count:d.count+1})}let l=e=>{let t=[...e];return t.every(e=>e.trim()!==``&&Number.isFinite(Number(e)))?t.sort((e,t)=>Number(e)-Number(t)):t.sort()},u=l(s),d=l(c),f,p;if(n.hmSpacing===`values`){let e=Float64Array.from(u,Number),t=Float64Array.from(d,Number);DX(e)&&(f=e),DX(t)&&(d=[...d].reverse(),p=t.reverse())}let m=[];for(let e of d)for(let t of u){let n=o.get(`${t}\0${e}`);m.push({x:t,y:e,value:n?n.sum/n.count:0})}e[t.id]={cells:m,xLabels:u,yLabels:d,xCentres:f,yCentres:p}}}return e},[w,l,u,R,d,D]),ce=zt(()=>{let e={};if(!w)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?eq(w.rows,n.vlValueCol,n.vlGroupCol||void 0,D):[]}return e},[w,l,u,D]),le=zt(()=>{let e={};if(!w)return e;let{rows:t}=w;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=D?.get(i),s=D?.get(a);if(o&&s){e[n.id]={actual:o,predicted:s};continue}let c=[],l=[];for(let e of t){let t=e[i],n=e[a];t!==void 0&&n!==void 0&&(c.push(t),l.push(n))}e[n.id]={actual:c,predicted:l}}return e},[w,l,u,D]),ue=zt(()=>{let e={};if(!w)return e;for(let t of l){if(t.kind!==`roc`)continue;let n=u[t.id],r=n?.kind===`roc`&&n.rocScoreCol?ZK(w.rows,n.rocScoreCol,D):void 0,i=n?.kind===`roc`&&n.rocLabelCol?ZK(w.rows,n.rocLabelCol,D):void 0;e[t.id]=r&&i?{scores:r,labels:i}:{scores:[],labels:[]}}return e},[w,l,u,D]),de=zt(()=>{let e={};if(!w)return e;let{rows:t}=w;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:ZK(t,e,D)??new Float64Array,axis:r})),c=s[0]?.values.length??t.length,l=i&&ZK(t,i,D)||Float64Array.from({length:c},(e,t)=>t);e[n.id]={xValues:l,series:s}}return e},[w,l,u,D]),fe=zt(()=>{let e={};if(!w)return e;let{rows:t}=w;for(let n of l){if(n.kind!==`controlchart`)continue;let r=u[n.id],i=r?.kind===`controlchart`&&r.ccValueCol?ZK(t,r.ccValueCol,D):void 0;if(!r||r.kind!==`controlchart`||!i){e[n.id]={length:0,value:[]};continue}let a=0;for(let e=0;e<i.length;e++)i[e]-i[e]===0&&a++;let o=a===i.length?null:new Uint32Array(a),s=o?new Float64Array(a):i;if(o)for(let e=0,t=0;e<i.length;e++)i[e]-i[e]===0&&(o[t]=e,s[t++]=i[e]);let c=r.ccSubgroupCol,l=c?D?.get(c):void 0,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},[w,l,u,D]),pe=zt(()=>{let e={};if(!w)return e;let{rows:t}=w;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=>ZK(t,e,D)??new Float64Array),a=Math.min(...i.map(e=>e.length)),o={length:a,columns:i},s=r.pcColorByCol;if(s)if(R.includes(s))o.colorValue=ZK(t,s,D);else{let e=new Map,n=new Int32Array(a);for(let r=0;r<a;r++){let i=String(t[r]?.[s]??``),a=e.get(i);a===void 0&&e.set(i,a=e.size),n[r]=a}o.colorIndex=n,o.colorLabels=[...e.keys()]}e[n.id]=o}return e},[w,l,u,R,D]),me=zt(()=>{let e={};if(!w)return e;let{rows:t}=w,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=ZK(t,a,D),f=ZK(t,o,D);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`&&R.includes(s))m.colorValue=ZK(t,s,D);else{let e=D?.get(s),n=new Map,r=new Int32Array(p);for(let i=0;i<p;i++){let a=String(e?e[i]:t[i]?.[s]??``),o=n.get(a);o===void 0&&n.set(a,o=n.size),r[i]=o}m.colorIndex=r,m.colorLabels=[...n.keys()]}if(l){let e=D?.get(l);m.label=e?t=>String(e[t]):e=>String(t[e]?.[l]??``)}e[r.id]=m}return e},[w,l,u,R,D]),he=zt(()=>{if(!w)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 w.rows){let t=String(e[n.fgNameCol]??``),i=n.fgParentCol?String(e[n.fgParentCol]??``):``,a=e[n.fgValueCol];!t||typeof a!=`number`||!Number.isFinite(a)||r.push({name:t,parent:i,value:a})}e[t.id]=r}return e},[w,l,u]),ge=zt(()=>{if(!w)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 w.rows){let t=String(e[n.bcCategoryCol]??`(blank)`);i.has(t)||i.set(t,r.map(()=>0));let a=new Map,o=i.get(t);for(let t=0;t<r.length;t++){let n=e[r[t]];typeof n==`number`&&Number.isFinite(n)&&(o[t]+=n),a.set(r[t],(a.get(r[t])??0)+1)}}e[t.id]={groups:Array.from(i.entries()).map(([e,t])=>({label:e,values:t})),seriesNames:r}}else{let n=w.rows,i=r.map(e=>ZK(n,e,D)),a=i.reduce((e,t)=>t?Math.min(e,t.length):e,1/0),o=Number.isFinite(a)?a:n.length,s=i.map(e=>e??new Float64Array(o).fill(NaN));e[t.id]={groups:[],columns:{length:o,values:s},seriesNames:r}}}return e},[w,l,u,D]),_e=zt(()=>{let e={};if(!w)return e;let{rows:t}=w;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=>ZK(t,e,D));if(r.rdGroupCol){let o=r.rdGroupCol,s=D?.get(o),c=s?s.length:t.length,l=new Map;for(let e=0;e<c;e++){let n=s?s[e]===s[e]?String(s[e]):`(blank)`:String(t[e][o]??`(blank)`),r=l.get(n);r||l.set(n,r=i.map(()=>0));for(let t=0;t<i.length;t++){let n=a[t]?.[e]??NaN;n-n===0&&(r[t]+=n)}}e[n.id]={axes:i,series:Array.from(l.entries()).map(([e,t])=>({name:e,values:t}))}}else{let t=a.map(e=>{let t=0,n=0;if(e)for(let r=0;r<e.length;r++)e[r]-e[r]===0&&(t+=e[r],n++);return t/(n||1)});e[n.id]={axes:i,series:[{name:`Series 1`,values:t}]}}}return e},[w,l,u,D]),ve=zt(()=>{if(!w)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=w.rows,i=n.acYCols.map(e=>ZK(r,e,D)),a=i[0]?.length??r.length,o=(n.acXCol?ZK(r,n.acXCol,D):void 0)??n1(a);e[t.id]=n.acYCols.flatMap((e,t)=>{let n=i[t];return n?[{name:e,x:o,y:n}]:[]})}return e},[w,l,u,D]),ye=zt(()=>{let e={};if(!w)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:QK(w.rows,e,D)??new Float64Array}))}return e},[w,l,u,D]),be=zt(()=>{let e={};if(!w)return e;let{rows:t}=w,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=ZK(t,i.bbXCol,D),o=ZK(t,i.bbYCol,D),s=ZK(t,i.bbSizeCol,D);if(!a||!o||!s){e[r.id]=n;continue}let c=Math.min(a.length,o.length,s.length),l=new Float64Array(c);for(let e=0;e<c;e++)l[e]=s[e]===s[e]?Math.max(0,s[e]):NaN;let 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=ZK(t,i.bbColorCol,D);else if(i.bbColorMode===`categorical`){let e=D?.get(i.bbColorCol),n=new Map,r=new Int32Array(c);for(let a=0;a<c;a++){let o=String(e?e[a]:t[a]?.[i.bbColorCol]??``),s=n.get(o);s===void 0&&n.set(o,s=n.size),r[a]=s}f.colorIndex=r,f.colorLabels=[...n.keys()]}}e[r.id]=f}return e},[w,l,u,D]),xe=zt(()=>{if(!w)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 w.rows){let t=String(e[n.tmNameCol]??``),i=n.tmParentCol?String(e[n.tmParentCol]??``):``,a=e[n.tmValueCol];!t||typeof a!=`number`||!Number.isFinite(a)||r.push({name:t,parent:i,value:a})}e[t.id]=r}return e},[w,l,u]),Se=zt(()=>{if(!w)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 w.rows){let t=String(e[n.skSourceCol]??``),a=String(e[n.skTargetCol]??``),o=e[n.skValueCol];!t||!a||typeof o!=`number`||!Number.isFinite(o)||(r.add(t),r.add(a),i.push({source:t,target:a,value:o}))}e[t.id]={nodeNames:Array.from(r),links:i}}return e},[w,l,u]),Ce=zt(()=>{let e={};if(!w)return e;for(let t of l){if(t.kind!==`calibration`)continue;let n=u[t.id],r=n?.kind===`calibration`&&n.cbScoreCol?ZK(w.rows,n.cbScoreCol,D):void 0,i=n?.kind===`calibration`&&n.cbLabelCol?ZK(w.rows,n.cbLabelCol,D):void 0;if(!n||n.kind!==`calibration`||!r||!i){e[t.id]=[];continue}let a=Math.max(2,n.cbBins),o=new Float64Array(a),s=new Float64Array(a);for(let e=0;e<Math.min(r.length,i.length);e++){let t=r[e],n=i[e];if(t-t!==0||n-n!==0)continue;let c=Math.max(0,Math.min(a-1,Math.floor(t*a)));o[c]+=n,s[c]++}e[t.id]=Array.from({length:a},(e,t)=>({center:(t+.5)/a,actual:s[t]>0?o[t]/s[t]:0,count:s[t]})).filter(e=>e.count>0)}return e},[w,l,u,D]),we=zt(()=>{let e={};if(!w)return e;let t={length:0,theoretical:[],sample:[]},n=e=>{let t=QK(w.rows,e,D);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},[w,l,u,D]),Te=zt(()=>{if(!w)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 w.rows){let t=String(e[n.gtLabelCol]??``),i=e[n.gtStartCol],a=e[n.gtEndCol];if(!t||typeof i!=`number`||typeof a!=`number`||!Number.isFinite(i)||!Number.isFinite(a))continue;let o={label:t,start:i,end:a};n.gtGroupCol&&e[n.gtGroupCol]!==void 0&&(o.group=String(e[n.gtGroupCol])),r.push(o)}e[t.id]=r}return e},[w,l,u]),Ee=w&&w.columnNames.indexOf(d)>=0?w.units[w.columnNames.indexOf(d)]??``:``,De=zt(()=>w?$$(w,E?T.length:0):{},[w,E,T]);return{dataset:b,datasetWithChannels:w,multiDatasetMode:E,numericCols:R,anyDuckDb:N,duckDbLayers:L,liveConn:v,liveOverlays:P,hasLiveSelected:_,staticXRange:F,xUnit:Ee,columnUnits:De,multibandDataByPanel:V,xyPointsByPanel:ee,xyzPointsByPanel:H,histogramDataByPanel:ne,polarDataByPanel:re,spectrumDataByPanel:ie,boxplotDataByPanel:ae,spectrogramDataByPanel:oe,heatmapDataByPanel:se,violinDataByPanel:ce,confusionDataByPanel:le,rocDataByPanel:ue,lossCurveDataByPanel:de,controlChartDataByPanel:fe,parallelCoordsDataByPanel:pe,embeddingDataByPanel:me,flameGraphDataByPanel:he,barChartDataByPanel:ge,radarDataByPanel:_e,areaChartDataByPanel:ve,cdfChartDataByPanel:ye,bubbleChartDataByPanel:be,treemapDataByPanel:xe,sankeyDataByPanel:Se,calibrationDataByPanel:Ce,qqPlotDataByPanel:we,ganttDataByPanel:Te,gaugeDataByPanel:zt(()=>{let e={};if(!w)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?ZK(w.rows,n,D):void 0;if(!r)return[];let i=1/0,a=-1/0,o=0,s=0,c=NaN;for(let e=0;e<r.length;e++){let t=r[e];t-t===0&&(t<i&&(i=t),t>a&&(a=t),o+=t,s++,c=t)}let l=s===0?NaN:e.value===`mean`?o/s:e.value===`min`?i:e.value===`max`?a:c,[u,d]=i1(s?i:0,s?a:1,t(e.min),t(e.max));return[{name:n,unit:De[n]??``,value:l,min:u,max:d,alarm:e.alarm??null,color:e.color,style:e.style,fromZero:e.fill===`zero`,colorMode:e.colorMode,stops:e.stops,stat:e.value}]})}return e},[w,l,u,D,De])}}function i1(e,t,n,r){t<=e&&(t=e+1);let i=zV(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 a1=`#fb7185`,o1=2500,s1=new Float64Array;function c1(e,t){return t&&e?.kind===`spectrogram`&&e.sgView!==`waterfall`&&e.sgSignalCol!==``}function l1(e){let t=u1(e);if(t.status!==`empty`||!e.data.dataset)return t;let n=new Set([...e.data.datasetWithChannels?.columnNames??[],...e.data.numericCols]);return Cr(e.settings).some(e=>!n.has(e))?{...t,status:`missing`}:t}function u1(e){let{panel:t,data:n,settings:r}=e;if(t.kind===`camera`)return{status:`ready`,data:null,node:J(s$,{settings:r?.kind===`camera`?r:or(),live:e.live??[],selection:e.selection??[],viewXRange:e.viewXRange,xIsTime:e.xKey===O,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=Z$((d?.series??[]).filter(t=>t.column!==e.xKey),d?.layout??`overlay`),n=h.reference===`dataset`&&h.datasetId?e.findDataset(h.datasetId):void 0,r=N$(h,!!n),i=r?[...D$(t,r),...t]:t;return o(J(DK,{...m,series:i,points:[],showLatestValues:!0,liveSource:M$(e.beaconLive,e.xKey,f,h,n),envelopes:n?P$(n,e.xKey,t,r??void 0):void 0,liveZoomMode:`free`}),{series:i,points:[]})}if(n.anyDuckDb)return u.length===0?s:o(J(JK,{...m,layers:n.duckDbLayers,xKey:e.xKey,columns:f,maxPoints:o1}),{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 _=n.liveConn,v=null,y=n.liveOverlays,b=!_&&y&&f.length>0?S$(y,e.xKey,f,l,n.staticXRange):void 0,x=!!b&&l.length>0,S=b??(_&&f.length>0?{pull:(t,n,r,i,a,o)=>{let s=_.source.version();if(o)return(!v||v.ver!==s||v.x0!==t||v.x1!==n||v.mp!==r||v.w?.[0]!==o[0]||v.w?.[1]!==o[1])&&(v={ver:s,x0:t,x1:n,mp:r,w:o,pts:_.source.getWindowPointsSync(f,{xKey:e.xKey,x0:t,x1:n},r,o[0],o[1])}),[v.pts];if(a){let i=2**Math.ceil(Math.log2((n-t)/8)),a=Math.floor(t/i)*i,o=Math.ceil(n/i)*i,c=Math.round(r*(o-a)/(n-t));return(!v||v.ver!==s||v.x0!==a||v.x1!==o||Math.abs(v.mp-c)>c*.25)&&(v={ver:s,x0:a,x1:o,mp:c,pts:_.source.getPointsSync(f,{xKey:e.xKey,x0:a,x1:o},c),held:g(f,e=>_.source.lastKnownSync(e),a,o,_.source.latestTimeSync())}),v.held?[v.pts,v.held]:[v.pts]}(!v||v.ver!==s||v.x0!==t||v.x1!==n||v.mp!==r)&&(v={ver:s,x0:t,x1:n,mp:r,pts:_.source.getPointsSync(f,{xKey:e.xKey,x0:t,x1:n},r)});let c=I(v.pts,i);if(e.xKey!==`ElapsedTime`)return[c];let l=g(f,e=>_.source.lastKnownSync(e),t,n,Math.min(_.source.latestTimeSync(),i??1/0));return l?[c,l]:[c]},cutOnGpu:e.xKey===`ElapsedTime`,id:_.id,latestT:()=>_.source.latestTimeSync(),timeAfter:e=>_.source.timeAfterSync(e),xAtTime:t=>_.source.xAtTimeSync(e.xKey,t),xBounds:()=>{let t=_.source.xBoundsSync(e.xKey);return t.x1>t.x0?[t.x0,t.x1]:null},latestX:()=>{let t=_.source.latestSync(e.xKey);return Number.isFinite(t)?t:null},version:()=>_.source.version(),latestValues:e=>_.source.latestValuesSync(e),...e.xKey===`ElapsedTime`?{}:{windowXBounds:(t,n)=>{let r=_.source.windowXBoundsSync(e.xKey,t,n);return r&&r.x1>r.x0?[r.x0,r.x1]:null},spanForSeconds:t=>_.source.xTravelSync(e.xKey,t),bufferedSeconds:()=>{let e=_.source.xBoundsSync(`ElapsedTime`);return e.x1-e.x0}}}:void 0);return o(J(DK,{...m,points:l,envelopes:t?.envelopes,showLatestValues:n.hasLiveSelected,fullXRange:n.staticXRange,liveSource:S,liveWindowSeconds:x?null:e.liveWindowSeconds,onLiveWindowChange:x?void 0:e.onLiveWindowChange,liveZoomMode:x?`free`:`follow`}),{series:u,points:l})}case`xyzmesh`:{let t=r?.kind===`xyzmesh`?r:Nn(4),l=n.xyzPointsByPanel[c];if(!l||l.points.length<1&&!l.surface)return s;let u=!!l.surface;return o(J(eY,{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:Dn(t.xyzXScale.scaleMin,t.xyzXScale.scaleMax),yRange:Dn(t.xyzYScale.scaleMin,t.xyzYScale.scaleMax),zRange:Dn(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:Mn(a1),l=n.xyPointsByPanel.pts[c]??[];if(l.length===0)return s;let u=n.xyPointsByPanel.colorMeta[c];return o(J(Vq,{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(J(cY,{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(J(EY,{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(J(HY,{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(J(JY,{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:t,rate:l,times:u}=n.spectrogramDataByPanel[c]??{signal:[],rate:1,times:void 0},d=c1(r,!!n.liveConn)?n.liveConn:null,f=r.sgSignalCol,p=d?{version:()=>d.source.version(),samples:()=>d.source.samplesSync(f),latestT:()=>d.source.latestTimeSync(),timeAfter:e=>d.source.timeAfterSync(e),id:d.id,windowSeconds:e.liveWindowSeconds}:void 0;return!p&&t.length<r.sgWindowSize?s:r.sgView===`waterfall`?o(J(SX,{signal:t,sampleRate:l,windowSize:r.sgWindowSize,overlap:r.sgOverlap,winFunc:r.sgWinFunc,yMode:r.sgYMode,backgroundToken:i,onPlotContextMenu:a}),t):o(J(_X,{signal:p?s1:t,sampleRate:l,windowSize:r.sgWindowSize,overlap:r.sgOverlap,winFunc:r.sgWinFunc,yMode:r.sgYMode,logFreq:r.sgLogFreq,times:p?void 0:u,backgroundToken:i,onPlotContextMenu:a,live:p}),t)}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(J(VX,{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(J(YX,{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(J(rZ,{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(J(lZ,{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(J(dZ,{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(J(_Z,{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(J(CZ,{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(J(NZ,{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(J(VZ,{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(J(qZ,{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(J(ZZ,{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(J(tQ,{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(J(iQ,{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(J(dQ,{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(J(gQ,{nodes:e,backgroundToken:i,onPlotContextMenu:a}),e)}case`sankey`:{let e=n.sankeyDataByPanel[c]??{nodeNames:[],links:[]};return e.links.length===0?s:o(J(SQ,{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(J(wQ,{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(J(EQ,{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(J(VQ,{gauges:e,live:t?{latestT:()=>t.source.latestTimeSync(),timeAfter:e=>t.source.timeAfterSync(e),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(J(jQ,{tasks:e,backgroundToken:i,onPlotContextMenu:a}),e)}}return s}var d1=500,f1=10,p1=300,m1=1.12;function h1(e){let t=null,n=null,r=!1,i=!1,a=null,o=0,s=(t,n)=>{let r=e.ownerDocument.elementFromPoint(t,n);return r&&e.contains(r)?r:e},c=(e,t,n,r={})=>s(t,n).dispatchEvent(new MouseEvent(e,{bubbles:!0,cancelable:!0,clientX:t,clientY:n,...r})),l=()=>{t&&=(clearTimeout(t),null)},u=e=>Math.hypot(e[0].clientX-e[1].clientX,e[0].clientY-e[1].clientY),d=e=>{if(l(),e.touches.length===2){n=null,o=u(e.touches);return}if(e.touches.length!==1)return;let{clientX:a,clientY:s}=e.touches[0];n={x:a,y:s,t:Date.now()},r=!1,i=!1,c(`mousemove`,a,s),t=setTimeout(()=>{t=null,i=!0,c(`contextmenu`,a,s,{button:2,buttons:2})},d1)},f=e=>{if(e.touches.length===2&&o>0){e.preventDefault();let t=u(e.touches),n=t/o;if(n<m1&&n>1/m1)return;let r=(e.touches[0].clientX+e.touches[1].clientX)/2,i=(e.touches[0].clientY+e.touches[1].clientY)/2;s(r,i).dispatchEvent(new WheelEvent(`wheel`,{bubbles:!0,cancelable:!0,clientX:r,clientY:i,deltaY:n>1?-100:100})),o=t;return}if(e.touches.length!==1||!n)return;let{clientX:t,clientY:i}=e.touches[0];Math.hypot(t-n.x,i-n.y)>f1&&(r=!0,l()),c(`mousemove`,t,i)},p=e=>{if(l(),e.touches.length<2&&(o=0),e.touches.length>0||!n)return;let t=n;if(n=null,i){e.preventDefault();return}if(r||Date.now()-t.t>p1){a=null;return}let s=Date.now();if(a&&s-a.t<p1&&Math.hypot(t.x-a.x,t.y-a.y)<30){e.preventDefault(),a=null,c(`dblclick`,t.x,t.y,{detail:2});return}a={x:t.x,y:t.y,t:s}};return e.addEventListener(`touchstart`,d,{passive:!0}),e.addEventListener(`touchmove`,f,{passive:!1}),e.addEventListener(`touchend`,p,{passive:!1}),e.addEventListener(`touchcancel`,p,{passive:!1}),()=>{l(),e.removeEventListener(`touchstart`,d),e.removeEventListener(`touchmove`,f),e.removeEventListener(`touchend`,p),e.removeEventListener(`touchcancel`,p)}}var g1=500,_1=1e3;function v1(e){if(Array.isArray(e))return y1(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,y1(n)));return t<0?null:t}function y1(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 b1(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 x1({stats:e,host:t}){let[n,r]=Bt(null);if(G(()=>{let n=t.current?.ownerDocument.defaultView??window,i=0,a=0,o=0,s=-1,c=-1,l=e.renders,u=t.current?FW(t.current):0,d=f=>{c>=0&&f-s>_1&&(c=f,s=f,a=0,o=0,l=e.renders,u=t.current?FW(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>=g1){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?FW(i):0;r({fps:a*1e3/p,repaints:(m-u)*1e3/p,worstFrameMs:o,renderMs:e.lastRenderMs,rendersPerSec:(e.renders-l)*1e3/p,points:v1(e.data),domNodes:i?i.getElementsByTagName(`*`).length:0,canvasMp:s/1e6,heapMb:d?d.usedJSHeapSize/1048576:null,live:(()=>{let e=cG();return e?{age:Date.now()/1e3-e.newest,lag:e.lag,wait:e.wait,waitAge:e.waitAge}: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 J(`dl`,{className:`kymo-perf-hud`,style:S1,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`,b1(n.points)]],[`DOM nodes`,b1(n.domNodes)],[`Canvas`,`${n.canvasMp.toFixed(2)} MP`],...n.heapMb===null?[]:[[`JS heap`,`${n.heapMb.toFixed(0)} MB`]],...n.live?[[`Data age`,`${n.live.age.toFixed(2)} s`],[`Live lag`,`${n.live.lag.toFixed(2)} s`],[`Late by`,`${n.live.wait.toFixed(2)} s · ${n.live.waitAge.toFixed(0)} s ago`]]:[]].map(([e,t,n])=>Gt(`div`,{style:C1,children:[J(`dt`,{style:w1,children:e}),J(`dd`,{style:n?{...T1,color:n}:T1,children:t})]},e))})}var S1={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)`},C1={display:`flex`,justifyContent:`space-between`,gap:12},w1={color:`var(--text-muted, #8a93a6)`},T1={margin:0,fontWeight:600,textAlign:`right`},E1=[],D1=180,O1=3,k1=`data-kymo-annotation-controls`;function A1(e,t,n,r){return e.anchor===`x`&&!r?null:e.points.map(([i,a])=>[e.anchor===`x`?wG(r,i):i*t,a*n])}function j1(e,t,n,r,i){return t.map(([t,a])=>[e.anchor===`x`&&i?TG(i,t):M1(t/Math.max(1,n)),M1(a/Math.max(1,r))])}var M1=e=>Math.round(e*1e4)/1e4,N1=Pt(function({annotations:e,tool:t,plotFrame:n,onChange:r,onToolEnd:i,onSelect:a,marks:o=E1,onMarkSelect:s,markFocus:c=null}){let l=q(null),u=Vt(n.subscribe,n.get),d=u?.x?u:null,[f,p]=Bt({w:0,h:0}),[m,h]=Bt(null),[g,_]=Bt(null),[v,y]=Bt(null),b=q({annotations:e,onChange:r,onToolEnd:i,onSelect:a,tool:t,selected:m,editing:g,frame:d,size:f});b.current={annotations:e,onChange:r,onToolEnd:i,onSelect:a,tool:t,selected:m,editing:g,frame:d,size:f};let x=e=>{b.current.selected!==e&&(b.current.selected=e,h(e),b.current.onSelect(e))};K(()=>{let e=l.current;if(!e)return;let t=e.ownerDocument.defaultView??window,n=()=>p({w:e.clientWidth,h:e.clientHeight});n();let r=new t.ResizeObserver(n);return r.observe(e),()=>r.disconnect()},[]),G(()=>{t&&x(null)}),G(()=>{m&&!e.some(e=>e.id===m)&&x(null)}),G(()=>()=>{b.current.selected&&b.current.onSelect(null)},[]),G(()=>{let e=l.current?.ownerDocument;if(!e)return;let t=e=>{let{selected:t,editing:n,tool:r,annotations:i,onChange:a,onToolEnd:o}=b.current;if(!(n||H1(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)),x(null)):e.key===`Escape`&&x(null))}},n=e=>{let t=b.current.selected,n=e.target;t&&!n?.closest?.(`[data-ann-id="${CSS.escape(t)}"], [data-kymo-annotation-controls]`)&&x(null)};return e.addEventListener(`keydown`,t),e.addEventListener(`pointerdown`,n,!0),()=>{e.removeEventListener(`keydown`,t),e.removeEventListener(`pointerdown`,n,!0)}},[]);let{w:S,h:C}=f,w=e=>{let t=l.current.getBoundingClientRect();return[e.clientX-t.left,e.clientY-t.top]},T=(e,t)=>{let n=l.current.ownerDocument,r=t=>e(w(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)},E=e=>r([...b.current.annotations,e]),D=e=>r(b.current.annotations.map(t=>t.id===e.id?e:t)),O=e=>{if(!t||e.button!==0||g)return;e.preventDefault(),e.stopPropagation();let n=w(e),r={id:crypto.randomUUID(),kind:t.kind,color:t.color,width:t.width,...d?{anchor:`x`}:{}},i=e=>j1(r,e,S,C,d);if(t.kind===`text`){y({...r,points:i([n]),text:``}),_(r.id);return}let a=t.kind===`brush`?[n]:[n,n],o={...r,points:i(a)};y(o);let s=!1;T((t,n)=>{if(s||=Math.hypot(n.clientX-e.clientX,n.clientY-e.clientY)>O1,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)},y(o)},()=>{y(null),s&&o.points.length>=2&&E(o)})},k=(e,t,n)=>{let r=A1(t,S,C,d);if(!r)return;let i=w(e),a=null;T((o,s)=>{if(!a&&Math.hypot(s.clientX-e.clientX,s.clientY-e.clientY)<=O1)return;let{size:c,frame:l}=b.current;a={...t,points:j1(t,n(r,[o[0]-i[0],o[1]-i[1]],o),c.w,c.h,l)},y(a)},()=>{y(null),a&&D(a)})},A=(e,n)=>{t||e.button!==0||g===n.id||(e.preventDefault(),e.stopPropagation(),x(n.id),k(e,n,(e,[t,n])=>e.map(([e,r])=>[e+t,r+n])))},j=(e,t,n)=>{e.button===0&&(e.preventDefault(),e.stopPropagation(),k(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}))},M=e=>{t||e.kind!==`text`&&e.kind!==`box`||(x(e.id),_(e.id))},N=e=>{let t=g;_(null);let n=v&&v.id===t?v:null;if(y(null),e===null||!t)return;let i=e.replace(/\s+$/,``),a=b.current.annotations;if(n){i&&E({...n,text:i});return}let o=a.find(e=>e.id===t);o&&(!i&&o.kind===`text`?r(a.filter(e=>e.id!==t)):D(V1(o,i)))},P=e=>{r(b.current.annotations.filter(t=>t.id!==e)),x(null)},F=(v?e.some(e=>e.id===v.id)?e.map(e=>e.id===v.id?v:e):[...e,v]:e).flatMap(e=>{let t=A1(e,S,C,d);return t?[{a:e,px:t}]:[]}),I=m?F.find(e=>e.a.id===m):void 0,L=d?o.map(e=>{let t=A1(tn(e,d.x.v1),S,C,d);return{m:e,x0:Math.min(t[0][0],t[1][0]),x1:Math.max(t[0][0],t[1][0])}}):[],R=[];if(d&&c)for(let{m:e,x0:t,x1:n}of L.filter(e=>e.m.ruleId===c&&e.x1>d.left&&e.x0<d.left+d.width).sort((e,t)=>e.x0-t.x0)){let r=Math.max(d.left,t)+4;n-r<24||(!R.length||r>=R[R.length-1].left+D1)&&R.push({m:e,left:r})}let z=I&&I.a.kind!==`text`?B1(I.px):null,B=e=>t=>{if(!t)return;let n=d&&e<d.left+d.width?e+t.offsetWidth-(d.left+d.width):0;t.style.transform=n>0?`translateX(${-Math.min(n,Math.max(0,e-d.left))}px)`:``},V=e=>Gt(Wt,{children:[J(`svg`,{className:`kymo-ann-svg`,width:S,height:C,viewBox:`0 0 ${S} ${C}`,"aria-hidden":`true`,children:e.map(({a:e,px:t})=>e.kind===`text`?null:J(`g`,{"data-ann-id":e.id,className:`kymo-ann kymo-ann--${e.kind}`,onPointerDown:t=>A(t,e),onDoubleClick:()=>M(e),children:J(I1,{a:e,px:t})},e.id))}),e.map(({a:e,px:t})=>{if(e.kind!==`text`&&e.kind!==`box`)return null;let n=g===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 Gt(`div`,{"data-ann-id":e.id,ref:e.kind===`text`?B(r.left):void 0,className:`kymo-ann-text kymo-ann-text--${e.kind}${m===e.id&&e.kind===`text`?` is-selected`:``}`,style:{...r,color:e.color,fontSize:e.kind===`text`?e.width:12},onPointerDown:t=>A(t,e),onDoubleClick:()=>M(e),children:[n?J(F1,{initial:e.text??``,onDone:N}):e.text,m===e.id&&e.kind===`text`&&!n?J(P1,{onDelete:()=>P(e.id),style:{right:-11,top:-11}}):null]},`t-${e.id}`)})]});return J(`div`,{ref:l,className:`kymo-annotations${t?` is-drawing is-tool-${t.kind}`:``}`,onPointerDown:O,onContextMenu:t?e=>e.preventDefault():void 0,children:S>0&&C>0?Gt(Wt,{children:[d&&L.length?Gt(`div`,{className:`kymo-ann-clip`,style:{clipPath:`inset(0 ${Math.max(0,S-d.left-d.width)}px 0 ${Math.max(0,d.left)}px)`},children:[J(`svg`,{className:`kymo-ann-svg kymo-marks`,width:S,height:C,viewBox:`0 0 ${S} ${C}`,children:L.map(({m:e,x0:t,x1:n})=>Gt(`g`,{"data-mark":e.ruleId,role:`img`,"aria-label":`${e.late?`Late · `:``}${e.ruleName}, ${e.severity}`,className:`kymo-mark kymo-mark--${e.severity}${e.late?` kymo-mark--late`:``}${c?e.ruleId===c?` is-focus`:` is-dim`:``}`,style:{color:en[e.severity]},children:[J(`rect`,{className:`kymo-mark-fill`,x:t,y:d.top,width:Math.max(1,n-t),height:d.height,fill:`currentColor`,fillOpacity:.12}),J(`rect`,{x:t,y:d.top,width:Math.max(1,n-t),height:2,fill:`currentColor`}),J(`rect`,{className:`kymo-mark-hit`,x:t,y:d.top,width:Math.max(6,n-t),height:8,onPointerDown:t=>{t.stopPropagation(),s?.(e.ruleId)}})]},e.id))}),R.map(({m:e,left:t})=>Gt(`div`,{className:`kymo-mark-label`,style:{left:t,top:d.top+6,color:en[e.severity]},children:[e.late?`Late · `:``,e.ruleName]},`l-${e.id}`))]}):null,V(F.filter(e=>e.a.anchor!==`x`)),d?J(`div`,{className:`kymo-ann-clip`,style:{clipPath:`inset(0 ${Math.max(0,S-d.left-d.width)}px 0 ${Math.max(0,d.left)}px)`},children:V(F.filter(e=>e.a.anchor===`x`))}):null,Gt(`svg`,{className:`kymo-ann-svg`,width:S,height:C,viewBox:`0 0 ${S} ${C}`,"aria-hidden":`true`,children:[z?J(`rect`,{className:`kymo-ann-selection`,x:z.x-6,y:z.y-6,width:z.w+12,height:z.h+12,rx:4}):null,I&&!g&&(I.a.kind===`box`||I.a.kind===`arrow`)?J(`g`,{"data-ann-id":I.a.id,children:L1(I.a,I.px).map(([e,t],n)=>J(`rect`,{className:`kymo-ann-handle kymo-ann-handle--${I.a.kind===`arrow`?`end`:n%2?`nesw`:`nwse`}`,x:e-4.5,y:t-4.5,width:9,height:9,rx:2,onPointerDown:e=>j(e,I.a,n)},n))}):null]}),z&&!g?J(P1,{onDelete:()=>P(I.a.id),id:I.a.id,style:{left:Math.min(S-12,z.x+z.w+6)-10,top:Math.max(10,z.y-6)-10}}):null]}):null})});function P1({onDelete:e,style:t,id:n}){return J(`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:J(`svg`,{viewBox:`0 0 10 10`,width:`8`,height:`8`,"aria-hidden":`true`,children:J(`path`,{d:`M2 2l6 6M8 2l-6 6`})})})}function F1({initial:e,onDone:t}){let n=q(null),r=q(!1),i=e=>{r.current||(r.current=!0,t(e))};return K(()=>{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)},[]),J(`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 I1({a:e,px:t}){let n={stroke:e.color,strokeWidth:e.width,fill:`none`,strokeLinecap:`round`,strokeLinejoin:`round`},r=t=>J(`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 Gt(Wt,{children:[r(c),J(`path`,{d:c,...n}),J(`path`,{d:c,fill:e.color,fillOpacity:.06,stroke:`none`,pointerEvents:`none`})]})}case`arrow`:{let[[i,a],[o,s]]=t,c=z1(i,a,o,s,e.width);return Gt(Wt,{children:[r(`M${i} ${a}L${o} ${s}`),J(`path`,{d:`M${i} ${a}L${c.base[0]} ${c.base[1]}`,...n}),J(`path`,{d:c.d,fill:e.color,stroke:e.color,strokeWidth:1,strokeLinejoin:`round`})]})}case`brush`:{let e=R1(t);return Gt(Wt,{children:[r(e),J(`path`,{d:e,...n})]})}}return null}function L1(e,t){if(e.kind===`arrow`)return t;let[[n,r],[i,a]]=t;return[[n,r],[i,r],[i,a],[n,a]]}function R1(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 z1(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 B1(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 V1(e,t){if(t)return{...e,text:t};let{text:n,...r}=e;return r}function H1(e){let t=e;return!!t&&(t.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName))}function U1(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=A1(i,n,r,o);t&&(e.save(),i.anchor===`x`&&o&&(e.beginPath(),e.rect(o.left,0,o.width,r),e.clip()),W1(e,i,t,a),e.restore())}e.restore()}function W1(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(R1(n)));else if(t.kind===`arrow`){let r=z1(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
+ `).filter(e=>!i.has(e));return a.length?[...r,...a]:r},[A,j,M]),z=zt(()=>{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]),B=zt(()=>{let e={};if(!w||N)return e;for(let[t,n]of JSON.parse(z)){let r=[];if(n.length>0)if(!E)r.push(p(w.rows,d,n,B$));else{let e=Math.max(1,Math.floor(B$/T.length));for(let t=0;t<T.length;t++){let i=T[t];if(P&&`live`in i&&i.live)continue;let a=k[t]??i.data.rows;r.push(p(a,d,n,e,`__${t}`,o[i.id]??0))}}e[t]=r}return e},[w,z,d,E,T,o,k,P,N]),V=zt(()=>{let e={};if(!w)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=>Z$(e,i),l;if(!E)l=a(r);else{let e=a(r);l=[];for(let t=0;t<T.length;t++){let n=uH(s,T[t].id,t,c);for(let r of e)l.push({...r,id:`${r.id}__${t}`,column:`${r.column}__${t}`,color:n})}}let f=B[t.id]??[],p=E&&n?.kind===`multiband`&&n.envelope?r.flatMap(e=>{let t=v$(f.flatMap((t,n)=>{let r=t.cols.get(`${e.column}__${n}`);return r?[{x:t.x,y:r}]:[]}),q$);return t?[{seriesId:e.id,color:e.color,...t}]:[]}):void 0,m=T.flatMap((e,t)=>`bands`in e&&e.bands?P$(e,d,r,E?uH(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},[w,l,u,d,E,T,s,c,o,B]),ee=zt(()=>{let e={pts:{},colorMeta:{},datasetColors:{}};if(!w)return e;let t={},r={},i={},a=G$,o=T.map((e,t)=>({id:e.id,rows:k[t]??m[e.id]??e.data.rows,full:a(e)})),f={id:`single`,rows:w.rows,full:T.length===1?a(T[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(E){let{cols:r,colors:a}=aq(o,l,p,{xKey:d,viewXRange:n,colorOverrides:s,palette:c});t[e.id]=r,i[e.id]=a;continue}let m=iq(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}},[w,l,u,n,d,E,T,m,s,c,k]),te=q(new Map),H=zt(()=>{let e={};if(!w)return e;let t={length:0,x:[],y:[],z:[]},{rows:r}=w,i=D;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=ZK(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=te.current.get(a.id);l?.length!==s*c&&te.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=ZK(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?ZK(r,s,i):void 0,p=c?ZK(r,c,i):void 0,m=l?ZK(r,l,i):void 0;if(!f||!p||!m){e[a.id]={points:t};continue}let h=n?ZK(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},[w,l,u,n,d,D]),ne=zt(()=>{let e={};if(!w)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&&QK(w.rows,n.histColumn,D)||new Float64Array}return e},[w,l,u,D]),re=zt(()=>{let e={};if(!w)return e;for(let t of l){if(t.kind!==`polar`)continue;let n=u[t.id],r=n?.kind===`polar`&&n.polarAngleCol?ZK(w.rows,n.polarAngleCol,D):void 0,i=n?.kind===`polar`&&n.polarRadiusCol?ZK(w.rows,n.polarRadiusCol,D):void 0;e[t.id]=r&&i?{angles:r,radii:i}:{angles:[],radii:[]}}return e},[w,l,u,D]),U=(e,t)=>{if(!E)return{rows:e,full:O};let n=K$(T,I,t);if(n<0)return{rows:[]};let r=T[n];return{rows:k[n]??m[r.id]??r.data.rows,full:G$(r,!0)}},W=(e,t,n,r)=>{let{rows:i,full:a}=U(e,t),o=t&&QK(i,t,a)||new Float64Array,s=n?ZK(i,n,a):void 0;return{signal:o,rate:s&&tq(s)||parseFloat(r)||1}},ie=zt(()=>{let e={};if(!w)return e;for(let t of l){if(t.kind!==`spectrum`)continue;let n=u[t.id];n?.kind===`spectrum`&&(e[t.id]=W(w.rows,n.specSignalCol,n.specTimeCol,n.specSampleRate))}return e},[w,l,u,O,E,T,k,m,I]),ae=zt(()=>{let e={};if(!w)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?eq(w.rows,n.boxValueCol,n.boxGroupCol||void 0,D):[]}return e},[w,l,u,D]),oe=zt(()=>{let e={};if(!w)return e;for(let t of l){if(t.kind!==`spectrogram`)continue;let n=u[t.id];if(n?.kind!==`spectrogram`)continue;let r=w.rows,i=U(r,n.sgSignalCol),a=n.sgSignalCol?$K(i.rows,n.sgSignalCol,n.sgTimeCol||d,i.full):void 0;e[t.id]={...W(r,n.sgSignalCol,n.sgTimeCol,n.sgSampleRate),...a}}return e},[w,l,u,O,d,E,T,k,m,I]),se=zt(()=>{if(!w)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=w.rows,i=n.hmColumns.flatMap(e=>{let t=ZK(r,e,D);return t?[{name:e,v:t}]:[]}),a=i.reduce((e,t)=>Math.min(e,t.v.length),i.length?1/0:0),o=ZK(r,d,D),s,c;if(n.hmSpacing===`values`){o&&DX(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&&DX(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=>R.includes(e));if(r.length<2){e[t.id]={cells:[],xLabels:r,yLabels:r};continue}let i=r.map(e=>{let t=[];for(let n of w.rows){let r=n[e];typeof r==`number`&&Number.isFinite(r)&&t.push(r)}return t}),a=i.map(e=>e.reduce((e,t)=>e+t,0)/(e.length||1)),o=[];for(let e=0;e<r.length;e++)for(let t=0;t<r.length;t++){let n=i[e],s=i[t],c=a[e],l=a[t],u=Math.min(n.length,s.length),d=0,f=0,p=0;for(let e=0;e<u;e++){let t=n[e]-c,r=s[e]-l;d+=t*r,f+=t*t,p+=r*r}let m=f>0&&p>0?d/Math.sqrt(f*p):+(e===t);o.push({x:r[t],y:r[e],value:m})}e[t.id]={cells:o,xLabels:r,yLabels:r}}else if(n.hmMode===`binned`||n.hmMode===`count`){let{hmXCol:r,hmYCol:i}=n,a=n.hmMode===`count`?``:n.hmValueCol;if(!r||!i||n.hmMode===`binned`&&!a){e[t.id]={cells:[],xLabels:[],yLabels:[]};continue}let o=e=>{let t=parseFloat(e);return Number.isFinite(t)?t:void 0};e[t.id]=L$(w.rows,{xCol:r,yCol:i,valueCol:a,xBins:n.hmXBins,yBins:n.hmYBins,xMin:o(n.hmXMin),xMax:o(n.hmXMax),yMin:o(n.hmYMin),yMax:o(n.hmYMax)})}else{let{hmXCol:r,hmYCol:i,hmValueCol:a}=n;if(!r||!i||!a){e[t.id]={cells:[],xLabels:[],yLabels:[]};continue}let o=new Map,s=new Set,c=new Set;for(let e of w.rows){let t=String(e[r]??``),n=String(e[i]??``),l=e[a];if(typeof l!=`number`||!Number.isFinite(l))continue;s.add(t),c.add(n);let u=`${t}\0${n}`,d=o.get(u)??{sum:0,count:0};o.set(u,{sum:d.sum+l,count:d.count+1})}let l=e=>{let t=[...e];return t.every(e=>e.trim()!==``&&Number.isFinite(Number(e)))?t.sort((e,t)=>Number(e)-Number(t)):t.sort()},u=l(s),d=l(c),f,p;if(n.hmSpacing===`values`){let e=Float64Array.from(u,Number),t=Float64Array.from(d,Number);DX(e)&&(f=e),DX(t)&&(d=[...d].reverse(),p=t.reverse())}let m=[];for(let e of d)for(let t of u){let n=o.get(`${t}\0${e}`);m.push({x:t,y:e,value:n?n.sum/n.count:0})}e[t.id]={cells:m,xLabels:u,yLabels:d,xCentres:f,yCentres:p}}}return e},[w,l,u,R,d,D]),ce=zt(()=>{let e={};if(!w)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?eq(w.rows,n.vlValueCol,n.vlGroupCol||void 0,D):[]}return e},[w,l,u,D]),le=zt(()=>{let e={};if(!w)return e;let{rows:t}=w;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=D?.get(i),s=D?.get(a);if(o&&s){e[n.id]={actual:o,predicted:s};continue}let c=[],l=[];for(let e of t){let t=e[i],n=e[a];t!==void 0&&n!==void 0&&(c.push(t),l.push(n))}e[n.id]={actual:c,predicted:l}}return e},[w,l,u,D]),ue=zt(()=>{let e={};if(!w)return e;for(let t of l){if(t.kind!==`roc`)continue;let n=u[t.id],r=n?.kind===`roc`&&n.rocScoreCol?ZK(w.rows,n.rocScoreCol,D):void 0,i=n?.kind===`roc`&&n.rocLabelCol?ZK(w.rows,n.rocLabelCol,D):void 0;e[t.id]=r&&i?{scores:r,labels:i}:{scores:[],labels:[]}}return e},[w,l,u,D]),de=zt(()=>{let e={};if(!w)return e;let{rows:t}=w;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:ZK(t,e,D)??new Float64Array,axis:r})),c=s[0]?.values.length??t.length,l=i&&ZK(t,i,D)||Float64Array.from({length:c},(e,t)=>t);e[n.id]={xValues:l,series:s}}return e},[w,l,u,D]),fe=zt(()=>{let e={};if(!w)return e;let{rows:t}=w;for(let n of l){if(n.kind!==`controlchart`)continue;let r=u[n.id],i=r?.kind===`controlchart`&&r.ccValueCol?ZK(t,r.ccValueCol,D):void 0;if(!r||r.kind!==`controlchart`||!i){e[n.id]={length:0,value:[]};continue}let a=0;for(let e=0;e<i.length;e++)i[e]-i[e]===0&&a++;let o=a===i.length?null:new Uint32Array(a),s=o?new Float64Array(a):i;if(o)for(let e=0,t=0;e<i.length;e++)i[e]-i[e]===0&&(o[t]=e,s[t++]=i[e]);let c=r.ccSubgroupCol,l=c?D?.get(c):void 0,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},[w,l,u,D]),pe=zt(()=>{let e={};if(!w)return e;let{rows:t}=w;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=>ZK(t,e,D)??new Float64Array),a=Math.min(...i.map(e=>e.length)),o={length:a,columns:i},s=r.pcColorByCol;if(s)if(R.includes(s))o.colorValue=ZK(t,s,D);else{let e=new Map,n=new Int32Array(a);for(let r=0;r<a;r++){let i=String(t[r]?.[s]??``),a=e.get(i);a===void 0&&e.set(i,a=e.size),n[r]=a}o.colorIndex=n,o.colorLabels=[...e.keys()]}e[n.id]=o}return e},[w,l,u,R,D]),me=zt(()=>{let e={};if(!w)return e;let{rows:t}=w,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=ZK(t,a,D),f=ZK(t,o,D);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`&&R.includes(s))m.colorValue=ZK(t,s,D);else{let e=D?.get(s),n=new Map,r=new Int32Array(p);for(let i=0;i<p;i++){let a=String(e?e[i]:t[i]?.[s]??``),o=n.get(a);o===void 0&&n.set(a,o=n.size),r[i]=o}m.colorIndex=r,m.colorLabels=[...n.keys()]}if(l){let e=D?.get(l);m.label=e?t=>String(e[t]):e=>String(t[e]?.[l]??``)}e[r.id]=m}return e},[w,l,u,R,D]),he=zt(()=>{if(!w)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 w.rows){let t=String(e[n.fgNameCol]??``),i=n.fgParentCol?String(e[n.fgParentCol]??``):``,a=e[n.fgValueCol];!t||typeof a!=`number`||!Number.isFinite(a)||r.push({name:t,parent:i,value:a})}e[t.id]=r}return e},[w,l,u]),ge=zt(()=>{if(!w)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 w.rows){let t=String(e[n.bcCategoryCol]??`(blank)`);i.has(t)||i.set(t,r.map(()=>0));let a=new Map,o=i.get(t);for(let t=0;t<r.length;t++){let n=e[r[t]];typeof n==`number`&&Number.isFinite(n)&&(o[t]+=n),a.set(r[t],(a.get(r[t])??0)+1)}}e[t.id]={groups:Array.from(i.entries()).map(([e,t])=>({label:e,values:t})),seriesNames:r}}else{let n=w.rows,i=r.map(e=>ZK(n,e,D)),a=i.reduce((e,t)=>t?Math.min(e,t.length):e,1/0),o=Number.isFinite(a)?a:n.length,s=i.map(e=>e??new Float64Array(o).fill(NaN));e[t.id]={groups:[],columns:{length:o,values:s},seriesNames:r}}}return e},[w,l,u,D]),_e=zt(()=>{let e={};if(!w)return e;let{rows:t}=w;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=>ZK(t,e,D));if(r.rdGroupCol){let o=r.rdGroupCol,s=D?.get(o),c=s?s.length:t.length,l=new Map;for(let e=0;e<c;e++){let n=s?s[e]===s[e]?String(s[e]):`(blank)`:String(t[e][o]??`(blank)`),r=l.get(n);r||l.set(n,r=i.map(()=>0));for(let t=0;t<i.length;t++){let n=a[t]?.[e]??NaN;n-n===0&&(r[t]+=n)}}e[n.id]={axes:i,series:Array.from(l.entries()).map(([e,t])=>({name:e,values:t}))}}else{let t=a.map(e=>{let t=0,n=0;if(e)for(let r=0;r<e.length;r++)e[r]-e[r]===0&&(t+=e[r],n++);return t/(n||1)});e[n.id]={axes:i,series:[{name:`Series 1`,values:t}]}}}return e},[w,l,u,D]),ve=zt(()=>{if(!w)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=w.rows,i=n.acYCols.map(e=>ZK(r,e,D)),a=i[0]?.length??r.length,o=(n.acXCol?ZK(r,n.acXCol,D):void 0)??n1(a);e[t.id]=n.acYCols.flatMap((e,t)=>{let n=i[t];return n?[{name:e,x:o,y:n}]:[]})}return e},[w,l,u,D]),ye=zt(()=>{let e={};if(!w)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:QK(w.rows,e,D)??new Float64Array}))}return e},[w,l,u,D]),be=zt(()=>{let e={};if(!w)return e;let{rows:t}=w,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=ZK(t,i.bbXCol,D),o=ZK(t,i.bbYCol,D),s=ZK(t,i.bbSizeCol,D);if(!a||!o||!s){e[r.id]=n;continue}let c=Math.min(a.length,o.length,s.length),l=new Float64Array(c);for(let e=0;e<c;e++)l[e]=s[e]===s[e]?Math.max(0,s[e]):NaN;let 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=ZK(t,i.bbColorCol,D);else if(i.bbColorMode===`categorical`){let e=D?.get(i.bbColorCol),n=new Map,r=new Int32Array(c);for(let a=0;a<c;a++){let o=String(e?e[a]:t[a]?.[i.bbColorCol]??``),s=n.get(o);s===void 0&&n.set(o,s=n.size),r[a]=s}f.colorIndex=r,f.colorLabels=[...n.keys()]}}e[r.id]=f}return e},[w,l,u,D]),xe=zt(()=>{if(!w)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 w.rows){let t=String(e[n.tmNameCol]??``),i=n.tmParentCol?String(e[n.tmParentCol]??``):``,a=e[n.tmValueCol];!t||typeof a!=`number`||!Number.isFinite(a)||r.push({name:t,parent:i,value:a})}e[t.id]=r}return e},[w,l,u]),Se=zt(()=>{if(!w)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 w.rows){let t=String(e[n.skSourceCol]??``),a=String(e[n.skTargetCol]??``),o=e[n.skValueCol];!t||!a||typeof o!=`number`||!Number.isFinite(o)||(r.add(t),r.add(a),i.push({source:t,target:a,value:o}))}e[t.id]={nodeNames:Array.from(r),links:i}}return e},[w,l,u]),Ce=zt(()=>{let e={};if(!w)return e;for(let t of l){if(t.kind!==`calibration`)continue;let n=u[t.id],r=n?.kind===`calibration`&&n.cbScoreCol?ZK(w.rows,n.cbScoreCol,D):void 0,i=n?.kind===`calibration`&&n.cbLabelCol?ZK(w.rows,n.cbLabelCol,D):void 0;if(!n||n.kind!==`calibration`||!r||!i){e[t.id]=[];continue}let a=Math.max(2,n.cbBins),o=new Float64Array(a),s=new Float64Array(a);for(let e=0;e<Math.min(r.length,i.length);e++){let t=r[e],n=i[e];if(t-t!==0||n-n!==0)continue;let c=Math.max(0,Math.min(a-1,Math.floor(t*a)));o[c]+=n,s[c]++}e[t.id]=Array.from({length:a},(e,t)=>({center:(t+.5)/a,actual:s[t]>0?o[t]/s[t]:0,count:s[t]})).filter(e=>e.count>0)}return e},[w,l,u,D]),we=zt(()=>{let e={};if(!w)return e;let t={length:0,theoretical:[],sample:[]},n=e=>{let t=QK(w.rows,e,D);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},[w,l,u,D]),Te=zt(()=>{if(!w)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 w.rows){let t=String(e[n.gtLabelCol]??``),i=e[n.gtStartCol],a=e[n.gtEndCol];if(!t||typeof i!=`number`||typeof a!=`number`||!Number.isFinite(i)||!Number.isFinite(a))continue;let o={label:t,start:i,end:a};n.gtGroupCol&&e[n.gtGroupCol]!==void 0&&(o.group=String(e[n.gtGroupCol])),r.push(o)}e[t.id]=r}return e},[w,l,u]),Ee=w&&w.columnNames.indexOf(d)>=0?w.units[w.columnNames.indexOf(d)]??``:``,De=zt(()=>w?$$(w,E?T.length:0):{},[w,E,T]);return{dataset:b,datasetWithChannels:w,multiDatasetMode:E,numericCols:R,anyDuckDb:N,duckDbLayers:L,liveConn:v,liveOverlays:P,hasLiveSelected:_,staticXRange:F,xUnit:Ee,columnUnits:De,multibandDataByPanel:V,xyPointsByPanel:ee,xyzPointsByPanel:H,histogramDataByPanel:ne,polarDataByPanel:re,spectrumDataByPanel:ie,boxplotDataByPanel:ae,spectrogramDataByPanel:oe,heatmapDataByPanel:se,violinDataByPanel:ce,confusionDataByPanel:le,rocDataByPanel:ue,lossCurveDataByPanel:de,controlChartDataByPanel:fe,parallelCoordsDataByPanel:pe,embeddingDataByPanel:me,flameGraphDataByPanel:he,barChartDataByPanel:ge,radarDataByPanel:_e,areaChartDataByPanel:ve,cdfChartDataByPanel:ye,bubbleChartDataByPanel:be,treemapDataByPanel:xe,sankeyDataByPanel:Se,calibrationDataByPanel:Ce,qqPlotDataByPanel:we,ganttDataByPanel:Te,gaugeDataByPanel:zt(()=>{let e={};if(!w)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?ZK(w.rows,n,D):void 0;if(!r)return[];let i=1/0,a=-1/0,o=0,s=0,c=NaN;for(let e=0;e<r.length;e++){let t=r[e];t-t===0&&(t<i&&(i=t),t>a&&(a=t),o+=t,s++,c=t)}let l=s===0?NaN:e.value===`mean`?o/s:e.value===`min`?i:e.value===`max`?a:c,[u,d]=i1(s?i:0,s?a:1,t(e.min),t(e.max));return[{name:n,unit:De[n]??``,value:l,min:u,max:d,alarm:e.alarm??null,color:e.color,style:e.style,fromZero:e.fill===`zero`,colorMode:e.colorMode,stops:e.stops,stat:e.value}]})}return e},[w,l,u,D,De])}}function i1(e,t,n,r){t<=e&&(t=e+1);let i=zV(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 a1=`#fb7185`,o1=2500,s1=new Float64Array;function c1(e,t){return t&&e?.kind===`spectrogram`&&e.sgView!==`waterfall`&&e.sgSignalCol!==``}function l1(e){let t=u1(e);if(t.status!==`empty`||!e.data.dataset)return t;let n=new Set([...e.data.datasetWithChannels?.columnNames??[],...e.data.numericCols]);return Cr(e.settings).some(e=>!n.has(e))?{...t,status:`missing`}:t}function u1(e){let{panel:t,data:n,settings:r}=e;if(t.kind===`camera`)return{status:`ready`,data:null,node:J(s$,{settings:r?.kind===`camera`?r:or(),live:e.live??[],selection:e.selection??[],viewXRange:e.viewXRange,xIsTime:e.xKey===O,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=Z$((d?.series??[]).filter(t=>t.column!==e.xKey),d?.layout??`overlay`),n=h.reference===`dataset`&&h.datasetId?e.findDataset(h.datasetId):void 0,r=N$(h,!!n),i=r?[...D$(t,r),...t]:t;return o(J(DK,{...m,series:i,points:[],showLatestValues:!0,liveSource:M$(e.beaconLive,e.xKey,f,h,n),envelopes:n?P$(n,e.xKey,t,r??void 0):void 0,liveZoomMode:`free`}),{series:i,points:[]})}if(n.anyDuckDb)return u.length===0?s:o(J(JK,{...m,layers:n.duckDbLayers,xKey:e.xKey,columns:f,maxPoints:o1}),{outOfCore:!0});if(!l.some(e=>e.length>0)&&!n.liveOverlays||u.length===0||!f.some(e=>n.numericCols.includes(e)))return s;let _=n.liveConn,v=null,y=n.liveOverlays,b=!_&&y&&f.length>0?S$(y,e.xKey,f,l,n.staticXRange):void 0,x=!!b&&l.length>0,S=b??(_&&f.length>0?{pull:(t,n,r,i,a,o)=>{let s=_.source.version();if(o)return(!v||v.ver!==s||v.x0!==t||v.x1!==n||v.mp!==r||v.w?.[0]!==o[0]||v.w?.[1]!==o[1])&&(v={ver:s,x0:t,x1:n,mp:r,w:o,pts:_.source.getWindowPointsSync(f,{xKey:e.xKey,x0:t,x1:n},r,o[0],o[1])}),[v.pts];if(a){let i=2**Math.ceil(Math.log2((n-t)/8)),a=Math.floor(t/i)*i,o=Math.ceil(n/i)*i,c=Math.round(r*(o-a)/(n-t));return(!v||v.ver!==s||v.x0!==a||v.x1!==o||Math.abs(v.mp-c)>c*.25)&&(v={ver:s,x0:a,x1:o,mp:c,pts:_.source.getPointsSync(f,{xKey:e.xKey,x0:a,x1:o},c),held:g(f,e=>_.source.lastKnownSync(e),a,o,_.source.latestTimeSync())}),v.held?[v.pts,v.held]:[v.pts]}(!v||v.ver!==s||v.x0!==t||v.x1!==n||v.mp!==r)&&(v={ver:s,x0:t,x1:n,mp:r,pts:_.source.getPointsSync(f,{xKey:e.xKey,x0:t,x1:n},r)});let c=I(v.pts,i);if(e.xKey!==`ElapsedTime`)return[c];let l=g(f,e=>_.source.lastKnownSync(e),t,n,Math.min(_.source.latestTimeSync(),i??1/0));return l?[c,l]:[c]},cutOnGpu:e.xKey===`ElapsedTime`,id:_.id,latestT:()=>_.source.latestTimeSync(),timeAfter:e=>_.source.timeAfterSync(e),xAtTime:t=>_.source.xAtTimeSync(e.xKey,t),xBounds:()=>{let t=_.source.xBoundsSync(e.xKey);return t.x1>t.x0?[t.x0,t.x1]:null},latestX:()=>{let t=_.source.latestSync(e.xKey);return Number.isFinite(t)?t:null},version:()=>_.source.version(),latestValues:e=>_.source.latestValuesSync(e),...e.xKey===`ElapsedTime`?{}:{windowXBounds:(t,n)=>{let r=_.source.windowXBoundsSync(e.xKey,t,n);return r&&r.x1>r.x0?[r.x0,r.x1]:null},spanForSeconds:t=>_.source.xTravelSync(e.xKey,t),bufferedSeconds:()=>{let e=_.source.xBoundsSync(`ElapsedTime`);return e.x1-e.x0}}}:void 0);return o(J(DK,{...m,points:l,envelopes:t?.envelopes,showLatestValues:n.hasLiveSelected,fullXRange:n.staticXRange,liveSource:S,liveWindowSeconds:x?null:e.liveWindowSeconds,onLiveWindowChange:x?void 0:e.onLiveWindowChange,liveZoomMode:x?`free`:`follow`}),{series:u,points:l})}case`xyzmesh`:{let t=r?.kind===`xyzmesh`?r:Nn(4),l=n.xyzPointsByPanel[c];if(!l||l.points.length<1&&!l.surface)return s;let u=!!l.surface;return o(J(eY,{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:Dn(t.xyzXScale.scaleMin,t.xyzXScale.scaleMax),yRange:Dn(t.xyzYScale.scaleMin,t.xyzYScale.scaleMax),zRange:Dn(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:Mn(a1),l=n.xyPointsByPanel.pts[c]??[];if(l.length===0)return s;let u=n.xyPointsByPanel.colorMeta[c];return o(J(Vq,{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(J(cY,{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(J(EY,{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(J(HY,{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(J(JY,{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:t,rate:l,times:u}=n.spectrogramDataByPanel[c]??{signal:[],rate:1,times:void 0},d=c1(r,!!n.liveConn)?n.liveConn:null,f=r.sgSignalCol,p=d?{version:()=>d.source.version(),samples:()=>d.source.samplesSync(f),latestT:()=>d.source.latestTimeSync(),timeAfter:e=>d.source.timeAfterSync(e),id:d.id,windowSeconds:e.liveWindowSeconds}:void 0;return!p&&t.length<r.sgWindowSize?s:r.sgView===`waterfall`?o(J(SX,{signal:t,sampleRate:l,windowSize:r.sgWindowSize,overlap:r.sgOverlap,winFunc:r.sgWinFunc,yMode:r.sgYMode,backgroundToken:i,onPlotContextMenu:a}),t):o(J(_X,{signal:p?s1:t,sampleRate:l,windowSize:r.sgWindowSize,overlap:r.sgOverlap,winFunc:r.sgWinFunc,yMode:r.sgYMode,logFreq:r.sgLogFreq,times:p?void 0:u,backgroundToken:i,onPlotContextMenu:a,live:p}),t)}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(J(VX,{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(J(YX,{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(J(rZ,{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(J(lZ,{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(J(dZ,{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(J(_Z,{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(J(CZ,{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(J(NZ,{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(J(VZ,{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(J(qZ,{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(J(ZZ,{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(J(tQ,{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(J(iQ,{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(J(dQ,{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(J(gQ,{nodes:e,backgroundToken:i,onPlotContextMenu:a}),e)}case`sankey`:{let e=n.sankeyDataByPanel[c]??{nodeNames:[],links:[]};return e.links.length===0?s:o(J(SQ,{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(J(wQ,{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(J(EQ,{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(J(VQ,{gauges:e,live:t?{latestT:()=>t.source.latestTimeSync(),timeAfter:e=>t.source.timeAfterSync(e),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(J(jQ,{tasks:e,backgroundToken:i,onPlotContextMenu:a}),e)}}return s}var d1=500,f1=10,p1=300,m1=1.12;function h1(e){let t=null,n=null,r=!1,i=!1,a=null,o=0,s=(t,n)=>{let r=e.ownerDocument.elementFromPoint(t,n);return r&&e.contains(r)?r:e},c=(e,t,n,r={})=>s(t,n).dispatchEvent(new MouseEvent(e,{bubbles:!0,cancelable:!0,clientX:t,clientY:n,...r})),l=()=>{t&&=(clearTimeout(t),null)},u=e=>Math.hypot(e[0].clientX-e[1].clientX,e[0].clientY-e[1].clientY),d=e=>{if(l(),e.touches.length===2){n=null,o=u(e.touches);return}if(e.touches.length!==1)return;let{clientX:a,clientY:s}=e.touches[0];n={x:a,y:s,t:Date.now()},r=!1,i=!1,c(`mousemove`,a,s),t=setTimeout(()=>{t=null,i=!0,c(`contextmenu`,a,s,{button:2,buttons:2})},d1)},f=e=>{if(e.touches.length===2&&o>0){e.preventDefault();let t=u(e.touches),n=t/o;if(n<m1&&n>1/m1)return;let r=(e.touches[0].clientX+e.touches[1].clientX)/2,i=(e.touches[0].clientY+e.touches[1].clientY)/2;s(r,i).dispatchEvent(new WheelEvent(`wheel`,{bubbles:!0,cancelable:!0,clientX:r,clientY:i,deltaY:n>1?-100:100})),o=t;return}if(e.touches.length!==1||!n)return;let{clientX:t,clientY:i}=e.touches[0];Math.hypot(t-n.x,i-n.y)>f1&&(r=!0,l()),c(`mousemove`,t,i)},p=e=>{if(l(),e.touches.length<2&&(o=0),e.touches.length>0||!n)return;let t=n;if(n=null,i){e.preventDefault();return}if(r||Date.now()-t.t>p1){a=null;return}let s=Date.now();if(a&&s-a.t<p1&&Math.hypot(t.x-a.x,t.y-a.y)<30){e.preventDefault(),a=null,c(`dblclick`,t.x,t.y,{detail:2});return}a={x:t.x,y:t.y,t:s}};return e.addEventListener(`touchstart`,d,{passive:!0}),e.addEventListener(`touchmove`,f,{passive:!1}),e.addEventListener(`touchend`,p,{passive:!1}),e.addEventListener(`touchcancel`,p,{passive:!1}),()=>{l(),e.removeEventListener(`touchstart`,d),e.removeEventListener(`touchmove`,f),e.removeEventListener(`touchend`,p),e.removeEventListener(`touchcancel`,p)}}var g1=500,_1=1e3;function v1(e){if(Array.isArray(e))return y1(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,y1(n)));return t<0?null:t}function y1(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 b1(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 x1({stats:e,host:t}){let[n,r]=Bt(null);if(G(()=>{let n=t.current?.ownerDocument.defaultView??window,i=0,a=0,o=0,s=-1,c=-1,l=e.renders,u=t.current?FW(t.current):0,d=f=>{c>=0&&f-s>_1&&(c=f,s=f,a=0,o=0,l=e.renders,u=t.current?FW(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>=g1){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?FW(i):0;r({fps:a*1e3/p,repaints:(m-u)*1e3/p,worstFrameMs:o,renderMs:e.lastRenderMs,rendersPerSec:(e.renders-l)*1e3/p,points:v1(e.data),domNodes:i?i.getElementsByTagName(`*`).length:0,canvasMp:s/1e6,heapMb:d?d.usedJSHeapSize/1048576:null,live:(()=>{let e=cG();return e?{age:Date.now()/1e3-e.newest,lag:e.lag,wait:e.wait,waitAge:e.waitAge}: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 J(`dl`,{className:`kymo-perf-hud`,style:S1,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`,b1(n.points)]],[`DOM nodes`,b1(n.domNodes)],[`Canvas`,`${n.canvasMp.toFixed(2)} MP`],...n.heapMb===null?[]:[[`JS heap`,`${n.heapMb.toFixed(0)} MB`]],...n.live?[[`Data age`,`${n.live.age.toFixed(2)} s`],[`Live lag`,`${n.live.lag.toFixed(2)} s`],[`Late by`,`${n.live.wait.toFixed(2)} s · ${n.live.waitAge.toFixed(0)} s ago`]]:[]].map(([e,t,n])=>Gt(`div`,{style:C1,children:[J(`dt`,{style:w1,children:e}),J(`dd`,{style:n?{...T1,color:n}:T1,children:t})]},e))})}var S1={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)`},C1={display:`flex`,justifyContent:`space-between`,gap:12},w1={color:`var(--text-muted, #8a93a6)`},T1={margin:0,fontWeight:600,textAlign:`right`},E1=[],D1=180,O1=3,k1=`data-kymo-annotation-controls`;function A1(e,t,n,r){return e.anchor===`x`&&!r?null:e.points.map(([i,a])=>[e.anchor===`x`?wG(r,i):i*t,a*n])}function j1(e,t,n,r,i){return t.map(([t,a])=>[e.anchor===`x`&&i?TG(i,t):M1(t/Math.max(1,n)),M1(a/Math.max(1,r))])}var M1=e=>Math.round(e*1e4)/1e4,N1=Pt(function({annotations:e,tool:t,plotFrame:n,onChange:r,onToolEnd:i,onSelect:a,marks:o=E1,onMarkSelect:s,markFocus:c=null}){let l=q(null),u=Vt(n.subscribe,n.get),d=u?.x?u:null,[f,p]=Bt({w:0,h:0}),[m,h]=Bt(null),[g,_]=Bt(null),[v,y]=Bt(null),b=q({annotations:e,onChange:r,onToolEnd:i,onSelect:a,tool:t,selected:m,editing:g,frame:d,size:f});b.current={annotations:e,onChange:r,onToolEnd:i,onSelect:a,tool:t,selected:m,editing:g,frame:d,size:f};let x=e=>{b.current.selected!==e&&(b.current.selected=e,h(e),b.current.onSelect(e))};K(()=>{let e=l.current;if(!e)return;let t=e.ownerDocument.defaultView??window,n=()=>p({w:e.clientWidth,h:e.clientHeight});n();let r=new t.ResizeObserver(n);return r.observe(e),()=>r.disconnect()},[]),G(()=>{t&&x(null)}),G(()=>{m&&!e.some(e=>e.id===m)&&x(null)}),G(()=>()=>{b.current.selected&&b.current.onSelect(null)},[]),G(()=>{let e=l.current?.ownerDocument;if(!e)return;let t=e=>{let{selected:t,editing:n,tool:r,annotations:i,onChange:a,onToolEnd:o}=b.current;if(!(n||H1(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)),x(null)):e.key===`Escape`&&x(null))}},n=e=>{let t=b.current.selected,n=e.target;t&&!n?.closest?.(`[data-ann-id="${CSS.escape(t)}"], [data-kymo-annotation-controls]`)&&x(null)};return e.addEventListener(`keydown`,t),e.addEventListener(`pointerdown`,n,!0),()=>{e.removeEventListener(`keydown`,t),e.removeEventListener(`pointerdown`,n,!0)}},[]);let{w:S,h:C}=f,w=e=>{let t=l.current.getBoundingClientRect();return[e.clientX-t.left,e.clientY-t.top]},T=(e,t)=>{let n=l.current.ownerDocument,r=t=>e(w(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)},E=e=>r([...b.current.annotations,e]),D=e=>r(b.current.annotations.map(t=>t.id===e.id?e:t)),O=e=>{if(!t||e.button!==0||g)return;e.preventDefault(),e.stopPropagation();let n=w(e),r={id:crypto.randomUUID(),kind:t.kind,color:t.color,width:t.width,...d?{anchor:`x`}:{}},i=e=>j1(r,e,S,C,d);if(t.kind===`text`){y({...r,points:i([n]),text:``}),_(r.id);return}let a=t.kind===`brush`?[n]:[n,n],o={...r,points:i(a)};y(o);let s=!1;T((t,n)=>{if(s||=Math.hypot(n.clientX-e.clientX,n.clientY-e.clientY)>O1,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)},y(o)},()=>{y(null),s&&o.points.length>=2&&E(o)})},k=(e,t,n)=>{let r=A1(t,S,C,d);if(!r)return;let i=w(e),a=null;T((o,s)=>{if(!a&&Math.hypot(s.clientX-e.clientX,s.clientY-e.clientY)<=O1)return;let{size:c,frame:l}=b.current;a={...t,points:j1(t,n(r,[o[0]-i[0],o[1]-i[1]],o),c.w,c.h,l)},y(a)},()=>{y(null),a&&D(a)})},A=(e,n)=>{t||e.button!==0||g===n.id||(e.preventDefault(),e.stopPropagation(),x(n.id),k(e,n,(e,[t,n])=>e.map(([e,r])=>[e+t,r+n])))},j=(e,t,n)=>{e.button===0&&(e.preventDefault(),e.stopPropagation(),k(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}))},M=e=>{t||e.kind!==`text`&&e.kind!==`box`||(x(e.id),_(e.id))},N=e=>{let t=g;_(null);let n=v&&v.id===t?v:null;if(y(null),e===null||!t)return;let i=e.replace(/\s+$/,``),a=b.current.annotations;if(n){i&&E({...n,text:i});return}let o=a.find(e=>e.id===t);o&&(!i&&o.kind===`text`?r(a.filter(e=>e.id!==t)):D(V1(o,i)))},P=e=>{r(b.current.annotations.filter(t=>t.id!==e)),x(null)},F=(v?e.some(e=>e.id===v.id)?e.map(e=>e.id===v.id?v:e):[...e,v]:e).flatMap(e=>{let t=A1(e,S,C,d);return t?[{a:e,px:t}]:[]}),I=m?F.find(e=>e.a.id===m):void 0,L=d?o.map(e=>{let t=A1(tn(e,d.x.v1),S,C,d);return{m:e,x0:Math.min(t[0][0],t[1][0]),x1:Math.max(t[0][0],t[1][0])}}):[],R=[];if(d&&c)for(let{m:e,x0:t,x1:n}of L.filter(e=>e.m.ruleId===c&&e.x1>d.left&&e.x0<d.left+d.width).sort((e,t)=>e.x0-t.x0)){let r=Math.max(d.left,t)+4;n-r<24||(!R.length||r>=R[R.length-1].left+D1)&&R.push({m:e,left:r})}let z=I&&I.a.kind!==`text`?B1(I.px):null,B=e=>t=>{if(!t)return;let n=d&&e<d.left+d.width?e+t.offsetWidth-(d.left+d.width):0;t.style.transform=n>0?`translateX(${-Math.min(n,Math.max(0,e-d.left))}px)`:``},V=e=>Gt(Wt,{children:[J(`svg`,{className:`kymo-ann-svg`,width:S,height:C,viewBox:`0 0 ${S} ${C}`,"aria-hidden":`true`,children:e.map(({a:e,px:t})=>e.kind===`text`?null:J(`g`,{"data-ann-id":e.id,className:`kymo-ann kymo-ann--${e.kind}`,onPointerDown:t=>A(t,e),onDoubleClick:()=>M(e),children:J(I1,{a:e,px:t})},e.id))}),e.map(({a:e,px:t})=>{if(e.kind!==`text`&&e.kind!==`box`)return null;let n=g===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 Gt(`div`,{"data-ann-id":e.id,ref:e.kind===`text`?B(r.left):void 0,className:`kymo-ann-text kymo-ann-text--${e.kind}${m===e.id&&e.kind===`text`?` is-selected`:``}`,style:{...r,color:e.color,fontSize:e.kind===`text`?e.width:12},onPointerDown:t=>A(t,e),onDoubleClick:()=>M(e),children:[n?J(F1,{initial:e.text??``,onDone:N}):e.text,m===e.id&&e.kind===`text`&&!n?J(P1,{onDelete:()=>P(e.id),style:{right:-11,top:-11}}):null]},`t-${e.id}`)})]});return J(`div`,{ref:l,className:`kymo-annotations${t?` is-drawing is-tool-${t.kind}`:``}`,onPointerDown:O,onContextMenu:t?e=>e.preventDefault():void 0,children:S>0&&C>0?Gt(Wt,{children:[d&&L.length?Gt(`div`,{className:`kymo-ann-clip`,style:{clipPath:`inset(0 ${Math.max(0,S-d.left-d.width)}px 0 ${Math.max(0,d.left)}px)`},children:[J(`svg`,{className:`kymo-ann-svg kymo-marks`,width:S,height:C,viewBox:`0 0 ${S} ${C}`,children:L.map(({m:e,x0:t,x1:n})=>Gt(`g`,{"data-mark":e.ruleId,role:`img`,"aria-label":`${e.late?`Late · `:``}${e.ruleName}, ${e.severity}`,className:`kymo-mark kymo-mark--${e.severity}${e.late?` kymo-mark--late`:``}${c?e.ruleId===c?` is-focus`:` is-dim`:``}`,style:{color:en[e.severity]},children:[J(`rect`,{className:`kymo-mark-fill`,x:t,y:d.top,width:Math.max(1,n-t),height:d.height,fill:`currentColor`,fillOpacity:.12}),J(`rect`,{x:t,y:d.top,width:Math.max(1,n-t),height:2,fill:`currentColor`}),J(`rect`,{className:`kymo-mark-hit`,x:t,y:d.top,width:Math.max(6,n-t),height:8,onPointerDown:t=>{t.stopPropagation(),s?.(e.ruleId)}})]},e.id))}),R.map(({m:e,left:t})=>Gt(`div`,{className:`kymo-mark-label`,style:{left:t,top:d.top+6,color:en[e.severity]},children:[e.late?`Late · `:``,e.ruleName]},`l-${e.id}`))]}):null,V(F.filter(e=>e.a.anchor!==`x`)),d?J(`div`,{className:`kymo-ann-clip`,style:{clipPath:`inset(0 ${Math.max(0,S-d.left-d.width)}px 0 ${Math.max(0,d.left)}px)`},children:V(F.filter(e=>e.a.anchor===`x`))}):null,Gt(`svg`,{className:`kymo-ann-svg`,width:S,height:C,viewBox:`0 0 ${S} ${C}`,"aria-hidden":`true`,children:[z?J(`rect`,{className:`kymo-ann-selection`,x:z.x-6,y:z.y-6,width:z.w+12,height:z.h+12,rx:4}):null,I&&!g&&(I.a.kind===`box`||I.a.kind===`arrow`)?J(`g`,{"data-ann-id":I.a.id,children:L1(I.a,I.px).map(([e,t],n)=>J(`rect`,{className:`kymo-ann-handle kymo-ann-handle--${I.a.kind===`arrow`?`end`:n%2?`nesw`:`nwse`}`,x:e-4.5,y:t-4.5,width:9,height:9,rx:2,onPointerDown:e=>j(e,I.a,n)},n))}):null]}),z&&!g?J(P1,{onDelete:()=>P(I.a.id),id:I.a.id,style:{left:Math.min(S-12,z.x+z.w+6)-10,top:Math.max(10,z.y-6)-10}}):null]}):null})});function P1({onDelete:e,style:t,id:n}){return J(`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:J(`svg`,{viewBox:`0 0 10 10`,width:`8`,height:`8`,"aria-hidden":`true`,children:J(`path`,{d:`M2 2l6 6M8 2l-6 6`})})})}function F1({initial:e,onDone:t}){let n=q(null),r=q(!1),i=e=>{r.current||(r.current=!0,t(e))};return K(()=>{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)},[]),J(`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 I1({a:e,px:t}){let n={stroke:e.color,strokeWidth:e.width,fill:`none`,strokeLinecap:`round`,strokeLinejoin:`round`},r=t=>J(`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 Gt(Wt,{children:[r(c),J(`path`,{d:c,...n}),J(`path`,{d:c,fill:e.color,fillOpacity:.06,stroke:`none`,pointerEvents:`none`})]})}case`arrow`:{let[[i,a],[o,s]]=t,c=z1(i,a,o,s,e.width);return Gt(Wt,{children:[r(`M${i} ${a}L${o} ${s}`),J(`path`,{d:`M${i} ${a}L${c.base[0]} ${c.base[1]}`,...n}),J(`path`,{d:c.d,fill:e.color,stroke:e.color,strokeWidth:1,strokeLinejoin:`round`})]})}case`brush`:{let e=R1(t);return Gt(Wt,{children:[r(e),J(`path`,{d:e,...n})]})}}return null}function L1(e,t){if(e.kind===`arrow`)return t;let[[n,r],[i,a]]=t;return[[n,r],[i,r],[i,a],[n,a]]}function R1(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 z1(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 B1(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 V1(e,t){if(t)return{...e,text:t};let{text:n,...r}=e;return r}function H1(e){let t=e;return!!t&&(t.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName))}function U1(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=A1(i,n,r,o);t&&(e.save(),i.anchor===`x`&&o&&(e.beginPath(),e.rect(o.left,0,o.width,r),e.clip()),W1(e,i,t,a),e.restore())}e.restore()}function W1(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(R1(n)));else if(t.kind===`arrow`){let r=z1(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(`
615
615
  `),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 G1={solid:void 0,dashed:`5 4`,dotted:`1 4`};function K1(e,t,n){if(!e||!(n===`x`?e.x:e.y))return null;if(n===`x`){let n=wG(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=EG(e,t.value);return r>=e.top-.5&&r<=e.top+e.height+.5?[e.left,r,e.left+e.width,r]:null}var q1=Pt(function({frame:e,alarm:t,axis:n}){let r=K1(Vt(e.subscribe,e.get),t,n);if(!r)return null;let i=t.linked?J1(r,n):null;return Gt(`svg`,{className:`kymo-alarm`,"aria-hidden":`true`,children:[J(`line`,{x1:r[0],y1:r[1],x2:r[2],y2:r[3],stroke:t.color,strokeWidth:t.width,strokeDasharray:t.linked===`active`?NG.join(` `):G1[t.style]}),i?J(`path`,{"data-alert-glyph":``,d:MG,transform:`translate(${i[0]} ${i[1]})`,fill:t.color}):null]})});function J1(e,t){return t===`y`?[e[2]-10-3,e[1]-10-2]:[e[0]+3,e[1]+2]}function Y1(e,t,n,r,i){let a=K1(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`?NG:G1[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=J1(a,r);FG(e,t[0],t[1],n.color)}e.restore()}}function X1(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,t0(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 Z1=new WeakMap;function Q1(e,t){let n=Z1.get(e);n||Z1.set(e,n=new Map);let r=n.get(t);return r||n.set(t,r=n=>e.view.setLiveWindow(n,t)),r}var $1=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=Ut(document.createElement(`div`)),this.root.render(J(s0,{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}},e0=new WeakMap;function t0(e){let t=e0.get(e);return t||(t=new $1(e),e0.set(e,t)),t}function n0(e,t,n,r={}){e.charts.get(t);let i=t0(e),a={key:crypto.randomUUID(),chartId:t,element:n,options:r,shiftDatasetId:null,emitter:LU(),xyz:null,annotationTool:null,selectedAnnotation:null,plotFrame:kG(),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 RO(`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 RO(`export_failed`,{reason:`canvas unavailable`}));for(let e of r)o.drawImage(e,0,0);let s=e.charts.get(t),c=_0(s.settings,C4(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=C0(s.annotations,d?S0(y0(u.marks,u.selection,v0(s.settings,d.xKey)),s.settings):[],l),p=yr(c);return p&&n.clientWidth>0&&Y1(o,a.plotFrame.get(),p.alarm,p.axis,i.width/n.clientWidth),f.length&&n.clientWidth>0&&U1(o,f,n.clientWidth,n.clientHeight,i.width/n.clientWidth,$.sans,l),new Promise((e,t)=>i.toBlob(n=>n?e(n):t(new RO(`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 r0(e){e0.get(e)?.refresh()}function i0(e){e0.get(e)?.dispose(),e0.delete(e)}function a0(e){let t=new MutationObserver(e);return t.observe(document.documentElement,{attributes:!0,attributeFilter:[`data-color-scheme`,`class`,`data-theme`]}),()=>t.disconnect()}var o0=()=>{let e=document.documentElement;return`${e.getAttribute(`data-color-scheme`)??``}|${e.getAttribute(`data-theme`)??``}|${e.className}`};function s0({engine:e,registry:t}){Vt(t.subscribe,t.getVersion);let n=C4(e),r=Vt(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 J(Wt,{children:[...i.values()].map(t=>J(d0,{engine:e,worksheet:t.worksheet,mounts:t.mounts},t.worksheet.id))})}var c0=1e3,l0=.25;function u0(e,t,n,r){let[i,a]=Bt(0),o=q(0),s=q(0);return G(()=>{o.current&&=(s.current=performance.now()-o.current,0)}),G(()=>{if(!n)return;let i=0,c=-1,l=0,u=n=>{if(i=jW(u),o.current||n<l||IW()||!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/l0-1),o.current=performance.now(),Ft(()=>a(e=>e+1)))};return i=jW(u),()=>MW(i)},[n,e,t]),zt(()=>n?e.map(e=>t.includes(e.id)?{...e,dataset:e.source.snapshot(c0)}:e):e,[e,t,n,i])}function d0({engine:e,worksheet:t,mounts:n}){let r=C4(e),i=Vt(r.store.subscribe,r.store.get),a=r.derived(),o=i.xRanges[t.id]??null,s=zt(()=>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=q(n);d.current=n;let f=q(()=>d.current.some(e=>e.element.isConnected&&(typeof e.element.checkVisibility!=`function`||e.element.checkVisibility()))).current,p=u0(s,i.selection,u,f),m=r.alertLines(),h=r1({worksheet:h0(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=q(FU()).current,_=Vt(a0,o0),v=t.id,y=Q1(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 J(Wt,{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=X1(n,e,v),l=_0(t.panelChartSettings[r.id],m);return Ht(J(D0,{mount:n,kind:r.kind,annotations:t.panelChartSettings[r.id]?.annotations,marks:S0(y0(i.marks,i.selection,v0(t.panelChartSettings[r.id],t.xKey)),t.panelChartSettings[r.id]),markFocus:i.markFocus,onMarkSelect:c.onMarkSelect,alarm:yr(l),onAnnotations:c.onAnnotations,onAnnotationToolEnd:c.onAnnotationToolEnd,onAnnotationSelect:c.onAnnotationSelect,render:u=>l1({panel:r,settings:l,background:n.options.style?.background??t.panelChartBackgrounds[r.id]??null,styleToken:JSON.stringify([_,n.options.theme,n.options.style,$]),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:i$(a.selectedDatasets,i.offsets),shiftMode:s?f0(e,s.id,s.name):void 0,onContextMenu:c.onContextMenu,xyzRef:c.xyzRef}),licensed:b},n.key),n.element,n.key)})})}function f0(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 p0=[],m0=new WeakMap;function h0(e,t){if(!t.size)return e;let n=m0.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]=_0(a,t),i[n]!==a&&(r=!0);let a=r?{...e,panelChartSettings:i}:e;return m0.set(e,{lines:t,out:a}),a}var g0=new WeakMap;function _0(e,t){if(!e||!t.size)return e;let n=g0.get(e);if(n&&n.lines===t)return n.out;let r=_r(e,t);return g0.set(e,{lines:t,out:r}),r}function v0(e,t){return e?.kind===`multiband`?t:e?.kind===`xyscatter`?e.xyXCol:``}var y0=w0((e,t,n)=>{let r=n?e.filter(e=>e.timeColumn===n&&t.includes(e.targetId)):b0;return r.length?r:b0}),b0=[],x0=new WeakMap;function S0(e,t){if(!e.length||!t)return e;let n=x0.get(t);if(n&&n.src===e)return n.out;let r=new Set(Cr(t)),i=e.filter(e=>!e.channels?.length||e.channels.some(e=>r.has(e))),a=i.length===e.length?e:i.length?i:b0;return x0.set(t,{src:e,out:a}),a}function C0(e,t,n){return!t.length||!n?.x?e:[...t.map(e=>tn(e,n.x.v1)),...e]}function w0(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 T0(e,t){e.data=t}function E0(e,t){e.status!==t&&(e.status=t,e.emitter.emit(`status`,t))}function D0({mount:e,kind:t,render:n,licensed:r,annotations:i,marks:a,markFocus:o,alarm:s,onAnnotations:c,onAnnotationToolEnd:l,onAnnotationSelect:u,onMarkSelect:d}){let f=q(null),[p,m]=Bt(0),h=Vt(dV,uV,()=>!1),g=!!e.options.debug,_=g||h,v=q({renderStart:0,lastRenderMs:0,renders:0,data:null}).current;_&&(v.renderStart=performance.now()),K(()=>{_&&(v.lastRenderMs=performance.now()-v.renderStart,v.renders++)}),G(()=>h?fV({kind:t,stats:v,host:f}):void 0,[h,t,v]),K(()=>{let e=f.current;if(!e)return;let t=()=>m(Math.max(120,Math.floor(e.clientHeight)));t();let n=new LW(t);n.observe(e);let r=h1(e);return()=>{n.disconnect(),r()}},[]);let{status:y,node:b,data:x}=n(p||400);v.data=x,G(()=>{T0(e,x)}),G(()=>{E0(e,y)});let{theme:S,style:C,className:w}=e.options,T={};return C?.background&&(T[`--chart-bg`]=C.background),C?.muted&&(T[`--chart-muted`]=C.muted),C?.grid&&(T[`--chart-grid`]=C.grid),C?.accent&&(T[`--accent`]=C.accent),Gt(`div`,{ref:f,onContextMenu:y===`ready`?void 0:t=>{t.preventDefault(),e.emitter.emit(`contextmenu`,{clientX:t.clientX,clientY:t.clientY})},className:w?`kymo-chart ${w}`:`kymo-chart`,"data-color-scheme":S,"data-status":y,style:T,children:[J(AG.Provider,{value:e.plotFrame.set,children:b}),y===`ready`&&s?J(q1,{frame:e.plotFrame,alarm:s.alarm,axis:s.axis}):null,y===`ready`&&(i?.length||e.annotationTool||a.length)?J(N1,{annotations:i??p0,tool:e.annotationTool,plotFrame:e.plotFrame,onChange:c,onToolEnd:l,onSelect:u,marks:a,markFocus:o,onMarkSelect:d}):null,g?J(x1,{stats:v,host:f}):null,r===!1?J(IU,{}):null]})}var O0=new WeakMap;function k0(e,t,n,r={}){let i=O0.get(e)??new Map;O0.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));for(let e of i.values())e.window.closed||e.window.focus();let c=40*(i.size+1),l=window.open(``,`kymoscope-chart-${t}`,`popup,width=${r.width??960},height=${r.height??600},left=${r.left??window.screenX+c},top=${r.top??window.screenY+c}`);if(!l)throw new RO(`popup_blocked`,{chartId:t});let u=l.document;u.head.replaceChildren(),u.body.replaceChildren(),u.title=s;for(let e of document.querySelectorAll(`style, link[rel="stylesheet"]`)){let t=e.cloneNode(!0);t instanceof HTMLLinkElement&&(t.href=e.href),u.head.appendChild(t)}let d=()=>{for(let e of[...u.documentElement.attributes])u.documentElement.removeAttribute(e.name);for(let e of document.documentElement.attributes)u.documentElement.setAttribute(e.name,e.value);u.body.className=document.body.className};d();let f=new MutationObserver(d);f.observe(document.documentElement,{attributes:!0}),f.observe(document.body,{attributes:!0,attributeFilter:[`class`]}),Object.assign(u.body.style,{margin:`0`,position:`fixed`,inset:`0`,display:`flex`,flexDirection:`column`,background:getComputedStyle(document.body).backgroundColor});let p=u.createElement(`div`);p.className=`kymo-window-controls`;let m=u.createElement(`div`);m.className=`kymo-window-plot`,Object.assign(m.style,{flex:`1`,minHeight:`0`,position:`relative`}),u.body.append(p,m),TW(l);let h=n(m,r.mount),g=LU(),_=!1,v=()=>{_||(_=!0,i.delete(t),EW(l),f.disconnect(),b(),window.removeEventListener(`pagehide`,y),h.destroy(),g.emit(`close`,void 0),g.clear())},y=()=>x.close(),b=e.subscribe(()=>{try{e.charts.get(t)}catch{x.close()}});l.addEventListener(`pagehide`,v),window.addEventListener(`pagehide`,y);let x={chartId:t,window:l,controls:p,view:h,close(){v(),l.closed||l.close()},on:(e,t)=>g.on(e,t)};return i.set(t,x),x}function A0(e){for(let t of[...O0.get(e)?.values()??[]])t.close()}function j0(e){let t=new Map;for(let[n,r]of O0.get(e)??[]){let e=r.window;e.closed||t.set(n,{left:e.screenX,top:e.screenY,width:e.innerWidth,height:e.innerHeight})}return t}var M0=12e3,N0=100;function P0(e,t=!1){let n,r=0;if(t&&e instanceof Float64Array){n=e;let t=0,i=0,a=0,o=n.length&-4;for(let e=0;e<o;e+=4)r+=n[e]*0,t+=n[e+1]*0,i+=n[e+2]*0,a+=n[e+3]*0;for(let e=o;e<n.length;e++)r+=n[e]*0;r+=t+i+a}else{n=new Float64Array(e.length);for(let t=0;t<n.length;t++){let i=+e[t];n[t]=i,r+=i*0}}if(r===0)return U.add(n),n;for(let e=0;e<n.length;e++){let t=n[e];t-t!==0&&(n[e]=NaN)}return n}function F0(e,t){let n=Object.keys(t.columns);if(n.length===0)throw new RO(`no_columns`);let r=t.columns[n[0]].length;if(n.some(e=>t.columns[e].length!==r))throw new RO(`column_length_mismatch`);let i=new Map(n.map(e=>[e,P0(t.columns[e],t.transfer)])),a=I0(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 RO(`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 I0(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,N0);t++)e.push(o.map(e=>{let r=n.get(e)[t];return r===r?String(r):``}).join(`,`));d=e.join(`
616
616
  `),f=ce(d)}let p={id:e,name:t,schema:l,rawText:d,parseConfig:f,fromColumns:!0};if(s>1e6){let e=new F$(n,r);return{...p,kind:`columnar`,source:e,data:{meta:``,columnNames:o,units:c,rows:e.sampleRowsSync(M0)}}}let m={meta:``,columnNames:o,units:c,rows:Ue({keys:o,length:s,values:o.map(e=>n.get(e)),text:o.map(()=>null)},i)};return{...p,kind:`memory`,source:new KO(m),data:m}}function L0(e,t,n){let r=e.fromColumns?R0(e):null;if(!r)throw new RO(`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)?(Xe(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{...z0(e,o,!0),columnSpares:s}}function R0(e){if(e.source instanceof F$)return new Map(e.source.columnMap);let t=we(e.data.rows);return t?new Map(t.keys.map((e,n)=>[e,t.values[n]])):null}function z0(e,t,n=!1){let r=e.fromColumns?R0(e):null;if(!r)throw new RO(`invalid_argument`,{reason:`only datasets added with addColumns can be replaced`});let i=r;for(let e of Object.keys(t))i.set(e,P0(t[e],n));let a=i.values().next().value.length;for(let e of i.values())if(e.length!==a)throw new RO(`column_length_mismatch`);let o=Object.fromEntries(e.schema.map(e=>[e.name,e.unit])),s=I0(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 B0=new WeakMap;function V0(e){let t=e.fromColumns?R0(e):null;if(!t)return e.rawText??``;let n=e.data.rows,r=B0.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(`,`));B0.set(n,r=a.join(`
617
617
  `))}return r}function H0(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 U0(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 W0(){let e=U0(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?AD(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=yH(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:NH(n.id,t),name:`${n.name} · Cycle ${t+1}`,data:r,source:new KO(r)}}),values:a.map(e=>kH(n.data.rows,e,r,i)),unit:o,isTime:i===`span`&&jH(r,o)}}return t}),t=U0((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=U0((e,t)=>e.filter(e=>e.kind===`data`&&t.includes(e.id))),r=U0(e=>b$(e.map(e=>e.data))),i=U0((e,t)=>t.length===0?e:b$(e?[e,...t.map(e=>e.dataset)]:t.map(e=>e.dataset))),a=U0((e,t,n,r)=>{let i=new Set;if(e)for(let t of n.length>0?n:[e])for(let e of w$(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=>IV(e.schema));return[...new Set([...a,...o])]});return{lapsByDataset:e,selectedDatasets:t,selectedLive:n,staticDataset:r,mergedDataset:i,mergedParts:U0((e,t)=>[...e.map(e=>e.data),...t.map(e=>e.dataset)]),numericColumns:U0((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:U0((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:U0((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 G0=[{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`}],K0=new Map(G0.map(e=>[e.kind,e.label]));function q0(e){return K0.get(e)??e}var J0=`kymoscope-live.v1`,Y0=`kymoscope-live.ack1`,X0=`kymoscope-live.ack2`,Z0=1e3,Q0=2e3,$0=3e4,e2=1e4,t2=30,n2=1e4,r2=300,i2=90,a2=e=>e.startsWith(`eyJ`);function o2(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 s2(e,t){return`${e.replace(/\/+$/,``)}/v1/streams/${t}/watch`}function c2(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=o2(r);if(a===null)return;let c=a2(r),d=c?Math.min(a,Date.now()/1e3+r2):a,f=Math.min(Math.max((d-(c?i2:t2))*1e3-Date.now(),n2),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=(e=!1)=>{if(s||a)return;let t=e?0:Math.min($0,Q0*2**c++)*(.75+Math.random()/2);a=setTimeout(()=>{a=null,f()},t)},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(s2(e.url,t),[J0,Y0,X0,`bearer.${a}`]);o.binaryType=`arraybuffer`,i=o;let f=a,p=Date.now(),m=0,h=setInterval(()=>{if(!(m===0||o.readyState!==1)){try{o.send(JSON.stringify({type:`ack`,b:m}))}catch{return}m=0}},Z0);o.onopen=()=>{r?.(`subscribed`),u(o,f)},o.onmessage=e=>{if(c=0,typeof e.data!=`string`){m+=e.data.byteLength,n(e.data);return}if(e.data.startsWith(`{"type":"probe"`))try{let t=JSON.parse(e.data).id;typeof t==`string`&&t.length<=64&&o.send(JSON.stringify({type:`ack`,id:t}))}catch{}},o.onclose=()=>{clearInterval(h),i===o&&(i=null,l(),!s&&(r?.(`error`),d(Date.now()-p>=e2)))}};return f(),()=>{if(s=!0,a&&=(clearTimeout(a),null),l(),i){let e=i;i=null,e.close(1e3)}}}var l2=960*1024,u2=24;function d2(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(u2+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=u2;return n&&(r[a++]=t.length,r.set(t,a),a+=t.length),r.set(e.payload,a),r}function f2(e){if(e.length<u2||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=u2,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 p2(e){let t=Math.max(1,Math.ceil(e.data.length/l2)),n=[];for(let r=0;r<t;r++)n.push(d2({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*l2,Math.min(e.data.length,(r+1)*l2))}));return n}var m2=8;function h2(e,t,n){let r=new Map,i=new Set,a=null,o=e=>{i.add(e.id),a=e.id,t({type:`schema`,id:e.id,names:e.channels.map(e=>e.name),units:e.channels.map(e=>e.unit)})},l=Promise.resolve(),u=n?Ct(n,e=>t({type:`integrity`,integrity:e})):null;return Object.assign(n=>{let d=E(e,n).catch(()=>null);u?.arrive(n,new Uint8Array(n,0,1)[0]&127,d),l=l.then(async()=>{try{let e=await d;if(!e)return;if(e.kind===6){let n=f2(e.plaintext);n&&t({type:`video`,m:n})}else if(e.kind===5){let t=await c(e.plaintext);if(r.delete(t.id),r.set(t.id,t),r.size>m2){let e=r.keys().next().value;r.delete(e),i.delete(e)}(t.channels.length>1e3||a!==null)&&t.id!==a&&o(t)}else if(e.kind===7){let n=await s(e.plaintext,r);n&&t({type:`last`,values:n})}else if(e.kind===4){let n=await B(e.plaintext,r);n&&t(n.historical?{type:`columns`,block:n.block,historical:!0}:{type:`columns`,block:n.block})}else if(e.kind===9){let n=await k(e.plaintext,r);if(!n||!n.index.length)return;i.has(n.schemaId)||o(r.get(n.schemaId)),t({type:`sparse`,...n})}else if(e.kind===3)t({type:`columns`,block:Ve(e.plaintext)});else if(e.kind===2){let n=j(e.plaintext);t({type:`frames`,frames:Array.isArray(n?.frames)?n.frames:[]})}}catch{}})},{reset:()=>u?.reset()})}var g2=``+new URL(`assets/liveIngestWorker-MA_RO8uZ.js`,import.meta.url).href;function _2(e,t,n,r,i){let a=()=>{let a=h2(n,r,t);return c2(e,t,a,e=>{e===`subscribed`&&a.reset(),i?.(e)})},o;try{if(typeof Worker>`u`)return a();o=zO(g2)}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 v2=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}},y2=class{#e;#t=new Set;onUse;constructor(e){this.#e=typeof e==`function`?e:()=>e}#n(e){return this.onUse?.(e),this.#e()}#r(e){return this.onUse?this.#n([e]):this.#e()}retrackCycles(){let e=this.#e();for(let t of this.#t)e.trackCycles(t)}size(){return this.#e().size}get columnNames(){return this.#e().columnNames}version(){return this.#e().version}columns(e){let t=this.#e(),n=t.firstAbs;return new x2(t,t=>{let r=this.#r(t).mirrorColumn(t);return r&&e?b2(r,n,e):r})}samplesSync(e){let t=this.#r(e),n=t.mirrorColumn(e);return n?{values:n,first:t.firstAbs}:null}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.onUse?this.#n([e.viewport.xKey,e.column]):this.#e();return qe(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.onUse?this.#n([t.xKey,...e]):this.#e()).decimateColumns(t.xKey,e,t.x0,t.x1,n)}getPointsSync(e,t,n){return(this.onUse?this.#n([t.xKey,...e]):this.#e()).decimatePoints(t.xKey,e,t.x0,t.x1,n)}getWindowPointsSync(e,t,n,r,i){return(this.onUse?this.#n([t.xKey,...e]):this.#e()).decimateWindow(t.xKey,e,t.x0,t.x1,n,r,i)}windowXBoundsSync(e,t,n){return this.#r(e).windowXBounds(e,t,n)}async xBounds(e){return this.xBoundsSync(e)}xBoundsSync(e){return this.#r(e).columnBounds(e)}xTravelSync(e,t){return this.#r(e).xTravel(e,t)}timeAfterSync(e){return this.#e().timeAfter(e)}latestTimeSync(){return this.#e().latestTime()}xAtTimeSync(e,t,n=!1){return this.#r(e).xAtTime(e,t,n)}latestSync(e){return this.#r(e).lastValue(e)}latestValuesSync(e){let t=this.#n(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.#r(e),n=t.valueBounds(e),r=t.lastKnown(e);if(!n&&!r)return null;let i=Math.min(n?.x0??1/0,r?.v??1/0),a=Math.max(n?.x1??-1/0,r?.v??-1/0);if(i!==a)return{min:i,max:a};let o=Math.max(.5,Math.abs(i)*.05);return{min:i-o,max:a+o}}lastKnownSync(e){return this.#e().lastKnown(e)}trackCycles(e){this.#t.add(e),this.#r(e).trackCycles(e)}cycleSpanSync(e){return this.#r(e).cycleSpan(e)}decimateCycleSync(e,t,n,r,i){return(this.onUse?this.#n([e,...n]):this.#e()).decimateCycle(e,t,n,r.x0,r.x1,i)}cyclePointsSync(e,t,n,r,i){return(this.onUse?this.#n([e,...n]):this.#e()).decimateCyclePoints(e,t,n,r.x0,r.x1,i)}async readColumns(e,t,n){let r=this.#n(e),i={};for(let a of e)r.has(a)&&(i[a]=r.columnValues(a).slice(t,t+n));return i}async dispose(){}};function b2(e,t,n){if(n.tail!==void 0)return e.length>n.tail?e.subarray(e.length-n.tail):e;let r=n.max??1/0;if(e.length<=r)return e;let i=Math.ceil(e.length/r),a=(i-t%i)%i,o=new Float64Array(Math.ceil((e.length-a)/i));for(let t=0,n=a;t<o.length;t++,n+=i)o[t]=e[n];return o}var x2=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)}},S2=512,C2=new WeakMap;function w2(e,t,n){let r=C2.get(e);r||C2.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 T2(e,t,n){let r=e.endAbs,i=Math.max(n,e.firstAbs);if(!(i>=r||t.length===0))for(let n of t){if(!n.enabled)continue;let a=vE(n.formula);if(!a.ok)continue;let{identifiers:o,functions:s}=yE(a.node);if(!o.every(t=>e.has(t)))continue;let c=s.some(e=>gE.includes(e)),l=Math.max(e.firstAbs,i-(c?S2:0)),u=new Map([O,...o].map(t=>[t,e.range(t,l,r)])),{carry:d,keep:f}=w2(e,`${n.id}|${n.formula}`,l),p=TE(n,e=>u.get(e),O,r-l,t,d);p.status===`ok`&&(e.writeComputed(n.name,n.units,i,p.values.subarray(i-l)),f())}}function E2(e,t){e.clearComputed(),C2.delete(e),T2(e,t,e.firstAbs)}var D2=8e3,O2=131072;function k2(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 A2=new Map;function j2(e,t){let n=`${t}|${Math.floor(e/900)}`,r=A2.get(n);r===void 0&&(r=lD(e,t),A2.size>1e4&&A2.clear(),A2.set(n,r));let i=(e+r)%86400;return i<0?i+86400:i}var M2=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`?j2(e,n.tz):n.kind===`elapsed`?e-this.#e:e<this.#e?NaN:n.kind===`event`?(this.#t!==this.#t&&t===t&&iD(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 N2(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&&iD(r.op,o,r.value)&&(a=e[t])}return{x:e.map(e=>e-a),t:e,cols:t}}let a=new M2(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 P2(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 F2(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 I2(e,t,n){let r=Math.max(2,Math.min(D2,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=P2(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 L2(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 R2=new WeakMap;function z2(e){let t=R2.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 R2.set(e,t),t}function B2(e,t,n){if(n===`minmax`)return{lo:e.min,hi:e.max};if(n===`sigma`){let n=z2(e);return{lo:e.mean.map((e,r)=>e-t*n[r]),hi:e.mean.map((e,r)=>e+t*n[r])}}let r=L2(n,e);return{lo:e.mean.map(e=>e-r),hi:e.mean.map(e=>e+r)}}function V2(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:_}=B2(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(L2(h,i),1e-9):0,C=z2(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=F2(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<F2(t.x,g,s)||a>F2(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 H2(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 U2(e,t){let n=Qe(e,{out:new Uint8Array(12+8*D2+18*Math.min(O2,t.length*D2))}),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}}function W2(e){if(!e.cycle)throw Error(`a live segment axis needs a cycle rule`);let t=new vD(e.cycle),n=new M2(e.axis),r=NaN,i=`channel`in e.axis?e.axis.channel:null,a=[...new Set([..._D(e.cycle),...i?[i]:[]])];return{feed(o,s,c=!1){let l=Math.max(s,o.firstAbs),u=o.endAbs;if(l>=u)return;let d=t=>{c||e.onEvent?.(t)},f=o.range(O,l,u),p=new Map(a.map(e=>[e,o.range(e,l,u)])),m=new Float64Array(f.length).fill(NaN),h=i?p.get(i):null,g=[];for(let e=0;e<f.length;e++){t.step(f[e],t=>{let n=p.get(t);return n?n[e]:NaN},g);let i=t.open()?.tstart??null;i!==null&&(i!==r&&(r=i,n.begin(i),d({type:`open`,tstart:i})),m[e]=n.x(f[e],h?h[e]:NaN))}for(let e of g)d({type:`close`,segment:{tstart:e.tstart,tend:e.tend,kpis:{duration:(e.tend??e.tstart)-e.tstart},...e.flags.length?{flags:e.flags}:{}}});o.writeComputed(e.column,e.unit,l,m)}}}var G2=1e7;function K2(e=globalThis.navigator?.deviceMemory){return Math.max(512,Math.round(((e??0)>0?e:16)*1024/8))}var q2=400,J2=4e3,Y2=1e3,X2=3e3,Z2=2,Q2=5e3,$2=1e4;function e4(e,t,n=`data`){let r=new M(t.capacity??G2,void 0,void 0,(t.maxMemoryMB??K2())*1024*1024);return{meta:e,buffer:r,source:new y2(()=>r),feed:null,unsub:()=>{},status:`connecting`,error:null,lastFrameAt:Date.now(),lastColCount:0,lastValued:0,recorder:null,dropped:0,recDropped:0,video:n===`camera`?new ZE:null,clock:n===`camera`?null:new v2,lagTicks:0,lastRejoinAt:0,rejoin:()=>{},subscribed:!1,releaseTimer:void 0}}function t4(e,t,n,i){let a,o=-1/0,s=new Map;return async c=>{if(a===void 0&&(a=c,s.set(t,c)),c===a)return e;if(Date.now()-o<2e3)return null;o=Date.now();let l=await i().catch(()=>null);if(!l||s.has(l.salt)&&s.get(l.salt)!==c)return null;let u=l.key??(n===null?null:await r(n,l.salt));return!u||!await Ne(u,l.key_check).catch(()=>!1)?null:(s.set(l.salt,c),u)}}function n4(e,t,n=()=>({}),i){let a=new Map,o=e,s=[],c=[],l=``,u=()=>{let e=[];for(let t of a.values())t.lastColCount=t.buffer.columnCount,t.lastValued=t.buffer.valuedCount,e.push({...t.meta,kind:t.video?`camera`:`data`,video:t.video,clock:t.clock,dataset:t.buffer.toDataset(q2),source:t.source,rowCount:t.buffer.size,status:t.status,error:t.error,recordingSince:t.recorder?.startedAt??null,droppedSamples:t.dropped,...t.integrity?{integrity:t.integrity}:{}});s=e,t(s)},d=(e,t)=>{let n=!1,r=e.buffer.endAbs;for(let r of t)r&&typeof r.t==`number`&&Array.isArray(r.signals)&&(e.buffer.push(r),e.recorder?.add(r),n=!0);n&&p(e,r,t[t.length-1]?.t)},f=(e,t)=>{let n=e.buffer.endAbs;e.buffer.pushColumns(t),e.recorder?.addColumns(t),t.t.length>0&&p(e,n,t.t[t.t.length-1])},p=(e,t,n)=>{T2(e.buffer,c,t),e.segAxis?.tracker.feed(e.buffer,t),i?.rows(e.meta.id,e.buffer,t),typeof n==`number`&&e.clock?.observe(n,Date.now()/1e3),h(e,t===0||e.buffer.columnCount!==e.lastColCount||e.buffer.valuedCount!==e.lastValued)},m=(e,t)=>{let n=e.buffer.endAbs,r=e.buffer.valuedCount,i=t();i?p(e,n,i.t[i.t.length-1]):h(e,e.buffer.valuedCount!==r)},h=(e,t)=>{e.lastFrameAt=Date.now();let n=e.status===`stale`||e.status===`connecting`;n&&(e.status=`live`),(n||t)&&u()},g=e=>{let t=a.get(e);t&&(clearTimeout(t.releaseTimer),t.unsub(),a.delete(e),u())},_=setInterval(()=>{let e=Date.now(),t=!1;for(let n of a.values()){n.status===`live`&&e-n.lastFrameAt>J2&&(n.status=`stale`,t=!0);let r=n.video&&n.subscribed&&n.status===`live`?n.video.info().lagMs:null;n.lagTicks=r!==null&&r>X2?n.lagTicks+1:0,n.video&&n.lagTicks>=Z2&&e-n.lastRejoinAt>=Q2&&(n.lagTicks=0,n.lastRejoinAt=e,n.video.resync(),n.unsub(),n.rejoin()),n.buffer.size&&i?.tick(n.meta.id,n.buffer,n.lastFrameAt)}t&&u()},Y2);return{connections:()=>s,disconnect:g,startRecording(e){let t=a.get(e);!t||t.recorder||(t.recorder=new eD,t.recDropped=0,u())},stopRecording(e){let t=a.get(e),n=t?.recorder;return!t||!n?null:(t.recorder=null,u(),{csv:n.toCsvParts(),rows:n.rows,name:t.meta.name,startedAt:n.startedAt,droppedSamples:t.recDropped})},setRelay(e){o=e},setSegmentAxis(e,t){let n=a.get(e);n&&(n.segAxis=t?{cfg:t,tracker:W2(t)}:void 0,t&&n.segAxis.tracker.feed(n.buffer,n.buffer.firstAbs,!t.replay),u())},setMathChannels(e){let t=JSON.stringify(e.map(e=>[e.id,e.name,e.units,e.formula,e.enabled]));if(t!==l){l=t,c=e;for(let t of a.values())t.video||(E2(t.buffer,e),t.segAxis&&(t.segAxis.tracker=W2(t.segAxis.cfg),t.segAxis.tracker.feed(t.buffer,t.buffer.firstAbs,!0)));a.size>0&&u()}},openLocal(e,t){let r=`local:${crypto.randomUUID()}`,i=e4({id:r,name:e,ownerName:`This page`,visibility:`private`,orgName:null,parentId:null,lowOf:null},{...n(),...t});return a.set(r,i),u(),{id:r,push:e=>{a.get(r)===i&&d(i,Array.isArray(e)?e:[e])},pushColumns:e=>{a.get(r)===i&&f(i,e)},close:()=>g(r)}},async connect(e,t,s){if(a.has(e.id))return;let l=o&&e.relay_url?{...o,url:e.relay_url,getToken:async e=>{let t=await o.getToken(e);return t&&!a2(t)?t:null}}:o;if(!l)throw new RO(`relay_unavailable`);let p;if(typeof t==`string`){let n=je(t).secret??t,i=await r(n,e.salt);if(!await Ne(i,e.key_check))throw new RO(`wrong_password`);p=s?.reload?t4(i,e.salt,n,s.reload):i}else if(p=`keyFor`in t?e=>t.keyFor(e):t,typeof p!=`function`){if(!await Ne(p,e.key_check))throw new RO(`wrong_password`);s?.reload&&(p=t4(p,e.salt,null,s.reload))}let g=e4({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,sync:e.sync??null,clockOffsetMs:e.clock_offset_ms??null},{...n(),...s},e.kind);a.set(e.id,g);let _=t=>{if(a.get(e.id)===g)if(t.type===`video`)g.video&&(g.video.push(t.m),h(g,!1));else if(t.type===`last`){let e=g.buffer;if(g.feed)g.feed.last(t.values);else for(let n of t.values)e.setLastKnown(n.name,n.unit,n.t,n.v);(e.columnCount!==g.lastColCount||e.valuedCount!==g.lastValued)&&u()}else if(t.type===`gap`)g.dropped+=t.samples,g.recorder&&(g.recDropped+=t.samples),u();else if(t.type===`integrity`){let e=g.integrity;g.integrity=t.integrity,(!e||e.broken!==t.integrity.broken)&&u()}else if(t.type===`columns`)if(t.historical)i?.historical?.(e.id,t.block);else if(g.feed){let e=[],n=[],r=[];for(let[i,a]of Object.entries(t.block.columns))for(let o=0;o<a.length;o++)Number.isFinite(a[o])&&(e.push(t.block.t[o]),n.push(i),r.push(a[o]));let i=g.feed;m(g,()=>i.pushNamed(e,n,r))}else f(g,t.block);else if(t.type===`schema`){if(!g.feed){let t=g.feed=new vt(g.buffer,g.buffer.memoryBudget/2),n=!1;g.source.onUse=r=>{!t.activate(r)||n||(n=!0,queueMicrotask(()=>{n=!1,a.get(e.id)===g&&(t.replay(),E2(g.buffer,c),g.source.retrackCycles(),g.segAxis&&(g.segAxis.tracker=W2(g.segAxis.cfg),g.segAxis.tracker.feed(g.buffer,g.buffer.firstAbs,!0)),u())}))}}g.feed.schema(t.id,t.names,t.units),u()}else if(t.type===`sparse`){if(t.historical||!g.feed)return;let e=g.feed;m(g,()=>e.push(t.schemaId,t.index,t.t,t.v))}else d(g,t.frames)},v=t=>{!g.subscribed||a.get(e.id)!==g||(t===`subscribed`?(g.status=`live`,g.lastFrameAt=Date.now()):t===`error`&&(g.status=`error`,g.error=`connection_error`),u())};g.rejoin=()=>{g.unsub=g.video?c2(l,e.id,h2(p,_),v):_2(l,e.id,p,_,v)};let y=g.video;y?(g.status=`idle`,y.onDemandChange(t=>{a.get(e.id)===g&&(clearTimeout(g.releaseTimer),t?g.subscribed||(g.subscribed=!0,y.resync(),g.status=`connecting`,g.lastFrameAt=Date.now(),g.rejoin(),u()):g.releaseTimer=setTimeout(()=>{g.subscribed=!1,g.unsub(),g.unsub=()=>{},g.status=`idle`,g.error=null,g.lagTicks=0,u()},$2))})):(g.subscribed=!0,g.rejoin()),u()},dispose(){clearInterval(_);for(let e of a.values())clearTimeout(e.releaseTimer),e.unsub();a.clear(),s=[]}}}function r4(e){return[...new Set(Object.values(e.signals??{}).flatMap(e=>`formula`in e?[e.formula]:e.channel?[e.channel]:[]))]}var i4=500,a4=1<<20;function o4(e){let t=[],n=new Map,r=new Map,i=[],a=``,o=(e,t)=>`${e}|${t}`,s=(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)},c=()=>[...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}}}),l=()=>{let t=c(),n=JSON.stringify(t);n!==a&&(a=n,e.setStates(t))};function u(n,r,a=!1){let o=t.find(e=>e.id===n.ruleId);if(n.kind===`raised`){i=[...i,{id:`${n.ruleId}|${n.target.id}|${n.t}${a?`|late`:``}`,ruleId:n.ruleId,ruleName:o?.name??``,severity:o?.severity??`info`,targetId:n.target.id,timeColumn:r,t0:n.t,t1:null,...a?{late:!0}:{},...o?{channels:r4(o)}:{}}];let e=i.filter(e=>e.targetId===n.target.id);e.length>i4&&(i=i.filter(t=>t!==e[0]))}else{let e=i.find(e=>e.ruleId===n.ruleId&&e.targetId===n.target.id&&e.t1===null&&!!e.late===a);e&&(i=i.map(t=>t===e?{...t,t1:n.t}:t))}e.setMarks(i),e.emit(a?{...n,late:!0}:n)}function d(){let i=new Set;for(let r of e.targets())for(let e of t){if(!s(e,r))continue;let t=o(e.id,r.id);i.add(t);let a=n.get(t),{channels:c,...l}=r;(!a||a.rule!==e)&&(a=Ot(e,l),n.set(t,a));for(let e of a.bind(c))u(e,r.kind===`stream`?O:``)}for(let e of n.keys())i.has(e)||n.delete(e);for(let[e,t]of r)n.get(e)?.rule!==t.rule&&r.delete(e);l()}return{setRules(n){let r=[],a=n.filter(e=>{let t=kt(e);return r.push(...t.map(t=>({ruleId:String(e?.id??``),...t}))),!t.length}),o=e.maxRules();o!==null&&a.length>o&&e.limit();let s=new Map(t.map(e=>[e.id,e]));t=(o===null?a:a.slice(0,o)).map(e=>{let t=s.get(e.id);return t&&t.version===e.version?t:e});let c=i.filter(e=>t.some(t=>t.id===e.ruleId));return c.length!==i.length&&(i=c,e.setMarks(i)),d(),r},rules:()=>t,state:c,async evaluate(n,r){let a=e.targets().find(e=>e.id===n&&e.kind===`dataset`);if(!a)return[];let{channels:o,...c}=a,l=[],d=t.filter(e=>(!r.ruleIds||r.ruleIds.includes(e.id))&&s(e,c)),f=d.map(e=>{let t=Ot(e,c);return t.bind(o),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+=a4){let i=await e.readDataset(n,[r.timeColumn,...p],t,a4),a=i[r.timeColumn];if(!a||!a.length)break;for(let e of f)l.push(...e.push({t:a,columns:i}));if(a.length<a4)break}i=i.filter(e=>!(e.targetId===n&&(!r.ruleIds||r.ruleIds.includes(e.ruleId)))),e.setMarks(i);for(let e of l)u(e,r.timeColumn);return l},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)u(e,O)}r&&l()},pushLate(t,i){let a=e.targets().find(e=>e.id===t&&e.kind===`stream`);if(!a)return;let{channels:o,...s}=a;for(let[e,a]of n){if(a.target.id!==t)continue;let n=r.get(e);(!n||n.rule!==a.rule)&&(n=Ot(a.rule,s),n.bind(o),r.set(e,n));for(let e of n.push(i))u(e,O,!0)}},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)u(e,O)}r&&l()},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:d,clearMarks(t){i=t?i.filter(e=>e.targetId!==t):[],e.setMarks(i)}}}var s4=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}},c4={maxChartsPerWorksheet:null,maxChannelsPerChart:null,maxWorksheets:null,maxMathChannels:null,maxAlertRules:null,canImportExportWorkspaces:!0};function l4(e,t,n){if(t===null)return e;let r=0;return e.filter(e=>n(e)||r++<Math.max(1,t))}var u4=[];function d4(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 f4=[`#a78bfa`,`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#94a3b8`];function p4(e=`ET`){return{id:crypto.randomUUID(),name:`Worksheet`,panels:[],panelChartSettings:{},panelChartBackgrounds:{},xKey:e}}function m4(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(Or({...e,name:a,source:`workbook`}))}return{channels:i,rename:r}}function h4(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 g4(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 _4(e,t,n){if(!e||!t)return vn();let{min:r,max:i}=LV(e.rows,t);if(!Number.isFinite(r)||!Number.isFinite(i))return vn();let a=zV(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 v4(e,t){let n=t.includes(e.xKey)?e.xKey:t.includes(`ET`)?`ET`:t.includes(`ElapsedTime`)?O: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:jn();r[n.id]={...i,kind:`multiband`,addColumn:i.addColumn&&t.includes(i.addColumn)?i.addColumn:t[0]}}else if(n.kind===`xyscatter`){let i=e&&e.kind===`xyscatter`?e:Mn(f4[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:Nn(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 y4(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 b4(){return typeof document>`u`?`dark`:hH(null)}function x4(e={}){let t={...e},n=!1,r=p4(),i=H0({datasets:[],selection:[],worksheets:[r],activeWorksheetId:r.id,xRanges:{},offsets:{},colors:{},liveWindowSeconds:15,cycleRules:[],live:[],video:[],mathChannels:[],limits:{...c4,...t.limits},exempt:[],palette:fH(t.palette,b4()),importing:0,licensed:null,history:{canUndo:!1,canRedo:!1},marks:[],markFocus:null,alerts:[],alertRules:[]}),a=LU(),o=()=>{let e=fH(t.palette,b4());i.set(t=>t.palette.join()===e.join()?t:{...t,palette:e})},s=typeof document>`u`?()=>{}:gH(null,o),c=W0(),l=()=>{if(n)throw new RO(`disposed`)},u=e=>{throw a.emit(`limit`,{reason:e}),new RO(`limit_reached`,{reason:e})},d=()=>i.get(),f=e=>d().exempt.includes(e)?c4:d().limits,p=e=>d().exempt.includes(e.id),m=(e,t,n)=>{let r=f(e).maxChannelsPerChart,i=RV(n);r!==null&&i>r&&i>RV(t)&&u(`channels-per-chart`)},h=U0((e,t)=>t===null?e:e.slice(0,t)),g=()=>{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=h(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)}},_=(e,t)=>({id:t.id,kind:t.kind,title:t.title??null,settings:e.panelChartSettings[t.id],background:e.panelChartBackgrounds[t.id]??null,annotations:e.panelChartSettings[t.id]?.annotations??u4,layout:t.rect,window:t.window??null}),v=U0((e,t,n,r)=>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=>_(e,t)),...r.includes(e.id)?{exempt:!0}:{}}))),y=U0((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:uH(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,fromLong:!!e.fromLong,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:uH(n,i.id,s(i.id,a),o),offset:r[i.id]??0,selected:t.includes(i.id),...e.cut?{cycle:d4(e.cut,a)}:{}})):null,selected:c?u===0?!1:u===l.length?!0:`partial`:t.includes(e.id)}})}),b=U0((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:uH(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,...e.integrity?{integrity:e.integrity}:{},channels:e.dataset.columnNames}))}),x=U0(e=>{let t=g();return{datasets:y(e.datasets,e.selection,e.colors,e.offsets,t.laps,t.selectedDatasets,e.palette),selection:e.selection,worksheets:v(e.worksheets,e.xRanges,e.liveWindowSeconds,e.exempt),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})(),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,markFocus:e.markFocus,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])),w=new s4({limit:100,mergeMs:500,now:()=>Date.now(),equals:(e,t)=>e.liveWindowSeconds===t.liveWindowSeconds&&S(e.worksheets,t.worksheets)&&S(e.channels,t.channels)}),T=!0,E=0,D=e=>{E++;try{e()}finally{E--}},k=e=>[e.worksheets,e.mathChannels,e.liveWindowSeconds],A=[],j=()=>{let e=d();return{worksheets:e.worksheets,channels:e.mathChannels.filter(e=>e.source===`workbook`),liveWindowSeconds:e.liveWindowSeconds,activeWorksheetId:e.activeWorksheetId}},M=()=>i.set(e=>e.history.canUndo===w.canUndo&&e.history.canRedo===w.canRedo?e:{...e,history:{canUndo:w.canUndo,canRedo:w.canRedo}}),N=()=>{if(T)return;let e=k(d());e.every((e,t)=>e===A[t])||(A=e,E?w.rebase(j()):w.observe(j()),M())},F=()=>{A=k(d()),w.clear(j()),M()},I=e=>{T=!0;let t;try{t=e()}finally{T=!1}return F(),t},L=()=>x(d());i.subscribe(()=>{N(),a.emit(`change`,L())});let R=e=>{let t=d(),n=t.worksheets.find(n=>n.id===(e??t.activeWorksheetId));if(!n)throw new RO(`not_found`,{worksheetId:e});return n},z=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 RO(`not_found`,{chartId:e})},B=(e,t)=>{let n=e=>e&&t?e.left===t.left&&e.top===t.top&&e.width===t.width&&e.height===t.height:!e&&!t,r=d().worksheets.find(t=>t.panels.some(t=>t.id===e&&!n(t.window)));r&&D(()=>V(r.id,n=>({...n,panels:n.panels.map(n=>{if(n.id!==e)return n;if(t)return{...n,window:{...t}};let{window:r,...i}=n;return i})})))},V=(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}),ee=(e,t)=>{let{ws:n}=z(e);V(n.id,n=>({...n,panelChartSettings:{...n.panelChartSettings,[e]:t(n.panelChartSettings[e])}}))},te=e=>i.set(t=>e.length===t.selection.length&&e.every((e,n)=>e===t.selection[n])?t:{...t,selection:e,xRanges:{}}),H=new Set,ne=n4(t.live?.relay,e=>{let t=e.map(e=>e.id),n=e.filter(e=>e.kind===`data`&&!H.has(e.id)).map(e=>e.id),r=[...H].filter(e=>!t.includes(e));if(H=new Set(t),i.set(t=>({...t,live:e})),r.length&&te(d().selection.filter(e=>!r.includes(e))),n.length){let e=d().selection,t=n.filter(t=>!e.includes(t));t.length&&te([...e,...t])}let a=g();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)||D(()=>V(t.id,e=>({...e,xKey:O})))}},()=>({capacity:t.live?.capacity,maxMemoryMB:t.live?.maxMemoryMB}),{rows:(e,t,n)=>{if(!de.rules().length)return;t.columnCount!==re.get(e)&&(re.set(e,t.columnCount),de.sync());let r=de.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);de.pushLive(e,{t:t.range(O,a,i),columns:o,scan:new Map})},historical:(e,t)=>{if(!de.rules().length||!t.t.length)return;let n={};for(let r of de.liveColumns(e)){let e=t.columns[r];e&&(n[r]=e instanceof Float64Array?e:Float64Array.from(e))}Object.keys(n).length&&de.pushLate(e,{t:t.t instanceof Float64Array?t.t:Float64Array.from(t.t),columns:n,scan:new Map})},tick:(e,t,n)=>{if(!de.rules().length)return;let r=t.range(O,t.endAbs-1,t.endAbs)[0];r===r&&de.tickLive(e,r+(Date.now()-n)/1e3)}}),re=new Map,U=U0((e,t)=>e.filter(e=>t.some(t=>BE([e],t.panelChartSettings,t.xKey).length>0))),W=()=>ne.setMathChannels(U(h(d().mathChannels,d().limits.maxMathChannels),d().worksheets));W(),i.subscribe(W);let ie=e=>{i.set(t=>({...t,datasets:[...t.datasets,e]})),te([...d().selection,e.id]);let t=IV(e.schema);t.length&&D(()=>i.set(e=>({...e,worksheets:e.worksheets.map(e=>v4(e,t))})))},ae=Promise.resolve(),oe=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 RO(`import_vetoed`);let{signal:s}=r;i.set(e=>({...e,importing:e.importing+o.length}));let c=ae.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 jB(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 FV({main:t,companions:i.companions,format:i.format.id},{priorInMemoryValues:CB(d().datasets),signal:s,onProgress:e=>a.emit(`import`,{file:t.name,phase:`progress`,fraction:e}),chooseChannels:r.chooseChannels,pickChannels:r.pickChannels}):[await SB(crypto.randomUUID(),t,d().datasets)??await bB(crypto.randomUUID(),t,g4,void 0,CB(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 RO(`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 RO&&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 ae=c.catch(()=>void 0),c},se=()=>setTimeout(()=>{n||r0(ot)},0),ce=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}}),te(d().selection.filter(e=>!t(e))),n.length>0&&se()},le=async(e,t,n={})=>{let[r,...i]=await FV({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}}}},de=o4({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({})}}),pe=U0((e,t)=>{let n=new Map;for(let r of e){let e=jt(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}),me=null;i.subscribe(()=>{let e=d();me&&me[0]===e.datasets&&me[1]===e.live||(me=[e.datasets,e.live],de.rules().length&&de.sync())});let he={importFiles:oe,warmImport(e={}){l(),xV(!!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 RO(`not_found`,{datasetId:e});if(!t.info?.combined||!(t.file instanceof File))throw new RO(`invalid_argument`,{reason:`only a combined multi-rate import can be split`});let n=await FV({main:t.file,companions:t.companions??[],format:t.info.importer},{priorInMemoryValues:CB(d().datasets.filter(t=>t.id!==e)),selection:t.info.selection,split:!0});ce([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 RO(`not_found`,{datasetId:e});if(!n.info||!(n.file instanceof File))throw new RO(`invalid_argument`,{reason:`only binary imports have channels to choose`});try{let r=await FV({main:n.file,companions:n.companions??[],format:n.info.importer},{priorInMemoryValues:CB(d().datasets.filter(t=>t.id!==e)),initial:n.info.selection,chooseChannels:t,pickChannels:!0});ce([e]);for(let e of r)ie(e);return r.map(e=>e.id)}catch(e){if(e instanceof RO&&e.code===`cancelled`)return null;throw e}},async combine(e){l();let t=d().datasets.find(t=>t.id===e);if(!t)throw new RO(`not_found`,{datasetId:e});let n=t.info?.splitKey;if(!n||!(t.file instanceof File))throw new RO(`invalid_argument`,{reason:`only datasets split from one file can be combined`});let r=d().datasets.filter(e=>e.info?.splitKey===n),i=await FV({main:t.file,companions:t.companions??[],format:t.info.importer},{priorInMemoryValues:CB(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 RO(`invalid_argument`,{reason:`these groups have no common time base`})}return ce(r.map(e=>e.id)),ie(i[0]),i[0].id},async openAsTable(e){l();let t=d().datasets.find(t=>t.id===e);if(!t)throw new RO(`not_found`,{datasetId:e});if(t.info?.meta.layout!==`long`||!(t.file instanceof File))throw new RO(`invalid_argument`,{reason:`only a file opened with one channel per tag can be opened as a table`});let n=CB(d().datasets.filter(t=>t.id!==e)),r=t.info.importer===`longtext`?[await bB(crypto.randomUUID(),t.file,g4,void 0,n)]:await FV({main:t.file,companions:t.companions??[],format:t.info.importer,asTable:!0},{priorInMemoryValues:n});ce([e]);for(let e of r)ie({...e,fromLong:{importer:t.info.importer}});return r.map(e=>e.id)},async openAsChannels(e){l();let t=d().datasets.find(t=>t.id===e);if(!t)throw new RO(`not_found`,{datasetId:e});if(!t.fromLong||!(t.file instanceof File))throw new RO(`invalid_argument`,{reason:`only a file opened as a table with openAsTable can be opened as one channel per tag`});let n=await FV({main:t.file,companions:t.companions??[],format:t.fromLong.importer},{priorInMemoryValues:CB(d().datasets.filter(t=>t.id!==e))});ce([e]);for(let e of n)ie(e);return n.map(e=>e.id)},async openRecording(e,t={}){l();let n=await le(e,CB(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 RO(`not_found`,{datasetId:e});let r=await le(t,CB(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),se()},addColumns(e){l();let t=F0(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 RO(`not_found`,{datasetId:e});let a=z0(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 RO(`not_found`,{datasetId:e});let a=L0(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 _B(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 RO(`not_found`,{datasetId:e});let i=await DD(r.source,n,kD(t)),a=new Map(t.filter(e=>e.kpis?.length).map(e=>[e.id,e.kpis]));return OD(i,t).map(e=>a.has(e.definitionId)?{...e,kpis:jD(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 RO(`not_found`,{datasetId:e});let r=n.schema.filter(e=>e.type===`number`&&e.name!==t.timeKey).map(e=>e.name),i=await DD(n.source,t.timeKey,r),a={...Object.fromEntries(n.schema.map(e=>[e.name,e.unit])),[TD]:`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 RO(`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(he.addColumns({name:`${n.name} · ${c}`,columns:ND(i,t.timeKey,r),units:a}))}if(t.tables!==!1){let e=FD(t.found,t.cycleId,t.defs,i);s.push(await he.addText(ID(e.cycles),`${n.name} · ${o(t.cycleId)}s.csv`)),e.phases.length&&s.push(await he.addText(ID(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 RO(`not_found`,{datasetId:e});let r;if(t){if(!t.defs.some(e=>e.id===t.cycleId))throw new RO(`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 DD(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=OD(a,t.defs).sort((e,t)=>e.tstart-t.tstart||!!e.parentIndex-+!!t.parentIndex).map(e=>c.has(e.definitionId)?{...e,kpis:jD(a,e,c.get(e.definitionId))}:e),u={...Object.fromEntries(n.schema.map(e=>[e.name,e.unit])),[TD]:`s`},d=e=>t.defs.find(t=>t.id===e)?.name??e,f=l.map(r=>F0(`${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:ND(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 te(o?c.length>0?[...s,...c]:[...s,e]:s),c.length},remove(e){l(),ce([e])},clear(){l(),ce(d().datasets.map(e=>e.id))},async configure(e,t){l();let n=d().datasets.find(t=>t.id===e);if(!n)throw new RO(`not_found`,{datasetId:e});if(t.parseConfig&&(n.kind!==`memory`||!n.parseConfig))throw new RO(`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 RO(`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?yH(n.data.rows,r.channel):[],l=r&&t.selectCycles===`best`?AH(c.map(e=>kH(n.data.rows,e,r.metric,r.stat))):null,u=l===null?c.map((t,n)=>NH(e,n)):[NH(e,l)];te(o?c.length>0?[...s,...u]:[...s,e]:s)}let r=t.parseConfig;if(!r)return;let a=(()=>{try{let e=fe(ue(n.rawText??``),r.headerRow);return n.data.columnNames.length===e.length&&n.data.columnNames.every((t,n)=>t===e[n])}catch{return!1}})();if(P(r,n.parseConfig)&&a)return;let o=n.fromColumns?V0(n):n.rawText??``,s=await UO(n.file?{file:n.file,config:r}:{rawText:o,config:r}),c=new KO(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),se(),n.cut&&await he.cut(e,n.cut);let p=g().selectedDatasets,m=new Set(p.flatMap(e=>e.data.columnNames)),h=s.columnNames.filter(e=>C(s.rows,e)),_=h.find(e=>e===`ET`)??h[0];D(()=>i.set(e=>({...e,worksheets:e.worksheets.map(e=>y4(!m.has(e.xKey)&&_?{...e,xKey:_}:e,e=>m.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(),te([...e])},toggle(e){l();let t=d().selection,n=g().laps[e];if(n){let e=n.laps.map(e=>e.id);te(e.every(e=>t.includes(e))?t.filter(t=>!e.includes(t)):[...t,...e.filter(e=>!t.includes(e))]);return}te(t.includes(e)?t.filter(t=>t!==e):[...t,e])},selectAll(){l();let e=g().laps,t=d().live.filter(e=>d().selection.includes(e.id)).map(e=>e.id);te([...d().datasets.flatMap(t=>e[t.id]?e[t.id].laps.map(e=>e.id):[t.id]),...t])},deselectAll(){l(),te([])},raw(e){let t=d().datasets.find(t=>t.id===e);if(!t)throw new RO(`not_found`,{datasetId:e});return{get rawText(){return t.kind===`memory`&&t.fromColumns?V0(t):t.rawText??``},data:t.data,parseConfig:t.parseConfig??null,kind:t.kind,beacon:t.beacon??null}},async columnBounds(e){l();let t=g(),n=t.selectedDatasets.find(t=>t.schema.some(t=>t.name===e));if(n&&n.kind===`memory`){let t=LV(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=ge(e);if(!i)return null;let a=LV(i.rows,e);return Number.isFinite(a.min)&&Number.isFinite(a.max)?a:null}},ge=(e,t=R().xKey)=>{let n=g();if(!n.merged)return null;if(!n.channels.find(t=>t.name===e))return n.merged;let r=zE(n.merged,n.channels,t);return{...n.merged,columnNames:[...n.merged.columnNames,...r.ok.map(e=>e.name)],rows:r.rows}},_e=(e,t,n)=>g().selectedLive.length>0?{...n,scaleMin:``,scaleMax:``,majorStep:``,minorStep:``}:_4(ge(e,t),e,n),ve={fromFileList:e=>uU(Array.from(e)),async fromDataTransfer(e){return dU(Array.from(e.items??[]).map(e=>e.webkitGetAsEntry?.()).filter(e=>!!e))},canPick:fU,pick:pU,tree:(e,t)=>lU(e,t),isImportable:cU},ye=(e,t)=>{l();let n=d(),r=n.limits.maxWorksheets;!t&&r!==null&&n.worksheets.filter(e=>!p(e)).length>=r&&u(`worksheets`);let a={...p4(R().xKey||`ET`),name:e};return i.set(e=>({...e,worksheets:[...e.worksheets,a],activeWorksheetId:a.id,exempt:t?[...e.exempt,a.id]:e.exempt})),a.id},be={add(e=`Worksheet`){return ye(e,!1)},rename(e,t){l(),R(e),V(e,e=>e.name===t?e:{...e,name:t})},remove(e){l();let t=d();if(R(e),t.worksheets.length<=1)throw new RO(`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(),R(e),i.set(t=>t.activeWorksheetId===e?t:{...t,activeWorksheetId:e})},setXKey(e,t){l(),R(e),V(e,e=>y4({...e,xKey:t},e=>e!==t)),i.set(t=>({...t,xRanges:{...t.xRanges,[e]:null},offsets:{}}))}},xe={mount(e,t,n){return l(),n0(ot,e,t,n)},openWindow(e,t){l(),z(e);let n=z(e).panel.window;return k0(ot,e,(t,n)=>n0(ot,e,t,n),{...n,...t})},recordWindows(){l();let e=j0(ot);for(let t of d().worksheets)for(let n of t.panels)B(n.id,e.get(n.id)??null)},setFonts(e){e.sans&&($.sans=e.sans),e.mono&&($.mono=e.mono),r0(ot)},kinds:()=>G0,label:q0,add(e,t={}){if(l(),!G0.some(t=>t.kind===e))throw new RO(`invalid_argument`,{kind:e});let n=R(t.worksheetId),r=f(n.id).maxChartsPerWorksheet;r!==null&&n.panels.length>=r&&u(`charts-per-worksheet`);let i={...hn(e,n.panels),...t.title?{title:t.title}:{}};t.layout&&(i.rect={...t.layout});let a=Sr([i],{},f4[2],4)[i.id],o=a,s=g().numericColumns;if(s.length&&(o.kind===`multiband`||o.kind===`xyscatter`||o.kind===`xyzmesh`)&&(o=v4({...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??_e(o.xyXCol,n.xKey,o.xyXScale),xyYScale:e.xyYScale??_e(o.xyYCol,n.xKey,o.xyYScale)}}return m(n.id,a,o),V(n.id,e=>({...e,panels:t.layout?[...e.panels,i]:_n([...e.panels,i]),panelChartSettings:{...e.panelChartSettings,[i.id]:o}})),i.id},remove(e){l();let{ws:t}=z(e);V(t.id,t=>{let n={...t.panelChartSettings},r={...t.panelChartBackgrounds};return delete n[e],delete r[e],{...t,panels:_n(t.panels.filter(t=>t.id!==e)),panelChartSettings:n,panelChartBackgrounds:r}})},rename(e,t){l();let{ws:n}=z(e),r=t?.trim()||void 0;V(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}=z(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:_e(e.xyXCol,n.xKey,r.xyXScale)}),typeof e.xyYCol==`string`&&e.xyYCol!==r.xyYCol&&!(`xyYScale`in e)&&(i={...i,xyYScale:_e(e.xyYCol,n.xKey,r.xyYScale)})}m(n.id,r,i),ee(e,()=>i)},replaceSettings(e,t){l();let{ws:n,panel:r}=z(e);if(t.kind!==r.kind)throw new RO(`invalid_argument`,{reason:`settings kind mismatch`});m(n.id,n.panelChartSettings[e],t),ee(e,()=>t)},setBackground(e,t){l();let{ws:n}=z(e);V(n.id,n=>({...n,panelChartBackgrounds:{...n.panelChartBackgrounds,[e]:t}}))},addAnnotation(e,t){l(),z(e);let n=Zt({...t,id:t.id||crypto.randomUUID()});if(!n)throw new RO(`invalid_argument`,{reason:`not a valid annotation`});return ee(e,e=>({...e,annotations:[...(e.annotations??[]).filter(e=>e.id!==n.id),n]})),n.id},updateAnnotation(e,t,n){l();let r=(z(e).ws.panelChartSettings[e]?.annotations??[]).find(e=>e.id===t);if(!r)throw new RO(`not_found`,{annotationId:t});let i=Zt({...r,...n,id:r.id,kind:r.kind});if(!i)throw new RO(`invalid_argument`,{reason:`not a valid annotation`});ee(e,e=>({...e,annotations:(e.annotations??[]).map(e=>e.id===i.id?i:e)}))},removeAnnotation(e,t){l(),z(e),ee(e,e=>({...e,annotations:(e.annotations??[]).filter(e=>e.id!==t)}))},setAnnotations(e,t){l(),z(e);let n=Qt(t)??[];ee(e,e=>({...e,annotations:n}))},setLayout(e,t){l();let{ws:n}=z(e);V(n.id,n=>({...n,panels:n.panels.map(n=>n.id===e?{...n,rect:{...t}}:n)}))},setLayouts(e,t){l(),V(e,e=>({...e,panels:e.panels.map(e=>t[e.id]?{...e,rect:{...t[e.id]}}:e)}))},autoLayout(e){l(),V(R(e).id,e=>({...e,panels:_n(e.panels)}))},get(e){let{ws:t,panel:n}=z(e);return _(t,n)},list(e){let t=R(e);return t.panels.map(e=>_(t,e))},async addSeries(e,t){l();let{ws:n}=z(e),r=n.panelChartSettings[e];if(!r||r.kind!==`multiband`)throw new RO(`invalid_argument`,{reason:`not a multiband chart`});let i=f(n.id).maxChannelsPerChart;i!==null&&RV(r)>=i&&u(`channels-per-chart`);let a=g().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&&a.length>0)return null;let c=Dr(),d={id:c,column:s,color:f4[r.series.length%f4.length],bandFromPct:0,bandToPct:100,scaleMin:0,scaleMax:+!!s,yMajorStep:0,yMinorStep:0};return ee(e,e=>e.kind===`multiband`?{...e,series:[...e.series,d]}:e),await xe.autoScaleSeries(e,c),c},async updateSeries(e,t,n){l();let{ws:r}=z(e),i=r.panelChartSettings[e],a=i&&i.kind===`multiband`?i.series.find(e=>e.id===t):void 0;if(!a)throw new RO(`not_found`,{seriesId:t});ee(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 xe.autoScaleSeries(e,t)},removeSeries(e,t){l(),ee(e,e=>e.kind===`multiband`?{...e,series:e.series.filter(e=>e.id!==t)}:e)},reorderSeries(e,t){l(),ee(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}=z(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 he.columnBounds(a.column);!o||n||ee(e,e=>e.kind===`multiband`?{...e,series:e.series.map(e=>e.id===t?{...e,scaleMin:o.min,scaleMax:o.max}:e)}:e)}},Se=new Set;i.subscribe(()=>{let e=new Set(g().numericColumns);if(e.size!==0){for(let t of d().worksheets)for(let[n,r]of Object.entries(t.panelChartSettings))if(r.kind===`multiband`)for(let t of r.series){let r=`${t.id}