@kymoscope/sdk 0.17.0 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{importer.worker-BblHvxro.js → importer.worker-BTbPiEHd.js} +4 -4
- package/dist/assets/liveIngestWorker-MA_RO8uZ.js +1 -0
- package/dist/importer-O00bqqEU.js +11 -0
- package/dist/importers-C90FOCV-.js +5 -0
- package/dist/kymoscope-embed.js +62 -61
- package/dist/kymoscope-sdk.js +86 -84
- package/dist/types/lib/data/liveDataSource.d.ts +5 -0
- package/dist/types/lib/importers/types.d.ts +2 -0
- package/dist/types/lib/live/blockWire.d.ts +17 -7
- package/dist/types/lib/live/buffer.d.ts +14 -1
- package/dist/types/lib/live/liveIngest.d.ts +16 -0
- package/dist/types/lib/live/sparseFeed.d.ts +39 -0
- package/dist/types/lib/live/sparseStore.d.ts +18 -0
- package/dist/types/lib/live/wire.d.ts +2 -0
- package/dist/types/lib/recordings/importer.d.ts +17 -1
- package/package.json +1 -1
- package/dist/assets/liveIngestWorker-UV5D515-.js +0 -1
- package/dist/importers-CLmQyVrb.js +0 -5
- package/dist/keys-B-nvFeb4.js +0 -11
package/dist/kymoscope-embed.js
CHANGED
|
@@ -75,12 +75,12 @@ In case of a (multi dimensional) array or matrix, the prob order quantile of all
|
|
|
75
75
|
`)}\n]`}concat(...t){let n=this.schema;return new e(n,this.data.concat(t.flatMap(({data:e})=>e)).map(e=>new gF(n,e)))}slice(t,n){let r=this.schema;return[t,n]=rM({length:this.numRows},t,n),new e(r,AM(this.data,this._offsets,t,n).map(e=>new gF(r,e)))}getChild(e){return this.getChildAt(this.schema.fields.findIndex(t=>t.name===e))}getChildAt(e){if(e>-1&&e<this.schema.fields.length){let t=this.data.map(t=>t.children[e]);if(t.length===0){let{type:n}=this.schema.fields[e],r=TM({type:n,length:0,nullCount:0});t.push(r._changeLengthAndBackfillNullBitmap(this.numRows))}return new YM(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 YM([TM({type:new _k,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]=uF(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(...uF(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)))}};pF=Symbol.toStringTag,mF[pF]=(e=>(e.schema=null,e.batches=[],e._offsets=new Uint32Array([0]),e._nullCount=-1,e[Symbol.isConcatSpreadable]=!0,e.isValid=NM(MM),e.get=NM(Jj.getVisitFn(Y.Struct)),e.set=PM(QA.getVisitFn(Y.Struct)),e.indexOf=FM(VM.getVisitFn(Y.Struct)),`Table`))(mF.prototype);var hF,gF=class e{constructor(...e){switch(e.length){case 2:if([this.schema]=e,!(this.schema instanceof fN)||([,this.data=TM({nullCount:0,type:new Wk(this.schema.fields),children:this.schema.fields.map(e=>TM({type:e.type,nullCount:0}))})]=e,!(this.data instanceof CM)))throw TypeError(`RecordBatch constructor expects a [Schema, Data] pair.`);[this.schema,this.data]=_F(this.schema,this.data.children);break;case 1:{let[t]=e,{fields:n,children:r,length:i}=Object.keys(t).reduce((e,n,r)=>(e.children[r]=t[n],e.length=Math.max(e.length,t[n].length),e.fields[r]=pN.new({name:n,type:t[n].type,nullable:!0}),e),{length:0,fields:[],children:[]}),a=new fN(n),o=TM({type:new Wk(n),length:i,children:r,nullCount:0});[this.schema,this.data]=_F(a,o.children,i);break}default:throw TypeError(`RecordBatch constructor expects an Object mapping names to child Data, or a [Schema, Data] pair.`)}}get dictionaries(){return this._dictionaries||=vF(this.schema.fields,this.data.children)}get numCols(){return this.schema.fields.length}get numRows(){return this.data.length}get nullCount(){return this.data.nullCount}isValid(e){return this.data.getValid(e)}get(e){return Jj.visit(this.data,e)}at(e){return this.get(iM(e,this.numRows))}set(e,t){return QA.visit(this.data,e,t)}indexOf(e,t){return VM.visit(this.data,e,t)}[Symbol.iterator](){return GM.visit(new YM([this.data]))}toArray(){return[...this]}concat(...e){return new mF(this.schema,[this,...e])}slice(t,n){let[r]=new YM([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 YM([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 YM([TM({type:new _k,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 fN(e,new Map(this.schema.metadata)),i=TM({type:new Wk(e),children:a})}return new e(r,i)}select(t){let n=this.schema.select(t),r=new Wk(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,TM({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,TM({type:new Wk(n.fields),length:this.numRows,children:r}))}};hF=Symbol.toStringTag,gF[hF]=(e=>(e._nullCount=-1,e[Symbol.isConcatSpreadable]=!0,`RecordBatch`))(gF.prototype);function _F(e,t,n=t.reduce((e,t)=>Math.max(e,t.length),0)){let r=[...e.fields],i=[...t],a=(n+63&-64)>>3;for(let[o,s]of e.fields.entries()){let e=t[o];(!e||e.length!==n)&&(r[o]=s.clone({nullable:!0}),i[o]=e?._changeLengthAndBackfillNullBitmap(n)??TM({type:s.type,length:n,nullCount:n,nullBitmap:new Uint8Array(a)}))}return[e.assign(r),TM({type:new Wk(r),length:n,children:i})]}function vF(e,t,n=new Map){if((e?.length??0)>0&&e?.length===t?.length)for(let r=-1,i=e.length;++r<i;){let{type:i}=e[r],a=t[r];for(let e of[a,...a?.dictionary?.data||[]])vF(i.children,e?.children,n);if(gk.isDictionary(i)){let{id:e}=i;if(!n.has(e))a?.dictionary&&n.set(e,a.dictionary);else if(n.get(e)!==a.dictionary)throw Error(`Cannot create Schema containing two different dictionaries with the same Id`)}}return n}var yF=class extends gF{constructor(e){let t=e.fields.map(e=>TM({type:e.type})),n=TM({type:new Wk(e.fields),nullCount:0,children:t});super(e,n)}},bF=class e{constructor(){this.bb=null,this.bb_pos=0}__init(e,t){return this.bb_pos=e,this.bb=t,this}static getRootAsMessage(t,n){return(n||new e).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsMessage(t,n){return t.setPosition(t.position()+4),(n||new e).__init(t.readInt32(t.position())+t.position(),t)}version(){let e=this.bb.__offset(this.bb_pos,4);return e?this.bb.readInt16(this.bb_pos+e):RD.V1}headerType(){let e=this.bb.__offset(this.bb_pos,6);return e?this.bb.readUint8(this.bb_pos+e):jO.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 cO).__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,RD.V1)}static addHeaderType(e,t){e.addFieldInt8(1,t,jO.NONE)}static addHeader(e,t){e.addFieldOffset(2,t,0)}static addBodyLength(e,t){e.addFieldInt64(3,t,BigInt(`0`))}static addCustomMetadata(e,t){e.addFieldOffset(4,t,0)}static createCustomMetadataVector(e,t){e.startVector(4,t.length,4);for(let n=t.length-1;n>=0;n--)e.addOffset(t[n]);return e.endVector()}static startCustomMetadataVector(e,t){e.startVector(4,t,4)}static endMessage(e){return e.endObject()}static finishMessageBuffer(e,t){e.finish(t)}static finishSizePrefixedMessageBuffer(e,t){e.finish(t,void 0,!0)}static createMessage(t,n,r,i,a,o){return e.startMessage(t),e.addVersion(t,n),e.addHeaderType(t,r),e.addHeader(t,i),e.addBodyLength(t,a),e.addCustomMetadata(t,o),e.endMessage(t)}},xF=new class extends Qk{visit(e,t){return e==null||t==null?void 0:super.visit(e,t)}visitNull(e,t){return SO.startNull(t),SO.endNull(t)}visitInt(e,t){return oO.startInt(t),oO.addBitWidth(t,e.bitWidth),oO.addIsSigned(t,e.isSigned),oO.endInt(t)}visitFloat(e,t){return gO.startFloatingPoint(t),gO.addPrecision(t,e.precision),gO.endFloatingPoint(t)}visitBinary(e,t){return lO.startBinary(t),lO.endBinary(t)}visitLargeBinary(e,t){return vO.startLargeBinary(t),vO.endLargeBinary(t)}visitBool(e,t){return uO.startBool(t),uO.endBool(t)}visitUtf8(e,t){return DO.startUtf8(t),DO.endUtf8(t)}visitLargeUtf8(e,t){return yO.startLargeUtf8(t),yO.endLargeUtf8(t)}visitDecimal(e,t){return fO.startDecimal(t),fO.addScale(t,e.scale),fO.addPrecision(t,e.precision),fO.addBitWidth(t,e.bitWidth),fO.endDecimal(t)}visitDate(e,t){return dO.startDate(t),dO.addUnit(t,e.unit),dO.endDate(t)}visitTime(e,t){return wO.startTime(t),wO.addUnit(t,e.unit),wO.addBitWidth(t,e.bitWidth),wO.endTime(t)}visitTimestamp(e,t){let n=e.timezone&&t.createString(e.timezone)||void 0;return TO.startTimestamp(t),TO.addUnit(t,e.unit),n!==void 0&&TO.addTimezone(t,n),TO.endTimestamp(t)}visitInterval(e,t){return _O.startInterval(t),_O.addUnit(t,e.unit),_O.endInterval(t)}visitDuration(e,t){return pO.startDuration(t),pO.addUnit(t,e.unit),pO.endDuration(t)}visitList(e,t){return bO.startList(t),bO.endList(t)}visitStruct(e,t){return CO.startStruct_(t),CO.endStruct_(t)}visitUnion(e,t){EO.startTypeIdsVector(t,e.typeIds.length);let n=EO.createTypeIdsVector(t,e.typeIds);return EO.startUnion(t),EO.addMode(t,e.mode),EO.addTypeIds(t,n),EO.endUnion(t)}visitDictionary(e,t){let n=this.visit(e.indices,t);return sO.startDictionaryEncoding(t),sO.addId(t,BigInt(e.id)),sO.addIsOrdered(t,e.isOrdered),n!==void 0&&sO.addIndexType(t,n),sO.endDictionaryEncoding(t)}visitFixedSizeBinary(e,t){return mO.startFixedSizeBinary(t),mO.addByteWidth(t,e.byteWidth),mO.endFixedSizeBinary(t)}visitFixedSizeList(e,t){return hO.startFixedSizeList(t),hO.addListSize(t,e.listSize),hO.endFixedSizeList(t)}visitMap(e,t){return xO.startMap(t),xO.addKeysSorted(t,e.keysSorted),xO.endMap(t)}};function SF(e,t=new Map){return new fN(TF(e,t),jF(e.metadata),t)}function CF(e){return new LF(e.count,DF(e.columns),OF(e.columns))}function wF(e){return new RF(CF(e.data),e.id,e.isDelta)}function TF(e,t){return(e.fields||[]).filter(Boolean).map(e=>pN.fromJSON(e,t))}function EF(e,t){return(e.children||[]).filter(Boolean).map(e=>pN.fromJSON(e,t))}function DF(e){return(e||[]).reduce((e,t)=>[...e,new BF(t.count,kF(t.VALIDITY)),...DF(t.children)],[])}function OF(e,t=[]){for(let n=-1,r=(e||[]).length;++n<r;){let r=e[n];r.VALIDITY&&t.push(new zF(t.length,r.VALIDITY.length)),r.TYPE_ID&&t.push(new zF(t.length,r.TYPE_ID.length)),r.OFFSET&&t.push(new zF(t.length,r.OFFSET.length)),r.DATA&&t.push(new zF(t.length,r.DATA.length)),t=OF(r.children,t)}return t}function kF(e){return(e||[]).reduce((e,t)=>e+ +(t===0),0)}function AF(e,t){let n,r,i,a,o,s;return!t||!(a=e.dictionary)?(o=NF(e,EF(e,t)),i=new pN(e.name,o,e.nullable,jF(e.metadata))):t.has(n=a.id)?(r=(r=a.indexType)?MF(r):new xk,s=new Xk(t.get(n),r,n,a.isOrdered),i=new pN(e.name,s,e.nullable,jF(e.metadata))):(r=(r=a.indexType)?MF(r):new xk,t.set(n,o=NF(e,EF(e,t))),s=new Xk(o,r,n,a.isOrdered),i=new pN(e.name,s,e.nullable,jF(e.metadata))),i||null}function jF(e=[]){return new Map(e.map(({key:e,value:t})=>[e,t]))}function MF(e){return new vk(e.isSigned,e.bitWidth)}function NF(e,t){let n=e.type.name;switch(n){case`NONE`:return new _k;case`null`:return new _k;case`binary`:return new jk;case`largebinary`:return new Mk;case`utf8`:return new Nk;case`largeutf8`:return new Pk;case`bool`:return new Fk;case`list`:return new Uk((t||[])[0]);case`struct`:return new Wk(t||[]);case`struct_`:return new Wk(t||[])}switch(n){case`int`:{let t=e.type;return new vk(t.isSigned,t.bitWidth)}case`floatingpoint`:{let t=e.type;return new Dk(BD[t.precision])}case`decimal`:{let t=e.type;return new Ik(t.scale,t.precision,t.bitWidth)}case`date`:{let t=e.type;return new Lk(VD[t.unit])}case`time`:{let t=e.type;return new Rk(HD[t.unit],t.bitWidth)}case`timestamp`:{let t=e.type;return new zk(HD[t.unit],t.timezone)}case`interval`:{let t=e.type;return new Vk(UD[t.unit])}case`duration`:{let t=e.type;return new Hk(HD[t.unit])}case`union`:{let n=e.type,[r,...i]=(n.mode+``).toLowerCase();return new Gk(zD[r.toUpperCase()+i.join(``)],n.typeIds||[],t||[])}case`fixedsizebinary`:{let t=e.type;return new Kk(t.byteWidth)}case`fixedsizelist`:{let n=e.type;return new qk(n.listSize,(t||[])[0])}case`map`:{let n=e.type;return new Jk((t||[])[0],n.keysSorted)}}throw Error(`Unrecognized type: "${n}"`)}var PF=XD,FF=YD,IF=class e{static fromJSON(t,n){let r=new e(0,RD.V5,n);return r._createHeader=VF(t,n),r}static decode(t){t=new FF(SD(t));let n=bF.getRootAsMessage(t),r=n.bodyLength(),i=n.version(),a=n.headerType(),o=new e(r,i,a);return o._createHeader=HF(n,a),o}static encode(e){let t=new PF,n=-1;return e.isSchema()?n=fN.encode(t,e.header()):e.isRecordBatch()?n=LF.encode(t,e.header()):e.isDictionaryBatch()&&(n=RF.encode(t,e.header())),bF.startMessage(t),bF.addVersion(t,RD.V5),bF.addHeader(t,n),bF.addHeaderType(t,e.headerType),bF.addBodyLength(t,BigInt(e.bodyLength)),bF.finishMessageBuffer(t,bF.endMessage(t)),t.asUint8Array()}static from(t,n=0){if(t instanceof fN)return new e(0,RD.V5,jO.Schema,t);if(t instanceof LF)return new e(n,RD.V5,jO.RecordBatch,t);if(t instanceof RF)return new e(n,RD.V5,jO.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===jO.Schema}isRecordBatch(){return this.headerType===jO.RecordBatch}isDictionaryBatch(){return this.headerType===jO.DictionaryBatch}constructor(e,t,n,r){this._version=t,this._headerType=n,this.body=new Uint8Array,r&&(this._createHeader=()=>r),this._bodyLength=FO(e)}},LF=class{get nodes(){return this._nodes}get length(){return this._length}get buffers(){return this._buffers}constructor(e,t,n){this._nodes=t,this._buffers=n,this._length=FO(e)}},RF=class{get id(){return this._id}get data(){return this._data}get isDelta(){return this._isDelta}get length(){return this.data.length}get nodes(){return this.data.nodes}get buffers(){return this.data.buffers}constructor(e,t,n=!1){this._data=e,this._isDelta=n,this._id=FO(t)}},zF=class{constructor(e,t){this.offset=FO(e),this.length=FO(t)}},BF=class{constructor(e,t){this.length=FO(e),this.nullCount=FO(t)}};function VF(e,t){return(()=>{switch(t){case jO.Schema:return fN.fromJSON(e);case jO.RecordBatch:return LF.fromJSON(e);case jO.DictionaryBatch:return RF.fromJSON(e)}throw Error(`Unrecognized Message type: { name: ${jO[t]}, type: ${t} }`)})}function HF(e,t){return(()=>{switch(t){case jO.Schema:return fN.decode(e.header(new AO),new Map,e.version());case jO.RecordBatch:return LF.decode(e.header(new nO),e.version());case jO.DictionaryBatch:return RF.decode(e.header(new rO),e.version())}throw Error(`Unrecognized Message type: { name: ${jO[t]}, type: ${t} }`)})}pN.encode=rI,pN.decode=QF,pN.fromJSON=AF,fN.encode=nI,fN.decode=UF,fN.fromJSON=SF,LF.encode=iI,LF.decode=WF,LF.fromJSON=CF,RF.encode=aI,RF.decode=GF,RF.fromJSON=wF,BF.encode=oI,BF.decode=qF,zF.encode=sI,zF.decode=KF;function UF(e,t=new Map,n=RD.V5){return new fN(XF(e,t),$F(e),t,n)}function WF(e,t=RD.V5){if(e.compression()!==null)throw Error(`Record batch compression not implemented`);return new LF(e.length(),JF(e),YF(e,t))}function GF(e,t=RD.V5){return new RF(LF.decode(e.data(),t),e.id(),e.isDelta())}function KF(e){return new zF(e.offset(),e.length())}function qF(e){return new BF(e.length(),e.nullCount())}function JF(e){let t=[];for(let n,r=-1,i=-1,a=e.nodesLength();++r<a;)(n=e.nodes(r))&&(t[++i]=BF.decode(n));return t}function YF(e,t){let n=[];for(let r,i=-1,a=-1,o=e.buffersLength();++i<o;)(r=e.buffers(i))&&(t<RD.V4&&(r.bb_pos+=8*(i+1)),n[++a]=zF.decode(r));return n}function XF(e,t){let n=[];for(let r,i=-1,a=-1,o=e.fieldsLength();++i<o;)(r=e.fields(i))&&(n[++a]=pN.decode(r,t));return n}function ZF(e,t){let n=[];for(let r,i=-1,a=-1,o=e.childrenLength();++i<o;)(r=e.children(i))&&(n[++a]=pN.decode(r,t));return n}function QF(e,t){let n,r,i,a,o,s;return!t||!(s=e.dictionary())?(i=tI(e,ZF(e,t)),r=new pN(e.name(),i,e.nullable(),$F(e))):t.has(n=FO(s.id()))?(a=(a=s.indexType())?eI(a):new xk,o=new Xk(t.get(n),a,n,s.isOrdered()),r=new pN(e.name(),o,e.nullable(),$F(e))):(a=(a=s.indexType())?eI(a):new xk,t.set(n,i=tI(e,ZF(e,t))),o=new Xk(i,a,n,s.isOrdered()),r=new pN(e.name(),o,e.nullable(),$F(e))),r||null}function $F(e){let t=new Map;if(e)for(let n,r,i=-1,a=Math.trunc(e.customMetadataLength());++i<a;)(n=e.customMetadata(i))&&(r=n.key())!=null&&t.set(r,n.value());return t}function eI(e){return new vk(e.isSigned(),e.bitWidth())}function tI(e,t){let n=e.typeType();switch(n){case OO.NONE:return new _k;case OO.Null:return new _k;case OO.Binary:return new jk;case OO.LargeBinary:return new Mk;case OO.Utf8:return new Nk;case OO.LargeUtf8:return new Pk;case OO.Bool:return new Fk;case OO.List:return new Uk((t||[])[0]);case OO.Struct_:return new Wk(t||[])}switch(n){case OO.Int:{let t=e.type(new oO);return new vk(t.isSigned(),t.bitWidth())}case OO.FloatingPoint:return new Dk(e.type(new gO).precision());case OO.Decimal:{let t=e.type(new fO);return new Ik(t.scale(),t.precision(),t.bitWidth())}case OO.Date:return new Lk(e.type(new dO).unit());case OO.Time:{let t=e.type(new wO);return new Rk(t.unit(),t.bitWidth())}case OO.Timestamp:{let t=e.type(new TO);return new zk(t.unit(),t.timezone())}case OO.Interval:return new Vk(e.type(new _O).unit());case OO.Duration:return new Hk(e.type(new pO).unit());case OO.Union:{let n=e.type(new EO);return new Gk(n.mode(),n.typeIdsArray()||[],t||[])}case OO.FixedSizeBinary:return new Kk(e.type(new mO).byteWidth());case OO.FixedSizeList:return new qk(e.type(new hO).listSize(),(t||[])[0]);case OO.Map:{let n=e.type(new xO);return new Jk((t||[])[0],n.keysSorted())}}throw Error(`Unrecognized type: "${OO[n]}" (${n})`)}function nI(e,t){let n=t.fields.map(t=>pN.encode(e,t));AO.startFieldsVector(e,n.length);let r=AO.createFieldsVector(e,n),i=t.metadata&&t.metadata.size>0?AO.createCustomMetadataVector(e,[...t.metadata].map(([t,n])=>{let r=e.createString(`${t}`),i=e.createString(`${n}`);return cO.startKeyValue(e),cO.addKey(e,r),cO.addValue(e,i),cO.endKeyValue(e)})):-1;return AO.startSchema(e),AO.addFields(e,r),AO.addEndianness(e,cI?iO.Little:iO.Big),i!==-1&&AO.addCustomMetadata(e,i),AO.endSchema(e)}function rI(e,t){let n=-1,r=-1,i=-1,a=t.type,o=t.typeId;gk.isDictionary(a)?(o=a.dictionary.typeId,i=xF.visit(a,e),r=xF.visit(a.dictionary,e)):r=xF.visit(a,e);let s=(a.children||[]).map(t=>pN.encode(e,t)),c=kO.createChildrenVector(e,s),l=t.metadata&&t.metadata.size>0?kO.createCustomMetadataVector(e,[...t.metadata].map(([t,n])=>{let r=e.createString(`${t}`),i=e.createString(`${n}`);return cO.startKeyValue(e),cO.addKey(e,r),cO.addValue(e,i),cO.endKeyValue(e)})):-1;return t.name&&(n=e.createString(t.name)),kO.startField(e),kO.addType(e,r),kO.addTypeType(e,o),kO.addChildren(e,c),kO.addNullable(e,!!t.nullable),n!==-1&&kO.addName(e,n),i!==-1&&kO.addDictionary(e,i),l!==-1&&kO.addCustomMetadata(e,l),kO.endField(e)}function iI(e,t){let n=t.nodes||[],r=t.buffers||[];nO.startNodesVector(e,n.length);for(let t of n.slice().reverse())BF.encode(e,t);let i=e.endVector();nO.startBuffersVector(e,r.length);for(let t of r.slice().reverse())zF.encode(e,t);let a=e.endVector();return nO.startRecordBatch(e),nO.addLength(e,BigInt(t.length)),nO.addNodes(e,i),nO.addBuffers(e,a),nO.endRecordBatch(e)}function aI(e,t){let n=LF.encode(e,t.data);return rO.startDictionaryBatch(e),rO.addId(e,BigInt(t.id)),rO.addIsDelta(e,t.isDelta),rO.addData(e,n),rO.endDictionaryBatch(e)}function oI(e,t){return tO.createFieldNode(e,BigInt(t.length),BigInt(t.nullCount))}function sI(e,t){return eO.createBuffer(e,BigInt(t.offset),BigInt(t.length))}var cI=(()=>{let e=new ArrayBuffer(2);return new DataView(e).setInt16(0,256,!0),new Int16Array(e)[0]===256})(),lI=e=>`Expected ${jO[e]} Message in stream, but was null or length 0.`,uI=e=>`Header pointer of flatbuffer-encoded ${jO[e]} Message is null or length 0.`,dI=(e,t)=>`Expected to read ${e} metadata bytes, but only read ${t}.`,fI=(e,t)=>`Expected to read ${e} bytes for message body, but only read ${t}.`,pI=class{constructor(e){this.source=e instanceof EN?e:new EN(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?xN:e}throw(e){return this.source.throw(e)}return(e){return this.source.return(e)}readMessage(e){let t;if((t=this.next()).done)return null;if(e!=null&&t.value.headerType!==e)throw Error(lI(e));return t.value}readMessageBody(e){if(e<=0)return new Uint8Array;let t=SD(this.source.read(e));if(t.byteLength<e)throw Error(fI(e,t.byteLength));return t.byteOffset%8==0&&t.byteOffset+t.byteLength<=t.buffer.byteLength?t:t.slice()}readSchema(e=!1){let t=jO.Schema,n=this.readMessage(t)?.header();if(e&&!n)throw Error(uI(t));return n}readMetadataLength(){let e=this.source.read(4),t=(e&&new YD(e))?.readInt32(0)||0;return{done:t===0,value:t}}readMetadata(e){let t=this.source.read(e);if(!t)return xN;if(t.byteLength<e)throw Error(dI(e,t.byteLength));return{done:!1,value:IF.decode(t)}}},mI=class{constructor(e,t){this.source=e instanceof DN?e:sD(e)?new jN(e,t):new DN(e)}[Symbol.asyncIterator](){return this}next(){return HE(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?xN:e})}throw(e){return HE(this,void 0,void 0,function*(){return yield this.source.throw(e)})}return(e){return HE(this,void 0,void 0,function*(){return yield this.source.return(e)})}readMessage(e){return HE(this,void 0,void 0,function*(){let t;if((t=yield this.next()).done)return null;if(e!=null&&t.value.headerType!==e)throw Error(lI(e));return t.value})}readMessageBody(e){return HE(this,void 0,void 0,function*(){if(e<=0)return new Uint8Array;let t=SD(yield this.source.read(e));if(t.byteLength<e)throw Error(fI(e,t.byteLength));return t.byteOffset%8==0&&t.byteOffset+t.byteLength<=t.buffer.byteLength?t:t.slice()})}readSchema(){return HE(this,arguments,void 0,function*(e=!1){let t=jO.Schema,n=(yield this.readMessage(t))?.header();if(e&&!n)throw Error(uI(t));return n})}readMetadataLength(){return HE(this,void 0,void 0,function*(){let e=yield this.source.read(4),t=(e&&new YD(e))?.readInt32(0)||0;return{done:t===0,value:t}})}readMetadata(e){return HE(this,void 0,void 0,function*(){let t=yield this.source.read(e);if(!t)return xN;if(t.byteLength<e)throw Error(dI(e,t.byteLength));return{done:!1,value:IF.decode(t)}})}},hI=class extends pI{constructor(e){super(new Uint8Array),this._schema=!1,this._body=[],this._batchIndex=0,this._dictionaryIndex=0,this._json=e instanceof SN?e:new SN(e)}next(){let{_json:e}=this;if(!this._schema)return this._schema=!0,{done:!1,value:IF.fromJSON(e.schema,jO.Schema)};if(this._dictionaryIndex<e.dictionaries.length){let t=e.dictionaries[this._dictionaryIndex++];return this._body=t.data.columns,{done:!1,value:IF.fromJSON(t,jO.DictionaryBatch)}}if(this._batchIndex<e.batches.length){let t=e.batches[this._batchIndex++];return this._body=t.columns,{done:!1,value:IF.fromJSON(t,jO.RecordBatch)}}return this._body=[],xN}readMessageBody(e){return t(this._body);function t(e){return(e||[]).reduce((e,n)=>[...e,...n.VALIDITY&&[n.VALIDITY]||[],...n.TYPE_ID&&[n.TYPE_ID]||[],...n.OFFSET&&[n.OFFSET]||[],...n.DATA&&[n.DATA]||[],...t(n.children)],[])}}readMessage(e){let t;if((t=this.next()).done)return null;if(e!=null&&t.value.headerType!==e)throw Error(lI(e));return t.value}readSchema(){let e=jO.Schema,t=this.readMessage(e),n=t?.header();if(!t||!n)throw Error(uI(e));return n}},gI=`ARROW1`,_I=new Uint8Array(6);for(let e=0;e<6;e+=1)_I[e]=gI.codePointAt(e);function vI(e,t=0){for(let n=-1,r=_I.length;++n<r;)if(_I[n]!==e[t+n])return!1;return!0}var yI=_I.length,bI=yI+4,xI=yI*2+4,SI=class e extends CN{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 nD(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 AD.toDOMStream(this.isSync()?{[Symbol.iterator]:()=>this}:{[Symbol.asyncIterator]:()=>this})}toNodeStream(){return AD.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:aD(t)?II(t):sD(t)?zI(t):nD(t)?HE(this,void 0,void 0,function*(){return yield e.from(yield t)}):cD(t)||dD(t)||pD(t)||iD(t)?RI(new DN(t)):LI(new EN(t))}static readAll(t){return t instanceof e?t.isSync()?PI(t):FI(t):aD(t)||ArrayBuffer.isView(t)||rD(t)||oD(t)?PI(t):FI(t)}},CI=class extends SI{constructor(e){super(e),this._impl=e}readAll(){return[...this]}[Symbol.iterator](){return this._impl[Symbol.iterator]()}[Symbol.asyncIterator](){return GE(this,arguments,function*(){yield WE(yield*KE(qE(this[Symbol.iterator]())))})}},wI=class extends SI{constructor(e){super(e),this._impl=e}readAll(){return HE(this,void 0,void 0,function*(){var e,t,n,r;let i=[];try{for(var a=!0,o=qE(this),s;s=yield o.next(),e=s.done,!e;a=!0){r=s.value,a=!1;let e=r;i.push(e)}}catch(e){t={error:e}}finally{try{!a&&!e&&(n=o.return)&&(yield n.call(o))}finally{if(t)throw t.error}}return i})}[Symbol.iterator](){throw Error(`AsyncRecordBatchStreamReader is not Iterable`)}[Symbol.asyncIterator](){return this._impl[Symbol.asyncIterator]()}},TI=class extends CI{constructor(e){super(e),this._impl=e}},EI=class extends wI{constructor(e){super(e),this._impl=e}},DI=class{get numDictionaries(){return this._dictionaryIndex}get numRecordBatches(){return this._recordBatchIndex}constructor(e=new Map){this.closed=!1,this.autoDestroy=!0,this._dictionaryIndex=0,this._recordBatchIndex=0,this.dictionaries=e}isSync(){return!1}isAsync(){return!1}isFile(){return!1}isStream(){return!1}reset(e){return this._dictionaryIndex=0,this._recordBatchIndex=0,this.schema=e,this.dictionaries=new Map,this}_loadRecordBatch(e,t){let n=this._loadVectors(e,t,this.schema.fields),r=TM({type:new Wk(this.schema.fields),length:e.length,children:n});return new gF(this.schema,r)}_loadDictionaryBatch(e,t){let{id:n,isDelta:r}=e,{dictionaries:i,schema:a}=this,o=i.get(n),s=a.dictionaries.get(n),c=this._loadVectors(e.data,t,[s]);return(o&&r?o.concat(new YM(c)):new YM(c)).memoize()}_loadVectors(e,t,n){return new BN(t,e.nodes,e.buffers,this.dictionaries,this.schema.metadataVersion).visitMany(n)}},OI=class extends DI{constructor(e,t){super(t),this._reader=aD(e)?new hI(this._handle=e):new pI(this._handle=e)}isSync(){return!0}isStream(){return!0}[Symbol.iterator](){return this}cancel(){!this.closed&&(this.closed=!0)&&(this.reset()._reader.return(),this._reader=null,this.dictionaries=null)}open(e){return this.closed||(this.autoDestroy=NI(this,e),(this.schema||=this._reader.readSchema())||this.cancel()),this}throw(e){return!this.closed&&this.autoDestroy&&(this.closed=!0)?this.reset()._reader.throw(e):xN}return(e){return!this.closed&&this.autoDestroy&&(this.closed=!0)?this.reset()._reader.return(e):xN}next(){if(this.closed)return xN;let e,{_reader:t}=this;for(;e=this._readNextMessageAndValidate();)if(e.isSchema())this.reset(e.header());else if(e.isRecordBatch()){this._recordBatchIndex++;let n=e.header(),r=t.readMessageBody(e.bodyLength);return{done:!1,value:this._loadRecordBatch(n,r)}}else if(e.isDictionaryBatch()){this._dictionaryIndex++;let n=e.header(),r=t.readMessageBody(e.bodyLength),i=this._loadDictionaryBatch(n,r);this.dictionaries.set(n.id,i)}return this.schema&&this._recordBatchIndex===0?(this._recordBatchIndex++,{done:!1,value:new yF(this.schema)}):this.return()}_readNextMessageAndValidate(e){return this._reader.readMessage(e)}},kI=class extends DI{constructor(e,t){super(t),this._reader=new mI(this._handle=e)}isAsync(){return!0}isStream(){return!0}[Symbol.asyncIterator](){return this}cancel(){return HE(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 HE(this,void 0,void 0,function*(){return this.closed||(this.autoDestroy=NI(this,e),(this.schema||=yield this._reader.readSchema())||(yield this.cancel())),this})}throw(e){return HE(this,void 0,void 0,function*(){return!this.closed&&this.autoDestroy&&(this.closed=!0)?yield this.reset()._reader.throw(e):xN})}return(e){return HE(this,void 0,void 0,function*(){return!this.closed&&this.autoDestroy&&(this.closed=!0)?yield this.reset()._reader.return(e):xN})}next(){return HE(this,void 0,void 0,function*(){if(this.closed)return xN;let e,{_reader:t}=this;for(;e=yield this._readNextMessageAndValidate();)if(e.isSchema())yield this.reset(e.header());else if(e.isRecordBatch()){this._recordBatchIndex++;let n=e.header(),r=yield t.readMessageBody(e.bodyLength);return{done:!1,value:this._loadRecordBatch(n,r)}}else if(e.isDictionaryBatch()){this._dictionaryIndex++;let n=e.header(),r=yield t.readMessageBody(e.bodyLength),i=this._loadDictionaryBatch(n,r);this.dictionaries.set(n.id,i)}return this.schema&&this._recordBatchIndex===0?(this._recordBatchIndex++,{done:!1,value:new yF(this.schema)}):yield this.return()})}_readNextMessageAndValidate(e){return HE(this,void 0,void 0,function*(){return yield this._reader.readMessage(e)})}},AI=class extends OI{get footer(){return this._footer}get numDictionaries(){return this._footer?this._footer.numDictionaries:0}get numRecordBatches(){return this._footer?this._footer.numRecordBatches:0}constructor(e,t){super(e instanceof AN?e:new AN(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(jO.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(jO.DictionaryBatch);if(e?.isDictionaryBatch()){let t=e.header(),n=this._reader.readMessageBody(e.bodyLength),r=this._loadDictionaryBatch(t,n);this.dictionaries.set(t.id,r)}}}_readFooter(){let{_handle:e}=this,t=e.size-bI,n=e.readInt32(t),r=e.readAt(t-n,n);return vN.decode(r)}_readNextMessageAndValidate(e){if(this._footer||this.open(),this._footer&&this._recordBatchIndex<this.numRecordBatches){let t=this._footer?.getRecordBatch(this._recordBatchIndex);if(t&&this._handle.seek(t.offset))return this._reader.readMessage(e)}return null}},jI=class extends kI{get footer(){return this._footer}get numDictionaries(){return this._footer?this._footer.numDictionaries:0}get numRecordBatches(){return this._footer?this._footer.numRecordBatches:0}constructor(e,...t){let n=typeof t[0]==`number`?void 0:t.shift(),r=t[0]instanceof Map?t.shift():void 0;super(e instanceof jN?e:new jN(e,n),r)}isFile(){return!0}isAsync(){return!0}open(e){let t=Object.create(null,{open:{get:()=>super.open}});return HE(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 HE(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(jO.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 HE(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(jO.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 HE(this,void 0,void 0,function*(){let{_handle:e}=this;e._pending&&(yield e._pending);let t=e.size-bI,n=yield e.readInt32(t),r=yield e.readAt(t-n,n);return vN.decode(r)})}_readNextMessageAndValidate(e){return HE(this,void 0,void 0,function*(){if(this._footer||(yield this.open()),this._footer&&this._recordBatchIndex<this.numRecordBatches){let t=this._footer.getRecordBatch(this._recordBatchIndex);if(t&&(yield this._handle.seek(t.offset)))return yield this._reader.readMessage(e)}return null})}},MI=class extends OI{constructor(e,t){super(e,t)}_loadVectors(e,t,n){return new VN(t,e.nodes,e.buffers,this.dictionaries,this.schema.metadataVersion).visitMany(n)}};function NI(e,t){return t&&typeof t.autoDestroy==`boolean`?t.autoDestroy:e.autoDestroy}function*PI(e){let t=SI.from(e);try{if(!t.open({autoDestroy:!1}).closed)do yield t;while(!t.reset().open().closed)}finally{t.cancel()}}function FI(e){return GE(this,arguments,function*(){let t=yield WE(SI.from(e));try{if(!(yield WE(t.open({autoDestroy:!1}))).closed)do yield yield WE(t);while(!(yield WE(t.reset().open())).closed)}finally{yield WE(t.cancel())}})}function II(e){return new CI(new MI(e))}function LI(e){let t=e.peek(yI+7&-8);return t&&t.byteLength>=4?vI(t)?new TI(new AI(e.read())):new CI(new OI(e)):new CI(new OI(function*(){}()))}function RI(e){return HE(this,void 0,void 0,function*(){let t=yield e.peek(yI+7&-8);return t&&t.byteLength>=4?vI(t)?new TI(new AI(yield e.read())):new wI(new kI(e)):new wI(new kI(function(){return GE(this,arguments,function*(){})}()))})}function zI(e){return HE(this,void 0,void 0,function*(){let{size:t}=yield e.stat(),n=new jN(e,t);return t>=xI&&vI(yield n.readAt(0,yI+7&-8))?new EI(new jI(n)):new wI(new kI(n))})}var BI=class e extends Qk{static assemble(...t){let n=e=>e.flatMap(e=>Array.isArray(e)?n(e):e instanceof gF?e.data.children:e.data),r=new e;return r.visitMany(n(t)),r}constructor(){super(),this._byteLength=0,this._nodes=[],this._buffers=[],this._bufferRegions=[]}visit(e){if(e instanceof YM)return this.visitMany(e.data),this;let{type:t}=e;if(!gk.isDictionary(t)){let{length:n}=e;if(n>2147483647)throw RangeError(`Cannot write arrays larger than 2^31 - 1 in length`);if(gk.isUnion(t))this.nodes.push(new BF(n,0));else{let{nullCount:r}=e;gk.isNull(t)||VI.call(this,r<=0?new Uint8Array:_M(e.offset,n,e.nullBitmap)),this.nodes.push(new BF(n,r))}}return super.visit(e)}visitNull(e){return this}visitDictionary(e){return this.visit(e.clone(e.type.indices))}get nodes(){return this._nodes}get buffers(){return this._buffers}get byteLength(){return this._byteLength}get bufferRegions(){return this._bufferRegions}};function VI(e){let t=e.byteLength+7&-8;return this.buffers.push(e),this.bufferRegions.push(new zF(this._byteLength,t)),this._byteLength+=t,this}function HI(e){let{type:t,length:n,typeIds:r,valueOffsets:i}=e;if(VI.call(this,r),t.mode===zD.Sparse)return qI.call(this,e);if(t.mode===zD.Dense){if(e.offset<=0)return VI.call(this,i),qI.call(this,e);{let a=new Int32Array(n),o=Object.create(null),s=Object.create(null);for(let e,t,c=-1;++c<n;)(e=r[c])!==void 0&&((t=o[e])===void 0&&(t=o[e]=i[c]),a[c]=i[c]-t,s[e]=(s[e]??0)+1);VI.call(this,a),this.visitMany(e.children.map((e,r)=>{let i=t.typeIds[r],a=o[i],c=s[i];return e.slice(a,Math.min(n,c))}))}}return this}function UI(e){let t;return e.nullCount>=e.length?VI.call(this,new Uint8Array):(t=e.values)instanceof Uint8Array?VI.call(this,_M(e.offset,e.length,t)):VI.call(this,vM(e.values))}function WI(e){return VI.call(this,e.values.subarray(0,e.length*e.stride))}function GI(e){let{length:t,values:n,valueOffsets:r}=e,i=FO(r[0]),a=FO(r[t]),o=Math.min(a-i,n.byteLength-i);return VI.call(this,OD(-i,t+1,r)),VI.call(this,n.subarray(i,i+o)),this}function KI(e){let{length:t,valueOffsets:n}=e;if(n){let{0:r,[t]:i}=n;return VI.call(this,OD(-r,t+1,n)),this.visit(e.children[0].slice(r,i-r))}return this.visit(e.children[0])}function qI(e){return this.visitMany(e.type.children.map((t,n)=>e.children[n]).filter(Boolean))[0]}BI.prototype.visitBool=UI,BI.prototype.visitInt=WI,BI.prototype.visitFloat=WI,BI.prototype.visitUtf8=GI,BI.prototype.visitLargeUtf8=GI,BI.prototype.visitBinary=GI,BI.prototype.visitLargeBinary=GI,BI.prototype.visitFixedSizeBinary=WI,BI.prototype.visitDate=WI,BI.prototype.visitTimestamp=WI,BI.prototype.visitTime=WI,BI.prototype.visitDecimal=WI,BI.prototype.visitList=KI,BI.prototype.visitStruct=qI,BI.prototype.visitUnion=HI,BI.prototype.visitInterval=WI,BI.prototype.visitDuration=WI,BI.prototype.visitFixedSizeList=KI,BI.prototype.visitMap=KI;var JI=class extends CN{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 TN,this._schema=null,this._dictionaryBlocks=[],this._recordBatchBlocks=[],this._seenDictionaries=new Map,this._dictionaryDeltaOffsets=new Map,tD(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 nD(e)?e.then(e=>this.writeAll(e)):iD(e)?QI(this,e):ZI(this,e)}get closed(){return this._sink.closed}[Symbol.asyncIterator](){return this._sink[Symbol.asyncIterator]()}toDOMStream(e){return this._sink.toDOMStream(e)}toNodeStream(e){return this._sink.toNodeStream(e)}close(){return this.reset()._sink.close()}abort(e){return this.reset()._sink.abort(e)}finish(){return this._autoDestroy?this.close():this.reset(this._sink,this._schema),this}reset(e=this._sink,t=null){return e===this._sink||e instanceof TN?this._sink=e:(this._sink=new TN,e&&uD(e)?this.toDOMStream({type:`bytes`}).pipeTo(e):e&&fD(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||!iF(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 mF&&!(t=e.schema)||e instanceof gF&&!(t=e.schema))return this.finish()&&void 0;if(t&&!iF(t,this._schema)){if(this._started&&this._autoDestroy)return this.close();this.reset(this._sink,t)}e instanceof gF?e instanceof yF||this._writeRecordBatch(e):e instanceof mF?this.writeAll(e.batches):rD(e)&&this.writeAll(e)}_writeMessage(e,t=8){let n=t-1,r=IF.encode(e),i=r.byteLength,a=this._writeLegacyIpcFormat?4:8,o=i+a+n&~n,s=o-i-a;return e.headerType===jO.RecordBatch?this._recordBatchBlocks.push(new bN(o,e.bodyLength,this._position)):e.headerType===jO.DictionaryBatch&&this._dictionaryBlocks.push(new bN(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=SD(e);t&&t.byteLength>0&&(this._sink.write(t),this._position+=t.byteLength)}return this}_writeSchema(e){return this._writeMessage(IF.from(e))}_writeFooter(e){return this._writeLegacyIpcFormat?this._write(Int32Array.of(0)):this._write(Int32Array.of(-1,0))}_writeMagic(){return this._write(_I)}_writePadding(e){return e>0?this._write(new Uint8Array(e)):this}_writeRecordBatch(e){let{byteLength:t,nodes:n,bufferRegions:r,buffers:i}=BI.assemble(e),a=new LF(e.numRows,n,r),o=IF.from(a,t);return this._writeDictionaries(e)._writeMessage(o)._writeBodyBuffers(i)}_writeDictionaryBatch(e,t,n=!1){let{byteLength:r,nodes:i,bufferRegions:a,buffers:o}=BI.assemble(new YM([e])),s=new RF(new LF(e.length,i,a),t,n),c=IF.from(s,r);return this._writeMessage(c)._writeBodyBuffers(o)}_writeBodyBuffers(e){let t,n,r;for(let i=-1,a=e.length;++i<a;)(t=e[i])&&(n=t.byteLength)>0&&(this._write(t),(r=(n+7&-8)-n)>0&&this._writePadding(r));return this}_writeDictionaries(e){for(let[t,n]of e.dictionaries){let e=n?.data??[],r=this._seenDictionaries.get(t),i=this._dictionaryDeltaOffsets.get(t)??0;if(!r||r.data[0]!==e[0])for(let[n,r]of e.entries())this._writeDictionaryBatch(r,t,n>0);else if(i<e.length)for(let n of e.slice(i))this._writeDictionaryBatch(n,t,!0);this._seenDictionaries.set(t,n),this._dictionaryDeltaOffsets.set(t,e.length)}return this}},YI=class e extends JI{static writeAll(t,n){let r=new e(n);return nD(t)?t.then(e=>r.writeAll(e)):iD(t)?QI(r,t):ZI(r,t)}},XI=class e extends JI{static writeAll(t){let n=new e;return nD(t)?t.then(e=>n.writeAll(e)):iD(t)?QI(n,t):ZI(n,t)}constructor(){super(),this._autoDestroy=!0}_writeSchema(e){return this._writeMagic()._writePadding(2)}_writeDictionaryBatch(e,t,n=!1){if(!n&&this._seenDictionaries.has(t))throw Error(`The Arrow File format does not support replacement dictionaries. `);return super._writeDictionaryBatch(e,t,n)}_writeFooter(e){let t=vN.encode(new vN(e,RD.V5,this._recordBatchBlocks,this._dictionaryBlocks));return super._writeFooter(e)._write(t)._write(Int32Array.of(t.byteLength))._writeMagic()}};function ZI(e,t){let n=t;t instanceof mF&&(n=t.batches,e.reset(void 0,t.schema));for(let t of n)e.write(t);return e.finish()}function QI(e,t){return HE(this,void 0,void 0,function*(){var n,r,i,a,o,s,c;try{for(n=!0,r=qE(t);i=yield r.next(),a=i.done,!a;n=!0){c=i.value,n=!1;let t=c;e.write(t)}}catch(e){o={error:e}}finally{try{!n&&!a&&(s=r.return)&&(yield s.call(r))}finally{if(o)throw o.error}}return e.finish()})}function $I(e,t=`stream`){return(t===`stream`?YI:XI).writeAll(e).toUint8Array(!0)}var eL=Object.create,tL=Object.defineProperty,nL=Object.getOwnPropertyDescriptor,rL=Object.getOwnPropertyNames,iL=Object.getPrototypeOf,aL=Object.prototype.hasOwnProperty,oL=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),sL=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(let i of rL(t))!aL.call(e,i)&&i!==n&&tL(e,i,{get:()=>t[i],enumerable:!(r=nL(t,i))||r.enumerable});return e},cL=(e,t,n)=>(n=e==null?{}:eL(iL(e)),sL(t||!e||!e.__esModule?tL(n,`default`,{value:e,enumerable:!0}):n,e)),lL=oL((e,t)=>{t.exports=Worker}),uL=(e=>(e[e.UNDEFINED=0]=`UNDEFINED`,e[e.AUTOMATIC=1]=`AUTOMATIC`,e[e.READ_ONLY=2]=`READ_ONLY`,e[e.READ_WRITE=3]=`READ_WRITE`,e))(uL||{}),dL=(e=>(e[e.IDENTIFIER=0]=`IDENTIFIER`,e[e.NUMERIC_CONSTANT=1]=`NUMERIC_CONSTANT`,e[e.STRING_CONSTANT=2]=`STRING_CONSTANT`,e[e.OPERATOR=3]=`OPERATOR`,e[e.KEYWORD=4]=`KEYWORD`,e[e.COMMENT=5]=`COMMENT`,e))(dL||{}),fL=(e=>(e[e.NONE=0]=`NONE`,e[e.DEBUG=1]=`DEBUG`,e[e.INFO=2]=`INFO`,e[e.WARNING=3]=`WARNING`,e[e.ERROR=4]=`ERROR`,e))(fL||{}),pL=(e=>(e[e.NONE=0]=`NONE`,e[e.CONNECT=1]=`CONNECT`,e[e.DISCONNECT=2]=`DISCONNECT`,e[e.OPEN=3]=`OPEN`,e[e.QUERY=4]=`QUERY`,e[e.INSTANTIATE=5]=`INSTANTIATE`,e))(pL||{}),mL=(e=>(e[e.NONE=0]=`NONE`,e[e.OK=1]=`OK`,e[e.ERROR=2]=`ERROR`,e[e.START=3]=`START`,e[e.RUN=4]=`RUN`,e[e.CAPTURE=5]=`CAPTURE`,e))(mL||{}),hL=(e=>(e[e.NONE=0]=`NONE`,e[e.WEB_WORKER=1]=`WEB_WORKER`,e[e.NODE_WORKER=2]=`NODE_WORKER`,e[e.BINDINGS=3]=`BINDINGS`,e[e.ASYNC_DUCKDB=4]=`ASYNC_DUCKDB`,e))(hL||{}),gL=class{constructor(e=2){this.level=e}log(e){e.level>=this.level&&console.log(e)}},_L=(e=>(e[e.SUCCESS=0]=`SUCCESS`,e[e.MAX_ARROW_ERROR=255]=`MAX_ARROW_ERROR`,e[e.DUCKDB_WASM_RETRY=256]=`DUCKDB_WASM_RETRY`,e))(_L||{}),vL=class{constructor(e,t){this._bindings=e,this._conn=t}get bindings(){return this._bindings}async close(){return this._bindings.disconnect(this._conn)}useUnsafe(e){return e(this._bindings,this._conn)}async query(e){this._bindings.logger.log({timestamp:new Date,level:2,origin:4,topic:4,event:4,value:e});let t=await this._bindings.runQuery(this._conn,e),n=SI.from(t);return console.assert(n.isSync(),`Reader is not sync`),console.assert(n.isFile(),`Reader is not file`),new mF(n)}async send(e,t=!1){this._bindings.logger.log({timestamp:new Date,level:2,origin:4,topic:4,event:4,value:e});let n=await this._bindings.startPendingQuery(this._conn,e,t);for(;n==null;){if(this._bindings.isDetached()){console.error(`cannot send a message since the worker is not set!`);return}n=await this._bindings.pollPendingQuery(this._conn)}let r=new yL(this._bindings,this._conn,n),i=await SI.from(r);return console.assert(i.isAsync()),console.assert(i.isStream()),i}async cancelSent(){return await this._bindings.cancelPendingQuery(this._conn)}async getTableNames(e){return await this._bindings.getTableNames(this._conn,e)}async prepare(e){let t=await this._bindings.createPrepared(this._conn,e);return new bL(this._bindings,this._conn,t)}async insertArrowTable(e,t){let n=$I(e,`stream`);await this.insertArrowFromIPCStream(n,t)}async insertArrowFromIPCStream(e,t){await this._bindings.insertArrowFromIPCStream(this._conn,e,t)}async insertCSVFromPath(e,t){await this._bindings.insertCSVFromPath(this._conn,e,t)}async insertJSONFromPath(e,t){await this._bindings.insertJSONFromPath(this._conn,e,t)}},yL=class{constructor(e,t,n){this.db=e,this.conn=t,this.header=n,this._first=!0,this._depleted=!1,this._inFlight=null}async next(){if(this._first)return this._first=!1,{done:!1,value:this.header};if(this._depleted)return{done:!0,value:null};let e=null;for(this._inFlight!=null&&(e=await this._inFlight,this._inFlight=null);e==null;)e=await this.db.fetchQueryResults(this.conn);return this._depleted=e.length==0,this._depleted||(this._inFlight=this.db.fetchQueryResults(this.conn)),{done:this._depleted,value:e}}[Symbol.asyncIterator](){return this}},bL=class{constructor(e,t,n){this.bindings=e,this.connectionId=t,this.statementId=n}async close(){await this.bindings.closePrepared(this.connectionId,this.statementId)}async query(...e){let t=await this.bindings.runPrepared(this.connectionId,this.statementId,e),n=SI.from(t);return console.assert(n.isSync()),console.assert(n.isFile()),new mF(n)}async send(...e){let t=await this.bindings.sendPrepared(this.connectionId,this.statementId,e),n=new yL(this.bindings,this.connectionId,t),r=await SI.from(n);return console.assert(r.isAsync()),console.assert(r.isStream()),r}},xL=(e=>(e.CANCEL_PENDING_QUERY=`CANCEL_PENDING_QUERY`,e.CLOSE_PREPARED=`CLOSE_PREPARED`,e.COLLECT_FILE_STATISTICS=`COLLECT_FILE_STATISTICS`,e.REGISTER_OPFS_FILE_NAME=`REGISTER_OPFS_FILE_NAME`,e.CONNECT=`CONNECT`,e.COPY_FILE_TO_BUFFER=`COPY_FILE_TO_BUFFER`,e.COPY_FILE_TO_PATH=`COPY_FILE_TO_PATH`,e.CREATE_PREPARED=`CREATE_PREPARED`,e.DISCONNECT=`DISCONNECT`,e.DROP_FILE=`DROP_FILE`,e.DROP_FILES=`DROP_FILES`,e.EXPORT_FILE_STATISTICS=`EXPORT_FILE_STATISTICS`,e.FETCH_QUERY_RESULTS=`FETCH_QUERY_RESULTS`,e.FLUSH_FILES=`FLUSH_FILES`,e.GET_FEATURE_FLAGS=`GET_FEATURE_FLAGS`,e.GET_TABLE_NAMES=`GET_TABLE_NAMES`,e.GET_VERSION=`GET_VERSION`,e.GLOB_FILE_INFOS=`GLOB_FILE_INFOS`,e.INSERT_ARROW_FROM_IPC_STREAM=`INSERT_ARROW_FROM_IPC_STREAM`,e.INSERT_CSV_FROM_PATH=`IMPORT_CSV_FROM_PATH`,e.INSERT_JSON_FROM_PATH=`IMPORT_JSON_FROM_PATH`,e.INSTANTIATE=`INSTANTIATE`,e.OPEN=`OPEN`,e.PING=`PING`,e.POLL_PENDING_QUERY=`POLL_PENDING_QUERY`,e.REGISTER_FILE_BUFFER=`REGISTER_FILE_BUFFER`,e.REGISTER_FILE_HANDLE=`REGISTER_FILE_HANDLE`,e.REGISTER_FILE_URL=`REGISTER_FILE_URL`,e.RESET=`RESET`,e.RUN_PREPARED=`RUN_PREPARED`,e.RUN_QUERY=`RUN_QUERY`,e.SEND_PREPARED=`SEND_PREPARED`,e.START_PENDING_QUERY=`START_PENDING_QUERY`,e.TOKENIZE=`TOKENIZE`,e))(xL||{}),SL=(e=>(e.CONNECTION_INFO=`CONNECTION_INFO`,e.ERROR=`ERROR`,e.FEATURE_FLAGS=`FEATURE_FLAGS`,e.FILE_BUFFER=`FILE_BUFFER`,e.FILE_INFOS=`FILE_INFOS`,e.FILE_SIZE=`FILE_SIZE`,e.FILE_STATISTICS=`FILE_STATISTICS`,e.INSTANTIATE_PROGRESS=`INSTANTIATE_PROGRESS`,e.LOG=`LOG`,e.PROGRESS_UPDATE=`PROGRESS_UPDATE`,e.OK=`OK`,e.PREPARED_STATEMENT_ID=`PREPARED_STATEMENT_ID`,e.QUERY_PLAN=`QUERY_PLAN`,e.QUERY_RESULT=`QUERY_RESULT`,e.QUERY_RESULT_CHUNK=`QUERY_RESULT_CHUNK`,e.QUERY_RESULT_HEADER=`QUERY_RESULT_HEADER`,e.QUERY_RESULT_HEADER_OR_NULL=`QUERY_RESULT_HEADER_OR_NULL`,e.REGISTERED_FILE=`REGISTERED_FILE`,e.SCRIPT_TOKENS=`SCRIPT_TOKENS`,e.SUCCESS=`SUCCESS`,e.TABLE_NAMES=`TABLE_NAMES`,e.VERSION_STRING=`VERSION_STRING`,e))(SL||{}),CL=class{constructor(e,t){this.promiseResolver=()=>{},this.promiseRejecter=()=>{},this.type=e,this.data=t,this.promise=new Promise((e,t)=>{this.promiseResolver=e,this.promiseRejecter=t})}};function wL(e){switch(e.typeId){case Y.Binary:return{sqlType:`binary`};case Y.Bool:return{sqlType:`bool`};case Y.Date:return{sqlType:`date`};case Y.DateDay:return{sqlType:`date32[d]`};case Y.DateMillisecond:return{sqlType:`date64[ms]`};case Y.Decimal:{let t=e;return{sqlType:`decimal`,precision:t.precision,scale:t.scale}}case Y.Float:return{sqlType:`float`};case Y.Float16:return{sqlType:`float16`};case Y.Float32:return{sqlType:`float32`};case Y.Float64:return{sqlType:`float64`};case Y.Int:return{sqlType:`int32`};case Y.Int16:return{sqlType:`int16`};case Y.Int32:return{sqlType:`int32`};case Y.Int64:return{sqlType:`int64`};case Y.Uint16:return{sqlType:`uint16`};case Y.Uint32:return{sqlType:`uint32`};case Y.Uint64:return{sqlType:`uint64`};case Y.Uint8:return{sqlType:`uint8`};case Y.IntervalDayTime:return{sqlType:`interval[dt]`};case Y.IntervalYearMonth:return{sqlType:`interval[m]`};case Y.List:return{sqlType:`list`,valueType:wL(e.valueType)};case Y.FixedSizeBinary:return{sqlType:`fixedsizebinary`,byteWidth:e.byteWidth};case Y.Null:return{sqlType:`null`};case Y.Utf8:return{sqlType:`utf8`};case Y.Struct:return{sqlType:`struct`,fields:e.children.map(e=>TL(e.name,e.type))};case Y.Map:{let t=e;return{sqlType:`map`,keyType:wL(t.keyType),valueType:wL(t.valueType)}}case Y.Time:return{sqlType:`time[s]`};case Y.TimeMicrosecond:return{sqlType:`time[us]`};case Y.TimeMillisecond:return{sqlType:`time[ms]`};case Y.TimeNanosecond:return{sqlType:`time[ns]`};case Y.TimeSecond:return{sqlType:`time[s]`};case Y.Timestamp:return{sqlType:`timestamp`,timezone:e.timezone||void 0};case Y.TimestampSecond:return{sqlType:`timestamp[s]`,timezone:e.timezone||void 0};case Y.TimestampMicrosecond:return{sqlType:`timestamp[us]`,timezone:e.timezone||void 0};case Y.TimestampNanosecond:return{sqlType:`timestamp[ns]`,timezone:e.timezone||void 0};case Y.TimestampMillisecond:return{sqlType:`timestamp[ms]`,timezone:e.timezone||void 0}}throw Error(`unsupported arrow type: ${e.toString()}`)}function TL(e,t){let n=wL(t);return n.name=e,n}var EL=/'(opfs:\/\/\S*?)'/g,DL=/(opfs:\/\/\S*?)/g;function OL(e){return e.search(DL)>-1}function kL(e){return[...e.matchAll(EL)].map(e=>e[1])}var AL=new TextEncoder,jL=class{constructor(e,t=null){this._onInstantiationProgress=[],this._onExecutionProgress=[],this._worker=null,this._workerShutdownPromise=null,this._workerShutdownResolver=()=>{},this._nextMessageId=0,this._pendingRequests=new Map,this._config={},this._logger=e,this._onMessageHandler=this.onMessage.bind(this),this._onErrorHandler=this.onError.bind(this),this._onCloseHandler=this.onClose.bind(this),t!=null&&this.attach(t)}get logger(){return this._logger}get config(){return this._config}attach(e){this._worker=e,this._worker.addEventListener(`message`,this._onMessageHandler),this._worker.addEventListener(`error`,this._onErrorHandler),this._worker.addEventListener(`close`,this._onCloseHandler),this._workerShutdownPromise=new Promise((e,t)=>{this._workerShutdownResolver=e})}detach(){this._worker&&(this._worker.removeEventListener(`message`,this._onMessageHandler),this._worker.removeEventListener(`error`,this._onErrorHandler),this._worker.removeEventListener(`close`,this._onCloseHandler),this._worker=null,this._workerShutdownResolver(null),this._workerShutdownPromise=null,this._workerShutdownResolver=()=>{})}async terminate(){this._worker&&(this._worker.terminate(),this._worker=null,this._workerShutdownPromise=null,this._workerShutdownResolver=()=>{})}async postTask(e,t=[]){if(!this._worker){console.error(`cannot send a message since the worker is not set!:`+e.type+`,`+e.data);return}let n=this._nextMessageId++;return this._pendingRequests.set(n,e),this._worker.postMessage({messageId:n,type:e.type,data:e.data},t),await e.promise}onMessage(e){var t;let n=e.data;switch(n.type){case`PROGRESS_UPDATE`:for(let e of this._onExecutionProgress)e(n.data);return;case`LOG`:this._logger.log(n.data);return;case`INSTANTIATE_PROGRESS`:for(let e of this._onInstantiationProgress)e(n.data);return}let r=this._pendingRequests.get(n.requestId);if(!r){console.warn(`unassociated response: [${n.requestId}, ${n.type.toString()}]`);return}if(this._pendingRequests.delete(n.requestId),n.type==`ERROR`){let e=Error(n.data.message);e.name=n.data.name,(t=Object.getOwnPropertyDescriptor(e,`stack`))!=null&&t.writable&&(e.stack=n.data.stack),r.promiseRejecter(e);return}switch(r.type){case`CLOSE_PREPARED`:case`COLLECT_FILE_STATISTICS`:case`REGISTER_OPFS_FILE_NAME`:case`COPY_FILE_TO_PATH`:case`DISCONNECT`:case`DROP_FILE`:case`DROP_FILES`:case`FLUSH_FILES`:case`INSERT_ARROW_FROM_IPC_STREAM`:case`IMPORT_CSV_FROM_PATH`:case`IMPORT_JSON_FROM_PATH`:case`OPEN`:case`PING`:case`REGISTER_FILE_BUFFER`:case`REGISTER_FILE_HANDLE`:case`REGISTER_FILE_URL`:case`RESET`:if(n.type==`OK`){r.promiseResolver(n.data);return}break;case`INSTANTIATE`:if(this._onInstantiationProgress=[],n.type==`OK`){r.promiseResolver(n.data);return}break;case`GLOB_FILE_INFOS`:if(n.type==`FILE_INFOS`){r.promiseResolver(n.data);return}break;case`GET_VERSION`:if(n.type==`VERSION_STRING`){r.promiseResolver(n.data);return}break;case`GET_FEATURE_FLAGS`:if(n.type==`FEATURE_FLAGS`){r.promiseResolver(n.data);return}break;case`GET_TABLE_NAMES`:if(n.type==`TABLE_NAMES`){r.promiseResolver(n.data);return}break;case`TOKENIZE`:if(n.type==`SCRIPT_TOKENS`){r.promiseResolver(n.data);return}break;case`COPY_FILE_TO_BUFFER`:if(n.type==`FILE_BUFFER`){r.promiseResolver(n.data);return}break;case`EXPORT_FILE_STATISTICS`:if(n.type==`FILE_STATISTICS`){r.promiseResolver(n.data);return}break;case`CONNECT`:if(n.type==`CONNECTION_INFO`){r.promiseResolver(n.data);return}break;case`RUN_PREPARED`:case`RUN_QUERY`:if(n.type==`QUERY_RESULT`){r.promiseResolver(n.data);return}break;case`SEND_PREPARED`:if(n.type==`QUERY_RESULT_HEADER`){r.promiseResolver(n.data);return}break;case`START_PENDING_QUERY`:if(n.type==`QUERY_RESULT_HEADER_OR_NULL`){r.promiseResolver(n.data);return}break;case`POLL_PENDING_QUERY`:if(n.type==`QUERY_RESULT_HEADER_OR_NULL`){r.promiseResolver(n.data);return}break;case`CANCEL_PENDING_QUERY`:if(this._onInstantiationProgress=[],n.type==`SUCCESS`){r.promiseResolver(n.data);return}break;case`FETCH_QUERY_RESULTS`:if(n.type==`QUERY_RESULT_CHUNK`){r.promiseResolver(n.data);return}break;case`CREATE_PREPARED`:if(n.type==`PREPARED_STATEMENT_ID`){r.promiseResolver(n.data);return}break}r.promiseRejecter(Error(`unexpected response type: ${n.type.toString()}`))}onError(e){console.error(e),console.error(`error in duckdb worker: ${e.message}`),this._pendingRequests.clear()}onClose(){if(this._workerShutdownResolver(null),this._pendingRequests.size!=0){console.warn(`worker terminated with ${this._pendingRequests.size} pending requests`);return}this._pendingRequests.clear()}isDetached(){return!this._worker}async reset(){let e=new CL(`RESET`,null);return await this.postTask(e)}async ping(){let e=new CL(`PING`,null);await this.postTask(e)}async dropFile(e){let t=new CL(`DROP_FILE`,e);return await this.postTask(t)}async dropFiles(e){let t=new CL(`DROP_FILES`,e);return await this.postTask(t)}async flushFiles(){let e=new CL(`FLUSH_FILES`,null);return await this.postTask(e)}async instantiate(e,t=null,n=e=>{}){this._onInstantiationProgress.push(n);let r=new CL(`INSTANTIATE`,[e,t]);return await this.postTask(r)}async getVersion(){let e=new CL(`GET_VERSION`,null);return await this.postTask(e)}async getFeatureFlags(){let e=new CL(`GET_FEATURE_FLAGS`,null);return await this.postTask(e)}async open(e){this._config=e;let t=new CL(`OPEN`,e);await this.postTask(t)}async tokenize(e){let t=new CL(`TOKENIZE`,e);return await this.postTask(t)}async connectInternal(){let e=new CL(`CONNECT`,null);return await this.postTask(e)}async connect(){let e=await this.connectInternal();return new vL(this,e)}async disconnect(e){let t=new CL(`DISCONNECT`,e);await this.postTask(t)}async runQuery(e,t){if(this.shouldOPFSFileHandling()){let n=await this.registerOPFSFileFromSQL(t);try{return await this._runQueryAsync(e,t)}finally{n.length>0&&await this.dropFiles(n)}}else return await this._runQueryAsync(e,t)}async _runQueryAsync(e,t){let n=new CL(`RUN_QUERY`,[e,t]);return await this.postTask(n)}async startPendingQuery(e,t,n=!1){if(this.shouldOPFSFileHandling()){let r=await this.registerOPFSFileFromSQL(t);try{return await this._startPendingQueryAsync(e,t,n)}finally{r.length>0&&await this.dropFiles(r)}}else return await this._startPendingQueryAsync(e,t,n)}async _startPendingQueryAsync(e,t,n=!1){let r=new CL(`START_PENDING_QUERY`,[e,t,n]);return await this.postTask(r)}async pollPendingQuery(e){let t=new CL(`POLL_PENDING_QUERY`,e);return await this.postTask(t)}async cancelPendingQuery(e){let t=new CL(`CANCEL_PENDING_QUERY`,e);return await this.postTask(t)}async fetchQueryResults(e){let t=new CL(`FETCH_QUERY_RESULTS`,e);return await this.postTask(t)}async getTableNames(e,t){let n=new CL(`GET_TABLE_NAMES`,[e,t]);return await this.postTask(n)}async createPrepared(e,t){let n=new CL(`CREATE_PREPARED`,[e,t]);return await this.postTask(n)}async closePrepared(e,t){let n=new CL(`CLOSE_PREPARED`,[e,t]);await this.postTask(n)}async runPrepared(e,t,n){let r=new CL(`RUN_PREPARED`,[e,t,n]);return await this.postTask(r)}async sendPrepared(e,t,n){let r=new CL(`SEND_PREPARED`,[e,t,n]);return await this.postTask(r)}async globFiles(e){let t=new CL(`GLOB_FILE_INFOS`,e);return await this.postTask(t)}async registerFileText(e,t){let n=AL.encode(t);await this.registerFileBuffer(e,n)}async registerFileURL(e,t,n,r){t===void 0&&(t=e);let i=new CL(`REGISTER_FILE_URL`,[e,t,n,r]);await this.postTask(i)}async registerEmptyFileBuffer(e){}async registerFileBuffer(e,t){let n=new CL(`REGISTER_FILE_BUFFER`,[e,t]);await this.postTask(n,[t.buffer])}async registerFileHandle(e,t,n,r){let i=new CL(`REGISTER_FILE_HANDLE`,[e,t,n,r]);await this.postTask(i,[])}async registerOPFSFileName(e){let t=new CL(`REGISTER_OPFS_FILE_NAME`,[e]);await this.postTask(t,[])}async collectFileStatistics(e,t){let n=new CL(`COLLECT_FILE_STATISTICS`,[e,t]);await this.postTask(n,[])}async exportFileStatistics(e){let t=new CL(`EXPORT_FILE_STATISTICS`,e);return await this.postTask(t,[])}async copyFileToBuffer(e){let t=new CL(`COPY_FILE_TO_BUFFER`,e);return await this.postTask(t)}async copyFileToPath(e,t){let n=new CL(`COPY_FILE_TO_PATH`,[e,t]);await this.postTask(n)}async insertArrowFromIPCStream(e,t,n){if(t.length==0)return;let r=new CL(`INSERT_ARROW_FROM_IPC_STREAM`,[e,t,n]);await this.postTask(r,[t.buffer])}async insertCSVFromPath(e,t,n){if(n.columns!==void 0){let e=[];for(let t in n.columns){let r=n.columns[t];e.push(TL(t,r))}n.columnsFlat=e,delete n.columns}let r=new CL(`IMPORT_CSV_FROM_PATH`,[e,t,n]);await this.postTask(r)}async insertJSONFromPath(e,t,n){if(n.columns!==void 0){let e=[];for(let t in n.columns){let r=n.columns[t];e.push(TL(t,r))}n.columnsFlat=e,delete n.columns}let r=new CL(`IMPORT_JSON_FROM_PATH`,[e,t,n]);await this.postTask(r)}shouldOPFSFileHandling(){return OL(this.config.path??``)?this.config.opfs?.fileHandling==`auto`:!1}async registerOPFSFileFromSQL(e){let t=kL(e),n=[];for(let e of t)try{await this.registerOPFSFileName(e),n.push(e)}catch(t){throw console.error(t),Error(`File Not found:`+e)}return n}};function ML(){let e=new TextDecoder;return t=>(typeof SharedArrayBuffer<`u`&&t.buffer instanceof SharedArrayBuffer&&(t=new Uint8Array(t)),e.decode(t))}ML();var NL=(e=>(e[e.BUFFER=0]=`BUFFER`,e[e.NODE_FS=1]=`NODE_FS`,e[e.BROWSER_FILEREADER=2]=`BROWSER_FILEREADER`,e[e.BROWSER_FSACCESS=3]=`BROWSER_FSACCESS`,e[e.HTTP=4]=`HTTP`,e[e.S3=5]=`S3`,e))(NL||{}),PL={name:`@duckdb/duckdb-wasm`,version:`1.33.1-dev45.0`,description:`DuckDB powered by WebAssembly`,license:`MIT`,repository:{type:`git`,url:`https://github.com/duckdb/duckdb-wasm.git`},keywords:[`sql`,`duckdb`,`relational`,`database`,`data`,`query`,`wasm`,`analytics`,`olap`,`arrow`,`parquet`,`json`,`csv`],dependencies:{"apache-arrow":`^17.0.0`,qs:`^6.14.1`},devDependencies:{"@types/emscripten":`^1.39.10`,"@types/jasmine":`^5.1.13`,"@typescript-eslint/eslint-plugin":`^6.21.0`,"@typescript-eslint/parser":`^6.21.0`,esbuild:`^0.20.2`,eslint:`^8.57.0`,"eslint-plugin-jasmine":`^4.1.3`,"eslint-plugin-react":`^7.37.5`,"fast-glob":`^3.3.2`,jasmine:`^5.13.0`,"jasmine-core":`^5.1.2`,"jasmine-spec-reporter":`^7.0.0`,"js-sha256":`^0.11.1`,karma:`^6.4.2`,"karma-chrome-launcher":`^3.2.0`,"karma-coverage":`^2.2.1`,"karma-firefox-launcher":`^2.1.3`,"karma-jasmine":`^5.1.0`,"karma-jasmine-html-reporter":`^2.1.0`,"karma-sourcemap-loader":`^0.4.0`,"karma-spec-reporter":`^0.0.36`,"make-dir":`^4.0.0`,nyc:`^15.1.0`,prettier:`^3.2.5`,puppeteer:`^22.8.0`,rimraf:`^5.0.5`,s3rver:`^3.7.1`,typedoc:`^0.28.15`,typescript:`^5.3.3`,"wasm-feature-detect":`^1.6.1`,"web-worker":`^1.2.0`},scripts:{"build:debug":`node bundle.mjs debug && tsc --emitDeclarationOnly`,"build:release":`node bundle.mjs release && tsc --emitDeclarationOnly`,docs:`typedoc`,format:`prettier --write "**/*.+(js|ts)"`,report:`node ./coverage.mjs`,"test:node":`node --enable-source-maps ../../node_modules/jasmine/bin/jasmine ./dist/tests-node.cjs`,"test:node:debug":`node --inspect-brk --enable-source-maps ../../node_modules/jasmine/bin/jasmine ./dist/tests-node.cjs`,"test:node:coverage":`nyc -r json --report-dir ./coverage/node node ../../node_modules/jasmine/bin/jasmine ./dist/tests-node.cjs`,"test:firefox":`karma start ./karma/tests-firefox.cjs`,"test:chrome":`karma start ./karma/tests-chrome.cjs`,"test:chrome:eh":`karma start ./karma/tests-chrome-eh.cjs`,"test:chrome:coverage":`karma start ./karma/tests-chrome-coverage.cjs`,"test:browser":`karma start ./karma/tests-all.cjs`,"test:browser:debug":`karma start ./karma/tests-debug.cjs`,test:`npm run test:chrome && npm run test:node`,"test:coverage":`npm run test:chrome:coverage && npm run test:node:coverage && npm run report`,lint:`eslint src test`},files:[`dist`,`!dist/tests-*`,`!dist/duckdb-browser-mvp.worker.js.map`,`!dist/types/test`],main:`dist/duckdb-browser.cjs`,module:`dist/duckdb-browser.mjs`,types:`dist/duckdb-browser.d.ts`,jsdelivr:`dist/duckdb-browser.cjs`,unpkg:`dist/duckdb-browser.mjs`,sideEffects:!1,browser:{fs:!1,path:!1,perf_hooks:!1,os:!1,worker_threads:!1},exports:{"./dist/duckdb-mvp.wasm":`./dist/duckdb-mvp.wasm`,"./dist/duckdb-eh.wasm":`./dist/duckdb-eh.wasm`,"./dist/duckdb-coi.wasm":`./dist/duckdb-coi.wasm`,"./dist/duckdb-browser":`./dist/duckdb-browser.mjs`,"./dist/duckdb-browser.cjs":`./dist/duckdb-browser.cjs`,"./dist/duckdb-browser.mjs":`./dist/duckdb-browser.mjs`,"./dist/duckdb-browser-coi.pthread.worker.js":`./dist/duckdb-browser-coi.pthread.worker.js`,"./dist/duckdb-browser-coi.worker.js":`./dist/duckdb-browser-coi.worker.js`,"./dist/duckdb-browser-eh.worker.js":`./dist/duckdb-browser-eh.worker.js`,"./dist/duckdb-browser-mvp.worker.js":`./dist/duckdb-browser-mvp.worker.js`,"./dist/duckdb-node":`./dist/duckdb-node.cjs`,"./dist/duckdb-node.cjs":`./dist/duckdb-node.cjs`,"./dist/duckdb-node-blocking":`./dist/duckdb-node-blocking.cjs`,"./dist/duckdb-node-blocking.cjs":`./dist/duckdb-node-blocking.cjs`,"./dist/duckdb-node-eh.worker.cjs":`./dist/duckdb-node-eh.worker.cjs`,"./dist/duckdb-node-mvp.worker.cjs":`./dist/duckdb-node-mvp.worker.cjs`,"./blocking":{node:{types:`./dist/duckdb-node-blocking.d.ts`,require:`./dist/duckdb-node-blocking.cjs`,import:`./dist/duckdb-node-blocking.cjs`},types:`./dist/duckdb-node-blocking.d.ts`,import:`./dist/duckdb-node-blocking.mjs`,require:`./dist/duckdb-node-blocking.cjs`},".":{browser:{types:`./dist/duckdb-browser.d.ts`,import:`./dist/duckdb-browser.mjs`,require:`./dist/duckdb-browser.cjs`},node:{types:`./dist/duckdb-node.d.ts`,import:`./dist/duckdb-node.cjs`,require:`./dist/duckdb-node.cjs`},types:`./dist/duckdb-browser.d.ts`,import:`./dist/duckdb-browser.mjs`,require:`./dist/duckdb-browser.cjs`}}};PL.name,PL.version;var FL=PL.version.split(`.`);FL[0],FL[1],FL[2],cL(lL());var IL=``+new URL(`assets/duckdb-browser-eh.worker--3HUwN9R.js`,__kymoscopeScriptUrl).href,LL=``+new URL(`assets/duckdb-eh-D-nnNw7L.wasm.gz`,__kymoscopeScriptUrl).href;async function RL(e){if(!e.endsWith(`.gz`))return e;let t=await fetch(e);if(!t.ok)throw Error(`DuckDB-WASM did not load (${t.status})`);let n=new Uint8Array(await t.arrayBuffer());return n[0]===31&&n[1]===139&&(n=new Uint8Array(await new Response(new Blob([n]).stream().pipeThrough(new DecompressionStream(`gzip`))).arrayBuffer())),URL.createObjectURL(new Blob([n],{type:`application/wasm`}))}var zL=null;function BL(){return zL||(zL=(async()=>{let e=e=>new URL(e,location.href).href,t=URL.createObjectURL(new Blob([`importScripts(${JSON.stringify(e(IL))});`],{type:`text/javascript`})),n=new Worker(t),r=new jL(new gL(fL.WARNING),n),i=await RL(e(LL));await r.instantiate(i,null),URL.revokeObjectURL(t),i.startsWith(`blob:`)&&URL.revokeObjectURL(i);let a=await r.connect();return await a.query(`SET checkpoint_threshold = '1TB'`),await a.query(`SET autoinstall_known_extensions = false`),await a.query(`SET autoload_known_extensions = false`),await a.close(),r})(),zL)}function VL(e){return`"`+e.replace(/"/g,`""`)+`"`}function HL(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=VL(e.xcol),r=VL(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 ${VL(e.table)} WHERE ${n} BETWEEN ? AND ? GROUP BY 1 ORDER BY 1`,params:[e.x0,t,e.maxPoints,e.x0,e.x1]}}function UL(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=VL(e.xcol),r=VL(e.table);return{sql:`SELECT least(floor((${n} - ?) / ?), ? - 1) AS b, ${e.ycols.map((e,t)=>`min(${VL(e)}) AS y${t}lo, max(${VL(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 WL=`__kym_bin`;function GL(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=VL(e.xcol),n=VL(e.srcTable);return`CREATE OR REPLACE TABLE ${VL(e.dstTable)} AS SELECT ${`CAST(floor((${t} - ${JL(e.x0base)}) / ${JL(e.binWidth)}) AS BIGINT)`} AS ${WL}, ${e.ycols.map(e=>`min(${VL(e)}) AS ${VL(e+`__lo`)}, max(${VL(e)}) AS ${VL(e+`__hi`)}`).join(`, `)} FROM ${n} WHERE ${t} IS NOT NULL GROUP BY 1`}function KL(e){let t=VL(e.srcTable);return`CREATE OR REPLACE TABLE ${VL(e.dstTable)} AS SELECT CAST(floor(${WL} / 2.0) AS BIGINT) AS ${WL}, ${e.ycols.map(e=>`min(${VL(e+`__lo`)}) AS ${VL(e+`__lo`)}, max(${VL(e+`__hi`)}) AS ${VL(e+`__hi`)}`).join(`, `)} FROM ${t} GROUP BY 1`}function qL(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=VL(e.levelTable);return{sql:`SELECT least(greatest(CAST(floor(? + ${WL} * ?) AS BIGINT), 0), ?) AS b, ${e.ycols.map((e,t)=>`min(${VL(e+`__lo`)}) AS y${t}lo, max(${VL(e+`__hi`)}) AS y${t}hi`).join(`, `)} FROM ${o} WHERE ${WL} BETWEEN ? AND ? GROUP BY 1 ORDER BY 1`,params:[r,n,e.maxPoints-1,i,a]}}function JL(e){if(!Number.isFinite(e))throw Error(`num: value must be finite`);return Number.isInteger(e)?String(e):e.toExponential(17)}function YL(e){let t=VL(e.table);return e.range?{sql:`SELECT count(*) AS n FROM ${t} WHERE ${VL(e.range.xcol)} BETWEEN ? AND ?`,params:[e.range.x0,e.range.x1]}:{sql:`SELECT count(*) AS n FROM ${t}`,params:[]}}function XL(e){if(!Number.isInteger(e.stride)||e.stride<1)throw Error(`buildSampleRowsSql: stride must be a positive integer`);let t=VL(e.table),n=e.range?` WHERE ${VL(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 ZL(e){return`'`+e.replace(/'/g,`''`)+`'`}function QL(e){let t=e.columnNames.map(ZL).join(`, `),n=e.delim===` `?`'\\t'`:ZL(e.delim),r=e.decimalComma?`decimal_separator=',', `:``;return`SELECT * FROM read_csv(${ZL(e.handle)}, header=false, skip=${e.dataStartRow}, delim=${n}, `+r+`names=[${t}], auto_type_candidates=['DOUBLE', 'VARCHAR'])`}function $L(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 eR=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}};xE();var tR=0,nR=()=>`t_${++tR}`,rR=5e4,iR=65536,aR=512,oR=2;function sR(e){return e<1?1:2**Math.floor(Math.log2(e))}var cR=class e{#e;#t;#n;#r;#i=new eR(96);#a=new Map;#o=new Map;#s=[];#c=0;constructor(e,t,n){this.#e=e,this.#t=t,this.#n=n,this.#r=new Set(t.map(e=>e.name))}static async open(t,n){let r=await BL(),i=await r.connect(),a=await t.slice(0,256*1024).text(),o=aE(a),s=cE(a),c=lE(o,s.headerRow),l=s.unitsRow===null?``:o[s.unitsRow]??``,u=eE(o[s.headerRow]??``),d=$T(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=nR(),m=QL({handle:`input.csv`,columnNames:c,delim:u,dataStartRow:s.dataStartRow,decimalComma:d});await i.query(`CREATE OR REPLACE TABLE ${VL(p)} AS ${m}`),await r.dropFile(`input.csv`).catch(()=>{});let h=l?l.split(u).map(e=>e.trim()):[],g=new Map;c.forEach((e,t)=>g.set(e,h[t]??``));let _=await e.attach(i,p,g);return n?.({phase:`done`,message:`Ready.`}),_}static async attach(t,n,r){return new e(t,(await t.query(`DESCRIBE ${VL(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}=HL({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 $L((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)??UL({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/oR,a=null;for(let t of e.levels)t.binWidth<=i&&(a=t);return a?qL({levelTable:a.table,ycols:t,x0base:e.x0base,binWidth:a.binWidth,x0:n.x0,x1:n.x1,maxPoints:r}):null}async#d(e){if(!this.#r.has(e))return null;let t=await(await BL()).connect();try{let n=YL({table:this.#n}),r=await t.query(n.sql),i=Number(r.getChild(`n`)?.get(0)??0);if(i<rR)return null;let a=await t.query(`SELECT min(${VL(e)}) AS lo, max(${VL(e)}) AS hi FROM ${VL(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(iR,sR(i));if(u<aR*2)return null;let d=++this.#c,f=[],p=u,m=0,h=`${this.#n}_p${d}_0`;await t.query(GL({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>=aR;){p/=2,m+=1;let e=`${this.#n}_p${d}_${m}`;await t.query(KL({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=YL({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}=XL({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(${VL(e)} AS DOUBLE), 'NaN'::DOUBLE) AS "c${t}"`).join(`, `),a=await this.#e.prepare(`SELECT ${i} FROM ${VL(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(${VL(e)}) AS lo, max(${VL(e)}) AS hi FROM ${VL(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 ${VL(e)}`)}catch{}try{await this.#e.query(`DROP TABLE IF EXISTS ${VL(this.#n)}`)}catch{}await this.#e.close()}};xE();var lR=1e8,uR=256*1024;function dR(e,t,n=0,r=lR){return e>314572800||n+t>r?`duckdb`:`memory`}function fR(e,t){let n=aE(t);t.length<e&&n.length>1&&(n=n.slice(0,-1));try{let t=cE(n.join(`
|
|
76
76
|
`)),r=lE(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)}}xE(),Qe();var pR=12e3;async function mR(e,t,n){let r=cE(n),i=typeof Worker>`u`?uE(n,r):await EE({rawText:n,config:r}),a=new VE(i);return{id:e,name:t,kind:`memory`,source:a,schema:await a.getSchema(),data:i,rawText:n,parseConfig:r}}async function hR(e,t,n,r,i=e=>e.text(),a){let o=cE(r),s=typeof Worker>`u`?await DE({rawText:await i(n),config:o},a):await DE({file:n,config:o},a),c=new VE(s);return{id:e,name:t,kind:`memory`,source:c,schema:await c.getSchema(),data:s,rawText:r,file:n,parseConfig:o}}async function gR(e,t,n){let r=await cR.open(t,n),i=await r.getSchema(),a=await r.sampleRows(pR),o={meta:``,columnNames:i.map(e=>e.name),units:i.map(e=>e.unit),rows:a},s=await t.slice(0,uR).text();return{id:e,name:t.name,kind:`duckdb`,source:r,schema:i,data:o,rawText:s,parseConfig:cE(s)}}async function _R(e,t,n,r,i=0,a){let o=await t.slice(0,uR).text();return dR(t.size,fR(t.size,o),i)===`memory`?hR(e,t.name,t,o,e=>n(e),a):gR(e,t,r)}function vR(e,t){return e instanceof File&&e.name===t.name&&e.size===t.size&&e.lastModified===t.lastModified}async function yR(e,t,n){let r=n.find(e=>e.kind===`memory`&&e.parseConfig&&vR(e.file,t)&&Ge(e.data.rows));if(!r)return null;let i=await t.slice(0,uR).text();if(!oE(r.parseConfig,cE(i)))return null;let a={...r.data,rows:qe(Ge(r.data.rows))};return{id:e,name:t.name,kind:`memory`,source:new VE(a),schema:r.schema,data:a,rawText:r.rawText,file:t,parseConfig:r.parseConfig}}function bR(e){let t=new Set,n=0;for(let r of e){if(r.kind!==`memory`)continue;let e=Ge(r.data.rows)??r.data.rows;t.has(e)||(t.add(e),n+=r.data.rows.length*r.data.columnNames.length)}return n}function xR(e,t,n=!0){let r=e.getUint32(n?t:t+4,n);return e.getUint32(n?t+4:t,n)*4294967296+r}function SR(e,t,n=!0){let r=e.getUint32(n?t:t+4,n);return e.getInt32(n?t+4:t,n)*4294967296+r}function CR(e,t=!1){let n=e.indexOf(0);return(t?DR:ER).decode(n<0?e:e.subarray(0,n))}function wR(e,t,n=0){if(e.length<n+t.length)return!1;for(let r=0;r<t.length;r++)if(e[n+r]!==t.charCodeAt(r))return!1;return!0}var TR,ER,DR,OR,kR,AR=c((()=>{TR=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),ER=new TextDecoder(`utf-8`),DR=new TextDecoder(`latin1`),OR=e=>DR.decode(e),kR=e=>ER.decode(e)})),jR,MR=c((()=>{AR(),jR={id:`mdf`,label:`ASAM MDF (MF4, MDF 3)`,extensions:[`.mf4`,`.mdf`,`.mf3`,`.dat`],companions:[{ext:`.dbc`,anyName:!0}],sniff:e=>wR(e,`MDF `)||wR(e,`UnFinMF `)}})),NR,PR=c((()=>{AR(),NR={id:`edf`,label:`EDF / BDF (+)`,extensions:[`.edf`,`.bdf`,`.rec`],sniff:e=>wR(e,`0 `)||e[0]===255&&wR(e,`BIOSEMI`,1)}})),FR,IR=c((()=>{AR(),FR={id:`xdf`,label:`XDF (Lab Streaming Layer)`,extensions:[`.xdf`],sniff:e=>wR(e,`XDF:`)}})),LR,RR=c((()=>{AR(),LR={id:`tdms`,label:`NI TDMS`,extensions:[`.tdms`],companions:[{ext:`.tdms_index`}],sniff:e=>wR(e,`TDSm`)}})),zR,BR=c((()=>{AR(),zR={id:`mat`,label:`MATLAB MAT (v5, v7.3)`,extensions:[`.mat`],sniff:e=>wR(e,`MATLAB 5.0 MAT-file`)||wR(e,`MATLAB 7.3 MAT-file`)}})),VR,HR,UR,WR=c((()=>{AR(),VR=`HDF\r
|
|
77
77
|
|
|
78
|
-
`,HR=e=>[0,512,1024,2048].some(t=>wR(e,VR,t)),UR={id:`hdf5`,label:`HDF5`,extensions:[`.h5`,`.hdf5`,`.hdf`,`.he5`,`.nc`],sniff:HR}})),GR,KR=c((()=>{AR(),GR={id:`comtrade`,label:`COMTRADE (IEEE C37.111)`,extensions:[`.cfg`,`.cff`],companions:[{ext:`.dat`}],sniff:e=>{let t=OR(e.subarray(0,512));if(/^---\s*file type:\s*CFG/i.test(t))return!0;let n=t.split(/\r?\n/);return n.length>2&&/^\s*\d+\s*,\s*\d+A\s*,\s*\d+D\s*$/i.test(n[1])}}}));MR(),PR(),IR(),RR(),BR(),WR(),KR();var qR=4096,JR=[`.dat`,`.txt`,`.csv`,`.tsv`],YR=[jR,NR,FR,LR,zR,UR,GR],XR=e=>{let t=e.lastIndexOf(`.`);return t<=0?``:e.slice(t).toLowerCase()},ZR=e=>{let t=e.lastIndexOf(`.`);return(t<=0?e:e.slice(0,t)).toLowerCase()};async function QR(e){let t=new Uint8Array(await e.slice(0,qR).arrayBuffer()),n=XR(e.name),r=YR.filter(e=>e.extensions.includes(n));for(let n of[...r,...YR.filter(e=>!r.includes(e))])if(n.sniff(t,e.name))return n;return null}async function $R(e){return new Uint8Array(await e.slice(0,qR).arrayBuffer()).includes(0)}async function ez(e){let t=await Promise.all(e.map(QR)),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]&&XR(e.name)===n.ext),o=a.find(e=>ZR(e.name)===ZR(i.main.name))??(n.anyName&&a.length===1?a[0]:void 0);o&&(i.companions.push(o),r.add(o))}let i=new Set(YR.flatMap(e=>(e.companions??[]).map(e=>e.ext))),a=[];for(let t of e){if(r.has(t))continue;let e=XR(t.name);e===`.dat`&&await $R(t)?a.push({file:t.name,error:Error(`This COMTRADE .dat needs its .cfg file — drop both together.`)}):JR.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 tz=[...new Set([...JR,...YR.flatMap(e=>[...e.extensions,...(e.companions??[]).map(e=>e.ext)])])];function nz(e){let t=0;for(let n=0;n<e.length;n++)e[n]!==e[n]&&t++;if(t===0)return ZM(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 ZM(TM({type:new Ak,data:e,nullBitmap:n,length:e.length,nullCount:t}))}var rz=122880,iz=class{#e;#t;#n;#r=!1;#i=[];#a=0;#o;rows=0;constructor(e,t,n,r=rz){this.#e=e,this.#t=t,this.#n=new fN(n.map(e=>new pN(e.name,e.text?new Nk:new Ak,!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?nz(i.subarray(0,t)):sF(i.slice(0,t),new Nk)).data[0]});this.#i.push(new gF(this.#n,TM({type:new Wk(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 mF(this.#n,this.#i);this.#i=[],this.#a=0,await this.#e.insertArrowTable(e,{name:this.#t,create:!this.#r}),this.#r=!0}};function az(e){let t=e.notes;for(let n of e.groups){n.name=hz(String(n.name),uz);for(let e of n.channels)e.name=hz(String(e.name),uz),e.unit=hz(String(e.unit??``),dz);Number.isInteger(n.samples)&&n.samples>=-1||(n.samples=-1),n.rateHz===null||Number.isFinite(n.rateHz)&&n.rateHz>0||(n.rateHz=null),n.time.kind===`rate`&&!(Number.isFinite(n.time.rate)&&n.time.rate>0&&Number.isFinite(n.time.start))&&(t.push(`${n.name}: its sample rate in the file is not usable; samples are numbered instead.`),n.time={kind:`index`},n.rateHz=null)}t.length>pz&&t.splice(pz,t.length-pz,`${t.length-pz} more notes.`),e.notes=t.map(e=>hz(String(e),fz));let n={};for(let[t,r]of Object.entries(e.meta).slice(0,mz))n[hz(t,uz)]=hz(String(r),fz);return e.meta=n,e.events=e.events.filter(e=>Number.isFinite(e.time)).map(e=>({time:e.time,text:hz(String(e.text),fz)})),e}function oz(e){return e instanceof Error&&(e.constructor===Error||e.name===`KymoscopeError`||e.name===`AbortError`)?e:Error(sz)}var sz,cz,lz,uz,dz,fz,pz,mz,hz,gz=c((()=>{sz=`This file couldn't be read (it may be damaged).`,cz=1032,lz=e=>e*cz+1024,uz=256,dz=64,fz=1e3,pz=100,mz=200,hz=(e,t)=>e.length>t?`${e.slice(0,t-1)}…`:e}));gz();var _z=`This file's groups do not interleave in time: reading them together would hold too much in memory. Choose fewer groups, or split them.`,vz=e=>e.length*(1+e.columns.length);function yz(e){let t=e[Symbol.asyncIterator]();return{pull:async()=>{let e=await t.next();return e.done?null:e.value}}}function bz(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-=vz(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+=vz(o.value))>128e6))throw Error(_z)}};return n.map((e,t)=>({pull:()=>a(t)}))}function xz(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 Sz=new Int32Array,Cz={t:new Float64Array,cols:[],from:0};function wz(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 Tz=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=Ez(xz(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(_z)}};function Ez(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 Dz(e,t){let n=e.length,r=e.map(e=>e.t),i=Int32Array.from(e,e=>e.from),a=Int32Array.from(e,e=>wz(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 Oz(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 kz(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];Oz(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}Oz(e,d,u,p,l-1,c[p]),o=c[l-1],t=d[u+l-1]}e.fill(t,o,e.length)}function Az(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 jz(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):Sz}function Mz(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=wz(i,e,r.from,i.length),o=new Int32Array(a-r.from);if(c.push(jz(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 Az(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),kz(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 Nz(e,t,n,r,i,a=!1){let o=e.map((e,r)=>new Tz(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=Dz(l.map(e=>e.pending[0]??Cz),e),n=[t];for(let e=0;e<o.length;e++)n.push(...Mz(o[e],t,c[e],u&&c[e],a));d+=t.length,t.length&&await r({length:t.length,columns:n})}return d}var Pz=class{#e;#t;#n;#r=0;constructor(e,t){let n=Math.max(1024,t);this.#e=e.map(e=>e.name),this.#t=e.map(()=>new Float64Array(n)),this.#n=e.map(()=>null)}append(e){let t=this.#r,n=t+e.length;if(n>this.#t[0].length){let e=Math.max(n,Math.ceil(this.#t[0].length*1.5));this.#t=this.#t.map(n=>{let r=new Float64Array(e);return r.set(n.subarray(0,t)),r})}e.columns.forEach((n,r)=>{let i=this.#t[r];if(n instanceof Float64Array){i.set(n.subarray(0,e.length),t);return}let a=this.#n[r];for(let o=0;o<e.length;o++){i[t+o]=NaN;let e=n[o];e!=null&&((a??=this.#n[r]=[])[t+o]=e)}}),this.#r=n}table(){let e=this.#r,t=this.#t.map(t=>t.length-e>t.length/100?t.slice(0,e):t.subarray(0,e));return{keys:this.#e,length:e,values:t,text:this.#n}}};function Fz(e,t=[`Time`]){let n=new Set(t.map(e=>e.toLowerCase())),r=new Map;return e.map(e=>{let t=e.trim()||`Channel`,i=t.toLowerCase(),a=t,o=r.get(i)??2;if(n.has(i)){for(;n.has(`${i} (${o})`);)o++;a=`${t} (${o++})`}return r.set(i,o),n.add(a.toLowerCase()),a})}var Iz=c((()=>{}));gz(),Iz();async function Lz(e,t,n){return az(await e.plan(t,n))}var Rz=(e,t,n)=>Math.max(0,Math.min(e,Math.max(1<<20,n),Math.floor(1e8/t)));function zz(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=Fz(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 Bz(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 Vz(e,t,n){let r=Bz(e,t);return r<0?Math.ceil(n/4):r*(1+t.reduce((e,t)=>e+t.channels.length,0))}async function Hz(e,t,n,r,i,a,o={}){let s=zz(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=>yz(d(e.streamGroup({...f,selection:[t]},t.group)))):bz(d(e.stream(f)),new Map(i.map((e,t)=>[e.group,t]))),m=Bz(n,i),h=a===`memory`?new Pz(s,Rz(m,s.length,r.size)):null,g=0,_=await Nz(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 Uz,Wz,Gz,Kz,qz=c((()=>{Uz=1<<20,Wz=64,Gz=16<<20,Kz=class{size;bytesRead=0;#e;#t=new Map;constructor(e){this.#e=e,this.size=e.size}async read(e,t){let n=Math.min(this.size,e+t);if(n<=e)return new Uint8Array;if(n-e>Uz)return this.slice(e,n-e);let r=Math.floor(e/Uz),i=Math.floor((n-1)/Uz),a=await this.#n(r);if(r===i)return a.subarray(e-r*Uz,n-r*Uz);let o=new Uint8Array(n-e),s=a.subarray(e-r*Uz);return o.set(s),o.set((await this.#n(i)).subarray(0,n-i*Uz),s.length),o}async slice(e,t){let n=Math.min(this.size,e+t);if(n<=e)return new Uint8Array;let r=new Uint8Array(await this.#e.slice(e,n).arrayBuffer());return this.bytesRead+=r.length,r}async*windows(e,t,n=Gz){let r=Math.min(this.size,e+t);for(let t=e;t<r;t+=n)yield{offset:t,bytes:await this.slice(t,Math.min(n,r-t))}}async#n(e){let t=this.#t.get(e);if(t)return this.#t.delete(e),this.#t.set(e,t),t;let n=await this.slice(e*Uz,Uz);return this.#t.size>=Wz&&this.#t.delete(this.#t.keys().next().value),this.#t.set(e,n),n}}}));qz();var Jz=``+new URL(`assets/importer.worker-BblHvxro.js`,__kymoscopeScriptUrl).href,Yz=``+new URL(`assets/h5wasmModule-BCQWU2Gw.js`,__kymoscopeScriptUrl).href;function Xz(e,t){return e.selection.find(e=>e.group===t)?.channels??[]}var Zz=c((()=>{}));function Qz(e){if(e.length>$z)return null;let t=e.match(/\d+\.?\d*(?:[eE][+-]?\d+)?|\.\d+(?:[eE][+-]?\d+)?|[A-Za-z_]\w*|\*\*|[-+*/^(),]|\S/g)??[],n=0,r=()=>t[n],i=()=>{throw Error(`formula`)},a=e=>{t[n++]!==e&&i()},o=()=>{let e=s();for(;r()===`+`||r()===`-`;){let r=t[n++],i=e,a=s();e=r===`+`?e=>i(e)+a(e):e=>i(e)-a(e)}return e},s=()=>{let e=c();for(;r()===`*`||r()===`/`;){let r=t[n++],i=e,a=c();e=r===`*`?e=>i(e)*a(e):e=>i(e)/a(e)}return e},c=()=>{if(r()===`-`){n++;let e=c();return t=>-e(t)}return r()===`+`?(n++,c()):l()},l=()=>{let e=u();if(r()===`^`||r()===`**`){n++;let t=c();return n=>e(n)**t(n)}return e},u=()=>{let e=t[n++];if(e===void 0&&i(),e===`(`){let e=o();return a(`)`),e}if(/^[\d.]/.test(e)){let t=Number(e);return Number.isFinite(t)||i(),()=>t}if(e===`X`||e===`x`||e===`X1`)return e=>e;if(Object.hasOwn(eB,e)){let t=eB[e];a(`(`);let i=[o()];for(;r()===`,`;)n++,i.push(o());return a(`)`),i.length===1?e=>t(i[0](e)):e=>t(...i.map(t=>t(e)))}return i()};try{let e=o();return n===t.length?e:null}catch{return null}}var $z,eB,tB=c((()=>{$z=4096,eB={sin:Math.sin,cos:Math.cos,tan:Math.tan,asin:Math.asin,acos:Math.acos,atan:Math.atan,sinh:Math.sinh,cosh:Math.cosh,tanh:Math.tanh,exp:Math.exp,ln:Math.log,log:Math.log,log10:Math.log10,sqrt:Math.sqrt,abs:Math.abs,pow:Math.pow,min:Math.min,max:Math.max}}));function nB(e,t){let{keys:n,vals:r}=e,i=n.length;if(i===0)return t;if(t<=n[0])return r[0];if(t>=n[i-1])return r[i-1];let a=0,o=i-1;for(;o-a>1;){let e=a+o>>1;n[e]<=t?a=e:o=e}return e.interp?r[a]+(r[o]-r[a])*(t-n[a])/(n[o]-n[a]):t-n[a]<=n[o]-t?r[a]:r[o]}function rB(e,t){let n=t.length;switch(e.k){case`lin`:{let{a:r,b:i}=e;if(r===1&&i===0)return;for(let e=0;e<n;e++)t[e]=r*t[e]+i;return}case`rat`:{let[r,i,a,o,s,c]=e.p;for(let e=0;e<n;e++){let n=t[e];t[e]=(r*n*n+i*n+a)/(o*n*n+s*n+c)}return}case`poly`:{let[r,i,a,o,s,c]=e.p;for(let e=0;e<n;e++){let n=t[e]-s-c;t[e]=(i-o*n)/(a*n-r)}return}case`alg`:{let r=e.f;for(let e=0;e<n;e++)t[e]=r(t[e]);return}case`tab`:for(let r=0;r<n;r++)t[r]=nB(e,t[r]);return;case`rtv`:for(let r=0;r<n;r++){let n=t[r],i=e.def;for(let t=0;t<e.lo.length;t++)if(n>=e.lo[t]&&n<=e.hi[t]){i=e.vals[t];break}t[r]=i}return;default:return}}function iB(e,t){let n=Float64Array.of(t);return rB(e,n),n[0]}function aB(e,t){let n=Array(t.length),r=e.ranges.every(e=>e.lo===e.hi)?new Map(e.ranges.map(e=>[e.lo,e.to])):null;for(let i=0;i<t.length;i++){let a=t[i];if(a!==a){n[i]=null;continue}let o=e.def;if(r){let e=r.get(a);e!==void 0&&(o=e)}else for(let t of e.ranges)if(a>=t.lo&&(e.int||t.lo===t.hi?a<=t.hi:a<t.hi)){o=t.to;break}n[i]=sB(o,a)}return n}var oB,sB,cB=c((()=>{oB={k:`id`},sB=(e,t)=>e===null||typeof e==`string`?e:String(iB(e,t))}));function lB(e,t){let n=(e,t)=>({type:e,bigEndian:t,encoding:`latin1`});switch(e){case 0:return n(`uint`,!t);case 1:return n(`int`,!t);case 2:case 3:return n(`float`,!t);case 7:return n(`string`,!1);case 8:return n(`bytes`,!1);case 9:return n(`uint`,!0);case 10:return n(`int`,!0);case 11:case 12:return n(`float`,!0);case 13:return n(`uint`,!1);case 14:return n(`int`,!1);case 15:case 16:return n(`float`,!1);default:return null}}async function uB(e,t,n){let r=TR(t).getUint16(24,!0)===0,i=async t=>{let n=TR(await e.read(t,4)).getUint16(2,r),i=await e.read(t,n);return{id:OR(i.subarray(0,2)),v:TR(i),b:i,size:n}},a=(e,t)=>e.getUint32(t,r),o=(e,t)=>e.getUint16(t,r),s=(e,t)=>e.getFloat64(t,r),c=async e=>e?CR((await i(e)).b.subarray(4),!0):``,l=[],u=new Set,d=e=>{if(u.has(e))throw Error(`This MDF file is damaged (its blocks link in a loop).`);u.add(e)},f=async(e,t)=>{if(!e)return{conv:oB,unit:``};let{v:n,b:r}=await i(e),l=CR(r.subarray(22,42),!0),u=o(n,42),d=o(n,44),f=e=>s(n,46+8*e);switch(u){case 0:return{conv:{k:`lin`,a:f(1),b:f(0)},unit:l};case 1:case 2:{let e=new Float64Array(d),t=new Float64Array(d);for(let n=0;n<d;n++)e[n]=f(2*n),t[n]=f(2*n+1);return{conv:{k:`tab`,keys:e,vals:t,interp:u===1},unit:l}}case 6:return{conv:{k:`poly`,p:[0,1,2,3,4,5].map(f)},unit:l};case 9:return{conv:{k:`rat`,p:[0,1,2,3,4,5].map(f)},unit:l};case 10:{let e=CR(r.subarray(46,302),!0),t=Qz(e);return{conv:t?{k:`alg`,f:t}:{k:`unsupported`,what:`the formula "${e}"`},unit:l}}case 11:return{conv:{k:`text`,ranges:Array.from({length:d},(e,t)=>{let i=46+40*t,a=s(n,i);return{lo:a,hi:a,to:CR(r.subarray(i+8,i+40),!0)}}),def:null,int:t},unit:l};case 12:{let e=await Promise.all(Array.from({length:d},async(e,t)=>{let r=46+20*t;return{lo:s(n,r),hi:s(n,r+8),to:await c(a(n,r+16))}}));return{conv:{k:`text`,ranges:e.slice(1),def:e[0]?.to??null,int:t},unit:l}}case 65535:return{conv:oB,unit:l};default:return{conv:{k:`unsupported`,what:`MDF3 conversion type ${u}`},unit:l}}},p=await i(64),m=null;if(p.size>=172&&(a(p.v,164)||a(p.v,168))){let e=a(p.v,168)*4294967296+a(p.v,164);m=new Date(e/1e6).toISOString()}else{let e=OR(p.b.subarray(18,28)),t=OR(p.b.subarray(28,36));/^\d\d:\d\d:\d{4}$/.test(e)&&(m=`${e.slice(6)}-${e.slice(3,5)}-${e.slice(0,2)}T${t}`)}let h=[],g=0;for(let e=a(p.v,4),t=0;e;t++){d(e);let n=await i(e),s=o(n.v,22),u=[];for(let e=a(n.v,8);e;){d(e);let n=await i(e),p=[],m=null;for(let e=a(n.v,8);e;){d(e);let t=await i(e),n=CR(t.b.subarray(26,58),!0),s=(t.size>=222?await c(a(t.v,218)):``)||n,u=lB(o(t.v,190),r),h=o(t.v,186)+(t.size>=228?8*o(t.v,226):0);if(!u)l.push(`${s}: MDF3 data type ${o(t.v,190)} is not supported; skipped.`);else{let{conv:e,unit:n}=await f(a(t.v,8),u.type!==`float`),r={name:s,unit:n,kind:o(t.v,24)===1?`master`:`value`,...u,conv:e,sd:null,sdRecordId:null,byteOffset:h>>3,bitOffset:h&7,bitCount:o(t.v,188),invalBit:null,allInvalid:!1};r.kind===`master`&&!m?m=r:r.kind===`value`&&p.push(r)}e=a(t.v,4)}g++,u.push({name:await c(a(n.v,12))||`Group ${g}`,dg:t,recordId:o(n.v,16),recordIdSize:+(s>0),idTrailer:+(s===2),dataBytes:o(n.v,20),invalBytes:0,cycles:a(n.v,22),vlsdCg:!1,sorted:!0,master:m,channels:p,stream:[],busType:0,busEvent:!1}),e=a(n.v,4)}let p=u.reduce((e,t)=>e+t.cycles*(t.recordIdSize+t.dataBytes+t.idTrailer),0),m=[{offset:a(n.v,16),length:p,zip:null}];for(let e of u)e.stream=m,e.sorted=u.length===1,h.push(e);e=a(n.v,4)}return{version:`MDF ${n}`,startTime:m,groups:h,notes:l,meta:{}}}var dB=c((()=>{AR(),tB(),cB()}));function fB(e,t){if(e.seen.has(t))throw Error(wB);e.seen.add(t)}async function pB(e,t){let n=await e.read(t,24);if(n.length<24)throw Error(`This MF4 is damaged (bad block at byte ${t}).`);let r=TR(n),i=OR(n.subarray(0,4)),a=xR(r,8),o=xR(r,16);if(!i.startsWith(`##`)||a<24+8*o||a>1<<26)throw Error(`This MF4 is damaged (bad block at byte ${t}).`);let s=await e.read(t,a);if(s.length<a)throw Error(`This MF4 is damaged (the block at byte ${t} runs past the end of the file).`);let c=TR(s),l=[];for(let e=0;e<o;e++)l.push(xR(c,24+8*e));let u=s.subarray(24+8*o);return{id:i,links:l,data:TR(u),bytes:u}}function mB(e){let t=e.indexOf(`<TX>`),n=t<0?-1:e.indexOf(`</TX>`,t+4);return(n>=0?e.slice(t+4,n):e.replace(/<[^<>]*>/g,``)).replace(/&(lt|gt|amp|quot|apos);/g,(e,t)=>TB[t]).trim()}function hB(e,t){if(!t)return Promise.resolve(``);let n=e.texts.get(t);return n||(n=pB(e.io,t).then(e=>{let t=CR(e.bytes);return e.id===`##MD`?mB(t):t}),e.texts.set(t,n)),n}async function gB(e,t,n=0){if(!t)return[];let r=e.io,i=await r.read(t,24),a=OR(i.subarray(0,4)),o=i.length<24?0:xR(TR(i),8);switch(a){case`##DT`:case`##SD`:case`##RD`:return[{offset:t+24,length:o-24,zip:null}];case`##DZ`:{let e=TR(await r.read(t+24,24));if(e.byteLength<24)throw Error(`This MF4 is damaged (bad block at byte ${t}).`);let n=e.getUint8(2);if(n===2||n===3)throw Error(`This MF4 uses zstd compression, which isn't supported yet.`);if(n===4||n===5)throw Error(`This MF4 uses LZ4 compression, which isn't supported yet.`);if(n>5)throw Error(`This MF4 is damaged (unknown compression type ${n}).`);let i=e.getUint32(4,!0),a=xR(e,8),o=xR(e,16);if(a>lz(o)||n===1&&i===0)throw Error(`This MF4 is damaged (bad compressed block at byte ${t}).`);if(n===1&&a>268435456)throw Error(`This MF4 has a compressed block over 256 MB, which Kymoscope cannot read.`);return[{offset:t+48,length:o,zip:{type:n,param:i,orgLength:a}}]}case`##DL`:{if(n>1)throw Error(`This MF4 is damaged (unexpected ${a} block in its data).`);let i=[];for(let n=t;n;){fB(e,n);let t=await pB(r,n);for(let n of t.links.slice(1))i.push(...await gB(e,n,2));n=t.links[0]}return i}case`##HL`:if(n>0)throw Error(`This MF4 is damaged (unexpected ${a} block in its data).`);return fB(e,t),gB(e,(await pB(r,t)).links[0],1);case`##DV`:case`##DI`:throw Error(`This MF4 uses column-oriented storage (MDF 4.2 DV/DI blocks), which Kymoscope cannot read yet.`);default:throw Error(`This MF4 is damaged (unexpected ${a} block in its data).`)}}async function _B(e,t,n){return t?OR(await e.io.read(t,4))===`##CC`?vB(e,t,n+1):hB(e,t):null}async function vB(e,t,n=0){if(!t||n>4||e.busy.has(t))return oB;let r=e.convs.get(t);if(r)return r;e.busy.add(t);try{let r=await yB(e,t,n);return e.convs.set(t,r),r}finally{e.busy.delete(t)}}async function yB(e,t,n){let r=await pB(e.io,t),i=r.data,a=i.getUint8(0),o=i.getUint16(4,!0),s=i.getUint16(6,!0),c=new Float64Array(s);for(let e=0;e<s;e++)c[e]=i.getFloat64(24+8*e,!0);let l=r.links.slice(4,4+o),u=()=>Promise.all(l.map(t=>_B(e,t,n)));switch(a){case 0:return oB;case 1:return{k:`lin`,b:c[0],a:c[1]};case 2:return{k:`rat`,p:[...c]};case 3:{let t=await hB(e,l[0]),n=Qz(t);return n?{k:`alg`,f:n}:{k:`unsupported`,what:`the formula "${t}"`}}case 4:case 5:{let e=s>>1,t=new Float64Array(e),n=new Float64Array(e);for(let r=0;r<e;r++)t[r]=c[2*r],n[r]=c[2*r+1];return{k:`tab`,keys:t,vals:n,interp:a===4}}case 6:{let e=Math.max(0,Math.floor((s-1)/3)),t=new Float64Array(e),n=new Float64Array(e),r=new Float64Array(e);for(let i=0;i<e;i++)t[i]=c[3*i],n[i]=c[3*i+1],r[i]=c[3*i+2];return{k:`rtv`,lo:t,hi:n,vals:r,def:c[s-1]}}case 7:{let e=await u();return{k:`text`,ranges:[...c].map((t,n)=>({lo:t,hi:t,to:e[n]??null})),def:e[s]??null,int:!0}}case 8:{let e=await u(),t=s>>1;return{k:`text`,ranges:Array.from({length:t},(t,n)=>({lo:c[2*n],hi:c[2*n+1],to:e[n]??null})),def:e[t]??null,int:!0}}default:return{k:`unsupported`,what:`conversion type ${a}`}}}async function bB(e,t){let{io:n,notes:r}=e,i=t.data,a=i.getUint8(0),o=i.getUint8(1),s=i.getUint8(2),c=await hB(e,t.links[2]),l=EB[s];if(!l)return r.push(`${c}: data type ${s} is not supported; the channel was skipped.`),null;let u;if(a===2||a===3)if(o===1)u=a===2?`master`:`vmaster`;else{if(r.push(`The master channel ${c} is not time (sync type ${o}): samples are numbered instead.`),a===3)return null;u=`value`}else if(a===1)u=`vlsd`;else if(a===0||a===4)u=`value`;else return r.push(`${c}: channel type ${a} is not supported; skipped.`),null;let d=await vB(e,t.links[4]),f=d.k===`text`?{...d,int:l.type!==`float`}:d,p=await hB(e,t.links[6]);!p&&t.links[4]&&(p=await hB(e,(await pB(n,t.links[4])).links[1]));let m=null,h=null;u===`vlsd`&&t.links[5]&&(OR(await n.read(t.links[5],4))===`##CG`?h=xR((await pB(n,t.links[5])).data,0):m=await gB(e,t.links[5]));let g=i.getUint32(12,!0);return{name:c,unit:p,kind:u,...l,conv:f,sd:m,sdRecordId:h,byteOffset:i.getUint32(4,!0),bitOffset:i.getUint8(3),bitCount:i.getUint32(8,!0),invalBit:g&2?i.getUint32(16,!0):null,allInvalid:(g&1)!=0}}async function xB(e,t,n,r=0){let{io:i,notes:a}=e;for(let o=t;o;){fB(e,o);let t=await pB(i,o),s=t.links[1];s&&r<4&&(OR(await i.read(s,4))===`##CN`?await xB(e,s,n,r+1):a.push(`${await hB(e,t.links[2])}: array channels (CA) are not supported yet; skipped.`));let c=await bB(e,t);c&&n.push(c),o=t.links[0]}}async function SB(e,t,n,r){let i=t.data,a=i.getUint16(16,!0),o=0;t.links[3]&&(o=(await pB(e.io,t.links[3])).data.getUint8(1));let s={name:await hB(e,t.links[2]),dg:n,recordId:xR(i,0),recordIdSize:r,idTrailer:0,dataBytes:i.getUint32(24,!0),invalBytes:i.getUint32(28,!0),cycles:xR(i,8),vlsdCg:(a&1)!=0,sorted:!0,master:null,channels:[],stream:[],busType:o,busEvent:(a&2)!=0};if(s.vlsdCg)return s;let c=[];await xB(e,t.links[1],c);for(let e of c)e.kind===`master`||e.kind===`vmaster`?s.master||=e:s.channels.push(e);return s}async function CB(e,t){let n=await pB(e,64);if(n.id!==`##HD`)throw Error(`This MF4 is damaged (no header block).`);let r=xR(n.data,0),i=(n.data.getUint8(12)&1)!=0,a=new Date(r/1e6).toISOString(),o=r>0?i?a.slice(0,-1):a:null,s={io:e,notes:[],seen:new Set,texts:new Map,convs:new Map,busy:new Set},c=[],l=0;for(let t=n.links[0],r=0;t;r++){fB(s,t);let n=await pB(e,t),i=n.data.getUint8(0),a=[];for(let t=n.links[1];t;){fB(s,t);let n=await pB(e,t),o=await SB(s,n,r,i);o.vlsdCg||(l++,o.name||=`Group ${l}`),a.push(o),t=n.links[0]}let o=await gB(s,n.links[2]),u=a.length===1;for(let e of a)e.stream=o,e.sorted=u,c.push(e);t=n.links[0]}return{version:`MF4 ${t}`,startTime:o,groups:c,notes:s.notes,meta:{}}}var wB,TB,EB,DB=c((()=>{AR(),tB(),gz(),cB(),wB=`This MF4 is damaged (its blocks link in a loop).`,TB={lt:`<`,gt:`>`,amp:`&`,quot:`"`,apos:`'`},EB={0:{type:`uint`,bigEndian:!1,encoding:`latin1`},1:{type:`uint`,bigEndian:!0,encoding:`latin1`},2:{type:`int`,bigEndian:!1,encoding:`latin1`},3:{type:`int`,bigEndian:!0,encoding:`latin1`},4:{type:`float`,bigEndian:!1,encoding:`latin1`},5:{type:`float`,bigEndian:!0,encoding:`latin1`},6:{type:`string`,bigEndian:!1,encoding:`latin1`},7:{type:`string`,bigEndian:!1,encoding:`utf-8`},8:{type:`string`,bigEndian:!1,encoding:`utf-16le`},9:{type:`string`,bigEndian:!0,encoding:`utf-16be`},10:{type:`bytes`,bigEndian:!1,encoding:`latin1`}}}));function OB(e){let t=e&32768?-1:1,n=e>>10&31,r=e&1023;return n===0?t*2**-14*(r/1024):n===31?r?NaN:t*(1/0):t*2**(n-15)*(1+r/1024)}function kB(e,t,n,r,i,a,o=0){let s=TR(t),c=!e.bigEndian,l=i+e.byteOffset,u=e.bitCount;if(e.bitOffset===0)if(e.type===`float`){if(u===64){for(let e=0;e<n;e++,l+=r)a[o+e]=s.getFloat64(l,c);return}if(u===32){for(let e=0;e<n;e++,l+=r)a[o+e]=s.getFloat32(l,c);return}if(u===16){for(let e=0;e<n;e++,l+=r)a[o+e]=OB(s.getUint16(l,c));return}}else if(e.type===`int`){if(u===8){for(let e=0;e<n;e++,l+=r)a[o+e]=s.getInt8(l);return}if(u===16){for(let e=0;e<n;e++,l+=r)a[o+e]=s.getInt16(l,c);return}if(u===32){for(let e=0;e<n;e++,l+=r)a[o+e]=s.getInt32(l,c);return}if(u===64){for(let e=0;e<n;e++,l+=r)a[o+e]=s.getInt32(l+(c?4:0),c)*4294967296+s.getUint32(l+(c?0:4),c);return}}else{if(u===8){for(let e=0;e<n;e++,l+=r)a[o+e]=t[l];return}if(u===16){for(let e=0;e<n;e++,l+=r)a[o+e]=s.getUint16(l,c);return}if(u===32){for(let e=0;e<n;e++,l+=r)a[o+e]=s.getUint32(l,c);return}if(u===64){for(let e=0;e<n;e++,l+=r)a[o+e]=s.getUint32(l+(c?4:0),c)*4294967296+s.getUint32(l+(c?0:4),c);return}}let d=e.bitOffset+u+7>>3,f=2**e.bitOffset,p=2**u,m=p/2,h=e.type===`int`;for(let e=0;e<n;e++,l+=r){let n=0;if(c)for(let e=d-1;e>=0;e--)n=n*256+t[l+e];else for(let e=0;e<d;e++)n=n*256+t[l+e];n=Math.floor(n/f)%p,a[o+e]=h&&n>=m?n-p:n}}function AB(e){let t=e.indexOf(`\0`);return t<0?e:e.slice(0,t)}function jB(e,t,n,r,i){let a=PB(e.encoding),o=e.bitCount>>3,s=Array(n);for(let c=0,l=i+e.byteOffset;c<n;c++,l+=r)s[c]=AB(a.decode(t.subarray(l,l+o)));return s}function MB(e,t,n,r,i,a){let o=a instanceof Float64Array?NaN:null;if(e.allInvalid){for(let e=0;e<n;e++)a[e]=o;return}if(e.invalBit===null)return;let s=1<<(e.invalBit&7);for(let c=0,l=i+(e.invalBit>>3);c<n;c++,l+=r)t[l]&s&&(a[c]=o)}var NB,PB,FB=c((()=>{AR(),NB=new Map,PB=e=>{let t=NB.get(e);return t||NB.set(e,t=new TextDecoder(e)),t}}));function IB(e,t){return e.kind===`vmaster`?!0:(e.kind===`vlsd`||e.type===`uint`||e.type===`int`||e.type===`float`?!(e.bitCount>=1&&e.bitCount<=64):!(e.bitCount>=8))?!1:HB(e)<=t.dataBytes}function LB(e,t){let n=e.notes;for(let r of e.groups){if(![0,1,2,4,8].includes(r.recordIdSize))throw Error(`This MDF file is damaged (bad record id size).`);if(r.vlsdCg)continue;let e=zB(r);if(e>BB||e===0){r.cycles>0&&n.push(`${r.name||`A group`}: its records are ${e===0?`empty`:`too large`} (damaged); skipped.`),r.cycles=0;continue}r.cycles=Math.min(r.cycles,Math.floor(VB(r.stream,t)/e));let i=r.channels.filter(e=>!IB(e,r));for(let e of i)n.push(`${e.name}: its bits lie outside its record (damaged); skipped.`);i.length&&(r.channels=r.channels.filter(e=>!i.includes(e))),r.master&&!IB(r.master,r)&&(n.push(`${r.master.name}: the time channel lies outside its record (damaged): samples are numbered instead.`),r.master=null);for(let e of r.master?[...r.channels,r.master]:r.channels)e.invalBit!==null&&e.invalBit>=8*r.invalBytes&&(e.invalBit=null)}}function RB(e,t){let n=0;for(let r of e.master?[...t,e.master]:t){if(r.invalBit!==null)return 1/0;r.kind!==`vmaster`&&(n=Math.max(n,r.byteOffset+(r.bitOffset+r.bitCount+7>>3)))}return e.recordIdSize+n}var zB,BB,VB,HB,UB=c((()=>{zB=e=>e.recordIdSize+e.dataBytes+e.invalBytes+e.idTrailer,BB=64<<20,VB=(e,t)=>e.reduce((e,n)=>e+(n.zip?n.zip.orgLength:Math.max(0,Math.min(n.length,t-n.offset))),0),HB=e=>e.byteOffset+Math.ceil((e.bitOffset+e.bitCount)/8)})),WB,GB,KB,qB,JB,YB,XB,ZB,QB,$B,eV,tV,nV,rV,iV,aV,oV,sV,cV,lV,uV,dV,fV,pV,mV,hV,gV,_V,vV,yV,bV,xV,SV,CV=c((()=>{for(WB=Uint8Array,GB=Uint16Array,KB=Int32Array,qB=new WB([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),JB=new WB([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),YB=new WB([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),XB=function(e,t){for(var n=new GB(31),r=0;r<31;++r)n[r]=t+=1<<e[r-1];for(var i=new KB(n[30]),r=1;r<30;++r)for(var a=n[r];a<n[r+1];++a)i[a]=a-n[r]<<5|r;return{b:n,r:i}},ZB=XB(qB,2),QB=ZB.b,$B=ZB.r,QB[28]=258,$B[258]=28,eV=XB(JB,0),tV=eV.b,eV.r,nV=new GB(32768),rV=0;rV<32768;++rV)iV=(rV&43690)>>1|(rV&21845)<<1,iV=(iV&52428)>>2|(iV&13107)<<2,iV=(iV&61680)>>4|(iV&3855)<<4,nV[rV]=((iV&65280)>>8|(iV&255)<<8)>>1;for(aV=(function(e,t,n){for(var r=e.length,i=0,a=new GB(t);i<r;++i)e[i]&&++a[e[i]-1];var o=new GB(t);for(i=1;i<t;++i)o[i]=o[i-1]+a[i-1]<<1;var s;if(n){s=new GB(1<<t);var c=15-t;for(i=0;i<r;++i)if(e[i])for(var l=i<<4|e[i],u=t-e[i],d=o[e[i]-1]++<<u,f=d|(1<<u)-1;d<=f;++d)s[nV[d]>>c]=l}else for(s=new GB(r),i=0;i<r;++i)e[i]&&(s[i]=nV[o[e[i]-1]++]>>15-e[i]);return s}),oV=new WB(288),rV=0;rV<144;++rV)oV[rV]=8;for(rV=144;rV<256;++rV)oV[rV]=9;for(rV=256;rV<280;++rV)oV[rV]=7;for(rV=280;rV<288;++rV)oV[rV]=8;for(sV=new WB(32),rV=0;rV<32;++rV)sV[rV]=5;cV=aV(oV,9,1),lV=aV(sV,5,1),uV=function(e){for(var t=e[0],n=1;n<e.length;++n)e[n]>t&&(t=e[n]);return t},dV=function(e,t,n){var r=t/8|0;return(e[r]|e[r+1]<<8)>>(t&7)&n},fV=function(e,t){var n=t/8|0;return(e[n]|e[n+1]<<8|e[n+2]<<16)>>(t&7)},pV=function(e){return(e+7)/8|0},mV=function(e,t,n){return(t==null||t<0)&&(t=0),(n==null||n>e.length)&&(n=e.length),new WB(e.subarray(t,n))},hV=[`unexpected EOF`,`invalid block type`,`invalid length/literal`,`invalid distance`,`stream finished`,`no stream handler`,,`no callback`,`invalid UTF-8 data`,`extra field too long`,`date not in range 1980-2099`,`filename too long`,`stream finishing`,`invalid zip data`],gV=function(e,t,n){var r=Error(t||hV[e]);if(r.code=e,Error.captureStackTrace&&Error.captureStackTrace(r,gV),!n)throw r;return r},_V=function(e,t,n,r){var i=e.length,a=r?r.length:0;if(!i||t.f&&!t.l)return n||new WB(0);var o=!n,s=o||t.i!=2,c=t.i;o&&(n=new WB(i*3));var l=function(e){var t=n.length;if(e>t){var r=new WB(Math.max(t*2,e));r.set(n),n=r}},u=t.f||0,d=t.p||0,f=t.b||0,p=t.l,m=t.d,h=t.m,g=t.n,_=i*8;do{if(!p){u=dV(e,d,1);var v=dV(e,d+1,3);if(d+=3,!v){var y=pV(d)+4,b=e[y-4]|e[y-3]<<8,x=y+b;if(x>i){c&&gV(0);break}s&&l(f+b),n.set(e.subarray(y,x),f),t.b=f+=b,t.p=d=x*8,t.f=u;continue}else if(v==1)p=cV,m=lV,h=9,g=5;else if(v==2){var S=dV(e,d,31)+257,C=dV(e,d+10,15)+4,w=S+dV(e,d+5,31)+1;d+=14;for(var T=new WB(w),E=new WB(19),D=0;D<C;++D)E[YB[D]]=dV(e,d+D*3,7);d+=C*3;for(var O=uV(E),k=(1<<O)-1,A=aV(E,O,1),D=0;D<w;){var j=A[dV(e,d,k)];d+=j&15;var y=j>>4;if(y<16)T[D++]=y;else{var M=0,N=0;for(y==16?(N=3+dV(e,d,3),d+=2,M=T[D-1]):y==17?(N=3+dV(e,d,7),d+=3):y==18&&(N=11+dV(e,d,127),d+=7);N--;)T[D++]=M}}var P=T.subarray(0,S),F=T.subarray(S);h=uV(P),g=uV(F),p=aV(P,h,1),m=aV(F,g,1)}else gV(1);if(d>_){c&&gV(0);break}}s&&l(f+131072);for(var I=(1<<h)-1,L=(1<<g)-1,R=d;;R=d){var M=p[fV(e,d)&I],z=M>>4;if(d+=M&15,d>_){c&&gV(0);break}if(M||gV(2),z<256)n[f++]=z;else if(z==256){R=d,p=null;break}else{var B=z-254;if(z>264){var D=z-257,V=qB[D];B=dV(e,d,(1<<V)-1)+QB[D],d+=V}var ee=m[fV(e,d)&L],H=ee>>4;ee||gV(3),d+=ee&15;var F=tV[H];if(H>3){var V=JB[H];F+=fV(e,d)&(1<<V)-1,d+=V}if(d>_){c&&gV(0);break}s&&l(f+131072);var U=f+B;if(f<F){var te=a-F,W=Math.min(F,U);for(te+f<0&&gV(3);f<W;++f)n[f]=r[te+f]}for(;f<U;++f)n[f]=n[f-F]}}t.l=p,t.p=R,t.b=f,t.f=u,p&&(u=1,t.m=h,t.d=m,t.n=g)}while(!u);return f!=n.length&&o?mV(n,0,f):n.subarray(0,f)},vV=new WB(0),yV=function(e,t){return((e[0]&15)!=8||e[0]>>4>7||(e[0]<<8|e[1])%31)&&gV(6,`invalid zlib data`),(e[1]>>5&1)==+!t&&gV(6,`invalid zlib data: `+(e[1]&32?`need`:`unexpected`)+` dictionary`),(e[1]>>3&4)+2},bV=function(){function e(e,t){typeof e==`function`&&(t=e,e={}),this.ondata=t;var n=e&&e.dictionary&&e.dictionary.subarray(-32768);this.s={i:0,b:n?n.length:0},this.o=new WB(32768),this.p=new WB(0),n&&this.o.set(n)}return e.prototype.e=function(e){if(this.ondata||gV(5),this.d&&gV(4),!this.p.length)this.p=e;else if(e.length){var t=new WB(this.p.length+e.length);t.set(this.p),t.set(e,this.p.length),this.p=t}},e.prototype.c=function(e){this.s.i=+(this.d=e||!1);var t=this.s.b,n=_V(this.p,this.s,this.o);this.ondata(mV(n,t,this.s.b),this.d),this.o=mV(n,this.s.b-32768),this.s.b=this.o.length,this.p=mV(this.p,this.s.p/8|0),this.s.p&=7},e.prototype.push=function(e,t){this.e(e),this.c(t)},e}(),xV=function(){function e(e,t){bV.call(this,e,t),this.v=e&&e.dictionary?2:1}return e.prototype.push=function(e,t){if(bV.prototype.e.call(this,e),this.v){if(this.p.length<6&&!t)return;this.p=this.p.subarray(yV(this.p,this.v-1)),this.v=0}t&&(this.p.length<4&&gV(6,`invalid zlib data`),this.p=this.p.subarray(0,-4)),bV.prototype.c.call(this,t)},e}(),SV=typeof TextDecoder<`u`&&new TextDecoder;try{SV.decode(vV,{stream:!0})}catch{}}));async function*wV(e){for(let t=0;t<e.length;t+=DV)yield e.subarray(t,t+DV)}async function*TV(e){if(typeof DecompressionStream!=`function`){let t=[],n=new xV(e=>{t.push(e)});for await(let r of e)for(n.push(r,!1);t.length;)yield t.shift();for(n.push(new Uint8Array,!0);t.length;)yield t.shift();return}let t=new DecompressionStream(`deflate`),n=t.writable.getWriter();(async()=>{for await(let t of e)await n.write(t);await n.close()})().catch(e=>n.abort(e).catch(()=>{}));let r=t.readable.getReader();try{for(;;){let{done:e,value:t}=await r.read().catch(e=>{throw e instanceof TypeError?Error(OV):e});if(e)return;yield t}}finally{r.cancel().catch(()=>{})}}async function EV(e,t=-1,n=1/0){let r=[],i=Math.min(t,n),a=t>=0?new Uint8Array(i):null,o=0;for await(let s of TV(wV(e))){if(a){if(o+s.length>t&&n>t)throw Error(`Compressed data is longer than its header says.`);a.set(o+s.length>i?s.subarray(0,i-o):s,o)}else r.push(s);if(o+=s.length,o>=n)break}if(a)return o>=i?a:a.subarray(0,o);let s=r.length===1?r[0]:new Uint8Array(o);return r.length>1&&r.reduce((e,t)=>(s.set(t,e),e+t.length),0),o>n?s.subarray(0,n):s}var DV,OV,kV=c((()=>{CV(),DV=65536,OV=`This file's compressed data is damaged.`}));function AV(e,t,n,r=t){let i=Math.floor(n/t),a=new Uint8Array(r<t?i*r:n),o=r%4==0&&IV?new Uint32Array(a.buffer,0,i*r>>2):null,s=r>>2;for(let t=0;t<i;t+=512){let n=Math.min(i,t+512);if(o)for(let a=0;a<r;a+=4){let r=a*i,c=r+i,l=c+i,u=l+i;for(let i=t,d=t*s+(a>>2);i<n;i++,d+=s)o[d]=e[r+i]|e[c+i]<<8|e[l+i]<<16|e[u+i]<<24}else for(let o=0;o<r;o++){let s=o*i;for(let i=t,c=t*r+o;i<n;i++,c+=r)a[c]=e[s+i]}}let c=i*t;return r===t&&a.set(e.subarray(c,n),c),a}function jV(e,t,n){if(!(n<t)||e.length===0)return t;let r=Math.min(t,n+3&-4);return r===t?t:e.every(e=>e.zip?.type===1&&e.zip.param===t&&e.zip.orgLength%t===0)?r:t}async function MV(e,t,n=1/0,r=1/0){let i=await e.slice(t.offset,t.length),{type:a,param:o,orgLength:s}=t.zip;if(a===0)return EV(i,s,r);let c=Math.min(n,o);return AV(await EV(i,s,c<o?s/o*c:1/0),o,s,c)}async function*NV(e,t,n,r=1/0){let i=e=>!!e?.zip&&!(e.zip.type===0&&(e.length>16777216||e.zip.orgLength>268435456)),a=null;for(let o=0;o<t.length;o++){let s=t[o];if(n?.throwIfAborted(),!s.zip)for await(let t of e.windows(s.offset,s.length))yield t.bytes;else if(i(s)){let n=a??MV(e,s,r);a=i(t[o+1])?MV(e,t[o+1],r):null,a?.catch(()=>{}),yield await n}else{let t=s.zip.orgLength;for await(let n of TV((async function*(){for await(let t of e.windows(s.offset,s.length))yield t.bytes})()))if(yield n.length>t?n.subarray(0,t):n,(t-=n.length)<=0)break}}}async function*PV(e,t,n,r){if(r<=0||t<=0)return;let i=Math.min(n,r),a=null,o=0,s=0;for await(let n of e){let e=0;for(;e<n.length&&s<r;){if(o===0){let a=Math.min(i,r-s,Math.floor((n.length-e)/t));if(a>0){yield{buf:n.subarray(e,e+a*t),n:a},s+=a,e+=a*t;continue}}a??=new Uint8Array(t*i);let c=Math.min(a.length,(r-s)*t),l=Math.min(n.length-e,c-o);if(a.set(n.subarray(e,e+l),o),o+=l,e+=l,o===c){let e=o/t;yield{buf:a,n:e},s+=e,o=0}}if(s>=r)return}a&&o>=t&&(yield{buf:a,n:Math.floor(o/t)})}async function FV(e,t,n,r){let i=n*r,a=0;for(let n of t){let t=n.zip?n.zip.orgLength:n.length;if(i<a)return null;if(i+r<=a+t)return n.zip?null:e.read(n.offset+i-a,r);a+=t}return null}var IV,LV,RV,zV=c((()=>{kV(),DB(),IV=new Uint8Array(Uint32Array.of(1).buffer)[0]===1,LV=(e,t)=>(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0,RV=class{#e;#t;#n;#r;#i=new Uint8Array;#a=0;#o;#s=0;constructor(e,t,n){this.#e=e,this.#t=t,this.#n=n,this.#r=NV(e,t,n),this.#o=t.reduce((e,t)=>e+(t.zip?t.zip.orgLength:t.length),0)}peek(e){let t=e-this.#a;if(t<0||t+4>this.#i.length)return null;let n=LV(this.#i,t);return t+4+n>this.#i.length?null:this.#i.subarray(t+4,t+4+n)}async get(e){for(;;){let t=this.peek(e);if(t)return t;let n=e-this.#a;if(e+4>this.#o||n>=0&&n+4<=this.#i.length&&e+4+LV(this.#i,n)>this.#o)throw Error(`This MF4 is damaged (string data ends early).`);e<this.#a&&(this.#r=NV(this.#e,this.#t,this.#n),this.#i=new Uint8Array,this.#a=0);let r=await this.#r.next();if(r.done)throw Error(`This MF4 is damaged (string data ends early).`);if((this.#s+=r.value.length)>4*this.#o+16777216)throw Error(`This MF4 is damaged (its string offsets jump back and forth).`);let i=Math.max(0,Math.min(e-this.#a,this.#i.length)),a=this.#i.subarray(i),o=new Uint8Array(a.length+r.value.length);o.set(a),o.set(r.value,a.length),this.#a+=i,this.#i=o}}}}));function BV(e,t,n,r,i=zB(e),a=new Float64Array(n)){let o=e.master;if(!o)return null;if(o.kind===`vmaster`)for(let e=0;e<n;e++)a[e]=r+e;else kB(o,t,n,i,e.recordIdSize,a);return rB(o.conv,a),a}function VV(e,t,n){return n===1?e[t]:n===2?e[t]|e[t+1]<<8:n===4?(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0:((e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0)+4294967296*((e[t+4]|e[t+5]<<8|e[t+6]<<16|e[t+7]<<24)>>>0)}function HV(e,t){let n=new Uint8Array(e.length+t.length);return n.set(e),n.set(t,e.length),n}async function*UV(e,t,n,r,i,a=1/0){let o=t.groups[n[0]];if(o.sorted){let t=jV(o.stream,zB(o),a),r=0;for await(let{buf:a,n:s}of PV(NV(e,o.stream,i,t),t,WV(t),o.cycles))yield{g:n[0],buf:a,n:s,start:r,size:t},r+=s;return}let s=t.groups.map((e,t)=>({g:e,k:t})).filter(({g:e})=>e.dg===o.dg),c=o.recordIdSize,l=new Map;for(let e of n){let n=t.groups[e],r=zB(n);l.set(n.recordId,{k:e,size:r,buf:new Uint8Array(r*Math.min(WV(r),Math.max(1,n.cycles))),fill:0,start:0})}let u=new Map(s.map(({g:e})=>[e.recordId,e.vlsdCg?-1:zB(e)])),d=new Map,f=new Uint8Array;for await(let t of NV(e,o.stream,i)){let e=f.length?HV(f,t):t,n=0;for(;!(n+c>e.length);){let t=VV(e,n,c),i=u.get(t);if(i===void 0)throw Error(`This MF4 is damaged (unknown record id ${t}).`);if(i<0){if(n+c+4>e.length)break;let i=(e[n+c]|e[n+c+1]<<8|e[n+c+2]<<16|e[n+c+3]<<24)>>>0;if(i>GV)throw Error(`This MF4 is damaged (a string record of ${i} bytes).`);let a=n+c+4+i;if(a>e.length)break;let o=d.get(t)??0;r.wanted(t)&&r.put(t,o,e.slice(n+c+4,a)),d.set(t,o+4+i),n=a;continue}if(n+i>e.length)break;let a=l.get(t);if(a&&(a.buf.set(e.subarray(n,n+i),a.fill),a.fill+=i,a.fill===a.buf.length)){let e=a.fill/a.size;yield{g:a.k,buf:a.buf,n:e,start:a.start,size:a.size},a.start+=e,a.fill=0}n+=i}f=e.slice(n)}for(let e of l.values())e.fill&&(yield{g:e.k,buf:e.buf,n:e.fill/e.size,start:e.start,size:e.size})}var WV,GV,KV,qV=c((()=>{cB(),FB(),UB(),zV(),WV=e=>Math.max(1,Math.min(65536,Math.floor((8<<20)/Math.max(1,e)))),GV=64<<20,KV=class{#e;#t;#n=new Map;#r=new Map;constructor(e,t){this.#e=e,this.#t=t}want(e){this.#r.has(e)||this.#r.set(e,new Map)}wanted(e){return this.#r.has(e)}put(e,t,n){this.#r.get(e).set(t,n)}async bytes(e,t){let n=Array(t.length);if(e.sdRecordId!==null){let r=this.#r.get(e.sdRecordId);for(let e=0;e<t.length;e++)n[e]=r?.get(t[e])??null,r?.delete(t[e]);return n}if(!e.sd)return n.fill(null);let r=this.#n.get(e);r||this.#n.set(e,r=new RV(this.#e,e.sd,this.#t));for(let e=0;e<t.length;e++)n[e]=r.peek(t[e])??await r.get(t[e]);return n}async strings(e,t){let n=PB(e.encoding);return(await this.bytes(e,t)).map(e=>e?AB(n.decode(e)):null)}}}));function JV(e){let t=e.split(`"`),n=new Map;for(let e=0;e+1<t.length;e+=2){let r=t[e].trim();rH.test(r)&&n.set(Number(r),t[e+1])}return n}function YV(e){let t=new Map,n=new Map,r=new Map,i=(e,t)=>{let i=n.get(Number(e));return i?r.get(i)?.get(t):void 0},a=null;for(let o of e.split(/\r?\n/)){let e=o.trim(),s;if(s=$V.exec(e)){let e=Number(s[1]),r=e>=2147483648,i=r?e-2147483648:e;a={id:i,extended:r,name:s[2],size:Number(s[3]),signals:[]},t.set(QV(i,r),a),n.set(e,a)}else if((s=eH.exec(e))&&a){let e=s[2],t=Number(s[3]),n=Number(s[4]);if(!iH(t,n)||!s[7].trim()||!s[8].trim())continue;let i={name:s[1],start:t,length:n,littleEndian:s[5]===`1`,signed:s[6]===`-`,factor:Number(s[7]),offset:Number(s[8]),unit:s[9],mux:e?e===`M`?`switch`:parseInt(e.slice(1),10):null,float:0,values:null};a.signals.push(i);let o=r.get(a);o||r.set(a,o=new Map),o.has(i.name)||o.set(i.name,i)}else if(s=tH.exec(e)){let e=i(s[1],s[2]);e&&(e.values=JV(s[3]))}else if(s=nH.exec(e)){let e=i(s[1],s[2]);e&&(e.float=s[3]===`1`?32:64)}else (e.startsWith(`BO_`)||e===``)&&e===``&&(a=null)}return t}function XV(e){if(e.float){let t=e.float/8,n=e.start>>3,r=e.littleEndian,i=new DataView(new ArrayBuffer(8));return(e,a)=>{for(let r=0;r<t;r++)i.setUint8(r,e[a+n+r]??0);return t===4?i.getFloat32(0,r):i.getFloat64(0,r)}}let t=e.length,n=2**t,r=n/2,i=e.signed;if(e.littleEndian){let a=e.start>>3,o=e.start&7;if(o+t<=32){let e=t===32?-1:(1<<t)-1;return(t,s)=>{let c=s+a,l=((t[c]|t[c+1]<<8|t[c+2]<<16|t[c+3]<<24)>>>o&e)>>>0;return i&&l>=r?l-n:l}}let s=o+t+7>>3,c=2**(t-(32-o)),l=2**(32-o);return(e,t)=>{let u=t+a,d=(e[u]|e[u+1]<<8|e[u+2]<<16|e[u+3]<<24)>>>o,f=0;for(let t=s-1;t>=4;t--)f=f*256+(e[u+t]??0);let p=d+f%c*l;return i&&p>=r?p-n:p}}let a=e.start>>3,o=e.start&7;if(7-o+t<=32){let e=32-(7-o)-t,s=t===32?-1:(1<<t)-1;return(t,o)=>{let c=o+a,l=((t[c]<<24|t[c+1]<<16|t[c+2]<<8|t[c+3])>>>e&s)>>>0;return i&&l>=r?l-n:l}}let s=(1<<o+1)-1,c=t-(o+1)>>3,l=t-(o+1)&7,u=2**l;return(e,t)=>{let o=(e[t+a]??0)&s,d=t+a+1;for(let t=0;t<c;t++)o=o*256+(e[d++]??0);return l>0&&(o=o*u+((e[d]??0)>>8-l)),i&&o>=r?o-n:o}}function ZV(e){let t=e.length,n=2**t,r=n/2,i=e.signed,a=t===32?-1:(1<<t)-1;if(!e.float&&e.littleEndian&&(e.start&7)+t<=32){let t=e.start>>3,o=e.start&7;return(e,s,c,l,u,d,f)=>{for(let p=0;p<l;p++){let l=s[c[p]]+t,m=((e[l]|e[l+1]<<8|e[l+2]<<16|e[l+3]<<24)>>>o&a)>>>0;u[p]=(i&&m>=r?m-n:m)*d+f}}}if(!e.float&&!e.littleEndian&&7-(e.start&7)+t<=32){let o=e.start>>3,s=32-(7-(e.start&7))-t;return(e,t,c,l,u,d,f)=>{for(let p=0;p<l;p++){let l=t[c[p]]+o,m=((e[l]<<24|e[l+1]<<16|e[l+2]<<8|e[l+3])>>>s&a)>>>0;u[p]=(i&&m>=r?m-n:m)*d+f}}}let o=XV(e);return(e,t,n,r,i,a,s)=>{for(let c=0;c<r;c++)i[c]=o(e,t[n[c]])*a+s}}var QV,$V,eH,tH,nH,rH,iH,aH=c((()=>{QV=(e,t)=>t?e+2147483648:e,$V=/^BO_\s+(\d+)\s+(\w+)\s*:\s*(\d+)/,eH=/^SG_\s+(\w+)\s*(?:(M|m\d+M?)\s*)?:\s*(\d+)\|(\d+)@([01])([+-])\s*\(([^,)]*),([^)]*)\)\s*\[[^\]]*\]\s*"([^"]*)"/,tH=/^VAL_\s+(\d+)\s+(\w+)\s+(.*);/,nH=/^SIG_VALTYPE_\s+(\d+)\s+(\w+)\s*:\s*([12])\s*;/,rH=/^-?\d+(?:\.\d+)?$/,iH=(e,t)=>e<=511&&t>=1&&t<=64}));function oH(e){if(!e.busEvent||e.busType!==2)return null;let t=t=>e.channels.find(e=>e.name.endsWith(t))??null,n=t(`DataFrame.ID`),r=t(`DataFrame.DataBytes`);return!n||!r?null:{id:n,ide:t(`DataFrame.IDE`),data:r}}async function sH(e,t,n,r,i,a,o,s){s.key.length<r&&Object.assign(s,{time:new Float64Array(r),key:new Float64Array(r),id:new Float64Array(r),ide:new Float64Array(r),dataAt:new Int32Array(r)});let c=e.recordIdSize,{id:l,ide:u,key:d,dataAt:f}=s;kB(t.id,n,r,a,c,l),t.ide&&kB(t.ide,n,r,a,c,u);for(let e=0;e<r;e++){let n=l[e],r=n&536870911;d[e]=QV(r,t.ide?u[e]!==0:n>=2147483648||r>2047)}if(s.bytes=null,t.data.kind===`vlsd`){let e=new Float64Array(r);kB({...t.data,type:`uint`},n,r,a,c,e),s.bytes=await o.bytes(t.data,e)}else for(let e=0,n=c+t.data.byteOffset;e<r;e++,n+=a)f[e]=n;if(!BV(e,n,r,i,a,s.time.subarray(0,r)))for(let e=0;e<r;e++)s.time[e]=i+e;return s.n=r,s.buf=n,s}function cH(e){return e.float?(e.start>>3)+e.float/8:e.littleEndian?(e.start>>3)+((e.start&7)+e.length+7>>3):(e.start>>3)+1+(Math.max(0,e.length-((e.start&7)+1))+7>>3)}function lH(e,t,n){let r=0;for(let e of n.values())for(let t of e.signals)r=Math.max(r,cH(t));let i=t.data.kind===`vlsd`?t.data:{...t.data,bitCount:Math.min(t.data.bitCount,r*8)};return RB(e,t.ide?[t.id,t.ide,i]:[t.id,i])}function uH(e,t){let n=t.map(t=>e.signals[e.channels[t].s]);return{route:e,col:n.map(ZV),read:n.map(XV),factor:n.map(e=>e.factor),offset:n.map(e=>e.offset),table:t.map((t,r)=>e.channels[t].text?n[r].values:null),idx:new Int32Array,cnt:0,n:0,t0:NaN,t1:NaN}}function dH(e,t,n,r,i,a=1,o=0){let s=new Float64Array(i);if(n.bytes)for(let e=0;e<i;e++)s[e]=t(n.bytes[r[e]]??vH,0)*a+o;else e(n.buf,n.dataAt,r,i,s,a,o);return s}function fH(e,t){let{idx:n,cnt:r}=e,i=new Float64Array(r);for(let e=0;e<r;e++)i[e]=t.time[n[e]];return e.n===0&&(e.t0=i[0]),e.t1=i[r-1],e.n+=r,e.cnt=0,{time:i,cols:e.col.map((i,a)=>{let o=e.table[a];return o?Array.from(dH(i,e.read[a],t,n,r),e=>o.get(e)??null):dH(i,e.read[a],t,n,r,e.factor[a],e.offset[a])})}}function pH(e,t){let n=e.signals.find(e=>e.mux===`switch`);return{key:QV(e.id,e.extended),skip:!1,frames:0,all:t,sw:n?{col:ZV(n),read:XV(n)}:null,byMux:new Map,idx:new Int32Array,cnt:0}}function mH(e,t,n){let r=[];for(let n=0;n<e.n;n++){let i=t.get(e.key[n]);if(i.skip){i.frames++;continue}i.cnt===0&&(r.push(i),i.idx.length<e.n&&(i.idx=new Int32Array(e.n))),i.idx[i.cnt++]=n}let i=[];for(let t of r){if(t.all&&(t.all.idx=t.idx,t.all.cnt=t.cnt,i.push(t.all)),t.sw){let r=dH(t.sw.col,t.sw.read,e,t.idx,t.cnt);for(let e=0;e<t.cnt;e++){let a=t.byMux.get(r[e]);a===void 0&&((a=n(t,r[e]))||t.byMux.size<4096)&&t.byMux.set(r[e],a),a&&(a.cnt===0&&(i.push(a),a.idx.length<t.cnt&&(a.idx=new Int32Array(t.cnt))),a.idx[a.cnt++]=t.idx[e])}}t.cnt=0}return i}async function hH(e,t,n,r){let i=new Map;if(t.groups.forEach((e,t)=>{let n=oH(e);n&&e.cycles>0&&i.set(t,n)}),i.size===0)return null;if(n.length===0)return{dbc:new Map,layouts:i,routes:[],notes:[],cache:new Map};let a=YV(kR(new Uint8Array(await n[0].arrayBuffer()))),o=[],s=new Map,c=new Map,l=0,u=new KV(e,r);for(let[n,d]of i){let i=t.groups[n],f=(e,t)=>{let n=e.signals.filter(e=>t===null?typeof e.mux!=`number`:e.mux===t),r=[];return n.forEach((e,t)=>{r.push({s:t,text:!1}),e.values&&r.push({s:t,text:!0})}),uH({key:QV(e.id,e.extended),mux:t,signals:n,channels:r},r.map((e,t)=>t))},p=new bH(e=>{let t=a.get(e);if(!t){let t=yH(e);return s.set(e,t),t}let r=pH(t,f(t,null));return o.push({model:n,m:r}),r});d.data.sdRecordId!==null&&u.want(d.data.sdRecordId);let m=_H();for await(let o of UV(e,t,[n],u,r,lH(i,d,a))){let e=await sH(i,d,o.buf,o.n,o.start,o.size,u,m),t=(e,t)=>{let n=a.get(e.key);return n.signals.some(e=>e.mux===t)?f(n,t):null};for(let n of mH(e,p,t)){let t=fH(n,e);if(l<0)continue;if((l+=t.time.length*(1+t.cols.length))>xH){l=-1,c.clear();continue}let r=c.get(n);r||c.set(n,r=[]),r.push(t)}}}let d=[],f=new Map;for(let{model:e,m:t}of o)for(let n of[t.all,...t.byMux.values()]){if(!n)continue;let{route:t,n:r,t0:i,t1:o}=n;if(t.signals.length===0)continue;let s=a.get(t.key);l>=0&&f.set(t,c.get(n)??[]),d.push({model:e,route:t,group:{name:t.mux===null?s.name:`${s.name} [m=${t.mux}]`,channels:t.channels.map(e=>({name:e.text?`${t.signals[e.s].name} (text)`:t.signals[e.s].name,unit:e.text?``:t.signals[e.s].unit,text:e.text})),samples:r,time:{kind:`timestamps`},rateHz:r>1&&o>i?Math.round((r-1)/(o-i)*1e6)/1e6:null}})}let p=[];if(s.size){let e=[...s.values()].reduce((e,t)=>e+t.frames,0),t=[...s.keys()].map(e=>`0x${(e%2147483648).toString(16).toUpperCase()}`).join(`, `);p.push(`${e} frame${e===1?``:`s`} with ${s.size} id${s.size===1?``:`s`} not in the DBC ${e===1?`was`:`were`} skipped (${t}).`)}return{dbc:a,layouts:i,routes:d,notes:p,cache:f}}async function*gH(e,t,n,r,i,a){let o=[];for(let e of i){let t=r.cache.get(e.route);if(!t){o.push(e);continue}r.cache.delete(e.route);let n=0;for(let r of t)yield{group:e.group,start:n,length:r.time.length,time:r.time,columns:e.sel.map(e=>r.cols[e])},n+=r.time.length}if(!o.length)return;let s=r.layouts.get(n),c=t.groups[n],l=new Map,u=new Map;for(let e of o){let t=uH(e.route,e.sel);l.set(t,e.group);let n=u.get(e.route.key);n||u.set(e.route.key,n={all:null,byMux:new Map}),e.route.mux===null?n.all=t:n.byMux.set(e.route.mux,t)}let d=new bH(e=>{let t=u.get(e);if(!t)return yH(e);let n=pH(r.dbc.get(e),t.all);return t.byMux.size||(n.sw=null),n}),f=new KV(e,a);s.data.sdRecordId!==null&&f.want(s.data.sdRecordId);let p=_H();for await(let i of UV(e,t,[n],f,a,lH(c,s,r.dbc))){let e=await sH(c,s,i.buf,i.n,i.start,i.size,f,p);for(let t of mH(e,d,(e,t)=>u.get(e.key).byMux.get(t)??null)){let n=t.n,r=fH(t,e);yield{group:l.get(t),start:n,length:r.time.length,time:r.time,columns:r.cols}}}}var _H,vH,yH,bH,xH,SH=c((()=>{aH(),AR(),FB(),qV(),UB(),_H=()=>({n:0,time:new Float64Array,key:new Float64Array,id:new Float64Array,ide:new Float64Array,bytes:null,buf:new Uint8Array,dataAt:new Int32Array}),vH=new Uint8Array,yH=e=>({key:e,skip:!0,frames:0,all:null,sw:null,byMux:new Map,idx:new Int32Array,cnt:0}),bH=class{#e=Array(2048);#t=new Map;#n;constructor(e){this.#n=e}get(e){let t=e<2048?this.#e[e]:this.#t.get(e);return t||(t=this.#n(e),e<2048?this.#e[e]=t:this.#t.set(e,t)),t}},xH=48e6}));async function CH(e,t){let n=t.master;if(!n||t.cycles<2)return null;if(n.kind===`vmaster`)return n.conv.k===`lin`&&n.conv.a>0?OH(1/n.conv.a):null;if(!t.sorted)return null;let r=zB(t),i=t.cycles,a,o;if(t.stream[0]?.zip){let n=jV(t.stream.slice(0,1),r,RB(t,[])),s=await MV(e,t.stream[0],n,4096*r);if(i=Math.min(t.cycles,Math.floor(s.length/n)),i<2)return null;a=s.subarray(0,n),o=s.subarray((i-1)*n,i*n)}else a=await FV(e,t.stream,0,r),o=await FV(e,t.stream,t.cycles-1,r);if(!a||!o)return null;let s=new Float64Array(2);return kB(n,a,1,r,t.recordIdSize,s,0),kB(n,o,1,r,t.recordIdSize,s,1),rB(n.conv,s),s[1]>s[0]?OH((i-1)/(s[1]-s[0])):null}async function wH(e,t,n,r,i,a,o){let s;if(e.kind===`vlsd`){let a=new Float64Array(n);kB({...e,type:`uint`},t,n,r,i,a),s=await o.strings(e,a)}else if(e.type===`string`)s=jB(e,t,n,r,i);else{let a=new Float64Array(n);kB(e,t,n,r,i,a),e.conv.k===`text`?s=aB(e.conv,a):(rB(e.conv,a),s=a)}return MB(e,t,n,r,a,s),s}async function TH(e,t,n,r,i,a,o,s){let c=e.recordIdSize,l=[];for(let i of t)l.push(await wH(e.channels[i],n,r,a,c,c+e.dataBytes,s));return{group:o,time:BV(e,n,r,i,a),start:i,length:r,columns:l}}async function*EH(e,t){let n=e.plan.state,r=t.filter(e=>n.groups[e].route),i=t.filter(e=>!n.groups[e].route);if(r.length){let t=r.map(t=>({group:t,route:n.groups[t].route,sel:Xz(e,t)}));yield*gH(e.io,n.model,n.groups[r[0]].model,n.bus,t,e.signal)}if(!i.length)return;let a=new KV(e.io,e.signal),o=new Map;for(let t of i){let r=n.groups[t],i=Xz(e,t).map(e=>r.channels[e]);for(let e of i){let t=n.model.groups[r.model].channels[e].sdRecordId;t!==null&&a.want(t)}o.set(r.model,{pg:t,cols:i})}let[s,{cols:c}]=o.entries().next().value,l=n.model.groups[s],u=o.size===1?RB(l,c.map(e=>l.channels[e])):1/0;for await(let t of UV(e.io,n.model,[...o.keys()],a,e.signal,u)){let{pg:e,cols:r}=o.get(t.g);yield await TH(n.model.groups[t.g],r,t.buf,t.n,t.start,t.size,e,a)}}function DH(e){let t=e.plan.state,n=new Map;for(let r of e.selection){let e=t.model.groups[t.groups[r.group].model].dg;n.set(e,[...n.get(e)??[],r.group])}return[...n].sort((e,t)=>e[0]-t[0]).map(([,e])=>e)}var OH,kH,AH,jH,MH=c((()=>{AR(),Zz(),dB(),DB(),cB(),FB(),MR(),UB(),qV(),zV(),SH(),OH=e=>Math.round(e*1e6)/1e6,kH=e=>e.kind===`value`?e.type!==`bytes`:e.kind===`vlsd`&&e.type===`string`,AH=e=>({name:e.name,unit:e.unit,text:e.type===`string`||e.kind===`vlsd`||e.conv.k===`text`}),jH={...jR,async plan(e,t){let n=await t.read(0,64);if(wR(n,`UnFinMF`))throw Error(`This MF4 was not finalized by its logger (it starts with UnFinMF). Finalize it with the logger software or asammdf, then open it again.`);let r=OR(n.subarray(8,16)).replace(/\0/g,``).trim(),i=Number(r.replace(`.`,``).slice(0,3))>=400?await CB(t,r):await uB(t,n,r);LB(i,t.size);let a=await hH(t,i,e.companions.filter(e=>e.name.toLowerCase().endsWith(`.dbc`))),o=new Set(a?.layouts.keys()??[]),s=[],c=[],l=[...i.notes],u=0;for(let e=0;e<i.groups.length;e++){let n=i.groups[e];if(n.vlsdCg||n.cycles===0||o.has(e))continue;let r=[];if(n.channels.forEach((e,t)=>{kH(e)?r.push(t):u++}),r.length!==0){for(let e of r){let t=n.channels[e].conv;t.k===`unsupported`&&l.push(`${n.channels[e].name}: ${t.what} is not supported; raw values are shown.`)}c.push({model:e,channels:r}),s.push({name:n.name,channels:r.map(e=>AH(n.channels[e])),samples:n.cycles,time:n.master?{kind:`timestamps`}:{kind:`index`},rateHz:await CH(t,n)})}}if(u&&l.push(`${u} byte-array channel${u===1?` was`:`s were`} skipped.`),a){if(a.routes.length===0&&a.dbc.size===0){if(s.length===0)throw Error(`This MF4 has raw CAN frames. Drop its .dbc file together with it to decode signals.`);l.push(`This MF4 also has raw CAN frames. Drop its .dbc file together with it to decode signals.`)}for(let e of a.routes)c.push({model:e.model,route:e.route}),s.push(e.group);l.push(...a.notes)}if(s.length===0)throw Error(`This MDF file has no channels with samples.`);let d={model:i,groups:c,bus:a};return{format:i.version,startTime:i.startTime,groups:s,meta:i.meta,events:[],notes:l,interleaved:!!a?.routes.length||i.groups.some(e=>!e.sorted&&!e.vlsdCg),state:d}},async*stream(e){for(let t of DH(e))yield*EH(e,t)},streamGroup(e,t){return EH(e,[t])}}}));function NH(e){let t=[];for(let n of kR(e).split(`\0`)){if(!n)continue;let e=n.split(``),r=parseFloat(e[0].split(``)[0]);Number.isFinite(r)&&t.push({onset:r,texts:e.slice(1).filter(e=>e.length>0)})}return t}function PH(e,t){let n=/^(\d\d)\.(\d\d)\.(\d\d)$/.exec(e),r=/^(\d\d)\.(\d\d)\.(\d\d)$/.exec(t);if(!n||!r)return null;let i=Number(n[3]);return`${i>=85?1900+i:2e3+i}-${n[2]}-${n[1]}T${r[1]}:${r[2]}:${r[3]}`}function FH(e,t,n,r,i,a,o,s){let{bit:c,off:l}=e;if(a===2)for(let e=0;e<i;e++)o[s+e]=c*(l+t.getInt16(r+2*e,!0));else for(let e=0,t=r;e<i;e++,t+=3)o[s+e]=c*(l+((n[t]|n[t+1]<<8|n[t+2]<<16)<<8>>8))}var IH,LH,RH=c((()=>{qz(),AR(),PR(),IH=e=>`${+e.toFixed(6)} Hz`,LH={...NR,async plan(e,t){let n=await t.read(0,256),r=(e,t)=>OR(n.subarray(e,e+t)).trim(),i=n[0]===255,a=parseInt(r(252,4),10),o=parseInt(r(184,8),10),s=r(192,44),c=/^(EDF|BDF)\+/.test(s),l=/^(EDF|BDF)\+D/.test(s),u=parseFloat(r(244,8));if(!(a>0)||o!==256*(a+1)||!(u>0))throw Error(`This EDF/BDF header is damaged.`);let d=await t.read(256,a*256),f=(e,t,n)=>OR(d.subarray(e*a+t*n,e*a+t*(n+1))).trim(),p=i?3:2,m=[],h=0;for(let e=0;e<a;e++){let t=parseFloat(f(104,8,e)),n=parseFloat(f(112,8,e)),r=parseFloat(f(120,8,e)),i=parseFloat(f(128,8,e)),a=Number(f(216,8,e));if(!(Number.isInteger(a)&&a>=0))throw Error(`This EDF/BDF header is damaged (samples per record).`);let o=(n-t)/(i-r);m.push({label:f(0,16,e),unit:f(96,8,e),spr:a,offset:h,bit:o,off:n/o-i}),h+=a*p}let g=h;if(!(g>0&&o+g<=t.size))throw Error(`This EDF/BDF file is damaged (its data records do not fit in it).`);let _=Math.floor((t.size-o)/g),v=parseInt(r(236,8),10),y=[];v>=0?v>_&&(y.push(`The file is shorter than its header says: ${_} of ${v} data records were read.`),v=_):v=_;let b=c?m.flatMap((e,t)=>/^(EDF|BDF) Annotations$/.test(e.label)?[t]:[]):[],x=new Map;m.forEach((e,t)=>{!b.includes(t)&&e.spr>0&&x.set(e.spr,[...x.get(e.spr)??[],t])});let S=[...x.values()],C=S.map(e=>{let t=m[e[0]].spr/u;return{name:IH(t),channels:e.map(e=>({name:m[e].label,unit:m[e].unit})),samples:v*m[e[0]].spr,rateHz:t,time:l?{kind:`timestamps`}:{kind:`rate`,rate:t,start:0}}}),w={headerBytes:o,records:v,duration:u,recordBytes:g,bps:p,signals:m,groups:S,annotations:b,discontinuous:l};return{format:`${i?`BDF`:`EDF`}${c?l?`+D`:`+`:``}`,startTime:PH(r(168,8),r(176,8)),groups:C,meta:{patient:r(8,80),recording:r(88,80)},events:[],notes:l?[`Discontinuous recording: each gap shows as a break in the traces.`,...y]:y,state:w}},async*stream(e){let t=e.plan.state,n=Math.max(1,Math.floor(Gz/t.recordBytes)),r=e.selection.map(e=>({g:e.group,chans:e.channels.map(n=>t.signals[t.groups[e.group][n]]),spr:t.signals[t.groups[e.group][0]].spr})),i=r.map(()=>0),a=0,o=NaN;for await(let s of e.io.windows(t.headerBytes,t.records*t.recordBytes,n*t.recordBytes)){e.signal?.throwIfAborted();let n=Math.floor(s.bytes.length/t.recordBytes);if(n===0)break;let c=TR(s.bytes),l=new Float64Array(n),u=[];for(let e=0;e<n;e++)l[e]=(a+e)*t.duration,t.annotations.forEach((n,r)=>{let i=t.signals[n],a=e*t.recordBytes+i.offset,o=NH(s.bytes.subarray(a,a+i.spr*t.bps));r===0&&o.length&&(l[e]=o[0].onset);for(let e of o)for(let t of e.texts)u.push({time:e.onset,text:t})});let d=new Uint8Array(n),f=0;if(t.discontinuous)for(let e=0;e<n;e++){let n=e?l[e-1]+t.duration:o;n===n&&l[e]>n+1e-9&&(d[e]=1,f++)}for(let e=0;e<r.length;e++){let a=r[e],p=a.spr/t.duration,m=n*a.spr+f,h=t.discontinuous?new Float64Array(m):null,g=a.chans.map(()=>new Float64Array(m)),_=0;for(let e=0;e<n;e++){if(d[e]){h[_]=e?l[e-1]+t.duration:o;for(let e of g)e[_]=NaN;_++}if(h)for(let t=0;t<a.spr;t++)h[_+t]=l[e]+t/p;let n=e*t.recordBytes;a.chans.forEach((e,r)=>FH(e,c,s.bytes,n+e.offset,a.spr,t.bps,g[r],_)),_+=a.spr}let v={group:a.g,time:h,start:i[e],length:m,columns:g};e===0&&u.length&&(v.events=u),i[e]+=m,yield v}o=l[n-1]+t.duration,a+=n}}}}));function zH(e,t,n=0){let r=e.indexOf(`<${t}>`,n);if(r<0)return``;let i=e.indexOf(`</${t}>`,r);return i<0?``:e.slice(r+t.length+2,i).trim()}function BH(e,t){let n=[];for(let r=e.indexOf(`<${t}>`);r>=0;){let i=e.indexOf(`</${t}>`,r);if(i<0)break;n.push(e.slice(r,i+t.length+3)),r=e.indexOf(`<${t}>`,i)}return n}function VH(e,t,n){let r=e[n];if((r===1||r===4||r===8)&&n+1+r<=e.length)return r===1?[e[n+1],2]:r===4?[t.getUint32(n+1,!0),5]:[xR(t,n+1),9];throw Error(`This XDF file is damaged (bad length field).`)}function HH(e,t,n,r){if(n>=e.length)return-1;if(e[n++]===8&&(n+=8),r.fmt!==`string`)return n+JH[r.fmt]*r.nch<=e.length?n+JH[r.fmt]*r.nch:-1;for(let i=0;i<r.nch;i++){if(n>=e.length)return-1;let[r,i]=VH(e,t,n);n+=i+r}return n<=e.length?n:-1}async function*UH(e,t){let n=new Uint8Array;for await(let r of e.windows(4,e.size-4)){t?.throwIfAborted();let i=r.bytes,a=r.offset-n.length;if(n.length){let e=new Uint8Array(n.length+i.length);e.set(n),e.set(i,n.length),i=e}let o=TR(i),s=0;for(;!(s+1>i.length);){let t=i[s];if(s+1+t>i.length)break;let[n,r]=VH(i,o,s),c=s+r+n;if(a+c>e.size)return;if(c>i.length)break;yield{tag:i[s+r]|i[s+r+1]<<8,body:i.subarray(s+r+2,c)},s=c}n=i.slice(s)}}function WH(e,t,n){let r=t-e.i0,i=n-e.t0;e.n++,e.si+=r,e.st+=i,e.sii+=r*r,e.sit+=r*i}function GH(e){let t=e.n*e.sii-e.si*e.si;e.b=t>0?(e.n*e.sit-e.si*e.st)/t:0,e.a=(e.st-e.b*e.si)/Math.max(1,e.n)}function KH(e){if(e.length===0)return[0,0];if(e.length===1)return[e[0][1],0];let t={i0:e[0][0],t0:0,n:0,si:0,st:0,sii:0,sit:0,a:0,b:0};for(let[n,r]of e)WH(t,n,r);return GH(t),[t.a-t.b*t.i0,t.b]}function qH(e,t,n){let r=t.t0+t.a+t.b*(n-t.i0);return r+e.c0+e.c1*r}var JH,YH,XH,ZH,QH=c((()=>{AR(),Iz(),Zz(),IR(),JH={float32:4,double64:8,int8:1,int16:2,int32:4,int64:8},YH=1e5,XH=e=>e.fmt===`string`||JH[e.fmt]!==void 0,ZH={...FR,async plan(e,t){let n=new Map,r=``;for await(let e of UH(t)){let t=TR(e.body);if(e.tag===1)r=kR(e.body);else if(e.tag===2){let r=t.getUint32(0,!0),i=kR(e.body.subarray(4)),a=parseInt(zH(i,`channel_count`),10)||1;if(!(a>=1&&a<=YH))throw Error(`This XDF file is damaged (a stream with ${a} channels).`);let o=BH(i,`channel`);n.set(r,{id:r,name:zH(i,`name`)||`Stream ${r}`,nch:a,srate:parseFloat(zH(i,`nominal_srate`))||0,fmt:zH(i,`channel_format`)||`float32`,labels:Array.from({length:a},(e,t)=>zH(o[t]??``,`label`)||`Ch${t+1}`),units:Array.from({length:a},(e,t)=>zH(o[t]??``,`unit`)),count:0,segs:[],clock:[],c0:0,c1:0,lastTs:NaN})}else if(e.tag===3){let r=n.get(t.getUint32(0,!0));if(!r||!XH(r))continue;let[i,a]=VH(e.body,t,4),o=4+a,s=JH[r.fmt],c=r.srate>0?Math.max(1,500/r.srate):1/0;for(let n=0;n<i&&!(HH(e.body,t,o,r)<0);n++){let n;if(e.body[o++]===8?(n=t.getFloat64(o,!0),o+=8):n=r.lastTs+(r.srate>0?1/r.srate:0),r.fmt===`string`)for(let n=0;n<r.nch;n++){let[n,r]=VH(e.body,t,o);o+=r+n}else o+=s*r.nch;if(r.srate>0){let e=r.segs[r.segs.length-1];(!e||n-r.lastTs>c)&&r.segs.push(e={i0:r.count,t0:n,n:0,si:0,st:0,sii:0,sit:0,a:0,b:0}),WH(e,r.count,n)}else r.count===0&&r.segs.push({i0:0,t0:n,n:1,si:0,st:0,sii:0,sit:0,a:0,b:0});r.lastTs=n,r.count++}}else if(e.tag===4){let e=n.get(t.getUint32(0,!0));e&&e.clock.push([t.getFloat64(4,!0),t.getFloat64(12,!0)])}}let i=[],a=[...n.values()].sort((e,t)=>e.id-t.id).filter(e=>(XH(e)||i.push(`${e.name}: channel format ${e.fmt} is not supported; skipped.`),XH(e))),o=1/0;for(let e of a){[e.c0,e.c1]=KH(e.clock);for(let t of e.segs)GH(t);if(e.count===0)continue;let t=e.srate>0?qH(e,e.segs[0],0):e.segs[0].t0+e.c0+e.c1*e.segs[0].t0;o=Math.min(o,t)}let s=Fz(a.map(e=>e.name),[]),c=a.map((e,t)=>({name:s[t],channels:e.labels.map((t,n)=>({name:t,unit:e.units[n],...e.fmt===`string`?{text:!0,sparse:!0}:{}})),samples:e.count,time:{kind:`timestamps`},rateHz:e.srate>0?e.srate:null,irregular:e.srate===0})),l=zH(r,`version`);return{format:`XDF ${l||`1.0`}`,startTime:null,groups:c,meta:{header:l},events:[],notes:i,state:{streams:a,origin:Number.isFinite(o)?o:0}}},async*stream(e){let t=e.plan.state,n=8192,r=new Map,i=e=>e.sel.map(()=>e.s.fmt===`string`?Array(n):new Float64Array(n));for(let a of e.selection){let o=t.streams[a.group],s={g:a.group,s:o,sel:Xz(e,a.group),time:new Float64Array(n),cols:[],n:0,start:0,seg:0,i:0,raw:NaN};s.cols=i(s),r.set(o.id,s)}let a=e=>{let t={group:e.g,time:e.time.slice(0,e.n),start:e.start,length:e.n,columns:e.cols.map(t=>t.slice(0,e.n))};return e.start+=e.n,e.n=0,e.time=new Float64Array(n),e.cols=i(e),t};for await(let i of UH(e.io,e.signal)){if(i.tag!==3)continue;let e=TR(i.body),o=r.get(e.getUint32(0,!0));if(!o)continue;let s=o.s,[c,l]=VH(i.body,e,4),u=4+l,d=JH[s.fmt],f=[];for(let r=0;r<c&&!(HH(i.body,e,u,s)<0);r++){let r;i.body[u++]===8?(r=e.getFloat64(u,!0),u+=8):r=o.raw+(s.srate>0?1/s.srate:0),o.raw=r;let c;if(s.srate>0){for(;o.seg+1<s.segs.length&&s.segs[o.seg+1].i0<=o.i;)o.seg++;c=qH(s,s.segs[o.seg],o.i)}else c=r+s.c0+s.c1*r;if(o.time[o.n]=c-t.origin,s.fmt===`string`){let n=[];for(let t=0;t<s.nch;t++){let[t,r]=VH(i.body,e,u);n.push(kR(i.body.subarray(u+r,u+r+t))),u+=r+t}o.sel.forEach((e,t)=>{o.cols[t][o.n]=n[e]}),f.push({time:c-t.origin,text:n.join(` `)})}else o.sel.forEach((t,n)=>{let r=u+t*d,i=o.cols[n];switch(s.fmt){case`float32`:i[o.n]=e.getFloat32(r,!0);break;case`double64`:i[o.n]=e.getFloat64(r,!0);break;case`int8`:i[o.n]=e.getInt8(r);break;case`int16`:i[o.n]=e.getInt16(r,!0);break;case`int32`:i[o.n]=e.getInt32(r,!0);break;default:i[o.n]=e.getInt32(r+4,!0)*4294967296+e.getUint32(r,!0)}}),u+=d*s.nch;o.i++,++o.n===n&&(yield a(o))}f.length&&(yield{group:o.g,time:new Float64Array,start:o.start,length:0,columns:o.sel.map(()=>new Float64Array),events:f})}for(let e of r.values())e.n&&(yield a(e))}}}));function $H(e,t,n,r,i){switch(r){case mU:{let r=e.getUint32(n,i);return[kR(t.subarray(n+4,n+4+r)),4+r]}case 1:return[e.getInt8(n),1];case 2:return[e.getInt16(n,i),2];case 3:return[e.getInt32(n,i),4];case 4:return[SR(e,n,i),8];case 5:return[e.getUint8(n),1];case 6:return[e.getUint16(n,i),2];case 7:return[e.getUint32(n,i),4];case 8:return[xR(e,n,i),8];case 9:case 25:return[e.getFloat32(n,i),4];case 10:case 26:return[e.getFloat64(n,i),8];case 33:return[e.getUint8(n)!==0,1];case hU:return[bU(e,n,i),16];default:throw Error(`This TDMS file has a property of type ${r}, which Kymoscope cannot read.`)}}function eU(e){let t=/^\/'((?:[^']|'')*)'(?:\/'((?:[^']|'')*)')?$/.exec(e);return t?[t[1].replace(/''/g,`'`),(t[2]??``).replace(/''/g,`'`)]:null}function tU(e){if(e.has(`NI_Number_Of_Scales`))return Number(e.get(`NI_Number_Of_Scales`));let t=0;for(let n of e.keys()){let e=/^NI_Scale\[(\d+)\]_Scale_Type$/.exec(n);e&&(t=Math.max(t,Number(e[1])+1))}return t}function nU(e,t,n){let r=e.find(e=>tU(e)>0);if(!r||r.get(`NI_Scaling_Status`)===`scaled`)return null;let i=(e,a)=>{if(e===xU||e<0||a>8)return e=>e;let o=r.get(`NI_Scale[${e}]_Scale_Type`);if(o===void 0)return e=>e;if(o===`Linear`){let t=Number(r.get(`NI_Scale[${e}]_Linear_Slope`)),n=Number(r.get(`NI_Scale[${e}]_Linear_Y_Intercept`)??0),o=i(Number(r.get(`NI_Scale[${e}]_Linear_Input_Source`)??xU),a+1);return o&&(e=>t*o(e)+n)}if(o===`Polynomial`){let o=Number(r.get(`NI_Scale[${e}]_Polynomial_Coefficients_Size`)??4);if(!(Number.isInteger(o)&&o>=0&&o<=64))return t.push(`${n}: an NI polynomial scale with ${o} coefficients is not supported; raw values are shown.`),null;let s=Array.from({length:o},(t,n)=>Number(r.get(`NI_Scale[${e}]_Polynomial_Coefficients[${n}]`))),c=i(Number(r.get(`NI_Scale[${e}]_Polynomial_Input_Source`)??xU),a+1);return c&&(e=>{let t=c(e),n=0;for(let e=o-1;e>=0;e--)n=n*t+s[e];return n})}return t.push(`${n}: NI scale type ${String(o)} is not supported; raw values are shown.`),null};return i(tU(r)-1,0)}function rU(e,t,n,r,i,a,o,s){let c=SU[e];if(c&&a&&r===gU[e]&&(t.byteOffset+n)%r===0){o.set(new c(t.buffer,t.byteOffset+n,i),s);return}switch(e){case 1:for(let e=0;e<i;e++,n+=r)o[s+e]=t.getInt8(n);return;case 2:for(let e=0;e<i;e++,n+=r)o[s+e]=t.getInt16(n,a);return;case 3:for(let e=0;e<i;e++,n+=r)o[s+e]=t.getInt32(n,a);return;case 4:for(let e=0;e<i;e++,n+=r)o[s+e]=SR(t,n,a);return;case 5:case 33:for(let e=0;e<i;e++,n+=r)o[s+e]=t.getUint8(n);return;case 6:for(let e=0;e<i;e++,n+=r)o[s+e]=t.getUint16(n,a);return;case 7:for(let e=0;e<i;e++,n+=r)o[s+e]=t.getUint32(n,a);return;case 8:for(let e=0;e<i;e++,n+=r)o[s+e]=xR(t,n,a);return;case 9:case 25:for(let e=0;e<i;e++,n+=r)o[s+e]=t.getFloat32(n,a);return;case 10:case 26:for(let e=0;e<i;e++,n+=r)o[s+e]=t.getFloat64(n,a);return;case hU:for(let e=0;e<i;e++,n+=r)o[s+e]=bU(t,n,a);return;default:o.fill(NaN,s,s+i)}}async function iU(e,t,n){let r=new Map,i=[],a=[],o=new Map,s=new Map,c=t??e,l=0,u=0;for(;l+28<=e.size&&u+28<=c.size;){let d=t?u:l,f=await c.read(d,28),p=TR(f);if(!(f[0]===84&&f[1]===68&&f[2]===83&&(f[3]===109||f[3]===104)))throw Error(`This TDMS file is damaged (no segment lead-in where one should be).`);let m=p.getUint32(4,!0),h=!(m&dU),g=xR(p,12,h),_=xR(p,20,h),v=g>=2**53?e.size:Math.min(e.size,l+28+g);if(_>v-l-28)throw Error(`This TDMS file is damaged (segment metadata longer than its segment).`);if(m&sU){let e=await c.read(d+28,_),t=TR(e);m&lU&&(a=[],o=new Map);let i=0,l=t.getUint32(i,h);i+=4;for(let c=0;c<l;c++){let c=t.getUint32(i,h),l=kR(e.subarray(i+4,i+4+c));i+=4+c;let u=eU(l),d=r.get(l);d||r.set(l,d={path:l,group:u?.[0]??``,name:u?.[1]??``,type:0,props:new Map,pieces:[],total:0});let f=t.getUint32(i,h);i+=4;let p=null;if(f===4294967295)p=null;else if(f===0)p=s.get(d)??null;else if(f===fU||f===pU){let e=xR(t,i+8,h),r=t.getUint32(i+16,h),a=f===fU?20:17,o=i+20,s=_U[t.getUint32(o,h)]??0,c=t.getUint32(o+8,h);i=o+r*a;let l=t.getUint32(i,h);i+=4;let u=0;for(let e=0;e<l;e++)u+=t.getUint32(i+4*e,h);i+=4*l,f===pU?n.push(`${d.name}: DAQmx digital line data is not supported; skipped.`):(r>1&&n.push(`${d.name}: only the first of its ${r} DAQmx scalers is read.`),p={type:s,count:e,bytes:0,daqmx:{byteOffset:c,stride:u}})}else{let e=t.getUint32(i,h),n=xR(t,i+8,h),r=e===mU?xR(t,i+16,h):n*(gU[e]??0);i+=f-4,p={type:e,count:n,bytes:r,daqmx:null}}p&&(d.type=p.type,s.set(d,p));let m=t.getUint32(i,h);i+=4;for(let n=0;n<m;n++){let n=t.getUint32(i,h),r=kR(e.subarray(i+4,i+4+n));i+=4+n;let a=t.getUint32(i,h);i+=4;let[o,s]=$H(t,e,i,a,h);d.props.set(r,o),i+=s}let g=o.get(d);g===void 0?o.set(d,a.push({obj:d,idx:p})-1):a[g].idx=p}}if(m&cU){let e=l+28+_,t=a.filter(e=>e.idx&&e.idx.count>0),n=t.filter(e=>e.idx.daqmx),r=(m&uU)!==0,o=0,s=0;n.length?(s=n[0].idx.daqmx.stride,o=n[0].idx.count*s):r?(s=t.reduce((e,t)=>e+(gU[t.idx.type]??0),0),o=(t[0]?.idx.count??0)*s):o=t.reduce((e,t)=>e+t.idx.bytes,0);let c=o>0?Math.floor((v-e)/o):0,u=i.push({rawStart:e,chunkSize:o,chunks:c,le:h})-1,d=0;for(let e of t){let t=e.idx,n=gU[t.type]??0,i=t.daqmx?{seg:u,count:t.count,offset:t.daqmx.byteOffset,bytes:0,stride:s,type:t.type}:{seg:u,count:t.count,offset:d,bytes:t.bytes,stride:r?s:n,type:t.type};t.daqmx||(d+=r?n:t.bytes),i.type===mU?i.count=Math.min(i.count,Math.floor(i.bytes/4)):n>0&&(i.count=Math.min(i.count,i.stride>0?Math.max(0,Math.floor((o-i.offset-n)/i.stride)+1):0)),e.obj.pieces.push(i),c&&(e.obj.total+=i.count*c)}}if(l=v,u+=28+_,v>=e.size)break}return{objs:[...r.values()],segments:i}}function aU(e,t,n,r,i,a){let o=0;for(;o<i&&r.pi<t.pieces.length;){let s=t.pieces[r.pi],c=e.segments[s.seg];if(r.chunk>=c.chunks){r.pi++,r.chunk=0,r.row=0;continue}let l=Math.min(i-o,s.count-r.row),u=c.rawStart+r.chunk*c.chunkSize+s.offset;if(s.type===mU)a.push({ch:n,at:u,end:u+s.bytes,rows:l,first:r.row,out:o,piece:s,le:c.le,range:0});else{let e=u+r.row*s.stride;a.push({ch:n,at:e,end:e+(l-1)*s.stride+gU[s.type],rows:l,first:r.row,out:o,piece:s,le:c.le,range:0})}o+=l,r.row+=l,r.row>=s.count&&(r.chunk++,r.row=0)}}async function*oU(e,t){let n=e.plan.state,r=n.groups[t],i=Xz(e,t).map(e=>r.channels[e]),a=r.time?[r.time,...i]:i;if(!a.length)return;let o=new Map(n.objs.map(e=>[e.path,e.props])),s=e=>o.get(e)??new Map,c=s(`/`),l=a.map(e=>nU([e.props,s(`/'${e.group.replace(/'/g,`''`)}'`),c],[],e.name)),u=a.map(()=>({pi:0,chunk:0,row:0})),d=a.reduce((e,t)=>Math.min(e,t.total),1/0);for(let i=0;i<d;){e.signal?.throwIfAborted();let o=Math.min(vU,d-i),s=[];a.forEach((e,t)=>aU(n,e,t,u[t],o,s));let c=s.slice().sort((e,t)=>e.at-t.at),f=[];for(let e of c){let t=f[f.length-1];t&&e.at<=t.end+yU&&Math.max(t.end,e.end)-t.at<=16777216?t.end=Math.max(t.end,e.end):f.push({at:e.at,end:e.end}),e.range=f.length-1}let p=[];for(let t of f)p.push(await e.io.slice(t.at,t.end-t.at));let m=p.map(TR),h=a.map(e=>e.type===mU?Array(o).fill(null):new Float64Array(o).fill(NaN));for(let e of s){let t=e.at-f[e.range].at,n=e.piece;if(n.type===mU){let r=p[e.range],i=m[e.range],a=t+4*n.count,o=h[e.ch];for(let n=0;n<e.rows;n++){let s=e.first+n,c=s===0?0:i.getUint32(t+4*(s-1),e.le),l=i.getUint32(t+4*s,e.le);o[e.out+n]=kR(r.subarray(a+c,a+l))}}else rU(n.type,m[e.range],t,n.stride,e.rows,e.le,h[e.ch],e.out)}for(let e=0;e<a.length;e++){let t=l[e],n=h[e];if(t&&n instanceof Float64Array)for(let e=0;e<o;e++)n[e]=t(n[e])}let g=null;if(r.time){g=h.shift();for(let e=0;e<o;e++)g[e]-=r.origin}yield{group:t,time:g,start:i,length:o,columns:h},i+=o}}var sU,cU,lU,uU,dU,fU,pU,mU,hU,gU,_U,vU,yU,bU,xU,SU,CU,wU=c((()=>{qz(),AR(),Zz(),RR(),sU=2,cU=8,lU=4,uU=32,dU=64,fU=4713,pU=4714,mU=32,hU=68,gU={1:1,2:2,3:4,4:8,5:1,6:2,7:4,8:8,9:4,10:8,25:4,26:8,33:1,68:16},_U={0:5,1:1,2:6,3:2,4:7,5:3,6:8,7:4,8:9,9:10,4294967295:hU},vU=65536,yU=65536,bU=(e,t,n)=>n?SR(e,t+8,n)+xR(e,t,n)/2**64:SR(e,t,n)+xR(e,t+8,n)/2**64,xU=4294967295,SU={1:Int8Array,2:Int16Array,3:Int32Array,5:Uint8Array,6:Uint16Array,7:Uint32Array,9:Float32Array,10:Float64Array,25:Float32Array,26:Float64Array,33:Uint8Array},CU={...LR,async plan(e,t){let n=e.companions.find(e=>e.name.toLowerCase().endsWith(`.tdms_index`)),r=[],{objs:i,segments:a}=await iU(t,n?new Kz(n):null,r),o=i.find(e=>e.path===`/`)?.props,s=i.filter(e=>e.name&&e.total>0&&(e.type===mU||gU[e.type])),c=new Set(s);for(let e of i)e.name&&e.total>0&&!c.has(e)&&r.push(`${e.name}: TDMS data type ${e.type} is not supported; skipped.`);let l=s.map(e=>e.props.get(`wf_start_time`)).filter(e=>typeof e==`number`),u=l.reduce((e,t)=>Math.min(e,t),l.length?1/0:0),d=new Map;for(let e of s){let t=`${e.total}|${e.props.get(`wf_increment`)??``}`,n=d.get(e.group)??new Map,r=n.get(t);r?r.push(e):n.set(t,[e]),d.set(e.group,n)}let f=[],p=[];for(let[e,t]of d)for(let n of t.values()){let r=n[0].props.get(`wf_increment`),i=typeof r==`number`&&r>0?1/r:null,a=i?null:n.find(e=>e.type===hU)??n.find(e=>e.type!==mU&&/^(time|timestamp|t)$/i.test(e.name))??null,o=n.filter(e=>e!==a),s=n[0].props.get(`wf_start_time`),c=i?Number(n[0].props.get(`wf_start_offset`)??0)+(typeof s==`number`?s-u:0):0;f.push({name:t.size===1?e:`${e} (${i?+i.toFixed(6):n[0].total} ${i?`Hz`:`samples`})`,channels:o.map(e=>({name:e.name,unit:String(e.props.get(`unit_string`)??``),text:e.type===mU})),samples:n[0].total,time:i?{kind:`rate`,rate:i,start:c}:a?{kind:`timestamps`}:{kind:`index`},rateHz:i}),p.push({channels:o,time:a,origin:0})}if(f.length===0)throw Error(`This TDMS file has no channels with data.`);let m=[];for(let e of p){if(!e.time)continue;let n=e.time.pieces[0],r=a[n.seg],i=await t.read(r.rawStart+n.offset,gU[n.type]??8),o=new Float64Array(1);rU(n.type,TR(i),0,0,1,r.le,o,0),m.push(o[0])}let h=m.reduce((e,t)=>Math.min(e,t),m.length?1/0:0);for(let e of p)e.origin=h;let g=new Date(Date.UTC(1904,0,1)+u*1e3),_=u&&Number.isFinite(g.getTime())?g.toISOString():null,v={objs:i,segments:a,groups:p},y={};for(let[e,t]of o??[])typeof t==`string`&&(y[e]=t);return{format:`TDMS`,startTime:_,groups:f,meta:y,events:[],notes:r,state:v}},async*stream(e){for(let t of e.selection)yield*oU(e,t.group)},streamGroup:(e,t)=>oU(e,t)}}));function TU(){let e=new Set,t=0,n=!1;return{enter(t){let r=null;try{r=t.create_reference?Array.prototype.join.call(t.create_reference().ref_data,`,`):null}catch{r=null}return r===null?!0:e.has(r)?(n=!0,!1):(e.add(r),!0)},count:()=>++t<=PU,note:()=>t>1e5?`This file has more than ${PU.toLocaleString(`en-US`)} objects (or links that repeat its groups); only the first were read.`:n?`Some groups of this file link back to a group already read; each was read once.`:null}}function EU(e,t,n,r){return t.reduce((e,t)=>e*t,1)*Math.max(1,e.metadata.size||1)>(r?n*1032+1024:n)}function DU(){!IU||LU||(LU=IU(),LU.catch(()=>{LU=null}))}function OU(e){if(!IU)return Promise.reject(Error(`HDF5 and MAT 7.3 files are read in the import worker, and this environment has no workers.`));DU();let t=RU.get(e);return t||(t=LU.then(t=>t(e)).then(e=>({root:e.root,close:()=>{}})),RU.set(e,t),t.catch(()=>RU.delete(e))),t}function kU(e,t,n){let r=zU.get(e);r||zU.set(e,r=new Map);let i=r.get(t);return i||r.set(t,i=n??e.get(t)),i}function AU(e){return e instanceof Float64Array?e:e instanceof BigInt64Array||e instanceof BigUint64Array?Float64Array.from(e,e=>Number(e)):ArrayBuffer.isView(e)?new Float64Array(e):Float64Array.from(e)}function jU(e,...t){for(let n of t){let t=e[n]?.value;if(typeof t==`string`)return t;if(Array.isArray(t)&&typeof t[0]==`string`)return t[0]}return``}function MU(e,...t){for(let n of t){let t=e[n]?.value,r=typeof t==`number`?t:ArrayBuffer.isView(t)?Number(t[0]):NaN;if(Number.isFinite(r))return r}return null}var NU,PU,FU,IU,LU,RU,zU,BU,VU=c((()=>{NU=e=>!!e&&typeof e.keys==`function`,PU=1e5,FU=e=>!!e&&typeof e.slice==`function`,IU=null,LU=null,RU=new WeakMap,zU=new WeakMap,BU={s:1,sec:1,second:1,seconds:1,ms:.001,msec:.001,us:1e-6,µs:1e-6,ns:1e-9}}));function HU(e,t,n,r,i,a,o=0){i.set(n,t.attrs);for(let s of t.keys()){if(!a.count())return;let c=n===`/`?`/${s}`:`${n}/${s}`,l=t.get(s);if(NU(l))o<16&&a.enter(l)&&HU(e,l,c,r,i,a,o+1);else if(FU(l)){let t=kU(e,c,l);r.push({path:c,parent:n,name:s,ds:t,attrs:t.attrs})}}}async function UU(e,t){let n=kU(e,t.path);if(t.col===null)return AU(n.slice([[0,1]]))[0]*t.factor;let r=n.slice([[0,1]]);return Number(r[0][t.col])*t.factor}async function*WU(e,t){let n=e.plan.state.groups[t],r=Xz(e,t).map(e=>n.cols[e]),i=await OU(e.files.main);try{let a=n.chunk??0,o=a>0?Math.max(1,Math.min(Math.floor((1<<20)/a),Math.ceil($U(r.length+1)/a)))*a:$U(r.length+1);for(let a=0;a<n.rows;a+=o){e.signal?.throwIfAborted();let s=Math.min(n.rows,a+o),c=s-a,l=null,u=e=>{let t=kU(i.root,e.path);if(n.kind===`vectors`){let n=t.slice([[a,s]]);if(e.text)return Array.from(n,e=>e==null?null:String(e));let r=AU(n);if(e.factor!==1)for(let t=0;t<c;t++)r[t]*=e.factor;return r}let r=new Float64Array(c);if(n.kind===`matrix`){let n=(t.shape??[0,1])[1],i=l??=t.slice([[a,s],[0,n]]);for(let t=0;t<c;t++)r[t]=Number(i[t*n+e.col])}else{let n=l??=t.slice([[a,s]]);for(let t=0;t<c;t++)r[t]=Number(n[t][e.col])*e.factor}return r},d=null;if(n.time){d=u(n.time);for(let e=0;e<c;e++)d[e]-=n.origin}yield{group:t,time:d,start:a,length:c,columns:r.map(u)}}}finally{i.close()}}var GU,KU,qU,JU,YU,XU,ZU,QU,$U,eW,tW=c((()=>{Zz(),WR(),VU(),GU=0,KU=1,qU=3,JU=6,YU=new Set([1,2,3,4,5,6]),XU=/^(time|t|timestamps?|.*[_ ]time|time[_ ].*)$/i,ZU=[`sampling_rate`,`sample_rate`,`samplerate`,`sampleRate`,`fs`,`Fs`,`rate`],QU=e=>e===`/`?`root`:e.slice(1),$U=e=>Math.max(4096,Math.min(1<<20,Math.floor((8<<20)/(8*Math.max(1,e))))),eW={...UR,async plan(e){let t=await OU(e.main);try{let n=[],r=new Map,i=TU();i.enter(t.root),HU(t.root,t.root,`/`,n,r,i);let a=[],o=i.note();o&&a.push(o);let s=new Map,c=[],l=0;for(let t of n){let n=t.ds.metadata.shape??[],r=t.ds.metadata.type,i=t.ds.metadata.chunks?t.ds.filters??[]:[],o=i.find(e=>!YU.has(e.id)),u=!o;if(u&&i.length>0&&n.length>0&&n.every(e=>e>0))try{t.ds.slice(n.map(()=>[0,1]))}catch{u=!1}if(!u){a.push(`${t.path}: compressed with a filter Kymoscope cannot read${o?` (${o.name||o.id})`:``}; skipped.`);continue}if(EU(t.ds,n,e.main.size,i.length>0)){a.push(`${t.path}: larger than the file can hold (never written, or damaged); skipped.`);continue}if(n.length===1&&n[0]>1&&(r===GU||r===KU||r===qU)){let e=`${t.parent}|${n[0]}`,r=s.get(e)??{parent:t.parent,n:n[0],leaves:[]};r.leaves.push(t),s.set(e,r)}else if(n.length===2&&n[0]>1&&n[1]<=4096&&(r===GU||r===KU)){let e=MU(t.attrs,...ZU);c.push({name:QU(t.path),kind:`matrix`,rows:n[0],rate:e,time:null,origin:0,cols:Array.from({length:n[1]},(e,n)=>({path:t.path,col:n,text:!1,factor:1}))})}else if(n.length===1&&r===JU){let e=(t.ds.metadata.compound_type?.members??[]).flatMap((e,n)=>e.type===GU||e.type===KU?[{path:t.path,col:n,text:!1,factor:1,name:e.name}]:[]),r=e.find(e=>XU.test(e.name));c.push({name:QU(t.path),kind:`compound`,rows:n[0],rate:null,origin:0,time:r??null,cols:e.filter(e=>e!==r)})}else l++}for(let e of s.values()){let t=[...s.values()].filter(t=>t.parent===e.parent).length>1,n=e.leaves.find(e=>jU(e.attrs,`CLASS`)===`DIMENSION_SCALE`)??e.leaves.find(e=>XU.test(e.name)&&e.ds.metadata.type!==qU),i=n?BU[jU(n.attrs,`units`,`unit`,`Units`)]??1:1,a=n?null:MU(r.get(e.parent)??{},...ZU);c.push({name:t?`${QU(e.parent)} (${e.n} rows)`:QU(e.parent),kind:`vectors`,rows:e.n,rate:a,origin:0,time:n?{path:n.path,col:null,text:!1,factor:i}:null,cols:e.leaves.filter(e=>e!==n).map(e=>({path:e.path,col:null,text:e.ds.metadata.type===qU,factor:1}))})}l&&a.push(`${l} dataset${l===1?``:`s`} with other shapes or types (images, references, 3-D) skipped.`),c.sort((e,t)=>e.name.localeCompare(t.name));let u=c.map((e,t)=>e.time||e.rate?t:-1).filter(e=>e>=0),d=1/0;for(let e of c)e.time&&(d=Math.min(d,await UU(t.root,e.time)));for(let e of c)e.origin=Number.isFinite(d)?d:0;let f=new Map(n.map(e=>[e.path,e]));for(let e of c)e.chunk=[...e.cols,...e.time?[e.time]:[]].reduce((e,t)=>Math.max(e,f.get(t.path).ds.metadata.chunks?.[0]??0),0);let p=e=>jU(f.get(e.path).attrs,`units`,`unit`,`Units`,`UNITS`),m=(e,t)=>e.kind===`matrix`?`${e.name.split(`/`).pop()}[${t.col+1}]`:e.kind===`compound`?f.get(t.path).ds.metadata.compound_type.members[t.col].name:t.path.split(`/`).pop(),h=c.map(e=>({name:e.name,channels:e.cols.map(t=>({name:m(e,t),unit:e.kind===`vectors`?p(t):``,text:t.text})),samples:e.rows,time:e.time?{kind:`timestamps`}:e.rate?{kind:`rate`,rate:e.rate,start:0}:{kind:`index`},rateHz:e.rate}));if(h.length===0)throw Error(`This HDF5 file has no datasets Kymoscope can plot.`);let g=h.length>20||h.length>1&&u.length<h.length,_=g?u.length?u:[c.reduce((e,t,n)=>t.rows*t.cols.length>c[e].rows*c[e].cols.length?n:e,0)]:void 0;return g&&a.push(`Only the groups with a time base are read unless you choose others in the channel picker.`),{format:`HDF5`,startTime:null,groups:h,meta:{},events:[],notes:a,pick:g,defaultGroups:_,state:{groups:c}}}finally{t.close()}},async*stream(e){for(let t of e.selection)yield*WU(e,t.group)},streamGroup:(e,t)=>WU(e,t)}}));function nW(e,t){let n=/^(.*)\.values(\[\d+\])?$/.exec(e.name),r=n&&(t.get(`${n[1]}.label`)||t.get(`${n[1]}.blockName`));return r?{...e,name:`${r}${n[2]??``}`}:e}function rW(e,t,n){let r=new Map;for(let t of e){if(!(t.length>1))continue;let e=r.get(t.length);e?e.push(t):r.set(t.length,[t])}let i=[...n].filter(([e])=>sW.test(cW(e))),a=i.length===1?i[0][1]:null,o=[];for(let[e,n]of r){let r=n.find(e=>oW.test(cW(e.name))||/(_time|\.Time)$/.test(e.name))??null;o.push({name:r?lW(r.name)||r.name:`${e} samples`,channels:n.filter(e=>e!==r).map(e=>nW(e,t)),time:r,rate:r?null:a,origin:0})}return o}function iW(e){return e.map(e=>({name:e.name,channels:e.channels.map(e=>({name:e.name,unit:``})),samples:e.channels[0]?.length??e.time?.length??0,time:e.time?{kind:`timestamps`}:e.rate?{kind:`rate`,rate:e.rate,start:0}:{kind:`index`},rateHz:e.rate}))}async function aW(e){let t=1/0;for(let n of e)n.time&&(t=Math.min(t,(await n.time.read(0,1))[0]));for(let n of e)n.origin=Number.isFinite(t)?t:0}var oW,sW,cW,lW,uW=c((()=>{oW=/^(time|t|tout|timestamps?)$/i,sW=/^(fs|sample_?rate|sampling_?rate|rate|samplerate)$/i,cW=e=>e.slice(e.lastIndexOf(`.`)+1),lW=e=>e.includes(`.`)?e.slice(0,e.lastIndexOf(`.`)):``}));function dW(e,t,n,r,i=1){let a=TR(t),o=r.length,s=vW[e]*i;if(e===9&&i===1&&n){r.set(t.byteOffset%8==0?new Float64Array(t.buffer,t.byteOffset,o):new Float64Array(t.slice(0,o*8).buffer));return}switch(e){case 1:for(let e=0,t=0;e<o;e++,t+=s)r[e]=a.getInt8(t);return;case 2:for(let e=0,t=0;e<o;e++,t+=s)r[e]=a.getUint8(t);return;case 3:for(let e=0,t=0;e<o;e++,t+=s)r[e]=a.getInt16(t,n);return;case 4:for(let e=0,t=0;e<o;e++,t+=s)r[e]=a.getUint16(t,n);return;case 5:for(let e=0,t=0;e<o;e++,t+=s)r[e]=a.getInt32(t,n);return;case 6:for(let e=0,t=0;e<o;e++,t+=s)r[e]=a.getUint32(t,n);return;case 7:for(let e=0,t=0;e<o;e++,t+=s)r[e]=a.getFloat32(t,n);return;case 9:for(let e=0,t=0;e<o;e++,t+=s)r[e]=a.getFloat64(t,n);return;case 12:for(let e=0,t=0;e<o;e++,t+=s)r[e]=a.getInt32(t+(n?4:0),n)*4294967296+a.getUint32(t+(n?0:4),n);return;case 13:for(let e=0,t=0;e<o;e++,t+=s)r[e]=a.getUint32(t+(n?4:0),n)*4294967296+a.getUint32(t+(n?0:4),n);return;default:r.fill(NaN)}}async function fW(e,t,n){let r=TR(await e.read(t,8)),i=r.getUint32(0,n);if(i>>>16)return{type:i&65535,bytes:i>>>16,data:t+4,next:t+8};let a=r.getUint32(4,n);return{type:i,bytes:a,data:t+8,next:i===15?t+8+a:t+8+a+(8-a%8)%8}}function pW(e,t,n,r,i){let[a,o]=t,s=vW[r.type];if(!s)return[];let c=(e,t)=>async(a,o)=>{let c=new Float64Array(o-a);return t===1?dW(r.type,await n.read(r.data+(e+a)*s,(o-a)*s),i,c):dW(r.type,await n.read(r.data+(e+a*t)*s,((o-a-1)*t+1)*s),i,c,t),c};return a===1||o===1?[{name:e,length:a*o,read:c(0,1)}]:a>=o?Array.from({length:o},(t,n)=>({name:`${e}[${n+1}]`,length:a,read:c(n*a,1)})):Array.from({length:a},(t,n)=>({name:`${e}[${n+1}]`,length:o,read:c(n,a)}))}async function mW(e,t,n,r,i,a,o){let s=t,c=await fW(e,s,n),l=TR(await e.read(c.data,8)).getUint32(0,n),u=l&255;s=c.next;let d=await fW(e,s,n);if(d.bytes>128){a.notes.push(`A MAT variable with more than 32 dimensions was skipped (damaged).`);return}let f=TR(await e.read(d.data,d.bytes)),p=Array.from({length:d.bytes/4},(e,t)=>f.getInt32(4*t,n));s=d.next;let m=await fW(e,s,n),h=OR(await e.read(m.data,m.bytes));s=m.next;let g=i??h,_=r?`${r}.${g}`:g,v=p.reduce((e,t)=>e*t,1);if(u>=6&&u<=15){if(v===0)return;let t=await fW(e,s,n);if(l&2048&&a.notes.push(`${_}: the imaginary part was skipped.`),p.length>2){a.notes.push(`${_}: arrays with more than two dimensions are skipped.`);return}if(!vW[t.type])return;if(!(v>0)||v*vW[t.type]>t.bytes||t.data+t.bytes>e.size){a.notes.push(`${_}: its data is shorter than its dimensions (damaged); skipped.`);return}if(v===1){let r=new Float64Array(1);dW(t.type,await e.read(t.data,vW[t.type]??8),n,r),a.scalars.set(_,r[0]);return}a.channels.push(...pW(_,p,e,t,n));return}if(u===4){let t=await fW(e,s,n);if(t.bytes>yW)return;let r=await e.read(t.data,t.bytes),i=t.type===3||t.type===4||t.type===17?new TextDecoder(n?`utf-16le`:`utf-16be`).decode(r.subarray(0,r.length&-2)):kR(r);p[0]<=1&&a.strings.set(_,i);return}if(u===2){let t=await fW(e,s,n),r=TR(await e.read(t.data,4)).getInt32(0,n);s=t.next;let i=await fW(e,s,n);if(!(r>0))return;let c=await e.read(i.data,i.bytes),l=Array.from({length:Math.floor(c.length/r)},(e,t)=>CR(c.subarray(t*r,(t+1)*r)));if(s=i.next,l.length===0||v*l.length*8>e.size-s){v>0&&l.length>0&&a.notes.push(`${_}: its fields are longer than the file (damaged); skipped.`);return}for(let t=0;t<v;t++){let r=v>1?`${_}(${t+1})`:_;for(let t of l){let i=await fW(e,s,n);i.type===14&&i.bytes>0&&o<16&&await mW(e,i.data,n,r,t,a,o+1),s=i.next}}return}u===1?a.notes.push(`${_}: cell arrays are skipped.`):u===5?a.notes.push(`${_}: sparse arrays are skipped.`):a.notes.includes(bW)||a.notes.push(bW)}async function hW(e){let t=OR((await e.read(0,128)).subarray(126,128))===`IM`,n={channels:[],strings:new Map,scalars:new Map,notes:[],sources:[]},r=new gW(e),i=0;for(let a=128;a+8<=e.size;){let o=await fW(r,a,t);if(o.type===15){if(o.bytes>1<<30)throw Error(`A compressed variable in this MAT file is over 1 GB; save it with -v7.3 to open it here.`);let r=await e.slice(o.data,o.bytes),a=await EV(r,-1,8),s=a.length<8?0:8+TR(a).getUint32(4,t);if(s>lz(o.bytes))throw Error(`A compressed variable in this MAT file is damaged.`);if(s>1<<30)throw Error(`A compressed variable in this MAT file is over 1 GB; save it with -v7.3 to open it here.`);let c=await EV(r,s,s),l=new _W(e,o.data,o.bytes,c);n.sources.push(l),i+=c.length;let u=await fW(l,0,t);if(u.type===14&&await mW(l,u.data,t,``,null,n,0),i>xW)for(let e of n.sources)e.keep=!1,e.release()}else o.type===14&&await mW(r,o.data,t,``,null,n,0);a=o.next}return n}var gW,_W,vW,yW,bW,xW,SW=c((()=>{AR(),gz(),kV(),gW=class{#e;size;constructor(e){this.#e=e,this.size=e.size}read(e,t){return t>=65536?this.#e.slice(e,t):this.#e.read(e,t)}release(){}},_W=class{#e;#t;#n;#r=null;keep=!0;size;constructor(e,t,n,r){this.#e=e,this.#t=t,this.#n=n,this.#r=r,this.size=r.length}async read(e,t){return this.#r??=await EV(await this.#e.slice(this.#t,this.#n),this.size,this.size),this.#r.subarray(e,e+t)}release(){this.keep||(this.#r=null)}},vW={1:1,2:1,3:2,4:2,5:4,6:4,7:4,9:8,12:8,13:8},yW=1<<17,bW=`MATLAB objects (timeseries, SimulationOutput) were skipped: save them as 'Structure with time' or as structs.`,xW=512<<20}));function CW(e,t){let n={channels:[],strings:new Map,scalars:new Map,notes:[]},r=TU();r.enter(e);let i=t=>kU(e,t),a=(e,t,n)=>{let r=null;return(a,o)=>((r?.s!==a||r.e!==o)&&(r={s:a,e:o,v:AU(t?i(e).slice([[0,n],[a,o]]):i(e).slice([[a,o],[0,n]]))}),r.v)},o=(e,s,c,l)=>{for(let u of e.keys()){if(!r.count())return;if(u.startsWith(`#`))continue;let d=e.get(u);if(!d)continue;let f=`${s}/${u}`,p=c?`${c}.${u}`:u,m=d.attrs,h=jU(m,`MATLAB_class`);if(m.MATLAB_empty)continue;if(NU(d)){h===`struct`&&l<16&&r.enter(d)&&o(d,f,p,l+1);continue}if(!FU(d))continue;let g=d.shape??[];if(h===`char`){if(g.reduce((e,t)=>e*t,1)>wW)continue;let e=AU(d.slice(g.map(e=>[0,e])));n.strings.set(p,new TextDecoder(`utf-16le`).decode(Uint16Array.from(e)))}else if(TW.has(h)&&g.length===2&&EU(d,g,t,!!d.metadata.chunks))n.notes.push(`${p}: larger than the file can hold (never written, or damaged); skipped.`);else if(TW.has(h)&&g.length===2){let[e,t]=g;if(e*t===1){n.scalars.set(p,AU(i(f).slice([[0,1],[0,1]]))[0]);continue}if(e===1||t===1){let r=e*t;n.channels.push({name:p,length:r,read:async(t,n)=>AU(e===1?i(f).slice([[0,1],[t,n]]):i(f).slice([[t,n],[0,1]]))})}else if(t>=e){let r=a(f,!0,e);for(let i=0;i<e;i++)n.channels.push({name:`${p}[${i+1}]`,length:t,read:async(e,t)=>r(e,t).slice(i*(t-e),(i+1)*(t-e))})}else{let r=a(f,!1,t);for(let i=0;i<t;i++)n.channels.push({name:`${p}[${i+1}]`,length:e,read:async(e,n)=>{let a=r(e,n),o=new Float64Array(n-e);for(let e=0;e<o.length;e++)o[e]=a[e*t+i];return o}})}}else h===`cell`?n.notes.push(`${p}: cell arrays are skipped.`):h&&n.notes.push(`${p}: MATLAB class ${h} is skipped.`)}};o(e,``,``,0);let s=r.note();return s&&n.notes.push(s),n}var wW,TW,EW=c((()=>{VU(),wW=65536,TW=new Set([`double`,`single`,`int8`,`uint8`,`int16`,`uint16`,`int32`,`uint32`,`int64`,`uint64`,`logical`])}));async function*DW(e,t){let n=e.plan.state,r=n.groups[t],i=Xz(e,t).map(e=>r.channels[e]),a=r.channels[0].length,o=OW(i.length+1);try{for(let n=0;n<a;n+=o){e.signal?.throwIfAborted();let s=Math.min(a,n+o),c=null;if(r.time){c=await r.time.read(n,s);for(let e=0;e<c.length;e++)c[e]-=r.origin}let l=[];for(let e of i)l.push(await e.read(n,s));yield{group:t,time:c,start:n,length:s-n,columns:l}}}finally{for(let e of n.sources)e.release()}}var OW,kW,AW=c((()=>{AR(),VU(),Zz(),BR(),uW(),SW(),EW(),OW=e=>Math.max(4096,Math.min(1<<18,Math.floor((16<<20)/(8*Math.max(1,e))))),kW={...zR,async plan(e,t){let n=wR(await t.read(0,20),`MATLAB 7.3`),r,i=[];if(n)r=CW((await OU(e.main)).root,e.main.size);else{let e=await hW(t);i=e.sources,r=e}let a=rW(r.channels,r.strings,r.scalars).filter(e=>e.channels.length>0);await aW(a);let o=iW(a);if(o.length===0)throw Error(`This MAT file has no numeric vectors or matrices to plot.`);let s=o.flatMap((e,t)=>e.time.kind===`index`?[]:[t]),c=o.length>1&&s.length<o.length,l=Object.fromEntries(r.strings);for(let[e,t]of r.scalars)l[e]=String(t);return{format:n?`MAT 7.3`:`MAT 5`,startTime:null,groups:o,meta:l,events:[],notes:r.notes,pick:c,defaultGroups:c&&s.length?s:void 0,state:{groups:a,sources:i}}},async*stream(e){for(let t of e.selection)yield*DW(e,t.group)},streamGroup:(e,t)=>DW(e,t)}}));function jW(e,t){let n=/^\s*(\d{1,2})\/(\d{1,2})\/(\d{2,4})\s*,\s*(\d{1,2}):(\d{2}):(\d{2})(?:\.(\d+))?/.exec(e??``);if(!n)return[null,0,!1];let[r,i]=t===1991?[n[2],n[1]]:[n[1],n[2]],a=n[3].length===2?2e3+Number(n[3]):Number(n[3]),o=Number(`${n[6]}.${n[7]??`0`}`);return[`${a}-${i.padStart(2,`0`)}-${r.padStart(2,`0`)}T${n[4].padStart(2,`0`)}:${n[5]}:${o.toFixed(3).padStart(6,`0`)}`,Date.UTC(a,Number(i)-1,Number(r),Number(n[4]),Number(n[5]))/1e3+o,(n[7]??``).length>6]}function MW(e){let t=e.split(/\r?\n/).map(e=>e.trim()),[n,,r]=t[0].split(`,`),i=Number(r)||1991,a=/(\d+)A\s*,\s*(\d+)D/i.exec(t[1]??``);if(!a)throw Error(`This COMTRADE .cfg is damaged (second line).`);let o=Number(a[1]),s=Number(a[2]);if(o+s>t.length)throw Error(`This COMTRADE .cfg is damaged (more channels than lines).`);let c=2,l=[];for(let e=0;e<o;e++,c++){let e=(t[c]??``).split(`,`);l.push({name:(e[1]??``).trim(),unit:(e[4]??``).trim(),a:Number(e[5]),b:Number(e[6]??0)||0})}let u=[];for(let e=0;e<s;e++,c++)u.push(((t[c]??``).split(`,`)[1]??``).trim());c++;let d=Number(t[c++]);if(!(Number.isInteger(d)&&d>=0&&d<=t.length-c))throw Error(`This COMTRADE .cfg is damaged (sample rates).`);let f=[];for(let e=0;e<Math.max(1,d);e++,c++){let[e,n]=(t[c]??``).split(`,`).map(Number);f.push([d===0?0:e,n])}let[p,m,h]=jW(t[c++],i),[g,_,v]=jW(t[c++],i),y=(t[c++]||`ASCII`).toUpperCase(),b=Number(t[c++])||1;return{station:n.trim(),rev:i,analog:l,digital:u,rates:f,start:p,trigger:g,startSec:m,triggerSec:_,ft:y,timemult:b,timebase:h||v?1e-9:1e-6}}async function NW(e){let t=OR(await e.read(0,Math.min(e.size,1<<20))),n=t.search(/---\s*file type:\s*CFG\s*---\r?\n/i),r=/---\s*file type:\s*DAT\s+(ASCII|BINARY32|BINARY|FLOAT32)(?:\s*:\s*(\d+))?\s*---\r?\n/i.exec(t);if(n<0||!r)throw Error(`This COMTRADE .cff is damaged (no CFG or DAT section in its first megabyte).`);let i=t.indexOf(`
|
|
78
|
+
`,HR=e=>[0,512,1024,2048].some(t=>wR(e,VR,t)),UR={id:`hdf5`,label:`HDF5`,extensions:[`.h5`,`.hdf5`,`.hdf`,`.he5`,`.nc`],sniff:HR}})),GR,KR=c((()=>{AR(),GR={id:`comtrade`,label:`COMTRADE (IEEE C37.111)`,extensions:[`.cfg`,`.cff`],companions:[{ext:`.dat`}],sniff:e=>{let t=OR(e.subarray(0,512));if(/^---\s*file type:\s*CFG/i.test(t))return!0;let n=t.split(/\r?\n/);return n.length>2&&/^\s*\d+\s*,\s*\d+A\s*,\s*\d+D\s*$/i.test(n[1])}}}));MR(),PR(),IR(),RR(),BR(),WR(),KR();var qR=4096,JR=[`.dat`,`.txt`,`.csv`,`.tsv`],YR=[jR,NR,FR,LR,zR,UR,GR],XR=e=>{let t=e.lastIndexOf(`.`);return t<=0?``:e.slice(t).toLowerCase()},ZR=e=>{let t=e.lastIndexOf(`.`);return(t<=0?e:e.slice(0,t)).toLowerCase()};async function QR(e){let t=new Uint8Array(await e.slice(0,qR).arrayBuffer()),n=XR(e.name),r=YR.filter(e=>e.extensions.includes(n));for(let n of[...r,...YR.filter(e=>!r.includes(e))])if(n.sniff(t,e.name))return n;return null}async function $R(e){return new Uint8Array(await e.slice(0,qR).arrayBuffer()).includes(0)}async function ez(e){let t=await Promise.all(e.map(QR)),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]&&XR(e.name)===n.ext),o=a.find(e=>ZR(e.name)===ZR(i.main.name))??(n.anyName&&a.length===1?a[0]:void 0);o&&(i.companions.push(o),r.add(o))}let i=new Set(YR.flatMap(e=>(e.companions??[]).map(e=>e.ext))),a=[];for(let t of e){if(r.has(t))continue;let e=XR(t.name);e===`.dat`&&await $R(t)?a.push({file:t.name,error:Error(`This COMTRADE .dat needs its .cfg file — drop both together.`)}):JR.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 tz=[...new Set([...JR,...YR.flatMap(e=>[...e.extensions,...(e.companions??[]).map(e=>e.ext)])])];function nz(e){let t=0;for(let n=0;n<e.length;n++)e[n]!==e[n]&&t++;if(t===0)return ZM(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 ZM(TM({type:new Ak,data:e,nullBitmap:n,length:e.length,nullCount:t}))}var rz=122880,iz=class{#e;#t;#n;#r=!1;#i=[];#a=0;#o;rows=0;constructor(e,t,n,r=rz){this.#e=e,this.#t=t,this.#n=new fN(n.map(e=>new pN(e.name,e.text?new Nk:new Ak,!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?nz(i.subarray(0,t)):sF(i.slice(0,t),new Nk)).data[0]});this.#i.push(new gF(this.#n,TM({type:new Wk(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 mF(this.#n,this.#i);this.#i=[],this.#a=0,await this.#e.insertArrowTable(e,{name:this.#t,create:!this.#r}),this.#r=!0}};function az(e){let t=e.notes;for(let n of e.groups){n.name=hz(String(n.name),uz);for(let e of n.channels)e.name=hz(String(e.name),uz),e.unit=hz(String(e.unit??``),dz);Number.isInteger(n.samples)&&n.samples>=-1||(n.samples=-1),n.rateHz===null||Number.isFinite(n.rateHz)&&n.rateHz>0||(n.rateHz=null),n.time.kind===`rate`&&!(Number.isFinite(n.time.rate)&&n.time.rate>0&&Number.isFinite(n.time.start))&&(t.push(`${n.name}: its sample rate in the file is not usable; samples are numbered instead.`),n.time={kind:`index`},n.rateHz=null)}t.length>pz&&t.splice(pz,t.length-pz,`${t.length-pz} more notes.`),e.notes=t.map(e=>hz(String(e),fz));let n={};for(let[t,r]of Object.entries(e.meta).slice(0,mz))n[hz(t,uz)]=hz(String(r),fz);return e.meta=n,e.events=e.events.filter(e=>Number.isFinite(e.time)).map(e=>({time:e.time,text:hz(String(e.text),fz)})),e}function oz(e){return e instanceof Error&&(e.constructor===Error||e.name===`KymoscopeError`||e.name===`AbortError`)?e:Error(sz)}var sz,cz,lz,uz,dz,fz,pz,mz,hz,gz=c((()=>{sz=`This file couldn't be read (it may be damaged).`,cz=1032,lz=e=>e*cz+1024,uz=256,dz=64,fz=1e3,pz=100,mz=200,hz=(e,t)=>e.length>t?`${e.slice(0,t-1)}…`:e}));gz();var _z=`This file's groups do not interleave in time: reading them together would hold too much in memory. Choose fewer groups, or split them.`,vz=e=>e.length*(1+e.columns.length);function yz(e){let t=e[Symbol.asyncIterator]();return{pull:async()=>{let e=await t.next();return e.done?null:e.value}}}function bz(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-=vz(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+=vz(o.value))>128e6))throw Error(_z)}};return n.map((e,t)=>({pull:()=>a(t)}))}function xz(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 Sz=new Int32Array,Cz={t:new Float64Array,cols:[],from:0};function wz(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 Tz=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=Ez(xz(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(_z)}};function Ez(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 Dz(e,t){let n=e.length,r=e.map(e=>e.t),i=Int32Array.from(e,e=>e.from),a=Int32Array.from(e,e=>wz(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 Oz(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 kz(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];Oz(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}Oz(e,d,u,p,l-1,c[p]),o=c[l-1],t=d[u+l-1]}e.fill(t,o,e.length)}function Az(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 jz(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):Sz}function Mz(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=wz(i,e,r.from,i.length),o=new Int32Array(a-r.from);if(c.push(jz(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 Az(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),kz(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 Nz(e,t,n,r,i,a=!1){let o=e.map((e,r)=>new Tz(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=Dz(l.map(e=>e.pending[0]??Cz),e),n=[t];for(let e=0;e<o.length;e++)n.push(...Mz(o[e],t,c[e],u&&c[e],a));d+=t.length,t.length&&await r({length:t.length,columns:n})}return d}var Pz=class{#e;#t;#n;#r=0;constructor(e,t){let n=Math.max(1024,t);this.#e=e.map(e=>e.name),this.#t=e.map(()=>new Float64Array(n)),this.#n=e.map(()=>null)}append(e){let t=this.#r,n=t+e.length;if(n>this.#t[0].length){let e=Math.max(n,Math.ceil(this.#t[0].length*1.5));this.#t=this.#t.map(n=>{let r=new Float64Array(e);return r.set(n.subarray(0,t)),r})}e.columns.forEach((n,r)=>{let i=this.#t[r];if(n instanceof Float64Array){i.set(n.subarray(0,e.length),t);return}let a=this.#n[r];for(let o=0;o<e.length;o++){i[t+o]=NaN;let e=n[o];e!=null&&((a??=this.#n[r]=[])[t+o]=e)}}),this.#r=n}table(){let e=this.#r,t=this.#t.map(t=>t.length-e>t.length/100?t.slice(0,e):t.subarray(0,e));return{keys:this.#e,length:e,values:t,text:this.#n}}};function Fz(e,t=[`Time`]){let n=new Set(t.map(e=>e.toLowerCase())),r=new Map;return e.map(e=>{let t=e.trim()||`Channel`,i=t.toLowerCase(),a=t,o=r.get(i)??2;if(n.has(i)){for(;n.has(`${i} (${o})`);)o++;a=`${t} (${o++})`}return r.set(i,o),n.add(a.toLowerCase()),a})}var Iz=c((()=>{}));gz(),Iz();async function Lz(e,t,n){return az(await e.plan(t,n))}var Rz=(e,t,n)=>Math.max(0,Math.min(e,Math.max(1<<20,n),Math.floor(1e8/t)));function zz(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=Fz(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 Bz(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 Vz(e,t,n){let r=Bz(e,t);return r<0?Math.ceil(n/4):r*(1+t.reduce((e,t)=>e+t.channels.length,0))}async function Hz(e,t,n,r,i,a,o={}){let s=zz(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=>yz(d(e.streamGroup({...f,selection:[t]},t.group)))):bz(d(e.stream(f)),new Map(i.map((e,t)=>[e.group,t]))),m=Bz(n,i),h=a===`memory`?new Pz(s,Rz(m,s.length,r.size)):null,g=0,_=await Nz(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 Uz,Wz,Gz,Kz,qz=c((()=>{Uz=1<<20,Wz=64,Gz=16<<20,Kz=class{size;bytesRead=0;#e;#t=new Map;constructor(e){this.#e=e,this.size=e.size}async read(e,t){let n=Math.min(this.size,e+t);if(n<=e)return new Uint8Array;if(n-e>Uz)return this.slice(e,n-e);let r=Math.floor(e/Uz),i=Math.floor((n-1)/Uz),a=await this.#n(r);if(r===i)return a.subarray(e-r*Uz,n-r*Uz);let o=new Uint8Array(n-e),s=a.subarray(e-r*Uz);return o.set(s),o.set((await this.#n(i)).subarray(0,n-i*Uz),s.length),o}async slice(e,t){let n=Math.min(this.size,e+t);if(n<=e)return new Uint8Array;let r=new Uint8Array(await this.#e.slice(e,n).arrayBuffer());return this.bytesRead+=r.length,r}async*windows(e,t,n=Gz){let r=Math.min(this.size,e+t);for(let t=e;t<r;t+=n)yield{offset:t,bytes:await this.slice(t,Math.min(n,r-t))}}async#n(e){let t=this.#t.get(e);if(t)return this.#t.delete(e),this.#t.set(e,t),t;let n=await this.slice(e*Uz,Uz);return this.#t.size>=Wz&&this.#t.delete(this.#t.keys().next().value),this.#t.set(e,n),n}}}));qz();var Jz=``+new URL(`assets/importer.worker-BTbPiEHd.js`,__kymoscopeScriptUrl).href,Yz=``+new URL(`assets/h5wasmModule-BCQWU2Gw.js`,__kymoscopeScriptUrl).href;function Xz(e,t){return e.selection.find(e=>e.group===t)?.channels??[]}var Zz=c((()=>{}));function Qz(e){if(e.length>$z)return null;let t=e.match(/\d+\.?\d*(?:[eE][+-]?\d+)?|\.\d+(?:[eE][+-]?\d+)?|[A-Za-z_]\w*|\*\*|[-+*/^(),]|\S/g)??[],n=0,r=()=>t[n],i=()=>{throw Error(`formula`)},a=e=>{t[n++]!==e&&i()},o=()=>{let e=s();for(;r()===`+`||r()===`-`;){let r=t[n++],i=e,a=s();e=r===`+`?e=>i(e)+a(e):e=>i(e)-a(e)}return e},s=()=>{let e=c();for(;r()===`*`||r()===`/`;){let r=t[n++],i=e,a=c();e=r===`*`?e=>i(e)*a(e):e=>i(e)/a(e)}return e},c=()=>{if(r()===`-`){n++;let e=c();return t=>-e(t)}return r()===`+`?(n++,c()):l()},l=()=>{let e=u();if(r()===`^`||r()===`**`){n++;let t=c();return n=>e(n)**t(n)}return e},u=()=>{let e=t[n++];if(e===void 0&&i(),e===`(`){let e=o();return a(`)`),e}if(/^[\d.]/.test(e)){let t=Number(e);return Number.isFinite(t)||i(),()=>t}if(e===`X`||e===`x`||e===`X1`)return e=>e;if(Object.hasOwn(eB,e)){let t=eB[e];a(`(`);let i=[o()];for(;r()===`,`;)n++,i.push(o());return a(`)`),i.length===1?e=>t(i[0](e)):e=>t(...i.map(t=>t(e)))}return i()};try{let e=o();return n===t.length?e:null}catch{return null}}var $z,eB,tB=c((()=>{$z=4096,eB={sin:Math.sin,cos:Math.cos,tan:Math.tan,asin:Math.asin,acos:Math.acos,atan:Math.atan,sinh:Math.sinh,cosh:Math.cosh,tanh:Math.tanh,exp:Math.exp,ln:Math.log,log:Math.log,log10:Math.log10,sqrt:Math.sqrt,abs:Math.abs,pow:Math.pow,min:Math.min,max:Math.max}}));function nB(e,t){let{keys:n,vals:r}=e,i=n.length;if(i===0)return t;if(t<=n[0])return r[0];if(t>=n[i-1])return r[i-1];let a=0,o=i-1;for(;o-a>1;){let e=a+o>>1;n[e]<=t?a=e:o=e}return e.interp?r[a]+(r[o]-r[a])*(t-n[a])/(n[o]-n[a]):t-n[a]<=n[o]-t?r[a]:r[o]}function rB(e,t){let n=t.length;switch(e.k){case`lin`:{let{a:r,b:i}=e;if(r===1&&i===0)return;for(let e=0;e<n;e++)t[e]=r*t[e]+i;return}case`rat`:{let[r,i,a,o,s,c]=e.p;for(let e=0;e<n;e++){let n=t[e];t[e]=(r*n*n+i*n+a)/(o*n*n+s*n+c)}return}case`poly`:{let[r,i,a,o,s,c]=e.p;for(let e=0;e<n;e++){let n=t[e]-s-c;t[e]=(i-o*n)/(a*n-r)}return}case`alg`:{let r=e.f;for(let e=0;e<n;e++)t[e]=r(t[e]);return}case`tab`:for(let r=0;r<n;r++)t[r]=nB(e,t[r]);return;case`rtv`:for(let r=0;r<n;r++){let n=t[r],i=e.def;for(let t=0;t<e.lo.length;t++)if(n>=e.lo[t]&&n<=e.hi[t]){i=e.vals[t];break}t[r]=i}return;default:return}}function iB(e,t){let n=Float64Array.of(t);return rB(e,n),n[0]}function aB(e,t){let n=Array(t.length),r=e.ranges.every(e=>e.lo===e.hi)?new Map(e.ranges.map(e=>[e.lo,e.to])):null;for(let i=0;i<t.length;i++){let a=t[i];if(a!==a){n[i]=null;continue}let o=e.def;if(r){let e=r.get(a);e!==void 0&&(o=e)}else for(let t of e.ranges)if(a>=t.lo&&(e.int||t.lo===t.hi?a<=t.hi:a<t.hi)){o=t.to;break}n[i]=sB(o,a)}return n}var oB,sB,cB=c((()=>{oB={k:`id`},sB=(e,t)=>e===null||typeof e==`string`?e:String(iB(e,t))}));function lB(e,t){let n=(e,t)=>({type:e,bigEndian:t,encoding:`latin1`});switch(e){case 0:return n(`uint`,!t);case 1:return n(`int`,!t);case 2:case 3:return n(`float`,!t);case 7:return n(`string`,!1);case 8:return n(`bytes`,!1);case 9:return n(`uint`,!0);case 10:return n(`int`,!0);case 11:case 12:return n(`float`,!0);case 13:return n(`uint`,!1);case 14:return n(`int`,!1);case 15:case 16:return n(`float`,!1);default:return null}}async function uB(e,t,n){let r=TR(t).getUint16(24,!0)===0,i=async t=>{let n=TR(await e.read(t,4)).getUint16(2,r),i=await e.read(t,n);return{id:OR(i.subarray(0,2)),v:TR(i),b:i,size:n}},a=(e,t)=>e.getUint32(t,r),o=(e,t)=>e.getUint16(t,r),s=(e,t)=>e.getFloat64(t,r),c=async e=>e?CR((await i(e)).b.subarray(4),!0):``,l=[],u=new Set,d=e=>{if(u.has(e))throw Error(`This MDF file is damaged (its blocks link in a loop).`);u.add(e)},f=async(e,t)=>{if(!e)return{conv:oB,unit:``};let{v:n,b:r}=await i(e),l=CR(r.subarray(22,42),!0),u=o(n,42),d=o(n,44),f=e=>s(n,46+8*e);switch(u){case 0:return{conv:{k:`lin`,a:f(1),b:f(0)},unit:l};case 1:case 2:{let e=new Float64Array(d),t=new Float64Array(d);for(let n=0;n<d;n++)e[n]=f(2*n),t[n]=f(2*n+1);return{conv:{k:`tab`,keys:e,vals:t,interp:u===1},unit:l}}case 6:return{conv:{k:`poly`,p:[0,1,2,3,4,5].map(f)},unit:l};case 9:return{conv:{k:`rat`,p:[0,1,2,3,4,5].map(f)},unit:l};case 10:{let e=CR(r.subarray(46,302),!0),t=Qz(e);return{conv:t?{k:`alg`,f:t}:{k:`unsupported`,what:`the formula "${e}"`},unit:l}}case 11:return{conv:{k:`text`,ranges:Array.from({length:d},(e,t)=>{let i=46+40*t,a=s(n,i);return{lo:a,hi:a,to:CR(r.subarray(i+8,i+40),!0)}}),def:null,int:t},unit:l};case 12:{let e=await Promise.all(Array.from({length:d},async(e,t)=>{let r=46+20*t;return{lo:s(n,r),hi:s(n,r+8),to:await c(a(n,r+16))}}));return{conv:{k:`text`,ranges:e.slice(1),def:e[0]?.to??null,int:t},unit:l}}case 65535:return{conv:oB,unit:l};default:return{conv:{k:`unsupported`,what:`MDF3 conversion type ${u}`},unit:l}}},p=await i(64),m=null;if(p.size>=172&&(a(p.v,164)||a(p.v,168))){let e=a(p.v,168)*4294967296+a(p.v,164);m=new Date(e/1e6).toISOString()}else{let e=OR(p.b.subarray(18,28)),t=OR(p.b.subarray(28,36));/^\d\d:\d\d:\d{4}$/.test(e)&&(m=`${e.slice(6)}-${e.slice(3,5)}-${e.slice(0,2)}T${t}`)}let h=[],g=0;for(let e=a(p.v,4),t=0;e;t++){d(e);let n=await i(e),s=o(n.v,22),u=[];for(let e=a(n.v,8);e;){d(e);let n=await i(e),p=[],m=null;for(let e=a(n.v,8);e;){d(e);let t=await i(e),n=CR(t.b.subarray(26,58),!0),s=(t.size>=222?await c(a(t.v,218)):``)||n,u=lB(o(t.v,190),r),h=o(t.v,186)+(t.size>=228?8*o(t.v,226):0);if(!u)l.push(`${s}: MDF3 data type ${o(t.v,190)} is not supported; skipped.`);else{let{conv:e,unit:n}=await f(a(t.v,8),u.type!==`float`),r={name:s,unit:n,kind:o(t.v,24)===1?`master`:`value`,...u,conv:e,sd:null,sdRecordId:null,byteOffset:h>>3,bitOffset:h&7,bitCount:o(t.v,188),invalBit:null,allInvalid:!1};r.kind===`master`&&!m?m=r:r.kind===`value`&&p.push(r)}e=a(t.v,4)}g++,u.push({name:await c(a(n.v,12))||`Group ${g}`,dg:t,recordId:o(n.v,16),recordIdSize:+(s>0),idTrailer:+(s===2),dataBytes:o(n.v,20),invalBytes:0,cycles:a(n.v,22),vlsdCg:!1,sorted:!0,master:m,channels:p,stream:[],busType:0,busEvent:!1}),e=a(n.v,4)}let p=u.reduce((e,t)=>e+t.cycles*(t.recordIdSize+t.dataBytes+t.idTrailer),0),m=[{offset:a(n.v,16),length:p,zip:null}];for(let e of u)e.stream=m,e.sorted=u.length===1,h.push(e);e=a(n.v,4)}return{version:`MDF ${n}`,startTime:m,groups:h,notes:l,meta:{}}}var dB=c((()=>{AR(),tB(),cB()}));function fB(e,t){if(e.seen.has(t))throw Error(wB);e.seen.add(t)}async function pB(e,t){let n=await e.read(t,24);if(n.length<24)throw Error(`This MF4 is damaged (bad block at byte ${t}).`);let r=TR(n),i=OR(n.subarray(0,4)),a=xR(r,8),o=xR(r,16);if(!i.startsWith(`##`)||a<24+8*o||a>1<<26)throw Error(`This MF4 is damaged (bad block at byte ${t}).`);let s=await e.read(t,a);if(s.length<a)throw Error(`This MF4 is damaged (the block at byte ${t} runs past the end of the file).`);let c=TR(s),l=[];for(let e=0;e<o;e++)l.push(xR(c,24+8*e));let u=s.subarray(24+8*o);return{id:i,links:l,data:TR(u),bytes:u}}function mB(e){let t=e.indexOf(`<TX>`),n=t<0?-1:e.indexOf(`</TX>`,t+4);return(n>=0?e.slice(t+4,n):e.replace(/<[^<>]*>/g,``)).replace(/&(lt|gt|amp|quot|apos);/g,(e,t)=>TB[t]).trim()}function hB(e,t){if(!t)return Promise.resolve(``);let n=e.texts.get(t);return n||(n=pB(e.io,t).then(e=>{let t=CR(e.bytes);return e.id===`##MD`?mB(t):t}),e.texts.set(t,n)),n}async function gB(e,t,n=0){if(!t)return[];let r=e.io,i=await r.read(t,24),a=OR(i.subarray(0,4)),o=i.length<24?0:xR(TR(i),8);switch(a){case`##DT`:case`##SD`:case`##RD`:return[{offset:t+24,length:o-24,zip:null}];case`##DZ`:{let e=TR(await r.read(t+24,24));if(e.byteLength<24)throw Error(`This MF4 is damaged (bad block at byte ${t}).`);let n=e.getUint8(2);if(n===2||n===3)throw Error(`This MF4 uses zstd compression, which isn't supported yet.`);if(n===4||n===5)throw Error(`This MF4 uses LZ4 compression, which isn't supported yet.`);if(n>5)throw Error(`This MF4 is damaged (unknown compression type ${n}).`);let i=e.getUint32(4,!0),a=xR(e,8),o=xR(e,16);if(a>lz(o)||n===1&&i===0)throw Error(`This MF4 is damaged (bad compressed block at byte ${t}).`);if(n===1&&a>268435456)throw Error(`This MF4 has a compressed block over 256 MB, which Kymoscope cannot read.`);return[{offset:t+48,length:o,zip:{type:n,param:i,orgLength:a}}]}case`##DL`:{if(n>1)throw Error(`This MF4 is damaged (unexpected ${a} block in its data).`);let i=[];for(let n=t;n;){fB(e,n);let t=await pB(r,n);for(let n of t.links.slice(1))i.push(...await gB(e,n,2));n=t.links[0]}return i}case`##HL`:if(n>0)throw Error(`This MF4 is damaged (unexpected ${a} block in its data).`);return fB(e,t),gB(e,(await pB(r,t)).links[0],1);case`##DV`:case`##DI`:throw Error(`This MF4 uses column-oriented storage (MDF 4.2 DV/DI blocks), which Kymoscope cannot read yet.`);default:throw Error(`This MF4 is damaged (unexpected ${a} block in its data).`)}}async function _B(e,t,n){return t?OR(await e.io.read(t,4))===`##CC`?vB(e,t,n+1):hB(e,t):null}async function vB(e,t,n=0){if(!t||n>4||e.busy.has(t))return oB;let r=e.convs.get(t);if(r)return r;e.busy.add(t);try{let r=await yB(e,t,n);return e.convs.set(t,r),r}finally{e.busy.delete(t)}}async function yB(e,t,n){let r=await pB(e.io,t),i=r.data,a=i.getUint8(0),o=i.getUint16(4,!0),s=i.getUint16(6,!0),c=new Float64Array(s);for(let e=0;e<s;e++)c[e]=i.getFloat64(24+8*e,!0);let l=r.links.slice(4,4+o),u=()=>Promise.all(l.map(t=>_B(e,t,n)));switch(a){case 0:return oB;case 1:return{k:`lin`,b:c[0],a:c[1]};case 2:return{k:`rat`,p:[...c]};case 3:{let t=await hB(e,l[0]),n=Qz(t);return n?{k:`alg`,f:n}:{k:`unsupported`,what:`the formula "${t}"`}}case 4:case 5:{let e=s>>1,t=new Float64Array(e),n=new Float64Array(e);for(let r=0;r<e;r++)t[r]=c[2*r],n[r]=c[2*r+1];return{k:`tab`,keys:t,vals:n,interp:a===4}}case 6:{let e=Math.max(0,Math.floor((s-1)/3)),t=new Float64Array(e),n=new Float64Array(e),r=new Float64Array(e);for(let i=0;i<e;i++)t[i]=c[3*i],n[i]=c[3*i+1],r[i]=c[3*i+2];return{k:`rtv`,lo:t,hi:n,vals:r,def:c[s-1]}}case 7:{let e=await u();return{k:`text`,ranges:[...c].map((t,n)=>({lo:t,hi:t,to:e[n]??null})),def:e[s]??null,int:!0}}case 8:{let e=await u(),t=s>>1;return{k:`text`,ranges:Array.from({length:t},(t,n)=>({lo:c[2*n],hi:c[2*n+1],to:e[n]??null})),def:e[t]??null,int:!0}}default:return{k:`unsupported`,what:`conversion type ${a}`}}}async function bB(e,t){let{io:n,notes:r}=e,i=t.data,a=i.getUint8(0),o=i.getUint8(1),s=i.getUint8(2),c=await hB(e,t.links[2]),l=EB[s];if(!l)return r.push(`${c}: data type ${s} is not supported; the channel was skipped.`),null;let u;if(a===2||a===3)if(o===1)u=a===2?`master`:`vmaster`;else{if(r.push(`The master channel ${c} is not time (sync type ${o}): samples are numbered instead.`),a===3)return null;u=`value`}else if(a===1)u=`vlsd`;else if(a===0||a===4)u=`value`;else return r.push(`${c}: channel type ${a} is not supported; skipped.`),null;let d=await vB(e,t.links[4]),f=d.k===`text`?{...d,int:l.type!==`float`}:d,p=await hB(e,t.links[6]);!p&&t.links[4]&&(p=await hB(e,(await pB(n,t.links[4])).links[1]));let m=null,h=null;u===`vlsd`&&t.links[5]&&(OR(await n.read(t.links[5],4))===`##CG`?h=xR((await pB(n,t.links[5])).data,0):m=await gB(e,t.links[5]));let g=i.getUint32(12,!0);return{name:c,unit:p,kind:u,...l,conv:f,sd:m,sdRecordId:h,byteOffset:i.getUint32(4,!0),bitOffset:i.getUint8(3),bitCount:i.getUint32(8,!0),invalBit:g&2?i.getUint32(16,!0):null,allInvalid:(g&1)!=0}}async function xB(e,t,n,r=0){let{io:i,notes:a}=e;for(let o=t;o;){fB(e,o);let t=await pB(i,o),s=t.links[1];s&&r<4&&(OR(await i.read(s,4))===`##CN`?await xB(e,s,n,r+1):a.push(`${await hB(e,t.links[2])}: array channels (CA) are not supported yet; skipped.`));let c=await bB(e,t);c&&n.push(c),o=t.links[0]}}async function SB(e,t,n,r){let i=t.data,a=i.getUint16(16,!0),o=0;t.links[3]&&(o=(await pB(e.io,t.links[3])).data.getUint8(1));let s={name:await hB(e,t.links[2]),dg:n,recordId:xR(i,0),recordIdSize:r,idTrailer:0,dataBytes:i.getUint32(24,!0),invalBytes:i.getUint32(28,!0),cycles:xR(i,8),vlsdCg:(a&1)!=0,sorted:!0,master:null,channels:[],stream:[],busType:o,busEvent:(a&2)!=0};if(s.vlsdCg)return s;let c=[];await xB(e,t.links[1],c);for(let e of c)e.kind===`master`||e.kind===`vmaster`?s.master||=e:s.channels.push(e);return s}async function CB(e,t){let n=await pB(e,64);if(n.id!==`##HD`)throw Error(`This MF4 is damaged (no header block).`);let r=xR(n.data,0),i=(n.data.getUint8(12)&1)!=0,a=new Date(r/1e6).toISOString(),o=r>0?i?a.slice(0,-1):a:null,s={io:e,notes:[],seen:new Set,texts:new Map,convs:new Map,busy:new Set},c=[],l=0;for(let t=n.links[0],r=0;t;r++){fB(s,t);let n=await pB(e,t),i=n.data.getUint8(0),a=[];for(let t=n.links[1];t;){fB(s,t);let n=await pB(e,t),o=await SB(s,n,r,i);o.vlsdCg||(l++,o.name||=`Group ${l}`),a.push(o),t=n.links[0]}let o=await gB(s,n.links[2]),u=a.length===1;for(let e of a)e.stream=o,e.sorted=u,c.push(e);t=n.links[0]}return{version:`MF4 ${t}`,startTime:o,groups:c,notes:s.notes,meta:{}}}var wB,TB,EB,DB=c((()=>{AR(),tB(),gz(),cB(),wB=`This MF4 is damaged (its blocks link in a loop).`,TB={lt:`<`,gt:`>`,amp:`&`,quot:`"`,apos:`'`},EB={0:{type:`uint`,bigEndian:!1,encoding:`latin1`},1:{type:`uint`,bigEndian:!0,encoding:`latin1`},2:{type:`int`,bigEndian:!1,encoding:`latin1`},3:{type:`int`,bigEndian:!0,encoding:`latin1`},4:{type:`float`,bigEndian:!1,encoding:`latin1`},5:{type:`float`,bigEndian:!0,encoding:`latin1`},6:{type:`string`,bigEndian:!1,encoding:`latin1`},7:{type:`string`,bigEndian:!1,encoding:`utf-8`},8:{type:`string`,bigEndian:!1,encoding:`utf-16le`},9:{type:`string`,bigEndian:!0,encoding:`utf-16be`},10:{type:`bytes`,bigEndian:!1,encoding:`latin1`}}}));function OB(e){let t=e&32768?-1:1,n=e>>10&31,r=e&1023;return n===0?t*2**-14*(r/1024):n===31?r?NaN:t*(1/0):t*2**(n-15)*(1+r/1024)}function kB(e,t,n,r,i,a,o=0){let s=TR(t),c=!e.bigEndian,l=i+e.byteOffset,u=e.bitCount;if(e.bitOffset===0)if(e.type===`float`){if(u===64){for(let e=0;e<n;e++,l+=r)a[o+e]=s.getFloat64(l,c);return}if(u===32){for(let e=0;e<n;e++,l+=r)a[o+e]=s.getFloat32(l,c);return}if(u===16){for(let e=0;e<n;e++,l+=r)a[o+e]=OB(s.getUint16(l,c));return}}else if(e.type===`int`){if(u===8){for(let e=0;e<n;e++,l+=r)a[o+e]=s.getInt8(l);return}if(u===16){for(let e=0;e<n;e++,l+=r)a[o+e]=s.getInt16(l,c);return}if(u===32){for(let e=0;e<n;e++,l+=r)a[o+e]=s.getInt32(l,c);return}if(u===64){for(let e=0;e<n;e++,l+=r)a[o+e]=s.getInt32(l+(c?4:0),c)*4294967296+s.getUint32(l+(c?0:4),c);return}}else{if(u===8){for(let e=0;e<n;e++,l+=r)a[o+e]=t[l];return}if(u===16){for(let e=0;e<n;e++,l+=r)a[o+e]=s.getUint16(l,c);return}if(u===32){for(let e=0;e<n;e++,l+=r)a[o+e]=s.getUint32(l,c);return}if(u===64){for(let e=0;e<n;e++,l+=r)a[o+e]=s.getUint32(l+(c?4:0),c)*4294967296+s.getUint32(l+(c?0:4),c);return}}let d=e.bitOffset+u+7>>3,f=2**e.bitOffset,p=2**u,m=p/2,h=e.type===`int`;for(let e=0;e<n;e++,l+=r){let n=0;if(c)for(let e=d-1;e>=0;e--)n=n*256+t[l+e];else for(let e=0;e<d;e++)n=n*256+t[l+e];n=Math.floor(n/f)%p,a[o+e]=h&&n>=m?n-p:n}}function AB(e){let t=e.indexOf(`\0`);return t<0?e:e.slice(0,t)}function jB(e,t,n,r,i){let a=PB(e.encoding),o=e.bitCount>>3,s=Array(n);for(let c=0,l=i+e.byteOffset;c<n;c++,l+=r)s[c]=AB(a.decode(t.subarray(l,l+o)));return s}function MB(e,t,n,r,i,a){let o=a instanceof Float64Array?NaN:null;if(e.allInvalid){for(let e=0;e<n;e++)a[e]=o;return}if(e.invalBit===null)return;let s=1<<(e.invalBit&7);for(let c=0,l=i+(e.invalBit>>3);c<n;c++,l+=r)t[l]&s&&(a[c]=o)}var NB,PB,FB=c((()=>{AR(),NB=new Map,PB=e=>{let t=NB.get(e);return t||NB.set(e,t=new TextDecoder(e)),t}}));function IB(e,t){return e.kind===`vmaster`?!0:(e.kind===`vlsd`||e.type===`uint`||e.type===`int`||e.type===`float`?!(e.bitCount>=1&&e.bitCount<=64):!(e.bitCount>=8))?!1:HB(e)<=t.dataBytes}function LB(e,t){let n=e.notes;for(let r of e.groups){if(![0,1,2,4,8].includes(r.recordIdSize))throw Error(`This MDF file is damaged (bad record id size).`);if(r.vlsdCg)continue;let e=zB(r);if(e>BB||e===0){r.cycles>0&&n.push(`${r.name||`A group`}: its records are ${e===0?`empty`:`too large`} (damaged); skipped.`),r.cycles=0;continue}r.cycles=Math.min(r.cycles,Math.floor(VB(r.stream,t)/e));let i=r.channels.filter(e=>!IB(e,r));for(let e of i)n.push(`${e.name}: its bits lie outside its record (damaged); skipped.`);i.length&&(r.channels=r.channels.filter(e=>!i.includes(e))),r.master&&!IB(r.master,r)&&(n.push(`${r.master.name}: the time channel lies outside its record (damaged): samples are numbered instead.`),r.master=null);for(let e of r.master?[...r.channels,r.master]:r.channels)e.invalBit!==null&&e.invalBit>=8*r.invalBytes&&(e.invalBit=null)}}function RB(e,t){let n=0;for(let r of e.master?[...t,e.master]:t){if(r.invalBit!==null)return 1/0;r.kind!==`vmaster`&&(n=Math.max(n,r.byteOffset+(r.bitOffset+r.bitCount+7>>3)))}return e.recordIdSize+n}var zB,BB,VB,HB,UB=c((()=>{zB=e=>e.recordIdSize+e.dataBytes+e.invalBytes+e.idTrailer,BB=64<<20,VB=(e,t)=>e.reduce((e,n)=>e+(n.zip?n.zip.orgLength:Math.max(0,Math.min(n.length,t-n.offset))),0),HB=e=>e.byteOffset+Math.ceil((e.bitOffset+e.bitCount)/8)})),WB,GB,KB,qB,JB,YB,XB,ZB,QB,$B,eV,tV,nV,rV,iV,aV,oV,sV,cV,lV,uV,dV,fV,pV,mV,hV,gV,_V,vV,yV,bV,xV,SV,CV=c((()=>{for(WB=Uint8Array,GB=Uint16Array,KB=Int32Array,qB=new WB([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),JB=new WB([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),YB=new WB([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),XB=function(e,t){for(var n=new GB(31),r=0;r<31;++r)n[r]=t+=1<<e[r-1];for(var i=new KB(n[30]),r=1;r<30;++r)for(var a=n[r];a<n[r+1];++a)i[a]=a-n[r]<<5|r;return{b:n,r:i}},ZB=XB(qB,2),QB=ZB.b,$B=ZB.r,QB[28]=258,$B[258]=28,eV=XB(JB,0),tV=eV.b,eV.r,nV=new GB(32768),rV=0;rV<32768;++rV)iV=(rV&43690)>>1|(rV&21845)<<1,iV=(iV&52428)>>2|(iV&13107)<<2,iV=(iV&61680)>>4|(iV&3855)<<4,nV[rV]=((iV&65280)>>8|(iV&255)<<8)>>1;for(aV=(function(e,t,n){for(var r=e.length,i=0,a=new GB(t);i<r;++i)e[i]&&++a[e[i]-1];var o=new GB(t);for(i=1;i<t;++i)o[i]=o[i-1]+a[i-1]<<1;var s;if(n){s=new GB(1<<t);var c=15-t;for(i=0;i<r;++i)if(e[i])for(var l=i<<4|e[i],u=t-e[i],d=o[e[i]-1]++<<u,f=d|(1<<u)-1;d<=f;++d)s[nV[d]>>c]=l}else for(s=new GB(r),i=0;i<r;++i)e[i]&&(s[i]=nV[o[e[i]-1]++]>>15-e[i]);return s}),oV=new WB(288),rV=0;rV<144;++rV)oV[rV]=8;for(rV=144;rV<256;++rV)oV[rV]=9;for(rV=256;rV<280;++rV)oV[rV]=7;for(rV=280;rV<288;++rV)oV[rV]=8;for(sV=new WB(32),rV=0;rV<32;++rV)sV[rV]=5;cV=aV(oV,9,1),lV=aV(sV,5,1),uV=function(e){for(var t=e[0],n=1;n<e.length;++n)e[n]>t&&(t=e[n]);return t},dV=function(e,t,n){var r=t/8|0;return(e[r]|e[r+1]<<8)>>(t&7)&n},fV=function(e,t){var n=t/8|0;return(e[n]|e[n+1]<<8|e[n+2]<<16)>>(t&7)},pV=function(e){return(e+7)/8|0},mV=function(e,t,n){return(t==null||t<0)&&(t=0),(n==null||n>e.length)&&(n=e.length),new WB(e.subarray(t,n))},hV=[`unexpected EOF`,`invalid block type`,`invalid length/literal`,`invalid distance`,`stream finished`,`no stream handler`,,`no callback`,`invalid UTF-8 data`,`extra field too long`,`date not in range 1980-2099`,`filename too long`,`stream finishing`,`invalid zip data`],gV=function(e,t,n){var r=Error(t||hV[e]);if(r.code=e,Error.captureStackTrace&&Error.captureStackTrace(r,gV),!n)throw r;return r},_V=function(e,t,n,r){var i=e.length,a=r?r.length:0;if(!i||t.f&&!t.l)return n||new WB(0);var o=!n,s=o||t.i!=2,c=t.i;o&&(n=new WB(i*3));var l=function(e){var t=n.length;if(e>t){var r=new WB(Math.max(t*2,e));r.set(n),n=r}},u=t.f||0,d=t.p||0,f=t.b||0,p=t.l,m=t.d,h=t.m,g=t.n,_=i*8;do{if(!p){u=dV(e,d,1);var v=dV(e,d+1,3);if(d+=3,!v){var y=pV(d)+4,b=e[y-4]|e[y-3]<<8,x=y+b;if(x>i){c&&gV(0);break}s&&l(f+b),n.set(e.subarray(y,x),f),t.b=f+=b,t.p=d=x*8,t.f=u;continue}else if(v==1)p=cV,m=lV,h=9,g=5;else if(v==2){var S=dV(e,d,31)+257,C=dV(e,d+10,15)+4,w=S+dV(e,d+5,31)+1;d+=14;for(var T=new WB(w),E=new WB(19),D=0;D<C;++D)E[YB[D]]=dV(e,d+D*3,7);d+=C*3;for(var O=uV(E),k=(1<<O)-1,A=aV(E,O,1),D=0;D<w;){var j=A[dV(e,d,k)];d+=j&15;var y=j>>4;if(y<16)T[D++]=y;else{var M=0,N=0;for(y==16?(N=3+dV(e,d,3),d+=2,M=T[D-1]):y==17?(N=3+dV(e,d,7),d+=3):y==18&&(N=11+dV(e,d,127),d+=7);N--;)T[D++]=M}}var P=T.subarray(0,S),F=T.subarray(S);h=uV(P),g=uV(F),p=aV(P,h,1),m=aV(F,g,1)}else gV(1);if(d>_){c&&gV(0);break}}s&&l(f+131072);for(var I=(1<<h)-1,L=(1<<g)-1,R=d;;R=d){var M=p[fV(e,d)&I],z=M>>4;if(d+=M&15,d>_){c&&gV(0);break}if(M||gV(2),z<256)n[f++]=z;else if(z==256){R=d,p=null;break}else{var B=z-254;if(z>264){var D=z-257,V=qB[D];B=dV(e,d,(1<<V)-1)+QB[D],d+=V}var ee=m[fV(e,d)&L],H=ee>>4;ee||gV(3),d+=ee&15;var F=tV[H];if(H>3){var V=JB[H];F+=fV(e,d)&(1<<V)-1,d+=V}if(d>_){c&&gV(0);break}s&&l(f+131072);var U=f+B;if(f<F){var te=a-F,W=Math.min(F,U);for(te+f<0&&gV(3);f<W;++f)n[f]=r[te+f]}for(;f<U;++f)n[f]=n[f-F]}}t.l=p,t.p=R,t.b=f,t.f=u,p&&(u=1,t.m=h,t.d=m,t.n=g)}while(!u);return f!=n.length&&o?mV(n,0,f):n.subarray(0,f)},vV=new WB(0),yV=function(e,t){return((e[0]&15)!=8||e[0]>>4>7||(e[0]<<8|e[1])%31)&&gV(6,`invalid zlib data`),(e[1]>>5&1)==+!t&&gV(6,`invalid zlib data: `+(e[1]&32?`need`:`unexpected`)+` dictionary`),(e[1]>>3&4)+2},bV=function(){function e(e,t){typeof e==`function`&&(t=e,e={}),this.ondata=t;var n=e&&e.dictionary&&e.dictionary.subarray(-32768);this.s={i:0,b:n?n.length:0},this.o=new WB(32768),this.p=new WB(0),n&&this.o.set(n)}return e.prototype.e=function(e){if(this.ondata||gV(5),this.d&&gV(4),!this.p.length)this.p=e;else if(e.length){var t=new WB(this.p.length+e.length);t.set(this.p),t.set(e,this.p.length),this.p=t}},e.prototype.c=function(e){this.s.i=+(this.d=e||!1);var t=this.s.b,n=_V(this.p,this.s,this.o);this.ondata(mV(n,t,this.s.b),this.d),this.o=mV(n,this.s.b-32768),this.s.b=this.o.length,this.p=mV(this.p,this.s.p/8|0),this.s.p&=7},e.prototype.push=function(e,t){this.e(e),this.c(t)},e}(),xV=function(){function e(e,t){bV.call(this,e,t),this.v=e&&e.dictionary?2:1}return e.prototype.push=function(e,t){if(bV.prototype.e.call(this,e),this.v){if(this.p.length<6&&!t)return;this.p=this.p.subarray(yV(this.p,this.v-1)),this.v=0}t&&(this.p.length<4&&gV(6,`invalid zlib data`),this.p=this.p.subarray(0,-4)),bV.prototype.c.call(this,t)},e}(),SV=typeof TextDecoder<`u`&&new TextDecoder;try{SV.decode(vV,{stream:!0})}catch{}}));async function*wV(e){for(let t=0;t<e.length;t+=DV)yield e.subarray(t,t+DV)}async function*TV(e){if(typeof DecompressionStream!=`function`){let t=[],n=new xV(e=>{t.push(e)});for await(let r of e)for(n.push(r,!1);t.length;)yield t.shift();for(n.push(new Uint8Array,!0);t.length;)yield t.shift();return}let t=new DecompressionStream(`deflate`),n=t.writable.getWriter();(async()=>{for await(let t of e)await n.write(t);await n.close()})().catch(e=>n.abort(e).catch(()=>{}));let r=t.readable.getReader();try{for(;;){let{done:e,value:t}=await r.read().catch(e=>{throw e instanceof TypeError?Error(OV):e});if(e)return;yield t}}finally{r.cancel().catch(()=>{})}}async function EV(e,t=-1,n=1/0){let r=[],i=Math.min(t,n),a=t>=0?new Uint8Array(i):null,o=0;for await(let s of TV(wV(e))){if(a){if(o+s.length>t&&n>t)throw Error(`Compressed data is longer than its header says.`);a.set(o+s.length>i?s.subarray(0,i-o):s,o)}else r.push(s);if(o+=s.length,o>=n)break}if(a)return o>=i?a:a.subarray(0,o);let s=r.length===1?r[0]:new Uint8Array(o);return r.length>1&&r.reduce((e,t)=>(s.set(t,e),e+t.length),0),o>n?s.subarray(0,n):s}var DV,OV,kV=c((()=>{CV(),DV=65536,OV=`This file's compressed data is damaged.`}));function AV(e,t,n,r=t){let i=Math.floor(n/t),a=new Uint8Array(r<t?i*r:n),o=r%4==0&&IV?new Uint32Array(a.buffer,0,i*r>>2):null,s=r>>2;for(let t=0;t<i;t+=512){let n=Math.min(i,t+512);if(o)for(let a=0;a<r;a+=4){let r=a*i,c=r+i,l=c+i,u=l+i;for(let i=t,d=t*s+(a>>2);i<n;i++,d+=s)o[d]=e[r+i]|e[c+i]<<8|e[l+i]<<16|e[u+i]<<24}else for(let o=0;o<r;o++){let s=o*i;for(let i=t,c=t*r+o;i<n;i++,c+=r)a[c]=e[s+i]}}let c=i*t;return r===t&&a.set(e.subarray(c,n),c),a}function jV(e,t,n){if(!(n<t)||e.length===0)return t;let r=Math.min(t,n+3&-4);return r===t?t:e.every(e=>e.zip?.type===1&&e.zip.param===t&&e.zip.orgLength%t===0)?r:t}async function MV(e,t,n=1/0,r=1/0){let i=await e.slice(t.offset,t.length),{type:a,param:o,orgLength:s}=t.zip;if(a===0)return EV(i,s,r);let c=Math.min(n,o);return AV(await EV(i,s,c<o?s/o*c:1/0),o,s,c)}async function*NV(e,t,n,r=1/0){let i=e=>!!e?.zip&&!(e.zip.type===0&&(e.length>16777216||e.zip.orgLength>268435456)),a=null;for(let o=0;o<t.length;o++){let s=t[o];if(n?.throwIfAborted(),!s.zip)for await(let t of e.windows(s.offset,s.length))yield t.bytes;else if(i(s)){let n=a??MV(e,s,r);a=i(t[o+1])?MV(e,t[o+1],r):null,a?.catch(()=>{}),yield await n}else{let t=s.zip.orgLength;for await(let n of TV((async function*(){for await(let t of e.windows(s.offset,s.length))yield t.bytes})()))if(yield n.length>t?n.subarray(0,t):n,(t-=n.length)<=0)break}}}async function*PV(e,t,n,r){if(r<=0||t<=0)return;let i=Math.min(n,r),a=null,o=0,s=0;for await(let n of e){let e=0;for(;e<n.length&&s<r;){if(o===0){let a=Math.min(i,r-s,Math.floor((n.length-e)/t));if(a>0){yield{buf:n.subarray(e,e+a*t),n:a},s+=a,e+=a*t;continue}}a??=new Uint8Array(t*i);let c=Math.min(a.length,(r-s)*t),l=Math.min(n.length-e,c-o);if(a.set(n.subarray(e,e+l),o),o+=l,e+=l,o===c){let e=o/t;yield{buf:a,n:e},s+=e,o=0}}if(s>=r)return}a&&o>=t&&(yield{buf:a,n:Math.floor(o/t)})}async function FV(e,t,n,r){let i=n*r,a=0;for(let n of t){let t=n.zip?n.zip.orgLength:n.length;if(i<a)return null;if(i+r<=a+t)return n.zip?null:e.read(n.offset+i-a,r);a+=t}return null}var IV,LV,RV,zV=c((()=>{kV(),DB(),IV=new Uint8Array(Uint32Array.of(1).buffer)[0]===1,LV=(e,t)=>(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0,RV=class{#e;#t;#n;#r;#i=new Uint8Array;#a=0;#o;#s=0;constructor(e,t,n){this.#e=e,this.#t=t,this.#n=n,this.#r=NV(e,t,n),this.#o=t.reduce((e,t)=>e+(t.zip?t.zip.orgLength:t.length),0)}peek(e){let t=e-this.#a;if(t<0||t+4>this.#i.length)return null;let n=LV(this.#i,t);return t+4+n>this.#i.length?null:this.#i.subarray(t+4,t+4+n)}async get(e){for(;;){let t=this.peek(e);if(t)return t;let n=e-this.#a;if(e+4>this.#o||n>=0&&n+4<=this.#i.length&&e+4+LV(this.#i,n)>this.#o)throw Error(`This MF4 is damaged (string data ends early).`);e<this.#a&&(this.#r=NV(this.#e,this.#t,this.#n),this.#i=new Uint8Array,this.#a=0);let r=await this.#r.next();if(r.done)throw Error(`This MF4 is damaged (string data ends early).`);if((this.#s+=r.value.length)>4*this.#o+16777216)throw Error(`This MF4 is damaged (its string offsets jump back and forth).`);let i=Math.max(0,Math.min(e-this.#a,this.#i.length)),a=this.#i.subarray(i),o=new Uint8Array(a.length+r.value.length);o.set(a),o.set(r.value,a.length),this.#a+=i,this.#i=o}}}}));function BV(e,t,n,r,i=zB(e),a=new Float64Array(n)){let o=e.master;if(!o)return null;if(o.kind===`vmaster`)for(let e=0;e<n;e++)a[e]=r+e;else kB(o,t,n,i,e.recordIdSize,a);return rB(o.conv,a),a}function VV(e,t,n){return n===1?e[t]:n===2?e[t]|e[t+1]<<8:n===4?(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0:((e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0)+4294967296*((e[t+4]|e[t+5]<<8|e[t+6]<<16|e[t+7]<<24)>>>0)}function HV(e,t){let n=new Uint8Array(e.length+t.length);return n.set(e),n.set(t,e.length),n}async function*UV(e,t,n,r,i,a=1/0){let o=t.groups[n[0]];if(o.sorted){let t=jV(o.stream,zB(o),a),r=0;for await(let{buf:a,n:s}of PV(NV(e,o.stream,i,t),t,WV(t),o.cycles))yield{g:n[0],buf:a,n:s,start:r,size:t},r+=s;return}let s=t.groups.map((e,t)=>({g:e,k:t})).filter(({g:e})=>e.dg===o.dg),c=o.recordIdSize,l=new Map;for(let e of n){let n=t.groups[e],r=zB(n);l.set(n.recordId,{k:e,size:r,buf:new Uint8Array(r*Math.min(WV(r),Math.max(1,n.cycles))),fill:0,start:0})}let u=new Map(s.map(({g:e})=>[e.recordId,e.vlsdCg?-1:zB(e)])),d=new Map,f=new Uint8Array;for await(let t of NV(e,o.stream,i)){let e=f.length?HV(f,t):t,n=0;for(;!(n+c>e.length);){let t=VV(e,n,c),i=u.get(t);if(i===void 0)throw Error(`This MF4 is damaged (unknown record id ${t}).`);if(i<0){if(n+c+4>e.length)break;let i=(e[n+c]|e[n+c+1]<<8|e[n+c+2]<<16|e[n+c+3]<<24)>>>0;if(i>GV)throw Error(`This MF4 is damaged (a string record of ${i} bytes).`);let a=n+c+4+i;if(a>e.length)break;let o=d.get(t)??0;r.wanted(t)&&r.put(t,o,e.slice(n+c+4,a)),d.set(t,o+4+i),n=a;continue}if(n+i>e.length)break;let a=l.get(t);if(a&&(a.buf.set(e.subarray(n,n+i),a.fill),a.fill+=i,a.fill===a.buf.length)){let e=a.fill/a.size;yield{g:a.k,buf:a.buf,n:e,start:a.start,size:a.size},a.start+=e,a.fill=0}n+=i}f=e.slice(n)}for(let e of l.values())e.fill&&(yield{g:e.k,buf:e.buf,n:e.fill/e.size,start:e.start,size:e.size})}var WV,GV,KV,qV=c((()=>{cB(),FB(),UB(),zV(),WV=e=>Math.max(1,Math.min(65536,Math.floor((8<<20)/Math.max(1,e)))),GV=64<<20,KV=class{#e;#t;#n=new Map;#r=new Map;constructor(e,t){this.#e=e,this.#t=t}want(e){this.#r.has(e)||this.#r.set(e,new Map)}wanted(e){return this.#r.has(e)}put(e,t,n){this.#r.get(e).set(t,n)}async bytes(e,t){let n=Array(t.length);if(e.sdRecordId!==null){let r=this.#r.get(e.sdRecordId);for(let e=0;e<t.length;e++)n[e]=r?.get(t[e])??null,r?.delete(t[e]);return n}if(!e.sd)return n.fill(null);let r=this.#n.get(e);r||this.#n.set(e,r=new RV(this.#e,e.sd,this.#t));for(let e=0;e<t.length;e++)n[e]=r.peek(t[e])??await r.get(t[e]);return n}async strings(e,t){let n=PB(e.encoding);return(await this.bytes(e,t)).map(e=>e?AB(n.decode(e)):null)}}}));function JV(e){let t=e.split(`"`),n=new Map;for(let e=0;e+1<t.length;e+=2){let r=t[e].trim();rH.test(r)&&n.set(Number(r),t[e+1])}return n}function YV(e){let t=new Map,n=new Map,r=new Map,i=(e,t)=>{let i=n.get(Number(e));return i?r.get(i)?.get(t):void 0},a=null;for(let o of e.split(/\r?\n/)){let e=o.trim(),s;if(s=$V.exec(e)){let e=Number(s[1]),r=e>=2147483648,i=r?e-2147483648:e;a={id:i,extended:r,name:s[2],size:Number(s[3]),signals:[]},t.set(QV(i,r),a),n.set(e,a)}else if((s=eH.exec(e))&&a){let e=s[2],t=Number(s[3]),n=Number(s[4]);if(!iH(t,n)||!s[7].trim()||!s[8].trim())continue;let i={name:s[1],start:t,length:n,littleEndian:s[5]===`1`,signed:s[6]===`-`,factor:Number(s[7]),offset:Number(s[8]),unit:s[9],mux:e?e===`M`?`switch`:parseInt(e.slice(1),10):null,float:0,values:null};a.signals.push(i);let o=r.get(a);o||r.set(a,o=new Map),o.has(i.name)||o.set(i.name,i)}else if(s=tH.exec(e)){let e=i(s[1],s[2]);e&&(e.values=JV(s[3]))}else if(s=nH.exec(e)){let e=i(s[1],s[2]);e&&(e.float=s[3]===`1`?32:64)}else (e.startsWith(`BO_`)||e===``)&&e===``&&(a=null)}return t}function XV(e){if(e.float){let t=e.float/8,n=e.start>>3,r=e.littleEndian,i=new DataView(new ArrayBuffer(8));return(e,a)=>{for(let r=0;r<t;r++)i.setUint8(r,e[a+n+r]??0);return t===4?i.getFloat32(0,r):i.getFloat64(0,r)}}let t=e.length,n=2**t,r=n/2,i=e.signed;if(e.littleEndian){let a=e.start>>3,o=e.start&7;if(o+t<=32){let e=t===32?-1:(1<<t)-1;return(t,s)=>{let c=s+a,l=((t[c]|t[c+1]<<8|t[c+2]<<16|t[c+3]<<24)>>>o&e)>>>0;return i&&l>=r?l-n:l}}let s=o+t+7>>3,c=2**(t-(32-o)),l=2**(32-o);return(e,t)=>{let u=t+a,d=(e[u]|e[u+1]<<8|e[u+2]<<16|e[u+3]<<24)>>>o,f=0;for(let t=s-1;t>=4;t--)f=f*256+(e[u+t]??0);let p=d+f%c*l;return i&&p>=r?p-n:p}}let a=e.start>>3,o=e.start&7;if(7-o+t<=32){let e=32-(7-o)-t,s=t===32?-1:(1<<t)-1;return(t,o)=>{let c=o+a,l=((t[c]<<24|t[c+1]<<16|t[c+2]<<8|t[c+3])>>>e&s)>>>0;return i&&l>=r?l-n:l}}let s=(1<<o+1)-1,c=t-(o+1)>>3,l=t-(o+1)&7,u=2**l;return(e,t)=>{let o=(e[t+a]??0)&s,d=t+a+1;for(let t=0;t<c;t++)o=o*256+(e[d++]??0);return l>0&&(o=o*u+((e[d]??0)>>8-l)),i&&o>=r?o-n:o}}function ZV(e){let t=e.length,n=2**t,r=n/2,i=e.signed,a=t===32?-1:(1<<t)-1;if(!e.float&&e.littleEndian&&(e.start&7)+t<=32){let t=e.start>>3,o=e.start&7;return(e,s,c,l,u,d,f)=>{for(let p=0;p<l;p++){let l=s[c[p]]+t,m=((e[l]|e[l+1]<<8|e[l+2]<<16|e[l+3]<<24)>>>o&a)>>>0;u[p]=(i&&m>=r?m-n:m)*d+f}}}if(!e.float&&!e.littleEndian&&7-(e.start&7)+t<=32){let o=e.start>>3,s=32-(7-(e.start&7))-t;return(e,t,c,l,u,d,f)=>{for(let p=0;p<l;p++){let l=t[c[p]]+o,m=((e[l]<<24|e[l+1]<<16|e[l+2]<<8|e[l+3])>>>s&a)>>>0;u[p]=(i&&m>=r?m-n:m)*d+f}}}let o=XV(e);return(e,t,n,r,i,a,s)=>{for(let c=0;c<r;c++)i[c]=o(e,t[n[c]])*a+s}}var QV,$V,eH,tH,nH,rH,iH,aH=c((()=>{QV=(e,t)=>t?e+2147483648:e,$V=/^BO_\s+(\d+)\s+(\w+)\s*:\s*(\d+)/,eH=/^SG_\s+(\w+)\s*(?:(M|m\d+M?)\s*)?:\s*(\d+)\|(\d+)@([01])([+-])\s*\(([^,)]*),([^)]*)\)\s*\[[^\]]*\]\s*"([^"]*)"/,tH=/^VAL_\s+(\d+)\s+(\w+)\s+(.*);/,nH=/^SIG_VALTYPE_\s+(\d+)\s+(\w+)\s*:\s*([12])\s*;/,rH=/^-?\d+(?:\.\d+)?$/,iH=(e,t)=>e<=511&&t>=1&&t<=64}));function oH(e){if(!e.busEvent||e.busType!==2)return null;let t=t=>e.channels.find(e=>e.name.endsWith(t))??null,n=t(`DataFrame.ID`),r=t(`DataFrame.DataBytes`);return!n||!r?null:{id:n,ide:t(`DataFrame.IDE`),data:r}}async function sH(e,t,n,r,i,a,o,s){s.key.length<r&&Object.assign(s,{time:new Float64Array(r),key:new Float64Array(r),id:new Float64Array(r),ide:new Float64Array(r),dataAt:new Int32Array(r)});let c=e.recordIdSize,{id:l,ide:u,key:d,dataAt:f}=s;kB(t.id,n,r,a,c,l),t.ide&&kB(t.ide,n,r,a,c,u);for(let e=0;e<r;e++){let n=l[e],r=n&536870911;d[e]=QV(r,t.ide?u[e]!==0:n>=2147483648||r>2047)}if(s.bytes=null,t.data.kind===`vlsd`){let e=new Float64Array(r);kB({...t.data,type:`uint`},n,r,a,c,e),s.bytes=await o.bytes(t.data,e)}else for(let e=0,n=c+t.data.byteOffset;e<r;e++,n+=a)f[e]=n;if(!BV(e,n,r,i,a,s.time.subarray(0,r)))for(let e=0;e<r;e++)s.time[e]=i+e;return s.n=r,s.buf=n,s}function cH(e){return e.float?(e.start>>3)+e.float/8:e.littleEndian?(e.start>>3)+((e.start&7)+e.length+7>>3):(e.start>>3)+1+(Math.max(0,e.length-((e.start&7)+1))+7>>3)}function lH(e,t,n){let r=0;for(let e of n.values())for(let t of e.signals)r=Math.max(r,cH(t));let i=t.data.kind===`vlsd`?t.data:{...t.data,bitCount:Math.min(t.data.bitCount,r*8)};return RB(e,t.ide?[t.id,t.ide,i]:[t.id,i])}function uH(e,t){let n=t.map(t=>e.signals[e.channels[t].s]);return{route:e,col:n.map(ZV),read:n.map(XV),factor:n.map(e=>e.factor),offset:n.map(e=>e.offset),table:t.map((t,r)=>e.channels[t].text?n[r].values:null),idx:new Int32Array,cnt:0,n:0,t0:NaN,t1:NaN}}function dH(e,t,n,r,i,a=1,o=0){let s=new Float64Array(i);if(n.bytes)for(let e=0;e<i;e++)s[e]=t(n.bytes[r[e]]??vH,0)*a+o;else e(n.buf,n.dataAt,r,i,s,a,o);return s}function fH(e,t){let{idx:n,cnt:r}=e,i=new Float64Array(r);for(let e=0;e<r;e++)i[e]=t.time[n[e]];return e.n===0&&(e.t0=i[0]),e.t1=i[r-1],e.n+=r,e.cnt=0,{time:i,cols:e.col.map((i,a)=>{let o=e.table[a];return o?Array.from(dH(i,e.read[a],t,n,r),e=>o.get(e)??null):dH(i,e.read[a],t,n,r,e.factor[a],e.offset[a])})}}function pH(e,t){let n=e.signals.find(e=>e.mux===`switch`);return{key:QV(e.id,e.extended),skip:!1,frames:0,all:t,sw:n?{col:ZV(n),read:XV(n)}:null,byMux:new Map,idx:new Int32Array,cnt:0}}function mH(e,t,n){let r=[];for(let n=0;n<e.n;n++){let i=t.get(e.key[n]);if(i.skip){i.frames++;continue}i.cnt===0&&(r.push(i),i.idx.length<e.n&&(i.idx=new Int32Array(e.n))),i.idx[i.cnt++]=n}let i=[];for(let t of r){if(t.all&&(t.all.idx=t.idx,t.all.cnt=t.cnt,i.push(t.all)),t.sw){let r=dH(t.sw.col,t.sw.read,e,t.idx,t.cnt);for(let e=0;e<t.cnt;e++){let a=t.byMux.get(r[e]);a===void 0&&((a=n(t,r[e]))||t.byMux.size<4096)&&t.byMux.set(r[e],a),a&&(a.cnt===0&&(i.push(a),a.idx.length<t.cnt&&(a.idx=new Int32Array(t.cnt))),a.idx[a.cnt++]=t.idx[e])}}t.cnt=0}return i}async function hH(e,t,n,r){let i=new Map;if(t.groups.forEach((e,t)=>{let n=oH(e);n&&e.cycles>0&&i.set(t,n)}),i.size===0)return null;if(n.length===0)return{dbc:new Map,layouts:i,routes:[],notes:[],cache:new Map};let a=YV(kR(new Uint8Array(await n[0].arrayBuffer()))),o=[],s=new Map,c=new Map,l=0,u=new KV(e,r);for(let[n,d]of i){let i=t.groups[n],f=(e,t)=>{let n=e.signals.filter(e=>t===null?typeof e.mux!=`number`:e.mux===t),r=[];return n.forEach((e,t)=>{r.push({s:t,text:!1}),e.values&&r.push({s:t,text:!0})}),uH({key:QV(e.id,e.extended),mux:t,signals:n,channels:r},r.map((e,t)=>t))},p=new bH(e=>{let t=a.get(e);if(!t){let t=yH(e);return s.set(e,t),t}let r=pH(t,f(t,null));return o.push({model:n,m:r}),r});d.data.sdRecordId!==null&&u.want(d.data.sdRecordId);let m=_H();for await(let o of UV(e,t,[n],u,r,lH(i,d,a))){let e=await sH(i,d,o.buf,o.n,o.start,o.size,u,m),t=(e,t)=>{let n=a.get(e.key);return n.signals.some(e=>e.mux===t)?f(n,t):null};for(let n of mH(e,p,t)){let t=fH(n,e);if(l<0)continue;if((l+=t.time.length*(1+t.cols.length))>xH){l=-1,c.clear();continue}let r=c.get(n);r||c.set(n,r=[]),r.push(t)}}}let d=[],f=new Map;for(let{model:e,m:t}of o)for(let n of[t.all,...t.byMux.values()]){if(!n)continue;let{route:t,n:r,t0:i,t1:o}=n;if(t.signals.length===0)continue;let s=a.get(t.key);l>=0&&f.set(t,c.get(n)??[]),d.push({model:e,route:t,group:{name:t.mux===null?s.name:`${s.name} [m=${t.mux}]`,channels:t.channels.map(e=>({name:e.text?`${t.signals[e.s].name} (text)`:t.signals[e.s].name,unit:e.text?``:t.signals[e.s].unit,text:e.text})),samples:r,time:{kind:`timestamps`},rateHz:r>1&&o>i?Math.round((r-1)/(o-i)*1e6)/1e6:null}})}let p=[];if(s.size){let e=[...s.values()].reduce((e,t)=>e+t.frames,0),t=[...s.keys()].map(e=>`0x${(e%2147483648).toString(16).toUpperCase()}`).join(`, `);p.push(`${e} frame${e===1?``:`s`} with ${s.size} id${s.size===1?``:`s`} not in the DBC ${e===1?`was`:`were`} skipped (${t}).`)}return{dbc:a,layouts:i,routes:d,notes:p,cache:f}}async function*gH(e,t,n,r,i,a){let o=[];for(let e of i){let t=r.cache.get(e.route);if(!t){o.push(e);continue}r.cache.delete(e.route);let n=0;for(let r of t)yield{group:e.group,start:n,length:r.time.length,time:r.time,columns:e.sel.map(e=>r.cols[e])},n+=r.time.length}if(!o.length)return;let s=r.layouts.get(n),c=t.groups[n],l=new Map,u=new Map;for(let e of o){let t=uH(e.route,e.sel);l.set(t,e.group);let n=u.get(e.route.key);n||u.set(e.route.key,n={all:null,byMux:new Map}),e.route.mux===null?n.all=t:n.byMux.set(e.route.mux,t)}let d=new bH(e=>{let t=u.get(e);if(!t)return yH(e);let n=pH(r.dbc.get(e),t.all);return t.byMux.size||(n.sw=null),n}),f=new KV(e,a);s.data.sdRecordId!==null&&f.want(s.data.sdRecordId);let p=_H();for await(let i of UV(e,t,[n],f,a,lH(c,s,r.dbc))){let e=await sH(c,s,i.buf,i.n,i.start,i.size,f,p);for(let t of mH(e,d,(e,t)=>u.get(e.key).byMux.get(t)??null)){let n=t.n,r=fH(t,e);yield{group:l.get(t),start:n,length:r.time.length,time:r.time,columns:r.cols}}}}var _H,vH,yH,bH,xH,SH=c((()=>{aH(),AR(),FB(),qV(),UB(),_H=()=>({n:0,time:new Float64Array,key:new Float64Array,id:new Float64Array,ide:new Float64Array,bytes:null,buf:new Uint8Array,dataAt:new Int32Array}),vH=new Uint8Array,yH=e=>({key:e,skip:!0,frames:0,all:null,sw:null,byMux:new Map,idx:new Int32Array,cnt:0}),bH=class{#e=Array(2048);#t=new Map;#n;constructor(e){this.#n=e}get(e){let t=e<2048?this.#e[e]:this.#t.get(e);return t||(t=this.#n(e),e<2048?this.#e[e]=t:this.#t.set(e,t)),t}},xH=48e6}));async function CH(e,t){let n=t.master;if(!n||t.cycles<2)return null;if(n.kind===`vmaster`)return n.conv.k===`lin`&&n.conv.a>0?OH(1/n.conv.a):null;if(!t.sorted)return null;let r=zB(t),i=t.cycles,a,o;if(t.stream[0]?.zip){let n=jV(t.stream.slice(0,1),r,RB(t,[])),s=await MV(e,t.stream[0],n,4096*r);if(i=Math.min(t.cycles,Math.floor(s.length/n)),i<2)return null;a=s.subarray(0,n),o=s.subarray((i-1)*n,i*n)}else a=await FV(e,t.stream,0,r),o=await FV(e,t.stream,t.cycles-1,r);if(!a||!o)return null;let s=new Float64Array(2);return kB(n,a,1,r,t.recordIdSize,s,0),kB(n,o,1,r,t.recordIdSize,s,1),rB(n.conv,s),s[1]>s[0]?OH((i-1)/(s[1]-s[0])):null}async function wH(e,t,n,r,i,a,o){let s;if(e.kind===`vlsd`){let a=new Float64Array(n);kB({...e,type:`uint`},t,n,r,i,a),s=await o.strings(e,a)}else if(e.type===`string`)s=jB(e,t,n,r,i);else{let a=new Float64Array(n);kB(e,t,n,r,i,a),e.conv.k===`text`?s=aB(e.conv,a):(rB(e.conv,a),s=a)}return MB(e,t,n,r,a,s),s}async function TH(e,t,n,r,i,a,o,s){let c=e.recordIdSize,l=[];for(let i of t)l.push(await wH(e.channels[i],n,r,a,c,c+e.dataBytes,s));return{group:o,time:BV(e,n,r,i,a),start:i,length:r,columns:l}}async function*EH(e,t){let n=e.plan.state,r=t.filter(e=>n.groups[e].route),i=t.filter(e=>!n.groups[e].route);if(r.length){let t=r.map(t=>({group:t,route:n.groups[t].route,sel:Xz(e,t)}));yield*gH(e.io,n.model,n.groups[r[0]].model,n.bus,t,e.signal)}if(!i.length)return;let a=new KV(e.io,e.signal),o=new Map;for(let t of i){let r=n.groups[t],i=Xz(e,t).map(e=>r.channels[e]);for(let e of i){let t=n.model.groups[r.model].channels[e].sdRecordId;t!==null&&a.want(t)}o.set(r.model,{pg:t,cols:i})}let[s,{cols:c}]=o.entries().next().value,l=n.model.groups[s],u=o.size===1?RB(l,c.map(e=>l.channels[e])):1/0;for await(let t of UV(e.io,n.model,[...o.keys()],a,e.signal,u)){let{pg:e,cols:r}=o.get(t.g);yield await TH(n.model.groups[t.g],r,t.buf,t.n,t.start,t.size,e,a)}}function DH(e){let t=e.plan.state,n=new Map;for(let r of e.selection){let e=t.model.groups[t.groups[r.group].model].dg;n.set(e,[...n.get(e)??[],r.group])}return[...n].sort((e,t)=>e[0]-t[0]).map(([,e])=>e)}var OH,kH,AH,jH,MH=c((()=>{AR(),Zz(),dB(),DB(),cB(),FB(),MR(),UB(),qV(),zV(),SH(),OH=e=>Math.round(e*1e6)/1e6,kH=e=>e.kind===`value`?e.type!==`bytes`:e.kind===`vlsd`&&e.type===`string`,AH=e=>({name:e.name,unit:e.unit,text:e.type===`string`||e.kind===`vlsd`||e.conv.k===`text`}),jH={...jR,async plan(e,t){let n=await t.read(0,64);if(wR(n,`UnFinMF`))throw Error(`This MF4 was not finalized by its logger (it starts with UnFinMF). Finalize it with the logger software or asammdf, then open it again.`);let r=OR(n.subarray(8,16)).replace(/\0/g,``).trim(),i=Number(r.replace(`.`,``).slice(0,3))>=400?await CB(t,r):await uB(t,n,r);LB(i,t.size);let a=await hH(t,i,e.companions.filter(e=>e.name.toLowerCase().endsWith(`.dbc`))),o=new Set(a?.layouts.keys()??[]),s=[],c=[],l=[...i.notes],u=0;for(let e=0;e<i.groups.length;e++){let n=i.groups[e];if(n.vlsdCg||n.cycles===0||o.has(e))continue;let r=[];if(n.channels.forEach((e,t)=>{kH(e)?r.push(t):u++}),r.length!==0){for(let e of r){let t=n.channels[e].conv;t.k===`unsupported`&&l.push(`${n.channels[e].name}: ${t.what} is not supported; raw values are shown.`)}c.push({model:e,channels:r}),s.push({name:n.name,channels:r.map(e=>AH(n.channels[e])),samples:n.cycles,time:n.master?{kind:`timestamps`}:{kind:`index`},rateHz:await CH(t,n)})}}if(u&&l.push(`${u} byte-array channel${u===1?` was`:`s were`} skipped.`),a){if(a.routes.length===0&&a.dbc.size===0){if(s.length===0)throw Error(`This MF4 has raw CAN frames. Drop its .dbc file together with it to decode signals.`);l.push(`This MF4 also has raw CAN frames. Drop its .dbc file together with it to decode signals.`)}for(let e of a.routes)c.push({model:e.model,route:e.route}),s.push(e.group);l.push(...a.notes)}if(s.length===0)throw Error(`This MDF file has no channels with samples.`);let d={model:i,groups:c,bus:a};return{format:i.version,startTime:i.startTime,groups:s,meta:i.meta,events:[],notes:l,interleaved:!!a?.routes.length||i.groups.some(e=>!e.sorted&&!e.vlsdCg),state:d}},async*stream(e){for(let t of DH(e))yield*EH(e,t)},streamGroup(e,t){return EH(e,[t])}}}));function NH(e){let t=[];for(let n of kR(e).split(`\0`)){if(!n)continue;let e=n.split(``),r=parseFloat(e[0].split(``)[0]);Number.isFinite(r)&&t.push({onset:r,texts:e.slice(1).filter(e=>e.length>0)})}return t}function PH(e,t){let n=/^(\d\d)\.(\d\d)\.(\d\d)$/.exec(e),r=/^(\d\d)\.(\d\d)\.(\d\d)$/.exec(t);if(!n||!r)return null;let i=Number(n[3]);return`${i>=85?1900+i:2e3+i}-${n[2]}-${n[1]}T${r[1]}:${r[2]}:${r[3]}`}function FH(e,t,n,r,i,a,o,s){let{bit:c,off:l}=e;if(a===2)for(let e=0;e<i;e++)o[s+e]=c*(l+t.getInt16(r+2*e,!0));else for(let e=0,t=r;e<i;e++,t+=3)o[s+e]=c*(l+((n[t]|n[t+1]<<8|n[t+2]<<16)<<8>>8))}var IH,LH,RH=c((()=>{qz(),AR(),PR(),IH=e=>`${+e.toFixed(6)} Hz`,LH={...NR,async plan(e,t){let n=await t.read(0,256),r=(e,t)=>OR(n.subarray(e,e+t)).trim(),i=n[0]===255,a=parseInt(r(252,4),10),o=parseInt(r(184,8),10),s=r(192,44),c=/^(EDF|BDF)\+/.test(s),l=/^(EDF|BDF)\+D/.test(s),u=parseFloat(r(244,8));if(!(a>0)||o!==256*(a+1)||!(u>0))throw Error(`This EDF/BDF header is damaged.`);let d=await t.read(256,a*256),f=(e,t,n)=>OR(d.subarray(e*a+t*n,e*a+t*(n+1))).trim(),p=i?3:2,m=[],h=0;for(let e=0;e<a;e++){let t=parseFloat(f(104,8,e)),n=parseFloat(f(112,8,e)),r=parseFloat(f(120,8,e)),i=parseFloat(f(128,8,e)),a=Number(f(216,8,e));if(!(Number.isInteger(a)&&a>=0))throw Error(`This EDF/BDF header is damaged (samples per record).`);let o=(n-t)/(i-r);m.push({label:f(0,16,e),unit:f(96,8,e),spr:a,offset:h,bit:o,off:n/o-i}),h+=a*p}let g=h;if(!(g>0&&o+g<=t.size))throw Error(`This EDF/BDF file is damaged (its data records do not fit in it).`);let _=Math.floor((t.size-o)/g),v=parseInt(r(236,8),10),y=[];v>=0?v>_&&(y.push(`The file is shorter than its header says: ${_} of ${v} data records were read.`),v=_):v=_;let b=c?m.flatMap((e,t)=>/^(EDF|BDF) Annotations$/.test(e.label)?[t]:[]):[],x=new Map;m.forEach((e,t)=>{!b.includes(t)&&e.spr>0&&x.set(e.spr,[...x.get(e.spr)??[],t])});let S=[...x.values()],C=S.map(e=>{let t=m[e[0]].spr/u;return{name:IH(t),channels:e.map(e=>({name:m[e].label,unit:m[e].unit})),samples:v*m[e[0]].spr,rateHz:t,time:l?{kind:`timestamps`}:{kind:`rate`,rate:t,start:0}}}),w={headerBytes:o,records:v,duration:u,recordBytes:g,bps:p,signals:m,groups:S,annotations:b,discontinuous:l};return{format:`${i?`BDF`:`EDF`}${c?l?`+D`:`+`:``}`,startTime:PH(r(168,8),r(176,8)),groups:C,meta:{patient:r(8,80),recording:r(88,80)},events:[],notes:l?[`Discontinuous recording: each gap shows as a break in the traces.`,...y]:y,state:w}},async*stream(e){let t=e.plan.state,n=Math.max(1,Math.floor(Gz/t.recordBytes)),r=e.selection.map(e=>({g:e.group,chans:e.channels.map(n=>t.signals[t.groups[e.group][n]]),spr:t.signals[t.groups[e.group][0]].spr})),i=r.map(()=>0),a=0,o=NaN;for await(let s of e.io.windows(t.headerBytes,t.records*t.recordBytes,n*t.recordBytes)){e.signal?.throwIfAborted();let n=Math.floor(s.bytes.length/t.recordBytes);if(n===0)break;let c=TR(s.bytes),l=new Float64Array(n),u=[];for(let e=0;e<n;e++)l[e]=(a+e)*t.duration,t.annotations.forEach((n,r)=>{let i=t.signals[n],a=e*t.recordBytes+i.offset,o=NH(s.bytes.subarray(a,a+i.spr*t.bps));r===0&&o.length&&(l[e]=o[0].onset);for(let e of o)for(let t of e.texts)u.push({time:e.onset,text:t})});let d=new Uint8Array(n),f=0;if(t.discontinuous)for(let e=0;e<n;e++){let n=e?l[e-1]+t.duration:o;n===n&&l[e]>n+1e-9&&(d[e]=1,f++)}for(let e=0;e<r.length;e++){let a=r[e],p=a.spr/t.duration,m=n*a.spr+f,h=t.discontinuous?new Float64Array(m):null,g=a.chans.map(()=>new Float64Array(m)),_=0;for(let e=0;e<n;e++){if(d[e]){h[_]=e?l[e-1]+t.duration:o;for(let e of g)e[_]=NaN;_++}if(h)for(let t=0;t<a.spr;t++)h[_+t]=l[e]+t/p;let n=e*t.recordBytes;a.chans.forEach((e,r)=>FH(e,c,s.bytes,n+e.offset,a.spr,t.bps,g[r],_)),_+=a.spr}let v={group:a.g,time:h,start:i[e],length:m,columns:g};e===0&&u.length&&(v.events=u),i[e]+=m,yield v}o=l[n-1]+t.duration,a+=n}}}}));function zH(e,t,n=0){let r=e.indexOf(`<${t}>`,n);if(r<0)return``;let i=e.indexOf(`</${t}>`,r);return i<0?``:e.slice(r+t.length+2,i).trim()}function BH(e,t){let n=[];for(let r=e.indexOf(`<${t}>`);r>=0;){let i=e.indexOf(`</${t}>`,r);if(i<0)break;n.push(e.slice(r,i+t.length+3)),r=e.indexOf(`<${t}>`,i)}return n}function VH(e,t,n){let r=e[n];if((r===1||r===4||r===8)&&n+1+r<=e.length)return r===1?[e[n+1],2]:r===4?[t.getUint32(n+1,!0),5]:[xR(t,n+1),9];throw Error(`This XDF file is damaged (bad length field).`)}function HH(e,t,n,r){if(n>=e.length)return-1;if(e[n++]===8&&(n+=8),r.fmt!==`string`)return n+JH[r.fmt]*r.nch<=e.length?n+JH[r.fmt]*r.nch:-1;for(let i=0;i<r.nch;i++){if(n>=e.length)return-1;let[r,i]=VH(e,t,n);n+=i+r}return n<=e.length?n:-1}async function*UH(e,t){let n=new Uint8Array;for await(let r of e.windows(4,e.size-4)){t?.throwIfAborted();let i=r.bytes,a=r.offset-n.length;if(n.length){let e=new Uint8Array(n.length+i.length);e.set(n),e.set(i,n.length),i=e}let o=TR(i),s=0;for(;!(s+1>i.length);){let t=i[s];if(s+1+t>i.length)break;let[n,r]=VH(i,o,s),c=s+r+n;if(a+c>e.size)return;if(c>i.length)break;yield{tag:i[s+r]|i[s+r+1]<<8,body:i.subarray(s+r+2,c)},s=c}n=i.slice(s)}}function WH(e,t,n){let r=t-e.i0,i=n-e.t0;e.n++,e.si+=r,e.st+=i,e.sii+=r*r,e.sit+=r*i}function GH(e){let t=e.n*e.sii-e.si*e.si;e.b=t>0?(e.n*e.sit-e.si*e.st)/t:0,e.a=(e.st-e.b*e.si)/Math.max(1,e.n)}function KH(e){if(e.length===0)return[0,0];if(e.length===1)return[e[0][1],0];let t={i0:e[0][0],t0:0,n:0,si:0,st:0,sii:0,sit:0,a:0,b:0};for(let[n,r]of e)WH(t,n,r);return GH(t),[t.a-t.b*t.i0,t.b]}function qH(e,t,n){let r=t.t0+t.a+t.b*(n-t.i0);return r+e.c0+e.c1*r}var JH,YH,XH,ZH,QH=c((()=>{AR(),Iz(),Zz(),IR(),JH={float32:4,double64:8,int8:1,int16:2,int32:4,int64:8},YH=1e5,XH=e=>e.fmt===`string`||JH[e.fmt]!==void 0,ZH={...FR,async plan(e,t){let n=new Map,r=``;for await(let e of UH(t)){let t=TR(e.body);if(e.tag===1)r=kR(e.body);else if(e.tag===2){let r=t.getUint32(0,!0),i=kR(e.body.subarray(4)),a=parseInt(zH(i,`channel_count`),10)||1;if(!(a>=1&&a<=YH))throw Error(`This XDF file is damaged (a stream with ${a} channels).`);let o=BH(i,`channel`);n.set(r,{id:r,name:zH(i,`name`)||`Stream ${r}`,nch:a,srate:parseFloat(zH(i,`nominal_srate`))||0,fmt:zH(i,`channel_format`)||`float32`,labels:Array.from({length:a},(e,t)=>zH(o[t]??``,`label`)||`Ch${t+1}`),units:Array.from({length:a},(e,t)=>zH(o[t]??``,`unit`)),count:0,segs:[],clock:[],c0:0,c1:0,lastTs:NaN})}else if(e.tag===3){let r=n.get(t.getUint32(0,!0));if(!r||!XH(r))continue;let[i,a]=VH(e.body,t,4),o=4+a,s=JH[r.fmt],c=r.srate>0?Math.max(1,500/r.srate):1/0;for(let n=0;n<i&&!(HH(e.body,t,o,r)<0);n++){let n;if(e.body[o++]===8?(n=t.getFloat64(o,!0),o+=8):n=r.lastTs+(r.srate>0?1/r.srate:0),r.fmt===`string`)for(let n=0;n<r.nch;n++){let[n,r]=VH(e.body,t,o);o+=r+n}else o+=s*r.nch;if(r.srate>0){let e=r.segs[r.segs.length-1];(!e||n-r.lastTs>c)&&r.segs.push(e={i0:r.count,t0:n,n:0,si:0,st:0,sii:0,sit:0,a:0,b:0}),WH(e,r.count,n)}else r.count===0&&r.segs.push({i0:0,t0:n,n:1,si:0,st:0,sii:0,sit:0,a:0,b:0});r.lastTs=n,r.count++}}else if(e.tag===4){let e=n.get(t.getUint32(0,!0));e&&e.clock.push([t.getFloat64(4,!0),t.getFloat64(12,!0)])}}let i=[],a=[...n.values()].sort((e,t)=>e.id-t.id).filter(e=>(XH(e)||i.push(`${e.name}: channel format ${e.fmt} is not supported; skipped.`),XH(e))),o=1/0;for(let e of a){[e.c0,e.c1]=KH(e.clock);for(let t of e.segs)GH(t);if(e.count===0)continue;let t=e.srate>0?qH(e,e.segs[0],0):e.segs[0].t0+e.c0+e.c1*e.segs[0].t0;o=Math.min(o,t)}let s=Fz(a.map(e=>e.name),[]),c=a.map((e,t)=>({name:s[t],channels:e.labels.map((t,n)=>({name:t,unit:e.units[n],...e.fmt===`string`?{text:!0,sparse:!0}:{}})),samples:e.count,time:{kind:`timestamps`},rateHz:e.srate>0?e.srate:null,irregular:e.srate===0})),l=zH(r,`version`);return{format:`XDF ${l||`1.0`}`,startTime:null,groups:c,meta:{header:l},events:[],notes:i,state:{streams:a,origin:Number.isFinite(o)?o:0}}},async*stream(e){let t=e.plan.state,n=8192,r=new Map,i=e=>e.sel.map(()=>e.s.fmt===`string`?Array(n):new Float64Array(n));for(let a of e.selection){let o=t.streams[a.group],s={g:a.group,s:o,sel:Xz(e,a.group),time:new Float64Array(n),cols:[],n:0,start:0,seg:0,i:0,raw:NaN};s.cols=i(s),r.set(o.id,s)}let a=e=>{let t={group:e.g,time:e.time.slice(0,e.n),start:e.start,length:e.n,columns:e.cols.map(t=>t.slice(0,e.n))};return e.start+=e.n,e.n=0,e.time=new Float64Array(n),e.cols=i(e),t};for await(let i of UH(e.io,e.signal)){if(i.tag!==3)continue;let e=TR(i.body),o=r.get(e.getUint32(0,!0));if(!o)continue;let s=o.s,[c,l]=VH(i.body,e,4),u=4+l,d=JH[s.fmt],f=[];for(let r=0;r<c&&!(HH(i.body,e,u,s)<0);r++){let r;i.body[u++]===8?(r=e.getFloat64(u,!0),u+=8):r=o.raw+(s.srate>0?1/s.srate:0),o.raw=r;let c;if(s.srate>0){for(;o.seg+1<s.segs.length&&s.segs[o.seg+1].i0<=o.i;)o.seg++;c=qH(s,s.segs[o.seg],o.i)}else c=r+s.c0+s.c1*r;if(o.time[o.n]=c-t.origin,s.fmt===`string`){let n=[];for(let t=0;t<s.nch;t++){let[t,r]=VH(i.body,e,u);n.push(kR(i.body.subarray(u+r,u+r+t))),u+=r+t}o.sel.forEach((e,t)=>{o.cols[t][o.n]=n[e]}),f.push({time:c-t.origin,text:n.join(` `)})}else o.sel.forEach((t,n)=>{let r=u+t*d,i=o.cols[n];switch(s.fmt){case`float32`:i[o.n]=e.getFloat32(r,!0);break;case`double64`:i[o.n]=e.getFloat64(r,!0);break;case`int8`:i[o.n]=e.getInt8(r);break;case`int16`:i[o.n]=e.getInt16(r,!0);break;case`int32`:i[o.n]=e.getInt32(r,!0);break;default:i[o.n]=e.getInt32(r+4,!0)*4294967296+e.getUint32(r,!0)}}),u+=d*s.nch;o.i++,++o.n===n&&(yield a(o))}f.length&&(yield{group:o.g,time:new Float64Array,start:o.start,length:0,columns:o.sel.map(()=>new Float64Array),events:f})}for(let e of r.values())e.n&&(yield a(e))}}}));function $H(e,t,n,r,i){switch(r){case mU:{let r=e.getUint32(n,i);return[kR(t.subarray(n+4,n+4+r)),4+r]}case 1:return[e.getInt8(n),1];case 2:return[e.getInt16(n,i),2];case 3:return[e.getInt32(n,i),4];case 4:return[SR(e,n,i),8];case 5:return[e.getUint8(n),1];case 6:return[e.getUint16(n,i),2];case 7:return[e.getUint32(n,i),4];case 8:return[xR(e,n,i),8];case 9:case 25:return[e.getFloat32(n,i),4];case 10:case 26:return[e.getFloat64(n,i),8];case 33:return[e.getUint8(n)!==0,1];case hU:return[bU(e,n,i),16];default:throw Error(`This TDMS file has a property of type ${r}, which Kymoscope cannot read.`)}}function eU(e){let t=/^\/'((?:[^']|'')*)'(?:\/'((?:[^']|'')*)')?$/.exec(e);return t?[t[1].replace(/''/g,`'`),(t[2]??``).replace(/''/g,`'`)]:null}function tU(e){if(e.has(`NI_Number_Of_Scales`))return Number(e.get(`NI_Number_Of_Scales`));let t=0;for(let n of e.keys()){let e=/^NI_Scale\[(\d+)\]_Scale_Type$/.exec(n);e&&(t=Math.max(t,Number(e[1])+1))}return t}function nU(e,t,n){let r=e.find(e=>tU(e)>0);if(!r||r.get(`NI_Scaling_Status`)===`scaled`)return null;let i=(e,a)=>{if(e===xU||e<0||a>8)return e=>e;let o=r.get(`NI_Scale[${e}]_Scale_Type`);if(o===void 0)return e=>e;if(o===`Linear`){let t=Number(r.get(`NI_Scale[${e}]_Linear_Slope`)),n=Number(r.get(`NI_Scale[${e}]_Linear_Y_Intercept`)??0),o=i(Number(r.get(`NI_Scale[${e}]_Linear_Input_Source`)??xU),a+1);return o&&(e=>t*o(e)+n)}if(o===`Polynomial`){let o=Number(r.get(`NI_Scale[${e}]_Polynomial_Coefficients_Size`)??4);if(!(Number.isInteger(o)&&o>=0&&o<=64))return t.push(`${n}: an NI polynomial scale with ${o} coefficients is not supported; raw values are shown.`),null;let s=Array.from({length:o},(t,n)=>Number(r.get(`NI_Scale[${e}]_Polynomial_Coefficients[${n}]`))),c=i(Number(r.get(`NI_Scale[${e}]_Polynomial_Input_Source`)??xU),a+1);return c&&(e=>{let t=c(e),n=0;for(let e=o-1;e>=0;e--)n=n*t+s[e];return n})}return t.push(`${n}: NI scale type ${String(o)} is not supported; raw values are shown.`),null};return i(tU(r)-1,0)}function rU(e,t,n,r,i,a,o,s){let c=SU[e];if(c&&a&&r===gU[e]&&(t.byteOffset+n)%r===0){o.set(new c(t.buffer,t.byteOffset+n,i),s);return}switch(e){case 1:for(let e=0;e<i;e++,n+=r)o[s+e]=t.getInt8(n);return;case 2:for(let e=0;e<i;e++,n+=r)o[s+e]=t.getInt16(n,a);return;case 3:for(let e=0;e<i;e++,n+=r)o[s+e]=t.getInt32(n,a);return;case 4:for(let e=0;e<i;e++,n+=r)o[s+e]=SR(t,n,a);return;case 5:case 33:for(let e=0;e<i;e++,n+=r)o[s+e]=t.getUint8(n);return;case 6:for(let e=0;e<i;e++,n+=r)o[s+e]=t.getUint16(n,a);return;case 7:for(let e=0;e<i;e++,n+=r)o[s+e]=t.getUint32(n,a);return;case 8:for(let e=0;e<i;e++,n+=r)o[s+e]=xR(t,n,a);return;case 9:case 25:for(let e=0;e<i;e++,n+=r)o[s+e]=t.getFloat32(n,a);return;case 10:case 26:for(let e=0;e<i;e++,n+=r)o[s+e]=t.getFloat64(n,a);return;case hU:for(let e=0;e<i;e++,n+=r)o[s+e]=bU(t,n,a);return;default:o.fill(NaN,s,s+i)}}async function iU(e,t,n){let r=new Map,i=[],a=[],o=new Map,s=new Map,c=t??e,l=0,u=0;for(;l+28<=e.size&&u+28<=c.size;){let d=t?u:l,f=await c.read(d,28),p=TR(f);if(!(f[0]===84&&f[1]===68&&f[2]===83&&(f[3]===109||f[3]===104)))throw Error(`This TDMS file is damaged (no segment lead-in where one should be).`);let m=p.getUint32(4,!0),h=!(m&dU),g=xR(p,12,h),_=xR(p,20,h),v=g>=2**53?e.size:Math.min(e.size,l+28+g);if(_>v-l-28)throw Error(`This TDMS file is damaged (segment metadata longer than its segment).`);if(m&sU){let e=await c.read(d+28,_),t=TR(e);m&lU&&(a=[],o=new Map);let i=0,l=t.getUint32(i,h);i+=4;for(let c=0;c<l;c++){let c=t.getUint32(i,h),l=kR(e.subarray(i+4,i+4+c));i+=4+c;let u=eU(l),d=r.get(l);d||r.set(l,d={path:l,group:u?.[0]??``,name:u?.[1]??``,type:0,props:new Map,pieces:[],total:0});let f=t.getUint32(i,h);i+=4;let p=null;if(f===4294967295)p=null;else if(f===0)p=s.get(d)??null;else if(f===fU||f===pU){let e=xR(t,i+8,h),r=t.getUint32(i+16,h),a=f===fU?20:17,o=i+20,s=_U[t.getUint32(o,h)]??0,c=t.getUint32(o+8,h);i=o+r*a;let l=t.getUint32(i,h);i+=4;let u=0;for(let e=0;e<l;e++)u+=t.getUint32(i+4*e,h);i+=4*l,f===pU?n.push(`${d.name}: DAQmx digital line data is not supported; skipped.`):(r>1&&n.push(`${d.name}: only the first of its ${r} DAQmx scalers is read.`),p={type:s,count:e,bytes:0,daqmx:{byteOffset:c,stride:u}})}else{let e=t.getUint32(i,h),n=xR(t,i+8,h),r=e===mU?xR(t,i+16,h):n*(gU[e]??0);i+=f-4,p={type:e,count:n,bytes:r,daqmx:null}}p&&(d.type=p.type,s.set(d,p));let m=t.getUint32(i,h);i+=4;for(let n=0;n<m;n++){let n=t.getUint32(i,h),r=kR(e.subarray(i+4,i+4+n));i+=4+n;let a=t.getUint32(i,h);i+=4;let[o,s]=$H(t,e,i,a,h);d.props.set(r,o),i+=s}let g=o.get(d);g===void 0?o.set(d,a.push({obj:d,idx:p})-1):a[g].idx=p}}if(m&cU){let e=l+28+_,t=a.filter(e=>e.idx&&e.idx.count>0),n=t.filter(e=>e.idx.daqmx),r=(m&uU)!==0,o=0,s=0;n.length?(s=n[0].idx.daqmx.stride,o=n[0].idx.count*s):r?(s=t.reduce((e,t)=>e+(gU[t.idx.type]??0),0),o=(t[0]?.idx.count??0)*s):o=t.reduce((e,t)=>e+t.idx.bytes,0);let c=o>0?Math.floor((v-e)/o):0,u=i.push({rawStart:e,chunkSize:o,chunks:c,le:h})-1,d=0;for(let e of t){let t=e.idx,n=gU[t.type]??0,i=t.daqmx?{seg:u,count:t.count,offset:t.daqmx.byteOffset,bytes:0,stride:s,type:t.type}:{seg:u,count:t.count,offset:d,bytes:t.bytes,stride:r?s:n,type:t.type};t.daqmx||(d+=r?n:t.bytes),i.type===mU?i.count=Math.min(i.count,Math.floor(i.bytes/4)):n>0&&(i.count=Math.min(i.count,i.stride>0?Math.max(0,Math.floor((o-i.offset-n)/i.stride)+1):0)),e.obj.pieces.push(i),c&&(e.obj.total+=i.count*c)}}if(l=v,u+=28+_,v>=e.size)break}return{objs:[...r.values()],segments:i}}function aU(e,t,n,r,i,a){let o=0;for(;o<i&&r.pi<t.pieces.length;){let s=t.pieces[r.pi],c=e.segments[s.seg];if(r.chunk>=c.chunks){r.pi++,r.chunk=0,r.row=0;continue}let l=Math.min(i-o,s.count-r.row),u=c.rawStart+r.chunk*c.chunkSize+s.offset;if(s.type===mU)a.push({ch:n,at:u,end:u+s.bytes,rows:l,first:r.row,out:o,piece:s,le:c.le,range:0});else{let e=u+r.row*s.stride;a.push({ch:n,at:e,end:e+(l-1)*s.stride+gU[s.type],rows:l,first:r.row,out:o,piece:s,le:c.le,range:0})}o+=l,r.row+=l,r.row>=s.count&&(r.chunk++,r.row=0)}}async function*oU(e,t){let n=e.plan.state,r=n.groups[t],i=Xz(e,t).map(e=>r.channels[e]),a=r.time?[r.time,...i]:i;if(!a.length)return;let o=new Map(n.objs.map(e=>[e.path,e.props])),s=e=>o.get(e)??new Map,c=s(`/`),l=a.map(e=>nU([e.props,s(`/'${e.group.replace(/'/g,`''`)}'`),c],[],e.name)),u=a.map(()=>({pi:0,chunk:0,row:0})),d=a.reduce((e,t)=>Math.min(e,t.total),1/0);for(let i=0;i<d;){e.signal?.throwIfAborted();let o=Math.min(vU,d-i),s=[];a.forEach((e,t)=>aU(n,e,t,u[t],o,s));let c=s.slice().sort((e,t)=>e.at-t.at),f=[];for(let e of c){let t=f[f.length-1];t&&e.at<=t.end+yU&&Math.max(t.end,e.end)-t.at<=16777216?t.end=Math.max(t.end,e.end):f.push({at:e.at,end:e.end}),e.range=f.length-1}let p=[];for(let t of f)p.push(await e.io.slice(t.at,t.end-t.at));let m=p.map(TR),h=a.map(e=>e.type===mU?Array(o).fill(null):new Float64Array(o).fill(NaN));for(let e of s){let t=e.at-f[e.range].at,n=e.piece;if(n.type===mU){let r=p[e.range],i=m[e.range],a=t+4*n.count,o=h[e.ch];for(let n=0;n<e.rows;n++){let s=e.first+n,c=s===0?0:i.getUint32(t+4*(s-1),e.le),l=i.getUint32(t+4*s,e.le);o[e.out+n]=kR(r.subarray(a+c,a+l))}}else rU(n.type,m[e.range],t,n.stride,e.rows,e.le,h[e.ch],e.out)}for(let e=0;e<a.length;e++){let t=l[e],n=h[e];if(t&&n instanceof Float64Array)for(let e=0;e<o;e++)n[e]=t(n[e])}let g=null;if(r.time){g=h.shift();for(let e=0;e<o;e++)g[e]-=r.origin}yield{group:t,time:g,start:i,length:o,columns:h},i+=o}}var sU,cU,lU,uU,dU,fU,pU,mU,hU,gU,_U,vU,yU,bU,xU,SU,CU,wU=c((()=>{qz(),AR(),Zz(),RR(),sU=2,cU=8,lU=4,uU=32,dU=64,fU=4713,pU=4714,mU=32,hU=68,gU={1:1,2:2,3:4,4:8,5:1,6:2,7:4,8:8,9:4,10:8,25:4,26:8,33:1,68:16},_U={0:5,1:1,2:6,3:2,4:7,5:3,6:8,7:4,8:9,9:10,4294967295:hU},vU=65536,yU=65536,bU=(e,t,n)=>n?SR(e,t+8,n)+xR(e,t,n)/2**64:SR(e,t,n)+xR(e,t+8,n)/2**64,xU=4294967295,SU={1:Int8Array,2:Int16Array,3:Int32Array,5:Uint8Array,6:Uint16Array,7:Uint32Array,9:Float32Array,10:Float64Array,25:Float32Array,26:Float64Array,33:Uint8Array},CU={...LR,async plan(e,t){let n=e.companions.find(e=>e.name.toLowerCase().endsWith(`.tdms_index`)),r=[],{objs:i,segments:a}=await iU(t,n?new Kz(n):null,r),o=i.find(e=>e.path===`/`)?.props,s=i.filter(e=>e.name&&e.total>0&&(e.type===mU||gU[e.type])),c=new Set(s);for(let e of i)e.name&&e.total>0&&!c.has(e)&&r.push(`${e.name}: TDMS data type ${e.type} is not supported; skipped.`);let l=s.map(e=>e.props.get(`wf_start_time`)).filter(e=>typeof e==`number`),u=l.reduce((e,t)=>Math.min(e,t),l.length?1/0:0),d=new Map;for(let e of s){let t=`${e.total}|${e.props.get(`wf_increment`)??``}`,n=d.get(e.group)??new Map,r=n.get(t);r?r.push(e):n.set(t,[e]),d.set(e.group,n)}let f=[],p=[];for(let[e,t]of d)for(let n of t.values()){let r=n[0].props.get(`wf_increment`),i=typeof r==`number`&&r>0?1/r:null,a=i?null:n.find(e=>e.type===hU)??n.find(e=>e.type!==mU&&/^(time|timestamp|t)$/i.test(e.name))??null,o=n.filter(e=>e!==a),s=n[0].props.get(`wf_start_time`),c=i?Number(n[0].props.get(`wf_start_offset`)??0)+(typeof s==`number`?s-u:0):0;f.push({name:t.size===1?e:`${e} (${i?+i.toFixed(6):n[0].total} ${i?`Hz`:`samples`})`,channels:o.map(e=>({name:e.name,unit:String(e.props.get(`unit_string`)??``),text:e.type===mU})),samples:n[0].total,time:i?{kind:`rate`,rate:i,start:c}:a?{kind:`timestamps`}:{kind:`index`},rateHz:i}),p.push({channels:o,time:a,origin:0})}if(f.length===0)throw Error(`This TDMS file has no channels with data.`);let m=[];for(let e of p){if(!e.time)continue;let n=e.time.pieces[0],r=a[n.seg],i=await t.read(r.rawStart+n.offset,gU[n.type]??8),o=new Float64Array(1);rU(n.type,TR(i),0,0,1,r.le,o,0),m.push(o[0])}let h=m.reduce((e,t)=>Math.min(e,t),m.length?1/0:0);for(let e of p)e.origin=h;let g=new Date(Date.UTC(1904,0,1)+u*1e3),_=u&&Number.isFinite(g.getTime())?g.toISOString():null,v={objs:i,segments:a,groups:p},y={};for(let[e,t]of o??[])typeof t==`string`&&(y[e]=t);return{format:`TDMS`,startTime:_,groups:f,meta:y,events:[],notes:r,state:v}},async*stream(e){for(let t of e.selection)yield*oU(e,t.group)},streamGroup:(e,t)=>oU(e,t)}}));function TU(){let e=new Set,t=0,n=!1;return{enter(t){let r=null;try{r=t.create_reference?Array.prototype.join.call(t.create_reference().ref_data,`,`):null}catch{r=null}return r===null?!0:e.has(r)?(n=!0,!1):(e.add(r),!0)},count:()=>++t<=PU,note:()=>t>1e5?`This file has more than ${PU.toLocaleString(`en-US`)} objects (or links that repeat its groups); only the first were read.`:n?`Some groups of this file link back to a group already read; each was read once.`:null}}function EU(e,t,n,r){return t.reduce((e,t)=>e*t,1)*Math.max(1,e.metadata.size||1)>(r?n*1032+1024:n)}function DU(){!IU||LU||(LU=IU(),LU.catch(()=>{LU=null}))}function OU(e){if(!IU)return Promise.reject(Error(`HDF5 and MAT 7.3 files are read in the import worker, and this environment has no workers.`));DU();let t=RU.get(e);return t||(t=LU.then(t=>t(e)).then(e=>({root:e.root,close:()=>{}})),RU.set(e,t),t.catch(()=>RU.delete(e))),t}function kU(e,t,n){let r=zU.get(e);r||zU.set(e,r=new Map);let i=r.get(t);return i||r.set(t,i=n??e.get(t)),i}function AU(e){return e instanceof Float64Array?e:e instanceof BigInt64Array||e instanceof BigUint64Array?Float64Array.from(e,e=>Number(e)):ArrayBuffer.isView(e)?new Float64Array(e):Float64Array.from(e)}function jU(e,...t){for(let n of t){let t=e[n]?.value;if(typeof t==`string`)return t;if(Array.isArray(t)&&typeof t[0]==`string`)return t[0]}return``}function MU(e,...t){for(let n of t){let t=e[n]?.value,r=typeof t==`number`?t:ArrayBuffer.isView(t)?Number(t[0]):NaN;if(Number.isFinite(r))return r}return null}var NU,PU,FU,IU,LU,RU,zU,BU,VU=c((()=>{NU=e=>!!e&&typeof e.keys==`function`,PU=1e5,FU=e=>!!e&&typeof e.slice==`function`,IU=null,LU=null,RU=new WeakMap,zU=new WeakMap,BU={s:1,sec:1,second:1,seconds:1,ms:.001,msec:.001,us:1e-6,µs:1e-6,ns:1e-9}}));function HU(e,t,n,r,i,a,o=0){i.set(n,t.attrs);for(let s of t.keys()){if(!a.count())return;let c=n===`/`?`/${s}`:`${n}/${s}`,l=t.get(s);if(NU(l))o<16&&a.enter(l)&&HU(e,l,c,r,i,a,o+1);else if(FU(l)){let t=kU(e,c,l);r.push({path:c,parent:n,name:s,ds:t,attrs:t.attrs})}}}async function UU(e,t){let n=kU(e,t.path);if(t.col===null)return AU(n.slice([[0,1]]))[0]*t.factor;let r=n.slice([[0,1]]);return Number(r[0][t.col])*t.factor}async function*WU(e,t){let n=e.plan.state.groups[t],r=Xz(e,t).map(e=>n.cols[e]),i=await OU(e.files.main);try{let a=n.chunk??0,o=a>0?Math.max(1,Math.min(Math.floor((1<<20)/a),Math.ceil($U(r.length+1)/a)))*a:$U(r.length+1);for(let a=0;a<n.rows;a+=o){e.signal?.throwIfAborted();let s=Math.min(n.rows,a+o),c=s-a,l=null,u=e=>{let t=kU(i.root,e.path);if(n.kind===`vectors`){let n=t.slice([[a,s]]);if(e.text)return Array.from(n,e=>e==null?null:String(e));let r=AU(n);if(e.factor!==1)for(let t=0;t<c;t++)r[t]*=e.factor;return r}let r=new Float64Array(c);if(n.kind===`matrix`){let n=(t.shape??[0,1])[1],i=l??=t.slice([[a,s],[0,n]]);for(let t=0;t<c;t++)r[t]=Number(i[t*n+e.col])}else{let n=l??=t.slice([[a,s]]);for(let t=0;t<c;t++)r[t]=Number(n[t][e.col])*e.factor}return r},d=null;if(n.time){d=u(n.time);for(let e=0;e<c;e++)d[e]-=n.origin}yield{group:t,time:d,start:a,length:c,columns:r.map(u)}}}finally{i.close()}}var GU,KU,qU,JU,YU,XU,ZU,QU,$U,eW,tW=c((()=>{Zz(),WR(),VU(),GU=0,KU=1,qU=3,JU=6,YU=new Set([1,2,3,4,5,6]),XU=/^(time|t|timestamps?|.*[_ ]time|time[_ ].*)$/i,ZU=[`sampling_rate`,`sample_rate`,`samplerate`,`sampleRate`,`fs`,`Fs`,`rate`],QU=e=>e===`/`?`root`:e.slice(1),$U=e=>Math.max(4096,Math.min(1<<20,Math.floor((8<<20)/(8*Math.max(1,e))))),eW={...UR,async plan(e){let t=await OU(e.main);try{let n=[],r=new Map,i=TU();i.enter(t.root),HU(t.root,t.root,`/`,n,r,i);let a=[],o=i.note();o&&a.push(o);let s=new Map,c=[],l=0;for(let t of n){let n=t.ds.metadata.shape??[],r=t.ds.metadata.type,i=t.ds.metadata.chunks?t.ds.filters??[]:[],o=i.find(e=>!YU.has(e.id)),u=!o;if(u&&i.length>0&&n.length>0&&n.every(e=>e>0))try{t.ds.slice(n.map(()=>[0,1]))}catch{u=!1}if(!u){a.push(`${t.path}: compressed with a filter Kymoscope cannot read${o?` (${o.name||o.id})`:``}; skipped.`);continue}if(EU(t.ds,n,e.main.size,i.length>0)){a.push(`${t.path}: larger than the file can hold (never written, or damaged); skipped.`);continue}if(n.length===1&&n[0]>1&&(r===GU||r===KU||r===qU)){let e=`${t.parent}|${n[0]}`,r=s.get(e)??{parent:t.parent,n:n[0],leaves:[]};r.leaves.push(t),s.set(e,r)}else if(n.length===2&&n[0]>1&&n[1]<=4096&&(r===GU||r===KU)){let e=MU(t.attrs,...ZU);c.push({name:QU(t.path),kind:`matrix`,rows:n[0],rate:e,time:null,origin:0,cols:Array.from({length:n[1]},(e,n)=>({path:t.path,col:n,text:!1,factor:1}))})}else if(n.length===1&&r===JU){let e=(t.ds.metadata.compound_type?.members??[]).flatMap((e,n)=>e.type===GU||e.type===KU?[{path:t.path,col:n,text:!1,factor:1,name:e.name}]:[]),r=e.find(e=>XU.test(e.name));c.push({name:QU(t.path),kind:`compound`,rows:n[0],rate:null,origin:0,time:r??null,cols:e.filter(e=>e!==r)})}else l++}for(let e of s.values()){let t=[...s.values()].filter(t=>t.parent===e.parent).length>1,n=e.leaves.find(e=>jU(e.attrs,`CLASS`)===`DIMENSION_SCALE`)??e.leaves.find(e=>XU.test(e.name)&&e.ds.metadata.type!==qU),i=n?BU[jU(n.attrs,`units`,`unit`,`Units`)]??1:1,a=n?null:MU(r.get(e.parent)??{},...ZU);c.push({name:t?`${QU(e.parent)} (${e.n} rows)`:QU(e.parent),kind:`vectors`,rows:e.n,rate:a,origin:0,time:n?{path:n.path,col:null,text:!1,factor:i}:null,cols:e.leaves.filter(e=>e!==n).map(e=>({path:e.path,col:null,text:e.ds.metadata.type===qU,factor:1}))})}l&&a.push(`${l} dataset${l===1?``:`s`} with other shapes or types (images, references, 3-D) skipped.`),c.sort((e,t)=>e.name.localeCompare(t.name));let u=c.map((e,t)=>e.time||e.rate?t:-1).filter(e=>e>=0),d=1/0;for(let e of c)e.time&&(d=Math.min(d,await UU(t.root,e.time)));for(let e of c)e.origin=Number.isFinite(d)?d:0;let f=new Map(n.map(e=>[e.path,e]));for(let e of c)e.chunk=[...e.cols,...e.time?[e.time]:[]].reduce((e,t)=>Math.max(e,f.get(t.path).ds.metadata.chunks?.[0]??0),0);let p=e=>jU(f.get(e.path).attrs,`units`,`unit`,`Units`,`UNITS`),m=(e,t)=>e.kind===`matrix`?`${e.name.split(`/`).pop()}[${t.col+1}]`:e.kind===`compound`?f.get(t.path).ds.metadata.compound_type.members[t.col].name:t.path.split(`/`).pop(),h=c.map(e=>({name:e.name,channels:e.cols.map(t=>({name:m(e,t),unit:e.kind===`vectors`?p(t):``,text:t.text})),samples:e.rows,time:e.time?{kind:`timestamps`}:e.rate?{kind:`rate`,rate:e.rate,start:0}:{kind:`index`},rateHz:e.rate}));if(h.length===0)throw Error(`This HDF5 file has no datasets Kymoscope can plot.`);let g=h.length>20||h.length>1&&u.length<h.length,_=g?u.length?u:[c.reduce((e,t,n)=>t.rows*t.cols.length>c[e].rows*c[e].cols.length?n:e,0)]:void 0;return g&&a.push(`Only the groups with a time base are read unless you choose others in the channel picker.`),{format:`HDF5`,startTime:null,groups:h,meta:{},events:[],notes:a,pick:g,defaultGroups:_,state:{groups:c}}}finally{t.close()}},async*stream(e){for(let t of e.selection)yield*WU(e,t.group)},streamGroup:(e,t)=>WU(e,t)}}));function nW(e,t){let n=/^(.*)\.values(\[\d+\])?$/.exec(e.name),r=n&&(t.get(`${n[1]}.label`)||t.get(`${n[1]}.blockName`));return r?{...e,name:`${r}${n[2]??``}`}:e}function rW(e,t,n){let r=new Map;for(let t of e){if(!(t.length>1))continue;let e=r.get(t.length);e?e.push(t):r.set(t.length,[t])}let i=[...n].filter(([e])=>sW.test(cW(e))),a=i.length===1?i[0][1]:null,o=[];for(let[e,n]of r){let r=n.find(e=>oW.test(cW(e.name))||/(_time|\.Time)$/.test(e.name))??null;o.push({name:r?lW(r.name)||r.name:`${e} samples`,channels:n.filter(e=>e!==r).map(e=>nW(e,t)),time:r,rate:r?null:a,origin:0})}return o}function iW(e){return e.map(e=>({name:e.name,channels:e.channels.map(e=>({name:e.name,unit:``})),samples:e.channels[0]?.length??e.time?.length??0,time:e.time?{kind:`timestamps`}:e.rate?{kind:`rate`,rate:e.rate,start:0}:{kind:`index`},rateHz:e.rate}))}async function aW(e){let t=1/0;for(let n of e)n.time&&(t=Math.min(t,(await n.time.read(0,1))[0]));for(let n of e)n.origin=Number.isFinite(t)?t:0}var oW,sW,cW,lW,uW=c((()=>{oW=/^(time|t|tout|timestamps?)$/i,sW=/^(fs|sample_?rate|sampling_?rate|rate|samplerate)$/i,cW=e=>e.slice(e.lastIndexOf(`.`)+1),lW=e=>e.includes(`.`)?e.slice(0,e.lastIndexOf(`.`)):``}));function dW(e,t,n,r,i=1){let a=TR(t),o=r.length,s=vW[e]*i;if(e===9&&i===1&&n){r.set(t.byteOffset%8==0?new Float64Array(t.buffer,t.byteOffset,o):new Float64Array(t.slice(0,o*8).buffer));return}switch(e){case 1:for(let e=0,t=0;e<o;e++,t+=s)r[e]=a.getInt8(t);return;case 2:for(let e=0,t=0;e<o;e++,t+=s)r[e]=a.getUint8(t);return;case 3:for(let e=0,t=0;e<o;e++,t+=s)r[e]=a.getInt16(t,n);return;case 4:for(let e=0,t=0;e<o;e++,t+=s)r[e]=a.getUint16(t,n);return;case 5:for(let e=0,t=0;e<o;e++,t+=s)r[e]=a.getInt32(t,n);return;case 6:for(let e=0,t=0;e<o;e++,t+=s)r[e]=a.getUint32(t,n);return;case 7:for(let e=0,t=0;e<o;e++,t+=s)r[e]=a.getFloat32(t,n);return;case 9:for(let e=0,t=0;e<o;e++,t+=s)r[e]=a.getFloat64(t,n);return;case 12:for(let e=0,t=0;e<o;e++,t+=s)r[e]=a.getInt32(t+(n?4:0),n)*4294967296+a.getUint32(t+(n?0:4),n);return;case 13:for(let e=0,t=0;e<o;e++,t+=s)r[e]=a.getUint32(t+(n?4:0),n)*4294967296+a.getUint32(t+(n?0:4),n);return;default:r.fill(NaN)}}async function fW(e,t,n){let r=TR(await e.read(t,8)),i=r.getUint32(0,n);if(i>>>16)return{type:i&65535,bytes:i>>>16,data:t+4,next:t+8};let a=r.getUint32(4,n);return{type:i,bytes:a,data:t+8,next:i===15?t+8+a:t+8+a+(8-a%8)%8}}function pW(e,t,n,r,i){let[a,o]=t,s=vW[r.type];if(!s)return[];let c=(e,t)=>async(a,o)=>{let c=new Float64Array(o-a);return t===1?dW(r.type,await n.read(r.data+(e+a)*s,(o-a)*s),i,c):dW(r.type,await n.read(r.data+(e+a*t)*s,((o-a-1)*t+1)*s),i,c,t),c};return a===1||o===1?[{name:e,length:a*o,read:c(0,1)}]:a>=o?Array.from({length:o},(t,n)=>({name:`${e}[${n+1}]`,length:a,read:c(n*a,1)})):Array.from({length:a},(t,n)=>({name:`${e}[${n+1}]`,length:o,read:c(n,a)}))}async function mW(e,t,n,r,i,a,o){let s=t,c=await fW(e,s,n),l=TR(await e.read(c.data,8)).getUint32(0,n),u=l&255;s=c.next;let d=await fW(e,s,n);if(d.bytes>128){a.notes.push(`A MAT variable with more than 32 dimensions was skipped (damaged).`);return}let f=TR(await e.read(d.data,d.bytes)),p=Array.from({length:d.bytes/4},(e,t)=>f.getInt32(4*t,n));s=d.next;let m=await fW(e,s,n),h=OR(await e.read(m.data,m.bytes));s=m.next;let g=i??h,_=r?`${r}.${g}`:g,v=p.reduce((e,t)=>e*t,1);if(u>=6&&u<=15){if(v===0)return;let t=await fW(e,s,n);if(l&2048&&a.notes.push(`${_}: the imaginary part was skipped.`),p.length>2){a.notes.push(`${_}: arrays with more than two dimensions are skipped.`);return}if(!vW[t.type])return;if(!(v>0)||v*vW[t.type]>t.bytes||t.data+t.bytes>e.size){a.notes.push(`${_}: its data is shorter than its dimensions (damaged); skipped.`);return}if(v===1){let r=new Float64Array(1);dW(t.type,await e.read(t.data,vW[t.type]??8),n,r),a.scalars.set(_,r[0]);return}a.channels.push(...pW(_,p,e,t,n));return}if(u===4){let t=await fW(e,s,n);if(t.bytes>yW)return;let r=await e.read(t.data,t.bytes),i=t.type===3||t.type===4||t.type===17?new TextDecoder(n?`utf-16le`:`utf-16be`).decode(r.subarray(0,r.length&-2)):kR(r);p[0]<=1&&a.strings.set(_,i);return}if(u===2){let t=await fW(e,s,n),r=TR(await e.read(t.data,4)).getInt32(0,n);s=t.next;let i=await fW(e,s,n);if(!(r>0))return;let c=await e.read(i.data,i.bytes),l=Array.from({length:Math.floor(c.length/r)},(e,t)=>CR(c.subarray(t*r,(t+1)*r)));if(s=i.next,l.length===0||v*l.length*8>e.size-s){v>0&&l.length>0&&a.notes.push(`${_}: its fields are longer than the file (damaged); skipped.`);return}for(let t=0;t<v;t++){let r=v>1?`${_}(${t+1})`:_;for(let t of l){let i=await fW(e,s,n);i.type===14&&i.bytes>0&&o<16&&await mW(e,i.data,n,r,t,a,o+1),s=i.next}}return}u===1?a.notes.push(`${_}: cell arrays are skipped.`):u===5?a.notes.push(`${_}: sparse arrays are skipped.`):a.notes.includes(bW)||a.notes.push(bW)}async function hW(e){let t=OR((await e.read(0,128)).subarray(126,128))===`IM`,n={channels:[],strings:new Map,scalars:new Map,notes:[],sources:[]},r=new gW(e),i=0;for(let a=128;a+8<=e.size;){let o=await fW(r,a,t);if(o.type===15){if(o.bytes>1<<30)throw Error(`A compressed variable in this MAT file is over 1 GB; save it with -v7.3 to open it here.`);let r=await e.slice(o.data,o.bytes),a=await EV(r,-1,8),s=a.length<8?0:8+TR(a).getUint32(4,t);if(s>lz(o.bytes))throw Error(`A compressed variable in this MAT file is damaged.`);if(s>1<<30)throw Error(`A compressed variable in this MAT file is over 1 GB; save it with -v7.3 to open it here.`);let c=await EV(r,s,s),l=new _W(e,o.data,o.bytes,c);n.sources.push(l),i+=c.length;let u=await fW(l,0,t);if(u.type===14&&await mW(l,u.data,t,``,null,n,0),i>xW)for(let e of n.sources)e.keep=!1,e.release()}else o.type===14&&await mW(r,o.data,t,``,null,n,0);a=o.next}return n}var gW,_W,vW,yW,bW,xW,SW=c((()=>{AR(),gz(),kV(),gW=class{#e;size;constructor(e){this.#e=e,this.size=e.size}read(e,t){return t>=65536?this.#e.slice(e,t):this.#e.read(e,t)}release(){}},_W=class{#e;#t;#n;#r=null;keep=!0;size;constructor(e,t,n,r){this.#e=e,this.#t=t,this.#n=n,this.#r=r,this.size=r.length}async read(e,t){return this.#r??=await EV(await this.#e.slice(this.#t,this.#n),this.size,this.size),this.#r.subarray(e,e+t)}release(){this.keep||(this.#r=null)}},vW={1:1,2:1,3:2,4:2,5:4,6:4,7:4,9:8,12:8,13:8},yW=1<<17,bW=`MATLAB objects (timeseries, SimulationOutput) were skipped: save them as 'Structure with time' or as structs.`,xW=512<<20}));function CW(e,t){let n={channels:[],strings:new Map,scalars:new Map,notes:[]},r=TU();r.enter(e);let i=t=>kU(e,t),a=(e,t,n)=>{let r=null;return(a,o)=>((r?.s!==a||r.e!==o)&&(r={s:a,e:o,v:AU(t?i(e).slice([[0,n],[a,o]]):i(e).slice([[a,o],[0,n]]))}),r.v)},o=(e,s,c,l)=>{for(let u of e.keys()){if(!r.count())return;if(u.startsWith(`#`))continue;let d=e.get(u);if(!d)continue;let f=`${s}/${u}`,p=c?`${c}.${u}`:u,m=d.attrs,h=jU(m,`MATLAB_class`);if(m.MATLAB_empty)continue;if(NU(d)){h===`struct`&&l<16&&r.enter(d)&&o(d,f,p,l+1);continue}if(!FU(d))continue;let g=d.shape??[];if(h===`char`){if(g.reduce((e,t)=>e*t,1)>wW)continue;let e=AU(d.slice(g.map(e=>[0,e])));n.strings.set(p,new TextDecoder(`utf-16le`).decode(Uint16Array.from(e)))}else if(TW.has(h)&&g.length===2&&EU(d,g,t,!!d.metadata.chunks))n.notes.push(`${p}: larger than the file can hold (never written, or damaged); skipped.`);else if(TW.has(h)&&g.length===2){let[e,t]=g;if(e*t===1){n.scalars.set(p,AU(i(f).slice([[0,1],[0,1]]))[0]);continue}if(e===1||t===1){let r=e*t;n.channels.push({name:p,length:r,read:async(t,n)=>AU(e===1?i(f).slice([[0,1],[t,n]]):i(f).slice([[t,n],[0,1]]))})}else if(t>=e){let r=a(f,!0,e);for(let i=0;i<e;i++)n.channels.push({name:`${p}[${i+1}]`,length:t,read:async(e,t)=>r(e,t).slice(i*(t-e),(i+1)*(t-e))})}else{let r=a(f,!1,t);for(let i=0;i<t;i++)n.channels.push({name:`${p}[${i+1}]`,length:e,read:async(e,n)=>{let a=r(e,n),o=new Float64Array(n-e);for(let e=0;e<o.length;e++)o[e]=a[e*t+i];return o}})}}else h===`cell`?n.notes.push(`${p}: cell arrays are skipped.`):h&&n.notes.push(`${p}: MATLAB class ${h} is skipped.`)}};o(e,``,``,0);let s=r.note();return s&&n.notes.push(s),n}var wW,TW,EW=c((()=>{VU(),wW=65536,TW=new Set([`double`,`single`,`int8`,`uint8`,`int16`,`uint16`,`int32`,`uint32`,`int64`,`uint64`,`logical`])}));async function*DW(e,t){let n=e.plan.state,r=n.groups[t],i=Xz(e,t).map(e=>r.channels[e]),a=r.channels[0].length,o=OW(i.length+1);try{for(let n=0;n<a;n+=o){e.signal?.throwIfAborted();let s=Math.min(a,n+o),c=null;if(r.time){c=await r.time.read(n,s);for(let e=0;e<c.length;e++)c[e]-=r.origin}let l=[];for(let e of i)l.push(await e.read(n,s));yield{group:t,time:c,start:n,length:s-n,columns:l}}}finally{for(let e of n.sources)e.release()}}var OW,kW,AW=c((()=>{AR(),VU(),Zz(),BR(),uW(),SW(),EW(),OW=e=>Math.max(4096,Math.min(1<<18,Math.floor((16<<20)/(8*Math.max(1,e))))),kW={...zR,async plan(e,t){let n=wR(await t.read(0,20),`MATLAB 7.3`),r,i=[];if(n)r=CW((await OU(e.main)).root,e.main.size);else{let e=await hW(t);i=e.sources,r=e}let a=rW(r.channels,r.strings,r.scalars).filter(e=>e.channels.length>0);await aW(a);let o=iW(a);if(o.length===0)throw Error(`This MAT file has no numeric vectors or matrices to plot.`);let s=o.flatMap((e,t)=>e.time.kind===`index`?[]:[t]),c=o.length>1&&s.length<o.length,l=Object.fromEntries(r.strings);for(let[e,t]of r.scalars)l[e]=String(t);return{format:n?`MAT 7.3`:`MAT 5`,startTime:null,groups:o,meta:l,events:[],notes:r.notes,pick:c,defaultGroups:c&&s.length?s:void 0,state:{groups:a,sources:i}}},async*stream(e){for(let t of e.selection)yield*DW(e,t.group)},streamGroup:(e,t)=>DW(e,t)}}));function jW(e,t){let n=/^\s*(\d{1,2})\/(\d{1,2})\/(\d{2,4})\s*,\s*(\d{1,2}):(\d{2}):(\d{2})(?:\.(\d+))?/.exec(e??``);if(!n)return[null,0,!1];let[r,i]=t===1991?[n[2],n[1]]:[n[1],n[2]],a=n[3].length===2?2e3+Number(n[3]):Number(n[3]),o=Number(`${n[6]}.${n[7]??`0`}`);return[`${a}-${i.padStart(2,`0`)}-${r.padStart(2,`0`)}T${n[4].padStart(2,`0`)}:${n[5]}:${o.toFixed(3).padStart(6,`0`)}`,Date.UTC(a,Number(i)-1,Number(r),Number(n[4]),Number(n[5]))/1e3+o,(n[7]??``).length>6]}function MW(e){let t=e.split(/\r?\n/).map(e=>e.trim()),[n,,r]=t[0].split(`,`),i=Number(r)||1991,a=/(\d+)A\s*,\s*(\d+)D/i.exec(t[1]??``);if(!a)throw Error(`This COMTRADE .cfg is damaged (second line).`);let o=Number(a[1]),s=Number(a[2]);if(o+s>t.length)throw Error(`This COMTRADE .cfg is damaged (more channels than lines).`);let c=2,l=[];for(let e=0;e<o;e++,c++){let e=(t[c]??``).split(`,`);l.push({name:(e[1]??``).trim(),unit:(e[4]??``).trim(),a:Number(e[5]),b:Number(e[6]??0)||0})}let u=[];for(let e=0;e<s;e++,c++)u.push(((t[c]??``).split(`,`)[1]??``).trim());c++;let d=Number(t[c++]);if(!(Number.isInteger(d)&&d>=0&&d<=t.length-c))throw Error(`This COMTRADE .cfg is damaged (sample rates).`);let f=[];for(let e=0;e<Math.max(1,d);e++,c++){let[e,n]=(t[c]??``).split(`,`).map(Number);f.push([d===0?0:e,n])}let[p,m,h]=jW(t[c++],i),[g,_,v]=jW(t[c++],i),y=(t[c++]||`ASCII`).toUpperCase(),b=Number(t[c++])||1;return{station:n.trim(),rev:i,analog:l,digital:u,rates:f,start:p,trigger:g,startSec:m,triggerSec:_,ft:y,timemult:b,timebase:h||v?1e-9:1e-6}}async function NW(e){let t=OR(await e.read(0,Math.min(e.size,1<<20))),n=t.search(/---\s*file type:\s*CFG\s*---\r?\n/i),r=/---\s*file type:\s*DAT\s+(ASCII|BINARY32|BINARY|FLOAT32)(?:\s*:\s*(\d+))?\s*---\r?\n/i.exec(t);if(n<0||!r)throw Error(`This COMTRADE .cff is damaged (no CFG or DAT section in its first megabyte).`);let i=t.indexOf(`
|
|
79
79
|
`,n)+1,a=t.slice(i).search(/---\s*file type:\s*(INF|HDR|DAT)/i),o=t.slice(i,a<0?void 0:i+a),s=r.index+r[0].length;return{cfg:o,offset:s,length:r[2]?Number(r[2]):e.size-s}}function PW(e,t,n,r){let i=0,a=0,o=t,s=0;for(let[t,c]of e){for(;o<c&&s<n;)r[s++]=a+(o-i)/t,o++;if(a+=(c-i)/t,i=c,s>=n)return}let c=e[e.length-1];for(;s<n;s++,o++)r[s]=a+(o-i)/c[0]}async function*FW(e){let t=e.plan.state,{cfg:n}=t,r=t.data===`self`?e.io:new Kz(RW(e.files)),i=Xz(e,0),a=n.analog.length,o=n.rates[0][0]>0,s=n.timemult*n.timebase,c=65536,l=0,u=(e,t,r)=>{let i=new Float64Array(e);if(o)PW(n.rates,l,e,i);else for(let n=0;n<e;n++)i[n]=t[n]*s;let a={group:0,time:i,start:l,length:e,columns:r};return l+=e,a};if(n.ft===`ASCII`){let o=n.rev>=1999?`99999`:``,s=i.map(e=>e<a?n.analog[e]:null),l=new Float64Array(c),d=i.map(()=>new Float64Array(c)),f=0,p=(e,t,n)=>{let r=e.slice(t,n).split(`,`);if(!(r.length<2)){l[f]=Number(r[1]);for(let e=0;e<i.length;e++){let t=(r[2+i[e]]??``).trim(),n=s[e];d[e][f]=t===``||n&&t===o?NaN:n?n.a*Number(t)+n.b:Number(t)}f++}},m=``,h=new TextDecoder(`latin1`);for await(let n of r.windows(t.offset,t.length)){e.signal?.throwIfAborted();let t=m+h.decode(n.bytes),r=0;for(let e=t.indexOf(`
|
|
80
80
|
`,r);e>=0;e=t.indexOf(`
|
|
81
|
-
`,r))p(t,r,e),r=e+1,f===c&&(yield u(f,l,d),l=new Float64Array(c),d=i.map(()=>new Float64Array(c)),f=0);m=t.slice(r)}m.trim()&&p(m,0,m.length),f&&(yield u(f,l.slice(0,f),d.map(e=>e.slice(0,f))));return}let d=t.recordSize,f=IW[n.ft],p=Math.max(1,Math.floor(Math.min(Gz,c*d)/d)),m=t.samples;for await(let s of r.windows(t.offset,Math.min(t.length,t.samples*d),p*d)){e.signal?.throwIfAborted();let t=Math.min(m,Math.floor(s.bytes.length/d));if(t<=0)break;let r=TR(s.bytes),c=new Float64Array(t);if(!o)for(let e=0;e<t;e++)c[e]=r.getUint32(e*d+4,!0);yield u(t,c,i.map(e=>{let i=new Float64Array(t);if(e<a){let{a,b:o}=n.analog[e],s=8+e*f;if(n.ft===`BINARY`)for(let e=0,n=s;e<t;e++,n+=d){let t=r.getInt16(n,!0);i[e]=t===-32768?NaN:a*t+o}else if(n.ft===`BINARY32`)for(let e=0,n=s;e<t;e++,n+=d){let t=r.getInt32(n,!0);i[e]=t===-2147483648?NaN:a*t+o}else for(let e=0,n=s;e<t;e++,n+=d)i[e]=a*r.getFloat32(n,!0)+o}else{let n=e-a,o=8+a*f+2*(n>>4),s=1<<(n&15);for(let e=0,n=o;e<t;e++,n+=d)i[e]=r.getUint16(n,!0)&s?1:0}return i})),m-=t}}var IW,LW,RW,zW,BW=c((()=>{qz(),AR(),Zz(),KR(),IW={BINARY:2,BINARY32:4,FLOAT32:4},LW=16<<20,RW=e=>e.companions.find(e=>e.name.toLowerCase().endsWith(`.dat`)),zW={...GR,async plan(e,t){let n=e.main.name.toLowerCase().endsWith(`.cff`),r,i;if(n){let e=await NW(t);r=e.cfg,i={data:`self`,offset:e.offset,length:e.length}}else{let n=RW(e);if(!n)throw Error(`This COMTRADE .cfg needs its .dat file: drop both together.`);if(t.size>LW)throw Error(`This .cfg is too large to be a COMTRADE configuration file.`);r=OR(await t.read(0,t.size)),i={data:`companion`,offset:0,length:n.size}}let a=MW(r);if(a.ft!==`ASCII`&&!IW[a.ft])throw Error(`This COMTRADE file has data file type ${a.ft}, which Kymoscope cannot read.`);let o=Math.ceil(a.digital.length/16),s=a.ft===`ASCII`?0:8+a.analog.length*IW[a.ft]+2*o,c=s?Math.floor(i.length/s):i.length,l=Math.min(a.rates[a.rates.length-1][1]||(s?c:-1),c),u=a.rates.length===1&&a.rates[0][0]>0?a.rates[0][0]:null,d=[`Analog values are shown as recorded (primary or secondary, per the CFG).`];return{format:`COMTRADE ${a.rev} (${a.ft})`,startTime:a.start,meta:{station:a.station,trigger:a.trigger??``},groups:[{name:a.station||`COMTRADE`,channels:[...a.analog.map(e=>({name:e.name,unit:e.unit})),...a.digital.map(e=>({name:e,unit:``}))],samples:l,time:{kind:`timestamps`},rateHz:u}],events:a.start&&a.trigger?[{time:Math.round((a.triggerSec-a.startSec)*1e6)/1e6,text:`Trigger`}]:[],notes:d,state:{...i,cfg:a,samples:l,recordSize:s}}},stream:e=>FW(e)}}));function VW(e,t,n){let r=t,i=r+n,a=[],o=``;for(;r<i;){let t=e[r++];if(!(t&128))a.push(t);else if((t&224)==192){let n=e[r++]&63;a.push((t&31)<<6|n)}else if((t&240)==224){let n=e[r++]&63,i=e[r++]&63;a.push((t&31)<<12|n<<6|i)}else if((t&248)==240){let n=e[r++]&63,i=e[r++]&63,o=e[r++]&63,s=(t&7)<<18|n<<12|i<<6|o;s>65535&&(s-=65536,a.push(s>>>10&1023|55296),s=56320|s&1023),a.push(s)}else a.push(t);a.length>=WW&&(o+=String.fromCharCode(...a),a.length=0)}return a.length>0&&(o+=String.fromCharCode(...a)),o}function HW(e,t,n){let r=e.subarray(t,t+n);return GW.decode(r)}function UW(e,t,n){return n>KW?HW(e,t,n):VW(e,t,n)}var WW,GW,KW,qW=c((()=>{new TextEncoder,WW=4096,GW=new TextDecoder,KW=200})),JW,YW=c((()=>{JW=class{type;data;constructor(e,t){this.type=e,this.data=t}}})),XW,ZW=c((()=>{XW=class e extends Error{constructor(t){super(t);let n=Object.create(e.prototype);Object.setPrototypeOf(this,n),Object.defineProperty(this,`name`,{configurable:!0,enumerable:!1,value:e.name})}}}));function QW(e,t,n){let r=Math.floor(n/4294967296),i=n;e.setUint32(t,r),e.setUint32(t+4,i)}function $W(e,t){let n=e.getInt32(t),r=e.getUint32(t+4);return n*4294967296+r}function eG(e,t){let n=e.getUint32(t),r=e.getUint32(t+4);return n*4294967296+r}var tG=c((()=>{}));function nG({sec:e,nsec:t}){if(e>=0&&t>=0&&e<=cG)if(t===0&&e<=sG){let t=new Uint8Array(4);return new DataView(t.buffer).setUint32(0,e),t}else{let n=e/4294967296,r=e&4294967295,i=new Uint8Array(8),a=new DataView(i.buffer);return a.setUint32(0,t<<2|n&3),a.setUint32(4,r),i}else{let n=new Uint8Array(12),r=new DataView(n.buffer);return r.setUint32(0,t),QW(r,4,e),n}}function rG(e){let t=e.getTime(),n=Math.floor(t/1e3),r=(t-n*1e3)*1e6,i=Math.floor(r/1e9);return{sec:n+i,nsec:r-i*1e9}}function iG(e){return e instanceof Date?nG(rG(e)):null}function aG(e){let t=new DataView(e.buffer,e.byteOffset,e.byteLength);switch(e.byteLength){case 4:return{sec:t.getUint32(0),nsec:0};case 8:{let e=t.getUint32(0),n=t.getUint32(4);return{sec:(e&3)*4294967296+n,nsec:e>>>2}}case 12:return{sec:$W(t,4),nsec:t.getUint32(0)};default:throw new XW(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${e.length}`)}}function oG(e){let t=aG(e);return new Date(t.sec*1e3+t.nsec/1e6)}var sG,cG,lG,uG=c((()=>{ZW(),tG(),sG=4294967295,cG=17179869183,lG={type:-1,encode:iG,decode:oG}})),dG,fG=c((()=>{YW(),uG(),dG=class e{static defaultCodec=new e;__brand;builtInEncoders=[];builtInDecoders=[];encoders=[];decoders=[];constructor(){this.register(lG)}register({type:e,encode:t,decode:n}){if(e>=0)this.encoders[e]=t,this.decoders[e]=n;else{let r=-1-e;this.builtInEncoders[r]=t,this.builtInDecoders[r]=n}}tryToEncode(e,t){for(let n=0;n<this.builtInEncoders.length;n++){let r=this.builtInEncoders[n];if(r!=null){let i=r(e,t);if(i!=null)return new JW(-1-n,i)}}for(let n=0;n<this.encoders.length;n++){let r=this.encoders[n];if(r!=null){let i=r(e,t);if(i!=null)return new JW(n,i)}}return e instanceof JW?e:null}decode(e,t,n){let r=t<0?this.builtInDecoders[-1-t]:this.decoders[t];return r?r(e,t,n):new JW(t,e)}}}));function pG(e){return e instanceof ArrayBuffer||typeof SharedArrayBuffer<`u`&&e instanceof SharedArrayBuffer}function mG(e){return e instanceof Uint8Array?e:ArrayBuffer.isView(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):pG(e)?new Uint8Array(e):Uint8Array.from(e)}var hG=c((()=>{}));function gG(e){return`${e<0?`-`:``}0x${Math.abs(e).toString(16).padStart(2,`0`)}`}var _G=c((()=>{})),vG,yG,bG,xG=c((()=>{qW(),vG=16,yG=16,bG=class{hit=0;miss=0;caches;maxKeyLength;maxLengthPerKey;constructor(e=vG,t=yG){this.maxKeyLength=e,this.maxLengthPerKey=t,this.caches=[];for(let e=0;e<this.maxKeyLength;e++)this.caches.push([])}canBeCached(e){return e>0&&e<=this.maxKeyLength}find(e,t,n){let r=this.caches[n-1];FIND_CHUNK:for(let i of r){let r=i.bytes;for(let i=0;i<n;i++)if(r[i]!==e[t+i])continue FIND_CHUNK;return i.str}return null}store(e,t){let n=this.caches[e.length-1],r={bytes:e,str:t};n.length>=this.maxLengthPerKey?n[Math.random()*n.length|0]=r:n.push(r)}decode(e,t,n){let r=this.find(e,t,n);if(r!=null)return this.hit++,r;this.miss++;let i=VW(e,t,n),a=Uint8Array.prototype.slice.call(e,t,t+n);return this.store(a,i),i}}})),SG,CG,wG,TG,EG,DG,OG,kG,AG,jG,MG,NG=c((()=>{_G(),fG(),tG(),qW(),hG(),xG(),ZW(),SG=`array`,CG=`map_key`,wG=`map_value`,TG=e=>{if(typeof e==`string`||typeof e==`number`)return e;throw new XW(`The type of key must be string or number but `+typeof e)},EG=class{stack=[];stackHeadPosition=-1;get length(){return this.stackHeadPosition+1}top(){return this.stack[this.stackHeadPosition]}pushArrayState(e){let t=this.getUninitializedStateFromPool();t.type=SG,t.position=0,t.size=e,t.array=Array(e)}pushMapState(e){let t=this.getUninitializedStateFromPool();t.type=CG,t.readCount=0,t.size=e,t.map={}}getUninitializedStateFromPool(){return this.stackHeadPosition++,this.stackHeadPosition===this.stack.length&&this.stack.push({type:void 0,size:0,array:void 0,position:0,readCount:0,map:void 0,key:null}),this.stack[this.stackHeadPosition]}release(e){if(this.stack[this.stackHeadPosition]!==e)throw Error(`Invalid stack state. Released state is not on top of the stack.`);if(e.type===SG){let t=e;t.size=0,t.array=void 0,t.position=0,t.type=void 0}if(e.type===CG||e.type===wG){let t=e;t.size=0,t.map=void 0,t.readCount=0,t.type=void 0}this.stackHeadPosition--}reset(){this.stack.length=0,this.stackHeadPosition=-1}},DG=-1,OG=new DataView(new ArrayBuffer(0)),kG=new Uint8Array(OG.buffer);try{OG.getInt8(0)}catch(e){if(!(e instanceof RangeError))throw Error(`This module is not supported in the current JavaScript engine because DataView does not throw RangeError on out-of-bounds access`)}AG=RangeError(`Insufficient data`),jG=new bG,MG=class e{extensionCodec;context;useBigInt64;rawStrings;maxStrLength;maxBinLength;maxArrayLength;maxMapLength;maxExtLength;keyDecoder;mapKeyConverter;totalPos=0;pos=0;view=OG;bytes=kG;headByte=DG;stack=new EG;entered=!1;constructor(e){this.extensionCodec=e?.extensionCodec??dG.defaultCodec,this.context=e?.context,this.useBigInt64=e?.useBigInt64??!1,this.rawStrings=e?.rawStrings??!1,this.maxStrLength=e?.maxStrLength??4294967295,this.maxBinLength=e?.maxBinLength??4294967295,this.maxArrayLength=e?.maxArrayLength??4294967295,this.maxMapLength=e?.maxMapLength??4294967295,this.maxExtLength=e?.maxExtLength??4294967295,this.keyDecoder=e?.keyDecoder===void 0?jG:e.keyDecoder,this.mapKeyConverter=e?.mapKeyConverter??TG}clone(){return new e({extensionCodec:this.extensionCodec,context:this.context,useBigInt64:this.useBigInt64,rawStrings:this.rawStrings,maxStrLength:this.maxStrLength,maxBinLength:this.maxBinLength,maxArrayLength:this.maxArrayLength,maxMapLength:this.maxMapLength,maxExtLength:this.maxExtLength,keyDecoder:this.keyDecoder})}reinitializeState(){this.totalPos=0,this.headByte=DG,this.stack.reset()}setBuffer(e){let t=mG(e);this.bytes=t,this.view=new DataView(t.buffer,t.byteOffset,t.byteLength),this.pos=0}appendBuffer(e){if(this.headByte===DG&&!this.hasRemaining(1))this.setBuffer(e);else{let t=this.bytes.subarray(this.pos),n=mG(e),r=new Uint8Array(t.length+n.length);r.set(t),r.set(n,t.length),this.setBuffer(r)}}hasRemaining(e){return this.view.byteLength-this.pos>=e}createExtraByteError(e){let{view:t,pos:n}=this;return RangeError(`Extra ${t.byteLength-n} of ${t.byteLength} byte(s) found at buffer[${e}]`)}decode(e){if(this.entered)return this.clone().decode(e);try{this.entered=!0,this.reinitializeState(),this.setBuffer(e);let t=this.doDecodeSync();if(this.hasRemaining(1))throw this.createExtraByteError(this.pos);return t}finally{this.entered=!1}}*decodeMulti(e){if(this.entered){yield*this.clone().decodeMulti(e);return}try{for(this.entered=!0,this.reinitializeState(),this.setBuffer(e);this.hasRemaining(1);)yield this.doDecodeSync()}finally{this.entered=!1}}async decodeAsync(e){if(this.entered)return this.clone().decodeAsync(e);try{this.entered=!0;let t=!1,n;for await(let r of e){if(t)throw this.entered=!1,this.createExtraByteError(this.totalPos);this.appendBuffer(r);try{n=this.doDecodeSync(),t=!0}catch(e){if(!(e instanceof RangeError))throw e}this.totalPos+=this.pos}if(t){if(this.hasRemaining(1))throw this.createExtraByteError(this.totalPos);return n}let{headByte:r,pos:i,totalPos:a}=this;throw RangeError(`Insufficient data in parsing ${gG(r)} at ${a} (${i} in the current buffer)`)}finally{this.entered=!1}}decodeArrayStream(e){return this.decodeMultiAsync(e,!0)}decodeStream(e){return this.decodeMultiAsync(e,!1)}async*decodeMultiAsync(e,t){if(this.entered){yield*this.clone().decodeMultiAsync(e,t);return}try{this.entered=!0;let n=t,r=-1;for await(let i of e){if(t&&r===0)throw this.createExtraByteError(this.totalPos);this.appendBuffer(i),n&&(r=this.readArraySize(),n=!1,this.complete());try{for(;yield this.doDecodeSync(),--r!==0;);}catch(e){if(!(e instanceof RangeError))throw e}this.totalPos+=this.pos}}finally{this.entered=!1}}doDecodeSync(){DECODE:for(;;){let e=this.readHeadByte(),t;if(e>=224)t=e-256;else if(e<192)if(e<128)t=e;else if(e<144){let n=e-128;if(n!==0){this.pushMapState(n),this.complete();continue DECODE}else t={}}else if(e<160){let n=e-144;if(n!==0){this.pushArrayState(n),this.complete();continue DECODE}else t=[]}else{let n=e-160;t=this.decodeString(n,0)}else if(e===192)t=null;else if(e===194)t=!1;else if(e===195)t=!0;else if(e===202)t=this.readF32();else if(e===203)t=this.readF64();else if(e===204)t=this.readU8();else if(e===205)t=this.readU16();else if(e===206)t=this.readU32();else if(e===207)t=this.useBigInt64?this.readU64AsBigInt():this.readU64();else if(e===208)t=this.readI8();else if(e===209)t=this.readI16();else if(e===210)t=this.readI32();else if(e===211)t=this.useBigInt64?this.readI64AsBigInt():this.readI64();else if(e===217){let e=this.lookU8();t=this.decodeString(e,1)}else if(e===218){let e=this.lookU16();t=this.decodeString(e,2)}else if(e===219){let e=this.lookU32();t=this.decodeString(e,4)}else if(e===220){let e=this.readU16();if(e!==0){this.pushArrayState(e),this.complete();continue DECODE}else t=[]}else if(e===221){let e=this.readU32();if(e!==0){this.pushArrayState(e),this.complete();continue DECODE}else t=[]}else if(e===222){let e=this.readU16();if(e!==0){this.pushMapState(e),this.complete();continue DECODE}else t={}}else if(e===223){let e=this.readU32();if(e!==0){this.pushMapState(e),this.complete();continue DECODE}else t={}}else if(e===196){let e=this.lookU8();t=this.decodeBinary(e,1)}else if(e===197){let e=this.lookU16();t=this.decodeBinary(e,2)}else if(e===198){let e=this.lookU32();t=this.decodeBinary(e,4)}else if(e===212)t=this.decodeExtension(1,0);else if(e===213)t=this.decodeExtension(2,0);else if(e===214)t=this.decodeExtension(4,0);else if(e===215)t=this.decodeExtension(8,0);else if(e===216)t=this.decodeExtension(16,0);else if(e===199){let e=this.lookU8();t=this.decodeExtension(e,1)}else if(e===200){let e=this.lookU16();t=this.decodeExtension(e,2)}else if(e===201){let e=this.lookU32();t=this.decodeExtension(e,4)}else throw new XW(`Unrecognized type byte: ${gG(e)}`);this.complete();let n=this.stack;for(;n.length>0;){let e=n.top();if(e.type===SG)if(e.array[e.position]=t,e.position++,e.position===e.size)t=e.array,n.release(e);else continue DECODE;else if(e.type===CG){if(t===`__proto__`)throw new XW(`The key __proto__ is not allowed`);e.key=this.mapKeyConverter(t),e.type=wG;continue DECODE}else if(e.map[e.key]=t,e.readCount++,e.readCount===e.size)t=e.map,n.release(e);else{e.key=null,e.type=CG;continue DECODE}}return t}}readHeadByte(){return this.headByte===DG&&(this.headByte=this.readU8()),this.headByte}complete(){this.headByte=DG}readArraySize(){let e=this.readHeadByte();switch(e){case 220:return this.readU16();case 221:return this.readU32();default:if(e<160)return e-144;throw new XW(`Unrecognized array type byte: ${gG(e)}`)}}pushMapState(e){if(e>this.maxMapLength)throw new XW(`Max length exceeded: map length (${e}) > maxMapLengthLength (${this.maxMapLength})`);this.stack.pushMapState(e)}pushArrayState(e){if(e>this.maxArrayLength)throw new XW(`Max length exceeded: array length (${e}) > maxArrayLength (${this.maxArrayLength})`);this.stack.pushArrayState(e)}decodeString(e,t){return!this.rawStrings||this.stateIsMapKey()?this.decodeUtf8String(e,t):this.decodeBinary(e,t)}decodeUtf8String(e,t){if(e>this.maxStrLength)throw new XW(`Max length exceeded: UTF-8 byte length (${e}) > maxStrLength (${this.maxStrLength})`);if(this.bytes.byteLength<this.pos+t+e)throw AG;let n=this.pos+t,r;return r=this.stateIsMapKey()&&this.keyDecoder?.canBeCached(e)?this.keyDecoder.decode(this.bytes,n,e):UW(this.bytes,n,e),this.pos+=t+e,r}stateIsMapKey(){return this.stack.length>0?this.stack.top().type===CG:!1}decodeBinary(e,t){if(e>this.maxBinLength)throw new XW(`Max length exceeded: bin length (${e}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining(e+t))throw AG;let n=this.pos+t,r=this.bytes.subarray(n,n+e);return this.pos+=t+e,r}decodeExtension(e,t){if(e>this.maxExtLength)throw new XW(`Max length exceeded: ext length (${e}) > maxExtLength (${this.maxExtLength})`);let n=this.view.getInt8(this.pos+t),r=this.decodeBinary(e,t+1);return this.extensionCodec.decode(r,n,this.context)}lookU8(){return this.view.getUint8(this.pos)}lookU16(){return this.view.getUint16(this.pos)}lookU32(){return this.view.getUint32(this.pos)}readU8(){let e=this.view.getUint8(this.pos);return this.pos++,e}readI8(){let e=this.view.getInt8(this.pos);return this.pos++,e}readU16(){let e=this.view.getUint16(this.pos);return this.pos+=2,e}readI16(){let e=this.view.getInt16(this.pos);return this.pos+=2,e}readU32(){let e=this.view.getUint32(this.pos);return this.pos+=4,e}readI32(){let e=this.view.getInt32(this.pos);return this.pos+=4,e}readU64(){let e=eG(this.view,this.pos);return this.pos+=8,e}readI64(){let e=$W(this.view,this.pos);return this.pos+=8,e}readU64AsBigInt(){let e=this.view.getBigUint64(this.pos);return this.pos+=8,e}readI64AsBigInt(){let e=this.view.getBigInt64(this.pos);return this.pos+=8,e}readF32(){let e=this.view.getFloat32(this.pos);return this.pos+=4,e}readF64(){let e=this.view.getFloat64(this.pos);return this.pos+=8,e}}}));function PG(e,t){return new MG(t).decode(e)}var FG=c((()=>{NG()})),IG=c((()=>{FG()}));function LG(e){let t=e=>RangeError(`columns message: ${e}`);e.byteOffset%8!=0&&(e=e.slice());let n=new DataView(e.buffer,e.byteOffset,e.byteLength);if(e.byteLength<8)throw t(`short`);if(n.getUint8(0)!==RG)throw t(`version ${n.getUint8(0)}`);let r=n.getUint16(2,!0),i=n.getUint32(4,!0),a=new TextDecoder,o=[],s=8;for(let i=0;i<r;i++){if(s+3>e.byteLength)throw t(`short channel table`);let r=n.getUint8(s),i=n.getUint8(s+1),c=n.getUint8(s+2);if(s+=3,r!==4&&r!==8)throw t(`value size ${r}`);if(s+i+c>e.byteLength)throw t(`short channel table`);o.push({name:a.decode(e.subarray(s,s+i)),unit:a.decode(e.subarray(s+i,s+i+c)),size:r}),s+=i+c}if(s=zG(s),s+zG(i*8)+o.reduce((e,t)=>e+zG(i*t.size),0)>e.byteLength)throw t(`short data`);let c=e.byteOffset,l=new Float64Array(e.buffer,c+s,i);s+=zG(i*8);let u={},d={};for(let t of o)u[t.name]=t.size===4?new Float32Array(e.buffer,c+s,i):new Float64Array(e.buffer,c+s,i),t.unit&&(d[t.name]=t.unit),s+=zG(i*t.size);return{t:l,columns:u,units:d}}var RG,zG,BG=c((()=>{RG=1,zG=e=>e+7&-8}));function VG(e,t,n,r){let i=t.length,a=t.map((e,t)=>`y${t}lo`),o=t.map((e,t)=>`y${t}hi`),s=new Uint8Array(e.length),c=0;for(let t=0;t<e.length;t++){let n=e[t];for(let e=0;e<i;e++){let r=n[o[e]];if(r!=null&&Number(r)!==Number(n[a[e]])){s[t]=1;break}}c+=1+s[t]}let l=new Float64Array(c),u=t.map(()=>new Float64Array(c).fill(NaN)),d,f=0,p=null;for(let t=0;t<e.length;t++){let m=e[t],h=n+(Number(m.b)+.5)*r,g=Number(m.pass??0);p!==null&&g!==p&&((d??=new Uint8Array(c))[f]=1),p=g,l[f]=h;for(let e=0;e<i;e++){let t=m[a[e]];t!=null&&(u[e][f]=Number(t))}if(f++,s[t]){l[f]=h;for(let e=0;e<i;e++){let t=m[o[e]];t!=null&&(u[e][f]=Number(t))}f++}}return{length:c,x:l,brk:d,cols:new Map(t.map((e,t)=>[e,u[t]]))}}function HG(e,t){if(t>=e.length)return e;let n=new Map;for(let[r,i]of e.cols)n.set(r,i.subarray(0,t));return{length:t,x:e.x.subarray(0,t),brk:e.brk?.subarray(0,t),cols:n}}function UG(e,t,n,r,i){let a=[];for(let o of new Set(e)){let e=t(o);if(!e||!(e.t<r))continue;let s=Math.max(n,e.t);s<i&&a.push({c:o,a:s,v:e.v})}if(a.length===0)return null;a.sort((e,t)=>e.a-t.a);let o=a.length+1,s=new Float64Array(o),c=new Map;return a.forEach((e,t)=>{let n=new Float64Array(o).fill(NaN);n[t]=n[o-1]=e.v,c.set(e.c,n),s[t]=e.a}),s[o-1]=i,{length:o,x:s,cols:c,hold:!0}}function WG(e,t){if(t===void 0||e.length===0||e.x[e.length-1]<=t)return e;let n=0,r=e.length;for(;n<r;){let i=n+r>>1;e.x[i]<=t?n=i+1:r=i}return HG(e,n)}function GG(e,t,n){let r=(t,n)=>{let r=0,i=e.length;for(;r<i;){let a=r+i>>1;(n?e.x[a]<=t:e.x[a]<t)?r=a+1:i=a}return r},i=r(t,!1),a=r(n,!0);if(i===0&&a===e.length)return e;let o=new Map;for(let[t,n]of e.cols)o.set(t,n.subarray(i,a));return{length:a-i,x:e.x.subarray(i,a),brk:e.brk?.subarray(i,a),cols:o}}function KG(e,t){let n=[];for(let r=0;r<e.length;r++)t(e.x[r])&&n.push(r);if(n.length===e.length)return e;let r=(e,t)=>{for(let r=0;r<n.length;r++)t[r]=e[n[r]];return t},i=new Map;for(let[t,a]of e.cols)i.set(t,r(a,new Float64Array(n.length)));return{length:n.length,x:r(e.x,new Float64Array(n.length)),brk:e.brk&&r(e.brk,new Uint8Array(n.length)),cols:i}}function qG(e,t,n,r,i=``,a=0){let o=Ge(e),s=gE(e.length,r),c=t=>{let n=o&&Ke(o,t);return n?e=>n[e]:n=>{let r=e[n][t];return typeof r==`number`?r:NaN}},l=c(t),u=[];for(let e of s)Number.isNaN(l(e))||u.push(e);let d=u.length,f=d===e.length&&a===0,p=o&&Ke(o,t),m=f&&p?p:Float64Array.from(u,e=>l(e)+a),h=new Map;for(let e of n){let t=o&&Ke(o,e);if(o&&!t)continue;if(f&&t){h.set(e+i,t);continue}let n=c(e),r=Float64Array.from(u,n);!t&&!r.some(e=>!Number.isNaN(e))||h.set(e+i,r)}return{length:d,x:m,cols:h}}function JG(e,t,n){if(!t&&n===0)return e;let r=e.x;if(n!==0){r=new Float64Array(e.length);for(let t=0;t<e.length;t++)r[t]=e.x[t]+n}let i=new Map;for(let[n,r]of e.cols)i.set(n+t,r);return{length:e.length,x:r,brk:e.brk,cols:i}}function YG(e){let t=e.filter(e=>e.length>0);if(t.length===0)return ZG;if(t.length===1)return t[0];let n=t.reduce((e,t)=>e+t.length,0),r=new Float64Array(n),i=new Set;for(let e of t)for(let t of e.cols.keys())i.add(t);let a=new Map;for(let e of i)a.set(e,new Float64Array(n).fill(NaN));let o,s=0;for(let e of t){r.set(e.x,s),e.brk&&(o??=new Uint8Array(n)).set(e.brk,s);for(let[t,n]of e.cols)a.get(t).set(n,s);s+=e.length}return{length:n,x:r,brk:o,cols:a}}var XG,ZG,QG=c((()=>{xE(),Qe(),jE(),XG=OE(new WeakSet),ZG={length:0,x:new Float64Array,cols:new Map}})),$G,eK,tK=c((()=>{$G=64,eK=class{nc;bucket;b;lo;hi;start=0;end=0;rowP;px=new Float64Array;pv=[];pStart=0;pEnd=0;mStart=0;mEnd=0;dirty=1/0;dirtyFront=-1;invalid=!0;constructor(e,t,n=1024){this.nc=e,this.bucket=t,this.b=new Float64Array(n),this.rowP=new Float64Array(n),this.lo=Array.from({length:e},()=>new Float64Array(n)),this.hi=Array.from({length:e},()=>new Float64Array(n))}get count(){return this.end-this.start}lowerBound(e){let t=this.start,n=this.end;for(;t<n;){let r=t+n>>>1;this.b[r]<e?t=r+1:n=r}return t}relocate(e,t){let n=this.count,r=n=>{if(t===n.length&&e<=this.start)return n.copyWithin(e,this.start,this.end),n;let r=new Float64Array(t);return r.set(n.subarray(this.start,this.end),e),r};this.b=r(this.b),this.rowP=r(this.rowP),this.lo=this.lo.map(r),this.hi=this.hi.map(r);let i=e-this.start;this.mStart+=i,this.mEnd+=i,this.dirty!==1/0&&(this.dirty+=i),this.dirtyFront>=0&&(this.dirtyFront+=i),this.start=e,this.end=e+n}touch(e){e===this.start&&e+1<this.mEnd?this.dirtyFront=e:e<this.dirty&&(this.dirty=e)}clearRow(e){for(let t=0;t<this.nc;t++)this.lo[t][e]=NaN,this.hi[t][e]=NaN;this.touch(e)}row(e){let t=this.end;if(t>this.start&&this.b[t-1]===e)return t-1;if(t===this.start||e>this.b[t-1])return t===this.b.length&&(this.start>this.count?this.relocate(0,this.b.length):this.relocate(0,Math.max(1024,this.b.length*2))),this.b[this.end]=e,this.clearRow(this.end),this.end++;let n=this.lowerBound(e);if(this.b[n]===e)return n;if(n!==this.start){this.end===this.b.length&&(this.start>this.count?this.relocate(0,this.b.length):this.relocate(0,Math.max(1024,this.b.length*2)),n=this.lowerBound(e));let t=e=>e.copyWithin(n+1,n,this.end);return t(this.b),t(this.rowP),this.lo.forEach(t),this.hi.forEach(t),this.end++,n<this.mEnd&&this.mEnd++,this.dirty!==1/0&&this.dirty>=n&&this.dirty++,this.b[n]=e,this.clearRow(n),n}if(this.start===0){let e=Math.max(1024,this.count);this.relocate(e,2*e+this.count)}return this.start--,this.b[this.start]=e,this.clearRow(this.start),this.invalid=!0,this.start}coarsen(e){let t=new Int32Array(this.end-this.start),n=this.start-1;for(let r=this.start;r<this.end;r++){let i=Math.floor(this.b[r]/e);(n<this.start||this.b[n]!==i)&&(this.b[++n]=i),t[r-this.start]=n}for(let e=0;e<this.nc;e++){let n=this.lo[e],r=this.hi[e],i=-1;for(let e=this.start;e<this.end;e++){let a=t[e-this.start],o=n[e],s=r[e];if(a!==i){n[a]=o,r[a]=s,i=a;continue}o===o&&(n[a]<=o||(n[a]=o),r[a]>=s||(r[a]=s))}}this.end=n+1,this.bucket*=e,this.dirty=1/0,this.dirtyFront=-1,this.invalid=!0}dropBelow(e){this.start=this.lowerBound(e),this.start===this.end&&(this.start=this.end=0,this.invalid=!0)}reset(e){this.clearRow(e)}fold(e,t,n,r){this.touch(e);for(let i=0;i<t.length;i++){let a=t[i],o=1/0,s=-1/0;for(let e=n;e<r;e++){let t=a[e];t<o&&(o=t),t>s&&(s=t)}if(o===1/0)continue;let c=this.lo[i],l=this.hi[i],u=c[e],d=l[e];c[e]=u<=o?u:o,l[e]=d>=s?d:s}}toRows(e,t,n,r,i){let a=[];for(let o=e;o<t;o++){let e={...n,b:this.b[o],pass:0};for(let t=0;t<this.nc;t++){let n=this.lo[t][o];n===n&&(e[r[t]]=n,e[i[t]]=this.hi[t][o])}a.push(e)}return a}pointsOf(e){for(let t=0;t<this.nc;t++){let n=this.hi[t][e];if(n===n&&n!==this.lo[t][e])return 2}return 1}writeRow(e,t,n){let r=(this.b[e]+.5)*this.bucket;this.px[t]=r;for(let n=0;n<this.nc;n++)this.pv[n][t]=this.lo[n][e];if(n===2){this.px[t+1]=r;for(let n=0;n<this.nc;n++)this.pv[n][t+1]=this.hi[n][e]}}reserve(e){if(this.pEnd+e<=this.px.length)return;let t=this.pEnd-this.pStart,n=$G-this.pStart,r=2*(t+e+$G)<=this.px.length,i=r?this.px.length:Math.max(4*this.b.length+$G,2*(t+e+$G)),a=e=>{if(r)return e.copyWithin($G,this.pStart,this.pEnd),e;let t=new Float64Array(i);return t.set(e.subarray(this.pStart,this.pEnd),$G),t};this.px=a(this.px),this.pv=this.pv.map(a);for(let e=this.mStart;e<this.mEnd;e++)this.rowP[e]+=n;this.pStart=$G,this.pEnd=$G+t}writeFrom(e){this.mEnd=e;for(let t=e;t<this.end;t++){let e=this.pointsOf(t);this.reserve(e),this.rowP[t]=this.pEnd,this.writeRow(t,this.pEnd,e),this.pEnd+=e,this.mEnd=t+1}}writeAll(){let e=this.start,t=this.count,n=new Uint8Array(t);for(let r=0;r<this.nc;r++){let i=this.lo[r],a=this.hi[r];for(let r=0;r<t;r++){let t=a[e+r];t===t&&t!==i[e+r]&&(n[r]=1)}}let r=0;for(let e=0;e<t;e++)r+=1+n[e];this.pStart=this.pEnd=$G,this.mStart=this.mEnd=e,this.reserve(r);let i=$G;for(let r=0;r<t;r++){let t=(this.b[e+r]+.5)*this.bucket;this.rowP[e+r]=i,this.px[i]=t,n[r]&&(this.px[i+1]=t),i+=1+n[r]}for(let r=0;r<this.nc;r++){let i=this.lo[r],a=this.hi[r],o=this.pv[r];for(let r=0;r<t;r++){let t=this.rowP[e+r];o[t]=i[e+r],n[r]&&(o[t+1]=a[e+r])}}this.pEnd=i,this.mEnd=this.end}sync(){if(this.pv.length!==this.nc&&(this.pv=Array.from({length:this.nc},()=>new Float64Array)),this.invalid||this.start<this.mStart||this.start>=this.mEnd)this.writeAll();else{this.start>this.mStart&&(this.mStart=this.start,this.pStart=this.rowP[this.start]);let e=Math.max(this.start,Math.min(this.dirty,this.mEnd)),t=this.dirtyFront;if(t===this.start)if(t+1<e){let e=this.pointsOf(t),n=this.rowP[t+1]-e;if(n<0)return this.invalid=!0,this.sync();this.rowP[t]=n,this.pStart=n,this.writeRow(t,n,e)}else e=t;e<this.end&&(e<this.mEnd&&(this.pEnd=this.rowP[e]),this.writeFrom(e))}this.dirty=1/0,this.dirtyFront=-1,this.invalid=!1}toPoints(e,t,n){this.sync();let r=e<t?this.rowP[e]:0,i=e<t?t<this.mEnd?this.rowP[t]:this.pEnd:0;return{length:i-r,x:this.px.subarray(r,i),cols:new Map(n.map((e,t)=>[e,this.pv[t].subarray(r,i)]))}}}}));function nK(e){if(!(e>0)||!Number.isFinite(e))return e;let t=10**Math.floor(Math.log10(e)),n=e/t;return(n<1.5?1:n<3.5?2:n<7.5?5:10)*t}function rK(e,t,n,r,i){if(n instanceof Float64Array||n instanceof Float32Array)e.set(n.subarray(r,r+i),t);else for(let a=0;a<i;a++)e[t+a]=+n[r+a]}function iK(e,t){let n=e.t.length,r=Object.keys(e.columns).filter(e=>e!==t);for(let t of r)if(e.columns[t].length!==n)throw RangeError(`live column "${t}" has ${e.columns[t].length} values for ${n} times`);return r}function aK(e){let t=fK[e];if(!t){let n=Array.from({length:e},(e,t)=>`y${t}lo`),r=Array.from({length:e},(e,t)=>`y${t}hi`);t={lo:n,hi:r,row:JSON.parse(JSON.stringify(Object.fromEntries([[`b`,0],[`pass`,0],...n.flatMap((e,t)=>[[e,null],[r[t],null]])])))},fK[e]=t}return t}function oK(e,t){return qe({keys:e,length:t[0]?.length??0,values:t,text:e.map(()=>null)})}var sK,cK,lK,uK,dK,fK,pK,mK,hK,gK=c((()=>{RE(),QG(),tK(),Qe(),sK=4e6,cK=60,lK=32,uK=4,dK=`ElapsedTime`,fK=[],pK=4096,mK=4,hK=class{time;alloc;maxBytes;cols=new Map;head=0;count=0;full=!1;pushed=0;clears=0;signalOrder=[];unitByName=new Map;capacity;timeColumn;timeUnit;lastBackAbs=-1;get timeMonotonic(){return this.lastBackAbs<=this.pushed-this.size}lastPushT=-1/0;decCache=null;passTrack=null;prevCyclePts=null;curCyclePts=null;trackers=new Map;debugLastScan=0;debugGrowCopied=0;timeDecs=new Map;mirrors=new Map;historyDec=null;snapDec=null;latest=new Map;constructor(e,t=dK,n=`s`,r=1/0){this.capacity=Math.max(2,Math.floor(e)),this.timeColumn=t,this.timeUnit=n,this.maxBytes=r,this.alloc=Math.min(this.capacity,pK),this.time=new Float64Array(this.alloc)}get maxSamples(){return this.capacity}newColumn(){if(this.growing)try{return new Float64Array(this.growing.next).fill(NaN)}catch(e){this.refused(e)}return new Float64Array(this.alloc).fill(NaN)}growing=null;stepGrow(e){if(this.full)return;if(!this.growing){if(this.count<this.alloc*.75||this.alloc>=this.capacity)return;let e=Math.min(this.capacity,this.alloc*2);if(e*8*(1+this.cols.size)>this.maxBytes)return;this.growing={next:e,todo:[null,...this.cols.keys()],owed:0}}let t=this.growing;t.owed+=t.todo.length*e/Math.max(1,this.alloc-this.count),this.moveColumns(Math.floor(t.owed))}moveColumns(e){let t=this.growing;for(;e>0&&t.todo.length>0;e--,t.owed--){let e=t.todo.pop(),n=e===null?this.time:this.cols.get(e);if(!n||n.length>=t.next)continue;let r;try{r=new Float64Array(t.next)}catch(e){this.refused(e);return}r.set(n),this.debugGrowCopied+=n.length,e===null?this.time=r:this.cols.set(e,r)}t.todo.length===0&&(this.alloc=t.next,this.growing=null)}growNow(){this.growing?this.moveColumns(1/0):this.grow()}grow(){let e=Math.min(this.capacity,this.alloc*2);if(e*8*(1+this.cols.size)>this.maxBytes){this.capacity=this.alloc;return}let t=t=>{let n=new Float64Array(e);return n.set(t),this.debugGrowCopied+=t.length,n};try{this.time=t(this.time);for(let[e,n]of this.cols)this.cols.set(e,t(n))}catch(e){this.refused(e);return}this.alloc=e}refused(e){if(!(e instanceof RangeError))throw e;this.capacity=this.alloc,this.growing=null}get version(){return this.pushed+this.clears}get size(){return this.full?this.capacity:this.count}push(e){for(let[t,n]of this.trackers){let r=t===this.timeColumn?e.t:e.signals.find(e=>e.name===t)?.value;r!==void 0&&Number.isFinite(r)&&this.advanceCycle(t,n,r,this.pushed)}let t=this.lastPushT;this.lastPushT=Math.max(t,e.t),!this.full&&this.count===this.alloc&&(this.growNow(),this.count===this.capacity&&(this.full=!0));let n=this.full?this.head:this.count;this.time[n]=e.t;for(let e of this.signalOrder)this.cols.get(e)[n]=NaN;for(let t of e.signals){if(this.computed.has(t.name))continue;let r=this.cols.get(t.name);r?t.unit&&t.unit!==this.unitByName.get(t.name)&&(this.unitByName.get(t.name)&&this.dropColumnSamples(t.name,r),this.unitByName.set(t.name,t.unit)):(r=this.newColumn(),this.cols.set(t.name,r),this.signalOrder.push(t.name),this.unitByName.set(t.name,t.unit??``)),r[n]=t.value,Number.isFinite(t.value)&&this.noteValue(t.name,e.t,t.value)}this.pushed++,this.full?this.head=(this.head+1)%this.capacity:(this.count++,this.count===this.capacity&&(this.full=!0)),this.stepGrow(1),e.t<t&&this.placeLate(t,e.t,1,!0,this.pushed-1)}pushColumns(e){let t=e.t,n=t.length,r=iK(e,this.timeColumn);if(n===0)return;if(this.trackers.size>0){for(let i=0;i<n;i++)this.push({t:t[i],signals:r.map(t=>({name:t,unit:e.units?.[t],value:e.columns[t][i]}))});return}for(let t of r){if(this.computed.has(t))continue;let n=e.units?.[t],r=this.cols.get(t);r?n&&n!==this.unitByName.get(t)&&(this.unitByName.get(t)&&this.dropColumnSamples(t,r),this.unitByName.set(t,n)):(this.cols.set(t,this.newColumn()),this.signalOrder.push(t),this.unitByName.set(t,n??``))}for(let i of r){if(this.computed.has(i))continue;let r=e.columns[i];for(let e=n-1;e>=0;e--)if(Number.isFinite(r[e])){this.noteValue(i,+t[e],r[e]);break}}let i=this.lastPushT,a=1/0,o=-1/0,s=!0,c=-1;for(let e=0;e<n;e++){let n=+t[e];n<(e>0?+t[e-1]:i)&&(c=e,e>0&&(s=!1)),n<a&&(a=n),n>o&&(o=n)}let l=this.pushed+c;this.lastPushT=Math.max(i,o);let u=Math.max(0,n-this.capacity);for(this.pushed+=u;u<n;){!this.full&&this.count===this.alloc&&(this.growNow(),this.count===this.capacity&&(this.full=!0));let r=this.full?this.head:this.count,i=Math.min(n-u,this.full?this.capacity-this.head:this.alloc-this.count);rK(this.time,r,t,u,i);for(let t of this.signalOrder){let n=this.cols.get(t),a=this.computed.has(t)?void 0:e.columns[t];a?rK(n,r,a,u,i):n.fill(NaN,r,r+i)}this.pushed+=i,u+=i,this.full?this.head=(this.head+i)%this.capacity:(this.count+=i,this.count===this.capacity&&(this.full=!0))}this.stepGrow(Math.min(n,this.capacity)),c>=0&&this.placeLate(i,a,Math.min(n,this.capacity),s,l)}placeLate(e,t,n,r,i){if(e-t>cK){this.steppedBack(i);return}let a=this.size,o=a-n,s=e=>this.full?(this.head+e)%this.capacity:e,c=0,l=o;for(;c<l;){let e=c+l>>>1;this.time[s(e)]<=t?c=e+1:l=e}r||(c=Math.min(c,o));let u=a-c;if(u<2)return;if(u*(this.cols.size+1)>sK||!this.timeMonotonic){this.steppedBack(i);return}let d=new Float64Array(u);for(let e=0;e<u;e++)d[e]=this.time[s(c+e)];let f=new Uint32Array(u);for(let e=0;e<u;e++)f[e]=e;f.sort((e,t)=>d[e]-d[t]||e-t);let p=new Set;for(let t=u-n;t<u;t++)if(!(t<0||d[t]>=e))for(let[e,n]of this.cols)Number.isFinite(n[s(c+t)])&&p.add(e);let m=[],h=this.snapDec;h&&h.key===`${this.signalOrder.join(`
|
|
82
|
-
`)}|${this.clears}`?m.push({k:h,names:this.signalOrder,ycols:this.signalOrder.map(e=>this.cols.get(e)),drop:()=>{this.snapDec===h&&(this.snapDec=null)}}):this.snapDec=null;for(let[e,t]of this.timeDecs)for(let n of t)m.push({k:n,names:n.cols,ycols:n.cols.map(e=>this.cols.get(e)),drop:()=>{let t=(this.timeDecs.get(e)??[]).filter(e=>e!==n);t.length>0?this.timeDecs.set(e,t):this.timeDecs.delete(e)}});let g=m.filter(e=>{let t=this.pushed-n-e.k.pushed;try{if(t<0||t>o||t*e.ycols.length>sK)throw Error(`behind`);return t>0&&(this.foldBuckets(e.k.store,o-t,o,e.k.bucket,e.ycols),e.k.pushed+=t),!0}catch{return e.drop(),!1}}),_=new Float64Array(u),v=e=>{for(let t=0;t<u;t++)_[t]=e[s(c+f[t])];for(let t=0;t<u;t++)e[s(c+t)]=_[t]};v(this.time);for(let e of this.cols.values())v(e);let y=this.pushed-a+c;this.decCache&&this.decCache.pushed>y&&(this.decCache.pushed=y);let b=this.passTrack;if(b&&b.done>y){b.cuts=b.cuts.filter(e=>e.abs<y),b.done=y,b.prevX=NaN;let e=this.cols.get(b.key);for(let t=y-1;e&&t>=this.pushed-a;t--){let n=e[this.physOf(t)];if(!Number.isNaN(n)){b.prevX=n;break}}}for(let t of g)if(t.names.some(e=>p.has(e)))try{for(let r=0;r<u;r++){if(f[r]<u-n||d[f[r]]>=e)continue;let i=s(c+r),a=Math.floor(this.time[i]/t.k.bucket);a>=t.k.fromB&&t.k.store.fold(t.k.store.row(a),t.ycols,i,i+1)}}catch{t.drop()}this.historyDec=null;for(let e of this.mirrors.values())e.end=Math.max(e.first,Math.min(e.end,y)),e.view=null;for(let[e,t]of this.boundsCache)t.loAbs>=y||t.hiAbs>=y?this.boundsCache.delete(e):(t.done=Math.min(t.done,y),t.version=-1)}steppedBack(e){this.lastBackAbs=e,this.timeDecs.clear(),this.snapDec=null}dropColumnSamples(e,t){t.fill(NaN),this.decCache=null,this.timeDecs.clear(),this.snapDec=null;for(let t of this.trackers.values())t.previous?.cols.delete(e);this.clears++}clear(){this.clears++,this.head=0,this.count=0,this.full=!1,this.pushed=0,this.growing=null,this.cols.clear(),this.computed.clear(),this.signalOrder.length=0,this.unitByName.clear(),this.decCache=null,this.timeDecs.clear(),this.snapDec=null,this.latest.clear(),this.lastBackAbs=-1,this.lastPushT=-1/0,this.trackers.clear()}columnArray(e){return e===this.timeColumn?this.time:this.cols.get(e)}physOf(e){let t=e-(this.pushed-this.size);return this.full?(this.head+t)%this.capacity:t}copyRange(e,t,n,r=[this.timeColumn,...this.signalOrder]){let i=Math.max(t,this.pushed-this.size),a=Math.max(0,n-i),o=this.columnArray(e),s=new Float64Array(a),c=new Map;for(let e of r)this.columnArray(e)&&c.set(e,new Float64Array(a));for(let e=0;e<a;e++){let t=this.physOf(i+e);s[e]=o?o[t]:NaN;for(let[n,r]of c)r[e]=this.columnArray(n)[t]}return{x:s,cols:c}}advanceCycle(e,t,n,r){Number.isFinite(t.lastX)&&n<t.lastX&&t.lastX-n>(t.hi-t.lo)/2?(t.previous=this.copyRange(e,t.start,r),t.start=r,t.lo=t.hi=n):Number.isFinite(t.lastX)?(n<t.lo&&(t.lo=n),n>t.hi&&(t.hi=n)):t.lo=t.hi=n,n<t.allLo&&(t.allLo=n),n>t.allHi&&(t.allHi=n),t.lastX=n}trackCycles(e){if(this.trackers.has(e))return;let t={start:this.pushed-this.size,lo:0,hi:0,lastX:NaN,allLo:1/0,allHi:-1/0,previous:null,next:this.pushed},n=this.columnArray(e),r=this.pushed-this.size;if(n)for(let i=r;i<this.pushed;i++){let r=n[this.physOf(i)];Number.isFinite(r)&&this.advanceCycle(e,t,r,i)}this.trackers.set(e,t)}cycleSpan(e){let t=this.trackers.get(e);return t&&t.allHi>t.allLo?[t.allLo,t.allHi]:null}decimateCycle(e,t,n,r,i,a){let o=this.trackers.get(e),s=n.filter(e=>this.cols.has(e));if(!o)return{x0:r,bucket:0,rows:[],columns:s};let c=t===`previous`?o.previous:this.copyRange(e,o.start,this.pushed,s);if(!c)return{x0:r,bucket:0,rows:[],columns:s};let l=s.map(e=>c.cols.get(e)??new Float64Array(c.x.length).fill(NaN));return ME(c.x,l,s,r,i,a)}decimateCyclePoints(e,t,n,r,i,a){let o=()=>{let o=this.decimateCycle(e,t,n,r,i,a);return VG(o.rows,o.columns,o.x0,o.bucket)},s=this.trackers.get(e),c=Math.floor(a),l=this.columnArray(e);if(!s||!l||!(i>r)||c<1)return o();let u=n.filter(e=>this.cols.has(e)),d=u.join(` `);if(t===`previous`){let e=this.prevCyclePts;if(e&&e.snap===s.previous&&e.x0===r&&e.x1===i&&e.mp===a&&e.colsKey===d)return e.pts;let t=o();return this.prevCyclePts={snap:s.previous,x0:r,x1:i,mp:a,colsKey:d,pts:t},t}if(s.start<this.pushed-this.size)return o();let f=this.curCyclePts;if((!f||f.key!==e||f.start!==s.start||f.x0!==r||f.x1!==i||f.mp!==a||f.colsKey!==d||f.clears!==this.clears)&&(f=this.curCyclePts={key:e,start:s.start,x0:r,x1:i,mp:a,colsKey:d,clears:this.clears,done:s.start,pts:null,seen:new Uint8Array(c),lo:u.map(()=>new Float64Array(c).fill(1/0)),hi:u.map(()=>new Float64Array(c).fill(-1/0))}),f.pts&&f.done===this.pushed)return f.pts;let p=(i-r)/a,m=u.map(e=>this.columnArray(e));for(let e=f.done;e<this.pushed;e++){let t=this.physOf(e),n=l[t];if(!(n>=r&&n<=i))continue;let a=Math.floor((n-r)/p);a>=c&&(a=c-1),f.seen[a]=1;for(let e=0;e<m.length;e++){let n=m[e][t];n===n&&(n<f.lo[e][a]&&(f.lo[e][a]=n),n>f.hi[e][a]&&(f.hi[e][a]=n))}}f.done=this.pushed;let h=0,g=new Uint8Array(c);for(let e=0;e<c;e++)if(f.seen[e]){for(let t=0;t<m.length;t++){let n=f.hi[t][e];if(n!==-1/0&&n!==f.lo[t][e]){g[e]=1;break}}h+=1+g[e]}let _=new Float64Array(h),v=u.map(()=>new Float64Array(h)),y=0;for(let e=0;e<c;e++){if(!f.seen[e])continue;let t=r+(e+.5)*p;_[y]=t;for(let t=0;t<m.length;t++){let n=f.lo[t][e];v[t][y]=n===1/0?NaN:n}if(y++,g[e]){_[y]=t;for(let t=0;t<m.length;t++){let n=f.hi[t][e];v[t][y]=n===-1/0?NaN:n}y++}}return f.pts={length:h,x:_,cols:new Map(u.map((e,t)=>[e,v[t]]))},f.pts}computed=new Set;get firstAbs(){return this.pushed-this.size}get endAbs(){return this.pushed}range(e,t,n){let r=Math.max(t,this.firstAbs),i=new Float64Array(Math.max(0,Math.min(n,this.pushed)-r)),a=this.columnArray(e);if(!a)return i.fill(NaN);for(let e=0;e<i.length;e++)i[e]=a[this.physOf(r+e)];return i}mirrorColumn(e){let t=this.columnArray(e);if(!t)return;let n=this.firstAbs,r=this.pushed,i=this.mirrors.get(e);if((!i||i.clears!==this.clears)&&(i={arr:new Float64Array(Math.max(16,r-n)),first:n,end:n,clears:this.clears,view:null},this.mirrors.set(e,i)),i.first===n&&i.end===r&&i.view)return i.view;if(n>i.first){let e=Math.max(0,i.end-n);e>0&&i.arr.copyWithin(0,n-i.first,i.end-i.first),i.first=n,i.end=n+e}if(i.arr.length<r-n){let e=new Float64Array(Math.max(r-n,i.arr.length*2));e.set(i.arr.subarray(0,i.end-i.first)),i.arr=e}for(let e=i.end;e<r;){let a=this.physOf(e),o=Math.min(r-e,(this.full?this.capacity:this.alloc)-a);i.arr.set(t.subarray(a,a+o),e-n),e+=o}return i.end=r,i.view=i.arr.subarray(0,r-n),i.view}writeComputed(e,t,n,r){let i=this.mirrors.get(e);i&&n<i.end&&(i.end=Math.max(i.first,n),i.view=null);let a=this.cols.get(e);(!a||!this.computed.has(e))&&(a||(a=this.newColumn(),this.cols.set(e,a),this.signalOrder.push(e)),this.computed.add(e)),this.unitByName.set(e,t);for(let e=0;e<r.length;e++){let t=n+e;t<this.firstAbs||t>=this.pushed||(a[this.physOf(t)]=r[e]??NaN)}let o=this.trackers.get(e);if(o){for(let t=0;t<r.length;t++){let i=n+t,a=r[t];i<o.next||i<this.firstAbs||i>=this.pushed||a===null||!Number.isFinite(a)||this.advanceCycle(e,o,a,i)}o.next=Math.max(o.next,Math.min(this.pushed,n+r.length))}}clearComputed(){for(let e of this.computed){this.cols.delete(e),this.unitByName.delete(e);for(let t of this.trackers.values())t.previous?.cols.delete(e)}this.signalOrder.splice(0,this.signalOrder.length,...this.signalOrder.filter(e=>!this.computed.has(e))),this.computed.clear(),this.decCache=null,this.timeDecs.clear(),this.clears++}get columnNames(){return[this.timeColumn,...this.signalOrder]}unitOf(e){return e===this.timeColumn?this.timeUnit:this.unitByName.get(e)??``}columnValues(e){let t=this.size,n=new Float64Array(t),r=e===this.timeColumn?this.time:this.cols.get(e);if(!r)return n.fill(NaN),n;for(let e=0;e<t;e++)n[e]=r[this.full?(this.head+e)%this.capacity:e];return n}accumulate(e,t,n,r,i){let a=aK(i.length),o=n[t];if(Number.isNaN(o))return;let s=Math.floor(o/r),c=e.get(s);c||(c={...a.row,b:s},e.set(s,c));for(let e=0;e<i.length;e++){let n=i[e][t];if(Number.isNaN(n))continue;let r=a.lo[e],o=a.hi[e],s=c[r],l=c[o];c[r]=s==null?n:Math.min(s,n),c[o]=l==null?n:Math.max(l,n)}}decimateColumns(e,t,n,r,i){if(e===this.timeColumn&&this.timeMonotonic)return this.decimateTime(t,n,r,i);let a=e===this.timeColumn?this.time:this.cols.get(e),o=a?t.filter(e=>this.cols.has(e)):[],s=(r-n)/i,c=this.size;if(c>1&&e===this.timeColumn&&this.timeMonotonic&&a){let e=a[this.full?this.head:0],t=(a[this.full?(this.head+c-1)%this.capacity:c-1]-e)/(c-1);t>0&&t<s&&(s=.7*Math.max(t,(r-n)/(i*mK)))}let l=nK(s);{let t=this.decCache;t&&t.xKey===e&&t.colsKey===o.join(` `)&&t.bucket>0&&s>=t.bucket*.5&&s<=t.bucket*2&&(l=t.bucket)}if(!a||o.length===0||!(r>n)||!(l>0))return{x0:n,bucket:0,rows:[],columns:o};let u=o.map(e=>this.cols.get(e)),d=this.size,f=o.join(`\0`);this.debugLastScan=0;let p=this.decCache,m=p!==null&&e===this.timeColumn&&this.timeMonotonic&&p.xKey===e&&p.colsKey===f&&p.bucket===l&&this.pushed>=p.pushed&&this.pushed-p.pushed<d&&p.map.size<this.capacity*2,h=p!==null&&p.xKey===e&&p.colsKey===f&&p.bucket===l&&p.pushed===this.pushed,g=this.pushed-d,_=e===this.timeColumn&&this.timeMonotonic?g:Math.max(g,this.passStart(e,a)),v=p!==null&&(_>g||!this.full)&&p.xKey===e&&p.colsKey===f&&p.bucket===l&&p.passStart===_&&p.pushed>=_&&p.pushed<=this.pushed,y;if(h&&p)y=p.map;else if(v&&p){y=p.map;for(let e=p.pushed;e<this.pushed;e++)this.debugLastScan++,this.accumulate(y,this.physOf(e),a,l,u);p.pushed=this.pushed}else if(m&&p){y=p.map;let e=this.pushed-p.pushed;for(let t=d-e;t<d;t++){let e=this.full?(this.head+t)%this.capacity:t;this.debugLastScan++,this.accumulate(y,e,a,l,u)}if(this.full&&d>0){let e=a[this.head];if(!Number.isNaN(e)){let t=Math.floor(e/l);for(let e=p.lowB;e<t;e++)y.delete(e);y.delete(t);for(let e=0;e<d;e++){let n=(this.head+e)%this.capacity,r=a[n];if(!Number.isNaN(r)){if(Math.floor(r/l)>t)break;this.debugLastScan++,this.accumulate(y,n,a,l,u)}}p.lowB=t}}p.pushed=this.pushed}else{y=new Map;let t=1/0;for(let e=_;e<this.pushed;e++){let n=this.physOf(e),r=a[n];if(Number.isNaN(r))continue;this.debugLastScan++,this.accumulate(y,n,a,l,u);let i=Math.floor(r/l);i<t&&(t=i)}this.decCache={xKey:e,colsKey:f,cols:o,bucket:l,map:y,pushed:this.pushed,lowB:Number.isFinite(t)?t:0,passStart:_}}let b=Math.floor(n/l),x=Math.floor(r/l),S=[];for(let e of y.values()){let t=e.b;t>=b&&t<=x&&S.push(e)}return S.sort((e,t)=>Number(e.b)-Number(t.b)),{x0:0,bucket:l,rows:S,columns:o}}passStart(e,t){let n=this.pushed-this.size,r=this.passTrack;(!r||r.key!==e||r.clears!==this.clears)&&(r=this.passTrack={key:e,clears:this.clears,done:n,prevX:NaN,cuts:[]});let{x0:i,x1:a}=this.columnBounds(e),o=(a-i)/2;for(let e=Math.max(r.done,n);e<this.pushed;e++){let n=t[this.physOf(e)];Number.isNaN(n)||(n<r.prevX-o&&(r.cuts.push({abs:e,drop:r.prevX-n}),r.cuts.length>64&&r.cuts.shift()),r.prevX=n)}for(r.done=this.pushed;r.cuts.length>0&&r.cuts[0].abs<n;)r.cuts.shift();for(let e=r.cuts.length-1;e>=0;e--)if(r.cuts[e].drop>o)return r.cuts[e].abs;return n}timeIndex(e){let t=0,n=this.size;for(;t<n;){let r=t+n>>>1;this.time[this.full?(this.head+r)%this.capacity:r]<e?t=r+1:n=r}return t}foldBuckets(e,t,n,r,i){this.eachBucketRun(t,n,r,(t,n,r)=>e.fold(e.row(t),i,n,r))}eachBucketRun(e,t,n,r){if(t<=e)return;this.debugLastScan+=t-e;let i=this.time,a=e=>Math.floor(i[e]/n),o=(e,t)=>{let n=e;for(;n<t;){let e=a(n),i=n,o=1;for(;n+o<t&&a(n+o)===e;)i=n+o,o*=2;let s=i+1,c=Math.min(n+o,t);for(;s<c;){let t=s+c>>>1;a(t)===e?s=t+1:c=t}r(e,n,s),n=s}};if(!this.full)return o(e,t);let s=(this.head+e)%this.capacity,c=s+(t-e);if(c<=this.capacity)return o(s,c);o(s,this.capacity),o(0,c-this.capacity)}decimateTime(e,t,n,r){let i=this.timeBuckets(e,t,n,r);if(!i.store)return{x0:t,bucket:0,rows:[],columns:i.cols};let a=aK(i.cols.length),o=()=>i.store.toRows(i.i0,i.i1,a.row,a.lo,a.hi),s=this.historyDec;return{x0:0,bucket:i.bucket,rows:s?.store===i.store?s.rows??=o():o(),columns:i.cols}}decimatePoints(e,t,n,r,i){if(e===this.timeColumn&&this.timeMonotonic){let e=this.timeBuckets(t,n,r,i);return e.store?e.store.toPoints(e.i0,e.i1,e.cols):{length:0,x:new Float64Array,cols:new Map(e.cols.map(e=>[e,new Float64Array]))}}let a=this.decimateColumns(e,t,n,r,i);return VG(a.rows,a.columns,a.x0,a.bucket)}timeBuckets(e,t,n,r){let i=e.filter(e=>this.cols.has(e)),a=this.size,o={cols:i,bucket:0,store:null,i0:0,i1:0};if(i.length===0||!(n>t)||a===0)return o;let s=e=>this.full?(this.head+e)%this.capacity:e,c=this.time[s(0)],l=this.time[s(a-1)],u=(n-t)/r;if(a>1){let e=(l-c)/(a-1);e>0&&e<u&&(u=.7*Math.max(e,(n-t)/(r*mK)))}let d=nK(u),f=i.join(` `),p=this.timeDecs.get(f)??[],m=p.find(e=>u>=e.bucket*.5&&u<=e.bucket*2)??null;if(m&&(d=m.bucket),!(d>0))return o;let h=i.map(e=>this.cols.get(e)),g=Math.floor(t/d),_=Math.floor(n/d);this.debugLastScan=0;let v=e=>({cols:i,bucket:d,store:e,i0:e.lowerBound(g),i1:e.lowerBound(_+1)});if(n<l-(n-t)){let e=this.timeIndex(g*d),t=this.timeIndex((_+1)*d),n=this.pushed-a,r=`${f}|${d}|${g}|${_}|${n+e}|${n+t}|${this.clears}`;if(this.historyDec?.key!==r){let n=new eK(i.length,d);this.foldBuckets(n,e,t,d,h),this.historyDec={key:r,store:n}}return v(this.historyDec.store)}let y=m?this.pushed-m.pushed:0;if(m&&m.colsKey===f&&m.bucket===d&&y>=0&&y<a){let e=m.store;if(g<m.fromB){let t=new eK(i.length,d);this.foldBuckets(t,this.timeIndex(g*d),this.timeIndex(m.fromB*d),d,h);for(let n=t.end-1;n>=t.start;n--){let r=e.row(t.b[n]);for(let i=0;i<t.nc;i++)e.lo[i][r]=t.lo[i][n],e.hi[i][r]=t.hi[i][n]}m.fromB=g}y>0&&this.foldBuckets(e,a-y,a,d,h);let t=Math.floor(c/d);return this.full&&t>=m.fromB&&(e.dropBelow(t),e.reset(e.row(t)),this.foldBuckets(e,0,this.timeIndex((t+1)*d),d,h),m.fromB=t),g>m.fromB&&(e.dropBelow(g),m.fromB=g),m.pushed=this.pushed,v(e)}let b=new eK(i.length,d),x=this.timeIndex(g*d);this.foldBuckets(b,x,a,d,h);let S={colsKey:f,cols:i,bucket:d,store:b,pushed:this.pushed,fromB:x===0?Math.floor(c/d):g};return this.timeDecs.delete(f),this.timeDecs.set(f,[S,...p.filter(e=>e!==m&&e.bucket!==d)].slice(0,uK)),this.timeDecs.size>lK&&this.timeDecs.delete(this.timeDecs.keys().next().value),v(b)}lastValue(e){let t=e===this.timeColumn?this.time:this.cols.get(e);return!t||this.size===0?NaN:t[this.full?(this.head-1+this.capacity)%this.capacity:this.count-1]}xTravel(e,t){let n=this.columnArray(e),r=this.size;if(!n||r<2)return NaN;let i=e=>this.full?(this.head+e)%this.capacity:e,a=this.time[i(r-1)],o=0,s=NaN,c=a;for(let e=r-1;e>=0;e--){let r=i(e),l=this.time[r];if(l<a-t)break;let u=n[r];Number.isNaN(u)||(s>u&&(o+=s-u),s=u,c=l)}let l=a-c;return l>0&&l<t?o*t/l:o}timeAfter(e){if(!this.timeMonotonic)return NaN;let t=e=>this.full?(this.head+e)%this.capacity:e,n=0,r=this.size;for(;n<r;){let i=n+r>>>1;this.time[t(i)]<=e?n=i+1:r=i}return n<this.size?this.time[t(n)]:NaN}latestTime(){return this.size===0?NaN:this.columnBounds(this.timeColumn).x1}xAtTime(e,t,n=!1){let r=this.columnArray(e),i=this.size;if(!r||i===0)return NaN;if(e===this.timeColumn&&!n){let{x0:n,x1:r}=this.columnBounds(e);return Math.min(r,Math.max(n,t))}if(!this.timeMonotonic)return NaN;let a=e=>this.full?(this.head+e)%this.capacity:e,o=0,s=i-1;if(t<=this.time[a(0)])return r[a(0)];if(t>=this.time[a(s)])return r[a(s)];for(;s-o>1;){let e=o+s>>1;this.time[a(e)]<=t?o=e:s=e}let c=a(o),l=a(s),u=r[c],d=r[l];if(n||!(d>=u))return u;let f=this.time[c],p=this.time[l];return p>f?u+(d-u)*(t-f)/(p-f):u}boundsCache=new Map;columnBounds(e){let t=e===this.timeColumn?this.time:this.cols.get(e),n=this.size;if(!t||n===0)return{x0:0,x1:0};if(t===this.time&&this.timeMonotonic)return{x0:this.time[this.full?this.head:0],x1:this.time[this.full?(this.head+n-1)%this.capacity:n-1]};let r=this.pushed-n,i=this.boundsCache.get(e);if(i&&i.version===this.version)return i.b;(!i||i.clears!==this.clears||i.loAbs<r||i.hiAbs<r)&&(i={version:-1,clears:this.clears,done:r,lo:1/0,hi:-1/0,loAbs:1/0,hiAbs:1/0,b:{x0:0,x1:0}},this.boundsCache.set(e,i));for(let e=Math.max(i.done,r);e<this.pushed;e++){let n=t[this.physOf(e)];Number.isNaN(n)||(n<=i.lo&&(i.lo=n,i.loAbs=e),n>=i.hi&&(i.hi=n,i.hiAbs=e))}return i.done=this.pushed,i.version=this.version,i.b=Number.isFinite(i.lo)?{x0:i.lo,x1:i.hi}:{x0:0,x1:0},i.b}toDataset(e){let t=[this.timeColumn,...this.signalOrder],n=[this.timeUnit,...this.signalOrder.map(e=>this.unitByName.get(e)??``)],r=this.size,i=e&&e>0&&r>e?Math.ceil(r/e):1,a=i>1&&this.timeMonotonic?this.snapshotRows(e):null;if(a)return{meta:``,columnNames:t,units:n,rows:a};let o=this.pushed-r,s=i>1?(i-o%i)%i:0,c=[];for(let e=s;e<r;e+=i)c.push(this.full?(this.head+e)%this.capacity:e);r>0&&(c.length===0||(r-1-s)%i!=0)&&c.push(this.full?(this.head+r-1)%this.capacity:r-1);let l=e=>{let t=new Float64Array(c.length);for(let n=0;n<c.length;n++)t[n]=e[c[n]];return t};return{meta:``,columnNames:t,units:n,rows:oK(t,[l(this.time),...this.signalOrder.map(e=>l(this.cols.get(e)))])}}snapshotRows(e){let t=this.size,n=e=>this.full?(this.head+e)%this.capacity:e,r=this.time[n(0)],i=this.time[n(t-1)],a=(i-r)*2/e;if(!(a>0))return null;let o=`${this.signalOrder.join(`
|
|
83
|
-
`)}|${this.clears}`,s=this.signalOrder.map(e=>this.cols.get(e)),c=this.snapDec,l=c?this.pushed-c.pushed:0;if(c&&c.key===o&&c.bucket<a&&l>=0&&l<t){let e=2;for(;c.bucket*e<a;)e*=2;c.store.coarsen(e),c.bucket*=e,c.fromB=Math.floor(c.fromB/e)}if(c&&c.key===o&&c.bucket>=a&&c.bucket<=a*4&&l>=0&&l<t){let e=c.store;l>0&&this.foldBuckets(e,t-l,t,c.bucket,s);let n=Math.floor(r/c.bucket);this.full&&n>=c.fromB&&(e.dropBelow(n),e.reset(e.row(n)),this.foldBuckets(e,0,this.timeIndex((n+1)*c.bucket),c.bucket,s),c.fromB=n),c.pushed=this.pushed}else{let n=2**Math.ceil(Math.log2(a));n<a&&(n*=2);let i=new eK(s.length,n,Math.ceil(e/2)+8);this.foldBuckets(i,0,t,n,s),c=this.snapDec={key:o,bucket:n,store:i,pushed:this.pushed,fromB:Math.floor(r/n)}}let u=c.store.toPoints(c.store.start,c.store.end,this.signalOrder),d=new Float64Array(u.x),f=d[0],p=d[d.length-1];for(let e=0;e<d.length;e++)d[e]=d[e]===p?i:d[e]===f?r:d[e];return oK([this.timeColumn,...this.signalOrder],[d,...this.signalOrder.map(e=>new Float64Array(u.cols.get(e)))])}valueBounds(e){let t=this.columnBounds(e);return Number.isFinite(this.boundsCache.get(e)?.lo??NaN)?t:null}hasValues(e){return this.latest.has(e)||this.computed.has(e)}get valuedCount(){return this.latest.size}lastKnown(e){return this.latest.get(e)}setLastKnown(e,t,n,r){e===this.timeColumn||this.computed.has(e)||!Number.isFinite(n)||!Number.isFinite(r)||(this.cols.has(e)||(this.cols.set(e,this.newColumn()),this.signalOrder.push(e),this.unitByName.set(e,t)),this.noteValue(e,n,r))}noteValue(e,t,n){let r=this.latest.get(e);r?t>=r.t&&(r.t=t,r.v=n):this.latest.set(e,{t,v:n})}}}));function _K(){let e=globalThis.crypto;if(!e?.subtle)throw Error(`WebCrypto SubtleCrypto is not available`);return e.subtle}function vK(e){let t=``;for(let n=0;n<e.length;n++)t+=String.fromCharCode(e[n]);return btoa(t)}function yK(e){let t=atob(e),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n}async function bK(e,t){let n=new TextEncoder,r=await _K().importKey(`raw`,n.encode(e),`PBKDF2`,!1,[`deriveKey`]);return _K().deriveKey({name:`PBKDF2`,salt:yK(t),iterations:FK,hash:`SHA-256`},r,{name:`AES-GCM`,length:256},!1,[`encrypt`,`decrypt`])}function xK(){(!IK||LK>4294967295)&&(IK=globalThis.crypto.getRandomValues(new Uint8Array(8)),LK=0);let e=new Uint8Array(12);return e.set(IK),new DataView(e.buffer).setUint32(8,LK++),e}async function SK(e,t){let n=yK(t.iv),r=yK(t.ciphertext),i=await _K().decrypt({name:`AES-GCM`,iv:n},e,r);return new Uint8Array(i)}async function CK(e,t,n,r){let i=await _K().decrypt({name:`AES-GCM`,iv:t,additionalData:r},e,n);return new Uint8Array(i)}async function wK(e,t){return JSON.parse(new TextDecoder().decode(await SK(e,t)))}async function TK(e,t){try{return await wK(e,t)===PK}catch{return!1}}function EK(e){let t=RK.exec(e.trim());return t?{auth:t[1],secret:t[2]??null}:{auth:e,secret:null}}function DK(e){return _K().importKey(`raw`,e,{name:`AES-GCM`,length:256},!1,[`encrypt`,`decrypt`])}function OK(e,t,n){return kK(e,t,n)}async function kK(e,t,n,r){let i=r??xK(),a=new Uint8Array(await _K().encrypt({name:`AES-GCM`,iv:i,additionalData:new TextEncoder().encode(n)},e,t));return{iv:vK(i),ct:vK(a)}}async function AK(e,t,n){return new Uint8Array(await _K().decrypt({name:`AES-GCM`,iv:yK(t.iv),additionalData:new TextEncoder().encode(n)},e,yK(t.ct)))}function jK(e,t,n){return MK(e,t,n)}async function MK(e,t,n,r,i){let a=vK(r??globalThis.crypto.getRandomValues(new Uint8Array(16))),o=await kK(await bK(e,a),t,n,i);return{kdf:{name:`PBKDF2`,hash:`SHA-256`,iterations:FK,salt:a},...o}}async function NK(e,t,n){let r=t?.kdf;if(r?.name!==`PBKDF2`||r.hash!==`SHA-256`||r.iterations!==FK||typeof r.salt!=`string`)throw Error(`unsupported_kdf`);return AK(await bK(e,r.salt),t,n)}var PK,FK,IK,LK,RK,zK,BK=c((()=>{PK=`kymoscope-live-key-check-v1`,FK=6e5,IK=null,LK=0,RK=/^((?:kymoscope|prism)_[A-Za-z0-9_-]+)(?:\.([A-Za-z0-9_-]+))?$/,new TextEncoder().encode(`kymoscope-device-wrap-v1`),new TextEncoder().encode(`kymoscope-sender-bind-v1`),zK=`kymoscope-workbook-export-v2`}));function VK(e){let t=new Uint8Array(e),n=t.length>0&&t[0]&128?2:1;return t.length<n+UK+WK?null:{kind:t[0]&-129,keyId:n===2?t[1]:null,iv:t.subarray(n,n+UK),ciphertext:t.subarray(n+UK),aad:t.subarray(0,n)}}async function HK(e,t){let n=VK(t);if(!n)return null;let r=typeof e==`function`?await e(n.keyId):e;if(!r)return null;let i=await CK(r,n.iv,n.ciphertext,n.aad);return{kind:n.kind,plaintext:i}}var UK,WK,GK=c((()=>{BK(),UK=12,WK=16}));function KK(e){if(e.length!==YK||e[0]!==1)return null;let t=new DataView(e.buffer,e.byteOffset,e.byteLength);return{streamId:ZK(e.subarray(1,17)),run:XK(e.subarray(17,25)),lane:e[25],seq:t.getBigUint64(26,!0),count:t.getUint32(34,!0),hash:e.slice(38,70)}}async function qK(e){let t=await Promise.all(e),n=new Uint8Array(t.length*32);return t.forEach((e,t)=>n.set(new Uint8Array(e),t*32)),new Uint8Array(await $K(n))}function JK(e,t,n=()=>Date.now()){let r={verified:0,broken:0},i=null,a=0n,o=null,s=0,c=0,l=0,u=Promise.resolve(),d=e=>{e?r.verified++:(r.broken++,r.lastBrokenAt=n()),t({...r})};return{integrity:r,reset(){i=null,o=null,c=s,l++},arrive(t,n,r){if(n!==8){o&&(o.push($K(t)),s++);return}let f=s;o||(o=[],c=s);let p=l;u=u.then(async()=>{let t=await r.catch(()=>null);if(p!==l)return;let n=t?KK(t.plaintext):null;if(!n||n.lane!==0||n.streamId!==e.toLowerCase()){i!==null&&d(!1);return}let s=f-c;if(i===null||n.run!==i){i=n.run,a=n.seq,o=o.slice(Math.max(0,s)),c=Math.max(c,f);return}let u=n.seq===a+1n&&n.count<=s&&eq(await qK(o.slice(0,n.count)),n.hash);if(p!==l)return;a=n.seq;let m=u?n.count:s;o=o.slice(m),c+=m,d(u)})}}}var YK,XK,ZK,QK,$K,eq,tq=c((()=>{GK(),YK=70,XK=e=>Array.from(e,e=>e.toString(16).padStart(2,`0`)).join(``),ZK=e=>{let t=XK(e);return`${t.slice(0,8)}-${t.slice(8,12)}-${t.slice(12,16)}-${t.slice(16,20)}-${t.slice(20)}`},QK=()=>globalThis.crypto.subtle,$K=e=>QK().digest(`SHA-256`,e),eq=(e,t)=>e.length===t.length&&e.every((e,n)=>e===t[n])}));async function nq(e,t,n,r){let i=t[t.length-1];if(!i||(i.bytes[0]&127)!=8)return`unchecked`;let a=await n(i.bytes).catch(()=>null),o=a?KK(a.plaintext):null,s=aq(await iq(oq(e.recordingId))).slice(0,16);return o&&o.lane===1&&o.run===s&&o.seq===BigInt(e.seq)&&e.seq===r&&o.count===t.length-1&&aq((await qK(t.slice(0,-1).map(e=>iq(e.bytes)))).buffer)===aq(o.hash.buffer)?`verified`:`broken`}function rq(e){let t=[...e],n=new Set(t.filter(e=>e.check!==`unchecked`).map(e=>e.rid)),r={verified:0,broken:0,unchecked:0};for(let e of t)e.check===`unchecked`&&n.has(e.rid)?r.broken++:r[e.check]++;return r}var iq,aq,oq,sq=c((()=>{GK(),tq(),iq=e=>crypto.subtle.digest(`SHA-256`,e),aq=e=>Array.from(new Uint8Array(e),e=>e.toString(16).padStart(2,`0`)).join(``),oq=e=>Uint8Array.from(e.replace(/-/g,``).match(/../g)??[],e=>parseInt(e,16))}));function cq(e){if(e.byteLength<8)throw vq(`block schema`,`short`);let t=new DataView(e.buffer,e.byteOffset,e.byteLength);if(t.getUint8(0)!==fq)throw vq(`block schema`,`version ${t.getUint8(0)}`);let n=t.getUint16(2,!0),r=t.getUint32(4,!0),i=new TextDecoder(`utf-8`,{fatal:!0}),a=[],o=8;try{for(let r=0;r<n;r++){if(o+3>e.byteLength)throw vq(`block schema`,`short channel table`);let n=t.getUint8(o),r=t.getUint8(o+1),s=t.getUint8(o+2);if(o+=3,n!==4&&n!==8)throw vq(`block schema`,`value size ${n}`);if(o+r+s>e.byteLength)throw vq(`block schema`,`short channel table`);a.push({name:i.decode(e.subarray(o,o+r)),unit:i.decode(e.subarray(o+r,o+r+s)),size:n}),o+=r+s}}catch(e){throw e instanceof RangeError?e:vq(`block schema`,`invalid text`)}return{id:r,channels:a}}function lq(e,t){if(e.byteLength<12)throw vq(`last values`,`short`);let n=new DataView(e.buffer,e.byteOffset,e.byteLength);if(n.getUint8(0)!==pq)throw vq(`last values`,`version ${n.getUint8(0)}`);let r=t.get(n.getUint32(4,!0));if(!r)return null;let i=n.getUint32(8,!0);if(i!==r.channels.length)throw vq(`last values`,`channel count differs from its schema`);if(e.byteLength<12+16*i)throw vq(`last values`,`short`);let a=[];for(let e=0;e<i;e++){let t=n.getFloat64(12+8*e,!0),o=n.getFloat64(12+8*(i+e),!0);Number.isFinite(t)&&Number.isFinite(o)&&a.push({name:r.channels[e].name,unit:r.channels[e].unit,t,v:o})}return a}async function uq(e,t){let n=new Blob([e]).stream().pipeThrough(new DecompressionStream(`deflate`)).getReader(),r=new Uint8Array(t),i=0;try{for(;;){let{done:e,value:a}=await n.read();if(e)break;if(i+a.length>t)throw vq(`block`,`body larger than its header says`);r.set(a,i),i+=a.length}}catch(e){throw await n.cancel().catch(()=>{}),e instanceof RangeError?e:vq(`block`,`body is not valid deflate`)}if(i!==t)throw vq(`block`,`body size mismatch`);return r}async function dq(e,t){if(e.byteLength<gq)throw vq(`block`,`short`);let n=new DataView(e.buffer,e.byteOffset,e.byteLength);if(n.getUint8(0)!==fq)throw vq(`block`,`version ${n.getUint8(0)}`);let r=n.getUint8(1),i=n.getUint16(2,!0),a=n.getUint32(4,!0),o=t.get(n.getUint32(8,!0));if(!o)return null;if(o.channels.length!==i)throw vq(`block`,`channel count differs from its schema`);let s=n.getFloat64(12,!0),c=Math.max(0,a-1),l=4*c+o.channels.reduce((e,t)=>e+t.size*a,0);if(l>_q)throw vq(`block`,`too large`);let u;if(r&mq)u=await uq(e.subarray(gq),l);else if(u=e.subarray(gq),u.byteLength<l)throw vq(`block`,`body size mismatch`);let d=new DataView(u.buffer,u.byteOffset,u.byteLength),f=new Float64Array(a),p=0;a&&(f[0]=s);for(let e=1;e<a;e++)p+=d.getInt32(4*(e-1),!0),f[e]=s+p/1e6;let m=4*c,h={},g={};for(let e of o.channels){let t=new Uint8Array(a*e.size);for(let n=0;n<e.size;n++)for(let r=0;r<a;r++)t[r*e.size+n]=u[m+n*a+r];h[e.name]=e.size===4?new Float32Array(t.buffer):new Float64Array(t.buffer),e.unit&&(g[e.name]=e.unit),m+=a*e.size}return{block:{t:f,columns:h,units:g},historical:(r&hq)!==0}}var fq,pq,mq,hq,gq,_q,vq,yq=c((()=>{fq=2,pq=1,mq=1,hq=2,gq=20,_q=64*1024*1024,vq=(e,t)=>RangeError(`${e}: ${t}`)}));function bq(e){let t=Array.from(e,e=>e.toString(16).padStart(2,`0`)).join(``);return`${t.slice(0,8)}-${t.slice(8,12)}-${t.slice(12,16)}-${t.slice(16,20)}-${t.slice(20)}`}function xq(e){if(e.length<56||Cq.some((t,n)=>e[n]!==t))throw RangeError(`not a KRC1 chunk`);let t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=t.getUint16(4,!0);if(n!==1)throw RangeError(`KRC version ${n}`);let r=t.getUint16(6,!0);if(r<56)throw RangeError(`KRC header too short`);return{recordingId:bq(e.subarray(8,24)),seq:t.getUint32(24,!0),count:t.getUint32(28,!0),bytes:t.getUint32(32,!0),headerBytes:r,t0:t.getFloat64(40,!0),t1:t.getFloat64(48,!0)}}function Sq(e){let t=xq(e),n=new DataView(e.buffer,e.byteOffset,e.byteLength),r=Math.min(e.length,t.bytes),i=[],a=t.headerBytes;for(;i.length<t.count&&a+12<=r;){let t=n.getUint32(a+8,!0);if(a+12+t>r)break;i.push({at:n.getFloat64(a,!0),bytes:e.subarray(a+12,a+12+t)}),a+=12+t}return{header:t,messages:i,truncated:i.length<t.count}}var Cq,wq=c((()=>{Cq=[75,82,67,49]}));function Tq(e){let t=new Map;return async n=>{if(n.length===0)return null;let r=n[0]&128?2:1;if(n.length<r+Eq+Dq)return null;let i=r===2?n[1]:null,a=t.get(i),o=[...a?[a]:[],...e.filter(e=>(e.keyId===i||e.keyId===null)&&e.key!==a).map(e=>e.key)];for(let e of o)try{let a=await CK(e,n.subarray(r,r+Eq),n.subarray(r+Eq),n.subarray(0,r));return t.set(i,e),{kind:n[0]&-129,plaintext:a}}catch{}return null}}var Eq,Dq,Oq=c((()=>{BK(),GK(),Eq=12,Dq=16}));async function*kq(e){let t=0;for(;t+56<=e.size;){let n=xq(await e.read(t,56));if(yield await e.slice(t,n.bytes),n.bytes<=56)return;t+=n.bytes}}function Aq(e){let t=e.filter(e=>e&&typeof e.t==`number`&&Array.isArray(e.signals)),n={},r={};return t.forEach((e,i)=>{for(let a of e.signals){if(!a||typeof a.name!=`string`)continue;let e=n[a.name]??=new Float64Array(t.length).fill(NaN);e[i]=typeof a.value==`number`?a.value:NaN,a.unit&&!r[a.name]&&(r[a.name]=a.unit)}}),{t:t.map(e=>e.t),columns:n,units:r}}function jq(e){let t=2166136261^e.length;for(let n=0,r=Math.min(e.length,64);n<r;n++)t=Math.imul(t^e[n],16777619);return t>>>0}async function*Mq(e,t,n,r,i=!1){let a=Tq(e.keys??[]),o=new Map,s=new Map,c=r?null:new Lq,l=null,u=0,d=e=>c?(c.sampled(e.columns),e.t.length&&(l=+e.t[e.t.length-1],u=e.at),c.start(e)):e,f={results:[]};for await(let e of kq(t)){let{header:t,messages:l}=Sq(e);if(n.t0??=t.t0,i){let e=t.recordingId;f.results.push({rid:e,check:await nq(t,l,a,f.rid===e?(f.seq??-1)+1:0)}),f.rid=e,f.seq=t.seq,n.chain=rq(f.results)}for(let e of l){let t=jq(e.bytes),i=s.get(t);if(i&&Iq(i,e.bytes))continue;s.set(t,e.bytes),s.size>Fq&&s.delete(s.keys().next().value);let l=await a(e.bytes);if(!l){n.lost++;continue}try{if(l.kind===5){let e=cq(l.plaintext);o.set(e.id,e);continue}if(l.kind===4){let t=await dq(l.plaintext,o);if(!t){n.lost++;continue}let i={at:e.at,t:t.block.t,columns:t.block.columns,units:t.block.units??{},historical:t.historical};t.historical&&c?.sampled(i.columns),(r===void 0||r===!!t.historical)&&(yield t.historical?i:d(i));continue}if(r)continue;if(l.kind===7){let e=lq(l.plaintext,o);e&&c?.note(e)}else if(l.kind===3){let t=LG(l.plaintext);yield d({at:e.at,t:t.t,columns:t.columns,units:t.units??{}})}else if(l.kind===2){let t=PG(l.plaintext);yield d({at:e.at,...Aq(Array.isArray(t?.frames)?t.frames:[])})}}catch{n.lost++}}}let p=c?.end(l,u);p&&(yield p)}function Nq(e,t,n){let r=e===null?t:t===null?e:Math.min(e,t);return r===null?{}:r>1e9?{wallOrigin:String(r),wallQuality:`exact`}:Number.isFinite(n)?{wallOrigin:String(r+n),wallQuality:`approx`}:{}}var Pq,Fq,Iq,Lq,Rq,zq=c((()=>{IG(),BG(),gK(),GK(),sq(),yq(),wq(),Oq(),Pq=8192,Fq=4096,Iq=(e,t)=>e.length===t.length&&e.every((e,n)=>e===t[n]),Lq=class{known=new Map;real=new Set;pending=new Set;held=new Set;note(e){for(let t of e){let e=this.known.get(t.name);(!e||t.t>=e.t)&&this.known.set(t.name,{t:t.t,v:t.v,unit:t.unit}),!this.real.has(t.name)&&!this.held.has(t.name)&&this.pending.add(t.name)}}sampled(e){for(let t of[this.pending,this.held])for(let n of t){let r=e[n];if(r){for(let e=0;e<r.length;e++)if(Number.isFinite(r[e])){this.real.add(n),t.delete(n);break}}}}start(e){if(this.pending.size===0||e.t.length===0)return e;let t={...e.columns},n={...e.units};for(let r of this.pending){let i=this.known.get(r),a=new Float64Array(e.t.length).fill(NaN);a[0]=i.v,t[r]=a,i.unit&&!n[r]&&(n[r]=i.unit),this.held.add(r)}return this.pending.clear(),{...e,columns:t,units:n}}end(e,t){if(e===null||this.held.size===0)return null;let n={},r={};for(let e of this.held){let t=this.known.get(e);n[e]=Float64Array.of(t.v),t.unit&&(r[e]=t.unit)}return{at:t,t:[e],columns:n,units:r}}},Rq={id:`krc`,label:`Kymoscope recording`,extensions:[],sniff:()=>!1,async plan(e,t){let n=[dK],r=new Map([[dK,`s`]]),i={lost:0,t0:null},a=0,o=!1,s=null,c=null,l=0,u=-1/0,d=0,f=1/0;for await(let p of Mq(e,t,i,void 0,!0)){a+=p.t.length,p.historical&&(o=!0);let e=p.t.length;e&&p.historical?c??=+p.t[0]:e&&(s??=+p.t[0],+p.t[0]+l<u&&(l=u+Math.max(0,(p.at-d)/1e3)-+p.t[0]),d=p.at,u=+p.t[e-1]+l,f=Math.min(f,p.at/1e3-u));for(let e of Object.keys(p.columns))e!==`ElapsedTime`&&(r.has(e)?!r.get(e)&&p.units[e]&&r.set(e,p.units[e]):(n.push(e),r.set(e,p.units[e]??``)))}let p=n.map(e=>({name:e,unit:r.get(e)??``})),m=i.lost?[`${i.lost} ${i.lost===1?`message`:`messages`} couldn't be opened with the keys this browser has.`]:[],h=i.chain?.broken??0;return h&&m.push(`Some of this recording was missing, out of order or changed where it is stored (${h} of ${h+(i.chain?.verified??0)} checked ${h+(i.chain?.verified??0)===1?`chunk`:`chunks`}).`),{format:`Kymoscope recording`,startTime:i.t0===null?null:new Date(i.t0).toISOString(),groups:[{name:`Recording`,channels:p,samples:a,time:{kind:`timestamps`},rateHz:null}],meta:{...Nq(s,c,f),...i.chain&&(i.chain.verified||i.chain.broken)?{chainVerified:String(i.chain.verified),chainBroken:String(i.chain.broken),chainUnchecked:String(i.chain.unchecked)}:{}},events:[],notes:m,state:{names:n,backlog:o}}},async*stream(e){let{names:t,backlog:n=!1}=e.plan.state,r=e.selection.find(e=>e.group===0)?.channels??[],i=new Map(r.map((e,n)=>[t[e],n])),a=i.get(dK),o=()=>r.map(()=>new Float64Array(Pq).fill(NaN)),s=new Float64Array(Pq),c=o(),l=0,u=0,d=0,f=-1/0,p=0,m=null,h=()=>{let e={group:0,time:s.slice(0,l),start:u,length:l,columns:c.map(e=>e.slice(0,l))};return u+=l,l=0,s=new Float64Array(Pq),c=o(),e};function*g(e){let t=e.t.length;for(let n=0;n<t;){let r=Math.min(t-n,Pq-l);for(let t=0;t<r;t++){let r=+e.t[n+t]+d;m??=r,s[l+t]=r-m}if(a!==void 0)for(let t=0;t<r;t++)c[a][l+t]=+e.t[n+t];for(let[t,a]of Object.entries(e.columns)){let e=t===`ElapsedTime`?void 0:i.get(t);if(e===void 0)continue;let o=c[e];if(a instanceof Float64Array||a instanceof Float32Array)o.set(a.subarray(n,n+r),l);else for(let e=0;e<r;e++)o[l+e]=+a[n+e]}l+=r,n+=r,l===Pq&&(yield h())}}let _=n?Mq(e.files,e.io,{lost:0,t0:null},!0):null,v=async()=>{for(let e=await _?.next();e&&!e.done;e=await _.next())if(e.value.t.length)return e.value;return null},y=await v();for await(let t of Mq(e.files,e.io,{lost:0,t0:null},n?!1:void 0)){if(e.signal?.aborted)return;let n=t.t.length;if(n!==0){for(+t.t[0]+d<f&&(d=f+Math.max(0,(t.at-p)/1e3)-+t.t[0]),p=t.at;y&&+y.t[0]<+t.t[0];y=await v())yield*g(y);yield*g(t),f=+t.t[n-1]+d}}for(;y&&!e.signal?.aborted;y=await v())yield*g(y);l>0&&(yield h())}}})),Bq=u({IMPORTERS:()=>Hq,importerFor:()=>Vq});function Vq(e){let t=Hq[e];if(!t)throw Error(`No importer for format ${e}.`);return t}var Hq,Uq=c((()=>{MH(),RH(),QH(),wU(),tW(),AW(),BW(),zq(),Hq={mdf:jH,edf:LH,xdf:ZH,tdms:CU,hdf5:eW,mat:kW,comtrade:zW,krc:Rq}}));qz(),gz();var Wq=()=>new SE(`cancelled`);function Gq(){let e=CE(Jz);return e.postMessage({type:`init`,h5Url:new URL(Yz,location.href).href}),e}var Kq=null,qq=e=>{typeof requestIdleCallback==`function`?requestIdleCallback(e,{timeout:5e3}):setTimeout(e,1e3)};function Jq(e,t=Gq){t===Gq&&typeof Worker>`u`||(Kq&&Kq.make!==t&&(Kq.w.terminate(),Kq=null),Kq??={w:t(),h5:!1,make:t},e&&!Kq.h5&&(Kq.h5=!0,Kq.w.postMessage({type:`warm`})))}function Yq(e){if(Kq?.make!==e)return{w:e(),rewarm:null};let{w:t,h5:n}=Kq;return Kq=null,{w:t,rewarm:n}}function Xq(e,t,n,r,i){return!r&&typeof Worker>`u`?Zq(e,t,n,i):$q(e,t,n,r??Gq)}function Zq(e,t,n,r=async e=>(await Promise.resolve().then(()=>(Uq(),Bq))).importerFor(e)){let i=new Kz(t.main),a=null,o=null,s=e=>e.catch(e=>{throw n?.aborted?Wq():oz(e)});return{plan:()=>s((async()=>(a=await r(e),o=await Lz(a,t,i)))()),read:(e,r,c={})=>(i.bytesRead=0,s(Hz(a,t,o,i,e,r,{...c,signal:n}))),close(){}}}var Qq=3e4;function $q(e,t,n,r){let{w:i,rewarm:a}=Yq(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>Qq&&p(Error(sz))},1e3),h=()=>p(Wq());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(Wq());return}if(d){a(Error(sz));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&&qq(()=>Jq(a,r))}}}Qe();var eJ=12e3,tJ=(e,t)=>t.map(t=>({group:t,channels:e.groups[t].channels.map((e,t)=>t)}));function nJ(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 rJ(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:nJ(e,n)}:null,splitKey:r,channels:n.reduce((e,t)=>e+t.channels.length,0),notes:e.notes,meta:e.meta,events:[]}}async function iJ(e,t,n,r,i,a){let o={meta:``,columnNames:n.columns.map(e=>e.name),units:n.columns.map(e=>e.unit),rows:qe(n.table)},s=new VE(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 aJ(e,t,n,r,i,a,o,s,c){let l=BL().then(e=>e.connect());l.catch(()=>void 0);let u=nR(),d=zz(r,i),f=new iz({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 cR.attach(p,u,new Map(d.map(e=>[e.name,e.unit]))),h=await m.getSchema(),g=await m.sampleRows(eJ);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 ${VL(u)}`).catch(()=>void 0),await t?.close().catch(()=>void 0),e}}async function oJ(e,t){let{main:n,companions:r}=e,i=Xq(e.format,{main:n,companions:r,keys:e.keys},t.signal,t.createWorker,t.find),a=[];try{t.priorInMemoryValues+n.size/8>1e8&&BL().catch(()=>void 0);let o=await i.plan(),s=t.selection??t.initial??tJ(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=>Vz(o,e,n.size),budget:lR,used:t.priorInMemoryValues,notes:o.notes});if(!e)throw new SE(`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=Vz(o,s,n.size),f=l.length>1?`${n.name} · ${o.groups[s[0].group].name}`:n.name,p=rJ(o,e.format,s,u),m=crypto.randomUUID();if(dR(0,c,d)===`memory`){let e=await i.read(s,`memory`,{progress:t.onProgress});a.push(await iJ(m,f,e,n,r,p)),d+=c}else a.push(await aJ(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 SE(`cancelled`):e}finally{i.close()}}function sJ(e){return e.filter(e=>e.type===`number`).map(e=>e.name)}function cJ(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 lJ(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 uJ(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 dJ(e){return Math.max(2,Math.min(6,Math.floor(e/64)))}function fJ(e,t,n,r){let i=Math.max(e,t)-Math.min(e,t),a=n!==void 0&&n>0&&Number.isFinite(n)?n:uJ(i,6);(a<=0||!Number.isFinite(a))&&(a=uJ(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 pJ(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 mJ(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 hJ={[-12]:`p`,[-9]:`n`,[-6]:`µ`,[-3]:`m`,0:``,3:`k`,6:`M`,9:`G`,12:`T`};function gJ(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 _J(e,t){if(!Number.isFinite(e))return`—`;if(!(t>0)||!Number.isFinite(t))return vJ(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(gJ(t/10**r))+hJ[r]}return e.toFixed(gJ(t))}function vJ(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)+hJ[n]}var yJ=946684800,bJ=4102444800;function xJ(e,t,n){return/\(([^)]*)\)\s*$/.exec(e)?.[1].trim()===`s`&&n>t&&t>=yJ&&n<=bJ}var SJ=new Map;function CJ(e){let t=SJ.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=CJ(void 0)}SJ.set(e,t)}return t}var wJ=new Map,TJ=(e,t)=>{let n=Math.round(e*1e3),r=Math.floor(n/1e3),i=`${t??``}|${r}`,a=wJ.get(i);if(!a){let e={};for(let{type:n,value:i}of CJ(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}`},wJ.size>=1024&&wJ.clear(),wJ.set(i,a)}return{...a,ms:String(n-r*1e3).padStart(3,`0`)}},EJ,DJ=new Set,OJ=()=>EJ;function kJ(e){return DJ.add(e),()=>{DJ.delete(e)}}function AJ(e,t,n,r=EJ){let i=TJ(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 jJ(e,t=EJ){let n=TJ(e,t);return`${n.date} ${n.year} ${n.hms}.${n.ms}`}var MJ=[`#fb923c`,`#60a5fa`,`#4ade80`,`#f87171`,`#facc15`,`#22d3ee`,`#f472b6`,`#2dd4bf`,`#94a3b8`,`#a3e635`];function NJ(e,t,n,r=MJ){let i=r.length>0?r:MJ;return e[t]??i[n%i.length]}function PJ(e){return[e===`light`?`#000000`:`#ffffff`,...MJ.slice(0,9)]}function FJ(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:PJ(t)}var IJ=[`class`,`data-theme`,`data-color-scheme`];function LJ(e){return e?.closest(`[data-color-scheme]`)??document.documentElement}function RJ(e){return LJ(e).getAttribute(`data-color-scheme`)===`light`?`light`:`dark`}function zJ(e,t){let n=new MutationObserver(t),r=new Set([document.documentElement,LJ(e)]);for(let e of r)n.observe(e,{attributes:!0,attributeFilter:IJ});return()=>n.disconnect()}var BJ=[{value:`span`,label:`Span (max − min)`},{value:`mean`,label:`Mean`},{value:`max`,label:`Max`},{value:`min`,label:`Min`}];function VJ(e,t){let n=[],r=Ew(),i=-1;for(let a=0;a<e.length;a++){let o=e[a][t];if(typeof o!=`number`)continue;let s=Dw(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 HJ(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 UJ(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 WJ(e,t){return t.trim()===`s`||/time/i.test(e)}function GJ(e,t){return`${e}::lap${t}`}BK();var KJ=(e,t,n)=>`kymoscope-workbook-export|3|${e}|${t??``}|${n??``}`,qJ=e=>new TextEncoder().encode(e);async function JJ(e,t){return{format:`kymoscope-workbook`,v:2,...await jK(t,qJ(JSON.stringify(e)),zK)}}async function YJ(e,t){let n=t.password?JSON.stringify(await JJ(e,t.password)):JSON.stringify(e),r=await OK(await DK(t.key),qJ(n),KJ(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 XJ(e){return!!e&&typeof e==`object`&&e.format===`kymoscope-workbook`}function ZJ(e){return XJ(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 QJ=e=>{try{return JSON.parse(new TextDecoder().decode(e))}catch{throw new SE(`bad_file`)}};async function $J(e,t){let n=ZJ(e);if(!n)throw new SE(`bad_file`);let r=e;if(n.v===3){let i=e;if(!t.key)throw new SE(`scope_key_required`,{scope:n.scope,scopeId:n.scopeId});let a;try{a=await AK(await DK(t.key),i,KJ(i.scope,i.scope_id,i.inner))}catch{throw new SE(`bad_file`)}if(r=QJ(a),!n.password)return r;if(r?.v!==2||!XJ(r))throw new SE(`bad_file`)}if(!t.password)throw new SE(`password_required`);let i;try{i=await NK(t.password,r,zK)}catch{throw new SE(`wrong_password`)}return QJ(i)}var eY=new Set(Object.keys(T));function tY(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`||!eY.has(n)||!r||![r.x,r.y,r.w,r.h].every(e=>typeof e==`number`&&Number.isFinite(e))?[]:[{...e,rect:D(n,r,96)}]}):[]}var nY=e=>({name:e.name,xKey:e.xKey,panels:e.panels,panelChartSettings:e.panelChartSettings,panelChartBackgrounds:e.panelChartBackgrounds,...e.liveWindowSeconds===void 0?{}:{liveWindowSeconds:e.liveWindowSeconds}});function rY(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 iY(e){return{version:2,worksheets:e.worksheets.map(e=>({...nY(e),panelChartSettings:rY(e.panelChartSettings)})),activeWorksheet:Math.max(0,e.worksheets.findIndex(t=>t.id===e.activeWorksheetId)),mathChannels:e.channels.map(e=>({name:e.name,formula:e.formula,units:e.units,enabled:e.enabled,...e.description?{description:e.description}:{}})),liveWindowSeconds:e.liveWindowSeconds,laps:e.laps?{channel:e.laps.channel,metric:e.laps.metric,stat:e.laps.stat}:null,...e.cycles?.length?{cycles:e.cycles}:{}}}function aY(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 oY(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 sY(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 cY(e){let t=await sY(e),n;try{n=JSON.parse(t)}catch{return{worksheets:[],errors:[`Not a valid JSON file.`]}}return mY(n)}var lY=new Set(BJ.map(e=>e.value)),uY=/^(#(?:[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 dY(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):uY.test(e.trim())}function fY(e){if(Array.isArray(e))return e.map(fY);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`&&!dY(r)||(t[n]=r&&typeof r==`object`?fY(r):r);return t}function pY(e){return!e||typeof e!=`object`?{}:Object.fromEntries(Object.entries(e).filter(([,e])=>e===null||dY(e)))}function mY(e){let t=e,n=t&&typeof t==`object`?t.version:void 0;if(!t||n!==1&&n!==2||!Array.isArray(t.worksheets))return{worksheets:[],errors:[`Unrecognized format. Is this a Kymoscope workbook file?`],activeIndex:0,mathChannels:[],liveWindowSeconds:void 0,laps:void 0,cycles:[]};let r=[],i=[];if(t.worksheets.forEach((e,t)=>{let n=e;if(typeof n?.name!=`string`||typeof n.xKey!=`string`){i.push(`Worksheet #${t+1} skipped: missing name or xKey.`);return}r.push({id:crypto.randomUUID(),name:n.name,xKey:n.xKey,panels:tY(n.panels),panelChartSettings:fY(n.panelChartSettings),panelChartBackgrounds:pY(n.panelChartBackgrounds),...He(n.liveWindowSeconds)})}),n===1)return{worksheets:r,errors:i,activeIndex:0,mathChannels:[],liveWindowSeconds:void 0,laps:void 0,cycles:[]};let a=(Array.isArray(t.mathChannels)?t.mathChannels:[]).flatMap(e=>{let t=e;return typeof t?.name!=`string`||!t.name.trim()||typeof t.formula!=`string`?[]:[{name:t.name,formula:t.formula,units:typeof t.units==`string`?t.units:``,enabled:t.enabled!==!1,...typeof t.description==`string`&&t.description?{description:t.description}:{}}]}),o=t.liveWindowSeconds,s=t.laps,c=s&&typeof s.channel==`string`&&typeof s.metric==`string`&&lY.has(s.stat)?{channel:s.channel,metric:s.metric,stat:s.stat}:null,l=typeof t.activeWorksheet==`number`&&Number.isInteger(t.activeWorksheet)?t.activeWorksheet:0;return{worksheets:r,errors:i,mathChannels:a,laps:c,cycles:Gw(t.cycles),activeIndex:Math.min(Math.max(0,l),Math.max(0,r.length-1)),liveWindowSeconds:o===null||typeof o==`number`&&o>0?o:void 0}}function hY(e){return e.some(e=>e.panels.length>0)}function gY(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:tY(t.panels),panelChartSettings:fY(t.panelChartSettings),panelChartBackgrounds:pY(t.panelChartBackgrounds),...He(t.liveWindowSeconds)}}function _Y(e){if(!e||typeof e!=`object`)return null;let t=e,n=t.kind;if(typeof n!=`string`||!eY.has(n))return null;let r=Be({__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 vY(e){let t=await sY(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=ZJ(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=gY(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=_Y(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 cY(e);return i.worksheets.length===0&&i.errors.length>0?{type:`error`,errors:i.errors}:{type:`workspace`,worksheets:i.worksheets,errors:i.errors}}var yY=tz;function bY(e){let t=e.toLowerCase();return!t.startsWith(`.`)&&yY.some(e=>t.endsWith(e))}function xY(e,t=``){let n={name:t,path:``,dirs:[],files:[],allPaths:[]};for(let t of e){if(!bY(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 SY(e){return e.map(e=>({path:e.webkitRelativePath||e.name,file:e}))}async function CY(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 wY(){return typeof window.showDirectoryPicker==`function`}async function TY(){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 EY={1:`dohstRIUBeOkkAXOTXhhEkXanWzz-V4M518JBqTehRM`};function DY(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 OY(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 kY(e){try{let t=JSON.parse(new TextDecoder().decode(DY(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 AY(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=kY(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`,DY(s),`Ed25519`,!1,[`verify`]);c=await crypto.subtle.verify(`Ed25519`,e,DY(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=>OY(e,t))?{ok:!0,sub:a.sub,exp:a.exp}:{ok:!1,reason:`domain`}:{ok:!1,reason:`bad_signature`}}function jY(e,t){return AY(e,t,EY,Date.now()/1e3)}var X={sans:`system-ui, sans-serif`,mono:`ui-monospace, monospace`};function MY(e){let t=e.getTransform().a||1;e.font=`13px ${X.sans}`,e.textAlign=`center`,e.textBaseline=`middle`,e.fillText(`No data to plot`,e.canvas.width/t/2,e.canvas.height/t/2)}var NY=l((e=>{var t=Symbol.for(`react.transitional.element`),n=Symbol.for(`react.portal`),r=Symbol.for(`react.fragment`),i=Symbol.for(`react.strict_mode`),a=Symbol.for(`react.profiler`),o=Symbol.for(`react.consumer`),s=Symbol.for(`react.context`),c=Symbol.for(`react.forward_ref`),l=Symbol.for(`react.suspense`),u=Symbol.for(`react.memo`),d=Symbol.for(`react.lazy`),f=Symbol.for(`react.activity`),p=Symbol.iterator;function m(e){return typeof e!=`object`||!e?null:(e=p&&e[p]||e[`@@iterator`],typeof e==`function`?e:null)}var h={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},g=Object.assign,_={};function v(e,t,n){this.props=e,this.context=t,this.refs=_,this.updater=n||h}v.prototype.isReactComponent={},v.prototype.setState=function(e,t){if(typeof e!=`object`&&typeof e!=`function`&&e!=null)throw Error(`takes an object of state variables to update or a function which returns an object of state variables.`);this.updater.enqueueSetState(this,e,t,`setState`)},v.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,`forceUpdate`)};function y(){}y.prototype=v.prototype;function b(e,t,n){this.props=e,this.context=t,this.refs=_,this.updater=n||h}var x=b.prototype=new y;x.constructor=b,g(x,v.prototype),x.isPureReactComponent=!0;var S=Array.isArray;function C(){}var w={H:null,A:null,T:null,S:null},T=Object.prototype.hasOwnProperty;function E(e,n,r){var i=r.ref;return{$$typeof:t,type:e,key:n,ref:i===void 0?null:i,props:r}}function D(e,t){return E(e.type,t,e.props)}function O(e){return typeof e==`object`&&!!e&&e.$$typeof===t}function k(e){var t={"=":`=0`,":":`=2`};return`$`+e.replace(/[=:]/g,function(e){return t[e]})}var A=/\/+/g;function j(e,t){return typeof e==`object`&&e&&e.key!=null?k(``+e.key):t.toString(36)}function M(e){switch(e.status){case`fulfilled`:return e.value;case`rejected`:throw e.reason;default:switch(typeof e.status==`string`?e.then(C,C):(e.status=`pending`,e.then(function(t){e.status===`pending`&&(e.status=`fulfilled`,e.value=t)},function(t){e.status===`pending`&&(e.status=`rejected`,e.reason=t)})),e.status){case`fulfilled`:return e.value;case`rejected`:throw e.reason}}throw e}function N(e,r,i,a,o){var s=typeof e;(s===`undefined`||s===`boolean`)&&(e=null);var c=!1;if(e===null)c=!0;else switch(s){case`bigint`:case`string`:case`number`:c=!0;break;case`object`:switch(e.$$typeof){case t:case n:c=!0;break;case d:return c=e._init,N(c(e._payload),r,i,a,o)}}if(c)return o=o(e),c=a===``?`.`+j(e,0):a,S(o)?(i=``,c!=null&&(i=c.replace(A,`$&/`)+`/`),N(o,r,i,``,function(e){return e})):o!=null&&(O(o)&&(o=D(o,i+(o.key==null||e&&e.key===o.key?``:(``+o.key).replace(A,`$&/`)+`/`)+c)),r.push(o)),1;c=0;var l=a===``?`.`:a+`:`;if(S(e))for(var u=0;u<e.length;u++)a=e[u],s=l+j(a,u),c+=N(a,r,i,s,o);else if(u=m(e),typeof u==`function`)for(e=u.call(e),u=0;!(a=e.next()).done;)a=a.value,s=l+j(a,u++),c+=N(a,r,i,s,o);else if(s===`object`){if(typeof e.then==`function`)return N(M(e),r,i,a,o);throw r=String(e),Error(`Objects are not valid as a React child (found: `+(r===`[object Object]`?`object with keys {`+Object.keys(e).join(`, `)+`}`:r)+`). If you meant to render a collection of children, use an array instead.`)}return c}function P(e,t,n){if(e==null)return e;var r=[],i=0;return N(e,r,``,``,function(e){return t.call(n,e,i++)}),r}function F(e){if(e._status===-1){var t=e._result;t=t(),t.then(function(t){(e._status===0||e._status===-1)&&(e._status=1,e._result=t)},function(t){(e._status===0||e._status===-1)&&(e._status=2,e._result=t)}),e._status===-1&&(e._status=0,e._result=t)}if(e._status===1)return e._result.default;throw e._result}var I=typeof reportError==`function`?reportError:function(e){if(typeof window==`object`&&typeof window.ErrorEvent==`function`){var t=new window.ErrorEvent(`error`,{bubbles:!0,cancelable:!0,message:typeof e==`object`&&e&&typeof e.message==`string`?String(e.message):String(e),error:e});if(!window.dispatchEvent(t))return}else if(typeof process==`object`&&typeof process.emit==`function`){process.emit(`uncaughtException`,e);return}console.error(e)},L={map:P,forEach:function(e,t,n){P(e,function(){t.apply(this,arguments)},n)},count:function(e){var t=0;return P(e,function(){t++}),t},toArray:function(e){return P(e,function(e){return e})||[]},only:function(e){if(!O(e))throw Error(`React.Children.only expected to receive a single React element child.`);return e}};e.Activity=f,e.Children=L,e.Component=v,e.Fragment=r,e.Profiler=a,e.PureComponent=b,e.StrictMode=i,e.Suspense=l,e.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=w,e.__COMPILER_RUNTIME={__proto__:null,c:function(e){return w.H.useMemoCache(e)}},e.cache=function(e){return function(){return e.apply(null,arguments)}},e.cacheSignal=function(){return null},e.cloneElement=function(e,t,n){if(e==null)throw Error(`The argument must be a React element, but you passed `+e+`.`);var r=g({},e.props),i=e.key;if(t!=null)for(a in t.key!==void 0&&(i=``+t.key),t)!T.call(t,a)||a===`key`||a===`__self`||a===`__source`||a===`ref`&&t.ref===void 0||(r[a]=t[a]);var a=arguments.length-2;if(a===1)r.children=n;else if(1<a){for(var o=Array(a),s=0;s<a;s++)o[s]=arguments[s+2];r.children=o}return E(e.type,i,r)},e.createContext=function(e){return e={$$typeof:s,_currentValue:e,_currentValue2:e,_threadCount:0,Provider:null,Consumer:null},e.Provider=e,e.Consumer={$$typeof:o,_context:e},e},e.createElement=function(e,t,n){var r,i={},a=null;if(t!=null)for(r in t.key!==void 0&&(a=``+t.key),t)T.call(t,r)&&r!==`key`&&r!==`__self`&&r!==`__source`&&(i[r]=t[r]);var o=arguments.length-2;if(o===1)i.children=n;else if(1<o){for(var s=Array(o),c=0;c<o;c++)s[c]=arguments[c+2];i.children=s}if(e&&e.defaultProps)for(r in o=e.defaultProps,o)i[r]===void 0&&(i[r]=o[r]);return E(e,a,i)},e.createRef=function(){return{current:null}},e.forwardRef=function(e){return{$$typeof:c,render:e}},e.isValidElement=O,e.lazy=function(e){return{$$typeof:d,_payload:{_status:-1,_result:e},_init:F}},e.memo=function(e,t){return{$$typeof:u,type:e,compare:t===void 0?null:t}},e.startTransition=function(e){var t=w.T,n={};w.T=n;try{var r=e(),i=w.S;i!==null&&i(n,r),typeof r==`object`&&r&&typeof r.then==`function`&&r.then(C,I)}catch(e){I(e)}finally{t!==null&&n.types!==null&&(t.types=n.types),w.T=t}},e.unstable_useCacheRefresh=function(){return w.H.useCacheRefresh()},e.use=function(e){return w.H.use(e)},e.useActionState=function(e,t,n){return w.H.useActionState(e,t,n)},e.useCallback=function(e,t){return w.H.useCallback(e,t)},e.useContext=function(e){return w.H.useContext(e)},e.useDebugValue=function(){},e.useDeferredValue=function(e,t){return w.H.useDeferredValue(e,t)},e.useEffect=function(e,t){return w.H.useEffect(e,t)},e.useEffectEvent=function(e){return w.H.useEffectEvent(e)},e.useId=function(){return w.H.useId()},e.useImperativeHandle=function(e,t,n){return w.H.useImperativeHandle(e,t,n)},e.useInsertionEffect=function(e,t){return w.H.useInsertionEffect(e,t)},e.useLayoutEffect=function(e,t){return w.H.useLayoutEffect(e,t)},e.useMemo=function(e,t){return w.H.useMemo(e,t)},e.useOptimistic=function(e,t){return w.H.useOptimistic(e,t)},e.useReducer=function(e,t,n){return w.H.useReducer(e,t,n)},e.useRef=function(e){return w.H.useRef(e)},e.useState=function(e){return w.H.useState(e)},e.useSyncExternalStore=function(e,t,n){return w.H.useSyncExternalStore(e,t,n)},e.useTransition=function(){return w.H.useTransition()},e.version=`19.2.5`})),PY=l(((e,t)=>{t.exports=NY()})),FY=l((e=>{var t=PY();function n(e){var t=`https://react.dev/errors/`+e;if(1<arguments.length){t+=`?args[]=`+encodeURIComponent(arguments[1]);for(var n=2;n<arguments.length;n++)t+=`&args[]=`+encodeURIComponent(arguments[n])}return`Minified React error #`+e+`; visit `+t+` for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`}function r(){}var i={d:{f:r,r:function(){throw Error(n(522))},D:r,C:r,L:r,m:r,X:r,S:r,M:r},p:0,findDOMNode:null},a=Symbol.for(`react.portal`);function o(e,t,n){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:a,key:r==null?null:``+r,children:e,containerInfo:t,implementation:n}}var s=t.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;function c(e,t){if(e===`font`)return``;if(typeof t==`string`)return t===`use-credentials`?t:``}e.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=i,e.createPortal=function(e,t){var r=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!t||t.nodeType!==1&&t.nodeType!==9&&t.nodeType!==11)throw Error(n(299));return o(e,t,null,r)},e.flushSync=function(e){var t=s.T,n=i.p;try{if(s.T=null,i.p=2,e)return e()}finally{s.T=t,i.p=n,i.d.f()}},e.preconnect=function(e,t){typeof e==`string`&&(t?(t=t.crossOrigin,t=typeof t==`string`?t===`use-credentials`?t:``:void 0):t=null,i.d.C(e,t))},e.prefetchDNS=function(e){typeof e==`string`&&i.d.D(e)},e.preinit=function(e,t){if(typeof e==`string`&&t&&typeof t.as==`string`){var n=t.as,r=c(n,t.crossOrigin),a=typeof t.integrity==`string`?t.integrity:void 0,o=typeof t.fetchPriority==`string`?t.fetchPriority:void 0;n===`style`?i.d.S(e,typeof t.precedence==`string`?t.precedence:void 0,{crossOrigin:r,integrity:a,fetchPriority:o}):n===`script`&&i.d.X(e,{crossOrigin:r,integrity:a,fetchPriority:o,nonce:typeof t.nonce==`string`?t.nonce:void 0})}},e.preinitModule=function(e,t){if(typeof e==`string`)if(typeof t==`object`&&t){if(t.as==null||t.as===`script`){var n=c(t.as,t.crossOrigin);i.d.M(e,{crossOrigin:n,integrity:typeof t.integrity==`string`?t.integrity:void 0,nonce:typeof t.nonce==`string`?t.nonce:void 0})}}else t??i.d.M(e)},e.preload=function(e,t){if(typeof e==`string`&&typeof t==`object`&&t&&typeof t.as==`string`){var n=t.as,r=c(n,t.crossOrigin);i.d.L(e,n,{crossOrigin:r,integrity:typeof t.integrity==`string`?t.integrity:void 0,nonce:typeof t.nonce==`string`?t.nonce:void 0,type:typeof t.type==`string`?t.type:void 0,fetchPriority:typeof t.fetchPriority==`string`?t.fetchPriority:void 0,referrerPolicy:typeof t.referrerPolicy==`string`?t.referrerPolicy:void 0,imageSrcSet:typeof t.imageSrcSet==`string`?t.imageSrcSet:void 0,imageSizes:typeof t.imageSizes==`string`?t.imageSizes:void 0,media:typeof t.media==`string`?t.media:void 0})}},e.preloadModule=function(e,t){if(typeof e==`string`)if(t){var n=c(t.as,t.crossOrigin);i.d.m(e,{as:typeof t.as==`string`&&t.as!==`script`?t.as:void 0,crossOrigin:n,integrity:typeof t.integrity==`string`?t.integrity:void 0})}else i.d.m(e)},e.requestFormReset=function(e){i.d.r(e)},e.unstable_batchedUpdates=function(e,t){return e(t)},e.useFormState=function(e,t,n){return s.H.useFormState(e,t,n)},e.useFormStatus=function(){return s.H.useHostTransitionStatus()},e.version=`19.2.5`})),IY=l(((e,t)=>{function n(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>`u`||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!=`function`))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(n)}catch(e){console.error(e)}}n(),t.exports=FY()})),LY=l((e=>{function t(e,t){var n=e.length;e.push(t);a:for(;0<n;){var r=n-1>>>1,a=e[r];if(0<i(a,t))e[r]=t,e[n]=a,n=r;else break a}}function n(e){return e.length===0?null:e[0]}function r(e){if(e.length===0)return null;var t=e[0],n=e.pop();if(n!==t){e[0]=n;a:for(var r=0,a=e.length,o=a>>>1;r<o;){var s=2*(r+1)-1,c=e[s],l=s+1,u=e[l];if(0>i(c,n))l<a&&0>i(u,c)?(e[r]=u,e[l]=n,r=l):(e[r]=c,e[s]=n,r=s);else if(l<a&&0>i(u,n))e[r]=u,e[l]=n,r=l;else break a}}return t}function i(e,t){var n=e.sortIndex-t.sortIndex;return n===0?e.id-t.id:n}if(e.unstable_now=void 0,typeof performance==`object`&&typeof performance.now==`function`){var a=performance;e.unstable_now=function(){return a.now()}}else{var o=Date,s=o.now();e.unstable_now=function(){return o.now()-s}}var c=[],l=[],u=1,d=null,f=3,p=!1,m=!1,h=!1,g=!1,_=typeof setTimeout==`function`?setTimeout:null,v=typeof clearTimeout==`function`?clearTimeout:null,y=typeof setImmediate<`u`?setImmediate:null;function b(e){for(var i=n(l);i!==null;){if(i.callback===null)r(l);else if(i.startTime<=e)r(l),i.sortIndex=i.expirationTime,t(c,i);else break;i=n(l)}}function x(e){if(h=!1,b(e),!m)if(n(c)!==null)m=!0,S||(S=!0,O());else{var t=n(l);t!==null&&j(x,t.startTime-e)}}var S=!1,C=-1,w=5,T=-1;function E(){return g?!0:!(e.unstable_now()-T<w)}function D(){if(g=!1,S){var t=e.unstable_now();T=t;var i=!0;try{a:{m=!1,h&&(h=!1,v(C),C=-1),p=!0;var a=f;try{b:{for(b(t),d=n(c);d!==null&&!(d.expirationTime>t&&E());){var o=d.callback;if(typeof o==`function`){d.callback=null,f=d.priorityLevel;var s=o(d.expirationTime<=t);if(t=e.unstable_now(),typeof s==`function`){d.callback=s,b(t),i=!0;break b}d===n(c)&&r(c),b(t)}else r(c);d=n(c)}if(d!==null)i=!0;else{var u=n(l);u!==null&&j(x,u.startTime-t),i=!1}}break a}finally{d=null,f=a,p=!1}i=void 0}}finally{i?O():S=!1}}}var O;if(typeof y==`function`)O=function(){y(D)};else if(typeof MessageChannel<`u`){var k=new MessageChannel,A=k.port2;k.port1.onmessage=D,O=function(){A.postMessage(null)}}else O=function(){_(D,0)};function j(t,n){C=_(function(){t(e.unstable_now())},n)}e.unstable_IdlePriority=5,e.unstable_ImmediatePriority=1,e.unstable_LowPriority=4,e.unstable_NormalPriority=3,e.unstable_Profiling=null,e.unstable_UserBlockingPriority=2,e.unstable_cancelCallback=function(e){e.callback=null},e.unstable_forceFrameRate=function(e){0>e||125<e?console.error(`forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported`):w=0<e?Math.floor(1e3/e):5},e.unstable_getCurrentPriorityLevel=function(){return f},e.unstable_next=function(e){switch(f){case 1:case 2:case 3:var t=3;break;default:t=f}var n=f;f=t;try{return e()}finally{f=n}},e.unstable_requestPaint=function(){g=!0},e.unstable_runWithPriority=function(e,t){switch(e){case 1:case 2:case 3:case 4:case 5:break;default:e=3}var n=f;f=e;try{return t()}finally{f=n}},e.unstable_scheduleCallback=function(r,i,a){var o=e.unstable_now();switch(typeof a==`object`&&a?(a=a.delay,a=typeof a==`number`&&0<a?o+a:o):a=o,r){case 1:var s=-1;break;case 2:s=250;break;case 5:s=1073741823;break;case 4:s=1e4;break;default:s=5e3}return s=a+s,r={id:u++,callback:i,priorityLevel:r,startTime:a,expirationTime:s,sortIndex:-1},a>o?(r.sortIndex=a,t(l,r),n(c)===null&&r===n(l)&&(h?(v(C),C=-1):h=!0,j(x,a-o))):(r.sortIndex=s,t(c,r),m||p||(m=!0,S||(S=!0,O()))),r},e.unstable_shouldYield=E,e.unstable_wrapCallback=function(e){var t=f;return function(){var n=f;f=t;try{return e.apply(this,arguments)}finally{f=n}}}})),RY=l(((e,t)=>{t.exports=LY()})),zY=l((e=>{var t=RY(),n=PY(),r=IY();function i(e){var t=`https://react.dev/errors/`+e;if(1<arguments.length){t+=`?args[]=`+encodeURIComponent(arguments[1]);for(var n=2;n<arguments.length;n++)t+=`&args[]=`+encodeURIComponent(arguments[n])}return`Minified React error #`+e+`; visit `+t+` for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`}function a(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function o(e){var t=e,n=e;if(e.alternate)for(;t.return;)t=t.return;else{e=t;do t=e,t.flags&4098&&(n=t.return),e=t.return;while(e)}return t.tag===3?n:null}function s(e){if(e.tag===13){var t=e.memoizedState;if(t===null&&(e=e.alternate,e!==null&&(t=e.memoizedState)),t!==null)return t.dehydrated}return null}function c(e){if(e.tag===31){var t=e.memoizedState;if(t===null&&(e=e.alternate,e!==null&&(t=e.memoizedState)),t!==null)return t.dehydrated}return null}function l(e){if(o(e)!==e)throw Error(i(188))}function u(e){var t=e.alternate;if(!t){if(t=o(e),t===null)throw Error(i(188));return t===e?e:null}for(var n=e,r=t;;){var a=n.return;if(a===null)break;var s=a.alternate;if(s===null){if(r=a.return,r!==null){n=r;continue}break}if(a.child===s.child){for(s=a.child;s;){if(s===n)return l(a),e;if(s===r)return l(a),t;s=s.sibling}throw Error(i(188))}if(n.return!==r.return)n=a,r=s;else{for(var c=!1,u=a.child;u;){if(u===n){c=!0,n=a,r=s;break}if(u===r){c=!0,r=a,n=s;break}u=u.sibling}if(!c){for(u=s.child;u;){if(u===n){c=!0,n=s,r=a;break}if(u===r){c=!0,r=s,n=a;break}u=u.sibling}if(!c)throw Error(i(189))}}if(n.alternate!==r)throw Error(i(190))}if(n.tag!==3)throw Error(i(188));return n.stateNode.current===n?e:t}function d(e){var t=e.tag;if(t===5||t===26||t===27||t===6)return e;for(e=e.child;e!==null;){if(t=d(e),t!==null)return t;e=e.sibling}return null}var f=Object.assign,p=Symbol.for(`react.element`),m=Symbol.for(`react.transitional.element`),h=Symbol.for(`react.portal`),g=Symbol.for(`react.fragment`),_=Symbol.for(`react.strict_mode`),v=Symbol.for(`react.profiler`),y=Symbol.for(`react.consumer`),b=Symbol.for(`react.context`),x=Symbol.for(`react.forward_ref`),S=Symbol.for(`react.suspense`),C=Symbol.for(`react.suspense_list`),w=Symbol.for(`react.memo`),T=Symbol.for(`react.lazy`),E=Symbol.for(`react.activity`),D=Symbol.for(`react.memo_cache_sentinel`),O=Symbol.iterator;function k(e){return typeof e!=`object`||!e?null:(e=O&&e[O]||e[`@@iterator`],typeof e==`function`?e:null)}var A=Symbol.for(`react.client.reference`);function j(e){if(e==null)return null;if(typeof e==`function`)return e.$$typeof===A?null:e.displayName||e.name||null;if(typeof e==`string`)return e;switch(e){case g:return`Fragment`;case v:return`Profiler`;case _:return`StrictMode`;case S:return`Suspense`;case C:return`SuspenseList`;case E:return`Activity`}if(typeof e==`object`)switch(e.$$typeof){case h:return`Portal`;case b:return e.displayName||`Context`;case y:return(e._context.displayName||`Context`)+`.Consumer`;case x:var t=e.render;return e=e.displayName,e||=(e=t.displayName||t.name||``,e===``?`ForwardRef`:`ForwardRef(`+e+`)`),e;case w:return t=e.displayName||null,t===null?j(e.type)||`Memo`:t;case T:t=e._payload,e=e._init;try{return j(e(t))}catch{}}return null}var M=Array.isArray,N=n.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,P=r.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,F={pending:!1,data:null,method:null,action:null},I=[],L=-1;function R(e){return{current:e}}function z(e){0>L||(e.current=I[L],I[L]=null,L--)}function B(e,t){L++,I[L]=e.current,e.current=t}var V=R(null),ee=R(null),H=R(null),U=R(null);function te(e,t){switch(B(H,t),B(ee,e),B(V,null),t.nodeType){case 9:case 11:e=(e=t.documentElement)&&(e=e.namespaceURI)?Ud(e):0;break;default:if(e=t.tagName,t=t.namespaceURI)t=Ud(t),e=Wd(t,e);else switch(e){case`svg`:e=1;break;case`math`:e=2;break;default:e=0}}z(V),B(V,e)}function W(){z(V),z(ee),z(H)}function ne(e){e.memoizedState!==null&&B(U,e);var t=V.current,n=Wd(t,e.type);t!==n&&(B(ee,e),B(V,n))}function G(e){ee.current===e&&(z(V),z(ee)),U.current===e&&(z(U),ep._currentValue=F)}var re,ie;function ae(e){if(re===void 0)try{throw Error()}catch(e){var t=e.stack.trim().match(/\n( *(at )?)/);re=t&&t[1]||``,ie=-1<e.stack.indexOf(`
|
|
81
|
+
`,r))p(t,r,e),r=e+1,f===c&&(yield u(f,l,d),l=new Float64Array(c),d=i.map(()=>new Float64Array(c)),f=0);m=t.slice(r)}m.trim()&&p(m,0,m.length),f&&(yield u(f,l.slice(0,f),d.map(e=>e.slice(0,f))));return}let d=t.recordSize,f=IW[n.ft],p=Math.max(1,Math.floor(Math.min(Gz,c*d)/d)),m=t.samples;for await(let s of r.windows(t.offset,Math.min(t.length,t.samples*d),p*d)){e.signal?.throwIfAborted();let t=Math.min(m,Math.floor(s.bytes.length/d));if(t<=0)break;let r=TR(s.bytes),c=new Float64Array(t);if(!o)for(let e=0;e<t;e++)c[e]=r.getUint32(e*d+4,!0);yield u(t,c,i.map(e=>{let i=new Float64Array(t);if(e<a){let{a,b:o}=n.analog[e],s=8+e*f;if(n.ft===`BINARY`)for(let e=0,n=s;e<t;e++,n+=d){let t=r.getInt16(n,!0);i[e]=t===-32768?NaN:a*t+o}else if(n.ft===`BINARY32`)for(let e=0,n=s;e<t;e++,n+=d){let t=r.getInt32(n,!0);i[e]=t===-2147483648?NaN:a*t+o}else for(let e=0,n=s;e<t;e++,n+=d)i[e]=a*r.getFloat32(n,!0)+o}else{let n=e-a,o=8+a*f+2*(n>>4),s=1<<(n&15);for(let e=0,n=o;e<t;e++,n+=d)i[e]=r.getUint16(n,!0)&s?1:0}return i})),m-=t}}var IW,LW,RW,zW,BW=c((()=>{qz(),AR(),Zz(),KR(),IW={BINARY:2,BINARY32:4,FLOAT32:4},LW=16<<20,RW=e=>e.companions.find(e=>e.name.toLowerCase().endsWith(`.dat`)),zW={...GR,async plan(e,t){let n=e.main.name.toLowerCase().endsWith(`.cff`),r,i;if(n){let e=await NW(t);r=e.cfg,i={data:`self`,offset:e.offset,length:e.length}}else{let n=RW(e);if(!n)throw Error(`This COMTRADE .cfg needs its .dat file: drop both together.`);if(t.size>LW)throw Error(`This .cfg is too large to be a COMTRADE configuration file.`);r=OR(await t.read(0,t.size)),i={data:`companion`,offset:0,length:n.size}}let a=MW(r);if(a.ft!==`ASCII`&&!IW[a.ft])throw Error(`This COMTRADE file has data file type ${a.ft}, which Kymoscope cannot read.`);let o=Math.ceil(a.digital.length/16),s=a.ft===`ASCII`?0:8+a.analog.length*IW[a.ft]+2*o,c=s?Math.floor(i.length/s):i.length,l=Math.min(a.rates[a.rates.length-1][1]||(s?c:-1),c),u=a.rates.length===1&&a.rates[0][0]>0?a.rates[0][0]:null,d=[`Analog values are shown as recorded (primary or secondary, per the CFG).`];return{format:`COMTRADE ${a.rev} (${a.ft})`,startTime:a.start,meta:{station:a.station,trigger:a.trigger??``},groups:[{name:a.station||`COMTRADE`,channels:[...a.analog.map(e=>({name:e.name,unit:e.unit})),...a.digital.map(e=>({name:e,unit:``}))],samples:l,time:{kind:`timestamps`},rateHz:u}],events:a.start&&a.trigger?[{time:Math.round((a.triggerSec-a.startSec)*1e6)/1e6,text:`Trigger`}]:[],notes:d,state:{...i,cfg:a,samples:l,recordSize:s}}},stream:e=>FW(e)}}));function VW(e,t,n){let r=t,i=r+n,a=[],o=``;for(;r<i;){let t=e[r++];if(!(t&128))a.push(t);else if((t&224)==192){let n=e[r++]&63;a.push((t&31)<<6|n)}else if((t&240)==224){let n=e[r++]&63,i=e[r++]&63;a.push((t&31)<<12|n<<6|i)}else if((t&248)==240){let n=e[r++]&63,i=e[r++]&63,o=e[r++]&63,s=(t&7)<<18|n<<12|i<<6|o;s>65535&&(s-=65536,a.push(s>>>10&1023|55296),s=56320|s&1023),a.push(s)}else a.push(t);a.length>=WW&&(o+=String.fromCharCode(...a),a.length=0)}return a.length>0&&(o+=String.fromCharCode(...a)),o}function HW(e,t,n){let r=e.subarray(t,t+n);return GW.decode(r)}function UW(e,t,n){return n>KW?HW(e,t,n):VW(e,t,n)}var WW,GW,KW,qW=c((()=>{new TextEncoder,WW=4096,GW=new TextDecoder,KW=200})),JW,YW=c((()=>{JW=class{type;data;constructor(e,t){this.type=e,this.data=t}}})),XW,ZW=c((()=>{XW=class e extends Error{constructor(t){super(t);let n=Object.create(e.prototype);Object.setPrototypeOf(this,n),Object.defineProperty(this,`name`,{configurable:!0,enumerable:!1,value:e.name})}}}));function QW(e,t,n){let r=Math.floor(n/4294967296),i=n;e.setUint32(t,r),e.setUint32(t+4,i)}function $W(e,t){let n=e.getInt32(t),r=e.getUint32(t+4);return n*4294967296+r}function eG(e,t){let n=e.getUint32(t),r=e.getUint32(t+4);return n*4294967296+r}var tG=c((()=>{}));function nG({sec:e,nsec:t}){if(e>=0&&t>=0&&e<=cG)if(t===0&&e<=sG){let t=new Uint8Array(4);return new DataView(t.buffer).setUint32(0,e),t}else{let n=e/4294967296,r=e&4294967295,i=new Uint8Array(8),a=new DataView(i.buffer);return a.setUint32(0,t<<2|n&3),a.setUint32(4,r),i}else{let n=new Uint8Array(12),r=new DataView(n.buffer);return r.setUint32(0,t),QW(r,4,e),n}}function rG(e){let t=e.getTime(),n=Math.floor(t/1e3),r=(t-n*1e3)*1e6,i=Math.floor(r/1e9);return{sec:n+i,nsec:r-i*1e9}}function iG(e){return e instanceof Date?nG(rG(e)):null}function aG(e){let t=new DataView(e.buffer,e.byteOffset,e.byteLength);switch(e.byteLength){case 4:return{sec:t.getUint32(0),nsec:0};case 8:{let e=t.getUint32(0),n=t.getUint32(4);return{sec:(e&3)*4294967296+n,nsec:e>>>2}}case 12:return{sec:$W(t,4),nsec:t.getUint32(0)};default:throw new XW(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${e.length}`)}}function oG(e){let t=aG(e);return new Date(t.sec*1e3+t.nsec/1e6)}var sG,cG,lG,uG=c((()=>{ZW(),tG(),sG=4294967295,cG=17179869183,lG={type:-1,encode:iG,decode:oG}})),dG,fG=c((()=>{YW(),uG(),dG=class e{static defaultCodec=new e;__brand;builtInEncoders=[];builtInDecoders=[];encoders=[];decoders=[];constructor(){this.register(lG)}register({type:e,encode:t,decode:n}){if(e>=0)this.encoders[e]=t,this.decoders[e]=n;else{let r=-1-e;this.builtInEncoders[r]=t,this.builtInDecoders[r]=n}}tryToEncode(e,t){for(let n=0;n<this.builtInEncoders.length;n++){let r=this.builtInEncoders[n];if(r!=null){let i=r(e,t);if(i!=null)return new JW(-1-n,i)}}for(let n=0;n<this.encoders.length;n++){let r=this.encoders[n];if(r!=null){let i=r(e,t);if(i!=null)return new JW(n,i)}}return e instanceof JW?e:null}decode(e,t,n){let r=t<0?this.builtInDecoders[-1-t]:this.decoders[t];return r?r(e,t,n):new JW(t,e)}}}));function pG(e){return e instanceof ArrayBuffer||typeof SharedArrayBuffer<`u`&&e instanceof SharedArrayBuffer}function mG(e){return e instanceof Uint8Array?e:ArrayBuffer.isView(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):pG(e)?new Uint8Array(e):Uint8Array.from(e)}var hG=c((()=>{}));function gG(e){return`${e<0?`-`:``}0x${Math.abs(e).toString(16).padStart(2,`0`)}`}var _G=c((()=>{})),vG,yG,bG,xG=c((()=>{qW(),vG=16,yG=16,bG=class{hit=0;miss=0;caches;maxKeyLength;maxLengthPerKey;constructor(e=vG,t=yG){this.maxKeyLength=e,this.maxLengthPerKey=t,this.caches=[];for(let e=0;e<this.maxKeyLength;e++)this.caches.push([])}canBeCached(e){return e>0&&e<=this.maxKeyLength}find(e,t,n){let r=this.caches[n-1];FIND_CHUNK:for(let i of r){let r=i.bytes;for(let i=0;i<n;i++)if(r[i]!==e[t+i])continue FIND_CHUNK;return i.str}return null}store(e,t){let n=this.caches[e.length-1],r={bytes:e,str:t};n.length>=this.maxLengthPerKey?n[Math.random()*n.length|0]=r:n.push(r)}decode(e,t,n){let r=this.find(e,t,n);if(r!=null)return this.hit++,r;this.miss++;let i=VW(e,t,n),a=Uint8Array.prototype.slice.call(e,t,t+n);return this.store(a,i),i}}})),SG,CG,wG,TG,EG,DG,OG,kG,AG,jG,MG,NG=c((()=>{_G(),fG(),tG(),qW(),hG(),xG(),ZW(),SG=`array`,CG=`map_key`,wG=`map_value`,TG=e=>{if(typeof e==`string`||typeof e==`number`)return e;throw new XW(`The type of key must be string or number but `+typeof e)},EG=class{stack=[];stackHeadPosition=-1;get length(){return this.stackHeadPosition+1}top(){return this.stack[this.stackHeadPosition]}pushArrayState(e){let t=this.getUninitializedStateFromPool();t.type=SG,t.position=0,t.size=e,t.array=Array(e)}pushMapState(e){let t=this.getUninitializedStateFromPool();t.type=CG,t.readCount=0,t.size=e,t.map={}}getUninitializedStateFromPool(){return this.stackHeadPosition++,this.stackHeadPosition===this.stack.length&&this.stack.push({type:void 0,size:0,array:void 0,position:0,readCount:0,map:void 0,key:null}),this.stack[this.stackHeadPosition]}release(e){if(this.stack[this.stackHeadPosition]!==e)throw Error(`Invalid stack state. Released state is not on top of the stack.`);if(e.type===SG){let t=e;t.size=0,t.array=void 0,t.position=0,t.type=void 0}if(e.type===CG||e.type===wG){let t=e;t.size=0,t.map=void 0,t.readCount=0,t.type=void 0}this.stackHeadPosition--}reset(){this.stack.length=0,this.stackHeadPosition=-1}},DG=-1,OG=new DataView(new ArrayBuffer(0)),kG=new Uint8Array(OG.buffer);try{OG.getInt8(0)}catch(e){if(!(e instanceof RangeError))throw Error(`This module is not supported in the current JavaScript engine because DataView does not throw RangeError on out-of-bounds access`)}AG=RangeError(`Insufficient data`),jG=new bG,MG=class e{extensionCodec;context;useBigInt64;rawStrings;maxStrLength;maxBinLength;maxArrayLength;maxMapLength;maxExtLength;keyDecoder;mapKeyConverter;totalPos=0;pos=0;view=OG;bytes=kG;headByte=DG;stack=new EG;entered=!1;constructor(e){this.extensionCodec=e?.extensionCodec??dG.defaultCodec,this.context=e?.context,this.useBigInt64=e?.useBigInt64??!1,this.rawStrings=e?.rawStrings??!1,this.maxStrLength=e?.maxStrLength??4294967295,this.maxBinLength=e?.maxBinLength??4294967295,this.maxArrayLength=e?.maxArrayLength??4294967295,this.maxMapLength=e?.maxMapLength??4294967295,this.maxExtLength=e?.maxExtLength??4294967295,this.keyDecoder=e?.keyDecoder===void 0?jG:e.keyDecoder,this.mapKeyConverter=e?.mapKeyConverter??TG}clone(){return new e({extensionCodec:this.extensionCodec,context:this.context,useBigInt64:this.useBigInt64,rawStrings:this.rawStrings,maxStrLength:this.maxStrLength,maxBinLength:this.maxBinLength,maxArrayLength:this.maxArrayLength,maxMapLength:this.maxMapLength,maxExtLength:this.maxExtLength,keyDecoder:this.keyDecoder})}reinitializeState(){this.totalPos=0,this.headByte=DG,this.stack.reset()}setBuffer(e){let t=mG(e);this.bytes=t,this.view=new DataView(t.buffer,t.byteOffset,t.byteLength),this.pos=0}appendBuffer(e){if(this.headByte===DG&&!this.hasRemaining(1))this.setBuffer(e);else{let t=this.bytes.subarray(this.pos),n=mG(e),r=new Uint8Array(t.length+n.length);r.set(t),r.set(n,t.length),this.setBuffer(r)}}hasRemaining(e){return this.view.byteLength-this.pos>=e}createExtraByteError(e){let{view:t,pos:n}=this;return RangeError(`Extra ${t.byteLength-n} of ${t.byteLength} byte(s) found at buffer[${e}]`)}decode(e){if(this.entered)return this.clone().decode(e);try{this.entered=!0,this.reinitializeState(),this.setBuffer(e);let t=this.doDecodeSync();if(this.hasRemaining(1))throw this.createExtraByteError(this.pos);return t}finally{this.entered=!1}}*decodeMulti(e){if(this.entered){yield*this.clone().decodeMulti(e);return}try{for(this.entered=!0,this.reinitializeState(),this.setBuffer(e);this.hasRemaining(1);)yield this.doDecodeSync()}finally{this.entered=!1}}async decodeAsync(e){if(this.entered)return this.clone().decodeAsync(e);try{this.entered=!0;let t=!1,n;for await(let r of e){if(t)throw this.entered=!1,this.createExtraByteError(this.totalPos);this.appendBuffer(r);try{n=this.doDecodeSync(),t=!0}catch(e){if(!(e instanceof RangeError))throw e}this.totalPos+=this.pos}if(t){if(this.hasRemaining(1))throw this.createExtraByteError(this.totalPos);return n}let{headByte:r,pos:i,totalPos:a}=this;throw RangeError(`Insufficient data in parsing ${gG(r)} at ${a} (${i} in the current buffer)`)}finally{this.entered=!1}}decodeArrayStream(e){return this.decodeMultiAsync(e,!0)}decodeStream(e){return this.decodeMultiAsync(e,!1)}async*decodeMultiAsync(e,t){if(this.entered){yield*this.clone().decodeMultiAsync(e,t);return}try{this.entered=!0;let n=t,r=-1;for await(let i of e){if(t&&r===0)throw this.createExtraByteError(this.totalPos);this.appendBuffer(i),n&&(r=this.readArraySize(),n=!1,this.complete());try{for(;yield this.doDecodeSync(),--r!==0;);}catch(e){if(!(e instanceof RangeError))throw e}this.totalPos+=this.pos}}finally{this.entered=!1}}doDecodeSync(){DECODE:for(;;){let e=this.readHeadByte(),t;if(e>=224)t=e-256;else if(e<192)if(e<128)t=e;else if(e<144){let n=e-128;if(n!==0){this.pushMapState(n),this.complete();continue DECODE}else t={}}else if(e<160){let n=e-144;if(n!==0){this.pushArrayState(n),this.complete();continue DECODE}else t=[]}else{let n=e-160;t=this.decodeString(n,0)}else if(e===192)t=null;else if(e===194)t=!1;else if(e===195)t=!0;else if(e===202)t=this.readF32();else if(e===203)t=this.readF64();else if(e===204)t=this.readU8();else if(e===205)t=this.readU16();else if(e===206)t=this.readU32();else if(e===207)t=this.useBigInt64?this.readU64AsBigInt():this.readU64();else if(e===208)t=this.readI8();else if(e===209)t=this.readI16();else if(e===210)t=this.readI32();else if(e===211)t=this.useBigInt64?this.readI64AsBigInt():this.readI64();else if(e===217){let e=this.lookU8();t=this.decodeString(e,1)}else if(e===218){let e=this.lookU16();t=this.decodeString(e,2)}else if(e===219){let e=this.lookU32();t=this.decodeString(e,4)}else if(e===220){let e=this.readU16();if(e!==0){this.pushArrayState(e),this.complete();continue DECODE}else t=[]}else if(e===221){let e=this.readU32();if(e!==0){this.pushArrayState(e),this.complete();continue DECODE}else t=[]}else if(e===222){let e=this.readU16();if(e!==0){this.pushMapState(e),this.complete();continue DECODE}else t={}}else if(e===223){let e=this.readU32();if(e!==0){this.pushMapState(e),this.complete();continue DECODE}else t={}}else if(e===196){let e=this.lookU8();t=this.decodeBinary(e,1)}else if(e===197){let e=this.lookU16();t=this.decodeBinary(e,2)}else if(e===198){let e=this.lookU32();t=this.decodeBinary(e,4)}else if(e===212)t=this.decodeExtension(1,0);else if(e===213)t=this.decodeExtension(2,0);else if(e===214)t=this.decodeExtension(4,0);else if(e===215)t=this.decodeExtension(8,0);else if(e===216)t=this.decodeExtension(16,0);else if(e===199){let e=this.lookU8();t=this.decodeExtension(e,1)}else if(e===200){let e=this.lookU16();t=this.decodeExtension(e,2)}else if(e===201){let e=this.lookU32();t=this.decodeExtension(e,4)}else throw new XW(`Unrecognized type byte: ${gG(e)}`);this.complete();let n=this.stack;for(;n.length>0;){let e=n.top();if(e.type===SG)if(e.array[e.position]=t,e.position++,e.position===e.size)t=e.array,n.release(e);else continue DECODE;else if(e.type===CG){if(t===`__proto__`)throw new XW(`The key __proto__ is not allowed`);e.key=this.mapKeyConverter(t),e.type=wG;continue DECODE}else if(e.map[e.key]=t,e.readCount++,e.readCount===e.size)t=e.map,n.release(e);else{e.key=null,e.type=CG;continue DECODE}}return t}}readHeadByte(){return this.headByte===DG&&(this.headByte=this.readU8()),this.headByte}complete(){this.headByte=DG}readArraySize(){let e=this.readHeadByte();switch(e){case 220:return this.readU16();case 221:return this.readU32();default:if(e<160)return e-144;throw new XW(`Unrecognized array type byte: ${gG(e)}`)}}pushMapState(e){if(e>this.maxMapLength)throw new XW(`Max length exceeded: map length (${e}) > maxMapLengthLength (${this.maxMapLength})`);this.stack.pushMapState(e)}pushArrayState(e){if(e>this.maxArrayLength)throw new XW(`Max length exceeded: array length (${e}) > maxArrayLength (${this.maxArrayLength})`);this.stack.pushArrayState(e)}decodeString(e,t){return!this.rawStrings||this.stateIsMapKey()?this.decodeUtf8String(e,t):this.decodeBinary(e,t)}decodeUtf8String(e,t){if(e>this.maxStrLength)throw new XW(`Max length exceeded: UTF-8 byte length (${e}) > maxStrLength (${this.maxStrLength})`);if(this.bytes.byteLength<this.pos+t+e)throw AG;let n=this.pos+t,r;return r=this.stateIsMapKey()&&this.keyDecoder?.canBeCached(e)?this.keyDecoder.decode(this.bytes,n,e):UW(this.bytes,n,e),this.pos+=t+e,r}stateIsMapKey(){return this.stack.length>0?this.stack.top().type===CG:!1}decodeBinary(e,t){if(e>this.maxBinLength)throw new XW(`Max length exceeded: bin length (${e}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining(e+t))throw AG;let n=this.pos+t,r=this.bytes.subarray(n,n+e);return this.pos+=t+e,r}decodeExtension(e,t){if(e>this.maxExtLength)throw new XW(`Max length exceeded: ext length (${e}) > maxExtLength (${this.maxExtLength})`);let n=this.view.getInt8(this.pos+t),r=this.decodeBinary(e,t+1);return this.extensionCodec.decode(r,n,this.context)}lookU8(){return this.view.getUint8(this.pos)}lookU16(){return this.view.getUint16(this.pos)}lookU32(){return this.view.getUint32(this.pos)}readU8(){let e=this.view.getUint8(this.pos);return this.pos++,e}readI8(){let e=this.view.getInt8(this.pos);return this.pos++,e}readU16(){let e=this.view.getUint16(this.pos);return this.pos+=2,e}readI16(){let e=this.view.getInt16(this.pos);return this.pos+=2,e}readU32(){let e=this.view.getUint32(this.pos);return this.pos+=4,e}readI32(){let e=this.view.getInt32(this.pos);return this.pos+=4,e}readU64(){let e=eG(this.view,this.pos);return this.pos+=8,e}readI64(){let e=$W(this.view,this.pos);return this.pos+=8,e}readU64AsBigInt(){let e=this.view.getBigUint64(this.pos);return this.pos+=8,e}readI64AsBigInt(){let e=this.view.getBigInt64(this.pos);return this.pos+=8,e}readF32(){let e=this.view.getFloat32(this.pos);return this.pos+=4,e}readF64(){let e=this.view.getFloat64(this.pos);return this.pos+=8,e}}}));function PG(e,t){return new MG(t).decode(e)}var FG=c((()=>{NG()})),IG=c((()=>{FG()}));function LG(e){let t=e=>RangeError(`columns message: ${e}`);e.byteOffset%8!=0&&(e=e.slice());let n=new DataView(e.buffer,e.byteOffset,e.byteLength);if(e.byteLength<8)throw t(`short`);if(n.getUint8(0)!==RG)throw t(`version ${n.getUint8(0)}`);let r=n.getUint16(2,!0),i=n.getUint32(4,!0),a=new TextDecoder,o=[],s=8;for(let i=0;i<r;i++){if(s+3>e.byteLength)throw t(`short channel table`);let r=n.getUint8(s),i=n.getUint8(s+1),c=n.getUint8(s+2);if(s+=3,r!==4&&r!==8)throw t(`value size ${r}`);if(s+i+c>e.byteLength)throw t(`short channel table`);o.push({name:a.decode(e.subarray(s,s+i)),unit:a.decode(e.subarray(s+i,s+i+c)),size:r}),s+=i+c}if(s=zG(s),s+zG(i*8)+o.reduce((e,t)=>e+zG(i*t.size),0)>e.byteLength)throw t(`short data`);let c=e.byteOffset,l=new Float64Array(e.buffer,c+s,i);s+=zG(i*8);let u={},d={};for(let t of o)u[t.name]=t.size===4?new Float32Array(e.buffer,c+s,i):new Float64Array(e.buffer,c+s,i),t.unit&&(d[t.name]=t.unit),s+=zG(i*t.size);return{t:l,columns:u,units:d}}var RG,zG,BG=c((()=>{RG=1,zG=e=>e+7&-8}));function VG(e,t,n,r){let i=t.length,a=t.map((e,t)=>`y${t}lo`),o=t.map((e,t)=>`y${t}hi`),s=new Uint8Array(e.length),c=0;for(let t=0;t<e.length;t++){let n=e[t];for(let e=0;e<i;e++){let r=n[o[e]];if(r!=null&&Number(r)!==Number(n[a[e]])){s[t]=1;break}}c+=1+s[t]}let l=new Float64Array(c),u=t.map(()=>new Float64Array(c).fill(NaN)),d,f=0,p=null;for(let t=0;t<e.length;t++){let m=e[t],h=n+(Number(m.b)+.5)*r,g=Number(m.pass??0);p!==null&&g!==p&&((d??=new Uint8Array(c))[f]=1),p=g,l[f]=h;for(let e=0;e<i;e++){let t=m[a[e]];t!=null&&(u[e][f]=Number(t))}if(f++,s[t]){l[f]=h;for(let e=0;e<i;e++){let t=m[o[e]];t!=null&&(u[e][f]=Number(t))}f++}}return{length:c,x:l,brk:d,cols:new Map(t.map((e,t)=>[e,u[t]]))}}function HG(e,t){if(t>=e.length)return e;let n=new Map;for(let[r,i]of e.cols)n.set(r,i.subarray(0,t));return{length:t,x:e.x.subarray(0,t),brk:e.brk?.subarray(0,t),cols:n}}function UG(e,t,n,r,i){let a=[];for(let o of new Set(e)){let e=t(o);if(!e||!(e.t<r))continue;let s=Math.max(n,e.t);s<i&&a.push({c:o,a:s,v:e.v})}if(a.length===0)return null;a.sort((e,t)=>e.a-t.a);let o=a.length+1,s=new Float64Array(o),c=new Map;return a.forEach((e,t)=>{let n=new Float64Array(o).fill(NaN);n[t]=n[o-1]=e.v,c.set(e.c,n),s[t]=e.a}),s[o-1]=i,{length:o,x:s,cols:c,hold:!0}}function WG(e,t){if(t===void 0||e.length===0||e.x[e.length-1]<=t)return e;let n=0,r=e.length;for(;n<r;){let i=n+r>>1;e.x[i]<=t?n=i+1:r=i}return HG(e,n)}function GG(e,t,n){let r=(t,n)=>{let r=0,i=e.length;for(;r<i;){let a=r+i>>1;(n?e.x[a]<=t:e.x[a]<t)?r=a+1:i=a}return r},i=r(t,!1),a=r(n,!0);if(i===0&&a===e.length)return e;let o=new Map;for(let[t,n]of e.cols)o.set(t,n.subarray(i,a));return{length:a-i,x:e.x.subarray(i,a),brk:e.brk?.subarray(i,a),cols:o}}function KG(e,t){let n=[];for(let r=0;r<e.length;r++)t(e.x[r])&&n.push(r);if(n.length===e.length)return e;let r=(e,t)=>{for(let r=0;r<n.length;r++)t[r]=e[n[r]];return t},i=new Map;for(let[t,a]of e.cols)i.set(t,r(a,new Float64Array(n.length)));return{length:n.length,x:r(e.x,new Float64Array(n.length)),brk:e.brk&&r(e.brk,new Uint8Array(n.length)),cols:i}}function qG(e,t,n,r,i=``,a=0){let o=Ge(e),s=gE(e.length,r),c=t=>{let n=o&&Ke(o,t);return n?e=>n[e]:n=>{let r=e[n][t];return typeof r==`number`?r:NaN}},l=c(t),u=[];for(let e of s)Number.isNaN(l(e))||u.push(e);let d=u.length,f=d===e.length&&a===0,p=o&&Ke(o,t),m=f&&p?p:Float64Array.from(u,e=>l(e)+a),h=new Map;for(let e of n){let t=o&&Ke(o,e);if(o&&!t)continue;if(f&&t){h.set(e+i,t);continue}let n=c(e),r=Float64Array.from(u,n);!t&&!r.some(e=>!Number.isNaN(e))||h.set(e+i,r)}return{length:d,x:m,cols:h}}function JG(e,t,n){if(!t&&n===0)return e;let r=e.x;if(n!==0){r=new Float64Array(e.length);for(let t=0;t<e.length;t++)r[t]=e.x[t]+n}let i=new Map;for(let[n,r]of e.cols)i.set(n+t,r);return{length:e.length,x:r,brk:e.brk,cols:i}}function YG(e){let t=e.filter(e=>e.length>0);if(t.length===0)return ZG;if(t.length===1)return t[0];let n=t.reduce((e,t)=>e+t.length,0),r=new Float64Array(n),i=new Set;for(let e of t)for(let t of e.cols.keys())i.add(t);let a=new Map;for(let e of i)a.set(e,new Float64Array(n).fill(NaN));let o,s=0;for(let e of t){r.set(e.x,s),e.brk&&(o??=new Uint8Array(n)).set(e.brk,s);for(let[t,n]of e.cols)a.get(t).set(n,s);s+=e.length}return{length:n,x:r,brk:o,cols:a}}var XG,ZG,QG=c((()=>{xE(),Qe(),jE(),XG=OE(new WeakSet),ZG={length:0,x:new Float64Array,cols:new Map}})),$G,eK,tK=c((()=>{$G=64,eK=class{nc;bucket;b;lo;hi;start=0;end=0;rowP;px=new Float64Array;pv=[];pStart=0;pEnd=0;mStart=0;mEnd=0;dirty=1/0;dirtyFront=-1;invalid=!0;constructor(e,t,n=1024){this.nc=e,this.bucket=t,this.b=new Float64Array(n),this.rowP=new Float64Array(n),this.lo=Array.from({length:e},()=>new Float64Array(n)),this.hi=Array.from({length:e},()=>new Float64Array(n))}get count(){return this.end-this.start}lowerBound(e){let t=this.start,n=this.end;for(;t<n;){let r=t+n>>>1;this.b[r]<e?t=r+1:n=r}return t}relocate(e,t){let n=this.count,r=n=>{if(t===n.length&&e<=this.start)return n.copyWithin(e,this.start,this.end),n;let r=new Float64Array(t);return r.set(n.subarray(this.start,this.end),e),r};this.b=r(this.b),this.rowP=r(this.rowP),this.lo=this.lo.map(r),this.hi=this.hi.map(r);let i=e-this.start;this.mStart+=i,this.mEnd+=i,this.dirty!==1/0&&(this.dirty+=i),this.dirtyFront>=0&&(this.dirtyFront+=i),this.start=e,this.end=e+n}touch(e){e===this.start&&e+1<this.mEnd?this.dirtyFront=e:e<this.dirty&&(this.dirty=e)}clearRow(e){for(let t=0;t<this.nc;t++)this.lo[t][e]=NaN,this.hi[t][e]=NaN;this.touch(e)}row(e){let t=this.end;if(t>this.start&&this.b[t-1]===e)return t-1;if(t===this.start||e>this.b[t-1])return t===this.b.length&&(this.start>this.count?this.relocate(0,this.b.length):this.relocate(0,Math.max(1024,this.b.length*2))),this.b[this.end]=e,this.clearRow(this.end),this.end++;let n=this.lowerBound(e);if(this.b[n]===e)return n;if(n!==this.start){this.end===this.b.length&&(this.start>this.count?this.relocate(0,this.b.length):this.relocate(0,Math.max(1024,this.b.length*2)),n=this.lowerBound(e));let t=e=>e.copyWithin(n+1,n,this.end);return t(this.b),t(this.rowP),this.lo.forEach(t),this.hi.forEach(t),this.end++,n<this.mEnd&&this.mEnd++,this.dirty!==1/0&&this.dirty>=n&&this.dirty++,this.b[n]=e,this.clearRow(n),n}if(this.start===0){let e=Math.max(1024,this.count);this.relocate(e,2*e+this.count)}return this.start--,this.b[this.start]=e,this.clearRow(this.start),this.invalid=!0,this.start}coarsen(e){let t=new Int32Array(this.end-this.start),n=this.start-1;for(let r=this.start;r<this.end;r++){let i=Math.floor(this.b[r]/e);(n<this.start||this.b[n]!==i)&&(this.b[++n]=i),t[r-this.start]=n}for(let e=0;e<this.nc;e++){let n=this.lo[e],r=this.hi[e],i=-1;for(let e=this.start;e<this.end;e++){let a=t[e-this.start],o=n[e],s=r[e];if(a!==i){n[a]=o,r[a]=s,i=a;continue}o===o&&(n[a]<=o||(n[a]=o),r[a]>=s||(r[a]=s))}}this.end=n+1,this.bucket*=e,this.dirty=1/0,this.dirtyFront=-1,this.invalid=!0}dropBelow(e){this.start=this.lowerBound(e),this.start===this.end&&(this.start=this.end=0,this.invalid=!0)}reset(e){this.clearRow(e)}fold(e,t,n,r){this.touch(e);for(let i=0;i<t.length;i++){let a=t[i],o=1/0,s=-1/0;for(let e=n;e<r;e++){let t=a[e];t<o&&(o=t),t>s&&(s=t)}if(o===1/0)continue;let c=this.lo[i],l=this.hi[i],u=c[e],d=l[e];c[e]=u<=o?u:o,l[e]=d>=s?d:s}}toRows(e,t,n,r,i){let a=[];for(let o=e;o<t;o++){let e={...n,b:this.b[o],pass:0};for(let t=0;t<this.nc;t++){let n=this.lo[t][o];n===n&&(e[r[t]]=n,e[i[t]]=this.hi[t][o])}a.push(e)}return a}pointsOf(e){for(let t=0;t<this.nc;t++){let n=this.hi[t][e];if(n===n&&n!==this.lo[t][e])return 2}return 1}writeRow(e,t,n){let r=(this.b[e]+.5)*this.bucket;this.px[t]=r;for(let n=0;n<this.nc;n++)this.pv[n][t]=this.lo[n][e];if(n===2){this.px[t+1]=r;for(let n=0;n<this.nc;n++)this.pv[n][t+1]=this.hi[n][e]}}reserve(e){if(this.pEnd+e<=this.px.length)return;let t=this.pEnd-this.pStart,n=$G-this.pStart,r=2*(t+e+$G)<=this.px.length,i=r?this.px.length:Math.max(4*this.b.length+$G,2*(t+e+$G)),a=e=>{if(r)return e.copyWithin($G,this.pStart,this.pEnd),e;let t=new Float64Array(i);return t.set(e.subarray(this.pStart,this.pEnd),$G),t};this.px=a(this.px),this.pv=this.pv.map(a);for(let e=this.mStart;e<this.mEnd;e++)this.rowP[e]+=n;this.pStart=$G,this.pEnd=$G+t}writeFrom(e){this.mEnd=e;for(let t=e;t<this.end;t++){let e=this.pointsOf(t);this.reserve(e),this.rowP[t]=this.pEnd,this.writeRow(t,this.pEnd,e),this.pEnd+=e,this.mEnd=t+1}}writeAll(){let e=this.start,t=this.count,n=new Uint8Array(t);for(let r=0;r<this.nc;r++){let i=this.lo[r],a=this.hi[r];for(let r=0;r<t;r++){let t=a[e+r];t===t&&t!==i[e+r]&&(n[r]=1)}}let r=0;for(let e=0;e<t;e++)r+=1+n[e];this.pStart=this.pEnd=$G,this.mStart=this.mEnd=e,this.reserve(r);let i=$G;for(let r=0;r<t;r++){let t=(this.b[e+r]+.5)*this.bucket;this.rowP[e+r]=i,this.px[i]=t,n[r]&&(this.px[i+1]=t),i+=1+n[r]}for(let r=0;r<this.nc;r++){let i=this.lo[r],a=this.hi[r],o=this.pv[r];for(let r=0;r<t;r++){let t=this.rowP[e+r];o[t]=i[e+r],n[r]&&(o[t+1]=a[e+r])}}this.pEnd=i,this.mEnd=this.end}sync(){if(this.pv.length!==this.nc&&(this.pv=Array.from({length:this.nc},()=>new Float64Array)),this.invalid||this.start<this.mStart||this.start>=this.mEnd)this.writeAll();else{this.start>this.mStart&&(this.mStart=this.start,this.pStart=this.rowP[this.start]);let e=Math.max(this.start,Math.min(this.dirty,this.mEnd)),t=this.dirtyFront;if(t===this.start)if(t+1<e){let e=this.pointsOf(t),n=this.rowP[t+1]-e;if(n<0)return this.invalid=!0,this.sync();this.rowP[t]=n,this.pStart=n,this.writeRow(t,n,e)}else e=t;e<this.end&&(e<this.mEnd&&(this.pEnd=this.rowP[e]),this.writeFrom(e))}this.dirty=1/0,this.dirtyFront=-1,this.invalid=!1}toPoints(e,t,n){this.sync();let r=e<t?this.rowP[e]:0,i=e<t?t<this.mEnd?this.rowP[t]:this.pEnd:0;return{length:i-r,x:this.px.subarray(r,i),cols:new Map(n.map((e,t)=>[e,this.pv[t].subarray(r,i)]))}}}}));function nK(e){if(!(e>0)||!Number.isFinite(e))return e;let t=10**Math.floor(Math.log10(e)),n=e/t;return(n<1.5?1:n<3.5?2:n<7.5?5:10)*t}function rK(e,t,n,r,i){if(n instanceof Float64Array||n instanceof Float32Array)e.set(n.subarray(r,r+i),t);else for(let a=0;a<i;a++)e[t+a]=+n[r+a]}function iK(e,t){let n=e.t.length,r=Object.keys(e.columns).filter(e=>e!==t);for(let t of r)if(e.columns[t].length!==n)throw RangeError(`live column "${t}" has ${e.columns[t].length} values for ${n} times`);return r}function aK(e){let t=fK[e];if(!t){let n=Array.from({length:e},(e,t)=>`y${t}lo`),r=Array.from({length:e},(e,t)=>`y${t}hi`);t={lo:n,hi:r,row:JSON.parse(JSON.stringify(Object.fromEntries([[`b`,0],[`pass`,0],...n.flatMap((e,t)=>[[e,null],[r[t],null]])])))},fK[e]=t}return t}function oK(e,t){return qe({keys:e,length:t[0]?.length??0,values:t,text:e.map(()=>null)})}var sK,cK,lK,uK,dK,fK,pK,mK,hK,gK=c((()=>{RE(),QG(),tK(),Qe(),sK=4e6,cK=60,lK=32,uK=4,dK=`ElapsedTime`,fK=[],pK=4096,mK=4,hK=class{time;alloc;maxBytes;cols=new Map;head=0;count=0;full=!1;pushed=0;clears=0;pushedBefore=0;signalOrder=[];unitByName=new Map;capacity;timeColumn;timeUnit;lastBackAbs=-1;get timeMonotonic(){return this.lastBackAbs<=this.pushed-this.size}lastPushT=-1/0;decCache=null;passTrack=null;prevCyclePts=null;curCyclePts=null;trackers=new Map;debugLastScan=0;debugGrowCopied=0;timeDecs=new Map;mirrors=new Map;historyDec=null;snapDec=null;latest=new Map;listed=new Map;constructor(e,t=dK,n=`s`,r=1/0){this.capacity=Math.max(2,Math.floor(e)),this.timeColumn=t,this.timeUnit=n,this.maxBytes=r,this.alloc=Math.min(this.capacity,pK),this.time=new Float64Array(this.alloc)}get maxSamples(){return this.capacity}newColumn(){if(this.growing)try{return new Float64Array(this.growing.next).fill(NaN)}catch(e){this.refused(e)}return new Float64Array(this.alloc).fill(NaN)}growing=null;stepGrow(e){if(this.full)return;if(!this.growing){if(this.count<this.alloc*.75||this.alloc>=this.capacity)return;let e=Math.min(this.capacity,this.alloc*2);if(e*8*(1+this.cols.size)>this.maxBytes)return;this.growing={next:e,todo:[null,...this.cols.keys()],owed:0}}let t=this.growing;t.owed+=t.todo.length*e/Math.max(1,this.alloc-this.count),this.moveColumns(Math.floor(t.owed))}moveColumns(e){let t=this.growing;for(;e>0&&t.todo.length>0;e--,t.owed--){let e=t.todo.pop(),n=e===null?this.time:this.cols.get(e);if(!n||n.length>=t.next)continue;let r;try{r=new Float64Array(t.next)}catch(e){this.refused(e);return}r.set(n),this.debugGrowCopied+=n.length,e===null?this.time=r:this.cols.set(e,r)}t.todo.length===0&&(this.alloc=t.next,this.growing=null)}growNow(){this.growing?this.moveColumns(1/0):this.grow()}grow(){let e=Math.min(this.capacity,this.alloc*2);if(e*8*(1+this.cols.size)>this.maxBytes){this.capacity=this.alloc;return}let t=t=>{let n=new Float64Array(e);return n.set(t),this.debugGrowCopied+=t.length,n};try{this.time=t(this.time);for(let[e,n]of this.cols)this.cols.set(e,t(n))}catch(e){this.refused(e);return}this.alloc=e}refused(e){if(!(e instanceof RangeError))throw e;this.capacity=this.alloc,this.growing=null}get version(){return this.pushedBefore+this.pushed+this.clears}get size(){return this.full?this.capacity:this.count}push(e){for(let[t,n]of this.trackers){let r=t===this.timeColumn?e.t:e.signals.find(e=>e.name===t)?.value;r!==void 0&&Number.isFinite(r)&&this.advanceCycle(t,n,r,this.pushed)}let t=this.lastPushT;this.lastPushT=Math.max(t,e.t),!this.full&&this.count===this.alloc&&(this.growNow(),this.count===this.capacity&&(this.full=!0));let n=this.full?this.head:this.count;this.time[n]=e.t;for(let e of this.signalOrder)this.cols.get(e)[n]=NaN;for(let t of e.signals){if(this.computed.has(t.name))continue;let r=this.cols.get(t.name);r?t.unit&&t.unit!==this.unitByName.get(t.name)&&(this.unitByName.get(t.name)&&this.dropColumnSamples(t.name,r),this.unitByName.set(t.name,t.unit)):(r=this.newColumn(),this.cols.set(t.name,r),this.signalOrder.push(t.name),this.listed.delete(t.name),this.unitByName.set(t.name,t.unit??``)),r[n]=t.value,Number.isFinite(t.value)&&this.noteValue(t.name,e.t,t.value)}this.pushed++,this.full?this.head=(this.head+1)%this.capacity:(this.count++,this.count===this.capacity&&(this.full=!0)),this.stepGrow(1),e.t<t&&this.placeLate(t,e.t,1,!0,this.pushed-1)}pushColumns(e){let t=e.t,n=t.length,r=iK(e,this.timeColumn);if(n===0)return;if(this.trackers.size>0){for(let i=0;i<n;i++)this.push({t:t[i],signals:r.map(t=>({name:t,unit:e.units?.[t],value:e.columns[t][i]}))});return}for(let t of r){if(this.computed.has(t))continue;let n=e.units?.[t],r=this.cols.get(t);r?n&&n!==this.unitByName.get(t)&&(this.unitByName.get(t)&&this.dropColumnSamples(t,r),this.unitByName.set(t,n)):(this.cols.set(t,this.newColumn()),this.signalOrder.push(t),this.listed.delete(t),this.unitByName.set(t,n??``))}for(let i of r){if(this.computed.has(i))continue;let r=e.columns[i];for(let e=n-1;e>=0;e--)if(Number.isFinite(r[e])){this.noteValue(i,+t[e],r[e]);break}}let i=this.lastPushT,a=1/0,o=-1/0,s=!0,c=-1;for(let e=0;e<n;e++){let n=+t[e];n<(e>0?+t[e-1]:i)&&(c=e,e>0&&(s=!1)),n<a&&(a=n),n>o&&(o=n)}let l=this.pushed+c;this.lastPushT=Math.max(i,o);let u=Math.max(0,n-this.capacity);for(this.pushed+=u;u<n;){!this.full&&this.count===this.alloc&&(this.growNow(),this.count===this.capacity&&(this.full=!0));let r=this.full?this.head:this.count,i=Math.min(n-u,this.full?this.capacity-this.head:this.alloc-this.count);rK(this.time,r,t,u,i);for(let t of this.signalOrder){let n=this.cols.get(t),a=this.computed.has(t)?void 0:e.columns[t];a?rK(n,r,a,u,i):n.fill(NaN,r,r+i)}this.pushed+=i,u+=i,this.full?this.head=(this.head+i)%this.capacity:(this.count+=i,this.count===this.capacity&&(this.full=!0))}this.stepGrow(Math.min(n,this.capacity)),c>=0&&this.placeLate(i,a,Math.min(n,this.capacity),s,l)}placeLate(e,t,n,r,i){if(e-t>cK){this.steppedBack(i);return}let a=this.size,o=a-n,s=e=>this.full?(this.head+e)%this.capacity:e,c=0,l=o;for(;c<l;){let e=c+l>>>1;this.time[s(e)]<=t?c=e+1:l=e}r||(c=Math.min(c,o));let u=a-c;if(u<2)return;if(u*(this.cols.size+1)>sK||!this.timeMonotonic){this.steppedBack(i);return}let d=new Float64Array(u);for(let e=0;e<u;e++)d[e]=this.time[s(c+e)];let f=new Uint32Array(u);for(let e=0;e<u;e++)f[e]=e;f.sort((e,t)=>d[e]-d[t]||e-t);let p=new Set;for(let t=u-n;t<u;t++)if(!(t<0||d[t]>=e))for(let[e,n]of this.cols)Number.isFinite(n[s(c+t)])&&p.add(e);let m=[],h=this.snapDec;h&&h.key===`${this.signalOrder.join(`
|
|
82
|
+
`)}|${this.clears}`?m.push({k:h,names:this.signalOrder,ycols:this.signalOrder.map(e=>this.cols.get(e)),drop:()=>{this.snapDec===h&&(this.snapDec=null)}}):this.snapDec=null;for(let[e,t]of this.timeDecs)for(let n of t)m.push({k:n,names:n.cols,ycols:n.cols.map(e=>this.cols.get(e)),drop:()=>{let t=(this.timeDecs.get(e)??[]).filter(e=>e!==n);t.length>0?this.timeDecs.set(e,t):this.timeDecs.delete(e)}});let g=m.filter(e=>{let t=this.pushed-n-e.k.pushed;try{if(t<0||t>o||t*e.ycols.length>sK)throw Error(`behind`);return t>0&&(this.foldBuckets(e.k.store,o-t,o,e.k.bucket,e.ycols),e.k.pushed+=t),!0}catch{return e.drop(),!1}}),_=new Float64Array(u),v=e=>{for(let t=0;t<u;t++)_[t]=e[s(c+f[t])];for(let t=0;t<u;t++)e[s(c+t)]=_[t]};v(this.time);for(let e of this.cols.values())v(e);let y=this.pushed-a+c;this.decCache&&this.decCache.pushed>y&&(this.decCache.pushed=y);let b=this.passTrack;if(b&&b.done>y){b.cuts=b.cuts.filter(e=>e.abs<y),b.done=y,b.prevX=NaN;let e=this.cols.get(b.key);for(let t=y-1;e&&t>=this.pushed-a;t--){let n=e[this.physOf(t)];if(!Number.isNaN(n)){b.prevX=n;break}}}for(let t of g)if(t.names.some(e=>p.has(e)))try{for(let r=0;r<u;r++){if(f[r]<u-n||d[f[r]]>=e)continue;let i=s(c+r),a=Math.floor(this.time[i]/t.k.bucket);a>=t.k.fromB&&t.k.store.fold(t.k.store.row(a),t.ycols,i,i+1)}}catch{t.drop()}this.historyDec=null;for(let e of this.mirrors.values())e.end=Math.max(e.first,Math.min(e.end,y)),e.view=null;for(let[e,t]of this.boundsCache)t.loAbs>=y||t.hiAbs>=y?this.boundsCache.delete(e):(t.done=Math.min(t.done,y),t.version=-1)}steppedBack(e){this.lastBackAbs=e,this.timeDecs.clear(),this.snapDec=null}dropColumnSamples(e,t){t.fill(NaN),this.decCache=null,this.timeDecs.clear(),this.snapDec=null;for(let t of this.trackers.values())t.previous?.cols.delete(e);this.clears++}clear(){this.clears++,this.pushedBefore+=this.pushed,this.head=0,this.count=0,this.full=!1,this.pushed=0,this.growing=null,this.cols.clear(),this.computed.clear(),this.signalOrder.length=0,this.unitByName.clear(),this.decCache=null,this.timeDecs.clear(),this.snapDec=null,this.latest.clear(),this.listed.clear(),this.lastBackAbs=-1,this.lastPushT=-1/0,this.trackers.clear()}columnArray(e){return e===this.timeColumn?this.time:this.cols.get(e)}physOf(e){let t=e-(this.pushed-this.size);return this.full?(this.head+t)%this.capacity:t}copyRange(e,t,n,r=[this.timeColumn,...this.signalOrder]){let i=Math.max(t,this.pushed-this.size),a=Math.max(0,n-i),o=this.columnArray(e),s=new Float64Array(a),c=new Map;for(let e of r)this.columnArray(e)&&c.set(e,new Float64Array(a));for(let e=0;e<a;e++){let t=this.physOf(i+e);s[e]=o?o[t]:NaN;for(let[n,r]of c)r[e]=this.columnArray(n)[t]}return{x:s,cols:c}}advanceCycle(e,t,n,r){Number.isFinite(t.lastX)&&n<t.lastX&&t.lastX-n>(t.hi-t.lo)/2?(t.previous=this.copyRange(e,t.start,r),t.start=r,t.lo=t.hi=n):Number.isFinite(t.lastX)?(n<t.lo&&(t.lo=n),n>t.hi&&(t.hi=n)):t.lo=t.hi=n,n<t.allLo&&(t.allLo=n),n>t.allHi&&(t.allHi=n),t.lastX=n}trackCycles(e){if(this.trackers.has(e))return;let t={start:this.pushed-this.size,lo:0,hi:0,lastX:NaN,allLo:1/0,allHi:-1/0,previous:null,next:this.pushed},n=this.columnArray(e),r=this.pushed-this.size;if(n)for(let i=r;i<this.pushed;i++){let r=n[this.physOf(i)];Number.isFinite(r)&&this.advanceCycle(e,t,r,i)}this.trackers.set(e,t)}cycleSpan(e){let t=this.trackers.get(e);return t&&t.allHi>t.allLo?[t.allLo,t.allHi]:null}decimateCycle(e,t,n,r,i,a){let o=this.trackers.get(e),s=n.filter(e=>this.cols.has(e));if(!o)return{x0:r,bucket:0,rows:[],columns:s};let c=t===`previous`?o.previous:this.copyRange(e,o.start,this.pushed,s);if(!c)return{x0:r,bucket:0,rows:[],columns:s};let l=s.map(e=>c.cols.get(e)??new Float64Array(c.x.length).fill(NaN));return ME(c.x,l,s,r,i,a)}decimateCyclePoints(e,t,n,r,i,a){let o=()=>{let o=this.decimateCycle(e,t,n,r,i,a);return VG(o.rows,o.columns,o.x0,o.bucket)},s=this.trackers.get(e),c=Math.floor(a),l=this.columnArray(e);if(!s||!l||!(i>r)||c<1)return o();let u=n.filter(e=>this.cols.has(e)),d=u.join(` `);if(t===`previous`){let e=this.prevCyclePts;if(e&&e.snap===s.previous&&e.x0===r&&e.x1===i&&e.mp===a&&e.colsKey===d)return e.pts;let t=o();return this.prevCyclePts={snap:s.previous,x0:r,x1:i,mp:a,colsKey:d,pts:t},t}if(s.start<this.pushed-this.size)return o();let f=this.curCyclePts;if((!f||f.key!==e||f.start!==s.start||f.x0!==r||f.x1!==i||f.mp!==a||f.colsKey!==d||f.clears!==this.clears)&&(f=this.curCyclePts={key:e,start:s.start,x0:r,x1:i,mp:a,colsKey:d,clears:this.clears,done:s.start,pts:null,seen:new Uint8Array(c),lo:u.map(()=>new Float64Array(c).fill(1/0)),hi:u.map(()=>new Float64Array(c).fill(-1/0))}),f.pts&&f.done===this.pushed)return f.pts;let p=(i-r)/a,m=u.map(e=>this.columnArray(e));for(let e=f.done;e<this.pushed;e++){let t=this.physOf(e),n=l[t];if(!(n>=r&&n<=i))continue;let a=Math.floor((n-r)/p);a>=c&&(a=c-1),f.seen[a]=1;for(let e=0;e<m.length;e++){let n=m[e][t];n===n&&(n<f.lo[e][a]&&(f.lo[e][a]=n),n>f.hi[e][a]&&(f.hi[e][a]=n))}}f.done=this.pushed;let h=0,g=new Uint8Array(c);for(let e=0;e<c;e++)if(f.seen[e]){for(let t=0;t<m.length;t++){let n=f.hi[t][e];if(n!==-1/0&&n!==f.lo[t][e]){g[e]=1;break}}h+=1+g[e]}let _=new Float64Array(h),v=u.map(()=>new Float64Array(h)),y=0;for(let e=0;e<c;e++){if(!f.seen[e])continue;let t=r+(e+.5)*p;_[y]=t;for(let t=0;t<m.length;t++){let n=f.lo[t][e];v[t][y]=n===1/0?NaN:n}if(y++,g[e]){_[y]=t;for(let t=0;t<m.length;t++){let n=f.hi[t][e];v[t][y]=n===-1/0?NaN:n}y++}}return f.pts={length:h,x:_,cols:new Map(u.map((e,t)=>[e,v[t]]))},f.pts}computed=new Set;get firstAbs(){return this.pushed-this.size}get endAbs(){return this.pushed}range(e,t,n){let r=Math.max(t,this.firstAbs),i=new Float64Array(Math.max(0,Math.min(n,this.pushed)-r)),a=this.columnArray(e);if(!a)return i.fill(NaN);for(let e=0;e<i.length;e++)i[e]=a[this.physOf(r+e)];return i}mirrorColumn(e){let t=this.columnArray(e);if(!t)return;let n=this.firstAbs,r=this.pushed,i=this.mirrors.get(e);if((!i||i.clears!==this.clears)&&(i={arr:new Float64Array(Math.max(16,r-n)),first:n,end:n,clears:this.clears,view:null},this.mirrors.set(e,i)),i.first===n&&i.end===r&&i.view)return i.view;if(n>i.first){let e=Math.max(0,i.end-n);e>0&&i.arr.copyWithin(0,n-i.first,i.end-i.first),i.first=n,i.end=n+e}if(i.arr.length<r-n){let e=new Float64Array(Math.max(r-n,i.arr.length*2));e.set(i.arr.subarray(0,i.end-i.first)),i.arr=e}for(let e=i.end;e<r;){let a=this.physOf(e),o=Math.min(r-e,(this.full?this.capacity:this.alloc)-a);i.arr.set(t.subarray(a,a+o),e-n),e+=o}return i.end=r,i.view=i.arr.subarray(0,r-n),i.view}writeComputed(e,t,n,r){let i=this.mirrors.get(e);i&&n<i.end&&(i.end=Math.max(i.first,n),i.view=null);let a=this.cols.get(e);(!a||!this.computed.has(e))&&(a||(a=this.newColumn(),this.cols.set(e,a),this.signalOrder.push(e),this.listed.delete(e)),this.computed.add(e)),this.unitByName.set(e,t);for(let e=0;e<r.length;e++){let t=n+e;t<this.firstAbs||t>=this.pushed||(a[this.physOf(t)]=r[e]??NaN)}let o=this.trackers.get(e);if(o){for(let t=0;t<r.length;t++){let i=n+t,a=r[t];i<o.next||i<this.firstAbs||i>=this.pushed||a===null||!Number.isFinite(a)||this.advanceCycle(e,o,a,i)}o.next=Math.max(o.next,Math.min(this.pushed,n+r.length))}}clearComputed(){for(let e of this.computed){this.cols.delete(e),this.unitByName.delete(e);for(let t of this.trackers.values())t.previous?.cols.delete(e)}this.signalOrder.splice(0,this.signalOrder.length,...this.signalOrder.filter(e=>!this.computed.has(e))),this.computed.clear(),this.decCache=null,this.timeDecs.clear(),this.clears++}get columnNames(){return[this.timeColumn,...this.signalOrder,...this.listed.keys()]}get columnCount(){return 1+this.signalOrder.length+this.listed.size}has(e){return e===this.timeColumn||this.cols.has(e)||this.listed.has(e)}unitOf(e){return e===this.timeColumn?this.timeUnit:this.unitByName.get(e)??this.listed.get(e)??``}columnValues(e){let t=this.size,n=new Float64Array(t),r=e===this.timeColumn?this.time:this.cols.get(e);if(!r)return n.fill(NaN),n;for(let e=0;e<t;e++)n[e]=r[this.full?(this.head+e)%this.capacity:e];return n}accumulate(e,t,n,r,i){let a=aK(i.length),o=n[t];if(Number.isNaN(o))return;let s=Math.floor(o/r),c=e.get(s);c||(c={...a.row,b:s},e.set(s,c));for(let e=0;e<i.length;e++){let n=i[e][t];if(Number.isNaN(n))continue;let r=a.lo[e],o=a.hi[e],s=c[r],l=c[o];c[r]=s==null?n:Math.min(s,n),c[o]=l==null?n:Math.max(l,n)}}decimateColumns(e,t,n,r,i){if(e===this.timeColumn&&this.timeMonotonic)return this.decimateTime(t,n,r,i);let a=e===this.timeColumn?this.time:this.cols.get(e),o=a?t.filter(e=>this.cols.has(e)):[],s=(r-n)/i,c=this.size;if(c>1&&e===this.timeColumn&&this.timeMonotonic&&a){let e=a[this.full?this.head:0],t=(a[this.full?(this.head+c-1)%this.capacity:c-1]-e)/(c-1);t>0&&t<s&&(s=.7*Math.max(t,(r-n)/(i*mK)))}let l=nK(s);{let t=this.decCache;t&&t.xKey===e&&t.colsKey===o.join(` `)&&t.bucket>0&&s>=t.bucket*.5&&s<=t.bucket*2&&(l=t.bucket)}if(!a||o.length===0||!(r>n)||!(l>0))return{x0:n,bucket:0,rows:[],columns:o};let u=o.map(e=>this.cols.get(e)),d=this.size,f=o.join(`\0`);this.debugLastScan=0;let p=this.decCache,m=p!==null&&e===this.timeColumn&&this.timeMonotonic&&p.xKey===e&&p.colsKey===f&&p.bucket===l&&this.pushed>=p.pushed&&this.pushed-p.pushed<d&&p.map.size<this.capacity*2,h=p!==null&&p.xKey===e&&p.colsKey===f&&p.bucket===l&&p.pushed===this.pushed,g=this.pushed-d,_=e===this.timeColumn&&this.timeMonotonic?g:Math.max(g,this.passStart(e,a)),v=p!==null&&(_>g||!this.full)&&p.xKey===e&&p.colsKey===f&&p.bucket===l&&p.passStart===_&&p.pushed>=_&&p.pushed<=this.pushed,y;if(h&&p)y=p.map;else if(v&&p){y=p.map;for(let e=p.pushed;e<this.pushed;e++)this.debugLastScan++,this.accumulate(y,this.physOf(e),a,l,u);p.pushed=this.pushed}else if(m&&p){y=p.map;let e=this.pushed-p.pushed;for(let t=d-e;t<d;t++){let e=this.full?(this.head+t)%this.capacity:t;this.debugLastScan++,this.accumulate(y,e,a,l,u)}if(this.full&&d>0){let e=a[this.head];if(!Number.isNaN(e)){let t=Math.floor(e/l);for(let e=p.lowB;e<t;e++)y.delete(e);y.delete(t);for(let e=0;e<d;e++){let n=(this.head+e)%this.capacity,r=a[n];if(!Number.isNaN(r)){if(Math.floor(r/l)>t)break;this.debugLastScan++,this.accumulate(y,n,a,l,u)}}p.lowB=t}}p.pushed=this.pushed}else{y=new Map;let t=1/0;for(let e=_;e<this.pushed;e++){let n=this.physOf(e),r=a[n];if(Number.isNaN(r))continue;this.debugLastScan++,this.accumulate(y,n,a,l,u);let i=Math.floor(r/l);i<t&&(t=i)}this.decCache={xKey:e,colsKey:f,cols:o,bucket:l,map:y,pushed:this.pushed,lowB:Number.isFinite(t)?t:0,passStart:_}}let b=Math.floor(n/l),x=Math.floor(r/l),S=[];for(let e of y.values()){let t=e.b;t>=b&&t<=x&&S.push(e)}return S.sort((e,t)=>Number(e.b)-Number(t.b)),{x0:0,bucket:l,rows:S,columns:o}}passStart(e,t){let n=this.pushed-this.size,r=this.passTrack;(!r||r.key!==e||r.clears!==this.clears)&&(r=this.passTrack={key:e,clears:this.clears,done:n,prevX:NaN,cuts:[]});let{x0:i,x1:a}=this.columnBounds(e),o=(a-i)/2;for(let e=Math.max(r.done,n);e<this.pushed;e++){let n=t[this.physOf(e)];Number.isNaN(n)||(n<r.prevX-o&&(r.cuts.push({abs:e,drop:r.prevX-n}),r.cuts.length>64&&r.cuts.shift()),r.prevX=n)}for(r.done=this.pushed;r.cuts.length>0&&r.cuts[0].abs<n;)r.cuts.shift();for(let e=r.cuts.length-1;e>=0;e--)if(r.cuts[e].drop>o)return r.cuts[e].abs;return n}timeIndex(e){let t=0,n=this.size;for(;t<n;){let r=t+n>>>1;this.time[this.full?(this.head+r)%this.capacity:r]<e?t=r+1:n=r}return t}foldBuckets(e,t,n,r,i){this.eachBucketRun(t,n,r,(t,n,r)=>e.fold(e.row(t),i,n,r))}eachBucketRun(e,t,n,r){if(t<=e)return;this.debugLastScan+=t-e;let i=this.time,a=e=>Math.floor(i[e]/n),o=(e,t)=>{let n=e;for(;n<t;){let e=a(n),i=n,o=1;for(;n+o<t&&a(n+o)===e;)i=n+o,o*=2;let s=i+1,c=Math.min(n+o,t);for(;s<c;){let t=s+c>>>1;a(t)===e?s=t+1:c=t}r(e,n,s),n=s}};if(!this.full)return o(e,t);let s=(this.head+e)%this.capacity,c=s+(t-e);if(c<=this.capacity)return o(s,c);o(s,this.capacity),o(0,c-this.capacity)}decimateTime(e,t,n,r){let i=this.timeBuckets(e,t,n,r);if(!i.store)return{x0:t,bucket:0,rows:[],columns:i.cols};let a=aK(i.cols.length),o=()=>i.store.toRows(i.i0,i.i1,a.row,a.lo,a.hi),s=this.historyDec;return{x0:0,bucket:i.bucket,rows:s?.store===i.store?s.rows??=o():o(),columns:i.cols}}decimatePoints(e,t,n,r,i){if(e===this.timeColumn&&this.timeMonotonic){let e=this.timeBuckets(t,n,r,i);return e.store?e.store.toPoints(e.i0,e.i1,e.cols):{length:0,x:new Float64Array,cols:new Map(e.cols.map(e=>[e,new Float64Array]))}}let a=this.decimateColumns(e,t,n,r,i);return VG(a.rows,a.columns,a.x0,a.bucket)}timeBuckets(e,t,n,r){let i=e.filter(e=>this.cols.has(e)),a=this.size,o={cols:i,bucket:0,store:null,i0:0,i1:0};if(i.length===0||!(n>t)||a===0)return o;let s=e=>this.full?(this.head+e)%this.capacity:e,c=this.time[s(0)],l=this.time[s(a-1)],u=(n-t)/r;if(a>1){let e=(l-c)/(a-1);e>0&&e<u&&(u=.7*Math.max(e,(n-t)/(r*mK)))}let d=nK(u),f=i.join(` `),p=this.timeDecs.get(f)??[],m=p.find(e=>u>=e.bucket*.5&&u<=e.bucket*2)??null;if(m&&(d=m.bucket),!(d>0))return o;let h=i.map(e=>this.cols.get(e)),g=Math.floor(t/d),_=Math.floor(n/d);this.debugLastScan=0;let v=e=>({cols:i,bucket:d,store:e,i0:e.lowerBound(g),i1:e.lowerBound(_+1)});if(n<l-(n-t)){let e=this.timeIndex(g*d),t=this.timeIndex((_+1)*d),n=this.pushed-a,r=`${f}|${d}|${g}|${_}|${n+e}|${n+t}|${this.clears}`;if(this.historyDec?.key!==r){let n=new eK(i.length,d);this.foldBuckets(n,e,t,d,h),this.historyDec={key:r,store:n}}return v(this.historyDec.store)}let y=m?this.pushed-m.pushed:0;if(m&&m.colsKey===f&&m.bucket===d&&y>=0&&y<a){let e=m.store;if(g<m.fromB){let t=new eK(i.length,d);this.foldBuckets(t,this.timeIndex(g*d),this.timeIndex(m.fromB*d),d,h);for(let n=t.end-1;n>=t.start;n--){let r=e.row(t.b[n]);for(let i=0;i<t.nc;i++)e.lo[i][r]=t.lo[i][n],e.hi[i][r]=t.hi[i][n]}m.fromB=g}y>0&&this.foldBuckets(e,a-y,a,d,h);let t=Math.floor(c/d);return this.full&&t>=m.fromB&&(e.dropBelow(t),e.reset(e.row(t)),this.foldBuckets(e,0,this.timeIndex((t+1)*d),d,h),m.fromB=t),g>m.fromB&&(e.dropBelow(g),m.fromB=g),m.pushed=this.pushed,v(e)}let b=new eK(i.length,d),x=this.timeIndex(g*d);this.foldBuckets(b,x,a,d,h);let S={colsKey:f,cols:i,bucket:d,store:b,pushed:this.pushed,fromB:x===0?Math.floor(c/d):g};return this.timeDecs.delete(f),this.timeDecs.set(f,[S,...p.filter(e=>e!==m&&e.bucket!==d)].slice(0,uK)),this.timeDecs.size>lK&&this.timeDecs.delete(this.timeDecs.keys().next().value),v(b)}lastValue(e){let t=e===this.timeColumn?this.time:this.cols.get(e);return!t||this.size===0?NaN:t[this.full?(this.head-1+this.capacity)%this.capacity:this.count-1]}xTravel(e,t){let n=this.columnArray(e),r=this.size;if(!n||r<2)return NaN;let i=e=>this.full?(this.head+e)%this.capacity:e,a=this.time[i(r-1)],o=0,s=NaN,c=a;for(let e=r-1;e>=0;e--){let r=i(e),l=this.time[r];if(l<a-t)break;let u=n[r];Number.isNaN(u)||(s>u&&(o+=s-u),s=u,c=l)}let l=a-c;return l>0&&l<t?o*t/l:o}timeAfter(e){if(!this.timeMonotonic)return NaN;let t=e=>this.full?(this.head+e)%this.capacity:e,n=0,r=this.size;for(;n<r;){let i=n+r>>>1;this.time[t(i)]<=e?n=i+1:r=i}return n<this.size?this.time[t(n)]:NaN}latestTime(){return this.size===0?NaN:this.columnBounds(this.timeColumn).x1}xAtTime(e,t,n=!1){let r=this.columnArray(e),i=this.size;if(!r||i===0)return NaN;if(e===this.timeColumn&&!n){let{x0:n,x1:r}=this.columnBounds(e);return Math.min(r,Math.max(n,t))}if(!this.timeMonotonic)return NaN;let a=e=>this.full?(this.head+e)%this.capacity:e,o=0,s=i-1;if(t<=this.time[a(0)])return r[a(0)];if(t>=this.time[a(s)])return r[a(s)];for(;s-o>1;){let e=o+s>>1;this.time[a(e)]<=t?o=e:s=e}let c=a(o),l=a(s),u=r[c],d=r[l];if(n||!(d>=u))return u;let f=this.time[c],p=this.time[l];return p>f?u+(d-u)*(t-f)/(p-f):u}boundsCache=new Map;columnBounds(e){let t=e===this.timeColumn?this.time:this.cols.get(e),n=this.size;if(!t||n===0)return{x0:0,x1:0};if(t===this.time&&this.timeMonotonic)return{x0:this.time[this.full?this.head:0],x1:this.time[this.full?(this.head+n-1)%this.capacity:n-1]};let r=this.pushed-n,i=this.boundsCache.get(e);if(i&&i.version===this.version)return i.b;(!i||i.clears!==this.clears||i.loAbs<r||i.hiAbs<r)&&(i={version:-1,clears:this.clears,done:r,lo:1/0,hi:-1/0,loAbs:1/0,hiAbs:1/0,b:{x0:0,x1:0}},this.boundsCache.set(e,i));for(let e=Math.max(i.done,r);e<this.pushed;e++){let n=t[this.physOf(e)];Number.isNaN(n)||(n<=i.lo&&(i.lo=n,i.loAbs=e),n>=i.hi&&(i.hi=n,i.hiAbs=e))}return i.done=this.pushed,i.version=this.version,i.b=Number.isFinite(i.lo)?{x0:i.lo,x1:i.hi}:{x0:0,x1:0},i.b}toDataset(e){let t=[...this.listed.keys()],n=[this.timeColumn,...this.signalOrder,...t],r=[this.timeUnit,...this.signalOrder.map(e=>this.unitByName.get(e)??``),...t.map(e=>this.listed.get(e))],i=this.size,a=e&&e>0&&i>e?Math.ceil(i/e):1,o=a>1&&this.timeMonotonic?this.snapshotRows(e,t):null;if(o)return{meta:``,columnNames:n,units:r,rows:o};let s=this.pushed-i,c=a>1?(a-s%a)%a:0,l=[];for(let e=c;e<i;e+=a)l.push(this.full?(this.head+e)%this.capacity:e);i>0&&(l.length===0||(i-1-c)%a!=0)&&l.push(this.full?(this.head+i-1)%this.capacity:i-1);let u=e=>{let t=new Float64Array(l.length);for(let n=0;n<l.length;n++)t[n]=e[l[n]];return t},d=t.length?new Float64Array(l.length).fill(NaN):null;return{meta:``,columnNames:n,units:r,rows:oK(n,[u(this.time),...this.signalOrder.map(e=>u(this.cols.get(e))),...t.map(()=>d)])}}snapshotRows(e,t){let n=this.size,r=e=>this.full?(this.head+e)%this.capacity:e,i=this.time[r(0)],a=this.time[r(n-1)],o=(a-i)*2/e;if(!(o>0))return null;let s=`${this.signalOrder.join(`
|
|
83
|
+
`)}|${this.clears}`,c=this.signalOrder.map(e=>this.cols.get(e)),l=this.snapDec,u=l?this.pushed-l.pushed:0;if(l&&l.key===s&&l.bucket<o&&u>=0&&u<n){let e=2;for(;l.bucket*e<o;)e*=2;l.store.coarsen(e),l.bucket*=e,l.fromB=Math.floor(l.fromB/e)}if(l&&l.key===s&&l.bucket>=o&&l.bucket<=o*4&&u>=0&&u<n){let e=l.store;u>0&&this.foldBuckets(e,n-u,n,l.bucket,c);let t=Math.floor(i/l.bucket);this.full&&t>=l.fromB&&(e.dropBelow(t),e.reset(e.row(t)),this.foldBuckets(e,0,this.timeIndex((t+1)*l.bucket),l.bucket,c),l.fromB=t),l.pushed=this.pushed}else{let t=2**Math.ceil(Math.log2(o));t<o&&(t*=2);let r=new eK(c.length,t,Math.ceil(e/2)+8);this.foldBuckets(r,0,n,t,c),l=this.snapDec={key:s,bucket:t,store:r,pushed:this.pushed,fromB:Math.floor(i/t)}}let d=l.store.toPoints(l.store.start,l.store.end,this.signalOrder),f=new Float64Array(d.x),p=f[0],m=f[f.length-1];for(let e=0;e<f.length;e++)f[e]=f[e]===m?a:f[e]===p?i:f[e];let h=t.length?new Float64Array(f.length).fill(NaN):null;return oK([this.timeColumn,...this.signalOrder,...t],[f,...this.signalOrder.map(e=>new Float64Array(d.cols.get(e))),...t.map(()=>h)])}valueBounds(e){let t=this.columnBounds(e);return Number.isFinite(this.boundsCache.get(e)?.lo??NaN)?t:null}hasValues(e){return this.latest.has(e)||this.computed.has(e)}get memoryBudget(){return this.maxBytes}get valuedCount(){return this.latest.size}lastKnown(e){return this.latest.get(e)}list(e,t,n=NaN,r=NaN){e===this.timeColumn||this.computed.has(e)||(this.cols.has(e)||this.listed.set(e,t),Number.isFinite(n)&&Number.isFinite(r)&&this.noteValue(e,n,r))}setLastKnown(e,t,n,r){e===this.timeColumn||this.computed.has(e)||!Number.isFinite(n)||!Number.isFinite(r)||(this.cols.has(e)||(this.cols.set(e,this.newColumn()),this.signalOrder.push(e),this.listed.delete(e),this.unitByName.set(e,t)),this.noteValue(e,n,r))}noteValue(e,t,n){let r=this.latest.get(e);r?t>=r.t&&(r.t=t,r.v=n):this.latest.set(e,{t,v:n})}}}));function _K(){let e=globalThis.crypto;if(!e?.subtle)throw Error(`WebCrypto SubtleCrypto is not available`);return e.subtle}function vK(e){let t=``;for(let n=0;n<e.length;n++)t+=String.fromCharCode(e[n]);return btoa(t)}function yK(e){let t=atob(e),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n}async function bK(e,t){let n=new TextEncoder,r=await _K().importKey(`raw`,n.encode(e),`PBKDF2`,!1,[`deriveKey`]);return _K().deriveKey({name:`PBKDF2`,salt:yK(t),iterations:FK,hash:`SHA-256`},r,{name:`AES-GCM`,length:256},!1,[`encrypt`,`decrypt`])}function xK(){(!IK||LK>4294967295)&&(IK=globalThis.crypto.getRandomValues(new Uint8Array(8)),LK=0);let e=new Uint8Array(12);return e.set(IK),new DataView(e.buffer).setUint32(8,LK++),e}async function SK(e,t){let n=yK(t.iv),r=yK(t.ciphertext),i=await _K().decrypt({name:`AES-GCM`,iv:n},e,r);return new Uint8Array(i)}async function CK(e,t,n,r){let i=await _K().decrypt({name:`AES-GCM`,iv:t,additionalData:r},e,n);return new Uint8Array(i)}async function wK(e,t){return JSON.parse(new TextDecoder().decode(await SK(e,t)))}async function TK(e,t){try{return await wK(e,t)===PK}catch{return!1}}function EK(e){let t=RK.exec(e.trim());return t?{auth:t[1],secret:t[2]??null}:{auth:e,secret:null}}function DK(e){return _K().importKey(`raw`,e,{name:`AES-GCM`,length:256},!1,[`encrypt`,`decrypt`])}function OK(e,t,n){return kK(e,t,n)}async function kK(e,t,n,r){let i=r??xK(),a=new Uint8Array(await _K().encrypt({name:`AES-GCM`,iv:i,additionalData:new TextEncoder().encode(n)},e,t));return{iv:vK(i),ct:vK(a)}}async function AK(e,t,n){return new Uint8Array(await _K().decrypt({name:`AES-GCM`,iv:yK(t.iv),additionalData:new TextEncoder().encode(n)},e,yK(t.ct)))}function jK(e,t,n){return MK(e,t,n)}async function MK(e,t,n,r,i){let a=vK(r??globalThis.crypto.getRandomValues(new Uint8Array(16))),o=await kK(await bK(e,a),t,n,i);return{kdf:{name:`PBKDF2`,hash:`SHA-256`,iterations:FK,salt:a},...o}}async function NK(e,t,n){let r=t?.kdf;if(r?.name!==`PBKDF2`||r.hash!==`SHA-256`||r.iterations!==FK||typeof r.salt!=`string`)throw Error(`unsupported_kdf`);return AK(await bK(e,r.salt),t,n)}var PK,FK,IK,LK,RK,zK,BK=c((()=>{PK=`kymoscope-live-key-check-v1`,FK=6e5,IK=null,LK=0,RK=/^((?:kymoscope|prism)_[A-Za-z0-9_-]+)(?:\.([A-Za-z0-9_-]+))?$/,new TextEncoder().encode(`kymoscope-device-wrap-v1`),new TextEncoder().encode(`kymoscope-sender-bind-v1`),zK=`kymoscope-workbook-export-v2`}));function VK(e){let t=new Uint8Array(e),n=t.length>0&&t[0]&128?2:1;return t.length<n+UK+WK?null:{kind:t[0]&-129,keyId:n===2?t[1]:null,iv:t.subarray(n,n+UK),ciphertext:t.subarray(n+UK),aad:t.subarray(0,n)}}async function HK(e,t){let n=VK(t);if(!n)return null;let r=typeof e==`function`?await e(n.keyId):e;if(!r)return null;let i=await CK(r,n.iv,n.ciphertext,n.aad);return{kind:n.kind,plaintext:i}}var UK,WK,GK=c((()=>{BK(),UK=12,WK=16})),KK,qK,JK,YK=c((()=>{KK=16,qK=class{t=new Float64Array(16);v=new Float64Array(16);start=0;end=0;get count(){return this.end-this.start}add(e,t){if(this.end===this.t.length){let e=this.count,t=e*2>this.t.length?this.t.length*2:this.t.length,n=new Float64Array(t),r=new Float64Array(t);n.set(this.t.subarray(this.start,this.end)),r.set(this.v.subarray(this.start,this.end)),this.t=n,this.v=r,this.start=0,this.end=e}this.t[this.end]=e,this.v[this.end++]=t}},JK=class{channels=new Map;events_=0;maxBytes;constructor(e){this.maxBytes=e}get bytes(){return this.events_*KK}add(e,t,n){let r=this.channels.get(e);r||this.channels.set(e,r=new qK),r.add(t,n),this.events_++,this.bytes>this.maxBytes&&this.evict()}events(e){let t=this.channels.get(e);return t?{t:t.t.subarray(t.start,t.end),v:t.v.subarray(t.start,t.end)}:{t:new Float64Array,v:new Float64Array}}evict(){let e=this.maxBytes*.9/KK;for(;this.events_>e;){let t=[...this.channels.values()].filter(e=>e.count>0).sort((e,t)=>t.count-e.count);if(!t.length)return;let n=t[0].count;for(let r of t){if(this.events_<=e||r.count*2<n)break;let t=Math.max(1,r.count>>1);r.start+=t,this.events_-=t}}}}}));function XK(e,t,n){let r=[];for(let t=0;t<e.length;t++)(t===0||e[t]!==e[t-1])&&r.push(e[t]);let i={},a=-1;for(let o=0;o<e.length;o++){(o===0||e[o]!==e[o-1])&&a++;let s=i[t[o]]??(i[t[o]]=new Float64Array(r.length).fill(NaN));s[a]=n[o]}return{t:Float64Array.from(r),columns:i}}var ZK,QK,$K,eq,tq,nq=c((()=>{YK(),ZK=1e3,QK=4,$K=4096,eq=class{buffer;store;schemas=new Map;known=new Map;active=new Set;constructor(e,t){this.buffer=e,this.store=new JK(t)}schema(e,t,n){this.schemas.delete(e),this.schemas.set(e,t),this.schemas.size>QK&&this.schemas.delete(this.schemas.keys().next().value),t.forEach((e,t)=>{this.known.has(e)||this.known.set(e,{unit:n[t]??``,t:NaN,v:NaN}),this.buffer.list(e,n[t]??``)})}last(e){for(let t of e)this.note(t.name,t.unit,t.t,t.v)}push(e,t,n,r){let i=this.schemas.get(e);return i?this.events(n.length,e=>i[t[e]],n,r):null}pushNamed(e,t,n){return this.events(e.length,e=>this.known.has(t[e])?t[e]:void 0,e,n)}events(e,t,n,r){let i=[];for(let a=0;a<e;a++){let e=t(a);e!==void 0&&(this.store.add(e,n[a],r[a]),this.note(e,this.known.get(e)?.unit??``,n[a],r[a]),this.active.has(e)&&i.push(a))}if(!i.length)return null;i.sort((e,t)=>n[e]-n[t]);let a=XK(i.map(e=>n[e]),i.map(e=>t(e)),i.map(e=>r[e]));return this.buffer.pushColumns(a),a}activate(e){let t=!1;for(let n of e){if(this.active.size>=1e3)break;this.known.has(n)&&!this.active.has(n)&&(this.active.add(n),t=!0)}return t}replay(){let e=this.buffer;e.clear();for(let[t,n]of this.known)e.list(t,n.unit,n.t,n.v);let t=[...this.active],n=t.map(e=>this.store.events(e)),r=n.map(e=>e.t.length-1),i=new tq(e=>-n[e].t[r[e]]);n.forEach((e,t)=>{e.t.length&&i.push(t)});let a=0,o=NaN;for(;i.size;){let t=i.top,s=n[t].t[r[t]];if(s!==o){if(a===e.maxSamples)break;a++,o=s}i.pop(),--r[t]>=0&&i.push(t)}let s=new tq(e=>n[e].t[r[e]]);n.forEach((e,t)=>{++r[t]<e.t.length&&s.push(t)});let c=new Float64Array($K),l={},u=-1,d=()=>{if(u<0)return;let t=u+1;e.pushColumns({t:c.subarray(0,t),columns:Object.fromEntries(Object.entries(l).map(([e,n])=>[e,n.subarray(0,t)]))}),c=new Float64Array($K),l={},u=-1};for(;s.size;){let e=s.top,i=n[e].t[r[e]];(u<0||i!==c[u])&&(u+1===$K&&d(),c[++u]=i),(l[t[e]]??=new Float64Array($K).fill(NaN))[u]=n[e].v[r[e]],s.pop(),++r[e]<n[e].t.length&&s.push(e)}d()}note(e,t,n,r){if(!Number.isFinite(n)||!Number.isFinite(r))return;let i=this.known.get(e);i?n<i.t||(i.t=n,i.v=r):this.known.set(e,{unit:t,t:n,v:r}),this.buffer.list(e,t,n,r)}},tq=class{h=[];key;constructor(e){this.key=e}get size(){return this.h.length}get top(){return this.h[0]}push(e){let t=this.h,n=this.key(e),r=t.push(e)-1;for(;r>0;){let e=r-1>>1;if(this.key(t[e])<=n)break;t[r]=t[e],r=e}t[r]=e}pop(){let e=this.h,t=e.pop();if(!e.length)return;let n=this.key(t),r=e.length,i=0;for(;;){let t=2*i+1;if(t>=r||(t+1<r&&this.key(e[t+1])<this.key(e[t])&&t++,this.key(e[t])>=n))break;e[i]=e[t],i=t}e[i]=t}}}));function rq(e){if(e.length!==oq||e[0]!==1)return null;let t=new DataView(e.buffer,e.byteOffset,e.byteLength);return{streamId:cq(e.subarray(1,17)),run:sq(e.subarray(17,25)),lane:e[25],seq:t.getBigUint64(26,!0),count:t.getUint32(34,!0),hash:e.slice(38,70)}}async function iq(e){let t=await Promise.all(e),n=new Uint8Array(t.length*32);return t.forEach((e,t)=>n.set(new Uint8Array(e),t*32)),new Uint8Array(await uq(n))}function aq(e,t,n=()=>Date.now()){let r={verified:0,broken:0},i=null,a=0n,o=null,s=0,c=0,l=0,u=Promise.resolve(),d=e=>{e?r.verified++:(r.broken++,r.lastBrokenAt=n()),t({...r})};return{integrity:r,reset(){i=null,o=null,c=s,l++},arrive(t,n,r){if(n!==8){o&&(o.push(uq(t)),s++);return}let f=s;o||(o=[],c=s);let p=l;u=u.then(async()=>{let t=await r.catch(()=>null);if(p!==l)return;let n=t?rq(t.plaintext):null;if(!n||n.lane!==0||n.streamId!==e.toLowerCase()){i!==null&&d(!1);return}let s=f-c;if(i===null||n.run!==i){i=n.run,a=n.seq,o=o.slice(Math.max(0,s)),c=Math.max(c,f);return}let u=n.seq===a+1n&&n.count<=s&&dq(await iq(o.slice(0,n.count)),n.hash);if(p!==l)return;a=n.seq;let m=u?n.count:s;o=o.slice(m),c+=m,d(u)})}}}var oq,sq,cq,lq,uq,dq,fq=c((()=>{GK(),oq=70,sq=e=>Array.from(e,e=>e.toString(16).padStart(2,`0`)).join(``),cq=e=>{let t=sq(e);return`${t.slice(0,8)}-${t.slice(8,12)}-${t.slice(12,16)}-${t.slice(16,20)}-${t.slice(20)}`},lq=()=>globalThis.crypto.subtle,uq=e=>lq().digest(`SHA-256`,e),dq=(e,t)=>e.length===t.length&&e.every((e,n)=>e===t[n])}));async function pq(e,t,n,r){let i=t[t.length-1];if(!i||(i.bytes[0]&127)!=8)return`unchecked`;let a=await n(i.bytes).catch(()=>null),o=a?rq(a.plaintext):null,s=gq(await hq(_q(e.recordingId))).slice(0,16);return o&&o.lane===1&&o.run===s&&o.seq===BigInt(e.seq)&&e.seq===r&&o.count===t.length-1&&gq((await iq(t.slice(0,-1).map(e=>hq(e.bytes)))).buffer)===gq(o.hash.buffer)?`verified`:`broken`}function mq(e){let t=[...e],n=new Set(t.filter(e=>e.check!==`unchecked`).map(e=>e.rid)),r={verified:0,broken:0,unchecked:0};for(let e of t)e.check===`unchecked`&&n.has(e.rid)?r.broken++:r[e.check]++;return r}var hq,gq,_q,vq=c((()=>{GK(),fq(),hq=e=>crypto.subtle.digest(`SHA-256`,e),gq=e=>Array.from(new Uint8Array(e),e=>e.toString(16).padStart(2,`0`)).join(``),_q=e=>Uint8Array.from(e.replace(/-/g,``).match(/../g)??[],e=>parseInt(e,16))}));function yq(e,t){let n=new TextDecoder(`utf-8`,{fatal:!0}),r=[],i=0;try{for(let a=0;a<t;a++){if(i+3>e.byteLength)throw zq(`block schema`,`short channel table`);let t=e[i],a=e[i+1],o=e[i+2];if(i+=3,t!==4&&t!==8)throw zq(`block schema`,`value size ${t}`);if(i+a+o>e.byteLength)throw zq(`block schema`,`short channel table`);r.push({name:n.decode(e.subarray(i,i+a)),unit:n.decode(e.subarray(i+a,i+a+o)),size:t}),i+=a+o}}catch(e){throw e instanceof RangeError?e:zq(`block schema`,`invalid text`)}return r}async function bq(e){if(e.byteLength<8)throw zq(`block schema`,`short`);let t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=t.getUint8(0);if(n===jq){if(e.byteLength<12)throw zq(`block schema`,`short`);let n=t.getUint32(4,!0);if(n>Fq)throw zq(`block schema`,`too many channels`);let r=t.getUint8(1)&kq?await wq(e.subarray(12),n*Iq,!1):e.subarray(12);return{id:t.getUint32(8,!0),channels:yq(r,n)}}if(n!==Dq)throw zq(`block schema`,`version ${n}`);return{id:t.getUint32(4,!0),channels:yq(e.subarray(8),t.getUint16(2,!0))}}function xq(e,t,n){let r=n.get(t.getUint32(4,!0));if(!r)return null;let i=t.getUint32(8,!0);if(i!==r.channels.length)throw zq(`last values`,`channel count differs from its schema`);if(e.byteLength<12+16*i)throw zq(`last values`,`short`);let a=[];for(let e=0;e<i;e++){let n=t.getFloat64(12+8*e,!0),o=t.getFloat64(12+8*(i+e),!0);Number.isFinite(n)&&Number.isFinite(o)&&a.push({name:r.channels[e].name,unit:r.channels[e].unit,t:n,v:o})}return a}async function Sq(e,t){if(e.byteLength<12)throw zq(`last values`,`short`);let n=new DataView(e.buffer,e.byteOffset,e.byteLength),r=n.getUint8(0);if(r===Oq)return xq(e,n,t);if(r!==Mq)throw zq(`last values`,`version ${r}`);if(e.byteLength<20)throw zq(`last values`,`short`);let i=n.getUint8(1),a=t.get(n.getUint32(4,!0));if(!a)return null;let o=n.getUint32(8,!0),s=n.getFloat64(12,!0),c=a.channels.length,l=(i&Pq)!==0;if(o>c||l&&o!==c)throw zq(`last values`,`entry count differs from its schema`);let u=(l?0:4*o)+4*o,d=i&kq?await wq(e.subarray(20),u+8*o,!1):e.subarray(20);if(d.byteLength<u)throw zq(`last values`,`short`);let f=new DataView(d.buffer,d.byteOffset,d.byteLength),p=[];for(let e=0;e<o;e++){let t=l?e:f.getUint32(4*e,!0);if(t>=c)throw zq(`last values`,`channel outside its schema`);p.push(t)}let m=l?0:4*o,h=p.filter(e=>a.channels[e].size===4),g=p.filter(e=>a.channels[e].size===8);if(d.byteLength!==u+4*h.length+8*g.length)throw zq(`last values`,`body size mismatch`);let _=Cq(d,u,h.length,4),v=Cq(d,u+4*h.length,g.length,8),y=new Map;h.forEach((e,t)=>y.set(e,_[t])),g.forEach((e,t)=>y.set(e,v[t]));let b=[];return p.forEach((e,t)=>{let n=s-f.getUint32(m+4*t,!0)/1e3,r=y.get(e);Number.isFinite(n)&&Number.isFinite(r)&&b.push({name:a.channels[e].name,unit:a.channels[e].unit,t:n,v:r})}),b}function Cq(e,t,n,r){let i=new Uint8Array(n*r);for(let a=0;a<r;a++)for(let o=0;o<n;o++)i[o*r+a]=e[t+a*n+o];return r===4?new Float32Array(i.buffer):new Float64Array(i.buffer)}async function wq(e,t,n=!0){let r=new Blob([e]).stream().pipeThrough(new DecompressionStream(`deflate`)).getReader(),i=new Uint8Array(Math.min(t,e.byteLength*4+1024)),a=0;try{for(;;){let{done:e,value:n}=await r.read();if(e)break;if(a+n.length>t)throw zq(`block`,`body larger than its header says`);if(a+n.length>i.length){let e=new Uint8Array(Math.min(t,Math.max(2*i.length,a+n.length)));e.set(i.subarray(0,a)),i=e}i.set(n,a),a+=n.length}}catch(e){throw await r.cancel().catch(()=>{}),e instanceof RangeError?e:zq(`block`,`body is not valid deflate`)}if(n&&a!==t)throw zq(`block`,`body size mismatch`);return i.length===a?i:i.subarray(0,a)}async function Tq(e,t){if(e.byteLength<Lq)throw zq(`block`,`short`);let n=new DataView(e.buffer,e.byteOffset,e.byteLength);if(n.getUint8(0)!==Dq)throw zq(`block`,`version ${n.getUint8(0)}`);let r=n.getUint8(1),i=n.getUint16(2,!0),a=n.getUint32(4,!0),o=n.getUint32(8,!0),s=t.get(o);if(!s)return null;if(s.channels.length!==i)throw zq(`block`,`channel count differs from its schema`);let c=n.getFloat64(12,!0),l=Math.max(0,a-1),u=4*l+s.channels.reduce((e,t)=>e+t.size*a,0);if(u>Rq)throw zq(`block`,`too large`);let d;if(r&kq)d=await wq(e.subarray(Lq),u);else if(d=e.subarray(Lq),d.byteLength<u)throw zq(`block`,`body size mismatch`);let f=new DataView(d.buffer,d.byteOffset,d.byteLength),p=new Float64Array(a),m=0;a&&(p[0]=c);for(let e=1;e<a;e++)m+=f.getInt32(4*(e-1),!0),p[e]=c+m/1e6;let h=4*l,g={},_={};for(let e of s.channels)g[e.name]=Cq(d,h,a,e.size),e.unit&&(_[e.name]=e.unit),h+=a*e.size;return{block:{t:p,columns:g,units:_},historical:(r&Aq)!==0,schemaId:o}}async function Eq(e,t){if(e.byteLength<Lq)throw zq(`sparse`,`short`);let n=new DataView(e.buffer,e.byteOffset,e.byteLength);if(n.getUint8(0)!==Nq)throw zq(`sparse`,`version ${n.getUint8(0)}`);let r=n.getUint8(1),i=n.getUint32(4,!0),a=t.get(i);if(!a)return null;let o=n.getUint32(8,!0),s=n.getFloat64(12,!0),c=4*o+4*Math.max(0,o-1);if(c+8*o>Rq)throw zq(`sparse`,`too large`);let l=r&kq?await wq(e.subarray(Lq),c+8*o,!1):e.subarray(Lq);if(l.byteLength<c)throw zq(`sparse`,`body size mismatch`);let u=new Uint32Array(o);for(let e=0;e<o;e++)u[e]=(l[e]|l[o+e]<<8|l[2*o+e]<<16|l[3*o+e]<<24)>>>0;let d=a.channels.length,f=0;for(let e=0;e<o;e++){if(u[e]>=d)throw zq(`sparse`,`event outside its schema`);a.channels[u[e]].size===4&&f++}if(l.byteLength!==c+4*f+8*(o-f))throw zq(`sparse`,`body size mismatch`);let p=new DataView(l.buffer,l.byteOffset,l.byteLength),m=new Float64Array(o),h=0;o&&(m[0]=s);for(let e=1;e<o;e++)h+=p.getInt32(4*o+4*(e-1),!0),m[e]=s+h/1e6;let g=Cq(l,c,f,4),_=Cq(l,c+4*f,o-f,8),v=new Float64Array(o);for(let e=0,t=0,n=0;e<o;e++)v[e]=a.channels[u[e]].size===4?g[t++]:_[n++];return{schemaId:i,index:u,t:m,v,historical:(r&Aq)!==0}}var Dq,Oq,kq,Aq,jq,Mq,Nq,Pq,Fq,Iq,Lq,Rq,zq,Bq=c((()=>{Dq=2,Oq=1,kq=1,Aq=2,jq=3,Mq=2,Nq=1,Pq=2,Fq=1e5,Iq=513,Lq=20,Rq=64*1024*1024,zq=(e,t)=>RangeError(`${e}: ${t}`)}));function Vq(e){let t=Array.from(e,e=>e.toString(16).padStart(2,`0`)).join(``);return`${t.slice(0,8)}-${t.slice(8,12)}-${t.slice(12,16)}-${t.slice(16,20)}-${t.slice(20)}`}function Hq(e){if(e.length<56||Wq.some((t,n)=>e[n]!==t))throw RangeError(`not a KRC1 chunk`);let t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=t.getUint16(4,!0);if(n!==1)throw RangeError(`KRC version ${n}`);let r=t.getUint16(6,!0);if(r<56)throw RangeError(`KRC header too short`);return{recordingId:Vq(e.subarray(8,24)),seq:t.getUint32(24,!0),count:t.getUint32(28,!0),bytes:t.getUint32(32,!0),headerBytes:r,t0:t.getFloat64(40,!0),t1:t.getFloat64(48,!0)}}function Uq(e){let t=Hq(e),n=new DataView(e.buffer,e.byteOffset,e.byteLength),r=Math.min(e.length,t.bytes),i=[],a=t.headerBytes;for(;i.length<t.count&&a+12<=r;){let t=n.getUint32(a+8,!0);if(a+12+t>r)break;i.push({at:n.getFloat64(a,!0),bytes:e.subarray(a+12,a+12+t)}),a+=12+t}return{header:t,messages:i,truncated:i.length<t.count}}var Wq,Gq=c((()=>{Wq=[75,82,67,49]}));function Kq(e){let t=new Map;return async n=>{if(n.length===0)return null;let r=n[0]&128?2:1;if(n.length<r+qq+Jq)return null;let i=r===2?n[1]:null,a=t.get(i),o=[...a?[a]:[],...e.filter(e=>(e.keyId===i||e.keyId===null)&&e.key!==a).map(e=>e.key)];for(let e of o)try{let a=await CK(e,n.subarray(r,r+qq),n.subarray(r+qq),n.subarray(0,r));return t.set(i,e),{kind:n[0]&-129,plaintext:a}}catch{}return null}}var qq,Jq,Yq=c((()=>{BK(),GK(),qq=12,Jq=16}));async function*Xq(e){let t=0;for(;t+56<=e.size;){let n=Hq(await e.read(t,56));if(yield await e.slice(t,n.bytes),n.bytes<=56)return;t+=n.bytes}}function Zq(e){let t=e.filter(e=>e&&typeof e.t==`number`&&Array.isArray(e.signals)),n={},r={};return t.forEach((e,i)=>{for(let a of e.signals){if(!a||typeof a.name!=`string`)continue;let e=n[a.name]??=new Float64Array(t.length).fill(NaN);e[i]=typeof a.value==`number`?a.value:NaN,a.unit&&!r[a.name]&&(r[a.name]=a.unit)}}),{t:t.map(e=>e.t),columns:n,units:r}}function Qq(e){let t=2166136261^e.length;for(let n=0,r=Math.min(e.length,64);n<r;n++)t=Math.imul(t^e[n],16777619);return t>>>0}async function*$q(e,t,n,r,i=!1){let a=Kq(e.keys??[]),o=new Map,s=new Map,c=r?null:new aJ,l=null,u=0,d=e=>c?(c.sampled(e),e.t.length&&(l=+e.t[e.t.length-1],u=e.at),c.start(e)):e,f={results:[]};for await(let e of Xq(t)){let{header:t,messages:l}=Uq(e);if(n.t0??=t.t0,i){let e=t.recordingId;f.results.push({rid:e,check:await pq(t,l,a,f.rid===e?(f.seq??-1)+1:0)}),f.rid=e,f.seq=t.seq,n.chain=mq(f.results)}for(let e of l){let t=Qq(e.bytes),i=s.get(t);if(i&&iJ(i,e.bytes))continue;s.set(t,e.bytes),s.size>rJ&&s.delete(s.keys().next().value);let l=await a(e.bytes);if(!l){n.lost++;continue}try{if(l.kind===5){let e=await bq(l.plaintext);o.set(e.id,e);continue}if(l.kind===4||l.kind===9){let t;if(l.kind===4){let r=await Tq(l.plaintext,o);if(!r){n.lost++;continue}t={at:e.at,t:r.block.t,columns:r.block.columns,units:r.block.units??{},historical:r.historical,schema:o.get(r.schemaId)}}else{let r=await Eq(l.plaintext,o);if(!r){n.lost++;continue}t={at:e.at,t:r.t,columns:{},units:{},historical:r.historical,events:{index:r.index,v:r.v},schema:o.get(r.schemaId)}}t.historical&&c?.sampled(t),(r===void 0||r===!!t.historical)&&(yield t.historical?t:d(t));continue}if(r)continue;if(l.kind===7){let e=await Sq(l.plaintext,o);e&&c?.note(e)}else if(l.kind===3){let t=LG(l.plaintext);yield d({at:e.at,t:t.t,columns:t.columns,units:t.units??{}})}else if(l.kind===2){let t=PG(l.plaintext);yield d({at:e.at,...Zq(Array.isArray(t?.frames)?t.frames:[])})}}catch{n.lost++}}}let p=c?.end(l,u);p&&(yield p)}function eJ(e,t,n){let r=e===null?t:t===null?e:Math.min(e,t);return r===null?{}:r>1e9?{wallOrigin:String(r),wallQuality:`exact`}:Number.isFinite(n)?{wallOrigin:String(r+n),wallQuality:`approx`}:{}}async function*tJ(e,t,n,r){let i=0,a=-1/0,o=0,s=n?$q(e,t,{lost:0,t0:null},!0):null,c=async()=>{for(let e=await s?.next();e&&!e.done;e=await s.next())if(e.value.t.length)return e.value;return null},l=await c();for await(let s of $q(e,t,{lost:0,t0:null},n?!1:void 0)){if(r?.aborted)return;let e=s.t.length;if(e!==0){for(+s.t[0]+i<a&&(i=a+Math.max(0,(s.at-o)/1e3)-+s.t[0]),o=s.at;l&&+l.t[0]<+s.t[0];l=await c())yield{b:l,shift:i};yield{b:s,shift:i},a=+s.t[e-1]+i}}for(;l&&!r?.aborted;l=await c())yield{b:l,shift:i}}var nJ,rJ,iJ,aJ,oJ,sJ=c((()=>{IG(),BG(),gK(),GK(),nq(),vq(),Bq(),Gq(),Yq(),nJ=8192,rJ=4096,iJ=(e,t)=>e.length===t.length&&e.every((e,n)=>e===t[n]),aJ=class{known=new Map;real=new Set;pending=new Set;held=new Set;note(e){for(let t of e){let e=this.known.get(t.name);(!e||t.t>=e.t)&&this.known.set(t.name,{t:t.t,v:t.v,unit:t.unit}),!this.real.has(t.name)&&!this.held.has(t.name)&&this.pending.add(t.name)}}sampled(e){if(this.pending.size+this.held.size===0)return;let t=e=>{(this.pending.delete(e)||this.held.delete(e))&&this.real.add(e)};for(let[n,r]of Object.entries(e.columns))if(!(!this.pending.has(n)&&!this.held.has(n))){for(let e=0;e<r.length;e++)if(Number.isFinite(r[e])){t(n);break}}if(e.events&&e.schema){let{index:n,v:r}=e.events;for(let i=0;i<r.length;i++)Number.isFinite(r[i])&&t(e.schema.channels[n[i]].name)}}start(e){if(this.pending.size===0||e.t.length===0)return e;let t={...e.columns},n={...e.units};for(let e of this.pending){let r=this.known.get(e);t[e]=Float64Array.of(r.v),r.unit&&!n[e]&&(n[e]=r.unit),this.held.add(e)}let r=[...this.pending];return this.pending.clear(),{...e,columns:t,units:n,more:r}}end(e,t){if(e===null||this.held.size===0)return null;let n={},r={};for(let e of this.held){let t=this.known.get(e);n[e]=Float64Array.of(t.v),t.unit&&(r[e]=t.unit)}return{at:t,t:[e],columns:n,units:r}}},oJ={id:`krc`,label:`Kymoscope recording`,extensions:[],sniff:()=>!1,async plan(e,t){let n=[dK],r=new Map([[dK,`s`]]),i={lost:0,t0:null},a=0,o=!1,s=null,c=null,l=0,u=-1/0,d=0,f=1/0,p=(e,t=``)=>{e!==`ElapsedTime`&&(r.has(e)?!r.get(e)&&t&&r.set(e,t):(n.push(e),r.set(e,t)))},m=new Set;for await(let n of $q(e,t,i,void 0,!0)){a+=n.t.length,n.historical&&(o=!0);let e=n.t.length;if(e&&n.historical?c??=+n.t[0]:e&&(s??=+n.t[0],+n.t[0]+l<u&&(l=u+Math.max(0,(n.at-d)/1e3)-+n.t[0]),d=n.at,u=+n.t[e-1]+l,f=Math.min(f,n.at/1e3-u)),n.schema){if(!m.has(n.schema.id)){m.add(n.schema.id);for(let e of n.schema.channels)p(e.name,e.unit)}for(let e of n.more??[])p(e,n.units[e])}else for(let e of Object.keys(n.columns))p(e,n.units[e])}let h=n.map(e=>({name:e,unit:r.get(e)??``})),g=i.lost?[`${i.lost} ${i.lost===1?`message`:`messages`} couldn't be opened with the keys this browser has.`]:[],_=i.chain?.broken??0,v=n.length-1,y=v>1e3?[{group:0,channels:n.slice(0,ZK+1).map((e,t)=>t)}]:void 0;return y&&g.push(`This recording has ${v.toLocaleString(`en-US`)} channels; the first ${ZK.toLocaleString(`en-US`)} are loaded.`),_&&g.push(`Some of this recording was missing, out of order or changed where it is stored (${_} of ${_+(i.chain?.verified??0)} checked ${_+(i.chain?.verified??0)===1?`chunk`:`chunks`}).`),{format:`Kymoscope recording`,startTime:i.t0===null?null:new Date(i.t0).toISOString(),groups:[{name:`Recording`,channels:h,samples:a,time:{kind:`timestamps`},rateHz:null}],meta:{...eJ(s,c,f),...i.chain&&(i.chain.verified||i.chain.broken)?{chainVerified:String(i.chain.verified),chainBroken:String(i.chain.broken),chainUnchecked:String(i.chain.unchecked)}:{}},events:[],notes:g,defaultSelection:y,state:{names:n,backlog:o}}},async*stream(e){let{names:t,backlog:n=!1}=e.plan.state,r=e.selection.find(e=>e.group===0)?.channels??[],i=new Map(r.map((e,n)=>[t[e],n])),a=i.get(dK),o=()=>r.map(()=>new Float64Array(nJ).fill(NaN)),s=new Float64Array(nJ),c=o(),l=0,u=0,d=0,f=null,p=()=>{let e={group:0,time:s.slice(0,l),start:u,length:l,columns:c.map(e=>e.slice(0,l))};return u+=l,l=0,s=new Float64Array(nJ),c=o(),e},m=new WeakMap,h=e=>{let t=m.get(e);return t||m.set(e,t=Int32Array.from(e.channels,e=>e.name===`ElapsedTime`?-2:i.get(e.name)??-1)),t};function*g(e,t,n,r){let o=Object.entries(e.columns).flatMap(([e,t])=>{let n=e===`ElapsedTime`?void 0:i.get(e);return n===void 0?[]:[[n,+t[0]]]});for(let i=0;i<e.t.length;i++){let u=r[t[i]];if(u===-1&&!(i===0&&o.length))continue;let m=+e.t[i];if(s[l]=m+d-f,a!==void 0&&(c[a][l]=m),u>=0&&(c[u][l]=n[i]),i===0)for(let[e,t]of o)c[e][l]=t;++l===nJ&&(yield p())}}function*_(e){let t=e.t.length;if(t&&(f??=+e.t[0]+d),e.events&&e.schema)return yield*g(e,e.events.index,e.events.v,h(e.schema));for(let n=0;n<t;){let r=Math.min(t-n,nJ-l);for(let t=0;t<r;t++)s[l+t]=+e.t[n+t]+d-f;if(a!==void 0)for(let t=0;t<r;t++)c[a][l+t]=+e.t[n+t];for(let[t,a]of Object.entries(e.columns)){let e=t===`ElapsedTime`?void 0:i.get(t);if(e===void 0)continue;let o=c[e];if(a instanceof Float64Array||a instanceof Float32Array)o.set(a.subarray(n,n+r),l);else for(let e=0;e<r;e++)o[l+e]=+a[n+e]}l+=r,n+=r,l===nJ&&(yield p())}}for await(let t of tJ(e.files,e.io,n,e.signal))d=t.shift,yield*_(t.b);l>0&&(yield p())}}})),cJ=u({IMPORTERS:()=>uJ,importerFor:()=>lJ});function lJ(e){let t=uJ[e];if(!t)throw Error(`No importer for format ${e}.`);return t}var uJ,dJ=c((()=>{MH(),RH(),QH(),wU(),tW(),AW(),BW(),sJ(),uJ={mdf:jH,edf:LH,xdf:ZH,tdms:CU,hdf5:eW,mat:kW,comtrade:zW,krc:oJ}}));qz(),gz();var fJ=()=>new SE(`cancelled`);function pJ(){let e=CE(Jz);return e.postMessage({type:`init`,h5Url:new URL(Yz,location.href).href}),e}var mJ=null,hJ=e=>{typeof requestIdleCallback==`function`?requestIdleCallback(e,{timeout:5e3}):setTimeout(e,1e3)};function gJ(e,t=pJ){t===pJ&&typeof Worker>`u`||(mJ&&mJ.make!==t&&(mJ.w.terminate(),mJ=null),mJ??={w:t(),h5:!1,make:t},e&&!mJ.h5&&(mJ.h5=!0,mJ.w.postMessage({type:`warm`})))}function _J(e){if(mJ?.make!==e)return{w:e(),rewarm:null};let{w:t,h5:n}=mJ;return mJ=null,{w:t,rewarm:n}}function vJ(e,t,n,r,i){return!r&&typeof Worker>`u`?yJ(e,t,n,i):xJ(e,t,n,r??pJ)}function yJ(e,t,n,r=async e=>(await Promise.resolve().then(()=>(dJ(),cJ))).importerFor(e)){let i=new Kz(t.main),a=null,o=null,s=e=>e.catch(e=>{throw n?.aborted?fJ():oz(e)});return{plan:()=>s((async()=>(a=await r(e),o=await Lz(a,t,i)))()),read:(e,r,c={})=>(i.bytesRead=0,s(Hz(a,t,o,i,e,r,{...c,signal:n}))),close(){}}}var bJ=3e4;function xJ(e,t,n,r){let{w:i,rewarm:a}=_J(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>bJ&&p(Error(sz))},1e3),h=()=>p(fJ());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(fJ());return}if(d){a(Error(sz));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&&hJ(()=>gJ(a,r))}}}Qe();var SJ=12e3,CJ=(e,t)=>t.map(t=>({group:t,channels:e.groups[t].channels.map((e,t)=>t)}));function wJ(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 TJ(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:wJ(e,n)}:null,splitKey:r,channels:n.reduce((e,t)=>e+t.channels.length,0),notes:e.notes,meta:e.meta,events:[]}}async function EJ(e,t,n,r,i,a){let o={meta:``,columnNames:n.columns.map(e=>e.name),units:n.columns.map(e=>e.unit),rows:qe(n.table)},s=new VE(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 DJ(e,t,n,r,i,a,o,s,c){let l=BL().then(e=>e.connect());l.catch(()=>void 0);let u=nR(),d=zz(r,i),f=new iz({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 cR.attach(p,u,new Map(d.map(e=>[e.name,e.unit]))),h=await m.getSchema(),g=await m.sampleRows(SJ);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 ${VL(u)}`).catch(()=>void 0),await t?.close().catch(()=>void 0),e}}async function OJ(e,t){let{main:n,companions:r}=e,i=vJ(e.format,{main:n,companions:r,keys:e.keys},t.signal,t.createWorker,t.find),a=[];try{t.priorInMemoryValues+n.size/8>1e8&&BL().catch(()=>void 0);let o=await i.plan(),s=t.selection??t.initial??o.defaultSelection??CJ(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=>Vz(o,e,n.size),budget:lR,used:t.priorInMemoryValues,notes:o.notes});if(!e)throw new SE(`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=Vz(o,s,n.size),f=l.length>1?`${n.name} · ${o.groups[s[0].group].name}`:n.name,p=TJ(o,e.format,s,u),m=crypto.randomUUID();if(dR(0,c,d)===`memory`){let e=await i.read(s,`memory`,{progress:t.onProgress});a.push(await EJ(m,f,e,n,r,p)),d+=c}else a.push(await DJ(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 SE(`cancelled`):e}finally{i.close()}}function kJ(e){return e.filter(e=>e.type===`number`).map(e=>e.name)}function AJ(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 jJ(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 MJ(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 NJ(e){return Math.max(2,Math.min(6,Math.floor(e/64)))}function PJ(e,t,n,r){let i=Math.max(e,t)-Math.min(e,t),a=n!==void 0&&n>0&&Number.isFinite(n)?n:MJ(i,6);(a<=0||!Number.isFinite(a))&&(a=MJ(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 FJ(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 IJ(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 LJ={[-12]:`p`,[-9]:`n`,[-6]:`µ`,[-3]:`m`,0:``,3:`k`,6:`M`,9:`G`,12:`T`};function RJ(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 zJ(e,t){if(!Number.isFinite(e))return`—`;if(!(t>0)||!Number.isFinite(t))return BJ(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(RJ(t/10**r))+LJ[r]}return e.toFixed(RJ(t))}function BJ(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)+LJ[n]}var VJ=946684800,HJ=4102444800;function UJ(e,t,n){return/\(([^)]*)\)\s*$/.exec(e)?.[1].trim()===`s`&&n>t&&t>=VJ&&n<=HJ}var WJ=new Map;function GJ(e){let t=WJ.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=GJ(void 0)}WJ.set(e,t)}return t}var KJ=new Map,qJ=(e,t)=>{let n=Math.round(e*1e3),r=Math.floor(n/1e3),i=`${t??``}|${r}`,a=KJ.get(i);if(!a){let e={};for(let{type:n,value:i}of GJ(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}`},KJ.size>=1024&&KJ.clear(),KJ.set(i,a)}return{...a,ms:String(n-r*1e3).padStart(3,`0`)}},JJ,YJ=new Set,XJ=()=>JJ;function ZJ(e){return YJ.add(e),()=>{YJ.delete(e)}}function QJ(e,t,n,r=JJ){let i=qJ(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 $J(e,t=JJ){let n=qJ(e,t);return`${n.date} ${n.year} ${n.hms}.${n.ms}`}var eY=[`#fb923c`,`#60a5fa`,`#4ade80`,`#f87171`,`#facc15`,`#22d3ee`,`#f472b6`,`#2dd4bf`,`#94a3b8`,`#a3e635`];function tY(e,t,n,r=eY){let i=r.length>0?r:eY;return e[t]??i[n%i.length]}function nY(e){return[e===`light`?`#000000`:`#ffffff`,...eY.slice(0,9)]}function rY(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:nY(t)}var iY=[`class`,`data-theme`,`data-color-scheme`];function aY(e){return e?.closest(`[data-color-scheme]`)??document.documentElement}function oY(e){return aY(e).getAttribute(`data-color-scheme`)===`light`?`light`:`dark`}function sY(e,t){let n=new MutationObserver(t),r=new Set([document.documentElement,aY(e)]);for(let e of r)n.observe(e,{attributes:!0,attributeFilter:iY});return()=>n.disconnect()}var cY=[{value:`span`,label:`Span (max − min)`},{value:`mean`,label:`Mean`},{value:`max`,label:`Max`},{value:`min`,label:`Min`}];function lY(e,t){let n=[],r=Ew(),i=-1;for(let a=0;a<e.length;a++){let o=e[a][t];if(typeof o!=`number`)continue;let s=Dw(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 uY(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 dY(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 fY(e,t){return t.trim()===`s`||/time/i.test(e)}function pY(e,t){return`${e}::lap${t}`}BK();var mY=(e,t,n)=>`kymoscope-workbook-export|3|${e}|${t??``}|${n??``}`,hY=e=>new TextEncoder().encode(e);async function gY(e,t){return{format:`kymoscope-workbook`,v:2,...await jK(t,hY(JSON.stringify(e)),zK)}}async function _Y(e,t){let n=t.password?JSON.stringify(await gY(e,t.password)):JSON.stringify(e),r=await OK(await DK(t.key),hY(n),mY(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 vY(e){return!!e&&typeof e==`object`&&e.format===`kymoscope-workbook`}function yY(e){return vY(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 bY=e=>{try{return JSON.parse(new TextDecoder().decode(e))}catch{throw new SE(`bad_file`)}};async function xY(e,t){let n=yY(e);if(!n)throw new SE(`bad_file`);let r=e;if(n.v===3){let i=e;if(!t.key)throw new SE(`scope_key_required`,{scope:n.scope,scopeId:n.scopeId});let a;try{a=await AK(await DK(t.key),i,mY(i.scope,i.scope_id,i.inner))}catch{throw new SE(`bad_file`)}if(r=bY(a),!n.password)return r;if(r?.v!==2||!vY(r))throw new SE(`bad_file`)}if(!t.password)throw new SE(`password_required`);let i;try{i=await NK(t.password,r,zK)}catch{throw new SE(`wrong_password`)}return bY(i)}var SY=new Set(Object.keys(T));function CY(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`||!SY.has(n)||!r||![r.x,r.y,r.w,r.h].every(e=>typeof e==`number`&&Number.isFinite(e))?[]:[{...e,rect:D(n,r,96)}]}):[]}var wY=e=>({name:e.name,xKey:e.xKey,panels:e.panels,panelChartSettings:e.panelChartSettings,panelChartBackgrounds:e.panelChartBackgrounds,...e.liveWindowSeconds===void 0?{}:{liveWindowSeconds:e.liveWindowSeconds}});function TY(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 EY(e){return{version:2,worksheets:e.worksheets.map(e=>({...wY(e),panelChartSettings:TY(e.panelChartSettings)})),activeWorksheet:Math.max(0,e.worksheets.findIndex(t=>t.id===e.activeWorksheetId)),mathChannels:e.channels.map(e=>({name:e.name,formula:e.formula,units:e.units,enabled:e.enabled,...e.description?{description:e.description}:{}})),liveWindowSeconds:e.liveWindowSeconds,laps:e.laps?{channel:e.laps.channel,metric:e.laps.metric,stat:e.laps.stat}:null,...e.cycles?.length?{cycles:e.cycles}:{}}}function DY(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 OY(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 kY(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 AY(e){let t=await kY(e),n;try{n=JSON.parse(t)}catch{return{worksheets:[],errors:[`Not a valid JSON file.`]}}return IY(n)}var jY=new Set(cY.map(e=>e.value)),MY=/^(#(?:[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 NY(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):MY.test(e.trim())}function PY(e){if(Array.isArray(e))return e.map(PY);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`&&!NY(r)||(t[n]=r&&typeof r==`object`?PY(r):r);return t}function FY(e){return!e||typeof e!=`object`?{}:Object.fromEntries(Object.entries(e).filter(([,e])=>e===null||NY(e)))}function IY(e){let t=e,n=t&&typeof t==`object`?t.version:void 0;if(!t||n!==1&&n!==2||!Array.isArray(t.worksheets))return{worksheets:[],errors:[`Unrecognized format. Is this a Kymoscope workbook file?`],activeIndex:0,mathChannels:[],liveWindowSeconds:void 0,laps:void 0,cycles:[]};let r=[],i=[];if(t.worksheets.forEach((e,t)=>{let n=e;if(typeof n?.name!=`string`||typeof n.xKey!=`string`){i.push(`Worksheet #${t+1} skipped: missing name or xKey.`);return}r.push({id:crypto.randomUUID(),name:n.name,xKey:n.xKey,panels:CY(n.panels),panelChartSettings:PY(n.panelChartSettings),panelChartBackgrounds:FY(n.panelChartBackgrounds),...He(n.liveWindowSeconds)})}),n===1)return{worksheets:r,errors:i,activeIndex:0,mathChannels:[],liveWindowSeconds:void 0,laps:void 0,cycles:[]};let a=(Array.isArray(t.mathChannels)?t.mathChannels:[]).flatMap(e=>{let t=e;return typeof t?.name!=`string`||!t.name.trim()||typeof t.formula!=`string`?[]:[{name:t.name,formula:t.formula,units:typeof t.units==`string`?t.units:``,enabled:t.enabled!==!1,...typeof t.description==`string`&&t.description?{description:t.description}:{}}]}),o=t.liveWindowSeconds,s=t.laps,c=s&&typeof s.channel==`string`&&typeof s.metric==`string`&&jY.has(s.stat)?{channel:s.channel,metric:s.metric,stat:s.stat}:null,l=typeof t.activeWorksheet==`number`&&Number.isInteger(t.activeWorksheet)?t.activeWorksheet:0;return{worksheets:r,errors:i,mathChannels:a,laps:c,cycles:Gw(t.cycles),activeIndex:Math.min(Math.max(0,l),Math.max(0,r.length-1)),liveWindowSeconds:o===null||typeof o==`number`&&o>0?o:void 0}}function LY(e){return e.some(e=>e.panels.length>0)}function RY(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:CY(t.panels),panelChartSettings:PY(t.panelChartSettings),panelChartBackgrounds:FY(t.panelChartBackgrounds),...He(t.liveWindowSeconds)}}function zY(e){if(!e||typeof e!=`object`)return null;let t=e,n=t.kind;if(typeof n!=`string`||!SY.has(n))return null;let r=Be({__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 BY(e){let t=await kY(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=yY(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=RY(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=zY(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 AY(e);return i.worksheets.length===0&&i.errors.length>0?{type:`error`,errors:i.errors}:{type:`workspace`,worksheets:i.worksheets,errors:i.errors}}var VY=tz;function HY(e){let t=e.toLowerCase();return!t.startsWith(`.`)&&VY.some(e=>t.endsWith(e))}function UY(e,t=``){let n={name:t,path:``,dirs:[],files:[],allPaths:[]};for(let t of e){if(!HY(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 WY(e){return e.map(e=>({path:e.webkitRelativePath||e.name,file:e}))}async function GY(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 KY(){return typeof window.showDirectoryPicker==`function`}async function qY(){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 JY={1:`dohstRIUBeOkkAXOTXhhEkXanWzz-V4M518JBqTehRM`};function YY(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 XY(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 ZY(e){try{let t=JSON.parse(new TextDecoder().decode(YY(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 QY(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=ZY(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`,YY(s),`Ed25519`,!1,[`verify`]);c=await crypto.subtle.verify(`Ed25519`,e,YY(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=>XY(e,t))?{ok:!0,sub:a.sub,exp:a.exp}:{ok:!1,reason:`domain`}:{ok:!1,reason:`bad_signature`}}function $Y(e,t){return QY(e,t,JY,Date.now()/1e3)}var X={sans:`system-ui, sans-serif`,mono:`ui-monospace, monospace`};function eX(e){let t=e.getTransform().a||1;e.font=`13px ${X.sans}`,e.textAlign=`center`,e.textBaseline=`middle`,e.fillText(`No data to plot`,e.canvas.width/t/2,e.canvas.height/t/2)}var tX=l((e=>{var t=Symbol.for(`react.transitional.element`),n=Symbol.for(`react.portal`),r=Symbol.for(`react.fragment`),i=Symbol.for(`react.strict_mode`),a=Symbol.for(`react.profiler`),o=Symbol.for(`react.consumer`),s=Symbol.for(`react.context`),c=Symbol.for(`react.forward_ref`),l=Symbol.for(`react.suspense`),u=Symbol.for(`react.memo`),d=Symbol.for(`react.lazy`),f=Symbol.for(`react.activity`),p=Symbol.iterator;function m(e){return typeof e!=`object`||!e?null:(e=p&&e[p]||e[`@@iterator`],typeof e==`function`?e:null)}var h={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},g=Object.assign,_={};function v(e,t,n){this.props=e,this.context=t,this.refs=_,this.updater=n||h}v.prototype.isReactComponent={},v.prototype.setState=function(e,t){if(typeof e!=`object`&&typeof e!=`function`&&e!=null)throw Error(`takes an object of state variables to update or a function which returns an object of state variables.`);this.updater.enqueueSetState(this,e,t,`setState`)},v.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,`forceUpdate`)};function y(){}y.prototype=v.prototype;function b(e,t,n){this.props=e,this.context=t,this.refs=_,this.updater=n||h}var x=b.prototype=new y;x.constructor=b,g(x,v.prototype),x.isPureReactComponent=!0;var S=Array.isArray;function C(){}var w={H:null,A:null,T:null,S:null},T=Object.prototype.hasOwnProperty;function E(e,n,r){var i=r.ref;return{$$typeof:t,type:e,key:n,ref:i===void 0?null:i,props:r}}function D(e,t){return E(e.type,t,e.props)}function O(e){return typeof e==`object`&&!!e&&e.$$typeof===t}function k(e){var t={"=":`=0`,":":`=2`};return`$`+e.replace(/[=:]/g,function(e){return t[e]})}var A=/\/+/g;function j(e,t){return typeof e==`object`&&e&&e.key!=null?k(``+e.key):t.toString(36)}function M(e){switch(e.status){case`fulfilled`:return e.value;case`rejected`:throw e.reason;default:switch(typeof e.status==`string`?e.then(C,C):(e.status=`pending`,e.then(function(t){e.status===`pending`&&(e.status=`fulfilled`,e.value=t)},function(t){e.status===`pending`&&(e.status=`rejected`,e.reason=t)})),e.status){case`fulfilled`:return e.value;case`rejected`:throw e.reason}}throw e}function N(e,r,i,a,o){var s=typeof e;(s===`undefined`||s===`boolean`)&&(e=null);var c=!1;if(e===null)c=!0;else switch(s){case`bigint`:case`string`:case`number`:c=!0;break;case`object`:switch(e.$$typeof){case t:case n:c=!0;break;case d:return c=e._init,N(c(e._payload),r,i,a,o)}}if(c)return o=o(e),c=a===``?`.`+j(e,0):a,S(o)?(i=``,c!=null&&(i=c.replace(A,`$&/`)+`/`),N(o,r,i,``,function(e){return e})):o!=null&&(O(o)&&(o=D(o,i+(o.key==null||e&&e.key===o.key?``:(``+o.key).replace(A,`$&/`)+`/`)+c)),r.push(o)),1;c=0;var l=a===``?`.`:a+`:`;if(S(e))for(var u=0;u<e.length;u++)a=e[u],s=l+j(a,u),c+=N(a,r,i,s,o);else if(u=m(e),typeof u==`function`)for(e=u.call(e),u=0;!(a=e.next()).done;)a=a.value,s=l+j(a,u++),c+=N(a,r,i,s,o);else if(s===`object`){if(typeof e.then==`function`)return N(M(e),r,i,a,o);throw r=String(e),Error(`Objects are not valid as a React child (found: `+(r===`[object Object]`?`object with keys {`+Object.keys(e).join(`, `)+`}`:r)+`). If you meant to render a collection of children, use an array instead.`)}return c}function P(e,t,n){if(e==null)return e;var r=[],i=0;return N(e,r,``,``,function(e){return t.call(n,e,i++)}),r}function F(e){if(e._status===-1){var t=e._result;t=t(),t.then(function(t){(e._status===0||e._status===-1)&&(e._status=1,e._result=t)},function(t){(e._status===0||e._status===-1)&&(e._status=2,e._result=t)}),e._status===-1&&(e._status=0,e._result=t)}if(e._status===1)return e._result.default;throw e._result}var I=typeof reportError==`function`?reportError:function(e){if(typeof window==`object`&&typeof window.ErrorEvent==`function`){var t=new window.ErrorEvent(`error`,{bubbles:!0,cancelable:!0,message:typeof e==`object`&&e&&typeof e.message==`string`?String(e.message):String(e),error:e});if(!window.dispatchEvent(t))return}else if(typeof process==`object`&&typeof process.emit==`function`){process.emit(`uncaughtException`,e);return}console.error(e)},L={map:P,forEach:function(e,t,n){P(e,function(){t.apply(this,arguments)},n)},count:function(e){var t=0;return P(e,function(){t++}),t},toArray:function(e){return P(e,function(e){return e})||[]},only:function(e){if(!O(e))throw Error(`React.Children.only expected to receive a single React element child.`);return e}};e.Activity=f,e.Children=L,e.Component=v,e.Fragment=r,e.Profiler=a,e.PureComponent=b,e.StrictMode=i,e.Suspense=l,e.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=w,e.__COMPILER_RUNTIME={__proto__:null,c:function(e){return w.H.useMemoCache(e)}},e.cache=function(e){return function(){return e.apply(null,arguments)}},e.cacheSignal=function(){return null},e.cloneElement=function(e,t,n){if(e==null)throw Error(`The argument must be a React element, but you passed `+e+`.`);var r=g({},e.props),i=e.key;if(t!=null)for(a in t.key!==void 0&&(i=``+t.key),t)!T.call(t,a)||a===`key`||a===`__self`||a===`__source`||a===`ref`&&t.ref===void 0||(r[a]=t[a]);var a=arguments.length-2;if(a===1)r.children=n;else if(1<a){for(var o=Array(a),s=0;s<a;s++)o[s]=arguments[s+2];r.children=o}return E(e.type,i,r)},e.createContext=function(e){return e={$$typeof:s,_currentValue:e,_currentValue2:e,_threadCount:0,Provider:null,Consumer:null},e.Provider=e,e.Consumer={$$typeof:o,_context:e},e},e.createElement=function(e,t,n){var r,i={},a=null;if(t!=null)for(r in t.key!==void 0&&(a=``+t.key),t)T.call(t,r)&&r!==`key`&&r!==`__self`&&r!==`__source`&&(i[r]=t[r]);var o=arguments.length-2;if(o===1)i.children=n;else if(1<o){for(var s=Array(o),c=0;c<o;c++)s[c]=arguments[c+2];i.children=s}if(e&&e.defaultProps)for(r in o=e.defaultProps,o)i[r]===void 0&&(i[r]=o[r]);return E(e,a,i)},e.createRef=function(){return{current:null}},e.forwardRef=function(e){return{$$typeof:c,render:e}},e.isValidElement=O,e.lazy=function(e){return{$$typeof:d,_payload:{_status:-1,_result:e},_init:F}},e.memo=function(e,t){return{$$typeof:u,type:e,compare:t===void 0?null:t}},e.startTransition=function(e){var t=w.T,n={};w.T=n;try{var r=e(),i=w.S;i!==null&&i(n,r),typeof r==`object`&&r&&typeof r.then==`function`&&r.then(C,I)}catch(e){I(e)}finally{t!==null&&n.types!==null&&(t.types=n.types),w.T=t}},e.unstable_useCacheRefresh=function(){return w.H.useCacheRefresh()},e.use=function(e){return w.H.use(e)},e.useActionState=function(e,t,n){return w.H.useActionState(e,t,n)},e.useCallback=function(e,t){return w.H.useCallback(e,t)},e.useContext=function(e){return w.H.useContext(e)},e.useDebugValue=function(){},e.useDeferredValue=function(e,t){return w.H.useDeferredValue(e,t)},e.useEffect=function(e,t){return w.H.useEffect(e,t)},e.useEffectEvent=function(e){return w.H.useEffectEvent(e)},e.useId=function(){return w.H.useId()},e.useImperativeHandle=function(e,t,n){return w.H.useImperativeHandle(e,t,n)},e.useInsertionEffect=function(e,t){return w.H.useInsertionEffect(e,t)},e.useLayoutEffect=function(e,t){return w.H.useLayoutEffect(e,t)},e.useMemo=function(e,t){return w.H.useMemo(e,t)},e.useOptimistic=function(e,t){return w.H.useOptimistic(e,t)},e.useReducer=function(e,t,n){return w.H.useReducer(e,t,n)},e.useRef=function(e){return w.H.useRef(e)},e.useState=function(e){return w.H.useState(e)},e.useSyncExternalStore=function(e,t,n){return w.H.useSyncExternalStore(e,t,n)},e.useTransition=function(){return w.H.useTransition()},e.version=`19.2.5`})),nX=l(((e,t)=>{t.exports=tX()})),rX=l((e=>{var t=nX();function n(e){var t=`https://react.dev/errors/`+e;if(1<arguments.length){t+=`?args[]=`+encodeURIComponent(arguments[1]);for(var n=2;n<arguments.length;n++)t+=`&args[]=`+encodeURIComponent(arguments[n])}return`Minified React error #`+e+`; visit `+t+` for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`}function r(){}var i={d:{f:r,r:function(){throw Error(n(522))},D:r,C:r,L:r,m:r,X:r,S:r,M:r},p:0,findDOMNode:null},a=Symbol.for(`react.portal`);function o(e,t,n){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:a,key:r==null?null:``+r,children:e,containerInfo:t,implementation:n}}var s=t.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;function c(e,t){if(e===`font`)return``;if(typeof t==`string`)return t===`use-credentials`?t:``}e.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=i,e.createPortal=function(e,t){var r=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!t||t.nodeType!==1&&t.nodeType!==9&&t.nodeType!==11)throw Error(n(299));return o(e,t,null,r)},e.flushSync=function(e){var t=s.T,n=i.p;try{if(s.T=null,i.p=2,e)return e()}finally{s.T=t,i.p=n,i.d.f()}},e.preconnect=function(e,t){typeof e==`string`&&(t?(t=t.crossOrigin,t=typeof t==`string`?t===`use-credentials`?t:``:void 0):t=null,i.d.C(e,t))},e.prefetchDNS=function(e){typeof e==`string`&&i.d.D(e)},e.preinit=function(e,t){if(typeof e==`string`&&t&&typeof t.as==`string`){var n=t.as,r=c(n,t.crossOrigin),a=typeof t.integrity==`string`?t.integrity:void 0,o=typeof t.fetchPriority==`string`?t.fetchPriority:void 0;n===`style`?i.d.S(e,typeof t.precedence==`string`?t.precedence:void 0,{crossOrigin:r,integrity:a,fetchPriority:o}):n===`script`&&i.d.X(e,{crossOrigin:r,integrity:a,fetchPriority:o,nonce:typeof t.nonce==`string`?t.nonce:void 0})}},e.preinitModule=function(e,t){if(typeof e==`string`)if(typeof t==`object`&&t){if(t.as==null||t.as===`script`){var n=c(t.as,t.crossOrigin);i.d.M(e,{crossOrigin:n,integrity:typeof t.integrity==`string`?t.integrity:void 0,nonce:typeof t.nonce==`string`?t.nonce:void 0})}}else t??i.d.M(e)},e.preload=function(e,t){if(typeof e==`string`&&typeof t==`object`&&t&&typeof t.as==`string`){var n=t.as,r=c(n,t.crossOrigin);i.d.L(e,n,{crossOrigin:r,integrity:typeof t.integrity==`string`?t.integrity:void 0,nonce:typeof t.nonce==`string`?t.nonce:void 0,type:typeof t.type==`string`?t.type:void 0,fetchPriority:typeof t.fetchPriority==`string`?t.fetchPriority:void 0,referrerPolicy:typeof t.referrerPolicy==`string`?t.referrerPolicy:void 0,imageSrcSet:typeof t.imageSrcSet==`string`?t.imageSrcSet:void 0,imageSizes:typeof t.imageSizes==`string`?t.imageSizes:void 0,media:typeof t.media==`string`?t.media:void 0})}},e.preloadModule=function(e,t){if(typeof e==`string`)if(t){var n=c(t.as,t.crossOrigin);i.d.m(e,{as:typeof t.as==`string`&&t.as!==`script`?t.as:void 0,crossOrigin:n,integrity:typeof t.integrity==`string`?t.integrity:void 0})}else i.d.m(e)},e.requestFormReset=function(e){i.d.r(e)},e.unstable_batchedUpdates=function(e,t){return e(t)},e.useFormState=function(e,t,n){return s.H.useFormState(e,t,n)},e.useFormStatus=function(){return s.H.useHostTransitionStatus()},e.version=`19.2.5`})),iX=l(((e,t)=>{function n(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>`u`||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!=`function`))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(n)}catch(e){console.error(e)}}n(),t.exports=rX()})),aX=l((e=>{function t(e,t){var n=e.length;e.push(t);a:for(;0<n;){var r=n-1>>>1,a=e[r];if(0<i(a,t))e[r]=t,e[n]=a,n=r;else break a}}function n(e){return e.length===0?null:e[0]}function r(e){if(e.length===0)return null;var t=e[0],n=e.pop();if(n!==t){e[0]=n;a:for(var r=0,a=e.length,o=a>>>1;r<o;){var s=2*(r+1)-1,c=e[s],l=s+1,u=e[l];if(0>i(c,n))l<a&&0>i(u,c)?(e[r]=u,e[l]=n,r=l):(e[r]=c,e[s]=n,r=s);else if(l<a&&0>i(u,n))e[r]=u,e[l]=n,r=l;else break a}}return t}function i(e,t){var n=e.sortIndex-t.sortIndex;return n===0?e.id-t.id:n}if(e.unstable_now=void 0,typeof performance==`object`&&typeof performance.now==`function`){var a=performance;e.unstable_now=function(){return a.now()}}else{var o=Date,s=o.now();e.unstable_now=function(){return o.now()-s}}var c=[],l=[],u=1,d=null,f=3,p=!1,m=!1,h=!1,g=!1,_=typeof setTimeout==`function`?setTimeout:null,v=typeof clearTimeout==`function`?clearTimeout:null,y=typeof setImmediate<`u`?setImmediate:null;function b(e){for(var i=n(l);i!==null;){if(i.callback===null)r(l);else if(i.startTime<=e)r(l),i.sortIndex=i.expirationTime,t(c,i);else break;i=n(l)}}function x(e){if(h=!1,b(e),!m)if(n(c)!==null)m=!0,S||(S=!0,O());else{var t=n(l);t!==null&&j(x,t.startTime-e)}}var S=!1,C=-1,w=5,T=-1;function E(){return g?!0:!(e.unstable_now()-T<w)}function D(){if(g=!1,S){var t=e.unstable_now();T=t;var i=!0;try{a:{m=!1,h&&(h=!1,v(C),C=-1),p=!0;var a=f;try{b:{for(b(t),d=n(c);d!==null&&!(d.expirationTime>t&&E());){var o=d.callback;if(typeof o==`function`){d.callback=null,f=d.priorityLevel;var s=o(d.expirationTime<=t);if(t=e.unstable_now(),typeof s==`function`){d.callback=s,b(t),i=!0;break b}d===n(c)&&r(c),b(t)}else r(c);d=n(c)}if(d!==null)i=!0;else{var u=n(l);u!==null&&j(x,u.startTime-t),i=!1}}break a}finally{d=null,f=a,p=!1}i=void 0}}finally{i?O():S=!1}}}var O;if(typeof y==`function`)O=function(){y(D)};else if(typeof MessageChannel<`u`){var k=new MessageChannel,A=k.port2;k.port1.onmessage=D,O=function(){A.postMessage(null)}}else O=function(){_(D,0)};function j(t,n){C=_(function(){t(e.unstable_now())},n)}e.unstable_IdlePriority=5,e.unstable_ImmediatePriority=1,e.unstable_LowPriority=4,e.unstable_NormalPriority=3,e.unstable_Profiling=null,e.unstable_UserBlockingPriority=2,e.unstable_cancelCallback=function(e){e.callback=null},e.unstable_forceFrameRate=function(e){0>e||125<e?console.error(`forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported`):w=0<e?Math.floor(1e3/e):5},e.unstable_getCurrentPriorityLevel=function(){return f},e.unstable_next=function(e){switch(f){case 1:case 2:case 3:var t=3;break;default:t=f}var n=f;f=t;try{return e()}finally{f=n}},e.unstable_requestPaint=function(){g=!0},e.unstable_runWithPriority=function(e,t){switch(e){case 1:case 2:case 3:case 4:case 5:break;default:e=3}var n=f;f=e;try{return t()}finally{f=n}},e.unstable_scheduleCallback=function(r,i,a){var o=e.unstable_now();switch(typeof a==`object`&&a?(a=a.delay,a=typeof a==`number`&&0<a?o+a:o):a=o,r){case 1:var s=-1;break;case 2:s=250;break;case 5:s=1073741823;break;case 4:s=1e4;break;default:s=5e3}return s=a+s,r={id:u++,callback:i,priorityLevel:r,startTime:a,expirationTime:s,sortIndex:-1},a>o?(r.sortIndex=a,t(l,r),n(c)===null&&r===n(l)&&(h?(v(C),C=-1):h=!0,j(x,a-o))):(r.sortIndex=s,t(c,r),m||p||(m=!0,S||(S=!0,O()))),r},e.unstable_shouldYield=E,e.unstable_wrapCallback=function(e){var t=f;return function(){var n=f;f=t;try{return e.apply(this,arguments)}finally{f=n}}}})),oX=l(((e,t)=>{t.exports=aX()})),sX=l((e=>{var t=oX(),n=nX(),r=iX();function i(e){var t=`https://react.dev/errors/`+e;if(1<arguments.length){t+=`?args[]=`+encodeURIComponent(arguments[1]);for(var n=2;n<arguments.length;n++)t+=`&args[]=`+encodeURIComponent(arguments[n])}return`Minified React error #`+e+`; visit `+t+` for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`}function a(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function o(e){var t=e,n=e;if(e.alternate)for(;t.return;)t=t.return;else{e=t;do t=e,t.flags&4098&&(n=t.return),e=t.return;while(e)}return t.tag===3?n:null}function s(e){if(e.tag===13){var t=e.memoizedState;if(t===null&&(e=e.alternate,e!==null&&(t=e.memoizedState)),t!==null)return t.dehydrated}return null}function c(e){if(e.tag===31){var t=e.memoizedState;if(t===null&&(e=e.alternate,e!==null&&(t=e.memoizedState)),t!==null)return t.dehydrated}return null}function l(e){if(o(e)!==e)throw Error(i(188))}function u(e){var t=e.alternate;if(!t){if(t=o(e),t===null)throw Error(i(188));return t===e?e:null}for(var n=e,r=t;;){var a=n.return;if(a===null)break;var s=a.alternate;if(s===null){if(r=a.return,r!==null){n=r;continue}break}if(a.child===s.child){for(s=a.child;s;){if(s===n)return l(a),e;if(s===r)return l(a),t;s=s.sibling}throw Error(i(188))}if(n.return!==r.return)n=a,r=s;else{for(var c=!1,u=a.child;u;){if(u===n){c=!0,n=a,r=s;break}if(u===r){c=!0,r=a,n=s;break}u=u.sibling}if(!c){for(u=s.child;u;){if(u===n){c=!0,n=s,r=a;break}if(u===r){c=!0,r=s,n=a;break}u=u.sibling}if(!c)throw Error(i(189))}}if(n.alternate!==r)throw Error(i(190))}if(n.tag!==3)throw Error(i(188));return n.stateNode.current===n?e:t}function d(e){var t=e.tag;if(t===5||t===26||t===27||t===6)return e;for(e=e.child;e!==null;){if(t=d(e),t!==null)return t;e=e.sibling}return null}var f=Object.assign,p=Symbol.for(`react.element`),m=Symbol.for(`react.transitional.element`),h=Symbol.for(`react.portal`),g=Symbol.for(`react.fragment`),_=Symbol.for(`react.strict_mode`),v=Symbol.for(`react.profiler`),y=Symbol.for(`react.consumer`),b=Symbol.for(`react.context`),x=Symbol.for(`react.forward_ref`),S=Symbol.for(`react.suspense`),C=Symbol.for(`react.suspense_list`),w=Symbol.for(`react.memo`),T=Symbol.for(`react.lazy`),E=Symbol.for(`react.activity`),D=Symbol.for(`react.memo_cache_sentinel`),O=Symbol.iterator;function k(e){return typeof e!=`object`||!e?null:(e=O&&e[O]||e[`@@iterator`],typeof e==`function`?e:null)}var A=Symbol.for(`react.client.reference`);function j(e){if(e==null)return null;if(typeof e==`function`)return e.$$typeof===A?null:e.displayName||e.name||null;if(typeof e==`string`)return e;switch(e){case g:return`Fragment`;case v:return`Profiler`;case _:return`StrictMode`;case S:return`Suspense`;case C:return`SuspenseList`;case E:return`Activity`}if(typeof e==`object`)switch(e.$$typeof){case h:return`Portal`;case b:return e.displayName||`Context`;case y:return(e._context.displayName||`Context`)+`.Consumer`;case x:var t=e.render;return e=e.displayName,e||=(e=t.displayName||t.name||``,e===``?`ForwardRef`:`ForwardRef(`+e+`)`),e;case w:return t=e.displayName||null,t===null?j(e.type)||`Memo`:t;case T:t=e._payload,e=e._init;try{return j(e(t))}catch{}}return null}var M=Array.isArray,N=n.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,P=r.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,F={pending:!1,data:null,method:null,action:null},I=[],L=-1;function R(e){return{current:e}}function z(e){0>L||(e.current=I[L],I[L]=null,L--)}function B(e,t){L++,I[L]=e.current,e.current=t}var V=R(null),ee=R(null),H=R(null),U=R(null);function te(e,t){switch(B(H,t),B(ee,e),B(V,null),t.nodeType){case 9:case 11:e=(e=t.documentElement)&&(e=e.namespaceURI)?Ud(e):0;break;default:if(e=t.tagName,t=t.namespaceURI)t=Ud(t),e=Wd(t,e);else switch(e){case`svg`:e=1;break;case`math`:e=2;break;default:e=0}}z(V),B(V,e)}function W(){z(V),z(ee),z(H)}function ne(e){e.memoizedState!==null&&B(U,e);var t=V.current,n=Wd(t,e.type);t!==n&&(B(ee,e),B(V,n))}function G(e){ee.current===e&&(z(V),z(ee)),U.current===e&&(z(U),ep._currentValue=F)}var re,ie;function ae(e){if(re===void 0)try{throw Error()}catch(e){var t=e.stack.trim().match(/\n( *(at )?)/);re=t&&t[1]||``,ie=-1<e.stack.indexOf(`
|
|
84
84
|
at`)?` (<anonymous>)`:-1<e.stack.indexOf(`@`)?`@unknown:0:0`:``}return`
|
|
85
85
|
`+re+e+ie}var oe=!1;function se(e,t){if(!e||oe)return``;oe=!0;var n=Error.prepareStackTrace;Error.prepareStackTrace=void 0;try{var r={DetermineComponentFrameRoot:function(){try{if(t){var n=function(){throw Error()};if(Object.defineProperty(n.prototype,`props`,{set:function(){throw Error()}}),typeof Reflect==`object`&&Reflect.construct){try{Reflect.construct(n,[])}catch(e){var r=e}Reflect.construct(e,[],n)}else{try{n.call()}catch(e){r=e}e.call(n.prototype)}}else{try{throw Error()}catch(e){r=e}(n=e())&&typeof n.catch==`function`&&n.catch(function(){})}}catch(e){if(e&&r&&typeof e.stack==`string`)return[e.stack,r.stack]}return[null,null]}};r.DetermineComponentFrameRoot.displayName=`DetermineComponentFrameRoot`;var i=Object.getOwnPropertyDescriptor(r.DetermineComponentFrameRoot,`name`);i&&i.configurable&&Object.defineProperty(r.DetermineComponentFrameRoot,`name`,{value:`DetermineComponentFrameRoot`});var a=r.DetermineComponentFrameRoot(),o=a[0],s=a[1];if(o&&s){var c=o.split(`
|
|
86
86
|
`),l=s.split(`
|
|
@@ -88,7 +88,7 @@ In case of a (multi dimensional) array or matrix, the prob order quantile of all
|
|
|
88
88
|
`+c[r].replace(` at new `,` at `);return e.displayName&&u.includes(`<anonymous>`)&&(u=u.replace(`<anonymous>`,e.displayName)),u}while(1<=r&&0<=i);break}}}finally{oe=!1,Error.prepareStackTrace=n}return(n=e?e.displayName||e.name:``)?ae(n):``}function ce(e,t){switch(e.tag){case 26:case 27:case 5:return ae(e.type);case 16:return ae(`Lazy`);case 13:return e.child!==t&&t!==null?ae(`Suspense Fallback`):ae(`Suspense`);case 19:return ae(`SuspenseList`);case 0:case 15:return se(e.type,!1);case 11:return se(e.type.render,!1);case 1:return se(e.type,!0);case 31:return ae(`Activity`);default:return``}}function le(e){try{var t=``,n=null;do t+=ce(e,n),n=e,e=e.return;while(e);return t}catch(e){return`
|
|
89
89
|
Error generating stack: `+e.message+`
|
|
90
90
|
`+e.stack}}var ue=Object.prototype.hasOwnProperty,de=t.unstable_scheduleCallback,fe=t.unstable_cancelCallback,pe=t.unstable_shouldYield,me=t.unstable_requestPaint,he=t.unstable_now,ge=t.unstable_getCurrentPriorityLevel,_e=t.unstable_ImmediatePriority,ve=t.unstable_UserBlockingPriority,ye=t.unstable_NormalPriority,be=t.unstable_LowPriority,xe=t.unstable_IdlePriority,Se=t.log,Ce=t.unstable_setDisableYieldValue,we=null,Te=null;function Ee(e){if(typeof Se==`function`&&Ce(e),Te&&typeof Te.setStrictMode==`function`)try{Te.setStrictMode(we,e)}catch{}}var De=Math.clz32?Math.clz32:Ae,Oe=Math.log,ke=Math.LN2;function Ae(e){return e>>>=0,e===0?32:31-(Oe(e)/ke|0)|0}var je=256,Me=262144,Ne=4194304;function Pe(e){var t=e&42;if(t!==0)return t;switch(e&-e){case 1:return 1;case 2:return 2;case 4:return 4;case 8:return 8;case 16:return 16;case 32:return 32;case 64:return 64;case 128:return 128;case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:return e&261888;case 262144:case 524288:case 1048576:case 2097152:return e&3932160;case 4194304:case 8388608:case 16777216:case 33554432:return e&62914560;case 67108864:return 67108864;case 134217728:return 134217728;case 268435456:return 268435456;case 536870912:return 536870912;case 1073741824:return 0;default:return e}}function Fe(e,t,n){var r=e.pendingLanes;if(r===0)return 0;var i=0,a=e.suspendedLanes,o=e.pingedLanes;e=e.warmLanes;var s=r&134217727;return s===0?(s=r&~a,s===0?o===0?n||(n=r&~e,n!==0&&(i=Pe(n))):i=Pe(o):i=Pe(s)):(r=s&~a,r===0?(o&=s,o===0?n||(n=s&~e,n!==0&&(i=Pe(n))):i=Pe(o)):i=Pe(r)),i===0?0:t!==0&&t!==i&&(t&a)===0&&(a=i&-i,n=t&-t,a>=n||a===32&&n&4194048)?t:i}function Ie(e,t){return(e.pendingLanes&~(e.suspendedLanes&~e.pingedLanes)&t)===0}function Le(e,t){switch(e){case 1:case 2:case 4:case 8:case 64:return t+250;case 16:case 32:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return t+5e3;case 4194304:case 8388608:case 16777216:case 33554432:return-1;case 67108864:case 134217728:case 268435456:case 536870912:case 1073741824:return-1;default:return-1}}function Re(){var e=Ne;return Ne<<=1,!(Ne&62914560)&&(Ne=4194304),e}function ze(e){for(var t=[],n=0;31>n;n++)t.push(e);return t}function Be(e,t){e.pendingLanes|=t,t!==268435456&&(e.suspendedLanes=0,e.pingedLanes=0,e.warmLanes=0)}function Ve(e,t,n,r,i,a){var o=e.pendingLanes;e.pendingLanes=n,e.suspendedLanes=0,e.pingedLanes=0,e.warmLanes=0,e.expiredLanes&=n,e.entangledLanes&=n,e.errorRecoveryDisabledLanes&=n,e.shellSuspendCounter=0;var s=e.entanglements,c=e.expirationTimes,l=e.hiddenUpdates;for(n=o&~n;0<n;){var u=31-De(n),d=1<<u;s[u]=0,c[u]=-1;var f=l[u];if(f!==null)for(l[u]=null,u=0;u<f.length;u++){var p=f[u];p!==null&&(p.lane&=-536870913)}n&=~d}r!==0&&He(e,r,0),a!==0&&i===0&&e.tag!==0&&(e.suspendedLanes|=a&~(o&~t))}function He(e,t,n){e.pendingLanes|=t,e.suspendedLanes&=~t;var r=31-De(t);e.entangledLanes|=t,e.entanglements[r]=e.entanglements[r]|1073741824|n&261930}function Ue(e,t){var n=e.entangledLanes|=t;for(e=e.entanglements;n;){var r=31-De(n),i=1<<r;i&t|e[r]&t&&(e[r]|=t),n&=~i}}function We(e,t){var n=t&-t;return n=n&42?1:Ge(n),(n&(e.suspendedLanes|t))===0?n:0}function Ge(e){switch(e){case 2:e=1;break;case 8:e=4;break;case 32:e=16;break;case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:case 4194304:case 8388608:case 16777216:case 33554432:e=128;break;case 268435456:e=134217728;break;default:e=0}return e}function Ke(e){return e&=-e,2<e?8<e?e&134217727?32:268435456:8:2}function qe(){var e=P.p;return e===0?(e=window.event,e===void 0?32:gp(e.type)):e}function Je(e,t){var n=P.p;try{return P.p=e,t()}finally{P.p=n}}var Ye=Math.random().toString(36).slice(2),Xe=`__reactFiber$`+Ye,Ze=`__reactProps$`+Ye,Qe=`__reactContainer$`+Ye,$e=`__reactEvents$`+Ye,et=`__reactListeners$`+Ye,tt=`__reactHandles$`+Ye,nt=`__reactResources$`+Ye,rt=`__reactMarker$`+Ye;function it(e){delete e[Xe],delete e[Ze],delete e[$e],delete e[et],delete e[tt]}function at(e){var t=e[Xe];if(t)return t;for(var n=e.parentNode;n;){if(t=n[Qe]||n[Xe]){if(n=t.alternate,t.child!==null||n!==null&&n.child!==null)for(e=pf(e);e!==null;){if(n=e[Xe])return n;e=pf(e)}return t}e=n,n=e.parentNode}return null}function ot(e){if(e=e[Xe]||e[Qe]){var t=e.tag;if(t===5||t===6||t===13||t===31||t===26||t===27||t===3)return e}return null}function st(e){var t=e.tag;if(t===5||t===26||t===27||t===6)return e.stateNode;throw Error(i(33))}function ct(e){var t=e[nt];return t||=e[nt]={hoistableStyles:new Map,hoistableScripts:new Map},t}function lt(e){e[rt]=!0}var ut=new Set,dt={};function ft(e,t){pt(e,t),pt(e+`Capture`,t)}function pt(e,t){for(dt[e]=t,e=0;e<t.length;e++)ut.add(t[e])}var mt=RegExp(`^[:A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD][:A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD\\-.0-9\\u00B7\\u0300-\\u036F\\u203F-\\u2040]*$`),ht={},gt={};function _t(e){return ue.call(gt,e)?!0:ue.call(ht,e)?!1:mt.test(e)?gt[e]=!0:(ht[e]=!0,!1)}function vt(e,t,n){if(_t(t))if(n===null)e.removeAttribute(t);else{switch(typeof n){case`undefined`:case`function`:case`symbol`:e.removeAttribute(t);return;case`boolean`:var r=t.toLowerCase().slice(0,5);if(r!==`data-`&&r!==`aria-`){e.removeAttribute(t);return}}e.setAttribute(t,``+n)}}function yt(e,t,n){if(n===null)e.removeAttribute(t);else{switch(typeof n){case`undefined`:case`function`:case`symbol`:case`boolean`:e.removeAttribute(t);return}e.setAttribute(t,``+n)}}function bt(e,t,n,r){if(r===null)e.removeAttribute(n);else{switch(typeof r){case`undefined`:case`function`:case`symbol`:case`boolean`:e.removeAttribute(n);return}e.setAttributeNS(t,n,``+r)}}function xt(e){switch(typeof e){case`bigint`:case`boolean`:case`number`:case`string`:case`undefined`:return e;case`object`:return e;default:return``}}function St(e){var t=e.type;return(e=e.nodeName)&&e.toLowerCase()===`input`&&(t===`checkbox`||t===`radio`)}function Ct(e,t,n){var r=Object.getOwnPropertyDescriptor(e.constructor.prototype,t);if(!e.hasOwnProperty(t)&&r!==void 0&&typeof r.get==`function`&&typeof r.set==`function`){var i=r.get,a=r.set;return Object.defineProperty(e,t,{configurable:!0,get:function(){return i.call(this)},set:function(e){n=``+e,a.call(this,e)}}),Object.defineProperty(e,t,{enumerable:r.enumerable}),{getValue:function(){return n},setValue:function(e){n=``+e},stopTracking:function(){e._valueTracker=null,delete e[t]}}}}function wt(e){if(!e._valueTracker){var t=St(e)?`checked`:`value`;e._valueTracker=Ct(e,t,``+e[t])}}function Tt(e){if(!e)return!1;var t=e._valueTracker;if(!t)return!0;var n=t.getValue(),r=``;return e&&(r=St(e)?e.checked?`true`:`false`:e.value),e=r,e===n?!1:(t.setValue(e),!0)}function Et(e){if(e||=typeof document<`u`?document:void 0,e===void 0)return null;try{return e.activeElement||e.body}catch{return e.body}}var Dt=/[\n"\\]/g;function Ot(e){return e.replace(Dt,function(e){return`\\`+e.charCodeAt(0).toString(16)+` `})}function kt(e,t,n,r,i,a,o,s){e.name=``,o!=null&&typeof o!=`function`&&typeof o!=`symbol`&&typeof o!=`boolean`?e.type=o:e.removeAttribute(`type`),t==null?o!==`submit`&&o!==`reset`||e.removeAttribute(`value`):o===`number`?(t===0&&e.value===``||e.value!=t)&&(e.value=``+xt(t)):e.value!==``+xt(t)&&(e.value=``+xt(t)),t==null?n==null?r!=null&&e.removeAttribute(`value`):jt(e,o,xt(n)):jt(e,o,xt(t)),i==null&&a!=null&&(e.defaultChecked=!!a),i!=null&&(e.checked=i&&typeof i!=`function`&&typeof i!=`symbol`),s!=null&&typeof s!=`function`&&typeof s!=`symbol`&&typeof s!=`boolean`?e.name=``+xt(s):e.removeAttribute(`name`)}function At(e,t,n,r,i,a,o,s){if(a!=null&&typeof a!=`function`&&typeof a!=`symbol`&&typeof a!=`boolean`&&(e.type=a),t!=null||n!=null){if(!(a!==`submit`&&a!==`reset`||t!=null)){wt(e);return}n=n==null?``:``+xt(n),t=t==null?n:``+xt(t),s||t===e.value||(e.value=t),e.defaultValue=t}r??=i,r=typeof r!=`function`&&typeof r!=`symbol`&&!!r,e.checked=s?e.checked:!!r,e.defaultChecked=!!r,o!=null&&typeof o!=`function`&&typeof o!=`symbol`&&typeof o!=`boolean`&&(e.name=o),wt(e)}function jt(e,t,n){t===`number`&&Et(e.ownerDocument)===e||e.defaultValue===``+n||(e.defaultValue=``+n)}function Mt(e,t,n,r){if(e=e.options,t){t={};for(var i=0;i<n.length;i++)t[`$`+n[i]]=!0;for(n=0;n<e.length;n++)i=t.hasOwnProperty(`$`+e[n].value),e[n].selected!==i&&(e[n].selected=i),i&&r&&(e[n].defaultSelected=!0)}else{for(n=``+xt(n),t=null,i=0;i<e.length;i++){if(e[i].value===n){e[i].selected=!0,r&&(e[i].defaultSelected=!0);return}t!==null||e[i].disabled||(t=e[i])}t!==null&&(t.selected=!0)}}function Nt(e,t,n){if(t!=null&&(t=``+xt(t),t!==e.value&&(e.value=t),n==null)){e.defaultValue!==t&&(e.defaultValue=t);return}e.defaultValue=n==null?``:``+xt(n)}function Pt(e,t,n,r){if(t==null){if(r!=null){if(n!=null)throw Error(i(92));if(M(r)){if(1<r.length)throw Error(i(93));r=r[0]}n=r}n??=``,t=n}n=xt(t),e.defaultValue=n,r=e.textContent,r===n&&r!==``&&r!==null&&(e.value=r),wt(e)}function Ft(e,t){if(t){var n=e.firstChild;if(n&&n===e.lastChild&&n.nodeType===3){n.nodeValue=t;return}}e.textContent=t}var It=new Set(`animationIterationCount aspectRatio borderImageOutset borderImageSlice borderImageWidth boxFlex boxFlexGroup boxOrdinalGroup columnCount columns flex flexGrow flexPositive flexShrink flexNegative flexOrder gridArea gridRow gridRowEnd gridRowSpan gridRowStart gridColumn gridColumnEnd gridColumnSpan gridColumnStart fontWeight lineClamp lineHeight opacity order orphans scale tabSize widows zIndex zoom fillOpacity floodOpacity stopOpacity strokeDasharray strokeDashoffset strokeMiterlimit strokeOpacity strokeWidth MozAnimationIterationCount MozBoxFlex MozBoxFlexGroup MozLineClamp msAnimationIterationCount msFlex msZoom msFlexGrow msFlexNegative msFlexOrder msFlexPositive msFlexShrink msGridColumn msGridColumnSpan msGridRow msGridRowSpan WebkitAnimationIterationCount WebkitBoxFlex WebKitBoxFlexGroup WebkitBoxOrdinalGroup WebkitColumnCount WebkitColumns WebkitFlex WebkitFlexGrow WebkitFlexPositive WebkitFlexShrink WebkitLineClamp`.split(` `));function Lt(e,t,n){var r=t.indexOf(`--`)===0;n==null||typeof n==`boolean`||n===``?r?e.setProperty(t,``):t===`float`?e.cssFloat=``:e[t]=``:r?e.setProperty(t,n):typeof n!=`number`||n===0||It.has(t)?t===`float`?e.cssFloat=n:e[t]=(``+n).trim():e[t]=n+`px`}function Rt(e,t,n){if(t!=null&&typeof t!=`object`)throw Error(i(62));if(e=e.style,n!=null){for(var r in n)!n.hasOwnProperty(r)||t!=null&&t.hasOwnProperty(r)||(r.indexOf(`--`)===0?e.setProperty(r,``):r===`float`?e.cssFloat=``:e[r]=``);for(var a in t)r=t[a],t.hasOwnProperty(a)&&n[a]!==r&&Lt(e,a,r)}else for(var o in t)t.hasOwnProperty(o)&&Lt(e,o,t[o])}function zt(e){if(e.indexOf(`-`)===-1)return!1;switch(e){case`annotation-xml`:case`color-profile`:case`font-face`:case`font-face-src`:case`font-face-uri`:case`font-face-format`:case`font-face-name`:case`missing-glyph`:return!1;default:return!0}}var Bt=new Map([[`acceptCharset`,`accept-charset`],[`htmlFor`,`for`],[`httpEquiv`,`http-equiv`],[`crossOrigin`,`crossorigin`],[`accentHeight`,`accent-height`],[`alignmentBaseline`,`alignment-baseline`],[`arabicForm`,`arabic-form`],[`baselineShift`,`baseline-shift`],[`capHeight`,`cap-height`],[`clipPath`,`clip-path`],[`clipRule`,`clip-rule`],[`colorInterpolation`,`color-interpolation`],[`colorInterpolationFilters`,`color-interpolation-filters`],[`colorProfile`,`color-profile`],[`colorRendering`,`color-rendering`],[`dominantBaseline`,`dominant-baseline`],[`enableBackground`,`enable-background`],[`fillOpacity`,`fill-opacity`],[`fillRule`,`fill-rule`],[`floodColor`,`flood-color`],[`floodOpacity`,`flood-opacity`],[`fontFamily`,`font-family`],[`fontSize`,`font-size`],[`fontSizeAdjust`,`font-size-adjust`],[`fontStretch`,`font-stretch`],[`fontStyle`,`font-style`],[`fontVariant`,`font-variant`],[`fontWeight`,`font-weight`],[`glyphName`,`glyph-name`],[`glyphOrientationHorizontal`,`glyph-orientation-horizontal`],[`glyphOrientationVertical`,`glyph-orientation-vertical`],[`horizAdvX`,`horiz-adv-x`],[`horizOriginX`,`horiz-origin-x`],[`imageRendering`,`image-rendering`],[`letterSpacing`,`letter-spacing`],[`lightingColor`,`lighting-color`],[`markerEnd`,`marker-end`],[`markerMid`,`marker-mid`],[`markerStart`,`marker-start`],[`overlinePosition`,`overline-position`],[`overlineThickness`,`overline-thickness`],[`paintOrder`,`paint-order`],[`panose-1`,`panose-1`],[`pointerEvents`,`pointer-events`],[`renderingIntent`,`rendering-intent`],[`shapeRendering`,`shape-rendering`],[`stopColor`,`stop-color`],[`stopOpacity`,`stop-opacity`],[`strikethroughPosition`,`strikethrough-position`],[`strikethroughThickness`,`strikethrough-thickness`],[`strokeDasharray`,`stroke-dasharray`],[`strokeDashoffset`,`stroke-dashoffset`],[`strokeLinecap`,`stroke-linecap`],[`strokeLinejoin`,`stroke-linejoin`],[`strokeMiterlimit`,`stroke-miterlimit`],[`strokeOpacity`,`stroke-opacity`],[`strokeWidth`,`stroke-width`],[`textAnchor`,`text-anchor`],[`textDecoration`,`text-decoration`],[`textRendering`,`text-rendering`],[`transformOrigin`,`transform-origin`],[`underlinePosition`,`underline-position`],[`underlineThickness`,`underline-thickness`],[`unicodeBidi`,`unicode-bidi`],[`unicodeRange`,`unicode-range`],[`unitsPerEm`,`units-per-em`],[`vAlphabetic`,`v-alphabetic`],[`vHanging`,`v-hanging`],[`vIdeographic`,`v-ideographic`],[`vMathematical`,`v-mathematical`],[`vectorEffect`,`vector-effect`],[`vertAdvY`,`vert-adv-y`],[`vertOriginX`,`vert-origin-x`],[`vertOriginY`,`vert-origin-y`],[`wordSpacing`,`word-spacing`],[`writingMode`,`writing-mode`],[`xmlnsXlink`,`xmlns:xlink`],[`xHeight`,`x-height`]]),Vt=/^[\u0000-\u001F ]*j[\r\n\t]*a[\r\n\t]*v[\r\n\t]*a[\r\n\t]*s[\r\n\t]*c[\r\n\t]*r[\r\n\t]*i[\r\n\t]*p[\r\n\t]*t[\r\n\t]*:/i;function Ht(e){return Vt.test(``+e)?`javascript:throw new Error('React has blocked a javascript: URL as a security precaution.')`:e}function Ut(){}var Wt=null;function Gt(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var Kt=null,qt=null;function Jt(e){var t=ot(e);if(t&&(e=t.stateNode)){var n=e[Ze]||null;a:switch(e=t.stateNode,t.type){case`input`:if(kt(e,n.value,n.defaultValue,n.defaultValue,n.checked,n.defaultChecked,n.type,n.name),t=n.name,n.type===`radio`&&t!=null){for(n=e;n.parentNode;)n=n.parentNode;for(n=n.querySelectorAll(`input[name="`+Ot(``+t)+`"][type="radio"]`),t=0;t<n.length;t++){var r=n[t];if(r!==e&&r.form===e.form){var a=r[Ze]||null;if(!a)throw Error(i(90));kt(r,a.value,a.defaultValue,a.defaultValue,a.checked,a.defaultChecked,a.type,a.name)}}for(t=0;t<n.length;t++)r=n[t],r.form===e.form&&Tt(r)}break a;case`textarea`:Nt(e,n.value,n.defaultValue);break a;case`select`:t=n.value,t!=null&&Mt(e,!!n.multiple,t,!1)}}}var Yt=!1;function Xt(e,t,n){if(Yt)return e(t,n);Yt=!0;try{return e(t)}finally{if(Yt=!1,(Kt!==null||qt!==null)&&(yu(),Kt&&(t=Kt,e=qt,qt=Kt=null,Jt(t),e)))for(t=0;t<e.length;t++)Jt(e[t])}}function Zt(e,t){var n=e.stateNode;if(n===null)return null;var r=n[Ze]||null;if(r===null)return null;n=r[t];a:switch(t){case`onClick`:case`onClickCapture`:case`onDoubleClick`:case`onDoubleClickCapture`:case`onMouseDown`:case`onMouseDownCapture`:case`onMouseMove`:case`onMouseMoveCapture`:case`onMouseUp`:case`onMouseUpCapture`:case`onMouseEnter`:(r=!r.disabled)||(e=e.type,r=!(e===`button`||e===`input`||e===`select`||e===`textarea`)),e=!r;break a;default:e=!1}if(e)return null;if(n&&typeof n!=`function`)throw Error(i(231,t,typeof n));return n}var Qt=!(typeof window>`u`||window.document===void 0||window.document.createElement===void 0),$t=!1;if(Qt)try{var en={};Object.defineProperty(en,`passive`,{get:function(){$t=!0}}),window.addEventListener(`test`,en,en),window.removeEventListener(`test`,en,en)}catch{$t=!1}var tn=null,nn=null,rn=null;function an(){if(rn)return rn;var e,t=nn,n=t.length,r,i=`value`in tn?tn.value:tn.textContent,a=i.length;for(e=0;e<n&&t[e]===i[e];e++);var o=n-e;for(r=1;r<=o&&t[n-r]===i[a-r];r++);return rn=i.slice(e,1<r?1-r:void 0)}function on(e){var t=e.keyCode;return`charCode`in e?(e=e.charCode,e===0&&t===13&&(e=13)):e=t,e===10&&(e=13),32<=e||e===13?e:0}function sn(){return!0}function cn(){return!1}function ln(e){function t(t,n,r,i,a){for(var o in this._reactName=t,this._targetInst=r,this.type=n,this.nativeEvent=i,this.target=a,this.currentTarget=null,e)e.hasOwnProperty(o)&&(t=e[o],this[o]=t?t(i):i[o]);return this.isDefaultPrevented=(i.defaultPrevented==null?!1===i.returnValue:i.defaultPrevented)?sn:cn,this.isPropagationStopped=cn,this}return f(t.prototype,{preventDefault:function(){this.defaultPrevented=!0;var e=this.nativeEvent;e&&(e.preventDefault?e.preventDefault():typeof e.returnValue!=`unknown`&&(e.returnValue=!1),this.isDefaultPrevented=sn)},stopPropagation:function(){var e=this.nativeEvent;e&&(e.stopPropagation?e.stopPropagation():typeof e.cancelBubble!=`unknown`&&(e.cancelBubble=!0),this.isPropagationStopped=sn)},persist:function(){},isPersistent:sn}),t}var un={eventPhase:0,bubbles:0,cancelable:0,timeStamp:function(e){return e.timeStamp||Date.now()},defaultPrevented:0,isTrusted:0},dn=ln(un),fn=f({},un,{view:0,detail:0}),pn=ln(fn),mn,hn,gn,_n=f({},fn,{screenX:0,screenY:0,clientX:0,clientY:0,pageX:0,pageY:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,getModifierState:Dn,button:0,buttons:0,relatedTarget:function(e){return e.relatedTarget===void 0?e.fromElement===e.srcElement?e.toElement:e.fromElement:e.relatedTarget},movementX:function(e){return`movementX`in e?e.movementX:(e!==gn&&(gn&&e.type===`mousemove`?(mn=e.screenX-gn.screenX,hn=e.screenY-gn.screenY):hn=mn=0,gn=e),mn)},movementY:function(e){return`movementY`in e?e.movementY:hn}}),vn=ln(_n),yn=ln(f({},_n,{dataTransfer:0})),bn=ln(f({},fn,{relatedTarget:0})),xn=ln(f({},un,{animationName:0,elapsedTime:0,pseudoElement:0})),Sn=ln(f({},un,{clipboardData:function(e){return`clipboardData`in e?e.clipboardData:window.clipboardData}})),Cn=ln(f({},un,{data:0})),K={Esc:`Escape`,Spacebar:` `,Left:`ArrowLeft`,Up:`ArrowUp`,Right:`ArrowRight`,Down:`ArrowDown`,Del:`Delete`,Win:`OS`,Menu:`ContextMenu`,Apps:`ContextMenu`,Scroll:`ScrollLock`,MozPrintableKey:`Unidentified`},wn={8:`Backspace`,9:`Tab`,12:`Clear`,13:`Enter`,16:`Shift`,17:`Control`,18:`Alt`,19:`Pause`,20:`CapsLock`,27:`Escape`,32:` `,33:`PageUp`,34:`PageDown`,35:`End`,36:`Home`,37:`ArrowLeft`,38:`ArrowUp`,39:`ArrowRight`,40:`ArrowDown`,45:`Insert`,46:`Delete`,112:`F1`,113:`F2`,114:`F3`,115:`F4`,116:`F5`,117:`F6`,118:`F7`,119:`F8`,120:`F9`,121:`F10`,122:`F11`,123:`F12`,144:`NumLock`,145:`ScrollLock`,224:`Meta`},Tn={Alt:`altKey`,Control:`ctrlKey`,Meta:`metaKey`,Shift:`shiftKey`};function En(e){var t=this.nativeEvent;return t.getModifierState?t.getModifierState(e):(e=Tn[e])?!!t[e]:!1}function Dn(){return En}var On=ln(f({},fn,{key:function(e){if(e.key){var t=K[e.key]||e.key;if(t!==`Unidentified`)return t}return e.type===`keypress`?(e=on(e),e===13?`Enter`:String.fromCharCode(e)):e.type===`keydown`||e.type===`keyup`?wn[e.keyCode]||`Unidentified`:``},code:0,location:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,repeat:0,locale:0,getModifierState:Dn,charCode:function(e){return e.type===`keypress`?on(e):0},keyCode:function(e){return e.type===`keydown`||e.type===`keyup`?e.keyCode:0},which:function(e){return e.type===`keypress`?on(e):e.type===`keydown`||e.type===`keyup`?e.keyCode:0}})),kn=ln(f({},_n,{pointerId:0,width:0,height:0,pressure:0,tangentialPressure:0,tiltX:0,tiltY:0,twist:0,pointerType:0,isPrimary:0})),An=ln(f({},fn,{touches:0,targetTouches:0,changedTouches:0,altKey:0,metaKey:0,ctrlKey:0,shiftKey:0,getModifierState:Dn})),jn=ln(f({},un,{propertyName:0,elapsedTime:0,pseudoElement:0})),Mn=ln(f({},_n,{deltaX:function(e){return`deltaX`in e?e.deltaX:`wheelDeltaX`in e?-e.wheelDeltaX:0},deltaY:function(e){return`deltaY`in e?e.deltaY:`wheelDeltaY`in e?-e.wheelDeltaY:`wheelDelta`in e?-e.wheelDelta:0},deltaZ:0,deltaMode:0})),Nn=ln(f({},un,{newState:0,oldState:0})),Pn=[9,13,27,32],Fn=Qt&&`CompositionEvent`in window,In=null;Qt&&`documentMode`in document&&(In=document.documentMode);var Ln=Qt&&`TextEvent`in window&&!In,Rn=Qt&&(!Fn||In&&8<In&&11>=In),zn=` `,Bn=!1;function Vn(e,t){switch(e){case`keyup`:return Pn.indexOf(t.keyCode)!==-1;case`keydown`:return t.keyCode!==229;case`keypress`:case`mousedown`:case`focusout`:return!0;default:return!1}}function Hn(e){return e=e.detail,typeof e==`object`&&`data`in e?e.data:null}var Un=!1;function Wn(e,t){switch(e){case`compositionend`:return Hn(t);case`keypress`:return t.which===32?(Bn=!0,zn):null;case`textInput`:return e=t.data,e===zn&&Bn?null:e;default:return null}}function Gn(e,t){if(Un)return e===`compositionend`||!Fn&&Vn(e,t)?(e=an(),rn=nn=tn=null,Un=!1,e):null;switch(e){case`paste`:return null;case`keypress`:if(!(t.ctrlKey||t.altKey||t.metaKey)||t.ctrlKey&&t.altKey){if(t.char&&1<t.char.length)return t.char;if(t.which)return String.fromCharCode(t.which)}return null;case`compositionend`:return Rn&&t.locale!==`ko`?null:t.data;default:return null}}var Kn={color:!0,date:!0,datetime:!0,"datetime-local":!0,email:!0,month:!0,number:!0,password:!0,range:!0,search:!0,tel:!0,text:!0,time:!0,url:!0,week:!0};function qn(e){var t=e&&e.nodeName&&e.nodeName.toLowerCase();return t===`input`?!!Kn[e.type]:t===`textarea`}function Jn(e,t,n,r){Kt?qt?qt.push(r):qt=[r]:Kt=r,t=Dd(t,`onChange`),0<t.length&&(n=new dn(`onChange`,`change`,null,n,r),e.push({event:n,listeners:t}))}var Yn=null,Xn=null;function Zn(e){yd(e,0)}function Qn(e){if(Tt(st(e)))return e}function $n(e,t){if(e===`change`)return t}var er=!1;if(Qt){var tr;if(Qt){var nr=`oninput`in document;if(!nr){var rr=document.createElement(`div`);rr.setAttribute(`oninput`,`return;`),nr=typeof rr.oninput==`function`}tr=nr}else tr=!1;er=tr&&(!document.documentMode||9<document.documentMode)}function ir(){Yn&&(Yn.detachEvent(`onpropertychange`,ar),Xn=Yn=null)}function ar(e){if(e.propertyName===`value`&&Qn(Xn)){var t=[];Jn(t,Xn,e,Gt(e)),Xt(Zn,t)}}function or(e,t,n){e===`focusin`?(ir(),Yn=t,Xn=n,Yn.attachEvent(`onpropertychange`,ar)):e===`focusout`&&ir()}function sr(e){if(e===`selectionchange`||e===`keyup`||e===`keydown`)return Qn(Xn)}function cr(e,t){if(e===`click`)return Qn(t)}function lr(e,t){if(e===`input`||e===`change`)return Qn(t)}function ur(e,t){return e===t&&(e!==0||1/e==1/t)||e!==e&&t!==t}var dr=typeof Object.is==`function`?Object.is:ur;function fr(e,t){if(dr(e,t))return!0;if(typeof e!=`object`||!e||typeof t!=`object`||!t)return!1;var n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(r=0;r<n.length;r++){var i=n[r];if(!ue.call(t,i)||!dr(e[i],t[i]))return!1}return!0}function pr(e){for(;e&&e.firstChild;)e=e.firstChild;return e}function mr(e,t){var n=pr(e);e=0;for(var r;n;){if(n.nodeType===3){if(r=e+n.textContent.length,e<=t&&r>=t)return{node:n,offset:t-e};e=r}a:{for(;n;){if(n.nextSibling){n=n.nextSibling;break a}n=n.parentNode}n=void 0}n=pr(n)}}function hr(e,t){return e&&t?e===t?!0:e&&e.nodeType===3?!1:t&&t.nodeType===3?hr(e,t.parentNode):`contains`in e?e.contains(t):e.compareDocumentPosition?!!(e.compareDocumentPosition(t)&16):!1:!1}function gr(e){e=e!=null&&e.ownerDocument!=null&&e.ownerDocument.defaultView!=null?e.ownerDocument.defaultView:window;for(var t=Et(e.document);t instanceof e.HTMLIFrameElement;){try{var n=typeof t.contentWindow.location.href==`string`}catch{n=!1}if(n)e=t.contentWindow;else break;t=Et(e.document)}return t}function _r(e){var t=e&&e.nodeName&&e.nodeName.toLowerCase();return t&&(t===`input`&&(e.type===`text`||e.type===`search`||e.type===`tel`||e.type===`url`||e.type===`password`)||t===`textarea`||e.contentEditable===`true`)}var vr=Qt&&`documentMode`in document&&11>=document.documentMode,yr=null,br=null,xr=null,Sr=!1;function Cr(e,t,n){var r=n.window===n?n.document:n.nodeType===9?n:n.ownerDocument;Sr||yr==null||yr!==Et(r)||(r=yr,`selectionStart`in r&&_r(r)?r={start:r.selectionStart,end:r.selectionEnd}:(r=(r.ownerDocument&&r.ownerDocument.defaultView||window).getSelection(),r={anchorNode:r.anchorNode,anchorOffset:r.anchorOffset,focusNode:r.focusNode,focusOffset:r.focusOffset}),xr&&fr(xr,r)||(xr=r,r=Dd(br,`onSelect`),0<r.length&&(t=new dn(`onSelect`,`select`,null,t,n),e.push({event:t,listeners:r}),t.target=yr)))}function wr(e,t){var n={};return n[e.toLowerCase()]=t.toLowerCase(),n[`Webkit`+e]=`webkit`+t,n[`Moz`+e]=`moz`+t,n}var Tr={animationend:wr(`Animation`,`AnimationEnd`),animationiteration:wr(`Animation`,`AnimationIteration`),animationstart:wr(`Animation`,`AnimationStart`),transitionrun:wr(`Transition`,`TransitionRun`),transitionstart:wr(`Transition`,`TransitionStart`),transitioncancel:wr(`Transition`,`TransitionCancel`),transitionend:wr(`Transition`,`TransitionEnd`)},Er={},Dr={};Qt&&(Dr=document.createElement(`div`).style,`AnimationEvent`in window||(delete Tr.animationend.animation,delete Tr.animationiteration.animation,delete Tr.animationstart.animation),`TransitionEvent`in window||delete Tr.transitionend.transition);function Or(e){if(Er[e])return Er[e];if(!Tr[e])return e;var t=Tr[e],n;for(n in t)if(t.hasOwnProperty(n)&&n in Dr)return Er[e]=t[n];return e}var kr=Or(`animationend`),Ar=Or(`animationiteration`),jr=Or(`animationstart`),Mr=Or(`transitionrun`),Nr=Or(`transitionstart`),Pr=Or(`transitioncancel`),Fr=Or(`transitionend`),q=new Map,Ir=`abort auxClick beforeToggle cancel canPlay canPlayThrough click close contextMenu copy cut drag dragEnd dragEnter dragExit dragLeave dragOver dragStart drop durationChange emptied encrypted ended error gotPointerCapture input invalid keyDown keyPress keyUp load loadedData loadedMetadata loadStart lostPointerCapture mouseDown mouseMove mouseOut mouseOver mouseUp paste pause play playing pointerCancel pointerDown pointerMove pointerOut pointerOver pointerUp progress rateChange reset resize seeked seeking stalled submit suspend timeUpdate touchCancel touchEnd touchStart volumeChange scroll toggle touchMove waiting wheel`.split(` `);Ir.push(`scrollEnd`);function Lr(e,t){q.set(e,t),ft(t,[e])}var Rr=typeof reportError==`function`?reportError:function(e){if(typeof window==`object`&&typeof window.ErrorEvent==`function`){var t=new window.ErrorEvent(`error`,{bubbles:!0,cancelable:!0,message:typeof e==`object`&&e&&typeof e.message==`string`?String(e.message):String(e),error:e});if(!window.dispatchEvent(t))return}else if(typeof process==`object`&&typeof process.emit==`function`){process.emit(`uncaughtException`,e);return}console.error(e)},zr=[],Br=0,Vr=0;function Hr(){for(var e=Br,t=Vr=Br=0;t<e;){var n=zr[t];zr[t++]=null;var r=zr[t];zr[t++]=null;var i=zr[t];zr[t++]=null;var a=zr[t];if(zr[t++]=null,r!==null&&i!==null){var o=r.pending;o===null?i.next=i:(i.next=o.next,o.next=i),r.pending=i}a!==0&&Kr(n,i,a)}}function Ur(e,t,n,r){zr[Br++]=e,zr[Br++]=t,zr[Br++]=n,zr[Br++]=r,Vr|=r,e.lanes|=r,e=e.alternate,e!==null&&(e.lanes|=r)}function Wr(e,t,n,r){return Ur(e,t,n,r),qr(e)}function Gr(e,t){return Ur(e,null,null,t),qr(e)}function Kr(e,t,n){e.lanes|=n;var r=e.alternate;r!==null&&(r.lanes|=n);for(var i=!1,a=e.return;a!==null;)a.childLanes|=n,r=a.alternate,r!==null&&(r.childLanes|=n),a.tag===22&&(e=a.stateNode,e===null||e._visibility&1||(i=!0)),e=a,a=a.return;return e.tag===3?(a=e.stateNode,i&&t!==null&&(i=31-De(n),e=a.hiddenUpdates,r=e[i],r===null?e[i]=[t]:r.push(t),t.lane=n|536870912),a):null}function qr(e){if(50<uu)throw uu=0,du=null,Error(i(185));for(var t=e.return;t!==null;)e=t,t=e.return;return e.tag===3?e.stateNode:null}var Jr={};function Yr(e,t,n,r){this.tag=e,this.key=n,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.refCleanup=this.ref=null,this.pendingProps=t,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=r,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function Xr(e,t,n,r){return new Yr(e,t,n,r)}function Zr(e){return e=e.prototype,!(!e||!e.isReactComponent)}function Qr(e,t){var n=e.alternate;return n===null?(n=Xr(e.tag,t,e.key,e.mode),n.elementType=e.elementType,n.type=e.type,n.stateNode=e.stateNode,n.alternate=e,e.alternate=n):(n.pendingProps=t,n.type=e.type,n.flags=0,n.subtreeFlags=0,n.deletions=null),n.flags=e.flags&65011712,n.childLanes=e.childLanes,n.lanes=e.lanes,n.child=e.child,n.memoizedProps=e.memoizedProps,n.memoizedState=e.memoizedState,n.updateQueue=e.updateQueue,t=e.dependencies,n.dependencies=t===null?null:{lanes:t.lanes,firstContext:t.firstContext},n.sibling=e.sibling,n.index=e.index,n.ref=e.ref,n.refCleanup=e.refCleanup,n}function $r(e,t){e.flags&=65011714;var n=e.alternate;return n===null?(e.childLanes=0,e.lanes=t,e.child=null,e.subtreeFlags=0,e.memoizedProps=null,e.memoizedState=null,e.updateQueue=null,e.dependencies=null,e.stateNode=null):(e.childLanes=n.childLanes,e.lanes=n.lanes,e.child=n.child,e.subtreeFlags=0,e.deletions=null,e.memoizedProps=n.memoizedProps,e.memoizedState=n.memoizedState,e.updateQueue=n.updateQueue,e.type=n.type,t=n.dependencies,e.dependencies=t===null?null:{lanes:t.lanes,firstContext:t.firstContext}),e}function ei(e,t,n,r,a,o){var s=0;if(r=e,typeof e==`function`)Zr(e)&&(s=1);else if(typeof e==`string`)s=Gf(e,n,V.current)?26:e===`html`||e===`head`||e===`body`?27:5;else a:switch(e){case E:return e=Xr(31,n,t,a),e.elementType=E,e.lanes=o,e;case g:return ti(n.children,a,o,t);case _:s=8,a|=24;break;case v:return e=Xr(12,n,t,a|2),e.elementType=v,e.lanes=o,e;case S:return e=Xr(13,n,t,a),e.elementType=S,e.lanes=o,e;case C:return e=Xr(19,n,t,a),e.elementType=C,e.lanes=o,e;default:if(typeof e==`object`&&e)switch(e.$$typeof){case b:s=10;break a;case y:s=9;break a;case x:s=11;break a;case w:s=14;break a;case T:s=16,r=null;break a}s=29,n=Error(i(130,e===null?`null`:typeof e,``)),r=null}return t=Xr(s,n,t,a),t.elementType=e,t.type=r,t.lanes=o,t}function ti(e,t,n,r){return e=Xr(7,e,r,t),e.lanes=n,e}function ni(e,t,n){return e=Xr(6,e,null,t),e.lanes=n,e}function ri(e){var t=Xr(18,null,null,0);return t.stateNode=e,t}function ii(e,t,n){return t=Xr(4,e.children===null?[]:e.children,e.key,t),t.lanes=n,t.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},t}var ai=new WeakMap;function oi(e,t){if(typeof e==`object`&&e){var n=ai.get(e);return n===void 0?(t={value:e,source:t,stack:le(t)},ai.set(e,t),t):n}return{value:e,source:t,stack:le(t)}}var si=[],ci=0,li=null,ui=0,di=[],fi=0,pi=null,mi=1,hi=``;function gi(e,t){si[ci++]=ui,si[ci++]=li,li=e,ui=t}function _i(e,t,n){di[fi++]=mi,di[fi++]=hi,di[fi++]=pi,pi=e;var r=mi;e=hi;var i=32-De(r)-1;r&=~(1<<i),n+=1;var a=32-De(t)+i;if(30<a){var o=i-i%5;a=(r&(1<<o)-1).toString(32),r>>=o,i-=o,mi=1<<32-De(t)+i|n<<i|r,hi=a+e}else mi=1<<a|n<<i|r,hi=e}function vi(e){e.return!==null&&(gi(e,1),_i(e,1,0))}function yi(e){for(;e===li;)li=si[--ci],si[ci]=null,ui=si[--ci],si[ci]=null;for(;e===pi;)pi=di[--fi],di[fi]=null,hi=di[--fi],di[fi]=null,mi=di[--fi],di[fi]=null}function bi(e,t){di[fi++]=mi,di[fi++]=hi,di[fi++]=pi,mi=t.id,hi=t.overflow,pi=e}var xi=null,Si=null,Ci=!1,wi=null,Ti=!1,Ei=Error(i(519));function Di(e){throw Ni(oi(Error(i(418,1<arguments.length&&arguments[1]!==void 0&&arguments[1]?`text`:`HTML`,``)),e)),Ei}function Oi(e){var t=e.stateNode,n=e.type,r=e.memoizedProps;switch(t[Xe]=e,t[Ze]=r,n){case`dialog`:bd(`cancel`,t),bd(`close`,t);break;case`iframe`:case`object`:case`embed`:bd(`load`,t);break;case`video`:case`audio`:for(n=0;n<_d.length;n++)bd(_d[n],t);break;case`source`:bd(`error`,t);break;case`img`:case`image`:case`link`:bd(`error`,t),bd(`load`,t);break;case`details`:bd(`toggle`,t);break;case`input`:bd(`invalid`,t),At(t,r.value,r.defaultValue,r.checked,r.defaultChecked,r.type,r.name,!0);break;case`select`:bd(`invalid`,t);break;case`textarea`:bd(`invalid`,t),Pt(t,r.value,r.defaultValue,r.children)}n=r.children,typeof n!=`string`&&typeof n!=`number`&&typeof n!=`bigint`||t.textContent===``+n||!0===r.suppressHydrationWarning||Nd(t.textContent,n)?(r.popover!=null&&(bd(`beforetoggle`,t),bd(`toggle`,t)),r.onScroll!=null&&bd(`scroll`,t),r.onScrollEnd!=null&&bd(`scrollend`,t),r.onClick!=null&&(t.onclick=Ut),t=!0):t=!1,t||Di(e,!0)}function ki(e){for(xi=e.return;xi;)switch(xi.tag){case 5:case 31:case 13:Ti=!1;return;case 27:case 3:Ti=!0;return;default:xi=xi.return}}function Ai(e){if(e!==xi)return!1;if(!Ci)return ki(e),Ci=!0,!1;var t=e.tag,n;if((n=t!==3&&t!==27)&&((n=t===5)&&(n=e.type,n=!(n!==`form`&&n!==`button`)||Gd(e.type,e.memoizedProps)),n=!n),n&&Si&&Di(e),ki(e),t===13){if(e=e.memoizedState,e=e===null?null:e.dehydrated,!e)throw Error(i(317));Si=ff(e)}else if(t===31){if(e=e.memoizedState,e=e===null?null:e.dehydrated,!e)throw Error(i(317));Si=ff(e)}else t===27?(t=Si,$d(e.type)?(e=df,df=null,Si=e):Si=t):Si=xi?uf(e.stateNode.nextSibling):null;return!0}function ji(){Si=xi=null,Ci=!1}function Mi(){var e=wi;return e!==null&&(Xl===null?Xl=e:Xl.push.apply(Xl,e),wi=null),e}function Ni(e){wi===null?wi=[e]:wi.push(e)}var Pi=R(null),Fi=null,Ii=null;function Li(e,t,n){B(Pi,t._currentValue),t._currentValue=n}function Ri(e){e._currentValue=Pi.current,z(Pi)}function zi(e,t,n){for(;e!==null;){var r=e.alternate;if((e.childLanes&t)===t?r!==null&&(r.childLanes&t)!==t&&(r.childLanes|=t):(e.childLanes|=t,r!==null&&(r.childLanes|=t)),e===n)break;e=e.return}}function Bi(e,t,n,r){var a=e.child;for(a!==null&&(a.return=e);a!==null;){var o=a.dependencies;if(o!==null){var s=a.child;o=o.firstContext;a:for(;o!==null;){var c=o;o=a;for(var l=0;l<t.length;l++)if(c.context===t[l]){o.lanes|=n,c=o.alternate,c!==null&&(c.lanes|=n),zi(o.return,n,e),r||(s=null);break a}o=c.next}}else if(a.tag===18){if(s=a.return,s===null)throw Error(i(341));s.lanes|=n,o=s.alternate,o!==null&&(o.lanes|=n),zi(s,n,e),s=null}else s=a.child;if(s!==null)s.return=a;else for(s=a;s!==null;){if(s===e){s=null;break}if(a=s.sibling,a!==null){a.return=s.return,s=a;break}s=s.return}a=s}}function Vi(e,t,n,r){e=null;for(var a=t,o=!1;a!==null;){if(!o){if(a.flags&524288)o=!0;else if(a.flags&262144)break}if(a.tag===10){var s=a.alternate;if(s===null)throw Error(i(387));if(s=s.memoizedProps,s!==null){var c=a.type;dr(a.pendingProps.value,s.value)||(e===null?e=[c]:e.push(c))}}else if(a===U.current){if(s=a.alternate,s===null)throw Error(i(387));s.memoizedState.memoizedState!==a.memoizedState.memoizedState&&(e===null?e=[ep]:e.push(ep))}a=a.return}e!==null&&Bi(t,e,n,r),t.flags|=262144}function Hi(e){for(e=e.firstContext;e!==null;){if(!dr(e.context._currentValue,e.memoizedValue))return!0;e=e.next}return!1}function Ui(e){Fi=e,Ii=null,e=e.dependencies,e!==null&&(e.firstContext=null)}function Wi(e){return Ki(Fi,e)}function Gi(e,t){return Fi===null&&Ui(e),Ki(e,t)}function Ki(e,t){var n=t._currentValue;if(t={context:t,memoizedValue:n,next:null},Ii===null){if(e===null)throw Error(i(308));Ii=t,e.dependencies={lanes:0,firstContext:t},e.flags|=524288}else Ii=Ii.next=t;return n}var qi=typeof AbortController<`u`?AbortController:function(){var e=[],t=this.signal={aborted:!1,addEventListener:function(t,n){e.push(n)}};this.abort=function(){t.aborted=!0,e.forEach(function(e){return e()})}},Ji=t.unstable_scheduleCallback,Yi=t.unstable_NormalPriority,Xi={$$typeof:b,Consumer:null,Provider:null,_currentValue:null,_currentValue2:null,_threadCount:0};function Zi(){return{controller:new qi,data:new Map,refCount:0}}function Qi(e){e.refCount--,e.refCount===0&&Ji(Yi,function(){e.controller.abort()})}var $i=null,ea=0,ta=0,na=null;function ra(e,t){if($i===null){var n=$i=[];ea=0,ta=dd(),na={status:`pending`,value:void 0,then:function(e){n.push(e)}}}return ea++,t.then(ia,ia),t}function ia(){if(--ea===0&&$i!==null){na!==null&&(na.status=`fulfilled`);var e=$i;$i=null,ta=0,na=null;for(var t=0;t<e.length;t++)(0,e[t])()}}function aa(e,t){var n=[],r={status:`pending`,value:null,reason:null,then:function(e){n.push(e)}};return e.then(function(){r.status=`fulfilled`,r.value=t;for(var e=0;e<n.length;e++)(0,n[e])(t)},function(e){for(r.status=`rejected`,r.reason=e,e=0;e<n.length;e++)(0,n[e])(void 0)}),r}var J=N.S;N.S=function(e,t){$l=he(),typeof t==`object`&&t&&typeof t.then==`function`&&ra(e,t),J!==null&&J(e,t)};var oa=R(null);function sa(){var e=oa.current;return e===null?Pl.pooledCache:e}function ca(e,t){t===null?B(oa,oa.current):B(oa,t.pool)}function la(){var e=sa();return e===null?null:{parent:Xi._currentValue,pool:e}}var ua=Error(i(460)),da=Error(i(474)),fa=Error(i(542)),pa={then:function(){}};function ma(e){return e=e.status,e===`fulfilled`||e===`rejected`}function ha(e,t,n){switch(n=e[n],n===void 0?e.push(t):n!==t&&(t.then(Ut,Ut),t=n),t.status){case`fulfilled`:return t.value;case`rejected`:throw e=t.reason,ya(e),e;default:if(typeof t.status==`string`)t.then(Ut,Ut);else{if(e=Pl,e!==null&&100<e.shellSuspendCounter)throw Error(i(482));e=t,e.status=`pending`,e.then(function(e){if(t.status===`pending`){var n=t;n.status=`fulfilled`,n.value=e}},function(e){if(t.status===`pending`){var n=t;n.status=`rejected`,n.reason=e}})}switch(t.status){case`fulfilled`:return t.value;case`rejected`:throw e=t.reason,ya(e),e}throw _a=t,ua}}function ga(e){try{var t=e._init;return t(e._payload)}catch(e){throw typeof e==`object`&&e&&typeof e.then==`function`?(_a=e,ua):e}}var _a=null;function va(){if(_a===null)throw Error(i(459));var e=_a;return _a=null,e}function ya(e){if(e===ua||e===fa)throw Error(i(483))}var ba=null,xa=0;function Sa(e){var t=xa;return xa+=1,ba===null&&(ba=[]),ha(ba,e,t)}function Ca(e,t){t=t.props.ref,e.ref=t===void 0?null:t}function wa(e,t){throw t.$$typeof===p?Error(i(525)):(e=Object.prototype.toString.call(t),Error(i(31,e===`[object Object]`?`object with keys {`+Object.keys(t).join(`, `)+`}`:e)))}function Ta(e){function t(t,n){if(e){var r=t.deletions;r===null?(t.deletions=[n],t.flags|=16):r.push(n)}}function n(n,r){if(!e)return null;for(;r!==null;)t(n,r),r=r.sibling;return null}function r(e){for(var t=new Map;e!==null;)e.key===null?t.set(e.index,e):t.set(e.key,e),e=e.sibling;return t}function a(e,t){return e=Qr(e,t),e.index=0,e.sibling=null,e}function o(t,n,r){return t.index=r,e?(r=t.alternate,r===null?(t.flags|=67108866,n):(r=r.index,r<n?(t.flags|=67108866,n):r)):(t.flags|=1048576,n)}function s(t){return e&&t.alternate===null&&(t.flags|=67108866),t}function c(e,t,n,r){return t===null||t.tag!==6?(t=ni(n,e.mode,r),t.return=e,t):(t=a(t,n),t.return=e,t)}function l(e,t,n,r){var i=n.type;return i===g?d(e,t,n.props.children,r,n.key):t!==null&&(t.elementType===i||typeof i==`object`&&i&&i.$$typeof===T&&ga(i)===t.type)?(t=a(t,n.props),Ca(t,n),t.return=e,t):(t=ei(n.type,n.key,n.props,null,e.mode,r),Ca(t,n),t.return=e,t)}function u(e,t,n,r){return t===null||t.tag!==4||t.stateNode.containerInfo!==n.containerInfo||t.stateNode.implementation!==n.implementation?(t=ii(n,e.mode,r),t.return=e,t):(t=a(t,n.children||[]),t.return=e,t)}function d(e,t,n,r,i){return t===null||t.tag!==7?(t=ti(n,e.mode,r,i),t.return=e,t):(t=a(t,n),t.return=e,t)}function f(e,t,n){if(typeof t==`string`&&t!==``||typeof t==`number`||typeof t==`bigint`)return t=ni(``+t,e.mode,n),t.return=e,t;if(typeof t==`object`&&t){switch(t.$$typeof){case m:return n=ei(t.type,t.key,t.props,null,e.mode,n),Ca(n,t),n.return=e,n;case h:return t=ii(t,e.mode,n),t.return=e,t;case T:return t=ga(t),f(e,t,n)}if(M(t)||k(t))return t=ti(t,e.mode,n,null),t.return=e,t;if(typeof t.then==`function`)return f(e,Sa(t),n);if(t.$$typeof===b)return f(e,Gi(e,t),n);wa(e,t)}return null}function p(e,t,n,r){var i=t===null?null:t.key;if(typeof n==`string`&&n!==``||typeof n==`number`||typeof n==`bigint`)return i===null?c(e,t,``+n,r):null;if(typeof n==`object`&&n){switch(n.$$typeof){case m:return n.key===i?l(e,t,n,r):null;case h:return n.key===i?u(e,t,n,r):null;case T:return n=ga(n),p(e,t,n,r)}if(M(n)||k(n))return i===null?d(e,t,n,r,null):null;if(typeof n.then==`function`)return p(e,t,Sa(n),r);if(n.$$typeof===b)return p(e,t,Gi(e,n),r);wa(e,n)}return null}function _(e,t,n,r,i){if(typeof r==`string`&&r!==``||typeof r==`number`||typeof r==`bigint`)return e=e.get(n)||null,c(t,e,``+r,i);if(typeof r==`object`&&r){switch(r.$$typeof){case m:return e=e.get(r.key===null?n:r.key)||null,l(t,e,r,i);case h:return e=e.get(r.key===null?n:r.key)||null,u(t,e,r,i);case T:return r=ga(r),_(e,t,n,r,i)}if(M(r)||k(r))return e=e.get(n)||null,d(t,e,r,i,null);if(typeof r.then==`function`)return _(e,t,n,Sa(r),i);if(r.$$typeof===b)return _(e,t,n,Gi(t,r),i);wa(t,r)}return null}function v(i,a,s,c){for(var l=null,u=null,d=a,m=a=0,h=null;d!==null&&m<s.length;m++){d.index>m?(h=d,d=null):h=d.sibling;var g=p(i,d,s[m],c);if(g===null){d===null&&(d=h);break}e&&d&&g.alternate===null&&t(i,d),a=o(g,a,m),u===null?l=g:u.sibling=g,u=g,d=h}if(m===s.length)return n(i,d),Ci&&gi(i,m),l;if(d===null){for(;m<s.length;m++)d=f(i,s[m],c),d!==null&&(a=o(d,a,m),u===null?l=d:u.sibling=d,u=d);return Ci&&gi(i,m),l}for(d=r(d);m<s.length;m++)h=_(d,i,m,s[m],c),h!==null&&(e&&h.alternate!==null&&d.delete(h.key===null?m:h.key),a=o(h,a,m),u===null?l=h:u.sibling=h,u=h);return e&&d.forEach(function(e){return t(i,e)}),Ci&&gi(i,m),l}function y(a,s,c,l){if(c==null)throw Error(i(151));for(var u=null,d=null,m=s,h=s=0,g=null,v=c.next();m!==null&&!v.done;h++,v=c.next()){m.index>h?(g=m,m=null):g=m.sibling;var y=p(a,m,v.value,l);if(y===null){m===null&&(m=g);break}e&&m&&y.alternate===null&&t(a,m),s=o(y,s,h),d===null?u=y:d.sibling=y,d=y,m=g}if(v.done)return n(a,m),Ci&&gi(a,h),u;if(m===null){for(;!v.done;h++,v=c.next())v=f(a,v.value,l),v!==null&&(s=o(v,s,h),d===null?u=v:d.sibling=v,d=v);return Ci&&gi(a,h),u}for(m=r(m);!v.done;h++,v=c.next())v=_(m,a,h,v.value,l),v!==null&&(e&&v.alternate!==null&&m.delete(v.key===null?h:v.key),s=o(v,s,h),d===null?u=v:d.sibling=v,d=v);return e&&m.forEach(function(e){return t(a,e)}),Ci&&gi(a,h),u}function x(e,r,o,c){if(typeof o==`object`&&o&&o.type===g&&o.key===null&&(o=o.props.children),typeof o==`object`&&o){switch(o.$$typeof){case m:a:{for(var l=o.key;r!==null;){if(r.key===l){if(l=o.type,l===g){if(r.tag===7){n(e,r.sibling),c=a(r,o.props.children),c.return=e,e=c;break a}}else if(r.elementType===l||typeof l==`object`&&l&&l.$$typeof===T&&ga(l)===r.type){n(e,r.sibling),c=a(r,o.props),Ca(c,o),c.return=e,e=c;break a}n(e,r);break}else t(e,r);r=r.sibling}o.type===g?(c=ti(o.props.children,e.mode,c,o.key),c.return=e,e=c):(c=ei(o.type,o.key,o.props,null,e.mode,c),Ca(c,o),c.return=e,e=c)}return s(e);case h:a:{for(l=o.key;r!==null;){if(r.key===l)if(r.tag===4&&r.stateNode.containerInfo===o.containerInfo&&r.stateNode.implementation===o.implementation){n(e,r.sibling),c=a(r,o.children||[]),c.return=e,e=c;break a}else{n(e,r);break}else t(e,r);r=r.sibling}c=ii(o,e.mode,c),c.return=e,e=c}return s(e);case T:return o=ga(o),x(e,r,o,c)}if(M(o))return v(e,r,o,c);if(k(o)){if(l=k(o),typeof l!=`function`)throw Error(i(150));return o=l.call(o),y(e,r,o,c)}if(typeof o.then==`function`)return x(e,r,Sa(o),c);if(o.$$typeof===b)return x(e,r,Gi(e,o),c);wa(e,o)}return typeof o==`string`&&o!==``||typeof o==`number`||typeof o==`bigint`?(o=``+o,r!==null&&r.tag===6?(n(e,r.sibling),c=a(r,o),c.return=e,e=c):(n(e,r),c=ni(o,e.mode,c),c.return=e,e=c),s(e)):n(e,r)}return function(e,t,n,r){try{xa=0;var i=x(e,t,n,r);return ba=null,i}catch(t){if(t===ua||t===fa)throw t;var a=Xr(29,t,null,e.mode);return a.lanes=r,a.return=e,a}}}var Ea=Ta(!0),Da=Ta(!1),Oa=!1;function ka(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,lanes:0,hiddenCallbacks:null},callbacks:null}}function Aa(e,t){e=e.updateQueue,t.updateQueue===e&&(t.updateQueue={baseState:e.baseState,firstBaseUpdate:e.firstBaseUpdate,lastBaseUpdate:e.lastBaseUpdate,shared:e.shared,callbacks:null})}function ja(e){return{lane:e,tag:0,payload:null,callback:null,next:null}}function Ma(e,t,n){var r=e.updateQueue;if(r===null)return null;if(r=r.shared,Nl&2){var i=r.pending;return i===null?t.next=t:(t.next=i.next,i.next=t),r.pending=t,t=qr(e),Kr(e,null,n),t}return Ur(e,r,t,n),qr(e)}function Na(e,t,n){if(t=t.updateQueue,t!==null&&(t=t.shared,n&4194048)){var r=t.lanes;r&=e.pendingLanes,n|=r,t.lanes=n,Ue(e,n)}}function Pa(e,t){var n=e.updateQueue,r=e.alternate;if(r!==null&&(r=r.updateQueue,n===r)){var i=null,a=null;if(n=n.firstBaseUpdate,n!==null){do{var o={lane:n.lane,tag:n.tag,payload:n.payload,callback:null,next:null};a===null?i=a=o:a=a.next=o,n=n.next}while(n!==null);a===null?i=a=t:a=a.next=t}else i=a=t;n={baseState:r.baseState,firstBaseUpdate:i,lastBaseUpdate:a,shared:r.shared,callbacks:r.callbacks},e.updateQueue=n;return}e=n.lastBaseUpdate,e===null?n.firstBaseUpdate=t:e.next=t,n.lastBaseUpdate=t}var Fa=!1;function Ia(){if(Fa){var e=na;if(e!==null)throw e}}function La(e,t,n,r){Fa=!1;var i=e.updateQueue;Oa=!1;var a=i.firstBaseUpdate,o=i.lastBaseUpdate,s=i.shared.pending;if(s!==null){i.shared.pending=null;var c=s,l=c.next;c.next=null,o===null?a=l:o.next=l,o=c;var u=e.alternate;u!==null&&(u=u.updateQueue,s=u.lastBaseUpdate,s!==o&&(s===null?u.firstBaseUpdate=l:s.next=l,u.lastBaseUpdate=c))}if(a!==null){var d=i.baseState;o=0,u=l=c=null,s=a;do{var p=s.lane&-536870913,m=p!==s.lane;if(m?(Il&p)===p:(r&p)===p){p!==0&&p===ta&&(Fa=!0),u!==null&&(u=u.next={lane:0,tag:s.tag,payload:s.payload,callback:null,next:null});a:{var h=e,g=s;p=t;var _=n;switch(g.tag){case 1:if(h=g.payload,typeof h==`function`){d=h.call(_,d,p);break a}d=h;break a;case 3:h.flags=h.flags&-65537|128;case 0:if(h=g.payload,p=typeof h==`function`?h.call(_,d,p):h,p==null)break a;d=f({},d,p);break a;case 2:Oa=!0}}p=s.callback,p!==null&&(e.flags|=64,m&&(e.flags|=8192),m=i.callbacks,m===null?i.callbacks=[p]:m.push(p))}else m={lane:p,tag:s.tag,payload:s.payload,callback:s.callback,next:null},u===null?(l=u=m,c=d):u=u.next=m,o|=p;if(s=s.next,s===null){if(s=i.shared.pending,s===null)break;m=s,s=m.next,m.next=null,i.lastBaseUpdate=m,i.shared.pending=null}}while(1);u===null&&(c=d),i.baseState=c,i.firstBaseUpdate=l,i.lastBaseUpdate=u,a===null&&(i.shared.lanes=0),Wl|=o,e.lanes=o,e.memoizedState=d}}function Ra(e,t){if(typeof e!=`function`)throw Error(i(191,e));e.call(t)}function za(e,t){var n=e.callbacks;if(n!==null)for(e.callbacks=null,e=0;e<n.length;e++)Ra(n[e],t)}var Ba=R(null),Va=R(0);function Ha(e,t){e=Hl,B(Va,e),B(Ba,t),Hl=e|t.baseLanes}function Ua(){B(Va,Hl),B(Ba,Ba.current)}function Wa(){Hl=Va.current,z(Ba),z(Va)}var Ga=R(null),Ka=null;function qa(e){var t=e.alternate;B(Qa,Qa.current&1),B(Ga,e),Ka===null&&(t===null||Ba.current!==null||t.memoizedState!==null)&&(Ka=e)}function Ja(e){B(Qa,Qa.current),B(Ga,e),Ka===null&&(Ka=e)}function Ya(e){e.tag===22?(B(Qa,Qa.current),B(Ga,e),Ka===null&&(Ka=e)):Xa(e)}function Xa(){B(Qa,Qa.current),B(Ga,Ga.current)}function Za(e){z(Ga),Ka===e&&(Ka=null),z(Qa)}var Qa=R(0);function $a(e){for(var t=e;t!==null;){if(t.tag===13){var n=t.memoizedState;if(n!==null&&(n=n.dehydrated,n===null||sf(n)||cf(n)))return t}else if(t.tag===19&&(t.memoizedProps.revealOrder===`forwards`||t.memoizedProps.revealOrder===`backwards`||t.memoizedProps.revealOrder===`unstable_legacy-backwards`||t.memoizedProps.revealOrder===`together`)){if(t.flags&128)return t}else if(t.child!==null){t.child.return=t,t=t.child;continue}if(t===e)break;for(;t.sibling===null;){if(t.return===null||t.return===e)return null;t=t.return}t.sibling.return=t.return,t=t.sibling}return null}var eo=0,to=null,no=null,ro=null,io=!1,ao=!1,oo=!1,so=0,co=0,lo=null,uo=0;function fo(){throw Error(i(321))}function po(e,t){if(t===null)return!1;for(var n=0;n<t.length&&n<e.length;n++)if(!dr(e[n],t[n]))return!1;return!0}function mo(e,t,n,r,i,a){return eo=a,to=t,t.memoizedState=null,t.updateQueue=null,t.lanes=0,N.H=e===null||e.memoizedState===null?js:Ms,oo=!1,a=n(r,i),oo=!1,ao&&(a=go(t,n,r,i)),ho(e),a}function ho(e){N.H=As;var t=no!==null&&no.next!==null;if(eo=0,ro=no=to=null,io=!1,co=0,lo=null,t)throw Error(i(300));e===null||Ys||(e=e.dependencies,e!==null&&Hi(e)&&(Ys=!0))}function go(e,t,n,r){to=e;var a=0;do{if(ao&&(lo=null),co=0,ao=!1,25<=a)throw Error(i(301));if(a+=1,ro=no=null,e.updateQueue!=null){var o=e.updateQueue;o.lastEffect=null,o.events=null,o.stores=null,o.memoCache!=null&&(o.memoCache.index=0)}N.H=Ns,o=t(n,r)}while(ao);return o}function _o(){var e=N.H,t=e.useState()[0];return t=typeof t.then==`function`?wo(t):t,e=e.useState()[0],(no===null?null:no.memoizedState)!==e&&(to.flags|=1024),t}function vo(){var e=so!==0;return so=0,e}function yo(e,t,n){t.updateQueue=e.updateQueue,t.flags&=-2053,e.lanes&=~n}function bo(e){if(io){for(e=e.memoizedState;e!==null;){var t=e.queue;t!==null&&(t.pending=null),e=e.next}io=!1}eo=0,ro=no=to=null,ao=!1,co=so=0,lo=null}function xo(){var e={memoizedState:null,baseState:null,baseQueue:null,queue:null,next:null};return ro===null?to.memoizedState=ro=e:ro=ro.next=e,ro}function So(){if(no===null){var e=to.alternate;e=e===null?null:e.memoizedState}else e=no.next;var t=ro===null?to.memoizedState:ro.next;if(t!==null)ro=t,no=e;else{if(e===null)throw to.alternate===null?Error(i(467)):Error(i(310));no=e,e={memoizedState:no.memoizedState,baseState:no.baseState,baseQueue:no.baseQueue,queue:no.queue,next:null},ro===null?to.memoizedState=ro=e:ro=ro.next=e}return ro}function Co(){return{lastEffect:null,events:null,stores:null,memoCache:null}}function wo(e){var t=co;return co+=1,lo===null&&(lo=[]),e=ha(lo,e,t),t=to,(ro===null?t.memoizedState:ro.next)===null&&(t=t.alternate,N.H=t===null||t.memoizedState===null?js:Ms),e}function To(e){if(typeof e==`object`&&e){if(typeof e.then==`function`)return wo(e);if(e.$$typeof===b)return Wi(e)}throw Error(i(438,String(e)))}function Eo(e){var t=null,n=to.updateQueue;if(n!==null&&(t=n.memoCache),t==null){var r=to.alternate;r!==null&&(r=r.updateQueue,r!==null&&(r=r.memoCache,r!=null&&(t={data:r.data.map(function(e){return e.slice()}),index:0})))}if(t??={data:[],index:0},n===null&&(n=Co(),to.updateQueue=n),n.memoCache=t,n=t.data[t.index],n===void 0)for(n=t.data[t.index]=Array(e),r=0;r<e;r++)n[r]=D;return t.index++,n}function Do(e,t){return typeof t==`function`?t(e):t}function Oo(e){return ko(So(),no,e)}function ko(e,t,n){var r=e.queue;if(r===null)throw Error(i(311));r.lastRenderedReducer=n;var a=e.baseQueue,o=r.pending;if(o!==null){if(a!==null){var s=a.next;a.next=o.next,o.next=s}t.baseQueue=a=o,r.pending=null}if(o=e.baseState,a===null)e.memoizedState=o;else{t=a.next;var c=s=null,l=null,u=t,d=!1;do{var f=u.lane&-536870913;if(f===u.lane?(eo&f)===f:(Il&f)===f){var p=u.revertLane;if(p===0)l!==null&&(l=l.next={lane:0,revertLane:0,gesture:null,action:u.action,hasEagerState:u.hasEagerState,eagerState:u.eagerState,next:null}),f===ta&&(d=!0);else if((eo&p)===p){u=u.next,p===ta&&(d=!0);continue}else f={lane:0,revertLane:u.revertLane,gesture:null,action:u.action,hasEagerState:u.hasEagerState,eagerState:u.eagerState,next:null},l===null?(c=l=f,s=o):l=l.next=f,to.lanes|=p,Wl|=p;f=u.action,oo&&n(o,f),o=u.hasEagerState?u.eagerState:n(o,f)}else p={lane:f,revertLane:u.revertLane,gesture:u.gesture,action:u.action,hasEagerState:u.hasEagerState,eagerState:u.eagerState,next:null},l===null?(c=l=p,s=o):l=l.next=p,to.lanes|=f,Wl|=f;u=u.next}while(u!==null&&u!==t);if(l===null?s=o:l.next=c,!dr(o,e.memoizedState)&&(Ys=!0,d&&(n=na,n!==null)))throw n;e.memoizedState=o,e.baseState=s,e.baseQueue=l,r.lastRenderedState=o}return a===null&&(r.lanes=0),[e.memoizedState,r.dispatch]}function Ao(e){var t=So(),n=t.queue;if(n===null)throw Error(i(311));n.lastRenderedReducer=e;var r=n.dispatch,a=n.pending,o=t.memoizedState;if(a!==null){n.pending=null;var s=a=a.next;do o=e(o,s.action),s=s.next;while(s!==a);dr(o,t.memoizedState)||(Ys=!0),t.memoizedState=o,t.baseQueue===null&&(t.baseState=o),n.lastRenderedState=o}return[o,r]}function jo(e,t,n){var r=to,a=So(),o=Ci;if(o){if(n===void 0)throw Error(i(407));n=n()}else n=t();var s=!dr((no||a).memoizedState,n);if(s&&(a.memoizedState=n,Ys=!0),a=a.queue,ns(Po.bind(null,r,a,e),[e]),a.getSnapshot!==t||s||ro!==null&&ro.memoizedState.tag&1){if(r.flags|=2048,Zo(9,{destroy:void 0},No.bind(null,r,a,n,t),null),Pl===null)throw Error(i(349));o||eo&127||Mo(r,t,n)}return n}function Mo(e,t,n){e.flags|=16384,e={getSnapshot:t,value:n},t=to.updateQueue,t===null?(t=Co(),to.updateQueue=t,t.stores=[e]):(n=t.stores,n===null?t.stores=[e]:n.push(e))}function No(e,t,n,r){t.value=n,t.getSnapshot=r,Fo(t)&&Io(e)}function Po(e,t,n){return n(function(){Fo(t)&&Io(e)})}function Fo(e){var t=e.getSnapshot;e=e.value;try{var n=t();return!dr(e,n)}catch{return!0}}function Io(e){var t=Gr(e,2);t!==null&&mu(t,e,2)}function Lo(e){var t=xo();if(typeof e==`function`){var n=e;if(e=n(),oo){Ee(!0);try{n()}finally{Ee(!1)}}}return t.memoizedState=t.baseState=e,t.queue={pending:null,lanes:0,dispatch:null,lastRenderedReducer:Do,lastRenderedState:e},t}function Ro(e,t,n,r){return e.baseState=n,ko(e,no,typeof r==`function`?r:Do)}function zo(e,t,n,r,a){if(Ds(e))throw Error(i(485));if(e=t.action,e!==null){var o={payload:a,action:e,next:null,isTransition:!0,status:`pending`,value:null,reason:null,listeners:[],then:function(e){o.listeners.push(e)}};N.T===null?o.isTransition=!1:n(!0),r(o),n=t.pending,n===null?(o.next=t.pending=o,Bo(t,o)):(o.next=n.next,t.pending=n.next=o)}}function Bo(e,t){var n=t.action,r=t.payload,i=e.state;if(t.isTransition){var a=N.T,o={};N.T=o;try{var s=n(i,r),c=N.S;c!==null&&c(o,s),Vo(e,t,s)}catch(n){Uo(e,t,n)}finally{a!==null&&o.types!==null&&(a.types=o.types),N.T=a}}else try{a=n(i,r),Vo(e,t,a)}catch(n){Uo(e,t,n)}}function Vo(e,t,n){typeof n==`object`&&n&&typeof n.then==`function`?n.then(function(n){Ho(e,t,n)},function(n){return Uo(e,t,n)}):Ho(e,t,n)}function Ho(e,t,n){t.status=`fulfilled`,t.value=n,Wo(t),e.state=n,t=e.pending,t!==null&&(n=t.next,n===t?e.pending=null:(n=n.next,t.next=n,Bo(e,n)))}function Uo(e,t,n){var r=e.pending;if(e.pending=null,r!==null){r=r.next;do t.status=`rejected`,t.reason=n,Wo(t),t=t.next;while(t!==r)}e.action=null}function Wo(e){e=e.listeners;for(var t=0;t<e.length;t++)(0,e[t])()}function Go(e,t){return t}function Ko(e,t){if(Ci){var n=Pl.formState;if(n!==null){a:{var r=to;if(Ci){if(Si){b:{for(var i=Si,a=Ti;i.nodeType!==8;){if(!a){i=null;break b}if(i=uf(i.nextSibling),i===null){i=null;break b}}a=i.data,i=a===`F!`||a===`F`?i:null}if(i){Si=uf(i.nextSibling),r=i.data===`F!`;break a}}Di(r)}r=!1}r&&(t=n[0])}}return n=xo(),n.memoizedState=n.baseState=t,r={pending:null,lanes:0,dispatch:null,lastRenderedReducer:Go,lastRenderedState:t},n.queue=r,n=ws.bind(null,to,r),r.dispatch=n,r=Lo(!1),a=Es.bind(null,to,!1,r.queue),r=xo(),i={state:t,dispatch:null,action:e,pending:null},r.queue=i,n=zo.bind(null,to,i,a,n),i.dispatch=n,r.memoizedState=e,[t,n,!1]}function qo(e){return Jo(So(),no,e)}function Jo(e,t,n){if(t=ko(e,t,Go)[0],e=Oo(Do)[0],typeof t==`object`&&t&&typeof t.then==`function`)try{var r=wo(t)}catch(e){throw e===ua?fa:e}else r=t;t=So();var i=t.queue,a=i.dispatch;return n!==t.memoizedState&&(to.flags|=2048,Zo(9,{destroy:void 0},Yo.bind(null,i,n),null)),[r,a,e]}function Yo(e,t){e.action=t}function Xo(e){var t=So(),n=no;if(n!==null)return Jo(t,n,e);So(),t=t.memoizedState,n=So();var r=n.queue.dispatch;return n.memoizedState=e,[t,r,!1]}function Zo(e,t,n,r){return e={tag:e,create:n,deps:r,inst:t,next:null},t=to.updateQueue,t===null&&(t=Co(),to.updateQueue=t),n=t.lastEffect,n===null?t.lastEffect=e.next=e:(r=n.next,n.next=e,e.next=r,t.lastEffect=e),e}function Qo(){return So().memoizedState}function $o(e,t,n,r){var i=xo();to.flags|=e,i.memoizedState=Zo(1|t,{destroy:void 0},n,r===void 0?null:r)}function es(e,t,n,r){var i=So();r=r===void 0?null:r;var a=i.memoizedState.inst;no!==null&&r!==null&&po(r,no.memoizedState.deps)?i.memoizedState=Zo(t,a,n,r):(to.flags|=e,i.memoizedState=Zo(1|t,a,n,r))}function ts(e,t){$o(8390656,8,e,t)}function ns(e,t){es(2048,8,e,t)}function rs(e){to.flags|=4;var t=to.updateQueue;if(t===null)t=Co(),to.updateQueue=t,t.events=[e];else{var n=t.events;n===null?t.events=[e]:n.push(e)}}function is(e){var t=So().memoizedState;return rs({ref:t,nextImpl:e}),function(){if(Nl&2)throw Error(i(440));return t.impl.apply(void 0,arguments)}}function as(e,t){return es(4,2,e,t)}function os(e,t){return es(4,4,e,t)}function ss(e,t){if(typeof t==`function`){e=e();var n=t(e);return function(){typeof n==`function`?n():t(null)}}if(t!=null)return e=e(),t.current=e,function(){t.current=null}}function cs(e,t,n){n=n==null?null:n.concat([e]),es(4,4,ss.bind(null,t,e),n)}function ls(){}function us(e,t){var n=So();t=t===void 0?null:t;var r=n.memoizedState;return t!==null&&po(t,r[1])?r[0]:(n.memoizedState=[e,t],e)}function ds(e,t){var n=So();t=t===void 0?null:t;var r=n.memoizedState;if(t!==null&&po(t,r[1]))return r[0];if(r=e(),oo){Ee(!0);try{e()}finally{Ee(!1)}}return n.memoizedState=[r,t],r}function fs(e,t,n){return n===void 0||eo&1073741824&&!(Il&261930)?e.memoizedState=t:(e.memoizedState=n,e=pu(),to.lanes|=e,Wl|=e,n)}function ps(e,t,n,r){return dr(n,t)?n:Ba.current===null?!(eo&42)||eo&1073741824&&!(Il&261930)?(Ys=!0,e.memoizedState=n):(e=pu(),to.lanes|=e,Wl|=e,t):(e=fs(e,n,r),dr(e,t)||(Ys=!0),e)}function ms(e,t,n,r,i){var a=P.p;P.p=a!==0&&8>a?a:8;var o=N.T,s={};N.T=s,Es(e,!1,t,n);try{var c=i(),l=N.S;l!==null&&l(s,c),typeof c==`object`&&c&&typeof c.then==`function`?Ts(e,t,aa(c,r),fu(e)):Ts(e,t,r,fu(e))}catch(n){Ts(e,t,{then:function(){},status:`rejected`,reason:n},fu())}finally{P.p=a,o!==null&&s.types!==null&&(o.types=s.types),N.T=o}}function hs(){}function gs(e,t,n,r){if(e.tag!==5)throw Error(i(476));var a=_s(e).queue;ms(e,a,t,F,n===null?hs:function(){return vs(e),n(r)})}function _s(e){var t=e.memoizedState;if(t!==null)return t;t={memoizedState:F,baseState:F,baseQueue:null,queue:{pending:null,lanes:0,dispatch:null,lastRenderedReducer:Do,lastRenderedState:F},next:null};var n={};return t.next={memoizedState:n,baseState:n,baseQueue:null,queue:{pending:null,lanes:0,dispatch:null,lastRenderedReducer:Do,lastRenderedState:n},next:null},e.memoizedState=t,e=e.alternate,e!==null&&(e.memoizedState=t),t}function vs(e){var t=_s(e);t.next===null&&(t=e.alternate.memoizedState),Ts(e,t.next.queue,{},fu())}function ys(){return Wi(ep)}function bs(){return So().memoizedState}function xs(){return So().memoizedState}function Ss(e){for(var t=e.return;t!==null;){switch(t.tag){case 24:case 3:var n=fu();e=ja(n);var r=Ma(t,e,n);r!==null&&(mu(r,t,n),Na(r,t,n)),t={cache:Zi()},e.payload=t;return}t=t.return}}function Cs(e,t,n){var r=fu();n={lane:r,revertLane:0,gesture:null,action:n,hasEagerState:!1,eagerState:null,next:null},Ds(e)?Os(t,n):(n=Wr(e,t,n,r),n!==null&&(mu(n,e,r),ks(n,t,r)))}function ws(e,t,n){Ts(e,t,n,fu())}function Ts(e,t,n,r){var i={lane:r,revertLane:0,gesture:null,action:n,hasEagerState:!1,eagerState:null,next:null};if(Ds(e))Os(t,i);else{var a=e.alternate;if(e.lanes===0&&(a===null||a.lanes===0)&&(a=t.lastRenderedReducer,a!==null))try{var o=t.lastRenderedState,s=a(o,n);if(i.hasEagerState=!0,i.eagerState=s,dr(s,o))return Ur(e,t,i,0),Pl===null&&Hr(),!1}catch{}if(n=Wr(e,t,i,r),n!==null)return mu(n,e,r),ks(n,t,r),!0}return!1}function Es(e,t,n,r){if(r={lane:2,revertLane:dd(),gesture:null,action:r,hasEagerState:!1,eagerState:null,next:null},Ds(e)){if(t)throw Error(i(479))}else t=Wr(e,n,r,2),t!==null&&mu(t,e,2)}function Ds(e){var t=e.alternate;return e===to||t!==null&&t===to}function Os(e,t){ao=io=!0;var n=e.pending;n===null?t.next=t:(t.next=n.next,n.next=t),e.pending=t}function ks(e,t,n){if(n&4194048){var r=t.lanes;r&=e.pendingLanes,n|=r,t.lanes=n,Ue(e,n)}}var As={readContext:Wi,use:To,useCallback:fo,useContext:fo,useEffect:fo,useImperativeHandle:fo,useLayoutEffect:fo,useInsertionEffect:fo,useMemo:fo,useReducer:fo,useRef:fo,useState:fo,useDebugValue:fo,useDeferredValue:fo,useTransition:fo,useSyncExternalStore:fo,useId:fo,useHostTransitionStatus:fo,useFormState:fo,useActionState:fo,useOptimistic:fo,useMemoCache:fo,useCacheRefresh:fo};As.useEffectEvent=fo;var js={readContext:Wi,use:To,useCallback:function(e,t){return xo().memoizedState=[e,t===void 0?null:t],e},useContext:Wi,useEffect:ts,useImperativeHandle:function(e,t,n){n=n==null?null:n.concat([e]),$o(4194308,4,ss.bind(null,t,e),n)},useLayoutEffect:function(e,t){return $o(4194308,4,e,t)},useInsertionEffect:function(e,t){$o(4,2,e,t)},useMemo:function(e,t){var n=xo();t=t===void 0?null:t;var r=e();if(oo){Ee(!0);try{e()}finally{Ee(!1)}}return n.memoizedState=[r,t],r},useReducer:function(e,t,n){var r=xo();if(n!==void 0){var i=n(t);if(oo){Ee(!0);try{n(t)}finally{Ee(!1)}}}else i=t;return r.memoizedState=r.baseState=i,e={pending:null,lanes:0,dispatch:null,lastRenderedReducer:e,lastRenderedState:i},r.queue=e,e=e.dispatch=Cs.bind(null,to,e),[r.memoizedState,e]},useRef:function(e){var t=xo();return e={current:e},t.memoizedState=e},useState:function(e){e=Lo(e);var t=e.queue,n=ws.bind(null,to,t);return t.dispatch=n,[e.memoizedState,n]},useDebugValue:ls,useDeferredValue:function(e,t){return fs(xo(),e,t)},useTransition:function(){var e=Lo(!1);return e=ms.bind(null,to,e.queue,!0,!1),xo().memoizedState=e,[!1,e]},useSyncExternalStore:function(e,t,n){var r=to,a=xo();if(Ci){if(n===void 0)throw Error(i(407));n=n()}else{if(n=t(),Pl===null)throw Error(i(349));Il&127||Mo(r,t,n)}a.memoizedState=n;var o={value:n,getSnapshot:t};return a.queue=o,ts(Po.bind(null,r,o,e),[e]),r.flags|=2048,Zo(9,{destroy:void 0},No.bind(null,r,o,n,t),null),n},useId:function(){var e=xo(),t=Pl.identifierPrefix;if(Ci){var n=hi,r=mi;n=(r&~(1<<32-De(r)-1)).toString(32)+n,t=`_`+t+`R_`+n,n=so++,0<n&&(t+=`H`+n.toString(32)),t+=`_`}else n=uo++,t=`_`+t+`r_`+n.toString(32)+`_`;return e.memoizedState=t},useHostTransitionStatus:ys,useFormState:Ko,useActionState:Ko,useOptimistic:function(e){var t=xo();t.memoizedState=t.baseState=e;var n={pending:null,lanes:0,dispatch:null,lastRenderedReducer:null,lastRenderedState:null};return t.queue=n,t=Es.bind(null,to,!0,n),n.dispatch=t,[e,t]},useMemoCache:Eo,useCacheRefresh:function(){return xo().memoizedState=Ss.bind(null,to)},useEffectEvent:function(e){var t=xo(),n={impl:e};return t.memoizedState=n,function(){if(Nl&2)throw Error(i(440));return n.impl.apply(void 0,arguments)}}},Ms={readContext:Wi,use:To,useCallback:us,useContext:Wi,useEffect:ns,useImperativeHandle:cs,useInsertionEffect:as,useLayoutEffect:os,useMemo:ds,useReducer:Oo,useRef:Qo,useState:function(){return Oo(Do)},useDebugValue:ls,useDeferredValue:function(e,t){return ps(So(),no.memoizedState,e,t)},useTransition:function(){var e=Oo(Do)[0],t=So().memoizedState;return[typeof e==`boolean`?e:wo(e),t]},useSyncExternalStore:jo,useId:bs,useHostTransitionStatus:ys,useFormState:qo,useActionState:qo,useOptimistic:function(e,t){return Ro(So(),no,e,t)},useMemoCache:Eo,useCacheRefresh:xs};Ms.useEffectEvent=is;var Ns={readContext:Wi,use:To,useCallback:us,useContext:Wi,useEffect:ns,useImperativeHandle:cs,useInsertionEffect:as,useLayoutEffect:os,useMemo:ds,useReducer:Ao,useRef:Qo,useState:function(){return Ao(Do)},useDebugValue:ls,useDeferredValue:function(e,t){var n=So();return no===null?fs(n,e,t):ps(n,no.memoizedState,e,t)},useTransition:function(){var e=Ao(Do)[0],t=So().memoizedState;return[typeof e==`boolean`?e:wo(e),t]},useSyncExternalStore:jo,useId:bs,useHostTransitionStatus:ys,useFormState:Xo,useActionState:Xo,useOptimistic:function(e,t){var n=So();return no===null?(n.baseState=e,[e,n.queue.dispatch]):Ro(n,no,e,t)},useMemoCache:Eo,useCacheRefresh:xs};Ns.useEffectEvent=is;function Ps(e,t,n,r){t=e.memoizedState,n=n(r,t),n=n==null?t:f({},t,n),e.memoizedState=n,e.lanes===0&&(e.updateQueue.baseState=n)}var Fs={enqueueSetState:function(e,t,n){e=e._reactInternals;var r=fu(),i=ja(r);i.payload=t,n!=null&&(i.callback=n),t=Ma(e,i,r),t!==null&&(mu(t,e,r),Na(t,e,r))},enqueueReplaceState:function(e,t,n){e=e._reactInternals;var r=fu(),i=ja(r);i.tag=1,i.payload=t,n!=null&&(i.callback=n),t=Ma(e,i,r),t!==null&&(mu(t,e,r),Na(t,e,r))},enqueueForceUpdate:function(e,t){e=e._reactInternals;var n=fu(),r=ja(n);r.tag=2,t!=null&&(r.callback=t),t=Ma(e,r,n),t!==null&&(mu(t,e,n),Na(t,e,n))}};function Is(e,t,n,r,i,a,o){return e=e.stateNode,typeof e.shouldComponentUpdate==`function`?e.shouldComponentUpdate(r,a,o):t.prototype&&t.prototype.isPureReactComponent?!fr(n,r)||!fr(i,a):!0}function Ls(e,t,n,r){e=t.state,typeof t.componentWillReceiveProps==`function`&&t.componentWillReceiveProps(n,r),typeof t.UNSAFE_componentWillReceiveProps==`function`&&t.UNSAFE_componentWillReceiveProps(n,r),t.state!==e&&Fs.enqueueReplaceState(t,t.state,null)}function Rs(e,t){var n=t;if(`ref`in t)for(var r in n={},t)r!==`ref`&&(n[r]=t[r]);if(e=e.defaultProps)for(var i in n===t&&(n=f({},n)),e)n[i]===void 0&&(n[i]=e[i]);return n}function zs(e){Rr(e)}function Bs(e){console.error(e)}function Vs(e){Rr(e)}function Hs(e,t){try{var n=e.onUncaughtError;n(t.value,{componentStack:t.stack})}catch(e){setTimeout(function(){throw e})}}function Us(e,t,n){try{var r=e.onCaughtError;r(n.value,{componentStack:n.stack,errorBoundary:t.tag===1?t.stateNode:null})}catch(e){setTimeout(function(){throw e})}}function Ws(e,t,n){return n=ja(n),n.tag=3,n.payload={element:null},n.callback=function(){Hs(e,t)},n}function Gs(e){return e=ja(e),e.tag=3,e}function Ks(e,t,n,r){var i=n.type.getDerivedStateFromError;if(typeof i==`function`){var a=r.value;e.payload=function(){return i(a)},e.callback=function(){Us(t,n,r)}}var o=n.stateNode;o!==null&&typeof o.componentDidCatch==`function`&&(e.callback=function(){Us(t,n,r),typeof i!=`function`&&(nu===null?nu=new Set([this]):nu.add(this));var e=r.stack;this.componentDidCatch(r.value,{componentStack:e===null?``:e})})}function qs(e,t,n,r,a){if(n.flags|=32768,typeof r==`object`&&r&&typeof r.then==`function`){if(t=n.alternate,t!==null&&Vi(t,n,a,!0),n=Ga.current,n!==null){switch(n.tag){case 31:case 13:return Ka===null?Eu():n.alternate===null&&Ul===0&&(Ul=3),n.flags&=-257,n.flags|=65536,n.lanes=a,r===pa?n.flags|=16384:(t=n.updateQueue,t===null?n.updateQueue=new Set([r]):t.add(r),Gu(e,r,a)),!1;case 22:return n.flags|=65536,r===pa?n.flags|=16384:(t=n.updateQueue,t===null?(t={transitions:null,markerInstances:null,retryQueue:new Set([r])},n.updateQueue=t):(n=t.retryQueue,n===null?t.retryQueue=new Set([r]):n.add(r)),Gu(e,r,a)),!1}throw Error(i(435,n.tag))}return Gu(e,r,a),Eu(),!1}if(Ci)return t=Ga.current,t===null?(r!==Ei&&(t=Error(i(423),{cause:r}),Ni(oi(t,n))),e=e.current.alternate,e.flags|=65536,a&=-a,e.lanes|=a,r=oi(r,n),a=Ws(e.stateNode,r,a),Pa(e,a),Ul!==4&&(Ul=2)):(!(t.flags&65536)&&(t.flags|=256),t.flags|=65536,t.lanes=a,r!==Ei&&(e=Error(i(422),{cause:r}),Ni(oi(e,n)))),!1;var o=Error(i(520),{cause:r});if(o=oi(o,n),Yl===null?Yl=[o]:Yl.push(o),Ul!==4&&(Ul=2),t===null)return!0;r=oi(r,n),n=t;do{switch(n.tag){case 3:return n.flags|=65536,e=a&-a,n.lanes|=e,e=Ws(n.stateNode,r,e),Pa(n,e),!1;case 1:if(t=n.type,o=n.stateNode,!(n.flags&128)&&(typeof t.getDerivedStateFromError==`function`||o!==null&&typeof o.componentDidCatch==`function`&&(nu===null||!nu.has(o))))return n.flags|=65536,a&=-a,n.lanes|=a,a=Gs(a),Ks(a,e,n,r),Pa(n,a),!1}n=n.return}while(n!==null);return!1}var Js=Error(i(461)),Ys=!1;function Xs(e,t,n,r){t.child=e===null?Da(t,null,n,r):Ea(t,e.child,n,r)}function Zs(e,t,n,r,i){n=n.render;var a=t.ref;if(`ref`in r){var o={};for(var s in r)s!==`ref`&&(o[s]=r[s])}else o=r;return Ui(t),r=mo(e,t,n,o,a,i),s=vo(),e!==null&&!Ys?(yo(e,t,i),xc(e,t,i)):(Ci&&s&&vi(t),t.flags|=1,Xs(e,t,r,i),t.child)}function Qs(e,t,n,r,i){if(e===null){var a=n.type;return typeof a==`function`&&!Zr(a)&&a.defaultProps===void 0&&n.compare===null?(t.tag=15,t.type=a,$s(e,t,a,r,i)):(e=ei(n.type,null,r,t,t.mode,i),e.ref=t.ref,e.return=t,t.child=e)}if(a=e.child,!Sc(e,i)){var o=a.memoizedProps;if(n=n.compare,n=n===null?fr:n,n(o,r)&&e.ref===t.ref)return xc(e,t,i)}return t.flags|=1,e=Qr(a,r),e.ref=t.ref,e.return=t,t.child=e}function $s(e,t,n,r,i){if(e!==null){var a=e.memoizedProps;if(fr(a,r)&&e.ref===t.ref)if(Ys=!1,t.pendingProps=r=a,Sc(e,i))e.flags&131072&&(Ys=!0);else return t.lanes=e.lanes,xc(e,t,i)}return sc(e,t,n,r,i)}function ec(e,t,n,r){var i=r.children,a=e===null?null:e.memoizedState;if(e===null&&t.stateNode===null&&(t.stateNode={_visibility:1,_pendingMarkers:null,_retryCache:null,_transitions:null}),r.mode===`hidden`){if(t.flags&128){if(a=a===null?n:a.baseLanes|n,e!==null){for(r=t.child=e.child,i=0;r!==null;)i=i|r.lanes|r.childLanes,r=r.sibling;r=i&~a}else r=0,t.child=null;return nc(e,t,a,n,r)}if(n&536870912)t.memoizedState={baseLanes:0,cachePool:null},e!==null&&ca(t,a===null?null:a.cachePool),a===null?Ua():Ha(t,a),Ya(t);else return r=t.lanes=536870912,nc(e,t,a===null?n:a.baseLanes|n,n,r)}else a===null?(e!==null&&ca(t,null),Ua(),Xa(t)):(ca(t,a.cachePool),Ha(t,a),Xa(t),t.memoizedState=null);return Xs(e,t,i,n),t.child}function tc(e,t){return e!==null&&e.tag===22||t.stateNode!==null||(t.stateNode={_visibility:1,_pendingMarkers:null,_retryCache:null,_transitions:null}),t.sibling}function nc(e,t,n,r,i){var a=sa();return a=a===null?null:{parent:Xi._currentValue,pool:a},t.memoizedState={baseLanes:n,cachePool:a},e!==null&&ca(t,null),Ua(),Ya(t),e!==null&&Vi(e,t,r,!0),t.childLanes=i,null}function rc(e,t){return t=gc({mode:t.mode,children:t.children},e.mode),t.ref=e.ref,e.child=t,t.return=e,t}function ic(e,t,n){return Ea(t,e.child,null,n),e=rc(t,t.pendingProps),e.flags|=2,Za(t),t.memoizedState=null,e}function ac(e,t,n){var r=t.pendingProps,a=(t.flags&128)!=0;if(t.flags&=-129,e===null){if(Ci){if(r.mode===`hidden`)return e=rc(t,r),t.lanes=536870912,tc(null,e);if(Ja(t),(e=Si)?(e=of(e,Ti),e=e!==null&&e.data===`&`?e:null,e!==null&&(t.memoizedState={dehydrated:e,treeContext:pi===null?null:{id:mi,overflow:hi},retryLane:536870912,hydrationErrors:null},n=ri(e),n.return=t,t.child=n,xi=t,Si=null)):e=null,e===null)throw Di(t);return t.lanes=536870912,null}return rc(t,r)}var o=e.memoizedState;if(o!==null){var s=o.dehydrated;if(Ja(t),a)if(t.flags&256)t.flags&=-257,t=ic(e,t,n);else if(t.memoizedState!==null)t.child=e.child,t.flags|=128,t=null;else throw Error(i(558));else if(Ys||Vi(e,t,n,!1),a=(n&e.childLanes)!==0,Ys||a){if(r=Pl,r!==null&&(s=We(r,n),s!==0&&s!==o.retryLane))throw o.retryLane=s,Gr(e,s),mu(r,e,s),Js;Eu(),t=ic(e,t,n)}else e=o.treeContext,Si=uf(s.nextSibling),xi=t,Ci=!0,wi=null,Ti=!1,e!==null&&bi(t,e),t=rc(t,r),t.flags|=4096;return t}return e=Qr(e.child,{mode:r.mode,children:r.children}),e.ref=t.ref,t.child=e,e.return=t,e}function oc(e,t){var n=t.ref;if(n===null)e!==null&&e.ref!==null&&(t.flags|=4194816);else{if(typeof n!=`function`&&typeof n!=`object`)throw Error(i(284));(e===null||e.ref!==n)&&(t.flags|=4194816)}}function sc(e,t,n,r,i){return Ui(t),n=mo(e,t,n,r,void 0,i),r=vo(),e!==null&&!Ys?(yo(e,t,i),xc(e,t,i)):(Ci&&r&&vi(t),t.flags|=1,Xs(e,t,n,i),t.child)}function cc(e,t,n,r,i,a){return Ui(t),t.updateQueue=null,n=go(t,r,n,i),ho(e),r=vo(),e!==null&&!Ys?(yo(e,t,a),xc(e,t,a)):(Ci&&r&&vi(t),t.flags|=1,Xs(e,t,n,a),t.child)}function lc(e,t,n,r,i){if(Ui(t),t.stateNode===null){var a=Jr,o=n.contextType;typeof o==`object`&&o&&(a=Wi(o)),a=new n(r,a),t.memoizedState=a.state!==null&&a.state!==void 0?a.state:null,a.updater=Fs,t.stateNode=a,a._reactInternals=t,a=t.stateNode,a.props=r,a.state=t.memoizedState,a.refs={},ka(t),o=n.contextType,a.context=typeof o==`object`&&o?Wi(o):Jr,a.state=t.memoizedState,o=n.getDerivedStateFromProps,typeof o==`function`&&(Ps(t,n,o,r),a.state=t.memoizedState),typeof n.getDerivedStateFromProps==`function`||typeof a.getSnapshotBeforeUpdate==`function`||typeof a.UNSAFE_componentWillMount!=`function`&&typeof a.componentWillMount!=`function`||(o=a.state,typeof a.componentWillMount==`function`&&a.componentWillMount(),typeof a.UNSAFE_componentWillMount==`function`&&a.UNSAFE_componentWillMount(),o!==a.state&&Fs.enqueueReplaceState(a,a.state,null),La(t,r,a,i),Ia(),a.state=t.memoizedState),typeof a.componentDidMount==`function`&&(t.flags|=4194308),r=!0}else if(e===null){a=t.stateNode;var s=t.memoizedProps,c=Rs(n,s);a.props=c;var l=a.context,u=n.contextType;o=Jr,typeof u==`object`&&u&&(o=Wi(u));var d=n.getDerivedStateFromProps;u=typeof d==`function`||typeof a.getSnapshotBeforeUpdate==`function`,s=t.pendingProps!==s,u||typeof a.UNSAFE_componentWillReceiveProps!=`function`&&typeof a.componentWillReceiveProps!=`function`||(s||l!==o)&&Ls(t,a,r,o),Oa=!1;var f=t.memoizedState;a.state=f,La(t,r,a,i),Ia(),l=t.memoizedState,s||f!==l||Oa?(typeof d==`function`&&(Ps(t,n,d,r),l=t.memoizedState),(c=Oa||Is(t,n,c,r,f,l,o))?(u||typeof a.UNSAFE_componentWillMount!=`function`&&typeof a.componentWillMount!=`function`||(typeof a.componentWillMount==`function`&&a.componentWillMount(),typeof a.UNSAFE_componentWillMount==`function`&&a.UNSAFE_componentWillMount()),typeof a.componentDidMount==`function`&&(t.flags|=4194308)):(typeof a.componentDidMount==`function`&&(t.flags|=4194308),t.memoizedProps=r,t.memoizedState=l),a.props=r,a.state=l,a.context=o,r=c):(typeof a.componentDidMount==`function`&&(t.flags|=4194308),r=!1)}else{a=t.stateNode,Aa(e,t),o=t.memoizedProps,u=Rs(n,o),a.props=u,d=t.pendingProps,f=a.context,l=n.contextType,c=Jr,typeof l==`object`&&l&&(c=Wi(l)),s=n.getDerivedStateFromProps,(l=typeof s==`function`||typeof a.getSnapshotBeforeUpdate==`function`)||typeof a.UNSAFE_componentWillReceiveProps!=`function`&&typeof a.componentWillReceiveProps!=`function`||(o!==d||f!==c)&&Ls(t,a,r,c),Oa=!1,f=t.memoizedState,a.state=f,La(t,r,a,i),Ia();var p=t.memoizedState;o!==d||f!==p||Oa||e!==null&&e.dependencies!==null&&Hi(e.dependencies)?(typeof s==`function`&&(Ps(t,n,s,r),p=t.memoizedState),(u=Oa||Is(t,n,u,r,f,p,c)||e!==null&&e.dependencies!==null&&Hi(e.dependencies))?(l||typeof a.UNSAFE_componentWillUpdate!=`function`&&typeof a.componentWillUpdate!=`function`||(typeof a.componentWillUpdate==`function`&&a.componentWillUpdate(r,p,c),typeof a.UNSAFE_componentWillUpdate==`function`&&a.UNSAFE_componentWillUpdate(r,p,c)),typeof a.componentDidUpdate==`function`&&(t.flags|=4),typeof a.getSnapshotBeforeUpdate==`function`&&(t.flags|=1024)):(typeof a.componentDidUpdate!=`function`||o===e.memoizedProps&&f===e.memoizedState||(t.flags|=4),typeof a.getSnapshotBeforeUpdate!=`function`||o===e.memoizedProps&&f===e.memoizedState||(t.flags|=1024),t.memoizedProps=r,t.memoizedState=p),a.props=r,a.state=p,a.context=c,r=u):(typeof a.componentDidUpdate!=`function`||o===e.memoizedProps&&f===e.memoizedState||(t.flags|=4),typeof a.getSnapshotBeforeUpdate!=`function`||o===e.memoizedProps&&f===e.memoizedState||(t.flags|=1024),r=!1)}return a=r,oc(e,t),r=(t.flags&128)!=0,a||r?(a=t.stateNode,n=r&&typeof n.getDerivedStateFromError!=`function`?null:a.render(),t.flags|=1,e!==null&&r?(t.child=Ea(t,e.child,null,i),t.child=Ea(t,null,n,i)):Xs(e,t,n,i),t.memoizedState=a.state,e=t.child):e=xc(e,t,i),e}function uc(e,t,n,r){return ji(),t.flags|=256,Xs(e,t,n,r),t.child}var dc={dehydrated:null,treeContext:null,retryLane:0,hydrationErrors:null};function fc(e){return{baseLanes:e,cachePool:la()}}function pc(e,t,n){return e=e===null?0:e.childLanes&~n,t&&(e|=ql),e}function mc(e,t,n){var r=t.pendingProps,a=!1,o=(t.flags&128)!=0,s;if((s=o)||(s=e!==null&&e.memoizedState===null?!1:(Qa.current&2)!=0),s&&(a=!0,t.flags&=-129),s=(t.flags&32)!=0,t.flags&=-33,e===null){if(Ci){if(a?qa(t):Xa(t),(e=Si)?(e=of(e,Ti),e=e!==null&&e.data!==`&`?e:null,e!==null&&(t.memoizedState={dehydrated:e,treeContext:pi===null?null:{id:mi,overflow:hi},retryLane:536870912,hydrationErrors:null},n=ri(e),n.return=t,t.child=n,xi=t,Si=null)):e=null,e===null)throw Di(t);return cf(e)?t.lanes=32:t.lanes=536870912,null}var c=r.children;return r=r.fallback,a?(Xa(t),a=t.mode,c=gc({mode:`hidden`,children:c},a),r=ti(r,a,n,null),c.return=t,r.return=t,c.sibling=r,t.child=c,r=t.child,r.memoizedState=fc(n),r.childLanes=pc(e,s,n),t.memoizedState=dc,tc(null,r)):(qa(t),hc(t,c))}var l=e.memoizedState;if(l!==null&&(c=l.dehydrated,c!==null)){if(o)t.flags&256?(qa(t),t.flags&=-257,t=_c(e,t,n)):t.memoizedState===null?(Xa(t),c=r.fallback,a=t.mode,r=gc({mode:`visible`,children:r.children},a),c=ti(c,a,n,null),c.flags|=2,r.return=t,c.return=t,r.sibling=c,t.child=r,Ea(t,e.child,null,n),r=t.child,r.memoizedState=fc(n),r.childLanes=pc(e,s,n),t.memoizedState=dc,t=tc(null,r)):(Xa(t),t.child=e.child,t.flags|=128,t=null);else if(qa(t),cf(c)){if(s=c.nextSibling&&c.nextSibling.dataset,s)var u=s.dgst;s=u,r=Error(i(419)),r.stack=``,r.digest=s,Ni({value:r,source:null,stack:null}),t=_c(e,t,n)}else if(Ys||Vi(e,t,n,!1),s=(n&e.childLanes)!==0,Ys||s){if(s=Pl,s!==null&&(r=We(s,n),r!==0&&r!==l.retryLane))throw l.retryLane=r,Gr(e,r),mu(s,e,r),Js;sf(c)||Eu(),t=_c(e,t,n)}else sf(c)?(t.flags|=192,t.child=e.child,t=null):(e=l.treeContext,Si=uf(c.nextSibling),xi=t,Ci=!0,wi=null,Ti=!1,e!==null&&bi(t,e),t=hc(t,r.children),t.flags|=4096);return t}return a?(Xa(t),c=r.fallback,a=t.mode,l=e.child,u=l.sibling,r=Qr(l,{mode:`hidden`,children:r.children}),r.subtreeFlags=l.subtreeFlags&65011712,u===null?(c=ti(c,a,n,null),c.flags|=2):c=Qr(u,c),c.return=t,r.return=t,r.sibling=c,t.child=r,tc(null,r),r=t.child,c=e.child.memoizedState,c===null?c=fc(n):(a=c.cachePool,a===null?a=la():(l=Xi._currentValue,a=a.parent===l?a:{parent:l,pool:l}),c={baseLanes:c.baseLanes|n,cachePool:a}),r.memoizedState=c,r.childLanes=pc(e,s,n),t.memoizedState=dc,tc(e.child,r)):(qa(t),n=e.child,e=n.sibling,n=Qr(n,{mode:`visible`,children:r.children}),n.return=t,n.sibling=null,e!==null&&(s=t.deletions,s===null?(t.deletions=[e],t.flags|=16):s.push(e)),t.child=n,t.memoizedState=null,n)}function hc(e,t){return t=gc({mode:`visible`,children:t},e.mode),t.return=e,e.child=t}function gc(e,t){return e=Xr(22,e,null,t),e.lanes=0,e}function _c(e,t,n){return Ea(t,e.child,null,n),e=hc(t,t.pendingProps.children),e.flags|=2,t.memoizedState=null,e}function vc(e,t,n){e.lanes|=t;var r=e.alternate;r!==null&&(r.lanes|=t),zi(e.return,t,n)}function yc(e,t,n,r,i,a){var o=e.memoizedState;o===null?e.memoizedState={isBackwards:t,rendering:null,renderingStartTime:0,last:r,tail:n,tailMode:i,treeForkCount:a}:(o.isBackwards=t,o.rendering=null,o.renderingStartTime=0,o.last=r,o.tail=n,o.tailMode=i,o.treeForkCount=a)}function bc(e,t,n){var r=t.pendingProps,i=r.revealOrder,a=r.tail;r=r.children;var o=Qa.current,s=(o&2)!=0;if(s?(o=o&1|2,t.flags|=128):o&=1,B(Qa,o),Xs(e,t,r,n),r=Ci?ui:0,!s&&e!==null&&e.flags&128)a:for(e=t.child;e!==null;){if(e.tag===13)e.memoizedState!==null&&vc(e,n,t);else if(e.tag===19)vc(e,n,t);else if(e.child!==null){e.child.return=e,e=e.child;continue}if(e===t)break a;for(;e.sibling===null;){if(e.return===null||e.return===t)break a;e=e.return}e.sibling.return=e.return,e=e.sibling}switch(i){case`forwards`:for(n=t.child,i=null;n!==null;)e=n.alternate,e!==null&&$a(e)===null&&(i=n),n=n.sibling;n=i,n===null?(i=t.child,t.child=null):(i=n.sibling,n.sibling=null),yc(t,!1,i,n,a,r);break;case`backwards`:case`unstable_legacy-backwards`:for(n=null,i=t.child,t.child=null;i!==null;){if(e=i.alternate,e!==null&&$a(e)===null){t.child=i;break}e=i.sibling,i.sibling=n,n=i,i=e}yc(t,!0,n,null,a,r);break;case`together`:yc(t,!1,null,null,void 0,r);break;default:t.memoizedState=null}return t.child}function xc(e,t,n){if(e!==null&&(t.dependencies=e.dependencies),Wl|=t.lanes,(n&t.childLanes)===0)if(e!==null){if(Vi(e,t,n,!1),(n&t.childLanes)===0)return null}else return null;if(e!==null&&t.child!==e.child)throw Error(i(153));if(t.child!==null){for(e=t.child,n=Qr(e,e.pendingProps),t.child=n,n.return=t;e.sibling!==null;)e=e.sibling,n=n.sibling=Qr(e,e.pendingProps),n.return=t;n.sibling=null}return t.child}function Sc(e,t){return(e.lanes&t)===0?(e=e.dependencies,!!(e!==null&&Hi(e))):!0}function Cc(e,t,n){switch(t.tag){case 3:te(t,t.stateNode.containerInfo),Li(t,Xi,e.memoizedState.cache),ji();break;case 27:case 5:ne(t);break;case 4:te(t,t.stateNode.containerInfo);break;case 10:Li(t,t.type,t.memoizedProps.value);break;case 31:if(t.memoizedState!==null)return t.flags|=128,Ja(t),null;break;case 13:var r=t.memoizedState;if(r!==null)return r.dehydrated===null?(n&t.child.childLanes)===0?(qa(t),e=xc(e,t,n),e===null?null:e.sibling):mc(e,t,n):(qa(t),t.flags|=128,null);qa(t);break;case 19:var i=(e.flags&128)!=0;if(r=(n&t.childLanes)!==0,r||=(Vi(e,t,n,!1),(n&t.childLanes)!==0),i){if(r)return bc(e,t,n);t.flags|=128}if(i=t.memoizedState,i!==null&&(i.rendering=null,i.tail=null,i.lastEffect=null),B(Qa,Qa.current),r)break;return null;case 22:return t.lanes=0,ec(e,t,n,t.pendingProps);case 24:Li(t,Xi,e.memoizedState.cache)}return xc(e,t,n)}function wc(e,t,n){if(e!==null)if(e.memoizedProps!==t.pendingProps)Ys=!0;else{if(!Sc(e,n)&&!(t.flags&128))return Ys=!1,Cc(e,t,n);Ys=!!(e.flags&131072)}else Ys=!1,Ci&&t.flags&1048576&&_i(t,ui,t.index);switch(t.lanes=0,t.tag){case 16:a:{var r=t.pendingProps;if(e=ga(t.elementType),t.type=e,typeof e==`function`)Zr(e)?(r=Rs(e,r),t.tag=1,t=lc(null,t,e,r,n)):(t.tag=0,t=sc(null,t,e,r,n));else{if(e!=null){var a=e.$$typeof;if(a===x){t.tag=11,t=Zs(null,t,e,r,n);break a}else if(a===w){t.tag=14,t=Qs(null,t,e,r,n);break a}}throw t=j(e)||e,Error(i(306,t,``))}}return t;case 0:return sc(e,t,t.type,t.pendingProps,n);case 1:return r=t.type,a=Rs(r,t.pendingProps),lc(e,t,r,a,n);case 3:a:{if(te(t,t.stateNode.containerInfo),e===null)throw Error(i(387));r=t.pendingProps;var o=t.memoizedState;a=o.element,Aa(e,t),La(t,r,null,n);var s=t.memoizedState;if(r=s.cache,Li(t,Xi,r),r!==o.cache&&Bi(t,[Xi],n,!0),Ia(),r=s.element,o.isDehydrated)if(o={element:r,isDehydrated:!1,cache:s.cache},t.updateQueue.baseState=o,t.memoizedState=o,t.flags&256){t=uc(e,t,r,n);break a}else if(r!==a){a=oi(Error(i(424)),t),Ni(a),t=uc(e,t,r,n);break a}else{switch(e=t.stateNode.containerInfo,e.nodeType){case 9:e=e.body;break;default:e=e.nodeName===`HTML`?e.ownerDocument.body:e}for(Si=uf(e.firstChild),xi=t,Ci=!0,wi=null,Ti=!0,n=Da(t,null,r,n),t.child=n;n;)n.flags=n.flags&-3|4096,n=n.sibling}else{if(ji(),r===a){t=xc(e,t,n);break a}Xs(e,t,r,n)}t=t.child}return t;case 26:return oc(e,t),e===null?(n=jf(t.type,null,t.pendingProps,null))?t.memoizedState=n:Ci||(n=t.type,e=t.pendingProps,r=Hd(H.current).createElement(n),r[Xe]=t,r[Ze]=e,Id(r,n,e),lt(r),t.stateNode=r):t.memoizedState=jf(t.type,e.memoizedProps,t.pendingProps,e.memoizedState),null;case 27:return ne(t),e===null&&Ci&&(r=t.stateNode=mf(t.type,t.pendingProps,H.current),xi=t,Ti=!0,a=Si,$d(t.type)?(df=a,Si=uf(r.firstChild)):Si=a),Xs(e,t,t.pendingProps.children,n),oc(e,t),e===null&&(t.flags|=4194304),t.child;case 5:return e===null&&Ci&&((a=r=Si)&&(r=rf(r,t.type,t.pendingProps,Ti),r===null?a=!1:(t.stateNode=r,xi=t,Si=uf(r.firstChild),Ti=!1,a=!0)),a||Di(t)),ne(t),a=t.type,o=t.pendingProps,s=e===null?null:e.memoizedProps,r=o.children,Gd(a,o)?r=null:s!==null&&Gd(a,s)&&(t.flags|=32),t.memoizedState!==null&&(a=mo(e,t,_o,null,null,n),ep._currentValue=a),oc(e,t),Xs(e,t,r,n),t.child;case 6:return e===null&&Ci&&((e=n=Si)&&(n=af(n,t.pendingProps,Ti),n===null?e=!1:(t.stateNode=n,xi=t,Si=null,e=!0)),e||Di(t)),null;case 13:return mc(e,t,n);case 4:return te(t,t.stateNode.containerInfo),r=t.pendingProps,e===null?t.child=Ea(t,null,r,n):Xs(e,t,r,n),t.child;case 11:return Zs(e,t,t.type,t.pendingProps,n);case 7:return Xs(e,t,t.pendingProps,n),t.child;case 8:return Xs(e,t,t.pendingProps.children,n),t.child;case 12:return Xs(e,t,t.pendingProps.children,n),t.child;case 10:return r=t.pendingProps,Li(t,t.type,r.value),Xs(e,t,r.children,n),t.child;case 9:return a=t.type._context,r=t.pendingProps.children,Ui(t),a=Wi(a),r=r(a),t.flags|=1,Xs(e,t,r,n),t.child;case 14:return Qs(e,t,t.type,t.pendingProps,n);case 15:return $s(e,t,t.type,t.pendingProps,n);case 19:return bc(e,t,n);case 31:return ac(e,t,n);case 22:return ec(e,t,n,t.pendingProps);case 24:return Ui(t),r=Wi(Xi),e===null?(a=sa(),a===null&&(a=Pl,o=Zi(),a.pooledCache=o,o.refCount++,o!==null&&(a.pooledCacheLanes|=n),a=o),t.memoizedState={parent:r,cache:a},ka(t),Li(t,Xi,a)):((e.lanes&n)!==0&&(Aa(e,t),La(t,null,null,n),Ia()),a=e.memoizedState,o=t.memoizedState,a.parent===r?(r=o.cache,Li(t,Xi,r),r!==a.cache&&Bi(t,[Xi],n,!0)):(a={parent:r,cache:r},t.memoizedState=a,t.lanes===0&&(t.memoizedState=t.updateQueue.baseState=a),Li(t,Xi,r))),Xs(e,t,t.pendingProps.children,n),t.child;case 29:throw t.pendingProps}throw Error(i(156,t.tag))}function Tc(e){e.flags|=4}function Ec(e,t,n,r,i){if((t=(e.mode&32)!=0)&&(t=!1),t){if(e.flags|=16777216,(i&335544128)===i)if(e.stateNode.complete)e.flags|=8192;else if(Cu())e.flags|=8192;else throw _a=pa,da}else e.flags&=-16777217}function Dc(e,t){if(t.type!==`stylesheet`||t.state.loading&4)e.flags&=-16777217;else if(e.flags|=16777216,!Kf(t))if(Cu())e.flags|=8192;else throw _a=pa,da}function Oc(e,t){t!==null&&(e.flags|=4),e.flags&16384&&(t=e.tag===22?536870912:Re(),e.lanes|=t,Jl|=t)}function kc(e,t){if(!Ci)switch(e.tailMode){case`hidden`:t=e.tail;for(var n=null;t!==null;)t.alternate!==null&&(n=t),t=t.sibling;n===null?e.tail=null:n.sibling=null;break;case`collapsed`:n=e.tail;for(var r=null;n!==null;)n.alternate!==null&&(r=n),n=n.sibling;r===null?t||e.tail===null?e.tail=null:e.tail.sibling=null:r.sibling=null}}function Ac(e){var t=e.alternate!==null&&e.alternate.child===e.child,n=0,r=0;if(t)for(var i=e.child;i!==null;)n|=i.lanes|i.childLanes,r|=i.subtreeFlags&65011712,r|=i.flags&65011712,i.return=e,i=i.sibling;else for(i=e.child;i!==null;)n|=i.lanes|i.childLanes,r|=i.subtreeFlags,r|=i.flags,i.return=e,i=i.sibling;return e.subtreeFlags|=r,e.childLanes=n,t}function jc(e,t,n){var r=t.pendingProps;switch(yi(t),t.tag){case 16:case 15:case 0:case 11:case 7:case 8:case 12:case 9:case 14:return Ac(t),null;case 1:return Ac(t),null;case 3:return n=t.stateNode,r=null,e!==null&&(r=e.memoizedState.cache),t.memoizedState.cache!==r&&(t.flags|=2048),Ri(Xi),W(),n.pendingContext&&(n.context=n.pendingContext,n.pendingContext=null),(e===null||e.child===null)&&(Ai(t)?Tc(t):e===null||e.memoizedState.isDehydrated&&!(t.flags&256)||(t.flags|=1024,Mi())),Ac(t),null;case 26:var a=t.type,o=t.memoizedState;return e===null?(Tc(t),o===null?(Ac(t),Ec(t,a,null,r,n)):(Ac(t),Dc(t,o))):o?o===e.memoizedState?(Ac(t),t.flags&=-16777217):(Tc(t),Ac(t),Dc(t,o)):(e=e.memoizedProps,e!==r&&Tc(t),Ac(t),Ec(t,a,e,r,n)),null;case 27:if(G(t),n=H.current,a=t.type,e!==null&&t.stateNode!=null)e.memoizedProps!==r&&Tc(t);else{if(!r){if(t.stateNode===null)throw Error(i(166));return Ac(t),null}e=V.current,Ai(t)?Oi(t,e):(e=mf(a,r,n),t.stateNode=e,Tc(t))}return Ac(t),null;case 5:if(G(t),a=t.type,e!==null&&t.stateNode!=null)e.memoizedProps!==r&&Tc(t);else{if(!r){if(t.stateNode===null)throw Error(i(166));return Ac(t),null}if(o=V.current,Ai(t))Oi(t,o);else{var s=Hd(H.current);switch(o){case 1:o=s.createElementNS(`http://www.w3.org/2000/svg`,a);break;case 2:o=s.createElementNS(`http://www.w3.org/1998/Math/MathML`,a);break;default:switch(a){case`svg`:o=s.createElementNS(`http://www.w3.org/2000/svg`,a);break;case`math`:o=s.createElementNS(`http://www.w3.org/1998/Math/MathML`,a);break;case`script`:o=s.createElement(`div`),o.innerHTML=`<script><\/script>`,o=o.removeChild(o.firstChild);break;case`select`:o=typeof r.is==`string`?s.createElement(`select`,{is:r.is}):s.createElement(`select`),r.multiple?o.multiple=!0:r.size&&(o.size=r.size);break;default:o=typeof r.is==`string`?s.createElement(a,{is:r.is}):s.createElement(a)}}o[Xe]=t,o[Ze]=r;a:for(s=t.child;s!==null;){if(s.tag===5||s.tag===6)o.appendChild(s.stateNode);else if(s.tag!==4&&s.tag!==27&&s.child!==null){s.child.return=s,s=s.child;continue}if(s===t)break a;for(;s.sibling===null;){if(s.return===null||s.return===t)break a;s=s.return}s.sibling.return=s.return,s=s.sibling}t.stateNode=o;a:switch(Id(o,a,r),a){case`button`:case`input`:case`select`:case`textarea`:r=!!r.autoFocus;break a;case`img`:r=!0;break a;default:r=!1}r&&Tc(t)}}return Ac(t),Ec(t,t.type,e===null?null:e.memoizedProps,t.pendingProps,n),null;case 6:if(e&&t.stateNode!=null)e.memoizedProps!==r&&Tc(t);else{if(typeof r!=`string`&&t.stateNode===null)throw Error(i(166));if(e=H.current,Ai(t)){if(e=t.stateNode,n=t.memoizedProps,r=null,a=xi,a!==null)switch(a.tag){case 27:case 5:r=a.memoizedProps}e[Xe]=t,e=!!(e.nodeValue===n||r!==null&&!0===r.suppressHydrationWarning||Nd(e.nodeValue,n)),e||Di(t,!0)}else e=Hd(e).createTextNode(r),e[Xe]=t,t.stateNode=e}return Ac(t),null;case 31:if(n=t.memoizedState,e===null||e.memoizedState!==null){if(r=Ai(t),n!==null){if(e===null){if(!r)throw Error(i(318));if(e=t.memoizedState,e=e===null?null:e.dehydrated,!e)throw Error(i(557));e[Xe]=t}else ji(),!(t.flags&128)&&(t.memoizedState=null),t.flags|=4;Ac(t),e=!1}else n=Mi(),e!==null&&e.memoizedState!==null&&(e.memoizedState.hydrationErrors=n),e=!0;if(!e)return t.flags&256?(Za(t),t):(Za(t),null);if(t.flags&128)throw Error(i(558))}return Ac(t),null;case 13:if(r=t.memoizedState,e===null||e.memoizedState!==null&&e.memoizedState.dehydrated!==null){if(a=Ai(t),r!==null&&r.dehydrated!==null){if(e===null){if(!a)throw Error(i(318));if(a=t.memoizedState,a=a===null?null:a.dehydrated,!a)throw Error(i(317));a[Xe]=t}else ji(),!(t.flags&128)&&(t.memoizedState=null),t.flags|=4;Ac(t),a=!1}else a=Mi(),e!==null&&e.memoizedState!==null&&(e.memoizedState.hydrationErrors=a),a=!0;if(!a)return t.flags&256?(Za(t),t):(Za(t),null)}return Za(t),t.flags&128?(t.lanes=n,t):(n=r!==null,e=e!==null&&e.memoizedState!==null,n&&(r=t.child,a=null,r.alternate!==null&&r.alternate.memoizedState!==null&&r.alternate.memoizedState.cachePool!==null&&(a=r.alternate.memoizedState.cachePool.pool),o=null,r.memoizedState!==null&&r.memoizedState.cachePool!==null&&(o=r.memoizedState.cachePool.pool),o!==a&&(r.flags|=2048)),n!==e&&n&&(t.child.flags|=8192),Oc(t,t.updateQueue),Ac(t),null);case 4:return W(),e===null&&Cd(t.stateNode.containerInfo),Ac(t),null;case 10:return Ri(t.type),Ac(t),null;case 19:if(z(Qa),r=t.memoizedState,r===null)return Ac(t),null;if(a=(t.flags&128)!=0,o=r.rendering,o===null)if(a)kc(r,!1);else{if(Ul!==0||e!==null&&e.flags&128)for(e=t.child;e!==null;){if(o=$a(e),o!==null){for(t.flags|=128,kc(r,!1),e=o.updateQueue,t.updateQueue=e,Oc(t,e),t.subtreeFlags=0,e=n,n=t.child;n!==null;)$r(n,e),n=n.sibling;return B(Qa,Qa.current&1|2),Ci&&gi(t,r.treeForkCount),t.child}e=e.sibling}r.tail!==null&&he()>eu&&(t.flags|=128,a=!0,kc(r,!1),t.lanes=4194304)}else{if(!a)if(e=$a(o),e!==null){if(t.flags|=128,a=!0,e=e.updateQueue,t.updateQueue=e,Oc(t,e),kc(r,!0),r.tail===null&&r.tailMode===`hidden`&&!o.alternate&&!Ci)return Ac(t),null}else 2*he()-r.renderingStartTime>eu&&n!==536870912&&(t.flags|=128,a=!0,kc(r,!1),t.lanes=4194304);r.isBackwards?(o.sibling=t.child,t.child=o):(e=r.last,e===null?t.child=o:e.sibling=o,r.last=o)}return r.tail===null?(Ac(t),null):(e=r.tail,r.rendering=e,r.tail=e.sibling,r.renderingStartTime=he(),e.sibling=null,n=Qa.current,B(Qa,a?n&1|2:n&1),Ci&&gi(t,r.treeForkCount),e);case 22:case 23:return Za(t),Wa(),r=t.memoizedState!==null,e===null?r&&(t.flags|=8192):e.memoizedState!==null!==r&&(t.flags|=8192),r?n&536870912&&!(t.flags&128)&&(Ac(t),t.subtreeFlags&6&&(t.flags|=8192)):Ac(t),n=t.updateQueue,n!==null&&Oc(t,n.retryQueue),n=null,e!==null&&e.memoizedState!==null&&e.memoizedState.cachePool!==null&&(n=e.memoizedState.cachePool.pool),r=null,t.memoizedState!==null&&t.memoizedState.cachePool!==null&&(r=t.memoizedState.cachePool.pool),r!==n&&(t.flags|=2048),e!==null&&z(oa),null;case 24:return n=null,e!==null&&(n=e.memoizedState.cache),t.memoizedState.cache!==n&&(t.flags|=2048),Ri(Xi),Ac(t),null;case 25:return null;case 30:return null}throw Error(i(156,t.tag))}function Mc(e,t){switch(yi(t),t.tag){case 1:return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 3:return Ri(Xi),W(),e=t.flags,e&65536&&!(e&128)?(t.flags=e&-65537|128,t):null;case 26:case 27:case 5:return G(t),null;case 31:if(t.memoizedState!==null){if(Za(t),t.alternate===null)throw Error(i(340));ji()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 13:if(Za(t),e=t.memoizedState,e!==null&&e.dehydrated!==null){if(t.alternate===null)throw Error(i(340));ji()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 19:return z(Qa),null;case 4:return W(),null;case 10:return Ri(t.type),null;case 22:case 23:return Za(t),Wa(),e!==null&&z(oa),e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 24:return Ri(Xi),null;case 25:return null;default:return null}}function Nc(e,t){switch(yi(t),t.tag){case 3:Ri(Xi),W();break;case 26:case 27:case 5:G(t);break;case 4:W();break;case 31:t.memoizedState!==null&&Za(t);break;case 13:Za(t);break;case 19:z(Qa);break;case 10:Ri(t.type);break;case 22:case 23:Za(t),Wa(),e!==null&&z(oa);break;case 24:Ri(Xi)}}function Pc(e,t){try{var n=t.updateQueue,r=n===null?null:n.lastEffect;if(r!==null){var i=r.next;n=i;do{if((n.tag&e)===e){r=void 0;var a=n.create,o=n.inst;r=a(),o.destroy=r}n=n.next}while(n!==i)}}catch(e){Wu(t,t.return,e)}}function Fc(e,t,n){try{var r=t.updateQueue,i=r===null?null:r.lastEffect;if(i!==null){var a=i.next;r=a;do{if((r.tag&e)===e){var o=r.inst,s=o.destroy;if(s!==void 0){o.destroy=void 0,i=t;var c=n,l=s;try{l()}catch(e){Wu(i,c,e)}}}r=r.next}while(r!==a)}}catch(e){Wu(t,t.return,e)}}function Ic(e){var t=e.updateQueue;if(t!==null){var n=e.stateNode;try{za(t,n)}catch(t){Wu(e,e.return,t)}}}function Lc(e,t,n){n.props=Rs(e.type,e.memoizedProps),n.state=e.memoizedState;try{n.componentWillUnmount()}catch(n){Wu(e,t,n)}}function Rc(e,t){try{var n=e.ref;if(n!==null){switch(e.tag){case 26:case 27:case 5:var r=e.stateNode;break;case 30:r=e.stateNode;break;default:r=e.stateNode}typeof n==`function`?e.refCleanup=n(r):n.current=r}}catch(n){Wu(e,t,n)}}function zc(e,t){var n=e.ref,r=e.refCleanup;if(n!==null)if(typeof r==`function`)try{r()}catch(n){Wu(e,t,n)}finally{e.refCleanup=null,e=e.alternate,e!=null&&(e.refCleanup=null)}else if(typeof n==`function`)try{n(null)}catch(n){Wu(e,t,n)}else n.current=null}function Bc(e){var t=e.type,n=e.memoizedProps,r=e.stateNode;try{a:switch(t){case`button`:case`input`:case`select`:case`textarea`:n.autoFocus&&r.focus();break a;case`img`:n.src?r.src=n.src:n.srcSet&&(r.srcset=n.srcSet)}}catch(t){Wu(e,e.return,t)}}function Vc(e,t,n){try{var r=e.stateNode;Ld(r,e.type,n,t),r[Ze]=t}catch(t){Wu(e,e.return,t)}}function Hc(e){return e.tag===5||e.tag===3||e.tag===26||e.tag===27&&$d(e.type)||e.tag===4}function Uc(e){a:for(;;){for(;e.sibling===null;){if(e.return===null||Hc(e.return))return null;e=e.return}for(e.sibling.return=e.return,e=e.sibling;e.tag!==5&&e.tag!==6&&e.tag!==18;){if(e.tag===27&&$d(e.type)||e.flags&2||e.child===null||e.tag===4)continue a;e.child.return=e,e=e.child}if(!(e.flags&2))return e.stateNode}}function Wc(e,t,n){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?(n.nodeType===9?n.body:n.nodeName===`HTML`?n.ownerDocument.body:n).insertBefore(e,t):(t=n.nodeType===9?n.body:n.nodeName===`HTML`?n.ownerDocument.body:n,t.appendChild(e),n=n._reactRootContainer,n!=null||t.onclick!==null||(t.onclick=Ut));else if(r!==4&&(r===27&&$d(e.type)&&(n=e.stateNode,t=null),e=e.child,e!==null))for(Wc(e,t,n),e=e.sibling;e!==null;)Wc(e,t,n),e=e.sibling}function Gc(e,t,n){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?n.insertBefore(e,t):n.appendChild(e);else if(r!==4&&(r===27&&$d(e.type)&&(n=e.stateNode),e=e.child,e!==null))for(Gc(e,t,n),e=e.sibling;e!==null;)Gc(e,t,n),e=e.sibling}function Kc(e){var t=e.stateNode,n=e.memoizedProps;try{for(var r=e.type,i=t.attributes;i.length;)t.removeAttributeNode(i[0]);Id(t,r,n),t[Xe]=e,t[Ze]=n}catch(t){Wu(e,e.return,t)}}var qc=!1,Jc=!1,Yc=!1,Xc=typeof WeakSet==`function`?WeakSet:Set,Zc=null;function Qc(e,t){if(e=e.containerInfo,Bd=lp,e=gr(e),_r(e)){if(`selectionStart`in e)var n={start:e.selectionStart,end:e.selectionEnd};else a:{n=(n=e.ownerDocument)&&n.defaultView||window;var r=n.getSelection&&n.getSelection();if(r&&r.rangeCount!==0){n=r.anchorNode;var a=r.anchorOffset,o=r.focusNode;r=r.focusOffset;try{n.nodeType,o.nodeType}catch{n=null;break a}var s=0,c=-1,l=-1,u=0,d=0,f=e,p=null;b:for(;;){for(var m;f!==n||a!==0&&f.nodeType!==3||(c=s+a),f!==o||r!==0&&f.nodeType!==3||(l=s+r),f.nodeType===3&&(s+=f.nodeValue.length),(m=f.firstChild)!==null;)p=f,f=m;for(;;){if(f===e)break b;if(p===n&&++u===a&&(c=s),p===o&&++d===r&&(l=s),(m=f.nextSibling)!==null)break;f=p,p=f.parentNode}f=m}n=c===-1||l===-1?null:{start:c,end:l}}else n=null}n||={start:0,end:0}}else n=null;for(Vd={focusedElem:e,selectionRange:n},lp=!1,Zc=t;Zc!==null;)if(t=Zc,e=t.child,t.subtreeFlags&1028&&e!==null)e.return=t,Zc=e;else for(;Zc!==null;){switch(t=Zc,o=t.alternate,e=t.flags,t.tag){case 0:if(e&4&&(e=t.updateQueue,e=e===null?null:e.events,e!==null))for(n=0;n<e.length;n++)a=e[n],a.ref.impl=a.nextImpl;break;case 11:case 15:break;case 1:if(e&1024&&o!==null){e=void 0,n=t,a=o.memoizedProps,o=o.memoizedState,r=n.stateNode;try{var h=Rs(n.type,a);e=r.getSnapshotBeforeUpdate(h,o),r.__reactInternalSnapshotBeforeUpdate=e}catch(e){Wu(n,n.return,e)}}break;case 3:if(e&1024){if(e=t.stateNode.containerInfo,n=e.nodeType,n===9)nf(e);else if(n===1)switch(e.nodeName){case`HEAD`:case`HTML`:case`BODY`:nf(e);break;default:e.textContent=``}}break;case 5:case 26:case 27:case 6:case 4:case 17:break;default:if(e&1024)throw Error(i(163))}if(e=t.sibling,e!==null){e.return=t.return,Zc=e;break}Zc=t.return}}function $c(e,t,n){var r=n.flags;switch(n.tag){case 0:case 11:case 15:ml(e,n),r&4&&Pc(5,n);break;case 1:if(ml(e,n),r&4)if(e=n.stateNode,t===null)try{e.componentDidMount()}catch(e){Wu(n,n.return,e)}else{var i=Rs(n.type,t.memoizedProps);t=t.memoizedState;try{e.componentDidUpdate(i,t,e.__reactInternalSnapshotBeforeUpdate)}catch(e){Wu(n,n.return,e)}}r&64&&Ic(n),r&512&&Rc(n,n.return);break;case 3:if(ml(e,n),r&64&&(e=n.updateQueue,e!==null)){if(t=null,n.child!==null)switch(n.child.tag){case 27:case 5:t=n.child.stateNode;break;case 1:t=n.child.stateNode}try{za(e,t)}catch(e){Wu(n,n.return,e)}}break;case 27:t===null&&r&4&&Kc(n);case 26:case 5:ml(e,n),t===null&&r&4&&Bc(n),r&512&&Rc(n,n.return);break;case 12:ml(e,n);break;case 31:ml(e,n),r&4&&al(e,n);break;case 13:ml(e,n),r&4&&ol(e,n),r&64&&(e=n.memoizedState,e!==null&&(e=e.dehydrated,e!==null&&(n=Ju.bind(null,n),lf(e,n))));break;case 22:if(r=n.memoizedState!==null||qc,!r){t=t!==null&&t.memoizedState!==null||Jc,i=qc;var a=Jc;qc=r,(Jc=t)&&!a?gl(e,n,(n.subtreeFlags&8772)!=0):ml(e,n),qc=i,Jc=a}break;case 30:break;default:ml(e,n)}}function el(e){var t=e.alternate;t!==null&&(e.alternate=null,el(t)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(t=e.stateNode,t!==null&&it(t)),e.stateNode=null,e.return=null,e.dependencies=null,e.memoizedProps=null,e.memoizedState=null,e.pendingProps=null,e.stateNode=null,e.updateQueue=null}var tl=null,nl=!1;function rl(e,t,n){for(n=n.child;n!==null;)il(e,t,n),n=n.sibling}function il(e,t,n){if(Te&&typeof Te.onCommitFiberUnmount==`function`)try{Te.onCommitFiberUnmount(we,n)}catch{}switch(n.tag){case 26:Jc||zc(n,t),rl(e,t,n),n.memoizedState?n.memoizedState.count--:n.stateNode&&(n=n.stateNode,n.parentNode.removeChild(n));break;case 27:Jc||zc(n,t);var r=tl,i=nl;$d(n.type)&&(tl=n.stateNode,nl=!1),rl(e,t,n),hf(n.stateNode),tl=r,nl=i;break;case 5:Jc||zc(n,t);case 6:if(r=tl,i=nl,tl=null,rl(e,t,n),tl=r,nl=i,tl!==null)if(nl)try{(tl.nodeType===9?tl.body:tl.nodeName===`HTML`?tl.ownerDocument.body:tl).removeChild(n.stateNode)}catch(e){Wu(n,t,e)}else try{tl.removeChild(n.stateNode)}catch(e){Wu(n,t,e)}break;case 18:tl!==null&&(nl?(e=tl,ef(e.nodeType===9?e.body:e.nodeName===`HTML`?e.ownerDocument.body:e,n.stateNode),Fp(e)):ef(tl,n.stateNode));break;case 4:r=tl,i=nl,tl=n.stateNode.containerInfo,nl=!0,rl(e,t,n),tl=r,nl=i;break;case 0:case 11:case 14:case 15:Fc(2,n,t),Jc||Fc(4,n,t),rl(e,t,n);break;case 1:Jc||(zc(n,t),r=n.stateNode,typeof r.componentWillUnmount==`function`&&Lc(n,t,r)),rl(e,t,n);break;case 21:rl(e,t,n);break;case 22:Jc=(r=Jc)||n.memoizedState!==null,rl(e,t,n),Jc=r;break;default:rl(e,t,n)}}function al(e,t){if(t.memoizedState===null&&(e=t.alternate,e!==null&&(e=e.memoizedState,e!==null))){e=e.dehydrated;try{Fp(e)}catch(e){Wu(t,t.return,e)}}}function ol(e,t){if(t.memoizedState===null&&(e=t.alternate,e!==null&&(e=e.memoizedState,e!==null&&(e=e.dehydrated,e!==null))))try{Fp(e)}catch(e){Wu(t,t.return,e)}}function sl(e){switch(e.tag){case 31:case 13:case 19:var t=e.stateNode;return t===null&&(t=e.stateNode=new Xc),t;case 22:return e=e.stateNode,t=e._retryCache,t===null&&(t=e._retryCache=new Xc),t;default:throw Error(i(435,e.tag))}}function cl(e,t){var n=sl(e);t.forEach(function(t){if(!n.has(t)){n.add(t);var r=Yu.bind(null,e,t);t.then(r,r)}})}function ll(e,t){var n=t.deletions;if(n!==null)for(var r=0;r<n.length;r++){var a=n[r],o=e,s=t,c=s;a:for(;c!==null;){switch(c.tag){case 27:if($d(c.type)){tl=c.stateNode,nl=!1;break a}break;case 5:tl=c.stateNode,nl=!1;break a;case 3:case 4:tl=c.stateNode.containerInfo,nl=!0;break a}c=c.return}if(tl===null)throw Error(i(160));il(o,s,a),tl=null,nl=!1,o=a.alternate,o!==null&&(o.return=null),a.return=null}if(t.subtreeFlags&13886)for(t=t.child;t!==null;)dl(t,e),t=t.sibling}var ul=null;function dl(e,t){var n=e.alternate,r=e.flags;switch(e.tag){case 0:case 11:case 14:case 15:ll(t,e),fl(e),r&4&&(Fc(3,e,e.return),Pc(3,e),Fc(5,e,e.return));break;case 1:ll(t,e),fl(e),r&512&&(Jc||n===null||zc(n,n.return)),r&64&&qc&&(e=e.updateQueue,e!==null&&(r=e.callbacks,r!==null&&(n=e.shared.hiddenCallbacks,e.shared.hiddenCallbacks=n===null?r:n.concat(r))));break;case 26:var a=ul;if(ll(t,e),fl(e),r&512&&(Jc||n===null||zc(n,n.return)),r&4){var o=n===null?null:n.memoizedState;if(r=e.memoizedState,n===null)if(r===null)if(e.stateNode===null){a:{r=e.type,n=e.memoizedProps,a=a.ownerDocument||a;b:switch(r){case`title`:o=a.getElementsByTagName(`title`)[0],(!o||o[rt]||o[Xe]||o.namespaceURI===`http://www.w3.org/2000/svg`||o.hasAttribute(`itemprop`))&&(o=a.createElement(r),a.head.insertBefore(o,a.querySelector(`head > title`))),Id(o,r,n),o[Xe]=e,lt(o),r=o;break a;case`link`:var s=Uf(`link`,`href`,a).get(r+(n.href||``));if(s){for(var c=0;c<s.length;c++)if(o=s[c],o.getAttribute(`href`)===(n.href==null||n.href===``?null:n.href)&&o.getAttribute(`rel`)===(n.rel==null?null:n.rel)&&o.getAttribute(`title`)===(n.title==null?null:n.title)&&o.getAttribute(`crossorigin`)===(n.crossOrigin==null?null:n.crossOrigin)){s.splice(c,1);break b}}o=a.createElement(r),Id(o,r,n),a.head.appendChild(o);break;case`meta`:if(s=Uf(`meta`,`content`,a).get(r+(n.content||``))){for(c=0;c<s.length;c++)if(o=s[c],o.getAttribute(`content`)===(n.content==null?null:``+n.content)&&o.getAttribute(`name`)===(n.name==null?null:n.name)&&o.getAttribute(`property`)===(n.property==null?null:n.property)&&o.getAttribute(`http-equiv`)===(n.httpEquiv==null?null:n.httpEquiv)&&o.getAttribute(`charset`)===(n.charSet==null?null:n.charSet)){s.splice(c,1);break b}}o=a.createElement(r),Id(o,r,n),a.head.appendChild(o);break;default:throw Error(i(468,r))}o[Xe]=e,lt(o),r=o}e.stateNode=r}else Wf(a,e.type,e.stateNode);else e.stateNode=Rf(a,r,e.memoizedProps);else o===r?r===null&&e.stateNode!==null&&Vc(e,e.memoizedProps,n.memoizedProps):(o===null?n.stateNode!==null&&(n=n.stateNode,n.parentNode.removeChild(n)):o.count--,r===null?Wf(a,e.type,e.stateNode):Rf(a,r,e.memoizedProps))}break;case 27:ll(t,e),fl(e),r&512&&(Jc||n===null||zc(n,n.return)),n!==null&&r&4&&Vc(e,e.memoizedProps,n.memoizedProps);break;case 5:if(ll(t,e),fl(e),r&512&&(Jc||n===null||zc(n,n.return)),e.flags&32){a=e.stateNode;try{Ft(a,``)}catch(t){Wu(e,e.return,t)}}r&4&&e.stateNode!=null&&(a=e.memoizedProps,Vc(e,a,n===null?a:n.memoizedProps)),r&1024&&(Yc=!0);break;case 6:if(ll(t,e),fl(e),r&4){if(e.stateNode===null)throw Error(i(162));r=e.memoizedProps,n=e.stateNode;try{n.nodeValue=r}catch(t){Wu(e,e.return,t)}}break;case 3:if(Hf=null,a=ul,ul=vf(t.containerInfo),ll(t,e),ul=a,fl(e),r&4&&n!==null&&n.memoizedState.isDehydrated)try{Fp(t.containerInfo)}catch(t){Wu(e,e.return,t)}Yc&&(Yc=!1,pl(e));break;case 4:r=ul,ul=vf(e.stateNode.containerInfo),ll(t,e),fl(e),ul=r;break;case 12:ll(t,e),fl(e);break;case 31:ll(t,e),fl(e),r&4&&(r=e.updateQueue,r!==null&&(e.updateQueue=null,cl(e,r)));break;case 13:ll(t,e),fl(e),e.child.flags&8192&&e.memoizedState!==null!=(n!==null&&n.memoizedState!==null)&&(Ql=he()),r&4&&(r=e.updateQueue,r!==null&&(e.updateQueue=null,cl(e,r)));break;case 22:a=e.memoizedState!==null;var l=n!==null&&n.memoizedState!==null,u=qc,d=Jc;if(qc=u||a,Jc=d||l,ll(t,e),Jc=d,qc=u,fl(e),r&8192)a:for(t=e.stateNode,t._visibility=a?t._visibility&-2:t._visibility|1,a&&(n===null||l||qc||Jc||hl(e)),n=null,t=e;;){if(t.tag===5||t.tag===26){if(n===null){l=n=t;try{if(o=l.stateNode,a)s=o.style,typeof s.setProperty==`function`?s.setProperty(`display`,`none`,`important`):s.display=`none`;else{c=l.stateNode;var f=l.memoizedProps.style,p=f!=null&&f.hasOwnProperty(`display`)?f.display:null;c.style.display=p==null||typeof p==`boolean`?``:(``+p).trim()}}catch(e){Wu(l,l.return,e)}}}else if(t.tag===6){if(n===null){l=t;try{l.stateNode.nodeValue=a?``:l.memoizedProps}catch(e){Wu(l,l.return,e)}}}else if(t.tag===18){if(n===null){l=t;try{var m=l.stateNode;a?tf(m,!0):tf(l.stateNode,!1)}catch(e){Wu(l,l.return,e)}}}else if((t.tag!==22&&t.tag!==23||t.memoizedState===null||t===e)&&t.child!==null){t.child.return=t,t=t.child;continue}if(t===e)break a;for(;t.sibling===null;){if(t.return===null||t.return===e)break a;n===t&&(n=null),t=t.return}n===t&&(n=null),t.sibling.return=t.return,t=t.sibling}r&4&&(r=e.updateQueue,r!==null&&(n=r.retryQueue,n!==null&&(r.retryQueue=null,cl(e,n))));break;case 19:ll(t,e),fl(e),r&4&&(r=e.updateQueue,r!==null&&(e.updateQueue=null,cl(e,r)));break;case 30:break;case 21:break;default:ll(t,e),fl(e)}}function fl(e){var t=e.flags;if(t&2){try{for(var n,r=e.return;r!==null;){if(Hc(r)){n=r;break}r=r.return}if(n==null)throw Error(i(160));switch(n.tag){case 27:var a=n.stateNode;Gc(e,Uc(e),a);break;case 5:var o=n.stateNode;n.flags&32&&(Ft(o,``),n.flags&=-33),Gc(e,Uc(e),o);break;case 3:case 4:var s=n.stateNode.containerInfo;Wc(e,Uc(e),s);break;default:throw Error(i(161))}}catch(t){Wu(e,e.return,t)}e.flags&=-3}t&4096&&(e.flags&=-4097)}function pl(e){if(e.subtreeFlags&1024)for(e=e.child;e!==null;){var t=e;pl(t),t.tag===5&&t.flags&1024&&t.stateNode.reset(),e=e.sibling}}function ml(e,t){if(t.subtreeFlags&8772)for(t=t.child;t!==null;)$c(e,t.alternate,t),t=t.sibling}function hl(e){for(e=e.child;e!==null;){var t=e;switch(t.tag){case 0:case 11:case 14:case 15:Fc(4,t,t.return),hl(t);break;case 1:zc(t,t.return);var n=t.stateNode;typeof n.componentWillUnmount==`function`&&Lc(t,t.return,n),hl(t);break;case 27:hf(t.stateNode);case 26:case 5:zc(t,t.return),hl(t);break;case 22:t.memoizedState===null&&hl(t);break;case 30:hl(t);break;default:hl(t)}e=e.sibling}}function gl(e,t,n){for(n&&=(t.subtreeFlags&8772)!=0,t=t.child;t!==null;){var r=t.alternate,i=e,a=t,o=a.flags;switch(a.tag){case 0:case 11:case 15:gl(i,a,n),Pc(4,a);break;case 1:if(gl(i,a,n),r=a,i=r.stateNode,typeof i.componentDidMount==`function`)try{i.componentDidMount()}catch(e){Wu(r,r.return,e)}if(r=a,i=r.updateQueue,i!==null){var s=r.stateNode;try{var c=i.shared.hiddenCallbacks;if(c!==null)for(i.shared.hiddenCallbacks=null,i=0;i<c.length;i++)Ra(c[i],s)}catch(e){Wu(r,r.return,e)}}n&&o&64&&Ic(a),Rc(a,a.return);break;case 27:Kc(a);case 26:case 5:gl(i,a,n),n&&r===null&&o&4&&Bc(a),Rc(a,a.return);break;case 12:gl(i,a,n);break;case 31:gl(i,a,n),n&&o&4&&al(i,a);break;case 13:gl(i,a,n),n&&o&4&&ol(i,a);break;case 22:a.memoizedState===null&&gl(i,a,n),Rc(a,a.return);break;case 30:break;default:gl(i,a,n)}t=t.sibling}}function _l(e,t){var n=null;e!==null&&e.memoizedState!==null&&e.memoizedState.cachePool!==null&&(n=e.memoizedState.cachePool.pool),e=null,t.memoizedState!==null&&t.memoizedState.cachePool!==null&&(e=t.memoizedState.cachePool.pool),e!==n&&(e!=null&&e.refCount++,n!=null&&Qi(n))}function vl(e,t){e=null,t.alternate!==null&&(e=t.alternate.memoizedState.cache),t=t.memoizedState.cache,t!==e&&(t.refCount++,e!=null&&Qi(e))}function yl(e,t,n,r){if(t.subtreeFlags&10256)for(t=t.child;t!==null;)bl(e,t,n,r),t=t.sibling}function bl(e,t,n,r){var i=t.flags;switch(t.tag){case 0:case 11:case 15:yl(e,t,n,r),i&2048&&Pc(9,t);break;case 1:yl(e,t,n,r);break;case 3:yl(e,t,n,r),i&2048&&(e=null,t.alternate!==null&&(e=t.alternate.memoizedState.cache),t=t.memoizedState.cache,t!==e&&(t.refCount++,e!=null&&Qi(e)));break;case 12:if(i&2048){yl(e,t,n,r),e=t.stateNode;try{var a=t.memoizedProps,o=a.id,s=a.onPostCommit;typeof s==`function`&&s(o,t.alternate===null?`mount`:`update`,e.passiveEffectDuration,-0)}catch(e){Wu(t,t.return,e)}}else yl(e,t,n,r);break;case 31:yl(e,t,n,r);break;case 13:yl(e,t,n,r);break;case 23:break;case 22:a=t.stateNode,o=t.alternate,t.memoizedState===null?a._visibility&2?yl(e,t,n,r):(a._visibility|=2,xl(e,t,n,r,(t.subtreeFlags&10256)!=0||!1)):a._visibility&2?yl(e,t,n,r):Sl(e,t),i&2048&&_l(o,t);break;case 24:yl(e,t,n,r),i&2048&&vl(t.alternate,t);break;default:yl(e,t,n,r)}}function xl(e,t,n,r,i){for(i&&=(t.subtreeFlags&10256)!=0||!1,t=t.child;t!==null;){var a=e,o=t,s=n,c=r,l=o.flags;switch(o.tag){case 0:case 11:case 15:xl(a,o,s,c,i),Pc(8,o);break;case 23:break;case 22:var u=o.stateNode;o.memoizedState===null?(u._visibility|=2,xl(a,o,s,c,i)):u._visibility&2?xl(a,o,s,c,i):Sl(a,o),i&&l&2048&&_l(o.alternate,o);break;case 24:xl(a,o,s,c,i),i&&l&2048&&vl(o.alternate,o);break;default:xl(a,o,s,c,i)}t=t.sibling}}function Sl(e,t){if(t.subtreeFlags&10256)for(t=t.child;t!==null;){var n=e,r=t,i=r.flags;switch(r.tag){case 22:Sl(n,r),i&2048&&_l(r.alternate,r);break;case 24:Sl(n,r),i&2048&&vl(r.alternate,r);break;default:Sl(n,r)}t=t.sibling}}var Cl=8192;function wl(e,t,n){if(e.subtreeFlags&Cl)for(e=e.child;e!==null;)Tl(e,t,n),e=e.sibling}function Tl(e,t,n){switch(e.tag){case 26:wl(e,t,n),e.flags&Cl&&e.memoizedState!==null&&qf(n,ul,e.memoizedState,e.memoizedProps);break;case 5:wl(e,t,n);break;case 3:case 4:var r=ul;ul=vf(e.stateNode.containerInfo),wl(e,t,n),ul=r;break;case 22:e.memoizedState===null&&(r=e.alternate,r!==null&&r.memoizedState!==null?(r=Cl,Cl=16777216,wl(e,t,n),Cl=r):wl(e,t,n));break;default:wl(e,t,n)}}function El(e){var t=e.alternate;if(t!==null&&(e=t.child,e!==null)){t.child=null;do t=e.sibling,e.sibling=null,e=t;while(e!==null)}}function Dl(e){var t=e.deletions;if(e.flags&16){if(t!==null)for(var n=0;n<t.length;n++){var r=t[n];Zc=r,Al(r,e)}El(e)}if(e.subtreeFlags&10256)for(e=e.child;e!==null;)Ol(e),e=e.sibling}function Ol(e){switch(e.tag){case 0:case 11:case 15:Dl(e),e.flags&2048&&Fc(9,e,e.return);break;case 3:Dl(e);break;case 12:Dl(e);break;case 22:var t=e.stateNode;e.memoizedState!==null&&t._visibility&2&&(e.return===null||e.return.tag!==13)?(t._visibility&=-3,kl(e)):Dl(e);break;default:Dl(e)}}function kl(e){var t=e.deletions;if(e.flags&16){if(t!==null)for(var n=0;n<t.length;n++){var r=t[n];Zc=r,Al(r,e)}El(e)}for(e=e.child;e!==null;){switch(t=e,t.tag){case 0:case 11:case 15:Fc(8,t,t.return),kl(t);break;case 22:n=t.stateNode,n._visibility&2&&(n._visibility&=-3,kl(t));break;default:kl(t)}e=e.sibling}}function Al(e,t){for(;Zc!==null;){var n=Zc;switch(n.tag){case 0:case 11:case 15:Fc(8,n,t);break;case 23:case 22:if(n.memoizedState!==null&&n.memoizedState.cachePool!==null){var r=n.memoizedState.cachePool.pool;r!=null&&r.refCount++}break;case 24:Qi(n.memoizedState.cache)}if(r=n.child,r!==null)r.return=n,Zc=r;else a:for(n=e;Zc!==null;){r=Zc;var i=r.sibling,a=r.return;if(el(r),r===n){Zc=null;break a}if(i!==null){i.return=a,Zc=i;break a}Zc=a}}}var jl={getCacheForType:function(e){var t=Wi(Xi),n=t.data.get(e);return n===void 0&&(n=e(),t.data.set(e,n)),n},cacheSignal:function(){return Wi(Xi).controller.signal}},Ml=typeof WeakMap==`function`?WeakMap:Map,Nl=0,Pl=null,Fl=null,Il=0,Ll=0,Rl=null,zl=!1,Bl=!1,Vl=!1,Hl=0,Ul=0,Wl=0,Gl=0,Kl=0,ql=0,Jl=0,Yl=null,Xl=null,Zl=!1,Ql=0,$l=0,eu=1/0,tu=null,nu=null,ru=0,iu=null,au=null,ou=0,su=0,cu=null,lu=null,uu=0,du=null;function fu(){return Nl&2&&Il!==0?Il&-Il:N.T===null?qe():dd()}function pu(){if(ql===0)if(!(Il&536870912)||Ci){var e=Me;Me<<=1,!(Me&3932160)&&(Me=262144),ql=e}else ql=536870912;return e=Ga.current,e!==null&&(e.flags|=32),ql}function mu(e,t,n){(e===Pl&&(Ll===2||Ll===9)||e.cancelPendingCommit!==null)&&(xu(e,0),vu(e,Il,ql,!1)),Be(e,n),(!(Nl&2)||e!==Pl)&&(e===Pl&&(!(Nl&2)&&(Gl|=n),Ul===4&&vu(e,Il,ql,!1)),rd(e))}function hu(e,t,n){if(Nl&6)throw Error(i(327));var r=!n&&(t&127)==0&&(t&e.expiredLanes)===0||Ie(e,t),a=r?ku(e,t):Du(e,t,!0),o=r;do{if(a===0){Bl&&!r&&vu(e,t,0,!1);break}else{if(n=e.current.alternate,o&&!_u(n)){a=Du(e,t,!1),o=!1;continue}if(a===2){if(o=t,e.errorRecoveryDisabledLanes&o)var s=0;else s=e.pendingLanes&-536870913,s=s===0?s&536870912?536870912:0:s;if(s!==0){t=s;a:{var c=e;a=Yl;var l=c.current.memoizedState.isDehydrated;if(l&&(xu(c,s).flags|=256),s=Du(c,s,!1),s!==2){if(Vl&&!l){c.errorRecoveryDisabledLanes|=o,Gl|=o,a=4;break a}o=Xl,Xl=a,o!==null&&(Xl===null?Xl=o:Xl.push.apply(Xl,o))}a=s}if(o=!1,a!==2)continue}}if(a===1){xu(e,0),vu(e,t,0,!0);break}a:{switch(r=e,o=a,o){case 0:case 1:throw Error(i(345));case 4:if((t&4194048)!==t)break;case 6:vu(r,t,ql,!zl);break a;case 2:Xl=null;break;case 3:case 5:break;default:throw Error(i(329))}if((t&62914560)===t&&(a=Ql+300-he(),10<a)){if(vu(r,t,ql,!zl),Fe(r,0,!0)!==0)break a;ou=t,r.timeoutHandle=Jd(gu.bind(null,r,n,Xl,tu,Zl,t,ql,Gl,Jl,zl,o,`Throttled`,-0,0),a);break a}gu(r,n,Xl,tu,Zl,t,ql,Gl,Jl,zl,o,null,-0,0)}}break}while(1);rd(e)}function gu(e,t,n,r,i,a,o,s,c,l,u,d,f,p){if(e.timeoutHandle=-1,d=t.subtreeFlags,d&8192||(d&16785408)==16785408){d={stylesheets:null,count:0,imgCount:0,imgBytes:0,suspenseyImages:[],waitingForImages:!0,waitingForViewTransition:!1,unsuspend:Ut},Tl(t,a,d);var m=(a&62914560)===a?Ql-he():(a&4194048)===a?$l-he():0;if(m=Yf(d,m),m!==null){ou=a,e.cancelPendingCommit=m(Iu.bind(null,e,t,a,n,r,i,o,s,c,u,d,null,f,p)),vu(e,a,o,!l);return}}Iu(e,t,a,n,r,i,o,s,c)}function _u(e){for(var t=e;;){var n=t.tag;if((n===0||n===11||n===15)&&t.flags&16384&&(n=t.updateQueue,n!==null&&(n=n.stores,n!==null)))for(var r=0;r<n.length;r++){var i=n[r],a=i.getSnapshot;i=i.value;try{if(!dr(a(),i))return!1}catch{return!1}}if(n=t.child,t.subtreeFlags&16384&&n!==null)n.return=t,t=n;else{if(t===e)break;for(;t.sibling===null;){if(t.return===null||t.return===e)return!0;t=t.return}t.sibling.return=t.return,t=t.sibling}}return!0}function vu(e,t,n,r){t&=~Kl,t&=~Gl,e.suspendedLanes|=t,e.pingedLanes&=~t,r&&(e.warmLanes|=t),r=e.expirationTimes;for(var i=t;0<i;){var a=31-De(i),o=1<<a;r[a]=-1,i&=~o}n!==0&&He(e,n,t)}function yu(){return Nl&6?!0:(id(0,!1),!1)}function bu(){if(Fl!==null){if(Ll===0)var e=Fl.return;else e=Fl,Ii=Fi=null,bo(e),ba=null,xa=0,e=Fl;for(;e!==null;)Nc(e.alternate,e),e=e.return;Fl=null}}function xu(e,t){var n=e.timeoutHandle;n!==-1&&(e.timeoutHandle=-1,Yd(n)),n=e.cancelPendingCommit,n!==null&&(e.cancelPendingCommit=null,n()),ou=0,bu(),Pl=e,Fl=n=Qr(e.current,null),Il=t,Ll=0,Rl=null,zl=!1,Bl=Ie(e,t),Vl=!1,Jl=ql=Kl=Gl=Wl=Ul=0,Xl=Yl=null,Zl=!1,t&8&&(t|=t&32);var r=e.entangledLanes;if(r!==0)for(e=e.entanglements,r&=t;0<r;){var i=31-De(r),a=1<<i;t|=e[i],r&=~a}return Hl=t,Hr(),n}function Su(e,t){to=null,N.H=As,t===ua||t===fa?(t=va(),Ll=3):t===da?(t=va(),Ll=4):Ll=t===Js?8:typeof t==`object`&&t&&typeof t.then==`function`?6:1,Rl=t,Fl===null&&(Ul=1,Hs(e,oi(t,e.current)))}function Cu(){var e=Ga.current;return e===null?!0:(Il&4194048)===Il?Ka===null:(Il&62914560)===Il||Il&536870912?e===Ka:!1}function wu(){var e=N.H;return N.H=As,e===null?As:e}function Tu(){var e=N.A;return N.A=jl,e}function Eu(){Ul=4,zl||(Il&4194048)!==Il&&Ga.current!==null||(Bl=!0),!(Wl&134217727)&&!(Gl&134217727)||Pl===null||vu(Pl,Il,ql,!1)}function Du(e,t,n){var r=Nl;Nl|=2;var i=wu(),a=Tu();(Pl!==e||Il!==t)&&(tu=null,xu(e,t)),t=!1;var o=Ul;a:do try{if(Ll!==0&&Fl!==null){var s=Fl,c=Rl;switch(Ll){case 8:bu(),o=6;break a;case 3:case 2:case 9:case 6:Ga.current===null&&(t=!0);var l=Ll;if(Ll=0,Rl=null,Nu(e,s,c,l),n&&Bl){o=0;break a}break;default:l=Ll,Ll=0,Rl=null,Nu(e,s,c,l)}}Ou(),o=Ul;break}catch(t){Su(e,t)}while(1);return t&&e.shellSuspendCounter++,Ii=Fi=null,Nl=r,N.H=i,N.A=a,Fl===null&&(Pl=null,Il=0,Hr()),o}function Ou(){for(;Fl!==null;)ju(Fl)}function ku(e,t){var n=Nl;Nl|=2;var r=wu(),a=Tu();Pl!==e||Il!==t?(tu=null,eu=he()+500,xu(e,t)):Bl=Ie(e,t);a:do try{if(Ll!==0&&Fl!==null){t=Fl;var o=Rl;b:switch(Ll){case 1:Ll=0,Rl=null,Nu(e,t,o,1);break;case 2:case 9:if(ma(o)){Ll=0,Rl=null,Mu(t);break}t=function(){Ll!==2&&Ll!==9||Pl!==e||(Ll=7),rd(e)},o.then(t,t);break a;case 3:Ll=7;break a;case 4:Ll=5;break a;case 7:ma(o)?(Ll=0,Rl=null,Mu(t)):(Ll=0,Rl=null,Nu(e,t,o,7));break;case 5:var s=null;switch(Fl.tag){case 26:s=Fl.memoizedState;case 5:case 27:var c=Fl;if(s?Kf(s):c.stateNode.complete){Ll=0,Rl=null;var l=c.sibling;if(l!==null)Fl=l;else{var u=c.return;u===null?Fl=null:(Fl=u,Pu(u))}break b}}Ll=0,Rl=null,Nu(e,t,o,5);break;case 6:Ll=0,Rl=null,Nu(e,t,o,6);break;case 8:bu(),Ul=6;break a;default:throw Error(i(462))}}Au();break}catch(t){Su(e,t)}while(1);return Ii=Fi=null,N.H=r,N.A=a,Nl=n,Fl===null?(Pl=null,Il=0,Hr(),Ul):0}function Au(){for(;Fl!==null&&!pe();)ju(Fl)}function ju(e){var t=wc(e.alternate,e,Hl);e.memoizedProps=e.pendingProps,t===null?Pu(e):Fl=t}function Mu(e){var t=e,n=t.alternate;switch(t.tag){case 15:case 0:t=cc(n,t,t.pendingProps,t.type,void 0,Il);break;case 11:t=cc(n,t,t.pendingProps,t.type.render,t.ref,Il);break;case 5:bo(t);default:Nc(n,t),t=Fl=$r(t,Hl),t=wc(n,t,Hl)}e.memoizedProps=e.pendingProps,t===null?Pu(e):Fl=t}function Nu(e,t,n,r){Ii=Fi=null,bo(t),ba=null,xa=0;var i=t.return;try{if(qs(e,i,t,n,Il)){Ul=1,Hs(e,oi(n,e.current)),Fl=null;return}}catch(t){if(i!==null)throw Fl=i,t;Ul=1,Hs(e,oi(n,e.current)),Fl=null;return}t.flags&32768?(Ci||r===1?e=!0:Bl||Il&536870912?e=!1:(zl=e=!0,(r===2||r===9||r===3||r===6)&&(r=Ga.current,r!==null&&r.tag===13&&(r.flags|=16384))),Fu(t,e)):Pu(t)}function Pu(e){var t=e;do{if(t.flags&32768){Fu(t,zl);return}e=t.return;var n=jc(t.alternate,t,Hl);if(n!==null){Fl=n;return}if(t=t.sibling,t!==null){Fl=t;return}Fl=t=e}while(t!==null);Ul===0&&(Ul=5)}function Fu(e,t){do{var n=Mc(e.alternate,e);if(n!==null){n.flags&=32767,Fl=n;return}if(n=e.return,n!==null&&(n.flags|=32768,n.subtreeFlags=0,n.deletions=null),!t&&(e=e.sibling,e!==null)){Fl=e;return}Fl=e=n}while(e!==null);Ul=6,Fl=null}function Iu(e,t,n,r,a,o,s,c,l){e.cancelPendingCommit=null;do Vu();while(ru!==0);if(Nl&6)throw Error(i(327));if(t!==null){if(t===e.current)throw Error(i(177));if(o=t.lanes|t.childLanes,o|=Vr,Ve(e,n,o,s,c,l),e===Pl&&(Fl=Pl=null,Il=0),au=t,iu=e,ou=n,su=o,cu=a,lu=r,t.subtreeFlags&10256||t.flags&10256?(e.callbackNode=null,e.callbackPriority=0,Xu(ye,function(){return Hu(),null})):(e.callbackNode=null,e.callbackPriority=0),r=(t.flags&13878)!=0,t.subtreeFlags&13878||r){r=N.T,N.T=null,a=P.p,P.p=2,s=Nl,Nl|=4;try{Qc(e,t,n)}finally{Nl=s,P.p=a,N.T=r}}ru=1,Lu(),Ru(),zu()}}function Lu(){if(ru===1){ru=0;var e=iu,t=au,n=(t.flags&13878)!=0;if(t.subtreeFlags&13878||n){n=N.T,N.T=null;var r=P.p;P.p=2;var i=Nl;Nl|=4;try{dl(t,e);var a=Vd,o=gr(e.containerInfo),s=a.focusedElem,c=a.selectionRange;if(o!==s&&s&&s.ownerDocument&&hr(s.ownerDocument.documentElement,s)){if(c!==null&&_r(s)){var l=c.start,u=c.end;if(u===void 0&&(u=l),`selectionStart`in s)s.selectionStart=l,s.selectionEnd=Math.min(u,s.value.length);else{var d=s.ownerDocument||document,f=d&&d.defaultView||window;if(f.getSelection){var p=f.getSelection(),m=s.textContent.length,h=Math.min(c.start,m),g=c.end===void 0?h:Math.min(c.end,m);!p.extend&&h>g&&(o=g,g=h,h=o);var _=mr(s,h),v=mr(s,g);if(_&&v&&(p.rangeCount!==1||p.anchorNode!==_.node||p.anchorOffset!==_.offset||p.focusNode!==v.node||p.focusOffset!==v.offset)){var y=d.createRange();y.setStart(_.node,_.offset),p.removeAllRanges(),h>g?(p.addRange(y),p.extend(v.node,v.offset)):(y.setEnd(v.node,v.offset),p.addRange(y))}}}}for(d=[],p=s;p=p.parentNode;)p.nodeType===1&&d.push({element:p,left:p.scrollLeft,top:p.scrollTop});for(typeof s.focus==`function`&&s.focus(),s=0;s<d.length;s++){var b=d[s];b.element.scrollLeft=b.left,b.element.scrollTop=b.top}}lp=!!Bd,Vd=Bd=null}finally{Nl=i,P.p=r,N.T=n}}e.current=t,ru=2}}function Ru(){if(ru===2){ru=0;var e=iu,t=au,n=(t.flags&8772)!=0;if(t.subtreeFlags&8772||n){n=N.T,N.T=null;var r=P.p;P.p=2;var i=Nl;Nl|=4;try{$c(e,t.alternate,t)}finally{Nl=i,P.p=r,N.T=n}}ru=3}}function zu(){if(ru===4||ru===3){ru=0,me();var e=iu,t=au,n=ou,r=lu;t.subtreeFlags&10256||t.flags&10256?ru=5:(ru=0,au=iu=null,Bu(e,e.pendingLanes));var i=e.pendingLanes;if(i===0&&(nu=null),Ke(n),t=t.stateNode,Te&&typeof Te.onCommitFiberRoot==`function`)try{Te.onCommitFiberRoot(we,t,void 0,(t.current.flags&128)==128)}catch{}if(r!==null){t=N.T,i=P.p,P.p=2,N.T=null;try{for(var a=e.onRecoverableError,o=0;o<r.length;o++){var s=r[o];a(s.value,{componentStack:s.stack})}}finally{N.T=t,P.p=i}}ou&3&&Vu(),rd(e),i=e.pendingLanes,n&261930&&i&42?e===du?uu++:(uu=0,du=e):uu=0,id(0,!1)}}function Bu(e,t){(e.pooledCacheLanes&=t)===0&&(t=e.pooledCache,t!=null&&(e.pooledCache=null,Qi(t)))}function Vu(){return Lu(),Ru(),zu(),Hu()}function Hu(){if(ru!==5)return!1;var e=iu,t=su;su=0;var n=Ke(ou),r=N.T,a=P.p;try{P.p=32>n?32:n,N.T=null,n=cu,cu=null;var o=iu,s=ou;if(ru=0,au=iu=null,ou=0,Nl&6)throw Error(i(331));var c=Nl;if(Nl|=4,Ol(o.current),bl(o,o.current,s,n),Nl=c,id(0,!1),Te&&typeof Te.onPostCommitFiberRoot==`function`)try{Te.onPostCommitFiberRoot(we,o)}catch{}return!0}finally{P.p=a,N.T=r,Bu(e,t)}}function Uu(e,t,n){t=oi(n,t),t=Ws(e.stateNode,t,2),e=Ma(e,t,2),e!==null&&(Be(e,2),rd(e))}function Wu(e,t,n){if(e.tag===3)Uu(e,e,n);else for(;t!==null;){if(t.tag===3){Uu(t,e,n);break}else if(t.tag===1){var r=t.stateNode;if(typeof t.type.getDerivedStateFromError==`function`||typeof r.componentDidCatch==`function`&&(nu===null||!nu.has(r))){e=oi(n,e),n=Gs(2),r=Ma(t,n,2),r!==null&&(Ks(n,r,t,e),Be(r,2),rd(r));break}}t=t.return}}function Gu(e,t,n){var r=e.pingCache;if(r===null){r=e.pingCache=new Ml;var i=new Set;r.set(t,i)}else i=r.get(t),i===void 0&&(i=new Set,r.set(t,i));i.has(n)||(Vl=!0,i.add(n),e=Ku.bind(null,e,t,n),t.then(e,e))}function Ku(e,t,n){var r=e.pingCache;r!==null&&r.delete(t),e.pingedLanes|=e.suspendedLanes&n,e.warmLanes&=~n,Pl===e&&(Il&n)===n&&(Ul===4||Ul===3&&(Il&62914560)===Il&&300>he()-Ql?!(Nl&2)&&xu(e,0):Kl|=n,Jl===Il&&(Jl=0)),rd(e)}function qu(e,t){t===0&&(t=Re()),e=Gr(e,t),e!==null&&(Be(e,t),rd(e))}function Ju(e){var t=e.memoizedState,n=0;t!==null&&(n=t.retryLane),qu(e,n)}function Yu(e,t){var n=0;switch(e.tag){case 31:case 13:var r=e.stateNode,a=e.memoizedState;a!==null&&(n=a.retryLane);break;case 19:r=e.stateNode;break;case 22:r=e.stateNode._retryCache;break;default:throw Error(i(314))}r!==null&&r.delete(t),qu(e,n)}function Xu(e,t){return de(e,t)}var Zu=null,Qu=null,$u=!1,ed=!1,td=!1,nd=0;function rd(e){e!==Qu&&e.next===null&&(Qu===null?Zu=Qu=e:Qu=Qu.next=e),ed=!0,$u||($u=!0,ud())}function id(e,t){if(!td&&ed){td=!0;do for(var n=!1,r=Zu;r!==null;){if(!t)if(e!==0){var i=r.pendingLanes;if(i===0)var a=0;else{var o=r.suspendedLanes,s=r.pingedLanes;a=(1<<31-De(42|e)+1)-1,a&=i&~(o&~s),a=a&201326741?a&201326741|1:a?a|2:0}a!==0&&(n=!0,ld(r,a))}else a=Il,a=Fe(r,r===Pl?a:0,r.cancelPendingCommit!==null||r.timeoutHandle!==-1),!(a&3)||Ie(r,a)||(n=!0,ld(r,a));r=r.next}while(n);td=!1}}function ad(){od()}function od(){ed=$u=!1;var e=0;nd!==0&&qd()&&(e=nd);for(var t=he(),n=null,r=Zu;r!==null;){var i=r.next,a=sd(r,t);a===0?(r.next=null,n===null?Zu=i:n.next=i,i===null&&(Qu=n)):(n=r,(e!==0||a&3)&&(ed=!0)),r=i}ru!==0&&ru!==5||id(e,!1),nd!==0&&(nd=0)}function sd(e,t){for(var n=e.suspendedLanes,r=e.pingedLanes,i=e.expirationTimes,a=e.pendingLanes&-62914561;0<a;){var o=31-De(a),s=1<<o,c=i[o];c===-1?((s&n)===0||(s&r)!==0)&&(i[o]=Le(s,t)):c<=t&&(e.expiredLanes|=s),a&=~s}if(t=Pl,n=Il,n=Fe(e,e===t?n:0,e.cancelPendingCommit!==null||e.timeoutHandle!==-1),r=e.callbackNode,n===0||e===t&&(Ll===2||Ll===9)||e.cancelPendingCommit!==null)return r!==null&&r!==null&&fe(r),e.callbackNode=null,e.callbackPriority=0;if(!(n&3)||Ie(e,n)){if(t=n&-n,t===e.callbackPriority)return t;switch(r!==null&&fe(r),Ke(n)){case 2:case 8:n=ve;break;case 32:n=ye;break;case 268435456:n=xe;break;default:n=ye}return r=cd.bind(null,e),n=de(n,r),e.callbackPriority=t,e.callbackNode=n,t}return r!==null&&r!==null&&fe(r),e.callbackPriority=2,e.callbackNode=null,2}function cd(e,t){if(ru!==0&&ru!==5)return e.callbackNode=null,e.callbackPriority=0,null;var n=e.callbackNode;if(Vu()&&e.callbackNode!==n)return null;var r=Il;return r=Fe(e,e===Pl?r:0,e.cancelPendingCommit!==null||e.timeoutHandle!==-1),r===0?null:(hu(e,r,t),sd(e,he()),e.callbackNode!=null&&e.callbackNode===n?cd.bind(null,e):null)}function ld(e,t){if(Vu())return null;hu(e,t,!0)}function ud(){Zd(function(){Nl&6?de(_e,ad):od()})}function dd(){if(nd===0){var e=ta;e===0&&(e=je,je<<=1,!(je&261888)&&(je=256)),nd=e}return nd}function fd(e){return e==null||typeof e==`symbol`||typeof e==`boolean`?null:typeof e==`function`?e:Ht(``+e)}function pd(e,t){var n=t.ownerDocument.createElement(`input`);return n.name=t.name,n.value=t.value,e.id&&n.setAttribute(`form`,e.id),t.parentNode.insertBefore(n,t),e=new FormData(e),n.parentNode.removeChild(n),e}function md(e,t,n,r,i){if(t===`submit`&&n&&n.stateNode===i){var a=fd((i[Ze]||null).action),o=r.submitter;o&&(t=(t=o[Ze]||null)?fd(t.formAction):o.getAttribute(`formAction`),t!==null&&(a=t,o=null));var s=new dn(`action`,`action`,null,r,i);e.push({event:s,listeners:[{instance:null,listener:function(){if(r.defaultPrevented){if(nd!==0){var e=o?pd(i,o):new FormData(i);gs(n,{pending:!0,data:e,method:i.method,action:a},null,e)}}else typeof a==`function`&&(s.preventDefault(),e=o?pd(i,o):new FormData(i),gs(n,{pending:!0,data:e,method:i.method,action:a},a,e))},currentTarget:i}]})}}for(var hd=0;hd<Ir.length;hd++){var gd=Ir[hd];Lr(gd.toLowerCase(),`on`+(gd[0].toUpperCase()+gd.slice(1)))}Lr(kr,`onAnimationEnd`),Lr(Ar,`onAnimationIteration`),Lr(jr,`onAnimationStart`),Lr(`dblclick`,`onDoubleClick`),Lr(`focusin`,`onFocus`),Lr(`focusout`,`onBlur`),Lr(Mr,`onTransitionRun`),Lr(Nr,`onTransitionStart`),Lr(Pr,`onTransitionCancel`),Lr(Fr,`onTransitionEnd`),pt(`onMouseEnter`,[`mouseout`,`mouseover`]),pt(`onMouseLeave`,[`mouseout`,`mouseover`]),pt(`onPointerEnter`,[`pointerout`,`pointerover`]),pt(`onPointerLeave`,[`pointerout`,`pointerover`]),ft(`onChange`,`change click focusin focusout input keydown keyup selectionchange`.split(` `)),ft(`onSelect`,`focusout contextmenu dragend focusin keydown keyup mousedown mouseup selectionchange`.split(` `)),ft(`onBeforeInput`,[`compositionend`,`keypress`,`textInput`,`paste`]),ft(`onCompositionEnd`,`compositionend focusout keydown keypress keyup mousedown`.split(` `)),ft(`onCompositionStart`,`compositionstart focusout keydown keypress keyup mousedown`.split(` `)),ft(`onCompositionUpdate`,`compositionupdate focusout keydown keypress keyup mousedown`.split(` `));var _d=`abort canplay canplaythrough durationchange emptied encrypted ended error loadeddata loadedmetadata loadstart pause play playing progress ratechange resize seeked seeking stalled suspend timeupdate volumechange waiting`.split(` `),vd=new Set(`beforetoggle cancel close invalid load scroll scrollend toggle`.split(` `).concat(_d));function yd(e,t){t=(t&4)!=0;for(var n=0;n<e.length;n++){var r=e[n],i=r.event;r=r.listeners;a:{var a=void 0;if(t)for(var o=r.length-1;0<=o;o--){var s=r[o],c=s.instance,l=s.currentTarget;if(s=s.listener,c!==a&&i.isPropagationStopped())break a;a=s,i.currentTarget=l;try{a(i)}catch(e){Rr(e)}i.currentTarget=null,a=c}else for(o=0;o<r.length;o++){if(s=r[o],c=s.instance,l=s.currentTarget,s=s.listener,c!==a&&i.isPropagationStopped())break a;a=s,i.currentTarget=l;try{a(i)}catch(e){Rr(e)}i.currentTarget=null,a=c}}}}function bd(e,t){var n=t[$e];n===void 0&&(n=t[$e]=new Set);var r=e+`__bubble`;n.has(r)||(wd(t,e,2,!1),n.add(r))}function xd(e,t,n){var r=0;t&&(r|=4),wd(n,e,r,t)}var Sd=`_reactListening`+Math.random().toString(36).slice(2);function Cd(e){if(!e[Sd]){e[Sd]=!0,ut.forEach(function(t){t!==`selectionchange`&&(vd.has(t)||xd(t,!1,e),xd(t,!0,e))});var t=e.nodeType===9?e:e.ownerDocument;t===null||t[Sd]||(t[Sd]=!0,xd(`selectionchange`,!1,t))}}function wd(e,t,n,r){switch(gp(t)){case 2:var i=up;break;case 8:i=dp;break;default:i=fp}n=i.bind(null,t,n,e),i=void 0,!$t||t!==`touchstart`&&t!==`touchmove`&&t!==`wheel`||(i=!0),r?i===void 0?e.addEventListener(t,n,!0):e.addEventListener(t,n,{capture:!0,passive:i}):i===void 0?e.addEventListener(t,n,!1):e.addEventListener(t,n,{passive:i})}function Td(e,t,n,r,i){var a=r;if(!(t&1)&&!(t&2)&&r!==null)a:for(;;){if(r===null)return;var s=r.tag;if(s===3||s===4){var c=r.stateNode.containerInfo;if(c===i)break;if(s===4)for(s=r.return;s!==null;){var l=s.tag;if((l===3||l===4)&&s.stateNode.containerInfo===i)return;s=s.return}for(;c!==null;){if(s=at(c),s===null)return;if(l=s.tag,l===5||l===6||l===26||l===27){r=a=s;continue a}c=c.parentNode}}r=r.return}Xt(function(){var r=a,i=Gt(n),s=[];a:{var c=q.get(e);if(c!==void 0){var l=dn,u=e;switch(e){case`keypress`:if(on(n)===0)break a;case`keydown`:case`keyup`:l=On;break;case`focusin`:u=`focus`,l=bn;break;case`focusout`:u=`blur`,l=bn;break;case`beforeblur`:case`afterblur`:l=bn;break;case`click`:if(n.button===2)break a;case`auxclick`:case`dblclick`:case`mousedown`:case`mousemove`:case`mouseup`:case`mouseout`:case`mouseover`:case`contextmenu`:l=vn;break;case`drag`:case`dragend`:case`dragenter`:case`dragexit`:case`dragleave`:case`dragover`:case`dragstart`:case`drop`:l=yn;break;case`touchcancel`:case`touchend`:case`touchmove`:case`touchstart`:l=An;break;case kr:case Ar:case jr:l=xn;break;case Fr:l=jn;break;case`scroll`:case`scrollend`:l=pn;break;case`wheel`:l=Mn;break;case`copy`:case`cut`:case`paste`:l=Sn;break;case`gotpointercapture`:case`lostpointercapture`:case`pointercancel`:case`pointerdown`:case`pointermove`:case`pointerout`:case`pointerover`:case`pointerup`:l=kn;break;case`toggle`:case`beforetoggle`:l=Nn}var d=(t&4)!=0,f=!d&&(e===`scroll`||e===`scrollend`),p=d?c===null?null:c+`Capture`:c;d=[];for(var m=r,h;m!==null;){var g=m;if(h=g.stateNode,g=g.tag,g!==5&&g!==26&&g!==27||h===null||p===null||(g=Zt(m,p),g!=null&&d.push(Ed(m,g,h))),f)break;m=m.return}0<d.length&&(c=new l(c,u,null,n,i),s.push({event:c,listeners:d}))}}if(!(t&7)){a:{if(c=e===`mouseover`||e===`pointerover`,l=e===`mouseout`||e===`pointerout`,c&&n!==Wt&&(u=n.relatedTarget||n.fromElement)&&(at(u)||u[Qe]))break a;if((l||c)&&(c=i.window===i?i:(c=i.ownerDocument)?c.defaultView||c.parentWindow:window,l?(u=n.relatedTarget||n.toElement,l=r,u=u?at(u):null,u!==null&&(f=o(u),d=u.tag,u!==f||d!==5&&d!==27&&d!==6)&&(u=null)):(l=null,u=r),l!==u)){if(d=vn,g=`onMouseLeave`,p=`onMouseEnter`,m=`mouse`,(e===`pointerout`||e===`pointerover`)&&(d=kn,g=`onPointerLeave`,p=`onPointerEnter`,m=`pointer`),f=l==null?c:st(l),h=u==null?c:st(u),c=new d(g,m+`leave`,l,n,i),c.target=f,c.relatedTarget=h,g=null,at(i)===r&&(d=new d(p,m+`enter`,u,n,i),d.target=h,d.relatedTarget=f,g=d),f=g,l&&u)b:{for(d=Od,p=l,m=u,h=0,g=p;g;g=d(g))h++;g=0;for(var _=m;_;_=d(_))g++;for(;0<h-g;)p=d(p),h--;for(;0<g-h;)m=d(m),g--;for(;h--;){if(p===m||m!==null&&p===m.alternate){d=p;break b}p=d(p),m=d(m)}d=null}else d=null;l!==null&&kd(s,c,l,d,!1),u!==null&&f!==null&&kd(s,f,u,d,!0)}}a:{if(c=r?st(r):window,l=c.nodeName&&c.nodeName.toLowerCase(),l===`select`||l===`input`&&c.type===`file`)var v=$n;else if(qn(c))if(er)v=lr;else{v=sr;var y=or}else l=c.nodeName,!l||l.toLowerCase()!==`input`||c.type!==`checkbox`&&c.type!==`radio`?r&&zt(r.elementType)&&(v=$n):v=cr;if(v&&=v(e,r)){Jn(s,v,n,i);break a}y&&y(e,c,r),e===`focusout`&&r&&c.type===`number`&&r.memoizedProps.value!=null&&jt(c,`number`,c.value)}switch(y=r?st(r):window,e){case`focusin`:(qn(y)||y.contentEditable===`true`)&&(yr=y,br=r,xr=null);break;case`focusout`:xr=br=yr=null;break;case`mousedown`:Sr=!0;break;case`contextmenu`:case`mouseup`:case`dragend`:Sr=!1,Cr(s,n,i);break;case`selectionchange`:if(vr)break;case`keydown`:case`keyup`:Cr(s,n,i)}var b;if(Fn)b:{switch(e){case`compositionstart`:var x=`onCompositionStart`;break b;case`compositionend`:x=`onCompositionEnd`;break b;case`compositionupdate`:x=`onCompositionUpdate`;break b}x=void 0}else Un?Vn(e,n)&&(x=`onCompositionEnd`):e===`keydown`&&n.keyCode===229&&(x=`onCompositionStart`);x&&(Rn&&n.locale!==`ko`&&(Un||x!==`onCompositionStart`?x===`onCompositionEnd`&&Un&&(b=an()):(tn=i,nn=`value`in tn?tn.value:tn.textContent,Un=!0)),y=Dd(r,x),0<y.length&&(x=new Cn(x,e,null,n,i),s.push({event:x,listeners:y}),b?x.data=b:(b=Hn(n),b!==null&&(x.data=b)))),(b=Ln?Wn(e,n):Gn(e,n))&&(x=Dd(r,`onBeforeInput`),0<x.length&&(y=new Cn(`onBeforeInput`,`beforeinput`,null,n,i),s.push({event:y,listeners:x}),y.data=b)),md(s,e,r,n,i)}yd(s,t)})}function Ed(e,t,n){return{instance:e,listener:t,currentTarget:n}}function Dd(e,t){for(var n=t+`Capture`,r=[];e!==null;){var i=e,a=i.stateNode;if(i=i.tag,i!==5&&i!==26&&i!==27||a===null||(i=Zt(e,n),i!=null&&r.unshift(Ed(e,i,a)),i=Zt(e,t),i!=null&&r.push(Ed(e,i,a))),e.tag===3)return r;e=e.return}return[]}function Od(e){if(e===null)return null;do e=e.return;while(e&&e.tag!==5&&e.tag!==27);return e||null}function kd(e,t,n,r,i){for(var a=t._reactName,o=[];n!==null&&n!==r;){var s=n,c=s.alternate,l=s.stateNode;if(s=s.tag,c!==null&&c===r)break;s!==5&&s!==26&&s!==27||l===null||(c=l,i?(l=Zt(n,a),l!=null&&o.unshift(Ed(n,l,c))):i||(l=Zt(n,a),l!=null&&o.push(Ed(n,l,c)))),n=n.return}o.length!==0&&e.push({event:t,listeners:o})}var Ad=/\r\n?/g,jd=/\u0000|\uFFFD/g;function Md(e){return(typeof e==`string`?e:``+e).replace(Ad,`
|
|
91
|
-
`).replace(jd,``)}function Nd(e,t){return t=Md(t),Md(e)===t}function Pd(e,t,n,r,a,o){switch(n){case`children`:typeof r==`string`?t===`body`||t===`textarea`&&r===``||Ft(e,r):(typeof r==`number`||typeof r==`bigint`)&&t!==`body`&&Ft(e,``+r);break;case`className`:yt(e,`class`,r);break;case`tabIndex`:yt(e,`tabindex`,r);break;case`dir`:case`role`:case`viewBox`:case`width`:case`height`:yt(e,n,r);break;case`style`:Rt(e,r,o);break;case`data`:if(t!==`object`){yt(e,`data`,r);break}case`src`:case`href`:if(r===``&&(t!==`a`||n!==`href`)){e.removeAttribute(n);break}if(r==null||typeof r==`function`||typeof r==`symbol`||typeof r==`boolean`){e.removeAttribute(n);break}r=Ht(``+r),e.setAttribute(n,r);break;case`action`:case`formAction`:if(typeof r==`function`){e.setAttribute(n,`javascript:throw new Error('A React form was unexpectedly submitted. If you called form.submit() manually, consider using form.requestSubmit() instead. If you\\'re trying to use event.stopPropagation() in a submit event handler, consider also calling event.preventDefault().')`);break}else typeof o==`function`&&(n===`formAction`?(t!==`input`&&Pd(e,t,`name`,a.name,a,null),Pd(e,t,`formEncType`,a.formEncType,a,null),Pd(e,t,`formMethod`,a.formMethod,a,null),Pd(e,t,`formTarget`,a.formTarget,a,null)):(Pd(e,t,`encType`,a.encType,a,null),Pd(e,t,`method`,a.method,a,null),Pd(e,t,`target`,a.target,a,null)));if(r==null||typeof r==`symbol`||typeof r==`boolean`){e.removeAttribute(n);break}r=Ht(``+r),e.setAttribute(n,r);break;case`onClick`:r!=null&&(e.onclick=Ut);break;case`onScroll`:r!=null&&bd(`scroll`,e);break;case`onScrollEnd`:r!=null&&bd(`scrollend`,e);break;case`dangerouslySetInnerHTML`:if(r!=null){if(typeof r!=`object`||!(`__html`in r))throw Error(i(61));if(n=r.__html,n!=null){if(a.children!=null)throw Error(i(60));e.innerHTML=n}}break;case`multiple`:e.multiple=r&&typeof r!=`function`&&typeof r!=`symbol`;break;case`muted`:e.muted=r&&typeof r!=`function`&&typeof r!=`symbol`;break;case`suppressContentEditableWarning`:case`suppressHydrationWarning`:case`defaultValue`:case`defaultChecked`:case`innerHTML`:case`ref`:break;case`autoFocus`:break;case`xlinkHref`:if(r==null||typeof r==`function`||typeof r==`boolean`||typeof r==`symbol`){e.removeAttribute(`xlink:href`);break}n=Ht(``+r),e.setAttributeNS(`http://www.w3.org/1999/xlink`,`xlink:href`,n);break;case`contentEditable`:case`spellCheck`:case`draggable`:case`value`:case`autoReverse`:case`externalResourcesRequired`:case`focusable`:case`preserveAlpha`:r!=null&&typeof r!=`function`&&typeof r!=`symbol`?e.setAttribute(n,``+r):e.removeAttribute(n);break;case`inert`:case`allowFullScreen`:case`async`:case`autoPlay`:case`controls`:case`default`:case`defer`:case`disabled`:case`disablePictureInPicture`:case`disableRemotePlayback`:case`formNoValidate`:case`hidden`:case`loop`:case`noModule`:case`noValidate`:case`open`:case`playsInline`:case`readOnly`:case`required`:case`reversed`:case`scoped`:case`seamless`:case`itemScope`:r&&typeof r!=`function`&&typeof r!=`symbol`?e.setAttribute(n,``):e.removeAttribute(n);break;case`capture`:case`download`:!0===r?e.setAttribute(n,``):!1!==r&&r!=null&&typeof r!=`function`&&typeof r!=`symbol`?e.setAttribute(n,r):e.removeAttribute(n);break;case`cols`:case`rows`:case`size`:case`span`:r!=null&&typeof r!=`function`&&typeof r!=`symbol`&&!isNaN(r)&&1<=r?e.setAttribute(n,r):e.removeAttribute(n);break;case`rowSpan`:case`start`:r==null||typeof r==`function`||typeof r==`symbol`||isNaN(r)?e.removeAttribute(n):e.setAttribute(n,r);break;case`popover`:bd(`beforetoggle`,e),bd(`toggle`,e),vt(e,`popover`,r);break;case`xlinkActuate`:bt(e,`http://www.w3.org/1999/xlink`,`xlink:actuate`,r);break;case`xlinkArcrole`:bt(e,`http://www.w3.org/1999/xlink`,`xlink:arcrole`,r);break;case`xlinkRole`:bt(e,`http://www.w3.org/1999/xlink`,`xlink:role`,r);break;case`xlinkShow`:bt(e,`http://www.w3.org/1999/xlink`,`xlink:show`,r);break;case`xlinkTitle`:bt(e,`http://www.w3.org/1999/xlink`,`xlink:title`,r);break;case`xlinkType`:bt(e,`http://www.w3.org/1999/xlink`,`xlink:type`,r);break;case`xmlBase`:bt(e,`http://www.w3.org/XML/1998/namespace`,`xml:base`,r);break;case`xmlLang`:bt(e,`http://www.w3.org/XML/1998/namespace`,`xml:lang`,r);break;case`xmlSpace`:bt(e,`http://www.w3.org/XML/1998/namespace`,`xml:space`,r);break;case`is`:vt(e,`is`,r);break;case`innerText`:case`textContent`:break;default:(!(2<n.length)||n[0]!==`o`&&n[0]!==`O`||n[1]!==`n`&&n[1]!==`N`)&&(n=Bt.get(n)||n,vt(e,n,r))}}function Fd(e,t,n,r,a,o){switch(n){case`style`:Rt(e,r,o);break;case`dangerouslySetInnerHTML`:if(r!=null){if(typeof r!=`object`||!(`__html`in r))throw Error(i(61));if(n=r.__html,n!=null){if(a.children!=null)throw Error(i(60));e.innerHTML=n}}break;case`children`:typeof r==`string`?Ft(e,r):(typeof r==`number`||typeof r==`bigint`)&&Ft(e,``+r);break;case`onScroll`:r!=null&&bd(`scroll`,e);break;case`onScrollEnd`:r!=null&&bd(`scrollend`,e);break;case`onClick`:r!=null&&(e.onclick=Ut);break;case`suppressContentEditableWarning`:case`suppressHydrationWarning`:case`innerHTML`:case`ref`:break;case`innerText`:case`textContent`:break;default:if(!dt.hasOwnProperty(n))a:{if(n[0]===`o`&&n[1]===`n`&&(a=n.endsWith(`Capture`),t=n.slice(2,a?n.length-7:void 0),o=e[Ze]||null,o=o==null?null:o[n],typeof o==`function`&&e.removeEventListener(t,o,a),typeof r==`function`)){typeof o!=`function`&&o!==null&&(n in e?e[n]=null:e.hasAttribute(n)&&e.removeAttribute(n)),e.addEventListener(t,r,a);break a}n in e?e[n]=r:!0===r?e.setAttribute(n,``):vt(e,n,r)}}}function Id(e,t,n){switch(t){case`div`:case`span`:case`svg`:case`path`:case`a`:case`g`:case`p`:case`li`:break;case`img`:bd(`error`,e),bd(`load`,e);var r=!1,a=!1,o;for(o in n)if(n.hasOwnProperty(o)){var s=n[o];if(s!=null)switch(o){case`src`:r=!0;break;case`srcSet`:a=!0;break;case`children`:case`dangerouslySetInnerHTML`:throw Error(i(137,t));default:Pd(e,t,o,s,n,null)}}a&&Pd(e,t,`srcSet`,n.srcSet,n,null),r&&Pd(e,t,`src`,n.src,n,null);return;case`input`:bd(`invalid`,e);var c=o=s=a=null,l=null,u=null;for(r in n)if(n.hasOwnProperty(r)){var d=n[r];if(d!=null)switch(r){case`name`:a=d;break;case`type`:s=d;break;case`checked`:l=d;break;case`defaultChecked`:u=d;break;case`value`:o=d;break;case`defaultValue`:c=d;break;case`children`:case`dangerouslySetInnerHTML`:if(d!=null)throw Error(i(137,t));break;default:Pd(e,t,r,d,n,null)}}At(e,o,c,l,u,s,a,!1);return;case`select`:for(a in bd(`invalid`,e),r=s=o=null,n)if(n.hasOwnProperty(a)&&(c=n[a],c!=null))switch(a){case`value`:o=c;break;case`defaultValue`:s=c;break;case`multiple`:r=c;default:Pd(e,t,a,c,n,null)}t=o,n=s,e.multiple=!!r,t==null?n!=null&&Mt(e,!!r,n,!0):Mt(e,!!r,t,!1);return;case`textarea`:for(s in bd(`invalid`,e),o=a=r=null,n)if(n.hasOwnProperty(s)&&(c=n[s],c!=null))switch(s){case`value`:r=c;break;case`defaultValue`:a=c;break;case`children`:o=c;break;case`dangerouslySetInnerHTML`:if(c!=null)throw Error(i(91));break;default:Pd(e,t,s,c,n,null)}Pt(e,r,a,o);return;case`option`:for(l in n)if(n.hasOwnProperty(l)&&(r=n[l],r!=null))switch(l){case`selected`:e.selected=r&&typeof r!=`function`&&typeof r!=`symbol`;break;default:Pd(e,t,l,r,n,null)}return;case`dialog`:bd(`beforetoggle`,e),bd(`toggle`,e),bd(`cancel`,e),bd(`close`,e);break;case`iframe`:case`object`:bd(`load`,e);break;case`video`:case`audio`:for(r=0;r<_d.length;r++)bd(_d[r],e);break;case`image`:bd(`error`,e),bd(`load`,e);break;case`details`:bd(`toggle`,e);break;case`embed`:case`source`:case`link`:bd(`error`,e),bd(`load`,e);case`area`:case`base`:case`br`:case`col`:case`hr`:case`keygen`:case`meta`:case`param`:case`track`:case`wbr`:case`menuitem`:for(u in n)if(n.hasOwnProperty(u)&&(r=n[u],r!=null))switch(u){case`children`:case`dangerouslySetInnerHTML`:throw Error(i(137,t));default:Pd(e,t,u,r,n,null)}return;default:if(zt(t)){for(d in n)n.hasOwnProperty(d)&&(r=n[d],r!==void 0&&Fd(e,t,d,r,n,void 0));return}}for(c in n)n.hasOwnProperty(c)&&(r=n[c],r!=null&&Pd(e,t,c,r,n,null))}function Ld(e,t,n,r){switch(t){case`div`:case`span`:case`svg`:case`path`:case`a`:case`g`:case`p`:case`li`:break;case`input`:var a=null,o=null,s=null,c=null,l=null,u=null,d=null;for(m in n){var f=n[m];if(n.hasOwnProperty(m)&&f!=null)switch(m){case`checked`:break;case`value`:break;case`defaultValue`:l=f;default:r.hasOwnProperty(m)||Pd(e,t,m,null,r,f)}}for(var p in r){var m=r[p];if(f=n[p],r.hasOwnProperty(p)&&(m!=null||f!=null))switch(p){case`type`:o=m;break;case`name`:a=m;break;case`checked`:u=m;break;case`defaultChecked`:d=m;break;case`value`:s=m;break;case`defaultValue`:c=m;break;case`children`:case`dangerouslySetInnerHTML`:if(m!=null)throw Error(i(137,t));break;default:m!==f&&Pd(e,t,p,m,r,f)}}kt(e,s,c,l,u,d,o,a);return;case`select`:for(o in m=s=c=p=null,n)if(l=n[o],n.hasOwnProperty(o)&&l!=null)switch(o){case`value`:break;case`multiple`:m=l;default:r.hasOwnProperty(o)||Pd(e,t,o,null,r,l)}for(a in r)if(o=r[a],l=n[a],r.hasOwnProperty(a)&&(o!=null||l!=null))switch(a){case`value`:p=o;break;case`defaultValue`:c=o;break;case`multiple`:s=o;default:o!==l&&Pd(e,t,a,o,r,l)}t=c,n=s,r=m,p==null?!!r!=!!n&&(t==null?Mt(e,!!n,n?[]:``,!1):Mt(e,!!n,t,!0)):Mt(e,!!n,p,!1);return;case`textarea`:for(c in m=p=null,n)if(a=n[c],n.hasOwnProperty(c)&&a!=null&&!r.hasOwnProperty(c))switch(c){case`value`:break;case`children`:break;default:Pd(e,t,c,null,r,a)}for(s in r)if(a=r[s],o=n[s],r.hasOwnProperty(s)&&(a!=null||o!=null))switch(s){case`value`:p=a;break;case`defaultValue`:m=a;break;case`children`:break;case`dangerouslySetInnerHTML`:if(a!=null)throw Error(i(91));break;default:a!==o&&Pd(e,t,s,a,r,o)}Nt(e,p,m);return;case`option`:for(var h in n)if(p=n[h],n.hasOwnProperty(h)&&p!=null&&!r.hasOwnProperty(h))switch(h){case`selected`:e.selected=!1;break;default:Pd(e,t,h,null,r,p)}for(l in r)if(p=r[l],m=n[l],r.hasOwnProperty(l)&&p!==m&&(p!=null||m!=null))switch(l){case`selected`:e.selected=p&&typeof p!=`function`&&typeof p!=`symbol`;break;default:Pd(e,t,l,p,r,m)}return;case`img`:case`link`:case`area`:case`base`:case`br`:case`col`:case`embed`:case`hr`:case`keygen`:case`meta`:case`param`:case`source`:case`track`:case`wbr`:case`menuitem`:for(var g in n)p=n[g],n.hasOwnProperty(g)&&p!=null&&!r.hasOwnProperty(g)&&Pd(e,t,g,null,r,p);for(u in r)if(p=r[u],m=n[u],r.hasOwnProperty(u)&&p!==m&&(p!=null||m!=null))switch(u){case`children`:case`dangerouslySetInnerHTML`:if(p!=null)throw Error(i(137,t));break;default:Pd(e,t,u,p,r,m)}return;default:if(zt(t)){for(var _ in n)p=n[_],n.hasOwnProperty(_)&&p!==void 0&&!r.hasOwnProperty(_)&&Fd(e,t,_,void 0,r,p);for(d in r)p=r[d],m=n[d],!r.hasOwnProperty(d)||p===m||p===void 0&&m===void 0||Fd(e,t,d,p,r,m);return}}for(var v in n)p=n[v],n.hasOwnProperty(v)&&p!=null&&!r.hasOwnProperty(v)&&Pd(e,t,v,null,r,p);for(f in r)p=r[f],m=n[f],!r.hasOwnProperty(f)||p===m||p==null&&m==null||Pd(e,t,f,p,r,m)}function Rd(e){switch(e){case`css`:case`script`:case`font`:case`img`:case`image`:case`input`:case`link`:return!0;default:return!1}}function zd(){if(typeof performance.getEntriesByType==`function`){for(var e=0,t=0,n=performance.getEntriesByType(`resource`),r=0;r<n.length;r++){var i=n[r],a=i.transferSize,o=i.initiatorType,s=i.duration;if(a&&s&&Rd(o)){for(o=0,s=i.responseEnd,r+=1;r<n.length;r++){var c=n[r],l=c.startTime;if(l>s)break;var u=c.transferSize,d=c.initiatorType;u&&Rd(d)&&(c=c.responseEnd,o+=u*(c<s?1:(s-l)/(c-l)))}if(--r,t+=8*(a+o)/(i.duration/1e3),e++,10<e)break}}if(0<e)return t/e/1e6}return navigator.connection&&(e=navigator.connection.downlink,typeof e==`number`)?e:5}var Bd=null,Vd=null;function Hd(e){return e.nodeType===9?e:e.ownerDocument}function Ud(e){switch(e){case`http://www.w3.org/2000/svg`:return 1;case`http://www.w3.org/1998/Math/MathML`:return 2;default:return 0}}function Wd(e,t){if(e===0)switch(t){case`svg`:return 1;case`math`:return 2;default:return 0}return e===1&&t===`foreignObject`?0:e}function Gd(e,t){return e===`textarea`||e===`noscript`||typeof t.children==`string`||typeof t.children==`number`||typeof t.children==`bigint`||typeof t.dangerouslySetInnerHTML==`object`&&t.dangerouslySetInnerHTML!==null&&t.dangerouslySetInnerHTML.__html!=null}var Kd=null;function qd(){var e=window.event;return e&&e.type===`popstate`?e===Kd?!1:(Kd=e,!0):(Kd=null,!1)}var Jd=typeof setTimeout==`function`?setTimeout:void 0,Yd=typeof clearTimeout==`function`?clearTimeout:void 0,Xd=typeof Promise==`function`?Promise:void 0,Zd=typeof queueMicrotask==`function`?queueMicrotask:Xd===void 0?Jd:function(e){return Xd.resolve(null).then(e).catch(Qd)};function Qd(e){setTimeout(function(){throw e})}function $d(e){return e===`head`}function ef(e,t){var n=t,r=0;do{var i=n.nextSibling;if(e.removeChild(n),i&&i.nodeType===8)if(n=i.data,n===`/$`||n===`/&`){if(r===0){e.removeChild(i),Fp(t);return}r--}else if(n===`$`||n===`$?`||n===`$~`||n===`$!`||n===`&`)r++;else if(n===`html`)hf(e.ownerDocument.documentElement);else if(n===`head`){n=e.ownerDocument.head,hf(n);for(var a=n.firstChild;a;){var o=a.nextSibling,s=a.nodeName;a[rt]||s===`SCRIPT`||s===`STYLE`||s===`LINK`&&a.rel.toLowerCase()===`stylesheet`||n.removeChild(a),a=o}}else n===`body`&&hf(e.ownerDocument.body);n=i}while(n);Fp(t)}function tf(e,t){var n=e;e=0;do{var r=n.nextSibling;if(n.nodeType===1?t?(n._stashedDisplay=n.style.display,n.style.display=`none`):(n.style.display=n._stashedDisplay||``,n.getAttribute(`style`)===``&&n.removeAttribute(`style`)):n.nodeType===3&&(t?(n._stashedText=n.nodeValue,n.nodeValue=``):n.nodeValue=n._stashedText||``),r&&r.nodeType===8)if(n=r.data,n===`/$`){if(e===0)break;e--}else n!==`$`&&n!==`$?`&&n!==`$~`&&n!==`$!`||e++;n=r}while(n)}function nf(e){var t=e.firstChild;for(t&&t.nodeType===10&&(t=t.nextSibling);t;){var n=t;switch(t=t.nextSibling,n.nodeName){case`HTML`:case`HEAD`:case`BODY`:nf(n),it(n);continue;case`SCRIPT`:case`STYLE`:continue;case`LINK`:if(n.rel.toLowerCase()===`stylesheet`)continue}e.removeChild(n)}}function rf(e,t,n,r){for(;e.nodeType===1;){var i=n;if(e.nodeName.toLowerCase()!==t.toLowerCase()){if(!r&&(e.nodeName!==`INPUT`||e.type!==`hidden`))break}else if(!r)if(t===`input`&&e.type===`hidden`){var a=i.name==null?null:``+i.name;if(i.type===`hidden`&&e.getAttribute(`name`)===a)return e}else return e;else if(!e[rt])switch(t){case`meta`:if(!e.hasAttribute(`itemprop`))break;return e;case`link`:if(a=e.getAttribute(`rel`),a===`stylesheet`&&e.hasAttribute(`data-precedence`)||a!==i.rel||e.getAttribute(`href`)!==(i.href==null||i.href===``?null:i.href)||e.getAttribute(`crossorigin`)!==(i.crossOrigin==null?null:i.crossOrigin)||e.getAttribute(`title`)!==(i.title==null?null:i.title))break;return e;case`style`:if(e.hasAttribute(`data-precedence`))break;return e;case`script`:if(a=e.getAttribute(`src`),(a!==(i.src==null?null:i.src)||e.getAttribute(`type`)!==(i.type==null?null:i.type)||e.getAttribute(`crossorigin`)!==(i.crossOrigin==null?null:i.crossOrigin))&&a&&e.hasAttribute(`async`)&&!e.hasAttribute(`itemprop`))break;return e;default:return e}if(e=uf(e.nextSibling),e===null)break}return null}function af(e,t,n){if(t===``)return null;for(;e.nodeType!==3;)if((e.nodeType!==1||e.nodeName!==`INPUT`||e.type!==`hidden`)&&!n||(e=uf(e.nextSibling),e===null))return null;return e}function of(e,t){for(;e.nodeType!==8;)if((e.nodeType!==1||e.nodeName!==`INPUT`||e.type!==`hidden`)&&!t||(e=uf(e.nextSibling),e===null))return null;return e}function sf(e){return e.data===`$?`||e.data===`$~`}function cf(e){return e.data===`$!`||e.data===`$?`&&e.ownerDocument.readyState!==`loading`}function lf(e,t){var n=e.ownerDocument;if(e.data===`$~`)e._reactRetry=t;else if(e.data!==`$?`||n.readyState!==`loading`)t();else{var r=function(){t(),n.removeEventListener(`DOMContentLoaded`,r)};n.addEventListener(`DOMContentLoaded`,r),e._reactRetry=r}}function uf(e){for(;e!=null;e=e.nextSibling){var t=e.nodeType;if(t===1||t===3)break;if(t===8){if(t=e.data,t===`$`||t===`$!`||t===`$?`||t===`$~`||t===`&`||t===`F!`||t===`F`)break;if(t===`/$`||t===`/&`)return null}}return e}var df=null;function ff(e){e=e.nextSibling;for(var t=0;e;){if(e.nodeType===8){var n=e.data;if(n===`/$`||n===`/&`){if(t===0)return uf(e.nextSibling);t--}else n!==`$`&&n!==`$!`&&n!==`$?`&&n!==`$~`&&n!==`&`||t++}e=e.nextSibling}return null}function pf(e){e=e.previousSibling;for(var t=0;e;){if(e.nodeType===8){var n=e.data;if(n===`$`||n===`$!`||n===`$?`||n===`$~`||n===`&`){if(t===0)return e;t--}else n!==`/$`&&n!==`/&`||t++}e=e.previousSibling}return null}function mf(e,t,n){switch(t=Hd(n),e){case`html`:if(e=t.documentElement,!e)throw Error(i(452));return e;case`head`:if(e=t.head,!e)throw Error(i(453));return e;case`body`:if(e=t.body,!e)throw Error(i(454));return e;default:throw Error(i(451))}}function hf(e){for(var t=e.attributes;t.length;)e.removeAttributeNode(t[0]);it(e)}var gf=new Map,_f=new Set;function vf(e){return typeof e.getRootNode==`function`?e.getRootNode():e.nodeType===9?e:e.ownerDocument}var yf=P.d;P.d={f:bf,r:xf,D:wf,C:Tf,L:Ef,m:Df,X:kf,S:Of,M:Af};function bf(){var e=yf.f(),t=yu();return e||t}function xf(e){var t=ot(e);t!==null&&t.tag===5&&t.type===`form`?vs(t):yf.r(e)}var Sf=typeof document>`u`?null:document;function Cf(e,t,n){var r=Sf;if(r&&typeof t==`string`&&t){var i=Ot(t);i=`link[rel="`+e+`"][href="`+i+`"]`,typeof n==`string`&&(i+=`[crossorigin="`+n+`"]`),_f.has(i)||(_f.add(i),e={rel:e,crossOrigin:n,href:t},r.querySelector(i)===null&&(t=r.createElement(`link`),Id(t,`link`,e),lt(t),r.head.appendChild(t)))}}function wf(e){yf.D(e),Cf(`dns-prefetch`,e,null)}function Tf(e,t){yf.C(e,t),Cf(`preconnect`,e,t)}function Ef(e,t,n){yf.L(e,t,n);var r=Sf;if(r&&e&&t){var i=`link[rel="preload"][as="`+Ot(t)+`"]`;t===`image`&&n&&n.imageSrcSet?(i+=`[imagesrcset="`+Ot(n.imageSrcSet)+`"]`,typeof n.imageSizes==`string`&&(i+=`[imagesizes="`+Ot(n.imageSizes)+`"]`)):i+=`[href="`+Ot(e)+`"]`;var a=i;switch(t){case`style`:a=Mf(e);break;case`script`:a=If(e)}gf.has(a)||(e=f({rel:`preload`,href:t===`image`&&n&&n.imageSrcSet?void 0:e,as:t},n),gf.set(a,e),r.querySelector(i)!==null||t===`style`&&r.querySelector(Nf(a))||t===`script`&&r.querySelector(Lf(a))||(t=r.createElement(`link`),Id(t,`link`,e),lt(t),r.head.appendChild(t)))}}function Df(e,t){yf.m(e,t);var n=Sf;if(n&&e){var r=t&&typeof t.as==`string`?t.as:`script`,i=`link[rel="modulepreload"][as="`+Ot(r)+`"][href="`+Ot(e)+`"]`,a=i;switch(r){case`audioworklet`:case`paintworklet`:case`serviceworker`:case`sharedworker`:case`worker`:case`script`:a=If(e)}if(!gf.has(a)&&(e=f({rel:`modulepreload`,href:e},t),gf.set(a,e),n.querySelector(i)===null)){switch(r){case`audioworklet`:case`paintworklet`:case`serviceworker`:case`sharedworker`:case`worker`:case`script`:if(n.querySelector(Lf(a)))return}r=n.createElement(`link`),Id(r,`link`,e),lt(r),n.head.appendChild(r)}}}function Of(e,t,n){yf.S(e,t,n);var r=Sf;if(r&&e){var i=ct(r).hoistableStyles,a=Mf(e);t||=`default`;var o=i.get(a);if(!o){var s={loading:0,preload:null};if(o=r.querySelector(Nf(a)))s.loading=5;else{e=f({rel:`stylesheet`,href:e,"data-precedence":t},n),(n=gf.get(a))&&Bf(e,n);var c=o=r.createElement(`link`);lt(c),Id(c,`link`,e),c._p=new Promise(function(e,t){c.onload=e,c.onerror=t}),c.addEventListener(`load`,function(){s.loading|=1}),c.addEventListener(`error`,function(){s.loading|=2}),s.loading|=4,zf(o,t,r)}o={type:`stylesheet`,instance:o,count:1,state:s},i.set(a,o)}}}function kf(e,t){yf.X(e,t);var n=Sf;if(n&&e){var r=ct(n).hoistableScripts,i=If(e),a=r.get(i);a||(a=n.querySelector(Lf(i)),a||(e=f({src:e,async:!0},t),(t=gf.get(i))&&Vf(e,t),a=n.createElement(`script`),lt(a),Id(a,`link`,e),n.head.appendChild(a)),a={type:`script`,instance:a,count:1,state:null},r.set(i,a))}}function Af(e,t){yf.M(e,t);var n=Sf;if(n&&e){var r=ct(n).hoistableScripts,i=If(e),a=r.get(i);a||(a=n.querySelector(Lf(i)),a||(e=f({src:e,async:!0,type:`module`},t),(t=gf.get(i))&&Vf(e,t),a=n.createElement(`script`),lt(a),Id(a,`link`,e),n.head.appendChild(a)),a={type:`script`,instance:a,count:1,state:null},r.set(i,a))}}function jf(e,t,n,r){var a=(a=H.current)?vf(a):null;if(!a)throw Error(i(446));switch(e){case`meta`:case`title`:return null;case`style`:return typeof n.precedence==`string`&&typeof n.href==`string`?(t=Mf(n.href),n=ct(a).hoistableStyles,r=n.get(t),r||(r={type:`style`,instance:null,count:0,state:null},n.set(t,r)),r):{type:`void`,instance:null,count:0,state:null};case`link`:if(n.rel===`stylesheet`&&typeof n.href==`string`&&typeof n.precedence==`string`){e=Mf(n.href);var o=ct(a).hoistableStyles,s=o.get(e);if(s||(a=a.ownerDocument||a,s={type:`stylesheet`,instance:null,count:0,state:{loading:0,preload:null}},o.set(e,s),(o=a.querySelector(Nf(e)))&&!o._p&&(s.instance=o,s.state.loading=5),gf.has(e)||(n={rel:`preload`,as:`style`,href:n.href,crossOrigin:n.crossOrigin,integrity:n.integrity,media:n.media,hrefLang:n.hrefLang,referrerPolicy:n.referrerPolicy},gf.set(e,n),o||Ff(a,e,n,s.state))),t&&r===null)throw Error(i(528,``));return s}if(t&&r!==null)throw Error(i(529,``));return null;case`script`:return t=n.async,n=n.src,typeof n==`string`&&t&&typeof t!=`function`&&typeof t!=`symbol`?(t=If(n),n=ct(a).hoistableScripts,r=n.get(t),r||(r={type:`script`,instance:null,count:0,state:null},n.set(t,r)),r):{type:`void`,instance:null,count:0,state:null};default:throw Error(i(444,e))}}function Mf(e){return`href="`+Ot(e)+`"`}function Nf(e){return`link[rel="stylesheet"][`+e+`]`}function Pf(e){return f({},e,{"data-precedence":e.precedence,precedence:null})}function Ff(e,t,n,r){e.querySelector(`link[rel="preload"][as="style"][`+t+`]`)?r.loading=1:(t=e.createElement(`link`),r.preload=t,t.addEventListener(`load`,function(){return r.loading|=1}),t.addEventListener(`error`,function(){return r.loading|=2}),Id(t,`link`,n),lt(t),e.head.appendChild(t))}function If(e){return`[src="`+Ot(e)+`"]`}function Lf(e){return`script[async]`+e}function Rf(e,t,n){if(t.count++,t.instance===null)switch(t.type){case`style`:var r=e.querySelector(`style[data-href~="`+Ot(n.href)+`"]`);if(r)return t.instance=r,lt(r),r;var a=f({},n,{"data-href":n.href,"data-precedence":n.precedence,href:null,precedence:null});return r=(e.ownerDocument||e).createElement(`style`),lt(r),Id(r,`style`,a),zf(r,n.precedence,e),t.instance=r;case`stylesheet`:a=Mf(n.href);var o=e.querySelector(Nf(a));if(o)return t.state.loading|=4,t.instance=o,lt(o),o;r=Pf(n),(a=gf.get(a))&&Bf(r,a),o=(e.ownerDocument||e).createElement(`link`),lt(o);var s=o;return s._p=new Promise(function(e,t){s.onload=e,s.onerror=t}),Id(o,`link`,r),t.state.loading|=4,zf(o,n.precedence,e),t.instance=o;case`script`:return o=If(n.src),(a=e.querySelector(Lf(o)))?(t.instance=a,lt(a),a):(r=n,(a=gf.get(o))&&(r=f({},n),Vf(r,a)),e=e.ownerDocument||e,a=e.createElement(`script`),lt(a),Id(a,`link`,r),e.head.appendChild(a),t.instance=a);case`void`:return null;default:throw Error(i(443,t.type))}else t.type===`stylesheet`&&!(t.state.loading&4)&&(r=t.instance,t.state.loading|=4,zf(r,n.precedence,e));return t.instance}function zf(e,t,n){for(var r=n.querySelectorAll(`link[rel="stylesheet"][data-precedence],style[data-precedence]`),i=r.length?r[r.length-1]:null,a=i,o=0;o<r.length;o++){var s=r[o];if(s.dataset.precedence===t)a=s;else if(a!==i)break}a?a.parentNode.insertBefore(e,a.nextSibling):(t=n.nodeType===9?n.head:n,t.insertBefore(e,t.firstChild))}function Bf(e,t){e.crossOrigin??=t.crossOrigin,e.referrerPolicy??=t.referrerPolicy,e.title??=t.title}function Vf(e,t){e.crossOrigin??=t.crossOrigin,e.referrerPolicy??=t.referrerPolicy,e.integrity??=t.integrity}var Hf=null;function Uf(e,t,n){if(Hf===null){var r=new Map,i=Hf=new Map;i.set(n,r)}else i=Hf,r=i.get(n),r||(r=new Map,i.set(n,r));if(r.has(e))return r;for(r.set(e,null),n=n.getElementsByTagName(e),i=0;i<n.length;i++){var a=n[i];if(!(a[rt]||a[Xe]||e===`link`&&a.getAttribute(`rel`)===`stylesheet`)&&a.namespaceURI!==`http://www.w3.org/2000/svg`){var o=a.getAttribute(t)||``;o=e+o;var s=r.get(o);s?s.push(a):r.set(o,[a])}}return r}function Wf(e,t,n){e=e.ownerDocument||e,e.head.insertBefore(n,t===`title`?e.querySelector(`head > title`):null)}function Gf(e,t,n){if(n===1||t.itemProp!=null)return!1;switch(e){case`meta`:case`title`:return!0;case`style`:if(typeof t.precedence!=`string`||typeof t.href!=`string`||t.href===``)break;return!0;case`link`:if(typeof t.rel!=`string`||typeof t.href!=`string`||t.href===``||t.onLoad||t.onError)break;switch(t.rel){case`stylesheet`:return e=t.disabled,typeof t.precedence==`string`&&e==null;default:return!0}case`script`:if(t.async&&typeof t.async!=`function`&&typeof t.async!=`symbol`&&!t.onLoad&&!t.onError&&t.src&&typeof t.src==`string`)return!0}return!1}function Kf(e){return!(e.type===`stylesheet`&&!(e.state.loading&3))}function qf(e,t,n,r){if(n.type===`stylesheet`&&(typeof r.media!=`string`||!1!==matchMedia(r.media).matches)&&!(n.state.loading&4)){if(n.instance===null){var i=Mf(r.href),a=t.querySelector(Nf(i));if(a){t=a._p,typeof t==`object`&&t&&typeof t.then==`function`&&(e.count++,e=Xf.bind(e),t.then(e,e)),n.state.loading|=4,n.instance=a,lt(a);return}a=t.ownerDocument||t,r=Pf(r),(i=gf.get(i))&&Bf(r,i),a=a.createElement(`link`),lt(a);var o=a;o._p=new Promise(function(e,t){o.onload=e,o.onerror=t}),Id(a,`link`,r),n.instance=a}e.stylesheets===null&&(e.stylesheets=new Map),e.stylesheets.set(n,t),(t=n.state.preload)&&!(n.state.loading&3)&&(e.count++,n=Xf.bind(e),t.addEventListener(`load`,n),t.addEventListener(`error`,n))}}var Jf=0;function Yf(e,t){return e.stylesheets&&e.count===0&&Qf(e,e.stylesheets),0<e.count||0<e.imgCount?function(n){var r=setTimeout(function(){if(e.stylesheets&&Qf(e,e.stylesheets),e.unsuspend){var t=e.unsuspend;e.unsuspend=null,t()}},6e4+t);0<e.imgBytes&&Jf===0&&(Jf=62500*zd());var i=setTimeout(function(){if(e.waitingForImages=!1,e.count===0&&(e.stylesheets&&Qf(e,e.stylesheets),e.unsuspend)){var t=e.unsuspend;e.unsuspend=null,t()}},(e.imgBytes>Jf?50:800)+t);return e.unsuspend=n,function(){e.unsuspend=null,clearTimeout(r),clearTimeout(i)}}:null}function Xf(){if(this.count--,this.count===0&&(this.imgCount===0||!this.waitingForImages)){if(this.stylesheets)Qf(this,this.stylesheets);else if(this.unsuspend){var e=this.unsuspend;this.unsuspend=null,e()}}}var Zf=null;function Qf(e,t){e.stylesheets=null,e.unsuspend!==null&&(e.count++,Zf=new Map,t.forEach($f,e),Zf=null,Xf.call(e))}function $f(e,t){if(!(t.state.loading&4)){var n=Zf.get(e);if(n)var r=n.get(null);else{n=new Map,Zf.set(e,n);for(var i=e.querySelectorAll(`link[data-precedence],style[data-precedence]`),a=0;a<i.length;a++){var o=i[a];(o.nodeName===`LINK`||o.getAttribute(`media`)!==`not all`)&&(n.set(o.dataset.precedence,o),r=o)}r&&n.set(null,r)}i=t.instance,o=i.getAttribute(`data-precedence`),a=n.get(o)||r,a===r&&n.set(null,i),n.set(o,i),this.count++,r=Xf.bind(this),i.addEventListener(`load`,r),i.addEventListener(`error`,r),a?a.parentNode.insertBefore(i,a.nextSibling):(e=e.nodeType===9?e.head:e,e.insertBefore(i,e.firstChild)),t.state.loading|=4}}var ep={$$typeof:b,Provider:null,Consumer:null,_currentValue:F,_currentValue2:F,_threadCount:0};function tp(e,t,n,r,i,a,o,s,c){this.tag=1,this.containerInfo=e,this.pingCache=this.current=this.pendingChildren=null,this.timeoutHandle=-1,this.callbackNode=this.next=this.pendingContext=this.context=this.cancelPendingCommit=null,this.callbackPriority=0,this.expirationTimes=ze(-1),this.entangledLanes=this.shellSuspendCounter=this.errorRecoveryDisabledLanes=this.expiredLanes=this.warmLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=ze(0),this.hiddenUpdates=ze(null),this.identifierPrefix=r,this.onUncaughtError=i,this.onCaughtError=a,this.onRecoverableError=o,this.pooledCache=null,this.pooledCacheLanes=0,this.formState=c,this.incompleteTransitions=new Map}function np(e,t,n,r,i,a,o,s,c,l,u,d){return e=new tp(e,t,n,o,c,l,u,d,s),t=1,!0===a&&(t|=24),a=Xr(3,null,null,t),e.current=a,a.stateNode=e,t=Zi(),t.refCount++,e.pooledCache=t,t.refCount++,a.memoizedState={element:r,isDehydrated:n,cache:t},ka(a),e}function rp(e){return e?(e=Jr,e):Jr}function ip(e,t,n,r,i,a){i=rp(i),r.context===null?r.context=i:r.pendingContext=i,r=ja(t),r.payload={element:n},a=a===void 0?null:a,a!==null&&(r.callback=a),n=Ma(e,r,t),n!==null&&(mu(n,e,t),Na(n,e,t))}function ap(e,t){if(e=e.memoizedState,e!==null&&e.dehydrated!==null){var n=e.retryLane;e.retryLane=n!==0&&n<t?n:t}}function op(e,t){ap(e,t),(e=e.alternate)&&ap(e,t)}function sp(e){if(e.tag===13||e.tag===31){var t=Gr(e,67108864);t!==null&&mu(t,e,67108864),op(e,67108864)}}function cp(e){if(e.tag===13||e.tag===31){var t=fu();t=Ge(t);var n=Gr(e,t);n!==null&&mu(n,e,t),op(e,t)}}var lp=!0;function up(e,t,n,r){var i=N.T;N.T=null;var a=P.p;try{P.p=2,fp(e,t,n,r)}finally{P.p=a,N.T=i}}function dp(e,t,n,r){var i=N.T;N.T=null;var a=P.p;try{P.p=8,fp(e,t,n,r)}finally{P.p=a,N.T=i}}function fp(e,t,n,r){if(lp){var i=pp(r);if(i===null)Td(e,t,r,mp,n),Tp(e,r);else if(Dp(i,e,t,n,r))r.stopPropagation();else if(Tp(e,r),t&4&&-1<wp.indexOf(e)){for(;i!==null;){var a=ot(i);if(a!==null)switch(a.tag){case 3:if(a=a.stateNode,a.current.memoizedState.isDehydrated){var o=Pe(a.pendingLanes);if(o!==0){var s=a;for(s.pendingLanes|=2,s.entangledLanes|=2;o;){var c=1<<31-De(o);s.entanglements[1]|=c,o&=~c}rd(a),!(Nl&6)&&(eu=he()+500,id(0,!1))}}break;case 31:case 13:s=Gr(a,2),s!==null&&mu(s,a,2),yu(),op(a,2)}if(a=pp(r),a===null&&Td(e,t,r,mp,n),a===i)break;i=a}i!==null&&r.stopPropagation()}else Td(e,t,r,null,n)}}function pp(e){return e=Gt(e),hp(e)}var mp=null;function hp(e){if(mp=null,e=at(e),e!==null){var t=o(e);if(t===null)e=null;else{var n=t.tag;if(n===13){if(e=s(t),e!==null)return e;e=null}else if(n===31){if(e=c(t),e!==null)return e;e=null}else if(n===3){if(t.stateNode.current.memoizedState.isDehydrated)return t.tag===3?t.stateNode.containerInfo:null;e=null}else t!==e&&(e=null)}}return mp=e,null}function gp(e){switch(e){case`beforetoggle`:case`cancel`:case`click`:case`close`:case`contextmenu`:case`copy`:case`cut`:case`auxclick`:case`dblclick`:case`dragend`:case`dragstart`:case`drop`:case`focusin`:case`focusout`:case`input`:case`invalid`:case`keydown`:case`keypress`:case`keyup`:case`mousedown`:case`mouseup`:case`paste`:case`pause`:case`play`:case`pointercancel`:case`pointerdown`:case`pointerup`:case`ratechange`:case`reset`:case`resize`:case`seeked`:case`submit`:case`toggle`:case`touchcancel`:case`touchend`:case`touchstart`:case`volumechange`:case`change`:case`selectionchange`:case`textInput`:case`compositionstart`:case`compositionend`:case`compositionupdate`:case`beforeblur`:case`afterblur`:case`beforeinput`:case`blur`:case`fullscreenchange`:case`focus`:case`hashchange`:case`popstate`:case`select`:case`selectstart`:return 2;case`drag`:case`dragenter`:case`dragexit`:case`dragleave`:case`dragover`:case`mousemove`:case`mouseout`:case`mouseover`:case`pointermove`:case`pointerout`:case`pointerover`:case`scroll`:case`touchmove`:case`wheel`:case`mouseenter`:case`mouseleave`:case`pointerenter`:case`pointerleave`:return 8;case`message`:switch(ge()){case _e:return 2;case ve:return 8;case ye:case be:return 32;case xe:return 268435456;default:return 32}default:return 32}}var _p=!1,vp=null,yp=null,bp=null,xp=new Map,Sp=new Map,Cp=[],wp=`mousedown mouseup touchcancel touchend touchstart auxclick dblclick pointercancel pointerdown pointerup dragend dragstart drop compositionend compositionstart keydown keypress keyup input textInput copy cut paste click change contextmenu reset`.split(` `);function Tp(e,t){switch(e){case`focusin`:case`focusout`:vp=null;break;case`dragenter`:case`dragleave`:yp=null;break;case`mouseover`:case`mouseout`:bp=null;break;case`pointerover`:case`pointerout`:xp.delete(t.pointerId);break;case`gotpointercapture`:case`lostpointercapture`:Sp.delete(t.pointerId)}}function Ep(e,t,n,r,i,a){return e===null||e.nativeEvent!==a?(e={blockedOn:t,domEventName:n,eventSystemFlags:r,nativeEvent:a,targetContainers:[i]},t!==null&&(t=ot(t),t!==null&&sp(t)),e):(e.eventSystemFlags|=r,t=e.targetContainers,i!==null&&t.indexOf(i)===-1&&t.push(i),e)}function Dp(e,t,n,r,i){switch(t){case`focusin`:return vp=Ep(vp,e,t,n,r,i),!0;case`dragenter`:return yp=Ep(yp,e,t,n,r,i),!0;case`mouseover`:return bp=Ep(bp,e,t,n,r,i),!0;case`pointerover`:var a=i.pointerId;return xp.set(a,Ep(xp.get(a)||null,e,t,n,r,i)),!0;case`gotpointercapture`:return a=i.pointerId,Sp.set(a,Ep(Sp.get(a)||null,e,t,n,r,i)),!0}return!1}function Op(e){var t=at(e.target);if(t!==null){var n=o(t);if(n!==null){if(t=n.tag,t===13){if(t=s(n),t!==null){e.blockedOn=t,Je(e.priority,function(){cp(n)});return}}else if(t===31){if(t=c(n),t!==null){e.blockedOn=t,Je(e.priority,function(){cp(n)});return}}else if(t===3&&n.stateNode.current.memoizedState.isDehydrated){e.blockedOn=n.tag===3?n.stateNode.containerInfo:null;return}}}e.blockedOn=null}function kp(e){if(e.blockedOn!==null)return!1;for(var t=e.targetContainers;0<t.length;){var n=pp(e.nativeEvent);if(n===null){n=e.nativeEvent;var r=new n.constructor(n.type,n);Wt=r,n.target.dispatchEvent(r),Wt=null}else return t=ot(n),t!==null&&sp(t),e.blockedOn=n,!1;t.shift()}return!0}function Ap(e,t,n){kp(e)&&n.delete(t)}function jp(){_p=!1,vp!==null&&kp(vp)&&(vp=null),yp!==null&&kp(yp)&&(yp=null),bp!==null&&kp(bp)&&(bp=null),xp.forEach(Ap),Sp.forEach(Ap)}function Mp(e,n){e.blockedOn===n&&(e.blockedOn=null,_p||(_p=!0,t.unstable_scheduleCallback(t.unstable_NormalPriority,jp)))}var Np=null;function Pp(e){Np!==e&&(Np=e,t.unstable_scheduleCallback(t.unstable_NormalPriority,function(){Np===e&&(Np=null);for(var t=0;t<e.length;t+=3){var n=e[t],r=e[t+1],i=e[t+2];if(typeof r!=`function`){if(hp(r||n)===null)continue;break}var a=ot(n);a!==null&&(e.splice(t,3),t-=3,gs(a,{pending:!0,data:i,method:n.method,action:r},r,i))}}))}function Fp(e){function t(t){return Mp(t,e)}vp!==null&&Mp(vp,e),yp!==null&&Mp(yp,e),bp!==null&&Mp(bp,e),xp.forEach(t),Sp.forEach(t);for(var n=0;n<Cp.length;n++){var r=Cp[n];r.blockedOn===e&&(r.blockedOn=null)}for(;0<Cp.length&&(n=Cp[0],n.blockedOn===null);)Op(n),n.blockedOn===null&&Cp.shift();if(n=(e.ownerDocument||e).$$reactFormReplay,n!=null)for(r=0;r<n.length;r+=3){var i=n[r],a=n[r+1],o=i[Ze]||null;if(typeof a==`function`)o||Pp(n);else if(o){var s=null;if(a&&a.hasAttribute(`formAction`)){if(i=a,o=a[Ze]||null)s=o.formAction;else if(hp(i)!==null)continue}else s=o.action;typeof s==`function`?n[r+1]=s:(n.splice(r,3),r-=3),Pp(n)}}}function Ip(){function e(e){e.canIntercept&&e.info===`react-transition`&&e.intercept({handler:function(){return new Promise(function(e){return i=e})},focusReset:`manual`,scroll:`manual`})}function t(){i!==null&&(i(),i=null),r||setTimeout(n,20)}function n(){if(!r&&!navigation.transition){var e=navigation.currentEntry;e&&e.url!=null&&navigation.navigate(e.url,{state:e.getState(),info:`react-transition`,history:`replace`})}}if(typeof navigation==`object`){var r=!1,i=null;return navigation.addEventListener(`navigate`,e),navigation.addEventListener(`navigatesuccess`,t),navigation.addEventListener(`navigateerror`,t),setTimeout(n,100),function(){r=!0,navigation.removeEventListener(`navigate`,e),navigation.removeEventListener(`navigatesuccess`,t),navigation.removeEventListener(`navigateerror`,t),i!==null&&(i(),i=null)}}}function Lp(e){this._internalRoot=e}Rp.prototype.render=Lp.prototype.render=function(e){var t=this._internalRoot;if(t===null)throw Error(i(409));var n=t.current;ip(n,fu(),e,t,null,null)},Rp.prototype.unmount=Lp.prototype.unmount=function(){var e=this._internalRoot;if(e!==null){this._internalRoot=null;var t=e.containerInfo;ip(e.current,2,null,e,null,null),yu(),t[Qe]=null}};function Rp(e){this._internalRoot=e}Rp.prototype.unstable_scheduleHydration=function(e){if(e){var t=qe();e={blockedOn:null,target:e,priority:t};for(var n=0;n<Cp.length&&t!==0&&t<Cp[n].priority;n++);Cp.splice(n,0,e),n===0&&Op(e)}};var zp=n.version;if(zp!==`19.2.5`)throw Error(i(527,zp,`19.2.5`));P.findDOMNode=function(e){var t=e._reactInternals;if(t===void 0)throw typeof e.render==`function`?Error(i(188)):(e=Object.keys(e).join(`,`),Error(i(268,e)));return e=u(t),e=e===null?null:d(e),e=e===null?null:e.stateNode,e};var Bp={bundleType:0,version:`19.2.5`,rendererPackageName:`react-dom`,currentDispatcherRef:N,reconcilerVersion:`19.2.5`};if(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<`u`){var Vp=__REACT_DEVTOOLS_GLOBAL_HOOK__;if(!Vp.isDisabled&&Vp.supportsFiber)try{we=Vp.inject(Bp),Te=Vp}catch{}}e.createRoot=function(e,t){if(!a(e))throw Error(i(299));var n=!1,r=``,o=zs,s=Bs,c=Vs;return t!=null&&(!0===t.unstable_strictMode&&(n=!0),t.identifierPrefix!==void 0&&(r=t.identifierPrefix),t.onUncaughtError!==void 0&&(o=t.onUncaughtError),t.onCaughtError!==void 0&&(s=t.onCaughtError),t.onRecoverableError!==void 0&&(c=t.onRecoverableError)),t=np(e,1,!1,null,null,n,r,null,o,s,c,Ip),e[Qe]=t.current,Cd(e),new Lp(t)}})),BY=l(((e,t)=>{function n(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>`u`||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!=`function`))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(n)}catch(e){console.error(e)}}n(),t.exports=zY()})),Z=PY(),VY=IY(),HY=BY();function UY(){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)}}}}var WY=l((e=>{var t=Symbol.for(`react.transitional.element`),n=Symbol.for(`react.fragment`);function r(e,n,r){var i=null;if(r!==void 0&&(i=``+r),n.key!==void 0&&(i=``+n.key),`key`in n)for(var a in r={},n)a!==`key`&&(r[a]=n[a]);else r=n;return n=r.ref,{$$typeof:t,type:e,key:i,ref:n===void 0?null:n,props:r}}e.Fragment=n,e.jsx=r,e.jsxs=r})),Q=l(((e,t)=>{t.exports=WY()}))();function GY(){return(0,Q.jsxs)(`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 `,(0,Q.jsx)(`strong`,{style:{color:`var(--accent, #f5a524)`,fontWeight:700},children:`Kymoscope`})]})}function KY(){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 qY(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 JY(e){return Math.max(0,(e>>1)-1)}var YY=2.5,XY=`#version 300 es
|
|
91
|
+
`).replace(jd,``)}function Nd(e,t){return t=Md(t),Md(e)===t}function Pd(e,t,n,r,a,o){switch(n){case`children`:typeof r==`string`?t===`body`||t===`textarea`&&r===``||Ft(e,r):(typeof r==`number`||typeof r==`bigint`)&&t!==`body`&&Ft(e,``+r);break;case`className`:yt(e,`class`,r);break;case`tabIndex`:yt(e,`tabindex`,r);break;case`dir`:case`role`:case`viewBox`:case`width`:case`height`:yt(e,n,r);break;case`style`:Rt(e,r,o);break;case`data`:if(t!==`object`){yt(e,`data`,r);break}case`src`:case`href`:if(r===``&&(t!==`a`||n!==`href`)){e.removeAttribute(n);break}if(r==null||typeof r==`function`||typeof r==`symbol`||typeof r==`boolean`){e.removeAttribute(n);break}r=Ht(``+r),e.setAttribute(n,r);break;case`action`:case`formAction`:if(typeof r==`function`){e.setAttribute(n,`javascript:throw new Error('A React form was unexpectedly submitted. If you called form.submit() manually, consider using form.requestSubmit() instead. If you\\'re trying to use event.stopPropagation() in a submit event handler, consider also calling event.preventDefault().')`);break}else typeof o==`function`&&(n===`formAction`?(t!==`input`&&Pd(e,t,`name`,a.name,a,null),Pd(e,t,`formEncType`,a.formEncType,a,null),Pd(e,t,`formMethod`,a.formMethod,a,null),Pd(e,t,`formTarget`,a.formTarget,a,null)):(Pd(e,t,`encType`,a.encType,a,null),Pd(e,t,`method`,a.method,a,null),Pd(e,t,`target`,a.target,a,null)));if(r==null||typeof r==`symbol`||typeof r==`boolean`){e.removeAttribute(n);break}r=Ht(``+r),e.setAttribute(n,r);break;case`onClick`:r!=null&&(e.onclick=Ut);break;case`onScroll`:r!=null&&bd(`scroll`,e);break;case`onScrollEnd`:r!=null&&bd(`scrollend`,e);break;case`dangerouslySetInnerHTML`:if(r!=null){if(typeof r!=`object`||!(`__html`in r))throw Error(i(61));if(n=r.__html,n!=null){if(a.children!=null)throw Error(i(60));e.innerHTML=n}}break;case`multiple`:e.multiple=r&&typeof r!=`function`&&typeof r!=`symbol`;break;case`muted`:e.muted=r&&typeof r!=`function`&&typeof r!=`symbol`;break;case`suppressContentEditableWarning`:case`suppressHydrationWarning`:case`defaultValue`:case`defaultChecked`:case`innerHTML`:case`ref`:break;case`autoFocus`:break;case`xlinkHref`:if(r==null||typeof r==`function`||typeof r==`boolean`||typeof r==`symbol`){e.removeAttribute(`xlink:href`);break}n=Ht(``+r),e.setAttributeNS(`http://www.w3.org/1999/xlink`,`xlink:href`,n);break;case`contentEditable`:case`spellCheck`:case`draggable`:case`value`:case`autoReverse`:case`externalResourcesRequired`:case`focusable`:case`preserveAlpha`:r!=null&&typeof r!=`function`&&typeof r!=`symbol`?e.setAttribute(n,``+r):e.removeAttribute(n);break;case`inert`:case`allowFullScreen`:case`async`:case`autoPlay`:case`controls`:case`default`:case`defer`:case`disabled`:case`disablePictureInPicture`:case`disableRemotePlayback`:case`formNoValidate`:case`hidden`:case`loop`:case`noModule`:case`noValidate`:case`open`:case`playsInline`:case`readOnly`:case`required`:case`reversed`:case`scoped`:case`seamless`:case`itemScope`:r&&typeof r!=`function`&&typeof r!=`symbol`?e.setAttribute(n,``):e.removeAttribute(n);break;case`capture`:case`download`:!0===r?e.setAttribute(n,``):!1!==r&&r!=null&&typeof r!=`function`&&typeof r!=`symbol`?e.setAttribute(n,r):e.removeAttribute(n);break;case`cols`:case`rows`:case`size`:case`span`:r!=null&&typeof r!=`function`&&typeof r!=`symbol`&&!isNaN(r)&&1<=r?e.setAttribute(n,r):e.removeAttribute(n);break;case`rowSpan`:case`start`:r==null||typeof r==`function`||typeof r==`symbol`||isNaN(r)?e.removeAttribute(n):e.setAttribute(n,r);break;case`popover`:bd(`beforetoggle`,e),bd(`toggle`,e),vt(e,`popover`,r);break;case`xlinkActuate`:bt(e,`http://www.w3.org/1999/xlink`,`xlink:actuate`,r);break;case`xlinkArcrole`:bt(e,`http://www.w3.org/1999/xlink`,`xlink:arcrole`,r);break;case`xlinkRole`:bt(e,`http://www.w3.org/1999/xlink`,`xlink:role`,r);break;case`xlinkShow`:bt(e,`http://www.w3.org/1999/xlink`,`xlink:show`,r);break;case`xlinkTitle`:bt(e,`http://www.w3.org/1999/xlink`,`xlink:title`,r);break;case`xlinkType`:bt(e,`http://www.w3.org/1999/xlink`,`xlink:type`,r);break;case`xmlBase`:bt(e,`http://www.w3.org/XML/1998/namespace`,`xml:base`,r);break;case`xmlLang`:bt(e,`http://www.w3.org/XML/1998/namespace`,`xml:lang`,r);break;case`xmlSpace`:bt(e,`http://www.w3.org/XML/1998/namespace`,`xml:space`,r);break;case`is`:vt(e,`is`,r);break;case`innerText`:case`textContent`:break;default:(!(2<n.length)||n[0]!==`o`&&n[0]!==`O`||n[1]!==`n`&&n[1]!==`N`)&&(n=Bt.get(n)||n,vt(e,n,r))}}function Fd(e,t,n,r,a,o){switch(n){case`style`:Rt(e,r,o);break;case`dangerouslySetInnerHTML`:if(r!=null){if(typeof r!=`object`||!(`__html`in r))throw Error(i(61));if(n=r.__html,n!=null){if(a.children!=null)throw Error(i(60));e.innerHTML=n}}break;case`children`:typeof r==`string`?Ft(e,r):(typeof r==`number`||typeof r==`bigint`)&&Ft(e,``+r);break;case`onScroll`:r!=null&&bd(`scroll`,e);break;case`onScrollEnd`:r!=null&&bd(`scrollend`,e);break;case`onClick`:r!=null&&(e.onclick=Ut);break;case`suppressContentEditableWarning`:case`suppressHydrationWarning`:case`innerHTML`:case`ref`:break;case`innerText`:case`textContent`:break;default:if(!dt.hasOwnProperty(n))a:{if(n[0]===`o`&&n[1]===`n`&&(a=n.endsWith(`Capture`),t=n.slice(2,a?n.length-7:void 0),o=e[Ze]||null,o=o==null?null:o[n],typeof o==`function`&&e.removeEventListener(t,o,a),typeof r==`function`)){typeof o!=`function`&&o!==null&&(n in e?e[n]=null:e.hasAttribute(n)&&e.removeAttribute(n)),e.addEventListener(t,r,a);break a}n in e?e[n]=r:!0===r?e.setAttribute(n,``):vt(e,n,r)}}}function Id(e,t,n){switch(t){case`div`:case`span`:case`svg`:case`path`:case`a`:case`g`:case`p`:case`li`:break;case`img`:bd(`error`,e),bd(`load`,e);var r=!1,a=!1,o;for(o in n)if(n.hasOwnProperty(o)){var s=n[o];if(s!=null)switch(o){case`src`:r=!0;break;case`srcSet`:a=!0;break;case`children`:case`dangerouslySetInnerHTML`:throw Error(i(137,t));default:Pd(e,t,o,s,n,null)}}a&&Pd(e,t,`srcSet`,n.srcSet,n,null),r&&Pd(e,t,`src`,n.src,n,null);return;case`input`:bd(`invalid`,e);var c=o=s=a=null,l=null,u=null;for(r in n)if(n.hasOwnProperty(r)){var d=n[r];if(d!=null)switch(r){case`name`:a=d;break;case`type`:s=d;break;case`checked`:l=d;break;case`defaultChecked`:u=d;break;case`value`:o=d;break;case`defaultValue`:c=d;break;case`children`:case`dangerouslySetInnerHTML`:if(d!=null)throw Error(i(137,t));break;default:Pd(e,t,r,d,n,null)}}At(e,o,c,l,u,s,a,!1);return;case`select`:for(a in bd(`invalid`,e),r=s=o=null,n)if(n.hasOwnProperty(a)&&(c=n[a],c!=null))switch(a){case`value`:o=c;break;case`defaultValue`:s=c;break;case`multiple`:r=c;default:Pd(e,t,a,c,n,null)}t=o,n=s,e.multiple=!!r,t==null?n!=null&&Mt(e,!!r,n,!0):Mt(e,!!r,t,!1);return;case`textarea`:for(s in bd(`invalid`,e),o=a=r=null,n)if(n.hasOwnProperty(s)&&(c=n[s],c!=null))switch(s){case`value`:r=c;break;case`defaultValue`:a=c;break;case`children`:o=c;break;case`dangerouslySetInnerHTML`:if(c!=null)throw Error(i(91));break;default:Pd(e,t,s,c,n,null)}Pt(e,r,a,o);return;case`option`:for(l in n)if(n.hasOwnProperty(l)&&(r=n[l],r!=null))switch(l){case`selected`:e.selected=r&&typeof r!=`function`&&typeof r!=`symbol`;break;default:Pd(e,t,l,r,n,null)}return;case`dialog`:bd(`beforetoggle`,e),bd(`toggle`,e),bd(`cancel`,e),bd(`close`,e);break;case`iframe`:case`object`:bd(`load`,e);break;case`video`:case`audio`:for(r=0;r<_d.length;r++)bd(_d[r],e);break;case`image`:bd(`error`,e),bd(`load`,e);break;case`details`:bd(`toggle`,e);break;case`embed`:case`source`:case`link`:bd(`error`,e),bd(`load`,e);case`area`:case`base`:case`br`:case`col`:case`hr`:case`keygen`:case`meta`:case`param`:case`track`:case`wbr`:case`menuitem`:for(u in n)if(n.hasOwnProperty(u)&&(r=n[u],r!=null))switch(u){case`children`:case`dangerouslySetInnerHTML`:throw Error(i(137,t));default:Pd(e,t,u,r,n,null)}return;default:if(zt(t)){for(d in n)n.hasOwnProperty(d)&&(r=n[d],r!==void 0&&Fd(e,t,d,r,n,void 0));return}}for(c in n)n.hasOwnProperty(c)&&(r=n[c],r!=null&&Pd(e,t,c,r,n,null))}function Ld(e,t,n,r){switch(t){case`div`:case`span`:case`svg`:case`path`:case`a`:case`g`:case`p`:case`li`:break;case`input`:var a=null,o=null,s=null,c=null,l=null,u=null,d=null;for(m in n){var f=n[m];if(n.hasOwnProperty(m)&&f!=null)switch(m){case`checked`:break;case`value`:break;case`defaultValue`:l=f;default:r.hasOwnProperty(m)||Pd(e,t,m,null,r,f)}}for(var p in r){var m=r[p];if(f=n[p],r.hasOwnProperty(p)&&(m!=null||f!=null))switch(p){case`type`:o=m;break;case`name`:a=m;break;case`checked`:u=m;break;case`defaultChecked`:d=m;break;case`value`:s=m;break;case`defaultValue`:c=m;break;case`children`:case`dangerouslySetInnerHTML`:if(m!=null)throw Error(i(137,t));break;default:m!==f&&Pd(e,t,p,m,r,f)}}kt(e,s,c,l,u,d,o,a);return;case`select`:for(o in m=s=c=p=null,n)if(l=n[o],n.hasOwnProperty(o)&&l!=null)switch(o){case`value`:break;case`multiple`:m=l;default:r.hasOwnProperty(o)||Pd(e,t,o,null,r,l)}for(a in r)if(o=r[a],l=n[a],r.hasOwnProperty(a)&&(o!=null||l!=null))switch(a){case`value`:p=o;break;case`defaultValue`:c=o;break;case`multiple`:s=o;default:o!==l&&Pd(e,t,a,o,r,l)}t=c,n=s,r=m,p==null?!!r!=!!n&&(t==null?Mt(e,!!n,n?[]:``,!1):Mt(e,!!n,t,!0)):Mt(e,!!n,p,!1);return;case`textarea`:for(c in m=p=null,n)if(a=n[c],n.hasOwnProperty(c)&&a!=null&&!r.hasOwnProperty(c))switch(c){case`value`:break;case`children`:break;default:Pd(e,t,c,null,r,a)}for(s in r)if(a=r[s],o=n[s],r.hasOwnProperty(s)&&(a!=null||o!=null))switch(s){case`value`:p=a;break;case`defaultValue`:m=a;break;case`children`:break;case`dangerouslySetInnerHTML`:if(a!=null)throw Error(i(91));break;default:a!==o&&Pd(e,t,s,a,r,o)}Nt(e,p,m);return;case`option`:for(var h in n)if(p=n[h],n.hasOwnProperty(h)&&p!=null&&!r.hasOwnProperty(h))switch(h){case`selected`:e.selected=!1;break;default:Pd(e,t,h,null,r,p)}for(l in r)if(p=r[l],m=n[l],r.hasOwnProperty(l)&&p!==m&&(p!=null||m!=null))switch(l){case`selected`:e.selected=p&&typeof p!=`function`&&typeof p!=`symbol`;break;default:Pd(e,t,l,p,r,m)}return;case`img`:case`link`:case`area`:case`base`:case`br`:case`col`:case`embed`:case`hr`:case`keygen`:case`meta`:case`param`:case`source`:case`track`:case`wbr`:case`menuitem`:for(var g in n)p=n[g],n.hasOwnProperty(g)&&p!=null&&!r.hasOwnProperty(g)&&Pd(e,t,g,null,r,p);for(u in r)if(p=r[u],m=n[u],r.hasOwnProperty(u)&&p!==m&&(p!=null||m!=null))switch(u){case`children`:case`dangerouslySetInnerHTML`:if(p!=null)throw Error(i(137,t));break;default:Pd(e,t,u,p,r,m)}return;default:if(zt(t)){for(var _ in n)p=n[_],n.hasOwnProperty(_)&&p!==void 0&&!r.hasOwnProperty(_)&&Fd(e,t,_,void 0,r,p);for(d in r)p=r[d],m=n[d],!r.hasOwnProperty(d)||p===m||p===void 0&&m===void 0||Fd(e,t,d,p,r,m);return}}for(var v in n)p=n[v],n.hasOwnProperty(v)&&p!=null&&!r.hasOwnProperty(v)&&Pd(e,t,v,null,r,p);for(f in r)p=r[f],m=n[f],!r.hasOwnProperty(f)||p===m||p==null&&m==null||Pd(e,t,f,p,r,m)}function Rd(e){switch(e){case`css`:case`script`:case`font`:case`img`:case`image`:case`input`:case`link`:return!0;default:return!1}}function zd(){if(typeof performance.getEntriesByType==`function`){for(var e=0,t=0,n=performance.getEntriesByType(`resource`),r=0;r<n.length;r++){var i=n[r],a=i.transferSize,o=i.initiatorType,s=i.duration;if(a&&s&&Rd(o)){for(o=0,s=i.responseEnd,r+=1;r<n.length;r++){var c=n[r],l=c.startTime;if(l>s)break;var u=c.transferSize,d=c.initiatorType;u&&Rd(d)&&(c=c.responseEnd,o+=u*(c<s?1:(s-l)/(c-l)))}if(--r,t+=8*(a+o)/(i.duration/1e3),e++,10<e)break}}if(0<e)return t/e/1e6}return navigator.connection&&(e=navigator.connection.downlink,typeof e==`number`)?e:5}var Bd=null,Vd=null;function Hd(e){return e.nodeType===9?e:e.ownerDocument}function Ud(e){switch(e){case`http://www.w3.org/2000/svg`:return 1;case`http://www.w3.org/1998/Math/MathML`:return 2;default:return 0}}function Wd(e,t){if(e===0)switch(t){case`svg`:return 1;case`math`:return 2;default:return 0}return e===1&&t===`foreignObject`?0:e}function Gd(e,t){return e===`textarea`||e===`noscript`||typeof t.children==`string`||typeof t.children==`number`||typeof t.children==`bigint`||typeof t.dangerouslySetInnerHTML==`object`&&t.dangerouslySetInnerHTML!==null&&t.dangerouslySetInnerHTML.__html!=null}var Kd=null;function qd(){var e=window.event;return e&&e.type===`popstate`?e===Kd?!1:(Kd=e,!0):(Kd=null,!1)}var Jd=typeof setTimeout==`function`?setTimeout:void 0,Yd=typeof clearTimeout==`function`?clearTimeout:void 0,Xd=typeof Promise==`function`?Promise:void 0,Zd=typeof queueMicrotask==`function`?queueMicrotask:Xd===void 0?Jd:function(e){return Xd.resolve(null).then(e).catch(Qd)};function Qd(e){setTimeout(function(){throw e})}function $d(e){return e===`head`}function ef(e,t){var n=t,r=0;do{var i=n.nextSibling;if(e.removeChild(n),i&&i.nodeType===8)if(n=i.data,n===`/$`||n===`/&`){if(r===0){e.removeChild(i),Fp(t);return}r--}else if(n===`$`||n===`$?`||n===`$~`||n===`$!`||n===`&`)r++;else if(n===`html`)hf(e.ownerDocument.documentElement);else if(n===`head`){n=e.ownerDocument.head,hf(n);for(var a=n.firstChild;a;){var o=a.nextSibling,s=a.nodeName;a[rt]||s===`SCRIPT`||s===`STYLE`||s===`LINK`&&a.rel.toLowerCase()===`stylesheet`||n.removeChild(a),a=o}}else n===`body`&&hf(e.ownerDocument.body);n=i}while(n);Fp(t)}function tf(e,t){var n=e;e=0;do{var r=n.nextSibling;if(n.nodeType===1?t?(n._stashedDisplay=n.style.display,n.style.display=`none`):(n.style.display=n._stashedDisplay||``,n.getAttribute(`style`)===``&&n.removeAttribute(`style`)):n.nodeType===3&&(t?(n._stashedText=n.nodeValue,n.nodeValue=``):n.nodeValue=n._stashedText||``),r&&r.nodeType===8)if(n=r.data,n===`/$`){if(e===0)break;e--}else n!==`$`&&n!==`$?`&&n!==`$~`&&n!==`$!`||e++;n=r}while(n)}function nf(e){var t=e.firstChild;for(t&&t.nodeType===10&&(t=t.nextSibling);t;){var n=t;switch(t=t.nextSibling,n.nodeName){case`HTML`:case`HEAD`:case`BODY`:nf(n),it(n);continue;case`SCRIPT`:case`STYLE`:continue;case`LINK`:if(n.rel.toLowerCase()===`stylesheet`)continue}e.removeChild(n)}}function rf(e,t,n,r){for(;e.nodeType===1;){var i=n;if(e.nodeName.toLowerCase()!==t.toLowerCase()){if(!r&&(e.nodeName!==`INPUT`||e.type!==`hidden`))break}else if(!r)if(t===`input`&&e.type===`hidden`){var a=i.name==null?null:``+i.name;if(i.type===`hidden`&&e.getAttribute(`name`)===a)return e}else return e;else if(!e[rt])switch(t){case`meta`:if(!e.hasAttribute(`itemprop`))break;return e;case`link`:if(a=e.getAttribute(`rel`),a===`stylesheet`&&e.hasAttribute(`data-precedence`)||a!==i.rel||e.getAttribute(`href`)!==(i.href==null||i.href===``?null:i.href)||e.getAttribute(`crossorigin`)!==(i.crossOrigin==null?null:i.crossOrigin)||e.getAttribute(`title`)!==(i.title==null?null:i.title))break;return e;case`style`:if(e.hasAttribute(`data-precedence`))break;return e;case`script`:if(a=e.getAttribute(`src`),(a!==(i.src==null?null:i.src)||e.getAttribute(`type`)!==(i.type==null?null:i.type)||e.getAttribute(`crossorigin`)!==(i.crossOrigin==null?null:i.crossOrigin))&&a&&e.hasAttribute(`async`)&&!e.hasAttribute(`itemprop`))break;return e;default:return e}if(e=uf(e.nextSibling),e===null)break}return null}function af(e,t,n){if(t===``)return null;for(;e.nodeType!==3;)if((e.nodeType!==1||e.nodeName!==`INPUT`||e.type!==`hidden`)&&!n||(e=uf(e.nextSibling),e===null))return null;return e}function of(e,t){for(;e.nodeType!==8;)if((e.nodeType!==1||e.nodeName!==`INPUT`||e.type!==`hidden`)&&!t||(e=uf(e.nextSibling),e===null))return null;return e}function sf(e){return e.data===`$?`||e.data===`$~`}function cf(e){return e.data===`$!`||e.data===`$?`&&e.ownerDocument.readyState!==`loading`}function lf(e,t){var n=e.ownerDocument;if(e.data===`$~`)e._reactRetry=t;else if(e.data!==`$?`||n.readyState!==`loading`)t();else{var r=function(){t(),n.removeEventListener(`DOMContentLoaded`,r)};n.addEventListener(`DOMContentLoaded`,r),e._reactRetry=r}}function uf(e){for(;e!=null;e=e.nextSibling){var t=e.nodeType;if(t===1||t===3)break;if(t===8){if(t=e.data,t===`$`||t===`$!`||t===`$?`||t===`$~`||t===`&`||t===`F!`||t===`F`)break;if(t===`/$`||t===`/&`)return null}}return e}var df=null;function ff(e){e=e.nextSibling;for(var t=0;e;){if(e.nodeType===8){var n=e.data;if(n===`/$`||n===`/&`){if(t===0)return uf(e.nextSibling);t--}else n!==`$`&&n!==`$!`&&n!==`$?`&&n!==`$~`&&n!==`&`||t++}e=e.nextSibling}return null}function pf(e){e=e.previousSibling;for(var t=0;e;){if(e.nodeType===8){var n=e.data;if(n===`$`||n===`$!`||n===`$?`||n===`$~`||n===`&`){if(t===0)return e;t--}else n!==`/$`&&n!==`/&`||t++}e=e.previousSibling}return null}function mf(e,t,n){switch(t=Hd(n),e){case`html`:if(e=t.documentElement,!e)throw Error(i(452));return e;case`head`:if(e=t.head,!e)throw Error(i(453));return e;case`body`:if(e=t.body,!e)throw Error(i(454));return e;default:throw Error(i(451))}}function hf(e){for(var t=e.attributes;t.length;)e.removeAttributeNode(t[0]);it(e)}var gf=new Map,_f=new Set;function vf(e){return typeof e.getRootNode==`function`?e.getRootNode():e.nodeType===9?e:e.ownerDocument}var yf=P.d;P.d={f:bf,r:xf,D:wf,C:Tf,L:Ef,m:Df,X:kf,S:Of,M:Af};function bf(){var e=yf.f(),t=yu();return e||t}function xf(e){var t=ot(e);t!==null&&t.tag===5&&t.type===`form`?vs(t):yf.r(e)}var Sf=typeof document>`u`?null:document;function Cf(e,t,n){var r=Sf;if(r&&typeof t==`string`&&t){var i=Ot(t);i=`link[rel="`+e+`"][href="`+i+`"]`,typeof n==`string`&&(i+=`[crossorigin="`+n+`"]`),_f.has(i)||(_f.add(i),e={rel:e,crossOrigin:n,href:t},r.querySelector(i)===null&&(t=r.createElement(`link`),Id(t,`link`,e),lt(t),r.head.appendChild(t)))}}function wf(e){yf.D(e),Cf(`dns-prefetch`,e,null)}function Tf(e,t){yf.C(e,t),Cf(`preconnect`,e,t)}function Ef(e,t,n){yf.L(e,t,n);var r=Sf;if(r&&e&&t){var i=`link[rel="preload"][as="`+Ot(t)+`"]`;t===`image`&&n&&n.imageSrcSet?(i+=`[imagesrcset="`+Ot(n.imageSrcSet)+`"]`,typeof n.imageSizes==`string`&&(i+=`[imagesizes="`+Ot(n.imageSizes)+`"]`)):i+=`[href="`+Ot(e)+`"]`;var a=i;switch(t){case`style`:a=Mf(e);break;case`script`:a=If(e)}gf.has(a)||(e=f({rel:`preload`,href:t===`image`&&n&&n.imageSrcSet?void 0:e,as:t},n),gf.set(a,e),r.querySelector(i)!==null||t===`style`&&r.querySelector(Nf(a))||t===`script`&&r.querySelector(Lf(a))||(t=r.createElement(`link`),Id(t,`link`,e),lt(t),r.head.appendChild(t)))}}function Df(e,t){yf.m(e,t);var n=Sf;if(n&&e){var r=t&&typeof t.as==`string`?t.as:`script`,i=`link[rel="modulepreload"][as="`+Ot(r)+`"][href="`+Ot(e)+`"]`,a=i;switch(r){case`audioworklet`:case`paintworklet`:case`serviceworker`:case`sharedworker`:case`worker`:case`script`:a=If(e)}if(!gf.has(a)&&(e=f({rel:`modulepreload`,href:e},t),gf.set(a,e),n.querySelector(i)===null)){switch(r){case`audioworklet`:case`paintworklet`:case`serviceworker`:case`sharedworker`:case`worker`:case`script`:if(n.querySelector(Lf(a)))return}r=n.createElement(`link`),Id(r,`link`,e),lt(r),n.head.appendChild(r)}}}function Of(e,t,n){yf.S(e,t,n);var r=Sf;if(r&&e){var i=ct(r).hoistableStyles,a=Mf(e);t||=`default`;var o=i.get(a);if(!o){var s={loading:0,preload:null};if(o=r.querySelector(Nf(a)))s.loading=5;else{e=f({rel:`stylesheet`,href:e,"data-precedence":t},n),(n=gf.get(a))&&Bf(e,n);var c=o=r.createElement(`link`);lt(c),Id(c,`link`,e),c._p=new Promise(function(e,t){c.onload=e,c.onerror=t}),c.addEventListener(`load`,function(){s.loading|=1}),c.addEventListener(`error`,function(){s.loading|=2}),s.loading|=4,zf(o,t,r)}o={type:`stylesheet`,instance:o,count:1,state:s},i.set(a,o)}}}function kf(e,t){yf.X(e,t);var n=Sf;if(n&&e){var r=ct(n).hoistableScripts,i=If(e),a=r.get(i);a||(a=n.querySelector(Lf(i)),a||(e=f({src:e,async:!0},t),(t=gf.get(i))&&Vf(e,t),a=n.createElement(`script`),lt(a),Id(a,`link`,e),n.head.appendChild(a)),a={type:`script`,instance:a,count:1,state:null},r.set(i,a))}}function Af(e,t){yf.M(e,t);var n=Sf;if(n&&e){var r=ct(n).hoistableScripts,i=If(e),a=r.get(i);a||(a=n.querySelector(Lf(i)),a||(e=f({src:e,async:!0,type:`module`},t),(t=gf.get(i))&&Vf(e,t),a=n.createElement(`script`),lt(a),Id(a,`link`,e),n.head.appendChild(a)),a={type:`script`,instance:a,count:1,state:null},r.set(i,a))}}function jf(e,t,n,r){var a=(a=H.current)?vf(a):null;if(!a)throw Error(i(446));switch(e){case`meta`:case`title`:return null;case`style`:return typeof n.precedence==`string`&&typeof n.href==`string`?(t=Mf(n.href),n=ct(a).hoistableStyles,r=n.get(t),r||(r={type:`style`,instance:null,count:0,state:null},n.set(t,r)),r):{type:`void`,instance:null,count:0,state:null};case`link`:if(n.rel===`stylesheet`&&typeof n.href==`string`&&typeof n.precedence==`string`){e=Mf(n.href);var o=ct(a).hoistableStyles,s=o.get(e);if(s||(a=a.ownerDocument||a,s={type:`stylesheet`,instance:null,count:0,state:{loading:0,preload:null}},o.set(e,s),(o=a.querySelector(Nf(e)))&&!o._p&&(s.instance=o,s.state.loading=5),gf.has(e)||(n={rel:`preload`,as:`style`,href:n.href,crossOrigin:n.crossOrigin,integrity:n.integrity,media:n.media,hrefLang:n.hrefLang,referrerPolicy:n.referrerPolicy},gf.set(e,n),o||Ff(a,e,n,s.state))),t&&r===null)throw Error(i(528,``));return s}if(t&&r!==null)throw Error(i(529,``));return null;case`script`:return t=n.async,n=n.src,typeof n==`string`&&t&&typeof t!=`function`&&typeof t!=`symbol`?(t=If(n),n=ct(a).hoistableScripts,r=n.get(t),r||(r={type:`script`,instance:null,count:0,state:null},n.set(t,r)),r):{type:`void`,instance:null,count:0,state:null};default:throw Error(i(444,e))}}function Mf(e){return`href="`+Ot(e)+`"`}function Nf(e){return`link[rel="stylesheet"][`+e+`]`}function Pf(e){return f({},e,{"data-precedence":e.precedence,precedence:null})}function Ff(e,t,n,r){e.querySelector(`link[rel="preload"][as="style"][`+t+`]`)?r.loading=1:(t=e.createElement(`link`),r.preload=t,t.addEventListener(`load`,function(){return r.loading|=1}),t.addEventListener(`error`,function(){return r.loading|=2}),Id(t,`link`,n),lt(t),e.head.appendChild(t))}function If(e){return`[src="`+Ot(e)+`"]`}function Lf(e){return`script[async]`+e}function Rf(e,t,n){if(t.count++,t.instance===null)switch(t.type){case`style`:var r=e.querySelector(`style[data-href~="`+Ot(n.href)+`"]`);if(r)return t.instance=r,lt(r),r;var a=f({},n,{"data-href":n.href,"data-precedence":n.precedence,href:null,precedence:null});return r=(e.ownerDocument||e).createElement(`style`),lt(r),Id(r,`style`,a),zf(r,n.precedence,e),t.instance=r;case`stylesheet`:a=Mf(n.href);var o=e.querySelector(Nf(a));if(o)return t.state.loading|=4,t.instance=o,lt(o),o;r=Pf(n),(a=gf.get(a))&&Bf(r,a),o=(e.ownerDocument||e).createElement(`link`),lt(o);var s=o;return s._p=new Promise(function(e,t){s.onload=e,s.onerror=t}),Id(o,`link`,r),t.state.loading|=4,zf(o,n.precedence,e),t.instance=o;case`script`:return o=If(n.src),(a=e.querySelector(Lf(o)))?(t.instance=a,lt(a),a):(r=n,(a=gf.get(o))&&(r=f({},n),Vf(r,a)),e=e.ownerDocument||e,a=e.createElement(`script`),lt(a),Id(a,`link`,r),e.head.appendChild(a),t.instance=a);case`void`:return null;default:throw Error(i(443,t.type))}else t.type===`stylesheet`&&!(t.state.loading&4)&&(r=t.instance,t.state.loading|=4,zf(r,n.precedence,e));return t.instance}function zf(e,t,n){for(var r=n.querySelectorAll(`link[rel="stylesheet"][data-precedence],style[data-precedence]`),i=r.length?r[r.length-1]:null,a=i,o=0;o<r.length;o++){var s=r[o];if(s.dataset.precedence===t)a=s;else if(a!==i)break}a?a.parentNode.insertBefore(e,a.nextSibling):(t=n.nodeType===9?n.head:n,t.insertBefore(e,t.firstChild))}function Bf(e,t){e.crossOrigin??=t.crossOrigin,e.referrerPolicy??=t.referrerPolicy,e.title??=t.title}function Vf(e,t){e.crossOrigin??=t.crossOrigin,e.referrerPolicy??=t.referrerPolicy,e.integrity??=t.integrity}var Hf=null;function Uf(e,t,n){if(Hf===null){var r=new Map,i=Hf=new Map;i.set(n,r)}else i=Hf,r=i.get(n),r||(r=new Map,i.set(n,r));if(r.has(e))return r;for(r.set(e,null),n=n.getElementsByTagName(e),i=0;i<n.length;i++){var a=n[i];if(!(a[rt]||a[Xe]||e===`link`&&a.getAttribute(`rel`)===`stylesheet`)&&a.namespaceURI!==`http://www.w3.org/2000/svg`){var o=a.getAttribute(t)||``;o=e+o;var s=r.get(o);s?s.push(a):r.set(o,[a])}}return r}function Wf(e,t,n){e=e.ownerDocument||e,e.head.insertBefore(n,t===`title`?e.querySelector(`head > title`):null)}function Gf(e,t,n){if(n===1||t.itemProp!=null)return!1;switch(e){case`meta`:case`title`:return!0;case`style`:if(typeof t.precedence!=`string`||typeof t.href!=`string`||t.href===``)break;return!0;case`link`:if(typeof t.rel!=`string`||typeof t.href!=`string`||t.href===``||t.onLoad||t.onError)break;switch(t.rel){case`stylesheet`:return e=t.disabled,typeof t.precedence==`string`&&e==null;default:return!0}case`script`:if(t.async&&typeof t.async!=`function`&&typeof t.async!=`symbol`&&!t.onLoad&&!t.onError&&t.src&&typeof t.src==`string`)return!0}return!1}function Kf(e){return!(e.type===`stylesheet`&&!(e.state.loading&3))}function qf(e,t,n,r){if(n.type===`stylesheet`&&(typeof r.media!=`string`||!1!==matchMedia(r.media).matches)&&!(n.state.loading&4)){if(n.instance===null){var i=Mf(r.href),a=t.querySelector(Nf(i));if(a){t=a._p,typeof t==`object`&&t&&typeof t.then==`function`&&(e.count++,e=Xf.bind(e),t.then(e,e)),n.state.loading|=4,n.instance=a,lt(a);return}a=t.ownerDocument||t,r=Pf(r),(i=gf.get(i))&&Bf(r,i),a=a.createElement(`link`),lt(a);var o=a;o._p=new Promise(function(e,t){o.onload=e,o.onerror=t}),Id(a,`link`,r),n.instance=a}e.stylesheets===null&&(e.stylesheets=new Map),e.stylesheets.set(n,t),(t=n.state.preload)&&!(n.state.loading&3)&&(e.count++,n=Xf.bind(e),t.addEventListener(`load`,n),t.addEventListener(`error`,n))}}var Jf=0;function Yf(e,t){return e.stylesheets&&e.count===0&&Qf(e,e.stylesheets),0<e.count||0<e.imgCount?function(n){var r=setTimeout(function(){if(e.stylesheets&&Qf(e,e.stylesheets),e.unsuspend){var t=e.unsuspend;e.unsuspend=null,t()}},6e4+t);0<e.imgBytes&&Jf===0&&(Jf=62500*zd());var i=setTimeout(function(){if(e.waitingForImages=!1,e.count===0&&(e.stylesheets&&Qf(e,e.stylesheets),e.unsuspend)){var t=e.unsuspend;e.unsuspend=null,t()}},(e.imgBytes>Jf?50:800)+t);return e.unsuspend=n,function(){e.unsuspend=null,clearTimeout(r),clearTimeout(i)}}:null}function Xf(){if(this.count--,this.count===0&&(this.imgCount===0||!this.waitingForImages)){if(this.stylesheets)Qf(this,this.stylesheets);else if(this.unsuspend){var e=this.unsuspend;this.unsuspend=null,e()}}}var Zf=null;function Qf(e,t){e.stylesheets=null,e.unsuspend!==null&&(e.count++,Zf=new Map,t.forEach($f,e),Zf=null,Xf.call(e))}function $f(e,t){if(!(t.state.loading&4)){var n=Zf.get(e);if(n)var r=n.get(null);else{n=new Map,Zf.set(e,n);for(var i=e.querySelectorAll(`link[data-precedence],style[data-precedence]`),a=0;a<i.length;a++){var o=i[a];(o.nodeName===`LINK`||o.getAttribute(`media`)!==`not all`)&&(n.set(o.dataset.precedence,o),r=o)}r&&n.set(null,r)}i=t.instance,o=i.getAttribute(`data-precedence`),a=n.get(o)||r,a===r&&n.set(null,i),n.set(o,i),this.count++,r=Xf.bind(this),i.addEventListener(`load`,r),i.addEventListener(`error`,r),a?a.parentNode.insertBefore(i,a.nextSibling):(e=e.nodeType===9?e.head:e,e.insertBefore(i,e.firstChild)),t.state.loading|=4}}var ep={$$typeof:b,Provider:null,Consumer:null,_currentValue:F,_currentValue2:F,_threadCount:0};function tp(e,t,n,r,i,a,o,s,c){this.tag=1,this.containerInfo=e,this.pingCache=this.current=this.pendingChildren=null,this.timeoutHandle=-1,this.callbackNode=this.next=this.pendingContext=this.context=this.cancelPendingCommit=null,this.callbackPriority=0,this.expirationTimes=ze(-1),this.entangledLanes=this.shellSuspendCounter=this.errorRecoveryDisabledLanes=this.expiredLanes=this.warmLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=ze(0),this.hiddenUpdates=ze(null),this.identifierPrefix=r,this.onUncaughtError=i,this.onCaughtError=a,this.onRecoverableError=o,this.pooledCache=null,this.pooledCacheLanes=0,this.formState=c,this.incompleteTransitions=new Map}function np(e,t,n,r,i,a,o,s,c,l,u,d){return e=new tp(e,t,n,o,c,l,u,d,s),t=1,!0===a&&(t|=24),a=Xr(3,null,null,t),e.current=a,a.stateNode=e,t=Zi(),t.refCount++,e.pooledCache=t,t.refCount++,a.memoizedState={element:r,isDehydrated:n,cache:t},ka(a),e}function rp(e){return e?(e=Jr,e):Jr}function ip(e,t,n,r,i,a){i=rp(i),r.context===null?r.context=i:r.pendingContext=i,r=ja(t),r.payload={element:n},a=a===void 0?null:a,a!==null&&(r.callback=a),n=Ma(e,r,t),n!==null&&(mu(n,e,t),Na(n,e,t))}function ap(e,t){if(e=e.memoizedState,e!==null&&e.dehydrated!==null){var n=e.retryLane;e.retryLane=n!==0&&n<t?n:t}}function op(e,t){ap(e,t),(e=e.alternate)&&ap(e,t)}function sp(e){if(e.tag===13||e.tag===31){var t=Gr(e,67108864);t!==null&&mu(t,e,67108864),op(e,67108864)}}function cp(e){if(e.tag===13||e.tag===31){var t=fu();t=Ge(t);var n=Gr(e,t);n!==null&&mu(n,e,t),op(e,t)}}var lp=!0;function up(e,t,n,r){var i=N.T;N.T=null;var a=P.p;try{P.p=2,fp(e,t,n,r)}finally{P.p=a,N.T=i}}function dp(e,t,n,r){var i=N.T;N.T=null;var a=P.p;try{P.p=8,fp(e,t,n,r)}finally{P.p=a,N.T=i}}function fp(e,t,n,r){if(lp){var i=pp(r);if(i===null)Td(e,t,r,mp,n),Tp(e,r);else if(Dp(i,e,t,n,r))r.stopPropagation();else if(Tp(e,r),t&4&&-1<wp.indexOf(e)){for(;i!==null;){var a=ot(i);if(a!==null)switch(a.tag){case 3:if(a=a.stateNode,a.current.memoizedState.isDehydrated){var o=Pe(a.pendingLanes);if(o!==0){var s=a;for(s.pendingLanes|=2,s.entangledLanes|=2;o;){var c=1<<31-De(o);s.entanglements[1]|=c,o&=~c}rd(a),!(Nl&6)&&(eu=he()+500,id(0,!1))}}break;case 31:case 13:s=Gr(a,2),s!==null&&mu(s,a,2),yu(),op(a,2)}if(a=pp(r),a===null&&Td(e,t,r,mp,n),a===i)break;i=a}i!==null&&r.stopPropagation()}else Td(e,t,r,null,n)}}function pp(e){return e=Gt(e),hp(e)}var mp=null;function hp(e){if(mp=null,e=at(e),e!==null){var t=o(e);if(t===null)e=null;else{var n=t.tag;if(n===13){if(e=s(t),e!==null)return e;e=null}else if(n===31){if(e=c(t),e!==null)return e;e=null}else if(n===3){if(t.stateNode.current.memoizedState.isDehydrated)return t.tag===3?t.stateNode.containerInfo:null;e=null}else t!==e&&(e=null)}}return mp=e,null}function gp(e){switch(e){case`beforetoggle`:case`cancel`:case`click`:case`close`:case`contextmenu`:case`copy`:case`cut`:case`auxclick`:case`dblclick`:case`dragend`:case`dragstart`:case`drop`:case`focusin`:case`focusout`:case`input`:case`invalid`:case`keydown`:case`keypress`:case`keyup`:case`mousedown`:case`mouseup`:case`paste`:case`pause`:case`play`:case`pointercancel`:case`pointerdown`:case`pointerup`:case`ratechange`:case`reset`:case`resize`:case`seeked`:case`submit`:case`toggle`:case`touchcancel`:case`touchend`:case`touchstart`:case`volumechange`:case`change`:case`selectionchange`:case`textInput`:case`compositionstart`:case`compositionend`:case`compositionupdate`:case`beforeblur`:case`afterblur`:case`beforeinput`:case`blur`:case`fullscreenchange`:case`focus`:case`hashchange`:case`popstate`:case`select`:case`selectstart`:return 2;case`drag`:case`dragenter`:case`dragexit`:case`dragleave`:case`dragover`:case`mousemove`:case`mouseout`:case`mouseover`:case`pointermove`:case`pointerout`:case`pointerover`:case`scroll`:case`touchmove`:case`wheel`:case`mouseenter`:case`mouseleave`:case`pointerenter`:case`pointerleave`:return 8;case`message`:switch(ge()){case _e:return 2;case ve:return 8;case ye:case be:return 32;case xe:return 268435456;default:return 32}default:return 32}}var _p=!1,vp=null,yp=null,bp=null,xp=new Map,Sp=new Map,Cp=[],wp=`mousedown mouseup touchcancel touchend touchstart auxclick dblclick pointercancel pointerdown pointerup dragend dragstart drop compositionend compositionstart keydown keypress keyup input textInput copy cut paste click change contextmenu reset`.split(` `);function Tp(e,t){switch(e){case`focusin`:case`focusout`:vp=null;break;case`dragenter`:case`dragleave`:yp=null;break;case`mouseover`:case`mouseout`:bp=null;break;case`pointerover`:case`pointerout`:xp.delete(t.pointerId);break;case`gotpointercapture`:case`lostpointercapture`:Sp.delete(t.pointerId)}}function Ep(e,t,n,r,i,a){return e===null||e.nativeEvent!==a?(e={blockedOn:t,domEventName:n,eventSystemFlags:r,nativeEvent:a,targetContainers:[i]},t!==null&&(t=ot(t),t!==null&&sp(t)),e):(e.eventSystemFlags|=r,t=e.targetContainers,i!==null&&t.indexOf(i)===-1&&t.push(i),e)}function Dp(e,t,n,r,i){switch(t){case`focusin`:return vp=Ep(vp,e,t,n,r,i),!0;case`dragenter`:return yp=Ep(yp,e,t,n,r,i),!0;case`mouseover`:return bp=Ep(bp,e,t,n,r,i),!0;case`pointerover`:var a=i.pointerId;return xp.set(a,Ep(xp.get(a)||null,e,t,n,r,i)),!0;case`gotpointercapture`:return a=i.pointerId,Sp.set(a,Ep(Sp.get(a)||null,e,t,n,r,i)),!0}return!1}function Op(e){var t=at(e.target);if(t!==null){var n=o(t);if(n!==null){if(t=n.tag,t===13){if(t=s(n),t!==null){e.blockedOn=t,Je(e.priority,function(){cp(n)});return}}else if(t===31){if(t=c(n),t!==null){e.blockedOn=t,Je(e.priority,function(){cp(n)});return}}else if(t===3&&n.stateNode.current.memoizedState.isDehydrated){e.blockedOn=n.tag===3?n.stateNode.containerInfo:null;return}}}e.blockedOn=null}function kp(e){if(e.blockedOn!==null)return!1;for(var t=e.targetContainers;0<t.length;){var n=pp(e.nativeEvent);if(n===null){n=e.nativeEvent;var r=new n.constructor(n.type,n);Wt=r,n.target.dispatchEvent(r),Wt=null}else return t=ot(n),t!==null&&sp(t),e.blockedOn=n,!1;t.shift()}return!0}function Ap(e,t,n){kp(e)&&n.delete(t)}function jp(){_p=!1,vp!==null&&kp(vp)&&(vp=null),yp!==null&&kp(yp)&&(yp=null),bp!==null&&kp(bp)&&(bp=null),xp.forEach(Ap),Sp.forEach(Ap)}function Mp(e,n){e.blockedOn===n&&(e.blockedOn=null,_p||(_p=!0,t.unstable_scheduleCallback(t.unstable_NormalPriority,jp)))}var Np=null;function Pp(e){Np!==e&&(Np=e,t.unstable_scheduleCallback(t.unstable_NormalPriority,function(){Np===e&&(Np=null);for(var t=0;t<e.length;t+=3){var n=e[t],r=e[t+1],i=e[t+2];if(typeof r!=`function`){if(hp(r||n)===null)continue;break}var a=ot(n);a!==null&&(e.splice(t,3),t-=3,gs(a,{pending:!0,data:i,method:n.method,action:r},r,i))}}))}function Fp(e){function t(t){return Mp(t,e)}vp!==null&&Mp(vp,e),yp!==null&&Mp(yp,e),bp!==null&&Mp(bp,e),xp.forEach(t),Sp.forEach(t);for(var n=0;n<Cp.length;n++){var r=Cp[n];r.blockedOn===e&&(r.blockedOn=null)}for(;0<Cp.length&&(n=Cp[0],n.blockedOn===null);)Op(n),n.blockedOn===null&&Cp.shift();if(n=(e.ownerDocument||e).$$reactFormReplay,n!=null)for(r=0;r<n.length;r+=3){var i=n[r],a=n[r+1],o=i[Ze]||null;if(typeof a==`function`)o||Pp(n);else if(o){var s=null;if(a&&a.hasAttribute(`formAction`)){if(i=a,o=a[Ze]||null)s=o.formAction;else if(hp(i)!==null)continue}else s=o.action;typeof s==`function`?n[r+1]=s:(n.splice(r,3),r-=3),Pp(n)}}}function Ip(){function e(e){e.canIntercept&&e.info===`react-transition`&&e.intercept({handler:function(){return new Promise(function(e){return i=e})},focusReset:`manual`,scroll:`manual`})}function t(){i!==null&&(i(),i=null),r||setTimeout(n,20)}function n(){if(!r&&!navigation.transition){var e=navigation.currentEntry;e&&e.url!=null&&navigation.navigate(e.url,{state:e.getState(),info:`react-transition`,history:`replace`})}}if(typeof navigation==`object`){var r=!1,i=null;return navigation.addEventListener(`navigate`,e),navigation.addEventListener(`navigatesuccess`,t),navigation.addEventListener(`navigateerror`,t),setTimeout(n,100),function(){r=!0,navigation.removeEventListener(`navigate`,e),navigation.removeEventListener(`navigatesuccess`,t),navigation.removeEventListener(`navigateerror`,t),i!==null&&(i(),i=null)}}}function Lp(e){this._internalRoot=e}Rp.prototype.render=Lp.prototype.render=function(e){var t=this._internalRoot;if(t===null)throw Error(i(409));var n=t.current;ip(n,fu(),e,t,null,null)},Rp.prototype.unmount=Lp.prototype.unmount=function(){var e=this._internalRoot;if(e!==null){this._internalRoot=null;var t=e.containerInfo;ip(e.current,2,null,e,null,null),yu(),t[Qe]=null}};function Rp(e){this._internalRoot=e}Rp.prototype.unstable_scheduleHydration=function(e){if(e){var t=qe();e={blockedOn:null,target:e,priority:t};for(var n=0;n<Cp.length&&t!==0&&t<Cp[n].priority;n++);Cp.splice(n,0,e),n===0&&Op(e)}};var zp=n.version;if(zp!==`19.2.5`)throw Error(i(527,zp,`19.2.5`));P.findDOMNode=function(e){var t=e._reactInternals;if(t===void 0)throw typeof e.render==`function`?Error(i(188)):(e=Object.keys(e).join(`,`),Error(i(268,e)));return e=u(t),e=e===null?null:d(e),e=e===null?null:e.stateNode,e};var Bp={bundleType:0,version:`19.2.5`,rendererPackageName:`react-dom`,currentDispatcherRef:N,reconcilerVersion:`19.2.5`};if(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<`u`){var Vp=__REACT_DEVTOOLS_GLOBAL_HOOK__;if(!Vp.isDisabled&&Vp.supportsFiber)try{we=Vp.inject(Bp),Te=Vp}catch{}}e.createRoot=function(e,t){if(!a(e))throw Error(i(299));var n=!1,r=``,o=zs,s=Bs,c=Vs;return t!=null&&(!0===t.unstable_strictMode&&(n=!0),t.identifierPrefix!==void 0&&(r=t.identifierPrefix),t.onUncaughtError!==void 0&&(o=t.onUncaughtError),t.onCaughtError!==void 0&&(s=t.onCaughtError),t.onRecoverableError!==void 0&&(c=t.onRecoverableError)),t=np(e,1,!1,null,null,n,r,null,o,s,c,Ip),e[Qe]=t.current,Cd(e),new Lp(t)}})),cX=l(((e,t)=>{function n(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>`u`||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!=`function`))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(n)}catch(e){console.error(e)}}n(),t.exports=sX()})),Z=nX(),lX=iX(),uX=cX();function dX(){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)}}}}var fX=l((e=>{var t=Symbol.for(`react.transitional.element`),n=Symbol.for(`react.fragment`);function r(e,n,r){var i=null;if(r!==void 0&&(i=``+r),n.key!==void 0&&(i=``+n.key),`key`in n)for(var a in r={},n)a!==`key`&&(r[a]=n[a]);else r=n;return n=r.ref,{$$typeof:t,type:e,key:i,ref:n===void 0?null:n,props:r}}e.Fragment=n,e.jsx=r,e.jsxs=r})),Q=l(((e,t)=>{t.exports=fX()}))();function pX(){return(0,Q.jsxs)(`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 `,(0,Q.jsx)(`strong`,{style:{color:`var(--accent, #f5a524)`,fontWeight:700},children:`Kymoscope`})]})}function mX(){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 hX(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 gX(e){return Math.max(0,(e>>1)-1)}var _X=2.5,vX=`#version 300 es
|
|
92
92
|
in vec2 a_corner; // static quad corner: (±1, ±1)
|
|
93
93
|
in vec2 a_a; // per-instance: segment start (CSS px)
|
|
94
94
|
in vec2 a_b; // per-instance: segment end (CSS px)
|
|
@@ -113,7 +113,7 @@ void main() {
|
|
|
113
113
|
v_pos = pos;
|
|
114
114
|
vec2 clip = pos / u_resolution * 2.0 - 1.0; // 0..1 → -1..1
|
|
115
115
|
gl_Position = vec4(clip.x, -clip.y, 0.0, 1.0); // flip y (px down → clip up)
|
|
116
|
-
}`,
|
|
116
|
+
}`,yX=`#version 300 es
|
|
117
117
|
precision highp float;
|
|
118
118
|
uniform vec4 u_color;
|
|
119
119
|
uniform float u_halfWidth; // visible half-thickness (CSS px)
|
|
@@ -144,7 +144,7 @@ void main() {
|
|
|
144
144
|
// correct on premultiplied colour — straight alpha would darken the AA fringe.
|
|
145
145
|
float a = u_color.a * cov;
|
|
146
146
|
outColor = vec4(u_color.rgb * a, a);
|
|
147
|
-
}`;function
|
|
147
|
+
}`;function bX(e,t,n){let r=e.createShader(t);return r?(e.shaderSource(r,n),e.compileShader(r),e.getShaderParameter(r,e.COMPILE_STATUS)?r:(console.error(`glLines shader compile failed:`,e.getShaderInfoLog(r)),e.deleteShader(r),null)):null}function xX(e,t=1){let n=e.getContext(`webgl2`,{antialias:!1,alpha:!0,premultipliedAlpha:!0});if(!n)return null;let r=bX(n,n.VERTEX_SHADER,vX),i=bX(n,n.FRAGMENT_SHADER,yX);if(!r||!i)return null;let a=n.createProgram();if(!a||(n.attachShader(a,r),n.attachShader(a,i),n.linkProgram(a),!n.getProgramParameter(a,n.LINK_STATUS)))return null;let o=n.getAttribLocation(a,`a_corner`),s=n.getAttribLocation(a,`a_a`),c=n.getAttribLocation(a,`a_b`),l=n.getUniformLocation(a,`u_resolution`),u=n.getUniformLocation(a,`u_color`),d=n.getUniformLocation(a,`u_ext`),f=n.getUniformLocation(a,`u_halfWidth`),p=n.createBuffer();n.bindBuffer(n.ARRAY_BUFFER,p),n.bufferData(n.ARRAY_BUFFER,Float32Array.from([-1,-1,1,-1,-1,1,1,1]),n.STATIC_DRAW);let m=n.createBuffer(),h=n.createFramebuffer(),g=n.createRenderbuffer(),_=1,v=1,y=(`clientWidth`in e?e.clientWidth:0)||1,b=(`clientHeight`in e?e.clientHeight:0)||1,x=1;return{resize(t,r,i){y=Math.max(1,t),b=Math.max(1,r),x=i*2,e.width=Math.round(y*i),e.height=Math.round(b*i),_=e.width*2,v=e.height*2,h&&g&&(n.bindRenderbuffer(n.RENDERBUFFER,g),n.renderbufferStorage(n.RENDERBUFFER,n.RGBA8,_,v),n.bindFramebuffer(n.FRAMEBUFFER,h),n.framebufferRenderbuffer(n.FRAMEBUFFER,n.COLOR_ATTACHMENT0,n.RENDERBUFFER,g),n.bindFramebuffer(n.FRAMEBUFFER,null))},draw(r){n.bindFramebuffer(n.FRAMEBUFFER,h),n.viewport(0,0,h?_:e.width,h?v:e.height),n.disable(n.SCISSOR_TEST),n.clearColor(0,0,0,0),n.clear(n.COLOR_BUFFER_BIT),n.useProgram(a),n.uniform2f(l,y,b),n.enable(n.BLEND),n.blendFunc(n.ONE,n.ONE_MINUS_SRC_ALPHA),n.bindBuffer(n.ARRAY_BUFFER,p),n.enableVertexAttribArray(o),n.vertexAttribPointer(o,2,n.FLOAT,!1,0,0),n.vertexAttribDivisor(o,0),n.bindBuffer(n.ARRAY_BUFFER,m),n.enableVertexAttribArray(s),n.vertexAttribPointer(s,2,n.FLOAT,!1,8,0),n.vertexAttribDivisor(s,1),n.enableVertexAttribArray(c),n.vertexAttribPointer(c,2,n.FLOAT,!1,8,8),n.vertexAttribDivisor(c,1);for(let e of r){let r=gX(e.points.length);if(r<1)continue;e.clip?(n.enable(n.SCISSOR_TEST),n.scissor(Math.round(e.clip.x*x),Math.round((b-e.clip.y-e.clip.h)*x),Math.round(e.clip.w*x),Math.round(e.clip.h*x))):n.disable(n.SCISSOR_TEST),n.bufferData(n.ARRAY_BUFFER,e.points,n.DYNAMIC_DRAW),n.uniform4fv(u,e.color);let i=e.width??t;n.uniform1f(d,i/2+_X),n.uniform1f(f,i/2),n.drawArraysInstanced(n.TRIANGLE_STRIP,0,4,r)}n.disable(n.SCISSOR_TEST),n.vertexAttribDivisor(s,0),n.vertexAttribDivisor(c,0),h&&(n.bindFramebuffer(n.READ_FRAMEBUFFER,h),n.bindFramebuffer(n.DRAW_FRAMEBUFFER,null),n.blitFramebuffer(0,0,_,v,0,0,e.width,e.height,n.COLOR_BUFFER_BIT,n.LINEAR),n.bindFramebuffer(n.FRAMEBUFFER,null))},dispose(){n.deleteBuffer(p),n.deleteBuffer(m),n.deleteFramebuffer(h),n.deleteRenderbuffer(g),n.deleteProgram(a),n.deleteShader(r),n.deleteShader(i),n.getExtension(`WEBGL_lose_context`)?.loseContext()}}}var SX=12,CX=0,wX=null,TX=new Set;function EX(){if(CX<SX)return!0;for(let e of[...TX]){if(CX<SX)break;e.hidden()&&e.evict()}return CX<SX}function DX(e){CX++,e&&TX.add(e);let t=!1;return()=>{t||(t=!0,CX--,e&&TX.delete(e))}}var OX=new Set;function kX(){if(wX&&!wX.gl.isContextLost())return wX;let e=document.createElement(`canvas`);e.width=1,e.height=1;let t=e.getContext(`webgl2`,{antialias:!1,alpha:!0,premultipliedAlpha:!0,preserveDrawingBuffer:!1});return wX=t?{canvas:e,gl:t}:null,e.addEventListener(`webglcontextlost`,e=>{e.preventDefault(),setTimeout(()=>{for(let e of[...OX])e()},0)}),wX}function AX(e,t=!1){if(t&&CX<SX){let t=DX();return{canvas:e,shared:!1,present(){},lost:()=>!1,release(){t();try{e.getContext(`webgl2`)?.getExtension(`WEBGL_lose_context`)?.loseContext()}catch{}}}}let n=kX();if(!n)return{canvas:e,shared:!1,present(){},lost:()=>!1,release(){}};let r=1,i=1,a={get width(){return r},set width(e){r=Math.max(1,Math.round(e)),n.canvas.width<r&&(n.canvas.width=r)},get height(){return i},set height(e){i=Math.max(1,Math.round(e)),n.canvas.height<i&&(n.canvas.height=i)},getContext(e){return e===`webgl2`?n.gl:null}},o=null;return{canvas:a,shared:!0,present(){e.width!==r&&(e.width=r),e.height!==i&&(e.height=i),o??=e.getContext(`2d`),o&&(o.globalCompositeOperation=`copy`,o.drawImage(n.canvas,0,n.canvas.height-i,r,i,0,0,r,i),o.globalCompositeOperation=`source-over`)},lost:()=>n.gl.isContextLost(),release(){}}}var jX=new WeakMap;function MX(e,t,n){let r=jX.get(e);return r||jX.set(e,r=new Map),r.has(t)||r.set(t,n()),r.get(t)}function NX(e,t){let n=AX(e),r=t(n.canvas);if(!r)return n.release(),null;let i=new Map,a=(e,t)=>{let n=t[0];return typeof n==`string`||typeof n==`number`&&(e===`setData`||e===`setStyles`)?`${e}:${n}`:e},o=(e,t)=>{let n=e=>{for(let t of[...i.keys()]){let n=t.indexOf(`:`);n>0&&!e(t.slice(n+1))&&i.delete(t)}};if(e===`remove`||e===`clearLayer`)n(e=>e!==String(t[0]));else if(e===`keep`&&Array.isArray(t[0])){let e=new Set(t[0].map(String));n(t=>e.has(t))}},s=()=>{try{r.dispose()}catch{}n.release(),n=AX(e);let a=t(n.canvas);if(!a)return!1;r=a;let o=[...i.values()];for(let e of o.filter(e=>e.name===`resize`).concat(o.filter(e=>e.name!==`resize`)))r[e.name](...e.args);return!0},c=()=>(n.lost()&&s(),r),l=()=>{n.lost()&&s()&&(r.render(),n.present())};return OX.add(l),new Proxy({},{get(e,t){if(t===`dispose`)return()=>{OX.delete(l),i.clear(),r.dispose(),n.release()};if(t===`render`)return()=>{c().render(),n.present()};let s=c()[t];return typeof s!=`function`||typeof t!=`string`?s:(...e)=>{if(o(t,e),t.startsWith(`set`)||t===`resize`){let n=a(t,e),r=i.get(n),o=t===`setData`&&typeof e[0]==`number`&&e[1]===null&&r?[e[0],r.args[1],r.args[2],...e.slice(3)]:e;i.delete(n),i.set(n,{name:t,args:o})}return s.apply(c(),e)}}})}var PX=1024,FX=`#version 300 es
|
|
148
148
|
in vec2 a_corner; // static quad corner: (±1, ±1)
|
|
149
149
|
in float a_ax; // per instance: segment start/end X (relative to the layer origin)
|
|
150
150
|
in float a_bx;
|
|
@@ -168,7 +168,7 @@ flat out float v_halfWidth;
|
|
|
168
168
|
flat out vec4 v_clip; // left, top, right, bottom (CSS px)
|
|
169
169
|
out vec2 v_pos;
|
|
170
170
|
vec4 style(int sid, int k) {
|
|
171
|
-
return texelFetch(u_styles, ivec2((sid % ${
|
|
171
|
+
return texelFetch(u_styles, ivec2((sid % ${PX}) * 3 + k, sid / ${PX}), 0);
|
|
172
172
|
}
|
|
173
173
|
void main() {
|
|
174
174
|
int sid = int(a_sid + 0.5);
|
|
@@ -203,7 +203,7 @@ void main() {
|
|
|
203
203
|
v_clip = vec4(u_left, top, min(u_left + u_plotW, u_cutPx), bottom);
|
|
204
204
|
vec2 clip = pos / u_resolution * 2.0 - 1.0;
|
|
205
205
|
gl_Position = vec4(clip.x, -clip.y, 0.0, 1.0);
|
|
206
|
-
}`,
|
|
206
|
+
}`,IX=`#version 300 es
|
|
207
207
|
precision highp float;
|
|
208
208
|
flat in vec2 v_a;
|
|
209
209
|
flat in vec2 v_b;
|
|
@@ -223,8 +223,8 @@ void main() {
|
|
|
223
223
|
if (cov <= 0.0) discard;
|
|
224
224
|
float alpha = v_color.a * cov;
|
|
225
225
|
outColor = vec4(v_color.rgb * alpha, alpha);
|
|
226
|
-
}`;function hX(e,t,n,r){let i=e.length,a=0;for(let t=0;t<i;t++)Number.isFinite(r[t])&&Number.isFinite(e[t])&&a++;if(a===i)return null;let o=new Float32Array(a),s=new Float32Array(a),c=new Uint8Array(a),l=0,u=!1;for(let a=0;a<i;a++)n[a]&&(u=!0),Number.isFinite(r[a])&&Number.isFinite(e[a])&&(o[l]=t[a],s[l]=r[a],u&&=(c[l]=255,!1),l++);return{x:o,y:s,starts:c}}function gX(e,t,n){let r=e.length,i=0;for(let t=0;t<r;t++)if(Number.isFinite(e[t])){i=e[t];break}let a=new Float32Array(r);for(let t=0;t<r;t++)a[t]=e[t]-i;let o=new Uint8Array(r);if(t)for(let e=0;e<r;e++)t[e]&&(o[e]=255);let s=n.map(t=>hX(e,a,o,t)??{x:a,y:t,starts:o}),c=s.map(e=>e.y.length),l=c.reduce((e,t)=>e+t,0),u=new Float32Array(l),d=new Float32Array(l),f=new Uint8Array(l),p=new Float32Array(l),m=0;return s.forEach((e,t)=>{u.set(e.x,m),d.set(e.y,m),f.set(e.starts,m),e.y.length>0&&(f[m]=255),p.fill(t,m,m+e.y.length),m+=e.y.length}),{origin:i,x:u,y:d,starts:f,sid:p,counts:c}}function _X(e,t,n,r,i,a){let o=(i-r)/a,s=(t,n)=>{let r=0,i=e.length;for(;r<i;){let a=r+i>>>1;(n?e[a]<=t:e[a]<t)?r=a+1:i=a}return r},c=s(r,!1),l=s(i,!0),u=t.length*(2*a+2),d=new Float32Array(u),f=new Float32Array(u),p=new Uint8Array(u),m=new Float32Array(u),h=0,g=(e,t,r)=>{d[h]=e-n,f[h]=t,m[h]=r,h++};return t.forEach((t,n)=>{let i=h;for(let r=c-1;r>=Math.max(0,c-64);r--)if(t[r]===t[r]){g(e[r],t[r],n);break}let s=c;for(let i=0;i<a&&s<l;i++){let c=i===a-1?1/0:r+(i+1)*o,u=1/0,d=-1/0,f=-1,p=-1;for(;s<l&&e[s]<c;s++){let e=t[s];e<u&&(u=e,f=s),e>d&&(d=e,p=s)}f<0||(f===p?g(e[f],u,n):f<p?(g(e[f],u,n),g(e[p],d,n)):(g(e[p],d,n),g(e[f],u,n)))}for(let r=l;r<Math.min(e.length,l+64);r++)if(t[r]===t[r]){g(e[r],t[r],n);break}h>i&&(p[i]=255)}),{x:d.subarray(0,h),y:f.subarray(0,h),starts:p.subarray(0,h),sid:m.subarray(0,h),bucket:o}}function vX(e){for(let t=1;t<e.length;t++)if(!(e[t]>=e[t-1]))return!1;return e.length===0||e[0]===e[0]}function yX(e,t=1){let n=e.getContext(`webgl2`,{antialias:!1,alpha:!0,premultipliedAlpha:!0}),r=typeof HTMLCanvasElement<`u`&&e instanceof HTMLCanvasElement||typeof OffscreenCanvas<`u`&&e instanceof OffscreenCanvas;if(!n)return null;let i=()=>{let e=QY(n,n.VERTEX_SHADER,pX),t=QY(n,n.FRAGMENT_SHADER,mX);if(!e||!t)return null;let r=n.createProgram();return r?(n.attachShader(r,e),n.attachShader(r,t),n.linkProgram(r),n.getProgramParameter(r,n.LINK_STATUS)?{prog:r,vs:e,fs:t}:(console.error(`glSeries program link failed:`,n.getProgramInfoLog(r)),null)):null},a=r?i():uX(n,`glSeries`,i);if(!a)return null;let{prog:o,vs:s,fs:c}=a,l=e=>n.getAttribLocation(o,e),u=l(`a_corner`),d=l(`a_ax`),f=l(`a_bx`),p=l(`a_ay`),m=l(`a_by`),h=l(`a_bstart`),g=l(`a_sid`),_=[d,f,p,m,h,g],v=e=>n.getUniformLocation(o,e),y={res:v(`u_resolution`),styles:v(`u_styles`),left:v(`u_left`),plotW:v(`u_plotW`),xoff:v(`u_xoff`),xscale:v(`u_xscale`),xR:v(`u_xR`),minGap:v(`u_minGap`),cutPx:v(`u_cutPx`)},b=n.createBuffer();n.bindBuffer(n.ARRAY_BUFFER,b),n.bufferData(n.ARRAY_BUFFER,Float32Array.from([-1,-1,1,-1,-1,1,1,1]),n.STATIC_DRAW);let x=n.createFramebuffer(),S=n.createRenderbuffer(),C=1,w=1,T=(`clientWidth`in e?e.clientWidth:0)||1,E=(`clientHeight`in e?e.clientHeight:0)||1,D=[],O=0,k=1,A=1/0,j=e=>{let t=n.createBuffer();return n.bindBuffer(n.ARRAY_BUFFER,t),n.bufferData(n.ARRAY_BUFFER,e,n.STATIC_DRAW),t},M=e=>{if(e)for(let t of[e.x,e.y,e.starts,e.sid])n.deleteBuffer(t)},N=e=>{e&&(M(e.full),M(e.res),n.deleteTexture(e.styles))},P=e=>({x:j(e.x),y:j(e.y),starts:j(e.starts),sid:j(e.sid),total:e.x.length}),F=e=>{let t=e.full;if(t&&t.version===e.version)return t;if(t&&e.valuesOnly&&t.whole&&e.counts.every(t=>t===e.xs.length)){let r=e.xs.length,i=e.columns.length===1?e.columns[0]:new Float32Array(r*e.columns.length);return e.columns.length>1&&e.columns.forEach((e,t)=>i.set(e,t*r)),n.bindBuffer(n.ARRAY_BUFFER,t.y),n.bufferSubData(n.ARRAY_BUFFER,0,i),t.version=e.version,t}M(t);let r=gX(e.xs,e.breaks,e.columns);return e.full={...P(r),version:e.version,whole:r.counts.every(t=>t===e.xs.length)},e.full},I=t=>{let n=Math.max(1,Math.round(t.plotW*(e.width/T)));if(t.resamplable&&k>O){let e=t.xs,r=0,i=e.length;for(;r<i;){let t=r+i>>>1;e[t]<O?r=t+1:i=t}let a=r;for(i=e.length;r<i;){let t=r+i>>>1;e[t]<=k?r=t+1:i=t}if(r-a>n*4){let r=`${t.version}|${O}|${k}|${n}`;if(t.res?.key!==r){M(t.res);let i=_X(e,t.columns,t.origin,O,k,n);t.res={...P(i),key:r,bucket:i.bucket}}return{d:t.res,minGap:t.res.bucket*2.5}}}return{d:F(t),minGap:0}},L=(e,r)=>{let i=e.counts.length,a=Math.max(1,Math.ceil(i/fX)),o=3*Math.min(Math.max(i,1),fX),s=new Float32Array(o*a*4);for(let n=0;n<i;n++){let i=r[n],a=(Math.floor(n/fX)*o+n%fX*3)*4;if(!i)continue;let c=i.width??t;s.set([Math.min(i.scaleMin,i.scaleMax),Math.max(i.scaleMin,i.scaleMax),i.bandTop,i.bandBottom],a),s.set(i.color,a+4),s.set([i.gapMedian,c/2,c/2+YY,+(e.counts[n]>=2)],a+8)}n.bindTexture(n.TEXTURE_2D,e.styles),n.texImage2D(n.TEXTURE_2D,0,n.RGBA32F,o,a,0,n.RGBA,n.FLOAT,s),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.NEAREST)};return{resize(t,r,i){T=Math.max(1,t),E=Math.max(1,r),e.width=Math.round(T*i),e.height=Math.round(E*i),C=e.width*2,w=e.height*2,x&&S&&(n.bindRenderbuffer(n.RENDERBUFFER,S),n.renderbufferStorage(n.RENDERBUFFER,n.RGBA8,C,w),n.bindFramebuffer(n.FRAMEBUFFER,x),n.framebufferRenderbuffer(n.FRAMEBUFFER,n.COLOR_ATTACHMENT0,n.RENDERBUFFER,S),n.bindFramebuffer(n.FRAMEBUFFER,null))},setData(e,t,r,i){let a=D[e],o=!t&&!!a&&i.length===a.columns.length;if(!t){if(!a)return;t=a.xs,r=a.breaks}let s=0;for(let e=0;e<t.length;e++)if(Number.isFinite(t[e])){s=t[e];break}let c=i.map(e=>{let t=0;for(let n=0;n<e.length;n++)e[n]===e[n]&&t++;return t});if(a&&(o||a.xs===t)){a.columns=i,a.counts=c,a.valuesOnly=o,a.version++,o||(M(a.full),a.full=null);return}let l={xs:t,breaks:r,columns:i,origin:s,counts:c,resamplable:!r?.some(e=>e)&&vX(t),version:0,valuesOnly:!1,full:null,res:null,styles:n.createTexture(),left:a?.left??0,plotW:a?.plotW??0};L(l,[]),D[e]=l,N(a)},setStyles(e,t,n,r){let i=D[e];i&&(L(i,t),i.left=n,i.plotW=r)},clearLayer(e){N(D[e]),D[e]=null},setView(e,t,n=1/0){O=e,k=t,A=n},render(){n.bindFramebuffer(n.FRAMEBUFFER,x),n.viewport(0,0,x?C:e.width,x?w:e.height),n.disable(n.SCISSOR_TEST),n.clearColor(0,0,0,0),n.clear(n.COLOR_BUFFER_BIT),n.useProgram(o),n.uniform2f(y.res,T,E),n.uniform1i(y.styles,0),n.activeTexture(n.TEXTURE0),n.enable(n.BLEND),n.blendFunc(n.ONE,n.ONE_MINUS_SRC_ALPHA),n.bindBuffer(n.ARRAY_BUFFER,b),n.enableVertexAttribArray(u),n.vertexAttribPointer(u,2,n.FLOAT,!1,0,0),n.vertexAttribDivisor(u,0);for(let e of _)n.enableVertexAttribArray(e),n.vertexAttribDivisor(e,1);let t=k-O||1;for(let e of D){if(!e)continue;n.uniform1f(y.left,e.left),n.uniform1f(y.plotW,e.plotW),n.uniform1f(y.xoff,O-e.origin),n.uniform1f(y.xscale,e.plotW/t),n.uniform1f(y.xR,t),n.uniform1f(y.cutPx,Number.isFinite(A)?e.left+(A-O)*(e.plotW/t):1e9);let{d:r,minGap:i}=I(e);r.total<2||(n.uniform1f(y.minGap,i),n.bindTexture(n.TEXTURE_2D,e.styles),n.bindBuffer(n.ARRAY_BUFFER,r.x),n.vertexAttribPointer(d,1,n.FLOAT,!1,4,0),n.vertexAttribPointer(f,1,n.FLOAT,!1,4,4),n.bindBuffer(n.ARRAY_BUFFER,r.y),n.vertexAttribPointer(p,1,n.FLOAT,!1,4,0),n.vertexAttribPointer(m,1,n.FLOAT,!1,4,4),n.bindBuffer(n.ARRAY_BUFFER,r.starts),n.vertexAttribPointer(h,1,n.UNSIGNED_BYTE,!0,1,1),n.bindBuffer(n.ARRAY_BUFFER,r.sid),n.vertexAttribPointer(g,1,n.FLOAT,!1,4,0),n.drawArraysInstanced(n.TRIANGLE_STRIP,0,4,r.total-1))}for(let e of _)n.vertexAttribDivisor(e,0);x&&(n.bindFramebuffer(n.READ_FRAMEBUFFER,x),n.bindFramebuffer(n.DRAW_FRAMEBUFFER,null),n.blitFramebuffer(0,0,C,w,0,0,e.width,e.height,n.COLOR_BUFFER_BIT,n.LINEAR),n.bindFramebuffer(n.FRAMEBUFFER,null))},dispose(){for(let e of D)N(e);D.length=0,n.deleteBuffer(b),n.deleteFramebuffer(x),n.deleteRenderbuffer(S),r&&(n.deleteProgram(o),n.deleteShader(s),n.deleteShader(c)),r&&n.getExtension(`WEBGL_lose_context`)?.loseContext()}}}``+new URL(`assets/offscreenLineWorker-C-_uNa_H.js`,__kymoscopeScriptUrl).href;var bX=[],xX=12,SX=!1,CX=!1,wX=0,TX=3,EX=1;function DX(){return!SX&&typeof Worker<`u`&&typeof HTMLCanvasElement<`u`&&typeof HTMLCanvasElement.prototype.transferControlToOffscreen==`function`}var OX=`kymoscope-gl-first-frame`;function kX(t,n=1,r,i,a){if(typeof t.transferControlToOffscreen!=`function`||typeof Worker>`u`)return null;let o,s=bX.pop();try{o=s??CE(``+new URL(`assets/offscreenLineWorker-C-_uNa_H.js`,__kymoscopeScriptUrl).href)}catch{return SX=!0,null}let c;try{c=t.transferControlToOffscreen()}catch{return s?bX.push(s):o.terminate(),null}let l=()=>{},u=EX++,d=!1;o.postMessage({type:`init`,canvas:c,lineWidth:n,gen:u},[c]),o.onmessage=e=>{e.data?.gen===u&&(e.data.type===`lost`?r?.():e.data.type===`first`&&(CX=!0,performance.mark?.(OX),l()))},o.onerror=()=>{d=!0,(!CX||++wX>=TX)&&(SX=!0),r?.()};let f=aX(i),p=-1,m=-1,h=-1,g={own:!0,resize(e,t,n){e===p&&t===m&&n===h||(p=e,m=t,h=n,o.postMessage({type:`resize`,w:e,h:t,dpr:n}))},setData(e,t){let n=[];t.xs&&n.push(t.xs.buffer),t.breaks&&n.push(t.breaks.buffer);for(let e of t.columns)n.push(e.buffer);o.postMessage({type:`data`,layer:e,...t},n)},setStyle(e,t){o.postMessage({type:`style`,layer:e,...t})},clear(e){o.postMessage({type:`clear`,layer:e})},setView(e,t,n){o.postMessage({type:`view`,xmin:e,xmax:t,cut:n})},dispose(){o.onmessage=null,o.onerror=null;let e=!d&&!SX&&bX.length<xX;try{o.postMessage({type:`dispose`})}catch{e=!1}e?bX.push(o):o.terminate(),f()}},_=a?AX(a,n):null;if(!_||!a)return g;let v=()=>{_&&(_.dispose(),_=null,a.getContext(`2d`)?.clearRect(0,0,a.width,a.height))};return l=()=>{(typeof requestAnimationFrame==`function`?requestAnimationFrame:setTimeout)(v)},{own:!0,resize(e,t,n){_?.resize(e,t,n),g.resize(e,t,n)},setData(e,t){_?.setData(e,{...t,xs:t.xs?t.xs.slice():null,breaks:t.breaks?.slice(),columns:t.columns.map(e=>e.slice())}),g.setData(e,t)},setStyle(e,t){_?.setStyle(e,t),g.setStyle(e,t)},clear(e){_?.clear(e),g.clear(e)},setView(e,t,n){_?.setView(e,t,n),g.setView(e,t,n)},dispose(){v(),g.dispose()}}}function AX(e,t=1){let n=dX(e,e=>yX(e,t));if(!n)return null;let r=0,i=1,a,o=``,s=(e,t)=>{n.setStyles(e,t.styles,t.left,t.plotW),r=t.xmin,i=t.xmax,a=t.cut,n.setView(r,i,a),n.render()};return{resize(e,t,r){let i=`${e}|${t}|${r}`;i!==o&&(o=i,n.resize(e,t,r),n.render())},setData(e,t){n.setData(e,t.xs,t.breaks,t.columns),s(e,t)},setStyle(e,t){s(e,t)},clear(e){n.clearLayer(e),n.render()},setView(e,t,o){e===r&&t===i&&o===a||(r=e,i=t,a=o,n.setView(e,t,o),n.render())},dispose(){n.dispose()}}}var jX=new Set;function MX(e){jX.add(e)}function NX(e){jX.delete(e)}function PX(){let e=typeof window>`u`?[]:[window];for(let t of jX)t.closed||e.push(t);return e}var FX=1,IX=new Map;function LX(e,t){let n=typeof window>`u`?void 0:window.performance?.timeOrigin,r=e.performance?.timeOrigin;return n!==void 0&&r!==void 0&&e!==window?t+(r-n):t}function RX(e){let t=FX++,n=PX();if(n.length===1){let r=n[0],i=r.requestAnimationFrame(n=>{IX.delete(t),e(LX(r,n))});return IX.set(t,[{w:n[0],id:i}]),t}let r=[];for(let i of n)r.push({w:i,id:i.requestAnimationFrame(n=>{IX.has(t)&&(zX(t),e(LX(i,n)))})});return IX.set(t,r),t}function zX(e){if(e==null)return;let t=IX.get(e);if(t){IX.delete(e);for(let{w:e,id:n}of t)e.closed||e.cancelAnimationFrame(n)}}var BX=new WeakMap;function VX(e){e&&BX.set(e,(BX.get(e)??0)+1)}function HX(e){let t=BX.get(e)??0;for(let n of e.querySelectorAll(`*`))t+=BX.get(n)??0;return t}function UX(){return PX().every(e=>e.document.hidden)}var WX=class{#e;#t=new Map;constructor(e){this.#e=e}observe(e,t){let n=e.ownerDocument.defaultView??window,r=this.#t.get(n);r||(r=new(n.ResizeObserver??ResizeObserver)(e=>this.#e(e,this)),this.#t.set(n,r)),r.observe(e,t)}unobserve(e){for(let t of this.#t.values())t.unobserve(e)}disconnect(){for(let e of this.#t.values())e.disconnect();this.#t.clear()}};function GX(e){return!!e&&e.isConnected&&typeof e.checkVisibility==`function`&&!e.checkVisibility()}function KX(e,t){let n=0,r=null,i=()=>GX(t()),a=t=>{n=0,!i()&&(r=t,e())};return{schedule(){n||=RX(a)},now(){if(i())return;let o=t()?.ownerDocument?.timeline?.currentTime;if(typeof o!=`number`||o===r){n||=RX(a);return}n&&=(zX(n),0),r=o,e()},cancel(){n&&zX(n),n=0}}}var qX=.6,JX=16,YX={ts:-1,work:0,floor:1/0},XX=1/0;function ZX(e,t=-1/0){if(e!==YX.ts){if(e>YX.ts&&e<YX.ts+YX.work/qX)return!1;YX={ts:e,work:0,floor:XX},XX=1/0}return YX.work>=JX||t>YX.floor?(XX=Math.min(XX,t),!1):!0}function QX(e,t){e===YX.ts&&(YX.work+=t)}function $X(e,t=typeof window>`u`?null:e=>{RX(e)}){let n=!1,r=null;return{set(i){if(r=i,!t){e(i);return}n||(n=!0,t(()=>{n=!1,e(r)}))}}}function eZ(e,t,n,r,i){return r+(e-t)/n*(i-r)}function tZ(e,t,n,r){let i=new Map,a=n.length;if(a===0)return i;let o=new Float64Array(a),s=new Float64Array(a).fill(1/0);for(let r of e){let e=r.x;for(let i=0;i<a;i++){let a=r.cols.get(n[i]);if(!a)continue;let c=s[i],l=o[i];for(let n=0;n<r.length;n++){let r=e[n],i=r<t?t-r:r-t;if(i>=c)continue;let o=a[n];Number.isFinite(o)&&(c=i,l=o)}s[i]=c,o[i]=l}}for(let e=0;e<a;e++)s[e]!==1/0&&(r&&s[e]>(r.get(n[e])??1/0)||i.set(n[e],o[e]));return i}function nZ(e,t,n,r=64){let i=new Map;if(t.length===0||!Number.isFinite(n))return i;let a=new Map;for(let o of e){if(o.length===0)continue;let e=0,s=o.length-1;for(;e<s;){let t=e+s>>1;o.x[t]<n?e=t+1:s=t}for(let s of t){let t=o.cols.get(s);if(t)for(let c=0;c<=r;c++){let r=e-c,l=e+c,u=r>=0&&Number.isFinite(t[r])?r:l<o.length&&Number.isFinite(t[l])?l:-1;if(u<0)continue;let d=Math.abs(o.x[u]-n);d<(a.get(s)??1/0)&&(a.set(s,d),i.set(s,t[u]));break}}}return i}function rZ(e,t){let n=new Map;if(t.length===0)return n;for(let r=e.length-1;r>=0&&n.size<t.length;r--){let i=e[r];for(let e of t){if(n.has(e))continue;let t=i.cols.get(e);if(t){for(let r=i.length-1;r>=0;r--)if(Number.isFinite(t[r])){n.set(e,t[r]);break}}}}return n}function iZ(e,t){return!(e>0)||!(t>0)?1:1-Math.exp(-e/t)}function aZ(e,t,n,r,i,a){let o=e;return n!==null&&Math.abs(t-n)<i*a&&(o+=t-n),o+(t-o)*r}function oZ(e,t,n,r=t){if(!(t>e)||n==null||!(n>0))return[e,t];let i=Number.isFinite(r)?Math.max(e,r):t;return i-n<e?[e,Math.min(t,e+n)]:[i-n,i]}function sZ(e,t){return e>0?Math.min(8e3,Math.max(400,Math.round(e*t*2))):2e3}var cZ=.5;function lZ(e,t,n,r=cZ){if(!(t>0))return e;let i=e!=null&&e>0?Math.min(e,t):t,a=n?i*.88:i/.88;return a>=t*.999?null:Math.max(r,a)}function uZ(e=0){return{d:null,lastT:NaN,wall:0,base:NaN,wait:e,waitAge:0,gap:NaN}}var dZ=new Map;function fZ(e,t,n,r){let i=dZ.get(e);if(i||dZ.set(e,i={p:uZ(),at:NaN,d:NaN}),n-i.at<2&&Number.isFinite(i.d))return i.d;let a=Number.isNaN(i.at)?16:n-i.at;return i.at=n,i.d=EZ(i.p,t,a,r),i.d}function pZ(){let e;for(let t of dZ.values())(!e||t.at>e.at)&&(e=t);return e&&Number.isFinite(e.d)?{newest:e.p.lastT,lag:e.p.lastT-e.d,wait:e.p.wait,waitAge:e.p.waitAge}:null}function mZ(e){return Math.min(SZ,e.wait*1.2+.05)}function hZ(e){return Number.isFinite(e.gap)?Math.min(e.gap,mZ(e)):0}function gZ(e){let t=dZ.get(e);return t?hZ(t.p):0}function _Z(e){let t=dZ.get(e);return t?mZ(t.p):0}function vZ(e,t,n){let r=e(t);if(!(n>0))return r;let i=(r-e(t-yZ))/yZ;return Number.isFinite(i)&&i>=0?r+i*n:r}var yZ=.25,bZ=1,xZ=250,SZ=3,CZ=90,wZ=30,TZ=.001;function EZ(e,t,n,r){if(!Number.isFinite(t))return t;let i=n/1e3;e.wall+=i;let a=n>xZ&&e.d!==null,o=e.lastT;if(t<e.lastT&&Object.assign(e,uZ(),{wall:e.wall}),t<=e.lastT)e.base+=i*TZ;else{let n=e.wall-t;e.base=Number.isNaN(e.base)?n:Math.min(e.base+i*TZ,n);let r=t-o;r>0&&r<bZ&&(e.gap=Number.isNaN(e.gap)?r:e.gap+(r-e.gap)*.1)}e.lastT=t;let s=e.wall-t-e.base;if(r){let n=t>o?r(o):NaN;s=t>o?e.wall-e.base-(Number.isFinite(n)?n:o):0}a||(e.waitAge+=i),a||(s>e.wait?(e.wait=Math.min(SZ,s),e.waitAge=0):s>e.wait*.8?e.waitAge=0:e.waitAge>CZ&&(e.wait*=Math.exp(-i/wZ)));let c=e.wall-e.base-mZ(e);if(e.d===null)e.d=e.wait>0?Math.min(t,c):t;else if(a||e.d<c-2)e.d=Math.min(t,c);else{let t=Math.min(n,64);e.d+=t/1e3,e.d+=(c-e.d)*Math.min(1,t/500)}return e.d>t&&(e.d=t),e.d}var DZ=(e,t)=>e.log?(Math.log10(Math.max(t,Number.MIN_VALUE))-Math.log10(e.v0))/(Math.log10(e.v1)-Math.log10(e.v0)||1):(t-e.v0)/(e.v1-e.v0||1),OZ=(e,t)=>e.log?10**(Math.log10(e.v0)+t*(Math.log10(e.v1)-Math.log10(e.v0))):e.v0+t*(e.v1-e.v0),kZ=(e,t)=>e.left+DZ(e.x,t)*e.width,AZ=(e,t)=>OZ(e.x,(t-e.left)/(e.width||1)),jZ=(e,t)=>e.top+(1-DZ(e.y,t))*e.height,MZ=e=>!e||Number.isFinite(e.v0)&&Number.isFinite(e.v1)&&e.v0!==e.v1&&(!e.log||e.v0>0&&e.v1>0),NZ=(e,t)=>e===t||!!e&&!!t&&e.v0===t.v0&&e.v1===t.v1&&!!e.log==!!t.log;function PZ(){let e=null,t=new Set;return{get:()=>e,set:n=>{if(n&&(n.width>0&&n.height>0?(!MZ(n.x)||!MZ(n.y))&&(n={...n,x:MZ(n.x)?n.x:void 0,y:MZ(n.y)?n.y:void 0}):n=null),!(n===e||n&&e&&n.left===e.left&&n.top===e.top&&n.width===e.width&&n.height===e.height&&NZ(n.x,e.x)&&NZ(n.y,e.y))){e=n;for(let e of[...t])e()}},subscribe:e=>(t.add(e),()=>{t.delete(e)})}}var FZ=(0,Z.createContext)(()=>{}),IZ=()=>(0,Z.useContext)(FZ),LZ=`M5 .8a3.1 3.1 0 0 0-3.1 3.1v2.3L.8 7.6h8.4L8.1 6.2V3.9A3.1 3.1 0 0 0 5 .8zM3.9 8.4a1.1 1.1 0 0 0 2.2 0z`,RZ=[5,4],zZ=null;function BZ(e,t,n,r){typeof Path2D>`u`||(zZ??=new Path2D(LZ),e.save(),e.setLineDash([]),e.translate(t,n),e.fillStyle=r,e.fill(zZ),e.restore())}QG(),jE();var VZ=(()=>{try{return localStorage.getItem(`glLines`)!==`0`}catch{return!0}})(),HZ=(()=>{try{return localStorage.getItem(`offscreenGl`)!==`0`}catch{return!0}})(),UZ=70;function WZ(e){return e===`dashed`?[5,4]:e===`dotted`?[1,4]:[]}var GZ={top:14,right:160,bottom:40,left:110},KZ={top:14,right:100,bottom:40,left:70},qZ=640,JZ={top:3,right:3,bottom:3,left:3},YZ=260;function XZ(e){return e<YZ?JZ:e<qZ?KZ:GZ}var ZZ=220,QZ=.05,$Z=2e3,eQ=4,tQ=1e3/120,nQ=`11.25px ${X.mono}`,rQ=11*1.125,iQ=24*1.125,aQ=iQ-rQ+26,oQ=.6,sQ=13,cQ=10,lQ=5,uQ=14,dQ=4;function fQ(e,t,n){return Math.min(n,Math.max(t,e))}function pQ(e,t,n,r,i){let a=Math.min(r,i),o=Math.max(r,i);return t+(1-fQ(o===a?.5:(e-a)/(o-a),0,1))*(n-t)}function mQ(e,t,n,r){let i=e+t;return{bandTop:i-r/100*t,bandBottom:i-n/100*t}}function hQ(e){return e.replace(/__(\d+|ref)$/,``)}function gQ(e,t,n){let r=Math.floor((n-t-rQ)/sQ)+1;return Math.max(0,Math.min(e,r))}function _Q(e){let t=0;for(let n of e)t+=n.length;return t}function vQ(e,t){let n=e.cols.get(t);return n?new Float32Array(n):new Float32Array(e.length).fill(NaN)}function yQ(e){let t=new Map;for(let n of e){let e=hQ(n.column),r=t.get(e)??[];r.push(n),t.set(e,r)}let n=new Set,r=[];for(let i of e){let e=hQ(i.column);if(n.has(e))continue;n.add(e);let a=t.get(e);r.push({base:e,leader:a[0],members:a})}return r}function bQ(e,t,n){let r=new Map,i=e.map((e,r)=>{let{bandTop:i}=mQ(t,n,e.leader.bandFromPct,e.leader.bandToPct);return{g:e,i:r,bandTop:i,blockDY:e.members.length>1?rQ+(e.members.length+1)*sQ:aQ}});i.sort((e,t)=>e.bandTop-t.bandTop||e.i-t.i);let a=-1/0;for(let{g:e,bandTop:t,blockDY:n}of i){let i=t+rQ,o=Math.max(i,a),s=o-rQ;r.set(e.leader.id,s),a=o+n}return r}function xQ(e,t){let n=e.cols.get(t);if(!n)return 0;let r=e.x;return n.length===e.length&&XG.has(n)?SQ(r,e.length):wQ(r,e.length,e=>Number.isFinite(n[e]))}function SQ(e,t){let n=CQ.get(e);return n===void 0&&(n=wQ(e,t,()=>!0),CQ.set(e,n)),n}var CQ=OE(new WeakMap);function wQ(e,t,n){let r=null,i=0,a=0;for(let o=0;o<t;o++)n(o)&&(r!==null&&e[o]!==r&&(i+=Math.abs(e[o]-r),a++),r=e[o]);return a===0?0:i/a}function TQ(e,t){return e>0?Math.max(e*4,t*1e-9):Math.max(t*1e-6,1e-12)}var EQ=1e30,DQ=250;function OQ({xLabel:e,series:t,points:n,columnUnits:r={},height:i=440,onPlotContextMenu:a,backgroundToken:o=``,viewXRange:s=null,onViewXRangeChange:c,liveZoom:l,liveZoomId:u,fullXRange:d=null,shiftMode:f,xAxisLine:p,yAxisLine:m,gridLine:h,lineWidth:g=1,envelopes:_,showLatestValues:v=!1,liveSource:y,liveWindowSeconds:b=null,onLiveWindowChange:x,liveZoomMode:S,onPlotWidthCss:C,onCursorX:w}){let T=IZ(),E=(0,Z.useRef)(null),D=(0,Z.useRef)(null),O=(0,Z.useRef)(null),k=(0,Z.useRef)(null),A=(0,Z.useRef)(null),j=(0,Z.useRef)(C);j.current=C;let M=(0,Z.useRef)(-1),N=(0,Z.useRef)(null),P=(0,Z.useRef)(!1),F=(0,Z.useRef)(null),I=(0,Z.useRef)(!1),L=(0,Z.useRef)(!1),R=(0,Z.useRef)(null),z=(0,Z.useRef)(null),B=(0,Z.useRef)({pts:null,layers:[]}),V=(0,Z.useRef)(new Map),ee=(0,Z.useRef)([]),H=(0,Z.useRef)(null),U=(0,Z.useRef)(null),te=(0,Z.useRef)(null),W=(0,Z.useRef)(null),ne=(0,Z.useRef)(null),G=(0,Z.useRef)(0),re=(0,Z.useRef)(0),ie=(0,Z.useRef)(!1),ae=(0,Z.useRef)(0),oe=(0,Z.useRef)($Z),se=(0,Z.useRef)(y),ce=(0,Z.useRef)(null),le=(0,Z.useRef)(uZ()),ue=(0,Z.useRef)(0),de=(0,Z.useRef)(void 0),fe=(0,Z.useRef)(0),pe=(0,Z.useRef)(0),me=(0,Z.useRef)(16),he=(0,Z.useRef)(!0),ge=(0,Z.useRef)(!1),[_e,ve]=(0,Z.useState)(0),ye=()=>GX(A.current);function be(){F.current?.dispose(),F.current=null,L.current=!1,I.current=!1,ee.current=[],ve(e=>e+1)}(0,Z.useEffect)(()=>{_e&&xt()},[_e]),(0,Z.useLayoutEffect)(()=>{se.current=y,ce.current=null,B.current={pts:null,layers:[]},V.current.clear()},[y]);let xe=(0,Z.useRef)(b);(0,Z.useLayoutEffect)(()=>{xe.current=b},[b]);let Se=(0,Z.useRef)(x);Se.current=x;let Ce=S??(x?`follow`:`free`),we=(0,Z.useRef)(Ce);we.current=Ce;let Te=(0,Z.useRef)(null);(0,Z.useLayoutEffect)(()=>{Te.current=null},[Ce,e]);let Ee=(0,Z.useRef)([]),De=(0,Z.useRef)(!1),Oe=(0,Z.useRef)(0),ke=(0,Z.useRef)(0),Ae=(0,Z.useRef)(0),je=(0,Z.useRef)(0),Me=(0,Z.useRef)(`none`),Ne=(0,Z.useRef)(0),Pe=(0,Z.useRef)(0),Fe=(0,Z.useRef)(0),Ie=(0,Z.useRef)(null),Le=(0,Z.useRef)(null),Re=(0,Z.useRef)(0);function ze(e){let t=XZ(e);return Re.current>0?{...t,left:t.left+Re.current}:t}let Be=(0,Z.useRef)(f),Ve=(0,Z.useRef)(null),He=(0,Z.useRef)({pts:null,x0:NaN,x1:NaN,ser:null}),Ue=(0,Z.useRef)(0),We=(0,Z.useRef)(0),Ge=(0,Z.useRef)(null),Ke=(0,Z.useRef)(null),qe=(0,Z.useRef)(null),Je=(0,Z.useRef)(null);(0,Z.useLayoutEffect)(()=>{Be.current=f},[f]),(0,Z.useEffect)(()=>(R.current&&=(clearTimeout(R.current),null),()=>{N.current?.dispose(),N.current=null;let e=F.current;e&&(R.current=setTimeout(()=>{e.dispose(),F.current===e&&(F.current=null),R.current=null},0))}),[]);let Ye=(0,Z.useSyncExternalStore)(kJ,OJ),Xe=(0,Z.useRef)({xLabel:e,series:t,points:n,height:i,columnUnits:r,shiftMode:f,xAxisLine:p,yAxisLine:m,gridLine:h,lineWidth:g,showLatestValues:v,envelopes:_}),Ze=(0,Z.useRef)(null),Qe=(0,Z.useRef)(null);(0,Z.useLayoutEffect)(()=>{Xe.current={xLabel:e,series:t,points:n,height:i,columnUnits:r,shiftMode:f,xAxisLine:p,yAxisLine:m,gridLine:h,lineWidth:g,showLatestValues:v,envelopes:_}},[e,t,n,i,r,f,p,m,h,g,v,_]);let $e=(0,Z.useRef)(c),et=(0,Z.useRef)(w);et.current=w,(0,Z.useLayoutEffect)(()=>{$e.current=c},[c]);let tt=(0,Z.useRef)(l),nt=(0,Z.useRef)(u);(0,Z.useLayoutEffect)(()=>{tt.current=l,nt.current=u},[l,u]),(0,Z.useEffect)(()=>{if(!(!l||!u))return l.subscribe((e,t)=>{e!==u&&(H.current=t?.[0]??null,U.current=t?.[1]??null,xt())})},[l,u]);let rt=(0,Z.useRef)(a);(0,Z.useLayoutEffect)(()=>{rt.current=a},[a]);let it=(0,Z.useMemo)(()=>{if(d&&d[1]>d[0])return{xmin:d[0],xmax:d[1]};let e=1/0,t=-1/0;for(let r of n)for(let n=0;n<r.length;n++){let i=r.x[n];i<e&&(e=i),i>t&&(t=i)}return(!Number.isFinite(e)||e===t)&&(--e,t+=1),{xmin:e,xmax:t}},[n,d]),at=(0,Z.useRef)(it);(0,Z.useLayoutEffect)(()=>{at.current=it},[it]);function ot(){return se.current!=null&&H.current===null&&U.current===null&&!De.current&&Ve.current===null}function st(){let{xmin:e,xmax:t}=at.current,n=H.current,r=U.current;if(n!==null&&r!==null&&r>n&&Number.isFinite(n)&&Number.isFinite(r))return{xmin:n,xmax:r};let i=te.current,a=W.current;return ot()&&i!==null&&a!==null&&a>i&&Number.isFinite(i)&&Number.isFinite(a)?{xmin:i,xmax:a}:{xmin:e,xmax:t}}function ct(e,t){let n=se.current;if(!n?.latestValues)return rZ(e,t);let r=n.latestValues(t),i=t.filter(e=>!r.has(e)),a=n.latestX?.();if(i.length>0&&a!=null)for(let[t,n]of nZ(e,i,a))r.set(t,n);return r}function lt(){return se.current?Ee.current:Xe.current.points}function ut(e,t,n){let r=new Map;for(let i of t)r.set(i,TQ(ht(e,i),n));return r}function dt(e){if(B.current.pts===e)return B.current.layers;let t=B.current.layers,n=se.current?.version?.(),r=e.map((e,r)=>({pts:e,key:t[r]?.pts===e?t[r].key:n??e}));return B.current={pts:e,layers:r},r}function ft(e,t){let n=V.current.get(e),r=performance.now(),i=n&&(n.key===t.key||typeof t.key==`number`&&typeof n.key==`number`&&r-n.at<DQ);return(!n||!i)&&(n={key:t.key,at:r,has:new Map,median:new Map},V.current.set(e,n)),n}function pt(e,t,n){let r=ft(e,t),i=r.has.get(n);if(i===void 0){let e=t.pts.cols.get(n);i=!!e&&e.some(Number.isFinite),r.has.set(n,i)}return i}function mt(e,t){return dt(e).some((e,n)=>pt(n,e,t))}function ht(e,t){let n=dt(e);for(let e=0;e<n.length;e++){if(!pt(e,n[e],t))continue;let r=ft(e,n[e]),i=r.median.get(t);return i===void 0&&(i=xQ(n[e].pts,t),r.median.set(t,i)),i}return 0}function gt(){if(Je.current)return Je.current;let e=A.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return Je.current=n,n}function _t(){let e=A.current,t=Math.max(1,e?.clientWidth||200),n=e?.clientHeight??0;return{w:t,h:Math.max(1,n>0?n:Xe.current.height)}}function vt(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function yt(){let e=E.current;if(!e)return;let{w:t,h:n}=_t(),r=vt(e,t,n);if(!r)return;{let e=lt(),t=st(),n=Xe.current.series,r=He.current;(r.pts!==e||r.x0!==t.xmin||r.x1!==t.xmax||r.ser!==n)&&(He.current={pts:e,x0:t.xmin,x1:t.xmax,ser:n},VX(A.current))}let i=XZ(t),a=i===JZ,{top:o,right:s,bottom:c}=i,l=i.left,u=t-l-s,d=n-o-c,{bg:f,muted:p,grid:m}=gt(),{xLabel:h,series:g,xAxisLine:_,yAxisLine:v,gridLine:y,lineWidth:b,columnUnits:x,showLatestValues:S}=Xe.current,C=lt();if(r.fillStyle=f,r.fillRect(0,0,t,n),_Q(C)<2||u<=0||d<=0){if(r.fillStyle=p,r.font=`13px ${X.sans}`,MY(r),N.current&&(N.current.resize(t,n,window.devicePixelRatio||1),N.current.draw([])),F.current){F.current.resize(t,n,window.devicePixelRatio||1);for(let e=0;e<ee.current.length;e++)F.current.clear(e);ee.current=[]}return}let{xmin:w,xmax:k}=st(),j=k-w,M=e=>l+(e-w)/j*u,z=g.filter(e=>e.bandToPct>e.bandFromPct&&e.scaleMin!==e.scaleMax&&mt(C,e.column)),B=yQ(z),V=bQ(B,o,d),H=new Map;for(let e of B){let t=V.get(e.leader.id);t!==void 0&&e.members.forEach(e=>H.set(e.id,t))}let U=new Set,te=new Set;for(let e of B)e.members.length>1&&e.members.forEach(e=>U.add(e.id)),te.add(e.leader.id);let W=`11px ${X.mono}`,ne=z.map(e=>{let{bandTop:t,bandBottom:n}=mQ(o,d,e.bandFromPct,e.bandToPct),r=Math.min(e.scaleMin,e.scaleMax),i=Math.max(e.scaleMin,e.scaleMax),{majorStep:a,minorStep:s}=fJ(e.scaleMin,e.scaleMax,e.yMajorStep??0,e.yMinorStep??0),c=a,l=pJ(r,i,c);l.length>120&&(l=pJ(r,i,c=fJ(e.scaleMin,e.scaleMax,0,0).majorStep));let u=mJ(r,i,s,l);return u.length>400&&(u=[]),{s:e,bandTop:t,bandBottom:n,majors:l,minors:u,step:c}}),G=new Map,re=0;{r.save(),r.font=W;let e=ne.filter(e=>te.has(e.s.id));e.sort((e,t)=>{let n=Math.abs(e.s.bandToPct-e.s.bandFromPct),r=Math.abs(t.s.bandToPct-t.s.bandFromPct);return n===r?ne.indexOf(e)-ne.indexOf(t):r-n});let n=new Map,a=[];for(let t of e){let r=0;for(;r<e.length;r++){let e=a[r];if(!e||e.length===0||!e.some(e=>t.bandTop<e.bandBottom&&t.bandBottom>e.bandTop))break}n.set(t.s.id,r),a[r]||(a[r]=[]),a[r].push(t)}let o=new Map,c=new Map;for(let t of e){let e=0;for(let n of t.majors){let i=_J(n,t.step),a=c.get(i);a===void 0&&c.set(i,a=r.measureText(i).width),a>e&&(e=a)}o.set(t.s.id,e)}let u=[],d=[],f=0;for(let e=0;e<a.length;e++){u[e]=f;let t=0;for(let n of a[e]??[]){let e=o.get(n.s.id)??0;e>t&&(t=e)}d[e]=t,f+=t+22}for(let e of ne){let t=n.get(e.s.id)??0;G.set(e.s.id,u[t]??0)}let p=i.left;for(let e=0;e<a.length;e++){let t=a[e];if(!t||t.length===0)continue;let n=(u[e]??0)+dQ+uQ+(d[e]??0)+6;n>p&&(p=n)}let m=Math.max(i.left,t-s-Math.max(120,t*.4)),h=Math.min(Math.ceil(p),m);h>l&&(re=h-l),r.restore()}re>0&&(l+=re,u=Math.max(1,t-l-s)),Re.current=re,T({left:l,top:o,width:u,height:d,x:{v0:w,v1:k}}),oe.current=sZ(u,window.devicePixelRatio||1);let ie=(e,t)=>1-(1-e)**t,ae=new Map,se=new Map;for(let e of ne){let t=`${e.bandTop}|${e.bandBottom}|${e.s.scaleMin}|${e.s.scaleMax}|${e.majors.join(`,`)}`,n=ae.get(t);n?n.k++:ae.set(t,{c:e,k:1});let r=U.has(e.s.id)?p:e.s.color,i=`${e.bandTop}|${e.bandBottom}|${r}`,a=se.get(i);a?a.k++:se.set(i,{c:e,color:r,k:1})}if((v?.style??`dashed`)!==`none`)for(let{c:{s:e,bandTop:t,bandBottom:n,majors:i},k:a}of ae.values()){r.save(),r.strokeStyle=v?.color??m,r.globalAlpha=ie(.1,a),r.lineWidth=v?.width??1,r.lineCap=`round`,r.setLineDash(WZ(v?.style??`dashed`));for(let a of i){let i=pQ(a,t,n,e.scaleMin,e.scaleMax);r.beginPath(),r.moveTo(l,i),r.lineTo(l+u,i),r.stroke()}r.restore()}for(let{c:{bandTop:e,bandBottom:t},color:n,k:i}of se.values())r.strokeStyle=n,r.lineWidth=1,r.setLineDash([]),r.globalAlpha=ie(.45,i),r.beginPath(),r.moveTo(l,e),r.lineTo(l,t),r.stroke(),r.globalAlpha=1;for(let{s:e,bandTop:t,bandBottom:n,majors:i,minors:o,step:s}of a?[]:ne){let a=U.has(e.id)?p:e.color;if(te.has(e.id)){let c=G.get(e.id)??0,u=l-c-dQ;r.strokeStyle=a,r.lineWidth=1;for(let i of o){let a=pQ(i,t,n,e.scaleMin,e.scaleMax);r.beginPath(),r.moveTo(u-lQ,a),r.lineTo(u,a),r.stroke()}r.font=W,r.textAlign=`right`,r.textBaseline=`middle`,r.strokeStyle=a,r.fillStyle=a;for(let a of i){let i=pQ(a,t,n,e.scaleMin,e.scaleMax);r.beginPath(),r.moveTo(u-cQ,i),r.lineTo(u,i),r.stroke(),r.fillText(_J(a,s),u-uQ,i)}}}if((y?.style??`solid`)!==`none`&&(r.strokeStyle=y?.color??m,r.lineWidth=y?.width??1,r.setLineDash(WZ(y?.style??`solid`)),r.strokeRect(l,o,u,d),r.setLineDash([])),(_?.style??`dashed`)!==`none`){r.strokeStyle=_?.color??m,r.lineWidth=_?.width??1,r.setLineDash(WZ(_?.style??`dashed`));for(let e=1;e<6;e++){let t=l+e/6*u;r.beginPath(),r.moveTo(t,o),r.lineTo(t,o+d),r.stroke()}r.setLineDash([])}let ce=o+d+10;r.fillStyle=p,r.font=`11px ${X.mono}`,r.textAlign=`center`,r.textBaseline=`top`;let le=xJ(h,w,w+j);for(let e=0;e<=(a?-1:6);e++){let t=w+e/6*j;r.fillText(le?AJ(t,j/6,j):_J(t,j/6),l+e/6*u,ce)}r.textBaseline=`bottom`,a||r.fillText(h,l+u/2,n-5);let{shiftMode:ue}=Xe.current;ue&&(r.globalAlpha=.8,r.font=`10px ${X.sans}`,r.fillStyle=p,r.textAlign=`center`,r.textBaseline=`top`,r.fillText(`⇄ shifting: ${ue.label}`,l+u/2,o+3),r.globalAlpha=1);let fe=Xe.current.envelopes;if(fe?.length){r.save(),r.beginPath(),r.rect(l,o,u,d),r.clip();for(let e of fe){let t=z.find(t=>t.id===e.seriesId||t.id.startsWith(`${e.seriesId}__`));if(!t)continue;let{bandTop:n,bandBottom:i}=mQ(o,d,t.bandFromPct,t.bandToPct),a=e=>pQ(e,n,i,t.scaleMin,t.scaleMax);r.fillStyle=e.color,r.globalAlpha=.2;let s=0;for(;s<e.x.length;){for(;s<e.x.length&&e.lo[s]!==e.lo[s];)s++;let t=s;for(;s<e.x.length&&e.lo[s]===e.lo[s];)s++;if(!(s-t<2)){r.beginPath(),r.moveTo(M(e.x[t]),a(e.hi[t]));for(let n=t+1;n<s;n++)r.lineTo(M(e.x[n]),a(e.hi[n]));for(let n=s-1;n>=t;n--)r.lineTo(M(e.x[n]),a(e.lo[n]));r.closePath(),r.fill()}}}r.restore()}R.current&&=(clearTimeout(R.current),null);let pe=HZ&&!I.current?F.current:null;if(HZ&&!pe&&!I.current&&D.current&&!L.current&&(pe=DX()&&iX()?kX(D.current,1,be,{hidden:ye,evict:be},O.current??void 0):AX(D.current),pe?(F.current=pe,L.current=!0):I.current=!0),pe){pe.resize(t,n,window.devicePixelRatio||1);let e=`${l.toFixed(2)}|${u.toFixed(2)}|${o}|${d}|${b}|`+z.map(e=>`${e.id}:${e.column}:${e.bandFromPct}:${e.bandToPct}:${e.scaleMin}:${e.scaleMax}:${e.color}`).join(`,`),r=dt(C),i=ee.current;for(let t=0;t<Math.max(r.length,i.length);t++){let n=r[t];if(!n){i[t]&&pe.clear(t),i[t]=null;continue}let a=z.filter(e=>pt(t,n,e.column)),s=a.map(e=>e.column).join(`
|
|
227
|
-
`),c=i[t];if(c&&c.pts===n.pts&&c.sig===e&&c.cols===s)continue;i[t]={pts:n.pts,sig:e,cols:s};let f={styles:a.map(e=>{let{bandTop:t,bandBottom:r}=mQ(o,d,e.bandFromPct,e.bandToPct);return{color:qY(e.color),bandTop:t,bandBottom:r,scaleMin:e.scaleMin,scaleMax:e.scaleMax,gapMedian:n.pts.hold?EQ:ht(C,e.column),width:b}}),left:l,plotW:u,xmin:w,xmax:k,cut:de.current};if(c&&c.pts===n.pts&&c.cols===s){pe.setStyle(t,f);continue}let p=n.pts,m=!!c&&c.pts.x===p.x&&c.pts.brk===p.brk&&c.cols===s;pe.setData(t,{...f,xs:m?null:p.x.slice(),breaks:m?void 0:p.brk?.slice(),columns:a.map(e=>vQ(p,e.column))})}i.length=r.length,pe.setView(w,k,de.current)}else{let e=N.current;VZ&&!e&&!P.current&&D.current&&!L.current&&(e=$Y(D.current),e?N.current=e:P.current=!0);let i=!!e;i&&e&&e.resize(t,n,window.devicePixelRatio||1);let a=[],s=ut(C,z.map(e=>e.column),j);for(let e of z){let{bandTop:t,bandBottom:n}=mQ(o,d,e.bandFromPct,e.bandToPct),c=s.get(e.column);if(i){let r={x:l,y:t,w:u,h:n-t},i=qY(e.color),o=[],s=null,d=()=>{o.length>=4&&a.push({points:Float32Array.from(o),color:i,clip:r,width:b}),o=[]};for(let r of C){let i=r.cols.get(e.column);if(i){s=null;for(let a=0;a<r.length;a++){r.brk?.[a]&&d();let l=i[a];if(!Number.isFinite(l))continue;let u=r.x[a];s!==null&&!r.hold&&Math.abs(u-s)>c&&d(),o.push(M(u),pQ(l,t,n,e.scaleMin,e.scaleMax)),s=u}d()}}d();continue}r.strokeStyle=e.color,r.lineWidth=b,r.lineJoin=`round`,r.lineCap=`round`,r.save(),r.beginPath(),r.rect(l,t,u,n-t),r.clip(),r.beginPath();let f=!1,p=null,m=!1;for(let i of C){let a=i.cols.get(e.column);if(a){m=!0;for(let o=0;o<i.length;o++){i.brk?.[o]&&(m=!0);let s=a[o];if(!Number.isFinite(s))continue;let l=i.x[o],u=M(l),d=pQ(s,t,n,e.scaleMin,e.scaleMax);f?m||p!==null&&!i.hold&&Math.abs(l-p)>c?(r.stroke(),r.beginPath(),r.moveTo(u,d),p=l,m=!1):(r.lineTo(u,d),p=l):(r.moveTo(u,d),f=!0,p=l,m=!1)}}}f&&r.stroke(),r.restore()}i&&e&&e.draw(a)}for(let e of z){if(!e.alarm)continue;let{bandTop:t,bandBottom:n}=mQ(o,d,e.bandFromPct,e.bandToPct),i=pQ(e.alarm.value,t,n,e.scaleMin,e.scaleMax);r.save(),r.beginPath(),r.rect(l,t,u,n-t),r.clip(),r.strokeStyle=e.alarm.color,r.lineWidth=e.alarm.width,r.setLineDash(e.alarm.linked===`active`?RZ:WZ(e.alarm.style)),r.beginPath(),r.moveTo(l,i),r.lineTo(l+u,i),r.stroke(),r.setLineDash([]),e.alarm.linked&&BZ(r,l+u-10-3,i-10-2,e.alarm.color),r.restore()}if(a)return;let me=S?ct(C,z.map(e=>e.column)):null,he=e=>{let t=me?.get(e.column);if(typeof t!=`number`)return`-`;let n=x[e.column]?.trim()??``;return`${vJ(t)}${n?` ${n}`:``}`},ge=l+u+8;r.font=nQ,r.textAlign=`left`;for(let e of B){let t=V.get(e.leader.id);if(t===void 0)continue;let i=e.members.length>1;if(r.fillStyle=i?p:e.leader.color,r.globalAlpha=1,r.fillText(e.base,ge,t+rQ),i){let i=gQ(e.members.length,t,n);for(let n=0;n<i;n++)r.fillStyle=e.members[n].color,r.globalAlpha=oQ,r.fillText(he(e.members[n]),ge,t+rQ+(n+1)*sQ)}else r.fillStyle=e.leader.color,r.globalAlpha=oQ,r.fillText(he(e.leader),ge,t+iQ);r.globalAlpha=1}}function bt(){let e=k.current;if(!e)return;let{w:t,h:n}=_t(),r=vt(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let{top:i,right:a,bottom:o,left:s}=ze(t),c=t-s-a,l=n-i-o,{series:u,columnUnits:d,xLabel:f}=Xe.current,p=lt();if(De.current&&c>0&&l>0){let e=Oe.current,t=ke.current,n=Ae.current,i=je.current,a=Math.min(e,n),o=Math.min(t,i),s=Math.abs(n-e),c=Math.abs(i-t);r.fillStyle=`rgba(59, 130, 246, 0.12)`,r.fillRect(a,o,s,c),r.strokeStyle=`rgba(59, 130, 246, 0.85)`,r.setLineDash([4,3]),r.lineWidth=1,r.strokeRect(a,o,s,c),r.setLineDash([])}let m=z.current;if(m===null||_Q(p)<2||c<=0||l<=0)return;let{xmin:h,xmax:g}=st(),_=u.filter(e=>e.bandToPct>e.bandFromPct&&e.scaleMin!==e.scaleMax&&mt(p,e.column)),v=[...new Set(_.map(e=>e.column))],y=ut(p,v,g-h),{bg:b,muted:x}=gt();r.strokeStyle=x,r.globalAlpha=.5,r.lineWidth=1,r.beginPath(),r.moveTo(m,i),r.lineTo(m,i+l),r.stroke(),r.globalAlpha=1;let S=yQ(_),C=bQ(S,i,l),w=s+c+8;r.font=nQ,r.textAlign=`left`;let T=eZ(m,s,c,h,g),E=tZ(p,T,v,y),D=e=>{let t=E.get(e.column);if(typeof t!=`number`)return`-`;let n=d[e.column]?.trim()??``;return`${vJ(t)}${n?` ${n}`:``}`};for(let e of S){let t=C.get(e.leader.id)??mQ(i,l,e.leader.bandFromPct,e.leader.bandToPct).bandTop;if(e.members.length>1){let i=e.members.length*sQ+4;r.fillStyle=b,r.fillRect(s+c+6,t+rQ+2,a-8,i);let o=gQ(e.members.length,t,n);for(let n=0;n<o;n++){let i=e.members[n];r.fillStyle=i.color,r.globalAlpha=oQ,r.fillText(D(i),w,t+rQ+(n+1)*sQ)}}else{let n=e.leader;r.fillStyle=b,r.fillRect(s+c+6,t+rQ+2,a-8,iQ-rQ+6),r.fillStyle=n.color,r.globalAlpha=oQ,r.fillText(D(n),w,t+iQ)}r.globalAlpha=1}let O=/^(.*?)\s*\(([^)]*)\)\s*$/.exec(f),A=O?O[1]:f,j=O?O[2].trim():``,M=xJ(f,h,g)?jJ(T):``,N=M.lastIndexOf(` `),P=M?[`${A} ${M.slice(0,N)}`,M.slice(N+1)]:[`${A} ${Math.round(T)}${j}`];r.font=nQ,r.textAlign=`left`,r.textBaseline=`alphabetic`,P.forEach((e,t)=>{let n=r.measureText(e).width,a=i+l-(P.length-1-t)*15;r.fillStyle=b,r.fillRect(w-2,a-11,n+6,15),r.fillStyle=x,r.globalAlpha=1,r.fillText(e,w,a)})}function xt(){if(se.current){ie.current=!0;return}Ge.current=()=>{yt(),bt()},!Ue.current&&(Ue.current=RX(e=>{Ue.current=0,!ye()&&(Ke.current=e,Ge.current?.())}))}function St(){if(se.current){ie.current=!0;return}let e=A.current?.ownerDocument.timeline?.currentTime;if(typeof e!=`number`||e===Ke.current){xt();return}Ke.current=e,zX(Ue.current),Ue.current=0,yt(),bt()}function Ct(){qe.current=bt,!We.current&&(We.current=RX(()=>{We.current=0,qe.current?.()}))}function wt(e){G.current=RX(wt);let t=se.current;if(!t)return;me.current+=(Math.min(50,pe.current?e-pe.current:16)-me.current)*.1,pe.current=e;let n=A.current;if(!(he.current&&!GX(n))){if(!ge.current){ge.current=!0;let e=F.current;e&&(ee.current.forEach((t,n)=>{t&&e.clear(n)}),ee.current=[],e.resize(1,1,1))}return}if(ge.current&&(ge.current=!1,F.current&&!F.current.own&&DX()&&iX())){be();return}if(fe.current&&e-fe.current<tQ-me.current/2||!ZX(e,fe.current||-1/0))return;fe.current=e;let r=performance.now(),i=t.xBounds();i&&i[1]>i[0]&&(at.current={xmin:i[0],xmax:i[1]});let a=ue.current?e-ue.current:16;ue.current=e,a>250&&(te.current=null,W.current=null);let o=t.latestT?.(),s,c;if(o!==void 0&&t.xAtTime&&Number.isFinite(o)){let e=t.id?fZ(t.id,o,performance.now(),t.timeAfter):EZ(le.current,o,a,t.timeAfter),n=t.id?_Z(t.id):mZ(le.current),r=vZ(t.xAtTime,e,n);Number.isFinite(r)&&(s=r);let i=vZ(t.xAtTime,e,n-(t.id?gZ(t.id):hZ(le.current)));Number.isFinite(i)&&(c=i)}if(ot()){let n=s??t.latestX?.()??at.current.xmax,r=xe.current,i=r!=null&&t.spanForSeconds?t.spanForSeconds(r):r??Te.current,[a,o]=oZ(at.current.xmin,at.current.xmax,i,n??void 0);if(!t.spanForSeconds&&s!==void 0&&s>a&&(o=s),Number.isFinite(a)&&Number.isFinite(o)&&o>a){let t=o-a,n=W.current!==null&&o<W.current-t;if(te.current===null||W.current===null||n)te.current=a,W.current=o,re.current=e;else{let n=re.current;re.current=e;let r=ne.current,i=iZ(n?Math.min(64,e-n):16,ZZ);te.current=aZ(te.current,a,r?r[0]:null,i,t,QZ),W.current=aZ(W.current,o,r?r[1]:null,i,t,QZ),Math.abs(a-te.current)<t*1e-6&&(te.current=a),Math.abs(o-W.current)<t*1e-6&&(W.current=o)}ne.current=[a,o]}}else te.current=null,W.current=null,re.current=0;let l=st(),u=t.version?.(),d=oe.current,f=ce.current,p=f!==null&&u!==void 0&&f.ver===u&&f.x0===l.xmin&&f.x1===l.xmax&&f.mp===d&&f.cut===c;(_Q(Ee.current)===0||!p&&e-ae.current>=eQ)&&(ae.current=e,de.current=t.cutOnGpu&&F.current?c:void 0,Ee.current=t.pull(l.xmin,l.xmax,d,c,de.current!==void 0),ce.current=u===void 0?null:{ver:u,x0:l.xmin,x1:l.xmax,mp:d,cut:c}),ie.current=!1,yt(),bt(),QX(e,performance.now()-r)}function Tt(){G.current||=(re.current=0,RX(wt))}function Et(){G.current&&(zX(G.current),G.current=0,ue.current=0,te.current=null,W.current=null,Ee.current=[],de.current=void 0)}(0,Z.useEffect)(()=>{let e=A.current,t=e?.ownerDocument.defaultView?.IntersectionObserver;if(!e||!t)return;let n=new t(e=>{let t=e[e.length-1];(t.isIntersecting||t.boundingClientRect.width>0)&&(he.current=t.isIntersecting)});return n.observe(e),()=>{n.disconnect(),he.current=!0}},[]),(0,Z.useEffect)(()=>(y?Tt():(Et(),xt()),Et),[!!y]),(0,Z.useEffect)(()=>zJ(A.current,()=>{Je.current=null,xt()}),[]),(0,Z.useEffect)(()=>{Je.current=null,xt()},[o]);let Dt=!!f;(0,Z.useEffect)(()=>{let e=k.current;e&&(e.style.cursor=Dt?`ew-resize`:``),xt()},[Dt,f?.label??``]);let Ot=s?.[0]??null,kt=s?.[1]??null;return(0,Z.useLayoutEffect)(()=>{H.current===Ot&&U.current===kt||(H.current=Ot,U.current=kt,xt())},[Ot,kt]),(0,Z.useEffect)(()=>{St()},[t,n,i,e,p,m,h,g,v,Ye]),(0,Z.useEffect)(()=>()=>{zX(Ue.current),zX(We.current),Ue.current=0,We.current=0},[]),(0,Z.useEffect)(()=>{let e=k.current,t=A.current;if(!e||!t)return;let n=()=>{let e=Math.round(t.clientWidth);e>0&&e!==M.current&&(M.current=e,j.current?.(e))};n();let r=new WX(()=>{Je.current=null,n(),xt()});r.observe(t);let i=$X(e=>et.current?.(e)),a=t=>{if(De.current||Ve.current!==null)return;if(_Q(lt())<2){z.current!==null&&(z.current=null,Ct(),i.set(null));return}let n=e.getBoundingClientRect(),r=t.clientX-n.left,a=t.clientY-n.top,{left:o,top:s,right:c,bottom:l}=ze(n.width),u=Math.max(1,n.width-o-c),d=n.height-s-l;if(r<o||r>o+u||a<s||a>s+d){z.current!==null&&(z.current=null,Ct(),i.set(null));return}z.current!==r&&(z.current=r,Ct());let{xmin:f,xmax:p}=st();i.set(eZ(r,o,u,f,p))},o=()=>{z.current!==null&&(z.current=null,Ct()),i.set(null)},s=e=>{Ze.current&&clearTimeout(Ze.current),Ze.current=setTimeout(()=>{Ze.current=null,$e.current?.(e)},UZ)},c=t=>{if(Me.current!==`none`||t.buttons&2||Date.now()-Fe.current<300||_Q(lt())<2)return;let n=e.getBoundingClientRect(),r=t.clientX-n.left,i=t.clientY-n.top,{top:a,left:o,right:c,bottom:l}=ze(n.width),u=Math.max(1,n.width-o-c),d=Math.max(1,n.height-a-l);if(r<o||r>o+u||i<a||i>a+d)return;t.preventDefault();let f=at.current,p=f.xmax-f.xmin;if(!(p>0))return;if(we.current===`follow`&&ot()&&!Se.current){Te.current=lZ(Te.current,p,t.deltaY<0,p*.001);return}if(we.current===`follow`&&ot()){let e=lZ(xe.current,se.current?.bufferedSeconds?.()??p,t.deltaY<0);xe.current=e,Qe.current&&clearTimeout(Qe.current),Qe.current=setTimeout(()=>{Qe.current=null,Se.current?.(e)},UZ);return}let m=H.current??f.xmin,h=(U.current??f.xmax)-m;if(!(h>0))return;let g=Date.now();g-Pe.current>300&&(Ie.current=H.current,Le.current=U.current),Pe.current=g;let _=m+(r-o)/u*h,v=t.deltaY<0,y=.88,b=v?h*y:h/y,x=Math.max(p*1e-7,1e-12);if(v)b=Math.max(b,x);else{if(b>=p*.999){H.current=null,U.current=null,s(null),tt.current?.publish(nt.current??``,null),xt();return}b=Math.min(b,p)}let S=(_-m)/h,C=_-S*b,w=_+(1-S)*b;C<f.xmin&&(w+=f.xmin-C,C=f.xmin),w>f.xmax&&(C-=w-f.xmax,w=f.xmax),w-C<b-1e-12&&(C=Math.max(f.xmin,_-b/2),w=C+b,w>f.xmax&&(w=f.xmax,C=w-b)),w-C>=p*.999?(H.current=null,U.current=null,s(null),tt.current?.publish(nt.current??``,null)):(H.current=C,U.current=w,s([C,w]),tt.current?.publish(nt.current??``,[C,w])),xt()},l=e=>{if(e.preventDefault(),Fe.current=Date.now(),Date.now()-Pe.current<300){H.current=Ie.current,U.current=Le.current;let e=Ie.current,t=Le.current;Ze.current&&=(clearTimeout(Ze.current),null),$e.current?.(e===null&&t===null?null:[e,t]),Pe.current=0,xt()}},u=t=>{if(t.button===0&&Be.current){let n=e.getBoundingClientRect(),{left:r,top:i,right:a,bottom:o}=ze(n.width),s=Math.max(1,n.width-r-a),c=n.height-i-o,l=t.clientX-n.left,u=t.clientY-n.top;if(l>=r&&l<=r+s&&u>=i&&u<=i+c){Ve.current=t.clientX,Be.current.onDragStart();try{e.setPointerCapture(t.pointerId)}catch{}}return}if(t.button!==2)return;if(t.preventDefault(),t.buttons===0){rt.current?.({clientX:t.clientX,clientY:t.clientY});return}if(Me.current!==`none`){De.current=!1,Me.current=`none`;try{e.releasePointerCapture(t.pointerId)}catch{}}let n=e.getBoundingClientRect(),r=t.clientX-n.left,i=t.clientY-n.top;Ne.current=Date.now(),Me.current=`menuOnly`,De.current=!1,Oe.current=r,ke.current=i,Ae.current=r,je.current=i;try{e.setPointerCapture(t.pointerId)}catch{}},d=t=>{if(Ve.current!==null){let n=t.clientX-Ve.current,r=e.getBoundingClientRect(),{left:i,right:a}=ze(r.width),o=Math.max(1,r.width-i-a),{xmin:s,xmax:c}=st(),l=c-s;l>0&&o>0&&Be.current?.onDragOffset(n/o*l);return}if(Me.current===`none`)return;let n=e.getBoundingClientRect(),r=t.clientX-n.left,i=t.clientY-n.top;if(Me.current===`menuOnly`){if(Date.now()-Ne.current<150)return;let e=r-Oe.current,t=i-ke.current;if(Math.sqrt(e*e+t*t)<12)return;let a=lt(),{top:o,left:s,right:c,bottom:l}=ze(n.width),u=n.width-s-c,d=n.height-o-l,f=u>0&&d>0&&Oe.current>=s&&Oe.current<=s+u&&ke.current>=o&&ke.current<=o+d;if(_Q(a)<2||!f)return;Me.current=`rubber`,De.current=!0,z.current=null}Me.current===`rubber`&&(t.preventDefault(),Ae.current=r,je.current=i,Ct())},f=t=>{if(t.button!==2)return;t.preventDefault();let n=Me.current;Me.current=`none`;try{e.releasePointerCapture(t.pointerId)}catch{}if(n===`menuOnly`){De.current=!1,Ct(),rt.current?.({clientX:t.clientX,clientY:t.clientY});return}if(n!==`rubber`||!De.current){De.current=!1,Ct();return}De.current=!1;let r=lt(),i=e.getBoundingClientRect(),{left:a,right:o}=ze(i.width),s=Math.max(1,i.width-a-o),c=Oe.current,l=Ae.current,u=Math.abs(l-c);if(_Q(r)<2||u<12){rt.current?.({clientX:t.clientX,clientY:t.clientY}),Ct();return}let d=fQ(Math.min(c,l),a,a+s),f=fQ(Math.max(c,l),a,a+s),{xmin:p,xmax:m}=st(),h=m-p;if(!(h>0)){rt.current?.({clientX:t.clientX,clientY:t.clientY}),Ct();return}let g=p+(d-a)/s*h,_=p+(f-a)/s*h;if(g>_){let e=g;g=_,_=e}let v=at.current,y=Math.min(v.xmin,v.xmax),b=Math.max(v.xmin,v.xmax);g=fQ(g,y,b),_=fQ(_,y,b);let x=_-g;if(x<=(b-y)*1e-12||x<=0){rt.current?.({clientX:t.clientX,clientY:t.clientY}),Ct();return}rt.current?.({clientX:t.clientX,clientY:t.clientY,zoomXRange:[g,_]}),Ct()},p=t=>{if(t.button===0&&Ve.current!==null){Ve.current=null;try{e.releasePointerCapture(t.pointerId)}catch{}return}if(t.button===2){f(t);return}if(t.buttons===0&&Me.current!==`none`){Me.current=`none`,De.current=!1;try{e.releasePointerCapture(t.pointerId)}catch{}rt.current?.({clientX:t.clientX,clientY:t.clientY}),Ct()}},m=t=>{Ve.current!==null&&(Ve.current=null),Me.current!==`none`&&(De.current=!1,Me.current=`none`);try{e.releasePointerCapture(t.pointerId)}catch{}Ct()},h=t=>{if(t.button!==0||_Q(lt())<2)return;let n=e.getBoundingClientRect(),r=t.clientX-n.left,i=t.clientY-n.top,{top:a,left:o,right:s,bottom:c}=ze(n.width),l=Math.max(1,n.width-o-s),u=Math.max(1,n.height-a-c);r<o||r>o+l||i<a||i>a+u||H.current===null&&U.current===null||(H.current=null,U.current=null,Ze.current&&=(clearTimeout(Ze.current),null),$e.current?.(null),tt.current?.publish(nt.current??``,null),xt(),Ct())},g=e=>{if(e.key!==`Escape`)return;let t=!1;Me.current!==`none`&&(Me.current=`none`,De.current=!1,t=!0),Ve.current!==null&&(Ve.current=null,t=!0),t&&Ct()};e.addEventListener(`mousemove`,a),e.addEventListener(`mouseleave`,o),e.addEventListener(`wheel`,c,{passive:!1}),e.addEventListener(`contextmenu`,l),e.addEventListener(`pointerdown`,u),e.addEventListener(`pointermove`,d),e.addEventListener(`pointerup`,p),e.addEventListener(`pointercancel`,m),e.addEventListener(`dblclick`,h);let _=e.ownerDocument.defaultView??window;return _.addEventListener(`keydown`,g),()=>{r.disconnect(),e.removeEventListener(`mousemove`,a),e.removeEventListener(`mouseleave`,o),e.removeEventListener(`wheel`,c),e.removeEventListener(`contextmenu`,l),e.removeEventListener(`pointerdown`,u),e.removeEventListener(`pointermove`,d),e.removeEventListener(`pointerup`,p),e.removeEventListener(`pointercancel`,m),e.removeEventListener(`dblclick`,h),_.removeEventListener(`keydown`,g),Ze.current&&clearTimeout(Ze.current),Qe.current&&clearTimeout(Qe.current)}},[]),(0,Q.jsxs)(`div`,{ref:A,className:`chart-canvas-wrap`,children:[(0,Q.jsx)(`canvas`,{ref:E,className:`chart-canvas`,role:`img`,"aria-label":`Chart of ${e}`}),(0,Q.jsx)(`canvas`,{ref:O,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),(0,Q.jsx)(`canvas`,{ref:D,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}},_e),(0,Q.jsx)(`canvas`,{ref:k,className:`chart-canvas chart-overlay`})]})}function kQ(){try{if(localStorage.getItem(`perfLog`)===`1`)return!0;if(localStorage.getItem(`perfLog`)===`0`)return!1}catch{}return!1}var AQ=!1;function jQ(){let e=kQ();return e&&!AQ&&(AQ=!0,console.log(`[perf] logging enabled — zoom an out-of-core chart to see decimate()/sampleRows timings`)),e}jQ();var MQ=new Map;function NQ(e,t){let n=(MQ.get(e)??0)+1;MQ.set(e,n),console.log(`[perf] ${e} #${n} ${t.toFixed(1)}ms`)}async function PQ(e,t){if(!jQ())return t();let n=performance.now();try{return await t()}finally{NQ(e,performance.now()-n)}}QG();var FQ=20;async function IQ(e,t,n,r){let{x0:i,bucket:a,rows:o,columns:s}=await PQ(`decimate(${t.length}col)`,()=>e.getSeriesMulti(t,n,r));return VG(o,s,i,a)}function LQ(e,t,n,r,i=0,a=!1,o=0){let[s,c]=(0,Z.useState)({points:ZG,fetchedViewport:null}),[l,u]=(0,Z.useState)(!1),d=`${t.join(`,`)}|${n?`${n.xKey}:${n.x0}:${n.x1}`:`none`}|${r}|${i}`,f=(0,Z.useMemo)(()=>{if(!a||!e?.getSeriesMultiSync||!n||t.length===0)return null;let i=o>0?e.getColumnsSync?.(t,n,o):null;if(i)return{points:i,loading:!1,fetchedViewport:n,full:!0};let s=e.getSeriesMultiSync(t,n,r);return{points:VG(s.rows,s.columns,s.x0,s.bucket),loading:!1,fetchedViewport:n}},[a,e,d,o]);return(0,Z.useEffect)(()=>{if(a)return;if(!e||!n||t.length===0){c({points:ZG,fetchedViewport:null});return}let i=!0;u(!0);let o=setTimeout(()=>{IQ(e,t,n,r).then(t=>{i&&(c({points:t,fetchedViewport:n,source:e}),u(!1))}).catch(()=>{i&&u(!1)})},FQ);return()=>{i=!1,clearTimeout(o)}},[e,d,a]),f||(s.source!==void 0&&s.source!==e?{points:ZG,loading:l,fetchedViewport:null}:{points:s.points,loading:l,fetchedViewport:s.fetchedViewport})}QG();var RQ=250,zQ=2,BQ=6e3,VQ=2e6,HQ=[];function UQ(e,t,n,r,i,a){let o=!!e&&e.columnSet.has(n),s=(0,Z.useMemo)(()=>e&&o?t.filter(t=>e.columnSet.has(t)):HQ,[e,o,t]),c=e&&o&&s.length>0?e.source:null,l=!!c&&!e?.live&&!!c.getSeriesMultiSync&&!!c.xBoundsSync,u=(0,Z.useMemo)(()=>l&&c?c.xBoundsSync(n):null,[l,c,n]),[d,f]=(0,Z.useState)(null),p=!!e?.live;(0,Z.useEffect)(()=>{if(!c||l)return;let e=!0,t=()=>c.xBounds(n).then(t=>{let r=c.version?.()??0;e&&f(e=>e&&e.source===c&&e.xKey===n&&e.ver===r?e:{source:c,xKey:n,b:t,ver:r})}).catch(()=>{});t();let r=p?setInterval(t,RQ):void 0;return()=>{e=!1,clearInterval(r)}},[c,n,p,l]);let m=d&&d.source===c&&d.xKey===n?d:null,h=u??m?.b??null,g=m?.ver??0,{points:_,loading:v,full:y}=LQ(c,s,c&&h&&h.x1>h.x0?{xKey:n,x0:h.x0,x1:h.x1}:null,Math.min(BQ,i*zQ),g,l,a),b=e?.xOffset??0,x=r&&r[1]>r[0]?r[0]-b:null,S=r&&r[1]>r[0]?r[1]-b:null,C=y||!!h&&x!==null&&S!==null&&x<=h.x0&&S>=h.x1,{points:w,fetchedViewport:T}=LQ(c,s,c&&x!==null&&S!==null&&!C?{xKey:n,x0:x,x1:S}:null,i,g,l,a),E=(0,Z.useMemo)(()=>!T||w.length===0?_:YG([KG(_,e=>e<T.x0),w,KG(_,e=>e>T.x1)]),[_,w,T]),D=!!c&&(h===null||v);return(0,Z.useMemo)(()=>e?{points:JG(E,e.keySuffix,e.xOffset),bounds:h?{x0:h.x0+e.xOffset,x1:h.x1+e.xOffset}:null,loading:D}:{points:ZG,bounds:null,loading:!1},[e,E,h,D])}var WQ=new WeakMap,GQ=0;function KQ(e){if(e.key!==void 0)return e.key;let t=WQ.get(e.source);return t===void 0&&WQ.set(e.source,t=GQ++),`${t}${e.keySuffix}`}function qQ(){let[e,t]=(0,Z.useState)(()=>new Map);return[e,(0,Z.useCallback)((e,n)=>t(t=>{if(n?t.get(e)===n:!t.has(e))return t;let r=new Map(t);return n?r.set(e,n):r.delete(e),r}),[])]}var JQ=(0,Z.memo)(function({id:e,layer:t,columns:n,xKey:r,view:i,mp:a,rawLimit:o,report:s}){let c=UQ(t,n,r,i,a,o);return(0,Z.useLayoutEffect)(()=>{s(e,c)},[e,c,s]),(0,Z.useLayoutEffect)(()=>()=>s(e,null),[e,s]),null});function YQ({layers:e,xKey:t,columns:n,maxPoints:r,...i}){let a=i.viewXRange??null,[o,s]=(0,Z.useState)(null),c=typeof window<`u`?Math.min(3,Math.max(1,window.devicePixelRatio||1)):1,l=o==null?r:Math.min(r,Math.round(o*c/50)*50),u=Math.max(1e3,Math.round(l/Math.sqrt(Math.max(1,e.length)))),d=Math.floor(VQ/Math.max(1,e.length)),[f,p]=qQ(),m=(0,Z.useMemo)(()=>e.map(KQ),[e]),h=(0,Z.useMemo)(()=>m.map(e=>f.get(e)),[m,f]),g=(0,Z.useMemo)(()=>h.flatMap(e=>e&&e.points.length>0?[e.points]:[]),[h]),_=(0,Z.useMemo)(()=>{let e=1/0,t=-1/0;for(let n of h){let r=n?.bounds;r&&(e=Math.min(e,r.x0),t=Math.max(t,r.x1))}return Number.isFinite(e)&&t>e?[e,t]:null},[h]),v=h.some(e=>!e||e.loading);return(0,Q.jsxs)(Q.Fragment,{children:[e.map((e,r)=>(0,Q.jsx)(JQ,{id:m[r],layer:e,columns:n,xKey:t,view:a,mp:u,rawLimit:d,report:p},m[r])),g.length===0?(0,Q.jsxs)(`div`,{className:`chart-placeholder chart-placeholder--no-data`,onContextMenu:e=>{e.preventDefault(),i.onPlotContextMenu?.({clientX:e.clientX,clientY:e.clientY})},children:[(0,Q.jsx)(`span`,{className:`content-empty-icon`,"aria-hidden":!0}),(0,Q.jsx)(`h2`,{children:v?`Loading…`:`No data to plot`}),v?null:(0,Q.jsx)(`p`,{children:`None of the selected datasets has this X column together with a plotted channel.`})]}):(0,Q.jsx)(OQ,{points:g,fullXRange:_,...i,onPlotWidthCss:s})]})}Qe(),QG();function XQ(e){return!!e&&!Array.isArray(e)&&typeof e.length==`number`&&`x`in e&&`y`in e}function ZQ(e){let t=e.length,n=new Float64Array(t),r=new Float64Array(t),i=t>0&&e[0].c!==void 0?new Float32Array(t):void 0,a=e.some(e=>e.d!==void 0)?new Uint8Array(t):void 0;for(let o=0;o<t;o++){let t=e[o];n[o]=t.x,r[o]=t.y,i&&(i[o]=t.c??0),a&&(a[o]=t.d??0)}return{length:t,x:n,y:r,c:i,d:a}}function QQ(e,t,n){let r=n?.get(t);if(r)return r;let i=Ge(e);if(i)return Ke(i,t);if(e.length===0||!(t in e[0]))return;let a=new Float64Array(e.length);for(let n=0;n<e.length;n++){let r=e[n][t];a[n]=typeof r==`number`?r:NaN}return a}function $Q(e,t,n){let r=QQ(e,t,n);if(!r||XG.has(r))return r;let i=0;for(let e=0;e<r.length;e++)r[e]-r[e]===0&&i++;if(i===r.length)return r;let a=new Float64Array(i);for(let e=0,t=0;e<r.length;e++)r[e]-r[e]===0&&(a[t++]=r[e]);return a}function e$(e,t,n,r){if(!n){let n=$Q(e,t,r);return n?[{label:t,values:n}]:[]}let i=QQ(e,t,r);if(!i)return[];let a=i.length,o=r?.has(n)||e.length>0&&typeof e[0][n]==`number`?QQ(e,n,r):void 0,s=t=>{if(o){let e=o[t];return e===e?String(e):`unknown`}return String(e[t]?.[n]??`unknown`)},c=new Map,l=[],u=new Int32Array(a),d=[];for(let e=0;e<a;e++){if(i[e]-i[e]!==0){u[e]=-1;continue}let t=s(e),n=c.get(t);n===void 0&&(c.set(t,n=l.length),l.push(t),d.push(0)),u[e]=n,d[n]++}let f=l.map((e,t)=>({label:e,values:new Float64Array(d[t])})),p=new Int32Array(l.length);for(let e=0;e<a;e++){let t=u[e];t>=0&&(f[t].values[p[t]++]=i[e])}return f}function t$(e){let t=NaN,n=NaN,r=0;for(let i=0;i<e.length;i++){let a=e[i];a-a===0&&(r===0&&(t=a),n=a,r++)}let i=n-t;return r>1&&i>0?(r-1)/i:null}function n$(e,t,n){let r=0;for(let i=0;i<e.length;i++)e[i]>=t&&e[i]<=n&&r++;let i=new Uint32Array(r),a=0;for(let r=0;r<e.length;r++)e[r]>=t&&e[r]<=n&&(i[a++]=r);return i}function r$(e,t){let n=new Float64Array(t.length);for(let r=0;r<t.length;r++)n[r]=e[t[r]];return n}function i$(e,t,n,r){let i=QQ(e.rows,t,e.full),a=QQ(e.rows,n,e.full);if(!i||!a)return null;let o=r.colorCol?QQ(e.rows,r.colorCol,e.full):void 0;if(r.viewXRange){let t=QQ(e.rows,r.xKey,e.full);if(t){let e=n$(t,r.viewXRange[0],r.viewXRange[1]);i=r$(i,e),a=r$(a,e),o&&=r$(o,e)}}let s=Math.min(i.length,a.length);if(!o)return{cols:{length:s,x:i,y:a}};let c=1/0,l=-1/0;for(let e=0;e<s;e++){let t=o[e];t<c&&(c=t),t>l&&(l=t)}if(!(l>c))return{cols:{length:s,x:i,y:a}};let u=new Float32Array(s),d=l-c;for(let e=0;e<s;e++){let t=o[e];u[e]=t===t?(t-c)/d:0}return{cols:{length:s,x:i,y:a,c:u},color:{label:r.colorCol,min:c,max:l}}}function a$(e,t,n,r){let i=[],a=[];e.forEach((e,o)=>{a.push(NJ(r.colorOverrides,e.id,o,r.palette));let s=i$(e,t,n,{xKey:r.xKey,viewXRange:r.viewXRange});i.push(s?.cols??{length:0,x:[],y:[]})});let o=i.reduce((e,t)=>e+t.length,0),s=new Float64Array(o),c=new Float64Array(o),l=new Uint8Array(o),u=0;return i.forEach((e,t)=>{for(let t=0;t<e.length;t++)s[u+t]=e.x[t],c[u+t]=e.y[t];l.fill(Math.min(t,255),u,u+e.length),u+=e.length}),{cols:{length:o,x:s,y:c,d:l},colors:a}}var o$=e=>XQ(e)?e:ZQ(e),s$=(e,t,n)=>t===t&&n===n&&(!e||t>=e.xmin&&t<=e.xmax&&n>=e.ymin&&n<=e.ymax);function c$(e,t,n){let r=t+1,i=Array.from({length:r},()=>Array(r).fill(0)),a=Array(r).fill(0),o=new Float64Array(2*r-1),s=0;for(let t=0;t<e.length;t++){let c=e.x[t],l=e.y[t];if(s$(n,c,l)){s++,o[0]=1;for(let e=1;e<o.length;e++)o[e]=o[e-1]*c;for(let e=0;e<r;e++){for(let t=0;t<r;t++)i[e][t]+=o[e+t];a[e]+=o[e]*l}}}if(s<r)return null;let c=i.map((e,t)=>[...e,a[t]]);for(let e=0;e<r;e++){let t=e;for(let n=e+1;n<r;n++)Math.abs(c[n][e])>Math.abs(c[t][e])&&(t=n);if([c[e],c[t]]=[c[t],c[e]],Math.abs(c[e][e])<1e-10)return null;let n=c[e][e];for(let t=e;t<=r;t++)c[e][t]/=n;for(let t=0;t<r;t++){if(t===e)continue;let n=c[t][e];for(let i=e;i<=r;i++)c[t][i]-=n*c[e][i]}}return c.map(e=>e[r])}function l$(e,t,n){return c$(o$(e),t,n)}function u$(e,t=4){if(!Number.isFinite(e))return`?`;let n=Math.abs(e);return n===0?`0`:n>=1e5||n>0&&n<.001?e.toExponential(2):e.toPrecision(t).replace(/\.?0+$/,``)}function d$(e,t,n){let r=[];for(let n=e.length-1;n>=0;n--){let i=e[n];n===0?r.push(u$(i)):n===1?r.push(`${u$(i)}·${t}`):r.push(`${u$(i)}·${t}${n>1?`^${n}`:``}`)}return`${n} = ${r.join(` + `).replace(/\+ -/g,`− `)}`}var f$=[[0,45,80,160],[.25,40,145,175],[.5,60,180,110],[.75,220,175,55],[1,210,75,55]];function p$(e){let t=0;for(let n=1;n<f$.length;n++){if(e<=f$[n][0]){t=n-1;break}n===f$.length-1&&(t=n-1)}let n=t+1,r=(e-f$[t][0])/(f$[n][0]-f$[t][0]);return{r:Math.round(f$[t][1]+r*(f$[n][1]-f$[t][1])),g:Math.round(f$[t][2]+r*(f$[n][2]-f$[t][2])),b:Math.round(f$[t][3]+r*(f$[n][3]-f$[t][3]))}}function m$(e){let{r:t,g:n,b:r}=p$(e);return`rgb(${t},${n},${r})`}function h$(e,t){if(!Number.isFinite(e))return 0;let n=Math.floor(e*t);return n<0?0:n>=t?t-1:n}QG();var g$=`#version 300 es
|
|
226
|
+
}`;function LX(e,t,n,r){let i=e.length,a=0;for(let t=0;t<i;t++)Number.isFinite(r[t])&&Number.isFinite(e[t])&&a++;if(a===i)return null;let o=new Float32Array(a),s=new Float32Array(a),c=new Uint8Array(a),l=0,u=!1;for(let a=0;a<i;a++)n[a]&&(u=!0),Number.isFinite(r[a])&&Number.isFinite(e[a])&&(o[l]=t[a],s[l]=r[a],u&&=(c[l]=255,!1),l++);return{x:o,y:s,starts:c}}function RX(e,t,n){let r=e.length,i=0;for(let t=0;t<r;t++)if(Number.isFinite(e[t])){i=e[t];break}let a=new Float32Array(r);for(let t=0;t<r;t++)a[t]=e[t]-i;let o=new Uint8Array(r);if(t)for(let e=0;e<r;e++)t[e]&&(o[e]=255);let s=n.map(t=>LX(e,a,o,t)??{x:a,y:t,starts:o}),c=s.map(e=>e.y.length),l=c.reduce((e,t)=>e+t,0),u=new Float32Array(l),d=new Float32Array(l),f=new Uint8Array(l),p=new Float32Array(l),m=0;return s.forEach((e,t)=>{u.set(e.x,m),d.set(e.y,m),f.set(e.starts,m),e.y.length>0&&(f[m]=255),p.fill(t,m,m+e.y.length),m+=e.y.length}),{origin:i,x:u,y:d,starts:f,sid:p,counts:c}}function zX(e,t,n,r,i,a){let o=(i-r)/a,s=(t,n)=>{let r=0,i=e.length;for(;r<i;){let a=r+i>>>1;(n?e[a]<=t:e[a]<t)?r=a+1:i=a}return r},c=s(r,!1),l=s(i,!0),u=t.length*(2*a+2),d=new Float32Array(u),f=new Float32Array(u),p=new Uint8Array(u),m=new Float32Array(u),h=0,g=(e,t,r)=>{d[h]=e-n,f[h]=t,m[h]=r,h++};return t.forEach((t,n)=>{let i=h;for(let r=c-1;r>=Math.max(0,c-64);r--)if(t[r]===t[r]){g(e[r],t[r],n);break}let s=c;for(let i=0;i<a&&s<l;i++){let c=i===a-1?1/0:r+(i+1)*o,u=1/0,d=-1/0,f=-1,p=-1;for(;s<l&&e[s]<c;s++){let e=t[s];e<u&&(u=e,f=s),e>d&&(d=e,p=s)}f<0||(f===p?g(e[f],u,n):f<p?(g(e[f],u,n),g(e[p],d,n)):(g(e[p],d,n),g(e[f],u,n)))}for(let r=l;r<Math.min(e.length,l+64);r++)if(t[r]===t[r]){g(e[r],t[r],n);break}h>i&&(p[i]=255)}),{x:d.subarray(0,h),y:f.subarray(0,h),starts:p.subarray(0,h),sid:m.subarray(0,h),bucket:o}}function BX(e){for(let t=1;t<e.length;t++)if(!(e[t]>=e[t-1]))return!1;return e.length===0||e[0]===e[0]}function VX(e,t=1){let n=e.getContext(`webgl2`,{antialias:!1,alpha:!0,premultipliedAlpha:!0}),r=typeof HTMLCanvasElement<`u`&&e instanceof HTMLCanvasElement||typeof OffscreenCanvas<`u`&&e instanceof OffscreenCanvas;if(!n)return null;let i=()=>{let e=bX(n,n.VERTEX_SHADER,FX),t=bX(n,n.FRAGMENT_SHADER,IX);if(!e||!t)return null;let r=n.createProgram();return r?(n.attachShader(r,e),n.attachShader(r,t),n.linkProgram(r),n.getProgramParameter(r,n.LINK_STATUS)?{prog:r,vs:e,fs:t}:(console.error(`glSeries program link failed:`,n.getProgramInfoLog(r)),null)):null},a=r?i():MX(n,`glSeries`,i);if(!a)return null;let{prog:o,vs:s,fs:c}=a,l=e=>n.getAttribLocation(o,e),u=l(`a_corner`),d=l(`a_ax`),f=l(`a_bx`),p=l(`a_ay`),m=l(`a_by`),h=l(`a_bstart`),g=l(`a_sid`),_=[d,f,p,m,h,g],v=e=>n.getUniformLocation(o,e),y={res:v(`u_resolution`),styles:v(`u_styles`),left:v(`u_left`),plotW:v(`u_plotW`),xoff:v(`u_xoff`),xscale:v(`u_xscale`),xR:v(`u_xR`),minGap:v(`u_minGap`),cutPx:v(`u_cutPx`)},b=n.createBuffer();n.bindBuffer(n.ARRAY_BUFFER,b),n.bufferData(n.ARRAY_BUFFER,Float32Array.from([-1,-1,1,-1,-1,1,1,1]),n.STATIC_DRAW);let x=n.createFramebuffer(),S=n.createRenderbuffer(),C=1,w=1,T=(`clientWidth`in e?e.clientWidth:0)||1,E=(`clientHeight`in e?e.clientHeight:0)||1,D=[],O=0,k=1,A=1/0,j=e=>{let t=n.createBuffer();return n.bindBuffer(n.ARRAY_BUFFER,t),n.bufferData(n.ARRAY_BUFFER,e,n.STATIC_DRAW),t},M=e=>{if(e)for(let t of[e.x,e.y,e.starts,e.sid])n.deleteBuffer(t)},N=e=>{e&&(M(e.full),M(e.res),n.deleteTexture(e.styles))},P=e=>({x:j(e.x),y:j(e.y),starts:j(e.starts),sid:j(e.sid),total:e.x.length}),F=e=>{let t=e.full;if(t&&t.version===e.version)return t;if(t&&e.valuesOnly&&t.whole&&e.counts.every(t=>t===e.xs.length)){let r=e.xs.length,i=e.columns.length===1?e.columns[0]:new Float32Array(r*e.columns.length);return e.columns.length>1&&e.columns.forEach((e,t)=>i.set(e,t*r)),n.bindBuffer(n.ARRAY_BUFFER,t.y),n.bufferSubData(n.ARRAY_BUFFER,0,i),t.version=e.version,t}M(t);let r=RX(e.xs,e.breaks,e.columns);return e.full={...P(r),version:e.version,whole:r.counts.every(t=>t===e.xs.length)},e.full},I=t=>{let n=Math.max(1,Math.round(t.plotW*(e.width/T)));if(t.resamplable&&k>O){let e=t.xs,r=0,i=e.length;for(;r<i;){let t=r+i>>>1;e[t]<O?r=t+1:i=t}let a=r;for(i=e.length;r<i;){let t=r+i>>>1;e[t]<=k?r=t+1:i=t}if(r-a>n*4){let r=`${t.version}|${O}|${k}|${n}`;if(t.res?.key!==r){M(t.res);let i=zX(e,t.columns,t.origin,O,k,n);t.res={...P(i),key:r,bucket:i.bucket}}return{d:t.res,minGap:t.res.bucket*2.5}}}return{d:F(t),minGap:0}},L=(e,r)=>{let i=e.counts.length,a=Math.max(1,Math.ceil(i/PX)),o=3*Math.min(Math.max(i,1),PX),s=new Float32Array(o*a*4);for(let n=0;n<i;n++){let i=r[n],a=(Math.floor(n/PX)*o+n%PX*3)*4;if(!i)continue;let c=i.width??t;s.set([Math.min(i.scaleMin,i.scaleMax),Math.max(i.scaleMin,i.scaleMax),i.bandTop,i.bandBottom],a),s.set(i.color,a+4),s.set([i.gapMedian,c/2,c/2+_X,+(e.counts[n]>=2)],a+8)}n.bindTexture(n.TEXTURE_2D,e.styles),n.texImage2D(n.TEXTURE_2D,0,n.RGBA32F,o,a,0,n.RGBA,n.FLOAT,s),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.NEAREST)};return{resize(t,r,i){T=Math.max(1,t),E=Math.max(1,r),e.width=Math.round(T*i),e.height=Math.round(E*i),C=e.width*2,w=e.height*2,x&&S&&(n.bindRenderbuffer(n.RENDERBUFFER,S),n.renderbufferStorage(n.RENDERBUFFER,n.RGBA8,C,w),n.bindFramebuffer(n.FRAMEBUFFER,x),n.framebufferRenderbuffer(n.FRAMEBUFFER,n.COLOR_ATTACHMENT0,n.RENDERBUFFER,S),n.bindFramebuffer(n.FRAMEBUFFER,null))},setData(e,t,r,i){let a=D[e],o=!t&&!!a&&i.length===a.columns.length;if(!t){if(!a)return;t=a.xs,r=a.breaks}let s=0;for(let e=0;e<t.length;e++)if(Number.isFinite(t[e])){s=t[e];break}let c=i.map(e=>{let t=0;for(let n=0;n<e.length;n++)e[n]===e[n]&&t++;return t});if(a&&(o||a.xs===t)){a.columns=i,a.counts=c,a.valuesOnly=o,a.version++,o||(M(a.full),a.full=null);return}let l={xs:t,breaks:r,columns:i,origin:s,counts:c,resamplable:!r?.some(e=>e)&&BX(t),version:0,valuesOnly:!1,full:null,res:null,styles:n.createTexture(),left:a?.left??0,plotW:a?.plotW??0};L(l,[]),D[e]=l,N(a)},setStyles(e,t,n,r){let i=D[e];i&&(L(i,t),i.left=n,i.plotW=r)},clearLayer(e){N(D[e]),D[e]=null},setView(e,t,n=1/0){O=e,k=t,A=n},render(){n.bindFramebuffer(n.FRAMEBUFFER,x),n.viewport(0,0,x?C:e.width,x?w:e.height),n.disable(n.SCISSOR_TEST),n.clearColor(0,0,0,0),n.clear(n.COLOR_BUFFER_BIT),n.useProgram(o),n.uniform2f(y.res,T,E),n.uniform1i(y.styles,0),n.activeTexture(n.TEXTURE0),n.enable(n.BLEND),n.blendFunc(n.ONE,n.ONE_MINUS_SRC_ALPHA),n.bindBuffer(n.ARRAY_BUFFER,b),n.enableVertexAttribArray(u),n.vertexAttribPointer(u,2,n.FLOAT,!1,0,0),n.vertexAttribDivisor(u,0);for(let e of _)n.enableVertexAttribArray(e),n.vertexAttribDivisor(e,1);let t=k-O||1;for(let e of D){if(!e)continue;n.uniform1f(y.left,e.left),n.uniform1f(y.plotW,e.plotW),n.uniform1f(y.xoff,O-e.origin),n.uniform1f(y.xscale,e.plotW/t),n.uniform1f(y.xR,t),n.uniform1f(y.cutPx,Number.isFinite(A)?e.left+(A-O)*(e.plotW/t):1e9);let{d:r,minGap:i}=I(e);r.total<2||(n.uniform1f(y.minGap,i),n.bindTexture(n.TEXTURE_2D,e.styles),n.bindBuffer(n.ARRAY_BUFFER,r.x),n.vertexAttribPointer(d,1,n.FLOAT,!1,4,0),n.vertexAttribPointer(f,1,n.FLOAT,!1,4,4),n.bindBuffer(n.ARRAY_BUFFER,r.y),n.vertexAttribPointer(p,1,n.FLOAT,!1,4,0),n.vertexAttribPointer(m,1,n.FLOAT,!1,4,4),n.bindBuffer(n.ARRAY_BUFFER,r.starts),n.vertexAttribPointer(h,1,n.UNSIGNED_BYTE,!0,1,1),n.bindBuffer(n.ARRAY_BUFFER,r.sid),n.vertexAttribPointer(g,1,n.FLOAT,!1,4,0),n.drawArraysInstanced(n.TRIANGLE_STRIP,0,4,r.total-1))}for(let e of _)n.vertexAttribDivisor(e,0);x&&(n.bindFramebuffer(n.READ_FRAMEBUFFER,x),n.bindFramebuffer(n.DRAW_FRAMEBUFFER,null),n.blitFramebuffer(0,0,C,w,0,0,e.width,e.height,n.COLOR_BUFFER_BIT,n.LINEAR),n.bindFramebuffer(n.FRAMEBUFFER,null))},dispose(){for(let e of D)N(e);D.length=0,n.deleteBuffer(b),n.deleteFramebuffer(x),n.deleteRenderbuffer(S),r&&(n.deleteProgram(o),n.deleteShader(s),n.deleteShader(c)),r&&n.getExtension(`WEBGL_lose_context`)?.loseContext()}}}``+new URL(`assets/offscreenLineWorker-C-_uNa_H.js`,__kymoscopeScriptUrl).href;var HX=[],UX=12,WX=!1,GX=!1,KX=0,qX=3,JX=1;function YX(){return!WX&&typeof Worker<`u`&&typeof HTMLCanvasElement<`u`&&typeof HTMLCanvasElement.prototype.transferControlToOffscreen==`function`}var XX=`kymoscope-gl-first-frame`;function ZX(t,n=1,r,i,a){if(typeof t.transferControlToOffscreen!=`function`||typeof Worker>`u`)return null;let o,s=HX.pop();try{o=s??CE(``+new URL(`assets/offscreenLineWorker-C-_uNa_H.js`,__kymoscopeScriptUrl).href)}catch{return WX=!0,null}let c;try{c=t.transferControlToOffscreen()}catch{return s?HX.push(s):o.terminate(),null}let l=()=>{},u=JX++,d=!1;o.postMessage({type:`init`,canvas:c,lineWidth:n,gen:u},[c]),o.onmessage=e=>{e.data?.gen===u&&(e.data.type===`lost`?r?.():e.data.type===`first`&&(GX=!0,performance.mark?.(XX),l()))},o.onerror=()=>{d=!0,(!GX||++KX>=qX)&&(WX=!0),r?.()};let f=DX(i),p=-1,m=-1,h=-1,g={own:!0,resize(e,t,n){e===p&&t===m&&n===h||(p=e,m=t,h=n,o.postMessage({type:`resize`,w:e,h:t,dpr:n}))},setData(e,t){let n=[];t.xs&&n.push(t.xs.buffer),t.breaks&&n.push(t.breaks.buffer);for(let e of t.columns)n.push(e.buffer);o.postMessage({type:`data`,layer:e,...t},n)},setStyle(e,t){o.postMessage({type:`style`,layer:e,...t})},clear(e){o.postMessage({type:`clear`,layer:e})},setView(e,t,n){o.postMessage({type:`view`,xmin:e,xmax:t,cut:n})},dispose(){o.onmessage=null,o.onerror=null;let e=!d&&!WX&&HX.length<UX;try{o.postMessage({type:`dispose`})}catch{e=!1}e?HX.push(o):o.terminate(),f()}},_=a?QX(a,n):null;if(!_||!a)return g;let v=()=>{_&&(_.dispose(),_=null,a.getContext(`2d`)?.clearRect(0,0,a.width,a.height))};return l=()=>{(typeof requestAnimationFrame==`function`?requestAnimationFrame:setTimeout)(v)},{own:!0,resize(e,t,n){_?.resize(e,t,n),g.resize(e,t,n)},setData(e,t){_?.setData(e,{...t,xs:t.xs?t.xs.slice():null,breaks:t.breaks?.slice(),columns:t.columns.map(e=>e.slice())}),g.setData(e,t)},setStyle(e,t){_?.setStyle(e,t),g.setStyle(e,t)},clear(e){_?.clear(e),g.clear(e)},setView(e,t,n){_?.setView(e,t,n),g.setView(e,t,n)},dispose(){v(),g.dispose()}}}function QX(e,t=1){let n=NX(e,e=>VX(e,t));if(!n)return null;let r=0,i=1,a,o=``,s=(e,t)=>{n.setStyles(e,t.styles,t.left,t.plotW),r=t.xmin,i=t.xmax,a=t.cut,n.setView(r,i,a),n.render()};return{resize(e,t,r){let i=`${e}|${t}|${r}`;i!==o&&(o=i,n.resize(e,t,r),n.render())},setData(e,t){n.setData(e,t.xs,t.breaks,t.columns),s(e,t)},setStyle(e,t){s(e,t)},clear(e){n.clearLayer(e),n.render()},setView(e,t,o){e===r&&t===i&&o===a||(r=e,i=t,a=o,n.setView(e,t,o),n.render())},dispose(){n.dispose()}}}var $X=new Set;function eZ(e){$X.add(e)}function tZ(e){$X.delete(e)}function nZ(){let e=typeof window>`u`?[]:[window];for(let t of $X)t.closed||e.push(t);return e}var rZ=1,iZ=new Map;function aZ(e,t){let n=typeof window>`u`?void 0:window.performance?.timeOrigin,r=e.performance?.timeOrigin;return n!==void 0&&r!==void 0&&e!==window?t+(r-n):t}function oZ(e){let t=rZ++,n=nZ();if(n.length===1){let r=n[0],i=r.requestAnimationFrame(n=>{iZ.delete(t),e(aZ(r,n))});return iZ.set(t,[{w:n[0],id:i}]),t}let r=[];for(let i of n)r.push({w:i,id:i.requestAnimationFrame(n=>{iZ.has(t)&&(sZ(t),e(aZ(i,n)))})});return iZ.set(t,r),t}function sZ(e){if(e==null)return;let t=iZ.get(e);if(t){iZ.delete(e);for(let{w:e,id:n}of t)e.closed||e.cancelAnimationFrame(n)}}var cZ=new WeakMap;function lZ(e){e&&cZ.set(e,(cZ.get(e)??0)+1)}function uZ(e){let t=cZ.get(e)??0;for(let n of e.querySelectorAll(`*`))t+=cZ.get(n)??0;return t}function dZ(){return nZ().every(e=>e.document.hidden)}var fZ=class{#e;#t=new Map;constructor(e){this.#e=e}observe(e,t){let n=e.ownerDocument.defaultView??window,r=this.#t.get(n);r||(r=new(n.ResizeObserver??ResizeObserver)(e=>this.#e(e,this)),this.#t.set(n,r)),r.observe(e,t)}unobserve(e){for(let t of this.#t.values())t.unobserve(e)}disconnect(){for(let e of this.#t.values())e.disconnect();this.#t.clear()}};function pZ(e){return!!e&&e.isConnected&&typeof e.checkVisibility==`function`&&!e.checkVisibility()}function mZ(e,t){let n=0,r=null,i=()=>pZ(t()),a=t=>{n=0,!i()&&(r=t,e())};return{schedule(){n||=oZ(a)},now(){if(i())return;let o=t()?.ownerDocument?.timeline?.currentTime;if(typeof o!=`number`||o===r){n||=oZ(a);return}n&&=(sZ(n),0),r=o,e()},cancel(){n&&sZ(n),n=0}}}var hZ=.6,gZ=16,_Z={ts:-1,work:0,floor:1/0},vZ=1/0;function yZ(e,t=-1/0){if(e!==_Z.ts){if(e>_Z.ts&&e<_Z.ts+_Z.work/hZ)return!1;_Z={ts:e,work:0,floor:vZ},vZ=1/0}return _Z.work>=gZ||t>_Z.floor?(vZ=Math.min(vZ,t),!1):!0}function bZ(e,t){e===_Z.ts&&(_Z.work+=t)}function xZ(e,t=typeof window>`u`?null:e=>{oZ(e)}){let n=!1,r=null;return{set(i){if(r=i,!t){e(i);return}n||(n=!0,t(()=>{n=!1,e(r)}))}}}function SZ(e,t,n,r,i){return r+(e-t)/n*(i-r)}function CZ(e,t,n,r){let i=new Map,a=n.length;if(a===0)return i;let o=new Float64Array(a),s=new Float64Array(a).fill(1/0);for(let r of e){let e=r.x;for(let i=0;i<a;i++){let a=r.cols.get(n[i]);if(!a)continue;let c=s[i],l=o[i];for(let n=0;n<r.length;n++){let r=e[n],i=r<t?t-r:r-t;if(i>=c)continue;let o=a[n];Number.isFinite(o)&&(c=i,l=o)}s[i]=c,o[i]=l}}for(let e=0;e<a;e++)s[e]!==1/0&&(r&&s[e]>(r.get(n[e])??1/0)||i.set(n[e],o[e]));return i}function wZ(e,t,n,r=64){let i=new Map;if(t.length===0||!Number.isFinite(n))return i;let a=new Map;for(let o of e){if(o.length===0)continue;let e=0,s=o.length-1;for(;e<s;){let t=e+s>>1;o.x[t]<n?e=t+1:s=t}for(let s of t){let t=o.cols.get(s);if(t)for(let c=0;c<=r;c++){let r=e-c,l=e+c,u=r>=0&&Number.isFinite(t[r])?r:l<o.length&&Number.isFinite(t[l])?l:-1;if(u<0)continue;let d=Math.abs(o.x[u]-n);d<(a.get(s)??1/0)&&(a.set(s,d),i.set(s,t[u]));break}}}return i}function TZ(e,t){let n=new Map;if(t.length===0)return n;for(let r=e.length-1;r>=0&&n.size<t.length;r--){let i=e[r];for(let e of t){if(n.has(e))continue;let t=i.cols.get(e);if(t){for(let r=i.length-1;r>=0;r--)if(Number.isFinite(t[r])){n.set(e,t[r]);break}}}}return n}function EZ(e,t){return!(e>0)||!(t>0)?1:1-Math.exp(-e/t)}function DZ(e,t,n,r,i,a){let o=e;return n!==null&&Math.abs(t-n)<i*a&&(o+=t-n),o+(t-o)*r}function OZ(e,t,n,r=t){if(!(t>e)||n==null||!(n>0))return[e,t];let i=Number.isFinite(r)?Math.max(e,r):t;return i-n<e?[e,Math.min(t,e+n)]:[i-n,i]}function kZ(e,t){return e>0?Math.min(8e3,Math.max(400,Math.round(e*t*2))):2e3}var AZ=.5;function jZ(e,t,n,r=AZ){if(!(t>0))return e;let i=e!=null&&e>0?Math.min(e,t):t,a=n?i*.88:i/.88;return a>=t*.999?null:Math.max(r,a)}function MZ(e=0){return{d:null,lastT:NaN,wall:0,base:NaN,wait:e,waitAge:0,gap:NaN}}var NZ=new Map;function PZ(e,t,n,r){let i=NZ.get(e);if(i||NZ.set(e,i={p:MZ(),at:NaN,d:NaN}),n-i.at<2&&Number.isFinite(i.d))return i.d;let a=Number.isNaN(i.at)?16:n-i.at;return i.at=n,i.d=JZ(i.p,t,a,r),i.d}function FZ(){let e;for(let t of NZ.values())(!e||t.at>e.at)&&(e=t);return e&&Number.isFinite(e.d)?{newest:e.p.lastT,lag:e.p.lastT-e.d,wait:e.p.wait,waitAge:e.p.waitAge}:null}function IZ(e){return Math.min(WZ,e.wait*1.2+.05)}function LZ(e){return Number.isFinite(e.gap)?Math.min(e.gap,IZ(e)):0}function RZ(e){let t=NZ.get(e);return t?LZ(t.p):0}function zZ(e){let t=NZ.get(e);return t?IZ(t.p):0}function BZ(e,t,n){let r=e(t);if(!(n>0))return r;let i=(r-e(t-VZ))/VZ;return Number.isFinite(i)&&i>=0?r+i*n:r}var VZ=.25,HZ=1,UZ=250,WZ=3,GZ=90,KZ=30,qZ=.001;function JZ(e,t,n,r){if(!Number.isFinite(t))return t;let i=n/1e3;e.wall+=i;let a=n>UZ&&e.d!==null,o=e.lastT;if(t<e.lastT&&Object.assign(e,MZ(),{wall:e.wall}),t<=e.lastT)e.base+=i*qZ;else{let n=e.wall-t;e.base=Number.isNaN(e.base)?n:Math.min(e.base+i*qZ,n);let r=t-o;r>0&&r<HZ&&(e.gap=Number.isNaN(e.gap)?r:e.gap+(r-e.gap)*.1)}e.lastT=t;let s=e.wall-t-e.base;if(r){let n=t>o?r(o):NaN;s=t>o?e.wall-e.base-(Number.isFinite(n)?n:o):0}a||(e.waitAge+=i),a||(s>e.wait?(e.wait=Math.min(WZ,s),e.waitAge=0):s>e.wait*.8?e.waitAge=0:e.waitAge>GZ&&(e.wait*=Math.exp(-i/KZ)));let c=e.wall-e.base-IZ(e);if(e.d===null)e.d=e.wait>0?Math.min(t,c):t;else if(a||e.d<c-2)e.d=Math.min(t,c);else{let t=Math.min(n,64);e.d+=t/1e3,e.d+=(c-e.d)*Math.min(1,t/500)}return e.d>t&&(e.d=t),e.d}var YZ=(e,t)=>e.log?(Math.log10(Math.max(t,Number.MIN_VALUE))-Math.log10(e.v0))/(Math.log10(e.v1)-Math.log10(e.v0)||1):(t-e.v0)/(e.v1-e.v0||1),XZ=(e,t)=>e.log?10**(Math.log10(e.v0)+t*(Math.log10(e.v1)-Math.log10(e.v0))):e.v0+t*(e.v1-e.v0),ZZ=(e,t)=>e.left+YZ(e.x,t)*e.width,QZ=(e,t)=>XZ(e.x,(t-e.left)/(e.width||1)),$Z=(e,t)=>e.top+(1-YZ(e.y,t))*e.height,eQ=e=>!e||Number.isFinite(e.v0)&&Number.isFinite(e.v1)&&e.v0!==e.v1&&(!e.log||e.v0>0&&e.v1>0),tQ=(e,t)=>e===t||!!e&&!!t&&e.v0===t.v0&&e.v1===t.v1&&!!e.log==!!t.log;function nQ(){let e=null,t=new Set;return{get:()=>e,set:n=>{if(n&&(n.width>0&&n.height>0?(!eQ(n.x)||!eQ(n.y))&&(n={...n,x:eQ(n.x)?n.x:void 0,y:eQ(n.y)?n.y:void 0}):n=null),!(n===e||n&&e&&n.left===e.left&&n.top===e.top&&n.width===e.width&&n.height===e.height&&tQ(n.x,e.x)&&tQ(n.y,e.y))){e=n;for(let e of[...t])e()}},subscribe:e=>(t.add(e),()=>{t.delete(e)})}}var rQ=(0,Z.createContext)(()=>{}),iQ=()=>(0,Z.useContext)(rQ),aQ=`M5 .8a3.1 3.1 0 0 0-3.1 3.1v2.3L.8 7.6h8.4L8.1 6.2V3.9A3.1 3.1 0 0 0 5 .8zM3.9 8.4a1.1 1.1 0 0 0 2.2 0z`,oQ=[5,4],sQ=null;function cQ(e,t,n,r){typeof Path2D>`u`||(sQ??=new Path2D(aQ),e.save(),e.setLineDash([]),e.translate(t,n),e.fillStyle=r,e.fill(sQ),e.restore())}QG(),jE();var lQ=(()=>{try{return localStorage.getItem(`glLines`)!==`0`}catch{return!0}})(),uQ=(()=>{try{return localStorage.getItem(`offscreenGl`)!==`0`}catch{return!0}})(),dQ=70;function fQ(e){return e===`dashed`?[5,4]:e===`dotted`?[1,4]:[]}var pQ={top:14,right:160,bottom:40,left:110},mQ={top:14,right:100,bottom:40,left:70},hQ=640,gQ={top:3,right:3,bottom:3,left:3},_Q=260;function vQ(e){return e<_Q?gQ:e<hQ?mQ:pQ}var yQ=220,bQ=.05,xQ=2e3,SQ=4,CQ=1e3/120,wQ=`11.25px ${X.mono}`,TQ=11*1.125,EQ=24*1.125,DQ=EQ-TQ+26,OQ=.6,kQ=13,AQ=10,jQ=5,MQ=14,NQ=4;function PQ(e,t,n){return Math.min(n,Math.max(t,e))}function FQ(e,t,n,r,i){let a=Math.min(r,i),o=Math.max(r,i);return t+(1-PQ(o===a?.5:(e-a)/(o-a),0,1))*(n-t)}function IQ(e,t,n,r){let i=e+t;return{bandTop:i-r/100*t,bandBottom:i-n/100*t}}function LQ(e){return e.replace(/__(\d+|ref)$/,``)}function RQ(e,t,n){let r=Math.floor((n-t-TQ)/kQ)+1;return Math.max(0,Math.min(e,r))}function zQ(e){let t=0;for(let n of e)t+=n.length;return t}function BQ(e,t){let n=e.cols.get(t);return n?new Float32Array(n):new Float32Array(e.length).fill(NaN)}function VQ(e){let t=new Map;for(let n of e){let e=LQ(n.column),r=t.get(e)??[];r.push(n),t.set(e,r)}let n=new Set,r=[];for(let i of e){let e=LQ(i.column);if(n.has(e))continue;n.add(e);let a=t.get(e);r.push({base:e,leader:a[0],members:a})}return r}function HQ(e,t,n){let r=new Map,i=e.map((e,r)=>{let{bandTop:i}=IQ(t,n,e.leader.bandFromPct,e.leader.bandToPct);return{g:e,i:r,bandTop:i,blockDY:e.members.length>1?TQ+(e.members.length+1)*kQ:DQ}});i.sort((e,t)=>e.bandTop-t.bandTop||e.i-t.i);let a=-1/0;for(let{g:e,bandTop:t,blockDY:n}of i){let i=t+TQ,o=Math.max(i,a),s=o-TQ;r.set(e.leader.id,s),a=o+n}return r}function UQ(e,t){let n=e.cols.get(t);if(!n)return 0;let r=e.x;return n.length===e.length&&XG.has(n)?WQ(r,e.length):KQ(r,e.length,e=>Number.isFinite(n[e]))}function WQ(e,t){let n=GQ.get(e);return n===void 0&&(n=KQ(e,t,()=>!0),GQ.set(e,n)),n}var GQ=OE(new WeakMap);function KQ(e,t,n){let r=null,i=0,a=0;for(let o=0;o<t;o++)n(o)&&(r!==null&&e[o]!==r&&(i+=Math.abs(e[o]-r),a++),r=e[o]);return a===0?0:i/a}function qQ(e,t){return e>0?Math.max(e*4,t*1e-9):Math.max(t*1e-6,1e-12)}var JQ=1e30,YQ=250;function XQ({xLabel:e,series:t,points:n,columnUnits:r={},height:i=440,onPlotContextMenu:a,backgroundToken:o=``,viewXRange:s=null,onViewXRangeChange:c,liveZoom:l,liveZoomId:u,fullXRange:d=null,shiftMode:f,xAxisLine:p,yAxisLine:m,gridLine:h,lineWidth:g=1,envelopes:_,showLatestValues:v=!1,liveSource:y,liveWindowSeconds:b=null,onLiveWindowChange:x,liveZoomMode:S,onPlotWidthCss:C,onCursorX:w}){let T=iQ(),E=(0,Z.useRef)(null),D=(0,Z.useRef)(null),O=(0,Z.useRef)(null),k=(0,Z.useRef)(null),A=(0,Z.useRef)(null),j=(0,Z.useRef)(C);j.current=C;let M=(0,Z.useRef)(-1),N=(0,Z.useRef)(null),P=(0,Z.useRef)(!1),F=(0,Z.useRef)(null),I=(0,Z.useRef)(!1),L=(0,Z.useRef)(!1),R=(0,Z.useRef)(null),z=(0,Z.useRef)(null),B=(0,Z.useRef)({pts:null,layers:[]}),V=(0,Z.useRef)(new Map),ee=(0,Z.useRef)([]),H=(0,Z.useRef)(null),U=(0,Z.useRef)(null),te=(0,Z.useRef)(null),W=(0,Z.useRef)(null),ne=(0,Z.useRef)(null),G=(0,Z.useRef)(0),re=(0,Z.useRef)(0),ie=(0,Z.useRef)(!1),ae=(0,Z.useRef)(0),oe=(0,Z.useRef)(xQ),se=(0,Z.useRef)(y),ce=(0,Z.useRef)(null),le=(0,Z.useRef)(MZ()),ue=(0,Z.useRef)(0),de=(0,Z.useRef)(void 0),fe=(0,Z.useRef)(0),pe=(0,Z.useRef)(0),me=(0,Z.useRef)(16),he=(0,Z.useRef)(!0),ge=(0,Z.useRef)(!1),[_e,ve]=(0,Z.useState)(0),ye=()=>pZ(A.current);function be(){F.current?.dispose(),F.current=null,L.current=!1,I.current=!1,ee.current=[],ve(e=>e+1)}(0,Z.useEffect)(()=>{_e&&xt()},[_e]),(0,Z.useLayoutEffect)(()=>{se.current=y,ce.current=null,B.current={pts:null,layers:[]},V.current.clear()},[y]);let xe=(0,Z.useRef)(b);(0,Z.useLayoutEffect)(()=>{xe.current=b},[b]);let Se=(0,Z.useRef)(x);Se.current=x;let Ce=S??(x?`follow`:`free`),we=(0,Z.useRef)(Ce);we.current=Ce;let Te=(0,Z.useRef)(null);(0,Z.useLayoutEffect)(()=>{Te.current=null},[Ce,e]);let Ee=(0,Z.useRef)([]),De=(0,Z.useRef)(!1),Oe=(0,Z.useRef)(0),ke=(0,Z.useRef)(0),Ae=(0,Z.useRef)(0),je=(0,Z.useRef)(0),Me=(0,Z.useRef)(`none`),Ne=(0,Z.useRef)(0),Pe=(0,Z.useRef)(0),Fe=(0,Z.useRef)(0),Ie=(0,Z.useRef)(null),Le=(0,Z.useRef)(null),Re=(0,Z.useRef)(0);function ze(e){let t=vQ(e);return Re.current>0?{...t,left:t.left+Re.current}:t}let Be=(0,Z.useRef)(f),Ve=(0,Z.useRef)(null),He=(0,Z.useRef)({pts:null,x0:NaN,x1:NaN,ser:null}),Ue=(0,Z.useRef)(0),We=(0,Z.useRef)(0),Ge=(0,Z.useRef)(null),Ke=(0,Z.useRef)(null),qe=(0,Z.useRef)(null),Je=(0,Z.useRef)(null);(0,Z.useLayoutEffect)(()=>{Be.current=f},[f]),(0,Z.useEffect)(()=>(R.current&&=(clearTimeout(R.current),null),()=>{N.current?.dispose(),N.current=null;let e=F.current;e&&(R.current=setTimeout(()=>{e.dispose(),F.current===e&&(F.current=null),R.current=null},0))}),[]);let Ye=(0,Z.useSyncExternalStore)(ZJ,XJ),Xe=(0,Z.useRef)({xLabel:e,series:t,points:n,height:i,columnUnits:r,shiftMode:f,xAxisLine:p,yAxisLine:m,gridLine:h,lineWidth:g,showLatestValues:v,envelopes:_}),Ze=(0,Z.useRef)(null),Qe=(0,Z.useRef)(null);(0,Z.useLayoutEffect)(()=>{Xe.current={xLabel:e,series:t,points:n,height:i,columnUnits:r,shiftMode:f,xAxisLine:p,yAxisLine:m,gridLine:h,lineWidth:g,showLatestValues:v,envelopes:_}},[e,t,n,i,r,f,p,m,h,g,v,_]);let $e=(0,Z.useRef)(c),et=(0,Z.useRef)(w);et.current=w,(0,Z.useLayoutEffect)(()=>{$e.current=c},[c]);let tt=(0,Z.useRef)(l),nt=(0,Z.useRef)(u);(0,Z.useLayoutEffect)(()=>{tt.current=l,nt.current=u},[l,u]),(0,Z.useEffect)(()=>{if(!(!l||!u))return l.subscribe((e,t)=>{e!==u&&(H.current=t?.[0]??null,U.current=t?.[1]??null,xt())})},[l,u]);let rt=(0,Z.useRef)(a);(0,Z.useLayoutEffect)(()=>{rt.current=a},[a]);let it=(0,Z.useMemo)(()=>{if(d&&d[1]>d[0])return{xmin:d[0],xmax:d[1]};let e=1/0,t=-1/0;for(let r of n)for(let n=0;n<r.length;n++){let i=r.x[n];i<e&&(e=i),i>t&&(t=i)}return(!Number.isFinite(e)||e===t)&&(--e,t+=1),{xmin:e,xmax:t}},[n,d]),at=(0,Z.useRef)(it);(0,Z.useLayoutEffect)(()=>{at.current=it},[it]);function ot(){return se.current!=null&&H.current===null&&U.current===null&&!De.current&&Ve.current===null}function st(){let{xmin:e,xmax:t}=at.current,n=H.current,r=U.current;if(n!==null&&r!==null&&r>n&&Number.isFinite(n)&&Number.isFinite(r))return{xmin:n,xmax:r};let i=te.current,a=W.current;return ot()&&i!==null&&a!==null&&a>i&&Number.isFinite(i)&&Number.isFinite(a)?{xmin:i,xmax:a}:{xmin:e,xmax:t}}function ct(e,t){let n=se.current;if(!n?.latestValues)return TZ(e,t);let r=n.latestValues(t),i=t.filter(e=>!r.has(e)),a=n.latestX?.();if(i.length>0&&a!=null)for(let[t,n]of wZ(e,i,a))r.set(t,n);return r}function lt(){return se.current?Ee.current:Xe.current.points}function ut(e,t,n){let r=new Map;for(let i of t)r.set(i,qQ(ht(e,i),n));return r}function dt(e){if(B.current.pts===e)return B.current.layers;let t=B.current.layers,n=se.current?.version?.(),r=e.map((e,r)=>({pts:e,key:t[r]?.pts===e?t[r].key:n??e}));return B.current={pts:e,layers:r},r}function ft(e,t){let n=V.current.get(e),r=performance.now(),i=n&&(n.key===t.key||typeof t.key==`number`&&typeof n.key==`number`&&r-n.at<YQ);return(!n||!i)&&(n={key:t.key,at:r,has:new Map,median:new Map},V.current.set(e,n)),n}function pt(e,t,n){let r=ft(e,t),i=r.has.get(n);if(i===void 0){let e=t.pts.cols.get(n);i=!!e&&e.some(Number.isFinite),r.has.set(n,i)}return i}function mt(e,t){return dt(e).some((e,n)=>pt(n,e,t))}function ht(e,t){let n=dt(e);for(let e=0;e<n.length;e++){if(!pt(e,n[e],t))continue;let r=ft(e,n[e]),i=r.median.get(t);return i===void 0&&(i=UQ(n[e].pts,t),r.median.set(t,i)),i}return 0}function gt(){if(Je.current)return Je.current;let e=A.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return Je.current=n,n}function _t(){let e=A.current,t=Math.max(1,e?.clientWidth||200),n=e?.clientHeight??0;return{w:t,h:Math.max(1,n>0?n:Xe.current.height)}}function vt(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function yt(){let e=E.current;if(!e)return;let{w:t,h:n}=_t(),r=vt(e,t,n);if(!r)return;{let e=lt(),t=st(),n=Xe.current.series,r=He.current;(r.pts!==e||r.x0!==t.xmin||r.x1!==t.xmax||r.ser!==n)&&(He.current={pts:e,x0:t.xmin,x1:t.xmax,ser:n},lZ(A.current))}let i=vQ(t),a=i===gQ,{top:o,right:s,bottom:c}=i,l=i.left,u=t-l-s,d=n-o-c,{bg:f,muted:p,grid:m}=gt(),{xLabel:h,series:g,xAxisLine:_,yAxisLine:v,gridLine:y,lineWidth:b,columnUnits:x,showLatestValues:S}=Xe.current,C=lt();if(r.fillStyle=f,r.fillRect(0,0,t,n),zQ(C)<2||u<=0||d<=0){if(r.fillStyle=p,r.font=`13px ${X.sans}`,eX(r),N.current&&(N.current.resize(t,n,window.devicePixelRatio||1),N.current.draw([])),F.current){F.current.resize(t,n,window.devicePixelRatio||1);for(let e=0;e<ee.current.length;e++)F.current.clear(e);ee.current=[]}return}let{xmin:w,xmax:k}=st(),j=k-w,M=e=>l+(e-w)/j*u,z=g.filter(e=>e.bandToPct>e.bandFromPct&&e.scaleMin!==e.scaleMax&&mt(C,e.column)),B=VQ(z),V=HQ(B,o,d),H=new Map;for(let e of B){let t=V.get(e.leader.id);t!==void 0&&e.members.forEach(e=>H.set(e.id,t))}let U=new Set,te=new Set;for(let e of B)e.members.length>1&&e.members.forEach(e=>U.add(e.id)),te.add(e.leader.id);let W=`11px ${X.mono}`,ne=z.map(e=>{let{bandTop:t,bandBottom:n}=IQ(o,d,e.bandFromPct,e.bandToPct),r=Math.min(e.scaleMin,e.scaleMax),i=Math.max(e.scaleMin,e.scaleMax),{majorStep:a,minorStep:s}=PJ(e.scaleMin,e.scaleMax,e.yMajorStep??0,e.yMinorStep??0),c=a,l=FJ(r,i,c);l.length>120&&(l=FJ(r,i,c=PJ(e.scaleMin,e.scaleMax,0,0).majorStep));let u=IJ(r,i,s,l);return u.length>400&&(u=[]),{s:e,bandTop:t,bandBottom:n,majors:l,minors:u,step:c}}),G=new Map,re=0;{r.save(),r.font=W;let e=ne.filter(e=>te.has(e.s.id));e.sort((e,t)=>{let n=Math.abs(e.s.bandToPct-e.s.bandFromPct),r=Math.abs(t.s.bandToPct-t.s.bandFromPct);return n===r?ne.indexOf(e)-ne.indexOf(t):r-n});let n=new Map,a=[];for(let t of e){let r=0;for(;r<e.length;r++){let e=a[r];if(!e||e.length===0||!e.some(e=>t.bandTop<e.bandBottom&&t.bandBottom>e.bandTop))break}n.set(t.s.id,r),a[r]||(a[r]=[]),a[r].push(t)}let o=new Map,c=new Map;for(let t of e){let e=0;for(let n of t.majors){let i=zJ(n,t.step),a=c.get(i);a===void 0&&c.set(i,a=r.measureText(i).width),a>e&&(e=a)}o.set(t.s.id,e)}let u=[],d=[],f=0;for(let e=0;e<a.length;e++){u[e]=f;let t=0;for(let n of a[e]??[]){let e=o.get(n.s.id)??0;e>t&&(t=e)}d[e]=t,f+=t+22}for(let e of ne){let t=n.get(e.s.id)??0;G.set(e.s.id,u[t]??0)}let p=i.left;for(let e=0;e<a.length;e++){let t=a[e];if(!t||t.length===0)continue;let n=(u[e]??0)+NQ+MQ+(d[e]??0)+6;n>p&&(p=n)}let m=Math.max(i.left,t-s-Math.max(120,t*.4)),h=Math.min(Math.ceil(p),m);h>l&&(re=h-l),r.restore()}re>0&&(l+=re,u=Math.max(1,t-l-s)),Re.current=re,T({left:l,top:o,width:u,height:d,x:{v0:w,v1:k}}),oe.current=kZ(u,window.devicePixelRatio||1);let ie=(e,t)=>1-(1-e)**t,ae=new Map,se=new Map;for(let e of ne){let t=`${e.bandTop}|${e.bandBottom}|${e.s.scaleMin}|${e.s.scaleMax}|${e.majors.join(`,`)}`,n=ae.get(t);n?n.k++:ae.set(t,{c:e,k:1});let r=U.has(e.s.id)?p:e.s.color,i=`${e.bandTop}|${e.bandBottom}|${r}`,a=se.get(i);a?a.k++:se.set(i,{c:e,color:r,k:1})}if((v?.style??`dashed`)!==`none`)for(let{c:{s:e,bandTop:t,bandBottom:n,majors:i},k:a}of ae.values()){r.save(),r.strokeStyle=v?.color??m,r.globalAlpha=ie(.1,a),r.lineWidth=v?.width??1,r.lineCap=`round`,r.setLineDash(fQ(v?.style??`dashed`));for(let a of i){let i=FQ(a,t,n,e.scaleMin,e.scaleMax);r.beginPath(),r.moveTo(l,i),r.lineTo(l+u,i),r.stroke()}r.restore()}for(let{c:{bandTop:e,bandBottom:t},color:n,k:i}of se.values())r.strokeStyle=n,r.lineWidth=1,r.setLineDash([]),r.globalAlpha=ie(.45,i),r.beginPath(),r.moveTo(l,e),r.lineTo(l,t),r.stroke(),r.globalAlpha=1;for(let{s:e,bandTop:t,bandBottom:n,majors:i,minors:o,step:s}of a?[]:ne){let a=U.has(e.id)?p:e.color;if(te.has(e.id)){let c=G.get(e.id)??0,u=l-c-NQ;r.strokeStyle=a,r.lineWidth=1;for(let i of o){let a=FQ(i,t,n,e.scaleMin,e.scaleMax);r.beginPath(),r.moveTo(u-jQ,a),r.lineTo(u,a),r.stroke()}r.font=W,r.textAlign=`right`,r.textBaseline=`middle`,r.strokeStyle=a,r.fillStyle=a;for(let a of i){let i=FQ(a,t,n,e.scaleMin,e.scaleMax);r.beginPath(),r.moveTo(u-AQ,i),r.lineTo(u,i),r.stroke(),r.fillText(zJ(a,s),u-MQ,i)}}}if((y?.style??`solid`)!==`none`&&(r.strokeStyle=y?.color??m,r.lineWidth=y?.width??1,r.setLineDash(fQ(y?.style??`solid`)),r.strokeRect(l,o,u,d),r.setLineDash([])),(_?.style??`dashed`)!==`none`){r.strokeStyle=_?.color??m,r.lineWidth=_?.width??1,r.setLineDash(fQ(_?.style??`dashed`));for(let e=1;e<6;e++){let t=l+e/6*u;r.beginPath(),r.moveTo(t,o),r.lineTo(t,o+d),r.stroke()}r.setLineDash([])}let ce=o+d+10;r.fillStyle=p,r.font=`11px ${X.mono}`,r.textAlign=`center`,r.textBaseline=`top`;let le=UJ(h,w,w+j);for(let e=0;e<=(a?-1:6);e++){let t=w+e/6*j;r.fillText(le?QJ(t,j/6,j):zJ(t,j/6),l+e/6*u,ce)}r.textBaseline=`bottom`,a||r.fillText(h,l+u/2,n-5);let{shiftMode:ue}=Xe.current;ue&&(r.globalAlpha=.8,r.font=`10px ${X.sans}`,r.fillStyle=p,r.textAlign=`center`,r.textBaseline=`top`,r.fillText(`⇄ shifting: ${ue.label}`,l+u/2,o+3),r.globalAlpha=1);let fe=Xe.current.envelopes;if(fe?.length){r.save(),r.beginPath(),r.rect(l,o,u,d),r.clip();for(let e of fe){let t=z.find(t=>t.id===e.seriesId||t.id.startsWith(`${e.seriesId}__`));if(!t)continue;let{bandTop:n,bandBottom:i}=IQ(o,d,t.bandFromPct,t.bandToPct),a=e=>FQ(e,n,i,t.scaleMin,t.scaleMax);r.fillStyle=e.color,r.globalAlpha=.2;let s=0;for(;s<e.x.length;){for(;s<e.x.length&&e.lo[s]!==e.lo[s];)s++;let t=s;for(;s<e.x.length&&e.lo[s]===e.lo[s];)s++;if(!(s-t<2)){r.beginPath(),r.moveTo(M(e.x[t]),a(e.hi[t]));for(let n=t+1;n<s;n++)r.lineTo(M(e.x[n]),a(e.hi[n]));for(let n=s-1;n>=t;n--)r.lineTo(M(e.x[n]),a(e.lo[n]));r.closePath(),r.fill()}}}r.restore()}R.current&&=(clearTimeout(R.current),null);let pe=uQ&&!I.current?F.current:null;if(uQ&&!pe&&!I.current&&D.current&&!L.current&&(pe=YX()&&EX()?ZX(D.current,1,be,{hidden:ye,evict:be},O.current??void 0):QX(D.current),pe?(F.current=pe,L.current=!0):I.current=!0),pe){pe.resize(t,n,window.devicePixelRatio||1);let e=`${l.toFixed(2)}|${u.toFixed(2)}|${o}|${d}|${b}|`+z.map(e=>`${e.id}:${e.column}:${e.bandFromPct}:${e.bandToPct}:${e.scaleMin}:${e.scaleMax}:${e.color}`).join(`,`),r=dt(C),i=ee.current;for(let t=0;t<Math.max(r.length,i.length);t++){let n=r[t];if(!n){i[t]&&pe.clear(t),i[t]=null;continue}let a=z.filter(e=>pt(t,n,e.column)),s=a.map(e=>e.column).join(`
|
|
227
|
+
`),c=i[t];if(c&&c.pts===n.pts&&c.sig===e&&c.cols===s)continue;i[t]={pts:n.pts,sig:e,cols:s};let f={styles:a.map(e=>{let{bandTop:t,bandBottom:r}=IQ(o,d,e.bandFromPct,e.bandToPct);return{color:hX(e.color),bandTop:t,bandBottom:r,scaleMin:e.scaleMin,scaleMax:e.scaleMax,gapMedian:n.pts.hold?JQ:ht(C,e.column),width:b}}),left:l,plotW:u,xmin:w,xmax:k,cut:de.current};if(c&&c.pts===n.pts&&c.cols===s){pe.setStyle(t,f);continue}let p=n.pts,m=!!c&&c.pts.x===p.x&&c.pts.brk===p.brk&&c.cols===s;pe.setData(t,{...f,xs:m?null:p.x.slice(),breaks:m?void 0:p.brk?.slice(),columns:a.map(e=>BQ(p,e.column))})}i.length=r.length,pe.setView(w,k,de.current)}else{let e=N.current;lQ&&!e&&!P.current&&D.current&&!L.current&&(e=xX(D.current),e?N.current=e:P.current=!0);let i=!!e;i&&e&&e.resize(t,n,window.devicePixelRatio||1);let a=[],s=ut(C,z.map(e=>e.column),j);for(let e of z){let{bandTop:t,bandBottom:n}=IQ(o,d,e.bandFromPct,e.bandToPct),c=s.get(e.column);if(i){let r={x:l,y:t,w:u,h:n-t},i=hX(e.color),o=[],s=null,d=()=>{o.length>=4&&a.push({points:Float32Array.from(o),color:i,clip:r,width:b}),o=[]};for(let r of C){let i=r.cols.get(e.column);if(i){s=null;for(let a=0;a<r.length;a++){r.brk?.[a]&&d();let l=i[a];if(!Number.isFinite(l))continue;let u=r.x[a];s!==null&&!r.hold&&Math.abs(u-s)>c&&d(),o.push(M(u),FQ(l,t,n,e.scaleMin,e.scaleMax)),s=u}d()}}d();continue}r.strokeStyle=e.color,r.lineWidth=b,r.lineJoin=`round`,r.lineCap=`round`,r.save(),r.beginPath(),r.rect(l,t,u,n-t),r.clip(),r.beginPath();let f=!1,p=null,m=!1;for(let i of C){let a=i.cols.get(e.column);if(a){m=!0;for(let o=0;o<i.length;o++){i.brk?.[o]&&(m=!0);let s=a[o];if(!Number.isFinite(s))continue;let l=i.x[o],u=M(l),d=FQ(s,t,n,e.scaleMin,e.scaleMax);f?m||p!==null&&!i.hold&&Math.abs(l-p)>c?(r.stroke(),r.beginPath(),r.moveTo(u,d),p=l,m=!1):(r.lineTo(u,d),p=l):(r.moveTo(u,d),f=!0,p=l,m=!1)}}}f&&r.stroke(),r.restore()}i&&e&&e.draw(a)}for(let e of z){if(!e.alarm)continue;let{bandTop:t,bandBottom:n}=IQ(o,d,e.bandFromPct,e.bandToPct),i=FQ(e.alarm.value,t,n,e.scaleMin,e.scaleMax);r.save(),r.beginPath(),r.rect(l,t,u,n-t),r.clip(),r.strokeStyle=e.alarm.color,r.lineWidth=e.alarm.width,r.setLineDash(e.alarm.linked===`active`?oQ:fQ(e.alarm.style)),r.beginPath(),r.moveTo(l,i),r.lineTo(l+u,i),r.stroke(),r.setLineDash([]),e.alarm.linked&&cQ(r,l+u-10-3,i-10-2,e.alarm.color),r.restore()}if(a)return;let me=S?ct(C,z.map(e=>e.column)):null,he=e=>{let t=me?.get(e.column);if(typeof t!=`number`)return`-`;let n=x[e.column]?.trim()??``;return`${BJ(t)}${n?` ${n}`:``}`},ge=l+u+8;r.font=wQ,r.textAlign=`left`;for(let e of B){let t=V.get(e.leader.id);if(t===void 0)continue;let i=e.members.length>1;if(r.fillStyle=i?p:e.leader.color,r.globalAlpha=1,r.fillText(e.base,ge,t+TQ),i){let i=RQ(e.members.length,t,n);for(let n=0;n<i;n++)r.fillStyle=e.members[n].color,r.globalAlpha=OQ,r.fillText(he(e.members[n]),ge,t+TQ+(n+1)*kQ)}else r.fillStyle=e.leader.color,r.globalAlpha=OQ,r.fillText(he(e.leader),ge,t+EQ);r.globalAlpha=1}}function bt(){let e=k.current;if(!e)return;let{w:t,h:n}=_t(),r=vt(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let{top:i,right:a,bottom:o,left:s}=ze(t),c=t-s-a,l=n-i-o,{series:u,columnUnits:d,xLabel:f}=Xe.current,p=lt();if(De.current&&c>0&&l>0){let e=Oe.current,t=ke.current,n=Ae.current,i=je.current,a=Math.min(e,n),o=Math.min(t,i),s=Math.abs(n-e),c=Math.abs(i-t);r.fillStyle=`rgba(59, 130, 246, 0.12)`,r.fillRect(a,o,s,c),r.strokeStyle=`rgba(59, 130, 246, 0.85)`,r.setLineDash([4,3]),r.lineWidth=1,r.strokeRect(a,o,s,c),r.setLineDash([])}let m=z.current;if(m===null||zQ(p)<2||c<=0||l<=0)return;let{xmin:h,xmax:g}=st(),_=u.filter(e=>e.bandToPct>e.bandFromPct&&e.scaleMin!==e.scaleMax&&mt(p,e.column)),v=[...new Set(_.map(e=>e.column))],y=ut(p,v,g-h),{bg:b,muted:x}=gt();r.strokeStyle=x,r.globalAlpha=.5,r.lineWidth=1,r.beginPath(),r.moveTo(m,i),r.lineTo(m,i+l),r.stroke(),r.globalAlpha=1;let S=VQ(_),C=HQ(S,i,l),w=s+c+8;r.font=wQ,r.textAlign=`left`;let T=SZ(m,s,c,h,g),E=CZ(p,T,v,y),D=e=>{let t=E.get(e.column);if(typeof t!=`number`)return`-`;let n=d[e.column]?.trim()??``;return`${BJ(t)}${n?` ${n}`:``}`};for(let e of S){let t=C.get(e.leader.id)??IQ(i,l,e.leader.bandFromPct,e.leader.bandToPct).bandTop;if(e.members.length>1){let i=e.members.length*kQ+4;r.fillStyle=b,r.fillRect(s+c+6,t+TQ+2,a-8,i);let o=RQ(e.members.length,t,n);for(let n=0;n<o;n++){let i=e.members[n];r.fillStyle=i.color,r.globalAlpha=OQ,r.fillText(D(i),w,t+TQ+(n+1)*kQ)}}else{let n=e.leader;r.fillStyle=b,r.fillRect(s+c+6,t+TQ+2,a-8,EQ-TQ+6),r.fillStyle=n.color,r.globalAlpha=OQ,r.fillText(D(n),w,t+EQ)}r.globalAlpha=1}let O=/^(.*?)\s*\(([^)]*)\)\s*$/.exec(f),A=O?O[1]:f,j=O?O[2].trim():``,M=UJ(f,h,g)?$J(T):``,N=M.lastIndexOf(` `),P=M?[`${A} ${M.slice(0,N)}`,M.slice(N+1)]:[`${A} ${Math.round(T)}${j}`];r.font=wQ,r.textAlign=`left`,r.textBaseline=`alphabetic`,P.forEach((e,t)=>{let n=r.measureText(e).width,a=i+l-(P.length-1-t)*15;r.fillStyle=b,r.fillRect(w-2,a-11,n+6,15),r.fillStyle=x,r.globalAlpha=1,r.fillText(e,w,a)})}function xt(){if(se.current){ie.current=!0;return}Ge.current=()=>{yt(),bt()},!Ue.current&&(Ue.current=oZ(e=>{Ue.current=0,!ye()&&(Ke.current=e,Ge.current?.())}))}function St(){if(se.current){ie.current=!0;return}let e=A.current?.ownerDocument.timeline?.currentTime;if(typeof e!=`number`||e===Ke.current){xt();return}Ke.current=e,sZ(Ue.current),Ue.current=0,yt(),bt()}function Ct(){qe.current=bt,!We.current&&(We.current=oZ(()=>{We.current=0,qe.current?.()}))}function wt(e){G.current=oZ(wt);let t=se.current;if(!t)return;me.current+=(Math.min(50,pe.current?e-pe.current:16)-me.current)*.1,pe.current=e;let n=A.current;if(!(he.current&&!pZ(n))){if(!ge.current){ge.current=!0;let e=F.current;e&&(ee.current.forEach((t,n)=>{t&&e.clear(n)}),ee.current=[],e.resize(1,1,1))}return}if(ge.current&&(ge.current=!1,F.current&&!F.current.own&&YX()&&EX())){be();return}if(fe.current&&e-fe.current<CQ-me.current/2||!yZ(e,fe.current||-1/0))return;fe.current=e;let r=performance.now(),i=t.xBounds();i&&i[1]>i[0]&&(at.current={xmin:i[0],xmax:i[1]});let a=ue.current?e-ue.current:16;ue.current=e,a>250&&(te.current=null,W.current=null);let o=t.latestT?.(),s,c;if(o!==void 0&&t.xAtTime&&Number.isFinite(o)){let e=t.id?PZ(t.id,o,performance.now(),t.timeAfter):JZ(le.current,o,a,t.timeAfter),n=t.id?zZ(t.id):IZ(le.current),r=BZ(t.xAtTime,e,n);Number.isFinite(r)&&(s=r);let i=BZ(t.xAtTime,e,n-(t.id?RZ(t.id):LZ(le.current)));Number.isFinite(i)&&(c=i)}if(ot()){let n=s??t.latestX?.()??at.current.xmax,r=xe.current,i=r!=null&&t.spanForSeconds?t.spanForSeconds(r):r??Te.current,[a,o]=OZ(at.current.xmin,at.current.xmax,i,n??void 0);if(!t.spanForSeconds&&s!==void 0&&s>a&&(o=s),Number.isFinite(a)&&Number.isFinite(o)&&o>a){let t=o-a,n=W.current!==null&&o<W.current-t;if(te.current===null||W.current===null||n)te.current=a,W.current=o,re.current=e;else{let n=re.current;re.current=e;let r=ne.current,i=EZ(n?Math.min(64,e-n):16,yQ);te.current=DZ(te.current,a,r?r[0]:null,i,t,bQ),W.current=DZ(W.current,o,r?r[1]:null,i,t,bQ),Math.abs(a-te.current)<t*1e-6&&(te.current=a),Math.abs(o-W.current)<t*1e-6&&(W.current=o)}ne.current=[a,o]}}else te.current=null,W.current=null,re.current=0;let l=st(),u=t.version?.(),d=oe.current,f=ce.current,p=f!==null&&u!==void 0&&f.ver===u&&f.x0===l.xmin&&f.x1===l.xmax&&f.mp===d&&f.cut===c;(zQ(Ee.current)===0||!p&&e-ae.current>=SQ)&&(ae.current=e,de.current=t.cutOnGpu&&F.current?c:void 0,Ee.current=t.pull(l.xmin,l.xmax,d,c,de.current!==void 0),ce.current=u===void 0?null:{ver:u,x0:l.xmin,x1:l.xmax,mp:d,cut:c}),ie.current=!1,yt(),bt(),bZ(e,performance.now()-r)}function Tt(){G.current||=(re.current=0,oZ(wt))}function Et(){G.current&&(sZ(G.current),G.current=0,ue.current=0,te.current=null,W.current=null,Ee.current=[],de.current=void 0)}(0,Z.useEffect)(()=>{let e=A.current,t=e?.ownerDocument.defaultView?.IntersectionObserver;if(!e||!t)return;let n=new t(e=>{let t=e[e.length-1];(t.isIntersecting||t.boundingClientRect.width>0)&&(he.current=t.isIntersecting)});return n.observe(e),()=>{n.disconnect(),he.current=!0}},[]),(0,Z.useEffect)(()=>(y?Tt():(Et(),xt()),Et),[!!y]),(0,Z.useEffect)(()=>sY(A.current,()=>{Je.current=null,xt()}),[]),(0,Z.useEffect)(()=>{Je.current=null,xt()},[o]);let Dt=!!f;(0,Z.useEffect)(()=>{let e=k.current;e&&(e.style.cursor=Dt?`ew-resize`:``),xt()},[Dt,f?.label??``]);let Ot=s?.[0]??null,kt=s?.[1]??null;return(0,Z.useLayoutEffect)(()=>{H.current===Ot&&U.current===kt||(H.current=Ot,U.current=kt,xt())},[Ot,kt]),(0,Z.useEffect)(()=>{St()},[t,n,i,e,p,m,h,g,v,Ye]),(0,Z.useEffect)(()=>()=>{sZ(Ue.current),sZ(We.current),Ue.current=0,We.current=0},[]),(0,Z.useEffect)(()=>{let e=k.current,t=A.current;if(!e||!t)return;let n=()=>{let e=Math.round(t.clientWidth);e>0&&e!==M.current&&(M.current=e,j.current?.(e))};n();let r=new fZ(()=>{Je.current=null,n(),xt()});r.observe(t);let i=xZ(e=>et.current?.(e)),a=t=>{if(De.current||Ve.current!==null)return;if(zQ(lt())<2){z.current!==null&&(z.current=null,Ct(),i.set(null));return}let n=e.getBoundingClientRect(),r=t.clientX-n.left,a=t.clientY-n.top,{left:o,top:s,right:c,bottom:l}=ze(n.width),u=Math.max(1,n.width-o-c),d=n.height-s-l;if(r<o||r>o+u||a<s||a>s+d){z.current!==null&&(z.current=null,Ct(),i.set(null));return}z.current!==r&&(z.current=r,Ct());let{xmin:f,xmax:p}=st();i.set(SZ(r,o,u,f,p))},o=()=>{z.current!==null&&(z.current=null,Ct()),i.set(null)},s=e=>{Ze.current&&clearTimeout(Ze.current),Ze.current=setTimeout(()=>{Ze.current=null,$e.current?.(e)},dQ)},c=t=>{if(Me.current!==`none`||t.buttons&2||Date.now()-Fe.current<300||zQ(lt())<2)return;let n=e.getBoundingClientRect(),r=t.clientX-n.left,i=t.clientY-n.top,{top:a,left:o,right:c,bottom:l}=ze(n.width),u=Math.max(1,n.width-o-c),d=Math.max(1,n.height-a-l);if(r<o||r>o+u||i<a||i>a+d)return;t.preventDefault();let f=at.current,p=f.xmax-f.xmin;if(!(p>0))return;if(we.current===`follow`&&ot()&&!Se.current){Te.current=jZ(Te.current,p,t.deltaY<0,p*.001);return}if(we.current===`follow`&&ot()){let e=jZ(xe.current,se.current?.bufferedSeconds?.()??p,t.deltaY<0);xe.current=e,Qe.current&&clearTimeout(Qe.current),Qe.current=setTimeout(()=>{Qe.current=null,Se.current?.(e)},dQ);return}let m=H.current??f.xmin,h=(U.current??f.xmax)-m;if(!(h>0))return;let g=Date.now();g-Pe.current>300&&(Ie.current=H.current,Le.current=U.current),Pe.current=g;let _=m+(r-o)/u*h,v=t.deltaY<0,y=.88,b=v?h*y:h/y,x=Math.max(p*1e-7,1e-12);if(v)b=Math.max(b,x);else{if(b>=p*.999){H.current=null,U.current=null,s(null),tt.current?.publish(nt.current??``,null),xt();return}b=Math.min(b,p)}let S=(_-m)/h,C=_-S*b,w=_+(1-S)*b;C<f.xmin&&(w+=f.xmin-C,C=f.xmin),w>f.xmax&&(C-=w-f.xmax,w=f.xmax),w-C<b-1e-12&&(C=Math.max(f.xmin,_-b/2),w=C+b,w>f.xmax&&(w=f.xmax,C=w-b)),w-C>=p*.999?(H.current=null,U.current=null,s(null),tt.current?.publish(nt.current??``,null)):(H.current=C,U.current=w,s([C,w]),tt.current?.publish(nt.current??``,[C,w])),xt()},l=e=>{if(e.preventDefault(),Fe.current=Date.now(),Date.now()-Pe.current<300){H.current=Ie.current,U.current=Le.current;let e=Ie.current,t=Le.current;Ze.current&&=(clearTimeout(Ze.current),null),$e.current?.(e===null&&t===null?null:[e,t]),Pe.current=0,xt()}},u=t=>{if(t.button===0&&Be.current){let n=e.getBoundingClientRect(),{left:r,top:i,right:a,bottom:o}=ze(n.width),s=Math.max(1,n.width-r-a),c=n.height-i-o,l=t.clientX-n.left,u=t.clientY-n.top;if(l>=r&&l<=r+s&&u>=i&&u<=i+c){Ve.current=t.clientX,Be.current.onDragStart();try{e.setPointerCapture(t.pointerId)}catch{}}return}if(t.button!==2)return;if(t.preventDefault(),t.buttons===0){rt.current?.({clientX:t.clientX,clientY:t.clientY});return}if(Me.current!==`none`){De.current=!1,Me.current=`none`;try{e.releasePointerCapture(t.pointerId)}catch{}}let n=e.getBoundingClientRect(),r=t.clientX-n.left,i=t.clientY-n.top;Ne.current=Date.now(),Me.current=`menuOnly`,De.current=!1,Oe.current=r,ke.current=i,Ae.current=r,je.current=i;try{e.setPointerCapture(t.pointerId)}catch{}},d=t=>{if(Ve.current!==null){let n=t.clientX-Ve.current,r=e.getBoundingClientRect(),{left:i,right:a}=ze(r.width),o=Math.max(1,r.width-i-a),{xmin:s,xmax:c}=st(),l=c-s;l>0&&o>0&&Be.current?.onDragOffset(n/o*l);return}if(Me.current===`none`)return;let n=e.getBoundingClientRect(),r=t.clientX-n.left,i=t.clientY-n.top;if(Me.current===`menuOnly`){if(Date.now()-Ne.current<150)return;let e=r-Oe.current,t=i-ke.current;if(Math.sqrt(e*e+t*t)<12)return;let a=lt(),{top:o,left:s,right:c,bottom:l}=ze(n.width),u=n.width-s-c,d=n.height-o-l,f=u>0&&d>0&&Oe.current>=s&&Oe.current<=s+u&&ke.current>=o&&ke.current<=o+d;if(zQ(a)<2||!f)return;Me.current=`rubber`,De.current=!0,z.current=null}Me.current===`rubber`&&(t.preventDefault(),Ae.current=r,je.current=i,Ct())},f=t=>{if(t.button!==2)return;t.preventDefault();let n=Me.current;Me.current=`none`;try{e.releasePointerCapture(t.pointerId)}catch{}if(n===`menuOnly`){De.current=!1,Ct(),rt.current?.({clientX:t.clientX,clientY:t.clientY});return}if(n!==`rubber`||!De.current){De.current=!1,Ct();return}De.current=!1;let r=lt(),i=e.getBoundingClientRect(),{left:a,right:o}=ze(i.width),s=Math.max(1,i.width-a-o),c=Oe.current,l=Ae.current,u=Math.abs(l-c);if(zQ(r)<2||u<12){rt.current?.({clientX:t.clientX,clientY:t.clientY}),Ct();return}let d=PQ(Math.min(c,l),a,a+s),f=PQ(Math.max(c,l),a,a+s),{xmin:p,xmax:m}=st(),h=m-p;if(!(h>0)){rt.current?.({clientX:t.clientX,clientY:t.clientY}),Ct();return}let g=p+(d-a)/s*h,_=p+(f-a)/s*h;if(g>_){let e=g;g=_,_=e}let v=at.current,y=Math.min(v.xmin,v.xmax),b=Math.max(v.xmin,v.xmax);g=PQ(g,y,b),_=PQ(_,y,b);let x=_-g;if(x<=(b-y)*1e-12||x<=0){rt.current?.({clientX:t.clientX,clientY:t.clientY}),Ct();return}rt.current?.({clientX:t.clientX,clientY:t.clientY,zoomXRange:[g,_]}),Ct()},p=t=>{if(t.button===0&&Ve.current!==null){Ve.current=null;try{e.releasePointerCapture(t.pointerId)}catch{}return}if(t.button===2){f(t);return}if(t.buttons===0&&Me.current!==`none`){Me.current=`none`,De.current=!1;try{e.releasePointerCapture(t.pointerId)}catch{}rt.current?.({clientX:t.clientX,clientY:t.clientY}),Ct()}},m=t=>{Ve.current!==null&&(Ve.current=null),Me.current!==`none`&&(De.current=!1,Me.current=`none`);try{e.releasePointerCapture(t.pointerId)}catch{}Ct()},h=t=>{if(t.button!==0||zQ(lt())<2)return;let n=e.getBoundingClientRect(),r=t.clientX-n.left,i=t.clientY-n.top,{top:a,left:o,right:s,bottom:c}=ze(n.width),l=Math.max(1,n.width-o-s),u=Math.max(1,n.height-a-c);r<o||r>o+l||i<a||i>a+u||H.current===null&&U.current===null||(H.current=null,U.current=null,Ze.current&&=(clearTimeout(Ze.current),null),$e.current?.(null),tt.current?.publish(nt.current??``,null),xt(),Ct())},g=e=>{if(e.key!==`Escape`)return;let t=!1;Me.current!==`none`&&(Me.current=`none`,De.current=!1,t=!0),Ve.current!==null&&(Ve.current=null,t=!0),t&&Ct()};e.addEventListener(`mousemove`,a),e.addEventListener(`mouseleave`,o),e.addEventListener(`wheel`,c,{passive:!1}),e.addEventListener(`contextmenu`,l),e.addEventListener(`pointerdown`,u),e.addEventListener(`pointermove`,d),e.addEventListener(`pointerup`,p),e.addEventListener(`pointercancel`,m),e.addEventListener(`dblclick`,h);let _=e.ownerDocument.defaultView??window;return _.addEventListener(`keydown`,g),()=>{r.disconnect(),e.removeEventListener(`mousemove`,a),e.removeEventListener(`mouseleave`,o),e.removeEventListener(`wheel`,c),e.removeEventListener(`contextmenu`,l),e.removeEventListener(`pointerdown`,u),e.removeEventListener(`pointermove`,d),e.removeEventListener(`pointerup`,p),e.removeEventListener(`pointercancel`,m),e.removeEventListener(`dblclick`,h),_.removeEventListener(`keydown`,g),Ze.current&&clearTimeout(Ze.current),Qe.current&&clearTimeout(Qe.current)}},[]),(0,Q.jsxs)(`div`,{ref:A,className:`chart-canvas-wrap`,children:[(0,Q.jsx)(`canvas`,{ref:E,className:`chart-canvas`,role:`img`,"aria-label":`Chart of ${e}`}),(0,Q.jsx)(`canvas`,{ref:O,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),(0,Q.jsx)(`canvas`,{ref:D,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}},_e),(0,Q.jsx)(`canvas`,{ref:k,className:`chart-canvas chart-overlay`})]})}function ZQ(){try{if(localStorage.getItem(`perfLog`)===`1`)return!0;if(localStorage.getItem(`perfLog`)===`0`)return!1}catch{}return!1}var QQ=!1;function $Q(){let e=ZQ();return e&&!QQ&&(QQ=!0,console.log(`[perf] logging enabled — zoom an out-of-core chart to see decimate()/sampleRows timings`)),e}$Q();var e$=new Map;function t$(e,t){let n=(e$.get(e)??0)+1;e$.set(e,n),console.log(`[perf] ${e} #${n} ${t.toFixed(1)}ms`)}async function n$(e,t){if(!$Q())return t();let n=performance.now();try{return await t()}finally{t$(e,performance.now()-n)}}QG();var r$=20;async function i$(e,t,n,r){let{x0:i,bucket:a,rows:o,columns:s}=await n$(`decimate(${t.length}col)`,()=>e.getSeriesMulti(t,n,r));return VG(o,s,i,a)}function a$(e,t,n,r,i=0,a=!1,o=0){let[s,c]=(0,Z.useState)({points:ZG,fetchedViewport:null}),[l,u]=(0,Z.useState)(!1),d=`${t.join(`,`)}|${n?`${n.xKey}:${n.x0}:${n.x1}`:`none`}|${r}|${i}`,f=(0,Z.useMemo)(()=>{if(!a||!e?.getSeriesMultiSync||!n||t.length===0)return null;let i=o>0?e.getColumnsSync?.(t,n,o):null;if(i)return{points:i,loading:!1,fetchedViewport:n,full:!0};let s=e.getSeriesMultiSync(t,n,r);return{points:VG(s.rows,s.columns,s.x0,s.bucket),loading:!1,fetchedViewport:n}},[a,e,d,o]);return(0,Z.useEffect)(()=>{if(a)return;if(!e||!n||t.length===0){c({points:ZG,fetchedViewport:null});return}let i=!0;u(!0);let o=setTimeout(()=>{i$(e,t,n,r).then(t=>{i&&(c({points:t,fetchedViewport:n,source:e}),u(!1))}).catch(()=>{i&&u(!1)})},r$);return()=>{i=!1,clearTimeout(o)}},[e,d,a]),f||(s.source!==void 0&&s.source!==e?{points:ZG,loading:l,fetchedViewport:null}:{points:s.points,loading:l,fetchedViewport:s.fetchedViewport})}QG();var o$=250,s$=2,c$=6e3,l$=2e6,u$=[];function d$(e,t,n,r,i,a){let o=!!e&&e.columnSet.has(n),s=(0,Z.useMemo)(()=>e&&o?t.filter(t=>e.columnSet.has(t)):u$,[e,o,t]),c=e&&o&&s.length>0?e.source:null,l=!!c&&!e?.live&&!!c.getSeriesMultiSync&&!!c.xBoundsSync,u=(0,Z.useMemo)(()=>l&&c?c.xBoundsSync(n):null,[l,c,n]),[d,f]=(0,Z.useState)(null),p=!!e?.live;(0,Z.useEffect)(()=>{if(!c||l)return;let e=!0,t=()=>c.xBounds(n).then(t=>{let r=c.version?.()??0;e&&f(e=>e&&e.source===c&&e.xKey===n&&e.ver===r?e:{source:c,xKey:n,b:t,ver:r})}).catch(()=>{});t();let r=p?setInterval(t,o$):void 0;return()=>{e=!1,clearInterval(r)}},[c,n,p,l]);let m=d&&d.source===c&&d.xKey===n?d:null,h=u??m?.b??null,g=m?.ver??0,{points:_,loading:v,full:y}=a$(c,s,c&&h&&h.x1>h.x0?{xKey:n,x0:h.x0,x1:h.x1}:null,Math.min(c$,i*s$),g,l,a),b=e?.xOffset??0,x=r&&r[1]>r[0]?r[0]-b:null,S=r&&r[1]>r[0]?r[1]-b:null,C=y||!!h&&x!==null&&S!==null&&x<=h.x0&&S>=h.x1,{points:w,fetchedViewport:T}=a$(c,s,c&&x!==null&&S!==null&&!C?{xKey:n,x0:x,x1:S}:null,i,g,l,a),E=(0,Z.useMemo)(()=>!T||w.length===0?_:YG([KG(_,e=>e<T.x0),w,KG(_,e=>e>T.x1)]),[_,w,T]),D=!!c&&(h===null||v);return(0,Z.useMemo)(()=>e?{points:JG(E,e.keySuffix,e.xOffset),bounds:h?{x0:h.x0+e.xOffset,x1:h.x1+e.xOffset}:null,loading:D}:{points:ZG,bounds:null,loading:!1},[e,E,h,D])}var f$=new WeakMap,p$=0;function m$(e){if(e.key!==void 0)return e.key;let t=f$.get(e.source);return t===void 0&&f$.set(e.source,t=p$++),`${t}${e.keySuffix}`}function h$(){let[e,t]=(0,Z.useState)(()=>new Map);return[e,(0,Z.useCallback)((e,n)=>t(t=>{if(n?t.get(e)===n:!t.has(e))return t;let r=new Map(t);return n?r.set(e,n):r.delete(e),r}),[])]}var g$=(0,Z.memo)(function({id:e,layer:t,columns:n,xKey:r,view:i,mp:a,rawLimit:o,report:s}){let c=d$(t,n,r,i,a,o);return(0,Z.useLayoutEffect)(()=>{s(e,c)},[e,c,s]),(0,Z.useLayoutEffect)(()=>()=>s(e,null),[e,s]),null});function _$({layers:e,xKey:t,columns:n,maxPoints:r,...i}){let a=i.viewXRange??null,[o,s]=(0,Z.useState)(null),c=typeof window<`u`?Math.min(3,Math.max(1,window.devicePixelRatio||1)):1,l=o==null?r:Math.min(r,Math.round(o*c/50)*50),u=Math.max(1e3,Math.round(l/Math.sqrt(Math.max(1,e.length)))),d=Math.floor(l$/Math.max(1,e.length)),[f,p]=h$(),m=(0,Z.useMemo)(()=>e.map(m$),[e]),h=(0,Z.useMemo)(()=>m.map(e=>f.get(e)),[m,f]),g=(0,Z.useMemo)(()=>h.flatMap(e=>e&&e.points.length>0?[e.points]:[]),[h]),_=(0,Z.useMemo)(()=>{let e=1/0,t=-1/0;for(let n of h){let r=n?.bounds;r&&(e=Math.min(e,r.x0),t=Math.max(t,r.x1))}return Number.isFinite(e)&&t>e?[e,t]:null},[h]),v=h.some(e=>!e||e.loading);return(0,Q.jsxs)(Q.Fragment,{children:[e.map((e,r)=>(0,Q.jsx)(g$,{id:m[r],layer:e,columns:n,xKey:t,view:a,mp:u,rawLimit:d,report:p},m[r])),g.length===0?(0,Q.jsxs)(`div`,{className:`chart-placeholder chart-placeholder--no-data`,onContextMenu:e=>{e.preventDefault(),i.onPlotContextMenu?.({clientX:e.clientX,clientY:e.clientY})},children:[(0,Q.jsx)(`span`,{className:`content-empty-icon`,"aria-hidden":!0}),(0,Q.jsx)(`h2`,{children:v?`Loading…`:`No data to plot`}),v?null:(0,Q.jsx)(`p`,{children:`None of the selected datasets has this X column together with a plotted channel.`})]}):(0,Q.jsx)(XQ,{points:g,fullXRange:_,...i,onPlotWidthCss:s})]})}Qe(),QG();function v$(e){return!!e&&!Array.isArray(e)&&typeof e.length==`number`&&`x`in e&&`y`in e}function y$(e){let t=e.length,n=new Float64Array(t),r=new Float64Array(t),i=t>0&&e[0].c!==void 0?new Float32Array(t):void 0,a=e.some(e=>e.d!==void 0)?new Uint8Array(t):void 0;for(let o=0;o<t;o++){let t=e[o];n[o]=t.x,r[o]=t.y,i&&(i[o]=t.c??0),a&&(a[o]=t.d??0)}return{length:t,x:n,y:r,c:i,d:a}}function b$(e,t,n){let r=n?.get(t);if(r)return r;let i=Ge(e);if(i)return Ke(i,t);if(e.length===0||!(t in e[0]))return;let a=new Float64Array(e.length);for(let n=0;n<e.length;n++){let r=e[n][t];a[n]=typeof r==`number`?r:NaN}return a}function x$(e,t,n){let r=b$(e,t,n);if(!r||XG.has(r))return r;let i=0;for(let e=0;e<r.length;e++)r[e]-r[e]===0&&i++;if(i===r.length)return r;let a=new Float64Array(i);for(let e=0,t=0;e<r.length;e++)r[e]-r[e]===0&&(a[t++]=r[e]);return a}function S$(e,t,n,r){if(!n){let n=x$(e,t,r);return n?[{label:t,values:n}]:[]}let i=b$(e,t,r);if(!i)return[];let a=i.length,o=r?.has(n)||e.length>0&&typeof e[0][n]==`number`?b$(e,n,r):void 0,s=t=>{if(o){let e=o[t];return e===e?String(e):`unknown`}return String(e[t]?.[n]??`unknown`)},c=new Map,l=[],u=new Int32Array(a),d=[];for(let e=0;e<a;e++){if(i[e]-i[e]!==0){u[e]=-1;continue}let t=s(e),n=c.get(t);n===void 0&&(c.set(t,n=l.length),l.push(t),d.push(0)),u[e]=n,d[n]++}let f=l.map((e,t)=>({label:e,values:new Float64Array(d[t])})),p=new Int32Array(l.length);for(let e=0;e<a;e++){let t=u[e];t>=0&&(f[t].values[p[t]++]=i[e])}return f}function C$(e){let t=NaN,n=NaN,r=0;for(let i=0;i<e.length;i++){let a=e[i];a-a===0&&(r===0&&(t=a),n=a,r++)}let i=n-t;return r>1&&i>0?(r-1)/i:null}function w$(e,t,n){let r=0;for(let i=0;i<e.length;i++)e[i]>=t&&e[i]<=n&&r++;let i=new Uint32Array(r),a=0;for(let r=0;r<e.length;r++)e[r]>=t&&e[r]<=n&&(i[a++]=r);return i}function T$(e,t){let n=new Float64Array(t.length);for(let r=0;r<t.length;r++)n[r]=e[t[r]];return n}function E$(e,t,n,r){let i=b$(e.rows,t,e.full),a=b$(e.rows,n,e.full);if(!i||!a)return null;let o=r.colorCol?b$(e.rows,r.colorCol,e.full):void 0;if(r.viewXRange){let t=b$(e.rows,r.xKey,e.full);if(t){let e=w$(t,r.viewXRange[0],r.viewXRange[1]);i=T$(i,e),a=T$(a,e),o&&=T$(o,e)}}let s=Math.min(i.length,a.length);if(!o)return{cols:{length:s,x:i,y:a}};let c=1/0,l=-1/0;for(let e=0;e<s;e++){let t=o[e];t<c&&(c=t),t>l&&(l=t)}if(!(l>c))return{cols:{length:s,x:i,y:a}};let u=new Float32Array(s),d=l-c;for(let e=0;e<s;e++){let t=o[e];u[e]=t===t?(t-c)/d:0}return{cols:{length:s,x:i,y:a,c:u},color:{label:r.colorCol,min:c,max:l}}}function D$(e,t,n,r){let i=[],a=[];e.forEach((e,o)=>{a.push(tY(r.colorOverrides,e.id,o,r.palette));let s=E$(e,t,n,{xKey:r.xKey,viewXRange:r.viewXRange});i.push(s?.cols??{length:0,x:[],y:[]})});let o=i.reduce((e,t)=>e+t.length,0),s=new Float64Array(o),c=new Float64Array(o),l=new Uint8Array(o),u=0;return i.forEach((e,t)=>{for(let t=0;t<e.length;t++)s[u+t]=e.x[t],c[u+t]=e.y[t];l.fill(Math.min(t,255),u,u+e.length),u+=e.length}),{cols:{length:o,x:s,y:c,d:l},colors:a}}var O$=e=>v$(e)?e:y$(e),k$=(e,t,n)=>t===t&&n===n&&(!e||t>=e.xmin&&t<=e.xmax&&n>=e.ymin&&n<=e.ymax);function A$(e,t,n){let r=t+1,i=Array.from({length:r},()=>Array(r).fill(0)),a=Array(r).fill(0),o=new Float64Array(2*r-1),s=0;for(let t=0;t<e.length;t++){let c=e.x[t],l=e.y[t];if(k$(n,c,l)){s++,o[0]=1;for(let e=1;e<o.length;e++)o[e]=o[e-1]*c;for(let e=0;e<r;e++){for(let t=0;t<r;t++)i[e][t]+=o[e+t];a[e]+=o[e]*l}}}if(s<r)return null;let c=i.map((e,t)=>[...e,a[t]]);for(let e=0;e<r;e++){let t=e;for(let n=e+1;n<r;n++)Math.abs(c[n][e])>Math.abs(c[t][e])&&(t=n);if([c[e],c[t]]=[c[t],c[e]],Math.abs(c[e][e])<1e-10)return null;let n=c[e][e];for(let t=e;t<=r;t++)c[e][t]/=n;for(let t=0;t<r;t++){if(t===e)continue;let n=c[t][e];for(let i=e;i<=r;i++)c[t][i]-=n*c[e][i]}}return c.map(e=>e[r])}function j$(e,t,n){return A$(O$(e),t,n)}function M$(e,t=4){if(!Number.isFinite(e))return`?`;let n=Math.abs(e);return n===0?`0`:n>=1e5||n>0&&n<.001?e.toExponential(2):e.toPrecision(t).replace(/\.?0+$/,``)}function N$(e,t,n){let r=[];for(let n=e.length-1;n>=0;n--){let i=e[n];n===0?r.push(M$(i)):n===1?r.push(`${M$(i)}·${t}`):r.push(`${M$(i)}·${t}${n>1?`^${n}`:``}`)}return`${n} = ${r.join(` + `).replace(/\+ -/g,`− `)}`}var P$=[[0,45,80,160],[.25,40,145,175],[.5,60,180,110],[.75,220,175,55],[1,210,75,55]];function F$(e){let t=0;for(let n=1;n<P$.length;n++){if(e<=P$[n][0]){t=n-1;break}n===P$.length-1&&(t=n-1)}let n=t+1,r=(e-P$[t][0])/(P$[n][0]-P$[t][0]);return{r:Math.round(P$[t][1]+r*(P$[n][1]-P$[t][1])),g:Math.round(P$[t][2]+r*(P$[n][2]-P$[t][2])),b:Math.round(P$[t][3]+r*(P$[n][3]-P$[t][3]))}}function I$(e){let{r:t,g:n,b:r}=F$(e);return`rgb(${t},${n},${r})`}function L$(e,t){if(!Number.isFinite(e))return 0;let n=Math.floor(e*t);return n<0?0:n>=t?t-1:n}QG();var R$=`#version 300 es
|
|
228
228
|
in vec2 a_corner;
|
|
229
229
|
in float a_x;
|
|
230
230
|
in float a_y;
|
|
@@ -249,7 +249,7 @@ void main() {
|
|
|
249
249
|
v_tex = (clamp(floor(a_k * u_kScale + 0.5), 0.0, 255.0) + 0.5) / 256.0;
|
|
250
250
|
vec2 clip = pos / u_resolution * 2.0 - 1.0;
|
|
251
251
|
gl_Position = vec4(clip.x, -clip.y, 0.0, 1.0);
|
|
252
|
-
}`,
|
|
252
|
+
}`,z$=`#version 300 es
|
|
253
253
|
precision highp float;
|
|
254
254
|
in vec2 v_local;
|
|
255
255
|
in float v_tex;
|
|
@@ -269,7 +269,7 @@ void main() {
|
|
|
269
269
|
vec4 c = texture(u_palette, vec2(v_tex, 0.5));
|
|
270
270
|
float a = c.a * u_alpha * cov;
|
|
271
271
|
outColor = vec4(c.rgb * a, a);
|
|
272
|
-
}`,
|
|
272
|
+
}`,B$=`#version 300 es
|
|
273
273
|
in float a_x;
|
|
274
274
|
in float a_y;
|
|
275
275
|
in float a_k;
|
|
@@ -288,7 +288,7 @@ void main() {
|
|
|
288
288
|
v_tex = (clamp(floor(a_k * u_kScale + 0.5), 0.0, 255.0) + 0.5) / 256.0;
|
|
289
289
|
vec2 clip = p / u_resolution * 2.0 - 1.0;
|
|
290
290
|
gl_Position = vec4(clip.x, -clip.y, 0.0, 1.0);
|
|
291
|
-
}`,
|
|
291
|
+
}`,V$=`#version 300 es
|
|
292
292
|
precision highp float;
|
|
293
293
|
in float v_tex;
|
|
294
294
|
uniform sampler2D u_palette;
|
|
@@ -307,7 +307,7 @@ void main() {
|
|
|
307
307
|
vec4 c = texture(u_palette, vec2(v_tex, 0.5));
|
|
308
308
|
float a = c.a * u_alpha * cov;
|
|
309
309
|
outColor = vec4(c.rgb * a, a);
|
|
310
|
-
}`,
|
|
310
|
+
}`,H$=`#version 300 es
|
|
311
311
|
in vec2 a_corner;
|
|
312
312
|
in float a_ax;
|
|
313
313
|
in float a_ay;
|
|
@@ -342,7 +342,7 @@ void main() {
|
|
|
342
342
|
v_tex = (clamp(floor(a_k * u_kScale + 0.5), 0.0, 255.0) + 0.5) / 256.0;
|
|
343
343
|
vec2 clip = pos / u_resolution * 2.0 - 1.0;
|
|
344
344
|
gl_Position = vec4(clip.x, -clip.y, 0.0, 1.0);
|
|
345
|
-
}`,
|
|
345
|
+
}`,U$=`#version 300 es
|
|
346
346
|
precision highp float;
|
|
347
347
|
flat in vec2 v_a;
|
|
348
348
|
flat in vec2 v_b;
|
|
@@ -363,7 +363,7 @@ void main() {
|
|
|
363
363
|
vec4 c = texture(u_palette, vec2(v_tex, 0.5));
|
|
364
364
|
float a = c.a * cov;
|
|
365
365
|
outColor = vec4(c.rgb * a, a);
|
|
366
|
-
}`,
|
|
366
|
+
}`,W$=`
|
|
367
367
|
uniform vec2 u_ox;
|
|
368
368
|
uniform vec2 u_oy;
|
|
369
369
|
float dbl(uvec2 b, vec2 o) {
|
|
@@ -377,21 +377,21 @@ float dbl(uvec2 b, vec2 o) {
|
|
|
377
377
|
float l = float(b.x & 0x1FFFFFFFu) * exp2(float(int(e) - 1075));
|
|
378
378
|
return (h - o.x) + ((sgn != 0u ? -l : l) - o.y);
|
|
379
379
|
}
|
|
380
|
-
`;function
|
|
381
|
-
`)}${c}`)}var
|
|
380
|
+
`;function G$(e,t,n,r){let i=W$,a=e,o=[];for(let[e,r]of[[t,`u_ox`],[n,`u_oy`]])for(let t of e)a=a.replace(`in float ${t};`,`in uvec2 ${t}_bits;`),o.push(` float ${t} = dbl(${t}_bits, ${r});`);let s=[...t,...n].map(e=>`${e} != ${e}`).join(` || `),c=r?`\n if (${s}) { gl_Position = vec4(2.0, 2.0, 2.0, 1.0); return; }`:``;return a.replace(`void main() {`,`${i}void main() {\n${o.join(`
|
|
381
|
+
`)}${c}`)}var K$=`#version 300 es
|
|
382
382
|
in uvec2 a_x_bits;
|
|
383
383
|
in uvec2 a_y_bits;
|
|
384
384
|
out float v_x;
|
|
385
385
|
out float v_y;
|
|
386
|
-
${
|
|
386
|
+
${W$}
|
|
387
387
|
void main() {
|
|
388
388
|
v_x = dbl(a_x_bits, u_ox);
|
|
389
389
|
v_y = dbl(a_y_bits, u_oy);
|
|
390
390
|
gl_Position = vec4(0.0);
|
|
391
|
-
}`,
|
|
391
|
+
}`,q$=`#version 300 es
|
|
392
392
|
precision mediump float;
|
|
393
393
|
out vec4 o;
|
|
394
|
-
void main() { o = vec4(0.0); }`;function E$(e,t,n,r){let i=QY(e,e.VERTEX_SHADER,t),a=QY(e,e.FRAGMENT_SHADER,n);if(!i||!a)return null;let o=e.createProgram();return e.attachShader(o,i),e.attachShader(o,a),r&&e.transformFeedbackVaryings(o,r,e.SEPARATE_ATTRIBS),e.linkProgram(o),e.getProgramParameter(o,e.LINK_STATUS)?{prog:o,shaders:[i,a]}:(console.error(`glPoints program link failed:`,e.getProgramInfoLog(o)),null)}function D$(e,t){if(!e)return[{v:0,a:0,b:t}];let n=[];for(let r=0;r<t;r++)r===0||e[r]!==e[r-1]?n.push({v:e[r],a:r,b:r+1}):n[n.length-1].b=r+1;return n}function O$(e,t,n,r,i,a){let o=[],s=0;for(let c of a){let a=n.filter(e=>e.v===c.v);if(a.length>1)return null;let l=-1;if(a.length===1){for(let n=a[0].a;n<a[0].b;n++)if(e[n]===r[c.a]&&t[n]===i[c.a]){l=n;break}}if(l<0){o.push({src:0,len:0});continue}let u=Math.min(a[0].b-l,c.b-c.a);for(let n=0;n<u;n++)if(e[l+n]!==r[c.a+n]||t[l+n]!==i[c.a+n])return null;o.push({src:l,len:u}),s+=u}return s>0?o:null}function k$(e){let t=e.getContext(`webgl2`,{antialias:!1,alpha:!0,premultipliedAlpha:!0});if(!t)return null;let n=uX(t,`glPoints|points`,()=>E$(t,g$,_$)),r=uX(t,`glPoints|lines`,()=>E$(t,b$,x$)),i=uX(t,`glPoints|points64`,()=>E$(t,C$(g$,[`a_x`],[`a_y`],!0),_$)),a=uX(t,`glPoints|sprites`,()=>E$(t,v$,y$)),o=uX(t,`glPoints|sprites64`,()=>E$(t,C$(v$,[`a_x`],[`a_y`],!0),y$)),s=uX(t,`glPoints|maxSprite`,()=>t.getParameter(t.ALIASED_POINT_SIZE_RANGE)[1]),c=uX(t,`glPoints|decode`,()=>E$(t,w$,T$,[`v_x`,`v_y`])),l=t.createVertexArray();if(!n||!r)return null;let u=(e,n)=>Object.fromEntries(n.map(n=>[n,t.getAttribLocation(e,n)])),d=(e,n)=>Object.fromEntries(n.map(n=>[n,t.getUniformLocation(e,n)])),f=u(n.prog,[`a_corner`,`a_x`,`a_y`,`a_k`,`a_r`]),p=d(n.prog,[`u_resolution`,`u_plot`,`u_view`,`u_radius`,`u_kScale`,`u_palette`,`u_alpha`,`u_clip`,`u_dpr`,`u_height`]),m=u(r.prog,[`a_corner`,`a_ax`,`a_ay`,`a_bx`,`a_by`,`a_bstart`,`a_k`]),h=d(r.prog,[`u_resolution`,`u_plot`,`u_view`,`u_ext`,`u_kScale`,`u_palette`,`u_half`,`u_clip`]),g=i&&u(i.prog,[`a_corner`,`a_x_bits`,`a_y_bits`,`a_k`,`a_r`]),_=i&&d(i.prog,[`u_resolution`,`u_plot`,`u_view`,`u_radius`,`u_kScale`,`u_palette`,`u_alpha`,`u_clip`,`u_dpr`,`u_height`,`u_ox`,`u_oy`]),v=[`u_resolution`,`u_plot`,`u_view`,`u_radius`,`u_kScale`,`u_palette`,`u_alpha`,`u_clip`,`u_dpr`,`u_height`],y=a&&u(a.prog,[`a_x`,`a_y`,`a_k`]),b=a&&d(a.prog,v),x=o&&u(o.prog,[`a_x_bits`,`a_y_bits`,`a_k`]),S=o&&d(o.prog,[...v,`u_ox`,`u_oy`]),C=c&&u(c.prog,[`a_x_bits`,`a_y_bits`]),w=c&&d(c.prog,[`u_ox`,`u_oy`]),T=t.createTransformFeedback(),E=t.createVertexArray(),D=t.createBuffer(),O=t.createBuffer(),k=!1,A=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,A),t.bufferData(t.ARRAY_BUFFER,Float32Array.from([-1,-1,1,-1,-1,1,1,1]),t.STATIC_DRAW);let j=t.createBuffer(),M=t.createBuffer(),N=t.createBuffer(),P=t.createBuffer(),F=t.createBuffer(),I=t.createBuffer(),L=t.createBuffer(),R=t.createBuffer(),z=null,B=t.createTexture(),V=0,ee=!1,H=!1,U=!1,te=0,W=0,ne=1,G=1,re=1,ie=1.8,ae=.8,oe=255,se=!0,ce=!1,le=1,ue={xmin:0,xmax:1,ymin:0,ymax:1},de={left:0,top:0,width:1,height:1},fe=new Float32Array,pe=new Float32Array,me=new Float32Array,he=new Uint8Array,ge=new Float32Array,_e=new Map,ve=(e,n,r)=>{t.bindBuffer(t.ARRAY_BUFFER,e);let i=r*n.BYTES_PER_ELEMENT;i<=(_e.get(e)??0)?t.bufferSubData(t.ARRAY_BUFFER,0,n,0,r):(t.bufferData(t.ARRAY_BUFFER,n.subarray(0,r),t.DYNAMIC_DRAW),_e.set(e,i))},ye=(e,n,r,i,a,o)=>{let s=r.BYTES_PER_ELEMENT;if(t.bindBuffer(t.ARRAY_BUFFER,n),(_e.get(n)??0)<o*s){let e=Math.ceil(o*1.25)*s;t.bufferData(t.ARRAY_BUFFER,e,t.DYNAMIC_DRAW),_e.set(n,e)}t.bindBuffer(t.COPY_READ_BUFFER,e),t.bindBuffer(t.COPY_WRITE_BUFFER,n),i.forEach((e,n)=>{a[n].len&&t.copyBufferSubData(t.COPY_READ_BUFFER,t.COPY_WRITE_BUFFER,a[n].src*s,e.a*s,a[n].len*s)}),t.bindBuffer(t.COPY_READ_BUFFER,null),t.bindBuffer(t.COPY_WRITE_BUFFER,null),i.forEach((e,n)=>{let i=e.a+a[n].len;e.b>i&&t.bufferSubData(t.ARRAY_BUFFER,i*s,r,i,e.b-i)})},be=(e,n,r=0,i=t.FLOAT)=>{t.bindBuffer(t.ARRAY_BUFFER,n),t.enableVertexAttribArray(e);let a=i===t.FLOAT?4:1;t.vertexAttribPointer(e,1,i,i!==t.FLOAT,a,r*a),t.vertexAttribDivisor(e,1)},xe=(e,n,r=0)=>{t.bindBuffer(t.ARRAY_BUFFER,n),t.enableVertexAttribArray(e),t.vertexAttribIPointer(e,2,t.UNSIGNED_INT,8,r*8),t.vertexAttribDivisor(e,1)},Se=e=>{t.bindBuffer(t.ARRAY_BUFFER,A),t.enableVertexAttribArray(e),t.vertexAttribPointer(e,2,t.FLOAT,!1,0,0),t.vertexAttribDivisor(e,0)};return{resize(t,n,r){ne=Math.max(1,t),G=Math.max(1,n),re=r,e.width=Math.round(ne*re),e.height=Math.round(G*re)},setData(e,t,n,r=!1,i){let a=Math.min(e.length,t.length);fe.length<a&&(fe=new Float32Array(a),pe=new Float32Array(a)),ee=!!n,H=!!i,n&&me.length<a&&(me=new Float32Array(a)),i&&ge.length<a&&(ge=new Float32Array(a)),ce&&he.length<a&&(he=new Uint8Array(a)),te=0,W=0;for(let n=0;n<a;n++)if(e[n]-e[n]===0&&t[n]-t[n]===0){te=e[n],W=t[n];break}let o=XG.has(e)&&XG.has(t);if(U=!!g&&!!c&&e instanceof Float64Array&&t instanceof Float64Array&&(o||!ce),k=!1,U){let o=e,s=t;if(n)for(let e=0;e<a;e++)me[e]=n[e];let c=D$(n&&r?n:void 0,a),l=z&&(!n||r)?O$(z.x,z.y,z.runs,o,s,c):null;if(l?(ye(j,I,o,c,l,a),[j,I]=[I,j],ye(M,L,s,c,l,a),[M,L]=[L,M],n&&(ye(N,R,me,c,l,a),[N,R]=[R,N])):(ve(j,o,a),ve(M,s,a),n&&ve(N,me,a)),(!z||z.x.length<a)&&(z={x:new Float64Array(Math.ceil(a*1.25)),y:new Float64Array(Math.ceil(a*1.25)),runs:c,n:a}),z.x.set(o.subarray(0,a)),z.y.set(s.subarray(0,a)),z.runs=c,z.n=a,i){for(let e=0;e<a;e++)ge[e]=i[e];ve(F,ge,a)}if(ce){if(he.fill(0,0,a),a&&(he[0]=255),n&&r)for(let e=1;e<a;e++)n[e]!==n[e-1]&&(he[e]=255);ve(P,he,a)}V=a;return}z=null;let s=0;if(XG.has(e)&&XG.has(t)){for(let t=0;t<a;t++)fe[t]=e[t]-te;for(let e=0;e<a;e++)pe[e]=t[e]-W;if(n)for(let e=0;e<a;e++)me[e]=n[e];if(i)for(let e=0;e<a;e++)ge[e]=i[e];if(ce&&(he.fill(0,0,a),a&&(he[0]=255),n&&r))for(let e=1;e<a;e++)n[e]!==n[e-1]&&(he[e]=255);s=a}else{let o=!0;for(let c=0;c<a;c++){let a=e[c],l=t[c];if(a-a!==0||l-l!==0){o=!0;continue}fe[s]=a-te,pe[s]=l-W,n&&(me[s]=n[c]),i&&(ge[s]=i[c]),ce&&(he[s]=o||r&&n&&s>0&&n[c]!==me[s-1]?255:0),o=!1,s++}}V=s,ve(j,fe,s),ve(M,pe,s),n&&ve(N,me,s),i&&ve(F,ge,s),ce&&ve(P,he,s)},setStyle(e,n,r){ie=n,ae=r;let i=new Uint8Array(256*4);if(e.kind===`single`){let t=e.rgba.map(e=>Math.round(e*255));for(let e=0;e<256;e++)i.set(t,e*4);oe=0}else i.set(e.palette.subarray(0,256*4)),oe=e.kind===`colormap`?255:1;t.bindTexture(t.TEXTURE_2D,B),t.texImage2D(t.TEXTURE_2D,0,t.RGBA8,256,1,0,t.RGBA,t.UNSIGNED_BYTE,i),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE)},setDraw(e,t,n){se=e,ce=t,le=n},setView(e,t,n,r,i){ue={xmin:e,xmax:t,ymin:n,ymax:r},de=i},render(){if(t.bindFramebuffer(t.FRAMEBUFFER,null),t.viewport(0,0,e.width,e.height),t.disable(t.SCISSOR_TEST),t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT),V===0)return;t.bindVertexArray(l),t.enable(t.BLEND),t.blendFunc(t.ONE,t.ONE_MINUS_SRC_ALPHA),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,B);let u=ee?oe:0,d=[ue.xmin-te,ue.xmax-te,ue.ymin-W,ue.ymax-W],v=[de.left,de.top,de.left+de.width,de.top+de.height],A=e=>{let t=Math.fround(e);return[t,e-t]},I=U,L=j,R=M;if(U&&ce&&V>1){if(!k){for(let e of[D,O])t.bindBuffer(t.ARRAY_BUFFER,e),(_e.get(e)??0)<V*4&&(t.bufferData(t.ARRAY_BUFFER,V*4,t.DYNAMIC_COPY),_e.set(e,V*4));t.bindBuffer(t.ARRAY_BUFFER,null),t.bindVertexArray(E),t.useProgram(c.prog),t.uniform2f(w.u_ox,...A(te)),t.uniform2f(w.u_oy,...A(W)),xe(C.a_x_bits,j),xe(C.a_y_bits,M),t.vertexAttribDivisor(C.a_x_bits,0),t.vertexAttribDivisor(C.a_y_bits,0),t.enable(t.RASTERIZER_DISCARD),t.bindTransformFeedback(t.TRANSFORM_FEEDBACK,T),t.bindBufferBase(t.TRANSFORM_FEEDBACK_BUFFER,0,D),t.bindBufferBase(t.TRANSFORM_FEEDBACK_BUFFER,1,O),t.beginTransformFeedback(t.POINTS),t.drawArrays(t.POINTS,0,V),t.endTransformFeedback(),t.bindBufferBase(t.TRANSFORM_FEEDBACK_BUFFER,0,null),t.bindBufferBase(t.TRANSFORM_FEEDBACK_BUFFER,1,null),t.bindTransformFeedback(t.TRANSFORM_FEEDBACK,null),t.disable(t.RASTERIZER_DISCARD),t.bindVertexArray(l),k=!0}I=!1,L=D,R=O}if(ce&&V>1){let e=h,n=m;t.useProgram(r.prog),t.uniform2f(e.u_resolution,ne,G),t.uniform4f(e.u_plot,de.left,de.top,de.width,de.height),t.uniform4f(e.u_view,...d),t.uniform1f(e.u_half,le/2),t.uniform1f(e.u_ext,le/2+1),t.uniform1f(e.u_kScale,u),t.uniform4f(e.u_clip,...v),t.uniform1i(e.u_palette,0),Se(n.a_corner),be(n.a_ax,L,0),be(n.a_bx,L,1),be(n.a_ay,R,0),be(n.a_by,R,1),be(n.a_bstart,P,1,t.UNSIGNED_BYTE),ee?be(n.a_k,N,0):(t.disableVertexAttribArray(n.a_k),t.vertexAttrib1f(n.a_k,0)),t.drawArraysInstanced(t.TRIANGLE_STRIP,0,4,V-1);for(let e of Object.values(n))t.vertexAttribDivisor(e,0)}if(se&&!H&&2*(ie+.5)*re<=s&&(I?o:a)){let n=I?S:b,r=I?x:y;t.useProgram((I?o:a).prog),I&&(t.uniform2f(n.u_ox,...A(te)),t.uniform2f(n.u_oy,...A(W))),t.uniform2f(n.u_resolution,ne,G),t.uniform4f(n.u_plot,de.left,de.top,de.width,de.height),t.uniform4f(n.u_view,...d),t.uniform1f(n.u_radius,ie),t.uniform1f(n.u_kScale,u),t.uniform1f(n.u_alpha,ae),t.uniform4f(n.u_clip,...v),t.uniform1f(n.u_dpr,re),t.uniform1f(n.u_height,e.height),t.uniform1i(n.u_palette,0),I?(xe(r.a_x_bits,j),xe(r.a_y_bits,M)):(be(r.a_x,L),be(r.a_y,R)),ee?be(r.a_k,N):(t.disableVertexAttribArray(r.a_k),t.vertexAttrib1f(r.a_k,0));for(let e of Object.values(r))t.vertexAttribDivisor(e,0);t.drawArrays(t.POINTS,0,V)}else if(se){let r=I?_:p,a=I?g:f;t.useProgram(I?i.prog:n.prog),I&&(t.uniform2f(r.u_ox,...A(te)),t.uniform2f(r.u_oy,...A(W))),t.uniform2f(r.u_resolution,ne,G),t.uniform4f(r.u_plot,de.left,de.top,de.width,de.height),t.uniform4f(r.u_view,...d),t.uniform1f(r.u_radius,ie),t.uniform1f(r.u_kScale,u),t.uniform1f(r.u_alpha,ae),t.uniform4f(r.u_clip,...v),t.uniform1f(r.u_dpr,re),t.uniform1f(r.u_height,e.height),t.uniform1i(r.u_palette,0),Se(a.a_corner),I?(xe(a.a_x_bits,j),xe(a.a_y_bits,M)):(be(a.a_x,L),be(a.a_y,R)),ee?be(a.a_k,N):(t.disableVertexAttribArray(a.a_k),t.vertexAttrib1f(a.a_k,0)),H?be(a.a_r,F):(t.disableVertexAttribArray(a.a_r),t.vertexAttrib1f(a.a_r,0)),t.drawArraysInstanced(t.TRIANGLE_STRIP,0,4,V);for(let e of Object.values(a))t.vertexAttribDivisor(e,0)}t.bindVertexArray(null)},dispose(){for(let e of[A,j,M,N,P,F,D,O,I,L,R])t.deleteBuffer(e);t.deleteTransformFeedback(T),t.deleteVertexArray(E),t.deleteTexture(B),t.deleteVertexArray(l)}}}var A$={top:3,right:3,bottom:3,left:3};function j$(e,t,n){return t<200||n<120?{...A$,tiny:!0}:{...e,tiny:!1}}var M$={top:14,right:24,bottom:40,left:78},N$=70,P$=6,F$=8,I$=1.8;function L$(e,t,n){return Math.min(n,Math.max(t,e))}function R$(e,t){let n=e[t],r=1/0,i=-1/0;for(let t=0;t<e.length;t++){let e=n[t];e<r&&(r=e),e>i&&(i=e)}(!Number.isFinite(r)||r===i)&&(--r,i+=1);let a=(i-r)*.04;return{min:r-a,max:i+a}}function z$(e){return e===`dashed`?[5,4]:e===`dotted`?[1,4]:[]}function B$({points:e,xLabel:t,yLabel:n,color:r=`#38bdf8`,datasetColors:i,colorLabel:a,colorRange:o,height:s=400,pointRadius:c=I$,drawMode:l=`points`,lineWidth:u=1,backgroundToken:d=``,onPlotContextMenu:f,xAxisLine:p,yAxisLine:m,gridLine:h,fitSettings:g,xScale:_,yScale:v}){let y=IZ(),b=(0,Z.useRef)(null),x=(0,Z.useRef)(null),S=(0,Z.useRef)(null),C=(0,Z.useRef)(f);(0,Z.useLayoutEffect)(()=>{C.current=f},[f]);let w=(0,Z.useRef)(null),T=(0,Z.useRef)(null),E=(0,Z.useRef)(null),D=(0,Z.useRef)(null),O=(0,Z.useRef)(null),k=(0,Z.useRef)(0),A=(0,Z.useRef)(null),j=(0,Z.useMemo)(()=>XQ(e)?e:ZQ(e),[e]),M=(0,Z.useRef)({cols:j,xLabel:t,yLabel:n,color:r,datasetColors:i,colorLabel:a,colorRange:o,height:s,pointRadius:c,drawMode:l,lineWidth:u,xAxisLine:p,yAxisLine:m,gridLine:h,fitSettings:g,xScale:_,yScale:v});(0,Z.useLayoutEffect)(()=>{M.current={cols:j,xLabel:t,yLabel:n,color:r,datasetColors:i,colorLabel:a,colorRange:o,height:s,pointRadius:c,drawMode:l,lineWidth:u,xAxisLine:p,yAxisLine:m,gridLine:h,fitSettings:g,xScale:_,yScale:v}},[j,t,n,r,i,a,o,s,c,l,u,p,m,h,g,_,v]);let N=(0,Z.useRef)({cols:null,value:{x:{min:0,max:1},y:{min:0,max:1}}});function P(){let e=M.current.cols,t=N.current;return t.cols!==e&&(t.value={x:R$(e,`x`),y:R$(e,`y`)},t.cols=e),t.value}(0,Z.useEffect)(()=>{T.current=null,E.current=null,D.current=null,O.current=null},[t,n]);function F(){let e=P(),t=T.current,n=E.current,r=D.current,i=O.current;return{xmin:t!==null&&n!==null&&n>t?t:e.x.min,xmax:t!==null&&n!==null&&n>t?n:e.x.max,ymin:r!==null&&i!==null&&i>r?r:e.y.min,ymax:r!==null&&i!==null&&i>r?i:e.y.max}}function I(){if(T.current!==null||D.current!==null)return F();let{xScale:e,yScale:t}=M.current,n=e=>{if(!e)return null;let t=parseFloat(e.scaleMin),n=parseFloat(e.scaleMax);return Number.isFinite(t)&&Number.isFinite(n)&&t<n?{min:t,max:n}:null},r=n(e)??P().x,i=n(t)??P().y;return{xmin:r.min,xmax:r.max,ymin:i.min,ymax:i.max}}function L(){if(A.current)return A.current;let e=S.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`,accent:`#f97316`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`,accent:t.getPropertyValue(`--accent`).trim()||`#f97316`};return A.current=n,n}function R(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function z(){let e=S.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||M.current.height)}}let B=(0,Z.useRef)(null),V=(0,Z.useRef)(null),ee=(0,Z.useRef)({r:null,failed:!1,data:null,mode:``,style:``,size:``});function H(e,t){let n=ee.current;!n.r&&!n.failed&&V.current&&(n.r=dX(V.current,k$),n.failed=!n.r);let r=n.r;if(!r||!V.current)return null;let{cols:i,color:a,datasetColors:o,pointRadius:s,drawMode:c,lineWidth:l}=M.current,u=Math.min(2,window.devicePixelRatio||1),d=`${e}x${t}@${u}`;n.size!==d&&(r.resize(e,t,u),V.current.style.width=`${e}px`,V.current.style.height=`${t}px`,n.size=d);let f=o&&o.length>0&&i.d?`dataset`:i.c?`colormap`:`single`,p=c!==`points`;r.setDraw(c!==`lines`,p,l),(n.data!==i||n.mode!==`${f}|${p}`)&&(r.setData(i.x,i.y,f===`dataset`?i.d:f===`colormap`?i.c:void 0,f===`dataset`),n.data=i,n.mode=`${f}|${p}`);let m=`${f}|${a}|${f===`dataset`?o.join(`,`):``}|${s}`;return n.style!==m&&(r.setStyle(H$(f,a,o),Math.max(.25,s),.8),n.style=m),r}(0,Z.useEffect)(()=>()=>{ee.current.r?.dispose(),ee.current.r=null},[]);let U=(0,Z.useRef)({cols:null,key:``,coeffs:null});function te(e,t,n){let r=`${t}|${n.xmin}|${n.xmax}|${n.ymin}|${n.ymax}`,i=U.current;return(i.cols!==e||i.key!==r)&&(U.current={cols:e,key:r,coeffs:l$(e,t,n)}),U.current.coeffs}let W=(0,Z.useRef)({pts:null,view:``}),ne=(0,Z.useRef)(``);function G(){let e=b.current;if(!e)return;let{w:t,h:n}=z(),r=R(e,t,n);if(!r)return;let{cols:i,xLabel:a,yLabel:o,color:s,datasetColors:c,colorLabel:l,colorRange:u,pointRadius:d,xAxisLine:f,yAxisLine:p,gridLine:m,fitSettings:h,xScale:g,yScale:_}=M.current,v=!!c&&c.length>0&&!!i.d,x=!v&&i.length>0&&!!i.c,C=j$(M$,t,n),w=C.tiny?C.right:x?N$:C.right,{top:T,bottom:E,left:D}=C,O=t-D-w,k=n-T-E,{bg:A,muted:j,grid:N,accent:P}=L(),F=Math.max(.25,d),V=H(t,n),ee=i.length>=1&&O>0&&k>0?I():null,U=[t,n,e.width,ee&&`${ee.xmin}|${ee.xmax}|${ee.ymin}|${ee.ymax}`,a,o,x,v,l,u?.join(),JSON.stringify([f,p,m,g,_]),A,j,N,P].join(`§`);if(V&&ee&&!h&&ne.current===U){let e=W.current;e.pts!==i&&(W.current={pts:i,view:e.view},VX(S.current)),V.setView(ee.xmin,ee.xmax,ee.ymin,ee.ymax,{left:D,top:T,width:O,height:k}),V.render();return}ne.current=U,r.fillStyle=A,r.fillRect(0,0,t,n);let G=B.current?R(B.current,t,n):null;G?.clearRect(0,0,t,n);let re=V;if(i.length<1||O<=0||k<=0){re?.render(),r.fillStyle=j,r.font=`13px ${X.sans}`,MY(r);return}let{xmin:ie,xmax:ae,ymin:oe,ymax:se}=I(),ce=ae-ie,le=se-oe,ue=e=>D+(e-ie)/ce*O;y({left:D,top:T,width:O,height:k,x:{v0:ie,v1:ae}});let de=e=>T+(se-e)/le*k,fe=(()=>{if(_?.majorStep){let e=parseFloat(_.majorStep);if(Number.isFinite(e)&&e>0)return e}return uJ(le,6)})(),pe=pJ(oe,se,fe);if((p?.style??`dashed`)!==`none`){r.strokeStyle=p?.color??N,r.lineWidth=p?.width??1,r.setLineDash(z$(p?.style??`dashed`));for(let e of pe){let t=de(e);r.beginPath(),r.moveTo(D,t),r.lineTo(D+O,t),r.stroke()}r.setLineDash([])}r.strokeStyle=j,r.lineWidth=1,r.fillStyle=j,r.font=`11px ${X.mono}`,r.textAlign=`right`,r.textBaseline=`middle`;for(let e of C.tiny?[]:pe){let t=de(e);r.beginPath(),r.moveTo(D-P$,t),r.lineTo(D,t),r.stroke(),r.fillText(_J(e,fe),D-F$,t)}let me=(()=>{if(g?.majorStep){let e=parseFloat(g.majorStep);if(Number.isFinite(e)&&e>0)return e}return uJ(ce,dJ(O))})(),he=pJ(ie,ae,me);if((f?.style??`dashed`)!==`none`){r.strokeStyle=f?.color??N,r.lineWidth=f?.width??1,r.setLineDash(z$(f?.style??`dashed`));for(let e of he){let t=ue(e);r.beginPath(),r.moveTo(t,T),r.lineTo(t,T+k),r.stroke()}r.setLineDash([])}r.strokeStyle=j,r.lineWidth=1,r.fillStyle=j,r.textAlign=`center`,r.textBaseline=`top`;for(let e of C.tiny?[]:he){let t=ue(e);r.beginPath(),r.moveTo(t,T+k),r.lineTo(t,T+k+P$),r.stroke(),r.fillText(_J(e,me),t,T+k+P$+2)}(m?.style??`solid`)!==`none`&&(r.strokeStyle=m?.color??N,r.lineWidth=m?.width??1,r.setLineDash(z$(m?.style??`solid`)),r.strokeRect(D,T,O,k),r.setLineDash([])),r.fillStyle=j,r.font=`11px ${X.mono}`,r.textAlign=`center`,r.textBaseline=`bottom`,C.tiny||(r.fillText(a,D+O/2,n-4),r.save(),r.translate(14,T+k/2),r.rotate(-Math.PI/2),r.fillText(o,0,0),r.restore());let ge=W.current;if((ge.pts!==i||ge.view!==`${ie}|${ae}|${oe}|${se}`)&&(W.current={pts:i,view:`${ie}|${ae}|${oe}|${se}`},VX(S.current)),re)re.setView(ie,ae,oe,se,{left:D,top:T,width:O,height:k}),re.render();else{let e={xToPx:ue,yToPx:de,left:D,top:T,plotW:O,plotH:k,dotR:F,col:s,dsColors:v?c:null,hasColormap:x};M.current.drawMode!==`points`&&W$(r,i,e,M.current.lineWidth),M.current.drawMode!==`lines`&&U$(r,i,e)}if(x&&!C.tiny){let e=D+O+10,n=k;for(let t=0;t<64;t++)r.fillStyle=m$(1-t/64),r.fillRect(e,T+t/64*n,10,n/64+1);r.strokeStyle=j,r.lineWidth=.5,r.strokeRect(e,T,10,n),r.fillStyle=j,r.font=`10px ${X.mono}`,r.textAlign=`left`,r.textBaseline=`top`;let i=u?String(u[1].toPrecision(3)):`1`,a=u?String(u[0].toPrecision(3)):`0`;r.fillText(i,e+10+3,T),r.textBaseline=`bottom`,r.fillText(a,e+10+3,T+n),l&&(r.save(),r.textBaseline=`middle`,r.translate(t-6,T+n/2),r.rotate(Math.PI/2),r.fillText(l,0,0),r.restore())}if(h&&G){let e=te(i,h.degree,{xmin:ie,xmax:ae,ymin:oe,ymax:se});if(e){G.save(),G.beginPath(),G.rect(D,T,O,k),G.clip(),G.strokeStyle=h.color,G.lineWidth=h.width,G.setLineDash(z$(h.lineStyle)),G.beginPath();for(let t=0;t<=300;t++){let n=ie+t/300*ce,r=e.reduce((e,t,r)=>e+t*n**+r,0),i=ue(n),a=de(r);t===0?G.moveTo(i,a):G.lineTo(i,a)}G.stroke(),G.setLineDash([]);let t=d$(e,`x`,`y`);G.fillStyle=P,G.font=`10px ${X.mono}`,G.textAlign=`right`,G.textBaseline=`top`,G.fillText(t,D+O-8,T+8),G.restore()}}if((g?.alarm||_?.alarm)&&G){if(G.save(),G.beginPath(),G.rect(D,T,O,k),G.clip(),g?.alarm){let e=g.alarm;G.strokeStyle=e.color,G.lineWidth=e.width,G.setLineDash(e.linked===`active`?RZ:z$(e.style));let t=ue(e.value);G.beginPath(),G.moveTo(t,T),G.lineTo(t,T+k),G.stroke(),G.setLineDash([]),e.linked&&BZ(G,t+3,T+2,e.color)}if(_?.alarm){let e=_.alarm;G.strokeStyle=e.color,G.lineWidth=e.width,G.setLineDash(e.linked===`active`?RZ:z$(e.style));let t=de(e.value);G.beginPath(),G.moveTo(D,t),G.lineTo(D+O,t),G.stroke(),G.setLineDash([]),e.linked&&BZ(G,D+O-10-3,t-10-2,e.color)}G.restore()}}let re=(0,Z.useRef)(``);function ie(){let e=x.current;if(!e)return;let{w:t,h:n}=z(),r=`${t}x${n}`;if(w.current===null&&re.current===r)return;let i=R(e,t,n);if(!i)return;i.clearRect(0,0,t,n),re.current=w.current===null?r:``;let a=w.current,{cols:o,color:s,datasetColors:c,pointRadius:l}=M.current;if(a===null||a>=o.length||o.length<1)return;let u=Math.max(4,l*2),d=o.d?.[a],f=c&&c.length>0&&d!==void 0?c[d]??s:s,{top:p,right:m,bottom:h,left:g}=j$(M$,t,n),_=t-g-m,v=n-p-h;if(_<=0||v<=0)return;let{xmin:y,xmax:b,ymin:S,ymax:C}=I(),T=b-y,E=C-S,D={x:o.x[a],y:o.y[a]},O=g+(D.x-y)/T*_,k=p+(C-D.y)/E*v,{bg:A,muted:j}=L();i.strokeStyle=j,i.globalAlpha=.4,i.lineWidth=1,i.setLineDash([3,3]),i.beginPath(),i.moveTo(O,p),i.lineTo(O,p+v),i.stroke(),i.beginPath(),i.moveTo(g,k),i.lineTo(g+_,k),i.stroke(),i.setLineDash([]),i.globalAlpha=1,i.fillStyle=f,i.beginPath(),i.arc(O,k,u,0,Math.PI*2),i.fill(),i.strokeStyle=A,i.lineWidth=1.5,i.beginPath(),i.arc(O,k,u,0,Math.PI*2),i.stroke();let N=`(${vJ(D.x)}, ${vJ(D.y)})`;i.font=`11px ${X.mono}`;let P=i.measureText(N).width+12,F=O+10,B=k-24;F+P>g+_&&(F=O-P-10),B<p&&(B=k+10),i.fillStyle=A,i.globalAlpha=.85,i.beginPath(),V$(i,F,B,P,20,4),i.fill(),i.globalAlpha=1,i.strokeStyle=j,i.lineWidth=.5,i.beginPath(),V$(i,F,B,P,20,4),i.stroke(),i.fillStyle=j,i.textAlign=`left`,i.textBaseline=`middle`,i.fillText(N,F+6,B+20/2)}let ae=(0,Z.useRef)(G),oe=(0,Z.useRef)(ie);(0,Z.useLayoutEffect)(()=>{ae.current=G,oe.current=ie});let se=(0,Z.useRef)(null);se.current??=KX(()=>{ae.current(),oe.current()},()=>S.current);function ce(){se.current.schedule()}function le(){k.current||=RX(()=>{k.current=0,oe.current()})}(0,Z.useEffect)(()=>()=>{se.current?.cancel(),zX(k.current),k.current=0},[]);let ue=(0,Z.useRef)(ce),de=(0,Z.useRef)(le);return(0,Z.useLayoutEffect)(()=>{ue.current=ce,de.current=le}),(0,Z.useEffect)(()=>zJ(S.current,()=>{A.current=null,ue.current()}),[]),(0,Z.useEffect)(()=>{A.current=null,ue.current()},[d]),(0,Z.useEffect)(()=>{se.current.now()},[e,t,n,r,i,s,c,l,u,p,m,h,g,_,v]),(0,Z.useEffect)(()=>{let e=x.current,t=S.current;if(!e||!t)return;let n=new WX(()=>{A.current=null,ue.current()});n.observe(t);let r=null;function i(e,t){let n=M.current.cols;if(n.length===0)return null;let{w:i,h:a}=z(),{top:o,right:s,bottom:c,left:l}=j$(M$,i,a),u=i-l-s,d=a-o-c,{xmin:f,xmax:p,ymin:m,ymax:h}=I(),g=p-f,_=h-m,v=Math.max(12,M.current.pointRadius*10),y=`${i}|${a}|${f}|${p}|${m}|${h}|${v}`;if(!r||r.cols!==n||r.key!==y){let e=Math.max(1,Math.ceil(u/v)),t=Math.max(1,Math.ceil(d/v)),i=t=>{let r=(n.x[t]-f)/g*u,i=(h-n.y[t])/_*d;return r>=0&&r<u&&i>=0&&i<d?Math.floor(i/v)*e+Math.floor(r/v):-1},a=new Uint32Array(e*t+1);for(let e=0;e<n.length;e++){let t=i(e);t>=0&&a[t+1]++}for(let n=0;n<e*t;n++)a[n+1]+=a[n];let o=a.slice(0,e*t),s=new Uint32Array(a[e*t]);for(let e=0;e<n.length;e++){let t=i(e);t>=0&&(s[o[t]++]=e)}r={cols:n,key:y,cell:v,nx:e,start:a,ix:s}}let b=r,x=Math.floor((e-l)/b.cell),S=Math.floor((t-o)/b.cell),C=(b.start.length-1)/b.nx,w=-1,T=v*v;for(let r=S-1;r<=S+1;r++)if(!(r<0||r>=C))for(let i=x-1;i<=x+1;i++){if(i<0||i>=b.nx)continue;let a=r*b.nx+i;for(let r=b.start[a];r<b.start[a+1];r++){let i=b.ix[r],a=l+(n.x[i]-f)/g*u,s=o+(h-n.y[i])/_*d,c=(a-e)**2+(s-t)**2;c<T&&(T=c,w=i)}}return w<0?null:w}let a=t=>{if(M.current.cols.length<1){w.current!==null&&(w.current=null,de.current());return}let n=e.getBoundingClientRect(),r=t.clientX-n.left,a=t.clientY-n.top,{left:o,top:s,right:c,bottom:l}=j$(M$,n.width,n.height),u=Math.max(1,n.width-o-c),d=n.height-s-l;if(r<o||r>o+u||a<s||a>s+d){w.current!==null&&(w.current=null,de.current());return}let f=i(r,a);w.current!==f&&(w.current=f,de.current())},o=()=>{w.current!==null&&(w.current=null,de.current())},s=t=>{if(M.current.cols.length<1)return;let n=e.getBoundingClientRect(),r=t.clientX-n.left,i=t.clientY-n.top,{top:a,left:o,right:s,bottom:c}=j$(M$,n.width,n.height),l=Math.max(1,n.width-o-s),u=Math.max(1,n.height-a-c);if(r<o||r>o+l||i<a||i>a+u)return;t.preventDefault();let d=P(),f=d.x.max-d.x.min,p=d.y.max-d.y.min,m=I(),h=m.xmin,g=m.xmax,_=m.ymin,v=m.ymax,y=g-h,b=v-_,x=(r-o)/l,S=(i-a)/u,C=h+x*y,w=v-S*b,k=t.deltaY<0,A=.88,j=k?A:1/A,N=y*j,F=b*j;if(!k&&N>=f*.999&&F>=p*.999){T.current=null,E.current=null,D.current=null,O.current=null,ue.current();return}N=L$(N,Math.max(f*1e-7,1e-12),f),F=L$(F,Math.max(p*1e-7,1e-12),p);let L=C-x*N,R=C+(1-x)*N;L<d.x.min&&(R+=d.x.min-L,L=d.x.min),R>d.x.max&&(L-=R-d.x.max,R=d.x.max);let z=w-(1-S)*F,B=w+S*F;z<d.y.min&&(B+=d.y.min-z,z=d.y.min),B>d.y.max&&(z-=B-d.y.max,B=d.y.max),T.current=L,E.current=R,D.current=z,O.current=B,ue.current()},c=e=>{e.button===0&&(T.current===null&&D.current===null||(T.current=null,E.current=null,D.current=null,O.current=null,ue.current(),de.current()))},l=e=>{e.preventDefault(),C.current?.({clientX:e.clientX,clientY:e.clientY})};return e.addEventListener(`mousemove`,a),e.addEventListener(`mouseleave`,o),e.addEventListener(`wheel`,s,{passive:!1}),e.addEventListener(`contextmenu`,l),e.addEventListener(`dblclick`,c),()=>{n.disconnect(),e.removeEventListener(`mousemove`,a),e.removeEventListener(`mouseleave`,o),e.removeEventListener(`wheel`,s),e.removeEventListener(`contextmenu`,l),e.removeEventListener(`dblclick`,c)}},[]),(0,Q.jsxs)(`div`,{ref:S,className:`chart-canvas-wrap`,children:[(0,Q.jsx)(`canvas`,{ref:b,className:`chart-canvas`,role:`img`,"aria-label":`Scatter ${t} vs ${n}`}),(0,Q.jsx)(`canvas`,{ref:V,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),(0,Q.jsx)(`canvas`,{ref:B,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),(0,Q.jsx)(`canvas`,{ref:x,className:`chart-canvas chart-overlay`})]})}function V$(e,t,n,r,i,a){e.moveTo(t+a,n),e.lineTo(t+r-a,n),e.arcTo(t+r,n,t+r,n+a,a),e.lineTo(t+r,n+i-a),e.arcTo(t+r,n+i,t+r-a,n+i,a),e.lineTo(t+a,n+i),e.arcTo(t,n+i,t,n+i-a,a),e.lineTo(t,n+a),e.arcTo(t,n,t+a,n,a)}function H$(e,t,n){if(e===`single`)return{kind:`single`,rgba:qY(t)};let r=new Uint8Array(256*4);for(let t=0;t<256;t++)if(e===`colormap`){let{r:e,g:n,b:i}=p$(t/255);r.set([e,n,i,255],t*4)}else{let e=qY(n[Math.min(t,n.length-1)]);r.set([e[0]*255,e[1]*255,e[2]*255,e[3]*255],t*4)}return{kind:e===`colormap`?`colormap`:`dataset`,palette:r}}function U$(e,t,n){let r=Math.PI*2,i=n.dsColors?n.dsColors.length:n.hasColormap?24:1,a=Array.from({length:i},()=>new Path2D);for(let e=0;e<t.length;e++){let o=n.xToPx(t.x[e]),s=n.yToPx(t.y[e]);if(!(o>=n.left&&o<=n.left+n.plotW&&s>=n.top&&s<=n.top+n.plotH))continue;let c=n.dsColors?Math.min(t.d?.[e]??0,i-1):n.hasColormap?h$(t.c?.[e]??0,24):0;a[c].moveTo(o+n.dotR,s),a[c].arc(o,s,n.dotR,0,r)}e.globalAlpha=.8;for(let t=0;t<i;t++)e.fillStyle=n.dsColors?n.dsColors[t]:n.hasColormap?m$((t+.5)/24):n.col,e.fill(a[t]);e.globalAlpha=1}function W$(e,t,n,r){e.save(),e.beginPath(),e.rect(n.left,n.top,n.plotW,n.plotH),e.clip(),e.lineWidth=r;let i=n.dsColors?n.dsColors.length:1;for(let r=0;r<i;r++){e.beginPath();let i=!1;for(let a=0;a<t.length;a++){if(n.dsColors&&(t.d?.[a]??0)!==r){i=!1;continue}let o=t.x[a],s=t.y[a];if(o-o!==0||s-s!==0){i=!1;continue}i?e.lineTo(n.xToPx(o),n.yToPx(s)):(e.moveTo(n.xToPx(o),n.yToPx(s)),i=!0)}e.strokeStyle=n.dsColors?n.dsColors[r]:n.col,e.stroke()}e.restore()}var G$=11102230246251565e-32,K$=134217729,q$=(3+8*G$)*G$;function J$(e,t,n,r,i){let a,o,s,c,l=t[0],u=r[0],d=0,f=0;u>l==u>-l?(a=l,l=t[++d]):(a=u,u=r[++f]);let p=0;if(d<e&&f<n)for(u>l==u>-l?(o=l+a,s=a-(o-l),l=t[++d]):(o=u+a,s=a-(o-u),u=r[++f]),a=o,s!==0&&(i[p++]=s);d<e&&f<n;)u>l==u>-l?(o=a+l,c=o-a,s=a-(o-c)+(l-c),l=t[++d]):(o=a+u,c=o-a,s=a-(o-c)+(u-c),u=r[++f]),a=o,s!==0&&(i[p++]=s);for(;d<e;)o=a+l,c=o-a,s=a-(o-c)+(l-c),l=t[++d],a=o,s!==0&&(i[p++]=s);for(;f<n;)o=a+u,c=o-a,s=a-(o-c)+(u-c),u=r[++f],a=o,s!==0&&(i[p++]=s);return(a!==0||p===0)&&(i[p++]=a),p}function Y$(e,t){let n=t[0];for(let r=1;r<e;r++)n+=t[r];return n}function $(e){return new Float64Array(e)}var X$=(3+16*G$)*G$,Z$=(2+12*G$)*G$,Q$=(9+64*G$)*G$*G$,$$=$(4),e1=$(8),t1=$(12),n1=$(16),r1=$(4);function i1(e,t,n,r,i,a,o){let s,c,l,u,d,f,p,m,h,g,_,v,y,b,x,S,C,w,T=e-i,E=n-i,D=t-a,O=r-a;b=T*O,f=K$*T,p=f-(f-T),m=T-p,f=K$*O,h=f-(f-O),g=O-h,x=m*g-(b-p*h-m*h-p*g),S=D*E,f=K$*D,p=f-(f-D),m=D-p,f=K$*E,h=f-(f-E),g=E-h,C=m*g-(S-p*h-m*h-p*g),_=x-C,d=x-_,$$[0]=x-(_+d)+(d-C),v=b+_,d=v-b,y=b-(v-d)+(_-d),_=y-S,d=y-_,$$[1]=y-(_+d)+(d-S),w=v+_,d=w-v,$$[2]=v-(w-d)+(_-d),$$[3]=w;let k=Y$(4,$$),A=Z$*o;if(k>=A||-k>=A||(d=e-T,s=e-(T+d)+(d-i),d=n-E,l=n-(E+d)+(d-i),d=t-D,c=t-(D+d)+(d-a),d=r-O,u=r-(O+d)+(d-a),s===0&&c===0&&l===0&&u===0)||(A=Q$*o+q$*Math.abs(k),k+=T*u+O*s-(D*l+E*c),k>=A||-k>=A))return k;b=s*O,f=K$*s,p=f-(f-s),m=s-p,f=K$*O,h=f-(f-O),g=O-h,x=m*g-(b-p*h-m*h-p*g),S=c*E,f=K$*c,p=f-(f-c),m=c-p,f=K$*E,h=f-(f-E),g=E-h,C=m*g-(S-p*h-m*h-p*g),_=x-C,d=x-_,r1[0]=x-(_+d)+(d-C),v=b+_,d=v-b,y=b-(v-d)+(_-d),_=y-S,d=y-_,r1[1]=y-(_+d)+(d-S),w=v+_,d=w-v,r1[2]=v-(w-d)+(_-d),r1[3]=w;let j=J$(4,$$,4,r1,e1);b=T*u,f=K$*T,p=f-(f-T),m=T-p,f=K$*u,h=f-(f-u),g=u-h,x=m*g-(b-p*h-m*h-p*g),S=D*l,f=K$*D,p=f-(f-D),m=D-p,f=K$*l,h=f-(f-l),g=l-h,C=m*g-(S-p*h-m*h-p*g),_=x-C,d=x-_,r1[0]=x-(_+d)+(d-C),v=b+_,d=v-b,y=b-(v-d)+(_-d),_=y-S,d=y-_,r1[1]=y-(_+d)+(d-S),w=v+_,d=w-v,r1[2]=v-(w-d)+(_-d),r1[3]=w;let M=J$(j,e1,4,r1,t1);return b=s*u,f=K$*s,p=f-(f-s),m=s-p,f=K$*u,h=f-(f-u),g=u-h,x=m*g-(b-p*h-m*h-p*g),S=c*l,f=K$*c,p=f-(f-c),m=c-p,f=K$*l,h=f-(f-l),g=l-h,C=m*g-(S-p*h-m*h-p*g),_=x-C,d=x-_,r1[0]=x-(_+d)+(d-C),v=b+_,d=v-b,y=b-(v-d)+(_-d),_=y-S,d=y-_,r1[1]=y-(_+d)+(d-S),w=v+_,d=w-v,r1[2]=v-(w-d)+(_-d),r1[3]=w,n1[J$(M,t1,4,r1,n1)-1]}function a1(e,t,n,r,i,a){let o=(t-a)*(n-i),s=(e-i)*(r-a),c=o-s,l=Math.abs(o+s);return Math.abs(c)>=X$*l?c:-i1(e,t,n,r,i,a,l)}(7+56*G$)*G$,(3+28*G$)*G$,(26+288*G$)*G$*G$,$(4),$(4),$(4),$(4),$(4),$(4),$(4),$(4),$(4),$(8),$(8),$(8),$(4),$(8),$(8),$(16),$(12),$(192),$(192),(10+96*G$)*G$,(4+48*G$)*G$,(44+576*G$)*G$*G$,$(4),$(4),$(4),$(4),$(4),$(4),$(4),$(4),$(8),$(8),$(8),$(8),$(8),$(8),$(8),$(8),$(8),$(4),$(4),$(4),$(8),$(16),$(16),$(16),$(32),$(32),$(48),$(64),$(1152),$(1152),(16+224*G$)*G$,(5+72*G$)*G$,(71+1408*G$)*G$*G$,$(4),$(4),$(4),$(4),$(4),$(4),$(4),$(4),$(4),$(4),$(24),$(24),$(24),$(24),$(24),$(24),$(24),$(24),$(24),$(24),$(1152),$(1152),$(1152),$(1152),$(1152),$(2304),$(2304),$(3456),$(5760),$(8),$(8),$(8),$(16),$(24),$(48),$(48),$(96),$(192),$(384),$(384),$(384),$(768),$(96),$(96),$(96),$(1152);var o1=2**-52,s1=new Uint32Array(512),c1=class e{static from(t,n=g1,r=_1){let i=t.length,a=new Float64Array(i*2);for(let e=0;e<i;e++){let i=t[e];a[2*e]=n(i),a[2*e+1]=r(i)}return new e(a)}constructor(e){let t=e.length>>1;if(t>0&&typeof e[0]!=`number`)throw Error(`Expected coords to contain numbers.`);this.coords=e;let n=Math.max(2*t-5,0);this._triangles=new Uint32Array(n*3),this._halfedges=new Int32Array(n*3),this._hashSize=Math.ceil(Math.sqrt(t)),this._hullPrev=new Uint32Array(t),this._hullNext=new Uint32Array(t),this._hullTri=new Uint32Array(t),this._hullHash=new Int32Array(this._hashSize),this._ids=new Uint32Array(t),this._dists=new Float64Array(t),this.trianglesLen=0,this._cx=0,this._cy=0,this._hullStart=0,this.hull=this._triangles,this.triangles=this._triangles,this.halfedges=this._halfedges,this.update()}update(){let{coords:e,_hullPrev:t,_hullNext:n,_hullTri:r,_hullHash:i}=this,a=e.length>>1,o=1/0,s=1/0,c=-1/0,l=-1/0;for(let t=0;t<a;t++){let n=e[2*t],r=e[2*t+1];n<o&&(o=n),r<s&&(s=r),n>c&&(c=n),r>l&&(l=r),this._ids[t]=t}let u=(o+c)/2,d=(s+l)/2,f=0,p=0,m=0;for(let t=0,n=1/0;t<a;t++){let r=u1(u,d,e[2*t],e[2*t+1]);r<n&&(f=t,n=r)}let h=e[2*f],g=e[2*f+1];for(let t=0,n=1/0;t<a;t++){if(t===f)continue;let r=u1(h,g,e[2*t],e[2*t+1]);r<n&&r>0&&(p=t,n=r)}let _=e[2*p],v=e[2*p+1],y=1/0;for(let t=0;t<a;t++){if(t===f||t===p)continue;let n=f1(h,g,_,v,e[2*t],e[2*t+1]);n<y&&(m=t,y=n)}let b=e[2*m],x=e[2*m+1];if(y===1/0){for(let t=0;t<a;t++)this._dists[t]=e[2*t]-e[0]||e[2*t+1]-e[1];m1(this._ids,this._dists,0,a-1);let t=new Uint32Array(a),n=0;for(let e=0,r=-1/0;e<a;e++){let i=this._ids[e],a=this._dists[i];a>r&&(t[n++]=i,r=a)}this.hull=t.subarray(0,n),this.triangles=new Uint32Array,this.halfedges=new Int32Array;return}if(a1(h,g,_,v,b,x)<0){let e=p,t=_,n=v;p=m,_=b,v=x,m=e,b=t,x=n}let S=p1(h,g,_,v,b,x);this._cx=S.x,this._cy=S.y;for(let t=0;t<a;t++)this._dists[t]=u1(e[2*t],e[2*t+1],S.x,S.y);m1(this._ids,this._dists,0,a-1),this._hullStart=f;let C=3;n[f]=t[m]=p,n[p]=t[f]=m,n[m]=t[p]=f,r[f]=0,r[p]=1,r[m]=2,i.fill(-1),i[this._hashKey(h,g)]=f,i[this._hashKey(_,v)]=p,i[this._hashKey(b,x)]=m,this.trianglesLen=0,this._addTriangle(f,p,m,-1,-1,-1);for(let a=0,o=0,s=0;a<this._ids.length;a++){let c=this._ids[a],l=e[2*c],u=e[2*c+1];if(a>0&&Math.abs(l-o)<=o1&&Math.abs(u-s)<=o1||(o=l,s=u,c===f||c===p||c===m))continue;let d=0;for(let e=0,t=this._hashKey(l,u);e<this._hashSize&&(d=i[(t+e)%this._hashSize],!(d!==-1&&d!==n[d]));e++);d=t[d];let h=d,g;for(;g=n[h],a1(l,u,e[2*h],e[2*h+1],e[2*g],e[2*g+1])>=0;)if(h=g,h===d){h=-1;break}if(h===-1)continue;let _=this._addTriangle(h,c,n[h],-1,-1,r[h]);r[c]=this._legalize(_+2),r[h]=_,C++;let v=n[h];for(;g=n[v],a1(l,u,e[2*v],e[2*v+1],e[2*g],e[2*g+1])<0;)_=this._addTriangle(v,c,g,r[c],-1,r[v]),r[c]=this._legalize(_+2),n[v]=v,C--,v=g;if(h===d)for(;g=t[h],a1(l,u,e[2*g],e[2*g+1],e[2*h],e[2*h+1])<0;)_=this._addTriangle(g,c,h,-1,r[h],r[g]),this._legalize(_+2),r[g]=_,n[h]=h,C--,h=g;this._hullStart=t[c]=h,n[h]=t[v]=c,n[c]=v,i[this._hashKey(l,u)]=c,i[this._hashKey(e[2*h],e[2*h+1])]=h}this.hull=new Uint32Array(C);for(let e=0,t=this._hullStart;e<C;e++)this.hull[e]=t,t=n[t];this.triangles=this._triangles.subarray(0,this.trianglesLen),this.halfedges=this._halfedges.subarray(0,this.trianglesLen)}_hashKey(e,t){return Math.floor(l1(e-this._cx,t-this._cy)*this._hashSize)%this._hashSize}_legalize(e){let{_triangles:t,_halfedges:n,coords:r}=this,i=0,a=0;for(;;){let o=n[e],s=e-e%3;if(a=s+(e+2)%3,o===-1){if(i===0)break;e=s1[--i];continue}let c=o-o%3,l=s+(e+1)%3,u=c+(o+2)%3,d=t[a],f=t[e],p=t[l],m=t[u];if(d1(r[2*d],r[2*d+1],r[2*f],r[2*f+1],r[2*p],r[2*p+1],r[2*m],r[2*m+1])){t[e]=m,t[o]=d;let r=n[u];if(r===-1){let t=this._hullStart;do{if(this._hullTri[t]===u){this._hullTri[t]=e;break}t=this._hullPrev[t]}while(t!==this._hullStart)}this._link(e,r),this._link(o,n[a]),this._link(a,u);let s=c+(o+1)%3;i<s1.length&&(s1[i++]=s)}else{if(i===0)break;e=s1[--i]}}return a}_link(e,t){this._halfedges[e]=t,t!==-1&&(this._halfedges[t]=e)}_addTriangle(e,t,n,r,i,a){let o=this.trianglesLen;return this._triangles[o]=e,this._triangles[o+1]=t,this._triangles[o+2]=n,this._link(o,r),this._link(o+1,i),this._link(o+2,a),this.trianglesLen+=3,o}};function l1(e,t){let n=e/(Math.abs(e)+Math.abs(t));return(t>0?3-n:1+n)/4}function u1(e,t,n,r){let i=e-n,a=t-r;return i*i+a*a}function d1(e,t,n,r,i,a,o,s){let c=e-o,l=t-s,u=n-o,d=r-s,f=i-o,p=a-s,m=c*c+l*l,h=u*u+d*d,g=f*f+p*p;return c*(d*g-h*p)-l*(u*g-h*f)+m*(u*p-d*f)<0}function f1(e,t,n,r,i,a){let o=n-e,s=r-t,c=i-e,l=a-t,u=o*o+s*s,d=c*c+l*l,f=.5/(o*l-s*c),p=(l*u-s*d)*f,m=(o*d-c*u)*f;return p*p+m*m}function p1(e,t,n,r,i,a){let o=n-e,s=r-t,c=i-e,l=a-t,u=o*o+s*s,d=c*c+l*l,f=.5/(o*l-s*c);return{x:e+(l*u-s*d)*f,y:t+(o*d-c*u)*f}}function m1(e,t,n,r){if(r-n<=20)for(let i=n+1;i<=r;i++){let r=e[i],a=t[r],o=i-1;for(;o>=n&&t[e[o]]>a;)e[o+1]=e[o--];e[o+1]=r}else{let i=n+r>>1,a=n+1,o=r;h1(e,i,a),t[e[n]]>t[e[r]]&&h1(e,n,r),t[e[a]]>t[e[r]]&&h1(e,a,r),t[e[n]]>t[e[a]]&&h1(e,n,a);let s=e[a],c=t[s];for(;;){do a++;while(t[e[a]]<c);do o--;while(t[e[o]]>c);if(o<a)break;h1(e,a,o)}e[n+1]=e[o],e[o]=s,r-a+1>=o-n?(m1(e,t,a,r),m1(e,t,n,o-1)):(m1(e,t,n,o-1),m1(e,t,a,r))}}function h1(e,t,n){let r=e[t];e[t]=e[n],e[n]=r}function g1(e){return e[0]}function _1(e){return e[1]}var v1=`
|
|
394
|
+
void main() { o = vec4(0.0); }`;function J$(e,t,n,r){let i=bX(e,e.VERTEX_SHADER,t),a=bX(e,e.FRAGMENT_SHADER,n);if(!i||!a)return null;let o=e.createProgram();return e.attachShader(o,i),e.attachShader(o,a),r&&e.transformFeedbackVaryings(o,r,e.SEPARATE_ATTRIBS),e.linkProgram(o),e.getProgramParameter(o,e.LINK_STATUS)?{prog:o,shaders:[i,a]}:(console.error(`glPoints program link failed:`,e.getProgramInfoLog(o)),null)}function Y$(e,t){if(!e)return[{v:0,a:0,b:t}];let n=[];for(let r=0;r<t;r++)r===0||e[r]!==e[r-1]?n.push({v:e[r],a:r,b:r+1}):n[n.length-1].b=r+1;return n}function X$(e,t,n,r,i,a){let o=[],s=0;for(let c of a){let a=n.filter(e=>e.v===c.v);if(a.length>1)return null;let l=-1;if(a.length===1){for(let n=a[0].a;n<a[0].b;n++)if(e[n]===r[c.a]&&t[n]===i[c.a]){l=n;break}}if(l<0){o.push({src:0,len:0});continue}let u=Math.min(a[0].b-l,c.b-c.a);for(let n=0;n<u;n++)if(e[l+n]!==r[c.a+n]||t[l+n]!==i[c.a+n])return null;o.push({src:l,len:u}),s+=u}return s>0?o:null}function Z$(e){let t=e.getContext(`webgl2`,{antialias:!1,alpha:!0,premultipliedAlpha:!0});if(!t)return null;let n=MX(t,`glPoints|points`,()=>J$(t,R$,z$)),r=MX(t,`glPoints|lines`,()=>J$(t,H$,U$)),i=MX(t,`glPoints|points64`,()=>J$(t,G$(R$,[`a_x`],[`a_y`],!0),z$)),a=MX(t,`glPoints|sprites`,()=>J$(t,B$,V$)),o=MX(t,`glPoints|sprites64`,()=>J$(t,G$(B$,[`a_x`],[`a_y`],!0),V$)),s=MX(t,`glPoints|maxSprite`,()=>t.getParameter(t.ALIASED_POINT_SIZE_RANGE)[1]),c=MX(t,`glPoints|decode`,()=>J$(t,K$,q$,[`v_x`,`v_y`])),l=t.createVertexArray();if(!n||!r)return null;let u=(e,n)=>Object.fromEntries(n.map(n=>[n,t.getAttribLocation(e,n)])),d=(e,n)=>Object.fromEntries(n.map(n=>[n,t.getUniformLocation(e,n)])),f=u(n.prog,[`a_corner`,`a_x`,`a_y`,`a_k`,`a_r`]),p=d(n.prog,[`u_resolution`,`u_plot`,`u_view`,`u_radius`,`u_kScale`,`u_palette`,`u_alpha`,`u_clip`,`u_dpr`,`u_height`]),m=u(r.prog,[`a_corner`,`a_ax`,`a_ay`,`a_bx`,`a_by`,`a_bstart`,`a_k`]),h=d(r.prog,[`u_resolution`,`u_plot`,`u_view`,`u_ext`,`u_kScale`,`u_palette`,`u_half`,`u_clip`]),g=i&&u(i.prog,[`a_corner`,`a_x_bits`,`a_y_bits`,`a_k`,`a_r`]),_=i&&d(i.prog,[`u_resolution`,`u_plot`,`u_view`,`u_radius`,`u_kScale`,`u_palette`,`u_alpha`,`u_clip`,`u_dpr`,`u_height`,`u_ox`,`u_oy`]),v=[`u_resolution`,`u_plot`,`u_view`,`u_radius`,`u_kScale`,`u_palette`,`u_alpha`,`u_clip`,`u_dpr`,`u_height`],y=a&&u(a.prog,[`a_x`,`a_y`,`a_k`]),b=a&&d(a.prog,v),x=o&&u(o.prog,[`a_x_bits`,`a_y_bits`,`a_k`]),S=o&&d(o.prog,[...v,`u_ox`,`u_oy`]),C=c&&u(c.prog,[`a_x_bits`,`a_y_bits`]),w=c&&d(c.prog,[`u_ox`,`u_oy`]),T=t.createTransformFeedback(),E=t.createVertexArray(),D=t.createBuffer(),O=t.createBuffer(),k=!1,A=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,A),t.bufferData(t.ARRAY_BUFFER,Float32Array.from([-1,-1,1,-1,-1,1,1,1]),t.STATIC_DRAW);let j=t.createBuffer(),M=t.createBuffer(),N=t.createBuffer(),P=t.createBuffer(),F=t.createBuffer(),I=t.createBuffer(),L=t.createBuffer(),R=t.createBuffer(),z=null,B=t.createTexture(),V=0,ee=!1,H=!1,U=!1,te=0,W=0,ne=1,G=1,re=1,ie=1.8,ae=.8,oe=255,se=!0,ce=!1,le=1,ue={xmin:0,xmax:1,ymin:0,ymax:1},de={left:0,top:0,width:1,height:1},fe=new Float32Array,pe=new Float32Array,me=new Float32Array,he=new Uint8Array,ge=new Float32Array,_e=new Map,ve=(e,n,r)=>{t.bindBuffer(t.ARRAY_BUFFER,e);let i=r*n.BYTES_PER_ELEMENT;i<=(_e.get(e)??0)?t.bufferSubData(t.ARRAY_BUFFER,0,n,0,r):(t.bufferData(t.ARRAY_BUFFER,n.subarray(0,r),t.DYNAMIC_DRAW),_e.set(e,i))},ye=(e,n,r,i,a,o)=>{let s=r.BYTES_PER_ELEMENT;if(t.bindBuffer(t.ARRAY_BUFFER,n),(_e.get(n)??0)<o*s){let e=Math.ceil(o*1.25)*s;t.bufferData(t.ARRAY_BUFFER,e,t.DYNAMIC_DRAW),_e.set(n,e)}t.bindBuffer(t.COPY_READ_BUFFER,e),t.bindBuffer(t.COPY_WRITE_BUFFER,n),i.forEach((e,n)=>{a[n].len&&t.copyBufferSubData(t.COPY_READ_BUFFER,t.COPY_WRITE_BUFFER,a[n].src*s,e.a*s,a[n].len*s)}),t.bindBuffer(t.COPY_READ_BUFFER,null),t.bindBuffer(t.COPY_WRITE_BUFFER,null),i.forEach((e,n)=>{let i=e.a+a[n].len;e.b>i&&t.bufferSubData(t.ARRAY_BUFFER,i*s,r,i,e.b-i)})},be=(e,n,r=0,i=t.FLOAT)=>{t.bindBuffer(t.ARRAY_BUFFER,n),t.enableVertexAttribArray(e);let a=i===t.FLOAT?4:1;t.vertexAttribPointer(e,1,i,i!==t.FLOAT,a,r*a),t.vertexAttribDivisor(e,1)},xe=(e,n,r=0)=>{t.bindBuffer(t.ARRAY_BUFFER,n),t.enableVertexAttribArray(e),t.vertexAttribIPointer(e,2,t.UNSIGNED_INT,8,r*8),t.vertexAttribDivisor(e,1)},Se=e=>{t.bindBuffer(t.ARRAY_BUFFER,A),t.enableVertexAttribArray(e),t.vertexAttribPointer(e,2,t.FLOAT,!1,0,0),t.vertexAttribDivisor(e,0)};return{resize(t,n,r){ne=Math.max(1,t),G=Math.max(1,n),re=r,e.width=Math.round(ne*re),e.height=Math.round(G*re)},setData(e,t,n,r=!1,i){let a=Math.min(e.length,t.length);fe.length<a&&(fe=new Float32Array(a),pe=new Float32Array(a)),ee=!!n,H=!!i,n&&me.length<a&&(me=new Float32Array(a)),i&&ge.length<a&&(ge=new Float32Array(a)),ce&&he.length<a&&(he=new Uint8Array(a)),te=0,W=0;for(let n=0;n<a;n++)if(e[n]-e[n]===0&&t[n]-t[n]===0){te=e[n],W=t[n];break}let o=XG.has(e)&&XG.has(t);if(U=!!g&&!!c&&e instanceof Float64Array&&t instanceof Float64Array&&(o||!ce),k=!1,U){let o=e,s=t;if(n)for(let e=0;e<a;e++)me[e]=n[e];let c=Y$(n&&r?n:void 0,a),l=z&&(!n||r)?X$(z.x,z.y,z.runs,o,s,c):null;if(l?(ye(j,I,o,c,l,a),[j,I]=[I,j],ye(M,L,s,c,l,a),[M,L]=[L,M],n&&(ye(N,R,me,c,l,a),[N,R]=[R,N])):(ve(j,o,a),ve(M,s,a),n&&ve(N,me,a)),(!z||z.x.length<a)&&(z={x:new Float64Array(Math.ceil(a*1.25)),y:new Float64Array(Math.ceil(a*1.25)),runs:c,n:a}),z.x.set(o.subarray(0,a)),z.y.set(s.subarray(0,a)),z.runs=c,z.n=a,i){for(let e=0;e<a;e++)ge[e]=i[e];ve(F,ge,a)}if(ce){if(he.fill(0,0,a),a&&(he[0]=255),n&&r)for(let e=1;e<a;e++)n[e]!==n[e-1]&&(he[e]=255);ve(P,he,a)}V=a;return}z=null;let s=0;if(XG.has(e)&&XG.has(t)){for(let t=0;t<a;t++)fe[t]=e[t]-te;for(let e=0;e<a;e++)pe[e]=t[e]-W;if(n)for(let e=0;e<a;e++)me[e]=n[e];if(i)for(let e=0;e<a;e++)ge[e]=i[e];if(ce&&(he.fill(0,0,a),a&&(he[0]=255),n&&r))for(let e=1;e<a;e++)n[e]!==n[e-1]&&(he[e]=255);s=a}else{let o=!0;for(let c=0;c<a;c++){let a=e[c],l=t[c];if(a-a!==0||l-l!==0){o=!0;continue}fe[s]=a-te,pe[s]=l-W,n&&(me[s]=n[c]),i&&(ge[s]=i[c]),ce&&(he[s]=o||r&&n&&s>0&&n[c]!==me[s-1]?255:0),o=!1,s++}}V=s,ve(j,fe,s),ve(M,pe,s),n&&ve(N,me,s),i&&ve(F,ge,s),ce&&ve(P,he,s)},setStyle(e,n,r){ie=n,ae=r;let i=new Uint8Array(256*4);if(e.kind===`single`){let t=e.rgba.map(e=>Math.round(e*255));for(let e=0;e<256;e++)i.set(t,e*4);oe=0}else i.set(e.palette.subarray(0,256*4)),oe=e.kind===`colormap`?255:1;t.bindTexture(t.TEXTURE_2D,B),t.texImage2D(t.TEXTURE_2D,0,t.RGBA8,256,1,0,t.RGBA,t.UNSIGNED_BYTE,i),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE)},setDraw(e,t,n){se=e,ce=t,le=n},setView(e,t,n,r,i){ue={xmin:e,xmax:t,ymin:n,ymax:r},de=i},render(){if(t.bindFramebuffer(t.FRAMEBUFFER,null),t.viewport(0,0,e.width,e.height),t.disable(t.SCISSOR_TEST),t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT),V===0)return;t.bindVertexArray(l),t.enable(t.BLEND),t.blendFunc(t.ONE,t.ONE_MINUS_SRC_ALPHA),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,B);let u=ee?oe:0,d=[ue.xmin-te,ue.xmax-te,ue.ymin-W,ue.ymax-W],v=[de.left,de.top,de.left+de.width,de.top+de.height],A=e=>{let t=Math.fround(e);return[t,e-t]},I=U,L=j,R=M;if(U&&ce&&V>1){if(!k){for(let e of[D,O])t.bindBuffer(t.ARRAY_BUFFER,e),(_e.get(e)??0)<V*4&&(t.bufferData(t.ARRAY_BUFFER,V*4,t.DYNAMIC_COPY),_e.set(e,V*4));t.bindBuffer(t.ARRAY_BUFFER,null),t.bindVertexArray(E),t.useProgram(c.prog),t.uniform2f(w.u_ox,...A(te)),t.uniform2f(w.u_oy,...A(W)),xe(C.a_x_bits,j),xe(C.a_y_bits,M),t.vertexAttribDivisor(C.a_x_bits,0),t.vertexAttribDivisor(C.a_y_bits,0),t.enable(t.RASTERIZER_DISCARD),t.bindTransformFeedback(t.TRANSFORM_FEEDBACK,T),t.bindBufferBase(t.TRANSFORM_FEEDBACK_BUFFER,0,D),t.bindBufferBase(t.TRANSFORM_FEEDBACK_BUFFER,1,O),t.beginTransformFeedback(t.POINTS),t.drawArrays(t.POINTS,0,V),t.endTransformFeedback(),t.bindBufferBase(t.TRANSFORM_FEEDBACK_BUFFER,0,null),t.bindBufferBase(t.TRANSFORM_FEEDBACK_BUFFER,1,null),t.bindTransformFeedback(t.TRANSFORM_FEEDBACK,null),t.disable(t.RASTERIZER_DISCARD),t.bindVertexArray(l),k=!0}I=!1,L=D,R=O}if(ce&&V>1){let e=h,n=m;t.useProgram(r.prog),t.uniform2f(e.u_resolution,ne,G),t.uniform4f(e.u_plot,de.left,de.top,de.width,de.height),t.uniform4f(e.u_view,...d),t.uniform1f(e.u_half,le/2),t.uniform1f(e.u_ext,le/2+1),t.uniform1f(e.u_kScale,u),t.uniform4f(e.u_clip,...v),t.uniform1i(e.u_palette,0),Se(n.a_corner),be(n.a_ax,L,0),be(n.a_bx,L,1),be(n.a_ay,R,0),be(n.a_by,R,1),be(n.a_bstart,P,1,t.UNSIGNED_BYTE),ee?be(n.a_k,N,0):(t.disableVertexAttribArray(n.a_k),t.vertexAttrib1f(n.a_k,0)),t.drawArraysInstanced(t.TRIANGLE_STRIP,0,4,V-1);for(let e of Object.values(n))t.vertexAttribDivisor(e,0)}if(se&&!H&&2*(ie+.5)*re<=s&&(I?o:a)){let n=I?S:b,r=I?x:y;t.useProgram((I?o:a).prog),I&&(t.uniform2f(n.u_ox,...A(te)),t.uniform2f(n.u_oy,...A(W))),t.uniform2f(n.u_resolution,ne,G),t.uniform4f(n.u_plot,de.left,de.top,de.width,de.height),t.uniform4f(n.u_view,...d),t.uniform1f(n.u_radius,ie),t.uniform1f(n.u_kScale,u),t.uniform1f(n.u_alpha,ae),t.uniform4f(n.u_clip,...v),t.uniform1f(n.u_dpr,re),t.uniform1f(n.u_height,e.height),t.uniform1i(n.u_palette,0),I?(xe(r.a_x_bits,j),xe(r.a_y_bits,M)):(be(r.a_x,L),be(r.a_y,R)),ee?be(r.a_k,N):(t.disableVertexAttribArray(r.a_k),t.vertexAttrib1f(r.a_k,0));for(let e of Object.values(r))t.vertexAttribDivisor(e,0);t.drawArrays(t.POINTS,0,V)}else if(se){let r=I?_:p,a=I?g:f;t.useProgram(I?i.prog:n.prog),I&&(t.uniform2f(r.u_ox,...A(te)),t.uniform2f(r.u_oy,...A(W))),t.uniform2f(r.u_resolution,ne,G),t.uniform4f(r.u_plot,de.left,de.top,de.width,de.height),t.uniform4f(r.u_view,...d),t.uniform1f(r.u_radius,ie),t.uniform1f(r.u_kScale,u),t.uniform1f(r.u_alpha,ae),t.uniform4f(r.u_clip,...v),t.uniform1f(r.u_dpr,re),t.uniform1f(r.u_height,e.height),t.uniform1i(r.u_palette,0),Se(a.a_corner),I?(xe(a.a_x_bits,j),xe(a.a_y_bits,M)):(be(a.a_x,L),be(a.a_y,R)),ee?be(a.a_k,N):(t.disableVertexAttribArray(a.a_k),t.vertexAttrib1f(a.a_k,0)),H?be(a.a_r,F):(t.disableVertexAttribArray(a.a_r),t.vertexAttrib1f(a.a_r,0)),t.drawArraysInstanced(t.TRIANGLE_STRIP,0,4,V);for(let e of Object.values(a))t.vertexAttribDivisor(e,0)}t.bindVertexArray(null)},dispose(){for(let e of[A,j,M,N,P,F,D,O,I,L,R])t.deleteBuffer(e);t.deleteTransformFeedback(T),t.deleteVertexArray(E),t.deleteTexture(B),t.deleteVertexArray(l)}}}var Q$={top:3,right:3,bottom:3,left:3};function $$(e,t,n){return t<200||n<120?{...Q$,tiny:!0}:{...e,tiny:!1}}var e1={top:14,right:24,bottom:40,left:78},t1=70,n1=6,r1=8,i1=1.8;function a1(e,t,n){return Math.min(n,Math.max(t,e))}function o1(e,t){let n=e[t],r=1/0,i=-1/0;for(let t=0;t<e.length;t++){let e=n[t];e<r&&(r=e),e>i&&(i=e)}(!Number.isFinite(r)||r===i)&&(--r,i+=1);let a=(i-r)*.04;return{min:r-a,max:i+a}}function s1(e){return e===`dashed`?[5,4]:e===`dotted`?[1,4]:[]}function c1({points:e,xLabel:t,yLabel:n,color:r=`#38bdf8`,datasetColors:i,colorLabel:a,colorRange:o,height:s=400,pointRadius:c=i1,drawMode:l=`points`,lineWidth:u=1,backgroundToken:d=``,onPlotContextMenu:f,xAxisLine:p,yAxisLine:m,gridLine:h,fitSettings:g,xScale:_,yScale:v}){let y=iQ(),b=(0,Z.useRef)(null),x=(0,Z.useRef)(null),S=(0,Z.useRef)(null),C=(0,Z.useRef)(f);(0,Z.useLayoutEffect)(()=>{C.current=f},[f]);let w=(0,Z.useRef)(null),T=(0,Z.useRef)(null),E=(0,Z.useRef)(null),D=(0,Z.useRef)(null),O=(0,Z.useRef)(null),k=(0,Z.useRef)(0),A=(0,Z.useRef)(null),j=(0,Z.useMemo)(()=>v$(e)?e:y$(e),[e]),M=(0,Z.useRef)({cols:j,xLabel:t,yLabel:n,color:r,datasetColors:i,colorLabel:a,colorRange:o,height:s,pointRadius:c,drawMode:l,lineWidth:u,xAxisLine:p,yAxisLine:m,gridLine:h,fitSettings:g,xScale:_,yScale:v});(0,Z.useLayoutEffect)(()=>{M.current={cols:j,xLabel:t,yLabel:n,color:r,datasetColors:i,colorLabel:a,colorRange:o,height:s,pointRadius:c,drawMode:l,lineWidth:u,xAxisLine:p,yAxisLine:m,gridLine:h,fitSettings:g,xScale:_,yScale:v}},[j,t,n,r,i,a,o,s,c,l,u,p,m,h,g,_,v]);let N=(0,Z.useRef)({cols:null,value:{x:{min:0,max:1},y:{min:0,max:1}}});function P(){let e=M.current.cols,t=N.current;return t.cols!==e&&(t.value={x:o1(e,`x`),y:o1(e,`y`)},t.cols=e),t.value}(0,Z.useEffect)(()=>{T.current=null,E.current=null,D.current=null,O.current=null},[t,n]);function F(){let e=P(),t=T.current,n=E.current,r=D.current,i=O.current;return{xmin:t!==null&&n!==null&&n>t?t:e.x.min,xmax:t!==null&&n!==null&&n>t?n:e.x.max,ymin:r!==null&&i!==null&&i>r?r:e.y.min,ymax:r!==null&&i!==null&&i>r?i:e.y.max}}function I(){if(T.current!==null||D.current!==null)return F();let{xScale:e,yScale:t}=M.current,n=e=>{if(!e)return null;let t=parseFloat(e.scaleMin),n=parseFloat(e.scaleMax);return Number.isFinite(t)&&Number.isFinite(n)&&t<n?{min:t,max:n}:null},r=n(e)??P().x,i=n(t)??P().y;return{xmin:r.min,xmax:r.max,ymin:i.min,ymax:i.max}}function L(){if(A.current)return A.current;let e=S.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`,accent:`#f97316`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`,accent:t.getPropertyValue(`--accent`).trim()||`#f97316`};return A.current=n,n}function R(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function z(){let e=S.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||M.current.height)}}let B=(0,Z.useRef)(null),V=(0,Z.useRef)(null),ee=(0,Z.useRef)({r:null,failed:!1,data:null,mode:``,style:``,size:``});function H(e,t){let n=ee.current;!n.r&&!n.failed&&V.current&&(n.r=NX(V.current,Z$),n.failed=!n.r);let r=n.r;if(!r||!V.current)return null;let{cols:i,color:a,datasetColors:o,pointRadius:s,drawMode:c,lineWidth:l}=M.current,u=Math.min(2,window.devicePixelRatio||1),d=`${e}x${t}@${u}`;n.size!==d&&(r.resize(e,t,u),V.current.style.width=`${e}px`,V.current.style.height=`${t}px`,n.size=d);let f=o&&o.length>0&&i.d?`dataset`:i.c?`colormap`:`single`,p=c!==`points`;r.setDraw(c!==`lines`,p,l),(n.data!==i||n.mode!==`${f}|${p}`)&&(r.setData(i.x,i.y,f===`dataset`?i.d:f===`colormap`?i.c:void 0,f===`dataset`),n.data=i,n.mode=`${f}|${p}`);let m=`${f}|${a}|${f===`dataset`?o.join(`,`):``}|${s}`;return n.style!==m&&(r.setStyle(u1(f,a,o),Math.max(.25,s),.8),n.style=m),r}(0,Z.useEffect)(()=>()=>{ee.current.r?.dispose(),ee.current.r=null},[]);let U=(0,Z.useRef)({cols:null,key:``,coeffs:null});function te(e,t,n){let r=`${t}|${n.xmin}|${n.xmax}|${n.ymin}|${n.ymax}`,i=U.current;return(i.cols!==e||i.key!==r)&&(U.current={cols:e,key:r,coeffs:j$(e,t,n)}),U.current.coeffs}let W=(0,Z.useRef)({pts:null,view:``}),ne=(0,Z.useRef)(``);function G(){let e=b.current;if(!e)return;let{w:t,h:n}=z(),r=R(e,t,n);if(!r)return;let{cols:i,xLabel:a,yLabel:o,color:s,datasetColors:c,colorLabel:l,colorRange:u,pointRadius:d,xAxisLine:f,yAxisLine:p,gridLine:m,fitSettings:h,xScale:g,yScale:_}=M.current,v=!!c&&c.length>0&&!!i.d,x=!v&&i.length>0&&!!i.c,C=$$(e1,t,n),w=C.tiny?C.right:x?t1:C.right,{top:T,bottom:E,left:D}=C,O=t-D-w,k=n-T-E,{bg:A,muted:j,grid:N,accent:P}=L(),F=Math.max(.25,d),V=H(t,n),ee=i.length>=1&&O>0&&k>0?I():null,U=[t,n,e.width,ee&&`${ee.xmin}|${ee.xmax}|${ee.ymin}|${ee.ymax}`,a,o,x,v,l,u?.join(),JSON.stringify([f,p,m,g,_]),A,j,N,P].join(`§`);if(V&&ee&&!h&&ne.current===U){let e=W.current;e.pts!==i&&(W.current={pts:i,view:e.view},lZ(S.current)),V.setView(ee.xmin,ee.xmax,ee.ymin,ee.ymax,{left:D,top:T,width:O,height:k}),V.render();return}ne.current=U,r.fillStyle=A,r.fillRect(0,0,t,n);let G=B.current?R(B.current,t,n):null;G?.clearRect(0,0,t,n);let re=V;if(i.length<1||O<=0||k<=0){re?.render(),r.fillStyle=j,r.font=`13px ${X.sans}`,eX(r);return}let{xmin:ie,xmax:ae,ymin:oe,ymax:se}=I(),ce=ae-ie,le=se-oe,ue=e=>D+(e-ie)/ce*O;y({left:D,top:T,width:O,height:k,x:{v0:ie,v1:ae}});let de=e=>T+(se-e)/le*k,fe=(()=>{if(_?.majorStep){let e=parseFloat(_.majorStep);if(Number.isFinite(e)&&e>0)return e}return MJ(le,6)})(),pe=FJ(oe,se,fe);if((p?.style??`dashed`)!==`none`){r.strokeStyle=p?.color??N,r.lineWidth=p?.width??1,r.setLineDash(s1(p?.style??`dashed`));for(let e of pe){let t=de(e);r.beginPath(),r.moveTo(D,t),r.lineTo(D+O,t),r.stroke()}r.setLineDash([])}r.strokeStyle=j,r.lineWidth=1,r.fillStyle=j,r.font=`11px ${X.mono}`,r.textAlign=`right`,r.textBaseline=`middle`;for(let e of C.tiny?[]:pe){let t=de(e);r.beginPath(),r.moveTo(D-n1,t),r.lineTo(D,t),r.stroke(),r.fillText(zJ(e,fe),D-r1,t)}let me=(()=>{if(g?.majorStep){let e=parseFloat(g.majorStep);if(Number.isFinite(e)&&e>0)return e}return MJ(ce,NJ(O))})(),he=FJ(ie,ae,me);if((f?.style??`dashed`)!==`none`){r.strokeStyle=f?.color??N,r.lineWidth=f?.width??1,r.setLineDash(s1(f?.style??`dashed`));for(let e of he){let t=ue(e);r.beginPath(),r.moveTo(t,T),r.lineTo(t,T+k),r.stroke()}r.setLineDash([])}r.strokeStyle=j,r.lineWidth=1,r.fillStyle=j,r.textAlign=`center`,r.textBaseline=`top`;for(let e of C.tiny?[]:he){let t=ue(e);r.beginPath(),r.moveTo(t,T+k),r.lineTo(t,T+k+n1),r.stroke(),r.fillText(zJ(e,me),t,T+k+n1+2)}(m?.style??`solid`)!==`none`&&(r.strokeStyle=m?.color??N,r.lineWidth=m?.width??1,r.setLineDash(s1(m?.style??`solid`)),r.strokeRect(D,T,O,k),r.setLineDash([])),r.fillStyle=j,r.font=`11px ${X.mono}`,r.textAlign=`center`,r.textBaseline=`bottom`,C.tiny||(r.fillText(a,D+O/2,n-4),r.save(),r.translate(14,T+k/2),r.rotate(-Math.PI/2),r.fillText(o,0,0),r.restore());let ge=W.current;if((ge.pts!==i||ge.view!==`${ie}|${ae}|${oe}|${se}`)&&(W.current={pts:i,view:`${ie}|${ae}|${oe}|${se}`},lZ(S.current)),re)re.setView(ie,ae,oe,se,{left:D,top:T,width:O,height:k}),re.render();else{let e={xToPx:ue,yToPx:de,left:D,top:T,plotW:O,plotH:k,dotR:F,col:s,dsColors:v?c:null,hasColormap:x};M.current.drawMode!==`points`&&f1(r,i,e,M.current.lineWidth),M.current.drawMode!==`lines`&&d1(r,i,e)}if(x&&!C.tiny){let e=D+O+10,n=k;for(let t=0;t<64;t++)r.fillStyle=I$(1-t/64),r.fillRect(e,T+t/64*n,10,n/64+1);r.strokeStyle=j,r.lineWidth=.5,r.strokeRect(e,T,10,n),r.fillStyle=j,r.font=`10px ${X.mono}`,r.textAlign=`left`,r.textBaseline=`top`;let i=u?String(u[1].toPrecision(3)):`1`,a=u?String(u[0].toPrecision(3)):`0`;r.fillText(i,e+10+3,T),r.textBaseline=`bottom`,r.fillText(a,e+10+3,T+n),l&&(r.save(),r.textBaseline=`middle`,r.translate(t-6,T+n/2),r.rotate(Math.PI/2),r.fillText(l,0,0),r.restore())}if(h&&G){let e=te(i,h.degree,{xmin:ie,xmax:ae,ymin:oe,ymax:se});if(e){G.save(),G.beginPath(),G.rect(D,T,O,k),G.clip(),G.strokeStyle=h.color,G.lineWidth=h.width,G.setLineDash(s1(h.lineStyle)),G.beginPath();for(let t=0;t<=300;t++){let n=ie+t/300*ce,r=e.reduce((e,t,r)=>e+t*n**+r,0),i=ue(n),a=de(r);t===0?G.moveTo(i,a):G.lineTo(i,a)}G.stroke(),G.setLineDash([]);let t=N$(e,`x`,`y`);G.fillStyle=P,G.font=`10px ${X.mono}`,G.textAlign=`right`,G.textBaseline=`top`,G.fillText(t,D+O-8,T+8),G.restore()}}if((g?.alarm||_?.alarm)&&G){if(G.save(),G.beginPath(),G.rect(D,T,O,k),G.clip(),g?.alarm){let e=g.alarm;G.strokeStyle=e.color,G.lineWidth=e.width,G.setLineDash(e.linked===`active`?oQ:s1(e.style));let t=ue(e.value);G.beginPath(),G.moveTo(t,T),G.lineTo(t,T+k),G.stroke(),G.setLineDash([]),e.linked&&cQ(G,t+3,T+2,e.color)}if(_?.alarm){let e=_.alarm;G.strokeStyle=e.color,G.lineWidth=e.width,G.setLineDash(e.linked===`active`?oQ:s1(e.style));let t=de(e.value);G.beginPath(),G.moveTo(D,t),G.lineTo(D+O,t),G.stroke(),G.setLineDash([]),e.linked&&cQ(G,D+O-10-3,t-10-2,e.color)}G.restore()}}let re=(0,Z.useRef)(``);function ie(){let e=x.current;if(!e)return;let{w:t,h:n}=z(),r=`${t}x${n}`;if(w.current===null&&re.current===r)return;let i=R(e,t,n);if(!i)return;i.clearRect(0,0,t,n),re.current=w.current===null?r:``;let a=w.current,{cols:o,color:s,datasetColors:c,pointRadius:l}=M.current;if(a===null||a>=o.length||o.length<1)return;let u=Math.max(4,l*2),d=o.d?.[a],f=c&&c.length>0&&d!==void 0?c[d]??s:s,{top:p,right:m,bottom:h,left:g}=$$(e1,t,n),_=t-g-m,v=n-p-h;if(_<=0||v<=0)return;let{xmin:y,xmax:b,ymin:S,ymax:C}=I(),T=b-y,E=C-S,D={x:o.x[a],y:o.y[a]},O=g+(D.x-y)/T*_,k=p+(C-D.y)/E*v,{bg:A,muted:j}=L();i.strokeStyle=j,i.globalAlpha=.4,i.lineWidth=1,i.setLineDash([3,3]),i.beginPath(),i.moveTo(O,p),i.lineTo(O,p+v),i.stroke(),i.beginPath(),i.moveTo(g,k),i.lineTo(g+_,k),i.stroke(),i.setLineDash([]),i.globalAlpha=1,i.fillStyle=f,i.beginPath(),i.arc(O,k,u,0,Math.PI*2),i.fill(),i.strokeStyle=A,i.lineWidth=1.5,i.beginPath(),i.arc(O,k,u,0,Math.PI*2),i.stroke();let N=`(${BJ(D.x)}, ${BJ(D.y)})`;i.font=`11px ${X.mono}`;let P=i.measureText(N).width+12,F=O+10,B=k-24;F+P>g+_&&(F=O-P-10),B<p&&(B=k+10),i.fillStyle=A,i.globalAlpha=.85,i.beginPath(),l1(i,F,B,P,20,4),i.fill(),i.globalAlpha=1,i.strokeStyle=j,i.lineWidth=.5,i.beginPath(),l1(i,F,B,P,20,4),i.stroke(),i.fillStyle=j,i.textAlign=`left`,i.textBaseline=`middle`,i.fillText(N,F+6,B+20/2)}let ae=(0,Z.useRef)(G),oe=(0,Z.useRef)(ie);(0,Z.useLayoutEffect)(()=>{ae.current=G,oe.current=ie});let se=(0,Z.useRef)(null);se.current??=mZ(()=>{ae.current(),oe.current()},()=>S.current);function ce(){se.current.schedule()}function le(){k.current||=oZ(()=>{k.current=0,oe.current()})}(0,Z.useEffect)(()=>()=>{se.current?.cancel(),sZ(k.current),k.current=0},[]);let ue=(0,Z.useRef)(ce),de=(0,Z.useRef)(le);return(0,Z.useLayoutEffect)(()=>{ue.current=ce,de.current=le}),(0,Z.useEffect)(()=>sY(S.current,()=>{A.current=null,ue.current()}),[]),(0,Z.useEffect)(()=>{A.current=null,ue.current()},[d]),(0,Z.useEffect)(()=>{se.current.now()},[e,t,n,r,i,s,c,l,u,p,m,h,g,_,v]),(0,Z.useEffect)(()=>{let e=x.current,t=S.current;if(!e||!t)return;let n=new fZ(()=>{A.current=null,ue.current()});n.observe(t);let r=null;function i(e,t){let n=M.current.cols;if(n.length===0)return null;let{w:i,h:a}=z(),{top:o,right:s,bottom:c,left:l}=$$(e1,i,a),u=i-l-s,d=a-o-c,{xmin:f,xmax:p,ymin:m,ymax:h}=I(),g=p-f,_=h-m,v=Math.max(12,M.current.pointRadius*10),y=`${i}|${a}|${f}|${p}|${m}|${h}|${v}`;if(!r||r.cols!==n||r.key!==y){let e=Math.max(1,Math.ceil(u/v)),t=Math.max(1,Math.ceil(d/v)),i=t=>{let r=(n.x[t]-f)/g*u,i=(h-n.y[t])/_*d;return r>=0&&r<u&&i>=0&&i<d?Math.floor(i/v)*e+Math.floor(r/v):-1},a=new Uint32Array(e*t+1);for(let e=0;e<n.length;e++){let t=i(e);t>=0&&a[t+1]++}for(let n=0;n<e*t;n++)a[n+1]+=a[n];let o=a.slice(0,e*t),s=new Uint32Array(a[e*t]);for(let e=0;e<n.length;e++){let t=i(e);t>=0&&(s[o[t]++]=e)}r={cols:n,key:y,cell:v,nx:e,start:a,ix:s}}let b=r,x=Math.floor((e-l)/b.cell),S=Math.floor((t-o)/b.cell),C=(b.start.length-1)/b.nx,w=-1,T=v*v;for(let r=S-1;r<=S+1;r++)if(!(r<0||r>=C))for(let i=x-1;i<=x+1;i++){if(i<0||i>=b.nx)continue;let a=r*b.nx+i;for(let r=b.start[a];r<b.start[a+1];r++){let i=b.ix[r],a=l+(n.x[i]-f)/g*u,s=o+(h-n.y[i])/_*d,c=(a-e)**2+(s-t)**2;c<T&&(T=c,w=i)}}return w<0?null:w}let a=t=>{if(M.current.cols.length<1){w.current!==null&&(w.current=null,de.current());return}let n=e.getBoundingClientRect(),r=t.clientX-n.left,a=t.clientY-n.top,{left:o,top:s,right:c,bottom:l}=$$(e1,n.width,n.height),u=Math.max(1,n.width-o-c),d=n.height-s-l;if(r<o||r>o+u||a<s||a>s+d){w.current!==null&&(w.current=null,de.current());return}let f=i(r,a);w.current!==f&&(w.current=f,de.current())},o=()=>{w.current!==null&&(w.current=null,de.current())},s=t=>{if(M.current.cols.length<1)return;let n=e.getBoundingClientRect(),r=t.clientX-n.left,i=t.clientY-n.top,{top:a,left:o,right:s,bottom:c}=$$(e1,n.width,n.height),l=Math.max(1,n.width-o-s),u=Math.max(1,n.height-a-c);if(r<o||r>o+l||i<a||i>a+u)return;t.preventDefault();let d=P(),f=d.x.max-d.x.min,p=d.y.max-d.y.min,m=I(),h=m.xmin,g=m.xmax,_=m.ymin,v=m.ymax,y=g-h,b=v-_,x=(r-o)/l,S=(i-a)/u,C=h+x*y,w=v-S*b,k=t.deltaY<0,A=.88,j=k?A:1/A,N=y*j,F=b*j;if(!k&&N>=f*.999&&F>=p*.999){T.current=null,E.current=null,D.current=null,O.current=null,ue.current();return}N=a1(N,Math.max(f*1e-7,1e-12),f),F=a1(F,Math.max(p*1e-7,1e-12),p);let L=C-x*N,R=C+(1-x)*N;L<d.x.min&&(R+=d.x.min-L,L=d.x.min),R>d.x.max&&(L-=R-d.x.max,R=d.x.max);let z=w-(1-S)*F,B=w+S*F;z<d.y.min&&(B+=d.y.min-z,z=d.y.min),B>d.y.max&&(z-=B-d.y.max,B=d.y.max),T.current=L,E.current=R,D.current=z,O.current=B,ue.current()},c=e=>{e.button===0&&(T.current===null&&D.current===null||(T.current=null,E.current=null,D.current=null,O.current=null,ue.current(),de.current()))},l=e=>{e.preventDefault(),C.current?.({clientX:e.clientX,clientY:e.clientY})};return e.addEventListener(`mousemove`,a),e.addEventListener(`mouseleave`,o),e.addEventListener(`wheel`,s,{passive:!1}),e.addEventListener(`contextmenu`,l),e.addEventListener(`dblclick`,c),()=>{n.disconnect(),e.removeEventListener(`mousemove`,a),e.removeEventListener(`mouseleave`,o),e.removeEventListener(`wheel`,s),e.removeEventListener(`contextmenu`,l),e.removeEventListener(`dblclick`,c)}},[]),(0,Q.jsxs)(`div`,{ref:S,className:`chart-canvas-wrap`,children:[(0,Q.jsx)(`canvas`,{ref:b,className:`chart-canvas`,role:`img`,"aria-label":`Scatter ${t} vs ${n}`}),(0,Q.jsx)(`canvas`,{ref:V,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),(0,Q.jsx)(`canvas`,{ref:B,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),(0,Q.jsx)(`canvas`,{ref:x,className:`chart-canvas chart-overlay`})]})}function l1(e,t,n,r,i,a){e.moveTo(t+a,n),e.lineTo(t+r-a,n),e.arcTo(t+r,n,t+r,n+a,a),e.lineTo(t+r,n+i-a),e.arcTo(t+r,n+i,t+r-a,n+i,a),e.lineTo(t+a,n+i),e.arcTo(t,n+i,t,n+i-a,a),e.lineTo(t,n+a),e.arcTo(t,n,t+a,n,a)}function u1(e,t,n){if(e===`single`)return{kind:`single`,rgba:hX(t)};let r=new Uint8Array(256*4);for(let t=0;t<256;t++)if(e===`colormap`){let{r:e,g:n,b:i}=F$(t/255);r.set([e,n,i,255],t*4)}else{let e=hX(n[Math.min(t,n.length-1)]);r.set([e[0]*255,e[1]*255,e[2]*255,e[3]*255],t*4)}return{kind:e===`colormap`?`colormap`:`dataset`,palette:r}}function d1(e,t,n){let r=Math.PI*2,i=n.dsColors?n.dsColors.length:n.hasColormap?24:1,a=Array.from({length:i},()=>new Path2D);for(let e=0;e<t.length;e++){let o=n.xToPx(t.x[e]),s=n.yToPx(t.y[e]);if(!(o>=n.left&&o<=n.left+n.plotW&&s>=n.top&&s<=n.top+n.plotH))continue;let c=n.dsColors?Math.min(t.d?.[e]??0,i-1):n.hasColormap?L$(t.c?.[e]??0,24):0;a[c].moveTo(o+n.dotR,s),a[c].arc(o,s,n.dotR,0,r)}e.globalAlpha=.8;for(let t=0;t<i;t++)e.fillStyle=n.dsColors?n.dsColors[t]:n.hasColormap?I$((t+.5)/24):n.col,e.fill(a[t]);e.globalAlpha=1}function f1(e,t,n,r){e.save(),e.beginPath(),e.rect(n.left,n.top,n.plotW,n.plotH),e.clip(),e.lineWidth=r;let i=n.dsColors?n.dsColors.length:1;for(let r=0;r<i;r++){e.beginPath();let i=!1;for(let a=0;a<t.length;a++){if(n.dsColors&&(t.d?.[a]??0)!==r){i=!1;continue}let o=t.x[a],s=t.y[a];if(o-o!==0||s-s!==0){i=!1;continue}i?e.lineTo(n.xToPx(o),n.yToPx(s)):(e.moveTo(n.xToPx(o),n.yToPx(s)),i=!0)}e.strokeStyle=n.dsColors?n.dsColors[r]:n.col,e.stroke()}e.restore()}var p1=11102230246251565e-32,m1=134217729,h1=(3+8*p1)*p1;function g1(e,t,n,r,i){let a,o,s,c,l=t[0],u=r[0],d=0,f=0;u>l==u>-l?(a=l,l=t[++d]):(a=u,u=r[++f]);let p=0;if(d<e&&f<n)for(u>l==u>-l?(o=l+a,s=a-(o-l),l=t[++d]):(o=u+a,s=a-(o-u),u=r[++f]),a=o,s!==0&&(i[p++]=s);d<e&&f<n;)u>l==u>-l?(o=a+l,c=o-a,s=a-(o-c)+(l-c),l=t[++d]):(o=a+u,c=o-a,s=a-(o-c)+(u-c),u=r[++f]),a=o,s!==0&&(i[p++]=s);for(;d<e;)o=a+l,c=o-a,s=a-(o-c)+(l-c),l=t[++d],a=o,s!==0&&(i[p++]=s);for(;f<n;)o=a+u,c=o-a,s=a-(o-c)+(u-c),u=r[++f],a=o,s!==0&&(i[p++]=s);return(a!==0||p===0)&&(i[p++]=a),p}function _1(e,t){let n=t[0];for(let r=1;r<e;r++)n+=t[r];return n}function $(e){return new Float64Array(e)}var v1=(3+16*p1)*p1,y1=(2+12*p1)*p1,b1=(9+64*p1)*p1*p1,x1=$(4),S1=$(8),C1=$(12),w1=$(16),T1=$(4);function E1(e,t,n,r,i,a,o){let s,c,l,u,d,f,p,m,h,g,_,v,y,b,x,S,C,w,T=e-i,E=n-i,D=t-a,O=r-a;b=T*O,f=m1*T,p=f-(f-T),m=T-p,f=m1*O,h=f-(f-O),g=O-h,x=m*g-(b-p*h-m*h-p*g),S=D*E,f=m1*D,p=f-(f-D),m=D-p,f=m1*E,h=f-(f-E),g=E-h,C=m*g-(S-p*h-m*h-p*g),_=x-C,d=x-_,x1[0]=x-(_+d)+(d-C),v=b+_,d=v-b,y=b-(v-d)+(_-d),_=y-S,d=y-_,x1[1]=y-(_+d)+(d-S),w=v+_,d=w-v,x1[2]=v-(w-d)+(_-d),x1[3]=w;let k=_1(4,x1),A=y1*o;if(k>=A||-k>=A||(d=e-T,s=e-(T+d)+(d-i),d=n-E,l=n-(E+d)+(d-i),d=t-D,c=t-(D+d)+(d-a),d=r-O,u=r-(O+d)+(d-a),s===0&&c===0&&l===0&&u===0)||(A=b1*o+h1*Math.abs(k),k+=T*u+O*s-(D*l+E*c),k>=A||-k>=A))return k;b=s*O,f=m1*s,p=f-(f-s),m=s-p,f=m1*O,h=f-(f-O),g=O-h,x=m*g-(b-p*h-m*h-p*g),S=c*E,f=m1*c,p=f-(f-c),m=c-p,f=m1*E,h=f-(f-E),g=E-h,C=m*g-(S-p*h-m*h-p*g),_=x-C,d=x-_,T1[0]=x-(_+d)+(d-C),v=b+_,d=v-b,y=b-(v-d)+(_-d),_=y-S,d=y-_,T1[1]=y-(_+d)+(d-S),w=v+_,d=w-v,T1[2]=v-(w-d)+(_-d),T1[3]=w;let j=g1(4,x1,4,T1,S1);b=T*u,f=m1*T,p=f-(f-T),m=T-p,f=m1*u,h=f-(f-u),g=u-h,x=m*g-(b-p*h-m*h-p*g),S=D*l,f=m1*D,p=f-(f-D),m=D-p,f=m1*l,h=f-(f-l),g=l-h,C=m*g-(S-p*h-m*h-p*g),_=x-C,d=x-_,T1[0]=x-(_+d)+(d-C),v=b+_,d=v-b,y=b-(v-d)+(_-d),_=y-S,d=y-_,T1[1]=y-(_+d)+(d-S),w=v+_,d=w-v,T1[2]=v-(w-d)+(_-d),T1[3]=w;let M=g1(j,S1,4,T1,C1);return b=s*u,f=m1*s,p=f-(f-s),m=s-p,f=m1*u,h=f-(f-u),g=u-h,x=m*g-(b-p*h-m*h-p*g),S=c*l,f=m1*c,p=f-(f-c),m=c-p,f=m1*l,h=f-(f-l),g=l-h,C=m*g-(S-p*h-m*h-p*g),_=x-C,d=x-_,T1[0]=x-(_+d)+(d-C),v=b+_,d=v-b,y=b-(v-d)+(_-d),_=y-S,d=y-_,T1[1]=y-(_+d)+(d-S),w=v+_,d=w-v,T1[2]=v-(w-d)+(_-d),T1[3]=w,w1[g1(M,C1,4,T1,w1)-1]}function D1(e,t,n,r,i,a){let o=(t-a)*(n-i),s=(e-i)*(r-a),c=o-s,l=Math.abs(o+s);return Math.abs(c)>=v1*l?c:-E1(e,t,n,r,i,a,l)}(7+56*p1)*p1,(3+28*p1)*p1,(26+288*p1)*p1*p1,$(4),$(4),$(4),$(4),$(4),$(4),$(4),$(4),$(4),$(8),$(8),$(8),$(4),$(8),$(8),$(16),$(12),$(192),$(192),(10+96*p1)*p1,(4+48*p1)*p1,(44+576*p1)*p1*p1,$(4),$(4),$(4),$(4),$(4),$(4),$(4),$(4),$(8),$(8),$(8),$(8),$(8),$(8),$(8),$(8),$(8),$(4),$(4),$(4),$(8),$(16),$(16),$(16),$(32),$(32),$(48),$(64),$(1152),$(1152),(16+224*p1)*p1,(5+72*p1)*p1,(71+1408*p1)*p1*p1,$(4),$(4),$(4),$(4),$(4),$(4),$(4),$(4),$(4),$(4),$(24),$(24),$(24),$(24),$(24),$(24),$(24),$(24),$(24),$(24),$(1152),$(1152),$(1152),$(1152),$(1152),$(2304),$(2304),$(3456),$(5760),$(8),$(8),$(8),$(16),$(24),$(48),$(48),$(96),$(192),$(384),$(384),$(384),$(768),$(96),$(96),$(96),$(1152);var O1=2**-52,k1=new Uint32Array(512),A1=class e{static from(t,n=R1,r=z1){let i=t.length,a=new Float64Array(i*2);for(let e=0;e<i;e++){let i=t[e];a[2*e]=n(i),a[2*e+1]=r(i)}return new e(a)}constructor(e){let t=e.length>>1;if(t>0&&typeof e[0]!=`number`)throw Error(`Expected coords to contain numbers.`);this.coords=e;let n=Math.max(2*t-5,0);this._triangles=new Uint32Array(n*3),this._halfedges=new Int32Array(n*3),this._hashSize=Math.ceil(Math.sqrt(t)),this._hullPrev=new Uint32Array(t),this._hullNext=new Uint32Array(t),this._hullTri=new Uint32Array(t),this._hullHash=new Int32Array(this._hashSize),this._ids=new Uint32Array(t),this._dists=new Float64Array(t),this.trianglesLen=0,this._cx=0,this._cy=0,this._hullStart=0,this.hull=this._triangles,this.triangles=this._triangles,this.halfedges=this._halfedges,this.update()}update(){let{coords:e,_hullPrev:t,_hullNext:n,_hullTri:r,_hullHash:i}=this,a=e.length>>1,o=1/0,s=1/0,c=-1/0,l=-1/0;for(let t=0;t<a;t++){let n=e[2*t],r=e[2*t+1];n<o&&(o=n),r<s&&(s=r),n>c&&(c=n),r>l&&(l=r),this._ids[t]=t}let u=(o+c)/2,d=(s+l)/2,f=0,p=0,m=0;for(let t=0,n=1/0;t<a;t++){let r=M1(u,d,e[2*t],e[2*t+1]);r<n&&(f=t,n=r)}let h=e[2*f],g=e[2*f+1];for(let t=0,n=1/0;t<a;t++){if(t===f)continue;let r=M1(h,g,e[2*t],e[2*t+1]);r<n&&r>0&&(p=t,n=r)}let _=e[2*p],v=e[2*p+1],y=1/0;for(let t=0;t<a;t++){if(t===f||t===p)continue;let n=P1(h,g,_,v,e[2*t],e[2*t+1]);n<y&&(m=t,y=n)}let b=e[2*m],x=e[2*m+1];if(y===1/0){for(let t=0;t<a;t++)this._dists[t]=e[2*t]-e[0]||e[2*t+1]-e[1];I1(this._ids,this._dists,0,a-1);let t=new Uint32Array(a),n=0;for(let e=0,r=-1/0;e<a;e++){let i=this._ids[e],a=this._dists[i];a>r&&(t[n++]=i,r=a)}this.hull=t.subarray(0,n),this.triangles=new Uint32Array,this.halfedges=new Int32Array;return}if(D1(h,g,_,v,b,x)<0){let e=p,t=_,n=v;p=m,_=b,v=x,m=e,b=t,x=n}let S=F1(h,g,_,v,b,x);this._cx=S.x,this._cy=S.y;for(let t=0;t<a;t++)this._dists[t]=M1(e[2*t],e[2*t+1],S.x,S.y);I1(this._ids,this._dists,0,a-1),this._hullStart=f;let C=3;n[f]=t[m]=p,n[p]=t[f]=m,n[m]=t[p]=f,r[f]=0,r[p]=1,r[m]=2,i.fill(-1),i[this._hashKey(h,g)]=f,i[this._hashKey(_,v)]=p,i[this._hashKey(b,x)]=m,this.trianglesLen=0,this._addTriangle(f,p,m,-1,-1,-1);for(let a=0,o=0,s=0;a<this._ids.length;a++){let c=this._ids[a],l=e[2*c],u=e[2*c+1];if(a>0&&Math.abs(l-o)<=O1&&Math.abs(u-s)<=O1||(o=l,s=u,c===f||c===p||c===m))continue;let d=0;for(let e=0,t=this._hashKey(l,u);e<this._hashSize&&(d=i[(t+e)%this._hashSize],!(d!==-1&&d!==n[d]));e++);d=t[d];let h=d,g;for(;g=n[h],D1(l,u,e[2*h],e[2*h+1],e[2*g],e[2*g+1])>=0;)if(h=g,h===d){h=-1;break}if(h===-1)continue;let _=this._addTriangle(h,c,n[h],-1,-1,r[h]);r[c]=this._legalize(_+2),r[h]=_,C++;let v=n[h];for(;g=n[v],D1(l,u,e[2*v],e[2*v+1],e[2*g],e[2*g+1])<0;)_=this._addTriangle(v,c,g,r[c],-1,r[v]),r[c]=this._legalize(_+2),n[v]=v,C--,v=g;if(h===d)for(;g=t[h],D1(l,u,e[2*g],e[2*g+1],e[2*h],e[2*h+1])<0;)_=this._addTriangle(g,c,h,-1,r[h],r[g]),this._legalize(_+2),r[g]=_,n[h]=h,C--,h=g;this._hullStart=t[c]=h,n[h]=t[v]=c,n[c]=v,i[this._hashKey(l,u)]=c,i[this._hashKey(e[2*h],e[2*h+1])]=h}this.hull=new Uint32Array(C);for(let e=0,t=this._hullStart;e<C;e++)this.hull[e]=t,t=n[t];this.triangles=this._triangles.subarray(0,this.trianglesLen),this.halfedges=this._halfedges.subarray(0,this.trianglesLen)}_hashKey(e,t){return Math.floor(j1(e-this._cx,t-this._cy)*this._hashSize)%this._hashSize}_legalize(e){let{_triangles:t,_halfedges:n,coords:r}=this,i=0,a=0;for(;;){let o=n[e],s=e-e%3;if(a=s+(e+2)%3,o===-1){if(i===0)break;e=k1[--i];continue}let c=o-o%3,l=s+(e+1)%3,u=c+(o+2)%3,d=t[a],f=t[e],p=t[l],m=t[u];if(N1(r[2*d],r[2*d+1],r[2*f],r[2*f+1],r[2*p],r[2*p+1],r[2*m],r[2*m+1])){t[e]=m,t[o]=d;let r=n[u];if(r===-1){let t=this._hullStart;do{if(this._hullTri[t]===u){this._hullTri[t]=e;break}t=this._hullPrev[t]}while(t!==this._hullStart)}this._link(e,r),this._link(o,n[a]),this._link(a,u);let s=c+(o+1)%3;i<k1.length&&(k1[i++]=s)}else{if(i===0)break;e=k1[--i]}}return a}_link(e,t){this._halfedges[e]=t,t!==-1&&(this._halfedges[t]=e)}_addTriangle(e,t,n,r,i,a){let o=this.trianglesLen;return this._triangles[o]=e,this._triangles[o+1]=t,this._triangles[o+2]=n,this._link(o,r),this._link(o+1,i),this._link(o+2,a),this.trianglesLen+=3,o}};function j1(e,t){let n=e/(Math.abs(e)+Math.abs(t));return(t>0?3-n:1+n)/4}function M1(e,t,n,r){let i=e-n,a=t-r;return i*i+a*a}function N1(e,t,n,r,i,a,o,s){let c=e-o,l=t-s,u=n-o,d=r-s,f=i-o,p=a-s,m=c*c+l*l,h=u*u+d*d,g=f*f+p*p;return c*(d*g-h*p)-l*(u*g-h*f)+m*(u*p-d*f)<0}function P1(e,t,n,r,i,a){let o=n-e,s=r-t,c=i-e,l=a-t,u=o*o+s*s,d=c*c+l*l,f=.5/(o*l-s*c),p=(l*u-s*d)*f,m=(o*d-c*u)*f;return p*p+m*m}function F1(e,t,n,r,i,a){let o=n-e,s=r-t,c=i-e,l=a-t,u=o*o+s*s,d=c*c+l*l,f=.5/(o*l-s*c);return{x:e+(l*u-s*d)*f,y:t+(o*d-c*u)*f}}function I1(e,t,n,r){if(r-n<=20)for(let i=n+1;i<=r;i++){let r=e[i],a=t[r],o=i-1;for(;o>=n&&t[e[o]]>a;)e[o+1]=e[o--];e[o+1]=r}else{let i=n+r>>1,a=n+1,o=r;L1(e,i,a),t[e[n]]>t[e[r]]&&L1(e,n,r),t[e[a]]>t[e[r]]&&L1(e,a,r),t[e[n]]>t[e[a]]&&L1(e,n,a);let s=e[a],c=t[s];for(;;){do a++;while(t[e[a]]<c);do o--;while(t[e[o]]>c);if(o<a)break;L1(e,a,o)}e[n+1]=e[o],e[o]=s,r-a+1>=o-n?(I1(e,t,a,r),I1(e,t,n,o-1)):(I1(e,t,n,o-1),I1(e,t,a,r))}}function L1(e,t,n){let r=e[t];e[t]=e[n],e[n]=r}function R1(e){return e[0]}function z1(e){return e[1]}var B1=`
|
|
395
395
|
uniform vec3 u_lo; // the box minimum, relative to the data origin
|
|
396
396
|
uniform vec3 u_span; // the box size (0: a flat axis)
|
|
397
397
|
uniform int u_flat; // 0: 3D camera, 1: a 2D view
|
|
@@ -427,17 +427,17 @@ vec4 place(vec3 d) {
|
|
|
427
427
|
float z = clamp(cz / 16.0, 0.0, 1.0) * 2.0 - 1.0;
|
|
428
428
|
return vec4(c.x * cz, -c.y * cz, z * cz, cz);
|
|
429
429
|
}
|
|
430
|
-
`,
|
|
430
|
+
`,V1=`bool outside(vec3 n) { return any(greaterThan(abs(n), vec3(1.0001))); }`,H1=`#version 300 es
|
|
431
431
|
in float a_x; in float a_y; in float a_z;
|
|
432
432
|
uniform float u_size;
|
|
433
|
-
${
|
|
434
|
-
${
|
|
433
|
+
${B1}
|
|
434
|
+
${V1}
|
|
435
435
|
void main() {
|
|
436
436
|
vec3 d = vec3(a_x, a_y, a_z);
|
|
437
437
|
gl_Position = place(d);
|
|
438
438
|
gl_PointSize = u_size;
|
|
439
439
|
if (a_x != a_x || a_y != a_y || a_z != a_z || outside(v_n)) gl_Position = vec4(2.0, 2.0, 2.0, 1.0);
|
|
440
|
-
}`,
|
|
440
|
+
}`,U1=`#version 300 es
|
|
441
441
|
precision highp float;
|
|
442
442
|
in vec3 v_n; in vec4 v_color;
|
|
443
443
|
uniform float u_size; // device px
|
|
@@ -448,10 +448,10 @@ void main() {
|
|
|
448
448
|
if (u_size >= 3.0 && r > u_size * 0.5) discard;
|
|
449
449
|
vec4 c = r > u_size * 0.5 - u_rim ? vec4(0.0588, 0.0627, 0.0784, 0.85) : v_color;
|
|
450
450
|
o = vec4(c.rgb * c.a, c.a);
|
|
451
|
-
}`,
|
|
451
|
+
}`,W1=`#version 300 es
|
|
452
452
|
in float a_x; in float a_y; in float a_z;
|
|
453
|
-
${
|
|
454
|
-
void main() { gl_Position = place(vec3(a_x, a_y, a_z)); }`,
|
|
453
|
+
${B1}
|
|
454
|
+
void main() { gl_Position = place(vec3(a_x, a_y, a_z)); }`,G1=`#version 300 es
|
|
455
455
|
precision highp int;
|
|
456
456
|
uniform highp sampler2D u_z;
|
|
457
457
|
uniform ivec2 u_n; // grid size
|
|
@@ -460,7 +460,7 @@ uniform int u_wstep; // grid cells between wire lines
|
|
|
460
460
|
uniform int u_wire;
|
|
461
461
|
uniform vec4 u_ext; // x0, x1, y0, y1 (relative to the origin)
|
|
462
462
|
out float v_hole;
|
|
463
|
-
${
|
|
463
|
+
${B1}
|
|
464
464
|
void main() {
|
|
465
465
|
int cx = (u_n.x - 2) / u_step + 1, cy = (u_n.y - 2) / u_step + 1;
|
|
466
466
|
int id = gl_VertexID, gx, gy;
|
|
@@ -479,29 +479,29 @@ void main() {
|
|
|
479
479
|
v_hole = z != z ? 1.0 : 0.0;
|
|
480
480
|
float fx = u_n.x > 1 ? float(gx) / float(u_n.x - 1) : 0.0, fy = u_n.y > 1 ? float(gy) / float(u_n.y - 1) : 0.0;
|
|
481
481
|
gl_Position = place(vec3(mix(u_ext.x, u_ext.y, fx), mix(u_ext.z, u_ext.w, fy), z == z ? z : 0.0));
|
|
482
|
-
}`,
|
|
482
|
+
}`,K1=`#version 300 es
|
|
483
483
|
precision highp float;
|
|
484
484
|
in vec3 v_n; in vec4 v_color;
|
|
485
485
|
uniform float u_alpha;
|
|
486
486
|
uniform vec4 u_solid; // a colour of its own (wire) when its alpha is set
|
|
487
|
-
${
|
|
487
|
+
${V1}
|
|
488
488
|
out vec4 o;
|
|
489
489
|
void main() {
|
|
490
490
|
if (outside(v_n)) discard;
|
|
491
491
|
vec4 c = u_solid.a > 0.0 ? u_solid : vec4(v_color.rgb, u_alpha);
|
|
492
492
|
o = vec4(c.rgb * c.a, c.a);
|
|
493
|
-
}`,
|
|
493
|
+
}`,q1=`#version 300 es
|
|
494
494
|
precision highp float;
|
|
495
495
|
in vec3 v_n; in vec4 v_color; in float v_hole;
|
|
496
496
|
uniform float u_alpha;
|
|
497
497
|
uniform vec4 u_solid;
|
|
498
|
-
${
|
|
498
|
+
${V1}
|
|
499
499
|
out vec4 o;
|
|
500
500
|
void main() {
|
|
501
501
|
if (v_hole > 0.0 || outside(v_n)) discard;
|
|
502
502
|
vec4 c = u_solid.a > 0.0 ? u_solid : vec4(v_color.rgb, u_alpha);
|
|
503
503
|
o = vec4(c.rgb * c.a, c.a);
|
|
504
|
-
}`,E1=16e6,D1=128,O1=[`u_lo`,`u_span`,`u_flat`,`u_eye`,`u_right`,`u_up`,`u_fwd`,`u_f`,`u_h`,`u_v`,`u_c`,`u_plot`,`u_resolution`,`u_palette`];function k1(e){for(let t=0;t<e.length;t++)if(e[t]===e[t]&&Math.abs(e[t])!==1/0)return e[t];return 0}function A1(e){let t=e.getContext(`webgl2`,{antialias:!0,alpha:!0,premultipliedAlpha:!0,depth:!0});if(!t)return null;let n=(e,n,r,i)=>uX(t,`gl3d|${e}|${n}`,()=>{let a=QY(t,t.VERTEX_SHADER,e),o=QY(t,t.FRAGMENT_SHADER,n);if(!a||!o)return null;let s=t.createProgram();return t.attachShader(s,a),t.attachShader(s,o),t.linkProgram(s),t.getProgramParameter(s,t.LINK_STATUS)?{prog:s,a:Object.fromEntries(r.map(e=>[e,t.getAttribLocation(s,e)])),u:Object.fromEntries([...O1,...i].map(e=>[e,t.getUniformLocation(s,e)]))}:(console.error(`gl3d program link failed:`,t.getProgramInfoLog(s)),null)}),r=[`a_x`,`a_y`,`a_z`],i=n(b1,x1,r,[`u_size`,`u_rim`]),a=n(S1,w1,r,[`u_alpha`,`u_solid`]),o=n(C1,T1,[],[`u_alpha`,`u_solid`,`u_z`,`u_n`,`u_step`,`u_wstep`,`u_wire`,`u_ext`]);if(!i||!a||!o)return null;let s=t.getParameter(t.MAX_TEXTURE_SIZE),c=t.createVertexArray(),l={x:t.createBuffer(),y:t.createBuffer(),z:t.createBuffer()},u=t.createBuffer(),d=t.createBuffer(),f=new Map,p=t.createTexture(),m=t.createTexture(),h=1,g=1,_=1,v={minX:0,maxX:1,minY:0,maxY:1,minZ:0,maxZ:1},y={kind:`2d`,h:0,v:1},b={left:0,top:0,width:1,height:1},x=null,S=0,C=[0,0,0],w=0,T=0,E=null,D={w:0,h:0},O=new Float32Array,k=(e,n,r)=>{t.bindBuffer(e,n),r.byteLength<=(f.get(n)??0)?t.bufferSubData(e,0,r):(t.bufferData(e,r,t.DYNAMIC_DRAW),f.set(n,r.byteLength))},A=(e,t)=>{let n=e.length;O.length<n&&(O=new Float32Array(n));for(let r=0;r<n;r++)O[r]=e[r]-t;return O.subarray(0,n)},j=(e,n)=>{let r=e.u,i=v;t.uniform3f(r.u_lo,i.minX-n[0],i.minY-n[1],i.minZ-n[2]);let a=(e,t)=>t-e>1e-12*Math.max(1,Math.abs(e))?t-e:0;t.uniform3f(r.u_span,a(i.minX,i.maxX),a(i.minY,i.maxY),a(i.minZ,i.maxZ));let o=e=>[+(e===0),+(e===1),+(e===2)];y.kind===`3d`?(t.uniform1i(r.u_flat,0),t.uniform3f(r.u_eye,...y.eye),t.uniform3f(r.u_right,...y.right),t.uniform3f(r.u_up,...y.up),t.uniform3f(r.u_fwd,...y.fwd),t.uniform1f(r.u_f,y.f)):(t.uniform1i(r.u_flat,1),t.uniform3f(r.u_h,...o(y.h)),t.uniform3f(r.u_v,...o(y.v))),t.uniform3f(r.u_c,...o(x.colorAxis)),t.uniform4f(r.u_plot,b.left,b.top,b.width,b.height),t.uniform2f(r.u_resolution,h,g),t.uniform1i(r.u_palette,0)},M=e=>{for(let n of[`x`,`y`,`z`]){let r=e.a[`a_${n}`];t.bindBuffer(t.ARRAY_BUFFER,l[n]),t.enableVertexAttribArray(r),t.vertexAttribPointer(r,1,t.FLOAT,!1,0,0)}};return{maxTextureSize:s,resize(t,n,r){h=Math.max(1,t),g=Math.max(1,n),_=r,e.width=Math.max(1,Math.round(h*_)),e.height=Math.max(1,Math.round(g*_))},setBounds(e){v=e},setView(e,t){y=e,b=t},setPoints(e,n,r){if(!e||!n||!r){S=0;return}S=Math.min(e.length,n.length,r.length),C=[k1(e),k1(n),k1(r)],k(t.ARRAY_BUFFER,l.x,A(e,C[0]).subarray(0,S)),k(t.ARRAY_BUFFER,l.y,A(n,C[1]).subarray(0,S)),k(t.ARRAY_BUFFER,l.z,A(r,C[2]).subarray(0,S))},setTriangles(e){if(!e||e.length<3){w=T=0;return}w=e.length-e.length%3,k(t.ELEMENT_ARRAY_BUFFER,u,e.subarray(0,w));let n=new Uint32Array(w*2);for(let t=0;t<w;t+=3){let r=e[t],i=e[t+1],a=e[t+2],o=t*2;n[o]=r,n[o+1]=i,n[o+2]=i,n[o+3]=a,n[o+4]=a,n[o+5]=r}T=n.length,k(t.ELEMENT_ARRAY_BUFFER,d,n)},setSurface(e,n=0,r=0,i=[0,1],a=[0,1]){if(!e||n<2||r<2||n>s||r>s){E=null;return}let o=k1(e),c=A(e,o).subarray(0,n*r);t.bindTexture(t.TEXTURE_2D,m),t.pixelStorei(t.UNPACK_ALIGNMENT,4),D.w===n&&D.h===r?t.texSubImage2D(t.TEXTURE_2D,0,0,0,n,r,t.RED,t.FLOAT,c):(t.texImage2D(t.TEXTURE_2D,0,t.R32F,n,r,0,t.RED,t.FLOAT,c),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),D={w:n,h:r}),E={w:n,h:r,origin:o,ext:[i[0],i[1],a[0],a[1]]}},setStyle(e){x?.palette!==e.palette&&(t.bindTexture(t.TEXTURE_2D,p),t.texImage2D(t.TEXTURE_2D,0,t.RGBA8,256,1,0,t.RGBA,t.UNSIGNED_BYTE,e.palette),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE)),x=e},render(){t.viewport(0,0,e.width,e.height),t.clearColor(0,0,0,0),t.clearDepth(1),t.clear(t.COLOR_BUFFER_BIT|t.DEPTH_BUFFER_BIT);let n=x;if(!n)return;t.bindVertexArray(c),t.enable(t.BLEND),t.blendFunc(t.ONE,t.ONE_MINUS_SRC_ALPHA),t.enable(t.DEPTH_TEST),t.depthFunc(t.LEQUAL),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,p),t.enable(t.POLYGON_OFFSET_FILL),t.polygonOffset(1,1);let r=n.wireColor;if(E){let e=o;t.useProgram(e.prog);let[i,a,s,c]=E.ext;j(e,[i,s,E.origin]),t.uniform4f(e.u.u_ext,0,a-i,0,c-s),t.activeTexture(t.TEXTURE1),t.bindTexture(t.TEXTURE_2D,m),t.uniform1i(e.u.u_z,1),t.uniform2i(e.u.u_n,E.w,E.h);let l=(E.w-1)*(E.h-1),u=Math.max(1,Math.ceil(Math.sqrt(l/E1))),d=Math.floor((E.w-2)/u)+1,f=Math.floor((E.h-2)/u)+1;if(t.uniform1i(e.u.u_step,u),t.uniform1f(e.u.u_alpha,n.fillAlpha),n.fill&&(t.uniform1i(e.u.u_wire,0),t.uniform4f(e.u.u_solid,0,0,0,0),t.drawArrays(t.TRIANGLES,0,d*f*6)),n.wire){let n=u*Math.max(1,Math.ceil(Math.max(d,f)/D1)),i=Math.floor((E.h-1)/n)+1,a=Math.floor((E.w-1)/n)+1;t.uniform1i(e.u.u_wire,1),t.uniform1i(e.u.u_wstep,n),t.uniform4f(e.u.u_solid,...r),t.drawArrays(t.LINES,0,(i*d+a*f)*2)}t.activeTexture(t.TEXTURE0)}if(S>0){if(w>0&&(n.fill||n.wire)){let e=a;t.useProgram(e.prog),j(e,C),M(e),t.uniform1f(e.u.u_alpha,n.fillAlpha),n.fill&&(t.uniform4f(e.u.u_solid,0,0,0,0),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,u),t.drawElements(t.TRIANGLES,w,t.UNSIGNED_INT,0)),n.wire&&(t.uniform4f(e.u.u_solid,...r),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,d),t.drawElements(t.LINES,T,t.UNSIGNED_INT,0))}let e=i;t.useProgram(e.prog),j(e,C),M(e);let o=Math.max(1,2*n.pointRadius*_);t.uniform1f(e.u.u_size,o),t.uniform1f(e.u.u_rim,o>=3?Math.max(.9,n.pointRadius*.3)*_:0),t.drawArrays(t.POINTS,0,S)}t.disable(t.POLYGON_OFFSET_FILL),t.disable(t.DEPTH_TEST),t.bindVertexArray(null)},dispose(){for(let e of[l.x,l.y,l.z,u,d])t.deleteBuffer(e);t.deleteTexture(p),t.deleteTexture(m),t.deleteVertexArray(c)}}}var j1=new Map;function M1(e,t){let n=j1.get(e);if(!n){let r=typeof OffscreenCanvas>`u`?null:new OffscreenCanvas(1,1).getContext(`2d`,{willReadFrequently:!0});if(!r)return[0,0,0,t];r.fillStyle=e,r.fillRect(0,0,1,1);let i=r.getImageData(0,0,1,1).data;j1.set(e,n=[i[0]/255,i[1]/255,i[2]/255,i[3]/255])}return[n[0],n[1],n[2],n[3]*t]}function N1(e,t){return{x:e.x-t.x,y:e.y-t.y,z:e.z-t.z}}function P1(e,t){return{x:e.y*t.z-e.z*t.y,y:e.z*t.x-e.x*t.z,z:e.x*t.y-e.y*t.x}}function F1(e,t){return e.x*t.x+e.y*t.y+e.z*t.z}function I1(e){return Math.sqrt(e.x*e.x+e.y*e.y+e.z*e.z)}function L1(e){let t=I1(e);return t>1e-12?{x:e.x/t,y:e.y/t,z:e.z/t}:{x:0,y:0,z:1}}function R1(e,t,n,r){let i=Math.cos(n),a=Math.sin(n),o=Math.cos(r),s=Math.sin(r);return{x:e.x+t*o*a,y:e.y+t*s,z:e.z+t*o*i}}function z1(e,t,n){let r=L1(N1(t,e)),i=L1(P1(r,n));return{right:i,up:P1(i,r),fwd:r,eye:e}}function B1(e,t,n,r,i){let a=N1(e,t.eye),o=F1(a,t.right),s=F1(a,t.up),c=F1(a,t.fwd);if(c<.01)return{sx:-9999,sy:-9999,depth:c};let l=1/Math.tan(n/2);return{sx:r/2+o/c*l*(i/2),sy:i/2-s/c*l*(i/2),depth:c}}function V1(e,t,n,r){let i=(e,t,n)=>{let r=n-t;return r<1e-12?0:(e-t)/r*2-1};return{x:i(e,r.minX,r.maxX),y:i(n,r.minZ,r.maxZ),z:i(t,r.minY,r.maxY)}}var H1=16,U1=.1,W1=Math.PI/4,G1=Math.PI/5,K1=3.2,q1=2e4,J1=(()=>{let e=new Uint8Array(256*4);for(let t=0;t<256;t++){let{r:n,g:r,b:i}=p$(t/255);e.set([n,r,i,255],t*4)}return e})();function Y1(e){if(!Array.isArray(e))return e;let t=e.length,n=new Float64Array(t),r=new Float64Array(t),i=new Float64Array(t);for(let a=0;a<t;a++)n[a]=e[a].x,r[a]=e[a].y,i[a]=e[a].z;return{length:t,x:n,y:r,z:i}}var X1=(e,t)=>!t||e>=t[0]&&e<=t[1];function Z1(e,t,n,r){let i=new Uint32Array(e.length),a=0;for(let o=0;o<e.length;o++){let s=e.x[o],c=e.y[o],l=e.z[o];s-s===0&&c-c===0&&l-l===0&&X1(s,t)&&X1(c,n)&&X1(l,r)&&(i[a++]=o)}if(a<3)return null;let o=new Float64Array(a*2);for(let t=0;t<a;t++)o[2*t]=e.x[i[t]],o[2*t+1]=e.y[i[t]];try{let e=new c1(o).triangles;for(let t=0;t<e.length;t++)e[t]=i[e[t]];return e.length>=3?e:null}catch{return null}}var Q1=(0,Z.forwardRef)(function({points:e,surface:t,xLabel:n,yLabel:r,zLabel:i,height:a=500,backgroundToken:o=``,xRange:s,yRange:c,zRange:l,viewMode:u,pointRadius:d=4,alarms:f,showMesh:p=!1,meshStyle:m=`filled`,meshOpacity:h=.85,onPlotContextMenu:g},_){let v=(0,Z.useRef)(g);(0,Z.useLayoutEffect)(()=>{v.current=g},[g]);let y=(0,Z.useRef)(null),b=(0,Z.useRef)(null),x=(0,Z.useRef)(null),S=(0,Z.useRef)(W1),C=(0,Z.useRef)(G1),w=(0,Z.useRef)(K1),T=(0,Z.useRef)(null),E=(0,Z.useRef)({xLabel:n,yLabel:r,zLabel:i,height:a,viewMode:u,pointRadius:d,alarms:f??[],showMesh:p,meshStyle:m,meshOpacity:h});(0,Z.useLayoutEffect)(()=>{E.current={xLabel:n,yLabel:r,zLabel:i,height:a,viewMode:u,pointRadius:d,alarms:f??[],showMesh:p,meshStyle:m,meshOpacity:h}},[n,r,i,a,u,d,f,p,m,h]);let D=(0,Z.useMemo)(()=>{let n=Y1(e),r=1/0,i=-1/0,a=1/0,o=-1/0,u=1/0,d=-1/0,f=0,p=0,m=0,h=0;for(let e=0;e<n.length;e++){let t=n.x[e],g=n.y[e],_=n.z[e];t-t!==0||g-g!==0||_-_!==0||!X1(t,s)||!X1(g,c)||!X1(_,l)||(t<r&&(r=t),t>i&&(i=t),g<a&&(a=g),g>o&&(o=g),_<u&&(u=_),_>d&&(d=_),f+=t,p+=g,m+=_,h++)}let g=null;if(t&&t.w>=2&&t.h>=2){let e=t.values,n=!1;for(let r=0;r<t.w*t.h;r++){let t=e[r];t-t===0&&(n=!0,t<u&&(u=t),t>d&&(d=t))}n&&(g=t,r=Math.min(r,t.x[0],t.x[1]),i=Math.max(i,t.x[0],t.x[1]),a=Math.min(a,t.y[0],t.y[1]),o=Math.max(o,t.y[0],t.y[1]))}if(h===0&&!g)return null;s&&(r=s[0],i=s[1]),c&&(a=c[0],o=c[1]),l&&(u=l[0],d=l[1]);let _={minX:r,maxX:i,minY:a,maxY:o,minZ:u,maxZ:d},v=h>0?V1(f/h,p/h,m/h,_):{x:0,y:0,z:0};return{cols:h>0?n:null,surface:g,bounds:_,center:v}},[e,t,s,c,l]),O=u??`3d`,k=p&&(O===`3d`||O===`xy`),A=(0,Z.useMemo)(()=>k&&D?.cols?Z1(D.cols,s,c,l):null,[k,D,s,c,l]),j=(0,Z.useRef)({model:D,triangles:A});(0,Z.useLayoutEffect)(()=>{j.current={model:D,triangles:A}},[D,A]);let M=(0,Z.useRef)({r:null,failed:!1,cols:null,surface:null,tris:null,size:``});function N(e,t,n){let r=M.current;!r.r&&!r.failed&&b.current&&(r.r=dX(b.current,A1),r.failed=!r.r);let i=r.r;if(!i||!b.current)return null;let a=`${e}x${t}@${n}`;r.size!==a&&(i.resize(e,t,n),b.current.style.width=`${e}px`,b.current.style.height=`${t}px`,r.size=a);let{model:o,triangles:s}=j.current,c=o?.cols??null;r.cols!==c&&(i.setPoints(c?.x??null,c?.y,c?.z),r.cols=c);let l=o?.surface??null;return r.surface!==l&&(i.setSurface(l?.values??null,l?.w,l?.h,l?.x,l?.y),r.surface=l),r.tris!==s&&(i.setTriangles(s),r.tris=s),i}(0,Z.useEffect)(()=>()=>{M.current.r?.dispose(),M.current.r=null},[]);let P=(0,Z.useRef)(null);function F(){let e=y.current,t=x.current;if(!e||!t)return;let n=Math.max(1,t.clientWidth),r=Math.max(1,t.clientHeight),i=Math.min(2,window.devicePixelRatio||1),a=Math.floor(n*i),o=Math.floor(r*i);(e.width!==a||e.height!==o)&&(e.width=a,e.height=o);let s=e.getContext(`2d`);if(!s)return;s.setTransform(i,0,0,i,0,0);let{bg:c,muted:l,grid:u}=I(),{xLabel:d,yLabel:f,zLabel:p}=E.current,m=Math.max(.25,E.current.pointRadius??4),h=j$({top:0,right:0,bottom:0,left:0},n,r).tiny;s.fillStyle=c,s.fillRect(0,0,n,r);let g=j.current.model,_=N(n,r,i);if(!g){if(_?.setStyle({palette:J1,colorAxis:2,pointRadius:m,fill:!1,wire:!1,fillAlpha:1,wireColor:[0,0,0,0]}),_?.setPoints(null),M.current.cols=null,_?.render(),h)return;s.fillStyle=l,s.font=`13px ${X.sans}`,MY(s);return}let v=g.bounds,b=E.current.viewMode??`3d`,T=b===`xz`?1:b===`yz`?0:2,D=[v.minX,v.minY,v.minZ][T],O=[v.maxX,v.maxY,v.maxZ][T],k=(e,t,n)=>{let r=T===0?e:T===1?t:n,i=O-D;return i>1e-12?(r-D)/i:.5},A,F,L,R=(e,t,r)=>{let i=n-28,a=t/32;for(let t=0;t<32;t++)s.fillStyle=m$(1-t/32),s.fillRect(i,e+t*a,14,a+1);s.strokeStyle=u,s.lineWidth=1,s.strokeRect(i,e,14,t),s.fillStyle=l,s.font=`9px ${X.mono}`,s.textAlign=`right`,s.fillText(vJ(O),i-4,e+4),s.fillText(vJ(D),i-4,e+t),s.fillText(r,i-4,e-6)},z=e=>{s.fillStyle=l,s.font=`10px ${X.sans}`,s.textAlign=`left`,s.globalAlpha=.7,s.fillText(e,H1,r-6),s.globalAlpha=1};if(b!==`3d`){let e,t,i,a,o,c,m,g,_;b===`xy`?(e=d,t=f,i=p,a=v.minX,o=v.maxX,c=v.minY,m=v.maxY,g=0,_=1):b===`xz`?(e=d,t=p,i=f,a=v.minX,o=v.maxX,c=v.minZ,m=v.maxZ,g=0,_=2):(e=f,t=p,i=d,a=v.minY,o=v.maxY,c=v.minZ,m=v.maxZ,g=1,_=2);let y=j$({left:72,right:48,top:24,bottom:52},n,r),x=Math.max(1,n-y.left-y.right),S=Math.max(1,r-y.top-y.bottom),C=o-a||1,w=m-c||1,T=e=>y.left+(e-a)/C*x,D=e=>y.top+S-(e-c)/w*S;A={left:y.left,top:y.top,width:x,height:S},L={kind:`2d`,h:g,v:_},F=(e,t,n)=>{let r=[e,t,n];return[T(r[g]),D(r[_])]};let O=uJ(C,8),k=uJ(w,8),j=pJ(a,o,O),M=pJ(c,m,k);s.strokeStyle=u,s.lineWidth=.5,s.globalAlpha=.3;for(let e of j){let t=T(e);s.beginPath(),s.moveTo(t,y.top),s.lineTo(t,y.top+S),s.stroke()}for(let e of M){let t=D(e);s.beginPath(),s.moveTo(y.left,t),s.lineTo(y.left+x,t),s.stroke()}s.globalAlpha=1,s.strokeStyle=u,s.lineWidth=1,s.strokeRect(y.left,y.top,x,S),s.save(),s.beginPath(),s.rect(y.left,y.top,x,S),s.clip();for(let e of E.current.alarms){let{axis:t,value:n,color:r,style:i,width:a}=e,o=null,c=null;b===`xy`?t===`x`?o=T(n):t===`y`&&(c=D(n)):b===`xz`?t===`x`?o=T(n):t===`z`&&(c=D(n)):t===`y`?o=T(n):t===`z`&&(c=D(n)),!(o===null&&c===null)&&(i===`dashed`?s.setLineDash([7,4]):i===`dotted`?s.setLineDash([2,4]):s.setLineDash([]),s.strokeStyle=r,s.lineWidth=a,s.globalAlpha=.9,s.beginPath(),o===null?c!==null&&(s.moveTo(y.left,c),s.lineTo(y.left+x,c)):(s.moveTo(o,y.top),s.lineTo(o,y.top+S)),s.stroke(),s.setLineDash([]),s.globalAlpha=1,s.fillStyle=r,s.font=`bold 10px ${X.mono}`,s.globalAlpha=.95,o===null?c!==null&&(s.textAlign=`left`,s.textBaseline=`bottom`,s.fillText(vJ(n),y.left+3,c-2)):(s.textAlign=`left`,s.textBaseline=`top`,s.fillText(vJ(n),o+3,y.top+2)),s.globalAlpha=1,s.textBaseline=`alphabetic`)}if(s.restore(),!h){s.fillStyle=l,s.font=`10px ${X.mono}`,s.textAlign=`center`,s.textBaseline=`top`;for(let e of j)s.fillText(_J(e,O),T(e),y.top+S+6);s.textAlign=`right`,s.textBaseline=`middle`;for(let e of M)s.fillText(_J(e,k),y.left-8,D(e));s.textBaseline=`alphabetic`,s.font=`bold 11px ${X.mono}`,s.textAlign=`center`,s.fillStyle=`#fb7185`,s.fillText(e,y.left+x/2,r-8),s.save(),s.translate(14,y.top+S/2),s.rotate(-Math.PI/2),s.fillStyle=`#38bdf8`,s.textAlign=`center`,s.fillText(t,0,0),s.restore(),R(y.top+8,Math.min(S-20,180),i),z(`2D projection: ${b.toUpperCase()} plane · Color = ${i}`)}}else{let e=S.current,t=C.current,i=w.current,a=z1(R1(g.center,i,e,t),g.center,{x:0,y:1,z:0}),o=Math.PI/3,c=h?3:H1,m=Math.max(1,n-c*2),_=Math.max(1,r-c*2-(h?0:24));A={left:c,top:c,width:m,height:_};let y=e=>[e.x,e.y,e.z];L={kind:`3d`,eye:y(a.eye),right:y(a.right),up:y(a.up),fwd:y(a.fwd),f:1/Math.tan(o/2)};let b=e=>{let t=B1(e,a,o,m,_);return{sx:t.sx+c,sy:t.sy+c,depth:t.depth}};F=(e,t,n)=>{let r=b(V1(e,t,n,v));return r.depth<.02?null:[r.sx,r.sy]};let x=(e,t,n)=>{let r=b(e),i=b(t);r.depth<.02||i.depth<.02||(s.strokeStyle=n.color,s.lineWidth=n.width,s.globalAlpha=n.alpha??1,s.beginPath(),s.moveTo(r.sx,r.sy),s.lineTo(i.sx,i.sy),s.stroke(),s.globalAlpha=1)},T=uJ(v.maxX-v.minX,6),D=uJ(v.maxY-v.minY,6),O=uJ(v.maxZ-v.minZ,6),k=pJ(v.minX,v.maxX,T),j=pJ(v.minY,v.maxY,D),M=pJ(v.minZ,v.maxZ,O),N=mJ(v.minX,v.maxX,T/5,k),P=mJ(v.minY,v.maxY,D/5,j),I=mJ(v.minZ,v.maxZ,O/5,M);for(let[e,t]of[[{x:-1,y:-1,z:-1},{x:1,y:-1,z:-1}],[{x:1,y:-1,z:-1},{x:1,y:-1,z:1}],[{x:1,y:-1,z:1},{x:-1,y:-1,z:1}],[{x:-1,y:-1,z:1},{x:-1,y:-1,z:-1}],[{x:-1,y:1,z:-1},{x:1,y:1,z:-1}],[{x:1,y:1,z:-1},{x:1,y:1,z:1}],[{x:1,y:1,z:1},{x:-1,y:1,z:1}],[{x:-1,y:1,z:1},{x:-1,y:1,z:-1}],[{x:-1,y:-1,z:-1},{x:-1,y:1,z:-1}],[{x:1,y:-1,z:-1},{x:1,y:1,z:-1}],[{x:1,y:-1,z:1},{x:1,y:1,z:1}],[{x:-1,y:-1,z:1},{x:-1,y:1,z:1}]])x(e,t,{color:u,width:1,alpha:.65});if(!h){for(let e of k){let t=V1(e,v.minY,v.minZ,v).x;x({x:t,y:-1,z:-1},{x:t,y:-1,z:1},{color:u,width:.75,alpha:.45})}for(let e of j){let t=V1(v.minX,e,v.minZ,v).z;x({x:-1,y:-1,z:t},{x:1,y:-1,z:t},{color:u,width:.75,alpha:.45})}for(let e of P){let t=V1(v.minX,e,v.minZ,v).z;x({x:-1,y:-1,z:t},{x:1,y:-1,z:t},{color:u,width:.5,alpha:.22})}for(let e of N){let t=V1(e,v.minY,v.minZ,v).x;x({x:t,y:-1,z:-1},{x:t,y:-1,z:1},{color:u,width:.5,alpha:.22})}let e=(e,t)=>{let n=U1*(t?1:.55);x({x:e,y:-1,z:-1},{x:e,y:-1+n,z:-1},{color:`#fb7185`,width:t?1.25:.75,alpha:.95})},t=(e,t)=>{let n=U1*(t?1:.55);x({x:-1,y:-1,z:e},{x:-1+n,y:-1,z:e},{color:`#38bdf8`,width:t?1.25:.75,alpha:.95})},n=(e,t)=>{let n=U1*(t?1:.55);x({x:-1,y:e,z:-1},{x:-1+n,y:e,z:-1},{color:`#4ade80`,width:t?1.25:.75,alpha:.95})};for(let t of N)e(V1(t,v.minY,v.minZ,v).x,!1);for(let t of k)e(V1(t,v.minY,v.minZ,v).x,!0);for(let e of P)t(V1(v.minX,e,v.minZ,v).z,!1);for(let e of j)t(V1(v.minX,e,v.minZ,v).z,!0);for(let e of I)n(V1(v.minX,v.minY,e,v).y,!1);for(let e of M)n(V1(v.minX,v.minY,e,v).y,!0)}let B=(e,t,n)=>{let r=n-t;return r<1e-12?0:(e-t)/r*2-1};for(let e of E.current.alarms){let{axis:t,value:n,color:r,style:i,width:a}=e,o;if(t===`z`){let e=B(n,v.minZ,v.maxZ);o=[{x:-1,y:e,z:-1},{x:1,y:e,z:-1},{x:1,y:e,z:1},{x:-1,y:e,z:1}]}else if(t===`x`){let e=B(n,v.minX,v.maxX);o=[{x:e,y:-1,z:-1},{x:e,y:1,z:-1},{x:e,y:1,z:1},{x:e,y:-1,z:1}]}else{let e=B(n,v.minY,v.maxY);o=[{x:-1,y:-1,z:e},{x:1,y:-1,z:e},{x:1,y:1,z:e},{x:-1,y:1,z:e}]}let c=o.map(e=>b(e));if(c.every(e=>e.depth>=.02)){s.beginPath(),s.moveTo(c[0].sx,c[0].sy);for(let e=1;e<c.length;e++)s.lineTo(c[e].sx,c[e].sy);s.closePath(),s.fillStyle=r,s.globalAlpha=.18,s.fill(),i===`dashed`?s.setLineDash([7,4]):i===`dotted`?s.setLineDash([2,4]):s.setLineDash([]),s.strokeStyle=r,s.lineWidth=a,s.globalAlpha=.9,s.beginPath(),s.moveTo(c[0].sx,c[0].sy);for(let e=1;e<c.length;e++)s.lineTo(c[e].sx,c[e].sy);s.closePath(),s.stroke(),s.setLineDash([]),s.globalAlpha=1;let e=c.reduce((e,t)=>t.sy>e.sy?t:e);s.fillStyle=r,s.font=`bold 10px ${X.mono}`,s.textAlign=`center`,s.globalAlpha=.95,s.fillText(`${t.toUpperCase()}=${vJ(n)}`,e.sx,e.sy-6),s.globalAlpha=1}}if(!h){s.font=`10px ${X.mono}`,s.textBaseline=`middle`;for(let e of k){let t=V1(e,v.minY,v.minZ,v).x,n=b({x:t,y:-1.2,z:-1.2});n.depth<.02||(s.fillStyle=l,s.textAlign=`center`,s.fillText(_J(e,T),n.sx,n.sy+12))}for(let e of j){let t=V1(v.minX,e,v.minZ,v).z,n=b({x:-1.22,y:-1,z:t});n.depth<.02||(s.textAlign=`right`,s.fillText(_J(e,D),n.sx-4,n.sy))}for(let e of M){let t=V1(v.minX,v.minY,e,v).y,n=b({x:-1.22,y:t,z:-1.2});n.depth<.02||(s.textAlign=`right`,s.fillText(_J(e,O),n.sx-4,n.sy))}s.textBaseline=`alphabetic`,s.font=`bold 11px ${X.mono}`;let e=b({x:1.15,y:-1,z:-1.15});e.depth>=.02&&(s.fillStyle=`#fb7185`,s.textAlign=`center`,s.fillText(d,e.sx,e.sy+16)),e=b({x:-1.18,y:-1,z:1.15}),e.depth>=.02&&(s.fillStyle=`#38bdf8`,s.textAlign=`center`,s.fillText(f,e.sx-10,e.sy)),e=b({x:-1.18,y:1.15,z:-1.18}),e.depth>=.02&&(s.fillStyle=`#4ade80`,s.textAlign=`center`,s.fillText(p,e.sx-10,e.sy)),R(H1+8,Math.min(r-80,180),p),z(`Drag: rotate | Wheel: zoom | Dbl‑click: reset · ${g.surface?`Surface`:E.current.showMesh?`Mesh: ${E.current.meshStyle}`:`Scatter`} · color = Z`)}}let{showMesh:B,meshStyle:V,meshOpacity:ee}=E.current,H=!!g.surface||B;if(_)_.setBounds(v),_.setView(L,A),_.setStyle({palette:J1,colorAxis:T,pointRadius:m,fill:H&&(V===`filled`||V===`both`),wire:H&&(V===`wireframe`||V===`both`),fillAlpha:ee,wireColor:M1(u,.5)}),_.render(),P.current!==g&&(P.current=g,VX(t));else if(g.cols){let e=g.cols,t=Math.max(1,Math.ceil(e.length/q1));for(let n=0;n<e.length;n+=t){let t=e.x[n],r=e.y[n],i=e.z[n];if(!(t>=v.minX&&t<=v.maxX&&r>=v.minY&&r<=v.maxY&&i>=v.minZ&&i<=v.maxZ))continue;let a=F(t,r,i);a&&(s.fillStyle=m$(k(t,r,i)),s.beginPath(),s.arc(a[0],a[1],m,0,Math.PI*2),s.fill())}}}function I(){if(T.current)return T.current;let e=x.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return T.current=n,n}let L=(0,Z.useRef)(F);(0,Z.useLayoutEffect)(()=>{L.current=F});let R=(0,Z.useRef)(null);R.current??=KX(()=>L.current(),()=>x.current),(0,Z.useEffect)(()=>()=>R.current?.cancel(),[]);let z=()=>{S.current=W1,C.current=G1,w.current=K1,R.current.schedule()};return(0,Z.useImperativeHandle)(_,()=>({autoscale:z}),[]),(0,Z.useEffect)(()=>zJ(x.current,()=>{T.current=null,R.current.schedule()}),[]),(0,Z.useEffect)(()=>{T.current=null,R.current.schedule()},[o]),(0,Z.useEffect)(()=>{R.current.now()},[D,A,n,r,i,a,u,d,f,p,m,h]),(0,Z.useEffect)(()=>{let e=y.current,t=x.current;if(!e||!t)return;let n=()=>R.current.schedule(),r=new WX(()=>{T.current=null,n()});r.observe(t);let i=!1,a=0,o=0,s=t=>{t.button===0&&(i=!0,a=t.clientX,o=t.clientY,e.setPointerCapture(t.pointerId))},c=e=>{if(!i)return;let t=e.clientX-a,r=e.clientY-o;a=e.clientX,o=e.clientY,S.current-=t*.008,C.current+=r*.008,C.current=Math.max(-Math.PI/2+.05,Math.min(Math.PI/2-.05,C.current)),n()},l=()=>{i=!1},u=e=>{e.preventDefault();let t=e.deltaY>0?1.08:.92;w.current=Math.max(1.2,Math.min(12,w.current*t)),n()},d=()=>{S.current=W1,C.current=G1,w.current=K1,n()},f=e=>{e.preventDefault(),v.current?.({clientX:e.clientX,clientY:e.clientY})};return e.addEventListener(`pointerdown`,s),e.addEventListener(`pointermove`,c),e.addEventListener(`pointerup`,l),e.addEventListener(`pointercancel`,l),e.addEventListener(`wheel`,u,{passive:!1}),e.addEventListener(`contextmenu`,f),e.addEventListener(`dblclick`,d),()=>{r.disconnect(),e.removeEventListener(`pointerdown`,s),e.removeEventListener(`pointermove`,c),e.removeEventListener(`pointerup`,l),e.removeEventListener(`pointercancel`,l),e.removeEventListener(`wheel`,u),e.removeEventListener(`contextmenu`,f),e.removeEventListener(`dblclick`,d)}},[]),(0,Q.jsxs)(`div`,{ref:x,className:`chart-canvas-wrap`,children:[(0,Q.jsx)(`canvas`,{ref:y,className:`chart-canvas`,role:`img`,"aria-label":`3D scatter: ${n} vs ${r} vs ${i}`,style:{display:`block`,width:`100%`,height:`100%`,cursor:`grab`}}),(0,Q.jsx)(`canvas`,{ref:b,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}})]})}),$1={top:14,right:24,bottom:40,left:64},e0=5;function t0(e){return e===`dashed`?[5,4]:e===`dotted`?[1,4]:[]}function n0(e){return Math.max(10,Math.min(200,Math.ceil(Math.sqrt(e))))}function r0(e,t,n){let r=(e-t)/n;return Math.exp(-.5*r*r)/(n*Math.sqrt(2*Math.PI))}function i0(e,t){let n=e.length;if(n===0)return null;let r=1/0,i=-1/0,a=0;for(let t=0;t<n;t++){let n=e[t];n<r&&(r=n),n>i&&(i=n),a+=n}r===i&&(--r,i+=1);let o=t>0?t:n0(n),s=(i-r)/o,c=Array(o).fill(0),l=a/n,u=0;for(let t=0;t<n;t++){let n=e[t];c[Math.min(o-1,Math.floor((n-r)/s))]++,u+=(n-l)**2}return{lo:r,hi:i,nBins:o,width:s,counts:c,mean:l,sd:Math.sqrt(u/n),total:n}}function a0({values:e,label:t,bins:n=0,color:r=`#38bdf8`,showNormal:i=!1,logY:a=!1,height:o=400,backgroundToken:s=``,onPlotContextMenu:c}){let l=IZ(),u=(0,Z.useRef)(null),d=(0,Z.useRef)(null),f=(0,Z.useRef)(null),p=(0,Z.useRef)(null),m=(0,Z.useRef)(0),h=(0,Z.useRef)(null),g=(0,Z.useRef)(c);(0,Z.useLayoutEffect)(()=>{g.current=c},[c]);let _=(0,Z.useRef)({values:e,label:t,bins:n,color:r,showNormal:i,logY:a,height:o});(0,Z.useLayoutEffect)(()=>{_.current={values:e,label:t,bins:n,color:r,showNormal:i,logY:a,height:o}},[e,t,n,r,i,a,o]);function v(){if(h.current)return h.current;let e=f.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return h.current=n,n}function y(){let e=f.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||_.current.height)}}function b(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}let x=(0,Z.useMemo)(()=>i0(e,n),[e,n]),S=(0,Z.useRef)(x);(0,Z.useLayoutEffect)(()=>{S.current=x},[x]);let C=()=>S.current;function w(){let e=u.current;if(!e)return;let{w:t,h:n}=y(),r=b(e,t,n);if(!r)return;let{top:i,right:a,bottom:o,left:s}=$1,c=t-s-a,d=n-i-o,{bg:f,muted:p,grid:m}=v(),{label:h,color:g,showNormal:x,logY:S}=_.current;r.fillStyle=f,r.fillRect(0,0,t,n);let w=C();if(!w||c<=0||d<=0){r.fillStyle=p,r.font=`13px ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,MY(r);return}let{lo:T,hi:E,nBins:D,width:O,counts:k,mean:A,sd:j,total:M}=w,N=Math.max(...k),P=S?Math.log10(N+1)+.1:N*1.08,F=e=>s+(e-T)/(E-T)*c;l({left:s,top:i,width:c,height:d,x:{v0:T,v1:E}});let I=e=>i+(P-(S?e>0?Math.log10(e):0:e))/(P-0)*d,L=S?1:uJ(P,5),R=pJ(0,S?P:N,L);r.strokeStyle=m,r.lineWidth=1,r.setLineDash(t0(`dashed`));for(let e of R){let t=I(e);r.beginPath(),r.moveTo(s,t),r.lineTo(s+c,t),r.stroke()}r.setLineDash([]);let z=Math.max(.5,c/D*.04);for(let e=0;e<D;e++){let t=F(T+e*O)+z/2,n=F(T+(e+1)*O)-z/2,i=I(0),a=I(k[e]);r.fillStyle=g,r.globalAlpha=.75,r.fillRect(t,a,n-t,i-a),r.globalAlpha=1}if(x&&j>0){r.beginPath();for(let e=0;e<=200;e++){let t=T+e/200*(E-T),n=r0(t,A,j)*M*O,i=F(t),a=I(n);e===0?r.moveTo(i,a):r.lineTo(i,a)}r.strokeStyle=`#f97316`,r.lineWidth=1,r.stroke()}r.strokeStyle=p,r.lineWidth=1,r.fillStyle=p,r.font=`11px ${X.mono}`,r.textAlign=`right`,r.textBaseline=`middle`;for(let e of R){let t=I(e);r.beginPath(),r.moveTo(s-e0,t),r.lineTo(s,t),r.stroke(),r.fillText(S?`10^${e.toFixed(0)}`:_J(e,L),s-4,t)}let B=uJ(E-T,dJ(c)),V=pJ(T,E,B);r.fillStyle=p,r.textAlign=`center`,r.textBaseline=`top`;for(let e of V){let t=F(e);r.beginPath(),r.moveTo(t,i+d),r.lineTo(t,i+d+e0),r.stroke(),r.fillText(_J(e,B),t,i+d+e0+2)}r.strokeStyle=m,r.lineWidth=1,r.strokeRect(s,i,c,d),r.fillStyle=p,r.font=`11px ${X.mono}`,r.textAlign=`center`,r.textBaseline=`bottom`,r.fillText(h,s+c/2,n-4),r.save(),r.translate(14,i+d/2),r.rotate(-Math.PI/2),r.textAlign=`center`,r.textBaseline=`middle`,r.fillText(S?`log₁₀(count)`:`count`,0,0),r.restore()}let T=(0,Z.useRef)(w);T.current=w;let E=(0,Z.useRef)(null);E.current??=KX(()=>T.current(),()=>f.current);let D=()=>E.current.schedule();function O(e){let t=d.current;if(!t)return;let{w:n,h:r}=y(),i=b(t,n,r);if(!i||(i.clearRect(0,0,n,r),e===null))return;let{top:a,right:o,bottom:s,left:c}=$1,l=n-c-o,u=r-a-s,{muted:f}=v(),p=C();if(!p)return;let{lo:m,hi:h,width:g,counts:_}=p,x=e=>c+(e-m)/(h-m)*l,S=x(m+e*g),w=x(m+(e+1)*g);i.fillStyle=`rgba(255,255,255,0.12)`,i.fillRect(S,a,w-S,u);let T=(S+w)/2,E=_[e],D=(E/p.total*100).toFixed(1),O=`${vJ(m+e*g)} – ${vJ(m+(e+1)*g)}`,k=`n = ${E} (${D}%)`;i.font=`11px ${X.mono}`;let A=i.measureText(k).width,j=i.measureText(O).width,M=Math.max(A,j),N=Math.min(T+8,c+l-M-8);i.fillStyle=f,i.textAlign=`left`,i.textBaseline=`top`,i.fillText(O,N,a+8),i.fillText(k,N,a+22)}function k(){zX(m.current),m.current=RX(()=>O(p.current))}return(0,Z.useEffect)(()=>{E.current.now()}),(0,Z.useEffect)(()=>()=>E.current?.cancel(),[]),(0,Z.useEffect)(()=>{h.current=null,D()},[s]),(0,Z.useLayoutEffect)(()=>{let e=f.current;if(!e)return;let t=new WX(()=>{h.current=null,D(),k()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{let e=d.current;if(!e)return;function t(t){let n=e.getBoundingClientRect(),{left:r}=$1,i=n.width-$1.left-$1.right,a=C();if(!a||i<=0){p.current=null,k();return}let o=t.clientX-n.left-r,s=Math.floor(o/i*a.nBins);p.current=s>=0&&s<a.nBins?s:null,k()}function n(){p.current=null,k()}function r(e){e.preventDefault(),g.current?.({clientX:e.clientX,clientY:e.clientY})}return e.addEventListener(`mousemove`,t),e.addEventListener(`mouseleave`,n),e.addEventListener(`contextmenu`,r),()=>{e.removeEventListener(`mousemove`,t),e.removeEventListener(`mouseleave`,n),e.removeEventListener(`contextmenu`,r)}},[]),(0,Q.jsxs)(`div`,{ref:f,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:u,className:`chart-canvas`,role:`img`,"aria-label":`Histogram of ${t}`}),(0,Q.jsx)(`canvas`,{ref:d,className:`chart-canvas chart-overlay`})]})}var o0=`
|
|
504
|
+
}`,J1=16e6,Y1=128,X1=[`u_lo`,`u_span`,`u_flat`,`u_eye`,`u_right`,`u_up`,`u_fwd`,`u_f`,`u_h`,`u_v`,`u_c`,`u_plot`,`u_resolution`,`u_palette`];function Z1(e){for(let t=0;t<e.length;t++)if(e[t]===e[t]&&Math.abs(e[t])!==1/0)return e[t];return 0}function Q1(e){let t=e.getContext(`webgl2`,{antialias:!0,alpha:!0,premultipliedAlpha:!0,depth:!0});if(!t)return null;let n=(e,n,r,i)=>MX(t,`gl3d|${e}|${n}`,()=>{let a=bX(t,t.VERTEX_SHADER,e),o=bX(t,t.FRAGMENT_SHADER,n);if(!a||!o)return null;let s=t.createProgram();return t.attachShader(s,a),t.attachShader(s,o),t.linkProgram(s),t.getProgramParameter(s,t.LINK_STATUS)?{prog:s,a:Object.fromEntries(r.map(e=>[e,t.getAttribLocation(s,e)])),u:Object.fromEntries([...X1,...i].map(e=>[e,t.getUniformLocation(s,e)]))}:(console.error(`gl3d program link failed:`,t.getProgramInfoLog(s)),null)}),r=[`a_x`,`a_y`,`a_z`],i=n(H1,U1,r,[`u_size`,`u_rim`]),a=n(W1,K1,r,[`u_alpha`,`u_solid`]),o=n(G1,q1,[],[`u_alpha`,`u_solid`,`u_z`,`u_n`,`u_step`,`u_wstep`,`u_wire`,`u_ext`]);if(!i||!a||!o)return null;let s=t.getParameter(t.MAX_TEXTURE_SIZE),c=t.createVertexArray(),l={x:t.createBuffer(),y:t.createBuffer(),z:t.createBuffer()},u=t.createBuffer(),d=t.createBuffer(),f=new Map,p=t.createTexture(),m=t.createTexture(),h=1,g=1,_=1,v={minX:0,maxX:1,minY:0,maxY:1,minZ:0,maxZ:1},y={kind:`2d`,h:0,v:1},b={left:0,top:0,width:1,height:1},x=null,S=0,C=[0,0,0],w=0,T=0,E=null,D={w:0,h:0},O=new Float32Array,k=(e,n,r)=>{t.bindBuffer(e,n),r.byteLength<=(f.get(n)??0)?t.bufferSubData(e,0,r):(t.bufferData(e,r,t.DYNAMIC_DRAW),f.set(n,r.byteLength))},A=(e,t)=>{let n=e.length;O.length<n&&(O=new Float32Array(n));for(let r=0;r<n;r++)O[r]=e[r]-t;return O.subarray(0,n)},j=(e,n)=>{let r=e.u,i=v;t.uniform3f(r.u_lo,i.minX-n[0],i.minY-n[1],i.minZ-n[2]);let a=(e,t)=>t-e>1e-12*Math.max(1,Math.abs(e))?t-e:0;t.uniform3f(r.u_span,a(i.minX,i.maxX),a(i.minY,i.maxY),a(i.minZ,i.maxZ));let o=e=>[+(e===0),+(e===1),+(e===2)];y.kind===`3d`?(t.uniform1i(r.u_flat,0),t.uniform3f(r.u_eye,...y.eye),t.uniform3f(r.u_right,...y.right),t.uniform3f(r.u_up,...y.up),t.uniform3f(r.u_fwd,...y.fwd),t.uniform1f(r.u_f,y.f)):(t.uniform1i(r.u_flat,1),t.uniform3f(r.u_h,...o(y.h)),t.uniform3f(r.u_v,...o(y.v))),t.uniform3f(r.u_c,...o(x.colorAxis)),t.uniform4f(r.u_plot,b.left,b.top,b.width,b.height),t.uniform2f(r.u_resolution,h,g),t.uniform1i(r.u_palette,0)},M=e=>{for(let n of[`x`,`y`,`z`]){let r=e.a[`a_${n}`];t.bindBuffer(t.ARRAY_BUFFER,l[n]),t.enableVertexAttribArray(r),t.vertexAttribPointer(r,1,t.FLOAT,!1,0,0)}};return{maxTextureSize:s,resize(t,n,r){h=Math.max(1,t),g=Math.max(1,n),_=r,e.width=Math.max(1,Math.round(h*_)),e.height=Math.max(1,Math.round(g*_))},setBounds(e){v=e},setView(e,t){y=e,b=t},setPoints(e,n,r){if(!e||!n||!r){S=0;return}S=Math.min(e.length,n.length,r.length),C=[Z1(e),Z1(n),Z1(r)],k(t.ARRAY_BUFFER,l.x,A(e,C[0]).subarray(0,S)),k(t.ARRAY_BUFFER,l.y,A(n,C[1]).subarray(0,S)),k(t.ARRAY_BUFFER,l.z,A(r,C[2]).subarray(0,S))},setTriangles(e){if(!e||e.length<3){w=T=0;return}w=e.length-e.length%3,k(t.ELEMENT_ARRAY_BUFFER,u,e.subarray(0,w));let n=new Uint32Array(w*2);for(let t=0;t<w;t+=3){let r=e[t],i=e[t+1],a=e[t+2],o=t*2;n[o]=r,n[o+1]=i,n[o+2]=i,n[o+3]=a,n[o+4]=a,n[o+5]=r}T=n.length,k(t.ELEMENT_ARRAY_BUFFER,d,n)},setSurface(e,n=0,r=0,i=[0,1],a=[0,1]){if(!e||n<2||r<2||n>s||r>s){E=null;return}let o=Z1(e),c=A(e,o).subarray(0,n*r);t.bindTexture(t.TEXTURE_2D,m),t.pixelStorei(t.UNPACK_ALIGNMENT,4),D.w===n&&D.h===r?t.texSubImage2D(t.TEXTURE_2D,0,0,0,n,r,t.RED,t.FLOAT,c):(t.texImage2D(t.TEXTURE_2D,0,t.R32F,n,r,0,t.RED,t.FLOAT,c),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),D={w:n,h:r}),E={w:n,h:r,origin:o,ext:[i[0],i[1],a[0],a[1]]}},setStyle(e){x?.palette!==e.palette&&(t.bindTexture(t.TEXTURE_2D,p),t.texImage2D(t.TEXTURE_2D,0,t.RGBA8,256,1,0,t.RGBA,t.UNSIGNED_BYTE,e.palette),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE)),x=e},render(){t.viewport(0,0,e.width,e.height),t.clearColor(0,0,0,0),t.clearDepth(1),t.clear(t.COLOR_BUFFER_BIT|t.DEPTH_BUFFER_BIT);let n=x;if(!n)return;t.bindVertexArray(c),t.enable(t.BLEND),t.blendFunc(t.ONE,t.ONE_MINUS_SRC_ALPHA),t.enable(t.DEPTH_TEST),t.depthFunc(t.LEQUAL),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,p),t.enable(t.POLYGON_OFFSET_FILL),t.polygonOffset(1,1);let r=n.wireColor;if(E){let e=o;t.useProgram(e.prog);let[i,a,s,c]=E.ext;j(e,[i,s,E.origin]),t.uniform4f(e.u.u_ext,0,a-i,0,c-s),t.activeTexture(t.TEXTURE1),t.bindTexture(t.TEXTURE_2D,m),t.uniform1i(e.u.u_z,1),t.uniform2i(e.u.u_n,E.w,E.h);let l=(E.w-1)*(E.h-1),u=Math.max(1,Math.ceil(Math.sqrt(l/J1))),d=Math.floor((E.w-2)/u)+1,f=Math.floor((E.h-2)/u)+1;if(t.uniform1i(e.u.u_step,u),t.uniform1f(e.u.u_alpha,n.fillAlpha),n.fill&&(t.uniform1i(e.u.u_wire,0),t.uniform4f(e.u.u_solid,0,0,0,0),t.drawArrays(t.TRIANGLES,0,d*f*6)),n.wire){let n=u*Math.max(1,Math.ceil(Math.max(d,f)/Y1)),i=Math.floor((E.h-1)/n)+1,a=Math.floor((E.w-1)/n)+1;t.uniform1i(e.u.u_wire,1),t.uniform1i(e.u.u_wstep,n),t.uniform4f(e.u.u_solid,...r),t.drawArrays(t.LINES,0,(i*d+a*f)*2)}t.activeTexture(t.TEXTURE0)}if(S>0){if(w>0&&(n.fill||n.wire)){let e=a;t.useProgram(e.prog),j(e,C),M(e),t.uniform1f(e.u.u_alpha,n.fillAlpha),n.fill&&(t.uniform4f(e.u.u_solid,0,0,0,0),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,u),t.drawElements(t.TRIANGLES,w,t.UNSIGNED_INT,0)),n.wire&&(t.uniform4f(e.u.u_solid,...r),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,d),t.drawElements(t.LINES,T,t.UNSIGNED_INT,0))}let e=i;t.useProgram(e.prog),j(e,C),M(e);let o=Math.max(1,2*n.pointRadius*_);t.uniform1f(e.u.u_size,o),t.uniform1f(e.u.u_rim,o>=3?Math.max(.9,n.pointRadius*.3)*_:0),t.drawArrays(t.POINTS,0,S)}t.disable(t.POLYGON_OFFSET_FILL),t.disable(t.DEPTH_TEST),t.bindVertexArray(null)},dispose(){for(let e of[l.x,l.y,l.z,u,d])t.deleteBuffer(e);t.deleteTexture(p),t.deleteTexture(m),t.deleteVertexArray(c)}}}var $1=new Map;function e0(e,t){let n=$1.get(e);if(!n){let r=typeof OffscreenCanvas>`u`?null:new OffscreenCanvas(1,1).getContext(`2d`,{willReadFrequently:!0});if(!r)return[0,0,0,t];r.fillStyle=e,r.fillRect(0,0,1,1);let i=r.getImageData(0,0,1,1).data;$1.set(e,n=[i[0]/255,i[1]/255,i[2]/255,i[3]/255])}return[n[0],n[1],n[2],n[3]*t]}function t0(e,t){return{x:e.x-t.x,y:e.y-t.y,z:e.z-t.z}}function n0(e,t){return{x:e.y*t.z-e.z*t.y,y:e.z*t.x-e.x*t.z,z:e.x*t.y-e.y*t.x}}function r0(e,t){return e.x*t.x+e.y*t.y+e.z*t.z}function i0(e){return Math.sqrt(e.x*e.x+e.y*e.y+e.z*e.z)}function a0(e){let t=i0(e);return t>1e-12?{x:e.x/t,y:e.y/t,z:e.z/t}:{x:0,y:0,z:1}}function o0(e,t,n,r){let i=Math.cos(n),a=Math.sin(n),o=Math.cos(r),s=Math.sin(r);return{x:e.x+t*o*a,y:e.y+t*s,z:e.z+t*o*i}}function s0(e,t,n){let r=a0(t0(t,e)),i=a0(n0(r,n));return{right:i,up:n0(i,r),fwd:r,eye:e}}function c0(e,t,n,r,i){let a=t0(e,t.eye),o=r0(a,t.right),s=r0(a,t.up),c=r0(a,t.fwd);if(c<.01)return{sx:-9999,sy:-9999,depth:c};let l=1/Math.tan(n/2);return{sx:r/2+o/c*l*(i/2),sy:i/2-s/c*l*(i/2),depth:c}}function l0(e,t,n,r){let i=(e,t,n)=>{let r=n-t;return r<1e-12?0:(e-t)/r*2-1};return{x:i(e,r.minX,r.maxX),y:i(n,r.minZ,r.maxZ),z:i(t,r.minY,r.maxY)}}var u0=16,d0=.1,f0=Math.PI/4,p0=Math.PI/5,m0=3.2,h0=2e4,g0=(()=>{let e=new Uint8Array(256*4);for(let t=0;t<256;t++){let{r:n,g:r,b:i}=F$(t/255);e.set([n,r,i,255],t*4)}return e})();function _0(e){if(!Array.isArray(e))return e;let t=e.length,n=new Float64Array(t),r=new Float64Array(t),i=new Float64Array(t);for(let a=0;a<t;a++)n[a]=e[a].x,r[a]=e[a].y,i[a]=e[a].z;return{length:t,x:n,y:r,z:i}}var v0=(e,t)=>!t||e>=t[0]&&e<=t[1];function y0(e,t,n,r){let i=new Uint32Array(e.length),a=0;for(let o=0;o<e.length;o++){let s=e.x[o],c=e.y[o],l=e.z[o];s-s===0&&c-c===0&&l-l===0&&v0(s,t)&&v0(c,n)&&v0(l,r)&&(i[a++]=o)}if(a<3)return null;let o=new Float64Array(a*2);for(let t=0;t<a;t++)o[2*t]=e.x[i[t]],o[2*t+1]=e.y[i[t]];try{let e=new A1(o).triangles;for(let t=0;t<e.length;t++)e[t]=i[e[t]];return e.length>=3?e:null}catch{return null}}var b0=(0,Z.forwardRef)(function({points:e,surface:t,xLabel:n,yLabel:r,zLabel:i,height:a=500,backgroundToken:o=``,xRange:s,yRange:c,zRange:l,viewMode:u,pointRadius:d=4,alarms:f,showMesh:p=!1,meshStyle:m=`filled`,meshOpacity:h=.85,onPlotContextMenu:g},_){let v=(0,Z.useRef)(g);(0,Z.useLayoutEffect)(()=>{v.current=g},[g]);let y=(0,Z.useRef)(null),b=(0,Z.useRef)(null),x=(0,Z.useRef)(null),S=(0,Z.useRef)(f0),C=(0,Z.useRef)(p0),w=(0,Z.useRef)(m0),T=(0,Z.useRef)(null),E=(0,Z.useRef)({xLabel:n,yLabel:r,zLabel:i,height:a,viewMode:u,pointRadius:d,alarms:f??[],showMesh:p,meshStyle:m,meshOpacity:h});(0,Z.useLayoutEffect)(()=>{E.current={xLabel:n,yLabel:r,zLabel:i,height:a,viewMode:u,pointRadius:d,alarms:f??[],showMesh:p,meshStyle:m,meshOpacity:h}},[n,r,i,a,u,d,f,p,m,h]);let D=(0,Z.useMemo)(()=>{let n=_0(e),r=1/0,i=-1/0,a=1/0,o=-1/0,u=1/0,d=-1/0,f=0,p=0,m=0,h=0;for(let e=0;e<n.length;e++){let t=n.x[e],g=n.y[e],_=n.z[e];t-t!==0||g-g!==0||_-_!==0||!v0(t,s)||!v0(g,c)||!v0(_,l)||(t<r&&(r=t),t>i&&(i=t),g<a&&(a=g),g>o&&(o=g),_<u&&(u=_),_>d&&(d=_),f+=t,p+=g,m+=_,h++)}let g=null;if(t&&t.w>=2&&t.h>=2){let e=t.values,n=!1;for(let r=0;r<t.w*t.h;r++){let t=e[r];t-t===0&&(n=!0,t<u&&(u=t),t>d&&(d=t))}n&&(g=t,r=Math.min(r,t.x[0],t.x[1]),i=Math.max(i,t.x[0],t.x[1]),a=Math.min(a,t.y[0],t.y[1]),o=Math.max(o,t.y[0],t.y[1]))}if(h===0&&!g)return null;s&&(r=s[0],i=s[1]),c&&(a=c[0],o=c[1]),l&&(u=l[0],d=l[1]);let _={minX:r,maxX:i,minY:a,maxY:o,minZ:u,maxZ:d},v=h>0?l0(f/h,p/h,m/h,_):{x:0,y:0,z:0};return{cols:h>0?n:null,surface:g,bounds:_,center:v}},[e,t,s,c,l]),O=u??`3d`,k=p&&(O===`3d`||O===`xy`),A=(0,Z.useMemo)(()=>k&&D?.cols?y0(D.cols,s,c,l):null,[k,D,s,c,l]),j=(0,Z.useRef)({model:D,triangles:A});(0,Z.useLayoutEffect)(()=>{j.current={model:D,triangles:A}},[D,A]);let M=(0,Z.useRef)({r:null,failed:!1,cols:null,surface:null,tris:null,size:``});function N(e,t,n){let r=M.current;!r.r&&!r.failed&&b.current&&(r.r=NX(b.current,Q1),r.failed=!r.r);let i=r.r;if(!i||!b.current)return null;let a=`${e}x${t}@${n}`;r.size!==a&&(i.resize(e,t,n),b.current.style.width=`${e}px`,b.current.style.height=`${t}px`,r.size=a);let{model:o,triangles:s}=j.current,c=o?.cols??null;r.cols!==c&&(i.setPoints(c?.x??null,c?.y,c?.z),r.cols=c);let l=o?.surface??null;return r.surface!==l&&(i.setSurface(l?.values??null,l?.w,l?.h,l?.x,l?.y),r.surface=l),r.tris!==s&&(i.setTriangles(s),r.tris=s),i}(0,Z.useEffect)(()=>()=>{M.current.r?.dispose(),M.current.r=null},[]);let P=(0,Z.useRef)(null);function F(){let e=y.current,t=x.current;if(!e||!t)return;let n=Math.max(1,t.clientWidth),r=Math.max(1,t.clientHeight),i=Math.min(2,window.devicePixelRatio||1),a=Math.floor(n*i),o=Math.floor(r*i);(e.width!==a||e.height!==o)&&(e.width=a,e.height=o);let s=e.getContext(`2d`);if(!s)return;s.setTransform(i,0,0,i,0,0);let{bg:c,muted:l,grid:u}=I(),{xLabel:d,yLabel:f,zLabel:p}=E.current,m=Math.max(.25,E.current.pointRadius??4),h=$$({top:0,right:0,bottom:0,left:0},n,r).tiny;s.fillStyle=c,s.fillRect(0,0,n,r);let g=j.current.model,_=N(n,r,i);if(!g){if(_?.setStyle({palette:g0,colorAxis:2,pointRadius:m,fill:!1,wire:!1,fillAlpha:1,wireColor:[0,0,0,0]}),_?.setPoints(null),M.current.cols=null,_?.render(),h)return;s.fillStyle=l,s.font=`13px ${X.sans}`,eX(s);return}let v=g.bounds,b=E.current.viewMode??`3d`,T=b===`xz`?1:b===`yz`?0:2,D=[v.minX,v.minY,v.minZ][T],O=[v.maxX,v.maxY,v.maxZ][T],k=(e,t,n)=>{let r=T===0?e:T===1?t:n,i=O-D;return i>1e-12?(r-D)/i:.5},A,F,L,R=(e,t,r)=>{let i=n-28,a=t/32;for(let t=0;t<32;t++)s.fillStyle=I$(1-t/32),s.fillRect(i,e+t*a,14,a+1);s.strokeStyle=u,s.lineWidth=1,s.strokeRect(i,e,14,t),s.fillStyle=l,s.font=`9px ${X.mono}`,s.textAlign=`right`,s.fillText(BJ(O),i-4,e+4),s.fillText(BJ(D),i-4,e+t),s.fillText(r,i-4,e-6)},z=e=>{s.fillStyle=l,s.font=`10px ${X.sans}`,s.textAlign=`left`,s.globalAlpha=.7,s.fillText(e,u0,r-6),s.globalAlpha=1};if(b!==`3d`){let e,t,i,a,o,c,m,g,_;b===`xy`?(e=d,t=f,i=p,a=v.minX,o=v.maxX,c=v.minY,m=v.maxY,g=0,_=1):b===`xz`?(e=d,t=p,i=f,a=v.minX,o=v.maxX,c=v.minZ,m=v.maxZ,g=0,_=2):(e=f,t=p,i=d,a=v.minY,o=v.maxY,c=v.minZ,m=v.maxZ,g=1,_=2);let y=$$({left:72,right:48,top:24,bottom:52},n,r),x=Math.max(1,n-y.left-y.right),S=Math.max(1,r-y.top-y.bottom),C=o-a||1,w=m-c||1,T=e=>y.left+(e-a)/C*x,D=e=>y.top+S-(e-c)/w*S;A={left:y.left,top:y.top,width:x,height:S},L={kind:`2d`,h:g,v:_},F=(e,t,n)=>{let r=[e,t,n];return[T(r[g]),D(r[_])]};let O=MJ(C,8),k=MJ(w,8),j=FJ(a,o,O),M=FJ(c,m,k);s.strokeStyle=u,s.lineWidth=.5,s.globalAlpha=.3;for(let e of j){let t=T(e);s.beginPath(),s.moveTo(t,y.top),s.lineTo(t,y.top+S),s.stroke()}for(let e of M){let t=D(e);s.beginPath(),s.moveTo(y.left,t),s.lineTo(y.left+x,t),s.stroke()}s.globalAlpha=1,s.strokeStyle=u,s.lineWidth=1,s.strokeRect(y.left,y.top,x,S),s.save(),s.beginPath(),s.rect(y.left,y.top,x,S),s.clip();for(let e of E.current.alarms){let{axis:t,value:n,color:r,style:i,width:a}=e,o=null,c=null;b===`xy`?t===`x`?o=T(n):t===`y`&&(c=D(n)):b===`xz`?t===`x`?o=T(n):t===`z`&&(c=D(n)):t===`y`?o=T(n):t===`z`&&(c=D(n)),!(o===null&&c===null)&&(i===`dashed`?s.setLineDash([7,4]):i===`dotted`?s.setLineDash([2,4]):s.setLineDash([]),s.strokeStyle=r,s.lineWidth=a,s.globalAlpha=.9,s.beginPath(),o===null?c!==null&&(s.moveTo(y.left,c),s.lineTo(y.left+x,c)):(s.moveTo(o,y.top),s.lineTo(o,y.top+S)),s.stroke(),s.setLineDash([]),s.globalAlpha=1,s.fillStyle=r,s.font=`bold 10px ${X.mono}`,s.globalAlpha=.95,o===null?c!==null&&(s.textAlign=`left`,s.textBaseline=`bottom`,s.fillText(BJ(n),y.left+3,c-2)):(s.textAlign=`left`,s.textBaseline=`top`,s.fillText(BJ(n),o+3,y.top+2)),s.globalAlpha=1,s.textBaseline=`alphabetic`)}if(s.restore(),!h){s.fillStyle=l,s.font=`10px ${X.mono}`,s.textAlign=`center`,s.textBaseline=`top`;for(let e of j)s.fillText(zJ(e,O),T(e),y.top+S+6);s.textAlign=`right`,s.textBaseline=`middle`;for(let e of M)s.fillText(zJ(e,k),y.left-8,D(e));s.textBaseline=`alphabetic`,s.font=`bold 11px ${X.mono}`,s.textAlign=`center`,s.fillStyle=`#fb7185`,s.fillText(e,y.left+x/2,r-8),s.save(),s.translate(14,y.top+S/2),s.rotate(-Math.PI/2),s.fillStyle=`#38bdf8`,s.textAlign=`center`,s.fillText(t,0,0),s.restore(),R(y.top+8,Math.min(S-20,180),i),z(`2D projection: ${b.toUpperCase()} plane · Color = ${i}`)}}else{let e=S.current,t=C.current,i=w.current,a=s0(o0(g.center,i,e,t),g.center,{x:0,y:1,z:0}),o=Math.PI/3,c=h?3:u0,m=Math.max(1,n-c*2),_=Math.max(1,r-c*2-(h?0:24));A={left:c,top:c,width:m,height:_};let y=e=>[e.x,e.y,e.z];L={kind:`3d`,eye:y(a.eye),right:y(a.right),up:y(a.up),fwd:y(a.fwd),f:1/Math.tan(o/2)};let b=e=>{let t=c0(e,a,o,m,_);return{sx:t.sx+c,sy:t.sy+c,depth:t.depth}};F=(e,t,n)=>{let r=b(l0(e,t,n,v));return r.depth<.02?null:[r.sx,r.sy]};let x=(e,t,n)=>{let r=b(e),i=b(t);r.depth<.02||i.depth<.02||(s.strokeStyle=n.color,s.lineWidth=n.width,s.globalAlpha=n.alpha??1,s.beginPath(),s.moveTo(r.sx,r.sy),s.lineTo(i.sx,i.sy),s.stroke(),s.globalAlpha=1)},T=MJ(v.maxX-v.minX,6),D=MJ(v.maxY-v.minY,6),O=MJ(v.maxZ-v.minZ,6),k=FJ(v.minX,v.maxX,T),j=FJ(v.minY,v.maxY,D),M=FJ(v.minZ,v.maxZ,O),N=IJ(v.minX,v.maxX,T/5,k),P=IJ(v.minY,v.maxY,D/5,j),I=IJ(v.minZ,v.maxZ,O/5,M);for(let[e,t]of[[{x:-1,y:-1,z:-1},{x:1,y:-1,z:-1}],[{x:1,y:-1,z:-1},{x:1,y:-1,z:1}],[{x:1,y:-1,z:1},{x:-1,y:-1,z:1}],[{x:-1,y:-1,z:1},{x:-1,y:-1,z:-1}],[{x:-1,y:1,z:-1},{x:1,y:1,z:-1}],[{x:1,y:1,z:-1},{x:1,y:1,z:1}],[{x:1,y:1,z:1},{x:-1,y:1,z:1}],[{x:-1,y:1,z:1},{x:-1,y:1,z:-1}],[{x:-1,y:-1,z:-1},{x:-1,y:1,z:-1}],[{x:1,y:-1,z:-1},{x:1,y:1,z:-1}],[{x:1,y:-1,z:1},{x:1,y:1,z:1}],[{x:-1,y:-1,z:1},{x:-1,y:1,z:1}]])x(e,t,{color:u,width:1,alpha:.65});if(!h){for(let e of k){let t=l0(e,v.minY,v.minZ,v).x;x({x:t,y:-1,z:-1},{x:t,y:-1,z:1},{color:u,width:.75,alpha:.45})}for(let e of j){let t=l0(v.minX,e,v.minZ,v).z;x({x:-1,y:-1,z:t},{x:1,y:-1,z:t},{color:u,width:.75,alpha:.45})}for(let e of P){let t=l0(v.minX,e,v.minZ,v).z;x({x:-1,y:-1,z:t},{x:1,y:-1,z:t},{color:u,width:.5,alpha:.22})}for(let e of N){let t=l0(e,v.minY,v.minZ,v).x;x({x:t,y:-1,z:-1},{x:t,y:-1,z:1},{color:u,width:.5,alpha:.22})}let e=(e,t)=>{let n=d0*(t?1:.55);x({x:e,y:-1,z:-1},{x:e,y:-1+n,z:-1},{color:`#fb7185`,width:t?1.25:.75,alpha:.95})},t=(e,t)=>{let n=d0*(t?1:.55);x({x:-1,y:-1,z:e},{x:-1+n,y:-1,z:e},{color:`#38bdf8`,width:t?1.25:.75,alpha:.95})},n=(e,t)=>{let n=d0*(t?1:.55);x({x:-1,y:e,z:-1},{x:-1+n,y:e,z:-1},{color:`#4ade80`,width:t?1.25:.75,alpha:.95})};for(let t of N)e(l0(t,v.minY,v.minZ,v).x,!1);for(let t of k)e(l0(t,v.minY,v.minZ,v).x,!0);for(let e of P)t(l0(v.minX,e,v.minZ,v).z,!1);for(let e of j)t(l0(v.minX,e,v.minZ,v).z,!0);for(let e of I)n(l0(v.minX,v.minY,e,v).y,!1);for(let e of M)n(l0(v.minX,v.minY,e,v).y,!0)}let B=(e,t,n)=>{let r=n-t;return r<1e-12?0:(e-t)/r*2-1};for(let e of E.current.alarms){let{axis:t,value:n,color:r,style:i,width:a}=e,o;if(t===`z`){let e=B(n,v.minZ,v.maxZ);o=[{x:-1,y:e,z:-1},{x:1,y:e,z:-1},{x:1,y:e,z:1},{x:-1,y:e,z:1}]}else if(t===`x`){let e=B(n,v.minX,v.maxX);o=[{x:e,y:-1,z:-1},{x:e,y:1,z:-1},{x:e,y:1,z:1},{x:e,y:-1,z:1}]}else{let e=B(n,v.minY,v.maxY);o=[{x:-1,y:-1,z:e},{x:1,y:-1,z:e},{x:1,y:1,z:e},{x:-1,y:1,z:e}]}let c=o.map(e=>b(e));if(c.every(e=>e.depth>=.02)){s.beginPath(),s.moveTo(c[0].sx,c[0].sy);for(let e=1;e<c.length;e++)s.lineTo(c[e].sx,c[e].sy);s.closePath(),s.fillStyle=r,s.globalAlpha=.18,s.fill(),i===`dashed`?s.setLineDash([7,4]):i===`dotted`?s.setLineDash([2,4]):s.setLineDash([]),s.strokeStyle=r,s.lineWidth=a,s.globalAlpha=.9,s.beginPath(),s.moveTo(c[0].sx,c[0].sy);for(let e=1;e<c.length;e++)s.lineTo(c[e].sx,c[e].sy);s.closePath(),s.stroke(),s.setLineDash([]),s.globalAlpha=1;let e=c.reduce((e,t)=>t.sy>e.sy?t:e);s.fillStyle=r,s.font=`bold 10px ${X.mono}`,s.textAlign=`center`,s.globalAlpha=.95,s.fillText(`${t.toUpperCase()}=${BJ(n)}`,e.sx,e.sy-6),s.globalAlpha=1}}if(!h){s.font=`10px ${X.mono}`,s.textBaseline=`middle`;for(let e of k){let t=l0(e,v.minY,v.minZ,v).x,n=b({x:t,y:-1.2,z:-1.2});n.depth<.02||(s.fillStyle=l,s.textAlign=`center`,s.fillText(zJ(e,T),n.sx,n.sy+12))}for(let e of j){let t=l0(v.minX,e,v.minZ,v).z,n=b({x:-1.22,y:-1,z:t});n.depth<.02||(s.textAlign=`right`,s.fillText(zJ(e,D),n.sx-4,n.sy))}for(let e of M){let t=l0(v.minX,v.minY,e,v).y,n=b({x:-1.22,y:t,z:-1.2});n.depth<.02||(s.textAlign=`right`,s.fillText(zJ(e,O),n.sx-4,n.sy))}s.textBaseline=`alphabetic`,s.font=`bold 11px ${X.mono}`;let e=b({x:1.15,y:-1,z:-1.15});e.depth>=.02&&(s.fillStyle=`#fb7185`,s.textAlign=`center`,s.fillText(d,e.sx,e.sy+16)),e=b({x:-1.18,y:-1,z:1.15}),e.depth>=.02&&(s.fillStyle=`#38bdf8`,s.textAlign=`center`,s.fillText(f,e.sx-10,e.sy)),e=b({x:-1.18,y:1.15,z:-1.18}),e.depth>=.02&&(s.fillStyle=`#4ade80`,s.textAlign=`center`,s.fillText(p,e.sx-10,e.sy)),R(u0+8,Math.min(r-80,180),p),z(`Drag: rotate | Wheel: zoom | Dbl‑click: reset · ${g.surface?`Surface`:E.current.showMesh?`Mesh: ${E.current.meshStyle}`:`Scatter`} · color = Z`)}}let{showMesh:B,meshStyle:V,meshOpacity:ee}=E.current,H=!!g.surface||B;if(_)_.setBounds(v),_.setView(L,A),_.setStyle({palette:g0,colorAxis:T,pointRadius:m,fill:H&&(V===`filled`||V===`both`),wire:H&&(V===`wireframe`||V===`both`),fillAlpha:ee,wireColor:e0(u,.5)}),_.render(),P.current!==g&&(P.current=g,lZ(t));else if(g.cols){let e=g.cols,t=Math.max(1,Math.ceil(e.length/h0));for(let n=0;n<e.length;n+=t){let t=e.x[n],r=e.y[n],i=e.z[n];if(!(t>=v.minX&&t<=v.maxX&&r>=v.minY&&r<=v.maxY&&i>=v.minZ&&i<=v.maxZ))continue;let a=F(t,r,i);a&&(s.fillStyle=I$(k(t,r,i)),s.beginPath(),s.arc(a[0],a[1],m,0,Math.PI*2),s.fill())}}}function I(){if(T.current)return T.current;let e=x.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return T.current=n,n}let L=(0,Z.useRef)(F);(0,Z.useLayoutEffect)(()=>{L.current=F});let R=(0,Z.useRef)(null);R.current??=mZ(()=>L.current(),()=>x.current),(0,Z.useEffect)(()=>()=>R.current?.cancel(),[]);let z=()=>{S.current=f0,C.current=p0,w.current=m0,R.current.schedule()};return(0,Z.useImperativeHandle)(_,()=>({autoscale:z}),[]),(0,Z.useEffect)(()=>sY(x.current,()=>{T.current=null,R.current.schedule()}),[]),(0,Z.useEffect)(()=>{T.current=null,R.current.schedule()},[o]),(0,Z.useEffect)(()=>{R.current.now()},[D,A,n,r,i,a,u,d,f,p,m,h]),(0,Z.useEffect)(()=>{let e=y.current,t=x.current;if(!e||!t)return;let n=()=>R.current.schedule(),r=new fZ(()=>{T.current=null,n()});r.observe(t);let i=!1,a=0,o=0,s=t=>{t.button===0&&(i=!0,a=t.clientX,o=t.clientY,e.setPointerCapture(t.pointerId))},c=e=>{if(!i)return;let t=e.clientX-a,r=e.clientY-o;a=e.clientX,o=e.clientY,S.current-=t*.008,C.current+=r*.008,C.current=Math.max(-Math.PI/2+.05,Math.min(Math.PI/2-.05,C.current)),n()},l=()=>{i=!1},u=e=>{e.preventDefault();let t=e.deltaY>0?1.08:.92;w.current=Math.max(1.2,Math.min(12,w.current*t)),n()},d=()=>{S.current=f0,C.current=p0,w.current=m0,n()},f=e=>{e.preventDefault(),v.current?.({clientX:e.clientX,clientY:e.clientY})};return e.addEventListener(`pointerdown`,s),e.addEventListener(`pointermove`,c),e.addEventListener(`pointerup`,l),e.addEventListener(`pointercancel`,l),e.addEventListener(`wheel`,u,{passive:!1}),e.addEventListener(`contextmenu`,f),e.addEventListener(`dblclick`,d),()=>{r.disconnect(),e.removeEventListener(`pointerdown`,s),e.removeEventListener(`pointermove`,c),e.removeEventListener(`pointerup`,l),e.removeEventListener(`pointercancel`,l),e.removeEventListener(`wheel`,u),e.removeEventListener(`contextmenu`,f),e.removeEventListener(`dblclick`,d)}},[]),(0,Q.jsxs)(`div`,{ref:x,className:`chart-canvas-wrap`,children:[(0,Q.jsx)(`canvas`,{ref:y,className:`chart-canvas`,role:`img`,"aria-label":`3D scatter: ${n} vs ${r} vs ${i}`,style:{display:`block`,width:`100%`,height:`100%`,cursor:`grab`}}),(0,Q.jsx)(`canvas`,{ref:b,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}})]})}),x0={top:14,right:24,bottom:40,left:64},S0=5;function C0(e){return e===`dashed`?[5,4]:e===`dotted`?[1,4]:[]}function w0(e){return Math.max(10,Math.min(200,Math.ceil(Math.sqrt(e))))}function T0(e,t,n){let r=(e-t)/n;return Math.exp(-.5*r*r)/(n*Math.sqrt(2*Math.PI))}function E0(e,t){let n=e.length;if(n===0)return null;let r=1/0,i=-1/0,a=0;for(let t=0;t<n;t++){let n=e[t];n<r&&(r=n),n>i&&(i=n),a+=n}r===i&&(--r,i+=1);let o=t>0?t:w0(n),s=(i-r)/o,c=Array(o).fill(0),l=a/n,u=0;for(let t=0;t<n;t++){let n=e[t];c[Math.min(o-1,Math.floor((n-r)/s))]++,u+=(n-l)**2}return{lo:r,hi:i,nBins:o,width:s,counts:c,mean:l,sd:Math.sqrt(u/n),total:n}}function D0({values:e,label:t,bins:n=0,color:r=`#38bdf8`,showNormal:i=!1,logY:a=!1,height:o=400,backgroundToken:s=``,onPlotContextMenu:c}){let l=iQ(),u=(0,Z.useRef)(null),d=(0,Z.useRef)(null),f=(0,Z.useRef)(null),p=(0,Z.useRef)(null),m=(0,Z.useRef)(0),h=(0,Z.useRef)(null),g=(0,Z.useRef)(c);(0,Z.useLayoutEffect)(()=>{g.current=c},[c]);let _=(0,Z.useRef)({values:e,label:t,bins:n,color:r,showNormal:i,logY:a,height:o});(0,Z.useLayoutEffect)(()=>{_.current={values:e,label:t,bins:n,color:r,showNormal:i,logY:a,height:o}},[e,t,n,r,i,a,o]);function v(){if(h.current)return h.current;let e=f.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return h.current=n,n}function y(){let e=f.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||_.current.height)}}function b(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}let x=(0,Z.useMemo)(()=>E0(e,n),[e,n]),S=(0,Z.useRef)(x);(0,Z.useLayoutEffect)(()=>{S.current=x},[x]);let C=()=>S.current;function w(){let e=u.current;if(!e)return;let{w:t,h:n}=y(),r=b(e,t,n);if(!r)return;let{top:i,right:a,bottom:o,left:s}=x0,c=t-s-a,d=n-i-o,{bg:f,muted:p,grid:m}=v(),{label:h,color:g,showNormal:x,logY:S}=_.current;r.fillStyle=f,r.fillRect(0,0,t,n);let w=C();if(!w||c<=0||d<=0){r.fillStyle=p,r.font=`13px ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,eX(r);return}let{lo:T,hi:E,nBins:D,width:O,counts:k,mean:A,sd:j,total:M}=w,N=Math.max(...k),P=S?Math.log10(N+1)+.1:N*1.08,F=e=>s+(e-T)/(E-T)*c;l({left:s,top:i,width:c,height:d,x:{v0:T,v1:E}});let I=e=>i+(P-(S?e>0?Math.log10(e):0:e))/(P-0)*d,L=S?1:MJ(P,5),R=FJ(0,S?P:N,L);r.strokeStyle=m,r.lineWidth=1,r.setLineDash(C0(`dashed`));for(let e of R){let t=I(e);r.beginPath(),r.moveTo(s,t),r.lineTo(s+c,t),r.stroke()}r.setLineDash([]);let z=Math.max(.5,c/D*.04);for(let e=0;e<D;e++){let t=F(T+e*O)+z/2,n=F(T+(e+1)*O)-z/2,i=I(0),a=I(k[e]);r.fillStyle=g,r.globalAlpha=.75,r.fillRect(t,a,n-t,i-a),r.globalAlpha=1}if(x&&j>0){r.beginPath();for(let e=0;e<=200;e++){let t=T+e/200*(E-T),n=T0(t,A,j)*M*O,i=F(t),a=I(n);e===0?r.moveTo(i,a):r.lineTo(i,a)}r.strokeStyle=`#f97316`,r.lineWidth=1,r.stroke()}r.strokeStyle=p,r.lineWidth=1,r.fillStyle=p,r.font=`11px ${X.mono}`,r.textAlign=`right`,r.textBaseline=`middle`;for(let e of R){let t=I(e);r.beginPath(),r.moveTo(s-S0,t),r.lineTo(s,t),r.stroke(),r.fillText(S?`10^${e.toFixed(0)}`:zJ(e,L),s-4,t)}let B=MJ(E-T,NJ(c)),V=FJ(T,E,B);r.fillStyle=p,r.textAlign=`center`,r.textBaseline=`top`;for(let e of V){let t=F(e);r.beginPath(),r.moveTo(t,i+d),r.lineTo(t,i+d+S0),r.stroke(),r.fillText(zJ(e,B),t,i+d+S0+2)}r.strokeStyle=m,r.lineWidth=1,r.strokeRect(s,i,c,d),r.fillStyle=p,r.font=`11px ${X.mono}`,r.textAlign=`center`,r.textBaseline=`bottom`,r.fillText(h,s+c/2,n-4),r.save(),r.translate(14,i+d/2),r.rotate(-Math.PI/2),r.textAlign=`center`,r.textBaseline=`middle`,r.fillText(S?`log₁₀(count)`:`count`,0,0),r.restore()}let T=(0,Z.useRef)(w);T.current=w;let E=(0,Z.useRef)(null);E.current??=mZ(()=>T.current(),()=>f.current);let D=()=>E.current.schedule();function O(e){let t=d.current;if(!t)return;let{w:n,h:r}=y(),i=b(t,n,r);if(!i||(i.clearRect(0,0,n,r),e===null))return;let{top:a,right:o,bottom:s,left:c}=x0,l=n-c-o,u=r-a-s,{muted:f}=v(),p=C();if(!p)return;let{lo:m,hi:h,width:g,counts:_}=p,x=e=>c+(e-m)/(h-m)*l,S=x(m+e*g),w=x(m+(e+1)*g);i.fillStyle=`rgba(255,255,255,0.12)`,i.fillRect(S,a,w-S,u);let T=(S+w)/2,E=_[e],D=(E/p.total*100).toFixed(1),O=`${BJ(m+e*g)} – ${BJ(m+(e+1)*g)}`,k=`n = ${E} (${D}%)`;i.font=`11px ${X.mono}`;let A=i.measureText(k).width,j=i.measureText(O).width,M=Math.max(A,j),N=Math.min(T+8,c+l-M-8);i.fillStyle=f,i.textAlign=`left`,i.textBaseline=`top`,i.fillText(O,N,a+8),i.fillText(k,N,a+22)}function k(){sZ(m.current),m.current=oZ(()=>O(p.current))}return(0,Z.useEffect)(()=>{E.current.now()}),(0,Z.useEffect)(()=>()=>E.current?.cancel(),[]),(0,Z.useEffect)(()=>{h.current=null,D()},[s]),(0,Z.useLayoutEffect)(()=>{let e=f.current;if(!e)return;let t=new fZ(()=>{h.current=null,D(),k()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{let e=d.current;if(!e)return;function t(t){let n=e.getBoundingClientRect(),{left:r}=x0,i=n.width-x0.left-x0.right,a=C();if(!a||i<=0){p.current=null,k();return}let o=t.clientX-n.left-r,s=Math.floor(o/i*a.nBins);p.current=s>=0&&s<a.nBins?s:null,k()}function n(){p.current=null,k()}function r(e){e.preventDefault(),g.current?.({clientX:e.clientX,clientY:e.clientY})}return e.addEventListener(`mousemove`,t),e.addEventListener(`mouseleave`,n),e.addEventListener(`contextmenu`,r),()=>{e.removeEventListener(`mousemove`,t),e.removeEventListener(`mouseleave`,n),e.removeEventListener(`contextmenu`,r)}},[]),(0,Q.jsxs)(`div`,{ref:f,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:u,className:`chart-canvas`,role:`img`,"aria-label":`Histogram of ${t}`}),(0,Q.jsx)(`canvas`,{ref:d,className:`chart-canvas chart-overlay`})]})}var O0=`
|
|
505
505
|
uniform vec2 u_resolution;
|
|
506
506
|
uniform vec4 u_plot; // left, top, width, height (CSS px)
|
|
507
507
|
uniform vec4 u_view; // xmin, xmax, ymin, ymax (relative to the layer origin)
|
|
@@ -510,7 +510,7 @@ vec2 project(float x, float y) {
|
|
|
510
510
|
u_plot.y + (u_view.w - y) / (u_view.w - u_view.z) * u_plot.w);
|
|
511
511
|
}
|
|
512
512
|
vec4 toClip(vec2 p) { vec2 c = p / u_resolution * 2.0 - 1.0; return vec4(c.x, -c.y, 0.0, 1.0); }
|
|
513
|
-
`,
|
|
513
|
+
`,k0=`
|
|
514
514
|
uniform vec4 u_clip; // left, top, right, bottom (CSS px)
|
|
515
515
|
uniform float u_dpr;
|
|
516
516
|
uniform float u_height; // canvas height (device px)
|
|
@@ -518,23 +518,23 @@ bool outside() {
|
|
|
518
518
|
vec2 f = vec2(gl_FragCoord.x, u_height - gl_FragCoord.y) / u_dpr;
|
|
519
519
|
return f.x < u_clip.x || f.x > u_clip.z || f.y < u_clip.y || f.y > u_clip.w;
|
|
520
520
|
}
|
|
521
|
-
`,
|
|
521
|
+
`,A0=`#version 300 es
|
|
522
522
|
in vec2 a_corner; // (0|1 along x, 0 = lo | 1 = hi)
|
|
523
523
|
in float a_xa; in float a_xb;
|
|
524
524
|
in float a_loa; in float a_lob;
|
|
525
525
|
in float a_hia; in float a_hib;
|
|
526
526
|
in float a_bstart;
|
|
527
|
-
${
|
|
527
|
+
${O0}
|
|
528
528
|
void main() {
|
|
529
529
|
if (a_bstart > 0.5) { gl_Position = vec4(2.0, 2.0, 2.0, 1.0); return; }
|
|
530
530
|
float x = a_corner.x < 0.5 ? a_xa : a_xb;
|
|
531
531
|
float lo = a_corner.x < 0.5 ? a_loa : a_lob;
|
|
532
532
|
float hi = a_corner.x < 0.5 ? a_hia : a_hib;
|
|
533
533
|
gl_Position = toClip(project(x, a_corner.y < 0.5 ? lo : hi));
|
|
534
|
-
}`,
|
|
534
|
+
}`,j0=`#version 300 es
|
|
535
535
|
in vec2 a_corner; // (0|1, 0|1)
|
|
536
536
|
in float a_x0; in float a_x1; in float a_y0; in float a_y1; in float a_k;
|
|
537
|
-
${
|
|
537
|
+
${O0}
|
|
538
538
|
flat out float v_k;
|
|
539
539
|
void main() {
|
|
540
540
|
vec2 p0 = project(a_x0, a_y0), p1 = project(a_x1, a_y1);
|
|
@@ -544,29 +544,29 @@ void main() {
|
|
|
544
544
|
vec2 half_ = max((hi - lo) * 0.5, vec2(0.5));
|
|
545
545
|
v_k = a_k;
|
|
546
546
|
gl_Position = toClip(c + (a_corner * 2.0 - 1.0) * half_);
|
|
547
|
-
}`,
|
|
547
|
+
}`,M0=`#version 300 es
|
|
548
548
|
precision highp float;
|
|
549
549
|
uniform vec4 u_color;
|
|
550
|
-
${
|
|
550
|
+
${k0}
|
|
551
551
|
out vec4 outColor;
|
|
552
552
|
void main() {
|
|
553
553
|
if (outside()) discard;
|
|
554
554
|
outColor = vec4(u_color.rgb * u_color.a, u_color.a);
|
|
555
|
-
}`,
|
|
555
|
+
}`,N0=`#version 300 es
|
|
556
556
|
precision highp float;
|
|
557
557
|
flat in float v_k;
|
|
558
558
|
uniform sampler2D u_palette;
|
|
559
|
-
${
|
|
559
|
+
${k0}
|
|
560
560
|
out vec4 outColor;
|
|
561
561
|
void main() {
|
|
562
562
|
if (outside()) discard;
|
|
563
563
|
vec4 c = texture(u_palette, vec2((v_k + 0.5) / 256.0, 0.5));
|
|
564
564
|
outColor = vec4(c.rgb * c.a, c.a);
|
|
565
|
-
}`,
|
|
565
|
+
}`,P0=`#version 300 es
|
|
566
566
|
in vec2 a_corner;
|
|
567
567
|
in float a_ax; in float a_ay; in float a_bx; in float a_by;
|
|
568
568
|
in float a_bstart;
|
|
569
|
-
${
|
|
569
|
+
${O0}
|
|
570
570
|
uniform float u_ext;
|
|
571
571
|
flat out vec2 v_a;
|
|
572
572
|
flat out vec2 v_b;
|
|
@@ -582,14 +582,14 @@ void main() {
|
|
|
582
582
|
vec2 pos = base + dir * (a_corner.x * u_ext) + n * (a_corner.y * u_ext);
|
|
583
583
|
v_a = a; v_b = b; v_pos = pos;
|
|
584
584
|
gl_Position = toClip(pos);
|
|
585
|
-
}`,
|
|
585
|
+
}`,F0=`#version 300 es
|
|
586
586
|
precision highp float;
|
|
587
587
|
flat in vec2 v_a;
|
|
588
588
|
flat in vec2 v_b;
|
|
589
589
|
in vec2 v_pos;
|
|
590
590
|
uniform vec4 u_color;
|
|
591
591
|
uniform float u_half;
|
|
592
|
-
${
|
|
592
|
+
${k0}
|
|
593
593
|
out vec4 outColor;
|
|
594
594
|
void main() {
|
|
595
595
|
if (outside()) discard;
|
|
@@ -601,21 +601,21 @@ void main() {
|
|
|
601
601
|
if (cov <= 0.0) discard;
|
|
602
602
|
float a = u_color.a * cov;
|
|
603
603
|
outColor = vec4(u_color.rgb * a, a);
|
|
604
|
-
}`,
|
|
604
|
+
}`,I0=`#version 300 es
|
|
605
605
|
in vec2 a_corner; // (0|1, 0|1)
|
|
606
606
|
uniform vec4 u_extent; // x0, x1, y0, y1 (relative to the layer origin)
|
|
607
|
-
${
|
|
607
|
+
${O0}
|
|
608
608
|
out vec2 v_uv;
|
|
609
609
|
void main() {
|
|
610
610
|
v_uv = a_corner;
|
|
611
611
|
gl_Position = toClip(project(mix(u_extent.x, u_extent.y, a_corner.x), mix(u_extent.z, u_extent.w, a_corner.y)));
|
|
612
|
-
}`,
|
|
612
|
+
}`,L0=`#version 300 es
|
|
613
613
|
precision highp float;
|
|
614
614
|
in vec2 v_uv;
|
|
615
615
|
uniform highp sampler2D u_values;
|
|
616
616
|
uniform sampler2D u_palette;
|
|
617
617
|
uniform vec2 u_range; // vmin, vmax
|
|
618
|
-
${
|
|
618
|
+
${k0}
|
|
619
619
|
out vec4 outColor;
|
|
620
620
|
void main() {
|
|
621
621
|
if (outside()) discard;
|
|
@@ -624,14 +624,15 @@ void main() {
|
|
|
624
624
|
float t = u_range.y > u_range.x ? clamp((v - u_range.x) / (u_range.y - u_range.x), 0.0, 1.0) : 0.5;
|
|
625
625
|
vec4 c = texture(u_palette, vec2((floor(t * 255.0) + 0.5) / 256.0, 0.5));
|
|
626
626
|
outColor = vec4(c.rgb * c.a, c.a);
|
|
627
|
-
}`,g0=-3e38;function _0(e){for(let t=0;t<e.length;t++)if(e[t]-e[t]===0)return e[t];return 0}function v0(e){let t=e.getContext(`webgl2`,{antialias:!1,alpha:!0,premultipliedAlpha:!0});if(!t)return null;let n=(e,n,i,a)=>uX(t,`glPlot|${e}|${n}`,()=>r(e,n,i,a)),r=(e,n,r,i)=>{let a=QY(t,t.VERTEX_SHADER,e),o=QY(t,t.FRAGMENT_SHADER,n);if(!a||!o)return null;let s=t.createProgram();if(t.attachShader(s,a),t.attachShader(s,o),t.linkProgram(s),!t.getProgramParameter(s,t.LINK_STATUS))return console.error(`glPlot program link failed:`,t.getProgramInfoLog(s)),null;let c=[`u_resolution`,`u_plot`,`u_view`,`u_clip`,`u_dpr`,`u_height`];return{prog:s,shaders:[a,o],a:Object.fromEntries([`a_corner`,...r].map(e=>[e,t.getAttribLocation(s,e)])),u:Object.fromEntries([...c,...i].map(e=>[e,t.getUniformLocation(s,e)]))}},i=n(c0,u0,[`a_xa`,`a_xb`,`a_loa`,`a_lob`,`a_hia`,`a_hib`,`a_bstart`],[`u_color`]),a=n(l0,d0,[`a_x0`,`a_x1`,`a_y0`,`a_y1`,`a_k`],[`u_palette`]),o=n(f0,p0,[`a_ax`,`a_ay`,`a_bx`,`a_by`,`a_bstart`],[`u_color`,`u_half`,`u_ext`]),s=n(m0,h0,[],[`u_extent`,`u_values`,`u_palette`,`u_range`]);if(!i||!a||!o||!s)return null;let c=t.getParameter(t.MAX_TEXTURE_SIZE),l=t.createVertexArray(),u=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,u),t.bufferData(t.ARRAY_BUFFER,Float32Array.from([0,0,1,0,0,1,1,1]),t.STATIC_DRAW);let d=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,d),t.bufferData(t.ARRAY_BUFFER,Float32Array.from([-1,-1,1,-1,-1,1,1,1]),t.STATIC_DRAW);let f=new Map,p=1,m=1,h=1,g={xmin:0,xmax:1,ymin:0,ymax:1},_={left:0,top:0,width:1,height:1},v=new WeakMap,y=new Float32Array,b=e=>{for(let n of Object.values(e.buffers))t.deleteBuffer(n);e.palette&&t.deleteTexture(e.palette),e.values&&t.deleteTexture(e.values)},x=new Float32Array,S=(e,n)=>{t.bindTexture(t.TEXTURE_2D,e),t.texImage2D(t.TEXTURE_2D,0,t.RGBA8,256,1,0,t.RGBA,t.UNSIGNED_BYTE,n),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE)},C=(e,t)=>{let n=f.get(e);if(n&&n.kind===t)return n;n&&b(n);let r={kind:t,n:0,ox:0,oy:0,buffers:{},color:[0,0,0,1],width:1};return f.set(e,r),r},w=(e,n,r)=>{let i=e.buffers[n]??=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,i),r.byteLength<=(v.get(i)??0)?t.bufferSubData(t.ARRAY_BUFFER,0,r):(t.bufferData(t.ARRAY_BUFFER,r,t.DYNAMIC_DRAW),v.set(i,r.byteLength))},T=(e,t,n,r)=>{let i=n.length;y.length<i&&(y=new Float32Array(i));for(let e=0;e<i;e++)y[e]=n[e]-r;w(e,t,y.subarray(0,i))},E=(e,t,n)=>{let r=new Uint8Array(e);t&&r.set(t.subarray(0,e)),e&&(r[0]=255);for(let t=0;t<e;t++)n(t)||(r[t]=255,t+1<e&&(r[t+1]=255));return r},D=(e,n,r=0,i=t.FLOAT)=>{if(e<0)return;t.bindBuffer(t.ARRAY_BUFFER,n),t.enableVertexAttribArray(e);let a=i===t.FLOAT?4:1;t.vertexAttribPointer(e,1,i,i!==t.FLOAT,a,r*a),t.vertexAttribDivisor(e,1)},O=(n,r,i)=>{t.useProgram(n.prog),t.uniform2f(n.u.u_resolution,p,m),t.uniform4f(n.u.u_plot,_.left,_.top,_.width,_.height),t.uniform4f(n.u.u_view,g.xmin-r.ox,g.xmax-r.ox,g.ymin-r.oy,g.ymax-r.oy),t.uniform4f(n.u.u_clip,_.left,_.top,_.left+_.width,_.top+_.height),t.uniform1f(n.u.u_dpr,h),t.uniform1f(n.u.u_height,e.height),t.bindBuffer(t.ARRAY_BUFFER,i),t.enableVertexAttribArray(n.a.a_corner),t.vertexAttribPointer(n.a.a_corner,2,t.FLOAT,!1,0,0),t.vertexAttribDivisor(n.a.a_corner,0)},k=e=>{for(let n of Object.values(e.a))n>=0&&t.vertexAttribDivisor(n,0)};return{resize(t,n,r){p=Math.max(1,t),m=Math.max(1,n),h=r,e.width=Math.round(p*h),e.height=Math.round(m*h)},setView(e,t,n,r,i){g={xmin:e,xmax:t,ymin:n,ymax:r},_=i},setBands(e,t,n,r,i,a){let o=C(e,`bands`),s=Math.min(t.length,n.length,r.length);o.ox=_0(t),o.oy=_0(r),T(o,`x`,t,o.ox),T(o,`lo`,n,o.oy),T(o,`hi`,r,o.oy),w(o,`start`,E(s,a,e=>t[e]-t[e]===0&&n[e]-n[e]===0&&r[e]-r[e]===0)),o.n=Math.max(0,s-1),o.color=i},setRects(e,n,r,i,a,o,s){let c=C(e,`rects`),l=Math.min(n.length,r.length,i.length,a.length);c.ox=_0(n),c.oy=_0(i),T(c,`x0`,n,c.ox),T(c,`x1`,r,c.ox),T(c,`y0`,i,c.oy),T(c,`y1`,a,c.oy),s?T(c,`k`,s,0):delete c.buffers.k;let u=new Uint8Array(256*4);for(let e=0;e<256;e++){let t=o[Math.min(e,o.length-1)]??[0,0,0,1];u.set([t[0]*255,t[1]*255,t[2]*255,t[3]*255],e*4)}c.palette??=t.createTexture(),t.bindTexture(t.TEXTURE_2D,c.palette),t.texImage2D(t.TEXTURE_2D,0,t.RGBA8,256,1,0,t.RGBA,t.UNSIGNED_BYTE,u),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),c.n=l},setLine(e,t,n,r,i,a){let o=C(e,`line`),s=Math.min(t.length,n.length);o.ox=_0(t),o.oy=_0(n),T(o,`x`,t,o.ox),T(o,`y`,n,o.oy),w(o,`start`,E(s,a,e=>t[e]-t[e]===0&&n[e]-n[e]===0)),o.n=Math.max(0,s-1),o.color=r,o.width=i},maxTextureSize:c,setGrid(e,n,r,i,a,o,s,c){let l=C(e,`grid`),u=r*i,d=0;for(let e=0;e<u;e++)d+=n[e]*0;let f=n.subarray(0,u);if(d!==0){x.length<u&&(x=new Float32Array(u));for(let e=0;e<u;e++){let t=n[e];x[e]=t===t?t:g0}f=x.subarray(0,u)}let p=!l.values;l.values??=t.createTexture(),t.bindTexture(t.TEXTURE_2D,l.values),t.pixelStorei(t.UNPACK_ALIGNMENT,4),!p&&l.grid&&l.grid.w===r&&l.grid.h===i?t.texSubImage2D(t.TEXTURE_2D,0,0,0,r,i,t.RED,t.FLOAT,f):(t.texImage2D(t.TEXTURE_2D,0,t.R32F,r,i,0,t.RED,t.FLOAT,f),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE)),l.palette??=t.createTexture(),S(l.palette,o);let[m,h,g,_]=a;l.ox=m,l.oy=g,l.grid={w:r,h:i,x0:m,x1:h,y0:g,y1:_,vmin:s,vmax:c},l.n=1},setGridRange(e,t,n){let r=f.get(e);r?.grid&&(r.grid.vmin=t,r.grid.vmax=n)},remove(e){let t=f.get(e);t&&(b(t),f.delete(e))},keep(e){let t=new Set(e);for(let e of[...f.keys()])t.has(e)||this.remove(e)},render(){t.bindFramebuffer(t.FRAMEBUFFER,null),t.viewport(0,0,e.width,e.height),t.disable(t.SCISSOR_TEST),t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT),t.bindVertexArray(l),t.enable(t.BLEND),t.blendFunc(t.ONE,t.ONE_MINUS_SRC_ALPHA);for(let e of f.values()){if(e.n<=0)continue;let n=e.buffers;if(e.kind===`bands`)O(i,e,u),t.uniform4f(i.u.u_color,...e.color),D(i.a.a_xa,n.x,0),D(i.a.a_xb,n.x,1),D(i.a.a_loa,n.lo,0),D(i.a.a_lob,n.lo,1),D(i.a.a_hia,n.hi,0),D(i.a.a_hib,n.hi,1),D(i.a.a_bstart,n.start,1,t.UNSIGNED_BYTE),t.drawArraysInstanced(t.TRIANGLE_STRIP,0,4,e.n),k(i);else if(e.kind===`grid`){let n=e.grid;O(s,e,u),t.uniform4f(s.u.u_extent,0,n.x1-n.x0,0,n.y1-n.y0),t.uniform2f(s.u.u_range,n.vmin,n.vmax),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,e.values),t.uniform1i(s.u.u_values,0),t.activeTexture(t.TEXTURE1),t.bindTexture(t.TEXTURE_2D,e.palette),t.uniform1i(s.u.u_palette,1),t.drawArrays(t.TRIANGLE_STRIP,0,4),t.activeTexture(t.TEXTURE0)}else e.kind===`rects`?(O(a,e,u),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,e.palette),t.uniform1i(a.u.u_palette,0),D(a.a.a_x0,n.x0),D(a.a.a_x1,n.x1),D(a.a.a_y0,n.y0),D(a.a.a_y1,n.y1),n.k?D(a.a.a_k,n.k):(t.disableVertexAttribArray(a.a.a_k),t.vertexAttrib1f(a.a.a_k,0)),t.drawArraysInstanced(t.TRIANGLE_STRIP,0,4,e.n),k(a)):(O(o,e,d),t.uniform4f(o.u.u_color,...e.color),t.uniform1f(o.u.u_half,e.width/2),t.uniform1f(o.u.u_ext,e.width/2+1.5),D(o.a.a_ax,n.x,0),D(o.a.a_bx,n.x,1),D(o.a.a_ay,n.y,0),D(o.a.a_by,n.y,1),D(o.a.a_bstart,n.start,1,t.UNSIGNED_BYTE),t.drawArraysInstanced(t.TRIANGLE_STRIP,0,4,e.n),k(o))}t.bindVertexArray(null)},dispose(){for(let e of f.values())b(e);f.clear(),t.deleteBuffer(u),t.deleteBuffer(d),t.deleteVertexArray(l)}}}function y0(e){let t=(0,Z.useRef)({plot:null,failed:!1,size:``});return(0,Z.useEffect)(()=>()=>{t.current.plot?.dispose(),t.current.plot=null},[]),(0,Z.useCallback)((n,r)=>{let i=t.current,a=e.current;if(!i.plot&&!i.failed&&a&&(i.plot=dX(a,v0),i.failed=!i.plot),!i.plot||!a)return null;let o=Math.min(2,window.devicePixelRatio||1),s=`${n}x${r}@${o}`;return i.size!==s&&(i.plot.resize(n,r,o),a.style.width=`${n}px`,a.style.height=`${r}px`,i.size=s),i.plot},[e])}function b0(e){let t=!1;for(let n=0;n<e.length;n++)if(Math.abs(e[n])>Math.PI*2){t=!0;break}let n=new Float64Array(e.length);for(let r=0;r<e.length;r++)n[r]=t?e[r]*Math.PI/180:e[r];return n}var x0=16;function S0(e,t,n,r){let i=b0(e),a=Math.min(i.length,t.length),o=1/0,s=-1/0;for(let e=0;e<a;e++){let n=t[e];n<o&&(o=n),n>s&&(s=n)}let c=n??Math.min(0,o),l=r??s,u=l-c||1,d=new Float64Array(a),f=new Float64Array(a),p=new Float64Array(x0),m=new Int32Array(x0);for(let e=0;e<a;e++){let n=Math.max(0,(t[e]-c)/u),r=i[e];n>1.0001?d[e]=f[e]=NaN:(d[e]=Math.sin(r)*n,f[e]=Math.cos(r)*n);let a=r%(2*Math.PI);a<0&&(a+=2*Math.PI);let o=Math.min(x0-1,Math.floor(a/(2*Math.PI)*x0));p[o]+=t[e],m[o]++}return{n:a,rMin:c,rMax:l,x:d,y:f,means:Array.from({length:x0},(e,t)=>m[t]>0?p[t]/m[t]:0)}}function C0({angles:e,radii:t,angleLabel:n,radiusLabel:r,color:i=`#a78bfa`,mode:a=`waveform`,radiusMin:o,radiusMax:s,height:c=400,backgroundToken:l=``,onPlotContextMenu:u}){let d=(0,Z.useRef)(null),f=(0,Z.useRef)(null),p=(0,Z.useRef)(null),m=(0,Z.useRef)(u);(0,Z.useLayoutEffect)(()=>{m.current=u},[u]);let h=(0,Z.useRef)({angles:e,radii:t,angleLabel:n,radiusLabel:r,color:i,mode:a,radiusMin:o,radiusMax:s,height:c});(0,Z.useLayoutEffect)(()=>{h.current={angles:e,radii:t,angleLabel:n,radiusLabel:r,color:i,mode:a,radiusMin:o,radiusMax:s,height:c}},[e,t,n,r,i,a,o,s,c]);let g=(0,Z.useMemo)(()=>S0(e,t,o,s),[e,t,o,s]),_=(0,Z.useRef)(g);(0,Z.useLayoutEffect)(()=>{_.current=g},[g]);let v=(0,Z.useRef)(null),y=y0(v),b=(0,Z.useRef)({geo:null,color:``});function x(){if(p.current)return p.current;let e=f.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return p.current=n,n}function S(){let e=f.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||h.current.height)}}function C(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function w(){let e=d.current;if(!e)return;let{w:t,h:n}=S(),r=C(e,t,n);if(!r)return;let{bg:i,muted:a,grid:o}=x(),{angleLabel:s,radiusLabel:c,color:l,mode:u}=h.current,f=_.current,{n:p,rMin:m,rMax:g}=f;r.fillStyle=i,r.fillRect(0,0,t,n);let v=y(t,n);if(p===0){v?.keep([]),v?.render(),r.fillStyle=a,r.font=`13px ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,MY(r);return}let w=g-m||1,T=(Math.min(t-64,n-32-24)-4)/2,E=t/2,D=32+T,O=uJ(w,4),k=pJ(m,g,O);r.strokeStyle=o,r.lineWidth=1,r.setLineDash([3,3]);for(let e of k){let t=(e-m)/w*T;t<0||(r.beginPath(),r.arc(E,D,t,0,Math.PI*2),r.stroke())}r.setLineDash([]),r.strokeStyle=o,r.lineWidth=1;for(let e=0;e<360;e+=30){let t=e*Math.PI/180;r.beginPath(),r.moveTo(E,D),r.lineTo(E+Math.cos(-t+Math.PI/2)*T,D+Math.sin(-t+Math.PI/2)*T),r.stroke()}r.fillStyle=a,r.font=`10px ${X.mono}`,r.textAlign=`center`,r.textBaseline=`middle`;for(let e=0;e<360;e+=30){let t=e*Math.PI/180,n=E+Math.sin(t)*(T+14),i=D-Math.cos(t)*(T+14);r.fillText(`${e}°`,n,i)}r.textAlign=`left`,r.textBaseline=`middle`;for(let e of k){let t=(e-m)/w*T;t<4||r.fillText(_J(e,O),E+4,D-t)}if(r.strokeStyle=a,r.lineWidth=1,r.setLineDash([]),r.beginPath(),r.arc(E,D,T,0,Math.PI*2),r.stroke(),r.save(),r.beginPath(),r.arc(E,D,T,0,Math.PI*2),r.clip(),u===`waveform`)if(v)(b.current.geo!==f||b.current.color!==l)&&(v.setLine(`wave`,f.x,f.y,M1(l,.9),1),b.current={geo:f,color:l}),v.keep([`wave`]),v.setView(-1,1,-1,1,{left:E-T,top:D-T,width:T*2,height:T*2}),v.render();else{r.strokeStyle=l,r.lineWidth=1,r.globalAlpha=.9,r.beginPath();let e=!1;for(let t=0;t<p;t++){let n=E+f.x[t]*T,i=D-f.y[t]*T;if(n!==n){e=!1;continue}e?r.lineTo(n,i):(r.moveTo(n,i),e=!0)}r.stroke(),r.globalAlpha=1}else{v?.keep([]),v?.render();let e=f.means,t=Math.max(...e,1e-10),n=2*Math.PI/x0;r.fillStyle=l,r.globalAlpha=.75;for(let i=0;i<x0;i++){let a=e[i]/t*T,o=i*n-Math.PI/2-n/2;r.beginPath(),r.moveTo(E,D),r.arc(E,D,a,o,o+n),r.closePath(),r.fill()}r.globalAlpha=1,r.strokeStyle=l,r.lineWidth=.5,r.globalAlpha=.4;for(let i=0;i<x0;i++){let a=e[i]/t*T,o=i*n-Math.PI/2-n/2;r.beginPath(),r.moveTo(E,D),r.arc(E,D,a,o,o+n),r.closePath(),r.stroke()}r.globalAlpha=1}r.restore(),r.fillStyle=a,r.font=`11px ${X.mono}`,r.textAlign=`center`,r.textBaseline=`bottom`,r.fillText(`${s} / ${c}`,E,n-4)}let T=(0,Z.useRef)(w);T.current=w;let E=(0,Z.useRef)(null);E.current??=KX(()=>T.current(),()=>f.current);let D=()=>E.current.schedule();return(0,Z.useEffect)(()=>{E.current.now()}),(0,Z.useEffect)(()=>()=>E.current?.cancel(),[]),(0,Z.useEffect)(()=>{p.current=null,D()},[l]),(0,Z.useLayoutEffect)(()=>{let e=f.current;if(!e)return;let t=new WX(()=>{p.current=null,D()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{let e=d.current;if(!e)return;let t=e=>{e.preventDefault(),m.current?.({clientX:e.clientX,clientY:e.clientY})};return e.addEventListener(`contextmenu`,t),()=>e.removeEventListener(`contextmenu`,t)},[]),(0,Q.jsxs)(`div`,{ref:f,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:d,className:`chart-canvas`,role:`img`,"aria-label":`Polar chart: ${n} vs ${r}`}),(0,Q.jsx)(`canvas`,{ref:v,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}})]})}function w0(e,t,n,r,i){let a=Math.min(e.length,t.length),o=(t,n)=>{let r=0,i=a;for(;r<i;){let a=r+i>>>1;(n?e[a]<=t:e[a]<t)?r=a+1:i=a}return r},s=o(n,!1),c=o(r,!0),l=Math.max(0,s-1),u=Math.min(a,c+1);if(u-l<=2*i){let e=new Uint32Array(u-l);for(let t=0;t<e.length;t++)e[t]=l+t;return e}let d=new Uint32Array(2*i+2),f=0;s>0&&(d[f++]=s-1);let p=(r-n)/i,m=s;for(let r=0;r<i&&m<c;r++){let a=r===i-1?1/0:n+(r+1)*p,o=1/0,s=-1/0,l=-1,u=-1;for(;m<c&&e[m]<a;m++){let e=t[m];e<o&&(o=e,l=m),e>s&&(s=e,u=m)}l<0||(l===u?d[f++]=l:l<u?(d[f++]=l,d[f++]=u):(d[f++]=u,d[f++]=l))}return c<a&&(d[f++]=c),d.subarray(0,f)}function T0(e,t){let n=e.length;if(n<=2*t)return Uint32Array.from({length:n},(e,t)=>t);let r=new Uint32Array(2*t),i=0;for(let a=0;a<t;a++){let o=Math.floor(a*n/t),s=Math.floor((a+1)*n/t),c=1/0,l=-1/0,u=-1,d=-1;for(let t=o;t<s;t++){let n=e[t];n<c&&(c=n,u=t),n>l&&(l=n,d=t)}u<0||(u===d?r[i++]=u:u<d?(r[i++]=u,r[i++]=d):(r[i++]=d,r[i++]=u))}return r.subarray(0,i)}function E0(e,t){let n=new Float64Array(t.length);for(let r=0;r<t.length;r++)n[r]=e[t[r]];return n}function D0(e){for(let t=1;t<e.length;t++)if(!(e[t]>=e[t-1]))return!1;return e.length===0||e[0]===e[0]}function O0(e,t){let n=e.length;for(let r=1,i=0;r<n;r++){let a=n>>1;for(;i&a;a>>=1)i^=a;if(i^=a,r<i){let n=e[r];e[r]=e[i],e[i]=n,n=t[r],t[r]=t[i],t[i]=n}}for(let r=2;r<=n;r<<=1){let i=r>>1,a=-2*Math.PI/r,o=Math.cos(a),s=Math.sin(a);for(let a=0;a<n;a+=r){let n=1,r=0;for(let c=0;c<i;c++){let l=a+c,u=l+i,d=e[u]*n-t[u]*r,f=e[u]*r+t[u]*n;e[u]=e[l]-d,t[u]=t[l]-f,e[l]+=d,t[l]+=f;let p=n*o-r*s;r=n*s+r*o,n=p}}}}var k0=new Float64Array,A0=new Float64Array;function j0(e,t,n){let r=t>>1;k0.length<r&&(k0=new Float64Array(r),A0=new Float64Array(r));let i=k0.subarray(0,r),a=A0.subarray(0,r),o=e.length;for(let t=0;t<r;t++){let r=2*t,s=r+1;i[t]=r<o?e[r]*(n?n[r]:1):0,a[t]=s<o?e[s]*(n?n[s]:1):0}O0(i,a);let s=new Float64Array(r),c=-2*Math.PI/t,l=Math.cos(c),u=Math.sin(c),d=1,f=0;for(let e=0;e<r;e++){let t=e===0?0:r-e,n=i[e],o=a[e],c=i[t],p=-a[t],m=(n+c)/2,h=(o+p)/2,g=(o-p)/2,_=-(n-c)/2,v=m+d*g-f*_,y=h+d*_+f*g;s[e]=Math.sqrt(v*v+y*y);let b=d*l-f*u;f=d*u+f*l,d=b}return s}var M0=new Float64Array,N0=0;function P0(e){if(N0===e)return M0.subarray(0,e);M0.length<e&&(M0=new Float64Array(Math.max(e,M0.length*2)));let t=2*Math.PI/Math.max(1,e-1),n=Math.cos(t),r=Math.sin(t),i=1,a=0;for(let t=0;t<e;t++){M0[t]=.5*(1-i);let e=i*n-a*r;a=a*n+i*r,i=e}return N0=e,M0.subarray(0,e)}var F0={top:14,right:24,bottom:40,left:64},I0=5;function L0(e){let t=1;for(;t<e;)t<<=1;return t}function R0(e,t,n,r){let i=e.length,a=Math.max(2,L0(i)),o=j0(e,a,n===`hann`?P0(i):void 0),s=a/2,c=new Float64Array(s),l=2/a;for(let e=0;e<s;e++){c[e]=e*t/a;let n=o[e]*l;o[e]=r===`db`?20*Math.log10(Math.max(n,1e-12)):n}return{freqs:c,amps:o}}function z0({signal:e,sampleRate:t=1,label:n,xMode:r=`hz`,yMode:i=`amplitude`,window:a=`hann`,color:o=`#34d399`,logX:s=!1,height:c=400,backgroundToken:l=``,onPlotContextMenu:u}){let d=IZ(),f=(0,Z.useRef)(null),p=(0,Z.useRef)(null),m=(0,Z.useRef)(null),h=(0,Z.useRef)(u);(0,Z.useLayoutEffect)(()=>{h.current=u},[u]);let g=(0,Z.useRef)({signal:e,sampleRate:t,label:n,xMode:r,yMode:i,window:a,color:o,logX:s,height:c});(0,Z.useLayoutEffect)(()=>{g.current={signal:e,sampleRate:t,label:n,xMode:r,yMode:i,window:a,color:o,logX:s,height:c}},[e,t,n,r,i,a,o,s,c]);let _=(0,Z.useMemo)(()=>e.length>=4?R0(e,t,a,i):null,[e,t,a,i]),v=(0,Z.useMemo)(()=>_&&s?_.freqs.map(e=>Math.log10(e)):null,[_,s]),y=(0,Z.useRef)(_&&{..._,logFreqs:v});(0,Z.useLayoutEffect)(()=>{y.current=_&&{..._,logFreqs:v}},[_,v]);function b(){if(m.current)return m.current;let e=p.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return m.current=n,n}function x(){let e=p.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||g.current.height)}}function S(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function C(){let e=f.current;if(!e)return;let{w:t,h:n}=x(),r=S(e,t,n);if(!r)return;let{top:i,right:a,bottom:o,left:s}=F0,c=t-s-a,l=n-i-o,{bg:u,muted:p,grid:m}=b(),{sampleRate:h,label:_,xMode:v,yMode:C,color:w,logX:T}=g.current,E=y.current;if(r.fillStyle=u,r.fillRect(0,0,t,n),!E||c<=0||l<=0){r.fillStyle=p,r.font=`13px ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,MY(r);return}let{freqs:D,amps:O,logFreqs:k}=E,A=D.length,j=v===`hz`?`${_} (Hz)`:`${_} (order)`,M=v===`order`&&h>0?h:1,N=D[1]/M,P=D[A-1]/M,F=1/0,I=-1/0;for(let e=1;e<A;e++)O[e]<F&&(F=O[e]),O[e]>I&&(I=O[e]);if(!Number.isFinite(F)||!Number.isFinite(I)){r.fillStyle=p,r.font=`13px ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,MY(r);return}let L=(I-F)*.05||.1;F-=L,I+=L;let R=T?e=>{if(e<=0||N<=0)return s;let t=Math.log10(N),n=Math.log10(P);return s+(Math.log10(e)-t)/(n-t)*c}:e=>s+(e-N)/(P-N)*c;T&&N<=0&&(N=D[1]>0?D[1]/M:.001),d({left:s,top:i,width:c,height:l,x:{v0:N,v1:P,log:T},y:{v0:F,v1:I}});let z=e=>i+(I-e)/(I-F)*l,B=uJ(I-F,5),V=pJ(F,I,B);r.strokeStyle=m,r.lineWidth=1,r.setLineDash([3,3]);for(let e of V)r.beginPath(),r.moveTo(s,z(e)),r.lineTo(s+c,z(e)),r.stroke();r.setLineDash([]);let ee=T?1:uJ(P-N,dJ(c)),H=T?(()=>{let e=[],t=Math.ceil(Math.log10(Math.max(N,1e-12))),n=Math.floor(Math.log10(P));for(let r=t;r<=n;r++)for(let t of[1,2,5]){let n=t*10**r;n>=N&&n<=P&&e.push(n)}return e})():pJ(N,P,ee);r.strokeStyle=m,r.lineWidth=1,r.setLineDash([3,3]);for(let e of H)r.beginPath(),r.moveTo(R(e),i),r.lineTo(R(e),i+l),r.stroke();r.setLineDash([]),r.strokeStyle=p,r.lineWidth=1,r.fillStyle=p,r.font=`11px ${X.mono}`,r.textAlign=`right`,r.textBaseline=`middle`;for(let e of V)r.beginPath(),r.moveTo(s-I0,z(e)),r.lineTo(s,z(e)),r.stroke(),r.fillText(_J(e,B),s-4,z(e));r.textAlign=`center`,r.textBaseline=`top`;for(let e of H)r.beginPath(),r.moveTo(R(e),i+l),r.lineTo(R(e),i+l+I0),r.stroke(),r.fillText(_J(e,T?e:ee),R(e),i+l+I0+2);r.strokeStyle=m,r.lineWidth=1,r.strokeRect(s,i,c,l),r.save(),r.beginPath(),r.rect(s,i,c,l),r.clip(),r.strokeStyle=w,r.lineWidth=1,r.beginPath();let U=!1,te=Math.min(2,window.devicePixelRatio||1),W=Math.max(1,Math.round(c*te)),ne=A>W*4?T&&k?w0(k,O,Math.log10(N*M),Math.log10(P*M),W):w0(D,O,N*M,P*M,W):null;for(let e=+!ne;e<(ne?ne.length:A);e++){let t=ne?ne[e]:e;if(t<1)continue;let n=D[t]/M;if(n<N||n>P)continue;let i=R(n),a=z(O[t]);U?r.lineTo(i,a):(r.moveTo(i,a),U=!0)}r.stroke(),r.restore(),r.fillStyle=p,r.font=`11px ${X.mono}`,r.save(),r.translate(14,i+l/2),r.rotate(-Math.PI/2),r.textAlign=`center`,r.textBaseline=`middle`,r.fillText(C===`db`?`dB`:`Amplitude`,0,0),r.restore(),r.textAlign=`center`,r.textBaseline=`bottom`,r.fillText(j,s+c/2,n-4)}let w=(0,Z.useRef)(C);w.current=C;let T=(0,Z.useRef)(null);T.current??=KX(()=>w.current(),()=>p.current);let E=()=>T.current.schedule();return(0,Z.useEffect)(()=>{T.current.now()}),(0,Z.useEffect)(()=>()=>T.current?.cancel(),[]),(0,Z.useEffect)(()=>{m.current=null,E()},[l]),(0,Z.useLayoutEffect)(()=>{let e=p.current;if(!e)return;let t=new WX(()=>{m.current=null,E()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{let e=f.current;if(!e)return;let t=e=>{e.preventDefault(),h.current?.({clientX:e.clientX,clientY:e.clientY})};return e.addEventListener(`contextmenu`,t),()=>e.removeEventListener(`contextmenu`,t)},[]),(0,Q.jsx)(`div`,{ref:p,style:{position:`relative`,width:`100%`,height:`100%`},children:(0,Q.jsx)(`canvas`,{ref:f,className:`chart-canvas`,role:`img`,"aria-label":`Spectrum of ${n}`})})}function B0(e,t,n=0,r=e.length-1){for(;r>n;){let i=n+r>>>1,a=e[n],o=e[i],s=e[r];if(a>o){let e=a;a=o,o=e}o>s&&(o=s),a>o&&(o=a);let c=o,l=n,u=r;for(;l<=u;){for(;e[l]<c;)l++;for(;e[u]>c;)u--;if(l<=u){let t=e[l];e[l]=e[u],e[u]=t,l++,u--}}if(t<=u)r=u;else if(t>=l)n=l;else break}return e[t]}function V0(e,t){let n=e.length;if(n===0)return t.map(()=>0);let r=[...new Set(t.flatMap(e=>{let t=e/100*(n-1);return[Math.floor(t),Math.ceil(t)]}))].sort((e,t)=>e-t),i=new Map,a=0;for(let t of r)i.set(t,B0(e,t,a)),a=t;return t.map(e=>{let t=e/100*(n-1),r=Math.floor(t);return i.get(r)+(i.get(Math.ceil(t))-i.get(r))*(t-r)})}var H0={top:14,right:24,bottom:48,left:64},U0=5;function W0(e,t){let n=e.length;if(n===0)return null;let[r,i,a,o,s]=V0(Float64Array.from(e),[0,25,50,75,100]),c=0;for(let t=0;t<n;t++)c+=e[t];let l=c/n;if(t!==`1.5iqr`)return{q1:i,median:a,q3:o,mean:l,whiskerLo:r,whiskerHi:s,outliers:new Float64Array};let u=o-i,d=i-1.5*u,f=o+1.5*u,p=1/0,m=-1/0,h=0;for(let t=0;t<n;t++){let n=e[t];if(n<d||n>f){h++;continue}n<p&&(p=n),n>m&&(m=n)}let g=new Float64Array(h);for(let t=0,r=0;t<n;t++){let n=e[t];(n<d||n>f)&&(g[r++]=n)}return g.sort(),{q1:i,median:a,q3:o,mean:l,whiskerLo:p<=m?p:i,whiskerHi:p<=m?m:o,outliers:g}}function G0({groups:e,color:t=`#fb923c`,whiskers:n=`1.5iqr`,height:r=400,backgroundToken:i=``,onPlotContextMenu:a}){let o=IZ(),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(null),u=(0,Z.useRef)(a);(0,Z.useLayoutEffect)(()=>{u.current=a},[a]);let d=(0,Z.useRef)({groups:e,color:t,whiskers:n,height:r});(0,Z.useLayoutEffect)(()=>{d.current={groups:e,color:t,whiskers:n,height:r}},[e,t,n,r]);let f=(0,Z.useMemo)(()=>e.filter(e=>e.values.length>0).map(e=>({label:e.label,box:W0(e.values,n)})),[e,n]),p=(0,Z.useRef)(f);(0,Z.useLayoutEffect)(()=>{p.current=f},[f]);function m(){if(l.current)return l.current;let e=c.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return l.current=n,n}function h(){let e=c.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||d.current.height)}}function g(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function _(){let e=s.current;if(!e)return;let{w:t,h:n}=h(),r=g(e,t,n);if(!r)return;let{top:i,right:a,bottom:c,left:l}=H0,u=t-l-a,f=n-i-c,{bg:_,muted:v,grid:y}=m(),{color:b}=d.current;r.fillStyle=_,r.fillRect(0,0,t,n);let x=p.current;if(x.length===0||u<=0||f<=0){r.fillStyle=v,r.font=`13px ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,MY(r);return}let S=1/0,C=-1/0;for(let e of x){e.box.whiskerLo<S&&(S=e.box.whiskerLo),e.box.whiskerHi>C&&(C=e.box.whiskerHi);for(let t of e.box.outliers)t<S&&(S=t),t>C&&(C=t)}let w=(C-S)*.08||1;S-=w,C+=w;let T=e=>i+(C-e)/(C-S)*f;o({left:l,top:i,width:u,height:f,y:{v0:S,v1:C}});let E=uJ(C-S,5),D=pJ(S,C,E);r.strokeStyle=y,r.lineWidth=1,r.setLineDash([3,3]);for(let e of D)r.beginPath(),r.moveTo(l,T(e)),r.lineTo(l+u,T(e)),r.stroke();r.setLineDash([]),r.strokeStyle=v,r.lineWidth=1,r.fillStyle=v,r.font=`11px ${X.mono}`,r.textAlign=`right`,r.textBaseline=`middle`;for(let e of D)r.beginPath(),r.moveTo(l-U0,T(e)),r.lineTo(l,T(e)),r.stroke(),r.fillText(_J(e,E),l-4,T(e));r.strokeStyle=y,r.lineWidth=1,r.strokeRect(l,i,u,f),r.save(),r.beginPath(),r.rect(l,i,u,f),r.clip();let O=x.length,k=u/O,A=Math.min(k*.55,60);for(let e=0;e<O;e++){let{box:t}=x[e],n=l+k*e+k/2;r.strokeStyle=b,r.lineWidth=1.5,r.beginPath(),r.moveTo(n,T(t.whiskerLo)),r.lineTo(n,T(t.whiskerHi)),r.stroke();let i=A*.35;r.beginPath(),r.moveTo(n-i,T(t.whiskerLo)),r.lineTo(n+i,T(t.whiskerLo)),r.moveTo(n-i,T(t.whiskerHi)),r.lineTo(n+i,T(t.whiskerHi)),r.stroke();let a=n-A/2,o=T(t.q3),s=Math.max(1,T(t.q1)-o);r.fillStyle=b,r.globalAlpha=.25,r.fillRect(a,o,A,s),r.globalAlpha=1,r.strokeStyle=b,r.lineWidth=1.5,r.strokeRect(a,o,A,s),r.strokeStyle=b,r.lineWidth=2.5,r.beginPath(),r.moveTo(a,T(t.median)),r.lineTo(a+A,T(t.median)),r.stroke();let c=T(t.mean);r.fillStyle=b,r.beginPath(),r.moveTo(n,c-5),r.lineTo(n+5,c),r.lineTo(n,c+5),r.lineTo(n-5,c),r.closePath(),r.fill(),r.fillStyle=b,r.globalAlpha=.6;let u=NaN;for(let e of t.outliers){let t=T(e);Math.abs(t-u)<.5||(u=t,r.beginPath(),r.arc(n,t,2.5,0,Math.PI*2),r.fill())}r.globalAlpha=1}r.restore(),r.fillStyle=v,r.font=`11px ${X.mono}`,r.textAlign=`center`,r.textBaseline=`top`;for(let e=0;e<O;e++){let t=l+k*e+k/2,n=x[e].label;r.save(),r.rect(l+k*e+2,i+f+U0+2,k-4,c-U0-4),r.clip(),r.fillText(n,t,i+f+U0+2),r.restore()}}let v=(0,Z.useRef)(_);v.current=_;let y=(0,Z.useRef)(null);y.current??=KX(()=>v.current(),()=>c.current);let b=()=>y.current.schedule();return(0,Z.useEffect)(()=>{y.current.now()}),(0,Z.useEffect)(()=>()=>y.current?.cancel(),[]),(0,Z.useEffect)(()=>{l.current=null,b()},[i]),(0,Z.useLayoutEffect)(()=>{let e=c.current;if(!e)return;let t=new WX(()=>{l.current=null,b()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{let e=s.current;if(!e)return;let t=e=>{e.preventDefault(),u.current?.({clientX:e.clientX,clientY:e.clientY})};return e.addEventListener(`contextmenu`,t),()=>e.removeEventListener(`contextmenu`,t)},[]),(0,Q.jsx)(`div`,{ref:c,style:{position:`relative`,width:`100%`,height:`100%`},children:(0,Q.jsx)(`canvas`,{ref:s,className:`chart-canvas`,role:`img`,"aria-label":`Box plot`})})}function K0(e,t){if(e.w<=t)return{grid:e,per:1};let n=e.w/t,r=new Float32Array(t*e.h);for(let i=0;i<e.h;i++){let a=i*e.w;for(let o=0;o<t;o++){let s=Math.floor(o*n),c=Math.min(e.w,Math.floor((o+1)*n)),l=0,u=0;for(let t=s;t<c;t++){let n=e.values[a+t];n===n&&(l+=n,u++)}r[i*t+o]=u?l/u:NaN}}let i=e.xLabels;return{grid:{w:t,h:e.h,values:r,xLabels:e=>typeof i==`function`?i(Math.floor(e*n)):i[Math.floor(e*n)],yLabels:e.yLabels},per:n}}function q0(e){let t=[];for(let n of e.split(`,`)){let e=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(n.trim());if(!e)return null;let r=e[1].length===3?e[1].replace(/./g,`$&$&`):e[1];t.push([parseInt(r.slice(0,2),16),parseInt(r.slice(2,4),16),parseInt(r.slice(4,6),16)])}return t.length>=2?t:null}var J0=e=>e.includes(`.`)&&!e.includes(`e`)?e.replace(/\.?0+$/,``):e;function Y0(e){return e>=1e3?`${J0((e/1e3).toPrecision(3))}k`:J0(e.toPrecision(3))}function X0(e,t){let n=e>>1,r=new Float64Array(e);for(let n=0;n<e;n++)r[n]=t?.5*(1-Math.cos(2*Math.PI*n/(e-1))):1;let i=Math.log2(e),a=new Uint32Array(e);for(let t=0;t<e;t++){let e=0,n=t;for(let t=0;t<i;t++)e=e<<1|n&1,n>>=1;a[t]=e}let o=new Float64Array(e),s=new Float64Array(e);return(t,i,c)=>{for(let n=0;n<e;n++){let e=a[n];o[n]=t[i+e]*r[e],s[n]=0}for(let t=2;t<=e;t<<=1){let n=t>>1,r=-2*Math.PI/t,i=Math.cos(r),a=Math.sin(r);for(let r=0;r<e;r+=t){let e=1,t=0;for(let c=0;c<n;c++){let l=r+c,u=l+n,d=o[u]*e-s[u]*t,f=o[u]*t+s[u]*e;o[u]=o[l]-d,s[u]=s[l]-f,o[l]+=d,s[l]+=f;let p=e*i-t*a;t=e*a+t*i,e=p}}}let l=0;for(let t=0;t<n;t++){let n=Math.sqrt(o[t]*o[t]+s[t]*s[t])/e;c[t]=n,n>l&&(l=n)}return l}}function Z0(e,t,n,r,i,a,o){let s=t>>1,c=e.length,l=c>=t?Math.floor((c-t)/n)+1:0,u=`${t}|${n}|${r}|${i}|${a?a.join(`,`):``}`,d=-1,f=0;if(o&&o.key===u&&o.frames>0&&c>0){let r=o.sig;for(let i=0;i*n<r.length&&f===0;i++){let a=i*n;if(r[a]!==e[0])continue;let s=Math.min(r.length-a,c),u=!0;for(let t=0;t<s;t++)if(r[a+t]!==e[t]){u=!1;break}if(!u)continue;let p=s>=t?Math.floor((s-t)/n)+1:0;d=i,f=Math.max(0,Math.min(p,o.frames-i,l))}}let p=new Float32Array(l*s),m=new Float32Array(l);if(f>0){for(let e=0;e<s;e++)p.set(o.values.subarray(e*o.frames+d,e*o.frames+d+f),e*l);m.set(o.frameMax.subarray(d,d+f))}let h=X0(t,r),g=new Float64Array(s);for(let t=f;t<l;t++){m[t]=h(e,t*n,g);for(let e=0;e<s;e++){let n=g[a?a[e]:e];p[e*l+t]=i?20*Math.log10(Math.max(n,1e-12)):n}}let _=1e-10;for(let e=0;e<l;e++)m[e]>_&&(_=m[e]);return{values:p,frames:l,bins:s,max:_,computed:l-f,sig:Float64Array.from(e),frameMax:m,key:u}}function Q0(e,t,n,r,i,a){let o=e>>1,s=new Float32Array(o*n).fill(NaN),c=new Float32Array(n),l=X0(e,r),u=new Float64Array(o),d={values:s,cap:n,bins:o,end:-1,count:0,max:1e-10,computed:0,update(r,f){let p=r.length,m=p>=e?Math.floor((f+p-e)/t)+1:0,h=Math.ceil(f/t);if(d.computed=0,m===d.end)return!1;let g=m-d.end,_=d.end;if(d.end<0||g<0||g>=n||h>d.end)s.fill(NaN),d.count=0,_=Math.max(h,m-n);else{for(let e=0;e<o;e++)s.copyWithin(e*n,e*n+g,(e+1)*n);c.copyWithin(0,g),d.count=Math.min(d.count,n-g)}if(d.end=Math.max(m,0),m<=_)return d.count>0||g<0;for(let e=_;e<m;e++){let d=n-(m-e);c[d]=l(r,e*t-f,u);for(let e=0;e<o;e++){let t=u[a?a[e]:e];s[e*n+d]=i?20*Math.log10(Math.max(t,1e-12)):t}}d.computed=m-_,d.count=Math.min(n,d.count+d.computed);let v=1e-10;for(let e=n-d.count;e<n;e++)c[e]>v&&(v=c[e]);return d.max=v,!0}};return d}var $0=1024,e2=1,t2=1e3/120,n2={top:14,right:24,bottom:40,left:68},r2=[[8,0,16],[48,0,96],[104,0,144],[160,0,128],[200,32,64],[230,100,16],[250,200,32],[255,255,220]],i2=-80;function a2(e,t=r2){let n=t.length-1,r=Math.min(n-1,Math.floor(e*n)),i=e*n-r,[a,o,s]=t[r],[c,l,u]=t[r+1];return[a+(c-a)*i,o+(l-o)*i,s+(u-s)*i]}function o2(e){let t=new Uint8Array(256*4);for(let n=0;n<256;n++){let[r,i,a]=a2(n/255,e);t.set([r,i,a,255],n*4)}return t}var s2=o2(r2);function c2(e){let t=1;for(;t<e;)t<<=1;return t}var l2=(e,t)=>Math.log(1+e/t*9)/Math.log(10),u2=(e,t)=>t*(10**e-1)/9,d2=new Float64Array;function f2({signal:e,sampleRate:t=1e3,windowSize:n=512,overlap:r=.5,winFunc:i=`hann`,yMode:a=`db`,logFreq:o=!1,label:s=``,backgroundToken:c=``,onPlotContextMenu:l,live:u}){let d=IZ(),f=(0,Z.useRef)(null),p=(0,Z.useRef)(null),m=(0,Z.useRef)(null),h=(0,Z.useRef)(null),g=(0,Z.useRef)(null),_=(0,Z.useRef)(l);(0,Z.useLayoutEffect)(()=>{_.current=l},[l]);let v=c2(Math.max(4,Math.min(n,4096))),y=Math.max(1,Math.round(v*(1-Math.max(0,Math.min(.95,r))))),b=(0,Z.useMemo)(()=>{if(!o)return null;let e=v>>1,n=t/2;return Int32Array.from({length:e},(t,r)=>Math.min(e-1,Math.floor(u2((r+.5)/e,n)/n*e)))},[o,v,t]),x=(0,Z.useRef)(null),S=u?d2:e,C=(0,Z.useMemo)(()=>x.current=Z0(S,v,y,i===`hann`,a===`db`,b,x.current),[S,v,y,i,a,b]),w=(0,Z.useMemo)(()=>({w:C.frames,h:C.bins,values:C.values,xLabels:[],yLabels:[]}),[C]),T=a===`db`?20*Math.log10(C.max):C.max,E=a===`db`?[T+i2,T]:[0,T],D=(0,Z.useRef)({grid:w,range:E,sampleRate:t,winSz:v,step:y,winFunc:i,yMode:a,logFreq:o,rowBin:b,label:s,live:u});(0,Z.useLayoutEffect)(()=>{D.current={grid:w,range:E,sampleRate:t,winSz:v,step:y,winFunc:i,yMode:a,logFreq:o,rowBin:b,label:s,live:u}},[w,E[0],E[1],t,v,y,i,a,o,b,s,u]);let O=(0,Z.useRef)({plot:null,failed:!1,size:``,grid:null,shown:null,palette:null});(0,Z.useEffect)(()=>()=>{O.current.plot?.dispose(),O.current.plot=null},[]);let k=(0,Z.useRef)({canvas:null,grid:null,lo:0,hi:0,palette:null}),A=(0,Z.useRef)({roll:null,cfg:null,version:NaN,grid:null,playout:uZ(),last:0,x1:NaN,axes:``}),j=(0,Z.useRef)(!0);function M(){if(g.current)return g.current;let e=h.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`,palette:s2};let t=getComputedStyle(e),n=q0(t.getPropertyValue(`--chart-spectrogram`)),r={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`,palette:n?o2(n):s2};return g.current=r,r}function N(){let e=h.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function P(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function F(e,t){let n=O.current;if(!n.plot&&!n.failed&&p.current&&(n.plot=dX(p.current,v0),n.failed=!n.plot),!n.plot||!p.current)return null;let r=Math.min(2,window.devicePixelRatio||1),i=`${e}x${t}@${r}`;return n.size!==i&&(n.plot.resize(e,t,r),p.current.style.width=`${e}px`,p.current.style.height=`${t}px`,n.size=i),n.plot}function I(e,t){let n=A.current,{sampleRate:r,winSz:i,step:a,winFunc:o,yMode:s,rowBin:c}=D.current,l=e.samples();if(!l)return null;let u=e.windowSeconds!=null&&e.windowSeconds>0?e.windowSeconds:null,d=u==null?l.values.length:(u+e2)*r,f=a;for(;d/f>$0;)f*=2;let p=u==null?$0:Math.max(2,Math.ceil(d/f)),m=n.cfg;(!n.roll||!m||m.winSz!==i||m.hop!==f||m.cap!==p||m.winFunc!==o||m.yMode!==s||m.rowBin!==c)&&(n.roll=Q0(i,f,p,o===`hann`,s===`db`,c),n.cfg={winSz:i,hop:f,cap:p,winFunc:o,yMode:s,rowBin:c},n.version=NaN,n.grid=null);let h=n.roll,g=e.version(),_=!1;g!==n.version&&(n.version=g,(h.update(l.values,l.first)||!n.grid)&&(n.grid={w:p,h:h.bins,values:h.values,xLabels:[],yLabels:[]},_=!0));let v=e.latestT(),y=p,b=NaN;if(Number.isFinite(v)){let a=e.id?fZ(e.id,v,t,e.timeAfter):EZ(n.playout,v,n.last?t-n.last:16,e.timeAfter),o=e.id?_Z(e.id):mZ(n.playout),s=e.id?gZ(e.id):hZ(n.playout),c=l.first+l.values.length-1-(v-(a+o-2*s))*r;y=Math.min(p,(c-i)/f-(h.end-p)),b=v-(l.first+l.values.length-1-((y+h.end-p)*f+i))/r}let x=u==null?p-h.count:y-u*r/f,S=s===`db`?20*Math.log10(h.max):h.max,C=_||y!==n.x1;return n.x1=y,{grid:h.count>0?n.grid:null,lo:s===`db`?S+i2:0,hi:S,x0:x,x1:y,hop:f,moved:C,tEnd:b}}function L(){let e=f.current;if(!e)return;let{w:t,h:n}=N(),r=A.current,i=D.current.live,a=null;if(i){j.current&&z.current.schedule();let e=performance.now();if(r.last&&e-r.last<t2-2)return;a=I(i,e),r.last=e}let o=j$(n2,t,n),{top:s,right:c,bottom:l,left:u}=o,p=t-u-c,g=n-s-l,_=M(),{bg:v,muted:y,grid:b}=_,{sampleRate:x,winSz:S,step:C,logFreq:w,label:T}=D.current,E=i?a?.grid??{w:0,h:0,values:new Float32Array,xLabels:[],yLabels:[]}:D.current.grid,[L,R]=a?[a.lo,a.hi]:D.current.range,B=F(t,n),V=a?(a.x1-a.x0)*a.hop/x:(E.w*C+S)/x,ee=a&&Number.isFinite(a.tEnd)?a.tEnd:V,H=ee-V,U=a?`${t}|${n}|${V.toPrecision(3)}|${ee}|${x}|${w}|${T}|${v}|${y}|${b}`:``,te=!!a&&!!B&&E.w>0&&r.axes===U;r.axes=``;let W=te?null:P(e,t,n);if(!te&&!W)return;let ne=!te&&m.current?P(m.current,t,n):null;if(ne?.clearRect(0,0,t,n),W&&(W.fillStyle=v,W.fillRect(0,0,t,n)),E.w===0||p<=0||g<=0){if(B?.keep([]),B?.render(),o.tiny||!W)return;W.fillStyle=y,W.font=`13px ${X.sans}`,W.textAlign=`left`,W.textBaseline=`top`,MY(W);return}let G=Math.min(2,window.devicePixelRatio||1),re=B?B.maxTextureSize:Math.max(1,Math.round(p*G));if(O.current.grid!==E||!O.current.shown||O.current.palette!==_.palette||!B&&!a&&O.current.shown.w>re){let e=a?E:K0(E,re).grid;B&&B.setGrid(`cells`,e.values,e.w,Math.min(e.h,B.maxTextureSize),[0,e.w,0,e.h],_.palette,L,R),O.current.grid=E,O.current.shown=e,O.current.palette=_.palette,a||VX(h.current)}a?.moved&&VX(h.current);let ie=O.current.shown,ae=a?a.x0:0,oe=a?a.x1:ie.w;if(B)B.keep([`cells`]),B.setGridRange(`cells`,L,R),B.setView(ae,oe,0,ie.h,{left:u,top:s,width:p,height:g}),B.render();else if(W){let e=k.current;if(e.grid!==ie||e.lo!==L||e.hi!==R||e.palette!==_.palette||!e.canvas){let t=e.canvas??document.createElement(`canvas`);t.width=ie.w,t.height=ie.h;let n=t.getContext(`2d`),r=n.createImageData(ie.w,ie.h),i=_.palette;for(let e=0;e<ie.h;e++)for(let t=0;t<ie.w;t++){let n=ie.values[e*ie.w+t];if(n!==n)continue;let a=Math.round(Math.max(0,Math.min(1,(n-L)/(R-L)))*255)*4,o=(t+(ie.h-1-e)*ie.w)*4;r.data[o]=i[a],r.data[o+1]=i[a+1],r.data[o+2]=i[a+2],r.data[o+3]=255}n.putImageData(r,0,0),k.current={canvas:t,grid:ie,lo:L,hi:R,palette:_.palette}}W.save(),W.beginPath(),W.rect(u,s,p,g),W.clip();let t=p/(oe-ae);W.drawImage(k.current.canvas,u-ae*t,s,ie.w*t,g),W.restore()}if(a&&(r.axes=U),o.tiny||!W)return;let se=ne??W,ce=x/2,le=e=>s+g*(1-(w?l2(e,ce):e/ce));se.strokeStyle=b,se.lineWidth=.5,se.globalAlpha=.4;let ue=pJ(0,ce,uJ(ce,5));se.setLineDash([3,4]);for(let e of ue){let t=le(e);se.beginPath(),se.moveTo(u,t),se.lineTo(u+p,t),se.stroke()}se.setLineDash([]),se.globalAlpha=1,se.strokeStyle=b,se.strokeRect(u,s,p,g),W.fillStyle=y,W.font=`10px ${X.mono}`,W.textAlign=`right`,W.textBaseline=`middle`,W.strokeStyle=y,W.lineWidth=1;for(let e of ue){let t=le(e);W.beginPath(),W.moveTo(u-4,t),W.lineTo(u,t),W.stroke(),W.fillText(Y0(e),u-6,t)}d({left:u,top:s,width:p,height:g,x:{v0:H,v1:ee}});let de=uJ(V,6),fe=pJ(H,ee,de);W.textAlign=`center`,W.textBaseline=`top`;for(let e of fe){let t=u+(e-H)/V*p;t<u-.5||t>u+p+.5||(W.beginPath(),W.moveTo(t,s+g),W.lineTo(t,s+g+4),W.stroke(),W.fillText(_J(e,de),t,s+g+6))}W.fillStyle=y,W.textAlign=`center`,W.textBaseline=`bottom`,W.fillText(T||`Time (s)`,u+p/2,n-4),W.save(),W.translate(12,s+g/2),W.rotate(-Math.PI/2),W.textAlign=`center`,W.fillText(`Frequency (Hz)`,0,0),W.restore()}let R=(0,Z.useRef)(L);(0,Z.useLayoutEffect)(()=>{R.current=L});let z=(0,Z.useRef)(null);z.current??=KX(()=>R.current(),()=>h.current);let B=!!u;return(0,Z.useEffect)(()=>{A.current.axes=``,z.current.now()},[w,E[0],E[1],t,v,y,a,o,s,B]),(0,Z.useEffect)(()=>()=>z.current?.cancel(),[]),(0,Z.useEffect)(()=>{g.current=null,z.current.schedule()},[c]),(0,Z.useLayoutEffect)(()=>{let e=h.current;if(!e)return;let t=new WX(()=>{g.current=null,z.current.schedule()});return t.observe(e),()=>t.disconnect()},[]),(0,Z.useEffect)(()=>{let e=h.current,t=e?.ownerDocument.defaultView?.IntersectionObserver;if(!e||!t)return;let n=new t(e=>{let t=e[e.length-1];(t.isIntersecting||t.boundingClientRect.width>0)&&(j.current=t.isIntersecting),j.current&&D.current.live&&z.current?.schedule()});return n.observe(e),()=>{n.disconnect(),j.current=!0}},[]),(0,Z.useLayoutEffect)(()=>{let e=m.current;if(!e)return;let t=e=>{e.preventDefault(),_.current?.({clientX:e.clientX,clientY:e.clientY})};return e.addEventListener(`contextmenu`,t),()=>e.removeEventListener(`contextmenu`,t)},[]),(0,Q.jsxs)(`div`,{ref:h,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:f,className:`chart-canvas`,role:`img`,"aria-label":`Spectrogram`}),(0,Q.jsx)(`canvas`,{ref:p,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),(0,Q.jsx)(`canvas`,{ref:m,className:`chart-canvas chart-overlay`})]})}var p2=300,m2=256,h2=-60,g2=[];function _2({signal:e,sampleRate:t,windowSize:n,overlap:r,winFunc:i,yMode:a,backgroundToken:o,onPlotContextMenu:s}){let c=2**Math.ceil(Math.log2(Math.max(4,Math.min(n,4096)))),l=Math.max(1,Math.round(c*(1-Math.max(0,Math.min(.95,r))))),u=a===`db`,d=(0,Z.useMemo)(()=>Z0(e,c,l,i===`hann`,u,null),[e,c,l,i,u]);return(0,Q.jsx)(Q1,{points:g2,surface:(0,Z.useMemo)(()=>v2(d,t,c,l,u),[d,t,c,l,u]),xLabel:`Time (s)`,yLabel:`Frequency (Hz)`,zLabel:u?`Level (dB)`:`Amplitude`,viewMode:`3d`,showMesh:!0,meshStyle:`filled`,meshOpacity:1,backgroundToken:o,onPlotContextMenu:s})}function v2(e,t,n,r,i){let{frames:a,bins:o,values:s}=e;if(a<2||o<2)return;let c=Math.min(a,p2),l=Math.min(o,m2),u=i?20*Math.log10(Math.max(e.max,1e-12))+h2:-1/0,d=new Float32Array(c*l);for(let e=0;e<l;e++){let t=Math.floor(e*o/l),n=Math.max(t+1,Math.floor((e+1)*o/l));for(let r=0;r<c;r++){let i=Math.floor(r*a/c),o=Math.max(i+1,Math.floor((r+1)*a/c)),l=-1/0;for(let e=t;e<n;e++)for(let t=i;t<o;t++){let n=s[e*a+t];n>l&&(l=n)}d[e*c+r]=Math.max(u,l)}}let f=e=>(e*r+n/2)/t;return{w:c,h:l,values:d,x:[f(0),f(a-1)],y:[0,(o-1)*t/n]}}function y2(e,t,n){return Array.from({length:n},(r,i)=>e+(i+1)/(n+1)*(t-e))}function b2(e,t,n,r){let i=[],a=(n,r)=>e[r*t+n],o=(e,t)=>(r-e)/(t-e);for(let e=0;e+1<n;e++)for(let n=0;n+1<t;n++){let t=a(n,e),s=a(n+1,e),c=a(n+1,e+1),l=a(n,e+1);if(t!==t||s!==s||c!==c||l!==l)continue;let u=(t>=r?8:0)|(s>=r?4:0)|(c>=r?2:0)|l>=r;if(u===0||u===15)continue;let d=()=>[n+o(t,s),e],f=()=>[n+1,e+o(s,c)],p=()=>[n+o(l,c),e+1],m=()=>[n,e+o(t,l)],h=(e,t)=>i.push([e[0],e[1],t[0],t[1]]);switch(u){case 1:case 14:h(m(),p());break;case 2:case 13:h(p(),f());break;case 3:case 12:h(m(),f());break;case 4:case 11:h(d(),f());break;case 6:case 9:h(d(),p());break;case 7:case 8:h(m(),d());break;case 5:case 10:{let e=(t+s+c+l)/4>=r;u===5===e?(h(m(),d()),h(p(),f())):(h(d(),f()),h(m(),p()));break}}}return i}function x2(e){let t=e.length,n=new Float64Array(t+1);if(t===1)return n[0]=e[0]-.5,n[1]=e[0]+.5,n;for(let r=1;r<t;r++)n[r]=(e[r-1]+e[r])/2;return n[0]=e[0]-(n[1]-e[0]),n[t]=e[t-1]+(e[t-1]-n[t-1]),n}function S2(e){if(e.length===0)return!1;for(let t=0;t<e.length;t++)if(!Number.isFinite(e[t])||t>0&&!(e[t]>e[t-1]))return!1;return!0}var C2={top:14,right:32,bottom:80,left:80};function w2(e,t,n){return[e[0]+(t[0]-e[0])*n,e[1]+(t[1]-e[1])*n,e[2]+(t[2]-e[2])*n]}var T2=[[33,102,172],[103,169,207],[209,229,240],[247,247,247],[253,219,199],[239,138,98],[178,24,43]],E2=[[13,8,135],[84,2,163],[139,10,165],[185,50,137],[219,92,104],[244,136,73],[254,188,43],[240,249,33]],D2=[[68,1,84],[72,40,120],[62,83,160],[49,120,178],[38,153,185],[31,184,187],[53,213,158],[117,231,101],[198,239,82],[253,231,37]];function O2(e,t){let n=e.length-1,r=Math.min(n-1,Math.floor(t*n));return w2(e[r],e[r+1],t*n-r)}function k2(e,t){return O2(t===`plasma`?E2:t===`viridis`?D2:T2,e)}function A2(e){let t=new Uint8Array(256*4);for(let n=0;n<256;n++){let[r,i,a]=k2(n/255,e);t.set([r,i,a,255],n*4)}return t}function j2(e){return Math.abs(e)>=1e4||Math.abs(e)<.01&&e!==0?e.toExponential(1):String(parseFloat(e.toPrecision(3)))}function M2(e,t,n){let r=new Map(t.map((e,t)=>[e,t])),i=new Map(n.map((e,t)=>[e,t])),a=new Float32Array(t.length*n.length);for(let n of e){let e=r.get(n.x),o=i.get(n.y);e!==void 0&&o!==void 0&&(a[o*t.length+e]=n.value)}return{w:t.length,h:n.length,values:a,xLabels:t,yLabels:n}}function N2(e,t,n,r,i,a,o){let s=(e,t,n)=>Float64Array.from({length:e+1},(r,i)=>t+i/e*n),c=!!a&&a.length===e.w,l=!!o&&o.length===e.h,u=s(e.w,t,r),d=s(e.h,n,i);if(c){let n=x2(a),i=n[e.w]-n[0];u=Float64Array.from(n,e=>t+(e-n[0])/i*r)}if(l){let t=x2(Float64Array.from(o).reverse()),r=e.h,a=t[r]-t[0];d=Float64Array.from({length:r+1},(e,o)=>n+(t[r]-t[r-o])/a*i)}return{xB:u,yB:d,byValue:c||l}}function P2(e,t){if(t<e[0]||t>=e[e.length-1])return-1;let n=0,r=e.length-1;for(;r-n>1;){let i=n+r>>1;e[i]<=t?n=i:r=i}return n}function F2(e,t,n,r,i,a){let o=Math.max(1,i),s=Math.max(1,a),c=Int32Array.from({length:o},(e,r)=>P2(t.xB,n+r+.5)),l=new Float32Array(o*s);for(let n=0;n<s;n++){let i=P2(t.yB,r+n+.5),a=i*e.w;for(let t=0;t<o;t++)l[n*o+t]=i<0||c[t]<0?NaN:e.values[a+c[t]]}return{w:o,h:s,values:l,xLabels:e.xLabels,yLabels:e.yLabels}}function I2({cells:e,xLabels:t,yLabels:n,grid:r,showValues:i=!0,colorScheme:a=`diverging`,vMin:o,vMax:s,xCentres:c,yCentres:l,contours:u=0,backgroundToken:d=``,onPlotContextMenu:f}){let p=(0,Z.useRef)(null),m=(0,Z.useRef)(null),h=(0,Z.useRef)(null),g=(0,Z.useRef)(null),_=(0,Z.useRef)(null),v=(0,Z.useRef)(null),y=(0,Z.useRef)(null),b=(0,Z.useRef)(0),x=(0,Z.useRef)(f);(0,Z.useLayoutEffect)(()=>{x.current=f},[f]);let S=(0,Z.useMemo)(()=>r??M2(e??[],t??[],n??[]),[r,e,t,n]),C=(0,Z.useMemo)(()=>{let e=o??1/0,t=s??-1/0;if(o===void 0||s===void 0){let n=1/0,r=-1/0;for(let e=0;e<S.w*S.h;e++){let t=S.values[e];t<n&&(n=t),t>r&&(r=t)}o===void 0&&(e=n),s===void 0&&(t=r)}return t>e||(e=Number.isFinite(e)?e-1:0,t=e+2),{lo:e,hi:t}},[S,o,s]),w=(0,Z.useRef)({data:S,range:C,showValues:i,colorScheme:a,xCentres:c,yCentres:l,contours:u});(0,Z.useLayoutEffect)(()=>{w.current={data:S,range:C,showValues:i,colorScheme:a,xCentres:c,yCentres:l,contours:u}},[S,C,i,a,c,l,u]);let T=(0,Z.useRef)({plot:null,failed:!1,size:``,data:null,key:``,shown:null,geo:null}),E=(0,Z.useRef)({key:``,grid:null,segs:[]});(0,Z.useEffect)(()=>()=>{T.current.plot?.dispose(),T.current.plot=null},[]);let D=(0,Z.useRef)({data:null,range:``});function O(){if(v.current)return v.current;let e=_.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return v.current=n,n}function k(){let e=_.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function A(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function j(e,t){let n=T.current;if(!n.plot&&!n.failed&&m.current&&(n.plot=dX(m.current,v0),n.failed=!n.plot),!n.plot||!m.current)return null;let r=Math.min(2,window.devicePixelRatio||1),i=`${e}x${t}@${r}`;return n.size!==i&&(n.plot.resize(e,t,r),m.current.style.width=`${e}px`,m.current.style.height=`${t}px`,n.size=i),n.plot}let M=(e,t)=>typeof e==`function`?e(t):e[t];function N(){let e=p.current;if(!e)return;let{w:t,h:n}=k(),r=A(e,t,n);if(!r)return;let i=h.current?A(h.current,t,n):null;i?.clearRect(0,0,t,n);let a=j$(C2,t,n),{top:o,right:s,bottom:c,left:l}=a,{bg:u,muted:d,grid:f}=O(),{data:m,range:{lo:g,hi:v},showValues:y,colorScheme:b}=w.current;r.fillStyle=u,r.fillRect(0,0,t,n);let x=j(t,n);if(m.w===0||m.h===0){x?.keep([]),x?.render(),r.fillStyle=d,r.font=`13px ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,MY(r);return}let S=t-l-s,C=n-o-c,N=Math.min(2,window.devicePixelRatio||1),P=D.current;(P.data!==m||P.range!==`${g}|${v}`)&&(D.current={data:m,range:`${g}|${v}`},VX(_.current));let{xCentres:F,yCentres:I,contours:L}=w.current,R=x?x.maxTextureSize:Math.max(1,Math.round(S*N)),z=K0(m,R).grid,B=N2(z,l,o,S,C,z===m?F:void 0,z===m?I:void 0),V=B.byValue,ee=`${R}|${b}|${V?`${S}x${C}`:``}`,H=T.current.shown;if(T.current.data!==m||T.current.key!==ee||!H){H=z;let e=V?F2(H,B,l,o,Math.round(S),Math.round(C)):H;x&&x.setGrid(`cells`,e.values,e.w,Math.min(e.h,x.maxTextureSize),[0,e.w,0,e.h],A2(b),g,v),T.current.data=m,T.current.key=ee,T.current.shown=H}T.current.geo=B;let U=V?Math.round(S):H.w,te=V?Math.round(C):H.h,W=e=>B.xB[e+1]-B.xB[e],ne=e=>B.yB[e+1]-B.yB[e];if(x)x.keep([`cells`]),x.setGridRange(`cells`,g,v),x.setView(0,U,te,0,{left:l,top:o,width:S,height:C}),x.render();else for(let e=0;e<H.h;e++)for(let t=0;t<H.w;t++){let n=H.values[e*H.w+t];if(Number.isNaN(n))continue;let[i,a,o]=k2(Math.max(0,Math.min(1,(n-g)/(v-g))),b);r.fillStyle=`rgb(${i|0},${a|0},${o|0})`,r.fillRect(B.xB[t],B.yB[e],W(t)+.5,ne(e)+.5)}let G=i??r;if(y){for(let e=0;e<H.h;e++)if(!(ne(e)<=16)){G.font=`${Math.min(12,Math.max(8,ne(e)*.4))}px ${X.mono}`,G.textAlign=`center`,G.textBaseline=`middle`;for(let t=0;t<H.w;t++){let n=H.values[e*H.w+t];if(Number.isNaN(n)||W(t)<=28)continue;let[r,i,a]=k2(Math.max(0,Math.min(1,(n-g)/(v-g))),b);G.fillStyle=.299*r+.587*i+.114*a>128?`#000`:`#fff`,G.fillText(j2(n),(B.xB[t]+B.xB[t+1])/2,(B.yB[e]+B.yB[e+1])/2)}}}if(S/H.w>=4&&C/H.h>=4){G.strokeStyle=u,G.lineWidth=.5;for(let e=0;e<=H.w;e++)G.beginPath(),G.moveTo(B.xB[e],o),G.lineTo(B.xB[e],o+C),G.stroke();for(let e=0;e<=H.h;e++)G.beginPath(),G.moveTo(l,B.yB[e]),G.lineTo(l+S,B.yB[e]),G.stroke()}let re=L>0?y2(g,v,L):[];if(re.length&&H.w>=2&&H.h>=2&&H.w*H.h<=4e6){let e=`${g}|${v}|${L}`;if(E.current.grid!==H||E.current.key!==e){let t=H;E.current={key:e,grid:t,segs:re.map(e=>b2(t.values,t.w,t.h,e))}}let t=(e,t)=>{let n=Math.min(t.length-3,Math.max(0,Math.floor(e))),r=(t[n]+t[n+1])/2;return r+((t[n+1]+t[n+2])/2-r)*(e-n)};G.save(),G.beginPath(),G.rect(l,o,S,C),G.clip(),G.lineCap=`round`,G.lineJoin=`round`;for(let[e,n]of[[2.6,`rgba(0,0,0,0.38)`],[1.1,`rgba(255,255,255,0.92)`]]){G.lineWidth=e,G.strokeStyle=n,G.beginPath();for(let e of E.current.segs)for(let[n,r,i,a]of e)G.moveTo(t(n,B.xB),t(r,B.yB)),G.lineTo(t(i,B.xB),t(a,B.yB));G.stroke()}G.restore()}r.fillStyle=d,r.font=`10px ${X.mono}`,r.textAlign=`center`,r.textBaseline=`top`;let ie=-1/0;for(let e=0;e<(a.tiny?0:H.w);e++){let t=(B.xB[e]+B.xB[e+1])/2;t-ie<18||(ie=t,r.save(),r.translate(t,o+C+4),r.rotate(-Math.PI/4),r.fillText(M(H.xLabels,e),0,0),r.restore())}r.textAlign=`right`,r.textBaseline=`middle`;let ae=-1/0;for(let e=0;e<(a.tiny?0:H.h);e++){let t=(B.yB[e]+B.yB[e+1])/2;t-ae<12||(ae=t,r.fillText(H.yLabels[e]??``,l-4,t))}if(a.tiny)return;let oe=t-s+4,se=o,ce=C;for(let e=0;e<ce;e++){let[t,n,i]=k2(1-e/ce,b);r.fillStyle=`rgb(${t|0},${n|0},${i|0})`,r.fillRect(oe,se+e,12,1)}r.strokeStyle=f,r.lineWidth=.5,r.strokeRect(oe,se,12,ce),r.fillStyle=d,r.font=`9px ${X.mono}`,r.textAlign=`left`,r.textBaseline=`middle`,r.fillText(j2(v),oe+12+2,se),r.fillText(j2(g),oe+12+2,se+ce),r.fillText(j2((g+v)/2),oe+12+2,se+ce/2),r.strokeStyle=`rgba(255,255,255,0.92)`,r.lineWidth=1;for(let e of re){let t=se+ce*(1-(e-g)/(v-g));r.beginPath(),r.moveTo(oe-2,t),r.lineTo(oe+12+2,t),r.stroke()}}function P(){let e=g.current;if(!e)return;let{w:t,h:n}=k(),r=A(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=y.current,a=T.current.shown,o=T.current.geo;if(!i||!a||!o)return;let{top:s,right:c,bottom:l}=j$(C2,t,n),{xi:u,yi:d}=i;if(u>=a.w||d>=a.h)return;let f=o.xB[u],p=o.xB[u+1],m=o.yB[d],h=o.yB[d+1];r.strokeStyle=`rgba(255,255,255,0.7)`,r.lineWidth=1.5,r.strokeRect(f+.5,m+.5,Math.max(1,p-f-1),Math.max(1,h-m-1));let _=a.values[d*a.w+u];if(!Number.isNaN(_)){let e=`${M(a.xLabels,u)} × ${a.yLabels[d]}: ${j2(_)}`;r.font=`11px ${X.mono}`;let n=r.measureText(e).width,i=Math.min(p+.1*(p-f),t-c-n-6),o=Math.max(s+4,m-.3*(h-m));r.fillStyle=`rgba(0,0,0,0.7)`,r.fillRect(i-3,o-3,n+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(e,i,o)}}let F=(0,Z.useRef)(N);F.current=N;let I=(0,Z.useRef)(null);I.current??=KX(()=>F.current(),()=>_.current);let L=()=>{b.current||=RX(()=>{b.current=0,P()})};return(0,Z.useEffect)(()=>{I.current.now()},[S,C,i,a,c,l,u]),(0,Z.useEffect)(()=>()=>{I.current?.cancel(),zX(b.current)},[]),(0,Z.useEffect)(()=>{v.current=null,I.current.schedule()},[d]),(0,Z.useLayoutEffect)(()=>{let e=_.current;if(!e)return;let t=new WX(()=>{v.current=null,I.current.schedule(),L()});return t.observe(e),()=>t.disconnect()},[]),(0,Z.useLayoutEffect)(()=>{let e=g.current;if(!e)return;let t=e=>{e.preventDefault(),x.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),{shown:r,geo:i}=T.current;if(!r||!i)return;let a=P2(i.xB,t.clientX-n.left),o=P2(i.yB,t.clientY-n.top);y.current=a>=0&&a<r.w&&o>=0&&o<r.h?{xi:a,yi:o}:null,L()},r=()=>{y.current=null,L()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),(0,Q.jsxs)(`div`,{ref:_,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:p,className:`chart-canvas`,role:`img`,"aria-label":`Heatmap`}),(0,Q.jsx)(`canvas`,{ref:m,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),(0,Q.jsx)(`canvas`,{ref:h,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),(0,Q.jsx)(`canvas`,{ref:g,className:`chart-canvas chart-overlay`})]})}var L2=2e3,R2=1024;function z2(e,t,n,r,i){let a=e.length,o=1/(a*t*Math.sqrt(2*Math.PI)),s=new Float64Array(n.length);if(a<=L2){for(let r=0;r<n.length;r++){let i=0;for(let o=0;o<a;o++){let a=(n[r]-e[o])/t;i+=Math.exp(-.5*a*a)}s[r]=i*o}return s}let c=new Float64Array(R2),l=(i-r)/R2||1;for(let t=0;t<a;t++)c[Math.max(0,Math.min(R2-1,Math.floor((e[t]-r)/l)))]++;for(let e=0;e<n.length;e++){let i=0;for(let a=0;a<R2;a++){if(c[a]===0)continue;let o=(n[e]-(r+(a+.5)*l))/t;i+=c[a]*Math.exp(-.5*o*o)}s[e]=i*o}return s}var B2={top:14,right:24,bottom:48,left:64},V2=120;function H2(e,t,n){let r=e.length;if(r<2)return 1;let i=0;for(let t=0;t<r;t++)i+=e[t];let a=i/r,o=0;for(let t=0;t<r;t++)o+=(e[t]-a)**2;let s=Math.sqrt(o/(r-1));return .9*Math.min(s,(n-t)/1.34)*r**-.2}function U2(e,t){let n=e.filter(e=>e.values.length>=2),r=1/0,i=-1/0,a=n.map(e=>{let[t,n,a,o,s]=V0(Float64Array.from(e.values),[0,25,50,75,100]);return t<r&&(r=t),s>i&&(i=s),{q1:n,median:a,q3:o}}),o=(i-r)*.1||1;r-=o,i+=o;let s=Float64Array.from({length:V2},(e,t)=>r+t/(V2-1)*(i-r));return{shapes:n.map((e,n)=>{let{q1:o,median:c,q3:l}=a[n],u=z2(e.values,t>0?t:H2(e.values,o,l),s,r,i),d=1e-10;for(let e of u)e>d&&(d=e);return{label:e.label,density:u,maxDensity:d,q1:o,median:c,q3:l}}),pts:s,yMin:r,yMax:i}}function W2({groups:e,color:t=`#818cf8`,showBox:n=!0,bandwidth:r=0,orientation:i=`vertical`,backgroundToken:a=``,onPlotContextMenu:o}){let s=IZ(),c=(0,Z.useRef)(null),l=(0,Z.useRef)(null),u=(0,Z.useRef)(null),d=(0,Z.useRef)(o);(0,Z.useLayoutEffect)(()=>{d.current=o},[o]);let f=(0,Z.useRef)({groups:e,color:t,showBox:n,bandwidth:r,orientation:i});(0,Z.useLayoutEffect)(()=>{f.current={groups:e,color:t,showBox:n,bandwidth:r,orientation:i}},[e,t,n,r,i]);let p=(0,Z.useMemo)(()=>U2(e,r),[e,r]),m=(0,Z.useRef)(p);(0,Z.useLayoutEffect)(()=>{m.current=p},[p]);function h(){if(u.current)return u.current;let e=l.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return u.current=n,n}function g(){let e=l.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function _(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function v(){let e=c.current;if(!e)return;let{w:t,h:n}=g(),r=_(e,t,n);if(!r)return;let{top:i,right:a,bottom:o,left:l}=B2,u=t-l-a,d=n-i-o,{bg:p,muted:v,grid:y}=h(),{color:b,showBox:x,orientation:S}=f.current;r.fillStyle=p,r.fillRect(0,0,t,n);let{shapes:C,pts:w,yMin:T,yMax:E}=m.current;if(C.length===0||u<=0||d<=0){r.fillStyle=v,r.font=`13px ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,MY(r);return}let D=S===`vertical`,O=D?e=>i+d*(1-(e-T)/(E-T)):e=>l+u*((e-T)/(E-T));s({left:l,top:i,width:u,height:d,...D?{y:{v0:T,v1:E}}:{x:{v0:T,v1:E}}});let k=uJ(E-T,5),A=pJ(T,E,k);r.strokeStyle=y,r.lineWidth=1,r.setLineDash([3,3]);for(let e of A)D?(r.beginPath(),r.moveTo(l,O(e)),r.lineTo(l+u,O(e)),r.stroke()):(r.beginPath(),r.moveTo(O(e),i),r.lineTo(O(e),i+d),r.stroke());if(r.setLineDash([]),r.fillStyle=v,r.font=`11px ${X.mono}`,r.strokeStyle=v,r.lineWidth=1,D){r.textAlign=`right`,r.textBaseline=`middle`;for(let e of A)r.beginPath(),r.moveTo(l-4,O(e)),r.lineTo(l,O(e)),r.stroke(),r.fillText(_J(e,k),l-6,O(e))}else{r.textAlign=`center`,r.textBaseline=`top`;for(let e of A)r.beginPath(),r.moveTo(O(e),i+d),r.lineTo(O(e),i+d+4),r.stroke(),r.fillText(_J(e,k),O(e),i+d+6)}r.strokeStyle=y,r.strokeRect(l,i,u,d),r.save(),r.beginPath(),r.rect(l,i,u,d),r.clip();let j=C.length,M=D?u/j:d/j;for(let e=0;e<j;e++){let{density:t,maxDensity:n,q1:a,median:o,q3:s}=C[e],c=D?l+M*e+M/2:i+M*e+M/2,u=M*.45;r.beginPath();for(let e=0;e<V2;e++){let i=t[e]/n*u,a=O(w[e]);D?e===0?r.moveTo(c-i,a):r.lineTo(c-i,a):e===0?r.moveTo(a,c-i):r.lineTo(a,c-i)}for(let e=V2-1;e>=0;e--){let i=t[e]/n*u,a=O(w[e]);D?r.lineTo(c+i,a):r.lineTo(a,c+i)}if(r.closePath(),r.fillStyle=b,r.globalAlpha=.35,r.fill(),r.strokeStyle=b,r.lineWidth=1,r.globalAlpha=.9,r.stroke(),r.globalAlpha=1,x){let e=u*.22;D?(r.fillStyle=b,r.globalAlpha=.7,r.fillRect(c-e,O(s),e*2,O(a)-O(s)),r.globalAlpha=1,r.strokeStyle=b,r.lineWidth=2,r.beginPath(),r.moveTo(c-e,O(o)),r.lineTo(c+e,O(o)),r.stroke()):(r.fillStyle=b,r.globalAlpha=.7,r.fillRect(O(a),c-e,O(s)-O(a),e*2),r.globalAlpha=1,r.strokeStyle=b,r.lineWidth=2,r.beginPath(),r.moveTo(O(o),c-e),r.lineTo(O(o),c+e),r.stroke())}}if(r.restore(),r.fillStyle=v,r.font=`11px ${X.mono}`,D){r.textAlign=`center`,r.textBaseline=`top`;for(let e=0;e<j;e++)r.fillText(C[e].label,l+M*e+M/2,i+d+6)}else{r.textAlign=`right`,r.textBaseline=`middle`;for(let e=0;e<j;e++)r.fillText(C[e].label,l-6,i+M*e+M/2)}}let y=(0,Z.useRef)(v);y.current=v;let b=(0,Z.useRef)(null);b.current??=KX(()=>y.current(),()=>l.current);let x=()=>b.current.schedule();return(0,Z.useEffect)(()=>{b.current.now()}),(0,Z.useEffect)(()=>()=>b.current?.cancel(),[]),(0,Z.useEffect)(()=>{u.current=null,x()},[a]),(0,Z.useLayoutEffect)(()=>{let e=l.current;if(!e)return;let t=new WX(()=>{u.current=null,x()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{let e=c.current;if(!e)return;let t=e=>{e.preventDefault(),d.current?.({clientX:e.clientX,clientY:e.clientY})};return e.addEventListener(`contextmenu`,t),()=>e.removeEventListener(`contextmenu`,t)},[]),(0,Q.jsx)(`div`,{ref:l,style:{position:`relative`,width:`100%`,height:`100%`},children:(0,Q.jsx)(`canvas`,{ref:c,className:`chart-canvas`,role:`img`,"aria-label":`Violin plot`})})}var G2={top:48,right:16,bottom:72,left:80},K2=[8,24,64],q2=[56,189,248];function J2(e,t,n){return[e[0]+(t[0]-e[0])*n,e[1]+(t[1]-e[1])*n,e[2]+(t[2]-e[2])*n]}function Y2(e){return`${(e*100).toFixed(1)}%`}function X2(e,t,n){if(e.length===0)return null;let r=Math.min(e.length,t.length),i=Array(r),a=Array(r),o=new Set,s=0;for(let n=0;n<r;n++)i[n]=String(e[n]),a[n]=String(t[n]),o.add(i[n]),o.add(a[n]),i[n]===a[n]&&s++;let c=[...o].sort(),l=c.length,u=new Map(c.map((e,t)=>[e,t])),d=Array.from({length:l},()=>Array(l).fill(0));for(let e=0;e<r;e++)d[u.get(i[e])][u.get(a[e])]++;let f=d.map(e=>e.reduce((e,t)=>e+t,0));return{classes:c,matrix:n?d.map((e,t)=>e.map(e=>f[t]>0?e/f[t]:0)):d,raw:d,accuracy:s/e.length}}function Z2({actual:e,predicted:t,normalize:n=!1,backgroundToken:r=``,onPlotContextMenu:i}){let a=(0,Z.useRef)(null),o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(null),u=(0,Z.useRef)(0),d=(0,Z.useRef)(i);(0,Z.useLayoutEffect)(()=>{d.current=i},[i]);let f=(0,Z.useRef)({actual:e,predicted:t,normalize:n});(0,Z.useLayoutEffect)(()=>{f.current={actual:e,predicted:t,normalize:n}},[e,t,n]);function p(){if(c.current)return c.current;let e=s.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return c.current=n,n}function m(){let e=s.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function h(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}let g=(0,Z.useMemo)(()=>X2(e,t,n),[e,t,n]),_=(0,Z.useRef)(g);(0,Z.useLayoutEffect)(()=>{_.current=g},[g]);let v=()=>_.current;function y(){let e=a.current;if(!e)return;let{w:t,h:n}=m(),r=h(e,t,n);if(!r)return;let{top:i,right:o,bottom:s,left:c}=G2,{bg:l,muted:u,grid:d}=p();r.fillStyle=l,r.fillRect(0,0,t,n);let g=v();if(!g){r.fillStyle=u,r.font=`13px ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,MY(r);return}let{classes:_,matrix:y,accuracy:b}=g,x=_.length,S=t-c-o,C=n-i-s,w=S/x,T=C/x,E=0;for(let e of y)for(let t of e)t>E&&(E=t);for(let e=0;e<x;e++)for(let t=0;t<x;t++){let n=y[e][t],[a,o,s]=J2(K2,q2,E>0?n/E:0);if(r.fillStyle=`rgb(${a|0},${o|0},${s|0})`,r.fillRect(c+t*w,i+e*T,w,T),w>24&&T>14){r.fillStyle=.299*a+.587*o+.114*s>100?`#000`:`#fff`,r.font=`${Math.min(12,Math.max(8,T*.38))}px ${X.mono}`,r.textAlign=`center`,r.textBaseline=`middle`;let l=f.current.normalize;r.fillText(l?Y2(n):String(n|0),c+(t+.5)*w,i+(e+.5)*T)}}r.strokeStyle=l,r.lineWidth=.5;for(let e=0;e<=x;e++)r.beginPath(),r.moveTo(c+e*w,i),r.lineTo(c+e*w,i+C),r.stroke(),r.beginPath(),r.moveTo(c,i+e*T),r.lineTo(c+S,i+e*T),r.stroke();r.strokeStyle=d,r.strokeRect(c,i,S,C),r.fillStyle=u,r.font=`10px ${X.mono}`,r.textAlign=`right`,r.textBaseline=`middle`;for(let e=0;e<x;e++)r.fillText(_[e],c-4,i+(e+.5)*T);r.textAlign=`center`,r.textBaseline=`top`;for(let e=0;e<x;e++)r.save(),r.translate(c+(e+.5)*w,i+C+4),r.rotate(-Math.PI/4),r.fillText(_[e],0,0),r.restore();r.fillStyle=u,r.font=`11px ${X.mono}`,r.textAlign=`center`,r.textBaseline=`bottom`,r.fillText(`Predicted`,c+S/2,n-4),r.save(),r.translate(12,i+C/2),r.rotate(-Math.PI/2),r.textAlign=`center`,r.fillText(`Actual`,0,0),r.restore(),r.fillStyle=u,r.font=`11px ${X.mono}`,r.textAlign=`center`,r.textBaseline=`middle`,r.fillText(`Accuracy: ${Y2(b)}`,c+S/2,i/2)}function b(){let e=o.current;if(!e)return;let{w:t,h:n}=m(),r=h(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=l.current;if(!i)return;let{top:a,right:s,bottom:c,left:u}=G2,d=v();if(!d)return;let{classes:p,matrix:g}=d,_=p.length,y=t-u-s,b=n-a-c,x=y/_,S=b/_;r.strokeStyle=`rgba(255,255,255,0.8)`,r.lineWidth=2,r.strokeRect(u+i.c*x+1,a+i.r*S+1,x-2,S-2);let C=g[i.r][i.c],w=f.current.normalize,T=`${p[i.r]} → ${p[i.c]}: ${w?Y2(C):C|0}`;r.font=`11px ${X.mono}`;let E=r.measureText(T).width,D=Math.min(u+(i.c+1.1)*x,t-E-6),O=Math.max(6,a+(i.r-.3)*S);r.fillStyle=`rgba(0,0,0,0.75)`,r.fillRect(D-3,O-3,E+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(T,D,O)}let x=(0,Z.useRef)(y);x.current=y;let S=(0,Z.useRef)(null);S.current??=KX(()=>x.current(),()=>s.current);let C=()=>S.current.schedule(),w=()=>{zX(u.current),u.current=RX(b)};return(0,Z.useEffect)(()=>{S.current.now()}),(0,Z.useEffect)(()=>()=>S.current?.cancel(),[]),(0,Z.useEffect)(()=>{c.current=null,C()},[r]),(0,Z.useLayoutEffect)(()=>{let e=s.current;if(!e)return;let t=new WX(()=>{c.current=null,C(),w()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{let e=o.current;if(!e)return;let t=e=>{e.preventDefault(),d.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),{top:r,right:i,bottom:a,left:o}=G2,s=v();if(!s)return;let c=s.classes.length,u=n.width-o-i,d=n.height-r-a,f=Math.floor((t.clientX-n.left-o)/(u/c)),p=Math.floor((t.clientY-n.top-r)/(d/c));l.current=p>=0&&p<c&&f>=0&&f<c?{r:p,c:f}:null,w()},r=()=>{l.current=null,w()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),(0,Q.jsxs)(`div`,{ref:s,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:a,className:`chart-canvas`,role:`img`,"aria-label":`Confusion matrix`}),(0,Q.jsx)(`canvas`,{ref:o,className:`chart-canvas chart-overlay`})]})}var Q2={top:24,right:24,bottom:48,left:64};function $2(e,t){let n=0,r=0,i=Math.min(e.length,t.length);for(let a=0;a<i;a++)e[a]-e[a]!==0||t[a]-t[a]!==0||(t[a]===1?n++:r++);let a=new Float64Array(n),o=new Float64Array(r);for(let n=0,r=0,s=0;n<i;n++)e[n]-e[n]!==0||t[n]-t[n]!==0||(t[n]===1?a[r++]=e[n]:o[s++]=e[n]);a.sort(),o.sort();let s=new Uint8Array(n+r);for(let e=0,t=n-1,i=r-1;e<s.length;e++)i<0||t>=0&&a[t]>=o[i]?(s[e]=1,t--):(s[e]=0,i--);return s}function e4(e){let t=0;for(let n of e)t+=n;let n=e.length-t;if(t===0||n===0)return null;let r=new Float64Array(e.length+2),i=new Float64Array(e.length+2),a=0,o=0,s=0;for(let c=0;c<e.length;c++)e[c]===1?a++:o++,r[c+1]=o/n,i[c+1]=a/t,s+=(r[c+1]-r[c])*(i[c+1]+i[c])/2;return r[e.length+1]=1,i[e.length+1]=1,{fpr:r,tpr:i,auc:s}}function t4(e){let t=0;for(let n of e)t+=n;if(t===0)return null;let n=new Float64Array(e.length),r=new Float64Array(e.length),i=0,a=0,o=0;for(let s=0;s<e.length;s++)e[s]===1?i++:a++,n[s]=i/t,r[s]=i/(i+a),s>0&&(o+=(n[s]-n[s-1])*r[s]);return{recall:n,precision:r,ap:o}}function n4(e,t,n,r){let i=n(0),a=r(0);e.moveTo(i,a);for(let o=1;o<t;o++){let s=n(o),c=r(o);o<t-1&&Math.abs(s-i)<.5&&Math.abs(c-a)<.5||(e.lineTo(s,c),i=s,a=c)}}function r4({scores:e,labels:t,mode:n=`roc`,color:r=`#f472b6`,backgroundToken:i=``,onPlotContextMenu:a}){let o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(a);(0,Z.useLayoutEffect)(()=>{l.current=a},[a]);let u=(0,Z.useRef)({scores:e,labels:t,mode:n,color:r});(0,Z.useLayoutEffect)(()=>{u.current={scores:e,labels:t,mode:n,color:r}},[e,t,n,r]);let d=(0,Z.useMemo)(()=>$2(e,t),[e,t]),f=(0,Z.useMemo)(()=>n===`pr`?{roc:null,pr:t4(d)}:{roc:e4(d),pr:null},[d,n]),p=(0,Z.useRef)(f);(0,Z.useLayoutEffect)(()=>{p.current=f},[f]);function m(){if(c.current)return c.current;let e=s.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return c.current=n,n}function h(){let e=s.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function g(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function _(){let e=o.current;if(!e)return;let{w:t,h:n}=h(),r=g(e,t,n);if(!r)return;let{top:i,right:a,bottom:s,left:c}=Q2,l=t-c-a,d=n-i-s,{bg:f,muted:_,grid:v}=m(),{scores:y,mode:b,color:x}=u.current;if(r.fillStyle=f,r.fillRect(0,0,t,n),y.length===0){r.fillStyle=_,r.font=`13px ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,MY(r);return}let S=e=>c+e*l,C=e=>i+(1-e)*d,w=pJ(0,1,uJ(1,5));r.strokeStyle=v,r.lineWidth=1,r.setLineDash([3,3]);for(let e of w)r.beginPath(),r.moveTo(S(e),i),r.lineTo(S(e),i+d),r.stroke(),r.beginPath(),r.moveTo(c,C(e)),r.lineTo(c+l,C(e)),r.stroke();if(r.setLineDash([]),b===`roc`&&(r.strokeStyle=_,r.lineWidth=1,r.setLineDash([4,4]),r.beginPath(),r.moveTo(S(0),C(0)),r.lineTo(S(1),C(1)),r.stroke(),r.setLineDash([])),b===`roc`){let e=p.current.roc;if(e){let t=e.fpr.length,n=t=>S(e.fpr[t]),a=t=>C(e.tpr[t]);r.beginPath(),n4(r,t,n,a),r.strokeStyle=x,r.lineWidth=1,r.stroke(),r.beginPath(),n4(r,t,n,a),r.lineTo(S(1),C(0)),r.lineTo(S(0),C(0)),r.closePath(),r.fillStyle=x,r.globalAlpha=.15,r.fill(),r.globalAlpha=1,r.fillStyle=x,r.font=`bold 13px ${X.mono}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`AUC = ${e.auc.toFixed(3)}`,c+8,i+8)}}else{let e=p.current.pr;if(e){let t=w0(e.recall,e.precision,0,1,Math.max(1,Math.round(l*Math.min(2,window.devicePixelRatio||1))));r.beginPath();for(let n=0;n<t.length;n++){let i=S(e.recall[t[n]]),a=C(e.precision[t[n]]);n===0?r.moveTo(i,a):r.lineTo(i,a)}r.strokeStyle=x,r.lineWidth=1,r.stroke(),r.fillStyle=x,r.font=`bold 13px ${X.mono}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`AP = ${e.ap.toFixed(3)}`,c+8,i+8)}}r.fillStyle=_,r.font=`11px ${X.mono}`,r.strokeStyle=_,r.lineWidth=1,r.textAlign=`right`,r.textBaseline=`middle`;for(let e of w)r.beginPath(),r.moveTo(c-4,C(e)),r.lineTo(c,C(e)),r.stroke(),r.fillText(e.toFixed(1),c-6,C(e));r.textAlign=`center`,r.textBaseline=`top`;for(let e of w)r.beginPath(),r.moveTo(S(e),i+d),r.lineTo(S(e),i+d+4),r.stroke(),r.fillText(e.toFixed(1),S(e),i+d+6);r.strokeStyle=v,r.strokeRect(c,i,l,d),r.fillStyle=_,r.textAlign=`center`,r.textBaseline=`bottom`,r.fillText(b===`roc`?`False Positive Rate`:`Recall`,c+l/2,n-4),r.save(),r.translate(12,i+d/2),r.rotate(-Math.PI/2),r.textAlign=`center`,r.fillText(b===`roc`?`True Positive Rate`:`Precision`,0,0),r.restore()}let v=(0,Z.useRef)(_);v.current=_;let y=(0,Z.useRef)(null);y.current??=KX(()=>v.current(),()=>s.current);let b=()=>y.current.schedule();return(0,Z.useEffect)(()=>{y.current.now()}),(0,Z.useEffect)(()=>()=>y.current?.cancel(),[]),(0,Z.useEffect)(()=>{c.current=null,b()},[i]),(0,Z.useLayoutEffect)(()=>{let e=s.current;if(!e)return;let t=new WX(()=>{c.current=null,b()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{let e=o.current;if(!e)return;let t=e=>{e.preventDefault(),l.current?.({clientX:e.clientX,clientY:e.clientY})};return e.addEventListener(`contextmenu`,t),()=>e.removeEventListener(`contextmenu`,t)},[]),(0,Q.jsx)(`div`,{ref:s,style:{position:`relative`,width:`100%`,height:`100%`},children:(0,Q.jsx)(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`ROC / PR curve`})})}var i4={top:20,right:64,bottom:48,left:64};function a4({xValues:e,series:t,xLabel:n=`Epoch`,backgroundToken:r=``,onPlotContextMenu:i}){let a=IZ(),o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(null),u=(0,Z.useRef)(null),d=(0,Z.useRef)(0),f=(0,Z.useRef)(i);(0,Z.useLayoutEffect)(()=>{f.current=i},[i]);let p=(0,Z.useRef)({xValues:e,series:t,xLabel:n});(0,Z.useLayoutEffect)(()=>{p.current={xValues:e,series:t,xLabel:n}},[e,t,n]);function m(){if(l.current)return l.current;let e=c.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return l.current=n,n}function h(){let e=c.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function g(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}let _=(0,Z.useMemo)(()=>{let n=e=>{let t=1/0,n=-1/0;for(let r of e)for(let e=0;e<r.values.length;e++){let i=r.values[e];i<t&&(t=i),i>n&&(n=i)}if(!Number.isFinite(t))return{lo:0,hi:1};let r=(n-t)*.06||.1;return{lo:t-r,hi:n+r}},r=t.filter(e=>e.axis===`left`),i=t.filter(e=>e.axis===`right`),a=1/0,o=-1/0;for(let t=0;t<e.length;t++){let n=e[t];n<a&&(a=n),n>o&&(o=n)}return{leftExt:n(r.length?r:t),rightExt:n(i.length?i:t),hasRight:i.length>0,xMin:a,xMax:o,ascending:D0(e)}},[e,t]),v=(0,Z.useRef)(_);(0,Z.useLayoutEffect)(()=>{v.current=_},[_]);function y(){let e=o.current;if(!e)return;let{w:t,h:n}=h(),r=g(e,t,n);if(!r)return;let{top:i,right:s,bottom:c,left:l}=i4,u=t-l-s,d=n-i-c,{bg:f,muted:_,grid:y}=m(),{xValues:b,series:x,xLabel:S}=p.current;if(r.fillStyle=f,r.fillRect(0,0,t,n),b.length===0||x.length===0){r.fillStyle=_,r.font=`13px ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,MY(r);return}let{leftExt:C,rightExt:w,hasRight:T,xMin:E,xMax:D,ascending:O}=v.current,k=e=>l+(e-E)/(D-E||1)*u;a({left:l,top:i,width:u,height:d,x:{v0:E,v1:D},y:{v0:C.lo,v1:C.hi}});let A=e=>i+(1-(e-C.lo)/(C.hi-C.lo))*d,j=e=>i+(1-(e-w.lo)/(w.hi-w.lo))*d,M=uJ(C.hi-C.lo,5),N=pJ(C.lo,C.hi,M);r.strokeStyle=y,r.lineWidth=1,r.setLineDash([3,3]);for(let e of N)r.beginPath(),r.moveTo(l,A(e)),r.lineTo(l+u,A(e)),r.stroke();let P=uJ(D-E,6),F=pJ(E,D,P);for(let e of F)r.beginPath(),r.moveTo(k(e),i),r.lineTo(k(e),i+d),r.stroke();r.setLineDash([]);let I=Math.min(2,window.devicePixelRatio||1),L=Math.max(1,Math.round(u*I));for(let e of x){let t=e.axis===`right`&&T?j:A,n=Math.min(b.length,e.values.length),i=O&&n>4*L?w0(b,e.values,E,D,L):null;r.beginPath();let a=!1;for(let o=0;o<(i?i.length:n);o++){let n=i?i[o]:o,s=b[n],c=e.values[n];if(s-s!==0||c-c!==0){a=!1;continue}let l=k(s),u=t(c);a?r.lineTo(l,u):(r.moveTo(l,u),a=!0)}r.strokeStyle=e.color,r.lineWidth=1,r.stroke()}r.fillStyle=_,r.font=`11px ${X.mono}`,r.strokeStyle=_,r.lineWidth=1,r.textAlign=`right`,r.textBaseline=`middle`;for(let e of N)r.beginPath(),r.moveTo(l-4,A(e)),r.lineTo(l,A(e)),r.stroke(),r.fillText(_J(e,M),l-6,A(e));if(T){let e=uJ(w.hi-w.lo,5),t=pJ(w.lo,w.hi,e);r.textAlign=`left`;for(let n of t)r.beginPath(),r.moveTo(l+u,j(n)),r.lineTo(l+u+4,j(n)),r.stroke(),r.fillText(_J(n,e),l+u+6,j(n))}r.textAlign=`center`,r.textBaseline=`top`;for(let e of F)r.beginPath(),r.moveTo(k(e),i+d),r.lineTo(k(e),i+d+4),r.stroke(),r.fillText(_J(e,P),k(e),i+d+6);r.strokeStyle=y,r.strokeRect(l,i,u,d),r.fillStyle=_,r.textAlign=`center`,r.textBaseline=`bottom`,r.fillText(S,l+u/2,n-4);let R=l+8,z=i+6;r.font=`10px ${X.mono}`,r.textBaseline=`middle`;for(let e of x)r.fillStyle=e.color,r.fillRect(R,z-4,16,3),r.fillStyle=_,r.textAlign=`left`,r.fillText(e.label,R+20,z),R+=r.measureText(e.label).width+36,R>l+u-60&&(R=l+8,z+=14)}function b(){let e=s.current;if(!e)return;let{w:t,h:n}=h(),r=g(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=u.current;if(i===null)return;let{top:a,right:o,bottom:c,left:l}=i4,d=t-l-o,f=n-a-c,{muted:_}=m(),{xValues:y,series:b}=p.current;if(y.length===0)return;let{xMin:x,xMax:S,ascending:C}=v.current,w=e=>l+(e-x)/(S-x||1)*d,T=Math.max(l,Math.min(l+d,i));r.strokeStyle=_,r.lineWidth=1,r.setLineDash([3,3]),r.beginPath(),r.moveTo(T,a),r.lineTo(T,a+f),r.stroke(),r.setLineDash([]);let E=(T-l)/d,D=Math.round(E*(y.length-1));if(C){let e=x+E*(S-x),t=0,n=y.length;for(;t<n;){let r=t+n>>>1;y[r]<e?t=r+1:n=r}D=t>0&&(t>=y.length||e-y[t-1]<y[t]-e)?t-1:t}if(D<0||D>=y.length)return;let O=a+8;r.font=`10px ${X.mono}`,r.textBaseline=`top`;for(let e of b)D<e.values.length&&Number.isFinite(e.values[D])&&(r.fillStyle=e.color,r.textAlign=`left`,r.fillText(`${e.label}: ${vJ(e.values[D])}`,T+6,O),O+=14);w(0)}let x=(0,Z.useRef)(y);x.current=y;let S=(0,Z.useRef)(null);S.current??=KX(()=>x.current(),()=>c.current);let C=()=>S.current.schedule(),w=()=>{zX(d.current),d.current=RX(b)};return(0,Z.useEffect)(()=>{S.current.now()}),(0,Z.useEffect)(()=>()=>S.current?.cancel(),[]),(0,Z.useEffect)(()=>{l.current=null,C()},[r]),(0,Z.useLayoutEffect)(()=>{let e=c.current;if(!e)return;let t=new WX(()=>{l.current=null,C(),w()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{let e=s.current;if(!e)return;let t=e=>{e.preventDefault(),f.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect();u.current=t.clientX-n.left,w()},r=()=>{u.current=null,w()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),(0,Q.jsxs)(`div`,{ref:c,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`Loss curves`}),(0,Q.jsx)(`canvas`,{ref:s,className:`chart-canvas chart-overlay`})]})}var o4={top:40,right:24,bottom:40,left:72},s4=`#ef4444`,c4=`#f97316`,l4=`#22d3ee`;function u4(e,t){let n=e.length,r=e.value;if(n===0)return null;let i=0;for(let e=0;e<n;e++)i+=r[e];let a=i/n,o=0;for(let e=0;e<n;e++)o+=(r[e]-a)**2;let s=Math.sqrt(o/n),c=a+t*s,l=a-t*s,u=l,d=c,f=0;for(let e=0;e<n;e++){let t=r[e];t<u&&(u=t),t>d&&(d=t),(t>c||t<l)&&f++}let p=(d-u)*.08||.5,m=new Uint32Array(f);for(let e=0,t=0;e<n;e++)(r[e]>c||r[e]<l)&&(m[t++]=e);return{mean:a,sd:s,ucl:c,lcl:l,yMin:u-p,yMax:d+p,ooc:m}}function d4({points:e,sigmaLevel:t=3,color:n=`#22d3ee`,backgroundToken:r=``,onPlotContextMenu:i}){let a=IZ(),o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(null),u=(0,Z.useRef)(null),d=(0,Z.useRef)(0),f=(0,Z.useRef)(i);(0,Z.useLayoutEffect)(()=>{f.current=i},[i]);let p=(0,Z.useRef)({points:e,sigmaLevel:t,color:n});(0,Z.useLayoutEffect)(()=>{p.current={points:e,sigmaLevel:t,color:n}},[e,t,n]);function m(){if(l.current)return l.current;let e=c.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return l.current=n,n}function h(){let e=c.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function g(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}let _=(0,Z.useMemo)(()=>u4(e,t),[e,t]),v=(0,Z.useRef)(_);(0,Z.useLayoutEffect)(()=>{v.current=_},[_]);let y=()=>v.current;function b(){let e=o.current;if(!e)return;let{w:t,h:n}=h(),r=g(e,t,n);if(!r)return;let{top:i,right:s,bottom:c,left:l}=o4,u=t-l-s,d=n-i-c,{bg:f,muted:_,grid:v}=m(),{points:b,color:x}=p.current;if(r.fillStyle=f,r.fillRect(0,0,t,n),b.length===0){r.fillStyle=_,r.font=`13px ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,MY(r);return}let S=y(),{mean:C,ucl:w,lcl:T,yMin:E,yMax:D}=S,O=e=>l+e/(b.length-1||1)*u;a({left:l,top:i,width:u,height:d,x:{v0:0,v1:b.length-1||1}});let k=e=>i+(1-(e-E)/(D-E))*d,A=uJ(D-E,5),j=pJ(E,D,A);r.strokeStyle=v,r.lineWidth=1,r.setLineDash([3,3]);for(let e of j)r.beginPath(),r.moveTo(l,k(e)),r.lineTo(l+u,k(e)),r.stroke();r.setLineDash([]);let M=(e,t,n,a=[])=>{let o=k(e);o<i||o>i+d||(r.strokeStyle=t,r.lineWidth=1.2,r.setLineDash(a),r.beginPath(),r.moveTo(l,o),r.lineTo(l+u,o),r.stroke(),r.setLineDash([]),r.fillStyle=t,r.font=`9px ${X.mono}`,r.textAlign=`right`,r.textBaseline=`middle`,r.fillText(`${n} ${vJ(e)}`,l+u-2,o-5))};M(w,c4,`UCL`,[5,3]),M(C,l4,`CL`,[]),M(T,c4,`LCL`,[5,3]);let N=Math.min(2,window.devicePixelRatio||1),P=Math.max(1,Math.round(u*N)),F=b.length,I=b.value,L=T0(I,P);r.beginPath();for(let e=0;e<L.length;e++){let t=L[e],n=O(t),i=k(I[t]);e===0?r.moveTo(n,i):r.lineTo(n,i)}r.strokeStyle=x,r.lineWidth=1,r.stroke();let R=(e,t)=>{r.beginPath(),r.arc(O(e),k(I[e]),t?4:3,0,Math.PI*2),r.fillStyle=t?s4:x,r.fill()};if(F<=u/4)for(let e=0;e<F;e++)R(e,I[e]>w||I[e]<T);else{let e=NaN,t=NaN;for(let n of S.ooc){let r=Math.round(O(n)),i=Math.round(k(I[n]));r===e&&i===t||(e=r,t=i,R(n,!0))}}r.fillStyle=_,r.font=`11px ${X.mono}`,r.strokeStyle=_,r.lineWidth=1,r.textAlign=`right`,r.textBaseline=`middle`;for(let e of j)r.beginPath(),r.moveTo(l-4,k(e)),r.lineTo(l,k(e)),r.stroke(),r.fillText(_J(e,A),l-6,k(e));r.strokeStyle=v,r.strokeRect(l,i,u,d)}function x(){let e=s.current;if(!e)return;let{w:t,h:n}=h(),r=g(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=u.current;if(i===null)return;let{top:a,right:o,bottom:c,left:l}=o4,d=t-l-o,f=n-a-c,{muted:_}=m(),{points:v}=p.current;if(v.length===0)return;let{ucl:b,lcl:x,yMin:S,yMax:C}=y(),w=e=>l+e/(v.length-1||1)*d,T=e=>a+(1-(e-S)/(C-S))*f,E=Math.round((i-l)/d*(v.length-1));if(E<0||E>=v.length)return;let D=v.value[E],O=w(E),k=T(D);r.strokeStyle=_,r.lineWidth=1,r.setLineDash([3,3]),r.beginPath(),r.moveTo(O,a),r.lineTo(O,a+f),r.stroke(),r.setLineDash([]);let A=v.subgroup?.(E),j=`${A?`${A}: `:`#${E+1}: `}${vJ(D)}`;r.font=`11px ${X.mono}`;let M=r.measureText(j).width,N=O+8+M>l+d?O-M-10:O+8;r.fillStyle=`rgba(0,0,0,0.75)`,r.fillRect(N-3,k-12,M+6,18),r.fillStyle=D>b||D<x?s4:_,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(j,N,k-11)}let S=(0,Z.useRef)(b);S.current=b;let C=(0,Z.useRef)(null);C.current??=KX(()=>S.current(),()=>c.current);let w=()=>C.current.schedule(),T=()=>{zX(d.current),d.current=RX(x)};return(0,Z.useEffect)(()=>{C.current.now()}),(0,Z.useEffect)(()=>()=>C.current?.cancel(),[]),(0,Z.useEffect)(()=>{l.current=null,w()},[r]),(0,Z.useLayoutEffect)(()=>{let e=c.current;if(!e)return;let t=new WX(()=>{l.current=null,w(),T()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{let e=s.current;if(!e)return;let t=e=>{e.preventDefault(),f.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect();u.current=t.clientX-n.left,T()},r=()=>{u.current=null,T()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),(0,Q.jsxs)(`div`,{ref:c,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`Control chart`}),(0,Q.jsx)(`canvas`,{ref:s,className:`chart-canvas chart-overlay`})]})}var f4={top:32,right:24,bottom:24,left:24},p4=[`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`,`#facc15`,`#60a5fa`],m4=16;function h4(e){return`rgb(${Math.round(255*Math.min(1,Math.max(0,3.5*e-.5)))},${Math.round(255*Math.min(1,Math.max(0,e<.5?2*e:2-2*e)))},${Math.round(255*Math.min(1,Math.max(0,1.5-3.5*e)))})`}function g4(e,t,n,r){let i=Math.min(t,e.columns.length),a=e.columns.slice(0,i).map(t=>{let n=1/0,r=-1/0;for(let i=0;i<e.length;i++){let e=t[i];e<n&&(n=e),e>r&&(r=e)}if(!Number.isFinite(n))return{lo:0,hi:1};let i=(r-n)*.05||.5;return{lo:n-i,hi:r+i}}),o={lo:0,hi:1},s=new Int32Array(e.length),c=[r];if(n&&e.colorValue){let t=e.colorValue,n=1/0,r=-1/0;for(let i=0;i<e.length;i++)t[i]<n&&(n=t[i]),t[i]>r&&(r=t[i]);Number.isFinite(n)&&(o={lo:n,hi:r}),c=Array.from({length:m4},(e,t)=>h4((t+.5)/m4));for(let n=0;n<e.length;n++){let e=(t[n]-o.lo)/(o.hi-o.lo||1);s[n]=t[n]===t[n]?Math.max(0,Math.min(m4-1,Math.floor(e*m4))):-1}for(let t=0;t<e.length;t++)s[t]<0&&(s[t]=0)}else if(!n&&e.colorIndex){c=p4;for(let t=0;t<e.length;t++)s[t]=Math.max(0,e.colorIndex[t])%p4.length}let l=new Int32Array(c.length);for(let t=0;t<e.length;t++)l[s[t]]++;let u=c.map((e,t)=>({color:e,x:new Float64Array(l[t]*i),y:new Float64Array(l[t]*i),starts:new Uint8Array(l[t]*i)})),d=new Int32Array(c.length);for(let t=0;t<e.length;t++){let n=u[s[t]],r=d[s[t]]++*i;n.starts[r]=1;for(let o=0;o<i;o++,r++){let i=a[o];n.x[r]=o,n.y[r]=(e.columns[o][t]-i.lo)/(i.hi-i.lo)}}return{k:i,extents:a,colorExt:o,groups:u.filter(e=>e.x.length>0)}}function _4({rows:e,axes:t,color:n=`#64748b`,colorByNumeric:r=!1,backgroundToken:i=``,onPlotContextMenu:a}){let o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(null),u=(0,Z.useRef)(null),d=(0,Z.useRef)(null),f=(0,Z.useRef)(null),p=(0,Z.useRef)(0),m=(0,Z.useRef)(a);(0,Z.useLayoutEffect)(()=>{m.current=a},[a]);let h=(0,Z.useMemo)(()=>g4(e,t.length,r,n),[e,t.length,r,n]),g=(0,Z.useRef)({rows:e,axes:t,colorByNumeric:r,model:h});(0,Z.useLayoutEffect)(()=>{g.current={rows:e,axes:t,colorByNumeric:r,model:h}},[e,t,r,h]);let _=y0(s),v=(0,Z.useRef)(null);function y(){if(d.current)return d.current;let e=u.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return d.current=n,n}function b(){let e=u.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function x(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function S(){let e=o.current;if(!e)return;let{w:t,h:n}=b(),r=x(e,t,n);if(!r)return;let i=c.current?x(c.current,t,n):null;i?.clearRect(0,0,t,n);let a=i??r,{top:s,right:l,bottom:d,left:f}=f4,{bg:p,muted:m}=y(),{rows:h,axes:S,colorByNumeric:C,model:w}=g.current;r.fillStyle=p,r.fillRect(0,0,t,n);let T=_(t,n);if(S.length<2||h.length===0||w.k<2){T?.keep([]),T?.render(),r.fillStyle=m,r.font=`13px ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`Select ≥ 2 axes`,f+8,s+8);return}let E=t-f-l,D=n-s-d,O=w.k,k=Array.from({length:O},(e,t)=>f+t/(O-1)*E),A=(e,t)=>{let n=w.extents[t];return s+(1-(e-n.lo)/(n.hi-n.lo))*D},j=Math.max(.05,Math.min(.7,60/h.length));if(T)v.current!==w&&(w.groups.forEach((e,t)=>T.setLine(`c${t}`,e.x,e.y,M1(e.color,j),1,e.starts)),v.current=w,VX(u.current)),T.keep(w.groups.map((e,t)=>`c${t}`)),T.setView(0,O-1,0,1,{left:f,top:s,width:E,height:D}),T.render();else{r.globalAlpha=j;for(let e of w.groups){r.beginPath();let t=!1;for(let n=0;n<e.x.length;n++){let i=e.y[n];if(e.starts[n]&&(t=!1),i!==i){t=!1;continue}let a=f+e.x[n]/(O-1)*E,o=s+(1-i)*D;t?r.lineTo(a,o):(r.moveTo(a,o),t=!0)}r.strokeStyle=e.color,r.lineWidth=1,r.stroke()}r.globalAlpha=1}a.strokeStyle=m,a.lineWidth=1.5;for(let e=0;e<O;e++)a.beginPath(),a.moveTo(k[e],s),a.lineTo(k[e],s+D),a.stroke();a.fillStyle=m,a.font=`9px ${X.mono}`;for(let e=0;e<O;e++){let t=w.extents[e];for(let n of[0,.25,.5,.75,1]){let r=t.lo+n*(t.hi-t.lo),i=A(r,e);a.beginPath(),a.moveTo(k[e]-3,i),a.lineTo(k[e]+3,i),a.stroke(),a.textAlign=e===O-1?`left`:`right`,a.textBaseline=`middle`,a.fillText(_J(r,(t.hi-t.lo)/4),k[e]+(e===O-1?5:-5),i)}a.font=`10px ${X.mono}`,a.textAlign=`center`,a.textBaseline=`bottom`,a.fillText(S[e],k[e],s-4)}let M=h.colorLabels??[];if(!C&&M.length>0&&M.length<=10){let e=f,t=s+D+8;a.font=`9px ${X.mono}`,a.textBaseline=`top`,M.forEach((n,r)=>{a.fillStyle=p4[r%p4.length],a.fillRect(e,t,10,8),a.fillStyle=m,a.textAlign=`left`,a.fillText(n,e+13,t),e+=a.measureText(n).width+26,e>f+E-40&&(e=f,t+=12)})}}function C(){let e=l.current;if(!e)return;let{w:t,h:n}=b(),r=x(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=f.current;if(i===null)return;let{top:a,right:o,bottom:s,left:c}=f4,{axes:u}=g.current;if(u.length<2)return;let d=t-c-o,p=c+i/(u.length-1)*d;r.strokeStyle=`rgba(255,255,255,0.6)`,r.lineWidth=2,r.beginPath(),r.moveTo(p,a-4),r.lineTo(p,a+(n-a-s)+4),r.stroke()}let w=(0,Z.useRef)(S);w.current=S;let T=(0,Z.useRef)(null);T.current??=KX(()=>w.current(),()=>u.current);let E=()=>T.current.schedule(),D=()=>{zX(p.current),p.current=RX(C)};return(0,Z.useEffect)(()=>{T.current.now()}),(0,Z.useEffect)(()=>()=>T.current?.cancel(),[]),(0,Z.useEffect)(()=>{d.current=null,E()},[i]),(0,Z.useLayoutEffect)(()=>{let e=u.current;if(!e)return;let t=new WX(()=>{d.current=null,E(),D()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{let e=l.current;if(!e)return;let t=e=>{e.preventDefault(),m.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),{axes:r}=g.current;if(r.length<2)return;let i=n.width-f4.left-f4.right,a=r.length,o=t.clientX-n.left-f4.left,s=Math.round(o/i*(a-1));f.current=Math.abs(o-s/(a-1)*i)<20&&s>=0&&s<a?s:null,D()},r=()=>{f.current=null,D()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),(0,Q.jsxs)(`div`,{ref:u,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`Parallel coordinates`}),(0,Q.jsx)(`canvas`,{ref:s,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),(0,Q.jsx)(`canvas`,{ref:c,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),(0,Q.jsx)(`canvas`,{ref:l,className:`chart-canvas chart-overlay`})]})}function v4(e,t,n,r,i,a){let o=Math.max(1,Math.ceil(t/r)),s=Math.max(1,Math.ceil(n/r)),c=e=>{let s=i(e),c=a(e);return s>=0&&s<t&&c>=0&&c<n?Math.floor(c/r)*o+Math.floor(s/r):-1},l=new Uint32Array(o*s+1);for(let t=0;t<e;t++){let e=c(t);e>=0&&l[e+1]++}for(let e=0;e<o*s;e++)l[e+1]+=l[e];let u=l.slice(0,o*s),d=new Uint32Array(l[o*s]);for(let t=0;t<e;t++){let e=c(t);e>=0&&(d[u[e]++]=t)}return{cell:r,nx:o,ny:s,start:l,ix:d}}function y4(e,t,n,r,i,a,o){let s=Math.floor(t/e.cell),c=Math.floor(n/e.cell),l=-1,u=r*r;for(let r=c-1;r<=c+1;r++)if(!(r<0||r>=e.ny))for(let c=s-1;c<=s+1;c++){if(c<0||c>=e.nx)continue;let s=r*e.nx+c;for(let r=e.start[s];r<e.start[s+1];r++){let s=e.ix[r],c=(i(s)-t)**2+(a(s)-n)**2;c<u&&(!o||c<o(s)**2)&&(u=c,l=s)}}return l<0?null:l}var b4={top:16,right:16,bottom:16,left:16},x4=[`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`,`#facc15`,`#60a5fa`];function S4(e){return[Math.round(255*Math.min(1,Math.max(0,3.5*e-.5))),Math.round(255*Math.min(1,Math.max(0,e<.5?2*e:2-2*e))),Math.round(255*Math.min(1,Math.max(0,1.5-3.5*e)))]}function C4(e){let[t,n,r]=S4(e);return`rgb(${t},${n},${r})`}var w4=(()=>{let e=new Uint8Array(1024);for(let t=0;t<256;t++)e.set([...S4(t/255),255],t*4);return e})(),T4=(()=>{let e=new Uint8Array(1024);for(let t=0;t<256;t++){let[n,r,i]=M1(x4[t%x4.length],1);e.set([n*255,r*255,i*255,255],t*4)}return e});function E4(e,t){let n=1/0,r=-1/0,i=1/0,a=-1/0;for(let t=0;t<e.length;t++){let o=e.x[t],s=e.y[t];o<n&&(n=o),o>r&&(r=o),s<i&&(i=s),s>a&&(a=s)}let o=!Number.isFinite(n)||!Number.isFinite(i)?{xLo:-1,xHi:1,yLo:-1,yHi:1}:(()=>{let e=(r-n)*.05||.5,t=(a-i)*.05||.5;return{xLo:n-e,xHi:r+e,yLo:i-t,yHi:a+t}})(),s={lo:0,hi:1},c=null,l=`single`;if(t&&e.colorValue){let t=e.colorValue,n=1/0,r=-1/0;for(let i=0;i<e.length;i++){let e=t[i];e<n&&(n=e),e>r&&(r=e)}Number.isFinite(n)&&(s={lo:n,hi:r}),c=new Float32Array(e.length);let i=s.hi-s.lo;for(let n=0;n<e.length;n++)c[n]=t[n]===t[n]?Math.max(0,Math.min(1,i>0?(t[n]-s.lo)/i:.5)):0;l=`colormap`}else !t&&e.colorIndex&&(c=Float32Array.from(e.colorIndex,e=>e>=0?e%256:0),l=`dataset`);return{ext:o,colorExt:s,key:c,mode:l}}function D4({points:e,color:t=`#64748b`,colorByNumeric:n=!1,pointSize:r=4,backgroundToken:i=``,onPlotContextMenu:a}){let o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(null),u=(0,Z.useRef)(null),d=(0,Z.useRef)(null),f=(0,Z.useRef)(0),p=(0,Z.useRef)(a);(0,Z.useLayoutEffect)(()=>{p.current=a},[a]);let m=(0,Z.useMemo)(()=>E4(e,n),[e,n]),h=(0,Z.useRef)({points:e,color:t,colorByNumeric:n,pointSize:r,model:m});(0,Z.useLayoutEffect)(()=>{h.current={points:e,color:t,colorByNumeric:n,pointSize:r,model:m}},[e,t,n,r,m]);let g=(0,Z.useRef)({r:null,failed:!1,size:``,model:null,style:``});(0,Z.useEffect)(()=>()=>{g.current.r?.dispose(),g.current.r=null},[]);function _(){if(u.current)return u.current;let e=l.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return u.current=n,n}function v(){let e=l.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function y(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function b(e,t){let{top:n,right:r,bottom:i,left:a}=b4,o=e-a-r,s=t-n-i,c=h.current.model.ext;return{xToPx:e=>a+(e-c.xLo)/(c.xHi-c.xLo)*o,yToPx:e=>n+(1-(e-c.yLo)/(c.yHi-c.yLo))*s,plotW:o,plotH:s,ext:c}}function x(e,t){let n=g.current;!n.r&&!n.failed&&s.current&&(n.r=dX(s.current,k$),n.failed=!n.r);let r=n.r;if(!r||!s.current)return null;let i=Math.min(2,window.devicePixelRatio||1),a=`${e}x${t}@${i}`;n.size!==a&&(r.resize(e,t,i),s.current.style.width=`${e}px`,s.current.style.height=`${t}px`,n.size=a);let{points:o,model:c,color:u,pointSize:d}=h.current;n.model!==c&&(r.setData(o.x,o.y,c.key??void 0),n.model=c,VX(l.current));let f=`${c.mode}|${u}|${d}`;return n.style!==f&&(r.setStyle(c.mode===`single`?{kind:`single`,rgba:M1(u,1)}:{kind:c.mode,palette:c.mode===`colormap`?w4:T4()},d,.8),r.setDraw(!0,!1,0),n.style=f),r}function S(){let e=o.current;if(!e)return;let{w:t,h:n}=v(),r=y(e,t,n);if(!r)return;let{bg:i,muted:a}=_(),{points:s,color:c,colorByNumeric:l,pointSize:u,model:d}=h.current;r.fillStyle=i,r.fillRect(0,0,t,n);let f=x(t,n);if(s.length===0){f?.setData([],[]),g.current.model=null,f?.render(),r.fillStyle=a,r.font=`13px ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,MY(r);return}let p=d.colorExt,{xToPx:m,yToPx:S,plotW:C,plotH:w,ext:T}=b(t,n);if(f)f.setView(T.xLo,T.xHi,T.yLo,T.yHi,{left:b4.left,top:b4.top,width:C,height:w}),f.render();else{for(let e=0;e<s.length;e++){let t=s.x[e],n=s.y[e];if(t!==t||n!==n)continue;let i=d.key?.[e]??0;r.beginPath(),r.arc(m(t),S(n),u,0,Math.PI*2),r.fillStyle=d.mode===`colormap`?C4(i):d.mode===`dataset`?x4[i%x4.length]:c,r.globalAlpha=.8,r.fill()}r.globalAlpha=1}if(l){let e=Math.min(120,Math.floor((n-b4.top-b4.bottom)*.4)),i=t-b4.right-12,o=b4.top+8;for(let t=0;t<e;t++)r.fillStyle=C4(1-t/(e-1)),r.fillRect(i,o+t,8,1);r.fillStyle=a,r.font=`9px ${X.mono}`,r.textAlign=`left`,r.textBaseline=`middle`;let s=e=>Math.abs(e)>=1e4||Math.abs(e)<.001&&e!==0?e.toExponential(1):String(parseFloat(e.toPrecision(3)));r.fillText(s(p.hi),i+10,o),r.fillText(s(p.lo),i+10,o+e)}let E=s.colorLabels??[];if(!l&&E.length>0&&E.length<=10){let e=b4.left,i=n-b4.bottom-10;r.font=`9px ${X.mono}`,r.textBaseline=`top`,E.forEach((n,o)=>{e>t-b4.right-60&&(e=b4.left,i-=14),r.fillStyle=x4[o%x4.length],r.beginPath(),r.arc(e+4,i+4,4,0,Math.PI*2),r.fill(),r.fillStyle=a,r.textAlign=`left`,r.fillText(n,e+10,i),e+=r.measureText(n).width+20})}}function C(){let e=c.current;if(!e)return;let{w:t,h:n}=v(),r=y(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=d.current;if(i===null)return;let{points:a,pointSize:o}=h.current;if(i<0||i>=a.length)return;let{xToPx:s,yToPx:l}=b(t,n),u=a.x[i],f=a.y[i],p=s(u),m=l(f);r.beginPath(),r.arc(p,m,o+3,0,Math.PI*2),r.strokeStyle=`rgba(255,255,255,0.9)`,r.lineWidth=2,r.stroke();let g=[],_=a.label?.(i);_&&g.push(_);let x=a.colorIndex?.[i];x!==void 0&&x>=0&&a.colorLabels?g.push(a.colorLabels[x]):a.colorValue&&g.push(a.colorValue[i].toFixed(3)),g.push(`(${u.toFixed(3)}, ${f.toFixed(3)})`);let S=g.join(` · `);r.font=`11px ${X.mono}`;let C=r.measureText(S).width,w=Math.max(4,Math.min(t-C-8,p+10)),T=m-20<b4.top?m+10:m-20;r.fillStyle=`rgba(0,0,0,0.75)`,r.fillRect(w-3,T-3,C+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(S,w,T)}let w=(0,Z.useRef)(S);w.current=S;let T=(0,Z.useRef)(null);T.current??=KX(()=>w.current(),()=>l.current);let E=()=>T.current.schedule(),D=()=>{zX(f.current),f.current=RX(C)};return(0,Z.useEffect)(()=>{T.current.now()}),(0,Z.useEffect)(()=>()=>T.current?.cancel(),[]),(0,Z.useEffect)(()=>{u.current=null,E()},[i]),(0,Z.useLayoutEffect)(()=>{let e=l.current;if(!e)return;let t=new WX(()=>{u.current=null,E(),D()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{let e=c.current;if(!e)return;let t=null,n=e=>{e.preventDefault(),p.current?.({clientX:e.clientX,clientY:e.clientY})},r=n=>{let r=e.getBoundingClientRect(),{points:i,pointSize:a,model:o}=h.current,{w:s,h:c}=v(),{xToPx:l,yToPx:u,plotW:f,plotH:p}=b(s,c),m=e=>l(i.x[e])-b4.left,g=e=>u(i.y[e])-b4.top,_=a+8,y=`${s}|${c}|${_}`;(!t||t.model!==o||t.key!==y)&&(t={model:o,key:y,g:v4(i.length,f,p,_,m,g)}),d.current=y4(t.g,n.clientX-r.left-b4.left,n.clientY-r.top-b4.top,_,m,g),D()},i=()=>{d.current=null,D()};return e.addEventListener(`contextmenu`,n),e.addEventListener(`mousemove`,r),e.addEventListener(`mouseleave`,i),()=>{e.removeEventListener(`contextmenu`,n),e.removeEventListener(`mousemove`,r),e.removeEventListener(`mouseleave`,i)}},[]),(0,Q.jsxs)(`div`,{ref:l,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`Embedding / scatter`}),(0,Q.jsx)(`canvas`,{ref:s,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),(0,Q.jsx)(`canvas`,{ref:c,className:`chart-canvas chart-overlay`})]})}var O4={top:8,right:8,bottom:8,left:8},k4=20,A4=[`#f97316`,`#fb923c`,`#fdba74`,`#fbbf24`,`#fcd34d`,`#4ade80`,`#34d399`,`#38bdf8`,`#818cf8`,`#a78bfa`];function j4(e){let t=new Map;for(let n of e){let e=n.parent??``;t.has(e)||t.set(e,[]),t.get(e).push(n)}function n(r,i){let a=(t.get(r)??[]).map(e=>n(e.name,i+1)),o=e.find(e=>e.name===r),s=a.reduce((e,t)=>e+t.value,0);return{name:r,value:o?Math.max(o.value,s):s,children:a,depth:i,x0:0,x1:1}}let r=new Set(e.map(e=>e.name)),i=e.filter(e=>!e.parent||!r.has(e.parent)).map(e=>n(e.name,0)),a=i.reduce((e,t)=>e+t.value,0)||1;function o(e,t,n){e.x0=t,e.x1=n;let r=n-t,i=t;for(let t of e.children){let n=t.value/e.value*r;o(t,i,i+n),i+=n}}let s=0;for(let e of i){let t=e.value/a;o(e,s,s+t),s+=t}return i}function M4(e){let t=[];function n(e){t.push(e);for(let t of e.children)n(t)}for(let t of e)n(t);return t}function N4(e){let t=0;function n(e){e.depth>t&&(t=e.depth);for(let t of e.children)n(t)}for(let t of e)n(t);return t}function P4(e){return A4[e%A4.length]}function F4({nodes:e,direction:t=`bottomup`,backgroundToken:n=``,onPlotContextMenu:r}){let i=(0,Z.useRef)(null),a=(0,Z.useRef)(null),o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(0),u=(0,Z.useRef)(r);(0,Z.useLayoutEffect)(()=>{u.current=r},[r]);let d=(0,Z.useRef)({nodes:e,direction:t});(0,Z.useLayoutEffect)(()=>{d.current={nodes:e,direction:t}},[e,t]);let f=(0,Z.useMemo)(()=>{let t=j4(e);return{roots:t,flat:M4(t),numRows:N4(t)+1}},[e]),p=(0,Z.useRef)(f);(0,Z.useLayoutEffect)(()=>{p.current=f},[f]);function m(){if(s.current)return s.current;let e=o.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return s.current=n,n}function h(){let e=o.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function g(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function _(e,t,n,r,i){let a=O4.left+e.x0*t,o=(e.x1-e.x0)*t;return{x:a,y:i===`topdown`?O4.top+e.depth*k4:O4.top+n-(e.depth+1)*k4,w:o,h:k4-1}}function v(){let e=i.current;if(!e)return;let{w:t,h:n}=h(),r=g(e,t,n);if(!r)return;let{bg:a,muted:o}=m(),{nodes:s,direction:c}=d.current;if(r.fillStyle=a,r.fillRect(0,0,t,n),s.length===0){r.fillStyle=o,r.font=`13px ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,MY(r);return}let{flat:l,numRows:u}=p.current,f=t-O4.left-O4.right,v=u*k4;for(let e of l){let t=_(e,f,v,u,c);if(!(t.w<1)&&(r.fillStyle=P4(e.depth),r.fillRect(t.x,t.y,t.w,t.h),t.w>24)){r.fillStyle=`rgba(0,0,0,0.75)`,r.font=`${Math.min(11,k4-4)}px ${X.mono}`,r.textAlign=`left`,r.textBaseline=`middle`;let n=e.name,i=Math.floor((t.w-4)/7),a=n.length>i?n.slice(0,i-1)+`…`:n;r.fillText(a,t.x+3,t.y+k4/2)}}}function y(){let e=a.current;if(!e)return;let{w:t,h:n}=h(),r=g(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=c.current;if(!i)return;let{direction:o}=d.current,{roots:s,numRows:l}=p.current;if(s.length===0)return;let u=_(i,t-O4.left-O4.right,l*k4,l,o);r.strokeStyle=`rgba(255,255,255,0.9)`,r.lineWidth=2,r.strokeRect(u.x+1,u.y+1,u.w-2,u.h-2);let f=`${i.name} (${i.value.toLocaleString()})`;r.font=`11px ${X.mono}`;let m=r.measureText(f).width,v=Math.max(4,Math.min(t-m-8,u.x+u.w/2-m/2)),y=u.y<30?u.y+k4+4:u.y-20;r.fillStyle=`rgba(0,0,0,0.8)`,r.fillRect(v-3,y-3,m+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(f,v,y)}let b=(0,Z.useRef)(v);b.current=v;let x=(0,Z.useRef)(null);x.current??=KX(()=>b.current(),()=>o.current);let S=()=>x.current.schedule(),C=()=>{zX(l.current),l.current=RX(y)};return(0,Z.useEffect)(()=>{x.current.now()}),(0,Z.useEffect)(()=>()=>x.current?.cancel(),[]),(0,Z.useEffect)(()=>{s.current=null,S()},[n]),(0,Z.useLayoutEffect)(()=>{let e=o.current;if(!e)return;let t=new WX(()=>{s.current=null,S(),C()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{let e=a.current;if(!e)return;let t=e=>{e.preventDefault(),u.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),{direction:r}=d.current,{roots:i,flat:a,numRows:o}=p.current;if(i.length===0){c.current=null,C();return}let s=t.clientX-n.left,l=t.clientY-n.top,u=n.width-O4.left-O4.right,f=o*k4,m=null;for(let e of a){let t=_(e,u,f,o,r);if(s>=t.x&&s<=t.x+t.w&&l>=t.y&&l<=t.y+t.h){m=e;break}}c.current=m,C()},r=()=>{c.current=null,C()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),(0,Q.jsxs)(`div`,{ref:o,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:i,className:`chart-canvas`,role:`img`,"aria-label":`Flame graph`}),(0,Q.jsx)(`canvas`,{ref:a,className:`chart-canvas chart-overlay`})]})}var I4={top:24,right:24,bottom:52,left:56},L4=[`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`,`#facc15`,`#60a5fa`],R4=.8;function z4(e,t,n,r){let i,a,o;if(t)a=t.length,i=t.values,o=e=>String(e+1);else{let t=e??[];a=t.length,i=Array.from({length:n},(e,n)=>Float64Array.from(t,e=>e.values[n]??0)),o=e=>t[e].label}let s=0,c=0;if(r===`stacked`)for(let e=0;e<a;e++){let t=0,n=0;for(let r of i){let i=r[e];i>0?t+=i:i<0&&(n+=i)}t>c&&(c=t),n<s&&(s=n)}else for(let e of i)for(let t=0;t<a;t++){let n=e[t];n>c&&(c=n),n<s&&(s=n)}return c===s&&(c=s+1),{n:a,values:i,label:o,lo:s,hi:c}}function B4(e,t,n){let r=e.values.length,i=[],a=[],o=[],s=[],c=[],l=(e,t,n,r,l)=>{i.push(e),a.push(t),o.push(n),s.push(r),c.push(l)};if(e.n<=n)for(let n=0;n<e.n;n++)if(t===`grouped`){let t=.8/r;for(let i=0;i<r;i++){let r=e.values[i][n];r===r&&l(n-.4+i*t,n-.4+(i+1)*t-t*.05,0,r,i)}}else{let t=0,i=0;for(let a=0;a<r;a++){let r=e.values[a][n];r!==r||r===0||(r>0?(l(n-.4,n+.4,t,t+r,a),t+=r):(l(n-.4,n+.4,i,i+r,a),i+=r))}}else{let i=e.n/n,a=new Float64Array(r),o=new Float64Array(r);for(let s=0;s<n;s++){let n=Math.floor(s*i),c=Math.min(e.n,Math.floor((s+1)*i));if(!(c<=n)){a.fill(0),o.fill(0);for(let i=n;i<c;i++){let n=0,s=0;for(let c=0;c<r;c++){let r=e.values[c][i];r===r&&(t===`stacked`?r>0?(n+=r,n>o[c]&&(o[c]=n)):(s+=r,s<a[c]&&(a[c]=s)):(r>o[c]&&(o[c]=r),r<a[c]&&(a[c]=r)))}}for(let e=t===`stacked`?r-1:0;t===`stacked`?e>=0:e<r;t===`stacked`?e--:e++)(o[e]!==0||a[e]!==0)&&l(n-.5,c-.5,a[e],o[e],e)}}}return{x0:Float64Array.from(i),x1:Float64Array.from(a),y0:Float64Array.from(o),y1:Float64Array.from(s),k:Float64Array.from(c)}}function V4({groups:e,columns:t,seriesNames:n,colors:r,mode:i=`grouped`,horizontal:a=!1,valueRange:o,backgroundToken:s=``,onPlotContextMenu:c}){let l=IZ(),u=(0,Z.useRef)(null),d=(0,Z.useRef)(null),f=(0,Z.useRef)(null),p=(0,Z.useRef)(null),m=(0,Z.useRef)(null),h=(0,Z.useRef)(null),g=(0,Z.useRef)(0),_=(0,Z.useRef)(c);(0,Z.useLayoutEffect)(()=>{_.current=c},[c]);let v=(0,Z.useRef)(null),y=(0,Z.useMemo)(()=>{let r=[e,i,n.length,t?.length,...t?.values??[]],a=v.current;if(a&&a.key.length===r.length&&a.key.every((e,t)=>e===r[t]))return a.value;let o=z4(e,t,n.length,i);return v.current={key:r,value:o},o},[e,t,n.length,i]),b=(0,Z.useRef)({bars:y,seriesNames:n,colors:r,mode:i,horizontal:a,valueRange:o});(0,Z.useLayoutEffect)(()=>{b.current={bars:y,seriesNames:n,colors:r,mode:i,horizontal:a,valueRange:o}},[y,n,r,i,a,o]);let x=(0,Z.useRef)({plot:null,failed:!1,key:``,data:null,size:``});(0,Z.useEffect)(()=>()=>{x.current.plot?.dispose(),x.current.plot=null},[]);let S=(0,Z.useRef)({bars:null,view:``});function C(){if(m.current)return m.current;let e=p.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return m.current=n,n}function w(){let e=p.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||300)}}function T(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function E(e){let t=b.current.colors??[];return Array.from({length:e},(e,n)=>t[n]??L4[n%L4.length])}function D(e,t){let{bars:n,valueRange:r}=b.current,i=n.lo,a=n.hi;r?.min!==void 0&&Number.isFinite(r.min)&&(i=r.min),r?.max!==void 0&&Number.isFinite(r.max)&&(a=r.max);let o=j$(I4,e,t),{top:s,right:c,bottom:l,left:u}=o;return{lo:i,hi:a,top:s,left:u,plotW:e-u-c,plotH:t-s-l,tiny:o.tiny}}function O(e,t){let n=x.current;if(!n.plot&&!n.failed&&d.current&&(n.plot=dX(d.current,v0),n.failed=!n.plot),!n.plot||!d.current)return null;let r=Math.min(2,window.devicePixelRatio||1),i=`${e}x${t}@${r}`;return n.size!==i&&(n.plot.resize(e,t,r),d.current.style.width=`${e}px`,d.current.style.height=`${t}px`,n.size=i),n.plot}function k(){let e=u.current;if(!e)return;let{w:t,h:n}=w(),r=T(e,t,n);if(!r)return;let{bg:i,muted:a,grid:o}=C(),{bars:s,seriesNames:c,mode:d,horizontal:f}=b.current;r.fillStyle=i,r.fillRect(0,0,t,n);let m=O(t,n);if(s.n===0||c.length===0){m?.keep([]),m?.render(),r.fillStyle=a,r.font=`13px ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,MY(r);return}let{lo:h,hi:g,top:_,left:v,plotW:y,plotH:k,tiny:A}=D(t,n),j=E(c.length),M=f?k:y,N=e=>f?v+(e-h)/(g-h)*y:_+k-(e-h)/(g-h)*k,P=e=>(f?_:v)+(e+.5)/s.n*M;l({left:v,top:_,width:y,height:k,...f?{x:{v0:h,v1:g}}:{y:{v0:h,v1:g}}}),r.strokeStyle=o,r.lineWidth=1;for(let e=0;e<=5;e++){let t=h+e/5*(g-h),n=N(t);r.beginPath(),f?(r.moveTo(n,_),r.lineTo(n,_+k)):(r.moveTo(v,n),r.lineTo(v+y,n)),r.stroke(),r.fillStyle=a,r.font=`9px ${X.mono}`,!A&&(f?(r.textAlign=`center`,r.textBaseline=`top`,r.fillText(_J(t,(g-h)/5),n,_+k+4)):(r.textAlign=`right`,r.textBaseline=`middle`,r.fillText(_J(t,(g-h)/5),v-4,n)))}let F=`${h}|${g}|${f}`;(S.current.bars!==s||S.current.view!==F)&&(S.current={bars:s,view:F},VX(p.current));let I=Math.min(2,window.devicePixelRatio||1),L=Math.max(1,Math.round(M*I)),R=j.map(e=>{let t=qY(e);return[t[0],t[1],t[2],R4]}),z={left:v,top:_,width:y,height:k};if(m){let e=`${d}|${f}|${L}|${j.join(`,`)}`;if(x.current.key!==e||x.current.data!==s){let t=B4(s,d,L);f?m.setRects(`bars`,t.y0,t.y1,t.x0,t.x1,R,t.k):m.setRects(`bars`,t.x0,t.x1,t.y0,t.y1,R,t.k),m.keep([`bars`]),x.current.key=e,x.current.data=s}f?m.setView(h,g,s.n-.5,-.5,z):m.setView(-.5,s.n-.5,h,g,z),m.render()}else{let e=B4(s,d,L);r.globalAlpha=R4;for(let t=0;t<e.x0.length;t++){r.fillStyle=j[e.k[t]];let n=P(e.x0[t]-.5),i=P(e.x1[t]-.5),a=N(e.y0[t]),o=N(e.y1[t]);f?r.fillRect(Math.min(a,o),n,Math.max(1,Math.abs(o-a)),Math.max(1,i-n)):r.fillRect(n,Math.min(a,o),Math.max(1,i-n),Math.max(1,Math.abs(o-a)))}r.globalAlpha=1}if(h<0&&g>0){let e=N(0);r.strokeStyle=a,r.lineWidth=1.5,r.beginPath(),f?(r.moveTo(e,_),r.lineTo(e,_+k)):(r.moveTo(v,e),r.lineTo(v+y,e)),r.stroke()}r.fillStyle=a,r.font=`9px ${X.mono}`;let B=Math.max(1,Math.ceil(s.n/Math.max(1,Math.floor(M/(f?14:48)))));for(let e=0;e<(A?0:s.n);e+=B){let t=P(e),n=s.label(e),i=n.length>14?n.slice(0,13)+`…`:n;f?(r.textAlign=`right`,r.textBaseline=`middle`,r.fillText(i,v-4,t)):(r.textAlign=`center`,r.textBaseline=`top`,r.fillText(i,t,_+k+4))}if(c.length>1&&!A){let e=f?_-14:_+k+32,t=v;r.font=`9px ${X.mono}`,r.textBaseline=`top`;for(let n=0;n<c.length&&(r.fillStyle=j[n],r.fillRect(t,e,10,8),r.fillStyle=a,r.textAlign=`left`,r.fillText(c[n],t+13,e),t+=r.measureText(c[n]).width+26,!(t>v+y-30));n++);}}function A(){let e=f.current;if(!e)return;let{w:t,h:n}=w(),r=T(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=h.current,{bars:a,seriesNames:o,horizontal:s}=b.current;if(i===null||i>=a.n)return;let{top:c,left:l,plotW:u,plotH:d}=D(t,n),p=s?d:u,m=(s?c:l)+(i+.5)/a.n*p,g=Math.max(1,p/a.n);r.fillStyle=`rgba(255,255,255,0.08)`,s?r.fillRect(l,m-g/2,u,g):r.fillRect(m-g/2,c,g,d);let _=a.values.map((e,t)=>`${o.length>1?o[t]+` `:``}${vJ(e[i])}`).join(` `),v=`${a.label(i)}: ${_}`;r.font=`11px ${X.mono}`;let y=r.measureText(v).width,x=s?l+u/2:m,S=s?m:c+d/2,C=Math.max(4,Math.min(t-y-8,x-y/2)),E=S-28<c?S+10:S-24;r.fillStyle=`rgba(0,0,0,0.8)`,r.fillRect(C-3,E-3,y+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(v,C,E)}let j=(0,Z.useRef)(k);j.current=k;let M=(0,Z.useRef)(null);M.current??=KX(()=>j.current(),()=>p.current);let N=()=>{g.current||=RX(()=>{g.current=0,A()})};return(0,Z.useEffect)(()=>{M.current.now()},[y,n,r,i,a,o]),(0,Z.useEffect)(()=>()=>{M.current?.cancel(),zX(g.current)},[]),(0,Z.useEffect)(()=>{m.current=null,M.current.schedule()},[s]),(0,Z.useLayoutEffect)(()=>{let e=p.current;if(!e)return;let t=new WX(()=>{m.current=null,M.current.schedule(),N()});return t.observe(e),()=>t.disconnect()},[]),(0,Z.useLayoutEffect)(()=>{let e=f.current;if(!e)return;let t=e=>{e.preventDefault(),_.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),{bars:r,horizontal:i}=b.current,{w:a,h:o}=w(),{top:s,left:c,plotW:l,plotH:u}=D(a,o),d=i?t.clientY-n.top-s:t.clientX-n.left-c,f=i?u:l,p=d>=0&&d<f&&r.n>0?Math.min(r.n-1,Math.floor(d/f*r.n)):null;p!==h.current&&(h.current=p,N())},r=()=>{h.current=null,N()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),(0,Q.jsxs)(`div`,{ref:p,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:u,className:`chart-canvas`,role:`img`,"aria-label":`Bar chart`}),(0,Q.jsx)(`canvas`,{ref:d,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),(0,Q.jsx)(`canvas`,{ref:f,className:`chart-canvas chart-overlay`})]})}var H4=[`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`];function U4(e,t){if(!t)return H4[e%H4.length];if(e===0)return t;let n=H4.filter(e=>e.toLowerCase()!==t.toLowerCase());return n[(e-1)%n.length]}var W4={top:36,right:36,bottom:36,left:36};function G4({axes:e,series:t,fill:n=!0,color:r,backgroundToken:i=``,onPlotContextMenu:a}){let o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(null),u=(0,Z.useRef)(a);(0,Z.useLayoutEffect)(()=>{u.current=a},[a]);let d=(0,Z.useRef)({axes:e,series:t,fill:n,color:r});(0,Z.useLayoutEffect)(()=>{d.current={axes:e,series:t,fill:n,color:r}},[e,t,n,r]);function f(){if(l.current)return l.current;let e=c.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return l.current=n,n}function p(){let e=c.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||300)}}function m(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function h(){let e=o.current;if(!e)return;let{w:t,h:n}=p(),r=m(e,t,n);if(!r)return;let{bg:i,muted:a,grid:s}=f(),{axes:c,series:l,fill:u}=d.current;if(r.fillStyle=i,r.fillRect(0,0,t,n),c.length<3||l.length===0){r.fillStyle=a,r.font=`13px ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`Select ≥ 3 axes`,W4.left+8,W4.top+8);return}let h=c.length,g=t/2,_=n/2,v=Math.min(t-W4.left-W4.right,n-W4.top-W4.bottom)/2,y=c.map((e,t)=>{let n=0;for(let e of l){let r=e.values[t]??0;r>n&&(n=r)}return n||1});function b(e){return Math.PI*2*e/h-Math.PI/2}function x(e,t){let n=b(e);return{x:g+Math.cos(n)*v*t,y:_+Math.sin(n)*v*t}}for(let e=1;e<=4;e++){let t=e/4;r.beginPath();for(let e=0;e<h;e++){let n=x(e,t);e===0?r.moveTo(n.x,n.y):r.lineTo(n.x,n.y)}r.closePath(),r.strokeStyle=s,r.lineWidth=1,r.stroke()}r.strokeStyle=a,r.lineWidth=1;for(let e=0;e<h;e++){let t=x(e,1);r.beginPath(),r.moveTo(g,_),r.lineTo(t.x,t.y),r.stroke(),r.fillStyle=a,r.font=`10px ${X.mono}`;let n=b(e),i=x(e,1+10/v);r.textAlign=Math.abs(Math.cos(n))<.1?`center`:Math.cos(n)<0?`right`:`left`,r.textBaseline=Math.abs(Math.sin(n))<.1?`middle`:Math.sin(n)<0?`bottom`:`top`;let o=c[e].length>12?c[e].slice(0,11)+`…`:c[e];r.fillText(o,i.x,i.y)}for(let e=0;e<l.length;e++){let t=l[e],n=U4(e,d.current.color);r.beginPath();for(let e=0;e<h;e++){let n=Math.max(0,Math.min(1,(t.values[e]??0)/y[e])),i=x(e,n);e===0?r.moveTo(i.x,i.y):r.lineTo(i.x,i.y)}r.closePath(),u&&(r.fillStyle=n,r.globalAlpha=.15,r.fill()),r.globalAlpha=1,r.strokeStyle=n,r.lineWidth=1,r.stroke();for(let e=0;e<h;e++){let i=Math.max(0,Math.min(1,(t.values[e]??0)/y[e])),a=x(e,i);r.beginPath(),r.arc(a.x,a.y,3,0,Math.PI*2),r.fillStyle=n,r.globalAlpha=.9,r.fill()}r.globalAlpha=1}if(l.length>1){let e=W4.left,i=n-W4.bottom-10;r.font=`9px ${X.mono}`,r.textBaseline=`top`;for(let n=0;n<l.length&&(r.fillStyle=U4(n,d.current.color),r.fillRect(e,i,10,8),r.fillStyle=a,r.textAlign=`left`,r.fillText(l[n].name,e+13,i),e+=r.measureText(l[n].name).width+26,!(e>t-W4.right-30));n++);}}let g=(0,Z.useRef)(h);g.current=h;let _=(0,Z.useRef)(null);_.current??=KX(()=>g.current(),()=>c.current);let v=()=>_.current.schedule();return(0,Z.useEffect)(()=>{_.current.now()}),(0,Z.useEffect)(()=>()=>_.current?.cancel(),[]),(0,Z.useEffect)(()=>{l.current=null,v()},[i]),(0,Z.useLayoutEffect)(()=>{let e=c.current;if(!e)return;let t=new WX(()=>{l.current=null,v()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{let e=s.current;if(!e)return;let t=e=>{e.preventDefault(),u.current?.({clientX:e.clientX,clientY:e.clientY})};return e.addEventListener(`contextmenu`,t),()=>{e.removeEventListener(`contextmenu`,t)}},[]),(0,Q.jsxs)(`div`,{ref:c,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`Radar chart`}),(0,Q.jsx)(`canvas`,{ref:s,className:`chart-canvas chart-overlay`})]})}var K4={top:16,right:16,bottom:40,left:52},q4=[`#38bdf8`,`#4ade80`,`#fb7185`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`];function J4(e,t){let n=e.length>0&&e.every(t=>t.x===e[0].x||t.x.length===e[0].x.length),r=t&&n,i=e.map(e=>e.x),a=[],o=[],s=null;for(let t of e){if(!r){a.push(t.y),o.push(null);continue}let e=t.x.length,n=new Float64Array(e);for(let r=0;r<e;r++){let e=t.y[r];n[r]=(s?s[r]:0)+(e>0?e:0)}a.push(n),o.push(s??null),s=n}let c=1/0,l=-1/0,u=0,d=0;for(let e of i)for(let t=0;t<e.length;t++){let n=e[t];n<c&&(c=n),n>l&&(l=n)}for(let e of a)for(let t=0;t<e.length;t++){let n=e[t];n<u&&(u=n),n>d&&(d=n)}return Number.isFinite(c)||(c=0,l=1),{x:i,lo:o,hi:a,ascending:i.map(e=>D0(e)),xLo:c,xHi:l,yLo:u,yHi:d}}function Y4({series:e,stacked:t=!1,yRange:n,backgroundToken:r=``,onPlotContextMenu:i}){let a=IZ(),o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(null),u=(0,Z.useRef)(null),d=(0,Z.useRef)(null),f=(0,Z.useRef)(0),p=(0,Z.useRef)(i);(0,Z.useLayoutEffect)(()=>{p.current=i},[i]);let m=(0,Z.useRef)(null),h=(0,Z.useMemo)(()=>{let n=m.current;if(n&&n.stacked===t&&n.series.length===e.length&&n.series.every((t,n)=>t.x===e[n].x&&t.y===e[n].y&&t.name===e[n].name))return n.value;let r=J4(e,t);return m.current={series:e,stacked:t,value:r},r},[e,t]),g=(0,Z.useRef)({series:e,prepared:h,yRange:n});(0,Z.useLayoutEffect)(()=>{g.current={series:e,prepared:h,yRange:n}},[e,h,n]);let _=(0,Z.useRef)({plot:null,failed:!1,key:``,size:``});(0,Z.useEffect)(()=>()=>{_.current.plot?.dispose(),_.current.plot=null},[]);let v=(0,Z.useRef)({prepared:null,view:``});function y(){if(u.current)return u.current;let e=l.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return u.current=n,n}function b(){let e=l.current;return{w:Math.max(1,e?.clientWidth||600),h:Math.max(1,e?.clientHeight||300)}}function x(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function S(e,t){let n=(e.xHi-e.xLo)*.01||.5,r=e.yLo,i=e.yHi;return i===r&&(i=r+1),i+=(i-r)*.05,t?.min!==void 0&&Number.isFinite(t.min)&&(r=t.min),t?.max!==void 0&&Number.isFinite(t.max)&&(i=t.max),{xLo:e.xLo-n,xHi:e.xHi+n,yLo:r,yHi:i}}function C(e,t,n,r,i){let a=e.x[t],o=e.hi[t],s=e.lo[t];if(!e.ascending[t]||a.length<=2*i)return{x:a,hi:o,lo:s??new Float64Array(a.length)};let c=w0(a,o,n,r,i);return{x:E0(a,c),hi:E0(o,c),lo:s?E0(s,c):new Float64Array(c.length)}}function w(){let e=o.current;if(!e)return;let{w:n,h:r}=b(),i=x(e,n,r);if(!i)return;let{bg:s,muted:c,grid:u}=y(),{series:d,prepared:f,yRange:p}=g.current;i.fillStyle=s,i.fillRect(0,0,n,r);let m=_.current.plot;if(d.length===0){m?.keep([]),m?.render(),i.fillStyle=c,i.font=`13px ${X.sans}`,i.textAlign=`left`,i.textBaseline=`top`,MY(i);return}let h=j$(K4,n,r),{top:w,right:D,bottom:O,left:k}=h,A=n-k-D,j=r-w-O,{xLo:M,xHi:N,yLo:P,yHi:F}=S(f,p),I=e=>k+(e-M)/(N-M)*A,L=e=>w+j-(e-P)/(F-P)*j;a({left:k,top:w,width:A,height:j,x:{v0:M,v1:N},y:{v0:P,v1:F}}),i.strokeStyle=u,i.lineWidth=1;for(let e=0;e<=5;e++){let t=P+e/5*(F-P),n=L(t);i.beginPath(),i.moveTo(k,n),i.lineTo(k+A,n),i.stroke(),i.fillStyle=c,i.font=`9px ${X.mono}`,i.textAlign=`right`,i.textBaseline=`middle`,h.tiny||i.fillText(_J(t,(F-P)/5),k-4,n)}let R=Math.min(8,f.x[0]?.length??5);for(let e=0;e<=R;e++){let t=M+e/R*(N-M),n=I(t);i.beginPath(),i.moveTo(n,w),i.lineTo(n,w+j),i.stroke(),i.fillStyle=c,i.font=`9px ${X.mono}`,i.textAlign=`center`,i.textBaseline=`top`,h.tiny||i.fillText(_J(t,(N-M)/R),n,w+j+4)}let z=`${M}|${N}|${P}|${F}`;(v.current.prepared!==f||v.current.view!==z)&&(v.current={prepared:f,view:z},VX(l.current));let B=E(n,r),V=Math.min(2,window.devicePixelRatio||1),ee=Math.max(1,Math.round(A*V)),H=d.map((e,t)=>qY(q4[t%q4.length]));if(B){let e=`${M}|${N}|${ee}`;if(_.current.key!==e||T.current!==f){let n=[];for(let e=0;e<d.length;e++){let r=C(f,e,M,N,ee),i=H[e],a=[i[0],i[1],i[2],f.lo[e]||t?.7:.25];B.setBands(`b${e}`,r.x,r.lo,r.hi,a),B.setLine(`l${e}`,r.x,r.hi,i,1),n.push(`b${e}`,`l${e}`)}B.keep(n),_.current.key=e,T.current=f}B.setView(M,N,P,F,{left:k,top:w,width:A,height:j}),B.render()}else for(let e=0;e<d.length;e++){let n=C(f,e,M,N,ee),r=q4[e%q4.length];i.save(),i.beginPath(),i.rect(k,w,A,j),i.clip(),i.beginPath();for(let e=0;e<n.x.length;e++){let t=I(n.x[e]);e===0?i.moveTo(t,L(n.lo[e])):i.lineTo(t,L(n.lo[e]))}for(let e=n.x.length-1;e>=0;e--)i.lineTo(I(n.x[e]),L(n.hi[e]));i.closePath(),i.fillStyle=r,i.globalAlpha=f.lo[e]||t?.7:.25,i.fill(),i.beginPath();for(let e=0;e<n.x.length;e++){let t=I(n.x[e]),r=L(n.hi[e]);e===0?i.moveTo(t,r):i.lineTo(t,r)}i.globalAlpha=1,i.strokeStyle=r,i.lineWidth=1,i.stroke(),i.restore()}if(d.length>1&&!h.tiny){let e=k,t=w+j+24;i.font=`9px ${X.mono}`,i.textBaseline=`top`;for(let n=0;n<d.length&&(i.fillStyle=q4[n%q4.length],i.fillRect(e,t,10,8),i.fillStyle=c,i.textAlign=`left`,i.fillText(d[n].name,e+13,t),e+=i.measureText(d[n].name).width+26,!(e>k+A-30));n++);}}let T=(0,Z.useRef)(null);function E(e,t){let n=_.current;if(!n.plot&&!n.failed&&s.current&&(n.plot=dX(s.current,v0),n.failed=!n.plot),!n.plot||!s.current)return null;let r=Math.min(2,window.devicePixelRatio||1),i=`${e}x${t}@${r}`;return n.size!==i&&(n.plot.resize(e,t,r),s.current.style.width=`${e}px`,s.current.style.height=`${t}px`,n.size=i),n.plot}function D(){let e=c.current;if(!e)return;let{w:t,h:n}=b(),r=x(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=d.current;if(i===null)return;let{prepared:a,yRange:o}=g.current,{top:s,right:l,left:u,bottom:f}=j$(K4,t,n),p=n-s-f;r.strokeStyle=`rgba(255,255,255,0.4)`,r.lineWidth=1,r.setLineDash([4,4]),r.beginPath(),r.moveTo(i,s),r.lineTo(i,s+p),r.stroke(),r.setLineDash([]);let{xLo:m,xHi:h}=S(a,o),_=t-u-l,v=`x=${vJ(m+(i-u)/_*(h-m))}`;r.font=`11px ${X.mono}`;let y=r.measureText(v).width,C=Math.max(4,Math.min(t-y-8,i-y/2));r.fillStyle=`rgba(0,0,0,0.7)`,r.fillRect(C-3,s-3,y+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(v,C,s)}let O=(0,Z.useRef)(w);O.current=w;let k=(0,Z.useRef)(null);k.current??=KX(()=>O.current(),()=>l.current);let A=()=>{f.current||=RX(()=>{f.current=0,D()})};return(0,Z.useEffect)(()=>{k.current.now()},[e,h,n]),(0,Z.useEffect)(()=>()=>{k.current?.cancel(),zX(f.current)},[]),(0,Z.useEffect)(()=>{u.current=null,k.current.schedule()},[r]),(0,Z.useLayoutEffect)(()=>{let e=l.current;if(!e)return;let t=new WX(()=>{u.current=null,k.current.schedule(),A()});return t.observe(e),()=>t.disconnect()},[]),(0,Z.useLayoutEffect)(()=>{let e=c.current;if(!e)return;let t=e=>{e.preventDefault(),p.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect();d.current=t.clientX-n.left,A()},r=()=>{d.current=null,A()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),(0,Q.jsxs)(`div`,{ref:l,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`Area chart`}),(0,Q.jsx)(`canvas`,{ref:s,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),(0,Q.jsx)(`canvas`,{ref:c,className:`chart-canvas chart-overlay`})]})}var X4={top:16,right:16,bottom:40,left:52},Z4=[`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`];function Q4({series:e,complement:t=!1,logX:n=!1,backgroundToken:r=``,onPlotContextMenu:i}){let a=IZ(),o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(null),u=(0,Z.useRef)(null),d=(0,Z.useRef)(0),f=(0,Z.useRef)(i);(0,Z.useLayoutEffect)(()=>{f.current=i},[i]);let p=(0,Z.useRef)({series:e,complement:t,logX:n});(0,Z.useLayoutEffect)(()=>{p.current={series:e,complement:t,logX:n}},[e,t,n]);let m=(0,Z.useMemo)(()=>{let t=e.map(e=>Float64Array.from(e.values).sort()),n=1/0,r=-1/0;for(let e of t)e.length&&(n=Math.min(n,e[0]),r=Math.max(r,e[e.length-1]));return{all:t,xLo:n,xHi:r}},[e]),h=(0,Z.useRef)(m);(0,Z.useLayoutEffect)(()=>{h.current=m},[m]);function g(){if(l.current)return l.current;let e=c.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return l.current=n,n}function _(){let e=c.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||300)}}function v(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function y(){let e=o.current;if(!e)return;let{w:t,h:n}=_(),r=v(e,t,n);if(!r)return;let{bg:i,muted:s,grid:c}=g(),{series:l,complement:u,logX:d}=p.current;if(r.fillStyle=i,r.fillRect(0,0,t,n),l.length===0){r.fillStyle=s,r.font=`13px ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,MY(r);return}let{top:f,right:m,bottom:y,left:b}=X4,x=t-b-m,S=n-f-y,{xLo:C,xHi:w}=h.current;Number.isFinite(C)||(C=0,w=1);let T=e=>Math.log10(Math.max(1e-10,e)),E=d?T(C):C,D=d?T(w):w,O=e=>b+((d?T(e):e)-E)/(D-E||1)*x,k=e=>f+S-e*S;a({left:b,top:f,width:x,height:S,x:{v0:C,v1:w,log:d}});for(let e=0;e<=5;e++){let t=e/5,n=k(t);r.strokeStyle=c,r.lineWidth=1,r.beginPath(),r.moveTo(b,n),r.lineTo(b+x,n),r.stroke(),r.fillStyle=s,r.font=`9px ${X.mono}`,r.textAlign=`right`,r.textBaseline=`middle`,r.fillText(String(t.toFixed(2)),b-4,n)}for(let e=0;e<=6;e++){let t=C+e/6*(w-C),n=O(t);r.strokeStyle=c,r.lineWidth=1,r.beginPath(),r.moveTo(n,f),r.lineTo(n,f+S),r.stroke(),r.fillStyle=s,r.font=`9px ${X.mono}`,r.textAlign=`center`,r.textBaseline=`top`,r.fillText(_J(t,(w-C)/6),n,f+S+4)}for(let e=0;e<l.length;e++){let t=h.current.all[e],n=t?.length??0;if(n===0)continue;let i=e=>k(u?1-(e+1)/n:(e+1)/n),a=O(t[0]),o=k(+!!u);r.beginPath(),r.moveTo(a,o);for(let e=0;e<n;e++){if(e+1<n&&t[e+1]===t[e])continue;let s=O(t[e]),c=i(e);if(Math.abs(s-a)<.5){o=c;continue}r.lineTo(a,o),r.lineTo(s,o),a=s,o=c}r.lineTo(a,o),r.strokeStyle=Z4[e%Z4.length],r.lineWidth=1,r.stroke()}if(l.length>1){let e=b,t=f+S+24;r.font=`9px ${X.mono}`,r.textBaseline=`top`;for(let n=0;n<l.length&&(r.fillStyle=Z4[n%Z4.length],r.fillRect(e,t,16,2),r.fillStyle=s,r.textAlign=`left`,r.fillText(l[n].name,e+20,t-3),e+=r.measureText(l[n].name).width+30,!(e>b+x-30));n++);}r.save(),r.translate(12,f+S/2),r.rotate(-Math.PI/2),r.fillStyle=s,r.font=`9px ${X.mono}`,r.textAlign=`center`,r.textBaseline=`middle`,r.fillText(u?`CCDF`:`CDF`,0,0),r.restore()}function b(){let e=s.current;if(!e)return;let{w:t,h:n}=_(),r=v(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=u.current;if(i===null)return;let{top:a,left:o,right:c}=X4,l=n-a-X4.bottom,d=t-o-c;r.strokeStyle=`rgba(255,255,255,0.4)`,r.lineWidth=1,r.setLineDash([4,4]),r.beginPath(),r.moveTo(i,a),r.lineTo(i,a+l),r.stroke(),r.setLineDash([]);let{xLo:f,xHi:p}=h.current;if(!Number.isFinite(f))return;let m=vJ(f+(i-o)/d*(p-f));r.font=`11px ${X.mono}`;let g=r.measureText(m).width,y=Math.max(4,Math.min(t-g-8,i-g/2));r.fillStyle=`rgba(0,0,0,0.7)`,r.fillRect(y-3,a+l+2,g+6,16),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(m,y,a+l+4)}let x=(0,Z.useRef)(y);x.current=y;let S=(0,Z.useRef)(null);S.current??=KX(()=>x.current(),()=>c.current);let C=()=>S.current.schedule(),w=()=>{zX(d.current),d.current=RX(b)};return(0,Z.useEffect)(()=>{S.current.now()}),(0,Z.useEffect)(()=>()=>S.current?.cancel(),[]),(0,Z.useEffect)(()=>{l.current=null,C()},[r]),(0,Z.useLayoutEffect)(()=>{let e=c.current;if(!e)return;let t=new WX(()=>{l.current=null,C(),w()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{let e=s.current;if(!e)return;let t=e=>{e.preventDefault(),f.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect();u.current=t.clientX-n.left,w()},r=()=>{u.current=null,w()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),(0,Q.jsxs)(`div`,{ref:c,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`CDF chart`}),(0,Q.jsx)(`canvas`,{ref:s,className:`chart-canvas chart-overlay`})]})}var $4={top:16,right:40,bottom:40,left:52},e3=[`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`,`#facc15`,`#60a5fa`];function t3(e){return[Math.round(255*Math.min(1,Math.max(0,3.5*e-.5))),Math.round(255*Math.min(1,Math.max(0,e<.5?2*e:2-2*e))),Math.round(255*Math.min(1,Math.max(0,1.5-3.5*e)))]}function n3(e){let[t,n,r]=t3(e);return`rgb(${t},${n},${r})`}var r3=(()=>{let e=new Uint8Array(1024);for(let t=0;t<256;t++)e.set([...t3(t/255),255],t*4);return e})(),i3=()=>{let e=new Uint8Array(1024);for(let t=0;t<256;t++){let[n,r,i]=M1(e3[t%e3.length],1);e.set([n*255,r*255,i*255,255],t*4)}return e};function a3(e,t,n){let r=e.length,i=1/0,a=-1/0,o=1/0,s=-1/0,c=1/0,l=-1/0;for(let t=0;t<r;t++){let n=e.x[t],r=e.y[t],u=e.size[t];n<i&&(i=n),n>a&&(a=n),r<o&&(o=r),r>s&&(s=r),u<c&&(c=u),u>l&&(l=u)}let u=Number.isFinite(i)?(()=>{let e=(a-i)*.1||1,t=(s-o)*.1||1;return{xLo:i-e,xHi:a+e,yLo:o-t,yHi:s+t,sLo:c,sHi:l}})():{xLo:-1,xHi:1,yLo:-1,yHi:1,sLo:1,sHi:1},d=u.sHi-u.sLo||1,f=new Float32Array(r);for(let t=0;t<r;t++)f[t]=3+(e.size[t]-u.sLo)/d*(n-3);let p=0,m=1,h=null,g=`single`;if(t&&e.colorValue){let t=e.colorValue,n=1/0,i=-1/0;for(let e=0;e<r;e++)t[e]<n&&(n=t[e]),t[e]>i&&(i=t[e]);Number.isFinite(n)&&(p=n,m=i),h=new Float32Array(r);for(let e=0;e<r;e++)h[e]=t[e]===t[e]?Math.max(0,Math.min(1,(t[e]-p)/(m-p||1))):0;g=`colormap`}else !t&&e.colorIndex&&(h=Float32Array.from(e.colorIndex,e=>e>=0?e%256:0),g=`dataset`);let _=Uint32Array.from({length:r},(e,t)=>t).sort((e,t)=>(f[t]||0)-(f[e]||0)),v=e=>{let t=new Float64Array(r);for(let n=0;n<r;n++)t[n]=e[_[n]];return t};return{ext:u,radius:f,key:h,mode:g,colorLo:p,colorHi:m,drawn:{x:v(e.x),y:v(e.y),r:v(f),k:h?v(h):void 0}}}function o3({points:e,color:t=`#64748b`,colorByNumeric:n=!1,maxRadius:r=24,backgroundToken:i=``,onPlotContextMenu:a}){let o=IZ(),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(null),u=(0,Z.useRef)(null),d=(0,Z.useRef)(null),f=(0,Z.useRef)(null),p=(0,Z.useRef)(0),m=(0,Z.useRef)(a);(0,Z.useLayoutEffect)(()=>{m.current=a},[a]);let h=(0,Z.useMemo)(()=>a3(e,n,r),[e,n,r]),g=(0,Z.useRef)({points:e,color:t,colorByNumeric:n,maxRadius:r,model:h});(0,Z.useLayoutEffect)(()=>{g.current={points:e,color:t,colorByNumeric:n,maxRadius:r,model:h}},[e,t,n,r,h]);let _=(0,Z.useRef)({r:null,failed:!1,size:``,model:null,style:``});(0,Z.useEffect)(()=>()=>{_.current.r?.dispose(),_.current.r=null},[]);function v(){if(d.current)return d.current;let e=u.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return d.current=n,n}function y(){let e=u.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||300)}}function b(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function x(e,t){let{xLo:n,xHi:r,yLo:i,yHi:a}=g.current.model.ext,{top:s,right:c,bottom:l,left:u}=$4,d=e-u-c,f=t-s-l;return o({left:u,top:s,width:d,height:f,x:{v0:n,v1:r},y:{v0:i,v1:a}}),{plotW:d,plotH:f,xToPx:e=>u+(e-n)/(r-n)*d,yToPx:e=>s+(1-(e-i)/(a-i))*f}}function S(e,t){let n=_.current;!n.r&&!n.failed&&c.current&&(n.r=dX(c.current,k$),n.failed=!n.r);let r=n.r;if(!r||!c.current)return null;let i=Math.min(2,window.devicePixelRatio||1),a=`${e}x${t}@${i}`;n.size!==a&&(r.resize(e,t,i),c.current.style.width=`${e}px`,c.current.style.height=`${t}px`,n.size=a);let{model:o,color:s}=g.current;n.model!==o&&(r.setData(o.drawn.x,o.drawn.y,o.drawn.k,!1,o.drawn.r),n.model=o,VX(u.current));let l=`${o.mode}|${s}`;return n.style!==l&&(r.setStyle(o.mode===`single`?{kind:`single`,rgba:M1(s,1)}:{kind:o.mode,palette:o.mode===`colormap`?r3:i3()},3,.65),r.setDraw(!0,!1,0),n.style=l),r}function C(){let e=s.current;if(!e)return;let{w:t,h:n}=y(),r=b(e,t,n);if(!r)return;let{bg:i,muted:a,grid:o}=v(),{points:c,color:l,colorByNumeric:u,model:d}=g.current;r.fillStyle=i,r.fillRect(0,0,t,n);let f=S(t,n);if(c.length===0){f?.setData([],[]),_.current.model=null,f?.render(),r.fillStyle=a,r.font=`13px ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,MY(r);return}let{xLo:p,xHi:m,yLo:h,yHi:C}=d.ext,{top:w,left:T}=$4,{plotW:E,plotH:D,xToPx:O,yToPx:k}=x(t,n);r.strokeStyle=o,r.lineWidth=1;for(let e=0;e<=5;e++){let t=p+e/5*(m-p),n=O(t);r.beginPath(),r.moveTo(n,w),r.lineTo(n,w+D),r.stroke(),r.fillStyle=a,r.font=`9px ${X.mono}`,r.textAlign=`center`,r.textBaseline=`top`,r.fillText(_J(t,(m-p)/5),n,w+D+4);let i=h+e/5*(C-h),o=k(i);r.beginPath(),r.moveTo(T,o),r.lineTo(T+E,o),r.stroke(),r.fillStyle=a,r.textAlign=`right`,r.textBaseline=`middle`,r.fillText(_J(i,(C-h)/5),T-4,o)}if(f)f.setView(p,m,h,C,{left:T,top:w,width:E,height:D}),f.render();else{let e=d.drawn;r.globalAlpha=.65;for(let t=0;t<e.x.length;t++){if(e.x[t]!==e.x[t]||e.y[t]!==e.y[t])continue;let n=e.k?.[t]??0;r.fillStyle=d.mode===`colormap`?n3(n):d.mode===`dataset`?e3[n%e3.length]:l,r.beginPath(),r.arc(O(e.x[t]),k(e.y[t]),e.r[t],0,Math.PI*2),r.fill()}r.globalAlpha=1}let A=c.colorLabels??[];if(!u&&A.length>0&&A.length<=10){let e=T,t=n-$4.bottom-10;r.font=`9px ${X.mono}`,r.textBaseline=`top`;for(let n=0;n<A.length;n++){let i=A[n];if(r.fillStyle=e3[n%e3.length],r.beginPath(),r.arc(e+4,t+4,4,0,Math.PI*2),r.fill(),r.fillStyle=a,r.textAlign=`left`,r.fillText(i,e+10,t),e+=r.measureText(i).width+20,e>T+E-60)break}}}function w(){let e=l.current;if(!e)return;let{w:t,h:n}=y(),r=b(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=f.current;if(i===null)return;let{points:a,model:o}=g.current;if(i<0||i>=a.length)return;let{xToPx:s,yToPx:c}=x(t,n),u=o.radius[i],d=s(a.x[i]),p=c(a.y[i]);r.beginPath(),r.arc(d,p,u+2,0,Math.PI*2),r.strokeStyle=`rgba(255,255,255,0.9)`,r.lineWidth=2,r.stroke();let m=[],h=a.label?.(i);h&&m.push(h),m.push(`(${vJ(a.x[i])}, ${vJ(a.y[i])})`),m.push(`size=${vJ(a.size[i])}`);let _=a.colorIndex?.[i];_!==void 0&&_>=0&&a.colorLabels?m.push(a.colorLabels[_]):a.colorValue&&m.push(vJ(a.colorValue[i]));let v=m.join(` · `);r.font=`11px ${X.mono}`;let S=r.measureText(v).width,C=Math.max(4,Math.min(t-S-8,d+u+4)),w=p-20<$4.top?p+u+4:p-20;r.fillStyle=`rgba(0,0,0,0.8)`,r.fillRect(C-3,w-3,S+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(v,C,w)}let T=(0,Z.useRef)(C);T.current=C;let E=(0,Z.useRef)(null);E.current??=KX(()=>T.current(),()=>u.current);let D=()=>E.current.schedule(),O=()=>{zX(p.current),p.current=RX(w)};return(0,Z.useEffect)(()=>{E.current.now()}),(0,Z.useEffect)(()=>()=>E.current?.cancel(),[]),(0,Z.useEffect)(()=>{d.current=null,D()},[i]),(0,Z.useLayoutEffect)(()=>{let e=u.current;if(!e)return;let t=new WX(()=>{d.current=null,D(),O()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{let e=l.current;if(!e)return;let t=null,n=e=>{e.preventDefault(),m.current?.({clientX:e.clientX,clientY:e.clientY})},r=n=>{let r=e.getBoundingClientRect(),{points:i,maxRadius:a,model:o}=g.current,{w:s,h:c}=y(),{plotW:l,plotH:u,xToPx:d,yToPx:p}=x(s,c),m=e=>d(i.x[e])-$4.left,h=e=>p(i.y[e])-$4.top,_=a+6,v=`${s}|${c}|${_}`;(!t||t.model!==o||t.key!==v)&&(t={model:o,key:v,g:v4(i.length,l,u,_,m,h)}),f.current=y4(t.g,n.clientX-r.left-$4.left,n.clientY-r.top-$4.top,_,m,h,e=>o.radius[e]+6),O()},i=()=>{f.current=null,O()};return e.addEventListener(`contextmenu`,n),e.addEventListener(`mousemove`,r),e.addEventListener(`mouseleave`,i),()=>{e.removeEventListener(`contextmenu`,n),e.removeEventListener(`mousemove`,r),e.removeEventListener(`mouseleave`,i)}},[]),(0,Q.jsxs)(`div`,{ref:u,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:s,className:`chart-canvas`,role:`img`,"aria-label":`Bubble chart`}),(0,Q.jsx)(`canvas`,{ref:c,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),(0,Q.jsx)(`canvas`,{ref:l,className:`chart-canvas chart-overlay`})]})}var s3={top:8,right:8,bottom:8,left:8},c3=[`#f97316`,`#38bdf8`,`#4ade80`,`#a78bfa`,`#fbbf24`,`#fb7185`,`#34d399`,`#e879f9`,`#facc15`,`#60a5fa`];function l3(e){let t=new Map;for(let n of e){let e=n.parent??``;t.has(e)||t.set(e,[]),t.get(e).push(n)}function n(r,i){let a=(t.get(r)??[]).map(e=>n(e.name,i+1)),o=e.find(e=>e.name===r),s=a.reduce((e,t)=>e+t.value,0);return{name:r,value:o?Math.max(o.value,s):s,children:a,depth:i}}let r=new Set(e.map(e=>e.name));return e.filter(e=>!e.parent||!r.has(e.parent)).map(e=>n(e.name,0))}function u3(e,t,n,r,i,a){if(e.length===0||r<=0||i<=0||e.reduce((e,t)=>e+t.value,0)===0)return[];let o=[],s=[...e].sort((e,t)=>t.value-e.value),c=t,l=n,u=r,d=i;for(;s.length>0;){let e=u*d,t=s.reduce((e,t)=>e+t.value,0),n=e/t,r=[],i=1/0;for(let e=1;e<=s.length;e++){let a=s.slice(0,e),o=a.reduce((e,t)=>e+t.value,0)/t*(u<=d?u:d),c=0;for(let e of a){let t=e.value*n/o,r=Math.max(t/o,o/t);r>c&&(c=r)}if(c<i)i=c,r=a;else break}let f=r.reduce((e,t)=>e+t.value,0),p=u<=d,m=f/t*(p?u:d),h=0;for(let e of r){let t=e.value/f,n=p?u:t*u,r=p?t*d:d,i=p?c:c+h,s=p?l+h:l,g=p?m:n,_=p?r:m;if(o.push({node:e,x:i,y:s,w:g,h:_,depth:a}),e.children.length>0&&g>4&&_>4){let t=u3(e.children,i+1,s+1,g-2,_-2,a+1);for(let e of t)o.push(e)}h+=p?r:n}s=s.slice(r.length),p?(c+=m,u-=m):(l+=m,d-=m)}return o}function d3({nodes:e,backgroundToken:t=``,onPlotContextMenu:n}){let r=(0,Z.useRef)(null),i=(0,Z.useRef)(null),a=(0,Z.useRef)(null),o=(0,Z.useRef)(null),s=(0,Z.useRef)([]),c=(0,Z.useRef)(null),l=(0,Z.useRef)(0),u=(0,Z.useRef)(n);(0,Z.useLayoutEffect)(()=>{u.current=n},[n]);let d=(0,Z.useRef)({nodes:e});(0,Z.useLayoutEffect)(()=>{d.current={nodes:e}},[e]);let f=(0,Z.useMemo)(()=>l3(e),[e]),p=(0,Z.useRef)(f);(0,Z.useLayoutEffect)(()=>{p.current=f},[f]);function m(){if(o.current)return o.current;let e=a.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return o.current=n,n}function h(){let e=a.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||300)}}function g(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function _(){let e=r.current;if(!e)return;let{w:t,h:n}=h(),i=g(e,t,n);if(!i)return;let{bg:a,muted:o}=m(),{nodes:l}=d.current;if(i.fillStyle=a,i.fillRect(0,0,t,n),l.length===0){i.fillStyle=o,i.font=`13px ${X.sans}`,i.textAlign=`left`,i.textBaseline=`top`,MY(i);return}let u=p.current,f=t-s3.left-s3.right,_=n-s3.top-s3.bottom,v=u3(u,s3.left,s3.top,f,_,0);s.current=v;for(let e=0;e<v.length;e++){let{node:t,x:n,y:r,w:o,h:s,depth:l}=v[e];if(o<2||s<2)continue;let u=c3[l%c3.length],d=c.current===e;if(i.fillStyle=u,i.globalAlpha=d?.95:.75,i.fillRect(n,r,o,s),i.globalAlpha=1,i.strokeStyle=a,i.lineWidth=1,i.strokeRect(n,r,o,s),o>20&&s>14){i.fillStyle=`rgba(0,0,0,0.75)`,i.font=`${Math.min(11,s-4)}px ${X.mono}`,i.textAlign=`left`,i.textBaseline=`top`;let e=Math.floor((o-4)/6),a=t.name.length>e?t.name.slice(0,e-1)+`…`:t.name;i.fillText(a,n+3,r+3)}}i.globalAlpha=1}function v(){let e=i.current;if(!e)return;let{w:t,h:n}=h(),r=g(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let a=c.current;if(a===null)return;let o=s.current;if(a<0||a>=o.length)return;let{node:l,x:u,y:d,w:f,h:p}=o[a];r.strokeStyle=`rgba(255,255,255,0.9)`,r.lineWidth=2,r.strokeRect(u+1,d+1,f-2,p-2);let m=`${l.name}: ${l.value.toLocaleString()}`;r.font=`11px ${X.mono}`;let _=r.measureText(m).width,v=Math.max(4,Math.min(t-_-8,u+f/2-_/2)),y=d<30?d+p+4:d-20;r.fillStyle=`rgba(0,0,0,0.8)`,r.fillRect(v-3,y-3,_+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(m,v,y)}let y=(0,Z.useRef)(_);y.current=_;let b=(0,Z.useRef)(null);b.current??=KX(()=>y.current(),()=>a.current);let x=()=>b.current.schedule(),S=()=>{zX(l.current),l.current=RX(v)};return(0,Z.useEffect)(()=>{b.current.now()}),(0,Z.useEffect)(()=>()=>b.current?.cancel(),[]),(0,Z.useEffect)(()=>{o.current=null,x()},[t]),(0,Z.useLayoutEffect)(()=>{let e=a.current;if(!e)return;let t=new WX(()=>{o.current=null,x(),S()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{let e=i.current;if(!e)return;let t=e=>{e.preventDefault(),u.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),r=t.clientX-n.left,i=t.clientY-n.top,a=s.current,o=null;for(let e=0;e<a.length;e++){let t=a[e];r>=t.x&&r<=t.x+t.w&&i>=t.y&&i<=t.y+t.h&&(o=e)}c.current=o,S()},r=()=>{c.current=null,S()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),(0,Q.jsxs)(`div`,{ref:a,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:r,className:`chart-canvas`,role:`img`,"aria-label":`Treemap`}),(0,Q.jsx)(`canvas`,{ref:i,className:`chart-canvas chart-overlay`})]})}var f3={top:8,right:8,bottom:8,left:8},p3=14,m3=8,h3=[`#38bdf8`,`#4ade80`,`#fb7185`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`,`#facc15`,`#60a5fa`];function g3(e,t,n,r){if(e.length===0||t.length===0)return{nodes:[],links:[]};let i=n-f3.left-f3.right,a=r-f3.top-f3.bottom,o=new Map;for(let t of e)o.set(t,0);let s=!0;for(;s;){s=!1;for(let e of t){let t=o.get(e.source)??0;(o.get(e.target)??0)<=t&&(o.set(e.target,t+1),s=!0)}}let c=Math.max(0,...Array.from(o.values())),l=e=>f3.left+e/Math.max(1,c)*(i-p3),u=new Map;for(let[e,t]of o)u.has(t)||u.set(t,[]),u.get(t).push(e);let d=new Map;for(let t of e)d.set(t,0);for(let e of t)d.set(e.source,(d.get(e.source)??0)+e.value),d.set(e.target,(d.get(e.target)??0)+e.value);let f=Math.max(1,...Array.from(d.values())),p=new Map;for(let[t,n]of u){let r=a-(n.length-1)*m3,i=0;for(let e of n)i+=Math.max(8,(d.get(e)??0)/f*r*.8);let o=f3.top+(a-i-(n.length-1)*m3)/2;for(let i=0;i<n.length;i++){let a=n[i],s=Math.max(8,(d.get(a)??0)/f*r*.8);p.set(a,{name:a,x:l(t),y:o,h:s,color:h3[e.indexOf(a)%h3.length]}),o+=s+m3}}let m=new Map,h=new Map;for(let[e,t]of p)m.set(e,t.y),h.set(e,t.y);let g=[];for(let e of t){let t=p.get(e.source),n=p.get(e.target);if(!t||!n)continue;let r=Math.max(1,e.value/f*t.h),i=m.get(e.source)??t.y,a=h.get(e.target)??n.y;m.set(e.source,i+r),h.set(e.target,a+r),g.push({sx:t.x+p3,sy:i+r/2,tx:n.x,ty:a+r/2,h:r,color:t.color,label:`${e.source} → ${e.target}: ${e.value.toLocaleString()}`})}return{nodes:Array.from(p.values()),links:g}}function _3({nodeNames:e,links:t,backgroundToken:n=``,onPlotContextMenu:r}){let i=(0,Z.useRef)(null),a=(0,Z.useRef)(null),o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),c=(0,Z.useRef)({nodes:[],links:[]}),l=(0,Z.useRef)(null),u=(0,Z.useRef)(0),d=(0,Z.useRef)(r);(0,Z.useLayoutEffect)(()=>{d.current=r},[r]);let f=(0,Z.useRef)({nodeNames:e,links:t});(0,Z.useLayoutEffect)(()=>{f.current={nodeNames:e,links:t}},[e,t]);function p(){if(s.current)return s.current;let e=o.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return s.current=n,n}function m(){let e=o.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||300)}}function h(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function g(){let e=i.current;if(!e)return;let{w:t,h:n}=m(),r=h(e,t,n);if(!r)return;let{bg:a,muted:o}=p(),{nodeNames:s,links:u}=f.current;if(r.fillStyle=a,r.fillRect(0,0,t,n),s.length===0||u.length===0){r.fillStyle=o,r.font=`13px ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,MY(r);return}let d=g3(s,u,t,n);c.current=d;for(let e=0;e<d.links.length;e++){let t=d.links[e],n=l.current===e,i=(t.tx-t.sx)/2;r.beginPath(),r.moveTo(t.sx,t.sy-t.h/2),r.bezierCurveTo(t.sx+i,t.sy-t.h/2,t.tx-i,t.ty-t.h/2,t.tx,t.ty-t.h/2),r.lineTo(t.tx,t.ty+t.h/2),r.bezierCurveTo(t.tx-i,t.ty+t.h/2,t.sx+i,t.sy+t.h/2,t.sx,t.sy+t.h/2),r.closePath(),r.fillStyle=t.color,r.globalAlpha=n?.55:.3,r.fill()}r.globalAlpha=1;for(let e of d.nodes)r.fillStyle=e.color,r.globalAlpha=.9,r.fillRect(e.x,e.y,p3,e.h),r.globalAlpha=1,r.fillStyle=o,r.font=`9px ${X.mono}`,r.textBaseline=`middle`,e.x>t/2?(r.textAlign=`right`,r.fillText(e.name,e.x-3,e.y+e.h/2)):(r.textAlign=`left`,r.fillText(e.name,e.x+p3+3,e.y+e.h/2));r.globalAlpha=1}function _(){let e=a.current;if(!e)return;let{w:t,h:n}=m(),r=h(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=l.current;if(i===null)return;let o=c.current;if(i<0||i>=o.links.length)return;let s=o.links[i],u=s.label;r.font=`11px ${X.mono}`;let d=r.measureText(u).width,f=Math.max(4,Math.min(t-d-8,(s.sx+s.tx)/2-d/2)),p=Math.max(4,(s.sy+s.ty)/2-10);r.fillStyle=`rgba(0,0,0,0.8)`,r.fillRect(f-3,p-3,d+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(u,f,p)}let v=(0,Z.useRef)(g);v.current=g;let y=(0,Z.useRef)(null);y.current??=KX(()=>v.current(),()=>o.current);let b=()=>y.current.schedule(),x=()=>{zX(u.current),u.current=RX(_)};return(0,Z.useEffect)(()=>{y.current.now()}),(0,Z.useEffect)(()=>()=>y.current?.cancel(),[]),(0,Z.useEffect)(()=>{s.current=null,b()},[n]),(0,Z.useLayoutEffect)(()=>{let e=o.current;if(!e)return;let t=new WX(()=>{s.current=null,b(),x()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{let e=a.current;if(!e)return;let t=e=>{e.preventDefault(),d.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),r=t.clientX-n.left,i=t.clientY-n.top,a=c.current,o=null;for(let e=0;e<a.links.length;e++){let t=a.links[e];if(r>=t.sx&&r<=t.tx&&Math.abs(i-(t.sy+t.ty)/2)<t.h/2+6){o=e;break}}l.current=o,x()},r=()=>{l.current=null,x()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),(0,Q.jsxs)(`div`,{ref:o,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:i,className:`chart-canvas`,role:`img`,"aria-label":`Sankey diagram`}),(0,Q.jsx)(`canvas`,{ref:a,className:`chart-canvas chart-overlay`})]})}var v3={top:24,right:24,bottom:52,left:52};function y3({bins:e,color:t=`#38bdf8`,backgroundToken:n=``,onPlotContextMenu:r}){let i=(0,Z.useRef)(null),a=(0,Z.useRef)(null),o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(0),u=(0,Z.useRef)(r);(0,Z.useLayoutEffect)(()=>{u.current=r},[r]);let d=(0,Z.useRef)({bins:e,color:t});(0,Z.useLayoutEffect)(()=>{d.current={bins:e,color:t}},[e,t]);function f(){if(s.current)return s.current;let e=o.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return s.current=n,n}function p(){let e=o.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||300)}}function m(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function h(){let e=i.current;if(!e)return;let{w:t,h:n}=p(),r=m(e,t,n);if(!r)return;let{bg:a,muted:o,grid:s}=f(),{bins:l,color:u}=d.current;if(r.fillStyle=a,r.fillRect(0,0,t,n),l.length===0){r.fillStyle=o,r.font=`13px ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,MY(r);return}let{top:h,right:g,bottom:_,left:v}=v3,y=t-v-g,b=n-h-_,x=e=>v+e*y,S=e=>h+(1-e)*b;for(let e=0;e<=5;e++){let t=e/5;r.strokeStyle=s,r.lineWidth=1,r.beginPath(),r.moveTo(v,S(t)),r.lineTo(v+y,S(t)),r.stroke(),r.beginPath(),r.moveTo(x(t),h),r.lineTo(x(t),h+b),r.stroke(),r.fillStyle=o,r.font=`9px ${X.mono}`,r.textAlign=`right`,r.textBaseline=`middle`,r.fillText(t.toFixed(2),v-4,S(t)),r.textAlign=`center`,r.textBaseline=`top`,r.fillText(t.toFixed(2),x(t),h+b+4)}r.strokeStyle=o,r.lineWidth=1.5,r.setLineDash([6,4]),r.beginPath(),r.moveTo(x(0),S(0)),r.lineTo(x(1),S(1)),r.stroke(),r.setLineDash([]);let C=Math.max(1,...l.map(e=>e.count)),w=b*.15;for(let e of l){let t=Math.max(1,y/l.length*.7),n=x(e.center)-t/2,i=e.count/C*w;r.fillStyle=u,r.globalAlpha=.3,r.fillRect(n,h+b-i,t,i)}r.globalAlpha=1,r.beginPath();for(let e=0;e<l.length;e++){let t=x(l[e].center),n=S(l[e].actual);e===0?r.moveTo(t,n):r.lineTo(t,n)}r.strokeStyle=u,r.lineWidth=1,r.stroke();for(let e=0;e<l.length;e++){let t=c.current===e;r.beginPath(),r.arc(x(l[e].center),S(l[e].actual),t?6:4,0,Math.PI*2),r.fillStyle=u,r.globalAlpha=t?1:.85,r.fill()}r.globalAlpha=1,r.fillStyle=o,r.font=`10px ${X.mono}`,r.textAlign=`center`,r.textBaseline=`bottom`,r.fillText(`Predicted probability`,v+y/2,n-4),r.save(),r.translate(12,h+b/2),r.rotate(-Math.PI/2),r.textAlign=`center`,r.textBaseline=`middle`,r.fillText(`Actual rate`,0,0),r.restore()}function g(){let e=a.current;if(!e)return;let{w:t,h:n}=p(),r=m(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=c.current;if(i===null)return;let{bins:o}=d.current;if(i<0||i>=o.length)return;let s=o[i],{top:l,left:u}=v3,f=t-u-v3.right,h=n-l-v3.bottom,g=u+s.center*f,_=l+(1-s.actual)*h,v=`pred=${s.center.toFixed(2)} actual=${s.actual.toFixed(3)} n=${s.count}`;r.font=`11px ${X.mono}`;let y=r.measureText(v).width,b=Math.max(4,Math.min(t-y-8,g-y/2)),x=_-28<l?_+12:_-24;r.fillStyle=`rgba(0,0,0,0.8)`,r.fillRect(b-3,x-3,y+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(v,b,x)}let _=(0,Z.useRef)(h);_.current=h;let v=(0,Z.useRef)(null);v.current??=KX(()=>_.current(),()=>o.current);let y=()=>v.current.schedule(),b=()=>{zX(l.current),l.current=RX(g)};return(0,Z.useEffect)(()=>{v.current.now()}),(0,Z.useEffect)(()=>()=>v.current?.cancel(),[]),(0,Z.useEffect)(()=>{s.current=null,y()},[n]),(0,Z.useLayoutEffect)(()=>{let e=o.current;if(!e)return;let t=new WX(()=>{s.current=null,y(),b()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{let e=a.current;if(!e)return;let t=e=>{e.preventDefault(),u.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),{bins:r}=d.current,{w:i}=p(),a=t.clientX-n.left,o=i-v3.left-v3.right,s=-1,l=20;for(let e=0;e<r.length;e++){let t=v3.left+r[e].center*o,n=Math.abs(a-t);n<l&&(l=n,s=e)}c.current=s>=0?s:null,b()},r=()=>{c.current=null,b()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),(0,Q.jsxs)(`div`,{ref:o,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:i,className:`chart-canvas`,role:`img`,"aria-label":`Calibration curve`}),(0,Q.jsx)(`canvas`,{ref:a,className:`chart-canvas chart-overlay`})]})}var b3={top:24,right:24,bottom:48,left:52};function x3({points:e,color:t=`#a78bfa`,backgroundToken:n=``,onPlotContextMenu:r}){let i=IZ(),a=(0,Z.useRef)(null),o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(null),u=(0,Z.useRef)(0),d=(0,Z.useRef)(r);(0,Z.useLayoutEffect)(()=>{d.current=r},[r]);let f=(0,Z.useRef)({points:e,color:t});(0,Z.useLayoutEffect)(()=>{f.current={points:e,color:t}},[e,t]);function p(){if(c.current)return c.current;let e=s.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return c.current=n,n}function m(){let e=s.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||300)}}function h(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function g(){let{points:e}=f.current,t=1/0,n=-1/0,r=1/0,i=-1/0;if(e.length>0&&(t=e.theoretical[0],n=e.theoretical[e.length-1],r=e.sample[0],i=e.sample[e.length-1]),!Number.isFinite(t))return{xLo:-3,xHi:3,yLo:-3,yHi:3};let a=(n-t)*.05||.5,o=(i-r)*.05||.5;return{xLo:t-a,xHi:n+a,yLo:r-o,yHi:i+o}}function _(){let e=a.current;if(!e)return;let{w:t,h:n}=m(),r=h(e,t,n);if(!r)return;let{bg:o,muted:s,grid:c}=p(),{points:u,color:d}=f.current;if(r.fillStyle=o,r.fillRect(0,0,t,n),u.length===0){r.fillStyle=s,r.font=`13px ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,MY(r);return}let{xLo:_,xHi:v,yLo:y,yHi:b}=g(),{top:x,right:S,bottom:C,left:w}=b3,T=t-w-S,E=n-x-C,D=e=>w+(e-_)/(v-_)*T,O=e=>x+(1-(e-y)/(b-y))*E;i({left:w,top:x,width:T,height:E,x:{v0:_,v1:v}}),r.strokeStyle=c,r.lineWidth=1;for(let e=0;e<=5;e++){let t=_+e/5*(v-_),n=D(t);r.beginPath(),r.moveTo(n,x),r.lineTo(n,x+E),r.stroke(),r.fillStyle=s,r.font=`9px ${X.mono}`,r.textAlign=`center`,r.textBaseline=`top`,r.fillText(_J(t,(v-_)/5),n,x+E+4);let i=y+e/5*(b-y),a=O(i);r.beginPath(),r.moveTo(w,a),r.lineTo(w+T,a),r.stroke(),r.fillStyle=s,r.textAlign=`right`,r.textBaseline=`middle`,r.fillText(_J(i,(b-y)/5),w-4,a)}let k=Math.max(_,y),A=Math.min(v,b);k<A&&(r.strokeStyle=s,r.lineWidth=1.5,r.setLineDash([6,4]),r.beginPath(),r.moveTo(D(k),O(k)),r.lineTo(D(A),O(A)),r.stroke(),r.setLineDash([])),r.fillStyle=d,r.globalAlpha=.75;let j=NaN,M=NaN;for(let e=0;e<u.length;e++){let t=Math.round(D(u.theoretical[e])),n=Math.round(O(u.sample[e]));t===j&&n===M||(j=t,M=n,r.beginPath(),r.arc(t,n,3,0,Math.PI*2),r.fill())}let N=l.current;N!==null&&N<u.length&&(r.globalAlpha=1,r.beginPath(),r.arc(D(u.theoretical[N]),O(u.sample[N]),5,0,Math.PI*2),r.fill()),r.globalAlpha=1,r.fillStyle=s,r.font=`10px ${X.mono}`,r.textAlign=`center`,r.textBaseline=`bottom`,r.fillText(`Theoretical quantiles`,w+T/2,n-4),r.save(),r.translate(12,x+E/2),r.rotate(-Math.PI/2),r.textAlign=`center`,r.textBaseline=`middle`,r.fillText(`Sample quantiles`,0,0),r.restore()}function v(){let e=o.current;if(!e)return;let{w:t,h:n}=m(),r=h(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=l.current;if(i===null)return;let{points:a}=f.current;if(i<0||i>=a.length)return;let s={theoretical:a.theoretical[i],sample:a.sample[i]},{xLo:c,xHi:u,yLo:d,yHi:p}=g(),{top:_,left:v}=b3,y=t-v-b3.right,b=n-_-b3.bottom,x=v+(s.theoretical-c)/(u-c)*y,S=_+(1-(s.sample-d)/(p-d))*b;r.beginPath(),r.arc(x,S,6,0,Math.PI*2),r.strokeStyle=`rgba(255,255,255,0.9)`,r.lineWidth=2,r.stroke();let C=`(${vJ(s.theoretical)}, ${vJ(s.sample)})`;r.font=`11px ${X.mono}`;let w=r.measureText(C).width,T=Math.max(4,Math.min(t-w-8,x+10)),E=S-20<_?S+10:S-20;r.fillStyle=`rgba(0,0,0,0.8)`,r.fillRect(T-3,E-3,w+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(C,T,E)}let y=(0,Z.useRef)(_);y.current=_;let b=(0,Z.useRef)(null);b.current??=KX(()=>y.current(),()=>s.current);let x=()=>b.current.schedule(),S=()=>{zX(u.current),u.current=RX(v)};return(0,Z.useEffect)(()=>{b.current.now()}),(0,Z.useEffect)(()=>()=>b.current?.cancel(),[]),(0,Z.useEffect)(()=>{c.current=null,x()},[n]),(0,Z.useLayoutEffect)(()=>{let e=s.current;if(!e)return;let t=new WX(()=>{c.current=null,x(),S()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{let e=o.current;if(!e)return;let t=e=>{e.preventDefault(),d.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),{points:r}=f.current,{w:i}=m(),{xLo:a,xHi:o,yLo:s,yHi:c}=g(),{top:u,left:d}=b3,p=i-d-b3.right,h=n.height-u-b3.bottom,_=t.clientX-n.left,v=t.clientY-n.top,y=e=>a+(e-d)/p*(o-a),b=e=>{let t=0,n=r.length;for(;t<n;){let i=t+n>>>1;r.theoretical[i]<e?t=i+1:n=i}return t},x=b(y(_-10)),C=Math.min(r.length,b(y(_+10))+1),w=-1,T=10**2;for(let e=x;e<C;e++){let t=d+(r.theoretical[e]-a)/(o-a)*p,n=u+(1-(r.sample[e]-s)/(c-s))*h,i=(_-t)**2+(v-n)**2;i<T&&(T=i,w=e)}l.current=w>=0?w:null,S()},r=()=>{l.current=null,S()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),(0,Q.jsxs)(`div`,{ref:s,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:a,className:`chart-canvas`,role:`img`,"aria-label":`Q-Q plot`}),(0,Q.jsx)(`canvas`,{ref:o,className:`chart-canvas chart-overlay`})]})}var S3={top:8,right:16,bottom:40,left:120},C3=22,w3=3,T3=[`#38bdf8`,`#4ade80`,`#fb7185`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`,`#facc15`,`#60a5fa`];function E3({tasks:e,backgroundToken:t=``,onPlotContextMenu:n}){let r=IZ(),i=(0,Z.useRef)(null),a=(0,Z.useRef)(null),o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(0),u=(0,Z.useRef)(n);(0,Z.useLayoutEffect)(()=>{u.current=n},[n]);let d=(0,Z.useRef)({tasks:e});(0,Z.useLayoutEffect)(()=>{d.current={tasks:e}},[e]);function f(){if(s.current)return s.current;let e=o.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return s.current=n,n}function p(){let e=o.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||300)}}function m(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function h(){let e=i.current;if(!e)return;let{w:t,h:n}=p(),a=m(e,t,n);if(!a)return;let{bg:o,muted:s,grid:l}=f(),{tasks:u}=d.current;if(a.fillStyle=o,a.fillRect(0,0,t,n),u.length===0){a.fillStyle=s,a.font=`13px ${X.sans}`,a.textAlign=`left`,a.textBaseline=`top`,MY(a);return}let h=1/0,g=-1/0;for(let e of u)e.start<h&&(h=e.start),e.end>g&&(g=e.end);Number.isFinite(h)||(h=0,g=1);let _=(g-h)*.02||1;h-=_,g+=_;let{top:v,right:y,bottom:b,left:x}=S3,S=t-x-y,C=e=>x+(e-h)/(g-h)*S;r({left:x,top:v,width:S,height:n-v-b,x:{v0:h,v1:g}});let w=new Map;for(let e of u){let t=e.group??e.label;w.has(t)||w.set(t,w.size)}let T=Math.min(8,Math.floor(S/60));a.strokeStyle=l,a.lineWidth=1;for(let e=0;e<=T;e++){let t=h+e/T*(g-h),n=C(t),r=u.length*(C3+w3)+v;a.beginPath(),a.moveTo(n,v),a.lineTo(n,r),a.stroke(),a.fillStyle=s,a.font=`9px ${X.mono}`,a.textAlign=`center`,a.textBaseline=`top`,a.fillText(_J(t,(g-h)/T),n,r+4)}for(let e=0;e<u.length;e++){let t=u[e],n=v+e*(C3+w3),r=T3[(w.get(t.group??t.label)??0)%T3.length],i=c.current===e,o=C(t.start),l=C(t.end),d=Math.max(2,l-o);a.fillStyle=r,a.globalAlpha=i?.95:.75,a.fillRect(o,n,d,C3-w3),a.globalAlpha=1,a.fillStyle=s,a.font=`9px ${X.mono}`,a.textAlign=`right`,a.textBaseline=`middle`;let f=t.label.length>16?t.label.slice(0,15)+`…`:t.label;a.fillText(f,x-4,n+(C3-w3)/2)}a.globalAlpha=1}function g(){let e=a.current;if(!e)return;let{w:t,h:n}=p(),r=m(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=c.current;if(i===null)return;let{tasks:o}=d.current;if(i<0||i>=o.length)return;let s=o[i],l=s.end-s.start,u=`${s.label}: ${vJ(s.start)} → ${vJ(s.end)} (${vJ(l)})`;r.font=`11px ${X.mono}`;let f=r.measureText(u).width,h=1/0,g=-1/0;for(let e of o)e.start<h&&(h=e.start),e.end>g&&(g=e.end);let _=(g-h)*.02||1;h-=_,g+=_;let v=t-S3.left-S3.right,y=e=>S3.left+(e-h)/(g-h)*v,b=S3.top+i*(C3+w3),x=(y(s.start)+y(s.end))/2,S=Math.max(4,Math.min(t-f-8,x-f/2)),C=b-22<S3.top?b+C3+4:b-20;r.fillStyle=`rgba(0,0,0,0.8)`,r.fillRect(S-3,C-3,f+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(u,S,C)}let _=(0,Z.useRef)(h);_.current=h;let v=(0,Z.useRef)(null);v.current??=KX(()=>_.current(),()=>o.current);let y=()=>v.current.schedule(),b=()=>{zX(l.current),l.current=RX(g)};return(0,Z.useEffect)(()=>{v.current.now()}),(0,Z.useEffect)(()=>()=>v.current?.cancel(),[]),(0,Z.useEffect)(()=>{s.current=null,y()},[t]),(0,Z.useLayoutEffect)(()=>{let e=o.current;if(!e)return;let t=new WX(()=>{s.current=null,y(),b()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{let e=a.current;if(!e)return;let t=e=>{e.preventDefault(),u.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),{tasks:r}=d.current,i=t.clientY-n.top,a=Math.floor((i-S3.top)/(C3+w3));c.current=a>=0&&a<r.length?a:null,b()},r=()=>{c.current=null,b()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),(0,Q.jsxs)(`div`,{ref:o,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:i,className:`chart-canvas`,role:`img`,"aria-label":`Gantt chart`}),(0,Q.jsx)(`canvas`,{ref:a,className:`chart-canvas chart-overlay`})]})}var D3=e=>[...e].filter(e=>Number.isFinite(e.at)).sort((e,t)=>e.at-t.at),O3=e=>{let t=/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})/i.exec(e);return t?[parseInt(t[1],16),parseInt(t[2],16),parseInt(t[3],16)]:[128,128,128]},k3=e=>`#${e.map(e=>Math.round(e).toString(16).padStart(2,`0`)).join(``)}`;function A3(e,t,n,r){let i=t?D3(t):[];if(!e||e===`solid`||i.length===0||!Number.isFinite(r))return n;if(e===`zones`){let e=i[0].color;for(let t of i)r>=t.at&&(e=t.color);return e}if(r<=i[0].at)return i[0].color;if(r>=i[i.length-1].at)return i[i.length-1].color;let a=0;for(;i[a+1].at<r;)a++;let o=i[a],s=i[a+1],c=(r-o.at)/(s.at-o.at||1),l=O3(o.color),u=O3(s.color);return k3([l[0]+(u[0]-l[0])*c,l[1]+(u[1]-l[1])*c,l[2]+(u[2]-l[2])*c])}function j3(e,t,n,r,i,a=96){let o=i-r||1,s=t?D3(t):[];if(!e||e===`solid`||s.length===0)return[{f0:0,f1:1,color:n}];if(e===`zones`){let e=[0,...s.slice(1).map(e=>(e.at-r)/o).filter(e=>e>0&&e<1),1];return e.slice(0,-1).map((t,i)=>({f0:t,f1:e[i+1],color:A3(`zones`,s,n,r+(t+e[i+1])/2*o)}))}return Array.from({length:a},(e,t)=>({f0:t/a,f1:(t+1)/a,color:A3(`gradient`,s,n,r+(t+.5)/a*o)}))}var M3=.75*Math.PI,N3=1.5*Math.PI;function P3({gauges:e,live:t,backgroundToken:n=``,onPlotContextMenu:r}){let i=(0,Z.useRef)(null),a=(0,Z.useRef)(null),o=(0,Z.useRef)(null),s=(0,Z.useRef)(r);(0,Z.useLayoutEffect)(()=>{s.current=r},[r]);let c=(0,Z.useRef)({gauges:e,live:t});(0,Z.useLayoutEffect)(()=>{c.current={gauges:e,live:t}},[e,t]);let l=(0,Z.useRef)(uZ()),u=(0,Z.useRef)(0);function d(){if(o.current)return o.current;let e=a.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`,ink:`#e4e4e7`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`,ink:t.getPropertyValue(`--chart-fg`).trim()||`#e4e4e7`};return o.current=n,n}function f(){let e=i.current,t=a.current;if(!e||!t)return;let n=Math.max(1,t.clientWidth),r=Math.max(1,t.clientHeight),o=Math.min(2,window.devicePixelRatio||1),s=Math.floor(n*o),f=Math.floor(r*o);(e.width!==s||e.height!==f)&&(e.width=s,e.height=f),e.style.width=`${n}px`,e.style.height=`${r}px`;let p=e.getContext(`2d`);if(!p)return;p.setTransform(o,0,0,o,0,0);let h=d(),{gauges:g,live:_}=c.current,v=g;if(_){let e=performance.now(),t=EZ(l.current,_.latestT(),e-u.current,_.timeAfter);u.current=e,v=g.map(e=>{if((e.stat??`last`)!==`last`)return e;let n=_.valueAt(e.name,t);return Number.isFinite(n)?{...e,value:n}:e}),m.current.schedule()}if(p.fillStyle=h.bg,p.fillRect(0,0,n,r),v.length===0){p.fillStyle=h.muted,p.font=`13px ${X.sans}`,p.textAlign=`left`,p.textBaseline=`top`,MY(p);return}let{cols:y,rows:b}=F3(v.length,n,r,v.some(e=>e.style===`arc`)?1.15:3.2),x=n/y,S=r/b;v.forEach((e,t)=>{let n=t%y*x,r=Math.floor(t/y)*S;e.style===`arc`?G3(p,e,n,r,x,S,e.color,e.alarm??null,h):K3(p,e,n,r,x,S,e.color,e.alarm??null,h)})}let p=(0,Z.useRef)(f);p.current=f;let m=(0,Z.useRef)(null);return m.current??=KX(()=>p.current(),()=>a.current),(0,Z.useEffect)(()=>{m.current.now()}),(0,Z.useEffect)(()=>()=>m.current?.cancel(),[]),(0,Z.useEffect)(()=>{o.current=null,m.current.schedule()},[n]),(0,Z.useLayoutEffect)(()=>{let e=a.current;if(!e)return;let t=new WX(()=>{o.current=null,m.current.schedule()});return t.observe(e),()=>t.disconnect()},[]),(0,Q.jsx)(`div`,{ref:a,style:{position:`relative`,width:`100%`,height:`100%`},children:(0,Q.jsx)(`canvas`,{ref:i,className:`chart-canvas`,role:`img`,"aria-label":`Gauges: ${e.map(e=>`${e.name} ${Number.isFinite(e.value)?I3(e.value,e.max-e.min):`no value`}${e.unit?` ${e.unit}`:``}`).join(`, `)}`,onContextMenu:e=>{e.preventDefault(),s.current?.({clientX:e.clientX,clientY:e.clientY})}})})}function F3(e,t,n,r){let i={cols:1,rows:e,size:-1};for(let a=1;a<=e;a++){let o=Math.ceil(e/a),s=t/a,c=n/o,l=Math.min(s,c*r);l>i.size&&(i={cols:a,rows:o,size:l})}return{cols:i.cols,rows:i.rows}}var I3=(e,t)=>_J(e,uJ(Math.abs(t),100)),L3=(e,t)=>Math.max(0,Math.min(1,(t-e.min)/(e.max-e.min||1))),R3=(e,t)=>{let n=e.fromZero?L3(e,0):0;return[Math.min(n,t),Math.max(n,t)]},z3=(e,t)=>!!t&&(t.linked?t.linked===`active`:Number.isFinite(e.value)&&e.value>=t.value),B3=e=>(e.colorMode===`gradient`||e.colorMode===`zones`)&&!!e.stops?.length,V3=(e,t)=>z3(e,t)?t.color:A3(e.colorMode,e.stops,e.color,e.value);function H3(e,t,n){for(let r of j3(t.colorMode,t.stops,t.color,t.min,t.max))e.addColorStop(n(r.f0),r.color),e.addColorStop(n(r.f1),r.color);return e}function U3(e,t,n){if(e.measureText(t).width<=n)return t;let r=t;for(;r.length>1&&e.measureText(`${r}…`).width>n;)r=r.slice(0,-1);return n>0?`${r}…`:``}var W3=Math.SQRT1_2;function G3(e,t,n,r,i,a,o,s,c){let l=Math.max(6,Math.min(i,a)*.06),u=t.max-t.min,d=I3(t.min,u),f=I3(t.max,u),p=e=>Math.max(9,Math.min(22,e*.1)),m=e=>Math.max(4,e*.13),h=Math.max(8,Math.min((i-2*l)/2,(a-2*l)/1.9)),g=0;for(let t=0;t<2;t++){e.font=`${p(h)}px ${X.mono}`,g=Math.max(e.measureText(d).width,e.measureText(f).width);let t=m(h),n=Math.max(h+t/2,W3*h+g/2),r=h+t/2+W3*h+t/2+6+p(h)*1.2;h=Math.max(8,Math.min(h*(i-2*l)/(2*n),h*(a-2*l)/r))}let _=m(h),v=p(h),y=h+_/2+W3*h+_/2+6+v*1.2,b=n+i/2,x=r+l+h+_/2+Math.max(0,(a-2*l-y)/2),S=e=>M3+e*N3;e.lineCap=`round`,e.lineWidth=_,e.strokeStyle=c.grid,e.beginPath(),e.arc(b,x,h,M3,M3+N3),e.stroke(),s&&s.value<t.max&&(e.globalAlpha=.3,e.strokeStyle=s.color,e.lineCap=`butt`,e.beginPath(),e.arc(b,x,h,S(L3(t,s.value)),M3+N3),e.stroke(),e.globalAlpha=1,e.lineCap=`round`);let[C,w]=R3(t,Number.isFinite(t.value)?L3(t,t.value):0),T=()=>{e.lineCap=t.fromZero?`butt`:`round`,e.beginPath(),e.arc(b,x,h,S(C),Math.max(S(C)+1e-4,S(w))),e.stroke(),e.lineCap=`round`};if(B3(t)){let n=N3/(2*Math.PI),r=H3(e.createConicGradient(M3,b,x),t,e=>e*n);r.addColorStop(1,A3(t.colorMode,t.stops,t.color,t.min)),e.strokeStyle=r,e.globalAlpha=.24,e.beginPath(),e.arc(b,x,h,M3,M3+N3),e.stroke(),e.globalAlpha=1,Number.isFinite(t.value)&&!z3(t,s)&&T()}if(Number.isFinite(t.value)&&(!B3(t)||z3(t,s))&&(e.strokeStyle=z3(t,s)?s.color:o,T()),t.fromZero&&t.min<0&&t.max>0){let n=S(L3(t,0));e.strokeStyle=c.muted,e.lineWidth=1.5,e.lineCap=`butt`,e.beginPath(),e.moveTo(b+Math.cos(n)*(h-_*.75),x+Math.sin(n)*(h-_*.75)),e.lineTo(b+Math.cos(n)*(h+_*.75),x+Math.sin(n)*(h+_*.75)),e.stroke(),e.lineWidth=_,e.lineCap=`round`}if(s&&s.value>=t.min&&s.value<=t.max){let n=S(L3(t,s.value));e.strokeStyle=s.color,e.lineWidth=Math.max(1.5,s.width),e.lineCap=`butt`,e.beginPath(),e.moveTo(b+Math.cos(n)*(h-_*.9),x+Math.sin(n)*(h-_*.9)),e.lineTo(b+Math.cos(n)*(h+_*.9),x+Math.sin(n)*(h+_*.9)),e.stroke();let r=h+_*.9+10*.7;s.linked&&BZ(e,b+Math.cos(n)*r-10/2,x+Math.sin(n)*r-10/2,s.color)}let E=Number.isFinite(t.value)?I3(t.value,u):`—`,D=2*(h-_)*.82,O=Math.max(11,h*.42);e.font=`650 ${O}px ${X.sans}`;let k=e.measureText(E).width;k>D&&(O=Math.max(9,O*D/k),e.font=`650 ${O}px ${X.sans}`),e.textAlign=`center`,e.textBaseline=`alphabetic`,e.fillStyle=z3(t,s)||B3(t)?V3(t,s):c.ink,e.fillText(E,b,x+O*.32),e.fillStyle=c.muted,t.unit&&(e.font=`600 ${Math.max(9,h*.13)}px ${X.sans}`,e.fillText(U3(e,t.unit,D),b,x+O*.32+Math.max(11,h*.19)));let A=x+W3*h+_/2+6,j=W3*h;e.textBaseline=`top`,e.font=`${v}px ${X.mono}`,e.fillText(d,b-j,A),e.fillText(f,b+j,A);let M=2*j-g-16,N=Math.max(10,Math.min(26,h*.13));e.font=`600 ${N}px ${X.sans}`;let P=e.measureText(t.name).width;P>M&&N>9&&(N=Math.max(9,N*M/P),e.font=`600 ${N}px ${X.sans}`),e.fillText(U3(e,t.name,M),b,A+(v-N)/2)}function K3(e,t,n,r,i,a,o,s,c){let l=Math.max(14,i*.06),u=n+l,d=n+i-l,f=d-u,p=Math.max(6,Math.min(16,a*.14)),m=Math.max(12,Math.min(34,a*.28)),h=r+a/2+m*.35,g=e=>u+L3(t,e)*f;e.textBaseline=`alphabetic`,e.fillStyle=c.muted,e.font=`600 ${Math.max(10,m*.42)}px ${X.sans}`,e.textAlign=`left`,e.fillText(U3(e,t.name,f),u,h-p/2-m-4),e.textAlign=`right`,e.fillStyle=z3(t,s)?s.color:c.ink,e.font=`650 ${m}px ${X.sans}`;let _=t.unit?(e.font=`600 ${Math.max(9,m*.4)}px ${X.sans}`,e.measureText(` ${t.unit}`).width):0;t.unit&&(e.fillStyle=c.muted,e.fillText(` ${t.unit}`,d,h-p/2-8)),e.fillStyle=z3(t,s)||B3(t)?V3(t,s):c.ink,e.font=`650 ${m}px ${X.sans}`,e.fillText(Number.isFinite(t.value)?I3(t.value,t.max-t.min):`—`,d-_,h-p/2-8),e.lineCap=`round`,e.lineWidth=p,e.strokeStyle=c.grid,e.beginPath(),e.moveTo(u,h),e.lineTo(d,h),e.stroke(),s&&s.value<t.max&&(e.globalAlpha=.3,e.strokeStyle=s.color,e.lineCap=`butt`,e.beginPath(),e.moveTo(g(s.value),h),e.lineTo(d,h),e.stroke(),e.globalAlpha=1,e.lineCap=`round`);let v=Number.isFinite(t.value)?L3(t,t.value):0,y=e=>u+e*f,[b,x]=R3(t,v),S=()=>{e.lineCap=t.fromZero?`butt`:`round`,e.beginPath(),e.moveTo(y(b),h),e.lineTo(Math.max(y(b)+.5,y(x)),h),e.stroke(),e.lineCap=`round`};B3(t)&&(e.strokeStyle=H3(e.createLinearGradient(u,0,d,0),t,e=>e),e.globalAlpha=.24,e.beginPath(),e.moveTo(u,h),e.lineTo(d,h),e.stroke(),e.globalAlpha=1,Number.isFinite(t.value)&&!z3(t,s)&&S()),Number.isFinite(t.value)&&(!B3(t)||z3(t,s))&&(e.strokeStyle=z3(t,s)?s.color:o,S()),t.fromZero&&t.min<0&&t.max>0&&(e.strokeStyle=c.muted,e.lineWidth=1.5,e.lineCap=`butt`,e.beginPath(),e.moveTo(g(0),h-p*.75),e.lineTo(g(0),h+p*.75),e.stroke(),e.lineWidth=p,e.lineCap=`round`),s&&s.value>=t.min&&s.value<=t.max&&(e.strokeStyle=s.color,e.lineWidth=Math.max(1.5,s.width),e.lineCap=`butt`,e.beginPath(),e.moveTo(g(s.value),h-p),e.lineTo(g(s.value),h+p),e.stroke(),s.linked&&BZ(e,g(s.value)-10/2,h-p-10-2,s.color)),e.fillStyle=c.muted,e.font=`${Math.max(9,m*.34)}px ${X.mono}`,e.textBaseline=`top`,e.textAlign=`left`,e.fillText(I3(t.min,t.max-t.min),u,h+p/2+4),e.textAlign=`right`,e.fillText(I3(t.max,t.max-t.min),d,h+p/2+4)}var q3=720;function J3(e,t){return t?e<q3:e<640}function Y3(e){return e<=1?{cols:1,rows:1}:e===2?{cols:2,rows:1}:e<=4?{cols:2,rows:2}:{cols:3,rows:3}}gK();function X3(e,t){return e.flatMap(e=>{let n=e.info?.meta;if(!n?.recordingId)return[];let r=n.wallOrigin?Number(n.wallOrigin):NaN,i=n.wallQuality;return[{recordingId:n.recordingId,wallOrigin:Number.isFinite(r)?r:null,wallQuality:i===`exact`||i===`approx`?i:null,xOffset:t[e.id]??0}]})}var Z3={get:()=>null,subscribe:()=>()=>{}};function Q3(e){let[t,n]=(0,Z.useState)(null);return(0,Z.useLayoutEffect)(()=>{let t=e.current;if(!t)return;let r=e=>n(t=>J3(e,t??!1));if(r(t.clientWidth),typeof ResizeObserver>`u`)return;let i=new ResizeObserver(e=>{for(let t of e)r(t.contentRect.width)});return i.observe(t),()=>i.disconnect()},[e]),t}function $3(e){let t=De(e.settings),[n,r]=(0,Z.useState)(null),[i,a]=(0,Z.useState)(null),o=(0,Z.useRef)(null);(0,Z.useEffect)(()=>{i&&o.current?.querySelector(`[data-camera="${CSS.escape(i)}"]`)?.focus()},[i]);let s=e.recordings??[],c=e=>s.findIndex(t=>t.recordingId===e.recordingId),l=(e.video??[]).filter(e=>e.kind===`recorded`&&c(e)>=0).sort((e,t)=>c(e)-c(t)),u=e.onContextMenu?t=>{t.preventDefault(),e.onContextMenu({clientX:t.clientX,clientY:t.clientY})}:void 0;if(!t.length){let t=[...new Set([...e.live.filter(e=>e.kind===`camera`&&!e.lowOf),...l].map(t=>Te(t,e.live)))].sort();return(0,Q.jsx)(t6,{onContextMenu:u,title:`Choose a camera in this panel's settings`,detail:t.length?t.join(`, `):void 0})}let d={panel:e,recorded:l,recIndex:c};if(t.length===1)return(0,Q.jsx)(e6,{...d,id:t[0],onMenu:u});let f=n&&t.includes(n)?n:null,p=f?[f]:t,{cols:m,rows:h}=Y3(p.length),g=()=>{a(f),r(null)};return(0,Q.jsxs)(`div`,{ref:o,className:`kymo-camera-wall`,style:{gridTemplateColumns:`repeat(${m}, minmax(0, 1fr))`,gridTemplateRows:`repeat(${h}, minmax(0, 1fr))`},onContextMenu:u,onKeyDown:e=>{e.key===`Escape`&&f&&(e.stopPropagation(),g())},children:[p.map(e=>(0,Q.jsx)(e6,{...d,id:e,multi:!0,wall:!f,onPick:f?void 0:()=>{a(null),r(e)}},e)),f?(0,Q.jsxs)(`button`,{type:`button`,className:`kymo-camera__all`,onClick:g,autoFocus:!0,children:[(0,Q.jsxs)(`svg`,{viewBox:`0 0 16 16`,"aria-hidden":`true`,children:[(0,Q.jsx)(`rect`,{x:`2`,y:`2`,width:`5`,height:`5`,rx:`1`}),(0,Q.jsx)(`rect`,{x:`9`,y:`2`,width:`5`,height:`5`,rx:`1`}),(0,Q.jsx)(`rect`,{x:`2`,y:`9`,width:`5`,height:`5`,rx:`1`}),(0,Q.jsx)(`rect`,{x:`9`,y:`9`,width:`5`,height:`5`,rx:`1`})]}),`All cameras`]}):null]})}function e6({panel:e,recorded:t,recIndex:n,id:r,multi:i,wall:a,onPick:o,onMenu:s}){let c=e.recordings??[],l={onMenu:s,wall:a,onPick:o},u=t.find(e=>e.id===r);if(u)return(0,Q.jsx)(n6,{...e,...l,source:u,name:i?Te(u,e.live):u.name,rec:c[n(u)]},`rec:${u.recordingId}:${u.id}`);let d=e.live.find(e=>e.id===r&&e.kind===`camera`);if(d?.limitNotice&&(d.limitNotice===`Video limit reached this month`||!d.video))return(0,Q.jsx)(t6,{onContextMenu:s,title:d.limitNotice,detail:Te(d,e.live)});if(!d?.video||d.status===`error`)return(0,Q.jsx)(t6,{onContextMenu:s,title:`Camera offline`,detail:d?Te(d,e.live):void 0});let f=e.live.find(e=>e.kind===`camera`&&e.lowOf===d.id&&e.video&&e.status!==`error`),p=f?.video?Sw({...f,video:f.video}):void 0;return(0,Q.jsx)(n6,{...e,...l,source:Sw({...d,video:d.video}),low:p,name:i?Te(d,e.live):d.name,conn:d},d.id)}function t6({title:e,detail:t,onContextMenu:n}){return(0,Q.jsx)(`div`,{className:`kymo-camera`,onContextMenu:n,children:(0,Q.jsxs)(`div`,{className:`kymo-camera__empty`,children:[(0,Q.jsxs)(`svg`,{className:`kymo-camera__empty-icon`,viewBox:`0 0 24 24`,"aria-hidden":`true`,children:[(0,Q.jsx)(`rect`,{x:`2.5`,y:`6`,width:`13`,height:`12`,rx:`2.5`}),(0,Q.jsx)(`path`,{d:`M15.5 10.5 21.5 7v10l-6-3.5`})]}),(0,Q.jsx)(`p`,{className:`kymo-camera__empty-title`,children:e}),t?(0,Q.jsx)(`p`,{className:`kymo-camera__empty-detail`,children:t}):null]})})}function n6(e){let{settings:t,source:n}=e,r=e.cursor??Z3,i=(0,Z.useSyncExternalStore)(r.subscribe,r.get),a=e=>e.kind===`data`,o=e.rec?void 0:t.syncStreamId?e.live.find(e=>e.id===t.syncStreamId&&a(e)):e.live.find(t=>t.id===e.conn.parentId&&a(t))??e.live.find(t=>a(t)&&e.selection.includes(t.id))??e.live.find(a),s=i??e.viewXRange?.[1]??null,c=null,l=null,u=o?.clock?.quality()??`none`,d=null;if(e.rec){let{wallOrigin:r,wallQuality:i,xOffset:a}=e.rec;u=i??`none`;let o=n.range()?.[0]??null;s===null?c=o:r===null?(c=o,l=`This recording has no wall clock`):e.xKey===`Time`?d=r+s-a+t.offsetMs/1e3:e.xKey===`ElapsedTime`&&i===`exact`?d=s-a+t.offsetMs/1e3:(c=o,l=`Sync needs a time X axis`)}else s!==null&&(e.xIsTime?(d=o?.clock?.toWall(s,t.offsetMs)??null,d===null&&(l=`No data stream to sync with`)):l=`Sync needs a time X axis`);let f=e.rec?n.dataClockOffsetMs:o?.clockOffsetMs;d!==null&&(c=d+vw(n.sync,d)+yw(n.clockOffsetMs,f));let p=(0,Z.useRef)(null),m=(0,Z.useRef)(null),h=Q3(p),g=h===null?null:e.low&&(h||e.wall)?e.low:n,_=(0,Z.useRef)(t.fit),v=(0,Z.useRef)(c);(0,Z.useLayoutEffect)(()=>{_.current=t.fit,v.current=c});let y=(0,Z.useRef)(null),b=(0,Z.useRef)(null),[x,S]=(0,Z.useState)(null),C=x??g??n,[w,T]=(0,Z.useState)(!1),[E,D]=(0,Z.useState)(!0);(0,Z.useEffect)(()=>{if(!g||y.current?.source===g)return;let e=!y.current,t=null,n=!1,r=()=>t?y.current===t:e,i=t=l6(g,m.current,()=>_.current,v.current,{unsupported:()=>{r()&&T(!0)},buffered:e=>{r()&&D(e)},frame:()=>{if(y.current===t){n||(n=!0,S(g));return}y.current?.dispose(),y.current=i,b.current=null,i.show(),n=!0,S(g),D(i.buffered())}},e);if(e){y.current=i;return}return b.current=i,()=>{y.current!==i&&(i.dispose(),b.current===i&&(b.current=null))}},[g]),(0,Z.useEffect)(()=>()=>{y.current?.dispose(),y.current=null},[]),(0,Z.useEffect)(()=>{y.current?.setTarget(c),b.current?.setTarget(c)},[c]);let O=r6(e.rec||c!==null?null:C),k=i6(e.rec?n:null),A=!!C.lowOf,j=C.info().latestT,M=!e.rec&&c!==null&&j!==null?c-j:null,N=e.rec?`No video at this time`:`Not buffered`;return(0,Q.jsxs)(`div`,{ref:p,className:`kymo-camera${e.onPick?` is-tile`:``}`,onContextMenu:e.onMenu,...e.onPick?{role:`button`,tabIndex:0,"data-camera":n.id,"aria-label":`Show ${e.name} alone`,onClick:e.onPick,onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),e.onPick())}}:{},children:[(0,Q.jsx)(`canvas`,{ref:m,className:`kymo-camera__video`,role:`img`,"aria-label":`Video from ${e.name}`}),w?(0,Q.jsx)(`div`,{className:`kymo-camera__empty`,children:(0,Q.jsx)(`p`,{className:`kymo-camera__empty-title`,children:`This browser can't decode this camera`})}):O===null?(0,Q.jsxs)(`div`,{className:`kymo-camera__overlay`,children:[(0,Q.jsx)(`span`,{className:`kymo-camera__name`,children:e.name}),e.rec?(0,Q.jsx)(`span`,{className:`kymo-camera__rec`,children:`Recording`}):c===null?(0,Q.jsx)(`span`,{className:`kymo-camera__live`,children:`LIVE`}):(0,Q.jsx)(`span`,{className:`kymo-camera__ago`,children:M===null?``:o6(M)}),A?(0,Q.jsx)(`span`,{className:`kymo-camera__badge`,title:`Low-quality copy (small panel)`,children:`LQ`}):null,c!==null&&u!==`none`?(0,Q.jsx)(`span`,{className:`kymo-camera__badge${u===`exact`?` is-exact`:``}`,children:u===`exact`?`Exact`:`Approx.`}):null,l??(c!==null&&!E?N:null)?(0,Q.jsx)(`span`,{className:`kymo-camera__note`,children:l??N}):null,e.conn?.limitNotice?(0,Q.jsx)(`span`,{className:`kymo-camera__note`,role:`status`,children:e.conn.limitNotice}):null,k?.broken?(0,Q.jsx)(`span`,{className:`kymo-camera__note`,role:`status`,title:`Some of this recording was missing, out of order or changed where it is stored (${k.broken} of ${k.broken+k.verified} checked ${k.broken+k.verified===1?`chunk`:`chunks`}). The video may have gaps there.`,children:`Some messages were missing or out of order`}):null]}):(0,Q.jsxs)(`div`,{className:`kymo-camera__empty kymo-camera__empty--cover`,role:`status`,children:[(0,Q.jsx)(`p`,{className:`kymo-camera__empty-title`,children:`No signal`}),(0,Q.jsxs)(`p`,{className:`kymo-camera__empty-detail`,children:[e.name,` · no video for `,a6(O)]})]})]})}function r6(e){let[t]=(0,Z.useState)(()=>Date.now()),[n,r]=(0,Z.useState)(null);return(0,Z.useEffect)(()=>{if(!e){r(null);return}let n=()=>{let{arrivedAt:n,gapMs:i}=e.info(),a=Date.now()-Math.max(n??0,t);r(a>_w(i)?Math.floor(a/1e3):null)};n();let i=setInterval(n,500);return()=>clearInterval(i)},[e,t]),n}function i6(e){let[t,n]=(0,Z.useState)(null);return(0,Z.useEffect)(()=>{if(!e?.integrity){n(null);return}let t=()=>{let t=e.integrity();n(e=>e?.verified===t?.verified&&e?.broken===t?.broken?e:t&&{verified:t.verified,broken:t.broken})};t();let r=setInterval(t,1e3);return()=>clearInterval(r)},[e]),t}function a6(e){return e<60?`${e} s`:e<3600?`${Math.floor(e/60)} min`:`${Math.floor(e/3600)} h`}function o6(e){let t=Math.abs(e).toFixed(1);return t===`0.0`?`0.0 s`:`${e<0?`−`:`+`}${t} s`}var s6=60,c6=.05;function l6(e,t,n,r,i,a=!0){let o=e.acquire?.(),s=!1,c=!0,l=e=>{c=e,i.buffered(e)},u=null,d=null,f=r,p=`live`,m=!0,h=!1,g=!1,_=null,v=null,y=null,b=[],x=uZ(),S=NaN,C=[],w=()=>{for(let e of b)e.close();b=[]},T=e=>{if(s){e.close();return}if(p===`seek`){_?.close(),_=e;return}for(b.push(e);b.length>(a?s6:1);)b.shift().close();i.frame?.()},E=e=>{if(!b.length)return;let t=b[b.length-1].timestamp/1e6,n=Number.isNaN(S)?16:e-S,r=Math.max(EZ(x,t,n,e=>{let t=b.find(t=>t.timestamp/1e6>e);return t?t.timestamp/1e6:NaN}),t-c6);x.d=r;let i=-1;for(;i+1<b.length&&b[i+1].timestamp/1e6<=r+1e-6;)i++;if(!(i<0)){for(let e=0;e<i;e++)b[e].close();v?.close(),v=b[i],b=b.slice(i+1)}},D=()=>{!d||d.state===`closed`?d=new VideoDecoder({output:T,error:()=>{}}):d.reset(),d.configure(u),m=!0},O=e=>{d?.state===`closed`&&e.key&&D(),!(d?.state!==`configured`||m&&!e.key)&&(m=!1,d.decode(new EncodedVideoChunk({type:e.key?`key`:`delta`,timestamp:Math.round(e.t*1e6),data:e.data})))},k=()=>{p=`live`,l(!0),w(),x=uZ(),D();for(let t of e.livePlan?.()??[])O(t)},A=async()=>{if(!h){h=!0;try{for(;!s&&p===`seek`&&g;){g=!1;let t=[];try{t=await e.seekPlan(f)}catch{}if(!(s||p!==`seek`||g)&&(l(t.length>0),t.length)){D();for(let e of t)O(e);try{await d.flush()}catch{}p===`seek`&&_&&(v?.close(),v=_,_=null,i.frame?.())}}}finally{h=!1,_?.close(),_=null}}},j=()=>{f===null?p!==`live`&&k():(p=`seek`,w(),g=!0,A())};e.onUnit&&C.push(e.onUnit(e=>{u&&p===`live`&&O(e)})),(async()=>{if(typeof VideoDecoder>`u`){i.unsupported();return}if(e.info().codec||(e.ready?await e.ready():e.onUnit&&await new Promise(t=>{let n=e.onUnit(()=>{e.info().codec&&(n(),t())});C.push(n)})),s)return;if(!e.info().codec){l(!1);return}let t={codec:e.info().codec,optimizeForLatency:!0,hardwareAcceleration:`no-preference`},n=!1;try{n=(await VideoDecoder.isConfigSupported(t)).supported===!0}catch{}if(!s){if(!n){i.unsupported();return}u=t,f===null?k():j()}})();let M=n(),N=()=>{if(!a)return;let e=window.devicePixelRatio||1,r=Math.max(1,Math.round(t.clientWidth*e)),i=Math.max(1,Math.round(t.clientHeight*e)),o=!1,s=performance.now();if(p===`live`&&E(s),S=s,(t.width!==r||t.height!==i)&&(t.width=r,t.height=i,o=!0),v&&(y?.close(),y=v,v=null,o=!0),n()!==M&&(M=n(),o=!0),!o||!y)return;let c=t.getContext(`2d`);if(!c)return;let l=y.displayWidth,u=y.displayHeight,d=M===`cover`?Math.max(r/l,i/u):Math.min(r/l,i/u),f=l*d,m=u*d;c.clearRect(0,0,r,i),c.drawImage(y,(r-f)/2,(i-m)/2,f,m)},P=0,F=()=>{P=RX(F),N()};return P=RX(F),{source:e,show(){a=!0},buffered:()=>c,setTarget(e){e!==f&&(f=e,u&&j())},dispose(){s=!0,zX(P),C.forEach(e=>e()),d&&d.state!==`closed`&&d.close();for(let e of[_,v,y])e?.close();_=v=y=null,w(),o?.()}}}function u6(e,t){let n=e.filter(e=>e.x.length>=2&&d6(e.x));if(n.length<2)return null;let r=1/0,i=-1/0;for(let e of n)e.x[0]<r&&(r=e.x[0]),e.x[e.x.length-1]>i&&(i=e.x[e.x.length-1]);if(!(i>r))return null;let a=Math.max(2,t),o=Float64Array.from({length:a},(e,t)=>r+t/(a-1)*(i-r)),s=new Float64Array(a).fill(1/0),c=new Float64Array(a).fill(-1/0),l=new Uint16Array(a);for(let e of n){let t=0;for(let n=0;n<a;n++){let r=o[n];if(r<e.x[0]||r>e.x[e.x.length-1])continue;for(;t<e.x.length-2&&e.x[t+1]<r;)t++;let i=e.x[t],a=e.x[t+1],u=e.y[t],d=e.y[t+1],f=a===i?u:u+(d-u)*(r-i)/(a-i);f-f===0&&(f<s[n]&&(s[n]=f),f>c[n]&&(c[n]=f),l[n]++)}}for(let e=0;e<a;e++)l[e]<2&&(s[e]=NaN,c[e]=NaN);return{x:o,lo:s,hi:c}}function d6(e){for(let t=1;t<e.length;t++)if(!(e[t]>=e[t-1]))return!1;return!0}function f6(e){if(e.length===0)return null;if(e.length===1)return e[0];let t=new Set,n={};for(let r of e)for(let e=0;e<r.columnNames.length;e++){let i=r.columnNames[e];t.add(i),r.units[e]?.trim()&&(n[i]=r.units[e])}let r=[...t];return{meta:``,columnNames:r,units:r.map(e=>n[e]??``),rows:e.flatMap(e=>e.rows)}}QG(),gK();function p6(e,t,n,r,i){return n||e.length===0||(t>0?e.length!==1:e.length<2||r!==`ElapsedTime`)?null:e.map((e,n)=>({conn:e,keySuffix:`__${t+n}`,offset:i[e.id]??0}))}function m6(e,t,n,r,i){if(e.length===1){let a=e[0];return h6(a.conn,t,n,a.keySuffix,a.offset,r,i)}let a=e.map(e=>h6(e.conn,t,n,e.keySuffix,e.offset,[],null)),o=()=>a.reduce((e,t)=>t.latestT()>e.latestT()?t:e);return{pull:(e,t,n,i)=>[...r,...a.flatMap(r=>r.pull(e,t,n,i))],xBounds:()=>{let e=i;for(let t of a){let n=t.xBounds();n&&(e=e?[Math.min(e[0],n[0]),Math.max(e[1],n[1])]:n)}return e},latestX:()=>o().latestX(),version:()=>a.reduce((e,t)=>e+t.version(),0),latestT:()=>o().latestT(),timeAfter:e=>o().timeAfter(e),xAtTime:e=>o().xAtTime(e),latestValues:e=>new Map(a.flatMap(t=>[...t.latestValues(e)]))}}function h6(e,t,n,r,i,a,o){let s=null;return{pull:(o,c,l,u)=>{let d=e.source.version();if(!s||s.ver!==d||s.x0!==o||s.x1!==c||s.mp!==l){let a=e.source.getPointsSync(n,{xKey:t,x0:o-i,x1:c-i},l),u=i===0?a.x:a.x.map(e=>e+i);s={ver:d,x0:o,x1:c,mp:l,pts:{...a,x:u,cols:new Map([...a.cols].map(([e,t])=>[e+r,t]))}}}let f=WG(s.pts,u);if(t!==`ElapsedTime`)return[...a,f];let p=Math.min(e.source.latestTimeSync(),u===void 0?1/0:u-i),m=UG(n,t=>e.source.lastKnownSync(t),o-i,c-i,p);if(!m)return[...a,f];let h=i===0?m.x:m.x.map(e=>e+i);return[...a,f,{...m,x:h,cols:new Map([...m.cols].map(([e,t])=>[e+r,t]))}]},xBounds:()=>{let n=e.source.xBoundsSync(t);return n.x1>n.x0?o?[Math.min(o[0],n.x0+i),Math.max(o[1],n.x1+i)]:[n.x0+i,n.x1+i]:o},latestX:()=>{let n=e.source.latestSync(t);return Number.isFinite(n)?n+i:null},version:()=>e.source.version(),id:e.id,latestT:()=>e.source.latestTimeSync(),timeAfter:t=>e.source.timeAfterSync(t),xAtTime:n=>e.source.xAtTimeSync(t,n)+i,latestValues:t=>{let n=new Map,i=t.filter(e=>e.endsWith(r)),a=e.source.latestValuesSync(i.map(e=>e.slice(0,-r.length)));for(let e of i){let t=a.get(e.slice(0,-r.length));t!==void 0&&n.set(e,t)}return n}}}xE();function g6(e,t){return e.filter(e=>mE(t,e))}QG();var _6=`__ref`,v6=8e3;function y6(e,t){return e.map(e=>({...e,id:`${e.id}${_6}`,column:`${e.column}${_6}`,color:t}))}var b6=new WeakMap;function x6(e,t,n){let r=e.data.rows,i=`${t}\n${n.join(`
|
|
628
|
-
`)}`,a=
|
|
627
|
+
}`,R0=-3e38;function z0(e){for(let t=0;t<e.length;t++)if(e[t]-e[t]===0)return e[t];return 0}function B0(e){let t=e.getContext(`webgl2`,{antialias:!1,alpha:!0,premultipliedAlpha:!0});if(!t)return null;let n=(e,n,i,a)=>MX(t,`glPlot|${e}|${n}`,()=>r(e,n,i,a)),r=(e,n,r,i)=>{let a=bX(t,t.VERTEX_SHADER,e),o=bX(t,t.FRAGMENT_SHADER,n);if(!a||!o)return null;let s=t.createProgram();if(t.attachShader(s,a),t.attachShader(s,o),t.linkProgram(s),!t.getProgramParameter(s,t.LINK_STATUS))return console.error(`glPlot program link failed:`,t.getProgramInfoLog(s)),null;let c=[`u_resolution`,`u_plot`,`u_view`,`u_clip`,`u_dpr`,`u_height`];return{prog:s,shaders:[a,o],a:Object.fromEntries([`a_corner`,...r].map(e=>[e,t.getAttribLocation(s,e)])),u:Object.fromEntries([...c,...i].map(e=>[e,t.getUniformLocation(s,e)]))}},i=n(A0,M0,[`a_xa`,`a_xb`,`a_loa`,`a_lob`,`a_hia`,`a_hib`,`a_bstart`],[`u_color`]),a=n(j0,N0,[`a_x0`,`a_x1`,`a_y0`,`a_y1`,`a_k`],[`u_palette`]),o=n(P0,F0,[`a_ax`,`a_ay`,`a_bx`,`a_by`,`a_bstart`],[`u_color`,`u_half`,`u_ext`]),s=n(I0,L0,[],[`u_extent`,`u_values`,`u_palette`,`u_range`]);if(!i||!a||!o||!s)return null;let c=t.getParameter(t.MAX_TEXTURE_SIZE),l=t.createVertexArray(),u=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,u),t.bufferData(t.ARRAY_BUFFER,Float32Array.from([0,0,1,0,0,1,1,1]),t.STATIC_DRAW);let d=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,d),t.bufferData(t.ARRAY_BUFFER,Float32Array.from([-1,-1,1,-1,-1,1,1,1]),t.STATIC_DRAW);let f=new Map,p=1,m=1,h=1,g={xmin:0,xmax:1,ymin:0,ymax:1},_={left:0,top:0,width:1,height:1},v=new WeakMap,y=new Float32Array,b=e=>{for(let n of Object.values(e.buffers))t.deleteBuffer(n);e.palette&&t.deleteTexture(e.palette),e.values&&t.deleteTexture(e.values)},x=new Float32Array,S=(e,n)=>{t.bindTexture(t.TEXTURE_2D,e),t.texImage2D(t.TEXTURE_2D,0,t.RGBA8,256,1,0,t.RGBA,t.UNSIGNED_BYTE,n),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE)},C=(e,t)=>{let n=f.get(e);if(n&&n.kind===t)return n;n&&b(n);let r={kind:t,n:0,ox:0,oy:0,buffers:{},color:[0,0,0,1],width:1};return f.set(e,r),r},w=(e,n,r)=>{let i=e.buffers[n]??=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,i),r.byteLength<=(v.get(i)??0)?t.bufferSubData(t.ARRAY_BUFFER,0,r):(t.bufferData(t.ARRAY_BUFFER,r,t.DYNAMIC_DRAW),v.set(i,r.byteLength))},T=(e,t,n,r)=>{let i=n.length;y.length<i&&(y=new Float32Array(i));for(let e=0;e<i;e++)y[e]=n[e]-r;w(e,t,y.subarray(0,i))},E=(e,t,n)=>{let r=new Uint8Array(e);t&&r.set(t.subarray(0,e)),e&&(r[0]=255);for(let t=0;t<e;t++)n(t)||(r[t]=255,t+1<e&&(r[t+1]=255));return r},D=(e,n,r=0,i=t.FLOAT)=>{if(e<0)return;t.bindBuffer(t.ARRAY_BUFFER,n),t.enableVertexAttribArray(e);let a=i===t.FLOAT?4:1;t.vertexAttribPointer(e,1,i,i!==t.FLOAT,a,r*a),t.vertexAttribDivisor(e,1)},O=(n,r,i)=>{t.useProgram(n.prog),t.uniform2f(n.u.u_resolution,p,m),t.uniform4f(n.u.u_plot,_.left,_.top,_.width,_.height),t.uniform4f(n.u.u_view,g.xmin-r.ox,g.xmax-r.ox,g.ymin-r.oy,g.ymax-r.oy),t.uniform4f(n.u.u_clip,_.left,_.top,_.left+_.width,_.top+_.height),t.uniform1f(n.u.u_dpr,h),t.uniform1f(n.u.u_height,e.height),t.bindBuffer(t.ARRAY_BUFFER,i),t.enableVertexAttribArray(n.a.a_corner),t.vertexAttribPointer(n.a.a_corner,2,t.FLOAT,!1,0,0),t.vertexAttribDivisor(n.a.a_corner,0)},k=e=>{for(let n of Object.values(e.a))n>=0&&t.vertexAttribDivisor(n,0)};return{resize(t,n,r){p=Math.max(1,t),m=Math.max(1,n),h=r,e.width=Math.round(p*h),e.height=Math.round(m*h)},setView(e,t,n,r,i){g={xmin:e,xmax:t,ymin:n,ymax:r},_=i},setBands(e,t,n,r,i,a){let o=C(e,`bands`),s=Math.min(t.length,n.length,r.length);o.ox=z0(t),o.oy=z0(r),T(o,`x`,t,o.ox),T(o,`lo`,n,o.oy),T(o,`hi`,r,o.oy),w(o,`start`,E(s,a,e=>t[e]-t[e]===0&&n[e]-n[e]===0&&r[e]-r[e]===0)),o.n=Math.max(0,s-1),o.color=i},setRects(e,n,r,i,a,o,s){let c=C(e,`rects`),l=Math.min(n.length,r.length,i.length,a.length);c.ox=z0(n),c.oy=z0(i),T(c,`x0`,n,c.ox),T(c,`x1`,r,c.ox),T(c,`y0`,i,c.oy),T(c,`y1`,a,c.oy),s?T(c,`k`,s,0):delete c.buffers.k;let u=new Uint8Array(256*4);for(let e=0;e<256;e++){let t=o[Math.min(e,o.length-1)]??[0,0,0,1];u.set([t[0]*255,t[1]*255,t[2]*255,t[3]*255],e*4)}c.palette??=t.createTexture(),t.bindTexture(t.TEXTURE_2D,c.palette),t.texImage2D(t.TEXTURE_2D,0,t.RGBA8,256,1,0,t.RGBA,t.UNSIGNED_BYTE,u),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),c.n=l},setLine(e,t,n,r,i,a){let o=C(e,`line`),s=Math.min(t.length,n.length);o.ox=z0(t),o.oy=z0(n),T(o,`x`,t,o.ox),T(o,`y`,n,o.oy),w(o,`start`,E(s,a,e=>t[e]-t[e]===0&&n[e]-n[e]===0)),o.n=Math.max(0,s-1),o.color=r,o.width=i},maxTextureSize:c,setGrid(e,n,r,i,a,o,s,c){let l=C(e,`grid`),u=r*i,d=0;for(let e=0;e<u;e++)d+=n[e]*0;let f=n.subarray(0,u);if(d!==0){x.length<u&&(x=new Float32Array(u));for(let e=0;e<u;e++){let t=n[e];x[e]=t===t?t:R0}f=x.subarray(0,u)}let p=!l.values;l.values??=t.createTexture(),t.bindTexture(t.TEXTURE_2D,l.values),t.pixelStorei(t.UNPACK_ALIGNMENT,4),!p&&l.grid&&l.grid.w===r&&l.grid.h===i?t.texSubImage2D(t.TEXTURE_2D,0,0,0,r,i,t.RED,t.FLOAT,f):(t.texImage2D(t.TEXTURE_2D,0,t.R32F,r,i,0,t.RED,t.FLOAT,f),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE)),l.palette??=t.createTexture(),S(l.palette,o);let[m,h,g,_]=a;l.ox=m,l.oy=g,l.grid={w:r,h:i,x0:m,x1:h,y0:g,y1:_,vmin:s,vmax:c},l.n=1},setGridRange(e,t,n){let r=f.get(e);r?.grid&&(r.grid.vmin=t,r.grid.vmax=n)},remove(e){let t=f.get(e);t&&(b(t),f.delete(e))},keep(e){let t=new Set(e);for(let e of[...f.keys()])t.has(e)||this.remove(e)},render(){t.bindFramebuffer(t.FRAMEBUFFER,null),t.viewport(0,0,e.width,e.height),t.disable(t.SCISSOR_TEST),t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT),t.bindVertexArray(l),t.enable(t.BLEND),t.blendFunc(t.ONE,t.ONE_MINUS_SRC_ALPHA);for(let e of f.values()){if(e.n<=0)continue;let n=e.buffers;if(e.kind===`bands`)O(i,e,u),t.uniform4f(i.u.u_color,...e.color),D(i.a.a_xa,n.x,0),D(i.a.a_xb,n.x,1),D(i.a.a_loa,n.lo,0),D(i.a.a_lob,n.lo,1),D(i.a.a_hia,n.hi,0),D(i.a.a_hib,n.hi,1),D(i.a.a_bstart,n.start,1,t.UNSIGNED_BYTE),t.drawArraysInstanced(t.TRIANGLE_STRIP,0,4,e.n),k(i);else if(e.kind===`grid`){let n=e.grid;O(s,e,u),t.uniform4f(s.u.u_extent,0,n.x1-n.x0,0,n.y1-n.y0),t.uniform2f(s.u.u_range,n.vmin,n.vmax),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,e.values),t.uniform1i(s.u.u_values,0),t.activeTexture(t.TEXTURE1),t.bindTexture(t.TEXTURE_2D,e.palette),t.uniform1i(s.u.u_palette,1),t.drawArrays(t.TRIANGLE_STRIP,0,4),t.activeTexture(t.TEXTURE0)}else e.kind===`rects`?(O(a,e,u),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,e.palette),t.uniform1i(a.u.u_palette,0),D(a.a.a_x0,n.x0),D(a.a.a_x1,n.x1),D(a.a.a_y0,n.y0),D(a.a.a_y1,n.y1),n.k?D(a.a.a_k,n.k):(t.disableVertexAttribArray(a.a.a_k),t.vertexAttrib1f(a.a.a_k,0)),t.drawArraysInstanced(t.TRIANGLE_STRIP,0,4,e.n),k(a)):(O(o,e,d),t.uniform4f(o.u.u_color,...e.color),t.uniform1f(o.u.u_half,e.width/2),t.uniform1f(o.u.u_ext,e.width/2+1.5),D(o.a.a_ax,n.x,0),D(o.a.a_bx,n.x,1),D(o.a.a_ay,n.y,0),D(o.a.a_by,n.y,1),D(o.a.a_bstart,n.start,1,t.UNSIGNED_BYTE),t.drawArraysInstanced(t.TRIANGLE_STRIP,0,4,e.n),k(o))}t.bindVertexArray(null)},dispose(){for(let e of f.values())b(e);f.clear(),t.deleteBuffer(u),t.deleteBuffer(d),t.deleteVertexArray(l)}}}function V0(e){let t=(0,Z.useRef)({plot:null,failed:!1,size:``});return(0,Z.useEffect)(()=>()=>{t.current.plot?.dispose(),t.current.plot=null},[]),(0,Z.useCallback)((n,r)=>{let i=t.current,a=e.current;if(!i.plot&&!i.failed&&a&&(i.plot=NX(a,B0),i.failed=!i.plot),!i.plot||!a)return null;let o=Math.min(2,window.devicePixelRatio||1),s=`${n}x${r}@${o}`;return i.size!==s&&(i.plot.resize(n,r,o),a.style.width=`${n}px`,a.style.height=`${r}px`,i.size=s),i.plot},[e])}function H0(e){let t=!1;for(let n=0;n<e.length;n++)if(Math.abs(e[n])>Math.PI*2){t=!0;break}let n=new Float64Array(e.length);for(let r=0;r<e.length;r++)n[r]=t?e[r]*Math.PI/180:e[r];return n}var U0=16;function W0(e,t,n,r){let i=H0(e),a=Math.min(i.length,t.length),o=1/0,s=-1/0;for(let e=0;e<a;e++){let n=t[e];n<o&&(o=n),n>s&&(s=n)}let c=n??Math.min(0,o),l=r??s,u=l-c||1,d=new Float64Array(a),f=new Float64Array(a),p=new Float64Array(U0),m=new Int32Array(U0);for(let e=0;e<a;e++){let n=Math.max(0,(t[e]-c)/u),r=i[e];n>1.0001?d[e]=f[e]=NaN:(d[e]=Math.sin(r)*n,f[e]=Math.cos(r)*n);let a=r%(2*Math.PI);a<0&&(a+=2*Math.PI);let o=Math.min(U0-1,Math.floor(a/(2*Math.PI)*U0));p[o]+=t[e],m[o]++}return{n:a,rMin:c,rMax:l,x:d,y:f,means:Array.from({length:U0},(e,t)=>m[t]>0?p[t]/m[t]:0)}}function G0({angles:e,radii:t,angleLabel:n,radiusLabel:r,color:i=`#a78bfa`,mode:a=`waveform`,radiusMin:o,radiusMax:s,height:c=400,backgroundToken:l=``,onPlotContextMenu:u}){let d=(0,Z.useRef)(null),f=(0,Z.useRef)(null),p=(0,Z.useRef)(null),m=(0,Z.useRef)(u);(0,Z.useLayoutEffect)(()=>{m.current=u},[u]);let h=(0,Z.useRef)({angles:e,radii:t,angleLabel:n,radiusLabel:r,color:i,mode:a,radiusMin:o,radiusMax:s,height:c});(0,Z.useLayoutEffect)(()=>{h.current={angles:e,radii:t,angleLabel:n,radiusLabel:r,color:i,mode:a,radiusMin:o,radiusMax:s,height:c}},[e,t,n,r,i,a,o,s,c]);let g=(0,Z.useMemo)(()=>W0(e,t,o,s),[e,t,o,s]),_=(0,Z.useRef)(g);(0,Z.useLayoutEffect)(()=>{_.current=g},[g]);let v=(0,Z.useRef)(null),y=V0(v),b=(0,Z.useRef)({geo:null,color:``});function x(){if(p.current)return p.current;let e=f.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return p.current=n,n}function S(){let e=f.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||h.current.height)}}function C(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function w(){let e=d.current;if(!e)return;let{w:t,h:n}=S(),r=C(e,t,n);if(!r)return;let{bg:i,muted:a,grid:o}=x(),{angleLabel:s,radiusLabel:c,color:l,mode:u}=h.current,f=_.current,{n:p,rMin:m,rMax:g}=f;r.fillStyle=i,r.fillRect(0,0,t,n);let v=y(t,n);if(p===0){v?.keep([]),v?.render(),r.fillStyle=a,r.font=`13px ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,eX(r);return}let w=g-m||1,T=(Math.min(t-64,n-32-24)-4)/2,E=t/2,D=32+T,O=MJ(w,4),k=FJ(m,g,O);r.strokeStyle=o,r.lineWidth=1,r.setLineDash([3,3]);for(let e of k){let t=(e-m)/w*T;t<0||(r.beginPath(),r.arc(E,D,t,0,Math.PI*2),r.stroke())}r.setLineDash([]),r.strokeStyle=o,r.lineWidth=1;for(let e=0;e<360;e+=30){let t=e*Math.PI/180;r.beginPath(),r.moveTo(E,D),r.lineTo(E+Math.cos(-t+Math.PI/2)*T,D+Math.sin(-t+Math.PI/2)*T),r.stroke()}r.fillStyle=a,r.font=`10px ${X.mono}`,r.textAlign=`center`,r.textBaseline=`middle`;for(let e=0;e<360;e+=30){let t=e*Math.PI/180,n=E+Math.sin(t)*(T+14),i=D-Math.cos(t)*(T+14);r.fillText(`${e}°`,n,i)}r.textAlign=`left`,r.textBaseline=`middle`;for(let e of k){let t=(e-m)/w*T;t<4||r.fillText(zJ(e,O),E+4,D-t)}if(r.strokeStyle=a,r.lineWidth=1,r.setLineDash([]),r.beginPath(),r.arc(E,D,T,0,Math.PI*2),r.stroke(),r.save(),r.beginPath(),r.arc(E,D,T,0,Math.PI*2),r.clip(),u===`waveform`)if(v)(b.current.geo!==f||b.current.color!==l)&&(v.setLine(`wave`,f.x,f.y,e0(l,.9),1),b.current={geo:f,color:l}),v.keep([`wave`]),v.setView(-1,1,-1,1,{left:E-T,top:D-T,width:T*2,height:T*2}),v.render();else{r.strokeStyle=l,r.lineWidth=1,r.globalAlpha=.9,r.beginPath();let e=!1;for(let t=0;t<p;t++){let n=E+f.x[t]*T,i=D-f.y[t]*T;if(n!==n){e=!1;continue}e?r.lineTo(n,i):(r.moveTo(n,i),e=!0)}r.stroke(),r.globalAlpha=1}else{v?.keep([]),v?.render();let e=f.means,t=Math.max(...e,1e-10),n=2*Math.PI/U0;r.fillStyle=l,r.globalAlpha=.75;for(let i=0;i<U0;i++){let a=e[i]/t*T,o=i*n-Math.PI/2-n/2;r.beginPath(),r.moveTo(E,D),r.arc(E,D,a,o,o+n),r.closePath(),r.fill()}r.globalAlpha=1,r.strokeStyle=l,r.lineWidth=.5,r.globalAlpha=.4;for(let i=0;i<U0;i++){let a=e[i]/t*T,o=i*n-Math.PI/2-n/2;r.beginPath(),r.moveTo(E,D),r.arc(E,D,a,o,o+n),r.closePath(),r.stroke()}r.globalAlpha=1}r.restore(),r.fillStyle=a,r.font=`11px ${X.mono}`,r.textAlign=`center`,r.textBaseline=`bottom`,r.fillText(`${s} / ${c}`,E,n-4)}let T=(0,Z.useRef)(w);T.current=w;let E=(0,Z.useRef)(null);E.current??=mZ(()=>T.current(),()=>f.current);let D=()=>E.current.schedule();return(0,Z.useEffect)(()=>{E.current.now()}),(0,Z.useEffect)(()=>()=>E.current?.cancel(),[]),(0,Z.useEffect)(()=>{p.current=null,D()},[l]),(0,Z.useLayoutEffect)(()=>{let e=f.current;if(!e)return;let t=new fZ(()=>{p.current=null,D()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{let e=d.current;if(!e)return;let t=e=>{e.preventDefault(),m.current?.({clientX:e.clientX,clientY:e.clientY})};return e.addEventListener(`contextmenu`,t),()=>e.removeEventListener(`contextmenu`,t)},[]),(0,Q.jsxs)(`div`,{ref:f,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:d,className:`chart-canvas`,role:`img`,"aria-label":`Polar chart: ${n} vs ${r}`}),(0,Q.jsx)(`canvas`,{ref:v,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}})]})}function K0(e,t,n,r,i){let a=Math.min(e.length,t.length),o=(t,n)=>{let r=0,i=a;for(;r<i;){let a=r+i>>>1;(n?e[a]<=t:e[a]<t)?r=a+1:i=a}return r},s=o(n,!1),c=o(r,!0),l=Math.max(0,s-1),u=Math.min(a,c+1);if(u-l<=2*i){let e=new Uint32Array(u-l);for(let t=0;t<e.length;t++)e[t]=l+t;return e}let d=new Uint32Array(2*i+2),f=0;s>0&&(d[f++]=s-1);let p=(r-n)/i,m=s;for(let r=0;r<i&&m<c;r++){let a=r===i-1?1/0:n+(r+1)*p,o=1/0,s=-1/0,l=-1,u=-1;for(;m<c&&e[m]<a;m++){let e=t[m];e<o&&(o=e,l=m),e>s&&(s=e,u=m)}l<0||(l===u?d[f++]=l:l<u?(d[f++]=l,d[f++]=u):(d[f++]=u,d[f++]=l))}return c<a&&(d[f++]=c),d.subarray(0,f)}function q0(e,t){let n=e.length;if(n<=2*t)return Uint32Array.from({length:n},(e,t)=>t);let r=new Uint32Array(2*t),i=0;for(let a=0;a<t;a++){let o=Math.floor(a*n/t),s=Math.floor((a+1)*n/t),c=1/0,l=-1/0,u=-1,d=-1;for(let t=o;t<s;t++){let n=e[t];n<c&&(c=n,u=t),n>l&&(l=n,d=t)}u<0||(u===d?r[i++]=u:u<d?(r[i++]=u,r[i++]=d):(r[i++]=d,r[i++]=u))}return r.subarray(0,i)}function J0(e,t){let n=new Float64Array(t.length);for(let r=0;r<t.length;r++)n[r]=e[t[r]];return n}function Y0(e){for(let t=1;t<e.length;t++)if(!(e[t]>=e[t-1]))return!1;return e.length===0||e[0]===e[0]}function X0(e,t){let n=e.length;for(let r=1,i=0;r<n;r++){let a=n>>1;for(;i&a;a>>=1)i^=a;if(i^=a,r<i){let n=e[r];e[r]=e[i],e[i]=n,n=t[r],t[r]=t[i],t[i]=n}}for(let r=2;r<=n;r<<=1){let i=r>>1,a=-2*Math.PI/r,o=Math.cos(a),s=Math.sin(a);for(let a=0;a<n;a+=r){let n=1,r=0;for(let c=0;c<i;c++){let l=a+c,u=l+i,d=e[u]*n-t[u]*r,f=e[u]*r+t[u]*n;e[u]=e[l]-d,t[u]=t[l]-f,e[l]+=d,t[l]+=f;let p=n*o-r*s;r=n*s+r*o,n=p}}}}var Z0=new Float64Array,Q0=new Float64Array;function $0(e,t,n){let r=t>>1;Z0.length<r&&(Z0=new Float64Array(r),Q0=new Float64Array(r));let i=Z0.subarray(0,r),a=Q0.subarray(0,r),o=e.length;for(let t=0;t<r;t++){let r=2*t,s=r+1;i[t]=r<o?e[r]*(n?n[r]:1):0,a[t]=s<o?e[s]*(n?n[s]:1):0}X0(i,a);let s=new Float64Array(r),c=-2*Math.PI/t,l=Math.cos(c),u=Math.sin(c),d=1,f=0;for(let e=0;e<r;e++){let t=e===0?0:r-e,n=i[e],o=a[e],c=i[t],p=-a[t],m=(n+c)/2,h=(o+p)/2,g=(o-p)/2,_=-(n-c)/2,v=m+d*g-f*_,y=h+d*_+f*g;s[e]=Math.sqrt(v*v+y*y);let b=d*l-f*u;f=d*u+f*l,d=b}return s}var e2=new Float64Array,t2=0;function n2(e){if(t2===e)return e2.subarray(0,e);e2.length<e&&(e2=new Float64Array(Math.max(e,e2.length*2)));let t=2*Math.PI/Math.max(1,e-1),n=Math.cos(t),r=Math.sin(t),i=1,a=0;for(let t=0;t<e;t++){e2[t]=.5*(1-i);let e=i*n-a*r;a=a*n+i*r,i=e}return t2=e,e2.subarray(0,e)}var r2={top:14,right:24,bottom:40,left:64},i2=5;function a2(e){let t=1;for(;t<e;)t<<=1;return t}function o2(e,t,n,r){let i=e.length,a=Math.max(2,a2(i)),o=$0(e,a,n===`hann`?n2(i):void 0),s=a/2,c=new Float64Array(s),l=2/a;for(let e=0;e<s;e++){c[e]=e*t/a;let n=o[e]*l;o[e]=r===`db`?20*Math.log10(Math.max(n,1e-12)):n}return{freqs:c,amps:o}}function s2({signal:e,sampleRate:t=1,label:n,xMode:r=`hz`,yMode:i=`amplitude`,window:a=`hann`,color:o=`#34d399`,logX:s=!1,height:c=400,backgroundToken:l=``,onPlotContextMenu:u}){let d=iQ(),f=(0,Z.useRef)(null),p=(0,Z.useRef)(null),m=(0,Z.useRef)(null),h=(0,Z.useRef)(u);(0,Z.useLayoutEffect)(()=>{h.current=u},[u]);let g=(0,Z.useRef)({signal:e,sampleRate:t,label:n,xMode:r,yMode:i,window:a,color:o,logX:s,height:c});(0,Z.useLayoutEffect)(()=>{g.current={signal:e,sampleRate:t,label:n,xMode:r,yMode:i,window:a,color:o,logX:s,height:c}},[e,t,n,r,i,a,o,s,c]);let _=(0,Z.useMemo)(()=>e.length>=4?o2(e,t,a,i):null,[e,t,a,i]),v=(0,Z.useMemo)(()=>_&&s?_.freqs.map(e=>Math.log10(e)):null,[_,s]),y=(0,Z.useRef)(_&&{..._,logFreqs:v});(0,Z.useLayoutEffect)(()=>{y.current=_&&{..._,logFreqs:v}},[_,v]);function b(){if(m.current)return m.current;let e=p.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return m.current=n,n}function x(){let e=p.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||g.current.height)}}function S(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function C(){let e=f.current;if(!e)return;let{w:t,h:n}=x(),r=S(e,t,n);if(!r)return;let{top:i,right:a,bottom:o,left:s}=r2,c=t-s-a,l=n-i-o,{bg:u,muted:p,grid:m}=b(),{sampleRate:h,label:_,xMode:v,yMode:C,color:w,logX:T}=g.current,E=y.current;if(r.fillStyle=u,r.fillRect(0,0,t,n),!E||c<=0||l<=0){r.fillStyle=p,r.font=`13px ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,eX(r);return}let{freqs:D,amps:O,logFreqs:k}=E,A=D.length,j=v===`hz`?`${_} (Hz)`:`${_} (order)`,M=v===`order`&&h>0?h:1,N=D[1]/M,P=D[A-1]/M,F=1/0,I=-1/0;for(let e=1;e<A;e++)O[e]<F&&(F=O[e]),O[e]>I&&(I=O[e]);if(!Number.isFinite(F)||!Number.isFinite(I)){r.fillStyle=p,r.font=`13px ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,eX(r);return}let L=(I-F)*.05||.1;F-=L,I+=L;let R=T?e=>{if(e<=0||N<=0)return s;let t=Math.log10(N),n=Math.log10(P);return s+(Math.log10(e)-t)/(n-t)*c}:e=>s+(e-N)/(P-N)*c;T&&N<=0&&(N=D[1]>0?D[1]/M:.001),d({left:s,top:i,width:c,height:l,x:{v0:N,v1:P,log:T},y:{v0:F,v1:I}});let z=e=>i+(I-e)/(I-F)*l,B=MJ(I-F,5),V=FJ(F,I,B);r.strokeStyle=m,r.lineWidth=1,r.setLineDash([3,3]);for(let e of V)r.beginPath(),r.moveTo(s,z(e)),r.lineTo(s+c,z(e)),r.stroke();r.setLineDash([]);let ee=T?1:MJ(P-N,NJ(c)),H=T?(()=>{let e=[],t=Math.ceil(Math.log10(Math.max(N,1e-12))),n=Math.floor(Math.log10(P));for(let r=t;r<=n;r++)for(let t of[1,2,5]){let n=t*10**r;n>=N&&n<=P&&e.push(n)}return e})():FJ(N,P,ee);r.strokeStyle=m,r.lineWidth=1,r.setLineDash([3,3]);for(let e of H)r.beginPath(),r.moveTo(R(e),i),r.lineTo(R(e),i+l),r.stroke();r.setLineDash([]),r.strokeStyle=p,r.lineWidth=1,r.fillStyle=p,r.font=`11px ${X.mono}`,r.textAlign=`right`,r.textBaseline=`middle`;for(let e of V)r.beginPath(),r.moveTo(s-i2,z(e)),r.lineTo(s,z(e)),r.stroke(),r.fillText(zJ(e,B),s-4,z(e));r.textAlign=`center`,r.textBaseline=`top`;for(let e of H)r.beginPath(),r.moveTo(R(e),i+l),r.lineTo(R(e),i+l+i2),r.stroke(),r.fillText(zJ(e,T?e:ee),R(e),i+l+i2+2);r.strokeStyle=m,r.lineWidth=1,r.strokeRect(s,i,c,l),r.save(),r.beginPath(),r.rect(s,i,c,l),r.clip(),r.strokeStyle=w,r.lineWidth=1,r.beginPath();let U=!1,te=Math.min(2,window.devicePixelRatio||1),W=Math.max(1,Math.round(c*te)),ne=A>W*4?T&&k?K0(k,O,Math.log10(N*M),Math.log10(P*M),W):K0(D,O,N*M,P*M,W):null;for(let e=+!ne;e<(ne?ne.length:A);e++){let t=ne?ne[e]:e;if(t<1)continue;let n=D[t]/M;if(n<N||n>P)continue;let i=R(n),a=z(O[t]);U?r.lineTo(i,a):(r.moveTo(i,a),U=!0)}r.stroke(),r.restore(),r.fillStyle=p,r.font=`11px ${X.mono}`,r.save(),r.translate(14,i+l/2),r.rotate(-Math.PI/2),r.textAlign=`center`,r.textBaseline=`middle`,r.fillText(C===`db`?`dB`:`Amplitude`,0,0),r.restore(),r.textAlign=`center`,r.textBaseline=`bottom`,r.fillText(j,s+c/2,n-4)}let w=(0,Z.useRef)(C);w.current=C;let T=(0,Z.useRef)(null);T.current??=mZ(()=>w.current(),()=>p.current);let E=()=>T.current.schedule();return(0,Z.useEffect)(()=>{T.current.now()}),(0,Z.useEffect)(()=>()=>T.current?.cancel(),[]),(0,Z.useEffect)(()=>{m.current=null,E()},[l]),(0,Z.useLayoutEffect)(()=>{let e=p.current;if(!e)return;let t=new fZ(()=>{m.current=null,E()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{let e=f.current;if(!e)return;let t=e=>{e.preventDefault(),h.current?.({clientX:e.clientX,clientY:e.clientY})};return e.addEventListener(`contextmenu`,t),()=>e.removeEventListener(`contextmenu`,t)},[]),(0,Q.jsx)(`div`,{ref:p,style:{position:`relative`,width:`100%`,height:`100%`},children:(0,Q.jsx)(`canvas`,{ref:f,className:`chart-canvas`,role:`img`,"aria-label":`Spectrum of ${n}`})})}function c2(e,t,n=0,r=e.length-1){for(;r>n;){let i=n+r>>>1,a=e[n],o=e[i],s=e[r];if(a>o){let e=a;a=o,o=e}o>s&&(o=s),a>o&&(o=a);let c=o,l=n,u=r;for(;l<=u;){for(;e[l]<c;)l++;for(;e[u]>c;)u--;if(l<=u){let t=e[l];e[l]=e[u],e[u]=t,l++,u--}}if(t<=u)r=u;else if(t>=l)n=l;else break}return e[t]}function l2(e,t){let n=e.length;if(n===0)return t.map(()=>0);let r=[...new Set(t.flatMap(e=>{let t=e/100*(n-1);return[Math.floor(t),Math.ceil(t)]}))].sort((e,t)=>e-t),i=new Map,a=0;for(let t of r)i.set(t,c2(e,t,a)),a=t;return t.map(e=>{let t=e/100*(n-1),r=Math.floor(t);return i.get(r)+(i.get(Math.ceil(t))-i.get(r))*(t-r)})}var u2={top:14,right:24,bottom:48,left:64},d2=5;function f2(e,t){let n=e.length;if(n===0)return null;let[r,i,a,o,s]=l2(Float64Array.from(e),[0,25,50,75,100]),c=0;for(let t=0;t<n;t++)c+=e[t];let l=c/n;if(t!==`1.5iqr`)return{q1:i,median:a,q3:o,mean:l,whiskerLo:r,whiskerHi:s,outliers:new Float64Array};let u=o-i,d=i-1.5*u,f=o+1.5*u,p=1/0,m=-1/0,h=0;for(let t=0;t<n;t++){let n=e[t];if(n<d||n>f){h++;continue}n<p&&(p=n),n>m&&(m=n)}let g=new Float64Array(h);for(let t=0,r=0;t<n;t++){let n=e[t];(n<d||n>f)&&(g[r++]=n)}return g.sort(),{q1:i,median:a,q3:o,mean:l,whiskerLo:p<=m?p:i,whiskerHi:p<=m?m:o,outliers:g}}function p2({groups:e,color:t=`#fb923c`,whiskers:n=`1.5iqr`,height:r=400,backgroundToken:i=``,onPlotContextMenu:a}){let o=iQ(),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(null),u=(0,Z.useRef)(a);(0,Z.useLayoutEffect)(()=>{u.current=a},[a]);let d=(0,Z.useRef)({groups:e,color:t,whiskers:n,height:r});(0,Z.useLayoutEffect)(()=>{d.current={groups:e,color:t,whiskers:n,height:r}},[e,t,n,r]);let f=(0,Z.useMemo)(()=>e.filter(e=>e.values.length>0).map(e=>({label:e.label,box:f2(e.values,n)})),[e,n]),p=(0,Z.useRef)(f);(0,Z.useLayoutEffect)(()=>{p.current=f},[f]);function m(){if(l.current)return l.current;let e=c.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return l.current=n,n}function h(){let e=c.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||d.current.height)}}function g(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function _(){let e=s.current;if(!e)return;let{w:t,h:n}=h(),r=g(e,t,n);if(!r)return;let{top:i,right:a,bottom:c,left:l}=u2,u=t-l-a,f=n-i-c,{bg:_,muted:v,grid:y}=m(),{color:b}=d.current;r.fillStyle=_,r.fillRect(0,0,t,n);let x=p.current;if(x.length===0||u<=0||f<=0){r.fillStyle=v,r.font=`13px ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,eX(r);return}let S=1/0,C=-1/0;for(let e of x){e.box.whiskerLo<S&&(S=e.box.whiskerLo),e.box.whiskerHi>C&&(C=e.box.whiskerHi);for(let t of e.box.outliers)t<S&&(S=t),t>C&&(C=t)}let w=(C-S)*.08||1;S-=w,C+=w;let T=e=>i+(C-e)/(C-S)*f;o({left:l,top:i,width:u,height:f,y:{v0:S,v1:C}});let E=MJ(C-S,5),D=FJ(S,C,E);r.strokeStyle=y,r.lineWidth=1,r.setLineDash([3,3]);for(let e of D)r.beginPath(),r.moveTo(l,T(e)),r.lineTo(l+u,T(e)),r.stroke();r.setLineDash([]),r.strokeStyle=v,r.lineWidth=1,r.fillStyle=v,r.font=`11px ${X.mono}`,r.textAlign=`right`,r.textBaseline=`middle`;for(let e of D)r.beginPath(),r.moveTo(l-d2,T(e)),r.lineTo(l,T(e)),r.stroke(),r.fillText(zJ(e,E),l-4,T(e));r.strokeStyle=y,r.lineWidth=1,r.strokeRect(l,i,u,f),r.save(),r.beginPath(),r.rect(l,i,u,f),r.clip();let O=x.length,k=u/O,A=Math.min(k*.55,60);for(let e=0;e<O;e++){let{box:t}=x[e],n=l+k*e+k/2;r.strokeStyle=b,r.lineWidth=1.5,r.beginPath(),r.moveTo(n,T(t.whiskerLo)),r.lineTo(n,T(t.whiskerHi)),r.stroke();let i=A*.35;r.beginPath(),r.moveTo(n-i,T(t.whiskerLo)),r.lineTo(n+i,T(t.whiskerLo)),r.moveTo(n-i,T(t.whiskerHi)),r.lineTo(n+i,T(t.whiskerHi)),r.stroke();let a=n-A/2,o=T(t.q3),s=Math.max(1,T(t.q1)-o);r.fillStyle=b,r.globalAlpha=.25,r.fillRect(a,o,A,s),r.globalAlpha=1,r.strokeStyle=b,r.lineWidth=1.5,r.strokeRect(a,o,A,s),r.strokeStyle=b,r.lineWidth=2.5,r.beginPath(),r.moveTo(a,T(t.median)),r.lineTo(a+A,T(t.median)),r.stroke();let c=T(t.mean);r.fillStyle=b,r.beginPath(),r.moveTo(n,c-5),r.lineTo(n+5,c),r.lineTo(n,c+5),r.lineTo(n-5,c),r.closePath(),r.fill(),r.fillStyle=b,r.globalAlpha=.6;let u=NaN;for(let e of t.outliers){let t=T(e);Math.abs(t-u)<.5||(u=t,r.beginPath(),r.arc(n,t,2.5,0,Math.PI*2),r.fill())}r.globalAlpha=1}r.restore(),r.fillStyle=v,r.font=`11px ${X.mono}`,r.textAlign=`center`,r.textBaseline=`top`;for(let e=0;e<O;e++){let t=l+k*e+k/2,n=x[e].label;r.save(),r.rect(l+k*e+2,i+f+d2+2,k-4,c-d2-4),r.clip(),r.fillText(n,t,i+f+d2+2),r.restore()}}let v=(0,Z.useRef)(_);v.current=_;let y=(0,Z.useRef)(null);y.current??=mZ(()=>v.current(),()=>c.current);let b=()=>y.current.schedule();return(0,Z.useEffect)(()=>{y.current.now()}),(0,Z.useEffect)(()=>()=>y.current?.cancel(),[]),(0,Z.useEffect)(()=>{l.current=null,b()},[i]),(0,Z.useLayoutEffect)(()=>{let e=c.current;if(!e)return;let t=new fZ(()=>{l.current=null,b()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{let e=s.current;if(!e)return;let t=e=>{e.preventDefault(),u.current?.({clientX:e.clientX,clientY:e.clientY})};return e.addEventListener(`contextmenu`,t),()=>e.removeEventListener(`contextmenu`,t)},[]),(0,Q.jsx)(`div`,{ref:c,style:{position:`relative`,width:`100%`,height:`100%`},children:(0,Q.jsx)(`canvas`,{ref:s,className:`chart-canvas`,role:`img`,"aria-label":`Box plot`})})}function m2(e,t){if(e.w<=t)return{grid:e,per:1};let n=e.w/t,r=new Float32Array(t*e.h);for(let i=0;i<e.h;i++){let a=i*e.w;for(let o=0;o<t;o++){let s=Math.floor(o*n),c=Math.min(e.w,Math.floor((o+1)*n)),l=0,u=0;for(let t=s;t<c;t++){let n=e.values[a+t];n===n&&(l+=n,u++)}r[i*t+o]=u?l/u:NaN}}let i=e.xLabels;return{grid:{w:t,h:e.h,values:r,xLabels:e=>typeof i==`function`?i(Math.floor(e*n)):i[Math.floor(e*n)],yLabels:e.yLabels},per:n}}function h2(e){let t=[];for(let n of e.split(`,`)){let e=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(n.trim());if(!e)return null;let r=e[1].length===3?e[1].replace(/./g,`$&$&`):e[1];t.push([parseInt(r.slice(0,2),16),parseInt(r.slice(2,4),16),parseInt(r.slice(4,6),16)])}return t.length>=2?t:null}var g2=e=>e.includes(`.`)&&!e.includes(`e`)?e.replace(/\.?0+$/,``):e;function _2(e){return e>=1e3?`${g2((e/1e3).toPrecision(3))}k`:g2(e.toPrecision(3))}function v2(e,t){let n=e>>1,r=new Float64Array(e);for(let n=0;n<e;n++)r[n]=t?.5*(1-Math.cos(2*Math.PI*n/(e-1))):1;let i=Math.log2(e),a=new Uint32Array(e);for(let t=0;t<e;t++){let e=0,n=t;for(let t=0;t<i;t++)e=e<<1|n&1,n>>=1;a[t]=e}let o=new Float64Array(e),s=new Float64Array(e);return(t,i,c)=>{for(let n=0;n<e;n++){let e=a[n];o[n]=t[i+e]*r[e],s[n]=0}for(let t=2;t<=e;t<<=1){let n=t>>1,r=-2*Math.PI/t,i=Math.cos(r),a=Math.sin(r);for(let r=0;r<e;r+=t){let e=1,t=0;for(let c=0;c<n;c++){let l=r+c,u=l+n,d=o[u]*e-s[u]*t,f=o[u]*t+s[u]*e;o[u]=o[l]-d,s[u]=s[l]-f,o[l]+=d,s[l]+=f;let p=e*i-t*a;t=e*a+t*i,e=p}}}let l=0;for(let t=0;t<n;t++){let n=Math.sqrt(o[t]*o[t]+s[t]*s[t])/e;c[t]=n,n>l&&(l=n)}return l}}function y2(e,t,n,r,i,a,o){let s=t>>1,c=e.length,l=c>=t?Math.floor((c-t)/n)+1:0,u=`${t}|${n}|${r}|${i}|${a?a.join(`,`):``}`,d=-1,f=0;if(o&&o.key===u&&o.frames>0&&c>0){let r=o.sig;for(let i=0;i*n<r.length&&f===0;i++){let a=i*n;if(r[a]!==e[0])continue;let s=Math.min(r.length-a,c),u=!0;for(let t=0;t<s;t++)if(r[a+t]!==e[t]){u=!1;break}if(!u)continue;let p=s>=t?Math.floor((s-t)/n)+1:0;d=i,f=Math.max(0,Math.min(p,o.frames-i,l))}}let p=new Float32Array(l*s),m=new Float32Array(l);if(f>0){for(let e=0;e<s;e++)p.set(o.values.subarray(e*o.frames+d,e*o.frames+d+f),e*l);m.set(o.frameMax.subarray(d,d+f))}let h=v2(t,r),g=new Float64Array(s);for(let t=f;t<l;t++){m[t]=h(e,t*n,g);for(let e=0;e<s;e++){let n=g[a?a[e]:e];p[e*l+t]=i?20*Math.log10(Math.max(n,1e-12)):n}}let _=1e-10;for(let e=0;e<l;e++)m[e]>_&&(_=m[e]);return{values:p,frames:l,bins:s,max:_,computed:l-f,sig:Float64Array.from(e),frameMax:m,key:u}}function b2(e,t,n,r,i,a){let o=e>>1,s=new Float32Array(o*n).fill(NaN),c=new Float32Array(n),l=v2(e,r),u=new Float64Array(o),d={values:s,cap:n,bins:o,end:-1,count:0,max:1e-10,computed:0,update(r,f){let p=r.length,m=p>=e?Math.floor((f+p-e)/t)+1:0,h=Math.ceil(f/t);if(d.computed=0,m===d.end)return!1;let g=m-d.end,_=d.end;if(d.end<0||g<0||g>=n||h>d.end)s.fill(NaN),d.count=0,_=Math.max(h,m-n);else{for(let e=0;e<o;e++)s.copyWithin(e*n,e*n+g,(e+1)*n);c.copyWithin(0,g),d.count=Math.min(d.count,n-g)}if(d.end=Math.max(m,0),m<=_)return d.count>0||g<0;for(let e=_;e<m;e++){let d=n-(m-e);c[d]=l(r,e*t-f,u);for(let e=0;e<o;e++){let t=u[a?a[e]:e];s[e*n+d]=i?20*Math.log10(Math.max(t,1e-12)):t}}d.computed=m-_,d.count=Math.min(n,d.count+d.computed);let v=1e-10;for(let e=n-d.count;e<n;e++)c[e]>v&&(v=c[e]);return d.max=v,!0}};return d}var x2=1024,S2=1,C2=1e3/120,w2={top:14,right:24,bottom:40,left:68},T2=[[8,0,16],[48,0,96],[104,0,144],[160,0,128],[200,32,64],[230,100,16],[250,200,32],[255,255,220]],E2=-80;function D2(e,t=T2){let n=t.length-1,r=Math.min(n-1,Math.floor(e*n)),i=e*n-r,[a,o,s]=t[r],[c,l,u]=t[r+1];return[a+(c-a)*i,o+(l-o)*i,s+(u-s)*i]}function O2(e){let t=new Uint8Array(256*4);for(let n=0;n<256;n++){let[r,i,a]=D2(n/255,e);t.set([r,i,a,255],n*4)}return t}var k2=O2(T2);function A2(e){let t=1;for(;t<e;)t<<=1;return t}var j2=(e,t)=>Math.log(1+e/t*9)/Math.log(10),M2=(e,t)=>t*(10**e-1)/9,N2=new Float64Array;function P2({signal:e,sampleRate:t=1e3,windowSize:n=512,overlap:r=.5,winFunc:i=`hann`,yMode:a=`db`,logFreq:o=!1,label:s=``,backgroundToken:c=``,onPlotContextMenu:l,live:u}){let d=iQ(),f=(0,Z.useRef)(null),p=(0,Z.useRef)(null),m=(0,Z.useRef)(null),h=(0,Z.useRef)(null),g=(0,Z.useRef)(null),_=(0,Z.useRef)(l);(0,Z.useLayoutEffect)(()=>{_.current=l},[l]);let v=A2(Math.max(4,Math.min(n,4096))),y=Math.max(1,Math.round(v*(1-Math.max(0,Math.min(.95,r))))),b=(0,Z.useMemo)(()=>{if(!o)return null;let e=v>>1,n=t/2;return Int32Array.from({length:e},(t,r)=>Math.min(e-1,Math.floor(M2((r+.5)/e,n)/n*e)))},[o,v,t]),x=(0,Z.useRef)(null),S=u?N2:e,C=(0,Z.useMemo)(()=>x.current=y2(S,v,y,i===`hann`,a===`db`,b,x.current),[S,v,y,i,a,b]),w=(0,Z.useMemo)(()=>({w:C.frames,h:C.bins,values:C.values,xLabels:[],yLabels:[]}),[C]),T=a===`db`?20*Math.log10(C.max):C.max,E=a===`db`?[T+E2,T]:[0,T],D=(0,Z.useRef)({grid:w,range:E,sampleRate:t,winSz:v,step:y,winFunc:i,yMode:a,logFreq:o,rowBin:b,label:s,live:u});(0,Z.useLayoutEffect)(()=>{D.current={grid:w,range:E,sampleRate:t,winSz:v,step:y,winFunc:i,yMode:a,logFreq:o,rowBin:b,label:s,live:u}},[w,E[0],E[1],t,v,y,i,a,o,b,s,u]);let O=(0,Z.useRef)({plot:null,failed:!1,size:``,grid:null,shown:null,palette:null});(0,Z.useEffect)(()=>()=>{O.current.plot?.dispose(),O.current.plot=null},[]);let k=(0,Z.useRef)({canvas:null,grid:null,lo:0,hi:0,palette:null}),A=(0,Z.useRef)({roll:null,cfg:null,version:NaN,grid:null,playout:MZ(),last:0,x1:NaN,axes:``}),j=(0,Z.useRef)(!0);function M(){if(g.current)return g.current;let e=h.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`,palette:k2};let t=getComputedStyle(e),n=h2(t.getPropertyValue(`--chart-spectrogram`)),r={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`,palette:n?O2(n):k2};return g.current=r,r}function N(){let e=h.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function P(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function F(e,t){let n=O.current;if(!n.plot&&!n.failed&&p.current&&(n.plot=NX(p.current,B0),n.failed=!n.plot),!n.plot||!p.current)return null;let r=Math.min(2,window.devicePixelRatio||1),i=`${e}x${t}@${r}`;return n.size!==i&&(n.plot.resize(e,t,r),p.current.style.width=`${e}px`,p.current.style.height=`${t}px`,n.size=i),n.plot}function I(e,t){let n=A.current,{sampleRate:r,winSz:i,step:a,winFunc:o,yMode:s,rowBin:c}=D.current,l=e.samples();if(!l)return null;let u=e.windowSeconds!=null&&e.windowSeconds>0?e.windowSeconds:null,d=u==null?l.values.length:(u+S2)*r,f=a;for(;d/f>x2;)f*=2;let p=u==null?x2:Math.max(2,Math.ceil(d/f)),m=n.cfg;(!n.roll||!m||m.winSz!==i||m.hop!==f||m.cap!==p||m.winFunc!==o||m.yMode!==s||m.rowBin!==c)&&(n.roll=b2(i,f,p,o===`hann`,s===`db`,c),n.cfg={winSz:i,hop:f,cap:p,winFunc:o,yMode:s,rowBin:c},n.version=NaN,n.grid=null);let h=n.roll,g=e.version(),_=!1;g!==n.version&&(n.version=g,(h.update(l.values,l.first)||!n.grid)&&(n.grid={w:p,h:h.bins,values:h.values,xLabels:[],yLabels:[]},_=!0));let v=e.latestT(),y=p,b=NaN;if(Number.isFinite(v)){let a=e.id?PZ(e.id,v,t,e.timeAfter):JZ(n.playout,v,n.last?t-n.last:16,e.timeAfter),o=e.id?zZ(e.id):IZ(n.playout),s=e.id?RZ(e.id):LZ(n.playout),c=l.first+l.values.length-1-(v-(a+o-2*s))*r;y=Math.min(p,(c-i)/f-(h.end-p)),b=v-(l.first+l.values.length-1-((y+h.end-p)*f+i))/r}let x=u==null?p-h.count:y-u*r/f,S=s===`db`?20*Math.log10(h.max):h.max,C=_||y!==n.x1;return n.x1=y,{grid:h.count>0?n.grid:null,lo:s===`db`?S+E2:0,hi:S,x0:x,x1:y,hop:f,moved:C,tEnd:b}}function L(){let e=f.current;if(!e)return;let{w:t,h:n}=N(),r=A.current,i=D.current.live,a=null;if(i){j.current&&z.current.schedule();let e=performance.now();if(r.last&&e-r.last<C2-2)return;a=I(i,e),r.last=e}let o=$$(w2,t,n),{top:s,right:c,bottom:l,left:u}=o,p=t-u-c,g=n-s-l,_=M(),{bg:v,muted:y,grid:b}=_,{sampleRate:x,winSz:S,step:C,logFreq:w,label:T}=D.current,E=i?a?.grid??{w:0,h:0,values:new Float32Array,xLabels:[],yLabels:[]}:D.current.grid,[L,R]=a?[a.lo,a.hi]:D.current.range,B=F(t,n),V=a?(a.x1-a.x0)*a.hop/x:(E.w*C+S)/x,ee=a&&Number.isFinite(a.tEnd)?a.tEnd:V,H=ee-V,U=a?`${t}|${n}|${V.toPrecision(3)}|${ee}|${x}|${w}|${T}|${v}|${y}|${b}`:``,te=!!a&&!!B&&E.w>0&&r.axes===U;r.axes=``;let W=te?null:P(e,t,n);if(!te&&!W)return;let ne=!te&&m.current?P(m.current,t,n):null;if(ne?.clearRect(0,0,t,n),W&&(W.fillStyle=v,W.fillRect(0,0,t,n)),E.w===0||p<=0||g<=0){if(B?.keep([]),B?.render(),o.tiny||!W)return;W.fillStyle=y,W.font=`13px ${X.sans}`,W.textAlign=`left`,W.textBaseline=`top`,eX(W);return}let G=Math.min(2,window.devicePixelRatio||1),re=B?B.maxTextureSize:Math.max(1,Math.round(p*G));if(O.current.grid!==E||!O.current.shown||O.current.palette!==_.palette||!B&&!a&&O.current.shown.w>re){let e=a?E:m2(E,re).grid;B&&B.setGrid(`cells`,e.values,e.w,Math.min(e.h,B.maxTextureSize),[0,e.w,0,e.h],_.palette,L,R),O.current.grid=E,O.current.shown=e,O.current.palette=_.palette,a||lZ(h.current)}a?.moved&&lZ(h.current);let ie=O.current.shown,ae=a?a.x0:0,oe=a?a.x1:ie.w;if(B)B.keep([`cells`]),B.setGridRange(`cells`,L,R),B.setView(ae,oe,0,ie.h,{left:u,top:s,width:p,height:g}),B.render();else if(W){let e=k.current;if(e.grid!==ie||e.lo!==L||e.hi!==R||e.palette!==_.palette||!e.canvas){let t=e.canvas??document.createElement(`canvas`);t.width=ie.w,t.height=ie.h;let n=t.getContext(`2d`),r=n.createImageData(ie.w,ie.h),i=_.palette;for(let e=0;e<ie.h;e++)for(let t=0;t<ie.w;t++){let n=ie.values[e*ie.w+t];if(n!==n)continue;let a=Math.round(Math.max(0,Math.min(1,(n-L)/(R-L)))*255)*4,o=(t+(ie.h-1-e)*ie.w)*4;r.data[o]=i[a],r.data[o+1]=i[a+1],r.data[o+2]=i[a+2],r.data[o+3]=255}n.putImageData(r,0,0),k.current={canvas:t,grid:ie,lo:L,hi:R,palette:_.palette}}W.save(),W.beginPath(),W.rect(u,s,p,g),W.clip();let t=p/(oe-ae);W.drawImage(k.current.canvas,u-ae*t,s,ie.w*t,g),W.restore()}if(a&&(r.axes=U),o.tiny||!W)return;let se=ne??W,ce=x/2,le=e=>s+g*(1-(w?j2(e,ce):e/ce));se.strokeStyle=b,se.lineWidth=.5,se.globalAlpha=.4;let ue=FJ(0,ce,MJ(ce,5));se.setLineDash([3,4]);for(let e of ue){let t=le(e);se.beginPath(),se.moveTo(u,t),se.lineTo(u+p,t),se.stroke()}se.setLineDash([]),se.globalAlpha=1,se.strokeStyle=b,se.strokeRect(u,s,p,g),W.fillStyle=y,W.font=`10px ${X.mono}`,W.textAlign=`right`,W.textBaseline=`middle`,W.strokeStyle=y,W.lineWidth=1;for(let e of ue){let t=le(e);W.beginPath(),W.moveTo(u-4,t),W.lineTo(u,t),W.stroke(),W.fillText(_2(e),u-6,t)}d({left:u,top:s,width:p,height:g,x:{v0:H,v1:ee}});let de=MJ(V,6),fe=FJ(H,ee,de);W.textAlign=`center`,W.textBaseline=`top`;for(let e of fe){let t=u+(e-H)/V*p;t<u-.5||t>u+p+.5||(W.beginPath(),W.moveTo(t,s+g),W.lineTo(t,s+g+4),W.stroke(),W.fillText(zJ(e,de),t,s+g+6))}W.fillStyle=y,W.textAlign=`center`,W.textBaseline=`bottom`,W.fillText(T||`Time (s)`,u+p/2,n-4),W.save(),W.translate(12,s+g/2),W.rotate(-Math.PI/2),W.textAlign=`center`,W.fillText(`Frequency (Hz)`,0,0),W.restore()}let R=(0,Z.useRef)(L);(0,Z.useLayoutEffect)(()=>{R.current=L});let z=(0,Z.useRef)(null);z.current??=mZ(()=>R.current(),()=>h.current);let B=!!u;return(0,Z.useEffect)(()=>{A.current.axes=``,z.current.now()},[w,E[0],E[1],t,v,y,a,o,s,B]),(0,Z.useEffect)(()=>()=>z.current?.cancel(),[]),(0,Z.useEffect)(()=>{g.current=null,z.current.schedule()},[c]),(0,Z.useLayoutEffect)(()=>{let e=h.current;if(!e)return;let t=new fZ(()=>{g.current=null,z.current.schedule()});return t.observe(e),()=>t.disconnect()},[]),(0,Z.useEffect)(()=>{let e=h.current,t=e?.ownerDocument.defaultView?.IntersectionObserver;if(!e||!t)return;let n=new t(e=>{let t=e[e.length-1];(t.isIntersecting||t.boundingClientRect.width>0)&&(j.current=t.isIntersecting),j.current&&D.current.live&&z.current?.schedule()});return n.observe(e),()=>{n.disconnect(),j.current=!0}},[]),(0,Z.useLayoutEffect)(()=>{let e=m.current;if(!e)return;let t=e=>{e.preventDefault(),_.current?.({clientX:e.clientX,clientY:e.clientY})};return e.addEventListener(`contextmenu`,t),()=>e.removeEventListener(`contextmenu`,t)},[]),(0,Q.jsxs)(`div`,{ref:h,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:f,className:`chart-canvas`,role:`img`,"aria-label":`Spectrogram`}),(0,Q.jsx)(`canvas`,{ref:p,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),(0,Q.jsx)(`canvas`,{ref:m,className:`chart-canvas chart-overlay`})]})}var F2=300,I2=256,L2=-60,R2=[];function z2({signal:e,sampleRate:t,windowSize:n,overlap:r,winFunc:i,yMode:a,backgroundToken:o,onPlotContextMenu:s}){let c=2**Math.ceil(Math.log2(Math.max(4,Math.min(n,4096)))),l=Math.max(1,Math.round(c*(1-Math.max(0,Math.min(.95,r))))),u=a===`db`,d=(0,Z.useMemo)(()=>y2(e,c,l,i===`hann`,u,null),[e,c,l,i,u]);return(0,Q.jsx)(b0,{points:R2,surface:(0,Z.useMemo)(()=>B2(d,t,c,l,u),[d,t,c,l,u]),xLabel:`Time (s)`,yLabel:`Frequency (Hz)`,zLabel:u?`Level (dB)`:`Amplitude`,viewMode:`3d`,showMesh:!0,meshStyle:`filled`,meshOpacity:1,backgroundToken:o,onPlotContextMenu:s})}function B2(e,t,n,r,i){let{frames:a,bins:o,values:s}=e;if(a<2||o<2)return;let c=Math.min(a,F2),l=Math.min(o,I2),u=i?20*Math.log10(Math.max(e.max,1e-12))+L2:-1/0,d=new Float32Array(c*l);for(let e=0;e<l;e++){let t=Math.floor(e*o/l),n=Math.max(t+1,Math.floor((e+1)*o/l));for(let r=0;r<c;r++){let i=Math.floor(r*a/c),o=Math.max(i+1,Math.floor((r+1)*a/c)),l=-1/0;for(let e=t;e<n;e++)for(let t=i;t<o;t++){let n=s[e*a+t];n>l&&(l=n)}d[e*c+r]=Math.max(u,l)}}let f=e=>(e*r+n/2)/t;return{w:c,h:l,values:d,x:[f(0),f(a-1)],y:[0,(o-1)*t/n]}}function V2(e,t,n){return Array.from({length:n},(r,i)=>e+(i+1)/(n+1)*(t-e))}function H2(e,t,n,r){let i=[],a=(n,r)=>e[r*t+n],o=(e,t)=>(r-e)/(t-e);for(let e=0;e+1<n;e++)for(let n=0;n+1<t;n++){let t=a(n,e),s=a(n+1,e),c=a(n+1,e+1),l=a(n,e+1);if(t!==t||s!==s||c!==c||l!==l)continue;let u=(t>=r?8:0)|(s>=r?4:0)|(c>=r?2:0)|l>=r;if(u===0||u===15)continue;let d=()=>[n+o(t,s),e],f=()=>[n+1,e+o(s,c)],p=()=>[n+o(l,c),e+1],m=()=>[n,e+o(t,l)],h=(e,t)=>i.push([e[0],e[1],t[0],t[1]]);switch(u){case 1:case 14:h(m(),p());break;case 2:case 13:h(p(),f());break;case 3:case 12:h(m(),f());break;case 4:case 11:h(d(),f());break;case 6:case 9:h(d(),p());break;case 7:case 8:h(m(),d());break;case 5:case 10:{let e=(t+s+c+l)/4>=r;u===5===e?(h(m(),d()),h(p(),f())):(h(d(),f()),h(m(),p()));break}}}return i}function U2(e){let t=e.length,n=new Float64Array(t+1);if(t===1)return n[0]=e[0]-.5,n[1]=e[0]+.5,n;for(let r=1;r<t;r++)n[r]=(e[r-1]+e[r])/2;return n[0]=e[0]-(n[1]-e[0]),n[t]=e[t-1]+(e[t-1]-n[t-1]),n}function W2(e){if(e.length===0)return!1;for(let t=0;t<e.length;t++)if(!Number.isFinite(e[t])||t>0&&!(e[t]>e[t-1]))return!1;return!0}var G2={top:14,right:32,bottom:80,left:80};function K2(e,t,n){return[e[0]+(t[0]-e[0])*n,e[1]+(t[1]-e[1])*n,e[2]+(t[2]-e[2])*n]}var q2=[[33,102,172],[103,169,207],[209,229,240],[247,247,247],[253,219,199],[239,138,98],[178,24,43]],J2=[[13,8,135],[84,2,163],[139,10,165],[185,50,137],[219,92,104],[244,136,73],[254,188,43],[240,249,33]],Y2=[[68,1,84],[72,40,120],[62,83,160],[49,120,178],[38,153,185],[31,184,187],[53,213,158],[117,231,101],[198,239,82],[253,231,37]];function X2(e,t){let n=e.length-1,r=Math.min(n-1,Math.floor(t*n));return K2(e[r],e[r+1],t*n-r)}function Z2(e,t){return X2(t===`plasma`?J2:t===`viridis`?Y2:q2,e)}function Q2(e){let t=new Uint8Array(256*4);for(let n=0;n<256;n++){let[r,i,a]=Z2(n/255,e);t.set([r,i,a,255],n*4)}return t}function $2(e){return Math.abs(e)>=1e4||Math.abs(e)<.01&&e!==0?e.toExponential(1):String(parseFloat(e.toPrecision(3)))}function e4(e,t,n){let r=new Map(t.map((e,t)=>[e,t])),i=new Map(n.map((e,t)=>[e,t])),a=new Float32Array(t.length*n.length);for(let n of e){let e=r.get(n.x),o=i.get(n.y);e!==void 0&&o!==void 0&&(a[o*t.length+e]=n.value)}return{w:t.length,h:n.length,values:a,xLabels:t,yLabels:n}}function t4(e,t,n,r,i,a,o){let s=(e,t,n)=>Float64Array.from({length:e+1},(r,i)=>t+i/e*n),c=!!a&&a.length===e.w,l=!!o&&o.length===e.h,u=s(e.w,t,r),d=s(e.h,n,i);if(c){let n=U2(a),i=n[e.w]-n[0];u=Float64Array.from(n,e=>t+(e-n[0])/i*r)}if(l){let t=U2(Float64Array.from(o).reverse()),r=e.h,a=t[r]-t[0];d=Float64Array.from({length:r+1},(e,o)=>n+(t[r]-t[r-o])/a*i)}return{xB:u,yB:d,byValue:c||l}}function n4(e,t){if(t<e[0]||t>=e[e.length-1])return-1;let n=0,r=e.length-1;for(;r-n>1;){let i=n+r>>1;e[i]<=t?n=i:r=i}return n}function r4(e,t,n,r,i,a){let o=Math.max(1,i),s=Math.max(1,a),c=Int32Array.from({length:o},(e,r)=>n4(t.xB,n+r+.5)),l=new Float32Array(o*s);for(let n=0;n<s;n++){let i=n4(t.yB,r+n+.5),a=i*e.w;for(let t=0;t<o;t++)l[n*o+t]=i<0||c[t]<0?NaN:e.values[a+c[t]]}return{w:o,h:s,values:l,xLabels:e.xLabels,yLabels:e.yLabels}}function i4({cells:e,xLabels:t,yLabels:n,grid:r,showValues:i=!0,colorScheme:a=`diverging`,vMin:o,vMax:s,xCentres:c,yCentres:l,contours:u=0,backgroundToken:d=``,onPlotContextMenu:f}){let p=(0,Z.useRef)(null),m=(0,Z.useRef)(null),h=(0,Z.useRef)(null),g=(0,Z.useRef)(null),_=(0,Z.useRef)(null),v=(0,Z.useRef)(null),y=(0,Z.useRef)(null),b=(0,Z.useRef)(0),x=(0,Z.useRef)(f);(0,Z.useLayoutEffect)(()=>{x.current=f},[f]);let S=(0,Z.useMemo)(()=>r??e4(e??[],t??[],n??[]),[r,e,t,n]),C=(0,Z.useMemo)(()=>{let e=o??1/0,t=s??-1/0;if(o===void 0||s===void 0){let n=1/0,r=-1/0;for(let e=0;e<S.w*S.h;e++){let t=S.values[e];t<n&&(n=t),t>r&&(r=t)}o===void 0&&(e=n),s===void 0&&(t=r)}return t>e||(e=Number.isFinite(e)?e-1:0,t=e+2),{lo:e,hi:t}},[S,o,s]),w=(0,Z.useRef)({data:S,range:C,showValues:i,colorScheme:a,xCentres:c,yCentres:l,contours:u});(0,Z.useLayoutEffect)(()=>{w.current={data:S,range:C,showValues:i,colorScheme:a,xCentres:c,yCentres:l,contours:u}},[S,C,i,a,c,l,u]);let T=(0,Z.useRef)({plot:null,failed:!1,size:``,data:null,key:``,shown:null,geo:null}),E=(0,Z.useRef)({key:``,grid:null,segs:[]});(0,Z.useEffect)(()=>()=>{T.current.plot?.dispose(),T.current.plot=null},[]);let D=(0,Z.useRef)({data:null,range:``});function O(){if(v.current)return v.current;let e=_.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return v.current=n,n}function k(){let e=_.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function A(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function j(e,t){let n=T.current;if(!n.plot&&!n.failed&&m.current&&(n.plot=NX(m.current,B0),n.failed=!n.plot),!n.plot||!m.current)return null;let r=Math.min(2,window.devicePixelRatio||1),i=`${e}x${t}@${r}`;return n.size!==i&&(n.plot.resize(e,t,r),m.current.style.width=`${e}px`,m.current.style.height=`${t}px`,n.size=i),n.plot}let M=(e,t)=>typeof e==`function`?e(t):e[t];function N(){let e=p.current;if(!e)return;let{w:t,h:n}=k(),r=A(e,t,n);if(!r)return;let i=h.current?A(h.current,t,n):null;i?.clearRect(0,0,t,n);let a=$$(G2,t,n),{top:o,right:s,bottom:c,left:l}=a,{bg:u,muted:d,grid:f}=O(),{data:m,range:{lo:g,hi:v},showValues:y,colorScheme:b}=w.current;r.fillStyle=u,r.fillRect(0,0,t,n);let x=j(t,n);if(m.w===0||m.h===0){x?.keep([]),x?.render(),r.fillStyle=d,r.font=`13px ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,eX(r);return}let S=t-l-s,C=n-o-c,N=Math.min(2,window.devicePixelRatio||1),P=D.current;(P.data!==m||P.range!==`${g}|${v}`)&&(D.current={data:m,range:`${g}|${v}`},lZ(_.current));let{xCentres:F,yCentres:I,contours:L}=w.current,R=x?x.maxTextureSize:Math.max(1,Math.round(S*N)),z=m2(m,R).grid,B=t4(z,l,o,S,C,z===m?F:void 0,z===m?I:void 0),V=B.byValue,ee=`${R}|${b}|${V?`${S}x${C}`:``}`,H=T.current.shown;if(T.current.data!==m||T.current.key!==ee||!H){H=z;let e=V?r4(H,B,l,o,Math.round(S),Math.round(C)):H;x&&x.setGrid(`cells`,e.values,e.w,Math.min(e.h,x.maxTextureSize),[0,e.w,0,e.h],Q2(b),g,v),T.current.data=m,T.current.key=ee,T.current.shown=H}T.current.geo=B;let U=V?Math.round(S):H.w,te=V?Math.round(C):H.h,W=e=>B.xB[e+1]-B.xB[e],ne=e=>B.yB[e+1]-B.yB[e];if(x)x.keep([`cells`]),x.setGridRange(`cells`,g,v),x.setView(0,U,te,0,{left:l,top:o,width:S,height:C}),x.render();else for(let e=0;e<H.h;e++)for(let t=0;t<H.w;t++){let n=H.values[e*H.w+t];if(Number.isNaN(n))continue;let[i,a,o]=Z2(Math.max(0,Math.min(1,(n-g)/(v-g))),b);r.fillStyle=`rgb(${i|0},${a|0},${o|0})`,r.fillRect(B.xB[t],B.yB[e],W(t)+.5,ne(e)+.5)}let G=i??r;if(y){for(let e=0;e<H.h;e++)if(!(ne(e)<=16)){G.font=`${Math.min(12,Math.max(8,ne(e)*.4))}px ${X.mono}`,G.textAlign=`center`,G.textBaseline=`middle`;for(let t=0;t<H.w;t++){let n=H.values[e*H.w+t];if(Number.isNaN(n)||W(t)<=28)continue;let[r,i,a]=Z2(Math.max(0,Math.min(1,(n-g)/(v-g))),b);G.fillStyle=.299*r+.587*i+.114*a>128?`#000`:`#fff`,G.fillText($2(n),(B.xB[t]+B.xB[t+1])/2,(B.yB[e]+B.yB[e+1])/2)}}}if(S/H.w>=4&&C/H.h>=4){G.strokeStyle=u,G.lineWidth=.5;for(let e=0;e<=H.w;e++)G.beginPath(),G.moveTo(B.xB[e],o),G.lineTo(B.xB[e],o+C),G.stroke();for(let e=0;e<=H.h;e++)G.beginPath(),G.moveTo(l,B.yB[e]),G.lineTo(l+S,B.yB[e]),G.stroke()}let re=L>0?V2(g,v,L):[];if(re.length&&H.w>=2&&H.h>=2&&H.w*H.h<=4e6){let e=`${g}|${v}|${L}`;if(E.current.grid!==H||E.current.key!==e){let t=H;E.current={key:e,grid:t,segs:re.map(e=>H2(t.values,t.w,t.h,e))}}let t=(e,t)=>{let n=Math.min(t.length-3,Math.max(0,Math.floor(e))),r=(t[n]+t[n+1])/2;return r+((t[n+1]+t[n+2])/2-r)*(e-n)};G.save(),G.beginPath(),G.rect(l,o,S,C),G.clip(),G.lineCap=`round`,G.lineJoin=`round`;for(let[e,n]of[[2.6,`rgba(0,0,0,0.38)`],[1.1,`rgba(255,255,255,0.92)`]]){G.lineWidth=e,G.strokeStyle=n,G.beginPath();for(let e of E.current.segs)for(let[n,r,i,a]of e)G.moveTo(t(n,B.xB),t(r,B.yB)),G.lineTo(t(i,B.xB),t(a,B.yB));G.stroke()}G.restore()}r.fillStyle=d,r.font=`10px ${X.mono}`,r.textAlign=`center`,r.textBaseline=`top`;let ie=-1/0;for(let e=0;e<(a.tiny?0:H.w);e++){let t=(B.xB[e]+B.xB[e+1])/2;t-ie<18||(ie=t,r.save(),r.translate(t,o+C+4),r.rotate(-Math.PI/4),r.fillText(M(H.xLabels,e),0,0),r.restore())}r.textAlign=`right`,r.textBaseline=`middle`;let ae=-1/0;for(let e=0;e<(a.tiny?0:H.h);e++){let t=(B.yB[e]+B.yB[e+1])/2;t-ae<12||(ae=t,r.fillText(H.yLabels[e]??``,l-4,t))}if(a.tiny)return;let oe=t-s+4,se=o,ce=C;for(let e=0;e<ce;e++){let[t,n,i]=Z2(1-e/ce,b);r.fillStyle=`rgb(${t|0},${n|0},${i|0})`,r.fillRect(oe,se+e,12,1)}r.strokeStyle=f,r.lineWidth=.5,r.strokeRect(oe,se,12,ce),r.fillStyle=d,r.font=`9px ${X.mono}`,r.textAlign=`left`,r.textBaseline=`middle`,r.fillText($2(v),oe+12+2,se),r.fillText($2(g),oe+12+2,se+ce),r.fillText($2((g+v)/2),oe+12+2,se+ce/2),r.strokeStyle=`rgba(255,255,255,0.92)`,r.lineWidth=1;for(let e of re){let t=se+ce*(1-(e-g)/(v-g));r.beginPath(),r.moveTo(oe-2,t),r.lineTo(oe+12+2,t),r.stroke()}}function P(){let e=g.current;if(!e)return;let{w:t,h:n}=k(),r=A(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=y.current,a=T.current.shown,o=T.current.geo;if(!i||!a||!o)return;let{top:s,right:c,bottom:l}=$$(G2,t,n),{xi:u,yi:d}=i;if(u>=a.w||d>=a.h)return;let f=o.xB[u],p=o.xB[u+1],m=o.yB[d],h=o.yB[d+1];r.strokeStyle=`rgba(255,255,255,0.7)`,r.lineWidth=1.5,r.strokeRect(f+.5,m+.5,Math.max(1,p-f-1),Math.max(1,h-m-1));let _=a.values[d*a.w+u];if(!Number.isNaN(_)){let e=`${M(a.xLabels,u)} × ${a.yLabels[d]}: ${$2(_)}`;r.font=`11px ${X.mono}`;let n=r.measureText(e).width,i=Math.min(p+.1*(p-f),t-c-n-6),o=Math.max(s+4,m-.3*(h-m));r.fillStyle=`rgba(0,0,0,0.7)`,r.fillRect(i-3,o-3,n+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(e,i,o)}}let F=(0,Z.useRef)(N);F.current=N;let I=(0,Z.useRef)(null);I.current??=mZ(()=>F.current(),()=>_.current);let L=()=>{b.current||=oZ(()=>{b.current=0,P()})};return(0,Z.useEffect)(()=>{I.current.now()},[S,C,i,a,c,l,u]),(0,Z.useEffect)(()=>()=>{I.current?.cancel(),sZ(b.current)},[]),(0,Z.useEffect)(()=>{v.current=null,I.current.schedule()},[d]),(0,Z.useLayoutEffect)(()=>{let e=_.current;if(!e)return;let t=new fZ(()=>{v.current=null,I.current.schedule(),L()});return t.observe(e),()=>t.disconnect()},[]),(0,Z.useLayoutEffect)(()=>{let e=g.current;if(!e)return;let t=e=>{e.preventDefault(),x.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),{shown:r,geo:i}=T.current;if(!r||!i)return;let a=n4(i.xB,t.clientX-n.left),o=n4(i.yB,t.clientY-n.top);y.current=a>=0&&a<r.w&&o>=0&&o<r.h?{xi:a,yi:o}:null,L()},r=()=>{y.current=null,L()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),(0,Q.jsxs)(`div`,{ref:_,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:p,className:`chart-canvas`,role:`img`,"aria-label":`Heatmap`}),(0,Q.jsx)(`canvas`,{ref:m,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),(0,Q.jsx)(`canvas`,{ref:h,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),(0,Q.jsx)(`canvas`,{ref:g,className:`chart-canvas chart-overlay`})]})}var a4=2e3,o4=1024;function s4(e,t,n,r,i){let a=e.length,o=1/(a*t*Math.sqrt(2*Math.PI)),s=new Float64Array(n.length);if(a<=a4){for(let r=0;r<n.length;r++){let i=0;for(let o=0;o<a;o++){let a=(n[r]-e[o])/t;i+=Math.exp(-.5*a*a)}s[r]=i*o}return s}let c=new Float64Array(o4),l=(i-r)/o4||1;for(let t=0;t<a;t++)c[Math.max(0,Math.min(o4-1,Math.floor((e[t]-r)/l)))]++;for(let e=0;e<n.length;e++){let i=0;for(let a=0;a<o4;a++){if(c[a]===0)continue;let o=(n[e]-(r+(a+.5)*l))/t;i+=c[a]*Math.exp(-.5*o*o)}s[e]=i*o}return s}var c4={top:14,right:24,bottom:48,left:64},l4=120;function u4(e,t,n){let r=e.length;if(r<2)return 1;let i=0;for(let t=0;t<r;t++)i+=e[t];let a=i/r,o=0;for(let t=0;t<r;t++)o+=(e[t]-a)**2;let s=Math.sqrt(o/(r-1));return .9*Math.min(s,(n-t)/1.34)*r**-.2}function d4(e,t){let n=e.filter(e=>e.values.length>=2),r=1/0,i=-1/0,a=n.map(e=>{let[t,n,a,o,s]=l2(Float64Array.from(e.values),[0,25,50,75,100]);return t<r&&(r=t),s>i&&(i=s),{q1:n,median:a,q3:o}}),o=(i-r)*.1||1;r-=o,i+=o;let s=Float64Array.from({length:l4},(e,t)=>r+t/(l4-1)*(i-r));return{shapes:n.map((e,n)=>{let{q1:o,median:c,q3:l}=a[n],u=s4(e.values,t>0?t:u4(e.values,o,l),s,r,i),d=1e-10;for(let e of u)e>d&&(d=e);return{label:e.label,density:u,maxDensity:d,q1:o,median:c,q3:l}}),pts:s,yMin:r,yMax:i}}function f4({groups:e,color:t=`#818cf8`,showBox:n=!0,bandwidth:r=0,orientation:i=`vertical`,backgroundToken:a=``,onPlotContextMenu:o}){let s=iQ(),c=(0,Z.useRef)(null),l=(0,Z.useRef)(null),u=(0,Z.useRef)(null),d=(0,Z.useRef)(o);(0,Z.useLayoutEffect)(()=>{d.current=o},[o]);let f=(0,Z.useRef)({groups:e,color:t,showBox:n,bandwidth:r,orientation:i});(0,Z.useLayoutEffect)(()=>{f.current={groups:e,color:t,showBox:n,bandwidth:r,orientation:i}},[e,t,n,r,i]);let p=(0,Z.useMemo)(()=>d4(e,r),[e,r]),m=(0,Z.useRef)(p);(0,Z.useLayoutEffect)(()=>{m.current=p},[p]);function h(){if(u.current)return u.current;let e=l.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return u.current=n,n}function g(){let e=l.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function _(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function v(){let e=c.current;if(!e)return;let{w:t,h:n}=g(),r=_(e,t,n);if(!r)return;let{top:i,right:a,bottom:o,left:l}=c4,u=t-l-a,d=n-i-o,{bg:p,muted:v,grid:y}=h(),{color:b,showBox:x,orientation:S}=f.current;r.fillStyle=p,r.fillRect(0,0,t,n);let{shapes:C,pts:w,yMin:T,yMax:E}=m.current;if(C.length===0||u<=0||d<=0){r.fillStyle=v,r.font=`13px ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,eX(r);return}let D=S===`vertical`,O=D?e=>i+d*(1-(e-T)/(E-T)):e=>l+u*((e-T)/(E-T));s({left:l,top:i,width:u,height:d,...D?{y:{v0:T,v1:E}}:{x:{v0:T,v1:E}}});let k=MJ(E-T,5),A=FJ(T,E,k);r.strokeStyle=y,r.lineWidth=1,r.setLineDash([3,3]);for(let e of A)D?(r.beginPath(),r.moveTo(l,O(e)),r.lineTo(l+u,O(e)),r.stroke()):(r.beginPath(),r.moveTo(O(e),i),r.lineTo(O(e),i+d),r.stroke());if(r.setLineDash([]),r.fillStyle=v,r.font=`11px ${X.mono}`,r.strokeStyle=v,r.lineWidth=1,D){r.textAlign=`right`,r.textBaseline=`middle`;for(let e of A)r.beginPath(),r.moveTo(l-4,O(e)),r.lineTo(l,O(e)),r.stroke(),r.fillText(zJ(e,k),l-6,O(e))}else{r.textAlign=`center`,r.textBaseline=`top`;for(let e of A)r.beginPath(),r.moveTo(O(e),i+d),r.lineTo(O(e),i+d+4),r.stroke(),r.fillText(zJ(e,k),O(e),i+d+6)}r.strokeStyle=y,r.strokeRect(l,i,u,d),r.save(),r.beginPath(),r.rect(l,i,u,d),r.clip();let j=C.length,M=D?u/j:d/j;for(let e=0;e<j;e++){let{density:t,maxDensity:n,q1:a,median:o,q3:s}=C[e],c=D?l+M*e+M/2:i+M*e+M/2,u=M*.45;r.beginPath();for(let e=0;e<l4;e++){let i=t[e]/n*u,a=O(w[e]);D?e===0?r.moveTo(c-i,a):r.lineTo(c-i,a):e===0?r.moveTo(a,c-i):r.lineTo(a,c-i)}for(let e=l4-1;e>=0;e--){let i=t[e]/n*u,a=O(w[e]);D?r.lineTo(c+i,a):r.lineTo(a,c+i)}if(r.closePath(),r.fillStyle=b,r.globalAlpha=.35,r.fill(),r.strokeStyle=b,r.lineWidth=1,r.globalAlpha=.9,r.stroke(),r.globalAlpha=1,x){let e=u*.22;D?(r.fillStyle=b,r.globalAlpha=.7,r.fillRect(c-e,O(s),e*2,O(a)-O(s)),r.globalAlpha=1,r.strokeStyle=b,r.lineWidth=2,r.beginPath(),r.moveTo(c-e,O(o)),r.lineTo(c+e,O(o)),r.stroke()):(r.fillStyle=b,r.globalAlpha=.7,r.fillRect(O(a),c-e,O(s)-O(a),e*2),r.globalAlpha=1,r.strokeStyle=b,r.lineWidth=2,r.beginPath(),r.moveTo(O(o),c-e),r.lineTo(O(o),c+e),r.stroke())}}if(r.restore(),r.fillStyle=v,r.font=`11px ${X.mono}`,D){r.textAlign=`center`,r.textBaseline=`top`;for(let e=0;e<j;e++)r.fillText(C[e].label,l+M*e+M/2,i+d+6)}else{r.textAlign=`right`,r.textBaseline=`middle`;for(let e=0;e<j;e++)r.fillText(C[e].label,l-6,i+M*e+M/2)}}let y=(0,Z.useRef)(v);y.current=v;let b=(0,Z.useRef)(null);b.current??=mZ(()=>y.current(),()=>l.current);let x=()=>b.current.schedule();return(0,Z.useEffect)(()=>{b.current.now()}),(0,Z.useEffect)(()=>()=>b.current?.cancel(),[]),(0,Z.useEffect)(()=>{u.current=null,x()},[a]),(0,Z.useLayoutEffect)(()=>{let e=l.current;if(!e)return;let t=new fZ(()=>{u.current=null,x()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{let e=c.current;if(!e)return;let t=e=>{e.preventDefault(),d.current?.({clientX:e.clientX,clientY:e.clientY})};return e.addEventListener(`contextmenu`,t),()=>e.removeEventListener(`contextmenu`,t)},[]),(0,Q.jsx)(`div`,{ref:l,style:{position:`relative`,width:`100%`,height:`100%`},children:(0,Q.jsx)(`canvas`,{ref:c,className:`chart-canvas`,role:`img`,"aria-label":`Violin plot`})})}var p4={top:48,right:16,bottom:72,left:80},m4=[8,24,64],h4=[56,189,248];function g4(e,t,n){return[e[0]+(t[0]-e[0])*n,e[1]+(t[1]-e[1])*n,e[2]+(t[2]-e[2])*n]}function _4(e){return`${(e*100).toFixed(1)}%`}function v4(e,t,n){if(e.length===0)return null;let r=Math.min(e.length,t.length),i=Array(r),a=Array(r),o=new Set,s=0;for(let n=0;n<r;n++)i[n]=String(e[n]),a[n]=String(t[n]),o.add(i[n]),o.add(a[n]),i[n]===a[n]&&s++;let c=[...o].sort(),l=c.length,u=new Map(c.map((e,t)=>[e,t])),d=Array.from({length:l},()=>Array(l).fill(0));for(let e=0;e<r;e++)d[u.get(i[e])][u.get(a[e])]++;let f=d.map(e=>e.reduce((e,t)=>e+t,0));return{classes:c,matrix:n?d.map((e,t)=>e.map(e=>f[t]>0?e/f[t]:0)):d,raw:d,accuracy:s/e.length}}function y4({actual:e,predicted:t,normalize:n=!1,backgroundToken:r=``,onPlotContextMenu:i}){let a=(0,Z.useRef)(null),o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(null),u=(0,Z.useRef)(0),d=(0,Z.useRef)(i);(0,Z.useLayoutEffect)(()=>{d.current=i},[i]);let f=(0,Z.useRef)({actual:e,predicted:t,normalize:n});(0,Z.useLayoutEffect)(()=>{f.current={actual:e,predicted:t,normalize:n}},[e,t,n]);function p(){if(c.current)return c.current;let e=s.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return c.current=n,n}function m(){let e=s.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function h(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}let g=(0,Z.useMemo)(()=>v4(e,t,n),[e,t,n]),_=(0,Z.useRef)(g);(0,Z.useLayoutEffect)(()=>{_.current=g},[g]);let v=()=>_.current;function y(){let e=a.current;if(!e)return;let{w:t,h:n}=m(),r=h(e,t,n);if(!r)return;let{top:i,right:o,bottom:s,left:c}=p4,{bg:l,muted:u,grid:d}=p();r.fillStyle=l,r.fillRect(0,0,t,n);let g=v();if(!g){r.fillStyle=u,r.font=`13px ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,eX(r);return}let{classes:_,matrix:y,accuracy:b}=g,x=_.length,S=t-c-o,C=n-i-s,w=S/x,T=C/x,E=0;for(let e of y)for(let t of e)t>E&&(E=t);for(let e=0;e<x;e++)for(let t=0;t<x;t++){let n=y[e][t],[a,o,s]=g4(m4,h4,E>0?n/E:0);if(r.fillStyle=`rgb(${a|0},${o|0},${s|0})`,r.fillRect(c+t*w,i+e*T,w,T),w>24&&T>14){r.fillStyle=.299*a+.587*o+.114*s>100?`#000`:`#fff`,r.font=`${Math.min(12,Math.max(8,T*.38))}px ${X.mono}`,r.textAlign=`center`,r.textBaseline=`middle`;let l=f.current.normalize;r.fillText(l?_4(n):String(n|0),c+(t+.5)*w,i+(e+.5)*T)}}r.strokeStyle=l,r.lineWidth=.5;for(let e=0;e<=x;e++)r.beginPath(),r.moveTo(c+e*w,i),r.lineTo(c+e*w,i+C),r.stroke(),r.beginPath(),r.moveTo(c,i+e*T),r.lineTo(c+S,i+e*T),r.stroke();r.strokeStyle=d,r.strokeRect(c,i,S,C),r.fillStyle=u,r.font=`10px ${X.mono}`,r.textAlign=`right`,r.textBaseline=`middle`;for(let e=0;e<x;e++)r.fillText(_[e],c-4,i+(e+.5)*T);r.textAlign=`center`,r.textBaseline=`top`;for(let e=0;e<x;e++)r.save(),r.translate(c+(e+.5)*w,i+C+4),r.rotate(-Math.PI/4),r.fillText(_[e],0,0),r.restore();r.fillStyle=u,r.font=`11px ${X.mono}`,r.textAlign=`center`,r.textBaseline=`bottom`,r.fillText(`Predicted`,c+S/2,n-4),r.save(),r.translate(12,i+C/2),r.rotate(-Math.PI/2),r.textAlign=`center`,r.fillText(`Actual`,0,0),r.restore(),r.fillStyle=u,r.font=`11px ${X.mono}`,r.textAlign=`center`,r.textBaseline=`middle`,r.fillText(`Accuracy: ${_4(b)}`,c+S/2,i/2)}function b(){let e=o.current;if(!e)return;let{w:t,h:n}=m(),r=h(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=l.current;if(!i)return;let{top:a,right:s,bottom:c,left:u}=p4,d=v();if(!d)return;let{classes:p,matrix:g}=d,_=p.length,y=t-u-s,b=n-a-c,x=y/_,S=b/_;r.strokeStyle=`rgba(255,255,255,0.8)`,r.lineWidth=2,r.strokeRect(u+i.c*x+1,a+i.r*S+1,x-2,S-2);let C=g[i.r][i.c],w=f.current.normalize,T=`${p[i.r]} → ${p[i.c]}: ${w?_4(C):C|0}`;r.font=`11px ${X.mono}`;let E=r.measureText(T).width,D=Math.min(u+(i.c+1.1)*x,t-E-6),O=Math.max(6,a+(i.r-.3)*S);r.fillStyle=`rgba(0,0,0,0.75)`,r.fillRect(D-3,O-3,E+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(T,D,O)}let x=(0,Z.useRef)(y);x.current=y;let S=(0,Z.useRef)(null);S.current??=mZ(()=>x.current(),()=>s.current);let C=()=>S.current.schedule(),w=()=>{sZ(u.current),u.current=oZ(b)};return(0,Z.useEffect)(()=>{S.current.now()}),(0,Z.useEffect)(()=>()=>S.current?.cancel(),[]),(0,Z.useEffect)(()=>{c.current=null,C()},[r]),(0,Z.useLayoutEffect)(()=>{let e=s.current;if(!e)return;let t=new fZ(()=>{c.current=null,C(),w()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{let e=o.current;if(!e)return;let t=e=>{e.preventDefault(),d.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),{top:r,right:i,bottom:a,left:o}=p4,s=v();if(!s)return;let c=s.classes.length,u=n.width-o-i,d=n.height-r-a,f=Math.floor((t.clientX-n.left-o)/(u/c)),p=Math.floor((t.clientY-n.top-r)/(d/c));l.current=p>=0&&p<c&&f>=0&&f<c?{r:p,c:f}:null,w()},r=()=>{l.current=null,w()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),(0,Q.jsxs)(`div`,{ref:s,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:a,className:`chart-canvas`,role:`img`,"aria-label":`Confusion matrix`}),(0,Q.jsx)(`canvas`,{ref:o,className:`chart-canvas chart-overlay`})]})}var b4={top:24,right:24,bottom:48,left:64};function x4(e,t){let n=0,r=0,i=Math.min(e.length,t.length);for(let a=0;a<i;a++)e[a]-e[a]!==0||t[a]-t[a]!==0||(t[a]===1?n++:r++);let a=new Float64Array(n),o=new Float64Array(r);for(let n=0,r=0,s=0;n<i;n++)e[n]-e[n]!==0||t[n]-t[n]!==0||(t[n]===1?a[r++]=e[n]:o[s++]=e[n]);a.sort(),o.sort();let s=new Uint8Array(n+r);for(let e=0,t=n-1,i=r-1;e<s.length;e++)i<0||t>=0&&a[t]>=o[i]?(s[e]=1,t--):(s[e]=0,i--);return s}function S4(e){let t=0;for(let n of e)t+=n;let n=e.length-t;if(t===0||n===0)return null;let r=new Float64Array(e.length+2),i=new Float64Array(e.length+2),a=0,o=0,s=0;for(let c=0;c<e.length;c++)e[c]===1?a++:o++,r[c+1]=o/n,i[c+1]=a/t,s+=(r[c+1]-r[c])*(i[c+1]+i[c])/2;return r[e.length+1]=1,i[e.length+1]=1,{fpr:r,tpr:i,auc:s}}function C4(e){let t=0;for(let n of e)t+=n;if(t===0)return null;let n=new Float64Array(e.length),r=new Float64Array(e.length),i=0,a=0,o=0;for(let s=0;s<e.length;s++)e[s]===1?i++:a++,n[s]=i/t,r[s]=i/(i+a),s>0&&(o+=(n[s]-n[s-1])*r[s]);return{recall:n,precision:r,ap:o}}function w4(e,t,n,r){let i=n(0),a=r(0);e.moveTo(i,a);for(let o=1;o<t;o++){let s=n(o),c=r(o);o<t-1&&Math.abs(s-i)<.5&&Math.abs(c-a)<.5||(e.lineTo(s,c),i=s,a=c)}}function T4({scores:e,labels:t,mode:n=`roc`,color:r=`#f472b6`,backgroundToken:i=``,onPlotContextMenu:a}){let o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(a);(0,Z.useLayoutEffect)(()=>{l.current=a},[a]);let u=(0,Z.useRef)({scores:e,labels:t,mode:n,color:r});(0,Z.useLayoutEffect)(()=>{u.current={scores:e,labels:t,mode:n,color:r}},[e,t,n,r]);let d=(0,Z.useMemo)(()=>x4(e,t),[e,t]),f=(0,Z.useMemo)(()=>n===`pr`?{roc:null,pr:C4(d)}:{roc:S4(d),pr:null},[d,n]),p=(0,Z.useRef)(f);(0,Z.useLayoutEffect)(()=>{p.current=f},[f]);function m(){if(c.current)return c.current;let e=s.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return c.current=n,n}function h(){let e=s.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function g(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function _(){let e=o.current;if(!e)return;let{w:t,h:n}=h(),r=g(e,t,n);if(!r)return;let{top:i,right:a,bottom:s,left:c}=b4,l=t-c-a,d=n-i-s,{bg:f,muted:_,grid:v}=m(),{scores:y,mode:b,color:x}=u.current;if(r.fillStyle=f,r.fillRect(0,0,t,n),y.length===0){r.fillStyle=_,r.font=`13px ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,eX(r);return}let S=e=>c+e*l,C=e=>i+(1-e)*d,w=FJ(0,1,MJ(1,5));r.strokeStyle=v,r.lineWidth=1,r.setLineDash([3,3]);for(let e of w)r.beginPath(),r.moveTo(S(e),i),r.lineTo(S(e),i+d),r.stroke(),r.beginPath(),r.moveTo(c,C(e)),r.lineTo(c+l,C(e)),r.stroke();if(r.setLineDash([]),b===`roc`&&(r.strokeStyle=_,r.lineWidth=1,r.setLineDash([4,4]),r.beginPath(),r.moveTo(S(0),C(0)),r.lineTo(S(1),C(1)),r.stroke(),r.setLineDash([])),b===`roc`){let e=p.current.roc;if(e){let t=e.fpr.length,n=t=>S(e.fpr[t]),a=t=>C(e.tpr[t]);r.beginPath(),w4(r,t,n,a),r.strokeStyle=x,r.lineWidth=1,r.stroke(),r.beginPath(),w4(r,t,n,a),r.lineTo(S(1),C(0)),r.lineTo(S(0),C(0)),r.closePath(),r.fillStyle=x,r.globalAlpha=.15,r.fill(),r.globalAlpha=1,r.fillStyle=x,r.font=`bold 13px ${X.mono}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`AUC = ${e.auc.toFixed(3)}`,c+8,i+8)}}else{let e=p.current.pr;if(e){let t=K0(e.recall,e.precision,0,1,Math.max(1,Math.round(l*Math.min(2,window.devicePixelRatio||1))));r.beginPath();for(let n=0;n<t.length;n++){let i=S(e.recall[t[n]]),a=C(e.precision[t[n]]);n===0?r.moveTo(i,a):r.lineTo(i,a)}r.strokeStyle=x,r.lineWidth=1,r.stroke(),r.fillStyle=x,r.font=`bold 13px ${X.mono}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`AP = ${e.ap.toFixed(3)}`,c+8,i+8)}}r.fillStyle=_,r.font=`11px ${X.mono}`,r.strokeStyle=_,r.lineWidth=1,r.textAlign=`right`,r.textBaseline=`middle`;for(let e of w)r.beginPath(),r.moveTo(c-4,C(e)),r.lineTo(c,C(e)),r.stroke(),r.fillText(e.toFixed(1),c-6,C(e));r.textAlign=`center`,r.textBaseline=`top`;for(let e of w)r.beginPath(),r.moveTo(S(e),i+d),r.lineTo(S(e),i+d+4),r.stroke(),r.fillText(e.toFixed(1),S(e),i+d+6);r.strokeStyle=v,r.strokeRect(c,i,l,d),r.fillStyle=_,r.textAlign=`center`,r.textBaseline=`bottom`,r.fillText(b===`roc`?`False Positive Rate`:`Recall`,c+l/2,n-4),r.save(),r.translate(12,i+d/2),r.rotate(-Math.PI/2),r.textAlign=`center`,r.fillText(b===`roc`?`True Positive Rate`:`Precision`,0,0),r.restore()}let v=(0,Z.useRef)(_);v.current=_;let y=(0,Z.useRef)(null);y.current??=mZ(()=>v.current(),()=>s.current);let b=()=>y.current.schedule();return(0,Z.useEffect)(()=>{y.current.now()}),(0,Z.useEffect)(()=>()=>y.current?.cancel(),[]),(0,Z.useEffect)(()=>{c.current=null,b()},[i]),(0,Z.useLayoutEffect)(()=>{let e=s.current;if(!e)return;let t=new fZ(()=>{c.current=null,b()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{let e=o.current;if(!e)return;let t=e=>{e.preventDefault(),l.current?.({clientX:e.clientX,clientY:e.clientY})};return e.addEventListener(`contextmenu`,t),()=>e.removeEventListener(`contextmenu`,t)},[]),(0,Q.jsx)(`div`,{ref:s,style:{position:`relative`,width:`100%`,height:`100%`},children:(0,Q.jsx)(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`ROC / PR curve`})})}var E4={top:20,right:64,bottom:48,left:64};function D4({xValues:e,series:t,xLabel:n=`Epoch`,backgroundToken:r=``,onPlotContextMenu:i}){let a=iQ(),o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(null),u=(0,Z.useRef)(null),d=(0,Z.useRef)(0),f=(0,Z.useRef)(i);(0,Z.useLayoutEffect)(()=>{f.current=i},[i]);let p=(0,Z.useRef)({xValues:e,series:t,xLabel:n});(0,Z.useLayoutEffect)(()=>{p.current={xValues:e,series:t,xLabel:n}},[e,t,n]);function m(){if(l.current)return l.current;let e=c.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return l.current=n,n}function h(){let e=c.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function g(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}let _=(0,Z.useMemo)(()=>{let n=e=>{let t=1/0,n=-1/0;for(let r of e)for(let e=0;e<r.values.length;e++){let i=r.values[e];i<t&&(t=i),i>n&&(n=i)}if(!Number.isFinite(t))return{lo:0,hi:1};let r=(n-t)*.06||.1;return{lo:t-r,hi:n+r}},r=t.filter(e=>e.axis===`left`),i=t.filter(e=>e.axis===`right`),a=1/0,o=-1/0;for(let t=0;t<e.length;t++){let n=e[t];n<a&&(a=n),n>o&&(o=n)}return{leftExt:n(r.length?r:t),rightExt:n(i.length?i:t),hasRight:i.length>0,xMin:a,xMax:o,ascending:Y0(e)}},[e,t]),v=(0,Z.useRef)(_);(0,Z.useLayoutEffect)(()=>{v.current=_},[_]);function y(){let e=o.current;if(!e)return;let{w:t,h:n}=h(),r=g(e,t,n);if(!r)return;let{top:i,right:s,bottom:c,left:l}=E4,u=t-l-s,d=n-i-c,{bg:f,muted:_,grid:y}=m(),{xValues:b,series:x,xLabel:S}=p.current;if(r.fillStyle=f,r.fillRect(0,0,t,n),b.length===0||x.length===0){r.fillStyle=_,r.font=`13px ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,eX(r);return}let{leftExt:C,rightExt:w,hasRight:T,xMin:E,xMax:D,ascending:O}=v.current,k=e=>l+(e-E)/(D-E||1)*u;a({left:l,top:i,width:u,height:d,x:{v0:E,v1:D},y:{v0:C.lo,v1:C.hi}});let A=e=>i+(1-(e-C.lo)/(C.hi-C.lo))*d,j=e=>i+(1-(e-w.lo)/(w.hi-w.lo))*d,M=MJ(C.hi-C.lo,5),N=FJ(C.lo,C.hi,M);r.strokeStyle=y,r.lineWidth=1,r.setLineDash([3,3]);for(let e of N)r.beginPath(),r.moveTo(l,A(e)),r.lineTo(l+u,A(e)),r.stroke();let P=MJ(D-E,6),F=FJ(E,D,P);for(let e of F)r.beginPath(),r.moveTo(k(e),i),r.lineTo(k(e),i+d),r.stroke();r.setLineDash([]);let I=Math.min(2,window.devicePixelRatio||1),L=Math.max(1,Math.round(u*I));for(let e of x){let t=e.axis===`right`&&T?j:A,n=Math.min(b.length,e.values.length),i=O&&n>4*L?K0(b,e.values,E,D,L):null;r.beginPath();let a=!1;for(let o=0;o<(i?i.length:n);o++){let n=i?i[o]:o,s=b[n],c=e.values[n];if(s-s!==0||c-c!==0){a=!1;continue}let l=k(s),u=t(c);a?r.lineTo(l,u):(r.moveTo(l,u),a=!0)}r.strokeStyle=e.color,r.lineWidth=1,r.stroke()}r.fillStyle=_,r.font=`11px ${X.mono}`,r.strokeStyle=_,r.lineWidth=1,r.textAlign=`right`,r.textBaseline=`middle`;for(let e of N)r.beginPath(),r.moveTo(l-4,A(e)),r.lineTo(l,A(e)),r.stroke(),r.fillText(zJ(e,M),l-6,A(e));if(T){let e=MJ(w.hi-w.lo,5),t=FJ(w.lo,w.hi,e);r.textAlign=`left`;for(let n of t)r.beginPath(),r.moveTo(l+u,j(n)),r.lineTo(l+u+4,j(n)),r.stroke(),r.fillText(zJ(n,e),l+u+6,j(n))}r.textAlign=`center`,r.textBaseline=`top`;for(let e of F)r.beginPath(),r.moveTo(k(e),i+d),r.lineTo(k(e),i+d+4),r.stroke(),r.fillText(zJ(e,P),k(e),i+d+6);r.strokeStyle=y,r.strokeRect(l,i,u,d),r.fillStyle=_,r.textAlign=`center`,r.textBaseline=`bottom`,r.fillText(S,l+u/2,n-4);let R=l+8,z=i+6;r.font=`10px ${X.mono}`,r.textBaseline=`middle`;for(let e of x)r.fillStyle=e.color,r.fillRect(R,z-4,16,3),r.fillStyle=_,r.textAlign=`left`,r.fillText(e.label,R+20,z),R+=r.measureText(e.label).width+36,R>l+u-60&&(R=l+8,z+=14)}function b(){let e=s.current;if(!e)return;let{w:t,h:n}=h(),r=g(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=u.current;if(i===null)return;let{top:a,right:o,bottom:c,left:l}=E4,d=t-l-o,f=n-a-c,{muted:_}=m(),{xValues:y,series:b}=p.current;if(y.length===0)return;let{xMin:x,xMax:S,ascending:C}=v.current,w=e=>l+(e-x)/(S-x||1)*d,T=Math.max(l,Math.min(l+d,i));r.strokeStyle=_,r.lineWidth=1,r.setLineDash([3,3]),r.beginPath(),r.moveTo(T,a),r.lineTo(T,a+f),r.stroke(),r.setLineDash([]);let E=(T-l)/d,D=Math.round(E*(y.length-1));if(C){let e=x+E*(S-x),t=0,n=y.length;for(;t<n;){let r=t+n>>>1;y[r]<e?t=r+1:n=r}D=t>0&&(t>=y.length||e-y[t-1]<y[t]-e)?t-1:t}if(D<0||D>=y.length)return;let O=a+8;r.font=`10px ${X.mono}`,r.textBaseline=`top`;for(let e of b)D<e.values.length&&Number.isFinite(e.values[D])&&(r.fillStyle=e.color,r.textAlign=`left`,r.fillText(`${e.label}: ${BJ(e.values[D])}`,T+6,O),O+=14);w(0)}let x=(0,Z.useRef)(y);x.current=y;let S=(0,Z.useRef)(null);S.current??=mZ(()=>x.current(),()=>c.current);let C=()=>S.current.schedule(),w=()=>{sZ(d.current),d.current=oZ(b)};return(0,Z.useEffect)(()=>{S.current.now()}),(0,Z.useEffect)(()=>()=>S.current?.cancel(),[]),(0,Z.useEffect)(()=>{l.current=null,C()},[r]),(0,Z.useLayoutEffect)(()=>{let e=c.current;if(!e)return;let t=new fZ(()=>{l.current=null,C(),w()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{let e=s.current;if(!e)return;let t=e=>{e.preventDefault(),f.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect();u.current=t.clientX-n.left,w()},r=()=>{u.current=null,w()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),(0,Q.jsxs)(`div`,{ref:c,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`Loss curves`}),(0,Q.jsx)(`canvas`,{ref:s,className:`chart-canvas chart-overlay`})]})}var O4={top:40,right:24,bottom:40,left:72},k4=`#ef4444`,A4=`#f97316`,j4=`#22d3ee`;function M4(e,t){let n=e.length,r=e.value;if(n===0)return null;let i=0;for(let e=0;e<n;e++)i+=r[e];let a=i/n,o=0;for(let e=0;e<n;e++)o+=(r[e]-a)**2;let s=Math.sqrt(o/n),c=a+t*s,l=a-t*s,u=l,d=c,f=0;for(let e=0;e<n;e++){let t=r[e];t<u&&(u=t),t>d&&(d=t),(t>c||t<l)&&f++}let p=(d-u)*.08||.5,m=new Uint32Array(f);for(let e=0,t=0;e<n;e++)(r[e]>c||r[e]<l)&&(m[t++]=e);return{mean:a,sd:s,ucl:c,lcl:l,yMin:u-p,yMax:d+p,ooc:m}}function N4({points:e,sigmaLevel:t=3,color:n=`#22d3ee`,backgroundToken:r=``,onPlotContextMenu:i}){let a=iQ(),o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(null),u=(0,Z.useRef)(null),d=(0,Z.useRef)(0),f=(0,Z.useRef)(i);(0,Z.useLayoutEffect)(()=>{f.current=i},[i]);let p=(0,Z.useRef)({points:e,sigmaLevel:t,color:n});(0,Z.useLayoutEffect)(()=>{p.current={points:e,sigmaLevel:t,color:n}},[e,t,n]);function m(){if(l.current)return l.current;let e=c.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return l.current=n,n}function h(){let e=c.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function g(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}let _=(0,Z.useMemo)(()=>M4(e,t),[e,t]),v=(0,Z.useRef)(_);(0,Z.useLayoutEffect)(()=>{v.current=_},[_]);let y=()=>v.current;function b(){let e=o.current;if(!e)return;let{w:t,h:n}=h(),r=g(e,t,n);if(!r)return;let{top:i,right:s,bottom:c,left:l}=O4,u=t-l-s,d=n-i-c,{bg:f,muted:_,grid:v}=m(),{points:b,color:x}=p.current;if(r.fillStyle=f,r.fillRect(0,0,t,n),b.length===0){r.fillStyle=_,r.font=`13px ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,eX(r);return}let S=y(),{mean:C,ucl:w,lcl:T,yMin:E,yMax:D}=S,O=e=>l+e/(b.length-1||1)*u;a({left:l,top:i,width:u,height:d,x:{v0:0,v1:b.length-1||1}});let k=e=>i+(1-(e-E)/(D-E))*d,A=MJ(D-E,5),j=FJ(E,D,A);r.strokeStyle=v,r.lineWidth=1,r.setLineDash([3,3]);for(let e of j)r.beginPath(),r.moveTo(l,k(e)),r.lineTo(l+u,k(e)),r.stroke();r.setLineDash([]);let M=(e,t,n,a=[])=>{let o=k(e);o<i||o>i+d||(r.strokeStyle=t,r.lineWidth=1.2,r.setLineDash(a),r.beginPath(),r.moveTo(l,o),r.lineTo(l+u,o),r.stroke(),r.setLineDash([]),r.fillStyle=t,r.font=`9px ${X.mono}`,r.textAlign=`right`,r.textBaseline=`middle`,r.fillText(`${n} ${BJ(e)}`,l+u-2,o-5))};M(w,A4,`UCL`,[5,3]),M(C,j4,`CL`,[]),M(T,A4,`LCL`,[5,3]);let N=Math.min(2,window.devicePixelRatio||1),P=Math.max(1,Math.round(u*N)),F=b.length,I=b.value,L=q0(I,P);r.beginPath();for(let e=0;e<L.length;e++){let t=L[e],n=O(t),i=k(I[t]);e===0?r.moveTo(n,i):r.lineTo(n,i)}r.strokeStyle=x,r.lineWidth=1,r.stroke();let R=(e,t)=>{r.beginPath(),r.arc(O(e),k(I[e]),t?4:3,0,Math.PI*2),r.fillStyle=t?k4:x,r.fill()};if(F<=u/4)for(let e=0;e<F;e++)R(e,I[e]>w||I[e]<T);else{let e=NaN,t=NaN;for(let n of S.ooc){let r=Math.round(O(n)),i=Math.round(k(I[n]));r===e&&i===t||(e=r,t=i,R(n,!0))}}r.fillStyle=_,r.font=`11px ${X.mono}`,r.strokeStyle=_,r.lineWidth=1,r.textAlign=`right`,r.textBaseline=`middle`;for(let e of j)r.beginPath(),r.moveTo(l-4,k(e)),r.lineTo(l,k(e)),r.stroke(),r.fillText(zJ(e,A),l-6,k(e));r.strokeStyle=v,r.strokeRect(l,i,u,d)}function x(){let e=s.current;if(!e)return;let{w:t,h:n}=h(),r=g(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=u.current;if(i===null)return;let{top:a,right:o,bottom:c,left:l}=O4,d=t-l-o,f=n-a-c,{muted:_}=m(),{points:v}=p.current;if(v.length===0)return;let{ucl:b,lcl:x,yMin:S,yMax:C}=y(),w=e=>l+e/(v.length-1||1)*d,T=e=>a+(1-(e-S)/(C-S))*f,E=Math.round((i-l)/d*(v.length-1));if(E<0||E>=v.length)return;let D=v.value[E],O=w(E),k=T(D);r.strokeStyle=_,r.lineWidth=1,r.setLineDash([3,3]),r.beginPath(),r.moveTo(O,a),r.lineTo(O,a+f),r.stroke(),r.setLineDash([]);let A=v.subgroup?.(E),j=`${A?`${A}: `:`#${E+1}: `}${BJ(D)}`;r.font=`11px ${X.mono}`;let M=r.measureText(j).width,N=O+8+M>l+d?O-M-10:O+8;r.fillStyle=`rgba(0,0,0,0.75)`,r.fillRect(N-3,k-12,M+6,18),r.fillStyle=D>b||D<x?k4:_,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(j,N,k-11)}let S=(0,Z.useRef)(b);S.current=b;let C=(0,Z.useRef)(null);C.current??=mZ(()=>S.current(),()=>c.current);let w=()=>C.current.schedule(),T=()=>{sZ(d.current),d.current=oZ(x)};return(0,Z.useEffect)(()=>{C.current.now()}),(0,Z.useEffect)(()=>()=>C.current?.cancel(),[]),(0,Z.useEffect)(()=>{l.current=null,w()},[r]),(0,Z.useLayoutEffect)(()=>{let e=c.current;if(!e)return;let t=new fZ(()=>{l.current=null,w(),T()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{let e=s.current;if(!e)return;let t=e=>{e.preventDefault(),f.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect();u.current=t.clientX-n.left,T()},r=()=>{u.current=null,T()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),(0,Q.jsxs)(`div`,{ref:c,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`Control chart`}),(0,Q.jsx)(`canvas`,{ref:s,className:`chart-canvas chart-overlay`})]})}var P4={top:32,right:24,bottom:24,left:24},F4=[`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`,`#facc15`,`#60a5fa`],I4=16;function L4(e){return`rgb(${Math.round(255*Math.min(1,Math.max(0,3.5*e-.5)))},${Math.round(255*Math.min(1,Math.max(0,e<.5?2*e:2-2*e)))},${Math.round(255*Math.min(1,Math.max(0,1.5-3.5*e)))})`}function R4(e,t,n,r){let i=Math.min(t,e.columns.length),a=e.columns.slice(0,i).map(t=>{let n=1/0,r=-1/0;for(let i=0;i<e.length;i++){let e=t[i];e<n&&(n=e),e>r&&(r=e)}if(!Number.isFinite(n))return{lo:0,hi:1};let i=(r-n)*.05||.5;return{lo:n-i,hi:r+i}}),o={lo:0,hi:1},s=new Int32Array(e.length),c=[r];if(n&&e.colorValue){let t=e.colorValue,n=1/0,r=-1/0;for(let i=0;i<e.length;i++)t[i]<n&&(n=t[i]),t[i]>r&&(r=t[i]);Number.isFinite(n)&&(o={lo:n,hi:r}),c=Array.from({length:I4},(e,t)=>L4((t+.5)/I4));for(let n=0;n<e.length;n++){let e=(t[n]-o.lo)/(o.hi-o.lo||1);s[n]=t[n]===t[n]?Math.max(0,Math.min(I4-1,Math.floor(e*I4))):-1}for(let t=0;t<e.length;t++)s[t]<0&&(s[t]=0)}else if(!n&&e.colorIndex){c=F4;for(let t=0;t<e.length;t++)s[t]=Math.max(0,e.colorIndex[t])%F4.length}let l=new Int32Array(c.length);for(let t=0;t<e.length;t++)l[s[t]]++;let u=c.map((e,t)=>({color:e,x:new Float64Array(l[t]*i),y:new Float64Array(l[t]*i),starts:new Uint8Array(l[t]*i)})),d=new Int32Array(c.length);for(let t=0;t<e.length;t++){let n=u[s[t]],r=d[s[t]]++*i;n.starts[r]=1;for(let o=0;o<i;o++,r++){let i=a[o];n.x[r]=o,n.y[r]=(e.columns[o][t]-i.lo)/(i.hi-i.lo)}}return{k:i,extents:a,colorExt:o,groups:u.filter(e=>e.x.length>0)}}function z4({rows:e,axes:t,color:n=`#64748b`,colorByNumeric:r=!1,backgroundToken:i=``,onPlotContextMenu:a}){let o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(null),u=(0,Z.useRef)(null),d=(0,Z.useRef)(null),f=(0,Z.useRef)(null),p=(0,Z.useRef)(0),m=(0,Z.useRef)(a);(0,Z.useLayoutEffect)(()=>{m.current=a},[a]);let h=(0,Z.useMemo)(()=>R4(e,t.length,r,n),[e,t.length,r,n]),g=(0,Z.useRef)({rows:e,axes:t,colorByNumeric:r,model:h});(0,Z.useLayoutEffect)(()=>{g.current={rows:e,axes:t,colorByNumeric:r,model:h}},[e,t,r,h]);let _=V0(s),v=(0,Z.useRef)(null);function y(){if(d.current)return d.current;let e=u.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return d.current=n,n}function b(){let e=u.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function x(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function S(){let e=o.current;if(!e)return;let{w:t,h:n}=b(),r=x(e,t,n);if(!r)return;let i=c.current?x(c.current,t,n):null;i?.clearRect(0,0,t,n);let a=i??r,{top:s,right:l,bottom:d,left:f}=P4,{bg:p,muted:m}=y(),{rows:h,axes:S,colorByNumeric:C,model:w}=g.current;r.fillStyle=p,r.fillRect(0,0,t,n);let T=_(t,n);if(S.length<2||h.length===0||w.k<2){T?.keep([]),T?.render(),r.fillStyle=m,r.font=`13px ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`Select ≥ 2 axes`,f+8,s+8);return}let E=t-f-l,D=n-s-d,O=w.k,k=Array.from({length:O},(e,t)=>f+t/(O-1)*E),A=(e,t)=>{let n=w.extents[t];return s+(1-(e-n.lo)/(n.hi-n.lo))*D},j=Math.max(.05,Math.min(.7,60/h.length));if(T)v.current!==w&&(w.groups.forEach((e,t)=>T.setLine(`c${t}`,e.x,e.y,e0(e.color,j),1,e.starts)),v.current=w,lZ(u.current)),T.keep(w.groups.map((e,t)=>`c${t}`)),T.setView(0,O-1,0,1,{left:f,top:s,width:E,height:D}),T.render();else{r.globalAlpha=j;for(let e of w.groups){r.beginPath();let t=!1;for(let n=0;n<e.x.length;n++){let i=e.y[n];if(e.starts[n]&&(t=!1),i!==i){t=!1;continue}let a=f+e.x[n]/(O-1)*E,o=s+(1-i)*D;t?r.lineTo(a,o):(r.moveTo(a,o),t=!0)}r.strokeStyle=e.color,r.lineWidth=1,r.stroke()}r.globalAlpha=1}a.strokeStyle=m,a.lineWidth=1.5;for(let e=0;e<O;e++)a.beginPath(),a.moveTo(k[e],s),a.lineTo(k[e],s+D),a.stroke();a.fillStyle=m,a.font=`9px ${X.mono}`;for(let e=0;e<O;e++){let t=w.extents[e];for(let n of[0,.25,.5,.75,1]){let r=t.lo+n*(t.hi-t.lo),i=A(r,e);a.beginPath(),a.moveTo(k[e]-3,i),a.lineTo(k[e]+3,i),a.stroke(),a.textAlign=e===O-1?`left`:`right`,a.textBaseline=`middle`,a.fillText(zJ(r,(t.hi-t.lo)/4),k[e]+(e===O-1?5:-5),i)}a.font=`10px ${X.mono}`,a.textAlign=`center`,a.textBaseline=`bottom`,a.fillText(S[e],k[e],s-4)}let M=h.colorLabels??[];if(!C&&M.length>0&&M.length<=10){let e=f,t=s+D+8;a.font=`9px ${X.mono}`,a.textBaseline=`top`,M.forEach((n,r)=>{a.fillStyle=F4[r%F4.length],a.fillRect(e,t,10,8),a.fillStyle=m,a.textAlign=`left`,a.fillText(n,e+13,t),e+=a.measureText(n).width+26,e>f+E-40&&(e=f,t+=12)})}}function C(){let e=l.current;if(!e)return;let{w:t,h:n}=b(),r=x(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=f.current;if(i===null)return;let{top:a,right:o,bottom:s,left:c}=P4,{axes:u}=g.current;if(u.length<2)return;let d=t-c-o,p=c+i/(u.length-1)*d;r.strokeStyle=`rgba(255,255,255,0.6)`,r.lineWidth=2,r.beginPath(),r.moveTo(p,a-4),r.lineTo(p,a+(n-a-s)+4),r.stroke()}let w=(0,Z.useRef)(S);w.current=S;let T=(0,Z.useRef)(null);T.current??=mZ(()=>w.current(),()=>u.current);let E=()=>T.current.schedule(),D=()=>{sZ(p.current),p.current=oZ(C)};return(0,Z.useEffect)(()=>{T.current.now()}),(0,Z.useEffect)(()=>()=>T.current?.cancel(),[]),(0,Z.useEffect)(()=>{d.current=null,E()},[i]),(0,Z.useLayoutEffect)(()=>{let e=u.current;if(!e)return;let t=new fZ(()=>{d.current=null,E(),D()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{let e=l.current;if(!e)return;let t=e=>{e.preventDefault(),m.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),{axes:r}=g.current;if(r.length<2)return;let i=n.width-P4.left-P4.right,a=r.length,o=t.clientX-n.left-P4.left,s=Math.round(o/i*(a-1));f.current=Math.abs(o-s/(a-1)*i)<20&&s>=0&&s<a?s:null,D()},r=()=>{f.current=null,D()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),(0,Q.jsxs)(`div`,{ref:u,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`Parallel coordinates`}),(0,Q.jsx)(`canvas`,{ref:s,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),(0,Q.jsx)(`canvas`,{ref:c,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),(0,Q.jsx)(`canvas`,{ref:l,className:`chart-canvas chart-overlay`})]})}function B4(e,t,n,r,i,a){let o=Math.max(1,Math.ceil(t/r)),s=Math.max(1,Math.ceil(n/r)),c=e=>{let s=i(e),c=a(e);return s>=0&&s<t&&c>=0&&c<n?Math.floor(c/r)*o+Math.floor(s/r):-1},l=new Uint32Array(o*s+1);for(let t=0;t<e;t++){let e=c(t);e>=0&&l[e+1]++}for(let e=0;e<o*s;e++)l[e+1]+=l[e];let u=l.slice(0,o*s),d=new Uint32Array(l[o*s]);for(let t=0;t<e;t++){let e=c(t);e>=0&&(d[u[e]++]=t)}return{cell:r,nx:o,ny:s,start:l,ix:d}}function V4(e,t,n,r,i,a,o){let s=Math.floor(t/e.cell),c=Math.floor(n/e.cell),l=-1,u=r*r;for(let r=c-1;r<=c+1;r++)if(!(r<0||r>=e.ny))for(let c=s-1;c<=s+1;c++){if(c<0||c>=e.nx)continue;let s=r*e.nx+c;for(let r=e.start[s];r<e.start[s+1];r++){let s=e.ix[r],c=(i(s)-t)**2+(a(s)-n)**2;c<u&&(!o||c<o(s)**2)&&(u=c,l=s)}}return l<0?null:l}var H4={top:16,right:16,bottom:16,left:16},U4=[`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`,`#facc15`,`#60a5fa`];function W4(e){return[Math.round(255*Math.min(1,Math.max(0,3.5*e-.5))),Math.round(255*Math.min(1,Math.max(0,e<.5?2*e:2-2*e))),Math.round(255*Math.min(1,Math.max(0,1.5-3.5*e)))]}function G4(e){let[t,n,r]=W4(e);return`rgb(${t},${n},${r})`}var K4=(()=>{let e=new Uint8Array(1024);for(let t=0;t<256;t++)e.set([...W4(t/255),255],t*4);return e})(),q4=(()=>{let e=new Uint8Array(1024);for(let t=0;t<256;t++){let[n,r,i]=e0(U4[t%U4.length],1);e.set([n*255,r*255,i*255,255],t*4)}return e});function J4(e,t){let n=1/0,r=-1/0,i=1/0,a=-1/0;for(let t=0;t<e.length;t++){let o=e.x[t],s=e.y[t];o<n&&(n=o),o>r&&(r=o),s<i&&(i=s),s>a&&(a=s)}let o=!Number.isFinite(n)||!Number.isFinite(i)?{xLo:-1,xHi:1,yLo:-1,yHi:1}:(()=>{let e=(r-n)*.05||.5,t=(a-i)*.05||.5;return{xLo:n-e,xHi:r+e,yLo:i-t,yHi:a+t}})(),s={lo:0,hi:1},c=null,l=`single`;if(t&&e.colorValue){let t=e.colorValue,n=1/0,r=-1/0;for(let i=0;i<e.length;i++){let e=t[i];e<n&&(n=e),e>r&&(r=e)}Number.isFinite(n)&&(s={lo:n,hi:r}),c=new Float32Array(e.length);let i=s.hi-s.lo;for(let n=0;n<e.length;n++)c[n]=t[n]===t[n]?Math.max(0,Math.min(1,i>0?(t[n]-s.lo)/i:.5)):0;l=`colormap`}else !t&&e.colorIndex&&(c=Float32Array.from(e.colorIndex,e=>e>=0?e%256:0),l=`dataset`);return{ext:o,colorExt:s,key:c,mode:l}}function Y4({points:e,color:t=`#64748b`,colorByNumeric:n=!1,pointSize:r=4,backgroundToken:i=``,onPlotContextMenu:a}){let o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(null),u=(0,Z.useRef)(null),d=(0,Z.useRef)(null),f=(0,Z.useRef)(0),p=(0,Z.useRef)(a);(0,Z.useLayoutEffect)(()=>{p.current=a},[a]);let m=(0,Z.useMemo)(()=>J4(e,n),[e,n]),h=(0,Z.useRef)({points:e,color:t,colorByNumeric:n,pointSize:r,model:m});(0,Z.useLayoutEffect)(()=>{h.current={points:e,color:t,colorByNumeric:n,pointSize:r,model:m}},[e,t,n,r,m]);let g=(0,Z.useRef)({r:null,failed:!1,size:``,model:null,style:``});(0,Z.useEffect)(()=>()=>{g.current.r?.dispose(),g.current.r=null},[]);function _(){if(u.current)return u.current;let e=l.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return u.current=n,n}function v(){let e=l.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function y(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function b(e,t){let{top:n,right:r,bottom:i,left:a}=H4,o=e-a-r,s=t-n-i,c=h.current.model.ext;return{xToPx:e=>a+(e-c.xLo)/(c.xHi-c.xLo)*o,yToPx:e=>n+(1-(e-c.yLo)/(c.yHi-c.yLo))*s,plotW:o,plotH:s,ext:c}}function x(e,t){let n=g.current;!n.r&&!n.failed&&s.current&&(n.r=NX(s.current,Z$),n.failed=!n.r);let r=n.r;if(!r||!s.current)return null;let i=Math.min(2,window.devicePixelRatio||1),a=`${e}x${t}@${i}`;n.size!==a&&(r.resize(e,t,i),s.current.style.width=`${e}px`,s.current.style.height=`${t}px`,n.size=a);let{points:o,model:c,color:u,pointSize:d}=h.current;n.model!==c&&(r.setData(o.x,o.y,c.key??void 0),n.model=c,lZ(l.current));let f=`${c.mode}|${u}|${d}`;return n.style!==f&&(r.setStyle(c.mode===`single`?{kind:`single`,rgba:e0(u,1)}:{kind:c.mode,palette:c.mode===`colormap`?K4:q4()},d,.8),r.setDraw(!0,!1,0),n.style=f),r}function S(){let e=o.current;if(!e)return;let{w:t,h:n}=v(),r=y(e,t,n);if(!r)return;let{bg:i,muted:a}=_(),{points:s,color:c,colorByNumeric:l,pointSize:u,model:d}=h.current;r.fillStyle=i,r.fillRect(0,0,t,n);let f=x(t,n);if(s.length===0){f?.setData([],[]),g.current.model=null,f?.render(),r.fillStyle=a,r.font=`13px ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,eX(r);return}let p=d.colorExt,{xToPx:m,yToPx:S,plotW:C,plotH:w,ext:T}=b(t,n);if(f)f.setView(T.xLo,T.xHi,T.yLo,T.yHi,{left:H4.left,top:H4.top,width:C,height:w}),f.render();else{for(let e=0;e<s.length;e++){let t=s.x[e],n=s.y[e];if(t!==t||n!==n)continue;let i=d.key?.[e]??0;r.beginPath(),r.arc(m(t),S(n),u,0,Math.PI*2),r.fillStyle=d.mode===`colormap`?G4(i):d.mode===`dataset`?U4[i%U4.length]:c,r.globalAlpha=.8,r.fill()}r.globalAlpha=1}if(l){let e=Math.min(120,Math.floor((n-H4.top-H4.bottom)*.4)),i=t-H4.right-12,o=H4.top+8;for(let t=0;t<e;t++)r.fillStyle=G4(1-t/(e-1)),r.fillRect(i,o+t,8,1);r.fillStyle=a,r.font=`9px ${X.mono}`,r.textAlign=`left`,r.textBaseline=`middle`;let s=e=>Math.abs(e)>=1e4||Math.abs(e)<.001&&e!==0?e.toExponential(1):String(parseFloat(e.toPrecision(3)));r.fillText(s(p.hi),i+10,o),r.fillText(s(p.lo),i+10,o+e)}let E=s.colorLabels??[];if(!l&&E.length>0&&E.length<=10){let e=H4.left,i=n-H4.bottom-10;r.font=`9px ${X.mono}`,r.textBaseline=`top`,E.forEach((n,o)=>{e>t-H4.right-60&&(e=H4.left,i-=14),r.fillStyle=U4[o%U4.length],r.beginPath(),r.arc(e+4,i+4,4,0,Math.PI*2),r.fill(),r.fillStyle=a,r.textAlign=`left`,r.fillText(n,e+10,i),e+=r.measureText(n).width+20})}}function C(){let e=c.current;if(!e)return;let{w:t,h:n}=v(),r=y(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=d.current;if(i===null)return;let{points:a,pointSize:o}=h.current;if(i<0||i>=a.length)return;let{xToPx:s,yToPx:l}=b(t,n),u=a.x[i],f=a.y[i],p=s(u),m=l(f);r.beginPath(),r.arc(p,m,o+3,0,Math.PI*2),r.strokeStyle=`rgba(255,255,255,0.9)`,r.lineWidth=2,r.stroke();let g=[],_=a.label?.(i);_&&g.push(_);let x=a.colorIndex?.[i];x!==void 0&&x>=0&&a.colorLabels?g.push(a.colorLabels[x]):a.colorValue&&g.push(a.colorValue[i].toFixed(3)),g.push(`(${u.toFixed(3)}, ${f.toFixed(3)})`);let S=g.join(` · `);r.font=`11px ${X.mono}`;let C=r.measureText(S).width,w=Math.max(4,Math.min(t-C-8,p+10)),T=m-20<H4.top?m+10:m-20;r.fillStyle=`rgba(0,0,0,0.75)`,r.fillRect(w-3,T-3,C+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(S,w,T)}let w=(0,Z.useRef)(S);w.current=S;let T=(0,Z.useRef)(null);T.current??=mZ(()=>w.current(),()=>l.current);let E=()=>T.current.schedule(),D=()=>{sZ(f.current),f.current=oZ(C)};return(0,Z.useEffect)(()=>{T.current.now()}),(0,Z.useEffect)(()=>()=>T.current?.cancel(),[]),(0,Z.useEffect)(()=>{u.current=null,E()},[i]),(0,Z.useLayoutEffect)(()=>{let e=l.current;if(!e)return;let t=new fZ(()=>{u.current=null,E(),D()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{let e=c.current;if(!e)return;let t=null,n=e=>{e.preventDefault(),p.current?.({clientX:e.clientX,clientY:e.clientY})},r=n=>{let r=e.getBoundingClientRect(),{points:i,pointSize:a,model:o}=h.current,{w:s,h:c}=v(),{xToPx:l,yToPx:u,plotW:f,plotH:p}=b(s,c),m=e=>l(i.x[e])-H4.left,g=e=>u(i.y[e])-H4.top,_=a+8,y=`${s}|${c}|${_}`;(!t||t.model!==o||t.key!==y)&&(t={model:o,key:y,g:B4(i.length,f,p,_,m,g)}),d.current=V4(t.g,n.clientX-r.left-H4.left,n.clientY-r.top-H4.top,_,m,g),D()},i=()=>{d.current=null,D()};return e.addEventListener(`contextmenu`,n),e.addEventListener(`mousemove`,r),e.addEventListener(`mouseleave`,i),()=>{e.removeEventListener(`contextmenu`,n),e.removeEventListener(`mousemove`,r),e.removeEventListener(`mouseleave`,i)}},[]),(0,Q.jsxs)(`div`,{ref:l,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`Embedding / scatter`}),(0,Q.jsx)(`canvas`,{ref:s,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),(0,Q.jsx)(`canvas`,{ref:c,className:`chart-canvas chart-overlay`})]})}var X4={top:8,right:8,bottom:8,left:8},Z4=20,Q4=[`#f97316`,`#fb923c`,`#fdba74`,`#fbbf24`,`#fcd34d`,`#4ade80`,`#34d399`,`#38bdf8`,`#818cf8`,`#a78bfa`];function $4(e){let t=new Map;for(let n of e){let e=n.parent??``;t.has(e)||t.set(e,[]),t.get(e).push(n)}function n(r,i){let a=(t.get(r)??[]).map(e=>n(e.name,i+1)),o=e.find(e=>e.name===r),s=a.reduce((e,t)=>e+t.value,0);return{name:r,value:o?Math.max(o.value,s):s,children:a,depth:i,x0:0,x1:1}}let r=new Set(e.map(e=>e.name)),i=e.filter(e=>!e.parent||!r.has(e.parent)).map(e=>n(e.name,0)),a=i.reduce((e,t)=>e+t.value,0)||1;function o(e,t,n){e.x0=t,e.x1=n;let r=n-t,i=t;for(let t of e.children){let n=t.value/e.value*r;o(t,i,i+n),i+=n}}let s=0;for(let e of i){let t=e.value/a;o(e,s,s+t),s+=t}return i}function e3(e){let t=[];function n(e){t.push(e);for(let t of e.children)n(t)}for(let t of e)n(t);return t}function t3(e){let t=0;function n(e){e.depth>t&&(t=e.depth);for(let t of e.children)n(t)}for(let t of e)n(t);return t}function n3(e){return Q4[e%Q4.length]}function r3({nodes:e,direction:t=`bottomup`,backgroundToken:n=``,onPlotContextMenu:r}){let i=(0,Z.useRef)(null),a=(0,Z.useRef)(null),o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(0),u=(0,Z.useRef)(r);(0,Z.useLayoutEffect)(()=>{u.current=r},[r]);let d=(0,Z.useRef)({nodes:e,direction:t});(0,Z.useLayoutEffect)(()=>{d.current={nodes:e,direction:t}},[e,t]);let f=(0,Z.useMemo)(()=>{let t=$4(e);return{roots:t,flat:e3(t),numRows:t3(t)+1}},[e]),p=(0,Z.useRef)(f);(0,Z.useLayoutEffect)(()=>{p.current=f},[f]);function m(){if(s.current)return s.current;let e=o.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return s.current=n,n}function h(){let e=o.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||400)}}function g(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function _(e,t,n,r,i){let a=X4.left+e.x0*t,o=(e.x1-e.x0)*t;return{x:a,y:i===`topdown`?X4.top+e.depth*Z4:X4.top+n-(e.depth+1)*Z4,w:o,h:Z4-1}}function v(){let e=i.current;if(!e)return;let{w:t,h:n}=h(),r=g(e,t,n);if(!r)return;let{bg:a,muted:o}=m(),{nodes:s,direction:c}=d.current;if(r.fillStyle=a,r.fillRect(0,0,t,n),s.length===0){r.fillStyle=o,r.font=`13px ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,eX(r);return}let{flat:l,numRows:u}=p.current,f=t-X4.left-X4.right,v=u*Z4;for(let e of l){let t=_(e,f,v,u,c);if(!(t.w<1)&&(r.fillStyle=n3(e.depth),r.fillRect(t.x,t.y,t.w,t.h),t.w>24)){r.fillStyle=`rgba(0,0,0,0.75)`,r.font=`${Math.min(11,Z4-4)}px ${X.mono}`,r.textAlign=`left`,r.textBaseline=`middle`;let n=e.name,i=Math.floor((t.w-4)/7),a=n.length>i?n.slice(0,i-1)+`…`:n;r.fillText(a,t.x+3,t.y+Z4/2)}}}function y(){let e=a.current;if(!e)return;let{w:t,h:n}=h(),r=g(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=c.current;if(!i)return;let{direction:o}=d.current,{roots:s,numRows:l}=p.current;if(s.length===0)return;let u=_(i,t-X4.left-X4.right,l*Z4,l,o);r.strokeStyle=`rgba(255,255,255,0.9)`,r.lineWidth=2,r.strokeRect(u.x+1,u.y+1,u.w-2,u.h-2);let f=`${i.name} (${i.value.toLocaleString()})`;r.font=`11px ${X.mono}`;let m=r.measureText(f).width,v=Math.max(4,Math.min(t-m-8,u.x+u.w/2-m/2)),y=u.y<30?u.y+Z4+4:u.y-20;r.fillStyle=`rgba(0,0,0,0.8)`,r.fillRect(v-3,y-3,m+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(f,v,y)}let b=(0,Z.useRef)(v);b.current=v;let x=(0,Z.useRef)(null);x.current??=mZ(()=>b.current(),()=>o.current);let S=()=>x.current.schedule(),C=()=>{sZ(l.current),l.current=oZ(y)};return(0,Z.useEffect)(()=>{x.current.now()}),(0,Z.useEffect)(()=>()=>x.current?.cancel(),[]),(0,Z.useEffect)(()=>{s.current=null,S()},[n]),(0,Z.useLayoutEffect)(()=>{let e=o.current;if(!e)return;let t=new fZ(()=>{s.current=null,S(),C()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{let e=a.current;if(!e)return;let t=e=>{e.preventDefault(),u.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),{direction:r}=d.current,{roots:i,flat:a,numRows:o}=p.current;if(i.length===0){c.current=null,C();return}let s=t.clientX-n.left,l=t.clientY-n.top,u=n.width-X4.left-X4.right,f=o*Z4,m=null;for(let e of a){let t=_(e,u,f,o,r);if(s>=t.x&&s<=t.x+t.w&&l>=t.y&&l<=t.y+t.h){m=e;break}}c.current=m,C()},r=()=>{c.current=null,C()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),(0,Q.jsxs)(`div`,{ref:o,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:i,className:`chart-canvas`,role:`img`,"aria-label":`Flame graph`}),(0,Q.jsx)(`canvas`,{ref:a,className:`chart-canvas chart-overlay`})]})}var i3={top:24,right:24,bottom:52,left:56},a3=[`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`,`#facc15`,`#60a5fa`],o3=.8;function s3(e,t,n,r){let i,a,o;if(t)a=t.length,i=t.values,o=e=>String(e+1);else{let t=e??[];a=t.length,i=Array.from({length:n},(e,n)=>Float64Array.from(t,e=>e.values[n]??0)),o=e=>t[e].label}let s=0,c=0;if(r===`stacked`)for(let e=0;e<a;e++){let t=0,n=0;for(let r of i){let i=r[e];i>0?t+=i:i<0&&(n+=i)}t>c&&(c=t),n<s&&(s=n)}else for(let e of i)for(let t=0;t<a;t++){let n=e[t];n>c&&(c=n),n<s&&(s=n)}return c===s&&(c=s+1),{n:a,values:i,label:o,lo:s,hi:c}}function c3(e,t,n){let r=e.values.length,i=[],a=[],o=[],s=[],c=[],l=(e,t,n,r,l)=>{i.push(e),a.push(t),o.push(n),s.push(r),c.push(l)};if(e.n<=n)for(let n=0;n<e.n;n++)if(t===`grouped`){let t=.8/r;for(let i=0;i<r;i++){let r=e.values[i][n];r===r&&l(n-.4+i*t,n-.4+(i+1)*t-t*.05,0,r,i)}}else{let t=0,i=0;for(let a=0;a<r;a++){let r=e.values[a][n];r!==r||r===0||(r>0?(l(n-.4,n+.4,t,t+r,a),t+=r):(l(n-.4,n+.4,i,i+r,a),i+=r))}}else{let i=e.n/n,a=new Float64Array(r),o=new Float64Array(r);for(let s=0;s<n;s++){let n=Math.floor(s*i),c=Math.min(e.n,Math.floor((s+1)*i));if(!(c<=n)){a.fill(0),o.fill(0);for(let i=n;i<c;i++){let n=0,s=0;for(let c=0;c<r;c++){let r=e.values[c][i];r===r&&(t===`stacked`?r>0?(n+=r,n>o[c]&&(o[c]=n)):(s+=r,s<a[c]&&(a[c]=s)):(r>o[c]&&(o[c]=r),r<a[c]&&(a[c]=r)))}}for(let e=t===`stacked`?r-1:0;t===`stacked`?e>=0:e<r;t===`stacked`?e--:e++)(o[e]!==0||a[e]!==0)&&l(n-.5,c-.5,a[e],o[e],e)}}}return{x0:Float64Array.from(i),x1:Float64Array.from(a),y0:Float64Array.from(o),y1:Float64Array.from(s),k:Float64Array.from(c)}}function l3({groups:e,columns:t,seriesNames:n,colors:r,mode:i=`grouped`,horizontal:a=!1,valueRange:o,backgroundToken:s=``,onPlotContextMenu:c}){let l=iQ(),u=(0,Z.useRef)(null),d=(0,Z.useRef)(null),f=(0,Z.useRef)(null),p=(0,Z.useRef)(null),m=(0,Z.useRef)(null),h=(0,Z.useRef)(null),g=(0,Z.useRef)(0),_=(0,Z.useRef)(c);(0,Z.useLayoutEffect)(()=>{_.current=c},[c]);let v=(0,Z.useRef)(null),y=(0,Z.useMemo)(()=>{let r=[e,i,n.length,t?.length,...t?.values??[]],a=v.current;if(a&&a.key.length===r.length&&a.key.every((e,t)=>e===r[t]))return a.value;let o=s3(e,t,n.length,i);return v.current={key:r,value:o},o},[e,t,n.length,i]),b=(0,Z.useRef)({bars:y,seriesNames:n,colors:r,mode:i,horizontal:a,valueRange:o});(0,Z.useLayoutEffect)(()=>{b.current={bars:y,seriesNames:n,colors:r,mode:i,horizontal:a,valueRange:o}},[y,n,r,i,a,o]);let x=(0,Z.useRef)({plot:null,failed:!1,key:``,data:null,size:``});(0,Z.useEffect)(()=>()=>{x.current.plot?.dispose(),x.current.plot=null},[]);let S=(0,Z.useRef)({bars:null,view:``});function C(){if(m.current)return m.current;let e=p.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return m.current=n,n}function w(){let e=p.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||300)}}function T(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function E(e){let t=b.current.colors??[];return Array.from({length:e},(e,n)=>t[n]??a3[n%a3.length])}function D(e,t){let{bars:n,valueRange:r}=b.current,i=n.lo,a=n.hi;r?.min!==void 0&&Number.isFinite(r.min)&&(i=r.min),r?.max!==void 0&&Number.isFinite(r.max)&&(a=r.max);let o=$$(i3,e,t),{top:s,right:c,bottom:l,left:u}=o;return{lo:i,hi:a,top:s,left:u,plotW:e-u-c,plotH:t-s-l,tiny:o.tiny}}function O(e,t){let n=x.current;if(!n.plot&&!n.failed&&d.current&&(n.plot=NX(d.current,B0),n.failed=!n.plot),!n.plot||!d.current)return null;let r=Math.min(2,window.devicePixelRatio||1),i=`${e}x${t}@${r}`;return n.size!==i&&(n.plot.resize(e,t,r),d.current.style.width=`${e}px`,d.current.style.height=`${t}px`,n.size=i),n.plot}function k(){let e=u.current;if(!e)return;let{w:t,h:n}=w(),r=T(e,t,n);if(!r)return;let{bg:i,muted:a,grid:o}=C(),{bars:s,seriesNames:c,mode:d,horizontal:f}=b.current;r.fillStyle=i,r.fillRect(0,0,t,n);let m=O(t,n);if(s.n===0||c.length===0){m?.keep([]),m?.render(),r.fillStyle=a,r.font=`13px ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,eX(r);return}let{lo:h,hi:g,top:_,left:v,plotW:y,plotH:k,tiny:A}=D(t,n),j=E(c.length),M=f?k:y,N=e=>f?v+(e-h)/(g-h)*y:_+k-(e-h)/(g-h)*k,P=e=>(f?_:v)+(e+.5)/s.n*M;l({left:v,top:_,width:y,height:k,...f?{x:{v0:h,v1:g}}:{y:{v0:h,v1:g}}}),r.strokeStyle=o,r.lineWidth=1;for(let e=0;e<=5;e++){let t=h+e/5*(g-h),n=N(t);r.beginPath(),f?(r.moveTo(n,_),r.lineTo(n,_+k)):(r.moveTo(v,n),r.lineTo(v+y,n)),r.stroke(),r.fillStyle=a,r.font=`9px ${X.mono}`,!A&&(f?(r.textAlign=`center`,r.textBaseline=`top`,r.fillText(zJ(t,(g-h)/5),n,_+k+4)):(r.textAlign=`right`,r.textBaseline=`middle`,r.fillText(zJ(t,(g-h)/5),v-4,n)))}let F=`${h}|${g}|${f}`;(S.current.bars!==s||S.current.view!==F)&&(S.current={bars:s,view:F},lZ(p.current));let I=Math.min(2,window.devicePixelRatio||1),L=Math.max(1,Math.round(M*I)),R=j.map(e=>{let t=hX(e);return[t[0],t[1],t[2],o3]}),z={left:v,top:_,width:y,height:k};if(m){let e=`${d}|${f}|${L}|${j.join(`,`)}`;if(x.current.key!==e||x.current.data!==s){let t=c3(s,d,L);f?m.setRects(`bars`,t.y0,t.y1,t.x0,t.x1,R,t.k):m.setRects(`bars`,t.x0,t.x1,t.y0,t.y1,R,t.k),m.keep([`bars`]),x.current.key=e,x.current.data=s}f?m.setView(h,g,s.n-.5,-.5,z):m.setView(-.5,s.n-.5,h,g,z),m.render()}else{let e=c3(s,d,L);r.globalAlpha=o3;for(let t=0;t<e.x0.length;t++){r.fillStyle=j[e.k[t]];let n=P(e.x0[t]-.5),i=P(e.x1[t]-.5),a=N(e.y0[t]),o=N(e.y1[t]);f?r.fillRect(Math.min(a,o),n,Math.max(1,Math.abs(o-a)),Math.max(1,i-n)):r.fillRect(n,Math.min(a,o),Math.max(1,i-n),Math.max(1,Math.abs(o-a)))}r.globalAlpha=1}if(h<0&&g>0){let e=N(0);r.strokeStyle=a,r.lineWidth=1.5,r.beginPath(),f?(r.moveTo(e,_),r.lineTo(e,_+k)):(r.moveTo(v,e),r.lineTo(v+y,e)),r.stroke()}r.fillStyle=a,r.font=`9px ${X.mono}`;let B=Math.max(1,Math.ceil(s.n/Math.max(1,Math.floor(M/(f?14:48)))));for(let e=0;e<(A?0:s.n);e+=B){let t=P(e),n=s.label(e),i=n.length>14?n.slice(0,13)+`…`:n;f?(r.textAlign=`right`,r.textBaseline=`middle`,r.fillText(i,v-4,t)):(r.textAlign=`center`,r.textBaseline=`top`,r.fillText(i,t,_+k+4))}if(c.length>1&&!A){let e=f?_-14:_+k+32,t=v;r.font=`9px ${X.mono}`,r.textBaseline=`top`;for(let n=0;n<c.length&&(r.fillStyle=j[n],r.fillRect(t,e,10,8),r.fillStyle=a,r.textAlign=`left`,r.fillText(c[n],t+13,e),t+=r.measureText(c[n]).width+26,!(t>v+y-30));n++);}}function A(){let e=f.current;if(!e)return;let{w:t,h:n}=w(),r=T(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=h.current,{bars:a,seriesNames:o,horizontal:s}=b.current;if(i===null||i>=a.n)return;let{top:c,left:l,plotW:u,plotH:d}=D(t,n),p=s?d:u,m=(s?c:l)+(i+.5)/a.n*p,g=Math.max(1,p/a.n);r.fillStyle=`rgba(255,255,255,0.08)`,s?r.fillRect(l,m-g/2,u,g):r.fillRect(m-g/2,c,g,d);let _=a.values.map((e,t)=>`${o.length>1?o[t]+` `:``}${BJ(e[i])}`).join(` `),v=`${a.label(i)}: ${_}`;r.font=`11px ${X.mono}`;let y=r.measureText(v).width,x=s?l+u/2:m,S=s?m:c+d/2,C=Math.max(4,Math.min(t-y-8,x-y/2)),E=S-28<c?S+10:S-24;r.fillStyle=`rgba(0,0,0,0.8)`,r.fillRect(C-3,E-3,y+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(v,C,E)}let j=(0,Z.useRef)(k);j.current=k;let M=(0,Z.useRef)(null);M.current??=mZ(()=>j.current(),()=>p.current);let N=()=>{g.current||=oZ(()=>{g.current=0,A()})};return(0,Z.useEffect)(()=>{M.current.now()},[y,n,r,i,a,o]),(0,Z.useEffect)(()=>()=>{M.current?.cancel(),sZ(g.current)},[]),(0,Z.useEffect)(()=>{m.current=null,M.current.schedule()},[s]),(0,Z.useLayoutEffect)(()=>{let e=p.current;if(!e)return;let t=new fZ(()=>{m.current=null,M.current.schedule(),N()});return t.observe(e),()=>t.disconnect()},[]),(0,Z.useLayoutEffect)(()=>{let e=f.current;if(!e)return;let t=e=>{e.preventDefault(),_.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),{bars:r,horizontal:i}=b.current,{w:a,h:o}=w(),{top:s,left:c,plotW:l,plotH:u}=D(a,o),d=i?t.clientY-n.top-s:t.clientX-n.left-c,f=i?u:l,p=d>=0&&d<f&&r.n>0?Math.min(r.n-1,Math.floor(d/f*r.n)):null;p!==h.current&&(h.current=p,N())},r=()=>{h.current=null,N()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),(0,Q.jsxs)(`div`,{ref:p,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:u,className:`chart-canvas`,role:`img`,"aria-label":`Bar chart`}),(0,Q.jsx)(`canvas`,{ref:d,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),(0,Q.jsx)(`canvas`,{ref:f,className:`chart-canvas chart-overlay`})]})}var u3=[`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`];function d3(e,t){if(!t)return u3[e%u3.length];if(e===0)return t;let n=u3.filter(e=>e.toLowerCase()!==t.toLowerCase());return n[(e-1)%n.length]}var f3={top:36,right:36,bottom:36,left:36};function p3({axes:e,series:t,fill:n=!0,color:r,backgroundToken:i=``,onPlotContextMenu:a}){let o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(null),u=(0,Z.useRef)(a);(0,Z.useLayoutEffect)(()=>{u.current=a},[a]);let d=(0,Z.useRef)({axes:e,series:t,fill:n,color:r});(0,Z.useLayoutEffect)(()=>{d.current={axes:e,series:t,fill:n,color:r}},[e,t,n,r]);function f(){if(l.current)return l.current;let e=c.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return l.current=n,n}function p(){let e=c.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||300)}}function m(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function h(){let e=o.current;if(!e)return;let{w:t,h:n}=p(),r=m(e,t,n);if(!r)return;let{bg:i,muted:a,grid:s}=f(),{axes:c,series:l,fill:u}=d.current;if(r.fillStyle=i,r.fillRect(0,0,t,n),c.length<3||l.length===0){r.fillStyle=a,r.font=`13px ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(`Select ≥ 3 axes`,f3.left+8,f3.top+8);return}let h=c.length,g=t/2,_=n/2,v=Math.min(t-f3.left-f3.right,n-f3.top-f3.bottom)/2,y=c.map((e,t)=>{let n=0;for(let e of l){let r=e.values[t]??0;r>n&&(n=r)}return n||1});function b(e){return Math.PI*2*e/h-Math.PI/2}function x(e,t){let n=b(e);return{x:g+Math.cos(n)*v*t,y:_+Math.sin(n)*v*t}}for(let e=1;e<=4;e++){let t=e/4;r.beginPath();for(let e=0;e<h;e++){let n=x(e,t);e===0?r.moveTo(n.x,n.y):r.lineTo(n.x,n.y)}r.closePath(),r.strokeStyle=s,r.lineWidth=1,r.stroke()}r.strokeStyle=a,r.lineWidth=1;for(let e=0;e<h;e++){let t=x(e,1);r.beginPath(),r.moveTo(g,_),r.lineTo(t.x,t.y),r.stroke(),r.fillStyle=a,r.font=`10px ${X.mono}`;let n=b(e),i=x(e,1+10/v);r.textAlign=Math.abs(Math.cos(n))<.1?`center`:Math.cos(n)<0?`right`:`left`,r.textBaseline=Math.abs(Math.sin(n))<.1?`middle`:Math.sin(n)<0?`bottom`:`top`;let o=c[e].length>12?c[e].slice(0,11)+`…`:c[e];r.fillText(o,i.x,i.y)}for(let e=0;e<l.length;e++){let t=l[e],n=d3(e,d.current.color);r.beginPath();for(let e=0;e<h;e++){let n=Math.max(0,Math.min(1,(t.values[e]??0)/y[e])),i=x(e,n);e===0?r.moveTo(i.x,i.y):r.lineTo(i.x,i.y)}r.closePath(),u&&(r.fillStyle=n,r.globalAlpha=.15,r.fill()),r.globalAlpha=1,r.strokeStyle=n,r.lineWidth=1,r.stroke();for(let e=0;e<h;e++){let i=Math.max(0,Math.min(1,(t.values[e]??0)/y[e])),a=x(e,i);r.beginPath(),r.arc(a.x,a.y,3,0,Math.PI*2),r.fillStyle=n,r.globalAlpha=.9,r.fill()}r.globalAlpha=1}if(l.length>1){let e=f3.left,i=n-f3.bottom-10;r.font=`9px ${X.mono}`,r.textBaseline=`top`;for(let n=0;n<l.length&&(r.fillStyle=d3(n,d.current.color),r.fillRect(e,i,10,8),r.fillStyle=a,r.textAlign=`left`,r.fillText(l[n].name,e+13,i),e+=r.measureText(l[n].name).width+26,!(e>t-f3.right-30));n++);}}let g=(0,Z.useRef)(h);g.current=h;let _=(0,Z.useRef)(null);_.current??=mZ(()=>g.current(),()=>c.current);let v=()=>_.current.schedule();return(0,Z.useEffect)(()=>{_.current.now()}),(0,Z.useEffect)(()=>()=>_.current?.cancel(),[]),(0,Z.useEffect)(()=>{l.current=null,v()},[i]),(0,Z.useLayoutEffect)(()=>{let e=c.current;if(!e)return;let t=new fZ(()=>{l.current=null,v()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{let e=s.current;if(!e)return;let t=e=>{e.preventDefault(),u.current?.({clientX:e.clientX,clientY:e.clientY})};return e.addEventListener(`contextmenu`,t),()=>{e.removeEventListener(`contextmenu`,t)}},[]),(0,Q.jsxs)(`div`,{ref:c,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`Radar chart`}),(0,Q.jsx)(`canvas`,{ref:s,className:`chart-canvas chart-overlay`})]})}var m3={top:16,right:16,bottom:40,left:52},h3=[`#38bdf8`,`#4ade80`,`#fb7185`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`];function g3(e,t){let n=e.length>0&&e.every(t=>t.x===e[0].x||t.x.length===e[0].x.length),r=t&&n,i=e.map(e=>e.x),a=[],o=[],s=null;for(let t of e){if(!r){a.push(t.y),o.push(null);continue}let e=t.x.length,n=new Float64Array(e);for(let r=0;r<e;r++){let e=t.y[r];n[r]=(s?s[r]:0)+(e>0?e:0)}a.push(n),o.push(s??null),s=n}let c=1/0,l=-1/0,u=0,d=0;for(let e of i)for(let t=0;t<e.length;t++){let n=e[t];n<c&&(c=n),n>l&&(l=n)}for(let e of a)for(let t=0;t<e.length;t++){let n=e[t];n<u&&(u=n),n>d&&(d=n)}return Number.isFinite(c)||(c=0,l=1),{x:i,lo:o,hi:a,ascending:i.map(e=>Y0(e)),xLo:c,xHi:l,yLo:u,yHi:d}}function _3({series:e,stacked:t=!1,yRange:n,backgroundToken:r=``,onPlotContextMenu:i}){let a=iQ(),o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(null),u=(0,Z.useRef)(null),d=(0,Z.useRef)(null),f=(0,Z.useRef)(0),p=(0,Z.useRef)(i);(0,Z.useLayoutEffect)(()=>{p.current=i},[i]);let m=(0,Z.useRef)(null),h=(0,Z.useMemo)(()=>{let n=m.current;if(n&&n.stacked===t&&n.series.length===e.length&&n.series.every((t,n)=>t.x===e[n].x&&t.y===e[n].y&&t.name===e[n].name))return n.value;let r=g3(e,t);return m.current={series:e,stacked:t,value:r},r},[e,t]),g=(0,Z.useRef)({series:e,prepared:h,yRange:n});(0,Z.useLayoutEffect)(()=>{g.current={series:e,prepared:h,yRange:n}},[e,h,n]);let _=(0,Z.useRef)({plot:null,failed:!1,key:``,size:``});(0,Z.useEffect)(()=>()=>{_.current.plot?.dispose(),_.current.plot=null},[]);let v=(0,Z.useRef)({prepared:null,view:``});function y(){if(u.current)return u.current;let e=l.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return u.current=n,n}function b(){let e=l.current;return{w:Math.max(1,e?.clientWidth||600),h:Math.max(1,e?.clientHeight||300)}}function x(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function S(e,t){let n=(e.xHi-e.xLo)*.01||.5,r=e.yLo,i=e.yHi;return i===r&&(i=r+1),i+=(i-r)*.05,t?.min!==void 0&&Number.isFinite(t.min)&&(r=t.min),t?.max!==void 0&&Number.isFinite(t.max)&&(i=t.max),{xLo:e.xLo-n,xHi:e.xHi+n,yLo:r,yHi:i}}function C(e,t,n,r,i){let a=e.x[t],o=e.hi[t],s=e.lo[t];if(!e.ascending[t]||a.length<=2*i)return{x:a,hi:o,lo:s??new Float64Array(a.length)};let c=K0(a,o,n,r,i);return{x:J0(a,c),hi:J0(o,c),lo:s?J0(s,c):new Float64Array(c.length)}}function w(){let e=o.current;if(!e)return;let{w:n,h:r}=b(),i=x(e,n,r);if(!i)return;let{bg:s,muted:c,grid:u}=y(),{series:d,prepared:f,yRange:p}=g.current;i.fillStyle=s,i.fillRect(0,0,n,r);let m=_.current.plot;if(d.length===0){m?.keep([]),m?.render(),i.fillStyle=c,i.font=`13px ${X.sans}`,i.textAlign=`left`,i.textBaseline=`top`,eX(i);return}let h=$$(m3,n,r),{top:w,right:D,bottom:O,left:k}=h,A=n-k-D,j=r-w-O,{xLo:M,xHi:N,yLo:P,yHi:F}=S(f,p),I=e=>k+(e-M)/(N-M)*A,L=e=>w+j-(e-P)/(F-P)*j;a({left:k,top:w,width:A,height:j,x:{v0:M,v1:N},y:{v0:P,v1:F}}),i.strokeStyle=u,i.lineWidth=1;for(let e=0;e<=5;e++){let t=P+e/5*(F-P),n=L(t);i.beginPath(),i.moveTo(k,n),i.lineTo(k+A,n),i.stroke(),i.fillStyle=c,i.font=`9px ${X.mono}`,i.textAlign=`right`,i.textBaseline=`middle`,h.tiny||i.fillText(zJ(t,(F-P)/5),k-4,n)}let R=Math.min(8,f.x[0]?.length??5);for(let e=0;e<=R;e++){let t=M+e/R*(N-M),n=I(t);i.beginPath(),i.moveTo(n,w),i.lineTo(n,w+j),i.stroke(),i.fillStyle=c,i.font=`9px ${X.mono}`,i.textAlign=`center`,i.textBaseline=`top`,h.tiny||i.fillText(zJ(t,(N-M)/R),n,w+j+4)}let z=`${M}|${N}|${P}|${F}`;(v.current.prepared!==f||v.current.view!==z)&&(v.current={prepared:f,view:z},lZ(l.current));let B=E(n,r),V=Math.min(2,window.devicePixelRatio||1),ee=Math.max(1,Math.round(A*V)),H=d.map((e,t)=>hX(h3[t%h3.length]));if(B){let e=`${M}|${N}|${ee}`;if(_.current.key!==e||T.current!==f){let n=[];for(let e=0;e<d.length;e++){let r=C(f,e,M,N,ee),i=H[e],a=[i[0],i[1],i[2],f.lo[e]||t?.7:.25];B.setBands(`b${e}`,r.x,r.lo,r.hi,a),B.setLine(`l${e}`,r.x,r.hi,i,1),n.push(`b${e}`,`l${e}`)}B.keep(n),_.current.key=e,T.current=f}B.setView(M,N,P,F,{left:k,top:w,width:A,height:j}),B.render()}else for(let e=0;e<d.length;e++){let n=C(f,e,M,N,ee),r=h3[e%h3.length];i.save(),i.beginPath(),i.rect(k,w,A,j),i.clip(),i.beginPath();for(let e=0;e<n.x.length;e++){let t=I(n.x[e]);e===0?i.moveTo(t,L(n.lo[e])):i.lineTo(t,L(n.lo[e]))}for(let e=n.x.length-1;e>=0;e--)i.lineTo(I(n.x[e]),L(n.hi[e]));i.closePath(),i.fillStyle=r,i.globalAlpha=f.lo[e]||t?.7:.25,i.fill(),i.beginPath();for(let e=0;e<n.x.length;e++){let t=I(n.x[e]),r=L(n.hi[e]);e===0?i.moveTo(t,r):i.lineTo(t,r)}i.globalAlpha=1,i.strokeStyle=r,i.lineWidth=1,i.stroke(),i.restore()}if(d.length>1&&!h.tiny){let e=k,t=w+j+24;i.font=`9px ${X.mono}`,i.textBaseline=`top`;for(let n=0;n<d.length&&(i.fillStyle=h3[n%h3.length],i.fillRect(e,t,10,8),i.fillStyle=c,i.textAlign=`left`,i.fillText(d[n].name,e+13,t),e+=i.measureText(d[n].name).width+26,!(e>k+A-30));n++);}}let T=(0,Z.useRef)(null);function E(e,t){let n=_.current;if(!n.plot&&!n.failed&&s.current&&(n.plot=NX(s.current,B0),n.failed=!n.plot),!n.plot||!s.current)return null;let r=Math.min(2,window.devicePixelRatio||1),i=`${e}x${t}@${r}`;return n.size!==i&&(n.plot.resize(e,t,r),s.current.style.width=`${e}px`,s.current.style.height=`${t}px`,n.size=i),n.plot}function D(){let e=c.current;if(!e)return;let{w:t,h:n}=b(),r=x(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=d.current;if(i===null)return;let{prepared:a,yRange:o}=g.current,{top:s,right:l,left:u,bottom:f}=$$(m3,t,n),p=n-s-f;r.strokeStyle=`rgba(255,255,255,0.4)`,r.lineWidth=1,r.setLineDash([4,4]),r.beginPath(),r.moveTo(i,s),r.lineTo(i,s+p),r.stroke(),r.setLineDash([]);let{xLo:m,xHi:h}=S(a,o),_=t-u-l,v=`x=${BJ(m+(i-u)/_*(h-m))}`;r.font=`11px ${X.mono}`;let y=r.measureText(v).width,C=Math.max(4,Math.min(t-y-8,i-y/2));r.fillStyle=`rgba(0,0,0,0.7)`,r.fillRect(C-3,s-3,y+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(v,C,s)}let O=(0,Z.useRef)(w);O.current=w;let k=(0,Z.useRef)(null);k.current??=mZ(()=>O.current(),()=>l.current);let A=()=>{f.current||=oZ(()=>{f.current=0,D()})};return(0,Z.useEffect)(()=>{k.current.now()},[e,h,n]),(0,Z.useEffect)(()=>()=>{k.current?.cancel(),sZ(f.current)},[]),(0,Z.useEffect)(()=>{u.current=null,k.current.schedule()},[r]),(0,Z.useLayoutEffect)(()=>{let e=l.current;if(!e)return;let t=new fZ(()=>{u.current=null,k.current.schedule(),A()});return t.observe(e),()=>t.disconnect()},[]),(0,Z.useLayoutEffect)(()=>{let e=c.current;if(!e)return;let t=e=>{e.preventDefault(),p.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect();d.current=t.clientX-n.left,A()},r=()=>{d.current=null,A()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),(0,Q.jsxs)(`div`,{ref:l,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`Area chart`}),(0,Q.jsx)(`canvas`,{ref:s,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),(0,Q.jsx)(`canvas`,{ref:c,className:`chart-canvas chart-overlay`})]})}var v3={top:16,right:16,bottom:40,left:52},y3=[`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`];function b3({series:e,complement:t=!1,logX:n=!1,backgroundToken:r=``,onPlotContextMenu:i}){let a=iQ(),o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(null),u=(0,Z.useRef)(null),d=(0,Z.useRef)(0),f=(0,Z.useRef)(i);(0,Z.useLayoutEffect)(()=>{f.current=i},[i]);let p=(0,Z.useRef)({series:e,complement:t,logX:n});(0,Z.useLayoutEffect)(()=>{p.current={series:e,complement:t,logX:n}},[e,t,n]);let m=(0,Z.useMemo)(()=>{let t=e.map(e=>Float64Array.from(e.values).sort()),n=1/0,r=-1/0;for(let e of t)e.length&&(n=Math.min(n,e[0]),r=Math.max(r,e[e.length-1]));return{all:t,xLo:n,xHi:r}},[e]),h=(0,Z.useRef)(m);(0,Z.useLayoutEffect)(()=>{h.current=m},[m]);function g(){if(l.current)return l.current;let e=c.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return l.current=n,n}function _(){let e=c.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||300)}}function v(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function y(){let e=o.current;if(!e)return;let{w:t,h:n}=_(),r=v(e,t,n);if(!r)return;let{bg:i,muted:s,grid:c}=g(),{series:l,complement:u,logX:d}=p.current;if(r.fillStyle=i,r.fillRect(0,0,t,n),l.length===0){r.fillStyle=s,r.font=`13px ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,eX(r);return}let{top:f,right:m,bottom:y,left:b}=v3,x=t-b-m,S=n-f-y,{xLo:C,xHi:w}=h.current;Number.isFinite(C)||(C=0,w=1);let T=e=>Math.log10(Math.max(1e-10,e)),E=d?T(C):C,D=d?T(w):w,O=e=>b+((d?T(e):e)-E)/(D-E||1)*x,k=e=>f+S-e*S;a({left:b,top:f,width:x,height:S,x:{v0:C,v1:w,log:d}});for(let e=0;e<=5;e++){let t=e/5,n=k(t);r.strokeStyle=c,r.lineWidth=1,r.beginPath(),r.moveTo(b,n),r.lineTo(b+x,n),r.stroke(),r.fillStyle=s,r.font=`9px ${X.mono}`,r.textAlign=`right`,r.textBaseline=`middle`,r.fillText(String(t.toFixed(2)),b-4,n)}for(let e=0;e<=6;e++){let t=C+e/6*(w-C),n=O(t);r.strokeStyle=c,r.lineWidth=1,r.beginPath(),r.moveTo(n,f),r.lineTo(n,f+S),r.stroke(),r.fillStyle=s,r.font=`9px ${X.mono}`,r.textAlign=`center`,r.textBaseline=`top`,r.fillText(zJ(t,(w-C)/6),n,f+S+4)}for(let e=0;e<l.length;e++){let t=h.current.all[e],n=t?.length??0;if(n===0)continue;let i=e=>k(u?1-(e+1)/n:(e+1)/n),a=O(t[0]),o=k(+!!u);r.beginPath(),r.moveTo(a,o);for(let e=0;e<n;e++){if(e+1<n&&t[e+1]===t[e])continue;let s=O(t[e]),c=i(e);if(Math.abs(s-a)<.5){o=c;continue}r.lineTo(a,o),r.lineTo(s,o),a=s,o=c}r.lineTo(a,o),r.strokeStyle=y3[e%y3.length],r.lineWidth=1,r.stroke()}if(l.length>1){let e=b,t=f+S+24;r.font=`9px ${X.mono}`,r.textBaseline=`top`;for(let n=0;n<l.length&&(r.fillStyle=y3[n%y3.length],r.fillRect(e,t,16,2),r.fillStyle=s,r.textAlign=`left`,r.fillText(l[n].name,e+20,t-3),e+=r.measureText(l[n].name).width+30,!(e>b+x-30));n++);}r.save(),r.translate(12,f+S/2),r.rotate(-Math.PI/2),r.fillStyle=s,r.font=`9px ${X.mono}`,r.textAlign=`center`,r.textBaseline=`middle`,r.fillText(u?`CCDF`:`CDF`,0,0),r.restore()}function b(){let e=s.current;if(!e)return;let{w:t,h:n}=_(),r=v(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=u.current;if(i===null)return;let{top:a,left:o,right:c}=v3,l=n-a-v3.bottom,d=t-o-c;r.strokeStyle=`rgba(255,255,255,0.4)`,r.lineWidth=1,r.setLineDash([4,4]),r.beginPath(),r.moveTo(i,a),r.lineTo(i,a+l),r.stroke(),r.setLineDash([]);let{xLo:f,xHi:p}=h.current;if(!Number.isFinite(f))return;let m=BJ(f+(i-o)/d*(p-f));r.font=`11px ${X.mono}`;let g=r.measureText(m).width,y=Math.max(4,Math.min(t-g-8,i-g/2));r.fillStyle=`rgba(0,0,0,0.7)`,r.fillRect(y-3,a+l+2,g+6,16),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(m,y,a+l+4)}let x=(0,Z.useRef)(y);x.current=y;let S=(0,Z.useRef)(null);S.current??=mZ(()=>x.current(),()=>c.current);let C=()=>S.current.schedule(),w=()=>{sZ(d.current),d.current=oZ(b)};return(0,Z.useEffect)(()=>{S.current.now()}),(0,Z.useEffect)(()=>()=>S.current?.cancel(),[]),(0,Z.useEffect)(()=>{l.current=null,C()},[r]),(0,Z.useLayoutEffect)(()=>{let e=c.current;if(!e)return;let t=new fZ(()=>{l.current=null,C(),w()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{let e=s.current;if(!e)return;let t=e=>{e.preventDefault(),f.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect();u.current=t.clientX-n.left,w()},r=()=>{u.current=null,w()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),(0,Q.jsxs)(`div`,{ref:c,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:o,className:`chart-canvas`,role:`img`,"aria-label":`CDF chart`}),(0,Q.jsx)(`canvas`,{ref:s,className:`chart-canvas chart-overlay`})]})}var x3={top:16,right:40,bottom:40,left:52},S3=[`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`,`#facc15`,`#60a5fa`];function C3(e){return[Math.round(255*Math.min(1,Math.max(0,3.5*e-.5))),Math.round(255*Math.min(1,Math.max(0,e<.5?2*e:2-2*e))),Math.round(255*Math.min(1,Math.max(0,1.5-3.5*e)))]}function w3(e){let[t,n,r]=C3(e);return`rgb(${t},${n},${r})`}var T3=(()=>{let e=new Uint8Array(1024);for(let t=0;t<256;t++)e.set([...C3(t/255),255],t*4);return e})(),E3=()=>{let e=new Uint8Array(1024);for(let t=0;t<256;t++){let[n,r,i]=e0(S3[t%S3.length],1);e.set([n*255,r*255,i*255,255],t*4)}return e};function D3(e,t,n){let r=e.length,i=1/0,a=-1/0,o=1/0,s=-1/0,c=1/0,l=-1/0;for(let t=0;t<r;t++){let n=e.x[t],r=e.y[t],u=e.size[t];n<i&&(i=n),n>a&&(a=n),r<o&&(o=r),r>s&&(s=r),u<c&&(c=u),u>l&&(l=u)}let u=Number.isFinite(i)?(()=>{let e=(a-i)*.1||1,t=(s-o)*.1||1;return{xLo:i-e,xHi:a+e,yLo:o-t,yHi:s+t,sLo:c,sHi:l}})():{xLo:-1,xHi:1,yLo:-1,yHi:1,sLo:1,sHi:1},d=u.sHi-u.sLo||1,f=new Float32Array(r);for(let t=0;t<r;t++)f[t]=3+(e.size[t]-u.sLo)/d*(n-3);let p=0,m=1,h=null,g=`single`;if(t&&e.colorValue){let t=e.colorValue,n=1/0,i=-1/0;for(let e=0;e<r;e++)t[e]<n&&(n=t[e]),t[e]>i&&(i=t[e]);Number.isFinite(n)&&(p=n,m=i),h=new Float32Array(r);for(let e=0;e<r;e++)h[e]=t[e]===t[e]?Math.max(0,Math.min(1,(t[e]-p)/(m-p||1))):0;g=`colormap`}else !t&&e.colorIndex&&(h=Float32Array.from(e.colorIndex,e=>e>=0?e%256:0),g=`dataset`);let _=Uint32Array.from({length:r},(e,t)=>t).sort((e,t)=>(f[t]||0)-(f[e]||0)),v=e=>{let t=new Float64Array(r);for(let n=0;n<r;n++)t[n]=e[_[n]];return t};return{ext:u,radius:f,key:h,mode:g,colorLo:p,colorHi:m,drawn:{x:v(e.x),y:v(e.y),r:v(f),k:h?v(h):void 0}}}function O3({points:e,color:t=`#64748b`,colorByNumeric:n=!1,maxRadius:r=24,backgroundToken:i=``,onPlotContextMenu:a}){let o=iQ(),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(null),u=(0,Z.useRef)(null),d=(0,Z.useRef)(null),f=(0,Z.useRef)(null),p=(0,Z.useRef)(0),m=(0,Z.useRef)(a);(0,Z.useLayoutEffect)(()=>{m.current=a},[a]);let h=(0,Z.useMemo)(()=>D3(e,n,r),[e,n,r]),g=(0,Z.useRef)({points:e,color:t,colorByNumeric:n,maxRadius:r,model:h});(0,Z.useLayoutEffect)(()=>{g.current={points:e,color:t,colorByNumeric:n,maxRadius:r,model:h}},[e,t,n,r,h]);let _=(0,Z.useRef)({r:null,failed:!1,size:``,model:null,style:``});(0,Z.useEffect)(()=>()=>{_.current.r?.dispose(),_.current.r=null},[]);function v(){if(d.current)return d.current;let e=u.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return d.current=n,n}function y(){let e=u.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||300)}}function b(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function x(e,t){let{xLo:n,xHi:r,yLo:i,yHi:a}=g.current.model.ext,{top:s,right:c,bottom:l,left:u}=x3,d=e-u-c,f=t-s-l;return o({left:u,top:s,width:d,height:f,x:{v0:n,v1:r},y:{v0:i,v1:a}}),{plotW:d,plotH:f,xToPx:e=>u+(e-n)/(r-n)*d,yToPx:e=>s+(1-(e-i)/(a-i))*f}}function S(e,t){let n=_.current;!n.r&&!n.failed&&c.current&&(n.r=NX(c.current,Z$),n.failed=!n.r);let r=n.r;if(!r||!c.current)return null;let i=Math.min(2,window.devicePixelRatio||1),a=`${e}x${t}@${i}`;n.size!==a&&(r.resize(e,t,i),c.current.style.width=`${e}px`,c.current.style.height=`${t}px`,n.size=a);let{model:o,color:s}=g.current;n.model!==o&&(r.setData(o.drawn.x,o.drawn.y,o.drawn.k,!1,o.drawn.r),n.model=o,lZ(u.current));let l=`${o.mode}|${s}`;return n.style!==l&&(r.setStyle(o.mode===`single`?{kind:`single`,rgba:e0(s,1)}:{kind:o.mode,palette:o.mode===`colormap`?T3:E3()},3,.65),r.setDraw(!0,!1,0),n.style=l),r}function C(){let e=s.current;if(!e)return;let{w:t,h:n}=y(),r=b(e,t,n);if(!r)return;let{bg:i,muted:a,grid:o}=v(),{points:c,color:l,colorByNumeric:u,model:d}=g.current;r.fillStyle=i,r.fillRect(0,0,t,n);let f=S(t,n);if(c.length===0){f?.setData([],[]),_.current.model=null,f?.render(),r.fillStyle=a,r.font=`13px ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,eX(r);return}let{xLo:p,xHi:m,yLo:h,yHi:C}=d.ext,{top:w,left:T}=x3,{plotW:E,plotH:D,xToPx:O,yToPx:k}=x(t,n);r.strokeStyle=o,r.lineWidth=1;for(let e=0;e<=5;e++){let t=p+e/5*(m-p),n=O(t);r.beginPath(),r.moveTo(n,w),r.lineTo(n,w+D),r.stroke(),r.fillStyle=a,r.font=`9px ${X.mono}`,r.textAlign=`center`,r.textBaseline=`top`,r.fillText(zJ(t,(m-p)/5),n,w+D+4);let i=h+e/5*(C-h),o=k(i);r.beginPath(),r.moveTo(T,o),r.lineTo(T+E,o),r.stroke(),r.fillStyle=a,r.textAlign=`right`,r.textBaseline=`middle`,r.fillText(zJ(i,(C-h)/5),T-4,o)}if(f)f.setView(p,m,h,C,{left:T,top:w,width:E,height:D}),f.render();else{let e=d.drawn;r.globalAlpha=.65;for(let t=0;t<e.x.length;t++){if(e.x[t]!==e.x[t]||e.y[t]!==e.y[t])continue;let n=e.k?.[t]??0;r.fillStyle=d.mode===`colormap`?w3(n):d.mode===`dataset`?S3[n%S3.length]:l,r.beginPath(),r.arc(O(e.x[t]),k(e.y[t]),e.r[t],0,Math.PI*2),r.fill()}r.globalAlpha=1}let A=c.colorLabels??[];if(!u&&A.length>0&&A.length<=10){let e=T,t=n-x3.bottom-10;r.font=`9px ${X.mono}`,r.textBaseline=`top`;for(let n=0;n<A.length;n++){let i=A[n];if(r.fillStyle=S3[n%S3.length],r.beginPath(),r.arc(e+4,t+4,4,0,Math.PI*2),r.fill(),r.fillStyle=a,r.textAlign=`left`,r.fillText(i,e+10,t),e+=r.measureText(i).width+20,e>T+E-60)break}}}function w(){let e=l.current;if(!e)return;let{w:t,h:n}=y(),r=b(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=f.current;if(i===null)return;let{points:a,model:o}=g.current;if(i<0||i>=a.length)return;let{xToPx:s,yToPx:c}=x(t,n),u=o.radius[i],d=s(a.x[i]),p=c(a.y[i]);r.beginPath(),r.arc(d,p,u+2,0,Math.PI*2),r.strokeStyle=`rgba(255,255,255,0.9)`,r.lineWidth=2,r.stroke();let m=[],h=a.label?.(i);h&&m.push(h),m.push(`(${BJ(a.x[i])}, ${BJ(a.y[i])})`),m.push(`size=${BJ(a.size[i])}`);let _=a.colorIndex?.[i];_!==void 0&&_>=0&&a.colorLabels?m.push(a.colorLabels[_]):a.colorValue&&m.push(BJ(a.colorValue[i]));let v=m.join(` · `);r.font=`11px ${X.mono}`;let S=r.measureText(v).width,C=Math.max(4,Math.min(t-S-8,d+u+4)),w=p-20<x3.top?p+u+4:p-20;r.fillStyle=`rgba(0,0,0,0.8)`,r.fillRect(C-3,w-3,S+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(v,C,w)}let T=(0,Z.useRef)(C);T.current=C;let E=(0,Z.useRef)(null);E.current??=mZ(()=>T.current(),()=>u.current);let D=()=>E.current.schedule(),O=()=>{sZ(p.current),p.current=oZ(w)};return(0,Z.useEffect)(()=>{E.current.now()}),(0,Z.useEffect)(()=>()=>E.current?.cancel(),[]),(0,Z.useEffect)(()=>{d.current=null,D()},[i]),(0,Z.useLayoutEffect)(()=>{let e=u.current;if(!e)return;let t=new fZ(()=>{d.current=null,D(),O()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{let e=l.current;if(!e)return;let t=null,n=e=>{e.preventDefault(),m.current?.({clientX:e.clientX,clientY:e.clientY})},r=n=>{let r=e.getBoundingClientRect(),{points:i,maxRadius:a,model:o}=g.current,{w:s,h:c}=y(),{plotW:l,plotH:u,xToPx:d,yToPx:p}=x(s,c),m=e=>d(i.x[e])-x3.left,h=e=>p(i.y[e])-x3.top,_=a+6,v=`${s}|${c}|${_}`;(!t||t.model!==o||t.key!==v)&&(t={model:o,key:v,g:B4(i.length,l,u,_,m,h)}),f.current=V4(t.g,n.clientX-r.left-x3.left,n.clientY-r.top-x3.top,_,m,h,e=>o.radius[e]+6),O()},i=()=>{f.current=null,O()};return e.addEventListener(`contextmenu`,n),e.addEventListener(`mousemove`,r),e.addEventListener(`mouseleave`,i),()=>{e.removeEventListener(`contextmenu`,n),e.removeEventListener(`mousemove`,r),e.removeEventListener(`mouseleave`,i)}},[]),(0,Q.jsxs)(`div`,{ref:u,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:s,className:`chart-canvas`,role:`img`,"aria-label":`Bubble chart`}),(0,Q.jsx)(`canvas`,{ref:c,className:`chart-canvas chart-overlay`,style:{pointerEvents:`none`}}),(0,Q.jsx)(`canvas`,{ref:l,className:`chart-canvas chart-overlay`})]})}var k3={top:8,right:8,bottom:8,left:8},A3=[`#f97316`,`#38bdf8`,`#4ade80`,`#a78bfa`,`#fbbf24`,`#fb7185`,`#34d399`,`#e879f9`,`#facc15`,`#60a5fa`];function j3(e){let t=new Map;for(let n of e){let e=n.parent??``;t.has(e)||t.set(e,[]),t.get(e).push(n)}function n(r,i){let a=(t.get(r)??[]).map(e=>n(e.name,i+1)),o=e.find(e=>e.name===r),s=a.reduce((e,t)=>e+t.value,0);return{name:r,value:o?Math.max(o.value,s):s,children:a,depth:i}}let r=new Set(e.map(e=>e.name));return e.filter(e=>!e.parent||!r.has(e.parent)).map(e=>n(e.name,0))}function M3(e,t,n,r,i,a){if(e.length===0||r<=0||i<=0||e.reduce((e,t)=>e+t.value,0)===0)return[];let o=[],s=[...e].sort((e,t)=>t.value-e.value),c=t,l=n,u=r,d=i;for(;s.length>0;){let e=u*d,t=s.reduce((e,t)=>e+t.value,0),n=e/t,r=[],i=1/0;for(let e=1;e<=s.length;e++){let a=s.slice(0,e),o=a.reduce((e,t)=>e+t.value,0)/t*(u<=d?u:d),c=0;for(let e of a){let t=e.value*n/o,r=Math.max(t/o,o/t);r>c&&(c=r)}if(c<i)i=c,r=a;else break}let f=r.reduce((e,t)=>e+t.value,0),p=u<=d,m=f/t*(p?u:d),h=0;for(let e of r){let t=e.value/f,n=p?u:t*u,r=p?t*d:d,i=p?c:c+h,s=p?l+h:l,g=p?m:n,_=p?r:m;if(o.push({node:e,x:i,y:s,w:g,h:_,depth:a}),e.children.length>0&&g>4&&_>4){let t=M3(e.children,i+1,s+1,g-2,_-2,a+1);for(let e of t)o.push(e)}h+=p?r:n}s=s.slice(r.length),p?(c+=m,u-=m):(l+=m,d-=m)}return o}function N3({nodes:e,backgroundToken:t=``,onPlotContextMenu:n}){let r=(0,Z.useRef)(null),i=(0,Z.useRef)(null),a=(0,Z.useRef)(null),o=(0,Z.useRef)(null),s=(0,Z.useRef)([]),c=(0,Z.useRef)(null),l=(0,Z.useRef)(0),u=(0,Z.useRef)(n);(0,Z.useLayoutEffect)(()=>{u.current=n},[n]);let d=(0,Z.useRef)({nodes:e});(0,Z.useLayoutEffect)(()=>{d.current={nodes:e}},[e]);let f=(0,Z.useMemo)(()=>j3(e),[e]),p=(0,Z.useRef)(f);(0,Z.useLayoutEffect)(()=>{p.current=f},[f]);function m(){if(o.current)return o.current;let e=a.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return o.current=n,n}function h(){let e=a.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||300)}}function g(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function _(){let e=r.current;if(!e)return;let{w:t,h:n}=h(),i=g(e,t,n);if(!i)return;let{bg:a,muted:o}=m(),{nodes:l}=d.current;if(i.fillStyle=a,i.fillRect(0,0,t,n),l.length===0){i.fillStyle=o,i.font=`13px ${X.sans}`,i.textAlign=`left`,i.textBaseline=`top`,eX(i);return}let u=p.current,f=t-k3.left-k3.right,_=n-k3.top-k3.bottom,v=M3(u,k3.left,k3.top,f,_,0);s.current=v;for(let e=0;e<v.length;e++){let{node:t,x:n,y:r,w:o,h:s,depth:l}=v[e];if(o<2||s<2)continue;let u=A3[l%A3.length],d=c.current===e;if(i.fillStyle=u,i.globalAlpha=d?.95:.75,i.fillRect(n,r,o,s),i.globalAlpha=1,i.strokeStyle=a,i.lineWidth=1,i.strokeRect(n,r,o,s),o>20&&s>14){i.fillStyle=`rgba(0,0,0,0.75)`,i.font=`${Math.min(11,s-4)}px ${X.mono}`,i.textAlign=`left`,i.textBaseline=`top`;let e=Math.floor((o-4)/6),a=t.name.length>e?t.name.slice(0,e-1)+`…`:t.name;i.fillText(a,n+3,r+3)}}i.globalAlpha=1}function v(){let e=i.current;if(!e)return;let{w:t,h:n}=h(),r=g(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let a=c.current;if(a===null)return;let o=s.current;if(a<0||a>=o.length)return;let{node:l,x:u,y:d,w:f,h:p}=o[a];r.strokeStyle=`rgba(255,255,255,0.9)`,r.lineWidth=2,r.strokeRect(u+1,d+1,f-2,p-2);let m=`${l.name}: ${l.value.toLocaleString()}`;r.font=`11px ${X.mono}`;let _=r.measureText(m).width,v=Math.max(4,Math.min(t-_-8,u+f/2-_/2)),y=d<30?d+p+4:d-20;r.fillStyle=`rgba(0,0,0,0.8)`,r.fillRect(v-3,y-3,_+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(m,v,y)}let y=(0,Z.useRef)(_);y.current=_;let b=(0,Z.useRef)(null);b.current??=mZ(()=>y.current(),()=>a.current);let x=()=>b.current.schedule(),S=()=>{sZ(l.current),l.current=oZ(v)};return(0,Z.useEffect)(()=>{b.current.now()}),(0,Z.useEffect)(()=>()=>b.current?.cancel(),[]),(0,Z.useEffect)(()=>{o.current=null,x()},[t]),(0,Z.useLayoutEffect)(()=>{let e=a.current;if(!e)return;let t=new fZ(()=>{o.current=null,x(),S()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{let e=i.current;if(!e)return;let t=e=>{e.preventDefault(),u.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),r=t.clientX-n.left,i=t.clientY-n.top,a=s.current,o=null;for(let e=0;e<a.length;e++){let t=a[e];r>=t.x&&r<=t.x+t.w&&i>=t.y&&i<=t.y+t.h&&(o=e)}c.current=o,S()},r=()=>{c.current=null,S()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),(0,Q.jsxs)(`div`,{ref:a,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:r,className:`chart-canvas`,role:`img`,"aria-label":`Treemap`}),(0,Q.jsx)(`canvas`,{ref:i,className:`chart-canvas chart-overlay`})]})}var P3={top:8,right:8,bottom:8,left:8},F3=14,I3=8,L3=[`#38bdf8`,`#4ade80`,`#fb7185`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`,`#facc15`,`#60a5fa`];function R3(e,t,n,r){if(e.length===0||t.length===0)return{nodes:[],links:[]};let i=n-P3.left-P3.right,a=r-P3.top-P3.bottom,o=new Map;for(let t of e)o.set(t,0);let s=!0;for(;s;){s=!1;for(let e of t){let t=o.get(e.source)??0;(o.get(e.target)??0)<=t&&(o.set(e.target,t+1),s=!0)}}let c=Math.max(0,...Array.from(o.values())),l=e=>P3.left+e/Math.max(1,c)*(i-F3),u=new Map;for(let[e,t]of o)u.has(t)||u.set(t,[]),u.get(t).push(e);let d=new Map;for(let t of e)d.set(t,0);for(let e of t)d.set(e.source,(d.get(e.source)??0)+e.value),d.set(e.target,(d.get(e.target)??0)+e.value);let f=Math.max(1,...Array.from(d.values())),p=new Map;for(let[t,n]of u){let r=a-(n.length-1)*I3,i=0;for(let e of n)i+=Math.max(8,(d.get(e)??0)/f*r*.8);let o=P3.top+(a-i-(n.length-1)*I3)/2;for(let i=0;i<n.length;i++){let a=n[i],s=Math.max(8,(d.get(a)??0)/f*r*.8);p.set(a,{name:a,x:l(t),y:o,h:s,color:L3[e.indexOf(a)%L3.length]}),o+=s+I3}}let m=new Map,h=new Map;for(let[e,t]of p)m.set(e,t.y),h.set(e,t.y);let g=[];for(let e of t){let t=p.get(e.source),n=p.get(e.target);if(!t||!n)continue;let r=Math.max(1,e.value/f*t.h),i=m.get(e.source)??t.y,a=h.get(e.target)??n.y;m.set(e.source,i+r),h.set(e.target,a+r),g.push({sx:t.x+F3,sy:i+r/2,tx:n.x,ty:a+r/2,h:r,color:t.color,label:`${e.source} → ${e.target}: ${e.value.toLocaleString()}`})}return{nodes:Array.from(p.values()),links:g}}function z3({nodeNames:e,links:t,backgroundToken:n=``,onPlotContextMenu:r}){let i=(0,Z.useRef)(null),a=(0,Z.useRef)(null),o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),c=(0,Z.useRef)({nodes:[],links:[]}),l=(0,Z.useRef)(null),u=(0,Z.useRef)(0),d=(0,Z.useRef)(r);(0,Z.useLayoutEffect)(()=>{d.current=r},[r]);let f=(0,Z.useRef)({nodeNames:e,links:t});(0,Z.useLayoutEffect)(()=>{f.current={nodeNames:e,links:t}},[e,t]);function p(){if(s.current)return s.current;let e=o.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return s.current=n,n}function m(){let e=o.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||300)}}function h(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function g(){let e=i.current;if(!e)return;let{w:t,h:n}=m(),r=h(e,t,n);if(!r)return;let{bg:a,muted:o}=p(),{nodeNames:s,links:u}=f.current;if(r.fillStyle=a,r.fillRect(0,0,t,n),s.length===0||u.length===0){r.fillStyle=o,r.font=`13px ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,eX(r);return}let d=R3(s,u,t,n);c.current=d;for(let e=0;e<d.links.length;e++){let t=d.links[e],n=l.current===e,i=(t.tx-t.sx)/2;r.beginPath(),r.moveTo(t.sx,t.sy-t.h/2),r.bezierCurveTo(t.sx+i,t.sy-t.h/2,t.tx-i,t.ty-t.h/2,t.tx,t.ty-t.h/2),r.lineTo(t.tx,t.ty+t.h/2),r.bezierCurveTo(t.tx-i,t.ty+t.h/2,t.sx+i,t.sy+t.h/2,t.sx,t.sy+t.h/2),r.closePath(),r.fillStyle=t.color,r.globalAlpha=n?.55:.3,r.fill()}r.globalAlpha=1;for(let e of d.nodes)r.fillStyle=e.color,r.globalAlpha=.9,r.fillRect(e.x,e.y,F3,e.h),r.globalAlpha=1,r.fillStyle=o,r.font=`9px ${X.mono}`,r.textBaseline=`middle`,e.x>t/2?(r.textAlign=`right`,r.fillText(e.name,e.x-3,e.y+e.h/2)):(r.textAlign=`left`,r.fillText(e.name,e.x+F3+3,e.y+e.h/2));r.globalAlpha=1}function _(){let e=a.current;if(!e)return;let{w:t,h:n}=m(),r=h(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=l.current;if(i===null)return;let o=c.current;if(i<0||i>=o.links.length)return;let s=o.links[i],u=s.label;r.font=`11px ${X.mono}`;let d=r.measureText(u).width,f=Math.max(4,Math.min(t-d-8,(s.sx+s.tx)/2-d/2)),p=Math.max(4,(s.sy+s.ty)/2-10);r.fillStyle=`rgba(0,0,0,0.8)`,r.fillRect(f-3,p-3,d+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(u,f,p)}let v=(0,Z.useRef)(g);v.current=g;let y=(0,Z.useRef)(null);y.current??=mZ(()=>v.current(),()=>o.current);let b=()=>y.current.schedule(),x=()=>{sZ(u.current),u.current=oZ(_)};return(0,Z.useEffect)(()=>{y.current.now()}),(0,Z.useEffect)(()=>()=>y.current?.cancel(),[]),(0,Z.useEffect)(()=>{s.current=null,b()},[n]),(0,Z.useLayoutEffect)(()=>{let e=o.current;if(!e)return;let t=new fZ(()=>{s.current=null,b(),x()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{let e=a.current;if(!e)return;let t=e=>{e.preventDefault(),d.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),r=t.clientX-n.left,i=t.clientY-n.top,a=c.current,o=null;for(let e=0;e<a.links.length;e++){let t=a.links[e];if(r>=t.sx&&r<=t.tx&&Math.abs(i-(t.sy+t.ty)/2)<t.h/2+6){o=e;break}}l.current=o,x()},r=()=>{l.current=null,x()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),(0,Q.jsxs)(`div`,{ref:o,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:i,className:`chart-canvas`,role:`img`,"aria-label":`Sankey diagram`}),(0,Q.jsx)(`canvas`,{ref:a,className:`chart-canvas chart-overlay`})]})}var B3={top:24,right:24,bottom:52,left:52};function V3({bins:e,color:t=`#38bdf8`,backgroundToken:n=``,onPlotContextMenu:r}){let i=(0,Z.useRef)(null),a=(0,Z.useRef)(null),o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(0),u=(0,Z.useRef)(r);(0,Z.useLayoutEffect)(()=>{u.current=r},[r]);let d=(0,Z.useRef)({bins:e,color:t});(0,Z.useLayoutEffect)(()=>{d.current={bins:e,color:t}},[e,t]);function f(){if(s.current)return s.current;let e=o.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return s.current=n,n}function p(){let e=o.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||300)}}function m(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function h(){let e=i.current;if(!e)return;let{w:t,h:n}=p(),r=m(e,t,n);if(!r)return;let{bg:a,muted:o,grid:s}=f(),{bins:l,color:u}=d.current;if(r.fillStyle=a,r.fillRect(0,0,t,n),l.length===0){r.fillStyle=o,r.font=`13px ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,eX(r);return}let{top:h,right:g,bottom:_,left:v}=B3,y=t-v-g,b=n-h-_,x=e=>v+e*y,S=e=>h+(1-e)*b;for(let e=0;e<=5;e++){let t=e/5;r.strokeStyle=s,r.lineWidth=1,r.beginPath(),r.moveTo(v,S(t)),r.lineTo(v+y,S(t)),r.stroke(),r.beginPath(),r.moveTo(x(t),h),r.lineTo(x(t),h+b),r.stroke(),r.fillStyle=o,r.font=`9px ${X.mono}`,r.textAlign=`right`,r.textBaseline=`middle`,r.fillText(t.toFixed(2),v-4,S(t)),r.textAlign=`center`,r.textBaseline=`top`,r.fillText(t.toFixed(2),x(t),h+b+4)}r.strokeStyle=o,r.lineWidth=1.5,r.setLineDash([6,4]),r.beginPath(),r.moveTo(x(0),S(0)),r.lineTo(x(1),S(1)),r.stroke(),r.setLineDash([]);let C=Math.max(1,...l.map(e=>e.count)),w=b*.15;for(let e of l){let t=Math.max(1,y/l.length*.7),n=x(e.center)-t/2,i=e.count/C*w;r.fillStyle=u,r.globalAlpha=.3,r.fillRect(n,h+b-i,t,i)}r.globalAlpha=1,r.beginPath();for(let e=0;e<l.length;e++){let t=x(l[e].center),n=S(l[e].actual);e===0?r.moveTo(t,n):r.lineTo(t,n)}r.strokeStyle=u,r.lineWidth=1,r.stroke();for(let e=0;e<l.length;e++){let t=c.current===e;r.beginPath(),r.arc(x(l[e].center),S(l[e].actual),t?6:4,0,Math.PI*2),r.fillStyle=u,r.globalAlpha=t?1:.85,r.fill()}r.globalAlpha=1,r.fillStyle=o,r.font=`10px ${X.mono}`,r.textAlign=`center`,r.textBaseline=`bottom`,r.fillText(`Predicted probability`,v+y/2,n-4),r.save(),r.translate(12,h+b/2),r.rotate(-Math.PI/2),r.textAlign=`center`,r.textBaseline=`middle`,r.fillText(`Actual rate`,0,0),r.restore()}function g(){let e=a.current;if(!e)return;let{w:t,h:n}=p(),r=m(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=c.current;if(i===null)return;let{bins:o}=d.current;if(i<0||i>=o.length)return;let s=o[i],{top:l,left:u}=B3,f=t-u-B3.right,h=n-l-B3.bottom,g=u+s.center*f,_=l+(1-s.actual)*h,v=`pred=${s.center.toFixed(2)} actual=${s.actual.toFixed(3)} n=${s.count}`;r.font=`11px ${X.mono}`;let y=r.measureText(v).width,b=Math.max(4,Math.min(t-y-8,g-y/2)),x=_-28<l?_+12:_-24;r.fillStyle=`rgba(0,0,0,0.8)`,r.fillRect(b-3,x-3,y+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(v,b,x)}let _=(0,Z.useRef)(h);_.current=h;let v=(0,Z.useRef)(null);v.current??=mZ(()=>_.current(),()=>o.current);let y=()=>v.current.schedule(),b=()=>{sZ(l.current),l.current=oZ(g)};return(0,Z.useEffect)(()=>{v.current.now()}),(0,Z.useEffect)(()=>()=>v.current?.cancel(),[]),(0,Z.useEffect)(()=>{s.current=null,y()},[n]),(0,Z.useLayoutEffect)(()=>{let e=o.current;if(!e)return;let t=new fZ(()=>{s.current=null,y(),b()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{let e=a.current;if(!e)return;let t=e=>{e.preventDefault(),u.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),{bins:r}=d.current,{w:i}=p(),a=t.clientX-n.left,o=i-B3.left-B3.right,s=-1,l=20;for(let e=0;e<r.length;e++){let t=B3.left+r[e].center*o,n=Math.abs(a-t);n<l&&(l=n,s=e)}c.current=s>=0?s:null,b()},r=()=>{c.current=null,b()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),(0,Q.jsxs)(`div`,{ref:o,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:i,className:`chart-canvas`,role:`img`,"aria-label":`Calibration curve`}),(0,Q.jsx)(`canvas`,{ref:a,className:`chart-canvas chart-overlay`})]})}var H3={top:24,right:24,bottom:48,left:52};function U3({points:e,color:t=`#a78bfa`,backgroundToken:n=``,onPlotContextMenu:r}){let i=iQ(),a=(0,Z.useRef)(null),o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(null),u=(0,Z.useRef)(0),d=(0,Z.useRef)(r);(0,Z.useLayoutEffect)(()=>{d.current=r},[r]);let f=(0,Z.useRef)({points:e,color:t});(0,Z.useLayoutEffect)(()=>{f.current={points:e,color:t}},[e,t]);function p(){if(c.current)return c.current;let e=s.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return c.current=n,n}function m(){let e=s.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||300)}}function h(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function g(){let{points:e}=f.current,t=1/0,n=-1/0,r=1/0,i=-1/0;if(e.length>0&&(t=e.theoretical[0],n=e.theoretical[e.length-1],r=e.sample[0],i=e.sample[e.length-1]),!Number.isFinite(t))return{xLo:-3,xHi:3,yLo:-3,yHi:3};let a=(n-t)*.05||.5,o=(i-r)*.05||.5;return{xLo:t-a,xHi:n+a,yLo:r-o,yHi:i+o}}function _(){let e=a.current;if(!e)return;let{w:t,h:n}=m(),r=h(e,t,n);if(!r)return;let{bg:o,muted:s,grid:c}=p(),{points:u,color:d}=f.current;if(r.fillStyle=o,r.fillRect(0,0,t,n),u.length===0){r.fillStyle=s,r.font=`13px ${X.sans}`,r.textAlign=`left`,r.textBaseline=`top`,eX(r);return}let{xLo:_,xHi:v,yLo:y,yHi:b}=g(),{top:x,right:S,bottom:C,left:w}=H3,T=t-w-S,E=n-x-C,D=e=>w+(e-_)/(v-_)*T,O=e=>x+(1-(e-y)/(b-y))*E;i({left:w,top:x,width:T,height:E,x:{v0:_,v1:v}}),r.strokeStyle=c,r.lineWidth=1;for(let e=0;e<=5;e++){let t=_+e/5*(v-_),n=D(t);r.beginPath(),r.moveTo(n,x),r.lineTo(n,x+E),r.stroke(),r.fillStyle=s,r.font=`9px ${X.mono}`,r.textAlign=`center`,r.textBaseline=`top`,r.fillText(zJ(t,(v-_)/5),n,x+E+4);let i=y+e/5*(b-y),a=O(i);r.beginPath(),r.moveTo(w,a),r.lineTo(w+T,a),r.stroke(),r.fillStyle=s,r.textAlign=`right`,r.textBaseline=`middle`,r.fillText(zJ(i,(b-y)/5),w-4,a)}let k=Math.max(_,y),A=Math.min(v,b);k<A&&(r.strokeStyle=s,r.lineWidth=1.5,r.setLineDash([6,4]),r.beginPath(),r.moveTo(D(k),O(k)),r.lineTo(D(A),O(A)),r.stroke(),r.setLineDash([])),r.fillStyle=d,r.globalAlpha=.75;let j=NaN,M=NaN;for(let e=0;e<u.length;e++){let t=Math.round(D(u.theoretical[e])),n=Math.round(O(u.sample[e]));t===j&&n===M||(j=t,M=n,r.beginPath(),r.arc(t,n,3,0,Math.PI*2),r.fill())}let N=l.current;N!==null&&N<u.length&&(r.globalAlpha=1,r.beginPath(),r.arc(D(u.theoretical[N]),O(u.sample[N]),5,0,Math.PI*2),r.fill()),r.globalAlpha=1,r.fillStyle=s,r.font=`10px ${X.mono}`,r.textAlign=`center`,r.textBaseline=`bottom`,r.fillText(`Theoretical quantiles`,w+T/2,n-4),r.save(),r.translate(12,x+E/2),r.rotate(-Math.PI/2),r.textAlign=`center`,r.textBaseline=`middle`,r.fillText(`Sample quantiles`,0,0),r.restore()}function v(){let e=o.current;if(!e)return;let{w:t,h:n}=m(),r=h(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=l.current;if(i===null)return;let{points:a}=f.current;if(i<0||i>=a.length)return;let s={theoretical:a.theoretical[i],sample:a.sample[i]},{xLo:c,xHi:u,yLo:d,yHi:p}=g(),{top:_,left:v}=H3,y=t-v-H3.right,b=n-_-H3.bottom,x=v+(s.theoretical-c)/(u-c)*y,S=_+(1-(s.sample-d)/(p-d))*b;r.beginPath(),r.arc(x,S,6,0,Math.PI*2),r.strokeStyle=`rgba(255,255,255,0.9)`,r.lineWidth=2,r.stroke();let C=`(${BJ(s.theoretical)}, ${BJ(s.sample)})`;r.font=`11px ${X.mono}`;let w=r.measureText(C).width,T=Math.max(4,Math.min(t-w-8,x+10)),E=S-20<_?S+10:S-20;r.fillStyle=`rgba(0,0,0,0.8)`,r.fillRect(T-3,E-3,w+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(C,T,E)}let y=(0,Z.useRef)(_);y.current=_;let b=(0,Z.useRef)(null);b.current??=mZ(()=>y.current(),()=>s.current);let x=()=>b.current.schedule(),S=()=>{sZ(u.current),u.current=oZ(v)};return(0,Z.useEffect)(()=>{b.current.now()}),(0,Z.useEffect)(()=>()=>b.current?.cancel(),[]),(0,Z.useEffect)(()=>{c.current=null,x()},[n]),(0,Z.useLayoutEffect)(()=>{let e=s.current;if(!e)return;let t=new fZ(()=>{c.current=null,x(),S()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{let e=o.current;if(!e)return;let t=e=>{e.preventDefault(),d.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),{points:r}=f.current,{w:i}=m(),{xLo:a,xHi:o,yLo:s,yHi:c}=g(),{top:u,left:d}=H3,p=i-d-H3.right,h=n.height-u-H3.bottom,_=t.clientX-n.left,v=t.clientY-n.top,y=e=>a+(e-d)/p*(o-a),b=e=>{let t=0,n=r.length;for(;t<n;){let i=t+n>>>1;r.theoretical[i]<e?t=i+1:n=i}return t},x=b(y(_-10)),C=Math.min(r.length,b(y(_+10))+1),w=-1,T=10**2;for(let e=x;e<C;e++){let t=d+(r.theoretical[e]-a)/(o-a)*p,n=u+(1-(r.sample[e]-s)/(c-s))*h,i=(_-t)**2+(v-n)**2;i<T&&(T=i,w=e)}l.current=w>=0?w:null,S()},r=()=>{l.current=null,S()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),(0,Q.jsxs)(`div`,{ref:s,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:a,className:`chart-canvas`,role:`img`,"aria-label":`Q-Q plot`}),(0,Q.jsx)(`canvas`,{ref:o,className:`chart-canvas chart-overlay`})]})}var W3={top:8,right:16,bottom:40,left:120},G3=22,K3=3,q3=[`#38bdf8`,`#4ade80`,`#fb7185`,`#fbbf24`,`#a78bfa`,`#f97316`,`#34d399`,`#e879f9`,`#facc15`,`#60a5fa`];function J3({tasks:e,backgroundToken:t=``,onPlotContextMenu:n}){let r=iQ(),i=(0,Z.useRef)(null),a=(0,Z.useRef)(null),o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(0),u=(0,Z.useRef)(n);(0,Z.useLayoutEffect)(()=>{u.current=n},[n]);let d=(0,Z.useRef)({tasks:e});(0,Z.useLayoutEffect)(()=>{d.current={tasks:e}},[e]);function f(){if(s.current)return s.current;let e=o.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`};return s.current=n,n}function p(){let e=o.current;return{w:Math.max(1,e?.clientWidth||200),h:Math.max(1,e?.clientHeight||300)}}function m(e,t,n){let r=Math.min(2,window.devicePixelRatio||1),i=Math.floor(t*r),a=Math.floor(n*r);(e.width!==i||e.height!==a)&&(e.width=i,e.height=a),e.style.width=`${t}px`,e.style.height=`${n}px`;let o=e.getContext(`2d`);return o&&o.setTransform(r,0,0,r,0,0),o}function h(){let e=i.current;if(!e)return;let{w:t,h:n}=p(),a=m(e,t,n);if(!a)return;let{bg:o,muted:s,grid:l}=f(),{tasks:u}=d.current;if(a.fillStyle=o,a.fillRect(0,0,t,n),u.length===0){a.fillStyle=s,a.font=`13px ${X.sans}`,a.textAlign=`left`,a.textBaseline=`top`,eX(a);return}let h=1/0,g=-1/0;for(let e of u)e.start<h&&(h=e.start),e.end>g&&(g=e.end);Number.isFinite(h)||(h=0,g=1);let _=(g-h)*.02||1;h-=_,g+=_;let{top:v,right:y,bottom:b,left:x}=W3,S=t-x-y,C=e=>x+(e-h)/(g-h)*S;r({left:x,top:v,width:S,height:n-v-b,x:{v0:h,v1:g}});let w=new Map;for(let e of u){let t=e.group??e.label;w.has(t)||w.set(t,w.size)}let T=Math.min(8,Math.floor(S/60));a.strokeStyle=l,a.lineWidth=1;for(let e=0;e<=T;e++){let t=h+e/T*(g-h),n=C(t),r=u.length*(G3+K3)+v;a.beginPath(),a.moveTo(n,v),a.lineTo(n,r),a.stroke(),a.fillStyle=s,a.font=`9px ${X.mono}`,a.textAlign=`center`,a.textBaseline=`top`,a.fillText(zJ(t,(g-h)/T),n,r+4)}for(let e=0;e<u.length;e++){let t=u[e],n=v+e*(G3+K3),r=q3[(w.get(t.group??t.label)??0)%q3.length],i=c.current===e,o=C(t.start),l=C(t.end),d=Math.max(2,l-o);a.fillStyle=r,a.globalAlpha=i?.95:.75,a.fillRect(o,n,d,G3-K3),a.globalAlpha=1,a.fillStyle=s,a.font=`9px ${X.mono}`,a.textAlign=`right`,a.textBaseline=`middle`;let f=t.label.length>16?t.label.slice(0,15)+`…`:t.label;a.fillText(f,x-4,n+(G3-K3)/2)}a.globalAlpha=1}function g(){let e=a.current;if(!e)return;let{w:t,h:n}=p(),r=m(e,t,n);if(!r)return;r.clearRect(0,0,t,n);let i=c.current;if(i===null)return;let{tasks:o}=d.current;if(i<0||i>=o.length)return;let s=o[i],l=s.end-s.start,u=`${s.label}: ${BJ(s.start)} → ${BJ(s.end)} (${BJ(l)})`;r.font=`11px ${X.mono}`;let f=r.measureText(u).width,h=1/0,g=-1/0;for(let e of o)e.start<h&&(h=e.start),e.end>g&&(g=e.end);let _=(g-h)*.02||1;h-=_,g+=_;let v=t-W3.left-W3.right,y=e=>W3.left+(e-h)/(g-h)*v,b=W3.top+i*(G3+K3),x=(y(s.start)+y(s.end))/2,S=Math.max(4,Math.min(t-f-8,x-f/2)),C=b-22<W3.top?b+G3+4:b-20;r.fillStyle=`rgba(0,0,0,0.8)`,r.fillRect(S-3,C-3,f+6,18),r.fillStyle=`#fff`,r.textAlign=`left`,r.textBaseline=`top`,r.fillText(u,S,C)}let _=(0,Z.useRef)(h);_.current=h;let v=(0,Z.useRef)(null);v.current??=mZ(()=>_.current(),()=>o.current);let y=()=>v.current.schedule(),b=()=>{sZ(l.current),l.current=oZ(g)};return(0,Z.useEffect)(()=>{v.current.now()}),(0,Z.useEffect)(()=>()=>v.current?.cancel(),[]),(0,Z.useEffect)(()=>{s.current=null,y()},[t]),(0,Z.useLayoutEffect)(()=>{let e=o.current;if(!e)return;let t=new fZ(()=>{s.current=null,y(),b()});return t.observe(e),()=>t.disconnect()}),(0,Z.useLayoutEffect)(()=>{let e=a.current;if(!e)return;let t=e=>{e.preventDefault(),u.current?.({clientX:e.clientX,clientY:e.clientY})},n=t=>{let n=e.getBoundingClientRect(),{tasks:r}=d.current,i=t.clientY-n.top,a=Math.floor((i-W3.top)/(G3+K3));c.current=a>=0&&a<r.length?a:null,b()},r=()=>{c.current=null,b()};return e.addEventListener(`contextmenu`,t),e.addEventListener(`mousemove`,n),e.addEventListener(`mouseleave`,r),()=>{e.removeEventListener(`contextmenu`,t),e.removeEventListener(`mousemove`,n),e.removeEventListener(`mouseleave`,r)}},[]),(0,Q.jsxs)(`div`,{ref:o,style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,Q.jsx)(`canvas`,{ref:i,className:`chart-canvas`,role:`img`,"aria-label":`Gantt chart`}),(0,Q.jsx)(`canvas`,{ref:a,className:`chart-canvas chart-overlay`})]})}var Y3=e=>[...e].filter(e=>Number.isFinite(e.at)).sort((e,t)=>e.at-t.at),X3=e=>{let t=/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})/i.exec(e);return t?[parseInt(t[1],16),parseInt(t[2],16),parseInt(t[3],16)]:[128,128,128]},Z3=e=>`#${e.map(e=>Math.round(e).toString(16).padStart(2,`0`)).join(``)}`;function Q3(e,t,n,r){let i=t?Y3(t):[];if(!e||e===`solid`||i.length===0||!Number.isFinite(r))return n;if(e===`zones`){let e=i[0].color;for(let t of i)r>=t.at&&(e=t.color);return e}if(r<=i[0].at)return i[0].color;if(r>=i[i.length-1].at)return i[i.length-1].color;let a=0;for(;i[a+1].at<r;)a++;let o=i[a],s=i[a+1],c=(r-o.at)/(s.at-o.at||1),l=X3(o.color),u=X3(s.color);return Z3([l[0]+(u[0]-l[0])*c,l[1]+(u[1]-l[1])*c,l[2]+(u[2]-l[2])*c])}function $3(e,t,n,r,i,a=96){let o=i-r||1,s=t?Y3(t):[];if(!e||e===`solid`||s.length===0)return[{f0:0,f1:1,color:n}];if(e===`zones`){let e=[0,...s.slice(1).map(e=>(e.at-r)/o).filter(e=>e>0&&e<1),1];return e.slice(0,-1).map((t,i)=>({f0:t,f1:e[i+1],color:Q3(`zones`,s,n,r+(t+e[i+1])/2*o)}))}return Array.from({length:a},(e,t)=>({f0:t/a,f1:(t+1)/a,color:Q3(`gradient`,s,n,r+(t+.5)/a*o)}))}var e6=.75*Math.PI,t6=1.5*Math.PI;function n6({gauges:e,live:t,backgroundToken:n=``,onPlotContextMenu:r}){let i=(0,Z.useRef)(null),a=(0,Z.useRef)(null),o=(0,Z.useRef)(null),s=(0,Z.useRef)(r);(0,Z.useLayoutEffect)(()=>{s.current=r},[r]);let c=(0,Z.useRef)({gauges:e,live:t});(0,Z.useLayoutEffect)(()=>{c.current={gauges:e,live:t}},[e,t]);let l=(0,Z.useRef)(MZ()),u=(0,Z.useRef)(0);function d(){if(o.current)return o.current;let e=a.current;if(!e)return{bg:`#0f1014`,muted:`#71717a`,grid:`#27272a`,ink:`#e4e4e7`};let t=getComputedStyle(e),n={bg:t.getPropertyValue(`--chart-bg`).trim()||`#0f1014`,muted:t.getPropertyValue(`--chart-muted`).trim()||`#71717a`,grid:t.getPropertyValue(`--chart-grid`).trim()||`#27272a`,ink:t.getPropertyValue(`--chart-fg`).trim()||`#e4e4e7`};return o.current=n,n}function f(){let e=i.current,t=a.current;if(!e||!t)return;let n=Math.max(1,t.clientWidth),r=Math.max(1,t.clientHeight),o=Math.min(2,window.devicePixelRatio||1),s=Math.floor(n*o),f=Math.floor(r*o);(e.width!==s||e.height!==f)&&(e.width=s,e.height=f),e.style.width=`${n}px`,e.style.height=`${r}px`;let p=e.getContext(`2d`);if(!p)return;p.setTransform(o,0,0,o,0,0);let h=d(),{gauges:g,live:_}=c.current,v=g;if(_){let e=performance.now(),t=JZ(l.current,_.latestT(),e-u.current,_.timeAfter);u.current=e,v=g.map(e=>{if((e.stat??`last`)!==`last`)return e;let n=_.valueAt(e.name,t);return Number.isFinite(n)?{...e,value:n}:e}),m.current.schedule()}if(p.fillStyle=h.bg,p.fillRect(0,0,n,r),v.length===0){p.fillStyle=h.muted,p.font=`13px ${X.sans}`,p.textAlign=`left`,p.textBaseline=`top`,eX(p);return}let{cols:y,rows:b}=r6(v.length,n,r,v.some(e=>e.style===`arc`)?1.15:3.2),x=n/y,S=r/b;v.forEach((e,t)=>{let n=t%y*x,r=Math.floor(t/y)*S;e.style===`arc`?p6(p,e,n,r,x,S,e.color,e.alarm??null,h):m6(p,e,n,r,x,S,e.color,e.alarm??null,h)})}let p=(0,Z.useRef)(f);p.current=f;let m=(0,Z.useRef)(null);return m.current??=mZ(()=>p.current(),()=>a.current),(0,Z.useEffect)(()=>{m.current.now()}),(0,Z.useEffect)(()=>()=>m.current?.cancel(),[]),(0,Z.useEffect)(()=>{o.current=null,m.current.schedule()},[n]),(0,Z.useLayoutEffect)(()=>{let e=a.current;if(!e)return;let t=new fZ(()=>{o.current=null,m.current.schedule()});return t.observe(e),()=>t.disconnect()},[]),(0,Q.jsx)(`div`,{ref:a,style:{position:`relative`,width:`100%`,height:`100%`},children:(0,Q.jsx)(`canvas`,{ref:i,className:`chart-canvas`,role:`img`,"aria-label":`Gauges: ${e.map(e=>`${e.name} ${Number.isFinite(e.value)?i6(e.value,e.max-e.min):`no value`}${e.unit?` ${e.unit}`:``}`).join(`, `)}`,onContextMenu:e=>{e.preventDefault(),s.current?.({clientX:e.clientX,clientY:e.clientY})}})})}function r6(e,t,n,r){let i={cols:1,rows:e,size:-1};for(let a=1;a<=e;a++){let o=Math.ceil(e/a),s=t/a,c=n/o,l=Math.min(s,c*r);l>i.size&&(i={cols:a,rows:o,size:l})}return{cols:i.cols,rows:i.rows}}var i6=(e,t)=>zJ(e,MJ(Math.abs(t),100)),a6=(e,t)=>Math.max(0,Math.min(1,(t-e.min)/(e.max-e.min||1))),o6=(e,t)=>{let n=e.fromZero?a6(e,0):0;return[Math.min(n,t),Math.max(n,t)]},s6=(e,t)=>!!t&&(t.linked?t.linked===`active`:Number.isFinite(e.value)&&e.value>=t.value),c6=e=>(e.colorMode===`gradient`||e.colorMode===`zones`)&&!!e.stops?.length,l6=(e,t)=>s6(e,t)?t.color:Q3(e.colorMode,e.stops,e.color,e.value);function u6(e,t,n){for(let r of $3(t.colorMode,t.stops,t.color,t.min,t.max))e.addColorStop(n(r.f0),r.color),e.addColorStop(n(r.f1),r.color);return e}function d6(e,t,n){if(e.measureText(t).width<=n)return t;let r=t;for(;r.length>1&&e.measureText(`${r}…`).width>n;)r=r.slice(0,-1);return n>0?`${r}…`:``}var f6=Math.SQRT1_2;function p6(e,t,n,r,i,a,o,s,c){let l=Math.max(6,Math.min(i,a)*.06),u=t.max-t.min,d=i6(t.min,u),f=i6(t.max,u),p=e=>Math.max(9,Math.min(22,e*.1)),m=e=>Math.max(4,e*.13),h=Math.max(8,Math.min((i-2*l)/2,(a-2*l)/1.9)),g=0;for(let t=0;t<2;t++){e.font=`${p(h)}px ${X.mono}`,g=Math.max(e.measureText(d).width,e.measureText(f).width);let t=m(h),n=Math.max(h+t/2,f6*h+g/2),r=h+t/2+f6*h+t/2+6+p(h)*1.2;h=Math.max(8,Math.min(h*(i-2*l)/(2*n),h*(a-2*l)/r))}let _=m(h),v=p(h),y=h+_/2+f6*h+_/2+6+v*1.2,b=n+i/2,x=r+l+h+_/2+Math.max(0,(a-2*l-y)/2),S=e=>e6+e*t6;e.lineCap=`round`,e.lineWidth=_,e.strokeStyle=c.grid,e.beginPath(),e.arc(b,x,h,e6,e6+t6),e.stroke(),s&&s.value<t.max&&(e.globalAlpha=.3,e.strokeStyle=s.color,e.lineCap=`butt`,e.beginPath(),e.arc(b,x,h,S(a6(t,s.value)),e6+t6),e.stroke(),e.globalAlpha=1,e.lineCap=`round`);let[C,w]=o6(t,Number.isFinite(t.value)?a6(t,t.value):0),T=()=>{e.lineCap=t.fromZero?`butt`:`round`,e.beginPath(),e.arc(b,x,h,S(C),Math.max(S(C)+1e-4,S(w))),e.stroke(),e.lineCap=`round`};if(c6(t)){let n=t6/(2*Math.PI),r=u6(e.createConicGradient(e6,b,x),t,e=>e*n);r.addColorStop(1,Q3(t.colorMode,t.stops,t.color,t.min)),e.strokeStyle=r,e.globalAlpha=.24,e.beginPath(),e.arc(b,x,h,e6,e6+t6),e.stroke(),e.globalAlpha=1,Number.isFinite(t.value)&&!s6(t,s)&&T()}if(Number.isFinite(t.value)&&(!c6(t)||s6(t,s))&&(e.strokeStyle=s6(t,s)?s.color:o,T()),t.fromZero&&t.min<0&&t.max>0){let n=S(a6(t,0));e.strokeStyle=c.muted,e.lineWidth=1.5,e.lineCap=`butt`,e.beginPath(),e.moveTo(b+Math.cos(n)*(h-_*.75),x+Math.sin(n)*(h-_*.75)),e.lineTo(b+Math.cos(n)*(h+_*.75),x+Math.sin(n)*(h+_*.75)),e.stroke(),e.lineWidth=_,e.lineCap=`round`}if(s&&s.value>=t.min&&s.value<=t.max){let n=S(a6(t,s.value));e.strokeStyle=s.color,e.lineWidth=Math.max(1.5,s.width),e.lineCap=`butt`,e.beginPath(),e.moveTo(b+Math.cos(n)*(h-_*.9),x+Math.sin(n)*(h-_*.9)),e.lineTo(b+Math.cos(n)*(h+_*.9),x+Math.sin(n)*(h+_*.9)),e.stroke();let r=h+_*.9+10*.7;s.linked&&cQ(e,b+Math.cos(n)*r-10/2,x+Math.sin(n)*r-10/2,s.color)}let E=Number.isFinite(t.value)?i6(t.value,u):`—`,D=2*(h-_)*.82,O=Math.max(11,h*.42);e.font=`650 ${O}px ${X.sans}`;let k=e.measureText(E).width;k>D&&(O=Math.max(9,O*D/k),e.font=`650 ${O}px ${X.sans}`),e.textAlign=`center`,e.textBaseline=`alphabetic`,e.fillStyle=s6(t,s)||c6(t)?l6(t,s):c.ink,e.fillText(E,b,x+O*.32),e.fillStyle=c.muted,t.unit&&(e.font=`600 ${Math.max(9,h*.13)}px ${X.sans}`,e.fillText(d6(e,t.unit,D),b,x+O*.32+Math.max(11,h*.19)));let A=x+f6*h+_/2+6,j=f6*h;e.textBaseline=`top`,e.font=`${v}px ${X.mono}`,e.fillText(d,b-j,A),e.fillText(f,b+j,A);let M=2*j-g-16,N=Math.max(10,Math.min(26,h*.13));e.font=`600 ${N}px ${X.sans}`;let P=e.measureText(t.name).width;P>M&&N>9&&(N=Math.max(9,N*M/P),e.font=`600 ${N}px ${X.sans}`),e.fillText(d6(e,t.name,M),b,A+(v-N)/2)}function m6(e,t,n,r,i,a,o,s,c){let l=Math.max(14,i*.06),u=n+l,d=n+i-l,f=d-u,p=Math.max(6,Math.min(16,a*.14)),m=Math.max(12,Math.min(34,a*.28)),h=r+a/2+m*.35,g=e=>u+a6(t,e)*f;e.textBaseline=`alphabetic`,e.fillStyle=c.muted,e.font=`600 ${Math.max(10,m*.42)}px ${X.sans}`,e.textAlign=`left`,e.fillText(d6(e,t.name,f),u,h-p/2-m-4),e.textAlign=`right`,e.fillStyle=s6(t,s)?s.color:c.ink,e.font=`650 ${m}px ${X.sans}`;let _=t.unit?(e.font=`600 ${Math.max(9,m*.4)}px ${X.sans}`,e.measureText(` ${t.unit}`).width):0;t.unit&&(e.fillStyle=c.muted,e.fillText(` ${t.unit}`,d,h-p/2-8)),e.fillStyle=s6(t,s)||c6(t)?l6(t,s):c.ink,e.font=`650 ${m}px ${X.sans}`,e.fillText(Number.isFinite(t.value)?i6(t.value,t.max-t.min):`—`,d-_,h-p/2-8),e.lineCap=`round`,e.lineWidth=p,e.strokeStyle=c.grid,e.beginPath(),e.moveTo(u,h),e.lineTo(d,h),e.stroke(),s&&s.value<t.max&&(e.globalAlpha=.3,e.strokeStyle=s.color,e.lineCap=`butt`,e.beginPath(),e.moveTo(g(s.value),h),e.lineTo(d,h),e.stroke(),e.globalAlpha=1,e.lineCap=`round`);let v=Number.isFinite(t.value)?a6(t,t.value):0,y=e=>u+e*f,[b,x]=o6(t,v),S=()=>{e.lineCap=t.fromZero?`butt`:`round`,e.beginPath(),e.moveTo(y(b),h),e.lineTo(Math.max(y(b)+.5,y(x)),h),e.stroke(),e.lineCap=`round`};c6(t)&&(e.strokeStyle=u6(e.createLinearGradient(u,0,d,0),t,e=>e),e.globalAlpha=.24,e.beginPath(),e.moveTo(u,h),e.lineTo(d,h),e.stroke(),e.globalAlpha=1,Number.isFinite(t.value)&&!s6(t,s)&&S()),Number.isFinite(t.value)&&(!c6(t)||s6(t,s))&&(e.strokeStyle=s6(t,s)?s.color:o,S()),t.fromZero&&t.min<0&&t.max>0&&(e.strokeStyle=c.muted,e.lineWidth=1.5,e.lineCap=`butt`,e.beginPath(),e.moveTo(g(0),h-p*.75),e.lineTo(g(0),h+p*.75),e.stroke(),e.lineWidth=p,e.lineCap=`round`),s&&s.value>=t.min&&s.value<=t.max&&(e.strokeStyle=s.color,e.lineWidth=Math.max(1.5,s.width),e.lineCap=`butt`,e.beginPath(),e.moveTo(g(s.value),h-p),e.lineTo(g(s.value),h+p),e.stroke(),s.linked&&cQ(e,g(s.value)-10/2,h-p-10-2,s.color)),e.fillStyle=c.muted,e.font=`${Math.max(9,m*.34)}px ${X.mono}`,e.textBaseline=`top`,e.textAlign=`left`,e.fillText(i6(t.min,t.max-t.min),u,h+p/2+4),e.textAlign=`right`,e.fillText(i6(t.max,t.max-t.min),d,h+p/2+4)}var h6=720;function g6(e,t){return t?e<h6:e<640}function _6(e){return e<=1?{cols:1,rows:1}:e===2?{cols:2,rows:1}:e<=4?{cols:2,rows:2}:{cols:3,rows:3}}gK();function v6(e,t){return e.flatMap(e=>{let n=e.info?.meta;if(!n?.recordingId)return[];let r=n.wallOrigin?Number(n.wallOrigin):NaN,i=n.wallQuality;return[{recordingId:n.recordingId,wallOrigin:Number.isFinite(r)?r:null,wallQuality:i===`exact`||i===`approx`?i:null,xOffset:t[e.id]??0}]})}var y6={get:()=>null,subscribe:()=>()=>{}};function b6(e){let[t,n]=(0,Z.useState)(null);return(0,Z.useLayoutEffect)(()=>{let t=e.current;if(!t)return;let r=e=>n(t=>g6(e,t??!1));if(r(t.clientWidth),typeof ResizeObserver>`u`)return;let i=new ResizeObserver(e=>{for(let t of e)r(t.contentRect.width)});return i.observe(t),()=>i.disconnect()},[e]),t}function x6(e){let t=De(e.settings),[n,r]=(0,Z.useState)(null),[i,a]=(0,Z.useState)(null),o=(0,Z.useRef)(null);(0,Z.useEffect)(()=>{i&&o.current?.querySelector(`[data-camera="${CSS.escape(i)}"]`)?.focus()},[i]);let s=e.recordings??[],c=e=>s.findIndex(t=>t.recordingId===e.recordingId),l=(e.video??[]).filter(e=>e.kind===`recorded`&&c(e)>=0).sort((e,t)=>c(e)-c(t)),u=e.onContextMenu?t=>{t.preventDefault(),e.onContextMenu({clientX:t.clientX,clientY:t.clientY})}:void 0;if(!t.length){let t=[...new Set([...e.live.filter(e=>e.kind===`camera`&&!e.lowOf),...l].map(t=>Te(t,e.live)))].sort();return(0,Q.jsx)(C6,{onContextMenu:u,title:`Choose a camera in this panel's settings`,detail:t.length?t.join(`, `):void 0})}let d={panel:e,recorded:l,recIndex:c};if(t.length===1)return(0,Q.jsx)(S6,{...d,id:t[0],onMenu:u});let f=n&&t.includes(n)?n:null,p=f?[f]:t,{cols:m,rows:h}=_6(p.length),g=()=>{a(f),r(null)};return(0,Q.jsxs)(`div`,{ref:o,className:`kymo-camera-wall`,style:{gridTemplateColumns:`repeat(${m}, minmax(0, 1fr))`,gridTemplateRows:`repeat(${h}, minmax(0, 1fr))`},onContextMenu:u,onKeyDown:e=>{e.key===`Escape`&&f&&(e.stopPropagation(),g())},children:[p.map(e=>(0,Q.jsx)(S6,{...d,id:e,multi:!0,wall:!f,onPick:f?void 0:()=>{a(null),r(e)}},e)),f?(0,Q.jsxs)(`button`,{type:`button`,className:`kymo-camera__all`,onClick:g,autoFocus:!0,children:[(0,Q.jsxs)(`svg`,{viewBox:`0 0 16 16`,"aria-hidden":`true`,children:[(0,Q.jsx)(`rect`,{x:`2`,y:`2`,width:`5`,height:`5`,rx:`1`}),(0,Q.jsx)(`rect`,{x:`9`,y:`2`,width:`5`,height:`5`,rx:`1`}),(0,Q.jsx)(`rect`,{x:`2`,y:`9`,width:`5`,height:`5`,rx:`1`}),(0,Q.jsx)(`rect`,{x:`9`,y:`9`,width:`5`,height:`5`,rx:`1`})]}),`All cameras`]}):null]})}function S6({panel:e,recorded:t,recIndex:n,id:r,multi:i,wall:a,onPick:o,onMenu:s}){let c=e.recordings??[],l={onMenu:s,wall:a,onPick:o},u=t.find(e=>e.id===r);if(u)return(0,Q.jsx)(w6,{...e,...l,source:u,name:i?Te(u,e.live):u.name,rec:c[n(u)]},`rec:${u.recordingId}:${u.id}`);let d=e.live.find(e=>e.id===r&&e.kind===`camera`);if(d?.limitNotice&&(d.limitNotice===`Video limit reached this month`||!d.video))return(0,Q.jsx)(C6,{onContextMenu:s,title:d.limitNotice,detail:Te(d,e.live)});if(!d?.video||d.status===`error`)return(0,Q.jsx)(C6,{onContextMenu:s,title:`Camera offline`,detail:d?Te(d,e.live):void 0});let f=e.live.find(e=>e.kind===`camera`&&e.lowOf===d.id&&e.video&&e.status!==`error`),p=f?.video?Sw({...f,video:f.video}):void 0;return(0,Q.jsx)(w6,{...e,...l,source:Sw({...d,video:d.video}),low:p,name:i?Te(d,e.live):d.name,conn:d},d.id)}function C6({title:e,detail:t,onContextMenu:n}){return(0,Q.jsx)(`div`,{className:`kymo-camera`,onContextMenu:n,children:(0,Q.jsxs)(`div`,{className:`kymo-camera__empty`,children:[(0,Q.jsxs)(`svg`,{className:`kymo-camera__empty-icon`,viewBox:`0 0 24 24`,"aria-hidden":`true`,children:[(0,Q.jsx)(`rect`,{x:`2.5`,y:`6`,width:`13`,height:`12`,rx:`2.5`}),(0,Q.jsx)(`path`,{d:`M15.5 10.5 21.5 7v10l-6-3.5`})]}),(0,Q.jsx)(`p`,{className:`kymo-camera__empty-title`,children:e}),t?(0,Q.jsx)(`p`,{className:`kymo-camera__empty-detail`,children:t}):null]})})}function w6(e){let{settings:t,source:n}=e,r=e.cursor??y6,i=(0,Z.useSyncExternalStore)(r.subscribe,r.get),a=e=>e.kind===`data`,o=e.rec?void 0:t.syncStreamId?e.live.find(e=>e.id===t.syncStreamId&&a(e)):e.live.find(t=>t.id===e.conn.parentId&&a(t))??e.live.find(t=>a(t)&&e.selection.includes(t.id))??e.live.find(a),s=i??e.viewXRange?.[1]??null,c=null,l=null,u=o?.clock?.quality()??`none`,d=null;if(e.rec){let{wallOrigin:r,wallQuality:i,xOffset:a}=e.rec;u=i??`none`;let o=n.range()?.[0]??null;s===null?c=o:r===null?(c=o,l=`This recording has no wall clock`):e.xKey===`Time`?d=r+s-a+t.offsetMs/1e3:e.xKey===`ElapsedTime`&&i===`exact`?d=s-a+t.offsetMs/1e3:(c=o,l=`Sync needs a time X axis`)}else s!==null&&(e.xIsTime?(d=o?.clock?.toWall(s,t.offsetMs)??null,d===null&&(l=`No data stream to sync with`)):l=`Sync needs a time X axis`);let f=e.rec?n.dataClockOffsetMs:o?.clockOffsetMs;d!==null&&(c=d+vw(n.sync,d)+yw(n.clockOffsetMs,f));let p=(0,Z.useRef)(null),m=(0,Z.useRef)(null),h=b6(p),g=h===null?null:e.low&&(h||e.wall)?e.low:n,_=(0,Z.useRef)(t.fit),v=(0,Z.useRef)(c);(0,Z.useLayoutEffect)(()=>{_.current=t.fit,v.current=c});let y=(0,Z.useRef)(null),b=(0,Z.useRef)(null),[x,S]=(0,Z.useState)(null),C=x??g??n,[w,T]=(0,Z.useState)(!1),[E,D]=(0,Z.useState)(!0);(0,Z.useEffect)(()=>{if(!g||y.current?.source===g)return;let e=!y.current,t=null,n=!1,r=()=>t?y.current===t:e,i=t=j6(g,m.current,()=>_.current,v.current,{unsupported:()=>{r()&&T(!0)},buffered:e=>{r()&&D(e)},frame:()=>{if(y.current===t){n||(n=!0,S(g));return}y.current?.dispose(),y.current=i,b.current=null,i.show(),n=!0,S(g),D(i.buffered())}},e);if(e){y.current=i;return}return b.current=i,()=>{y.current!==i&&(i.dispose(),b.current===i&&(b.current=null))}},[g]),(0,Z.useEffect)(()=>()=>{y.current?.dispose(),y.current=null},[]),(0,Z.useEffect)(()=>{y.current?.setTarget(c),b.current?.setTarget(c)},[c]);let O=T6(e.rec||c!==null?null:C),k=E6(e.rec?n:null),A=!!C.lowOf,j=C.info().latestT,M=!e.rec&&c!==null&&j!==null?c-j:null,N=e.rec?`No video at this time`:`Not buffered`;return(0,Q.jsxs)(`div`,{ref:p,className:`kymo-camera${e.onPick?` is-tile`:``}`,onContextMenu:e.onMenu,...e.onPick?{role:`button`,tabIndex:0,"data-camera":n.id,"aria-label":`Show ${e.name} alone`,onClick:e.onPick,onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),e.onPick())}}:{},children:[(0,Q.jsx)(`canvas`,{ref:m,className:`kymo-camera__video`,role:`img`,"aria-label":`Video from ${e.name}`}),w?(0,Q.jsx)(`div`,{className:`kymo-camera__empty`,children:(0,Q.jsx)(`p`,{className:`kymo-camera__empty-title`,children:`This browser can't decode this camera`})}):O===null?(0,Q.jsxs)(`div`,{className:`kymo-camera__overlay`,children:[(0,Q.jsx)(`span`,{className:`kymo-camera__name`,children:e.name}),e.rec?(0,Q.jsx)(`span`,{className:`kymo-camera__rec`,children:`Recording`}):c===null?(0,Q.jsx)(`span`,{className:`kymo-camera__live`,children:`LIVE`}):(0,Q.jsx)(`span`,{className:`kymo-camera__ago`,children:M===null?``:O6(M)}),A?(0,Q.jsx)(`span`,{className:`kymo-camera__badge`,title:`Low-quality copy (small panel)`,children:`LQ`}):null,c!==null&&u!==`none`?(0,Q.jsx)(`span`,{className:`kymo-camera__badge${u===`exact`?` is-exact`:``}`,children:u===`exact`?`Exact`:`Approx.`}):null,l??(c!==null&&!E?N:null)?(0,Q.jsx)(`span`,{className:`kymo-camera__note`,children:l??N}):null,e.conn?.limitNotice?(0,Q.jsx)(`span`,{className:`kymo-camera__note`,role:`status`,children:e.conn.limitNotice}):null,k?.broken?(0,Q.jsx)(`span`,{className:`kymo-camera__note`,role:`status`,title:`Some of this recording was missing, out of order or changed where it is stored (${k.broken} of ${k.broken+k.verified} checked ${k.broken+k.verified===1?`chunk`:`chunks`}). The video may have gaps there.`,children:`Some messages were missing or out of order`}):null]}):(0,Q.jsxs)(`div`,{className:`kymo-camera__empty kymo-camera__empty--cover`,role:`status`,children:[(0,Q.jsx)(`p`,{className:`kymo-camera__empty-title`,children:`No signal`}),(0,Q.jsxs)(`p`,{className:`kymo-camera__empty-detail`,children:[e.name,` · no video for `,D6(O)]})]})]})}function T6(e){let[t]=(0,Z.useState)(()=>Date.now()),[n,r]=(0,Z.useState)(null);return(0,Z.useEffect)(()=>{if(!e){r(null);return}let n=()=>{let{arrivedAt:n,gapMs:i}=e.info(),a=Date.now()-Math.max(n??0,t);r(a>_w(i)?Math.floor(a/1e3):null)};n();let i=setInterval(n,500);return()=>clearInterval(i)},[e,t]),n}function E6(e){let[t,n]=(0,Z.useState)(null);return(0,Z.useEffect)(()=>{if(!e?.integrity){n(null);return}let t=()=>{let t=e.integrity();n(e=>e?.verified===t?.verified&&e?.broken===t?.broken?e:t&&{verified:t.verified,broken:t.broken})};t();let r=setInterval(t,1e3);return()=>clearInterval(r)},[e]),t}function D6(e){return e<60?`${e} s`:e<3600?`${Math.floor(e/60)} min`:`${Math.floor(e/3600)} h`}function O6(e){let t=Math.abs(e).toFixed(1);return t===`0.0`?`0.0 s`:`${e<0?`−`:`+`}${t} s`}var k6=60,A6=.05;function j6(e,t,n,r,i,a=!0){let o=e.acquire?.(),s=!1,c=!0,l=e=>{c=e,i.buffered(e)},u=null,d=null,f=r,p=`live`,m=!0,h=!1,g=!1,_=null,v=null,y=null,b=[],x=MZ(),S=NaN,C=[],w=()=>{for(let e of b)e.close();b=[]},T=e=>{if(s){e.close();return}if(p===`seek`){_?.close(),_=e;return}for(b.push(e);b.length>(a?k6:1);)b.shift().close();i.frame?.()},E=e=>{if(!b.length)return;let t=b[b.length-1].timestamp/1e6,n=Number.isNaN(S)?16:e-S,r=Math.max(JZ(x,t,n,e=>{let t=b.find(t=>t.timestamp/1e6>e);return t?t.timestamp/1e6:NaN}),t-A6);x.d=r;let i=-1;for(;i+1<b.length&&b[i+1].timestamp/1e6<=r+1e-6;)i++;if(!(i<0)){for(let e=0;e<i;e++)b[e].close();v?.close(),v=b[i],b=b.slice(i+1)}},D=()=>{!d||d.state===`closed`?d=new VideoDecoder({output:T,error:()=>{}}):d.reset(),d.configure(u),m=!0},O=e=>{d?.state===`closed`&&e.key&&D(),!(d?.state!==`configured`||m&&!e.key)&&(m=!1,d.decode(new EncodedVideoChunk({type:e.key?`key`:`delta`,timestamp:Math.round(e.t*1e6),data:e.data})))},k=()=>{p=`live`,l(!0),w(),x=MZ(),D();for(let t of e.livePlan?.()??[])O(t)},A=async()=>{if(!h){h=!0;try{for(;!s&&p===`seek`&&g;){g=!1;let t=[];try{t=await e.seekPlan(f)}catch{}if(!(s||p!==`seek`||g)&&(l(t.length>0),t.length)){D();for(let e of t)O(e);try{await d.flush()}catch{}p===`seek`&&_&&(v?.close(),v=_,_=null,i.frame?.())}}}finally{h=!1,_?.close(),_=null}}},j=()=>{f===null?p!==`live`&&k():(p=`seek`,w(),g=!0,A())};e.onUnit&&C.push(e.onUnit(e=>{u&&p===`live`&&O(e)})),(async()=>{if(typeof VideoDecoder>`u`){i.unsupported();return}if(e.info().codec||(e.ready?await e.ready():e.onUnit&&await new Promise(t=>{let n=e.onUnit(()=>{e.info().codec&&(n(),t())});C.push(n)})),s)return;if(!e.info().codec){l(!1);return}let t={codec:e.info().codec,optimizeForLatency:!0,hardwareAcceleration:`no-preference`},n=!1;try{n=(await VideoDecoder.isConfigSupported(t)).supported===!0}catch{}if(!s){if(!n){i.unsupported();return}u=t,f===null?k():j()}})();let M=n(),N=()=>{if(!a)return;let e=window.devicePixelRatio||1,r=Math.max(1,Math.round(t.clientWidth*e)),i=Math.max(1,Math.round(t.clientHeight*e)),o=!1,s=performance.now();if(p===`live`&&E(s),S=s,(t.width!==r||t.height!==i)&&(t.width=r,t.height=i,o=!0),v&&(y?.close(),y=v,v=null,o=!0),n()!==M&&(M=n(),o=!0),!o||!y)return;let c=t.getContext(`2d`);if(!c)return;let l=y.displayWidth,u=y.displayHeight,d=M===`cover`?Math.max(r/l,i/u):Math.min(r/l,i/u),f=l*d,m=u*d;c.clearRect(0,0,r,i),c.drawImage(y,(r-f)/2,(i-m)/2,f,m)},P=0,F=()=>{P=oZ(F),N()};return P=oZ(F),{source:e,show(){a=!0},buffered:()=>c,setTarget(e){e!==f&&(f=e,u&&j())},dispose(){s=!0,sZ(P),C.forEach(e=>e()),d&&d.state!==`closed`&&d.close();for(let e of[_,v,y])e?.close();_=v=y=null,w(),o?.()}}}function M6(e,t){let n=e.filter(e=>e.x.length>=2&&N6(e.x));if(n.length<2)return null;let r=1/0,i=-1/0;for(let e of n)e.x[0]<r&&(r=e.x[0]),e.x[e.x.length-1]>i&&(i=e.x[e.x.length-1]);if(!(i>r))return null;let a=Math.max(2,t),o=Float64Array.from({length:a},(e,t)=>r+t/(a-1)*(i-r)),s=new Float64Array(a).fill(1/0),c=new Float64Array(a).fill(-1/0),l=new Uint16Array(a);for(let e of n){let t=0;for(let n=0;n<a;n++){let r=o[n];if(r<e.x[0]||r>e.x[e.x.length-1])continue;for(;t<e.x.length-2&&e.x[t+1]<r;)t++;let i=e.x[t],a=e.x[t+1],u=e.y[t],d=e.y[t+1],f=a===i?u:u+(d-u)*(r-i)/(a-i);f-f===0&&(f<s[n]&&(s[n]=f),f>c[n]&&(c[n]=f),l[n]++)}}for(let e=0;e<a;e++)l[e]<2&&(s[e]=NaN,c[e]=NaN);return{x:o,lo:s,hi:c}}function N6(e){for(let t=1;t<e.length;t++)if(!(e[t]>=e[t-1]))return!1;return!0}function P6(e){if(e.length===0)return null;if(e.length===1)return e[0];let t=new Set,n={};for(let r of e)for(let e=0;e<r.columnNames.length;e++){let i=r.columnNames[e];t.add(i),r.units[e]?.trim()&&(n[i]=r.units[e])}let r=[...t];return{meta:``,columnNames:r,units:r.map(e=>n[e]??``),rows:e.flatMap(e=>e.rows)}}QG(),gK();function F6(e,t,n,r,i){return n||e.length===0||(t>0?e.length!==1:e.length<2||r!==`ElapsedTime`)?null:e.map((e,n)=>({conn:e,keySuffix:`__${t+n}`,offset:i[e.id]??0}))}function I6(e,t,n,r,i){if(e.length===1){let a=e[0];return L6(a.conn,t,n,a.keySuffix,a.offset,r,i)}let a=e.map(e=>L6(e.conn,t,n,e.keySuffix,e.offset,[],null)),o=()=>a.reduce((e,t)=>t.latestT()>e.latestT()?t:e);return{pull:(e,t,n,i)=>[...r,...a.flatMap(r=>r.pull(e,t,n,i))],xBounds:()=>{let e=i;for(let t of a){let n=t.xBounds();n&&(e=e?[Math.min(e[0],n[0]),Math.max(e[1],n[1])]:n)}return e},latestX:()=>o().latestX(),version:()=>a.reduce((e,t)=>e+t.version(),0),latestT:()=>o().latestT(),timeAfter:e=>o().timeAfter(e),xAtTime:e=>o().xAtTime(e),latestValues:e=>new Map(a.flatMap(t=>[...t.latestValues(e)]))}}function L6(e,t,n,r,i,a,o){let s=null;return{pull:(o,c,l,u)=>{let d=e.source.version();if(!s||s.ver!==d||s.x0!==o||s.x1!==c||s.mp!==l){let a=e.source.getPointsSync(n,{xKey:t,x0:o-i,x1:c-i},l),u=i===0?a.x:a.x.map(e=>e+i);s={ver:d,x0:o,x1:c,mp:l,pts:{...a,x:u,cols:new Map([...a.cols].map(([e,t])=>[e+r,t]))}}}let f=WG(s.pts,u);if(t!==`ElapsedTime`)return[...a,f];let p=Math.min(e.source.latestTimeSync(),u===void 0?1/0:u-i),m=UG(n,t=>e.source.lastKnownSync(t),o-i,c-i,p);if(!m)return[...a,f];let h=i===0?m.x:m.x.map(e=>e+i);return[...a,f,{...m,x:h,cols:new Map([...m.cols].map(([e,t])=>[e+r,t]))}]},xBounds:()=>{let n=e.source.xBoundsSync(t);return n.x1>n.x0?o?[Math.min(o[0],n.x0+i),Math.max(o[1],n.x1+i)]:[n.x0+i,n.x1+i]:o},latestX:()=>{let n=e.source.latestSync(t);return Number.isFinite(n)?n+i:null},version:()=>e.source.version(),id:e.id,latestT:()=>e.source.latestTimeSync(),timeAfter:t=>e.source.timeAfterSync(t),xAtTime:n=>e.source.xAtTimeSync(t,n)+i,latestValues:t=>{let n=new Map,i=t.filter(e=>e.endsWith(r)),a=e.source.latestValuesSync(i.map(e=>e.slice(0,-r.length)));for(let e of i){let t=a.get(e.slice(0,-r.length));t!==void 0&&n.set(e,t)}return n}}}xE();function R6(e,t){return e.filter(e=>mE(t,e))}QG();var z6=`__ref`,B6=8e3;function V6(e,t){return e.map(e=>({...e,id:`${e.id}${z6}`,column:`${e.column}${z6}`,color:t}))}var H6=new WeakMap;function U6(e,t,n){let r=e.data.rows,i=`${t}\n${n.join(`
|
|
628
|
+
`)}`,a=H6.get(r);a||(a=new Map,H6.set(r,a));let o=a.get(i);if(o)return o;let s=W6(qG(r,t,n,B6,z6)),c={points:s,span:s.length>1?[s.x[0],s.x[s.length-1]]:null};return a.set(i,c),c}function W6(e){let t=!0;for(let n=1;n<e.length&&t;n++)t=e.x[n-1]<=e.x[n];if(t)return e;let n=Array.from({length:e.length},(e,t)=>t).sort((t,n)=>e.x[t]-e.x[n]),r=new Map;for(let[t,i]of e.cols)r.set(t,Float64Array.from(n,e=>i[e]));return{length:e.length,x:Float64Array.from(n,t=>e.x[t]),cols:r}}function G6(e,t){return e?t?[Math.min(e[0],t[0]),Math.max(e[1],t[1])]:e:t}function K6(e,t,n,r,i){e.source.trackCycles(t);let a=r.reference===`dataset`&&i?U6(i,t,n):null,o=null;return{pull:(i,s,c,l)=>{let u=e.source.version();if(!o||o.ver!==u||o.x0!==i||o.x1!==s||o.mp!==c){let l=ZG;if(r.reference===`previous`){let r=e.source.cyclePointsSync(t,`previous`,n,{x0:i,x1:s},c);l={...r,cols:new Map([...r.cols].map(([e,t])=>[e+z6,t]))}}else a&&(l=GG(a.points,i,s));o={ver:u,x0:i,x1:s,mp:c,live:e.source.cyclePointsSync(t,`current`,n,{x0:i,x1:s},c),ref:l}}return[o.ref,WG(o.live,l)]},id:e.id,latestT:()=>e.source.latestTimeSync(),timeAfter:t=>e.source.timeAfterSync(t),xAtTime:n=>e.source.xAtTimeSync(t,n),xBounds:()=>G6(e.source.cycleSpanSync(t),a?.span??null),latestX:()=>{let n=e.source.latestSync(t);return Number.isFinite(n)?n:null},version:()=>e.source.version(),latestValues:t=>e.source.latestValuesSync(t)}}function q6(e,t){return e.reference===`previous`?e.previousColor:e.reference===`dataset`&&t?e.datasetColor:null}function J6(e,t,n,r,i=0){let a=e.bands;if(!a)return[];let o=n.filter(e=>a[e.column]);if(o.length===0||e.data.rows.length!==a[o[0].column].lo.length)return[];let s=Float64Array.from(e.data.rows,e=>{let n=e[t];return typeof n==`number`?n+i:NaN});return o.map(e=>({seriesId:e.id,color:r??e.color,x:s,lo:a[e.column].lo,hi:a[e.column].hi}))}RE();var Y6=class{#e;#t;#n;#r=new Map;constructor(e,t={}){this.#e=e,this.#t=[...e.keys()].map(e=>({name:e,type:`number`,unit:t[e]??``})),this.#n=e.size?e.values().next().value.length:0}get length(){return this.#n}get columnMap(){return this.#e}async getSchema(){return this.#t}async getSeries(e){let t=this.#e.get(e.viewport.xKey),n=this.#e.get(e.column);return!t||!n?FE(new Float64Array,new Float64Array,e.viewport.x0,e.viewport.x1,e.maxPoints):FE(t,n,e.viewport.x0,e.viewport.x1,e.maxPoints)}async getSeriesMulti(e,t,n){return this.getSeriesMultiSync(e,t,n)}getSeriesMultiSync(e,t,n){let r=this.#e.get(t.xKey),i=r?e.filter(e=>this.#e.has(e)):[];return!r||i.length===0?{x0:t.x0,bucket:0,rows:[],columns:i}:ME(r,i.map(e=>this.#e.get(e)),i,t.x0,t.x1,n)}getColumnsSync(e,t,n){let r=this.#e.get(t.xKey),i=r?e.filter(e=>this.#e.has(e)):[];return!r||i.length===0?null:IE(r,i.map(e=>this.#e.get(e)),i,t.x0,t.x1,n)}async readColumns(e,t,n){let r={};for(let i of e){let e=this.#e.get(i);e&&(r[i]=e.slice(t,t+n))}return r}async xBounds(e){return this.xBoundsSync(e)}xBoundsSync(e){let t=this.#r.get(e);if(!t){let n=this.#e.get(e),r=1/0,i=-1/0;if(n)for(let e=0;e<n.length;e++){let t=n[e];t<r&&(r=t),t>i&&(i=t)}t=r<=i?{x0:r,x1:i}:{x0:0,x1:0},this.#r.set(e,t)}return t}sampleRowsSync(e,t){let n=t?this.#e.get(t.xcol):void 0,r=null;if(t&&n){r=[];for(let e=0;e<n.length;e++)n[e]>=t.x0&&n[e]<=t.x1&&r.push(e)}let i=r?r.length:this.#n,a=Math.max(1,Math.ceil(i/e)),o=[...this.#e.keys()],s=o.map(e=>this.#e.get(e)),c=[];for(let e=0;e<i;e+=a){let t=r?r[e]:e,n={};for(let e=0;e<o.length;e++){let r=s[e][t];n[o[e]]=Number.isNaN(r)?null:r}c.push(n)}return c}async sampleRows(e,t){return this.sampleRowsSync(e,t)}async dispose(){}};function X6(e){if(!Number.isFinite(e))return`—`;let t=Math.abs(e);return t>=1e4||t<.01&&e!==0?e.toExponential(1):String(parseFloat(e.toPrecision(4)))}function Z6(e,t){let n=Math.max(1,Math.min(50,Math.floor(t.xBins))),r=Math.max(1,Math.min(50,Math.floor(t.yBins))),i=t.xMin,a=t.xMax,o=t.yMin,s=t.yMax;if(i===void 0||a===void 0||o===void 0||s===void 0){let n=1/0,r=-1/0,c=1/0,l=-1/0;for(let i of e){let e=i[t.xCol],a=i[t.yCol];typeof e==`number`&&Number.isFinite(e)&&(e<n&&(n=e),e>r&&(r=e)),typeof a==`number`&&Number.isFinite(a)&&(a<c&&(c=a),a>l&&(l=a))}i===void 0&&(i=n),a===void 0&&(a=r),o===void 0&&(o=c),s===void 0&&(s=l)}let c=a-i,l=s-o;if(!(c>0)||!(l>0))return{cells:[],xLabels:[],yLabels:[]};let u=new Float64Array(n*r),d=new Float64Array(n*r),f=t.valueCol===``;for(let p of e){let e=p[t.xCol],m=p[t.yCol];if(typeof e!=`number`||!Number.isFinite(e)||typeof m!=`number`||!Number.isFinite(m)||e<i||e>a||m<o||m>s)continue;let h=Math.floor((e-i)/c*n);h>=n&&(h=n-1),h<0&&(h=0);let g=Math.floor((m-o)/l*r);g>=r&&(g=r-1),g<0&&(g=0);let _=g*n+h;if(f)d[_]+=1;else{let e=p[t.valueCol];if(typeof e!=`number`||!Number.isFinite(e))continue;u[_]+=e,d[_]+=1}}let p=Array.from({length:n},(e,t)=>X6(i+(t+.5)*(c/n))),m=Array.from({length:r},(e,t)=>X6(o+(r-1-t+.5)*(l/r))),h=[];for(let e=0;e<r;e++){let t=r-1-e;for(let r=0;r<n;r++){let i=e*n+r,a=d[i],o=f?a:a>0?u[i]/a:NaN;h.push({x:p[r],y:m[t],value:o})}}return{cells:h,xLabels:p,yLabels:m}}QG(),gK();var Q6=8e3,$6=3e3,e8=[];function t8(e){return`live`in e?e.live.source.columns():`source`in e&&e.source instanceof Y6?e.source.columnMap:void 0}var n8=4e3,r8=new WeakMap;function i8(e,t,n){let r=r8.get(e);r||r8.set(e,r=new Map);let i=JSON.stringify([n,...t]),a=r.get(i);return a||r.set(i,a=new VE({meta:``,columnNames:[n,...t],units:[],rows:e})),a}var a8=new WeakMap;function o8(e,t){if(t!==`parallel`||e.length===0)return e;let n=e.length,r=100/n;return e.map((e,t)=>({...e,bandFromPct:Math.round((n-1-t)*r),bandToPct:Math.round((n-t)*r)}))}function s8(e,t){let n=1/0,r=-1/0;for(let{rows:i,offset:a}of e){let e=a8.get(i);e||(e=new Map,a8.set(i,e));let o=e.get(t);if(o===void 0){let n=1/0,r=-1/0;for(let e of i){let i=e[t];typeof i!=`number`||!Number.isFinite(i)||(i<n&&(n=i),i>r&&(r=i))}o=Number.isFinite(n)?[n,r]:null,e.set(t,o)}o&&(n=Math.min(n,o[0]+a),r=Math.max(r,o[1]+a))}return Number.isFinite(n)&&r>n?[n,r]:null}function c8(e,t){let n={};for(let t=0;t<e.columnNames.length;t++){let r=e.units[t]?.trim();r&&(n[e.columnNames[t]]=r)}let r=Object.entries(n);for(let e=0;e<t;e++)for(let[t,i]of r)n[`${t}__${e}`]=i;return n}function l8(e,t){let n=1/0,r=-1/0;for(let i of e){let e=i[t];typeof e!=`number`||!Number.isFinite(e)||(e<n&&(n=e),e>r&&(r=e))}if(!(r>n))return e;let i=(r-n)/2,a=0,o=NaN;for(let n=0;n<e.length;n++){let r=e[n][t];typeof r!=`number`||!Number.isFinite(r)||(r<o-i&&(a=n),o=r)}return a===0?e:e.slice(a)}var u8=new Map;function d8(e){let t=u8.get(e);return t||(t=Float64Array.from({length:e},(e,t)=>t),u8.clear(),u8.set(e,t)),t}function f8(e){let{worksheet:t,viewXRange:n,selectedIds:r,selectedDatasets:i,mathChannels:a,datasetOffsets:o,datasetColors:s,datasetPalette:c}=e,l=t.panels,u=t.panelChartSettings,d=t.xKey,f={connections:(0,Z.useMemo)(()=>d===`ElapsedTime`?e.liveConnections:e.liveConnections.map(e=>{let t=l8(e.dataset.rows,d);return t===e.dataset.rows?e:{...e,dataset:{...e.dataset,rows:t}}}),[e.liveConnections,d])},[p,m]=(0,Z.useState)({}),h=(0,Z.useMemo)(()=>l.some(e=>e.kind!==`multiband`),[l]),g=(0,Z.useMemo)(()=>f.connections.some(e=>r.includes(e.id)),[f.connections,r]),_=(0,Z.useMemo)(()=>{let e=f.connections.filter(e=>r.includes(e.id));return e.length===1&&i.length===0?e[0]:null},[f.connections,r,i]),v=(0,Z.useMemo)(()=>P6(i.map(e=>{let t=p[e.id];return t?{...e.data,rows:t}:e.data})),[i,p]),y=(0,Z.useMemo)(()=>{let e=f.connections.filter(e=>r.includes(e.id)).map(e=>e.dataset);return e.length===0?v:P6(v?[v,...e]:e)},[v,f.connections,r]),b=(0,Z.useMemo)(()=>fw(a,u,d).map(e=>e.id).join(`
|
|
629
629
|
`),[a,u,d]),x=(0,Z.useMemo)(()=>{let e=new Set(b.split(`
|
|
630
|
-
`));return a.filter(t=>e.has(t.id))},[a,b]),S=(0,Z.useMemo)(()=>{if(!y)return null;let e=[...i.map(e=>{let t=p[e.id];return t?{...e.data,rows:t}:e.data}),...f.connections.filter(e=>r.includes(e.id)).map(e=>e.dataset)];if(x.length===0)return{dataset:y,partRows:e.map(e=>e.rows),parts:e};let t=e.map(e=>dw(e,x,d)),n=new Set(t.flatMap(e=>e.ok.map(e=>e.id))),a=x.filter(e=>n.has(e.id)),o=t.map(e=>e.rows),s=t.map(e=>e.ok.map(e=>e.name));if(a.length===0)return{dataset:y,partRows:o,parts:e};let c=a.filter(e=>!y.columnNames.includes(e.name));return{dataset:{meta:y.meta,columnNames:[...y.columnNames,...c.map(e=>e.name)],units:[...y.units,...c.map(e=>e.units)],rows:o.length===1?o[0]:[].concat(...o)},partRows:o,parts:e,okByPart:s}},[y,i,p,f.connections,r,x,d]),C=S?.dataset??null,w=(0,Z.useMemo)(()=>{let e=f.connections.filter(e=>r.includes(e.id));return e.length===0?i:[...i,...e.map(e=>({id:e.id,name:e.name,data:e.dataset,live:e}))]},[i,f.connections,r]),T=w.length>1,E=(0,Z.useMemo)(()=>w.length===1?
|
|
630
|
+
`));return a.filter(t=>e.has(t.id))},[a,b]),S=(0,Z.useMemo)(()=>{if(!y)return null;let e=[...i.map(e=>{let t=p[e.id];return t?{...e.data,rows:t}:e.data}),...f.connections.filter(e=>r.includes(e.id)).map(e=>e.dataset)];if(x.length===0)return{dataset:y,partRows:e.map(e=>e.rows),parts:e};let t=e.map(e=>dw(e,x,d)),n=new Set(t.flatMap(e=>e.ok.map(e=>e.id))),a=x.filter(e=>n.has(e.id)),o=t.map(e=>e.rows),s=t.map(e=>e.ok.map(e=>e.name));if(a.length===0)return{dataset:y,partRows:o,parts:e};let c=a.filter(e=>!y.columnNames.includes(e.name));return{dataset:{meta:y.meta,columnNames:[...y.columnNames,...c.map(e=>e.name)],units:[...y.units,...c.map(e=>e.units)],rows:o.length===1?o[0]:[].concat(...o)},partRows:o,parts:e,okByPart:s}},[y,i,p,f.connections,r,x,d]),C=S?.dataset??null,w=(0,Z.useMemo)(()=>{let e=f.connections.filter(e=>r.includes(e.id));return e.length===0?i:[...i,...e.map(e=>({id:e.id,name:e.name,data:e.dataset,live:e}))]},[i,f.connections,r]),T=w.length>1,E=(0,Z.useMemo)(()=>w.length===1?t8(w[0]):void 0,[w]),D=S?.partRows??e8;(0,Z.useEffect)(()=>{let e=i.filter(e=>e.kind!==`memory`);if(e.length===0)return;if(!n||!h){m(e=>Object.keys(e).length?{}:e);return}let t=!1,r=setTimeout(()=>{(async()=>{let r=await Promise.all(e.map(async e=>{let t={xcol:d,x0:n[0],x1:n[1]};try{let n=e.source,r=await n$(`sampleRows`,()=>n.sampleRows($6,t));return[e.id,r]}catch{return null}}));if(t)return;let i={};for(let e of r)e&&(i[e[0]]=e[1]);m(i)})()},150);return()=>{t=!0,clearTimeout(r)}},[i,n,d,h]);let O=(0,Z.useMemo)(()=>C?.columnNames.join(`
|
|
631
631
|
`)??``,[C]),k=a.map(e=>e.name).join(`
|
|
632
|
-
`),A=(0,Z.useMemo)(()=>{let e=i.filter(e=>e.kind!==`memory`).flatMap(e=>
|
|
633
|
-
`).filter(e=>!i.has(e));return a.length?[...r,...a]:r},[O,k,A]),L=(0,Z.useMemo)(()=>{let e=[];for(let t of l){if(t.kind!==`multiband`)continue;let n=u[t.id],r=n&&n.kind===`multiband`?n.series:[];e.push([t.id,[...new Set(r.map(e=>e.column).filter(e=>e!==d))]])}return JSON.stringify(e)},[l,u,d]),R=(0,Z.useMemo)(()=>{let e={};if(!C||j)return e;for(let[t,n]of JSON.parse(L)){let r=[];if(n.length>0)if(!T)r.push(qG(C.rows,d,n,A6));else{let e=Math.max(1,Math.floor(A6/w.length));for(let t=0;t<w.length;t++){let i=w[t];if(M&&`live`in i&&i.live)continue;let a=D[t]??i.data.rows;r.push(qG(a,d,n,e,`__${t}`,o[i.id]??0))}}e[t]=r}return e},[C,L,d,T,w,o,D,M,j]),z=(0,Z.useMemo)(()=>{let e={};if(!C)return e;for(let t of l){if(t.kind!==`multiband`)continue;let n=u[t.id],r=(n&&n.kind===`multiband`?n.series:[]).filter(e=>e.column!==d),i=n&&n.kind===`multiband`?n.layout:`overlay`,a=e=>R6(e,i),l;if(!T)l=a(r);else{let e=a(r);l=[];for(let t=0;t<w.length;t++){let n=NJ(s,w[t].id,t,c);for(let r of e)l.push({...r,id:`${r.id}__${t}`,column:`${r.column}__${t}`,color:n})}}let f=R[t.id]??[],p=T&&n?.kind===`multiband`&&n.envelope?r.flatMap(e=>{let t=u6(f.flatMap((t,n)=>{let r=t.cols.get(`${e.column}__${n}`);return r?[{x:t.x,y:r}]:[]}),P6);return t?[{seriesId:e.id,color:e.color,...t}]:[]}):void 0,m=w.flatMap((e,t)=>`bands`in e&&e.bands?E6(e,d,r,T?NJ(s,e.id,t,c):void 0,o[e.id]??0):[]),h=[...p??[],...m];e[t.id]={effectiveSeries:l,points:f,envelopes:h.length?h:void 0}}return e},[C,l,u,d,T,w,s,c,o,R]),B=(0,Z.useMemo)(()=>{let e={pts:{},colorMeta:{},datasetColors:{}};if(!C)return e;let t={},r={},i={},a=N6,o=w.map((e,t)=>({id:e.id,rows:D[t]??p[e.id]??e.data.rows,full:a(e)})),f={id:`single`,rows:C.rows,full:w.length===1?a(w[0]):void 0};for(let e of l){if(e.kind!==`xyscatter`)continue;let a=u[e.id];if(!a||a.kind!==`xyscatter`)continue;let{xyXCol:l,xyYCol:p}=a;if(!l||!p){t[e.id]={length:0,x:[],y:[]};continue}if(T){let{cols:r,colors:a}=a$(o,l,p,{xKey:d,viewXRange:n,colorOverrides:s,palette:c});t[e.id]=r,i[e.id]=a;continue}let m=i$(f,l,p,{xKey:d,viewXRange:n,colorCol:a.xyColorCol||void 0});t[e.id]=m?.cols??{length:0,x:[],y:[]},m?.color&&(r[e.id]=m.color)}return{pts:t,colorMeta:r,datasetColors:i}},[C,l,u,n,d,T,w,p,s,c,D]),V=(0,Z.useRef)(new Map),ee=(0,Z.useMemo)(()=>{let e={};if(!C)return e;let t={length:0,x:[],y:[],z:[]},{rows:r}=C,i=E;for(let a of l){if(a.kind!==`xyzmesh`)continue;let o=u[a.id];if(!o||o.kind!==`xyzmesh`)continue;if(o.xyzMode===`matrix`){let n=(o.xyzColumns??[]).flatMap(e=>{let t=QQ(r,e,i);return t?[t]:[]}),s=n[0]?.length??0,c=n.length;if(s<2||c<2){e[a.id]={points:t};continue}let l=V.current.get(a.id);l?.length!==s*c&&V.current.set(a.id,l=new Float32Array(s*c)),n.forEach((e,t)=>l.set(e.length===s?e:e.subarray(0,s),t*s));let u=QQ(r,d,i),f=u&&!(o.xyzColumns??[]).includes(d)&&u.length>=s&&Number.isFinite(u[0])&&Number.isFinite(u[s-1])?[u[0],u[s-1]]:[0,s-1];e[a.id]={points:t,surface:{w:s,h:c,values:l,x:f,y:[0,c-1]}};continue}let{xyzXCol:s,xyzYCol:c,xyzZCol:l}=o,f=s?QQ(r,s,i):void 0,p=c?QQ(r,c,i):void 0,m=l?QQ(r,l,i):void 0;if(!f||!p||!m){e[a.id]={points:t};continue}let h=n?QQ(r,d,i):void 0;if(!n||!h){e[a.id]={points:{length:Math.min(f.length,p.length,m.length),x:f,y:p,z:m}};continue}let[g,_]=n,v=0;for(let e=0;e<h.length;e++)h[e]>=g&&h[e]<=_&&v++;let y=new Float64Array(v),b=new Float64Array(v),x=new Float64Array(v);for(let e=0,t=0;e<h.length;e++)h[e]>=g&&h[e]<=_&&(y[t]=f[e],b[t]=p[e],x[t]=m[e],t++);e[a.id]={points:{length:v,x:y,y:b,z:x}}}return e},[C,l,u,n,d,E]),H=(0,Z.useMemo)(()=>{let e={};if(!C)return e;for(let t of l){if(t.kind!==`histogram`)continue;let n=u[t.id];e[t.id]=n?.kind===`histogram`&&n.histColumn&&$Q(C.rows,n.histColumn,E)||new Float64Array}return e},[C,l,u,E]),U=(0,Z.useMemo)(()=>{let e={};if(!C)return e;for(let t of l){if(t.kind!==`polar`)continue;let n=u[t.id],r=n?.kind===`polar`&&n.polarAngleCol?QQ(C.rows,n.polarAngleCol,E):void 0,i=n?.kind===`polar`&&n.polarRadiusCol?QQ(C.rows,n.polarRadiusCol,E):void 0;e[t.id]=r&&i?{angles:r,radii:i}:{angles:[],radii:[]}}return e},[C,l,u,E]),te=(e,t,n,r)=>{let i=t&&$Q(e,t,E)||new Float64Array,a=n?QQ(e,n,E):void 0;return{signal:i,rate:a&&t$(a)||parseFloat(r)||1}},W=(0,Z.useMemo)(()=>{let e={};if(!C)return e;for(let t of l){if(t.kind!==`spectrum`)continue;let n=u[t.id];n?.kind===`spectrum`&&(e[t.id]=te(C.rows,n.specSignalCol,n.specTimeCol,n.specSampleRate))}return e},[C,l,u,E]),ne=(0,Z.useMemo)(()=>{let e={};if(!C)return e;for(let t of l){if(t.kind!==`boxplot`)continue;let n=u[t.id];e[t.id]=n?.kind===`boxplot`&&n.boxValueCol?e$(C.rows,n.boxValueCol,n.boxGroupCol||void 0,E):[]}return e},[C,l,u,E]),G=(0,Z.useMemo)(()=>{let e={};if(!C)return e;for(let t of l){if(t.kind!==`spectrogram`)continue;let n=u[t.id];n?.kind===`spectrogram`&&(e[t.id]=te(C.rows,n.sgSignalCol,n.sgTimeCol,n.sgSampleRate))}return e},[C,l,u,E]),re=(0,Z.useMemo)(()=>{if(!C)return{};let e={};for(let t of l){if(t.kind!==`heatmap`)continue;let n=u[t.id];if(!n||n.kind!==`heatmap`){e[t.id]={cells:[],xLabels:[],yLabels:[]};continue}if(n.hmMode===`matrix`){let r=C.rows,i=n.hmColumns.flatMap(e=>{let t=QQ(r,e,E);return t?[{name:e,v:t}]:[]}),a=i.reduce((e,t)=>Math.min(e,t.v.length),i.length?1/0:0),o=QQ(r,d,E),s,c;if(n.hmSpacing===`values`){o&&S2(o.subarray(0,a))&&(s=Float64Array.from(o.subarray(0,a)));let e=i.map(e=>({c:e,v:parseFloat(e.name)})).sort((e,t)=>t.v-e.v);e.length&&S2(e.map(e=>e.v).reverse())&&(i=e.map(e=>e.c),c=Float64Array.from(e,e=>e.v))}let l=i.length,u=new Float32Array(a*l);i.forEach((e,t)=>u.set(e.v.subarray(0,a),t*a));let f=e=>String(o?+o[e].toPrecision(6):e+1);e[t.id]={cells:[],xLabels:[],yLabels:i.map(e=>e.name),grid:{w:a,h:l,values:u,xLabels:f,yLabels:i.map(e=>e.name)},xCentres:s,yCentres:c}}else if(n.hmMode===`correlation`){let r=n.hmColumns.filter(e=>I.includes(e));if(r.length<2){e[t.id]={cells:[],xLabels:r,yLabels:r};continue}let i=r.map(e=>{let t=[];for(let n of C.rows){let r=n[e];typeof r==`number`&&Number.isFinite(r)&&t.push(r)}return t}),a=i.map(e=>e.reduce((e,t)=>e+t,0)/(e.length||1)),o=[];for(let e=0;e<r.length;e++)for(let t=0;t<r.length;t++){let n=i[e],s=i[t],c=a[e],l=a[t],u=Math.min(n.length,s.length),d=0,f=0,p=0;for(let e=0;e<u;e++){let t=n[e]-c,r=s[e]-l;d+=t*r,f+=t*t,p+=r*r}let m=f>0&&p>0?d/Math.sqrt(f*p):+(e===t);o.push({x:r[t],y:r[e],value:m})}e[t.id]={cells:o,xLabels:r,yLabels:r}}else if(n.hmMode===`binned`||n.hmMode===`count`){let{hmXCol:r,hmYCol:i}=n,a=n.hmMode===`count`?``:n.hmValueCol;if(!r||!i||n.hmMode===`binned`&&!a){e[t.id]={cells:[],xLabels:[],yLabels:[]};continue}let o=e=>{let t=parseFloat(e);return Number.isFinite(t)?t:void 0};e[t.id]=k6(C.rows,{xCol:r,yCol:i,valueCol:a,xBins:n.hmXBins,yBins:n.hmYBins,xMin:o(n.hmXMin),xMax:o(n.hmXMax),yMin:o(n.hmYMin),yMax:o(n.hmYMax)})}else{let{hmXCol:r,hmYCol:i,hmValueCol:a}=n;if(!r||!i||!a){e[t.id]={cells:[],xLabels:[],yLabels:[]};continue}let o=new Map,s=new Set,c=new Set;for(let e of C.rows){let t=String(e[r]??``),n=String(e[i]??``),l=e[a];if(typeof l!=`number`||!Number.isFinite(l))continue;s.add(t),c.add(n);let u=`${t}\0${n}`,d=o.get(u)??{sum:0,count:0};o.set(u,{sum:d.sum+l,count:d.count+1})}let l=e=>{let t=[...e];return t.every(e=>e.trim()!==``&&Number.isFinite(Number(e)))?t.sort((e,t)=>Number(e)-Number(t)):t.sort()},u=l(s),d=l(c),f,p;if(n.hmSpacing===`values`){let e=Float64Array.from(u,Number),t=Float64Array.from(d,Number);S2(e)&&(f=e),S2(t)&&(d=[...d].reverse(),p=t.reverse())}let m=[];for(let e of d)for(let t of u){let n=o.get(`${t}\0${e}`);m.push({x:t,y:e,value:n?n.sum/n.count:0})}e[t.id]={cells:m,xLabels:u,yLabels:d,xCentres:f,yCentres:p}}}return e},[C,l,u,I,d,E]),ie=(0,Z.useMemo)(()=>{let e={};if(!C)return e;for(let t of l){if(t.kind!==`violin`)continue;let n=u[t.id];e[t.id]=n?.kind===`violin`&&n.vlValueCol?e$(C.rows,n.vlValueCol,n.vlGroupCol||void 0,E):[]}return e},[C,l,u,E]),ae=(0,Z.useMemo)(()=>{let e={};if(!C)return e;let{rows:t}=C;for(let n of l){if(n.kind!==`confusion`)continue;let r=u[n.id];if(!r||r.kind!==`confusion`||!r.cfActualCol||!r.cfPredictedCol){e[n.id]={actual:[],predicted:[]};continue}let{cfActualCol:i,cfPredictedCol:a}=r,o=E?.get(i),s=E?.get(a);if(o&&s){e[n.id]={actual:o,predicted:s};continue}let c=[],l=[];for(let e of t){let t=e[i],n=e[a];t!==void 0&&n!==void 0&&(c.push(t),l.push(n))}e[n.id]={actual:c,predicted:l}}return e},[C,l,u,E]),oe=(0,Z.useMemo)(()=>{let e={};if(!C)return e;for(let t of l){if(t.kind!==`roc`)continue;let n=u[t.id],r=n?.kind===`roc`&&n.rocScoreCol?QQ(C.rows,n.rocScoreCol,E):void 0,i=n?.kind===`roc`&&n.rocLabelCol?QQ(C.rows,n.rocLabelCol,E):void 0;e[t.id]=r&&i?{scores:r,labels:i}:{scores:[],labels:[]}}return e},[C,l,u,E]),se=(0,Z.useMemo)(()=>{let e={};if(!C)return e;let{rows:t}=C;for(let n of l){if(n.kind!==`losscurve`)continue;let r=u[n.id];if(!r||r.kind!==`losscurve`){e[n.id]={xValues:[],series:[]};continue}let{lcXCol:i,lcLeftCols:a,lcRightCols:o}=r,s=[...a.map(e=>({...e,axis:`left`})),...o.map(e=>({...e,axis:`right`}))].map(({column:e,color:n,axis:r})=>({label:e,color:n,values:QQ(t,e,E)??new Float64Array,axis:r})),c=s[0]?.values.length??t.length,l=i&&QQ(t,i,E)||Float64Array.from({length:c},(e,t)=>t);e[n.id]={xValues:l,series:s}}return e},[C,l,u,E]),ce=(0,Z.useMemo)(()=>{let e={};if(!C)return e;let{rows:t}=C;for(let n of l){if(n.kind!==`controlchart`)continue;let r=u[n.id],i=r?.kind===`controlchart`&&r.ccValueCol?QQ(t,r.ccValueCol,E):void 0;if(!r||r.kind!==`controlchart`||!i){e[n.id]={length:0,value:[]};continue}let a=0;for(let e=0;e<i.length;e++)i[e]-i[e]===0&&a++;let o=a===i.length?null:new Uint32Array(a),s=o?new Float64Array(a):i;if(o)for(let e=0,t=0;e<i.length;e++)i[e]-i[e]===0&&(o[t]=e,s[t++]=i[e]);let c=r.ccSubgroupCol,l=c?E?.get(c):void 0,d=e=>o?o[e]:e;e[n.id]={length:a,value:s,subgroup:c?e=>String(l?l[d(e)]:t[d(e)]?.[c]??``):void 0}}return e},[C,l,u,E]),le=(0,Z.useMemo)(()=>{let e={};if(!C)return e;let{rows:t}=C;for(let n of l){if(n.kind!==`parallelcoords`)continue;let r=u[n.id];if(!r||r.kind!==`parallelcoords`||r.pcColumns.length<2){e[n.id]={length:0,columns:[]};continue}let i=r.pcColumns.map(e=>QQ(t,e,E)??new Float64Array),a=Math.min(...i.map(e=>e.length)),o={length:a,columns:i},s=r.pcColorByCol;if(s)if(I.includes(s))o.colorValue=QQ(t,s,E);else{let e=new Map,n=new Int32Array(a);for(let r=0;r<a;r++){let i=String(t[r]?.[s]??``),a=e.get(i);a===void 0&&e.set(i,a=e.size),n[r]=a}o.colorIndex=n,o.colorLabels=[...e.keys()]}e[n.id]=o}return e},[C,l,u,I,E]),ue=(0,Z.useMemo)(()=>{let e={};if(!C)return e;let{rows:t}=C,n={length:0,x:[],y:[]};for(let r of l){if(r.kind!==`embedding`)continue;let i=u[r.id];if(!i||i.kind!==`embedding`||!i.emXCol||!i.emYCol){e[r.id]=n;continue}let{emXCol:a,emYCol:o,emColorCol:s,emColorMode:c,emLabelCol:l}=i,d=QQ(t,a,E),f=QQ(t,o,E);if(!d||!f){e[r.id]=n;continue}let p=Math.min(d.length,f.length),m={length:p,x:d,y:f};if(s)if(c===`numeric`&&I.includes(s))m.colorValue=QQ(t,s,E);else{let e=E?.get(s),n=new Map,r=new Int32Array(p);for(let i=0;i<p;i++){let a=String(e?e[i]:t[i]?.[s]??``),o=n.get(a);o===void 0&&n.set(a,o=n.size),r[i]=o}m.colorIndex=r,m.colorLabels=[...n.keys()]}if(l){let e=E?.get(l);m.label=e?t=>String(e[t]):e=>String(t[e]?.[l]??``)}e[r.id]=m}return e},[C,l,u,I,E]),de=(0,Z.useMemo)(()=>{if(!C)return{};let e={};for(let t of l){if(t.kind!==`flamegraph`)continue;let n=u[t.id];if(!n||n.kind!==`flamegraph`||!n.fgNameCol||!n.fgValueCol){e[t.id]=[];continue}let r=[];for(let e of C.rows){let t=String(e[n.fgNameCol]??``),i=n.fgParentCol?String(e[n.fgParentCol]??``):``,a=e[n.fgValueCol];!t||typeof a!=`number`||!Number.isFinite(a)||r.push({name:t,parent:i,value:a})}e[t.id]=r}return e},[C,l,u]),fe=(0,Z.useMemo)(()=>{if(!C)return{};let e={};for(let t of l){if(t.kind!==`barchart`)continue;let n=u[t.id];if(!n||n.kind!==`barchart`||n.bcValueCols.length===0){e[t.id]={groups:[],seriesNames:[]};continue}let r=n.bcValueCols;if(n.bcCategoryCol){let i=new Map;for(let e of C.rows){let t=String(e[n.bcCategoryCol]??`(blank)`);i.has(t)||i.set(t,r.map(()=>0));let a=new Map,o=i.get(t);for(let t=0;t<r.length;t++){let n=e[r[t]];typeof n==`number`&&Number.isFinite(n)&&(o[t]+=n),a.set(r[t],(a.get(r[t])??0)+1)}}e[t.id]={groups:Array.from(i.entries()).map(([e,t])=>({label:e,values:t})),seriesNames:r}}else{let n=C.rows,i=r.map(e=>QQ(n,e,E)),a=i.reduce((e,t)=>t?Math.min(e,t.length):e,1/0),o=Number.isFinite(a)?a:n.length,s=i.map(e=>e??new Float64Array(o).fill(NaN));e[t.id]={groups:[],columns:{length:o,values:s},seriesNames:r}}}return e},[C,l,u,E]),pe=(0,Z.useMemo)(()=>{let e={};if(!C)return e;let{rows:t}=C;for(let n of l){if(n.kind!==`radar`)continue;let r=u[n.id];if(!r||r.kind!==`radar`||r.rdAxesCols.length<3){e[n.id]={axes:[],series:[]};continue}let i=r.rdAxesCols,a=i.map(e=>QQ(t,e,E));if(r.rdGroupCol){let o=r.rdGroupCol,s=E?.get(o),c=s?s.length:t.length,l=new Map;for(let e=0;e<c;e++){let n=s?s[e]===s[e]?String(s[e]):`(blank)`:String(t[e][o]??`(blank)`),r=l.get(n);r||l.set(n,r=i.map(()=>0));for(let t=0;t<i.length;t++){let n=a[t]?.[e]??NaN;n-n===0&&(r[t]+=n)}}e[n.id]={axes:i,series:Array.from(l.entries()).map(([e,t])=>({name:e,values:t}))}}else{let t=a.map(e=>{let t=0,n=0;if(e)for(let r=0;r<e.length;r++)e[r]-e[r]===0&&(t+=e[r],n++);return t/(n||1)});e[n.id]={axes:i,series:[{name:`Series 1`,values:t}]}}}return e},[C,l,u,E]),me=(0,Z.useMemo)(()=>{if(!C)return{};let e={};for(let t of l){if(t.kind!==`areachart`)continue;let n=u[t.id];if(!n||n.kind!==`areachart`||n.acYCols.length===0){e[t.id]=[];continue}let r=C.rows,i=n.acYCols.map(e=>QQ(r,e,E)),a=i[0]?.length??r.length,o=(n.acXCol?QQ(r,n.acXCol,E):void 0)??U6(a);e[t.id]=n.acYCols.flatMap((e,t)=>{let n=i[t];return n?[{name:e,x:o,y:n}]:[]})}return e},[C,l,u,E]),he=(0,Z.useMemo)(()=>{let e={};if(!C)return e;for(let t of l){if(t.kind!==`cdfchart`)continue;let n=u[t.id];if(!n||n.kind!==`cdfchart`){e[t.id]=[];continue}e[t.id]=n.cdValueCols.map(e=>({name:e,values:$Q(C.rows,e,E)??new Float64Array}))}return e},[C,l,u,E]),ge=(0,Z.useMemo)(()=>{let e={};if(!C)return e;let{rows:t}=C,n={length:0,x:[],y:[],size:[]};for(let r of l){if(r.kind!==`bubblechart`)continue;let i=u[r.id];if(!i||i.kind!==`bubblechart`||!i.bbXCol||!i.bbYCol||!i.bbSizeCol){e[r.id]=n;continue}let a=QQ(t,i.bbXCol,E),o=QQ(t,i.bbYCol,E),s=QQ(t,i.bbSizeCol,E);if(!a||!o||!s){e[r.id]=n;continue}let c=Math.min(a.length,o.length,s.length),l=new Float64Array(c);for(let e=0;e<c;e++)l[e]=s[e]===s[e]?Math.max(0,s[e]):NaN;let d=new Float64Array(c);for(let e=0;e<c;e++)d[e]=l[e]===l[e]?a[e]:NaN;let f={length:c,x:d,y:o,size:l};if(i.bbColorCol){if(i.bbColorMode===`numeric`)f.colorValue=QQ(t,i.bbColorCol,E);else if(i.bbColorMode===`categorical`){let e=E?.get(i.bbColorCol),n=new Map,r=new Int32Array(c);for(let a=0;a<c;a++){let o=String(e?e[a]:t[a]?.[i.bbColorCol]??``),s=n.get(o);s===void 0&&n.set(o,s=n.size),r[a]=s}f.colorIndex=r,f.colorLabels=[...n.keys()]}}e[r.id]=f}return e},[C,l,u,E]),_e=(0,Z.useMemo)(()=>{if(!C)return{};let e={};for(let t of l){if(t.kind!==`treemap`)continue;let n=u[t.id];if(!n||n.kind!==`treemap`||!n.tmNameCol||!n.tmValueCol){e[t.id]=[];continue}let r=[];for(let e of C.rows){let t=String(e[n.tmNameCol]??``),i=n.tmParentCol?String(e[n.tmParentCol]??``):``,a=e[n.tmValueCol];!t||typeof a!=`number`||!Number.isFinite(a)||r.push({name:t,parent:i,value:a})}e[t.id]=r}return e},[C,l,u]),ve=(0,Z.useMemo)(()=>{if(!C)return{};let e={};for(let t of l){if(t.kind!==`sankey`)continue;let n=u[t.id];if(!n||n.kind!==`sankey`||!n.skSourceCol||!n.skTargetCol||!n.skValueCol){e[t.id]={nodeNames:[],links:[]};continue}let r=new Set,i=[];for(let e of C.rows){let t=String(e[n.skSourceCol]??``),a=String(e[n.skTargetCol]??``),o=e[n.skValueCol];!t||!a||typeof o!=`number`||!Number.isFinite(o)||(r.add(t),r.add(a),i.push({source:t,target:a,value:o}))}e[t.id]={nodeNames:Array.from(r),links:i}}return e},[C,l,u]),ye=(0,Z.useMemo)(()=>{let e={};if(!C)return e;for(let t of l){if(t.kind!==`calibration`)continue;let n=u[t.id],r=n?.kind===`calibration`&&n.cbScoreCol?QQ(C.rows,n.cbScoreCol,E):void 0,i=n?.kind===`calibration`&&n.cbLabelCol?QQ(C.rows,n.cbLabelCol,E):void 0;if(!n||n.kind!==`calibration`||!r||!i){e[t.id]=[];continue}let a=Math.max(2,n.cbBins),o=new Float64Array(a),s=new Float64Array(a);for(let e=0;e<Math.min(r.length,i.length);e++){let t=r[e],n=i[e];if(t-t!==0||n-n!==0)continue;let c=Math.max(0,Math.min(a-1,Math.floor(t*a)));o[c]+=n,s[c]++}e[t.id]=Array.from({length:a},(e,t)=>({center:(t+.5)/a,actual:s[t]>0?o[t]/s[t]:0,count:s[t]})).filter(e=>e.count>0)}return e},[C,l,u,E]),be=(0,Z.useMemo)(()=>{let e={};if(!C)return e;let t={length:0,theoretical:[],sample:[]},n=e=>{let t=$Q(C.rows,e,E);return t?Float64Array.from(t).sort():new Float64Array};for(let r of l){if(r.kind!==`qqplot`)continue;let i=u[r.id];if(!i||i.kind!==`qqplot`||!i.qqValueCol){e[r.id]=t;continue}let a=n(i.qqValueCol),o=a.length;if(o===0){e[r.id]=t;continue}if(i.qqMode===`column`&&i.qqRefCol){let t=n(i.qqRefCol),s=Math.min(o,t.length);e[r.id]={length:s,theoretical:t.subarray(0,s),sample:a.subarray(0,s)}}else{let t=e=>{let t=[2.515517,.802853,.010328],n=[1.432788,.189269,.001308],r=Math.sqrt(-2*Math.log(Math.min(e,1-e))),i=r-(t[0]+t[1]*r+t[2]*r*r)/(1+n[0]*r+n[1]*r*r+n[2]*r*r*r);return e<.5?-i:i},n=new Float64Array(o);for(let e=0;e<o;e++)n[e]=t((e+.5)/o);e[r.id]={length:o,theoretical:n,sample:a}}}return e},[C,l,u,E]),xe=(0,Z.useMemo)(()=>{if(!C)return{};let e={};for(let t of l){if(t.kind!==`gantt`)continue;let n=u[t.id];if(!n||n.kind!==`gantt`||!n.gtLabelCol||!n.gtStartCol||!n.gtEndCol){e[t.id]=[];continue}let r=[];for(let e of C.rows){let t=String(e[n.gtLabelCol]??``),i=e[n.gtStartCol],a=e[n.gtEndCol];if(!t||typeof i!=`number`||typeof a!=`number`||!Number.isFinite(i)||!Number.isFinite(a))continue;let o={label:t,start:i,end:a};n.gtGroupCol&&e[n.gtGroupCol]!==void 0&&(o.group=String(e[n.gtGroupCol])),r.push(o)}e[t.id]=r}return e},[C,l,u]),Se=C&&C.columnNames.indexOf(d)>=0?C.units[C.columnNames.indexOf(d)]??``:``,Ce=(0,Z.useMemo)(()=>C?B6(C,T?w.length:0):{},[C,T,w]);return{dataset:y,datasetWithChannels:C,multiDatasetMode:T,numericCols:I,anyDuckDb:j,duckDbLayers:F,liveConn:_,liveOverlays:M,hasLiveSelected:g,staticXRange:N,xUnit:Se,columnUnits:Ce,multibandDataByPanel:z,xyPointsByPanel:B,xyzPointsByPanel:ee,histogramDataByPanel:H,polarDataByPanel:U,spectrumDataByPanel:W,boxplotDataByPanel:ne,spectrogramDataByPanel:G,heatmapDataByPanel:re,violinDataByPanel:ie,confusionDataByPanel:ae,rocDataByPanel:oe,lossCurveDataByPanel:se,controlChartDataByPanel:ce,parallelCoordsDataByPanel:le,embeddingDataByPanel:ue,flameGraphDataByPanel:de,barChartDataByPanel:fe,radarDataByPanel:pe,areaChartDataByPanel:me,cdfChartDataByPanel:he,bubbleChartDataByPanel:ge,treemapDataByPanel:_e,sankeyDataByPanel:ve,calibrationDataByPanel:ye,qqPlotDataByPanel:be,ganttDataByPanel:xe,gaugeDataByPanel:(0,Z.useMemo)(()=>{let e={};if(!C)return e;let t=e=>e.trim()!==``&&Number.isFinite(Number(e))?Number(e):void 0;for(let n of l){if(n.kind!==`gauge`)continue;let r=u[n.id];if(r?.kind!==`gauge`){e[n.id]=[];continue}e[n.id]=r.ggGauges.flatMap(e=>{let n=e.column,r=n?QQ(C.rows,n,E):void 0;if(!r)return[];let i=1/0,a=-1/0,o=0,s=0,c=NaN;for(let e=0;e<r.length;e++){let t=r[e];t-t===0&&(t<i&&(i=t),t>a&&(a=t),o+=t,s++,c=t)}let l=s===0?NaN:e.value===`mean`?o/s:e.value===`min`?i:e.value===`max`?a:c,[u,d]=G6(s?i:0,s?a:1,t(e.min),t(e.max));return[{name:n,unit:Ce[n]??``,value:l,min:u,max:d,alarm:e.alarm??null,color:e.color,style:e.style,fromZero:e.fill===`zero`,colorMode:e.colorMode,stops:e.stops,stat:e.value}]})}return e},[C,l,u,E,Ce])}}function G6(e,t,n,r){t<=e&&(t=e+1);let i=uJ(t-e,5),a=n??Math.floor(e/i)*i,o=r??Math.ceil(t/i)*i;return o>a?[a,o]:[a,a+1]}QG(),gK();var K6=`#fb7185`,q6=2500,J6=new Float64Array;function Y6(e,t){return t&&e?.kind===`spectrogram`&&e.sgView!==`waterfall`&&e.sgSignalCol!==``}function X6(e){let t=[],n=(e,r)=>{if(typeof e==`string`){e&&(r===`column`||/(Col|Cols|Column|Columns)$/.test(r))&&t.push(e);return}if(Array.isArray(e)){for(let t of e)n(t,r);return}if(e&&typeof e==`object`)for(let[t,r]of Object.entries(e))t!==`addColumn`&&n(r,t)};return n(e,``),[...new Set(t)]}function Z6(e){let t=Q6(e);if(t.status!==`empty`||!e.data.dataset)return t;let n=new Set([...e.data.datasetWithChannels?.columnNames??[],...e.data.numericCols]);return X6(e.settings).some(e=>!n.has(e))?{...t,status:`missing`}:t}function Q6(e){let{panel:t,data:n,settings:r}=e;if(t.kind===`camera`)return{status:`ready`,data:null,node:(0,Q.jsx)($3,{settings:r?.kind===`camera`?r:Ee(),live:e.live??[],selection:e.selection??[],viewXRange:e.viewXRange,xIsTime:e.xKey===dK,xKey:e.xKey,video:e.video,recordings:e.recordings,cursor:e.cursor,onContextMenu:t=>e.onContextMenu(t)})};if(!n.dataset)return{status:`no-data`,node:null,data:null};let i=`${e.background??`theme`}|${e.styleToken}`,a=t=>e.onContextMenu(t),o=(e,t)=>({status:`ready`,node:e,data:t}),s={status:`empty`,node:null,data:null},c=t.id;switch(t.kind){case`multiband`:{let t=n.multibandDataByPanel[c],l=t?.points??[],u=t?.effectiveSeries??[],d=r?.kind===`multiband`?r:null,f=[...new Set((d?.series??[]).map(e=>e.column).filter(t=>t!==e.xKey))],p=e.xKey===`ElapsedTime`&&!n.numericCols.includes(`Time`)?`Time`:e.xKey,m={xLabel:n.xUnit?`${p} (${n.xUnit})`:p,series:u,columnUnits:n.columnUnits,height:e.height,backgroundToken:i,viewXRange:e.viewXRange,onViewXRangeChange:e.onViewXRangeChange,onCursorX:e.onCursorX,liveZoom:e.liveZoom,liveZoomId:c,xAxisLine:d?.xAxisLine,yAxisLine:d?.yAxisLine,gridLine:d?.gridLine,lineWidth:d?.lineWidth,onPlotContextMenu:a,shiftMode:e.shiftMode},h=d?.beacon;if(h?.enabled&&e.beaconLive&&f.length>0){let t=R6((d?.series??[]).filter(t=>t.column!==e.xKey),d?.layout??`overlay`),n=h.reference===`dataset`&&h.datasetId?e.findDataset(h.datasetId):void 0,r=T6(h,!!n),i=r?[...y6(t,r),...t]:t;return o((0,Q.jsx)(OQ,{...m,series:i,points:[],showLatestValues:!0,liveSource:w6(e.beaconLive,e.xKey,f,h,n),envelopes:n?E6(n,e.xKey,t,r??void 0):void 0,liveZoomMode:`free`}),{series:i,points:[]})}if(n.anyDuckDb)return u.length===0?s:o((0,Q.jsx)(YQ,{...m,layers:n.duckDbLayers,xKey:e.xKey,columns:f,maxPoints:q6}),{series:u,columns:f});if(!l.some(e=>e.length>0)&&!n.liveOverlays||u.length===0||!f.some(e=>n.numericCols.includes(e)))return s;let g=n.liveConn,_=null,v=n.liveOverlays,y=!g&&v&&f.length>0?m6(v,e.xKey,f,l,n.staticXRange):void 0,b=!!y&&l.length>0,x=y??(g&&f.length>0?{pull:(t,n,r,i,a)=>{let o=g.source.version();if(a){let i=2**Math.ceil(Math.log2((n-t)/8)),a=Math.floor(t/i)*i,s=Math.ceil(n/i)*i,c=Math.round(r*(s-a)/(n-t));return(!_||_.ver!==o||_.x0!==a||_.x1!==s||Math.abs(_.mp-c)>c*.25)&&(_={ver:o,x0:a,x1:s,mp:c,pts:g.source.getPointsSync(f,{xKey:e.xKey,x0:a,x1:s},c),held:UG(f,e=>g.source.lastKnownSync(e),a,s,g.source.latestTimeSync())}),_.held?[_.pts,_.held]:[_.pts]}(!_||_.ver!==o||_.x0!==t||_.x1!==n||_.mp!==r)&&(_={ver:o,x0:t,x1:n,mp:r,pts:g.source.getPointsSync(f,{xKey:e.xKey,x0:t,x1:n},r)});let s=WG(_.pts,i);if(e.xKey!==`ElapsedTime`)return[s];let c=UG(f,e=>g.source.lastKnownSync(e),t,n,Math.min(g.source.latestTimeSync(),i??1/0));return c?[s,c]:[s]},cutOnGpu:e.xKey===`ElapsedTime`,id:g.id,latestT:()=>g.source.latestTimeSync(),timeAfter:e=>g.source.timeAfterSync(e),xAtTime:t=>g.source.xAtTimeSync(e.xKey,t),xBounds:()=>{let t=g.source.xBoundsSync(e.xKey);return t.x1>t.x0?[t.x0,t.x1]:null},latestX:()=>{let t=g.source.latestSync(e.xKey);return Number.isFinite(t)?t:null},version:()=>g.source.version(),latestValues:e=>g.source.latestValuesSync(e),...e.xKey===`ElapsedTime`?{}:{spanForSeconds:t=>g.source.xTravelSync(e.xKey,t),bufferedSeconds:()=>{let e=g.source.xBoundsSync(`ElapsedTime`);return e.x1-e.x0}}}:void 0);return o((0,Q.jsx)(OQ,{...m,points:l,envelopes:t?.envelopes,showLatestValues:n.hasLiveSelected,fullXRange:n.staticXRange,liveSource:x,liveWindowSeconds:b?null:e.liveWindowSeconds,onLiveWindowChange:b?void 0:e.onLiveWindowChange,liveZoomMode:b?`free`:`follow`}),{series:u,points:l})}case`xyzmesh`:{let t=r?.kind===`xyzmesh`?r:te(4),l=n.xyzPointsByPanel[c];if(!l||l.points.length<1&&!l.surface)return s;let u=!!l.surface;return o((0,Q.jsx)(Q1,{ref:e.xyzRef,points:l.points,surface:l.surface,xLabel:u?(t.xyzColumns??[]).includes(e.xKey)?`Row`:e.xKey:t.xyzXCol,yLabel:u?`Column`:t.xyzYCol,zLabel:u?`Value`:t.xyzZCol,height:e.height,backgroundToken:i,xRange:V(t.xyzXScale.scaleMin,t.xyzXScale.scaleMax),yRange:V(t.xyzYScale.scaleMin,t.xyzYScale.scaleMax),zRange:V(t.xyzZScale.scaleMin,t.xyzZScale.scaleMax),viewMode:t.xyzViewMode,pointRadius:t.xyzPointRadius,showMesh:t.showMesh,meshStyle:t.meshStyle,meshOpacity:t.meshOpacity,alarms:[...t.xyzXScale.alarm?[{axis:`x`,...t.xyzXScale.alarm}]:[],...t.xyzYScale.alarm?[{axis:`y`,...t.xyzYScale.alarm}]:[],...t.xyzZScale.alarm?[{axis:`z`,...t.xyzZScale.alarm}]:[]],onPlotContextMenu:a}),l.surface??l.points)}case`xyscatter`:{let t=r?.kind===`xyscatter`?r:U(K6),l=n.xyPointsByPanel.pts[c]??[];if(l.length===0)return s;let u=n.xyPointsByPanel.colorMeta[c];return o((0,Q.jsx)(B$,{points:l,xLabel:t.xyXCol,yLabel:t.xyYCol,color:t.xyColor,datasetColors:n.xyPointsByPanel.datasetColors[c],colorLabel:u?.label,colorRange:u?[u.min,u.max]:void 0,pointRadius:t.xyPointRadius,drawMode:t.xyDrawMode,lineWidth:t.xyLineWidth,height:e.height,backgroundToken:i,xAxisLine:t.xyXAxisLine,yAxisLine:t.xyYAxisLine,gridLine:t.xyGridLine,fitSettings:t.xyFit,xScale:t.xyXScale,yScale:t.xyYScale,onPlotContextMenu:a}),l)}case`histogram`:{if(r?.kind!==`histogram`)return s;let t=n.histogramDataByPanel[c]??[];return t.length===0?s:o((0,Q.jsx)(a0,{values:t,label:r.histColumn,bins:r.histBins,color:r.histColor,showNormal:r.histNormal,logY:r.histLogY,height:e.height,backgroundToken:i,onPlotContextMenu:a}),t)}case`polar`:{if(r?.kind!==`polar`)return s;let t=n.polarDataByPanel[c]??{angles:[],radii:[]};if(t.angles.length===0)return s;let l=parseFloat(r.polarRadiusMin),u=parseFloat(r.polarRadiusMax);return o((0,Q.jsx)(C0,{angles:t.angles,radii:t.radii,angleLabel:r.polarAngleCol,radiusLabel:r.polarRadiusCol,color:r.polarColor,mode:r.polarMode,radiusMin:Number.isFinite(l)?l:void 0,radiusMax:Number.isFinite(u)?u:void 0,height:e.height,backgroundToken:i,onPlotContextMenu:a}),t)}case`spectrum`:{if(r?.kind!==`spectrum`)return s;let{signal:t,rate:l}=n.spectrumDataByPanel[c]??{signal:[],rate:1};return t.length<4?s:o((0,Q.jsx)(z0,{signal:t,sampleRate:l,label:r.specSignalCol,xMode:r.specXMode,yMode:r.specYMode,window:r.specWindow,color:r.specColor,logX:r.specLogX,height:e.height,backgroundToken:i,onPlotContextMenu:a}),t)}case`boxplot`:{if(r?.kind!==`boxplot`)return s;let t=n.boxplotDataByPanel[c]??[];return t.length===0?s:o((0,Q.jsx)(G0,{groups:t,color:r.boxColor,whiskers:r.boxWhiskers,height:e.height,backgroundToken:i,onPlotContextMenu:a}),t)}case`spectrogram`:{if(r?.kind!==`spectrogram`)return s;let{signal:t,rate:l}=n.spectrogramDataByPanel[c]??{signal:[],rate:1},u=Y6(r,!!n.liveConn)?n.liveConn:null,d=r.sgSignalCol,f=u?{version:()=>u.source.version(),samples:()=>u.source.samplesSync(d),latestT:()=>u.source.latestTimeSync(),timeAfter:e=>u.source.timeAfterSync(e),id:u.id,windowSeconds:e.liveWindowSeconds}:void 0;return!f&&t.length<r.sgWindowSize?s:r.sgView===`waterfall`?o((0,Q.jsx)(_2,{signal:t,sampleRate:l,windowSize:r.sgWindowSize,overlap:r.sgOverlap,winFunc:r.sgWinFunc,yMode:r.sgYMode,backgroundToken:i,onPlotContextMenu:a}),t):o((0,Q.jsx)(f2,{signal:f?J6:t,sampleRate:l,windowSize:r.sgWindowSize,overlap:r.sgOverlap,winFunc:r.sgWinFunc,yMode:r.sgYMode,logFreq:r.sgLogFreq,backgroundToken:i,onPlotContextMenu:a,live:f}),t)}case`heatmap`:{if(r?.kind!==`heatmap`)return s;let e=n.heatmapDataByPanel[c]??{cells:[],xLabels:[],yLabels:[]};if(e.cells.length===0&&!(e.grid&&e.grid.w*e.grid.h>0))return s;let t=e=>e!==void 0&&e.trim()!==``&&Number.isFinite(Number(e))?Number(e):void 0;return o((0,Q.jsx)(I2,{cells:e.cells,xLabels:e.xLabels,yLabels:e.yLabels,grid:e.grid,showValues:r.hmShowValues,colorScheme:r.hmColorScheme,xCentres:e.xCentres,yCentres:e.yCentres,contours:r.hmContours??0,vMin:t(r.hmRange?.scaleMin),vMax:t(r.hmRange?.scaleMax),backgroundToken:i,onPlotContextMenu:a}),e)}case`violin`:{if(r?.kind!==`violin`)return s;let e=n.violinDataByPanel[c]??[];return e.some(e=>e.values.length>0)?o((0,Q.jsx)(W2,{groups:e,color:r.vlColor,showBox:r.vlShowBox,bandwidth:parseFloat(r.vlBandwidth)||void 0,orientation:r.vlOrientation,backgroundToken:i,onPlotContextMenu:a}),e):s}case`confusion`:{if(r?.kind!==`confusion`)return s;let e=n.confusionDataByPanel[c]??{actual:[],predicted:[]};return e.actual.length===0?s:o((0,Q.jsx)(Z2,{actual:e.actual,predicted:e.predicted,normalize:r.cfNormalize,backgroundToken:i,onPlotContextMenu:a}),e)}case`roc`:{if(r?.kind!==`roc`)return s;let e=n.rocDataByPanel[c]??{scores:[],labels:[]};return e.scores.length===0?s:o((0,Q.jsx)(r4,{scores:e.scores,labels:e.labels,mode:r.rocMode,color:r.rocColor,backgroundToken:i,onPlotContextMenu:a}),e)}case`losscurve`:{if(r?.kind!==`losscurve`)return s;let e=n.lossCurveDataByPanel[c]??{xValues:[],series:[]};return e.series.length===0?s:o((0,Q.jsx)(a4,{xValues:e.xValues,series:e.series,xLabel:r.lcXCol||`Step`,backgroundToken:i,onPlotContextMenu:a}),e)}case`controlchart`:{if(r?.kind!==`controlchart`)return s;let e=n.controlChartDataByPanel[c];return!e||e.length<2?s:o((0,Q.jsx)(d4,{points:e,sigmaLevel:r.ccSigmaLevel,color:r.ccColor,backgroundToken:i,onPlotContextMenu:a}),e)}case`parallelcoords`:{if(r?.kind!==`parallelcoords`)return s;let e=n.parallelCoordsDataByPanel[c];if(!e||e.length===0||r.pcColumns.length<2)return s;let t=r.pcColorByCol?n.numericCols.includes(r.pcColorByCol):!1;return o((0,Q.jsx)(_4,{rows:e,axes:r.pcColumns,color:r.pcColor,colorByNumeric:t,backgroundToken:i,onPlotContextMenu:a}),e)}case`embedding`:{if(r?.kind!==`embedding`)return s;let e=n.embeddingDataByPanel[c];return!e||e.length===0?s:o((0,Q.jsx)(D4,{points:e,color:r.emColor,colorByNumeric:r.emColorMode===`numeric`&&!!r.emColorCol,pointSize:r.emPointSize,backgroundToken:i,onPlotContextMenu:a}),e)}case`flamegraph`:{if(r?.kind!==`flamegraph`)return s;let e=n.flameGraphDataByPanel[c]??[];return e.length===0?s:o((0,Q.jsx)(F4,{nodes:e,direction:r.fgDirection,backgroundToken:i,onPlotContextMenu:a}),e)}case`barchart`:{if(r?.kind!==`barchart`)return s;let e=n.barChartDataByPanel[c]??{groups:[],seriesNames:[]};if(e.groups.length===0&&!e.columns?.length)return s;let t=e=>e!==void 0&&e.trim()!==``&&Number.isFinite(Number(e))?Number(e):void 0,l=r.bcValueScale?{min:t(r.bcValueScale.scaleMin),max:t(r.bcValueScale.scaleMax)}:void 0;return o((0,Q.jsx)(V4,{groups:e.columns?void 0:e.groups,columns:e.columns,seriesNames:e.seriesNames,mode:r.bcMode,horizontal:r.bcHorizontal,valueRange:l,backgroundToken:i,onPlotContextMenu:a}),e)}case`radar`:{if(r?.kind!==`radar`)return s;let e=n.radarDataByPanel[c]??{axes:[],series:[]};return e.axes.length<3?s:o((0,Q.jsx)(G4,{axes:e.axes,series:e.series,fill:r.rdFill,color:r.rdColor,backgroundToken:i,onPlotContextMenu:a}),e)}case`areachart`:{if(r?.kind!==`areachart`)return s;let e=n.areaChartDataByPanel[c]??[];if(e.length===0)return s;let t=e=>e!==void 0&&e.trim()!==``&&Number.isFinite(Number(e))?Number(e):void 0,l=r.acYScale?{min:t(r.acYScale.scaleMin),max:t(r.acYScale.scaleMax)}:void 0;return o((0,Q.jsx)(Y4,{series:e,stacked:r.acStacked,yRange:l,backgroundToken:i,onPlotContextMenu:a}),e)}case`cdfchart`:{if(r?.kind!==`cdfchart`)return s;let e=n.cdfChartDataByPanel[c]??[];return e.length===0?s:o((0,Q.jsx)(Q4,{series:e,complement:r.cdComplement,logX:r.cdLogX,backgroundToken:i,onPlotContextMenu:a}),e)}case`bubblechart`:{if(r?.kind!==`bubblechart`)return s;let e=n.bubbleChartDataByPanel[c];return!e||e.length===0?s:o((0,Q.jsx)(o3,{points:e,color:r.bbColor,colorByNumeric:r.bbColorMode===`numeric`,maxRadius:r.bbMaxRadius,backgroundToken:i,onPlotContextMenu:a}),e)}case`treemap`:{let e=n.treemapDataByPanel[c]??[];return e.length===0?s:o((0,Q.jsx)(d3,{nodes:e,backgroundToken:i,onPlotContextMenu:a}),e)}case`sankey`:{let e=n.sankeyDataByPanel[c]??{nodeNames:[],links:[]};return e.links.length===0?s:o((0,Q.jsx)(_3,{nodeNames:e.nodeNames,links:e.links,backgroundToken:i,onPlotContextMenu:a}),e)}case`calibration`:{if(r?.kind!==`calibration`)return s;let e=n.calibrationDataByPanel[c]??[];return e.length===0?s:o((0,Q.jsx)(y3,{bins:e,color:r.cbColor,backgroundToken:i,onPlotContextMenu:a}),e)}case`qqplot`:{if(r?.kind!==`qqplot`)return s;let e=n.qqPlotDataByPanel[c];return!e||e.length===0?s:o((0,Q.jsx)(x3,{points:e,color:r.qqColor,backgroundToken:i,onPlotContextMenu:a}),e)}case`gauge`:{if(r?.kind!==`gauge`)return s;let e=n.gaugeDataByPanel[c]??[];if(e.length===0)return s;let t=n.liveConn??(n.liveOverlays?.length===1?n.liveOverlays[0].conn:void 0);return o((0,Q.jsx)(P3,{gauges:e,live:t?{latestT:()=>t.source.latestTimeSync(),timeAfter:e=>t.source.timeAfterSync(e),valueAt:(e,n)=>t.source.xAtTimeSync(e,n,!0)}:void 0,backgroundToken:i,onPlotContextMenu:a}),e)}case`gantt`:{let e=n.ganttDataByPanel[c]??[];return e.length===0?s:o((0,Q.jsx)(E3,{tasks:e,backgroundToken:i,onPlotContextMenu:a}),e)}}return s}var $6=500,e8=1e3;function t8(e){if(Array.isArray(e))return n8(e);if(!e||typeof e!=`object`)return null;let t=-1;for(let n of Object.values(e))Array.isArray(n)&&(t=Math.max(t,n8(n)));return t<0?null:t}function n8(e){let t=e=>!!e&&typeof e==`object`&&e.x instanceof Float64Array;return e.length>0&&t(e[0])?e.reduce((e,n)=>e+(t(n)?n.length:0),0):e.length}function r8(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e4?`${Math.round(e/1e3)}k`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function i8({stats:e,host:t}){let[n,r]=(0,Z.useState)(null);if((0,Z.useEffect)(()=>{let n=t.current?.ownerDocument.defaultView??window,i=0,a=0,o=0,s=-1,c=-1,l=e.renders,u=t.current?HX(t.current):0,d=f=>{c>=0&&f-s>e8&&(c=f,s=f,a=0,o=0,l=e.renders,u=t.current?HX(t.current):0),c<0?(c=f,s=f):f!==s&&(o=Math.max(o,f-s),s=f,a++);let p=f-c;if(p>=$6){let i=t.current,s=0;if(i)for(let e of i.getElementsByTagName(`canvas`))s+=e.width*e.height;let d=n.performance.memory,m=i?HX(i):0;r({fps:a*1e3/p,repaints:(m-u)*1e3/p,worstFrameMs:o,renderMs:e.lastRenderMs,rendersPerSec:(e.renders-l)*1e3/p,points:t8(e.data),domNodes:i?i.getElementsByTagName(`*`).length:0,canvasMp:s/1e6,heapMb:d?d.usedJSHeapSize/1048576:null,live:(()=>{let e=pZ();return e?{age:Date.now()/1e3-e.newest,lag:e.lag,wait:e.wait,waitAge:e.waitAge}:null})()}),a=0,o=0,c=f,l=e.renders,u=m}i=n.requestAnimationFrame(d)};return i=n.requestAnimationFrame(d),()=>n.cancelAnimationFrame(i)},[e,t]),!n)return null;let i=n.fps<20?`var(--danger, #e5484d)`:n.fps<45?`var(--accent, #f5a524)`:void 0;return(0,Q.jsx)(`dl`,{className:`kymo-perf-hud`,style:a8,children:[[`FPS`,n.fps.toFixed(0),i],[`Repaints/s`,n.repaints.toFixed(0)],[`Slowest frame`,`${n.worstFrameMs.toFixed(1)} ms`],[`Render`,`${n.renderMs.toFixed(1)} ms`],[`Renders/s`,n.rendersPerSec.toFixed(1)],...n.points===null?[]:[[`Points`,r8(n.points)]],[`DOM nodes`,r8(n.domNodes)],[`Canvas`,`${n.canvasMp.toFixed(2)} MP`],...n.heapMb===null?[]:[[`JS heap`,`${n.heapMb.toFixed(0)} MB`]],...n.live?[[`Data age`,`${n.live.age.toFixed(2)} s`],[`Live lag`,`${n.live.lag.toFixed(2)} s`],[`Late by`,`${n.live.wait.toFixed(2)} s · ${n.live.waitAge.toFixed(0)} s ago`]]:[]].map(([e,t,n])=>(0,Q.jsxs)(`div`,{style:o8,children:[(0,Q.jsx)(`dt`,{style:s8,children:e}),(0,Q.jsx)(`dd`,{style:n?{...c8,color:n}:c8,children:t})]},e))})}var a8={position:`absolute`,top:8,right:8,zIndex:60,flex:`none`,pointerEvents:`none`,userSelect:`none`,margin:0,padding:`6px 9px`,minWidth:148,display:`grid`,gap:1,font:`500 10.5px/1.35 var(--font-sans, system-ui)`,fontVariantNumeric:`tabular-nums`,fontFeatureSettings:`"tnum" 1`,color:`var(--text-strong, #f3f5fa)`,background:`color-mix(in oklch, var(--bg-elevated, #1b2130) 86%, transparent)`,border:`1px solid var(--border, #33405a)`,borderRadius:6,boxShadow:`0 4px 14px color-mix(in oklch, black 28%, transparent)`},o8={display:`flex`,justifyContent:`space-between`,gap:12},s8={color:`var(--text-muted, #8a93a6)`},c8={margin:0,fontWeight:600,textAlign:`right`},l8=[],u8=3;function d8(e,t,n,r){return e.anchor===`x`&&!r?null:e.points.map(([i,a])=>[e.anchor===`x`?kZ(r,i):i*t,a*n])}function f8(e,t,n,r,i){return t.map(([t,a])=>[e.anchor===`x`&&i?AZ(i,t):p8(t/Math.max(1,n)),p8(a/Math.max(1,r))])}var p8=e=>Math.round(e*1e4)/1e4,m8=(0,Z.memo)(function({annotations:e,tool:t,plotFrame:n,onChange:r,onToolEnd:i,onSelect:a,marks:o=l8,onMarkSelect:s}){let c=(0,Z.useRef)(null),l=(0,Z.useSyncExternalStore)(n.subscribe,n.get),u=l?.x?l:null,[d,f]=(0,Z.useState)({w:0,h:0}),[p,m]=(0,Z.useState)(null),[h,g]=(0,Z.useState)(null),[_,v]=(0,Z.useState)(null),y=(0,Z.useRef)({annotations:e,onChange:r,onToolEnd:i,onSelect:a,tool:t,selected:p,editing:h,frame:u,size:d});y.current={annotations:e,onChange:r,onToolEnd:i,onSelect:a,tool:t,selected:p,editing:h,frame:u,size:d};let b=e=>{y.current.selected!==e&&(y.current.selected=e,m(e),y.current.onSelect(e))};(0,Z.useLayoutEffect)(()=>{let e=c.current;if(!e)return;let t=e.ownerDocument.defaultView??window,n=()=>f({w:e.clientWidth,h:e.clientHeight});n();let r=new t.ResizeObserver(n);return r.observe(e),()=>r.disconnect()},[]),(0,Z.useEffect)(()=>{t&&b(null)}),(0,Z.useEffect)(()=>{p&&!e.some(e=>e.id===p)&&b(null)}),(0,Z.useEffect)(()=>()=>{y.current.selected&&y.current.onSelect(null)},[]),(0,Z.useEffect)(()=>{let e=c.current?.ownerDocument;if(!e)return;let t=e=>{let{selected:t,editing:n,tool:r,annotations:i,onChange:a,onToolEnd:o}=y.current;if(!(n||C8(e.target))){if(e.key===`Escape`&&r){o();return}t&&(e.key===`Delete`||e.key===`Backspace`?(e.preventDefault(),a(i.filter(e=>e.id!==t)),b(null)):e.key===`Escape`&&b(null))}},n=e=>{let t=y.current.selected,n=e.target;t&&!n?.closest?.(`[data-ann-id="${CSS.escape(t)}"], [data-kymo-annotation-controls]`)&&b(null)};return e.addEventListener(`keydown`,t),e.addEventListener(`pointerdown`,n,!0),()=>{e.removeEventListener(`keydown`,t),e.removeEventListener(`pointerdown`,n,!0)}},[]);let{w:C,h:w}=d,T=e=>{let t=c.current.getBoundingClientRect();return[e.clientX-t.left,e.clientY-t.top]},E=(e,t)=>{let n=c.current.ownerDocument,r=t=>e(T(t),t),i=()=>{n.removeEventListener(`pointermove`,r),n.removeEventListener(`pointerup`,i),n.removeEventListener(`pointercancel`,i),t()};n.addEventListener(`pointermove`,r),n.addEventListener(`pointerup`,i),n.addEventListener(`pointercancel`,i)},D=e=>r([...y.current.annotations,e]),O=e=>r(y.current.annotations.map(t=>t.id===e.id?e:t)),k=e=>{if(!t||e.button!==0||h)return;e.preventDefault(),e.stopPropagation();let n=T(e),r={id:crypto.randomUUID(),kind:t.kind,color:t.color,width:t.width,...u?{anchor:`x`}:{}},i=e=>f8(r,e,C,w,u);if(t.kind===`text`){v({...r,points:i([n]),text:``}),g(r.id);return}let a=t.kind===`brush`?[n]:[n,n],o={...r,points:i(a)};v(o);let s=!1;E((t,n)=>{if(s||=Math.hypot(n.clientX-e.clientX,n.clientY-e.clientY)>u8,r.kind===`brush`){let e=a[a.length-1];if(Math.hypot(t[0]-e[0],t[1]-e[1])<2)return;a=[...a,t]}else a=[a[0],t];o={...o,points:i(a)},v(o)},()=>{v(null),s&&o.points.length>=2&&D(o)})},A=(e,t,n)=>{let r=d8(t,C,w,u);if(!r)return;let i=T(e),a=null;E((o,s)=>{if(!a&&Math.hypot(s.clientX-e.clientX,s.clientY-e.clientY)<=u8)return;let{size:c,frame:l}=y.current;a={...t,points:f8(t,n(r,[o[0]-i[0],o[1]-i[1]],o),c.w,c.h,l)},v(a)},()=>{v(null),a&&O(a)})},j=(e,n)=>{t||e.button!==0||h===n.id||(e.preventDefault(),e.stopPropagation(),b(n.id),A(e,n,(e,[t,n])=>e.map(([e,r])=>[e+t,r+n])))},M=(e,t,n)=>{e.button===0&&(e.preventDefault(),e.stopPropagation(),A(e,t,(e,r,i)=>{let a=e.map(e=>[...e]);return t.kind===`arrow`?a[n]=i:(a[+(n===1||n===2)][0]=i[0],a[+(n===2||n===3)][1]=i[1]),a}))},N=e=>{t||e.kind!==`text`&&e.kind!==`box`||(b(e.id),g(e.id))},P=e=>{let t=h;g(null);let n=_&&_.id===t?_:null;if(v(null),e===null||!t)return;let i=e.replace(/\s+$/,``),a=y.current.annotations;if(n){i&&D({...n,text:i});return}let o=a.find(e=>e.id===t);o&&(!i&&o.kind===`text`?r(a.filter(e=>e.id!==t)):O(S8(o,i)))},F=e=>{r(y.current.annotations.filter(t=>t.id!==e)),b(null)},I=(_?e.some(e=>e.id===_.id)?e.map(e=>e.id===_.id?_:e):[...e,_]:e).flatMap(e=>{let t=d8(e,C,w,u);return t?[{a:e,px:t}]:[]}),L=p?I.find(e=>e.a.id===p):void 0,R=u?o.map(e=>{let t=d8(S(e,u.x.v1),C,w,u);return{m:e,x0:Math.min(t[0][0],t[1][0]),x1:Math.max(t[0][0],t[1][0])}}):[],z=L&&L.a.kind!==`text`?x8(L.px):null,B=e=>(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`svg`,{className:`kymo-ann-svg`,width:C,height:w,viewBox:`0 0 ${C} ${w}`,"aria-hidden":`true`,children:e.map(({a:e,px:t})=>e.kind===`text`?null:(0,Q.jsx)(`g`,{"data-ann-id":e.id,className:`kymo-ann kymo-ann--${e.kind}`,onPointerDown:t=>j(t,e),onDoubleClick:()=>N(e),children:(0,Q.jsx)(_8,{a:e,px:t})},e.id))}),e.map(({a:e,px:t})=>{if(e.kind!==`text`&&e.kind!==`box`)return null;let n=h===e.id;if(!n&&!e.text)return null;let r=e.kind===`text`?{left:t[0][0],top:t[0][1]}:{left:Math.min(t[0][0],t[1][0]),top:Math.min(t[0][1],t[1][1]),transform:`translateY(calc(-100% - 3px))`};return(0,Q.jsxs)(`div`,{"data-ann-id":e.id,className:`kymo-ann-text kymo-ann-text--${e.kind}${p===e.id&&e.kind===`text`?` is-selected`:``}`,style:{...r,color:e.color,fontSize:e.kind===`text`?e.width:12},onPointerDown:t=>j(t,e),onDoubleClick:()=>N(e),children:[n?(0,Q.jsx)(g8,{initial:e.text??``,onDone:P}):e.text,p===e.id&&e.kind===`text`&&!n?(0,Q.jsx)(h8,{onDelete:()=>F(e.id),style:{right:-11,top:-11}}):null]},`t-${e.id}`)})]});return(0,Q.jsx)(`div`,{ref:c,className:`kymo-annotations${t?` is-drawing is-tool-${t.kind}`:``}`,onPointerDown:k,onContextMenu:t?e=>e.preventDefault():void 0,children:C>0&&w>0?(0,Q.jsxs)(Q.Fragment,{children:[u&&R.length?(0,Q.jsx)(`div`,{className:`kymo-ann-clip`,style:{clipPath:`inset(0 ${Math.max(0,C-u.left-u.width)}px 0 ${Math.max(0,u.left)}px)`},children:(0,Q.jsx)(`svg`,{className:`kymo-ann-svg kymo-marks`,width:C,height:w,viewBox:`0 0 ${C} ${w}`,children:R.map(({m:e,x0:t,x1:n})=>(0,Q.jsxs)(`g`,{"data-mark":e.ruleId,role:`img`,"aria-label":`${e.late?`Late · `:``}${e.ruleName}, ${e.severity}`,className:`kymo-mark kymo-mark--${e.severity}${e.late?` kymo-mark--late`:``}`,style:{color:x[e.severity]},children:[(0,Q.jsx)(`rect`,{x:t,y:u.top,width:Math.max(1,n-t),height:u.height,fill:`currentColor`,fillOpacity:.12}),(0,Q.jsx)(`rect`,{x:t,y:u.top,width:Math.max(1,n-t),height:2,fill:`currentColor`}),(0,Q.jsx)(`rect`,{className:`kymo-mark-hit`,x:t,y:u.top,width:Math.max(6,n-t),height:8,onPointerDown:t=>{t.stopPropagation(),s?.(e.ruleId)}})]},e.id))})}):null,B(I.filter(e=>e.a.anchor!==`x`)),u?(0,Q.jsx)(`div`,{className:`kymo-ann-clip`,style:{clipPath:`inset(0 ${Math.max(0,C-u.left-u.width)}px 0 ${Math.max(0,u.left)}px)`},children:B(I.filter(e=>e.a.anchor===`x`))}):null,(0,Q.jsxs)(`svg`,{className:`kymo-ann-svg`,width:C,height:w,viewBox:`0 0 ${C} ${w}`,"aria-hidden":`true`,children:[z?(0,Q.jsx)(`rect`,{className:`kymo-ann-selection`,x:z.x-6,y:z.y-6,width:z.w+12,height:z.h+12,rx:4}):null,L&&!h&&(L.a.kind===`box`||L.a.kind===`arrow`)?(0,Q.jsx)(`g`,{"data-ann-id":L.a.id,children:v8(L.a,L.px).map(([e,t],n)=>(0,Q.jsx)(`rect`,{className:`kymo-ann-handle kymo-ann-handle--${L.a.kind===`arrow`?`end`:n%2?`nesw`:`nwse`}`,x:e-4.5,y:t-4.5,width:9,height:9,rx:2,onPointerDown:e=>M(e,L.a,n)},n))}):null]}),z&&!h?(0,Q.jsx)(h8,{onDelete:()=>F(L.a.id),id:L.a.id,style:{left:Math.min(C-12,z.x+z.w+6)-10,top:Math.max(10,z.y-6)-10}}):null]}):null})});function h8({onDelete:e,style:t,id:n}){return(0,Q.jsx)(`button`,{type:`button`,className:`kymo-ann-delete`,style:t,"data-ann-id":n,"aria-label":`Delete annotation`,title:`Delete (Del)`,onPointerDown:e=>e.stopPropagation(),onClick:e,children:(0,Q.jsx)(`svg`,{viewBox:`0 0 10 10`,width:`8`,height:`8`,"aria-hidden":`true`,children:(0,Q.jsx)(`path`,{d:`M2 2l6 6M8 2l-6 6`})})})}function g8({initial:e,onDone:t}){let n=(0,Z.useRef)(null),r=(0,Z.useRef)(!1),i=e=>{r.current||(r.current=!0,t(e))};return(0,Z.useLayoutEffect)(()=>{let t=n.current;if(!t)return;t.textContent=e,t.focus();let r=t.ownerDocument.createRange();r.selectNodeContents(t);let i=t.ownerDocument.defaultView?.getSelection();i?.removeAllRanges(),i?.addRange(r)},[]),(0,Q.jsx)(`div`,{ref:n,className:`kymo-ann-editor`,contentEditable:`plaintext-only`,suppressContentEditableWarning:!0,role:`textbox`,"aria-label":`Annotation text`,"aria-multiline":`true`,onPointerDown:e=>e.stopPropagation(),onKeyDown:e=>{e.stopPropagation(),e.key===`Enter`&&!e.shiftKey?(e.preventDefault(),i(n.current?.innerText??``)):e.key===`Escape`&&(e.preventDefault(),i(null))},onBlur:()=>i(n.current?.innerText??``)})}function _8({a:e,px:t}){let n={stroke:e.color,strokeWidth:e.width,fill:`none`,strokeLinecap:`round`,strokeLinejoin:`round`},r=t=>(0,Q.jsx)(`path`,{className:`kymo-ann-hit`,d:t,strokeWidth:Math.max(12,e.width+10)});switch(e.kind){case`box`:{let[[i,a],[o,s]]=t,c=`M${i} ${a}H${o}V${s}H${i}Z`;return(0,Q.jsxs)(Q.Fragment,{children:[r(c),(0,Q.jsx)(`path`,{d:c,...n}),(0,Q.jsx)(`path`,{d:c,fill:e.color,fillOpacity:.06,stroke:`none`,pointerEvents:`none`})]})}case`arrow`:{let[[i,a],[o,s]]=t,c=b8(i,a,o,s,e.width);return(0,Q.jsxs)(Q.Fragment,{children:[r(`M${i} ${a}L${o} ${s}`),(0,Q.jsx)(`path`,{d:`M${i} ${a}L${c.base[0]} ${c.base[1]}`,...n}),(0,Q.jsx)(`path`,{d:c.d,fill:e.color,stroke:e.color,strokeWidth:1,strokeLinejoin:`round`})]})}case`brush`:{let e=y8(t);return(0,Q.jsxs)(Q.Fragment,{children:[r(e),(0,Q.jsx)(`path`,{d:e,...n})]})}}return null}function v8(e,t){if(e.kind===`arrow`)return t;let[[n,r],[i,a]]=t;return[[n,r],[i,r],[i,a],[n,a]]}function y8(e){if(e.length===0)return``;if(e.length<3)return`M${e[0][0]} ${e[0][1]}`+e.slice(1).map(([e,t])=>`L${e} ${t}`).join(``);let t=`M${e[0][0]} ${e[0][1]}`;for(let n=1;n<e.length-1;n++){let[r,i]=e[n],[a,o]=e[n+1];t+=`Q${r} ${i} ${(r+a)/2} ${(i+o)/2}`}let[n,r]=e[e.length-1];return t+`L${n} ${r}`}function b8(e,t,n,r,i){let a=Math.max(9,i*4),o=Math.atan2(r-t,n-e),s=.42,c=[n-a*Math.cos(o-s),r-a*Math.sin(o-s)],l=[n-a*Math.cos(o+s),r-a*Math.sin(o+s)],u=[n-a*.8*Math.cos(o),r-a*.8*Math.sin(o)];return{d:`M${n} ${r}L${c[0]} ${c[1]}L${l[0]} ${l[1]}Z`,base:u,l:c,r:l}}function x8(e){let t=e.map(e=>e[0]),n=e.map(e=>e[1]),r=Math.min(...t),i=Math.min(...n);return{x:r,y:i,w:Math.max(...t)-r,h:Math.max(...n)-i}}function S8(e,t){if(t)return{...e,text:t};let{text:n,...r}=e;return r}function C8(e){let t=e;return!!t&&(t.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName))}function w8(e,t,n,r,i,a,o){e.save(),e.scale(i,i),e.lineCap=`round`,e.lineJoin=`round`;for(let i of t){let t=d8(i,n,r,o);t&&(e.save(),i.anchor===`x`&&o&&(e.beginPath(),e.rect(o.left,0,o.width,r),e.clip()),T8(e,i,t,a),e.restore())}e.restore()}function T8(e,t,n,r){if(e.strokeStyle=t.color,e.fillStyle=t.color,e.lineWidth=t.width,t.kind===`box`)e.strokeRect(n[0][0],n[0][1],n[1][0]-n[0][0],n[1][1]-n[0][1]);else if(t.kind===`brush`)e.stroke(new Path2D(y8(n)));else if(t.kind===`arrow`){let r=b8(n[0][0],n[0][1],n[1][0],n[1][1],t.width);e.beginPath(),e.moveTo(n[0][0],n[0][1]),e.lineTo(r.base[0],r.base[1]),e.stroke(),e.beginPath(),e.moveTo(n[1][0],n[1][1]),e.lineTo(r.l[0],r.l[1]),e.lineTo(r.r[0],r.r[1]),e.closePath(),e.fill()}if(!t.text)return;let i=t.kind===`text`?t.width:12;e.font=`600 ${i}px ${r}`,e.textBaseline=`top`;let a=t.text.split(`
|
|
634
|
-
`),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 E8={solid:void 0,dashed:`5 4`,dotted:`1 4`};function D8(e,t,n){if(!e||!(n===`x`?e.x:e.y))return null;if(n===`x`){let n=kZ(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=jZ(e,t.value);return r>=e.top-.5&&r<=e.top+e.height+.5?[e.left,r,e.left+e.width,r]:null}var O8=(0,Z.memo)(function({frame:e,alarm:t,axis:n}){let r=D8((0,Z.useSyncExternalStore)(e.subscribe,e.get),t,n);if(!r)return null;let i=t.linked?k8(r,n):null;return(0,Q.jsxs)(`svg`,{className:`kymo-alarm`,"aria-hidden":`true`,children:[(0,Q.jsx)(`line`,{x1:r[0],y1:r[1],x2:r[2],y2:r[3],stroke:t.color,strokeWidth:t.width,strokeDasharray:t.linked===`active`?RZ.join(` `):E8[t.style]}),i?(0,Q.jsx)(`path`,{"data-alert-glyph":``,d:LZ,transform:`translate(${i[0]} ${i[1]})`,fill:t.color}):null]})});function k8(e,t){return t===`y`?[e[2]-10-3,e[1]-10-2]:[e[0]+3,e[1]+2]}function A8(e,t,n,r,i){let a=D8(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`?RZ:E8[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=k8(a,r);BZ(e,t[0],t[1],n.color)}e.restore()}}function j8(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,I8(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 M8=new WeakMap;function N8(e,t){let n=M8.get(e);n||M8.set(e,n=new Map);let r=n.get(t);return r||n.set(t,r=n=>e.view.setLiveWindow(n,t)),r}var P8=class{mounts=new Map;version=0;listeners=new Set;root=null;engine;constructor(e){this.engine=e}subscribe=e=>(this.listeners.add(e),()=>{this.listeners.delete(e)});getVersion=()=>this.version;bump(){this.version++;for(let e of[...this.listeners])e()}add(e){this.mounts.set(e.key,e),this.root||(this.root=(0,HY.createRoot)(document.createElement(`div`)),this.root.render((0,Q.jsx)(H8,{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}},F8=new WeakMap;function I8(e){let t=F8.get(e);return t||(t=new P8(e),F8.set(e,t)),t}function L8(e,t,n,r={}){e.charts.get(t);let i=I8(e),a={key:crypto.randomUUID(),chartId:t,element:n,options:r,shiftDatasetId:null,emitter:KY(),xyz:null,annotationTool:null,selectedAnnotation:null,plotFrame:PZ(),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 SE(`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 SE(`export_failed`,{reason:`canvas unavailable`}));for(let e of r)o.drawImage(e,0,0);let s=e.charts.get(t),c=Q8(s.settings,i9(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=t5(s.annotations,d?$8(u.marks,u.selection,d.xKey):[],l),p=Re(c);return p&&n.clientWidth>0&&A8(o,a.plotFrame.get(),p.alarm,p.axis,i.width/n.clientWidth),f.length&&n.clientWidth>0&&w8(o,f,n.clientWidth,n.clientHeight,i.width/n.clientWidth,X.sans,l),new Promise((e,t)=>i.toBlob(n=>n?e(n):t(new SE(`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 R8(e){F8.get(e)?.refresh()}function z8(e){F8.get(e)?.dispose(),F8.delete(e)}function B8(e){let t=new MutationObserver(e);return t.observe(document.documentElement,{attributes:!0,attributeFilter:[`data-color-scheme`,`class`,`data-theme`]}),()=>t.disconnect()}var V8=()=>{let e=document.documentElement;return`${e.getAttribute(`data-color-scheme`)??``}|${e.getAttribute(`data-theme`)??``}|${e.className}`};function H8({engine:e,registry:t}){(0,Z.useSyncExternalStore)(t.subscribe,t.getVersion);let n=i9(e),r=(0,Z.useSyncExternalStore)(n.store.subscribe,n.store.get),i=new Map;for(let e of t.mounts.values()){let t=r.worksheets.find(t=>t.panels.some(t=>t.id===e.chartId));if(!t)continue;let n=i.get(t.id)??{worksheet:t,mounts:[]};n.mounts.push(e),i.set(t.id,n)}return(0,Q.jsx)(Q.Fragment,{children:[...i.values()].map(t=>(0,Q.jsx)(K8,{engine:e,worksheet:t.worksheet,mounts:t.mounts},t.worksheet.id))})}var U8=1e3,W8=.25;function G8(e,t,n,r){let[i,a]=(0,Z.useState)(0),o=(0,Z.useRef)(0),s=(0,Z.useRef)(0);return(0,Z.useEffect)(()=>{o.current&&=(s.current=performance.now()-o.current,0)}),(0,Z.useEffect)(()=>{if(!n)return;let i=0,c=-1,l=0,u=n=>{if(i=RX(u),o.current||n<l||UX()||!r())return;let d=0;for(let n of e)t.includes(n.id)&&(d+=n.source.version());d!==c&&(c=d,l=n+s.current*(1/W8-1),o.current=performance.now(),(0,Z.startTransition)(()=>a(e=>e+1)))};return i=RX(u),()=>zX(i)},[n,e,t]),(0,Z.useMemo)(()=>n?e.map(e=>t.includes(e.id)?{...e,dataset:e.source.snapshot(U8)}:e):e,[e,t,n,i])}function K8({engine:e,worksheet:t,mounts:n}){let r=i9(e),i=(0,Z.useSyncExternalStore)(r.store.subscribe,r.store.get),a=r.derived(),o=i.xRanges[t.id]??null,s=(0,Z.useMemo)(()=>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=(0,Z.useRef)(n);d.current=n;let f=(0,Z.useRef)(()=>d.current.some(e=>e.element.isConnected&&(typeof e.element.checkVisibility!=`function`||e.element.checkVisibility()))).current,p=G8(s,i.selection,u,f),m=r.alertLines(),h=W6({worksheet:X8(t,m),viewXRange:o,selectedIds:i.selection,selectedDatasets:a.selectedDatasets,liveConnections:p,mathChannels:a.channels,datasetOffsets:i.offsets,datasetColors:i.colors,datasetPalette:i.palette}),g=(0,Z.useRef)(UY()).current,_=(0,Z.useSyncExternalStore)(B8,V8),v=t.id,y=N8(e,v),b=i.licensed,x=a.selectedLive[0]??null,S=e=>i.datasets.find(t=>t.id===e)??Object.values(a.laps).flatMap(e=>e.laps).find(t=>t.id===e);return(0,Q.jsx)(Q.Fragment,{children:n.map(n=>{let r=t.panels.find(e=>e.id===n.chartId);if(!r)return null;let s=n.shiftDatasetId?a.selectedDatasets.find(e=>e.id===n.shiftDatasetId):void 0,c=j8(n,e,v),l=Q8(t.panelChartSettings[r.id],m);return(0,VY.createPortal)((0,Q.jsx)(a5,{mount:n,annotations:t.panelChartSettings[r.id]?.annotations,marks:$8(i.marks,i.selection,t.xKey),onMarkSelect:c.onMarkSelect,alarm:Re(l),onAnnotations:c.onAnnotations,onAnnotationToolEnd:c.onAnnotationToolEnd,onAnnotationSelect:c.onAnnotationSelect,render:u=>Z6({panel:r,settings:l,background:n.options.style?.background??t.panelChartBackgrounds[r.id]??null,styleToken:JSON.stringify([_,n.options.theme,n.options.style,X]),data:h,xKey:t.xKey,height:u,viewXRange:o,onViewXRangeChange:c.onViewXRangeChange,onCursorX:c.onCursorX,liveZoom:g,liveWindowSeconds:t.liveWindowSeconds===void 0?i.liveWindowSeconds:t.liveWindowSeconds,onLiveWindowChange:y,beaconLive:x,findDataset:S,live:i.live,selection:i.selection,cursor:c.cursor,video:e.video.sources(),recordings:X3(a.selectedDatasets,i.offsets),shiftMode:s?q8(e,s.id,s.name):void 0,onContextMenu:c.onContextMenu,xyzRef:c.xyzRef}),licensed:b},n.key),n.element,n.key)})})}function q8(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 J8=[],Y8=new WeakMap;function X8(e,t){if(!t.size)return e;let n=Y8.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]=Q8(a,t),i[n]!==a&&(r=!0);let a=r?{...e,panelChartSettings:i}:e;return Y8.set(e,{lines:t,out:a}),a}var Z8=new WeakMap;function Q8(e,t){if(!e||!t.size)return e;let n=Z8.get(e);if(n&&n.lines===t)return n.out;let r=Ie(e,t);return Z8.set(e,{lines:t,out:r}),r}var $8=n5((e,t,n)=>{let r=e.filter(e=>e.timeColumn===n&&t.includes(e.targetId));return r.length?r:e5}),e5=[];function t5(e,t,n){return!t.length||!n?.x?e:[...t.map(e=>S(e,n.x.v1)),...e]}function n5(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 r5(e,t){e.data=t}function i5(e,t){e.status!==t&&(e.status=t,e.emitter.emit(`status`,t))}function a5({mount:e,render:t,licensed:n,annotations:r,marks:i,alarm:a,onAnnotations:o,onAnnotationToolEnd:s,onAnnotationSelect:c,onMarkSelect:l}){let u=(0,Z.useRef)(null),[d,f]=(0,Z.useState)(0),p=!!e.options.debug,m=(0,Z.useRef)({renderStart:0,lastRenderMs:0,renders:0,data:null}).current;p&&(m.renderStart=performance.now()),(0,Z.useLayoutEffect)(()=>{p&&(m.lastRenderMs=performance.now()-m.renderStart,m.renders++)}),(0,Z.useLayoutEffect)(()=>{let e=u.current;if(!e)return;let t=()=>f(Math.max(120,Math.floor(e.clientHeight)));t();let n=new WX(t);return n.observe(e),()=>n.disconnect()},[]);let{status:h,node:g,data:_}=t(d||400);m.data=_,(0,Z.useEffect)(()=>{r5(e,_)}),(0,Z.useEffect)(()=>{i5(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),(0,Q.jsxs)(`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:[(0,Q.jsx)(FZ.Provider,{value:e.plotFrame.set,children:g}),h===`ready`&&a?(0,Q.jsx)(O8,{frame:e.plotFrame,alarm:a.alarm,axis:a.axis}):null,h===`ready`&&(r?.length||e.annotationTool||i.length)?(0,Q.jsx)(m8,{annotations:r??J8,tool:e.annotationTool,plotFrame:e.plotFrame,onChange:o,onToolEnd:s,onSelect:c,marks:i,onMarkSelect:l}):null,p?(0,Q.jsx)(i8,{stats:m,host:u}):null,n===!1?(0,Q.jsx)(GY,{}):null]})}var o5=new WeakMap;function s5(e,t,n,r={}){let i=o5.get(e)??new Map;o5.set(e,i);let a=i.get(t);if(a&&!a.window.closed)return a.window.focus(),a;let o=e.charts.get(t),s=r.title??(o.title||e.charts.label(o.kind));for(let e of i.values())e.window.closed||e.window.focus();let c=40*(i.size+1),l=window.open(``,`kymoscope-chart-${t}`,`popup,width=${r.width??960},height=${r.height??600},left=${r.left??window.screenX+c},top=${r.top??window.screenY+c}`);if(!l)throw new SE(`popup_blocked`,{chartId:t});let u=l.document;u.head.replaceChildren(),u.body.replaceChildren(),u.title=s;for(let e of document.querySelectorAll(`style, link[rel="stylesheet"]`)){let t=e.cloneNode(!0);t instanceof HTMLLinkElement&&(t.href=e.href),u.head.appendChild(t)}let d=()=>{for(let e of[...u.documentElement.attributes])u.documentElement.removeAttribute(e.name);for(let e of document.documentElement.attributes)u.documentElement.setAttribute(e.name,e.value);u.body.className=document.body.className};d();let f=new MutationObserver(d);f.observe(document.documentElement,{attributes:!0}),f.observe(document.body,{attributes:!0,attributeFilter:[`class`]}),Object.assign(u.body.style,{margin:`0`,position:`fixed`,inset:`0`,display:`flex`,flexDirection:`column`,background:getComputedStyle(document.body).backgroundColor});let p=u.createElement(`div`);p.className=`kymo-window-controls`;let m=u.createElement(`div`);m.className=`kymo-window-plot`,Object.assign(m.style,{flex:`1`,minHeight:`0`,position:`relative`}),u.body.append(p,m),MX(l);let h=n(m,r.mount),g=KY(),_=!1,v=()=>{_||(_=!0,i.delete(t),NX(l),f.disconnect(),b(),window.removeEventListener(`pagehide`,y),h.destroy(),g.emit(`close`,void 0),g.clear())},y=()=>x.close(),b=e.subscribe(()=>{try{e.charts.get(t)}catch{x.close()}});l.addEventListener(`pagehide`,v),window.addEventListener(`pagehide`,y);let x={chartId:t,window:l,controls:p,view:h,close(){v(),l.closed||l.close()},on:(e,t)=>g.on(e,t)};return i.set(t,x),x}function c5(e){for(let t of[...o5.get(e)?.values()??[]])t.close()}function l5(e){let t=new Map;for(let[n,r]of o5.get(e)??[]){let e=r.window;e.closed||t.set(n,{left:e.screenX,top:e.screenY,width:e.innerWidth,height:e.innerHeight})}return t}xE(),Qe(),QG(),jE();var u5=12e3,d5=100;function f5(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 XG.add(n),n;for(let e=0;e<n.length;e++){let t=n[e];t-t!==0&&(n[e]=NaN)}return n}function p5(e,t){let n=Object.keys(t.columns);if(n.length===0)throw new SE(`no_columns`);let r=t.columns[n[0]].length;if(n.some(e=>t.columns[e].length!==r))throw new SE(`column_length_mismatch`);let i=new Map(n.map(e=>[e,f5(t.columns[e],t.transfer)])),a=m5(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 SE(`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 m5(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,d5);t++)e.push(o.map(e=>{let r=n.get(e)[t];return r===r?String(r):``}).join(`,`));d=e.join(`
|
|
635
|
-
`),f=cE(d)}let p={id:e,name:t,schema:l,rawText:d,parseConfig:f,fromColumns:!0};if(s>1e6){let e=new
|
|
636
|
-
`))}return r}function b5(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 x5(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)}gK();function S5(){let e=x5(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?Zw(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=VJ(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:GJ(n.id,t),name:`${n.name} · Cycle ${t+1}`,data:r,source:new VE(r)}}),values:a.map(e=>HJ(n.data.rows,e,r,i)),unit:o,isTime:i===`span`&&WJ(r,o)}}return t}),t=x5((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=x5((e,t)=>e.filter(e=>e.kind===`data`&&t.includes(e.id))),r=x5(e=>f6(e.map(e=>e.data))),i=x5((e,t)=>t.length===0?e:f6(e?[e,...t.map(e=>e.dataset)]:t.map(e=>e.dataset))),a=x5((e,t,n,r)=>{let i=new Set;if(e)for(let t of n.length>0?n:[e])for(let e of g6(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=>sJ(e.schema));return[...new Set([...a,...o])]});return{lapsByDataset:e,selectedDatasets:t,selectedLive:n,staticDataset:r,mergedDataset:i,mergedParts:x5((e,t)=>[...e.map(e=>e.data),...t.map(e=>e.dataset)]),numericColumns:x5((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:x5((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:x5((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 C5=[{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`}],w5=new Map(C5.map(e=>[e.kind,e.label]));function T5(e){return w5.get(e)??e}var E5=`kymoscope-live.v1`,D5=`kymoscope-live.ack1`,O5=`kymoscope-live.ack2`,k5=1e3,A5=2e3,j5=3e4,M5=1e4,N5=30,P5=1e4,F5=300,I5=90,L5=e=>e.startsWith(`eyJ`);function R5(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 z5(e,t){return`${e.replace(/\/+$/,``)}/v1/streams/${t}/watch`}function B5(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=R5(r);if(a===null)return;let c=L5(r),d=c?Math.min(a,Date.now()/1e3+F5):a,f=Math.min(Math.max((d-(c?I5:N5))*1e3-Date.now(),P5),2**31-1);o=setTimeout(async()=>{o=null;let r=null;try{r=await e.getToken(t)}catch{r=null}if(!(s||i!==n||!r)){try{n.send(JSON.stringify({type:`auth`,token:r}))}catch{return}u(n,r)}},f)},d=(e=!1)=>{if(s||a)return;let t=e?0:Math.min(j5,A5*2**c++)*(.75+Math.random()/2);a=setTimeout(()=>{a=null,f()},t)},f=async()=>{if(s)return;let a=null;try{a=await e.getToken(t)}catch{a=null}if(s)return;if(!a){r?.(`error`),d();return}let o=new WebSocket(z5(e.url,t),[E5,D5,O5,`bearer.${a}`]);o.binaryType=`arraybuffer`,i=o;let f=a,p=Date.now(),m=0,h=setInterval(()=>{if(!(m===0||o.readyState!==1)){try{o.send(JSON.stringify({type:`ack`,b:m}))}catch{return}m=0}},k5);o.onopen=()=>{r?.(`subscribed`),u(o,f)},o.onmessage=e=>{if(c=0,typeof e.data!=`string`){m+=e.data.byteLength,n(e.data);return}if(e.data.startsWith(`{"type":"probe"`))try{let t=JSON.parse(e.data).id;typeof t==`string`&&t.length<=64&&o.send(JSON.stringify({type:`ack`,id:t}))}catch{}},o.onclose=()=>{clearInterval(h),i===o&&(i=null,l(),!s&&(r?.(`error`),d(Date.now()-p>=M5)))}};return f(),()=>{if(s=!0,a&&=(clearTimeout(a),null),l(),i){let e=i;i=null,e.close(1e3)}}}var V5=24;function H5(e){if(e.length<V5||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=V5,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)}}IG(),GK(),BG(),yq(),tq();function U5(e,t,n){let r=new Map,i=Promise.resolve(),a=n?JK(n,e=>t({type:`integrity`,integrity:e})):null;return Object.assign(n=>{let o=HK(e,n).catch(()=>null);a?.arrive(n,new Uint8Array(n,0,1)[0]&127,o),i=i.then(async()=>{try{let e=await o;if(!e)return;if(e.kind===6){let n=H5(e.plaintext);n&&t({type:`video`,m:n})}else if(e.kind===5){let t=cq(e.plaintext);r.set(t.id,t)}else if(e.kind===7){let n=lq(e.plaintext,r);n&&t({type:`last`,values:n})}else if(e.kind===4){let n=await dq(e.plaintext,r);n&&t(n.historical?{type:`columns`,block:n.block,historical:!0}:{type:`columns`,block:n.block})}else if(e.kind===3)t({type:`columns`,block:LG(e.plaintext)});else if(e.kind===2){let n=PG(e.plaintext);t({type:`frames`,frames:Array.isArray(n?.frames)?n.frames:[]})}}catch{}})},{reset:()=>a?.reset()})}var W5=``+new URL(`assets/liveIngestWorker-UV5D515-.js`,__kymoscopeScriptUrl).href;function G5(e,t,n,r,i){let a=()=>{let a=U5(n,r,t);return B5(e,t,a,e=>{e===`subscribed`&&a.reset(),i?.(e)})},o;try{if(typeof Worker>`u`)return a();o=CE(W5)}catch{return a()}let s=!1,c=()=>{try{o.postMessage({type:`stop`})}catch{o.terminate()}};return o.onmessage=a=>{let s=a.data;if(s.type===`decoded`){if(r(s.d),s.bytes)try{o.postMessage({type:`ack`,bytes:s.bytes})}catch{}}else if(s.type===`status`)i?.(s.status);else if(s.type===`ask`){let r=s.what===`token`?e.getToken(t):typeof n==`function`?n(s.arg):n;Promise.resolve(r).catch(()=>null).then(e=>{try{o.postMessage({type:`reply`,id:s.id,value:e})}catch{}})}},o.onerror=()=>{o.terminate(),!s&&(c=a())},o.postMessage({type:`start`,url:e.url,streamId:t,key:typeof n==`function`?null:n}),()=>{s=!0,c()}}var K5=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}};RE();var q5=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 J5(new Set(e.columnNames),t=>e.mirrorColumn(t))}samplesSync(e){let t=this.#e(),n=t.mirrorColumn(e);return n?{values:n,first:t.firstAbs}:null}hasValues(e){return this.#e().hasValues(e)}snapshot(e){return this.#e().toDataset(e)}async getSchema(){let e=this.#e();return e.columnNames.map(t=>({name:t,type:`number`,unit:e.unitOf(t)}))}async getSeries(e){let t=this.#e();return FE(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)}timeAfterSync(e){return this.#e().timeAfter(e)}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(){}},J5=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)}};gK();var Y5=4096,X5=5e3,Z5=class{startedAt=Date.now();n=0;capacity=Y5;time=new Float64Array(Y5);cols=new Map;order=[];units=new Map;timeColumn;timeUnit;constructor(e=dK,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=iK(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(Q5).join(`,`)}\n${t.map(Q5).join(`,`)}\n`],r=this.order.map(e=>this.cols.get(e));for(let e=0;e<this.n;e+=X5){let t=Math.min(this.n,e+X5),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+=`
|
|
637
|
-
`}n.push(i)}return n}};function Q5(e){let t=/^[=+\-@\t\r]/.test(e)?`'${e}`:e;return/[",\n\r]/.test(t)?`"${t.replace(/"/g,`""`)}"`:t}gK();var $5=512,e7=new WeakMap;function t7(e,t,n){let r=e7.get(e);r||e7.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 n7(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=WC(n.formula);if(!o.ok)continue;let{identifiers:s,functions:c}=GC(o.node);if(!s.every(e=>a.has(e)))continue;let l=c.some(e=>HC.includes(e)),u=Math.max(e.firstAbs,i-(l?$5:0)),d=new Map([dK,...s].map(t=>[t,e.range(t,u,r)])),{carry:f,keep:p}=t7(e,`${n.id}|${n.formula}`,u),m=ZC(n,e=>d.get(e),dK,r-u,t,f);m.status===`ok`&&(e.writeComputed(n.name,n.units,i,m.values.subarray(i-u)),p())}}function r7(e,t){e.clearComputed(),e7.delete(e),n7(e,t,e.firstAbs)}var i7=new Map;function a7(e,t){let n=`${t}|${Math.floor(e/900)}`,r=i7.get(n);r===void 0&&(r=Aw(e,t),i7.size>1e4&&i7.clear(),i7.set(n,r));let i=(e+r)%86400;return i<0?i+86400:i}var o7=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`?a7(e,n.tz):n.kind===`elapsed`?e-this.#e:e<this.#e?NaN:n.kind===`event`?(this.#t!==this.#t&&t===t&&Tw(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)}};gK();function s7(e){if(!e.cycle)throw Error(`a live segment axis needs a cycle rule`);let t=new zw(e.cycle),n=new o7(e.axis),r=NaN,i=`channel`in e.axis?e.axis.channel:null,a=[...new Set([...Rw(e.cycle),...i?[i]:[]])];return{feed(o,s,c=!1){let l=Math.max(s,o.firstAbs),u=o.endAbs;if(l>=u)return;let d=t=>{c||e.onEvent?.(t)},f=o.range(dK,l,u),p=new Map(a.map(e=>[e,o.range(e,l,u)])),m=new Float64Array(f.length).fill(NaN),h=i?p.get(i):null,g=[];for(let e=0;e<f.length;e++){t.step(f[e],t=>{let n=p.get(t);return n?n[e]:NaN},g);let i=t.open()?.tstart??null;i!==null&&(i!==r&&(r=i,n.begin(i),d({type:`open`,tstart:i})),m[e]=n.x(f[e],h?h[e]:NaN))}for(let e of g)d({type:`close`,segment:{tstart:e.tstart,tend:e.tend,kpis:{duration:(e.tend??e.tstart)-e.tstart},...e.flags.length?{flags:e.flags}:{}}});o.writeComputed(e.column,e.unit,l,m)}}}BK(),gK();var c7=1e7;function l7(e=globalThis.navigator?.deviceMemory){return Math.max(512,Math.round(((e??0)>0?e:16)*1024/8))}var u7=400,d7=4e3,f7=1e3,p7=3e3,m7=2,h7=5e3,g7=1e4;function _7(e,t,n=`data`){let r=new hK(t.capacity??c7,void 0,void 0,(t.maxMemoryMB??l7())*1024*1024);return{meta:e,buffer:r,source:new q5(()=>r),unsub:()=>{},status:`connecting`,error:null,lastFrameAt:Date.now(),lastColCount:0,lastValued:0,recorder:null,dropped:0,recDropped:0,video:n===`camera`?new Cw:null,clock:n===`camera`?null:new K5,lagTicks:0,lastRejoinAt:0,rejoin:()=>{},subscribed:!1,releaseTimer:void 0}}function v7(e,t,n,r){let i,a=-1/0,o=new Map;return async s=>{if(i===void 0&&(i=s,o.set(t,s)),s===i)return e;if(Date.now()-a<2e3)return null;a=Date.now();let c=await r().catch(()=>null);if(!c||o.has(c.salt)&&o.get(c.salt)!==s)return null;let l=c.key??(n===null?null:await bK(n,c.salt));return!l||!await TK(l,c.key_check).catch(()=>!1)?null:(o.set(c.salt,s),l)}}function y7(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(u7),source:t.source,rowCount:t.buffer.size,status:t.status,error:t.error,recordingSince:t.recorder?.startedAt??null,droppedSamples:t.dropped,...t.integrity?{integrity:t.integrity}:{}});o=e,t(o)},u=(e,t)=>{let n=!1,r=e.buffer.endAbs;for(let r of t)r&&typeof r.t==`number`&&Array.isArray(r.signals)&&(e.buffer.push(r),e.recorder?.add(r),n=!0);n&&f(e,r,t[t.length-1]?.t)},d=(e,t)=>{let n=e.buffer.endAbs;e.buffer.pushColumns(t),e.recorder?.addColumns(t),t.t.length>0&&f(e,n,t.t[t.t.length-1])},f=(e,t,n)=>{n7(e.buffer,s,t),e.segAxis?.tracker.feed(e.buffer,t),r?.rows(e.meta.id,e.buffer,t),typeof n==`number`&&e.clock?.observe(n,Date.now()/1e3),p(e,t===0||e.buffer.columnNames.length!==e.lastColCount||e.buffer.valuedCount!==e.lastValued)},p=(e,t)=>{e.lastFrameAt=Date.now();let n=e.status===`stale`||e.status===`connecting`;n&&(e.status=`live`),(n||t)&&l()},m=e=>{let t=i.get(e);t&&(clearTimeout(t.releaseTimer),t.unsub(),i.delete(e),l())},h=setInterval(()=>{let e=Date.now(),t=!1;for(let n of i.values()){n.status===`live`&&e-n.lastFrameAt>d7&&(n.status=`stale`,t=!0);let i=n.video&&n.subscribed&&n.status===`live`?n.video.info().lagMs:null;n.lagTicks=i!==null&&i>p7?n.lagTicks+1:0,n.video&&n.lagTicks>=m7&&e-n.lastRejoinAt>=h7&&(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()},f7);return{connections:()=>o,disconnect:m,startRecording(e){let t=i.get(e);!t||t.recorder||(t.recorder=new Z5,t.recDropped=0,l())},stopRecording(e){let t=i.get(e),n=t?.recorder;return!t||!n?null:(t.recorder=null,l(),{csv:n.toCsvParts(),rows:n.rows,name:t.meta.name,startedAt:n.startedAt,droppedSamples:t.recDropped})},setRelay(e){a=e},setSegmentAxis(e,t){let n=i.get(e);n&&(n.segAxis=t?{cfg:t,tracker:s7(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||(r7(t.buffer,e),t.segAxis&&(t.segAxis.tracker=s7(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=_7({id:r,name:e,ownerName:`This page`,visibility:`private`,orgName:null,parentId:null,lowOf:null},{...n(),...t});return i.set(r,a),l(),{id:r,push:e=>{i.get(r)===a&&u(a,Array.isArray(e)?e:[e])},pushColumns:e=>{i.get(r)===a&&d(a,e)},close:()=>m(r)}},async connect(e,t,o){if(i.has(e.id))return;let s=a&&e.relay_url?{...a,url:e.relay_url,getToken:async e=>{let t=await a.getToken(e);return t&&!L5(t)?t:null}}:a;if(!s)throw new SE(`relay_unavailable`);let c;if(typeof t==`string`){let n=EK(t).secret??t,r=await bK(n,e.salt);if(!await TK(r,e.key_check))throw new SE(`wrong_password`);c=o?.reload?v7(r,e.salt,n,o.reload):r}else if(c=`keyFor`in t?e=>t.keyFor(e):t,typeof c!=`function`){if(!await TK(c,e.key_check))throw new SE(`wrong_password`);o?.reload&&(c=v7(c,e.salt,null,o.reload))}let f=_7({id:e.id,name:e.name,ownerName:e.owner_name??``,visibility:e.visibility??`private`,orgName:e.org_name??null,projectName:e.project_name??null,parentId:e.parent_stream_id??null,lowOf:e.low_of_stream_id??null,limitNotice:e.limit_notice??null,sync:e.sync??null,clockOffsetMs:e.clock_offset_ms??null},{...n(),...o},e.kind);i.set(e.id,f);let m=t=>{if(i.get(e.id)===f)if(t.type===`video`)f.video&&(f.video.push(t.m),p(f,!1));else if(t.type===`last`){let e=f.buffer;for(let n of t.values)e.setLastKnown(n.name,n.unit,n.t,n.v);(e.columnNames.length!==f.lastColCount||e.valuedCount!==f.lastValued)&&l()}else if(t.type===`gap`)f.dropped+=t.samples,f.recorder&&(f.recDropped+=t.samples),l();else if(t.type===`integrity`){let e=f.integrity;f.integrity=t.integrity,(!e||e.broken!==t.integrity.broken)&&l()}else t.type===`columns`?t.historical?r?.historical?.(e.id,t.block):d(f,t.block):u(f,t.frames)},h=t=>{!f.subscribed||i.get(e.id)!==f||(t===`subscribed`?(f.status=`live`,f.lastFrameAt=Date.now()):t===`error`&&(f.status=`error`,f.error=`connection_error`),l())};f.rejoin=()=>{f.unsub=f.video?B5(s,e.id,U5(c,m),h):G5(s,e.id,c,m,h)};let g=f.video;g?(f.status=`idle`,g.onDemandChange(t=>{i.get(e.id)===f&&(clearTimeout(f.releaseTimer),t?f.subscribed||(f.subscribed=!0,g.resync(),f.status=`connecting`,f.lastFrameAt=Date.now(),f.rejoin(),l()):f.releaseTimer=setTimeout(()=>{f.subscribed=!1,f.unsub(),f.unsub=()=>{},f.status=`idle`,f.error=null,f.lagTicks=0,l()},g7))})):(f.subscribed=!0,f.rejoin()),l()},dispose(){clearInterval(h);for(let e of i.values())clearTimeout(e.releaseTimer),e.unsub();i.clear(),o=[]}}}function b7(e){let t=Object.keys(e.signals),n=x7(e.derived??{}),r=[...t,...n],i=e=>r.indexOf(e),a=n.map(t=>{let n=e.derived[t];return{i:i(t),d:n,src:(n.op===`diff`?[n.a,n.b]:[n.of]).map(i)}}),o=[],s=r.map(()=>!1),c=r.map(()=>e.staleS!=null),l=null,u=!1,d=e=>{u||(u=!0,l=e)},f=e=>{let t=e;if(`all`in t||`any`in t){let e=`all`in t,n=(e?t.all:t.any).map(f),r=o.length,i=n.filter(e=>`i`in o[e]);i.forEach((t,n)=>{let i=o[t];i.into=r,i.mode=n===0?0:e?1:2}),o.push({k:e?`all`:`any`,kids:n,rest:n.filter(e=>!i.includes(e)),fused:i.length>0})}else if(`not`in t){let e=f(t.not);o.push({k:`not`,kid:e})}else{let e=[`above`,`below`,`outside`,`inside`,`equals`,`changes`,`noData`].find(e=>e in t),n=i(t[e]),r=t.value??NaN,a=t.lo??NaN,l=t.hi??NaN;d(e===`above`?{i:n,excess:e=>e-r}:e===`below`?{i:n,excess:e=>r-e}:e===`outside`?{i:n,excess:e=>Math.max(e-l,a-e)}:null),e===`changes`&&(s[n]=!0),e===`noData`&&(c[n]=!0),o.push({k:e,i:n,v:r,lo:a,hi:l,h:t.hysteresis??0,f:t.forS??0,prev:0,into:o.length,mode:0})}return o.length-1};return f(e.when),{aliases:r,base:t.length,derived:a,ops:o,needPrev:s,needAt:c,first:l}}function x7(e){let t=[],n=new Set,r=i=>{if(n.has(i)||!(i in e))return;n.add(i);let a=e[i];for(let e of a.op===`diff`?[a.a,a.b]:[a.of])r(e);t.push(i)};return Object.keys(e).forEach(r),t}var S7=`\0t`;function C7(e,t){return`formula`in e?{applies:!0,column:e.formula}:e.stream&&!(t.kind===`stream`&&t.id===e.stream)||e.history&&!(t.kind===`history`&&t.id===e.history)||e.dataset&&!(t.kind===`dataset`&&t.name===e.dataset)?{applies:!1,column:null}:e.tag?{applies:!0,column:t.tags?.[e.tag]??null}:{applies:!0,column:e.channel}}function w7(e,t){let n=b7(e),r=n.aliases.length,i=n.base,a=e.staleS??1/0,o=Object.values(e.signals),s=o.every(e=>C7(e,t).applies),c=o.map(()=>null),l=!1,u=[],d=`idle`,f=NaN,p=NaN,m=-1/0,h=0,g=null,_=new Float64Array(r).fill(NaN),v=new Float64Array(r).fill(NaN),y=new Float64Array(r).fill(NaN),b=n.derived.map(()=>k7()),x=Array(r),S=Array(r),C=Array(r),w=Array(r),T=0,E=[],D=[],O=[],k=[],A=new Float64Array,j=new Float64Array,M=new Float64Array,N=new Int32Array,P=new Uint8Array,F=[],I=e=>{e<=T||(T=Math.max(e,T*2,64),E=Array.from({length:r},()=>new Float64Array(T)),D=Array.from({length:r},()=>new Float64Array(T)),O=Array.from({length:r},()=>new Uint8Array(T)),k=Array.from({length:r},()=>new Float64Array(T)),A=new Float64Array(T),j=new Float64Array(T),M=new Float64Array(T),N=new Int32Array(T),P=new Uint8Array(T).fill(1),F=n.ops.map(()=>new Int8Array(T)))},L=(n,r,i={})=>({ruleId:e.id,ruleVersion:e.version,target:t,kind:n,t:r,...i}),R=()=>{_.fill(NaN),v.fill(NaN),y.fill(NaN);for(let e of b)e.head=0,e.len=0,e.sum=0};function z(n){let r=[];if(!e.enabled||!s)return r;let i=new Set(n),a=o.map(e=>C7(e,t).column),f=o.map((e,t)=>a[t]!==null&&i.has(a[t])?null:`formula`in e?e.formula:e.channel).filter(e=>e!==null),p=l;return c=a,u=[...new Set(f)],l=u.length===0,p&&!l&&((d===`active`||d===`clearing`)&&r.push(L(`lost`,m)),d=`idle`,g=null,R()),r}function B(e,t){for(let r=0;r<n.derived.length;r++){let{i,d:a,src:o}=n.derived[r],s=x[o[0]],c=C[o[0]],l=E[i],u=D[i],d=O[i],f=k[i],p=n.needPrev[i],m=_[i],h=v[i],g=y[i];if(a.op===`abs`||a.op===`diff`){let n=a.op===`diff`,r=n?x[o[1]]:s,b=n?C[o[1]]:c;if((c===P||b===P)&&!p){if(n)for(let t=0;t<e;t++)l[t]=s[t]-r[t];else for(let t=0;t<e;t++)l[t]=Math.abs(s[t]);y[i]=e>=2?l[e-2]:_[i],_[i]=l[e-1],v[i]=t[e-1],x[i]=l,S[i]=t,C[i]=P,w[i]=f;continue}for(let i=0;i<e;i++)c[i]||n&&b[i]?(g=m,m=n?s[i]-r[i]:Math.abs(s[i]),h=t[i],d[i]=1):d[i]=0,l[i]=m,u[i]=h,p&&(f[i]=g)}else{let o=b[r],T=a.windowS;if(a.op===`min`||a.op===`max`){let n=a.op===`max`;for(let r=0;r<e;r++){let e=t[r],i=e-T,a=s[r],_=c[r]===1&&a-a===0;if(_){for(;o.len&&(n?o.x[o.head+o.len-1&o.mask]<=a:o.x[o.head+o.len-1&o.mask]>=a);)o.len--;j7(o,e,a)}for(;o.len&&o.t[o.head]<i;)o.head=o.head+1&o.mask,o.len--;if(_){let t=o.x[o.head];g=m,m=t,t===t&&(h=e),d[r]=1}else d[r]=0;l[r]=m,u[r]=h,p&&(f[r]=g)}}else{let r=a.op===`mean`,b=o.len;A.length<b+e&&(A=new Float64Array(2*(b+e)),j=new Float64Array(2*(b+e)));for(let e=0;e<b;e++){let t=o.head+e&o.mask;A[e]=o.t[t],j[e]=o.x[t]}let E=0,D=b,O=o.sum,k=c===P;for(let t=0;k&&t<e;t++)k=s[t]-s[t]===0;if(k&&!p&&!n.needAt[i]){for(let n=0;n<e;n++){let e=t[n],i=s[n],a=e-T;if(A[D]=e,j[D]=i,D++,r)for(O+=i;A[E]<a;)O-=j[E],E++;else for(;A[E]<a;)E++;l[n]=m=r?O/(D-E):D-E>=2&&e>A[E]?(i-j[E])/(e-A[E]):NaN}g=e>=2?l[e-2]:_[i];for(let n=e-1;n>=0;n--)if(l[n]===l[n]){h=t[n];break}o.head=0,o.len=0,A7(o,A,j,E,D),o.sum=O,_[i]=m,v[i]=h,y[i]=g,x[i]=l,S[i]=t,C[i]=P,w[i]=f;continue}for(let n=0;n<e;n++){let e=s[n];if(c[n]===1&&e-e===0){let i=t[n],a=i-T;if(A[D]=i,j[D]=e,D++,r)for(O+=e;A[E]<a;)O-=j[E],E++;else for(;A[E]<a;)E++;let o=r?O/(D-E):D-E>=2&&i>A[E]?(e-j[E])/(i-A[E]):NaN;g=m,m=o,o===o&&(h=i),d[n]=1}else d[n]=0;l[n]=m,u[n]=h,p&&(f[n]=g)}o.head=0,o.len=0,A7(o,A,j,E,D),o.sum=O}}_[i]=m,v[i]=h,y[i]=g,x[i]=l,S[i]=u,C[i]=d,w[i]=f}}function V(e,t){let r=a!==1/0;for(let i=0;i<n.ops.length;i++){let o=n.ops[i];if(o.k===`all`||o.k===`any`){let t=F[i],n=o.k===`all`,r=o.rest,a=0;for(o.fused||(t.set(F[r[0]].subarray(0,e)),a=1);a<r.length;a++){let i=F[r[a]];if(n)for(let n=0;n<e;n++)i[n]<t[n]&&(t[n]=i[n]);else for(let n=0;n<e;n++)i[n]>t[n]&&(t[n]=i[n])}continue}if(o.k===`not`){let t=F[i],n=F[o.kid];for(let r=0;r<e;r++)t[r]=O7-n[r];continue}let s=o,c=x[s.i],l=S[s.i],u=F[s.into],d=s.mode,f=s.prev;switch(o.k){case`noData`:{let n=o.f;for(let r=0;r<e;r++){let e=l[r]===l[r]?t[r]-l[r]>=n?O7:0:D7;(d===0||(d===2?e>u[r]:e<u[r]))&&(u[r]=e)}break}case`above`:{let n=o.v,i=n-o.h;for(let o=0;o<e;o++){let e=c[o],s;e!==e||r&&t[o]-l[o]>=a&&l[o]!==t[o]?s=D7:(e>n?f=O7:e<=i&&(f=0),s=f),(d===0||(d===2?s>u[o]:s<u[o]))&&(u[o]=s)}break}case`below`:{let n=o.v,i=n+o.h;for(let o=0;o<e;o++){let e=c[o],s;e!==e||r&&t[o]-l[o]>=a&&l[o]!==t[o]?s=D7:(e<n?f=O7:e>=i&&(f=0),s=f),(d===0||(d===2?s>u[o]:s<u[o]))&&(u[o]=s)}break}case`outside`:{let n=o.lo,i=o.hi,s=n+o.h,p=i-o.h;for(let o=0;o<e;o++){let e=c[o],m;e!==e||r&&t[o]-l[o]>=a&&l[o]!==t[o]?m=D7:(e<n||e>i?f=O7:e>=s&&e<=p&&(f=0),m=f),(d===0||(d===2?m>u[o]:m<u[o]))&&(u[o]=m)}break}case`inside`:{let n=o.lo,i=o.hi,s=n-o.h,p=i+o.h;for(let o=0;o<e;o++){let e=c[o],m;e!==e||r&&t[o]-l[o]>=a&&l[o]!==t[o]?m=D7:(e>=n&&e<=i?f=O7:(e<s||e>p)&&(f=0),m=f),(d===0||(d===2?m>u[o]:m<u[o]))&&(u[o]=m)}break}case`equals`:{let n=o.v;for(let i=0;i<e;i++){let e=c[i],o;o=e!==e||r&&t[i]-l[i]>=a&&l[i]!==t[i]?D7:e===n?O7:0,(d===0||(d===2?o>u[i]:o<u[i]))&&(u[i]=o)}break}case`changes`:{let n=C[o.i],i=w[o.i];for(let o=0;o<e;o++){let e=c[o],s;if(e!==e||r&&t[o]-l[o]>=a&&l[o]!==t[o])s=D7;else{let t=i[o];s=t===t?n[o]&&e!==t?O7:0:D7}(d===0||(d===2?s>u[o]:s<u[o]))&&(u[o]=s)}break}}o.prev=f}return F[n.ops.length-1]}function ee(t,r,i,a){let o=n.first,s=o?x[o.i]:null;for(let n=0;n<t;n++){let t=i[n];if(d===`idle`){if(t!==O7)continue;d=`pending`,f=r[n],g=null}if(s){let e=s[n];if(e===e){let t=o.excess(e);t>0&&(g===null||t>o.excess(g.v))&&(g={v:e,t:r[n]})}}if(t===D7)continue;let c=r[n];if(d===`pending`){if(t===0){d=`idle`,g=null;continue}c-f>=e.forS&&(d=`active`,a.push(L(`raised`,f)));continue}if(d===`active`){if(t===O7)continue;d=`clearing`,p=c}else if(t===O7){d=`active`;continue}c-p>=e.clearForS&&(d=`idle`,a.push(L(`cleared`,p,g?{peak:g}:{})),g=null)}}function H(t){let r=[];if(!e.enabled||!s||!l)return r;let a=t.t,o=a.length;if(!o)return r;I(o);let u=null,d=c.map(e=>e!==null&&t.columns[e]||(u??=new Float64Array(o).fill(NaN))),f=d.map((e,n)=>E7(t,c[n],e)),p=a[0]>m&&a[o-1]<1/0&&T7(t)&&f.some(Boolean),g,b;if(p)g=o,b=a,m=a[o-1];else{g=0;for(let e=0;e<o;e++){let t=!1;for(let n=0;n<i;n++)if(d[n][e]===d[n][e]){t=!0;break}if(!t)continue;let n=a[e];if(n<=m||n-n!==0){h++;continue}N[g]=e,M[g]=n,g++,m=n}if(!g)return r;b=M}for(let e=0;e<i;e++){let t=d[e],r=n.needPrev[e];if(p&&f[e]){if(r){let n=k[e];n[0]=_[e];for(let e=1;e<g;e++)n[e]=t[e-1];w[e]=n}y[e]=g>=2?t[g-2]:_[e],_[e]=t[g-1],v[e]=a[g-1],x[e]=t,S[e]=a,C[e]=P;continue}let i=E[e],o=D[e],s=O[e],c=k[e],l=_[e],u=v[e],m=y[e];for(let e=0;e<g;e++){let n=t[p?e:N[e]];n===n?(m=l,l=n,u=b[e],s[e]=1):s[e]=0,i[e]=l,o[e]=u,r&&(c[e]=m)}_[e]=l,v[e]=u,y[e]=m,x[e]=i,S[e]=o,C[e]=s,w[e]=c}return B(g,b),ee(g,b,V(g,b),r),r}function U(t){let n=[];if(!e.enabled||!s||!l||t<=m)return n;I(1);for(let e=0;e<r;e++)E[e][0]=_[e],D[e][0]=v[e],O[e][0]=0,k[e][0]=y[e],x[e]=E[e],S[e]=D[e],C[e]=O[e],w[e]=k[e];return M[0]=t,ee(1,M,V(1,M),n),n}function te(){let t=e.enabled?s?l?d:`waiting`:`not_applicable`:`disabled`;return{state:t,...t===`waiting`?{missing:u}:{},...d!==`idle`&&l?{since:d===`clearing`?p:f}:{},late:h,lastT:m}}return z([]),{rule:e,target:t,bind:z,push:H,tick:U,state:te}}function T7(e){let t=e.scan?.get(S7);if(t===void 0){let n=e.t;t=!0;for(let e=1;e<n.length;e++)if(!(n[e]>n[e-1])){t=!1;break}e.scan?.set(S7,t)}return t}function E7(e,t,n){let r=t===null?void 0:e.scan?.get(t);if(r===void 0){r=!0;for(let e=0;e<n.length;e++)if(n[e]!==n[e]){r=!1;break}t!==null&&e.scan?.set(t,r)}return r}var D7=1,O7=2,k7=()=>({t:new Float64Array(16),x:new Float64Array(16),head:0,len:0,mask:15,sum:0});function A7(e,t,n,r,i){let a=i-r;if(a<=0)return;if(e.len+a>e.mask+1){let t=e.mask+1;for(;t<e.len+a;)t*=2;let n=new Float64Array(t),r=new Float64Array(t);for(let t=0;t<e.len;t++)n[t]=e.t[e.head+t&e.mask],r[t]=e.x[e.head+t&e.mask];e.t=n,e.x=r,e.head=0,e.mask=t-1}let o=e.head+e.len&e.mask,s=Math.min(a,e.mask+1-o);e.t.set(t.subarray(r,r+s),o),e.x.set(n.subarray(r,r+s),o),s<a&&(e.t.set(t.subarray(r+s,i),0),e.x.set(n.subarray(r+s,i),0)),e.len+=a}function j7(e,t,n){if(e.len===e.mask+1){let t=e.len*2,n=new Float64Array(t),r=new Float64Array(t);for(let t=0;t<e.len;t++)n[t]=e.t[e.head+t&e.mask],r[t]=e.x[e.head+t&e.mask];e.t=n,e.x=r,e.head=0,e.mask=t-1}let r=e.head+e.len&e.mask;e.t[r]=t,e.x[r]=n,e.len++}var M7=[`above`,`below`,`outside`,`inside`,`equals`,`changes`,`noData`],N7=/^[A-Za-z_][A-Za-z0-9_]{0,31}$/,P7=[`info`,`warning`,`critical`],F7=[`browser`,`collector`],I7=e=>typeof e==`number`&&Number.isFinite(e),L7=e=>I7(e)&&e>=0&&e<=86400;function R7(e){let t=[],n=(e,n)=>{t.push({code:e,path:n})};if(!e||typeof e!=`object`)return[{code:`not_a_rule`,path:``}];let r=e;r.kyr!==1&&n(`unsupported_version`,`kyr`),(typeof r.id!=`string`||!r.id)&&n(`bad_id`,`id`),(!Number.isInteger(r.version)||r.version<1)&&n(`bad_version`,`version`),(typeof r.name!=`string`||!r.name.trim()||r.name.length>120)&&n(`bad_name`,`name`),P7.includes(r.severity)||n(`bad_severity`,`severity`);for(let e of[`forS`,`clearForS`])L7(r[e])||n(`bad_duration`,e);r.staleS!=null&&!L7(r.staleS)&&n(`bad_duration`,`staleS`),(!Array.isArray(r.runWhere)||!r.runWhere.length||!r.runWhere.every(e=>F7.includes(e)))&&n(`bad_run_where`,`runWhere`);let i=new Map,a=r.signals&&typeof r.signals==`object`?r.signals:{};Object.keys(a).length||n(`no_signals`,`signals`);for(let[e,t]of Object.entries(a)){N7.test(e)||n(`bad_alias`,`signals.${e}`),i.set(e,`signal`);let a=t&&typeof t==`object`?t:{};`formula`in a?((typeof a.formula!=`string`||!a.formula)&&n(`bad_channel`,`signals.${e}`),Array.isArray(r.runWhere)&&r.runWhere.length===1&&r.runWhere[0]===`browser`||n(`formula_browser_only`,`signals.${e}`)):(typeof a.channel!=`string`||!a.channel||a.channel.length>200)&&n(`bad_channel`,`signals.${e}`)}let o=r.derived&&typeof r.derived==`object`?r.derived:{};for(let e of Object.keys(o))N7.test(e)||n(`bad_alias`,`derived.${e}`),i.has(e)&&n(`duplicate_alias`,`derived.${e}`),i.set(e,`derived`);let s=e=>e.op===`diff`?[e.a,e.b]:[e.of],c=new Set;for(let[e,t]of Object.entries(o)){let r=t&&typeof t==`object`?t:{};if(![`rate`,`mean`,`min`,`max`,`abs`,`diff`].includes(r.op)){n(`bad_derived`,`derived.${e}`);continue}c.add(e),[`rate`,`mean`,`min`,`max`].includes(r.op)&&!(L7(r.windowS)&&r.windowS>0)&&n(`bad_duration`,`derived.${e}.windowS`);for(let t of s(r))(typeof t!=`string`||!i.has(t))&&n(`unknown_alias`,`derived.${e}`)}let l=new Set,u=new Set,d=e=>{if(u.has(e)||i.get(e)!==`derived`||!c.has(e))return!0;if(l.has(e))return!1;l.add(e);let t=s(o[e]).every(e=>typeof e!=`string`||d(e));return l.delete(e),u.add(e),t};for(let e of Object.keys(o))if(!d(e)){n(`derived_cycle`,`derived.${e}`);break}let f=0,p=(e,t,r)=>{if(!e||typeof e!=`object`)return n(`bad_condition`,t);let a=e;for(let e of[`all`,`any`])if(e in a)return r>=3?n(`too_deep`,t):!Array.isArray(a[e])||!a[e].length?n(`bad_condition`,t):a[e].forEach((n,i)=>p(n,`${t}.${e}[${i}]`,r+1));if(`not`in a)return r>=3?n(`too_deep`,t):p(a.not,`${t}.not`,r+1);let o=M7.find(e=>e in a);if(!o)return n(`unsupported_condition`,t);f++,(typeof a[o]!=`string`||!i.has(a[o]))&&n(`unknown_alias`,t),a.hysteresis!=null&&!(I7(a.hysteresis)&&a.hysteresis>=0)&&n(`bad_hysteresis`,t),(o===`above`||o===`below`||o===`equals`)&&!I7(a.value)&&n(`bad_value`,t),(o===`outside`||o===`inside`)&&!(I7(a.lo)&&I7(a.hi)&&a.lo<a.hi)&&n(`bad_band`,t),o===`noData`&&!L7(a.forS)&&n(`bad_duration`,`${t}.forS`)};return p(r.when,`when`,0),f>16&&n(`too_many_leaves`,`when`),t}gK();var z7=500,B7=1<<20;function V7(e){let t=[],n=new Map,r=new Map,i=[],a=``,o=(e,t)=>`${e}|${t}`,s=(e,t)=>{let n=t.kind===`stream`?e.targets?.streams:t.kind===`history`?e.targets?.histories:e.targets?.datasets;return!n||n.includes(t.kind===`dataset`?t.name??t.id:t.id)},c=()=>[...n.values()].map(e=>{let{state:t,missing:n,since:r}=e.state();return{ruleId:e.rule.id,target:e.target,state:t,...n?{missing:n}:{},...r===void 0?{}:{since:r}}}),l=()=>{let t=c(),n=JSON.stringify(t);n!==a&&(a=n,e.setStates(t))};function u(n,r,a=!1){let o=t.find(e=>e.id===n.ruleId);if(n.kind===`raised`){i=[...i,{id:`${n.ruleId}|${n.target.id}|${n.t}${a?`|late`:``}`,ruleId:n.ruleId,ruleName:o?.name??``,severity:o?.severity??`info`,targetId:n.target.id,timeColumn:r,t0:n.t,t1:null,...a?{late:!0}:{}}];let e=i.filter(e=>e.targetId===n.target.id);e.length>z7&&(i=i.filter(t=>t!==e[0]))}else{let e=i.find(e=>e.ruleId===n.ruleId&&e.targetId===n.target.id&&e.t1===null&&!!e.late===a);e&&(i=i.map(t=>t===e?{...t,t1:n.t}:t))}e.setMarks(i),e.emit(a?{...n,late:!0}:n)}function d(){let i=new Set;for(let r of e.targets())for(let e of t){if(!s(e,r))continue;let t=o(e.id,r.id);i.add(t);let a=n.get(t),{channels:c,...l}=r;(!a||a.rule!==e)&&(a=w7(e,l),n.set(t,a));for(let e of a.bind(c))u(e,r.kind===`stream`?dK:``)}for(let e of n.keys())i.has(e)||n.delete(e);for(let[e,t]of r)n.get(e)?.rule!==t.rule&&r.delete(e);l()}return{setRules(n){let r=[],i=n.filter(e=>{let t=R7(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}),d(),r},rules:()=>t,state:c,async evaluate(n,r){let a=e.targets().find(e=>e.id===n&&e.kind===`dataset`);if(!a)return[];let{channels:o,...c}=a,l=[],d=t.filter(e=>(!r.ruleIds||r.ruleIds.includes(e.id))&&s(e,c)),f=d.map(e=>{let t=w7(e,c);return t.bind(o),t}),p=[...new Set(d.flatMap(e=>Object.values(e.signals).map(e=>`formula`in e?e.formula:e.channel)))];for(let t=0;;t+=B7){let i=await e.readDataset(n,[r.timeColumn,...p],t,B7),a=i[r.timeColumn];if(!a||!a.length)break;for(let e of f)l.push(...e.push({t:a,columns:i}));if(a.length<B7)break}i=i.filter(e=>!(e.targetId===n&&(!r.ruleIds||r.ruleIds.includes(e.ruleId)))),e.setMarks(i);for(let e of l)u(e,r.timeColumn);return l},pushLive(e,t){let r=!1;for(let i of n.values()){if(i.target.id!==e)continue;let n=i.push(t);n.length&&(r=!0);for(let e of n)u(e,dK)}r&&l()},pushLate(t,i){let a=e.targets().find(e=>e.id===t&&e.kind===`stream`);if(!a)return;let{channels:o,...s}=a;for(let[e,a]of n){if(a.target.id!==t)continue;let n=r.get(e);(!n||n.rule!==a.rule)&&(n=w7(a.rule,s),n.bind(o),r.set(e,n));for(let e of n.push(i))u(e,dK,!0)}},tickLive(e,t){let r=!1;for(let i of n.values()){if(i.target.id!==e)continue;let n=i.tick(t);n.length&&(r=!0);for(let e of n)u(e,dK)}r&&l()},liveColumns(e){let t=new Set;for(let r of n.values())if(r.target.id===e)for(let e of Object.values(r.rule.signals))t.add(`formula`in e?e.formula:e.channel);return[...t]},sync:d,clearMarks(t){i=t?i.filter(e=>e.targetId!==t):[],e.setMarks(i)}}}function H7(e){let t=e.when;for(;t&&typeof t==`object`;)if(`all`in t)t=t.all[0];else if(`any`in t)t=t.any[0];else if(`not`in t)return null;else break;return t?`above`in t||`below`in t?Number.isFinite(t.value)?t.value:null:`outside`in t&&Number.isFinite(t.hi)?t.hi:null:null}var U7=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}},W7={maxChartsPerWorksheet:null,maxChannelsPerChart:null,maxWorksheets:null,maxMathChannels:null,maxAlertRules:null,canImportExportWorkspaces:!0};xE(),gK();var G7=[];function K7(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 q7=[`#a78bfa`,`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#94a3b8`];function J7(e=`ET`){return{id:crypto.randomUUID(),name:`Worksheet`,panels:[],panelChartSettings:{},panelChartBackgrounds:{},xKey:e}}function Y7(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(We({...e,name:a,source:`workbook`}))}return{channels:i,rename:r}}function X7(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 Z7(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 Q7(e,t,n){if(!e||!t)return N();let{min:r,max:i}=cJ(e.rows,t);if(!Number.isFinite(r)||!Number.isFinite(i))return N();let a=uJ(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 $7(e,t){let n=t.includes(e.xKey)?e.xKey:t.includes(`ET`)?`ET`:t.includes(`ElapsedTime`)?dK: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:H();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:U(q7[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:te(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 e9(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 t9(){return typeof document>`u`?`dark`:RJ(null)}function n9(e={}){let t={...e},n=!1,r=J7(),i=b5({datasets:[],selection:[],worksheets:[r],activeWorksheetId:r.id,xRanges:{},offsets:{},colors:{},liveWindowSeconds:15,cycleRules:[],live:[],video:[],mathChannels:[],limits:{...W7,...t.limits},palette:FJ(t.palette,t9()),importing:0,licensed:null,history:{canUndo:!1,canRedo:!1},marks:[],alerts:[],alertRules:[]}),a=KY(),o=()=>{let e=FJ(t.palette,t9());i.set(t=>t.palette.join()===e.join()?t:{...t,palette:e})},s=typeof document>`u`?()=>{}:zJ(null,o),c=S5(),l=()=>{if(n)throw new SE(`disposed`)},u=e=>{throw a.emit(`limit`,{reason:e}),new SE(`limit_reached`,{reason:e})},d=()=>i.get(),f=(e,t)=>{let n=d().limits.maxChannelsPerChart,r=lJ(t);n!==null&&r>n&&r>lJ(e)&&u(`channels-per-chart`)},p=x5((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??G7,layout:t.rect,window:t.window??null}),g=x5((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))}))),_=x5((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:NJ(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:NJ(n,i.id,s(i.id,a),o),offset:r[i.id]??0,selected:t.includes(i.id),...e.cut?{cycle:K7(e.cut,a)}:{}})):null,selected:c?u===0?!1:u===l.length?!0:`partial`:t.includes(e.id)}})}),b=x5((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:NJ(n,e.id,a.includes(e.id)?r+a.indexOf(e.id):o,i),customColor:e.id in n,recordingSince:e.recordingSince,limitNotice:e.limitNotice??null,...e.integrity?{integrity:e.integrity}:{},channels:e.dataset.columnNames}))}),x=x5(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:b(e.live,e.selection,e.colors,t.selectedDatasets.length,e.palette),liveWindowSeconds:(()=>{let t=e.worksheets.find(t=>t.id===e.activeWorksheetId);return t?.liveWindowSeconds===void 0?e.liveWindowSeconds:t.liveWindowSeconds})(),cycleRules:e.cycleRules,limits:e.limits,palette:e.palette,importing:e.importing,licensed:e.licensed,hasData:t.merged!==null,multiDataset:t.selectedDatasets.length+t.selectedLive.length>1,numericColumns:t.numericColumns,allColumns:t.allColumns,columnUnits:t.columnUnits,history:e.history,marks:e.marks,alerts:e.alerts}}),S=(e,t)=>e===t||e.length===t.length&&e.every((e,n)=>e===t[n]||JSON.stringify(e)===JSON.stringify(t[n])),C=new U7({limit:100,mergeMs:500,now:()=>Date.now(),equals:(e,t)=>e.liveWindowSeconds===t.liveWindowSeconds&&S(e.worksheets,t.worksheets)&&S(e.channels,t.channels)}),w=!0,T=0,E=e=>{T++;try{e()}finally{T--}},D=e=>[e.worksheets,e.mathChannels,e.liveWindowSeconds],O=[],k=()=>{let e=d();return{worksheets:e.worksheets,channels:e.mathChannels.filter(e=>e.source===`workbook`),liveWindowSeconds:e.liveWindowSeconds,activeWorksheetId:e.activeWorksheetId}},j=()=>i.set(e=>e.history.canUndo===C.canUndo&&e.history.canRedo===C.canRedo?e:{...e,history:{canUndo:C.canUndo,canRedo:C.canRedo}}),N=()=>{if(w)return;let e=D(d());e.every((e,t)=>e===O[t])||(O=e,T?C.rebase(k()):C.observe(k()),j())},P=()=>{O=D(d()),C.clear(k()),j()},F=e=>{w=!0;let t;try{t=e()}finally{w=!1}return P(),t},I=()=>x(d());i.subscribe(()=>{N(),a.emit(`change`,I())});let L=e=>{let t=d(),n=t.worksheets.find(n=>n.id===(e??t.activeWorksheetId));if(!n)throw new SE(`not_found`,{worksheetId:e});return n},R=e=>{for(let t of d().worksheets){let n=t.panels.find(t=>t.id===e);if(n)return{ws:t,panel:n}}throw new SE(`not_found`,{chartId:e})},z=(e,t)=>{let n=e=>e&&t?e.left===t.left&&e.top===t.top&&e.width===t.width&&e.height===t.height:!e&&!t,r=d().worksheets.find(t=>t.panels.some(t=>t.id===e&&!n(t.window)));r&&E(()=>B(r.id,n=>({...n,panels:n.panels.map(n=>{if(n.id!==e)return n;if(t)return{...n,window:{...t}};let{window:r,...i}=n;return i})})))},B=(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}),V=(e,t)=>{let{ws:n}=R(e);B(n.id,n=>({...n,panelChartSettings:{...n.panelChartSettings,[e]:t(n.panelChartSettings[e])}}))},ee=e=>i.set(t=>e.length===t.selection.length&&e.every((e,n)=>e===t.selection[n])?t:{...t,selection:e,xRanges:{}}),H=new Set,U=y7(t.live?.relay,e=>{let t=e.map(e=>e.id),n=e.filter(e=>e.kind===`data`&&!H.has(e.id)).map(e=>e.id),r=[...H].filter(e=>!t.includes(e));if(H=new Set(t),i.set(t=>({...t,live:e})),r.length&&ee(d().selection.filter(e=>!r.includes(e))),n.length){let e=d().selection,t=n.filter(t=>!e.includes(t));t.length&&ee([...e,...t])}let a=m();if(a.selectedLive.length&&a.merged){let e=a.merged.columnNames;if(e.includes(`ElapsedTime`))for(let t of d().worksheets)e.includes(t.xKey)||E(()=>B(t.id,e=>({...e,xKey:dK})))}},()=>({capacity:t.live?.capacity,maxMemoryMB:t.live?.maxMemoryMB}),{rows:(e,t,n)=>{if(!ce.rules().length)return;t.columnNames.length!==te.get(e)&&(te.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(dK,a,i),columns:o,scan:new Map})},historical:(e,t)=>{if(!ce.rules().length||!t.t.length)return;let n={};for(let r of ce.liveColumns(e)){let e=t.columns[r];e&&(n[r]=e instanceof Float64Array?e:Float64Array.from(e))}Object.keys(n).length&&ce.pushLate(e,{t:t.t instanceof Float64Array?t.t:Float64Array.from(t.t),columns:n,scan:new Map})},tick:(e,t,n)=>{if(!ce.rules().length)return;let r=t.range(dK,t.endAbs-1,t.endAbs)[0];r===r&&ce.tickLive(e,r+(Date.now()-n)/1e3)}}),te=new Map,W=x5((e,t)=>e.filter(e=>t.some(t=>fw([e],t.panelChartSettings,t.xKey).length>0))),ne=()=>U.setMathChannels(W(p(d().mathChannels,d().limits.maxMathChannels),d().worksheets));ne(),i.subscribe(ne);let G=e=>{i.set(t=>({...t,datasets:[...t.datasets,e]})),ee([...d().selection,e.id]);let t=sJ(e.schema);t.length&&E(()=>i.set(e=>({...e,worksheets:e.worksheets.map(e=>$7(e,t))})))},re=Promise.resolve(),ie=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 SE(`import_vetoed`);let{signal:s}=r;i.set(e=>({...e,importing:e.importing+o.length}));let c=re.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 ez(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 oJ({main:t,companions:i.companions,format:i.format.id},{priorInMemoryValues:bR(d().datasets),signal:s,onProgress:e=>a.emit(`import`,{file:t.name,phase:`progress`,fraction:e}),chooseChannels:r.chooseChannels,pickChannels:r.pickChannels}):[await yR(crypto.randomUUID(),t,d().datasets)??await _R(crypto.randomUUID(),t,Z7,void 0,bR(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 SE(`cancelled`)}for(let t of o)G(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 SE&&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 re=c.catch(()=>void 0),c},ae=()=>setTimeout(()=>{n||R8(it)},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}}),ee(d().selection.filter(e=>!t(e))),n.length>0&&ae()},se=async(e,t,n={})=>{let[r,...i]=await oJ({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=V7({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=x5((e,t)=>{let n=new Map;for(let r of e){let e=H7(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:ie,warmImport(e={}){l(),Jq(!!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 SE(`not_found`,{datasetId:e});if(!t.info?.combined||!(t.file instanceof File))throw new SE(`invalid_argument`,{reason:`only a combined multi-rate import can be split`});let n=await oJ({main:t.file,companions:t.companions??[],format:t.info.importer},{priorInMemoryValues:bR(d().datasets.filter(t=>t.id!==e)),selection:t.info.selection,split:!0});oe([e]);for(let e of n)G(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 SE(`not_found`,{datasetId:e});if(!n.info||!(n.file instanceof File))throw new SE(`invalid_argument`,{reason:`only binary imports have channels to choose`});try{let r=await oJ({main:n.file,companions:n.companions??[],format:n.info.importer},{priorInMemoryValues:bR(d().datasets.filter(t=>t.id!==e)),initial:n.info.selection,chooseChannels:t,pickChannels:!0});oe([e]);for(let e of r)G(e);return r.map(e=>e.id)}catch(e){if(e instanceof SE&&e.code===`cancelled`)return null;throw e}},async combine(e){l();let t=d().datasets.find(t=>t.id===e);if(!t)throw new SE(`not_found`,{datasetId:e});let n=t.info?.splitKey;if(!n||!(t.file instanceof File))throw new SE(`invalid_argument`,{reason:`only datasets split from one file can be combined`});let r=d().datasets.filter(e=>e.info?.splitKey===n),i=await oJ({main:t.file,companions:t.companions??[],format:t.info.importer},{priorInMemoryValues:bR(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 SE(`invalid_argument`,{reason:`these groups have no common time base`})}return oe(r.map(e=>e.id)),G(i[0]),i[0].id},async openRecording(e,t={}){l();let n=await se(e,bR(d().datasets),t);return G(n),n.id},async reopenRecording(e,t){l();let n=d().datasets.find(t=>t.id===e);if(!n)throw new SE(`not_found`,{datasetId:e});let r=await se(t,bR(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()},addColumns(e){l();let t=p5(crypto.randomUUID(),e);return G(t),t.id},replaceColumns(e,t,n={}){l();let r=d().datasets.find(t=>t.id===e);if(!r)throw new SE(`not_found`,{datasetId:e});let a=_5(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 SE(`not_found`,{datasetId:e});let a=h5(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 mR(crypto.randomUUID(),t,e);return G(n),n.id},async findCycles(e,t,n){l();let r=d().datasets.find(t=>t.id===e);if(!r)throw new SE(`not_found`,{datasetId:e});let i=await Jw(r.source,n,Xw(t)),a=new Map(t.filter(e=>e.kpis?.length).map(e=>[e.id,e.kpis]));return Yw(i,t).map(e=>a.has(e.definitionId)?{...e,kpis:Qw(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 SE(`not_found`,{datasetId:e});let r=n.schema.filter(e=>e.type===`number`&&e.name!==t.timeKey).map(e=>e.name),i=await Jw(n.source,t.timeKey,r),a={...Object.fromEntries(n.schema.map(e=>[e.name,e.unit])),[Kw]:`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 SE(`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:eT(i,t.timeKey,r),units:a}))}if(t.tables!==!1){let e=nT(t.found,t.cycleId,t.defs,i);s.push(await de.addText(rT(e.cycles),`${n.name} · ${o(t.cycleId)}s.csv`)),e.phases.length&&s.push(await de.addText(rT(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 SE(`not_found`,{datasetId:e});let r;if(t){if(!t.defs.some(e=>e.id===t.cycleId))throw new SE(`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 Jw(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=Yw(a,t.defs).sort((e,t)=>e.tstart-t.tstart||!!e.parentIndex-+!!t.parentIndex).map(e=>c.has(e.definitionId)?{...e,kpis:Qw(a,e,c.get(e.definitionId))}:e),u={...Object.fromEntries(n.schema.map(e=>[e.name,e.unit])),[Kw]:`s`},d=e=>t.defs.find(t=>t.id===e)?.name??e,f=l.map(r=>p5(`${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:eT(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 ee(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 SE(`not_found`,{datasetId:e});if(t.parseConfig&&(n.kind!==`memory`||!n.parseConfig))throw new SE(`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 SE(`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?VJ(n.data.rows,r.channel):[],l=r&&t.selectCycles===`best`?UJ(c.map(e=>HJ(n.data.rows,e,r.metric,r.stat))):null,u=l===null?c.map((t,n)=>GJ(e,n)):[GJ(e,l)];ee(o?c.length>0?[...s,...u]:[...s,e]:s)}let r=t.parseConfig;if(!r)return;let a=(()=>{try{let e=lE(aE(n.rawText??``),r.headerRow);return n.data.columnNames.length===e.length&&n.data.columnNames.every((t,n)=>t===e[n])}catch{return!1}})();if(oE(r,n.parseConfig)&&a)return;let o=n.fromColumns?y5(n):n.rawText??``,s=await DE(n.file?{file:n.file,config:r}:{rawText:o,config:r}),c=new VE(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=>mE(s.rows,e)),_=g.find(e=>e===`ET`)??g[0];E(()=>i.set(e=>({...e,worksheets:e.worksheets.map(e=>e9(!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(),ee([...e])},toggle(e){l();let t=d().selection,n=m().laps[e];if(n){let e=n.laps.map(e=>e.id);ee(e.every(e=>t.includes(e))?t.filter(t=>!e.includes(t)):[...t,...e.filter(e=>!t.includes(e))]);return}ee(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);ee([...d().datasets.flatMap(t=>e[t.id]?e[t.id].laps.map(e=>e.id):[t.id]),...t])},deselectAll(){l(),ee([])},raw(e){let t=d().datasets.find(t=>t.id===e);if(!t)throw new SE(`not_found`,{datasetId:e});return{get rawText(){return t.kind===`memory`&&t.fromColumns?y5(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=cJ(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=cJ(i.rows,e);return Number.isFinite(a.min)&&Number.isFinite(a.max)?a:null}},fe=(e,t=L().xKey)=>{let n=m();if(!n.merged)return null;if(!n.channels.find(t=>t.name===e))return n.merged;let r=dw(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:``}:Q7(fe(e,t),e,n),me={fromFileList:e=>SY(Array.from(e)),async fromDataTransfer(e){return CY(Array.from(e.items??[]).map(e=>e.webkitGetAsEntry?.()).filter(e=>!!e))},canPick:wY,pick:TY,tree:(e,t)=>xY(e,t),isImportable:bY},he={add(e=`Worksheet`){l();let t=d(),n=t.limits.maxWorksheets;n!==null&&t.worksheets.length>=n&&u(`worksheets`);let r={...J7(L().xKey||`ET`),name:e};return i.set(e=>({...e,worksheets:[...e.worksheets,r],activeWorksheetId:r.id})),r.id},rename(e,t){l(),L(e),B(e,e=>e.name===t?e:{...e,name:t})},remove(e){l();let t=d();if(L(e),t.worksheets.length<=1)throw new SE(`invalid_argument`,{reason:`the last worksheet cannot be removed`});let n=t.worksheets.findIndex(t=>t.id===e),r=t.worksheets.filter(t=>t.id!==e);i.set(t=>({...t,worksheets:r,activeWorksheetId:t.activeWorksheetId===e?r[Math.max(0,n-1)].id:t.activeWorksheetId}))},reorder(e,t){l(),i.set(n=>{if(e===t||e<0||t<0||e>=n.worksheets.length||t>=n.worksheets.length)return n;let r=[...n.worksheets],[i]=r.splice(e,1);return r.splice(t,0,i),{...n,worksheets:r}})},activate(e){l(),L(e),i.set(t=>t.activeWorksheetId===e?t:{...t,activeWorksheetId:e,xRanges:{...t.xRanges,[e]:null}})},setXKey(e,t){l(),L(e),B(e,e=>e9({...e,xKey:t},e=>e!==t)),i.set(t=>({...t,xRanges:{...t.xRanges,[e]:null},offsets:{}}))}},ge={mount(e,t,n){return l(),L8(it,e,t,n)},openWindow(e,t){l(),R(e);let n=R(e).panel.window;return s5(it,e,(t,n)=>L8(it,e,t,n),{...n,...t})},recordWindows(){l();let e=l5(it);for(let t of d().worksheets)for(let n of t.panels)z(n.id,e.get(n.id)??null)},setFonts(e){e.sans&&(X.sans=e.sans),e.mono&&(X.mono=e.mono),R8(it)},kinds:()=>C5,label:T5,add(e,t={}){if(l(),!C5.some(t=>t.kind===e))throw new SE(`invalid_argument`,{kind:e});let n=L(t.worksheetId),r=d().limits.maxChartsPerWorksheet;r!==null&&n.panels.length>=r&&u(`charts-per-worksheet`);let i={...A(e,n.panels),...t.title?{title:t.title}:{}};t.layout&&(i.rect={...t.layout});let a=Ve([i],{},q7[2],4)[i.id],o=a,s=m().numericColumns;if(s.length&&(o.kind===`multiband`||o.kind===`xyscatter`||o.kind===`xyzmesh`)&&(o=$7({...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),B(n.id,e=>({...e,panels:t.layout?[...e.panels,i]:M([...e.panels,i]),panelChartSettings:{...e.panelChartSettings,[i.id]:o}})),i.id},remove(e){l();let{ws:t}=R(e);B(t.id,t=>{let n={...t.panelChartSettings},r={...t.panelChartBackgrounds};return delete n[e],delete r[e],{...t,panels:M(t.panels.filter(t=>t.id!==e)),panelChartSettings:n,panelChartBackgrounds:r}})},rename(e,t){l();let{ws:n}=R(e),r=t?.trim()||void 0;B(n.id,t=>({...t,panels:t.panels.map(t=>{if(t.id!==e)return t;let{title:n,...i}=t;return r?{...i,title:r}:i})}))},update(e,t){l();let{ws:n}=R(e),r=n.panelChartSettings[e],i={...r,...t,kind:r.kind};if(r.kind===`xyscatter`&&i.kind===`xyscatter`){let e=t;typeof e.xyXCol==`string`&&e.xyXCol!==r.xyXCol&&!(`xyXScale`in e)&&(i={...i,xyXScale: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),V(e,()=>i)},replaceSettings(e,t){l();let{ws:n,panel:r}=R(e);if(t.kind!==r.kind)throw new SE(`invalid_argument`,{reason:`settings kind mismatch`});f(n.panelChartSettings[e],t),V(e,()=>t)},setBackground(e,t){l();let{ws:n}=R(e);B(n.id,n=>({...n,panelChartBackgrounds:{...n.panelChartBackgrounds,[e]:t}}))},addAnnotation(e,t){l(),R(e);let n=v({...t,id:t.id||crypto.randomUUID()});if(!n)throw new SE(`invalid_argument`,{reason:`not a valid annotation`});return V(e,e=>({...e,annotations:[...(e.annotations??[]).filter(e=>e.id!==n.id),n]})),n.id},updateAnnotation(e,t,n){l();let r=(R(e).ws.panelChartSettings[e]?.annotations??[]).find(e=>e.id===t);if(!r)throw new SE(`not_found`,{annotationId:t});let i=v({...r,...n,id:r.id,kind:r.kind});if(!i)throw new SE(`invalid_argument`,{reason:`not a valid annotation`});V(e,e=>({...e,annotations:(e.annotations??[]).map(e=>e.id===i.id?i:e)}))},removeAnnotation(e,t){l(),R(e),V(e,e=>({...e,annotations:(e.annotations??[]).filter(e=>e.id!==t)}))},setAnnotations(e,t){l(),R(e);let n=y(t)??[];V(e,e=>({...e,annotations:n}))},setLayout(e,t){l();let{ws:n}=R(e);B(n.id,n=>({...n,panels:n.panels.map(n=>n.id===e?{...n,rect:{...t}}:n)}))},setLayouts(e,t){l(),B(e,e=>({...e,panels:e.panels.map(e=>t[e.id]?{...e,rect:{...t[e.id]}}:e)}))},autoLayout(e){l(),B(L(e).id,e=>({...e,panels:M(e.panels)}))},get(e){let{ws:t,panel:n}=R(e);return h(t,n)},list(e){let t=L(e);return t.panels.map(e=>h(t,e))},async addSeries(e,t){l();let{ws:n}=R(e),r=n.panelChartSettings[e];if(!r||r.kind!==`multiband`)throw new SE(`invalid_argument`,{reason:`not a multiband chart`});let i=d().limits.maxChannelsPerChart;i!==null&&lJ(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=Ue(),f={id:c,column:s,color:q7[r.series.length%q7.length],bandFromPct:0,bandToPct:100,scaleMin:0,scaleMax:1,yMajorStep:0,yMinorStep:0};return V(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}=R(e),i=r.panelChartSettings[e],a=i&&i.kind===`multiband`?i.series.find(e=>e.id===t):void 0;if(!a)throw new SE(`not_found`,{seriesId:t});V(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(),V(e,e=>e.kind===`multiband`?{...e,series:e.series.filter(e=>e.id!==t)}:e)},reorderSeries(e,t){l(),V(e,e=>{if(e.kind!==`multiband`)return e;let n=new Map(e.series.map(e=>[e.id,e])),r=t.map(e=>n.get(e)).filter(e=>!!e),i=e.series.filter(e=>!t.includes(e.id));return{...e,series:[...r,...i]}})},async autoScaleSeries(e,t){l();let{ws:r}=R(e),i=r.panelChartSettings[e],a=i&&i.kind===`multiband`?i.series.find(e=>e.id===t):void 0;if(!a)return;let o=await de.columnBounds(a.column);!o||n||V(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=L(t).id;i.set(t=>{let r=t.xRanges[n]??null;return r===e||r&&e&&r[0]===e[0]&&r[1]===e[1]?t:{...t,xRanges:{...t.xRanges,[n]:e}}})},resetZoom(e){ve.setXRange(null,e)},setCursorX(e,t){l();let n=L(t).id;(_e.get(n)??null)!==e&&(_e.set(n,e),a.emit(`cursorchange`,{worksheetId:n,x:e}))},cursorX(e){return _e.get(L(e).id)??null},setLiveWindow(e,t){l();let n=L(t);n.liveWindowSeconds!==e&&B(n.id,t=>({...t,liveWindowSeconds:e}))}},ye={save(e){l();let t=e.id??crypto.randomUUID(),[n]=Gw([{...e,id:t,parentId:e.parentId??null}].concat(d().cycleRules.filter(e=>e.id!==t))).filter(e=>e.id===t);if(!n)throw new SE(`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=We(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 SE(`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 SE(`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 hw(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:()=>pw(d().mathChannels),preview(e,t){let n=m();return n.merged?qC(e,n.merged,L(t).xKey,n.channels.filter(t=>t.id!==e.id)):null},sync(e){l(),i.set(t=>{let n=t.mathChannels.filter(e=>e.source===`workbook`),r=n.length?[...e,...n]:e;return t.mathChannels===r?t:{...t,mathChannels:r}})}},xe=x5((e,t)=>[...e.flatMap(e=>e.kind===`camera`&&e.video?[Sw({...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}:${e.sync?`${e.sync.offsetMs}/${e.sync.driftPpm}/${e.sync.method}`:``}`).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]}))},setSync(e,t,n){l();for(let r of xe(d().live,d().video))r.id===e&&(t===void 0||(r.recordingId??null)===t)&&(r.sync=n);i.set(e=>({...e,video:[...e.video]}))},async detectSync(e,t,n){l();let r=d().video.find(n=>n.kind===`recorded`&&n.id===e&&n.recordingId===t),i=d().datasets.find(e=>e.info?.meta?.recordingId===t);if(!r||!i)throw Error(`Open the recording this camera was recorded with`);let a=Number(i.info?.meta?.wallOrigin);if(!Number.isFinite(a)||!i.schema.some(e=>e.name===`Time`))throw Error(`This recording has no wall clock`);let o=await zT({video:r,data:i.source,schema:i.schema,timeKey:`Time`,wallOrigin:a},n);return o.ok?{...o,offsetMs:o.offsetMs-yw(r.clockOffsetMs,r.dataClockOffsetMs)*1e3}:o},relayClock(){l();let e=t.live?.relay?.url;return e?XT(e,fetch,Date.now):Promise.resolve(null)},async calibrateFlash(e,t,n={}){l();let r=xe(d().live,d().video).find(t=>t.kind===`live`&&t.id===e);if(!r?.unitsBetween)throw Error(`This camera isn’t live`);let i=r.clockOffsetMs??n.displayClockOffsetMs??0,a=t.map(e=>({t:e.t+i/1e3,level:e.level})),o=r.acquire?.();try{let e=a[a.length-1].t+3;for(let t=0;(r.range()?.[1]??0)<e&&t<15e3;t+=250){if(n.signal?.aborted)throw new DOMException(`The operation was aborted.`,`AbortError`);await new Promise(e=>setTimeout(e,250))}return JT(await RT(r,[[a[0].t-1,e]],{signal:n.signal,onProgress:n.onProgress}),a)}finally{o?.()}},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(),U.openLocal(e,t)},async connect(e,t,n){l(),await U.connect(e,t,n)},startRecording(e){l(),U.startRecording(e)},stopRecording(e){return l(),U.stopRecording(e)},setSegmentAxis(e,t){l(),U.setSegmentAxis(e,t)},rowCount(e){return U.connections().find(t=>t.id===e)?.source.size()??0},disconnect(e){l(),U.disconnect(e),ee(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 SE(`bad_file`)}if(typeof e==`string`)try{return JSON.parse(e)}catch{throw new SE(`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=Be(e.panelChartSettings,q7[2],4),n={};for(let r of e.panels)t[r.id]?.kind===r.kind&&(n[r.id]=t[r.id]);return{...e,panelChartSettings:Ve(e.panels,n,q7[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=L(t),r=d().limits.maxChartsPerWorksheet;r!==null&&n.panels.length>=r&&u(`charts-per-worksheet`);let i=d().limits.maxChannelsPerChart;i!==null&&lJ(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 B(n.id,t=>({...t,panels:M([...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 iY({worksheets:e.worksheets,activeWorksheetId:e.activeWorksheetId,channels:W(p(e.mathChannels,e.limits.maxMathChannels),e.worksheets),liveWindowSeconds:e.liveWindowSeconds,laps:e.datasets.find(e=>e.beacon)?.beacon??null,cycles:e.cycleRules})},Le=e=>{if(e.worksheets.length===0)throw new SE(`bad_workspace`,{errors:e.errors});let{channels:t,rename:n}=Y7(d().mathChannels,e.mathChannels);Pe(n.size?e.worksheets.map(e=>X7(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,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=>$7(e,t)):e.worksheets;w=!0;try{i.set(t=>{let r=t=>e.worksheets.some(e=>e.id===t);return{...t,worksheets:n,activeWorksheetId:r(t.activeWorksheetId)?t.activeWorksheetId:r(e.activeWorksheetId)?e.activeWorksheetId:e.worksheets[0].id,xRanges:Object.fromEntries(Object.entries(t.xRanges).filter(([e])=>r(e))),mathChannels:[...t.mathChannels.filter(e=>e.source!==`workbook`),...e.channels],liveWindowSeconds:e.liveWindowSeconds}})}finally{w=!1}O=D(d()),C.rebase(k()),j()},ze={undo(){l(),Re(C.undo())},redo(){l(),Re(C.redo())},clear(){l(),P()}},He={hasWork:()=>hY(d().worksheets),exportWorksheet(e){l(),Ee();let t=L(e),n=aY(t);return{json:n,blob:Ae(n),filename:`${ke(t.name||`worksheet`)}.kymosh`}},exportChart(e){l(),Ee();let{ws:t,panel:n}=R(e),r=oY(n,t.panelChartSettings[e],t.panelChartBackgrounds[e]??null);return{json:r,blob:Ae(r),filename:`${ke(n.title?.trim()||n.kind)}.json`}},parseFile:e=>vY(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 JJ(Ie(),e):await YJ(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 XJ(n)&&(n=await $J(n,t)),F(()=>Le(mY(n)))},toWorkbook:Ie,openWorkbook(e){return l(),F(()=>Le(mY(e)))},async importWorksheet(e){l(),Ee();let t=d();t.limits.maxWorksheets!==null&&t.worksheets.length>=t.limits.maxWorksheets&&u(`worksheets`);let n=await vY(await Oe(e));if(n.type!==`worksheet`)throw new SE(`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 vY(await Oe(e));if(n.type!==`chart`)throw new SE(`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):[J7()];F(()=>i.set(t=>({...t,datasets:e.datasets,worksheets:n,activeWorksheetId:n.some(t=>t.id===e.activeWorksheetId)?e.activeWorksheetId:n[0].id,selection:e.selection,xRanges:{},offsets:{},colors:{}})))},reset(){l(),F(()=>{oe(d().datasets.map(e=>e.id));let e=J7();i.set(t=>({...t,worksheets:[e],activeWorksheetId:e.id,xRanges:{},offsets:{},colors:{},mathChannels:t.mathChannels.filter(e=>e.source!==`workbook`)}))})}},Ge={merged(e){let t=m();if(!t.merged||t.channels.length===0)return t.merged;let n=dw(t.merged,t.channels,L(e).xKey);return{...t.merged,columnNames:[...t.merged.columnNames,...n.ok.map(e=>e.name)],units:[...t.merged.units,...n.ok.map(e=>e.units)],rows:n.rows}},plotted(){return m().merged}},Ke=typeof location<`u`?location.hostname:``,qe=t.license,Je=t.licenseKey,Ye=!1,Xe={},Ze=e=>{n||i.set(t=>({...t,licensed:e}))},Qe=(e,t,n)=>{clearTimeout(Xe[e]);let r=Math.max(0,t-Date.now()),i=r>2**31-1;Xe[e]=setTimeout(()=>{i?Qe(e,t,n):n()},i?2**31-1:r)},$e=e=>Qe(`renew`,e,()=>void tt()),et=e=>Qe(`expiry`,e*1e3+1e3,()=>{jY(Je,Ke).then(e=>{n||Ze(e.ok)})});async function tt(){let e=36e5,t,r=null,i;try{t=await Promise.race([qe.get(),new Promise((e,t)=>{i=setTimeout(()=>t(Error(`timeout`)),3e4)})]),r=await jY(t,Ke)}catch{}finally{clearTimeout(i)}if(n)return!1;if(r?.ok)return Je=t,Ye=!0,Ze(!0),et(r.exp),$e(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 jY(Je,Ke);return n?!1:(Ze(a.ok),$e(Date.now()+e),a.ok)}let nt=!qe||t.licenseKey?jY(t.licenseKey,Ke).then(e=>(e.ok||console.warn(`[kymoscope] license ${e.reason}: showing attribution`),!Ye&&!n&&(Ze(e.ok),e.ok&&qe&&et(e.exp)),e.ok)):null,rt=qe?tt():nt;w=!1,P();let it={getState:I,subscribe(e){return i.subscribe(e)},on:a.on,licensed:rt,isLicensed:()=>d().licensed,setOptions(e){if(l(),t={...t,...e},e.live&&U.setRelay(e.live.relay),e.palette&&o(),e.limits){let t={...d().limits,...e.limits};i.set(e=>{let n=t.maxWorksheets===null?e.worksheets:e.worksheets.slice(0,Math.max(1,t.maxWorksheets)),r=n.some(t=>t.id===e.activeWorksheetId)?e.activeWorksheetId:n[0].id;return{...e,limits:t,activeWorksheetId:r}})}},datasets:de,folders:me,worksheets:he,charts:ge,view:ve,mathChannels:be,cycles:ye,live:Te,video:we,io:He,history:ze,data:Ge,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(Xe.renew),clearTimeout(Xe.expiry),s(),c5(it),z8(it),U.dispose();for(let e of d().datasets)e.source.dispose().catch(()=>void 0);a.emit(`dispose`,void 0),a.clear()}}};return r9.set(it,{store:i,derived:m,live:U,alertLines:()=>le(d().alertRules,d().alerts)}),it}var r9=new WeakMap;function i9(e){let t=r9.get(e);if(!t)throw new SE(`invalid_argument`,{reason:`not a Kymoscope engine`});return t}return t.CHART_KINDS=C5,t.KymoscopeError=SE,t.chartLabel=T5,t.createEngine=n9,t.verifyLicense=jY,t})({});
|
|
632
|
+
`),A=(0,Z.useMemo)(()=>{let e=i.filter(e=>e.kind!==`memory`).flatMap(e=>kJ(e.schema));return e.length?e:null},[i]),j=(0,Z.useMemo)(()=>i.some(e=>e.kind!==`memory`)||!g&&i.some(e=>e.data.rows.length>Q6),[i,g]),M=(0,Z.useMemo)(()=>F6(f.connections.filter(e=>r.includes(e.id)),i.length,j,d,o),[j,i,f.connections,r,o,d]),N=(0,Z.useMemo)(()=>{if(!g||i.length===0||j)return null;let e=i.map((e,t)=>{let n=e.data.rows;return{rows:n.length>0&&typeof n[0][d]==`number`?n:D[t]??n,offset:o[e.id]??0}});if(!M)for(let t of f.connections)r.includes(t.id)&&e.push({rows:t.dataset.rows,offset:o[t.id]??0});return s8(e,d)},[g,i,j,D,o,d,f.connections,r,M]),P=S&&`okByPart`in S?S.okByPart:void 0,F=(0,Z.useMemo)(()=>{if(!j)return[];let e=w.map((e,t)=>({live:`live`in e&&!!e.live,source:`live`in e&&e.live?e.live.source:e.source,columnSet:new Set(`live`in e&&e.live?e.data.columnNames:e.schema.map(e=>e.name)),keySuffix:T?`__${t}`:``,xOffset:o[e.id]??0,key:`${e.id}|${T?t:``}`}));return w.forEach((t,n)=>{let r=P?.[n],i=D[n];`live`in t&&t.live||!r?.length||!i||e.push({...e[n],live:!1,source:i8(i,r,d),columnSet:new Set([d,...r]),key:`${e[n].key}|channels`})}),e},[j,w,T,o,P,D,d]),I=(0,Z.useMemo)(()=>{let e=S?.parts??(C?[C]:[]),t=new Set;for(let n of e)for(let e of R6(n.columnNames,n.rows))t.add(e);let n=C?C.columnNames.filter(e=>t.has(e)):[],r=[...new Set(A?[...n,...A]:n)];if(k===``)return r;let i=new Set(r),a=k.split(`
|
|
633
|
+
`).filter(e=>!i.has(e));return a.length?[...r,...a]:r},[O,k,A]),L=(0,Z.useMemo)(()=>{let e=[];for(let t of l){if(t.kind!==`multiband`)continue;let n=u[t.id],r=n&&n.kind===`multiband`?n.series:[];e.push([t.id,[...new Set(r.map(e=>e.column).filter(e=>e!==d))]])}return JSON.stringify(e)},[l,u,d]),R=(0,Z.useMemo)(()=>{let e={};if(!C||j)return e;for(let[t,n]of JSON.parse(L)){let r=[];if(n.length>0)if(!T)r.push(qG(C.rows,d,n,Q6));else{let e=Math.max(1,Math.floor(Q6/w.length));for(let t=0;t<w.length;t++){let i=w[t];if(M&&`live`in i&&i.live)continue;let a=D[t]??i.data.rows;r.push(qG(a,d,n,e,`__${t}`,o[i.id]??0))}}e[t]=r}return e},[C,L,d,T,w,o,D,M,j]),z=(0,Z.useMemo)(()=>{let e={};if(!C)return e;for(let t of l){if(t.kind!==`multiband`)continue;let n=u[t.id],r=(n&&n.kind===`multiband`?n.series:[]).filter(e=>e.column!==d),i=n&&n.kind===`multiband`?n.layout:`overlay`,a=e=>o8(e,i),l;if(!T)l=a(r);else{let e=a(r);l=[];for(let t=0;t<w.length;t++){let n=tY(s,w[t].id,t,c);for(let r of e)l.push({...r,id:`${r.id}__${t}`,column:`${r.column}__${t}`,color:n})}}let f=R[t.id]??[],p=T&&n?.kind===`multiband`&&n.envelope?r.flatMap(e=>{let t=M6(f.flatMap((t,n)=>{let r=t.cols.get(`${e.column}__${n}`);return r?[{x:t.x,y:r}]:[]}),n8);return t?[{seriesId:e.id,color:e.color,...t}]:[]}):void 0,m=w.flatMap((e,t)=>`bands`in e&&e.bands?J6(e,d,r,T?tY(s,e.id,t,c):void 0,o[e.id]??0):[]),h=[...p??[],...m];e[t.id]={effectiveSeries:l,points:f,envelopes:h.length?h:void 0}}return e},[C,l,u,d,T,w,s,c,o,R]),B=(0,Z.useMemo)(()=>{let e={pts:{},colorMeta:{},datasetColors:{}};if(!C)return e;let t={},r={},i={},a=t8,o=w.map((e,t)=>({id:e.id,rows:D[t]??p[e.id]??e.data.rows,full:a(e)})),f={id:`single`,rows:C.rows,full:w.length===1?a(w[0]):void 0};for(let e of l){if(e.kind!==`xyscatter`)continue;let a=u[e.id];if(!a||a.kind!==`xyscatter`)continue;let{xyXCol:l,xyYCol:p}=a;if(!l||!p){t[e.id]={length:0,x:[],y:[]};continue}if(T){let{cols:r,colors:a}=D$(o,l,p,{xKey:d,viewXRange:n,colorOverrides:s,palette:c});t[e.id]=r,i[e.id]=a;continue}let m=E$(f,l,p,{xKey:d,viewXRange:n,colorCol:a.xyColorCol||void 0});t[e.id]=m?.cols??{length:0,x:[],y:[]},m?.color&&(r[e.id]=m.color)}return{pts:t,colorMeta:r,datasetColors:i}},[C,l,u,n,d,T,w,p,s,c,D]),V=(0,Z.useRef)(new Map),ee=(0,Z.useMemo)(()=>{let e={};if(!C)return e;let t={length:0,x:[],y:[],z:[]},{rows:r}=C,i=E;for(let a of l){if(a.kind!==`xyzmesh`)continue;let o=u[a.id];if(!o||o.kind!==`xyzmesh`)continue;if(o.xyzMode===`matrix`){let n=(o.xyzColumns??[]).flatMap(e=>{let t=b$(r,e,i);return t?[t]:[]}),s=n[0]?.length??0,c=n.length;if(s<2||c<2){e[a.id]={points:t};continue}let l=V.current.get(a.id);l?.length!==s*c&&V.current.set(a.id,l=new Float32Array(s*c)),n.forEach((e,t)=>l.set(e.length===s?e:e.subarray(0,s),t*s));let u=b$(r,d,i),f=u&&!(o.xyzColumns??[]).includes(d)&&u.length>=s&&Number.isFinite(u[0])&&Number.isFinite(u[s-1])?[u[0],u[s-1]]:[0,s-1];e[a.id]={points:t,surface:{w:s,h:c,values:l,x:f,y:[0,c-1]}};continue}let{xyzXCol:s,xyzYCol:c,xyzZCol:l}=o,f=s?b$(r,s,i):void 0,p=c?b$(r,c,i):void 0,m=l?b$(r,l,i):void 0;if(!f||!p||!m){e[a.id]={points:t};continue}let h=n?b$(r,d,i):void 0;if(!n||!h){e[a.id]={points:{length:Math.min(f.length,p.length,m.length),x:f,y:p,z:m}};continue}let[g,_]=n,v=0;for(let e=0;e<h.length;e++)h[e]>=g&&h[e]<=_&&v++;let y=new Float64Array(v),b=new Float64Array(v),x=new Float64Array(v);for(let e=0,t=0;e<h.length;e++)h[e]>=g&&h[e]<=_&&(y[t]=f[e],b[t]=p[e],x[t]=m[e],t++);e[a.id]={points:{length:v,x:y,y:b,z:x}}}return e},[C,l,u,n,d,E]),H=(0,Z.useMemo)(()=>{let e={};if(!C)return e;for(let t of l){if(t.kind!==`histogram`)continue;let n=u[t.id];e[t.id]=n?.kind===`histogram`&&n.histColumn&&x$(C.rows,n.histColumn,E)||new Float64Array}return e},[C,l,u,E]),U=(0,Z.useMemo)(()=>{let e={};if(!C)return e;for(let t of l){if(t.kind!==`polar`)continue;let n=u[t.id],r=n?.kind===`polar`&&n.polarAngleCol?b$(C.rows,n.polarAngleCol,E):void 0,i=n?.kind===`polar`&&n.polarRadiusCol?b$(C.rows,n.polarRadiusCol,E):void 0;e[t.id]=r&&i?{angles:r,radii:i}:{angles:[],radii:[]}}return e},[C,l,u,E]),te=(e,t,n,r)=>{let i=t&&x$(e,t,E)||new Float64Array,a=n?b$(e,n,E):void 0;return{signal:i,rate:a&&C$(a)||parseFloat(r)||1}},W=(0,Z.useMemo)(()=>{let e={};if(!C)return e;for(let t of l){if(t.kind!==`spectrum`)continue;let n=u[t.id];n?.kind===`spectrum`&&(e[t.id]=te(C.rows,n.specSignalCol,n.specTimeCol,n.specSampleRate))}return e},[C,l,u,E]),ne=(0,Z.useMemo)(()=>{let e={};if(!C)return e;for(let t of l){if(t.kind!==`boxplot`)continue;let n=u[t.id];e[t.id]=n?.kind===`boxplot`&&n.boxValueCol?S$(C.rows,n.boxValueCol,n.boxGroupCol||void 0,E):[]}return e},[C,l,u,E]),G=(0,Z.useMemo)(()=>{let e={};if(!C)return e;for(let t of l){if(t.kind!==`spectrogram`)continue;let n=u[t.id];n?.kind===`spectrogram`&&(e[t.id]=te(C.rows,n.sgSignalCol,n.sgTimeCol,n.sgSampleRate))}return e},[C,l,u,E]),re=(0,Z.useMemo)(()=>{if(!C)return{};let e={};for(let t of l){if(t.kind!==`heatmap`)continue;let n=u[t.id];if(!n||n.kind!==`heatmap`){e[t.id]={cells:[],xLabels:[],yLabels:[]};continue}if(n.hmMode===`matrix`){let r=C.rows,i=n.hmColumns.flatMap(e=>{let t=b$(r,e,E);return t?[{name:e,v:t}]:[]}),a=i.reduce((e,t)=>Math.min(e,t.v.length),i.length?1/0:0),o=b$(r,d,E),s,c;if(n.hmSpacing===`values`){o&&W2(o.subarray(0,a))&&(s=Float64Array.from(o.subarray(0,a)));let e=i.map(e=>({c:e,v:parseFloat(e.name)})).sort((e,t)=>t.v-e.v);e.length&&W2(e.map(e=>e.v).reverse())&&(i=e.map(e=>e.c),c=Float64Array.from(e,e=>e.v))}let l=i.length,u=new Float32Array(a*l);i.forEach((e,t)=>u.set(e.v.subarray(0,a),t*a));let f=e=>String(o?+o[e].toPrecision(6):e+1);e[t.id]={cells:[],xLabels:[],yLabels:i.map(e=>e.name),grid:{w:a,h:l,values:u,xLabels:f,yLabels:i.map(e=>e.name)},xCentres:s,yCentres:c}}else if(n.hmMode===`correlation`){let r=n.hmColumns.filter(e=>I.includes(e));if(r.length<2){e[t.id]={cells:[],xLabels:r,yLabels:r};continue}let i=r.map(e=>{let t=[];for(let n of C.rows){let r=n[e];typeof r==`number`&&Number.isFinite(r)&&t.push(r)}return t}),a=i.map(e=>e.reduce((e,t)=>e+t,0)/(e.length||1)),o=[];for(let e=0;e<r.length;e++)for(let t=0;t<r.length;t++){let n=i[e],s=i[t],c=a[e],l=a[t],u=Math.min(n.length,s.length),d=0,f=0,p=0;for(let e=0;e<u;e++){let t=n[e]-c,r=s[e]-l;d+=t*r,f+=t*t,p+=r*r}let m=f>0&&p>0?d/Math.sqrt(f*p):+(e===t);o.push({x:r[t],y:r[e],value:m})}e[t.id]={cells:o,xLabels:r,yLabels:r}}else if(n.hmMode===`binned`||n.hmMode===`count`){let{hmXCol:r,hmYCol:i}=n,a=n.hmMode===`count`?``:n.hmValueCol;if(!r||!i||n.hmMode===`binned`&&!a){e[t.id]={cells:[],xLabels:[],yLabels:[]};continue}let o=e=>{let t=parseFloat(e);return Number.isFinite(t)?t:void 0};e[t.id]=Z6(C.rows,{xCol:r,yCol:i,valueCol:a,xBins:n.hmXBins,yBins:n.hmYBins,xMin:o(n.hmXMin),xMax:o(n.hmXMax),yMin:o(n.hmYMin),yMax:o(n.hmYMax)})}else{let{hmXCol:r,hmYCol:i,hmValueCol:a}=n;if(!r||!i||!a){e[t.id]={cells:[],xLabels:[],yLabels:[]};continue}let o=new Map,s=new Set,c=new Set;for(let e of C.rows){let t=String(e[r]??``),n=String(e[i]??``),l=e[a];if(typeof l!=`number`||!Number.isFinite(l))continue;s.add(t),c.add(n);let u=`${t}\0${n}`,d=o.get(u)??{sum:0,count:0};o.set(u,{sum:d.sum+l,count:d.count+1})}let l=e=>{let t=[...e];return t.every(e=>e.trim()!==``&&Number.isFinite(Number(e)))?t.sort((e,t)=>Number(e)-Number(t)):t.sort()},u=l(s),d=l(c),f,p;if(n.hmSpacing===`values`){let e=Float64Array.from(u,Number),t=Float64Array.from(d,Number);W2(e)&&(f=e),W2(t)&&(d=[...d].reverse(),p=t.reverse())}let m=[];for(let e of d)for(let t of u){let n=o.get(`${t}\0${e}`);m.push({x:t,y:e,value:n?n.sum/n.count:0})}e[t.id]={cells:m,xLabels:u,yLabels:d,xCentres:f,yCentres:p}}}return e},[C,l,u,I,d,E]),ie=(0,Z.useMemo)(()=>{let e={};if(!C)return e;for(let t of l){if(t.kind!==`violin`)continue;let n=u[t.id];e[t.id]=n?.kind===`violin`&&n.vlValueCol?S$(C.rows,n.vlValueCol,n.vlGroupCol||void 0,E):[]}return e},[C,l,u,E]),ae=(0,Z.useMemo)(()=>{let e={};if(!C)return e;let{rows:t}=C;for(let n of l){if(n.kind!==`confusion`)continue;let r=u[n.id];if(!r||r.kind!==`confusion`||!r.cfActualCol||!r.cfPredictedCol){e[n.id]={actual:[],predicted:[]};continue}let{cfActualCol:i,cfPredictedCol:a}=r,o=E?.get(i),s=E?.get(a);if(o&&s){e[n.id]={actual:o,predicted:s};continue}let c=[],l=[];for(let e of t){let t=e[i],n=e[a];t!==void 0&&n!==void 0&&(c.push(t),l.push(n))}e[n.id]={actual:c,predicted:l}}return e},[C,l,u,E]),oe=(0,Z.useMemo)(()=>{let e={};if(!C)return e;for(let t of l){if(t.kind!==`roc`)continue;let n=u[t.id],r=n?.kind===`roc`&&n.rocScoreCol?b$(C.rows,n.rocScoreCol,E):void 0,i=n?.kind===`roc`&&n.rocLabelCol?b$(C.rows,n.rocLabelCol,E):void 0;e[t.id]=r&&i?{scores:r,labels:i}:{scores:[],labels:[]}}return e},[C,l,u,E]),se=(0,Z.useMemo)(()=>{let e={};if(!C)return e;let{rows:t}=C;for(let n of l){if(n.kind!==`losscurve`)continue;let r=u[n.id];if(!r||r.kind!==`losscurve`){e[n.id]={xValues:[],series:[]};continue}let{lcXCol:i,lcLeftCols:a,lcRightCols:o}=r,s=[...a.map(e=>({...e,axis:`left`})),...o.map(e=>({...e,axis:`right`}))].map(({column:e,color:n,axis:r})=>({label:e,color:n,values:b$(t,e,E)??new Float64Array,axis:r})),c=s[0]?.values.length??t.length,l=i&&b$(t,i,E)||Float64Array.from({length:c},(e,t)=>t);e[n.id]={xValues:l,series:s}}return e},[C,l,u,E]),ce=(0,Z.useMemo)(()=>{let e={};if(!C)return e;let{rows:t}=C;for(let n of l){if(n.kind!==`controlchart`)continue;let r=u[n.id],i=r?.kind===`controlchart`&&r.ccValueCol?b$(t,r.ccValueCol,E):void 0;if(!r||r.kind!==`controlchart`||!i){e[n.id]={length:0,value:[]};continue}let a=0;for(let e=0;e<i.length;e++)i[e]-i[e]===0&&a++;let o=a===i.length?null:new Uint32Array(a),s=o?new Float64Array(a):i;if(o)for(let e=0,t=0;e<i.length;e++)i[e]-i[e]===0&&(o[t]=e,s[t++]=i[e]);let c=r.ccSubgroupCol,l=c?E?.get(c):void 0,d=e=>o?o[e]:e;e[n.id]={length:a,value:s,subgroup:c?e=>String(l?l[d(e)]:t[d(e)]?.[c]??``):void 0}}return e},[C,l,u,E]),le=(0,Z.useMemo)(()=>{let e={};if(!C)return e;let{rows:t}=C;for(let n of l){if(n.kind!==`parallelcoords`)continue;let r=u[n.id];if(!r||r.kind!==`parallelcoords`||r.pcColumns.length<2){e[n.id]={length:0,columns:[]};continue}let i=r.pcColumns.map(e=>b$(t,e,E)??new Float64Array),a=Math.min(...i.map(e=>e.length)),o={length:a,columns:i},s=r.pcColorByCol;if(s)if(I.includes(s))o.colorValue=b$(t,s,E);else{let e=new Map,n=new Int32Array(a);for(let r=0;r<a;r++){let i=String(t[r]?.[s]??``),a=e.get(i);a===void 0&&e.set(i,a=e.size),n[r]=a}o.colorIndex=n,o.colorLabels=[...e.keys()]}e[n.id]=o}return e},[C,l,u,I,E]),ue=(0,Z.useMemo)(()=>{let e={};if(!C)return e;let{rows:t}=C,n={length:0,x:[],y:[]};for(let r of l){if(r.kind!==`embedding`)continue;let i=u[r.id];if(!i||i.kind!==`embedding`||!i.emXCol||!i.emYCol){e[r.id]=n;continue}let{emXCol:a,emYCol:o,emColorCol:s,emColorMode:c,emLabelCol:l}=i,d=b$(t,a,E),f=b$(t,o,E);if(!d||!f){e[r.id]=n;continue}let p=Math.min(d.length,f.length),m={length:p,x:d,y:f};if(s)if(c===`numeric`&&I.includes(s))m.colorValue=b$(t,s,E);else{let e=E?.get(s),n=new Map,r=new Int32Array(p);for(let i=0;i<p;i++){let a=String(e?e[i]:t[i]?.[s]??``),o=n.get(a);o===void 0&&n.set(a,o=n.size),r[i]=o}m.colorIndex=r,m.colorLabels=[...n.keys()]}if(l){let e=E?.get(l);m.label=e?t=>String(e[t]):e=>String(t[e]?.[l]??``)}e[r.id]=m}return e},[C,l,u,I,E]),de=(0,Z.useMemo)(()=>{if(!C)return{};let e={};for(let t of l){if(t.kind!==`flamegraph`)continue;let n=u[t.id];if(!n||n.kind!==`flamegraph`||!n.fgNameCol||!n.fgValueCol){e[t.id]=[];continue}let r=[];for(let e of C.rows){let t=String(e[n.fgNameCol]??``),i=n.fgParentCol?String(e[n.fgParentCol]??``):``,a=e[n.fgValueCol];!t||typeof a!=`number`||!Number.isFinite(a)||r.push({name:t,parent:i,value:a})}e[t.id]=r}return e},[C,l,u]),fe=(0,Z.useMemo)(()=>{if(!C)return{};let e={};for(let t of l){if(t.kind!==`barchart`)continue;let n=u[t.id];if(!n||n.kind!==`barchart`||n.bcValueCols.length===0){e[t.id]={groups:[],seriesNames:[]};continue}let r=n.bcValueCols;if(n.bcCategoryCol){let i=new Map;for(let e of C.rows){let t=String(e[n.bcCategoryCol]??`(blank)`);i.has(t)||i.set(t,r.map(()=>0));let a=new Map,o=i.get(t);for(let t=0;t<r.length;t++){let n=e[r[t]];typeof n==`number`&&Number.isFinite(n)&&(o[t]+=n),a.set(r[t],(a.get(r[t])??0)+1)}}e[t.id]={groups:Array.from(i.entries()).map(([e,t])=>({label:e,values:t})),seriesNames:r}}else{let n=C.rows,i=r.map(e=>b$(n,e,E)),a=i.reduce((e,t)=>t?Math.min(e,t.length):e,1/0),o=Number.isFinite(a)?a:n.length,s=i.map(e=>e??new Float64Array(o).fill(NaN));e[t.id]={groups:[],columns:{length:o,values:s},seriesNames:r}}}return e},[C,l,u,E]),pe=(0,Z.useMemo)(()=>{let e={};if(!C)return e;let{rows:t}=C;for(let n of l){if(n.kind!==`radar`)continue;let r=u[n.id];if(!r||r.kind!==`radar`||r.rdAxesCols.length<3){e[n.id]={axes:[],series:[]};continue}let i=r.rdAxesCols,a=i.map(e=>b$(t,e,E));if(r.rdGroupCol){let o=r.rdGroupCol,s=E?.get(o),c=s?s.length:t.length,l=new Map;for(let e=0;e<c;e++){let n=s?s[e]===s[e]?String(s[e]):`(blank)`:String(t[e][o]??`(blank)`),r=l.get(n);r||l.set(n,r=i.map(()=>0));for(let t=0;t<i.length;t++){let n=a[t]?.[e]??NaN;n-n===0&&(r[t]+=n)}}e[n.id]={axes:i,series:Array.from(l.entries()).map(([e,t])=>({name:e,values:t}))}}else{let t=a.map(e=>{let t=0,n=0;if(e)for(let r=0;r<e.length;r++)e[r]-e[r]===0&&(t+=e[r],n++);return t/(n||1)});e[n.id]={axes:i,series:[{name:`Series 1`,values:t}]}}}return e},[C,l,u,E]),me=(0,Z.useMemo)(()=>{if(!C)return{};let e={};for(let t of l){if(t.kind!==`areachart`)continue;let n=u[t.id];if(!n||n.kind!==`areachart`||n.acYCols.length===0){e[t.id]=[];continue}let r=C.rows,i=n.acYCols.map(e=>b$(r,e,E)),a=i[0]?.length??r.length,o=(n.acXCol?b$(r,n.acXCol,E):void 0)??d8(a);e[t.id]=n.acYCols.flatMap((e,t)=>{let n=i[t];return n?[{name:e,x:o,y:n}]:[]})}return e},[C,l,u,E]),he=(0,Z.useMemo)(()=>{let e={};if(!C)return e;for(let t of l){if(t.kind!==`cdfchart`)continue;let n=u[t.id];if(!n||n.kind!==`cdfchart`){e[t.id]=[];continue}e[t.id]=n.cdValueCols.map(e=>({name:e,values:x$(C.rows,e,E)??new Float64Array}))}return e},[C,l,u,E]),ge=(0,Z.useMemo)(()=>{let e={};if(!C)return e;let{rows:t}=C,n={length:0,x:[],y:[],size:[]};for(let r of l){if(r.kind!==`bubblechart`)continue;let i=u[r.id];if(!i||i.kind!==`bubblechart`||!i.bbXCol||!i.bbYCol||!i.bbSizeCol){e[r.id]=n;continue}let a=b$(t,i.bbXCol,E),o=b$(t,i.bbYCol,E),s=b$(t,i.bbSizeCol,E);if(!a||!o||!s){e[r.id]=n;continue}let c=Math.min(a.length,o.length,s.length),l=new Float64Array(c);for(let e=0;e<c;e++)l[e]=s[e]===s[e]?Math.max(0,s[e]):NaN;let d=new Float64Array(c);for(let e=0;e<c;e++)d[e]=l[e]===l[e]?a[e]:NaN;let f={length:c,x:d,y:o,size:l};if(i.bbColorCol){if(i.bbColorMode===`numeric`)f.colorValue=b$(t,i.bbColorCol,E);else if(i.bbColorMode===`categorical`){let e=E?.get(i.bbColorCol),n=new Map,r=new Int32Array(c);for(let a=0;a<c;a++){let o=String(e?e[a]:t[a]?.[i.bbColorCol]??``),s=n.get(o);s===void 0&&n.set(o,s=n.size),r[a]=s}f.colorIndex=r,f.colorLabels=[...n.keys()]}}e[r.id]=f}return e},[C,l,u,E]),_e=(0,Z.useMemo)(()=>{if(!C)return{};let e={};for(let t of l){if(t.kind!==`treemap`)continue;let n=u[t.id];if(!n||n.kind!==`treemap`||!n.tmNameCol||!n.tmValueCol){e[t.id]=[];continue}let r=[];for(let e of C.rows){let t=String(e[n.tmNameCol]??``),i=n.tmParentCol?String(e[n.tmParentCol]??``):``,a=e[n.tmValueCol];!t||typeof a!=`number`||!Number.isFinite(a)||r.push({name:t,parent:i,value:a})}e[t.id]=r}return e},[C,l,u]),ve=(0,Z.useMemo)(()=>{if(!C)return{};let e={};for(let t of l){if(t.kind!==`sankey`)continue;let n=u[t.id];if(!n||n.kind!==`sankey`||!n.skSourceCol||!n.skTargetCol||!n.skValueCol){e[t.id]={nodeNames:[],links:[]};continue}let r=new Set,i=[];for(let e of C.rows){let t=String(e[n.skSourceCol]??``),a=String(e[n.skTargetCol]??``),o=e[n.skValueCol];!t||!a||typeof o!=`number`||!Number.isFinite(o)||(r.add(t),r.add(a),i.push({source:t,target:a,value:o}))}e[t.id]={nodeNames:Array.from(r),links:i}}return e},[C,l,u]),ye=(0,Z.useMemo)(()=>{let e={};if(!C)return e;for(let t of l){if(t.kind!==`calibration`)continue;let n=u[t.id],r=n?.kind===`calibration`&&n.cbScoreCol?b$(C.rows,n.cbScoreCol,E):void 0,i=n?.kind===`calibration`&&n.cbLabelCol?b$(C.rows,n.cbLabelCol,E):void 0;if(!n||n.kind!==`calibration`||!r||!i){e[t.id]=[];continue}let a=Math.max(2,n.cbBins),o=new Float64Array(a),s=new Float64Array(a);for(let e=0;e<Math.min(r.length,i.length);e++){let t=r[e],n=i[e];if(t-t!==0||n-n!==0)continue;let c=Math.max(0,Math.min(a-1,Math.floor(t*a)));o[c]+=n,s[c]++}e[t.id]=Array.from({length:a},(e,t)=>({center:(t+.5)/a,actual:s[t]>0?o[t]/s[t]:0,count:s[t]})).filter(e=>e.count>0)}return e},[C,l,u,E]),be=(0,Z.useMemo)(()=>{let e={};if(!C)return e;let t={length:0,theoretical:[],sample:[]},n=e=>{let t=x$(C.rows,e,E);return t?Float64Array.from(t).sort():new Float64Array};for(let r of l){if(r.kind!==`qqplot`)continue;let i=u[r.id];if(!i||i.kind!==`qqplot`||!i.qqValueCol){e[r.id]=t;continue}let a=n(i.qqValueCol),o=a.length;if(o===0){e[r.id]=t;continue}if(i.qqMode===`column`&&i.qqRefCol){let t=n(i.qqRefCol),s=Math.min(o,t.length);e[r.id]={length:s,theoretical:t.subarray(0,s),sample:a.subarray(0,s)}}else{let t=e=>{let t=[2.515517,.802853,.010328],n=[1.432788,.189269,.001308],r=Math.sqrt(-2*Math.log(Math.min(e,1-e))),i=r-(t[0]+t[1]*r+t[2]*r*r)/(1+n[0]*r+n[1]*r*r+n[2]*r*r*r);return e<.5?-i:i},n=new Float64Array(o);for(let e=0;e<o;e++)n[e]=t((e+.5)/o);e[r.id]={length:o,theoretical:n,sample:a}}}return e},[C,l,u,E]),xe=(0,Z.useMemo)(()=>{if(!C)return{};let e={};for(let t of l){if(t.kind!==`gantt`)continue;let n=u[t.id];if(!n||n.kind!==`gantt`||!n.gtLabelCol||!n.gtStartCol||!n.gtEndCol){e[t.id]=[];continue}let r=[];for(let e of C.rows){let t=String(e[n.gtLabelCol]??``),i=e[n.gtStartCol],a=e[n.gtEndCol];if(!t||typeof i!=`number`||typeof a!=`number`||!Number.isFinite(i)||!Number.isFinite(a))continue;let o={label:t,start:i,end:a};n.gtGroupCol&&e[n.gtGroupCol]!==void 0&&(o.group=String(e[n.gtGroupCol])),r.push(o)}e[t.id]=r}return e},[C,l,u]),Se=C&&C.columnNames.indexOf(d)>=0?C.units[C.columnNames.indexOf(d)]??``:``,Ce=(0,Z.useMemo)(()=>C?c8(C,T?w.length:0):{},[C,T,w]);return{dataset:y,datasetWithChannels:C,multiDatasetMode:T,numericCols:I,anyDuckDb:j,duckDbLayers:F,liveConn:_,liveOverlays:M,hasLiveSelected:g,staticXRange:N,xUnit:Se,columnUnits:Ce,multibandDataByPanel:z,xyPointsByPanel:B,xyzPointsByPanel:ee,histogramDataByPanel:H,polarDataByPanel:U,spectrumDataByPanel:W,boxplotDataByPanel:ne,spectrogramDataByPanel:G,heatmapDataByPanel:re,violinDataByPanel:ie,confusionDataByPanel:ae,rocDataByPanel:oe,lossCurveDataByPanel:se,controlChartDataByPanel:ce,parallelCoordsDataByPanel:le,embeddingDataByPanel:ue,flameGraphDataByPanel:de,barChartDataByPanel:fe,radarDataByPanel:pe,areaChartDataByPanel:me,cdfChartDataByPanel:he,bubbleChartDataByPanel:ge,treemapDataByPanel:_e,sankeyDataByPanel:ve,calibrationDataByPanel:ye,qqPlotDataByPanel:be,ganttDataByPanel:xe,gaugeDataByPanel:(0,Z.useMemo)(()=>{let e={};if(!C)return e;let t=e=>e.trim()!==``&&Number.isFinite(Number(e))?Number(e):void 0;for(let n of l){if(n.kind!==`gauge`)continue;let r=u[n.id];if(r?.kind!==`gauge`){e[n.id]=[];continue}e[n.id]=r.ggGauges.flatMap(e=>{let n=e.column,r=n?b$(C.rows,n,E):void 0;if(!r)return[];let i=1/0,a=-1/0,o=0,s=0,c=NaN;for(let e=0;e<r.length;e++){let t=r[e];t-t===0&&(t<i&&(i=t),t>a&&(a=t),o+=t,s++,c=t)}let l=s===0?NaN:e.value===`mean`?o/s:e.value===`min`?i:e.value===`max`?a:c,[u,d]=p8(s?i:0,s?a:1,t(e.min),t(e.max));return[{name:n,unit:Ce[n]??``,value:l,min:u,max:d,alarm:e.alarm??null,color:e.color,style:e.style,fromZero:e.fill===`zero`,colorMode:e.colorMode,stops:e.stops,stat:e.value}]})}return e},[C,l,u,E,Ce])}}function p8(e,t,n,r){t<=e&&(t=e+1);let i=MJ(t-e,5),a=n??Math.floor(e/i)*i,o=r??Math.ceil(t/i)*i;return o>a?[a,o]:[a,a+1]}QG(),gK();var m8=`#fb7185`,h8=2500,g8=new Float64Array;function _8(e,t){return t&&e?.kind===`spectrogram`&&e.sgView!==`waterfall`&&e.sgSignalCol!==``}function v8(e){let t=[],n=(e,r)=>{if(typeof e==`string`){e&&(r===`column`||/(Col|Cols|Column|Columns)$/.test(r))&&t.push(e);return}if(Array.isArray(e)){for(let t of e)n(t,r);return}if(e&&typeof e==`object`)for(let[t,r]of Object.entries(e))t!==`addColumn`&&n(r,t)};return n(e,``),[...new Set(t)]}function y8(e){let t=b8(e);if(t.status!==`empty`||!e.data.dataset)return t;let n=new Set([...e.data.datasetWithChannels?.columnNames??[],...e.data.numericCols]);return v8(e.settings).some(e=>!n.has(e))?{...t,status:`missing`}:t}function b8(e){let{panel:t,data:n,settings:r}=e;if(t.kind===`camera`)return{status:`ready`,data:null,node:(0,Q.jsx)(x6,{settings:r?.kind===`camera`?r:Ee(),live:e.live??[],selection:e.selection??[],viewXRange:e.viewXRange,xIsTime:e.xKey===dK,xKey:e.xKey,video:e.video,recordings:e.recordings,cursor:e.cursor,onContextMenu:t=>e.onContextMenu(t)})};if(!n.dataset)return{status:`no-data`,node:null,data:null};let i=`${e.background??`theme`}|${e.styleToken}`,a=t=>e.onContextMenu(t),o=(e,t)=>({status:`ready`,node:e,data:t}),s={status:`empty`,node:null,data:null},c=t.id;switch(t.kind){case`multiband`:{let t=n.multibandDataByPanel[c],l=t?.points??[],u=t?.effectiveSeries??[],d=r?.kind===`multiband`?r:null,f=[...new Set((d?.series??[]).map(e=>e.column).filter(t=>t!==e.xKey))],p=e.xKey===`ElapsedTime`&&!n.numericCols.includes(`Time`)?`Time`:e.xKey,m={xLabel:n.xUnit?`${p} (${n.xUnit})`:p,series:u,columnUnits:n.columnUnits,height:e.height,backgroundToken:i,viewXRange:e.viewXRange,onViewXRangeChange:e.onViewXRangeChange,onCursorX:e.onCursorX,liveZoom:e.liveZoom,liveZoomId:c,xAxisLine:d?.xAxisLine,yAxisLine:d?.yAxisLine,gridLine:d?.gridLine,lineWidth:d?.lineWidth,onPlotContextMenu:a,shiftMode:e.shiftMode},h=d?.beacon;if(h?.enabled&&e.beaconLive&&f.length>0){let t=o8((d?.series??[]).filter(t=>t.column!==e.xKey),d?.layout??`overlay`),n=h.reference===`dataset`&&h.datasetId?e.findDataset(h.datasetId):void 0,r=q6(h,!!n),i=r?[...V6(t,r),...t]:t;return o((0,Q.jsx)(XQ,{...m,series:i,points:[],showLatestValues:!0,liveSource:K6(e.beaconLive,e.xKey,f,h,n),envelopes:n?J6(n,e.xKey,t,r??void 0):void 0,liveZoomMode:`free`}),{series:i,points:[]})}if(n.anyDuckDb)return u.length===0?s:o((0,Q.jsx)(_$,{...m,layers:n.duckDbLayers,xKey:e.xKey,columns:f,maxPoints:h8}),{series:u,columns:f});if(!l.some(e=>e.length>0)&&!n.liveOverlays||u.length===0||!f.some(e=>n.numericCols.includes(e)))return s;let g=n.liveConn,_=null,v=n.liveOverlays,y=!g&&v&&f.length>0?I6(v,e.xKey,f,l,n.staticXRange):void 0,b=!!y&&l.length>0,x=y??(g&&f.length>0?{pull:(t,n,r,i,a)=>{let o=g.source.version();if(a){let i=2**Math.ceil(Math.log2((n-t)/8)),a=Math.floor(t/i)*i,s=Math.ceil(n/i)*i,c=Math.round(r*(s-a)/(n-t));return(!_||_.ver!==o||_.x0!==a||_.x1!==s||Math.abs(_.mp-c)>c*.25)&&(_={ver:o,x0:a,x1:s,mp:c,pts:g.source.getPointsSync(f,{xKey:e.xKey,x0:a,x1:s},c),held:UG(f,e=>g.source.lastKnownSync(e),a,s,g.source.latestTimeSync())}),_.held?[_.pts,_.held]:[_.pts]}(!_||_.ver!==o||_.x0!==t||_.x1!==n||_.mp!==r)&&(_={ver:o,x0:t,x1:n,mp:r,pts:g.source.getPointsSync(f,{xKey:e.xKey,x0:t,x1:n},r)});let s=WG(_.pts,i);if(e.xKey!==`ElapsedTime`)return[s];let c=UG(f,e=>g.source.lastKnownSync(e),t,n,Math.min(g.source.latestTimeSync(),i??1/0));return c?[s,c]:[s]},cutOnGpu:e.xKey===`ElapsedTime`,id:g.id,latestT:()=>g.source.latestTimeSync(),timeAfter:e=>g.source.timeAfterSync(e),xAtTime:t=>g.source.xAtTimeSync(e.xKey,t),xBounds:()=>{let t=g.source.xBoundsSync(e.xKey);return t.x1>t.x0?[t.x0,t.x1]:null},latestX:()=>{let t=g.source.latestSync(e.xKey);return Number.isFinite(t)?t:null},version:()=>g.source.version(),latestValues:e=>g.source.latestValuesSync(e),...e.xKey===`ElapsedTime`?{}:{spanForSeconds:t=>g.source.xTravelSync(e.xKey,t),bufferedSeconds:()=>{let e=g.source.xBoundsSync(`ElapsedTime`);return e.x1-e.x0}}}:void 0);return o((0,Q.jsx)(XQ,{...m,points:l,envelopes:t?.envelopes,showLatestValues:n.hasLiveSelected,fullXRange:n.staticXRange,liveSource:x,liveWindowSeconds:b?null:e.liveWindowSeconds,onLiveWindowChange:b?void 0:e.onLiveWindowChange,liveZoomMode:b?`free`:`follow`}),{series:u,points:l})}case`xyzmesh`:{let t=r?.kind===`xyzmesh`?r:te(4),l=n.xyzPointsByPanel[c];if(!l||l.points.length<1&&!l.surface)return s;let u=!!l.surface;return o((0,Q.jsx)(b0,{ref:e.xyzRef,points:l.points,surface:l.surface,xLabel:u?(t.xyzColumns??[]).includes(e.xKey)?`Row`:e.xKey:t.xyzXCol,yLabel:u?`Column`:t.xyzYCol,zLabel:u?`Value`:t.xyzZCol,height:e.height,backgroundToken:i,xRange:V(t.xyzXScale.scaleMin,t.xyzXScale.scaleMax),yRange:V(t.xyzYScale.scaleMin,t.xyzYScale.scaleMax),zRange:V(t.xyzZScale.scaleMin,t.xyzZScale.scaleMax),viewMode:t.xyzViewMode,pointRadius:t.xyzPointRadius,showMesh:t.showMesh,meshStyle:t.meshStyle,meshOpacity:t.meshOpacity,alarms:[...t.xyzXScale.alarm?[{axis:`x`,...t.xyzXScale.alarm}]:[],...t.xyzYScale.alarm?[{axis:`y`,...t.xyzYScale.alarm}]:[],...t.xyzZScale.alarm?[{axis:`z`,...t.xyzZScale.alarm}]:[]],onPlotContextMenu:a}),l.surface??l.points)}case`xyscatter`:{let t=r?.kind===`xyscatter`?r:U(m8),l=n.xyPointsByPanel.pts[c]??[];if(l.length===0)return s;let u=n.xyPointsByPanel.colorMeta[c];return o((0,Q.jsx)(c1,{points:l,xLabel:t.xyXCol,yLabel:t.xyYCol,color:t.xyColor,datasetColors:n.xyPointsByPanel.datasetColors[c],colorLabel:u?.label,colorRange:u?[u.min,u.max]:void 0,pointRadius:t.xyPointRadius,drawMode:t.xyDrawMode,lineWidth:t.xyLineWidth,height:e.height,backgroundToken:i,xAxisLine:t.xyXAxisLine,yAxisLine:t.xyYAxisLine,gridLine:t.xyGridLine,fitSettings:t.xyFit,xScale:t.xyXScale,yScale:t.xyYScale,onPlotContextMenu:a}),l)}case`histogram`:{if(r?.kind!==`histogram`)return s;let t=n.histogramDataByPanel[c]??[];return t.length===0?s:o((0,Q.jsx)(D0,{values:t,label:r.histColumn,bins:r.histBins,color:r.histColor,showNormal:r.histNormal,logY:r.histLogY,height:e.height,backgroundToken:i,onPlotContextMenu:a}),t)}case`polar`:{if(r?.kind!==`polar`)return s;let t=n.polarDataByPanel[c]??{angles:[],radii:[]};if(t.angles.length===0)return s;let l=parseFloat(r.polarRadiusMin),u=parseFloat(r.polarRadiusMax);return o((0,Q.jsx)(G0,{angles:t.angles,radii:t.radii,angleLabel:r.polarAngleCol,radiusLabel:r.polarRadiusCol,color:r.polarColor,mode:r.polarMode,radiusMin:Number.isFinite(l)?l:void 0,radiusMax:Number.isFinite(u)?u:void 0,height:e.height,backgroundToken:i,onPlotContextMenu:a}),t)}case`spectrum`:{if(r?.kind!==`spectrum`)return s;let{signal:t,rate:l}=n.spectrumDataByPanel[c]??{signal:[],rate:1};return t.length<4?s:o((0,Q.jsx)(s2,{signal:t,sampleRate:l,label:r.specSignalCol,xMode:r.specXMode,yMode:r.specYMode,window:r.specWindow,color:r.specColor,logX:r.specLogX,height:e.height,backgroundToken:i,onPlotContextMenu:a}),t)}case`boxplot`:{if(r?.kind!==`boxplot`)return s;let t=n.boxplotDataByPanel[c]??[];return t.length===0?s:o((0,Q.jsx)(p2,{groups:t,color:r.boxColor,whiskers:r.boxWhiskers,height:e.height,backgroundToken:i,onPlotContextMenu:a}),t)}case`spectrogram`:{if(r?.kind!==`spectrogram`)return s;let{signal:t,rate:l}=n.spectrogramDataByPanel[c]??{signal:[],rate:1},u=_8(r,!!n.liveConn)?n.liveConn:null,d=r.sgSignalCol,f=u?{version:()=>u.source.version(),samples:()=>u.source.samplesSync(d),latestT:()=>u.source.latestTimeSync(),timeAfter:e=>u.source.timeAfterSync(e),id:u.id,windowSeconds:e.liveWindowSeconds}:void 0;return!f&&t.length<r.sgWindowSize?s:r.sgView===`waterfall`?o((0,Q.jsx)(z2,{signal:t,sampleRate:l,windowSize:r.sgWindowSize,overlap:r.sgOverlap,winFunc:r.sgWinFunc,yMode:r.sgYMode,backgroundToken:i,onPlotContextMenu:a}),t):o((0,Q.jsx)(P2,{signal:f?g8:t,sampleRate:l,windowSize:r.sgWindowSize,overlap:r.sgOverlap,winFunc:r.sgWinFunc,yMode:r.sgYMode,logFreq:r.sgLogFreq,backgroundToken:i,onPlotContextMenu:a,live:f}),t)}case`heatmap`:{if(r?.kind!==`heatmap`)return s;let e=n.heatmapDataByPanel[c]??{cells:[],xLabels:[],yLabels:[]};if(e.cells.length===0&&!(e.grid&&e.grid.w*e.grid.h>0))return s;let t=e=>e!==void 0&&e.trim()!==``&&Number.isFinite(Number(e))?Number(e):void 0;return o((0,Q.jsx)(i4,{cells:e.cells,xLabels:e.xLabels,yLabels:e.yLabels,grid:e.grid,showValues:r.hmShowValues,colorScheme:r.hmColorScheme,xCentres:e.xCentres,yCentres:e.yCentres,contours:r.hmContours??0,vMin:t(r.hmRange?.scaleMin),vMax:t(r.hmRange?.scaleMax),backgroundToken:i,onPlotContextMenu:a}),e)}case`violin`:{if(r?.kind!==`violin`)return s;let e=n.violinDataByPanel[c]??[];return e.some(e=>e.values.length>0)?o((0,Q.jsx)(f4,{groups:e,color:r.vlColor,showBox:r.vlShowBox,bandwidth:parseFloat(r.vlBandwidth)||void 0,orientation:r.vlOrientation,backgroundToken:i,onPlotContextMenu:a}),e):s}case`confusion`:{if(r?.kind!==`confusion`)return s;let e=n.confusionDataByPanel[c]??{actual:[],predicted:[]};return e.actual.length===0?s:o((0,Q.jsx)(y4,{actual:e.actual,predicted:e.predicted,normalize:r.cfNormalize,backgroundToken:i,onPlotContextMenu:a}),e)}case`roc`:{if(r?.kind!==`roc`)return s;let e=n.rocDataByPanel[c]??{scores:[],labels:[]};return e.scores.length===0?s:o((0,Q.jsx)(T4,{scores:e.scores,labels:e.labels,mode:r.rocMode,color:r.rocColor,backgroundToken:i,onPlotContextMenu:a}),e)}case`losscurve`:{if(r?.kind!==`losscurve`)return s;let e=n.lossCurveDataByPanel[c]??{xValues:[],series:[]};return e.series.length===0?s:o((0,Q.jsx)(D4,{xValues:e.xValues,series:e.series,xLabel:r.lcXCol||`Step`,backgroundToken:i,onPlotContextMenu:a}),e)}case`controlchart`:{if(r?.kind!==`controlchart`)return s;let e=n.controlChartDataByPanel[c];return!e||e.length<2?s:o((0,Q.jsx)(N4,{points:e,sigmaLevel:r.ccSigmaLevel,color:r.ccColor,backgroundToken:i,onPlotContextMenu:a}),e)}case`parallelcoords`:{if(r?.kind!==`parallelcoords`)return s;let e=n.parallelCoordsDataByPanel[c];if(!e||e.length===0||r.pcColumns.length<2)return s;let t=r.pcColorByCol?n.numericCols.includes(r.pcColorByCol):!1;return o((0,Q.jsx)(z4,{rows:e,axes:r.pcColumns,color:r.pcColor,colorByNumeric:t,backgroundToken:i,onPlotContextMenu:a}),e)}case`embedding`:{if(r?.kind!==`embedding`)return s;let e=n.embeddingDataByPanel[c];return!e||e.length===0?s:o((0,Q.jsx)(Y4,{points:e,color:r.emColor,colorByNumeric:r.emColorMode===`numeric`&&!!r.emColorCol,pointSize:r.emPointSize,backgroundToken:i,onPlotContextMenu:a}),e)}case`flamegraph`:{if(r?.kind!==`flamegraph`)return s;let e=n.flameGraphDataByPanel[c]??[];return e.length===0?s:o((0,Q.jsx)(r3,{nodes:e,direction:r.fgDirection,backgroundToken:i,onPlotContextMenu:a}),e)}case`barchart`:{if(r?.kind!==`barchart`)return s;let e=n.barChartDataByPanel[c]??{groups:[],seriesNames:[]};if(e.groups.length===0&&!e.columns?.length)return s;let t=e=>e!==void 0&&e.trim()!==``&&Number.isFinite(Number(e))?Number(e):void 0,l=r.bcValueScale?{min:t(r.bcValueScale.scaleMin),max:t(r.bcValueScale.scaleMax)}:void 0;return o((0,Q.jsx)(l3,{groups:e.columns?void 0:e.groups,columns:e.columns,seriesNames:e.seriesNames,mode:r.bcMode,horizontal:r.bcHorizontal,valueRange:l,backgroundToken:i,onPlotContextMenu:a}),e)}case`radar`:{if(r?.kind!==`radar`)return s;let e=n.radarDataByPanel[c]??{axes:[],series:[]};return e.axes.length<3?s:o((0,Q.jsx)(p3,{axes:e.axes,series:e.series,fill:r.rdFill,color:r.rdColor,backgroundToken:i,onPlotContextMenu:a}),e)}case`areachart`:{if(r?.kind!==`areachart`)return s;let e=n.areaChartDataByPanel[c]??[];if(e.length===0)return s;let t=e=>e!==void 0&&e.trim()!==``&&Number.isFinite(Number(e))?Number(e):void 0,l=r.acYScale?{min:t(r.acYScale.scaleMin),max:t(r.acYScale.scaleMax)}:void 0;return o((0,Q.jsx)(_3,{series:e,stacked:r.acStacked,yRange:l,backgroundToken:i,onPlotContextMenu:a}),e)}case`cdfchart`:{if(r?.kind!==`cdfchart`)return s;let e=n.cdfChartDataByPanel[c]??[];return e.length===0?s:o((0,Q.jsx)(b3,{series:e,complement:r.cdComplement,logX:r.cdLogX,backgroundToken:i,onPlotContextMenu:a}),e)}case`bubblechart`:{if(r?.kind!==`bubblechart`)return s;let e=n.bubbleChartDataByPanel[c];return!e||e.length===0?s:o((0,Q.jsx)(O3,{points:e,color:r.bbColor,colorByNumeric:r.bbColorMode===`numeric`,maxRadius:r.bbMaxRadius,backgroundToken:i,onPlotContextMenu:a}),e)}case`treemap`:{let e=n.treemapDataByPanel[c]??[];return e.length===0?s:o((0,Q.jsx)(N3,{nodes:e,backgroundToken:i,onPlotContextMenu:a}),e)}case`sankey`:{let e=n.sankeyDataByPanel[c]??{nodeNames:[],links:[]};return e.links.length===0?s:o((0,Q.jsx)(z3,{nodeNames:e.nodeNames,links:e.links,backgroundToken:i,onPlotContextMenu:a}),e)}case`calibration`:{if(r?.kind!==`calibration`)return s;let e=n.calibrationDataByPanel[c]??[];return e.length===0?s:o((0,Q.jsx)(V3,{bins:e,color:r.cbColor,backgroundToken:i,onPlotContextMenu:a}),e)}case`qqplot`:{if(r?.kind!==`qqplot`)return s;let e=n.qqPlotDataByPanel[c];return!e||e.length===0?s:o((0,Q.jsx)(U3,{points:e,color:r.qqColor,backgroundToken:i,onPlotContextMenu:a}),e)}case`gauge`:{if(r?.kind!==`gauge`)return s;let e=n.gaugeDataByPanel[c]??[];if(e.length===0)return s;let t=n.liveConn??(n.liveOverlays?.length===1?n.liveOverlays[0].conn:void 0);return o((0,Q.jsx)(n6,{gauges:e,live:t?{latestT:()=>t.source.latestTimeSync(),timeAfter:e=>t.source.timeAfterSync(e),valueAt:(e,n)=>t.source.xAtTimeSync(e,n,!0)}:void 0,backgroundToken:i,onPlotContextMenu:a}),e)}case`gantt`:{let e=n.ganttDataByPanel[c]??[];return e.length===0?s:o((0,Q.jsx)(J3,{tasks:e,backgroundToken:i,onPlotContextMenu:a}),e)}}return s}var x8=500,S8=1e3;function C8(e){if(Array.isArray(e))return w8(e);if(!e||typeof e!=`object`)return null;let t=-1;for(let n of Object.values(e))Array.isArray(n)&&(t=Math.max(t,w8(n)));return t<0?null:t}function w8(e){let t=e=>!!e&&typeof e==`object`&&e.x instanceof Float64Array;return e.length>0&&t(e[0])?e.reduce((e,n)=>e+(t(n)?n.length:0),0):e.length}function T8(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e4?`${Math.round(e/1e3)}k`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function E8({stats:e,host:t}){let[n,r]=(0,Z.useState)(null);if((0,Z.useEffect)(()=>{let n=t.current?.ownerDocument.defaultView??window,i=0,a=0,o=0,s=-1,c=-1,l=e.renders,u=t.current?uZ(t.current):0,d=f=>{c>=0&&f-s>S8&&(c=f,s=f,a=0,o=0,l=e.renders,u=t.current?uZ(t.current):0),c<0?(c=f,s=f):f!==s&&(o=Math.max(o,f-s),s=f,a++);let p=f-c;if(p>=x8){let i=t.current,s=0;if(i)for(let e of i.getElementsByTagName(`canvas`))s+=e.width*e.height;let d=n.performance.memory,m=i?uZ(i):0;r({fps:a*1e3/p,repaints:(m-u)*1e3/p,worstFrameMs:o,renderMs:e.lastRenderMs,rendersPerSec:(e.renders-l)*1e3/p,points:C8(e.data),domNodes:i?i.getElementsByTagName(`*`).length:0,canvasMp:s/1e6,heapMb:d?d.usedJSHeapSize/1048576:null,live:(()=>{let e=FZ();return e?{age:Date.now()/1e3-e.newest,lag:e.lag,wait:e.wait,waitAge:e.waitAge}:null})()}),a=0,o=0,c=f,l=e.renders,u=m}i=n.requestAnimationFrame(d)};return i=n.requestAnimationFrame(d),()=>n.cancelAnimationFrame(i)},[e,t]),!n)return null;let i=n.fps<20?`var(--danger, #e5484d)`:n.fps<45?`var(--accent, #f5a524)`:void 0;return(0,Q.jsx)(`dl`,{className:`kymo-perf-hud`,style:D8,children:[[`FPS`,n.fps.toFixed(0),i],[`Repaints/s`,n.repaints.toFixed(0)],[`Slowest frame`,`${n.worstFrameMs.toFixed(1)} ms`],[`Render`,`${n.renderMs.toFixed(1)} ms`],[`Renders/s`,n.rendersPerSec.toFixed(1)],...n.points===null?[]:[[`Points`,T8(n.points)]],[`DOM nodes`,T8(n.domNodes)],[`Canvas`,`${n.canvasMp.toFixed(2)} MP`],...n.heapMb===null?[]:[[`JS heap`,`${n.heapMb.toFixed(0)} MB`]],...n.live?[[`Data age`,`${n.live.age.toFixed(2)} s`],[`Live lag`,`${n.live.lag.toFixed(2)} s`],[`Late by`,`${n.live.wait.toFixed(2)} s · ${n.live.waitAge.toFixed(0)} s ago`]]:[]].map(([e,t,n])=>(0,Q.jsxs)(`div`,{style:O8,children:[(0,Q.jsx)(`dt`,{style:k8,children:e}),(0,Q.jsx)(`dd`,{style:n?{...A8,color:n}:A8,children:t})]},e))})}var D8={position:`absolute`,top:8,right:8,zIndex:60,flex:`none`,pointerEvents:`none`,userSelect:`none`,margin:0,padding:`6px 9px`,minWidth:148,display:`grid`,gap:1,font:`500 10.5px/1.35 var(--font-sans, system-ui)`,fontVariantNumeric:`tabular-nums`,fontFeatureSettings:`"tnum" 1`,color:`var(--text-strong, #f3f5fa)`,background:`color-mix(in oklch, var(--bg-elevated, #1b2130) 86%, transparent)`,border:`1px solid var(--border, #33405a)`,borderRadius:6,boxShadow:`0 4px 14px color-mix(in oklch, black 28%, transparent)`},O8={display:`flex`,justifyContent:`space-between`,gap:12},k8={color:`var(--text-muted, #8a93a6)`},A8={margin:0,fontWeight:600,textAlign:`right`},j8=[],M8=3;function N8(e,t,n,r){return e.anchor===`x`&&!r?null:e.points.map(([i,a])=>[e.anchor===`x`?ZZ(r,i):i*t,a*n])}function P8(e,t,n,r,i){return t.map(([t,a])=>[e.anchor===`x`&&i?QZ(i,t):F8(t/Math.max(1,n)),F8(a/Math.max(1,r))])}var F8=e=>Math.round(e*1e4)/1e4,I8=(0,Z.memo)(function({annotations:e,tool:t,plotFrame:n,onChange:r,onToolEnd:i,onSelect:a,marks:o=j8,onMarkSelect:s}){let c=(0,Z.useRef)(null),l=(0,Z.useSyncExternalStore)(n.subscribe,n.get),u=l?.x?l:null,[d,f]=(0,Z.useState)({w:0,h:0}),[p,m]=(0,Z.useState)(null),[h,g]=(0,Z.useState)(null),[_,v]=(0,Z.useState)(null),y=(0,Z.useRef)({annotations:e,onChange:r,onToolEnd:i,onSelect:a,tool:t,selected:p,editing:h,frame:u,size:d});y.current={annotations:e,onChange:r,onToolEnd:i,onSelect:a,tool:t,selected:p,editing:h,frame:u,size:d};let b=e=>{y.current.selected!==e&&(y.current.selected=e,m(e),y.current.onSelect(e))};(0,Z.useLayoutEffect)(()=>{let e=c.current;if(!e)return;let t=e.ownerDocument.defaultView??window,n=()=>f({w:e.clientWidth,h:e.clientHeight});n();let r=new t.ResizeObserver(n);return r.observe(e),()=>r.disconnect()},[]),(0,Z.useEffect)(()=>{t&&b(null)}),(0,Z.useEffect)(()=>{p&&!e.some(e=>e.id===p)&&b(null)}),(0,Z.useEffect)(()=>()=>{y.current.selected&&y.current.onSelect(null)},[]),(0,Z.useEffect)(()=>{let e=c.current?.ownerDocument;if(!e)return;let t=e=>{let{selected:t,editing:n,tool:r,annotations:i,onChange:a,onToolEnd:o}=y.current;if(!(n||G8(e.target))){if(e.key===`Escape`&&r){o();return}t&&(e.key===`Delete`||e.key===`Backspace`?(e.preventDefault(),a(i.filter(e=>e.id!==t)),b(null)):e.key===`Escape`&&b(null))}},n=e=>{let t=y.current.selected,n=e.target;t&&!n?.closest?.(`[data-ann-id="${CSS.escape(t)}"], [data-kymo-annotation-controls]`)&&b(null)};return e.addEventListener(`keydown`,t),e.addEventListener(`pointerdown`,n,!0),()=>{e.removeEventListener(`keydown`,t),e.removeEventListener(`pointerdown`,n,!0)}},[]);let{w:C,h:w}=d,T=e=>{let t=c.current.getBoundingClientRect();return[e.clientX-t.left,e.clientY-t.top]},E=(e,t)=>{let n=c.current.ownerDocument,r=t=>e(T(t),t),i=()=>{n.removeEventListener(`pointermove`,r),n.removeEventListener(`pointerup`,i),n.removeEventListener(`pointercancel`,i),t()};n.addEventListener(`pointermove`,r),n.addEventListener(`pointerup`,i),n.addEventListener(`pointercancel`,i)},D=e=>r([...y.current.annotations,e]),O=e=>r(y.current.annotations.map(t=>t.id===e.id?e:t)),k=e=>{if(!t||e.button!==0||h)return;e.preventDefault(),e.stopPropagation();let n=T(e),r={id:crypto.randomUUID(),kind:t.kind,color:t.color,width:t.width,...u?{anchor:`x`}:{}},i=e=>P8(r,e,C,w,u);if(t.kind===`text`){v({...r,points:i([n]),text:``}),g(r.id);return}let a=t.kind===`brush`?[n]:[n,n],o={...r,points:i(a)};v(o);let s=!1;E((t,n)=>{if(s||=Math.hypot(n.clientX-e.clientX,n.clientY-e.clientY)>M8,r.kind===`brush`){let e=a[a.length-1];if(Math.hypot(t[0]-e[0],t[1]-e[1])<2)return;a=[...a,t]}else a=[a[0],t];o={...o,points:i(a)},v(o)},()=>{v(null),s&&o.points.length>=2&&D(o)})},A=(e,t,n)=>{let r=N8(t,C,w,u);if(!r)return;let i=T(e),a=null;E((o,s)=>{if(!a&&Math.hypot(s.clientX-e.clientX,s.clientY-e.clientY)<=M8)return;let{size:c,frame:l}=y.current;a={...t,points:P8(t,n(r,[o[0]-i[0],o[1]-i[1]],o),c.w,c.h,l)},v(a)},()=>{v(null),a&&O(a)})},j=(e,n)=>{t||e.button!==0||h===n.id||(e.preventDefault(),e.stopPropagation(),b(n.id),A(e,n,(e,[t,n])=>e.map(([e,r])=>[e+t,r+n])))},M=(e,t,n)=>{e.button===0&&(e.preventDefault(),e.stopPropagation(),A(e,t,(e,r,i)=>{let a=e.map(e=>[...e]);return t.kind===`arrow`?a[n]=i:(a[+(n===1||n===2)][0]=i[0],a[+(n===2||n===3)][1]=i[1]),a}))},N=e=>{t||e.kind!==`text`&&e.kind!==`box`||(b(e.id),g(e.id))},P=e=>{let t=h;g(null);let n=_&&_.id===t?_:null;if(v(null),e===null||!t)return;let i=e.replace(/\s+$/,``),a=y.current.annotations;if(n){i&&D({...n,text:i});return}let o=a.find(e=>e.id===t);o&&(!i&&o.kind===`text`?r(a.filter(e=>e.id!==t)):O(W8(o,i)))},F=e=>{r(y.current.annotations.filter(t=>t.id!==e)),b(null)},I=(_?e.some(e=>e.id===_.id)?e.map(e=>e.id===_.id?_:e):[...e,_]:e).flatMap(e=>{let t=N8(e,C,w,u);return t?[{a:e,px:t}]:[]}),L=p?I.find(e=>e.a.id===p):void 0,R=u?o.map(e=>{let t=N8(S(e,u.x.v1),C,w,u);return{m:e,x0:Math.min(t[0][0],t[1][0]),x1:Math.max(t[0][0],t[1][0])}}):[],z=L&&L.a.kind!==`text`?U8(L.px):null,B=e=>(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`svg`,{className:`kymo-ann-svg`,width:C,height:w,viewBox:`0 0 ${C} ${w}`,"aria-hidden":`true`,children:e.map(({a:e,px:t})=>e.kind===`text`?null:(0,Q.jsx)(`g`,{"data-ann-id":e.id,className:`kymo-ann kymo-ann--${e.kind}`,onPointerDown:t=>j(t,e),onDoubleClick:()=>N(e),children:(0,Q.jsx)(z8,{a:e,px:t})},e.id))}),e.map(({a:e,px:t})=>{if(e.kind!==`text`&&e.kind!==`box`)return null;let n=h===e.id;if(!n&&!e.text)return null;let r=e.kind===`text`?{left:t[0][0],top:t[0][1]}:{left:Math.min(t[0][0],t[1][0]),top:Math.min(t[0][1],t[1][1]),transform:`translateY(calc(-100% - 3px))`};return(0,Q.jsxs)(`div`,{"data-ann-id":e.id,className:`kymo-ann-text kymo-ann-text--${e.kind}${p===e.id&&e.kind===`text`?` is-selected`:``}`,style:{...r,color:e.color,fontSize:e.kind===`text`?e.width:12},onPointerDown:t=>j(t,e),onDoubleClick:()=>N(e),children:[n?(0,Q.jsx)(R8,{initial:e.text??``,onDone:P}):e.text,p===e.id&&e.kind===`text`&&!n?(0,Q.jsx)(L8,{onDelete:()=>F(e.id),style:{right:-11,top:-11}}):null]},`t-${e.id}`)})]});return(0,Q.jsx)(`div`,{ref:c,className:`kymo-annotations${t?` is-drawing is-tool-${t.kind}`:``}`,onPointerDown:k,onContextMenu:t?e=>e.preventDefault():void 0,children:C>0&&w>0?(0,Q.jsxs)(Q.Fragment,{children:[u&&R.length?(0,Q.jsx)(`div`,{className:`kymo-ann-clip`,style:{clipPath:`inset(0 ${Math.max(0,C-u.left-u.width)}px 0 ${Math.max(0,u.left)}px)`},children:(0,Q.jsx)(`svg`,{className:`kymo-ann-svg kymo-marks`,width:C,height:w,viewBox:`0 0 ${C} ${w}`,children:R.map(({m:e,x0:t,x1:n})=>(0,Q.jsxs)(`g`,{"data-mark":e.ruleId,role:`img`,"aria-label":`${e.late?`Late · `:``}${e.ruleName}, ${e.severity}`,className:`kymo-mark kymo-mark--${e.severity}${e.late?` kymo-mark--late`:``}`,style:{color:x[e.severity]},children:[(0,Q.jsx)(`rect`,{x:t,y:u.top,width:Math.max(1,n-t),height:u.height,fill:`currentColor`,fillOpacity:.12}),(0,Q.jsx)(`rect`,{x:t,y:u.top,width:Math.max(1,n-t),height:2,fill:`currentColor`}),(0,Q.jsx)(`rect`,{className:`kymo-mark-hit`,x:t,y:u.top,width:Math.max(6,n-t),height:8,onPointerDown:t=>{t.stopPropagation(),s?.(e.ruleId)}})]},e.id))})}):null,B(I.filter(e=>e.a.anchor!==`x`)),u?(0,Q.jsx)(`div`,{className:`kymo-ann-clip`,style:{clipPath:`inset(0 ${Math.max(0,C-u.left-u.width)}px 0 ${Math.max(0,u.left)}px)`},children:B(I.filter(e=>e.a.anchor===`x`))}):null,(0,Q.jsxs)(`svg`,{className:`kymo-ann-svg`,width:C,height:w,viewBox:`0 0 ${C} ${w}`,"aria-hidden":`true`,children:[z?(0,Q.jsx)(`rect`,{className:`kymo-ann-selection`,x:z.x-6,y:z.y-6,width:z.w+12,height:z.h+12,rx:4}):null,L&&!h&&(L.a.kind===`box`||L.a.kind===`arrow`)?(0,Q.jsx)(`g`,{"data-ann-id":L.a.id,children:B8(L.a,L.px).map(([e,t],n)=>(0,Q.jsx)(`rect`,{className:`kymo-ann-handle kymo-ann-handle--${L.a.kind===`arrow`?`end`:n%2?`nesw`:`nwse`}`,x:e-4.5,y:t-4.5,width:9,height:9,rx:2,onPointerDown:e=>M(e,L.a,n)},n))}):null]}),z&&!h?(0,Q.jsx)(L8,{onDelete:()=>F(L.a.id),id:L.a.id,style:{left:Math.min(C-12,z.x+z.w+6)-10,top:Math.max(10,z.y-6)-10}}):null]}):null})});function L8({onDelete:e,style:t,id:n}){return(0,Q.jsx)(`button`,{type:`button`,className:`kymo-ann-delete`,style:t,"data-ann-id":n,"aria-label":`Delete annotation`,title:`Delete (Del)`,onPointerDown:e=>e.stopPropagation(),onClick:e,children:(0,Q.jsx)(`svg`,{viewBox:`0 0 10 10`,width:`8`,height:`8`,"aria-hidden":`true`,children:(0,Q.jsx)(`path`,{d:`M2 2l6 6M8 2l-6 6`})})})}function R8({initial:e,onDone:t}){let n=(0,Z.useRef)(null),r=(0,Z.useRef)(!1),i=e=>{r.current||(r.current=!0,t(e))};return(0,Z.useLayoutEffect)(()=>{let t=n.current;if(!t)return;t.textContent=e,t.focus();let r=t.ownerDocument.createRange();r.selectNodeContents(t);let i=t.ownerDocument.defaultView?.getSelection();i?.removeAllRanges(),i?.addRange(r)},[]),(0,Q.jsx)(`div`,{ref:n,className:`kymo-ann-editor`,contentEditable:`plaintext-only`,suppressContentEditableWarning:!0,role:`textbox`,"aria-label":`Annotation text`,"aria-multiline":`true`,onPointerDown:e=>e.stopPropagation(),onKeyDown:e=>{e.stopPropagation(),e.key===`Enter`&&!e.shiftKey?(e.preventDefault(),i(n.current?.innerText??``)):e.key===`Escape`&&(e.preventDefault(),i(null))},onBlur:()=>i(n.current?.innerText??``)})}function z8({a:e,px:t}){let n={stroke:e.color,strokeWidth:e.width,fill:`none`,strokeLinecap:`round`,strokeLinejoin:`round`},r=t=>(0,Q.jsx)(`path`,{className:`kymo-ann-hit`,d:t,strokeWidth:Math.max(12,e.width+10)});switch(e.kind){case`box`:{let[[i,a],[o,s]]=t,c=`M${i} ${a}H${o}V${s}H${i}Z`;return(0,Q.jsxs)(Q.Fragment,{children:[r(c),(0,Q.jsx)(`path`,{d:c,...n}),(0,Q.jsx)(`path`,{d:c,fill:e.color,fillOpacity:.06,stroke:`none`,pointerEvents:`none`})]})}case`arrow`:{let[[i,a],[o,s]]=t,c=H8(i,a,o,s,e.width);return(0,Q.jsxs)(Q.Fragment,{children:[r(`M${i} ${a}L${o} ${s}`),(0,Q.jsx)(`path`,{d:`M${i} ${a}L${c.base[0]} ${c.base[1]}`,...n}),(0,Q.jsx)(`path`,{d:c.d,fill:e.color,stroke:e.color,strokeWidth:1,strokeLinejoin:`round`})]})}case`brush`:{let e=V8(t);return(0,Q.jsxs)(Q.Fragment,{children:[r(e),(0,Q.jsx)(`path`,{d:e,...n})]})}}return null}function B8(e,t){if(e.kind===`arrow`)return t;let[[n,r],[i,a]]=t;return[[n,r],[i,r],[i,a],[n,a]]}function V8(e){if(e.length===0)return``;if(e.length<3)return`M${e[0][0]} ${e[0][1]}`+e.slice(1).map(([e,t])=>`L${e} ${t}`).join(``);let t=`M${e[0][0]} ${e[0][1]}`;for(let n=1;n<e.length-1;n++){let[r,i]=e[n],[a,o]=e[n+1];t+=`Q${r} ${i} ${(r+a)/2} ${(i+o)/2}`}let[n,r]=e[e.length-1];return t+`L${n} ${r}`}function H8(e,t,n,r,i){let a=Math.max(9,i*4),o=Math.atan2(r-t,n-e),s=.42,c=[n-a*Math.cos(o-s),r-a*Math.sin(o-s)],l=[n-a*Math.cos(o+s),r-a*Math.sin(o+s)],u=[n-a*.8*Math.cos(o),r-a*.8*Math.sin(o)];return{d:`M${n} ${r}L${c[0]} ${c[1]}L${l[0]} ${l[1]}Z`,base:u,l:c,r:l}}function U8(e){let t=e.map(e=>e[0]),n=e.map(e=>e[1]),r=Math.min(...t),i=Math.min(...n);return{x:r,y:i,w:Math.max(...t)-r,h:Math.max(...n)-i}}function W8(e,t){if(t)return{...e,text:t};let{text:n,...r}=e;return r}function G8(e){let t=e;return!!t&&(t.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName))}function K8(e,t,n,r,i,a,o){e.save(),e.scale(i,i),e.lineCap=`round`,e.lineJoin=`round`;for(let i of t){let t=N8(i,n,r,o);t&&(e.save(),i.anchor===`x`&&o&&(e.beginPath(),e.rect(o.left,0,o.width,r),e.clip()),q8(e,i,t,a),e.restore())}e.restore()}function q8(e,t,n,r){if(e.strokeStyle=t.color,e.fillStyle=t.color,e.lineWidth=t.width,t.kind===`box`)e.strokeRect(n[0][0],n[0][1],n[1][0]-n[0][0],n[1][1]-n[0][1]);else if(t.kind===`brush`)e.stroke(new Path2D(V8(n)));else if(t.kind===`arrow`){let r=H8(n[0][0],n[0][1],n[1][0],n[1][1],t.width);e.beginPath(),e.moveTo(n[0][0],n[0][1]),e.lineTo(r.base[0],r.base[1]),e.stroke(),e.beginPath(),e.moveTo(n[1][0],n[1][1]),e.lineTo(r.l[0],r.l[1]),e.lineTo(r.r[0],r.r[1]),e.closePath(),e.fill()}if(!t.text)return;let i=t.kind===`text`?t.width:12;e.font=`600 ${i}px ${r}`,e.textBaseline=`top`;let a=t.text.split(`
|
|
634
|
+
`),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 J8={solid:void 0,dashed:`5 4`,dotted:`1 4`};function Y8(e,t,n){if(!e||!(n===`x`?e.x:e.y))return null;if(n===`x`){let n=ZZ(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=$Z(e,t.value);return r>=e.top-.5&&r<=e.top+e.height+.5?[e.left,r,e.left+e.width,r]:null}var X8=(0,Z.memo)(function({frame:e,alarm:t,axis:n}){let r=Y8((0,Z.useSyncExternalStore)(e.subscribe,e.get),t,n);if(!r)return null;let i=t.linked?Z8(r,n):null;return(0,Q.jsxs)(`svg`,{className:`kymo-alarm`,"aria-hidden":`true`,children:[(0,Q.jsx)(`line`,{x1:r[0],y1:r[1],x2:r[2],y2:r[3],stroke:t.color,strokeWidth:t.width,strokeDasharray:t.linked===`active`?oQ.join(` `):J8[t.style]}),i?(0,Q.jsx)(`path`,{"data-alert-glyph":``,d:aQ,transform:`translate(${i[0]} ${i[1]})`,fill:t.color}):null]})});function Z8(e,t){return t===`y`?[e[2]-10-3,e[1]-10-2]:[e[0]+3,e[1]+2]}function Q8(e,t,n,r,i){let a=Y8(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`?oQ:J8[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=Z8(a,r);cQ(e,t[0],t[1],n.color)}e.restore()}}function $8(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,i5(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 e5=new WeakMap;function t5(e,t){let n=e5.get(e);n||e5.set(e,n=new Map);let r=n.get(t);return r||n.set(t,r=n=>e.view.setLiveWindow(n,t)),r}var n5=class{mounts=new Map;version=0;listeners=new Set;root=null;engine;constructor(e){this.engine=e}subscribe=e=>(this.listeners.add(e),()=>{this.listeners.delete(e)});getVersion=()=>this.version;bump(){this.version++;for(let e of[...this.listeners])e()}add(e){this.mounts.set(e.key,e),this.root||(this.root=(0,uX.createRoot)(document.createElement(`div`)),this.root.render((0,Q.jsx)(u5,{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}},r5=new WeakMap;function i5(e){let t=r5.get(e);return t||(t=new n5(e),r5.set(e,t)),t}function a5(e,t,n,r={}){e.charts.get(t);let i=i5(e),a={key:crypto.randomUUID(),chartId:t,element:n,options:r,shiftDatasetId:null,emitter:mX(),xyz:null,annotationTool:null,selectedAnnotation:null,plotFrame:nQ(),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 SE(`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 SE(`export_failed`,{reason:`canvas unavailable`}));for(let e of r)o.drawImage(e,0,0);let s=e.charts.get(t),c=b5(s.settings,D9(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=C5(s.annotations,d?x5(u.marks,u.selection,d.xKey):[],l),p=Re(c);return p&&n.clientWidth>0&&Q8(o,a.plotFrame.get(),p.alarm,p.axis,i.width/n.clientWidth),f.length&&n.clientWidth>0&&K8(o,f,n.clientWidth,n.clientHeight,i.width/n.clientWidth,X.sans,l),new Promise((e,t)=>i.toBlob(n=>n?e(n):t(new SE(`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 o5(e){r5.get(e)?.refresh()}function s5(e){r5.get(e)?.dispose(),r5.delete(e)}function c5(e){let t=new MutationObserver(e);return t.observe(document.documentElement,{attributes:!0,attributeFilter:[`data-color-scheme`,`class`,`data-theme`]}),()=>t.disconnect()}var l5=()=>{let e=document.documentElement;return`${e.getAttribute(`data-color-scheme`)??``}|${e.getAttribute(`data-theme`)??``}|${e.className}`};function u5({engine:e,registry:t}){(0,Z.useSyncExternalStore)(t.subscribe,t.getVersion);let n=D9(e),r=(0,Z.useSyncExternalStore)(n.store.subscribe,n.store.get),i=new Map;for(let e of t.mounts.values()){let t=r.worksheets.find(t=>t.panels.some(t=>t.id===e.chartId));if(!t)continue;let n=i.get(t.id)??{worksheet:t,mounts:[]};n.mounts.push(e),i.set(t.id,n)}return(0,Q.jsx)(Q.Fragment,{children:[...i.values()].map(t=>(0,Q.jsx)(m5,{engine:e,worksheet:t.worksheet,mounts:t.mounts},t.worksheet.id))})}var d5=1e3,f5=.25;function p5(e,t,n,r){let[i,a]=(0,Z.useState)(0),o=(0,Z.useRef)(0),s=(0,Z.useRef)(0);return(0,Z.useEffect)(()=>{o.current&&=(s.current=performance.now()-o.current,0)}),(0,Z.useEffect)(()=>{if(!n)return;let i=0,c=-1,l=0,u=n=>{if(i=oZ(u),o.current||n<l||dZ()||!r())return;let d=0;for(let n of e)t.includes(n.id)&&(d+=n.source.version());d!==c&&(c=d,l=n+s.current*(1/f5-1),o.current=performance.now(),(0,Z.startTransition)(()=>a(e=>e+1)))};return i=oZ(u),()=>sZ(i)},[n,e,t]),(0,Z.useMemo)(()=>n?e.map(e=>t.includes(e.id)?{...e,dataset:e.source.snapshot(d5)}:e):e,[e,t,n,i])}function m5({engine:e,worksheet:t,mounts:n}){let r=D9(e),i=(0,Z.useSyncExternalStore)(r.store.subscribe,r.store.get),a=r.derived(),o=i.xRanges[t.id]??null,s=(0,Z.useMemo)(()=>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=(0,Z.useRef)(n);d.current=n;let f=(0,Z.useRef)(()=>d.current.some(e=>e.element.isConnected&&(typeof e.element.checkVisibility!=`function`||e.element.checkVisibility()))).current,p=p5(s,i.selection,u,f),m=r.alertLines(),h=f8({worksheet:v5(t,m),viewXRange:o,selectedIds:i.selection,selectedDatasets:a.selectedDatasets,liveConnections:p,mathChannels:a.channels,datasetOffsets:i.offsets,datasetColors:i.colors,datasetPalette:i.palette}),g=(0,Z.useRef)(dX()).current,_=(0,Z.useSyncExternalStore)(c5,l5),v=t.id,y=t5(e,v),b=i.licensed,x=a.selectedLive[0]??null,S=e=>i.datasets.find(t=>t.id===e)??Object.values(a.laps).flatMap(e=>e.laps).find(t=>t.id===e);return(0,Q.jsx)(Q.Fragment,{children:n.map(n=>{let r=t.panels.find(e=>e.id===n.chartId);if(!r)return null;let s=n.shiftDatasetId?a.selectedDatasets.find(e=>e.id===n.shiftDatasetId):void 0,c=$8(n,e,v),l=b5(t.panelChartSettings[r.id],m);return(0,lX.createPortal)((0,Q.jsx)(D5,{mount:n,annotations:t.panelChartSettings[r.id]?.annotations,marks:x5(i.marks,i.selection,t.xKey),onMarkSelect:c.onMarkSelect,alarm:Re(l),onAnnotations:c.onAnnotations,onAnnotationToolEnd:c.onAnnotationToolEnd,onAnnotationSelect:c.onAnnotationSelect,render:u=>y8({panel:r,settings:l,background:n.options.style?.background??t.panelChartBackgrounds[r.id]??null,styleToken:JSON.stringify([_,n.options.theme,n.options.style,X]),data:h,xKey:t.xKey,height:u,viewXRange:o,onViewXRangeChange:c.onViewXRangeChange,onCursorX:c.onCursorX,liveZoom:g,liveWindowSeconds:t.liveWindowSeconds===void 0?i.liveWindowSeconds:t.liveWindowSeconds,onLiveWindowChange:y,beaconLive:x,findDataset:S,live:i.live,selection:i.selection,cursor:c.cursor,video:e.video.sources(),recordings:v6(a.selectedDatasets,i.offsets),shiftMode:s?h5(e,s.id,s.name):void 0,onContextMenu:c.onContextMenu,xyzRef:c.xyzRef}),licensed:b},n.key),n.element,n.key)})})}function h5(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 g5=[],_5=new WeakMap;function v5(e,t){if(!t.size)return e;let n=_5.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]=b5(a,t),i[n]!==a&&(r=!0);let a=r?{...e,panelChartSettings:i}:e;return _5.set(e,{lines:t,out:a}),a}var y5=new WeakMap;function b5(e,t){if(!e||!t.size)return e;let n=y5.get(e);if(n&&n.lines===t)return n.out;let r=Ie(e,t);return y5.set(e,{lines:t,out:r}),r}var x5=w5((e,t,n)=>{let r=e.filter(e=>e.timeColumn===n&&t.includes(e.targetId));return r.length?r:S5}),S5=[];function C5(e,t,n){return!t.length||!n?.x?e:[...t.map(e=>S(e,n.x.v1)),...e]}function w5(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 T5(e,t){e.data=t}function E5(e,t){e.status!==t&&(e.status=t,e.emitter.emit(`status`,t))}function D5({mount:e,render:t,licensed:n,annotations:r,marks:i,alarm:a,onAnnotations:o,onAnnotationToolEnd:s,onAnnotationSelect:c,onMarkSelect:l}){let u=(0,Z.useRef)(null),[d,f]=(0,Z.useState)(0),p=!!e.options.debug,m=(0,Z.useRef)({renderStart:0,lastRenderMs:0,renders:0,data:null}).current;p&&(m.renderStart=performance.now()),(0,Z.useLayoutEffect)(()=>{p&&(m.lastRenderMs=performance.now()-m.renderStart,m.renders++)}),(0,Z.useLayoutEffect)(()=>{let e=u.current;if(!e)return;let t=()=>f(Math.max(120,Math.floor(e.clientHeight)));t();let n=new fZ(t);return n.observe(e),()=>n.disconnect()},[]);let{status:h,node:g,data:_}=t(d||400);m.data=_,(0,Z.useEffect)(()=>{T5(e,_)}),(0,Z.useEffect)(()=>{E5(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),(0,Q.jsxs)(`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:[(0,Q.jsx)(rQ.Provider,{value:e.plotFrame.set,children:g}),h===`ready`&&a?(0,Q.jsx)(X8,{frame:e.plotFrame,alarm:a.alarm,axis:a.axis}):null,h===`ready`&&(r?.length||e.annotationTool||i.length)?(0,Q.jsx)(I8,{annotations:r??g5,tool:e.annotationTool,plotFrame:e.plotFrame,onChange:o,onToolEnd:s,onSelect:c,marks:i,onMarkSelect:l}):null,p?(0,Q.jsx)(E8,{stats:m,host:u}):null,n===!1?(0,Q.jsx)(pX,{}):null]})}var O5=new WeakMap;function k5(e,t,n,r={}){let i=O5.get(e)??new Map;O5.set(e,i);let a=i.get(t);if(a&&!a.window.closed)return a.window.focus(),a;let o=e.charts.get(t),s=r.title??(o.title||e.charts.label(o.kind));for(let e of i.values())e.window.closed||e.window.focus();let c=40*(i.size+1),l=window.open(``,`kymoscope-chart-${t}`,`popup,width=${r.width??960},height=${r.height??600},left=${r.left??window.screenX+c},top=${r.top??window.screenY+c}`);if(!l)throw new SE(`popup_blocked`,{chartId:t});let u=l.document;u.head.replaceChildren(),u.body.replaceChildren(),u.title=s;for(let e of document.querySelectorAll(`style, link[rel="stylesheet"]`)){let t=e.cloneNode(!0);t instanceof HTMLLinkElement&&(t.href=e.href),u.head.appendChild(t)}let d=()=>{for(let e of[...u.documentElement.attributes])u.documentElement.removeAttribute(e.name);for(let e of document.documentElement.attributes)u.documentElement.setAttribute(e.name,e.value);u.body.className=document.body.className};d();let f=new MutationObserver(d);f.observe(document.documentElement,{attributes:!0}),f.observe(document.body,{attributes:!0,attributeFilter:[`class`]}),Object.assign(u.body.style,{margin:`0`,position:`fixed`,inset:`0`,display:`flex`,flexDirection:`column`,background:getComputedStyle(document.body).backgroundColor});let p=u.createElement(`div`);p.className=`kymo-window-controls`;let m=u.createElement(`div`);m.className=`kymo-window-plot`,Object.assign(m.style,{flex:`1`,minHeight:`0`,position:`relative`}),u.body.append(p,m),eZ(l);let h=n(m,r.mount),g=mX(),_=!1,v=()=>{_||(_=!0,i.delete(t),tZ(l),f.disconnect(),b(),window.removeEventListener(`pagehide`,y),h.destroy(),g.emit(`close`,void 0),g.clear())},y=()=>x.close(),b=e.subscribe(()=>{try{e.charts.get(t)}catch{x.close()}});l.addEventListener(`pagehide`,v),window.addEventListener(`pagehide`,y);let x={chartId:t,window:l,controls:p,view:h,close(){v(),l.closed||l.close()},on:(e,t)=>g.on(e,t)};return i.set(t,x),x}function A5(e){for(let t of[...O5.get(e)?.values()??[]])t.close()}function j5(e){let t=new Map;for(let[n,r]of O5.get(e)??[]){let e=r.window;e.closed||t.set(n,{left:e.screenX,top:e.screenY,width:e.innerWidth,height:e.innerHeight})}return t}xE(),Qe(),QG(),jE();var M5=12e3,N5=100;function P5(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 XG.add(n),n;for(let e=0;e<n.length;e++){let t=n[e];t-t!==0&&(n[e]=NaN)}return n}function F5(e,t){let n=Object.keys(t.columns);if(n.length===0)throw new SE(`no_columns`);let r=t.columns[n[0]].length;if(n.some(e=>t.columns[e].length!==r))throw new SE(`column_length_mismatch`);let i=new Map(n.map(e=>[e,P5(t.columns[e],t.transfer)])),a=I5(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 SE(`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 I5(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,N5);t++)e.push(o.map(e=>{let r=n.get(e)[t];return r===r?String(r):``}).join(`,`));d=e.join(`
|
|
635
|
+
`),f=cE(d)}let p={id:e,name:t,schema:l,rawText:d,parseConfig:f,fromColumns:!0};if(s>1e6){let e=new Y6(n,r);return{...p,kind:`columnar`,source:e,data:{meta:``,columnNames:o,units:c,rows:e.sampleRowsSync(M5)}}}let m={meta:``,columnNames:o,units:c,rows:qe({keys:o,length:s,values:o.map(e=>n.get(e)),text:o.map(()=>null)},i)};return{...p,kind:`memory`,source:new VE(m),data:m}}function L5(e,t,n){let r=e.fromColumns?R5(e):null;if(!r)throw new SE(`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)?(kE(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{...z5(e,o,!0),columnSpares:s}}function R5(e){if(e.source instanceof Y6)return new Map(e.source.columnMap);let t=Ge(e.data.rows);return t?new Map(t.keys.map((e,n)=>[e,t.values[n]])):null}function z5(e,t,n=!1){let r=e.fromColumns?R5(e):null;if(!r)throw new SE(`invalid_argument`,{reason:`only datasets added with addColumns can be replaced`});let i=r;for(let e of Object.keys(t))i.set(e,P5(t[e],n));let a=i.values().next().value.length;for(let e of i.values())if(e.length!==a)throw new SE(`column_length_mismatch`);let o=Object.fromEntries(e.schema.map(e=>[e.name,e.unit])),s=I5(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 B5=new WeakMap;function V5(e){let t=e.fromColumns?R5(e):null;if(!t)return e.rawText??``;let n=e.data.rows,r=B5.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(`,`));B5.set(n,r=a.join(`
|
|
636
|
+
`))}return r}function H5(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 U5(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)}gK();function W5(){let e=U5(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?Zw(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=lY(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:pY(n.id,t),name:`${n.name} · Cycle ${t+1}`,data:r,source:new VE(r)}}),values:a.map(e=>uY(n.data.rows,e,r,i)),unit:o,isTime:i===`span`&&fY(r,o)}}return t}),t=U5((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=U5((e,t)=>e.filter(e=>e.kind===`data`&&t.includes(e.id))),r=U5(e=>P6(e.map(e=>e.data))),i=U5((e,t)=>t.length===0?e:P6(e?[e,...t.map(e=>e.dataset)]:t.map(e=>e.dataset))),a=U5((e,t,n,r)=>{let i=new Set;if(e)for(let t of n.length>0?n:[e])for(let e of R6(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=>kJ(e.schema));return[...new Set([...a,...o])]});return{lapsByDataset:e,selectedDatasets:t,selectedLive:n,staticDataset:r,mergedDataset:i,mergedParts:U5((e,t)=>[...e.map(e=>e.data),...t.map(e=>e.dataset)]),numericColumns:U5((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:U5((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:U5((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 G5=[{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`}],K5=new Map(G5.map(e=>[e.kind,e.label]));function q5(e){return K5.get(e)??e}var J5=`kymoscope-live.v1`,Y5=`kymoscope-live.ack1`,X5=`kymoscope-live.ack2`,Z5=1e3,Q5=2e3,$5=3e4,e7=1e4,t7=30,n7=1e4,r7=300,i7=90,a7=e=>e.startsWith(`eyJ`);function o7(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 s7(e,t){return`${e.replace(/\/+$/,``)}/v1/streams/${t}/watch`}function c7(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=o7(r);if(a===null)return;let c=a7(r),d=c?Math.min(a,Date.now()/1e3+r7):a,f=Math.min(Math.max((d-(c?i7:t7))*1e3-Date.now(),n7),2**31-1);o=setTimeout(async()=>{o=null;let r=null;try{r=await e.getToken(t)}catch{r=null}if(!(s||i!==n||!r)){try{n.send(JSON.stringify({type:`auth`,token:r}))}catch{return}u(n,r)}},f)},d=(e=!1)=>{if(s||a)return;let t=e?0:Math.min($5,Q5*2**c++)*(.75+Math.random()/2);a=setTimeout(()=>{a=null,f()},t)},f=async()=>{if(s)return;let a=null;try{a=await e.getToken(t)}catch{a=null}if(s)return;if(!a){r?.(`error`),d();return}let o=new WebSocket(s7(e.url,t),[J5,Y5,X5,`bearer.${a}`]);o.binaryType=`arraybuffer`,i=o;let f=a,p=Date.now(),m=0,h=setInterval(()=>{if(!(m===0||o.readyState!==1)){try{o.send(JSON.stringify({type:`ack`,b:m}))}catch{return}m=0}},Z5);o.onopen=()=>{r?.(`subscribed`),u(o,f)},o.onmessage=e=>{if(c=0,typeof e.data!=`string`){m+=e.data.byteLength,n(e.data);return}if(e.data.startsWith(`{"type":"probe"`))try{let t=JSON.parse(e.data).id;typeof t==`string`&&t.length<=64&&o.send(JSON.stringify({type:`ack`,id:t}))}catch{}},o.onclose=()=>{clearInterval(h),i===o&&(i=null,l(),!s&&(r?.(`error`),d(Date.now()-p>=e7)))}};return f(),()=>{if(s=!0,a&&=(clearTimeout(a),null),l(),i){let e=i;i=null,e.close(1e3)}}}var l7=24;function u7(e){if(e.length<l7||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=l7,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)}}IG(),GK(),BG(),Bq(),nq(),fq();var d7=8;function f7(e,t,n){let r=new Map,i=new Set,a=null,o=e=>{i.add(e.id),a=e.id,t({type:`schema`,id:e.id,names:e.channels.map(e=>e.name),units:e.channels.map(e=>e.unit)})},s=Promise.resolve(),c=n?aq(n,e=>t({type:`integrity`,integrity:e})):null;return Object.assign(n=>{let l=HK(e,n).catch(()=>null);c?.arrive(n,new Uint8Array(n,0,1)[0]&127,l),s=s.then(async()=>{try{let e=await l;if(!e)return;if(e.kind===6){let n=u7(e.plaintext);n&&t({type:`video`,m:n})}else if(e.kind===5){let t=await bq(e.plaintext);if(r.delete(t.id),r.set(t.id,t),r.size>d7){let e=r.keys().next().value;r.delete(e),i.delete(e)}(t.channels.length>1e3||a!==null)&&t.id!==a&&o(t)}else if(e.kind===7){let n=await Sq(e.plaintext,r);n&&t({type:`last`,values:n})}else if(e.kind===4){let n=await Tq(e.plaintext,r);n&&t(n.historical?{type:`columns`,block:n.block,historical:!0}:{type:`columns`,block:n.block})}else if(e.kind===9){let n=await Eq(e.plaintext,r);if(!n||!n.index.length)return;i.has(n.schemaId)||o(r.get(n.schemaId)),t({type:`sparse`,...n})}else if(e.kind===3)t({type:`columns`,block:LG(e.plaintext)});else if(e.kind===2){let n=PG(e.plaintext);t({type:`frames`,frames:Array.isArray(n?.frames)?n.frames:[]})}}catch{}})},{reset:()=>c?.reset()})}var p7=``+new URL(`assets/liveIngestWorker-MA_RO8uZ.js`,__kymoscopeScriptUrl).href;function m7(e,t,n,r,i){let a=()=>{let a=f7(n,r,t);return c7(e,t,a,e=>{e===`subscribed`&&a.reset(),i?.(e)})},o;try{if(typeof Worker>`u`)return a();o=CE(p7)}catch{return a()}let s=!1,c=()=>{try{o.postMessage({type:`stop`})}catch{o.terminate()}};return o.onmessage=a=>{let s=a.data;if(s.type===`decoded`){if(r(s.d),s.bytes)try{o.postMessage({type:`ack`,bytes:s.bytes})}catch{}}else if(s.type===`status`)i?.(s.status);else if(s.type===`ask`){let r=s.what===`token`?e.getToken(t):typeof n==`function`?n(s.arg):n;Promise.resolve(r).catch(()=>null).then(e=>{try{o.postMessage({type:`reply`,id:s.id,value:e})}catch{}})}},o.onerror=()=>{o.terminate(),!s&&(c=a())},o.postMessage({type:`start`,url:e.url,streamId:t,key:typeof n==`function`?null:n}),()=>{s=!0,c()}}var h7=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}};RE();var g7=class{#e;#t=new Set;onUse;constructor(e){this.#e=typeof e==`function`?e:()=>e}#n(e){return this.onUse?.(e),this.#e()}#r(e){return this.onUse?this.#n([e]):this.#e()}retrackCycles(){let e=this.#e();for(let t of this.#t)e.trackCycles(t)}size(){return this.#e().size}get columnNames(){return this.#e().columnNames}version(){return this.#e().version}columns(){return new _7(this.#e(),e=>this.#r(e).mirrorColumn(e))}samplesSync(e){let t=this.#r(e),n=t.mirrorColumn(e);return n?{values:n,first:t.firstAbs}:null}hasValues(e){return this.#e().hasValues(e)}snapshot(e){return this.#e().toDataset(e)}async getSchema(){let e=this.#e();return e.columnNames.map(t=>({name:t,type:`number`,unit:e.unitOf(t)}))}async getSeries(e){let t=this.onUse?this.#n([e.viewport.xKey,e.column]):this.#e();return FE(t.columnValues(e.viewport.xKey),t.columnValues(e.column),e.viewport.x0,e.viewport.x1,e.maxPoints)}async getSeriesMulti(e,t,n){return this.getSeriesMultiSync(e,t,n)}getSeriesMultiSync(e,t,n){return(this.onUse?this.#n([t.xKey,...e]):this.#e()).decimateColumns(t.xKey,e,t.x0,t.x1,n)}getPointsSync(e,t,n){return(this.onUse?this.#n([t.xKey,...e]):this.#e()).decimatePoints(t.xKey,e,t.x0,t.x1,n)}async xBounds(e){return this.xBoundsSync(e)}xBoundsSync(e){return this.#r(e).columnBounds(e)}xTravelSync(e,t){return this.#r(e).xTravel(e,t)}timeAfterSync(e){return this.#e().timeAfter(e)}latestTimeSync(){return this.#e().latestTime()}xAtTimeSync(e,t,n=!1){return this.#r(e).xAtTime(e,t,n)}latestSync(e){return this.#r(e).lastValue(e)}latestValuesSync(e){let t=this.#n(e),n=new Map;for(let r of e){let e=t.lastValue(r),i=t.lastKnown(r);Number.isFinite(e)?n.set(r,e):i&&n.set(r,i.v)}return n}valueBoundsSync(e){let t=this.#r(e),n=t.valueBounds(e),r=t.lastKnown(e);if(!n&&!r)return null;let i=Math.min(n?.x0??1/0,r?.v??1/0),a=Math.max(n?.x1??-1/0,r?.v??-1/0);if(i!==a)return{min:i,max:a};let o=Math.max(.5,Math.abs(i)*.05);return{min:i-o,max:a+o}}lastKnownSync(e){return this.#e().lastKnown(e)}trackCycles(e){this.#t.add(e),this.#r(e).trackCycles(e)}cycleSpanSync(e){return this.#r(e).cycleSpan(e)}decimateCycleSync(e,t,n,r,i){return(this.onUse?this.#n([e,...n]):this.#e()).decimateCycle(e,t,n,r.x0,r.x1,i)}cyclePointsSync(e,t,n,r,i){return(this.onUse?this.#n([e,...n]):this.#e()).decimateCyclePoints(e,t,n,r.x0,r.x1,i)}async readColumns(e,t,n){let r=this.#n(e),i={};for(let a of e)r.has(a)&&(i[a]=r.columnValues(a).slice(t,t+n));return i}async dispose(){}},_7=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)}};gK();var v7=4096,y7=5e3,b7=class{startedAt=Date.now();n=0;capacity=v7;time=new Float64Array(v7);cols=new Map;order=[];units=new Map;timeColumn;timeUnit;constructor(e=dK,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=iK(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(x7).join(`,`)}\n${t.map(x7).join(`,`)}\n`],r=this.order.map(e=>this.cols.get(e));for(let e=0;e<this.n;e+=y7){let t=Math.min(this.n,e+y7),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+=`
|
|
637
|
+
`}n.push(i)}return n}};function x7(e){let t=/^[=+\-@\t\r]/.test(e)?`'${e}`:e;return/[",\n\r]/.test(t)?`"${t.replace(/"/g,`""`)}"`:t}gK();var S7=512,C7=new WeakMap;function w7(e,t,n){let r=C7.get(e);r||C7.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 T7(e,t,n){let r=e.endAbs,i=Math.max(n,e.firstAbs);if(!(i>=r||t.length===0))for(let n of t){if(!n.enabled)continue;let a=WC(n.formula);if(!a.ok)continue;let{identifiers:o,functions:s}=GC(a.node);if(!o.every(t=>e.has(t)))continue;let c=s.some(e=>HC.includes(e)),l=Math.max(e.firstAbs,i-(c?S7:0)),u=new Map([dK,...o].map(t=>[t,e.range(t,l,r)])),{carry:d,keep:f}=w7(e,`${n.id}|${n.formula}`,l),p=ZC(n,e=>u.get(e),dK,r-l,t,d);p.status===`ok`&&(e.writeComputed(n.name,n.units,i,p.values.subarray(i-l)),f())}}function E7(e,t){e.clearComputed(),C7.delete(e),T7(e,t,e.firstAbs)}var D7=new Map;function O7(e,t){let n=`${t}|${Math.floor(e/900)}`,r=D7.get(n);r===void 0&&(r=Aw(e,t),D7.size>1e4&&D7.clear(),D7.set(n,r));let i=(e+r)%86400;return i<0?i+86400:i}var k7=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`?O7(e,n.tz):n.kind===`elapsed`?e-this.#e:e<this.#e?NaN:n.kind===`event`?(this.#t!==this.#t&&t===t&&Tw(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)}};gK();function A7(e){if(!e.cycle)throw Error(`a live segment axis needs a cycle rule`);let t=new zw(e.cycle),n=new k7(e.axis),r=NaN,i=`channel`in e.axis?e.axis.channel:null,a=[...new Set([...Rw(e.cycle),...i?[i]:[]])];return{feed(o,s,c=!1){let l=Math.max(s,o.firstAbs),u=o.endAbs;if(l>=u)return;let d=t=>{c||e.onEvent?.(t)},f=o.range(dK,l,u),p=new Map(a.map(e=>[e,o.range(e,l,u)])),m=new Float64Array(f.length).fill(NaN),h=i?p.get(i):null,g=[];for(let e=0;e<f.length;e++){t.step(f[e],t=>{let n=p.get(t);return n?n[e]:NaN},g);let i=t.open()?.tstart??null;i!==null&&(i!==r&&(r=i,n.begin(i),d({type:`open`,tstart:i})),m[e]=n.x(f[e],h?h[e]:NaN))}for(let e of g)d({type:`close`,segment:{tstart:e.tstart,tend:e.tend,kpis:{duration:(e.tend??e.tstart)-e.tstart},...e.flags.length?{flags:e.flags}:{}}});o.writeComputed(e.column,e.unit,l,m)}}}BK(),gK(),nq();var j7=1e7;function M7(e=globalThis.navigator?.deviceMemory){return Math.max(512,Math.round(((e??0)>0?e:16)*1024/8))}var N7=400,P7=4e3,F7=1e3,I7=3e3,L7=2,R7=5e3,z7=1e4;function B7(e,t,n=`data`){let r=new hK(t.capacity??j7,void 0,void 0,(t.maxMemoryMB??M7())*1024*1024);return{meta:e,buffer:r,source:new g7(()=>r),feed:null,unsub:()=>{},status:`connecting`,error:null,lastFrameAt:Date.now(),lastColCount:0,lastValued:0,recorder:null,dropped:0,recDropped:0,video:n===`camera`?new Cw:null,clock:n===`camera`?null:new h7,lagTicks:0,lastRejoinAt:0,rejoin:()=>{},subscribed:!1,releaseTimer:void 0}}function V7(e,t,n,r){let i,a=-1/0,o=new Map;return async s=>{if(i===void 0&&(i=s,o.set(t,s)),s===i)return e;if(Date.now()-a<2e3)return null;a=Date.now();let c=await r().catch(()=>null);if(!c||o.has(c.salt)&&o.get(c.salt)!==s)return null;let l=c.key??(n===null?null:await bK(n,c.salt));return!l||!await TK(l,c.key_check).catch(()=>!1)?null:(o.set(c.salt,s),l)}}function H7(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.columnCount,t.lastValued=t.buffer.valuedCount,e.push({...t.meta,kind:t.video?`camera`:`data`,video:t.video,clock:t.clock,dataset:t.buffer.toDataset(N7),source:t.source,rowCount:t.buffer.size,status:t.status,error:t.error,recordingSince:t.recorder?.startedAt??null,droppedSamples:t.dropped,...t.integrity?{integrity:t.integrity}:{}});o=e,t(o)},u=(e,t)=>{let n=!1,r=e.buffer.endAbs;for(let r of t)r&&typeof r.t==`number`&&Array.isArray(r.signals)&&(e.buffer.push(r),e.recorder?.add(r),n=!0);n&&f(e,r,t[t.length-1]?.t)},d=(e,t)=>{let n=e.buffer.endAbs;e.buffer.pushColumns(t),e.recorder?.addColumns(t),t.t.length>0&&f(e,n,t.t[t.t.length-1])},f=(e,t,n)=>{T7(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.columnCount!==e.lastColCount||e.buffer.valuedCount!==e.lastValued)},p=(e,t)=>{let n=e.buffer.endAbs,r=e.buffer.valuedCount,i=t();i?f(e,n,i.t[i.t.length-1]):m(e,e.buffer.valuedCount!==r)},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>P7&&(n.status=`stale`,t=!0);let i=n.video&&n.subscribed&&n.status===`live`?n.video.info().lagMs:null;n.lagTicks=i!==null&&i>I7?n.lagTicks+1:0,n.video&&n.lagTicks>=L7&&e-n.lastRejoinAt>=R7&&(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()},F7);return{connections:()=>o,disconnect:h,startRecording(e){let t=i.get(e);!t||t.recorder||(t.recorder=new b7,t.recDropped=0,l())},stopRecording(e){let t=i.get(e),n=t?.recorder;return!t||!n?null:(t.recorder=null,l(),{csv:n.toCsvParts(),rows:n.rows,name:t.meta.name,startedAt:n.startedAt,droppedSamples:t.recDropped})},setRelay(e){a=e},setSegmentAxis(e,t){let n=i.get(e);n&&(n.segAxis=t?{cfg:t,tracker:A7(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||(E7(t.buffer,e),t.segAxis&&(t.segAxis.tracker=A7(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=B7({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,o){if(i.has(e.id))return;let c=a&&e.relay_url?{...a,url:e.relay_url,getToken:async e=>{let t=await a.getToken(e);return t&&!a7(t)?t:null}}:a;if(!c)throw new SE(`relay_unavailable`);let f;if(typeof t==`string`){let n=EK(t).secret??t,r=await bK(n,e.salt);if(!await TK(r,e.key_check))throw new SE(`wrong_password`);f=o?.reload?V7(r,e.salt,n,o.reload):r}else if(f=`keyFor`in t?e=>t.keyFor(e):t,typeof f!=`function`){if(!await TK(f,e.key_check))throw new SE(`wrong_password`);o?.reload&&(f=V7(f,e.salt,null,o.reload))}let h=B7({id:e.id,name:e.name,ownerName:e.owner_name??``,visibility:e.visibility??`private`,orgName:e.org_name??null,projectName:e.project_name??null,parentId:e.parent_stream_id??null,lowOf:e.low_of_stream_id??null,limitNotice:e.limit_notice??null,sync:e.sync??null,clockOffsetMs:e.clock_offset_ms??null},{...n(),...o},e.kind);i.set(e.id,h);let g=t=>{if(i.get(e.id)===h)if(t.type===`video`)h.video&&(h.video.push(t.m),m(h,!1));else if(t.type===`last`){let e=h.buffer;if(h.feed)h.feed.last(t.values);else for(let n of t.values)e.setLastKnown(n.name,n.unit,n.t,n.v);(e.columnCount!==h.lastColCount||e.valuedCount!==h.lastValued)&&l()}else if(t.type===`gap`)h.dropped+=t.samples,h.recorder&&(h.recDropped+=t.samples),l();else if(t.type===`integrity`){let e=h.integrity;h.integrity=t.integrity,(!e||e.broken!==t.integrity.broken)&&l()}else if(t.type===`columns`)if(t.historical)r?.historical?.(e.id,t.block);else if(h.feed){let e=[],n=[],r=[];for(let[i,a]of Object.entries(t.block.columns))for(let o=0;o<a.length;o++)Number.isFinite(a[o])&&(e.push(t.block.t[o]),n.push(i),r.push(a[o]));let i=h.feed;p(h,()=>i.pushNamed(e,n,r))}else d(h,t.block);else if(t.type===`schema`){if(!h.feed){let t=h.feed=new eq(h.buffer,h.buffer.memoryBudget/2),n=!1;h.source.onUse=r=>{!t.activate(r)||n||(n=!0,queueMicrotask(()=>{n=!1,i.get(e.id)===h&&(t.replay(),E7(h.buffer,s),h.source.retrackCycles(),h.segAxis&&(h.segAxis.tracker=A7(h.segAxis.cfg),h.segAxis.tracker.feed(h.buffer,h.buffer.firstAbs,!0)),l())}))}}h.feed.schema(t.id,t.names,t.units),l()}else if(t.type===`sparse`){if(t.historical||!h.feed)return;let e=h.feed;p(h,()=>e.push(t.schemaId,t.index,t.t,t.v))}else u(h,t.frames)},_=t=>{!h.subscribed||i.get(e.id)!==h||(t===`subscribed`?(h.status=`live`,h.lastFrameAt=Date.now()):t===`error`&&(h.status=`error`,h.error=`connection_error`),l())};h.rejoin=()=>{h.unsub=h.video?c7(c,e.id,f7(f,g),_):m7(c,e.id,f,g,_)};let v=h.video;v?(h.status=`idle`,v.onDemandChange(t=>{i.get(e.id)===h&&(clearTimeout(h.releaseTimer),t?h.subscribed||(h.subscribed=!0,v.resync(),h.status=`connecting`,h.lastFrameAt=Date.now(),h.rejoin(),l()):h.releaseTimer=setTimeout(()=>{h.subscribed=!1,h.unsub(),h.unsub=()=>{},h.status=`idle`,h.error=null,h.lagTicks=0,l()},z7))})):(h.subscribed=!0,h.rejoin()),l()},dispose(){clearInterval(g);for(let e of i.values())clearTimeout(e.releaseTimer),e.unsub();i.clear(),o=[]}}}function U7(e){let t=Object.keys(e.signals),n=W7(e.derived??{}),r=[...t,...n],i=e=>r.indexOf(e),a=n.map(t=>{let n=e.derived[t];return{i:i(t),d:n,src:(n.op===`diff`?[n.a,n.b]:[n.of]).map(i)}}),o=[],s=r.map(()=>!1),c=r.map(()=>e.staleS!=null),l=null,u=!1,d=e=>{u||(u=!0,l=e)},f=e=>{let t=e;if(`all`in t||`any`in t){let e=`all`in t,n=(e?t.all:t.any).map(f),r=o.length,i=n.filter(e=>`i`in o[e]);i.forEach((t,n)=>{let i=o[t];i.into=r,i.mode=n===0?0:e?1:2}),o.push({k:e?`all`:`any`,kids:n,rest:n.filter(e=>!i.includes(e)),fused:i.length>0})}else if(`not`in t){let e=f(t.not);o.push({k:`not`,kid:e})}else{let e=[`above`,`below`,`outside`,`inside`,`equals`,`changes`,`noData`].find(e=>e in t),n=i(t[e]),r=t.value??NaN,a=t.lo??NaN,l=t.hi??NaN;d(e===`above`?{i:n,excess:e=>e-r}:e===`below`?{i:n,excess:e=>r-e}:e===`outside`?{i:n,excess:e=>Math.max(e-l,a-e)}:null),e===`changes`&&(s[n]=!0),e===`noData`&&(c[n]=!0),o.push({k:e,i:n,v:r,lo:a,hi:l,h:t.hysteresis??0,f:t.forS??0,prev:0,into:o.length,mode:0})}return o.length-1};return f(e.when),{aliases:r,base:t.length,derived:a,ops:o,needPrev:s,needAt:c,first:l}}function W7(e){let t=[],n=new Set,r=i=>{if(n.has(i)||!(i in e))return;n.add(i);let a=e[i];for(let e of a.op===`diff`?[a.a,a.b]:[a.of])r(e);t.push(i)};return Object.keys(e).forEach(r),t}var G7=`\0t`;function K7(e,t){return`formula`in e?{applies:!0,column:e.formula}:e.stream&&!(t.kind===`stream`&&t.id===e.stream)||e.history&&!(t.kind===`history`&&t.id===e.history)||e.dataset&&!(t.kind===`dataset`&&t.name===e.dataset)?{applies:!1,column:null}:e.tag?{applies:!0,column:t.tags?.[e.tag]??null}:{applies:!0,column:e.channel}}function q7(e,t){let n=U7(e),r=n.aliases.length,i=n.base,a=e.staleS??1/0,o=Object.values(e.signals),s=o.every(e=>K7(e,t).applies),c=o.map(()=>null),l=!1,u=[],d=`idle`,f=NaN,p=NaN,m=-1/0,h=0,g=null,_=new Float64Array(r).fill(NaN),v=new Float64Array(r).fill(NaN),y=new Float64Array(r).fill(NaN),b=n.derived.map(()=>Q7()),x=Array(r),S=Array(r),C=Array(r),w=Array(r),T=0,E=[],D=[],O=[],k=[],A=new Float64Array,j=new Float64Array,M=new Float64Array,N=new Int32Array,P=new Uint8Array,F=[],I=e=>{e<=T||(T=Math.max(e,T*2,64),E=Array.from({length:r},()=>new Float64Array(T)),D=Array.from({length:r},()=>new Float64Array(T)),O=Array.from({length:r},()=>new Uint8Array(T)),k=Array.from({length:r},()=>new Float64Array(T)),A=new Float64Array(T),j=new Float64Array(T),M=new Float64Array(T),N=new Int32Array(T),P=new Uint8Array(T).fill(1),F=n.ops.map(()=>new Int8Array(T)))},L=(n,r,i={})=>({ruleId:e.id,ruleVersion:e.version,target:t,kind:n,t:r,...i}),R=()=>{_.fill(NaN),v.fill(NaN),y.fill(NaN);for(let e of b)e.head=0,e.len=0,e.sum=0};function z(n){let r=[];if(!e.enabled||!s)return r;let i=new Set(n),a=o.map(e=>K7(e,t).column),f=o.map((e,t)=>a[t]!==null&&i.has(a[t])?null:`formula`in e?e.formula:e.channel).filter(e=>e!==null),p=l;return c=a,u=[...new Set(f)],l=u.length===0,p&&!l&&((d===`active`||d===`clearing`)&&r.push(L(`lost`,m)),d=`idle`,g=null,R()),r}function B(e,t){for(let r=0;r<n.derived.length;r++){let{i,d:a,src:o}=n.derived[r],s=x[o[0]],c=C[o[0]],l=E[i],u=D[i],d=O[i],f=k[i],p=n.needPrev[i],m=_[i],h=v[i],g=y[i];if(a.op===`abs`||a.op===`diff`){let n=a.op===`diff`,r=n?x[o[1]]:s,b=n?C[o[1]]:c;if((c===P||b===P)&&!p){if(n)for(let t=0;t<e;t++)l[t]=s[t]-r[t];else for(let t=0;t<e;t++)l[t]=Math.abs(s[t]);y[i]=e>=2?l[e-2]:_[i],_[i]=l[e-1],v[i]=t[e-1],x[i]=l,S[i]=t,C[i]=P,w[i]=f;continue}for(let i=0;i<e;i++)c[i]||n&&b[i]?(g=m,m=n?s[i]-r[i]:Math.abs(s[i]),h=t[i],d[i]=1):d[i]=0,l[i]=m,u[i]=h,p&&(f[i]=g)}else{let o=b[r],T=a.windowS;if(a.op===`min`||a.op===`max`){let n=a.op===`max`;for(let r=0;r<e;r++){let e=t[r],i=e-T,a=s[r],_=c[r]===1&&a-a===0;if(_){for(;o.len&&(n?o.x[o.head+o.len-1&o.mask]<=a:o.x[o.head+o.len-1&o.mask]>=a);)o.len--;e9(o,e,a)}for(;o.len&&o.t[o.head]<i;)o.head=o.head+1&o.mask,o.len--;if(_){let t=o.x[o.head];g=m,m=t,t===t&&(h=e),d[r]=1}else d[r]=0;l[r]=m,u[r]=h,p&&(f[r]=g)}}else{let r=a.op===`mean`,b=o.len;A.length<b+e&&(A=new Float64Array(2*(b+e)),j=new Float64Array(2*(b+e)));for(let e=0;e<b;e++){let t=o.head+e&o.mask;A[e]=o.t[t],j[e]=o.x[t]}let E=0,D=b,O=o.sum,k=c===P;for(let t=0;k&&t<e;t++)k=s[t]-s[t]===0;if(k&&!p&&!n.needAt[i]){for(let n=0;n<e;n++){let e=t[n],i=s[n],a=e-T;if(A[D]=e,j[D]=i,D++,r)for(O+=i;A[E]<a;)O-=j[E],E++;else for(;A[E]<a;)E++;l[n]=m=r?O/(D-E):D-E>=2&&e>A[E]?(i-j[E])/(e-A[E]):NaN}g=e>=2?l[e-2]:_[i];for(let n=e-1;n>=0;n--)if(l[n]===l[n]){h=t[n];break}o.head=0,o.len=0,$7(o,A,j,E,D),o.sum=O,_[i]=m,v[i]=h,y[i]=g,x[i]=l,S[i]=t,C[i]=P,w[i]=f;continue}for(let n=0;n<e;n++){let e=s[n];if(c[n]===1&&e-e===0){let i=t[n],a=i-T;if(A[D]=i,j[D]=e,D++,r)for(O+=e;A[E]<a;)O-=j[E],E++;else for(;A[E]<a;)E++;let o=r?O/(D-E):D-E>=2&&i>A[E]?(e-j[E])/(i-A[E]):NaN;g=m,m=o,o===o&&(h=i),d[n]=1}else d[n]=0;l[n]=m,u[n]=h,p&&(f[n]=g)}o.head=0,o.len=0,$7(o,A,j,E,D),o.sum=O}}_[i]=m,v[i]=h,y[i]=g,x[i]=l,S[i]=u,C[i]=d,w[i]=f}}function V(e,t){let r=a!==1/0;for(let i=0;i<n.ops.length;i++){let o=n.ops[i];if(o.k===`all`||o.k===`any`){let t=F[i],n=o.k===`all`,r=o.rest,a=0;for(o.fused||(t.set(F[r[0]].subarray(0,e)),a=1);a<r.length;a++){let i=F[r[a]];if(n)for(let n=0;n<e;n++)i[n]<t[n]&&(t[n]=i[n]);else for(let n=0;n<e;n++)i[n]>t[n]&&(t[n]=i[n])}continue}if(o.k===`not`){let t=F[i],n=F[o.kid];for(let r=0;r<e;r++)t[r]=Z7-n[r];continue}let s=o,c=x[s.i],l=S[s.i],u=F[s.into],d=s.mode,f=s.prev;switch(o.k){case`noData`:{let n=o.f;for(let r=0;r<e;r++){let e=l[r]===l[r]?t[r]-l[r]>=n?Z7:0:X7;(d===0||(d===2?e>u[r]:e<u[r]))&&(u[r]=e)}break}case`above`:{let n=o.v,i=n-o.h;for(let o=0;o<e;o++){let e=c[o],s;e!==e||r&&t[o]-l[o]>=a&&l[o]!==t[o]?s=X7:(e>n?f=Z7:e<=i&&(f=0),s=f),(d===0||(d===2?s>u[o]:s<u[o]))&&(u[o]=s)}break}case`below`:{let n=o.v,i=n+o.h;for(let o=0;o<e;o++){let e=c[o],s;e!==e||r&&t[o]-l[o]>=a&&l[o]!==t[o]?s=X7:(e<n?f=Z7:e>=i&&(f=0),s=f),(d===0||(d===2?s>u[o]:s<u[o]))&&(u[o]=s)}break}case`outside`:{let n=o.lo,i=o.hi,s=n+o.h,p=i-o.h;for(let o=0;o<e;o++){let e=c[o],m;e!==e||r&&t[o]-l[o]>=a&&l[o]!==t[o]?m=X7:(e<n||e>i?f=Z7:e>=s&&e<=p&&(f=0),m=f),(d===0||(d===2?m>u[o]:m<u[o]))&&(u[o]=m)}break}case`inside`:{let n=o.lo,i=o.hi,s=n-o.h,p=i+o.h;for(let o=0;o<e;o++){let e=c[o],m;e!==e||r&&t[o]-l[o]>=a&&l[o]!==t[o]?m=X7:(e>=n&&e<=i?f=Z7:(e<s||e>p)&&(f=0),m=f),(d===0||(d===2?m>u[o]:m<u[o]))&&(u[o]=m)}break}case`equals`:{let n=o.v;for(let i=0;i<e;i++){let e=c[i],o;o=e!==e||r&&t[i]-l[i]>=a&&l[i]!==t[i]?X7:e===n?Z7:0,(d===0||(d===2?o>u[i]:o<u[i]))&&(u[i]=o)}break}case`changes`:{let n=C[o.i],i=w[o.i];for(let o=0;o<e;o++){let e=c[o],s;if(e!==e||r&&t[o]-l[o]>=a&&l[o]!==t[o])s=X7;else{let t=i[o];s=t===t?n[o]&&e!==t?Z7:0:X7}(d===0||(d===2?s>u[o]:s<u[o]))&&(u[o]=s)}break}}o.prev=f}return F[n.ops.length-1]}function ee(t,r,i,a){let o=n.first,s=o?x[o.i]:null;for(let n=0;n<t;n++){let t=i[n];if(d===`idle`){if(t!==Z7)continue;d=`pending`,f=r[n],g=null}if(s){let e=s[n];if(e===e){let t=o.excess(e);t>0&&(g===null||t>o.excess(g.v))&&(g={v:e,t:r[n]})}}if(t===X7)continue;let c=r[n];if(d===`pending`){if(t===0){d=`idle`,g=null;continue}c-f>=e.forS&&(d=`active`,a.push(L(`raised`,f)));continue}if(d===`active`){if(t===Z7)continue;d=`clearing`,p=c}else if(t===Z7){d=`active`;continue}c-p>=e.clearForS&&(d=`idle`,a.push(L(`cleared`,p,g?{peak:g}:{})),g=null)}}function H(t){let r=[];if(!e.enabled||!s||!l)return r;let a=t.t,o=a.length;if(!o)return r;I(o);let u=null,d=c.map(e=>e!==null&&t.columns[e]||(u??=new Float64Array(o).fill(NaN))),f=d.map((e,n)=>Y7(t,c[n],e)),p=a[0]>m&&a[o-1]<1/0&&J7(t)&&f.some(Boolean),g,b;if(p)g=o,b=a,m=a[o-1];else{g=0;for(let e=0;e<o;e++){let t=!1;for(let n=0;n<i;n++)if(d[n][e]===d[n][e]){t=!0;break}if(!t)continue;let n=a[e];if(n<=m||n-n!==0){h++;continue}N[g]=e,M[g]=n,g++,m=n}if(!g)return r;b=M}for(let e=0;e<i;e++){let t=d[e],r=n.needPrev[e];if(p&&f[e]){if(r){let n=k[e];n[0]=_[e];for(let e=1;e<g;e++)n[e]=t[e-1];w[e]=n}y[e]=g>=2?t[g-2]:_[e],_[e]=t[g-1],v[e]=a[g-1],x[e]=t,S[e]=a,C[e]=P;continue}let i=E[e],o=D[e],s=O[e],c=k[e],l=_[e],u=v[e],m=y[e];for(let e=0;e<g;e++){let n=t[p?e:N[e]];n===n?(m=l,l=n,u=b[e],s[e]=1):s[e]=0,i[e]=l,o[e]=u,r&&(c[e]=m)}_[e]=l,v[e]=u,y[e]=m,x[e]=i,S[e]=o,C[e]=s,w[e]=c}return B(g,b),ee(g,b,V(g,b),r),r}function U(t){let n=[];if(!e.enabled||!s||!l||t<=m)return n;I(1);for(let e=0;e<r;e++)E[e][0]=_[e],D[e][0]=v[e],O[e][0]=0,k[e][0]=y[e],x[e]=E[e],S[e]=D[e],C[e]=O[e],w[e]=k[e];return M[0]=t,ee(1,M,V(1,M),n),n}function te(){let t=e.enabled?s?l?d:`waiting`:`not_applicable`:`disabled`;return{state:t,...t===`waiting`?{missing:u}:{},...d!==`idle`&&l?{since:d===`clearing`?p:f}:{},late:h,lastT:m}}return z([]),{rule:e,target:t,bind:z,push:H,tick:U,state:te}}function J7(e){let t=e.scan?.get(G7);if(t===void 0){let n=e.t;t=!0;for(let e=1;e<n.length;e++)if(!(n[e]>n[e-1])){t=!1;break}e.scan?.set(G7,t)}return t}function Y7(e,t,n){let r=t===null?void 0:e.scan?.get(t);if(r===void 0){r=!0;for(let e=0;e<n.length;e++)if(n[e]!==n[e]){r=!1;break}t!==null&&e.scan?.set(t,r)}return r}var X7=1,Z7=2,Q7=()=>({t:new Float64Array(16),x:new Float64Array(16),head:0,len:0,mask:15,sum:0});function $7(e,t,n,r,i){let a=i-r;if(a<=0)return;if(e.len+a>e.mask+1){let t=e.mask+1;for(;t<e.len+a;)t*=2;let n=new Float64Array(t),r=new Float64Array(t);for(let t=0;t<e.len;t++)n[t]=e.t[e.head+t&e.mask],r[t]=e.x[e.head+t&e.mask];e.t=n,e.x=r,e.head=0,e.mask=t-1}let o=e.head+e.len&e.mask,s=Math.min(a,e.mask+1-o);e.t.set(t.subarray(r,r+s),o),e.x.set(n.subarray(r,r+s),o),s<a&&(e.t.set(t.subarray(r+s,i),0),e.x.set(n.subarray(r+s,i),0)),e.len+=a}function e9(e,t,n){if(e.len===e.mask+1){let t=e.len*2,n=new Float64Array(t),r=new Float64Array(t);for(let t=0;t<e.len;t++)n[t]=e.t[e.head+t&e.mask],r[t]=e.x[e.head+t&e.mask];e.t=n,e.x=r,e.head=0,e.mask=t-1}let r=e.head+e.len&e.mask;e.t[r]=t,e.x[r]=n,e.len++}var t9=[`above`,`below`,`outside`,`inside`,`equals`,`changes`,`noData`],n9=/^[A-Za-z_][A-Za-z0-9_]{0,31}$/,r9=[`info`,`warning`,`critical`],i9=[`browser`,`collector`],a9=e=>typeof e==`number`&&Number.isFinite(e),o9=e=>a9(e)&&e>=0&&e<=86400;function s9(e){let t=[],n=(e,n)=>{t.push({code:e,path:n})};if(!e||typeof e!=`object`)return[{code:`not_a_rule`,path:``}];let r=e;r.kyr!==1&&n(`unsupported_version`,`kyr`),(typeof r.id!=`string`||!r.id)&&n(`bad_id`,`id`),(!Number.isInteger(r.version)||r.version<1)&&n(`bad_version`,`version`),(typeof r.name!=`string`||!r.name.trim()||r.name.length>120)&&n(`bad_name`,`name`),r9.includes(r.severity)||n(`bad_severity`,`severity`);for(let e of[`forS`,`clearForS`])o9(r[e])||n(`bad_duration`,e);r.staleS!=null&&!o9(r.staleS)&&n(`bad_duration`,`staleS`),(!Array.isArray(r.runWhere)||!r.runWhere.length||!r.runWhere.every(e=>i9.includes(e)))&&n(`bad_run_where`,`runWhere`);let i=new Map,a=r.signals&&typeof r.signals==`object`?r.signals:{};Object.keys(a).length||n(`no_signals`,`signals`);for(let[e,t]of Object.entries(a)){n9.test(e)||n(`bad_alias`,`signals.${e}`),i.set(e,`signal`);let a=t&&typeof t==`object`?t:{};`formula`in a?((typeof a.formula!=`string`||!a.formula)&&n(`bad_channel`,`signals.${e}`),Array.isArray(r.runWhere)&&r.runWhere.length===1&&r.runWhere[0]===`browser`||n(`formula_browser_only`,`signals.${e}`)):(typeof a.channel!=`string`||!a.channel||a.channel.length>200)&&n(`bad_channel`,`signals.${e}`)}let o=r.derived&&typeof r.derived==`object`?r.derived:{};for(let e of Object.keys(o))n9.test(e)||n(`bad_alias`,`derived.${e}`),i.has(e)&&n(`duplicate_alias`,`derived.${e}`),i.set(e,`derived`);let s=e=>e.op===`diff`?[e.a,e.b]:[e.of],c=new Set;for(let[e,t]of Object.entries(o)){let r=t&&typeof t==`object`?t:{};if(![`rate`,`mean`,`min`,`max`,`abs`,`diff`].includes(r.op)){n(`bad_derived`,`derived.${e}`);continue}c.add(e),[`rate`,`mean`,`min`,`max`].includes(r.op)&&!(o9(r.windowS)&&r.windowS>0)&&n(`bad_duration`,`derived.${e}.windowS`);for(let t of s(r))(typeof t!=`string`||!i.has(t))&&n(`unknown_alias`,`derived.${e}`)}let l=new Set,u=new Set,d=e=>{if(u.has(e)||i.get(e)!==`derived`||!c.has(e))return!0;if(l.has(e))return!1;l.add(e);let t=s(o[e]).every(e=>typeof e!=`string`||d(e));return l.delete(e),u.add(e),t};for(let e of Object.keys(o))if(!d(e)){n(`derived_cycle`,`derived.${e}`);break}let f=0,p=(e,t,r)=>{if(!e||typeof e!=`object`)return n(`bad_condition`,t);let a=e;for(let e of[`all`,`any`])if(e in a)return r>=3?n(`too_deep`,t):!Array.isArray(a[e])||!a[e].length?n(`bad_condition`,t):a[e].forEach((n,i)=>p(n,`${t}.${e}[${i}]`,r+1));if(`not`in a)return r>=3?n(`too_deep`,t):p(a.not,`${t}.not`,r+1);let o=t9.find(e=>e in a);if(!o)return n(`unsupported_condition`,t);f++,(typeof a[o]!=`string`||!i.has(a[o]))&&n(`unknown_alias`,t),a.hysteresis!=null&&!(a9(a.hysteresis)&&a.hysteresis>=0)&&n(`bad_hysteresis`,t),(o===`above`||o===`below`||o===`equals`)&&!a9(a.value)&&n(`bad_value`,t),(o===`outside`||o===`inside`)&&!(a9(a.lo)&&a9(a.hi)&&a.lo<a.hi)&&n(`bad_band`,t),o===`noData`&&!o9(a.forS)&&n(`bad_duration`,`${t}.forS`)};return p(r.when,`when`,0),f>16&&n(`too_many_leaves`,`when`),t}gK();var c9=500,l9=1<<20;function u9(e){let t=[],n=new Map,r=new Map,i=[],a=``,o=(e,t)=>`${e}|${t}`,s=(e,t)=>{let n=t.kind===`stream`?e.targets?.streams:t.kind===`history`?e.targets?.histories:e.targets?.datasets;return!n||n.includes(t.kind===`dataset`?t.name??t.id:t.id)},c=()=>[...n.values()].map(e=>{let{state:t,missing:n,since:r}=e.state();return{ruleId:e.rule.id,target:e.target,state:t,...n?{missing:n}:{},...r===void 0?{}:{since:r}}}),l=()=>{let t=c(),n=JSON.stringify(t);n!==a&&(a=n,e.setStates(t))};function u(n,r,a=!1){let o=t.find(e=>e.id===n.ruleId);if(n.kind===`raised`){i=[...i,{id:`${n.ruleId}|${n.target.id}|${n.t}${a?`|late`:``}`,ruleId:n.ruleId,ruleName:o?.name??``,severity:o?.severity??`info`,targetId:n.target.id,timeColumn:r,t0:n.t,t1:null,...a?{late:!0}:{}}];let e=i.filter(e=>e.targetId===n.target.id);e.length>c9&&(i=i.filter(t=>t!==e[0]))}else{let e=i.find(e=>e.ruleId===n.ruleId&&e.targetId===n.target.id&&e.t1===null&&!!e.late===a);e&&(i=i.map(t=>t===e?{...t,t1:n.t}:t))}e.setMarks(i),e.emit(a?{...n,late:!0}:n)}function d(){let i=new Set;for(let r of e.targets())for(let e of t){if(!s(e,r))continue;let t=o(e.id,r.id);i.add(t);let a=n.get(t),{channels:c,...l}=r;(!a||a.rule!==e)&&(a=q7(e,l),n.set(t,a));for(let e of a.bind(c))u(e,r.kind===`stream`?dK:``)}for(let e of n.keys())i.has(e)||n.delete(e);for(let[e,t]of r)n.get(e)?.rule!==t.rule&&r.delete(e);l()}return{setRules(n){let r=[],i=n.filter(e=>{let t=s9(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}),d(),r},rules:()=>t,state:c,async evaluate(n,r){let a=e.targets().find(e=>e.id===n&&e.kind===`dataset`);if(!a)return[];let{channels:o,...c}=a,l=[],d=t.filter(e=>(!r.ruleIds||r.ruleIds.includes(e.id))&&s(e,c)),f=d.map(e=>{let t=q7(e,c);return t.bind(o),t}),p=[...new Set(d.flatMap(e=>Object.values(e.signals).map(e=>`formula`in e?e.formula:e.channel)))];for(let t=0;;t+=l9){let i=await e.readDataset(n,[r.timeColumn,...p],t,l9),a=i[r.timeColumn];if(!a||!a.length)break;for(let e of f)l.push(...e.push({t:a,columns:i}));if(a.length<l9)break}i=i.filter(e=>!(e.targetId===n&&(!r.ruleIds||r.ruleIds.includes(e.ruleId)))),e.setMarks(i);for(let e of l)u(e,r.timeColumn);return l},pushLive(e,t){let r=!1;for(let i of n.values()){if(i.target.id!==e)continue;let n=i.push(t);n.length&&(r=!0);for(let e of n)u(e,dK)}r&&l()},pushLate(t,i){let a=e.targets().find(e=>e.id===t&&e.kind===`stream`);if(!a)return;let{channels:o,...s}=a;for(let[e,a]of n){if(a.target.id!==t)continue;let n=r.get(e);(!n||n.rule!==a.rule)&&(n=q7(a.rule,s),n.bind(o),r.set(e,n));for(let e of n.push(i))u(e,dK,!0)}},tickLive(e,t){let r=!1;for(let i of n.values()){if(i.target.id!==e)continue;let n=i.tick(t);n.length&&(r=!0);for(let e of n)u(e,dK)}r&&l()},liveColumns(e){let t=new Set;for(let r of n.values())if(r.target.id===e)for(let e of Object.values(r.rule.signals))t.add(`formula`in e?e.formula:e.channel);return[...t]},sync:d,clearMarks(t){i=t?i.filter(e=>e.targetId!==t):[],e.setMarks(i)}}}function d9(e){let t=e.when;for(;t&&typeof t==`object`;)if(`all`in t)t=t.all[0];else if(`any`in t)t=t.any[0];else if(`not`in t)return null;else break;return t?`above`in t||`below`in t?Number.isFinite(t.value)?t.value:null:`outside`in t&&Number.isFinite(t.hi)?t.hi:null:null}var f9=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}},p9={maxChartsPerWorksheet:null,maxChannelsPerChart:null,maxWorksheets:null,maxMathChannels:null,maxAlertRules:null,canImportExportWorkspaces:!0};xE(),gK();var m9=[];function h9(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 g9=[`#a78bfa`,`#38bdf8`,`#fb7185`,`#4ade80`,`#fbbf24`,`#94a3b8`];function _9(e=`ET`){return{id:crypto.randomUUID(),name:`Worksheet`,panels:[],panelChartSettings:{},panelChartBackgrounds:{},xKey:e}}function v9(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(We({...e,name:a,source:`workbook`}))}return{channels:i,rename:r}}function y9(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 b9(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 x9(e,t,n){if(!e||!t)return N();let{min:r,max:i}=AJ(e.rows,t);if(!Number.isFinite(r)||!Number.isFinite(i))return N();let a=MJ(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 S9(e,t){let n=t.includes(e.xKey)?e.xKey:t.includes(`ET`)?`ET`:t.includes(`ElapsedTime`)?dK: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:H();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:U(g9[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:te(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 C9(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 w9(){return typeof document>`u`?`dark`:oY(null)}function T9(e={}){let t={...e},n=!1,r=_9(),i=H5({datasets:[],selection:[],worksheets:[r],activeWorksheetId:r.id,xRanges:{},offsets:{},colors:{},liveWindowSeconds:15,cycleRules:[],live:[],video:[],mathChannels:[],limits:{...p9,...t.limits},palette:rY(t.palette,w9()),importing:0,licensed:null,history:{canUndo:!1,canRedo:!1},marks:[],alerts:[],alertRules:[]}),a=mX(),o=()=>{let e=rY(t.palette,w9());i.set(t=>t.palette.join()===e.join()?t:{...t,palette:e})},s=typeof document>`u`?()=>{}:sY(null,o),c=W5(),l=()=>{if(n)throw new SE(`disposed`)},u=e=>{throw a.emit(`limit`,{reason:e}),new SE(`limit_reached`,{reason:e})},d=()=>i.get(),f=(e,t)=>{let n=d().limits.maxChannelsPerChart,r=jJ(t);n!==null&&r>n&&r>jJ(e)&&u(`channels-per-chart`)},p=U5((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??m9,layout:t.rect,window:t.window??null}),g=U5((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))}))),_=U5((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:tY(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:tY(n,i.id,s(i.id,a),o),offset:r[i.id]??0,selected:t.includes(i.id),...e.cut?{cycle:h9(e.cut,a)}:{}})):null,selected:c?u===0?!1:u===l.length?!0:`partial`:t.includes(e.id)}})}),b=U5((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:tY(n,e.id,a.includes(e.id)?r+a.indexOf(e.id):o,i),customColor:e.id in n,recordingSince:e.recordingSince,limitNotice:e.limitNotice??null,...e.integrity?{integrity:e.integrity}:{},channels:e.dataset.columnNames}))}),x=U5(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:b(e.live,e.selection,e.colors,t.selectedDatasets.length,e.palette),liveWindowSeconds:(()=>{let t=e.worksheets.find(t=>t.id===e.activeWorksheetId);return t?.liveWindowSeconds===void 0?e.liveWindowSeconds:t.liveWindowSeconds})(),cycleRules:e.cycleRules,limits:e.limits,palette:e.palette,importing:e.importing,licensed:e.licensed,hasData:t.merged!==null,multiDataset:t.selectedDatasets.length+t.selectedLive.length>1,numericColumns:t.numericColumns,allColumns:t.allColumns,columnUnits:t.columnUnits,history:e.history,marks:e.marks,alerts:e.alerts}}),S=(e,t)=>e===t||e.length===t.length&&e.every((e,n)=>e===t[n]||JSON.stringify(e)===JSON.stringify(t[n])),C=new f9({limit:100,mergeMs:500,now:()=>Date.now(),equals:(e,t)=>e.liveWindowSeconds===t.liveWindowSeconds&&S(e.worksheets,t.worksheets)&&S(e.channels,t.channels)}),w=!0,T=0,E=e=>{T++;try{e()}finally{T--}},D=e=>[e.worksheets,e.mathChannels,e.liveWindowSeconds],O=[],k=()=>{let e=d();return{worksheets:e.worksheets,channels:e.mathChannels.filter(e=>e.source===`workbook`),liveWindowSeconds:e.liveWindowSeconds,activeWorksheetId:e.activeWorksheetId}},j=()=>i.set(e=>e.history.canUndo===C.canUndo&&e.history.canRedo===C.canRedo?e:{...e,history:{canUndo:C.canUndo,canRedo:C.canRedo}}),N=()=>{if(w)return;let e=D(d());e.every((e,t)=>e===O[t])||(O=e,T?C.rebase(k()):C.observe(k()),j())},P=()=>{O=D(d()),C.clear(k()),j()},F=e=>{w=!0;let t;try{t=e()}finally{w=!1}return P(),t},I=()=>x(d());i.subscribe(()=>{N(),a.emit(`change`,I())});let L=e=>{let t=d(),n=t.worksheets.find(n=>n.id===(e??t.activeWorksheetId));if(!n)throw new SE(`not_found`,{worksheetId:e});return n},R=e=>{for(let t of d().worksheets){let n=t.panels.find(t=>t.id===e);if(n)return{ws:t,panel:n}}throw new SE(`not_found`,{chartId:e})},z=(e,t)=>{let n=e=>e&&t?e.left===t.left&&e.top===t.top&&e.width===t.width&&e.height===t.height:!e&&!t,r=d().worksheets.find(t=>t.panels.some(t=>t.id===e&&!n(t.window)));r&&E(()=>B(r.id,n=>({...n,panels:n.panels.map(n=>{if(n.id!==e)return n;if(t)return{...n,window:{...t}};let{window:r,...i}=n;return i})})))},B=(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}),V=(e,t)=>{let{ws:n}=R(e);B(n.id,n=>({...n,panelChartSettings:{...n.panelChartSettings,[e]:t(n.panelChartSettings[e])}}))},ee=e=>i.set(t=>e.length===t.selection.length&&e.every((e,n)=>e===t.selection[n])?t:{...t,selection:e,xRanges:{}}),H=new Set,U=H7(t.live?.relay,e=>{let t=e.map(e=>e.id),n=e.filter(e=>e.kind===`data`&&!H.has(e.id)).map(e=>e.id),r=[...H].filter(e=>!t.includes(e));if(H=new Set(t),i.set(t=>({...t,live:e})),r.length&&ee(d().selection.filter(e=>!r.includes(e))),n.length){let e=d().selection,t=n.filter(t=>!e.includes(t));t.length&&ee([...e,...t])}let a=m();if(a.selectedLive.length&&a.merged){let e=a.merged.columnNames;if(e.includes(`ElapsedTime`))for(let t of d().worksheets)e.includes(t.xKey)||E(()=>B(t.id,e=>({...e,xKey:dK})))}},()=>({capacity:t.live?.capacity,maxMemoryMB:t.live?.maxMemoryMB}),{rows:(e,t,n)=>{if(!ce.rules().length)return;t.columnCount!==te.get(e)&&(te.set(e,t.columnCount),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(dK,a,i),columns:o,scan:new Map})},historical:(e,t)=>{if(!ce.rules().length||!t.t.length)return;let n={};for(let r of ce.liveColumns(e)){let e=t.columns[r];e&&(n[r]=e instanceof Float64Array?e:Float64Array.from(e))}Object.keys(n).length&&ce.pushLate(e,{t:t.t instanceof Float64Array?t.t:Float64Array.from(t.t),columns:n,scan:new Map})},tick:(e,t,n)=>{if(!ce.rules().length)return;let r=t.range(dK,t.endAbs-1,t.endAbs)[0];r===r&&ce.tickLive(e,r+(Date.now()-n)/1e3)}}),te=new Map,W=U5((e,t)=>e.filter(e=>t.some(t=>fw([e],t.panelChartSettings,t.xKey).length>0))),ne=()=>U.setMathChannels(W(p(d().mathChannels,d().limits.maxMathChannels),d().worksheets));ne(),i.subscribe(ne);let G=e=>{i.set(t=>({...t,datasets:[...t.datasets,e]})),ee([...d().selection,e.id]);let t=kJ(e.schema);t.length&&E(()=>i.set(e=>({...e,worksheets:e.worksheets.map(e=>S9(e,t))})))},re=Promise.resolve(),ie=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 SE(`import_vetoed`);let{signal:s}=r;i.set(e=>({...e,importing:e.importing+o.length}));let c=re.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 ez(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 OJ({main:t,companions:i.companions,format:i.format.id},{priorInMemoryValues:bR(d().datasets),signal:s,onProgress:e=>a.emit(`import`,{file:t.name,phase:`progress`,fraction:e}),chooseChannels:r.chooseChannels,pickChannels:r.pickChannels}):[await yR(crypto.randomUUID(),t,d().datasets)??await _R(crypto.randomUUID(),t,b9,void 0,bR(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 SE(`cancelled`)}for(let t of o)G(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 SE&&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 re=c.catch(()=>void 0),c},ae=()=>setTimeout(()=>{n||o5(at)},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}}),ee(d().selection.filter(e=>!t(e))),n.length>0&&ae()},se=async(e,t,n={})=>{let[r,...i]=await OJ({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=u9({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=U5((e,t)=>{let n=new Map;for(let r of e){let e=d9(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:ie,warmImport(e={}){l(),gJ(!!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 SE(`not_found`,{datasetId:e});if(!t.info?.combined||!(t.file instanceof File))throw new SE(`invalid_argument`,{reason:`only a combined multi-rate import can be split`});let n=await OJ({main:t.file,companions:t.companions??[],format:t.info.importer},{priorInMemoryValues:bR(d().datasets.filter(t=>t.id!==e)),selection:t.info.selection,split:!0});oe([e]);for(let e of n)G(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 SE(`not_found`,{datasetId:e});if(!n.info||!(n.file instanceof File))throw new SE(`invalid_argument`,{reason:`only binary imports have channels to choose`});try{let r=await OJ({main:n.file,companions:n.companions??[],format:n.info.importer},{priorInMemoryValues:bR(d().datasets.filter(t=>t.id!==e)),initial:n.info.selection,chooseChannels:t,pickChannels:!0});oe([e]);for(let e of r)G(e);return r.map(e=>e.id)}catch(e){if(e instanceof SE&&e.code===`cancelled`)return null;throw e}},async combine(e){l();let t=d().datasets.find(t=>t.id===e);if(!t)throw new SE(`not_found`,{datasetId:e});let n=t.info?.splitKey;if(!n||!(t.file instanceof File))throw new SE(`invalid_argument`,{reason:`only datasets split from one file can be combined`});let r=d().datasets.filter(e=>e.info?.splitKey===n),i=await OJ({main:t.file,companions:t.companions??[],format:t.info.importer},{priorInMemoryValues:bR(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 SE(`invalid_argument`,{reason:`these groups have no common time base`})}return oe(r.map(e=>e.id)),G(i[0]),i[0].id},async openRecording(e,t={}){l();let n=await se(e,bR(d().datasets),t);return G(n),n.id},async reopenRecording(e,t){l();let n=d().datasets.find(t=>t.id===e);if(!n)throw new SE(`not_found`,{datasetId:e});let r=await se(t,bR(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()},addColumns(e){l();let t=F5(crypto.randomUUID(),e);return G(t),t.id},replaceColumns(e,t,n={}){l();let r=d().datasets.find(t=>t.id===e);if(!r)throw new SE(`not_found`,{datasetId:e});let a=z5(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 SE(`not_found`,{datasetId:e});let a=L5(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 mR(crypto.randomUUID(),t,e);return G(n),n.id},async findCycles(e,t,n){l();let r=d().datasets.find(t=>t.id===e);if(!r)throw new SE(`not_found`,{datasetId:e});let i=await Jw(r.source,n,Xw(t)),a=new Map(t.filter(e=>e.kpis?.length).map(e=>[e.id,e.kpis]));return Yw(i,t).map(e=>a.has(e.definitionId)?{...e,kpis:Qw(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 SE(`not_found`,{datasetId:e});let r=n.schema.filter(e=>e.type===`number`&&e.name!==t.timeKey).map(e=>e.name),i=await Jw(n.source,t.timeKey,r),a={...Object.fromEntries(n.schema.map(e=>[e.name,e.unit])),[Kw]:`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 SE(`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:eT(i,t.timeKey,r),units:a}))}if(t.tables!==!1){let e=nT(t.found,t.cycleId,t.defs,i);s.push(await de.addText(rT(e.cycles),`${n.name} · ${o(t.cycleId)}s.csv`)),e.phases.length&&s.push(await de.addText(rT(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 SE(`not_found`,{datasetId:e});let r;if(t){if(!t.defs.some(e=>e.id===t.cycleId))throw new SE(`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 Jw(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=Yw(a,t.defs).sort((e,t)=>e.tstart-t.tstart||!!e.parentIndex-+!!t.parentIndex).map(e=>c.has(e.definitionId)?{...e,kpis:Qw(a,e,c.get(e.definitionId))}:e),u={...Object.fromEntries(n.schema.map(e=>[e.name,e.unit])),[Kw]:`s`},d=e=>t.defs.find(t=>t.id===e)?.name??e,f=l.map(r=>F5(`${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:eT(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 ee(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 SE(`not_found`,{datasetId:e});if(t.parseConfig&&(n.kind!==`memory`||!n.parseConfig))throw new SE(`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 SE(`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?lY(n.data.rows,r.channel):[],l=r&&t.selectCycles===`best`?dY(c.map(e=>uY(n.data.rows,e,r.metric,r.stat))):null,u=l===null?c.map((t,n)=>pY(e,n)):[pY(e,l)];ee(o?c.length>0?[...s,...u]:[...s,e]:s)}let r=t.parseConfig;if(!r)return;let a=(()=>{try{let e=lE(aE(n.rawText??``),r.headerRow);return n.data.columnNames.length===e.length&&n.data.columnNames.every((t,n)=>t===e[n])}catch{return!1}})();if(oE(r,n.parseConfig)&&a)return;let o=n.fromColumns?V5(n):n.rawText??``,s=await DE(n.file?{file:n.file,config:r}:{rawText:o,config:r}),c=new VE(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=>mE(s.rows,e)),_=g.find(e=>e===`ET`)??g[0];E(()=>i.set(e=>({...e,worksheets:e.worksheets.map(e=>C9(!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(),ee([...e])},toggle(e){l();let t=d().selection,n=m().laps[e];if(n){let e=n.laps.map(e=>e.id);ee(e.every(e=>t.includes(e))?t.filter(t=>!e.includes(t)):[...t,...e.filter(e=>!t.includes(e))]);return}ee(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);ee([...d().datasets.flatMap(t=>e[t.id]?e[t.id].laps.map(e=>e.id):[t.id]),...t])},deselectAll(){l(),ee([])},raw(e){let t=d().datasets.find(t=>t.id===e);if(!t)throw new SE(`not_found`,{datasetId:e});return{get rawText(){return t.kind===`memory`&&t.fromColumns?V5(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=AJ(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=AJ(i.rows,e);return Number.isFinite(a.min)&&Number.isFinite(a.max)?a:null}},fe=(e,t=L().xKey)=>{let n=m();if(!n.merged)return null;if(!n.channels.find(t=>t.name===e))return n.merged;let r=dw(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:``}:x9(fe(e,t),e,n),me={fromFileList:e=>WY(Array.from(e)),async fromDataTransfer(e){return GY(Array.from(e.items??[]).map(e=>e.webkitGetAsEntry?.()).filter(e=>!!e))},canPick:KY,pick:qY,tree:(e,t)=>UY(e,t),isImportable:HY},he={add(e=`Worksheet`){l();let t=d(),n=t.limits.maxWorksheets;n!==null&&t.worksheets.length>=n&&u(`worksheets`);let r={..._9(L().xKey||`ET`),name:e};return i.set(e=>({...e,worksheets:[...e.worksheets,r],activeWorksheetId:r.id})),r.id},rename(e,t){l(),L(e),B(e,e=>e.name===t?e:{...e,name:t})},remove(e){l();let t=d();if(L(e),t.worksheets.length<=1)throw new SE(`invalid_argument`,{reason:`the last worksheet cannot be removed`});let n=t.worksheets.findIndex(t=>t.id===e),r=t.worksheets.filter(t=>t.id!==e);i.set(t=>({...t,worksheets:r,activeWorksheetId:t.activeWorksheetId===e?r[Math.max(0,n-1)].id:t.activeWorksheetId}))},reorder(e,t){l(),i.set(n=>{if(e===t||e<0||t<0||e>=n.worksheets.length||t>=n.worksheets.length)return n;let r=[...n.worksheets],[i]=r.splice(e,1);return r.splice(t,0,i),{...n,worksheets:r}})},activate(e){l(),L(e),i.set(t=>t.activeWorksheetId===e?t:{...t,activeWorksheetId:e,xRanges:{...t.xRanges,[e]:null}})},setXKey(e,t){l(),L(e),B(e,e=>C9({...e,xKey:t},e=>e!==t)),i.set(t=>({...t,xRanges:{...t.xRanges,[e]:null},offsets:{}}))}},ge={mount(e,t,n){return l(),a5(at,e,t,n)},openWindow(e,t){l(),R(e);let n=R(e).panel.window;return k5(at,e,(t,n)=>a5(at,e,t,n),{...n,...t})},recordWindows(){l();let e=j5(at);for(let t of d().worksheets)for(let n of t.panels)z(n.id,e.get(n.id)??null)},setFonts(e){e.sans&&(X.sans=e.sans),e.mono&&(X.mono=e.mono),o5(at)},kinds:()=>G5,label:q5,add(e,t={}){if(l(),!G5.some(t=>t.kind===e))throw new SE(`invalid_argument`,{kind:e});let n=L(t.worksheetId),r=d().limits.maxChartsPerWorksheet;r!==null&&n.panels.length>=r&&u(`charts-per-worksheet`);let i={...A(e,n.panels),...t.title?{title:t.title}:{}};t.layout&&(i.rect={...t.layout});let a=Ve([i],{},g9[2],4)[i.id],o=a,s=m().numericColumns;if(s.length&&(o.kind===`multiband`||o.kind===`xyscatter`||o.kind===`xyzmesh`)&&(o=S9({...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),B(n.id,e=>({...e,panels:t.layout?[...e.panels,i]:M([...e.panels,i]),panelChartSettings:{...e.panelChartSettings,[i.id]:o}})),i.id},remove(e){l();let{ws:t}=R(e);B(t.id,t=>{let n={...t.panelChartSettings},r={...t.panelChartBackgrounds};return delete n[e],delete r[e],{...t,panels:M(t.panels.filter(t=>t.id!==e)),panelChartSettings:n,panelChartBackgrounds:r}})},rename(e,t){l();let{ws:n}=R(e),r=t?.trim()||void 0;B(n.id,t=>({...t,panels:t.panels.map(t=>{if(t.id!==e)return t;let{title:n,...i}=t;return r?{...i,title:r}:i})}))},update(e,t){l();let{ws:n}=R(e),r=n.panelChartSettings[e],i={...r,...t,kind:r.kind};if(r.kind===`xyscatter`&&i.kind===`xyscatter`){let e=t;typeof e.xyXCol==`string`&&e.xyXCol!==r.xyXCol&&!(`xyXScale`in e)&&(i={...i,xyXScale: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),V(e,()=>i)},replaceSettings(e,t){l();let{ws:n,panel:r}=R(e);if(t.kind!==r.kind)throw new SE(`invalid_argument`,{reason:`settings kind mismatch`});f(n.panelChartSettings[e],t),V(e,()=>t)},setBackground(e,t){l();let{ws:n}=R(e);B(n.id,n=>({...n,panelChartBackgrounds:{...n.panelChartBackgrounds,[e]:t}}))},addAnnotation(e,t){l(),R(e);let n=v({...t,id:t.id||crypto.randomUUID()});if(!n)throw new SE(`invalid_argument`,{reason:`not a valid annotation`});return V(e,e=>({...e,annotations:[...(e.annotations??[]).filter(e=>e.id!==n.id),n]})),n.id},updateAnnotation(e,t,n){l();let r=(R(e).ws.panelChartSettings[e]?.annotations??[]).find(e=>e.id===t);if(!r)throw new SE(`not_found`,{annotationId:t});let i=v({...r,...n,id:r.id,kind:r.kind});if(!i)throw new SE(`invalid_argument`,{reason:`not a valid annotation`});V(e,e=>({...e,annotations:(e.annotations??[]).map(e=>e.id===i.id?i:e)}))},removeAnnotation(e,t){l(),R(e),V(e,e=>({...e,annotations:(e.annotations??[]).filter(e=>e.id!==t)}))},setAnnotations(e,t){l(),R(e);let n=y(t)??[];V(e,e=>({...e,annotations:n}))},setLayout(e,t){l();let{ws:n}=R(e);B(n.id,n=>({...n,panels:n.panels.map(n=>n.id===e?{...n,rect:{...t}}:n)}))},setLayouts(e,t){l(),B(e,e=>({...e,panels:e.panels.map(e=>t[e.id]?{...e,rect:{...t[e.id]}}:e)}))},autoLayout(e){l(),B(L(e).id,e=>({...e,panels:M(e.panels)}))},get(e){let{ws:t,panel:n}=R(e);return h(t,n)},list(e){let t=L(e);return t.panels.map(e=>h(t,e))},async addSeries(e,t){l();let{ws:n}=R(e),r=n.panelChartSettings[e];if(!r||r.kind!==`multiband`)throw new SE(`invalid_argument`,{reason:`not a multiband chart`});let i=d().limits.maxChannelsPerChart;i!==null&&jJ(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&&a.length>0)return null;let c=Ue(),f={id:c,column:s,color:g9[r.series.length%g9.length],bandFromPct:0,bandToPct:100,scaleMin:0,scaleMax:+!!s,yMajorStep:0,yMinorStep:0};return V(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}=R(e),i=r.panelChartSettings[e],a=i&&i.kind===`multiband`?i.series.find(e=>e.id===t):void 0;if(!a)throw new SE(`not_found`,{seriesId:t});V(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(),V(e,e=>e.kind===`multiband`?{...e,series:e.series.filter(e=>e.id!==t)}:e)},reorderSeries(e,t){l(),V(e,e=>{if(e.kind!==`multiband`)return e;let n=new Map(e.series.map(e=>[e.id,e])),r=t.map(e=>n.get(e)).filter(e=>!!e),i=e.series.filter(e=>!t.includes(e.id));return{...e,series:[...r,...i]}})},async autoScaleSeries(e,t){l();let{ws:r}=R(e),i=r.panelChartSettings[e],a=i&&i.kind===`multiband`?i.series.find(e=>e.id===t):void 0;if(!a)return;let o=await de.columnBounds(a.column);!o||n||V(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 Set;i.subscribe(()=>{let e=new Set(m().numericColumns);if(e.size!==0){for(let t of d().worksheets)for(let[n,r]of Object.entries(t.panelChartSettings))if(r.kind===`multiband`)for(let t of r.series){let r=`${t.id}
|
|
638
|
+
${t.column}`;t.scaleMin!==t.scaleMax||!e.has(t.column)||_e.has(r)||(_e.add(r),ge.autoScaleSeries(n,t.id))}}});let ve=new Map,ye={setXRange(e,t){l();let n=L(t).id;i.set(t=>{let r=t.xRanges[n]??null;return r===e||r&&e&&r[0]===e[0]&&r[1]===e[1]?t:{...t,xRanges:{...t.xRanges,[n]:e}}})},resetZoom(e){ye.setXRange(null,e)},setCursorX(e,t){l();let n=L(t).id;(ve.get(n)??null)!==e&&(ve.set(n,e),a.emit(`cursorchange`,{worksheetId:n,x:e}))},cursorX(e){return ve.get(L(e).id)??null},setLiveWindow(e,t){l();let n=L(t);n.liveWindowSeconds!==e&&B(n.id,t=>({...t,liveWindowSeconds:e}))}},be={save(e){l();let t=e.id??crypto.randomUUID(),[n]=Gw([{...e,id:t,parentId:e.parentId??null}].concat(d().cycleRules.filter(e=>e.id!==t))).filter(e=>e.id===t);if(!n)throw new SE(`invalid_argument`,{reason:`not a valid cycle rule (or its parent is missing)`});return i.set(e=>({...e,cycleRules:e.cycleRules.some(e=>e.id===t)?e.cycleRules.map(e=>e.id===t?n:e):[...e.cycleRules,n]})),t},remove(e){l();let t=new Set([e]);for(let e=!0;e;){e=!1;for(let n of d().cycleRules)n.parentId&&t.has(n.parentId)&&!t.has(n.id)&&(t.add(n.id),e=!0)}i.set(e=>({...e,cycleRules:e.cycleRules.filter(e=>!t.has(e.id))}))}},xe={create(e){l();let n=d(),r=n.limits.maxMathChannels;r!==null&&n.mathChannels.length>=r&&u(`math-channels`);let o=We(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 SE(`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 SE(`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 hw(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:()=>pw(d().mathChannels),preview(e,t){let n=m();return n.merged?qC(e,n.merged,L(t).xKey,n.channels.filter(t=>t.id!==e.id)):null},sync(e){l(),i.set(t=>{let n=t.mathChannels.filter(e=>e.source===`workbook`),r=n.length?[...e,...n]:e;return t.mathChannels===r?t:{...t,mathChannels:r}})}},Se=U5((e,t)=>[...e.flatMap(e=>e.kind===`camera`&&e.video?[Sw({...e,video:e.video})]:[]),...t]),Ce=``;i.subscribe(()=>{let e=Se(d().live,d().video),t=e.map(e=>`${e.kind}:${e.id}:${e.recordingId??``}:${e.name}:${e.sync?`${e.sync.offsetMs}/${e.sync.driftPpm}/${e.sync.method}`:``}`).join(`|`);t!==Ce&&(Ce=t,a.emit(`videochange`,{sources:e}))});let we=(e,t,n)=>e.id===t&&(n===void 0||(e.recordingId??null)===n),Te={sources:()=>Se(d().live,d().video),register(e){l(),i.set(t=>({...t,video:[...t.video.filter(t=>!we(t,e.id,e.recordingId??null)),e]}))},setSync(e,t,n){l();for(let r of Se(d().live,d().video))r.id===e&&(t===void 0||(r.recordingId??null)===t)&&(r.sync=n);i.set(e=>({...e,video:[...e.video]}))},async detectSync(e,t,n){l();let r=d().video.find(n=>n.kind===`recorded`&&n.id===e&&n.recordingId===t),i=d().datasets.find(e=>e.info?.meta?.recordingId===t);if(!r||!i)throw Error(`Open the recording this camera was recorded with`);let a=Number(i.info?.meta?.wallOrigin);if(!Number.isFinite(a)||!i.schema.some(e=>e.name===`Time`))throw Error(`This recording has no wall clock`);let o=await zT({video:r,data:i.source,schema:i.schema,timeKey:`Time`,wallOrigin:a},n);return o.ok?{...o,offsetMs:o.offsetMs-yw(r.clockOffsetMs,r.dataClockOffsetMs)*1e3}:o},relayClock(){l();let e=t.live?.relay?.url;return e?XT(e,fetch,Date.now):Promise.resolve(null)},async calibrateFlash(e,t,n={}){l();let r=Se(d().live,d().video).find(t=>t.kind===`live`&&t.id===e);if(!r?.unitsBetween)throw Error(`This camera isn’t live`);let i=r.clockOffsetMs??n.displayClockOffsetMs??0,a=t.map(e=>({t:e.t+i/1e3,level:e.level})),o=r.acquire?.();try{let e=a[a.length-1].t+3;for(let t=0;(r.range()?.[1]??0)<e&&t<15e3;t+=250){if(n.signal?.aborted)throw new DOMException(`The operation was aborted.`,`AbortError`);await new Promise(e=>setTimeout(e,250))}return JT(await RT(r,[[a[0].t-1,e]],{signal:n.signal,onProgress:n.onProgress}),a)}finally{o?.()}},unregister(e,t){l(),i.set(n=>n.video.some(n=>we(n,e,t))?{...n,video:n.video.filter(n=>!we(n,e,t))}:n)}},Ee={openLocal(e,t){return l(),U.openLocal(e,t)},async connect(e,t,n){l(),await U.connect(e,t,n)},startRecording(e){l(),U.startRecording(e)},stopRecording(e){return l(),U.stopRecording(e)},setSegmentAxis(e,t){l(),U.setSegmentAxis(e,t)},rowCount(e){return U.connections().find(t=>t.id===e)?.source.size()??0},disconnect(e){l(),U.disconnect(e),ee(d().selection.filter(t=>t!==e))}},De=()=>{d().limits.canImportExportWorkspaces||u(`workspaces-io`)},Oe=async e=>{if(e instanceof Blob)try{return JSON.parse(await e.text())}catch{throw new SE(`bad_file`)}if(typeof e==`string`)try{return JSON.parse(e)}catch{throw new SE(`bad_file`)}return e},ke=async e=>e instanceof File?e:new File([JSON.stringify(await Oe(e))],`import.json`,{type:`application/json`}),Ae=e=>e.replace(/[^\w.-]+/g,`_`),je=e=>new Blob([JSON.stringify(e,null,2)],{type:`application/json`}),Me=e=>{let t=Be(e.panelChartSettings,g9[2],4),n={};for(let r of e.panels)t[r.id]?.kind===r.kind&&(n[r.id]=t[r.id]);return{...e,panelChartSettings:Ve(e.panels,n,g9[2],4)}},Ne=(e,t)=>e.map(e=>{let n=e=>{let n=t.has(e)?crypto.randomUUID():e;return t.add(n),n},r=new Map(e.panels.map(e=>[e.id,n(e.id)])),i=e=>Object.fromEntries(Object.entries(e).map(([e,t])=>[r.get(e)??e,t]));return{...e,id:n(e.id),panels:e.panels.map(e=>({...e,id:r.get(e.id)})),panelChartSettings:i(e.panelChartSettings),panelChartBackgrounds:i(e.panelChartBackgrounds??{})}}),Pe=()=>new Set(d().worksheets.flatMap(e=>[e.id,...e.panels.map(e=>e.id)])),Fe=(e,t=0)=>{let n=d().limits.maxWorksheets,r=Ne((n===null?e:e.slice(0,Math.max(1,n))).map(Me),new Set),a=r[Math.min(t,r.length-1)];i.set(e=>({...e,worksheets:r,activeWorksheetId:a.id,xRanges:{}}))},Ie=(e,t)=>{let n=L(t),r=d().limits.maxChartsPerWorksheet;r!==null&&n.panels.length>=r&&u(`charts-per-worksheet`);let i=d().limits.maxChannelsPerChart;i!==null&&jJ(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 B(n.id,t=>({...t,panels:M([...t.panels,o]),panelChartSettings:{...t.panelChartSettings,[a]:e.settings},panelChartBackgrounds:e.background===null?t.panelChartBackgrounds:{...t.panelChartBackgrounds,[a]:e.background}})),a},Le=()=>{let e=d();return EY({worksheets:e.worksheets,activeWorksheetId:e.activeWorksheetId,channels:W(p(e.mathChannels,e.limits.maxMathChannels),e.worksheets),liveWindowSeconds:e.liveWindowSeconds,laps:e.datasets.find(e=>e.beacon)?.beacon??null,cycles:e.cycleRules})},Re=e=>{if(e.worksheets.length===0)throw new SE(`bad_workspace`,{errors:e.errors});let{channels:t,rename:n}=v9(d().mathChannels,e.mathChannels);Fe(n.size?e.worksheets.map(e=>y9(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,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}},ze=e=>{if(e===null)return;let t=m().numericColumns,n=t.length?e.worksheets.map(e=>S9(e,t)):e.worksheets;w=!0;try{i.set(t=>{let r=t=>e.worksheets.some(e=>e.id===t);return{...t,worksheets:n,activeWorksheetId:r(t.activeWorksheetId)?t.activeWorksheetId:r(e.activeWorksheetId)?e.activeWorksheetId:e.worksheets[0].id,xRanges:Object.fromEntries(Object.entries(t.xRanges).filter(([e])=>r(e))),mathChannels:[...t.mathChannels.filter(e=>e.source!==`workbook`),...e.channels],liveWindowSeconds:e.liveWindowSeconds}})}finally{w=!1}O=D(d()),C.rebase(k()),j()},He={undo(){l(),ze(C.undo())},redo(){l(),ze(C.redo())},clear(){l(),P()}},Ge={hasWork:()=>LY(d().worksheets),exportWorksheet(e){l(),De();let t=L(e),n=DY(t);return{json:n,blob:je(n),filename:`${Ae(t.name||`worksheet`)}.kymosh`}},exportChart(e){l(),De();let{ws:t,panel:n}=R(e),r=OY(n,t.panelChartSettings[e],t.panelChartBackgrounds[e]??null);return{json:r,blob:je(r),filename:`${Ae(n.title?.trim()||n.kind)}.json`}},parseFile:e=>BY(e),exportWorkspace(){l(),De();let e=Le();return{json:e,blob:je(e),filename:`kymoscope-workspace-${new Date().toISOString().slice(0,10)}.json`}},async exportWorkspaceEncrypted(e){l(),De();let t=typeof e==`string`?await gY(Le(),e):await _Y(Le(),e);return{json:t,blob:je(t),filename:`kymoscope-workbook-${new Date().toISOString().slice(0,10)}.kymo`}},async importWorkspace(e,t={}){l(),De();let n=await Oe(e);return vY(n)&&(n=await xY(n,t)),F(()=>Re(IY(n)))},toWorkbook:Le,openWorkbook(e){return l(),F(()=>Re(IY(e)))},async importWorksheet(e){l(),De();let t=d();t.limits.maxWorksheets!==null&&t.worksheets.length>=t.limits.maxWorksheets&&u(`worksheets`);let n=await BY(await ke(e));if(n.type!==`worksheet`)throw new SE(`bad_file`,{found:n.type});let[r]=Ne([Me(n.worksheet)],Pe());return i.set(e=>({...e,worksheets:[...e.worksheets,r],activeWorksheetId:r.id})),r.id},async importChart(e,t){l(),De();let n=await BY(await ke(e));if(n.type!==`chart`)throw new SE(`bad_file`,{found:n.type});return Ie(n.chart,t)},snapshot(){let e=d();return{datasets:e.datasets,worksheets:e.worksheets,activeWorksheetId:e.activeWorksheetId,selection:e.selection}},restore(e){l();let t=new Set(e.datasets);for(let e of d().datasets)t.has(e)||e.source.dispose().catch(()=>void 0);let n=e.worksheets.length?e.worksheets.map(Me):[_9()];F(()=>i.set(t=>({...t,datasets:e.datasets,worksheets:n,activeWorksheetId:n.some(t=>t.id===e.activeWorksheetId)?e.activeWorksheetId:n[0].id,selection:e.selection,xRanges:{},offsets:{},colors:{}})))},reset(){l(),F(()=>{oe(d().datasets.map(e=>e.id));let e=_9();i.set(t=>({...t,worksheets:[e],activeWorksheetId:e.id,xRanges:{},offsets:{},colors:{},mathChannels:t.mathChannels.filter(e=>e.source!==`workbook`)}))})}},Ke={merged(e){let t=m();if(!t.merged||t.channels.length===0)return t.merged;let n=dw(t.merged,t.channels,L(e).xKey);return{...t.merged,columnNames:[...t.merged.columnNames,...n.ok.map(e=>e.name)],units:[...t.merged.units,...n.ok.map(e=>e.units)],rows:n.rows}},plotted(){return m().merged}},qe=typeof location<`u`?location.hostname:``,Je=t.license,Ye=t.licenseKey,Xe=!1,Ze={},Qe=e=>{n||i.set(t=>({...t,licensed:e}))},$e=(e,t,n)=>{clearTimeout(Ze[e]);let r=Math.max(0,t-Date.now()),i=r>2**31-1;Ze[e]=setTimeout(()=>{i?$e(e,t,n):n()},i?2**31-1:r)},et=e=>$e(`renew`,e,()=>void nt()),tt=e=>$e(`expiry`,e*1e3+1e3,()=>{$Y(Ye,qe).then(e=>{n||Qe(e.ok)})});async function nt(){let e=36e5,t,r=null,i;try{t=await Promise.race([Je.get(),new Promise((e,t)=>{i=setTimeout(()=>t(Error(`timeout`)),3e4)})]),r=await $Y(t,qe)}catch{}finally{clearTimeout(i)}if(n)return!1;if(r?.ok)return Ye=t,Xe=!0,Qe(!0),tt(r.exp),et(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 $Y(Ye,qe);return n?!1:(Qe(a.ok),et(Date.now()+e),a.ok)}let rt=!Je||t.licenseKey?$Y(t.licenseKey,qe).then(e=>(e.ok||console.warn(`[kymoscope] license ${e.reason}: showing attribution`),!Xe&&!n&&(Qe(e.ok),e.ok&&Je&&tt(e.exp)),e.ok)):null,it=Je?nt():rt;w=!1,P();let at={getState:I,subscribe(e){return i.subscribe(e)},on:a.on,licensed:it,isLicensed:()=>d().licensed,setOptions(e){if(l(),t={...t,...e},e.live&&U.setRelay(e.live.relay),e.palette&&o(),e.limits){let t={...d().limits,...e.limits};i.set(e=>{let n=t.maxWorksheets===null?e.worksheets:e.worksheets.slice(0,Math.max(1,t.maxWorksheets)),r=n.some(t=>t.id===e.activeWorksheetId)?e.activeWorksheetId:n[0].id;return{...e,limits:t,activeWorksheetId:r}})}},datasets:de,folders:me,worksheets:he,charts:ge,view:ye,mathChannels:xe,cycles:be,live:Ee,video:Te,io:Ge,history:He,data:Ke,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(Ze.renew),clearTimeout(Ze.expiry),s(),A5(at),s5(at),U.dispose();for(let e of d().datasets)e.source.dispose().catch(()=>void 0);a.emit(`dispose`,void 0),a.clear()}}};return E9.set(at,{store:i,derived:m,live:U,alertLines:()=>le(d().alertRules,d().alerts)}),at}var E9=new WeakMap;function D9(e){let t=E9.get(e);if(!t)throw new SE(`invalid_argument`,{reason:`not a Kymoscope engine`});return t}return t.CHART_KINDS=G5,t.KymoscopeError=SE,t.chartLabel=q5,t.createEngine=T9,t.verifyLicense=$Y,t})({});
|