@kymoscope/sdk 0.7.0 → 0.8.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,$t as t,A as n,At as r,B as i,Bt as a,C as o,Ct as s,D as c,Dt as l,E as u,Et as d,F as f,G as p,Gt as m,H as h,Ht as g,I as _,J as v,Jt as y,K as b,Kt as x,L as S,M as C,N as w,O as T,Ot as E,P as D,Q as O,Qt as k,R as A,S as j,St as M,T as N,Tt as P,U as F,Ut as I,V as L,Vt as R,W as z,Wt as B,X as V,Xt as ee,Y as te,Yt as H,Z as ne,Zt as re,_ as ie,_t as U,a as ae,at as oe,b as se,bt as ce,c as le,ct as ue,d as de,dt as fe,en as pe,et as me,f as he,ft as ge,g as _e,gt as ve,h as ye,ht as be,i as xe,it as Se,j as Ce,jt as we,k as Te,kt as Ee,l as De,lt as Oe,m as ke,mt as Ae,n as je,nn as Me,nt as Ne,o as Pe,ot as Fe,p as Ie,pt as Le,q as Re,qt as ze,r as Be,rt as Ve,st as He,tn as Ue,tt as We,u as Ge,ut as Ke,v as qe,w as Je,x as Ye,y as Xe,yt as Ze,z as Qe,zt as $e}from"./keys-Ckhja7xC.js";import{i as et,n as tt,r as nt,t as rt}from"./threshold-C9it0Y7P.js";import{createContext as it,forwardRef as at,memo as ot,startTransition as st,useCallback as ct,useContext as lt,useEffect as W,useImperativeHandle as ut,useLayoutEffect as G,useMemo as dt,useRef as K,useState as ft,useSyncExternalStore as pt}from"react";import{createPortal as mt}from"react-dom";import{createRoot as ht}from"react-dom/client";import{Fragment as gt,jsx as q,jsxs as _t}from"react/jsx-runtime";var vt=Object.create,yt=Object.defineProperty,bt=Object.getOwnPropertyDescriptor,xt=Object.getOwnPropertyNames,St=Object.getPrototypeOf,Ct=Object.prototype.hasOwnProperty,wt=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Tt=(e,t)=>{let n={};for(var r in e)yt(n,r,{get:e[r],enumerable:!0});return t||yt(n,Symbol.toStringTag,{value:`Module`}),n},Et=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=xt(t),a=0,o=i.length,s;a<o;a++)s=i[a],!Ct.call(e,s)&&s!==n&&yt(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=bt(t,s))||r.enumerable});return e},Dt=(e,t,n)=>(n=e==null?{}:vt(St(e)),Et(t||!e||!e.__esModule?yt(n,`default`,{value:e,enumerable:!0}):n,e)),Ot=[`text`,`brush`,`arrow`,`box`],kt={text:14,brush:3,arrow:2,box:2},At=/^#[0-9a-fA-F]{6}$/,jt={text:[1,1],arrow:[2,2],box:[2,2],brush:[2,1/0]},Mt=e=>typeof e==`number`&&Number.isFinite(e);function Nt(e){if(!e||typeof e!=`object`)return null;let t=e,n=t.kind;if(!Ot.includes(n)||typeof t.id!=`string`||!t.id||!Array.isArray(t.points))return null;let r=t.points.filter(e=>Array.isArray(e)&&Mt(e[0])&&Mt(e[1])).map(([e,t])=>[e,t]),[i,a]=jt[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`&&At.test(t.color)?t.color:`#f5a524`,width:Mt(t.width)&&t.width>0?Math.min(96,t.width):kt[n],...typeof t.text==`string`&&t.text!==``?{text:t.text}:{}}}function Pt(e){return Array.isArray(e)?e.map(Nt).filter(e=>e!==null):null}var Ft={info:`#8a93a6`,warning:`#f5a524`,critical:`#e5484d`},It={info:`var(--text-muted, #8a93a6)`,warning:`var(--accent, #f5a524)`,critical:`var(--danger, #e5484d)`};function Lt(e,t){return{id:`mark:${e.id}`,kind:`box`,anchor:`x`,points:[[e.t0,0],[e.t1??t,1]],color:Ft[e.severity],width:1,...e.ruleName?{text:e.ruleName}:{}}}var Rt=96,zt=96,Bt=2,Vt={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},Ht={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},Ut=Vt,Wt=Ht;function Gt(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 Kt(e,t,n,r=96){let i=Vt[e],a=Ht[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 qt(e,t,n,r,i,a,o=96,s=96){let c=Math.round(r/Math.max(1e-6,a.width/o)),l=Math.round(i/Math.max(1e-6,a.height/s));return n===`move`?Kt(e,{...t,x:t.x+c,y:t.y+l},o,s):{...t,w:Math.max(Vt[e],Math.min(t.w+c,o-t.x)),h:Math.max(Ht[e],Math.min(t.h+l,s-t.y))}}function Jt(e,t,n){for(let r of t)if(r.id!==n&&Gt(e,r.rect))return!0;return!1}function Yt(e,t,n=96){let r=Vt[e],i=Ht[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=Kt(e,{x:s,y:i,w:a,h:o},n);if(!Jt(r,t,``))return r}return Kt(e,{x:0,y:0,w:r,h:i},n)}function Xt(e,t){return{id:crypto.randomUUID(),kind:e,rect:Yt(e,t)}}function Zt(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=Zt(e-4).map(e=>({x:e.x*.5,y:e.y,w:e.w*.5,h:e.h})),n=Zt(4).map(e=>({x:.5+e.x*.5,y:e.y,w:e.w*.5,h:e.h}));return[...t,...n]}function Qt(e,t=96,n=96){let r=Zt(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 $t(){return{scaleMin:``,scaleMax:``,majorStep:``,minorStep:``,alarm:null}}var en={style:`dashed`,width:1,color:null},tn={style:`solid`,width:1,color:null},nn={enabled:!1,reference:`previous`,datasetId:null,datasetColor:`#94a3b8`,previousColor:`#64748b`},rn=/^#[0-9a-f]{6}$/i;function an(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`&&rn.test(t.datasetColor)?t.datasetColor:nn.datasetColor,previousColor:typeof t.previousColor==`string`&&rn.test(t.previousColor)?t.previousColor:nn.previousColor}}var on=[`#f5a524`,`#38bdf8`,`#22c55e`,`#f472b6`,`#a78bfa`,`#fb7185`];function sn(e,t){return{id:crypto.randomUUID(),column:e,color:on[t%on.length],value:`last`,style:`arc`,min:``,max:``}}function cn(e,t){if(!e||typeof e!=`object`)return null;let n=e;if(typeof n.column!=`string`)return null;let r=Zn(n.alarm);return{id:typeof n.id==`string`&&n.id?n.id:`g${t}`,column:n.column,color:typeof n.color==`string`?n.color:on[t%on.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 ln(e,t){let n=parseFloat(e),r=parseFloat(t);return Number.isFinite(n)&&Number.isFinite(r)&&n<r?[n,r]:void 0}var un=1.8,dn=4,fn=1;function pn(){return{kind:`multiband`,series:[],addColumn:``,layout:`overlay`,xAxisLine:{...en},yAxisLine:{...en},gridLine:{...tn},lineWidth:1}}function mn(e){return{kind:`xyscatter`,xyXCol:``,xyYCol:``,xyColorCol:null,xyColor:e,xyPointRadius:un,xyXAxisLine:{...en},xyYAxisLine:{...en},xyGridLine:{...tn},xyFit:null,xyXScale:$t(),xyYScale:$t()}}function hn(e=4){return{kind:`xyzmesh`,xyzXCol:``,xyzYCol:``,xyzZCol:``,xyzViewMode:`3d`,xyzXScale:$t(),xyzYScale:$t(),xyzZScale:$t(),xyzPointRadius:e,showMesh:!1,meshStyle:`filled`,meshOpacity:.85}}function gn(){return{kind:`histogram`,histColumn:``,histBins:0,histColor:`#38bdf8`,histNormal:!1,histLogY:!1}}function _n(){return{kind:`polar`,polarAngleCol:``,polarRadiusCol:``,polarColor:`#a78bfa`,polarMode:`waveform`,polarRadiusMin:``,polarRadiusMax:``}}function vn(){return{kind:`spectrum`,specSignalCol:``,specTimeCol:``,specSampleRate:`1000`,specXMode:`hz`,specYMode:`amplitude`,specWindow:`hann`,specColor:`#34d399`,specLogX:!1}}function yn(){return{kind:`boxplot`,boxValueCol:``,boxGroupCol:``,boxColor:`#fb923c`,boxWhiskers:`1.5iqr`}}function bn(){return{kind:`spectrogram`,sgSignalCol:``,sgTimeCol:``,sgSampleRate:`1000`,sgWindowSize:512,sgOverlap:.5,sgWinFunc:`hann`,sgYMode:`db`,sgLogFreq:!1}}function xn(){return{kind:`heatmap`,hmMode:`binned`,hmColumns:[],hmXCol:``,hmYCol:``,hmValueCol:``,hmXBins:6,hmYBins:6,hmXMin:``,hmXMax:``,hmYMin:``,hmYMax:``,hmShowValues:!0,hmColorScheme:`diverging`}}function Sn(){return{kind:`violin`,vlValueCol:``,vlGroupCol:``,vlColor:`#818cf8`,vlShowBox:!0,vlBandwidth:``,vlOrientation:`vertical`}}function Cn(){return{kind:`confusion`,cfActualCol:``,cfPredictedCol:``,cfNormalize:!1}}function wn(){return{kind:`roc`,rocScoreCol:``,rocLabelCol:``,rocMode:`roc`,rocColor:`#f472b6`}}function Tn(){return{kind:`losscurve`,lcXCol:``,lcLeftCols:[],lcRightCols:[]}}function En(){return{kind:`controlchart`,ccValueCol:``,ccSubgroupCol:``,ccSigmaLevel:3,ccColor:`#22d3ee`}}function Dn(){return{kind:`parallelcoords`,pcColumns:[],pcColorByCol:``,pcColor:`#64748b`}}function On(){return{kind:`embedding`,emXCol:``,emYCol:``,emColorCol:``,emColorMode:`categorical`,emLabelCol:``,emPointSize:3,emColor:`#a78bfa`}}function kn(){return{kind:`flamegraph`,fgNameCol:``,fgParentCol:``,fgValueCol:``,fgDirection:`topdown`}}function An(){return{kind:`barchart`,bcCategoryCol:``,bcValueCols:[],bcMode:`grouped`,bcHorizontal:!1}}function jn(){return{kind:`radar`,rdAxesCols:[],rdGroupCol:``,rdColor:`#38bdf8`,rdFill:!0}}function Mn(){return{kind:`areachart`,acXCol:``,acYCols:[],acStacked:!1}}function Nn(){return{kind:`cdfchart`,cdValueCols:[],cdComplement:!1,cdLogX:!1}}function Pn(){return{kind:`bubblechart`,bbXCol:``,bbYCol:``,bbSizeCol:``,bbColorCol:``,bbColorMode:`categorical`,bbColor:`#64748b`,bbMaxRadius:24}}function Fn(){return{kind:`treemap`,tmNameCol:``,tmParentCol:``,tmValueCol:``}}function In(){return{kind:`sankey`,skSourceCol:``,skTargetCol:``,skValueCol:``}}function Ln(){return{kind:`gauge`,ggGauges:[]}}function Rn(){return{kind:`calibration`,cbScoreCol:``,cbLabelCol:``,cbBins:10,cbColor:`#38bdf8`}}function zn(){return{kind:`qqplot`,qqValueCol:``,qqMode:`normal`,qqRefCol:``,qqColor:`#a78bfa`}}function Bn(){return{kind:`gantt`,gtLabelCol:``,gtStartCol:``,gtEndCol:``,gtGroupCol:``}}function Vn(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 Hn=()=>({kind:`camera`,cameraStreamId:``,cameras:[],syncStreamId:``,offsetMs:0,fit:`contain`}),Un=9;function Wn(e){return e.cameraStreamId?e.cameras?.[0]===e.cameraStreamId?e.cameras.slice(0,9):[e.cameraStreamId]:[]}function Gn(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 Kn(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 qn(e,t){return Kn(e)?e:{...t}}function Jn(e){if(!e||typeof e!=`object`)return!1;let t=e;return t.kind===`multiband`&&Array.isArray(t.series)&&t.series.every(Gn)&&typeof t.addColumn==`string`}function Yn(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 Xn(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 Zn(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`&&Qn.test(t.ruleId)?{ruleId:t.ruleId}:{}}}var Qn=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function $n(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 er){let t=er[e.kind],n=r(i[t]);n!==i[t]&&o(t,n)}return a||e}var er={histogram:`histAlarm`,spectrum:`specAlarm`,areachart:`acAlarm`,losscurve:`lcAlarm`,cdfchart:`cdAlarm`,bubblechart:`bbAlarm`,boxplot:`boxAlarm`,violin:`vlAlarm`,barchart:`bcAlarm`,gantt:`gtAlarm`};function tr(e){if(!e||!(e.kind in er))return null;let t=e[er[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 nr(e){let t=$t();if(!e||typeof e!=`object`)return t;let n=e,r=Zn(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 rr(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(Jn(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:Zn(e.alarm)}:e):e.series,addColumn:e.addColumn,layout:e.layout===`parallel`?`parallel`:`overlay`,xAxisLine:qn(e.xAxisLine,en),yAxisLine:qn(e.yAxisLine,en),gridLine:qn(e.gridLine,tn),lineWidth:typeof e.lineWidth==`number`&&Number.isFinite(e.lineWidth)?Math.min(6,Math.max(.5,e.lineWidth)):1,...an(e.beacon)?{beacon:an(e.beacon)}:{},...e.envelope===!0?{envelope:!0}:{}}}else if(Yn(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:qn(e.xyXAxisLine,en),xyYAxisLine:qn(e.xyYAxisLine,en),xyGridLine:qn(e.xyGridLine,tn),xyFit:a,xyXScale:nr(e.xyXScale),xyYScale:nr(e.xyYScale)}}else if(Xn(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??nr(n.xyzXScale),xyzYScale:a??nr(n.xyzYScale),xyzZScale:o??nr(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=cn(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:Wn({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]?Pt(n?.annotations):null;e?.length&&(r[t]={...r[t],annotations:e});let i=r[t]?er[r[t].kind]:void 0,a=i?Zn(n[i]):null;i&&a&&(r[t]={...r[t],[i]:a})}return r}function ir(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]=pn(),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]=hn(r),a=!0)}else if(t.kind===`histogram`){let e=i[t.id];(!e||e.kind!==`histogram`)&&(i[t.id]=gn(),a=!0)}else if(t.kind===`polar`){let e=i[t.id];(!e||e.kind!==`polar`)&&(i[t.id]=_n(),a=!0)}else if(t.kind===`spectrum`){let e=i[t.id];(!e||e.kind!==`spectrum`)&&(i[t.id]=vn(),a=!0)}else if(t.kind===`boxplot`){let e=i[t.id];(!e||e.kind!==`boxplot`)&&(i[t.id]=yn(),a=!0)}else t.kind===`spectrogram`?(!i[t.id]||i[t.id].kind!==`spectrogram`)&&(i[t.id]=bn(),a=!0):t.kind===`heatmap`?(!i[t.id]||i[t.id].kind!==`heatmap`)&&(i[t.id]=xn(),a=!0):t.kind===`violin`?(!i[t.id]||i[t.id].kind!==`violin`)&&(i[t.id]=Sn(),a=!0):t.kind===`confusion`?(!i[t.id]||i[t.id].kind!==`confusion`)&&(i[t.id]=Cn(),a=!0):t.kind===`roc`?(!i[t.id]||i[t.id].kind!==`roc`)&&(i[t.id]=wn(),a=!0):t.kind===`losscurve`?(!i[t.id]||i[t.id].kind!==`losscurve`)&&(i[t.id]=Tn(),a=!0):t.kind===`controlchart`?(!i[t.id]||i[t.id].kind!==`controlchart`)&&(i[t.id]=En(),a=!0):t.kind===`parallelcoords`?(!i[t.id]||i[t.id].kind!==`parallelcoords`)&&(i[t.id]=Dn(),a=!0):t.kind===`embedding`?(!i[t.id]||i[t.id].kind!==`embedding`)&&(i[t.id]=On(),a=!0):t.kind===`flamegraph`?(!i[t.id]||i[t.id].kind!==`flamegraph`)&&(i[t.id]=kn(),a=!0):t.kind===`barchart`?(!i[t.id]||i[t.id].kind!==`barchart`)&&(i[t.id]=An(),a=!0):t.kind===`radar`?(!i[t.id]||i[t.id].kind!==`radar`)&&(i[t.id]=jn(),a=!0):t.kind===`areachart`?(!i[t.id]||i[t.id].kind!==`areachart`)&&(i[t.id]=Mn(),a=!0):t.kind===`cdfchart`?(!i[t.id]||i[t.id].kind!==`cdfchart`)&&(i[t.id]=Nn(),a=!0):t.kind===`bubblechart`?(!i[t.id]||i[t.id].kind!==`bubblechart`)&&(i[t.id]=Pn(),a=!0):t.kind===`treemap`?(!i[t.id]||i[t.id].kind!==`treemap`)&&(i[t.id]=Fn(),a=!0):t.kind===`sankey`?(!i[t.id]||i[t.id].kind!==`sankey`)&&(i[t.id]=In(),a=!0):t.kind===`gauge`?(!i[t.id]||i[t.id].kind!==`gauge`)&&(i[t.id]=Ln(),a=!0):t.kind===`calibration`?(!i[t.id]||i[t.id].kind!==`calibration`)&&(i[t.id]=Rn(),a=!0):t.kind===`qqplot`?(!i[t.id]||i[t.id].kind!==`qqplot`)&&(i[t.id]=zn(),a=!0):t.kind===`gantt`?(!i[t.id]||i[t.id].kind!==`gantt`)&&(i[t.id]=Bn(),a=!0):t.kind===`camera`&&(!i[t.id]||i[t.id].kind!==`camera`)&&(i[t.id]=Hn(),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 ar(e){return e===null||typeof e==`number`&&e>0?{liveWindowSeconds:e}:{}}function or(e){return Number.isNaN(e)?0:Math.min(100,Math.max(0,e))}function sr(){return crypto.randomUUID()}function cr(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 lr(){return lr=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},lr.apply(null,arguments)}var ur={relTol:1e-12,absTol:1e-15,matrix:`Matrix`,number:`number`,numberFallback:`number`,precision:64,predictable:!1,randomSeed:null,legacySubset:!1};function dr(e,t){if(pr(e,t)||mr(e,t))return e[t];throw _r(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 fr(e,t,n){if(pr(e,t)||mr(e,t))return e[t]=n,n;throw Error(`No access to property "${t}"`)}function pr(e,t){return vr(e)?!(t in Object.prototype):!1}function mr(e,t){return Array.isArray(e)?typeof t==`number`||typeof t==`string`&&hr(t)||t===`length`:!1}function hr(e){return/^\d+$/.test(e)}function gr(e,t){if(!_r(e,t))throw Error(`No access to method "`+t+`"`);return e[t]}function _r(e,t){return e==null||typeof e[t]!=`function`||Ti(e,t)&&Object.getPrototypeOf&&t in Object.getPrototypeOf(e)?!1:yr.has(t)?!0:!(t in Object.prototype||t in Function.prototype)}function vr(e){return typeof e==`object`&&e&&e.constructor===Object}var yr=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 dr(this.wrappedObject,e)}set(e,t){return fr(this.wrappedObject,e,t),this}has(e){return pr(this.wrappedObject,e)&&e in this.wrappedObject}entries(){return Sr(this.keys(),e=>[e,this.get(e)])}forEach(e){for(var t of this.keys())e(this.get(t),t,this)}delete(e){pr(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}},xr=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 Sr(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 Sr(e,t){return{next:()=>{var n=e.next();return n.done?n:{value:t(n.value),done:!1}}}}function Cr(){return new Map}function wr(e){if(!e)return Cr();if(qr(e))return e;if(Kr(e))return new br(e);throw Error(`createMap can create maps from objects or Maps`)}function Tr(e){if(e instanceof br)return e.wrappedObject;var t={};for(var n of e.keys())fr(t,n,e.get(n));return t}function Er(e){return typeof e==`number`}function Dr(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 Or(e){return typeof e==`bigint`}function kr(e){return e&&typeof e==`object`&&Object.getPrototypeOf(e).isComplex===!0||!1}function Ar(e){return e&&typeof e==`object`&&Object.getPrototypeOf(e).isFraction===!0||!1}function jr(e){return e&&e.constructor.prototype.isUnit===!0||!1}function Mr(e){return typeof e==`string`}var Nr=Array.isArray;function Pr(e){return e&&e.constructor.prototype.isMatrix===!0||!1}function Fr(e){return Array.isArray(e)||Pr(e)}function Ir(e){return e&&e.isDenseMatrix&&e.constructor.prototype.isMatrix===!0||!1}function Lr(e){return e&&e.isSparseMatrix&&e.constructor.prototype.isMatrix===!0||!1}function Rr(e){return e&&e.constructor.prototype.isRange===!0||!1}function zr(e){return e&&e.constructor.prototype.isIndex===!0||!1}function Br(e){return typeof e==`boolean`}function Vr(e){return e&&e.constructor.prototype.isResultSet===!0||!1}function Hr(e){return e&&e.constructor.prototype.isHelp===!0||!1}function Ur(e){return typeof e==`function`}function Wr(e){return e instanceof Date}function Gr(e){return e instanceof RegExp}function Kr(e){return!!(e&&typeof e==`object`&&e.constructor===Object&&!kr(e)&&!Ar(e))}function qr(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 Jr(e){return qr(e)&&qr(e.a)&&qr(e.b)}function Yr(e){return qr(e)&&Kr(e.wrappedObject)}function Xr(e){return e===null}function Zr(e){return e===void 0}function Qr(e){return e&&e.isAccessorNode===!0&&e.constructor.prototype.isNode===!0||!1}function $r(e){return e&&e.isArrayNode===!0&&e.constructor.prototype.isNode===!0||!1}function ei(e){return e&&e.isAssignmentNode===!0&&e.constructor.prototype.isNode===!0||!1}function ti(e){return e&&e.isBlockNode===!0&&e.constructor.prototype.isNode===!0||!1}function ni(e){return e&&e.isConditionalNode===!0&&e.constructor.prototype.isNode===!0||!1}function ri(e){return e&&e.isConstantNode===!0&&e.constructor.prototype.isNode===!0||!1}function ii(e){return ri(e)||ui(e)&&e.args.length===1&&ri(e.args[0])&&`-+~`.includes(e.op)}function ai(e){return e&&e.isFunctionAssignmentNode===!0&&e.constructor.prototype.isNode===!0||!1}function oi(e){return e&&e.isFunctionNode===!0&&e.constructor.prototype.isNode===!0||!1}function si(e){return e&&e.isIndexNode===!0&&e.constructor.prototype.isNode===!0||!1}function ci(e){return e&&e.isNode===!0&&e.constructor.prototype.isNode===!0||!1}function li(e){return e&&e.isObjectNode===!0&&e.constructor.prototype.isNode===!0||!1}function ui(e){return e&&e.isOperatorNode===!0&&e.constructor.prototype.isNode===!0||!1}function di(e){return e&&e.isParenthesisNode===!0&&e.constructor.prototype.isNode===!0||!1}function fi(e){return e&&e.isRangeNode===!0&&e.constructor.prototype.isNode===!0||!1}function pi(e){return e&&e.isRelationalNode===!0&&e.constructor.prototype.isNode===!0||!1}function mi(e){return e&&e.isSymbolNode===!0&&e.constructor.prototype.isNode===!0||!1}function hi(e){return e&&e.constructor.prototype.isChain===!0||!1}function gi(e){var t=typeof e;return t===`object`?e===null?`null`:Dr(e)?`BigNumber`:e.constructor&&e.constructor.name?e.constructor.name:`Object`:t}function _i(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 _i(e)});if(e instanceof Date)return new Date(e.valueOf());if(Dr(e))return e;if(Kr(e))return vi(e,_i);if(t===`function`)return e;throw TypeError(`Cannot clone: unknown type of value (value: ${e})`)}function vi(e,t){var n={};for(var r in e)Ti(e,r)&&(n[r]=t(e[r]));return n}function yi(e,t){for(var n in t)Ti(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(Ti(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 xi(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(!xi(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)||!xi(e[n],t[n]))return!1;for(n in t)if(!(n in e))return!1;return!0}else return e===t}function Si(e){var t={};return Ci(e,t),t}function Ci(e,t){for(var n in e)if(Ti(e,n)){var r=e[n];typeof r==`object`&&r?Ci(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 Ti(e,t){return e&&Object.hasOwnProperty.call(e,t)}function Ei(e){return e&&typeof e.factory==`function`}function Di(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 Oi=[`Matrix`,`Array`],ki=[`number`,`BigNumber`,`bigint`,`Fraction`];function Ai(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=_i(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=_i(e);ji(r,`matrix`,Oi),ji(r,`number`,ki),bi(e,r);var o=_i(e);return t(`config`,o,a,_i(r)),o}else return _i(e)}return n.MATRIX_OPTIONS=Oi,n.NUMBER_OPTIONS=ki,Object.keys(ur).forEach(t=>{Object.defineProperty(n,t,{get:()=>e[t],enumerable:!0,configurable:!0})}),n}function ji(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 Mi=wt(((e,t)=>{(function(n,r){typeof e==`object`&&t!==void 0?t.exports=r():typeof define==`function`&&define.amd?define(r):(n=typeof globalThis<`u`?globalThis:n||self,n.typed=r())})(e,(function(){function e(){return!0}function t(){return!1}function n(){}let r=`Argument is not a typed-function.`;function i(){function a(e){return typeof e==`object`&&!!e&&e.constructor===Object}let o=[{name:`number`,test:function(e){return typeof e==`number`}},{name:`string`,test:function(e){return typeof e==`string`}},{name:`boolean`,test:function(e){return typeof e==`boolean`}},{name:`Function`,test:function(e){return typeof e==`function`}},{name:`Array`,test:Array.isArray},{name:`Date`,test:function(e){return e instanceof Date}},{name:`RegExp`,test:function(e){return e instanceof RegExp}},{name:`Object`,test:a},{name:`null`,test:function(e){return e===null}},{name:`undefined`,test:function(e){return e===void 0}}],s={name:`any`,test:e,isAny:!0},c,l,u=0,d={createCount:0};function f(e){let t=c.get(e);if(t)return t;let n=`Unknown type "`+e+`"`,r=e.toLowerCase(),i;for(i of l)if(i.toLowerCase()===r){n+=`. Did you mean "`+i+`" ?`;break}throw TypeError(n)}function p(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:`any`,n=t?f(t).index:l.length,r=[];for(let t=0;t<e.length;++t){if(!e[t]||typeof e[t].name!=`string`||typeof e[t].test!=`function`)throw TypeError(`Object with properties {name: string, test: function} expected`);let i=e[t].name;if(c.has(i))throw TypeError(`Duplicate type name "`+i+`"`);r.push(i),c.set(i,{name:i,test:e[t].test,isAny:e[t].isAny,index:n+t,conversionsTo:[]})}let i=l.slice(n);l=l.slice(0,n).concat(r).concat(i);for(let e=n+r.length;e<l.length;++e)c.get(l[e]).index=e}function m(){c=new Map,l=[],u=0,p([s],!1)}m(),p(o);function h(){let e;for(e of l)c.get(e).conversionsTo=[];u=0}function g(e){let t=l.filter(t=>{let n=c.get(t);return!n.isAny&&n.test(e)});return t.length?t:[`any`]}function _(e){return e&&typeof e==`function`&&`_typedFunctionData`in e}function v(e,t,n){if(!_(e))throw TypeError(r);let i=n&&n.exact,a=T(Array.isArray(t)?t.join(`,`):t),o=x(a);if(!i||o in e.signatures){let t=e._typedFunctionData.signatureMap.get(o);if(t)return t}let s=a.length,c;if(i){c=[];let t;for(t in e.signatures)c.push(e._typedFunctionData.signatureMap.get(t))}else c=e._typedFunctionData.signatures;for(let e=0;e<s;++e){let t=a[e],n=[],r;for(r of c){let i=k(r.params,e);if(!(!i||t.restParam&&!i.restParam)){if(!i.hasAny){let e=w(i);if(t.types.some(t=>!e.has(t.name)))continue}n.push(r)}}if(c=n,c.length===0)break}let l;for(l of c)if(l.params.length<=s)return l;throw TypeError(`Signature not found (signature: `+(e.name||`unnamed`)+`(`+x(a,`, `)+`))`)}function y(e,t,n){return v(e,t,n).implementation}function b(e,t){let n=f(t);if(n.test(e))return e;let r=n.conversionsTo;if(r.length===0)throw Error(`There are no conversions to `+t+` defined.`);for(let t=0;t<r.length;t++)if(f(r[t].from).test(e))return r[t].convert(e);throw Error(`Cannot convert `+e+` to `+t)}function x(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:`,`;return e.map(e=>e.name).join(t)}function S(e){let t=e.indexOf(`...`)===0,n=(t?e.length>3?e.slice(3):`any`:e).split(`|`).map(e=>f(e.trim())),r=!1,i=t?`...`:``;return{types:n.map(function(e){return r=e.isAny||r,i+=e.name+`|`,{name:e.name,typeIndex:e.index,test:e.test,isAny:e.isAny,conversion:null,conversionIndex:-1}}),name:i.slice(0,-1),hasAny:r,hasConversion:!1,restParam:t}}function C(e){let t=R(e.types.map(e=>e.name)),n=e.hasAny,r=e.name,i=t.map(function(e){let t=f(e.from);return n=t.isAny||n,r+=`|`+e.from,{name:e.from,typeIndex:t.index,test:t.test,isAny:t.isAny,conversion:e,conversionIndex:e.index}});return{types:e.types.concat(i),name:r,hasAny:n,hasConversion:i.length>0,restParam:e.restParam}}function w(e){return e.typeSet||(e.typeSet=new Set,e.types.forEach(t=>e.typeSet.add(t.name))),e.typeSet}function T(e){let t=[];if(typeof e!=`string`)throw TypeError(`Signatures must be strings`);let n=e.trim();if(n===``)return t;let r=n.split(`,`);for(let e=0;e<r.length;++e){let n=S(r[e].trim());if(n.restParam&&e!==r.length-1)throw SyntaxError(`Unexpected rest parameter "`+r[e]+`": only allowed for the last parameter`);if(n.types.length===0)return null;t.push(n)}return t}function E(e){let t=oe(e);return t?t.restParam:!1}function D(t){if(!t||t.types.length===0)return e;if(t.types.length===1)return f(t.types[0].name).test;if(t.types.length===2){let e=f(t.types[0].name).test,n=f(t.types[1].name).test;return function(t){return e(t)||n(t)}}else{let e=t.types.map(function(e){return f(e.name).test});return function(t){for(let n=0;n<e.length;n++)if(e[n](t))return!0;return!1}}}function O(e){let t,n,r;if(E(e)){t=ae(e).map(D);let n=t.length,r=D(oe(e)),i=function(e){for(let t=n;t<e.length;t++)if(!r(e[t]))return!1;return!0};return function(e){for(let n=0;n<t.length;n++)if(!t[n](e[n]))return!1;return i(e)&&e.length>=n+1}}else if(e.length===0)return function(e){return e.length===0};else if(e.length===1)return n=D(e[0]),function(e){return n(e[0])&&e.length===1};else if(e.length===2)return n=D(e[0]),r=D(e[1]),function(e){return n(e[0])&&r(e[1])&&e.length===2};else return t=e.map(D),function(e){for(let n=0;n<t.length;n++)if(!t[n](e[n]))return!1;return e.length===t.length}}function k(e,t){return t<e.length?e[t]:E(e)?oe(e):null}function A(e,t){let n=k(e,t);return n?w(n):new Set}function j(e){return e.conversion===null||e.conversion===void 0}function M(e,t){let n=new Set;return e.forEach(e=>{let r=A(e.params,t),i;for(i of r)n.add(i)}),n.has(`any`)?[`any`]:Array.from(n)}function N(e,t,n){let r,i,a=e||`unnamed`,o=n,s;for(s=0;s<t.length;s++){let e=[];if(o.forEach(n=>{let r=D(k(n.params,s));(s<n.params.length||E(n.params))&&r(t[s])&&e.push(n)}),e.length===0){if(i=M(o,s),i.length>0){let e=g(t[s]);return r=TypeError(`Unexpected type of argument in function `+a+` (expected: `+i.join(` or `)+`, actual: `+e.join(` | `)+`, index: `+s+`)`),r.data={category:`wrongType`,fn:a,index:s,actual:e,expected:i},r}}else o=e}let c=o.map(function(e){return E(e.params)?1/0:e.params.length});if(t.length<Math.min.apply(null,c))return i=M(o,s),r=TypeError(`Too few arguments in function `+a+` (expected: `+i.join(` or `)+`, index: `+t.length+`)`),r.data={category:`tooFewArgs`,fn:a,index:t.length,expected:i},r;let l=Math.max.apply(null,c);if(t.length>l)return r=TypeError(`Too many arguments in function `+a+` (expected: `+l+`, actual: `+t.length+`)`),r.data={category:`tooManyArgs`,fn:a,index:t.length,expectedLength:l},r;let u=[];for(let e=0;e<t.length;++e)u.push(g(t[e]).join(`|`));return r=TypeError(`Arguments of type "`+u.join(`, `)+`" do not match any of the defined signatures of function `+a+`.`),r.data={category:`mismatch`,actual:u},r}function P(e){let t=l.length+1;for(let n=0;n<e.types.length;n++)t=Math.min(t,e.types[n].typeIndex);return t}function F(e){let t=u+1;for(let n=0;n<e.types.length;n++)j(e.types[n])||(t=Math.min(t,e.types[n].conversionIndex));return t}function I(e,t){if(e.hasAny){if(!t.hasAny)return .1}else if(t.hasAny)return-.1;if(e.restParam){if(!t.restParam)return .01}else if(t.restParam)return-.01;let n=P(e)-P(t);if(n<0)return-.001;if(n>0)return .001;let r=F(e),i=F(t);if(e.hasConversion){if(!t.hasConversion)return(1+r)*1e-6}else if(t.hasConversion)return-(1+i)*1e-6;let a=r-i;return a<0?-1e-7:a>0?1e-7:0}function L(e,t){let n=e.params,r=t.params,i=oe(n),a=oe(r),o=E(n),s=E(r);if(o&&i.hasAny){if(!s||!a.hasAny)return 1e7}else if(s&&a.hasAny)return-1e7;let c=0,l=0,u;for(u of n)u.hasAny&&++c,u.hasConversion&&++l;let d=0,f=0;for(u of r)u.hasAny&&++d,u.hasConversion&&++f;if(c!==d)return(c-d)*1e6;if(o&&i.hasConversion){if(!s||!a.hasConversion)return 1e5}else if(s&&a.hasConversion)return-1e5;if(l!==f)return(l-f)*1e4;if(o){if(!s)return 1e3}else if(s)return-1e3;let p=(n.length-r.length)*(o?-100:100);if(p!==0)return p;let m=[],h=0;for(let e=0;e<n.length;++e){let t=I(n[e],r[e]);m.push(t),h+=t}if(h!==0)return(h<0?-10:10)+h;let g,_=9,v=_/(m.length+1);for(g of m){if(g!==0)return(g<0?-_:_)+g;_-=v}return 0}function R(e){if(e.length===0)return[];let t=e.map(f);if(e.length===1)return t[0].conversionsTo;let n=new Set(e),r=new Set;for(let e=0;e<t.length;++e)for(let i of t[e].conversionsTo)n.has(i.from)||r.add(i.from);let i=[];for(let e of r){let n=u+1,r=null;for(let i=0;i<t.length;++i)for(let a of t[i].conversionsTo)a.from===e&&a.index<n&&(n=a.index,r=a);i.push(r)}return i}function z(e,t){let n=t,r=``;if(e.some(e=>e.hasConversion)){let i=E(e),a=e.map(B);r=a.map(e=>e.name).join(`;`),n=function(){let e=[],n=i?arguments.length-1:arguments.length;for(let t=0;t<n;t++)e[t]=a[t](arguments[t]);return i&&(e[n]=arguments[n].map(a[n])),t.apply(this,e)}}let i=n;if(E(e)){let t=e.length-1;i=function(){return n.apply(this,se(arguments,0,t).concat([se(arguments,t)]))}}return r&&Object.defineProperty(i,`name`,{value:r}),i}function B(e){let t,n,r,i,a=[],o=[],s=``;e.types.forEach(function(e){e.conversion&&(s+=e.conversion.from+`~>`+e.conversion.to+`,`,a.push(f(e.conversion.from).test),o.push(e.conversion.convert))}),s=s?s.slice(0,-1):`pass`;let c=e=>e;switch(o.length){case 0:break;case 1:t=a[0],r=o[0],c=function(e){return t(e)?r(e):e};break;case 2:t=a[0],n=a[1],r=o[0],i=o[1],c=function(e){return t(e)?r(e):n(e)?i(e):e};break;default:c=function(e){for(let t=0;t<o.length;t++)if(a[t](e))return o[t](e);return e}}return Object.defineProperty(c,`name`,{value:s}),c}function V(e){function t(e,n,r){if(n<e.length){let i=e[n],a=[];if(i.restParam){let e=i.types.filter(j);e.length<i.types.length&&a.push({types:e,name:`...`+e.map(e=>e.name).join(`|`),hasAny:e.some(e=>e.isAny),hasConversion:!1,restParam:!0}),a.push(i)}else a=i.types.map(function(e){return{types:[e],name:e.name,hasAny:e.isAny,hasConversion:e.conversion,restParam:!1}});return le(a,function(i){return t(e,n+1,r.concat([i]))})}else return[r]}return t(e,0,[])}function ee(e,t){let n=Math.max(e.length,t.length);for(let r=0;r<n;r++){let n=A(e,r),i=A(t,r),a=!1,o;for(o of i)if(n.has(o)){a=!0;break}if(!a)return!1}let r=e.length,i=t.length,a=E(e),o=E(t);return a?o?r===i:i>=r:o?r>=i:r===i}function te(e){return e.map(e=>me(e)?fe(e.referToSelf.callback):pe(e)?de(e.referTo.references,e.referTo.callback):e)}function H(e,t,n){let r=[],i;for(i of e){let e=n[i];if(typeof e!=`number`)throw TypeError(`No definition for referenced signature "`+i+`"`);if(e=t[e],typeof e!=`function`)return!1;r.push(e)}return r}function ne(e,t,n){let r=te(e),i=Array(r.length).fill(!1),a=!0;for(;a;){a=!1;let e=!0;for(let o=0;o<r.length;++o){if(i[o])continue;let s=r[o];if(me(s))r[o]=s.referToSelf.callback(n),r[o].referToSelf=s.referToSelf,i[o]=!0,e=!1;else if(pe(s)){let n=H(s.referTo.references,r,t);n?(r[o]=s.referTo.callback.apply(this,n),r[o].referTo=s.referTo,i[o]=!0,e=!1):a=!0}}if(e&&a)throw SyntaxError(`Circular reference detected in resolving typed.referTo`)}return r}function re(e){let t=/\bthis(\(|\.signatures\b)/;Object.keys(e).forEach(n=>{let r=e[n];if(t.test(r.toString()))throw SyntaxError("Using `this` to self-reference a function is deprecated since typed-function@3. Use typed.referTo and typed.referToSelf instead.")})}function ie(e,r){if(d.createCount++,Object.keys(r).length===0)throw SyntaxError(`No signatures provided`);d.warnAgainstDeprecatedThis&&re(r);let i=[],a=[],o={},s=[],c;for(c in r){if(!Object.prototype.hasOwnProperty.call(r,c))continue;let e=T(c);if(!e)continue;i.forEach(function(t){if(ee(t,e))throw TypeError(`Conflicting signatures "`+x(t)+`" and "`+x(e)+`".`)}),i.push(e);let t=a.length;a.push(r[c]);let n=e.map(C),l;for(l of V(n)){let e=x(l);s.push({params:l,name:e,fn:t}),l.every(e=>!e.hasConversion)&&(o[e]=t)}}s.sort(L);let l=ne(a,o,ve),u;for(u in o)Object.prototype.hasOwnProperty.call(o,u)&&(o[u]=l[o[u]]);let f=[],p=new Map;for(u of s)p.has(u.name)||(u.fn=l[u.fn],f.push(u),p.set(u.name,u));let m=f[0]&&f[0].params.length<=2&&!E(f[0].params),h=f[1]&&f[1].params.length<=2&&!E(f[1].params),g=f[2]&&f[2].params.length<=2&&!E(f[2].params),_=f[3]&&f[3].params.length<=2&&!E(f[3].params),v=f[4]&&f[4].params.length<=2&&!E(f[4].params),y=f[5]&&f[5].params.length<=2&&!E(f[5].params),b=m&&h&&g&&_&&v&&y;for(let e=0;e<f.length;++e)f[e].test=O(f[e].params);let S=m?D(f[0].params[0]):t,w=h?D(f[1].params[0]):t,k=g?D(f[2].params[0]):t,A=_?D(f[3].params[0]):t,j=v?D(f[4].params[0]):t,M=y?D(f[5].params[0]):t,N=m?D(f[0].params[1]):t,P=h?D(f[1].params[1]):t,F=g?D(f[2].params[1]):t,I=_?D(f[3].params[1]):t,R=v?D(f[4].params[1]):t,B=y?D(f[5].params[1]):t;for(let e=0;e<f.length;++e)f[e].implementation=z(f[e].params,f[e].fn);let te=m?f[0].implementation:n,H=h?f[1].implementation:n,ie=g?f[2].implementation:n,U=_?f[3].implementation:n,ae=v?f[4].implementation:n,oe=y?f[5].implementation:n,se=m?f[0].params.length:-1,ce=h?f[1].params.length:-1,le=g?f[2].params.length:-1,ue=_?f[3].params.length:-1,de=v?f[4].params.length:-1,fe=y?f[5].params.length:-1,pe=b?6:0,me=f.length,he=f.map(e=>e.test),ge=f.map(e=>e.implementation),_e=function(){for(let e=pe;e<me;e++)if(he[e](arguments))return ge[e].apply(this,arguments);return d.onMismatch(e,arguments,f)};function ve(e,t){return arguments.length===se&&S(e)&&N(t)?te.apply(this,arguments):arguments.length===ce&&w(e)&&P(t)?H.apply(this,arguments):arguments.length===le&&k(e)&&F(t)?ie.apply(this,arguments):arguments.length===ue&&A(e)&&I(t)?U.apply(this,arguments):arguments.length===de&&j(e)&&R(t)?ae.apply(this,arguments):arguments.length===fe&&M(e)&&B(t)?oe.apply(this,arguments):_e.apply(this,arguments)}try{Object.defineProperty(ve,`name`,{value:e})}catch{}return ve.signatures=o,ve._typedFunctionData={signatures:f,signatureMap:p},ve}function U(e,t,n){throw N(e,t,n)}function ae(e){return se(e,0,e.length-1)}function oe(e){return e[e.length-1]}function se(e,t,n){return Array.prototype.slice.call(e,t,n)}function ce(e,t){for(let n=0;n<e.length;n++)if(t(e[n]))return e[n]}function le(e,t){return Array.prototype.concat.apply([],e.map(t))}function ue(){let e=ae(arguments).map(e=>x(T(e))),t=oe(arguments);if(typeof t!=`function`)throw TypeError(`Callback function expected as last argument`);return de(e,t)}function de(e,t){return{referTo:{references:e,callback:t}}}function fe(e){if(typeof e!=`function`)throw TypeError(`Callback function expected as first argument`);return{referToSelf:{callback:e}}}function pe(e){return e&&typeof e.referTo==`object`&&Array.isArray(e.referTo.references)&&typeof e.referTo.callback==`function`}function me(e){return e&&typeof e.referToSelf==`object`&&typeof e.referToSelf.callback==`function`}function he(e,t){if(!e)return t;if(t&&t!==e){let n=Error(`Function names do not match (expected: `+e+`, actual: `+t+`)`);throw n.data={actual:t,expected:e},n}return e}function ge(e){let t;for(let n in e)Object.prototype.hasOwnProperty.call(e,n)&&(_(e[n])||typeof e[n].signature==`string`)&&(t=he(t,e[n].name));return t}function _e(e,t){let n;for(n in t)if(Object.prototype.hasOwnProperty.call(t,n)){if(n in e&&t[n]!==e[n]){let r=Error(`Signature "`+n+`" is defined twice`);throw r.data={signature:n,sourceFunction:t[n],destFunction:e[n]},r}e[n]=t[n]}}let ve=d;d=function(e){let t=typeof e==`string`,n=+!!t,r=t?e:``,i={};for(let e=n;e<arguments.length;++e){let n=arguments[e],o={},s;if(typeof n==`function`?(s=n.name,typeof n.signature==`string`?o[n.signature]=n:_(n)&&(o=n.signatures)):a(n)&&(o=n,t||(s=ge(n))),Object.keys(o).length===0){let t=TypeError(`Argument to 'typed' at index `+e+` is not a (typed) function, nor an object with signatures as keys and functions as values.`);throw t.data={index:e,argument:n},t}t||(r=he(r,s)),_e(i,o)}return ie(r||``,i)},d.create=i,d.createCount=ve.createCount,d.onMismatch=U,d.throwMismatchError=U,d.createError=N,d.clear=m,d.clearConversions=h,d.addTypes=p,d._findType=f,d.referTo=ue,d.referToSelf=fe,d.convert=b,d.findSignature=v,d.find=y,d.isTypedFunction=_,d.warnAgainstDeprecatedThis=!0,d.addType=function(e,t){let n=`any`;t!==!1&&c.has(`Object`)&&(n=`Object`),d.addTypes([e],n)};function ye(e){if(!e||typeof e.from!=`string`||typeof e.to!=`string`||typeof e.convert!=`function`)throw TypeError(`Object with properties {from: string, to: string, convert: function} expected`);if(e.to===e.from)throw SyntaxError(`Illegal to define conversion from "`+e.from+`" to itself.`)}return d.addConversion=function(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{override:!1};ye(e);let n=f(e.to),r=n.conversionsTo.find(t=>t.from===e.from);if(r)if(t&&t.override)d.removeConversion({from:r.from,to:e.to,convert:r.convert});else throw Error(`There is already a conversion from "`+e.from+`" to "`+n.name+`"`);n.conversionsTo.push({from:e.from,to:n.name,convert:e.convert,index:u++})},d.addConversions=function(e,t){e.forEach(e=>d.addConversion(e,t))},d.removeConversion=function(e){ye(e);let t=f(e.to),n=ce(t.conversionsTo,t=>t.from===e.from);if(!n)throw Error(`Attempt to remove nonexistent conversion from `+e.from+` to `+e.to);if(n.convert!==e.convert)throw Error(`Conversion to remove does not match existing conversion`);let r=t.conversionsTo.indexOf(n);t.conversionsTo.splice(r,1)},d.resolve=function(e,t){if(!_(e))throw TypeError(r);let n=e._typedFunctionData.signatures;for(let e=0;e<n.length;++e)if(n[e].test(t))return n[e];return null},d}return i()}))}));function J(e,t,n,r){function i(r){var i=Di(r,t.map(Ii));return Pi(e,t,r),n(i)}return i.isFactory=!0,i.fn=e,i.dependencies=t.slice().sort(),r&&(i.meta=r),i}function Ni(e){return typeof e==`function`&&typeof e.fn==`string`&&Array.isArray(e.dependencies)}function Pi(e,t,n){if(!t.filter(e=>!Fi(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 Fi(e){return e&&e[0]===`?`}function Ii(e){return e&&e[0]===`?`?e.slice(1):e}function Li(e){return typeof e==`boolean`?!0:Number.isFinite(e)?e===Math.round(e):!1}function Ri(e,t){if(t.number===`bigint`)try{BigInt(e)}catch{return t.numberFallback}return t.number}var zi=Math.sign||function(e){return e>0?1:e<0?-1:0},Bi=Math.log2||function(e){return Math.log(e)/Math.LN2},Vi=Math.log10||function(e){return Math.log(e)/Math.LN10},Hi=Math.log1p||function(e){return Math.log(e+1)},Ui=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},Wi=Math.expm1||function(e){return e>=2e-4||e<=-2e-4?Math.exp(e)-1:e+e*e/2+e*e*e/6};function Gi(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(!Li(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(!Li(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 Ki(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}=qi(t);switch(n){case`fixed`:return Xi(e,r);case`exponential`:return Zi(e,r);case`engineering`:return Yi(e,r);case`bin`:return Gi(e,2,i);case`oct`:return Gi(e,8,i);case`hex`:return Gi(e,16,i);case`auto`:return Qi(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 qi(e){var t=`auto`,n,r;if(e!==void 0)if(Er(e))n=e;else if(Dr(e))n=e.toNumber();else if(Kr(e))e.precision!==void 0&&(n=ua(e.precision,()=>{throw Error(`Option "precision" must be a number or BigNumber`)})),e.wordSize!==void 0&&(r=ua(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 Ji(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 Yi(e,t){if(isNaN(e)||!Number.isFinite(e))return String(e);var n=$i(Ji(e),t),r=n.exponent,i=n.coefficients,a=r%3==0?r:r<0?r-3-r%3:r-r%3;if(Er(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=Er(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 Xi(e,t){if(isNaN(e)||!Number.isFinite(e))return String(e);var n=Ji(e),r=typeof t==`number`?$i(n,n.exponent+1+t):n,i=r.coefficients,a=r.exponent+1,o=a+(t||0);return i.length<o&&(i=i.concat(ea(o-i.length))),a<0&&(i=ea(-a+1).concat(i),a=1),a<i.length&&i.splice(a,0,a===0?`0.`:`.`),r.sign+i.join(``)}function Zi(e,t){if(isNaN(e)||!Number.isFinite(Number(e)))return String(e);var n=Ji(e),r=t?$i(n,t):n,i=r.coefficients,a=r.exponent;i.length<t&&(i=i.concat(ea(t-i.length)));var o=i.shift();return r.sign+o+(i.length>0?`.`+i.join(``):``)+`e`+(a>=0?`+`:``)+a}function Qi(e,t,n){if(isNaN(e)||!Number.isFinite(e))return String(e);var r=da(n?.lowerExp,-3),i=da(n?.upperExp,5),a=Ji(e),o=t?$i(a,t):a;if(o.exponent<r||o.exponent>=i)return Zi(e,t);var s=o.coefficients,c=o.exponent;s.length<t&&(s=s.concat(ea(t-s.length))),s=s.concat(ea(c-s.length+1+(s.length<t?t-s.length:0))),s=ea(-c).concat(s);var l=c>0?c:0;return l<s.length-1&&s.splice(l+1,0,`.`),o.sign+s.join(``)}function $i(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 ea(e){for(var t=[],n=0;n<e;n++)t.push(0);return t}function ta(e){return e.toExponential().replace(/e.*$/,``).replace(/^0\.?0*|\./,``).length}function na(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 ra=Math.acosh||function(e){return Math.log(Math.sqrt(e*e-1)+e)},ia=Math.asinh||function(e){return Math.log(Math.sqrt(e*e+1)+e)},aa=Math.atanh||function(e){return Math.log((1+e)/(1-e))/2},oa=Math.cosh||function(e){return(Math.exp(e)+Math.exp(-e))/2},sa=Math.sinh||function(e){return(Math.exp(e)-Math.exp(-e))/2},ca=Math.tanh||function(e){var t=Math.exp(2*e);return(t-1)/(t+1)};function la(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 ua(e,t){if(Er(e))return e;if(Dr(e))return e.toNumber();t()}function da(e,t){return Er(e)?e:Dr(e)?e.toNumber():t}var fa=Dt(Mi(),1),pa=function(){return pa=fa.default.create,fa.default},ma=J(`typed`,[`?BigNumber`,`?Complex`,`?DenseMatrix`,`?Fraction`],function(e){var{BigNumber:t,Complex:n,DenseMatrix:r,Fraction:i}=e,a=pa();return a.clear(),a.addTypes([{name:`number`,test:Er},{name:`Complex`,test:kr},{name:`BigNumber`,test:Dr},{name:`bigint`,test:Or},{name:`Fraction`,test:Ar},{name:`Unit`,test:jr},{name:`identifier`,test:e=>Mr&&/^(?:[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:Mr},{name:`Chain`,test:hi},{name:`Array`,test:Nr},{name:`Matrix`,test:Pr},{name:`DenseMatrix`,test:Ir},{name:`SparseMatrix`,test:Lr},{name:`Range`,test:Rr},{name:`Index`,test:zr},{name:`boolean`,test:Br},{name:`ResultSet`,test:Vr},{name:`Help`,test:Hr},{name:`function`,test:Ur},{name:`Date`,test:Wr},{name:`RegExp`,test:Gr},{name:`null`,test:Xr},{name:`undefined`,test:Zr},{name:`AccessorNode`,test:Qr},{name:`ArrayNode`,test:$r},{name:`AssignmentNode`,test:ei},{name:`BlockNode`,test:ti},{name:`ConditionalNode`,test:ni},{name:`ConstantNode`,test:ri},{name:`FunctionNode`,test:oi},{name:`FunctionAssignmentNode`,test:ai},{name:`IndexNode`,test:si},{name:`Node`,test:ci},{name:`ObjectNode`,test:li},{name:`OperatorNode`,test:ui},{name:`ParenthesisNode`,test:di},{name:`RangeNode`,test:fi},{name:`RelationalNode`,test:pi},{name:`SymbolNode`,test:mi},{name:`Map`,test:qr},{name:`Object`,test:Kr}]),a.addConversions([{from:`number`,to:`BigNumber`,convert:function(e){if(t||ha(e),ta(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||ga(e),new n(e,0)}},{from:`BigNumber`,to:`Complex`,convert:function(e){return n||ga(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||ha(e),new t(e.toString())}},{from:`bigint`,to:`Fraction`,convert:function(e){return i||va(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||ga(e),new n(e.valueOf(),0)}},{from:`number`,to:`Fraction`,convert:function(e){i||va(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||ha(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||va(e);try{return new i(e)}catch{throw Error(`Cannot convert "`+e+`" to Fraction`)}}},{from:`string`,to:`Complex`,convert:function(e){n||ga(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||ha(e),new t(+e)}},{from:`boolean`,to:`bigint`,convert:function(e){return BigInt(+e)}},{from:`boolean`,to:`Fraction`,convert:function(e){return i||va(e),new i(+e)}},{from:`boolean`,to:`string`,convert:function(e){return String(e)}},{from:`Array`,to:`Matrix`,convert:function(e){return r||_a(),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&&Fr(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&&Fr(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 ha(e){throw Error(`Cannot convert value ${e} into a BigNumber: no class 'BigNumber' provided`)}function ga(e){throw Error(`Cannot convert value ${e} into a Complex number: no class 'Complex' provided`)}function _a(){throw Error(`Cannot convert array into a Matrix: no class 'DenseMatrix' provided`)}function va(e){throw Error(`Cannot convert value ${e} into a Fraction, no class 'Fraction' provided.`)}var ya=J(`ResultSet`,[],()=>{function e(t){if(!(this instanceof e))throw SyntaxError(`Constructor must be called with the new operator`);this.entries=t||[]}return e.prototype.type=`ResultSet`,e.prototype.isResultSet=!0,e.prototype.valueOf=function(){return this.entries},e.prototype.toString=function(){return`[`+this.entries.map(String).join(`, `)+`]`},e.prototype.toJSON=function(){return{mathjs:`ResultSet`,entries:this.entries}},e.fromJSON=function(t){return new e(t.entries)},e},{isClass:!0}),ba=9e15,xa=1e9,Sa=`0123456789abcdef`,Ca=`2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058`,wa=`3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789`,Ta={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-ba,maxE:ba,crypto:!1},Ea,Da,Oa=!0,ka=`[DecimalError] `,Aa=ka+`Invalid argument: `,ja=ka+`Precision limit exceeded`,Ma=ka+`crypto unavailable`,Na=`[object Decimal]`,Pa=Math.floor,Fa=Math.pow,Ia=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,La=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,Ra=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,za=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,Ba=1e7,Va=7,Ha=9007199254740991,Ua=Ca.length-1,Wa=wa.length-1,Y={toStringTag:Na};Y.absoluteValue=Y.abs=function(){var e=new this.constructor(this);return e.s<0&&(e.s=1),Za(e)},Y.ceil=function(){return Za(new this.constructor(this),this.e+1,2)},Y.clampedTo=Y.clamp=function(e,t){var n,r=this,i=r.constructor;if(e=new i(e),t=new i(t),!e.s||!t.s)return new i(NaN);if(e.gt(t))throw Error(Aa+t);return n=r.cmp(e),n<0?e:r.cmp(t)>0?t:new i(r)},Y.comparedTo=Y.cmp=function(e){var t,n,r,i,a=this,o=a.d,s=(e=new a.constructor(e)).d,c=a.s,l=e.s;if(!o||!s)return!c||!l?NaN:c===l?o===s?0:!o^c<0?1:-1:c;if(!o[0]||!s[0])return o[0]?c:s[0]?-l:0;if(c!==l)return c;if(a.e!==e.e)return a.e>e.e^c<0?1:-1;for(r=o.length,i=s.length,t=0,n=r<i?r:i;t<n;++t)if(o[t]!==s[t])return o[t]>s[t]^c<0?1:-1;return r===i?0:r>i^c<0?1:-1},Y.cosine=Y.cos=function(){var e,t,n=this,r=n.constructor;return n.d?n.d[0]?(e=r.precision,t=r.rounding,r.precision=e+Math.max(n.e,n.sd())+Va,r.rounding=1,n=Ya(r,go(r,n)),r.precision=e,r.rounding=t,Za(Da==2||Da==3?n.neg():n,e,t,!0)):new r(1):new r(NaN)},Y.cubeRoot=Y.cbrt=function(){var e,t,n,r,i,a,o,s,c,l,u=this,d=u.constructor;if(!u.isFinite()||u.isZero())return new d(u);for(Oa=!1,a=u.s*Fa(u.s*u,1/3),!a||Math.abs(a)==1/0?(n=Ga(u.d),e=u.e,(a=(e-n.length+1)%3)&&(n+=a==1||a==-2?`0`:`00`),a=Fa(n,1/3),e=Pa((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=Xa(l.plus(u).times(s),l.plus(c),o+2,1),Ga(s.d).slice(0,o)===(n=Ga(r.d)).slice(0,o))if(n=n.slice(o-3,o+1),n==`9999`||!i&&n==`4999`){if(!i&&(Za(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`)&&(Za(r,e+1,1),t=!r.times(r).times(r).eq(u));break}return Oa=!0,Za(r,e,d.rounding,t)},Y.decimalPlaces=Y.dp=function(){var e,t=this.d,n=NaN;if(t){if(e=t.length-1,n=(e-Pa(this.e/Va))*Va,e=t[e],e)for(;e%10==0;e/=10)n--;n<0&&(n=0)}return n},Y.dividedBy=Y.div=function(e){return Xa(this,new this.constructor(e))},Y.dividedToIntegerBy=Y.divToInt=function(e){var t=this,n=t.constructor;return Za(Xa(t,new n(e),0,1,1),n.precision,n.rounding)},Y.equals=Y.eq=function(e){return this.cmp(e)===0},Y.floor=function(){return Za(new this.constructor(this),this.e+1,3)},Y.greaterThan=Y.gt=function(e){return this.cmp(e)>0},Y.greaterThanOrEqualTo=Y.gte=function(e){var t=this.cmp(e);return t==1||t===0},Y.hyperbolicCosine=Y.cosh=function(){var e,t,n,r,i,a=this,o=a.constructor,s=new o(1);if(!a.isFinite())return new o(a.s?1/0:NaN);if(a.isZero())return s;n=o.precision,r=o.rounding,o.precision=n+Math.max(a.e,a.sd())+4,o.rounding=1,i=a.d.length,i<32?(e=Math.ceil(i/3),t=(1/ho(4,e)).toString()):(e=16,t=`2.3283064365386962890625e-10`),a=mo(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 Za(a,o.precision=n,o.rounding=r,!0)},Y.hyperbolicSine=Y.sinh=function(){var e,t,n,r,i=this,a=i.constructor;if(!i.isFinite()||i.isZero())return new a(i);if(t=a.precision,n=a.rounding,a.precision=t+Math.max(i.e,i.sd())+4,a.rounding=1,r=i.d.length,r<3)i=mo(a,2,i,i,!0);else{e=1.4*Math.sqrt(r),e=e>16?16:e|0,i=i.times(1/ho(5,e)),i=mo(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,Za(i,t,n,!0)},Y.hyperbolicTangent=Y.tanh=function(){var e,t,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+7,r.rounding=1,Xa(n.sinh(),n.cosh(),r.precision=e,r.rounding=t)):new r(n.s)},Y.inverseCosine=Y.acos=function(){var e=this,t=e.constructor,n=e.abs().cmp(1),r=t.precision,i=t.rounding;return n===-1?e.isZero()?to(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()?to(t,r,i):new t(0):new t(NaN)},Y.inverseHyperbolicCosine=Y.acosh=function(){var e,t,n=this,r=n.constructor;return n.lte(1)?new r(n.eq(1)?0:NaN):n.isFinite()?(e=r.precision,t=r.rounding,r.precision=e+Math.max(Math.abs(n.e),n.sd())+4,r.rounding=1,Oa=!1,n=n.times(n).minus(1).sqrt().plus(n),Oa=!0,r.precision=e,r.rounding=t,n.ln()):new r(n)},Y.inverseHyperbolicSine=Y.asinh=function(){var e,t,n=this,r=n.constructor;return!n.isFinite()||n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+2*Math.max(Math.abs(n.e),n.sd())+6,r.rounding=1,Oa=!1,n=n.times(n).plus(1).sqrt().plus(n),Oa=!0,r.precision=e,r.rounding=t,n.ln())},Y.inverseHyperbolicTangent=Y.atanh=function(){var e,t,n,r,i=this,a=i.constructor;return i.isFinite()?i.e>=0?new a(i.abs().eq(1)?i.s/0:i.isZero()?i:NaN):(e=a.precision,t=a.rounding,r=i.sd(),Math.max(r,e)<2*-i.e-1?Za(new a(i),e,t,!0):(a.precision=n=r-i.e,i=Xa(i.plus(1),new a(1).minus(i),n+e,1),a.precision=e+4,a.rounding=1,i=i.ln(),a.precision=e,a.rounding=t,i.times(.5))):new a(NaN)},Y.inverseSine=Y.asin=function(){var e,t,n,r,i=this,a=i.constructor;return i.isZero()?new a(i):(t=i.abs().cmp(1),n=a.precision,r=a.rounding,t===-1?(a.precision=n+6,a.rounding=1,i=i.div(new a(1).minus(i.times(i)).sqrt().plus(1)).atan(),a.precision=n,a.rounding=r,i.times(2)):t===0?(e=to(a,n+4,r).times(.5),e.s=i.s,e):new a(NaN))},Y.inverseTangent=Y.atan=function(){var e,t,n,r,i,a,o,s,c,l=this,u=l.constructor,d=u.precision,f=u.rounding;if(!l.isFinite()){if(!l.s)return new u(NaN);if(d+4<=Wa)return o=to(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<=Wa)return o=to(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/Va+2|0),e=n;e;--e)l=l.div(l.times(l).plus(1).sqrt().plus(1));for(Oa=!1,t=Math.ceil(s/Va),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)),Oa=!0,Za(o,u.precision=d,u.rounding=f,!0)},Y.isFinite=function(){return!!this.d},Y.isInteger=Y.isInt=function(){return!!this.d&&Pa(this.e/Va)>this.d.length-2},Y.isNaN=function(){return!this.s},Y.isNegative=Y.isNeg=function(){return this.s<0},Y.isPositive=Y.isPos=function(){return this.s>0},Y.isZero=function(){return!!this.d&&this.d[0]===0},Y.lessThan=Y.lt=function(e){return this.cmp(e)<0},Y.lessThanOrEqualTo=Y.lte=function(e){return this.cmp(e)<1},Y.logarithm=Y.log=function(e){var t,n,r,i,a,o,s,c,l=this,u=l.constructor,d=u.precision,f=u.rounding,p=5;if(e==null)e=new u(10),t=!0;else{if(e=new u(e),n=e.d,e.s<0||!n||!n[0]||e.eq(1))return new u(NaN);t=e.eq(10)}if(n=l.d,l.s<0||!n||!n[0]||l.eq(1))return new u(n&&!n[0]?-1/0:l.s==1?n?0:1/0:NaN);if(t)if(n.length>1)a=!0;else{for(i=n[0];i%10==0;)i/=10;a=i!==1}if(Oa=!1,s=d+p,o=co(l,s),r=t?eo(u,s+10):co(e,s),c=Xa(o,r,s,1),qa(c.d,i=d,f))do if(s+=10,o=co(l,s),r=t?eo(u,s+10):co(e,s),c=Xa(o,r,s,1),!a){+Ga(c.d).slice(i+1,i+15)+1==0x5af3107a4000&&(c=Za(c,d+1,0));break}while(qa(c.d,i+=10,f));return Oa=!0,Za(c,d,f)},Y.minus=Y.sub=function(e){var t,n,r,i,a,o,s,c,l,u,d,f,p=this,m=p.constructor;if(e=new m(e),!p.d||!e.d)return!p.s||!e.s?e=new m(NaN):p.d?e.s=-e.s:e=new m(e.d||p.s!==e.s?p:NaN),e;if(p.s!=e.s)return e.s=-e.s,p.plus(e);if(l=p.d,f=e.d,s=m.precision,c=m.rounding,!l[0]||!f[0]){if(f[0])e.s=-e.s;else if(l[0])e=new m(p);else return new m(c===3?-0:0);return Oa?Za(e,s,c):e}if(n=Pa(e.e/Va),u=Pa(p.e/Va),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/Va),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]=Ba-1;--l[i],l[r]+=Ba}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=$a(l,n),Oa?Za(e,s,c):e):new m(c===3?-0:0)},Y.modulo=Y.mod=function(e){var t,n=this,r=n.constructor;return e=new r(e),!n.d||!e.s||e.d&&!e.d[0]?new r(NaN):!e.d||n.d&&!n.d[0]?Za(new r(n),r.precision,r.rounding):(Oa=!1,r.modulo==9?(t=Xa(n,e.abs(),0,3,1),t.s*=e.s):t=Xa(n,e,0,r.modulo,1),t=t.times(e),Oa=!0,n.minus(t))},Y.naturalExponential=Y.exp=function(){return so(this)},Y.naturalLogarithm=Y.ln=function(){return co(this)},Y.negated=Y.neg=function(){var e=new this.constructor(this);return e.s=-e.s,Za(e)},Y.plus=Y.add=function(e){var t,n,r,i,a,o,s,c,l,u,d=this,f=d.constructor;if(e=new f(e),!d.d||!e.d)return!d.s||!e.s?e=new f(NaN):d.d||(e=new f(e.d||d.s===e.s?d:NaN)),e;if(d.s!=e.s)return e.s=-e.s,d.minus(e);if(l=d.d,u=e.d,s=f.precision,c=f.rounding,!l[0]||!u[0])return u[0]||(e=new f(d)),Oa?Za(e,s,c):e;if(a=Pa(d.e/Va),r=Pa(e.e/Va),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/Va),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)/Ba|0,l[i]%=Ba;for(t&&(l.unshift(t),++r),o=l.length;l[--o]==0;)l.pop();return e.d=l,e.e=$a(l,r),Oa?Za(e,s,c):e},Y.precision=Y.sd=function(e){var t,n=this;if(e!==void 0&&e!==!!e&&e!==1&&e!==0)throw Error(Aa+e);return n.d?(t=no(n.d),e&&n.e+1>t&&(t=n.e+1)):t=NaN,t},Y.round=function(){var e=this,t=e.constructor;return Za(new t(e),e.e+1,t.rounding)},Y.sine=Y.sin=function(){var e,t,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+Math.max(n.e,n.sd())+Va,r.rounding=1,n=po(r,go(r,n)),r.precision=e,r.rounding=t,Za(Da>2?n.neg():n,e,t,!0)):new r(NaN)},Y.squareRoot=Y.sqrt=function(){var e,t,n,r,i,a,o=this,s=o.d,c=o.e,l=o.s,u=o.constructor;if(l!==1||!s||!s[0])return new u(!l||l<0&&(!s||s[0])?NaN:s?o:1/0);for(Oa=!1,l=Math.sqrt(+o),l==0||l==1/0?(t=Ga(s),(t.length+c)%2==0&&(t+=`0`),l=Math.sqrt(t),c=Pa((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(Xa(o,a,n+2,1)).times(.5),Ga(a.d).slice(0,n)===(t=Ga(r.d)).slice(0,n))if(t=t.slice(n-3,n+1),t==`9999`||!i&&t==`4999`){if(!i&&(Za(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`)&&(Za(r,c+1,1),e=!r.times(r).eq(o));break}return Oa=!0,Za(r,c,u.rounding,e)},Y.tangent=Y.tan=function(){var e,t,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+10,r.rounding=1,n=n.sin(),n.s=1,n=Xa(n,new r(1).minus(n.times(n)).sqrt(),e+10,0),r.precision=e,r.rounding=t,Za(Da==2||Da==4?n.neg():n,e,t,!0)):new r(NaN)},Y.times=Y.mul=function(e){var t,n,r,i,a,o,s,c,l,u=this,d=u.constructor,f=u.d,p=(e=new d(e)).d;if(e.s*=u.s,!f||!f[0]||!p||!p[0])return new d(!e.s||f&&!f[0]&&!p||p&&!p[0]&&!f?NaN:!f||!p?e.s/0:e.s*0);for(n=Pa(u.e/Va)+Pa(e.e/Va),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%Ba|0,t=s/Ba|0;a[i]=(a[i]+t)%Ba|0}for(;!a[--o];)a.pop();return t?++n:a.shift(),e.d=a,e.e=$a(a,n),Oa?Za(e,d.precision,d.rounding):e},Y.toBinary=function(e,t){return _o(this,2,e,t)},Y.toDecimalPlaces=Y.toDP=function(e,t){var n=this,r=n.constructor;return n=new r(n),e===void 0?n:(Ka(e,0,xa),t===void 0?t=r.rounding:Ka(t,0,8),Za(n,e+n.e+1,t))},Y.toExponential=function(e,t){var n,r=this,i=r.constructor;return e===void 0?n=Qa(r,!0):(Ka(e,0,xa),t===void 0?t=i.rounding:Ka(t,0,8),r=Za(new i(r),e+1,t),n=Qa(r,!0,e+1)),r.isNeg()&&!r.isZero()?`-`+n:n},Y.toFixed=function(e,t){var n,r,i=this,a=i.constructor;return e===void 0?n=Qa(i):(Ka(e,0,xa),t===void 0?t=a.rounding:Ka(t,0,8),r=Za(new a(i),e+i.e+1,t),n=Qa(r,!1,e+r.e+1)),i.isNeg()&&!i.isZero()?`-`+n:n},Y.toFraction=function(e){var t,n,r,i,a,o,s,c,l,u,d,f,p=this,m=p.d,h=p.constructor;if(!m)return new h(p);if(l=n=new h(1),r=c=new h(0),t=new h(r),a=t.e=no(m)-p.e-1,o=a%Va,t.d[0]=Fa(10,o<0?Va+o:o),e==null)e=a>0?t:l;else{if(s=new h(e),!s.isInt()||s.lt(l))throw Error(Aa+s);e=s.gt(t)?a>0?t:l:s}for(Oa=!1,s=new h(Ga(m)),u=h.precision,h.precision=a=m.length*Va*2;d=Xa(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=Xa(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=Xa(l,r,a,1).minus(p).abs().cmp(Xa(c,n,a,1).minus(p).abs())<1?[l,r]:[c,n],h.precision=u,Oa=!0,f},Y.toHexadecimal=Y.toHex=function(e,t){return _o(this,16,e,t)},Y.toNearest=function(e,t){var n=this,r=n.constructor;if(n=new r(n),e==null){if(!n.d)return n;e=new r(1),t=r.rounding}else{if(e=new r(e),t===void 0?t=r.rounding:Ka(t,0,8),!n.d)return e.s?n:e;if(!e.d)return e.s&&=n.s,e}return e.d[0]?(Oa=!1,n=Xa(n,e,0,t,1).times(e),Oa=!0,Za(n)):(e.s=n.s,n=e),n},Y.toNumber=function(){return+this},Y.toOctal=function(e,t){return _o(this,8,e,t)},Y.toPower=Y.pow=function(e){var t,n,r,i,a,o,s=this,c=s.constructor,l=+(e=new c(e));if(!s.d||!e.d||!s.d[0]||!e.d[0])return new c(Fa(+s,l));if(s=new c(s),s.eq(1))return s;if(r=c.precision,a=c.rounding,e.eq(1))return Za(s,r,a);if(t=Pa(e.e/Va),t>=e.d.length-1&&(n=l<0?-l:l)<=Ha)return i=io(c,s,n,r),e.s<0?new c(1).div(i):Za(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=Fa(+s,l),t=n==0||!isFinite(n)?Pa(l*(Math.log(`0.`+Ga(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):(Oa=!1,c.rounding=s.s=1,n=Math.min(12,(t+``).length),i=so(e.times(co(s,r+n)),r),i.d&&(i=Za(i,r+5,1),qa(i.d,r,a)&&(t=r+10,i=Za(so(e.times(co(s,t+n)),t),t+5,1),+Ga(i.d).slice(r+1,r+15)+1==0x5af3107a4000&&(i=Za(i,r+1,0)))),i.s=o,Oa=!0,c.rounding=a,Za(i,r,a))},Y.toPrecision=function(e,t){var n,r=this,i=r.constructor;return e===void 0?n=Qa(r,r.e<=i.toExpNeg||r.e>=i.toExpPos):(Ka(e,1,xa),t===void 0?t=i.rounding:Ka(t,0,8),r=Za(new i(r),e,t),n=Qa(r,e<=r.e||r.e<=i.toExpNeg,e)),r.isNeg()&&!r.isZero()?`-`+n:n},Y.toSignificantDigits=Y.toSD=function(e,t){var n=this,r=n.constructor;return e===void 0?(e=r.precision,t=r.rounding):(Ka(e,1,xa),t===void 0?t=r.rounding:Ka(t,0,8)),Za(new r(n),e,t)},Y.toString=function(){var e=this,t=e.constructor,n=Qa(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()&&!e.isZero()?`-`+n:n},Y.truncated=Y.trunc=function(){return Za(new this.constructor(this),this.e+1,1)},Y.valueOf=Y.toJSON=function(){var e=this,t=e.constructor,n=Qa(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()?`-`+n:n};function Ga(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=Va-r.length,n&&(a+=ro(n)),a+=r;o=e[t],r=o+``,n=Va-r.length,n&&(a+=ro(n))}else if(o===0)return`0`;for(;o%10==0;)o/=10;return a+o}function Ka(e,t,n){if(e!==~~e||e<t||e>n)throw Error(Aa+e)}function qa(e,t,n,r){var i,a,o,s;for(a=e[0];a>=10;a/=10)--t;return--t<0?(t+=Va,i=0):(i=Math.ceil((t+1)/Va),t%=Va),a=Fa(10,Va-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)==Fa(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)==Fa(10,t-3)-1,o}function Ja(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]+=Sa.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 Ya(e,t){var n,r,i;if(t.isZero())return t;r=t.d.length,r<32?(n=Math.ceil(r/3),i=(1/ho(4,n)).toString()):(n=16,i=`2.3283064365386962890625e-10`),e.precision+=n,t=mo(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 Xa=(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=Ba,p=Va,u=Pa(r.e/p)-Pa(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,Ea=m;else{for(d=1,f=v[0];f>=10;f/=10)d++;_.e=d+u*p-1,Za(_,s?a+_.e+1:a,o,m)}return _}})();function Za(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+=Va,o=t,u=d[f=0],c=u/Fa(10,i-o-1)%10|0;else if(f=Math.ceil((a+1)/Va),s=d.length,f>=s)if(r){for(;s++<=f;)d.push(0);u=c=0,i=1,a%=Va,o=a-Va+1}else break out;else{for(u=s=d[f],i=1;s>=10;s/=10)i++;a%=Va,o=a-Va+i,c=o<0?0:u/Fa(10,i-o-1)%10|0}if(r=r||t<0||d[f+1]!==void 0||(o<0?u:u%Fa(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/Fa(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]=Fa(10,(Va-t%Va)%Va),e.e=-t||0):d[0]=e.e=0,e;if(a==0?(d.length=f,s=1,f--):(d.length=f+1,s=Fa(10,Va-a),d[f]=o>0?(u/Fa(10,i-o)%Fa(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]==Ba&&(d[0]=1));break}else{if(d[f]+=s,d[f]!=Ba)break;d[f--]=0,s=1}for(a=d.length;d[--a]===0;)d.pop()}return Oa&&(e.e>p.maxE?(e.d=null,e.e=NaN):e.e<p.minE&&(e.e=0,e.d=[0])),e}function Qa(e,t,n){if(!e.isFinite())return lo(e);var r,i=e.e,a=Ga(e.d),o=a.length;return t?(n&&(r=n-o)>0?a=a.charAt(0)+`.`+a.slice(1)+ro(r):o>1&&(a=a.charAt(0)+`.`+a.slice(1)),a=a+(e.e<0?`e`:`e+`)+e.e):i<0?(a=`0.`+ro(-i-1)+a,n&&(r=n-o)>0&&(a+=ro(r))):i>=o?(a+=ro(i+1-o),n&&(r=n-i-1)>0&&(a=a+`.`+ro(r))):((r=i+1)<o&&(a=a.slice(0,r)+`.`+a.slice(r)),n&&(r=n-o)>0&&(i+1===o&&(a+=`.`),a+=ro(r))),a}function $a(e,t){var n=e[0];for(t*=Va;n>=10;n/=10)t++;return t}function eo(e,t,n){if(t>Ua)throw Oa=!0,n&&(e.precision=n),Error(ja);return Za(new e(Ca),t,1,!0)}function to(e,t,n){if(t>Wa)throw Error(ja);return Za(new e(wa),t,n,!0)}function no(e){var t=e.length-1,n=t*Va+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 ro(e){for(var t=``;e--;)t+=`0`;return t}function io(e,t,n,r){var i,a=new e(1),o=Math.ceil(r/Va+4);for(Oa=!1;;){if(n%2&&(a=a.times(t),vo(a.d,o)&&(i=!0)),n=Pa(n/2),n===0){n=a.d.length-1,i&&a.d[n]===0&&++a.d[n];break}t=t.times(t),vo(t.d,o)}return Oa=!0,a}function ao(e){return e.d[e.d.length-1]&1}function oo(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 so(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?(Oa=!1,c=m):c=t,s=new f(.03125);e.e>-2;)e=e.times(s),d+=5;for(r=Math.log(Fa(2,d))/Math.LN10*2+5|0,c+=r,n=a=o=new f(1),f.precision=c;;){if(a=Za(a.times(e),c,1),n=n.times(++u),s=o.plus(Xa(a,n,c,1)),Ga(s.d).slice(0,c)===Ga(o.d).slice(0,c)){for(i=d;i--;)o=Za(o.times(o),c,1);if(t==null)if(l<3&&qa(o.d,c-r,p,l))f.precision=c+=10,n=a=s=new f(1),u=0,l++;else return Za(o,f.precision=m,p,Oa=!0);else return f.precision=m,o}o=s}}function co(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?(Oa=!1,u=y):u=t,_.precision=u+=m,n=Ga(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=Ga(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=eo(_,u+2,y).times(a+``),h=co(new _(r+`.`+n.slice(1)),u-m).plus(l),_.precision=y,t==null?Za(h,y,v,Oa=!0):h;for(d=h,c=o=h=Xa(h.minus(1),h.plus(1),u,1),f=Za(h.times(h),u,1),i=3;;){if(o=Za(o.times(f),u,1),l=c.plus(Xa(o,new _(i),u,1)),Ga(l.d).slice(0,u)===Ga(c.d).slice(0,u))if(c=c.times(2),a!==0&&(c=c.plus(eo(_,u+2,y).times(a+``))),c=Xa(c,new _(p),u,1),t==null)if(qa(c.d,u-m,v,s))_.precision=u+=m,l=o=h=Xa(d.minus(1),d.plus(1),u,1),f=Za(h.times(h),u,1),i=s=1;else return Za(c,_.precision=y,v,Oa=!0);else return _.precision=y,c;c=l,i+=2}}function lo(e){return String(e.s*e.s/0)}function uo(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)%Va,n<0&&(r+=Va),r<i){for(r&&e.d.push(+t.slice(0,r)),i-=Va;r<i;)e.d.push(+t.slice(r,r+=Va));t=t.slice(r),r=Va-t.length}else r-=i;for(;r--;)t+=`0`;e.d.push(+t),Oa&&(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 fo(e,t){var n,r,i,a,o,s,c,l,u;if(t.indexOf(`_`)>-1){if(t=t.replace(/(\d)_(?=\d)/g,`$1`),za.test(t))return uo(e,t)}else if(t===`Infinity`||t===`NaN`)return+t||(e.s=NaN),e.e=NaN,e.d=null,e;if(La.test(t))n=16,t=t.toLowerCase();else if(Ia.test(t))n=2;else if(Ra.test(t))n=8;else throw Error(Aa+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=io(r,new r(n),a,a*2)),l=Ja(t,n,Ba),u=l.length-1,a=u;l[a]===0;--a)l.pop();return a<0?new r(e.s*0):(e.e=$a(l,u),e.d=l,Oa=!1,o&&(e=Xa(e,i,s*4)),c&&(e=e.times(Math.abs(c)<54?Fa(2,c):os.pow(2,c))),Oa=!0,e)}function po(e,t){var n,r=t.d.length;if(r<3)return t.isZero()?t:mo(e,2,t,t);n=1.4*Math.sqrt(r),n=n>16?16:n|0,t=t.times(1/ho(5,n)),t=mo(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 mo(e,t,n,r,i){var a,o,s,c,l=1,u=e.precision,d=Math.ceil(u/Va);for(Oa=!1,c=n.times(n),s=new e(r);;){if(o=Xa(s.times(c),new e(t++*t++),u,1),s=i?r.plus(o):r.minus(o),r=Xa(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 Oa=!0,o.d.length=d+1,o}function ho(e,t){for(var n=e;--t;)n*=e;return n}function go(e,t){var n,r=t.s<0,i=to(e,e.precision,1),a=i.times(.5);if(t=t.abs(),t.lte(a))return Da=r?4:1,t;if(n=t.divToInt(i),n.isZero())Da=r?3:2;else{if(t=t.minus(n.times(i)),t.lte(a))return Da=ao(n)?r?2:3:r?4:1,t;Da=ao(n)?r?1:4:r?3:2}return t.minus(i).abs()}function _o(e,t,n,r){var i,a,o,s,c,l,u,d,f,p=e.constructor,m=n!==void 0;if(m?(Ka(n,1,xa),r===void 0?r=p.rounding:Ka(r,0,8)):(n=p.precision,r=p.rounding),!e.isFinite())u=lo(e);else{for(u=Qa(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=Ja(Qa(f),10,i),f.e=f.d.length),d=Ja(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=Xa(e,f,n,r,0,i),d=e.d,a=e.e,l=Ea),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+=Sa.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=Ja(u,i,t),c=d.length;!d[c-1];--c);for(o=1,u=`1.`;o<c;o++)u+=Sa.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 vo(e,t){if(e.length>t)return e.length=t,!0}function yo(e){return new this(e).abs()}function bo(e){return new this(e).acos()}function xo(e){return new this(e).acosh()}function So(e,t){return new this(e).plus(t)}function Co(e){return new this(e).asin()}function wo(e){return new this(e).asinh()}function To(e){return new this(e).atan()}function Eo(e){return new this(e).atanh()}function Do(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=to(this,a,1).times(t.s>0?.25:.75),n.s=e.s):!t.d||e.isZero()?(n=t.s<0?to(this,r,i):new this(0),n.s=e.s):!e.d||t.isZero()?(n=to(this,a,1).times(.5),n.s=e.s):t.s<0?(this.precision=a,this.rounding=1,n=this.atan(Xa(e,t,a,1)),t=to(this,a,1),this.precision=r,this.rounding=i,n=e.s<0?n.minus(t):n.plus(t)):n=this.atan(Xa(e,t,a,1)),n}function Oo(e){return new this(e).cbrt()}function ko(e){return Za(e=new this(e),e.e+1,2)}function Ao(e,t,n){return new this(e).clamp(t,n)}function jo(e){if(!e||typeof e!=`object`)throw Error(ka+`Object expected`);var t,n,r,i=e.defaults===!0,a=[`precision`,1,xa,`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]=Ta[n]),(r=e[n])!==void 0)if(Pa(r)===r&&r>=a[t+1]&&r<=a[t+2])this[n]=r;else throw Error(Aa+n+`: `+r);if(n=`crypto`,i&&(this[n]=Ta[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(Ma);else this[n]=!1;else throw Error(Aa+n+`: `+r);return this}function Mo(e){return new this(e).cos()}function No(e){return new this(e).cosh()}function Po(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,zo(e)){a.s=e.s,Oa?!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++;Oa?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 uo(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),za.test(e)?uo(a,e):fo(a,e);if(r===`bigint`)return e<0?(e=-e,a.s=-1):a.s=1,uo(a,e.toString());throw Error(Aa+e)}if(i.prototype=Y,i.ROUND_UP=0,i.ROUND_DOWN=1,i.ROUND_CEIL=2,i.ROUND_FLOOR=3,i.ROUND_HALF_UP=4,i.ROUND_HALF_DOWN=5,i.ROUND_HALF_EVEN=6,i.ROUND_HALF_CEIL=7,i.ROUND_HALF_FLOOR=8,i.EUCLID=9,i.config=i.set=jo,i.clone=Po,i.isDecimal=zo,i.abs=yo,i.acos=bo,i.acosh=xo,i.add=So,i.asin=Co,i.asinh=wo,i.atan=To,i.atanh=Eo,i.atan2=Do,i.cbrt=Oo,i.ceil=ko,i.clamp=Ao,i.cos=Mo,i.cosh=No,i.div=Fo,i.exp=Io,i.floor=Lo,i.hypot=Ro,i.ln=Bo,i.log=Vo,i.log10=Uo,i.log2=Ho,i.max=Wo,i.min=Go,i.mod=Ko,i.mul=qo,i.pow=Jo,i.random=Yo,i.round=Xo,i.sign=Zo,i.sin=Qo,i.sinh=$o,i.sqrt=es,i.sub=ts,i.sum=ns,i.tan=rs,i.tanh=is,i.trunc=as,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 Fo(e,t){return new this(e).div(t)}function Io(e){return new this(e).exp()}function Lo(e){return Za(e=new this(e),e.e+1,3)}function Ro(){var e,t,n=new this(0);for(Oa=!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 Oa=!0,new this(1/0);n=t}return Oa=!0,n.sqrt()}function zo(e){return e instanceof os||e&&e.toStringTag===Na||!1}function Bo(e){return new this(e).ln()}function Vo(e,t){return new this(e).log(t)}function Ho(e){return new this(e).log(2)}function Uo(e){return new this(e).log(10)}function Wo(){return oo(this,arguments,-1)}function Go(){return oo(this,arguments,1)}function Ko(e,t){return new this(e).mod(t)}function qo(e,t){return new this(e).mul(t)}function Jo(e,t){return new this(e).pow(t)}function Yo(e){var t,n,r,i,a=0,o=new this(1),s=[];if(e===void 0?e=this.precision:Ka(e,1,xa),r=Math.ceil(e/Va),!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(Ma);for(r=s[--a],e%=Va,r&&e&&(i=Fa(10,Va-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-=Va)s.shift();for(r=1,i=s[0];i>=10;i/=10)r++;r<Va&&(n-=Va-r)}return o.e=n,o.d=s,o}function Xo(e){return Za(e=new this(e),e.e+1,this.rounding)}function Zo(e){return e=new this(e),e.d?e.d[0]?e.s:0*e.s:e.s||NaN}function Qo(e){return new this(e).sin()}function $o(e){return new this(e).sinh()}function es(e){return new this(e).sqrt()}function ts(e,t){return new this(e).sub(t)}function ns(){var e=0,t=arguments,n=new this(t[e]);for(Oa=!1;n.s&&++e<t.length;)n=n.plus(t[e]);return Oa=!0,Za(n,this.precision,this.rounding)}function rs(e){return new this(e).tan()}function is(e){return new this(e).tanh()}function as(e){return Za(e=new this(e),e.e+1,1)}Y[Symbol.for(`nodejs.util.inspect.custom`)]=Y.toString,Y[Symbol.toStringTag]=`Decimal`;var os=Y.constructor=Po(Ta);Ca=new os(Ca),wa=new os(wa);var ss=J(`BigNumber`,[`?on`,`config`],e=>{var{on:t,config:n}=e,r=os.clone({precision:n.precision,modulo:os.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}),cs=Math.cosh||function(e){return Math.abs(e)<1e-9?1-e:(Math.exp(e)+Math.exp(-e))*.5},ls=Math.sinh||function(e){return Math.abs(e)<1e-9?e:(Math.exp(e)-Math.exp(-e))*.5},us=e=>{let t=Math.sin(.5*e);return-2*t*t},ds=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))},fs=function(){throw SyntaxError(`Invalid Param`)};function ps(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 ms={re:0,im:0},hs=function(e,t){let n=ms;if(e==null)n.re=n.im=0;else if(t!==void 0)n.re=e,n.im=t;else switch(typeof e){case`object`:if(`im`in e&&`re`in e)n.re=e.re,n.im=e.im;else if(`abs`in e&&`arg`in e){if(!isFinite(e.abs)&&isFinite(e.arg))return X.INFINITY;n.re=e.abs*Math.cos(e.arg),n.im=e.abs*Math.sin(e.arg)}else if(`r`in e&&`phi`in e){if(!isFinite(e.r)&&isFinite(e.phi))return X.INFINITY;n.re=e.r*Math.cos(e.phi),n.im=e.r*Math.sin(e.phi)}else e.length===2?(n.re=e[0],n.im=e[1]):fs();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&&fs();for(let e=0;e<t.length;e++){let a=t[e];a===` `||a===` `||a===`
2
+ import{$ as e,$t as t,A as n,At as r,B as i,Bt as a,C as o,Ct as s,D as c,Dt as l,E as u,Et as d,F as f,G as p,Gt as m,H as h,Ht as g,I as _,J as v,Jt as y,K as b,Kt as x,L as S,M as C,N as w,O as T,Ot as E,P as D,Q as O,Qt as k,R as A,S as j,St as M,T as N,Tt as P,U as F,Ut as I,V as L,Vt as R,W as z,Wt as B,X as V,Xt as ee,Y as te,Yt as H,Z as ne,Zt as re,_ as ie,_t as U,a as ae,at as oe,b as se,bt as ce,c as le,ct as ue,d as de,dt as fe,en as pe,et as me,f as he,ft as ge,g as _e,gt as ve,h as ye,ht as be,i as xe,it as Se,j as Ce,jt as we,k as Te,kt as Ee,l as De,lt as Oe,m as ke,mt as Ae,n as je,nn as Me,nt as Ne,o as Pe,ot as Fe,p as Ie,pt as Le,q as Re,qt as ze,r as Be,rt as Ve,st as He,tn as Ue,tt as We,u as Ge,ut as Ke,v as qe,w as Je,x as Ye,y as Xe,yt as Ze,z as Qe,zt as $e}from"./keys-AcReVG65.js";import{i as et,n as tt,r as nt,t as rt}from"./threshold-C9it0Y7P.js";import{createContext as it,forwardRef as at,memo as ot,startTransition as st,useCallback as ct,useContext as lt,useEffect as W,useImperativeHandle as ut,useLayoutEffect as G,useMemo as dt,useRef as K,useState as ft,useSyncExternalStore as pt}from"react";import{createPortal as mt}from"react-dom";import{createRoot as ht}from"react-dom/client";import{Fragment as gt,jsx as q,jsxs as _t}from"react/jsx-runtime";var vt=Object.create,yt=Object.defineProperty,bt=Object.getOwnPropertyDescriptor,xt=Object.getOwnPropertyNames,St=Object.getPrototypeOf,Ct=Object.prototype.hasOwnProperty,wt=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Tt=(e,t)=>{let n={};for(var r in e)yt(n,r,{get:e[r],enumerable:!0});return t||yt(n,Symbol.toStringTag,{value:`Module`}),n},Et=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=xt(t),a=0,o=i.length,s;a<o;a++)s=i[a],!Ct.call(e,s)&&s!==n&&yt(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=bt(t,s))||r.enumerable});return e},Dt=(e,t,n)=>(n=e==null?{}:vt(St(e)),Et(t||!e||!e.__esModule?yt(n,`default`,{value:e,enumerable:!0}):n,e)),Ot=[`text`,`brush`,`arrow`,`box`],kt={text:14,brush:3,arrow:2,box:2},At=/^#[0-9a-fA-F]{6}$/,jt={text:[1,1],arrow:[2,2],box:[2,2],brush:[2,1/0]},Mt=e=>typeof e==`number`&&Number.isFinite(e);function Nt(e){if(!e||typeof e!=`object`)return null;let t=e,n=t.kind;if(!Ot.includes(n)||typeof t.id!=`string`||!t.id||!Array.isArray(t.points))return null;let r=t.points.filter(e=>Array.isArray(e)&&Mt(e[0])&&Mt(e[1])).map(([e,t])=>[e,t]),[i,a]=jt[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`&&At.test(t.color)?t.color:`#f5a524`,width:Mt(t.width)&&t.width>0?Math.min(96,t.width):kt[n],...typeof t.text==`string`&&t.text!==``?{text:t.text}:{}}}function Pt(e){return Array.isArray(e)?e.map(Nt).filter(e=>e!==null):null}var Ft={info:`#8a93a6`,warning:`#f5a524`,critical:`#e5484d`},It={info:`var(--text-muted, #8a93a6)`,warning:`var(--accent, #f5a524)`,critical:`var(--danger, #e5484d)`};function Lt(e,t){return{id:`mark:${e.id}`,kind:`box`,anchor:`x`,points:[[e.t0,0],[e.t1??t,1]],color:Ft[e.severity],width:1,...e.ruleName?{text:e.ruleName}:{}}}var Rt=96,zt=96,Bt=2,Vt={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},Ht={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},Ut=Vt,Wt=Ht;function Gt(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 Kt(e,t,n,r=96){let i=Vt[e],a=Ht[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 qt(e,t,n,r,i,a,o=96,s=96){let c=Math.round(r/Math.max(1e-6,a.width/o)),l=Math.round(i/Math.max(1e-6,a.height/s));return n===`move`?Kt(e,{...t,x:t.x+c,y:t.y+l},o,s):{...t,w:Math.max(Vt[e],Math.min(t.w+c,o-t.x)),h:Math.max(Ht[e],Math.min(t.h+l,s-t.y))}}function Jt(e,t,n){for(let r of t)if(r.id!==n&&Gt(e,r.rect))return!0;return!1}function Yt(e,t,n=96){let r=Vt[e],i=Ht[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=Kt(e,{x:s,y:i,w:a,h:o},n);if(!Jt(r,t,``))return r}return Kt(e,{x:0,y:0,w:r,h:i},n)}function Xt(e,t){return{id:crypto.randomUUID(),kind:e,rect:Yt(e,t)}}function Zt(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=Zt(e-4).map(e=>({x:e.x*.5,y:e.y,w:e.w*.5,h:e.h})),n=Zt(4).map(e=>({x:.5+e.x*.5,y:e.y,w:e.w*.5,h:e.h}));return[...t,...n]}function Qt(e,t=96,n=96){let r=Zt(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 $t(){return{scaleMin:``,scaleMax:``,majorStep:``,minorStep:``,alarm:null}}var en={style:`dashed`,width:1,color:null},tn={style:`solid`,width:1,color:null},nn={enabled:!1,reference:`previous`,datasetId:null,datasetColor:`#94a3b8`,previousColor:`#64748b`},rn=/^#[0-9a-f]{6}$/i;function an(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`&&rn.test(t.datasetColor)?t.datasetColor:nn.datasetColor,previousColor:typeof t.previousColor==`string`&&rn.test(t.previousColor)?t.previousColor:nn.previousColor}}var on=[`#f5a524`,`#38bdf8`,`#22c55e`,`#f472b6`,`#a78bfa`,`#fb7185`];function sn(e,t){return{id:crypto.randomUUID(),column:e,color:on[t%on.length],value:`last`,style:`arc`,min:``,max:``}}function cn(e,t){if(!e||typeof e!=`object`)return null;let n=e;if(typeof n.column!=`string`)return null;let r=Zn(n.alarm);return{id:typeof n.id==`string`&&n.id?n.id:`g${t}`,column:n.column,color:typeof n.color==`string`?n.color:on[t%on.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 ln(e,t){let n=parseFloat(e),r=parseFloat(t);return Number.isFinite(n)&&Number.isFinite(r)&&n<r?[n,r]:void 0}var un=1.8,dn=4,fn=1;function pn(){return{kind:`multiband`,series:[],addColumn:``,layout:`overlay`,xAxisLine:{...en},yAxisLine:{...en},gridLine:{...tn},lineWidth:1}}function mn(e){return{kind:`xyscatter`,xyXCol:``,xyYCol:``,xyColorCol:null,xyColor:e,xyPointRadius:un,xyXAxisLine:{...en},xyYAxisLine:{...en},xyGridLine:{...tn},xyFit:null,xyXScale:$t(),xyYScale:$t()}}function hn(e=4){return{kind:`xyzmesh`,xyzXCol:``,xyzYCol:``,xyzZCol:``,xyzViewMode:`3d`,xyzXScale:$t(),xyzYScale:$t(),xyzZScale:$t(),xyzPointRadius:e,showMesh:!1,meshStyle:`filled`,meshOpacity:.85}}function gn(){return{kind:`histogram`,histColumn:``,histBins:0,histColor:`#38bdf8`,histNormal:!1,histLogY:!1}}function _n(){return{kind:`polar`,polarAngleCol:``,polarRadiusCol:``,polarColor:`#a78bfa`,polarMode:`waveform`,polarRadiusMin:``,polarRadiusMax:``}}function vn(){return{kind:`spectrum`,specSignalCol:``,specTimeCol:``,specSampleRate:`1000`,specXMode:`hz`,specYMode:`amplitude`,specWindow:`hann`,specColor:`#34d399`,specLogX:!1}}function yn(){return{kind:`boxplot`,boxValueCol:``,boxGroupCol:``,boxColor:`#fb923c`,boxWhiskers:`1.5iqr`}}function bn(){return{kind:`spectrogram`,sgSignalCol:``,sgTimeCol:``,sgSampleRate:`1000`,sgWindowSize:512,sgOverlap:.5,sgWinFunc:`hann`,sgYMode:`db`,sgLogFreq:!1}}function xn(){return{kind:`heatmap`,hmMode:`binned`,hmColumns:[],hmXCol:``,hmYCol:``,hmValueCol:``,hmXBins:6,hmYBins:6,hmXMin:``,hmXMax:``,hmYMin:``,hmYMax:``,hmShowValues:!0,hmColorScheme:`diverging`}}function Sn(){return{kind:`violin`,vlValueCol:``,vlGroupCol:``,vlColor:`#818cf8`,vlShowBox:!0,vlBandwidth:``,vlOrientation:`vertical`}}function Cn(){return{kind:`confusion`,cfActualCol:``,cfPredictedCol:``,cfNormalize:!1}}function wn(){return{kind:`roc`,rocScoreCol:``,rocLabelCol:``,rocMode:`roc`,rocColor:`#f472b6`}}function Tn(){return{kind:`losscurve`,lcXCol:``,lcLeftCols:[],lcRightCols:[]}}function En(){return{kind:`controlchart`,ccValueCol:``,ccSubgroupCol:``,ccSigmaLevel:3,ccColor:`#22d3ee`}}function Dn(){return{kind:`parallelcoords`,pcColumns:[],pcColorByCol:``,pcColor:`#64748b`}}function On(){return{kind:`embedding`,emXCol:``,emYCol:``,emColorCol:``,emColorMode:`categorical`,emLabelCol:``,emPointSize:3,emColor:`#a78bfa`}}function kn(){return{kind:`flamegraph`,fgNameCol:``,fgParentCol:``,fgValueCol:``,fgDirection:`topdown`}}function An(){return{kind:`barchart`,bcCategoryCol:``,bcValueCols:[],bcMode:`grouped`,bcHorizontal:!1}}function jn(){return{kind:`radar`,rdAxesCols:[],rdGroupCol:``,rdColor:`#38bdf8`,rdFill:!0}}function Mn(){return{kind:`areachart`,acXCol:``,acYCols:[],acStacked:!1}}function Nn(){return{kind:`cdfchart`,cdValueCols:[],cdComplement:!1,cdLogX:!1}}function Pn(){return{kind:`bubblechart`,bbXCol:``,bbYCol:``,bbSizeCol:``,bbColorCol:``,bbColorMode:`categorical`,bbColor:`#64748b`,bbMaxRadius:24}}function Fn(){return{kind:`treemap`,tmNameCol:``,tmParentCol:``,tmValueCol:``}}function In(){return{kind:`sankey`,skSourceCol:``,skTargetCol:``,skValueCol:``}}function Ln(){return{kind:`gauge`,ggGauges:[]}}function Rn(){return{kind:`calibration`,cbScoreCol:``,cbLabelCol:``,cbBins:10,cbColor:`#38bdf8`}}function zn(){return{kind:`qqplot`,qqValueCol:``,qqMode:`normal`,qqRefCol:``,qqColor:`#a78bfa`}}function Bn(){return{kind:`gantt`,gtLabelCol:``,gtStartCol:``,gtEndCol:``,gtGroupCol:``}}function Vn(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 Hn=()=>({kind:`camera`,cameraStreamId:``,cameras:[],syncStreamId:``,offsetMs:0,fit:`contain`}),Un=9;function Wn(e){return e.cameraStreamId?e.cameras?.[0]===e.cameraStreamId?e.cameras.slice(0,9):[e.cameraStreamId]:[]}function Gn(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 Kn(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 qn(e,t){return Kn(e)?e:{...t}}function Jn(e){if(!e||typeof e!=`object`)return!1;let t=e;return t.kind===`multiband`&&Array.isArray(t.series)&&t.series.every(Gn)&&typeof t.addColumn==`string`}function Yn(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 Xn(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 Zn(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`&&Qn.test(t.ruleId)?{ruleId:t.ruleId}:{}}}var Qn=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function $n(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 er){let t=er[e.kind],n=r(i[t]);n!==i[t]&&o(t,n)}return a||e}var er={histogram:`histAlarm`,spectrum:`specAlarm`,areachart:`acAlarm`,losscurve:`lcAlarm`,cdfchart:`cdAlarm`,bubblechart:`bbAlarm`,boxplot:`boxAlarm`,violin:`vlAlarm`,barchart:`bcAlarm`,gantt:`gtAlarm`};function tr(e){if(!e||!(e.kind in er))return null;let t=e[er[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 nr(e){let t=$t();if(!e||typeof e!=`object`)return t;let n=e,r=Zn(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 rr(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(Jn(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:Zn(e.alarm)}:e):e.series,addColumn:e.addColumn,layout:e.layout===`parallel`?`parallel`:`overlay`,xAxisLine:qn(e.xAxisLine,en),yAxisLine:qn(e.yAxisLine,en),gridLine:qn(e.gridLine,tn),lineWidth:typeof e.lineWidth==`number`&&Number.isFinite(e.lineWidth)?Math.min(6,Math.max(.5,e.lineWidth)):1,...an(e.beacon)?{beacon:an(e.beacon)}:{},...e.envelope===!0?{envelope:!0}:{}}}else if(Yn(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:qn(e.xyXAxisLine,en),xyYAxisLine:qn(e.xyYAxisLine,en),xyGridLine:qn(e.xyGridLine,tn),xyFit:a,xyXScale:nr(e.xyXScale),xyYScale:nr(e.xyYScale)}}else if(Xn(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??nr(n.xyzXScale),xyzYScale:a??nr(n.xyzYScale),xyzZScale:o??nr(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=cn(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:Wn({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]?Pt(n?.annotations):null;e?.length&&(r[t]={...r[t],annotations:e});let i=r[t]?er[r[t].kind]:void 0,a=i?Zn(n[i]):null;i&&a&&(r[t]={...r[t],[i]:a})}return r}function ir(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]=pn(),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]=hn(r),a=!0)}else if(t.kind===`histogram`){let e=i[t.id];(!e||e.kind!==`histogram`)&&(i[t.id]=gn(),a=!0)}else if(t.kind===`polar`){let e=i[t.id];(!e||e.kind!==`polar`)&&(i[t.id]=_n(),a=!0)}else if(t.kind===`spectrum`){let e=i[t.id];(!e||e.kind!==`spectrum`)&&(i[t.id]=vn(),a=!0)}else if(t.kind===`boxplot`){let e=i[t.id];(!e||e.kind!==`boxplot`)&&(i[t.id]=yn(),a=!0)}else t.kind===`spectrogram`?(!i[t.id]||i[t.id].kind!==`spectrogram`)&&(i[t.id]=bn(),a=!0):t.kind===`heatmap`?(!i[t.id]||i[t.id].kind!==`heatmap`)&&(i[t.id]=xn(),a=!0):t.kind===`violin`?(!i[t.id]||i[t.id].kind!==`violin`)&&(i[t.id]=Sn(),a=!0):t.kind===`confusion`?(!i[t.id]||i[t.id].kind!==`confusion`)&&(i[t.id]=Cn(),a=!0):t.kind===`roc`?(!i[t.id]||i[t.id].kind!==`roc`)&&(i[t.id]=wn(),a=!0):t.kind===`losscurve`?(!i[t.id]||i[t.id].kind!==`losscurve`)&&(i[t.id]=Tn(),a=!0):t.kind===`controlchart`?(!i[t.id]||i[t.id].kind!==`controlchart`)&&(i[t.id]=En(),a=!0):t.kind===`parallelcoords`?(!i[t.id]||i[t.id].kind!==`parallelcoords`)&&(i[t.id]=Dn(),a=!0):t.kind===`embedding`?(!i[t.id]||i[t.id].kind!==`embedding`)&&(i[t.id]=On(),a=!0):t.kind===`flamegraph`?(!i[t.id]||i[t.id].kind!==`flamegraph`)&&(i[t.id]=kn(),a=!0):t.kind===`barchart`?(!i[t.id]||i[t.id].kind!==`barchart`)&&(i[t.id]=An(),a=!0):t.kind===`radar`?(!i[t.id]||i[t.id].kind!==`radar`)&&(i[t.id]=jn(),a=!0):t.kind===`areachart`?(!i[t.id]||i[t.id].kind!==`areachart`)&&(i[t.id]=Mn(),a=!0):t.kind===`cdfchart`?(!i[t.id]||i[t.id].kind!==`cdfchart`)&&(i[t.id]=Nn(),a=!0):t.kind===`bubblechart`?(!i[t.id]||i[t.id].kind!==`bubblechart`)&&(i[t.id]=Pn(),a=!0):t.kind===`treemap`?(!i[t.id]||i[t.id].kind!==`treemap`)&&(i[t.id]=Fn(),a=!0):t.kind===`sankey`?(!i[t.id]||i[t.id].kind!==`sankey`)&&(i[t.id]=In(),a=!0):t.kind===`gauge`?(!i[t.id]||i[t.id].kind!==`gauge`)&&(i[t.id]=Ln(),a=!0):t.kind===`calibration`?(!i[t.id]||i[t.id].kind!==`calibration`)&&(i[t.id]=Rn(),a=!0):t.kind===`qqplot`?(!i[t.id]||i[t.id].kind!==`qqplot`)&&(i[t.id]=zn(),a=!0):t.kind===`gantt`?(!i[t.id]||i[t.id].kind!==`gantt`)&&(i[t.id]=Bn(),a=!0):t.kind===`camera`&&(!i[t.id]||i[t.id].kind!==`camera`)&&(i[t.id]=Hn(),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 ar(e){return e===null||typeof e==`number`&&e>0?{liveWindowSeconds:e}:{}}function or(e){return Number.isNaN(e)?0:Math.min(100,Math.max(0,e))}function sr(){return crypto.randomUUID()}function cr(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 lr(){return lr=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},lr.apply(null,arguments)}var ur={relTol:1e-12,absTol:1e-15,matrix:`Matrix`,number:`number`,numberFallback:`number`,precision:64,predictable:!1,randomSeed:null,legacySubset:!1};function dr(e,t){if(pr(e,t)||mr(e,t))return e[t];throw _r(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 fr(e,t,n){if(pr(e,t)||mr(e,t))return e[t]=n,n;throw Error(`No access to property "${t}"`)}function pr(e,t){return vr(e)?!(t in Object.prototype):!1}function mr(e,t){return Array.isArray(e)?typeof t==`number`||typeof t==`string`&&hr(t)||t===`length`:!1}function hr(e){return/^\d+$/.test(e)}function gr(e,t){if(!_r(e,t))throw Error(`No access to method "`+t+`"`);return e[t]}function _r(e,t){return e==null||typeof e[t]!=`function`||Ti(e,t)&&Object.getPrototypeOf&&t in Object.getPrototypeOf(e)?!1:yr.has(t)?!0:!(t in Object.prototype||t in Function.prototype)}function vr(e){return typeof e==`object`&&e&&e.constructor===Object}var yr=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 dr(this.wrappedObject,e)}set(e,t){return fr(this.wrappedObject,e,t),this}has(e){return pr(this.wrappedObject,e)&&e in this.wrappedObject}entries(){return Sr(this.keys(),e=>[e,this.get(e)])}forEach(e){for(var t of this.keys())e(this.get(t),t,this)}delete(e){pr(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}},xr=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 Sr(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 Sr(e,t){return{next:()=>{var n=e.next();return n.done?n:{value:t(n.value),done:!1}}}}function Cr(){return new Map}function wr(e){if(!e)return Cr();if(qr(e))return e;if(Kr(e))return new br(e);throw Error(`createMap can create maps from objects or Maps`)}function Tr(e){if(e instanceof br)return e.wrappedObject;var t={};for(var n of e.keys())fr(t,n,e.get(n));return t}function Er(e){return typeof e==`number`}function Dr(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 Or(e){return typeof e==`bigint`}function kr(e){return e&&typeof e==`object`&&Object.getPrototypeOf(e).isComplex===!0||!1}function Ar(e){return e&&typeof e==`object`&&Object.getPrototypeOf(e).isFraction===!0||!1}function jr(e){return e&&e.constructor.prototype.isUnit===!0||!1}function Mr(e){return typeof e==`string`}var Nr=Array.isArray;function Pr(e){return e&&e.constructor.prototype.isMatrix===!0||!1}function Fr(e){return Array.isArray(e)||Pr(e)}function Ir(e){return e&&e.isDenseMatrix&&e.constructor.prototype.isMatrix===!0||!1}function Lr(e){return e&&e.isSparseMatrix&&e.constructor.prototype.isMatrix===!0||!1}function Rr(e){return e&&e.constructor.prototype.isRange===!0||!1}function zr(e){return e&&e.constructor.prototype.isIndex===!0||!1}function Br(e){return typeof e==`boolean`}function Vr(e){return e&&e.constructor.prototype.isResultSet===!0||!1}function Hr(e){return e&&e.constructor.prototype.isHelp===!0||!1}function Ur(e){return typeof e==`function`}function Wr(e){return e instanceof Date}function Gr(e){return e instanceof RegExp}function Kr(e){return!!(e&&typeof e==`object`&&e.constructor===Object&&!kr(e)&&!Ar(e))}function qr(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 Jr(e){return qr(e)&&qr(e.a)&&qr(e.b)}function Yr(e){return qr(e)&&Kr(e.wrappedObject)}function Xr(e){return e===null}function Zr(e){return e===void 0}function Qr(e){return e&&e.isAccessorNode===!0&&e.constructor.prototype.isNode===!0||!1}function $r(e){return e&&e.isArrayNode===!0&&e.constructor.prototype.isNode===!0||!1}function ei(e){return e&&e.isAssignmentNode===!0&&e.constructor.prototype.isNode===!0||!1}function ti(e){return e&&e.isBlockNode===!0&&e.constructor.prototype.isNode===!0||!1}function ni(e){return e&&e.isConditionalNode===!0&&e.constructor.prototype.isNode===!0||!1}function ri(e){return e&&e.isConstantNode===!0&&e.constructor.prototype.isNode===!0||!1}function ii(e){return ri(e)||ui(e)&&e.args.length===1&&ri(e.args[0])&&`-+~`.includes(e.op)}function ai(e){return e&&e.isFunctionAssignmentNode===!0&&e.constructor.prototype.isNode===!0||!1}function oi(e){return e&&e.isFunctionNode===!0&&e.constructor.prototype.isNode===!0||!1}function si(e){return e&&e.isIndexNode===!0&&e.constructor.prototype.isNode===!0||!1}function ci(e){return e&&e.isNode===!0&&e.constructor.prototype.isNode===!0||!1}function li(e){return e&&e.isObjectNode===!0&&e.constructor.prototype.isNode===!0||!1}function ui(e){return e&&e.isOperatorNode===!0&&e.constructor.prototype.isNode===!0||!1}function di(e){return e&&e.isParenthesisNode===!0&&e.constructor.prototype.isNode===!0||!1}function fi(e){return e&&e.isRangeNode===!0&&e.constructor.prototype.isNode===!0||!1}function pi(e){return e&&e.isRelationalNode===!0&&e.constructor.prototype.isNode===!0||!1}function mi(e){return e&&e.isSymbolNode===!0&&e.constructor.prototype.isNode===!0||!1}function hi(e){return e&&e.constructor.prototype.isChain===!0||!1}function gi(e){var t=typeof e;return t===`object`?e===null?`null`:Dr(e)?`BigNumber`:e.constructor&&e.constructor.name?e.constructor.name:`Object`:t}function _i(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 _i(e)});if(e instanceof Date)return new Date(e.valueOf());if(Dr(e))return e;if(Kr(e))return vi(e,_i);if(t===`function`)return e;throw TypeError(`Cannot clone: unknown type of value (value: ${e})`)}function vi(e,t){var n={};for(var r in e)Ti(e,r)&&(n[r]=t(e[r]));return n}function yi(e,t){for(var n in t)Ti(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(Ti(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 xi(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(!xi(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)||!xi(e[n],t[n]))return!1;for(n in t)if(!(n in e))return!1;return!0}else return e===t}function Si(e){var t={};return Ci(e,t),t}function Ci(e,t){for(var n in e)if(Ti(e,n)){var r=e[n];typeof r==`object`&&r?Ci(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 Ti(e,t){return e&&Object.hasOwnProperty.call(e,t)}function Ei(e){return e&&typeof e.factory==`function`}function Di(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 Oi=[`Matrix`,`Array`],ki=[`number`,`BigNumber`,`bigint`,`Fraction`];function Ai(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=_i(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=_i(e);ji(r,`matrix`,Oi),ji(r,`number`,ki),bi(e,r);var o=_i(e);return t(`config`,o,a,_i(r)),o}else return _i(e)}return n.MATRIX_OPTIONS=Oi,n.NUMBER_OPTIONS=ki,Object.keys(ur).forEach(t=>{Object.defineProperty(n,t,{get:()=>e[t],enumerable:!0,configurable:!0})}),n}function ji(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 Mi=wt(((e,t)=>{(function(n,r){typeof e==`object`&&t!==void 0?t.exports=r():typeof define==`function`&&define.amd?define(r):(n=typeof globalThis<`u`?globalThis:n||self,n.typed=r())})(e,(function(){function e(){return!0}function t(){return!1}function n(){}let r=`Argument is not a typed-function.`;function i(){function a(e){return typeof e==`object`&&!!e&&e.constructor===Object}let o=[{name:`number`,test:function(e){return typeof e==`number`}},{name:`string`,test:function(e){return typeof e==`string`}},{name:`boolean`,test:function(e){return typeof e==`boolean`}},{name:`Function`,test:function(e){return typeof e==`function`}},{name:`Array`,test:Array.isArray},{name:`Date`,test:function(e){return e instanceof Date}},{name:`RegExp`,test:function(e){return e instanceof RegExp}},{name:`Object`,test:a},{name:`null`,test:function(e){return e===null}},{name:`undefined`,test:function(e){return e===void 0}}],s={name:`any`,test:e,isAny:!0},c,l,u=0,d={createCount:0};function f(e){let t=c.get(e);if(t)return t;let n=`Unknown type "`+e+`"`,r=e.toLowerCase(),i;for(i of l)if(i.toLowerCase()===r){n+=`. Did you mean "`+i+`" ?`;break}throw TypeError(n)}function p(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:`any`,n=t?f(t).index:l.length,r=[];for(let t=0;t<e.length;++t){if(!e[t]||typeof e[t].name!=`string`||typeof e[t].test!=`function`)throw TypeError(`Object with properties {name: string, test: function} expected`);let i=e[t].name;if(c.has(i))throw TypeError(`Duplicate type name "`+i+`"`);r.push(i),c.set(i,{name:i,test:e[t].test,isAny:e[t].isAny,index:n+t,conversionsTo:[]})}let i=l.slice(n);l=l.slice(0,n).concat(r).concat(i);for(let e=n+r.length;e<l.length;++e)c.get(l[e]).index=e}function m(){c=new Map,l=[],u=0,p([s],!1)}m(),p(o);function h(){let e;for(e of l)c.get(e).conversionsTo=[];u=0}function g(e){let t=l.filter(t=>{let n=c.get(t);return!n.isAny&&n.test(e)});return t.length?t:[`any`]}function _(e){return e&&typeof e==`function`&&`_typedFunctionData`in e}function v(e,t,n){if(!_(e))throw TypeError(r);let i=n&&n.exact,a=T(Array.isArray(t)?t.join(`,`):t),o=x(a);if(!i||o in e.signatures){let t=e._typedFunctionData.signatureMap.get(o);if(t)return t}let s=a.length,c;if(i){c=[];let t;for(t in e.signatures)c.push(e._typedFunctionData.signatureMap.get(t))}else c=e._typedFunctionData.signatures;for(let e=0;e<s;++e){let t=a[e],n=[],r;for(r of c){let i=k(r.params,e);if(!(!i||t.restParam&&!i.restParam)){if(!i.hasAny){let e=w(i);if(t.types.some(t=>!e.has(t.name)))continue}n.push(r)}}if(c=n,c.length===0)break}let l;for(l of c)if(l.params.length<=s)return l;throw TypeError(`Signature not found (signature: `+(e.name||`unnamed`)+`(`+x(a,`, `)+`))`)}function y(e,t,n){return v(e,t,n).implementation}function b(e,t){let n=f(t);if(n.test(e))return e;let r=n.conversionsTo;if(r.length===0)throw Error(`There are no conversions to `+t+` defined.`);for(let t=0;t<r.length;t++)if(f(r[t].from).test(e))return r[t].convert(e);throw Error(`Cannot convert `+e+` to `+t)}function x(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:`,`;return e.map(e=>e.name).join(t)}function S(e){let t=e.indexOf(`...`)===0,n=(t?e.length>3?e.slice(3):`any`:e).split(`|`).map(e=>f(e.trim())),r=!1,i=t?`...`:``;return{types:n.map(function(e){return r=e.isAny||r,i+=e.name+`|`,{name:e.name,typeIndex:e.index,test:e.test,isAny:e.isAny,conversion:null,conversionIndex:-1}}),name:i.slice(0,-1),hasAny:r,hasConversion:!1,restParam:t}}function C(e){let t=R(e.types.map(e=>e.name)),n=e.hasAny,r=e.name,i=t.map(function(e){let t=f(e.from);return n=t.isAny||n,r+=`|`+e.from,{name:e.from,typeIndex:t.index,test:t.test,isAny:t.isAny,conversion:e,conversionIndex:e.index}});return{types:e.types.concat(i),name:r,hasAny:n,hasConversion:i.length>0,restParam:e.restParam}}function w(e){return e.typeSet||(e.typeSet=new Set,e.types.forEach(t=>e.typeSet.add(t.name))),e.typeSet}function T(e){let t=[];if(typeof e!=`string`)throw TypeError(`Signatures must be strings`);let n=e.trim();if(n===``)return t;let r=n.split(`,`);for(let e=0;e<r.length;++e){let n=S(r[e].trim());if(n.restParam&&e!==r.length-1)throw SyntaxError(`Unexpected rest parameter "`+r[e]+`": only allowed for the last parameter`);if(n.types.length===0)return null;t.push(n)}return t}function E(e){let t=oe(e);return t?t.restParam:!1}function D(t){if(!t||t.types.length===0)return e;if(t.types.length===1)return f(t.types[0].name).test;if(t.types.length===2){let e=f(t.types[0].name).test,n=f(t.types[1].name).test;return function(t){return e(t)||n(t)}}else{let e=t.types.map(function(e){return f(e.name).test});return function(t){for(let n=0;n<e.length;n++)if(e[n](t))return!0;return!1}}}function O(e){let t,n,r;if(E(e)){t=ae(e).map(D);let n=t.length,r=D(oe(e)),i=function(e){for(let t=n;t<e.length;t++)if(!r(e[t]))return!1;return!0};return function(e){for(let n=0;n<t.length;n++)if(!t[n](e[n]))return!1;return i(e)&&e.length>=n+1}}else if(e.length===0)return function(e){return e.length===0};else if(e.length===1)return n=D(e[0]),function(e){return n(e[0])&&e.length===1};else if(e.length===2)return n=D(e[0]),r=D(e[1]),function(e){return n(e[0])&&r(e[1])&&e.length===2};else return t=e.map(D),function(e){for(let n=0;n<t.length;n++)if(!t[n](e[n]))return!1;return e.length===t.length}}function k(e,t){return t<e.length?e[t]:E(e)?oe(e):null}function A(e,t){let n=k(e,t);return n?w(n):new Set}function j(e){return e.conversion===null||e.conversion===void 0}function M(e,t){let n=new Set;return e.forEach(e=>{let r=A(e.params,t),i;for(i of r)n.add(i)}),n.has(`any`)?[`any`]:Array.from(n)}function N(e,t,n){let r,i,a=e||`unnamed`,o=n,s;for(s=0;s<t.length;s++){let e=[];if(o.forEach(n=>{let r=D(k(n.params,s));(s<n.params.length||E(n.params))&&r(t[s])&&e.push(n)}),e.length===0){if(i=M(o,s),i.length>0){let e=g(t[s]);return r=TypeError(`Unexpected type of argument in function `+a+` (expected: `+i.join(` or `)+`, actual: `+e.join(` | `)+`, index: `+s+`)`),r.data={category:`wrongType`,fn:a,index:s,actual:e,expected:i},r}}else o=e}let c=o.map(function(e){return E(e.params)?1/0:e.params.length});if(t.length<Math.min.apply(null,c))return i=M(o,s),r=TypeError(`Too few arguments in function `+a+` (expected: `+i.join(` or `)+`, index: `+t.length+`)`),r.data={category:`tooFewArgs`,fn:a,index:t.length,expected:i},r;let l=Math.max.apply(null,c);if(t.length>l)return r=TypeError(`Too many arguments in function `+a+` (expected: `+l+`, actual: `+t.length+`)`),r.data={category:`tooManyArgs`,fn:a,index:t.length,expectedLength:l},r;let u=[];for(let e=0;e<t.length;++e)u.push(g(t[e]).join(`|`));return r=TypeError(`Arguments of type "`+u.join(`, `)+`" do not match any of the defined signatures of function `+a+`.`),r.data={category:`mismatch`,actual:u},r}function P(e){let t=l.length+1;for(let n=0;n<e.types.length;n++)t=Math.min(t,e.types[n].typeIndex);return t}function F(e){let t=u+1;for(let n=0;n<e.types.length;n++)j(e.types[n])||(t=Math.min(t,e.types[n].conversionIndex));return t}function I(e,t){if(e.hasAny){if(!t.hasAny)return .1}else if(t.hasAny)return-.1;if(e.restParam){if(!t.restParam)return .01}else if(t.restParam)return-.01;let n=P(e)-P(t);if(n<0)return-.001;if(n>0)return .001;let r=F(e),i=F(t);if(e.hasConversion){if(!t.hasConversion)return(1+r)*1e-6}else if(t.hasConversion)return-(1+i)*1e-6;let a=r-i;return a<0?-1e-7:a>0?1e-7:0}function L(e,t){let n=e.params,r=t.params,i=oe(n),a=oe(r),o=E(n),s=E(r);if(o&&i.hasAny){if(!s||!a.hasAny)return 1e7}else if(s&&a.hasAny)return-1e7;let c=0,l=0,u;for(u of n)u.hasAny&&++c,u.hasConversion&&++l;let d=0,f=0;for(u of r)u.hasAny&&++d,u.hasConversion&&++f;if(c!==d)return(c-d)*1e6;if(o&&i.hasConversion){if(!s||!a.hasConversion)return 1e5}else if(s&&a.hasConversion)return-1e5;if(l!==f)return(l-f)*1e4;if(o){if(!s)return 1e3}else if(s)return-1e3;let p=(n.length-r.length)*(o?-100:100);if(p!==0)return p;let m=[],h=0;for(let e=0;e<n.length;++e){let t=I(n[e],r[e]);m.push(t),h+=t}if(h!==0)return(h<0?-10:10)+h;let g,_=9,v=_/(m.length+1);for(g of m){if(g!==0)return(g<0?-_:_)+g;_-=v}return 0}function R(e){if(e.length===0)return[];let t=e.map(f);if(e.length===1)return t[0].conversionsTo;let n=new Set(e),r=new Set;for(let e=0;e<t.length;++e)for(let i of t[e].conversionsTo)n.has(i.from)||r.add(i.from);let i=[];for(let e of r){let n=u+1,r=null;for(let i=0;i<t.length;++i)for(let a of t[i].conversionsTo)a.from===e&&a.index<n&&(n=a.index,r=a);i.push(r)}return i}function z(e,t){let n=t,r=``;if(e.some(e=>e.hasConversion)){let i=E(e),a=e.map(B);r=a.map(e=>e.name).join(`;`),n=function(){let e=[],n=i?arguments.length-1:arguments.length;for(let t=0;t<n;t++)e[t]=a[t](arguments[t]);return i&&(e[n]=arguments[n].map(a[n])),t.apply(this,e)}}let i=n;if(E(e)){let t=e.length-1;i=function(){return n.apply(this,se(arguments,0,t).concat([se(arguments,t)]))}}return r&&Object.defineProperty(i,`name`,{value:r}),i}function B(e){let t,n,r,i,a=[],o=[],s=``;e.types.forEach(function(e){e.conversion&&(s+=e.conversion.from+`~>`+e.conversion.to+`,`,a.push(f(e.conversion.from).test),o.push(e.conversion.convert))}),s=s?s.slice(0,-1):`pass`;let c=e=>e;switch(o.length){case 0:break;case 1:t=a[0],r=o[0],c=function(e){return t(e)?r(e):e};break;case 2:t=a[0],n=a[1],r=o[0],i=o[1],c=function(e){return t(e)?r(e):n(e)?i(e):e};break;default:c=function(e){for(let t=0;t<o.length;t++)if(a[t](e))return o[t](e);return e}}return Object.defineProperty(c,`name`,{value:s}),c}function V(e){function t(e,n,r){if(n<e.length){let i=e[n],a=[];if(i.restParam){let e=i.types.filter(j);e.length<i.types.length&&a.push({types:e,name:`...`+e.map(e=>e.name).join(`|`),hasAny:e.some(e=>e.isAny),hasConversion:!1,restParam:!0}),a.push(i)}else a=i.types.map(function(e){return{types:[e],name:e.name,hasAny:e.isAny,hasConversion:e.conversion,restParam:!1}});return le(a,function(i){return t(e,n+1,r.concat([i]))})}else return[r]}return t(e,0,[])}function ee(e,t){let n=Math.max(e.length,t.length);for(let r=0;r<n;r++){let n=A(e,r),i=A(t,r),a=!1,o;for(o of i)if(n.has(o)){a=!0;break}if(!a)return!1}let r=e.length,i=t.length,a=E(e),o=E(t);return a?o?r===i:i>=r:o?r>=i:r===i}function te(e){return e.map(e=>me(e)?fe(e.referToSelf.callback):pe(e)?de(e.referTo.references,e.referTo.callback):e)}function H(e,t,n){let r=[],i;for(i of e){let e=n[i];if(typeof e!=`number`)throw TypeError(`No definition for referenced signature "`+i+`"`);if(e=t[e],typeof e!=`function`)return!1;r.push(e)}return r}function ne(e,t,n){let r=te(e),i=Array(r.length).fill(!1),a=!0;for(;a;){a=!1;let e=!0;for(let o=0;o<r.length;++o){if(i[o])continue;let s=r[o];if(me(s))r[o]=s.referToSelf.callback(n),r[o].referToSelf=s.referToSelf,i[o]=!0,e=!1;else if(pe(s)){let n=H(s.referTo.references,r,t);n?(r[o]=s.referTo.callback.apply(this,n),r[o].referTo=s.referTo,i[o]=!0,e=!1):a=!0}}if(e&&a)throw SyntaxError(`Circular reference detected in resolving typed.referTo`)}return r}function re(e){let t=/\bthis(\(|\.signatures\b)/;Object.keys(e).forEach(n=>{let r=e[n];if(t.test(r.toString()))throw SyntaxError("Using `this` to self-reference a function is deprecated since typed-function@3. Use typed.referTo and typed.referToSelf instead.")})}function ie(e,r){if(d.createCount++,Object.keys(r).length===0)throw SyntaxError(`No signatures provided`);d.warnAgainstDeprecatedThis&&re(r);let i=[],a=[],o={},s=[],c;for(c in r){if(!Object.prototype.hasOwnProperty.call(r,c))continue;let e=T(c);if(!e)continue;i.forEach(function(t){if(ee(t,e))throw TypeError(`Conflicting signatures "`+x(t)+`" and "`+x(e)+`".`)}),i.push(e);let t=a.length;a.push(r[c]);let n=e.map(C),l;for(l of V(n)){let e=x(l);s.push({params:l,name:e,fn:t}),l.every(e=>!e.hasConversion)&&(o[e]=t)}}s.sort(L);let l=ne(a,o,ve),u;for(u in o)Object.prototype.hasOwnProperty.call(o,u)&&(o[u]=l[o[u]]);let f=[],p=new Map;for(u of s)p.has(u.name)||(u.fn=l[u.fn],f.push(u),p.set(u.name,u));let m=f[0]&&f[0].params.length<=2&&!E(f[0].params),h=f[1]&&f[1].params.length<=2&&!E(f[1].params),g=f[2]&&f[2].params.length<=2&&!E(f[2].params),_=f[3]&&f[3].params.length<=2&&!E(f[3].params),v=f[4]&&f[4].params.length<=2&&!E(f[4].params),y=f[5]&&f[5].params.length<=2&&!E(f[5].params),b=m&&h&&g&&_&&v&&y;for(let e=0;e<f.length;++e)f[e].test=O(f[e].params);let S=m?D(f[0].params[0]):t,w=h?D(f[1].params[0]):t,k=g?D(f[2].params[0]):t,A=_?D(f[3].params[0]):t,j=v?D(f[4].params[0]):t,M=y?D(f[5].params[0]):t,N=m?D(f[0].params[1]):t,P=h?D(f[1].params[1]):t,F=g?D(f[2].params[1]):t,I=_?D(f[3].params[1]):t,R=v?D(f[4].params[1]):t,B=y?D(f[5].params[1]):t;for(let e=0;e<f.length;++e)f[e].implementation=z(f[e].params,f[e].fn);let te=m?f[0].implementation:n,H=h?f[1].implementation:n,ie=g?f[2].implementation:n,U=_?f[3].implementation:n,ae=v?f[4].implementation:n,oe=y?f[5].implementation:n,se=m?f[0].params.length:-1,ce=h?f[1].params.length:-1,le=g?f[2].params.length:-1,ue=_?f[3].params.length:-1,de=v?f[4].params.length:-1,fe=y?f[5].params.length:-1,pe=b?6:0,me=f.length,he=f.map(e=>e.test),ge=f.map(e=>e.implementation),_e=function(){for(let e=pe;e<me;e++)if(he[e](arguments))return ge[e].apply(this,arguments);return d.onMismatch(e,arguments,f)};function ve(e,t){return arguments.length===se&&S(e)&&N(t)?te.apply(this,arguments):arguments.length===ce&&w(e)&&P(t)?H.apply(this,arguments):arguments.length===le&&k(e)&&F(t)?ie.apply(this,arguments):arguments.length===ue&&A(e)&&I(t)?U.apply(this,arguments):arguments.length===de&&j(e)&&R(t)?ae.apply(this,arguments):arguments.length===fe&&M(e)&&B(t)?oe.apply(this,arguments):_e.apply(this,arguments)}try{Object.defineProperty(ve,`name`,{value:e})}catch{}return ve.signatures=o,ve._typedFunctionData={signatures:f,signatureMap:p},ve}function U(e,t,n){throw N(e,t,n)}function ae(e){return se(e,0,e.length-1)}function oe(e){return e[e.length-1]}function se(e,t,n){return Array.prototype.slice.call(e,t,n)}function ce(e,t){for(let n=0;n<e.length;n++)if(t(e[n]))return e[n]}function le(e,t){return Array.prototype.concat.apply([],e.map(t))}function ue(){let e=ae(arguments).map(e=>x(T(e))),t=oe(arguments);if(typeof t!=`function`)throw TypeError(`Callback function expected as last argument`);return de(e,t)}function de(e,t){return{referTo:{references:e,callback:t}}}function fe(e){if(typeof e!=`function`)throw TypeError(`Callback function expected as first argument`);return{referToSelf:{callback:e}}}function pe(e){return e&&typeof e.referTo==`object`&&Array.isArray(e.referTo.references)&&typeof e.referTo.callback==`function`}function me(e){return e&&typeof e.referToSelf==`object`&&typeof e.referToSelf.callback==`function`}function he(e,t){if(!e)return t;if(t&&t!==e){let n=Error(`Function names do not match (expected: `+e+`, actual: `+t+`)`);throw n.data={actual:t,expected:e},n}return e}function ge(e){let t;for(let n in e)Object.prototype.hasOwnProperty.call(e,n)&&(_(e[n])||typeof e[n].signature==`string`)&&(t=he(t,e[n].name));return t}function _e(e,t){let n;for(n in t)if(Object.prototype.hasOwnProperty.call(t,n)){if(n in e&&t[n]!==e[n]){let r=Error(`Signature "`+n+`" is defined twice`);throw r.data={signature:n,sourceFunction:t[n],destFunction:e[n]},r}e[n]=t[n]}}let ve=d;d=function(e){let t=typeof e==`string`,n=+!!t,r=t?e:``,i={};for(let e=n;e<arguments.length;++e){let n=arguments[e],o={},s;if(typeof n==`function`?(s=n.name,typeof n.signature==`string`?o[n.signature]=n:_(n)&&(o=n.signatures)):a(n)&&(o=n,t||(s=ge(n))),Object.keys(o).length===0){let t=TypeError(`Argument to 'typed' at index `+e+` is not a (typed) function, nor an object with signatures as keys and functions as values.`);throw t.data={index:e,argument:n},t}t||(r=he(r,s)),_e(i,o)}return ie(r||``,i)},d.create=i,d.createCount=ve.createCount,d.onMismatch=U,d.throwMismatchError=U,d.createError=N,d.clear=m,d.clearConversions=h,d.addTypes=p,d._findType=f,d.referTo=ue,d.referToSelf=fe,d.convert=b,d.findSignature=v,d.find=y,d.isTypedFunction=_,d.warnAgainstDeprecatedThis=!0,d.addType=function(e,t){let n=`any`;t!==!1&&c.has(`Object`)&&(n=`Object`),d.addTypes([e],n)};function ye(e){if(!e||typeof e.from!=`string`||typeof e.to!=`string`||typeof e.convert!=`function`)throw TypeError(`Object with properties {from: string, to: string, convert: function} expected`);if(e.to===e.from)throw SyntaxError(`Illegal to define conversion from "`+e.from+`" to itself.`)}return d.addConversion=function(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{override:!1};ye(e);let n=f(e.to),r=n.conversionsTo.find(t=>t.from===e.from);if(r)if(t&&t.override)d.removeConversion({from:r.from,to:e.to,convert:r.convert});else throw Error(`There is already a conversion from "`+e.from+`" to "`+n.name+`"`);n.conversionsTo.push({from:e.from,to:n.name,convert:e.convert,index:u++})},d.addConversions=function(e,t){e.forEach(e=>d.addConversion(e,t))},d.removeConversion=function(e){ye(e);let t=f(e.to),n=ce(t.conversionsTo,t=>t.from===e.from);if(!n)throw Error(`Attempt to remove nonexistent conversion from `+e.from+` to `+e.to);if(n.convert!==e.convert)throw Error(`Conversion to remove does not match existing conversion`);let r=t.conversionsTo.indexOf(n);t.conversionsTo.splice(r,1)},d.resolve=function(e,t){if(!_(e))throw TypeError(r);let n=e._typedFunctionData.signatures;for(let e=0;e<n.length;++e)if(n[e].test(t))return n[e];return null},d}return i()}))}));function J(e,t,n,r){function i(r){var i=Di(r,t.map(Ii));return Pi(e,t,r),n(i)}return i.isFactory=!0,i.fn=e,i.dependencies=t.slice().sort(),r&&(i.meta=r),i}function Ni(e){return typeof e==`function`&&typeof e.fn==`string`&&Array.isArray(e.dependencies)}function Pi(e,t,n){if(!t.filter(e=>!Fi(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 Fi(e){return e&&e[0]===`?`}function Ii(e){return e&&e[0]===`?`?e.slice(1):e}function Li(e){return typeof e==`boolean`?!0:Number.isFinite(e)?e===Math.round(e):!1}function Ri(e,t){if(t.number===`bigint`)try{BigInt(e)}catch{return t.numberFallback}return t.number}var zi=Math.sign||function(e){return e>0?1:e<0?-1:0},Bi=Math.log2||function(e){return Math.log(e)/Math.LN2},Vi=Math.log10||function(e){return Math.log(e)/Math.LN10},Hi=Math.log1p||function(e){return Math.log(e+1)},Ui=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},Wi=Math.expm1||function(e){return e>=2e-4||e<=-2e-4?Math.exp(e)-1:e+e*e/2+e*e*e/6};function Gi(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(!Li(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(!Li(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 Ki(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}=qi(t);switch(n){case`fixed`:return Xi(e,r);case`exponential`:return Zi(e,r);case`engineering`:return Yi(e,r);case`bin`:return Gi(e,2,i);case`oct`:return Gi(e,8,i);case`hex`:return Gi(e,16,i);case`auto`:return Qi(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 qi(e){var t=`auto`,n,r;if(e!==void 0)if(Er(e))n=e;else if(Dr(e))n=e.toNumber();else if(Kr(e))e.precision!==void 0&&(n=ua(e.precision,()=>{throw Error(`Option "precision" must be a number or BigNumber`)})),e.wordSize!==void 0&&(r=ua(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 Ji(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 Yi(e,t){if(isNaN(e)||!Number.isFinite(e))return String(e);var n=$i(Ji(e),t),r=n.exponent,i=n.coefficients,a=r%3==0?r:r<0?r-3-r%3:r-r%3;if(Er(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=Er(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 Xi(e,t){if(isNaN(e)||!Number.isFinite(e))return String(e);var n=Ji(e),r=typeof t==`number`?$i(n,n.exponent+1+t):n,i=r.coefficients,a=r.exponent+1,o=a+(t||0);return i.length<o&&(i=i.concat(ea(o-i.length))),a<0&&(i=ea(-a+1).concat(i),a=1),a<i.length&&i.splice(a,0,a===0?`0.`:`.`),r.sign+i.join(``)}function Zi(e,t){if(isNaN(e)||!Number.isFinite(Number(e)))return String(e);var n=Ji(e),r=t?$i(n,t):n,i=r.coefficients,a=r.exponent;i.length<t&&(i=i.concat(ea(t-i.length)));var o=i.shift();return r.sign+o+(i.length>0?`.`+i.join(``):``)+`e`+(a>=0?`+`:``)+a}function Qi(e,t,n){if(isNaN(e)||!Number.isFinite(e))return String(e);var r=da(n?.lowerExp,-3),i=da(n?.upperExp,5),a=Ji(e),o=t?$i(a,t):a;if(o.exponent<r||o.exponent>=i)return Zi(e,t);var s=o.coefficients,c=o.exponent;s.length<t&&(s=s.concat(ea(t-s.length))),s=s.concat(ea(c-s.length+1+(s.length<t?t-s.length:0))),s=ea(-c).concat(s);var l=c>0?c:0;return l<s.length-1&&s.splice(l+1,0,`.`),o.sign+s.join(``)}function $i(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 ea(e){for(var t=[],n=0;n<e;n++)t.push(0);return t}function ta(e){return e.toExponential().replace(/e.*$/,``).replace(/^0\.?0*|\./,``).length}function na(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 ra=Math.acosh||function(e){return Math.log(Math.sqrt(e*e-1)+e)},ia=Math.asinh||function(e){return Math.log(Math.sqrt(e*e+1)+e)},aa=Math.atanh||function(e){return Math.log((1+e)/(1-e))/2},oa=Math.cosh||function(e){return(Math.exp(e)+Math.exp(-e))/2},sa=Math.sinh||function(e){return(Math.exp(e)-Math.exp(-e))/2},ca=Math.tanh||function(e){var t=Math.exp(2*e);return(t-1)/(t+1)};function la(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 ua(e,t){if(Er(e))return e;if(Dr(e))return e.toNumber();t()}function da(e,t){return Er(e)?e:Dr(e)?e.toNumber():t}var fa=Dt(Mi(),1),pa=function(){return pa=fa.default.create,fa.default},ma=J(`typed`,[`?BigNumber`,`?Complex`,`?DenseMatrix`,`?Fraction`],function(e){var{BigNumber:t,Complex:n,DenseMatrix:r,Fraction:i}=e,a=pa();return a.clear(),a.addTypes([{name:`number`,test:Er},{name:`Complex`,test:kr},{name:`BigNumber`,test:Dr},{name:`bigint`,test:Or},{name:`Fraction`,test:Ar},{name:`Unit`,test:jr},{name:`identifier`,test:e=>Mr&&/^(?:[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:Mr},{name:`Chain`,test:hi},{name:`Array`,test:Nr},{name:`Matrix`,test:Pr},{name:`DenseMatrix`,test:Ir},{name:`SparseMatrix`,test:Lr},{name:`Range`,test:Rr},{name:`Index`,test:zr},{name:`boolean`,test:Br},{name:`ResultSet`,test:Vr},{name:`Help`,test:Hr},{name:`function`,test:Ur},{name:`Date`,test:Wr},{name:`RegExp`,test:Gr},{name:`null`,test:Xr},{name:`undefined`,test:Zr},{name:`AccessorNode`,test:Qr},{name:`ArrayNode`,test:$r},{name:`AssignmentNode`,test:ei},{name:`BlockNode`,test:ti},{name:`ConditionalNode`,test:ni},{name:`ConstantNode`,test:ri},{name:`FunctionNode`,test:oi},{name:`FunctionAssignmentNode`,test:ai},{name:`IndexNode`,test:si},{name:`Node`,test:ci},{name:`ObjectNode`,test:li},{name:`OperatorNode`,test:ui},{name:`ParenthesisNode`,test:di},{name:`RangeNode`,test:fi},{name:`RelationalNode`,test:pi},{name:`SymbolNode`,test:mi},{name:`Map`,test:qr},{name:`Object`,test:Kr}]),a.addConversions([{from:`number`,to:`BigNumber`,convert:function(e){if(t||ha(e),ta(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||ga(e),new n(e,0)}},{from:`BigNumber`,to:`Complex`,convert:function(e){return n||ga(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||ha(e),new t(e.toString())}},{from:`bigint`,to:`Fraction`,convert:function(e){return i||va(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||ga(e),new n(e.valueOf(),0)}},{from:`number`,to:`Fraction`,convert:function(e){i||va(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||ha(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||va(e);try{return new i(e)}catch{throw Error(`Cannot convert "`+e+`" to Fraction`)}}},{from:`string`,to:`Complex`,convert:function(e){n||ga(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||ha(e),new t(+e)}},{from:`boolean`,to:`bigint`,convert:function(e){return BigInt(+e)}},{from:`boolean`,to:`Fraction`,convert:function(e){return i||va(e),new i(+e)}},{from:`boolean`,to:`string`,convert:function(e){return String(e)}},{from:`Array`,to:`Matrix`,convert:function(e){return r||_a(),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&&Fr(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&&Fr(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 ha(e){throw Error(`Cannot convert value ${e} into a BigNumber: no class 'BigNumber' provided`)}function ga(e){throw Error(`Cannot convert value ${e} into a Complex number: no class 'Complex' provided`)}function _a(){throw Error(`Cannot convert array into a Matrix: no class 'DenseMatrix' provided`)}function va(e){throw Error(`Cannot convert value ${e} into a Fraction, no class 'Fraction' provided.`)}var ya=J(`ResultSet`,[],()=>{function e(t){if(!(this instanceof e))throw SyntaxError(`Constructor must be called with the new operator`);this.entries=t||[]}return e.prototype.type=`ResultSet`,e.prototype.isResultSet=!0,e.prototype.valueOf=function(){return this.entries},e.prototype.toString=function(){return`[`+this.entries.map(String).join(`, `)+`]`},e.prototype.toJSON=function(){return{mathjs:`ResultSet`,entries:this.entries}},e.fromJSON=function(t){return new e(t.entries)},e},{isClass:!0}),ba=9e15,xa=1e9,Sa=`0123456789abcdef`,Ca=`2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058`,wa=`3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789`,Ta={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-ba,maxE:ba,crypto:!1},Ea,Da,Oa=!0,ka=`[DecimalError] `,Aa=ka+`Invalid argument: `,ja=ka+`Precision limit exceeded`,Ma=ka+`crypto unavailable`,Na=`[object Decimal]`,Pa=Math.floor,Fa=Math.pow,Ia=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,La=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,Ra=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,za=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,Ba=1e7,Va=7,Ha=9007199254740991,Ua=Ca.length-1,Wa=wa.length-1,Y={toStringTag:Na};Y.absoluteValue=Y.abs=function(){var e=new this.constructor(this);return e.s<0&&(e.s=1),Za(e)},Y.ceil=function(){return Za(new this.constructor(this),this.e+1,2)},Y.clampedTo=Y.clamp=function(e,t){var n,r=this,i=r.constructor;if(e=new i(e),t=new i(t),!e.s||!t.s)return new i(NaN);if(e.gt(t))throw Error(Aa+t);return n=r.cmp(e),n<0?e:r.cmp(t)>0?t:new i(r)},Y.comparedTo=Y.cmp=function(e){var t,n,r,i,a=this,o=a.d,s=(e=new a.constructor(e)).d,c=a.s,l=e.s;if(!o||!s)return!c||!l?NaN:c===l?o===s?0:!o^c<0?1:-1:c;if(!o[0]||!s[0])return o[0]?c:s[0]?-l:0;if(c!==l)return c;if(a.e!==e.e)return a.e>e.e^c<0?1:-1;for(r=o.length,i=s.length,t=0,n=r<i?r:i;t<n;++t)if(o[t]!==s[t])return o[t]>s[t]^c<0?1:-1;return r===i?0:r>i^c<0?1:-1},Y.cosine=Y.cos=function(){var e,t,n=this,r=n.constructor;return n.d?n.d[0]?(e=r.precision,t=r.rounding,r.precision=e+Math.max(n.e,n.sd())+Va,r.rounding=1,n=Ya(r,go(r,n)),r.precision=e,r.rounding=t,Za(Da==2||Da==3?n.neg():n,e,t,!0)):new r(1):new r(NaN)},Y.cubeRoot=Y.cbrt=function(){var e,t,n,r,i,a,o,s,c,l,u=this,d=u.constructor;if(!u.isFinite()||u.isZero())return new d(u);for(Oa=!1,a=u.s*Fa(u.s*u,1/3),!a||Math.abs(a)==1/0?(n=Ga(u.d),e=u.e,(a=(e-n.length+1)%3)&&(n+=a==1||a==-2?`0`:`00`),a=Fa(n,1/3),e=Pa((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=Xa(l.plus(u).times(s),l.plus(c),o+2,1),Ga(s.d).slice(0,o)===(n=Ga(r.d)).slice(0,o))if(n=n.slice(o-3,o+1),n==`9999`||!i&&n==`4999`){if(!i&&(Za(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`)&&(Za(r,e+1,1),t=!r.times(r).times(r).eq(u));break}return Oa=!0,Za(r,e,d.rounding,t)},Y.decimalPlaces=Y.dp=function(){var e,t=this.d,n=NaN;if(t){if(e=t.length-1,n=(e-Pa(this.e/Va))*Va,e=t[e],e)for(;e%10==0;e/=10)n--;n<0&&(n=0)}return n},Y.dividedBy=Y.div=function(e){return Xa(this,new this.constructor(e))},Y.dividedToIntegerBy=Y.divToInt=function(e){var t=this,n=t.constructor;return Za(Xa(t,new n(e),0,1,1),n.precision,n.rounding)},Y.equals=Y.eq=function(e){return this.cmp(e)===0},Y.floor=function(){return Za(new this.constructor(this),this.e+1,3)},Y.greaterThan=Y.gt=function(e){return this.cmp(e)>0},Y.greaterThanOrEqualTo=Y.gte=function(e){var t=this.cmp(e);return t==1||t===0},Y.hyperbolicCosine=Y.cosh=function(){var e,t,n,r,i,a=this,o=a.constructor,s=new o(1);if(!a.isFinite())return new o(a.s?1/0:NaN);if(a.isZero())return s;n=o.precision,r=o.rounding,o.precision=n+Math.max(a.e,a.sd())+4,o.rounding=1,i=a.d.length,i<32?(e=Math.ceil(i/3),t=(1/ho(4,e)).toString()):(e=16,t=`2.3283064365386962890625e-10`),a=mo(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 Za(a,o.precision=n,o.rounding=r,!0)},Y.hyperbolicSine=Y.sinh=function(){var e,t,n,r,i=this,a=i.constructor;if(!i.isFinite()||i.isZero())return new a(i);if(t=a.precision,n=a.rounding,a.precision=t+Math.max(i.e,i.sd())+4,a.rounding=1,r=i.d.length,r<3)i=mo(a,2,i,i,!0);else{e=1.4*Math.sqrt(r),e=e>16?16:e|0,i=i.times(1/ho(5,e)),i=mo(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,Za(i,t,n,!0)},Y.hyperbolicTangent=Y.tanh=function(){var e,t,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+7,r.rounding=1,Xa(n.sinh(),n.cosh(),r.precision=e,r.rounding=t)):new r(n.s)},Y.inverseCosine=Y.acos=function(){var e=this,t=e.constructor,n=e.abs().cmp(1),r=t.precision,i=t.rounding;return n===-1?e.isZero()?to(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()?to(t,r,i):new t(0):new t(NaN)},Y.inverseHyperbolicCosine=Y.acosh=function(){var e,t,n=this,r=n.constructor;return n.lte(1)?new r(n.eq(1)?0:NaN):n.isFinite()?(e=r.precision,t=r.rounding,r.precision=e+Math.max(Math.abs(n.e),n.sd())+4,r.rounding=1,Oa=!1,n=n.times(n).minus(1).sqrt().plus(n),Oa=!0,r.precision=e,r.rounding=t,n.ln()):new r(n)},Y.inverseHyperbolicSine=Y.asinh=function(){var e,t,n=this,r=n.constructor;return!n.isFinite()||n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+2*Math.max(Math.abs(n.e),n.sd())+6,r.rounding=1,Oa=!1,n=n.times(n).plus(1).sqrt().plus(n),Oa=!0,r.precision=e,r.rounding=t,n.ln())},Y.inverseHyperbolicTangent=Y.atanh=function(){var e,t,n,r,i=this,a=i.constructor;return i.isFinite()?i.e>=0?new a(i.abs().eq(1)?i.s/0:i.isZero()?i:NaN):(e=a.precision,t=a.rounding,r=i.sd(),Math.max(r,e)<2*-i.e-1?Za(new a(i),e,t,!0):(a.precision=n=r-i.e,i=Xa(i.plus(1),new a(1).minus(i),n+e,1),a.precision=e+4,a.rounding=1,i=i.ln(),a.precision=e,a.rounding=t,i.times(.5))):new a(NaN)},Y.inverseSine=Y.asin=function(){var e,t,n,r,i=this,a=i.constructor;return i.isZero()?new a(i):(t=i.abs().cmp(1),n=a.precision,r=a.rounding,t===-1?(a.precision=n+6,a.rounding=1,i=i.div(new a(1).minus(i.times(i)).sqrt().plus(1)).atan(),a.precision=n,a.rounding=r,i.times(2)):t===0?(e=to(a,n+4,r).times(.5),e.s=i.s,e):new a(NaN))},Y.inverseTangent=Y.atan=function(){var e,t,n,r,i,a,o,s,c,l=this,u=l.constructor,d=u.precision,f=u.rounding;if(!l.isFinite()){if(!l.s)return new u(NaN);if(d+4<=Wa)return o=to(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<=Wa)return o=to(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/Va+2|0),e=n;e;--e)l=l.div(l.times(l).plus(1).sqrt().plus(1));for(Oa=!1,t=Math.ceil(s/Va),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)),Oa=!0,Za(o,u.precision=d,u.rounding=f,!0)},Y.isFinite=function(){return!!this.d},Y.isInteger=Y.isInt=function(){return!!this.d&&Pa(this.e/Va)>this.d.length-2},Y.isNaN=function(){return!this.s},Y.isNegative=Y.isNeg=function(){return this.s<0},Y.isPositive=Y.isPos=function(){return this.s>0},Y.isZero=function(){return!!this.d&&this.d[0]===0},Y.lessThan=Y.lt=function(e){return this.cmp(e)<0},Y.lessThanOrEqualTo=Y.lte=function(e){return this.cmp(e)<1},Y.logarithm=Y.log=function(e){var t,n,r,i,a,o,s,c,l=this,u=l.constructor,d=u.precision,f=u.rounding,p=5;if(e==null)e=new u(10),t=!0;else{if(e=new u(e),n=e.d,e.s<0||!n||!n[0]||e.eq(1))return new u(NaN);t=e.eq(10)}if(n=l.d,l.s<0||!n||!n[0]||l.eq(1))return new u(n&&!n[0]?-1/0:l.s==1?n?0:1/0:NaN);if(t)if(n.length>1)a=!0;else{for(i=n[0];i%10==0;)i/=10;a=i!==1}if(Oa=!1,s=d+p,o=co(l,s),r=t?eo(u,s+10):co(e,s),c=Xa(o,r,s,1),qa(c.d,i=d,f))do if(s+=10,o=co(l,s),r=t?eo(u,s+10):co(e,s),c=Xa(o,r,s,1),!a){+Ga(c.d).slice(i+1,i+15)+1==0x5af3107a4000&&(c=Za(c,d+1,0));break}while(qa(c.d,i+=10,f));return Oa=!0,Za(c,d,f)},Y.minus=Y.sub=function(e){var t,n,r,i,a,o,s,c,l,u,d,f,p=this,m=p.constructor;if(e=new m(e),!p.d||!e.d)return!p.s||!e.s?e=new m(NaN):p.d?e.s=-e.s:e=new m(e.d||p.s!==e.s?p:NaN),e;if(p.s!=e.s)return e.s=-e.s,p.plus(e);if(l=p.d,f=e.d,s=m.precision,c=m.rounding,!l[0]||!f[0]){if(f[0])e.s=-e.s;else if(l[0])e=new m(p);else return new m(c===3?-0:0);return Oa?Za(e,s,c):e}if(n=Pa(e.e/Va),u=Pa(p.e/Va),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/Va),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]=Ba-1;--l[i],l[r]+=Ba}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=$a(l,n),Oa?Za(e,s,c):e):new m(c===3?-0:0)},Y.modulo=Y.mod=function(e){var t,n=this,r=n.constructor;return e=new r(e),!n.d||!e.s||e.d&&!e.d[0]?new r(NaN):!e.d||n.d&&!n.d[0]?Za(new r(n),r.precision,r.rounding):(Oa=!1,r.modulo==9?(t=Xa(n,e.abs(),0,3,1),t.s*=e.s):t=Xa(n,e,0,r.modulo,1),t=t.times(e),Oa=!0,n.minus(t))},Y.naturalExponential=Y.exp=function(){return so(this)},Y.naturalLogarithm=Y.ln=function(){return co(this)},Y.negated=Y.neg=function(){var e=new this.constructor(this);return e.s=-e.s,Za(e)},Y.plus=Y.add=function(e){var t,n,r,i,a,o,s,c,l,u,d=this,f=d.constructor;if(e=new f(e),!d.d||!e.d)return!d.s||!e.s?e=new f(NaN):d.d||(e=new f(e.d||d.s===e.s?d:NaN)),e;if(d.s!=e.s)return e.s=-e.s,d.minus(e);if(l=d.d,u=e.d,s=f.precision,c=f.rounding,!l[0]||!u[0])return u[0]||(e=new f(d)),Oa?Za(e,s,c):e;if(a=Pa(d.e/Va),r=Pa(e.e/Va),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/Va),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)/Ba|0,l[i]%=Ba;for(t&&(l.unshift(t),++r),o=l.length;l[--o]==0;)l.pop();return e.d=l,e.e=$a(l,r),Oa?Za(e,s,c):e},Y.precision=Y.sd=function(e){var t,n=this;if(e!==void 0&&e!==!!e&&e!==1&&e!==0)throw Error(Aa+e);return n.d?(t=no(n.d),e&&n.e+1>t&&(t=n.e+1)):t=NaN,t},Y.round=function(){var e=this,t=e.constructor;return Za(new t(e),e.e+1,t.rounding)},Y.sine=Y.sin=function(){var e,t,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+Math.max(n.e,n.sd())+Va,r.rounding=1,n=po(r,go(r,n)),r.precision=e,r.rounding=t,Za(Da>2?n.neg():n,e,t,!0)):new r(NaN)},Y.squareRoot=Y.sqrt=function(){var e,t,n,r,i,a,o=this,s=o.d,c=o.e,l=o.s,u=o.constructor;if(l!==1||!s||!s[0])return new u(!l||l<0&&(!s||s[0])?NaN:s?o:1/0);for(Oa=!1,l=Math.sqrt(+o),l==0||l==1/0?(t=Ga(s),(t.length+c)%2==0&&(t+=`0`),l=Math.sqrt(t),c=Pa((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(Xa(o,a,n+2,1)).times(.5),Ga(a.d).slice(0,n)===(t=Ga(r.d)).slice(0,n))if(t=t.slice(n-3,n+1),t==`9999`||!i&&t==`4999`){if(!i&&(Za(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`)&&(Za(r,c+1,1),e=!r.times(r).eq(o));break}return Oa=!0,Za(r,c,u.rounding,e)},Y.tangent=Y.tan=function(){var e,t,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+10,r.rounding=1,n=n.sin(),n.s=1,n=Xa(n,new r(1).minus(n.times(n)).sqrt(),e+10,0),r.precision=e,r.rounding=t,Za(Da==2||Da==4?n.neg():n,e,t,!0)):new r(NaN)},Y.times=Y.mul=function(e){var t,n,r,i,a,o,s,c,l,u=this,d=u.constructor,f=u.d,p=(e=new d(e)).d;if(e.s*=u.s,!f||!f[0]||!p||!p[0])return new d(!e.s||f&&!f[0]&&!p||p&&!p[0]&&!f?NaN:!f||!p?e.s/0:e.s*0);for(n=Pa(u.e/Va)+Pa(e.e/Va),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%Ba|0,t=s/Ba|0;a[i]=(a[i]+t)%Ba|0}for(;!a[--o];)a.pop();return t?++n:a.shift(),e.d=a,e.e=$a(a,n),Oa?Za(e,d.precision,d.rounding):e},Y.toBinary=function(e,t){return _o(this,2,e,t)},Y.toDecimalPlaces=Y.toDP=function(e,t){var n=this,r=n.constructor;return n=new r(n),e===void 0?n:(Ka(e,0,xa),t===void 0?t=r.rounding:Ka(t,0,8),Za(n,e+n.e+1,t))},Y.toExponential=function(e,t){var n,r=this,i=r.constructor;return e===void 0?n=Qa(r,!0):(Ka(e,0,xa),t===void 0?t=i.rounding:Ka(t,0,8),r=Za(new i(r),e+1,t),n=Qa(r,!0,e+1)),r.isNeg()&&!r.isZero()?`-`+n:n},Y.toFixed=function(e,t){var n,r,i=this,a=i.constructor;return e===void 0?n=Qa(i):(Ka(e,0,xa),t===void 0?t=a.rounding:Ka(t,0,8),r=Za(new a(i),e+i.e+1,t),n=Qa(r,!1,e+r.e+1)),i.isNeg()&&!i.isZero()?`-`+n:n},Y.toFraction=function(e){var t,n,r,i,a,o,s,c,l,u,d,f,p=this,m=p.d,h=p.constructor;if(!m)return new h(p);if(l=n=new h(1),r=c=new h(0),t=new h(r),a=t.e=no(m)-p.e-1,o=a%Va,t.d[0]=Fa(10,o<0?Va+o:o),e==null)e=a>0?t:l;else{if(s=new h(e),!s.isInt()||s.lt(l))throw Error(Aa+s);e=s.gt(t)?a>0?t:l:s}for(Oa=!1,s=new h(Ga(m)),u=h.precision,h.precision=a=m.length*Va*2;d=Xa(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=Xa(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=Xa(l,r,a,1).minus(p).abs().cmp(Xa(c,n,a,1).minus(p).abs())<1?[l,r]:[c,n],h.precision=u,Oa=!0,f},Y.toHexadecimal=Y.toHex=function(e,t){return _o(this,16,e,t)},Y.toNearest=function(e,t){var n=this,r=n.constructor;if(n=new r(n),e==null){if(!n.d)return n;e=new r(1),t=r.rounding}else{if(e=new r(e),t===void 0?t=r.rounding:Ka(t,0,8),!n.d)return e.s?n:e;if(!e.d)return e.s&&=n.s,e}return e.d[0]?(Oa=!1,n=Xa(n,e,0,t,1).times(e),Oa=!0,Za(n)):(e.s=n.s,n=e),n},Y.toNumber=function(){return+this},Y.toOctal=function(e,t){return _o(this,8,e,t)},Y.toPower=Y.pow=function(e){var t,n,r,i,a,o,s=this,c=s.constructor,l=+(e=new c(e));if(!s.d||!e.d||!s.d[0]||!e.d[0])return new c(Fa(+s,l));if(s=new c(s),s.eq(1))return s;if(r=c.precision,a=c.rounding,e.eq(1))return Za(s,r,a);if(t=Pa(e.e/Va),t>=e.d.length-1&&(n=l<0?-l:l)<=Ha)return i=io(c,s,n,r),e.s<0?new c(1).div(i):Za(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=Fa(+s,l),t=n==0||!isFinite(n)?Pa(l*(Math.log(`0.`+Ga(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):(Oa=!1,c.rounding=s.s=1,n=Math.min(12,(t+``).length),i=so(e.times(co(s,r+n)),r),i.d&&(i=Za(i,r+5,1),qa(i.d,r,a)&&(t=r+10,i=Za(so(e.times(co(s,t+n)),t),t+5,1),+Ga(i.d).slice(r+1,r+15)+1==0x5af3107a4000&&(i=Za(i,r+1,0)))),i.s=o,Oa=!0,c.rounding=a,Za(i,r,a))},Y.toPrecision=function(e,t){var n,r=this,i=r.constructor;return e===void 0?n=Qa(r,r.e<=i.toExpNeg||r.e>=i.toExpPos):(Ka(e,1,xa),t===void 0?t=i.rounding:Ka(t,0,8),r=Za(new i(r),e,t),n=Qa(r,e<=r.e||r.e<=i.toExpNeg,e)),r.isNeg()&&!r.isZero()?`-`+n:n},Y.toSignificantDigits=Y.toSD=function(e,t){var n=this,r=n.constructor;return e===void 0?(e=r.precision,t=r.rounding):(Ka(e,1,xa),t===void 0?t=r.rounding:Ka(t,0,8)),Za(new r(n),e,t)},Y.toString=function(){var e=this,t=e.constructor,n=Qa(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()&&!e.isZero()?`-`+n:n},Y.truncated=Y.trunc=function(){return Za(new this.constructor(this),this.e+1,1)},Y.valueOf=Y.toJSON=function(){var e=this,t=e.constructor,n=Qa(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()?`-`+n:n};function Ga(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=Va-r.length,n&&(a+=ro(n)),a+=r;o=e[t],r=o+``,n=Va-r.length,n&&(a+=ro(n))}else if(o===0)return`0`;for(;o%10==0;)o/=10;return a+o}function Ka(e,t,n){if(e!==~~e||e<t||e>n)throw Error(Aa+e)}function qa(e,t,n,r){var i,a,o,s;for(a=e[0];a>=10;a/=10)--t;return--t<0?(t+=Va,i=0):(i=Math.ceil((t+1)/Va),t%=Va),a=Fa(10,Va-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)==Fa(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)==Fa(10,t-3)-1,o}function Ja(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]+=Sa.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 Ya(e,t){var n,r,i;if(t.isZero())return t;r=t.d.length,r<32?(n=Math.ceil(r/3),i=(1/ho(4,n)).toString()):(n=16,i=`2.3283064365386962890625e-10`),e.precision+=n,t=mo(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 Xa=(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=Ba,p=Va,u=Pa(r.e/p)-Pa(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,Ea=m;else{for(d=1,f=v[0];f>=10;f/=10)d++;_.e=d+u*p-1,Za(_,s?a+_.e+1:a,o,m)}return _}})();function Za(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+=Va,o=t,u=d[f=0],c=u/Fa(10,i-o-1)%10|0;else if(f=Math.ceil((a+1)/Va),s=d.length,f>=s)if(r){for(;s++<=f;)d.push(0);u=c=0,i=1,a%=Va,o=a-Va+1}else break out;else{for(u=s=d[f],i=1;s>=10;s/=10)i++;a%=Va,o=a-Va+i,c=o<0?0:u/Fa(10,i-o-1)%10|0}if(r=r||t<0||d[f+1]!==void 0||(o<0?u:u%Fa(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/Fa(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]=Fa(10,(Va-t%Va)%Va),e.e=-t||0):d[0]=e.e=0,e;if(a==0?(d.length=f,s=1,f--):(d.length=f+1,s=Fa(10,Va-a),d[f]=o>0?(u/Fa(10,i-o)%Fa(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]==Ba&&(d[0]=1));break}else{if(d[f]+=s,d[f]!=Ba)break;d[f--]=0,s=1}for(a=d.length;d[--a]===0;)d.pop()}return Oa&&(e.e>p.maxE?(e.d=null,e.e=NaN):e.e<p.minE&&(e.e=0,e.d=[0])),e}function Qa(e,t,n){if(!e.isFinite())return lo(e);var r,i=e.e,a=Ga(e.d),o=a.length;return t?(n&&(r=n-o)>0?a=a.charAt(0)+`.`+a.slice(1)+ro(r):o>1&&(a=a.charAt(0)+`.`+a.slice(1)),a=a+(e.e<0?`e`:`e+`)+e.e):i<0?(a=`0.`+ro(-i-1)+a,n&&(r=n-o)>0&&(a+=ro(r))):i>=o?(a+=ro(i+1-o),n&&(r=n-i-1)>0&&(a=a+`.`+ro(r))):((r=i+1)<o&&(a=a.slice(0,r)+`.`+a.slice(r)),n&&(r=n-o)>0&&(i+1===o&&(a+=`.`),a+=ro(r))),a}function $a(e,t){var n=e[0];for(t*=Va;n>=10;n/=10)t++;return t}function eo(e,t,n){if(t>Ua)throw Oa=!0,n&&(e.precision=n),Error(ja);return Za(new e(Ca),t,1,!0)}function to(e,t,n){if(t>Wa)throw Error(ja);return Za(new e(wa),t,n,!0)}function no(e){var t=e.length-1,n=t*Va+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 ro(e){for(var t=``;e--;)t+=`0`;return t}function io(e,t,n,r){var i,a=new e(1),o=Math.ceil(r/Va+4);for(Oa=!1;;){if(n%2&&(a=a.times(t),vo(a.d,o)&&(i=!0)),n=Pa(n/2),n===0){n=a.d.length-1,i&&a.d[n]===0&&++a.d[n];break}t=t.times(t),vo(t.d,o)}return Oa=!0,a}function ao(e){return e.d[e.d.length-1]&1}function oo(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 so(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?(Oa=!1,c=m):c=t,s=new f(.03125);e.e>-2;)e=e.times(s),d+=5;for(r=Math.log(Fa(2,d))/Math.LN10*2+5|0,c+=r,n=a=o=new f(1),f.precision=c;;){if(a=Za(a.times(e),c,1),n=n.times(++u),s=o.plus(Xa(a,n,c,1)),Ga(s.d).slice(0,c)===Ga(o.d).slice(0,c)){for(i=d;i--;)o=Za(o.times(o),c,1);if(t==null)if(l<3&&qa(o.d,c-r,p,l))f.precision=c+=10,n=a=s=new f(1),u=0,l++;else return Za(o,f.precision=m,p,Oa=!0);else return f.precision=m,o}o=s}}function co(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?(Oa=!1,u=y):u=t,_.precision=u+=m,n=Ga(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=Ga(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=eo(_,u+2,y).times(a+``),h=co(new _(r+`.`+n.slice(1)),u-m).plus(l),_.precision=y,t==null?Za(h,y,v,Oa=!0):h;for(d=h,c=o=h=Xa(h.minus(1),h.plus(1),u,1),f=Za(h.times(h),u,1),i=3;;){if(o=Za(o.times(f),u,1),l=c.plus(Xa(o,new _(i),u,1)),Ga(l.d).slice(0,u)===Ga(c.d).slice(0,u))if(c=c.times(2),a!==0&&(c=c.plus(eo(_,u+2,y).times(a+``))),c=Xa(c,new _(p),u,1),t==null)if(qa(c.d,u-m,v,s))_.precision=u+=m,l=o=h=Xa(d.minus(1),d.plus(1),u,1),f=Za(h.times(h),u,1),i=s=1;else return Za(c,_.precision=y,v,Oa=!0);else return _.precision=y,c;c=l,i+=2}}function lo(e){return String(e.s*e.s/0)}function uo(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)%Va,n<0&&(r+=Va),r<i){for(r&&e.d.push(+t.slice(0,r)),i-=Va;r<i;)e.d.push(+t.slice(r,r+=Va));t=t.slice(r),r=Va-t.length}else r-=i;for(;r--;)t+=`0`;e.d.push(+t),Oa&&(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 fo(e,t){var n,r,i,a,o,s,c,l,u;if(t.indexOf(`_`)>-1){if(t=t.replace(/(\d)_(?=\d)/g,`$1`),za.test(t))return uo(e,t)}else if(t===`Infinity`||t===`NaN`)return+t||(e.s=NaN),e.e=NaN,e.d=null,e;if(La.test(t))n=16,t=t.toLowerCase();else if(Ia.test(t))n=2;else if(Ra.test(t))n=8;else throw Error(Aa+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=io(r,new r(n),a,a*2)),l=Ja(t,n,Ba),u=l.length-1,a=u;l[a]===0;--a)l.pop();return a<0?new r(e.s*0):(e.e=$a(l,u),e.d=l,Oa=!1,o&&(e=Xa(e,i,s*4)),c&&(e=e.times(Math.abs(c)<54?Fa(2,c):os.pow(2,c))),Oa=!0,e)}function po(e,t){var n,r=t.d.length;if(r<3)return t.isZero()?t:mo(e,2,t,t);n=1.4*Math.sqrt(r),n=n>16?16:n|0,t=t.times(1/ho(5,n)),t=mo(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 mo(e,t,n,r,i){var a,o,s,c,l=1,u=e.precision,d=Math.ceil(u/Va);for(Oa=!1,c=n.times(n),s=new e(r);;){if(o=Xa(s.times(c),new e(t++*t++),u,1),s=i?r.plus(o):r.minus(o),r=Xa(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 Oa=!0,o.d.length=d+1,o}function ho(e,t){for(var n=e;--t;)n*=e;return n}function go(e,t){var n,r=t.s<0,i=to(e,e.precision,1),a=i.times(.5);if(t=t.abs(),t.lte(a))return Da=r?4:1,t;if(n=t.divToInt(i),n.isZero())Da=r?3:2;else{if(t=t.minus(n.times(i)),t.lte(a))return Da=ao(n)?r?2:3:r?4:1,t;Da=ao(n)?r?1:4:r?3:2}return t.minus(i).abs()}function _o(e,t,n,r){var i,a,o,s,c,l,u,d,f,p=e.constructor,m=n!==void 0;if(m?(Ka(n,1,xa),r===void 0?r=p.rounding:Ka(r,0,8)):(n=p.precision,r=p.rounding),!e.isFinite())u=lo(e);else{for(u=Qa(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=Ja(Qa(f),10,i),f.e=f.d.length),d=Ja(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=Xa(e,f,n,r,0,i),d=e.d,a=e.e,l=Ea),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+=Sa.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=Ja(u,i,t),c=d.length;!d[c-1];--c);for(o=1,u=`1.`;o<c;o++)u+=Sa.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 vo(e,t){if(e.length>t)return e.length=t,!0}function yo(e){return new this(e).abs()}function bo(e){return new this(e).acos()}function xo(e){return new this(e).acosh()}function So(e,t){return new this(e).plus(t)}function Co(e){return new this(e).asin()}function wo(e){return new this(e).asinh()}function To(e){return new this(e).atan()}function Eo(e){return new this(e).atanh()}function Do(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=to(this,a,1).times(t.s>0?.25:.75),n.s=e.s):!t.d||e.isZero()?(n=t.s<0?to(this,r,i):new this(0),n.s=e.s):!e.d||t.isZero()?(n=to(this,a,1).times(.5),n.s=e.s):t.s<0?(this.precision=a,this.rounding=1,n=this.atan(Xa(e,t,a,1)),t=to(this,a,1),this.precision=r,this.rounding=i,n=e.s<0?n.minus(t):n.plus(t)):n=this.atan(Xa(e,t,a,1)),n}function Oo(e){return new this(e).cbrt()}function ko(e){return Za(e=new this(e),e.e+1,2)}function Ao(e,t,n){return new this(e).clamp(t,n)}function jo(e){if(!e||typeof e!=`object`)throw Error(ka+`Object expected`);var t,n,r,i=e.defaults===!0,a=[`precision`,1,xa,`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]=Ta[n]),(r=e[n])!==void 0)if(Pa(r)===r&&r>=a[t+1]&&r<=a[t+2])this[n]=r;else throw Error(Aa+n+`: `+r);if(n=`crypto`,i&&(this[n]=Ta[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(Ma);else this[n]=!1;else throw Error(Aa+n+`: `+r);return this}function Mo(e){return new this(e).cos()}function No(e){return new this(e).cosh()}function Po(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,zo(e)){a.s=e.s,Oa?!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++;Oa?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 uo(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),za.test(e)?uo(a,e):fo(a,e);if(r===`bigint`)return e<0?(e=-e,a.s=-1):a.s=1,uo(a,e.toString());throw Error(Aa+e)}if(i.prototype=Y,i.ROUND_UP=0,i.ROUND_DOWN=1,i.ROUND_CEIL=2,i.ROUND_FLOOR=3,i.ROUND_HALF_UP=4,i.ROUND_HALF_DOWN=5,i.ROUND_HALF_EVEN=6,i.ROUND_HALF_CEIL=7,i.ROUND_HALF_FLOOR=8,i.EUCLID=9,i.config=i.set=jo,i.clone=Po,i.isDecimal=zo,i.abs=yo,i.acos=bo,i.acosh=xo,i.add=So,i.asin=Co,i.asinh=wo,i.atan=To,i.atanh=Eo,i.atan2=Do,i.cbrt=Oo,i.ceil=ko,i.clamp=Ao,i.cos=Mo,i.cosh=No,i.div=Fo,i.exp=Io,i.floor=Lo,i.hypot=Ro,i.ln=Bo,i.log=Vo,i.log10=Uo,i.log2=Ho,i.max=Wo,i.min=Go,i.mod=Ko,i.mul=qo,i.pow=Jo,i.random=Yo,i.round=Xo,i.sign=Zo,i.sin=Qo,i.sinh=$o,i.sqrt=es,i.sub=ts,i.sum=ns,i.tan=rs,i.tanh=is,i.trunc=as,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 Fo(e,t){return new this(e).div(t)}function Io(e){return new this(e).exp()}function Lo(e){return Za(e=new this(e),e.e+1,3)}function Ro(){var e,t,n=new this(0);for(Oa=!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 Oa=!0,new this(1/0);n=t}return Oa=!0,n.sqrt()}function zo(e){return e instanceof os||e&&e.toStringTag===Na||!1}function Bo(e){return new this(e).ln()}function Vo(e,t){return new this(e).log(t)}function Ho(e){return new this(e).log(2)}function Uo(e){return new this(e).log(10)}function Wo(){return oo(this,arguments,-1)}function Go(){return oo(this,arguments,1)}function Ko(e,t){return new this(e).mod(t)}function qo(e,t){return new this(e).mul(t)}function Jo(e,t){return new this(e).pow(t)}function Yo(e){var t,n,r,i,a=0,o=new this(1),s=[];if(e===void 0?e=this.precision:Ka(e,1,xa),r=Math.ceil(e/Va),!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(Ma);for(r=s[--a],e%=Va,r&&e&&(i=Fa(10,Va-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-=Va)s.shift();for(r=1,i=s[0];i>=10;i/=10)r++;r<Va&&(n-=Va-r)}return o.e=n,o.d=s,o}function Xo(e){return Za(e=new this(e),e.e+1,this.rounding)}function Zo(e){return e=new this(e),e.d?e.d[0]?e.s:0*e.s:e.s||NaN}function Qo(e){return new this(e).sin()}function $o(e){return new this(e).sinh()}function es(e){return new this(e).sqrt()}function ts(e,t){return new this(e).sub(t)}function ns(){var e=0,t=arguments,n=new this(t[e]);for(Oa=!1;n.s&&++e<t.length;)n=n.plus(t[e]);return Oa=!0,Za(n,this.precision,this.rounding)}function rs(e){return new this(e).tan()}function is(e){return new this(e).tanh()}function as(e){return Za(e=new this(e),e.e+1,1)}Y[Symbol.for(`nodejs.util.inspect.custom`)]=Y.toString,Y[Symbol.toStringTag]=`Decimal`;var os=Y.constructor=Po(Ta);Ca=new os(Ca),wa=new os(wa);var ss=J(`BigNumber`,[`?on`,`config`],e=>{var{on:t,config:n}=e,r=os.clone({precision:n.precision,modulo:os.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}),cs=Math.cosh||function(e){return Math.abs(e)<1e-9?1-e:(Math.exp(e)+Math.exp(-e))*.5},ls=Math.sinh||function(e){return Math.abs(e)<1e-9?e:(Math.exp(e)-Math.exp(-e))*.5},us=e=>{let t=Math.sin(.5*e);return-2*t*t},ds=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))},fs=function(){throw SyntaxError(`Invalid Param`)};function ps(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 ms={re:0,im:0},hs=function(e,t){let n=ms;if(e==null)n.re=n.im=0;else if(t!==void 0)n.re=e,n.im=t;else switch(typeof e){case`object`:if(`im`in e&&`re`in e)n.re=e.re,n.im=e.im;else if(`abs`in e&&`arg`in e){if(!isFinite(e.abs)&&isFinite(e.arg))return X.INFINITY;n.re=e.abs*Math.cos(e.arg),n.im=e.abs*Math.sin(e.arg)}else if(`r`in e&&`phi`in e){if(!isFinite(e.r)&&isFinite(e.phi))return X.INFINITY;n.re=e.r*Math.cos(e.phi),n.im=e.r*Math.sin(e.phi)}else e.length===2?(n.re=e[0],n.im=e[1]):fs();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&&fs();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&&fs(),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))&&fs(),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&&fs();break;case`number`:n.im=0,n.re=e;break;default:fs()}return isNaN(n.re)||isNaN(n.im),n};function X(e,t){if(!(this instanceof X))return new X(e,t);let n=hs(e,t);this.re=n.re,this.im=n.im}X.prototype={re:0,im:0,sign:function(){let e=ds(this.re,this.im);return new X(this.re/e,this.im/e)},add:function(e,t){let n=hs(e,t),r=this.isInfinite(),i=!(isFinite(n.re)&&isFinite(n.im));return r||i?r&&i?X.NAN:X.INFINITY:new X(this.re+n.re,this.im+n.im)},sub:function(e,t){let n=hs(e,t),r=this.isInfinite(),i=!(isFinite(n.re)&&isFinite(n.im));return r||i?r&&i?X.NAN:X.INFINITY:new X(this.re-n.re,this.im-n.im)},mul:function(e,t){let n=hs(e,t),r=this.isInfinite(),i=!(isFinite(n.re)&&isFinite(n.im)),a=this.re===0&&this.im===0,o=n.re===0&&n.im===0;return r&&o||i&&a?X.NAN:r||i?X.INFINITY:n.im===0&&this.im===0?new X(this.re*n.re,0):new X(this.re*n.re-this.im*n.im,this.re*n.im+this.im*n.re)},div:function(e,t){let n=hs(e,t),r=this.isInfinite(),i=!(isFinite(n.re)&&isFinite(n.im)),a=this.re===0&&this.im===0,o=n.re===0&&n.im===0;if(a&&o||r&&i)return X.NAN;if(o||r)return X.INFINITY;if(a||i)return X.ZERO;if(n.im===0)return new X(this.re/n.re,this.im/n.re);if(Math.abs(n.re)<Math.abs(n.im)){let e=n.re/n.im,t=n.re*e+n.im;return new X((this.re*e+this.im)/t,(this.im*e-this.re)/t)}else{let e=n.im/n.re,t=n.im*e+n.re;return new X((this.re+this.im*e)/t,(this.im-this.re*e)/t)}},pow:function(e,t){let n=hs(e,t),r=this.re===0&&this.im===0;if(n.re===0&&n.im===0)return X.ONE;if(n.im===0){if(this.im===0&&this.re>0)return new X(this.re**+n.re,0);if(this.re===0)switch((n.re%4+4)%4){case 0:return new X(this.im**+n.re,0);case 1:return new X(0,this.im**+n.re);case 2:return new X(-(this.im**+n.re),0);case 3:return new X(0,-(this.im**+n.re))}}if(r&&n.re>0)return X.ZERO;let i=Math.atan2(this.im,this.re),a=ps(this.re,this.im),o=Math.exp(n.re*a-n.im*i),s=n.im*a+n.re*i;return new X(o*Math.cos(s),o*Math.sin(s))},sqrt:function(){let e=this.re,t=this.im;if(t===0)return e>=0?new X(Math.sqrt(e),0):new X(0,Math.sqrt(-e));let n=ds(e,t),r=Math.sqrt(.5*(n+Math.abs(e))),i=Math.abs(t)/(2*r);return e>=0?new X(r,t<0?-i:i):new X(i,t<0?-r:r)},exp:function(){let e=Math.exp(this.re);return this.im===0?new X(e,0):new X(e*Math.cos(this.im),e*Math.sin(this.im))},expm1:function(){let e=this.re,t=this.im;return new X(Math.expm1(e)*Math.cos(t)+us(t),Math.exp(e)*Math.sin(t))},log:function(){let e=this.re,t=this.im;return t===0&&e>0?new X(Math.log(e),0):new X(ps(e,t),Math.atan2(t,e))},abs:function(){return ds(this.re,this.im)},arg:function(){return Math.atan2(this.im,this.re)},sin:function(){let e=this.re,t=this.im;return new X(Math.sin(e)*cs(t),Math.cos(e)*ls(t))},cos:function(){let e=this.re,t=this.im;return new X(Math.cos(e)*cs(t),-Math.sin(e)*ls(t))},tan:function(){let e=2*this.re,t=2*this.im,n=Math.cos(e)+cs(t);return new X(Math.sin(e)/n,ls(t)/n)},cot:function(){let e=2*this.re,t=2*this.im,n=Math.cos(e)-cs(t);return new X(-Math.sin(e)/n,ls(t)/n)},sec:function(){let e=this.re,t=this.im,n=.5*cs(2*t)+.5*Math.cos(2*e);return new X(Math.cos(e)*cs(t)/n,Math.sin(e)*ls(t)/n)},csc:function(){let e=this.re,t=this.im,n=.5*cs(2*t)-.5*Math.cos(2*e);return new X(Math.sin(e)*cs(t)/n,-Math.cos(e)*ls(t)/n)},asin:function(){let e=this.re,t=this.im,n=new X(t*t-e*e+1,-2*e*t).sqrt(),r=new X(n.re-t,n.im+e).log();return new X(r.im,-r.re)},acos:function(){let e=this.re,t=this.im,n=new X(t*t-e*e+1,-2*e*t).sqrt(),r=new X(n.re-t,n.im+e).log();return new X(Math.PI/2-r.im,r.re)},atan:function(){let e=this.re,t=this.im;if(e===0){if(t===1)return new X(0,1/0);if(t===-1)return new X(0,-1/0)}let n=e*e+(1-t)*(1-t),r=new X((1-t*t-e*e)/n,-2*e/n).log();return new X(-.5*r.im,.5*r.re)},acot:function(){let e=this.re,t=this.im;if(t===0)return new X(Math.atan2(1,e),0);let n=e*e+t*t;return n===0?new X(e===0?0:e/0,t===0?0:-t/0).atan():new X(e/n,-t/n).atan()},asec:function(){let e=this.re,t=this.im;if(e===0&&t===0)return new X(0,1/0);let n=e*e+t*t;return n===0?new X(e===0?0:e/0,t===0?0:-t/0).acos():new X(e/n,-t/n).acos()},acsc:function(){let e=this.re,t=this.im;if(e===0&&t===0)return new X(Math.PI/2,1/0);let n=e*e+t*t;return n===0?new X(e===0?0:e/0,t===0?0:-t/0).asin():new X(e/n,-t/n).asin()},sinh:function(){let e=this.re,t=this.im;return new X(ls(e)*Math.cos(t),cs(e)*Math.sin(t))},cosh:function(){let e=this.re,t=this.im;return new X(cs(e)*Math.cos(t),ls(e)*Math.sin(t))},tanh:function(){let e=2*this.re,t=2*this.im,n=cs(e)+Math.cos(t);return new X(ls(e)/n,Math.sin(t)/n)},coth:function(){let e=2*this.re,t=2*this.im,n=cs(e)-Math.cos(t);return new X(ls(e)/n,-Math.sin(t)/n)},csch:function(){let e=this.re,t=this.im,n=Math.cos(2*t)-cs(2*e);return new X(-2*ls(e)*Math.cos(t)/n,2*cs(e)*Math.sin(t)/n)},sech:function(){let e=this.re,t=this.im,n=Math.cos(2*t)+cs(2*e);return new X(2*cs(e)*Math.cos(t)/n,-2*ls(e)*Math.sin(t)/n)},asinh:function(){let e=this.re,t=this.im;if(t===0){if(e===0)return new X(0,0);let t=Math.abs(e),n=Math.log(t+Math.sqrt(t*t+1));return new X(e<0?-n:n,0)}let n=new X(e*e-t*t+1,2*e*t).sqrt();return new X(e+n.re,t+n.im).log()},acosh:function(){let e=this.re,t=this.im;if(t===0){if(e>1)return new X(Math.log(e+Math.sqrt(e-1)*Math.sqrt(e+1)),0);if(e<-1){let t=Math.sqrt(e*e-1);return new X(Math.log(-e+t),Math.PI)}return new X(0,Math.acos(e))}let n=new X(e-1,t).sqrt(),r=new X(e+1,t).sqrt();return new X(e+n.re*r.re-n.im*r.im,t+n.re*r.im+n.im*r.re).log()},atanh:function(){let e=this.re,t=this.im;if(t===0){if(e===0)return new X(0,0);if(e===1)return new X(1/0,0);if(e===-1)return new X(-1/0,0);if(-1<e&&e<1)return new X(.5*Math.log((1+e)/(1-e)),0);if(e>1){let t=(e+1)/(e-1);return new X(.5*Math.log(t),-Math.PI/2)}let t=(1+e)/(1-e);return new X(.5*Math.log(-t),Math.PI/2)}let n=1-e,r=1+e,i=n*n+t*t;if(i===0)return new X(e===-1?0:e/0,t===0?0:t/0);let a=(r*n-t*t)/i,o=(t*n+r*t)/i;return new X(ps(a,o)/2,Math.atan2(o,a)/2)},acoth:function(){let e=this.re,t=this.im;if(e===0&&t===0)return new X(0,Math.PI/2);let n=e*e+t*t;return n===0?new X(e===0?0:e/0,t===0?0:-t/0).atanh():new X(e/n,-t/n).atanh()},acsch:function(){let e=this.re,t=this.im;if(t===0){if(e===0)return new X(1/0,0);let t=1/e;return new X(Math.log(t+Math.sqrt(t*t+1)),0)}let n=e*e+t*t;return n===0?new X(e===0?0:e/0,t===0?0:-t/0).asinh():new X(e/n,-t/n).asinh()},asech:function(){let e=this.re,t=this.im;if(this.isZero())return X.INFINITY;let n=e*e+t*t;return n===0?new X(e===0?0:e/0,t===0?0:-t/0).acosh():new X(e/n,-t/n).acosh()},inverse:function(){if(this.isZero())return X.INFINITY;if(this.isInfinite())return X.ZERO;let e=this.re,t=this.im,n=e*e+t*t;return new X(e/n,-t/n)},conjugate:function(){return new X(this.re,-this.im)},neg:function(){return new X(-this.re,-this.im)},ceil:function(e){return e=10**(e||0),new X(Math.ceil(this.re*e)/e,Math.ceil(this.im*e)/e)},floor:function(e){return e=10**(e||0),new X(Math.floor(this.re*e)/e,Math.floor(this.im*e)/e)},round:function(e){return e=10**(e||0),new X(Math.round(this.re*e)/e,Math.round(this.im*e)/e)},equals:function(e,t){let n=hs(e,t);return Math.abs(n.re-this.re)<=X.EPSILON&&Math.abs(n.im-this.im)<=X.EPSILON},clone:function(){return new X(this.re,this.im)},toString:function(){let e=this.re,t=this.im,n=``;return this.isNaN()?`NaN`:this.isInfinite()?`Infinity`:(Math.abs(e)<X.EPSILON&&(e=0),Math.abs(t)<X.EPSILON&&(t=0),t===0?n+e:(e===0?t<0&&(t=-t,n+=`-`):(n+=e,n+=` `,t<0?(t=-t,n+=`-`):n+=`+`,n+=` `),t!==1&&(n+=t),n+`i`))},toVector:function(){return[this.re,this.im]},valueOf:function(){return this.im===0?this.re:null},isNaN:function(){return isNaN(this.re)||isNaN(this.im)},isZero:function(){return this.im===0&&this.re===0},isFinite:function(){return isFinite(this.re)&&isFinite(this.im)},isInfinite:function(){return!this.isFinite()}},X.ZERO=new X(0,0),X.ONE=new X(1,0),X.I=new X(0,1),X.PI=new X(Math.PI,0),X.E=new X(Math.E,0),X.INFINITY=new X(1/0,1/0),X.NAN=new X(NaN,NaN),X.EPSILON=1e-15;var gs=J(`Complex`,[],()=>(Object.defineProperty(X,`name`,{value:`Complex`}),X.prototype.constructor=X,X.prototype.type=`Complex`,X.prototype.isComplex=!0,X.prototype.toJSON=function(){return{mathjs:`Complex`,re:this.re,im:this.im}},X.prototype.toPolar=function(){return{r:this.abs(),phi:this.arg()}},X.prototype.format=function(e){var t=``,n=this.im,r=this.re,i=Ki(this.re,e),a=Ki(this.im,e),o=Er(e)?e:e?e.precision:null;if(o!==null){var s=10**-o;Math.abs(r/n)<s&&(r=0),Math.abs(n/r)<s&&(n=0)}return t=n===0?i:r===0?n===1?`i`:n===-1?`-i`:a+`i`:n<0?n===-1?i+` - i`:i+` - `+a.substring(1)+`i`:n===1?i+` + i`:i+` + `+a+`i`,t},X.fromPolar=function(e){switch(arguments.length){case 1:var t=arguments[0];if(typeof t==`object`)return X(t);throw TypeError(`Input has to be an object with r and phi keys.`);case 2:var n=arguments[0],r=arguments[1];if(Er(n)){if(jr(r)&&r.hasBase(`ANGLE`)&&(r=r.toNumber(`rad`)),Er(r))return new X({r:n,phi:r});throw TypeError(`Phi is not a number nor an angle unit.`)}else throw TypeError(`Radius r is not a number.`);default:throw SyntaxError(`Wrong number of arguments in function fromPolar`)}},X.prototype.valueOf=X.prototype.toString,X.fromJSON=function(e){return new X(e)},X.compare=function(e,t){return e.re>t.re?1:e.re<t.re?-1:e.im>t.im?1:e.im<t.im?-1:0},X),{isClass:!0});typeof BigInt>`u`&&(BigInt=function(e){if(isNaN(e))throw Error(``);return e});var _s=BigInt(0),vs=BigInt(1),ys=BigInt(2),bs=BigInt(3),xs=BigInt(5),Ss=BigInt(10);BigInt(2**53-1);var Cs=2e3,ws={s:vs,n:_s,d:vs};function Ts(e,t){try{e=BigInt(e)}catch{throw Ls()}return e*t}function Es(e){return typeof e==`bigint`?e:Math.floor(e)}function Ds(e,t){if(t===_s)throw Is();let n=Object.create(Fs.prototype);n.s=e<_s?-vs:vs,e=e<_s?-e:e;let r=Ps(e,t);return n.n=e/r,n.d=t/r,n}var Os=[ys*ys,ys,ys*ys,ys,ys*ys,ys*bs,ys,ys*bs];function ks(e){let t=Object.create(null);if(e<=vs)return t[e]=vs,t;let n=e=>{t[e]=(t[e]||_s)+vs};for(;e%ys===_s;)n(ys),e/=ys;for(;e%bs===_s;)n(bs),e/=bs;for(;e%xs===_s;)n(xs),e/=xs;for(let t=0,r=ys+xs;r*r<=e;){for(;e%r===_s;)n(r),e/=r;r+=Os[t],t=t+1&7}return e>vs&&n(e),t}var As=function(e,t){let n=_s,r=vs,i=vs;if(e!=null)if(t!==void 0){if(typeof e==`bigint`)n=e;else if(isNaN(e))throw Ls();else if(e%1!=0)throw Rs();else n=BigInt(e);if(typeof t==`bigint`)r=t;else if(isNaN(t))throw Ls();else if(t%1!=0)throw Rs();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 Ls();i=n*r}else if(typeof e==`number`){if(isNaN(e))throw Ls();if(e<0&&(i=-vs,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=_s,o=_s,s=_s,c=vs,l=vs,u=e.replace(/_/g,``).match(/\d+|./g);if(u===null)throw Ls();if(u[t]===`-`?(i=-vs,t++):u[t]===`+`&&t++,u.length===t+1?o=Ts(u[t++],i):u[t+1]===`.`||u[t]===`.`?(u[t]!==`.`&&(a=Ts(u[t++],i)),t++,(t+1===u.length||u[t+1]===`(`&&u[t+3]===`)`||u[t+1]===`'`&&u[t+3]===`'`)&&(o=Ts(u[t],i),c=Ss**BigInt(u[t].length),t++),(u[t]===`(`&&u[t+2]===`)`||u[t]===`'`&&u[t+2]===`'`)&&(s=Ts(u[t+1],i),l=Ss**BigInt(u[t+1].length)-vs,t+=3)):u[t+1]===`/`||u[t+1]===`:`?(o=Ts(u[t],i),c=Ts(u[t+2],vs),t+=3):u[t+3]===`/`&&u[t+1]===` `&&(a=Ts(u[t],i),o=Ts(u[t+2],i),c=Ts(u[t+4],vs),t+=5),u.length<=t)r=c*l,i=n=s+r*a+l*o;else throw Ls()}else if(typeof e==`bigint`)n=e,i=e,r=vs;else throw Ls();if(r===_s)throw Is();ws.s=i<_s?-vs:vs,ws.n=n<_s?-n:n,ws.d=r<_s?-r:r};function js(e,t,n){let r=vs;for(;t>_s;e=e*e%n,t>>=vs)t&vs&&(r=r*e%n);return r}function Ms(e,t){for(;t%ys===_s;t/=ys);for(;t%xs===_s;t/=xs);if(t===vs)return _s;let n=Ss%t,r=1;for(;n!==vs;r++)if(n=n*Ss%t,r>Cs)return _s;return BigInt(r)}function Ns(e,t,n){let r=vs,i=js(Ss,n,t);for(let e=0;e<300;e++){if(r===i)return BigInt(e);r=r*Ss%t,i=i*Ss%t}return 0}function Ps(e,t){if(!e)return t;if(!t)return e;for(;;){if(e%=t,!e)return t;if(t%=e,!t)return e}}function Fs(e,t){if(As(e,t),this instanceof Fs)e=Ps(ws.d,ws.n),this.s=ws.s,this.n=ws.n/e,this.d=ws.d/e;else return Ds(ws.s*ws.n,ws.d)}var Is=function(){return Error(`Division by Zero`)},Ls=function(){return Error(`Invalid argument`)},Rs=function(){return Error(`Parameters must be integer`)};Fs.prototype={s:vs,n:_s,d:vs,abs:function(){return Ds(this.n,this.d)},neg:function(){return Ds(-this.s*this.n,this.d)},add:function(e,t){return As(e,t),Ds(this.s*this.n*ws.d+ws.s*this.d*ws.n,this.d*ws.d)},sub:function(e,t){return As(e,t),Ds(this.s*this.n*ws.d-ws.s*this.d*ws.n,this.d*ws.d)},mul:function(e,t){return As(e,t),Ds(this.s*ws.s*this.n*ws.n,this.d*ws.d)},div:function(e,t){return As(e,t),Ds(this.s*ws.s*this.n*ws.d,this.d*ws.n)},clone:function(){return Ds(this.s*this.n,this.d)},mod:function(e,t){if(e===void 0)return Ds(this.s*this.n%this.d,vs);if(As(e,t),_s===ws.n*this.d)throw Is();return Ds(this.s*(ws.d*this.n)%(ws.n*this.d),ws.d*this.d)},gcd:function(e,t){return As(e,t),Ds(Ps(ws.n,this.n)*Ps(ws.d,this.d),ws.d*this.d)},lcm:function(e,t){return As(e,t),ws.n===_s&&this.n===_s?Ds(_s,vs):Ds(ws.n*this.n,Ps(ws.n,this.n)*Ps(ws.d,this.d))},inverse:function(){return Ds(this.s*this.d,this.n)},pow:function(e,t){if(As(e,t),ws.d===vs)return ws.s<_s?Ds((this.s*this.d)**ws.n,this.n**ws.n):Ds((this.s*this.n)**ws.n,this.d**ws.n);if(this.s<_s)return null;let n=ks(this.n),r=ks(this.d),i=vs,a=vs;for(let e in n)if(e!==`1`){if(e===`0`){i=_s;break}if(n[e]*=ws.n,n[e]%ws.d===_s)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===_s)r[e]/=ws.d;else return null;a*=BigInt(e)**r[e]}return ws.s<_s?Ds(a,i):Ds(i,a)},log:function(e,t){if(As(e,t),this.s<=_s||ws.s<=_s)return null;let n=Object.create(null),r=ks(ws.n),i=ks(ws.d),a=ks(this.n),o=ks(this.d);for(let e in i)r[e]=(r[e]||_s)-i[e];for(let e in o)a[e]=(a[e]||_s)-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]||_s,n=a[e]||_s;if(t===_s){if(n!==_s)return null;continue}let i=n,o=t,l=Ps(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?Ds(s,c):null},equals:function(e,t){return As(e,t),this.s*this.n*ws.d===ws.s*ws.n*this.d},lt:function(e,t){return As(e,t),this.s*this.n*ws.d<ws.s*ws.n*this.d},lte:function(e,t){return As(e,t),this.s*this.n*ws.d<=ws.s*ws.n*this.d},gt:function(e,t){return As(e,t),this.s*this.n*ws.d>ws.s*ws.n*this.d},gte:function(e,t){return As(e,t),this.s*this.n*ws.d>=ws.s*ws.n*this.d},compare:function(e,t){As(e,t);let n=this.s*this.n*ws.d-ws.s*ws.n*this.d;return(_s<n)-(n<_s)},ceil:function(e){return e=Ss**BigInt(e||0),Ds(Es(this.s*e*this.n/this.d)+(e*this.n%this.d>_s&&this.s>=_s?vs:_s),e)},floor:function(e){return e=Ss**BigInt(e||0),Ds(Es(this.s*e*this.n/this.d)-(e*this.n%this.d>_s&&this.s<_s?vs:_s),e)},round:function(e){return e=Ss**BigInt(e||0),Ds(Es(this.s*e*this.n/this.d)+this.s*((this.s>=_s?vs:_s)+ys*(e*this.n%this.d)>this.d?vs:_s),e)},roundTo:function(e,t){As(e,t);let n=this.n*ws.d,r=this.d*ws.n,i=n%r,a=Es(n/r);return i+i>=r&&a++,Ds(this.s*a*ws.n,ws.d)},divisible:function(e,t){return As(e,t),ws.n===_s?!1:this.n*ws.d%(ws.n*this.d)===_s},valueOf:function(){return Number(this.s*this.n)/Number(this.d)},toString:function(e=15){let t=this.n,n=this.d,r=Ms(t,n),i=Ns(t,n,r),a=this.s<_s?`-`:``;if(a+=Es(t/n),t%=n,t*=Ss,t&&(a+=`.`),r){for(let e=i;e--;)a+=Es(t/n),t%=n,t*=Ss;a+=`(`;for(let e=r;e--;)a+=Es(t/n),t%=n,t*=Ss;a+=`)`}else for(let r=e;t&&r--;)a+=Es(t/n),t%=n,t*=Ss;return a},toFraction:function(e=!1){let t=this.n,n=this.d,r=this.s<_s?`-`:``;if(n===vs)r+=t;else{let i=Es(t/n);e&&i>_s&&(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<_s?`-`:``;if(n===vs)r+=t;else{let i=Es(t/n);e&&i>_s&&(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(Es(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=Ds(r[e-1],vs);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 zs=J(`Fraction`,[],()=>(Object.defineProperty(Fs,`name`,{value:`Fraction`}),Fs.prototype.constructor=Fs,Fs.prototype.type=`Fraction`,Fs.prototype.isFraction=!0,Fs.prototype.toJSON=function(){return{mathjs:`Fraction`,n:String(this.s*this.n),d:String(this.d)}},Fs.fromJSON=function(e){return new Fs(e)},Fs),{isClass:!0}),Bs=J(`Range`,[],()=>{function e(t,n,r){if(!(this instanceof e))throw SyntaxError(`Constructor must be called with the new operator`);var i=t!=null,a=n!=null,o=r!=null;if(i){if(Dr(t))t=t.toNumber();else if(typeof t!=`number`&&!Or(t))throw TypeError(`Parameter start must be a number or bigint`)}if(a){if(Dr(n))n=n.toNumber();else if(typeof n!=`number`&&!Or(n))throw TypeError(`Parameter end must be a number or bigint`)}if(o){if(Dr(r))r=r.toNumber();else if(typeof r!=`number`&&!Or(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&&na(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 zi(n)===zi(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=Ki(this.start,e);return this.step!==1&&(t+=`:`+Ki(this.step,e)),t+=`:`+Ki(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}),Vs=J(`Matrix`,[],()=>{function e(){if(!(this instanceof e))throw SyntaxError(`Constructor must be called with the new operator`)}return e.prototype.type=`Matrix`,e.prototype.isMatrix=!0,e.prototype.storage=function(){throw Error(`Cannot invoke storage on a Matrix interface`)},e.prototype.datatype=function(){throw Error(`Cannot invoke datatype on a Matrix interface`)},e.prototype.create=function(e,t){throw Error(`Cannot invoke create on a Matrix interface`)},e.prototype.subset=function(e,t,n){throw Error(`Cannot invoke subset on a Matrix interface`)},e.prototype.get=function(e){throw Error(`Cannot invoke get on a Matrix interface`)},e.prototype.set=function(e,t,n){throw Error(`Cannot invoke set on a Matrix interface`)},e.prototype.resize=function(e,t){throw Error(`Cannot invoke resize on a Matrix interface`)},e.prototype.reshape=function(e,t){throw Error(`Cannot invoke reshape on a Matrix interface`)},e.prototype.clone=function(){throw Error(`Cannot invoke clone on a Matrix interface`)},e.prototype.size=function(){throw Error(`Cannot invoke size on a Matrix interface`)},e.prototype.map=function(e,t){throw Error(`Cannot invoke map on a Matrix interface`)},e.prototype.forEach=function(e){throw Error(`Cannot invoke forEach on a Matrix interface`)},e.prototype[Symbol.iterator]=function(){throw Error(`Cannot iterate a Matrix interface`)},e.prototype.toArray=function(){throw Error(`Cannot invoke toArray on a Matrix interface`)},e.prototype.valueOf=function(){throw Error(`Cannot invoke valueOf on a Matrix interface`)},e.prototype.format=function(e){throw Error(`Cannot invoke format on a Matrix interface`)},e.prototype.toString=function(){throw Error(`Cannot invoke toString on a Matrix interface`)},e},{isClass:!0});function Hs(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(!Li(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 Us(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}=qi(t);switch(n){case`fixed`:return Ks(e,r);case`exponential`:return Gs(e,r);case`engineering`:return Ws(e,r);case`bin`:return Hs(e,2,i);case`oct`:return Hs(e,8,i);case`hex`:return Hs(e,16,i);case`auto`:var a=qs(t?.lowerExp,-3),o=qs(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():Gs(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 Ws(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 Gs(e,t){return t===void 0?e.toExponential():e.toExponential(t-1)}function Ks(e,t){return e.toFixed(t)}function qs(e,t){return Er(e)?e:Dr(e)?e.toNumber():t}function Js(e,t){var n=e.length-t.length,r=e.length;return e.substring(n,r)===t}function Ys(e,t){var n=Xs(e,t);return t&&typeof t==`object`&&`truncate`in t&&n.length>t.truncate?n.substring(0,t.truncate-3)+`...`:n}function Xs(e,t){return typeof e==`number`?Ki(e,t):Dr(e)?Us(e,t):tc(e)?!t||t.fraction!==`decimal`?`${e.s*e.n}/${e.d}`:e.toString():Array.isArray(e)?ec(e,t):Mr(e)?Zs(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=>Zs(n)+`: `+Ys(e[n],t)).join(`, `)+`}`:String(e)}function Zs(e){for(var t=String(e),n=``,r=0;r<t.length;){var i=t.charAt(r);n+=i in Qs?Qs[i]:i,r++}return`"`+n+`"`}var Qs={'"':`\\"`,"\\":`\\\\`,"\b":`\\b`,"\f":`\\f`,"\n":`\\n`,"\r":`\\r`," ":`\\t`};function $s(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 ec(e,t){if(Array.isArray(e)){for(var n=`[`,r=e.length,i=0;i<r;i++)i!==0&&(n+=`, `),n+=ec(e[i],t);return n+=`]`,n}else return Ys(e,t)}function tc(e){return e&&typeof e==`object`&&typeof e.s==`bigint`&&typeof e.n==`bigint`&&typeof e.d==`bigint`||!1}function nc(e,t){if(!Mr(e))throw TypeError(`Unexpected type of argument in function compareText (expected: string or Array or Matrix, actual: `+gi(e)+`, index: 0)`);if(!Mr(t))throw TypeError(`Unexpected type of argument in function compareText (expected: string or Array or Matrix, actual: `+gi(t)+`, index: 1)`);return e===t?0:e>t?1:-1}function rc(e,t,n){if(!(this instanceof rc))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}rc.prototype=RangeError(),rc.prototype.constructor=RangeError,rc.prototype.name=`DimensionError`,rc.prototype.isDimensionError=!0;function ic(e,t,n){if(!(this instanceof ic))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}ic.prototype=RangeError(),ic.prototype.constructor=RangeError,ic.prototype.name=`IndexError`,ic.prototype.isIndexError=!0;function ac(e){for(var t=[];Array.isArray(e);)t.push(e.length),e=e[0];return t}function oc(e,t,n){var r,i=e.length;if(i!==t[n])throw new rc(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 rc(t.length-1,t.length,`<`);oc(e[r],t,a)}}else for(r=0;r<i;r++)if(Array.isArray(e[r]))throw new rc(t.length+1,t.length,`>`)}function sc(e,t){if(t.length===0){if(Array.isArray(e))throw new rc(e.length,0)}else oc(e,t,0)}function cc(e,t){var n=e.isMatrix?e._size:ac(e);t._sourceSize.forEach((e,t)=>{if(e!==null&&e!==n[t])throw new rc(e,n[t])})}function lc(e,t){if(e!==void 0){if(!Er(e)||!Li(e))throw TypeError(`Index must be an integer (value: `+e+`)`);if(e<0||typeof t==`number`&&e>=t)throw new ic(e,t)}}function uc(e){for(var t=0;t<e._dimensions.length;++t){var n=e._dimensions[t];if(n._data&&Nr(n._data)){if(n._size[0]===0)return!0}else if(n.isRange){if(n.start===n.end)return!0}else if(Mr(n)&&n.length===0)return!0}return!1}function dc(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(!Er(e)||!Li(e)||e<0)throw TypeError(`Invalid size, must contain positive integers (size: `+Ys(t)+`)`)}),(Er(e)||Dr(e))&&(e=[e]),fc(e,t,0,n===void 0?0:n),e}function fc(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),fc(a,t,l,r);for(i=c;i<s;i++)a=[],e[i]=a,fc(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 pc(e,t){var n=xc(e,!0),r=n.length;if(!Array.isArray(e)||!Array.isArray(t))throw TypeError(`Array expected`);if(t.length===0)throw new rc(0,r,`!=`);t=mc(t,r);var i=hc(t);if(r!==i)throw new rc(i,r,`!=`);try{return gc(n,t)}catch(e){throw e instanceof rc?new rc(i,r,`!=`):e}}function mc(e,t){var n=hc(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 hc(e){return e.reduce((e,t)=>e*t,1)}function gc(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 _c(e,t){for(var n=t||ac(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=vc(e,r,0),n.length=r),e}function vc(e,t,n){var r,i;if(n<t){var a=n+1;for(r=0,i=e.length;r<i;r++)e[r]=vc(e[r],t,a)}else for(;Array.isArray(e);)e=e[0];return e}function yc(e,t,n,r){var i=r||ac(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 xc(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 Sc(e,t){return Array.prototype.map.call(e,t)}function Cc(e,t){Array.prototype.forEach.call(e,t)}function wc(e,t){if(ac(e).length!==1)throw Error(`Only one dimensional matrices supported`);return Array.prototype.filter.call(e,t)}function Tc(e,t){if(ac(e).length!==1)throw Error(`Only one dimensional matrices supported`);return Array.prototype.filter.call(e,e=>t.test(e))}function Ec(e,t){return Array.prototype.join.call(e,t)}function Dc(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 Oc(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 kc(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?kc(a,t):t(a);if(n===void 0)n=s;else if(n!==s)return`mixed`}return n}function Ac(e,t,n,r){if(r<n){if(e.length!==t.length)throw new rc(e.length,t.length);for(var i=[],a=0;a<e.length;a++)i[a]=Ac(e[a],t[a],n,r+1);return i}else return e.concat(t)}function jc(){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 Ac(e,n,t,0)},e[0]);throw Error(`Wrong number of arguments in function concat`)}function Mc(){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++)Nc(e[l],r);return r}function Nc(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 Pc(e,t){var n=ac(e);if(xi(n,t))return e;Nc(n,t);var r=Mc(n,t),i=r.length,a=[...Array(i-n.length).fill(1),...n],o=zc(e);n.length<i&&(o=pc(o,a),n=ac(o));for(var s=0;s<i;s++)n[s]<r[s]&&(o=Fc(o,r[s],s),n=ac(o));return o}function Fc(e,t,n){return jc(...Array(t).fill(e),n)}function Ic(e,t){if(!Array.isArray(e))throw Error(`Array expected`);if(!Array.isArray(t))throw Error(`Array expected for index`);var n=ac(e);if(t.length!==n.length)throw new rc(t.length,n.length);for(var r=0;r<t.length;r++)lc(t[r],n[r]);return t.reduce((e,t)=>e[t],e)}function Lc(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 Rc(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 zc(e){return lr([],e)}function Bc(e,t,n,r){if(fa.default.isTypedFunction(e)){var i;if(r)i=1;else{var a=t.isMatrix?t.size():ac(t);if(!a.length||a[a.length-1]===0)return{isUnary:r,fn:e};var o=a.map(()=>0);i=Uc(e,t.isMatrix?t.get(o):Ic(t,o),o,t)}var s;if(t.isMatrix&&t.dataType!==`mixed`&&t.dataType!==void 0){var c=Vc(e,i);s=c===void 0?e:c}else s=e;return i>=1&&i<=3?{isUnary:i===1,fn:function(){return Wc(s,[...arguments].slice(0,i),n,e.name)}}:{isUnary:!1,fn:function(){return Wc(s,[...arguments],n,e.name)}}}return r===void 0?{isUnary:Hc(e),fn:e}:{isUnary:r,fn:e}}function Vc(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 Hc(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 Uc(e,t,n,r){for(var i=[t,n,r],a=3;a>0;a--){var o=i.slice(0,a);if(fa.default.resolve(e,o)!==null)return a}}function Wc(e,t,n,r){try{return e(...t)}catch(e){Gc(e,t,n,r)}}function Gc(e,t,n,r){if(e instanceof TypeError&&e.data?.category===`wrongType`){var i=[];throw i.push(`value: ${gi(t[0])}`),t.length>=2&&i.push(`index: ${gi(t[1])}`),t.length>=3&&i.push(`array: ${gi(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 Kc=J(`DenseMatrix`,[`Matrix`,`config`],e=>{var{Matrix:t,config:n}=e;function r(e,t){if(!(this instanceof r))throw SyntaxError(`Constructor must be called with the new operator`);if(t&&!Mr(t))throw Error(`Invalid datatype: `+t);if(Pr(e))e.type===`DenseMatrix`?(this._data=_i(e._data),this._size=_i(e._size),this._datatype=t||e._datatype):(this._data=e.toArray(),this._size=e.size(),this._datatype=t||e._datatype);else if(e&&Nr(e.data)&&Nr(e.size))this._data=e.data,this._size=e.size,sc(this._data,this._size),this._datatype=t||e.datatype;else if(Nr(e))this._data=u(e),this._size=ac(this._data),sc(this._data,this._size),this._datatype=t;else if(e)throw TypeError(`Unsupported type of data (`+gi(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 kc(this._data,gi)},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 Ic(this._data,e)},r.prototype.set=function(e,t,n){if(!Nr(e))throw TypeError(`Array expected`);if(e.length<this._size.length)throw new rc(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],lc(a,s.length),s=s[a];return a=e[e.length-1],lc(a,s.length),s[a]=t,this};function i(e,t){if(!zr(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 rc(i.length,e._size.length);for(var o=t.min(),s=t.max(),c=0,l=e._size.length;c<l;c++)lc(o[c],e._size[c]),lc(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 Er(e)?t(e):e.map(t).valueOf()}return Er(o)?r[a]=null:r[a]=o.size()[0],a<n?s(o,t=>(lc(t,e.length),i(e[t],a+1))):s(o,t=>(lc(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(Pr(n)?(o=n.size(),n=n.valueOf()):o=ac(n),a){if(o.length!==0)throw TypeError(`Scalar expected`);e.set(t.min(),n,r)}else{if(!xi(o,i)){if(o.length===0)n=Pc([n],i);else try{n=Pc(n,i)}catch{}o=ac(n)}if(i.length<e._size.length)throw new rc(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=yc(n,i.length,u,o)}if(!xi(i,o))throw new rc(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)=>{lc(t,e.length),i(e[t],n[r[0]],a+1)},c=(t,r)=>{lc(t,e.length),e[t]=n[r[0]]};a<r?Er(o)?s(o,[0]):o.forEach(s):Er(o)?c(o,[0]):o.forEach(c)}}r.prototype.resize=function(e,t,n){if(!Fr(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;Nr(r);)r=r[0];return r}return e._size=t.slice(0),e._data=dc(e._data,e._size,n),e}r.prototype.reshape=function(e,t){var n=t?this.clone():this;return n._data=pc(n._data,e),n._size=mc(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:_i(this._data),size:_i(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=Bc(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=Bc(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 _i(this._data)},r.prototype.valueOf=function(){return this._data},r.prototype.format=function(e){return Ys(this._data,e)},r.prototype.toString=function(){return Ys(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(Dr(e)&&(e=e.toNumber()),!Er(e)||!Li(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(!Nr(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(Dr(e)&&(e=e.toNumber()),!Er(e)||!Li(e)||e<1)throw Error(`Size values must be positive integers`);return e}),n){if(Dr(n)&&(n=n.toNumber()),!Er(n)||!Li(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(Nr(t)){if(t.length!==l)throw Error(`Invalid value array length`);u=function(e){return t[e]}}else if(Pr(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||=Dr(u(0))?u(0).mul(0):0;var f=[];if(e.length>0){f=dc(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(!Er(e)||!Li(e)||!Er(t)||!Li(t))throw Error(`Row index must be positive integers`);if(this._size.length!==2)throw Error(`Only two dimensional matrix is supported`);return lc(e,this._size[0]),lc(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 Pr(e)?u(e.valueOf()):Nr(e)?e.map(u):e}return r},{isClass:!0}),qc=`clone`,Jc=J(qc,[`typed`],e=>{var{typed:t}=e;return t(qc,{any:_i})});function Yc(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 Xc(e){for(var t=0;t<e.length;t++)if(Fr(e[t]))return!0;return!1}function Zc(e,t){Pr(e)?e.forEach(e=>t(e),!1,!0):Rc(e,t,!0)}function Qc(e,t,n){if(!n)return Pr(e)?e.map(e=>t(e),!1,!0):Lc(e,t,!0);var r=e=>e===0?e:t(e);return Pr(e)?e.map(e=>r(e),!1,!0):Lc(e,r,!0)}function $c(e,t,n){var r=Array.isArray(e)?ac(e):e.size();if(t<0||t>=r.length)throw new ic(t,r.length);return Pr(e)?e.create(el(e.valueOf(),t,n),e.datatype()):el(e,t,n)}function el(e,t,n){var r,i,a,o;if(t<=0)if(Array.isArray(e[0])){for(o=Yc(e),i=[],r=0;r<o.length;r++)i[r]=el(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]=el(e[r],t-1,n);return i}}function tl(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 nl=`isInteger`,rl=J(nl,[`typed`,`equal`],e=>{var{typed:t,equal:n}=e;return t(nl,{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=>Qc(t,e))})}),il=`number`,al=`number, number`;function ol(e){return Math.abs(e)}ol.signature=il;function sl(e,t){return e+t}sl.signature=al;function cl(e,t){return e-t}cl.signature=al;function ll(e,t){return e*t}ll.signature=al;function ul(e,t){return e/t}ul.signature=al;function dl(e){return-e}dl.signature=il;function fl(e){return e}fl.signature=il;function pl(e){return Ui(e)}pl.signature=il;function ml(e){return e*e*e}ml.signature=il;function hl(e){return Math.exp(e)}hl.signature=il;function gl(e){return Wi(e)}gl.signature=il;function _l(e,t){if(!Li(e)||!Li(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}_l.signature=al;function vl(e,t){if(!Li(e)||!Li(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)}vl.signature=al;function yl(e,t){return t?Math.log(e)/Math.log(t):Math.log(e)}function bl(e){return Vi(e)}bl.signature=il;function xl(e){return Bi(e)}xl.signature=il;function Sl(e){return Hi(e)}Sl.signature=il;function Cl(e,t){return t===0?e:e-t*Math.floor(e/t)}Cl.signature=al;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 Tl(e){return zi(e)}Tl.signature=il;function El(e){return Math.sqrt(e)}El.signature=il;function Dl(e){return e*e}Dl.signature=il;function Ol(e,t){var n,r,i,a=0,o=1,s=1,c=0;if(!Li(e)||!Li(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]}Ol.signature=al;function kl(e,t){return e*e<1&&t===1/0||e*e>1&&t===-1/0?0:e**+t}kl.signature=al;function Al(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0;if(!Li(t)||t<0||t>15)throw Error(`Number of decimals in function round must be an integer from 0 to 15 inclusive`);return parseFloat(Xi(e,t))}function jl(e){return Math.abs(e)}jl.signature=il;var Ml=`number`,Nl=`number, number`;function Pl(e,t){if(!Li(e)||!Li(t))throw Error(`Integers expected in function bitAnd`);return e&t}Pl.signature=Nl;function Fl(e){if(!Li(e))throw Error(`Integer expected in function bitNot`);return~e}Fl.signature=Ml;function Il(e,t){if(!Li(e)||!Li(t))throw Error(`Integers expected in function bitOr`);return e|t}Il.signature=Nl;function Ll(e,t){if(!Li(e)||!Li(t))throw Error(`Integers expected in function bitXor`);return e^t}Ll.signature=Nl;function Rl(e,t){if(!Li(e)||!Li(t))throw Error(`Integers expected in function leftShift`);return e<<t}Rl.signature=Nl;function zl(e,t){if(!Li(e)||!Li(t))throw Error(`Integers expected in function rightArithShift`);return e>>t}zl.signature=Nl;function Bl(e,t){if(!Li(e)||!Li(t))throw Error(`Integers expected in function rightLogShift`);return e>>>t}Bl.signature=Nl;function Vl(e,t){if(t<e)return 1;if(t===e)return t;var n=t+e>>1;return Vl(e,n)*Vl(n+1,t)}function Hl(e,t){if(!Li(e)||e<0||!Li(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/=Vl(a,o)),r}Hl.signature=`number, number`;var Ul=Math.PI,Wl=2*Math.PI,Gl=Math.E,Kl=1.618033988749895,ql=`number`,Jl=`number, number`;function Yl(e){return!e}Yl.signature=ql;function Xl(e,t){return!!(e||t)}Xl.signature=Jl;function Zl(e,t){return!!e!=!!t}Zl.signature=Jl;function Ql(e,t){return!!(e&&t)}Ql.signature=Jl;function $l(e){var t;if(Li(e))return e<=0?Number.isFinite(e)?1/0:NaN:e>171?1/0:Vl(1,e-1);if(e<.5)return Math.PI/(Math.sin(Math.PI*e)*$l(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=tu[0];for(var o=1;o<tu.length;++o)t+=tu[o]/(e+o);var s=e+eu+.5;return Math.sqrt(2*Math.PI)*s**+(e+.5)*Math.exp(-s)*t}$l.signature=`number`;var eu=4.7421875,tu=[.9999999999999971,57.15623566586292,-59.59796035547549,14.136097974741746,-.4919138160976202,3399464998481189e-20,4652362892704858e-20,-9837447530487956e-20,.0001580887032249125,-.00021026444172410488,.00021743961811521265,-.0001643181065367639,8441822398385275e-20,-26190838401581408e-21,36899182659531625e-22],nu=.9189385332046728,ru=[1.000000000190015,76.18009172947146,-86.50532032941678,24.01409824083091,-1.231739572450155,.001208650973866179,-5395239384953e-18];function iu(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))-iu(1-e);--e;for(var t=e+5+.5,n=ru[0],r=6;r>=1;r--)n+=ru[r]/(e+r);return nu+(e+.5)*Math.log(t)-t+Math.log(n)}iu.signature=`number`;var au=`number`,ou=`number, number`;function su(e){return Math.acos(e)}su.signature=au;function cu(e){return ra(e)}cu.signature=au;function lu(e){return Math.atan(1/e)}lu.signature=au;function uu(e){return Number.isFinite(e)?(Math.log((e+1)/e)+Math.log(e/(e-1)))/2:0}uu.signature=au;function du(e){return Math.asin(1/e)}du.signature=au;function fu(e){var t=1/e;return Math.log(t+Math.sqrt(t*t+1))}fu.signature=au;function pu(e){return Math.acos(1/e)}pu.signature=au;function mu(e){var t=1/e,n=Math.sqrt(t*t-1);return Math.log(n+t)}mu.signature=au;function hu(e){return Math.asin(e)}hu.signature=au;function gu(e){return ia(e)}gu.signature=au;function _u(e){return Math.atan(e)}_u.signature=au;function vu(e,t){return Math.atan2(e,t)}vu.signature=ou;function yu(e){return aa(e)}yu.signature=au;function bu(e){return Math.cos(e)}bu.signature=au;function xu(e){return oa(e)}xu.signature=au;function Su(e){return 1/Math.tan(e)}Su.signature=au;function Cu(e){var t=Math.exp(2*e);return(t+1)/(t-1)}Cu.signature=au;function wu(e){return 1/Math.sin(e)}wu.signature=au;function Tu(e){return e===0?1/0:Math.abs(2/(Math.exp(e)-Math.exp(-e)))*zi(e)}Tu.signature=au;function Eu(e){return 1/Math.cos(e)}Eu.signature=au;function Du(e){return 2/(Math.exp(e)+Math.exp(-e))}Du.signature=au;function Ou(e){return Math.sin(e)}Ou.signature=au;function ku(e){return sa(e)}ku.signature=au;function Au(e){return Math.tan(e)}Au.signature=au;function ju(e){return ca(e)}ju.signature=au;var Mu=`number`;function Nu(e){return Li(e)}Nu.signature=Mu;function Pu(e){return e<0}Pu.signature=Mu;function Fu(e){return e>0}Fu.signature=Mu;function Iu(e){return e===0}Iu.signature=Mu;function Lu(e){return Number.isNaN(e)}Lu.signature=Mu;function Ru(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 zu=`isNegative`,Bu=J(zu,[`typed`,`config`],e=>{var{typed:t,config:n}=e;return t(zu,{number:e=>na(e,0,n.relTol,n.absTol)?!1:Pu(e),BigNumber:e=>Ru(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=>Qc(t,e))})}),Vu=`isNumeric`,Hu=J(Vu,[`typed`],e=>{var{typed:t}=e;return t(Vu,{"number | BigNumber | bigint | Fraction | boolean":()=>!0,"Complex | Unit | string | null | undefined | Node":()=>!1,"Array | Matrix":t.referToSelf(e=>t=>Qc(t,e))})}),Uu=`hasNumericValue`,Wu=J(Uu,[`typed`,`isNumeric`],e=>{var{typed:t,isNumeric:n}=e;return t(Uu,{boolean:()=>!0,string:function(e){return e.trim().length>0&&!isNaN(Number(e))},any:function(e){return n(e)}})}),Gu=`isPositive`,Ku=J(Gu,[`typed`,`config`],e=>{var{typed:t,config:n}=e;return t(Gu,{number:e=>na(e,0,n.relTol,n.absTol)?!1:Fu(e),BigNumber:e=>Ru(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=>Qc(t,e))})}),qu=`isZero`,Ju=J(qu,[`typed`,`equalScalar`],e=>{var{typed:t,equalScalar:n}=e;return t(qu,{"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=>Qc(t,e))})}),Yu=`isNaN`,Xu=J(Yu,[`typed`],e=>{var{typed:t}=e;return t(Yu,{number:Lu,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=>Qc(t,e))})}),Zu=`isBounded`,Qu=J(Zu,[`typed`],e=>{var{typed:t}=e;return t(Zu,{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))))})}),$u=`isFinite`,ed=J($u,[`typed`,`isBounded`,`map`],e=>{var{typed:t,isBounded:n,map:r}=e;return t($u,{"Array | Matrix":e=>r(e,n),any:e=>n(e)})}),td=`typeOf`,nd=J(td,[`typed`],e=>{var{typed:t}=e;return t(td,{any:gi})});function rd(e,t,n,r){return na(e.re,t.re,n,r)&&na(e.im,t.im,n,r)}var id=J(`compareUnits`,[`typed`],e=>{var{typed:t}=e;return{"Unit, Unit":t.referToSelf(e=>(n,r)=>{if(!n.equalBase(r))throw Error(`Cannot compare units with different base`);return t.find(e,[n.valueType(),r.valueType()])(n.value,r.value)})}}),ad=`equalScalar`,od=J(ad,[`typed`,`config`],e=>{var{typed:t,config:n}=e;return t(ad,{"boolean, boolean":function(e,t){return e===t},"number, number":function(e,t){return na(e,t,n.relTol,n.absTol)},"BigNumber, BigNumber":function(e,t){return e.eq(t)||Ru(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 rd(e,t,n.relTol,n.absTol)}},id({typed:t}))});J(ad,[`typed`,`config`],e=>{var{typed:t,config:n}=e;return t(ad,{"number, number":function(e,t){return na(e,t,n.relTol,n.absTol)}})});var sd=J(`SparseMatrix`,[`typed`,`equalScalar`,`Matrix`],e=>{var{typed:t,equalScalar:n,Matrix:r}=e;function i(e,t){if(!(this instanceof i))throw SyntaxError(`Constructor must be called with the new operator`);if(t&&!Mr(t))throw Error(`Invalid datatype: `+t);if(Pr(e))a(this,e,t);else if(e&&Nr(e.index)&&Nr(e.ptr)&&Nr(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(Nr(e))o(this,e,t);else if(e)throw TypeError(`Unsupported type of data (`+gi(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?_i(t._values):void 0,e._index=_i(t._index),e._ptr=_i(t._ptr),e._size=_i(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(Mr(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(Nr(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 kc(this._values,gi)},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(!zr(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 rc(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++)lc(c[r],e._size[r]),lc(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(Pr(n)?(o=n.size(),n=n.toArray()):o=ac(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 rc(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=yc(n,i.length,c,o)}if(!xi(i,o))throw new rc(i,o,`>`);if(i.length===1)d(t.dimension(0),(t,i)=>{lc(t),e.set([t,0],n[i[0]],r)});else{var l=t.dimension(0),u=t.dimension(1);d(l,(t,i)=>{lc(t),d(u,(a,o)=>{lc(a),e.set([t,a],n[i[0]][o[0]],r)})})}}return e;function d(e,t){Er(e)?t(e,[0]):e.forEach(t)}}i.prototype.get=function(e){if(!Nr(e))throw TypeError(`Array expected`);if(e.length!==this._size.length)throw new rc(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];lc(t,this._size[0]),lc(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(!Nr(e))throw TypeError(`Array expected`);if(e.length!==this._size.length)throw new rc(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;Mr(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]),lc(a,s),lc(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(!Fr(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(!Er(e)||!Li(e)||e<0)throw TypeError(`Invalid size, must contain positive integers (size: `+Ys(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;Mr(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(!Nr(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(!Er(t)||!Li(t)||t<=-2||t===0)throw TypeError(`Invalid size, must contain positive integers or -1 (size: `+Ys(e)+`)`)});var n=this._size[0]*this._size[1];if(e=mc(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?_i(this._values):void 0,index:_i(this._index),ptr:_i(this._ptr),size:_i(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=Bc(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;Mr(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=Bc(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?_i(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 [`+Ys(t,e)+` x `+Ys(n,e)+`] density: `+Ys(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
  (`+Ys(l,e)+`, `+Ys(a,e)+`) ==> `+(this._values?Ys(this._values[c],e):`X`)}return i},i.prototype.toString=function(){return Ys(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(Dr(e)&&(e=e.toNumber()),!Er(e)||!Li(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(!Nr(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(Dr(e)&&(e=e.toNumber()),!Er(e)||!Li(e)||e<1)throw Error(`Size values must be positive integers`);return e}),a){if(Dr(a)&&(a=a.toNumber()),!Er(a)||!Li(a))throw TypeError(`The parameter k must be an integer number`)}else a=0;var c=n,l=0;Mr(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(Nr(r)){if(r.length!==m)throw Error(`Invalid value array length`);h=function(e){return r[e]}}else if(Pr(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(!Er(e)||!Li(e)||!Er(t)||!Li(t))throw Error(`Row index must be positive integers`);if(this._size.length!==2)throw Error(`Only two dimensional matrix is supported`);return lc(e,this._size[0]),lc(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}),cd=`number`,ld=[`typed`];function ud(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 dd(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 fd=J(cd,ld,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=ud(e);if(t)return dd(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=>Qc(t,e))});return n.fromJSON=function(e){return parseFloat(e.value)},n}),pd=J(`bigint`,[`typed`],e=>{var{typed:t}=e,n=t(`bigint`,{"":function(){return 0n},bigint:function(e){return e},number:function(e){return BigInt(e.toFixed())},BigNumber:function(e){return BigInt(e.round().toString())},Fraction:function(e){return BigInt(e.valueOf().toFixed())},"string | boolean":function(e){return BigInt(e)},null:function(e){return 0n},"Array | Matrix":t.referToSelf(e=>t=>Qc(t,e))});return n.fromJSON=function(e){return BigInt(e.value)},n}),md=`string`,hd=J(md,[`typed`],e=>{var{typed:t}=e;return t(md,{"":function(){return``},number:Ki,null:function(e){return`null`},boolean:function(e){return e+``},string:function(e){return e},"Array | Matrix":t.referToSelf(e=>t=>Qc(t,e)),any:function(e){return String(e)}})}),gd=`boolean`,_d=J(gd,[`typed`],e=>{var{typed:t}=e;return t(gd,{"":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=>Qc(t,e))})}),vd=J(`bignumber`,[`typed`,`BigNumber`],e=>{var{typed:t,BigNumber:n}=e;return t(`bignumber`,{"":function(){return new n(0)},number:function(e){return new n(e+``)},string:function(e){var t=e.match(/(0[box][0-9a-fA-F]*)i([0-9]*)/);if(t){var r=t[2],i=n(t[1]),a=new n(2).pow(Number(r));if(i.gt(a.sub(1)))throw SyntaxError(`String "${e}" is out of range`);var o=new n(2).pow(Number(r)-1);return i.gte(o)?i.sub(a):i}return new n(e)},BigNumber:function(e){return e},bigint:function(e){return new n(e.toString())},Unit:t.referToSelf(e=>t=>{var n=t.clone();return n.value=e(t.value),n}),Fraction:function(e){return new n(String(e.n)).div(String(e.d)).times(String(e.s))},null:function(e){return new n(0)},"Array | Matrix":t.referToSelf(e=>t=>Qc(t,e))})}),yd=J(`complex`,[`typed`,`Complex`],e=>{var{typed:t,Complex:n}=e;return t(`complex`,{"":function(){return n.ZERO},number:function(e){return new n(e,0)},"number, number":function(e,t){return new n(e,t)},"BigNumber, BigNumber":function(e,t){return new n(e.toNumber(),t.toNumber())},Fraction:function(e){return new n(e.valueOf(),0)},Complex:function(e){return e.clone()},string:function(e){return n(e)},null:function(e){return n(0)},Object:function(e){if(`re`in e&&`im`in e)return new n(e.re,e.im);if(`r`in e&&`phi`in e||`abs`in e&&`arg`in e)return new n(e);throw Error(`Expected object with properties (re and im) or (r and phi) or (abs and arg)`)},"Array | Matrix":t.referToSelf(e=>t=>Qc(t,e))})}),bd=J(`fraction`,[`typed`,`Fraction`],e=>{var{typed:t,Fraction:n}=e;return t(`fraction`,{number:function(e){if(!Number.isFinite(e)||isNaN(e))throw Error(e+` cannot be represented as a fraction`);return new n(e)},string:function(e){return new n(e)},"number, number":function(e,t){return new n(e,t)},"bigint, bigint":function(e,t){return new n(e,t)},null:function(e){return new n(0)},BigNumber:function(e){return new n(e.toString())},bigint:function(e){return new n(e.toString())},Fraction:function(e){return e},Unit:t.referToSelf(e=>t=>{var n=t.clone();return n.value=e(t.value),n}),Object:function(e){return new n(e)},"Array | Matrix":t.referToSelf(e=>t=>Qc(t,e))})}),xd=`matrix`,Sd=J(xd,[`typed`,`Matrix`,`DenseMatrix`,`SparseMatrix`],e=>{var{typed:t,Matrix:n,DenseMatrix:r,SparseMatrix:i}=e;return t(xd,{"":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)+`.`)}}),Cd=`matrixFromFunction`,wd=J(Cd,[`typed`,`matrix`,`isZero`],e=>{var{typed:t,matrix:n,isZero:r}=e;return t(Cd,{"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}}),Td=`matrixFromRows`,Ed=J(Td,[`typed`,`matrix`,`flatten`,`size`],e=>{var{typed:t,matrix:n,flatten:r,size:i}=e;return t(Td,{"...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.`)}}),Dd=`matrixFromColumns`,Od=J(Dd,[`typed`,`matrix`,`flatten`,`size`],e=>{var{typed:t,matrix:n,flatten:r,size:i}=e;return t(Dd,{"...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.`)}}),kd=`splitUnit`,Ad=J(kd,[`typed`],e=>{var{typed:t}=e;return t(kd,{"Unit, Array":function(e,t){return e.splitUnit(t)}})}),jd=`unaryMinus`,Md=J(jd,[`typed`],e=>{var{typed:t}=e;return t(jd,{number:dl,"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=>Qc(t,e,!0))})}),Nd=`unaryPlus`,Pd=J(Nd,[`typed`,`config`,`numeric`],e=>{var{typed:t,config:n,numeric:r}=e;return t(Nd,{number:fl,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=>Qc(t,e,!0)),boolean:function(e){return r(+!!e,n.number)},string:function(e){return r(e,Ri(e,n))}})}),Fd=`abs`,Id=J(Fd,[`typed`],e=>{var{typed:t}=e;return t(Fd,{number:ol,"Complex | BigNumber | Fraction | Unit":e=>e.abs(),bigint:e=>e<0n?-e:e,"Array | Matrix":t.referToSelf(e=>t=>Qc(t,e,!0))})}),Ld=`mapSlices`,Rd=J(Ld,[`typed`,`isInteger`],e=>{var{typed:t,isInteger:n}=e;return t(Ld,{"Array | Matrix, number | BigNumber, function":function(e,t,r){if(!n(t))throw TypeError(`Integer number expected for dimension`);var i=Array.isArray(e)?ac(e):e.size();if(t<0||t>=i.length)throw new ic(t,i.length);return Pr(e)?e.create(zd(e.valueOf(),t,r),e.datatype()):zd(e,t,r)}})},{formerly:`apply`});function zd(e,t,n){var r,i,a;if(t<=0)if(Array.isArray(e[0])){for(a=Bd(e),i=[],r=0;r<a.length;r++)i[r]=zd(a[r],t-1,n);return i}else return n(e);else{for(i=[],r=0;r<e.length;r++)i[r]=zd(e[r],t-1,n);return i}}function Bd(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 Vd=`addScalar`,Hd=J(Vd,[`typed`],e=>{var{typed:t}=e;return t(Vd,{"number, number":sl,"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})})}),Ud=`subtractScalar`,Wd=J(Ud,[`typed`],e=>{var{typed:t}=e;return t(Ud,{"number, number":cl,"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})})}),Gd=`cbrt`,Kd=J(Gd,[`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(Gd,{number:pl,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(pl(i),0).mul(new o(0,r).exp());if(n){var c=[s,new o(pl(i),0).mul(new o(0,r+Math.PI*2/3).exp()),new o(pl(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&&kr(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=Dr(e.value)?new s(1).div(3):Ar(e.value)?new c(1,3):1/3,o=e.pow(a);return n&&(o.value=i(o.value)),o}}}),qd=J(`matAlgo11xS0s`,[`typed`,`equalScalar`],e=>{var{typed:t,equalScalar:n}=e;return function(e,r,i,a){var o=e._values,s=e._index,c=e._ptr,l=e._size,u=e._datatype;if(!o)throw Error(`Cannot perform operation on Pattern Sparse Matrix and Scalar value`);var d=l[0],f=l[1],p,m=n,h=0,g=i;typeof u==`string`&&(p=u,m=t.find(n,[p,p]),h=t.convert(0,p),r=t.convert(r,p),g=t.find(i,[p,p]));for(var _=[],v=[],y=[],b=0;b<f;b++){y[b]=v.length;for(var x=c[b],S=c[b+1],C=x;C<S;C++){var w=s[C],T=a?g(r,o[C]):g(o[C],r);m(T,h)||(v.push(w),_.push(T))}}return y[f]=v.length,e.createSparseMatrix({values:_,index:v,ptr:y,size:[d,f],datatype:p})}}),Jd=J(`matAlgo12xSfs`,[`typed`,`DenseMatrix`],e=>{var{typed:t,DenseMatrix:n}=e;return function(e,r,i,a){var o=e._values,s=e._index,c=e._ptr,l=e._size,u=e._datatype;if(!o)throw Error(`Cannot perform operation on Pattern Sparse Matrix and Scalar value`);var d=l[0],f=l[1],p,m=i;typeof u==`string`&&(p=u,r=t.convert(r,p),m=t.find(i,[p,p]));for(var h=[],g=[],_=[],v=0;v<f;v++){for(var y=v+1,b=c[v],x=c[v+1],S=b;S<x;S++){var C=s[S];g[C]=o[S],_[C]=y}for(var w=0;w<d;w++)v===0&&(h[w]=[]),_[w]===y?h[w][v]=a?m(r,g[w]):m(g[w],r):h[w][v]=a?m(r,0):m(0,r)}return new n({data:h,size:[d,f],datatype:p})}}),Yd=J(`matAlgo14xDs`,[`typed`],e=>{var{typed:t}=e;return function(e,r,i,a){var o=e._data,s=e._size,c=e._datatype,l,u=i;typeof c==`string`&&(l=c,r=t.convert(r,l),u=t.find(i,[l,l]));var d=s.length>0?n(u,0,s,s[0],o,r,a):[];return e.createDenseMatrix({data:d,size:_i(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}}),Xd=`ceil`,Zd=[`typed`,`config`,`round`,`matrix`,`equalScalar`,`zeros`,`DenseMatrix`],Qd=new os(10),$d=J(Xd,[`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:na(e,i,n.relTol,n.absTol)&&!na(e,t,n.relTol,n.absTol)?i:t}return t(Xd,{number:i,"number, number":function(e,t){if(!Li(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}})}),ef=J(Xd,Zd,e=>{var{typed:t,config:n,round:r,matrix:i,equalScalar:a,zeros:o,DenseMatrix:s}=e,c=qd({typed:t,equalScalar:a}),l=Jd({typed:t,DenseMatrix:s}),u=Yd({typed:t}),d=$d({typed:t,config:n,round:r});function f(e){var t=(e,t)=>Ru(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=Qd.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)=>Qc(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=>Qc(t,e,!0)),"Array, number | BigNumber":t.referToSelf(e=>(t,n)=>Qc(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))})}),tf=`cube`,nf=J(tf,[`typed`],e=>{var{typed:t}=e;return t(tf,{number:ml,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)}})}),rf=`exp`,af=J(rf,[`typed`],e=>{var{typed:t}=e;return t(rf,{number:hl,Complex:function(e){return e.exp()},BigNumber:function(e){return e.exp()}})}),of=`expm1`,sf=J(of,[`typed`,`Complex`],e=>{var{typed:t,Complex:n}=e;return t(of,{number:gl,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)}})}),cf=`fix`,lf=[`typed`,`Complex`,`matrix`,`ceil`,`floor`,`equalScalar`,`zeros`,`DenseMatrix`],uf=J(cf,[`typed`,`ceil`,`floor`],e=>{var{typed:t,ceil:n,floor:r}=e;return t(cf,{number:function(e){return e>0?r(e):n(e)},"number, number":function(e,t){return e>0?r(e,t):n(e,t)}})}),df=J(cf,lf,e=>{var{typed:t,Complex:n,matrix:r,ceil:i,floor:a,equalScalar:o,zeros:s,DenseMatrix:c}=e,l=Jd({typed:t,DenseMatrix:c}),u=Yd({typed:t}),d=uf({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)=>Qc(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=>Qc(t,e,!0)),"Array | Matrix, number | BigNumber":t.referToSelf(e=>(t,n)=>Qc(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))})}),ff=`floor`,pf=[`typed`,`config`,`round`,`matrix`,`equalScalar`,`zeros`,`DenseMatrix`],mf=new os(10),hf=J(ff,[`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:na(e,i,n.relTol,n.absTol)&&!na(e,t,n.relTol,n.absTol)?i:t}return t(ff,{number:i,"number, number":function(e,t){if(!Li(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}})}),gf=J(ff,pf,e=>{var{typed:t,config:n,round:r,matrix:i,equalScalar:a,zeros:o,DenseMatrix:s}=e,c=qd({typed:t,equalScalar:a}),l=Jd({typed:t,DenseMatrix:s}),u=Yd({typed:t}),d=hf({typed:t,config:n,round:r});function f(e){var t=(e,t)=>Ru(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=mf.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)=>Qc(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=>Qc(t,e,!0)),"Array, number | BigNumber":t.referToSelf(e=>(t,n)=>Qc(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))})}),_f=J(`matAlgo02xDS0`,[`typed`,`equalScalar`],e=>{var{typed:t,equalScalar:n}=e;return function(e,r,i,a){var o=e._data,s=e._size,c=e._datatype||e.getDataType(),l=r._values,u=r._index,d=r._ptr,f=r._size,p=r._datatype||r._data===void 0?r._datatype:r.getDataType();if(s.length!==f.length)throw new rc(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})}}),vf=J(`matAlgo03xDSf`,[`typed`],e=>{var{typed:t}=e;return function(e,n,r,i){var a=e._data,o=e._size,s=e._datatype||e.getDataType(),c=n._values,l=n._index,u=n._ptr,d=n._size,f=n._datatype||n._data===void 0?n._datatype:n.getDataType();if(o.length!==d.length)throw new rc(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})}}),yf=J(`matAlgo05xSfSf`,[`typed`,`equalScalar`],e=>{var{typed:t,equalScalar:n}=e;return function(e,r,i){var a=e._values,o=e._index,s=e._ptr,c=e._size,l=e._datatype||e._data===void 0?e._datatype:e.getDataType(),u=r._values,d=r._index,f=r._ptr,p=r._size,m=r._datatype||r._data===void 0?r._datatype:r.getDataType();if(c.length!==p.length)throw new rc(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=J(`matAlgo13xDD`,[`typed`],e=>{var{typed:t}=e;return function(e,r,i){var a=e._data,o=e._size,s=e._datatype,c=r._data,l=r._size,u=r._datatype,d=[];if(o.length!==l.length)throw new rc(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 xf(e,t){if(xi(e.size(),t.size()))return[e,t];var n=Mc(e.size(),t.size());return[e,t].map(e=>Sf(e,n))}function Sf(e,t){return xi(e.size(),t)?e:e.create(Pc(e.valueOf(),t),e.datatype())}var Cf=J(`matrixAlgorithmSuite`,[`typed`,`matrix`],e=>{var{typed:t,matrix:n}=e,r=bf({typed:t}),i=Yd({typed:t});return function(e){var a=e.elop,o=e.SD||e.DS,s;a?(s={"DenseMatrix, DenseMatrix":(e,t)=>r(...xf(e,t),a),"Array, Array":(e,t)=>r(...xf(n(e),n(t)),a).valueOf(),"Array, DenseMatrix":(e,t)=>r(...xf(n(e),t),a),"DenseMatrix, Array":(e,t)=>r(...xf(e,n(t)),a)},e.SS&&(s[`SparseMatrix, SparseMatrix`]=(t,n)=>e.SS(...xf(t,n),a,!1)),e.DS&&(s[`DenseMatrix, SparseMatrix`]=(t,n)=>e.DS(...xf(t,n),a,!1),s[`Array, SparseMatrix`]=(t,r)=>e.DS(...xf(n(t),r),a,!1)),o&&(s[`SparseMatrix, DenseMatrix`]=(e,t)=>o(...xf(t,e),a,!0),s[`SparseMatrix, Array`]=(e,t)=>o(...xf(n(t),e),a,!0))):(s={"DenseMatrix, DenseMatrix":t.referToSelf(e=>(t,n)=>r(...xf(t,n),e)),"Array, Array":t.referToSelf(e=>(t,i)=>r(...xf(n(t),n(i)),e).valueOf()),"Array, DenseMatrix":t.referToSelf(e=>(t,i)=>r(...xf(n(t),i),e)),"DenseMatrix, Array":t.referToSelf(e=>(t,i)=>r(...xf(t,n(i)),e))},e.SS&&(s[`SparseMatrix, SparseMatrix`]=t.referToSelf(t=>(n,r)=>e.SS(...xf(n,r),t,!1))),e.DS&&(s[`DenseMatrix, SparseMatrix`]=t.referToSelf(t=>(n,r)=>e.DS(...xf(n,r),t,!1)),s[`Array, SparseMatrix`]=t.referToSelf(t=>(r,i)=>e.DS(...xf(n(r),i),t,!1))),o&&(s[`SparseMatrix, DenseMatrix`]=t.referToSelf(e=>(t,n)=>o(...xf(n,t),e,!0)),s[`SparseMatrix, Array`]=t.referToSelf(e=>(t,r)=>o(...xf(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&&yi(s,a.signatures),s}}),wf=`mod`,Tf=J(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=gf({typed:t,config:n,round:r,matrix:i,equalScalar:a,zeros:o,DenseMatrix:s}),u=_f({typed:t,equalScalar:a}),d=vf({typed:t}),f=yf({typed:t,equalScalar:a}),p=qd({typed:t,equalScalar:a}),m=Jd({typed:t,DenseMatrix:s}),h=Cf({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)}}),Ef=J(`matAlgo01xDSid`,[`typed`],e=>{var{typed:t}=e;return function(e,n,r,i){var a=e._data,o=e._size,s=e._datatype||e.getDataType(),c=n._values,l=n._index,u=n._ptr,d=n._size,f=n._datatype||n._data===void 0?n._datatype:n.getDataType();if(o.length!==d.length)throw new rc(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})}}),Df=J(`matAlgo04xSidSid`,[`typed`,`equalScalar`],e=>{var{typed:t,equalScalar:n}=e;return function(e,r,i){var a=e._values,o=e._index,s=e._ptr,c=e._size,l=e._datatype||e._data===void 0?e._datatype:e.getDataType(),u=r._values,d=r._index,f=r._ptr,p=r._size,m=r._datatype||r._data===void 0?r._datatype:r.getDataType();if(c.length!==p.length)throw new rc(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})}}),Of=J(`matAlgo10xSids`,[`typed`,`DenseMatrix`],e=>{var{typed:t,DenseMatrix:n}=e;return function(e,r,i,a){var o=e._values,s=e._index,c=e._ptr,l=e._size,u=e._datatype;if(!o)throw Error(`Cannot perform operation on Pattern Sparse Matrix and Scalar value`);var d=l[0],f=l[1],p,m=i;typeof u==`string`&&(p=u,r=t.convert(r,p),m=t.find(i,[p,p]));for(var h=[],g=[],_=[],v=0;v<f;v++){for(var y=v+1,b=c[v],x=c[v+1],S=b;S<x;S++){var C=s[S];g[C]=o[S],_[C]=y}for(var w=0;w<d;w++)v===0&&(h[w]=[]),_[w]===y?h[w][v]=a?m(r,g[w]):m(g[w],r):h[w][v]=r}return new n({data:h,size:[d,f],datatype:p})}});function kf(e,t,n,r){if(!(this instanceof kf))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}kf.prototype=Error(),kf.prototype.constructor=Error,kf.prototype.name=`ArgumentsError`,kf.prototype.isArgumentsError=!0;var Af=`gcd`,jf=[`typed`,`config`,`round`,`matrix`,`equalScalar`,`zeros`,`BigNumber`,`DenseMatrix`,`concat`],Mf=`number | BigNumber | Fraction | Matrix | Array`,Nf=`${Mf}, ${Mf}, ...${Mf}`;function Pf(e){return!e.some(e=>Array.isArray(e))}var Ff=J(Af,jf,e=>{var{typed:t,matrix:n,config:r,round:i,equalScalar:a,zeros:o,BigNumber:s,DenseMatrix:c,concat:l}=e,u=Tf({typed:t,config:r,round:i,matrix:n,equalScalar:a,zeros:o,DenseMatrix:c,concat:l}),d=Ef({typed:t}),f=Df({typed:t,equalScalar:a}),p=Of({typed:t,DenseMatrix:c}),m=Cf({typed:t,matrix:n,concat:l});return t(Af,{"number, number":h,"BigNumber, BigNumber":g,"Fraction, Fraction":(e,t)=>e.gcd(t)},m({SS:f,DS:d,Ss:p}),{[Nf]: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])&&Pf(t[0]))return e(...t[0]);if(Pf(t))return e(...t);throw new kf(`gcd() supports only 1d matrices!`)}),Matrix:t.referToSelf(e=>t=>e(t.toArray()))});function h(e,t){if(!Li(e)||!Li(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}}),If=J(`matAlgo06xS0S0`,[`typed`,`equalScalar`],e=>{var{typed:t,equalScalar:n}=e;return function(e,r,i){var a=e._values,o=e._size,s=e._datatype||e._data===void 0?e._datatype:e.getDataType(),c=r._values,l=r._size,u=r._datatype||r._data===void 0?r._datatype:r.getDataType();if(o.length!==l.length)throw new rc(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(tl(e,C,x,b,S,w,v,g),tl(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})}}),Lf=`lcm`,Rf=J(Lf,[`typed`,`matrix`,`equalScalar`,`concat`],e=>{var{typed:t,matrix:n,equalScalar:r,concat:i}=e,a=_f({typed:t,equalScalar:r}),o=If({typed:t,equalScalar:r}),s=qd({typed:t,equalScalar:r}),c=Cf({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(Lf,{"number, number":vl,"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 zf(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 Bf=`log10`,Vf=[`typed`,`config`,`Complex`],Hf=bl(16),Uf=J(Bf,Vf,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(Bf,{number:function(e){return e>=0||n.predictable?bl(e):a(e)},bigint:zf(Hf,bl,n,a),Complex:i,BigNumber:function(e){return!e.isNegative()||n.predictable?e.log():a(e.toNumber())},"Array | Matrix":t.referToSelf(e=>t=>Qc(t,e))})}),Wf=`log2`,Gf=J(Wf,[`typed`,`config`,`Complex`],e=>{var{typed:t,config:n,Complex:r}=e;function i(e){return a(new r(e,0))}return t(Wf,{number:function(e){return e>=0||n.predictable?xl(e):i(e)},bigint:zf(4,xl,n,i),Complex:a,BigNumber:function(e){return!e.isNegative()||n.predictable?e.log(2):i(e.toNumber())},"Array | Matrix":t.referToSelf(e=>t=>Qc(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)}}),Kf=J(`multiplyScalar`,[`typed`],e=>{var{typed:t}=e;return t(`multiplyScalar`,{"number, number":ll,"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)})}),qf=`multiply`,Jf=J(qf,[`typed`,`matrix`,`addScalar`,`multiplyScalar`,`equalScalar`,`dot`],e=>{var{typed:t,matrix:n,addScalar:r,multiplyScalar:i,equalScalar:a,dot:o}=e,s=qd({typed:t,equalScalar:a}),c=Yd({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(qf,i,{"Array, Array":t.referTo(`Matrix, Matrix`,e=>(t,r)=>{l(ac(t),ac(r));var i=e(n(t),n(r));return Pr(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})})}),Yf=`nthRoot`,Xf=J(Yf,[`typed`,`matrix`,`equalScalar`,`BigNumber`,`concat`],e=>{var{typed:t,matrix:n,equalScalar:r,BigNumber:i,concat:a}=e,o=Ef({typed:t}),s=_f({typed:t,equalScalar:r}),c=If({typed:t,equalScalar:r}),l=qd({typed:t,equalScalar:r}),u=Cf({typed:t,matrix:n,concat:a});function d(){throw Error(`Complex number not supported in function nthRoot. Use nthRoots instead.`)}return t(Yf,{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))}}),Zf=`sign`,Qf=J(Zf,[`typed`,`BigNumber`,`Fraction`,`complex`],e=>{var{typed:t,BigNumber:n,complex:r,Fraction:i}=e;return t(Zf,{number:Tl,Complex:function(e){return e.im===0?r(Tl(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=>Qc(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)})})}),$f=J(`sqrt`,[`config`,`typed`,`Complex`],e=>{var{config:t,typed:n,Complex:r}=e;return n(`sqrt`,{number:i,Complex:function(e){return e.sqrt()},BigNumber:function(e){return!e.isNegative()||t.predictable?e.sqrt():i(e.toNumber())},Unit:function(e){return e.pow(.5)}});function i(e){return isNaN(e)?NaN:e>=0||t.predictable?Math.sqrt(e):new r(e,0).sqrt()}}),ep=`square`,tp=J(ep,[`typed`],e=>{var{typed:t}=e;return t(ep,{number:Dl,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)}})}),np=`subtract`,rp=J(np,[`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=Ef({typed:t}),l=vf({typed:t}),u=yf({typed:t,equalScalar:r}),d=Of({typed:t,DenseMatrix:o}),f=Jd({typed:t,DenseMatrix:o}),p=Cf({typed:t,matrix:n,concat:s});return t(np,{"any, any":i},p({elop:i,SS:u,DS:c,SD:l,Ss:f,sS:d}))}),ip=`xgcd`,ap=J(ip,[`typed`,`config`,`matrix`,`BigNumber`],e=>{var{typed:t,config:n,matrix:r,BigNumber:i}=e;return t(ip,{"number, number":function(e,t){var i=Ol(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)}}),op=`invmod`,sp=J(op,[`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(op,{"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}}),cp=J(`matAlgo09xS0Sf`,[`typed`,`equalScalar`],e=>{var{typed:t,equalScalar:n}=e;return function(e,r,i){var a=e._values,o=e._index,s=e._ptr,c=e._size,l=e._datatype||e._data===void 0?e._datatype:e.getDataType(),u=r._values,d=r._index,f=r._ptr,p=r._size,m=r._datatype||r._data===void 0?r._datatype:r.getDataType();if(c.length!==p.length)throw new rc(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})}}),lp=`dotMultiply`,up=J(lp,[`typed`,`matrix`,`equalScalar`,`multiplyScalar`,`concat`],e=>{var{typed:t,matrix:n,equalScalar:r,multiplyScalar:i,concat:a}=e,o=_f({typed:t,equalScalar:r}),s=cp({typed:t,equalScalar:r}),c=qd({typed:t,equalScalar:r});return t(lp,Cf({typed:t,matrix:n,concat:a})({elop:i,SS:s,DS:o,Ss:c}))});function dp(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 mp(e,t,function(e,t){return e&t})}function fp(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 pp(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:mp(e,t,function(e,t){return e|t})}function mp(e,t,n){var r=e.constructor,i,a,o=+(e.s<0),s=+(t.s<0);if(o){i=hp(fp(e));for(var c=0;c<i.length;++c)i[c]^=1}else i=hp(e);if(s){a=hp(fp(t));for(var l=0;l<a.length;++l)a[l]^=1}else a=hp(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 hp(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 gp(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)?fp(t):t.eq(r)?fp(e):!e.isFinite()||!t.isFinite()?!e.isFinite()&&!t.isFinite()?r:new n(e.isNegative()===t.isNegative()?1/0:-1/0):mp(e,t,function(e,t){return e^t})}function _p(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 vp(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 yp=`bitAnd`,bp=J(yp,[`typed`,`matrix`,`equalScalar`,`concat`],e=>{var{typed:t,matrix:n,equalScalar:r,concat:i}=e,a=_f({typed:t,equalScalar:r}),o=If({typed:t,equalScalar:r}),s=qd({typed:t,equalScalar:r}),c=Cf({typed:t,matrix:n,concat:i});return t(yp,{"number, number":Pl,"BigNumber, BigNumber":dp,"bigint, bigint":(e,t)=>e&t},c({SS:o,DS:a,Ss:s}))}),xp=`bitNot`,Sp=J(xp,[`typed`],e=>{var{typed:t}=e;return t(xp,{number:Fl,BigNumber:fp,bigint:e=>~e,"Array | Matrix":t.referToSelf(e=>t=>Qc(t,e))})}),Cp=`bitOr`,wp=J(Cp,[`typed`,`matrix`,`equalScalar`,`DenseMatrix`,`concat`],e=>{var{typed:t,matrix:n,equalScalar:r,DenseMatrix:i,concat:a}=e,o=Ef({typed:t}),s=Df({typed:t,equalScalar:r}),c=Of({typed:t,DenseMatrix:i}),l=Cf({typed:t,matrix:n,concat:a});return t(Cp,{"number, number":Il,"BigNumber, BigNumber":pp,"bigint, bigint":(e,t)=>e|t},l({SS:s,DS:o,Ss:c}))}),Tp=J(`matAlgo07xSSf`,[`typed`,`SparseMatrix`],e=>{var{typed:t,SparseMatrix:n}=e;return function(e,i,a){var o=e._size,s=e._datatype||e._data===void 0?e._datatype:e.getDataType(),c=i._size,l=i._datatype||i._data===void 0?i._datatype:i.getDataType();if(o.length!==c.length)throw new rc(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]}}}),Ep=`bitXor`,Dp=J(Ep,[`typed`,`matrix`,`DenseMatrix`,`concat`,`SparseMatrix`],e=>{var{typed:t,matrix:n,DenseMatrix:r,concat:i,SparseMatrix:a}=e,o=vf({typed:t}),s=Tp({typed:t,SparseMatrix:a}),c=Jd({typed:t,DenseMatrix:r}),l=Cf({typed:t,matrix:n,concat:i});return t(Ep,{"number, number":Ll,"BigNumber, BigNumber":gp,"bigint, bigint":(e,t)=>e^t},l({SS:s,DS:o,Ss:c}))}),Op=`arg`,kp=J(Op,[`typed`],e=>{var{typed:t}=e;return t(Op,{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=>Qc(t,e))})}),Ap=`conj`,jp=J(Ap,[`typed`],e=>{var{typed:t}=e;return t(Ap,{"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=>Qc(t,e))})}),Mp=`im`,Np=J(Mp,[`typed`],e=>{var{typed:t}=e;return t(Mp,{number:()=>0,"BigNumber | Fraction":e=>e.mul(0),Complex:e=>e.im,"Array | Matrix":t.referToSelf(e=>t=>Qc(t,e))})}),Pp=`re`,Fp=J(Pp,[`typed`],e=>{var{typed:t}=e;return t(Pp,{"number | BigNumber | Fraction":e=>e,Complex:e=>e.re,"Array | Matrix":t.referToSelf(e=>t=>Qc(t,e))})}),Ip=`not`,Lp=J(Ip,[`typed`],e=>{var{typed:t}=e;return t(Ip,{"null | undefined":()=>!0,number:Yl,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=>Qc(t,e))})}),Rp=`nullish`,zp=J(Rp,[`typed`,`matrix`,`size`,`flatten`,`deepEqual`],e=>{var{typed:t,matrix:n,size:r,flatten:i,deepEqual:a}=e,o=vf({typed:t}),s=Yd({typed:t}),c=bf({typed:t});return t(Rp,{"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 rc(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())})}),Bp=`or`,Vp=J(Bp,[`typed`,`matrix`,`equalScalar`,`DenseMatrix`,`concat`],e=>{var{typed:t,matrix:n,equalScalar:r,DenseMatrix:i,concat:a}=e,o=vf({typed:t}),s=yf({typed:t,equalScalar:r}),c=Jd({typed:t,DenseMatrix:i}),l=Cf({typed:t,matrix:n,concat:a});return t(Bp,{"number, number":Xl,"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":Xl,"Unit, Unit":t.referToSelf(e=>(t,n)=>e(t.value||0,n.value||0))},l({SS:s,DS:o,Ss:c}))}),Hp=`xor`,Up=J(Hp,[`typed`,`matrix`,`DenseMatrix`,`concat`,`SparseMatrix`],e=>{var{typed:t,matrix:n,DenseMatrix:r,concat:i,SparseMatrix:a}=e,o=vf({typed:t}),s=Tp({typed:t,SparseMatrix:a}),c=Jd({typed:t,DenseMatrix:r}),l=Cf({typed:t,matrix:n,concat:i});return t(Hp,{"number, number":Zl,"Complex, Complex":function(e,t){return(e.re!==0||e.im!==0)!=(t.re!==0||t.im!==0)},"bigint, bigint":Zl,"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}))}),Wp=`concat`,Gp=J(Wp,[`typed`,`matrix`,`isInteger`],e=>{var{typed:t,matrix:n,isInteger:r}=e;return t(Wp,{"...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(Pr(l)&&(s=!0),Er(l)||Dr(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 ic(a,o+1)}else{var u=_i(l).valueOf(),d=ac(u);if(c[t]=u,o=a,a=d.length-1,t>0&&a!==o)throw new rc(o+1,a+1)}}if(c.length===0)throw SyntaxError(`At least one matrix expected`);for(var f=c.shift();c.length;)f=jc(f,c.shift(),a);return s?n(f):f},"...string":function(e){return e.join(``)}})}),Kp=`column`,qp=J(Kp,[`typed`,`Index`,`matrix`,`range`],e=>{var{typed:t,Index:n,matrix:r,range:i}=e;return t(Kp,{"Matrix, number":a,"Array, number":function(e,t){return a(r(_i(e)),t).valueOf()}});function a(e,t){if(e.size().length!==2)throw Error(`Only two dimensional matrix is supported`);lc(t,e.size()[1]);var a=new n(i(0,e.size()[0]),[t]),o=e.subset(a);return Pr(o)?o:r([[o]])}}),Jp=`count`,Yp=J(Jp,[`typed`,`size`,`prod`],e=>{var{typed:t,size:n,prod:r}=e;return t(Jp,{string:function(e){return e.length},"Matrix | Array":function(e){return r(n(e))}})}),Xp=`cross`,Zp=J(Xp,[`typed`,`matrix`,`subtract`,`multiply`],e=>{var{typed:t,matrix:n,subtract:r,multiply:i}=e;return t(Xp,{"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(ac(e).length,ac(t).length);e=_c(e),t=_c(t);var a=ac(e),o=ac(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}}),Qp=`diag`,$p=J(Qp,[`typed`,`matrix`,`DenseMatrix`,`SparseMatrix`],e=>{var{typed:t,matrix:n,DenseMatrix:r,SparseMatrix:i}=e;return t(Qp,{Array:function(e){return a(e,0,ac(e),null)},"Array, number":function(e,t){return a(e,t,ac(e),null)},"Array, BigNumber":function(e,t){return a(e,t.toNumber(),ac(e),null)},"Array, string":function(e,t){return a(e,0,ac(e),t)},"Array, number, string":function(e,t,n){return a(e,t,ac(e),n)},"Array, BigNumber, string":function(e,t,n){return a(e,t.toNumber(),ac(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(!Li(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(Pr(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)}}),em=J(`filter`,[`typed`],e=>{var{typed:t}=e;return t(`filter`,{"Array, function":tm,"Matrix, function":function(e,t){return e.create(tm(e.valueOf(),t),e.datatype())},"Array, RegExp":Tc,"Matrix, RegExp":function(e,t){return e.create(Tc(e.valueOf(),t),e.datatype())}})});function tm(e,t){var n=Bc(t,e,`filter`);return n.isUnary?wc(e,n.fn):wc(e,function(e,t,r){return n.fn(e,[t],r)})}var nm=`flatten`,rm=J(nm,[`typed`],e=>{var{typed:t}=e;return t(nm,{Array:function(e){return xc(e)},DenseMatrix:function(e){return e.create(xc(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())`)}})}),im=`forEach`,am=J(im,[`typed`],e=>{var{typed:t}=e;return t(im,{"Array, function":om,"Matrix, function":function(e,t){e.forEach(t)}})});function om(e,t){var n=Bc(t,e,im);Rc(e,n.fn,n.isUnary)}var sm=`getMatrixDataType`,cm=J(sm,[`typed`],e=>{var{typed:t}=e;return t(sm,{Array:function(e){return kc(e,gi)},Matrix:function(e){return e.getDataType()}})}),lm=`identity`,um=J(lm,[`typed`,`config`,`matrix`,`BigNumber`,`DenseMatrix`,`SparseMatrix`],e=>{var{typed:t,config:n,matrix:r,BigNumber:i,DenseMatrix:a,SparseMatrix:o}=e;return t(lm,{"":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=Dr(e)||Dr(t)?i:null;if(Dr(e)&&(e=e.toNumber()),Dr(t)&&(t=t.toNumber()),!Li(e)||e<1||!Li(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=dc([],l,c),d=e<t?e:t,f=0;f<d;f++)u[f][f]=s;return u}}),dm=`kron`,fm=J(dm,[`typed`,`matrix`,`multiplyScalar`],e=>{var{typed:t,matrix:n,multiplyScalar:r}=e;return t(dm,{"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=ac(e).length,o=ac(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)))}}),pm=`map`,mm=J(pm,[`typed`],e=>{var{typed:t}=e;return t(pm,{"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():ac(e)),u=Mc(...l),d=e.length,f=c?(e,t)=>e.get(t):Ic,p=e.map((e,t)=>{var n=l[t].map(()=>0);return e.isMatrix?e.get(n):Ic(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(Pc(t.toArray(),u),t.datatype()):e[0].create(Pc(t.valueOf(),u))):e.map(e=>e.isMatrix?Pc(e.toArray(),u):Pc(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():ac(e)),a=Mc(...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=Bc(t,e,pm);return Lc(e,n.fn,n.isUnary)}}),hm=`diff`,gm=J(hm,[`typed`,`matrix`,`subtract`,`number`],e=>{var{typed:t,matrix:n,subtract:r,number:i}=e;return t(hm,{"Array | Matrix":function(e){return Pr(e)?n(o(e.toArray())):o(e)},"Array | Matrix, number":function(e,t){if(!Li(t))throw RangeError(`Dimension must be a whole number`);return Pr(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(Pr(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){Pr(e)&&(e=e.toArray()),Pr(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}}),_m=J(`ones`,[`typed`,`config`,`matrix`,`BigNumber`],e=>{var{typed:t,config:n,matrix:r,BigNumber:i}=e;return t(`ones`,{"":function(){return n.matrix===`Array`?a([]):a([],`default`)},"...number | BigNumber | string":function(e){return typeof e[e.length-1]==`string`?a(e,e.pop()):n.matrix===`Array`?a(e):a(e,`default`)},Array:a,Matrix:function(e){var t=e.storage();return a(e.valueOf(),t)},"Array | Matrix, string":function(e,t){return a(e.valueOf(),t)}});function a(e,t){var n=o(e)?new i(1):1;if(s(e),t){var a=r(t);return e.length>0?a.resize(e,n):a}else{var c=[];return e.length>0?dc(c,e,n):c}}function o(e){var t=!1;return e.forEach(function(e,n,r){Dr(e)&&(t=!0,r[n]=e.toNumber())}),t}function s(e){e.forEach(function(e){if(typeof e!=`number`||!Li(e)||e<0)throw Error(`Parameters in function ones must be positive integers`)})}});function vm(){throw Error(`No "bignumber" implementation available`)}function ym(){throw Error(`No "fraction" implementation available`)}function bm(){throw Error(`No "matrix" implementation available`)}var xm=`range`,Sm=J(xm,[`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(xm,{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&&vm(),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}}}),Cm=`reshape`,wm=J(Cm,[`typed`,`isInteger`,`matrix`],e=>{var{typed:t,isInteger:n}=e;return t(Cm,{"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)}),pc(e,t)}})}),Tm=J(`resize`,[`config`,`matrix`],e=>{var{config:t,matrix:n}=e;return function(e,i,a){if(arguments.length!==2&&arguments.length!==3)throw new kf(`resize`,arguments.length,2,3);if(Pr(i)&&(i=i.valueOf()),Dr(i[0])&&(i=i.map(function(e){return Dr(e)?e.toNumber():e})),Pr(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 _i(e)}else{Array.isArray(e)||(e=[e]),e=_i(e);var s=dc(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 rc(t.length,1);var r=t[0];if(typeof r!=`number`||!Li(r))throw TypeError(`Invalid size, must contain positive integers (size: `+Ys(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}}),Em=`rotate`,Dm=J(Em,[`typed`,`multiply`,`rotationMatrix`],e=>{var{typed:t,multiply:n,rotationMatrix:r}=e;return t(Em,{"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)?ac(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}`)}}),Om=`rotationMatrix`,km=J(Om,[`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(Om,{"":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=Dr(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=Dr(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)}}),Am=`row`,jm=J(Am,[`typed`,`Index`,`matrix`,`range`],e=>{var{typed:t,Index:n,matrix:r,range:i}=e;return t(Am,{"Matrix, number":a,"Array, number":function(e,t){return a(r(_i(e)),t).valueOf()}});function a(e,t){if(e.size().length!==2)throw Error(`Only two dimensional matrix is supported`);lc(t,e.size()[0]);var a=i(0,e.size()[1]),o=new n([t],a),s=e.subset(o);return Pr(s)?s:r([[s]])}}),Mm=`size`,Nm=J(Mm,[`typed`],e=>{var{typed:t}=e;return t(Mm,{Matrix:e=>e.size(),Array:ac,string:e=>[e.length],"number | Complex | BigNumber | Unit | boolean | null":e=>[]})}),Pm=`squeeze`,Fm=J(Pm,[`typed`],e=>{var{typed:t}=e;return t(Pm,{Array:function(e){return _c(_i(e))},Matrix:function(e){var t=_c(e.toArray());return Array.isArray(t)?e.create(t,e.datatype()):t},any:function(e){return _i(e)}})}),Im=`subset`,Lm=J(Im,[`typed`,`matrix`,`zeros`,`add`],e=>{var{typed:t,matrix:n,zeros:r,add:i}=e;return t(Im,{"Matrix, Index":function(e,t){return uc(t)?n():(cc(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":Bm,"string, Index":Rm,"Matrix, Index, any, any":function(e,t,n,r){return uc(t)?e:(cc(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":zm,"string, Index, string, string":zm,"Object, Index, any":Vm});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 Rm(e,t){if(!zr(t))throw TypeError(`Index expected`);if(uc(t))return``;if(cc(Array.from(e),t),t.size().length!==1)throw new rc(t.size().length,1);var n=e.length;lc(t.min()[0],n),lc(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 zm(e,t,n,r){if(!t||t.isIndex!==!0)throw TypeError(`Index expected`);if(uc(t))return e;if(cc(Array.from(e),t),t.size().length!==1)throw new rc(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 rc(i.size()[0],n.length);var a=e.length;lc(t.min()[0]),lc(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 Bm(e,t){if(!uc(t)){if(t.size().length!==1)throw new rc(t.size(),1);var n=t.dimension(0);if(typeof n!=`string`)throw TypeError(`String expected as index to retrieve an object property`);return dr(e,n)}}function Vm(e,t,n){if(uc(t))return e;if(t.size().length!==1)throw new rc(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=_i(e);return fr(i,r,n),i}var Hm=`transpose`,Um=J(Hm,[`typed`,`matrix`],e=>{var{typed:t,matrix:n}=e;return t(Hm,{Array:e=>r(n(e)).valueOf(),Matrix:r,any:_i});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: `+Ys(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: `+Ys(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]=_i(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]=_i(r[v]))}return e.createSparseMatrix({values:o,index:s,ptr:c,size:[n,t],datatype:e._datatype})}}),Wm=`ctranspose`,Gm=J(Wm,[`typed`,`transpose`,`conj`],e=>{var{typed:t,transpose:n,conj:r}=e;return t(Wm,{any:function(e){return r(n(e))}})}),Km=`zeros`,qm=J(Km,[`typed`,`config`,`matrix`,`BigNumber`],e=>{var{typed:t,config:n,matrix:r,BigNumber:i}=e;return t(Km,{"":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?dc(c,e,n):c}}function o(e){var t=!1;return e.forEach(function(e,n,r){Dr(e)&&(t=!0,r[n]=e.toNumber())}),t}function s(e){e.forEach(function(e){if(typeof e!=`number`||!Li(e)||e<0)throw Error(`Parameters in function zeros must be positive integers`)})}}),Jm=`fft`,Ym=J(Jm,[`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(Jm,{Array:m,Matrix:function(e){return e.create(m(e.valueOf()),e.datatype())}});function m(e){var t=ac(e);return t.length===1?_(e,t[0]):h(e.map(e=>m(e,t.slice(1))),0)}function h(e,t){var n=ac(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=ac(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)}}),Xm=`ifft`,Zm=J(Xm,[`typed`,`fft`,`dotDivide`,`conj`],e=>{var{typed:t,fft:n,dotDivide:r,conj:i}=e;return t(Xm,{"Array | Matrix":function(e){var t=Pr(e)?e.size():ac(e);return r(i(n(i(e))),t.reduce((e,t)=>e*t,1))}})});function Qm(e){"@babel/helpers - typeof";return Qm=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},Qm(e)}function $m(e,t){if(Qm(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(Qm(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function eh(e){var t=$m(e,`string`);return Qm(t)==`symbol`?t:t+``}function th(e,t,n){return(t=eh(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function nh(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 rh(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?nh(Object(n),!0).forEach(function(t){th(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):nh(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}var ih=J(`solveODE`,[`typed`,`add`,`subtract`,`multiply`,`divide`,`max`,`map`,`abs`,`isPositive`,`isNegative`,`larger`,`smaller`,`matrix`,`bignumber`,`unaryMinus`],e=>{var{typed:t,add:n,subtract:r,multiply:i,divide:a,max:o,map:s,abs:c,isPositive:l,isNegative:u,larger:d,smaller:f,matrix:p,bignumber:m,unaryMinus:h}=e;function g(e){return function(t,p,g,_){if(!(p.length===2&&(p.every(S)||p.every(jr))))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(jr)))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(Dr),[P,F,I,L]=N?[m(e.a),m(e.c),m(e.b),m(e.bp)]:[e.a,e.c,e.b,e.bp],R=w?C?w:h(w):a(r(y,v),O),z=[v],B=[g],V=r(I,L),ee=0,te=0,H=b(C),ne=x(C);H(z[ee],y);){var re=[];R=ne(z[ee],y,R),re.push(t(z[ee],B[ee]));for(var ie=1;ie<F.length;++ie)re.push(t(n(z[ee],i(F[ie],R)),n(B[ee],i(R,P[ie],re))));var U=o(c(s(i(V,re),e=>jr(e)?e.value:e)));U<k&&k/U>1/4&&(z.push(n(z[ee],R)),B.push(n(B[ee],i(R,I,re))),ee++);var ae=.84*(k/U)**(1/5);if(f(ae,A)?ae=A:d(ae,j)&&(ae=j),ae=N?m(ae):ae,R=i(R,ae),T&&d(c(R),T)?R=C?T:h(T):E&&f(c(R),E)&&(R=C?E:h(E)),te++,te>M)throw Error(`Maximum number of iterations reached, try changing options`)}return{t:z,y:B}}}function _(e,t,n,r){return g({a:[[],[1/2],[0,3/4],[2/9,1/3,4/9]],c:[null,1/2,3/4,1],b:[2/9,1/3,4/9,0],bp:[7/24,1/4,1/3,1/8]})(e,t,n,r)}function v(e,t,n,r){return g({a:[[],[1/5],[3/40,9/40],[44/45,-56/15,32/9],[19372/6561,-25360/2187,64448/6561,-212/729],[9017/3168,-355/33,46732/5247,49/176,-5103/18656],[35/384,0,500/1113,125/192,-2187/6784,11/84]],c:[null,1/5,3/10,4/5,8/9,1,1],b:[35/384,0,500/1113,125/192,-2187/6784,11/84,0],bp:[5179/57600,0,7571/16695,393/640,-92097/339200,187/2100,1/40]})(e,t,n,r)}function y(e,t,n,r){var i=r.method?r.method:`RK45`,a={RK23:_,RK45:v};if(i.toUpperCase()in a){var o=rh({},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 Dr(e)||Er(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]))}}})}),ah=J(`erf`,[`typed`],e=>{var{typed:t}=e;return t(`name`,{number:function(e){var t=Math.abs(e);return t>=uh?zi(e):t<=oh?zi(e)*n(t):t<=4?zi(e)*(1-r(t)):zi(e)*(1-i(t))},"Array | Matrix":t.referToSelf(e=>t=>Qc(t,e))});function n(e){var t=e*e,n=ch[0][4]*t,r=t,i;for(i=0;i<3;i+=1)n=(n+ch[0][i])*t,r=(r+lh[0][i])*t;return e*(n+ch[0][3])/(r+lh[0][3])}function r(e){var t=ch[1][8]*e,n=e,r;for(r=0;r<7;r+=1)t=(t+ch[1][r])*e,n=(n+lh[1][r])*e;var i=(t+ch[1][7])/(n+lh[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=ch[2][5]*t,r=t,i;for(i=0;i<4;i+=1)n=(n+ch[2][i])*t,r=(r+lh[2][i])*t;var a=t*(n+ch[2][4])/(r+lh[2][4]);a=(sh-a)/e,t=parseInt(e*16)/16;var o=(e-t)*(e+t);return Math.exp(-t*t)*Math.exp(-o)*a}}),oh=.46875,sh=.5641895835477563,ch=[[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]],lh=[[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]],uh=2**53,dh=`zeta`,fh=J(dh,[`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(dh,{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)}}),ph=`mode`,mh=J(ph,[`typed`,`isNaN`,`isNumeric`],e=>{var{typed:t,isNaN:n,isNumeric:r}=e;return t(ph,{"Array | Matrix":i,"...":function(e){return i(e)}});function i(e){if(e=xc(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 hh(e,t,n){var r;return String(e).includes(`Unexpected type`)?(r=arguments.length>2?` (type: `+gi(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: `+gi(n)+`, value: `+JSON.stringify(n)+`)`:``,TypeError(`Cannot calculate `+t+`, no ordering relation is defined for complex numbers`+r)):e}var gh=`prod`,_h=J(gh,[`typed`,`config`,`multiplyScalar`,`numeric`],e=>{var{typed:t,config:n,multiplyScalar:r,numeric:i}=e;return t(gh,{"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(Zc(e,function(e){try{t=t===void 0?e:r(t,e)}catch(t){throw hh(t,`prod`,e)}}),typeof t==`string`&&(t=i(t,Ri(t,n))),t===void 0)throw Error(`Cannot calculate prod of an empty array`);return t}}),vh=`format`,yh=J(vh,[`typed`],e=>{var{typed:t}=e;return t(vh,{any:Ys,"any, Object | function | number | BigNumber":Ys})}),bh=`bin`,xh=J(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})}})}),Sh=`oct`,Ch=J(Sh,[`typed`,`format`],e=>{var{typed:t,format:n}=e;return t(Sh,{"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`,Th=J(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})}})}),Eh=/\$([\w.]+)/g,Dh=`print`,Oh=J(Dh,[`typed`],e=>{var{typed:t}=e;return t(Dh,{"string, Object | Array":kh,"string, Object | Array, number | Object":kh})});function kh(e,t,n){return e.replace(Eh,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:Mr(a)?a:Ys(a,n)})}var Ah=`to`,jh=J(Ah,[`typed`,`matrix`,`concat`],e=>{var{typed:t,matrix:n,concat:r}=e;return t(Ah,{"Unit, Unit | string":(e,t)=>e.to(t)},Cf({typed:t,matrix:n,concat:r})({Ds:!0}))}),Mh=`toBest`,Nh=J(Mh,[`typed`],e=>{var{typed:t}=e;return t(Mh,{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)})}),Ph=`isPrime`,Fh=J(Ph,[`typed`],e=>{var{typed:t}=e;return t(Ph,{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=>Qc(t,e))})}),Ih=J(`numeric`,[`number`,`?bignumber`,`?fraction`],e=>{var{number:t,bignumber:n,fraction:r}=e,i={string:!0,number:!0,BigNumber:!0,Fraction:!0},a={number:e=>t(e),BigNumber:n?e=>n(e):vm,bigint:e=>BigInt(e),Fraction:r?e=>r(e):ym};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=gi(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)}}),Lh=`divideScalar`,Rh=J(Lh,[`typed`,`numeric`],e=>{var{typed:t,numeric:n}=e;return t(Lh,{"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)})}),zh=`pow`,Bh=J(zh,[`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(zh,{"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&&!Li(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:Li(t)||e>=0||n.predictable?kl(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(!Li(t))throw TypeError(`For A^b, b must be an integer (value is `+t+`)`);var n=ac(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))}}),Vh=`Number of decimals in function round must be an integer`,Hh=`round`,Uh=J(Hh,[`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=qd({typed:t,equalScalar:i}),l=Jd({typed:t,DenseMatrix:s}),u=Yd({typed:t});function d(e){return Math.abs(Ji(e).exponent)}return t(Hh,{number:function(e){var t=Al(e,d(n.relTol));return Al(na(e,t,n.relTol,n.absTol)?t:e)},"number, number":function(e,t){var r=d(n.relTol);if(t>=r)return Al(e,t);var i=Al(e,r);return Al(na(e,i,n.relTol,n.absTol)?i:e,t)},"number, BigNumber":function(e,t){if(!t.isInteger())throw TypeError(Vh);return new o(e).toDecimalPlaces(t.toNumber())},Complex:function(e){return e.round()},"Complex, number":function(e,t){if(t%1)throw TypeError(Vh);return e.round(t)},"Complex, BigNumber":function(e,t){if(!t.isInteger())throw TypeError(Vh);var n=t.toNumber();return e.round(n)},BigNumber:function(e){var t=new o(e).toDecimalPlaces(d(n.relTol));return(Ru(e,t,n.relTol,n.absTol)?t:e).toDecimalPlaces(0)},"BigNumber, BigNumber":function(e,t){if(!t.isInteger())throw TypeError(Vh);var r=d(n.relTol);if(t>=r)return e.toDecimalPlaces(t.toNumber());var i=e.toDecimalPlaces(r);return(Ru(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(Vh);return e.round(t)},"Fraction, BigNumber":function(e,t){if(!t.isInteger())throw TypeError(Vh);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)=>Qc(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=>Qc(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())})}),Wh=`log`,Gh=[`config`,`typed`,`typeOf`,`divideScalar`,`Complex`],Kh=Math.log(16),qh=J(Wh,Gh,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(Wh,{number:function(e){return e>=0||r.predictable?yl(e):s(e)},bigint:zf(Kh,yl,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))})})}),Jh=`log1p`,Yh=J(Jh,[`typed`,`config`,`divideScalar`,`log`,`Complex`],e=>{var{typed:t,config:n,divideScalar:r,log:i,Complex:a}=e;return t(Jh,{number:function(e){return e>=-1||n.predictable?Hi(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=>Qc(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))}}),Xh=`nthRoots`,Zh=J(Xh,[`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(Xh,{Complex:function(e){return o(e,2)},"Complex, number":o})}),Qh=`dotPow`,$h=J(Qh,[`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=vf({typed:t}),l=Tp({typed:t,SparseMatrix:s}),u=qd({typed:t,equalScalar:n}),d=Jd({typed:t,DenseMatrix:a}),f=Cf({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(Qh,f({elop:t(p),SS:l,DS:c,Ss:u,sS:d}))}),eg=`dotDivide`,tg=J(eg,[`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=_f({typed:t,equalScalar:r}),l=vf({typed:t}),u=Tp({typed:t,SparseMatrix:s}),d=qd({typed:t,equalScalar:r}),f=Jd({typed:t,DenseMatrix:a});return t(eg,Cf({typed:t,matrix:n,concat:o})({elop:i,SS:u,DS:l,SD:c,Ss:d,sS:f}))});function ng(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: `+Ys(i)+`)`);var a=i[0];if(a!==i[1])throw RangeError(`Matrix must be square (size: `+Ys(i)+`)`);var o=[];if(Pr(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(Ir(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(Lr(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(Nr(n)){var v=ac(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 rg=`lsolve`,ig=J(rg,[`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=ng({DenseMatrix:s});return t(rg,{"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]})}}),ag=`usolve`,og=J(ag,[`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=ng({DenseMatrix:s});return t(ag,{"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]})}}),sg=`lsolveAll`,cg=J(sg,[`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=ng({DenseMatrix:s});return t(sg,{"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]}))}}),lg=`usolveAll`,ug=J(lg,[`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=ng({DenseMatrix:s});return t(lg,{"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]}))}}),dg=J(`matAlgo08xS0Sid`,[`typed`,`equalScalar`],e=>{var{typed:t,equalScalar:n}=e;return function(e,r,i){var a=e._values,o=e._index,s=e._ptr,c=e._size,l=e._datatype||e._data===void 0?e._datatype:e.getDataType(),u=r._values,d=r._index,f=r._ptr,p=r._size,m=r._datatype||r._data===void 0?r._datatype:r.getDataType();if(c.length!==p.length)throw new rc(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})}}),fg=J(`useMatrixForArrayScalar`,[`typed`,`matrix`],e=>{var{typed:t,matrix:n}=e;return{"Array, number":t.referTo(`DenseMatrix, number`,e=>(t,r)=>e(n(t),r).valueOf()),"Array, BigNumber":t.referTo(`DenseMatrix, BigNumber`,e=>(t,r)=>e(n(t),r).valueOf()),"number, Array":t.referTo(`number, DenseMatrix`,e=>(t,r)=>e(t,n(r)).valueOf()),"BigNumber, Array":t.referTo(`BigNumber, DenseMatrix`,e=>(t,r)=>e(t,n(r)).valueOf())}}),pg=`leftShift`,mg=J(pg,[`typed`,`matrix`,`equalScalar`,`zeros`,`DenseMatrix`,`concat`],e=>{var{typed:t,matrix:n,equalScalar:r,zeros:i,DenseMatrix:a,concat:o}=e,s=Ef({typed:t}),c=_f({typed:t,equalScalar:r}),l=dg({typed:t,equalScalar:r}),u=Of({typed:t,DenseMatrix:a}),d=qd({typed:t,equalScalar:r}),f=Yd({typed:t}),p=Cf({typed:t,matrix:n,concat:o}),m=fg({typed:t,matrix:n});return t(pg,{"number, number":Rl,"BigNumber, BigNumber":_p,"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}))}),hg=`rightArithShift`,gg=J(hg,[`typed`,`matrix`,`equalScalar`,`zeros`,`DenseMatrix`,`concat`],e=>{var{typed:t,matrix:n,equalScalar:r,zeros:i,DenseMatrix:a,concat:o}=e,s=Ef({typed:t}),c=_f({typed:t,equalScalar:r}),l=dg({typed:t,equalScalar:r}),u=Of({typed:t,DenseMatrix:a}),d=qd({typed:t,equalScalar:r}),f=Yd({typed:t}),p=Cf({typed:t,matrix:n,concat:o}),m=fg({typed:t,matrix:n});return t(hg,{"number, number":zl,"BigNumber, BigNumber":vp,"bigint, bigint":(e,t)=>e>>t,"SparseMatrix, number | BigNumber":t.referToSelf(e=>(t,n)=>r(n,0)?t.clone():d(t,n,e,!1)),"DenseMatrix, number | BigNumber":t.referToSelf(e=>(t,n)=>r(n,0)?t.clone():f(t,n,e,!1)),"number | BigNumber, SparseMatrix":t.referToSelf(e=>(t,n)=>r(t,0)?i(n.size(),n.storage()):u(n,t,e,!0)),"number | BigNumber, DenseMatrix":t.referToSelf(e=>(t,n)=>r(t,0)?i(n.size(),n.storage()):f(n,t,e,!0))},m,p({SS:l,DS:s,SD:c}))}),_g=`rightLogShift`,vg=J(_g,[`typed`,`matrix`,`equalScalar`,`zeros`,`DenseMatrix`,`concat`],e=>{var{typed:t,matrix:n,equalScalar:r,zeros:i,DenseMatrix:a,concat:o}=e,s=Ef({typed:t}),c=_f({typed:t,equalScalar:r}),l=dg({typed:t,equalScalar:r}),u=Of({typed:t,DenseMatrix:a}),d=qd({typed:t,equalScalar:r}),f=Yd({typed:t}),p=Cf({typed:t,matrix:n,concat:o}),m=fg({typed:t,matrix:n});return t(_g,{"number, number":Bl,"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}))}),yg=`and`,bg=J(yg,[`typed`,`matrix`,`equalScalar`,`zeros`,`not`,`concat`],e=>{var{typed:t,matrix:n,equalScalar:r,zeros:i,not:a,concat:o}=e,s=_f({typed:t,equalScalar:r}),c=If({typed:t,equalScalar:r}),l=qd({typed:t,equalScalar:r}),u=Yd({typed:t}),d=Cf({typed:t,matrix:n,concat:o});return t(yg,{"number, number":Ql,"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":Ql,"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}))}),xg=`compare`,Sg=J(xg,[`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=vf({typed:t}),u=yf({typed:t,equalScalar:r}),d=Jd({typed:t,DenseMatrix:s}),f=Cf({typed:t,matrix:i,concat:c}),p=id({typed:t});return t(xg,Cg({typed:t,config:n}),{"boolean, boolean":function(e,t){return e===t?0:e>t?1:-1},"BigNumber, BigNumber":function(e,t){return Ru(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}))}),Cg=J(xg,[`typed`,`config`],e=>{var{typed:t,config:n}=e;return t(xg,{"number, number":function(e,t){return na(e,t,n.relTol,n.absTol)?0:e>t?1:-1}})}),wg=Dt(wt(((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),Tg=`compareNatural`,Eg=J(Tg,[`typed`,`compare`],e=>{var{typed:t,compare:n}=e,r=n.signatures[`boolean,boolean`];return t(Tg,{"any, any":i});function i(e,t){var c=gi(e),l=gi(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 Dg(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 Lr(t)&&Lr(n)?o(e,t.toJSON().values,n.toJSON().values):Lr(t)?a(e,t.toArray(),n):Lr(n)?a(e,t,n.toArray()):Ir(t)?a(e,t.toJSON().data,n):Ir(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 Dg(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 Og=`compareText`,kg=[`typed`,`matrix`,`concat`];nc.signature=`any, any`;var Ag=J(Og,kg,e=>{var{typed:t,matrix:n,concat:r}=e;return t(Og,nc,Cf({typed:t,matrix:n,concat:r})({elop:nc,Ds:!0}))}),jg=`equal`,Mg=J(jg,[`typed`,`matrix`,`equalScalar`,`DenseMatrix`,`SparseMatrix`],e=>{var{typed:t,matrix:n,equalScalar:r,DenseMatrix:i,concat:a,SparseMatrix:o}=e,s=vf({typed:t}),c=Tp({typed:t,SparseMatrix:o}),l=Jd({typed:t,DenseMatrix:i}),u=Cf({typed:t,matrix:n});return t(jg,Ng({typed:t,equalScalar:r}),u({elop:r,SS:c,DS:s,Ss:l}))}),Ng=J(jg,[`typed`,`equalScalar`],e=>{var{typed:t,equalScalar:n}=e;return t(jg,{"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)}})}),Pg=`equalText`,Fg=J(Pg,[`typed`,`compareText`,`isZero`],e=>{var{typed:t,compareText:n,isZero:r}=e;return t(Pg,{"any, any":function(e,t){return r(n(e,t))}})}),Ig=`smaller`,Lg=J(Ig,[`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=vf({typed:t}),l=Tp({typed:t,SparseMatrix:s}),u=Jd({typed:t,DenseMatrix:a}),d=Cf({typed:t,matrix:i,concat:o}),f=id({typed:t});function p(e,t){return e.lt(t)&&!Ru(e,t,n.relTol,n.absTol)}return t(Ig,Rg({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}))}),Rg=J(Ig,[`typed`,`config`],e=>{var{typed:t,config:n}=e;return t(Ig,{"number, number":function(e,t){return e<t&&!na(e,t,n.relTol,n.absTol)}})}),zg=`smallerEq`,Bg=J(zg,[`typed`,`config`,`matrix`,`DenseMatrix`,`concat`,`SparseMatrix`],e=>{var{typed:t,config:n,matrix:r,DenseMatrix:i,concat:a,SparseMatrix:o}=e,s=vf({typed:t}),c=Tp({typed:t,SparseMatrix:o}),l=Jd({typed:t,DenseMatrix:i}),u=Cf({typed:t,matrix:r,concat:a}),d=id({typed:t});return t(zg,Vg({typed:t,config:n}),{"boolean, boolean":(e,t)=>e<=t,"BigNumber, BigNumber":function(e,t){return e.lte(t)||Ru(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}))}),Vg=J(zg,[`typed`,`config`],e=>{var{typed:t,config:n}=e;return t(zg,{"number, number":function(e,t){return e<=t||na(e,t,n.relTol,n.absTol)}})}),Hg=`larger`,Ug=J(Hg,[`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=vf({typed:t}),l=Tp({typed:t,SparseMatrix:s}),u=Jd({typed:t,DenseMatrix:a}),d=Cf({typed:t,matrix:i,concat:o}),f=id({typed:t});function p(e,t){return e.gt(t)&&!Ru(e,t,n.relTol,n.absTol)}return t(Hg,Wg({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}))}),Wg=J(Hg,[`typed`,`config`],e=>{var{typed:t,config:n}=e;return t(Hg,{"number, number":function(e,t){return e>t&&!na(e,t,n.relTol,n.absTol)}})}),Gg=`largerEq`,Kg=J(Gg,[`typed`,`config`,`matrix`,`DenseMatrix`,`concat`,`SparseMatrix`],e=>{var{typed:t,config:n,matrix:r,DenseMatrix:i,concat:a,SparseMatrix:o}=e,s=vf({typed:t}),c=Tp({typed:t,SparseMatrix:o}),l=Jd({typed:t,DenseMatrix:i}),u=Cf({typed:t,matrix:r,concat:a}),d=id({typed:t});return t(Gg,qg({typed:t,config:n}),{"boolean, boolean":(e,t)=>e>=t,"BigNumber, BigNumber":function(e,t){return e.gte(t)||Ru(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}))}),qg=J(Gg,[`typed`,`config`],e=>{var{typed:t,config:n}=e;return t(Gg,{"number, number":function(e,t){return e>=t||na(e,t,n.relTol,n.absTol)}})}),Jg=`deepEqual`,Yg=J(Jg,[`typed`,`equal`],e=>{var{typed:t,equal:n}=e;return t(Jg,{"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)}}),Xg=`unequal`,Zg=J(Xg,[`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=vf({typed:t}),l=Tp({typed:t,SparseMatrix:s}),u=Jd({typed:t,DenseMatrix:a}),d=Cf({typed:t,matrix:i,concat:o});return t(Xg,Qg({typed:t,equalScalar:r}),d({elop:f,SS:l,DS:c,Ss:u}));function f(e,t){return!r(e,t)}}),Qg=J(Xg,[`typed`,`equalScalar`],e=>{var{typed:t,equalScalar:n}=e;return t(Xg,{"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)}})}),$g=`partitionSelect`,e_=J($g,[`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($g,{"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(!Li(t)||t<0)throw Error(`k must be a non-negative integer`);if(Pr(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]}}),t_=`sort`,n_=J(t_,[`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(t_,{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(ac(e).length!==1)throw Error(`One dimensional array expected`)}function l(e){if(e.size().length!==1)throw Error(`One dimensional matrix expected`)}}),r_=`max`,i_=J(r_,[`typed`,`config`,`numeric`,`larger`,`isNaN`],e=>{var{typed:t,config:n,numeric:r,larger:i,isNaN:a}=e;return t(r_,{"Array | Matrix":s,"Array | Matrix, number | BigNumber":function(e,t){return $c(e,t.valueOf(),o)},"...":function(e){if(Xc(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 hh(e,`max`,t)}}function s(e){var t;if(Zc(e,function(e){try{(a(e)||t===void 0||i(e,t))&&(t=e)}catch(t){throw hh(t,`max`,e)}}),t===void 0)throw Error(`Cannot calculate max of an empty array`);return typeof t==`string`&&(t=r(t,Ri(t,n))),t}}),a_=`min`,o_=J(a_,[`typed`,`config`,`numeric`,`smaller`,`isNaN`],e=>{var{typed:t,config:n,numeric:r,smaller:i,isNaN:a}=e;return t(a_,{"Array | Matrix":s,"Array | Matrix, number | BigNumber":function(e,t){return $c(e,t.valueOf(),o)},"...":function(e){if(Xc(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 hh(e,`min`,t)}}function s(e){var t;if(Zc(e,function(e){try{(a(e)||t===void 0||i(e,t))&&(t=e)}catch(t){throw hh(t,`min`,e)}}),t===void 0)throw Error(`Cannot calculate min of an empty array`);return typeof t==`string`&&(t=r(t,Ri(t,n))),t}}),s_=J(`ImmutableDenseMatrix`,[`smaller`,`DenseMatrix`],e=>{var{smaller:t,DenseMatrix:n}=e;function r(e,t){if(!(this instanceof r))throw SyntaxError(`Constructor must be called with the new operator`);if(t&&!Mr(t))throw Error(`Invalid datatype: `+t);if(Pr(e)||Nr(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&&Nr(e.data)&&Nr(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 (`+gi(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 Pr(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:_i(this._data),size:_i(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}),c_=J(`Index`,[`ImmutableDenseMatrix`,`getMatrixDataType`],e=>{var{ImmutableDenseMatrix:t,getMatrixDataType:n}=e;function r(){if(!(this instanceof r))throw SyntaxError(`Constructor must be called with the new operator`);this._dimensions=[],this._sourceSize=[],this._isScalar=!0;for(var e=0,t=arguments.length;e<t;e++){var a=e<0||arguments.length<=e?void 0:arguments[e],o=Nr(a),s=Pr(a),c=typeof a,l=null;if(Rr(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(l_(a).valueOf())),s&&(u=i(l_(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(!Er(e[n])||!Li(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=_i(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]=Mr(r)||Er(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]=Mr(r)||Er(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]=Mr(r)||Er(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 Er(e)?this._dimensions[e]??null:null},r.prototype.isObjectProperty=function(){return this._dimensions.length===1&&Mr(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(Mr(r)||Er(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];Mr(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 l_(e){var t=[];return e.forEach((e,n)=>{e&&t.push(n)}),t}var u_=J(`FibonacciHeap`,[`smaller`,`larger`],e=>{var{smaller:t,larger:n}=e,r=1/Math.log((1+Math.sqrt(5))/2);function i(){if(!(this instanceof i))throw SyntaxError(`Constructor must be called with the new operator`);this._minimum=null,this._size=0}i.prototype.type=`FibonacciHeap`,i.prototype.isFibonacciHeap=!0,i.prototype.insert=function(e,n){var r={key:e,value:n,degree:0};if(this._minimum){var i=this._minimum;r.left=i,r.right=i.right,i.right=r,r.right.left=r,t(e,i.key)&&(this._minimum=r)}else r.left=r,r.right=r,this._minimum=r;return this._size++,r},i.prototype.size=function(){return this._size},i.prototype.clear=function(){this._minimum=null,this._size=0},i.prototype.isEmpty=function(){return this._size===0},i.prototype.extractMinimum=function(){var e=this._minimum;if(e===null)return e;for(var t=this._minimum,n=e.degree,r=e.child;n>0;){var i=r.right;r.left.right=r.right,r.right.left=r.left,r.left=t,r.right=t.right,t.right=r,r.right.left=r,r.parent=null,r=i,n--}return e.left.right=e.right,e.right.left=e.left,e===e.right?t=null:(t=e.right,t=l(t,this._size)),this._size--,this._minimum=t,e},i.prototype.remove=function(e){this._minimum=a(this._minimum,e,-1),this.extractMinimum()};function a(e,n,r){n.key=r;var i=n.parent;return i&&t(n.key,i.key)&&(o(e,n,i),s(e,i)),t(n.key,e.key)&&(e=n),e}function o(e,t,n){t.left.right=t.right,t.right.left=t.left,n.degree--,n.child===t&&(n.child=t.right),n.degree===0&&(n.child=null),t.left=e,t.right=e.right,e.right=t,t.right.left=t,t.parent=null,t.mark=!1}function s(e,t){var n=t.parent;n&&(t.mark?(o(e,t,n),s(n)):t.mark=!0)}var c=function(e,t){e.left.right=e.right,e.right.left=e.left,e.parent=t,t.child?(e.left=t.child,e.right=t.child.right,t.child.right=e,e.right.left=e):(t.child=e,e.right=e,e.left=e),t.degree++,e.mark=!1};function l(e,i){var a=Math.floor(Math.log(i)*r)+1,o=Array(a),s=0,l=e;if(l)for(s++,l=l.right;l!==e;)s++,l=l.right;for(var u;s>0;){for(var d=l.degree,f=l.right;u=o[d],u;){if(n(l.key,u.key)){var p=u;u=l,l=p}c(u,l),o[d]=null,d++}o[d]=l,l=f,s--}e=null;for(var m=0;m<a;m++)u=o[m],u&&(e?(u.left.right=u.right,u.right.left=u.left,u.left=e,u.right=e.right,e.right=u,u.right.left=u,t(u.key,e.key)&&(e=u)):e=u);return e}return i},{isClass:!0}),d_=J(`Spa`,[`addScalar`,`equalScalar`,`FibonacciHeap`],e=>{var{addScalar:t,equalScalar:n,FibonacciHeap:r}=e;function i(){if(!(this instanceof i))throw SyntaxError(`Constructor must be called with the new operator`);this._values=[],this._heap=new r}return i.prototype.type=`Spa`,i.prototype.isSpa=!0,i.prototype.set=function(e,t){if(this._values[e])this._values[e].value=t;else{var n=this._heap.insert(e,t);this._values[e]=n}},i.prototype.get=function(e){var t=this._values[e];return t?t.value:0},i.prototype.accumulate=function(e,n){var r=this._values[e];r?r.value=t(r.value,n):(r=this._heap.insert(e,n),this._values[e]=r)},i.prototype.forEach=function(e,t,r){var i=this._heap,a=this._values,o=[],s=i.extractMinimum();for(s&&o.push(s);s&&s.key<=t;)s.key>=e&&(n(s.value,0)||r(s.key,s.value,this)),s=i.extractMinimum(),s&&o.push(s);for(var c=0;c<o.length;c++){var l=o[c];s=i.insert(l.key,l.value),a[s.key]=s}},i.prototype.swap=function(e,t){var n=this._values[e],r=this._values[t];if(!n&&r)n=this._heap.insert(e,r.value),this._heap.remove(r),this._values[e]=n,this._values[t]=void 0;else if(n&&!r)r=this._heap.insert(t,n.value),this._heap.remove(n),this._values[t]=r,this._values[e]=void 0;else if(n&&r){var i=n.value;n.value=r.value,r.value=i}},i},{isClass:!0});function f_(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 p_(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:f_(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 m_=p_(function(e){return new e(1).exp()},{hasher:v_}),h_=p_(function(e){return new e(1).plus(new e(5).sqrt()).div(2)},{hasher:v_}),g_=p_(function(e){return e.acos(-1)},{hasher:v_}),__=p_(function(e){return g_(e).times(2)},{hasher:v_});function v_(e){return e[0].precision}function y_(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?y_(Object(n),!0).forEach(function(t){th(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):y_(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}var x_=J(`Unit`,[`?on`,`config`,`addScalar`,`subtractScalar`,`multiplyScalar`,`divideScalar`,`pow`,`abs`,`fix`,`round`,`equal`,`isNumeric`,`format`,`number`,`Complex`,`BigNumber`,`Fraction`],e=>{var{on:t,config:n,addScalar:r,subtractScalar:i,multiplyScalar:a,divideScalar:o,pow:s,abs:c,fix:l,round:u,equal:d,isNumeric:f,format:p,number:m,Complex:h,BigNumber:g,Fraction:_}=e,v=m,y=!1,b=!0;function x(e,t){if(!(this instanceof x))throw Error(`Constructor must be called with the new operator`);if(!(e==null||f(e)||kr(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(jr(t)&&t.value===null)this.fixPrefix=t.fixPrefix,this.skipAutomaticSimplification=t.skipAutomaticSimplification,this.dimensions=t.dimensions.slice(0),this.units=t.units.map(e=>lr({},e));else throw TypeError(`Second parameter in Unit constructor must be a string or valueless Unit`);this.value=this._normalize(e)}Object.defineProperty(x,`name`,{value:`Unit`}),x.prototype.constructor=x,x.prototype.type=`Unit`,x.prototype.isUnit=!0;var S,C,w;function T(){for(;w===` `||w===` `;)O()}function E(e){return e>=`0`&&e<=`9`||e===`.`}function D(e){return e>=`0`&&e<=`9`}function O(){C++,w=S.charAt(C)}function k(e){C=e,w=S.charAt(C)}function A(){var e=``,t=C;if(w===`+`?O():w===`-`&&(e+=w,O()),!E(w))return k(t),null;if(w===`.`){if(e+=w,O(),!D(w))return k(t),null}else{for(;D(w);)e+=w,O();w===`.`&&(e+=w,O())}for(;D(w);)e+=w,O();if(w===`E`||w===`e`){var n=``,r=C;if(n+=w,O(),(w===`+`||w===`-`)&&(n+=w,O()),!D(w))return k(r),e;for(e+=n;D(w);)e+=w,O()}return e}function j(){for(var e=``;D(w)||x.isValidAlpha(w);)e+=w,O();var t=e.charAt(0);return x.isValidAlpha(t)?e:null}function M(e){return w===e?(O(),e):null}x.parse=function(e,t){if(t||={},S=e,C=-1,w=``,typeof S!=`string`)throw TypeError(`Invalid argument in Unit.parse, string expected`);var r=new x;r.units=[];var i=1,a=!1;O(),T();var o=A(),s=null;if(o){if(n.number===`BigNumber`)s=new g(o);else if(n.number===`Fraction`)try{s=new _(o)}catch{s=parseFloat(o)}else s=parseFloat(o);T(),M(`*`)?(i=1,a=!0):M(`/`)&&(i=-1,a=!0)}for(var c=[],l=1;;){for(T();w===`(`;)c.push(i),l*=i,i=1,O(),T();var u=void 0;if(w){var d=w;if(u=j(),u===null)throw SyntaxError(`Unexpected "`+d+`" in "`+S+`" at index `+C.toString())}else break;var f=N(u);if(f===null)throw SyntaxError(`Unit "`+u+`" not found.`);var p=i*l;if(T(),M(`^`)){T();var m=A();if(m===null)throw SyntaxError(`In "`+e+`", "^" must be followed by a floating-point number`);p*=m}r.units.push({unit:f.unit,prefix:f.prefix,power:p});for(var h=0;h<B.length;h++)r.dimensions[h]+=(f.unit.dimensions[h]||0)*p;for(T();w===`)`;){if(c.length===0)throw SyntaxError(`Unmatched ")" in "`+S+`" at index `+C.toString());l/=c.pop(),O(),T()}if(a=!1,M(`*`)?(i=1,a=!0):M(`/`)?(i=-1,a=!0):i=1,f.unit.base){var v=f.unit.base.key;ie.auto[v]={unit:f.unit,prefix:f.prefix}}}if(T(),w)throw SyntaxError(`Could not parse: "`+e+`"`);if(a)throw SyntaxError(`Trailing characters: "`+e+`"`);if(c.length!==0)throw SyntaxError(`Unmatched "(" in "`+S+`"`);if(r.units.length===0&&!t.allowNoUnits)throw SyntaxError(`"`+e+`" contains no units`);return r.value=s===void 0?null:r._normalize(s),r},x.prototype.clone=function(){var e=new x;e.fixPrefix=this.fixPrefix,e.skipAutomaticSimplification=this.skipAutomaticSimplification,e.value=_i(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])Ti(this.units[t],n)&&(e.units[t][n]=this.units[t][n]);return e},x.prototype.valueType=function(){return gi(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(gi(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(gi(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=p_(e=>{if(Ti(H,e)){var t=H[e];return{unit:t,prefix:t.prefixes[``]}}for(var n in H)if(Ti(H,n)&&Js(e,n)){var r=H[n],i=e.length-n.length,a=e.substring(0,i),o=Ti(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=jr(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,jr(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=jr(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,jr(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(gi(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(jr(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=_i(t);else{var o=x._getNumberConverter(gi(t)),s=this.units[0].unit.value,c=this.units[0].unit.offset,l=a(s,c),u=n.units[0].unit.value,d=n.units[0].unit.offset,f=a(u,d);n.value=r(t,o(i(l,f)))}return n.fixPrefix=!0,n.skipAutomaticSimplification=!0,n},x.prototype.toNumber=function(e){return v(this.toNumeric(e))},x.prototype.toNumeric=function(e){var t=e?this.to(e):this.clone();return t._isDerived()||t.units.length===0?t._denormalize(t.value):t._denormalize(t.value,t.units[0].prefix.value)},x.prototype.toString=function(){return this.format()},x.prototype.toJSON=function(){return{mathjs:`Unit`,value:this._denormalize(this.value),unit:this.units.length>0?this.formatUnits():null,fixPrefix:this.fixPrefix,skipSimp:this.skipAutomaticSimplification}},x.fromJSON=function(e){var t=new x(e.value,e.unit??void 0);return t.fixPrefix=e.fixPrefix??y,t.skipAutomaticSimplification=e.skipSimp??b,t},x.prototype.valueOf=x.prototype.toString,x.prototype.simplify=function(){var e=this.clone(),t=[],n;for(var r in U)if(Ti(U,r)&&e.hasBase(V[r])){n=r;break}if(n===`NONE`)e.units=[];else{var i;if(n&&Ti(U,n)&&(i=U[n]),i)e.units=[{unit:i.unit,prefix:i.prefix,power:1}];else{for(var a=!1,o=0;o<B.length;o++){var s=B[o];Math.abs(e.dimensions[o]||0)>1e-12&&(Ti(U,s)?t.push({unit:U[s].unit,prefix:U[s].prefix,power:e.dimensions[o]||0}):a=!0)}t.length<e.units.length&&!a&&(e.units=t)}}return e},x.prototype.toSI=function(){for(var e=this.clone(),t=[],n=0;n<B.length;n++){var r=B[n];if(Math.abs(e.dimensions[n]||0)>1e-12)if(Ti(ie.si,r))t.push({unit:ie.si[r].unit,prefix:ie.si[r].prefix,power:e.dimensions[n]||0});else throw Error(`Cannot express custom unit `+r+` in SI units`)}return e.units=t,e.fixPrefix=!0,e.skipAutomaticSimplification=!0,this.value===null?e:(e.value=null,this.to(e))},x.prototype.formatUnits=function(){for(var e=``,t=``,n=0,r=0,i=0;i<this.units.length;i++)this.units[i].power>0?(n++,e+=` `+this.units[i].prefix.name+this.units[i].unit.name,Math.abs(this.units[i].power-1)>1e-15&&(e+=`^`+this.units[i].power)):this.units[i].power<0&&r++;if(r>0)for(var a=0;a<this.units.length;a++)this.units[a].power<0&&(n>0?(t+=` `+this.units[a].prefix.name+this.units[a].unit.name,Math.abs(this.units[a].power+1)>1e-15&&(t+=`^`+-this.units[a].power)):(t+=` `+this.units[a].prefix.name+this.units[a].unit.name,t+=`^`+this.units[a].power));e=e.substr(1),t=t.substr(1),n>1&&r>0&&(e=`(`+e+`)`),r>1&&n>0&&(t=`(`+t+`)`);var o=e;return n>0&&r>0&&(o+=` / `),o+=t,o},x.prototype.toBest=function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(e&&!Array.isArray(e))throw Error(`Invalid unit type. Expected string or Unit.`);var n=this.units[0].unit.prefixes;if(e&&e.length>0){var r=e.map(e=>{var t=null;if(typeof e==`string`){if(t=x.parse(e),!t)throw Error(`Invalid unit type. Expected compatible string or Unit.`)}else if(!jr(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&&kr(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&&kr(e.value)&&(t=Math.abs(e.value.re)<1e-14),e.units)Ti(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(Ti(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=lr({},z.SHORT,z.LONG),z.BINARY_SHORT=lr({},z.BINARY_SHORT_SI,z.BINARY_SHORT_IEC),z.BINARY_LONG=lr({},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)Ti(V,ee)&&(V[ee].key=ee);var te={name:``,base:{},value:1,offset:0,dimensions:B.map(e=>0)},H={meter:{name:`meter`,base:V.LENGTH,prefixes:z.LONG,value:1,offset:0},inch:{name:`inch`,base:V.LENGTH,prefixes:z.NONE,value:.0254,offset:0},foot:{name:`foot`,base:V.LENGTH,prefixes:z.NONE,value:.3048,offset:0},yard:{name:`yard`,base:V.LENGTH,prefixes:z.NONE,value:.9144,offset:0},mile:{name:`mile`,base:V.LENGTH,prefixes:z.NONE,value:1609.344,offset:0},link:{name:`link`,base:V.LENGTH,prefixes:z.NONE,value:.201168,offset:0},rod:{name:`rod`,base:V.LENGTH,prefixes:z.NONE,value:5.0292,offset:0},chain:{name:`chain`,base:V.LENGTH,prefixes:z.NONE,value:20.1168,offset:0},angstrom:{name:`angstrom`,base:V.LENGTH,prefixes:z.NONE,value:1e-10,offset:0},m:{name:`m`,base:V.LENGTH,prefixes:z.SHORT,value:1,offset:0},in:{name:`in`,base:V.LENGTH,prefixes:z.NONE,value:.0254,offset:0},ft:{name:`ft`,base:V.LENGTH,prefixes:z.NONE,value:.3048,offset:0},yd:{name:`yd`,base:V.LENGTH,prefixes:z.NONE,value:.9144,offset:0},mi:{name:`mi`,base:V.LENGTH,prefixes:z.NONE,value:1609.344,offset:0},li:{name:`li`,base:V.LENGTH,prefixes:z.NONE,value:.201168,offset:0},rd:{name:`rd`,base:V.LENGTH,prefixes:z.NONE,value:5.02921,offset:0},ch:{name:`ch`,base:V.LENGTH,prefixes:z.NONE,value:20.1168,offset:0},mil:{name:`mil`,base:V.LENGTH,prefixes:z.NONE,value:254e-7,offset:0},m2:{name:`m2`,base:V.SURFACE,prefixes:z.SQUARED,value:1,offset:0},sqin:{name:`sqin`,base:V.SURFACE,prefixes:z.NONE,value:64516e-8,offset:0},sqft:{name:`sqft`,base:V.SURFACE,prefixes:z.NONE,value:.09290304,offset:0},sqyd:{name:`sqyd`,base:V.SURFACE,prefixes:z.NONE,value:.83612736,offset:0},sqmi:{name:`sqmi`,base:V.SURFACE,prefixes:z.NONE,value:2589988.110336,offset:0},sqrd:{name:`sqrd`,base:V.SURFACE,prefixes:z.NONE,value:25.29295,offset:0},sqch:{name:`sqch`,base:V.SURFACE,prefixes:z.NONE,value:404.6873,offset:0},sqmil:{name:`sqmil`,base:V.SURFACE,prefixes:z.NONE,value:64516e-14,offset:0},acre:{name:`acre`,base:V.SURFACE,prefixes:z.NONE,value:4046.86,offset:0},hectare:{name:`hectare`,base:V.SURFACE,prefixes:z.NONE,value:1e4,offset:0},m3:{name:`m3`,base:V.VOLUME,prefixes:z.CUBIC,value:1,offset:0},L:{name:`L`,base:V.VOLUME,prefixes:z.SHORT,value:.001,offset:0},l:{name:`l`,base:V.VOLUME,prefixes:z.SHORT,value:.001,offset:0},litre:{name:`litre`,base:V.VOLUME,prefixes:z.LONG,value:.001,offset:0},cuin:{name:`cuin`,base:V.VOLUME,prefixes:z.NONE,value:16387064e-12,offset:0},cuft:{name:`cuft`,base:V.VOLUME,prefixes:z.NONE,value:.028316846592,offset:0},cuyd:{name:`cuyd`,base:V.VOLUME,prefixes:z.NONE,value:.764554857984,offset:0},teaspoon:{name:`teaspoon`,base:V.VOLUME,prefixes:z.NONE,value:5e-6,offset:0},tablespoon:{name:`tablespoon`,base:V.VOLUME,prefixes:z.NONE,value:15e-6,offset:0},drop:{name:`drop`,base:V.VOLUME,prefixes:z.NONE,value:5e-8,offset:0},gtt:{name:`gtt`,base:V.VOLUME,prefixes:z.NONE,value:5e-8,offset:0},minim:{name:`minim`,base:V.VOLUME,prefixes:z.NONE,value:6.1611519921875e-8,offset:0},fluiddram:{name:`fluiddram`,base:V.VOLUME,prefixes:z.NONE,value:36966911953125e-19,offset:0},fluidounce:{name:`fluidounce`,base:V.VOLUME,prefixes:z.NONE,value:295735295625e-16,offset:0},gill:{name:`gill`,base:V.VOLUME,prefixes:z.NONE,value:.00011829411825,offset:0},cc:{name:`cc`,base:V.VOLUME,prefixes:z.NONE,value:1e-6,offset:0},cup:{name:`cup`,base:V.VOLUME,prefixes:z.NONE,value:.0002365882365,offset:0},pint:{name:`pint`,base:V.VOLUME,prefixes:z.NONE,value:.000473176473,offset:0},quart:{name:`quart`,base:V.VOLUME,prefixes:z.NONE,value:.000946352946,offset:0},gallon:{name:`gallon`,base:V.VOLUME,prefixes:z.NONE,value:.003785411784,offset:0},beerbarrel:{name:`beerbarrel`,base:V.VOLUME,prefixes:z.NONE,value:.117347765304,offset:0},oilbarrel:{name:`oilbarrel`,base:V.VOLUME,prefixes:z.NONE,value:.158987294928,offset:0},hogshead:{name:`hogshead`,base:V.VOLUME,prefixes:z.NONE,value:.238480942392,offset:0},g:{name:`g`,base:V.MASS,prefixes:z.SHORT,value:.001,offset:0},gram:{name:`gram`,base:V.MASS,prefixes:z.LONG,value:.001,offset:0},ton:{name:`ton`,base:V.MASS,prefixes:z.SHORT,value:907.18474,offset:0},t:{name:`t`,base:V.MASS,prefixes:z.SHORT,value:1e3,offset:0},tonne:{name:`tonne`,base:V.MASS,prefixes:z.LONG,value:1e3,offset:0},grain:{name:`grain`,base:V.MASS,prefixes:z.NONE,value:6479891e-11,offset:0},dram:{name:`dram`,base:V.MASS,prefixes:z.NONE,value:.0017718451953125,offset:0},ounce:{name:`ounce`,base:V.MASS,prefixes:z.NONE,value:.028349523125,offset:0},poundmass:{name:`poundmass`,base:V.MASS,prefixes:z.NONE,value:.45359237,offset:0},hundredweight:{name:`hundredweight`,base:V.MASS,prefixes:z.NONE,value:45.359237,offset:0},stick:{name:`stick`,base:V.MASS,prefixes:z.NONE,value:.115,offset:0},stone:{name:`stone`,base:V.MASS,prefixes:z.NONE,value:6.35029318,offset:0},gr:{name:`gr`,base:V.MASS,prefixes:z.NONE,value:6479891e-11,offset:0},dr:{name:`dr`,base:V.MASS,prefixes:z.NONE,value:.0017718451953125,offset:0},oz:{name:`oz`,base:V.MASS,prefixes:z.NONE,value:.028349523125,offset:0},lbm:{name:`lbm`,base:V.MASS,prefixes:z.NONE,value:.45359237,offset:0},cwt:{name:`cwt`,base:V.MASS,prefixes:z.NONE,value:45.359237,offset:0},s:{name:`s`,base:V.TIME,prefixes:z.SHORT,value:1,offset:0},min:{name:`min`,base:V.TIME,prefixes:z.NONE,value:60,offset:0},h:{name:`h`,base:V.TIME,prefixes:z.NONE,value:3600,offset:0},second:{name:`second`,base:V.TIME,prefixes:z.LONG,value:1,offset:0},sec:{name:`sec`,base:V.TIME,prefixes:z.LONG,value:1,offset:0},minute:{name:`minute`,base:V.TIME,prefixes:z.NONE,value:60,offset:0},hour:{name:`hour`,base:V.TIME,prefixes:z.NONE,value:3600,offset:0},day:{name:`day`,base:V.TIME,prefixes:z.NONE,value:86400,offset:0},week:{name:`week`,base:V.TIME,prefixes:z.NONE,value:7*86400,offset:0},month:{name:`month`,base:V.TIME,prefixes:z.NONE,value:2629800,offset:0},year:{name:`year`,base:V.TIME,prefixes:z.NONE,value:31557600,offset:0},decade:{name:`decade`,base:V.TIME,prefixes:z.NONE,value:315576e3,offset:0},century:{name:`century`,base:V.TIME,prefixes:z.NONE,value:315576e4,offset:0},millennium:{name:`millennium`,base:V.TIME,prefixes:z.NONE,value:315576e5,offset:0},hertz:{name:`Hertz`,base:V.FREQUENCY,prefixes:z.LONG,value:1,offset:0,reciprocal:!0},Hz:{name:`Hz`,base:V.FREQUENCY,prefixes:z.SHORT,value:1,offset:0,reciprocal:!0},rad:{name:`rad`,base:V.ANGLE,prefixes:z.SHORT,value:1,offset:0},radian:{name:`radian`,base:V.ANGLE,prefixes:z.LONG,value:1,offset:0},deg:{name:`deg`,base:V.ANGLE,prefixes:z.SHORT,value:null,offset:0},degree:{name:`degree`,base:V.ANGLE,prefixes:z.LONG,value:null,offset:0},grad:{name:`grad`,base:V.ANGLE,prefixes:z.SHORT,value:null,offset:0},gradian:{name:`gradian`,base:V.ANGLE,prefixes:z.LONG,value:null,offset:0},cycle:{name:`cycle`,base:V.ANGLE,prefixes:z.NONE,value:null,offset:0},arcsec:{name:`arcsec`,base:V.ANGLE,prefixes:z.NONE,value:null,offset:0},arcmin:{name:`arcmin`,base:V.ANGLE,prefixes:z.NONE,value:null,offset:0},A:{name:`A`,base:V.CURRENT,prefixes:z.SHORT,value:1,offset:0},ampere:{name:`ampere`,base:V.CURRENT,prefixes:z.LONG,value:1,offset:0},K:{name:`K`,base:V.TEMPERATURE,prefixes:z.SHORT,value:1,offset:0},degC:{name:`degC`,base:V.TEMPERATURE,prefixes:z.SHORT,value:1,offset:273.15},degF:{name:`degF`,base:V.TEMPERATURE,prefixes:z.SHORT,value:new _(5,9),offset:459.67},degR:{name:`degR`,base:V.TEMPERATURE,prefixes:z.SHORT,value:new _(5,9),offset:0},kelvin:{name:`kelvin`,base:V.TEMPERATURE,prefixes:z.LONG,value:1,offset:0},celsius:{name:`celsius`,base:V.TEMPERATURE,prefixes:z.LONG,value:1,offset:273.15},fahrenheit:{name:`fahrenheit`,base:V.TEMPERATURE,prefixes:z.LONG,value:new _(5,9),offset:459.67},rankine:{name:`rankine`,base:V.TEMPERATURE,prefixes:z.LONG,value:new _(5,9),offset:0},mol:{name:`mol`,base:V.AMOUNT_OF_SUBSTANCE,prefixes:z.SHORT,value:1,offset:0},mole:{name:`mole`,base:V.AMOUNT_OF_SUBSTANCE,prefixes:z.LONG,value:1,offset:0},cd:{name:`cd`,base:V.LUMINOUS_INTENSITY,prefixes:z.SHORT,value:1,offset:0},candela:{name:`candela`,base:V.LUMINOUS_INTENSITY,prefixes:z.LONG,value:1,offset:0},N:{name:`N`,base:V.FORCE,prefixes:z.SHORT,value:1,offset:0},newton:{name:`newton`,base:V.FORCE,prefixes:z.LONG,value:1,offset:0},dyn:{name:`dyn`,base:V.FORCE,prefixes:z.SHORT,value:1e-5,offset:0},dyne:{name:`dyne`,base:V.FORCE,prefixes:z.LONG,value:1e-5,offset:0},lbf:{name:`lbf`,base:V.FORCE,prefixes:z.NONE,value:4.4482216152605,offset:0},poundforce:{name:`poundforce`,base:V.FORCE,prefixes:z.NONE,value:4.4482216152605,offset:0},kip:{name:`kip`,base:V.FORCE,prefixes:z.LONG,value:4448.2216,offset:0},kilogramforce:{name:`kilogramforce`,base:V.FORCE,prefixes:z.NONE,value:9.80665,offset:0},J:{name:`J`,base:V.ENERGY,prefixes:z.SHORT,value:1,offset:0},joule:{name:`joule`,base:V.ENERGY,prefixes:z.LONG,value:1,offset:0},erg:{name:`erg`,base:V.ENERGY,prefixes:z.SHORTLONG,value:1e-7,offset:0},Wh:{name:`Wh`,base:V.ENERGY,prefixes:z.SHORT,value:3600,offset:0},BTU:{name:`BTU`,base:V.ENERGY,prefixes:z.BTU,value:1055.05585262,offset:0},eV:{name:`eV`,base:V.ENERGY,prefixes:z.SHORT,value:1602176565e-28,offset:0},electronvolt:{name:`electronvolt`,base:V.ENERGY,prefixes:z.LONG,value:1602176565e-28,offset:0},W:{name:`W`,base:V.POWER,prefixes:z.SHORT,value:1,offset:0},watt:{name:`watt`,base:V.POWER,prefixes:z.LONG,value:1,offset:0},hp:{name:`hp`,base:V.POWER,prefixes:z.NONE,value:745.6998715386,offset:0},VAR:{name:`VAR`,base:V.POWER,prefixes:z.SHORT,value:h.I,offset:0},VA:{name:`VA`,base:V.POWER,prefixes:z.SHORT,value:1,offset:0},Pa:{name:`Pa`,base:V.PRESSURE,prefixes:z.SHORT,value:1,offset:0},psi:{name:`psi`,base:V.PRESSURE,prefixes:z.NONE,value:6894.75729276459,offset:0},atm:{name:`atm`,base:V.PRESSURE,prefixes:z.NONE,value:101325,offset:0},bar:{name:`bar`,base:V.PRESSURE,prefixes:z.SHORTLONG,value:1e5,offset:0},torr:{name:`torr`,base:V.PRESSURE,prefixes:z.NONE,value:133.322,offset:0},mmHg:{name:`mmHg`,base:V.PRESSURE,prefixes:z.NONE,value:133.322,offset:0},mmH2O:{name:`mmH2O`,base:V.PRESSURE,prefixes:z.NONE,value:9.80665,offset:0},cmH2O:{name:`cmH2O`,base:V.PRESSURE,prefixes:z.NONE,value:98.0665,offset:0},coulomb:{name:`coulomb`,base:V.ELECTRIC_CHARGE,prefixes:z.LONG,value:1,offset:0},C:{name:`C`,base:V.ELECTRIC_CHARGE,prefixes:z.SHORT,value:1,offset:0},Ah:{name:`Ah`,base:V.ELECTRIC_CHARGE,prefixes:z.SHORT,value:3600,offset:0},farad:{name:`farad`,base:V.ELECTRIC_CAPACITANCE,prefixes:z.LONG,value:1,offset:0},F:{name:`F`,base:V.ELECTRIC_CAPACITANCE,prefixes:z.SHORT,value:1,offset:0},volt:{name:`volt`,base:V.ELECTRIC_POTENTIAL,prefixes:z.LONG,value:1,offset:0},V:{name:`V`,base:V.ELECTRIC_POTENTIAL,prefixes:z.SHORT,value:1,offset:0},ohm:{name:`ohm`,base:V.ELECTRIC_RESISTANCE,prefixes:z.SHORTLONG,value:1,offset:0},henry:{name:`henry`,base:V.ELECTRIC_INDUCTANCE,prefixes:z.LONG,value:1,offset:0},H:{name:`H`,base:V.ELECTRIC_INDUCTANCE,prefixes:z.SHORT,value:1,offset:0},siemens:{name:`siemens`,base:V.ELECTRIC_CONDUCTANCE,prefixes:z.LONG,value:1,offset:0},S:{name:`S`,base:V.ELECTRIC_CONDUCTANCE,prefixes:z.SHORT,value:1,offset:0},weber:{name:`weber`,base:V.MAGNETIC_FLUX,prefixes:z.LONG,value:1,offset:0},Wb:{name:`Wb`,base:V.MAGNETIC_FLUX,prefixes:z.SHORT,value:1,offset:0},tesla:{name:`tesla`,base:V.MAGNETIC_FLUX_DENSITY,prefixes:z.LONG,value:1,offset:0},T:{name:`T`,base:V.MAGNETIC_FLUX_DENSITY,prefixes:z.SHORT,value:1,offset:0},b:{name:`b`,base:V.BIT,prefixes:z.BINARY_SHORT,value:1,offset:0},bits:{name:`bits`,base:V.BIT,prefixes:z.BINARY_LONG,value:1,offset:0},B:{name:`B`,base:V.BIT,prefixes:z.BINARY_SHORT,value:8,offset:0},bytes:{name:`bytes`,base:V.BIT,prefixes:z.BINARY_LONG,value:8,offset:0}},ne={meters:`meter`,inches:`inch`,feet:`foot`,yards:`yard`,miles:`mile`,links:`link`,rods:`rod`,chains:`chain`,angstroms:`angstrom`,lt:`l`,litres:`litre`,liter:`litre`,liters:`litre`,teaspoons:`teaspoon`,tablespoons:`tablespoon`,minims:`minim`,fldr:`fluiddram`,fluiddrams:`fluiddram`,floz:`fluidounce`,fluidounces:`fluidounce`,gi:`gill`,gills:`gill`,cp:`cup`,cups:`cup`,pt:`pint`,pints:`pint`,qt:`quart`,quarts:`quart`,gal:`gallon`,gallons:`gallon`,bbl:`beerbarrel`,beerbarrels:`beerbarrel`,obl:`oilbarrel`,oilbarrels:`oilbarrel`,hogsheads:`hogshead`,gtts:`gtt`,grams:`gram`,tons:`ton`,tonnes:`tonne`,grains:`grain`,drams:`dram`,ounces:`ounce`,poundmasses:`poundmass`,hundredweights:`hundredweight`,sticks:`stick`,lb:`lbm`,lbs:`lbm`,kips:`kip`,kgf:`kilogramforce`,acres:`acre`,hectares:`hectare`,sqfeet:`sqft`,sqyard:`sqyd`,sqmile:`sqmi`,sqmiles:`sqmi`,mmhg:`mmHg`,mmh2o:`mmH2O`,cmh2o:`cmH2O`,seconds:`second`,secs:`second`,minutes:`minute`,mins:`minute`,hours:`hour`,hr:`hour`,hrs:`hour`,days:`day`,weeks:`week`,months:`month`,years:`year`,decades:`decade`,centuries:`century`,millennia:`millennium`,hertz:`hertz`,radians:`radian`,degrees:`degree`,gradians:`gradian`,cycles:`cycle`,arcsecond:`arcsec`,arcseconds:`arcsec`,arcminute:`arcmin`,arcminutes:`arcmin`,BTUs:`BTU`,watts:`watt`,joules:`joule`,amperes:`ampere`,amps:`ampere`,amp:`ampere`,coulombs:`coulomb`,volts:`volt`,ohms:`ohm`,farads:`farad`,webers:`weber`,teslas:`tesla`,electronvolts:`electronvolt`,moles:`mole`,bit:`bits`,byte:`bytes`};function re(e){if(e.number===`BigNumber`){var t=g_(g);H.rad.value=new g(1),H.deg.value=t.div(180),H.grad.value=t.div(200),H.cycle.value=t.times(2),H.arcsec.value=t.div(648e3),H.arcmin.value=t.div(10800)}else H.rad.value=1,H.deg.value=Math.PI/180,H.grad.value=Math.PI/200,H.cycle.value=Math.PI*2,H.arcsec.value=Math.PI/648e3,H.arcmin.value=Math.PI/10800;H.radian.value=H.rad.value,H.degree.value=H.deg.value,H.gradian.value=H.grad.value}re(n),t&&t(`config`,function(e,t){e.number!==t.number&&re(e)});var ie={si:{NONE:{unit:te,prefix:z.NONE[``]},LENGTH:{unit:H.m,prefix:z.SHORT[``]},MASS:{unit:H.g,prefix:z.SHORT.k},TIME:{unit:H.s,prefix:z.SHORT[``]},CURRENT:{unit:H.A,prefix:z.SHORT[``]},TEMPERATURE:{unit:H.K,prefix:z.SHORT[``]},LUMINOUS_INTENSITY:{unit:H.cd,prefix:z.SHORT[``]},AMOUNT_OF_SUBSTANCE:{unit:H.mol,prefix:z.SHORT[``]},ANGLE:{unit:H.rad,prefix:z.SHORT[``]},BIT:{unit:H.bits,prefix:z.SHORT[``]},FORCE:{unit:H.N,prefix:z.SHORT[``]},ENERGY:{unit:H.J,prefix:z.SHORT[``]},POWER:{unit:H.W,prefix:z.SHORT[``]},PRESSURE:{unit:H.Pa,prefix:z.SHORT[``]},ELECTRIC_CHARGE:{unit:H.C,prefix:z.SHORT[``]},ELECTRIC_CAPACITANCE:{unit:H.F,prefix:z.SHORT[``]},ELECTRIC_POTENTIAL:{unit:H.V,prefix:z.SHORT[``]},ELECTRIC_RESISTANCE:{unit:H.ohm,prefix:z.SHORT[``]},ELECTRIC_INDUCTANCE:{unit:H.H,prefix:z.SHORT[``]},ELECTRIC_CONDUCTANCE:{unit:H.S,prefix:z.SHORT[``]},MAGNETIC_FLUX:{unit:H.Wb,prefix:z.SHORT[``]},MAGNETIC_FLUX_DENSITY:{unit:H.T,prefix:z.SHORT[``]},FREQUENCY:{unit:H.Hz,prefix:z.SHORT[``]}}};ie.cgs=JSON.parse(JSON.stringify(ie.si)),ie.cgs.LENGTH={unit:H.m,prefix:z.SHORT.c},ie.cgs.MASS={unit:H.g,prefix:z.SHORT[``]},ie.cgs.FORCE={unit:H.dyn,prefix:z.SHORT[``]},ie.cgs.ENERGY={unit:H.erg,prefix:z.NONE[``]},ie.us=JSON.parse(JSON.stringify(ie.si)),ie.us.LENGTH={unit:H.ft,prefix:z.NONE[``]},ie.us.MASS={unit:H.lbm,prefix:z.NONE[``]},ie.us.TEMPERATURE={unit:H.degF,prefix:z.NONE[``]},ie.us.FORCE={unit:H.lbf,prefix:z.NONE[``]},ie.us.ENERGY={unit:H.BTU,prefix:z.BTU[``]},ie.us.POWER={unit:H.hp,prefix:z.NONE[``]},ie.us.PRESSURE={unit:H.psi,prefix:z.NONE[``]},ie.auto=JSON.parse(JSON.stringify(ie.si));var U=ie.auto;for(var ae in x.setUnitSystem=function(e){if(Ti(ie,e))U=ie[e];else throw Error(`Unit system `+e+` does not exist. Choices are: `+Object.keys(ie).join(`, `))},x.getUnitSystem=function(){for(var e in ie)if(Ti(ie,e)&&ie[e]===U)return e},x.typeConverters={BigNumber:function(e){return e!=null&&e.isFraction?new g(String(e.n)).div(String(e.d)).times(String(e.s)):new g(e+``)},Fraction:function(e){return new _(e)},Complex:function(e){return e},number:function(e){return e!=null&&e.isFraction?m(e):e}},x.prototype._numberConverter=function(){var e=x.typeConverters[this.valueType()];if(e)return e;throw TypeError(`Unsupported Unit value type "`+this.valueType()+`"`)},x._getNumberConverter=function(e){if(!x.typeConverters[e])throw TypeError(`Unsupported type "`+e+`"`);return x.typeConverters[e]},H)if(Ti(H,ae)){var oe=H[ae];oe.dimensions=oe.base.dimensions}for(var se in ne)if(Ti(ne,se)){var ce=H[ne[se]],le={};for(var ue in ce)Ti(ce,ue)&&(le[ue]=ce[ue]);le.name=se,H[se]=le}x.isValidAlpha=function(e){return/^[a-zA-Z]$/.test(e)};function de(e){for(var t=0;t<e.length;t++){if(w=e.charAt(t),t===0&&!x.isValidAlpha(w))throw Error(`Invalid unit name (must begin with alpha character): "`+e+`"`);if(t>0&&!(x.isValidAlpha(w)||D(w)))throw Error(`Invalid unit name (only alphanumeric characters are allowed): "`+e+`"`)}}return x.createUnit=function(e,t){if(typeof e!=`object`)throw TypeError(`createUnit expects first parameter to be of type 'Object'`);if(t&&t.override){for(var n in e)if(Ti(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)Ti(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(Ti(H,e))throw Error(`Cannot create unit "`+e+`": a unit with that name already exists`);de(e);var n=null,r=[],i=0,a,o,s;if(t&&t.type===`Unit`)n=t.clone();else if(typeof t==`string`)t!==``&&(a=t);else if(typeof t==`object`)a=t.definition,o=t.prefixes,i=t.offset,s=t.baseName,t.aliases&&(r=t.aliases.valueOf());else throw TypeError(`Cannot create unit "`+e+`" from "`+t.toString()+`": expecting "string" or "Unit" or "Object"`);if(r){for(var c=0;c<r.length;c++)if(Ti(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(Ti(V,d)){for(var f=!0,p=0;p<B.length;p++)if(Math.abs((l.dimensions[p]||0)-(V[d].dimensions[p]||0))>1e-12){f=!1;break}if(f){u=!0,l.base=V[d];break}}if(!u){s||=e+`_STUFF`;var m={dimensions:n.dimensions.slice(0)};m.key=s,V[s]=m,U[s]={unit:l,prefix:z.NONE[``]},l.base=V[s]}}else{if(s||=e+`_STUFF`,B.indexOf(s)>=0)throw Error(`Cannot create new base unit "`+e+`": a base unit with that name already exists (and cannot be overridden)`);for(var h in B.push(s),V)Ti(V,h)&&(V[h].dimensions[B.length-1]=0);for(var g={dimensions:[]},_=0;_<B.length;_++)g.dimensions[_]=0;g.dimensions[B.length-1]=1,g.key=s,V[s]=g,l={name:e,value:1,dimensions:V[s].dimensions.slice(0),prefixes:o,offset:i,base:V[s]},U[s]={unit:l,prefix:z.NONE[``]}}x.UNITS[e]=l;for(var v=0;v<r.length;v++){var y=r[v],b={};for(var S in l)Ti(l,S)&&(b[S]=l[S]);b.name=y,x.UNITS[y]=b}return delete N.cache,new x(null,e)},x.deleteUnit=function(e){delete x.UNITS[e],delete N.cache},x.PREFIXES=z,x.BASE_DIMENSIONS=B,x.BASE_UNITS=V,x.UNIT_SYSTEMS=ie,x.UNITS=H,x},{isClass:!0}),S_=`unit`,C_=J(S_,[`typed`,`Unit`],e=>{var{typed:t,Unit:n}=e;return t(S_,{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=>Qc(t,e))})}),w_=`sparse`,T_=J(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)}})}),E_=`createUnit`,D_=J(E_,[`typed`,`Unit`],e=>{var{typed:t,Unit:n}=e;return t(E_,{"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,{})}})}),O_=`acos`,k_=J(O_,[`typed`,`config`,`Complex`],e=>{var{typed:t,config:n,Complex:r}=e;return t(O_,{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()}})}),A_=`acosh`,j_=J(A_,[`typed`,`config`,`Complex`],e=>{var{typed:t,config:n,Complex:r}=e;return t(A_,{number:function(e){return e>=1||n.predictable?cu(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()}})}),M_=`acot`,N_=J(M_,[`typed`,`BigNumber`],e=>{var{typed:t,BigNumber:n}=e;return t(M_,{number:lu,Complex:function(e){return e.acot()},BigNumber:function(e){return new n(1).div(e).atan()}})}),P_=`acoth`,F_=J(P_,[`typed`,`config`,`Complex`,`BigNumber`],e=>{var{typed:t,config:n,Complex:r,BigNumber:i}=e;return t(P_,{number:function(e){return e>=1||e<=-1||n.predictable?uu(e):new r(e,0).acoth()},Complex:function(e){return e.acoth()},BigNumber:function(e){return new i(1).div(e).atanh()}})}),I_=`acsc`,L_=J(I_,[`typed`,`config`,`Complex`,`BigNumber`],e=>{var{typed:t,config:n,Complex:r,BigNumber:i}=e;return t(I_,{number:function(e){return e<=-1||e>=1||n.predictable?du(e):new r(e,0).acsc()},Complex:function(e){return e.acsc()},BigNumber:function(e){return new i(1).div(e).asin()}})}),R_=`acsch`,z_=J(R_,[`typed`,`BigNumber`],e=>{var{typed:t,BigNumber:n}=e;return t(R_,{number:fu,Complex:function(e){return e.acsch()},BigNumber:function(e){return new n(1).div(e).asinh()}})}),B_=`asec`,V_=J(B_,[`typed`,`config`,`Complex`,`BigNumber`],e=>{var{typed:t,config:n,Complex:r,BigNumber:i}=e;return t(B_,{number:function(e){return e<=-1||e>=1||n.predictable?pu(e):new r(e,0).asec()},Complex:function(e){return e.asec()},BigNumber:function(e){return new i(1).div(e).acos()}})}),H_=`asech`,U_=J(H_,[`typed`,`config`,`Complex`,`BigNumber`],e=>{var{typed:t,config:n,Complex:r,BigNumber:i}=e;return t(H_,{number:function(e){if(e<=1&&e>=-1||n.predictable){var t=1/e;if(t>0||n.predictable)return mu(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()}})}),W_=`asin`,G_=J(W_,[`typed`,`config`,`Complex`],e=>{var{typed:t,config:n,Complex:r}=e;return t(W_,{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()}})}),K_=J(`asinh`,[`typed`],e=>{var{typed:t}=e;return t(`asinh`,{number:gu,Complex:function(e){return e.asinh()},BigNumber:function(e){return e.asinh()}})}),q_=J(`atan`,[`typed`],e=>{var{typed:t}=e;return t(`atan`,{number:function(e){return Math.atan(e)},Complex:function(e){return e.atan()},BigNumber:function(e){return e.atan()}})}),J_=`atan2`,Y_=J(J_,[`typed`,`matrix`,`equalScalar`,`BigNumber`,`DenseMatrix`,`concat`],e=>{var{typed:t,matrix:n,equalScalar:r,BigNumber:i,DenseMatrix:a,concat:o}=e,s=_f({typed:t,equalScalar:r}),c=vf({typed:t}),l=cp({typed:t,equalScalar:r}),u=qd({typed:t,equalScalar:r}),d=Jd({typed:t,DenseMatrix:a}),f=Cf({typed:t,matrix:n,concat:o});return t(J_,{"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}))}),X_=`atanh`,Z_=J(X_,[`typed`,`config`,`Complex`],e=>{var{typed:t,config:n,Complex:r}=e;return t(X_,{number:function(e){return e<=1&&e>=-1||n.predictable?yu(e):new r(e,0).atanh()},Complex:function(e){return e.atanh()},BigNumber:function(e){return e.atanh()}})}),Q_=J(`trigUnit`,[`typed`],e=>{var{typed:t}=e;return{Unit:t.referToSelf(e=>n=>{if(!n.hasBase(n.constructor.BASE_UNITS.ANGLE))throw TypeError(`Unit in function cot is no angle`);return t.find(e,n.valueType())(n.value)})}}),$_=`cos`,ev=J($_,[`typed`],e=>{var{typed:t}=e,n=Q_({typed:t});return t($_,{number:Math.cos,"Complex | BigNumber":e=>e.cos()},n)}),tv=`cosh`,nv=J(tv,[`typed`],e=>{var{typed:t}=e;return t(tv,{number:oa,"Complex | BigNumber":e=>e.cosh()})}),rv=`cot`,iv=J(rv,[`typed`,`BigNumber`],e=>{var{typed:t,BigNumber:n}=e,r=Q_({typed:t});return t(rv,{number:Su,Complex:e=>e.cot(),BigNumber:e=>new n(1).div(e.tan())},r)}),av=`coth`,ov=J(av,[`typed`,`BigNumber`],e=>{var{typed:t,BigNumber:n}=e;return t(av,{number:Cu,Complex:e=>e.coth(),BigNumber:e=>new n(1).div(e.tanh())})}),sv=`csc`,cv=J(sv,[`typed`,`BigNumber`],e=>{var{typed:t,BigNumber:n}=e,r=Q_({typed:t});return t(sv,{number:wu,Complex:e=>e.csc(),BigNumber:e=>new n(1).div(e.sin())},r)}),lv=`csch`,uv=J(lv,[`typed`,`BigNumber`],e=>{var{typed:t,BigNumber:n}=e;return t(lv,{number:Tu,Complex:e=>e.csch(),BigNumber:e=>new n(1).div(e.sinh())})}),dv=`sec`,fv=J(dv,[`typed`,`BigNumber`],e=>{var{typed:t,BigNumber:n}=e,r=Q_({typed:t});return t(dv,{number:Eu,Complex:e=>e.sec(),BigNumber:e=>new n(1).div(e.cos())},r)}),pv=`sech`,mv=J(pv,[`typed`,`BigNumber`],e=>{var{typed:t,BigNumber:n}=e;return t(pv,{number:Du,Complex:e=>e.sech(),BigNumber:e=>new n(1).div(e.cosh())})}),hv=`sin`,gv=J(hv,[`typed`],e=>{var{typed:t}=e,n=Q_({typed:t});return t(hv,{number:Math.sin,"Complex | BigNumber":e=>e.sin()},n)}),_v=`sinh`,vv=J(_v,[`typed`],e=>{var{typed:t}=e;return t(_v,{number:ku,"Complex | BigNumber":e=>e.sinh()})}),yv=`tan`,bv=J(yv,[`typed`],e=>{var{typed:t}=e,n=Q_({typed:t});return t(yv,{number:Math.tan,"Complex | BigNumber":e=>e.tan()},n)}),xv=J(`tanh`,[`typed`],e=>{var{typed:t}=e;return t(`tanh`,{number:ca,"Complex | BigNumber":e=>e.tanh()})}),Sv=`setCartesian`,Cv=J(Sv,[`typed`,`size`,`subset`,`compareNatural`,`Index`,`DenseMatrix`],e=>{var{typed:t,size:n,subset:r,compareNatural:i,Index:a,DenseMatrix:o}=e;return t(Sv,{"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=xc(Array.isArray(e)?e:e.toArray()).sort(i),l=xc(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)}})}),wv=`setDifference`,Tv=J(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, 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 xc(e.toArray());else{var c=Dc(xc(Array.isArray(e)?e:e.toArray()).sort(i)),l=Dc(xc(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)?Oc(s):new o(Oc(s))}})}),Ev=`setDistinct`,Dv=J(Ev,[`typed`,`size`,`subset`,`compareNatural`,`Index`,`DenseMatrix`],e=>{var{typed:t,size:n,subset:r,compareNatural:i,Index:a,DenseMatrix:o}=e;return t(Ev,{"Array | Matrix":function(e){var t;if(r(n(e),new a(0))===0)t=[];else{var s=xc(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)}})}),Ov=`setIntersect`,kv=J(Ov,[`typed`,`size`,`subset`,`compareNatural`,`Index`,`DenseMatrix`],e=>{var{typed:t,size:n,subset:r,compareNatural:i,Index:a,DenseMatrix:o}=e;return t(Ov,{"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=Dc(xc(Array.isArray(e)?e:e.toArray()).sort(i)),l=Dc(xc(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)?Oc(s):new o(Oc(s))}})}),Av=`setIsSubset`,jv=J(Av,[`typed`,`size`,`subset`,`compareNatural`,`Index`],e=>{var{typed:t,size:n,subset:r,compareNatural:i,Index:a}=e;return t(Av,{"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=Dc(xc(Array.isArray(e)?e:e.toArray()).sort(i)),s=Dc(xc(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}})}),Mv=`setMultiplicity`,Nv=J(Mv,[`typed`,`size`,`subset`,`compareNatural`,`Index`],e=>{var{typed:t,size:n,subset:r,compareNatural:i,Index:a}=e;return t(Mv,{"number | BigNumber | Fraction | Complex, Array | Matrix":function(e,t){if(r(n(t),new a(0))===0)return 0;for(var o=xc(Array.isArray(t)?t:t.toArray()),s=0,c=0;c<o.length;c++)i(o[c],e)===0&&s++;return s}})}),Pv=`setPowerset`,Fv=J(Pv,[`typed`,`size`,`subset`,`compareNatural`,`Index`],e=>{var{typed:t,size:n,subset:r,compareNatural:i,Index:a}=e;return t(Pv,{"Array | Matrix":function(e){if(r(n(e),new a(0))===0)return[];for(var t=xc(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}}),Iv=`setSize`,Lv=J(Iv,[`typed`,`compareNatural`],e=>{var{typed:t,compareNatural:n}=e;return t(Iv,{"Array | Matrix":function(e){return Array.isArray(e)?xc(e).length:xc(e.toArray()).length},"Array | Matrix, boolean":function(e,t){if(t===!1||e.length===0)return Array.isArray(e)?xc(e).length:xc(e.toArray()).length;for(var r=xc(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}})}),Rv=`setSymDifference`,zv=J(Rv,[`typed`,`size`,`concat`,`subset`,`setDifference`,`Index`],e=>{var{typed:t,size:n,concat:r,subset:i,setDifference:a,Index:o}=e;return t(Rv,{"Array | Matrix, Array | Matrix":function(e,t){if(i(n(e),new o(0))===0)return xc(t);if(i(n(t),new o(0))===0)return xc(e);var s=xc(e),c=xc(t);return r(a(s,c),a(c,s))}})}),Bv=`setUnion`,Vv=J(Bv,[`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(Bv,{"Array | Matrix, Array | Matrix":function(e,t){if(i(n(e),new s(0))===0)return xc(t);if(i(n(t),new s(0))===0)return xc(e);var c=xc(e),l=xc(t);return r(o(c,l),a(c,l))}})}),Hv=`add`,Uv=J(Hv,[`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=Ef({typed:t}),l=Df({typed:t,equalScalar:i}),u=Of({typed:t,DenseMatrix:a}),d=Cf({typed:t,matrix:n,concat:s});return t(Hv,{"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}))}),Wv=`hypot`,Gv=J(Wv,[`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(Wv,{"... number | BigNumber":l,Array:l,Matrix:e=>l(xc(e.toArray(),!0))});function l(e){for(var t=0,l=0,u=0;u<e.length;u++){if(kr(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))}}),Kv=`norm`,qv=J(Kv,[`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(Kv,{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`)}}}),Jv=`dot`,Yv=J(Jv,[`typed`,`addScalar`,`multiplyScalar`,`conj`,`size`],e=>{var{typed:t,addScalar:n,multiplyScalar:r,conj:i,size:a}=e;return t(Jv,{"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=Pr(e)?e._data:e,u=Pr(e)?e._datatype||e.getDataType():void 0,d=Pr(s)?s._data:s,f=Pr(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}}),Xv=J(`trace`,[`typed`,`matrix`,`add`],e=>{var{typed:t,matrix:n,add:r}=e;return t(`trace`,{Array:function(e){return i(n(e))},SparseMatrix:a,DenseMatrix:i,any:_i});function i(e){var t=e._size,n=e._data;switch(t.length){case 1:if(t[0]===1)return _i(n[0]);throw RangeError(`Matrix must be square (size: `+Ys(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: `+Ys(t)+`)`);default:throw RangeError(`Matrix must be two dimensional (size: `+Ys(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: `+Ys(a)+`)`)}}),Zv=`index`,Qv=J(Zv,[`typed`,`Index`],e=>{var{typed:t,Index:n}=e;return t(Zv,{"...number | string | BigNumber | Range | Array | Matrix":function(e){var t=e.map(function(e){return Dr(e)?e.toNumber():Nr(e)||Pr(e)?e.map(function(e){return Dr(e)?e.toNumber():e}):e}),r=new n;return n.apply(r,t),r}})}),$v=new Set([`end`]),ey=J(`Node`,[`mathWithTransform`],e=>{var{mathWithTransform:t}=e;function n(e){for(var t of[...$v])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(!ci(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&&xi(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 ty(e){return e&&e.isIndexError?new ic(e.index+1,e.min+1,e.max===void 0?void 0:e.max+1):e}function ny(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 dr(e,n.getObjectProperty())}else throw TypeError(`Cannot apply index: unsupported type of object`)}catch(e){throw ty(e)}}}var ry=`AccessorNode`,iy=J(ry,[`subset`,`Node`],e=>{var{subset:t,Node:n}=e,r=ny({subset:t});function i(e){return!(Qr(e)||$r(e)||ri(e)||oi(e)||li(e)||di(e)||mi(e))}class a extends n{constructor(e,t){var n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:!1;if(super(),!ci(e))throw TypeError(`Node expected for parameter "object"`);if(!si(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 ry}get isAccessorNode(){return!0}_compile(e,t){var n=this.object._compile(e,t),i=this.index._compile(e,t),a=this.optionalChaining,o=Qr(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 dr(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:ry,object:this.object,index:this.index,optionalChaining:this.optionalChaining}}static fromJSON(e){return new a(e.object,e.index,e.optionalChaining)}}return th(a,`name`,ry),a},{isClass:!0,isNode:!0}),ay=`ArrayNode`,oy=J(ay,[`Node`],e=>{var{Node:t}=e;class n extends t{constructor(e){if(super(),this.items=e||[],!Array.isArray(this.items)||!this.items.every(ci))throw TypeError(`Array containing Nodes expected`)}get type(){return ay}get isArrayNode(){return!0}_compile(e,t){var n=Sc(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(Sc(n,function(n){return n(e,t,i)}))}}else return function(e,t,r){return Sc(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:ay,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($r)&&!n.every($r),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 th(n,`name`,ay),n},{isClass:!0,isNode:!0});function sy(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 fr(e,r.getObjectProperty(),i),e}else throw TypeError(`Cannot apply index: unsupported type of object`)}catch(e){throw ty(e)}}}var cy=[{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 ly(e,t){if(!t||t!==`auto`)return e;for(var n=e;di(n);)n=n.content;return n}function uy(e,t,n,r){var i=e;t!==`keep`&&(i=e.getContent());for(var a=i.getIdentifier(),o=null,s=0;s<cy.length;s++)if(a in cy[s]){o=s;break}if(a===`OperatorNode:multiply`&&i.implicit&&n!==`show`){var c=ly(i.args[0],t);!(ri(c)&&r&&r.getIdentifier()===`OperatorNode:divide`&&ii(ly(r.args[0],t)))&&!(c.getIdentifier()===`OperatorNode:divide`&&ii(ly(c.args[0],t))&&ri(ly(c.args[1])))&&(o+=1)}return o}function dy(e,t){var n=e;t!==`keep`&&(n=e.getContent());var r=n.getIdentifier(),i=uy(n,t);if(i===null)return null;var a=cy[i][r];if(Ti(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 fy(e,t,n){var r=n===`keep`?e:e.getContent(),i=n===`keep`?t:e.getContent(),a=r.getIdentifier(),o=i.getIdentifier(),s=uy(r,n);if(s===null)return null;var c=cy[s][a];if(Ti(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 py(e){var t=`OperatorNode:`+e;for(var n of cy)if(t in n)return n[t].op;return null}var my=`AssignmentNode`,hy=J(my,[`subset`,`?matrix`,`Node`],e=>{var{subset:t,matrix:n,Node:r}=e,i=ny({subset:t}),a=sy({subset:t,matrix:n});function o(e,t,n){t||=`keep`;var r=uy(e,t,n),i=uy(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,!mi(e)&&!Qr(e))throw TypeError(`SymbolNode or AccessorNode expected as "object"`);if(mi(e)&&e.name===`end`)throw Error(`Cannot assign to symbol "end"`);if(this.index&&!si(this.index))throw TypeError(`IndexNode expected as "index"`);if(!ci(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(!mi(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 fr(i,c,a),a}}else if(mi(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=dr(i,u),c=r(e,t,s),d=o(e,t,n);return fr(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 th(s,`name`,my),s},{isClass:!0,isNode:!0}),gy=`BlockNode`,_y=J(gy,[`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(!ci(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 gy}get isBlockNode(){return!0}_compile(e,n){var r=Sc(this.blocks,function(t){return{evaluate:t.node._compile(e,n),visible:t.visible}});return function(e,n,i){var a=[];return Cc(r,function(t){var r=t.evaluate(e,n,i);t.visible&&a.push(r)}),new t(a)}}forEach(e){for(var t=0;t<this.blocks.length;t++)e(this.blocks[t].node,`blocks[`+t+`].node`,this)}map(e){for(var t=[],n=0;n<this.blocks.length;n++){var i=this.blocks[n];t[n]={node:this._ifNode(e(i.node,`blocks[`+n+`].node`,this)),visible:i.visible}}return new r(t)}clone(){return new r(this.blocks.map(function(e){return{node:e.node,visible:e.visible}}))}_toString(e){return this.blocks.map(function(t){return t.node.toString(e)+(t.visible?``:`;`)}).join(`
@@ -67,7 +67,7 @@ In case of a (multi dimensional) array or matrix, the prob order quantile of all
67
67
  return false;
68
68
  }`),e.length!==n.length&&(t=`if (x !== x) return false;\n${t}`),Function(`x`,`${t}\nreturn true;`)}function XM(e){return typeof e==`bigint`?`${AO(e)}n`:AO(e)}function ZM(e,t){let n=Math.ceil(e)*t-1;return(n-n%64+64||64)/t}function QM(e,t=0){return e.length>=t?e.subarray(0,t):pD(new e.constructor(t),e,0)}var $M=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(ZM(r===0?n*1:n*2,this.BYTES_PER_ELEMENT))}return this}flush(e=this.length){e=ZM(e*this.stride,this.BYTES_PER_ELEMENT);let t=QM(this.buffer,e);return this.clear(),t}clear(){return this.length=0,this.buffer=new this.ArrayType,this}_resize(e){return this.buffer=QM(this.buffer,e)}},eN=class extends $M{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}},tN=class extends eN{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()}},nN=class extends eN{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)}},rN=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=qk(e),this._nulls=new tN,t&&t.length>0&&(this._isValid=YM(t))}toVector(){return new GM([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(),xM({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}};rN.prototype.length=1,rN.prototype.stride=1,rN.prototype.children=null,rN.prototype.finished=!1,rN.prototype.nullValues=null,rN.prototype._isValid=()=>!0;var iN=class extends rN{constructor(e){super(e),this._values=new eN(this.ArrayType,0,this.stride)}setValue(e,t){let n=this._values;return n.reserve(e-n.length+1),super.setValue(e,t)}},aN=class extends rN{constructor(e){super(e),this._pendingLength=0,this._offsets=new nN(e.type)}setValue(e,t){let n=this._pending||=new Map,r=n.get(e);r&&(this._pendingLength-=r.length),this._pendingLength+=t instanceof Yj?t[Gj].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}},oN=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()}},sN=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):PD.V1}schema(e){let t=this.bb.__offset(this.bb_pos,6);return t?(e||new EO).__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 oN).__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 oN).__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 iO).__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,PD.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)}},cN=class e{constructor(e=[],t,n,r=PD.V5){this.fields=e||[],this.metadata=t||new Map,n||=dN(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=uN(uN(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:uN(uN(new Map,r[t].metadata),e.metadata)}))&&!1:!0}),o=dN(a,new Map);return new e([...r,...a],i,new Map([...this.dictionaries,...o]))}};cN.prototype.fields=null,cN.prototype.metadata=null,cN.prototype.dictionaries=null;var lN=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)}};lN.prototype.type=null,lN.prototype.name=null,lN.prototype.nullable=null,lN.prototype.metadata=null;function uN(e,t){return new Map([...e||new Map,...t||new Map])}function dN(e,t=new Map){for(let n=-1,r=e.length;++n<r;){let r=e[n].type;if(fk.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&&dN(r.children,t)}return t}var fN=KD,pN=GD,mN=class{static decode(e){e=new pN(vD(e));let t=sN.getRootAsFooter(e);return new hN(cN.decode(t.schema(),new Map,t.version()),t)}static encode(e){let t=new fN,n=cN.encode(t,e.schema);sN.startRecordBatchesVector(t,e.numRecordBatches);for(let n of[...e.recordBatches()].slice().reverse())gN.encode(t,n);let r=t.endVector();sN.startDictionariesVector(t,e.numDictionaries);for(let n of[...e.dictionaryBatches()].slice().reverse())gN.encode(t,n);let i=t.endVector();return sN.startFooter(t),sN.addSchema(t,n),sN.addVersion(t,PD.V5),sN.addRecordBatches(t,r),sN.addDictionaries(t,i),sN.finishFooterBuffer(t,sN.endFooter(t)),t.asUint8Array()}get numRecordBatches(){return this._recordBatches.length}get numDictionaries(){return this._dictionaryBatches.length}constructor(e,t=PD.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}},hN=class extends mN{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 gN.decode(t)}return null}getDictionaryBatch(e){if(e>=0&&e<this.numDictionaries){let t=this._footer.dictionaries(e);if(t)return gN.decode(t)}return null}},gN=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 oN.createBlock(e,r,n,i)}constructor(e,t,n){this.metaDataLength=e,this.offset=jO(n),this.bodyLength=jO(t)}},_N=Object.freeze({done:!0,value:void 0}),vN=class{constructor(e){this._json=e}get schema(){return this._json.schema}get batches(){return this._json.batches||[]}get dictionaries(){return this._json.dictionaries||[]}},yN=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()}},bN=class extends yN{constructor(){super(),this._values=[],this.resolvers=[],this._closedPromise=new Promise(e=>this._closedPromiseResolve=e)}get closed(){return this._closedPromise}cancel(e){return RE(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(_N);this._closedPromiseResolve(),this._closedPromiseResolve=void 0}}[Symbol.asyncIterator](){return this}toDOMStream(e){return ED.toDOMStream(this._closedPromiseResolve||this._error?this:this._values,e)}toNodeStream(e){return ED.toNodeStream(this._closedPromiseResolve||this._error?this:this._values,e)}throw(e){return RE(this,void 0,void 0,function*(){return yield this.abort(e),_N})}return(e){return RE(this,void 0,void 0,function*(){return yield this.close(),_N})}read(e){return RE(this,void 0,void 0,function*(){return(yield this.next(e,`read`)).value})}peek(e){return RE(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(_N)}_ensureOpen(){if(this._closedPromiseResolve)return!0;throw Error(`AsyncQueue is closed`)}},xN=class extends bN{write(e){if((e=vD(e)).byteLength>0)return super.write(e)}toString(e=!1){return e?GE(this.toUint8Array(!0)):this.toUint8Array(!1).then(GE)}toUint8Array(e=!1){return e?mD(this._values)[0]:RE(this,void 0,void 0,function*(){var e,t,n,r;let i=[],a=0;try{for(var o=!0,s=UE(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 mD(i,a)[0]})}},SN=class{constructor(e){e&&(this.source=new wN(ED.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)}},CN=class e{constructor(t){t instanceof e?this.source=t.source:t instanceof xN?this.source=new TN(ED.fromAsyncIterable(t)):lD(t)?this.source=new TN(ED.fromNodeStream(t)):sD(t)?this.source=new TN(ED.fromDOMStream(t)):iD(t)?this.source=new TN(ED.fromDOMStream(t.body)):$E(t)?this.source=new TN(ED.fromIterable(t)):(QE(t)||eD(t))&&(this.source=new TN(ED.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)}},wN=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)||_N)}return(e){return Object.create(this.source.return&&this.source.return(e)||_N)}},TN=class{constructor(e){this.source=e,this._closedPromise=new Promise(e=>this._closedPromiseResolve=e)}cancel(e){return RE(this,void 0,void 0,function*(){yield this.return(e)})}get closed(){return this._closedPromise}read(e){return RE(this,void 0,void 0,function*(){return(yield this.next(e,`read`)).value})}peek(e){return RE(this,void 0,void 0,function*(){return(yield this.next(e,`peek`)).value})}next(e){return RE(this,arguments,void 0,function*(e,t=`read`){return yield this.source.next({cmd:t,size:e})})}throw(e){return RE(this,void 0,void 0,function*(){let t=this.source.throw&&(yield this.source.throw(e))||_N;return this._closedPromiseResolve&&this._closedPromiseResolve(),this._closedPromiseResolve=void 0,Object.create(t)})}return(e){return RE(this,void 0,void 0,function*(){let t=this.source.return&&(yield this.source.return(e))||_N;return this._closedPromiseResolve&&this._closedPromiseResolve(),this._closedPromiseResolve=void 0,Object.create(t)})}},EN=class extends SN{constructor(e,t){super(),this.position=0,this.buffer=vD(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}}},DN=class extends CN{constructor(e,t){super(),this.position=0,this._handle=e,typeof t==`number`?this.size=t:this._pending=RE(this,void 0,void 0,function*(){this.size=(yield e.stat()).size,delete this._pending})}readInt32(e){return RE(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 RE(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 RE(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 RE(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 RE(this,void 0,void 0,function*(){let e=this._handle;this._handle=null,e&&(yield e.close())})}throw(e){return RE(this,void 0,void 0,function*(){return yield this.close(),{done:!0,value:e}})}return(e){return RE(this,void 0,void 0,function*(){return yield this.close(),{done:!0,value:e}})}},ON=65536;function kN(e){return e<0&&(e=4294967295+e+1),`0x${e.toString(16)}`}var AN=8,jN=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8],MN=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?ON: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`${kN(this.buffer[1])} ${kN(this.buffer[0])}`}},NN=class e extends MN{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=AN<r-n?AN:r-n,o=new e(new Uint32Array([Number.parseInt(t.slice(n,n+a),10),0])),s=new e(new Uint32Array([jN[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)}},PN=class e extends MN{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=AN<i-n?AN:i-n,o=new e(new Uint32Array([Number.parseInt(t.slice(n,n+r),10),0])),s=new e(new Uint32Array([jN[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)}},FN=class e{constructor(e){this.buffer=e}high(){return new PN(new Uint32Array(this.buffer.buffer,this.buffer.byteOffset+8,2))}low(){return new PN(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 NN(new Uint32Array([this.buffer[3],0])),n=new NN(new Uint32Array([this.buffer[2],0])),r=new NN(new Uint32Array([this.buffer[1],0])),i=new NN(new Uint32Array([this.buffer[0],0])),a=new NN(new Uint32Array([e.buffer[3],0])),o=new NN(new Uint32Array([e.buffer[2],0])),s=new NN(new Uint32Array([e.buffer[1],0])),c=new NN(new Uint32Array([e.buffer[0],0])),l=NN.multiply(i,c);this.buffer[0]=l.low();let u=new NN(new Uint32Array([l.high(),0]));return l=NN.multiply(r,c),u.plus(l),l=NN.multiply(i,s),u.plus(l),this.buffer[1]=u.low(),this.buffer[3]=+!!u.lessThan(l),this.buffer[2]=u.high(),new NN(new Uint32Array(this.buffer.buffer,this.buffer.byteOffset+8,2)).plus(NN.multiply(n,c)).plus(NN.multiply(r,s)).plus(NN.multiply(i,o)),this.buffer[3]+=NN.multiply(t,c).plus(NN.multiply(n,s)).plus(NN.multiply(r,o)).plus(NN.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`${kN(this.buffer[3])} ${kN(this.buffer[2])} ${kN(this.buffer[1])} ${kN(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=AN<i-n?AN:i-n,o=new e(new Uint32Array([Number.parseInt(t.slice(n,n+r),10),0,0,0])),s=new e(new Uint32Array([jN[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}},IN=class extends Jk{constructor(e,t,n,r,i=PD.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 lN?e.type:e)}visitNull(e,{length:t}=this.nextFieldNode()){return xM({type:e,length:t})}visitBool(e,{length:t,nullCount:n}=this.nextFieldNode()){return xM({type:e,length:t,nullCount:n,nullBitmap:this.readNullBitmap(e,n),data:this.readData(e)})}visitInt(e,{length:t,nullCount:n}=this.nextFieldNode()){return xM({type:e,length:t,nullCount:n,nullBitmap:this.readNullBitmap(e,n),data:this.readData(e)})}visitFloat(e,{length:t,nullCount:n}=this.nextFieldNode()){return xM({type:e,length:t,nullCount:n,nullBitmap:this.readNullBitmap(e,n),data:this.readData(e)})}visitUtf8(e,{length:t,nullCount:n}=this.nextFieldNode()){return xM({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 xM({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 xM({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 xM({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 xM({type:e,length:t,nullCount:n,nullBitmap:this.readNullBitmap(e,n),data:this.readData(e)})}visitDate(e,{length:t,nullCount:n}=this.nextFieldNode()){return xM({type:e,length:t,nullCount:n,nullBitmap:this.readNullBitmap(e,n),data:this.readData(e)})}visitTimestamp(e,{length:t,nullCount:n}=this.nextFieldNode()){return xM({type:e,length:t,nullCount:n,nullBitmap:this.readNullBitmap(e,n),data:this.readData(e)})}visitTime(e,{length:t,nullCount:n}=this.nextFieldNode()){return xM({type:e,length:t,nullCount:n,nullBitmap:this.readNullBitmap(e,n),data:this.readData(e)})}visitDecimal(e,{length:t,nullCount:n}=this.nextFieldNode()){return xM({type:e,length:t,nullCount:n,nullBitmap:this.readNullBitmap(e,n),data:this.readData(e)})}visitList(e,{length:t,nullCount:n}=this.nextFieldNode()){return xM({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 xM({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<PD.V5&&this.readNullBitmap(e,n),e.mode===FD.Sparse?this.visitSparseUnion(e,{length:t,nullCount:n}):this.visitDenseUnion(e,{length:t,nullCount:n})}visitDenseUnion(e,{length:t,nullCount:n}=this.nextFieldNode()){return xM({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 xM({type:e,length:t,nullCount:n,typeIds:this.readTypeIds(e),children:this.visitMany(e.children)})}visitDictionary(e,{length:t,nullCount:n}=this.nextFieldNode()){return xM({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 xM({type:e,length:t,nullCount:n,nullBitmap:this.readNullBitmap(e,n),data:this.readData(e)})}visitDuration(e,{length:t,nullCount:n}=this.nextFieldNode()){return xM({type:e,length:t,nullCount:n,nullBitmap:this.readNullBitmap(e,n),data:this.readData(e)})}visitFixedSizeList(e,{length:t,nullCount:n}=this.nextFieldNode()){return xM({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 xM({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)}},LN=class extends IN{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:mM(this.sources[n])}readOffsets(e,{offset:t}=this.nextBufferRange()){return hD(Uint8Array,hD(e.OffsetArrayType,this.sources[t]))}readTypeIds(e,{offset:t}=this.nextBufferRange()){return hD(Uint8Array,hD(e.ArrayType,this.sources[t]))}readData(e,{offset:t}=this.nextBufferRange()){let{sources:n}=this;return fk.isTimestamp(e)||(fk.isInt(e)||fk.isTime(e))&&e.bitWidth===64||fk.isDuration(e)||fk.isDate(e)&&e.unit===LD.MILLISECOND?hD(Uint8Array,PN.convertArray(n[t])):fk.isDecimal(e)?hD(Uint8Array,FN.convertArray(n[t])):fk.isBinary(e)||fk.isLargeBinary(e)||fk.isFixedSizeBinary(e)?RN(n[t]):fk.isBool(e)?mM(n[t]):fk.isUtf8(e)||fk.isLargeUtf8(e)?qE(n[t].join(``)):hD(Uint8Array,hD(e.ArrayType,n[t].map(e=>+e)))}};function RN(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 zN=class extends aN{constructor(e){super(e),this._values=new $M(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,vD(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}}},BN=class extends aN{constructor(e){super(e),this._values=new $M(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,vD(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}}},VN=class extends rN{constructor(e){super(e),this._values=new tN}setValue(e,t){this._values.set(e,+t)}},HN=class extends iN{};HN.prototype._setValue=gA;var UN=class extends HN{};UN.prototype._setValue=dA;var WN=class extends HN{};WN.prototype._setValue=fA;var GN=class extends iN{};GN.prototype._setValue=DA;var KN=class extends rN{constructor({type:e,nullValues:t,dictionaryHashFunction:n}){super({type:new Kk(e.dictionary,e.indices,e.id,e.isOrdered)}),this._nulls=null,this._dictionaryOffset=0,this._keysToIndices=Object.create(null),this.indices=nF({type:this.type.indices,nullValues:t}),this.dictionary=nF({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}`}},qN=class extends iN{};qN.prototype._setValue=pA;var JN=class extends rN{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 Uk(this.type.listSize,new lN(t,e.type,!0)),n}},YN=class extends iN{setValue(e,t){this._values.set(e,t)}},XN=class extends YN{setValue(e,t){super.setValue(e,tA(t))}},ZN=class extends YN{},QN=class extends YN{},$N=class extends iN{};$N.prototype._setValue=zA;var eP=class extends $N{};eP.prototype._setValue=BA;var tP=class extends $N{};tP.prototype._setValue=VA;var nP=class extends iN{};nP.prototype._setValue=KA;var rP=class extends nP{};rP.prototype._setValue=HA;var iP=class extends nP{};iP.prototype._setValue=UA;var aP=class extends nP{};aP.prototype._setValue=WA;var oP=class extends nP{};oP.prototype._setValue=GA;var sP=class extends iN{setValue(e,t){this._values.set(e,t)}},cP=class extends sP{},lP=class extends sP{},uP=class extends sP{},dP=class extends sP{},fP=class extends sP{},pP=class extends sP{},mP=class extends sP{},hP=class extends sP{},gP=class extends aN{constructor(e){super(e),this._offsets=new nN(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 zk(new lN(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])}}},_P=class extends aN{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 Wk(new lN(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}}},vP=class extends rN{setValue(e,t){}setValid(e,t){return this.length=Math.max(e+1,this.length),t}},yP=class extends rN{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 Bk([...this.type.children,new lN(t,e.type,!0)]),n}},bP=class extends iN{};bP.prototype._setValue=xA;var xP=class extends bP{};xP.prototype._setValue=_A;var SP=class extends bP{};SP.prototype._setValue=vA;var CP=class extends bP{};CP.prototype._setValue=yA;var wP=class extends bP{};wP.prototype._setValue=bA;var TP=class extends iN{};TP.prototype._setValue=EA;var EP=class extends TP{};EP.prototype._setValue=SA;var DP=class extends TP{};DP.prototype._setValue=CA;var OP=class extends TP{};OP.prototype._setValue=wA;var kP=class extends TP{};kP.prototype._setValue=TA;var AP=class extends rN{constructor(e){super(e),this._typeIds=new eN(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 lN(t,e.type)];return this.type=new Vk(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.")}},jP=class extends AP{},MP=class extends AP{constructor(e){super(e),this._offsets=new eN(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)}},NP=class extends aN{constructor(e){super(e),this._values=new $M(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,qE(t))}_flushPending(e,t){}};NP.prototype._flushPending=zN.prototype._flushPending;var PP=class extends aN{constructor(e){super(e),this._values=new $M(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,qE(t))}_flushPending(e,t){}};PP.prototype._flushPending=BN.prototype._flushPending;var FP=new class extends Jk{visitNull(){return vP}visitBool(){return VN}visitInt(){return sP}visitInt8(){return cP}visitInt16(){return lP}visitInt32(){return uP}visitInt64(){return dP}visitUint8(){return fP}visitUint16(){return pP}visitUint32(){return mP}visitUint64(){return hP}visitFloat(){return YN}visitFloat16(){return XN}visitFloat32(){return ZN}visitFloat64(){return QN}visitUtf8(){return NP}visitLargeUtf8(){return PP}visitBinary(){return zN}visitLargeBinary(){return BN}visitFixedSizeBinary(){return qN}visitDate(){return HN}visitDateDay(){return UN}visitDateMillisecond(){return WN}visitTimestamp(){return bP}visitTimestampSecond(){return xP}visitTimestampMillisecond(){return SP}visitTimestampMicrosecond(){return CP}visitTimestampNanosecond(){return wP}visitTime(){return TP}visitTimeSecond(){return EP}visitTimeMillisecond(){return DP}visitTimeMicrosecond(){return OP}visitTimeNanosecond(){return kP}visitDecimal(){return GN}visitList(){return gP}visitStruct(){return yP}visitUnion(){return AP}visitDenseUnion(){return MP}visitSparseUnion(){return jP}visitDictionary(){return KN}visitInterval(){return $N}visitIntervalDayTime(){return eP}visitIntervalYearMonth(){return tP}visitDuration(){return nP}visitDurationSecond(){return rP}visitDurationMillisecond(){return iP}visitDurationMicrosecond(){return aP}visitDurationNanosecond(){return oP}visitFixedSizeList(){return JN}visitMap(){return _P}},IP=class extends Jk{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 LP(e,t){return t instanceof e.constructor}function RP(e,t){return e===t||LP(e,t)}function zP(e,t){return e===t||LP(e,t)&&e.bitWidth===t.bitWidth&&e.isSigned===t.isSigned}function BP(e,t){return e===t||LP(e,t)&&e.precision===t.precision}function VP(e,t){return e===t||LP(e,t)&&e.byteWidth===t.byteWidth}function HP(e,t){return e===t||LP(e,t)&&e.unit===t.unit}function UP(e,t){return e===t||LP(e,t)&&e.unit===t.unit&&e.timezone===t.timezone}function WP(e,t){return e===t||LP(e,t)&&e.unit===t.unit&&e.bitWidth===t.bitWidth}function GP(e,t){return e===t||LP(e,t)&&e.children.length===t.children.length&&$P.compareManyFields(e.children,t.children)}function KP(e,t){return e===t||LP(e,t)&&e.children.length===t.children.length&&$P.compareManyFields(e.children,t.children)}function qP(e,t){return e===t||LP(e,t)&&e.mode===t.mode&&e.typeIds.every((e,n)=>e===t.typeIds[n])&&$P.compareManyFields(e.children,t.children)}function JP(e,t){return e===t||LP(e,t)&&e.id===t.id&&e.isOrdered===t.isOrdered&&$P.visit(e.indices,t.indices)&&$P.visit(e.dictionary,t.dictionary)}function YP(e,t){return e===t||LP(e,t)&&e.unit===t.unit}function XP(e,t){return e===t||LP(e,t)&&e.unit===t.unit}function ZP(e,t){return e===t||LP(e,t)&&e.listSize===t.listSize&&e.children.length===t.children.length&&$P.compareManyFields(e.children,t.children)}function QP(e,t){return e===t||LP(e,t)&&e.keysSorted===t.keysSorted&&e.children.length===t.children.length&&$P.compareManyFields(e.children,t.children)}IP.prototype.visitNull=RP,IP.prototype.visitBool=RP,IP.prototype.visitInt=zP,IP.prototype.visitInt8=zP,IP.prototype.visitInt16=zP,IP.prototype.visitInt32=zP,IP.prototype.visitInt64=zP,IP.prototype.visitUint8=zP,IP.prototype.visitUint16=zP,IP.prototype.visitUint32=zP,IP.prototype.visitUint64=zP,IP.prototype.visitFloat=BP,IP.prototype.visitFloat16=BP,IP.prototype.visitFloat32=BP,IP.prototype.visitFloat64=BP,IP.prototype.visitUtf8=RP,IP.prototype.visitLargeUtf8=RP,IP.prototype.visitBinary=RP,IP.prototype.visitLargeBinary=RP,IP.prototype.visitFixedSizeBinary=VP,IP.prototype.visitDate=HP,IP.prototype.visitDateDay=HP,IP.prototype.visitDateMillisecond=HP,IP.prototype.visitTimestamp=UP,IP.prototype.visitTimestampSecond=UP,IP.prototype.visitTimestampMillisecond=UP,IP.prototype.visitTimestampMicrosecond=UP,IP.prototype.visitTimestampNanosecond=UP,IP.prototype.visitTime=WP,IP.prototype.visitTimeSecond=WP,IP.prototype.visitTimeMillisecond=WP,IP.prototype.visitTimeMicrosecond=WP,IP.prototype.visitTimeNanosecond=WP,IP.prototype.visitDecimal=RP,IP.prototype.visitList=GP,IP.prototype.visitStruct=KP,IP.prototype.visitUnion=qP,IP.prototype.visitDenseUnion=qP,IP.prototype.visitSparseUnion=qP,IP.prototype.visitDictionary=JP,IP.prototype.visitInterval=YP,IP.prototype.visitIntervalDayTime=YP,IP.prototype.visitIntervalYearMonth=YP,IP.prototype.visitDuration=XP,IP.prototype.visitDurationSecond=XP,IP.prototype.visitDurationMillisecond=XP,IP.prototype.visitDurationMicrosecond=XP,IP.prototype.visitDurationNanosecond=XP,IP.prototype.visitFixedSizeList=ZP,IP.prototype.visitMap=QP;var $P=new IP;function eF(e,t){return $P.compareSchemas(e,t)}function tF(e,t){return $P.visit(e,t)}function nF(e){let t=e.type,n=new(FP.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(nF(Object.assign(Object.assign({},i),{type:t})))}}return n}function rF(e,t){if(e instanceof yM||e instanceof GM||e.type instanceof fk||ArrayBuffer.isView(e))return qM(e);let n=[...aF({type:t??iF(e),nullValues:[null]})(e)],r=n.length===1?n[0]:n.reduce((e,t)=>e.concat(t));return fk.isDictionary(r.type)?r.memoize():r}function iF(e){if(e.length===0)return new pk;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 Ek;if(a+t===e.length)return new Kk(new kk,new _k);if(o+t===e.length)return new vk;if(s+t===e.length)return new jk;if(c+t===e.length)return new Ik;if(n+t===e.length){let t=e,n=iF(t[t.findIndex(e=>e!=null)]);if(t.every(e=>e==null||tF(n,iF(e))))return new zk(new lN(``,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 lN(e,iF([n[e]]),!0));return new Bk([...t.values()])}throw TypeError(`Unable to infer Vector type from input values, explicit type declaration expected.`)}function aF(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=nF(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 oF(e,t){return sF(e,t.map(e=>e.data.concat()))}function sF(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=cF(n,o,u,t,i),o>0&&(r[a++]=xM({type:new Bk(n),length:o,nullCount:0,children:u.slice()})))}return[e=e.assign(n),r.map(t=>new pF(e,t))]}function cF(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)??xM({type:r.type,length:t,nullCount:t,nullBitmap:new Uint8Array(a)})}}return n}var lF,uF=class e{constructor(...t){if(t.length===0)return this.batches=[],this.schema=new cN([]),this._offsets=[0],this;let n,r;t[0]instanceof cN&&(n=t.shift()),t.at(-1)instanceof Uint32Array&&(r=t.pop());let i=t=>{if(t){if(t instanceof pF)return[t];if(t instanceof e)return t.batches;if(t instanceof yM){if(t.type instanceof Bk)return[new pF(new cN(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 GM([t[e]])),[,i]=oF(n??new cN(e.map((e,t)=>new lN(String(e),r[t].type,r[t].nullable))),r);return i.length===0?[new pF(t)]:i}}return[]},a=t.flatMap(e=>i(e));if(n=n??a[0]?.schema??new cN([]),!(n instanceof cN))throw TypeError(`Table constructor expects a [Schema, RecordBatch[]] pair.`);for(let e of a){if(!(e instanceof pF))throw TypeError(`Table constructor expects a [Schema, RecordBatch[]] pair.`);if(!eF(n,e.schema))throw TypeError(`Table and inner RecordBatch schemas must be equivalent.`)}this.schema=n,this.batches=a,this._offsets=r??TM(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=wM(this.data)),this._nullCount}isValid(e){return!1}get(e){return null}at(e){return this.get(eM(e,this.numRows))}set(e,t){}indexOf(e,t){return-1}[Symbol.iterator](){return this.batches.length>0?VM.visit(new GM(this.data)):[][Symbol.iterator]()}toArray(){return[...this]}toString(){return`[\n ${this.toArray().join(`,
69
69
  `)}\n]`}concat(...t){let n=this.schema;return new e(n,this.data.concat(t.flatMap(({data:e})=>e)).map(e=>new pF(n,e)))}slice(t,n){let r=this.schema;return[t,n]=$j({length:this.numRows},t,n),new e(r,EM(this.data,this._offsets,t,n).map(e=>new pF(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=xM({type:n,length:0,nullCount:0});t.push(r._changeLengthAndBackfillNullBitmap(this.numRows))}return new GM(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 GM([xM({type:new pk,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]=oF(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(...oF(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)))}};lF=Symbol.toStringTag,uF[lF]=(e=>(e.schema=null,e.batches=[],e._offsets=new Uint32Array([0]),e._nullCount=-1,e[Symbol.isConcatSpreadable]=!0,e.isValid=kM(OM),e.get=kM(Wj.getVisitFn(Z.Struct)),e.set=AM(JA.getVisitFn(Z.Struct)),e.indexOf=jM(LM.getVisitFn(Z.Struct)),`Table`))(uF.prototype);function dF(e){let t={},n=Object.entries(e);for(let[e,r]of n)t[e]=rF(r);return new uF(t)}var fF,pF=class e{constructor(...e){switch(e.length){case 2:if([this.schema]=e,!(this.schema instanceof cN)||([,this.data=xM({nullCount:0,type:new Bk(this.schema.fields),children:this.schema.fields.map(e=>xM({type:e.type,nullCount:0}))})]=e,!(this.data instanceof yM)))throw TypeError(`RecordBatch constructor expects a [Schema, Data] pair.`);[this.schema,this.data]=mF(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]=lN.new({name:n,type:t[n].type,nullable:!0}),e),{length:0,fields:[],children:[]}),a=new cN(n),o=xM({type:new Bk(n),length:i,children:r,nullCount:0});[this.schema,this.data]=mF(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||=hF(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 Wj.visit(this.data,e)}at(e){return this.get(eM(e,this.numRows))}set(e,t){return JA.visit(this.data,e,t)}indexOf(e,t){return LM.visit(this.data,e,t)}[Symbol.iterator](){return VM.visit(new GM([this.data]))}toArray(){return[...this]}concat(...e){return new uF(this.schema,[this,...e])}slice(t,n){let[r]=new GM([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 GM([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 GM([xM({type:new pk,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 cN(e,new Map(this.schema.metadata)),i=xM({type:new Bk(e),children:a})}return new e(r,i)}select(t){let n=this.schema.select(t),r=new Bk(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,xM({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,xM({type:new Bk(n.fields),length:this.numRows,children:r}))}};fF=Symbol.toStringTag,pF[fF]=(e=>(e._nullCount=-1,e[Symbol.isConcatSpreadable]=!0,`RecordBatch`))(pF.prototype);function mF(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)??xM({type:s.type,length:n,nullCount:n,nullBitmap:new Uint8Array(a)}))}return[e.assign(r),xM({type:new Bk(r),length:n,children:i})]}function hF(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||[]])hF(i.children,e?.children,n);if(fk.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 gF=class extends pF{constructor(e){let t=e.fields.map(e=>xM({type:e.type})),n=xM({type:new Bk(e.fields),nullCount:0,children:t});super(e,n)}},_F=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):PD.V1}headerType(){let e=this.bb.__offset(this.bb_pos,6);return e?this.bb.readUint8(this.bb_pos+e):DO.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 iO).__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,PD.V1)}static addHeaderType(e,t){e.addFieldInt8(1,t,DO.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)}},vF=new class extends Jk{visit(e,t){return e==null||t==null?void 0:super.visit(e,t)}visitNull(e,t){return vO.startNull(t),vO.endNull(t)}visitInt(e,t){return nO.startInt(t),nO.addBitWidth(t,e.bitWidth),nO.addIsSigned(t,e.isSigned),nO.endInt(t)}visitFloat(e,t){return fO.startFloatingPoint(t),fO.addPrecision(t,e.precision),fO.endFloatingPoint(t)}visitBinary(e,t){return aO.startBinary(t),aO.endBinary(t)}visitLargeBinary(e,t){return mO.startLargeBinary(t),mO.endLargeBinary(t)}visitBool(e,t){return oO.startBool(t),oO.endBool(t)}visitUtf8(e,t){return CO.startUtf8(t),CO.endUtf8(t)}visitLargeUtf8(e,t){return hO.startLargeUtf8(t),hO.endLargeUtf8(t)}visitDecimal(e,t){return cO.startDecimal(t),cO.addScale(t,e.scale),cO.addPrecision(t,e.precision),cO.addBitWidth(t,e.bitWidth),cO.endDecimal(t)}visitDate(e,t){return sO.startDate(t),sO.addUnit(t,e.unit),sO.endDate(t)}visitTime(e,t){return bO.startTime(t),bO.addUnit(t,e.unit),bO.addBitWidth(t,e.bitWidth),bO.endTime(t)}visitTimestamp(e,t){let n=e.timezone&&t.createString(e.timezone)||void 0;return xO.startTimestamp(t),xO.addUnit(t,e.unit),n!==void 0&&xO.addTimezone(t,n),xO.endTimestamp(t)}visitInterval(e,t){return pO.startInterval(t),pO.addUnit(t,e.unit),pO.endInterval(t)}visitDuration(e,t){return lO.startDuration(t),lO.addUnit(t,e.unit),lO.endDuration(t)}visitList(e,t){return gO.startList(t),gO.endList(t)}visitStruct(e,t){return yO.startStruct_(t),yO.endStruct_(t)}visitUnion(e,t){SO.startTypeIdsVector(t,e.typeIds.length);let n=SO.createTypeIdsVector(t,e.typeIds);return SO.startUnion(t),SO.addMode(t,e.mode),SO.addTypeIds(t,n),SO.endUnion(t)}visitDictionary(e,t){let n=this.visit(e.indices,t);return rO.startDictionaryEncoding(t),rO.addId(t,BigInt(e.id)),rO.addIsOrdered(t,e.isOrdered),n!==void 0&&rO.addIndexType(t,n),rO.endDictionaryEncoding(t)}visitFixedSizeBinary(e,t){return uO.startFixedSizeBinary(t),uO.addByteWidth(t,e.byteWidth),uO.endFixedSizeBinary(t)}visitFixedSizeList(e,t){return dO.startFixedSizeList(t),dO.addListSize(t,e.listSize),dO.endFixedSizeList(t)}visitMap(e,t){return _O.startMap(t),_O.addKeysSorted(t,e.keysSorted),_O.endMap(t)}};function yF(e,t=new Map){return new cN(SF(e,t),OF(e.metadata),t)}function bF(e){return new PF(e.count,wF(e.columns),TF(e.columns))}function xF(e){return new FF(bF(e.data),e.id,e.isDelta)}function SF(e,t){return(e.fields||[]).filter(Boolean).map(e=>lN.fromJSON(e,t))}function CF(e,t){return(e.children||[]).filter(Boolean).map(e=>lN.fromJSON(e,t))}function wF(e){return(e||[]).reduce((e,t)=>[...e,new LF(t.count,EF(t.VALIDITY)),...wF(t.children)],[])}function TF(e,t=[]){for(let n=-1,r=(e||[]).length;++n<r;){let r=e[n];r.VALIDITY&&t.push(new IF(t.length,r.VALIDITY.length)),r.TYPE_ID&&t.push(new IF(t.length,r.TYPE_ID.length)),r.OFFSET&&t.push(new IF(t.length,r.OFFSET.length)),r.DATA&&t.push(new IF(t.length,r.DATA.length)),t=TF(r.children,t)}return t}function EF(e){return(e||[]).reduce((e,t)=>e+ +(t===0),0)}function DF(e,t){let n,r,i,a,o,s;return!t||!(a=e.dictionary)?(o=AF(e,CF(e,t)),i=new lN(e.name,o,e.nullable,OF(e.metadata))):t.has(n=a.id)?(r=(r=a.indexType)?kF(r):new _k,s=new Kk(t.get(n),r,n,a.isOrdered),i=new lN(e.name,s,e.nullable,OF(e.metadata))):(r=(r=a.indexType)?kF(r):new _k,t.set(n,o=AF(e,CF(e,t))),s=new Kk(o,r,n,a.isOrdered),i=new lN(e.name,s,e.nullable,OF(e.metadata))),i||null}function OF(e=[]){return new Map(e.map(({key:e,value:t})=>[e,t]))}function kF(e){return new mk(e.isSigned,e.bitWidth)}function AF(e,t){let n=e.type.name;switch(n){case`NONE`:return new pk;case`null`:return new pk;case`binary`:return new Dk;case`largebinary`:return new Ok;case`utf8`:return new kk;case`largeutf8`:return new Ak;case`bool`:return new jk;case`list`:return new zk((t||[])[0]);case`struct`:return new Bk(t||[]);case`struct_`:return new Bk(t||[])}switch(n){case`int`:{let t=e.type;return new mk(t.isSigned,t.bitWidth)}case`floatingpoint`:{let t=e.type;return new Ck(ID[t.precision])}case`decimal`:{let t=e.type;return new Mk(t.scale,t.precision,t.bitWidth)}case`date`:{let t=e.type;return new Nk(LD[t.unit])}case`time`:{let t=e.type;return new Pk(RD[t.unit],t.bitWidth)}case`timestamp`:{let t=e.type;return new Fk(RD[t.unit],t.timezone)}case`interval`:{let t=e.type;return new Lk(zD[t.unit])}case`duration`:{let t=e.type;return new Rk(RD[t.unit])}case`union`:{let n=e.type,[r,...i]=(n.mode+``).toLowerCase();return new Vk(FD[r.toUpperCase()+i.join(``)],n.typeIds||[],t||[])}case`fixedsizebinary`:{let t=e.type;return new Hk(t.byteWidth)}case`fixedsizelist`:{let n=e.type;return new Uk(n.listSize,(t||[])[0])}case`map`:{let n=e.type;return new Wk((t||[])[0],n.keysSorted)}}throw Error(`Unrecognized type: "${n}"`)}var jF=KD,MF=GD,NF=class e{static fromJSON(t,n){let r=new e(0,PD.V5,n);return r._createHeader=RF(t,n),r}static decode(t){t=new MF(vD(t));let n=_F.getRootAsMessage(t),r=n.bodyLength(),i=n.version(),a=n.headerType(),o=new e(r,i,a);return o._createHeader=zF(n,a),o}static encode(e){let t=new jF,n=-1;return e.isSchema()?n=cN.encode(t,e.header()):e.isRecordBatch()?n=PF.encode(t,e.header()):e.isDictionaryBatch()&&(n=FF.encode(t,e.header())),_F.startMessage(t),_F.addVersion(t,PD.V5),_F.addHeader(t,n),_F.addHeaderType(t,e.headerType),_F.addBodyLength(t,BigInt(e.bodyLength)),_F.finishMessageBuffer(t,_F.endMessage(t)),t.asUint8Array()}static from(t,n=0){if(t instanceof cN)return new e(0,PD.V5,DO.Schema,t);if(t instanceof PF)return new e(n,PD.V5,DO.RecordBatch,t);if(t instanceof FF)return new e(n,PD.V5,DO.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===DO.Schema}isRecordBatch(){return this.headerType===DO.RecordBatch}isDictionaryBatch(){return this.headerType===DO.DictionaryBatch}constructor(e,t,n,r){this._version=t,this._headerType=n,this.body=new Uint8Array,r&&(this._createHeader=()=>r),this._bodyLength=jO(e)}},PF=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=jO(e)}},FF=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=jO(t)}},IF=class{constructor(e,t){this.offset=jO(e),this.length=jO(t)}},LF=class{constructor(e,t){this.length=jO(e),this.nullCount=jO(t)}};function RF(e,t){return(()=>{switch(t){case DO.Schema:return cN.fromJSON(e);case DO.RecordBatch:return PF.fromJSON(e);case DO.DictionaryBatch:return FF.fromJSON(e)}throw Error(`Unrecognized Message type: { name: ${DO[t]}, type: ${t} }`)})}function zF(e,t){return(()=>{switch(t){case DO.Schema:return cN.decode(e.header(new EO),new Map,e.version());case DO.RecordBatch:return PF.decode(e.header(new QD),e.version());case DO.DictionaryBatch:return FF.decode(e.header(new $D),e.version())}throw Error(`Unrecognized Message type: { name: ${DO[t]}, type: ${t} }`)})}lN.encode=eI,lN.decode=YF,lN.fromJSON=DF,cN.encode=$F,cN.decode=BF,cN.fromJSON=yF,PF.encode=tI,PF.decode=VF,PF.fromJSON=bF,FF.encode=nI,FF.decode=HF,FF.fromJSON=xF,LF.encode=rI,LF.decode=WF,IF.encode=iI,IF.decode=UF;function BF(e,t=new Map,n=PD.V5){return new cN(qF(e,t),XF(e),t,n)}function VF(e,t=PD.V5){if(e.compression()!==null)throw Error(`Record batch compression not implemented`);return new PF(e.length(),GF(e),KF(e,t))}function HF(e,t=PD.V5){return new FF(PF.decode(e.data(),t),e.id(),e.isDelta())}function UF(e){return new IF(e.offset(),e.length())}function WF(e){return new LF(e.length(),e.nullCount())}function GF(e){let t=[];for(let n,r=-1,i=-1,a=e.nodesLength();++r<a;)(n=e.nodes(r))&&(t[++i]=LF.decode(n));return t}function KF(e,t){let n=[];for(let r,i=-1,a=-1,o=e.buffersLength();++i<o;)(r=e.buffers(i))&&(t<PD.V4&&(r.bb_pos+=8*(i+1)),n[++a]=IF.decode(r));return n}function qF(e,t){let n=[];for(let r,i=-1,a=-1,o=e.fieldsLength();++i<o;)(r=e.fields(i))&&(n[++a]=lN.decode(r,t));return n}function JF(e,t){let n=[];for(let r,i=-1,a=-1,o=e.childrenLength();++i<o;)(r=e.children(i))&&(n[++a]=lN.decode(r,t));return n}function YF(e,t){let n,r,i,a,o,s;return!t||!(s=e.dictionary())?(i=QF(e,JF(e,t)),r=new lN(e.name(),i,e.nullable(),XF(e))):t.has(n=jO(s.id()))?(a=(a=s.indexType())?ZF(a):new _k,o=new Kk(t.get(n),a,n,s.isOrdered()),r=new lN(e.name(),o,e.nullable(),XF(e))):(a=(a=s.indexType())?ZF(a):new _k,t.set(n,i=QF(e,JF(e,t))),o=new Kk(i,a,n,s.isOrdered()),r=new lN(e.name(),o,e.nullable(),XF(e))),r||null}function XF(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 ZF(e){return new mk(e.isSigned(),e.bitWidth())}function QF(e,t){let n=e.typeType();switch(n){case wO.NONE:return new pk;case wO.Null:return new pk;case wO.Binary:return new Dk;case wO.LargeBinary:return new Ok;case wO.Utf8:return new kk;case wO.LargeUtf8:return new Ak;case wO.Bool:return new jk;case wO.List:return new zk((t||[])[0]);case wO.Struct_:return new Bk(t||[])}switch(n){case wO.Int:{let t=e.type(new nO);return new mk(t.isSigned(),t.bitWidth())}case wO.FloatingPoint:return new Ck(e.type(new fO).precision());case wO.Decimal:{let t=e.type(new cO);return new Mk(t.scale(),t.precision(),t.bitWidth())}case wO.Date:return new Nk(e.type(new sO).unit());case wO.Time:{let t=e.type(new bO);return new Pk(t.unit(),t.bitWidth())}case wO.Timestamp:{let t=e.type(new xO);return new Fk(t.unit(),t.timezone())}case wO.Interval:return new Lk(e.type(new pO).unit());case wO.Duration:return new Rk(e.type(new lO).unit());case wO.Union:{let n=e.type(new SO);return new Vk(n.mode(),n.typeIdsArray()||[],t||[])}case wO.FixedSizeBinary:return new Hk(e.type(new uO).byteWidth());case wO.FixedSizeList:return new Uk(e.type(new dO).listSize(),(t||[])[0]);case wO.Map:{let n=e.type(new _O);return new Wk((t||[])[0],n.keysSorted())}}throw Error(`Unrecognized type: "${wO[n]}" (${n})`)}function $F(e,t){let n=t.fields.map(t=>lN.encode(e,t));EO.startFieldsVector(e,n.length);let r=EO.createFieldsVector(e,n),i=t.metadata&&t.metadata.size>0?EO.createCustomMetadataVector(e,[...t.metadata].map(([t,n])=>{let r=e.createString(`${t}`),i=e.createString(`${n}`);return iO.startKeyValue(e),iO.addKey(e,r),iO.addValue(e,i),iO.endKeyValue(e)})):-1;return EO.startSchema(e),EO.addFields(e,r),EO.addEndianness(e,aI?eO.Little:eO.Big),i!==-1&&EO.addCustomMetadata(e,i),EO.endSchema(e)}function eI(e,t){let n=-1,r=-1,i=-1,a=t.type,o=t.typeId;fk.isDictionary(a)?(o=a.dictionary.typeId,i=vF.visit(a,e),r=vF.visit(a.dictionary,e)):r=vF.visit(a,e);let s=(a.children||[]).map(t=>lN.encode(e,t)),c=TO.createChildrenVector(e,s),l=t.metadata&&t.metadata.size>0?TO.createCustomMetadataVector(e,[...t.metadata].map(([t,n])=>{let r=e.createString(`${t}`),i=e.createString(`${n}`);return iO.startKeyValue(e),iO.addKey(e,r),iO.addValue(e,i),iO.endKeyValue(e)})):-1;return t.name&&(n=e.createString(t.name)),TO.startField(e),TO.addType(e,r),TO.addTypeType(e,o),TO.addChildren(e,c),TO.addNullable(e,!!t.nullable),n!==-1&&TO.addName(e,n),i!==-1&&TO.addDictionary(e,i),l!==-1&&TO.addCustomMetadata(e,l),TO.endField(e)}function tI(e,t){let n=t.nodes||[],r=t.buffers||[];QD.startNodesVector(e,n.length);for(let t of n.slice().reverse())LF.encode(e,t);let i=e.endVector();QD.startBuffersVector(e,r.length);for(let t of r.slice().reverse())IF.encode(e,t);let a=e.endVector();return QD.startRecordBatch(e),QD.addLength(e,BigInt(t.length)),QD.addNodes(e,i),QD.addBuffers(e,a),QD.endRecordBatch(e)}function nI(e,t){let n=PF.encode(e,t.data);return $D.startDictionaryBatch(e),$D.addId(e,BigInt(t.id)),$D.addIsDelta(e,t.isDelta),$D.addData(e,n),$D.endDictionaryBatch(e)}function rI(e,t){return ZD.createFieldNode(e,BigInt(t.length),BigInt(t.nullCount))}function iI(e,t){return XD.createBuffer(e,BigInt(t.offset),BigInt(t.length))}var aI=(()=>{let e=new ArrayBuffer(2);return new DataView(e).setInt16(0,256,!0),new Int16Array(e)[0]===256})(),oI=e=>`Expected ${DO[e]} Message in stream, but was null or length 0.`,sI=e=>`Header pointer of flatbuffer-encoded ${DO[e]} Message is null or length 0.`,cI=(e,t)=>`Expected to read ${e} metadata bytes, but only read ${t}.`,lI=(e,t)=>`Expected to read ${e} bytes for message body, but only read ${t}.`,uI=class{constructor(e){this.source=e instanceof SN?e:new SN(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?_N: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(oI(e));return t.value}readMessageBody(e){if(e<=0)return new Uint8Array;let t=vD(this.source.read(e));if(t.byteLength<e)throw Error(lI(e,t.byteLength));return t.byteOffset%8==0&&t.byteOffset+t.byteLength<=t.buffer.byteLength?t:t.slice()}readSchema(e=!1){let t=DO.Schema,n=this.readMessage(t)?.header();if(e&&!n)throw Error(sI(t));return n}readMetadataLength(){let e=this.source.read(4),t=(e&&new GD(e))?.readInt32(0)||0;return{done:t===0,value:t}}readMetadata(e){let t=this.source.read(e);if(!t)return _N;if(t.byteLength<e)throw Error(cI(e,t.byteLength));return{done:!1,value:NF.decode(t)}}},dI=class{constructor(e,t){this.source=e instanceof CN?e:rD(e)?new DN(e,t):new CN(e)}[Symbol.asyncIterator](){return this}next(){return RE(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?_N:e})}throw(e){return RE(this,void 0,void 0,function*(){return yield this.source.throw(e)})}return(e){return RE(this,void 0,void 0,function*(){return yield this.source.return(e)})}readMessage(e){return RE(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(oI(e));return t.value})}readMessageBody(e){return RE(this,void 0,void 0,function*(){if(e<=0)return new Uint8Array;let t=vD(yield this.source.read(e));if(t.byteLength<e)throw Error(lI(e,t.byteLength));return t.byteOffset%8==0&&t.byteOffset+t.byteLength<=t.buffer.byteLength?t:t.slice()})}readSchema(){return RE(this,arguments,void 0,function*(e=!1){let t=DO.Schema,n=(yield this.readMessage(t))?.header();if(e&&!n)throw Error(sI(t));return n})}readMetadataLength(){return RE(this,void 0,void 0,function*(){let e=yield this.source.read(4),t=(e&&new GD(e))?.readInt32(0)||0;return{done:t===0,value:t}})}readMetadata(e){return RE(this,void 0,void 0,function*(){let t=yield this.source.read(e);if(!t)return _N;if(t.byteLength<e)throw Error(cI(e,t.byteLength));return{done:!1,value:NF.decode(t)}})}},fI=class extends uI{constructor(e){super(new Uint8Array),this._schema=!1,this._body=[],this._batchIndex=0,this._dictionaryIndex=0,this._json=e instanceof vN?e:new vN(e)}next(){let{_json:e}=this;if(!this._schema)return this._schema=!0,{done:!1,value:NF.fromJSON(e.schema,DO.Schema)};if(this._dictionaryIndex<e.dictionaries.length){let t=e.dictionaries[this._dictionaryIndex++];return this._body=t.data.columns,{done:!1,value:NF.fromJSON(t,DO.DictionaryBatch)}}if(this._batchIndex<e.batches.length){let t=e.batches[this._batchIndex++];return this._body=t.columns,{done:!1,value:NF.fromJSON(t,DO.RecordBatch)}}return this._body=[],_N}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(oI(e));return t.value}readSchema(){let e=DO.Schema,t=this.readMessage(e),n=t?.header();if(!t||!n)throw Error(sI(e));return n}},pI=`ARROW1`,mI=new Uint8Array(6);for(let e=0;e<6;e+=1)mI[e]=pI.codePointAt(e);function hI(e,t=0){for(let n=-1,r=mI.length;++n<r;)if(mI[n]!==e[t+n])return!1;return!0}var gI=mI.length,_I=gI+4,vI=gI*2+4,yI=class e extends yN{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 QE(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 ED.toDOMStream(this.isSync()?{[Symbol.iterator]:()=>this}:{[Symbol.asyncIterator]:()=>this})}toNodeStream(){return ED.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:tD(t)?NI(t):rD(t)?II(t):QE(t)?RE(this,void 0,void 0,function*(){return yield e.from(yield t)}):iD(t)||sD(t)||lD(t)||eD(t)?FI(new CN(t)):PI(new SN(t))}static readAll(t){return t instanceof e?t.isSync()?jI(t):MI(t):tD(t)||ArrayBuffer.isView(t)||$E(t)||nD(t)?jI(t):MI(t)}},bI=class extends yI{constructor(e){super(e),this._impl=e}readAll(){return[...this]}[Symbol.iterator](){return this._impl[Symbol.iterator]()}[Symbol.asyncIterator](){return VE(this,arguments,function*(){yield BE(yield*HE(UE(this[Symbol.iterator]())))})}},xI=class extends yI{constructor(e){super(e),this._impl=e}readAll(){return RE(this,void 0,void 0,function*(){var e,t,n,r;let i=[];try{for(var a=!0,o=UE(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]()}},SI=class extends bI{constructor(e){super(e),this._impl=e}},CI=class extends xI{constructor(e){super(e),this._impl=e}},wI=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=xM({type:new Bk(this.schema.fields),length:e.length,children:n});return new pF(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 GM(c)):new GM(c)).memoize()}_loadVectors(e,t,n){return new IN(t,e.nodes,e.buffers,this.dictionaries,this.schema.metadataVersion).visitMany(n)}},TI=class extends wI{constructor(e,t){super(t),this._reader=tD(e)?new fI(this._handle=e):new uI(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=AI(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):_N}return(e){return!this.closed&&this.autoDestroy&&(this.closed=!0)?this.reset()._reader.return(e):_N}next(){if(this.closed)return _N;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 gF(this.schema)}):this.return()}_readNextMessageAndValidate(e){return this._reader.readMessage(e)}},EI=class extends wI{constructor(e,t){super(t),this._reader=new dI(this._handle=e)}isAsync(){return!0}isStream(){return!0}[Symbol.asyncIterator](){return this}cancel(){return RE(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 RE(this,void 0,void 0,function*(){return this.closed||(this.autoDestroy=AI(this,e),(this.schema||=yield this._reader.readSchema())||(yield this.cancel())),this})}throw(e){return RE(this,void 0,void 0,function*(){return!this.closed&&this.autoDestroy&&(this.closed=!0)?yield this.reset()._reader.throw(e):_N})}return(e){return RE(this,void 0,void 0,function*(){return!this.closed&&this.autoDestroy&&(this.closed=!0)?yield this.reset()._reader.return(e):_N})}next(){return RE(this,void 0,void 0,function*(){if(this.closed)return _N;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 gF(this.schema)}):yield this.return()})}_readNextMessageAndValidate(e){return RE(this,void 0,void 0,function*(){return yield this._reader.readMessage(e)})}},DI=class extends TI{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 EN?e:new EN(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(DO.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(DO.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-_I,n=e.readInt32(t),r=e.readAt(t-n,n);return mN.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}},OI=class extends EI{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 DN?e:new DN(e,n),r)}isFile(){return!0}isAsync(){return!0}open(e){let t=Object.create(null,{open:{get:()=>super.open}});return RE(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 RE(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(DO.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 RE(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(DO.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 RE(this,void 0,void 0,function*(){let{_handle:e}=this;e._pending&&(yield e._pending);let t=e.size-_I,n=yield e.readInt32(t),r=yield e.readAt(t-n,n);return mN.decode(r)})}_readNextMessageAndValidate(e){return RE(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})}},kI=class extends TI{constructor(e,t){super(e,t)}_loadVectors(e,t,n){return new LN(t,e.nodes,e.buffers,this.dictionaries,this.schema.metadataVersion).visitMany(n)}};function AI(e,t){return t&&typeof t.autoDestroy==`boolean`?t.autoDestroy:e.autoDestroy}function*jI(e){let t=yI.from(e);try{if(!t.open({autoDestroy:!1}).closed)do yield t;while(!t.reset().open().closed)}finally{t.cancel()}}function MI(e){return VE(this,arguments,function*(){let t=yield BE(yI.from(e));try{if(!(yield BE(t.open({autoDestroy:!1}))).closed)do yield yield BE(t);while(!(yield BE(t.reset().open())).closed)}finally{yield BE(t.cancel())}})}function NI(e){return new bI(new kI(e))}function PI(e){let t=e.peek(gI+7&-8);return t&&t.byteLength>=4?hI(t)?new SI(new DI(e.read())):new bI(new TI(e)):new bI(new TI(function*(){}()))}function FI(e){return RE(this,void 0,void 0,function*(){let t=yield e.peek(gI+7&-8);return t&&t.byteLength>=4?hI(t)?new SI(new DI(yield e.read())):new xI(new EI(e)):new xI(new EI(function(){return VE(this,arguments,function*(){})}()))})}function II(e){return RE(this,void 0,void 0,function*(){let{size:t}=yield e.stat(),n=new DN(e,t);return t>=vI&&hI(yield n.readAt(0,gI+7&-8))?new CI(new OI(n)):new xI(new EI(n))})}var LI=class e extends Jk{static assemble(...t){let n=e=>e.flatMap(e=>Array.isArray(e)?n(e):e instanceof pF?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 GM)return this.visitMany(e.data),this;let{type:t}=e;if(!fk.isDictionary(t)){let{length:n}=e;if(n>2147483647)throw RangeError(`Cannot write arrays larger than 2^31 - 1 in length`);if(fk.isUnion(t))this.nodes.push(new LF(n,0));else{let{nullCount:r}=e;fk.isNull(t)||RI.call(this,r<=0?new Uint8Array:pM(e.offset,n,e.nullBitmap)),this.nodes.push(new LF(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 RI(e){let t=e.byteLength+7&-8;return this.buffers.push(e),this.bufferRegions.push(new IF(this._byteLength,t)),this._byteLength+=t,this}function zI(e){let{type:t,length:n,typeIds:r,valueOffsets:i}=e;if(RI.call(this,r),t.mode===FD.Sparse)return WI.call(this,e);if(t.mode===FD.Dense){if(e.offset<=0)return RI.call(this,i),WI.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);RI.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 BI(e){let t;return e.nullCount>=e.length?RI.call(this,new Uint8Array):(t=e.values)instanceof Uint8Array?RI.call(this,pM(e.offset,e.length,t)):RI.call(this,mM(e.values))}function VI(e){return RI.call(this,e.values.subarray(0,e.length*e.stride))}function HI(e){let{length:t,values:n,valueOffsets:r}=e,i=jO(r[0]),a=jO(r[t]),o=Math.min(a-i,n.byteLength-i);return RI.call(this,wD(-i,t+1,r)),RI.call(this,n.subarray(i,i+o)),this}function UI(e){let{length:t,valueOffsets:n}=e;if(n){let{0:r,[t]:i}=n;return RI.call(this,wD(-r,t+1,n)),this.visit(e.children[0].slice(r,i-r))}return this.visit(e.children[0])}function WI(e){return this.visitMany(e.type.children.map((t,n)=>e.children[n]).filter(Boolean))[0]}LI.prototype.visitBool=BI,LI.prototype.visitInt=VI,LI.prototype.visitFloat=VI,LI.prototype.visitUtf8=HI,LI.prototype.visitLargeUtf8=HI,LI.prototype.visitBinary=HI,LI.prototype.visitLargeBinary=HI,LI.prototype.visitFixedSizeBinary=VI,LI.prototype.visitDate=VI,LI.prototype.visitTimestamp=VI,LI.prototype.visitTime=VI,LI.prototype.visitDecimal=VI,LI.prototype.visitList=UI,LI.prototype.visitStruct=WI,LI.prototype.visitUnion=zI,LI.prototype.visitInterval=VI,LI.prototype.visitDuration=VI,LI.prototype.visitFixedSizeList=UI,LI.prototype.visitMap=UI;var GI=class extends yN{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 xN,this._schema=null,this._dictionaryBlocks=[],this._recordBatchBlocks=[],this._seenDictionaries=new Map,this._dictionaryDeltaOffsets=new Map,ZE(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 QE(e)?e.then(e=>this.writeAll(e)):eD(e)?YI(this,e):JI(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 xN?this._sink=e:(this._sink=new xN,e&&oD(e)?this.toDOMStream({type:`bytes`}).pipeTo(e):e&&cD(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||!eF(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 uF&&!(t=e.schema)||e instanceof pF&&!(t=e.schema))return this.finish()&&void 0;if(t&&!eF(t,this._schema)){if(this._started&&this._autoDestroy)return this.close();this.reset(this._sink,t)}e instanceof pF?e instanceof gF||this._writeRecordBatch(e):e instanceof uF?this.writeAll(e.batches):$E(e)&&this.writeAll(e)}_writeMessage(e,t=8){let n=t-1,r=NF.encode(e),i=r.byteLength,a=this._writeLegacyIpcFormat?4:8,o=i+a+n&~n,s=o-i-a;return e.headerType===DO.RecordBatch?this._recordBatchBlocks.push(new gN(o,e.bodyLength,this._position)):e.headerType===DO.DictionaryBatch&&this._dictionaryBlocks.push(new gN(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=vD(e);t&&t.byteLength>0&&(this._sink.write(t),this._position+=t.byteLength)}return this}_writeSchema(e){return this._writeMessage(NF.from(e))}_writeFooter(e){return this._writeLegacyIpcFormat?this._write(Int32Array.of(0)):this._write(Int32Array.of(-1,0))}_writeMagic(){return this._write(mI)}_writePadding(e){return e>0?this._write(new Uint8Array(e)):this}_writeRecordBatch(e){let{byteLength:t,nodes:n,bufferRegions:r,buffers:i}=LI.assemble(e),a=new PF(e.numRows,n,r),o=NF.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}=LI.assemble(new GM([e])),s=new FF(new PF(e.length,i,a),t,n),c=NF.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}},KI=class e extends GI{static writeAll(t,n){let r=new e(n);return QE(t)?t.then(e=>r.writeAll(e)):eD(t)?YI(r,t):JI(r,t)}},qI=class e extends GI{static writeAll(t){let n=new e;return QE(t)?t.then(e=>n.writeAll(e)):eD(t)?YI(n,t):JI(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=mN.encode(new mN(e,PD.V5,this._recordBatchBlocks,this._dictionaryBlocks));return super._writeFooter(e)._write(t)._write(Int32Array.of(t.byteLength))._writeMagic()}};function JI(e,t){let n=t;t instanceof uF&&(n=t.batches,e.reset(void 0,t.schema));for(let t of n)e.write(t);return e.finish()}function YI(e,t){return RE(this,void 0,void 0,function*(){var n,r,i,a,o,s,c;try{for(n=!0,r=UE(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 XI(e,t=`stream`){return(t===`stream`?KI:qI).writeAll(e).toUint8Array(!0)}var ZI=Object.create,QI=Object.defineProperty,$I=Object.getOwnPropertyDescriptor,eL=Object.getOwnPropertyNames,tL=Object.getPrototypeOf,nL=Object.prototype.hasOwnProperty,rL=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),iL=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(let i of eL(t))!nL.call(e,i)&&i!==n&&QI(e,i,{get:()=>t[i],enumerable:!(r=$I(t,i))||r.enumerable});return e},aL=(e,t,n)=>(n=e==null?{}:ZI(tL(e)),iL(t||!e||!e.__esModule?QI(n,`default`,{value:e,enumerable:!0}):n,e)),oL=rL((e,t)=>{t.exports=Worker}),sL=(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))(sL||{}),cL=(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))(cL||{}),lL=(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))(lL||{}),uL=(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))(uL||{}),dL=(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))(dL||{}),fL=(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))(fL||{}),pL=class{constructor(e=2){this.level=e}log(e){e.level>=this.level&&console.log(e)}},mL=(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))(mL||{}),hL=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=yI.from(t);return console.assert(n.isSync(),`Reader is not sync`),console.assert(n.isFile(),`Reader is not file`),new uF(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 gL(this._bindings,this._conn,n),i=await yI.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 _L(this._bindings,this._conn,t)}async insertArrowTable(e,t){let n=XI(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)}},gL=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}},_L=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=yI.from(t);return console.assert(n.isSync()),console.assert(n.isFile()),new uF(n)}async send(...e){let t=await this.bindings.sendPrepared(this.connectionId,this.statementId,e),n=new gL(this.bindings,this.connectionId,t),r=await yI.from(n);return console.assert(r.isAsync()),console.assert(r.isStream()),r}},vL=(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))(vL||{}),yL=(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))(yL||{}),bL=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 xL(e){switch(e.typeId){case Z.Binary:return{sqlType:`binary`};case Z.Bool:return{sqlType:`bool`};case Z.Date:return{sqlType:`date`};case Z.DateDay:return{sqlType:`date32[d]`};case Z.DateMillisecond:return{sqlType:`date64[ms]`};case Z.Decimal:{let t=e;return{sqlType:`decimal`,precision:t.precision,scale:t.scale}}case Z.Float:return{sqlType:`float`};case Z.Float16:return{sqlType:`float16`};case Z.Float32:return{sqlType:`float32`};case Z.Float64:return{sqlType:`float64`};case Z.Int:return{sqlType:`int32`};case Z.Int16:return{sqlType:`int16`};case Z.Int32:return{sqlType:`int32`};case Z.Int64:return{sqlType:`int64`};case Z.Uint16:return{sqlType:`uint16`};case Z.Uint32:return{sqlType:`uint32`};case Z.Uint64:return{sqlType:`uint64`};case Z.Uint8:return{sqlType:`uint8`};case Z.IntervalDayTime:return{sqlType:`interval[dt]`};case Z.IntervalYearMonth:return{sqlType:`interval[m]`};case Z.List:return{sqlType:`list`,valueType:xL(e.valueType)};case Z.FixedSizeBinary:return{sqlType:`fixedsizebinary`,byteWidth:e.byteWidth};case Z.Null:return{sqlType:`null`};case Z.Utf8:return{sqlType:`utf8`};case Z.Struct:return{sqlType:`struct`,fields:e.children.map(e=>SL(e.name,e.type))};case Z.Map:{let t=e;return{sqlType:`map`,keyType:xL(t.keyType),valueType:xL(t.valueType)}}case Z.Time:return{sqlType:`time[s]`};case Z.TimeMicrosecond:return{sqlType:`time[us]`};case Z.TimeMillisecond:return{sqlType:`time[ms]`};case Z.TimeNanosecond:return{sqlType:`time[ns]`};case Z.TimeSecond:return{sqlType:`time[s]`};case Z.Timestamp:return{sqlType:`timestamp`,timezone:e.timezone||void 0};case Z.TimestampSecond:return{sqlType:`timestamp[s]`,timezone:e.timezone||void 0};case Z.TimestampMicrosecond:return{sqlType:`timestamp[us]`,timezone:e.timezone||void 0};case Z.TimestampNanosecond:return{sqlType:`timestamp[ns]`,timezone:e.timezone||void 0};case Z.TimestampMillisecond:return{sqlType:`timestamp[ms]`,timezone:e.timezone||void 0}}throw Error(`unsupported arrow type: ${e.toString()}`)}function SL(e,t){let n=xL(t);return n.name=e,n}var CL=/'(opfs:\/\/\S*?)'/g,wL=/(opfs:\/\/\S*?)/g;function TL(e){return e.search(wL)>-1}function EL(e){return[...e.matchAll(CL)].map(e=>e[1])}var DL=new TextEncoder,OL=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 bL(`RESET`,null);return await this.postTask(e)}async ping(){let e=new bL(`PING`,null);await this.postTask(e)}async dropFile(e){let t=new bL(`DROP_FILE`,e);return await this.postTask(t)}async dropFiles(e){let t=new bL(`DROP_FILES`,e);return await this.postTask(t)}async flushFiles(){let e=new bL(`FLUSH_FILES`,null);return await this.postTask(e)}async instantiate(e,t=null,n=e=>{}){this._onInstantiationProgress.push(n);let r=new bL(`INSTANTIATE`,[e,t]);return await this.postTask(r)}async getVersion(){let e=new bL(`GET_VERSION`,null);return await this.postTask(e)}async getFeatureFlags(){let e=new bL(`GET_FEATURE_FLAGS`,null);return await this.postTask(e)}async open(e){this._config=e;let t=new bL(`OPEN`,e);await this.postTask(t)}async tokenize(e){let t=new bL(`TOKENIZE`,e);return await this.postTask(t)}async connectInternal(){let e=new bL(`CONNECT`,null);return await this.postTask(e)}async connect(){let e=await this.connectInternal();return new hL(this,e)}async disconnect(e){let t=new bL(`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 bL(`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 bL(`START_PENDING_QUERY`,[e,t,n]);return await this.postTask(r)}async pollPendingQuery(e){let t=new bL(`POLL_PENDING_QUERY`,e);return await this.postTask(t)}async cancelPendingQuery(e){let t=new bL(`CANCEL_PENDING_QUERY`,e);return await this.postTask(t)}async fetchQueryResults(e){let t=new bL(`FETCH_QUERY_RESULTS`,e);return await this.postTask(t)}async getTableNames(e,t){let n=new bL(`GET_TABLE_NAMES`,[e,t]);return await this.postTask(n)}async createPrepared(e,t){let n=new bL(`CREATE_PREPARED`,[e,t]);return await this.postTask(n)}async closePrepared(e,t){let n=new bL(`CLOSE_PREPARED`,[e,t]);await this.postTask(n)}async runPrepared(e,t,n){let r=new bL(`RUN_PREPARED`,[e,t,n]);return await this.postTask(r)}async sendPrepared(e,t,n){let r=new bL(`SEND_PREPARED`,[e,t,n]);return await this.postTask(r)}async globFiles(e){let t=new bL(`GLOB_FILE_INFOS`,e);return await this.postTask(t)}async registerFileText(e,t){let n=DL.encode(t);await this.registerFileBuffer(e,n)}async registerFileURL(e,t,n,r){t===void 0&&(t=e);let i=new bL(`REGISTER_FILE_URL`,[e,t,n,r]);await this.postTask(i)}async registerEmptyFileBuffer(e){}async registerFileBuffer(e,t){let n=new bL(`REGISTER_FILE_BUFFER`,[e,t]);await this.postTask(n,[t.buffer])}async registerFileHandle(e,t,n,r){let i=new bL(`REGISTER_FILE_HANDLE`,[e,t,n,r]);await this.postTask(i,[])}async registerOPFSFileName(e){let t=new bL(`REGISTER_OPFS_FILE_NAME`,[e]);await this.postTask(t,[])}async collectFileStatistics(e,t){let n=new bL(`COLLECT_FILE_STATISTICS`,[e,t]);await this.postTask(n,[])}async exportFileStatistics(e){let t=new bL(`EXPORT_FILE_STATISTICS`,e);return await this.postTask(t,[])}async copyFileToBuffer(e){let t=new bL(`COPY_FILE_TO_BUFFER`,e);return await this.postTask(t)}async copyFileToPath(e,t){let n=new bL(`COPY_FILE_TO_PATH`,[e,t]);await this.postTask(n)}async insertArrowFromIPCStream(e,t,n){if(t.length==0)return;let r=new bL(`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(SL(t,r))}n.columnsFlat=e,delete n.columns}let r=new bL(`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(SL(t,r))}n.columnsFlat=e,delete n.columns}let r=new bL(`IMPORT_JSON_FROM_PATH`,[e,t,n]);await this.postTask(r)}shouldOPFSFileHandling(){return TL(this.config.path??``)?this.config.opfs?.fileHandling==`auto`:!1}async registerOPFSFileFromSQL(e){let t=EL(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 kL(){let e=new TextDecoder;return t=>(typeof SharedArrayBuffer<`u`&&t.buffer instanceof SharedArrayBuffer&&(t=new Uint8Array(t)),e.decode(t))}kL();var AL=(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))(AL||{}),jL={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`}}};jL.name,jL.version;var ML=jL.version.split(`.`);ML[0],ML[1],ML[2],aL(oL());var NL=``+new URL(`assets/duckdb-browser-eh.worker--3HUwN9R.js`,import.meta.url).href,PL=``+new URL(`assets/duckdb-eh-D-nnNw7L.wasm.gz`,import.meta.url).href;async function FL(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 IL=null;function LL(){return IL||(IL=(async()=>{let e=e=>new URL(e,location.href).href,t=URL.createObjectURL(new Blob([`importScripts(${JSON.stringify(e(NL))});`],{type:`text/javascript`})),n=new Worker(t),r=new OL(new pL(lL.WARNING),n),i=await FL(e(PL));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})(),IL)}var RL=null;function zL(){return RL??=(async()=>{let e=await LL(),t=await e.connect();try{await t.query(`SET custom_extension_repository = '${new URL(`/duckdb-ext`,location.href).href}'`),await t.query(`LOAD parquet`)}finally{await t.close()}return e})().catch(e=>{throw RL=null,e}),RL}function BL(e){return`"`+e.replace(/"/g,`""`)+`"`}function VL(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=BL(e.xcol),r=BL(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 ${BL(e.table)} WHERE ${n} BETWEEN ? AND ? GROUP BY 1 ORDER BY 1`,params:[e.x0,t,e.maxPoints,e.x0,e.x1]}}function HL(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=BL(e.xcol),r=BL(e.table);return{sql:`SELECT least(floor((${n} - ?) / ?), ? - 1) AS b, ${e.ycols.map((e,t)=>`min(${BL(e)}) AS y${t}lo, max(${BL(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 UL=`__kym_bin`;function WL(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=BL(e.xcol),n=BL(e.srcTable);return`CREATE OR REPLACE TABLE ${BL(e.dstTable)} AS SELECT ${`CAST(floor((${t} - ${qL(e.x0base)}) / ${qL(e.binWidth)}) AS BIGINT)`} AS ${UL}, ${e.ycols.map(e=>`min(${BL(e)}) AS ${BL(e+`__lo`)}, max(${BL(e)}) AS ${BL(e+`__hi`)}`).join(`, `)} FROM ${n} WHERE ${t} IS NOT NULL GROUP BY 1`}function GL(e){let t=BL(e.srcTable);return`CREATE OR REPLACE TABLE ${BL(e.dstTable)} AS SELECT CAST(floor(${UL} / 2.0) AS BIGINT) AS ${UL}, ${e.ycols.map(e=>`min(${BL(e+`__lo`)}) AS ${BL(e+`__lo`)}, max(${BL(e+`__hi`)}) AS ${BL(e+`__hi`)}`).join(`, `)} FROM ${t} GROUP BY 1`}function KL(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=BL(e.levelTable);return{sql:`SELECT least(greatest(CAST(floor(? + ${UL} * ?) AS BIGINT), 0), ?) AS b, ${e.ycols.map((e,t)=>`min(${BL(e+`__lo`)}) AS y${t}lo, max(${BL(e+`__hi`)}) AS y${t}hi`).join(`, `)} FROM ${o} WHERE ${UL} BETWEEN ? AND ? GROUP BY 1 ORDER BY 1`,params:[r,n,e.maxPoints-1,i,a]}}function qL(e){if(!Number.isFinite(e))throw Error(`num: value must be finite`);return Number.isInteger(e)?String(e):e.toExponential(17)}function JL(e){let t=BL(e.table);return e.range?{sql:`SELECT count(*) AS n FROM ${t} WHERE ${BL(e.range.xcol)} BETWEEN ? AND ?`,params:[e.range.x0,e.range.x1]}:{sql:`SELECT count(*) AS n FROM ${t}`,params:[]}}function YL(e){if(!Number.isInteger(e.stride)||e.stride<1)throw Error(`buildSampleRowsSql: stride must be a positive integer`);let t=BL(e.table),n=e.range?` WHERE ${BL(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 XL(e){return`'`+e.replace(/'/g,`''`)+`'`}function ZL(e){let t=e.columnNames.map(XL).join(`, `),n=e.delim===` `?`'\\t'`:XL(e.delim),r=e.decimalComma?`decimal_separator=',', `:``;return`SELECT * FROM read_csv(${XL(e.handle)}, header=false, skip=${e.dataStartRow}, delim=${n}, `+r+`names=[${t}], auto_type_candidates=['DOUBLE', 'VARCHAR'])`}function QL(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 $L=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}},eR=0,tR=()=>`t_${++eR}`,nR=5e4,rR=65536,iR=512,aR=2;function oR(e){return e<1?1:2**Math.floor(Math.log2(e))}var sR=class e{#e;#t;#n;#r;#i=new $L(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 LL(),i=await r.connect(),a=await t.slice(0,256*1024).text(),o=ze(a),s=y(a),c=H(o,s.headerRow),l=s.unitsRow===null?``:o[s.unitsRow]??``,u=x(o[s.headerRow]??``),d=m(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=tR(),h=ZL({handle:`input.csv`,columnNames:c,delim:u,dataStartRow:s.dataStartRow,decimalComma:d});await i.query(`CREATE OR REPLACE TABLE ${BL(p)} AS ${h}`),await r.dropFile(`input.csv`).catch(()=>{});let g=l?l.split(u).map(e=>e.trim()):[],_=new Map;c.forEach((e,t)=>_.set(e,g[t]??``));let v=await e.attach(i,p,_);return n?.({phase:`done`,message:`Ready.`}),v}static async attach(t,n,r){return new e(t,(await t.query(`DESCRIBE ${BL(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}=VL({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 QL((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)??HL({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/aR,a=null;for(let t of e.levels)t.binWidth<=i&&(a=t);return a?KL({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 LL()).connect();try{let n=JL({table:this.#n}),r=await t.query(n.sql),i=Number(r.getChild(`n`)?.get(0)??0);if(i<nR)return null;let a=await t.query(`SELECT min(${BL(e)}) AS lo, max(${BL(e)}) AS hi FROM ${BL(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(rR,oR(i));if(u<iR*2)return null;let d=++this.#c,f=[],p=u,m=0,h=`${this.#n}_p${d}_0`;await t.query(WL({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>=iR;){p/=2,m+=1;let e=`${this.#n}_p${d}_${m}`;await t.query(GL({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=JL({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}=YL({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(${BL(e)} AS DOUBLE), 'NaN'::DOUBLE) AS "c${t}"`).join(`, `),a=await this.#e.prepare(`SELECT ${i} FROM ${BL(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(${BL(e)}) AS lo, max(${BL(e)}) AS hi FROM ${BL(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 ${BL(e)}`)}catch{}try{await this.#e.query(`DROP TABLE IF EXISTS ${BL(this.#n)}`)}catch{}await this.#e.close()}},cR=1e8,lR=256*1024;function uR(e,t,n=0,r=cR){return e>314572800||n+t>r?`duckdb`:`memory`}function dR(e,t){let n=ze(t);t.length<e&&n.length>1&&(n=n.slice(0,-1));try{let t=y(n.join(`
70
- `)),r=H(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 fR=12e3;async function pR(e,t,n){let r=y(n),i=typeof Worker>`u`?k(n,r):await NE({rawText:n,config:r}),a=new LE(i);return{id:e,name:t,kind:`memory`,source:a,schema:await a.getSchema(),data:i,rawText:n,parseConfig:r}}async function mR(e,t,n,r,i=e=>e.text(),a){let o=y(r),s=typeof Worker>`u`?await PE({rawText:await i(n),config:o},a):await PE({file:n,config:o},a),c=new LE(s);return{id:e,name:t,kind:`memory`,source:c,schema:await c.getSchema(),data:s,rawText:r,file:n,parseConfig:o}}async function hR(e,t,n){let r=await sR.open(t,n),i=await r.getSchema(),a=await r.sampleRows(fR),o={meta:``,columnNames:i.map(e=>e.name),units:i.map(e=>e.unit),rows:a},s=await t.slice(0,lR).text();return{id:e,name:t.name,kind:`duckdb`,source:r,schema:i,data:o,rawText:s,parseConfig:y(s)}}async function gR(e,t,n,r,i=0,a){let o=await t.slice(0,lR).text();return uR(t.size,dR(t.size,o),i)===`memory`?mR(e,t.name,t,o,e=>n(e),a):hR(e,t,r)}function _R(e,t){return e instanceof File&&e.name===t.name&&e.size===t.size&&e.lastModified===t.lastModified}async function vR(e,t,n){let r=n.find(e=>e.kind===`memory`&&e.parseConfig&&_R(e.file,t)&&Ue(e.data.rows));if(!r)return null;let i=await t.slice(0,lR).text();if(!ee(r.parseConfig,y(i)))return null;let a={...r.data,rows:Me(Ue(r.data.rows))};return{id:e,name:t.name,kind:`memory`,source:new LE(a),schema:r.schema,data:a,rawText:r.rawText,file:t,parseConfig:r.parseConfig}}function yR(e){let t=new Set,n=0;for(let r of e){if(r.kind!==`memory`)continue;let e=Ue(r.data.rows)??r.data.rows;t.has(e)||(t.add(e),n+=r.data.rows.length*r.data.columnNames.length)}return n}var bR=4096,xR=[`.dat`,`.txt`,`.csv`,`.tsv`],SR=[we,r,Ee,E,l,d,P],CR=e=>{let t=e.lastIndexOf(`.`);return t<=0?``:e.slice(t).toLowerCase()},wR=e=>{let t=e.lastIndexOf(`.`);return(t<=0?e:e.slice(0,t)).toLowerCase()};async function TR(e){let t=new Uint8Array(await e.slice(0,bR).arrayBuffer()),n=CR(e.name),r=SR.filter(e=>e.extensions.includes(n));for(let n of[...r,...SR.filter(e=>!r.includes(e))])if(n.sniff(t,e.name))return n;return null}async function ER(e){return new Uint8Array(await e.slice(0,bR).arrayBuffer()).includes(0)}async function DR(e){let t=await Promise.all(e.map(TR)),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]&&CR(e.name)===n.ext),o=a.find(e=>wR(e.name)===wR(i.main.name))??(n.anyName&&a.length===1?a[0]:void 0);o&&(i.companions.push(o),r.add(o))}let i=new Set(SR.flatMap(e=>(e.companions??[]).map(e=>e.ext))),a=[];for(let t of e){if(r.has(t))continue;let e=CR(t.name);e===`.dat`&&await ER(t)?a.push({file:t.name,error:Error(`This COMTRADE .dat needs its .cfg file — drop both together.`)}):xR.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 OR=[...new Set([...xR,...SR.flatMap(e=>[...e.extensions,...(e.companions??[]).map(e=>e.ext)])])];function kR(e){let t=0;for(let n=0;n<e.length;n++)e[n]!==e[n]&&t++;if(t===0)return qM(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 qM(xM({type:new Ek,data:e,nullBitmap:n,length:e.length,nullCount:t}))}var AR=122880,jR=class{#e;#t;#n;#r=!1;#i=[];#a=0;#o;rows=0;constructor(e,t,n,r=AR){this.#e=e,this.#t=t,this.#n=new cN(n.map(e=>new lN(e.name,e.text?new kk:new Ek,!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?kR(i.subarray(0,t)):rF(i.slice(0,t),new kk)).data[0]});this.#i.push(new pF(this.#n,xM({type:new Bk(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 uF(this.#n,this.#i);this.#i=[],this.#a=0,await this.#e.insertArrowTable(e,{name:this.#t,create:!this.#r}),this.#r=!0}},MR=`This file's groups do not interleave in time: reading them together would hold too much in memory. Choose fewer groups, or split them.`,NR=e=>e.length*(1+e.columns.length);function PR(e){let t=e[Symbol.asyncIterator]();return{pull:async()=>{let e=await t.next();return e.done?null:e.value}}}function FR(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-=NR(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+=NR(o.value))>128e6))throw Error(MR)}};return n.map((e,t)=>({pull:()=>a(t)}))}function IR(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 LR=new Int32Array,RR={t:new Float64Array,cols:[],from:0};function zR(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 BR=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=VR(IR(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(MR)}};function VR(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 HR(e,t){let n=e.length,r=e.map(e=>e.t),i=Int32Array.from(e,e=>e.from),a=Int32Array.from(e,e=>zR(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 UR(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 WR(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];UR(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}UR(e,d,u,p,l-1,c[p]),o=c[l-1],t=d[u+l-1]}e.fill(t,o,e.length)}function GR(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 KR(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):LR}function qR(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=zR(i,e,r.from,i.length),o=new Int32Array(a-r.from);if(c.push(KR(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 GR(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),WR(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 JR(e,t,n,r,i,a=!1){let o=e.map((e,r)=>new BR(e,t[r],n[r])),s=-1;e.forEach((t,n)=>{!t.irregular&&(s<0||t.samples>e[s].samples)&&(s=n)});let c=e.map((e,t)=>t===s||!!e.irregular),l=o.filter((e,t)=>c[t]),u=l.length===1,d=0;for(;;){i?.throwIfAborted();for(let e of l)for(;!e.done&&e.rows()===0;)await e.fill();if(l.every(e=>e.rows()===0))break;let e=1/0;for(let t of l)t.done||(e=Math.min(e,t.lastTime()));for(let t=0;t<o.length;t++)if(!c[t])for(;!o[t].done&&o[t].lastTime()<=e;)await o[t].fill();let t=HR(l.map(e=>e.pending[0]??RR),e),n=[t];for(let e=0;e<o.length;e++)n.push(...qR(o[e],t,c[e],u&&c[e],a));d+=t.length,t.length&&await r({length:t.length,columns:n})}return d}var YR=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 XR(e,t,n){return M(await e.plan(t,n))}var ZR=(e,t,n)=>Math.max(0,Math.min(e,Math.max(1<<20,n),Math.floor(1e8/t)));function QR(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=Ze(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 $R(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 ez(e,t,n){let r=$R(e,t);return r<0?Math.ceil(n/4):r*(1+t.reduce((e,t)=>e+t.channels.length,0))}async function tz(e,t,n,r,i,a,o={}){let s=QR(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=>PR(d(e.streamGroup({...f,selection:[t]},t.group)))):FR(d(e.stream(f)),new Map(i.map((e,t)=>[e.group,t]))),m=$R(n,i),h=a===`memory`?new YR(s,ZR(m,s.length,r.size)):null,g=0,_=await JR(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 nz=``+new URL(`assets/importer.worker-CLBGjz4d.js`,import.meta.url).href,rz=``+new URL(`assets/h5wasmModule-BCQWU2Gw.js`,import.meta.url).href,iz=()=>new kE(`cancelled`);function az(){let e=AE(nz);return e.postMessage({type:`init`,h5Url:new URL(rz,location.href).href}),e}var oz=null,sz=e=>{typeof requestIdleCallback==`function`?requestIdleCallback(e,{timeout:5e3}):setTimeout(e,1e3)};function cz(e,t=az){t===az&&typeof Worker>`u`||(oz&&oz.make!==t&&(oz.w.terminate(),oz=null),oz??={w:t(),h5:!1,make:t},e&&!oz.h5&&(oz.h5=!0,oz.w.postMessage({type:`warm`})))}function lz(e){if(oz?.make!==e)return{w:e(),rewarm:null};let{w:t,h5:n}=oz;return oz=null,{w:t,rewarm:n}}function uz(e,t,n,r,i){return!r&&typeof Worker>`u`?dz(e,t,n,i):pz(e,t,n,r??az)}function dz(e,t,n,r=async e=>(await import(`./importers-BfJxlMFJ.js`)).importerFor(e)){let i=new U(t.main),a=null,o=null,c=e=>e.catch(e=>{throw n?.aborted?iz():s(e)});return{plan:()=>c((async()=>(a=await r(e),o=await XR(a,t,i)))()),read:(e,r,s={})=>(i.bytesRead=0,c(tz(a,t,o,i,e,r,{...s,signal:n}))),close(){}}}var fz=3e4;function pz(e,t,n,r){let{w:i,rewarm:a}=lz(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>fz&&p(Error(ce))},1e3),h=()=>p(iz());n?.addEventListener(`abort`,h,{once:!0}),i.onmessage=e=>{let t=e.data,n=o;n&&((t.type!==`alive`||t.work!==l)&&(c=Date.now()),t.type===`alive`?l=t.work:t.type===`plan`?(o=null,n.resolve(t.plan)):t.type===`progress`?n.on.progress?.(t.fraction):t.type===`chunk`?(u++,s=s.then(()=>n.on.chunk(t.chunk)).then(()=>{u--,c=Date.now(),i.postMessage({type:`ack`})},e=>{u--,p(e instanceof Error?e:Error(String(e)))})):t.type===`done`?s.then(()=>{o===n&&(o=null,n.resolve(t.result))}):f(Error(t.message)))},i.onerror=e=>f(e instanceof Error?e:Error(`The import worker failed.`));let g=(e,t={})=>new Promise((r,a)=>{if(n?.aborted){a(iz());return}if(d){a(Error(ce));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&&sz(()=>cz(a,r))}}}var mz=12e3,hz=(e,t)=>t.map(t=>({group:t,channels:e.groups[t].channels.map((e,t)=>t)}));function gz(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 _z(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:gz(e,n)}:null,splitKey:r,channels:n.reduce((e,t)=>e+t.channels.length,0),notes:e.notes,meta:e.meta,events:[]}}async function vz(e,t,n,r,i,a){let o={meta:``,columnNames:n.columns.map(e=>e.name),units:n.columns.map(e=>e.unit),rows:Me(n.table)},s=new LE(o);return{id:e,name:t,kind:`memory`,source:s,schema:await s.getSchema(),data:o,file:r,companions:i,info:{...a,events:n.events}}}async function yz(e,t,n,r,i,a,o,s,c){let l=LL().then(e=>e.connect());l.catch(()=>void 0);let u=tR(),d=QR(r,i),f=new jR({insertArrowTable:async(e,t)=>(await l).insertArrowTable(e,t)},u,d);try{let r=await n.read(i,`stream`,{progress:c,chunk:e=>f.append(e)});if(await f.flush(),f.rows===0)throw Error(`${t}: the file has no samples.`);let p=await l,m=await sR.attach(p,u,new Map(d.map(e=>[e.name,e.unit]))),h=await m.getSchema(),g=await m.sampleRows(mz);return{id:e,name:t,kind:`duckdb`,source:m,schema:h,data:{meta:``,columnNames:h.map(e=>e.name),units:h.map(e=>e.unit),rows:g},file:a,companions:o,info:{...s,events:r.events}}}catch(e){let t=await l.catch(()=>null);throw await t?.query(`DROP TABLE IF EXISTS ${BL(u)}`).catch(()=>void 0),await t?.close().catch(()=>void 0),e}}async function bz(e,t){let{main:n,companions:r}=e,i=uz(e.format,{main:n,companions:r,keys:e.keys},t.signal,t.createWorker,t.find),a=[];try{t.priorInMemoryValues+n.size/8>1e8&&LL().catch(()=>void 0);let o=await i.plan(),s=t.selection??t.initial??hz(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=>ez(o,e,n.size),budget:cR,used:t.priorInMemoryValues,notes:o.notes});if(!e)throw new kE(`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=ez(o,s,n.size),f=l.length>1?`${n.name} · ${o.groups[s[0].group].name}`:n.name,p=_z(o,e.format,s,u),m=crypto.randomUUID();if(uR(0,c,d)===`memory`){let e=await i.read(s,`memory`,{progress:t.onProgress});a.push(await vz(m,f,e,n,r,p)),d+=c}else a.push(await yz(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 kE(`cancelled`):e}finally{i.close()}}function xz(e){return e.filter(e=>e.type===`number`).map(e=>e.name)}function Sz(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 Cz(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 wz(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 Tz(e){return Math.max(2,Math.min(6,Math.floor(e/64)))}function Ez(e,t,n,r){let i=Math.max(e,t)-Math.min(e,t),a=n!==void 0&&n>0&&Number.isFinite(n)?n:wz(i,6);(a<=0||!Number.isFinite(a))&&(a=wz(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 Dz(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 Oz(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 kz={[-12]:`p`,[-9]:`n`,[-6]:`µ`,[-3]:`m`,0:``,3:`k`,6:`M`,9:`G`,12:`T`};function Az(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 jz(e,t){if(!Number.isFinite(e))return`—`;if(!(t>0)||!Number.isFinite(t))return Mz(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(Az(t/10**r))+kz[r]}return e.toFixed(Az(t))}function Mz(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)+kz[n]}var Nz=946684800,Pz=4102444800;function Fz(e,t,n){return/\(([^)]*)\)\s*$/.exec(e)?.[1].trim()===`s`&&n>t&&t>=Nz&&n<=Pz}var Iz=new Map;function Lz(e){let t=Iz.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=Lz(void 0)}Iz.set(e,t)}return t}var Rz=new Map,zz=(e,t)=>{let n=Math.round(e*1e3),r=Math.floor(n/1e3),i=`${t??``}|${r}`,a=Rz.get(i);if(!a){let e={};for(let{type:n,value:i}of Lz(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}`},Rz.size>=1024&&Rz.clear(),Rz.set(i,a)}return{...a,ms:String(n-r*1e3).padStart(3,`0`)}},Bz,Vz=new Set;function Hz(e){if(e!==void 0)try{new Intl.DateTimeFormat(void 0,{timeZone:e})}catch{e=void 0}if(e!==Bz){Bz=e;for(let e of Vz)e()}}var Uz=()=>Bz;function Wz(e){return Vz.add(e),()=>{Vz.delete(e)}}function Gz(e,t,n,r=Bz){let i=zz(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 Kz(e,t=Bz){let n=zz(e,t);return`${n.date} ${n.year} ${n.hms}.${n.ms}`}var qz=[`#fb923c`,`#60a5fa`,`#4ade80`,`#f87171`,`#facc15`,`#22d3ee`,`#f472b6`,`#2dd4bf`,`#94a3b8`,`#a3e635`];function Jz(e,t,n,r=qz){let i=r.length>0?r:qz;return e[t]??i[n%i.length]}function Yz(e){return[e===`light`?`#000000`:`#ffffff`,...qz.slice(0,9)]}function Xz(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:Yz(t)}var Zz=[`class`,`data-theme`,`data-color-scheme`];function Qz(e){return e?.closest(`[data-color-scheme]`)??document.documentElement}function $z(e){return Qz(e).getAttribute(`data-color-scheme`)===`light`?`light`:`dark`}function eB(e,t){let n=new MutationObserver(t),r=new Set([document.documentElement,Qz(e)]);for(let e of r)n.observe(e,{attributes:!0,attributeFilter:Zz});return()=>n.disconnect()}function tB(e,t){return!!t&&e.composedPath().includes(t)}var nB=[`min`,`max`,`mean`,`integral`,`first`,`last`,`delta`],rB=e=>`${e.channel}:${e.stat}`,iB=e=>`channel`in e?[e.channel]:[];function aB(e,t,n){switch(e){case`>`:return t>n;case`>=`:return t>=n;case`<`:return t<n;case`<=`:return t<=n;case`==`:return t===n;default:return t!==n}}function oB(e,t,n,r){switch(e){case`>`:case`>=`:return t<n-r;case`<`:case`<=`:return t>n+r;case`==`:return t!==n;default:return t===n}}var sB=()=>({prev:NaN,lo:0,hi:0});function cB(e,t){if(e.prev!==e.prev)return e.prev=e.lo=e.hi=t,!1;let n=t<e.prev&&e.prev-t>(e.hi-e.lo)/2;return n?e.lo=e.hi=t:(t<e.lo&&(e.lo=t),t>e.hi&&(e.hi=t)),e.prev=t,n}var lB=new Map,uB=e=>{let t=lB.get(e);return t||(t=new Intl.DateTimeFormat(`en-US`,{timeZone:e,hourCycle:`h23`,year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`}),lB.set(e,t)),t};function dB(e,t){let n={};for(let r of uB(t).formatToParts(new Date(Math.floor(e)*1e3)))n[r.type]=r.value;return(Date.UTC(+n.year,n.month-1,+n.day,+n.hour,+n.minute,+n.second)-Math.floor(e)*1e3)/1e3}function fB(e,t){let n=e+dB(e,t);return new Date(Math.floor(n)*1e3).toISOString().slice(0,10)}function pB(e,t,n){let[r,i,a]=e.split(`-`).map(Number),[o,s]=t.split(`:`).map(Number),c=Date.UTC(r,i-1,a,o,s)/1e3;return c-dB(c-dB(c,n),n)}var mB=(e,t)=>{let[n,r,i]=e.split(`-`).map(Number);return new Date(Date.UTC(n,r-1,i+t)).toISOString().slice(0,10)},hB=class{n=0;sum=0;min=1/0;max=-1/0;first=NaN;last=NaN;integral=0;lastT=NaN;add(e,t){t===t&&(this.n>0?this.integral+=(t+this.last)/2*(e-this.lastT):this.first=t,this.n++,this.sum+=t,t<this.min&&(this.min=t),t>this.max&&(this.max=t),this.last=t,this.lastT=e)}value(e){if(this.n===0)return null;switch(e){case`min`:return this.min;case`max`:return this.max;case`mean`:return this.sum/this.n;case`integral`:return this.integral;case`first`:return this.first;case`last`:return this.last;default:return this.last-this.first}}},gB=class{rule;kpis;#e;#t=null;#n=NaN;#r=sB();#i=!1;#a=NaN;#o=NaN;#s=NaN;#c=new Map;constructor(e,t=[]){this.rule=e,this.kpis=t,this.#e=[...new Set(t.map(e=>e.channel))]}#l(e){this.#t={tstart:e,acc:new Map(this.#e.map(e=>[e,new hB]))}}#u(e,t,n){let r={duration:(t??n)-e.tstart};for(let t of this.kpis)r[rB(t)]=e.acc.get(t.channel).value(t.stat);return{tstart:e.tstart,tend:t,kpis:r}}#d(e){let t=this.#t;return this.#t=null,t?this.#u(t,e,e):null}assumeOpen(e){this.#t||(this.#l(e),this.rule.kind===`condition`&&(this.#i=!0))}#f(e){let t=this.#c.get(e);if(!t){let n=this.rule;t=n.starts.map(t=>pB(e,t,n.tz)).sort((e,t)=>e-t),this.#c.set(e,t)}return t}#p(e){let t=this.rule.tz,n=fB(e,t),r=-1/0;for(let t of this.#f(n))t<=e&&(r=t);if(r>-1/0)return r;let i=this.#f(mB(n,-1));return i[i.length-1]}#m(e){let t=this.rule.tz,n=fB(e,t);for(let t of this.#f(n))if(t>e)return t;return this.#f(mB(n,1))[0]}feed(e,t,n){let r=[],i=this.rule,a=i.kind===`edge`||i.kind===`condition`?t(i.channel):void 0,o=this.#e.map(e=>[e,t(e)]);for(let t=0;t<e.length;t++){let s=e[t];if(i.kind===`window`){if(!(s>=this.#a&&s<this.#o)){let e=this.#p(s);if(this.#t){let t=this.#d(this.#o<=e?this.#o:e);t&&r.push(t)}this.#a=e,this.#o=this.#m(e),this.#l(e)}}else if(a&&i.kind!==`manual`){let e=a[t];if(e===e){if(i.kind===`edge`){let t=!1;if(i.on===`reset`){let n=this.#r.prev!==this.#r.prev;t=cB(this.#r,e),n&&!this.#t&&this.#l(s)}else if(this.#n===this.#n){let n=i.value??0;t=i.on===`change`?e!==this.#n:i.on===`rise`?this.#n<n&&e>=n:this.#n>n&&e<=n}if(this.#n=e,t){let e=this.#d(s);e&&r.push(e),this.#l(s)}}else if(!this.#i)aB(i.op,e,i.value)&&(this.#i=!0,this.#l(s));else if(oB(i.op,e,i.value,i.hysteresis??0)){this.#i=!1;let e=this.#d(s);e&&s-e.tstart>=(i.min_s??0)&&r.push(e)}}}let c=this.#t;if(c)for(let[e,n]of o)n&&c.acc.get(e).add(s,n[t]);this.#s=s,n?.(t,c?c.tstart:null)}return r}open(){let e=this.#t;return!e||this.rule.kind===`condition`&&this.#s-e.tstart<(this.rule.min_s??0)?null:this.#u(e,null,this.#s)}},_B=[{value:`span`,label:`Span (max − min)`},{value:`mean`,label:`Mean`},{value:`max`,label:`Max`},{value:`min`,label:`Min`}];function vB(e,t){let n=[],r=sB(),i=-1;for(let a=0;a<e.length;a++){let o=e[a][t];if(typeof o!=`number`)continue;let s=cB(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 yB(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=vB(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 bB(e,t){return yB(e,t)[0]??t[0]??``}function xB(e,t,n){if(n&&t.includes(n.channel)&&vB(e,n.channel).length>1)return{...n,metric:t.includes(n.metric)?n.metric:n.channel};let r=yB(e,t);if(r.length===0)return null;let i=r.find(e=>/time/i.test(e));return{channel:r[0],metric:i??r[0],stat:`span`}}function SB(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 CB(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 wB(e,t){return t.trim()===`s`||/time/i.test(e)}function TB(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?Mz(e):e.toFixed(r>=1e3?0:r>=100?1:3);return t.trim()?`${i} ${t.trim()}`:i}function EB(e,t){return`${e}::lap${t}`}function DB(e){let t=new Map,n=n=>{let r=t.get(n);return r||t.set(n,r=e.at.map(t=>pB(n,t,e.tz)).sort((e,t)=>e-t)),r},r=t=>{let r=fB(t,e.tz),i=-1/0;for(let e of n(r))e<=t&&(i=e);if(i>-1/0)return i;let a=n(mB(r,-1));return a[a.length-1]},i=t=>{let r=fB(t,e.tz);for(let e of n(r))if(e>t)return e;return n(mB(r,1))[0]},a=NaN,o=NaN,s={on:!1,edge:!1,at:NaN,event:!0,step(e){if(s.edge=s.on=!(e.t>=a&&e.t<o),!s.edge)return;let t=r(e.t);s.closeAt=o<=t?o:t,s.at=a=t,o=i(t)}};return s}function OB(e){switch(e.kind){case`compare`:{let t={on:!1,edge:!1,at:NaN,event:!1,step(n){let r=n.v(e.channel);r===r&&(t.on=aB(e.op,r,e.value)),t.at=n.t}};return t}case`elapsed`:{let t={on:!1,edge:!1,at:NaN,event:!1,step(n){let r=n.t-(e.from===`start`?n.start:n.ps);t.on=r===r&&(e.op===`>=`?r>=e.seconds:r<=e.seconds),t.at=n.t}};return t}case`change`:case`cross`:{let t=NaN,n={on:!1,edge:!1,at:NaN,event:!0,step(r){let i=r.v(e.channel);n.edge=!1,i===i&&(t===t&&(n.edge=e.kind===`change`?i!==t:e.dir===`rise`?t<e.value&&i>=e.value:t>e.value&&i<=e.value),t=i),n.on=n.edge,n.at=r.t}};return n}case`reset`:{let t=sB(),n={on:!1,edge:!1,at:NaN,event:!0,step(r){let i=r.v(e.channel);n.edge=i===i&&(t.prev===t.prev?cB(t,i):(cB(t,i),!0)),n.on=n.edge,n.at=r.t}};return n}case`clock`:return DB(e);case`parent-start`:{let e=!1,t={on:!1,edge:!1,at:NaN,event:!0,step(n){t.on=t.edge=!e,e=!0,t.at=n.ps}};return t}case`all`:case`any`:{let t=e.of.map(OB),n={on:!1,edge:!1,at:NaN,event:t.some(e=>e.event),step(r){for(let e of t)e.step(r);n.on=e.kind===`all`?t.every(e=>e.on):t.some(e=>e.on),n.edge=n.on&&t.some(e=>e.edge),n.at=r.t}};return n}default:return{on:!1,edge:!1,at:NaN,event:!0,step(){}}}}var kB=(e,t)=>e.kind===t||(e.kind===`all`||e.kind===`any`)&&e.of.some(e=>kB(e,t));function AB(e){let t=new Set,n=e=>{`channel`in e&&t.add(e.channel),(e.kind===`all`||e.kind===`any`)&&e.of.forEach(n)};return n(e.start),n(e.end),[...t]}var jB=class{rule;#e;#t;#n=NaN;#r=!1;#i=NaN;#a=NaN;#o=NaN;#s=NaN;#c;#l;constructor(e){this.rule=e,this.#c=kB(e.end,`parent-end`),this.#l=e.end.kind===`next-start`,this.#u()}#u(){this.#e=OB(this.rule.start),this.#t=OB(this.rule.end),this.#r=!1}#d(e,t,n){let r=this.rule.limits;if(!r)return[];let i=[],a=r.from===`start`?e:this.#n;return r.expectedWithin_s!=null&&t-a>r.expectedWithin_s&&i.push(`late`),r.max_s!=null&&t-e>r.max_s&&i.push(`too-long`),n&&r.min_s!=null&&t-e<r.min_s&&i.push(`too-short`),i}#f(e,t,n=!1){let r={tstart:this.#i,tend:e,flags:this.#d(this.#i,e,!0)};n&&(r.incomplete=!0),t.push(r),this.#i=this.#o=NaN}parentStart(e){this.#n=e,this.#i=this.#a=this.#o=NaN,this.#u()}parentEnd(e,t){this.#i===this.#i&&this.#f(e,t,!this.#c),this.#a=NaN,this.#n=NaN}step(e,t,n){this.#n!==this.#n&&(this.#n=e);let r={t:e,v:t,ps:this.#n,start:this.#i},i=this.#e,a=this.#t;i.step(r),a.step(r);let o=i.on&&(!this.#r||i.edge);this.#r=i.on;let s=i.event&&!(this.rule.start.kind===`all`||this.rule.start.kind===`any`)?i.at:e;if(this.#i===this.#i&&!this.#l&&e>this.#i){let t=this.rule.ignoreDips_s??0;a.on?t>0&&!a.event?(this.#o!==this.#o&&(this.#o=e),e-this.#o>=t&&this.#f(this.#o,n)):this.#f(e,n):this.#o=NaN}let c=e=>{this.#i===this.#i&&this.#f(this.#l&&i.closeAt!==void 0?i.closeAt:e,n),this.#i=e},l=this.#i!==this.#i||this.#l,u=this.rule.minHold_s??0;this.#a===this.#a?i.on?e-this.#a>=u&&(l&&c(this.#a),this.#a=NaN):this.#a=NaN:o&&l&&(u>0&&!i.event?this.#a=s:c(s)),this.#s=e}open(){return this.#i===this.#i?{tstart:this.#i,tend:null,flags:this.#d(this.#i,this.#s,!1)}:null}},MB=class{#e;constructor(e){let t=[],n=r=>{for(let i of e)i.parentId===r&&(t.push(i),n(i.id))};n(null),this.#e=t.map(e=>({...e,runner:new jB(e.rule),count:0,current:0,kids:[]})),this.#e.forEach((e,t)=>{e.parentId&&this.#e.find(t=>t.id===e.parentId).kids.push(t)})}#t(e,t,n,r){let i=this.#e[e];for(let e of t)n.push({...e,definitionId:i.id,index:i.current,...r?{parentIndex:r}:{}})}#n(e){let t=this.#e[e].parentId;return t?this.#e.find(e=>e.id===t).current:void 0}#r(e,t,n){for(let r of this.#e[e].kids){this.#r(r,t,n);let i=[];this.#e[r].runner.parentEnd(t,i),this.#t(r,i,n,this.#e[e].current)}}#i(e,t,n,r){let i=this.#e[e],a=i.runner.open()?.tstart,o=[];i.runner.step(t,n,o);let s=i.runner.open()?.tstart;if(o.length)for(let t of o)this.#r(e,t.tend,r),r.push({...t,definitionId:i.id,index:i.current,...this.#n(e)?{parentIndex:this.#n(e)}:{}});if(s!==void 0&&s!==a){i.current=++i.count;for(let e of i.kids)this.#e[e].current=this.#e[e].count=0,this.#e[e].runner.parentStart(s)}if(s!==void 0)for(let e of i.kids)this.#i(e,t,n,r)}feed(e,t){let n=new Map,r=e=>(n.has(e)||n.set(e,t(e)),n.get(e)),i=[],a=0,o=e=>{let t=r(e);return t?t[a]:NaN};for(;a<e.length;a++)for(let t=0;t<this.#e.length;t++)this.#e[t].parentId||this.#i(t,e[a],o,i);return i}open(){let e=[];return this.#e.forEach((t,n)=>{let r=t.runner.open(),i=this.#n(n);r&&(!t.parentId||this.#e.find(e=>e.id===t.parentId).runner.open())&&e.push({...r,definitionId:t.id,index:t.current,...i?{parentIndex:i}:{}})}),e}},NB=new Set([`>`,`>=`,`<`,`<=`,`==`,`!=`]),PB=e=>typeof e==`number`&&Number.isFinite(e),FB=e=>typeof e==`string`&&e.length>0;function IB(e,t){let n=e;if(!n||typeof n!=`object`)return!1;switch(n.kind){case`parent-start`:case`parent-end`:case`next-start`:case`manual`:return!0;case`all`:case`any`:return t<3&&Array.isArray(n.of)&&n.of.length>0&&n.of.every(e=>IB(e,t+1));case`compare`:return FB(n.channel)&&NB.has(n.op)&&PB(n.value);case`change`:case`reset`:return FB(n.channel);case`cross`:return FB(n.channel)&&(n.dir===`rise`||n.dir===`fall`)&&PB(n.value);case`elapsed`:return(n.from===`parent-start`||n.from===`start`)&&(n.op===`>=`||n.op===`<=`)&&PB(n.seconds);case`clock`:return Array.isArray(n.at)&&n.at.length>0&&n.at.every(e=>typeof e==`string`&&/^\d\d:\d\d$/.test(e))&&FB(n.tz);default:return!1}}function LB(e){if(!Array.isArray(e))return[];let t=e.filter(e=>{let t=e?.rule,n=t?.limits;return FB(e?.id)&&FB(e?.name)&&(e.parentId===null||FB(e.parentId))&&!!t&&IB(t.start,1)&&IB(t.end,1)&&(t.minHold_s===void 0||PB(t.minHold_s))&&(t.ignoreDips_s===void 0||PB(t.ignoreDips_s))&&(n===void 0||typeof n==`object`&&[`expectedWithin_s`,`min_s`,`max_s`].every(e=>n[e]===void 0||PB(n[e])))}),n=new Set(t.map(e=>e.id));return t.filter(e=>e.parentId===null||n.has(e.parentId)).map(e=>{let t=Array.isArray(e.kpis)?e.kpis.filter(e=>FB(e?.channel)&&nB.includes(e.stat)).slice(0,50):[],n=FB(e.show?.channel)&&nB.includes(e.show.stat)?{channel:e.show.channel,stat:e.show.stat}:void 0;return{id:e.id,name:e.name,parentId:e.parentId,rule:e.rule,...t.length?{kpis:t}:{},...n?{show:n}:{}}})}var RB=`Cycle time`,zB=65536;async function BB(e,t,n){let r=[...new Set([t,...n])],i=[];for(let n=0;;n+=zB){let a=await e.readColumns(r,n,zB),o=a[t]?.length??0;if(o>0&&i.push(a),o<zB)break}let a=e=>{if(!i.some(t=>t[e]))return;let n=new Float64Array(i.reduce((e,n)=>e+n[t].length,0)).fill(NaN),r=0;for(let a of i)a[e]&&n.set(a[e],r),r+=a[t].length;return n},o=new Map;for(let e of r){let n=e===t?void 0:a(e);n&&o.set(e,n)}return{t:a(t)??new Float64Array,cols:o}}function VB(e,t){let n=new MB(t);return[...n.feed(e.t,t=>e.cols.get(t)),...n.open()]}var HB=e=>[...new Set(e.flatMap(e=>[...AB(e.rule),...(e.kpis??[]).map(e=>e.channel)]))],UB=e=>`${e.channel} ${e.stat}`;function WB(e,t,n){let r=GB(e.t,t.tstart),i=t.tend===null?e.t.length:GB(e.t,t.tend),a={};for(let t of n){let n=e.cols.get(t.channel),o=new hB;if(n)for(let t=r;t<i;t++)o.add(e.t[t],n[t]);a[UB(t)]=o.value(t.stat)}return a}function GB(e,t){let n=0,r=e.length;for(;n<r;){let i=n+r>>1;e[i]<t?n=i+1:r=i}return n}function KB(e,t,n){let r=GB(e.t,n.tstart),i=n.tend===null?e.t.length:GB(e.t,n.tend),a=e.t.subarray(r,i),o={[RB]:a.map(e=>e-n.tstart),[t]:a};for(let[t,n]of e.cols)o[t]=n.subarray(r,i);return o}var qB=e=>e.replace(`-`,` `);function JB(e,t,n,r){let i=Object.fromEntries(n.map(e=>[e.id,e.name])),a=e=>n.find(t=>t.id===e)?.kpis??[],o=e=>r?WB(r,e,a(e.definitionId)):{},s=n.filter(e=>e.parentId===t).map(e=>e.id),c=e=>e.tend===null?null:e.tend-e.tstart,l=e.filter(e=>s.includes(e.definitionId)).sort((e,t)=>e.tstart-t.tstart);return{cycles:e.filter(e=>e.definitionId===t).sort((e,t)=>e.index-t.index).map(e=>{let t=l.filter(t=>t.parentIndex===e.index),n={Cycle:e.index,Start:e.tstart,End:e.tend,Duration:c(e)};for(let e of s){let r=t.filter(t=>t.definitionId===e);n[`${i[e]??e} duration`]=r.length&&r.every(e=>e.tend!==null)?r.reduce((e,t)=>e+t.tend-t.tstart,0):null}return Object.assign(n,o(e)),n.Flags=[...e.flags.map(qB),...t.flatMap(e=>e.flags.map(t=>`${i[e.definitionId]??e.definitionId} ${qB(t)}`))].join(`, `),n}),phases:l.map(e=>({Cycle:e.parentIndex,Phase:i[e.definitionId]??e.definitionId,Start:e.tstart,End:e.tend,Duration:c(e),...o(e),Flags:e.flags.map(qB).join(`, `)}))}}function YB(e){if(e.length===0)return``;let t=Object.keys(e[0]),n=e=>e===null?``:typeof e==`number`?String(e):/[",\n]/.test(e)?`"${e.replace(/"/g,`""`)}"`:e;return[t.map(n).join(`,`),...e.map(e=>t.map(t=>n(e[t]??null)).join(`,`))].join(`
70
+ `)),r=H(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 fR=12e3;async function pR(e,t,n){let r=y(n),i=typeof Worker>`u`?k(n,r):await NE({rawText:n,config:r}),a=new LE(i);return{id:e,name:t,kind:`memory`,source:a,schema:await a.getSchema(),data:i,rawText:n,parseConfig:r}}async function mR(e,t,n,r,i=e=>e.text(),a){let o=y(r),s=typeof Worker>`u`?await PE({rawText:await i(n),config:o},a):await PE({file:n,config:o},a),c=new LE(s);return{id:e,name:t,kind:`memory`,source:c,schema:await c.getSchema(),data:s,rawText:r,file:n,parseConfig:o}}async function hR(e,t,n){let r=await sR.open(t,n),i=await r.getSchema(),a=await r.sampleRows(fR),o={meta:``,columnNames:i.map(e=>e.name),units:i.map(e=>e.unit),rows:a},s=await t.slice(0,lR).text();return{id:e,name:t.name,kind:`duckdb`,source:r,schema:i,data:o,rawText:s,parseConfig:y(s)}}async function gR(e,t,n,r,i=0,a){let o=await t.slice(0,lR).text();return uR(t.size,dR(t.size,o),i)===`memory`?mR(e,t.name,t,o,e=>n(e),a):hR(e,t,r)}function _R(e,t){return e instanceof File&&e.name===t.name&&e.size===t.size&&e.lastModified===t.lastModified}async function vR(e,t,n){let r=n.find(e=>e.kind===`memory`&&e.parseConfig&&_R(e.file,t)&&Ue(e.data.rows));if(!r)return null;let i=await t.slice(0,lR).text();if(!ee(r.parseConfig,y(i)))return null;let a={...r.data,rows:Me(Ue(r.data.rows))};return{id:e,name:t.name,kind:`memory`,source:new LE(a),schema:r.schema,data:a,rawText:r.rawText,file:t,parseConfig:r.parseConfig}}function yR(e){let t=new Set,n=0;for(let r of e){if(r.kind!==`memory`)continue;let e=Ue(r.data.rows)??r.data.rows;t.has(e)||(t.add(e),n+=r.data.rows.length*r.data.columnNames.length)}return n}var bR=4096,xR=[`.dat`,`.txt`,`.csv`,`.tsv`],SR=[we,r,Ee,E,l,d,P],CR=e=>{let t=e.lastIndexOf(`.`);return t<=0?``:e.slice(t).toLowerCase()},wR=e=>{let t=e.lastIndexOf(`.`);return(t<=0?e:e.slice(0,t)).toLowerCase()};async function TR(e){let t=new Uint8Array(await e.slice(0,bR).arrayBuffer()),n=CR(e.name),r=SR.filter(e=>e.extensions.includes(n));for(let n of[...r,...SR.filter(e=>!r.includes(e))])if(n.sniff(t,e.name))return n;return null}async function ER(e){return new Uint8Array(await e.slice(0,bR).arrayBuffer()).includes(0)}async function DR(e){let t=await Promise.all(e.map(TR)),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]&&CR(e.name)===n.ext),o=a.find(e=>wR(e.name)===wR(i.main.name))??(n.anyName&&a.length===1?a[0]:void 0);o&&(i.companions.push(o),r.add(o))}let i=new Set(SR.flatMap(e=>(e.companions??[]).map(e=>e.ext))),a=[];for(let t of e){if(r.has(t))continue;let e=CR(t.name);e===`.dat`&&await ER(t)?a.push({file:t.name,error:Error(`This COMTRADE .dat needs its .cfg file — drop both together.`)}):xR.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 OR=[...new Set([...xR,...SR.flatMap(e=>[...e.extensions,...(e.companions??[]).map(e=>e.ext)])])];function kR(e){let t=0;for(let n=0;n<e.length;n++)e[n]!==e[n]&&t++;if(t===0)return qM(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 qM(xM({type:new Ek,data:e,nullBitmap:n,length:e.length,nullCount:t}))}var AR=122880,jR=class{#e;#t;#n;#r=!1;#i=[];#a=0;#o;rows=0;constructor(e,t,n,r=AR){this.#e=e,this.#t=t,this.#n=new cN(n.map(e=>new lN(e.name,e.text?new kk:new Ek,!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?kR(i.subarray(0,t)):rF(i.slice(0,t),new kk)).data[0]});this.#i.push(new pF(this.#n,xM({type:new Bk(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 uF(this.#n,this.#i);this.#i=[],this.#a=0,await this.#e.insertArrowTable(e,{name:this.#t,create:!this.#r}),this.#r=!0}},MR=`This file's groups do not interleave in time: reading them together would hold too much in memory. Choose fewer groups, or split them.`,NR=e=>e.length*(1+e.columns.length);function PR(e){let t=e[Symbol.asyncIterator]();return{pull:async()=>{let e=await t.next();return e.done?null:e.value}}}function FR(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-=NR(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+=NR(o.value))>128e6))throw Error(MR)}};return n.map((e,t)=>({pull:()=>a(t)}))}function IR(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 LR=new Int32Array,RR={t:new Float64Array,cols:[],from:0};function zR(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 BR=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=VR(IR(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(MR)}};function VR(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 HR(e,t){let n=e.length,r=e.map(e=>e.t),i=Int32Array.from(e,e=>e.from),a=Int32Array.from(e,e=>zR(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 UR(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 WR(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];UR(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}UR(e,d,u,p,l-1,c[p]),o=c[l-1],t=d[u+l-1]}e.fill(t,o,e.length)}function GR(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 KR(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):LR}function qR(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=zR(i,e,r.from,i.length),o=new Int32Array(a-r.from);if(c.push(KR(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 GR(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),WR(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 JR(e,t,n,r,i,a=!1){let o=e.map((e,r)=>new BR(e,t[r],n[r])),s=-1;e.forEach((t,n)=>{!t.irregular&&(s<0||t.samples>e[s].samples)&&(s=n)});let c=e.map((e,t)=>t===s||!!e.irregular),l=o.filter((e,t)=>c[t]),u=l.length===1,d=0;for(;;){i?.throwIfAborted();for(let e of l)for(;!e.done&&e.rows()===0;)await e.fill();if(l.every(e=>e.rows()===0))break;let e=1/0;for(let t of l)t.done||(e=Math.min(e,t.lastTime()));for(let t=0;t<o.length;t++)if(!c[t])for(;!o[t].done&&o[t].lastTime()<=e;)await o[t].fill();let t=HR(l.map(e=>e.pending[0]??RR),e),n=[t];for(let e=0;e<o.length;e++)n.push(...qR(o[e],t,c[e],u&&c[e],a));d+=t.length,t.length&&await r({length:t.length,columns:n})}return d}var YR=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 XR(e,t,n){return M(await e.plan(t,n))}var ZR=(e,t,n)=>Math.max(0,Math.min(e,Math.max(1<<20,n),Math.floor(1e8/t)));function QR(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=Ze(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 $R(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 ez(e,t,n){let r=$R(e,t);return r<0?Math.ceil(n/4):r*(1+t.reduce((e,t)=>e+t.channels.length,0))}async function tz(e,t,n,r,i,a,o={}){let s=QR(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=>PR(d(e.streamGroup({...f,selection:[t]},t.group)))):FR(d(e.stream(f)),new Map(i.map((e,t)=>[e.group,t]))),m=$R(n,i),h=a===`memory`?new YR(s,ZR(m,s.length,r.size)):null,g=0,_=await JR(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 nz=``+new URL(`assets/importer.worker-CLBGjz4d.js`,import.meta.url).href,rz=``+new URL(`assets/h5wasmModule-BCQWU2Gw.js`,import.meta.url).href,iz=()=>new kE(`cancelled`);function az(){let e=AE(nz);return e.postMessage({type:`init`,h5Url:new URL(rz,location.href).href}),e}var oz=null,sz=e=>{typeof requestIdleCallback==`function`?requestIdleCallback(e,{timeout:5e3}):setTimeout(e,1e3)};function cz(e,t=az){t===az&&typeof Worker>`u`||(oz&&oz.make!==t&&(oz.w.terminate(),oz=null),oz??={w:t(),h5:!1,make:t},e&&!oz.h5&&(oz.h5=!0,oz.w.postMessage({type:`warm`})))}function lz(e){if(oz?.make!==e)return{w:e(),rewarm:null};let{w:t,h5:n}=oz;return oz=null,{w:t,rewarm:n}}function uz(e,t,n,r,i){return!r&&typeof Worker>`u`?dz(e,t,n,i):pz(e,t,n,r??az)}function dz(e,t,n,r=async e=>(await import(`./importers-rg_Kg8Bl.js`)).importerFor(e)){let i=new U(t.main),a=null,o=null,c=e=>e.catch(e=>{throw n?.aborted?iz():s(e)});return{plan:()=>c((async()=>(a=await r(e),o=await XR(a,t,i)))()),read:(e,r,s={})=>(i.bytesRead=0,c(tz(a,t,o,i,e,r,{...s,signal:n}))),close(){}}}var fz=3e4;function pz(e,t,n,r){let{w:i,rewarm:a}=lz(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>fz&&p(Error(ce))},1e3),h=()=>p(iz());n?.addEventListener(`abort`,h,{once:!0}),i.onmessage=e=>{let t=e.data,n=o;n&&((t.type!==`alive`||t.work!==l)&&(c=Date.now()),t.type===`alive`?l=t.work:t.type===`plan`?(o=null,n.resolve(t.plan)):t.type===`progress`?n.on.progress?.(t.fraction):t.type===`chunk`?(u++,s=s.then(()=>n.on.chunk(t.chunk)).then(()=>{u--,c=Date.now(),i.postMessage({type:`ack`})},e=>{u--,p(e instanceof Error?e:Error(String(e)))})):t.type===`done`?s.then(()=>{o===n&&(o=null,n.resolve(t.result))}):f(Error(t.message)))},i.onerror=e=>f(e instanceof Error?e:Error(`The import worker failed.`));let g=(e,t={})=>new Promise((r,a)=>{if(n?.aborted){a(iz());return}if(d){a(Error(ce));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&&sz(()=>cz(a,r))}}}var mz=12e3,hz=(e,t)=>t.map(t=>({group:t,channels:e.groups[t].channels.map((e,t)=>t)}));function gz(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 _z(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:gz(e,n)}:null,splitKey:r,channels:n.reduce((e,t)=>e+t.channels.length,0),notes:e.notes,meta:e.meta,events:[]}}async function vz(e,t,n,r,i,a){let o={meta:``,columnNames:n.columns.map(e=>e.name),units:n.columns.map(e=>e.unit),rows:Me(n.table)},s=new LE(o);return{id:e,name:t,kind:`memory`,source:s,schema:await s.getSchema(),data:o,file:r,companions:i,info:{...a,events:n.events}}}async function yz(e,t,n,r,i,a,o,s,c){let l=LL().then(e=>e.connect());l.catch(()=>void 0);let u=tR(),d=QR(r,i),f=new jR({insertArrowTable:async(e,t)=>(await l).insertArrowTable(e,t)},u,d);try{let r=await n.read(i,`stream`,{progress:c,chunk:e=>f.append(e)});if(await f.flush(),f.rows===0)throw Error(`${t}: the file has no samples.`);let p=await l,m=await sR.attach(p,u,new Map(d.map(e=>[e.name,e.unit]))),h=await m.getSchema(),g=await m.sampleRows(mz);return{id:e,name:t,kind:`duckdb`,source:m,schema:h,data:{meta:``,columnNames:h.map(e=>e.name),units:h.map(e=>e.unit),rows:g},file:a,companions:o,info:{...s,events:r.events}}}catch(e){let t=await l.catch(()=>null);throw await t?.query(`DROP TABLE IF EXISTS ${BL(u)}`).catch(()=>void 0),await t?.close().catch(()=>void 0),e}}async function bz(e,t){let{main:n,companions:r}=e,i=uz(e.format,{main:n,companions:r,keys:e.keys},t.signal,t.createWorker,t.find),a=[];try{t.priorInMemoryValues+n.size/8>1e8&&LL().catch(()=>void 0);let o=await i.plan(),s=t.selection??t.initial??hz(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=>ez(o,e,n.size),budget:cR,used:t.priorInMemoryValues,notes:o.notes});if(!e)throw new kE(`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=ez(o,s,n.size),f=l.length>1?`${n.name} · ${o.groups[s[0].group].name}`:n.name,p=_z(o,e.format,s,u),m=crypto.randomUUID();if(uR(0,c,d)===`memory`){let e=await i.read(s,`memory`,{progress:t.onProgress});a.push(await vz(m,f,e,n,r,p)),d+=c}else a.push(await yz(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 kE(`cancelled`):e}finally{i.close()}}function xz(e){return e.filter(e=>e.type===`number`).map(e=>e.name)}function Sz(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 Cz(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 wz(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 Tz(e){return Math.max(2,Math.min(6,Math.floor(e/64)))}function Ez(e,t,n,r){let i=Math.max(e,t)-Math.min(e,t),a=n!==void 0&&n>0&&Number.isFinite(n)?n:wz(i,6);(a<=0||!Number.isFinite(a))&&(a=wz(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 Dz(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 Oz(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 kz={[-12]:`p`,[-9]:`n`,[-6]:`µ`,[-3]:`m`,0:``,3:`k`,6:`M`,9:`G`,12:`T`};function Az(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 jz(e,t){if(!Number.isFinite(e))return`—`;if(!(t>0)||!Number.isFinite(t))return Mz(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(Az(t/10**r))+kz[r]}return e.toFixed(Az(t))}function Mz(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)+kz[n]}var Nz=946684800,Pz=4102444800;function Fz(e,t,n){return/\(([^)]*)\)\s*$/.exec(e)?.[1].trim()===`s`&&n>t&&t>=Nz&&n<=Pz}var Iz=new Map;function Lz(e){let t=Iz.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=Lz(void 0)}Iz.set(e,t)}return t}var Rz=new Map,zz=(e,t)=>{let n=Math.round(e*1e3),r=Math.floor(n/1e3),i=`${t??``}|${r}`,a=Rz.get(i);if(!a){let e={};for(let{type:n,value:i}of Lz(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}`},Rz.size>=1024&&Rz.clear(),Rz.set(i,a)}return{...a,ms:String(n-r*1e3).padStart(3,`0`)}},Bz,Vz=new Set;function Hz(e){if(e!==void 0)try{new Intl.DateTimeFormat(void 0,{timeZone:e})}catch{e=void 0}if(e!==Bz){Bz=e;for(let e of Vz)e()}}var Uz=()=>Bz;function Wz(e){return Vz.add(e),()=>{Vz.delete(e)}}function Gz(e,t,n,r=Bz){let i=zz(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 Kz(e,t=Bz){let n=zz(e,t);return`${n.date} ${n.year} ${n.hms}.${n.ms}`}var qz=[`#fb923c`,`#60a5fa`,`#4ade80`,`#f87171`,`#facc15`,`#22d3ee`,`#f472b6`,`#2dd4bf`,`#94a3b8`,`#a3e635`];function Jz(e,t,n,r=qz){let i=r.length>0?r:qz;return e[t]??i[n%i.length]}function Yz(e){return[e===`light`?`#000000`:`#ffffff`,...qz.slice(0,9)]}function Xz(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:Yz(t)}var Zz=[`class`,`data-theme`,`data-color-scheme`];function Qz(e){return e?.closest(`[data-color-scheme]`)??document.documentElement}function $z(e){return Qz(e).getAttribute(`data-color-scheme`)===`light`?`light`:`dark`}function eB(e,t){let n=new MutationObserver(t),r=new Set([document.documentElement,Qz(e)]);for(let e of r)n.observe(e,{attributes:!0,attributeFilter:Zz});return()=>n.disconnect()}function tB(e,t){return!!t&&e.composedPath().includes(t)}var nB=[`min`,`max`,`mean`,`integral`,`first`,`last`,`delta`],rB=e=>`${e.channel}:${e.stat}`,iB=e=>`channel`in e?[e.channel]:[];function aB(e,t,n){switch(e){case`>`:return t>n;case`>=`:return t>=n;case`<`:return t<n;case`<=`:return t<=n;case`==`:return t===n;default:return t!==n}}function oB(e,t,n,r){switch(e){case`>`:case`>=`:return t<n-r;case`<`:case`<=`:return t>n+r;case`==`:return t!==n;default:return t===n}}var sB=()=>({prev:NaN,lo:0,hi:0});function cB(e,t){if(e.prev!==e.prev)return e.prev=e.lo=e.hi=t,!1;let n=t<e.prev&&e.prev-t>(e.hi-e.lo)/2;return n?e.lo=e.hi=t:(t<e.lo&&(e.lo=t),t>e.hi&&(e.hi=t)),e.prev=t,n}var lB=new Map,uB=e=>{let t=lB.get(e);return t||(t=new Intl.DateTimeFormat(`en-US`,{timeZone:e,hourCycle:`h23`,year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`}),lB.set(e,t)),t};function dB(e,t){let n={};for(let r of uB(t).formatToParts(new Date(Math.floor(e)*1e3)))n[r.type]=r.value;return(Date.UTC(+n.year,n.month-1,+n.day,+n.hour,+n.minute,+n.second)-Math.floor(e)*1e3)/1e3}function fB(e,t){let n=e+dB(e,t);return new Date(Math.floor(n)*1e3).toISOString().slice(0,10)}function pB(e,t,n){let[r,i,a]=e.split(`-`).map(Number),[o,s]=t.split(`:`).map(Number),c=Date.UTC(r,i-1,a,o,s)/1e3;return c-dB(c-dB(c,n),n)}var mB=(e,t)=>{let[n,r,i]=e.split(`-`).map(Number);return new Date(Date.UTC(n,r-1,i+t)).toISOString().slice(0,10)},hB=class{n=0;sum=0;min=1/0;max=-1/0;first=NaN;last=NaN;integral=0;lastT=NaN;add(e,t){t===t&&(this.n>0?this.integral+=(t+this.last)/2*(e-this.lastT):this.first=t,this.n++,this.sum+=t,t<this.min&&(this.min=t),t>this.max&&(this.max=t),this.last=t,this.lastT=e)}value(e){if(this.n===0)return null;switch(e){case`min`:return this.min;case`max`:return this.max;case`mean`:return this.sum/this.n;case`integral`:return this.integral;case`first`:return this.first;case`last`:return this.last;default:return this.last-this.first}}},gB=class{rule;kpis;#e;#t=null;#n=NaN;#r=sB();#i=!1;#a=NaN;#o=NaN;#s=NaN;#c=new Map;constructor(e,t=[]){this.rule=e,this.kpis=t,this.#e=[...new Set(t.map(e=>e.channel))]}#l(e){this.#t={tstart:e,acc:new Map(this.#e.map(e=>[e,new hB]))}}#u(e,t,n){let r={duration:(t??n)-e.tstart};for(let t of this.kpis)r[rB(t)]=e.acc.get(t.channel).value(t.stat);return{tstart:e.tstart,tend:t,kpis:r}}#d(e){let t=this.#t;return this.#t=null,t?this.#u(t,e,e):null}assumeOpen(e){this.#t||(this.#l(e),this.rule.kind===`condition`&&(this.#i=!0))}#f(e){let t=this.#c.get(e);if(!t){let n=this.rule;t=n.starts.map(t=>pB(e,t,n.tz)).sort((e,t)=>e-t),this.#c.set(e,t)}return t}#p(e){let t=this.rule.tz,n=fB(e,t),r=-1/0;for(let t of this.#f(n))t<=e&&(r=t);if(r>-1/0)return r;let i=this.#f(mB(n,-1));return i[i.length-1]}#m(e){let t=this.rule.tz,n=fB(e,t);for(let t of this.#f(n))if(t>e)return t;return this.#f(mB(n,1))[0]}feed(e,t,n){let r=[],i=this.rule,a=i.kind===`edge`||i.kind===`condition`?t(i.channel):void 0,o=this.#e.map(e=>[e,t(e)]);for(let t=0;t<e.length;t++){let s=e[t];if(i.kind===`window`){if(!(s>=this.#a&&s<this.#o)){let e=this.#p(s);if(this.#t){let t=this.#d(this.#o<=e?this.#o:e);t&&r.push(t)}this.#a=e,this.#o=this.#m(e),this.#l(e)}}else if(a&&i.kind!==`manual`){let e=a[t];if(e===e){if(i.kind===`edge`){let t=!1;if(i.on===`reset`){let n=this.#r.prev!==this.#r.prev;t=cB(this.#r,e),n&&!this.#t&&this.#l(s)}else if(this.#n===this.#n){let n=i.value??0;t=i.on===`change`?e!==this.#n:i.on===`rise`?this.#n<n&&e>=n:this.#n>n&&e<=n}if(this.#n=e,t){let e=this.#d(s);e&&r.push(e),this.#l(s)}}else if(!this.#i)aB(i.op,e,i.value)&&(this.#i=!0,this.#l(s));else if(oB(i.op,e,i.value,i.hysteresis??0)){this.#i=!1;let e=this.#d(s);e&&s-e.tstart>=(i.min_s??0)&&r.push(e)}}}let c=this.#t;if(c)for(let[e,n]of o)n&&c.acc.get(e).add(s,n[t]);this.#s=s,n?.(t,c?c.tstart:null)}return r}open(){let e=this.#t;return!e||this.rule.kind===`condition`&&this.#s-e.tstart<(this.rule.min_s??0)?null:this.#u(e,null,this.#s)}},_B=[{value:`span`,label:`Span (max − min)`},{value:`mean`,label:`Mean`},{value:`max`,label:`Max`},{value:`min`,label:`Min`}];function vB(e,t){let n=[],r=sB(),i=-1;for(let a=0;a<e.length;a++){let o=e[a][t];if(typeof o!=`number`)continue;let s=cB(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 yB(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=vB(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 bB(e,t){return yB(e,t)[0]??t[0]??``}function xB(e,t,n){if(n&&t.includes(n.channel)&&vB(e,n.channel).length>1)return{...n,metric:t.includes(n.metric)?n.metric:n.channel};let r=yB(e,t);if(r.length===0)return null;let i=r.find(e=>/time/i.test(e));return{channel:r[0],metric:i??r[0],stat:`span`}}function SB(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 CB(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 wB(e,t){return t.trim()===`s`||/time/i.test(e)}function TB(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?Mz(e):e.toFixed(r>=1e3?0:r>=100?1:3);return t.trim()?`${i} ${t.trim()}`:i}function EB(e,t){return`${e}::lap${t}`}function DB(e){let t=new Map,n=n=>{let r=t.get(n);return r||t.set(n,r=e.at.map(t=>pB(n,t,e.tz)).sort((e,t)=>e-t)),r},r=t=>{let r=fB(t,e.tz),i=-1/0;for(let e of n(r))e<=t&&(i=e);if(i>-1/0)return i;let a=n(mB(r,-1));return a[a.length-1]},i=t=>{let r=fB(t,e.tz);for(let e of n(r))if(e>t)return e;return n(mB(r,1))[0]},a=NaN,o=NaN,s={on:!1,edge:!1,at:NaN,event:!0,step(e){if(s.edge=s.on=!(e.t>=a&&e.t<o),!s.edge)return;let t=r(e.t);s.closeAt=o<=t?o:t,s.at=a=t,o=i(t)}};return s}function OB(e){switch(e.kind){case`compare`:{let t={on:!1,edge:!1,at:NaN,event:!1,step(n){let r=n.v(e.channel);r===r&&(t.on=aB(e.op,r,e.value)),t.at=n.t}};return t}case`elapsed`:{let t={on:!1,edge:!1,at:NaN,event:!1,step(n){let r=n.t-(e.from===`start`?n.start:n.ps);t.on=r===r&&(e.op===`>=`?r>=e.seconds:r<=e.seconds),t.at=n.t}};return t}case`change`:case`cross`:{let t=NaN,n={on:!1,edge:!1,at:NaN,event:!0,step(r){let i=r.v(e.channel);n.edge=!1,i===i&&(t===t&&(n.edge=e.kind===`change`?i!==t:e.dir===`rise`?t<e.value&&i>=e.value:t>e.value&&i<=e.value),t=i),n.on=n.edge,n.at=r.t}};return n}case`reset`:{let t=sB(),n={on:!1,edge:!1,at:NaN,event:!0,step(r){let i=r.v(e.channel);n.edge=i===i&&(t.prev===t.prev?cB(t,i):(cB(t,i),!0)),n.on=n.edge,n.at=r.t}};return n}case`clock`:return DB(e);case`parent-start`:{let e=!1,t={on:!1,edge:!1,at:NaN,event:!0,step(n){t.on=t.edge=!e,e=!0,t.at=n.ps}};return t}case`all`:case`any`:{let t=e.of.map(OB),n={on:!1,edge:!1,at:NaN,event:t.some(e=>e.event),step(r){for(let e of t)e.step(r);n.on=e.kind===`all`?t.every(e=>e.on):t.some(e=>e.on),n.edge=n.on&&t.some(e=>e.edge),n.at=r.t}};return n}default:return{on:!1,edge:!1,at:NaN,event:!0,step(){}}}}var kB=(e,t)=>e.kind===t||(e.kind===`all`||e.kind===`any`)&&e.of.some(e=>kB(e,t));function AB(e){let t=new Set,n=e=>{`channel`in e&&t.add(e.channel),(e.kind===`all`||e.kind===`any`)&&e.of.forEach(n)};return n(e.start),n(e.end),[...t]}var jB=class{rule;#e;#t;#n=NaN;#r=!1;#i=NaN;#a=NaN;#o=NaN;#s=NaN;#c;#l;constructor(e){this.rule=e,this.#c=kB(e.end,`parent-end`),this.#l=e.end.kind===`next-start`,this.#u()}#u(){this.#e=OB(this.rule.start),this.#t=OB(this.rule.end),this.#r=!1}#d(e,t,n){let r=this.rule.limits;if(!r)return[];let i=[],a=r.from===`start`?e:this.#n;return r.expectedWithin_s!=null&&t-a>r.expectedWithin_s&&i.push(`late`),r.max_s!=null&&t-e>r.max_s&&i.push(`too-long`),n&&r.min_s!=null&&t-e<r.min_s&&i.push(`too-short`),i}#f(e,t,n=!1){let r={tstart:this.#i,tend:e,flags:this.#d(this.#i,e,!0)};n&&(r.incomplete=!0),t.push(r),this.#i=this.#o=NaN}parentStart(e){this.#n=e,this.#i=this.#a=this.#o=NaN,this.#u()}parentEnd(e,t){this.#i===this.#i&&this.#f(e,t,!this.#c),this.#a=NaN,this.#n=NaN}step(e,t,n){this.#n!==this.#n&&(this.#n=e);let r={t:e,v:t,ps:this.#n,start:this.#i},i=this.#e,a=this.#t;i.step(r),a.step(r);let o=i.on&&(!this.#r||i.edge);this.#r=i.on;let s=i.event&&!(this.rule.start.kind===`all`||this.rule.start.kind===`any`)?i.at:e;if(this.#i===this.#i&&!this.#l&&e>this.#i){let t=this.rule.ignoreDips_s??0;a.on?t>0&&!a.event?(this.#o!==this.#o&&(this.#o=e),e-this.#o>=t&&this.#f(this.#o,n)):this.#f(e,n):this.#o=NaN}let c=e=>{this.#i===this.#i&&this.#f(this.#l&&i.closeAt!==void 0?i.closeAt:e,n),this.#i=e},l=this.#i!==this.#i||this.#l,u=this.rule.minHold_s??0;this.#a===this.#a?i.on?e-this.#a>=u&&(l&&c(this.#a),this.#a=NaN):this.#a=NaN:o&&l&&(u>0&&!i.event?this.#a=s:c(s)),this.#s=e}open(){return this.#i===this.#i?{tstart:this.#i,tend:null,flags:this.#d(this.#i,this.#s,!1)}:null}},MB=class{#e;constructor(e){let t=[],n=r=>{for(let i of e)i.parentId===r&&(t.push(i),n(i.id))};n(null),this.#e=t.map(e=>({...e,runner:new jB(e.rule),count:0,current:0,kids:[]})),this.#e.forEach((e,t)=>{e.parentId&&this.#e.find(t=>t.id===e.parentId).kids.push(t)})}#t(e,t,n,r){let i=this.#e[e];for(let e of t)n.push({...e,definitionId:i.id,index:i.current,...r?{parentIndex:r}:{}})}#n(e){let t=this.#e[e].parentId;return t?this.#e.find(e=>e.id===t).current:void 0}#r(e,t,n){for(let r of this.#e[e].kids){this.#r(r,t,n);let i=[];this.#e[r].runner.parentEnd(t,i),this.#t(r,i,n,this.#e[e].current)}}#i(e,t,n,r){let i=this.#e[e],a=i.runner.open()?.tstart,o=[];i.runner.step(t,n,o);let s=i.runner.open()?.tstart;if(o.length)for(let t of o)this.#r(e,t.tend,r),r.push({...t,definitionId:i.id,index:i.current,...this.#n(e)?{parentIndex:this.#n(e)}:{}});if(s!==void 0&&s!==a){i.current=++i.count;for(let e of i.kids)this.#e[e].current=this.#e[e].count=0,this.#e[e].runner.parentStart(s)}if(s!==void 0)for(let e of i.kids)this.#i(e,t,n,r)}feed(e,t){let n=new Map,r=e=>(n.has(e)||n.set(e,t(e)),n.get(e)),i=[],a=0,o=e=>{let t=r(e);return t?t[a]:NaN};for(;a<e.length;a++)for(let t=0;t<this.#e.length;t++)this.#e[t].parentId||this.#i(t,e[a],o,i);return i}open(){let e=[];return this.#e.forEach((t,n)=>{let r=t.runner.open(),i=this.#n(n);r&&(!t.parentId||this.#e.find(e=>e.id===t.parentId).runner.open())&&e.push({...r,definitionId:t.id,index:t.current,...i?{parentIndex:i}:{}})}),e}},NB=new Set([`>`,`>=`,`<`,`<=`,`==`,`!=`]),PB=e=>typeof e==`number`&&Number.isFinite(e),FB=e=>typeof e==`string`&&e.length>0;function IB(e,t){let n=e;if(!n||typeof n!=`object`)return!1;switch(n.kind){case`parent-start`:case`parent-end`:case`next-start`:case`manual`:return!0;case`all`:case`any`:return t<3&&Array.isArray(n.of)&&n.of.length>0&&n.of.every(e=>IB(e,t+1));case`compare`:return FB(n.channel)&&NB.has(n.op)&&PB(n.value);case`change`:case`reset`:return FB(n.channel);case`cross`:return FB(n.channel)&&(n.dir===`rise`||n.dir===`fall`)&&PB(n.value);case`elapsed`:return(n.from===`parent-start`||n.from===`start`)&&(n.op===`>=`||n.op===`<=`)&&PB(n.seconds);case`clock`:return Array.isArray(n.at)&&n.at.length>0&&n.at.every(e=>typeof e==`string`&&/^\d\d:\d\d$/.test(e))&&FB(n.tz);default:return!1}}function LB(e){if(!Array.isArray(e))return[];let t=e.filter(e=>{let t=e?.rule,n=t?.limits;return FB(e?.id)&&FB(e?.name)&&(e.parentId===null||FB(e.parentId))&&!!t&&IB(t.start,1)&&IB(t.end,1)&&(t.minHold_s===void 0||PB(t.minHold_s))&&(t.ignoreDips_s===void 0||PB(t.ignoreDips_s))&&(n===void 0||typeof n==`object`&&[`expectedWithin_s`,`min_s`,`max_s`].every(e=>n[e]===void 0||PB(n[e])))}),n=new Set(t.map(e=>e.id));return t.filter(e=>e.parentId===null||n.has(e.parentId)).map(e=>{let t=Array.isArray(e.kpis)?e.kpis.filter(e=>FB(e?.channel)&&nB.includes(e.stat)).slice(0,50):[],n=FB(e.show?.channel)&&nB.includes(e.show.stat)?{channel:e.show.channel,stat:e.show.stat}:void 0;return{id:e.id,name:e.name,parentId:e.parentId,rule:e.rule,...t.length?{kpis:t}:{},...n?{show:n}:{}}})}var RB=`Cycle time`,zB=65536;async function BB(e,t,n){let r=[...new Set([t,...n])],i=[];for(let n=0;;n+=zB){let a=await e.readColumns(r,n,zB),o=a[t]?.length??0;if(o>0&&i.push(a),o<zB)break}let a=e=>{if(!i.some(t=>t[e]))return;let n=new Float64Array(i.reduce((e,n)=>e+n[t].length,0)).fill(NaN),r=0;for(let a of i)a[e]&&n.set(a[e],r),r+=a[t].length;return n},o=new Map;for(let e of r){let n=e===t?void 0:a(e);n&&o.set(e,n)}return{t:a(t)??new Float64Array,cols:o}}function VB(e,t){let n=new MB(t);return[...n.feed(e.t,t=>e.cols.get(t)),...n.open()]}var HB=e=>[...new Set(e.flatMap(e=>[...AB(e.rule),...(e.kpis??[]).map(e=>e.channel)]))],UB=e=>`${e.channel} ${e.stat}`;function WB(e,t,n){let r=GB(e.t,t.tstart),i=t.tend===null?e.t.length:GB(e.t,t.tend),a={};for(let t of n){let n=e.cols.get(t.channel),o=new hB;if(n)for(let t=r;t<i;t++)o.add(e.t[t],n[t]);a[UB(t)]=o.value(t.stat)}return a}function GB(e,t){let n=0,r=e.length;for(;n<r;){let i=n+r>>1;e[i]<t?n=i+1:r=i}return n}function KB(e,t,n){let r=GB(e.t,n.tstart),i=n.tend===null?e.t.length:GB(e.t,n.tend),a=e.t.subarray(r,i),o={[RB]:a.map(e=>e-n.tstart),[t]:a};for(let[t,n]of e.cols)o[t]=n.subarray(r,i);return o}var qB=e=>e.replace(`-`,` `);function JB(e,t,n,r){let i=Object.fromEntries(n.map(e=>[e.id,e.name])),a=e=>n.find(t=>t.id===e)?.kpis??[],o=e=>r?WB(r,e,a(e.definitionId)):{},s=n.filter(e=>e.parentId===t).map(e=>e.id),c=e=>e.tend===null?null:e.tend-e.tstart,l=e.filter(e=>s.includes(e.definitionId)).sort((e,t)=>e.tstart-t.tstart);return{cycles:e.filter(e=>e.definitionId===t).sort((e,t)=>e.index-t.index).map(e=>{let t=l.filter(t=>t.parentIndex===e.index),n={Cycle:e.index,Start:e.tstart,End:e.tend,Duration:c(e)};for(let e of s){let r=t.filter(t=>t.definitionId===e);n[`${i[e]??e} duration`]=r.length&&r.every(e=>e.tend!==null)?r.reduce((e,t)=>e+t.tend-t.tstart,0):null}return Object.assign(n,o(e)),n.Flags=[...e.flags.map(qB),...t.flatMap(e=>e.flags.map(t=>`${i[e.definitionId]??e.definitionId} ${qB(t)}`))].join(`, `),n}),phases:l.map(e=>({Cycle:e.parentIndex,Phase:i[e.definitionId]??e.definitionId,Start:e.tstart,End:e.tend,Duration:c(e),...o(e),Flags:e.flags.map(qB).join(`, `)}))}}function YB(e){if(e.length===0)return``;let t=Object.keys(e[0]),n=e=>e===null?``:typeof e==`number`?String(e):/[",\n]/.test(e)?`"${e.replace(/"/g,`""`)}"`:e;return[t.map(n).join(`,`),...e.map(e=>t.map(t=>n(e[t]??null)).join(`,`))].join(`
71
71
  `)}var XB=(e,t,n)=>`kymoscope-workbook-export|3|${e}|${t??``}|${n??``}`,ZB=e=>new TextEncoder().encode(e);async function QB(e,t){return{format:`kymoscope-workbook`,v:2,...await oe(t,ZB(JSON.stringify(e)),C)}}async function $B(e,t){let n=t.password?JSON.stringify(await QB(e,t.password)):JSON.stringify(e),r=await Se(await z(t.key),ZB(n),XB(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 eV(e){return!!e&&typeof e==`object`&&e.format===`kymoscope-workbook`}function tV(e){return eV(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 nV=e=>{try{return JSON.parse(new TextDecoder().decode(e))}catch{throw new kE(`bad_file`)}};async function rV(e,t){let n=tV(e);if(!n)throw new kE(`bad_file`);let r=e;if(n.v===3){let i=e;if(!t.key)throw new kE(`scope_key_required`,{scope:n.scope,scopeId:n.scopeId});let a;try{a=await Re(await z(t.key),i,XB(i.scope,i.scope_id,i.inner))}catch{throw new kE(`bad_file`)}if(r=nV(a),!n.password)return r;if(r?.v!==2||!eV(r))throw new kE(`bad_file`)}if(!t.password)throw new kE(`password_required`);let i;try{i=await v(t.password,r,C)}catch{throw new kE(`wrong_password`)}return nV(i)}var iV=new Set(Object.keys(Ut));function aV(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`||!iV.has(n)||!r||![r.x,r.y,r.w,r.h].every(e=>typeof e==`number`&&Number.isFinite(e))?[]:[{...e,rect:Kt(n,r,96)}]}):[]}var oV=e=>({name:e.name,xKey:e.xKey,panels:e.panels,panelChartSettings:e.panelChartSettings,panelChartBackgrounds:e.panelChartBackgrounds,...e.liveWindowSeconds===void 0?{}:{liveWindowSeconds:e.liveWindowSeconds}});function sV(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 cV(e){return{version:2,worksheets:e.worksheets.map(e=>({...oV(e),panelChartSettings:sV(e.panelChartSettings)})),activeWorksheet:Math.max(0,e.worksheets.findIndex(t=>t.id===e.activeWorksheetId)),mathChannels:e.channels.map(e=>({name:e.name,formula:e.formula,units:e.units,enabled:e.enabled,...e.description?{description:e.description}:{}})),liveWindowSeconds:e.liveWindowSeconds,laps:e.laps?{channel:e.laps.channel,metric:e.laps.metric,stat:e.laps.stat}:null,segments:e.segments??null,...e.cycles?.length?{cycles:e.cycles}:{}}}function lV(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 uV(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 dV(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 fV(e){let t=await dV(e),n;try{n=JSON.parse(t)}catch{return{worksheets:[],errors:[`Not a valid JSON file.`]}}return vV(n)}var pV=new Set(_B.map(e=>e.value)),mV=/^(#(?:[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 hV(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):mV.test(e.trim())}function gV(e){if(Array.isArray(e))return e.map(gV);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`&&!hV(r)||(t[n]=r&&typeof r==`object`?gV(r):r);return t}function _V(e){return!e||typeof e!=`object`?{}:Object.fromEntries(Object.entries(e).filter(([,e])=>e===null||hV(e)))}function vV(e){let t=e,n=t&&typeof t==`object`?t.version:void 0;if(!t||n!==1&&n!==2||!Array.isArray(t.worksheets))return{worksheets:[],errors:[`Unrecognized format. Is this a Kymoscope workbook file?`],activeIndex:0,mathChannels:[],liveWindowSeconds:void 0,laps:void 0,segments:void 0,cycles:[]};let r=[],i=[];if(t.worksheets.forEach((e,t)=>{let n=e;if(typeof n?.name!=`string`||typeof n.xKey!=`string`){i.push(`Worksheet #${t+1} skipped: missing name or xKey.`);return}r.push({id:crypto.randomUUID(),name:n.name,xKey:n.xKey,panels:aV(n.panels),panelChartSettings:gV(n.panelChartSettings),panelChartBackgrounds:_V(n.panelChartBackgrounds),...ar(n.liveWindowSeconds)})}),n===1)return{worksheets:r,errors:i,activeIndex:0,mathChannels:[],liveWindowSeconds:void 0,laps:void 0,segments:void 0,cycles:[]};let a=(Array.isArray(t.mathChannels)?t.mathChannels:[]).flatMap(e=>{let t=e;return typeof t?.name!=`string`||!t.name.trim()||typeof t.formula!=`string`?[]:[{name:t.name,formula:t.formula,units:typeof t.units==`string`?t.units:``,enabled:t.enabled!==!1,...typeof t.description==`string`&&t.description?{description:t.description}:{}}]}),o=t.liveWindowSeconds,s=t.laps,c=s&&typeof s.channel==`string`&&typeof s.metric==`string`&&pV.has(s.stat)?{channel:s.channel,metric:s.metric,stat:s.stat}:null,l=t.segments,u=e=>typeof e==`string`&&/^[0-9a-f-]{36}$/i.test(e),d=l===void 0?void 0:l&&u(l.historyId)&&(l.definitionId==null||u(l.definitionId))&&(l.referenceId==null||u(l.referenceId))?{historyId:l.historyId,definitionId:l.definitionId??null,referenceId:l.referenceId??null}:null,f=typeof t.activeWorksheet==`number`&&Number.isInteger(t.activeWorksheet)?t.activeWorksheet:0;return{worksheets:r,errors:i,mathChannels:a,laps:c,segments:d,cycles:LB(t.cycles),activeIndex:Math.min(Math.max(0,f),Math.max(0,r.length-1)),liveWindowSeconds:o===null||typeof o==`number`&&o>0?o:void 0}}function yV(e){return e.some(e=>e.panels.length>0)}function bV(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:aV(t.panels),panelChartSettings:gV(t.panelChartSettings),panelChartBackgrounds:_V(t.panelChartBackgrounds),...ar(t.liveWindowSeconds)}}function xV(e){if(!e||typeof e!=`object`)return null;let t=e,n=t.kind;if(typeof n!=`string`||!iV.has(n))return null;let r=rr({__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 SV(e){let t=await dV(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=tV(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=bV(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=xV(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 fV(e);return i.worksheets.length===0&&i.errors.length>0?{type:`error`,errors:i.errors}:{type:`workspace`,worksheets:i.worksheets,errors:i.errors}}var CV=OR;function wV(e){let t=e.toLowerCase();return!t.startsWith(`.`)&&CV.some(e=>t.endsWith(e))}function TV(e,t=``){let n={name:t,path:``,dirs:[],files:[],allPaths:[]};for(let t of e){if(!wV(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 EV(e){return e.map(e=>({path:e.webkitRelativePath||e.name,file:e}))}async function DV(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 OV(){return typeof window.showDirectoryPicker==`function`}async function kV(){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 AV={1:`dohstRIUBeOkkAXOTXhhEkXanWzz-V4M518JBqTehRM`};function jV(e){let t=e.replace(/-/g,`+`).replace(/_/g,`/`)+`===`.slice((e.length+3)%4),n=atob(t),r=new Uint8Array(n.length);for(let e=0;e<n.length;e++)r[e]=n.charCodeAt(e);return r}function MV(e,t){let n=e.toLowerCase(),r=t.toLowerCase();return n.startsWith(`*.`)?r.endsWith(n.slice(1))&&r.length>n.length-1:n===r}function NV(e){try{let t=JSON.parse(new TextDecoder().decode(jV(e)));return typeof t.sub!=`string`||typeof t.exp!=`number`||!Array.isArray(t.domains)||!t.domains.every(e=>typeof e==`string`)||t.kid!==void 0&&typeof t.kid!=`string`?null:t}catch{return null}}async function PV(e,t,n,r){if(!e)return{ok:!1,reason:`missing`};if(typeof e!=`string`)return{ok:!1,reason:`malformed`};let i=e.trim().split(`.`);if(i.length!==2||!i[0]||!i[1])return{ok:!1,reason:`malformed`};let a=NV(i[0]);if(!a)return{ok:!1,reason:`malformed`};let o=a.kid??`1`,s=typeof n==`string`?n:Object.hasOwn(n,o)?n[o]:void 0;if(!s)return{ok:!1,reason:`bad_signature`};let c;try{let e=await crypto.subtle.importKey(`raw`,jV(s),`Ed25519`,!1,[`verify`]);c=await crypto.subtle.verify(`Ed25519`,e,jV(i[1]),new TextEncoder().encode(i[0]))}catch{return{ok:!1,reason:`unsupported`}}return c?a.exp<r?{ok:!1,reason:`expired`}:a.domains.some(e=>MV(e,t))?{ok:!0,sub:a.sub,exp:a.exp}:{ok:!1,reason:`domain`}:{ok:!1,reason:`bad_signature`}}function FV(e,t){return PV(e,t,AV,Date.now()/1e3)}var Q={sans:`system-ui, sans-serif`,mono:`ui-monospace, monospace`};function IV(){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 LV(){return _t(`span`,{className:`kymoscope-attribution`,role:`note`,style:{position:`absolute`,right:10,bottom:8,zIndex:50,pointerEvents:`none`,font:`500 11px/1.2 var(--font-sans, system-ui)`,letterSpacing:`0.02em`,padding:`4px 8px`,borderRadius:999,color:`var(--text-muted, #8a93a6)`,background:`color-mix(in oklch, var(--bg-elevated, #1b2130) 88%, transparent)`,border:`1px solid var(--border, #33405a)`},children:[`Powered by `,q(`strong`,{style:{color:`var(--accent, #f5a524)`,fontWeight:700},children:`Kymoscope`})]})}function RV(){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 zV(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 BV(e){return Math.max(0,(e>>1)-1)}var VV=2.5,HV=`#version 300 es
72
72
  in vec2 a_corner; // static quad corner: (±1, ±1)
73
73
  in vec2 a_a; // per-instance: segment start (CSS px)
@@ -614,7 +614,7 @@ void main() {
614
614
  `),o=i*1.25,s=n[0][0],c=n[0][1];t.kind===`box`&&(s=Math.min(n[0][0],n[1][0]),c=Math.min(n[0][1],n[1][1])-a.length*o-7),a.forEach((t,n)=>e.fillText(t,s+6,c+2+n*o))}var AZ={solid:void 0,dashed:`5 4`,dotted:`1 4`};function jZ(e,t,n){if(!e||!(n===`x`?e.x:e.y))return null;if(n===`x`){let n=qH(e,t.value);return n>=e.left-.5&&n<=e.left+e.width+.5?[n,e.top,n,e.top+e.height]:null}let r=YH(e,t.value);return r>=e.top-.5&&r<=e.top+e.height+.5?[e.left,r,e.left+e.width,r]:null}var MZ=ot(function({frame:e,alarm:t,axis:n}){let r=jZ(pt(e.subscribe,e.get),t,n);if(!r)return null;let i=t.linked?NZ(r,n):null;return _t(`svg`,{className:`kymo-alarm`,"aria-hidden":`true`,children:[q(`line`,{x1:r[0],y1:r[1],x2:r[2],y2:r[3],stroke:t.color,strokeWidth:t.width,strokeDasharray:t.linked===`active`?nU.join(` `):AZ[t.style]}),i?q(`path`,{"data-alert-glyph":``,d:tU,transform:`translate(${i[0]} ${i[1]})`,fill:t.color}):null]})});function NZ(e,t){return t===`y`?[e[2]-10-3,e[1]-10-2]:[e[0]+3,e[1]+2]}function PZ(e,t,n,r,i){let a=jZ(t,n,r);if(a){if(e.save(),e.scale(i,i),e.strokeStyle=n.color,e.lineWidth=n.width,e.setLineDash(n.linked===`active`?nU:AZ[n.style]?.split(` `).map(Number)??[]),e.beginPath(),e.moveTo(a[0],a[1]),e.lineTo(a[2],a[3]),e.stroke(),n.linked){let t=NZ(a,r);iU(e,t[0],t[1],n.color)}e.restore()}}function FZ(e,t,n){return e.handlers?.wsId===n?e.handlers:e.handlers={wsId:n,onViewXRangeChange:r=>{t.view.setXRange(r,n),e.emitter.emit(`viewchange`,r)},onCursorX:e=>{try{t.view.setCursorX(e,n)}catch{}},cursor:{get:()=>{try{return t.view.cursorX(n)}catch{return null}},subscribe:e=>t.on(`cursorchange`,t=>{t.worksheetId===n&&e(t.x)})},onContextMenu:t=>e.emitter.emit(`contextmenu`,t),xyzRef:t=>{e.xyz=t},onAnnotations:n=>t.charts.setAnnotations(e.chartId,n),onAnnotationToolEnd:()=>{e.annotationTool=null,BZ(t).bump(),e.emitter.emit(`annotationtool`,null)},onAnnotationSelect:t=>{e.selectedAnnotation=t,e.emitter.emit(`annotationselect`,t)},onMarkSelect:t=>e.emitter.emit(`markselect`,t)}}var IZ=new WeakMap;function LZ(e,t){let n=IZ.get(e);n||IZ.set(e,n=new Map);let r=n.get(t);return r||n.set(t,r=n=>e.view.setLiveWindow(n,t)),r}var RZ=class{mounts=new Map;version=0;listeners=new Set;root=null;engine;constructor(e){this.engine=e}subscribe=e=>(this.listeners.add(e),()=>{this.listeners.delete(e)});getVersion=()=>this.version;bump(){this.version++;for(let e of[...this.listeners])e()}add(e){this.mounts.set(e.key,e),this.root||(this.root=ht(document.createElement(`div`)),this.root.render(q(KZ,{engine:this.engine,registry:this}))),this.bump()}remove(e){this.mounts.delete(e)&&this.bump()}refresh(){this.bump()}dispose(){this.mounts.clear(),this.root?.unmount(),this.root=null}},zZ=new WeakMap;function BZ(e){let t=zZ.get(e);return t||(t=new RZ(e),zZ.set(e,t)),t}function VZ(e,t,n,r={}){e.charts.get(t);let i=BZ(e),a={key:crypto.randomUUID(),chartId:t,element:n,options:r,shiftDatasetId:null,emitter:RV(),xyz:null,annotationTool:null,selectedAnnotation:null,plotFrame:QH(),status:null,data:null};i.add(a);let o=!1;return{chartId:t,status:()=>a.status,data:()=>a.data,on:(e,t)=>a.emitter.on(e,t),exportPng(){let r=Array.from(n.querySelectorAll(`canvas`));if(r.length===0)return Promise.reject(new kE(`export_failed`,{reason:`nothing to export`}));let i=document.createElement(`canvas`);i.width=r[0].width,i.height=r[0].height;let o=i.getContext(`2d`);if(!o)return Promise.reject(new kE(`export_failed`,{reason:`canvas unavailable`}));for(let e of r)o.drawImage(e,0,0);let s=e.charts.get(t),c=nQ(s.settings,i1(e).alertLines()),l=a.plotFrame.get()?.x?a.plotFrame.get():null,u=e.getState(),d=u.worksheets.find(e=>e.charts.some(e=>e.id===t)),f=aQ(s.annotations,d?rQ(u.marks,u.selection,d.xKey):[],l),p=tr(c);return p&&n.clientWidth>0&&PZ(o,a.plotFrame.get(),p.alarm,p.axis,i.width/n.clientWidth),f.length&&n.clientWidth>0&&OZ(o,f,n.clientWidth,n.clientHeight,i.width/n.clientWidth,Q.sans,l),new Promise((e,t)=>i.toBlob(n=>n?e(n):t(new kE(`export_failed`,{reason:`encode failed`})),`image/png`))},autoscale(){a.xyz?.autoscale()},setShiftMode(e){a.shiftDatasetId!==e&&(a.shiftDatasetId=e,i.bump())},setAnnotationTool(e){a.annotationTool=e?{...e}:null,i.bump()},annotationTool:()=>a.annotationTool,selectedAnnotation:()=>a.selectedAnnotation,setOptions(e){a.options={...e},i.bump()},destroy(){o||(o=!0,a.emitter.clear(),i.remove(a.key))}}}function HZ(e){zZ.get(e)?.refresh()}function UZ(e){zZ.get(e)?.dispose(),zZ.delete(e)}function WZ(e){let t=new MutationObserver(e);return t.observe(document.documentElement,{attributes:!0,attributeFilter:[`data-color-scheme`,`class`,`data-theme`]}),()=>t.disconnect()}var GZ=()=>{let e=document.documentElement;return`${e.getAttribute(`data-color-scheme`)??``}|${e.getAttribute(`data-theme`)??``}|${e.className}`};function KZ({engine:e,registry:t}){pt(t.subscribe,t.getVersion);let n=i1(e),r=pt(n.store.subscribe,n.store.get),i=new Map;for(let e of t.mounts.values()){let t=r.worksheets.find(t=>t.panels.some(t=>t.id===e.chartId));if(!t)continue;let n=i.get(t.id)??{worksheet:t,mounts:[]};n.mounts.push(e),i.set(t.id,n)}return q(gt,{children:[...i.values()].map(t=>q(XZ,{engine:e,worksheet:t.worksheet,mounts:t.mounts},t.worksheet.id))})}var qZ=1e3,JZ=.25;function YZ(e,t,n){let[r,i]=ft(0),a=K(0),o=K(0);return W(()=>{a.current&&=(o.current=performance.now()-a.current,0)}),W(()=>{if(!n)return;let r=0,s=-1,c=0,l=n=>{if(r=yH(l),a.current||n<c||wH())return;let u=0;for(let n of e)t.includes(n.id)&&(u+=n.source.version());u!==s&&(s=u,c=n+o.current*(1/JZ-1),a.current=performance.now(),st(()=>i(e=>e+1)))};return r=yH(l),()=>bH(r)},[n,e,t]),dt(()=>n?e.map(e=>t.includes(e.id)?{...e,dataset:e.source.snapshot(qZ)}:e):e,[e,t,n,r])}function XZ({engine:e,worksheet:t,mounts:n}){let r=i1(e),i=pt(r.store.subscribe,r.store.get),a=r.derived(),o=i.xRanges[t.id]??null,s=dt(()=>i.live.filter(e=>e.kind===`data`),[i.live]),c=a.selectedLive.length,l=e=>{let n=t.panelChartSettings[e];return n?.kind===`multiband`&&n.beacon?.enabled===!0},u=c>0&&t.panels.some(e=>e.kind!==`multiband`&&e.kind!==`camera`||c>1&&!l(e.id)),d=YZ(s,i.selection,u),f=r.alertLines(),p=ZX({worksheet:eQ(t,f),viewXRange:o,selectedIds:i.selection,selectedDatasets:a.selectedDatasets,liveConnections:d,mathChannels:a.channels,datasetOffsets:i.offsets,datasetColors:i.colors,datasetPalette:i.palette}),m=K(IV()).current,h=pt(WZ,GZ),g=t.id,_=LZ(e,g),v=i.licensed,y=a.selectedLive[0]??null,b=e=>i.datasets.find(t=>t.id===e)??Object.values(a.laps).flatMap(e=>e.laps).find(t=>t.id===e);return q(gt,{children:n.map(n=>{let r=t.panels.find(e=>e.id===n.chartId);if(!r)return null;let s=n.shiftDatasetId?a.selectedDatasets.find(e=>e.id===n.shiftDatasetId):void 0,c=FZ(n,e,g),l=nQ(t.panelChartSettings[r.id],f);return mt(q(lQ,{mount:n,annotations:t.panelChartSettings[r.id]?.annotations,marks:rQ(i.marks,i.selection,t.xKey),onMarkSelect:c.onMarkSelect,alarm:tr(l),onAnnotations:c.onAnnotations,onAnnotationToolEnd:c.onAnnotationToolEnd,onAnnotationSelect:c.onAnnotationSelect,render:u=>tZ({panel:r,settings:l,background:n.options.style?.background??t.panelChartBackgrounds[r.id]??null,styleToken:JSON.stringify([h,n.options.theme,n.options.style,Q]),data:p,xKey:t.xKey,height:u,viewXRange:o,onViewXRangeChange:c.onViewXRangeChange,onCursorX:c.onCursorX,liveZoom:m,liveWindowSeconds:t.liveWindowSeconds===void 0?i.liveWindowSeconds:t.liveWindowSeconds,onLiveWindowChange:_,beaconLive:y,findDataset:b,live:i.live,selection:i.selection,cursor:c.cursor,video:e.video.sources(),recordings:oX(a.selectedDatasets,i.offsets),shiftMode:s?ZZ(e,s.id,s.name):void 0,onContextMenu:c.onContextMenu,xyzRef:c.xyzRef}),licensed:v},n.key),n.element,n.key)})})}function ZZ(e,t,n){let r=0;return{label:n,onDragStart:()=>{r=e.getState().datasets.find(e=>e.id===t)?.offset??0},onDragOffset:n=>e.datasets.setOffset(t,r+n)}}var QZ=[],$Z=new WeakMap;function eQ(e,t){if(!t.size)return e;let n=$Z.get(e);if(n&&n.lines===t)return n.out;let r=!1,i={};for(let[n,a]of Object.entries(e.panelChartSettings))i[n]=nQ(a,t),i[n]!==a&&(r=!0);let a=r?{...e,panelChartSettings:i}:e;return $Z.set(e,{lines:t,out:a}),a}var tQ=new WeakMap;function nQ(e,t){if(!e||!t.size)return e;let n=tQ.get(e);if(n&&n.lines===t)return n.out;let r=$n(e,t);return tQ.set(e,{lines:t,out:r}),r}var rQ=oQ((e,t,n)=>{let r=e.filter(e=>e.timeColumn===n&&t.includes(e.targetId));return r.length?r:iQ}),iQ=[];function aQ(e,t,n){return!t.length||!n?.x?e:[...t.map(e=>Lt(e,n.x.v1)),...e]}function oQ(e){let t=null,n;return(r,i,a)=>t&&t[0]===r&&t[1]===i&&t[2]===a?n:(t=[r,i,a],n=e(r,i,a),n)}function sQ(e,t){e.data=t}function cQ(e,t){e.status!==t&&(e.status=t,e.emitter.emit(`status`,t))}function lQ({mount:e,render:t,licensed:n,annotations:r,marks:i,alarm:a,onAnnotations:o,onAnnotationToolEnd:s,onAnnotationSelect:c,onMarkSelect:l}){let u=K(null),[d,f]=ft(0),p=!!e.options.debug,m=K({renderStart:0,lastRenderMs:0,renders:0,data:null}).current;p&&(m.renderStart=performance.now()),G(()=>{p&&(m.lastRenderMs=performance.now()-m.renderStart,m.renders++)}),G(()=>{let e=u.current;if(!e)return;let t=()=>f(Math.max(120,Math.floor(e.clientHeight)));t();let n=new TH(t);return n.observe(e),()=>n.disconnect()},[]);let{status:h,node:g,data:_}=t(d||400);m.data=_,W(()=>{sQ(e,_)}),W(()=>{cQ(e,h)});let{theme:v,style:y,className:b}=e.options,x={};return y?.background&&(x[`--chart-bg`]=y.background),y?.muted&&(x[`--chart-muted`]=y.muted),y?.grid&&(x[`--chart-grid`]=y.grid),y?.accent&&(x[`--accent`]=y.accent),_t(`div`,{ref:u,onContextMenu:h===`ready`?void 0:t=>{t.preventDefault(),e.emitter.emit(`contextmenu`,{clientX:t.clientX,clientY:t.clientY})},className:b?`kymo-chart ${b}`:`kymo-chart`,"data-color-scheme":v,"data-status":h,style:x,children:[q($H.Provider,{value:e.plotFrame.set,children:g}),h===`ready`&&a?q(MZ,{frame:e.plotFrame,alarm:a.alarm,axis:a.axis}):null,h===`ready`&&(r?.length||e.annotationTool||i.length)?q(vZ,{annotations:r??QZ,tool:e.annotationTool,plotFrame:e.plotFrame,onChange:o,onToolEnd:s,onSelect:c,marks:i,onMarkSelect:l}):null,p?q(sZ,{stats:m,host:u}):null,n===!1?q(LV,{}):null]})}var uQ=new WeakMap;function dQ(e,t,n,r={}){let i=uQ.get(e)??new Map;uQ.set(e,i);let a=i.get(t);if(a&&!a.window.closed)return a.window.focus(),a;let o=e.charts.get(t),s=r.title??(o.title||e.charts.label(o.kind)),c=window.open(``,`kymoscope-chart-${t}`,`popup,width=${r.width??960},height=${r.height??600}`);if(!c)throw new kE(`popup_blocked`,{chartId:t});let l=c.document;l.head.replaceChildren(),l.body.replaceChildren(),l.title=s;for(let e of document.querySelectorAll(`style, link[rel="stylesheet"]`)){let t=e.cloneNode(!0);t instanceof HTMLLinkElement&&(t.href=e.href),l.head.appendChild(t)}let u=()=>{for(let e of[...l.documentElement.attributes])l.documentElement.removeAttribute(e.name);for(let e of document.documentElement.attributes)l.documentElement.setAttribute(e.name,e.value);l.body.className=document.body.className};u();let d=new MutationObserver(u);d.observe(document.documentElement,{attributes:!0}),d.observe(document.body,{attributes:!0,attributeFilter:[`class`]}),Object.assign(l.body.style,{margin:`0`,position:`fixed`,inset:`0`,display:`flex`,flexDirection:`column`,background:getComputedStyle(document.body).backgroundColor});let f=l.createElement(`div`);f.className=`kymo-window-controls`;let p=l.createElement(`div`);p.className=`kymo-window-plot`,Object.assign(p.style,{flex:`1`,minHeight:`0`,position:`relative`}),l.body.append(f,p),mH(c);let m=n(p,r.mount),h=RV(),g=!1,_=()=>{g||(g=!0,i.delete(t),hH(c),d.disconnect(),y(),window.removeEventListener(`pagehide`,v),m.destroy(),h.emit(`close`,void 0),h.clear())},v=()=>b.close(),y=e.subscribe(()=>{try{e.charts.get(t)}catch{b.close()}});c.addEventListener(`pagehide`,_),window.addEventListener(`pagehide`,v);let b={chartId:t,window:c,controls:f,view:m,close(){_(),c.closed||c.close()},on:(e,t)=>h.on(e,t)};return i.set(t,b),b}function fQ(e){for(let t of[...uQ.get(e)?.values()??[]])t.close()}function pQ(e,t,n=!1){let r=0,i=e.length;for(;r<i;){let a=r+i>>>1;(n?e[a]<=t:e[a]<t)?r=a+1:i=a}return r}function mQ(e,t,n){if(n<=t)return null;if(t===0&&n===e.t.length)return e;let r=e=>new Map([...e].map(([e,r])=>[e,r.subarray(t,n)])),i=r(e.lo);return{t:e.t.subarray(t,n),lo:i,hi:e.hi===e.lo?i:r(e.hi),level:e.level}}var hQ=(e,t,n)=>mQ(e,pQ(e.t,t),pQ(e.t,n,!0));function gQ(e,t,n,r){let i=[];for(let t of e){let e=mQ(t,0,pQ(t.t,n)),a=mQ(t,pQ(t.t,r,!0),t.t.length);e&&i.push(e),a&&i.push(a)}return[...i,...t]}var _Q=class{pieces;#e;#t;#n=new Map;#r=new Map;constructor(e,t={}){this.pieces=e.filter(e=>e.t.length>0).sort((e,t)=>e.t[0]-t.t[0]),this.#e=t;for(let e of this.pieces)for(let[t,n]of e.lo){let r=e.hi===e.lo?n:e.hi.get(t);if(!r)continue;let i=this.#n.get(t);i||this.#n.set(t,i=[]),i.push({t:e.t,L:n,H:r})}this.#t=[...this.#n.keys()].sort((e,t)=>e.localeCompare(t))}schemaSync(){return[{name:qe,type:`number`,unit:`s`},...this.#t.map(e=>({name:e,type:`number`,unit:this.#e[e]??``}))]}async getSchema(){return this.schemaSync()}async readColumns(e,t,n){let r=e.filter(e=>e===`ElapsedTime`||this.#n.has(e)),i=this.pieces.reduce((e,t)=>e+t.t.length,0),a=Math.max(0,Math.min(n,i-t)),o=Object.fromEntries(r.map(e=>[e,new Float64Array(a).fill(NaN)])),s=0;for(let e of this.pieces){let n=Math.max(0,t-s),i=Math.min(e.t.length,t+a-s);for(let a of r){let r=a===`ElapsedTime`?e.t:e.lo.get(a);r&&i>n&&o[a].set(r.subarray(n,i),s+n-t)}if(s+=e.t.length,s>=t+a)break}return o}getSeriesMultiSync(e,t,n){let{x0:r,x1:i}=t,a=t.xKey===`ElapsedTime`?e.filter(e=>this.#n.has(e)):[];if(!(i>r)||n<1||a.length===0)return{x0:r,bucket:0,rows:[],columns:a};let o=Math.floor(n),s=(i-r)/n,c=a.map(()=>new Float64Array(o).fill(1/0)),l=a.map(()=>new Float64Array(o).fill(-1/0));for(let e=0;e<a.length;e++){let t=c[e],n=l[e];for(let{t:c,L:l,H:u}of this.#n.get(a[e])){if(c[c.length-1]<r||c[0]>i)continue;let e=pQ(c,i,!0);for(let i=pQ(c,r);i<e;i++){let e=l[i];if(e!==e)continue;let a=Math.floor((c[i]-r)/s);a>=o&&(a=o-1),e<t[a]&&(t[a]=e),u[i]>n[a]&&(n[a]=u[i])}}}let u=[];for(let e=0;e<o;e++){let t=null;for(let n=0;n<a.length;n++)c[n][e]!==1/0&&(t??={b:e},t[`y${n}lo`]=c[n][e],t[`y${n}hi`]=l[n][e]);t&&u.push(t)}return{x0:r,bucket:s,rows:u,columns:a}}async getSeriesMulti(e,t,n){return this.getSeriesMultiSync(e,t,n)}async getSeries(e){let t=this.getSeriesMultiSync([e.column],e.viewport,e.maxPoints),n=t.rows.length,r={x:new Float64Array(n),min:new Float64Array(n),max:new Float64Array(n),first:new Float64Array(n),last:new Float64Array(n)};return t.rows.forEach((e,n)=>{r.x[n]=t.x0+(e.b+.5)*t.bucket,r.min[n]=r.first[n]=e.y0lo,r.max[n]=r.last[n]=e.y0hi}),r}xBoundsSync(e){let t=this.#r.get(e);if(t)return t;let n=1/0,r=-1/0;if(e===`ElapsedTime`)for(let e of this.pieces)n=Math.min(n,e.t[0]),r=Math.max(r,e.t[e.t.length-1]);for(let{L:t,H:i}of this.#n.get(e)??[])for(let e=0;e<t.length;e++)t[e]<n&&(n=t[e]),i[e]>r&&(r=i[e]);return t=n<=r?{x0:n,x1:r}:{x0:0,x1:0},this.#r.set(e,t),t}async xBounds(e){return this.xBoundsSync(e)}sampleRowsSync(e){let t=this.pieces.reduce((e,t)=>e+t.t.length,0),n=Math.max(1,Math.ceil(t/Math.max(1,e))),r=[],i=0,a=0;for(let e of this.pieces){let t=i-a;if(a+=e.t.length,!(t>=e.t.length))for(let a=t;a<e.t.length;a+=n,i+=n){let t={[qe]:e.t[a]};for(let[n,r]of e.lo){let e=r[a];t[n]=e===e?e:null}r.push(t)}}return r.sort((e,t)=>e[qe]-t[qe])}async dispose(){}},vQ=12e3,yQ=100;function bQ(e,t=!1){let n,r=0;if(t&&e instanceof Float64Array){n=e;let t=0,i=0,a=0,o=n.length&-4;for(let e=0;e<o;e+=4)r+=n[e]*0,t+=n[e+1]*0,i+=n[e+2]*0,a+=n[e+3]*0;for(let e=o;e<n.length;e++)r+=n[e]*0;r+=t+i+a}else{n=new Float64Array(e.length);for(let t=0;t<n.length;t++){let i=+e[t];n[t]=i,r+=i*0}}if(r===0)return u.add(n),n;for(let e=0;e<n.length;e++){let t=n[e];t-t!==0&&(n[e]=NaN)}return n}function xQ(e,t){let n=Object.keys(t.columns);if(n.length===0)throw new kE(`no_columns`);let r=t.columns[n[0]].length;if(n.some(e=>t.columns[e].length!==r))throw new kE(`column_length_mismatch`);let i=new Map(n.map(e=>[e,bQ(t.columns[e],t.transfer)])),a=SQ(e,t.name,i,t.units??{});if(t.bands){for(let e of Object.values(t.bands))if(e.lo.length!==r||e.hi.length!==r)throw new kE(`column_length_mismatch`);a.bands=Object.fromEntries(Object.entries(t.bands).map(([e,t])=>[e,{lo:Float64Array.from(t.lo),hi:Float64Array.from(t.hi)}]))}return a}function SQ(e,t,n,r,i,a){let o=[...n.keys()],s=n.get(o[0]).length,c=o.map(e=>r[e]??``),l=o.map((e,t)=>({name:e,type:`number`,unit:c[t]})),u=!!a&&a.schema.length===o.length&&a.schema.every((e,t)=>e.name===o[t]),d,f;if(u)d=a.rawText??``,f=a.parseConfig;else{let e=[o.join(`,`)];for(let t=0;t<Math.min(s,yQ);t++)e.push(o.map(e=>{let r=n.get(e)[t];return r===r?String(r):``}).join(`,`));d=e.join(`
615
615
  `),f=y(d)}let p={id:e,name:t,schema:l,rawText:d,parseConfig:f,fromColumns:!0};if(s>1e6){let e=new MX(n,r);return{...p,kind:`columnar`,source:e,data:{meta:``,columnNames:o,units:c,rows:e.sampleRowsSync(vQ)}}}let m={meta:``,columnNames:o,units:c,rows:Me({keys:o,length:s,values:o.map(e=>n.get(e)),text:o.map(()=>null)},i)};return{...p,kind:`memory`,source:new LE(m),data:m}}function CQ(e,t,n){let r=e.fromColumns?wQ(e):null;if(!r)throw new kE(`invalid_argument`,{reason:`only datasets added with addColumns can be written`});let i=r.values().next().value.length,a=e.columnSpares??new Map,o={};for(let e of t){let t=a.get(e);t&&t.length===i&&t!==r.get(e)?(I(t),o[e]=t):o[e]=new Float64Array(i)}n(o,Object.fromEntries(t.map(e=>[e,r.get(e)])));let s=new Map(a);for(let e of t){let t=r.get(e);t?s.set(e,t):s.delete(e)}return{...TQ(e,o,!0),columnSpares:s}}function wQ(e){if(e.source instanceof MX)return new Map(e.source.columnMap);let t=Ue(e.data.rows);return t?new Map(t.keys.map((e,n)=>[e,t.values[n]])):null}function TQ(e,t,n=!1){let r=e.fromColumns?wQ(e):null;if(!r)throw new kE(`invalid_argument`,{reason:`only datasets added with addColumns can be replaced`});let i=r;for(let e of Object.keys(t))i.set(e,bQ(t[e],n));let a=i.values().next().value.length;for(let e of i.values())if(e.length!==a)throw new kE(`column_length_mismatch`);let o=Object.fromEntries(e.schema.map(e=>[e.name,e.unit])),s=SQ(e.id,e.name,i,o,e.kind===`memory`?e.data.rows:void 0,e),c=s.schema.length===e.schema.length&&s.schema.every((t,n)=>t.name===e.schema[n].name);return{...s,schema:c?e.schema:s.schema,beacon:e.beacon,bands:e.bands}}var EQ=new WeakMap;function DQ(e){let t=e.fromColumns?wQ(e):null;if(!t)return e.rawText??``;let n=e.data.rows,r=EQ.get(n);if(r===void 0){let e=[...t.keys()],i=e.map(e=>t.get(e)),a=[e.join(`,`)],o=i[0].length;for(let e=0;e<o;e++)a.push(i.map(t=>t[e]===t[e]?String(t[e]):``).join(`,`));EQ.set(n,r=a.join(`
616
616
  `))}return r}function OQ(e,t){let n=new _Q(t.pieces,t.units),r=n.schemaSync();return{id:e,name:t.name,kind:`columnar`,source:n,schema:r,data:{meta:``,columnNames:r.map(e=>e.name),units:r.map(e=>e.unit),rows:n.sampleRowsSync(vQ)}}}function kQ(e){let t=e,n=new Set;return{get:()=>t,set(e){let r=e(t);if(r!==t){t=r;for(let e of[...n])try{e()}catch(e){console.error(`[kymoscope] subscriber failed`,e)}}},subscribe(e){return n.add(e),()=>{n.delete(e)}}}}function AQ(e){let t=null,n;return(...r)=>t&&t.length===r.length&&t.every((e,t)=>e===r[t])?n:(t=r,n=e(...r),n)}function jQ(){let e=AQ(e=>{let t={};for(let n of e){if(n.cut){let e=n.cut.defs.find(e=>e.id===n.cut.cycleId)?.show,r=e&&e.channel!==n.cut.timeKey?UB(e):null;t[n.id]=r?{laps:n.cut.parts,values:n.cut.found.map(e=>e.kpis?.[r]??null),unit:n.schema.find(t=>t.name===e.channel)?.unit??``,isTime:!1}:{laps:n.cut.parts,values:n.cut.found.map(e=>e.tend===null?null:e.tend-e.tstart),unit:`s`,isTime:!0};continue}if(!n.beacon||n.kind!==`memory`)continue;let{channel:e,metric:r,stat:i}=n.beacon,a=vB(n.data.rows,e);if(a.length===0)continue;let o=n.data.units[n.data.columnNames.indexOf(r)]??``;t[n.id]={laps:a.map((e,t)=>{let r={...n.data,rows:n.data.rows.slice(e.start,e.end)};return{...n,id:EB(n.id,t),name:`${n.name} · Cycle ${t+1}`,data:r,source:new LE(r)}}),values:a.map(e=>SB(n.data.rows,e,r,i)),unit:o,isTime:i===`span`&&wB(r,o)}}return t}),t=AQ((e,t,n)=>e.flatMap(e=>t[e.id]?t[e.id].laps.filter(e=>n.includes(e.id)):n.includes(e.id)?[e]:[])),n=AQ((e,t)=>e.filter(e=>e.kind===`data`&&t.includes(e.id))),r=AQ(e=>_X(e.map(e=>e.data))),i=AQ((e,t)=>t.length===0?e:_X(e?[e,...t.map(e=>e.dataset)]:t.map(e=>e.dataset))),a=AQ((e,t,n,r)=>{let i=new Set;if(e)for(let t of n.length>0?n:[e])for(let e of xX(t.columnNames,t.rows))i.add(e);for(let e of r)for(let t of e.dataset.columnNames)(t===`ElapsedTime`||e.source.hasValues(t))&&i.add(t);let a=e?e.columnNames.filter(e=>i.has(e)):[],o=t.filter(e=>e.kind!==`memory`).flatMap(e=>xz(e.schema));return[...new Set([...a,...o])]});return{lapsByDataset:e,selectedDatasets:t,selectedLive:n,staticDataset:r,mergedDataset:i,mergedParts:AQ((e,t)=>[...e.map(e=>e.data),...t.map(e=>e.dataset)]),numericColumns:AQ((e,t,n,r=[],i=[])=>{let o=a(e,t,r,i),s=new Set(o);return[...o,...n.map(e=>e.name).filter(e=>!s.has(e))]}),allColumns:AQ((e,t,n)=>[...new Set([...e?.columnNames??[],...t.filter(e=>e.kind!==`memory`).flatMap(e=>e.schema.map(e=>e.name)),...n.map(e=>e.name)])]),columnUnits:AQ((e,t)=>{let n={};e&&e.columnNames.forEach((t,r)=>{let i=e.units[r]?.trim();i&&(n[t]=i)});for(let e of t)e.units&&(n[e.name]=e.units);return n})}}var MQ=[{kind:`multiband`,label:`Multi-band`},{kind:`xyscatter`,label:`X-Y scatter`},{kind:`xyzmesh`,label:`X-Y-Z mesh`},{kind:`histogram`,label:`Histogram`},{kind:`polar`,label:`Polar`},{kind:`spectrum`,label:`Spectrum`},{kind:`boxplot`,label:`Box Plot`},{kind:`spectrogram`,label:`Spectrogram`},{kind:`heatmap`,label:`Heatmap`},{kind:`violin`,label:`Violin`},{kind:`confusion`,label:`Confusion Matrix`},{kind:`roc`,label:`ROC Curve`},{kind:`losscurve`,label:`Loss Curves`},{kind:`controlchart`,label:`Control Chart`},{kind:`parallelcoords`,label:`Parallel Coords`},{kind:`embedding`,label:`Embedding`},{kind:`flamegraph`,label:`Flame Graph`},{kind:`barchart`,label:`Bar Chart`},{kind:`radar`,label:`Radar`},{kind:`areachart`,label:`Area Chart`},{kind:`cdfchart`,label:`CDF / ECDF`},{kind:`bubblechart`,label:`Bubble Chart`},{kind:`treemap`,label:`Treemap`},{kind:`sankey`,label:`Sankey`},{kind:`calibration`,label:`Calibration Curve`},{kind:`gauge`,label:`Gauges`},{kind:`camera`,label:`Camera`},{kind:`qqplot`,label:`Q-Q Plot`},{kind:`gantt`,label:`Gantt Chart`}],NQ=new Map(MQ.map(e=>[e.kind,e.label]));function PQ(e){return NQ.get(e)??e}var FQ=`kymoscope-live.v1`,IQ=2e3,LQ=3e4,RQ=30,zQ=1e4,BQ=300,VQ=90,HQ=e=>e.startsWith(`eyJ`);function UQ(e){try{let t=e.split(`.`)[1]??``,n=atob(t.replace(/-/g,`+`).replace(/_/g,`/`)+`===`.slice((t.length+3)%4)),r=JSON.parse(n).exp;return typeof r==`number`?r:null}catch{return null}}function WQ(e,t){return`${e.replace(/\/+$/,``)}/v1/streams/${t}/watch`}function GQ(e,t,n,r){let i=null,a=null,o=null,s=!1,c=0,l=()=>{o&&=(clearTimeout(o),null)},u=(n,r)=>{l();let a=UQ(r);if(a===null)return;let c=HQ(r),d=c?Math.min(a,Date.now()/1e3+BQ):a,f=Math.min(Math.max((d-(c?VQ:RQ))*1e3-Date.now(),zQ),2**31-1);o=setTimeout(async()=>{o=null;let r=null;try{r=await e.getToken(t)}catch{r=null}if(!(s||i!==n||!r)){try{n.send(JSON.stringify({type:`auth`,token:r}))}catch{return}u(n,r)}},f)},d=()=>{if(s||a)return;let e=Math.min(LQ,IQ*2**c++)*(.75+Math.random()/2);a=setTimeout(()=>{a=null,f()},e)},f=async()=>{if(s)return;let a=null;try{a=await e.getToken(t)}catch{a=null}if(s)return;if(!a){r?.(`error`),d();return}let o=new WebSocket(WQ(e.url,t),[FQ,`bearer.${a}`]);o.binaryType=`arraybuffer`,i=o;let f=a;o.onopen=()=>{r?.(`subscribed`),u(o,f)},o.onmessage=e=>{c=0,typeof e.data!=`string`&&n(e.data)},o.onclose=()=>{i===o&&(i=null,l(),!s&&(r?.(`error`),d()))}};return f(),()=>{if(s=!0,a&&=(clearTimeout(a),null),l(),i){let e=i;i=null,e.close(1e3)}}}var KQ=960*1024,qQ=24;function JQ(e){let t=e.key&&e.fragIndex===0?new TextEncoder().encode(e.codec):new Uint8Array;if(t.length>255)throw Error(`codec string too long`);let n=e.key&&e.fragIndex===0?1+t.length:0,r=new Uint8Array(qQ+n+e.payload.length),i=new DataView(r.buffer);i.setUint8(0,1),i.setUint8(1,!!e.key|(e.last?2:0)),i.setUint8(2,1),i.setUint8(3,0),i.setFloat64(4,e.t,!0),i.setUint32(12,e.seq>>>0,!0),i.setUint16(16,e.fragIndex,!0),i.setUint16(18,e.fragCount,!0),i.setUint16(20,e.width,!0),i.setUint16(22,e.height,!0);let a=qQ;return n&&(r[a++]=t.length,r.set(t,a),a+=t.length),r.set(e.payload,a),r}function YQ(e){if(e.length<qQ||e[0]!==1||e[2]!==1)return null;let t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=(e[1]&1)!=0,r=t.getUint16(16,!0),i=t.getUint16(18,!0);if(i===0||r>=i)return null;let a=qQ,o=``;if(n&&r===0){if(e.length<a+1||e.length<a+1+e[a])return null;o=new TextDecoder().decode(e.subarray(a+1,a+1+e[a])),a+=1+e[a]}return{key:n,last:(e[1]&2)!=0,t:t.getFloat64(4,!0),seq:t.getUint32(12,!0),fragIndex:r,fragCount:i,width:t.getUint16(20,!0),height:t.getUint16(22,!0),codec:o,payload:e.subarray(a)}}function XQ(e){let t=Math.max(1,Math.ceil(e.data.length/KQ)),n=[];for(let r=0;r<t;r++)n.push(JQ({key:e.key,last:r===t-1,t:e.t,seq:e.seq,fragIndex:r,fragCount:t,width:e.width,height:e.height,codec:e.codec,payload:e.data.subarray(r*KQ,Math.min(e.data.length,(r+1)*KQ))}));return n}var ZQ=class{samples=[];exact=!1;windowS;constructor(e=30){this.windowS=e}observe(e,t){if(e>1e9){this.samples=[],this.exact=!0;return}this.exact=!1;let n=t-e,r=this.samples[this.samples.length-1];for(r&&Math.abs(n-r.off)>1&&(this.samples=[]),this.samples.push({at:t,off:n});this.samples.length&&this.samples[0].at<t-this.windowS;)this.samples.shift()}quality(){return this.exact?`exact`:this.samples.length?`approx`:`none`}toWall(e,t=0){if(this.exact)return e+t/1e3;if(!this.samples.length)return null;let n=1/0;for(let e of this.samples)n=Math.min(n,e.off);return e+n+t/1e3}toStream(e,t=0){let n=this.toWall(0,t);return n===null?null:e-n}},QQ=class{#e;constructor(e){this.#e=typeof e==`function`?e:()=>e}size(){return this.#e().size}get columnNames(){return this.#e().columnNames}version(){return this.#e().version}columns(){let e=this.#e();return new $Q(new Set(e.columnNames),t=>e.mirrorColumn(t))}hasValues(e){return this.#e().hasValues(e)}snapshot(e){return this.#e().toDataset(e)}async getSchema(){let e=this.#e();return e.columnNames.map(t=>({name:t,type:`number`,unit:e.unitOf(t)}))}async getSeries(e){let t=this.#e();return $e(t.columnValues(e.viewport.xKey),t.columnValues(e.column),e.viewport.x0,e.viewport.x1,e.maxPoints)}async getSeriesMulti(e,t,n){return this.getSeriesMultiSync(e,t,n)}getSeriesMultiSync(e,t,n){return this.#e().decimateColumns(t.xKey,e,t.x0,t.x1,n)}getPointsSync(e,t,n){return this.#e().decimatePoints(t.xKey,e,t.x0,t.x1,n)}async xBounds(e){return this.xBoundsSync(e)}xBoundsSync(e){return this.#e().columnBounds(e)}xTravelSync(e,t){return this.#e().xTravel(e,t)}latestTimeSync(){return this.#e().latestTime()}xAtTimeSync(e,t,n=!1){return this.#e().xAtTime(e,t,n)}latestSync(e){return this.#e().lastValue(e)}latestValuesSync(e){let t=this.#e(),n=new Map;for(let r of e){let e=t.lastValue(r),i=t.lastKnown(r);Number.isFinite(e)?n.set(r,e):i&&n.set(r,i.v)}return n}valueBoundsSync(e){let t=this.#e().valueBounds(e),n=this.#e().lastKnown(e);if(!t&&!n)return null;let r=Math.min(t?.x0??1/0,n?.v??1/0),i=Math.max(t?.x1??-1/0,n?.v??-1/0);if(r!==i)return{min:r,max:i};let a=Math.max(.5,Math.abs(r)*.05);return{min:r-a,max:i+a}}lastKnownSync(e){return this.#e().lastKnown(e)}trackCycles(e){this.#e().trackCycles(e)}cycleSpanSync(e){return this.#e().cycleSpan(e)}decimateCycleSync(e,t,n,r,i){return this.#e().decimateCycle(e,t,n,r.x0,r.x1,i)}cyclePointsSync(e,t,n,r,i){return this.#e().decimateCyclePoints(e,t,n,r.x0,r.x1,i)}async readColumns(e,t,n){let r=this.#e(),i=new Set(r.columnNames),a={};for(let o of e)i.has(o)&&(a[o]=r.columnValues(o).slice(t,t+n));return a}async dispose(){}},$Q=class extends Map{#e;#t;constructor(e,t){super(),this.#e=e,this.#t=t}get(e){if(!super.has(e)&&this.#e.has(e)){let t=this.#t(e);t&&super.set(e,t)}return super.get(e)}has(e){return this.#e.has(e)}},e$=4096,t$=5e3,n$=class{startedAt=Date.now();n=0;capacity=e$;time=new Float64Array(e$);cols=new Map;order=[];units=new Map;timeColumn;timeUnit;constructor(e=qe,t=`s`){this.timeColumn=e,this.timeUnit=t}get rows(){return this.n}add(e){this.n===this.capacity&&this.grow();let t=this.n;this.time[t]=e.t;for(let n of e.signals){let e=this.cols.get(n.name);e||(e=new Float64Array(this.capacity).fill(NaN),this.cols.set(n.name,e),this.order.push(n.name)),n.unit&&!this.units.get(n.name)&&this.units.set(n.name,n.unit),e[t]=typeof n.value==`number`?n.value:NaN}this.n++}addColumns(e){let t=se(e,this.timeColumn),n=e.t.length;for(;this.n+n>this.capacity;)this.grow();let r=this.n,i=(e,t)=>{if(t instanceof Float64Array||t instanceof Float32Array)e.set(t,r);else for(let i=0;i<n;i++)e[r+i]=+t[i]};i(this.time,e.t);for(let n of t){let t=this.cols.get(n);t||(t=new Float64Array(this.capacity).fill(NaN),this.cols.set(n,t),this.order.push(n));let r=e.units?.[n];r&&!this.units.get(n)&&this.units.set(n,r),i(t,e.columns[n])}this.n+=n}grow(){let e=this.capacity*2,t=new Float64Array(e);t.set(this.time),this.time=t;for(let[t,n]of this.cols){let r=new Float64Array(e).fill(NaN);r.set(n),this.cols.set(t,r)}this.capacity=e}toCsvParts(){let e=[this.timeColumn,...this.order],t=[this.timeUnit,...this.order.map(e=>this.units.get(e)??``)],n=[`${e.map(r$).join(`,`)}\n${t.map(r$).join(`,`)}\n`],r=this.order.map(e=>this.cols.get(e));for(let e=0;e<this.n;e+=t$){let t=Math.min(this.n,e+t$),i=``;for(let n=e;n<t;n++){i+=String(this.time[n]);for(let e of r){let t=e[n];i+=Number.isNaN(t)?`,`:`,${t}`}i+=`
617
- `}n.push(i)}return n}};function r$(e){let t=/^[=+\-@\t\r]/.test(e)?`'${e}`:e;return/[",\n\r]/.test(t)?`"${t.replace(/"/g,`""`)}"`:t}var i$=512,a$=new WeakMap;function o$(e,t,n){let r=a$.get(e);r||a$.set(e,r=new Map);let i=r.get(t),a={start:n,values:[]};return{carry:{start:e=>{let t=i?.values[e];if(!i||!t)return 0;for(let e=Math.min(n-i.start,t.length-1);e>=0;e--){let n=t[e];if(n!==null&&Number.isFinite(n))return n}return 0},done:(e,t)=>{a.values[e]=t}},keep:()=>{r.set(t,a)}}}function s$(e,t,n){let r=e.endAbs,i=Math.max(n,e.firstAbs);if(i>=r||t.length===0)return;let a=new Set(e.columnNames);for(let n of t){if(!n.enabled)continue;let o=eE(n.formula);if(!o.ok)continue;let{identifiers:s,functions:c}=tE(o.node);if(!s.every(e=>a.has(e)))continue;let l=c.some(e=>QT.includes(e)),u=Math.max(e.firstAbs,i-(l?i$:0)),d=new Map([qe,...s].map(t=>[t,e.range(t,u,r)])),{carry:f,keep:p}=o$(e,`${n.id}|${n.formula}`,u),m=sE(n,e=>d.get(e),qe,r-u,t,f);m.status===`ok`&&(e.writeComputed(n.name,n.units,i,m.values.subarray(i-u)),p())}}function c$(e,t){e.clearComputed(),a$.delete(e),s$(e,t,e.firstAbs)}var l$=8e3,u$=131072;function d$(e,t={}){switch(e.kind){case`elapsed`:return{name:`Elapsed`,unit:`s`};case`event`:return{name:`Since ${e.channel} ${e.op} ${e.value}`,unit:`s`};case`clock`:return{name:`Time of day`,unit:`s`};default:{let n=t[e.channel]??``;return e.integral?{name:`∫${e.channel}`,unit:n?`${n}·s`:`s`}:{name:`${e.channel} since start`,unit:n}}}}var f$=new Map;function p$(e,t){let n=`${t}|${Math.floor(e/900)}`,r=f$.get(n);r===void 0&&(r=dB(e,t),f$.size>1e4&&f$.clear(),f$.set(n,r));let i=(e+r)%86400;return i<0?i+86400:i}var m$=class{axis;#e=NaN;#t=NaN;#n=NaN;#r=0;#i=NaN;#a=NaN;constructor(e){this.axis=e}begin(e){this.#e=e,this.#t=NaN,this.#n=NaN,this.#r=0,this.#i=NaN,this.#a=NaN}x(e,t){let n=this.axis;return n.kind===`clock`?p$(e,n.tz):n.kind===`elapsed`?e-this.#e:e<this.#e?NaN:n.kind===`event`?(this.#t!==this.#t&&t===t&&aB(n.op,t,n.value)&&(this.#t=e),e-this.#t):n.integral?(t===t&&(this.#i===this.#i&&(this.#r+=(t+this.#i)/2*(e-this.#a)),this.#i=t,this.#a=e),this.#i===this.#i?this.#r:NaN):(t===t&&(this.#n!==this.#n&&(this.#n=t),this.#i=t),this.#i===this.#i?this.#i-this.#n:NaN)}};function h$(e,t,n,r){let i=`channel`in r?t.get(r.channel):void 0;if(r.kind===`event`){let a=NaN;for(let t=0;t<e.length&&a!==a;t++){let o=i?i[t]:NaN;e[t]>=n&&o===o&&aB(r.op,o,r.value)&&(a=e[t])}return{x:e.map(e=>e-a),t:e,cols:t}}let a=new m$(r);a.begin(n);let o=new Float64Array(e.length);for(let t=0;t<e.length;t++)o[t]=a.x(e[t],i?i[t]:NaN);return{x:o,t:e,cols:t}}function g$(e,t,n){let r=[];for(let n=0;n<e.length;n++)e[n]===e[n]&&t[n]===t[n]&&r.push(n);let i=!0;for(let t=1;t<r.length&&i;t++)i=e[r[t-1]]<=e[r[t]];i||r.sort((t,n)=>e[t]-e[n]);let a=r.length,o=new Float64Array(n.length).fill(NaN);if(a<2)return o;let s=Float64Array.from(r,t=>e[t]),c=Float64Array.from(r,e=>t[e]),l=Float64Array.from({length:a-1},(e,t)=>s[t+1]-s[t]).sort(),u=l[l.length>>1],d=u>0?4*u:1/0,f=0;for(let e=0;e<n.length;e++){let t=n[e];if(!(t>=s[0]&&t<=s[a-1]))continue;for(;f<a-2&&s[f+1]<t;)f++;let r=s[f],i=s[f+1];i-r>d||(o[e]=i===r?c[f]:c[f]+(c[f+1]-c[f])*(t-r)/(i-r))}return o}function _$(e,t,n){let r=e.length;if(r===0||!(n>=e[0]&&n<=e[r-1]))return NaN;if(r===1)return t[0];let i=(n-e[0])/(e[r-1]-e[0])*(r-1),a=Math.min(r-2,Math.floor(i));return t[a]+(t[a+1]-t[a])*(i-a)}function v$(e,t,n){let r=Math.max(2,Math.min(l$,Math.floor(n)));if(r*t.length>131072)throw Error(`too_many_cells`);let i=1/0,a=-1/0;for(let t of e)for(let e of t.x)e===e&&(e<i&&(i=e),e>a&&(a=e));if(!(a>i))throw Error(`empty`);let o=Float64Array.from({length:r},(e,t)=>i+t*(a-i)/(r-1)),s=new Map;for(let n of t){let t=new Uint16Array(r),i=new Float64Array(r),a=new Float64Array(r),c=new Float32Array(r).fill(1/0),l=new Float32Array(r).fill(-1/0);for(let s of e){let e=s.cols.get(n);if(!e)continue;let u=g$(s.x,e,o);for(let e=0;e<r;e++){let n=u[e];if(n!==n)continue;let r=++t[e],o=n-i[e];i[e]+=o/r,a[e]+=o*(n-i[e]),n<c[e]&&(c[e]=n),n>l[e]&&(l[e]=n)}}let u={mean:new Float32Array(r),sd:new Float32Array(r),min:c,max:l,n:t};for(let e=0;e<r;e++){if(t[e]===0){u.mean[e]=u.sd[e]=u.min[e]=u.max[e]=NaN;continue}u.mean[e]=i[e],u.sd[e]=t[e]>1?Math.sqrt(a[e]/(t[e]-1)):0}s.set(n,u)}return{x:o,channels:s}}function y$(e,t){if(e.unit===`abs`)return e.tolerance;let n=1/0,r=-1/0;for(let e of t.mean)e===e&&(e<n&&(n=e),e>r&&(r=e));return r>=n?Math.max(r-n,Math.abs(r),Math.abs(n))*e.tolerance/100:0}var b$=new WeakMap;function x$(e){let t=b$.get(e);if(t)return t;let n=e.sd.length,r=Math.max(2,Math.round(n/100));t=new Float32Array(n).fill(NaN);for(let i=0;i<n;i++){if(e.n[i]<2)continue;let a=0,o=0;for(let t=Math.max(0,i-r);t<=Math.min(n-1,i+r);t++)e.n[t]>=2&&e.sd[t]===e.sd[t]&&(a+=e.sd[t]**2,o++);t[i]=o?Math.sqrt(a/o):NaN}return b$.set(e,t),t}function S$(e,t,n){if(n===`minmax`)return{lo:e.min,hi:e.max};if(n===`sigma`){let n=x$(e);return{lo:e.mean.map((e,r)=>e-t*n[r]),hi:e.mean.map((e,r)=>e+t*n[r])}}let r=y$(n,e);return{lo:e.mean.map(e=>e-r),hi:e.mean.map(e=>e+r)}}function C$(e,t,n,r=`sigma`,i=0){let a=typeof r==`function`?r:()=>({band:r,k:n}),o=[...t.channels.keys()],s=new Map,c=new Map,l=[],u=new Uint8Array(e.t.length),d=o.map(()=>new Uint8Array(e.t.length)),f=t.x.length;o.forEach((n,r)=>{let i=t.channels.get(n),o=e.cols.get(n);if(!o)return;let{band:p,k:m}=a(n),h=typeof p==`object`?p:null,{lo:g,hi:_}=S$(i,m,p),v=0,y=0,b=0;for(let e of i.mean)if(e===e){v++;let t=e-y;y+=t/v,b+=t*(e-y)}let x=v>1?Math.max(Math.sqrt(b/(v-1)),1e-9):1e-9,S=h?Math.max(y$(h,i),1e-9):0,C=x$(i),w=new Float64Array(e.t.length).fill(NaN),T=new Float64Array(e.t.length).fill(NaN),E=0,D=0;for(let n=0;n<e.t.length;n++){let a=o[n],s=e.x[n];if(a!==a||s!==s)continue;let c=_$(t.x,i.mean,s);if(c!==c)continue;w[n]=a-c;let l=Math.round((s-t.x[0])/(t.x[f-1]-t.x[0])*(f-1));T[n]=Math.abs(a-c)/(h?S:i.n[l]>=2&&C[l]===C[l]?Math.max(C[l],1e-9):x),E+=T[n],D++,(h||i.n[l]>=2)&&(a<_$(t.x,g,s)||a>_$(t.x,_,s))&&(u[n]=1,d[r][n]=1)}s.set(n,w),c.set(n,T),l.push({channel:n,z:D?E/D:0})}),l.sort((e,t)=>t.z-e.z);let p=[];for(let t=0;t<u.length;t++){if(!u[t])continue;let n=t;for(;n<u.length&&u[n];)n++;let r=p[p.length-1];r&&e.t[t]-e.t[Math.min(r[1],u.length-1)]<i?r[1]=n:p.push([t,n]),t=n}let m=[];for(let[t,n]of p){let r=e.t[t],a=e.t[Math.min(n,u.length-1)];a-r>=i&&m.push({t0:r,t1:a,channels:o.filter((e,r)=>d[r].subarray(t,n).includes(1))})}return{delta:s,score:l,deviations:m,z:c}}function w$(e,t){let n=e.x.length,r=t.length,i=new DataView(new ArrayBuffer(12+8*n+r*n*18));[75,82,66,49].forEach((e,t)=>i.setUint8(t,e)),i.setUint32(4,n,!0),i.setUint32(8,r,!0);let a=12;for(let t=0;t<n;t++,a+=8)i.setFloat64(a,e.x[t],!0);for(let r of t){let t=e.channels.get(r);if(!t)throw Error(`The reference has no channel ${r}`);for(let e of[t.mean,t.sd,t.min,t.max])for(let t=0;t<n;t++,a+=4)i.setFloat32(a,e[t],!0);for(let e=0;e<n;e++,a+=2)i.setUint16(a,t.n[e],!0)}return De(new Uint8Array(i.buffer))}function T$(e,t){let n=le(e),r=new DataView(n.buffer,n.byteOffset,n.byteLength);if(n.length<12||String.fromCharCode(n[0],n[1],n[2],n[3])!==`KRB1`)throw Error(`Not a reference band`);let i=r.getUint32(4,!0),a=r.getUint32(8,!0);if(a!==t.length||n.length!==12+8*i+a*i*18)throw Error(`This reference band does not match its channels`);let o=12,s=new Float64Array(i);for(let e=0;e<i;e++,o+=8)s[e]=r.getFloat64(o,!0);let c=new Map;for(let e of t){let t=()=>{let e=new Float32Array(i);for(let t=0;t<i;t++,o+=4)e[t]=r.getFloat32(o,!0);return e},n=t(),a=t(),s=t(),l=t(),u=new Uint16Array(i);for(let e=0;e<i;e++,o+=2)u[e]=r.getUint16(o,!0);c.set(e,{mean:n,sd:a,min:s,max:l,n:u})}return{x:s,channels:c}}var E$=` Δ`,D$=class{#e;constructor(e){this.#e=new jB(e)}assumeOpen(e){}feed(e,t,n){let r=[];for(let i=0;i<e.length;i++)this.#e.step(e[i],e=>{let n=t(e);return n?n[i]:NaN},r),n?.(i,this.#e.open()?.tstart??null);return r.map(e=>({tstart:e.tstart,tend:e.tend,kpis:{duration:(e.tend??e.tstart)-e.tstart},...e.flags.length?{flags:e.flags}:{}}))}};function O$(e){if(!e.cycle&&!e.rule)throw Error(`a live segment axis needs a rule or a cycle rule`);let t=e.cycle?new D$(e.cycle):new gB(e.rule,e.kpis??[]),n=new m$(e.axis),r=NaN;e.start!=null&&(t.assumeOpen(e.start),n.begin(e.start),r=e.start);let i=e.reference??null,a=i?[...i.channels]:[],o=i?i.grid.length:0,s=`channel`in e.axis?e.axis.channel:null,c=[...new Set([...e.cycle?AB(e.cycle):iB(e.rule),...(e.kpis??[]).map(e=>e.channel),...s?[s]:[],...a.map(([e])=>e)])],l=e.minDeviationS??5,u=NaN,d=NaN,f=NaN,p=new Set,m=!1,h=e=>{m&&e({type:`deviation-end`,t0:u,t1:d,channels:[...p]}),u=d=f=NaN,p=new Set,m=!1};return{feed(g,_,v=!1){let y=Math.max(_,g.firstAbs),b=g.endAbs;if(y>=b)return;let x=t=>{v||e.onEvent?.(t)},S=g.range(qe,y,b),C=new Map(c.map(e=>[e,g.range(e,y,b)])),w=new Float64Array(S.length).fill(NaN),T=a.map(([e,t])=>({name:e,b:t,v:C.get(e),d:new Float64Array(S.length).fill(NaN)})),E=s?C.get(s):null,D=t.feed(S,e=>C.get(e),(e,t)=>{if(t===null)return;t!==r&&(h(x),r=t,n.begin(t),x({type:`open`,tstart:t}));let a=n.x(S[e],E?E[e]:NaN);if(w[e]=a,!i||a!==a)return;let s=o>1?Math.round((a-i.grid[0])/(i.grid[o-1]-i.grid[0])*(o-1)):0,c=!1;for(let t of T){let n=t.v[e],r=_$(i.grid,t.b.mean,a);n!==n||r!==r||(t.d[e]=n-r,t.b.n[s]>=2&&(n<_$(i.grid,t.b.lo,a)||n>_$(i.grid,t.b.hi,a))&&(c=!0,p.add(t.name)))}c?(u!==u&&(u=S[e]),d=S[e],f=NaN,!m&&S[e]-u>=l&&(m=!0,x({type:`deviation`,t0:u,channels:[...p]}))):u===u&&(f!==f&&(f=S[e]),S[e]-f>=l&&h(x))});for(let e of D)x({type:`close`,segment:e});g.writeComputed(e.column,e.unit,y,w);for(let e of T)g.writeComputed(`${e.name} Δ`,g.unitOf(e.name),y,e.d)}}}var k$=1e7,A$=512,j$=400,M$=4e3,N$=1e3,P$=3e3,F$=2,I$=5e3,L$=1e4;function R$(e,t,n=`data`){let r=new Xe(t.capacity??k$,void 0,void 0,(t.maxMemoryMB??A$)*1024*1024);return{meta:e,buffer:r,source:new QQ(()=>r),unsub:()=>{},status:`connecting`,error:null,lastFrameAt:Date.now(),lastColCount:0,lastValued:0,recorder:null,schemas:new Map,video:n===`camera`?new OE:null,clock:n===`camera`?null:new ZQ,lagTicks:0,lastRejoinAt:0,rejoin:()=>{},subscribed:!1,releaseTimer:void 0}}function z$(e,t,n=()=>({}),r){let i=new Map,a=e,o=[],s=[],c=``,l=()=>{let e=[];for(let t of i.values())t.lastColCount=t.buffer.columnNames.length,t.lastValued=t.buffer.valuedCount,e.push({...t.meta,kind:t.video?`camera`:`data`,video:t.video,clock:t.clock,dataset:t.buffer.toDataset(j$),source:t.source,rowCount:t.buffer.size,status:t.status,error:t.error,recordingSince:t.recorder?.startedAt??null});o=e,t(o)},u=(e,t)=>{let n=!1,r=e.buffer.endAbs;for(let r of t)r&&typeof r.t==`number`&&Array.isArray(r.signals)&&(e.buffer.push(r),e.recorder?.add(r),n=!0);n&&p(e,r,t[t.length-1]?.t)},d=(e,t)=>{let n=e.buffer.endAbs;e.buffer.pushColumns(t),e.recorder?.addColumns(t),t.t.length>0&&p(e,n,t.t[t.t.length-1])},p=(e,t,n)=>{s$(e.buffer,s,t),e.segAxis?.tracker.feed(e.buffer,t),r?.rows(e.meta.id,e.buffer,t),typeof n==`number`&&e.clock?.observe(n,Date.now()/1e3),m(e,t===0||e.buffer.columnNames.length!==e.lastColCount||e.buffer.valuedCount!==e.lastValued)},m=(e,t)=>{e.lastFrameAt=Date.now();let n=e.status===`stale`||e.status===`connecting`;n&&(e.status=`live`),(n||t)&&l()},h=e=>{let t=i.get(e);t&&(clearTimeout(t.releaseTimer),t.unsub(),i.delete(e),l())},g=setInterval(()=>{let e=Date.now(),t=!1;for(let n of i.values()){n.status===`live`&&e-n.lastFrameAt>M$&&(n.status=`stale`,t=!0);let i=n.video&&n.subscribed&&n.status===`live`?n.video.info().lagMs:null;n.lagTicks=i!==null&&i>P$?n.lagTicks+1:0,n.video&&n.lagTicks>=F$&&e-n.lastRejoinAt>=I$&&(n.lagTicks=0,n.lastRejoinAt=e,n.video.resync(),n.unsub(),n.rejoin()),n.buffer.size&&r?.tick(n.meta.id,n.buffer,n.lastFrameAt)}t&&l()},N$);return{connections:()=>o,disconnect:h,startRecording(e){let t=i.get(e);!t||t.recorder||(t.recorder=new n$,l())},stopRecording(e){let t=i.get(e),n=t?.recorder;return!t||!n?null:(t.recorder=null,l(),{csv:n.toCsvParts(),rows:n.rows,name:t.meta.name,startedAt:n.startedAt})},setRelay(e){a=e},setSegmentAxis(e,t){let n=i.get(e);n&&(n.segAxis=t?{cfg:t,tracker:O$(t)}:void 0,t&&n.segAxis.tracker.feed(n.buffer,n.buffer.firstAbs,!t.replay),l())},setMathChannels(e){let t=JSON.stringify(e.map(e=>[e.id,e.name,e.units,e.formula,e.enabled]));if(t!==c){c=t,s=e;for(let t of i.values())t.video||(c$(t.buffer,e),t.segAxis&&(t.segAxis.tracker=O$(t.segAxis.cfg),t.segAxis.tracker.feed(t.buffer,t.buffer.firstAbs,!0)));i.size>0&&l()}},openLocal(e,t){let r=`local:${crypto.randomUUID()}`,a=R$({id:r,name:e,ownerName:`This page`,visibility:`private`,orgName:null,parentId:null,lowOf:null},{...n(),...t});return i.set(r,a),l(),{id:r,push:e=>{i.get(r)===a&&u(a,Array.isArray(e)?e:[e])},pushColumns:e=>{i.get(r)===a&&d(a,e)},close:()=>h(r)}},async connect(e,t,r){if(i.has(e.id))return;let o=a&&e.relay_url?{...a,url:e.relay_url}:a;if(!o)throw new kE(`relay_unavailable`);let s=typeof t==`string`?await f(ue(t).secret??t,e.salt):`keyFor`in t?e=>t.keyFor(e):t;if(typeof s!=`function`&&!await ge(s,e.key_check))throw new kE(`wrong_password`);let c=R$({id:e.id,name:e.name,ownerName:e.owner_name??``,visibility:e.visibility??`private`,orgName:e.org_name??null,projectName:e.project_name??null,parentId:e.parent_stream_id??null,lowOf:e.low_of_stream_id??null},{...n(),...r},e.kind);i.set(e.id,c);let p=Promise.resolve();c.rejoin=()=>{c.unsub=GQ(o,e.id,t=>{let n=ye(s,t).catch(()=>null);p=p.then(async()=>{try{let t=await n;if(!t||i.get(e.id)!==c)return;if(t.kind===6){let e=YQ(t.plaintext);e&&c.video&&(c.video.push(e),m(c,!1));return}if(t.kind===5){let e=de(t.plaintext);c.schemas.set(e.id,e);return}if(t.kind===7){let e=he(t.plaintext,c.schemas);if(!e)return;let n=c.buffer;for(let t of e)n.setLastKnown(t.name,t.unit,t.t,t.v);(n.columnNames.length!==c.lastColCount||n.valuedCount!==c.lastValued)&&l();return}if(t.kind===4){let e=await Ge(t.plaintext,c.schemas);e&&!e.historical&&d(c,e.block);return}if(t.kind===3)return d(c,Ie(t.plaintext));if(t.kind!==2)return;let r=ie(t.plaintext);u(c,Array.isArray(r?.frames)?r.frames:[])}catch{}})},t=>{!c.subscribed||i.get(e.id)!==c||(t===`subscribed`?(c.status=`live`,c.lastFrameAt=Date.now()):t===`error`&&(c.status=`error`,c.error=`connection_error`),l())})};let h=c.video;h?(c.status=`idle`,h.onDemandChange(t=>{i.get(e.id)===c&&(clearTimeout(c.releaseTimer),t?c.subscribed||(c.subscribed=!0,h.resync(),c.status=`connecting`,c.lastFrameAt=Date.now(),c.rejoin(),l()):c.releaseTimer=setTimeout(()=>{c.subscribed=!1,c.unsub(),c.unsub=()=>{},c.status=`idle`,c.error=null,c.lagTicks=0,l()},L$))})):(c.subscribed=!0,c.rejoin()),l()},dispose(){clearInterval(g);for(let e of i.values())clearTimeout(e.releaseTimer),e.unsub();i.clear(),o=[]}}}var B$=500,V$=1<<20;function H$(e){let t=[],n=new Map,r=[],i=``,a=(e,t)=>`${e}|${t}`,o=(e,t)=>{let n=t.kind===`stream`?e.targets?.streams:t.kind===`history`?e.targets?.histories:e.targets?.datasets;return!n||n.includes(t.kind===`dataset`?t.name??t.id:t.id)},s=()=>[...n.values()].map(e=>{let{state:t,missing:n,since:r}=e.state();return{ruleId:e.rule.id,target:e.target,state:t,...n?{missing:n}:{},...r===void 0?{}:{since:r}}}),c=()=>{let t=s(),n=JSON.stringify(t);n!==i&&(i=n,e.setStates(t))};function l(n,i){let a=t.find(e=>e.id===n.ruleId);if(n.kind===`raised`){r=[...r,{id:`${n.ruleId}|${n.target.id}|${n.t}`,ruleId:n.ruleId,ruleName:a?.name??``,severity:a?.severity??`info`,targetId:n.target.id,timeColumn:i,t0:n.t,t1:null}];let e=r.filter(e=>e.targetId===n.target.id);e.length>B$&&(r=r.filter(t=>t!==e[0]))}else{let e=r.find(e=>e.ruleId===n.ruleId&&e.targetId===n.target.id&&e.t1===null);e&&(r=r.map(t=>t===e?{...t,t1:n.t}:t))}e.setMarks(r),e.emit(n)}function u(){let r=new Set;for(let i of e.targets())for(let e of t){if(!o(e,i))continue;let t=a(e.id,i.id);r.add(t);let s=n.get(t),{channels:c,...u}=i;(!s||s.rule!==e)&&(s=et(e,u),n.set(t,s));for(let e of s.bind(c))l(e,i.kind===`stream`?qe:``)}for(let e of n.keys())r.has(e)||n.delete(e);c()}return{setRules(n){let r=[],i=n.filter(e=>{let t=tt(e);return r.push(...t.map(t=>({ruleId:String(e?.id??``),...t}))),!t.length}),a=e.maxRules();a!==null&&i.length>a&&e.limit();let o=new Map(t.map(e=>[e.id,e]));return t=(a===null?i:i.slice(0,a)).map(e=>{let t=o.get(e.id);return t&&t.version===e.version?t:e}),u(),r},rules:()=>t,state:s,async evaluate(n,i){let a=e.targets().find(e=>e.id===n&&e.kind===`dataset`);if(!a)return[];let{channels:s,...c}=a,u=[],d=t.filter(e=>(!i.ruleIds||i.ruleIds.includes(e.id))&&o(e,c)),f=d.map(e=>{let t=et(e,c);return t.bind(s),t}),p=[...new Set(d.flatMap(e=>Object.values(e.signals).map(e=>`formula`in e?e.formula:e.channel)))];for(let t=0;;t+=V$){let r=await e.readDataset(n,[i.timeColumn,...p],t,V$),a=r[i.timeColumn];if(!a||!a.length)break;for(let e of f)u.push(...e.push({t:a,columns:r}));if(a.length<V$)break}r=r.filter(e=>!(e.targetId===n&&(!i.ruleIds||i.ruleIds.includes(e.ruleId)))),e.setMarks(r);for(let e of u)l(e,i.timeColumn);return u},pushLive(e,t){let r=!1;for(let i of n.values()){if(i.target.id!==e)continue;let n=i.push(t);n.length&&(r=!0);for(let e of n)l(e,qe)}r&&c()},tickLive(e,t){let r=!1;for(let i of n.values()){if(i.target.id!==e)continue;let n=i.tick(t);n.length&&(r=!0);for(let e of n)l(e,qe)}r&&c()},liveColumns(e){let t=new Set;for(let r of n.values())if(r.target.id===e)for(let e of Object.values(r.rule.signals))t.add(`formula`in e?e.formula:e.channel);return[...t]},sync:u,clearMarks(t){r=t?r.filter(e=>e.targetId!==t):[],e.setMarks(r)}}}var U$=class{past=[];future=[];current=null;lastAt=-1/0;o;equals;constructor(e){this.o=e,this.equals=e.equals??Object.is}get canUndo(){return this.past.length>0}get canRedo(){return this.future.length>0}observe(e){if(this.current===null)return this.current=e,!1;if(this.equals(e,this.current))return!1;let t=this.o.now();return t-this.lastAt<this.o.mergeMs&&this.past.length>0||(this.past.push(this.current),this.past.length>this.o.limit&&this.past.shift()),this.current=e,this.future=[],this.lastAt=t,!0}rebase(e){this.current=e}undo(){if(this.past.length===0)return null;let e=this.past.pop();return this.future.push(this.current),this.current=e,this.lastAt=-1/0,e}redo(){if(this.future.length===0)return null;let e=this.future.pop();return this.past.push(this.current),this.current=e,this.lastAt=-1/0,e}clear(e){this.past=[],this.future=[],this.current=e,this.lastAt=-1/0}},W$={maxChartsPerWorksheet:null,maxChannelsPerChart:null,maxWorksheets:null,maxMathChannels:null,maxAlertRules:null,canImportExportWorkspaces:!0},G$=[];function K$(e,t){let n=e.found[t];return{definitionId:n.definitionId,rule:e.defs.find(e=>e.id===n.definitionId)?.name??n.definitionId,index:n.index,parentIndex:n.parentIndex??null,tstart:n.tstart,tend:n.tend,flags:n.flags,kpis:n.kpis??{},incomplete:!!n.incomplete}}var q$=[`#a78bfa`,`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#94a3b8`];function J$(e=`ET`){return{id:crypto.randomUUID(),name:`Worksheet`,panels:[],panelChartSettings:{},panelChartBackgrounds:{},xKey:e}}function Y$(e,t){let n=e.filter(e=>e.source!==`workbook`),r=new Map,i=[];for(let e of t){let t=n.find(t=>t.name===e.name);if(t&&t.formula===e.formula&&t.units===e.units)continue;let a=t?`${e.name} (workbook)`:e.name;t&&r.set(e.name,a),i.push(cr({...e,name:a,source:`workbook`}))}return{channels:i,rename:r}}function X$(e,t){let n=JSON.stringify({xKey:e.xKey,panelChartSettings:e.panelChartSettings});for(let[e,r]of t)n=n.split(JSON.stringify(e)).join(JSON.stringify(r));return{...e,...JSON.parse(n)}}function Z$(e){return typeof e.text==`function`?e.text():new Promise((t,n)=>{let r=new FileReader;r.onload=()=>t(String(r.result??``)),r.onerror=()=>n(r.error),r.readAsText(e)})}function Q$(e,t,n){if(!e||!t)return $t();let{min:r,max:i}=Sz(e.rows,t);if(!Number.isFinite(r)||!Number.isFinite(i))return $t();let a=wz(i-r||1,6),o=a>=1?Math.round(a):a,s=o>=1?1:o/10,c=Math.max(0,Math.ceil(-Math.log10(s))),l=e=>String(Number(e.toFixed(c)));return{...n,scaleMin:l(Math.floor(r/s)*s),scaleMax:l(Math.ceil(i/s)*s),majorStep:l(o),minorStep:``}}function $$(e,t){let n=t.includes(e.xKey)?e.xKey:t.includes(`ET`)?`ET`:t.includes(`ElapsedTime`)?qe:t[0],r={...e.panelChartSettings};for(let n of e.panels){let e=r[n.id];if(n.kind===`multiband`){let i=e&&e.kind===`multiband`?e:pn();r[n.id]={...i,kind:`multiband`,addColumn:i.addColumn&&t.includes(i.addColumn)?i.addColumn:t[0]}}else if(n.kind===`xyscatter`){let i=e&&e.kind===`xyscatter`?e:mn(q$[2]),a=i.xyXCol||t[0],o=i.xyYCol||(t.length>1&&t[1]!==a?t[1]:t[0]);r[n.id]={...i,kind:`xyscatter`,xyXCol:a,xyYCol:o}}else if(n.kind===`xyzmesh`){let i=e&&e.kind===`xyzmesh`?e:hn(4),a=i.xyzXCol||t[0],o=i.xyzYCol||(t.length>1?t[1]:t[0]),s=i.xyzZCol||(t.length>2?t[2]:t[0]);r[n.id]={...i,kind:`xyzmesh`,xyzXCol:a,xyzYCol:o,xyzZCol:s}}}return{...e,xKey:n,panelChartSettings:r}}function e1(e,t){let n=!1,r={...e.panelChartSettings};for(let[i,a]of Object.entries(e.panelChartSettings)){if(a.kind!==`multiband`)continue;let e=a.series.filter(e=>t(e.column));e.length!==a.series.length&&(r[i]={...a,series:e},n=!0)}return n?{...e,panelChartSettings:r}:e}function t1(){return typeof document>`u`?`dark`:$z(null)}function n1(e={}){let t={...e},n=!1,r=J$(),i=kQ({datasets:[],selection:[],worksheets:[r],activeWorksheetId:r.id,xRanges:{},offsets:{},colors:{},liveWindowSeconds:15,segmentContext:null,cycleRules:[],live:[],video:[],mathChannels:[],limits:{...W$,...t.limits},palette:Xz(t.palette,t1()),importing:0,licensed:null,history:{canUndo:!1,canRedo:!1},marks:[],alerts:[],alertRules:[]}),a=RV(),o=()=>{let e=Xz(t.palette,t1());i.set(t=>t.palette.join()===e.join()?t:{...t,palette:e})},s=typeof document>`u`?()=>{}:eB(null,o),c=jQ(),l=()=>{if(n)throw new kE(`disposed`)},u=e=>{throw a.emit(`limit`,{reason:e}),new kE(`limit_reached`,{reason:e})},d=()=>i.get(),f=(e,t)=>{let n=d().limits.maxChannelsPerChart,r=Cz(t);n!==null&&r>n&&r>Cz(e)&&u(`channels-per-chart`)},p=AQ((e,t)=>t===null?e:e.slice(0,t)),m=()=>{let e=d(),t=c.lapsByDataset(e.datasets),n=c.selectedDatasets(e.datasets,t,e.selection),r=c.selectedLive(e.live,e.selection),i=c.staticDataset(n),a=c.mergedDataset(i,r),o=p(e.mathChannels,e.limits.maxMathChannels);return{laps:t,selectedDatasets:n,selectedLive:r,staticDataset:i,merged:a,channels:o,numericColumns:c.numericColumns(a,n,o,c.mergedParts(n,r),r),allColumns:c.allColumns(a,n,o),columnUnits:c.columnUnits(a,o)}},h=(e,t)=>({id:t.id,kind:t.kind,title:t.title??null,settings:e.panelChartSettings[t.id],background:e.panelChartBackgrounds[t.id]??null,annotations:e.panelChartSettings[t.id]?.annotations??G$,layout:t.rect}),g=AQ((e,t,n)=>e.map(e=>({id:e.id,name:e.name,xKey:e.xKey,xRange:t[e.id]??null,liveWindowSeconds:e.liveWindowSeconds===void 0?n:e.liveWindowSeconds,charts:e.panels.map(t=>h(e,t))}))),_=AQ((e,t,n,r,i,a,o)=>{let s=(e,t)=>{let n=a.findIndex(t=>t.id===e);return n>=0?n:t};return e.map((e,a)=>{let c=i[e.id],l=c?.laps.map(e=>e.id)??[],u=l.filter(e=>t.includes(e)).length;return{id:e.id,name:e.name,kind:e.kind,columns:e.schema.map(e=>({name:e.name,unit:e.unit??``,numeric:e.type===`number`})),rowCount:e.data.rows.length,color:Jz(n,e.id,s(e.id,a),o),customColor:e.id in n,offset:r[e.id]??0,parseConfig:e.parseConfig??null,fileInfo:e.info??null,beacon:e.beacon??null,cut:e.cut?{cycleId:e.cut.cycleId,timeKey:e.cut.timeKey,defs:e.cut.defs}:null,laps:c?c.laps.map((i,a)=>({id:i.id,name:i.name,value:c.values[a],unit:c.unit,isTime:c.isTime,color:Jz(n,i.id,s(i.id,a),o),offset:r[i.id]??0,selected:t.includes(i.id),...e.cut?{cycle:K$(e.cut,a)}:{}})):null,selected:c?u===0?!1:u===l.length?!0:`partial`:t.includes(e.id)}})}),v=AQ((e,t,n,r,i)=>{let a=e.filter(e=>t.includes(e.id)).map(e=>e.id);return e.map((e,o)=>({id:e.id,name:e.name,ownerName:e.ownerName,visibility:e.visibility,orgName:e.orgName,kind:e.kind,parentId:e.parentId,lowOf:e.lowOf,status:e.status,error:e.error,rowCount:e.rowCount,selected:t.includes(e.id),color:Jz(n,e.id,a.includes(e.id)?r+a.indexOf(e.id):o,i),customColor:e.id in n,recordingSince:e.recordingSince,channels:e.dataset.columnNames}))}),y=AQ(e=>{let t=m();return{datasets:_(e.datasets,e.selection,e.colors,e.offsets,t.laps,t.selectedDatasets,e.palette),selection:e.selection,worksheets:g(e.worksheets,e.xRanges,e.liveWindowSeconds),activeWorksheetId:e.activeWorksheetId,mathChannels:t.channels,live:v(e.live,e.selection,e.colors,t.selectedDatasets.length,e.palette),liveWindowSeconds:(()=>{let t=e.worksheets.find(t=>t.id===e.activeWorksheetId);return t?.liveWindowSeconds===void 0?e.liveWindowSeconds:t.liveWindowSeconds})(),segmentContext:e.segmentContext,cycleRules:e.cycleRules,limits:e.limits,palette:e.palette,importing:e.importing,licensed:e.licensed,hasData:t.merged!==null,multiDataset:t.selectedDatasets.length+t.selectedLive.length>1,numericColumns:t.numericColumns,allColumns:t.allColumns,columnUnits:t.columnUnits,history:e.history,marks:e.marks,alerts:e.alerts}}),b=(e,t)=>e===t||e.length===t.length&&e.every((e,n)=>e===t[n]||JSON.stringify(e)===JSON.stringify(t[n])),x=new U$({limit:100,mergeMs:500,now:()=>Date.now(),equals:(e,t)=>e.liveWindowSeconds===t.liveWindowSeconds&&b(e.worksheets,t.worksheets)&&b(e.channels,t.channels)}),S=!0,C=0,w=e=>{C++;try{e()}finally{C--}},T=e=>[e.worksheets,e.mathChannels,e.liveWindowSeconds],E=[],D=()=>{let e=d();return{worksheets:e.worksheets,channels:e.mathChannels.filter(e=>e.source===`workbook`),liveWindowSeconds:e.liveWindowSeconds,activeWorksheetId:e.activeWorksheetId}},O=()=>i.set(e=>e.history.canUndo===x.canUndo&&e.history.canRedo===x.canRedo?e:{...e,history:{canUndo:x.canUndo,canRedo:x.canRedo}}),k=()=>{if(S)return;let e=T(d());e.every((e,t)=>e===E[t])||(E=e,C?x.rebase(D()):x.observe(D()),O())},A=()=>{E=T(d()),x.clear(D()),O()},j=e=>{S=!0;let t;try{t=e()}finally{S=!1}return A(),t},M=()=>y(d());i.subscribe(()=>{k(),a.emit(`change`,M())});let N=e=>{let t=d(),n=t.worksheets.find(n=>n.id===(e??t.activeWorksheetId));if(!n)throw new kE(`not_found`,{worksheetId:e});return n},P=e=>{for(let t of d().worksheets){let n=t.panels.find(t=>t.id===e);if(n)return{ws:t,panel:n}}throw new kE(`not_found`,{chartId:e})},F=(e,t)=>i.set(n=>{let r=!1,i=n.worksheets.map(n=>{if(n.id!==e)return n;let i=t(n);return i!==n&&(r=!0),i});return r?{...n,worksheets:i}:n}),I=(e,t)=>{let{ws:n}=P(e);F(n.id,n=>({...n,panelChartSettings:{...n.panelChartSettings,[e]:t(n.panelChartSettings[e])}}))},L=e=>i.set(t=>e.length===t.selection.length&&e.every((e,n)=>e===t.selection[n])?t:{...t,selection:e,xRanges:{}}),R=new Set,z=z$(t.live?.relay,e=>{let t=e.map(e=>e.id),n=e.filter(e=>e.kind===`data`&&!R.has(e.id)).map(e=>e.id),r=[...R].filter(e=>!t.includes(e));if(R=new Set(t),i.set(t=>({...t,live:e})),r.length&&L(d().selection.filter(e=>!r.includes(e))),n.length){let e=d().selection,t=n.filter(t=>!e.includes(t));t.length&&L([...e,...t])}let a=m();if(a.selectedLive.length&&a.merged){let e=a.merged.columnNames;if(e.includes(`ElapsedTime`))for(let t of d().worksheets)e.includes(t.xKey)||w(()=>F(t.id,e=>({...e,xKey:qe})))}},()=>({capacity:t.live?.capacity,maxMemoryMB:t.live?.maxMemoryMB}),{rows:(e,t,n)=>{if(!ce.rules().length)return;t.columnNames.length!==V.get(e)&&(V.set(e,t.columnNames.length),ce.sync());let r=ce.liveColumns(e);if(!r.length)return;let i=t.endAbs,a=Math.max(n,t.firstAbs);if(i<=a)return;let o={};for(let e of r)o[e]=t.range(e,a,i);ce.pushLive(e,{t:t.range(qe,a,i),columns:o,scan:new Map})},tick:(e,t,n)=>{if(!ce.rules().length)return;let r=t.range(qe,t.endAbs-1,t.endAbs)[0];r===r&&ce.tickLive(e,r+(Date.now()-n)/1e3)}}),V=new Map,te=AQ((e,t)=>e.filter(e=>t.some(t=>SE([e],t.panelChartSettings,t.xKey).length>0))),ne=()=>z.setMathChannels(te(p(d().mathChannels,d().limits.maxMathChannels),d().worksheets));ne(),i.subscribe(ne);let re=e=>{i.set(t=>({...t,datasets:[...t.datasets,e]})),L([...d().selection,e.id]);let t=xz(e.schema);t.length&&w(()=>i.set(e=>({...e,worksheets:e.worksheets.map(e=>$$(e,t))})))},ie=Promise.resolve(),U=async(e,r={})=>{l();let o=e.map(e=>e instanceof File?e:e.file);if(o.length===0)return{ids:[],errors:[]};if(await t.beforeImport?.()===!1)throw new kE(`import_vetoed`);let{signal:s}=r;i.set(e=>({...e,importing:e.importing+o.length}));let c=ie.then(async()=>{let e={ids:[],errors:[]},t=o.length,c=e=>{t-=e,i.set(t=>({...t,importing:Math.max(0,t.importing-e)}))};try{let{items:t,errors:i}=await DR(o);c(o.length-t.length);for(let{file:t,error:n}of i)e.errors.push({file:t,error:n}),a.emit(`import`,{file:t,phase:`error`,error:n}),a.emit(`error`,{error:n,context:`import`});for(let i of t){if(n)break;if(s?.aborted){e.cancelled=!0;break}let t=i.main;await new Promise(e=>setTimeout(e,0)),a.emit(`import`,{file:t.name,phase:`start`});try{let o=i.format?await bz({main:t,companions:i.companions,format:i.format.id},{priorInMemoryValues:yR(d().datasets),signal:s,onProgress:e=>a.emit(`import`,{file:t.name,phase:`progress`,fraction:e}),chooseChannels:r.chooseChannels,pickChannels:r.pickChannels}):[await vR(crypto.randomUUID(),t,d().datasets)??await gR(crypto.randomUUID(),t,Z$,void 0,yR(d().datasets),s)];if(n){for(let e of o)e.source.dispose();break}if(s?.aborted){for(let e of o)e.source.dispose();throw new kE(`cancelled`)}for(let t of o)re(t),e.ids.push(t.id);a.emit(`import`,{file:t.name,phase:`done`,datasetId:o[0].id,datasetIds:o.map(e=>e.id)})}catch(n){let r=n instanceof Error?n:Error(String(n));a.emit(`import`,{file:t.name,phase:`error`,error:r}),r instanceof kE&&r.code===`cancelled`?e.cancelled=!0:(e.errors.push({file:t.name,error:r}),a.emit(`error`,{error:r,context:`import`}))}finally{c(1)}if(e.cancelled)break}}finally{t>0&&c(t)}return e});return ie=c.catch(()=>void 0),c},ae=()=>setTimeout(()=>{n||HZ(nt)},0),oe=e=>{let t=t=>e.some(e=>t===e||t.startsWith(`${e}::`)),n=d().datasets.filter(t=>e.includes(t.id));for(let e of n)e.source.dispose().catch(()=>void 0);i.set(n=>{let r={...n.offsets},i={...n.colors};for(let e of Object.keys(r))t(e)&&delete r[e];for(let e of Object.keys(i))t(e)&&delete i[e];return{...n,datasets:n.datasets.filter(t=>!e.includes(t.id)),offsets:r,colors:i}}),L(d().selection.filter(e=>!t(e))),n.length>0&&ae()},se=async(e,t,n={})=>{let[r,...i]=await bz({main:new File(e.chunks,`${e.name}.krc`),companions:[],format:`krc`,keys:e.keys},{priorInMemoryValues:t,...n});for(let e of i)e.source.dispose();return{...r,file:void 0,name:e.name,info:r.info&&{...r.info,startTime:e.startTime??r.info.startTime,meta:{...r.info.meta,recordingId:e.recordingId}}}},ce=H$({targets:()=>[...d().datasets.map(e=>({kind:`dataset`,id:e.id,name:e.name,channels:e.schema.map(e=>e.name)})),...d().live.filter(e=>e.kind===`data`).map(e=>({kind:`stream`,id:e.id,name:e.name,channels:e.source.columnNames}))],maxRules:()=>d().limits.maxAlertRules,emit:e=>a.emit(`alert`,e),limit:()=>a.emit(`limit`,{reason:`alert-rules`}),setMarks:e=>i.set(t=>({...t,marks:e})),setStates:e=>i.set(t=>({...t,alerts:e})),readDataset:(e,t,n,r)=>{let i=d().datasets.find(t=>t.id===e);return i?i.source.readColumns(t,n,r):Promise.resolve({})}}),le=AQ((e,t)=>{let n=new Map;for(let r of e){let e=rt(r);e!==null&&n.set(r.id,{value:e,active:t.some(e=>e.ruleId===r.id&&(e.state===`active`||e.state===`clearing`))})}return n}),ue=null;i.subscribe(()=>{let e=d();ue&&ue[0]===e.datasets&&ue[1]===e.live||(ue=[e.datasets,e.live],ce.rules().length&&ce.sync())});let de={importFiles:U,warmImport(e={}){l(),cz(!!e.formats?.some(e=>e===`hdf5`||e===`mat`))},async splitByRate(e){l();let t=d().datasets.find(t=>t.id===e);if(!t)throw new kE(`not_found`,{datasetId:e});if(!t.info?.combined||!(t.file instanceof File))throw new kE(`invalid_argument`,{reason:`only a combined multi-rate import can be split`});let n=await bz({main:t.file,companions:t.companions??[],format:t.info.importer},{priorInMemoryValues:yR(d().datasets.filter(t=>t.id!==e)),selection:t.info.selection,split:!0});oe([e]);for(let e of n)re(e);return n.map(e=>e.id)},async chooseChannels(e,t){l();let n=d().datasets.find(t=>t.id===e);if(!n)throw new kE(`not_found`,{datasetId:e});if(!n.info||!(n.file instanceof File))throw new kE(`invalid_argument`,{reason:`only binary imports have channels to choose`});try{let r=await bz({main:n.file,companions:n.companions??[],format:n.info.importer},{priorInMemoryValues:yR(d().datasets.filter(t=>t.id!==e)),initial:n.info.selection,chooseChannels:t,pickChannels:!0});oe([e]);for(let e of r)re(e);return r.map(e=>e.id)}catch(e){if(e instanceof kE&&e.code===`cancelled`)return null;throw e}},async combine(e){l();let t=d().datasets.find(t=>t.id===e);if(!t)throw new kE(`not_found`,{datasetId:e});let n=t.info?.splitKey;if(!n||!(t.file instanceof File))throw new kE(`invalid_argument`,{reason:`only datasets split from one file can be combined`});let r=d().datasets.filter(e=>e.info?.splitKey===n),i=await bz({main:t.file,companions:t.companions??[],format:t.info.importer},{priorInMemoryValues:yR(d().datasets.filter(e=>!r.includes(e))),selection:r.flatMap(e=>e.info.selection)});if(i.length!==1){for(let e of i)e.source.dispose();throw new kE(`invalid_argument`,{reason:`these groups have no common time base`})}return oe(r.map(e=>e.id)),re(i[0]),i[0].id},async openRecording(e,t={}){l();let n=await se(e,yR(d().datasets),t);return re(n),n.id},async reopenRecording(e,t){l();let n=d().datasets.find(t=>t.id===e);if(!n)throw new kE(`not_found`,{datasetId:e});let r=await se(t,yR(d().datasets.filter(t=>t.id!==e)));i.set(t=>({...t,datasets:t.datasets.map(t=>t.id===e?{...r,id:e,beacon:n.beacon}:t)})),n.source.dispose().catch(()=>void 0),ae()},openHistoryRange(e){l();let t=OQ(crypto.randomUUID(),e);return re(t),t.id},updateHistoryRange(e,t){l();let n=d().datasets.find(t=>t.id===e);if(!n)throw new kE(`not_found`,{datasetId:e});if(!(n.source instanceof _Q)){let t=`dataset ${e} is not a history range: only datasets opened with openHistoryRange can be updated`;throw Object.assign(new kE(`invalid_argument`,{datasetId:e,reason:t}),{message:t})}let r=OQ(e,t);i.set(t=>({...t,datasets:t.datasets.map(t=>t.id===e?{...r,beacon:n.beacon}:t)})),ae()},addColumns(e){l();let t=xQ(crypto.randomUUID(),e);return re(t),t.id},replaceColumns(e,t,n={}){l();let r=d().datasets.find(t=>t.id===e);if(!r)throw new kE(`not_found`,{datasetId:e});let a=TQ(r,t,n.transfer);i.set(t=>({...t,datasets:t.datasets.map(t=>t.id===e?a:t)}))},writeColumns(e,t,n){l();let r=d().datasets.find(t=>t.id===e);if(!r)throw new kE(`not_found`,{datasetId:e});let a=CQ(r,t,n);i.set(t=>({...t,datasets:t.datasets.map(t=>t.id===e?a:t)}))},async addText(e,t=`dataset.csv`){l();let n=await pR(crypto.randomUUID(),t,e);return re(n),n.id},async findCycles(e,t,n){l();let r=d().datasets.find(t=>t.id===e);if(!r)throw new kE(`not_found`,{datasetId:e});let i=await BB(r.source,n,HB(t)),a=new Map(t.filter(e=>e.kpis?.length).map(e=>[e.id,e.kpis]));return VB(i,t).map(e=>a.has(e.definitionId)?{...e,kpis:WB(i,e,a.get(e.definitionId))}:e)},async addCycles(e,t){l();let n=d().datasets.find(t=>t.id===e);if(!n)throw new kE(`not_found`,{datasetId:e});let r=n.schema.filter(e=>e.type===`number`&&e.name!==t.timeKey).map(e=>e.name),i=await BB(n.source,t.timeKey,r),a={...Object.fromEntries(n.schema.map(e=>[e.name,e.unit])),[RB]:`s`},o=e=>t.defs.find(t=>t.id===e)?.name??e,s=[];for(let e of t.pick){let r=t.found.find(t=>t.definitionId===e.definitionId&&t.index===e.index&&t.parentIndex===e.parentIndex);if(!r)throw new kE(`not_found`,{reason:`no ${o(e.definitionId)} ${e.index} in the cycles found`});let c=r.parentIndex?`${o(t.cycleId)} ${r.parentIndex} · ${o(r.definitionId)}`:`${o(r.definitionId)} ${r.index}`;s.push(de.addColumns({name:`${n.name} · ${c}`,columns:KB(i,t.timeKey,r),units:a}))}if(t.tables!==!1){let e=JB(t.found,t.cycleId,t.defs,i);s.push(await de.addText(YB(e.cycles),`${n.name} · ${o(t.cycleId)}s.csv`)),e.phases.length&&s.push(await de.addText(YB(e.phases),`${n.name} · Phases.csv`))}return s},async cut(e,t){l();let n=d().datasets.find(t=>t.id===e);if(!n)throw new kE(`not_found`,{datasetId:e});let r;if(t){if(!t.defs.some(e=>e.id===t.cycleId))throw new kE(`invalid_argument`,{reason:`cycleId is not one of defs`});let i=n.schema.filter(e=>e.type===`number`&&e.name!==t.timeKey).map(e=>e.name),a=await BB(n.source,t.timeKey,i),o=t.defs.find(e=>e.id===t.cycleId)?.show,s=e=>[...e.kpis??[],...o&&o.channel!==t.timeKey?[o]:[]],c=new Map(t.defs.filter(e=>s(e).length).map(e=>[e.id,s(e)])),l=VB(a,t.defs).sort((e,t)=>e.tstart-t.tstart||!!e.parentIndex-+!!t.parentIndex).map(e=>c.has(e.definitionId)?{...e,kpis:WB(a,e,c.get(e.definitionId))}:e),u={...Object.fromEntries(n.schema.map(e=>[e.name,e.unit])),[RB]:`s`},d=e=>t.defs.find(t=>t.id===e)?.name??e,f=l.map(r=>xQ(`${e}::${r.definitionId}:${r.parentIndex??0}:${r.index}`,{name:r.parentIndex?`${n.name} · ${d(t.cycleId)} ${r.parentIndex} · ${d(r.definitionId)}`:`${n.name} · ${d(r.definitionId)} ${r.index}`,columns:KB(a,t.timeKey,r),units:u})),p=a.t.length?a.t[a.t.length-1]:NaN,m=l.map(e=>e.tend===null&&p===p?{...e,tend:p,incomplete:!0}:e);r={defs:t.defs,cycleId:t.cycleId,timeKey:t.timeKey,found:m,parts:f}}else if(!n.cut)return 0;if(!d().datasets.some(t=>t.id===e))return 0;i.set(t=>({...t,datasets:t.datasets.map(t=>t.id===e?{...t,cut:r}:t)}));let a=d().selection,o=a.some(t=>t===e||t.startsWith(`${e}::`)),s=a.filter(t=>t!==e&&!t.startsWith(`${e}::`)),c=r?r.parts.filter((e,t)=>!r.found[t].parentIndex).map(e=>e.id):[];return L(o?c.length>0?[...s,...c]:[...s,e]:s),c.length},remove(e){l(),oe([e])},clear(){l(),oe(d().datasets.map(e=>e.id))},async configure(e,t){l();let n=d().datasets.find(t=>t.id===e);if(!n)throw new kE(`not_found`,{datasetId:e});if(t.parseConfig&&(n.kind!==`memory`||!n.parseConfig))throw new kE(`invalid_argument`,{reason:n.parseConfig?`out-of-core datasets cannot be re-parsed`:`binary files have no text parse settings`});if(t.beacon!==void 0&&t.beacon!==null&&n.kind!==`memory`)throw new kE(`invalid_argument`,{reason:`laps need an in-memory dataset`});if(t.beacon!==void 0&&JSON.stringify(t.beacon)!==JSON.stringify(n.beacon??null)){let r=t.beacon??void 0;i.set(t=>({...t,datasets:t.datasets.map(t=>t.id===e?{...t,beacon:r}:t)}));let a=d().selection,o=a.some(t=>t===e||t.startsWith(`${e}::`)),s=a.filter(t=>t!==e&&!t.startsWith(`${e}::`)),c=r?vB(n.data.rows,r.channel):[],l=r&&t.selectCycles===`best`?CB(c.map(e=>SB(n.data.rows,e,r.metric,r.stat))):null,u=l===null?c.map((t,n)=>EB(e,n)):[EB(e,l)];L(o?c.length>0?[...s,...u]:[...s,e]:s)}let r=t.parseConfig;if(!r)return;let a=(()=>{try{let e=H(ze(n.rawText??``),r.headerRow);return n.data.columnNames.length===e.length&&n.data.columnNames.every((t,n)=>t===e[n])}catch{return!1}})();if(ee(r,n.parseConfig)&&a)return;let o=n.fromColumns?DQ(n):n.rawText??``,s=await PE(n.file?{file:n.file,config:r}:{rawText:o,config:r}),c=new LE(s),u=await c.getSchema(),f=n.fromColumns?{rawText:o,fromColumns:!1}:{};i.set(t=>({...t,datasets:t.datasets.map(t=>t.id===e?{...t,...f,data:s,source:c,schema:u,parseConfig:r}:t)})),n.source.dispose().catch(()=>void 0),ae(),n.cut&&await de.cut(e,n.cut);let p=m().selectedDatasets,h=new Set(p.flatMap(e=>e.data.columnNames)),g=s.columnNames.filter(e=>B(s.rows,e)),_=g.find(e=>e===`ET`)??g[0];w(()=>i.set(e=>({...e,worksheets:e.worksheets.map(e=>e1(!h.has(e.xKey)&&_?{...e,xKey:_}:e,e=>h.has(e)))})))},setColor(e,t){l(),i.set(n=>{let r={...n.colors};return t===null?delete r[e]:r[e]=t,{...n,colors:r}})},setOffset(e,t){l(),i.set(n=>({...n,offsets:{...n.offsets,[e]:t}}))},resetOffsets(){l(),i.set(e=>Object.keys(e.offsets).length?{...e,offsets:{}}:e)},select(e){l(),L([...e])},toggle(e){l();let t=d().selection,n=m().laps[e];if(n){let e=n.laps.map(e=>e.id);L(e.every(e=>t.includes(e))?t.filter(t=>!e.includes(t)):[...t,...e.filter(e=>!t.includes(e))]);return}L(t.includes(e)?t.filter(t=>t!==e):[...t,e])},selectAll(){l();let e=m().laps,t=d().live.filter(e=>d().selection.includes(e.id)).map(e=>e.id);L([...d().datasets.flatMap(t=>e[t.id]?e[t.id].laps.map(e=>e.id):[t.id]),...t])},deselectAll(){l(),L([])},raw(e){let t=d().datasets.find(t=>t.id===e);if(!t)throw new kE(`not_found`,{datasetId:e});return{get rawText(){return t.kind===`memory`&&t.fromColumns?DQ(t):t.rawText??``},data:t.data,parseConfig:t.parseConfig??null,kind:t.kind,beacon:t.beacon??null}},async columnBounds(e){l();let t=m(),n=t.selectedDatasets.find(t=>t.schema.some(t=>t.name===e));if(n&&n.kind===`memory`){let t=Sz(n.data.rows,e);if(Number.isFinite(t.min)&&Number.isFinite(t.max))return t}else if(n){let t=await n.source.xBounds(e).catch(()=>null);if(t&&Number.isFinite(t.x0)&&Number.isFinite(t.x1)&&t.x1>=t.x0)return{min:t.x0,max:t.x1}}let r=t.selectedLive.find(t=>t.dataset.columnNames.includes(e));if(r){let t=r.source.valueBoundsSync(e);if(t)return t}let i=fe(e);if(!i)return null;let a=Sz(i.rows,e);return Number.isFinite(a.min)&&Number.isFinite(a.max)?a:null}},fe=(e,t=N().xKey)=>{let n=m();if(!n.merged)return null;if(!n.channels.find(t=>t.name===e))return n.merged;let r=xE(n.merged,n.channels,t);return{...n.merged,columnNames:[...n.merged.columnNames,...r.ok.map(e=>e.name)],rows:r.rows}},pe=(e,t,n)=>m().selectedLive.length>0?{...n,scaleMin:``,scaleMax:``,majorStep:``,minorStep:``}:Q$(fe(e,t),e,n),me={fromFileList:e=>EV(Array.from(e)),async fromDataTransfer(e){return DV(Array.from(e.items??[]).map(e=>e.webkitGetAsEntry?.()).filter(e=>!!e))},canPick:OV,pick:kV,tree:(e,t)=>TV(e,t),isImportable:wV},he={add(e=`Worksheet`){l();let t=d(),n=t.limits.maxWorksheets;n!==null&&t.worksheets.length>=n&&u(`worksheets`);let r={...J$(N().xKey||`ET`),name:e};return i.set(e=>({...e,worksheets:[...e.worksheets,r],activeWorksheetId:r.id})),r.id},rename(e,t){l(),N(e),F(e,e=>e.name===t?e:{...e,name:t})},remove(e){l();let t=d();if(N(e),t.worksheets.length<=1)throw new kE(`invalid_argument`,{reason:`the last worksheet cannot be removed`});let n=t.worksheets.findIndex(t=>t.id===e),r=t.worksheets.filter(t=>t.id!==e);i.set(t=>({...t,worksheets:r,activeWorksheetId:t.activeWorksheetId===e?r[Math.max(0,n-1)].id:t.activeWorksheetId}))},reorder(e,t){l(),i.set(n=>{if(e===t||e<0||t<0||e>=n.worksheets.length||t>=n.worksheets.length)return n;let r=[...n.worksheets],[i]=r.splice(e,1);return r.splice(t,0,i),{...n,worksheets:r}})},activate(e){l(),N(e),i.set(t=>t.activeWorksheetId===e?t:{...t,activeWorksheetId:e,xRanges:{...t.xRanges,[e]:null}})},setXKey(e,t){l(),N(e),F(e,e=>e1({...e,xKey:t},e=>e!==t)),i.set(t=>({...t,xRanges:{...t.xRanges,[e]:null},offsets:{}}))}},ge={mount(e,t,n){return l(),VZ(nt,e,t,n)},openWindow(e,t){return l(),P(e),dQ(nt,e,(t,n)=>VZ(nt,e,t,n),t)},setFonts(e){e.sans&&(Q.sans=e.sans),e.mono&&(Q.mono=e.mono),HZ(nt)},kinds:()=>MQ,label:PQ,add(e,t={}){if(l(),!MQ.some(t=>t.kind===e))throw new kE(`invalid_argument`,{kind:e});let n=N(t.worksheetId),r=d().limits.maxChartsPerWorksheet;r!==null&&n.panels.length>=r&&u(`charts-per-worksheet`);let i={...Xt(e,n.panels),...t.title?{title:t.title}:{}};t.layout&&(i.rect={...t.layout});let a=ir([i],{},q$[2],4)[i.id],o=a,s=m().numericColumns;if(s.length&&(o.kind===`multiband`||o.kind===`xyscatter`||o.kind===`xyzmesh`)&&(o=$$({...n,panels:[i],panelChartSettings:{[i.id]:o}},s).panelChartSettings[i.id],o.kind===`multiband`&&(o={...o,addColumn:s.find(e=>e!==n.xKey)??s[0]})),t.settings&&(o={...o,...t.settings,kind:o.kind}),s.length&&o.kind===`xyscatter`){let e=t.settings??{};o={...o,xyXScale:e.xyXScale??pe(o.xyXCol,n.xKey,o.xyXScale),xyYScale:e.xyYScale??pe(o.xyYCol,n.xKey,o.xyYScale)}}return f(a,o),F(n.id,e=>({...e,panels:t.layout?[...e.panels,i]:Qt([...e.panels,i]),panelChartSettings:{...e.panelChartSettings,[i.id]:o}})),i.id},remove(e){l();let{ws:t}=P(e);F(t.id,t=>{let n={...t.panelChartSettings},r={...t.panelChartBackgrounds};return delete n[e],delete r[e],{...t,panels:Qt(t.panels.filter(t=>t.id!==e)),panelChartSettings:n,panelChartBackgrounds:r}})},rename(e,t){l();let{ws:n}=P(e),r=t?.trim()||void 0;F(n.id,t=>({...t,panels:t.panels.map(t=>{if(t.id!==e)return t;let{title:n,...i}=t;return r?{...i,title:r}:i})}))},update(e,t){l();let{ws:n}=P(e),r=n.panelChartSettings[e],i={...r,...t,kind:r.kind};if(r.kind===`xyscatter`&&i.kind===`xyscatter`){let e=t;typeof e.xyXCol==`string`&&e.xyXCol!==r.xyXCol&&!(`xyXScale`in e)&&(i={...i,xyXScale:pe(e.xyXCol,n.xKey,r.xyXScale)}),typeof e.xyYCol==`string`&&e.xyYCol!==r.xyYCol&&!(`xyYScale`in e)&&(i={...i,xyYScale:pe(e.xyYCol,n.xKey,r.xyYScale)})}f(r,i),I(e,()=>i)},replaceSettings(e,t){l();let{ws:n,panel:r}=P(e);if(t.kind!==r.kind)throw new kE(`invalid_argument`,{reason:`settings kind mismatch`});f(n.panelChartSettings[e],t),I(e,()=>t)},setBackground(e,t){l();let{ws:n}=P(e);F(n.id,n=>({...n,panelChartBackgrounds:{...n.panelChartBackgrounds,[e]:t}}))},addAnnotation(e,t){l(),P(e);let n=Nt({...t,id:t.id||crypto.randomUUID()});if(!n)throw new kE(`invalid_argument`,{reason:`not a valid annotation`});return I(e,e=>({...e,annotations:[...(e.annotations??[]).filter(e=>e.id!==n.id),n]})),n.id},updateAnnotation(e,t,n){l();let r=(P(e).ws.panelChartSettings[e]?.annotations??[]).find(e=>e.id===t);if(!r)throw new kE(`not_found`,{annotationId:t});let i=Nt({...r,...n,id:r.id,kind:r.kind});if(!i)throw new kE(`invalid_argument`,{reason:`not a valid annotation`});I(e,e=>({...e,annotations:(e.annotations??[]).map(e=>e.id===i.id?i:e)}))},removeAnnotation(e,t){l(),P(e),I(e,e=>({...e,annotations:(e.annotations??[]).filter(e=>e.id!==t)}))},setAnnotations(e,t){l(),P(e);let n=Pt(t)??[];I(e,e=>({...e,annotations:n}))},setLayout(e,t){l();let{ws:n}=P(e);F(n.id,n=>({...n,panels:n.panels.map(n=>n.id===e?{...n,rect:{...t}}:n)}))},setLayouts(e,t){l(),F(e,e=>({...e,panels:e.panels.map(e=>t[e.id]?{...e,rect:{...t[e.id]}}:e)}))},autoLayout(e){l(),F(N(e).id,e=>({...e,panels:Qt(e.panels)}))},get(e){let{ws:t,panel:n}=P(e);return h(t,n)},list(e){let t=N(e);return t.panels.map(e=>h(t,e))},async addSeries(e,t){l();let{ws:n}=P(e),r=n.panelChartSettings[e];if(!r||r.kind!==`multiband`)throw new kE(`invalid_argument`,{reason:`not a multiband chart`});let i=d().limits.maxChannelsPerChart;i!==null&&Cz(r)>=i&&u(`channels-per-chart`);let a=m().numericColumns,o=new Set(r.series.map(e=>e.column)),s=t??a.find(e=>e!==n.xKey&&!o.has(e))??a.find(e=>e!==n.xKey)??``;if(!s)return null;let c=sr(),f={id:c,column:s,color:q$[r.series.length%q$.length],bandFromPct:0,bandToPct:100,scaleMin:0,scaleMax:1,yMajorStep:0,yMinorStep:0};return I(e,e=>e.kind===`multiband`?{...e,series:[...e.series,f]}:e),await ge.autoScaleSeries(e,c),c},async updateSeries(e,t,n){l();let{ws:r}=P(e),i=r.panelChartSettings[e],a=i&&i.kind===`multiband`?i.series.find(e=>e.id===t):void 0;if(!a)throw new kE(`not_found`,{seriesId:t});I(e,e=>e.kind===`multiband`?{...e,series:e.series.map(e=>e.id===t?{...e,...n,id:e.id}:e)}:e),n.column&&n.column!==a.column&&n.scaleMin===void 0&&n.scaleMax===void 0&&await ge.autoScaleSeries(e,t)},removeSeries(e,t){l(),I(e,e=>e.kind===`multiband`?{...e,series:e.series.filter(e=>e.id!==t)}:e)},reorderSeries(e,t){l(),I(e,e=>{if(e.kind!==`multiband`)return e;let n=new Map(e.series.map(e=>[e.id,e])),r=t.map(e=>n.get(e)).filter(e=>!!e),i=e.series.filter(e=>!t.includes(e.id));return{...e,series:[...r,...i]}})},async autoScaleSeries(e,t){l();let{ws:r}=P(e),i=r.panelChartSettings[e],a=i&&i.kind===`multiband`?i.series.find(e=>e.id===t):void 0;if(!a)return;let o=await de.columnBounds(a.column);!o||n||I(e,e=>e.kind===`multiband`?{...e,series:e.series.map(e=>e.id===t?{...e,scaleMin:o.min,scaleMax:o.max}:e)}:e)}},_e=new Map,ve={setXRange(e,t){l();let n=N(t).id;i.set(t=>{let r=t.xRanges[n]??null;return r===e||r&&e&&r[0]===e[0]&&r[1]===e[1]?t:{...t,xRanges:{...t.xRanges,[n]:e}}})},resetZoom(e){ve.setXRange(null,e)},setCursorX(e,t){l();let n=N(t).id;(_e.get(n)??null)!==e&&(_e.set(n,e),a.emit(`cursorchange`,{worksheetId:n,x:e}))},cursorX(e){return _e.get(N(e).id)??null},setLiveWindow(e,t){l();let n=N(t);n.liveWindowSeconds!==e&&F(n.id,t=>({...t,liveWindowSeconds:e}))},setSegmentContext(e){l(),i.set(t=>JSON.stringify(t.segmentContext)===JSON.stringify(e)?t:{...t,segmentContext:e})}},ye={save(e){l();let t=e.id??crypto.randomUUID(),[n]=LB([{...e,id:t,parentId:e.parentId??null}].concat(d().cycleRules.filter(e=>e.id!==t))).filter(e=>e.id===t);if(!n)throw new kE(`invalid_argument`,{reason:`not a valid cycle rule (or its parent is missing)`});return i.set(e=>({...e,cycleRules:e.cycleRules.some(e=>e.id===t)?e.cycleRules.map(e=>e.id===t?n:e):[...e.cycleRules,n]})),t},remove(e){l();let t=new Set([e]);for(let e=!0;e;){e=!1;for(let n of d().cycleRules)n.parentId&&t.has(n.parentId)&&!t.has(n.id)&&(t.add(n.id),e=!0)}i.set(e=>({...e,cycleRules:e.cycleRules.filter(e=>!t.has(e.id))}))}},be={create(e){l();let n=d(),r=n.limits.maxMathChannels;r!==null&&n.mathChannels.length>=r&&u(`math-channels`);let o=cr(e);return i.set(e=>({...e,mathChannels:[...e.mathChannels,o]})),Promise.resolve(t.mathChannels?.create(o)).catch(e=>a.emit(`error`,{error:e,context:`mathChannels.create`})),o},update(e,n){l();let r=d().mathChannels.find(t=>t.id===e);if(!r)throw new kE(`not_found`,{channelId:e});i.set(t=>({...t,mathChannels:t.mathChannels.map(t=>t.id===e?{...t,...n,updatedAt:Date.now()}:t)})),r.source!==`workbook`&&Promise.resolve(t.mathChannels?.update(e,n)).catch(e=>a.emit(`error`,{error:e,context:`mathChannels.update`}))},remove(e){l();let n=d().mathChannels.find(t=>t.id===e);if(!n)throw new kE(`not_found`,{channelId:e});i.set(t=>({...t,mathChannels:t.mathChannels.filter(t=>t.id!==e)})),n.source!==`workbook`&&Promise.resolve(t.mathChannels?.remove(e)).catch(e=>a.emit(`error`,{error:e,context:`mathChannels.remove`}))},async importFile(e){l();let{channels:n,errors:r}=await TE(e),a=d(),o=a.limits.maxMathChannels===null?n.length:Math.max(0,a.limits.maxMathChannels-a.mathChannels.length);n.length>0&&o===0&&u(`math-channels`);let s=n.slice(0,o);return i.set(e=>({...e,mathChannels:[...e.mathChannels,...s]})),await t.mathChannels?.importMany(s),{channels:s,errors:r}},async importMany(e){l();let n=d(),r=n.limits.maxMathChannels===null?e.length:Math.max(0,n.limits.maxMathChannels-n.mathChannels.length);e.length>0&&r===0&&u(`math-channels`);let a=e.slice(0,r);return i.set(e=>({...e,mathChannels:[...e.mathChannels,...a]})),await t.mathChannels?.importMany(a),a},exportBlob:()=>CE(d().mathChannels),preview(e,t){let n=m();return n.merged?rE(e,n.merged,N(t).xKey,n.channels.filter(t=>t.id!==e.id)):null},sync(e){l(),i.set(t=>{let n=t.mathChannels.filter(e=>e.source===`workbook`),r=n.length?[...e,...n]:e;return t.mathChannels===r?t:{...t,mathChannels:r}})}},xe=AQ((e,t)=>[...e.flatMap(e=>e.kind===`camera`&&e.video?[DE({...e,video:e.video})]:[]),...t]),Se=``;i.subscribe(()=>{let e=xe(d().live,d().video),t=e.map(e=>`${e.kind}:${e.id}:${e.recordingId??``}:${e.name}`).join(`|`);t!==Se&&(Se=t,a.emit(`videochange`,{sources:e}))});let Ce=(e,t,n)=>e.id===t&&(n===void 0||(e.recordingId??null)===n),we={sources:()=>xe(d().live,d().video),register(e){l(),i.set(t=>({...t,video:[...t.video.filter(t=>!Ce(t,e.id,e.recordingId??null)),e]}))},unregister(e,t){l(),i.set(n=>n.video.some(n=>Ce(n,e,t))?{...n,video:n.video.filter(n=>!Ce(n,e,t))}:n)}},Te={openLocal(e,t){return l(),z.openLocal(e,t)},async connect(e,t,n){l(),await z.connect(e,t,n)},startRecording(e){l(),z.startRecording(e)},stopRecording(e){return l(),z.stopRecording(e)},setSegmentAxis(e,t){l(),z.setSegmentAxis(e,t)},rowCount(e){return z.connections().find(t=>t.id===e)?.source.size()??0},disconnect(e){l(),z.disconnect(e),L(d().selection.filter(t=>t!==e))}},Ee=()=>{d().limits.canImportExportWorkspaces||u(`workspaces-io`)},De=async e=>{if(e instanceof Blob)try{return JSON.parse(await e.text())}catch{throw new kE(`bad_file`)}if(typeof e==`string`)try{return JSON.parse(e)}catch{throw new kE(`bad_file`)}return e},Oe=async e=>e instanceof File?e:new File([JSON.stringify(await De(e))],`import.json`,{type:`application/json`}),ke=e=>e.replace(/[^\w.-]+/g,`_`),Ae=e=>new Blob([JSON.stringify(e,null,2)],{type:`application/json`}),je=e=>{let t=rr(e.panelChartSettings,q$[2],4),n={};for(let r of e.panels)t[r.id]?.kind===r.kind&&(n[r.id]=t[r.id]);return{...e,panelChartSettings:ir(e.panels,n,q$[2],4)}},Me=(e,t)=>e.map(e=>{let n=e=>{let n=t.has(e)?crypto.randomUUID():e;return t.add(n),n},r=new Map(e.panels.map(e=>[e.id,n(e.id)])),i=e=>Object.fromEntries(Object.entries(e).map(([e,t])=>[r.get(e)??e,t]));return{...e,id:n(e.id),panels:e.panels.map(e=>({...e,id:r.get(e.id)})),panelChartSettings:i(e.panelChartSettings),panelChartBackgrounds:i(e.panelChartBackgrounds??{})}}),Ne=()=>new Set(d().worksheets.flatMap(e=>[e.id,...e.panels.map(e=>e.id)])),Pe=(e,t=0)=>{let n=d().limits.maxWorksheets,r=Me((n===null?e:e.slice(0,Math.max(1,n))).map(je),new Set),a=r[Math.min(t,r.length-1)];i.set(e=>({...e,worksheets:r,activeWorksheetId:a.id,xRanges:{}}))},Fe=(e,t)=>{let n=N(t),r=d().limits.maxChartsPerWorksheet;r!==null&&n.panels.length>=r&&u(`charts-per-worksheet`);let i=d().limits.maxChannelsPerChart;i!==null&&Cz(e.settings)>i&&u(`channels-per-chart`);let a=crypto.randomUUID(),o={id:a,kind:e.kind,rect:{x:0,y:0,w:6,h:24},...e.title?{title:e.title}:{}};return F(n.id,t=>({...t,panels:Qt([...t.panels,o]),panelChartSettings:{...t.panelChartSettings,[a]:e.settings},panelChartBackgrounds:e.background===null?t.panelChartBackgrounds:{...t.panelChartBackgrounds,[a]:e.background}})),a},Ie=()=>{let e=d();return cV({worksheets:e.worksheets,activeWorksheetId:e.activeWorksheetId,channels:te(p(e.mathChannels,e.limits.maxMathChannels),e.worksheets),liveWindowSeconds:e.liveWindowSeconds,laps:e.datasets.find(e=>e.beacon)?.beacon??null,segments:e.segmentContext,cycles:e.cycleRules})},Le=e=>{if(e.worksheets.length===0)throw new kE(`bad_workspace`,{errors:e.errors});let{channels:t,rename:n}=Y$(d().mathChannels,e.mathChannels);Pe(n.size?e.worksheets.map(e=>X$(e,n)):e.worksheets,e.activeIndex),i.set(n=>({...n,mathChannels:[...n.mathChannels.filter(e=>e.source!==`workbook`),...t],liveWindowSeconds:e.liveWindowSeconds===void 0?n.liveWindowSeconds:e.liveWindowSeconds,segmentContext:e.segments??null,cycleRules:e.cycles}));let r=e.laps;if(r)for(let e of d().datasets)e.kind!==`memory`||e.beacon||!e.data.columnNames.includes(r.channel)||de.configure(e.id,{beacon:r}).catch(e=>a.emit(`error`,{error:e,context:`io.openWorkbook`}));return{worksheets:e.worksheets.length,errors:e.errors}},Re=e=>{if(e===null)return;let t=m().numericColumns,n=t.length?e.worksheets.map(e=>$$(e,t)):e.worksheets;S=!0;try{i.set(t=>{let r=t=>e.worksheets.some(e=>e.id===t);return{...t,worksheets:n,activeWorksheetId:r(t.activeWorksheetId)?t.activeWorksheetId:r(e.activeWorksheetId)?e.activeWorksheetId:e.worksheets[0].id,xRanges:Object.fromEntries(Object.entries(t.xRanges).filter(([e])=>r(e))),mathChannels:[...t.mathChannels.filter(e=>e.source!==`workbook`),...e.channels],liveWindowSeconds:e.liveWindowSeconds}})}finally{S=!1}E=T(d()),x.rebase(D()),O()},Be={undo(){l(),Re(x.undo())},redo(){l(),Re(x.redo())},clear(){l(),A()}},Ve={hasWork:()=>yV(d().worksheets),exportWorksheet(e){l(),Ee();let t=N(e),n=lV(t);return{json:n,blob:Ae(n),filename:`${ke(t.name||`worksheet`)}.json`}},exportChart(e){l(),Ee();let{ws:t,panel:n}=P(e),r=uV(n,t.panelChartSettings[e],t.panelChartBackgrounds[e]??null);return{json:r,blob:Ae(r),filename:`${ke(n.title?.trim()||n.kind)}.json`}},parseFile:e=>SV(e),exportWorkspace(){l(),Ee();let e=Ie();return{json:e,blob:Ae(e),filename:`kymoscope-workspace-${new Date().toISOString().slice(0,10)}.json`}},async exportWorkspaceEncrypted(e){l(),Ee();let t=typeof e==`string`?await QB(Ie(),e):await $B(Ie(),e);return{json:t,blob:Ae(t),filename:`kymoscope-workbook-${new Date().toISOString().slice(0,10)}.kymo`}},async importWorkspace(e,t={}){l(),Ee();let n=await De(e);return eV(n)&&(n=await rV(n,t)),j(()=>Le(vV(n)))},toWorkbook:Ie,openWorkbook(e){return l(),j(()=>Le(vV(e)))},async importWorksheet(e){l(),Ee();let t=d();t.limits.maxWorksheets!==null&&t.worksheets.length>=t.limits.maxWorksheets&&u(`worksheets`);let n=await SV(await Oe(e));if(n.type!==`worksheet`)throw new kE(`bad_file`,{found:n.type});let[r]=Me([je(n.worksheet)],Ne());return i.set(e=>({...e,worksheets:[...e.worksheets,r],activeWorksheetId:r.id})),r.id},async importChart(e,t){l(),Ee();let n=await SV(await Oe(e));if(n.type!==`chart`)throw new kE(`bad_file`,{found:n.type});return Fe(n.chart,t)},snapshot(){let e=d();return{datasets:e.datasets,worksheets:e.worksheets,activeWorksheetId:e.activeWorksheetId,selection:e.selection}},restore(e){l();let t=new Set(e.datasets);for(let e of d().datasets)t.has(e)||e.source.dispose().catch(()=>void 0);let n=e.worksheets.length?e.worksheets.map(je):[J$()];j(()=>i.set(t=>({...t,datasets:e.datasets,worksheets:n,activeWorksheetId:n.some(t=>t.id===e.activeWorksheetId)?e.activeWorksheetId:n[0].id,selection:e.selection,xRanges:{},offsets:{},colors:{}})))},reset(){l(),j(()=>{oe(d().datasets.map(e=>e.id));let e=J$();i.set(t=>({...t,worksheets:[e],activeWorksheetId:e.id,xRanges:{},offsets:{},colors:{},mathChannels:t.mathChannels.filter(e=>e.source!==`workbook`)}))})}},He={merged(e){let t=m();if(!t.merged||t.channels.length===0)return t.merged;let n=xE(t.merged,t.channels,N(e).xKey);return{...t.merged,columnNames:[...t.merged.columnNames,...n.ok.map(e=>e.name)],units:[...t.merged.units,...n.ok.map(e=>e.units)],rows:n.rows}},plotted(){return m().merged}},Ue=typeof location<`u`?location.hostname:``,We=t.license,Ge=t.licenseKey,Ke=!1,Je={},Ye=e=>{n||i.set(t=>({...t,licensed:e}))},Xe=(e,t,n)=>{clearTimeout(Je[e]);let r=Math.max(0,t-Date.now()),i=r>2**31-1;Je[e]=setTimeout(()=>{i?Xe(e,t,n):n()},i?2**31-1:r)},Ze=e=>Xe(`renew`,e,()=>void $e()),Qe=e=>Xe(`expiry`,e*1e3+1e3,()=>{FV(Ge,Ue).then(e=>{n||Ye(e.ok)})});async function $e(){let e=36e5,t,r=null,i;try{t=await Promise.race([We.get(),new Promise((e,t)=>{i=setTimeout(()=>t(Error(`timeout`)),3e4)})]),r=await FV(t,Ue)}catch{}finally{clearTimeout(i)}if(n)return!1;if(r?.ok)return Ge=t,Ke=!0,Ye(!0),Qe(r.exp),Ze(Math.max(r.exp*1e3-168*e,Date.now()+e)),!0;console.warn(`[kymoscope] license renewal failed (${r?r.reason:`license.get failed or timed out`}): keeping the current key`);let a=await FV(Ge,Ue);return n?!1:(Ye(a.ok),Ze(Date.now()+e),a.ok)}let et=!We||t.licenseKey?FV(t.licenseKey,Ue).then(e=>(e.ok||console.warn(`[kymoscope] license ${e.reason}: showing attribution`),!Ke&&!n&&(Ye(e.ok),e.ok&&We&&Qe(e.exp)),e.ok)):null,tt=We?$e():et;S=!1,A();let nt={getState:M,subscribe(e){return i.subscribe(e)},on:a.on,licensed:tt,isLicensed:()=>d().licensed,setOptions(e){if(l(),t={...t,...e},e.live&&z.setRelay(e.live.relay),e.palette&&o(),e.limits){let t={...d().limits,...e.limits};i.set(e=>{let n=t.maxWorksheets===null?e.worksheets:e.worksheets.slice(0,Math.max(1,t.maxWorksheets)),r=n.some(t=>t.id===e.activeWorksheetId)?e.activeWorksheetId:n[0].id;return{...e,limits:t,activeWorksheetId:r}})}},datasets:de,folders:me,worksheets:he,charts:ge,view:ve,mathChannels:be,cycles:ye,live:Te,video:we,io:Ve,history:Be,data:He,alerts:{setRules:e=>{l();let t=ce.setRules(e);return i.set(e=>({...e,alertRules:ce.rules()})),t},rules:ce.rules,state:ce.state,evaluate:(e,t)=>(l(),ce.evaluate(e,t)),clearMarks:ce.clearMarks},marks:{list:()=>d().marks},dispose(){if(!n){n=!0,clearTimeout(Je.renew),clearTimeout(Je.expiry),s(),fQ(nt),UZ(nt),z.dispose();for(let e of d().datasets)e.source.dispose().catch(()=>void 0);a.emit(`dispose`,void 0),a.clear()}}};return r1.set(nt,{store:i,derived:m,live:z,alertLines:()=>le(d().alertRules,d().alerts)}),nt}var r1=new WeakMap;function i1(e){let t=r1.get(e);if(!t)throw new kE(`invalid_argument`,{reason:`not a Kymoscope engine`});return t}var a1=2e3,o1=3;function s1(e){let t=e[0].v.fragCount,n=new Map;for(let r of e)r.v.fragCount===t&&!n.has(r.v.fragIndex)&&n.set(r.v.fragIndex,r);let r=[];for(let e=0;e<t;e++){let t=n.get(e);if(!t)return null;r.push(t.v.payload)}let i=n.get(0),a=r[0];if(t>1){a=new Uint8Array(r.reduce((e,t)=>e+t.length,0));for(let e=0,n=0;e<t;e++)a.set(r[e],n),n+=r[e].length}return{t:i.v.t,seq:i.v.seq,key:i.v.key,data:a,arrivedAt:i.at}}function c1(e){let t=[],n=0;for(;n<e.length&&e[n].v.fragIndex>0&&e[n].v.seq===e[0].v.seq;)t.push(e[n++]);let r=[],i=[],a=[];for(;n<=e.length;n++){let t=e[n];if(a.length&&(!t||t.v.seq!==a[0].v.seq)){let e=s1(a);e?r.push(e):t||(i=a),a=[]}t&&a.push(t)}return{head:t,units:r,tail:i}}var l1=class{kind=`recorded`;id;name;parentId;parentName;recordingId;chunks;fetch;open;maxBytes;cache=new Map;sizes=new Map;bytes=0;width=0;height=0;codec=``;waiting=null;constructor(e){this.id=e.id,this.name=e.name,this.parentId=e.parentId,this.parentName=e.parentName??null,this.recordingId=e.recordingId,this.chunks=[...e.chunks].sort((e,t)=>e.seq-t.seq),this.fetch=e.fetchChunk,this.open=e.open,this.maxBytes=e.maxBytes??256*1024*1024}async parse(e){let t=new Uint8Array(await this.fetch(this.chunks[e].seq)),n=[];for(let e of ae(t).messages){let t=null;try{t=await ye(this.open,e.bytes.slice().buffer)}catch{}if(t?.kind!==6)continue;let r=YQ(t.plaintext);r&&(r.key&&r.fragIndex===0&&!this.codec&&(this.codec=r.codec,this.width=r.width,this.height=r.height),n.push({v:r,at:e.at}))}let r=c1(n),i=e=>e.reduce((e,t)=>e+t.v.payload.length,0);return{...r,bytes:r.units.reduce((e,t)=>e+t.data.length,0)+i(r.head)+i(r.tail)}}parsed(e){let t=this.cache.get(e);if(t)return this.cache.delete(e),this.cache.set(e,t),t;let n=this.parse(e);return this.cache.set(e,n),n.then(t=>{this.cache.get(e)===n&&(this.sizes.set(e,[t.bytes,t.units.length]),this.bytes+=t.bytes,this.evict(e))},()=>{this.cache.get(e)===n&&this.cache.delete(e)}),n}evict(e){for(let t of this.cache.keys()){if(this.bytes<=this.maxBytes)return;let n=this.sizes.get(t);t===e||!n||(this.bytes-=n[0],this.sizes.delete(t),this.cache.delete(t))}}async units(e){let t;try{t=await this.parsed(e)}catch{return[]}if(t.full)return t.full;if(!t.tail.length||e+1>=this.chunks.length)return t.full=t.units;let n=await this.parsed(e+1).catch(()=>null);if(!n)return t.units;let r=null;try{r=s1([...t.tail,...n.head.filter(e=>e.v.seq===t.tail[0].v.seq)])}catch{}return t.full=r?[...t.units,r]:t.units}async seekPlan(e){let t=this.chunks.length;if(!t)return[];let n=e*1e3,r=0;for(;r+1<t&&this.chunks[r+1].t0<=n;)r++;let i=r,a=r+1<t&&this.chunks[r+1].t0-n<a1?r+1:r,o=(await Promise.all(Array.from({length:a-i+1},(e,t)=>this.units(i+t)))).flat(),s=()=>{let t=o.length-1;for(;t>=0&&o[t].t>e;)t--;let n=t;for(;n>=0&&!o[n].key;)n--;return[n,t]},[c,l]=s();for(let e=0;c<0&&i>0&&e<o1;e++)o=[...await this.units(--i),...o],[c,l]=s();return a+1<t&&this.units(a+1),c<0?[]:o.slice(c,l+1)}ready(){return this.waiting??=(async()=>{for(let e=0;e<Math.min(this.chunks.length,o1+1)&&!this.codec;e++)await this.units(e);this.codec||(this.waiting=null)})()}info(){let e=0;for(let[,t]of this.sizes.values())e+=t;return{width:this.width,height:this.height,codec:this.codec,latestT:this.range()?.[1]??null,lagMs:null,units:e,bytes:this.bytes}}range(){let e=this.chunks.length;return e?[this.chunks[0].t0/1e3,this.chunks[e-1].t1/1e3]:null}},u1=1e4,d1=72e4,f1=3e5,p1=3e4,m1=1e4,h1=1e4,g1=64*1024,_1=50,v1=class extends Error{status;code;detail;constructor(e,t,n){super(`${n} (${t})`),this.status=e,this.code=t,this.detail=n}},y1=e=>Uint8Array.from(atob(e),e=>e.charCodeAt(0)),b1=class{opts;deps;auth;secret;password;token=``;ticket=``;ticketRec=!1;authRec=!1;relayUrl=null;apiKeyId=null;projectId=null;e2ee=!1;sid=null;salt=``;key=null;raw=null;epoch=0;haveKey=!1;sealed=null;device=null;senderDeviceId=null;deviceRetried=!1;maxBytesPerSec=0;maxMessageBytes=g1;ws=null;open=!1;everOpen=!1;connectedAt=0;authAt=0;delay=1e3;lastToken=0;viewerCount=0;busy=!1;stopped=!1;refusal=null;heartbeatTimer=null;pingTimer=null;retryTimer=null;statusFns=new Set;viewerFns=new Set;lastStatus=``;constructor(e,t){let{auth:n,secret:r}=ue(e.apiKey);if(!r)throw Error(`This API key has no encryption secret (created before keys carried one). Create a new API key in Kymoscope.`);if(e.kind===`camera`&&!e.parentStreamId)throw Error(`A camera is added to one of your live streams: choose its stream (parentStreamId).`);if(!!e.layer!=!!e.lowOf)throw Error(`A low layer needs both layer: 'low' and lowOf (its high camera's stream id).`);if(e.layer&&e.kind!==`camera`)throw Error(`Only a camera has a low layer.`);if(e.visibility===`open`&&e.password)throw Error(`An open stream has no password: anyone may watch it. Remove the password, or use visibility 'private'.`);this.opts=e,this.deps=t,this.auth=n,this.secret=r,this.password=e.visibility===`open`?Ce:e.password||r}get streamId(){return this.sid}get viewers(){return this.viewerCount}get limits(){return{maxBytesPerSec:this.maxBytesPerSec,maxMessageBytes:this.maxMessageBytes}}onStatus(e){return this.statusFns.add(e),()=>{this.statusFns.delete(e)}}onViewers(e){return this.viewerFns.add(e),()=>{this.viewerFns.delete(e)}}async start(){this.emit();try{let e=await this.deps.store.load();this.salt=e?.salt??L();let t=await this.mint();this.token=t.token,this.relayUrl=t.relayUrl??null,this.maxBytesPerSec=t.maxBytesPerSec||0,this.maxMessageBytes=t.maxMessageBytes||g1,this.apiKeyId=t.apiKeyId??null;let n=t.project;this.e2ee=!!n?.e2ee;let r={};if(this.e2ee){this.projectId=n?.id??null;let t=e?.apiKeyId===this.apiKeyId;this.device=t&&e?.device||await Qe(),t&&e?.streamKey?{key:this.key,epoch:this.epoch,sealed:this.sealed}=e.streamKey:this.key=await z(O()),r.sender_device=await this.senderDevice()}else this.raw=y1(await _(this.password,this.salt)),this.key=await z(this.raw);let i=await this.register(e?.streamId??null,r);if(this.sid=i.stream.id,this.ticket=i.ticket,this.ticketRec=!!i.recording,this.e2ee?(this.senderDeviceId=i.sender_device_id??null,this.projectId=i.project?.id??this.projectId,await this.save(),await this.applyProject(i.project)):(await this.save(),await this.wrapFor(i.devices)),!this.relayUrl)throw Error(`stream-token returned no relayUrl`)}catch(e){throw e instanceof v1&&e.status>=400&&e.status<500&&this.refuse(e),e}this.stopped||(this.lastToken=this.deps.now(),this.connect(),this.heartbeatTimer=setInterval(()=>{this.housekeeping()},u1),this.emit())}async send(e,t){let n=this.key,r=this.e2ee?this.epoch&255:void 0;if(this.stopped||!this.open||!n||this.e2ee&&!this.haveKey)return!1;let i=await _e(n,e,t,r),a=this.ws;if(!this.open||!a)return!1;try{return a.send(i),!0}catch{return!1}}stop(){this.stopped=!0,this.heartbeatTimer&&clearInterval(this.heartbeatTimer),this.retryTimer&&clearTimeout(this.retryTimer),this.heartbeatTimer=this.retryTimer=null;let e=this.ws;if(this.disconnect(),e){e.onopen=e.onmessage=e.onclose=null;try{e.close(1e3)}catch{}}}async post(e,t,n){let r;try{r=await this.deps.fetch(`${this.opts.supabaseUrl.replace(/\/+$/,``)}/functions/v1/${e}`,{method:`POST`,headers:t,body:n===void 0?void 0:JSON.stringify(n)})}catch(e){throw new v1(0,`network`,e?.message??String(e))}let i=await r.text(),a=null;try{a=JSON.parse(i)}catch{}if(r.status!==200)throw new v1(r.status,a?.error??`error`,a?.message??a?.error??i);return a}mint(){return this.post(`stream-token`,{"x-api-key":this.auth})}call(e){return this.post(`stream-publisher`,{Authorization:`Bearer ${this.token}`,"Content-Type":`application/json`},e)}async register(e,t){let n={action:`register`,name:this.opts.name,salt:this.salt,key_check:await p(this.key),visibility:this.opts.visibility??`private`,kind:this.opts.kind,...t};return this.opts.kind===`camera`&&(n.parent_stream_id=this.opts.parentStreamId),this.opts.layer&&(n.layer=this.opts.layer,n.low_of=this.opts.lowOf),e&&(n.stream_id=e),this.call(n)}async senderDevice(){let e=this.device.publicKey;return{public_key:e,binding:await He(await Fe(this.secret),this.apiKeyId??``,e)}}async housekeeping(){if(!(this.busy||this.stopped)){this.busy=!0;try{let e=this.deps.now();if(e-this.lastToken>=d1){this.lastToken=e;try{this.token=(await this.mint()).token}catch{return}}if(this.e2ee){let e=await this.call({action:`heartbeat`,stream_id:this.sid,sender_device_id:this.senderDeviceId,epoch:this.haveKey?this.epoch:0});this.setTicket(e.ticket,!!e.recording),await this.applyProject(e.project)}else{let e=await this.call({action:`heartbeat`,stream_id:this.sid});this.setTicket(e.ticket,!!e.recording),await this.wrapFor(e.devices)}}catch(e){e instanceof v1&&(e.status===401||e.status===403)&&this.refuse(e)}finally{this.busy=!1}}}async wrapFor(e){let t=[];for(let n of e??[])try{t.push({device_id:n.id,wrapped:await ve(n.public_key,this.raw,`${this.sid}|${n.id}`)})}catch{}if(t.length)try{await this.call({action:`wrap_keys`,stream_id:this.sid,keys:t.slice(0,_1)})}catch{}}async applyProject(e){if(!this.e2ee||!e)return;let t=e.key;if(!t){this.emit();return}let n=Number(t.epoch);if(this.haveKey&&n<=this.epoch)return;let r;try{r=await Ke(this.device.privateKey,t.wrapped,ne(this.projectId,n,this.senderDeviceId))}catch{if(this.deviceRetried)return;this.deviceRetried=!0,this.device=await Qe(),await this.reregister();return}let i=Oe(this.sid,this.projectId,n),a=this.key,o=n===this.epoch?this.sealed:null;if(o)try{await b(r,o,i)}catch{o=null}if(!o){let e=O();a=await z(e),o=await Ve(r,e,i),e.fill(0)}try{await this.call({action:`wrap_keys`,stream_id:this.sid,sender_device_id:this.senderDeviceId,project_wrap:{epoch:n,iv:o.iv,ct:o.ct}})}catch{return}this.stopped||(this.key=a,this.sealed=o,this.epoch=n,this.haveKey=!0,await this.save(),this.emit())}async reregister(){let e;try{e=await this.register(this.sid,{sender_device:await this.senderDevice()})}catch{return}this.ticket=e.ticket,this.ticketRec=!!e.recording,this.senderDeviceId=e.sender_device_id??null;let t=e.stream.id;if(t!==this.sid){this.sid=t;let e=this.ws;if(e){this.disconnect(),e.onopen=e.onmessage=e.onclose=null;try{e.close(1e3)}catch{}this.connect()}}await this.save(),await this.applyProject(e.project),this.deviceRetried=!1}async save(){try{await this.deps.store.save({apiKeyId:this.apiKeyId,streamId:this.sid,salt:this.salt,device:this.e2ee?this.device:null,streamKey:this.e2ee&&this.haveKey?{epoch:this.epoch,key:this.key,sealed:this.sealed}:null})}catch{}}connect(){if(this.retryTimer=null,this.stopped)return;let e=this.relayUrl.replace(/\/+$/,``).replace(/^http(s?):\/\//,`ws$1://`),t;try{t=new this.deps.WebSocket(`${e}/v1/streams/${this.sid}/publish`,[FQ,`bearer.${this.ticket}`])}catch{this.dropped();return}t.binaryType=`arraybuffer`,this.ws=t,t.onopen=()=>{t===this.ws&&(this.open=this.everOpen=!0,this.connectedAt=this.authAt=this.deps.now(),this.authRec=this.ticketRec,this.pingTimer=setInterval(()=>{try{t.send(`ping`)}catch{}},p1),this.emit())},t.onmessage=e=>{if(!(t!==this.ws||typeof e.data!=`string`||!e.data.startsWith(`{`)))try{let t=JSON.parse(e.data);t?.type===`viewers`&&this.setViewers(Number(t.count)||0)}catch{}},t.onclose=()=>{t===this.ws&&this.dropped()}}disconnect(){this.ws=null,this.open=!1,this.pingTimer&&clearInterval(this.pingTimer),this.pingTimer=null,this.setViewers(0)}dropped(){let e=this.open&&this.deps.now()-this.connectedAt>=h1;if(this.disconnect(),this.stopped)return;let t=0;e?this.delay=1e3:(t=this.delay,this.delay=Math.min(this.delay*2,m1)),this.retryTimer=setTimeout(()=>this.connect(),t),this.emit()}setTicket(e,t){this.ticket=e,this.ticketRec=t;let n=this.deps.now();if(t||(this.authRec=!1),!(!this.open||!this.ws)&&!(n-this.authAt<f1&&!(t&&!this.authRec)))try{this.ws.send(JSON.stringify({type:`auth`,token:e})),this.authAt=n,this.authRec=t}catch{}}setViewers(e){if(e!==this.viewerCount){this.viewerCount=e;for(let t of this.viewerFns)t(e);this.emit()}}refuse(e){this.refusal={code:e.code,message:e.detail},this.emit(),this.stop()}status(){return this.refusal?{phase:`refused`,...this.refusal}:this.sid?this.e2ee&&!this.haveKey?{phase:`waiting_approval`}:this.open?{phase:`live`,viewers:this.viewerCount}:this.everOpen?{phase:`reconnecting`}:{phase:`registering`}:{phase:`registering`}}emit(){let e=this.status(),t=JSON.stringify(e);if(t!==this.lastStatus){this.lastStatus=t;for(let t of this.statusFns)t(e)}}},x1={"720p30":{width:1280,height:720,fps:30,kbps:2e3},"1080p30":{width:1920,height:1080,fps:30,kbps:4e3}},S1={width:640,height:360,fps:15,kbps:400},C1=[`avc1.640028`,`avc1.4d0028`,`avc1.42e028`],w1=[`avc1.64001f`,`avc1.4d001f`,`avc1.42e01f`],T1=2,E1=1e3,D1=1e3;async function*O1(e){if(typeof MediaStreamTrackProcessor<`u`){let t=new MediaStreamTrackProcessor({track:e}).readable.getReader();try{for(;;){let{value:e,done:n}=await t.read();if(n)return;yield e}}finally{t.cancel().catch(()=>{})}}let t=document.createElement(`video`);t.muted=!0,t.playsInline=!0,t.srcObject=new MediaStream([e]),await t.play();try{for(;e.readyState===`live`;)await new Promise(e=>t.requestVideoFrameCallback(()=>e())),yield new VideoFrame(t,{timestamp:Math.round(performance.now()*1e3)})}finally{t.pause(),t.srcObject=null}}function k1(){let e=null;return(t,n,r)=>(e??=new OffscreenCanvas(n,r).getContext(`2d`),e.drawImage(t,0,0,n,r),new VideoFrame(e.canvas,{timestamp:t.timestamp}))}var A1=class{encoder=null;codec=``;error=null;unsubscribe=null;lastKey=-1/0;keyPending=!1;resume=!0;lastViewers=0;encoding=!1;dropped=0;seq=0;times=new Map;window=[];sending=Promise.resolve();publisher;preset;keyframeMs;Encoder;now;constructor(e,t,n,r,i){this.publisher=e,this.preset=t,this.keyframeMs=n,this.Encoder=r,this.now=i}async configure(){let{width:e,height:t,fps:n,kbps:r}=this.preset,i=this.publisher.limits.maxBytesPerSec,a=i>0?Math.min(r*1e3,i*8/1.25):r*1e3,o=null;for(let r of t>720?C1:w1){let i={codec:r,width:e,height:t,bitrate:a,framerate:n,avc:{format:`annexb`},latencyMode:`realtime`,bitrateMode:`constant`};if((await this.Encoder.isConfigSupported(i)).supported===!0){o=i;break}}return o?(this.codec=o.codec,this.encoder=new this.Encoder({output:e=>this.onChunk(e),error:e=>{this.error=e.message||String(e),this.closeEncoder()}}),this.encoder.configure(o),this.lastViewers=this.publisher.viewers,this.unsubscribe=this.publisher.onViewers(e=>{e>this.lastViewers&&(this.keyPending=!0),this.lastViewers=e}),!0):!1}ready(){let e=this.encoder;return this.encoding=!!e&&!this.error&&this.publisher.viewers>0,!e||!this.encoding?(this.resume=!0,!1):e.encodeQueueSize>T1?(this.dropped++,!1):!0}encode(e){let t=this.now(),n=t-this.lastKey,r=this.resume||n>=this.keyframeMs||this.keyPending&&n>=E1;r&&(this.lastKey=t,this.keyPending=this.resume=!1);let i=(performance.timeOrigin+e.timestamp/1e3)/1e3;Math.abs(i-Date.now()/1e3)>60&&(i=Date.now()/1e3),this.times.set(e.timestamp,i),this.encoder.encode(e,{keyFrame:r})}onChunk(e){let t=new Uint8Array(e.byteLength);e.copyTo(t);let n=this.times.get(e.timestamp)??Date.now()/1e3;this.times.delete(e.timestamp);let{width:r,height:i}=this.preset,a=XQ({key:e.type===`key`,t:n,seq:this.seq++,width:r,height:i,codec:this.codec,data:t});for(let e of a)this.sending=this.sending.then(()=>this.publisher.send(6,e)).catch(()=>!1);this.window.push({at:this.now(),bytes:t.length})}get queue(){return this.encoder?.state===`configured`?this.encoder.encodeQueueSize:0}stats(){let e=this.now();for(;this.window.length&&e-this.window[0].at>=D1;)this.window.shift();let t=this.window.reduce((e,t)=>e+t.bytes,0);return{fps:this.window.length,kbps:t*8/1e3,viewers:this.publisher.viewers,encoding:this.encoding}}stop(){this.encoding=!1,this.closeEncoder(),this.unsubscribe?.(),this.unsubscribe=null}closeEncoder(){this.encoder&&this.encoder.state!==`closed`&&this.encoder.close()}},j1=class{high;lowOpt;low=null;lowAt=-1/0;keyframeMs;Encoder;now;frames;scale;stopped=!1;statsFns=new Set;lastStats=-1/0;constructor(e,t,n={}){this.keyframeMs=(t.keyframeS??2)*1e3,this.Encoder=n.VideoEncoder??VideoEncoder,this.now=n.now??Date.now,this.frames=n.frames??O1,this.scale=n.scale??k1(),this.high=new A1(e,t.preset,this.keyframeMs,this.Encoder,this.now),this.lowOpt=t.low?{publisher:t.low.publisher,preset:t.low.preset??S1}:null}async start(e){if(!await this.high.configure())throw new kE(`camera_codec_unsupported`);if(this.lowOpt){let e=new A1(this.lowOpt.publisher,this.lowOpt.preset,this.keyframeMs,this.Encoder,this.now);await e.configure()&&(this.low=e)}this.loop(e)}async loop(e){for await(let t of this.frames(e)){if(this.stopped){t.close();break}try{this.onFrame(t)}finally{t.close()}this.emitStats()}}onFrame(e){this.high.ready()&&this.high.encode(e);let t=this.low;if(!t)return;let n=this.now();if(n-this.lowAt<750/t.preset.fps||!t.ready())return;this.lowAt=n;let r=this.scale(e,t.preset.width,t.preset.height);try{t.encode(r)}finally{r.close()}}stats(){return{...this.high.stats(),dropped:this.high.dropped,queue:this.high.queue,error:this.high.error,low:this.low?this.low.stats():null}}onStats(e){return this.statsFns.add(e),()=>{this.statsFns.delete(e)}}emitStats(){let e=this.now();if(e-this.lastStats<D1||!this.statsFns.size)return;this.lastStats=e;let t=this.stats();for(let e of this.statsFns)e(t)}stop(){this.stopped=!0,this.high.stop(),this.low?.stop()}},M1=class{#e;constructor(e){this.#e=e}head(){let e=this.#e;return`${e.map(e=>r$(e.name)).join(`,`)}\n${e.map(e=>r$(e.unit)).join(`,`)}\n`}append(e){let t=e.columns,n=``;for(let r=0;r<e.length;r++){for(let e=0;e<t.length;e++){let i=t[e][r];n+=(e?`,`:``)+(Number.isNaN(i)?``:String(i))}n+=`
617
+ `}n.push(i)}return n}};function r$(e){let t=/^[=+\-@\t\r]/.test(e)?`'${e}`:e;return/[",\n\r]/.test(t)?`"${t.replace(/"/g,`""`)}"`:t}var i$=512,a$=new WeakMap;function o$(e,t,n){let r=a$.get(e);r||a$.set(e,r=new Map);let i=r.get(t),a={start:n,values:[]};return{carry:{start:e=>{let t=i?.values[e];if(!i||!t)return 0;for(let e=Math.min(n-i.start,t.length-1);e>=0;e--){let n=t[e];if(n!==null&&Number.isFinite(n))return n}return 0},done:(e,t)=>{a.values[e]=t}},keep:()=>{r.set(t,a)}}}function s$(e,t,n){let r=e.endAbs,i=Math.max(n,e.firstAbs);if(i>=r||t.length===0)return;let a=new Set(e.columnNames);for(let n of t){if(!n.enabled)continue;let o=eE(n.formula);if(!o.ok)continue;let{identifiers:s,functions:c}=tE(o.node);if(!s.every(e=>a.has(e)))continue;let l=c.some(e=>QT.includes(e)),u=Math.max(e.firstAbs,i-(l?i$:0)),d=new Map([qe,...s].map(t=>[t,e.range(t,u,r)])),{carry:f,keep:p}=o$(e,`${n.id}|${n.formula}`,u),m=sE(n,e=>d.get(e),qe,r-u,t,f);m.status===`ok`&&(e.writeComputed(n.name,n.units,i,m.values.subarray(i-u)),p())}}function c$(e,t){e.clearComputed(),a$.delete(e),s$(e,t,e.firstAbs)}var l$=8e3,u$=131072;function d$(e,t={}){switch(e.kind){case`elapsed`:return{name:`Elapsed`,unit:`s`};case`event`:return{name:`Since ${e.channel} ${e.op} ${e.value}`,unit:`s`};case`clock`:return{name:`Time of day`,unit:`s`};default:{let n=t[e.channel]??``;return e.integral?{name:`∫${e.channel}`,unit:n?`${n}·s`:`s`}:{name:`${e.channel} since start`,unit:n}}}}var f$=new Map;function p$(e,t){let n=`${t}|${Math.floor(e/900)}`,r=f$.get(n);r===void 0&&(r=dB(e,t),f$.size>1e4&&f$.clear(),f$.set(n,r));let i=(e+r)%86400;return i<0?i+86400:i}var m$=class{axis;#e=NaN;#t=NaN;#n=NaN;#r=0;#i=NaN;#a=NaN;constructor(e){this.axis=e}begin(e){this.#e=e,this.#t=NaN,this.#n=NaN,this.#r=0,this.#i=NaN,this.#a=NaN}x(e,t){let n=this.axis;return n.kind===`clock`?p$(e,n.tz):n.kind===`elapsed`?e-this.#e:e<this.#e?NaN:n.kind===`event`?(this.#t!==this.#t&&t===t&&aB(n.op,t,n.value)&&(this.#t=e),e-this.#t):n.integral?(t===t&&(this.#i===this.#i&&(this.#r+=(t+this.#i)/2*(e-this.#a)),this.#i=t,this.#a=e),this.#i===this.#i?this.#r:NaN):(t===t&&(this.#n!==this.#n&&(this.#n=t),this.#i=t),this.#i===this.#i?this.#i-this.#n:NaN)}};function h$(e,t,n,r){let i=`channel`in r?t.get(r.channel):void 0;if(r.kind===`event`){let a=NaN;for(let t=0;t<e.length&&a!==a;t++){let o=i?i[t]:NaN;e[t]>=n&&o===o&&aB(r.op,o,r.value)&&(a=e[t])}return{x:e.map(e=>e-a),t:e,cols:t}}let a=new m$(r);a.begin(n);let o=new Float64Array(e.length);for(let t=0;t<e.length;t++)o[t]=a.x(e[t],i?i[t]:NaN);return{x:o,t:e,cols:t}}function g$(e,t,n){let r=[];for(let n=0;n<e.length;n++)e[n]===e[n]&&t[n]===t[n]&&r.push(n);let i=!0;for(let t=1;t<r.length&&i;t++)i=e[r[t-1]]<=e[r[t]];i||r.sort((t,n)=>e[t]-e[n]);let a=r.length,o=new Float64Array(n.length).fill(NaN);if(a<2)return o;let s=Float64Array.from(r,t=>e[t]),c=Float64Array.from(r,e=>t[e]),l=Float64Array.from({length:a-1},(e,t)=>s[t+1]-s[t]).sort(),u=l[l.length>>1],d=u>0?4*u:1/0,f=0;for(let e=0;e<n.length;e++){let t=n[e];if(!(t>=s[0]&&t<=s[a-1]))continue;for(;f<a-2&&s[f+1]<t;)f++;let r=s[f],i=s[f+1];i-r>d||(o[e]=i===r?c[f]:c[f]+(c[f+1]-c[f])*(t-r)/(i-r))}return o}function _$(e,t,n){let r=e.length;if(r===0||!(n>=e[0]&&n<=e[r-1]))return NaN;if(r===1)return t[0];let i=(n-e[0])/(e[r-1]-e[0])*(r-1),a=Math.min(r-2,Math.floor(i));return t[a]+(t[a+1]-t[a])*(i-a)}function v$(e,t,n){let r=Math.max(2,Math.min(l$,Math.floor(n)));if(r*t.length>131072)throw Error(`too_many_cells`);let i=1/0,a=-1/0;for(let t of e)for(let e of t.x)e===e&&(e<i&&(i=e),e>a&&(a=e));if(!(a>i))throw Error(`empty`);let o=Float64Array.from({length:r},(e,t)=>i+t*(a-i)/(r-1)),s=new Map;for(let n of t){let t=new Uint16Array(r),i=new Float64Array(r),a=new Float64Array(r),c=new Float32Array(r).fill(1/0),l=new Float32Array(r).fill(-1/0);for(let s of e){let e=s.cols.get(n);if(!e)continue;let u=g$(s.x,e,o);for(let e=0;e<r;e++){let n=u[e];if(n!==n)continue;let r=++t[e],o=n-i[e];i[e]+=o/r,a[e]+=o*(n-i[e]),n<c[e]&&(c[e]=n),n>l[e]&&(l[e]=n)}}let u={mean:new Float32Array(r),sd:new Float32Array(r),min:c,max:l,n:t};for(let e=0;e<r;e++){if(t[e]===0){u.mean[e]=u.sd[e]=u.min[e]=u.max[e]=NaN;continue}u.mean[e]=i[e],u.sd[e]=t[e]>1?Math.sqrt(a[e]/(t[e]-1)):0}s.set(n,u)}return{x:o,channels:s}}function y$(e,t){if(e.unit===`abs`)return e.tolerance;let n=1/0,r=-1/0;for(let e of t.mean)e===e&&(e<n&&(n=e),e>r&&(r=e));return r>=n?Math.max(r-n,Math.abs(r),Math.abs(n))*e.tolerance/100:0}var b$=new WeakMap;function x$(e){let t=b$.get(e);if(t)return t;let n=e.sd.length,r=Math.max(2,Math.round(n/100));t=new Float32Array(n).fill(NaN);for(let i=0;i<n;i++){if(e.n[i]<2)continue;let a=0,o=0;for(let t=Math.max(0,i-r);t<=Math.min(n-1,i+r);t++)e.n[t]>=2&&e.sd[t]===e.sd[t]&&(a+=e.sd[t]**2,o++);t[i]=o?Math.sqrt(a/o):NaN}return b$.set(e,t),t}function S$(e,t,n){if(n===`minmax`)return{lo:e.min,hi:e.max};if(n===`sigma`){let n=x$(e);return{lo:e.mean.map((e,r)=>e-t*n[r]),hi:e.mean.map((e,r)=>e+t*n[r])}}let r=y$(n,e);return{lo:e.mean.map(e=>e-r),hi:e.mean.map(e=>e+r)}}function C$(e,t,n,r=`sigma`,i=0){let a=typeof r==`function`?r:()=>({band:r,k:n}),o=[...t.channels.keys()],s=new Map,c=new Map,l=[],u=new Uint8Array(e.t.length),d=o.map(()=>new Uint8Array(e.t.length)),f=t.x.length;o.forEach((n,r)=>{let i=t.channels.get(n),o=e.cols.get(n);if(!o)return;let{band:p,k:m}=a(n),h=typeof p==`object`?p:null,{lo:g,hi:_}=S$(i,m,p),v=0,y=0,b=0;for(let e of i.mean)if(e===e){v++;let t=e-y;y+=t/v,b+=t*(e-y)}let x=v>1?Math.max(Math.sqrt(b/(v-1)),1e-9):1e-9,S=h?Math.max(y$(h,i),1e-9):0,C=x$(i),w=new Float64Array(e.t.length).fill(NaN),T=new Float64Array(e.t.length).fill(NaN),E=0,D=0;for(let n=0;n<e.t.length;n++){let a=o[n],s=e.x[n];if(a!==a||s!==s)continue;let c=_$(t.x,i.mean,s);if(c!==c)continue;w[n]=a-c;let l=Math.round((s-t.x[0])/(t.x[f-1]-t.x[0])*(f-1));T[n]=Math.abs(a-c)/(h?S:i.n[l]>=2&&C[l]===C[l]?Math.max(C[l],1e-9):x),E+=T[n],D++,(h||i.n[l]>=2)&&(a<_$(t.x,g,s)||a>_$(t.x,_,s))&&(u[n]=1,d[r][n]=1)}s.set(n,w),c.set(n,T),l.push({channel:n,z:D?E/D:0})}),l.sort((e,t)=>t.z-e.z);let p=[];for(let t=0;t<u.length;t++){if(!u[t])continue;let n=t;for(;n<u.length&&u[n];)n++;let r=p[p.length-1];r&&e.t[t]-e.t[Math.min(r[1],u.length-1)]<i?r[1]=n:p.push([t,n]),t=n}let m=[];for(let[t,n]of p){let r=e.t[t],a=e.t[Math.min(n,u.length-1)];a-r>=i&&m.push({t0:r,t1:a,channels:o.filter((e,r)=>d[r].subarray(t,n).includes(1))})}return{delta:s,score:l,deviations:m,z:c}}function w$(e,t){let n=e.x.length,r=t.length,i=new DataView(new ArrayBuffer(12+8*n+r*n*18));[75,82,66,49].forEach((e,t)=>i.setUint8(t,e)),i.setUint32(4,n,!0),i.setUint32(8,r,!0);let a=12;for(let t=0;t<n;t++,a+=8)i.setFloat64(a,e.x[t],!0);for(let r of t){let t=e.channels.get(r);if(!t)throw Error(`The reference has no channel ${r}`);for(let e of[t.mean,t.sd,t.min,t.max])for(let t=0;t<n;t++,a+=4)i.setFloat32(a,e[t],!0);for(let e=0;e<n;e++,a+=2)i.setUint16(a,t.n[e],!0)}return De(new Uint8Array(i.buffer))}function T$(e,t){let n=le(e),r=new DataView(n.buffer,n.byteOffset,n.byteLength);if(n.length<12||String.fromCharCode(n[0],n[1],n[2],n[3])!==`KRB1`)throw Error(`Not a reference band`);let i=r.getUint32(4,!0),a=r.getUint32(8,!0);if(a!==t.length||n.length!==12+8*i+a*i*18)throw Error(`This reference band does not match its channels`);let o=12,s=new Float64Array(i);for(let e=0;e<i;e++,o+=8)s[e]=r.getFloat64(o,!0);let c=new Map;for(let e of t){let t=()=>{let e=new Float32Array(i);for(let t=0;t<i;t++,o+=4)e[t]=r.getFloat32(o,!0);return e},n=t(),a=t(),s=t(),l=t(),u=new Uint16Array(i);for(let e=0;e<i;e++,o+=2)u[e]=r.getUint16(o,!0);c.set(e,{mean:n,sd:a,min:s,max:l,n:u})}return{x:s,channels:c}}var E$=` Δ`,D$=class{#e;constructor(e){this.#e=new jB(e)}assumeOpen(e){}feed(e,t,n){let r=[];for(let i=0;i<e.length;i++)this.#e.step(e[i],e=>{let n=t(e);return n?n[i]:NaN},r),n?.(i,this.#e.open()?.tstart??null);return r.map(e=>({tstart:e.tstart,tend:e.tend,kpis:{duration:(e.tend??e.tstart)-e.tstart},...e.flags.length?{flags:e.flags}:{}}))}};function O$(e){if(!e.cycle&&!e.rule)throw Error(`a live segment axis needs a rule or a cycle rule`);let t=e.cycle?new D$(e.cycle):new gB(e.rule,e.kpis??[]),n=new m$(e.axis),r=NaN;e.start!=null&&(t.assumeOpen(e.start),n.begin(e.start),r=e.start);let i=e.reference??null,a=i?[...i.channels]:[],o=i?i.grid.length:0,s=`channel`in e.axis?e.axis.channel:null,c=[...new Set([...e.cycle?AB(e.cycle):iB(e.rule),...(e.kpis??[]).map(e=>e.channel),...s?[s]:[],...a.map(([e])=>e)])],l=e.minDeviationS??5,u=NaN,d=NaN,f=NaN,p=new Set,m=!1,h=e=>{m&&e({type:`deviation-end`,t0:u,t1:d,channels:[...p]}),u=d=f=NaN,p=new Set,m=!1};return{feed(g,_,v=!1){let y=Math.max(_,g.firstAbs),b=g.endAbs;if(y>=b)return;let x=t=>{v||e.onEvent?.(t)},S=g.range(qe,y,b),C=new Map(c.map(e=>[e,g.range(e,y,b)])),w=new Float64Array(S.length).fill(NaN),T=a.map(([e,t])=>({name:e,b:t,v:C.get(e),d:new Float64Array(S.length).fill(NaN)})),E=s?C.get(s):null,D=t.feed(S,e=>C.get(e),(e,t)=>{if(t===null)return;t!==r&&(h(x),r=t,n.begin(t),x({type:`open`,tstart:t}));let a=n.x(S[e],E?E[e]:NaN);if(w[e]=a,!i||a!==a)return;let s=o>1?Math.round((a-i.grid[0])/(i.grid[o-1]-i.grid[0])*(o-1)):0,c=!1;for(let t of T){let n=t.v[e],r=_$(i.grid,t.b.mean,a);n!==n||r!==r||(t.d[e]=n-r,t.b.n[s]>=2&&(n<_$(i.grid,t.b.lo,a)||n>_$(i.grid,t.b.hi,a))&&(c=!0,p.add(t.name)))}c?(u!==u&&(u=S[e]),d=S[e],f=NaN,!m&&S[e]-u>=l&&(m=!0,x({type:`deviation`,t0:u,channels:[...p]}))):u===u&&(f!==f&&(f=S[e]),S[e]-f>=l&&h(x))});for(let e of D)x({type:`close`,segment:e});g.writeComputed(e.column,e.unit,y,w);for(let e of T)g.writeComputed(`${e.name} Δ`,g.unitOf(e.name),y,e.d)}}}var k$=1e7;function A$(e=globalThis.navigator?.deviceMemory){return Math.max(512,Math.round(((e??0)>0?e:16)*1024/8))}var j$=400,M$=4e3,N$=1e3,P$=3e3,F$=2,I$=5e3,L$=1e4;function R$(e,t,n=`data`){let r=new Xe(t.capacity??k$,void 0,void 0,(t.maxMemoryMB??A$())*1024*1024);return{meta:e,buffer:r,source:new QQ(()=>r),unsub:()=>{},status:`connecting`,error:null,lastFrameAt:Date.now(),lastColCount:0,lastValued:0,recorder:null,schemas:new Map,video:n===`camera`?new OE:null,clock:n===`camera`?null:new ZQ,lagTicks:0,lastRejoinAt:0,rejoin:()=>{},subscribed:!1,releaseTimer:void 0}}function z$(e,t,n=()=>({}),r){let i=new Map,a=e,o=[],s=[],c=``,l=()=>{let e=[];for(let t of i.values())t.lastColCount=t.buffer.columnNames.length,t.lastValued=t.buffer.valuedCount,e.push({...t.meta,kind:t.video?`camera`:`data`,video:t.video,clock:t.clock,dataset:t.buffer.toDataset(j$),source:t.source,rowCount:t.buffer.size,status:t.status,error:t.error,recordingSince:t.recorder?.startedAt??null});o=e,t(o)},u=(e,t)=>{let n=!1,r=e.buffer.endAbs;for(let r of t)r&&typeof r.t==`number`&&Array.isArray(r.signals)&&(e.buffer.push(r),e.recorder?.add(r),n=!0);n&&p(e,r,t[t.length-1]?.t)},d=(e,t)=>{let n=e.buffer.endAbs;e.buffer.pushColumns(t),e.recorder?.addColumns(t),t.t.length>0&&p(e,n,t.t[t.t.length-1])},p=(e,t,n)=>{s$(e.buffer,s,t),e.segAxis?.tracker.feed(e.buffer,t),r?.rows(e.meta.id,e.buffer,t),typeof n==`number`&&e.clock?.observe(n,Date.now()/1e3),m(e,t===0||e.buffer.columnNames.length!==e.lastColCount||e.buffer.valuedCount!==e.lastValued)},m=(e,t)=>{e.lastFrameAt=Date.now();let n=e.status===`stale`||e.status===`connecting`;n&&(e.status=`live`),(n||t)&&l()},h=e=>{let t=i.get(e);t&&(clearTimeout(t.releaseTimer),t.unsub(),i.delete(e),l())},g=setInterval(()=>{let e=Date.now(),t=!1;for(let n of i.values()){n.status===`live`&&e-n.lastFrameAt>M$&&(n.status=`stale`,t=!0);let i=n.video&&n.subscribed&&n.status===`live`?n.video.info().lagMs:null;n.lagTicks=i!==null&&i>P$?n.lagTicks+1:0,n.video&&n.lagTicks>=F$&&e-n.lastRejoinAt>=I$&&(n.lagTicks=0,n.lastRejoinAt=e,n.video.resync(),n.unsub(),n.rejoin()),n.buffer.size&&r?.tick(n.meta.id,n.buffer,n.lastFrameAt)}t&&l()},N$);return{connections:()=>o,disconnect:h,startRecording(e){let t=i.get(e);!t||t.recorder||(t.recorder=new n$,l())},stopRecording(e){let t=i.get(e),n=t?.recorder;return!t||!n?null:(t.recorder=null,l(),{csv:n.toCsvParts(),rows:n.rows,name:t.meta.name,startedAt:n.startedAt})},setRelay(e){a=e},setSegmentAxis(e,t){let n=i.get(e);n&&(n.segAxis=t?{cfg:t,tracker:O$(t)}:void 0,t&&n.segAxis.tracker.feed(n.buffer,n.buffer.firstAbs,!t.replay),l())},setMathChannels(e){let t=JSON.stringify(e.map(e=>[e.id,e.name,e.units,e.formula,e.enabled]));if(t!==c){c=t,s=e;for(let t of i.values())t.video||(c$(t.buffer,e),t.segAxis&&(t.segAxis.tracker=O$(t.segAxis.cfg),t.segAxis.tracker.feed(t.buffer,t.buffer.firstAbs,!0)));i.size>0&&l()}},openLocal(e,t){let r=`local:${crypto.randomUUID()}`,a=R$({id:r,name:e,ownerName:`This page`,visibility:`private`,orgName:null,parentId:null,lowOf:null},{...n(),...t});return i.set(r,a),l(),{id:r,push:e=>{i.get(r)===a&&u(a,Array.isArray(e)?e:[e])},pushColumns:e=>{i.get(r)===a&&d(a,e)},close:()=>h(r)}},async connect(e,t,r){if(i.has(e.id))return;let o=a&&e.relay_url?{...a,url:e.relay_url}:a;if(!o)throw new kE(`relay_unavailable`);let s=typeof t==`string`?await f(ue(t).secret??t,e.salt):`keyFor`in t?e=>t.keyFor(e):t;if(typeof s!=`function`&&!await ge(s,e.key_check))throw new kE(`wrong_password`);let c=R$({id:e.id,name:e.name,ownerName:e.owner_name??``,visibility:e.visibility??`private`,orgName:e.org_name??null,projectName:e.project_name??null,parentId:e.parent_stream_id??null,lowOf:e.low_of_stream_id??null},{...n(),...r},e.kind);i.set(e.id,c);let p=Promise.resolve();c.rejoin=()=>{c.unsub=GQ(o,e.id,t=>{let n=ye(s,t).catch(()=>null);p=p.then(async()=>{try{let t=await n;if(!t||i.get(e.id)!==c)return;if(t.kind===6){let e=YQ(t.plaintext);e&&c.video&&(c.video.push(e),m(c,!1));return}if(t.kind===5){let e=de(t.plaintext);c.schemas.set(e.id,e);return}if(t.kind===7){let e=he(t.plaintext,c.schemas);if(!e)return;let n=c.buffer;for(let t of e)n.setLastKnown(t.name,t.unit,t.t,t.v);(n.columnNames.length!==c.lastColCount||n.valuedCount!==c.lastValued)&&l();return}if(t.kind===4){let e=await Ge(t.plaintext,c.schemas);e&&!e.historical&&d(c,e.block);return}if(t.kind===3)return d(c,Ie(t.plaintext));if(t.kind!==2)return;let r=ie(t.plaintext);u(c,Array.isArray(r?.frames)?r.frames:[])}catch{}})},t=>{!c.subscribed||i.get(e.id)!==c||(t===`subscribed`?(c.status=`live`,c.lastFrameAt=Date.now()):t===`error`&&(c.status=`error`,c.error=`connection_error`),l())})};let h=c.video;h?(c.status=`idle`,h.onDemandChange(t=>{i.get(e.id)===c&&(clearTimeout(c.releaseTimer),t?c.subscribed||(c.subscribed=!0,h.resync(),c.status=`connecting`,c.lastFrameAt=Date.now(),c.rejoin(),l()):c.releaseTimer=setTimeout(()=>{c.subscribed=!1,c.unsub(),c.unsub=()=>{},c.status=`idle`,c.error=null,c.lagTicks=0,l()},L$))})):(c.subscribed=!0,c.rejoin()),l()},dispose(){clearInterval(g);for(let e of i.values())clearTimeout(e.releaseTimer),e.unsub();i.clear(),o=[]}}}var B$=500,V$=1<<20;function H$(e){let t=[],n=new Map,r=[],i=``,a=(e,t)=>`${e}|${t}`,o=(e,t)=>{let n=t.kind===`stream`?e.targets?.streams:t.kind===`history`?e.targets?.histories:e.targets?.datasets;return!n||n.includes(t.kind===`dataset`?t.name??t.id:t.id)},s=()=>[...n.values()].map(e=>{let{state:t,missing:n,since:r}=e.state();return{ruleId:e.rule.id,target:e.target,state:t,...n?{missing:n}:{},...r===void 0?{}:{since:r}}}),c=()=>{let t=s(),n=JSON.stringify(t);n!==i&&(i=n,e.setStates(t))};function l(n,i){let a=t.find(e=>e.id===n.ruleId);if(n.kind===`raised`){r=[...r,{id:`${n.ruleId}|${n.target.id}|${n.t}`,ruleId:n.ruleId,ruleName:a?.name??``,severity:a?.severity??`info`,targetId:n.target.id,timeColumn:i,t0:n.t,t1:null}];let e=r.filter(e=>e.targetId===n.target.id);e.length>B$&&(r=r.filter(t=>t!==e[0]))}else{let e=r.find(e=>e.ruleId===n.ruleId&&e.targetId===n.target.id&&e.t1===null);e&&(r=r.map(t=>t===e?{...t,t1:n.t}:t))}e.setMarks(r),e.emit(n)}function u(){let r=new Set;for(let i of e.targets())for(let e of t){if(!o(e,i))continue;let t=a(e.id,i.id);r.add(t);let s=n.get(t),{channels:c,...u}=i;(!s||s.rule!==e)&&(s=et(e,u),n.set(t,s));for(let e of s.bind(c))l(e,i.kind===`stream`?qe:``)}for(let e of n.keys())r.has(e)||n.delete(e);c()}return{setRules(n){let r=[],i=n.filter(e=>{let t=tt(e);return r.push(...t.map(t=>({ruleId:String(e?.id??``),...t}))),!t.length}),a=e.maxRules();a!==null&&i.length>a&&e.limit();let o=new Map(t.map(e=>[e.id,e]));return t=(a===null?i:i.slice(0,a)).map(e=>{let t=o.get(e.id);return t&&t.version===e.version?t:e}),u(),r},rules:()=>t,state:s,async evaluate(n,i){let a=e.targets().find(e=>e.id===n&&e.kind===`dataset`);if(!a)return[];let{channels:s,...c}=a,u=[],d=t.filter(e=>(!i.ruleIds||i.ruleIds.includes(e.id))&&o(e,c)),f=d.map(e=>{let t=et(e,c);return t.bind(s),t}),p=[...new Set(d.flatMap(e=>Object.values(e.signals).map(e=>`formula`in e?e.formula:e.channel)))];for(let t=0;;t+=V$){let r=await e.readDataset(n,[i.timeColumn,...p],t,V$),a=r[i.timeColumn];if(!a||!a.length)break;for(let e of f)u.push(...e.push({t:a,columns:r}));if(a.length<V$)break}r=r.filter(e=>!(e.targetId===n&&(!i.ruleIds||i.ruleIds.includes(e.ruleId)))),e.setMarks(r);for(let e of u)l(e,i.timeColumn);return u},pushLive(e,t){let r=!1;for(let i of n.values()){if(i.target.id!==e)continue;let n=i.push(t);n.length&&(r=!0);for(let e of n)l(e,qe)}r&&c()},tickLive(e,t){let r=!1;for(let i of n.values()){if(i.target.id!==e)continue;let n=i.tick(t);n.length&&(r=!0);for(let e of n)l(e,qe)}r&&c()},liveColumns(e){let t=new Set;for(let r of n.values())if(r.target.id===e)for(let e of Object.values(r.rule.signals))t.add(`formula`in e?e.formula:e.channel);return[...t]},sync:u,clearMarks(t){r=t?r.filter(e=>e.targetId!==t):[],e.setMarks(r)}}}var U$=class{past=[];future=[];current=null;lastAt=-1/0;o;equals;constructor(e){this.o=e,this.equals=e.equals??Object.is}get canUndo(){return this.past.length>0}get canRedo(){return this.future.length>0}observe(e){if(this.current===null)return this.current=e,!1;if(this.equals(e,this.current))return!1;let t=this.o.now();return t-this.lastAt<this.o.mergeMs&&this.past.length>0||(this.past.push(this.current),this.past.length>this.o.limit&&this.past.shift()),this.current=e,this.future=[],this.lastAt=t,!0}rebase(e){this.current=e}undo(){if(this.past.length===0)return null;let e=this.past.pop();return this.future.push(this.current),this.current=e,this.lastAt=-1/0,e}redo(){if(this.future.length===0)return null;let e=this.future.pop();return this.past.push(this.current),this.current=e,this.lastAt=-1/0,e}clear(e){this.past=[],this.future=[],this.current=e,this.lastAt=-1/0}},W$={maxChartsPerWorksheet:null,maxChannelsPerChart:null,maxWorksheets:null,maxMathChannels:null,maxAlertRules:null,canImportExportWorkspaces:!0},G$=[];function K$(e,t){let n=e.found[t];return{definitionId:n.definitionId,rule:e.defs.find(e=>e.id===n.definitionId)?.name??n.definitionId,index:n.index,parentIndex:n.parentIndex??null,tstart:n.tstart,tend:n.tend,flags:n.flags,kpis:n.kpis??{},incomplete:!!n.incomplete}}var q$=[`#a78bfa`,`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#94a3b8`];function J$(e=`ET`){return{id:crypto.randomUUID(),name:`Worksheet`,panels:[],panelChartSettings:{},panelChartBackgrounds:{},xKey:e}}function Y$(e,t){let n=e.filter(e=>e.source!==`workbook`),r=new Map,i=[];for(let e of t){let t=n.find(t=>t.name===e.name);if(t&&t.formula===e.formula&&t.units===e.units)continue;let a=t?`${e.name} (workbook)`:e.name;t&&r.set(e.name,a),i.push(cr({...e,name:a,source:`workbook`}))}return{channels:i,rename:r}}function X$(e,t){let n=JSON.stringify({xKey:e.xKey,panelChartSettings:e.panelChartSettings});for(let[e,r]of t)n=n.split(JSON.stringify(e)).join(JSON.stringify(r));return{...e,...JSON.parse(n)}}function Z$(e){return typeof e.text==`function`?e.text():new Promise((t,n)=>{let r=new FileReader;r.onload=()=>t(String(r.result??``)),r.onerror=()=>n(r.error),r.readAsText(e)})}function Q$(e,t,n){if(!e||!t)return $t();let{min:r,max:i}=Sz(e.rows,t);if(!Number.isFinite(r)||!Number.isFinite(i))return $t();let a=wz(i-r||1,6),o=a>=1?Math.round(a):a,s=o>=1?1:o/10,c=Math.max(0,Math.ceil(-Math.log10(s))),l=e=>String(Number(e.toFixed(c)));return{...n,scaleMin:l(Math.floor(r/s)*s),scaleMax:l(Math.ceil(i/s)*s),majorStep:l(o),minorStep:``}}function $$(e,t){let n=t.includes(e.xKey)?e.xKey:t.includes(`ET`)?`ET`:t.includes(`ElapsedTime`)?qe:t[0],r={...e.panelChartSettings};for(let n of e.panels){let e=r[n.id];if(n.kind===`multiband`){let i=e&&e.kind===`multiband`?e:pn();r[n.id]={...i,kind:`multiband`,addColumn:i.addColumn&&t.includes(i.addColumn)?i.addColumn:t[0]}}else if(n.kind===`xyscatter`){let i=e&&e.kind===`xyscatter`?e:mn(q$[2]),a=i.xyXCol||t[0],o=i.xyYCol||(t.length>1&&t[1]!==a?t[1]:t[0]);r[n.id]={...i,kind:`xyscatter`,xyXCol:a,xyYCol:o}}else if(n.kind===`xyzmesh`){let i=e&&e.kind===`xyzmesh`?e:hn(4),a=i.xyzXCol||t[0],o=i.xyzYCol||(t.length>1?t[1]:t[0]),s=i.xyzZCol||(t.length>2?t[2]:t[0]);r[n.id]={...i,kind:`xyzmesh`,xyzXCol:a,xyzYCol:o,xyzZCol:s}}}return{...e,xKey:n,panelChartSettings:r}}function e1(e,t){let n=!1,r={...e.panelChartSettings};for(let[i,a]of Object.entries(e.panelChartSettings)){if(a.kind!==`multiband`)continue;let e=a.series.filter(e=>t(e.column));e.length!==a.series.length&&(r[i]={...a,series:e},n=!0)}return n?{...e,panelChartSettings:r}:e}function t1(){return typeof document>`u`?`dark`:$z(null)}function n1(e={}){let t={...e},n=!1,r=J$(),i=kQ({datasets:[],selection:[],worksheets:[r],activeWorksheetId:r.id,xRanges:{},offsets:{},colors:{},liveWindowSeconds:15,segmentContext:null,cycleRules:[],live:[],video:[],mathChannels:[],limits:{...W$,...t.limits},palette:Xz(t.palette,t1()),importing:0,licensed:null,history:{canUndo:!1,canRedo:!1},marks:[],alerts:[],alertRules:[]}),a=RV(),o=()=>{let e=Xz(t.palette,t1());i.set(t=>t.palette.join()===e.join()?t:{...t,palette:e})},s=typeof document>`u`?()=>{}:eB(null,o),c=jQ(),l=()=>{if(n)throw new kE(`disposed`)},u=e=>{throw a.emit(`limit`,{reason:e}),new kE(`limit_reached`,{reason:e})},d=()=>i.get(),f=(e,t)=>{let n=d().limits.maxChannelsPerChart,r=Cz(t);n!==null&&r>n&&r>Cz(e)&&u(`channels-per-chart`)},p=AQ((e,t)=>t===null?e:e.slice(0,t)),m=()=>{let e=d(),t=c.lapsByDataset(e.datasets),n=c.selectedDatasets(e.datasets,t,e.selection),r=c.selectedLive(e.live,e.selection),i=c.staticDataset(n),a=c.mergedDataset(i,r),o=p(e.mathChannels,e.limits.maxMathChannels);return{laps:t,selectedDatasets:n,selectedLive:r,staticDataset:i,merged:a,channels:o,numericColumns:c.numericColumns(a,n,o,c.mergedParts(n,r),r),allColumns:c.allColumns(a,n,o),columnUnits:c.columnUnits(a,o)}},h=(e,t)=>({id:t.id,kind:t.kind,title:t.title??null,settings:e.panelChartSettings[t.id],background:e.panelChartBackgrounds[t.id]??null,annotations:e.panelChartSettings[t.id]?.annotations??G$,layout:t.rect}),g=AQ((e,t,n)=>e.map(e=>({id:e.id,name:e.name,xKey:e.xKey,xRange:t[e.id]??null,liveWindowSeconds:e.liveWindowSeconds===void 0?n:e.liveWindowSeconds,charts:e.panels.map(t=>h(e,t))}))),_=AQ((e,t,n,r,i,a,o)=>{let s=(e,t)=>{let n=a.findIndex(t=>t.id===e);return n>=0?n:t};return e.map((e,a)=>{let c=i[e.id],l=c?.laps.map(e=>e.id)??[],u=l.filter(e=>t.includes(e)).length;return{id:e.id,name:e.name,kind:e.kind,columns:e.schema.map(e=>({name:e.name,unit:e.unit??``,numeric:e.type===`number`})),rowCount:e.data.rows.length,color:Jz(n,e.id,s(e.id,a),o),customColor:e.id in n,offset:r[e.id]??0,parseConfig:e.parseConfig??null,fileInfo:e.info??null,beacon:e.beacon??null,cut:e.cut?{cycleId:e.cut.cycleId,timeKey:e.cut.timeKey,defs:e.cut.defs}:null,laps:c?c.laps.map((i,a)=>({id:i.id,name:i.name,value:c.values[a],unit:c.unit,isTime:c.isTime,color:Jz(n,i.id,s(i.id,a),o),offset:r[i.id]??0,selected:t.includes(i.id),...e.cut?{cycle:K$(e.cut,a)}:{}})):null,selected:c?u===0?!1:u===l.length?!0:`partial`:t.includes(e.id)}})}),v=AQ((e,t,n,r,i)=>{let a=e.filter(e=>t.includes(e.id)).map(e=>e.id);return e.map((e,o)=>({id:e.id,name:e.name,ownerName:e.ownerName,visibility:e.visibility,orgName:e.orgName,kind:e.kind,parentId:e.parentId,lowOf:e.lowOf,status:e.status,error:e.error,rowCount:e.rowCount,selected:t.includes(e.id),color:Jz(n,e.id,a.includes(e.id)?r+a.indexOf(e.id):o,i),customColor:e.id in n,recordingSince:e.recordingSince,channels:e.dataset.columnNames}))}),y=AQ(e=>{let t=m();return{datasets:_(e.datasets,e.selection,e.colors,e.offsets,t.laps,t.selectedDatasets,e.palette),selection:e.selection,worksheets:g(e.worksheets,e.xRanges,e.liveWindowSeconds),activeWorksheetId:e.activeWorksheetId,mathChannels:t.channels,live:v(e.live,e.selection,e.colors,t.selectedDatasets.length,e.palette),liveWindowSeconds:(()=>{let t=e.worksheets.find(t=>t.id===e.activeWorksheetId);return t?.liveWindowSeconds===void 0?e.liveWindowSeconds:t.liveWindowSeconds})(),segmentContext:e.segmentContext,cycleRules:e.cycleRules,limits:e.limits,palette:e.palette,importing:e.importing,licensed:e.licensed,hasData:t.merged!==null,multiDataset:t.selectedDatasets.length+t.selectedLive.length>1,numericColumns:t.numericColumns,allColumns:t.allColumns,columnUnits:t.columnUnits,history:e.history,marks:e.marks,alerts:e.alerts}}),b=(e,t)=>e===t||e.length===t.length&&e.every((e,n)=>e===t[n]||JSON.stringify(e)===JSON.stringify(t[n])),x=new U$({limit:100,mergeMs:500,now:()=>Date.now(),equals:(e,t)=>e.liveWindowSeconds===t.liveWindowSeconds&&b(e.worksheets,t.worksheets)&&b(e.channels,t.channels)}),S=!0,C=0,w=e=>{C++;try{e()}finally{C--}},T=e=>[e.worksheets,e.mathChannels,e.liveWindowSeconds],E=[],D=()=>{let e=d();return{worksheets:e.worksheets,channels:e.mathChannels.filter(e=>e.source===`workbook`),liveWindowSeconds:e.liveWindowSeconds,activeWorksheetId:e.activeWorksheetId}},O=()=>i.set(e=>e.history.canUndo===x.canUndo&&e.history.canRedo===x.canRedo?e:{...e,history:{canUndo:x.canUndo,canRedo:x.canRedo}}),k=()=>{if(S)return;let e=T(d());e.every((e,t)=>e===E[t])||(E=e,C?x.rebase(D()):x.observe(D()),O())},A=()=>{E=T(d()),x.clear(D()),O()},j=e=>{S=!0;let t;try{t=e()}finally{S=!1}return A(),t},M=()=>y(d());i.subscribe(()=>{k(),a.emit(`change`,M())});let N=e=>{let t=d(),n=t.worksheets.find(n=>n.id===(e??t.activeWorksheetId));if(!n)throw new kE(`not_found`,{worksheetId:e});return n},P=e=>{for(let t of d().worksheets){let n=t.panels.find(t=>t.id===e);if(n)return{ws:t,panel:n}}throw new kE(`not_found`,{chartId:e})},F=(e,t)=>i.set(n=>{let r=!1,i=n.worksheets.map(n=>{if(n.id!==e)return n;let i=t(n);return i!==n&&(r=!0),i});return r?{...n,worksheets:i}:n}),I=(e,t)=>{let{ws:n}=P(e);F(n.id,n=>({...n,panelChartSettings:{...n.panelChartSettings,[e]:t(n.panelChartSettings[e])}}))},L=e=>i.set(t=>e.length===t.selection.length&&e.every((e,n)=>e===t.selection[n])?t:{...t,selection:e,xRanges:{}}),R=new Set,z=z$(t.live?.relay,e=>{let t=e.map(e=>e.id),n=e.filter(e=>e.kind===`data`&&!R.has(e.id)).map(e=>e.id),r=[...R].filter(e=>!t.includes(e));if(R=new Set(t),i.set(t=>({...t,live:e})),r.length&&L(d().selection.filter(e=>!r.includes(e))),n.length){let e=d().selection,t=n.filter(t=>!e.includes(t));t.length&&L([...e,...t])}let a=m();if(a.selectedLive.length&&a.merged){let e=a.merged.columnNames;if(e.includes(`ElapsedTime`))for(let t of d().worksheets)e.includes(t.xKey)||w(()=>F(t.id,e=>({...e,xKey:qe})))}},()=>({capacity:t.live?.capacity,maxMemoryMB:t.live?.maxMemoryMB}),{rows:(e,t,n)=>{if(!ce.rules().length)return;t.columnNames.length!==V.get(e)&&(V.set(e,t.columnNames.length),ce.sync());let r=ce.liveColumns(e);if(!r.length)return;let i=t.endAbs,a=Math.max(n,t.firstAbs);if(i<=a)return;let o={};for(let e of r)o[e]=t.range(e,a,i);ce.pushLive(e,{t:t.range(qe,a,i),columns:o,scan:new Map})},tick:(e,t,n)=>{if(!ce.rules().length)return;let r=t.range(qe,t.endAbs-1,t.endAbs)[0];r===r&&ce.tickLive(e,r+(Date.now()-n)/1e3)}}),V=new Map,te=AQ((e,t)=>e.filter(e=>t.some(t=>SE([e],t.panelChartSettings,t.xKey).length>0))),ne=()=>z.setMathChannels(te(p(d().mathChannels,d().limits.maxMathChannels),d().worksheets));ne(),i.subscribe(ne);let re=e=>{i.set(t=>({...t,datasets:[...t.datasets,e]})),L([...d().selection,e.id]);let t=xz(e.schema);t.length&&w(()=>i.set(e=>({...e,worksheets:e.worksheets.map(e=>$$(e,t))})))},ie=Promise.resolve(),U=async(e,r={})=>{l();let o=e.map(e=>e instanceof File?e:e.file);if(o.length===0)return{ids:[],errors:[]};if(await t.beforeImport?.()===!1)throw new kE(`import_vetoed`);let{signal:s}=r;i.set(e=>({...e,importing:e.importing+o.length}));let c=ie.then(async()=>{let e={ids:[],errors:[]},t=o.length,c=e=>{t-=e,i.set(t=>({...t,importing:Math.max(0,t.importing-e)}))};try{let{items:t,errors:i}=await DR(o);c(o.length-t.length);for(let{file:t,error:n}of i)e.errors.push({file:t,error:n}),a.emit(`import`,{file:t,phase:`error`,error:n}),a.emit(`error`,{error:n,context:`import`});for(let i of t){if(n)break;if(s?.aborted){e.cancelled=!0;break}let t=i.main;await new Promise(e=>setTimeout(e,0)),a.emit(`import`,{file:t.name,phase:`start`});try{let o=i.format?await bz({main:t,companions:i.companions,format:i.format.id},{priorInMemoryValues:yR(d().datasets),signal:s,onProgress:e=>a.emit(`import`,{file:t.name,phase:`progress`,fraction:e}),chooseChannels:r.chooseChannels,pickChannels:r.pickChannels}):[await vR(crypto.randomUUID(),t,d().datasets)??await gR(crypto.randomUUID(),t,Z$,void 0,yR(d().datasets),s)];if(n){for(let e of o)e.source.dispose();break}if(s?.aborted){for(let e of o)e.source.dispose();throw new kE(`cancelled`)}for(let t of o)re(t),e.ids.push(t.id);a.emit(`import`,{file:t.name,phase:`done`,datasetId:o[0].id,datasetIds:o.map(e=>e.id)})}catch(n){let r=n instanceof Error?n:Error(String(n));a.emit(`import`,{file:t.name,phase:`error`,error:r}),r instanceof kE&&r.code===`cancelled`?e.cancelled=!0:(e.errors.push({file:t.name,error:r}),a.emit(`error`,{error:r,context:`import`}))}finally{c(1)}if(e.cancelled)break}}finally{t>0&&c(t)}return e});return ie=c.catch(()=>void 0),c},ae=()=>setTimeout(()=>{n||HZ(nt)},0),oe=e=>{let t=t=>e.some(e=>t===e||t.startsWith(`${e}::`)),n=d().datasets.filter(t=>e.includes(t.id));for(let e of n)e.source.dispose().catch(()=>void 0);i.set(n=>{let r={...n.offsets},i={...n.colors};for(let e of Object.keys(r))t(e)&&delete r[e];for(let e of Object.keys(i))t(e)&&delete i[e];return{...n,datasets:n.datasets.filter(t=>!e.includes(t.id)),offsets:r,colors:i}}),L(d().selection.filter(e=>!t(e))),n.length>0&&ae()},se=async(e,t,n={})=>{let[r,...i]=await bz({main:new File(e.chunks,`${e.name}.krc`),companions:[],format:`krc`,keys:e.keys},{priorInMemoryValues:t,...n});for(let e of i)e.source.dispose();return{...r,file:void 0,name:e.name,info:r.info&&{...r.info,startTime:e.startTime??r.info.startTime,meta:{...r.info.meta,recordingId:e.recordingId}}}},ce=H$({targets:()=>[...d().datasets.map(e=>({kind:`dataset`,id:e.id,name:e.name,channels:e.schema.map(e=>e.name)})),...d().live.filter(e=>e.kind===`data`).map(e=>({kind:`stream`,id:e.id,name:e.name,channels:e.source.columnNames}))],maxRules:()=>d().limits.maxAlertRules,emit:e=>a.emit(`alert`,e),limit:()=>a.emit(`limit`,{reason:`alert-rules`}),setMarks:e=>i.set(t=>({...t,marks:e})),setStates:e=>i.set(t=>({...t,alerts:e})),readDataset:(e,t,n,r)=>{let i=d().datasets.find(t=>t.id===e);return i?i.source.readColumns(t,n,r):Promise.resolve({})}}),le=AQ((e,t)=>{let n=new Map;for(let r of e){let e=rt(r);e!==null&&n.set(r.id,{value:e,active:t.some(e=>e.ruleId===r.id&&(e.state===`active`||e.state===`clearing`))})}return n}),ue=null;i.subscribe(()=>{let e=d();ue&&ue[0]===e.datasets&&ue[1]===e.live||(ue=[e.datasets,e.live],ce.rules().length&&ce.sync())});let de={importFiles:U,warmImport(e={}){l(),cz(!!e.formats?.some(e=>e===`hdf5`||e===`mat`))},async splitByRate(e){l();let t=d().datasets.find(t=>t.id===e);if(!t)throw new kE(`not_found`,{datasetId:e});if(!t.info?.combined||!(t.file instanceof File))throw new kE(`invalid_argument`,{reason:`only a combined multi-rate import can be split`});let n=await bz({main:t.file,companions:t.companions??[],format:t.info.importer},{priorInMemoryValues:yR(d().datasets.filter(t=>t.id!==e)),selection:t.info.selection,split:!0});oe([e]);for(let e of n)re(e);return n.map(e=>e.id)},async chooseChannels(e,t){l();let n=d().datasets.find(t=>t.id===e);if(!n)throw new kE(`not_found`,{datasetId:e});if(!n.info||!(n.file instanceof File))throw new kE(`invalid_argument`,{reason:`only binary imports have channels to choose`});try{let r=await bz({main:n.file,companions:n.companions??[],format:n.info.importer},{priorInMemoryValues:yR(d().datasets.filter(t=>t.id!==e)),initial:n.info.selection,chooseChannels:t,pickChannels:!0});oe([e]);for(let e of r)re(e);return r.map(e=>e.id)}catch(e){if(e instanceof kE&&e.code===`cancelled`)return null;throw e}},async combine(e){l();let t=d().datasets.find(t=>t.id===e);if(!t)throw new kE(`not_found`,{datasetId:e});let n=t.info?.splitKey;if(!n||!(t.file instanceof File))throw new kE(`invalid_argument`,{reason:`only datasets split from one file can be combined`});let r=d().datasets.filter(e=>e.info?.splitKey===n),i=await bz({main:t.file,companions:t.companions??[],format:t.info.importer},{priorInMemoryValues:yR(d().datasets.filter(e=>!r.includes(e))),selection:r.flatMap(e=>e.info.selection)});if(i.length!==1){for(let e of i)e.source.dispose();throw new kE(`invalid_argument`,{reason:`these groups have no common time base`})}return oe(r.map(e=>e.id)),re(i[0]),i[0].id},async openRecording(e,t={}){l();let n=await se(e,yR(d().datasets),t);return re(n),n.id},async reopenRecording(e,t){l();let n=d().datasets.find(t=>t.id===e);if(!n)throw new kE(`not_found`,{datasetId:e});let r=await se(t,yR(d().datasets.filter(t=>t.id!==e)));i.set(t=>({...t,datasets:t.datasets.map(t=>t.id===e?{...r,id:e,beacon:n.beacon}:t)})),n.source.dispose().catch(()=>void 0),ae()},openHistoryRange(e){l();let t=OQ(crypto.randomUUID(),e);return re(t),t.id},updateHistoryRange(e,t){l();let n=d().datasets.find(t=>t.id===e);if(!n)throw new kE(`not_found`,{datasetId:e});if(!(n.source instanceof _Q)){let t=`dataset ${e} is not a history range: only datasets opened with openHistoryRange can be updated`;throw Object.assign(new kE(`invalid_argument`,{datasetId:e,reason:t}),{message:t})}let r=OQ(e,t);i.set(t=>({...t,datasets:t.datasets.map(t=>t.id===e?{...r,beacon:n.beacon}:t)})),ae()},addColumns(e){l();let t=xQ(crypto.randomUUID(),e);return re(t),t.id},replaceColumns(e,t,n={}){l();let r=d().datasets.find(t=>t.id===e);if(!r)throw new kE(`not_found`,{datasetId:e});let a=TQ(r,t,n.transfer);i.set(t=>({...t,datasets:t.datasets.map(t=>t.id===e?a:t)}))},writeColumns(e,t,n){l();let r=d().datasets.find(t=>t.id===e);if(!r)throw new kE(`not_found`,{datasetId:e});let a=CQ(r,t,n);i.set(t=>({...t,datasets:t.datasets.map(t=>t.id===e?a:t)}))},async addText(e,t=`dataset.csv`){l();let n=await pR(crypto.randomUUID(),t,e);return re(n),n.id},async findCycles(e,t,n){l();let r=d().datasets.find(t=>t.id===e);if(!r)throw new kE(`not_found`,{datasetId:e});let i=await BB(r.source,n,HB(t)),a=new Map(t.filter(e=>e.kpis?.length).map(e=>[e.id,e.kpis]));return VB(i,t).map(e=>a.has(e.definitionId)?{...e,kpis:WB(i,e,a.get(e.definitionId))}:e)},async addCycles(e,t){l();let n=d().datasets.find(t=>t.id===e);if(!n)throw new kE(`not_found`,{datasetId:e});let r=n.schema.filter(e=>e.type===`number`&&e.name!==t.timeKey).map(e=>e.name),i=await BB(n.source,t.timeKey,r),a={...Object.fromEntries(n.schema.map(e=>[e.name,e.unit])),[RB]:`s`},o=e=>t.defs.find(t=>t.id===e)?.name??e,s=[];for(let e of t.pick){let r=t.found.find(t=>t.definitionId===e.definitionId&&t.index===e.index&&t.parentIndex===e.parentIndex);if(!r)throw new kE(`not_found`,{reason:`no ${o(e.definitionId)} ${e.index} in the cycles found`});let c=r.parentIndex?`${o(t.cycleId)} ${r.parentIndex} · ${o(r.definitionId)}`:`${o(r.definitionId)} ${r.index}`;s.push(de.addColumns({name:`${n.name} · ${c}`,columns:KB(i,t.timeKey,r),units:a}))}if(t.tables!==!1){let e=JB(t.found,t.cycleId,t.defs,i);s.push(await de.addText(YB(e.cycles),`${n.name} · ${o(t.cycleId)}s.csv`)),e.phases.length&&s.push(await de.addText(YB(e.phases),`${n.name} · Phases.csv`))}return s},async cut(e,t){l();let n=d().datasets.find(t=>t.id===e);if(!n)throw new kE(`not_found`,{datasetId:e});let r;if(t){if(!t.defs.some(e=>e.id===t.cycleId))throw new kE(`invalid_argument`,{reason:`cycleId is not one of defs`});let i=n.schema.filter(e=>e.type===`number`&&e.name!==t.timeKey).map(e=>e.name),a=await BB(n.source,t.timeKey,i),o=t.defs.find(e=>e.id===t.cycleId)?.show,s=e=>[...e.kpis??[],...o&&o.channel!==t.timeKey?[o]:[]],c=new Map(t.defs.filter(e=>s(e).length).map(e=>[e.id,s(e)])),l=VB(a,t.defs).sort((e,t)=>e.tstart-t.tstart||!!e.parentIndex-+!!t.parentIndex).map(e=>c.has(e.definitionId)?{...e,kpis:WB(a,e,c.get(e.definitionId))}:e),u={...Object.fromEntries(n.schema.map(e=>[e.name,e.unit])),[RB]:`s`},d=e=>t.defs.find(t=>t.id===e)?.name??e,f=l.map(r=>xQ(`${e}::${r.definitionId}:${r.parentIndex??0}:${r.index}`,{name:r.parentIndex?`${n.name} · ${d(t.cycleId)} ${r.parentIndex} · ${d(r.definitionId)}`:`${n.name} · ${d(r.definitionId)} ${r.index}`,columns:KB(a,t.timeKey,r),units:u})),p=a.t.length?a.t[a.t.length-1]:NaN,m=l.map(e=>e.tend===null&&p===p?{...e,tend:p,incomplete:!0}:e);r={defs:t.defs,cycleId:t.cycleId,timeKey:t.timeKey,found:m,parts:f}}else if(!n.cut)return 0;if(!d().datasets.some(t=>t.id===e))return 0;i.set(t=>({...t,datasets:t.datasets.map(t=>t.id===e?{...t,cut:r}:t)}));let a=d().selection,o=a.some(t=>t===e||t.startsWith(`${e}::`)),s=a.filter(t=>t!==e&&!t.startsWith(`${e}::`)),c=r?r.parts.filter((e,t)=>!r.found[t].parentIndex).map(e=>e.id):[];return L(o?c.length>0?[...s,...c]:[...s,e]:s),c.length},remove(e){l(),oe([e])},clear(){l(),oe(d().datasets.map(e=>e.id))},async configure(e,t){l();let n=d().datasets.find(t=>t.id===e);if(!n)throw new kE(`not_found`,{datasetId:e});if(t.parseConfig&&(n.kind!==`memory`||!n.parseConfig))throw new kE(`invalid_argument`,{reason:n.parseConfig?`out-of-core datasets cannot be re-parsed`:`binary files have no text parse settings`});if(t.beacon!==void 0&&t.beacon!==null&&n.kind!==`memory`)throw new kE(`invalid_argument`,{reason:`laps need an in-memory dataset`});if(t.beacon!==void 0&&JSON.stringify(t.beacon)!==JSON.stringify(n.beacon??null)){let r=t.beacon??void 0;i.set(t=>({...t,datasets:t.datasets.map(t=>t.id===e?{...t,beacon:r}:t)}));let a=d().selection,o=a.some(t=>t===e||t.startsWith(`${e}::`)),s=a.filter(t=>t!==e&&!t.startsWith(`${e}::`)),c=r?vB(n.data.rows,r.channel):[],l=r&&t.selectCycles===`best`?CB(c.map(e=>SB(n.data.rows,e,r.metric,r.stat))):null,u=l===null?c.map((t,n)=>EB(e,n)):[EB(e,l)];L(o?c.length>0?[...s,...u]:[...s,e]:s)}let r=t.parseConfig;if(!r)return;let a=(()=>{try{let e=H(ze(n.rawText??``),r.headerRow);return n.data.columnNames.length===e.length&&n.data.columnNames.every((t,n)=>t===e[n])}catch{return!1}})();if(ee(r,n.parseConfig)&&a)return;let o=n.fromColumns?DQ(n):n.rawText??``,s=await PE(n.file?{file:n.file,config:r}:{rawText:o,config:r}),c=new LE(s),u=await c.getSchema(),f=n.fromColumns?{rawText:o,fromColumns:!1}:{};i.set(t=>({...t,datasets:t.datasets.map(t=>t.id===e?{...t,...f,data:s,source:c,schema:u,parseConfig:r}:t)})),n.source.dispose().catch(()=>void 0),ae(),n.cut&&await de.cut(e,n.cut);let p=m().selectedDatasets,h=new Set(p.flatMap(e=>e.data.columnNames)),g=s.columnNames.filter(e=>B(s.rows,e)),_=g.find(e=>e===`ET`)??g[0];w(()=>i.set(e=>({...e,worksheets:e.worksheets.map(e=>e1(!h.has(e.xKey)&&_?{...e,xKey:_}:e,e=>h.has(e)))})))},setColor(e,t){l(),i.set(n=>{let r={...n.colors};return t===null?delete r[e]:r[e]=t,{...n,colors:r}})},setOffset(e,t){l(),i.set(n=>({...n,offsets:{...n.offsets,[e]:t}}))},resetOffsets(){l(),i.set(e=>Object.keys(e.offsets).length?{...e,offsets:{}}:e)},select(e){l(),L([...e])},toggle(e){l();let t=d().selection,n=m().laps[e];if(n){let e=n.laps.map(e=>e.id);L(e.every(e=>t.includes(e))?t.filter(t=>!e.includes(t)):[...t,...e.filter(e=>!t.includes(e))]);return}L(t.includes(e)?t.filter(t=>t!==e):[...t,e])},selectAll(){l();let e=m().laps,t=d().live.filter(e=>d().selection.includes(e.id)).map(e=>e.id);L([...d().datasets.flatMap(t=>e[t.id]?e[t.id].laps.map(e=>e.id):[t.id]),...t])},deselectAll(){l(),L([])},raw(e){let t=d().datasets.find(t=>t.id===e);if(!t)throw new kE(`not_found`,{datasetId:e});return{get rawText(){return t.kind===`memory`&&t.fromColumns?DQ(t):t.rawText??``},data:t.data,parseConfig:t.parseConfig??null,kind:t.kind,beacon:t.beacon??null}},async columnBounds(e){l();let t=m(),n=t.selectedDatasets.find(t=>t.schema.some(t=>t.name===e));if(n&&n.kind===`memory`){let t=Sz(n.data.rows,e);if(Number.isFinite(t.min)&&Number.isFinite(t.max))return t}else if(n){let t=await n.source.xBounds(e).catch(()=>null);if(t&&Number.isFinite(t.x0)&&Number.isFinite(t.x1)&&t.x1>=t.x0)return{min:t.x0,max:t.x1}}let r=t.selectedLive.find(t=>t.dataset.columnNames.includes(e));if(r){let t=r.source.valueBoundsSync(e);if(t)return t}let i=fe(e);if(!i)return null;let a=Sz(i.rows,e);return Number.isFinite(a.min)&&Number.isFinite(a.max)?a:null}},fe=(e,t=N().xKey)=>{let n=m();if(!n.merged)return null;if(!n.channels.find(t=>t.name===e))return n.merged;let r=xE(n.merged,n.channels,t);return{...n.merged,columnNames:[...n.merged.columnNames,...r.ok.map(e=>e.name)],rows:r.rows}},pe=(e,t,n)=>m().selectedLive.length>0?{...n,scaleMin:``,scaleMax:``,majorStep:``,minorStep:``}:Q$(fe(e,t),e,n),me={fromFileList:e=>EV(Array.from(e)),async fromDataTransfer(e){return DV(Array.from(e.items??[]).map(e=>e.webkitGetAsEntry?.()).filter(e=>!!e))},canPick:OV,pick:kV,tree:(e,t)=>TV(e,t),isImportable:wV},he={add(e=`Worksheet`){l();let t=d(),n=t.limits.maxWorksheets;n!==null&&t.worksheets.length>=n&&u(`worksheets`);let r={...J$(N().xKey||`ET`),name:e};return i.set(e=>({...e,worksheets:[...e.worksheets,r],activeWorksheetId:r.id})),r.id},rename(e,t){l(),N(e),F(e,e=>e.name===t?e:{...e,name:t})},remove(e){l();let t=d();if(N(e),t.worksheets.length<=1)throw new kE(`invalid_argument`,{reason:`the last worksheet cannot be removed`});let n=t.worksheets.findIndex(t=>t.id===e),r=t.worksheets.filter(t=>t.id!==e);i.set(t=>({...t,worksheets:r,activeWorksheetId:t.activeWorksheetId===e?r[Math.max(0,n-1)].id:t.activeWorksheetId}))},reorder(e,t){l(),i.set(n=>{if(e===t||e<0||t<0||e>=n.worksheets.length||t>=n.worksheets.length)return n;let r=[...n.worksheets],[i]=r.splice(e,1);return r.splice(t,0,i),{...n,worksheets:r}})},activate(e){l(),N(e),i.set(t=>t.activeWorksheetId===e?t:{...t,activeWorksheetId:e,xRanges:{...t.xRanges,[e]:null}})},setXKey(e,t){l(),N(e),F(e,e=>e1({...e,xKey:t},e=>e!==t)),i.set(t=>({...t,xRanges:{...t.xRanges,[e]:null},offsets:{}}))}},ge={mount(e,t,n){return l(),VZ(nt,e,t,n)},openWindow(e,t){return l(),P(e),dQ(nt,e,(t,n)=>VZ(nt,e,t,n),t)},setFonts(e){e.sans&&(Q.sans=e.sans),e.mono&&(Q.mono=e.mono),HZ(nt)},kinds:()=>MQ,label:PQ,add(e,t={}){if(l(),!MQ.some(t=>t.kind===e))throw new kE(`invalid_argument`,{kind:e});let n=N(t.worksheetId),r=d().limits.maxChartsPerWorksheet;r!==null&&n.panels.length>=r&&u(`charts-per-worksheet`);let i={...Xt(e,n.panels),...t.title?{title:t.title}:{}};t.layout&&(i.rect={...t.layout});let a=ir([i],{},q$[2],4)[i.id],o=a,s=m().numericColumns;if(s.length&&(o.kind===`multiband`||o.kind===`xyscatter`||o.kind===`xyzmesh`)&&(o=$$({...n,panels:[i],panelChartSettings:{[i.id]:o}},s).panelChartSettings[i.id],o.kind===`multiband`&&(o={...o,addColumn:s.find(e=>e!==n.xKey)??s[0]})),t.settings&&(o={...o,...t.settings,kind:o.kind}),s.length&&o.kind===`xyscatter`){let e=t.settings??{};o={...o,xyXScale:e.xyXScale??pe(o.xyXCol,n.xKey,o.xyXScale),xyYScale:e.xyYScale??pe(o.xyYCol,n.xKey,o.xyYScale)}}return f(a,o),F(n.id,e=>({...e,panels:t.layout?[...e.panels,i]:Qt([...e.panels,i]),panelChartSettings:{...e.panelChartSettings,[i.id]:o}})),i.id},remove(e){l();let{ws:t}=P(e);F(t.id,t=>{let n={...t.panelChartSettings},r={...t.panelChartBackgrounds};return delete n[e],delete r[e],{...t,panels:Qt(t.panels.filter(t=>t.id!==e)),panelChartSettings:n,panelChartBackgrounds:r}})},rename(e,t){l();let{ws:n}=P(e),r=t?.trim()||void 0;F(n.id,t=>({...t,panels:t.panels.map(t=>{if(t.id!==e)return t;let{title:n,...i}=t;return r?{...i,title:r}:i})}))},update(e,t){l();let{ws:n}=P(e),r=n.panelChartSettings[e],i={...r,...t,kind:r.kind};if(r.kind===`xyscatter`&&i.kind===`xyscatter`){let e=t;typeof e.xyXCol==`string`&&e.xyXCol!==r.xyXCol&&!(`xyXScale`in e)&&(i={...i,xyXScale:pe(e.xyXCol,n.xKey,r.xyXScale)}),typeof e.xyYCol==`string`&&e.xyYCol!==r.xyYCol&&!(`xyYScale`in e)&&(i={...i,xyYScale:pe(e.xyYCol,n.xKey,r.xyYScale)})}f(r,i),I(e,()=>i)},replaceSettings(e,t){l();let{ws:n,panel:r}=P(e);if(t.kind!==r.kind)throw new kE(`invalid_argument`,{reason:`settings kind mismatch`});f(n.panelChartSettings[e],t),I(e,()=>t)},setBackground(e,t){l();let{ws:n}=P(e);F(n.id,n=>({...n,panelChartBackgrounds:{...n.panelChartBackgrounds,[e]:t}}))},addAnnotation(e,t){l(),P(e);let n=Nt({...t,id:t.id||crypto.randomUUID()});if(!n)throw new kE(`invalid_argument`,{reason:`not a valid annotation`});return I(e,e=>({...e,annotations:[...(e.annotations??[]).filter(e=>e.id!==n.id),n]})),n.id},updateAnnotation(e,t,n){l();let r=(P(e).ws.panelChartSettings[e]?.annotations??[]).find(e=>e.id===t);if(!r)throw new kE(`not_found`,{annotationId:t});let i=Nt({...r,...n,id:r.id,kind:r.kind});if(!i)throw new kE(`invalid_argument`,{reason:`not a valid annotation`});I(e,e=>({...e,annotations:(e.annotations??[]).map(e=>e.id===i.id?i:e)}))},removeAnnotation(e,t){l(),P(e),I(e,e=>({...e,annotations:(e.annotations??[]).filter(e=>e.id!==t)}))},setAnnotations(e,t){l(),P(e);let n=Pt(t)??[];I(e,e=>({...e,annotations:n}))},setLayout(e,t){l();let{ws:n}=P(e);F(n.id,n=>({...n,panels:n.panels.map(n=>n.id===e?{...n,rect:{...t}}:n)}))},setLayouts(e,t){l(),F(e,e=>({...e,panels:e.panels.map(e=>t[e.id]?{...e,rect:{...t[e.id]}}:e)}))},autoLayout(e){l(),F(N(e).id,e=>({...e,panels:Qt(e.panels)}))},get(e){let{ws:t,panel:n}=P(e);return h(t,n)},list(e){let t=N(e);return t.panels.map(e=>h(t,e))},async addSeries(e,t){l();let{ws:n}=P(e),r=n.panelChartSettings[e];if(!r||r.kind!==`multiband`)throw new kE(`invalid_argument`,{reason:`not a multiband chart`});let i=d().limits.maxChannelsPerChart;i!==null&&Cz(r)>=i&&u(`channels-per-chart`);let a=m().numericColumns,o=new Set(r.series.map(e=>e.column)),s=t??a.find(e=>e!==n.xKey&&!o.has(e))??a.find(e=>e!==n.xKey)??``;if(!s)return null;let c=sr(),f={id:c,column:s,color:q$[r.series.length%q$.length],bandFromPct:0,bandToPct:100,scaleMin:0,scaleMax:1,yMajorStep:0,yMinorStep:0};return I(e,e=>e.kind===`multiband`?{...e,series:[...e.series,f]}:e),await ge.autoScaleSeries(e,c),c},async updateSeries(e,t,n){l();let{ws:r}=P(e),i=r.panelChartSettings[e],a=i&&i.kind===`multiband`?i.series.find(e=>e.id===t):void 0;if(!a)throw new kE(`not_found`,{seriesId:t});I(e,e=>e.kind===`multiband`?{...e,series:e.series.map(e=>e.id===t?{...e,...n,id:e.id}:e)}:e),n.column&&n.column!==a.column&&n.scaleMin===void 0&&n.scaleMax===void 0&&await ge.autoScaleSeries(e,t)},removeSeries(e,t){l(),I(e,e=>e.kind===`multiband`?{...e,series:e.series.filter(e=>e.id!==t)}:e)},reorderSeries(e,t){l(),I(e,e=>{if(e.kind!==`multiband`)return e;let n=new Map(e.series.map(e=>[e.id,e])),r=t.map(e=>n.get(e)).filter(e=>!!e),i=e.series.filter(e=>!t.includes(e.id));return{...e,series:[...r,...i]}})},async autoScaleSeries(e,t){l();let{ws:r}=P(e),i=r.panelChartSettings[e],a=i&&i.kind===`multiband`?i.series.find(e=>e.id===t):void 0;if(!a)return;let o=await de.columnBounds(a.column);!o||n||I(e,e=>e.kind===`multiband`?{...e,series:e.series.map(e=>e.id===t?{...e,scaleMin:o.min,scaleMax:o.max}:e)}:e)}},_e=new Map,ve={setXRange(e,t){l();let n=N(t).id;i.set(t=>{let r=t.xRanges[n]??null;return r===e||r&&e&&r[0]===e[0]&&r[1]===e[1]?t:{...t,xRanges:{...t.xRanges,[n]:e}}})},resetZoom(e){ve.setXRange(null,e)},setCursorX(e,t){l();let n=N(t).id;(_e.get(n)??null)!==e&&(_e.set(n,e),a.emit(`cursorchange`,{worksheetId:n,x:e}))},cursorX(e){return _e.get(N(e).id)??null},setLiveWindow(e,t){l();let n=N(t);n.liveWindowSeconds!==e&&F(n.id,t=>({...t,liveWindowSeconds:e}))},setSegmentContext(e){l(),i.set(t=>JSON.stringify(t.segmentContext)===JSON.stringify(e)?t:{...t,segmentContext:e})}},ye={save(e){l();let t=e.id??crypto.randomUUID(),[n]=LB([{...e,id:t,parentId:e.parentId??null}].concat(d().cycleRules.filter(e=>e.id!==t))).filter(e=>e.id===t);if(!n)throw new kE(`invalid_argument`,{reason:`not a valid cycle rule (or its parent is missing)`});return i.set(e=>({...e,cycleRules:e.cycleRules.some(e=>e.id===t)?e.cycleRules.map(e=>e.id===t?n:e):[...e.cycleRules,n]})),t},remove(e){l();let t=new Set([e]);for(let e=!0;e;){e=!1;for(let n of d().cycleRules)n.parentId&&t.has(n.parentId)&&!t.has(n.id)&&(t.add(n.id),e=!0)}i.set(e=>({...e,cycleRules:e.cycleRules.filter(e=>!t.has(e.id))}))}},be={create(e){l();let n=d(),r=n.limits.maxMathChannels;r!==null&&n.mathChannels.length>=r&&u(`math-channels`);let o=cr(e);return i.set(e=>({...e,mathChannels:[...e.mathChannels,o]})),Promise.resolve(t.mathChannels?.create(o)).catch(e=>a.emit(`error`,{error:e,context:`mathChannels.create`})),o},update(e,n){l();let r=d().mathChannels.find(t=>t.id===e);if(!r)throw new kE(`not_found`,{channelId:e});i.set(t=>({...t,mathChannels:t.mathChannels.map(t=>t.id===e?{...t,...n,updatedAt:Date.now()}:t)})),r.source!==`workbook`&&Promise.resolve(t.mathChannels?.update(e,n)).catch(e=>a.emit(`error`,{error:e,context:`mathChannels.update`}))},remove(e){l();let n=d().mathChannels.find(t=>t.id===e);if(!n)throw new kE(`not_found`,{channelId:e});i.set(t=>({...t,mathChannels:t.mathChannels.filter(t=>t.id!==e)})),n.source!==`workbook`&&Promise.resolve(t.mathChannels?.remove(e)).catch(e=>a.emit(`error`,{error:e,context:`mathChannels.remove`}))},async importFile(e){l();let{channels:n,errors:r}=await TE(e),a=d(),o=a.limits.maxMathChannels===null?n.length:Math.max(0,a.limits.maxMathChannels-a.mathChannels.length);n.length>0&&o===0&&u(`math-channels`);let s=n.slice(0,o);return i.set(e=>({...e,mathChannels:[...e.mathChannels,...s]})),await t.mathChannels?.importMany(s),{channels:s,errors:r}},async importMany(e){l();let n=d(),r=n.limits.maxMathChannels===null?e.length:Math.max(0,n.limits.maxMathChannels-n.mathChannels.length);e.length>0&&r===0&&u(`math-channels`);let a=e.slice(0,r);return i.set(e=>({...e,mathChannels:[...e.mathChannels,...a]})),await t.mathChannels?.importMany(a),a},exportBlob:()=>CE(d().mathChannels),preview(e,t){let n=m();return n.merged?rE(e,n.merged,N(t).xKey,n.channels.filter(t=>t.id!==e.id)):null},sync(e){l(),i.set(t=>{let n=t.mathChannels.filter(e=>e.source===`workbook`),r=n.length?[...e,...n]:e;return t.mathChannels===r?t:{...t,mathChannels:r}})}},xe=AQ((e,t)=>[...e.flatMap(e=>e.kind===`camera`&&e.video?[DE({...e,video:e.video})]:[]),...t]),Se=``;i.subscribe(()=>{let e=xe(d().live,d().video),t=e.map(e=>`${e.kind}:${e.id}:${e.recordingId??``}:${e.name}`).join(`|`);t!==Se&&(Se=t,a.emit(`videochange`,{sources:e}))});let Ce=(e,t,n)=>e.id===t&&(n===void 0||(e.recordingId??null)===n),we={sources:()=>xe(d().live,d().video),register(e){l(),i.set(t=>({...t,video:[...t.video.filter(t=>!Ce(t,e.id,e.recordingId??null)),e]}))},unregister(e,t){l(),i.set(n=>n.video.some(n=>Ce(n,e,t))?{...n,video:n.video.filter(n=>!Ce(n,e,t))}:n)}},Te={openLocal(e,t){return l(),z.openLocal(e,t)},async connect(e,t,n){l(),await z.connect(e,t,n)},startRecording(e){l(),z.startRecording(e)},stopRecording(e){return l(),z.stopRecording(e)},setSegmentAxis(e,t){l(),z.setSegmentAxis(e,t)},rowCount(e){return z.connections().find(t=>t.id===e)?.source.size()??0},disconnect(e){l(),z.disconnect(e),L(d().selection.filter(t=>t!==e))}},Ee=()=>{d().limits.canImportExportWorkspaces||u(`workspaces-io`)},De=async e=>{if(e instanceof Blob)try{return JSON.parse(await e.text())}catch{throw new kE(`bad_file`)}if(typeof e==`string`)try{return JSON.parse(e)}catch{throw new kE(`bad_file`)}return e},Oe=async e=>e instanceof File?e:new File([JSON.stringify(await De(e))],`import.json`,{type:`application/json`}),ke=e=>e.replace(/[^\w.-]+/g,`_`),Ae=e=>new Blob([JSON.stringify(e,null,2)],{type:`application/json`}),je=e=>{let t=rr(e.panelChartSettings,q$[2],4),n={};for(let r of e.panels)t[r.id]?.kind===r.kind&&(n[r.id]=t[r.id]);return{...e,panelChartSettings:ir(e.panels,n,q$[2],4)}},Me=(e,t)=>e.map(e=>{let n=e=>{let n=t.has(e)?crypto.randomUUID():e;return t.add(n),n},r=new Map(e.panels.map(e=>[e.id,n(e.id)])),i=e=>Object.fromEntries(Object.entries(e).map(([e,t])=>[r.get(e)??e,t]));return{...e,id:n(e.id),panels:e.panels.map(e=>({...e,id:r.get(e.id)})),panelChartSettings:i(e.panelChartSettings),panelChartBackgrounds:i(e.panelChartBackgrounds??{})}}),Ne=()=>new Set(d().worksheets.flatMap(e=>[e.id,...e.panels.map(e=>e.id)])),Pe=(e,t=0)=>{let n=d().limits.maxWorksheets,r=Me((n===null?e:e.slice(0,Math.max(1,n))).map(je),new Set),a=r[Math.min(t,r.length-1)];i.set(e=>({...e,worksheets:r,activeWorksheetId:a.id,xRanges:{}}))},Fe=(e,t)=>{let n=N(t),r=d().limits.maxChartsPerWorksheet;r!==null&&n.panels.length>=r&&u(`charts-per-worksheet`);let i=d().limits.maxChannelsPerChart;i!==null&&Cz(e.settings)>i&&u(`channels-per-chart`);let a=crypto.randomUUID(),o={id:a,kind:e.kind,rect:{x:0,y:0,w:6,h:24},...e.title?{title:e.title}:{}};return F(n.id,t=>({...t,panels:Qt([...t.panels,o]),panelChartSettings:{...t.panelChartSettings,[a]:e.settings},panelChartBackgrounds:e.background===null?t.panelChartBackgrounds:{...t.panelChartBackgrounds,[a]:e.background}})),a},Ie=()=>{let e=d();return cV({worksheets:e.worksheets,activeWorksheetId:e.activeWorksheetId,channels:te(p(e.mathChannels,e.limits.maxMathChannels),e.worksheets),liveWindowSeconds:e.liveWindowSeconds,laps:e.datasets.find(e=>e.beacon)?.beacon??null,segments:e.segmentContext,cycles:e.cycleRules})},Le=e=>{if(e.worksheets.length===0)throw new kE(`bad_workspace`,{errors:e.errors});let{channels:t,rename:n}=Y$(d().mathChannels,e.mathChannels);Pe(n.size?e.worksheets.map(e=>X$(e,n)):e.worksheets,e.activeIndex),i.set(n=>({...n,mathChannels:[...n.mathChannels.filter(e=>e.source!==`workbook`),...t],liveWindowSeconds:e.liveWindowSeconds===void 0?n.liveWindowSeconds:e.liveWindowSeconds,segmentContext:e.segments??null,cycleRules:e.cycles}));let r=e.laps;if(r)for(let e of d().datasets)e.kind!==`memory`||e.beacon||!e.data.columnNames.includes(r.channel)||de.configure(e.id,{beacon:r}).catch(e=>a.emit(`error`,{error:e,context:`io.openWorkbook`}));return{worksheets:e.worksheets.length,errors:e.errors}},Re=e=>{if(e===null)return;let t=m().numericColumns,n=t.length?e.worksheets.map(e=>$$(e,t)):e.worksheets;S=!0;try{i.set(t=>{let r=t=>e.worksheets.some(e=>e.id===t);return{...t,worksheets:n,activeWorksheetId:r(t.activeWorksheetId)?t.activeWorksheetId:r(e.activeWorksheetId)?e.activeWorksheetId:e.worksheets[0].id,xRanges:Object.fromEntries(Object.entries(t.xRanges).filter(([e])=>r(e))),mathChannels:[...t.mathChannels.filter(e=>e.source!==`workbook`),...e.channels],liveWindowSeconds:e.liveWindowSeconds}})}finally{S=!1}E=T(d()),x.rebase(D()),O()},Be={undo(){l(),Re(x.undo())},redo(){l(),Re(x.redo())},clear(){l(),A()}},Ve={hasWork:()=>yV(d().worksheets),exportWorksheet(e){l(),Ee();let t=N(e),n=lV(t);return{json:n,blob:Ae(n),filename:`${ke(t.name||`worksheet`)}.json`}},exportChart(e){l(),Ee();let{ws:t,panel:n}=P(e),r=uV(n,t.panelChartSettings[e],t.panelChartBackgrounds[e]??null);return{json:r,blob:Ae(r),filename:`${ke(n.title?.trim()||n.kind)}.json`}},parseFile:e=>SV(e),exportWorkspace(){l(),Ee();let e=Ie();return{json:e,blob:Ae(e),filename:`kymoscope-workspace-${new Date().toISOString().slice(0,10)}.json`}},async exportWorkspaceEncrypted(e){l(),Ee();let t=typeof e==`string`?await QB(Ie(),e):await $B(Ie(),e);return{json:t,blob:Ae(t),filename:`kymoscope-workbook-${new Date().toISOString().slice(0,10)}.kymo`}},async importWorkspace(e,t={}){l(),Ee();let n=await De(e);return eV(n)&&(n=await rV(n,t)),j(()=>Le(vV(n)))},toWorkbook:Ie,openWorkbook(e){return l(),j(()=>Le(vV(e)))},async importWorksheet(e){l(),Ee();let t=d();t.limits.maxWorksheets!==null&&t.worksheets.length>=t.limits.maxWorksheets&&u(`worksheets`);let n=await SV(await Oe(e));if(n.type!==`worksheet`)throw new kE(`bad_file`,{found:n.type});let[r]=Me([je(n.worksheet)],Ne());return i.set(e=>({...e,worksheets:[...e.worksheets,r],activeWorksheetId:r.id})),r.id},async importChart(e,t){l(),Ee();let n=await SV(await Oe(e));if(n.type!==`chart`)throw new kE(`bad_file`,{found:n.type});return Fe(n.chart,t)},snapshot(){let e=d();return{datasets:e.datasets,worksheets:e.worksheets,activeWorksheetId:e.activeWorksheetId,selection:e.selection}},restore(e){l();let t=new Set(e.datasets);for(let e of d().datasets)t.has(e)||e.source.dispose().catch(()=>void 0);let n=e.worksheets.length?e.worksheets.map(je):[J$()];j(()=>i.set(t=>({...t,datasets:e.datasets,worksheets:n,activeWorksheetId:n.some(t=>t.id===e.activeWorksheetId)?e.activeWorksheetId:n[0].id,selection:e.selection,xRanges:{},offsets:{},colors:{}})))},reset(){l(),j(()=>{oe(d().datasets.map(e=>e.id));let e=J$();i.set(t=>({...t,worksheets:[e],activeWorksheetId:e.id,xRanges:{},offsets:{},colors:{},mathChannels:t.mathChannels.filter(e=>e.source!==`workbook`)}))})}},He={merged(e){let t=m();if(!t.merged||t.channels.length===0)return t.merged;let n=xE(t.merged,t.channels,N(e).xKey);return{...t.merged,columnNames:[...t.merged.columnNames,...n.ok.map(e=>e.name)],units:[...t.merged.units,...n.ok.map(e=>e.units)],rows:n.rows}},plotted(){return m().merged}},Ue=typeof location<`u`?location.hostname:``,We=t.license,Ge=t.licenseKey,Ke=!1,Je={},Ye=e=>{n||i.set(t=>({...t,licensed:e}))},Xe=(e,t,n)=>{clearTimeout(Je[e]);let r=Math.max(0,t-Date.now()),i=r>2**31-1;Je[e]=setTimeout(()=>{i?Xe(e,t,n):n()},i?2**31-1:r)},Ze=e=>Xe(`renew`,e,()=>void $e()),Qe=e=>Xe(`expiry`,e*1e3+1e3,()=>{FV(Ge,Ue).then(e=>{n||Ye(e.ok)})});async function $e(){let e=36e5,t,r=null,i;try{t=await Promise.race([We.get(),new Promise((e,t)=>{i=setTimeout(()=>t(Error(`timeout`)),3e4)})]),r=await FV(t,Ue)}catch{}finally{clearTimeout(i)}if(n)return!1;if(r?.ok)return Ge=t,Ke=!0,Ye(!0),Qe(r.exp),Ze(Math.max(r.exp*1e3-168*e,Date.now()+e)),!0;console.warn(`[kymoscope] license renewal failed (${r?r.reason:`license.get failed or timed out`}): keeping the current key`);let a=await FV(Ge,Ue);return n?!1:(Ye(a.ok),Ze(Date.now()+e),a.ok)}let et=!We||t.licenseKey?FV(t.licenseKey,Ue).then(e=>(e.ok||console.warn(`[kymoscope] license ${e.reason}: showing attribution`),!Ke&&!n&&(Ye(e.ok),e.ok&&We&&Qe(e.exp)),e.ok)):null,tt=We?$e():et;S=!1,A();let nt={getState:M,subscribe(e){return i.subscribe(e)},on:a.on,licensed:tt,isLicensed:()=>d().licensed,setOptions(e){if(l(),t={...t,...e},e.live&&z.setRelay(e.live.relay),e.palette&&o(),e.limits){let t={...d().limits,...e.limits};i.set(e=>{let n=t.maxWorksheets===null?e.worksheets:e.worksheets.slice(0,Math.max(1,t.maxWorksheets)),r=n.some(t=>t.id===e.activeWorksheetId)?e.activeWorksheetId:n[0].id;return{...e,limits:t,activeWorksheetId:r}})}},datasets:de,folders:me,worksheets:he,charts:ge,view:ve,mathChannels:be,cycles:ye,live:Te,video:we,io:Ve,history:Be,data:He,alerts:{setRules:e=>{l();let t=ce.setRules(e);return i.set(e=>({...e,alertRules:ce.rules()})),t},rules:ce.rules,state:ce.state,evaluate:(e,t)=>(l(),ce.evaluate(e,t)),clearMarks:ce.clearMarks},marks:{list:()=>d().marks},dispose(){if(!n){n=!0,clearTimeout(Je.renew),clearTimeout(Je.expiry),s(),fQ(nt),UZ(nt),z.dispose();for(let e of d().datasets)e.source.dispose().catch(()=>void 0);a.emit(`dispose`,void 0),a.clear()}}};return r1.set(nt,{store:i,derived:m,live:z,alertLines:()=>le(d().alertRules,d().alerts)}),nt}var r1=new WeakMap;function i1(e){let t=r1.get(e);if(!t)throw new kE(`invalid_argument`,{reason:`not a Kymoscope engine`});return t}var a1=2e3,o1=3;function s1(e){let t=e[0].v.fragCount,n=new Map;for(let r of e)r.v.fragCount===t&&!n.has(r.v.fragIndex)&&n.set(r.v.fragIndex,r);let r=[];for(let e=0;e<t;e++){let t=n.get(e);if(!t)return null;r.push(t.v.payload)}let i=n.get(0),a=r[0];if(t>1){a=new Uint8Array(r.reduce((e,t)=>e+t.length,0));for(let e=0,n=0;e<t;e++)a.set(r[e],n),n+=r[e].length}return{t:i.v.t,seq:i.v.seq,key:i.v.key,data:a,arrivedAt:i.at}}function c1(e){let t=[],n=0;for(;n<e.length&&e[n].v.fragIndex>0&&e[n].v.seq===e[0].v.seq;)t.push(e[n++]);let r=[],i=[],a=[];for(;n<=e.length;n++){let t=e[n];if(a.length&&(!t||t.v.seq!==a[0].v.seq)){let e=s1(a);e?r.push(e):t||(i=a),a=[]}t&&a.push(t)}return{head:t,units:r,tail:i}}var l1=class{kind=`recorded`;id;name;parentId;parentName;recordingId;chunks;fetch;open;maxBytes;cache=new Map;sizes=new Map;bytes=0;width=0;height=0;codec=``;waiting=null;constructor(e){this.id=e.id,this.name=e.name,this.parentId=e.parentId,this.parentName=e.parentName??null,this.recordingId=e.recordingId,this.chunks=[...e.chunks].sort((e,t)=>e.seq-t.seq),this.fetch=e.fetchChunk,this.open=e.open,this.maxBytes=e.maxBytes??256*1024*1024}async parse(e){let t=new Uint8Array(await this.fetch(this.chunks[e].seq)),n=[];for(let e of ae(t).messages){let t=null;try{t=await ye(this.open,e.bytes.slice().buffer)}catch{}if(t?.kind!==6)continue;let r=YQ(t.plaintext);r&&(r.key&&r.fragIndex===0&&!this.codec&&(this.codec=r.codec,this.width=r.width,this.height=r.height),n.push({v:r,at:e.at}))}let r=c1(n),i=e=>e.reduce((e,t)=>e+t.v.payload.length,0);return{...r,bytes:r.units.reduce((e,t)=>e+t.data.length,0)+i(r.head)+i(r.tail)}}parsed(e){let t=this.cache.get(e);if(t)return this.cache.delete(e),this.cache.set(e,t),t;let n=this.parse(e);return this.cache.set(e,n),n.then(t=>{this.cache.get(e)===n&&(this.sizes.set(e,[t.bytes,t.units.length]),this.bytes+=t.bytes,this.evict(e))},()=>{this.cache.get(e)===n&&this.cache.delete(e)}),n}evict(e){for(let t of this.cache.keys()){if(this.bytes<=this.maxBytes)return;let n=this.sizes.get(t);t===e||!n||(this.bytes-=n[0],this.sizes.delete(t),this.cache.delete(t))}}async units(e){let t;try{t=await this.parsed(e)}catch{return[]}if(t.full)return t.full;if(!t.tail.length||e+1>=this.chunks.length)return t.full=t.units;let n=await this.parsed(e+1).catch(()=>null);if(!n)return t.units;let r=null;try{r=s1([...t.tail,...n.head.filter(e=>e.v.seq===t.tail[0].v.seq)])}catch{}return t.full=r?[...t.units,r]:t.units}async seekPlan(e){let t=this.chunks.length;if(!t)return[];let n=e*1e3,r=0;for(;r+1<t&&this.chunks[r+1].t0<=n;)r++;let i=r,a=r+1<t&&this.chunks[r+1].t0-n<a1?r+1:r,o=(await Promise.all(Array.from({length:a-i+1},(e,t)=>this.units(i+t)))).flat(),s=()=>{let t=o.length-1;for(;t>=0&&o[t].t>e;)t--;let n=t;for(;n>=0&&!o[n].key;)n--;return[n,t]},[c,l]=s();for(let e=0;c<0&&i>0&&e<o1;e++)o=[...await this.units(--i),...o],[c,l]=s();return a+1<t&&this.units(a+1),c<0?[]:o.slice(c,l+1)}ready(){return this.waiting??=(async()=>{for(let e=0;e<Math.min(this.chunks.length,o1+1)&&!this.codec;e++)await this.units(e);this.codec||(this.waiting=null)})()}info(){let e=0;for(let[,t]of this.sizes.values())e+=t;return{width:this.width,height:this.height,codec:this.codec,latestT:this.range()?.[1]??null,lagMs:null,units:e,bytes:this.bytes}}range(){let e=this.chunks.length;return e?[this.chunks[0].t0/1e3,this.chunks[e-1].t1/1e3]:null}},u1=1e4,d1=72e4,f1=3e5,p1=3e4,m1=1e4,h1=1e4,g1=64*1024,_1=50,v1=class extends Error{status;code;detail;constructor(e,t,n){super(`${n} (${t})`),this.status=e,this.code=t,this.detail=n}},y1=e=>Uint8Array.from(atob(e),e=>e.charCodeAt(0)),b1=class{opts;deps;auth;secret;password;token=``;ticket=``;ticketRec=!1;authRec=!1;relayUrl=null;apiKeyId=null;projectId=null;e2ee=!1;sid=null;salt=``;key=null;raw=null;epoch=0;haveKey=!1;sealed=null;device=null;senderDeviceId=null;deviceRetried=!1;maxBytesPerSec=0;maxMessageBytes=g1;ws=null;open=!1;everOpen=!1;connectedAt=0;authAt=0;delay=1e3;lastToken=0;viewerCount=0;busy=!1;stopped=!1;refusal=null;heartbeatTimer=null;pingTimer=null;retryTimer=null;statusFns=new Set;viewerFns=new Set;lastStatus=``;constructor(e,t){let{auth:n,secret:r}=ue(e.apiKey);if(!r)throw Error(`This API key has no encryption secret (created before keys carried one). Create a new API key in Kymoscope.`);if(e.kind===`camera`&&!e.parentStreamId)throw Error(`A camera is added to one of your live streams: choose its stream (parentStreamId).`);if(!!e.layer!=!!e.lowOf)throw Error(`A low layer needs both layer: 'low' and lowOf (its high camera's stream id).`);if(e.layer&&e.kind!==`camera`)throw Error(`Only a camera has a low layer.`);if(e.visibility===`open`&&e.password)throw Error(`An open stream has no password: anyone may watch it. Remove the password, or use visibility 'private'.`);this.opts=e,this.deps=t,this.auth=n,this.secret=r,this.password=e.visibility===`open`?Ce:e.password||r}get streamId(){return this.sid}get viewers(){return this.viewerCount}get limits(){return{maxBytesPerSec:this.maxBytesPerSec,maxMessageBytes:this.maxMessageBytes}}onStatus(e){return this.statusFns.add(e),()=>{this.statusFns.delete(e)}}onViewers(e){return this.viewerFns.add(e),()=>{this.viewerFns.delete(e)}}async start(){this.emit();try{let e=await this.deps.store.load();this.salt=e?.salt??L();let t=await this.mint();this.token=t.token,this.relayUrl=t.relayUrl??null,this.maxBytesPerSec=t.maxBytesPerSec||0,this.maxMessageBytes=t.maxMessageBytes||g1,this.apiKeyId=t.apiKeyId??null;let n=t.project;this.e2ee=!!n?.e2ee;let r={};if(this.e2ee){this.projectId=n?.id??null;let t=e?.apiKeyId===this.apiKeyId;this.device=t&&e?.device||await Qe(),t&&e?.streamKey?{key:this.key,epoch:this.epoch,sealed:this.sealed}=e.streamKey:this.key=await z(O()),r.sender_device=await this.senderDevice()}else this.raw=y1(await _(this.password,this.salt)),this.key=await z(this.raw);let i=await this.register(e?.streamId??null,r);if(this.sid=i.stream.id,this.ticket=i.ticket,this.ticketRec=!!i.recording,this.e2ee?(this.senderDeviceId=i.sender_device_id??null,this.projectId=i.project?.id??this.projectId,await this.save(),await this.applyProject(i.project)):(await this.save(),await this.wrapFor(i.devices)),!this.relayUrl)throw Error(`stream-token returned no relayUrl`)}catch(e){throw e instanceof v1&&e.status>=400&&e.status<500&&this.refuse(e),e}this.stopped||(this.lastToken=this.deps.now(),this.connect(),this.heartbeatTimer=setInterval(()=>{this.housekeeping()},u1),this.emit())}async send(e,t){let n=this.key,r=this.e2ee?this.epoch&255:void 0;if(this.stopped||!this.open||!n||this.e2ee&&!this.haveKey)return!1;let i=await _e(n,e,t,r),a=this.ws;if(!this.open||!a)return!1;try{return a.send(i),!0}catch{return!1}}stop(){this.stopped=!0,this.heartbeatTimer&&clearInterval(this.heartbeatTimer),this.retryTimer&&clearTimeout(this.retryTimer),this.heartbeatTimer=this.retryTimer=null;let e=this.ws;if(this.disconnect(),e){e.onopen=e.onmessage=e.onclose=null;try{e.close(1e3)}catch{}}}async post(e,t,n){let r;try{r=await this.deps.fetch(`${this.opts.supabaseUrl.replace(/\/+$/,``)}/functions/v1/${e}`,{method:`POST`,headers:t,body:n===void 0?void 0:JSON.stringify(n)})}catch(e){throw new v1(0,`network`,e?.message??String(e))}let i=await r.text(),a=null;try{a=JSON.parse(i)}catch{}if(r.status!==200)throw new v1(r.status,a?.error??`error`,a?.message??a?.error??i);return a}mint(){return this.post(`stream-token`,{"x-api-key":this.auth})}call(e){return this.post(`stream-publisher`,{Authorization:`Bearer ${this.token}`,"Content-Type":`application/json`},e)}async register(e,t){let n={action:`register`,name:this.opts.name,salt:this.salt,key_check:await p(this.key),visibility:this.opts.visibility??`private`,kind:this.opts.kind,...t};return this.opts.kind===`camera`&&(n.parent_stream_id=this.opts.parentStreamId),this.opts.layer&&(n.layer=this.opts.layer,n.low_of=this.opts.lowOf),e&&(n.stream_id=e),this.call(n)}async senderDevice(){let e=this.device.publicKey;return{public_key:e,binding:await He(await Fe(this.secret),this.apiKeyId??``,e)}}async housekeeping(){if(!(this.busy||this.stopped)){this.busy=!0;try{let e=this.deps.now();if(e-this.lastToken>=d1){this.lastToken=e;try{this.token=(await this.mint()).token}catch{return}}if(this.e2ee){let e=await this.call({action:`heartbeat`,stream_id:this.sid,sender_device_id:this.senderDeviceId,epoch:this.haveKey?this.epoch:0});this.setTicket(e.ticket,!!e.recording),await this.applyProject(e.project)}else{let e=await this.call({action:`heartbeat`,stream_id:this.sid});this.setTicket(e.ticket,!!e.recording),await this.wrapFor(e.devices)}}catch(e){e instanceof v1&&(e.status===401||e.status===403)&&this.refuse(e)}finally{this.busy=!1}}}async wrapFor(e){let t=[];for(let n of e??[])try{t.push({device_id:n.id,wrapped:await ve(n.public_key,this.raw,`${this.sid}|${n.id}`)})}catch{}if(t.length)try{await this.call({action:`wrap_keys`,stream_id:this.sid,keys:t.slice(0,_1)})}catch{}}async applyProject(e){if(!this.e2ee||!e)return;let t=e.key;if(!t){this.emit();return}let n=Number(t.epoch);if(this.haveKey&&n<=this.epoch)return;let r;try{r=await Ke(this.device.privateKey,t.wrapped,ne(this.projectId,n,this.senderDeviceId))}catch{if(this.deviceRetried)return;this.deviceRetried=!0,this.device=await Qe(),await this.reregister();return}let i=Oe(this.sid,this.projectId,n),a=this.key,o=n===this.epoch?this.sealed:null;if(o)try{await b(r,o,i)}catch{o=null}if(!o){let e=O();a=await z(e),o=await Ve(r,e,i),e.fill(0)}try{await this.call({action:`wrap_keys`,stream_id:this.sid,sender_device_id:this.senderDeviceId,project_wrap:{epoch:n,iv:o.iv,ct:o.ct}})}catch{return}this.stopped||(this.key=a,this.sealed=o,this.epoch=n,this.haveKey=!0,await this.save(),this.emit())}async reregister(){let e;try{e=await this.register(this.sid,{sender_device:await this.senderDevice()})}catch{return}this.ticket=e.ticket,this.ticketRec=!!e.recording,this.senderDeviceId=e.sender_device_id??null;let t=e.stream.id;if(t!==this.sid){this.sid=t;let e=this.ws;if(e){this.disconnect(),e.onopen=e.onmessage=e.onclose=null;try{e.close(1e3)}catch{}this.connect()}}await this.save(),await this.applyProject(e.project),this.deviceRetried=!1}async save(){try{await this.deps.store.save({apiKeyId:this.apiKeyId,streamId:this.sid,salt:this.salt,device:this.e2ee?this.device:null,streamKey:this.e2ee&&this.haveKey?{epoch:this.epoch,key:this.key,sealed:this.sealed}:null})}catch{}}connect(){if(this.retryTimer=null,this.stopped)return;let e=this.relayUrl.replace(/\/+$/,``).replace(/^http(s?):\/\//,`ws$1://`),t;try{t=new this.deps.WebSocket(`${e}/v1/streams/${this.sid}/publish`,[FQ,`bearer.${this.ticket}`])}catch{this.dropped();return}t.binaryType=`arraybuffer`,this.ws=t,t.onopen=()=>{t===this.ws&&(this.open=this.everOpen=!0,this.connectedAt=this.authAt=this.deps.now(),this.authRec=this.ticketRec,this.pingTimer=setInterval(()=>{try{t.send(`ping`)}catch{}},p1),this.emit())},t.onmessage=e=>{if(!(t!==this.ws||typeof e.data!=`string`||!e.data.startsWith(`{`)))try{let t=JSON.parse(e.data);t?.type===`viewers`&&this.setViewers(Number(t.count)||0)}catch{}},t.onclose=()=>{t===this.ws&&this.dropped()}}disconnect(){this.ws=null,this.open=!1,this.pingTimer&&clearInterval(this.pingTimer),this.pingTimer=null,this.setViewers(0)}dropped(){let e=this.open&&this.deps.now()-this.connectedAt>=h1;if(this.disconnect(),this.stopped)return;let t=0;e?this.delay=1e3:(t=this.delay,this.delay=Math.min(this.delay*2,m1)),this.retryTimer=setTimeout(()=>this.connect(),t),this.emit()}setTicket(e,t){this.ticket=e,this.ticketRec=t;let n=this.deps.now();if(t||(this.authRec=!1),!(!this.open||!this.ws)&&!(n-this.authAt<f1&&!(t&&!this.authRec)))try{this.ws.send(JSON.stringify({type:`auth`,token:e})),this.authAt=n,this.authRec=t}catch{}}setViewers(e){if(e!==this.viewerCount){this.viewerCount=e;for(let t of this.viewerFns)t(e);this.emit()}}refuse(e){this.refusal={code:e.code,message:e.detail},this.emit(),this.stop()}status(){return this.refusal?{phase:`refused`,...this.refusal}:this.sid?this.e2ee&&!this.haveKey?{phase:`waiting_approval`}:this.open?{phase:`live`,viewers:this.viewerCount}:this.everOpen?{phase:`reconnecting`}:{phase:`registering`}:{phase:`registering`}}emit(){let e=this.status(),t=JSON.stringify(e);if(t!==this.lastStatus){this.lastStatus=t;for(let t of this.statusFns)t(e)}}},x1={"720p30":{width:1280,height:720,fps:30,kbps:2e3},"1080p30":{width:1920,height:1080,fps:30,kbps:4e3}},S1={width:640,height:360,fps:15,kbps:400},C1=[`avc1.640028`,`avc1.4d0028`,`avc1.42e028`],w1=[`avc1.64001f`,`avc1.4d001f`,`avc1.42e01f`],T1=2,E1=1e3,D1=1e3;async function*O1(e){if(typeof MediaStreamTrackProcessor<`u`){let t=new MediaStreamTrackProcessor({track:e}).readable.getReader();try{for(;;){let{value:e,done:n}=await t.read();if(n)return;yield e}}finally{t.cancel().catch(()=>{})}}let t=document.createElement(`video`);t.muted=!0,t.playsInline=!0,t.srcObject=new MediaStream([e]),await t.play();try{for(;e.readyState===`live`;)await new Promise(e=>t.requestVideoFrameCallback(()=>e())),yield new VideoFrame(t,{timestamp:Math.round(performance.now()*1e3)})}finally{t.pause(),t.srcObject=null}}function k1(){let e=null;return(t,n,r)=>(e??=new OffscreenCanvas(n,r).getContext(`2d`),e.drawImage(t,0,0,n,r),new VideoFrame(e.canvas,{timestamp:t.timestamp}))}var A1=class{encoder=null;codec=``;error=null;unsubscribe=null;lastKey=-1/0;keyPending=!1;resume=!0;lastViewers=0;encoding=!1;dropped=0;seq=0;times=new Map;window=[];sending=Promise.resolve();publisher;preset;keyframeMs;Encoder;now;constructor(e,t,n,r,i){this.publisher=e,this.preset=t,this.keyframeMs=n,this.Encoder=r,this.now=i}async configure(){let{width:e,height:t,fps:n,kbps:r}=this.preset,i=this.publisher.limits.maxBytesPerSec,a=i>0?Math.min(r*1e3,i*8/1.25):r*1e3,o=null;for(let r of t>720?C1:w1){let i={codec:r,width:e,height:t,bitrate:a,framerate:n,avc:{format:`annexb`},latencyMode:`realtime`,bitrateMode:`constant`};if((await this.Encoder.isConfigSupported(i)).supported===!0){o=i;break}}return o?(this.codec=o.codec,this.encoder=new this.Encoder({output:e=>this.onChunk(e),error:e=>{this.error=e.message||String(e),this.closeEncoder()}}),this.encoder.configure(o),this.lastViewers=this.publisher.viewers,this.unsubscribe=this.publisher.onViewers(e=>{e>this.lastViewers&&(this.keyPending=!0),this.lastViewers=e}),!0):!1}ready(){let e=this.encoder;return this.encoding=!!e&&!this.error&&this.publisher.viewers>0,!e||!this.encoding?(this.resume=!0,!1):e.encodeQueueSize>T1?(this.dropped++,!1):!0}encode(e){let t=this.now(),n=t-this.lastKey,r=this.resume||n>=this.keyframeMs||this.keyPending&&n>=E1;r&&(this.lastKey=t,this.keyPending=this.resume=!1);let i=(performance.timeOrigin+e.timestamp/1e3)/1e3;Math.abs(i-Date.now()/1e3)>60&&(i=Date.now()/1e3),this.times.set(e.timestamp,i),this.encoder.encode(e,{keyFrame:r})}onChunk(e){let t=new Uint8Array(e.byteLength);e.copyTo(t);let n=this.times.get(e.timestamp)??Date.now()/1e3;this.times.delete(e.timestamp);let{width:r,height:i}=this.preset,a=XQ({key:e.type===`key`,t:n,seq:this.seq++,width:r,height:i,codec:this.codec,data:t});for(let e of a)this.sending=this.sending.then(()=>this.publisher.send(6,e)).catch(()=>!1);this.window.push({at:this.now(),bytes:t.length})}get queue(){return this.encoder?.state===`configured`?this.encoder.encodeQueueSize:0}stats(){let e=this.now();for(;this.window.length&&e-this.window[0].at>=D1;)this.window.shift();let t=this.window.reduce((e,t)=>e+t.bytes,0);return{fps:this.window.length,kbps:t*8/1e3,viewers:this.publisher.viewers,encoding:this.encoding}}stop(){this.encoding=!1,this.closeEncoder(),this.unsubscribe?.(),this.unsubscribe=null}closeEncoder(){this.encoder&&this.encoder.state!==`closed`&&this.encoder.close()}},j1=class{high;lowOpt;low=null;lowAt=-1/0;keyframeMs;Encoder;now;frames;scale;stopped=!1;statsFns=new Set;lastStats=-1/0;constructor(e,t,n={}){this.keyframeMs=(t.keyframeS??2)*1e3,this.Encoder=n.VideoEncoder??VideoEncoder,this.now=n.now??Date.now,this.frames=n.frames??O1,this.scale=n.scale??k1(),this.high=new A1(e,t.preset,this.keyframeMs,this.Encoder,this.now),this.lowOpt=t.low?{publisher:t.low.publisher,preset:t.low.preset??S1}:null}async start(e){if(!await this.high.configure())throw new kE(`camera_codec_unsupported`);if(this.lowOpt){let e=new A1(this.lowOpt.publisher,this.lowOpt.preset,this.keyframeMs,this.Encoder,this.now);await e.configure()&&(this.low=e)}this.loop(e)}async loop(e){for await(let t of this.frames(e)){if(this.stopped){t.close();break}try{this.onFrame(t)}finally{t.close()}this.emitStats()}}onFrame(e){this.high.ready()&&this.high.encode(e);let t=this.low;if(!t)return;let n=this.now();if(n-this.lowAt<750/t.preset.fps||!t.ready())return;this.lowAt=n;let r=this.scale(e,t.preset.width,t.preset.height);try{t.encode(r)}finally{r.close()}}stats(){return{...this.high.stats(),dropped:this.high.dropped,queue:this.high.queue,error:this.high.error,low:this.low?this.low.stats():null}}onStats(e){return this.statsFns.add(e),()=>{this.statsFns.delete(e)}}emitStats(){let e=this.now();if(e-this.lastStats<D1||!this.statsFns.size)return;this.lastStats=e;let t=this.stats();for(let e of this.statsFns)e(t)}stop(){this.stopped=!0,this.high.stop(),this.low?.stop()}},M1=class{#e;constructor(e){this.#e=e}head(){let e=this.#e;return`${e.map(e=>r$(e.name)).join(`,`)}\n${e.map(e=>r$(e.unit)).join(`,`)}\n`}append(e){let t=e.columns,n=``;for(let r=0;r<e.length;r++){for(let e=0;e<t.length;e++){let i=t[e][r];n+=(e?`,`:``)+(Number.isNaN(i)?``:String(i))}n+=`
618
618
  `}return n}end(){}},N1=new TextEncoder,P1=e=>e+7&-8,F1=104,I1=64,L1=104,R1=160,z1=4;function B1(e,t,n){let r=24+t.length*8+n.length,i=new Uint8Array(P1(r)),a=new DataView(i.buffer);return i.set(N1.encode(e),0),a.setBigUint64(8,BigInt(r),!0),a.setBigUint64(16,BigInt(t.length),!0),t.forEach((e,t)=>a.setBigUint64(24+t*8,BigInt(e),!0)),i.set(n,24+t.length*8),i}var V1=(e,t)=>B1(e,[],N1.encode(`${t}\0`)),H1=e=>BigInt(Math.round(e))*1000000n,U1=class{#e;#t;#n;#r=0;constructor(e,t,n){this.#e=e,this.#t=t?Date.parse(t):Date.now(),this.#n=n}append(e){let t=e.columns,n=t.length,r=new Float64Array(e.length*n);for(let i=0;i<e.length;i++)for(let e=0;e<n;e++)r[i*n+e]=t[e][i];return this.#r+=e.length,new Uint8Array(r.buffer)}end(){if(this.#r!==this.#n)throw Error(`The recording changed while it was exported (${this.#r} of ${this.#n} rows).`)}head(){let e=this.#e.length,t=[],n=64+F1,r=e=>{let r=n;return t.push(e),n+=e.length,r},i=r(V1(`##MD`,`<FHcomment><TX>Kymoscope cloud recording</TX><tool_id>Kymoscope</tool_id><tool_vendor>Kymoscope</tool_vendor><tool_version>1</tool_version></FHcomment>`)),a=new Uint8Array(16);new DataView(a.buffer).setBigUint64(0,H1(this.#t),!0);let o=r(B1(`##FH`,[0,i],a)),s=this.#e.map(e=>r(V1(`##TX`,e.name))),c=this.#e.map(e=>e.unit?r(V1(`##TX`,e.unit)):0),l=n,u=l+I1,d=this.#e.map((e,t)=>u+L1+t*R1),f=B1(`##DG`,[0,u,u+L1+e*R1,0],new Uint8Array(8)),p=new Uint8Array(32),m=new DataView(p.buffer);m.setBigUint64(8,BigInt(this.#n),!0),m.setUint32(24,e*8,!0);let h=B1(`##CG`,[0,d[0],0,0,0,0],p),g=this.#e.map((t,n)=>{let r=new Uint8Array(72),i=new DataView(r.buffer);return i.setUint8(0,n===0?2:0),i.setUint8(1,+(n===0)),i.setUint8(2,z1),i.setUint32(4,n*8,!0),i.setUint32(8,64,!0),i.setUint8(20,255),B1(`##CN`,[n+1<e?d[n+1]:0,0,s[n],0,0,0,c[n],0],r)}),_=new Uint8Array(24);_.set(N1.encode(`##DT`),0),new DataView(_.buffer).setBigUint64(8,BigInt(24+this.#n*e*8),!0);let v=new Uint8Array(64);v.set(N1.encode(`MDF 4.10 Kymoscop`),0),new DataView(v.buffer).setUint16(28,410,!0);let y=new Uint8Array(32);new DataView(y.buffer).setBigUint64(0,H1(this.#t),!0);let b=[v,B1(`##HD`,[l,o,0,0,0,0],y),...t,f,h,...g,_],x=new Uint8Array(b.reduce((e,t)=>e+t.length,0));return b.reduce((e,t)=>(x.set(t,e),e+t.length),0),x}},W1={csv:`text/csv`,mf4:`application/octet-stream`,parquet:`application/vnd.apache.parquet`};async function G1(e,t,n,r={}){let i=uz(`krc`,{main:new File(e.chunks,`${e.name}.krc`),companions:[],keys:e.keys},r.signal,r.createWorker);try{let e=await i.plan(),a=[{group:0,channels:e.groups[0].channels.map((e,t)=>t)}],o=t===`csv`?new M1(QR(e,a)):new U1(QR(e,a),e.startTime,e.groups[0].samples);await n(o.head()),await i.read(a,`stream`,{chunk:async e=>{await n(o.append(e))},progress:r.onProgress}),o.end()}finally{i.close()}}async function K1(e,t,n={}){let r=[];return await G1(e,t,e=>{r.push(e)},n),new Blob(r,{type:W1[t]})}var q1=(e,t)=>`khd1|${e.stream}|${e.day}|${e.kind}|${e.level}|${t}`;function J1(e){if(e.length<9)throw Error(`Not a Kymoscope day file (too short)`);let t=e.subarray(e.length-9);if(String.fromCharCode(t[5],t[6],t[7],t[8])!==`KHD1`)throw Error(`Not a Kymoscope day file`);if(t[4]!==1)throw Error(`Unknown Kymoscope day file format ${t[4]}`);return new DataView(t.buffer,t.byteOffset,4).getUint32(0,!0)}var Y1=new TextEncoder;async function X1(e,t,n,r){let i=await crypto.subtle.decrypt({name:`AES-GCM`,iv:t.subarray(0,12),additionalData:Y1.encode(q1(n,r))},e,t.subarray(12));return new Uint8Array(i)}async function Z1(e,t,n){let r=JSON.parse(new TextDecoder().decode(le(await X1(e,t,n,`footer`))));if(r.format!==1||r.stream!==n.stream||r.day!==n.day||r.kind!==n.kind||r.level!==n.level)throw Error(`This day file belongs to another history or day`);return r}var Q1=0;async function $1(e,t){let n=await zL(),r=e.map(()=>`khd_${++Q1}.parquet`),i=[];try{for(let t=0;t<e.length;t++)await n.registerFileBuffer(r[t],e[t]),i.push(r[t]);let a=await n.connect();try{return await t(r,e=>a.query(e))}finally{await a.close()}}finally{for(let e of i)await n.dropFile(e).catch(()=>void 0)}}var e0=(e,t)=>e.getChild(t).toArray();function t0(){$1([],async(e,t)=>{await t(`COPY (SELECT 1::BIGINT AS t) TO 'khd_warm.parquet' (FORMAT parquet)`),await t(`SELECT t FROM read_parquet('khd_warm.parquet')`)}).catch(()=>void 0)}async function n0(e,t){return $1([e],async([e],n)=>{let r=await n(`SELECT (t::DOUBLE / 1e6) AS t${t.map(e=>`, coalesce("c${e}", 'NaN'::FLOAT) AS "c${e}"`).join(``)} FROM read_parquet('${e}') ORDER BY t`);return{t:Float64Array.from(e0(r,`t`)),cols:t.map(e=>Float32Array.from(e0(r,`c${e}`)))}})}async function r0(e){return e.some(e=>e.channels.length)?$1(e.map(e=>e.bytes),async(t,n)=>{let r=await n(`SELECT k, (t::DOUBLE / 1e6) AS t, ch, "min", "max" FROM (${t.flatMap((t,n)=>e[n].channels.length?[`SELECT ${n} AS k, t, ch, "min", "max" FROM read_parquet('${t}') WHERE ch IN (${e[n].channels.join(`,`)})`]:[]).join(` UNION ALL `)}) ORDER BY k, ch, t`),i=e0(r,`k`),a=e0(r,`t`),o=e0(r,`ch`),s=e0(r,`min`),c=e0(r,`max`),l=[];for(let t=0,n=0;t<e.length;t++){let e=n;for(;e<i.length&&i[e]===t;)e++;l.push({t:Float64Array.from({length:e-n},(e,t)=>a[n+t]),ch:Int32Array.from({length:e-n},(e,t)=>o[n+t]),min:Float32Array.from({length:e-n},(e,t)=>s[n+t]),max:Float32Array.from({length:e-n},(e,t)=>c[n+t])}),n=e}return l}):e.map(()=>({t:new Float64Array,ch:new Int32Array,min:new Float32Array,max:new Float32Array}))}var i0=2*1024**3;async function a0(){try{return await(await navigator.storage.getDirectory()).getDirectoryHandle(`kymoscope-history`,{create:!0})}catch{return null}}async function o0(){try{let e=(await navigator.storage.estimate()).quota??0;return e>0?Math.min(i0,e*.2):i0}catch{return i0}}function s0(e=a0,t=o0){let n=null,r=null,i=0,a=()=>n??=e().catch(()=>null),o=e=>e.replace(/[^A-Za-z0-9._-]/g,`_`),s=()=>r??=(async()=>{let e=new Map,t=await a();if(i=0,t)for await(let[n,r]of t.entries()){if(r.kind!==`file`||!r.getFile)continue;let t=await r.getFile();e.set(n,{size:t.size,at:t.lastModified}),i+=t.size}return e})().catch(e=>{throw r=null,e});return{async get(e){try{let t=await a();return t?new Uint8Array(await(await(await t.getFileHandle(o(e))).getFile()).arrayBuffer()):null}catch{return null}},async put(e,n){try{let r=await a();if(!r)return;let c=await s(),l=o(e),u=await(await r.getFileHandle(l,{create:!0})).createWritable();try{await u.write(n),await u.close()}catch(e){throw await u.abort?.().catch(()=>void 0),e}i+=n.length-(c.get(l)?.size??0),c.set(l,{size:n.length,at:Date.now()});let d=await t();if(i<=d)return;for(let[e,t]of[...c].sort((e,t)=>e[1].at-t[1].at)){if(i<=d*.9)break;try{await r.removeEntry(e)}catch{continue}c.delete(e),i-=t.size}}catch{}}}}var c0=16,l0=2e3,u0=512*1024,d0=64*1024,f0=64*1024,p0=8*1024*1024;function m0(e,t=l0){for(let n of[3600,60])if(e/n>=t/2)return n;return 0}var h0={0:[0,60,3600],60:[60,3600,0],3600:[3600,60,0]};function g0(e,t){let n=new Map;for(let t of e)n.set(t.day,[...n.get(t.day)??[],t]);let r=[];for(let[,e]of[...n].sort((e,t)=>e[0].localeCompare(t[0]))){let n=h0[t].map(t=>e.find(e=>e.level===t)).find(Boolean);n&&r.push(n)}return r}async function _0(e,t,n){let r=Array(e.length),i=0;return await Promise.all(Array.from({length:Math.min(t,e.length)},async()=>{for(;i<e.length;){let t=i++;r[t]=await n(e[t])}})),r}function v0(e){let t=[];for(let n of[...e].sort((e,t)=>e.off-t.off)){let e=t[t.length-1];e&&n.off-e.end<=f0&&n.off+n.len-e.start<=p0?e.end=Math.max(e.end,n.off+n.len):t.push({start:n.off,end:n.off+n.len})}return t}var y0=(e,t)=>({stream:e.historyStreamId,day:t.day,kind:t.kind,level:t.level}),b0=(e,t)=>async(n,r,i)=>{let a=t.get(n.id);return a?a.subarray(r,i):(e.signal?.throwIfAborted(),e.fetchRange(n.id,r,i,e.signal))};async function x0(e,t,n=new Map){let r=e.footers?.get(t.id);if(r)return r;let i=await e.cache?.get(`${t.id}/footer`)??null;if(!i){t.bytes<=u0&&n.set(t.id,await e.fetchRange(t.id,0,t.bytes,e.signal));let r=b0(e,n),a=await r(t,Math.max(0,t.bytes-d0),t.bytes),o=J1(a);i=o+9<=a.length?a.slice(a.length-9-o,a.length-9):(await r(t,t.bytes-9-o,t.bytes-9)).slice(),await e.cache?.put(`${t.id}/footer`,i)}let a=await Z1(await e.key(t.keyId),i,y0(e,t));return e.footers?.set(t.id,a),a}var S0=e=>e?.code===`missing`;async function C0(e){let t=async()=>{let t=g0(e.segments,e.level).map(e=>e.id).join(),n=await e.relist();return g0(n,e.level).map(e=>e.id).join()===t?null:n},n,r;try{n=await w0(e)}catch(n){if(!e.relist||e.signal?.aborted||!(r=await t()))throw n;return w0({...e,segments:r})}return!n.missingDays.length||!e.relist||e.signal?.aborted||!(r=await t())?n:w0({...e,segments:r})}async function w0(e){let t=g0(e.segments,e.level),n=new Set(e.channels),r=new Map,i=b0(e,r),a=new Set,o=async(t,n)=>{try{return await n()}catch(n){if(e.onMissing!==`gap`||!S0(n))throw n;return a.add(t.id),null}},s=await _0(t,16,t=>o(t,()=>x0(e,t,r))),c={},l={},u=[];t.forEach((t,r)=>{let i=s[r];if(i){l[t.day]=t.level;for(let e of i.channels)n.has(e.n)&&e.u&&!c[e.n]&&(c[e.n]=e.u);i.blocks.forEach((r,a)=>{if(r.t1<e.t0||r.t0>e.t1)return;let o=r.ch.filter(e=>n.has(i.channels[e].n));o.length&&u.push({s:t,f:i,i:a,chs:o})})}});let d=new Map;await _0(u,16,async t=>{let n=await e.cache?.get(`${t.s.id}/${t.i}`);n&&d.set(t,n)});let f=new Map;for(let e of u)d.has(e)||f.set(e.s.id,[...f.get(e.s.id)??[],e]);await _0([...f.values()].flatMap(e=>v0(e.map(e=>e.f.blocks[e.i])).map(t=>({js:e,r:t}))),16,async({js:t,r:n})=>{let r=await o(t[0].s,()=>i(t[0].s,n.start,n.end));if(r)for(let i of t){let t=i.f.blocks[i.i];if(t.off<n.start||t.off+t.len>n.end)continue;let a=r.slice(t.off-n.start,t.off-n.start+t.len);d.set(i,a),e.cacheWrite!==!1&&await e.cache?.put(`${i.s.id}/${i.i}`,a)}});let p=[],m=[];return await _0(u.filter(e=>!a.has(e.s.id)),16,async t=>{let n=await X1(await e.key(t.s.keyId),d.get(t),y0(e,t.s),t.i);if(t.s.kind===`rollup`){m.push({j:t,plain:n});return}let r=await n0(n,t.chs),i=new Map(t.chs.map((e,n)=>[t.f.channels[e].n,r.cols[n]])),a=hQ({t:r.t,lo:i,hi:i,level:0},e.t0,e.t1);a&&p.push(a)}),(await r0(m.map(e=>({bytes:e.plain,channels:e.j.chs})))).forEach((t,n)=>{let{j:r}=m[n],i=r.s.level/2;for(let n=0;n<t.ch.length;){let a=n;for(;a<t.ch.length&&t.ch[a]===t.ch[n];)a++;let o=r.f.channels[t.ch[n]].n,s=hQ({t:t.t.slice(n,a).map(e=>e+i),lo:new Map([[o,t.min.slice(n,a)]]),hi:new Map([[o,t.max.slice(n,a)]]),level:r.s.level},e.t0,e.t1);s&&p.push(s),n=a}}),{pieces:p.sort((e,t)=>e.t[0]-t.t[0]),units:c,levels:l,missingDays:t.filter(e=>a.has(e.id)).map(e=>e.day)}}var T0=25e6,E0=3e7,D0=1<<20,O0=8192,k0=65536;function A0(e){for(let t=1;t<10;t++){let n=+e.toPrecision(t);if(Math.fround(n)===e)return String(n)}return String(e)}function j0(e){let t=Math.round(e*1e6),n=Math.floor(t/1e6);return`${new Date(n*1e3).toISOString().slice(0,19)}.${String(t-n*1e6).padStart(6,`0`)}Z`}function M0(e,t){let n=e.filter(e=>t.some(t=>e.lo.has(t))).map(e=>e.t),r=new Float64Array(n.reduce((e,t)=>e+t.length,0)),i=0;for(let e of n)r.set(e,i),i+=e.length;r.sort();let a=0;for(let e=0;e<r.length;e++)(a===0||r[e]!==r[a-1])&&(r[a++]=r[e]);let o=r.slice(0,a);if(o.length*t.length>25e6)throw Error(`too_wide`);let s=t.map(()=>new Float32Array(o.length).fill(NaN));for(let n of e)t.forEach((e,t)=>{let r=n.lo.get(e);if(r){for(let e=0,i=pQ(o,n.t[0]);e<n.t.length;e++)if(r[e]===r[e]){for(;o[i]<n.t[e];)i++;s[t][i]=r[e]}}});return{t:o,cols:s}}async function N0(e,t,n,r={}){if(!e.channels.length)throw Error(`Pick at least one channel to export.`);let i=[...new Set(e.segments.map(e=>e.day))].sort(),a=i.map(t=>e.segments.find(e=>e.day===t&&e.kind===`raw`)).filter(e=>!!e),o=i.filter(e=>!a.some(t=>t.day===e)),s=new Set,c=()=>({skippedDays:[...o,...s].sort(),missingDays:[...s].sort()}),l=async t=>{let n=await C0({...e,segments:[t],level:0,cacheWrite:!1,relist:e.relist&&(async()=>(await e.relist()).filter(e=>e.day===t.day&&e.kind===`raw`))});for(let e of n.missingDays)s.add(e);return n},u=e=>r.onProgress?.((e+1)/a.length);if(t===`parquet`)return await F0(a,l,e.channels,n,u),c();if(t===`csv`){let t=!1;for(let[r,i]of a.entries()){let a=await l(i);!t&&!a.missingDays.length&&(await n(`time,${e.channels.map(r$).join(`,`)}\nUTC,${e.channels.map(e=>r$(a.units[e]??``)).join(`,`)}\n`),t=!0);let o=M0(a.pieces,e.channels);for(let e=0;e<o.t.length;e+=O0){let t=``;for(let n=e;n<Math.min(o.t.length,e+O0);n++){t+=j0(o.t[n]);for(let e of o.cols)t+=e[n]===e[n]?`,${A0(e[n])}`:`,`;t+=`
619
619
  `}await n(t)}u(r)}return t||await n(`time,${e.channels.map(r$).join(`,`)}\n`),c()}let d=0,f=NaN,p={};for(let t of a){let n=await l(t),r=M0(n.pieces,e.channels);d+=r.t.length,Number.isNaN(f)&&r.t.length&&(f=r.t[0]),p={...n.units,...p}}let m=new U1([{name:`time`,unit:`s`,text:!1},...e.channels.map(e=>({name:e,unit:p[e]??``,text:!1}))],Number.isNaN(f)?null:new Date(f*1e3).toISOString(),d);await n(m.head());for(let[t,r]of a.entries()){let i=M0((await l(r)).pieces,e.channels),a=i.t.map(e=>e-f);for(let e=0;e<i.t.length;e+=k0){let t=Math.min(i.t.length,e+k0);await n(m.append({length:t-e,columns:[a.subarray(e,t),...i.cols.map(n=>Float64Array.from(n.subarray(e,t)))]}))}u(t)}return m.end(),c()}var P0=0;async function F0(e,t,n,r,i,a={max:E0,chunk:D0}){let o=await zL(),s=await o.connect(),c=++P0,l=`khd_values_${c}`,u=`khd_names_${c}`,d=`khd_export_${c}.parquet`,f=new Float64Array(a.chunk),p=new Int32Array(a.chunk),m=new Float32Array(a.chunk),h=0,g=0,_=async()=>{h&&await s.insertArrowTable(dF({time:f.slice(0,h),ch:p.slice(0,h),value:m.slice(0,h)}),{name:l,create:!1}),h=0};try{await s.query(`CREATE TABLE ${u} (ch INTEGER, channel VARCHAR)`),await s.query(`INSERT INTO ${u} VALUES ${n.map((e,t)=>`(${t}, '${e.replace(/'/g,`''`)}')`).join(`, `)}`),await s.query(`CREATE TABLE ${l} (time DOUBLE, ch INTEGER, value FLOAT)`);for(let[r,o]of e.entries()){for(let e of(await t(o)).pieces)for(let[t,r]of n.entries()){let n=e.lo.get(r);if(n){for(let r=0;r<n.length;r++)if(n[r]===n[r]){if(++g>a.max)throw Object.assign(Error(`This export has more than ${(a.max/1e6).toLocaleString(`en-US`)} million values, too many for Parquet in the browser: export a shorter range or fewer channels.`),{code:`too_large`});f[h]=e.t[r],p[h]=t,m[h]=n[r],++h===a.chunk&&await _()}}}await _(),i(r)}await o.registerEmptyFileBuffer(d),await s.query(`COPY (SELECT to_timestamp(v.time) AS time, n.channel, v.value FROM ${l} v JOIN ${u} n USING (ch)
620
620
  ORDER BY v.time, n.channel) TO '${d}' (FORMAT parquet, COMPRESSION zstd)`),await r(await o.copyFileToBuffer(d))}finally{await s.query(`DROP TABLE IF EXISTS ${l}; DROP TABLE IF EXISTS ${u}`).catch(()=>void 0),await s.close(),await o.dropFile(d).catch(()=>void 0)}}export{mZ as ANNOTATION_CONTROLS_ATTR,Ot as ANNOTATION_KINDS,m$ as AxisState,_B as BEACON_STATS,x1 as CAMERA_PRESETS,er as CHART_ALARM_FIELDS,MQ as CHART_KINDS,RB as CYCLE_TIME,j1 as CameraSender,jB as CycleRunner,MB as CycleSet,Rt as DASHBOARD_GRID_COLS,Bt as DASHBOARD_GRID_GAP_PX,zt as DASHBOARD_GRID_ROWS,qz as DATASET_PALETTE,kt as DEFAULT_ANNOTATION_WIDTH,en as DEFAULT_AXIS_LINE,nn as DEFAULT_BEACON,tn as DEFAULT_GRID_LINE,fn as DEFAULT_TRACE_WIDTH,dn as DEFAULT_XYZ_POINT_RADIUS,un as DEFAULT_XY_POINT_RADIUS,E$ as DELTA_SUFFIX,W1 as EXPORT_TYPES,ST as FUNCTION_REFERENCE,l0 as HISTORY_PIXELS,_Q as HistoryDataSource,CV as IMPORTABLE_EXT,ke as KIND_VIDEO,nB as KPI_STATS,xe as KRC_HEADER_BYTES,hB as KpiAcc,kE as KymoscopeError,nt as LEAF_KEYS,qe as LIVE_TIME_COLUMN,S1 as LOW_PRESET,b1 as LivePublisher,u$ as MAX_BAND_CELLS,l$ as MAX_GRID,Un as MAX_PANEL_CAMERAS,E0 as MAX_PARQUET_VALUES,T0 as MAX_WIDE_CELLS,Wt as MIN_PANEL_H,Ut as MIN_PANEL_W,Ce as OPEN_STREAM_PASSWORD,c0 as RANGE_PARALLEL,l1 as RecordedVideoSource,gB as RuleRunner,Ft as SEVERITY_HEX,W$ as UNLIMITED,KQ as VIDEO_MAX_FRAGMENT,QT as WINDOW_FN_NAMES,C as WORKBOOK_EXPORT_AAD,w as alertRuleAad,h$ as alignSegment,Qt as arrangeAutoLayout,d$ as axisColumn,S$ as bandEdges,CB as bestCycleIndex,D as bindKeyAad,q1 as blockAad,s0 as blockCache,kW as buildEquation,CE as buildMathChannelsBlob,v$ as buildReference,TV as buildTree,Vn as cameraLabel,tr as chartAlarm,Cz as chartChannelCount,PQ as chartLabel,m0 as chooseLevel,or as clampPct,Kt as clampRectForKind,hQ as clipPiece,v0 as coalesce,Zn as coerceAlarmLine,Nt as coerceAnnotation,RY as colorAt,Jz as colorForDataset,$z as colorSchemeOf,VY as colorsCss,B as columnIsNumeric,aB as compareOp,C$ as compareToReference,EW as computePolyFit,DW as computeR2,n1 as createEngine,et as createRuleEvaluator,KB as cutCycle,AB as cycleRuleChannels,JB as cycleTables,yB as cyclicChannels,T$ as decodeBand,YQ as decodeVideo,IX as decorateColumnLabel,Mn as defaultAreaChartPanelSettings,An as defaultBarChartPanelSettings,yn as defaultBoxPlotPanelSettings,Pn as defaultBubbleChartPanelSettings,Rn as defaultCalibrationPanelSettings,Hn as defaultCameraPanelSettings,Nn as defaultCdfChartPanelSettings,Cn as defaultConfusionPanelSettings,En as defaultControlChartPanelSettings,Yz as defaultDatasetPalette,On as defaultEmbeddingPanelSettings,kn as defaultFlameGraphPanelSettings,Bn as defaultGanttPanelSettings,Ln as defaultGaugePanelSettings,xn as defaultHeatmapPanelSettings,gn as defaultHistogramPanelSettings,Tn as defaultLossCurvePanelSettings,pn as defaultMultibandPanelSettings,Dn as defaultParallelCoordsPanelSettings,_n as defaultPolarPanelSettings,zn as defaultQQPlotPanelSettings,jn as defaultRadarPanelSettings,wn as defaultRocPanelSettings,In as defaultSankeyPanelSettings,bn as defaultSpectrogramPanelSettings,vn as defaultSpectrumPanelSettings,Fn as defaultTreemapPanelSettings,Sn as defaultViolinPanelSettings,$t as defaultXyAxisScaleSettings,mn as defaultXyPanelSettings,hn as defaultXyzPanelSettings,HB as definitionChannels,f as deriveKey,_ as deriveRawKeyBase64,S as deviceFingerprint,qt as dragLayout,w$ as encodeBand,JQ as encodeVideo,$B as encryptWorkbookFile,ir as ensurePanelSettingsForPanels,rE as evalChannel,tB as eventWithin,N0 as exportHistoryTo,K1 as exportRecording,G1 as exportRecordingTo,tE as extractFreeIdentifiers,A0 as f32text,VB as findCycles,J1 as footerLength,Gz as formatClockTick,Kz as formatClockValue,TB as formatLapValue,XQ as fragmentVideo,A as generateApiToken,Qe as generateDeviceKeyPair,i as generateRecoveryKeyPair,L as generateSalt,Uz as getClockTimeZone,ze as getRawNonEmptyLines,_$ as gridAt,bB as guessBeaconChannel,h as hashToken,F as historyKeyAad,z as importStreamKey,y as inferParseConfig,Fz as isClockAxis,wV as isImportable,FX as isMathChannelName,j0 as isoMicros,UB as kpiColumn,rB as kpiKey,WB as kpisOf,O$ as liveSegmentTracker,fB as localDay,p$ as localSeconds,p as makeKeyCheck,Lt as markToAnnotation,sn as newGaugeItem,cr as newMathChannel,Xt as newPanel,sB as newResetState,sr as newSeriesId,wz as niceMajorStep,eB as observeColorScheme,pR as openDatasetFromText,Z1 as openFooter,ye as openMessage,X1 as openSealed,b as openUnderProjectKey,Re as openWithKey,v as openWithPassword,Wn as panelCameras,H as parseColumnNames,ee as parseConfigsEqual,LB as parseCycleDefinitions,k as parseDatasetWithConfig,eE as parseFormula,ae as parseKrc,Pe as parseKrcHeader,TE as parseMathChannelsFile,ln as parseOptionalAxisRange,rr as parsePanelChartSettingsMap,te as parseRecoveryCode,g0 as pickSegments,_0 as pool,x$ as pooledSd,BY as presetStops,V as projectConfigKeyAad,ne as projectWrapAad,O as randomKey,x0 as readFooter,C0 as readHistoryRange,BB as readSource,je as recordingKeyAad,Be as recordingKeySealAad,e as recoveryAttestationAad,me as recoveryCode,We as recoveryKeyAad,Ne as recoveryPrivateKey,jX as referenceBands,g$ as resample,cB as resetStep,$n as resolveLinkedAlarms,YB as rowsCsv,iB as ruleChannels,_e as sealMessage,Ve as sealUnderProjectKey,Se as sealWithKey,oe as sealWithPassword,Fe as senderBindKey,He as senderBinding,Hz as setClockTimeZone,mB as shiftDay,mQ as slicePiece,gQ as splicePieces,ue as splitApiKey,vB as splitLaps,Oe as streamKeyAad,t as subsampleIndices,Wz as subscribeClockTimeZone,xB as suggestBeacon,rt as thresholdOf,dB as tzOffsetS,Ke as unwrapForDevice,fe as unwrapStreamKey,tt as validateRule,ge as verifyKeyCheck,FV as verifyLicense,Le as verifySenderBinding,t0 as warmHistoryDecoder,M0 as wideDay,Ae as workbookBodyAad,XB as workbookExportAad,tV as workbookFileInfo,be as workbookKeyAad,ve as wrapForDevice,pB as zonedInstant};