svm0n_datadeck/main.js
SVM0N 22e434f0e0 feat(chart): bar/aggregate mode for categorical X + size-by point radius
Picking a categorical column as X (view picker or a csv-chart x: line)
flips into bar mode: one bar per value, with a count/sum/avg aggregate
select (persisted as chartAgg; agg: in blocks). Hue makes grouped bars;
comma-separated columns (Genre, Tags) split so a row counts once per
value; empty X buckets as a — bar pinned last. Fit/formula controls hide
in bar mode. Size-by maps a numeric column onto 3–14 px point radii with
a sqrt (area-true) scale — chartSizeCol / size: — with the raw value in
the tooltip. Bar controller registered in the shared lazy loader.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-12 01:41:23 +00:00

408 lines
395 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use strict";var yc=Object.create;var Ts=Object.defineProperty;var xc=Object.getOwnPropertyDescriptor;var Cc=Object.getOwnPropertyNames;var _c=Object.getPrototypeOf,Sc=Object.prototype.hasOwnProperty;var Ec=(s,t,e)=>t in s?Ts(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e;var bi=(s,t)=>()=>(s&&(t=s(s=0)),t);var kc=(s,t)=>()=>(t||s((t={exports:{}}).exports,t),t.exports),Uo=(s,t)=>{for(var e in t)Ts(s,e,{get:t[e],enumerable:!0})},Yo=(s,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Cc(t))!Sc.call(s,i)&&i!==e&&Ts(s,i,{get:()=>t[i],enumerable:!(n=xc(t,i))||n.enumerable});return s};var dn=(s,t,e)=>(e=s!=null?yc(_c(s)):{},Yo(t||!s||!s.__esModule?Ts(e,"default",{value:s,enumerable:!0}):e,s)),wc=s=>Yo(Ts({},"__esModule",{value:!0}),s);var G=(s,t,e)=>(Ec(s,typeof t!="symbol"?t+"":t,e),e);var Ls=kc((vi,yi)=>{((s,t)=>{typeof define=="function"&&define.amd?define([],t):typeof yi=="object"&&typeof vi!="undefined"?yi.exports=t():s.Papa=t()})(vi,function s(){var t=typeof self!="undefined"?self:typeof window!="undefined"?window:t!==void 0?t:{},e,n=!t.document&&!!t.postMessage,i=t.IS_PAPA_WORKER||!1,o={},r=0,a={};function l(x){this._handle=null,this._finished=!1,this._completed=!1,this._halted=!1,this._input=null,this._baseIndex=0,this._partialLine="",this._rowCount=0,this._start=0,this._nextChunk=null,this.isFirstChunk=!0,this._completeResults={data:[],errors:[],meta:{}},function(v){var _=C(v);_.chunkSize=parseInt(_.chunkSize),v.step||v.chunk||(_.chunkSize=null),this._handle=new f(_),(this._handle.streamer=this)._config=_}.call(this,x),this.parseChunk=function(v,_){var w=parseInt(this._config.skipFirstNLines)||0;if(this.isFirstChunk&&0<w){let k=this._config.newline;k||(D=this._config.quoteChar||'"',k=this._handle.guessLineEndings(v,D)),v=[...v.split(k).slice(w)].join(k)}this.isFirstChunk&&S(this._config.beforeFirstChunk)&&(D=this._config.beforeFirstChunk(v))!==void 0&&(v=D),this.isFirstChunk=!1,this._halted=!1;var w=this._partialLine+v,D=(this._partialLine="",this._handle.parse(w,this._baseIndex,!this._finished));if(!this._handle.paused()&&!this._handle.aborted()){if(v=D.meta.cursor,w=(this._finished||(this._partialLine=w.substring(v-this._baseIndex),this._baseIndex=v),D&&D.data&&(this._rowCount+=D.data.length),this._finished||this._config.preview&&this._rowCount>=this._config.preview),i)t.postMessage({results:D,workerId:a.WORKER_ID,finished:w});else if(S(this._config.chunk)&&!_){if(this._config.chunk(D,this._handle),this._handle.paused()||this._handle.aborted())return void(this._halted=!0);this._completeResults=D=void 0}return this._config.step||this._config.chunk||(this._completeResults.data=this._completeResults.data.concat(D.data),this._completeResults.errors=this._completeResults.errors.concat(D.errors),this._completeResults.meta=D.meta),this._completed||!w||!S(this._config.complete)||D&&D.meta.aborted||(this._config.complete(this._completeResults,this._input),this._completed=!0),w||D&&D.meta.paused||this._nextChunk(),D}this._halted=!0},this._sendError=function(v){S(this._config.error)?this._config.error(v):i&&this._config.error&&t.postMessage({workerId:a.WORKER_ID,error:v,finished:!1})}}function c(x){var v;(x=x||{}).chunkSize||(x.chunkSize=a.RemoteChunkSize),l.call(this,x),this._nextChunk=n?function(){this._readChunk(),this._chunkLoaded()}:function(){this._readChunk()},this.stream=function(_){this._input=_,this._nextChunk()},this._readChunk=function(){if(this._finished)this._chunkLoaded();else{if(v=new XMLHttpRequest,this._config.withCredentials&&(v.withCredentials=this._config.withCredentials),n||(v.onload=E(this._chunkLoaded,this),v.onerror=E(this._chunkError,this)),v.open(this._config.downloadRequestBody?"POST":"GET",this._input,!n),this._config.downloadRequestHeaders){var _,w=this._config.downloadRequestHeaders;for(_ in w)v.setRequestHeader(_,w[_])}var D;this._config.chunkSize&&(D=this._start+this._config.chunkSize-1,v.setRequestHeader("Range","bytes="+this._start+"-"+D));try{v.send(this._config.downloadRequestBody)}catch(k){this._chunkError(k.message)}n&&v.status===0&&this._chunkError()}},this._chunkLoaded=function(){v.readyState===4&&(v.status<200||400<=v.status?this._chunkError():(this._start+=this._config.chunkSize||v.responseText.length,this._finished=!this._config.chunkSize||this._start>=(_=>(_=_.getResponseHeader("Content-Range"))!==null?parseInt(_.substring(_.lastIndexOf("/")+1)):-1)(v),this.parseChunk(v.responseText)))},this._chunkError=function(_){_=v.statusText||_,this._sendError(new Error(_))}}function d(x){(x=x||{}).chunkSize||(x.chunkSize=a.LocalChunkSize),l.call(this,x);var v,_,w=typeof FileReader!="undefined";this.stream=function(D){this._input=D,_=D.slice||D.webkitSlice||D.mozSlice,w?((v=new FileReader).onload=E(this._chunkLoaded,this),v.onerror=E(this._chunkError,this)):v=new FileReaderSync,this._nextChunk()},this._nextChunk=function(){this._finished||this._config.preview&&!(this._rowCount<this._config.preview)||this._readChunk()},this._readChunk=function(){var D=this._input,k=(this._config.chunkSize&&(k=Math.min(this._start+this._config.chunkSize,this._input.size),D=_.call(D,this._start,k)),v.readAsText(D,this._config.encoding));w||this._chunkLoaded({target:{result:k}})},this._chunkLoaded=function(D){this._start+=this._config.chunkSize,this._finished=!this._config.chunkSize||this._start>=this._input.size,this.parseChunk(D.target.result)},this._chunkError=function(){this._sendError(v.error)}}function h(x){var v;l.call(this,x=x||{}),this.stream=function(_){return v=_,this._nextChunk()},this._nextChunk=function(){var _,w;if(!this._finished)return _=this._config.chunkSize,v=_?(w=v.substring(0,_),v.substring(_)):(w=v,""),this._finished=!v,this.parseChunk(w)}}function u(x){l.call(this,x=x||{});var v=[],_=!0,w=!1;this.pause=function(){l.prototype.pause.apply(this,arguments),this._input.pause()},this.resume=function(){l.prototype.resume.apply(this,arguments),this._input.resume()},this.stream=function(D){this._input=D,this._input.on("data",this._streamData),this._input.on("end",this._streamEnd),this._input.on("error",this._streamError)},this._checkIsFinished=function(){w&&v.length===1&&(this._finished=!0)},this._nextChunk=function(){this._checkIsFinished(),v.length?this.parseChunk(v.shift()):_=!0},this._streamData=E(function(D){try{v.push(typeof D=="string"?D:D.toString(this._config.encoding)),_&&(_=!1,this._checkIsFinished(),this.parseChunk(v.shift()))}catch(k){this._streamError(k)}},this),this._streamError=E(function(D){this._streamCleanUp(),this._sendError(D)},this),this._streamEnd=E(function(){this._streamCleanUp(),w=!0,this._streamData("")},this),this._streamCleanUp=E(function(){this._input.removeListener("data",this._streamData),this._input.removeListener("end",this._streamEnd),this._input.removeListener("error",this._streamError)},this)}function f(x){var v,_,w,D,k=Math.pow(2,53),T=-k,A=/^\s*-?(\d+\.?|\.\d+|\d+\.\d+)([eE][-+]?\d+)?\s*$/,I=/^((\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z)))$/,V=this,O=0,M=0,j=!1,F=!1,Y=[],$={data:[],errors:[],meta:{}};function R(P){return x.skipEmptyLines==="greedy"?P.join("").trim()==="":P.length===1&&P[0].length===0}function W(){if($&&w&&(N("Delimiter","UndetectableDelimiter","Unable to auto-detect delimiting character; defaulted to '"+a.DefaultDelimiter+"'"),w=!1),x.skipEmptyLines&&($.data=$.data.filter(function(H){return!R(H)})),K()){let H=function(U,q){S(x.transformHeader)&&(U=x.transformHeader(U,q)),Y.push(U)};var B=H;if($)if(Array.isArray($.data[0])){for(var P=0;K()&&P<$.data.length;P++)$.data[P].forEach(H);$.data.splice(0,1)}else $.data.forEach(H)}function L(H,U){for(var q=x.header?{}:[],X=0;X<H.length;X++){var Z=X,at=H[X],at=((Q,st)=>(lt=>(x.dynamicTypingFunction&&x.dynamicTyping[lt]===void 0&&(x.dynamicTyping[lt]=x.dynamicTypingFunction(lt)),(x.dynamicTyping[lt]||x.dynamicTyping)===!0))(Q)?st==="true"||st==="TRUE"||st!=="false"&&st!=="FALSE"&&((lt=>{if(A.test(lt)&&(lt=parseFloat(lt),T<lt&&lt<k))return 1})(st)?parseFloat(st):I.test(st)?new Date(st):st===""?null:st):st)(Z=x.header?X>=Y.length?"__parsed_extra":Y[X]:Z,at=x.transform?x.transform(at,Z):at);Z==="__parsed_extra"?(q[Z]=q[Z]||[],q[Z].push(at)):q[Z]=at}return x.header&&(X>Y.length?N("FieldMismatch","TooManyFields","Too many fields: expected "+Y.length+" fields but parsed "+X,M+U):X<Y.length&&N("FieldMismatch","TooFewFields","Too few fields: expected "+Y.length+" fields but parsed "+X,M+U)),q}var z;$&&(x.header||x.dynamicTyping||x.transform)&&(z=1,!$.data.length||Array.isArray($.data[0])?($.data=$.data.map(L),z=$.data.length):$.data=L($.data,0),x.header&&$.meta&&($.meta.fields=Y),M+=z)}function K(){return x.header&&Y.length===0}function N(P,L,z,B){P={type:P,code:L,message:z},B!==void 0&&(P.row=B),$.errors.push(P)}S(x.step)&&(D=x.step,x.step=function(P){$=P,K()?W():(W(),$.data.length!==0&&(O+=P.data.length,x.preview&&O>x.preview?_.abort():($.data=$.data[0],D($,V))))}),this.parse=function(P,L,z){var B=x.quoteChar||'"',B=(x.newline||(x.newline=this.guessLineEndings(P,B)),w=!1,x.delimiter?S(x.delimiter)&&(x.delimiter=x.delimiter(P),$.meta.delimiter=x.delimiter):((B=((H,U,q,X,Z)=>{var at,Q,st,lt;Z=Z||[","," ","|",";",a.RECORD_SEP,a.UNIT_SEP];for(var Wt=0;Wt<Z.length;Wt++){for(var ot,pt=Z[Wt],ft=0,Gt=0,yt=0,Dt=(st=void 0,new p({comments:X,delimiter:pt,newline:U,preview:10}).parse(H)),oe=0;oe<Dt.data.length;oe++)q&&R(Dt.data[oe])?yt++:(ot=Dt.data[oe].length,Gt+=ot,st===void 0?st=ot:0<ot&&(ft+=Math.abs(ot-st),st=ot));0<Dt.data.length&&(Gt/=Dt.data.length-yt),(Q===void 0||ft<=Q)&&(lt===void 0||lt<Gt)&&1.99<Gt&&(Q=ft,at=pt,lt=Gt)}return{successful:!!(x.delimiter=at),bestDelimiter:at}})(P,x.newline,x.skipEmptyLines,x.comments,x.delimitersToGuess)).successful?x.delimiter=B.bestDelimiter:(w=!0,x.delimiter=a.DefaultDelimiter),$.meta.delimiter=x.delimiter),C(x));return x.preview&&x.header&&B.preview++,v=P,_=new p(B),$=_.parse(v,L,z),W(),j?{meta:{paused:!0}}:$||{meta:{paused:!1}}},this.paused=function(){return j},this.pause=function(){j=!0,_.abort(),v=S(x.chunk)?"":v.substring(_.getCharIndex())},this.resume=function(){V.streamer._halted?(j=!1,V.streamer.parseChunk(v,!0)):setTimeout(V.resume,3)},this.aborted=function(){return F},this.abort=function(){F=!0,_.abort(),$.meta.aborted=!0,S(x.complete)&&x.complete($),v=""},this.guessLineEndings=function(H,B){H=H.substring(0,1048576);var B=new RegExp(g(B)+"([^]*?)"+g(B),"gm"),z=(H=H.replace(B,"")).split("\r"),B=H.split(`
`),H=1<B.length&&B[0].length<z[0].length;if(z.length===1||H)return`
`;for(var U=0,q=0;q<z.length;q++)z[q][0]===`
`&&U++;return U>=z.length/2?`\r
`:"\r"}}function g(x){return x.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function p(x){var v=(x=x||{}).delimiter,_=x.newline,w=x.comments,D=x.step,k=x.preview,T=x.fastMode,A=null,I=!1,V=x.quoteChar==null?'"':x.quoteChar,O=V;if(x.escapeChar!==void 0&&(O=x.escapeChar),(typeof v!="string"||-1<a.BAD_DELIMITERS.indexOf(v))&&(v=","),w===v)throw new Error("Comment character same as delimiter");w===!0?w="#":(typeof w!="string"||-1<a.BAD_DELIMITERS.indexOf(w))&&(w=!1),_!==`
`&&_!=="\r"&&_!==`\r
`&&(_=`
`);var M=0,j=!1;this.parse=function(F,Y,$){if(typeof F!="string")throw new Error("Input must be a string");var R=F.length,W=v.length,K=_.length,N=w.length,P=S(D),L=[],z=[],B=[],H=M=0;if(!F)return ft();if(T||T!==!1&&F.indexOf(V)===-1){for(var U=F.split(_),q=0;q<U.length;q++){if(B=U[q],M+=B.length,q!==U.length-1)M+=_.length;else if($)return ft();if(!w||B.substring(0,N)!==w){if(P){if(L=[],lt(B.split(v)),Gt(),j)return ft()}else lt(B.split(v));if(k&&k<=q)return L=L.slice(0,k),ft(!0)}}return ft()}for(var X=F.indexOf(v,M),Z=F.indexOf(_,M),at=new RegExp(g(O)+g(V),"g"),Q=F.indexOf(V,M);;)if(F[M]===V)for(Q=M,M++;;){if((Q=F.indexOf(V,Q+1))===-1)return $||z.push({type:"Quotes",code:"MissingQuotes",message:"Quoted field unterminated",row:L.length,index:M}),ot();if(Q===R-1)return ot(F.substring(M,Q).replace(at,V));if(V===O&&F[Q+1]===O)Q++;else if(V===O||Q===0||F[Q-1]!==O){X!==-1&&X<Q+1&&(X=F.indexOf(v,Q+1));var st=Wt((Z=Z!==-1&&Z<Q+1?F.indexOf(_,Q+1):Z)===-1?X:Math.min(X,Z));if(F.substr(Q+1+st,W)===v){B.push(F.substring(M,Q).replace(at,V)),F[M=Q+1+st+W]!==V&&(Q=F.indexOf(V,M)),X=F.indexOf(v,M),Z=F.indexOf(_,M);break}if(st=Wt(Z),F.substring(Q+1+st,Q+1+st+K)===_){if(B.push(F.substring(M,Q).replace(at,V)),pt(Q+1+st+K),X=F.indexOf(v,M),Q=F.indexOf(V,M),P&&(Gt(),j))return ft();if(k&&L.length>=k)return ft(!0);break}z.push({type:"Quotes",code:"InvalidQuotes",message:"Trailing quote on quoted field is malformed",row:L.length,index:M}),Q++}}else if(w&&B.length===0&&F.substring(M,M+N)===w){if(Z===-1)return ft();M=Z+K,Z=F.indexOf(_,M),X=F.indexOf(v,M)}else if(X!==-1&&(X<Z||Z===-1))B.push(F.substring(M,X)),M=X+W,X=F.indexOf(v,M);else{if(Z===-1)break;if(B.push(F.substring(M,Z)),pt(Z+K),P&&(Gt(),j))return ft();if(k&&L.length>=k)return ft(!0)}return ot();function lt(yt){L.push(yt),H=M}function Wt(yt){var Dt=0;return Dt=yt!==-1&&(yt=F.substring(Q+1,yt))&&yt.trim()===""?yt.length:Dt}function ot(yt){return $||(yt===void 0&&(yt=F.substring(M)),B.push(yt),M=R,lt(B),P&&Gt()),ft()}function pt(yt){M=yt,lt(B),B=[],Z=F.indexOf(_,M)}function ft(yt){if(x.header&&!Y&&L.length&&!I){var Dt=L[0],oe=Object.create(null),mi=new Set(Dt);let Wo=!1;for(let Ye=0;Ye<Dt.length;Ye++){let qt=Dt[Ye];if(oe[qt=S(x.transformHeader)?x.transformHeader(qt,Ye):qt]){let Ds,jo=oe[qt];for(;Ds=qt+"_"+jo,jo++,mi.has(Ds););mi.add(Ds),Dt[Ye]=Ds,oe[qt]++,Wo=!0,(A=A===null?{}:A)[Ds]=qt}else oe[qt]=1,Dt[Ye]=qt;mi.add(qt)}Wo&&console.warn("Duplicate headers found and renamed."),I=!0}return{data:L,errors:z,meta:{delimiter:v,linebreak:_,aborted:j,truncated:!!yt,cursor:H+(Y||0),renamedHeaders:A}}}function Gt(){D(ft()),L=[],z=[]}},this.abort=function(){j=!0},this.getCharIndex=function(){return M}}function b(x){var v=x.data,_=o[v.workerId],w=!1;if(v.error)_.userError(v.error,v.file);else if(v.results&&v.results.data){var D={abort:function(){w=!0,m(v.workerId,{data:[],errors:[],meta:{aborted:!0}})},pause:y,resume:y};if(S(_.userStep)){for(var k=0;k<v.results.data.length&&(_.userStep({data:v.results.data[k],errors:v.results.errors,meta:v.results.meta},D),!w);k++);delete v.results}else S(_.userChunk)&&(_.userChunk(v.results,D,v.file),delete v.results)}v.finished&&!w&&m(v.workerId,v.results)}function m(x,v){var _=o[x];S(_.userComplete)&&_.userComplete(v),_.terminate(),delete o[x]}function y(){throw new Error("Not implemented.")}function C(x){if(typeof x!="object"||x===null)return x;var v,_=Array.isArray(x)?[]:{};for(v in x)_[v]=C(x[v]);return _}function E(x,v){return function(){x.apply(v,arguments)}}function S(x){return typeof x=="function"}return a.parse=function(x,v){var _=(v=v||{}).dynamicTyping||!1;if(S(_)&&(v.dynamicTypingFunction=_,_={}),v.dynamicTyping=_,v.transform=!!S(v.transform)&&v.transform,!v.worker||!a.WORKERS_SUPPORTED)return _=null,a.NODE_STREAM_INPUT,typeof x=="string"?(x=(w=>w.charCodeAt(0)!==65279?w:w.slice(1))(x),_=new(v.download?c:h)(v)):x.readable===!0&&S(x.read)&&S(x.on)?_=new u(v):(t.File&&x instanceof File||x instanceof Object)&&(_=new d(v)),_.stream(x);(_=(()=>{var w;return!!a.WORKERS_SUPPORTED&&(w=(()=>{var D=t.URL||t.webkitURL||null,k=s.toString();return a.BLOB_URL||(a.BLOB_URL=D.createObjectURL(new Blob(["var global = (function() { if (typeof self !== 'undefined') { return self; } if (typeof window !== 'undefined') { return window; } if (typeof global !== 'undefined') { return global; } return {}; })(); global.IS_PAPA_WORKER=true; ","(",k,")();"],{type:"text/javascript"})))})(),(w=new t.Worker(w)).onmessage=b,w.id=r++,o[w.id]=w)})()).userStep=v.step,_.userChunk=v.chunk,_.userComplete=v.complete,_.userError=v.error,v.step=S(v.step),v.chunk=S(v.chunk),v.complete=S(v.complete),v.error=S(v.error),delete v.worker,_.postMessage({input:x,config:v,workerId:_.id})},a.unparse=function(x,v){var _=!1,w=!0,D=",",k=`\r
`,T='"',A=T+T,I=!1,V=null,O=!1,M=((()=>{if(typeof v=="object"){if(typeof v.delimiter!="string"||a.BAD_DELIMITERS.filter(function(Y){return v.delimiter.indexOf(Y)!==-1}).length||(D=v.delimiter),typeof v.quotes!="boolean"&&typeof v.quotes!="function"&&!Array.isArray(v.quotes)||(_=v.quotes),typeof v.skipEmptyLines!="boolean"&&typeof v.skipEmptyLines!="string"||(I=v.skipEmptyLines),typeof v.newline=="string"&&(k=v.newline),typeof v.quoteChar=="string"&&(T=v.quoteChar),typeof v.header=="boolean"&&(w=v.header),Array.isArray(v.columns)){if(v.columns.length===0)throw new Error("Option columns is empty");V=v.columns}v.escapeChar!==void 0&&(A=v.escapeChar+T),v.escapeFormulae instanceof RegExp?O=v.escapeFormulae:typeof v.escapeFormulae=="boolean"&&v.escapeFormulae&&(O=/^[=+\-@\t\r].*$/)}})(),new RegExp(g(T),"g"));if(typeof x=="string"&&(x=JSON.parse(x)),Array.isArray(x)){if(!x.length||Array.isArray(x[0]))return j(null,x,I);if(typeof x[0]=="object")return j(V||Object.keys(x[0]),x,I)}else if(typeof x=="object")return typeof x.data=="string"&&(x.data=JSON.parse(x.data)),Array.isArray(x.data)&&(x.fields||(x.fields=x.meta&&x.meta.fields||V),x.fields||(x.fields=Array.isArray(x.data[0])?x.fields:typeof x.data[0]=="object"?Object.keys(x.data[0]):[]),Array.isArray(x.data[0])||typeof x.data[0]=="object"||(x.data=[x.data])),j(x.fields||[],x.data||[],I);throw new Error("Unable to serialize unrecognized input");function j(Y,$,R){var W="",K=(typeof Y=="string"&&(Y=JSON.parse(Y)),typeof $=="string"&&($=JSON.parse($)),Array.isArray(Y)&&0<Y.length),N=!Array.isArray($[0]);if(K&&w){for(var P=0;P<Y.length;P++)0<P&&(W+=D),W+=F(Y[P],P);0<$.length&&(W+=k)}for(var L=0;L<$.length;L++){var z=(K?Y:$[L]).length,B=!1,H=K?Object.keys($[L]).length===0:$[L].length===0;if(R&&!K&&(B=R==="greedy"?$[L].join("").trim()==="":$[L].length===1&&$[L][0].length===0),R==="greedy"&&K){for(var U=[],q=0;q<z;q++){var X=N?Y[q]:q;U.push($[L][X])}B=U.join("").trim()===""}if(!B){for(var Z=0;Z<z;Z++){0<Z&&!H&&(W+=D);var at=K&&N?Y[Z]:Z;W+=F($[L][at],Z)}L<$.length-1&&(!R||0<z&&!H)&&(W+=k)}}return W}function F(Y,$){var R,W;return Y==null?"":Y.constructor===Date?JSON.stringify(Y).slice(1,25):(W=!1,O&&typeof Y=="string"&&O.test(Y)&&(Y="'"+Y,W=!0),R=Y.toString().replace(M,A),(W=W||_===!0||typeof _=="function"&&_(Y,$)||Array.isArray(_)&&_[$]||((K,N)=>{for(var P=0;P<N.length;P++)if(-1<K.indexOf(N[P]))return!0;return!1})(R,a.BAD_DELIMITERS)||-1<R.indexOf(D)||R.charAt(0)===" "||R.charAt(R.length-1)===" ")?T+R+T:R)}},a.RECORD_SEP="",a.UNIT_SEP="",a.BYTE_ORDER_MARK="\uFEFF",a.BAD_DELIMITERS=["\r",`
`,'"',a.BYTE_ORDER_MARK],a.WORKERS_SUPPORTED=!n&&!!t.Worker,a.NODE_STREAM_INPUT=1,a.LocalChunkSize=10485760,a.RemoteChunkSize=5242880,a.DefaultDelimiter=",",a.Parser=p,a.ParserHandle=f,a.NetworkStreamer=c,a.FileStreamer=d,a.StringStreamer=h,a.ReadableStreamStreamer=u,t.jQuery&&((e=t.jQuery).fn.parse=function(x){var v=x.config||{},_=[];return this.each(function(k){if(!(e(this).prop("tagName").toUpperCase()==="INPUT"&&e(this).attr("type").toLowerCase()==="file"&&t.FileReader)||!this.files||this.files.length===0)return!0;for(var T=0;T<this.files.length;T++)_.push({file:this.files[T],inputElem:this,instanceConfig:e.extend({},v)})}),w(),this;function w(){if(_.length===0)S(x.complete)&&x.complete();else{var k,T,A,I,V=_[0];if(S(x.before)){var O=x.before(V.file,V.inputElem);if(typeof O=="object"){if(O.action==="abort")return k="AbortError",T=V.file,A=V.inputElem,I=O.reason,void(S(x.error)&&x.error({name:k},T,A,I));if(O.action==="skip")return void D();typeof O.config=="object"&&(V.instanceConfig=e.extend(V.instanceConfig,O.config))}else if(O==="skip")return void D()}var M=V.instanceConfig.complete;V.instanceConfig.complete=function(j){S(M)&&M(j,V.file,V.inputElem),D()},a.parse(V.file,V.instanceConfig)}}function D(){_.splice(0,1),w()}}),i&&(t.onmessage=function(x){x=x.data,a.WORKER_ID===void 0&&x&&(a.WORKER_ID=x.workerId),typeof x.input=="string"?t.postMessage({workerId:a.WORKER_ID,results:a.parse(x.input,x.config),finished:!0}):(t.File&&x.input instanceof File||x.input instanceof Object)&&(x=a.parse(x.input,x.config))&&t.postMessage({workerId:a.WORKER_ID,results:x,finished:!0})}),(c.prototype=Object.create(l.prototype)).constructor=c,(d.prototype=Object.create(l.prototype)).constructor=d,(h.prototype=Object.create(h.prototype)).constructor=h,(u.prototype=Object.create(l.prototype)).constructor=u,a})});function zs(s){return s+.5|0}function Ns(s){return pe(zs(s*2.55),0,255)}function me(s){return pe(zs(s*255),0,255)}function re(s){return pe(zs(s/2.55)/100,0,1)}function Sr(s){return pe(zs(s*100),0,100)}function sd(s){var t=s.length,e;return s[0]==="#"&&(t===4||t===5?e={r:255&zt[s[1]]*17,g:255&zt[s[2]]*17,b:255&zt[s[3]]*17,a:t===5?zt[s[4]]*17:255}:(t===7||t===9)&&(e={r:zt[s[1]]<<4|zt[s[2]],g:zt[s[3]]<<4|zt[s[4]],b:zt[s[5]]<<4|zt[s[6]],a:t===9?zt[s[7]]<<4|zt[s[8]]:255})),e}function id(s){var t=ed(s)?Jc:td;return s?"#"+t(s.r)+t(s.g)+t(s.b)+nd(s.a,t):void 0}function Mr(s,t,e){let n=t*Math.min(e,1-e),i=(o,r=(o+s/30)%12)=>e-n*Math.max(Math.min(r-3,9-r,1),-1);return[i(0),i(8),i(4)]}function rd(s,t,e){let n=(i,o=(i+s/60)%6)=>e-e*t*Math.max(Math.min(o,4-o,1),0);return[n(5),n(3),n(1)]}function ad(s,t,e){let n=Mr(s,1,.5),i;for(t+e>1&&(i=1/(t+e),t*=i,e*=i),i=0;i<3;i++)n[i]*=1-t-e,n[i]+=t;return n}function ld(s,t,e,n,i){return s===i?(t-e)/n+(t<e?6:0):t===i?(e-s)/n+2:(s-t)/n+4}function Ai(s){let e=s.r/255,n=s.g/255,i=s.b/255,o=Math.max(e,n,i),r=Math.min(e,n,i),a=(o+r)/2,l,c,d;return o!==r&&(d=o-r,c=a>.5?d/(2-o-r):d/(o+r),l=ld(e,n,i,d,o),l=l*60+.5),[l|0,c||0,a]}function Ri(s,t,e,n){return(Array.isArray(t)?s(t[0],t[1],t[2]):s(t,e,n)).map(me)}function Pi(s,t,e){return Ri(Mr,s,t,e)}function cd(s,t,e){return Ri(ad,s,t,e)}function dd(s,t,e){return Ri(rd,s,t,e)}function Dr(s){return(s%360+360)%360}function hd(s){let t=od.exec(s),e=255,n;if(!t)return;t[5]!==n&&(e=t[6]?Ns(+t[5]):me(+t[5]));let i=Dr(+t[2]),o=+t[3]/100,r=+t[4]/100;return t[1]==="hwb"?n=cd(i,o,r):t[1]==="hsv"?n=dd(i,o,r):n=Pi(i,o,r),{r:n[0],g:n[1],b:n[2],a:e}}function ud(s,t){var e=Ai(s);e[0]=Dr(e[0]+t),e=Pi(e),s.r=e[0],s.g=e[1],s.b=e[2]}function fd(s){if(!s)return;let t=Ai(s),e=t[0],n=Sr(t[1]),i=Sr(t[2]);return s.a<255?`hsla(${e}, ${n}%, ${i}%, ${re(s.a)})`:`hsl(${e}, ${n}%, ${i}%)`}function gd(){let s={},t=Object.keys(kr),e=Object.keys(Er),n,i,o,r,a;for(n=0;n<t.length;n++){for(r=a=t[n],i=0;i<e.length;i++)o=e[i],a=a.replace(o,Er[o]);o=parseInt(kr[r],16),s[a]=[o>>16&255,o>>8&255,o&255]}return s}function pd(s){En||(En=gd(),En.transparent=[0,0,0,0]);let t=En[s.toLowerCase()];return t&&{r:t[0],g:t[1],b:t[2],a:t.length===4?t[3]:255}}function bd(s){let t=md.exec(s),e=255,n,i,o;if(t){if(t[7]!==n){let r=+t[7];e=t[8]?Ns(r):pe(r*255,0,255)}return n=+t[1],i=+t[3],o=+t[5],n=255&(t[2]?Ns(n):pe(n,0,255)),i=255&(t[4]?Ns(i):pe(i,0,255)),o=255&(t[6]?Ns(o):pe(o,0,255)),{r:n,g:i,b:o,a:e}}}function vd(s){return s&&(s.a<255?`rgba(${s.r}, ${s.g}, ${s.b}, ${re(s.a)})`:`rgb(${s.r}, ${s.g}, ${s.b})`)}function yd(s,t,e){let n=is(re(s.r)),i=is(re(s.g)),o=is(re(s.b));return{r:me(Ti(n+e*(is(re(t.r))-n))),g:me(Ti(i+e*(is(re(t.g))-i))),b:me(Ti(o+e*(is(re(t.b))-o))),a:s.a+e*(t.a-s.a)}}function kn(s,t,e){if(s){let n=Ai(s);n[t]=Math.max(0,Math.min(n[t]+n[t]*e,t===0?360:1)),n=Pi(n),s.r=n[0],s.g=n[1],s.b=n[2]}}function Tr(s,t){return s&&Object.assign(t||{},s)}function wr(s){var t={r:0,g:0,b:0,a:255};return Array.isArray(s)?s.length>=3&&(t={r:s[0],g:s[1],b:s[2],a:255},s.length>3&&(t.a=me(s[3]))):(t=Tr(s,{r:0,g:0,b:0,a:1}),t.a=me(t.a)),t}function xd(s){return s.charAt(0)==="r"?bd(s):hd(s)}var pe,zt,Li,Jc,td,Sn,ed,nd,od,Er,kr,En,md,Ti,is,$s,Lr=bi(()=>{pe=(s,t,e)=>Math.max(Math.min(s,e),t);zt={0:0,1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8,9:9,A:10,B:11,C:12,D:13,E:14,F:15,a:10,b:11,c:12,d:13,e:14,f:15},Li=[..."0123456789ABCDEF"],Jc=s=>Li[s&15],td=s=>Li[(s&240)>>4]+Li[s&15],Sn=s=>(s&240)>>4===(s&15),ed=s=>Sn(s.r)&&Sn(s.g)&&Sn(s.b)&&Sn(s.a);nd=(s,t)=>s<255?t(s):"";od=/^(hsla?|hwb|hsv)\(\s*([-+.e\d]+)(?:deg)?[\s,]+([-+.e\d]+)%[\s,]+([-+.e\d]+)%(?:[\s,]+([-+.e\d]+)(%)?)?\s*\)$/;Er={x:"dark",Z:"light",Y:"re",X:"blu",W:"gr",V:"medium",U:"slate",A:"ee",T:"ol",S:"or",B:"ra",C:"lateg",D:"ights",R:"in",Q:"turquois",E:"hi",P:"ro",O:"al",N:"le",M:"de",L:"yello",F:"en",K:"ch",G:"arks",H:"ea",I:"ightg",J:"wh"},kr={OiceXe:"f0f8ff",antiquewEte:"faebd7",aqua:"ffff",aquamarRe:"7fffd4",azuY:"f0ffff",beige:"f5f5dc",bisque:"ffe4c4",black:"0",blanKedOmond:"ffebcd",Xe:"ff",XeviTet:"8a2be2",bPwn:"a52a2a",burlywood:"deb887",caMtXe:"5f9ea0",KartYuse:"7fff00",KocTate:"d2691e",cSO:"ff7f50",cSnflowerXe:"6495ed",cSnsilk:"fff8dc",crimson:"dc143c",cyan:"ffff",xXe:"8b",xcyan:"8b8b",xgTMnPd:"b8860b",xWay:"a9a9a9",xgYF:"6400",xgYy:"a9a9a9",xkhaki:"bdb76b",xmagFta:"8b008b",xTivegYF:"556b2f",xSange:"ff8c00",xScEd:"9932cc",xYd:"8b0000",xsOmon:"e9967a",xsHgYF:"8fbc8f",xUXe:"483d8b",xUWay:"2f4f4f",xUgYy:"2f4f4f",xQe:"ced1",xviTet:"9400d3",dAppRk:"ff1493",dApskyXe:"bfff",dimWay:"696969",dimgYy:"696969",dodgerXe:"1e90ff",fiYbrick:"b22222",flSOwEte:"fffaf0",foYstWAn:"228b22",fuKsia:"ff00ff",gaRsbSo:"dcdcdc",ghostwEte:"f8f8ff",gTd:"ffd700",gTMnPd:"daa520",Way:"808080",gYF:"8000",gYFLw:"adff2f",gYy:"808080",honeyMw:"f0fff0",hotpRk:"ff69b4",RdianYd:"cd5c5c",Rdigo:"4b0082",ivSy:"fffff0",khaki:"f0e68c",lavFMr:"e6e6fa",lavFMrXsh:"fff0f5",lawngYF:"7cfc00",NmoncEffon:"fffacd",ZXe:"add8e6",ZcSO:"f08080",Zcyan:"e0ffff",ZgTMnPdLw:"fafad2",ZWay:"d3d3d3",ZgYF:"90ee90",ZgYy:"d3d3d3",ZpRk:"ffb6c1",ZsOmon:"ffa07a",ZsHgYF:"20b2aa",ZskyXe:"87cefa",ZUWay:"778899",ZUgYy:"778899",ZstAlXe:"b0c4de",ZLw:"ffffe0",lime:"ff00",limegYF:"32cd32",lRF:"faf0e6",magFta:"ff00ff",maPon:"800000",VaquamarRe:"66cdaa",VXe:"cd",VScEd:"ba55d3",VpurpN:"9370db",VsHgYF:"3cb371",VUXe:"7b68ee",VsprRggYF:"fa9a",VQe:"48d1cc",VviTetYd:"c71585",midnightXe:"191970",mRtcYam:"f5fffa",mistyPse:"ffe4e1",moccasR:"ffe4b5",navajowEte:"ffdead",navy:"80",Tdlace:"fdf5e6",Tive:"808000",TivedBb:"6b8e23",Sange:"ffa500",SangeYd:"ff4500",ScEd:"da70d6",pOegTMnPd:"eee8aa",pOegYF:"98fb98",pOeQe:"afeeee",pOeviTetYd:"db7093",papayawEp:"ffefd5",pHKpuff:"ffdab9",peru:"cd853f",pRk:"ffc0cb",plum:"dda0dd",powMrXe:"b0e0e6",purpN:"800080",YbeccapurpN:"663399",Yd:"ff0000",Psybrown:"bc8f8f",PyOXe:"4169e1",saddNbPwn:"8b4513",sOmon:"fa8072",sandybPwn:"f4a460",sHgYF:"2e8b57",sHshell:"fff5ee",siFna:"a0522d",silver:"c0c0c0",skyXe:"87ceeb",UXe:"6a5acd",UWay:"708090",UgYy:"708090",snow:"fffafa",sprRggYF:"ff7f",stAlXe:"4682b4",tan:"d2b48c",teO:"8080",tEstN:"d8bfd8",tomato:"ff6347",Qe:"40e0d0",viTet:"ee82ee",JHt:"f5deb3",wEte:"ffffff",wEtesmoke:"f5f5f5",Lw:"ffff00",LwgYF:"9acd32"};md=/^rgba?\(\s*([-+.\d]+)(%)?[\s,]+([-+.e\d]+)(%)?[\s,]+([-+.e\d]+)(%)?(?:[\s,/]+([-+.e\d]+)(%)?)?\s*\)$/;Ti=s=>s<=.0031308?s*12.92:Math.pow(s,1/2.4)*1.055-.055,is=s=>s<=.04045?s/12.92:Math.pow((s+.055)/1.055,2.4);$s=class s{constructor(t){if(t instanceof s)return t;let e=typeof t,n;e==="object"?n=wr(t):e==="string"&&(n=sd(t)||pd(t)||xd(t)),this._rgb=n,this._valid=!!n}get valid(){return this._valid}get rgb(){var t=Tr(this._rgb);return t&&(t.a=re(t.a)),t}set rgb(t){this._rgb=wr(t)}rgbString(){return this._valid?vd(this._rgb):void 0}hexString(){return this._valid?id(this._rgb):void 0}hslString(){return this._valid?fd(this._rgb):void 0}mix(t,e){if(t){let n=this.rgb,i=t.rgb,o,r=e===o?.5:e,a=2*r-1,l=n.a-i.a,c=((a*l===-1?a:(a+l)/(1+a*l))+1)/2;o=1-c,n.r=255&c*n.r+o*i.r+.5,n.g=255&c*n.g+o*i.g+.5,n.b=255&c*n.b+o*i.b+.5,n.a=r*n.a+(1-r)*i.a,this.rgb=n}return this}interpolate(t,e){return t&&(this._rgb=yd(this._rgb,t._rgb,e)),this}clone(){return new s(this.rgb)}alpha(t){return this._rgb.a=me(t),this}clearer(t){let e=this._rgb;return e.a*=1-t,this}greyscale(){let t=this._rgb,e=zs(t.r*.3+t.g*.59+t.b*.11);return t.r=t.g=t.b=e,this}opaquer(t){let e=this._rgb;return e.a*=1+t,this}negate(){let t=this._rgb;return t.r=255-t.r,t.g=255-t.g,t.b=255-t.b,this}lighten(t){return kn(this._rgb,2,t),this}darken(t){return kn(this._rgb,2,-t),this}saturate(t){return kn(this._rgb,1,t),this}desaturate(t){return kn(this._rgb,1,-t),this}rotate(t){return ud(this._rgb,t),this}}});function Jt(){}function tt(s){return s==null}function dt(s){if(Array.isArray&&Array.isArray(s))return!0;let t=Object.prototype.toString.call(s);return t.slice(0,7)==="[object"&&t.slice(-6)==="Array]"}function et(s){return s!==null&&Object.prototype.toString.call(s)==="[object Object]"}function gt(s){return(typeof s=="number"||s instanceof Number)&&isFinite(+s)}function Tt(s,t){return gt(s)?s:t}function J(s,t){return typeof s=="undefined"?t:s}function ct(s,t,e){if(s&&typeof s.call=="function")return s.apply(e,t)}function rt(s,t,e,n){let i,o,r;if(dt(s))if(o=s.length,n)for(i=o-1;i>=0;i--)t.call(e,s[i],i);else for(i=0;i<o;i++)t.call(e,s[i],i);else if(et(s))for(r=Object.keys(s),o=r.length,i=0;i<o;i++)t.call(e,s[r[i]],r[i])}function js(s,t){let e,n,i,o;if(!s||!t||s.length!==t.length)return!1;for(e=0,n=s.length;e<n;++e)if(i=s[e],o=t[e],i.datasetIndex!==o.datasetIndex||i.index!==o.index)return!1;return!0}function Tn(s){if(dt(s))return s.map(Tn);if(et(s)){let t=Object.create(null),e=Object.keys(s),n=e.length,i=0;for(;i<n;++i)t[e[i]]=Tn(s[e[i]]);return t}return s}function Wr(s){return["__proto__","prototype","constructor"].indexOf(s)===-1}function Cd(s,t,e,n){if(!Wr(s))return;let i=t[s],o=e[s];et(i)&&et(o)?rs(i,o,n):t[s]=Tn(o)}function rs(s,t,e){let n=dt(t)?t:[t],i=n.length;if(!et(s))return s;e=e||{};let o=e.merger||Cd,r;for(let a=0;a<i;++a){if(r=n[a],!et(r))continue;let l=Object.keys(r);for(let c=0,d=l.length;c<d;++c)o(l[c],s,r,e)}return s}function ls(s,t){return rs(s,t,{merger:_d})}function _d(s,t,e){if(!Wr(s))return;let n=t[s],i=e[s];et(n)&&et(i)?ls(n,i):Object.prototype.hasOwnProperty.call(t,s)||(t[s]=Tn(i))}function Sd(s){let t=s.split("."),e=[],n="";for(let i of t)n+=i,n.endsWith("\\")?n=n.slice(0,-1)+".":(e.push(n),n="");return e}function Ed(s){let t=Sd(s);return e=>{for(let n of t){if(n==="")break;e=e&&e[n]}return e}}function ce(s,t){return(Ar[t]||(Ar[t]=Ed(t)))(s)}function Pn(s){return s.charAt(0).toUpperCase()+s.slice(1)}function jr(s){return s.type==="mouseup"||s.type==="click"||s.type==="contextmenu"}function ds(s,t,e){return Math.abs(s-t)<e}function Ni(s){let t=Math.round(s);s=ds(s,t,s/1e3)?t:s;let e=Math.pow(10,Math.floor(le(s))),n=s/e;return(n<=1?1:n<=2?2:n<=5?5:10)*e}function Ur(s){let t=[],e=Math.sqrt(s),n;for(n=1;n<e;n++)s%n===0&&(t.push(n),t.push(s/n));return e===(e|0)&&t.push(e),t.sort((i,o)=>i-o).pop(),t}function Md(s){return typeof s=="symbol"||typeof s=="object"&&s!==null&&!(Symbol.toPrimitive in s||"toString"in s||"valueOf"in s)}function Oe(s){return!Md(s)&&!isNaN(parseFloat(s))&&isFinite(s)}function Yr(s,t){let e=Math.round(s);return e-t<=s&&e+t>=s}function $i(s,t,e){let n,i,o;for(n=0,i=s.length;n<i;n++)o=s[n][e],isNaN(o)||(t.min=Math.min(t.min,o),t.max=Math.max(t.max,o))}function Ht(s){return s*(nt/180)}function On(s){return s*(180/nt)}function zi(s){if(!gt(s))return;let t=1,e=0;for(;Math.round(s*t)/t!==s;)t*=10,e++;return e}function Hi(s,t){let e=t.x-s.x,n=t.y-s.y,i=Math.sqrt(e*e+n*n),o=Math.atan2(n,e);return o<-.5*nt&&(o+=ht),{angle:o,distance:i}}function An(s,t){return Math.sqrt(Math.pow(t.x-s.x,2)+Math.pow(t.y-s.y,2))}function Dd(s,t){return(s-t+kd)%ht-nt}function Ct(s){return(s%ht+ht)%ht}function hs(s,t,e,n){let i=Ct(s),o=Ct(t),r=Ct(e),a=Ct(o-i),l=Ct(r-i),c=Ct(i-o),d=Ct(i-r);return i===o||i===r||n&&o===r||a>l&&c<d}function vt(s,t,e){return Math.max(t,Math.min(e,s))}function Kr(s){return vt(s,-32768,32767)}function te(s,t,e,n=1e-6){return s>=Math.min(t,e)-n&&s<=Math.max(t,e)+n}function Fn(s,t,e){e=e||(r=>s[r]<t);let n=s.length-1,i=0,o;for(;n-i>1;)o=i+n>>1,e(o)?i=o:n=o;return{lo:i,hi:n}}function qr(s,t,e){let n=0,i=s.length;for(;n<i&&s[n]<t;)n++;for(;i>n&&s[i-1]>e;)i--;return n>0||i<s.length?s.slice(n,i):s}function Qr(s,t){if(s._chartjs){s._chartjs.listeners.push(t);return}Object.defineProperty(s,"_chartjs",{configurable:!0,enumerable:!1,value:{listeners:[t]}}),Xr.forEach(e=>{let n="_onData"+Pn(e),i=s[e];Object.defineProperty(s,e,{configurable:!0,enumerable:!1,value(...o){let r=i.apply(this,o);return s._chartjs.listeners.forEach(a=>{typeof a[n]=="function"&&a[n](...o)}),r}})})}function Wi(s,t){let e=s._chartjs;if(!e)return;let n=e.listeners,i=n.indexOf(t);i!==-1&&n.splice(i,1),!(n.length>0)&&(Xr.forEach(o=>{delete s[o]}),delete s._chartjs)}function ji(s){let t=new Set(s);return t.size===s.length?s:Array.from(t)}function Yi(s,t){let e=[],n=!1;return function(...i){e=i,n||(n=!0,Ui.call(window,()=>{n=!1,s.apply(t,e)}))}}function Zr(s,t){let e;return function(...n){return t?(clearTimeout(e),e=setTimeout(s,t,n)):s.apply(this,n),t}}function Ki(s,t,e){let n=t.length,i=0,o=n;if(s._sorted){let{iScale:r,vScale:a,_parsed:l}=s,c=s.dataset&&s.dataset.options?s.dataset.options.spanGaps:null,d=r.axis,{min:h,max:u,minDefined:f,maxDefined:g}=r.getUserBounds();if(f){if(i=Math.min(Qt(l,d,h).lo,e?n:Qt(t,d,r.getPixelForValue(h)).lo),c){let p=l.slice(0,i+1).reverse().findIndex(b=>!tt(b[a.axis]));i-=Math.max(0,p)}i=vt(i,0,n-1)}if(g){let p=Math.max(Qt(l,r.axis,u,!0).hi+1,e?0:Qt(t,d,r.getPixelForValue(u),!0).hi+1);if(c){let b=l.slice(p-1).findIndex(m=>!tt(m[a.axis]));p+=Math.max(0,b)}o=vt(p,i,n)-i}else o=n-i}return{start:i,count:o}}function Gi(s){let{xScale:t,yScale:e,_scaleRanges:n}=s,i={xmin:t.min,xmax:t.max,ymin:e.min,ymax:e.max};if(!n)return s._scaleRanges=i,!0;let o=n.xmin!==t.min||n.xmax!==t.max||n.ymin!==e.min||n.ymax!==e.max;return Object.assign(n,i),o}function qi(s){if(s&&typeof s=="object"){let t=s.toString();return t==="[object CanvasPattern]"||t==="[object CanvasGradient]"}return!1}function Xi(s){return qi(s)?s:new $s(s)}function Oi(s){return qi(s)?s:new $s(s).saturate(.5).darken(.1).hexString()}function Ad(s){s.set("animation",{delay:void 0,duration:1e3,easing:"easeOutQuart",fn:void 0,from:void 0,loop:void 0,to:void 0,type:void 0}),s.describe("animation",{_fallback:!1,_indexable:!1,_scriptable:t=>t!=="onProgress"&&t!=="onComplete"&&t!=="fn"}),s.set("animations",{colors:{type:"color",properties:Ld},numbers:{type:"number",properties:Td}}),s.describe("animations",{_fallback:"animation"}),s.set("transitions",{active:{animation:{duration:400}},resize:{animation:{duration:0}},show:{animations:{colors:{from:"transparent"},visible:{type:"boolean",duration:0}}},hide:{animations:{colors:{to:"transparent"},visible:{type:"boolean",easing:"linear",fn:t=>t|0}}}})}function Rd(s){s.set("layout",{autoPadding:!0,padding:{top:0,right:0,bottom:0,left:0}})}function Pd(s,t){t=t||{};let e=s+JSON.stringify(t),n=Fr.get(e);return n||(n=new Intl.NumberFormat(s,t),Fr.set(e,n)),n}function us(s,t,e){return Pd(t,e).format(s)}function Od(s,t){let e=t.length>3?t[2].value-t[1].value:t[1].value-t[0].value;return Math.abs(e)>=1&&s!==Math.floor(s)&&(e=s-Math.floor(s)),e}function Fd(s){s.set("scale",{display:!0,offset:!1,reverse:!1,beginAtZero:!1,bounds:"ticks",clip:!0,grace:0,grid:{display:!0,lineWidth:1,drawOnChartArea:!0,drawTicks:!0,tickLength:8,tickWidth:(t,e)=>e.lineWidth,tickColor:(t,e)=>e.color,offset:!1},border:{display:!0,dash:[],dashOffset:0,width:1},title:{display:!1,text:"",padding:{top:4,bottom:4}},ticks:{minRotation:0,maxRotation:50,mirror:!1,textStrokeWidth:0,textStrokeColor:"",padding:3,display:!0,autoSkip:!0,autoSkipPadding:3,labelOffset:0,callback:fs.formatters.values,minor:{},major:{},align:"center",crossAlign:"near",showLabelBackdrop:!1,backdropColor:"rgba(255, 255, 255, 0.75)",backdropPadding:2}}),s.route("scale.ticks","color","","color"),s.route("scale.grid","color","","borderColor"),s.route("scale.border","color","","borderColor"),s.route("scale.title","color","","color"),s.describe("scale",{_fallback:!1,_scriptable:t=>!t.startsWith("before")&&!t.startsWith("after")&&t!=="callback"&&t!=="parser",_indexable:t=>t!=="borderDash"&&t!=="tickBorderDash"&&t!=="dash"}),s.describe("scales",{_fallback:"scale"}),s.describe("scale.ticks",{_scriptable:t=>t!=="backdropPadding"&&t!=="callback",_indexable:t=>t!=="backdropPadding"})}function Hs(s,t){if(!t)return s;let e=t.split(".");for(let n=0,i=e.length;n<i;++n){let o=e[n];s=s[o]||(s[o]=Object.create(null))}return s}function Fi(s,t,e){return typeof t=="string"?rs(Hs(s,t),e):rs(Hs(s,""),t)}function Id(s){return!s||tt(s.size)||tt(s.family)?null:(s.style?s.style+" ":"")+(s.weight?s.weight+" ":"")+s.size+"px "+s.family}function Ws(s,t,e,n,i){let o=t[i];return o||(o=t[i]=s.measureText(i).width,e.push(i)),o>n&&(n=o),n}function ea(s,t,e,n){n=n||{};let i=n.data=n.data||{},o=n.garbageCollect=n.garbageCollect||[];n.font!==t&&(i=n.data={},o=n.garbageCollect=[],n.font=t),s.save(),s.font=t;let r=0,a=e.length,l,c,d,h,u;for(l=0;l<a;l++)if(h=e[l],h!=null&&!dt(h))r=Ws(s,i,o,r,h);else if(dt(h))for(c=0,d=h.length;c<d;c++)u=h[c],u!=null&&!dt(u)&&(r=Ws(s,i,o,r,u));s.restore();let f=o.length/2;if(f>e.length){for(l=0;l<f;l++)delete i[o[l]];o.splice(0,f)}return r}function xe(s,t,e){let n=s.currentDevicePixelRatio,i=e!==0?Math.max(e/2,.5):0;return Math.round((t-i)*n)/n+i}function Qi(s,t){!t&&!s||(t=t||s.getContext("2d"),t.save(),t.resetTransform(),t.clearRect(0,0,s.width,s.height),t.restore())}function Bn(s,t,e,n){Zi(s,t,e,n,null)}function Zi(s,t,e,n,i){let o,r,a,l,c,d,h,u,f=t.pointStyle,g=t.rotation,p=t.radius,b=(g||0)*wd;if(f&&typeof f=="object"&&(o=f.toString(),o==="[object HTMLImageElement]"||o==="[object HTMLCanvasElement]")){s.save(),s.translate(e,n),s.rotate(b),s.drawImage(f,-f.width/2,-f.height/2,f.width,f.height),s.restore();return}if(!(isNaN(p)||p<=0)){switch(s.beginPath(),f){default:i?s.ellipse(e,n,i/2,p,0,0,ht):s.arc(e,n,p,0,ht),s.closePath();break;case"triangle":d=i?i/2:p,s.moveTo(e+Math.sin(b)*d,n-Math.cos(b)*p),b+=Rr,s.lineTo(e+Math.sin(b)*d,n-Math.cos(b)*p),b+=Rr,s.lineTo(e+Math.sin(b)*d,n-Math.cos(b)*p),s.closePath();break;case"rectRounded":c=p*.516,l=p-c,r=Math.cos(b+Ae)*l,h=Math.cos(b+Ae)*(i?i/2-c:l),a=Math.sin(b+Ae)*l,u=Math.sin(b+Ae)*(i?i/2-c:l),s.arc(e-h,n-a,c,b-nt,b-mt),s.arc(e+u,n-r,c,b-mt,b),s.arc(e+h,n+a,c,b,b+mt),s.arc(e-u,n+r,c,b+mt,b+nt),s.closePath();break;case"rect":if(!g){l=Math.SQRT1_2*p,d=i?i/2:l,s.rect(e-d,n-l,2*d,2*l);break}b+=Ae;case"rectRot":h=Math.cos(b)*(i?i/2:p),r=Math.cos(b)*p,a=Math.sin(b)*p,u=Math.sin(b)*(i?i/2:p),s.moveTo(e-h,n-a),s.lineTo(e+u,n-r),s.lineTo(e+h,n+a),s.lineTo(e-u,n+r),s.closePath();break;case"crossRot":b+=Ae;case"cross":h=Math.cos(b)*(i?i/2:p),r=Math.cos(b)*p,a=Math.sin(b)*p,u=Math.sin(b)*(i?i/2:p),s.moveTo(e-h,n-a),s.lineTo(e+h,n+a),s.moveTo(e+u,n-r),s.lineTo(e-u,n+r);break;case"star":h=Math.cos(b)*(i?i/2:p),r=Math.cos(b)*p,a=Math.sin(b)*p,u=Math.sin(b)*(i?i/2:p),s.moveTo(e-h,n-a),s.lineTo(e+h,n+a),s.moveTo(e+u,n-r),s.lineTo(e-u,n+r),b+=Ae,h=Math.cos(b)*(i?i/2:p),r=Math.cos(b)*p,a=Math.sin(b)*p,u=Math.sin(b)*(i?i/2:p),s.moveTo(e-h,n-a),s.lineTo(e+h,n+a),s.moveTo(e+u,n-r),s.lineTo(e-u,n+r);break;case"line":r=i?i/2:Math.cos(b)*p,a=Math.sin(b)*p,s.moveTo(e-r,n-a),s.lineTo(e+r,n+a);break;case"dash":s.moveTo(e,n),s.lineTo(e+Math.cos(b)*(i?i/2:p),n+Math.sin(b)*p);break;case!1:s.closePath();break}s.fill(),t.borderWidth>0&&s.stroke()}}function Zt(s,t,e){return e=e||.5,!t||s&&s.x>t.left-e&&s.x<t.right+e&&s.y>t.top-e&&s.y<t.bottom+e}function Us(s,t){s.save(),s.beginPath(),s.rect(t.left,t.top,t.right-t.left,t.bottom-t.top),s.clip()}function Ys(s){s.restore()}function sa(s,t,e,n,i){if(!t)return s.lineTo(e.x,e.y);if(i==="middle"){let o=(t.x+e.x)/2;s.lineTo(o,t.y),s.lineTo(o,e.y)}else i==="after"!=!!n?s.lineTo(t.x,e.y):s.lineTo(e.x,t.y);s.lineTo(e.x,e.y)}function na(s,t,e,n){if(!t)return s.lineTo(e.x,e.y);s.bezierCurveTo(n?t.cp1x:t.cp2x,n?t.cp1y:t.cp2y,n?e.cp2x:e.cp1x,n?e.cp2y:e.cp1y,e.x,e.y)}function Vd(s,t){t.translation&&s.translate(t.translation[0],t.translation[1]),tt(t.rotation)||s.rotate(t.rotation),t.color&&(s.fillStyle=t.color),t.textAlign&&(s.textAlign=t.textAlign),t.textBaseline&&(s.textBaseline=t.textBaseline)}function Bd(s,t,e,n,i){if(i.strikethrough||i.underline){let o=s.measureText(n),r=t-o.actualBoundingBoxLeft,a=t+o.actualBoundingBoxRight,l=e-o.actualBoundingBoxAscent,c=e+o.actualBoundingBoxDescent,d=i.strikethrough?(l+c)/2:c;s.strokeStyle=s.fillStyle,s.beginPath(),s.lineWidth=i.decorationWidth||2,s.moveTo(r,d),s.lineTo(a,d),s.stroke()}}function Nd(s,t){let e=s.fillStyle;s.fillStyle=t.color,s.fillRect(t.left,t.top,t.width,t.height),s.fillStyle=e}function Ce(s,t,e,n,i,o={}){let r=dt(t)?t:[t],a=o.strokeWidth>0&&o.strokeColor!=="",l,c;for(s.save(),s.font=i.string,Vd(s,o),l=0;l<r.length;++l)c=r[l],o.backdrop&&Nd(s,o.backdrop),a&&(o.strokeColor&&(s.strokeStyle=o.strokeColor),tt(o.strokeWidth)||(s.lineWidth=o.strokeWidth),s.strokeText(c,e,n,o.maxWidth)),s.fillText(c,e,n,o.maxWidth),Bd(s,e,n,c,o),n+=Number(i.lineHeight);s.restore()}function gs(s,t){let{x:e,y:n,w:i,h:o,radius:r}=t;s.arc(e+r.topLeft,n+r.topLeft,r.topLeft,1.5*nt,nt,!0),s.lineTo(e,n+o-r.bottomLeft),s.arc(e+r.bottomLeft,n+o-r.bottomLeft,r.bottomLeft,nt,mt,!0),s.lineTo(e+i-r.bottomRight,n+o),s.arc(e+i-r.bottomRight,n+o-r.bottomRight,r.bottomRight,mt,0,!0),s.lineTo(e+i,n+r.topRight),s.arc(e+i-r.topRight,n+r.topRight,r.topRight,0,-mt,!0),s.lineTo(e+r.topLeft,n)}function Hd(s,t){let e=(""+s).match($d);if(!e||e[1]==="normal")return t*1.2;switch(s=+e[2],e[3]){case"px":return s;case"%":s/=100;break}return t*s}function Nn(s,t){let e={},n=et(t),i=n?Object.keys(t):t,o=et(s)?n?r=>J(s[r],s[t[r]]):r=>s[r]:()=>s;for(let r of i)e[r]=Wd(o(r));return e}function Ji(s){return Nn(s,{top:"y",right:"x",bottom:"y",left:"x"})}function _e(s){return Nn(s,["topLeft","topRight","bottomLeft","bottomRight"])}function St(s){let t=Ji(s);return t.width=t.left+t.right,t.height=t.top+t.bottom,t}function bt(s,t){s=s||{},t=t||ut.font;let e=J(s.size,t.size);typeof e=="string"&&(e=parseInt(e,10));let n=J(s.style,t.style);n&&!(""+n).match(zd)&&(console.warn('Invalid font style specified: "'+n+'"'),n=void 0);let i={family:J(s.family,t.family),lineHeight:Hd(J(s.lineHeight,t.lineHeight),e),size:e,style:n,weight:J(s.weight,t.weight),string:""};return i.string=Id(i),i}function ps(s,t,e,n){let i=!0,o,r,a;for(o=0,r=s.length;o<r;++o)if(a=s[o],a!==void 0&&(t!==void 0&&typeof a=="function"&&(a=a(t),i=!1),e!==void 0&&dt(a)&&(a=a[e%a.length],i=!1),a!==void 0))return n&&!i&&(n.cacheable=!1),a}function ia(s,t,e){let{min:n,max:i}=s,o=Vi(t,(i-n)/2),r=(a,l)=>e&&a===0?0:a+l;return{min:r(n,-Math.abs(o)),max:r(i,o)}}function de(s,t){return Object.assign(Object.create(s),t)}function $n(s,t=[""],e,n,i=()=>s[0]){let o=e||s;typeof n=="undefined"&&(n=aa("_fallback",s));let r={[Symbol.toStringTag]:"Object",_cacheable:!0,_scopes:s,_rootScopes:o,_fallback:n,_getTarget:i,override:a=>$n([a,...s],t,o,n)};return new Proxy(r,{deleteProperty(a,l){return delete a[l],delete a._keys,delete s[0][l],!0},get(a,l){return oa(a,l,()=>Qd(l,t,s,a))},getOwnPropertyDescriptor(a,l){return Reflect.getOwnPropertyDescriptor(a._scopes[0],l)},getPrototypeOf(){return Reflect.getPrototypeOf(s[0])},has(a,l){return Vr(a).includes(l)},ownKeys(a){return Vr(a)},set(a,l,c){let d=a._storage||(a._storage=i());return a[l]=d[l]=c,delete a._keys,!0}})}function Pe(s,t,e,n){let i={_cacheable:!1,_proxy:s,_context:t,_subProxy:e,_stack:new Set,_descriptors:to(s,n),setContext:o=>Pe(s,o,e,n),override:o=>Pe(s.override(o),t,e,n)};return new Proxy(i,{deleteProperty(o,r){return delete o[r],delete s[r],!0},get(o,r,a){return oa(o,r,()=>Ud(o,r,a))},getOwnPropertyDescriptor(o,r){return o._descriptors.allKeys?Reflect.has(s,r)?{enumerable:!0,configurable:!0}:void 0:Reflect.getOwnPropertyDescriptor(s,r)},getPrototypeOf(){return Reflect.getPrototypeOf(s)},has(o,r){return Reflect.has(s,r)},ownKeys(){return Reflect.ownKeys(s)},set(o,r,a){return s[r]=a,delete o[r],!0}})}function to(s,t={scriptable:!0,indexable:!0}){let{_scriptable:e=t.scriptable,_indexable:n=t.indexable,_allKeys:i=t.allKeys}=s;return{allKeys:i,scriptable:e,indexable:n,isScriptable:ae(e)?e:()=>e,isIndexable:ae(n)?n:()=>n}}function oa(s,t,e){if(Object.prototype.hasOwnProperty.call(s,t)||t==="constructor")return s[t];let n=e();return s[t]=n,n}function Ud(s,t,e){let{_proxy:n,_context:i,_subProxy:o,_descriptors:r}=s,a=n[t];return ae(a)&&r.isScriptable(t)&&(a=Yd(t,a,s,e)),dt(a)&&a.length&&(a=Kd(t,a,s,r.isIndexable)),eo(t,a)&&(a=Pe(a,i,o&&o[t],r)),a}function Yd(s,t,e,n){let{_proxy:i,_context:o,_subProxy:r,_stack:a}=e;if(a.has(s))throw new Error("Recursion detected: "+Array.from(a).join("->")+"->"+s);a.add(s);let l=t(o,r||n);return a.delete(s),eo(s,l)&&(l=so(i._scopes,i,s,l)),l}function Kd(s,t,e,n){let{_proxy:i,_context:o,_subProxy:r,_descriptors:a}=e;if(typeof o.index!="undefined"&&n(s))return t[o.index%t.length];if(et(t[0])){let l=t,c=i._scopes.filter(d=>d!==l);t=[];for(let d of l){let h=so(c,i,s,d);t.push(Pe(h,o,r&&r[s],a))}}return t}function ra(s,t,e){return ae(s)?s(t,e):s}function qd(s,t,e,n,i){for(let o of t){let r=Gd(e,o);if(r){s.add(r);let a=ra(r._fallback,e,i);if(typeof a!="undefined"&&a!==e&&a!==n)return a}else if(r===!1&&typeof n!="undefined"&&e!==n)return null}return!1}function so(s,t,e,n){let i=t._rootScopes,o=ra(t._fallback,e,n),r=[...s,...i],a=new Set;a.add(n);let l=Ir(a,r,e,o||e,n);return l===null||typeof o!="undefined"&&o!==e&&(l=Ir(a,r,o,l,n),l===null)?!1:$n(Array.from(a),[""],i,o,()=>Xd(t,e,n))}function Ir(s,t,e,n,i){for(;e;)e=qd(s,t,e,n,i);return e}function Xd(s,t,e){let n=s._getTarget();t in n||(n[t]={});let i=n[t];return dt(i)&&et(e)?e:i||{}}function Qd(s,t,e,n){let i;for(let o of t)if(i=aa(jd(o,s),e),typeof i!="undefined")return eo(s,i)?so(e,n,s,i):i}function aa(s,t){for(let e of t){if(!e)continue;let n=e[s];if(typeof n!="undefined")return n}}function Vr(s){let t=s._keys;return t||(t=s._keys=Zd(s._scopes)),t}function Zd(s){let t=new Set;for(let e of s)for(let n of Object.keys(e).filter(i=>!i.startsWith("_")))t.add(n);return Array.from(t)}function no(s,t,e,n){let{iScale:i}=s,{key:o="r"}=this._parsing,r=new Array(n),a,l,c,d;for(a=0,l=n;a<l;++a)c=a+e,d=t[c],r[a]={r:i.parse(ce(d,o),c)};return r}function th(s,t,e,n){let i=s.skip?t:s,o=t,r=e.skip?t:e,a=An(o,i),l=An(r,o),c=a/(a+l),d=l/(a+l);c=isNaN(c)?0:c,d=isNaN(d)?0:d;let h=n*c,u=n*d;return{previous:{x:o.x-h*(r.x-i.x),y:o.y-h*(r.y-i.y)},next:{x:o.x+u*(r.x-i.x),y:o.y+u*(r.y-i.y)}}}function eh(s,t,e){let n=s.length,i,o,r,a,l,c=as(s,0);for(let d=0;d<n-1;++d)if(l=c,c=as(s,d+1),!(!l||!c)){if(ds(t[d],0,Jd)){e[d]=e[d+1]=0;continue}i=e[d]/t[d],o=e[d+1]/t[d],a=Math.pow(i,2)+Math.pow(o,2),!(a<=9)&&(r=3/Math.sqrt(a),e[d]=i*r*t[d],e[d+1]=o*r*t[d])}}function sh(s,t,e="x"){let n=la(e),i=s.length,o,r,a,l=as(s,0);for(let c=0;c<i;++c){if(r=a,a=l,l=as(s,c+1),!a)continue;let d=a[e],h=a[n];r&&(o=(d-r[e])/3,a[`cp1${e}`]=d-o,a[`cp1${n}`]=h-o*t[c]),l&&(o=(l[e]-d)/3,a[`cp2${e}`]=d+o,a[`cp2${n}`]=h+o*t[c])}}function nh(s,t="x"){let e=la(t),n=s.length,i=Array(n).fill(0),o=Array(n),r,a,l,c=as(s,0);for(r=0;r<n;++r)if(a=l,l=c,c=as(s,r+1),!!l){if(c){let d=c[t]-l[t];i[r]=d!==0?(c[e]-l[e])/d:0}o[r]=a?c?Ut(i[r-1])!==Ut(i[r])?0:(i[r-1]+i[r])/2:i[r-1]:i[r]}eh(s,i,o),sh(s,o,t)}function Mn(s,t,e){return Math.max(Math.min(s,e),t)}function ih(s,t){let e,n,i,o,r,a=Zt(s[0],t);for(e=0,n=s.length;e<n;++e)r=o,o=a,a=e<n-1&&Zt(s[e+1],t),o&&(i=s[e],r&&(i.cp1x=Mn(i.cp1x,t.left,t.right),i.cp1y=Mn(i.cp1y,t.top,t.bottom)),a&&(i.cp2x=Mn(i.cp2x,t.left,t.right),i.cp2y=Mn(i.cp2y,t.top,t.bottom)))}function ca(s,t,e,n,i){let o,r,a,l;if(t.spanGaps&&(s=s.filter(c=>!c.skip)),t.cubicInterpolationMode==="monotone")nh(s,i);else{let c=n?s[s.length-1]:s[0];for(o=0,r=s.length;o<r;++o)a=s[o],l=th(c,a,s[Math.min(o+1,r-(n?0:1))%r],t.tension),a.cp1x=l.previous.x,a.cp1y=l.previous.y,a.cp2x=l.next.x,a.cp2y=l.next.y,c=a}t.capBezierPoints&&ih(s,e)}function zn(){return typeof window!="undefined"&&typeof document!="undefined"}function Hn(s){let t=s.parentNode;return t&&t.toString()==="[object ShadowRoot]"&&(t=t.host),t}function Rn(s,t,e){let n;return typeof s=="string"?(n=parseInt(s,10),s.indexOf("%")!==-1&&(n=n/100*t.parentNode[e])):n=s,n}function oh(s,t){return Wn(s).getPropertyValue(t)}function Re(s,t,e){let n={};e=e?"-"+e:"";for(let i=0;i<4;i++){let o=rh[i];n[o]=parseFloat(s[t+"-"+o+e])||0}return n.width=n.left+n.right,n.height=n.top+n.bottom,n}function lh(s,t){let e=s.touches,n=e&&e.length?e[0]:s,{offsetX:i,offsetY:o}=n,r=!1,a,l;if(ah(i,o,s.target))a=i,l=o;else{let c=t.getBoundingClientRect();a=n.clientX-c.left,l=n.clientY-c.top,r=!0}return{x:a,y:l,box:r}}function Se(s,t){if("native"in s)return s;let{canvas:e,currentDevicePixelRatio:n}=t,i=Wn(e),o=i.boxSizing==="border-box",r=Re(i,"padding"),a=Re(i,"border","width"),{x:l,y:c,box:d}=lh(s,e),h=r.left+(d&&a.left),u=r.top+(d&&a.top),{width:f,height:g}=t;return o&&(f-=r.width+a.width,g-=r.height+a.height),{x:Math.round((l-h)/f*e.width/n),y:Math.round((c-u)/g*e.height/n)}}function ch(s,t,e){let n,i;if(t===void 0||e===void 0){let o=s&&Hn(s);if(!o)t=s.clientWidth,e=s.clientHeight;else{let r=o.getBoundingClientRect(),a=Wn(o),l=Re(a,"border","width"),c=Re(a,"padding");t=r.width-c.width-l.width,e=r.height-c.height-l.height,n=Rn(a.maxWidth,o,"clientWidth"),i=Rn(a.maxHeight,o,"clientHeight")}}return{width:t,height:e,maxWidth:n||Ln,maxHeight:i||Ln}}function da(s,t,e,n){let i=Wn(s),o=Re(i,"margin"),r=Rn(i.maxWidth,s,"clientWidth")||Ln,a=Rn(i.maxHeight,s,"clientHeight")||Ln,l=ch(s,t,e),{width:c,height:d}=l;if(i.boxSizing==="content-box"){let u=Re(i,"border","width"),f=Re(i,"padding");c-=f.width+u.width,d-=f.height+u.height}return c=Math.max(0,c-o.width),d=Math.max(0,n?c/n:d-o.height),c=ve(Math.min(c,r,l.maxWidth)),d=ve(Math.min(d,a,l.maxHeight)),c&&!d&&(d=ve(c/2)),(t!==void 0||e!==void 0)&&n&&l.height&&d>l.height&&(d=l.height,c=ve(Math.floor(d*n))),{width:c,height:d}}function io(s,t,e){let n=t||1,i=ve(s.height*n),o=ve(s.width*n);s.height=ve(s.height),s.width=ve(s.width);let r=s.canvas;return r.style&&(e||!r.style.height&&!r.style.width)&&(r.style.height=`${s.height}px`,r.style.width=`${s.width}px`),s.currentDevicePixelRatio!==n||r.height!==i||r.width!==o?(s.currentDevicePixelRatio=n,r.height=i,r.width=o,s.ctx.setTransform(n,0,0,n,0,0),!0):!1}function oo(s,t){let e=oh(s,t),n=e&&e.match(/^(\d+)(\.\d+)?px$/);return n?+n[1]:void 0}function be(s,t,e,n){return{x:s.x+e*(t.x-s.x),y:s.y+e*(t.y-s.y)}}function ua(s,t,e,n){return{x:s.x+e*(t.x-s.x),y:n==="middle"?e<.5?s.y:t.y:n==="after"?e<1?s.y:t.y:e>0?t.y:s.y}}function fa(s,t,e,n){let i={x:s.cp2x,y:s.cp2y},o={x:t.cp1x,y:t.cp1y},r=be(s,i,e),a=be(i,o,e),l=be(o,t,e),c=be(r,a,e),d=be(a,l,e);return be(c,d,e)}function Fe(s,t,e){return s?dh(t,e):hh()}function ro(s,t){let e,n;(t==="ltr"||t==="rtl")&&(e=s.canvas.style,n=[e.getPropertyValue("direction"),e.getPropertyPriority("direction")],e.setProperty("direction",t,"important"),s.prevTextDirection=n)}function ao(s,t){t!==void 0&&(delete s.prevTextDirection,s.canvas.style.setProperty("direction",t[0],t[1]))}function ga(s){return s==="angle"?{between:hs,compare:Dd,normalize:Ct}:{between:te,compare:(t,e)=>t-e,normalize:t=>t}}function Br({start:s,end:t,count:e,loop:n,style:i}){return{start:s%e,end:t%e,loop:n&&(t-s+1)%e===0,style:i}}function uh(s,t,e){let{property:n,start:i,end:o}=e,{between:r,normalize:a}=ga(n),l=t.length,{start:c,end:d,loop:h}=s,u,f;if(h){for(c+=l,d+=l,u=0,f=l;u<f&&r(a(t[c%l][n]),i,o);++u)c--,d--;c%=l,d%=l}return d<c&&(d+=l),{start:c,end:d,loop:h,style:s.style}}function lo(s,t,e){if(!e)return[s];let{property:n,start:i,end:o}=e,r=t.length,{compare:a,between:l,normalize:c}=ga(n),{start:d,end:h,loop:u,style:f}=uh(s,t,e),g=[],p=!1,b=null,m,y,C,E=()=>l(i,C,m)&&a(i,C)!==0,S=()=>a(o,m)===0||l(o,C,m),x=()=>p||E(),v=()=>!p||S();for(let _=d,w=d;_<=h;++_)y=t[_%r],!y.skip&&(m=c(y[n]),m!==C&&(p=l(m,i,o),b===null&&x()&&(b=a(m,i)===0?_:w),b!==null&&v()&&(g.push(Br({start:b,end:_,loop:u,count:r,style:f})),b=null),w=_,C=m));return b!==null&&g.push(Br({start:b,end:h,loop:u,count:r,style:f})),g}function co(s,t){let e=[],n=s.segments;for(let i=0;i<n.length;i++){let o=lo(n[i],s.points,t);o.length&&e.push(...o)}return e}function fh(s,t,e,n){let i=0,o=t-1;if(e&&!n)for(;i<t&&!s[i].skip;)i++;for(;i<t&&s[i].skip;)i++;for(i%=t,e&&(o+=i);o>i&&s[o%t].skip;)o--;return o%=t,{start:i,end:o}}function gh(s,t,e,n){let i=s.length,o=[],r=t,a=s[t],l;for(l=t+1;l<=e;++l){let c=s[l%i];c.skip||c.stop?a.skip||(n=!1,o.push({start:t%i,end:(l-1)%i,loop:n}),t=r=c.stop?l:null):(r=l,a.skip&&(t=l)),a=c}return r!==null&&o.push({start:t%i,end:r%i,loop:n}),o}function pa(s,t){let e=s.points,n=s.options.spanGaps,i=e.length;if(!i)return[];let o=!!s._loop,{start:r,end:a}=fh(e,i,o,n);if(n===!0)return Nr(s,[{start:r,end:a,loop:o}],e,t);let l=a<r?a+i:a,c=!!s._fullLoop&&r===0&&a===i-1;return Nr(s,gh(e,r,l,c),e,t)}function Nr(s,t,e,n){return!n||!n.setContext||!e?t:ph(s,t,e,n)}function ph(s,t,e,n){let i=s._chart.getContext(),o=$r(s.options),{_datasetIndex:r,options:{spanGaps:a}}=s,l=e.length,c=[],d=o,h=t[0].start,u=h;function f(g,p,b,m){let y=a?-1:1;if(g!==p){for(g+=l;e[g%l].skip;)g-=y;for(;e[p%l].skip;)p+=y;g%l!==p%l&&(c.push({start:g%l,end:p%l,loop:b,style:m}),d=m,h=p%l)}}for(let g of t){h=a?h:g.start;let p=e[h%l],b;for(u=h+1;u<=g.end;u++){let m=e[u%l];b=$r(n.setContext(de(i,{type:"segment",p0:p,p1:m,p0DataIndex:(u-1)%l,p1DataIndex:u%l,datasetIndex:r}))),mh(b,d)&&f(h,u-1,g.loop,d),p=m,d=b}h<u-1&&f(h,u-1,g.loop,d)}return c}function $r(s){return{backgroundColor:s.backgroundColor,borderCapStyle:s.borderCapStyle,borderDash:s.borderDash,borderDashOffset:s.borderDashOffset,borderJoinStyle:s.borderJoinStyle,borderWidth:s.borderWidth,borderColor:s.borderColor}}function mh(s,t){if(!t)return!1;let e=[],n=function(i,o){return qi(o)?(e.includes(o)||e.push(o),e.indexOf(o)):o};return JSON.stringify(s,n)!==JSON.stringify(t,n)}function Dn(s,t,e){return s.options.clip?s[e]:t[e]}function bh(s,t){let{xScale:e,yScale:n}=s;return e&&n?{left:Dn(e,t,"left"),right:Dn(e,t,"right"),top:Dn(n,t,"top"),bottom:Dn(n,t,"bottom")}:t}function ho(s,t){let e=t._clip;if(e.disabled)return!1;let n=bh(t,s.chartArea);return{left:e.left===!1?0:n.left-(e.left===!0?0:e.left),right:e.right===!1?s.width:n.right+(e.right===!0?0:e.right),top:e.top===!1?0:n.top-(e.top===!0?0:e.top),bottom:e.bottom===!1?s.height:n.bottom+(e.bottom===!0?0:e.bottom)}}var zr,Hr,Vi,Ar,cs,ae,Bi,nt,ht,kd,Ln,wd,mt,Ae,Rr,le,Ut,Qt,Gr,Xr,Ui,In,_t,Jr,wn,Pr,Or,os,Td,Ld,Fr,ta,fs,ye,Vn,Ii,ut,$d,zd,Wd,jd,eo,Gd,Jd,as,la,Wn,rh,ah,ve,ha,dh,hh,ma=bi(()=>{Lr();zr=(()=>{let s=0;return()=>s++})();Hr=(s,t)=>typeof s=="string"&&s.endsWith("%")?parseFloat(s)/100:+s/t,Vi=(s,t)=>typeof s=="string"&&s.endsWith("%")?parseFloat(s)/100*t:+s;Ar={"":s=>s,x:s=>s.x,y:s=>s.y};cs=s=>typeof s!="undefined",ae=s=>typeof s=="function",Bi=(s,t)=>{if(s.size!==t.size)return!1;for(let e of s)if(!t.has(e))return!1;return!0};nt=Math.PI,ht=2*nt,kd=ht+nt,Ln=Number.POSITIVE_INFINITY,wd=nt/180,mt=nt/2,Ae=nt/4,Rr=nt*2/3,le=Math.log10,Ut=Math.sign;Qt=(s,t,e,n)=>Fn(s,e,n?i=>{let o=s[i][t];return o<e||o===e&&s[i+1][t]===e}:i=>s[i][t]<e),Gr=(s,t,e)=>Fn(s,e,n=>s[n][t]>=e);Xr=["push","pop","shift","splice","unshift"];Ui=function(){return typeof window=="undefined"?function(s){return s()}:window.requestAnimationFrame}();In=s=>s==="start"?"left":s==="end"?"right":"center",_t=(s,t,e)=>s==="start"?t:s==="end"?e:(t+e)/2,Jr=(s,t,e,n)=>s===(n?"left":"right")?e:s==="center"?(t+e)/2:t;wn=s=>s===0||s===1,Pr=(s,t,e)=>-(Math.pow(2,10*(s-=1))*Math.sin((s-t)*ht/e)),Or=(s,t,e)=>Math.pow(2,-10*s)*Math.sin((s-t)*ht/e)+1,os={linear:s=>s,easeInQuad:s=>s*s,easeOutQuad:s=>-s*(s-2),easeInOutQuad:s=>(s/=.5)<1?.5*s*s:-.5*(--s*(s-2)-1),easeInCubic:s=>s*s*s,easeOutCubic:s=>(s-=1)*s*s+1,easeInOutCubic:s=>(s/=.5)<1?.5*s*s*s:.5*((s-=2)*s*s+2),easeInQuart:s=>s*s*s*s,easeOutQuart:s=>-((s-=1)*s*s*s-1),easeInOutQuart:s=>(s/=.5)<1?.5*s*s*s*s:-.5*((s-=2)*s*s*s-2),easeInQuint:s=>s*s*s*s*s,easeOutQuint:s=>(s-=1)*s*s*s*s+1,easeInOutQuint:s=>(s/=.5)<1?.5*s*s*s*s*s:.5*((s-=2)*s*s*s*s+2),easeInSine:s=>-Math.cos(s*mt)+1,easeOutSine:s=>Math.sin(s*mt),easeInOutSine:s=>-.5*(Math.cos(nt*s)-1),easeInExpo:s=>s===0?0:Math.pow(2,10*(s-1)),easeOutExpo:s=>s===1?1:-Math.pow(2,-10*s)+1,easeInOutExpo:s=>wn(s)?s:s<.5?.5*Math.pow(2,10*(s*2-1)):.5*(-Math.pow(2,-10*(s*2-1))+2),easeInCirc:s=>s>=1?s:-(Math.sqrt(1-s*s)-1),easeOutCirc:s=>Math.sqrt(1-(s-=1)*s),easeInOutCirc:s=>(s/=.5)<1?-.5*(Math.sqrt(1-s*s)-1):.5*(Math.sqrt(1-(s-=2)*s)+1),easeInElastic:s=>wn(s)?s:Pr(s,.075,.3),easeOutElastic:s=>wn(s)?s:Or(s,.075,.3),easeInOutElastic(s){return wn(s)?s:s<.5?.5*Pr(s*2,.1125,.45):.5+.5*Or(s*2-1,.1125,.45)},easeInBack(s){return s*s*((1.70158+1)*s-1.70158)},easeOutBack(s){return(s-=1)*s*((1.70158+1)*s+1.70158)+1},easeInOutBack(s){let t=1.70158;return(s/=.5)<1?.5*(s*s*(((t*=1.525)+1)*s-t)):.5*((s-=2)*s*(((t*=1.525)+1)*s+t)+2)},easeInBounce:s=>1-os.easeOutBounce(1-s),easeOutBounce(s){return s<1/2.75?7.5625*s*s:s<2/2.75?7.5625*(s-=1.5/2.75)*s+.75:s<2.5/2.75?7.5625*(s-=2.25/2.75)*s+.9375:7.5625*(s-=2.625/2.75)*s+.984375},easeInOutBounce:s=>s<.5?os.easeInBounce(s*2)*.5:os.easeOutBounce(s*2-1)*.5+.5};Td=["x","y","borderWidth","radius","tension"],Ld=["color","borderColor","backgroundColor"];Fr=new Map;ta={values(s){return dt(s)?s:""+s},numeric(s,t,e){if(s===0)return"0";let n=this.chart.options.locale,i,o=s;if(e.length>1){let c=Math.max(Math.abs(e[0].value),Math.abs(e[e.length-1].value));(c<1e-4||c>1e15)&&(i="scientific"),o=Od(s,e)}let r=le(Math.abs(o)),a=isNaN(r)?1:Math.max(Math.min(-1*Math.floor(r),20),0),l={notation:i,minimumFractionDigits:a,maximumFractionDigits:a};return Object.assign(l,this.options.ticks.format),us(s,n,l)},logarithmic(s,t,e){if(s===0)return"0";let n=e[t].significand||s/Math.pow(10,Math.floor(le(s)));return[1,2,3,5,10,15].includes(n)||t>.8*e.length?ta.numeric.call(this,s,t,e):""}};fs={formatters:ta};ye=Object.create(null),Vn=Object.create(null);Ii=class{constructor(t,e){this.animation=void 0,this.backgroundColor="rgba(0,0,0,0.1)",this.borderColor="rgba(0,0,0,0.1)",this.color="#666",this.datasets={},this.devicePixelRatio=n=>n.chart.platform.getDevicePixelRatio(),this.elements={},this.events=["mousemove","mouseout","click","touchstart","touchmove"],this.font={family:"'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",size:12,style:"normal",lineHeight:1.2,weight:null},this.hover={},this.hoverBackgroundColor=(n,i)=>Oi(i.backgroundColor),this.hoverBorderColor=(n,i)=>Oi(i.borderColor),this.hoverColor=(n,i)=>Oi(i.color),this.indexAxis="x",this.interaction={mode:"nearest",intersect:!0,includeInvisible:!1},this.maintainAspectRatio=!0,this.onHover=null,this.onClick=null,this.parsing=!0,this.plugins={},this.responsive=!0,this.scale=void 0,this.scales={},this.showLine=!0,this.drawActiveElementsOnTop=!0,this.describe(t),this.apply(e)}set(t,e){return Fi(this,t,e)}get(t){return Hs(this,t)}describe(t,e){return Fi(Vn,t,e)}override(t,e){return Fi(ye,t,e)}route(t,e,n,i){let o=Hs(this,t),r=Hs(this,n),a="_"+e;Object.defineProperties(o,{[a]:{value:o[e],writable:!0},[e]:{enumerable:!0,get(){let l=this[a],c=r[i];return et(l)?Object.assign({},c,l):J(l,c)},set(l){this[a]=l}}})}apply(t){t.forEach(e=>e(this))}},ut=new Ii({_scriptable:s=>!s.startsWith("on"),_indexable:s=>s!=="events",hover:{_fallback:"interaction"},interaction:{_scriptable:!1,_indexable:!1}},[Ad,Rd,Fd]);$d=/^(normal|(\d+(?:\.\d+)?)(px|em|%)?)$/,zd=/^(normal|italic|initial|inherit|unset|(oblique( -?[0-9]?[0-9]deg)?))$/;Wd=s=>+s||0;jd=(s,t)=>s?s+Pn(t):t,eo=(s,t)=>et(t)&&s!=="adapters"&&(Object.getPrototypeOf(t)===null||t.constructor===Object);Gd=(s,t)=>s===!0?t:typeof s=="string"?ce(t,s):void 0;Jd=Number.EPSILON||1e-14,as=(s,t)=>t<s.length&&!s[t].skip&&s[t],la=s=>s==="x"?"y":"x";Wn=s=>s.ownerDocument.defaultView.getComputedStyle(s,null);rh=["top","right","bottom","left"];ah=(s,t,e)=>(s>0||t>0)&&(!e||!e.shadowRoot);ve=s=>Math.round(s*10)/10;ha=function(){let s=!1;try{let t={get passive(){return s=!0,!1}};zn()&&(window.addEventListener("test",null,t),window.removeEventListener("test",null,t))}catch(t){}return s}();dh=function(s,t){return{x(e){return s+s+t-e},setWidth(e){t=e},textAlign(e){return e==="center"?e:e==="right"?"left":"right"},xPlus(e,n){return e-n},leftForLtr(e,n){return e-n}}},hh=function(){return{x(s){return s},setWidth(s){},textAlign(s){return s},xPlus(s,t){return s+t},leftForLtr(s,t){return s}}}});var Xl={};Uo(Xl,{Animation:()=>Zn,Animations:()=>en,ArcElement:()=>Ee,BarController:()=>Be,BarElement:()=>je,BasePlatform:()=>sn,BasicPlatform:()=>Jn,BubbleController:()=>Ne,CategoryScale:()=>ys,Chart:()=>ne,Colors:()=>Il,DatasetController:()=>At,Decimation:()=>Bl,DomPlatform:()=>ei,DoughnutController:()=>ie,Element:()=>Pt,Filler:()=>$l,Interaction:()=>xl,Legend:()=>Hl,LineController:()=>$e,LineElement:()=>Kt,LinearScale:()=>xs,LogarithmicScale:()=>Cs,PieController:()=>bs,PointElement:()=>We,PolarAreaController:()=>we,RadarController:()=>ze,RadialLinearScale:()=>ke,Scale:()=>Te,ScatterController:()=>He,SubTitle:()=>jl,Ticks:()=>fs,TimeScale:()=>De,TimeSeriesScale:()=>_s,Title:()=>Wl,Tooltip:()=>Yl,_adapters:()=>yl,_detectPlatform:()=>kl,animator:()=>se,controllers:()=>vl,defaults:()=>ut,elements:()=>Pl,layouts:()=>Et,plugins:()=>Kl,registerables:()=>vg,registry:()=>Yt,scales:()=>ql});function yh(s,t){let e=[],n=Object.keys(t);for(let i=0;i<n.length;i++){let o=s[n[i]];o&&o.active()&&e.push(o.wait())}return Promise.all(e)}function xh(s,t){if(!t)return;let e=s.options;if(!e){s.options=t;return}return e.$shared&&(s.options=e=Object.assign({},e,{$shared:!1,$animations:{}})),e}function va(s,t){let e=s&&s.options||{},n=e.reverse,i=e.min===void 0?t:0,o=e.max===void 0?t:0;return{start:n?o:i,end:n?i:o}}function Ch(s,t,e){if(e===!1)return!1;let n=va(s,e),i=va(t,e);return{top:i.end,right:n.end,bottom:i.start,left:n.start}}function _h(s){let t,e,n,i;return et(s)?(t=s.top,e=s.right,n=s.bottom,i=s.left):t=e=n=i=s,{top:t,right:e,bottom:n,left:i,disabled:s===!1}}function ml(s,t){let e=[],n=s._getSortedDatasetMetas(t),i,o;for(i=0,o=n.length;i<o;++i)e.push(n[i].index);return e}function ya(s,t,e,n={}){let i=s.keys,o=n.mode==="single",r,a,l,c;if(t===null)return;let d=!1;for(r=0,a=i.length;r<a;++r){if(l=+i[r],l===e){if(d=!0,n.all)continue;break}c=s.values[l],gt(c)&&(o||t===0||Ut(t)===Ut(c))&&(t+=c)}return!d&&!n.all?0:t}function Sh(s,t){let{iScale:e,vScale:n}=t,i=e.axis==="x"?"x":"y",o=n.axis==="x"?"x":"y",r=Object.keys(s),a=new Array(r.length),l,c,d;for(l=0,c=r.length;l<c;++l)d=r[l],a[l]={[i]:d,[o]:s[d]};return a}function uo(s,t){let e=s&&s.options.stacked;return e||e===void 0&&t.stack!==void 0}function Eh(s,t,e){return`${s.id}.${t.id}.${e.stack||e.type}`}function kh(s){let{min:t,max:e,minDefined:n,maxDefined:i}=s.getUserBounds();return{min:n?t:Number.NEGATIVE_INFINITY,max:i?e:Number.POSITIVE_INFINITY}}function wh(s,t,e){let n=s[t]||(s[t]={});return n[e]||(n[e]={})}function xa(s,t,e,n){for(let i of t.getMatchingVisibleMetas(n).reverse()){let o=s[i.index];if(e&&o>0||!e&&o<0)return i.index}return null}function Ca(s,t){let{chart:e,_cachedMeta:n}=s,i=e._stacks||(e._stacks={}),{iScale:o,vScale:r,index:a}=n,l=o.axis,c=r.axis,d=Eh(o,r,n),h=t.length,u;for(let f=0;f<h;++f){let g=t[f],{[l]:p,[c]:b}=g,m=g._stacks||(g._stacks={});u=m[c]=wh(i,d,p),u[a]=b,u._top=xa(u,r,!0,n.type),u._bottom=xa(u,r,!1,n.type);let y=u._visualValues||(u._visualValues={});y[a]=b}}function fo(s,t){let e=s.scales;return Object.keys(e).filter(n=>e[n].axis===t).shift()}function Mh(s,t){return de(s,{active:!1,dataset:void 0,datasetIndex:t,index:t,mode:"default",type:"dataset"})}function Dh(s,t,e){return de(s,{active:!1,dataIndex:t,parsed:void 0,raw:void 0,element:e,index:t,mode:"default",type:"data"})}function Ks(s,t){let e=s.controller.index,n=s.vScale&&s.vScale.axis;if(n){t=t||s._parsed;for(let i of t){let o=i._stacks;if(!o||o[n]===void 0||o[n][e]===void 0)return;delete o[n][e],o[n]._visualValues!==void 0&&o[n]._visualValues[e]!==void 0&&delete o[n]._visualValues[e]}}}function Lh(s,t){if(!s._cache.$bar){let e=s.getMatchingVisibleMetas(t),n=[];for(let i=0,o=e.length;i<o;i++)n=n.concat(e[i].controller.getAllParsedValues(s));s._cache.$bar=ji(n.sort((i,o)=>i-o))}return s._cache.$bar}function Ah(s){let t=s.iScale,e=Lh(t,s.type),n=t._length,i,o,r,a,l=()=>{r===32767||r===-32768||(cs(a)&&(n=Math.min(n,Math.abs(r-a)||n)),a=r)};for(i=0,o=e.length;i<o;++i)r=t.getPixelForValue(e[i]),l();for(a=void 0,i=0,o=t.ticks.length;i<o;++i)r=t.getPixelForTick(i),l();return n}function Rh(s,t,e,n){let i=e.barThickness,o,r;return tt(i)?(o=t.min*e.categoryPercentage,r=e.barPercentage):(o=i*n,r=1),{chunk:o/n,ratio:r,start:t.pixels[s]-o/2}}function Ph(s,t,e,n){let i=t.pixels,o=i[s],r=s>0?i[s-1]:null,a=s<i.length-1?i[s+1]:null,l=e.categoryPercentage;r===null&&(r=o-(a===null?t.end-t.start:a-o)),a===null&&(a=o+o-r);let c=o-(o-Math.min(r,a))/2*l;return{chunk:Math.abs(a-r)/2*l/n,ratio:e.barPercentage,start:c}}function Oh(s,t,e,n){let i=e.parse(s[0],n),o=e.parse(s[1],n),r=Math.min(i,o),a=Math.max(i,o),l=r,c=a;Math.abs(r)>Math.abs(a)&&(l=a,c=r),t[e.axis]=c,t._custom={barStart:l,barEnd:c,start:i,end:o,min:r,max:a}}function bl(s,t,e,n){return dt(s)?Oh(s,t,e,n):t[e.axis]=e.parse(s,n),t}function Sa(s,t,e,n){let i=s.iScale,o=s.vScale,r=i.getLabels(),a=i===o,l=[],c,d,h,u;for(c=e,d=e+n;c<d;++c)u=t[c],h={},h[i.axis]=a||i.parse(r[c],c),l.push(bl(u,h,o,c));return l}function po(s){return s&&s.barStart!==void 0&&s.barEnd!==void 0}function Fh(s,t,e){return s!==0?Ut(s):(t.isHorizontal()?1:-1)*(t.min>=e?1:-1)}function Ih(s){let t,e,n,i,o;return s.horizontal?(t=s.base>s.x,e="left",n="right"):(t=s.base<s.y,e="bottom",n="top"),t?(i="end",o="start"):(i="start",o="end"),{start:e,end:n,reverse:t,top:i,bottom:o}}function Vh(s,t,e,n){let i=t.borderSkipped,o={};if(!i){s.borderSkipped=o;return}if(i===!0){s.borderSkipped={top:!0,right:!0,bottom:!0,left:!0};return}let{start:r,end:a,reverse:l,top:c,bottom:d}=Ih(s);i==="middle"&&e&&(s.enableBorderRadius=!0,(e._top||0)===n?i=c:(e._bottom||0)===n?i=d:(o[Ea(d,r,a,l)]=!0,i=c)),o[Ea(i,r,a,l)]=!0,s.borderSkipped=o}function Ea(s,t,e,n){return n?(s=Bh(s,t,e),s=ka(s,e,t)):s=ka(s,t,e),s}function Bh(s,t,e){return s===t?e:s===e?t:s}function ka(s,t,e){return s==="start"?t:s==="end"?e:s}function Nh(s,{inflateAmount:t},e){s.inflateAmount=t==="auto"?e===1?.33:0:t}function $h(s,t,e){let n=1,i=1,o=0,r=0;if(t<ht){let a=s,l=a+t,c=Math.cos(a),d=Math.sin(a),h=Math.cos(l),u=Math.sin(l),f=(C,E,S)=>hs(C,a,l,!0)?1:Math.max(E,E*e,S,S*e),g=(C,E,S)=>hs(C,a,l,!0)?-1:Math.min(E,E*e,S,S*e),p=f(0,c,h),b=f(mt,d,u),m=g(nt,c,h),y=g(nt+mt,d,u);n=(p-m)/2,i=(b-y)/2,o=-(p+m)/2,r=-(b+y)/2}return{ratioX:n,ratioY:i,offsetX:o,offsetY:r}}function Ie(){throw new Error("This method is not implemented: Check that a complete date adapter is provided.")}function zh(s,t,e,n){let{controller:i,data:o,_sorted:r}=s,a=i._cachedMeta.iScale,l=s.dataset&&s.dataset.options?s.dataset.options.spanGaps:null;if(a&&t===a.axis&&t!=="r"&&r&&o.length){let c=a._reversePixels?Gr:Qt;if(n){if(i._sharedOptions){let d=o[0],h=typeof d.getRange=="function"&&d.getRange(t);if(h){let u=c(o,t,e-h),f=c(o,t,e+h);return{lo:u.lo,hi:f.hi}}}}else{let d=c(o,t,e);if(l){let{vScale:h}=i._cachedMeta,{_parsed:u}=s,f=u.slice(0,d.lo+1).reverse().findIndex(p=>!tt(p[h.axis]));d.lo-=Math.max(0,f);let g=u.slice(d.hi).findIndex(p=>!tt(p[h.axis]));d.hi+=Math.max(0,g)}return d}}return{lo:0,hi:o.length-1}}function an(s,t,e,n,i){let o=s.getSortedVisibleDatasetMetas(),r=e[t];for(let a=0,l=o.length;a<l;++a){let{index:c,data:d}=o[a],{lo:h,hi:u}=zh(o[a],t,r,i);for(let f=h;f<=u;++f){let g=d[f];g.skip||n(g,c,f)}}}function Hh(s){let t=s.indexOf("x")!==-1,e=s.indexOf("y")!==-1;return function(n,i){let o=t?Math.abs(n.x-i.x):0,r=e?Math.abs(n.y-i.y):0;return Math.sqrt(Math.pow(o,2)+Math.pow(r,2))}}function mo(s,t,e,n,i){let o=[];return!i&&!s.isPointInArea(t)||an(s,e,t,function(a,l,c){!i&&!Zt(a,s.chartArea,0)||a.inRange(t.x,t.y,n)&&o.push({element:a,datasetIndex:l,index:c})},!0),o}function Wh(s,t,e,n){let i=[];function o(r,a,l){let{startAngle:c,endAngle:d}=r.getProps(["startAngle","endAngle"],n),{angle:h}=Hi(r,{x:t.x,y:t.y});hs(h,c,d)&&i.push({element:r,datasetIndex:a,index:l})}return an(s,e,t,o),i}function jh(s,t,e,n,i,o){let r=[],a=Hh(e),l=Number.POSITIVE_INFINITY;function c(d,h,u){let f=d.inRange(t.x,t.y,i);if(n&&!f)return;let g=d.getCenterPoint(i);if(!(!!o||s.isPointInArea(g))&&!f)return;let b=a(t,g);b<l?(r=[{element:d,datasetIndex:h,index:u}],l=b):b===l&&r.push({element:d,datasetIndex:h,index:u})}return an(s,e,t,c),r}function bo(s,t,e,n,i,o){return!o&&!s.isPointInArea(t)?[]:e==="r"&&!n?Wh(s,t,e,i):jh(s,t,e,n,i,o)}function wa(s,t,e,n,i){let o=[],r=e==="x"?"inXRange":"inYRange",a=!1;return an(s,e,t,(l,c,d)=>{l[r]&&l[r](t[e],i)&&(o.push({element:l,datasetIndex:c,index:d}),a=a||l.inRange(t.x,t.y,i))}),n&&!a?[]:o}function Gs(s,t){return s.filter(e=>e.pos===t)}function Ma(s,t){return s.filter(e=>Cl.indexOf(e.pos)===-1&&e.box.axis===t)}function qs(s,t){return s.sort((e,n)=>{let i=t?n:e,o=t?e:n;return i.weight===o.weight?i.index-o.index:i.weight-o.weight})}function Uh(s){let t=[],e,n,i,o,r,a;for(e=0,n=(s||[]).length;e<n;++e)i=s[e],{position:o,options:{stack:r,stackWeight:a=1}}=i,t.push({index:e,box:i,pos:o,horizontal:i.isHorizontal(),weight:i.weight,stack:r&&o+r,stackWeight:a});return t}function Yh(s){let t={};for(let e of s){let{stack:n,pos:i,stackWeight:o}=e;if(!n||!Cl.includes(i))continue;let r=t[n]||(t[n]={count:0,placed:0,weight:0,size:0});r.count++,r.weight+=o}return t}function Kh(s,t){let e=Yh(s),{vBoxMaxWidth:n,hBoxMaxHeight:i}=t,o,r,a;for(o=0,r=s.length;o<r;++o){a=s[o];let{fullSize:l}=a.box,c=e[a.stack],d=c&&a.stackWeight/c.weight;a.horizontal?(a.width=d?d*n:l&&t.availableWidth,a.height=i):(a.width=n,a.height=d?d*i:l&&t.availableHeight)}return e}function Gh(s){let t=Uh(s),e=qs(t.filter(c=>c.box.fullSize),!0),n=qs(Gs(t,"left"),!0),i=qs(Gs(t,"right")),o=qs(Gs(t,"top"),!0),r=qs(Gs(t,"bottom")),a=Ma(t,"x"),l=Ma(t,"y");return{fullSize:e,leftAndTop:n.concat(o),rightAndBottom:i.concat(l).concat(r).concat(a),chartArea:Gs(t,"chartArea"),vertical:n.concat(i).concat(l),horizontal:o.concat(r).concat(a)}}function Da(s,t,e,n){return Math.max(s[e],t[e])+Math.max(s[n],t[n])}function _l(s,t){s.top=Math.max(s.top,t.top),s.left=Math.max(s.left,t.left),s.bottom=Math.max(s.bottom,t.bottom),s.right=Math.max(s.right,t.right)}function qh(s,t,e,n){let{pos:i,box:o}=e,r=s.maxPadding;if(!et(i)){e.size&&(s[i]-=e.size);let h=n[e.stack]||{size:0,count:1};h.size=Math.max(h.size,e.horizontal?o.height:o.width),e.size=h.size/h.count,s[i]+=e.size}o.getPadding&&_l(r,o.getPadding());let a=Math.max(0,t.outerWidth-Da(r,s,"left","right")),l=Math.max(0,t.outerHeight-Da(r,s,"top","bottom")),c=a!==s.w,d=l!==s.h;return s.w=a,s.h=l,e.horizontal?{same:c,other:d}:{same:d,other:c}}function Xh(s){let t=s.maxPadding;function e(n){let i=Math.max(t[n]-s[n],0);return s[n]+=i,i}s.y+=e("top"),s.x+=e("left"),e("right"),e("bottom")}function Qh(s,t){let e=t.maxPadding;function n(i){let o={left:0,top:0,right:0,bottom:0};return i.forEach(r=>{o[r]=Math.max(t[r],e[r])}),o}return n(s?["left","right"]:["top","bottom"])}function Zs(s,t,e,n){let i=[],o,r,a,l,c,d;for(o=0,r=s.length,c=0;o<r;++o){a=s[o],l=a.box,l.update(a.width||t.w,a.height||t.h,Qh(a.horizontal,t));let{same:h,other:u}=qh(t,e,a,n);c|=h&&i.length,d=d||u,l.fullSize||i.push(a)}return c&&Zs(i,t,e,n)||d}function jn(s,t,e,n,i){s.top=e,s.left=t,s.right=t+n,s.bottom=e+i,s.width=n,s.height=i}function Ta(s,t,e,n){let i=e.padding,{x:o,y:r}=t;for(let a of s){let l=a.box,c=n[a.stack]||{count:1,placed:0,weight:1},d=a.stackWeight/c.weight||1;if(a.horizontal){let h=t.w*d,u=c.size||l.height;cs(c.start)&&(r=c.start),l.fullSize?jn(l,i.left,r,e.outerWidth-i.right-i.left,u):jn(l,t.left+c.placed,r,h,u),c.start=r,c.placed+=h,r=l.bottom}else{let h=t.h*d,u=c.size||l.width;cs(c.start)&&(o=c.start),l.fullSize?jn(l,o,i.top,u,e.outerHeight-i.bottom-i.top):jn(l,o,t.top+c.placed,u,h),c.start=o,c.placed+=h,o=l.right}}t.x=o,t.y=r}function Jh(s,t){let e=s.style,n=s.getAttribute("height"),i=s.getAttribute("width");if(s[Xn]={initial:{height:n,width:i,style:{display:e.display,height:e.height,width:e.width}}},e.display=e.display||"block",e.boxSizing=e.boxSizing||"border-box",La(i)){let o=oo(s,"width");o!==void 0&&(s.width=o)}if(La(n))if(s.style.height==="")s.height=s.width/(t||2);else{let o=oo(s,"height");o!==void 0&&(s.height=o)}return s}function tu(s,t,e){s&&s.addEventListener(t,e,Sl)}function eu(s,t,e){s&&s.canvas&&s.canvas.removeEventListener(t,e,Sl)}function su(s,t){let e=Zh[s.type]||s.type,{x:n,y:i}=Se(s,t);return{type:e,chart:t,native:s,x:n!==void 0?n:null,y:i!==void 0?i:null}}function ti(s,t){for(let e of s)if(e===t||e.contains(t))return!0}function nu(s,t,e){let n=s.canvas,i=new MutationObserver(o=>{let r=!1;for(let a of o)r=r||ti(a.addedNodes,n),r=r&&!ti(a.removedNodes,n);r&&e()});return i.observe(document,{childList:!0,subtree:!0}),i}function iu(s,t,e){let n=s.canvas,i=new MutationObserver(o=>{let r=!1;for(let a of o)r=r||ti(a.removedNodes,n),r=r&&!ti(a.addedNodes,n);r&&e()});return i.observe(document,{childList:!0,subtree:!0}),i}function El(){let s=window.devicePixelRatio;s!==Aa&&(Aa=s,nn.forEach((t,e)=>{e.currentDevicePixelRatio!==s&&t()}))}function ou(s,t){nn.size||window.addEventListener("resize",El),nn.set(s,t)}function ru(s){nn.delete(s),nn.size||window.removeEventListener("resize",El)}function au(s,t,e){let n=s.canvas,i=n&&Hn(n);if(!i)return;let o=Yi((a,l)=>{let c=i.clientWidth;e(a,l),c<i.clientWidth&&e()},window),r=new ResizeObserver(a=>{let l=a[0],c=l.contentRect.width,d=l.contentRect.height;c===0&&d===0||o(c,d)});return r.observe(i),ou(s,o),r}function vo(s,t,e){e&&e.disconnect(),t==="resize"&&ru(s)}function lu(s,t,e){let n=s.canvas,i=Yi(o=>{s.ctx!==null&&e(su(o,s))},s);return tu(n,t,i),i}function kl(s){return!zn()||typeof OffscreenCanvas!="undefined"&&s instanceof OffscreenCanvas?Jn:ei}function cu(s,t){let e=s.options.ticks,n=du(s),i=Math.min(e.maxTicksLimit||n,n),o=e.major.enabled?uu(t):[],r=o.length,a=o[0],l=o[r-1],c=[];if(r>i)return fu(t,c,o,r/i),c;let d=hu(o,t,i);if(r>0){let h,u,f=r>1?Math.round((l-a)/(r-1)):null;for(Un(t,c,d,tt(f)?0:a-f,a),h=0,u=r-1;h<u;h++)Un(t,c,d,o[h],o[h+1]);return Un(t,c,d,l,tt(f)?t.length:l+f),c}return Un(t,c,d),c}function du(s){let t=s.options.offset,e=s._tickSize(),n=s._length/e+(t?0:1),i=s._maxLength/e;return Math.floor(Math.min(n,i))}function hu(s,t,e){let n=gu(s),i=t.length/e;if(!n)return Math.max(i,1);let o=Ur(n);for(let r=0,a=o.length-1;r<a;r++){let l=o[r];if(l>i)return l}return Math.max(i,1)}function uu(s){let t=[],e,n;for(e=0,n=s.length;e<n;e++)s[e].major&&t.push(e);return t}function fu(s,t,e,n){let i=0,o=e[0],r;for(n=Math.ceil(n),r=0;r<s.length;r++)r===o&&(t.push(s[r]),i++,o=e[i*n])}function Un(s,t,e,n,i){let o=J(n,0),r=Math.min(J(i,s.length),s.length),a=0,l,c,d;for(e=Math.ceil(e),i&&(l=i-n,e=l/Math.floor(l/e)),d=o;d<0;)a++,d=Math.round(o+a*e);for(c=Math.max(o,0);c<r;c++)c===d&&(t.push(s[c]),a++,d=Math.round(o+a*e))}function gu(s){let t=s.length,e,n;if(t<2)return!1;for(n=s[0],e=1;e<t;++e)if(s[e]-s[e-1]!==n)return!1;return n}function Oa(s,t){let e=[],n=s.length/t,i=s.length,o=0;for(;o<i;o+=n)e.push(s[Math.floor(o)]);return e}function mu(s,t,e){let n=s.ticks.length,i=Math.min(t,n-1),o=s._startPixel,r=s._endPixel,a=1e-6,l=s.getPixelForTick(i),c;if(!(e&&(n===1?c=Math.max(l-o,r-l):t===0?c=(s.getPixelForTick(1)-l)/2:c=(l-s.getPixelForTick(i-1))/2,l+=i<t?c:-c,l<o-a||l>r+a)))return l}function bu(s,t){rt(s,e=>{let n=e.gc,i=n.length/2,o;if(i>t){for(o=0;o<i;++o)delete e.data[n[o]];n.splice(0,i)}})}function Xs(s){return s.drawTicks?s.tickLength:0}function Fa(s,t){if(!s.display)return 0;let e=bt(s.font,t),n=St(s.padding);return(dt(s.text)?s.text.length:1)*e.lineHeight+n.height}function vu(s,t){return de(s,{scale:t,type:"scale"})}function yu(s,t,e){return de(s,{tick:e,index:t,type:"tick"})}function xu(s,t,e){let n=In(s);return(e&&t!=="right"||!e&&t==="right")&&(n=pu(n)),n}function Cu(s,t,e,n){let{top:i,left:o,bottom:r,right:a,chart:l}=s,{chartArea:c,scales:d}=l,h=0,u,f,g,p=r-i,b=a-o;if(s.isHorizontal()){if(f=_t(n,o,a),et(e)){let m=Object.keys(e)[0],y=e[m];g=d[m].getPixelForValue(y)+p-t}else e==="center"?g=(c.bottom+c.top)/2+p-t:g=Ra(s,e,t);u=a-o}else{if(et(e)){let m=Object.keys(e)[0],y=e[m];f=d[m].getPixelForValue(y)-b+t}else e==="center"?f=(c.left+c.right)/2-b+t:f=Ra(s,e,t);g=_t(n,r,i),h=e==="left"?-mt:mt}return{titleX:f,titleY:g,maxWidth:u,rotation:h}}function _u(s,t,e){let n=rs(Object.create(null),[e?ut.get(e):{},ut.get(t),s.defaults]);ut.set(t,n),s.defaultRoutes&&Su(t,s.defaultRoutes),s.descriptors&&ut.describe(t,s.descriptors)}function Su(s,t){Object.keys(t).forEach(e=>{let n=e.split("."),i=n.pop(),o=[s].concat(n).join("."),r=t[e].split("."),a=r.pop(),l=r.join(".");ut.route(o,i,l,a)})}function Eu(s){return"id"in s&&"defaults"in s}function ku(s){let t={},e=[],n=Object.keys(Yt.plugins.items);for(let o=0;o<n.length;o++)e.push(Yt.getPlugin(n[o]));let i=s.plugins||[];for(let o=0;o<i.length;o++){let r=i[o];e.indexOf(r)===-1&&(e.push(r),t[r.id]=!0)}return{plugins:e,localIds:t}}function wu(s,t){return!t&&s===!1?null:s===!0?{}:s}function Mu(s,{plugins:t,localIds:e},n,i){let o=[],r=s.getContext();for(let a of t){let l=a.id,c=wu(n[l],i);c!==null&&o.push({plugin:a,options:Du(s.config,{plugin:a,local:e[l]},c,r)})}return o}function Du(s,{plugin:t,local:e},n,i){let o=s.pluginScopeKeys(t),r=s.getOptionScopes(n,o);return e&&t.defaults&&r.push(t.defaults),s.createResolver(r,i,[""],{scriptable:!1,indexable:!1,allKeys:!0})}function Mo(s,t){let e=ut.datasets[s]||{};return((t.datasets||{})[s]||{}).indexAxis||t.indexAxis||e.indexAxis||"x"}function Tu(s,t){let e=s;return s==="_index_"?e=t:s==="_value_"&&(e=t==="x"?"y":"x"),e}function Lu(s,t){return s===t?"_index_":"_value_"}function Ia(s){if(s==="x"||s==="y"||s==="r")return s}function Au(s){if(s==="top"||s==="bottom")return"x";if(s==="left"||s==="right")return"y"}function Do(s,...t){if(Ia(s))return s;for(let e of t){let n=e.axis||Au(e.position)||s.length>1&&Ia(s[0].toLowerCase());if(n)return n}throw new Error(`Cannot determine type of '${s}' axis. Please provide 'axis' or 'position' option.`)}function Va(s,t,e){if(e[t+"AxisID"]===s)return{axis:t}}function Ru(s,t){if(t.data&&t.data.datasets){let e=t.data.datasets.filter(n=>n.xAxisID===s||n.yAxisID===s);if(e.length)return Va(s,"x",e[0])||Va(s,"y",e[0])}return{}}function Pu(s,t){let e=ye[s.type]||{scales:{}},n=t.scales||{},i=Mo(s.type,t),o=Object.create(null);return Object.keys(n).forEach(r=>{let a=n[r];if(!et(a))return console.error(`Invalid scale configuration for scale: ${r}`);if(a._proxy)return console.warn(`Ignoring resolver passed as options for scale: ${r}`);let l=Do(r,a,Ru(r,s),ut.scales[a.type]),c=Lu(l,i),d=e.scales||{};o[r]=ls(Object.create(null),[{axis:l},a,d[l],d[c]])}),s.data.datasets.forEach(r=>{let a=r.type||s.type,l=r.indexAxis||Mo(a,t),d=(ye[a]||{}).scales||{};Object.keys(d).forEach(h=>{let u=Tu(h,l),f=r[u+"AxisID"]||u;o[f]=o[f]||Object.create(null),ls(o[f],[{axis:u},n[f],d[h]])})}),Object.keys(o).forEach(r=>{let a=o[r];ls(a,[ut.scales[a.type],ut.scale])}),o}function wl(s){let t=s.options||(s.options={});t.plugins=J(t.plugins,{}),t.scales=Pu(s,t)}function Ml(s){return s=s||{},s.datasets=s.datasets||[],s.labels=s.labels||[],s}function Ou(s){return s=s||{},s.data=Ml(s.data),wl(s),s}function Yn(s,t){let e=Ba.get(s);return e||(e=t(),Ba.set(s,e),Dl.add(e)),e}function Na(s,t,e){let n=s.get(t);n||(n=new Map,s.set(t,n));let i=e.join(),o=n.get(i);return o||(o={resolver:$n(t,e),subPrefixes:e.filter(a=>!a.toLowerCase().includes("hover"))},n.set(i,o)),o}function Iu(s,t){let{isScriptable:e,isIndexable:n}=to(s);for(let i of t){let o=e(i),r=n(i),a=(r||o)&&s[i];if(o&&(ae(a)||Fu(a))||r&&dt(a))return!0}return!1}function $a(s,t){return s==="top"||s==="bottom"||Bu.indexOf(s)===-1&&t==="x"}function za(s,t){return function(e,n){return e[s]===n[s]?e[t]-n[t]:e[s]-n[s]}}function Ha(s){let t=s.chart,e=t.options.animation;t.notifyPlugins("afterRender"),ct(e&&e.onComplete,[s],t)}function Nu(s){let t=s.chart,e=t.options.animation;ct(e&&e.onProgress,[s],t)}function Tl(s){return zn()&&typeof s=="string"?s=document.getElementById(s):s&&s.length&&(s=s[0]),s&&s.canvas&&(s=s.canvas),s}function $u(s,t,e){let n=Object.keys(s);for(let i of n){let o=+i;if(o>=t){let r=s[i];delete s[i],(e>0||o>t)&&(s[o+e]=r)}}}function zu(s,t,e,n){return!e||s.type==="mouseout"?null:n?t:s}function ja(){return rt(ne.instances,s=>s._plugins.invalidate())}function Hu(s,t,e){let{startAngle:n,x:i,y:o,outerRadius:r,innerRadius:a,options:l}=t,{borderWidth:c,borderJoinStyle:d}=l,h=Math.min(c/r,Ct(n-e));if(s.beginPath(),s.arc(i,o,r-c/2,n+h/2,e-h/2),a>0){let u=Math.min(c/a,Ct(n-e));s.arc(i,o,a+c/2,e-u/2,n+u/2,!0)}else{let u=Math.min(c/2,r*Ct(n-e));if(d==="round")s.arc(i,o,u,e-nt/2,n+nt/2,!0);else if(d==="bevel"){let f=2*u*u,g=-f*Math.cos(e+nt/2)+i,p=-f*Math.sin(e+nt/2)+o,b=f*Math.cos(n+nt/2)+i,m=f*Math.sin(n+nt/2)+o;s.lineTo(g,p),s.lineTo(b,m)}}s.closePath(),s.moveTo(0,0),s.rect(0,0,s.canvas.width,s.canvas.height),s.clip("evenodd")}function Wu(s,t,e){let{startAngle:n,pixelMargin:i,x:o,y:r,outerRadius:a,innerRadius:l}=t,c=i/a;s.beginPath(),s.arc(o,r,a,n-c,e+c),l>i?(c=i/l,s.arc(o,r,l,e+c,n-c,!0)):s.arc(o,r,i,e+mt,n-mt),s.closePath(),s.clip()}function ju(s){return Nn(s,["outerStart","outerEnd","innerStart","innerEnd"])}function Uu(s,t,e,n){let i=ju(s.options.borderRadius),o=(e-t)/2,r=Math.min(o,n*t/2),a=l=>{let c=(e-Math.min(o,l))*n/2;return vt(l,0,Math.min(o,c))};return{outerStart:a(i.outerStart),outerEnd:a(i.outerEnd),innerStart:vt(i.innerStart,0,r),innerEnd:vt(i.innerEnd,0,r)}}function ms(s,t,e,n){return{x:e+s*Math.cos(t),y:n+s*Math.sin(t)}}function si(s,t,e,n,i,o){let{x:r,y:a,startAngle:l,pixelMargin:c,innerRadius:d}=t,h=Math.max(t.outerRadius+n+e-c,0),u=d>0?d+n+e+c:0,f=0,g=i-l;if(n){let V=d>0?d-n:0,O=h>0?h-n:0,M=(V+O)/2,j=M!==0?g*M/(M+n):g;f=(g-j)/2}let p=Math.max(.001,g*h-e/nt)/h,b=(g-p)/2,m=l+b+f,y=i-b-f,{outerStart:C,outerEnd:E,innerStart:S,innerEnd:x}=Uu(t,u,h,y-m),v=h-C,_=h-E,w=m+C/v,D=y-E/_,k=u+S,T=u+x,A=m+S/k,I=y-x/T;if(s.beginPath(),o){let V=(w+D)/2;if(s.arc(r,a,h,w,V),s.arc(r,a,h,V,D),E>0){let F=ms(_,D,r,a);s.arc(F.x,F.y,E,D,y+mt)}let O=ms(T,y,r,a);if(s.lineTo(O.x,O.y),x>0){let F=ms(T,I,r,a);s.arc(F.x,F.y,x,y+mt,I+Math.PI)}let M=(y-x/u+(m+S/u))/2;if(s.arc(r,a,u,y-x/u,M,!0),s.arc(r,a,u,M,m+S/u,!0),S>0){let F=ms(k,A,r,a);s.arc(F.x,F.y,S,A+Math.PI,m-mt)}let j=ms(v,m,r,a);if(s.lineTo(j.x,j.y),C>0){let F=ms(v,w,r,a);s.arc(F.x,F.y,C,m-mt,w)}}else{s.moveTo(r,a);let V=Math.cos(w)*h+r,O=Math.sin(w)*h+a;s.lineTo(V,O);let M=Math.cos(D)*h+r,j=Math.sin(D)*h+a;s.lineTo(M,j)}s.closePath()}function Yu(s,t,e,n,i){let{fullCircles:o,startAngle:r,circumference:a}=t,l=t.endAngle;if(o){si(s,t,e,n,l,i);for(let c=0;c<o;++c)s.fill();isNaN(a)||(l=r+(a%ht||ht))}return si(s,t,e,n,l,i),s.fill(),l}function Ku(s,t,e,n,i){let{fullCircles:o,startAngle:r,circumference:a,options:l}=t,{borderWidth:c,borderJoinStyle:d,borderDash:h,borderDashOffset:u,borderRadius:f}=l,g=l.borderAlign==="inner";if(!c)return;s.setLineDash(h||[]),s.lineDashOffset=u,g?(s.lineWidth=c*2,s.lineJoin=d||"round"):(s.lineWidth=c,s.lineJoin=d||"bevel");let p=t.endAngle;if(o){si(s,t,e,n,p,i);for(let b=0;b<o;++b)s.stroke();isNaN(a)||(p=r+(a%ht||ht))}g&&Wu(s,t,p),l.selfJoin&&p-r>=nt&&f===0&&d!=="miter"&&Hu(s,t,p),o||(si(s,t,e,n,p,i),s.stroke())}function Ll(s,t,e=t){s.lineCap=J(e.borderCapStyle,t.borderCapStyle),s.setLineDash(J(e.borderDash,t.borderDash)),s.lineDashOffset=J(e.borderDashOffset,t.borderDashOffset),s.lineJoin=J(e.borderJoinStyle,t.borderJoinStyle),s.lineWidth=J(e.borderWidth,t.borderWidth),s.strokeStyle=J(e.borderColor,t.borderColor)}function Gu(s,t,e){s.lineTo(e.x,e.y)}function qu(s){return s.stepped?sa:s.tension||s.cubicInterpolationMode==="monotone"?na:Gu}function Al(s,t,e={}){let n=s.length,{start:i=0,end:o=n-1}=e,{start:r,end:a}=t,l=Math.max(i,r),c=Math.min(o,a),d=i<r&&o<r||i>a&&o>a;return{count:n,start:l,loop:t.loop,ilen:c<l&&!d?n+c-l:c-l}}function Xu(s,t,e,n){let{points:i,options:o}=t,{count:r,start:a,loop:l,ilen:c}=Al(i,e,n),d=qu(o),{move:h=!0,reverse:u}=n||{},f,g,p;for(f=0;f<=c;++f)g=i[(a+(u?c-f:f))%r],!g.skip&&(h?(s.moveTo(g.x,g.y),h=!1):d(s,p,g,u,o.stepped),p=g);return l&&(g=i[(a+(u?c:0))%r],d(s,p,g,u,o.stepped)),!!l}function Qu(s,t,e,n){let i=t.points,{count:o,start:r,ilen:a}=Al(i,e,n),{move:l=!0,reverse:c}=n||{},d=0,h=0,u,f,g,p,b,m,y=E=>(r+(c?a-E:E))%o,C=()=>{p!==b&&(s.lineTo(d,b),s.lineTo(d,p),s.lineTo(d,m))};for(l&&(f=i[y(0)],s.moveTo(f.x,f.y)),u=0;u<=a;++u){if(f=i[y(u)],f.skip)continue;let E=f.x,S=f.y,x=E|0;x===g?(S<p?p=S:S>b&&(b=S),d=(h*d+E)/++h):(C(),s.lineTo(E,S),g=x,h=0,p=b=S),m=S}C()}function Lo(s){let t=s.options,e=t.borderDash&&t.borderDash.length;return!s._decimated&&!s._loop&&!t.tension&&t.cubicInterpolationMode!=="monotone"&&!t.stepped&&!e?Qu:Xu}function Zu(s){return s.stepped?ua:s.tension||s.cubicInterpolationMode==="monotone"?fa:be}function Ju(s,t,e,n){let i=t._path;i||(i=t._path=new Path2D,t.path(i,e,n)&&i.closePath()),Ll(s,t.options),s.stroke(i)}function tf(s,t,e,n){let{segments:i,options:o}=t,r=Lo(t);for(let a of i)Ll(s,o,a.style),s.beginPath(),r(s,t,a,{start:e,end:e+n-1})&&s.closePath(),s.stroke()}function sf(s,t,e,n){ef&&!t.options.segment?Ju(s,t,e,n):tf(s,t,e,n)}function Ua(s,t,e,n){let i=s.options,{[e]:o}=s.getProps([e],n);return Math.abs(t-o)<i.radius+i.hitRadius}function Rl(s,t){let{x:e,y:n,base:i,width:o,height:r}=s.getProps(["x","y","base","width","height"],t),a,l,c,d,h;return s.horizontal?(h=r/2,a=Math.min(e,i),l=Math.max(e,i),c=n-h,d=n+h):(h=o/2,a=e-h,l=e+h,c=Math.min(n,i),d=Math.max(n,i)),{left:a,top:c,right:l,bottom:d}}function Me(s,t,e,n){return s?0:vt(t,e,n)}function nf(s,t,e){let n=s.options.borderWidth,i=s.borderSkipped,o=Ji(n);return{t:Me(i.top,o.top,0,e),r:Me(i.right,o.right,0,t),b:Me(i.bottom,o.bottom,0,e),l:Me(i.left,o.left,0,t)}}function of(s,t,e){let{enableBorderRadius:n}=s.getProps(["enableBorderRadius"]),i=s.options.borderRadius,o=_e(i),r=Math.min(t,e),a=s.borderSkipped,l=n||et(i);return{topLeft:Me(!l||a.top||a.left,o.topLeft,0,r),topRight:Me(!l||a.top||a.right,o.topRight,0,r),bottomLeft:Me(!l||a.bottom||a.left,o.bottomLeft,0,r),bottomRight:Me(!l||a.bottom||a.right,o.bottomRight,0,r)}}function rf(s){let t=Rl(s),e=t.right-t.left,n=t.bottom-t.top,i=nf(s,e/2,n/2),o=of(s,e/2,n/2);return{outer:{x:t.left,y:t.top,w:e,h:n,radius:o},inner:{x:t.left+i.l,y:t.top+i.t,w:e-i.l-i.r,h:n-i.t-i.b,radius:{topLeft:Math.max(0,o.topLeft-Math.max(i.t,i.l)),topRight:Math.max(0,o.topRight-Math.max(i.t,i.r)),bottomLeft:Math.max(0,o.bottomLeft-Math.max(i.b,i.l)),bottomRight:Math.max(0,o.bottomRight-Math.max(i.b,i.r))}}}}function yo(s,t,e,n){let i=t===null,o=e===null,a=s&&!(i&&o)&&Rl(s,n);return a&&(i||te(t,a.left,a.right))&&(o||te(e,a.top,a.bottom))}function af(s){return s.topLeft||s.topRight||s.bottomLeft||s.bottomRight}function lf(s,t){s.rect(t.x,t.y,t.w,t.h)}function xo(s,t,e={}){let n=s.x!==e.x?-t:0,i=s.y!==e.y?-t:0,o=(s.x+s.w!==e.x+e.w?t:0)-n,r=(s.y+s.h!==e.y+e.h?t:0)-i;return{x:s.x+n,y:s.y+i,w:s.w+o,h:s.h+r,radius:s.radius}}function Ol(s){return Ao[s%Ao.length]}function Fl(s){return Ya[s%Ya.length]}function cf(s,t){return s.borderColor=Ol(t),s.backgroundColor=Fl(t),++t}function df(s,t){return s.backgroundColor=s.data.map(()=>Ol(t++)),t}function hf(s,t){return s.backgroundColor=s.data.map(()=>Fl(t++)),t}function uf(s){let t=0;return(e,n)=>{let i=s.getDatasetMeta(n).controller;i instanceof ie?t=df(e,t):i instanceof we?t=hf(e,t):i&&(t=cf(e,t))}}function Ka(s){let t;for(t in s)if(s[t].borderColor||s[t].backgroundColor)return!0;return!1}function ff(s){return s&&(s.borderColor||s.backgroundColor)}function gf(){return ut.borderColor!=="rgba(0,0,0,0.1)"||ut.backgroundColor!=="rgba(0,0,0,0.1)"}function pf(s,t,e,n,i){let o=i.samples||n;if(o>=e)return s.slice(t,t+e);let r=[],a=(e-2)/(o-2),l=0,c=t+e-1,d=t,h,u,f,g,p;for(r[l++]=s[d],h=0;h<o-2;h++){let b=0,m=0,y,C=Math.floor((h+1)*a)+1+t,E=Math.min(Math.floor((h+2)*a)+1,e)+t,S=E-C;for(y=C;y<E;y++)b+=s[y].x,m+=s[y].y;b/=S,m/=S;let x=Math.floor(h*a)+1+t,v=Math.min(Math.floor((h+1)*a)+1,e)+t,{x:_,y:w}=s[d];for(f=g=-1,y=x;y<v;y++)g=.5*Math.abs((_-b)*(s[y].y-w)-(_-s[y].x)*(m-w)),g>f&&(f=g,u=s[y],p=y);r[l++]=u,d=p}return r[l++]=s[c],r}function mf(s,t,e,n){let i=0,o=0,r,a,l,c,d,h,u,f,g,p,b=[],m=t+e-1,y=s[t].x,E=s[m].x-y;for(r=t;r<t+e;++r){a=s[r],l=(a.x-y)/E*n,c=a.y;let S=l|0;if(S===d)c<g?(g=c,h=r):c>p&&(p=c,u=r),i=(o*i+a.x)/++o;else{let x=r-1;if(!tt(h)&&!tt(u)){let v=Math.min(h,u),_=Math.max(h,u);v!==f&&v!==x&&b.push({...s[v],x:i}),_!==f&&_!==x&&b.push({...s[_],x:i})}r>0&&x!==f&&b.push(s[x]),b.push(a),d=S,o=0,g=p=c,h=u=f=r}}return b}function Vl(s){if(s._decimated){let t=s._data;delete s._decimated,delete s._data,Object.defineProperty(s,"data",{configurable:!0,enumerable:!0,writable:!0,value:t})}}function Ga(s){s.data.datasets.forEach(t=>{Vl(t)})}function bf(s,t){let e=t.length,n=0,i,{iScale:o}=s,{min:r,max:a,minDefined:l,maxDefined:c}=o.getUserBounds();return l&&(n=vt(Qt(t,o.axis,r).lo,0,e-1)),c?i=vt(Qt(t,o.axis,a).hi+1,n,e)-n:i=e-n,{start:n,count:i}}function vf(s,t,e){let n=s.segments,i=s.points,o=t.points,r=[];for(let a of n){let{start:l,end:c}=a;c=oi(l,c,i);let d=Ro(e,i[l],i[c],a.loop);if(!t.segments){r.push({source:a,target:d,start:i[l],end:i[c]});continue}let h=co(t,d);for(let u of h){let f=Ro(e,o[u.start],o[u.end],u.loop),g=lo(a,i,f);for(let p of g)r.push({source:p,target:u,start:{[e]:qa(d,f,"start",Math.max)},end:{[e]:qa(d,f,"end",Math.min)}})}}return r}function Ro(s,t,e,n){if(n)return;let i=t[s],o=e[s];return s==="angle"&&(i=Ct(i),o=Ct(o)),{property:s,start:i,end:o}}function yf(s,t){let{x:e=null,y:n=null}=s||{},i=t.points,o=[];return t.segments.forEach(({start:r,end:a})=>{a=oi(r,a,i);let l=i[r],c=i[a];n!==null?(o.push({x:l.x,y:n}),o.push({x:c.x,y:n})):e!==null&&(o.push({x:e,y:l.y}),o.push({x:e,y:c.y}))}),o}function oi(s,t,e){for(;t>s;t--){let n=e[t];if(!isNaN(n.x)&&!isNaN(n.y))break}return t}function qa(s,t,e,n){return s&&t?n(s[e],t[e]):s?s[e]:t?t[e]:0}function Nl(s,t){let e=[],n=!1;return dt(s)?(n=!0,e=s):e=yf(s,t),e.length?new Kt({points:e,options:{tension:0},_loop:n,_fullLoop:n}):null}function Xa(s){return s&&s.fill!==!1}function xf(s,t,e){let i=s[t].fill,o=[t],r;if(!e)return i;for(;i!==!1&&o.indexOf(i)===-1;){if(!gt(i))return i;if(r=s[i],!r)return!1;if(r.visible)return i;o.push(i),i=r.fill}return!1}function Cf(s,t,e){let n=kf(s);if(et(n))return isNaN(n.value)?!1:n;let i=parseFloat(n);return gt(i)&&Math.floor(i)===i?_f(n[0],t,i,e):["origin","start","end","stack","shape"].indexOf(n)>=0&&n}function _f(s,t,e,n){return(s==="-"||s==="+")&&(e=t+e),e===t||e<0||e>=n?!1:e}function Sf(s,t){let e=null;return s==="start"?e=t.bottom:s==="end"?e=t.top:et(s)?e=t.getPixelForValue(s.value):t.getBasePixel&&(e=t.getBasePixel()),e}function Ef(s,t,e){let n;return s==="start"?n=e:s==="end"?n=t.options.reverse?t.min:t.max:et(s)?n=s.value:n=t.getBaseValue(),n}function kf(s){let t=s.options,e=t.fill,n=J(e&&e.target,e);return n===void 0&&(n=!!t.backgroundColor),n===!1||n===null?!1:n===!0?"origin":n}function wf(s){let{scale:t,index:e,line:n}=s,i=[],o=n.segments,r=n.points,a=Mf(t,e);a.push(Nl({x:null,y:t.bottom},n));for(let l=0;l<o.length;l++){let c=o[l];for(let d=c.start;d<=c.end;d++)Df(i,r[d],a)}return new Kt({points:i,options:{}})}function Mf(s,t){let e=[],n=s.getMatchingVisibleMetas("line");for(let i=0;i<n.length;i++){let o=n[i];if(o.index===t)break;o.hidden||e.unshift(o.dataset)}return e}function Df(s,t,e){let n=[];for(let i=0;i<e.length;i++){let o=e[i],{first:r,last:a,point:l}=Tf(o,t,"x");if(!(!l||r&&a)){if(r)n.unshift(l);else if(s.push(l),!a)break}}s.push(...n)}function Tf(s,t,e){let n=s.interpolate(t,e);if(!n)return{};let i=n[e],o=s.segments,r=s.points,a=!1,l=!1;for(let c=0;c<o.length;c++){let d=o[c],h=r[d.start][e],u=r[d.end][e];if(te(i,h,u)){a=i===h,l=i===u;break}}return{first:a,last:l,point:n}}function Lf(s){let{chart:t,fill:e,line:n}=s;if(gt(e))return Af(t,e);if(e==="stack")return wf(s);if(e==="shape")return!0;let i=Rf(s);return i instanceof ni?i:Nl(i,n)}function Af(s,t){let e=s.getDatasetMeta(t);return e&&s.isDatasetVisible(t)?e.dataset:null}function Rf(s){return(s.scale||{}).getPointPositionForValue?Of(s):Pf(s)}function Pf(s){let{scale:t={},fill:e}=s,n=Sf(e,t);if(gt(n)){let i=t.isHorizontal();return{x:i?n:null,y:i?null:n}}return null}function Of(s){let{scale:t,fill:e}=s,n=t.options,i=t.getLabels().length,o=n.reverse?t.max:t.min,r=Ef(e,t,o),a=[];if(n.grid.circular){let l=t.getPointPositionForValue(0,o);return new ni({x:l.x,y:l.y,radius:t.getDistanceFromCenterForValue(r)})}for(let l=0;l<i;++l)a.push(t.getPointPositionForValue(l,r));return a}function Co(s,t,e){let n=Lf(t),{chart:i,index:o,line:r,scale:a,axis:l}=t,c=r.options,d=c.fill,h=c.backgroundColor,{above:u=h,below:f=h}=d||{},g=i.getDatasetMeta(o),p=ho(i,g);n&&r.points.length&&(Us(s,e),Ff(s,{line:r,target:n,above:u,below:f,area:e,scale:a,axis:l,clip:p}),Ys(s))}function Ff(s,t){let{line:e,target:n,above:i,below:o,area:r,scale:a,clip:l}=t,c=e._loop?"angle":t.axis;s.save();let d=o;o!==i&&(c==="x"?(Qa(s,n,r.top),_o(s,{line:e,target:n,color:i,scale:a,property:c,clip:l}),s.restore(),s.save(),Qa(s,n,r.bottom)):c==="y"&&(Za(s,n,r.left),_o(s,{line:e,target:n,color:o,scale:a,property:c,clip:l}),s.restore(),s.save(),Za(s,n,r.right),d=i)),_o(s,{line:e,target:n,color:d,scale:a,property:c,clip:l}),s.restore()}function Qa(s,t,e){let{segments:n,points:i}=t,o=!0,r=!1;s.beginPath();for(let a of n){let{start:l,end:c}=a,d=i[l],h=i[oi(l,c,i)];o?(s.moveTo(d.x,d.y),o=!1):(s.lineTo(d.x,e),s.lineTo(d.x,d.y)),r=!!t.pathSegment(s,a,{move:r}),r?s.closePath():s.lineTo(h.x,e)}s.lineTo(t.first().x,e),s.closePath(),s.clip()}function Za(s,t,e){let{segments:n,points:i}=t,o=!0,r=!1;s.beginPath();for(let a of n){let{start:l,end:c}=a,d=i[l],h=i[oi(l,c,i)];o?(s.moveTo(d.x,d.y),o=!1):(s.lineTo(e,d.y),s.lineTo(d.x,d.y)),r=!!t.pathSegment(s,a,{move:r}),r?s.closePath():s.lineTo(e,h.y)}s.lineTo(e,t.first().y),s.closePath(),s.clip()}function _o(s,t){let{line:e,target:n,property:i,color:o,scale:r,clip:a}=t,l=vf(e,n,i);for(let{source:c,target:d,start:h,end:u}of l){let{style:{backgroundColor:f=o}={}}=c,g=n!==!0;s.save(),s.fillStyle=f,If(s,r,a,g&&Ro(i,h,u)),s.beginPath();let p=!!e.pathSegment(s,c),b;if(g){p?s.closePath():Ja(s,n,u,i);let m=!!n.pathSegment(s,d,{move:p,reverse:!0});b=p&&m,b||Ja(s,n,h,i)}s.closePath(),s.fill(b?"evenodd":"nonzero"),s.restore()}}function If(s,t,e,n){let i=t.chart.chartArea,{property:o,start:r,end:a}=n||{};if(o==="x"||o==="y"){let l,c,d,h;o==="x"?(l=r,c=i.top,d=a,h=i.bottom):(l=i.left,c=r,d=i.right,h=a),s.beginPath(),e&&(l=Math.max(l,e.left),d=Math.min(d,e.right),c=Math.max(c,e.top),h=Math.min(h,e.bottom)),s.rect(l,c,d-l,h-c),s.clip()}}function Ja(s,t,e,n){let i=t.interpolate(e,n);i&&s.lineTo(i.x,i.y)}function Bf(s,t,e,n,i){let o=Nf(n,s,t,e),r=$f(i,n,t.lineHeight);return{itemWidth:o,itemHeight:r}}function Nf(s,t,e,n){let i=s.text;return i&&typeof i!="string"&&(i=i.reduce((o,r)=>o.length>r.length?o:r)),t+e.size/2+n.measureText(i).width}function $f(s,t,e){let n=s;return typeof t.text!="string"&&(n=zl(t,e)),n}function zl(s,t){let e=s.text?s.text.length:0;return t*e}function zf(s,t){return!!((s==="mousemove"||s==="mouseout")&&(t.onHover||t.onLeave)||t.onClick&&(s==="click"||s==="mouseup"))}function Hf(s,t){let e=new on({ctx:s.ctx,options:t,chart:s});Et.configure(s,e,t),Et.addBox(s,e),s.titleBlock=e}function ee(s,t){return t&&(dt(t)?Array.prototype.push.apply(s,t):s.push(t)),s}function he(s){return(typeof s=="string"||s instanceof String)&&s.indexOf(`
`)>-1?s.split(`
`):s}function Wf(s,t){let{element:e,datasetIndex:n,index:i}=t,o=s.getDatasetMeta(n).controller,{label:r,value:a}=o.getLabelAndValue(i);return{chart:s,label:r,parsed:o.getParsed(i),raw:s.data.datasets[n].data[i],formattedValue:a,dataset:o.getDataset(),dataIndex:i,datasetIndex:n,element:e}}function el(s,t){let e=s.chart.ctx,{body:n,footer:i,title:o}=s,{boxWidth:r,boxHeight:a}=t,l=bt(t.bodyFont),c=bt(t.titleFont),d=bt(t.footerFont),h=o.length,u=i.length,f=n.length,g=St(t.padding),p=g.height,b=0,m=n.reduce((E,S)=>E+S.before.length+S.lines.length+S.after.length,0);if(m+=s.beforeBody.length+s.afterBody.length,h&&(p+=h*c.lineHeight+(h-1)*t.titleSpacing+t.titleMarginBottom),m){let E=t.displayColors?Math.max(a,l.lineHeight):l.lineHeight;p+=f*E+(m-f)*l.lineHeight+(m-1)*t.bodySpacing}u&&(p+=t.footerMarginTop+u*d.lineHeight+(u-1)*t.footerSpacing);let y=0,C=function(E){b=Math.max(b,e.measureText(E).width+y)};return e.save(),e.font=c.string,rt(s.title,C),e.font=l.string,rt(s.beforeBody.concat(s.afterBody),C),y=t.displayColors?r+2+t.boxPadding:0,rt(n,E=>{rt(E.before,C),rt(E.lines,C),rt(E.after,C)}),y=0,e.font=d.string,rt(s.footer,C),e.restore(),b+=g.width,{width:b,height:p}}function jf(s,t){let{y:e,height:n}=t;return e<n/2?"top":e>s.height-n/2?"bottom":"center"}function Uf(s,t,e,n){let{x:i,width:o}=n,r=e.caretSize+e.caretPadding;if(s==="left"&&i+o+r>t.width||s==="right"&&i-o-r<0)return!0}function Yf(s,t,e,n){let{x:i,width:o}=e,{width:r,chartArea:{left:a,right:l}}=s,c="center";return n==="center"?c=i<=(a+l)/2?"left":"right":i<=o/2?c="left":i>=r-o/2&&(c="right"),Uf(c,s,t,e)&&(c="center"),c}function sl(s,t,e){let n=e.yAlign||t.yAlign||jf(s,e);return{xAlign:e.xAlign||t.xAlign||Yf(s,t,e,n),yAlign:n}}function Kf(s,t){let{x:e,width:n}=s;return t==="right"?e-=n:t==="center"&&(e-=n/2),e}function Gf(s,t,e){let{y:n,height:i}=s;return t==="top"?n+=e:t==="bottom"?n-=i+e:n-=i/2,n}function nl(s,t,e,n){let{caretSize:i,caretPadding:o,cornerRadius:r}=s,{xAlign:a,yAlign:l}=e,c=i+o,{topLeft:d,topRight:h,bottomLeft:u,bottomRight:f}=_e(r),g=Kf(t,a),p=Gf(t,l,c);return l==="center"?a==="left"?g+=c:a==="right"&&(g-=c):a==="left"?g-=Math.max(d,u)+i:a==="right"&&(g+=Math.max(h,f)+i),{x:vt(g,0,n.width-t.width),y:vt(p,0,n.height-t.height)}}function Gn(s,t,e){let n=St(e.padding);return t==="center"?s.x+s.width/2:t==="right"?s.x+s.width-n.right:s.x+n.left}function il(s){return ee([],he(s))}function qf(s,t,e){return de(s,{tooltip:t,tooltipItems:e,type:"tooltip"})}function ol(s,t){let e=t&&t.dataset&&t.dataset.tooltip&&t.dataset.tooltip.callbacks;return e?s.override(e):s}function Lt(s,t,e,n){let i=s[t].call(e,n);return typeof i=="undefined"?Ul[t].call(e,n):i}function Qf(s,t,e,n){let i=s.indexOf(t);if(i===-1)return Xf(s,t,e,n);let o=s.lastIndexOf(t);return i!==o?e:i}function rl(s){let t=this.getLabels();return s>=0&&s<t.length?t[s]:s}function Jf(s,t){let e=[],{bounds:i,step:o,min:r,max:a,precision:l,count:c,maxTicks:d,maxDigits:h,includeBounds:u}=s,f=o||1,g=d-1,{min:p,max:b}=t,m=!tt(r),y=!tt(a),C=!tt(c),E=(b-p)/(h+1),S=Ni((b-p)/g/f)*f,x,v,_,w;if(S<1e-14&&!m&&!y)return[{value:p},{value:b}];w=Math.ceil(b/S)-Math.floor(p/S),w>g&&(S=Ni(w*S/g/f)*f),tt(l)||(x=Math.pow(10,l),S=Math.ceil(S*x)/x),i==="ticks"?(v=Math.floor(p/S)*S,_=Math.ceil(b/S)*S):(v=p,_=b),m&&y&&o&&Yr((a-r)/o,S/1e3)?(w=Math.round(Math.min((a-r)/S,d)),S=(a-r)/w,v=r,_=a):C?(v=m?r:v,_=y?a:_,w=c-1,S=(_-v)/w):(w=(_-v)/S,ds(w,Math.round(w),S/1e3)?w=Math.round(w):w=Math.ceil(w));let D=Math.max(zi(S),zi(v));x=Math.pow(10,tt(l)?D:l),v=Math.round(v*x)/x,_=Math.round(_*x)/x;let k=0;for(m&&(u&&v!==r?(e.push({value:r}),v<r&&k++,ds(Math.round((v+k*S)*x)/x,r,al(r,E,s))&&k++):v<r&&k++);k<w;++k){let T=Math.round((v+k*S)*x)/x;if(y&&T>a)break;e.push({value:T})}return y&&u&&_!==a?e.length&&ds(e[e.length-1].value,a,al(a,E,s))?e[e.length-1].value=a:e.push({value:a}):(!y||_===a)&&e.push({value:_}),e}function al(s,t,{horizontal:e,minRotation:n}){let i=Ht(n),o=(e?Math.sin(i):Math.cos(i))||.001,r=.75*t*(""+s).length;return Math.min(t/o,r)}function ll(s){return s/Math.pow(10,rn(s))===1}function cl(s,t,e){let n=Math.pow(10,e),i=Math.floor(s/n);return Math.ceil(t/n)-i}function tg(s,t){let e=t-s,n=rn(e);for(;cl(s,t,n)>10;)n++;for(;cl(s,t,n)<10;)n--;return Math.min(n,rn(s))}function eg(s,{min:t,max:e}){t=Tt(s.min,t);let n=[],i=rn(t),o=tg(t,e),r=o<0?Math.pow(10,Math.abs(o)):1,a=Math.pow(10,o),l=i>o?Math.pow(10,i):0,c=Math.round((t-l)*r)/r,d=Math.floor((t-l)/a/10)*a*10,h=Math.floor((c-d)/Math.pow(10,o)),u=Tt(s.min,Math.round((l+d+h*Math.pow(10,o))*r)/r);for(;u<e;)n.push({value:u,major:ll(u),significand:h}),h>=10?h=h<15?15:20:h++,h>=20&&(o++,h=2,r=o>=0?1:r),u=Math.round((l+d+h*Math.pow(10,o))*r)/r;let f=Tt(s.max,u);return n.push({value:f,major:ll(f),significand:h}),n}function Po(s){let t=s.ticks;if(t.display&&s.display){let e=St(t.backdropPadding);return J(t.font&&t.font.size,ut.font.size)+e.height}return 0}function sg(s,t,e){return e=dt(e)?e:[e],{w:ea(s,t.string,e),h:e.length*t.lineHeight}}function dl(s,t,e,n,i){return s===n||s===i?{start:t-e/2,end:t+e/2}:s<n||s>i?{start:t-e,end:t}:{start:t,end:t+e}}function ng(s){let t={l:s.left+s._padding.left,r:s.right-s._padding.right,t:s.top+s._padding.top,b:s.bottom-s._padding.bottom},e=Object.assign({},t),n=[],i=[],o=s._pointLabels.length,r=s.options.pointLabels,a=r.centerPointLabels?nt/o:0;for(let l=0;l<o;l++){let c=r.setContext(s.getPointLabelContext(l));i[l]=c.padding;let d=s.getPointPosition(l,s.drawingArea+i[l],a),h=bt(c.font),u=sg(s.ctx,h,s._pointLabels[l]);n[l]=u;let f=Ct(s.getIndexAngle(l)+a),g=Math.round(On(f)),p=dl(g,d.x,u.w,0,180),b=dl(g,d.y,u.h,90,270);ig(e,t,f,p,b)}s.setCenterPoint(t.l-e.l,e.r-t.r,t.t-e.t,e.b-t.b),s._pointLabelItems=ag(s,n,i)}function ig(s,t,e,n,i){let o=Math.abs(Math.sin(e)),r=Math.abs(Math.cos(e)),a=0,l=0;n.start<t.l?(a=(t.l-n.start)/o,s.l=Math.min(s.l,t.l-a)):n.end>t.r&&(a=(n.end-t.r)/o,s.r=Math.max(s.r,t.r+a)),i.start<t.t?(l=(t.t-i.start)/r,s.t=Math.min(s.t,t.t-l)):i.end>t.b&&(l=(i.end-t.b)/r,s.b=Math.max(s.b,t.b+l))}function og(s,t,e){let n=s.drawingArea,{extra:i,additionalAngle:o,padding:r,size:a}=e,l=s.getPointPosition(t,n+i+r,o),c=Math.round(On(Ct(l.angle+mt))),d=dg(l.y,a.h,c),h=lg(c),u=cg(l.x,a.w,h);return{visible:!0,x:l.x,y:d,textAlign:h,left:u,top:d,right:u+a.w,bottom:d+a.h}}function rg(s,t){if(!t)return!0;let{left:e,top:n,right:i,bottom:o}=s;return!(Zt({x:e,y:n},t)||Zt({x:e,y:o},t)||Zt({x:i,y:n},t)||Zt({x:i,y:o},t))}function ag(s,t,e){let n=[],i=s._pointLabels.length,o=s.options,{centerPointLabels:r,display:a}=o.pointLabels,l={extra:Po(o)/2,additionalAngle:r?nt/i:0},c;for(let d=0;d<i;d++){l.padding=e[d],l.size=t[d];let h=og(s,d,l);n.push(h),a==="auto"&&(h.visible=rg(h,c),h.visible&&(c=h))}return n}function lg(s){return s===0||s===180?"center":s<180?"left":"right"}function cg(s,t,e){return e==="right"?s-=t:e==="center"&&(s-=t/2),s}function dg(s,t,e){return e===90||e===270?s-=t/2:(e>270||e<90)&&(s-=t),s}function hg(s,t,e){let{left:n,top:i,right:o,bottom:r}=e,{backdropColor:a}=t;if(!tt(a)){let l=_e(t.borderRadius),c=St(t.backdropPadding);s.fillStyle=a;let d=n-c.left,h=i-c.top,u=o-n+c.width,f=r-i+c.height;Object.values(l).some(g=>g!==0)?(s.beginPath(),gs(s,{x:d,y:h,w:u,h:f,radius:l}),s.fill()):s.fillRect(d,h,u,f)}}function ug(s,t){let{ctx:e,options:{pointLabels:n}}=s;for(let i=t-1;i>=0;i--){let o=s._pointLabelItems[i];if(!o.visible)continue;let r=n.setContext(s.getPointLabelContext(i));hg(e,r,o);let a=bt(r.font),{x:l,y:c,textAlign:d}=o;Ce(e,s._pointLabels[i],l,c+a.lineHeight/2,a,{color:r.color,textAlign:d,textBaseline:"middle"})}}function Gl(s,t,e,n){let{ctx:i}=s;if(e)i.arc(s.xCenter,s.yCenter,t,0,ht);else{let o=s.getPointPosition(0,t);i.moveTo(o.x,o.y);for(let r=1;r<n;r++)o=s.getPointPosition(r,t),i.lineTo(o.x,o.y)}}function fg(s,t,e,n,i){let o=s.ctx,r=t.circular,{color:a,lineWidth:l}=t;!r&&!n||!a||!l||e<0||(o.save(),o.strokeStyle=a,o.lineWidth=l,o.setLineDash(i.dash||[]),o.lineDashOffset=i.dashOffset,o.beginPath(),Gl(s,e,r,n),o.closePath(),o.stroke(),o.restore())}function gg(s,t,e){return de(s,{label:e,index:t,type:"pointLabel"})}function hl(s,t){return s-t}function ul(s,t){if(tt(t))return null;let e=s._adapter,{parser:n,round:i,isoWeekday:o}=s._parseOpts,r=t;return typeof n=="function"&&(r=n(r)),gt(r)||(r=typeof n=="string"?e.parse(r,n):e.parse(r)),r===null?null:(i&&(r=i==="week"&&(Oe(o)||o===!0)?e.startOf(r,"isoWeek",o):e.startOf(r,i)),+r)}function fl(s,t,e,n){let i=Rt.length;for(let o=Rt.indexOf(s);o<i-1;++o){let r=ri[Rt[o]],a=r.steps?r.steps:Number.MAX_SAFE_INTEGER;if(r.common&&Math.ceil((e-t)/(a*r.size))<=n)return Rt[o]}return Rt[i-1]}function pg(s,t,e,n,i){for(let o=Rt.length-1;o>=Rt.indexOf(e);o--){let r=Rt[o];if(ri[r].common&&s._adapter.diff(i,n,r)>=t-1)return r}return Rt[e?Rt.indexOf(e):0]}function mg(s){for(let t=Rt.indexOf(s)+1,e=Rt.length;t<e;++t)if(ri[Rt[t]].common)return Rt[t]}function gl(s,t,e){if(!e)s[t]=!0;else if(e.length){let{lo:n,hi:i}=Fn(e,t),o=e[n]>=t?e[n]:e[i];s[o]=!0}}function bg(s,t,e,n){let i=s._adapter,o=+i.startOf(t[0].value,n),r=t[t.length-1].value,a,l;for(a=o;a<=r;a=+i.add(a,1,n))l=e[a],l>=0&&(t[l].major=!0);return t}function pl(s,t,e){let n=[],i={},o=t.length,r,a;for(r=0;r<o;++r)a=t[r],i[a]=r,n.push({value:a,major:!1});return o===0||!e?n:bg(s,n,i,e)}function qn(s,t,e){let n=0,i=s.length-1,o,r,a,l;e?(t>=s[n].pos&&t<=s[i].pos&&({lo:n,hi:i}=Qt(s,"pos",t)),{pos:o,time:a}=s[n],{pos:r,time:l}=s[i]):(t>=s[n].time&&t<=s[i].time&&({lo:n,hi:i}=Qt(s,"time",t)),{time:o,pos:a}=s[n],{time:r,pos:l}=s[i]);let c=r-o;return c?a+(l-a)*(t-o)/c:a}var So,se,ba,vh,Zn,en,go,_a,Th,At,Be,Ne,ie,$e,we,bs,ze,He,vl,Eo,yl,xl,Cl,Et,sn,Jn,Xn,Zh,La,Sl,nn,Aa,ei,Pt,pu,Ra,Pa,Te,vs,ko,Yt,wo,Ba,Dl,Qs,To,Fu,Vu,Bu,Qn,Wa,ne,Ee,ef,Kt,We,je,Pl,Ao,Ya,Il,Bl,ni,$l,tl,Vf,ii,Hl,on,Wl,Kn,jl,Js,Ul,tn,Yl,Kl,Xf,Zf,ys,Ss,xs,rn,Ve,Cs,ke,ri,Rt,De,_s,ql,vg,Ql=bi(()=>{ma();So=class{constructor(){this._request=null,this._charts=new Map,this._running=!1,this._lastDate=void 0}_notify(t,e,n,i){let o=e.listeners[i],r=e.duration;o.forEach(a=>a({chart:t,initial:e.initial,numSteps:r,currentStep:Math.min(n-e.start,r)}))}_refresh(){this._request||(this._running=!0,this._request=Ui.call(window,()=>{this._update(),this._request=null,this._running&&this._refresh()}))}_update(t=Date.now()){let e=0;this._charts.forEach((n,i)=>{if(!n.running||!n.items.length)return;let o=n.items,r=o.length-1,a=!1,l;for(;r>=0;--r)l=o[r],l._active?(l._total>n.duration&&(n.duration=l._total),l.tick(t),a=!0):(o[r]=o[o.length-1],o.pop());a&&(i.draw(),this._notify(i,n,t,"progress")),o.length||(n.running=!1,this._notify(i,n,t,"complete"),n.initial=!1),e+=o.length}),this._lastDate=t,e===0&&(this._running=!1)}_getAnims(t){let e=this._charts,n=e.get(t);return n||(n={running:!1,initial:!0,items:[],listeners:{complete:[],progress:[]}},e.set(t,n)),n}listen(t,e,n){this._getAnims(t).listeners[e].push(n)}add(t,e){!e||!e.length||this._getAnims(t).items.push(...e)}has(t){return this._getAnims(t).items.length>0}start(t){let e=this._charts.get(t);e&&(e.running=!0,e.start=Date.now(),e.duration=e.items.reduce((n,i)=>Math.max(n,i._duration),0),this._refresh())}running(t){if(!this._running)return!1;let e=this._charts.get(t);return!(!e||!e.running||!e.items.length)}stop(t){let e=this._charts.get(t);if(!e||!e.items.length)return;let n=e.items,i=n.length-1;for(;i>=0;--i)n[i].cancel();e.items=[],this._notify(t,e,Date.now(),"complete")}remove(t){return this._charts.delete(t)}},se=new So,ba="transparent",vh={boolean(s,t,e){return e>.5?t:s},color(s,t,e){let n=Xi(s||ba),i=n.valid&&Xi(t||ba);return i&&i.valid?i.mix(n,e).hexString():t},number(s,t,e){return s+(t-s)*e}},Zn=class{constructor(t,e,n,i){let o=e[n];i=ps([t.to,i,o,t.from]);let r=ps([t.from,o,i]);this._active=!0,this._fn=t.fn||vh[t.type||typeof r],this._easing=os[t.easing]||os.linear,this._start=Math.floor(Date.now()+(t.delay||0)),this._duration=this._total=Math.floor(t.duration),this._loop=!!t.loop,this._target=e,this._prop=n,this._from=r,this._to=i,this._promises=void 0}active(){return this._active}update(t,e,n){if(this._active){this._notify(!1);let i=this._target[this._prop],o=n-this._start,r=this._duration-o;this._start=n,this._duration=Math.floor(Math.max(r,t.duration)),this._total+=o,this._loop=!!t.loop,this._to=ps([t.to,e,i,t.from]),this._from=ps([t.from,i,e])}}cancel(){this._active&&(this.tick(Date.now()),this._active=!1,this._notify(!1))}tick(t){let e=t-this._start,n=this._duration,i=this._prop,o=this._from,r=this._loop,a=this._to,l;if(this._active=o!==a&&(r||e<n),!this._active){this._target[i]=a,this._notify(!0);return}if(e<0){this._target[i]=o;return}l=e/n%2,l=r&&l>1?2-l:l,l=this._easing(Math.min(1,Math.max(0,l))),this._target[i]=this._fn(o,a,l)}wait(){let t=this._promises||(this._promises=[]);return new Promise((e,n)=>{t.push({res:e,rej:n})})}_notify(t){let e=t?"res":"rej",n=this._promises||[];for(let i=0;i<n.length;i++)n[i][e]()}},en=class{constructor(t,e){this._chart=t,this._properties=new Map,this.configure(e)}configure(t){if(!et(t))return;let e=Object.keys(ut.animation),n=this._properties;Object.getOwnPropertyNames(t).forEach(i=>{let o=t[i];if(!et(o))return;let r={};for(let a of e)r[a]=o[a];(dt(o.properties)&&o.properties||[i]).forEach(a=>{(a===i||!n.has(a))&&n.set(a,r)})})}_animateOptions(t,e){let n=e.options,i=xh(t,n);if(!i)return[];let o=this._createAnimations(i,n);return n.$shared&&yh(t.options.$animations,n).then(()=>{t.options=n},()=>{}),o}_createAnimations(t,e){let n=this._properties,i=[],o=t.$animations||(t.$animations={}),r=Object.keys(e),a=Date.now(),l;for(l=r.length-1;l>=0;--l){let c=r[l];if(c.charAt(0)==="$")continue;if(c==="options"){i.push(...this._animateOptions(t,e));continue}let d=e[c],h=o[c],u=n.get(c);if(h)if(u&&h.active()){h.update(u,d,a);continue}else h.cancel();if(!u||!u.duration){t[c]=d;continue}o[c]=h=new Zn(u,t,c,d),i.push(h)}return i}update(t,e){if(this._properties.size===0){Object.assign(t,e);return}let n=this._createAnimations(t,e);if(n.length)return se.add(this._chart,n),!0}};go=s=>s==="reset"||s==="none",_a=(s,t)=>t?s:Object.assign({},s),Th=(s,t,e)=>s&&!t.hidden&&t._stacked&&{keys:ml(e,!0),values:null},At=class{constructor(t,e){this.chart=t,this._ctx=t.ctx,this.index=e,this._cachedDataOpts={},this._cachedMeta=this.getMeta(),this._type=this._cachedMeta.type,this.options=void 0,this._parsing=!1,this._data=void 0,this._objectData=void 0,this._sharedOptions=void 0,this._drawStart=void 0,this._drawCount=void 0,this.enableOptionSharing=!1,this.supportsDecimation=!1,this.$context=void 0,this._syncList=[],this.datasetElementType=new.target.datasetElementType,this.dataElementType=new.target.dataElementType,this.initialize()}initialize(){let t=this._cachedMeta;this.configure(),this.linkScales(),t._stacked=uo(t.vScale,t),this.addElements(),this.options.fill&&!this.chart.isPluginEnabled("filler")&&console.warn("Tried to use the 'fill' option without the 'Filler' plugin enabled. Please import and register the 'Filler' plugin and make sure it is not disabled in the options")}updateIndex(t){this.index!==t&&Ks(this._cachedMeta),this.index=t}linkScales(){let t=this.chart,e=this._cachedMeta,n=this.getDataset(),i=(h,u,f,g)=>h==="x"?u:h==="r"?g:f,o=e.xAxisID=J(n.xAxisID,fo(t,"x")),r=e.yAxisID=J(n.yAxisID,fo(t,"y")),a=e.rAxisID=J(n.rAxisID,fo(t,"r")),l=e.indexAxis,c=e.iAxisID=i(l,o,r,a),d=e.vAxisID=i(l,r,o,a);e.xScale=this.getScaleForId(o),e.yScale=this.getScaleForId(r),e.rScale=this.getScaleForId(a),e.iScale=this.getScaleForId(c),e.vScale=this.getScaleForId(d)}getDataset(){return this.chart.data.datasets[this.index]}getMeta(){return this.chart.getDatasetMeta(this.index)}getScaleForId(t){return this.chart.scales[t]}_getOtherScale(t){let e=this._cachedMeta;return t===e.iScale?e.vScale:e.iScale}reset(){this._update("reset")}_destroy(){let t=this._cachedMeta;this._data&&Wi(this._data,this),t._stacked&&Ks(t)}_dataCheck(){let t=this.getDataset(),e=t.data||(t.data=[]),n=this._data;if(et(e)){let i=this._cachedMeta;this._data=Sh(e,i)}else if(n!==e){if(n){Wi(n,this);let i=this._cachedMeta;Ks(i),i._parsed=[]}e&&Object.isExtensible(e)&&Qr(e,this),this._syncList=[],this._data=e}}addElements(){let t=this._cachedMeta;this._dataCheck(),this.datasetElementType&&(t.dataset=new this.datasetElementType)}buildOrUpdateElements(t){let e=this._cachedMeta,n=this.getDataset(),i=!1;this._dataCheck();let o=e._stacked;e._stacked=uo(e.vScale,e),e.stack!==n.stack&&(i=!0,Ks(e),e.stack=n.stack),this._resyncElements(t),(i||o!==e._stacked)&&(Ca(this,e._parsed),e._stacked=uo(e.vScale,e))}configure(){let t=this.chart.config,e=t.datasetScopeKeys(this._type),n=t.getOptionScopes(this.getDataset(),e,!0);this.options=t.createResolver(n,this.getContext()),this._parsing=this.options.parsing,this._cachedDataOpts={}}parse(t,e){let{_cachedMeta:n,_data:i}=this,{iScale:o,_stacked:r}=n,a=o.axis,l=t===0&&e===i.length?!0:n._sorted,c=t>0&&n._parsed[t-1],d,h,u;if(this._parsing===!1)n._parsed=i,n._sorted=!0,u=i;else{dt(i[t])?u=this.parseArrayData(n,i,t,e):et(i[t])?u=this.parseObjectData(n,i,t,e):u=this.parsePrimitiveData(n,i,t,e);let f=()=>h[a]===null||c&&h[a]<c[a];for(d=0;d<e;++d)n._parsed[d+t]=h=u[d],l&&(f()&&(l=!1),c=h);n._sorted=l}r&&Ca(this,u)}parsePrimitiveData(t,e,n,i){let{iScale:o,vScale:r}=t,a=o.axis,l=r.axis,c=o.getLabels(),d=o===r,h=new Array(i),u,f,g;for(u=0,f=i;u<f;++u)g=u+n,h[u]={[a]:d||o.parse(c[g],g),[l]:r.parse(e[g],g)};return h}parseArrayData(t,e,n,i){let{xScale:o,yScale:r}=t,a=new Array(i),l,c,d,h;for(l=0,c=i;l<c;++l)d=l+n,h=e[d],a[l]={x:o.parse(h[0],d),y:r.parse(h[1],d)};return a}parseObjectData(t,e,n,i){let{xScale:o,yScale:r}=t,{xAxisKey:a="x",yAxisKey:l="y"}=this._parsing,c=new Array(i),d,h,u,f;for(d=0,h=i;d<h;++d)u=d+n,f=e[u],c[d]={x:o.parse(ce(f,a),u),y:r.parse(ce(f,l),u)};return c}getParsed(t){return this._cachedMeta._parsed[t]}getDataElement(t){return this._cachedMeta.data[t]}applyStack(t,e,n){let i=this.chart,o=this._cachedMeta,r=e[t.axis],a={keys:ml(i,!0),values:e._stacks[t.axis]._visualValues};return ya(a,r,o.index,{mode:n})}updateRangeFromParsed(t,e,n,i){let o=n[e.axis],r=o===null?NaN:o,a=i&&n._stacks[e.axis];i&&a&&(i.values=a,r=ya(i,o,this._cachedMeta.index)),t.min=Math.min(t.min,r),t.max=Math.max(t.max,r)}getMinMax(t,e){let n=this._cachedMeta,i=n._parsed,o=n._sorted&&t===n.iScale,r=i.length,a=this._getOtherScale(t),l=Th(e,n,this.chart),c={min:Number.POSITIVE_INFINITY,max:Number.NEGATIVE_INFINITY},{min:d,max:h}=kh(a),u,f;function g(){f=i[u];let p=f[a.axis];return!gt(f[t.axis])||d>p||h<p}for(u=0;u<r&&!(!g()&&(this.updateRangeFromParsed(c,t,f,l),o));++u);if(o){for(u=r-1;u>=0;--u)if(!g()){this.updateRangeFromParsed(c,t,f,l);break}}return c}getAllParsedValues(t){let e=this._cachedMeta._parsed,n=[],i,o,r;for(i=0,o=e.length;i<o;++i)r=e[i][t.axis],gt(r)&&n.push(r);return n}getMaxOverflow(){return!1}getLabelAndValue(t){let e=this._cachedMeta,n=e.iScale,i=e.vScale,o=this.getParsed(t);return{label:n?""+n.getLabelForValue(o[n.axis]):"",value:i?""+i.getLabelForValue(o[i.axis]):""}}_update(t){let e=this._cachedMeta;this.update(t||"default"),e._clip=_h(J(this.options.clip,Ch(e.xScale,e.yScale,this.getMaxOverflow())))}update(t){}draw(){let t=this._ctx,e=this.chart,n=this._cachedMeta,i=n.data||[],o=e.chartArea,r=[],a=this._drawStart||0,l=this._drawCount||i.length-a,c=this.options.drawActiveElementsOnTop,d;for(n.dataset&&n.dataset.draw(t,o,a,l),d=a;d<a+l;++d){let h=i[d];h.hidden||(h.active&&c?r.push(h):h.draw(t,o))}for(d=0;d<r.length;++d)r[d].draw(t,o)}getStyle(t,e){let n=e?"active":"default";return t===void 0&&this._cachedMeta.dataset?this.resolveDatasetElementOptions(n):this.resolveDataElementOptions(t||0,n)}getContext(t,e,n){let i=this.getDataset(),o;if(t>=0&&t<this._cachedMeta.data.length){let r=this._cachedMeta.data[t];o=r.$context||(r.$context=Dh(this.getContext(),t,r)),o.parsed=this.getParsed(t),o.raw=i.data[t],o.index=o.dataIndex=t}else o=this.$context||(this.$context=Mh(this.chart.getContext(),this.index)),o.dataset=i,o.index=o.datasetIndex=this.index;return o.active=!!e,o.mode=n,o}resolveDatasetElementOptions(t){return this._resolveElementOptions(this.datasetElementType.id,t)}resolveDataElementOptions(t,e){return this._resolveElementOptions(this.dataElementType.id,e,t)}_resolveElementOptions(t,e="default",n){let i=e==="active",o=this._cachedDataOpts,r=t+"-"+e,a=o[r],l=this.enableOptionSharing&&cs(n);if(a)return _a(a,l);let c=this.chart.config,d=c.datasetElementScopeKeys(this._type,t),h=i?[`${t}Hover`,"hover",t,""]:[t,""],u=c.getOptionScopes(this.getDataset(),d),f=Object.keys(ut.elements[t]),g=()=>this.getContext(n,i,e),p=c.resolveNamedOptions(u,f,g,h);return p.$shared&&(p.$shared=l,o[r]=Object.freeze(_a(p,l))),p}_resolveAnimations(t,e,n){let i=this.chart,o=this._cachedDataOpts,r=`animation-${e}`,a=o[r];if(a)return a;let l;if(i.options.animation!==!1){let d=this.chart.config,h=d.datasetAnimationScopeKeys(this._type,e),u=d.getOptionScopes(this.getDataset(),h);l=d.createResolver(u,this.getContext(t,n,e))}let c=new en(i,l&&l.animations);return l&&l._cacheable&&(o[r]=Object.freeze(c)),c}getSharedOptions(t){if(t.$shared)return this._sharedOptions||(this._sharedOptions=Object.assign({},t))}includeOptions(t,e){return!e||go(t)||this.chart._animationsDisabled}_getSharedOptions(t,e){let n=this.resolveDataElementOptions(t,e),i=this._sharedOptions,o=this.getSharedOptions(n),r=this.includeOptions(e,o)||o!==i;return this.updateSharedOptions(o,e,n),{sharedOptions:o,includeOptions:r}}updateElement(t,e,n,i){go(i)?Object.assign(t,n):this._resolveAnimations(e,i).update(t,n)}updateSharedOptions(t,e,n){t&&!go(e)&&this._resolveAnimations(void 0,e).update(t,n)}_setStyle(t,e,n,i){t.active=i;let o=this.getStyle(e,i);this._resolveAnimations(e,n,i).update(t,{options:!i&&this.getSharedOptions(o)||o})}removeHoverStyle(t,e,n){this._setStyle(t,n,"active",!1)}setHoverStyle(t,e,n){this._setStyle(t,n,"active",!0)}_removeDatasetHoverStyle(){let t=this._cachedMeta.dataset;t&&this._setStyle(t,void 0,"active",!1)}_setDatasetHoverStyle(){let t=this._cachedMeta.dataset;t&&this._setStyle(t,void 0,"active",!0)}_resyncElements(t){let e=this._data,n=this._cachedMeta.data;for(let[a,l,c]of this._syncList)this[a](l,c);this._syncList=[];let i=n.length,o=e.length,r=Math.min(o,i);r&&this.parse(0,r),o>i?this._insertElements(i,o-i,t):o<i&&this._removeElements(o,i-o)}_insertElements(t,e,n=!0){let i=this._cachedMeta,o=i.data,r=t+e,a,l=c=>{for(c.length+=e,a=c.length-1;a>=r;a--)c[a]=c[a-e]};for(l(o),a=t;a<r;++a)o[a]=new this.dataElementType;this._parsing&&l(i._parsed),this.parse(t,e),n&&this.updateElements(o,t,e,"reset")}updateElements(t,e,n,i){}_removeElements(t,e){let n=this._cachedMeta;if(this._parsing){let i=n._parsed.splice(t,e);n._stacked&&Ks(n,i)}n.data.splice(t,e)}_sync(t){if(this._parsing)this._syncList.push(t);else{let[e,n,i]=t;this[e](n,i)}this.chart._dataChanges.push([this.index,...t])}_onDataPush(){let t=arguments.length;this._sync(["_insertElements",this.getDataset().data.length-t,t])}_onDataPop(){this._sync(["_removeElements",this._cachedMeta.data.length-1,1])}_onDataShift(){this._sync(["_removeElements",0,1])}_onDataSplice(t,e){e&&this._sync(["_removeElements",t,e]);let n=arguments.length-2;n&&this._sync(["_insertElements",t,n])}_onDataUnshift(){this._sync(["_insertElements",0,arguments.length])}};G(At,"defaults",{}),G(At,"datasetElementType",null),G(At,"dataElementType",null);Be=class extends At{parsePrimitiveData(t,e,n,i){return Sa(t,e,n,i)}parseArrayData(t,e,n,i){return Sa(t,e,n,i)}parseObjectData(t,e,n,i){let{iScale:o,vScale:r}=t,{xAxisKey:a="x",yAxisKey:l="y"}=this._parsing,c=o.axis==="x"?a:l,d=r.axis==="x"?a:l,h=[],u,f,g,p;for(u=n,f=n+i;u<f;++u)p=e[u],g={},g[o.axis]=o.parse(ce(p,c),u),h.push(bl(ce(p,d),g,r,u));return h}updateRangeFromParsed(t,e,n,i){super.updateRangeFromParsed(t,e,n,i);let o=n._custom;o&&e===this._cachedMeta.vScale&&(t.min=Math.min(t.min,o.min),t.max=Math.max(t.max,o.max))}getMaxOverflow(){return 0}getLabelAndValue(t){let e=this._cachedMeta,{iScale:n,vScale:i}=e,o=this.getParsed(t),r=o._custom,a=po(r)?"["+r.start+", "+r.end+"]":""+i.getLabelForValue(o[i.axis]);return{label:""+n.getLabelForValue(o[n.axis]),value:a}}initialize(){this.enableOptionSharing=!0,super.initialize();let t=this._cachedMeta;t.stack=this.getDataset().stack}update(t){let e=this._cachedMeta;this.updateElements(e.data,0,e.data.length,t)}updateElements(t,e,n,i){let o=i==="reset",{index:r,_cachedMeta:{vScale:a}}=this,l=a.getBasePixel(),c=a.isHorizontal(),d=this._getRuler(),{sharedOptions:h,includeOptions:u}=this._getSharedOptions(e,i);for(let f=e;f<e+n;f++){let g=this.getParsed(f),p=o||tt(g[a.axis])?{base:l,head:l}:this._calculateBarValuePixels(f),b=this._calculateBarIndexPixels(f,d),m=(g._stacks||{})[a.axis],y={horizontal:c,base:p.base,enableBorderRadius:!m||po(g._custom)||r===m._top||r===m._bottom,x:c?p.head:b.center,y:c?b.center:p.head,height:c?b.size:Math.abs(p.size),width:c?Math.abs(p.size):b.size};u&&(y.options=h||this.resolveDataElementOptions(f,t[f].active?"active":i));let C=y.options||t[f].options;Vh(y,C,m,r),Nh(y,C,d.ratio),this.updateElement(t[f],f,y,i)}}_getStacks(t,e){let{iScale:n}=this._cachedMeta,i=n.getMatchingVisibleMetas(this._type).filter(d=>d.controller.options.grouped),o=n.options.stacked,r=[],a=this._cachedMeta.controller.getParsed(e),l=a&&a[n.axis],c=d=>{let h=d._parsed.find(f=>f[n.axis]===l),u=h&&h[d.vScale.axis];if(tt(u)||isNaN(u))return!0};for(let d of i)if(!(e!==void 0&&c(d))&&((o===!1||r.indexOf(d.stack)===-1||o===void 0&&d.stack===void 0)&&r.push(d.stack),d.index===t))break;return r.length||r.push(void 0),r}_getStackCount(t){return this._getStacks(void 0,t).length}_getAxisCount(){return this._getAxis().length}getFirstScaleIdForIndexAxis(){let t=this.chart.scales,e=this.chart.options.indexAxis;return Object.keys(t).filter(n=>t[n].axis===e).shift()}_getAxis(){let t={},e=this.getFirstScaleIdForIndexAxis();for(let n of this.chart.data.datasets)t[J(this.chart.options.indexAxis==="x"?n.xAxisID:n.yAxisID,e)]=!0;return Object.keys(t)}_getStackIndex(t,e,n){let i=this._getStacks(t,n),o=e!==void 0?i.indexOf(e):-1;return o===-1?i.length-1:o}_getRuler(){let t=this.options,e=this._cachedMeta,n=e.iScale,i=[],o,r;for(o=0,r=e.data.length;o<r;++o)i.push(n.getPixelForValue(this.getParsed(o)[n.axis],o));let a=t.barThickness;return{min:a||Ah(e),pixels:i,start:n._startPixel,end:n._endPixel,stackCount:this._getStackCount(),scale:n,grouped:t.grouped,ratio:a?1:t.categoryPercentage*t.barPercentage}}_calculateBarValuePixels(t){let{_cachedMeta:{vScale:e,_stacked:n,index:i},options:{base:o,minBarLength:r}}=this,a=o||0,l=this.getParsed(t),c=l._custom,d=po(c),h=l[e.axis],u=0,f=n?this.applyStack(e,l,n):h,g,p;f!==h&&(u=f-h,f=h),d&&(h=c.barStart,f=c.barEnd-c.barStart,h!==0&&Ut(h)!==Ut(c.barEnd)&&(u=0),u+=h);let b=!tt(o)&&!d?o:u,m=e.getPixelForValue(b);if(this.chart.getDataVisibility(t)?g=e.getPixelForValue(u+f):g=m,p=g-m,Math.abs(p)<r){p=Fh(p,e,a)*r,h===a&&(m-=p/2);let y=e.getPixelForDecimal(0),C=e.getPixelForDecimal(1),E=Math.min(y,C),S=Math.max(y,C);m=Math.max(Math.min(m,S),E),g=m+p,n&&!d&&(l._stacks[e.axis]._visualValues[i]=e.getValueForPixel(g)-e.getValueForPixel(m))}if(m===e.getPixelForValue(a)){let y=Ut(p)*e.getLineWidthForValue(a)/2;m+=y,p-=y}return{size:p,base:m,head:g,center:g+p/2}}_calculateBarIndexPixels(t,e){let n=e.scale,i=this.options,o=i.skipNull,r=J(i.maxBarThickness,1/0),a,l,c=this._getAxisCount();if(e.grouped){let d=o?this._getStackCount(t):e.stackCount,h=i.barThickness==="flex"?Ph(t,e,i,d*c):Rh(t,e,i,d*c),u=this.chart.options.indexAxis==="x"?this.getDataset().xAxisID:this.getDataset().yAxisID,f=this._getAxis().indexOf(J(u,this.getFirstScaleIdForIndexAxis())),g=this._getStackIndex(this.index,this._cachedMeta.stack,o?t:void 0)+f;a=h.start+h.chunk*g+h.chunk/2,l=Math.min(r,h.chunk*h.ratio)}else a=n.getPixelForValue(this.getParsed(t)[n.axis],t),l=Math.min(r,e.min*e.ratio);return{base:a-l/2,head:a+l/2,center:a,size:l}}draw(){let t=this._cachedMeta,e=t.vScale,n=t.data,i=n.length,o=0;for(;o<i;++o)this.getParsed(o)[e.axis]!==null&&!n[o].hidden&&n[o].draw(this._ctx)}};G(Be,"id","bar"),G(Be,"defaults",{datasetElementType:!1,dataElementType:"bar",categoryPercentage:.8,barPercentage:.9,grouped:!0,animations:{numbers:{type:"number",properties:["x","y","base","width","height"]}}}),G(Be,"overrides",{scales:{_index_:{type:"category",offset:!0,grid:{offset:!0}},_value_:{type:"linear",beginAtZero:!0}}});Ne=class extends At{initialize(){this.enableOptionSharing=!0,super.initialize()}parsePrimitiveData(t,e,n,i){let o=super.parsePrimitiveData(t,e,n,i);for(let r=0;r<o.length;r++)o[r]._custom=this.resolveDataElementOptions(r+n).radius;return o}parseArrayData(t,e,n,i){let o=super.parseArrayData(t,e,n,i);for(let r=0;r<o.length;r++){let a=e[n+r];o[r]._custom=J(a[2],this.resolveDataElementOptions(r+n).radius)}return o}parseObjectData(t,e,n,i){let o=super.parseObjectData(t,e,n,i);for(let r=0;r<o.length;r++){let a=e[n+r];o[r]._custom=J(a&&a.r&&+a.r,this.resolveDataElementOptions(r+n).radius)}return o}getMaxOverflow(){let t=this._cachedMeta.data,e=0;for(let n=t.length-1;n>=0;--n)e=Math.max(e,t[n].size(this.resolveDataElementOptions(n))/2);return e>0&&e}getLabelAndValue(t){let e=this._cachedMeta,n=this.chart.data.labels||[],{xScale:i,yScale:o}=e,r=this.getParsed(t),a=i.getLabelForValue(r.x),l=o.getLabelForValue(r.y),c=r._custom;return{label:n[t]||"",value:"("+a+", "+l+(c?", "+c:"")+")"}}update(t){let e=this._cachedMeta.data;this.updateElements(e,0,e.length,t)}updateElements(t,e,n,i){let o=i==="reset",{iScale:r,vScale:a}=this._cachedMeta,{sharedOptions:l,includeOptions:c}=this._getSharedOptions(e,i),d=r.axis,h=a.axis;for(let u=e;u<e+n;u++){let f=t[u],g=!o&&this.getParsed(u),p={},b=p[d]=o?r.getPixelForDecimal(.5):r.getPixelForValue(g[d]),m=p[h]=o?a.getBasePixel():a.getPixelForValue(g[h]);p.skip=isNaN(b)||isNaN(m),c&&(p.options=l||this.resolveDataElementOptions(u,f.active?"active":i),o&&(p.options.radius=0)),this.updateElement(f,u,p,i)}}resolveDataElementOptions(t,e){let n=this.getParsed(t),i=super.resolveDataElementOptions(t,e);i.$shared&&(i=Object.assign({},i,{$shared:!1}));let o=i.radius;return e!=="active"&&(i.radius=0),i.radius+=J(n&&n._custom,o),i}};G(Ne,"id","bubble"),G(Ne,"defaults",{datasetElementType:!1,dataElementType:"point",animations:{numbers:{type:"number",properties:["x","y","borderWidth","radius"]}}}),G(Ne,"overrides",{scales:{x:{type:"linear"},y:{type:"linear"}}});ie=class extends At{constructor(t,e){super(t,e),this.enableOptionSharing=!0,this.innerRadius=void 0,this.outerRadius=void 0,this.offsetX=void 0,this.offsetY=void 0}linkScales(){}parse(t,e){let n=this.getDataset().data,i=this._cachedMeta;if(this._parsing===!1)i._parsed=n;else{let o=l=>+n[l];if(et(n[t])){let{key:l="value"}=this._parsing;o=c=>+ce(n[c],l)}let r,a;for(r=t,a=t+e;r<a;++r)i._parsed[r]=o(r)}}_getRotation(){return Ht(this.options.rotation-90)}_getCircumference(){return Ht(this.options.circumference)}_getRotationExtents(){let t=ht,e=-ht;for(let n=0;n<this.chart.data.datasets.length;++n)if(this.chart.isDatasetVisible(n)&&this.chart.getDatasetMeta(n).type===this._type){let i=this.chart.getDatasetMeta(n).controller,o=i._getRotation(),r=i._getCircumference();t=Math.min(t,o),e=Math.max(e,o+r)}return{rotation:t,circumference:e-t}}update(t){let e=this.chart,{chartArea:n}=e,i=this._cachedMeta,o=i.data,r=this.getMaxBorderWidth()+this.getMaxOffset(o)+this.options.spacing,a=Math.max((Math.min(n.width,n.height)-r)/2,0),l=Math.min(Hr(this.options.cutout,a),1),c=this._getRingWeight(this.index),{circumference:d,rotation:h}=this._getRotationExtents(),{ratioX:u,ratioY:f,offsetX:g,offsetY:p}=$h(h,d,l),b=(n.width-r)/u,m=(n.height-r)/f,y=Math.max(Math.min(b,m)/2,0),C=Vi(this.options.radius,y),E=Math.max(C*l,0),S=(C-E)/this._getVisibleDatasetWeightTotal();this.offsetX=g*C,this.offsetY=p*C,i.total=this.calculateTotal(),this.outerRadius=C-S*this._getRingWeightOffset(this.index),this.innerRadius=Math.max(this.outerRadius-S*c,0),this.updateElements(o,0,o.length,t)}_circumference(t,e){let n=this.options,i=this._cachedMeta,o=this._getCircumference();return e&&n.animation.animateRotate||!this.chart.getDataVisibility(t)||i._parsed[t]===null||i.data[t].hidden?0:this.calculateCircumference(i._parsed[t]*o/ht)}updateElements(t,e,n,i){let o=i==="reset",r=this.chart,a=r.chartArea,c=r.options.animation,d=(a.left+a.right)/2,h=(a.top+a.bottom)/2,u=o&&c.animateScale,f=u?0:this.innerRadius,g=u?0:this.outerRadius,{sharedOptions:p,includeOptions:b}=this._getSharedOptions(e,i),m=this._getRotation(),y;for(y=0;y<e;++y)m+=this._circumference(y,o);for(y=e;y<e+n;++y){let C=this._circumference(y,o),E=t[y],S={x:d+this.offsetX,y:h+this.offsetY,startAngle:m,endAngle:m+C,circumference:C,outerRadius:g,innerRadius:f};b&&(S.options=p||this.resolveDataElementOptions(y,E.active?"active":i)),m+=C,this.updateElement(E,y,S,i)}}calculateTotal(){let t=this._cachedMeta,e=t.data,n=0,i;for(i=0;i<e.length;i++){let o=t._parsed[i];o!==null&&!isNaN(o)&&this.chart.getDataVisibility(i)&&!e[i].hidden&&(n+=Math.abs(o))}return n}calculateCircumference(t){let e=this._cachedMeta.total;return e>0&&!isNaN(t)?ht*(Math.abs(t)/e):0}getLabelAndValue(t){let e=this._cachedMeta,n=this.chart,i=n.data.labels||[],o=us(e._parsed[t],n.options.locale);return{label:i[t]||"",value:o}}getMaxBorderWidth(t){let e=0,n=this.chart,i,o,r,a,l;if(!t){for(i=0,o=n.data.datasets.length;i<o;++i)if(n.isDatasetVisible(i)){r=n.getDatasetMeta(i),t=r.data,a=r.controller;break}}if(!t)return 0;for(i=0,o=t.length;i<o;++i)l=a.resolveDataElementOptions(i),l.borderAlign!=="inner"&&(e=Math.max(e,l.borderWidth||0,l.hoverBorderWidth||0));return e}getMaxOffset(t){let e=0;for(let n=0,i=t.length;n<i;++n){let o=this.resolveDataElementOptions(n);e=Math.max(e,o.offset||0,o.hoverOffset||0)}return e}_getRingWeightOffset(t){let e=0;for(let n=0;n<t;++n)this.chart.isDatasetVisible(n)&&(e+=this._getRingWeight(n));return e}_getRingWeight(t){return Math.max(J(this.chart.data.datasets[t].weight,1),0)}_getVisibleDatasetWeightTotal(){return this._getRingWeightOffset(this.chart.data.datasets.length)||1}};G(ie,"id","doughnut"),G(ie,"defaults",{datasetElementType:!1,dataElementType:"arc",animation:{animateRotate:!0,animateScale:!1},animations:{numbers:{type:"number",properties:["circumference","endAngle","innerRadius","outerRadius","startAngle","x","y","offset","borderWidth","spacing"]}},cutout:"50%",rotation:0,circumference:360,radius:"100%",spacing:0,indexAxis:"r"}),G(ie,"descriptors",{_scriptable:t=>t!=="spacing",_indexable:t=>t!=="spacing"&&!t.startsWith("borderDash")&&!t.startsWith("hoverBorderDash")}),G(ie,"overrides",{aspectRatio:1,plugins:{legend:{labels:{generateLabels(t){let e=t.data,{labels:{pointStyle:n,textAlign:i,color:o,useBorderRadius:r,borderRadius:a}}=t.legend.options;return e.labels.length&&e.datasets.length?e.labels.map((l,c)=>{let h=t.getDatasetMeta(0).controller.getStyle(c);return{text:l,fillStyle:h.backgroundColor,fontColor:o,hidden:!t.getDataVisibility(c),lineDash:h.borderDash,lineDashOffset:h.borderDashOffset,lineJoin:h.borderJoinStyle,lineWidth:h.borderWidth,strokeStyle:h.borderColor,textAlign:i,pointStyle:n,borderRadius:r&&(a||h.borderRadius),index:c}}):[]}},onClick(t,e,n){n.chart.toggleDataVisibility(e.index),n.chart.update()}}}});$e=class extends At{initialize(){this.enableOptionSharing=!0,this.supportsDecimation=!0,super.initialize()}update(t){let e=this._cachedMeta,{dataset:n,data:i=[],_dataset:o}=e,r=this.chart._animationsDisabled,{start:a,count:l}=Ki(e,i,r);this._drawStart=a,this._drawCount=l,Gi(e)&&(a=0,l=i.length),n._chart=this.chart,n._datasetIndex=this.index,n._decimated=!!o._decimated,n.points=i;let c=this.resolveDatasetElementOptions(t);this.options.showLine||(c.borderWidth=0),c.segment=this.options.segment,this.updateElement(n,void 0,{animated:!r,options:c},t),this.updateElements(i,a,l,t)}updateElements(t,e,n,i){let o=i==="reset",{iScale:r,vScale:a,_stacked:l,_dataset:c}=this._cachedMeta,{sharedOptions:d,includeOptions:h}=this._getSharedOptions(e,i),u=r.axis,f=a.axis,{spanGaps:g,segment:p}=this.options,b=Oe(g)?g:Number.POSITIVE_INFINITY,m=this.chart._animationsDisabled||o||i==="none",y=e+n,C=t.length,E=e>0&&this.getParsed(e-1);for(let S=0;S<C;++S){let x=t[S],v=m?x:{};if(S<e||S>=y){v.skip=!0;continue}let _=this.getParsed(S),w=tt(_[f]),D=v[u]=r.getPixelForValue(_[u],S),k=v[f]=o||w?a.getBasePixel():a.getPixelForValue(l?this.applyStack(a,_,l):_[f],S);v.skip=isNaN(D)||isNaN(k)||w,v.stop=S>0&&Math.abs(_[u]-E[u])>b,p&&(v.parsed=_,v.raw=c.data[S]),h&&(v.options=d||this.resolveDataElementOptions(S,x.active?"active":i)),m||this.updateElement(x,S,v,i),E=_}}getMaxOverflow(){let t=this._cachedMeta,e=t.dataset,n=e.options&&e.options.borderWidth||0,i=t.data||[];if(!i.length)return n;let o=i[0].size(this.resolveDataElementOptions(0)),r=i[i.length-1].size(this.resolveDataElementOptions(i.length-1));return Math.max(n,o,r)/2}draw(){let t=this._cachedMeta;t.dataset.updateControlPoints(this.chart.chartArea,t.iScale.axis),super.draw()}};G($e,"id","line"),G($e,"defaults",{datasetElementType:"line",dataElementType:"point",showLine:!0,spanGaps:!1}),G($e,"overrides",{scales:{_index_:{type:"category"},_value_:{type:"linear"}}});we=class extends At{constructor(t,e){super(t,e),this.innerRadius=void 0,this.outerRadius=void 0}getLabelAndValue(t){let e=this._cachedMeta,n=this.chart,i=n.data.labels||[],o=us(e._parsed[t].r,n.options.locale);return{label:i[t]||"",value:o}}parseObjectData(t,e,n,i){return no.bind(this)(t,e,n,i)}update(t){let e=this._cachedMeta.data;this._updateRadius(),this.updateElements(e,0,e.length,t)}getMinMax(){let t=this._cachedMeta,e={min:Number.POSITIVE_INFINITY,max:Number.NEGATIVE_INFINITY};return t.data.forEach((n,i)=>{let o=this.getParsed(i).r;!isNaN(o)&&this.chart.getDataVisibility(i)&&(o<e.min&&(e.min=o),o>e.max&&(e.max=o))}),e}_updateRadius(){let t=this.chart,e=t.chartArea,n=t.options,i=Math.min(e.right-e.left,e.bottom-e.top),o=Math.max(i/2,0),r=Math.max(n.cutoutPercentage?o/100*n.cutoutPercentage:1,0),a=(o-r)/t.getVisibleDatasetCount();this.outerRadius=o-a*this.index,this.innerRadius=this.outerRadius-a}updateElements(t,e,n,i){let o=i==="reset",r=this.chart,l=r.options.animation,c=this._cachedMeta.rScale,d=c.xCenter,h=c.yCenter,u=c.getIndexAngle(0)-.5*nt,f=u,g,p=360/this.countVisibleElements();for(g=0;g<e;++g)f+=this._computeAngle(g,i,p);for(g=e;g<e+n;g++){let b=t[g],m=f,y=f+this._computeAngle(g,i,p),C=r.getDataVisibility(g)?c.getDistanceFromCenterForValue(this.getParsed(g).r):0;f=y,o&&(l.animateScale&&(C=0),l.animateRotate&&(m=y=u));let E={x:d,y:h,innerRadius:0,outerRadius:C,startAngle:m,endAngle:y,options:this.resolveDataElementOptions(g,b.active?"active":i)};this.updateElement(b,g,E,i)}}countVisibleElements(){let t=this._cachedMeta,e=0;return t.data.forEach((n,i)=>{!isNaN(this.getParsed(i).r)&&this.chart.getDataVisibility(i)&&e++}),e}_computeAngle(t,e,n){return this.chart.getDataVisibility(t)?Ht(this.resolveDataElementOptions(t,e).angle||n):0}};G(we,"id","polarArea"),G(we,"defaults",{dataElementType:"arc",animation:{animateRotate:!0,animateScale:!0},animations:{numbers:{type:"number",properties:["x","y","startAngle","endAngle","innerRadius","outerRadius"]}},indexAxis:"r",startAngle:0}),G(we,"overrides",{aspectRatio:1,plugins:{legend:{labels:{generateLabels(t){let e=t.data;if(e.labels.length&&e.datasets.length){let{labels:{pointStyle:n,color:i}}=t.legend.options;return e.labels.map((o,r)=>{let l=t.getDatasetMeta(0).controller.getStyle(r);return{text:o,fillStyle:l.backgroundColor,strokeStyle:l.borderColor,fontColor:i,lineWidth:l.borderWidth,pointStyle:n,hidden:!t.getDataVisibility(r),index:r}})}return[]}},onClick(t,e,n){n.chart.toggleDataVisibility(e.index),n.chart.update()}}},scales:{r:{type:"radialLinear",angleLines:{display:!1},beginAtZero:!0,grid:{circular:!0},pointLabels:{display:!1},startAngle:0}}});bs=class extends ie{};G(bs,"id","pie"),G(bs,"defaults",{cutout:0,rotation:0,circumference:360,radius:"100%"});ze=class extends At{getLabelAndValue(t){let e=this._cachedMeta.vScale,n=this.getParsed(t);return{label:e.getLabels()[t],value:""+e.getLabelForValue(n[e.axis])}}parseObjectData(t,e,n,i){return no.bind(this)(t,e,n,i)}update(t){let e=this._cachedMeta,n=e.dataset,i=e.data||[],o=e.iScale.getLabels();if(n.points=i,t!=="resize"){let r=this.resolveDatasetElementOptions(t);this.options.showLine||(r.borderWidth=0);let a={_loop:!0,_fullLoop:o.length===i.length,options:r};this.updateElement(n,void 0,a,t)}this.updateElements(i,0,i.length,t)}updateElements(t,e,n,i){let o=this._cachedMeta.rScale,r=i==="reset";for(let a=e;a<e+n;a++){let l=t[a],c=this.resolveDataElementOptions(a,l.active?"active":i),d=o.getPointPositionForValue(a,this.getParsed(a).r),h=r?o.xCenter:d.x,u=r?o.yCenter:d.y,f={x:h,y:u,angle:d.angle,skip:isNaN(h)||isNaN(u),options:c};this.updateElement(l,a,f,i)}}};G(ze,"id","radar"),G(ze,"defaults",{datasetElementType:"line",dataElementType:"point",indexAxis:"r",showLine:!0,elements:{line:{fill:"start"}}}),G(ze,"overrides",{aspectRatio:1,scales:{r:{type:"radialLinear"}}});He=class extends At{getLabelAndValue(t){let e=this._cachedMeta,n=this.chart.data.labels||[],{xScale:i,yScale:o}=e,r=this.getParsed(t),a=i.getLabelForValue(r.x),l=o.getLabelForValue(r.y);return{label:n[t]||"",value:"("+a+", "+l+")"}}update(t){let e=this._cachedMeta,{data:n=[]}=e,i=this.chart._animationsDisabled,{start:o,count:r}=Ki(e,n,i);if(this._drawStart=o,this._drawCount=r,Gi(e)&&(o=0,r=n.length),this.options.showLine){this.datasetElementType||this.addElements();let{dataset:a,_dataset:l}=e;a._chart=this.chart,a._datasetIndex=this.index,a._decimated=!!l._decimated,a.points=n;let c=this.resolveDatasetElementOptions(t);c.segment=this.options.segment,this.updateElement(a,void 0,{animated:!i,options:c},t)}else this.datasetElementType&&(delete e.dataset,this.datasetElementType=!1);this.updateElements(n,o,r,t)}addElements(){let{showLine:t}=this.options;!this.datasetElementType&&t&&(this.datasetElementType=this.chart.registry.getElement("line")),super.addElements()}updateElements(t,e,n,i){let o=i==="reset",{iScale:r,vScale:a,_stacked:l,_dataset:c}=this._cachedMeta,d=this.resolveDataElementOptions(e,i),h=this.getSharedOptions(d),u=this.includeOptions(i,h),f=r.axis,g=a.axis,{spanGaps:p,segment:b}=this.options,m=Oe(p)?p:Number.POSITIVE_INFINITY,y=this.chart._animationsDisabled||o||i==="none",C=e>0&&this.getParsed(e-1);for(let E=e;E<e+n;++E){let S=t[E],x=this.getParsed(E),v=y?S:{},_=tt(x[g]),w=v[f]=r.getPixelForValue(x[f],E),D=v[g]=o||_?a.getBasePixel():a.getPixelForValue(l?this.applyStack(a,x,l):x[g],E);v.skip=isNaN(w)||isNaN(D)||_,v.stop=E>0&&Math.abs(x[f]-C[f])>m,b&&(v.parsed=x,v.raw=c.data[E]),u&&(v.options=h||this.resolveDataElementOptions(E,S.active?"active":i)),y||this.updateElement(S,E,v,i),C=x}this.updateSharedOptions(h,i,d)}getMaxOverflow(){let t=this._cachedMeta,e=t.data||[];if(!this.options.showLine){let a=0;for(let l=e.length-1;l>=0;--l)a=Math.max(a,e[l].size(this.resolveDataElementOptions(l))/2);return a>0&&a}let n=t.dataset,i=n.options&&n.options.borderWidth||0;if(!e.length)return i;let o=e[0].size(this.resolveDataElementOptions(0)),r=e[e.length-1].size(this.resolveDataElementOptions(e.length-1));return Math.max(i,o,r)/2}};G(He,"id","scatter"),G(He,"defaults",{datasetElementType:!1,dataElementType:"point",showLine:!1,fill:!1}),G(He,"overrides",{interaction:{mode:"point"},scales:{x:{type:"linear"},y:{type:"linear"}}});vl=Object.freeze({__proto__:null,BarController:Be,BubbleController:Ne,DoughnutController:ie,LineController:$e,PieController:bs,PolarAreaController:we,RadarController:ze,ScatterController:He});Eo=class s{constructor(t){G(this,"options");this.options=t||{}}static override(t){Object.assign(s.prototype,t)}init(){}formats(){return Ie()}parse(){return Ie()}format(){return Ie()}add(){return Ie()}diff(){return Ie()}startOf(){return Ie()}endOf(){return Ie()}},yl={_date:Eo};xl={evaluateInteractionItems:an,modes:{index(s,t,e,n){let i=Se(t,s),o=e.axis||"x",r=e.includeInvisible||!1,a=e.intersect?mo(s,i,o,n,r):bo(s,i,o,!1,n,r),l=[];return a.length?(s.getSortedVisibleDatasetMetas().forEach(c=>{let d=a[0].index,h=c.data[d];h&&!h.skip&&l.push({element:h,datasetIndex:c.index,index:d})}),l):[]},dataset(s,t,e,n){let i=Se(t,s),o=e.axis||"xy",r=e.includeInvisible||!1,a=e.intersect?mo(s,i,o,n,r):bo(s,i,o,!1,n,r);if(a.length>0){let l=a[0].datasetIndex,c=s.getDatasetMeta(l).data;a=[];for(let d=0;d<c.length;++d)a.push({element:c[d],datasetIndex:l,index:d})}return a},point(s,t,e,n){let i=Se(t,s),o=e.axis||"xy",r=e.includeInvisible||!1;return mo(s,i,o,n,r)},nearest(s,t,e,n){let i=Se(t,s),o=e.axis||"xy",r=e.includeInvisible||!1;return bo(s,i,o,e.intersect,n,r)},x(s,t,e,n){let i=Se(t,s);return wa(s,i,"x",e.intersect,n)},y(s,t,e,n){let i=Se(t,s);return wa(s,i,"y",e.intersect,n)}}},Cl=["left","top","right","bottom"];Et={addBox(s,t){s.boxes||(s.boxes=[]),t.fullSize=t.fullSize||!1,t.position=t.position||"top",t.weight=t.weight||0,t._layers=t._layers||function(){return[{z:0,draw(e){t.draw(e)}}]},s.boxes.push(t)},removeBox(s,t){let e=s.boxes?s.boxes.indexOf(t):-1;e!==-1&&s.boxes.splice(e,1)},configure(s,t,e){t.fullSize=e.fullSize,t.position=e.position,t.weight=e.weight},update(s,t,e,n){if(!s)return;let i=St(s.options.layout.padding),o=Math.max(t-i.width,0),r=Math.max(e-i.height,0),a=Gh(s.boxes),l=a.vertical,c=a.horizontal;rt(s.boxes,p=>{typeof p.beforeLayout=="function"&&p.beforeLayout()});let d=l.reduce((p,b)=>b.box.options&&b.box.options.display===!1?p:p+1,0)||1,h=Object.freeze({outerWidth:t,outerHeight:e,padding:i,availableWidth:o,availableHeight:r,vBoxMaxWidth:o/2/d,hBoxMaxHeight:r/2}),u=Object.assign({},i);_l(u,St(n));let f=Object.assign({maxPadding:u,w:o,h:r,x:i.left,y:i.top},i),g=Kh(l.concat(c),h);Zs(a.fullSize,f,h,g),Zs(l,f,h,g),Zs(c,f,h,g)&&Zs(l,f,h,g),Xh(f),Ta(a.leftAndTop,f,h,g),f.x+=f.w,f.y+=f.h,Ta(a.rightAndBottom,f,h,g),s.chartArea={left:f.left,top:f.top,right:f.left+f.w,bottom:f.top+f.h,height:f.h,width:f.w},rt(a.chartArea,p=>{let b=p.box;Object.assign(b,s.chartArea),b.update(f.w,f.h,{left:0,top:0,right:0,bottom:0})})}},sn=class{acquireContext(t,e){}releaseContext(t){return!1}addEventListener(t,e,n){}removeEventListener(t,e,n){}getDevicePixelRatio(){return 1}getMaximumSize(t,e,n,i){return e=Math.max(0,e||t.width),n=n||t.height,{width:e,height:Math.max(0,i?Math.floor(e/i):n)}}isAttached(t){return!0}updateConfig(t){}},Jn=class extends sn{acquireContext(t){return t&&t.getContext&&t.getContext("2d")||null}updateConfig(t){t.options.animation=!1}},Xn="$chartjs",Zh={touchstart:"mousedown",touchmove:"mousemove",touchend:"mouseup",pointerenter:"mouseenter",pointerdown:"mousedown",pointermove:"mousemove",pointerup:"mouseup",pointerleave:"mouseout",pointerout:"mouseout"},La=s=>s===null||s==="";Sl=ha?{passive:!0}:!1;nn=new Map,Aa=0;ei=class extends sn{acquireContext(t,e){let n=t&&t.getContext&&t.getContext("2d");return n&&n.canvas===t?(Jh(t,e),n):null}releaseContext(t){let e=t.canvas;if(!e[Xn])return!1;let n=e[Xn].initial;["height","width"].forEach(o=>{let r=n[o];tt(r)?e.removeAttribute(o):e.setAttribute(o,r)});let i=n.style||{};return Object.keys(i).forEach(o=>{e.style[o]=i[o]}),e.width=e.width,delete e[Xn],!0}addEventListener(t,e,n){this.removeEventListener(t,e);let i=t.$proxies||(t.$proxies={}),r={attach:nu,detach:iu,resize:au}[e]||lu;i[e]=r(t,e,n)}removeEventListener(t,e){let n=t.$proxies||(t.$proxies={}),i=n[e];if(!i)return;({attach:vo,detach:vo,resize:vo}[e]||eu)(t,e,i),n[e]=void 0}getDevicePixelRatio(){return window.devicePixelRatio}getMaximumSize(t,e,n,i){return da(t,e,n,i)}isAttached(t){let e=t&&Hn(t);return!!(e&&e.isConnected)}};Pt=class{constructor(){G(this,"x");G(this,"y");G(this,"active",!1);G(this,"options");G(this,"$animations")}tooltipPosition(t){let{x:e,y:n}=this.getProps(["x","y"],t);return{x:e,y:n}}hasValue(){return Oe(this.x)&&Oe(this.y)}getProps(t,e){let n=this.$animations;if(!e||!n)return this;let i={};return t.forEach(o=>{i[o]=n[o]&&n[o].active()?n[o]._to:this[o]}),i}};G(Pt,"defaults",{}),G(Pt,"defaultRoutes");pu=s=>s==="left"?"right":s==="right"?"left":s,Ra=(s,t,e)=>t==="top"||t==="left"?s[t]+e:s[t]-e,Pa=(s,t)=>Math.min(t||s,s);Te=class s extends Pt{constructor(t){super(),this.id=t.id,this.type=t.type,this.options=void 0,this.ctx=t.ctx,this.chart=t.chart,this.top=void 0,this.bottom=void 0,this.left=void 0,this.right=void 0,this.width=void 0,this.height=void 0,this._margins={left:0,right:0,top:0,bottom:0},this.maxWidth=void 0,this.maxHeight=void 0,this.paddingTop=void 0,this.paddingBottom=void 0,this.paddingLeft=void 0,this.paddingRight=void 0,this.axis=void 0,this.labelRotation=void 0,this.min=void 0,this.max=void 0,this._range=void 0,this.ticks=[],this._gridLineItems=null,this._labelItems=null,this._labelSizes=null,this._length=0,this._maxLength=0,this._longestTextCache={},this._startPixel=void 0,this._endPixel=void 0,this._reversePixels=!1,this._userMax=void 0,this._userMin=void 0,this._suggestedMax=void 0,this._suggestedMin=void 0,this._ticksLength=0,this._borderValue=0,this._cache={},this._dataLimitsCached=!1,this.$context=void 0}init(t){this.options=t.setContext(this.getContext()),this.axis=t.axis,this._userMin=this.parse(t.min),this._userMax=this.parse(t.max),this._suggestedMin=this.parse(t.suggestedMin),this._suggestedMax=this.parse(t.suggestedMax)}parse(t,e){return t}getUserBounds(){let{_userMin:t,_userMax:e,_suggestedMin:n,_suggestedMax:i}=this;return t=Tt(t,Number.POSITIVE_INFINITY),e=Tt(e,Number.NEGATIVE_INFINITY),n=Tt(n,Number.POSITIVE_INFINITY),i=Tt(i,Number.NEGATIVE_INFINITY),{min:Tt(t,n),max:Tt(e,i),minDefined:gt(t),maxDefined:gt(e)}}getMinMax(t){let{min:e,max:n,minDefined:i,maxDefined:o}=this.getUserBounds(),r;if(i&&o)return{min:e,max:n};let a=this.getMatchingVisibleMetas();for(let l=0,c=a.length;l<c;++l)r=a[l].controller.getMinMax(this,t),i||(e=Math.min(e,r.min)),o||(n=Math.max(n,r.max));return e=o&&e>n?n:e,n=i&&e>n?e:n,{min:Tt(e,Tt(n,e)),max:Tt(n,Tt(e,n))}}getPadding(){return{left:this.paddingLeft||0,top:this.paddingTop||0,right:this.paddingRight||0,bottom:this.paddingBottom||0}}getTicks(){return this.ticks}getLabels(){let t=this.chart.data;return this.options.labels||(this.isHorizontal()?t.xLabels:t.yLabels)||t.labels||[]}getLabelItems(t=this.chart.chartArea){return this._labelItems||(this._labelItems=this._computeLabelItems(t))}beforeLayout(){this._cache={},this._dataLimitsCached=!1}beforeUpdate(){ct(this.options.beforeUpdate,[this])}update(t,e,n){let{beginAtZero:i,grace:o,ticks:r}=this.options,a=r.sampleSize;this.beforeUpdate(),this.maxWidth=t,this.maxHeight=e,this._margins=n=Object.assign({left:0,right:0,top:0,bottom:0},n),this.ticks=null,this._labelSizes=null,this._gridLineItems=null,this._labelItems=null,this.beforeSetDimensions(),this.setDimensions(),this.afterSetDimensions(),this._maxLength=this.isHorizontal()?this.width+n.left+n.right:this.height+n.top+n.bottom,this._dataLimitsCached||(this.beforeDataLimits(),this.determineDataLimits(),this.afterDataLimits(),this._range=ia(this,o,i),this._dataLimitsCached=!0),this.beforeBuildTicks(),this.ticks=this.buildTicks()||[],this.afterBuildTicks();let l=a<this.ticks.length;this._convertTicksToLabels(l?Oa(this.ticks,a):this.ticks),this.configure(),this.beforeCalculateLabelRotation(),this.calculateLabelRotation(),this.afterCalculateLabelRotation(),r.display&&(r.autoSkip||r.source==="auto")&&(this.ticks=cu(this,this.ticks),this._labelSizes=null,this.afterAutoSkip()),l&&this._convertTicksToLabels(this.ticks),this.beforeFit(),this.fit(),this.afterFit(),this.afterUpdate()}configure(){let t=this.options.reverse,e,n;this.isHorizontal()?(e=this.left,n=this.right):(e=this.top,n=this.bottom,t=!t),this._startPixel=e,this._endPixel=n,this._reversePixels=t,this._length=n-e,this._alignToPixels=this.options.alignToPixels}afterUpdate(){ct(this.options.afterUpdate,[this])}beforeSetDimensions(){ct(this.options.beforeSetDimensions,[this])}setDimensions(){this.isHorizontal()?(this.width=this.maxWidth,this.left=0,this.right=this.width):(this.height=this.maxHeight,this.top=0,this.bottom=this.height),this.paddingLeft=0,this.paddingTop=0,this.paddingRight=0,this.paddingBottom=0}afterSetDimensions(){ct(this.options.afterSetDimensions,[this])}_callHooks(t){this.chart.notifyPlugins(t,this.getContext()),ct(this.options[t],[this])}beforeDataLimits(){this._callHooks("beforeDataLimits")}determineDataLimits(){}afterDataLimits(){this._callHooks("afterDataLimits")}beforeBuildTicks(){this._callHooks("beforeBuildTicks")}buildTicks(){return[]}afterBuildTicks(){this._callHooks("afterBuildTicks")}beforeTickToLabelConversion(){ct(this.options.beforeTickToLabelConversion,[this])}generateTickLabels(t){let e=this.options.ticks,n,i,o;for(n=0,i=t.length;n<i;n++)o=t[n],o.label=ct(e.callback,[o.value,n,t],this)}afterTickToLabelConversion(){ct(this.options.afterTickToLabelConversion,[this])}beforeCalculateLabelRotation(){ct(this.options.beforeCalculateLabelRotation,[this])}calculateLabelRotation(){let t=this.options,e=t.ticks,n=Pa(this.ticks.length,t.ticks.maxTicksLimit),i=e.minRotation||0,o=e.maxRotation,r=i,a,l,c;if(!this._isVisible()||!e.display||i>=o||n<=1||!this.isHorizontal()){this.labelRotation=i;return}let d=this._getLabelSizes(),h=d.widest.width,u=d.highest.height,f=vt(this.chart.width-h,0,this.maxWidth);a=t.offset?this.maxWidth/n:f/(n-1),h+6>a&&(a=f/(n-(t.offset?.5:1)),l=this.maxHeight-Xs(t.grid)-e.padding-Fa(t.title,this.chart.options.font),c=Math.sqrt(h*h+u*u),r=On(Math.min(Math.asin(vt((d.highest.height+6)/a,-1,1)),Math.asin(vt(l/c,-1,1))-Math.asin(vt(u/c,-1,1)))),r=Math.max(i,Math.min(o,r))),this.labelRotation=r}afterCalculateLabelRotation(){ct(this.options.afterCalculateLabelRotation,[this])}afterAutoSkip(){}beforeFit(){ct(this.options.beforeFit,[this])}fit(){let t={width:0,height:0},{chart:e,options:{ticks:n,title:i,grid:o}}=this,r=this._isVisible(),a=this.isHorizontal();if(r){let l=Fa(i,e.options.font);if(a?(t.width=this.maxWidth,t.height=Xs(o)+l):(t.height=this.maxHeight,t.width=Xs(o)+l),n.display&&this.ticks.length){let{first:c,last:d,widest:h,highest:u}=this._getLabelSizes(),f=n.padding*2,g=Ht(this.labelRotation),p=Math.cos(g),b=Math.sin(g);if(a){let m=n.mirror?0:b*h.width+p*u.height;t.height=Math.min(this.maxHeight,t.height+m+f)}else{let m=n.mirror?0:p*h.width+b*u.height;t.width=Math.min(this.maxWidth,t.width+m+f)}this._calculatePadding(c,d,b,p)}}this._handleMargins(),a?(this.width=this._length=e.width-this._margins.left-this._margins.right,this.height=t.height):(this.width=t.width,this.height=this._length=e.height-this._margins.top-this._margins.bottom)}_calculatePadding(t,e,n,i){let{ticks:{align:o,padding:r},position:a}=this.options,l=this.labelRotation!==0,c=a!=="top"&&this.axis==="x";if(this.isHorizontal()){let d=this.getPixelForTick(0)-this.left,h=this.right-this.getPixelForTick(this.ticks.length-1),u=0,f=0;l?c?(u=i*t.width,f=n*e.height):(u=n*t.height,f=i*e.width):o==="start"?f=e.width:o==="end"?u=t.width:o!=="inner"&&(u=t.width/2,f=e.width/2),this.paddingLeft=Math.max((u-d+r)*this.width/(this.width-d),0),this.paddingRight=Math.max((f-h+r)*this.width/(this.width-h),0)}else{let d=e.height/2,h=t.height/2;o==="start"?(d=0,h=t.height):o==="end"&&(d=e.height,h=0),this.paddingTop=d+r,this.paddingBottom=h+r}}_handleMargins(){this._margins&&(this._margins.left=Math.max(this.paddingLeft,this._margins.left),this._margins.top=Math.max(this.paddingTop,this._margins.top),this._margins.right=Math.max(this.paddingRight,this._margins.right),this._margins.bottom=Math.max(this.paddingBottom,this._margins.bottom))}afterFit(){ct(this.options.afterFit,[this])}isHorizontal(){let{axis:t,position:e}=this.options;return e==="top"||e==="bottom"||t==="x"}isFullSize(){return this.options.fullSize}_convertTicksToLabels(t){this.beforeTickToLabelConversion(),this.generateTickLabels(t);let e,n;for(e=0,n=t.length;e<n;e++)tt(t[e].label)&&(t.splice(e,1),n--,e--);this.afterTickToLabelConversion()}_getLabelSizes(){let t=this._labelSizes;if(!t){let e=this.options.ticks.sampleSize,n=this.ticks;e<n.length&&(n=Oa(n,e)),this._labelSizes=t=this._computeLabelSizes(n,n.length,this.options.ticks.maxTicksLimit)}return t}_computeLabelSizes(t,e,n){let{ctx:i,_longestTextCache:o}=this,r=[],a=[],l=Math.floor(e/Pa(e,n)),c=0,d=0,h,u,f,g,p,b,m,y,C,E,S;for(h=0;h<e;h+=l){if(g=t[h].label,p=this._resolveTickFontOptions(h),i.font=b=p.string,m=o[b]=o[b]||{data:{},gc:[]},y=p.lineHeight,C=E=0,!tt(g)&&!dt(g))C=Ws(i,m.data,m.gc,C,g),E=y;else if(dt(g))for(u=0,f=g.length;u<f;++u)S=g[u],!tt(S)&&!dt(S)&&(C=Ws(i,m.data,m.gc,C,S),E+=y);r.push(C),a.push(E),c=Math.max(C,c),d=Math.max(E,d)}bu(o,e);let x=r.indexOf(c),v=a.indexOf(d),_=w=>({width:r[w]||0,height:a[w]||0});return{first:_(0),last:_(e-1),widest:_(x),highest:_(v),widths:r,heights:a}}getLabelForValue(t){return t}getPixelForValue(t,e){return NaN}getValueForPixel(t){}getPixelForTick(t){let e=this.ticks;return t<0||t>e.length-1?null:this.getPixelForValue(e[t].value)}getPixelForDecimal(t){this._reversePixels&&(t=1-t);let e=this._startPixel+t*this._length;return Kr(this._alignToPixels?xe(this.chart,e,0):e)}getDecimalForPixel(t){let e=(t-this._startPixel)/this._length;return this._reversePixels?1-e:e}getBasePixel(){return this.getPixelForValue(this.getBaseValue())}getBaseValue(){let{min:t,max:e}=this;return t<0&&e<0?e:t>0&&e>0?t:0}getContext(t){let e=this.ticks||[];if(t>=0&&t<e.length){let n=e[t];return n.$context||(n.$context=yu(this.getContext(),t,n))}return this.$context||(this.$context=vu(this.chart.getContext(),this))}_tickSize(){let t=this.options.ticks,e=Ht(this.labelRotation),n=Math.abs(Math.cos(e)),i=Math.abs(Math.sin(e)),o=this._getLabelSizes(),r=t.autoSkipPadding||0,a=o?o.widest.width+r:0,l=o?o.highest.height+r:0;return this.isHorizontal()?l*n>a*i?a/n:l/i:l*i<a*n?l/n:a/i}_isVisible(){let t=this.options.display;return t!=="auto"?!!t:this.getMatchingVisibleMetas().length>0}_computeGridLineItems(t){let e=this.axis,n=this.chart,i=this.options,{grid:o,position:r,border:a}=i,l=o.offset,c=this.isHorizontal(),h=this.ticks.length+(l?1:0),u=Xs(o),f=[],g=a.setContext(this.getContext()),p=g.display?g.width:0,b=p/2,m=function(O){return xe(n,O,p)},y,C,E,S,x,v,_,w,D,k,T,A;if(r==="top")y=m(this.bottom),v=this.bottom-u,w=y-b,k=m(t.top)+b,A=t.bottom;else if(r==="bottom")y=m(this.top),k=t.top,A=m(t.bottom)-b,v=y+b,w=this.top+u;else if(r==="left")y=m(this.right),x=this.right-u,_=y-b,D=m(t.left)+b,T=t.right;else if(r==="right")y=m(this.left),D=t.left,T=m(t.right)-b,x=y+b,_=this.left+u;else if(e==="x"){if(r==="center")y=m((t.top+t.bottom)/2+.5);else if(et(r)){let O=Object.keys(r)[0],M=r[O];y=m(this.chart.scales[O].getPixelForValue(M))}k=t.top,A=t.bottom,v=y+b,w=v+u}else if(e==="y"){if(r==="center")y=m((t.left+t.right)/2);else if(et(r)){let O=Object.keys(r)[0],M=r[O];y=m(this.chart.scales[O].getPixelForValue(M))}x=y-b,_=x-u,D=t.left,T=t.right}let I=J(i.ticks.maxTicksLimit,h),V=Math.max(1,Math.ceil(h/I));for(C=0;C<h;C+=V){let O=this.getContext(C),M=o.setContext(O),j=a.setContext(O),F=M.lineWidth,Y=M.color,$=j.dash||[],R=j.dashOffset,W=M.tickWidth,K=M.tickColor,N=M.tickBorderDash||[],P=M.tickBorderDashOffset;E=mu(this,C,l),E!==void 0&&(S=xe(n,E,F),c?x=_=D=T=S:v=w=k=A=S,f.push({tx1:x,ty1:v,tx2:_,ty2:w,x1:D,y1:k,x2:T,y2:A,width:F,color:Y,borderDash:$,borderDashOffset:R,tickWidth:W,tickColor:K,tickBorderDash:N,tickBorderDashOffset:P}))}return this._ticksLength=h,this._borderValue=y,f}_computeLabelItems(t){let e=this.axis,n=this.options,{position:i,ticks:o}=n,r=this.isHorizontal(),a=this.ticks,{align:l,crossAlign:c,padding:d,mirror:h}=o,u=Xs(n.grid),f=u+d,g=h?-d:f,p=-Ht(this.labelRotation),b=[],m,y,C,E,S,x,v,_,w,D,k,T,A="middle";if(i==="top")x=this.bottom-g,v=this._getXAxisLabelAlignment();else if(i==="bottom")x=this.top+g,v=this._getXAxisLabelAlignment();else if(i==="left"){let V=this._getYAxisLabelAlignment(u);v=V.textAlign,S=V.x}else if(i==="right"){let V=this._getYAxisLabelAlignment(u);v=V.textAlign,S=V.x}else if(e==="x"){if(i==="center")x=(t.top+t.bottom)/2+f;else if(et(i)){let V=Object.keys(i)[0],O=i[V];x=this.chart.scales[V].getPixelForValue(O)+f}v=this._getXAxisLabelAlignment()}else if(e==="y"){if(i==="center")S=(t.left+t.right)/2-f;else if(et(i)){let V=Object.keys(i)[0],O=i[V];S=this.chart.scales[V].getPixelForValue(O)}v=this._getYAxisLabelAlignment(u).textAlign}e==="y"&&(l==="start"?A="top":l==="end"&&(A="bottom"));let I=this._getLabelSizes();for(m=0,y=a.length;m<y;++m){C=a[m],E=C.label;let V=o.setContext(this.getContext(m));_=this.getPixelForTick(m)+o.labelOffset,w=this._resolveTickFontOptions(m),D=w.lineHeight,k=dt(E)?E.length:1;let O=k/2,M=V.color,j=V.textStrokeColor,F=V.textStrokeWidth,Y=v;r?(S=_,v==="inner"&&(m===y-1?Y=this.options.reverse?"left":"right":m===0?Y=this.options.reverse?"right":"left":Y="center"),i==="top"?c==="near"||p!==0?T=-k*D+D/2:c==="center"?T=-I.highest.height/2-O*D+D:T=-I.highest.height+D/2:c==="near"||p!==0?T=D/2:c==="center"?T=I.highest.height/2-O*D:T=I.highest.height-k*D,h&&(T*=-1),p!==0&&!V.showLabelBackdrop&&(S+=D/2*Math.sin(p))):(x=_,T=(1-k)*D/2);let $;if(V.showLabelBackdrop){let R=St(V.backdropPadding),W=I.heights[m],K=I.widths[m],N=T-R.top,P=0-R.left;switch(A){case"middle":N-=W/2;break;case"bottom":N-=W;break}switch(v){case"center":P-=K/2;break;case"right":P-=K;break;case"inner":m===y-1?P-=K:m>0&&(P-=K/2);break}$={left:P,top:N,width:K+R.width,height:W+R.height,color:V.backdropColor}}b.push({label:E,font:w,textOffset:T,options:{rotation:p,color:M,strokeColor:j,strokeWidth:F,textAlign:Y,textBaseline:A,translation:[S,x],backdrop:$}})}return b}_getXAxisLabelAlignment(){let{position:t,ticks:e}=this.options;if(-Ht(this.labelRotation))return t==="top"?"left":"right";let i="center";return e.align==="start"?i="left":e.align==="end"?i="right":e.align==="inner"&&(i="inner"),i}_getYAxisLabelAlignment(t){let{position:e,ticks:{crossAlign:n,mirror:i,padding:o}}=this.options,r=this._getLabelSizes(),a=t+o,l=r.widest.width,c,d;return e==="left"?i?(d=this.right+o,n==="near"?c="left":n==="center"?(c="center",d+=l/2):(c="right",d+=l)):(d=this.right-a,n==="near"?c="right":n==="center"?(c="center",d-=l/2):(c="left",d=this.left)):e==="right"?i?(d=this.left+o,n==="near"?c="right":n==="center"?(c="center",d-=l/2):(c="left",d-=l)):(d=this.left+a,n==="near"?c="left":n==="center"?(c="center",d+=l/2):(c="right",d=this.right)):c="right",{textAlign:c,x:d}}_computeLabelArea(){if(this.options.ticks.mirror)return;let t=this.chart,e=this.options.position;if(e==="left"||e==="right")return{top:0,left:this.left,bottom:t.height,right:this.right};if(e==="top"||e==="bottom")return{top:this.top,left:0,bottom:this.bottom,right:t.width}}drawBackground(){let{ctx:t,options:{backgroundColor:e},left:n,top:i,width:o,height:r}=this;e&&(t.save(),t.fillStyle=e,t.fillRect(n,i,o,r),t.restore())}getLineWidthForValue(t){let e=this.options.grid;if(!this._isVisible()||!e.display)return 0;let i=this.ticks.findIndex(o=>o.value===t);return i>=0?e.setContext(this.getContext(i)).lineWidth:0}drawGrid(t){let e=this.options.grid,n=this.ctx,i=this._gridLineItems||(this._gridLineItems=this._computeGridLineItems(t)),o,r,a=(l,c,d)=>{!d.width||!d.color||(n.save(),n.lineWidth=d.width,n.strokeStyle=d.color,n.setLineDash(d.borderDash||[]),n.lineDashOffset=d.borderDashOffset,n.beginPath(),n.moveTo(l.x,l.y),n.lineTo(c.x,c.y),n.stroke(),n.restore())};if(e.display)for(o=0,r=i.length;o<r;++o){let l=i[o];e.drawOnChartArea&&a({x:l.x1,y:l.y1},{x:l.x2,y:l.y2},l),e.drawTicks&&a({x:l.tx1,y:l.ty1},{x:l.tx2,y:l.ty2},{color:l.tickColor,width:l.tickWidth,borderDash:l.tickBorderDash,borderDashOffset:l.tickBorderDashOffset})}}drawBorder(){let{chart:t,ctx:e,options:{border:n,grid:i}}=this,o=n.setContext(this.getContext()),r=n.display?o.width:0;if(!r)return;let a=i.setContext(this.getContext(0)).lineWidth,l=this._borderValue,c,d,h,u;this.isHorizontal()?(c=xe(t,this.left,r)-r/2,d=xe(t,this.right,a)+a/2,h=u=l):(h=xe(t,this.top,r)-r/2,u=xe(t,this.bottom,a)+a/2,c=d=l),e.save(),e.lineWidth=o.width,e.strokeStyle=o.color,e.beginPath(),e.moveTo(c,h),e.lineTo(d,u),e.stroke(),e.restore()}drawLabels(t){if(!this.options.ticks.display)return;let n=this.ctx,i=this._computeLabelArea();i&&Us(n,i);let o=this.getLabelItems(t);for(let r of o){let a=r.options,l=r.font,c=r.label,d=r.textOffset;Ce(n,c,0,d,l,a)}i&&Ys(n)}drawTitle(){let{ctx:t,options:{position:e,title:n,reverse:i}}=this;if(!n.display)return;let o=bt(n.font),r=St(n.padding),a=n.align,l=o.lineHeight/2;e==="bottom"||e==="center"||et(e)?(l+=r.bottom,dt(n.text)&&(l+=o.lineHeight*(n.text.length-1))):l+=r.top;let{titleX:c,titleY:d,maxWidth:h,rotation:u}=Cu(this,l,e,a);Ce(t,n.text,0,0,o,{color:n.color,maxWidth:h,rotation:u,textAlign:xu(a,e,i),textBaseline:"middle",translation:[c,d]})}draw(t){this._isVisible()&&(this.drawBackground(),this.drawGrid(t),this.drawBorder(),this.drawTitle(),this.drawLabels(t))}_layers(){let t=this.options,e=t.ticks&&t.ticks.z||0,n=J(t.grid&&t.grid.z,-1),i=J(t.border&&t.border.z,0);return!this._isVisible()||this.draw!==s.prototype.draw?[{z:e,draw:o=>{this.draw(o)}}]:[{z:n,draw:o=>{this.drawBackground(),this.drawGrid(o),this.drawTitle()}},{z:i,draw:()=>{this.drawBorder()}},{z:e,draw:o=>{this.drawLabels(o)}}]}getMatchingVisibleMetas(t){let e=this.chart.getSortedVisibleDatasetMetas(),n=this.axis+"AxisID",i=[],o,r;for(o=0,r=e.length;o<r;++o){let a=e[o];a[n]===this.id&&(!t||a.type===t)&&i.push(a)}return i}_resolveTickFontOptions(t){let e=this.options.ticks.setContext(this.getContext(t));return bt(e.font)}_maxDigits(){let t=this._resolveTickFontOptions(0).lineHeight;return(this.isHorizontal()?this.width:this.height)/t}},vs=class{constructor(t,e,n){this.type=t,this.scope=e,this.override=n,this.items=Object.create(null)}isForType(t){return Object.prototype.isPrototypeOf.call(this.type.prototype,t.prototype)}register(t){let e=Object.getPrototypeOf(t),n;Eu(e)&&(n=this.register(e));let i=this.items,o=t.id,r=this.scope+"."+o;if(!o)throw new Error("class does not have id: "+t);return o in i||(i[o]=t,_u(t,r,n),this.override&&ut.override(t.id,t.overrides)),r}get(t){return this.items[t]}unregister(t){let e=this.items,n=t.id,i=this.scope;n in e&&delete e[n],i&&n in ut[i]&&(delete ut[i][n],this.override&&delete ye[n])}};ko=class{constructor(){this.controllers=new vs(At,"datasets",!0),this.elements=new vs(Pt,"elements"),this.plugins=new vs(Object,"plugins"),this.scales=new vs(Te,"scales"),this._typedRegistries=[this.controllers,this.scales,this.elements]}add(...t){this._each("register",t)}remove(...t){this._each("unregister",t)}addControllers(...t){this._each("register",t,this.controllers)}addElements(...t){this._each("register",t,this.elements)}addPlugins(...t){this._each("register",t,this.plugins)}addScales(...t){this._each("register",t,this.scales)}getController(t){return this._get(t,this.controllers,"controller")}getElement(t){return this._get(t,this.elements,"element")}getPlugin(t){return this._get(t,this.plugins,"plugin")}getScale(t){return this._get(t,this.scales,"scale")}removeControllers(...t){this._each("unregister",t,this.controllers)}removeElements(...t){this._each("unregister",t,this.elements)}removePlugins(...t){this._each("unregister",t,this.plugins)}removeScales(...t){this._each("unregister",t,this.scales)}_each(t,e,n){[...e].forEach(i=>{let o=n||this._getRegistryForType(i);n||o.isForType(i)||o===this.plugins&&i.id?this._exec(t,o,i):rt(i,r=>{let a=n||this._getRegistryForType(r);this._exec(t,a,r)})})}_exec(t,e,n){let i=Pn(t);ct(n["before"+i],[],n),e[t](n),ct(n["after"+i],[],n)}_getRegistryForType(t){for(let e=0;e<this._typedRegistries.length;e++){let n=this._typedRegistries[e];if(n.isForType(t))return n}return this.plugins}_get(t,e,n){let i=e.get(t);if(i===void 0)throw new Error('"'+t+'" is not a registered '+n+".");return i}},Yt=new ko,wo=class{constructor(){this._init=void 0}notify(t,e,n,i){if(e==="beforeInit"&&(this._init=this._createDescriptors(t,!0),this._notify(this._init,t,"install")),this._init===void 0)return;let o=i?this._descriptors(t).filter(i):this._descriptors(t),r=this._notify(o,t,e,n);return e==="afterDestroy"&&(this._notify(o,t,"stop"),this._notify(this._init,t,"uninstall"),this._init=void 0),r}_notify(t,e,n,i){i=i||{};for(let o of t){let r=o.plugin,a=r[n],l=[e,i,o.options];if(ct(a,l,r)===!1&&i.cancelable)return!1}return!0}invalidate(){tt(this._cache)||(this._oldCache=this._cache,this._cache=void 0)}_descriptors(t){if(this._cache)return this._cache;let e=this._cache=this._createDescriptors(t);return this._notifyStateChanges(t),e}_createDescriptors(t,e){let n=t&&t.config,i=J(n.options&&n.options.plugins,{}),o=ku(n);return i===!1&&!e?[]:Mu(t,o,i,e)}_notifyStateChanges(t){let e=this._oldCache||[],n=this._cache,i=(o,r)=>o.filter(a=>!r.some(l=>a.plugin.id===l.plugin.id));this._notify(i(e,n),t,"stop"),this._notify(i(n,e),t,"start")}};Ba=new Map,Dl=new Set;Qs=(s,t,e)=>{let n=ce(t,e);n!==void 0&&s.add(n)},To=class{constructor(t){this._config=Ou(t),this._scopeCache=new Map,this._resolverCache=new Map}get platform(){return this._config.platform}get type(){return this._config.type}set type(t){this._config.type=t}get data(){return this._config.data}set data(t){this._config.data=Ml(t)}get options(){return this._config.options}set options(t){this._config.options=t}get plugins(){return this._config.plugins}update(){let t=this._config;this.clearCache(),wl(t)}clearCache(){this._scopeCache.clear(),this._resolverCache.clear()}datasetScopeKeys(t){return Yn(t,()=>[[`datasets.${t}`,""]])}datasetAnimationScopeKeys(t,e){return Yn(`${t}.transition.${e}`,()=>[[`datasets.${t}.transitions.${e}`,`transitions.${e}`],[`datasets.${t}`,""]])}datasetElementScopeKeys(t,e){return Yn(`${t}-${e}`,()=>[[`datasets.${t}.elements.${e}`,`datasets.${t}`,`elements.${e}`,""]])}pluginScopeKeys(t){let e=t.id,n=this.type;return Yn(`${n}-plugin-${e}`,()=>[[`plugins.${e}`,...t.additionalOptionScopes||[]]])}_cachedScopes(t,e){let n=this._scopeCache,i=n.get(t);return(!i||e)&&(i=new Map,n.set(t,i)),i}getOptionScopes(t,e,n){let{options:i,type:o}=this,r=this._cachedScopes(t,n),a=r.get(e);if(a)return a;let l=new Set;e.forEach(d=>{t&&(l.add(t),d.forEach(h=>Qs(l,t,h))),d.forEach(h=>Qs(l,i,h)),d.forEach(h=>Qs(l,ye[o]||{},h)),d.forEach(h=>Qs(l,ut,h)),d.forEach(h=>Qs(l,Vn,h))});let c=Array.from(l);return c.length===0&&c.push(Object.create(null)),Dl.has(e)&&r.set(e,c),c}chartOptionScopes(){let{options:t,type:e}=this;return[t,ye[e]||{},ut.datasets[e]||{},{type:e},ut,Vn]}resolveNamedOptions(t,e,n,i=[""]){let o={$shared:!0},{resolver:r,subPrefixes:a}=Na(this._resolverCache,t,i),l=r;if(Iu(r,e)){o.$shared=!1,n=ae(n)?n():n;let c=this.createResolver(t,n,a);l=Pe(r,n,c)}for(let c of e)o[c]=l[c];return o}createResolver(t,e,n=[""],i){let{resolver:o}=Na(this._resolverCache,t,n);return et(e)?Pe(o,e,void 0,i):o}};Fu=s=>et(s)&&Object.getOwnPropertyNames(s).some(t=>ae(s[t]));Vu="4.5.1",Bu=["top","bottom","left","right","chartArea"];Qn={},Wa=s=>{let t=Tl(s);return Object.values(Qn).filter(e=>e.canvas===t).pop()};ne=class{static register(...t){Yt.add(...t),ja()}static unregister(...t){Yt.remove(...t),ja()}constructor(t,e){let n=this.config=new To(e),i=Tl(t),o=Wa(i);if(o)throw new Error("Canvas is already in use. Chart with ID '"+o.id+"' must be destroyed before the canvas with ID '"+o.canvas.id+"' can be reused.");let r=n.createResolver(n.chartOptionScopes(),this.getContext());this.platform=new(n.platform||kl(i)),this.platform.updateConfig(n);let a=this.platform.acquireContext(i,r.aspectRatio),l=a&&a.canvas,c=l&&l.height,d=l&&l.width;if(this.id=zr(),this.ctx=a,this.canvas=l,this.width=d,this.height=c,this._options=r,this._aspectRatio=this.aspectRatio,this._layers=[],this._metasets=[],this._stacks=void 0,this.boxes=[],this.currentDevicePixelRatio=void 0,this.chartArea=void 0,this._active=[],this._lastEvent=void 0,this._listeners={},this._responsiveListeners=void 0,this._sortedMetasets=[],this.scales={},this._plugins=new wo,this.$proxies={},this._hiddenIndices={},this.attached=!1,this._animationsDisabled=void 0,this.$context=void 0,this._doResize=Zr(h=>this.update(h),r.resizeDelay||0),this._dataChanges=[],Qn[this.id]=this,!a||!l){console.error("Failed to create chart: can't acquire context from the given item");return}se.listen(this,"complete",Ha),se.listen(this,"progress",Nu),this._initialize(),this.attached&&this.update()}get aspectRatio(){let{options:{aspectRatio:t,maintainAspectRatio:e},width:n,height:i,_aspectRatio:o}=this;return tt(t)?e&&o?o:i?n/i:null:t}get data(){return this.config.data}set data(t){this.config.data=t}get options(){return this._options}set options(t){this.config.options=t}get registry(){return Yt}_initialize(){return this.notifyPlugins("beforeInit"),this.options.responsive?this.resize():io(this,this.options.devicePixelRatio),this.bindEvents(),this.notifyPlugins("afterInit"),this}clear(){return Qi(this.canvas,this.ctx),this}stop(){return se.stop(this),this}resize(t,e){se.running(this)?this._resizeBeforeDraw={width:t,height:e}:this._resize(t,e)}_resize(t,e){let n=this.options,i=this.canvas,o=n.maintainAspectRatio&&this.aspectRatio,r=this.platform.getMaximumSize(i,t,e,o),a=n.devicePixelRatio||this.platform.getDevicePixelRatio(),l=this.width?"resize":"attach";this.width=r.width,this.height=r.height,this._aspectRatio=this.aspectRatio,io(this,a,!0)&&(this.notifyPlugins("resize",{size:r}),ct(n.onResize,[this,r],this),this.attached&&this._doResize(l)&&this.render())}ensureScalesHaveIDs(){let e=this.options.scales||{};rt(e,(n,i)=>{n.id=i})}buildOrUpdateScales(){let t=this.options,e=t.scales,n=this.scales,i=Object.keys(n).reduce((r,a)=>(r[a]=!1,r),{}),o=[];e&&(o=o.concat(Object.keys(e).map(r=>{let a=e[r],l=Do(r,a),c=l==="r",d=l==="x";return{options:a,dposition:c?"chartArea":d?"bottom":"left",dtype:c?"radialLinear":d?"category":"linear"}}))),rt(o,r=>{let a=r.options,l=a.id,c=Do(l,a),d=J(a.type,r.dtype);(a.position===void 0||$a(a.position,c)!==$a(r.dposition))&&(a.position=r.dposition),i[l]=!0;let h=null;if(l in n&&n[l].type===d)h=n[l];else{let u=Yt.getScale(d);h=new u({id:l,type:d,ctx:this.ctx,chart:this}),n[h.id]=h}h.init(a,t)}),rt(i,(r,a)=>{r||delete n[a]}),rt(n,r=>{Et.configure(this,r,r.options),Et.addBox(this,r)})}_updateMetasets(){let t=this._metasets,e=this.data.datasets.length,n=t.length;if(t.sort((i,o)=>i.index-o.index),n>e){for(let i=e;i<n;++i)this._destroyDatasetMeta(i);t.splice(e,n-e)}this._sortedMetasets=t.slice(0).sort(za("order","index"))}_removeUnreferencedMetasets(){let{_metasets:t,data:{datasets:e}}=this;t.length>e.length&&delete this._stacks,t.forEach((n,i)=>{e.filter(o=>o===n._dataset).length===0&&this._destroyDatasetMeta(i)})}buildOrUpdateControllers(){let t=[],e=this.data.datasets,n,i;for(this._removeUnreferencedMetasets(),n=0,i=e.length;n<i;n++){let o=e[n],r=this.getDatasetMeta(n),a=o.type||this.config.type;if(r.type&&r.type!==a&&(this._destroyDatasetMeta(n),r=this.getDatasetMeta(n)),r.type=a,r.indexAxis=o.indexAxis||Mo(a,this.options),r.order=o.order||0,r.index=n,r.label=""+o.label,r.visible=this.isDatasetVisible(n),r.controller)r.controller.updateIndex(n),r.controller.linkScales();else{let l=Yt.getController(a),{datasetElementType:c,dataElementType:d}=ut.datasets[a];Object.assign(l,{dataElementType:Yt.getElement(d),datasetElementType:c&&Yt.getElement(c)}),r.controller=new l(this,n),t.push(r.controller)}}return this._updateMetasets(),t}_resetElements(){rt(this.data.datasets,(t,e)=>{this.getDatasetMeta(e).controller.reset()},this)}reset(){this._resetElements(),this.notifyPlugins("reset")}update(t){let e=this.config;e.update();let n=this._options=e.createResolver(e.chartOptionScopes(),this.getContext()),i=this._animationsDisabled=!n.animation;if(this._updateScales(),this._checkEventBindings(),this._updateHiddenIndices(),this._plugins.invalidate(),this.notifyPlugins("beforeUpdate",{mode:t,cancelable:!0})===!1)return;let o=this.buildOrUpdateControllers();this.notifyPlugins("beforeElementsUpdate");let r=0;for(let c=0,d=this.data.datasets.length;c<d;c++){let{controller:h}=this.getDatasetMeta(c),u=!i&&o.indexOf(h)===-1;h.buildOrUpdateElements(u),r=Math.max(+h.getMaxOverflow(),r)}r=this._minPadding=n.layout.autoPadding?r:0,this._updateLayout(r),i||rt(o,c=>{c.reset()}),this._updateDatasets(t),this.notifyPlugins("afterUpdate",{mode:t}),this._layers.sort(za("z","_idx"));let{_active:a,_lastEvent:l}=this;l?this._eventHandler(l,!0):a.length&&this._updateHoverStyles(a,a,!0),this.render()}_updateScales(){rt(this.scales,t=>{Et.removeBox(this,t)}),this.ensureScalesHaveIDs(),this.buildOrUpdateScales()}_checkEventBindings(){let t=this.options,e=new Set(Object.keys(this._listeners)),n=new Set(t.events);(!Bi(e,n)||!!this._responsiveListeners!==t.responsive)&&(this.unbindEvents(),this.bindEvents())}_updateHiddenIndices(){let{_hiddenIndices:t}=this,e=this._getUniformDataChanges()||[];for(let{method:n,start:i,count:o}of e){let r=n==="_removeElements"?-o:o;$u(t,i,r)}}_getUniformDataChanges(){let t=this._dataChanges;if(!t||!t.length)return;this._dataChanges=[];let e=this.data.datasets.length,n=o=>new Set(t.filter(r=>r[0]===o).map((r,a)=>a+","+r.splice(1).join(","))),i=n(0);for(let o=1;o<e;o++)if(!Bi(i,n(o)))return;return Array.from(i).map(o=>o.split(",")).map(o=>({method:o[1],start:+o[2],count:+o[3]}))}_updateLayout(t){if(this.notifyPlugins("beforeLayout",{cancelable:!0})===!1)return;Et.update(this,this.width,this.height,t);let e=this.chartArea,n=e.width<=0||e.height<=0;this._layers=[],rt(this.boxes,i=>{n&&i.position==="chartArea"||(i.configure&&i.configure(),this._layers.push(...i._layers()))},this),this._layers.forEach((i,o)=>{i._idx=o}),this.notifyPlugins("afterLayout")}_updateDatasets(t){if(this.notifyPlugins("beforeDatasetsUpdate",{mode:t,cancelable:!0})!==!1){for(let e=0,n=this.data.datasets.length;e<n;++e)this.getDatasetMeta(e).controller.configure();for(let e=0,n=this.data.datasets.length;e<n;++e)this._updateDataset(e,ae(t)?t({datasetIndex:e}):t);this.notifyPlugins("afterDatasetsUpdate",{mode:t})}}_updateDataset(t,e){let n=this.getDatasetMeta(t),i={meta:n,index:t,mode:e,cancelable:!0};this.notifyPlugins("beforeDatasetUpdate",i)!==!1&&(n.controller._update(e),i.cancelable=!1,this.notifyPlugins("afterDatasetUpdate",i))}render(){this.notifyPlugins("beforeRender",{cancelable:!0})!==!1&&(se.has(this)?this.attached&&!se.running(this)&&se.start(this):(this.draw(),Ha({chart:this})))}draw(){let t;if(this._resizeBeforeDraw){let{width:n,height:i}=this._resizeBeforeDraw;this._resizeBeforeDraw=null,this._resize(n,i)}if(this.clear(),this.width<=0||this.height<=0||this.notifyPlugins("beforeDraw",{cancelable:!0})===!1)return;let e=this._layers;for(t=0;t<e.length&&e[t].z<=0;++t)e[t].draw(this.chartArea);for(this._drawDatasets();t<e.length;++t)e[t].draw(this.chartArea);this.notifyPlugins("afterDraw")}_getSortedDatasetMetas(t){let e=this._sortedMetasets,n=[],i,o;for(i=0,o=e.length;i<o;++i){let r=e[i];(!t||r.visible)&&n.push(r)}return n}getSortedVisibleDatasetMetas(){return this._getSortedDatasetMetas(!0)}_drawDatasets(){if(this.notifyPlugins("beforeDatasetsDraw",{cancelable:!0})===!1)return;let t=this.getSortedVisibleDatasetMetas();for(let e=t.length-1;e>=0;--e)this._drawDataset(t[e]);this.notifyPlugins("afterDatasetsDraw")}_drawDataset(t){let e=this.ctx,n={meta:t,index:t.index,cancelable:!0},i=ho(this,t);this.notifyPlugins("beforeDatasetDraw",n)!==!1&&(i&&Us(e,i),t.controller.draw(),i&&Ys(e),n.cancelable=!1,this.notifyPlugins("afterDatasetDraw",n))}isPointInArea(t){return Zt(t,this.chartArea,this._minPadding)}getElementsAtEventForMode(t,e,n,i){let o=xl.modes[e];return typeof o=="function"?o(this,t,n,i):[]}getDatasetMeta(t){let e=this.data.datasets[t],n=this._metasets,i=n.filter(o=>o&&o._dataset===e).pop();return i||(i={type:null,data:[],dataset:null,controller:null,hidden:null,xAxisID:null,yAxisID:null,order:e&&e.order||0,index:t,_dataset:e,_parsed:[],_sorted:!1},n.push(i)),i}getContext(){return this.$context||(this.$context=de(null,{chart:this,type:"chart"}))}getVisibleDatasetCount(){return this.getSortedVisibleDatasetMetas().length}isDatasetVisible(t){let e=this.data.datasets[t];if(!e)return!1;let n=this.getDatasetMeta(t);return typeof n.hidden=="boolean"?!n.hidden:!e.hidden}setDatasetVisibility(t,e){let n=this.getDatasetMeta(t);n.hidden=!e}toggleDataVisibility(t){this._hiddenIndices[t]=!this._hiddenIndices[t]}getDataVisibility(t){return!this._hiddenIndices[t]}_updateVisibility(t,e,n){let i=n?"show":"hide",o=this.getDatasetMeta(t),r=o.controller._resolveAnimations(void 0,i);cs(e)?(o.data[e].hidden=!n,this.update()):(this.setDatasetVisibility(t,n),r.update(o,{visible:n}),this.update(a=>a.datasetIndex===t?i:void 0))}hide(t,e){this._updateVisibility(t,e,!1)}show(t,e){this._updateVisibility(t,e,!0)}_destroyDatasetMeta(t){let e=this._metasets[t];e&&e.controller&&e.controller._destroy(),delete this._metasets[t]}_stop(){let t,e;for(this.stop(),se.remove(this),t=0,e=this.data.datasets.length;t<e;++t)this._destroyDatasetMeta(t)}destroy(){this.notifyPlugins("beforeDestroy");let{canvas:t,ctx:e}=this;this._stop(),this.config.clearCache(),t&&(this.unbindEvents(),Qi(t,e),this.platform.releaseContext(e),this.canvas=null,this.ctx=null),delete Qn[this.id],this.notifyPlugins("afterDestroy")}toBase64Image(...t){return this.canvas.toDataURL(...t)}bindEvents(){this.bindUserEvents(),this.options.responsive?this.bindResponsiveEvents():this.attached=!0}bindUserEvents(){let t=this._listeners,e=this.platform,n=(o,r)=>{e.addEventListener(this,o,r),t[o]=r},i=(o,r,a)=>{o.offsetX=r,o.offsetY=a,this._eventHandler(o)};rt(this.options.events,o=>n(o,i))}bindResponsiveEvents(){this._responsiveListeners||(this._responsiveListeners={});let t=this._responsiveListeners,e=this.platform,n=(l,c)=>{e.addEventListener(this,l,c),t[l]=c},i=(l,c)=>{t[l]&&(e.removeEventListener(this,l,c),delete t[l])},o=(l,c)=>{this.canvas&&this.resize(l,c)},r,a=()=>{i("attach",a),this.attached=!0,this.resize(),n("resize",o),n("detach",r)};r=()=>{this.attached=!1,i("resize",o),this._stop(),this._resize(0,0),n("attach",a)},e.isAttached(this.canvas)?a():r()}unbindEvents(){rt(this._listeners,(t,e)=>{this.platform.removeEventListener(this,e,t)}),this._listeners={},rt(this._responsiveListeners,(t,e)=>{this.platform.removeEventListener(this,e,t)}),this._responsiveListeners=void 0}updateHoverStyle(t,e,n){let i=n?"set":"remove",o,r,a,l;for(e==="dataset"&&(o=this.getDatasetMeta(t[0].datasetIndex),o.controller["_"+i+"DatasetHoverStyle"]()),a=0,l=t.length;a<l;++a){r=t[a];let c=r&&this.getDatasetMeta(r.datasetIndex).controller;c&&c[i+"HoverStyle"](r.element,r.datasetIndex,r.index)}}getActiveElements(){return this._active||[]}setActiveElements(t){let e=this._active||[],n=t.map(({datasetIndex:o,index:r})=>{let a=this.getDatasetMeta(o);if(!a)throw new Error("No dataset found at index "+o);return{datasetIndex:o,element:a.data[r],index:r}});!js(n,e)&&(this._active=n,this._lastEvent=null,this._updateHoverStyles(n,e))}notifyPlugins(t,e,n){return this._plugins.notify(this,t,e,n)}isPluginEnabled(t){return this._plugins._cache.filter(e=>e.plugin.id===t).length===1}_updateHoverStyles(t,e,n){let i=this.options.hover,o=(l,c)=>l.filter(d=>!c.some(h=>d.datasetIndex===h.datasetIndex&&d.index===h.index)),r=o(e,t),a=n?t:o(t,e);r.length&&this.updateHoverStyle(r,i.mode,!1),a.length&&i.mode&&this.updateHoverStyle(a,i.mode,!0)}_eventHandler(t,e){let n={event:t,replay:e,cancelable:!0,inChartArea:this.isPointInArea(t)},i=r=>(r.options.events||this.options.events).includes(t.native.type);if(this.notifyPlugins("beforeEvent",n,i)===!1)return;let o=this._handleEvent(t,e,n.inChartArea);return n.cancelable=!1,this.notifyPlugins("afterEvent",n,i),(o||n.changed)&&this.render(),this}_handleEvent(t,e,n){let{_active:i=[],options:o}=this,r=e,a=this._getActiveElements(t,i,n,r),l=jr(t),c=zu(t,this._lastEvent,n,l);n&&(this._lastEvent=null,ct(o.onHover,[t,a,this],this),l&&ct(o.onClick,[t,a,this],this));let d=!js(a,i);return(d||e)&&(this._active=a,this._updateHoverStyles(a,i,e)),this._lastEvent=c,d}_getActiveElements(t,e,n,i){if(t.type==="mouseout")return[];if(!n)return e;let o=this.options.hover;return this.getElementsAtEventForMode(t,o.mode,o,i)}};G(ne,"defaults",ut),G(ne,"instances",Qn),G(ne,"overrides",ye),G(ne,"registry",Yt),G(ne,"version",Vu),G(ne,"getChart",Wa);Ee=class extends Pt{constructor(e){super();G(this,"circumference");G(this,"endAngle");G(this,"fullCircles");G(this,"innerRadius");G(this,"outerRadius");G(this,"pixelMargin");G(this,"startAngle");this.options=void 0,this.circumference=void 0,this.startAngle=void 0,this.endAngle=void 0,this.innerRadius=void 0,this.outerRadius=void 0,this.pixelMargin=0,this.fullCircles=0,e&&Object.assign(this,e)}inRange(e,n,i){let o=this.getProps(["x","y"],i),{angle:r,distance:a}=Hi(o,{x:e,y:n}),{startAngle:l,endAngle:c,innerRadius:d,outerRadius:h,circumference:u}=this.getProps(["startAngle","endAngle","innerRadius","outerRadius","circumference"],i),f=(this.options.spacing+this.options.borderWidth)/2,g=J(u,c-l),p=hs(r,l,c)&&l!==c,b=g>=ht||p,m=te(a,d+f,h+f);return b&&m}getCenterPoint(e){let{x:n,y:i,startAngle:o,endAngle:r,innerRadius:a,outerRadius:l}=this.getProps(["x","y","startAngle","endAngle","innerRadius","outerRadius"],e),{offset:c,spacing:d}=this.options,h=(o+r)/2,u=(a+l+d+c)/2;return{x:n+Math.cos(h)*u,y:i+Math.sin(h)*u}}tooltipPosition(e){return this.getCenterPoint(e)}draw(e){let{options:n,circumference:i}=this,o=(n.offset||0)/4,r=(n.spacing||0)/2,a=n.circular;if(this.pixelMargin=n.borderAlign==="inner"?.33:0,this.fullCircles=i>ht?Math.floor(i/ht):0,i===0||this.innerRadius<0||this.outerRadius<0)return;e.save();let l=(this.startAngle+this.endAngle)/2;e.translate(Math.cos(l)*o,Math.sin(l)*o);let c=1-Math.sin(Math.min(nt,i||0)),d=o*c;e.fillStyle=n.backgroundColor,e.strokeStyle=n.borderColor,Yu(e,this,d,r,a),Ku(e,this,d,r,a),e.restore()}};G(Ee,"id","arc"),G(Ee,"defaults",{borderAlign:"center",borderColor:"#fff",borderDash:[],borderDashOffset:0,borderJoinStyle:void 0,borderRadius:0,borderWidth:2,offset:0,spacing:0,angle:void 0,circular:!0,selfJoin:!1}),G(Ee,"defaultRoutes",{backgroundColor:"backgroundColor"}),G(Ee,"descriptors",{_scriptable:!0,_indexable:e=>e!=="borderDash"});ef=typeof Path2D=="function";Kt=class extends Pt{constructor(t){super(),this.animated=!0,this.options=void 0,this._chart=void 0,this._loop=void 0,this._fullLoop=void 0,this._path=void 0,this._points=void 0,this._segments=void 0,this._decimated=!1,this._pointsUpdated=!1,this._datasetIndex=void 0,t&&Object.assign(this,t)}updateControlPoints(t,e){let n=this.options;if((n.tension||n.cubicInterpolationMode==="monotone")&&!n.stepped&&!this._pointsUpdated){let i=n.spanGaps?this._loop:this._fullLoop;ca(this._points,n,t,i,e),this._pointsUpdated=!0}}set points(t){this._points=t,delete this._segments,delete this._path,this._pointsUpdated=!1}get points(){return this._points}get segments(){return this._segments||(this._segments=pa(this,this.options.segment))}first(){let t=this.segments,e=this.points;return t.length&&e[t[0].start]}last(){let t=this.segments,e=this.points,n=t.length;return n&&e[t[n-1].end]}interpolate(t,e){let n=this.options,i=t[e],o=this.points,r=co(this,{property:e,start:i,end:i});if(!r.length)return;let a=[],l=Zu(n),c,d;for(c=0,d=r.length;c<d;++c){let{start:h,end:u}=r[c],f=o[h],g=o[u];if(f===g){a.push(f);continue}let p=Math.abs((i-f[e])/(g[e]-f[e])),b=l(f,g,p,n.stepped);b[e]=t[e],a.push(b)}return a.length===1?a[0]:a}pathSegment(t,e,n){return Lo(this)(t,this,e,n)}path(t,e,n){let i=this.segments,o=Lo(this),r=this._loop;e=e||0,n=n||this.points.length-e;for(let a of i)r&=o(t,this,a,{start:e,end:e+n-1});return!!r}draw(t,e,n,i){let o=this.options||{};(this.points||[]).length&&o.borderWidth&&(t.save(),sf(t,this,n,i),t.restore()),this.animated&&(this._pointsUpdated=!1,this._path=void 0)}};G(Kt,"id","line"),G(Kt,"defaults",{borderCapStyle:"butt",borderDash:[],borderDashOffset:0,borderJoinStyle:"miter",borderWidth:3,capBezierPoints:!0,cubicInterpolationMode:"default",fill:!1,spanGaps:!1,stepped:!1,tension:0}),G(Kt,"defaultRoutes",{backgroundColor:"backgroundColor",borderColor:"borderColor"}),G(Kt,"descriptors",{_scriptable:!0,_indexable:t=>t!=="borderDash"&&t!=="fill"});We=class extends Pt{constructor(e){super();G(this,"parsed");G(this,"skip");G(this,"stop");this.options=void 0,this.parsed=void 0,this.skip=void 0,this.stop=void 0,e&&Object.assign(this,e)}inRange(e,n,i){let o=this.options,{x:r,y:a}=this.getProps(["x","y"],i);return Math.pow(e-r,2)+Math.pow(n-a,2)<Math.pow(o.hitRadius+o.radius,2)}inXRange(e,n){return Ua(this,e,"x",n)}inYRange(e,n){return Ua(this,e,"y",n)}getCenterPoint(e){let{x:n,y:i}=this.getProps(["x","y"],e);return{x:n,y:i}}size(e){e=e||this.options||{};let n=e.radius||0;n=Math.max(n,n&&e.hoverRadius||0);let i=n&&e.borderWidth||0;return(n+i)*2}draw(e,n){let i=this.options;this.skip||i.radius<.1||!Zt(this,n,this.size(i)/2)||(e.strokeStyle=i.borderColor,e.lineWidth=i.borderWidth,e.fillStyle=i.backgroundColor,Bn(e,i,this.x,this.y))}getRange(){let e=this.options||{};return e.radius+e.hitRadius}};G(We,"id","point"),G(We,"defaults",{borderWidth:1,hitRadius:1,hoverBorderWidth:1,hoverRadius:4,pointStyle:"circle",radius:3,rotation:0}),G(We,"defaultRoutes",{backgroundColor:"backgroundColor",borderColor:"borderColor"});je=class extends Pt{constructor(t){super(),this.options=void 0,this.horizontal=void 0,this.base=void 0,this.width=void 0,this.height=void 0,this.inflateAmount=void 0,t&&Object.assign(this,t)}draw(t){let{inflateAmount:e,options:{borderColor:n,backgroundColor:i}}=this,{inner:o,outer:r}=rf(this),a=af(r.radius)?gs:lf;t.save(),(r.w!==o.w||r.h!==o.h)&&(t.beginPath(),a(t,xo(r,e,o)),t.clip(),a(t,xo(o,-e,r)),t.fillStyle=n,t.fill("evenodd")),t.beginPath(),a(t,xo(o,e)),t.fillStyle=i,t.fill(),t.restore()}inRange(t,e,n){return yo(this,t,e,n)}inXRange(t,e){return yo(this,t,null,e)}inYRange(t,e){return yo(this,null,t,e)}getCenterPoint(t){let{x:e,y:n,base:i,horizontal:o}=this.getProps(["x","y","base","horizontal"],t);return{x:o?(e+i)/2:e,y:o?n:(n+i)/2}}getRange(t){return t==="x"?this.width/2:this.height/2}};G(je,"id","bar"),G(je,"defaults",{borderSkipped:"start",borderWidth:0,borderRadius:0,inflateAmount:"auto",pointStyle:void 0}),G(je,"defaultRoutes",{backgroundColor:"backgroundColor",borderColor:"borderColor"});Pl=Object.freeze({__proto__:null,ArcElement:Ee,BarElement:je,LineElement:Kt,PointElement:We}),Ao=["rgb(54, 162, 235)","rgb(255, 99, 132)","rgb(255, 159, 64)","rgb(255, 205, 86)","rgb(75, 192, 192)","rgb(153, 102, 255)","rgb(201, 203, 207)"],Ya=Ao.map(s=>s.replace("rgb(","rgba(").replace(")",", 0.5)"));Il={id:"colors",defaults:{enabled:!0,forceOverride:!1},beforeLayout(s,t,e){if(!e.enabled)return;let{data:{datasets:n},options:i}=s.config,{elements:o}=i,r=Ka(n)||ff(i)||o&&Ka(o)||gf();if(!e.forceOverride&&r)return;let a=uf(s);n.forEach(a)}};Bl={id:"decimation",defaults:{algorithm:"min-max",enabled:!1},beforeElementsUpdate:(s,t,e)=>{if(!e.enabled){Ga(s);return}let n=s.width;s.data.datasets.forEach((i,o)=>{let{_data:r,indexAxis:a}=i,l=s.getDatasetMeta(o),c=r||i.data;if(ps([a,s.options.indexAxis])==="y"||!l.controller.supportsDecimation)return;let d=s.scales[l.xAxisID];if(d.type!=="linear"&&d.type!=="time"||s.options.parsing)return;let{start:h,count:u}=bf(l,c),f=e.threshold||4*n;if(u<=f){Vl(i);return}tt(r)&&(i._data=c,delete i.data,Object.defineProperty(i,"data",{configurable:!0,enumerable:!0,get:function(){return this._decimated},set:function(p){this._data=p}}));let g;switch(e.algorithm){case"lttb":g=pf(c,h,u,n,e);break;case"min-max":g=mf(c,h,u,n);break;default:throw new Error(`Unsupported decimation algorithm '${e.algorithm}'`)}i._decimated=g})},destroy(s){Ga(s)}};ni=class{constructor(t){this.x=t.x,this.y=t.y,this.radius=t.radius}pathSegment(t,e,n){let{x:i,y:o,radius:r}=this;return e=e||{start:0,end:ht},t.arc(i,o,r,e.end,e.start,!0),!n.bounds}interpolate(t){let{x:e,y:n,radius:i}=this,o=t.angle;return{x:e+Math.cos(o)*i,y:n+Math.sin(o)*i,angle:o}}};$l={id:"filler",afterDatasetsUpdate(s,t,e){let n=(s.data.datasets||[]).length,i=[],o,r,a,l;for(r=0;r<n;++r)o=s.getDatasetMeta(r),a=o.dataset,l=null,a&&a.options&&a instanceof Kt&&(l={visible:s.isDatasetVisible(r),index:r,fill:Cf(a,r,n),chart:s,axis:o.controller.options.indexAxis,scale:o.vScale,line:a}),o.$filler=l,i.push(l);for(r=0;r<n;++r)l=i[r],!(!l||l.fill===!1)&&(l.fill=xf(i,r,e.propagate))},beforeDraw(s,t,e){let n=e.drawTime==="beforeDraw",i=s.getSortedVisibleDatasetMetas(),o=s.chartArea;for(let r=i.length-1;r>=0;--r){let a=i[r].$filler;a&&(a.line.updateControlPoints(o,a.axis),n&&a.fill&&Co(s.ctx,a,o))}},beforeDatasetsDraw(s,t,e){if(e.drawTime!=="beforeDatasetsDraw")return;let n=s.getSortedVisibleDatasetMetas();for(let i=n.length-1;i>=0;--i){let o=n[i].$filler;Xa(o)&&Co(s.ctx,o,s.chartArea)}},beforeDatasetDraw(s,t,e){let n=t.meta.$filler;!Xa(n)||e.drawTime!=="beforeDatasetDraw"||Co(s.ctx,n,s.chartArea)},defaults:{propagate:!0,drawTime:"beforeDatasetDraw"}},tl=(s,t)=>{let{boxHeight:e=t,boxWidth:n=t}=s;return s.usePointStyle&&(e=Math.min(e,t),n=s.pointStyleWidth||Math.min(n,t)),{boxWidth:n,boxHeight:e,itemHeight:Math.max(t,e)}},Vf=(s,t)=>s!==null&&t!==null&&s.datasetIndex===t.datasetIndex&&s.index===t.index,ii=class extends Pt{constructor(t){super(),this._added=!1,this.legendHitBoxes=[],this._hoveredItem=null,this.doughnutMode=!1,this.chart=t.chart,this.options=t.options,this.ctx=t.ctx,this.legendItems=void 0,this.columnSizes=void 0,this.lineWidths=void 0,this.maxHeight=void 0,this.maxWidth=void 0,this.top=void 0,this.bottom=void 0,this.left=void 0,this.right=void 0,this.height=void 0,this.width=void 0,this._margins=void 0,this.position=void 0,this.weight=void 0,this.fullSize=void 0}update(t,e,n){this.maxWidth=t,this.maxHeight=e,this._margins=n,this.setDimensions(),this.buildLabels(),this.fit()}setDimensions(){this.isHorizontal()?(this.width=this.maxWidth,this.left=this._margins.left,this.right=this.width):(this.height=this.maxHeight,this.top=this._margins.top,this.bottom=this.height)}buildLabels(){let t=this.options.labels||{},e=ct(t.generateLabels,[this.chart],this)||[];t.filter&&(e=e.filter(n=>t.filter(n,this.chart.data))),t.sort&&(e=e.sort((n,i)=>t.sort(n,i,this.chart.data))),this.options.reverse&&e.reverse(),this.legendItems=e}fit(){let{options:t,ctx:e}=this;if(!t.display){this.width=this.height=0;return}let n=t.labels,i=bt(n.font),o=i.size,r=this._computeTitleHeight(),{boxWidth:a,itemHeight:l}=tl(n,o),c,d;e.font=i.string,this.isHorizontal()?(c=this.maxWidth,d=this._fitRows(r,o,a,l)+10):(d=this.maxHeight,c=this._fitCols(r,i,a,l)+10),this.width=Math.min(c,t.maxWidth||this.maxWidth),this.height=Math.min(d,t.maxHeight||this.maxHeight)}_fitRows(t,e,n,i){let{ctx:o,maxWidth:r,options:{labels:{padding:a}}}=this,l=this.legendHitBoxes=[],c=this.lineWidths=[0],d=i+a,h=t;o.textAlign="left",o.textBaseline="middle";let u=-1,f=-d;return this.legendItems.forEach((g,p)=>{let b=n+e/2+o.measureText(g.text).width;(p===0||c[c.length-1]+b+2*a>r)&&(h+=d,c[c.length-(p>0?0:1)]=0,f+=d,u++),l[p]={left:0,top:f,row:u,width:b,height:i},c[c.length-1]+=b+a}),h}_fitCols(t,e,n,i){let{ctx:o,maxHeight:r,options:{labels:{padding:a}}}=this,l=this.legendHitBoxes=[],c=this.columnSizes=[],d=r-t,h=a,u=0,f=0,g=0,p=0;return this.legendItems.forEach((b,m)=>{let{itemWidth:y,itemHeight:C}=Bf(n,e,o,b,i);m>0&&f+C+2*a>d&&(h+=u+a,c.push({width:u,height:f}),g+=u+a,p++,u=f=0),l[m]={left:g,top:f,col:p,width:y,height:C},u=Math.max(u,y),f+=C+a}),h+=u,c.push({width:u,height:f}),h}adjustHitBoxes(){if(!this.options.display)return;let t=this._computeTitleHeight(),{legendHitBoxes:e,options:{align:n,labels:{padding:i},rtl:o}}=this,r=Fe(o,this.left,this.width);if(this.isHorizontal()){let a=0,l=_t(n,this.left+i,this.right-this.lineWidths[a]);for(let c of e)a!==c.row&&(a=c.row,l=_t(n,this.left+i,this.right-this.lineWidths[a])),c.top+=this.top+t+i,c.left=r.leftForLtr(r.x(l),c.width),l+=c.width+i}else{let a=0,l=_t(n,this.top+t+i,this.bottom-this.columnSizes[a].height);for(let c of e)c.col!==a&&(a=c.col,l=_t(n,this.top+t+i,this.bottom-this.columnSizes[a].height)),c.top=l,c.left+=this.left+i,c.left=r.leftForLtr(r.x(c.left),c.width),l+=c.height+i}}isHorizontal(){return this.options.position==="top"||this.options.position==="bottom"}draw(){if(this.options.display){let t=this.ctx;Us(t,this),this._draw(),Ys(t)}}_draw(){let{options:t,columnSizes:e,lineWidths:n,ctx:i}=this,{align:o,labels:r}=t,a=ut.color,l=Fe(t.rtl,this.left,this.width),c=bt(r.font),{padding:d}=r,h=c.size,u=h/2,f;this.drawTitle(),i.textAlign=l.textAlign("left"),i.textBaseline="middle",i.lineWidth=.5,i.font=c.string;let{boxWidth:g,boxHeight:p,itemHeight:b}=tl(r,h),m=function(x,v,_){if(isNaN(g)||g<=0||isNaN(p)||p<0)return;i.save();let w=J(_.lineWidth,1);if(i.fillStyle=J(_.fillStyle,a),i.lineCap=J(_.lineCap,"butt"),i.lineDashOffset=J(_.lineDashOffset,0),i.lineJoin=J(_.lineJoin,"miter"),i.lineWidth=w,i.strokeStyle=J(_.strokeStyle,a),i.setLineDash(J(_.lineDash,[])),r.usePointStyle){let D={radius:p*Math.SQRT2/2,pointStyle:_.pointStyle,rotation:_.rotation,borderWidth:w},k=l.xPlus(x,g/2),T=v+u;Zi(i,D,k,T,r.pointStyleWidth&&g)}else{let D=v+Math.max((h-p)/2,0),k=l.leftForLtr(x,g),T=_e(_.borderRadius);i.beginPath(),Object.values(T).some(A=>A!==0)?gs(i,{x:k,y:D,w:g,h:p,radius:T}):i.rect(k,D,g,p),i.fill(),w!==0&&i.stroke()}i.restore()},y=function(x,v,_){Ce(i,_.text,x,v+b/2,c,{strikethrough:_.hidden,textAlign:l.textAlign(_.textAlign)})},C=this.isHorizontal(),E=this._computeTitleHeight();C?f={x:_t(o,this.left+d,this.right-n[0]),y:this.top+d+E,line:0}:f={x:this.left+d,y:_t(o,this.top+E+d,this.bottom-e[0].height),line:0},ro(this.ctx,t.textDirection);let S=b+d;this.legendItems.forEach((x,v)=>{i.strokeStyle=x.fontColor,i.fillStyle=x.fontColor;let _=i.measureText(x.text).width,w=l.textAlign(x.textAlign||(x.textAlign=r.textAlign)),D=g+u+_,k=f.x,T=f.y;l.setWidth(this.width),C?v>0&&k+D+d>this.right&&(T=f.y+=S,f.line++,k=f.x=_t(o,this.left+d,this.right-n[f.line])):v>0&&T+S>this.bottom&&(k=f.x=k+e[f.line].width+d,f.line++,T=f.y=_t(o,this.top+E+d,this.bottom-e[f.line].height));let A=l.x(k);if(m(A,T,x),k=Jr(w,k+g+u,C?k+D:this.right,t.rtl),y(l.x(k),T,x),C)f.x+=D+d;else if(typeof x.text!="string"){let I=c.lineHeight;f.y+=zl(x,I)+d}else f.y+=S}),ao(this.ctx,t.textDirection)}drawTitle(){let t=this.options,e=t.title,n=bt(e.font),i=St(e.padding);if(!e.display)return;let o=Fe(t.rtl,this.left,this.width),r=this.ctx,a=e.position,l=n.size/2,c=i.top+l,d,h=this.left,u=this.width;if(this.isHorizontal())u=Math.max(...this.lineWidths),d=this.top+c,h=_t(t.align,h,this.right-u);else{let g=this.columnSizes.reduce((p,b)=>Math.max(p,b.height),0);d=c+_t(t.align,this.top,this.bottom-g-t.labels.padding-this._computeTitleHeight())}let f=_t(a,h,h+u);r.textAlign=o.textAlign(In(a)),r.textBaseline="middle",r.strokeStyle=e.color,r.fillStyle=e.color,r.font=n.string,Ce(r,e.text,f,d,n)}_computeTitleHeight(){let t=this.options.title,e=bt(t.font),n=St(t.padding);return t.display?e.lineHeight+n.height:0}_getLegendItemAt(t,e){let n,i,o;if(te(t,this.left,this.right)&&te(e,this.top,this.bottom)){for(o=this.legendHitBoxes,n=0;n<o.length;++n)if(i=o[n],te(t,i.left,i.left+i.width)&&te(e,i.top,i.top+i.height))return this.legendItems[n]}return null}handleEvent(t){let e=this.options;if(!zf(t.type,e))return;let n=this._getLegendItemAt(t.x,t.y);if(t.type==="mousemove"||t.type==="mouseout"){let i=this._hoveredItem,o=Vf(i,n);i&&!o&&ct(e.onLeave,[t,i,this],this),this._hoveredItem=n,n&&!o&&ct(e.onHover,[t,n,this],this)}else n&&ct(e.onClick,[t,n,this],this)}};Hl={id:"legend",_element:ii,start(s,t,e){let n=s.legend=new ii({ctx:s.ctx,options:e,chart:s});Et.configure(s,n,e),Et.addBox(s,n)},stop(s){Et.removeBox(s,s.legend),delete s.legend},beforeUpdate(s,t,e){let n=s.legend;Et.configure(s,n,e),n.options=e},afterUpdate(s){let t=s.legend;t.buildLabels(),t.adjustHitBoxes()},afterEvent(s,t){t.replay||s.legend.handleEvent(t.event)},defaults:{display:!0,position:"top",align:"center",fullSize:!0,reverse:!1,weight:1e3,onClick(s,t,e){let n=t.datasetIndex,i=e.chart;i.isDatasetVisible(n)?(i.hide(n),t.hidden=!0):(i.show(n),t.hidden=!1)},onHover:null,onLeave:null,labels:{color:s=>s.chart.options.color,boxWidth:40,padding:10,generateLabels(s){let t=s.data.datasets,{labels:{usePointStyle:e,pointStyle:n,textAlign:i,color:o,useBorderRadius:r,borderRadius:a}}=s.legend.options;return s._getSortedDatasetMetas().map(l=>{let c=l.controller.getStyle(e?0:void 0),d=St(c.borderWidth);return{text:t[l.index].label,fillStyle:c.backgroundColor,fontColor:o,hidden:!l.visible,lineCap:c.borderCapStyle,lineDash:c.borderDash,lineDashOffset:c.borderDashOffset,lineJoin:c.borderJoinStyle,lineWidth:(d.width+d.height)/4,strokeStyle:c.borderColor,pointStyle:n||c.pointStyle,rotation:c.rotation,textAlign:i||c.textAlign,borderRadius:r&&(a||c.borderRadius),datasetIndex:l.index}},this)}},title:{color:s=>s.chart.options.color,display:!1,position:"center",text:""}},descriptors:{_scriptable:s=>!s.startsWith("on"),labels:{_scriptable:s=>!["generateLabels","filter","sort"].includes(s)}}},on=class extends Pt{constructor(t){super(),this.chart=t.chart,this.options=t.options,this.ctx=t.ctx,this._padding=void 0,this.top=void 0,this.bottom=void 0,this.left=void 0,this.right=void 0,this.width=void 0,this.height=void 0,this.position=void 0,this.weight=void 0,this.fullSize=void 0}update(t,e){let n=this.options;if(this.left=0,this.top=0,!n.display){this.width=this.height=this.right=this.bottom=0;return}this.width=this.right=t,this.height=this.bottom=e;let i=dt(n.text)?n.text.length:1;this._padding=St(n.padding);let o=i*bt(n.font).lineHeight+this._padding.height;this.isHorizontal()?this.height=o:this.width=o}isHorizontal(){let t=this.options.position;return t==="top"||t==="bottom"}_drawArgs(t){let{top:e,left:n,bottom:i,right:o,options:r}=this,a=r.align,l=0,c,d,h;return this.isHorizontal()?(d=_t(a,n,o),h=e+t,c=o-n):(r.position==="left"?(d=n+t,h=_t(a,i,e),l=nt*-.5):(d=o-t,h=_t(a,e,i),l=nt*.5),c=i-e),{titleX:d,titleY:h,maxWidth:c,rotation:l}}draw(){let t=this.ctx,e=this.options;if(!e.display)return;let n=bt(e.font),o=n.lineHeight/2+this._padding.top,{titleX:r,titleY:a,maxWidth:l,rotation:c}=this._drawArgs(o);Ce(t,e.text,0,0,n,{color:e.color,maxWidth:l,rotation:c,textAlign:In(e.align),textBaseline:"middle",translation:[r,a]})}};Wl={id:"title",_element:on,start(s,t,e){Hf(s,e)},stop(s){let t=s.titleBlock;Et.removeBox(s,t),delete s.titleBlock},beforeUpdate(s,t,e){let n=s.titleBlock;Et.configure(s,n,e),n.options=e},defaults:{align:"center",display:!1,font:{weight:"bold"},fullSize:!0,padding:10,position:"top",text:"",weight:2e3},defaultRoutes:{color:"color"},descriptors:{_scriptable:!0,_indexable:!1}},Kn=new WeakMap,jl={id:"subtitle",start(s,t,e){let n=new on({ctx:s.ctx,options:e,chart:s});Et.configure(s,n,e),Et.addBox(s,n),Kn.set(s,n)},stop(s){Et.removeBox(s,Kn.get(s)),Kn.delete(s)},beforeUpdate(s,t,e){let n=Kn.get(s);Et.configure(s,n,e),n.options=e},defaults:{align:"center",display:!1,font:{weight:"normal"},fullSize:!0,padding:0,position:"top",text:"",weight:1500},defaultRoutes:{color:"color"},descriptors:{_scriptable:!0,_indexable:!1}},Js={average(s){if(!s.length)return!1;let t,e,n=new Set,i=0,o=0;for(t=0,e=s.length;t<e;++t){let a=s[t].element;if(a&&a.hasValue()){let l=a.tooltipPosition();n.add(l.x),i+=l.y,++o}}return o===0||n.size===0?!1:{x:[...n].reduce((a,l)=>a+l)/n.size,y:i/o}},nearest(s,t){if(!s.length)return!1;let e=t.x,n=t.y,i=Number.POSITIVE_INFINITY,o,r,a;for(o=0,r=s.length;o<r;++o){let l=s[o].element;if(l&&l.hasValue()){let c=l.getCenterPoint(),d=An(t,c);d<i&&(i=d,a=l)}}if(a){let l=a.tooltipPosition();e=l.x,n=l.y}return{x:e,y:n}}};Ul={beforeTitle:Jt,title(s){if(s.length>0){let t=s[0],e=t.chart.data.labels,n=e?e.length:0;if(this&&this.options&&this.options.mode==="dataset")return t.dataset.label||"";if(t.label)return t.label;if(n>0&&t.dataIndex<n)return e[t.dataIndex]}return""},afterTitle:Jt,beforeBody:Jt,beforeLabel:Jt,label(s){if(this&&this.options&&this.options.mode==="dataset")return s.label+": "+s.formattedValue||s.formattedValue;let t=s.dataset.label||"";t&&(t+=": ");let e=s.formattedValue;return tt(e)||(t+=e),t},labelColor(s){let e=s.chart.getDatasetMeta(s.datasetIndex).controller.getStyle(s.dataIndex);return{borderColor:e.borderColor,backgroundColor:e.backgroundColor,borderWidth:e.borderWidth,borderDash:e.borderDash,borderDashOffset:e.borderDashOffset,borderRadius:0}},labelTextColor(){return this.options.bodyColor},labelPointStyle(s){let e=s.chart.getDatasetMeta(s.datasetIndex).controller.getStyle(s.dataIndex);return{pointStyle:e.pointStyle,rotation:e.rotation}},afterLabel:Jt,afterBody:Jt,beforeFooter:Jt,footer:Jt,afterFooter:Jt};tn=class extends Pt{constructor(t){super(),this.opacity=0,this._active=[],this._eventPosition=void 0,this._size=void 0,this._cachedAnimations=void 0,this._tooltipItems=[],this.$animations=void 0,this.$context=void 0,this.chart=t.chart,this.options=t.options,this.dataPoints=void 0,this.title=void 0,this.beforeBody=void 0,this.body=void 0,this.afterBody=void 0,this.footer=void 0,this.xAlign=void 0,this.yAlign=void 0,this.x=void 0,this.y=void 0,this.height=void 0,this.width=void 0,this.caretX=void 0,this.caretY=void 0,this.labelColors=void 0,this.labelPointStyles=void 0,this.labelTextColors=void 0}initialize(t){this.options=t,this._cachedAnimations=void 0,this.$context=void 0}_resolveAnimations(){let t=this._cachedAnimations;if(t)return t;let e=this.chart,n=this.options.setContext(this.getContext()),i=n.enabled&&e.options.animation&&n.animations,o=new en(this.chart,i);return i._cacheable&&(this._cachedAnimations=Object.freeze(o)),o}getContext(){return this.$context||(this.$context=qf(this.chart.getContext(),this,this._tooltipItems))}getTitle(t,e){let{callbacks:n}=e,i=Lt(n,"beforeTitle",this,t),o=Lt(n,"title",this,t),r=Lt(n,"afterTitle",this,t),a=[];return a=ee(a,he(i)),a=ee(a,he(o)),a=ee(a,he(r)),a}getBeforeBody(t,e){return il(Lt(e.callbacks,"beforeBody",this,t))}getBody(t,e){let{callbacks:n}=e,i=[];return rt(t,o=>{let r={before:[],lines:[],after:[]},a=ol(n,o);ee(r.before,he(Lt(a,"beforeLabel",this,o))),ee(r.lines,Lt(a,"label",this,o)),ee(r.after,he(Lt(a,"afterLabel",this,o))),i.push(r)}),i}getAfterBody(t,e){return il(Lt(e.callbacks,"afterBody",this,t))}getFooter(t,e){let{callbacks:n}=e,i=Lt(n,"beforeFooter",this,t),o=Lt(n,"footer",this,t),r=Lt(n,"afterFooter",this,t),a=[];return a=ee(a,he(i)),a=ee(a,he(o)),a=ee(a,he(r)),a}_createItems(t){let e=this._active,n=this.chart.data,i=[],o=[],r=[],a=[],l,c;for(l=0,c=e.length;l<c;++l)a.push(Wf(this.chart,e[l]));return t.filter&&(a=a.filter((d,h,u)=>t.filter(d,h,u,n))),t.itemSort&&(a=a.sort((d,h)=>t.itemSort(d,h,n))),rt(a,d=>{let h=ol(t.callbacks,d);i.push(Lt(h,"labelColor",this,d)),o.push(Lt(h,"labelPointStyle",this,d)),r.push(Lt(h,"labelTextColor",this,d))}),this.labelColors=i,this.labelPointStyles=o,this.labelTextColors=r,this.dataPoints=a,a}update(t,e){let n=this.options.setContext(this.getContext()),i=this._active,o,r=[];if(!i.length)this.opacity!==0&&(o={opacity:0});else{let a=Js[n.position].call(this,i,this._eventPosition);r=this._createItems(n),this.title=this.getTitle(r,n),this.beforeBody=this.getBeforeBody(r,n),this.body=this.getBody(r,n),this.afterBody=this.getAfterBody(r,n),this.footer=this.getFooter(r,n);let l=this._size=el(this,n),c=Object.assign({},a,l),d=sl(this.chart,n,c),h=nl(n,c,d,this.chart);this.xAlign=d.xAlign,this.yAlign=d.yAlign,o={opacity:1,x:h.x,y:h.y,width:l.width,height:l.height,caretX:a.x,caretY:a.y}}this._tooltipItems=r,this.$context=void 0,o&&this._resolveAnimations().update(this,o),t&&n.external&&n.external.call(this,{chart:this.chart,tooltip:this,replay:e})}drawCaret(t,e,n,i){let o=this.getCaretPosition(t,n,i);e.lineTo(o.x1,o.y1),e.lineTo(o.x2,o.y2),e.lineTo(o.x3,o.y3)}getCaretPosition(t,e,n){let{xAlign:i,yAlign:o}=this,{caretSize:r,cornerRadius:a}=n,{topLeft:l,topRight:c,bottomLeft:d,bottomRight:h}=_e(a),{x:u,y:f}=t,{width:g,height:p}=e,b,m,y,C,E,S;return o==="center"?(E=f+p/2,i==="left"?(b=u,m=b-r,C=E+r,S=E-r):(b=u+g,m=b+r,C=E-r,S=E+r),y=b):(i==="left"?m=u+Math.max(l,d)+r:i==="right"?m=u+g-Math.max(c,h)-r:m=this.caretX,o==="top"?(C=f,E=C-r,b=m-r,y=m+r):(C=f+p,E=C+r,b=m+r,y=m-r),S=C),{x1:b,x2:m,x3:y,y1:C,y2:E,y3:S}}drawTitle(t,e,n){let i=this.title,o=i.length,r,a,l;if(o){let c=Fe(n.rtl,this.x,this.width);for(t.x=Gn(this,n.titleAlign,n),e.textAlign=c.textAlign(n.titleAlign),e.textBaseline="middle",r=bt(n.titleFont),a=n.titleSpacing,e.fillStyle=n.titleColor,e.font=r.string,l=0;l<o;++l)e.fillText(i[l],c.x(t.x),t.y+r.lineHeight/2),t.y+=r.lineHeight+a,l+1===o&&(t.y+=n.titleMarginBottom-a)}}_drawColorBox(t,e,n,i,o){let r=this.labelColors[n],a=this.labelPointStyles[n],{boxHeight:l,boxWidth:c}=o,d=bt(o.bodyFont),h=Gn(this,"left",o),u=i.x(h),f=l<d.lineHeight?(d.lineHeight-l)/2:0,g=e.y+f;if(o.usePointStyle){let p={radius:Math.min(c,l)/2,pointStyle:a.pointStyle,rotation:a.rotation,borderWidth:1},b=i.leftForLtr(u,c)+c/2,m=g+l/2;t.strokeStyle=o.multiKeyBackground,t.fillStyle=o.multiKeyBackground,Bn(t,p,b,m),t.strokeStyle=r.borderColor,t.fillStyle=r.backgroundColor,Bn(t,p,b,m)}else{t.lineWidth=et(r.borderWidth)?Math.max(...Object.values(r.borderWidth)):r.borderWidth||1,t.strokeStyle=r.borderColor,t.setLineDash(r.borderDash||[]),t.lineDashOffset=r.borderDashOffset||0;let p=i.leftForLtr(u,c),b=i.leftForLtr(i.xPlus(u,1),c-2),m=_e(r.borderRadius);Object.values(m).some(y=>y!==0)?(t.beginPath(),t.fillStyle=o.multiKeyBackground,gs(t,{x:p,y:g,w:c,h:l,radius:m}),t.fill(),t.stroke(),t.fillStyle=r.backgroundColor,t.beginPath(),gs(t,{x:b,y:g+1,w:c-2,h:l-2,radius:m}),t.fill()):(t.fillStyle=o.multiKeyBackground,t.fillRect(p,g,c,l),t.strokeRect(p,g,c,l),t.fillStyle=r.backgroundColor,t.fillRect(b,g+1,c-2,l-2))}t.fillStyle=this.labelTextColors[n]}drawBody(t,e,n){let{body:i}=this,{bodySpacing:o,bodyAlign:r,displayColors:a,boxHeight:l,boxWidth:c,boxPadding:d}=n,h=bt(n.bodyFont),u=h.lineHeight,f=0,g=Fe(n.rtl,this.x,this.width),p=function(_){e.fillText(_,g.x(t.x+f),t.y+u/2),t.y+=u+o},b=g.textAlign(r),m,y,C,E,S,x,v;for(e.textAlign=r,e.textBaseline="middle",e.font=h.string,t.x=Gn(this,b,n),e.fillStyle=n.bodyColor,rt(this.beforeBody,p),f=a&&b!=="right"?r==="center"?c/2+d:c+2+d:0,E=0,x=i.length;E<x;++E){for(m=i[E],y=this.labelTextColors[E],e.fillStyle=y,rt(m.before,p),C=m.lines,a&&C.length&&(this._drawColorBox(e,t,E,g,n),u=Math.max(h.lineHeight,l)),S=0,v=C.length;S<v;++S)p(C[S]),u=h.lineHeight;rt(m.after,p)}f=0,u=h.lineHeight,rt(this.afterBody,p),t.y-=o}drawFooter(t,e,n){let i=this.footer,o=i.length,r,a;if(o){let l=Fe(n.rtl,this.x,this.width);for(t.x=Gn(this,n.footerAlign,n),t.y+=n.footerMarginTop,e.textAlign=l.textAlign(n.footerAlign),e.textBaseline="middle",r=bt(n.footerFont),e.fillStyle=n.footerColor,e.font=r.string,a=0;a<o;++a)e.fillText(i[a],l.x(t.x),t.y+r.lineHeight/2),t.y+=r.lineHeight+n.footerSpacing}}drawBackground(t,e,n,i){let{xAlign:o,yAlign:r}=this,{x:a,y:l}=t,{width:c,height:d}=n,{topLeft:h,topRight:u,bottomLeft:f,bottomRight:g}=_e(i.cornerRadius);e.fillStyle=i.backgroundColor,e.strokeStyle=i.borderColor,e.lineWidth=i.borderWidth,e.beginPath(),e.moveTo(a+h,l),r==="top"&&this.drawCaret(t,e,n,i),e.lineTo(a+c-u,l),e.quadraticCurveTo(a+c,l,a+c,l+u),r==="center"&&o==="right"&&this.drawCaret(t,e,n,i),e.lineTo(a+c,l+d-g),e.quadraticCurveTo(a+c,l+d,a+c-g,l+d),r==="bottom"&&this.drawCaret(t,e,n,i),e.lineTo(a+f,l+d),e.quadraticCurveTo(a,l+d,a,l+d-f),r==="center"&&o==="left"&&this.drawCaret(t,e,n,i),e.lineTo(a,l+h),e.quadraticCurveTo(a,l,a+h,l),e.closePath(),e.fill(),i.borderWidth>0&&e.stroke()}_updateAnimationTarget(t){let e=this.chart,n=this.$animations,i=n&&n.x,o=n&&n.y;if(i||o){let r=Js[t.position].call(this,this._active,this._eventPosition);if(!r)return;let a=this._size=el(this,t),l=Object.assign({},r,this._size),c=sl(e,t,l),d=nl(t,l,c,e);(i._to!==d.x||o._to!==d.y)&&(this.xAlign=c.xAlign,this.yAlign=c.yAlign,this.width=a.width,this.height=a.height,this.caretX=r.x,this.caretY=r.y,this._resolveAnimations().update(this,d))}}_willRender(){return!!this.opacity}draw(t){let e=this.options.setContext(this.getContext()),n=this.opacity;if(!n)return;this._updateAnimationTarget(e);let i={width:this.width,height:this.height},o={x:this.x,y:this.y};n=Math.abs(n)<.001?0:n;let r=St(e.padding),a=this.title.length||this.beforeBody.length||this.body.length||this.afterBody.length||this.footer.length;e.enabled&&a&&(t.save(),t.globalAlpha=n,this.drawBackground(o,t,i,e),ro(t,e.textDirection),o.y+=r.top,this.drawTitle(o,t,e),this.drawBody(o,t,e),this.drawFooter(o,t,e),ao(t,e.textDirection),t.restore())}getActiveElements(){return this._active||[]}setActiveElements(t,e){let n=this._active,i=t.map(({datasetIndex:a,index:l})=>{let c=this.chart.getDatasetMeta(a);if(!c)throw new Error("Cannot find a dataset at index "+a);return{datasetIndex:a,element:c.data[l],index:l}}),o=!js(n,i),r=this._positionChanged(i,e);(o||r)&&(this._active=i,this._eventPosition=e,this._ignoreReplayEvents=!0,this.update(!0))}handleEvent(t,e,n=!0){if(e&&this._ignoreReplayEvents)return!1;this._ignoreReplayEvents=!1;let i=this.options,o=this._active||[],r=this._getActiveElements(t,o,e,n),a=this._positionChanged(r,t),l=e||!js(r,o)||a;return l&&(this._active=r,(i.enabled||i.external)&&(this._eventPosition={x:t.x,y:t.y},this.update(!0,e))),l}_getActiveElements(t,e,n,i){let o=this.options;if(t.type==="mouseout")return[];if(!i)return e.filter(a=>this.chart.data.datasets[a.datasetIndex]&&this.chart.getDatasetMeta(a.datasetIndex).controller.getParsed(a.index)!==void 0);let r=this.chart.getElementsAtEventForMode(t,o.mode,o,n);return o.reverse&&r.reverse(),r}_positionChanged(t,e){let{caretX:n,caretY:i,options:o}=this,r=Js[o.position].call(this,t,e);return r!==!1&&(n!==r.x||i!==r.y)}};G(tn,"positioners",Js);Yl={id:"tooltip",_element:tn,positioners:Js,afterInit(s,t,e){e&&(s.tooltip=new tn({chart:s,options:e}))},beforeUpdate(s,t,e){s.tooltip&&s.tooltip.initialize(e)},reset(s,t,e){s.tooltip&&s.tooltip.initialize(e)},afterDraw(s){let t=s.tooltip;if(t&&t._willRender()){let e={tooltip:t};if(s.notifyPlugins("beforeTooltipDraw",{...e,cancelable:!0})===!1)return;t.draw(s.ctx),s.notifyPlugins("afterTooltipDraw",e)}},afterEvent(s,t){if(s.tooltip){let e=t.replay;s.tooltip.handleEvent(t.event,e,t.inChartArea)&&(t.changed=!0)}},defaults:{enabled:!0,external:null,position:"average",backgroundColor:"rgba(0,0,0,0.8)",titleColor:"#fff",titleFont:{weight:"bold"},titleSpacing:2,titleMarginBottom:6,titleAlign:"left",bodyColor:"#fff",bodySpacing:2,bodyFont:{},bodyAlign:"left",footerColor:"#fff",footerSpacing:2,footerMarginTop:6,footerFont:{weight:"bold"},footerAlign:"left",padding:6,caretPadding:2,caretSize:5,cornerRadius:6,boxHeight:(s,t)=>t.bodyFont.size,boxWidth:(s,t)=>t.bodyFont.size,multiKeyBackground:"#fff",displayColors:!0,boxPadding:0,borderColor:"rgba(0,0,0,0)",borderWidth:0,animation:{duration:400,easing:"easeOutQuart"},animations:{numbers:{type:"number",properties:["x","y","width","height","caretX","caretY"]},opacity:{easing:"linear",duration:200}},callbacks:Ul},defaultRoutes:{bodyFont:"font",footerFont:"font",titleFont:"font"},descriptors:{_scriptable:s=>s!=="filter"&&s!=="itemSort"&&s!=="external",_indexable:!1,callbacks:{_scriptable:!1,_indexable:!1},animation:{_fallback:!1},animations:{_fallback:"animation"}},additionalOptionScopes:["interaction"]},Kl=Object.freeze({__proto__:null,Colors:Il,Decimation:Bl,Filler:$l,Legend:Hl,SubTitle:jl,Title:Wl,Tooltip:Yl}),Xf=(s,t,e,n)=>(typeof t=="string"?(e=s.push(t)-1,n.unshift({index:e,label:t})):isNaN(t)&&(e=null),e);Zf=(s,t)=>s===null?null:vt(Math.round(s),0,t);ys=class extends Te{constructor(t){super(t),this._startValue=void 0,this._valueRange=0,this._addedLabels=[]}init(t){let e=this._addedLabels;if(e.length){let n=this.getLabels();for(let{index:i,label:o}of e)n[i]===o&&n.splice(i,1);this._addedLabels=[]}super.init(t)}parse(t,e){if(tt(t))return null;let n=this.getLabels();return e=isFinite(e)&&n[e]===t?e:Qf(n,t,J(e,t),this._addedLabels),Zf(e,n.length-1)}determineDataLimits(){let{minDefined:t,maxDefined:e}=this.getUserBounds(),{min:n,max:i}=this.getMinMax(!0);this.options.bounds==="ticks"&&(t||(n=0),e||(i=this.getLabels().length-1)),this.min=n,this.max=i}buildTicks(){let t=this.min,e=this.max,n=this.options.offset,i=[],o=this.getLabels();o=t===0&&e===o.length-1?o:o.slice(t,e+1),this._valueRange=Math.max(o.length-(n?0:1),1),this._startValue=this.min-(n?.5:0);for(let r=t;r<=e;r++)i.push({value:r});return i}getLabelForValue(t){return rl.call(this,t)}configure(){super.configure(),this.isHorizontal()||(this._reversePixels=!this._reversePixels)}getPixelForValue(t){return typeof t!="number"&&(t=this.parse(t)),t===null?NaN:this.getPixelForDecimal((t-this._startValue)/this._valueRange)}getPixelForTick(t){let e=this.ticks;return t<0||t>e.length-1?null:this.getPixelForValue(e[t].value)}getValueForPixel(t){return Math.round(this._startValue+this.getDecimalForPixel(t)*this._valueRange)}getBasePixel(){return this.bottom}};G(ys,"id","category"),G(ys,"defaults",{ticks:{callback:rl}});Ss=class extends Te{constructor(t){super(t),this.start=void 0,this.end=void 0,this._startValue=void 0,this._endValue=void 0,this._valueRange=0}parse(t,e){return tt(t)||(typeof t=="number"||t instanceof Number)&&!isFinite(+t)?null:+t}handleTickRangeOptions(){let{beginAtZero:t}=this.options,{minDefined:e,maxDefined:n}=this.getUserBounds(),{min:i,max:o}=this,r=l=>i=e?i:l,a=l=>o=n?o:l;if(t){let l=Ut(i),c=Ut(o);l<0&&c<0?a(0):l>0&&c>0&&r(0)}if(i===o){let l=o===0?1:Math.abs(o*.05);a(o+l),t||r(i-l)}this.min=i,this.max=o}getTickLimit(){let t=this.options.ticks,{maxTicksLimit:e,stepSize:n}=t,i;return n?(i=Math.ceil(this.max/n)-Math.floor(this.min/n)+1,i>1e3&&(console.warn(`scales.${this.id}.ticks.stepSize: ${n} would result generating up to ${i} ticks. Limiting to 1000.`),i=1e3)):(i=this.computeTickLimit(),e=e||11),e&&(i=Math.min(e,i)),i}computeTickLimit(){return Number.POSITIVE_INFINITY}buildTicks(){let t=this.options,e=t.ticks,n=this.getTickLimit();n=Math.max(2,n);let i={maxTicks:n,bounds:t.bounds,min:t.min,max:t.max,precision:e.precision,step:e.stepSize,count:e.count,maxDigits:this._maxDigits(),horizontal:this.isHorizontal(),minRotation:e.minRotation||0,includeBounds:e.includeBounds!==!1},o=this._range||this,r=Jf(i,o);return t.bounds==="ticks"&&$i(r,this,"value"),t.reverse?(r.reverse(),this.start=this.max,this.end=this.min):(this.start=this.min,this.end=this.max),r}configure(){let t=this.ticks,e=this.min,n=this.max;if(super.configure(),this.options.offset&&t.length){let i=(n-e)/Math.max(t.length-1,1)/2;e-=i,n+=i}this._startValue=e,this._endValue=n,this._valueRange=n-e}getLabelForValue(t){return us(t,this.chart.options.locale,this.options.ticks.format)}},xs=class extends Ss{determineDataLimits(){let{min:t,max:e}=this.getMinMax(!0);this.min=gt(t)?t:0,this.max=gt(e)?e:1,this.handleTickRangeOptions()}computeTickLimit(){let t=this.isHorizontal(),e=t?this.width:this.height,n=Ht(this.options.ticks.minRotation),i=(t?Math.sin(n):Math.cos(n))||.001,o=this._resolveTickFontOptions(0);return Math.ceil(e/Math.min(40,o.lineHeight/i))}getPixelForValue(t){return t===null?NaN:this.getPixelForDecimal((t-this._startValue)/this._valueRange)}getValueForPixel(t){return this._startValue+this.getDecimalForPixel(t)*this._valueRange}};G(xs,"id","linear"),G(xs,"defaults",{ticks:{callback:fs.formatters.numeric}});rn=s=>Math.floor(le(s)),Ve=(s,t)=>Math.pow(10,rn(s)+t);Cs=class extends Te{constructor(t){super(t),this.start=void 0,this.end=void 0,this._startValue=void 0,this._valueRange=0}parse(t,e){let n=Ss.prototype.parse.apply(this,[t,e]);if(n===0){this._zero=!0;return}return gt(n)&&n>0?n:null}determineDataLimits(){let{min:t,max:e}=this.getMinMax(!0);this.min=gt(t)?Math.max(0,t):null,this.max=gt(e)?Math.max(0,e):null,this.options.beginAtZero&&(this._zero=!0),this._zero&&this.min!==this._suggestedMin&&!gt(this._userMin)&&(this.min=t===Ve(this.min,0)?Ve(this.min,-1):Ve(this.min,0)),this.handleTickRangeOptions()}handleTickRangeOptions(){let{minDefined:t,maxDefined:e}=this.getUserBounds(),n=this.min,i=this.max,o=a=>n=t?n:a,r=a=>i=e?i:a;n===i&&(n<=0?(o(1),r(10)):(o(Ve(n,-1)),r(Ve(i,1)))),n<=0&&o(Ve(i,-1)),i<=0&&r(Ve(n,1)),this.min=n,this.max=i}buildTicks(){let t=this.options,e={min:this._userMin,max:this._userMax},n=eg(e,this);return t.bounds==="ticks"&&$i(n,this,"value"),t.reverse?(n.reverse(),this.start=this.max,this.end=this.min):(this.start=this.min,this.end=this.max),n}getLabelForValue(t){return t===void 0?"0":us(t,this.chart.options.locale,this.options.ticks.format)}configure(){let t=this.min;super.configure(),this._startValue=le(t),this._valueRange=le(this.max)-le(t)}getPixelForValue(t){return(t===void 0||t===0)&&(t=this.min),t===null||isNaN(t)?NaN:this.getPixelForDecimal(t===this.min?0:(le(t)-this._startValue)/this._valueRange)}getValueForPixel(t){let e=this.getDecimalForPixel(t);return Math.pow(10,this._startValue+e*this._valueRange)}};G(Cs,"id","logarithmic"),G(Cs,"defaults",{ticks:{callback:fs.formatters.logarithmic,major:{enabled:!0}}});ke=class extends Ss{constructor(t){super(t),this.xCenter=void 0,this.yCenter=void 0,this.drawingArea=void 0,this._pointLabels=[],this._pointLabelItems=[]}setDimensions(){let t=this._padding=St(Po(this.options)/2),e=this.width=this.maxWidth-t.width,n=this.height=this.maxHeight-t.height;this.xCenter=Math.floor(this.left+e/2+t.left),this.yCenter=Math.floor(this.top+n/2+t.top),this.drawingArea=Math.floor(Math.min(e,n)/2)}determineDataLimits(){let{min:t,max:e}=this.getMinMax(!1);this.min=gt(t)&&!isNaN(t)?t:0,this.max=gt(e)&&!isNaN(e)?e:0,this.handleTickRangeOptions()}computeTickLimit(){return Math.ceil(this.drawingArea/Po(this.options))}generateTickLabels(t){Ss.prototype.generateTickLabels.call(this,t),this._pointLabels=this.getLabels().map((e,n)=>{let i=ct(this.options.pointLabels.callback,[e,n],this);return i||i===0?i:""}).filter((e,n)=>this.chart.getDataVisibility(n))}fit(){let t=this.options;t.display&&t.pointLabels.display?ng(this):this.setCenterPoint(0,0,0,0)}setCenterPoint(t,e,n,i){this.xCenter+=Math.floor((t-e)/2),this.yCenter+=Math.floor((n-i)/2),this.drawingArea-=Math.min(this.drawingArea/2,Math.max(t,e,n,i))}getIndexAngle(t){let e=ht/(this._pointLabels.length||1),n=this.options.startAngle||0;return Ct(t*e+Ht(n))}getDistanceFromCenterForValue(t){if(tt(t))return NaN;let e=this.drawingArea/(this.max-this.min);return this.options.reverse?(this.max-t)*e:(t-this.min)*e}getValueForDistanceFromCenter(t){if(tt(t))return NaN;let e=t/(this.drawingArea/(this.max-this.min));return this.options.reverse?this.max-e:this.min+e}getPointLabelContext(t){let e=this._pointLabels||[];if(t>=0&&t<e.length){let n=e[t];return gg(this.getContext(),t,n)}}getPointPosition(t,e,n=0){let i=this.getIndexAngle(t)-mt+n;return{x:Math.cos(i)*e+this.xCenter,y:Math.sin(i)*e+this.yCenter,angle:i}}getPointPositionForValue(t,e){return this.getPointPosition(t,this.getDistanceFromCenterForValue(e))}getBasePosition(t){return this.getPointPositionForValue(t||0,this.getBaseValue())}getPointLabelPosition(t){let{left:e,top:n,right:i,bottom:o}=this._pointLabelItems[t];return{left:e,top:n,right:i,bottom:o}}drawBackground(){let{backgroundColor:t,grid:{circular:e}}=this.options;if(t){let n=this.ctx;n.save(),n.beginPath(),Gl(this,this.getDistanceFromCenterForValue(this._endValue),e,this._pointLabels.length),n.closePath(),n.fillStyle=t,n.fill(),n.restore()}}drawGrid(){let t=this.ctx,e=this.options,{angleLines:n,grid:i,border:o}=e,r=this._pointLabels.length,a,l,c;if(e.pointLabels.display&&ug(this,r),i.display&&this.ticks.forEach((d,h)=>{if(h!==0||h===0&&this.min<0){l=this.getDistanceFromCenterForValue(d.value);let u=this.getContext(h),f=i.setContext(u),g=o.setContext(u);fg(this,f,l,r,g)}}),n.display){for(t.save(),a=r-1;a>=0;a--){let d=n.setContext(this.getPointLabelContext(a)),{color:h,lineWidth:u}=d;!u||!h||(t.lineWidth=u,t.strokeStyle=h,t.setLineDash(d.borderDash),t.lineDashOffset=d.borderDashOffset,l=this.getDistanceFromCenterForValue(e.reverse?this.min:this.max),c=this.getPointPosition(a,l),t.beginPath(),t.moveTo(this.xCenter,this.yCenter),t.lineTo(c.x,c.y),t.stroke())}t.restore()}}drawBorder(){}drawLabels(){let t=this.ctx,e=this.options,n=e.ticks;if(!n.display)return;let i=this.getIndexAngle(0),o,r;t.save(),t.translate(this.xCenter,this.yCenter),t.rotate(i),t.textAlign="center",t.textBaseline="middle",this.ticks.forEach((a,l)=>{if(l===0&&this.min>=0&&!e.reverse)return;let c=n.setContext(this.getContext(l)),d=bt(c.font);if(o=this.getDistanceFromCenterForValue(this.ticks[l].value),c.showLabelBackdrop){t.font=d.string,r=t.measureText(a.label).width,t.fillStyle=c.backdropColor;let h=St(c.backdropPadding);t.fillRect(-r/2-h.left,-o-d.size/2-h.top,r+h.width,d.size+h.height)}Ce(t,a.label,0,-o,d,{color:c.color,strokeColor:c.textStrokeColor,strokeWidth:c.textStrokeWidth})}),t.restore()}drawTitle(){}};G(ke,"id","radialLinear"),G(ke,"defaults",{display:!0,animate:!0,position:"chartArea",angleLines:{display:!0,lineWidth:1,borderDash:[],borderDashOffset:0},grid:{circular:!1},startAngle:0,ticks:{showLabelBackdrop:!0,callback:fs.formatters.numeric},pointLabels:{backdropColor:void 0,backdropPadding:2,display:!0,font:{size:10},callback(t){return t},padding:5,centerPointLabels:!1}}),G(ke,"defaultRoutes",{"angleLines.color":"borderColor","pointLabels.color":"color","ticks.color":"color"}),G(ke,"descriptors",{angleLines:{_fallback:"grid"}});ri={millisecond:{common:!0,size:1,steps:1e3},second:{common:!0,size:1e3,steps:60},minute:{common:!0,size:6e4,steps:60},hour:{common:!0,size:36e5,steps:24},day:{common:!0,size:864e5,steps:30},week:{common:!1,size:6048e5,steps:4},month:{common:!0,size:2628e6,steps:12},quarter:{common:!1,size:7884e6,steps:4},year:{common:!0,size:3154e7}},Rt=Object.keys(ri);De=class extends Te{constructor(t){super(t),this._cache={data:[],labels:[],all:[]},this._unit="day",this._majorUnit=void 0,this._offsets={},this._normalized=!1,this._parseOpts=void 0}init(t,e={}){let n=t.time||(t.time={}),i=this._adapter=new yl._date(t.adapters.date);i.init(e),ls(n.displayFormats,i.formats()),this._parseOpts={parser:n.parser,round:n.round,isoWeekday:n.isoWeekday},super.init(t),this._normalized=e.normalized}parse(t,e){return t===void 0?null:ul(this,t)}beforeLayout(){super.beforeLayout(),this._cache={data:[],labels:[],all:[]}}determineDataLimits(){let t=this.options,e=this._adapter,n=t.time.unit||"day",{min:i,max:o,minDefined:r,maxDefined:a}=this.getUserBounds();function l(c){!r&&!isNaN(c.min)&&(i=Math.min(i,c.min)),!a&&!isNaN(c.max)&&(o=Math.max(o,c.max))}(!r||!a)&&(l(this._getLabelBounds()),(t.bounds!=="ticks"||t.ticks.source!=="labels")&&l(this.getMinMax(!1))),i=gt(i)&&!isNaN(i)?i:+e.startOf(Date.now(),n),o=gt(o)&&!isNaN(o)?o:+e.endOf(Date.now(),n)+1,this.min=Math.min(i,o-1),this.max=Math.max(i+1,o)}_getLabelBounds(){let t=this.getLabelTimestamps(),e=Number.POSITIVE_INFINITY,n=Number.NEGATIVE_INFINITY;return t.length&&(e=t[0],n=t[t.length-1]),{min:e,max:n}}buildTicks(){let t=this.options,e=t.time,n=t.ticks,i=n.source==="labels"?this.getLabelTimestamps():this._generate();t.bounds==="ticks"&&i.length&&(this.min=this._userMin||i[0],this.max=this._userMax||i[i.length-1]);let o=this.min,r=this.max,a=qr(i,o,r);return this._unit=e.unit||(n.autoSkip?fl(e.minUnit,this.min,this.max,this._getLabelCapacity(o)):pg(this,a.length,e.minUnit,this.min,this.max)),this._majorUnit=!n.major.enabled||this._unit==="year"?void 0:mg(this._unit),this.initOffsets(i),t.reverse&&a.reverse(),pl(this,a,this._majorUnit)}afterAutoSkip(){this.options.offsetAfterAutoskip&&this.initOffsets(this.ticks.map(t=>+t.value))}initOffsets(t=[]){let e=0,n=0,i,o;this.options.offset&&t.length&&(i=this.getDecimalForValue(t[0]),t.length===1?e=1-i:e=(this.getDecimalForValue(t[1])-i)/2,o=this.getDecimalForValue(t[t.length-1]),t.length===1?n=o:n=(o-this.getDecimalForValue(t[t.length-2]))/2);let r=t.length<3?.5:.25;e=vt(e,0,r),n=vt(n,0,r),this._offsets={start:e,end:n,factor:1/(e+1+n)}}_generate(){let t=this._adapter,e=this.min,n=this.max,i=this.options,o=i.time,r=o.unit||fl(o.minUnit,e,n,this._getLabelCapacity(e)),a=J(i.ticks.stepSize,1),l=r==="week"?o.isoWeekday:!1,c=Oe(l)||l===!0,d={},h=e,u,f;if(c&&(h=+t.startOf(h,"isoWeek",l)),h=+t.startOf(h,c?"day":r),t.diff(n,e,r)>1e5*a)throw new Error(e+" and "+n+" are too far apart with stepSize of "+a+" "+r);let g=i.ticks.source==="data"&&this.getDataTimestamps();for(u=h,f=0;u<n;u=+t.add(u,a,r),f++)gl(d,u,g);return(u===n||i.bounds==="ticks"||f===1)&&gl(d,u,g),Object.keys(d).sort(hl).map(p=>+p)}getLabelForValue(t){let e=this._adapter,n=this.options.time;return n.tooltipFormat?e.format(t,n.tooltipFormat):e.format(t,n.displayFormats.datetime)}format(t,e){let i=this.options.time.displayFormats,o=this._unit,r=e||i[o];return this._adapter.format(t,r)}_tickFormatFunction(t,e,n,i){let o=this.options,r=o.ticks.callback;if(r)return ct(r,[t,e,n],this);let a=o.time.displayFormats,l=this._unit,c=this._majorUnit,d=l&&a[l],h=c&&a[c],u=n[e],f=c&&h&&u&&u.major;return this._adapter.format(t,i||(f?h:d))}generateTickLabels(t){let e,n,i;for(e=0,n=t.length;e<n;++e)i=t[e],i.label=this._tickFormatFunction(i.value,e,t)}getDecimalForValue(t){return t===null?NaN:(t-this.min)/(this.max-this.min)}getPixelForValue(t){let e=this._offsets,n=this.getDecimalForValue(t);return this.getPixelForDecimal((e.start+n)*e.factor)}getValueForPixel(t){let e=this._offsets,n=this.getDecimalForPixel(t)/e.factor-e.end;return this.min+n*(this.max-this.min)}_getLabelSize(t){let e=this.options.ticks,n=this.ctx.measureText(t).width,i=Ht(this.isHorizontal()?e.maxRotation:e.minRotation),o=Math.cos(i),r=Math.sin(i),a=this._resolveTickFontOptions(0).size;return{w:n*o+a*r,h:n*r+a*o}}_getLabelCapacity(t){let e=this.options.time,n=e.displayFormats,i=n[e.unit]||n.millisecond,o=this._tickFormatFunction(t,0,pl(this,[t],this._majorUnit),i),r=this._getLabelSize(o),a=Math.floor(this.isHorizontal()?this.width/r.w:this.height/r.h)-1;return a>0?a:1}getDataTimestamps(){let t=this._cache.data||[],e,n;if(t.length)return t;let i=this.getMatchingVisibleMetas();if(this._normalized&&i.length)return this._cache.data=i[0].controller.getAllParsedValues(this);for(e=0,n=i.length;e<n;++e)t=t.concat(i[e].controller.getAllParsedValues(this));return this._cache.data=this.normalize(t)}getLabelTimestamps(){let t=this._cache.labels||[],e,n;if(t.length)return t;let i=this.getLabels();for(e=0,n=i.length;e<n;++e)t.push(ul(this,i[e]));return this._cache.labels=this._normalized?t:this.normalize(t)}normalize(t){return ji(t.sort(hl))}};G(De,"id","time"),G(De,"defaults",{bounds:"data",adapters:{},time:{parser:!1,unit:!1,round:!1,isoWeekday:!1,minUnit:"millisecond",displayFormats:{}},ticks:{source:"auto",callback:!1,major:{enabled:!1}}});_s=class extends De{constructor(t){super(t),this._table=[],this._minPos=void 0,this._tableRange=void 0}initOffsets(){let t=this._getTimestampsForTable(),e=this._table=this.buildLookupTable(t);this._minPos=qn(e,this.min),this._tableRange=qn(e,this.max)-this._minPos,super.initOffsets(t)}buildLookupTable(t){let{min:e,max:n}=this,i=[],o=[],r,a,l,c,d;for(r=0,a=t.length;r<a;++r)c=t[r],c>=e&&c<=n&&i.push(c);if(i.length<2)return[{time:e,pos:0},{time:n,pos:1}];for(r=0,a=i.length;r<a;++r)d=i[r+1],l=i[r-1],c=i[r],Math.round((d+l)/2)!==c&&o.push({time:c,pos:r/(a-1)});return o}_generate(){let t=this.min,e=this.max,n=super.getDataTimestamps();return(!n.includes(t)||!n.length)&&n.splice(0,0,t),(!n.includes(e)||n.length===1)&&n.push(e),n.sort((i,o)=>i-o)}_getTimestampsForTable(){let t=this._cache.all||[];if(t.length)return t;let e=this.getDataTimestamps(),n=this.getLabelTimestamps();return e.length&&n.length?t=this.normalize(e.concat(n)):t=e.length?e:n,t=this._cache.all=t,t}getDecimalForValue(t){return(qn(this._table,t)-this._minPos)/this._tableRange}getValueForPixel(t){let e=this._offsets,n=this.getDecimalForPixel(t)/e.factor-e.end;return qn(this._table,n*this._tableRange+this._minPos,!0)}};G(_s,"id","timeseries"),G(_s,"defaults",De.defaults);ql=Object.freeze({__proto__:null,CategoryScale:ys,LinearScale:xs,LogarithmicScale:Cs,RadialLinearScale:ke,TimeScale:De,TimeSeriesScale:_s}),vg=[vl,Pl,Kl,ql]});var Bg={};Uo(Bg,{CardView:()=>Ms,default:()=>pi});module.exports=wc(Bg);var it=require("obsidian"),vc=dn(Ls());var Mc=["AT","BE","CZ","DK","EE","FI","FR","DE","GR","HU","IS","IT","LV","LI","LT","LU","MT","NL","NO","PL","PT","SK","SI","ES","SE","CH"],Dc=[{label:"\u{1F1EA}\u{1F1FA} Schengen 90/180 (example)",scope:{countries:Mc},window:{type:"rolling",days:180},threshold:90,note:"Example rule \u2014 add your own in Settings \u2192 CSV Card View."}],xi={defaultMode:"kanban-genre",notesColumns:["notes","note","Notes","Note","description","Description","review","Review"],statusColumn:"status",categoryColumn:"category",notesSubfolder:"Notes",columnWidths:{},selectColumns:["Category","Type","Rating","Status","rating","type","category","status","Score /5"],fileConfigs:{},residencyRules:Dc,showResidency:!0},hn="xlsx-card-view";var Ko=dn(Ls()),Go=require("obsidian"),Ke=["Image","image","Cover","cover","Poster","poster","Thumbnail","thumbnail","Thumb","thumb","Photo","photo","Picture","picture","Img","img"],Ge=["Title","title","Name","name"],qe=["Category","category","Categories","categories","Genre","genre","Genres","genres","Type","type","Types","types","Tag","tag","Tags","tags","Topic","topic","Topics","topics","Subject","subject","Section","section"],Xe=["Status","status","State","state","Progress","progress","Stage","stage","Read","read","Watched","watched","Seen","seen","Done","done","Completed","completed"],Qe=["Notes","notes","Note","note","Summary","summary","Review","review","Quote","quote","Quotes","quotes","Comment","comment","Comments","comments","Description","description","Annotation","annotation"];function un(s,t,e){let n=(t!=null?t:"").trim();if(!n)return null;if(/^(https?:|data:)/i.test(n))return n;let i=n.match(/!?\[\[([^\]|]+)(?:\|[^\]]*)?\]\]/);if(i)n=i[1].trim();else{let r=n.match(/!\[[^\]]*\]\(([^)]+)\)/);r&&(n=r[1].trim())}if(/^(https?:|data:)/i.test(n))return n;let o=s.metadataCache.getFirstLinkpathDest(n,e);return o instanceof Go.TFile?s.vault.getResourcePath(o):null}var Tc=15;function Xt(s){return s>=1&&s<=Tc}var Lc=["0","1","true","false","yes","no",""];function Ze(s){return s.length>0&&s.every(t=>Lc.includes(t))}function Je(s){let t=(s!=null?s:"").toLowerCase().trim();return t==="1"||t==="true"||t==="yes"}function ts(s=new Date){return`${s.getFullYear()}-${String(s.getMonth()+1).padStart(2,"0")}-${String(s.getDate()).padStart(2,"0")}`}function As(s){return s.replace(/[\\/:*?"<>|#^[\]]/g,"").replace(/\s+/g," ").trim().slice(0,100)}function qo(s){return s.toLowerCase().replace(/[^\p{L}\p{N}/_-]+/gu,"-").replace(/-+/g,"-").replace(/^-+|-+$/g,"")}function Bt(s){var i,o;if(!s||!s.trim())return{headers:[],rows:[]};let t=Ko.default.parse(s,{header:!0,skipEmptyLines:!0}),e=((i=t.meta.fields)!=null?i:[]).map(String),n=((o=t.data)!=null?o:[]).map(r=>{let a={};return e.forEach(l=>{a[l]=r[l]!=null?String(r[l]):""}),a});return{headers:e,rows:n}}function ue(s,t){if(!s)return s;let e=s.startsWith("./")||s.startsWith("../")||s==="."||s==="..";if(!e&&s.includes("/"))return s;if(!e)return t?`${t}/${s}`:s;let n=t?t.split("/").filter(Boolean):[];for(let i of s.split("/"))if(!(i===""||i===".")){if(i===".."){n.pop();continue}n.push(i)}return n.join("/")}function Xo(s,t,e){let n=e==="asc"?1:-1;return[...s].sort((i,o)=>{var u,f;let r=((u=i[t])!=null?u:"").trim(),a=((f=o[t])!=null?f:"").trim();if(!r&&!a)return 0;if(!r)return 1;if(!a)return-1;let l=parseFloat(r),c=parseFloat(a);return(!isNaN(l)&&!isNaN(c)&&/^-?[\d.]/.test(r)&&/^-?[\d.]/.test(a)?l-c:r.localeCompare(a,void 0,{numeric:!0,sensitivity:"base"}))*n})}function kt(s){return s.split(/[\s_-]+/).map(t=>t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()).join(" ")}function Qo(s,t){let e=(s!=null?s:"").trim();if(!e||e.toLowerCase()==="unrated"||e==="\u2014"||e==="-")return"";if(/[★⭐☆]/.test(e))return e;if(/^\d+$/.test(e)){let o=parseInt(e,10);if(o>=1&&o<=5)return"\u2605".repeat(o)}let i=Ac(e,t);return i&&i!==e&&i!=="\u2014"?i:""}function Ac(s,t){var o;let e=t.toLowerCase();if(!["rating","score","score /5"].includes(e))return s;let n=s.toLowerCase().trim();return(o={excellent:"\u2605\u2605\u2605\u2605\u2605",great:"\u2605\u2605\u2605\u2605\u2605",good:"\u2605\u2605\u2605\u2605\u2606",fair:"\u2605\u2605\u2605\u2606\u2606",poor:"\u2605\u2605\u2606\u2606\u2606",bad:"\u2605\u2606\u2606\u2606\u2606",5:"\u2605\u2605\u2605\u2605\u2605",4:"\u2605\u2605\u2605\u2605\u2606",3:"\u2605\u2605\u2605\u2606\u2606",2:"\u2605\u2605\u2606\u2606\u2606",1:"\u2605\u2606\u2606\u2606\u2606",0:"\u2606\u2606\u2606\u2606\u2606",unrated:"\u2014","":"\u2014"}[n])!=null?o:s}function Zo(s,t){if(/^(year|released|decade)$/i.test((s!=null?s:"").trim()))return!0;let e=t.map(i=>(i!=null?i:"").trim()).filter(Boolean);return e.length<3?!1:e.filter(i=>/^(1[89]|20)\d{2}$/.test(i)).length/e.length>=.8}function Jo(s){let t=(s!=null?s:"").match(/\b(1[89]\d{2}|20\d{2})\b/);return t?`${Math.floor(parseInt(t[1],10)/10)*10}s`:null}function tr(s,t,e){var r;if(!t.length)return null;let n=Math.max(12,t.length/3),i=null,o=1/0;for(let a of s){if(e.has(a))continue;let l=new Set;for(let d of t)((r=d[a])!=null?r:"").split(",").forEach(h=>{let u=h.trim();u&&l.add(u)});if(l.size<2||l.size>n)continue;let c=Math.abs(Math.log(l.size/8));c<o&&(o=c,i=a)}return i}function xt(s){return/^(categor(y|ies)|genres?|tags?|themes?|topics?)$/i.test((s!=null?s:"").trim())}function Ft(s,t,e,n,i,o){var D;document.body.querySelectorAll(".csv-select-picker").forEach(k=>k.remove());let r=document.body.createDiv({cls:"csv-select-picker"});r.style.position="fixed",r.style.zIndex="9999";let a=()=>{let k=s.getBoundingClientRect(),T=r.offsetHeight||280,A=k.bottom+4+T>window.innerHeight&&k.top-4-T>0;r.style.left=k.left+"px",r.style.top=A?k.top-4-T+"px":k.bottom+4+"px"};a();let l=k=>{!r.contains(k.target)&&k.target!==s&&d()},c=k=>{r.contains(k.target)||d()},d=()=>{r.remove(),document.removeEventListener("mousedown",l),window.removeEventListener("scroll",c,!0),window.removeEventListener("resize",d)},h=r.createEl("input",{cls:"csv-picker-search",type:"text",placeholder:"Search or add\u2026"});h.focus();let u=r.createDiv({cls:"csv-picker-list"}),f=!!(o!=null&&o.multi),g=k=>k.split(",").map(T=>T.trim()).filter(Boolean),p=new Set(f?g(t):[]),b=()=>n([...p].join(", ")),m=f?Array.from(new Set(e.flatMap(g))):Array.from(new Set(e.filter(Boolean))),y=[],C=0,E=()=>{u.querySelectorAll(".csv-picker-item").forEach((k,T)=>{k.toggleClass("csv-picker-item--hover",T===C),T===C&&k.scrollIntoView({block:"nearest"})})},S=k=>{if(!f){n(k.isClear?"":k.value),d();return}k.isClear?p.clear():(p.has(k.value)?p.delete(k.value):p.add(k.value),k.isAdd&&!m.includes(k.value)&&m.push(k.value)),b(),k.isAdd?(h.value="",_("")):_(h.value)},x=k=>f?p.has(k):k===t,v=()=>f?p.size>0:!!t,_=k=>{u.empty(),y=[];let T=k?m.filter(A=>A.toLowerCase().includes(k.toLowerCase())):m;if(v()){y.push({value:"",isClear:!0});let A=u.createDiv({cls:"csv-picker-item csv-picker-clear"});A.setText(f?"\u2715 Clear all":"\u2715 Clear"),A.addEventListener("mousedown",I=>{I.preventDefault(),S({value:"",isClear:!0})})}if(T.forEach(A=>{y.push({value:A});let I=u.createDiv({cls:`csv-picker-item ${x(A)?"active":""}`});I.setText(f?`${p.has(A)?"\u2713 ":""}${A}`:A),I.addEventListener("mousedown",V=>{V.preventDefault(),S({value:A})})}),k&&!m.some(A=>A.toLowerCase()===k.toLowerCase())){y.push({value:k,isAdd:!0});let A=u.createDiv({cls:"csv-picker-item csv-picker-add"});A.setText(`+ Add "${k}"`),A.addEventListener("mousedown",I=>{I.preventDefault(),S({value:k,isAdd:!0})})}!T.length&&!k&&u.createDiv({cls:"csv-picker-empty",text:"No options yet. Type to add."}),C=Math.min(C,Math.max(y.length-1,0)),E()};f&&r.createEl("button",{cls:"csv-picker-done",text:"Done"}).addEventListener("mousedown",k=>{k.preventDefault(),d()}),_(""),a(),h.addEventListener("input",()=>{C=0,_(h.value),a()});let w=typeof window!="undefined"&&((D=window.matchMedia)==null?void 0:D.call(window,"(pointer: coarse)").matches);setTimeout(()=>{document.addEventListener("mousedown",l),w||(window.addEventListener("scroll",c,!0),window.addEventListener("resize",d))},0),h.addEventListener("keydown",k=>{if(k.key==="Escape"){d();return}if(k.key==="ArrowDown"){k.preventDefault(),y.length&&(C=(C+1)%y.length,E());return}if(k.key==="ArrowUp"){k.preventDefault(),y.length&&(C=(C-1+y.length)%y.length,E());return}if(k.key==="Enter")if(k.preventDefault(),y[C])S(y[C]);else{let T=h.value.trim();T&&(n(T),d())}})}function er(s,t,e){return!s[t]||t===e||(s[e]||(s[e]=s[t]),delete s[t]),s}var Rc={source:["confirmed","inferred","conflict"],resolved:["yes","no"]};function sr(s){var t;return(t=Rc[s.trim().toLowerCase()])!=null?t:null}function wt(s){return/(^|[_\s-])(date|due|deadline)([_\s-]|$)/i.test(s.trim())}var fn=/^\d{4}-\d{2}-\d{2}$/;var It=require("obsidian");function mn(s,t,e,n,i=wt){let o=i(t)&&(e===""||fn.test(e.slice(0,10))),r=o?e.slice(0,10):e,a=s.createEl("input",{cls:n,type:o?"date":"text",value:r});o||(a.placeholder=t);let l=sr(t);if(l){let c=`csv-dl-${t.toLowerCase().replace(/[^a-z0-9]+/g,"-")}-${Math.random().toString(36).slice(2,7)}`,d=s.createEl("datalist");d.id=c,l.forEach(h=>d.createEl("option",{value:h})),a.setAttr("list",c)}return a}var es=class extends It.Modal{constructor(t,e,n,i,o,r,a={},l=()=>!1,c,d,h=wt){super(t),this.headers=e,this.isNotesCol=n,this.isSelectCol=i,this.getColumnValues=o,this.onSubmit=r,this.optionPresets=a,this.isBooleanCol=l,this.isCategoricalCol=c!=null?c:u=>this.isSelectCol(u)||Xt(this.getColumnValues(u).length),this.titleCol=d!=null?d:this.headers.find(u=>["title","name"].includes(u.toLowerCase())),this.isDateCol=h}onOpen(){let{contentEl:t}=this;t.empty(),t.addClass("csv-add-modal"),t.createEl("h2",{text:"Add new entry",cls:"csv-modal-title"});let e=t.createDiv({cls:"csv-modal-form"}),n={};this.headers.forEach(d=>n[d]="");let i=this.titleCol,o=new Map;i&&this.getColumnValues(i).forEach(d=>{let h=d.trim().toLowerCase();h&&!o.has(h)&&o.set(h,d.trim())}),this.headers.forEach(d=>{var b;let h=e.createDiv({cls:"csv-modal-row"});h.createEl("label",{text:kt(d),cls:"csv-modal-label"});let u=(b=this.optionPresets[d])!=null?b:[],f=d===i,g=xt(d),p=!f&&!this.isNotesCol(d)&&!g&&(u.length>0||this.isCategoricalCol(d));if(this.isBooleanCol(d)){n[d]="0";let m=h.createDiv({cls:"csv-toggle"});m.createDiv({cls:"csv-toggle-knob"}),m.addEventListener("click",()=>{let y=!m.hasClass("is-on");m.toggleClass("is-on",y),n[d]=y?"1":"0"})}else if(this.isNotesCol(d)){let m=h.createEl("textarea",{cls:"csv-modal-textarea",placeholder:"Markdown supported\u2026"});m.addEventListener("input",()=>{n[d]=m.value})}else if(p){let m="__custom__",y=[];[...u,...this.getColumnValues(d)].forEach(S=>{let x=(S!=null?S:"").trim();x&&!y.some(v=>v.toLowerCase()===x.toLowerCase())&&y.push(x)});let C=h.createEl("select",{cls:"csv-modal-select"});C.createEl("option",{text:"\u2014",value:""}),y.forEach(S=>C.createEl("option",{text:S,value:S})),C.createEl("option",{text:"+ Custom\u2026",value:m});let E=h.createEl("input",{cls:"csv-modal-input csv-modal-custom",type:"text",placeholder:`Custom ${kt(d).toLowerCase()}`});E.hide(),E.addEventListener("input",()=>{n[d]=E.value}),E.addEventListener("keydown",S=>{S.key==="Enter"&&c()}),C.addEventListener("change",()=>{C.value===m?(E.show(),E.focus(),n[d]=E.value):(E.hide(),n[d]=C.value)})}else if(!f&&g&&this.isSelectCol(d)){let y=h.createDiv({cls:"csv-modal-select-wrap"}).createDiv({cls:"csv-select-chip empty"});y.setText("\u2014 click to select \u2014"),y.addEventListener("click",C=>{C.stopPropagation(),Ft(y,n[d],this.getColumnValues(d),E=>{n[d]=E,y.setText(E||"\u2014 click to select \u2014"),y.toggleClass("empty",!E)},t,{multi:xt(d)})})}else{let m=mn(h,d,"","csv-modal-input",y=>this.isDateCol(y));if(m.addEventListener("input",()=>{n[d]=m.value}),m.addEventListener("keydown",y=>{y.key==="Enter"&&c()}),d===i&&o.size){let y=h.createDiv({cls:"csv-modal-dup-hint"});y.hide(),m.addEventListener("input",()=>{let C=o.get(m.value.trim().toLowerCase());C?(y.setText(`\u26A0 \u201C${C}\u201D is already in this file`),y.show()):y.hide()})}}});let r=t.createDiv({cls:"csv-modal-btns"});r.createEl("button",{text:"Cancel",cls:"csv-modal-cancel"}).addEventListener("click",()=>this.close()),r.createEl("button",{text:"Add entry",cls:"csv-modal-submit"}).addEventListener("click",()=>c());let c=()=>{if(!Object.values(n).some(h=>h.trim())){new It.Notice("Fill in at least one field.");return}this.onSubmit(n),this.close()}}onClose(){this.contentEl.empty()}},ss=class extends It.Modal{constructor(e,n,i,o,r,a,l,c,d,h,u,f,g=()=>!1,p=wt){super(e);this.vvHandler=null;this.row={...n},this.notesCol=i,this.headers=o,this.filePath=r,this.renderComponent=new It.Component,this.isNotesCol=a,this.isSelectCol=l,this.getColumnValues=c,this.onSave=d,this.onDelete=h,this.isCategoricalCol=u!=null?u:b=>this.isSelectCol(b)||!wt(b)&&Xt(this.getColumnValues(b).length),this.titleCol=f!=null?f:this.headers.find(b=>["title","name","Title","Name"].includes(b)),this.isBooleanCol=g,this.isDateCol=p,this.modalEl.addClass("csv-note-expander-modal")}onOpen(){var g,p,b,m,y;this.renderComponent.load();let{contentEl:e}=this;e.empty(),e.addClass("csv-note-expander");let n=window.visualViewport;if(n){let C=()=>{this.modalEl.style.setProperty("--csv-modal-vh",`${n.height}px`)};C(),n.addEventListener("resize",C),n.addEventListener("scroll",C),this.vvHandler=C}let i=e.createDiv({cls:"csv-expander-header"});i.createDiv({cls:"csv-expander-title",text:(p=this.row[(g=this.titleCol)!=null?g:this.headers[0]])!=null?p:"\u2014"});let o=i.createDiv({cls:"csv-expander-header-btns"}),r=e.createDiv({cls:"csv-expander-fields"}),a=this.titleCol,l=this.headers.find(C=>["author","Author","director","Director","artist","Artist","creator","Creator"].includes(C));this.headers.forEach(C=>{var v;if(this.isNotesCol(C))return;let E=r.createDiv({cls:"csv-expander-field-row"});if(E.createDiv({cls:"csv-expander-field-label",text:kt(C)}),this.isBooleanCol(C)){let _=Je((v=this.row[C])!=null?v:""),w=E.createDiv({cls:`csv-toggle ${_?"is-on":""}`});w.createDiv({cls:"csv-toggle-knob"}),w.addEventListener("click",()=>{let D=!w.hasClass("is-on");w.toggleClass("is-on",D),this.row[C]=D?"1":"0"});return}let S=xt(C);if(C!==a&&(S?this.isSelectCol(C):this.isCategoricalCol(C))){let _=E.createDiv({cls:`csv-select-chip ${this.row[C]?"":"empty"}`});_.setText(this.row[C]||"\u2014"),_.addEventListener("click",w=>{w.stopPropagation(),Ft(_,this.row[C],this.getColumnValues(C),D=>{this.row[C]=D,_.setText(D||"\u2014"),_.toggleClass("empty",!D)},e,{multi:xt(C)})})}else{let _=E.createDiv({cls:"csv-expander-field-value",text:this.row[C]||"\u2014"});_.addEventListener("click",()=>{var k;if(_.querySelector("input"))return;_.empty();let w=mn(_,C,(k=this.row[C])!=null?k:"","csv-inline-input",this.isDateCol);w.focus(),w.type==="text"&&w.select(),w.addEventListener("click",T=>T.stopPropagation());let D=()=>{this.row[C]=w.value,_.empty(),_.setText(w.value||"\u2014")};w.addEventListener("blur",D),w.addEventListener("keydown",T=>{T.key==="Enter"&&w.blur(),T.key==="Escape"&&(_.empty(),_.setText(this.row[C]||"\u2014"))})})}});let c=!1,d=this.notesCol&&(b=this.row[this.notesCol])!=null?b:"",h=null;if(this.notesCol){e.createDiv({cls:"csv-expander-divider"}).createDiv({cls:"csv-expander-notes-label",text:this.notesCol});let E=e.createDiv({cls:"csv-expander-rendered markdown-rendered"});E.title="Click to edit";let S=e.createDiv({cls:"csv-expander-editor"});S.style.display="none";let x=()=>{E.empty(),d.trim()?It.MarkdownRenderer.render(this.app,d,E,this.filePath,this.renderComponent):E.createDiv({cls:"csv-notes-empty",text:"+ Add note"})};x(),h=S.createEl("textarea",{cls:"csv-expander-textarea"}),h.value=d,h.addEventListener("input",()=>{d=h.value});let v=()=>{c||(c=!0,E.style.display="none",S.style.display="flex",h.value=d,h.focus())},_=()=>{c&&(c=!1,S.style.display="none",E.style.display="",d=h.value,x())};E.addEventListener("click",w=>{if(w.target.closest("a, button, input, textarea, [contenteditable]"))return;let k=window.getSelection();k&&k.toString().length>0||v()}),h.addEventListener("keydown",w=>{w.key==="Escape"&&(w.preventDefault(),h.blur())}),h.addEventListener("blur",_)}let u=e.createDiv({cls:"csv-expander-footer"});if(this.onDelete){let C=String((y=this.row[(m=this.titleCol)!=null?m:this.headers[0]])!=null?y:"").trim();u.createEl("button",{cls:"csv-expander-delete-btn",text:"Delete"}).addEventListener("click",()=>{let E=C||"this entry";window.confirm(`Delete "${E}"? This can't be undone.`)&&(this.onDelete(),this.close())})}let f=u.createDiv({cls:"csv-expander-footer-right"});f.createEl("button",{cls:"csv-modal-cancel",text:"Cancel"}).addEventListener("click",()=>this.close()),f.createEl("button",{cls:"csv-expander-save-btn",text:"Save & close"}).addEventListener("click",()=>{this.notesCol&&(c&&h&&(d=h.value),this.row[this.notesCol]=d),this.onSave(this.row),this.close()})}onClose(){let e=window.visualViewport;e&&this.vvHandler&&(e.removeEventListener("resize",this.vvHandler),e.removeEventListener("scroll",this.vvHandler)),this.vvHandler=null,this.renderComponent.unload(),this.contentEl.empty()}};var gn=class extends It.Modal{constructor(t,e,n,i,o,r,a,l,c,d,h,u,f,g=()=>0){super(t),this.headers=e,this.filePath=n,this.current={...i,habitColumns:i.habitColumns?[...i.habitColumns]:void 0,categoricalColumns:i.categoricalColumns?[...i.categoricalColumns]:void 0},this.autoDetectedHabits=o,this.autoDetectedCategorical=r,this.autoDetectedRoles=a,this.availableModes=l,this.onSave=c,this.getHeaders=d,this.getFileCfg=h,this.onAddColumn=u,this.onRemoveColumn=f,this.onCleanupBooleanColumn=g}onOpen(){var I,V,O;let{contentEl:t}=this;t.empty(),t.addClass("csv-add-modal"),t.createEl("h2",{text:"View settings for this file",cls:"csv-modal-title"}),t.createEl("p",{text:"These settings apply only to this file and override the global defaults.",cls:"csv-modal-desc"});let e=t.createDiv({cls:"csv-modal-form"}),n=()=>{this.headers=this.getHeaders();let M=this.getFileCfg();this.current={...M,habitColumns:M.habitColumns?[...M.habitColumns]:void 0,categoricalColumns:M.categoricalColumns?[...M.categoricalColumns]:void 0},this.onOpen()},i=e.createDiv({cls:"csv-modal-row"});i.createEl("label",{text:"Columns",cls:"csv-modal-label"}),i.createEl("p",{cls:"csv-modal-hint",text:`Type and Function are each exclusive per column \u2014 picking one clears it from whichever column held it before. "auto" means it's already doing that by column name, with nothing saved here yet. Card field is independent and can combine with anything. Checkbox columns get a "Clean up" action that rewrites every row to strict 1/0 right away \u2014 not deferred to Save.`});let o=[{value:"text",label:"Text"},{value:"checkbox",label:"Checkbox"},{value:"categorical",label:"Categorical"},{value:"date",label:"Date"}],r=[{value:"",label:"\u2014 no function \u2014"},{value:"title",label:"Title"},{value:"category",label:"Column group (Kanban lanes)"},{value:"status",label:"Row group / Status / Checkmark"},{value:"notes",label:"Notes"},{value:"image",label:"Image (card / kanban thumbnail)"},{value:"anki",label:"Anki card front"}],a=M=>{var $,R,W;let j=($=this.current.habitColumns)!=null?$:this.autoDetectedHabits,F=(R=this.current.categoricalColumns)!=null?R:this.autoDetectedCategorical,Y=(W=this.current.dateColumns)!=null?W:this.headers.filter(K=>wt(K));return j.includes(M)?{type:"checkbox",auto:!this.current.habitColumns}:F.includes(M)?{type:"categorical",auto:!this.current.categoricalColumns}:Y.includes(M)?{type:"date",auto:!this.current.dateColumns}:{type:"text",auto:!1}},l=(M,j)=>{this.current.habitColumns||(this.current.habitColumns=[...this.autoDetectedHabits]),this.current.categoricalColumns||(this.current.categoricalColumns=[...this.autoDetectedCategorical]),this.current.dateColumns||(this.current.dateColumns=this.headers.filter(F=>wt(F))),this.current.habitColumns=this.current.habitColumns.filter(F=>F!==M),this.current.categoricalColumns=this.current.categoricalColumns.filter(F=>F!==M),this.current.dateColumns=this.current.dateColumns.filter(F=>F!==M),j==="checkbox"?this.current.habitColumns.push(M):j==="categorical"?this.current.categoricalColumns.push(M):j==="date"&&this.current.dateColumns.push(M)},c=(V=(I=this.current.titleColumn)!=null?I:this.autoDetectedRoles.title)!=null?V:this.headers[0],h=i.createDiv({cls:"csv-modal-colcfg-table-wrap"}).createEl("table",{cls:"csv-modal-colcfg-table"}),u=h.createEl("thead").createEl("tr");["Column","Type","Visibility"].forEach(M=>u.createEl("th",{text:M}));let f=h.createEl("tbody"),g=()=>{var j;f.empty();let M=new Set((j=this.current.cardFields)!=null?j:this.headers);this.headers.forEach(F=>{let Y=f.createEl("tr"),$=Y.createEl("td",{cls:"csv-modal-colcfg-name"});$.createSpan({text:F});let R=$.createEl("button",{cls:"csv-modal-column-remove",text:"\u2715",attr:{title:`Remove "${F}" \u2014 deletes this column's data from every row`}});R.addEventListener("click",()=>{if(R.hasClass("confirm")){this.onRemoveColumn(F),n();return}f.querySelectorAll(".csv-modal-column-remove.confirm").forEach(P=>{P.removeClass("confirm"),P.setText("\u2715")}),R.addClass("confirm"),R.setText("Confirm?"),window.setTimeout(()=>{R.isConnected&&(R.removeClass("confirm"),R.setText("\u2715"))},3e3)});let W=Y.createEl("td",{cls:"csv-modal-colcfg-type-cell"});if(F===c)W.createSpan({cls:"csv-modal-colcfg-fixed",text:"Text"});else{let P=W.createEl("select",{cls:"csv-modal-select csv-modal-colcfg-type"}),{type:L,auto:z}=a(F);if(o.forEach(B=>{let H=P.createEl("option",{text:B.label,value:B.value});B.value===L&&(H.selected=!0)}),z&&P.addClass("auto-detected"),P.addEventListener("change",()=>{l(F,P.value),g()}),z&&W.createSpan({cls:"csv-modal-colcfg-auto-badge",text:"auto"}),L==="checkbox"){let B=W.createEl("button",{cls:"csv-modal-colcfg-cleanup-btn",text:"Clean up",attr:{title:`Rewrite every row in "${F}" to strict 1/0 (yes/true/1 \u2192 1, everything else \u2192 0)`}});B.addEventListener("click",()=>{if(B.hasClass("confirm")){let H=this.onCleanupBooleanColumn(F);new It.Notice(H>0?`"${F}": normalized ${H} row${H===1?"":"s"} to 1/0.`:`"${F}" is already strict 1/0 \u2014 nothing to change.`);return}f.querySelectorAll(".csv-modal-colcfg-cleanup-btn.confirm").forEach(H=>{H.removeClass("confirm"),H.setText("Clean up")}),B.addClass("confirm"),B.setText("Confirm?"),window.setTimeout(()=>{B.isConnected&&(B.removeClass("confirm"),B.setText("Clean up"))},3e3)})}}let N=Y.createEl("td",{cls:"csv-modal-colcfg-card-cell"}).createEl("input",{type:"checkbox"});N.checked=M.has(F),N.addEventListener("change",()=>{this.current.cardFields||(this.current.cardFields=[...this.headers]),N.checked?this.current.cardFields.includes(F)||this.current.cardFields.push(F):this.current.cardFields=this.current.cardFields.filter(P=>P!==F)})})};g();let p=t.createDiv({cls:"csv-modal-section",attr:{style:"margin-top: 24px;"}});p.createEl("h3",{text:"Column Functions",cls:"csv-modal-h3"}),p.createEl("p",{cls:"csv-modal-desc",text:"Assign specific roles to your columns. 'auto' means it's already doing that by column name. Selecting '\u2014 none \u2014' disables the function entirely."});let m=p.createDiv({cls:"csv-modal-colcfg-table-wrap"}).createEl("table",{cls:"csv-modal-colcfg-table"}),y=m.createEl("thead").createEl("tr");["Function","Column"].forEach(M=>y.createEl("th",{text:M}));let C=m.createEl("tbody"),E=()=>{C.empty(),r.forEach(M=>{var K,N,P,L,z,B,H,U,q,X,Z,at;if(M.value==="")return;let j=C.createEl("tr");j.createEl("td",{cls:"csv-modal-colcfg-name"}).setText(M.label);let Y=j.createEl("td",{cls:"csv-modal-colcfg-type-cell"}),$=Y.createEl("select",{cls:"csv-modal-select csv-modal-colcfg-role"});$.createEl("option",{text:"\u2014 none \u2014",value:""});let R="",W=!1;M.value==="title"?(R=(N=(K=this.current.titleColumn)!=null?K:this.autoDetectedRoles.title)!=null?N:"",W=this.current.titleColumn===void 0&&!!this.autoDetectedRoles.title):M.value==="category"?(R=(L=(P=this.current.categoryColumn)!=null?P:this.autoDetectedRoles.category)!=null?L:"",W=this.current.categoryColumn===void 0&&!!this.autoDetectedRoles.category):M.value==="status"?(R=(B=(z=this.current.statusColumn)!=null?z:this.autoDetectedRoles.status)!=null?B:"",W=this.current.statusColumn===void 0&&!!this.autoDetectedRoles.status):M.value==="notes"?(R=(U=(H=this.current.notesColumn)!=null?H:this.autoDetectedRoles.notes)!=null?U:"",W=this.current.notesColumn===void 0&&!!this.autoDetectedRoles.notes):M.value==="image"?(R=(X=(q=this.current.imageColumn)!=null?q:this.autoDetectedRoles.image)!=null?X:"",W=this.current.imageColumn===void 0&&!!this.autoDetectedRoles.image):M.value==="anki"&&(R=(at=(Z=this.current.ankiFrontCol)!=null?Z:this.autoDetectedRoles.anki)!=null?at:"",W=this.current.ankiFrontCol===void 0&&!!this.autoDetectedRoles.anki),this.headers.forEach(Q=>{let st=$.createEl("option",{text:Q,value:Q});Q===R&&(st.selected=!0)}),W&&R!==""&&$.addClass("auto-detected"),$.addEventListener("change",()=>{let Q=$.value;Q&&(M.value!=="title"&&this.current.titleColumn===Q&&(this.current.titleColumn=void 0),M.value!=="category"&&this.current.categoryColumn===Q&&(this.current.categoryColumn=void 0),M.value!=="status"&&this.current.statusColumn===Q&&(this.current.statusColumn=void 0),M.value!=="notes"&&this.current.notesColumn===Q&&(this.current.notesColumn=void 0),M.value!=="image"&&this.current.imageColumn===Q&&(this.current.imageColumn=void 0),M.value!=="anki"&&this.current.ankiFrontCol===Q&&(this.current.ankiFrontCol=void 0)),M.value==="title"?this.current.titleColumn=Q:M.value==="category"?this.current.categoryColumn=Q:M.value==="status"?this.current.statusColumn=Q:M.value==="notes"?this.current.notesColumn=Q:M.value==="image"?this.current.imageColumn=Q:M.value==="anki"&&(this.current.ankiFrontCol=Q),E()}),W&&R!==""&&Y.createSpan({cls:"csv-modal-colcfg-auto-badge",text:"auto"})})};E();let S=i.createDiv({cls:"csv-modal-add-column"}),x=S.createEl("input",{cls:"csv-modal-input",type:"text",placeholder:"New column name"}),v=S.createEl("button",{cls:"csv-modal-cancel",text:"+ Add column"}),_=()=>{let M=this.onAddColumn(x.value);if(M){new It.Notice(M);return}n()};v.addEventListener("click",_),x.addEventListener("keydown",M=>{M.key==="Enter"&&(M.preventDefault(),_())});let w=e.createDiv({cls:"csv-modal-row"});w.createEl("label",{text:"Default view",cls:"csv-modal-label"});let D=w.createEl("select",{cls:"csv-modal-select"}),k=[["\u2014 use global default \u2014",""],...this.availableModes.map(M=>[M.label,M.id])],T=(O=this.current.defaultMode)!=null?O:"";T&&!this.availableModes.some(M=>M.id===T)&&k.push([`${T} (no longer available)`,T]),k.forEach(([M,j])=>{let F=D.createEl("option",{text:M,value:j});T===j&&(F.selected=!0)}),D.addEventListener("change",()=>{this.current.defaultMode=D.value?D.value:void 0});let A=t.createDiv({cls:"csv-modal-btns"});A.createEl("button",{text:"Cancel",cls:"csv-modal-cancel"}).addEventListener("click",()=>this.close()),A.createEl("button",{text:"Save",cls:"csv-modal-submit"}).addEventListener("click",()=>{this.onSave(this.current),this.close()})}onClose(){this.contentEl.empty()}},pn=class extends It.Modal{constructor(e,n,i,o,r){super(e);this.title=n;this.initial=i;this.placeholder=o;this.onSubmit=r}onOpen(){let{contentEl:e}=this;e.empty(),e.addClass("csv-add-modal"),e.createEl("h2",{text:this.title,cls:"csv-modal-title"});let n=e.createEl("input",{cls:"csv-modal-field",type:"text"});n.value=this.initial,n.placeholder=this.placeholder,window.setTimeout(()=>{n.focus(),n.select()},0);let i=()=>{let r=n.value.trim();r&&(this.onSubmit(r),this.close())};n.addEventListener("keydown",r=>{r.key==="Enter"&&(r.preventDefault(),i())});let o=e.createDiv({cls:"csv-modal-btns"});o.createEl("button",{text:"Cancel",cls:"csv-modal-cancel"}).addEventListener("click",()=>this.close()),o.createEl("button",{text:"Create",cls:"csv-modal-submit"}).addEventListener("click",i)}onClose(){this.contentEl.empty()}};var Ci=195,Pc={AF:"Afghanistan",AL:"Albania",DZ:"Algeria",AD:"Andorra",AO:"Angola",AR:"Argentina",AM:"Armenia",AU:"Australia",AT:"Austria",AZ:"Azerbaijan",BD:"Bangladesh",BY:"Belarus",BE:"Belgium",BO:"Bolivia",BA:"Bosnia",BW:"Botswana",BR:"Brazil",BG:"Bulgaria",KH:"Cambodia",CM:"Cameroon",CA:"Canada",CL:"Chile",CN:"China",CO:"Colombia",HR:"Croatia",CU:"Cuba",CY:"Cyprus",CZ:"Czechia",DK:"Denmark",DO:"Dominican Rep.",EC:"Ecuador",EG:"Egypt",ET:"Ethiopia",FI:"Finland",FR:"France",GE:"Georgia",DE:"Germany",GH:"Ghana",GR:"Greece",GT:"Guatemala",GY:"Guyana",HT:"Haiti",HN:"Honduras",HU:"Hungary",IS:"Iceland",IN:"India",ID:"Indonesia",IR:"Iran",IQ:"Iraq",IE:"Ireland",IL:"Israel",IT:"Italy",JP:"Japan",JO:"Jordan",KZ:"Kazakhstan",KE:"Kenya",KP:"N. Korea",KR:"S. Korea",KW:"Kuwait",KG:"Kyrgyzstan",LA:"Laos",LV:"Latvia",LB:"Lebanon",LY:"Libya",LI:"Liechtenstein",LT:"Lithuania",LU:"Luxembourg",MY:"Malaysia",ML:"Mali",MT:"Malta",MR:"Mauritania",MX:"Mexico",MD:"Moldova",MN:"Mongolia",ME:"Montenegro",MA:"Morocco",MZ:"Mozambique",MM:"Myanmar",NA:"Namibia",NP:"Nepal",NL:"Netherlands",NZ:"New Zealand",NI:"Nicaragua",NE:"Niger",NG:"Nigeria",NO:"Norway",OM:"Oman",PK:"Pakistan",PA:"Panama",PG:"Papua New Guinea",PY:"Paraguay",PE:"Peru",PH:"Philippines",PL:"Poland",PT:"Portugal",QA:"Qatar",RO:"Romania",RU:"Russia",RW:"Rwanda",SA:"Saudi Arabia",SN:"Senegal",RS:"Serbia",SG:"Singapore",SK:"Slovakia",SI:"Slovenia",SO:"Somalia",ZA:"South Africa",SS:"South Sudan",ES:"Spain",LK:"Sri Lanka",SD:"Sudan",SE:"Sweden",CH:"Switzerland",SY:"Syria",TJ:"Tajikistan",TZ:"Tanzania",TH:"Thailand",TN:"Tunisia",TR:"Turkey",TM:"Turkmenistan",UG:"Uganda",UA:"Ukraine",AE:"UAE",GB:"United Kingdom",US:"United States",UY:"Uruguay",UZ:"Uzbekistan",VN:"Vietnam",YE:"Yemen",ZM:"Zambia",ZW:"Zimbabwe",MC:"Monaco",BZ:"Belize"},Oc={AF:["DZ","AO","BJ","BW","BF","BI","CM","CV","CF","TD","KM","CD","CG","CI","DJ","EG","GQ","ER","ET","GA","GM","GH","GN","GW","KE","LS","LR","LY","MG","MW","ML","MR","MU","MA","MZ","NA","NE","NG","RE","RW","ST","SN","SC","SL","SO","ZA","SS","SD","TZ","TG","TN","UG","ZM","ZW"],AN:["AQ"],AS:["AF","AM","AZ","BH","BD","BT","BN","KH","CN","CY","GE","IN","ID","IR","IQ","IL","JP","JO","KZ","KW","KG","LA","LB","MY","MV","MN","MM","NP","KP","OM","PK","PS","PH","QA","RU","SA","SG","KR","LK","SY","TW","TJ","TH","TL","TR","TM","AE","UZ","VN","YE"],EU:["AL","AD","AT","BY","BE","BA","BG","HR","CZ","DK","EE","FI","FR","DE","GR","HU","IS","IE","IT","XK","LV","LI","LT","LU","MT","MD","MC","ME","NL","MK","NO","PL","PT","RO","RU","SM","RS","SK","SI","ES","SE","CH","UA","GB","VA"],NA:["AG","BS","BB","BZ","CA","CR","CU","DM","DO","SV","GD","GT","HT","HN","JM","MX","NI","PA","KN","LC","VC","TT","US"],OC:["AU","FJ","KI","MH","FM","NR","NZ","PW","PG","WS","SB","TO","TV","VU"],SA:["AR","BO","BR","CL","CO","EC","GY","PY","PE","SR","UY","VE"]},nr={AF:"Africa",AN:"Antarctica",AS:"Asia",EU:"Europe",NA:"N. America",OC:"Oceania",SA:"S. America"},ir={};for(let[s,t]of Object.entries(Oc))for(let e of t)ir[e]=s;function Mt(s){return Pc[s]||s}function jt(s){return!s||s.length!==2?"":String.fromCodePoint(...s.toUpperCase().split("").map(t=>t.charCodeAt(0)+127397))}function Nt(s){if(!s||s.indexOf("?")!==-1)return null;let t=new Date(s+"T12:00:00Z");return isNaN(t.getTime())?null:t}function Rs(s){let t=Nt(s.date_entered),e=Nt(s.date_left);return!t||!e?0:Math.max(Math.round((e.getTime()-t.getTime())/864e5),1)}function or(s,t=new Date){let e=t.getTime(),n=null,i=-1/0;for(let o of s){let r=Nt(o.date_entered);if(!(!r||r.getTime()>e)){if(o.date_left.trim()!==""){let a=Nt(o.date_left);if(!a||a.getTime()<e)continue}r.getTime()>i&&(n=o,i=r.getTime())}}return n}function rr(s){let t=m=>{var y,C,E,S,x,v,_,w;return{date_entered:(y=m.date_entered)!=null?y:"",date_left:(C=m.date_left)!=null?C:"",country:((E=m.country)!=null?E:"").trim().toUpperCase(),city:(S=m.city)!=null?S:"",visa_status:(x=m.visa_status)!=null?x:"",notes:(v=m.notes)!=null?v:"",source:((_=m.source)!=null?_:"").trim().toLowerCase(),resolved:(w=m.resolved)!=null?w:"",_src:m}},e=s.map(t).filter(m=>m.country),n=e.filter(m=>m.source==="confirmed"),i=e.filter(m=>m.source==="inferred"),o=e.filter(m=>m.source==="conflict"),r=[];for(let m of n){let y=Nt(m.date_entered),C=Nt(m.date_left);y&&C&&r.push([y.getTime(),C.getTime()])}let a=m=>{let y=Nt(m.date_entered),C=Nt(m.date_left);if(!y||!C)return!1;let E=y.getTime(),S=C.getTime();return r.some(([x,v])=>E<=v&&S>=x)},l=i.filter(m=>Nt(m.date_entered)&&Nt(m.date_left)&&!a(m)),c=new Set(n.map(m=>m.country)),d=new Set(i.map(m=>m.country)),h=new Set([...d].filter(m=>!c.has(m))),u=new Set([...c,...d]),f=new Map;for(let m of n)f.set(m.country,(f.get(m.country)||0)+Rs(m));let g=[...f.entries()].map(([m,y])=>({iso:m,days:y})).sort((m,y)=>y.days-m.days||Mt(m.iso).localeCompare(Mt(y.iso))),p=g.reduce((m,y)=>m+y.days,0),b=new Set;for(let m of c){let y=ir[m];y&&b.add(y)}return{confirmed:n,inferred:i,conflicts:o,inferredVisible:l,confRanges:r,confirmedCountries:c,inferredOnlyCountries:h,allCountries:u,countryDays:g,totalConfirmedDays:p,visitedContinents:b,worldPct:Math.round(c.size/Ci*100)}}var _i=864e5;function ar(s){if(!s||s.indexOf("?")!==-1)return null;let t=Date.parse(s+"T00:00:00Z");return isNaN(t)?null:t}function Fc(s,t,e,n){let i=Math.max(s,e),o=Math.min(t,n);return o<=i?0:Math.round((o-i)/_i)}function Ic(s,t){var i;let e=s.window;if(e.type==="all-time")return{start:-1/0,end:1/0,label:"all time"};if(e.type==="calendar-year"){let o=new Date(t).getUTCFullYear();return{start:Date.UTC(o,0,1),end:Date.UTC(o+1,0,1),label:`in ${o}`}}let n=(i=e.days)!=null?i:180;return{start:t-n*_i,end:t+_i,label:`in last ${n} days`}}function lr(s,t,e=Date.now()){var d,h,u;let n=(d=s.scope.countries)!=null?d:s.scope.country?[s.scope.country]:[],i=new Set(n.map(f=>f.toUpperCase())),o=new Set(((u=(h=s.exempt)==null?void 0:h.visa_status)!=null?u:[]).map(f=>f.toLowerCase().trim())),r=Ic(s,e),a=0;for(let f of t){if(!i.has((f.country||"").toUpperCase())||o.has((f.visa_status||"").toLowerCase().trim()))continue;let g=ar(f.date_entered),p=ar(f.date_left);g===null||p===null||(a+=Fc(g,p,r.start,r.end))}let l=s.threshold-a,c=a>=s.threshold?"over":a/s.threshold>=.8?"warn":"ok";return{rule:s,used:a,threshold:s.threshold,remaining:l,windowLabel:r.label,status:c}}var cr=["#c9a96e","#4a6fa5","#5ba06e","#a05b8a","#6ea0a0","#a0855b","#7a6ea0","#a06e6e","#6e8fa0","#a09e5b"],Vc=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function Bc(){let s=new Map,t=0;return e=>(s.has(e)||s.set(e,cr[t++%cr.length]),s.get(e))}function Nc(s){let t=document.body.createDiv({cls:"csv-tv-tooltip"}),e=null,n=(r,a)=>{let c=r+14,d=a+16,h=t.offsetWidth,u=t.offsetHeight;c+h+8>window.innerWidth&&(c=r-h-14),d+u+8>window.innerHeight&&(d=a-u-16),t.style.left=`${Math.max(8,c)}px`,t.style.top=`${Math.max(8,d)}px`},i=r=>{var c,d;let a=(d=(c=r.target)==null?void 0:c.closest("[data-tip]"))!=null?d:null,l=(a==null?void 0:a.getAttribute("data-tip"))||"";if(!a||!l){e&&(e=null,t.removeClass("is-on"));return}a!==e&&(e=a,t.setText(l),t.addClass("is-on")),n(r.clientX,r.clientY)},o=()=>{e=null,t.removeClass("is-on")};return s.addEventListener("pointermove",i),s.addEventListener("pointerleave",o),()=>{s.removeEventListener("pointermove",i),s.removeEventListener("pointerleave",o),t.remove()}}function Si(s){let t=Rs(s);return t?`${t}d`:"\u2014"}function ns(s){return s||"\u2014"}function Os(s){return s.createDiv({cls:"csv-tv-table-wrap"}).createEl("table",{cls:"csv-tv-table"})}function Ps(s,t,e,n){s.addClass("csv-tv-editable"),s.title="Click to edit";let i=()=>{s.empty(),s.setText(t[e]?t[e]:"\u2014")};i(),s.addEventListener("click",()=>{var r;if(s.querySelector("input"))return;s.empty();let o=mn(s,e,(r=t[e])!=null?r:"","csv-inline-input");o.focus(),o.type==="text"&&o.select(),o.addEventListener("blur",()=>{t[e]=o.value,n(),i()}),o.addEventListener("keydown",a=>{var l;a.key==="Enter"&&o.blur(),a.key==="Escape"&&(o.value=(l=t[e])!=null?l:"",o.blur())})})}async function dr(s,t,e,n=()=>{},i=null,o=()=>{}){let r=rr(t),a=s.createDiv({cls:"csv-tv"});if(!r.confirmed.length&&!r.inferred.length){a.createDiv({cls:"csv-empty-state",text:"No travel rows found. Expected columns: country, date_entered, date_left, source."});return}o(Nc(a));let l=null,c=()=>{a.querySelectorAll(".country-path").forEach(f=>{let g=(f.getAttribute("data-iso")||"").toUpperCase();f.classList.toggle("cp-selected",!!l&&g===l)}),a.querySelectorAll(".csv-tv-seg").forEach(f=>{f.classList.toggle("is-dim",!!l&&f.getAttribute("data-iso")!==l)}),a.querySelectorAll("tr[data-iso]").forEach(f=>{f.classList.toggle("is-selected",!!l&&f.getAttribute("data-iso")===l)}),u.empty(),l&&(Hc(u,r,l,()=>d(null)),u.scrollIntoView({behavior:"smooth",block:"nearest"}))},d=f=>{l=f&&f!==l?f:null,c()};$c(a,r);let h=a.createDiv({cls:"csv-tv-mapwrap"});h.createDiv({cls:"csv-tv-map-loading",text:"Loading map\u2026"});let u=a.createDiv({cls:"csv-tv-detailwrap"});i&&i.length&&Wc(a,r.confirmed,i),jc(a,r,d),Uc(a,r,d),Yc(a,r,n);try{let f=await e();h.empty(),f?zc(h,f,r,d):h.createDiv({cls:"csv-tv-map-loading",text:"World map asset not found (world-map.svg)."})}catch(f){h.empty(),h.createDiv({cls:"csv-tv-map-loading",text:"Couldn't load world map."})}}function $c(s,t){let e=s.createDiv({cls:"csv-tv-stats"}),n=(c,d,h="")=>{let u=e.createDiv({cls:"csv-tv-stat"});u.createDiv({cls:"csv-tv-stat-label",text:c}),u.createDiv({cls:"csv-tv-stat-value",text:d}),h&&u.createDiv({cls:"csv-tv-stat-sub",text:h})},i=Math.round(t.allCountries.size/Ci*100);n("Countries",String(t.confirmedCountries.size),`${t.worldPct}% of world`),n("Incl. photos",String(t.allCountries.size),`${i}% of world`),n("Continents",`${t.visitedContinents.size} / 7`,[...t.visitedContinents].map(c=>nr[c]||c).sort().join(", ")),n("Confirmed trips",String(t.confirmed.length)),n("Confirmed days",String(t.totalConfirmedDays));let o=new Set(t.confirmed.map(c=>c.city.trim().toLowerCase()).filter(Boolean));o.size&&n("Cities",String(o.size));let r=null,a=0;for(let c of t.confirmed){let d=Rs(c);d>a&&(a=d,r=c)}if(r){let c=r.date_entered.slice(0,4);n("Longest trip",`${a}d`,`${jt(r.country)} ${Mt(r.country)}${c?` \xB7 ${c}`:""}`)}let l=or(t.confirmed);if(l){let c=Nt(l.date_entered),d=Math.max(1,Math.round((Date.now()-c.getTime())/864e5)+1),h=s.createDiv({cls:"csv-tv-now"});h.createSpan({cls:"csv-tv-now-loc",text:`\u{1F4CD} Currently in ${jt(l.country)} ${Mt(l.country)}`}),h.createSpan({cls:"csv-tv-now-sub",text:` \u2014 since ${l.date_entered} (day ${d})${l.city?` \xB7 ${l.city}`:""}`})}}function zc(s,t,e,n){let i=s.createDiv({cls:"csv-tv-map"});i.innerHTML=t,i.querySelectorAll(".country-path").forEach(r=>{let a=(r.getAttribute("data-iso")||"").toUpperCase();if(r.classList.remove("cp-unvisited","cp-confirmed","cp-inferred"),a&&e.confirmedCountries.has(a)){r.classList.add("cp-confirmed");let l=e.countryDays.find(c=>c.iso===a);r.setAttr("aria-label",`${Mt(a)} \u2014 ${l&&l.days?l.days+"d confirmed":"confirmed"}`),r.setAttr("data-tip",`${Mt(a)}${l&&l.days?" \xB7 "+l.days+"d":""} \xB7 click for trips`)}else a&&e.inferredOnlyCountries.has(a)?(r.classList.add("cp-inferred"),r.setAttr("aria-label",`${Mt(a)} \u2014 photo evidence`),r.setAttr("data-tip",`${Mt(a)} \xB7 photo evidence \xB7 click for trips`)):a?(r.classList.add("cp-unvisited"),r.setAttr("data-tip",Mt(a))):r.classList.add("cp-unvisited");a&&r.addEventListener("click",()=>{e.allCountries.has(a)?n(a):n(null)})}),i.querySelectorAll(".country-path").forEach(r=>{try{let a=r.getBoundingClientRect();a.width&&a.height&&Math.max(a.width,a.height)<12&&r.classList.add("cp-tiny")}catch(a){}});let o=s.createDiv({cls:"csv-tv-map-legend"});o.createSpan({cls:"csv-tv-leg"}).innerHTML='<span class="csv-tv-dot cp-confirmed"></span> Confirmed',o.createSpan({cls:"csv-tv-leg"}).innerHTML='<span class="csv-tv-dot cp-inferred"></span> Photo evidence'}function Hc(s,t,e,n){var b,m;let i=s.createDiv({cls:"csv-tv-detail"}),o=i.createDiv({cls:"csv-tv-detail-head"});o.createSpan({cls:"csv-tv-detail-flag",text:jt(e)});let r=o.createDiv({cls:"csv-tv-detail-titles"});r.createDiv({cls:"csv-tv-detail-name",text:Mt(e)});let a=t.confirmed.filter(y=>y.country===e),l=t.inferred.filter(y=>y.country===e),c=(m=(b=t.countryDays.find(y=>y.iso===e))==null?void 0:b.days)!=null?m:0,d=new Set([...a,...l].map(y=>y.city.trim()).filter(Boolean)),h=[];a.length&&h.push(`${a.length} confirmed trip${a.length===1?"":"s"}`),c&&h.push(`${c}d total`),l.length&&h.push(`${l.length} photo-inferred`),d.size&&h.push(`${d.size} cit${d.size===1?"y":"ies"}`),r.createDiv({cls:"csv-tv-detail-sub",text:h.join(" \xB7 ")}),o.createEl("button",{cls:"csv-tv-detail-close",text:"\u2715",title:"Close"}).addEventListener("click",n);let u=bn([...a.map(y=>({r:y,inf:!1,date_entered:y.date_entered})),...l.map(y=>({r:y,inf:!0,date_entered:y.date_entered}))]);if(!u.length)return;let f=Os(i),g=f.createEl("thead").createEl("tr");["","Entered","Left","Days","City","Visa"].forEach(y=>g.createEl("th",{text:y}));let p=f.createEl("tbody");for(let{r:y,inf:C}of u){let E=p.createEl("tr");E.createEl("td",{text:C?"\u{1F4F7}":"",cls:"csv-tv-flag",attr:C?{"data-tip":"Photo-inferred"}:{}}),E.createEl("td",{text:ns(y.date_entered)}),E.createEl("td",{text:ns(y.date_left)}),E.createEl("td",{text:Si(y)}),E.createEl("td",{text:y.city}),E.createEl("td",{text:y.visa_status})}}function Wc(s,t,e){s.createDiv({cls:"csv-tv-sec-title",text:"Residency counters"});let n=s.createDiv({cls:"csv-tv-res-grid"});for(let i of e){let o=lr(i,t),r=n.createDiv({cls:`csv-tv-res-card csv-tv-res-${o.status}`});r.createDiv({cls:"csv-tv-res-label",text:i.label});let a=r.createDiv({cls:"csv-tv-res-nums"});a.createSpan({cls:"csv-tv-res-used",text:String(o.used)}),a.createSpan({cls:"csv-tv-res-thresh",text:` / ${o.threshold}`}),a.createSpan({cls:"csv-tv-res-window",text:` ${o.windowLabel}`});let l=r.createDiv({cls:"csv-tv-res-bar"});l.createDiv({cls:"csv-tv-res-fill"}).style.width=`${Math.min(100,Math.round(o.used/o.threshold*100))}%`;let c=o.status==="over"?i.onExceed?`Over \u2014 ${i.onExceed}`:"Limit reached":`${o.remaining} day${o.remaining===1?"":"s"} left`;r.createDiv({cls:"csv-tv-res-status",text:c}),i.note&&r.createDiv({cls:"csv-tv-res-note",text:i.note})}s.createDiv({cls:"csv-tv-res-disclaimer",text:"Indicators only \u2014 not legal or tax advice. Based on confirmed trips."})}function jc(s,t,e){s.createDiv({cls:"csv-tv-sec-title",text:"Countries visited"});let n=Os(s),i=n.createEl("thead").createEl("tr");["","Country","Total days"].forEach(r=>i.createEl("th",{text:r}));let o=n.createEl("tbody");for(let{iso:r,days:a}of t.countryDays){let l=o.createEl("tr",{cls:"csv-tv-row-click",attr:{"data-iso":r}});l.createEl("td",{text:jt(r),cls:"csv-tv-flag"}),l.createEl("td",{text:Mt(r)}),l.createEl("td",{text:a?`${a}d`:"\u2014"}),l.addEventListener("click",()=>e(r))}if(t.inferredOnlyCountries.size){let r=s.createDiv({cls:"csv-tv-photo-only"});r.createSpan({text:"\u{1F4F7} Photo evidence only: "}),r.createSpan({text:[...t.inferredOnlyCountries].sort().map(jt).join(" ")})}}function Uc(s,t,e){s.createDiv({cls:"csv-tv-sec-title",text:"Timeline"});let n=Bc(),i=[...t.confirmed.map(c=>({...c,_inf:!1})),...t.inferredVisible.map(c=>({...c,_inf:!0}))].filter(c=>c.date_entered&&c.date_left&&c.date_entered.indexOf("?")===-1),o=new Map;for(let c of i){let d=parseInt(c.date_entered.slice(0,4)),h=parseInt(c.date_left.slice(0,4));if(!(isNaN(d)||isNaN(h)))for(let u=d;u<=h;u++)o.has(u)||o.set(u,[]),o.get(u).push(c)}let r=[...o.keys()].sort((c,d)=>d-c),a=s.createDiv({cls:"csv-tv-timeline"});for(let c of r){let d=new Date(`${c}-01-01T12:00:00Z`).getTime(),h=new Date(`${c}-12-31T12:00:00Z`).getTime(),u=h-d,f=a.createDiv({cls:"csv-tv-tl-year"}),g=0,p=new Set;for(let C of o.get(c)){if(p.add(C.country),C._inf)continue;let E=Math.max(new Date(C.date_entered+"T12:00:00Z").getTime(),d),S=Math.min(new Date(C.date_left+"T12:00:00Z").getTime(),h);E<=S&&(g+=Math.max(Math.round((S-E)/864e5)+1,1))}let b=f.createDiv({cls:"csv-tv-tl-label"});b.createSpan({text:String(c)}),b.createSpan({cls:"csv-tv-tl-sub",text:`${g?`${g}d \xB7 `:""}${p.size} ${p.size===1?"country":"countries"}`});let m=f.createDiv({cls:"csv-tv-month-row"});Vc.forEach(C=>m.createDiv({cls:"csv-tv-month-tick",text:C}));let y=f.createDiv({cls:"csv-tv-track"});for(let C of o.get(c)){let E=Math.max(new Date(C.date_entered+"T12:00:00Z").getTime(),d),S=Math.min(new Date(C.date_left+"T12:00:00Z").getTime(),h);if(E>S)continue;let x=(E-d)/u*100,v=Math.max((S-E+864e5)/u*100,.5),_=n(C.country),w=y.createDiv({cls:`csv-tv-seg${C._inf?" csv-tv-seg-inf":""}`});w.style.left=`${x}%`,w.style.width=`${v}%`,C._inf?(w.style.borderColor=_,w.style.background=_+"22",w.style.color=_):w.style.background=_,w.setAttr("data-iso",C.country),w.setAttr("data-tip",`${Mt(C.country)} ${C.date_entered} \u2192 ${C.date_left} (${Rs(C)}d)${C.visa_status?" ["+C.visa_status+"]":""}${C._inf?" [photo]":""}`),w.addEventListener("click",()=>e(C.country)),v>4?w.createSpan({cls:"csv-tv-seg-lbl",text:`${jt(C.country)} ${C.country}`}):v>2&&w.createSpan({cls:"csv-tv-seg-lbl",text:jt(C.country)})}}a.createDiv({cls:"csv-tv-tl-legend"}).setText("Confirmed (solid) \xB7 Photo inferred (outlined)")}function bn(s){return[...s].sort((t,e)=>!t.date_entered&&!e.date_entered?0:t.date_entered?e.date_entered?e.date_entered.localeCompare(t.date_entered):-1:1)}function Yc(s,t,e){s.createDiv({cls:"csv-tv-sec-title",text:"Confirmed trips"}),s.createDiv({cls:"csv-tv-edit-hint",text:"Dates, city, visa and notes are editable \u2014 click a cell. Edit country in Table view."});let n=Os(s),i=n.createEl("thead").createEl("tr");["","Country","Entered","Left","Duration","City","Visa","Notes"].forEach(r=>i.createEl("th",{text:r}));let o=n.createEl("tbody");for(let r of bn(t.confirmed)){let a=o.createEl("tr");a.createEl("td",{text:jt(r.country),cls:"csv-tv-flag"}),a.createEl("td",{text:Mt(r.country)}),Ps(a.createEl("td"),r._src,"date_entered",e),Ps(a.createEl("td"),r._src,"date_left",e),a.createEl("td",{text:Si(r)}),Ps(a.createEl("td"),r._src,"city",e),Ps(a.createEl("td"),r._src,"visa_status",e),Ps(a.createEl("td"),r._src,"notes",e)}if(t.inferred.length){let r=s.createEl("details",{cls:"csv-tv-details"});r.createEl("summary",{text:`\u{1F4F7} Photo inferred trips (${t.inferred.length})`});let a=Os(r),l=a.createEl("thead").createEl("tr");["","Country","Entered","Left","Days","City"].forEach(d=>l.createEl("th",{text:d}));let c=a.createEl("tbody");for(let d of bn(t.inferred)){let h=c.createEl("tr");h.createEl("td",{text:jt(d.country),cls:"csv-tv-flag"}),h.createEl("td",{text:Mt(d.country)}),h.createEl("td",{text:ns(d.date_entered)}),h.createEl("td",{text:ns(d.date_left)}),h.createEl("td",{text:Si(d)}),h.createEl("td",{text:d.city})}}if(t.conflicts.length){let r=s.createEl("details",{cls:"csv-tv-details csv-tv-details-warn"});r.createEl("summary",{text:`\u26A0 ${t.conflicts.length} conflict(s) \u2014 photo evidence contradicts a confirmed entry`});let a=Os(r),l=a.createEl("thead").createEl("tr");["","Country (photos)","Dates","Detail"].forEach(d=>l.createEl("th",{text:d}));let c=a.createEl("tbody");for(let d of bn(t.conflicts)){let h=c.createEl("tr");h.createEl("td",{text:jt(d.country),cls:"csv-tv-flag"}),h.createEl("td",{text:d.country}),h.createEl("td",{text:`${ns(d.date_entered)} \u2192 ${ns(d.date_left)}`}),h.createEl("td",{text:d.notes})}}}var Vt=require("obsidian"),vn=class extends Vt.PluginSettingTab{constructor(t,e){super(t,e),this.plugin=e}display(){let{containerEl:t}=this;t.empty(),t.createEl("h2",{text:"XLSX Card View"}),new Vt.Setting(t).setName("Default view mode").addDropdown(n=>n.addOption("kanban-genre","Kanban").addOption("table","Table").setValue(this.plugin.settings.defaultMode).onChange(async i=>{this.plugin.settings.defaultMode=i,await this.plugin.saveSettings()})),new Vt.Setting(t).setName("Status column name").addText(n=>n.setValue(this.plugin.settings.statusColumn).onChange(async i=>{this.plugin.settings.statusColumn=i,await this.plugin.saveSettings()})),new Vt.Setting(t).setName("Category/Genre column name").addText(n=>n.setValue(this.plugin.settings.categoryColumn).onChange(async i=>{this.plugin.settings.categoryColumn=i,await this.plugin.saveSettings()})),new Vt.Setting(t).setName("Notes column names").setDesc("Comma-separated.").addText(n=>n.setValue(this.plugin.settings.notesColumns.join(", ")).onChange(async i=>{this.plugin.settings.notesColumns=i.split(",").map(o=>o.trim()),await this.plugin.saveSettings()})),new Vt.Setting(t).setName("Select/dropdown columns").setDesc("Comma-separated column names that use a dropdown picker.").addText(n=>n.setValue(this.plugin.settings.selectColumns.join(", ")).onChange(async i=>{this.plugin.settings.selectColumns=i.split(",").map(o=>o.trim()),await this.plugin.saveSettings()})),new Vt.Setting(t).setName("Notes subfolder").addText(n=>n.setPlaceholder("Notes").setValue(this.plugin.settings.notesSubfolder).onChange(async i=>{this.plugin.settings.notesSubfolder=i,await this.plugin.saveSettings()})),new Vt.Setting(t).setName("Reset column widths").addButton(n=>n.setButtonText("Reset").onClick(async()=>{this.plugin.settings.columnWidths={},await this.plugin.saveSettings(),new Vt.Notice("Column widths reset.")})),new Vt.Setting(t).setName("Residency counters (travel view)").setDesc("Show residency / tax day-gauges in the travel view.").addToggle(n=>n.setValue(this.plugin.settings.showResidency!==!1).onChange(async i=>{this.plugin.settings.showResidency=i,await this.plugin.saveSettings()})),t.createEl("h3",{text:"Residency rules"}),t.createEl("p",{cls:"setting-item-description",text:"Each rule counts days in the listed countries within the window, minus exempt visa rows, against the threshold. Counts confirmed trips only. Indicators, not legal/tax advice."});let e=t.createDiv({cls:"csv-rr-wrap"});this.renderResidencyRules(e)}renderResidencyRules(t){var o;t.empty();let e=(o=this.plugin.settings.residencyRules)!=null?o:this.plugin.settings.residencyRules=[],n=()=>void this.plugin.saveSettings();e.forEach((r,a)=>{var m,y,C,E,S,x;let l=t.createDiv({cls:"csv-rr-card"}),c=l.createDiv({cls:"csv-rr-head"}),d=c.createEl("input",{cls:"csv-rr-label",type:"text",value:r.label});d.placeholder="Label (e.g. \u{1F1EA}\u{1F1FA} Schengen 90/180)",d.addEventListener("input",()=>{r.label=d.value,n()});let h=c.createEl("button",{cls:"csv-rr-del",text:"\u2715"});h.setAttr("aria-label","Remove rule"),h.addEventListener("click",async()=>{e.splice(a,1),await this.plugin.saveSettings(),this.renderResidencyRules(t)});let u=l.createDiv({cls:"csv-rr-grid"}),f=(v,_,w,D="")=>{let k=u.createDiv({cls:"csv-rr-field"});k.createEl("label",{text:v});let T=k.createEl("input",{type:"text",value:_});D&&(T.placeholder=D),T.addEventListener("input",()=>{w(T.value),n()})},g=(m=r.scope.countries)!=null?m:r.scope.country?[r.scope.country]:[];f("Countries (ISO-2, comma)",g.join(", "),v=>{r.scope={countries:v.split(",").map(_=>_.trim().toUpperCase()).filter(Boolean)}},"US, GB");let p=u.createDiv({cls:"csv-rr-field"});p.createEl("label",{text:"Window"});let b=p.createEl("select");[["calendar-year","Calendar year"],["rolling","Rolling N days"],["all-time","All time"]].forEach(([v,_])=>{let w=b.createEl("option",{text:_,value:v});r.window.type===v&&(w.selected=!0)}),b.addEventListener("change",()=>{r.window={type:b.value,days:r.window.days},n(),this.renderResidencyRules(t)}),r.window.type==="rolling"&&f("Rolling days",String((y=r.window.days)!=null?y:180),v=>{let _=parseInt(v,10);r.window.days=isNaN(_)?void 0:_},"180"),f("Threshold (days)",String(r.threshold),v=>{let _=parseInt(v,10);r.threshold=isNaN(_)?0:_},"183"),f("Exempt visas (comma)",((E=(C=r.exempt)==null?void 0:C.visa_status)!=null?E:[]).join(", "),v=>{let _=v.split(",").map(w=>w.trim()).filter(Boolean);r.exempt=_.length?{visa_status:_}:void 0},"F-1, J-1"),f("On-exceed label",(S=r.onExceed)!=null?S:"",v=>{r.onExceed=v||void 0},"tax resident"),f("Note",(x=r.note)!=null?x:"",v=>{r.note=v||void 0},"optional caveat")}),t.createDiv({cls:"csv-rr-btns"}).createEl("button",{cls:"csv-rr-add",text:"+ Add rule"}).addEventListener("click",async()=>{e.push({label:"New rule",scope:{countries:[]},window:{type:"calendar-year"},threshold:183}),await this.plugin.saveSettings(),this.renderResidencyRules(t)})}};var fe=require("obsidian"),hr=dn(Ls());async function ur(s,t,e,n,i={}){var F,Y,$;let o=t.split(`
`).map(R=>R.trim()).filter(Boolean),r="";for(let R of o)if(R.startsWith("file:")){r=R.replace("file:","").trim();break}if(!r){e.createEl("p",{text:"Error: No file specified. Use: file: yourfile.csv",cls:"csv-add-error"});return}let a=s.vault.getAbstractFileByPath(n.sourcePath),l=(Y=(F=a==null?void 0:a.parent)==null?void 0:F.path)!=null?Y:"",c=ue(r,l),d=s.vault.getAbstractFileByPath(c);if(!d||!(d instanceof fe.TFile)){e.createEl("p",{text:`Error: File not found: ${c}`,cls:"csv-add-error"});return}let h=($=i[c])!=null?$:{},u=[],f=[];try{let R=await s.vault.read(d),W=Bt(R);u=W.headers,f=W.rows}catch(R){e.createEl("p",{text:`Error reading file: ${R}`,cls:"csv-add-error"});return}if(!u.length){e.createEl("p",{text:"Error: No columns found in file",cls:"csv-add-error"});return}let g=R=>{let W=R.toLowerCase();if(["date","day","datum"].includes(W))return!0;let K=f.slice(0,5).map(N=>{var P;return(P=N[R])!=null?P:""});return K.length>0&&K.every(N=>/^\d{4}-\d{2}-\d{2}$/.test(N))},p=R=>{let W=R.toLowerCase();return["notes","note","comments","description","journal"].includes(W)},b=h.habitColumns?h.habitColumns.filter(R=>u.includes(R)):u.filter(R=>!g(R)&&Ze(f.map(W=>{var K;return((K=W[R])!=null?K:"").toLowerCase().trim()}))),m=u.filter(R=>g(R)),y=u.filter(R=>p(R)),C=u.filter(R=>!b.includes(R)&&!m.includes(R)&&!y.includes(R)),E=h.titleColumn?u.find(R=>R.toLowerCase()===h.titleColumn.toLowerCase()):u.find(R=>["title","name"].includes(R.toLowerCase())),S=e.createDiv({cls:"csv-add-form csv-add-compact"}),x=S.createEl("button",{cls:"csv-add-trigger",text:"+ New entry"});x.style.display="none";let v=S.createDiv({cls:"csv-add-card"}),_=v.createDiv({cls:"csv-add-card-header"});_.createEl("span",{cls:"csv-add-card-title",text:"New entry"});let w=_.createEl("button",{cls:"csv-add-card-close",text:"\xD7"}),D=v.createDiv({cls:"csv-add-rows"}),k={},T={},A=(R,W)=>{let K=D.createDiv({cls:`csv-add-row csv-add-row-${W}`});return K.createEl("span",{cls:"csv-add-row-label",text:kt(R)}),K};m.forEach(R=>{let K=A(R,"date").createEl("input",{cls:"csv-add-row-control",type:"date"});K.value=ts(),k[R]=K}),b.forEach(R=>{T[R]=!1;let K=A(R,"toggle").createEl("label",{cls:"csv-add-switch"}),N=K.createEl("input",{type:"checkbox",cls:"csv-add-switch-input"});K.createEl("span",{cls:"csv-add-switch-track"}),N.addEventListener("change",()=>{T[R]=N.checked}),k[R]=N}),C.forEach(R=>{let W=A(R,"field"),K=new Set(f.map(P=>{var L;return((L=P[R])!=null?L:"").trim()}).filter(Boolean));if(R!==E&&(h.categoricalColumns?h.categoricalColumns.includes(R):Xt(K.size))){let P=W.createEl("select",{cls:"csv-add-row-control"});P.createEl("option",{text:"\u2014",value:""}),Array.from(K).sort().forEach(B=>P.createEl("option",{text:B,value:B})),P.createEl("option",{text:"+ Custom",value:"__custom__"});let L=D.createDiv({cls:"csv-add-row csv-add-row-custom"});L.style.display="none";let z=L.createEl("input",{cls:"csv-add-row-control",type:"text",placeholder:`Custom ${kt(R).toLowerCase()}`});D.insertBefore(L,W.nextSibling),P.addEventListener("change",()=>{L.style.display=P.value==="__custom__"?"flex":"none",P.value==="__custom__"&&z.focus()}),k[R]=P,k[`${R}__custom`]=z}else k[R]=W.createEl("input",{cls:"csv-add-row-control",type:"text",placeholder:kt(R)})}),y.forEach(R=>{let W=D.createDiv({cls:"csv-add-row csv-add-row-notes"});W.createEl("span",{cls:"csv-add-row-label",text:kt(R)}),k[R]=W.createEl("textarea",{cls:"csv-add-row-textarea",placeholder:"Optional notes\u2026"})});let I=v.createEl("button",{text:"Add",cls:"csv-add-submit"}),V=_.querySelector(".csv-add-card-title"),O=()=>{if(!m.length)return;let R=k[m[0]];if(!R)return;let W=R.value,K=f.find(N=>N[m[0]]===W);V&&V.setText(K?`Updating ${W}`:"New entry"),v.classList.toggle("is-updating",!!K),I.setText(K?"Update":"Add"),b.forEach(N=>{var z;let P=k[N];if(!P)return;let L=Je((z=K==null?void 0:K[N])!=null?z:"");P.checked=L,T[N]=L}),[...C,...y].forEach(N=>{var z;let P=k[N];if(!P)return;let L=(z=K==null?void 0:K[N])!=null?z:"";if(P instanceof HTMLSelectElement){let B=Array.from(P.options).find(q=>q.value===L),H=k[`${N}__custom`],U=H==null?void 0:H.closest(".csv-add-row-custom");B?(P.value=L,U&&(U.style.display="none"),H&&(H.value="")):L?(P.value="__custom__",H&&(H.value=L),U&&(U.style.display="flex")):(P.value="",U&&(U.style.display="none"),H&&(H.value=""))}else P instanceof HTMLTextAreaElement,P.value=L})};if(O(),m.length){let R=k[m[0]];R==null||R.addEventListener("change",O)}let M=()=>{v.style.display="block",x.style.display="none";let R=v.querySelector(".csv-add-row-control");R==null||R.focus()},j=()=>{v.style.display="none",x.style.display=""};x.addEventListener("click",M),w.addEventListener("click",j),I.addEventListener("click",async()=>{let R={};u.forEach(B=>{var H,U,q,X;b.includes(B)?R[B]=T[B]?"1":"0":k[B]instanceof HTMLSelectElement&&k[B].value==="__custom__"?R[B]=(U=(H=k[`${B}__custom`])==null?void 0:H.value)!=null?U:"":k[B]instanceof HTMLTextAreaElement?R[B]=k[B].value:R[B]=(X=(q=k[B])==null?void 0:q.value)!=null?X:""});let W=m.length>0&&m.some(B=>{var H;return((H=R[B])!=null?H:"").trim()}),K=[...C,...y].some(B=>{var H;return((H=R[B])!=null?H:"").trim()}),N=b.some(B=>T[B]);if(!W&&!K&&!N){new fe.Notice("Please fill at least one field");return}let P=[];try{let B=await s.vault.read(d);P=Bt(B).rows}catch(B){new fe.Notice(`Error reading file: ${B}`);return}let L=!1,z=-1;if(m.length>0){let B=m[0],H=R[B];if(z=P.findIndex(U=>U[B]===H),z>=0){L=!0;let U=P[z];u.forEach(q=>{var X;(b.includes(q)||((X=R[q])!=null?X:"").trim())&&(U[q]=R[q])})}else P.push(R)}else P.push(R);try{let B=hr.default.unparse(P,{columns:u});await s.vault.modify(d,B),new fe.Notice(L?`Updated entry for ${R[m[0]]||""}`:`Added entry to ${d.basename}`),f.length=0,f.push(...P),m.length>0?O():(b.forEach(H=>{T[H]=!1;let U=k[H];U&&(U.checked=!1)}),[...C,...y].forEach(H=>{let U=k[H];U instanceof HTMLSelectElement?U.selectedIndex=0:(U instanceof HTMLTextAreaElement||U)&&(U.value="");let q=k[`${H}__custom`];if(q){q.value="";let X=q.closest(".csv-add-row-custom");X&&(X.style.display="none")}})),setTimeout(async()=>{let H=s.vault.getAbstractFileByPath(n.sourcePath);if(H instanceof fe.TFile){let U=s.workspace.activeLeaf;U&&await U.openFile(H,{state:{mode:"preview"}})}},300)}catch(B){new fe.Notice(`Error saving: ${B}`)}})}function yn(s,t){let e=s.getFilteredRows();s.searchQuery.trim()&&t.createDiv({cls:"csv-search-results",text:`Found ${e.length} of ${s.rows.length} entries`});let i=t.createDiv({cls:"csv-table-wrapper"}).createEl("table",{cls:"csv-table"}),o=i.createEl("thead").createEl("tr");s.headers.forEach(l=>{let c=o.createEl("th");c.setText(l),c.addClass("csv-th-sortable"),s.tableSortCol===l&&c.createSpan({cls:"csv-th-sort-indicator",text:s.tableSortDir==="asc"?" \u25B2":" \u25BC"}),c.title="Click to sort",c.addEventListener("click",g=>{g.target.closest(".csv-col-resize-handle")||(s.tableSortCol!==l?(s.tableSortCol=l,s.tableSortDir="asc"):s.tableSortDir==="asc"?s.tableSortDir="desc":s.tableSortCol=null,s.renderView())});let d=s.settings.columnWidths[l];d&&(c.style.width=d+"px");let h=c.createDiv({cls:"csv-col-resize-handle"}),u=0,f=0;h.addEventListener("pointerdown",g=>{g.preventDefault(),g.stopPropagation(),h.setPointerCapture(g.pointerId),u=g.clientX,f=c.offsetWidth;let p=m=>{c.style.width=Math.max(60,f+m.clientX-u)+"px"},b=m=>{s.settings.columnWidths[l]=Math.max(60,f+m.clientX-u),h.removeEventListener("pointermove",p),h.removeEventListener("pointerup",b),s.persistSettings()};h.addEventListener("pointermove",p),h.addEventListener("pointerup",b)})}),o.createEl("th",{text:""});let r=matchMedia("(pointer: coarse)").matches,a=i.createEl("tbody");e.forEach(l=>{let c=a.createEl("tr");c.addEventListener("contextmenu",u=>s.openRowContextMenu(l,u)),s.headers.forEach(u=>{var g,p;let f=c.createEl("td");if(s.isNotesCol(u)){f.addClass("csv-table-notes-cell");let b=((g=l[u])!=null?g:"").replace(/#{1,6}\s/g,"").replace(/[*_>`]/g,"").split(`
`).filter(C=>C.trim()).slice(0,3).join(" \xB7 "),m=b?b.slice(0,200)+(b.length>200?"\u2026":""):"+ Add note",y=f.createSpan({text:m});b||y.addClass("csv-table-notes-empty"),f.title="Click to open note",f.addEventListener("click",C=>{C.stopPropagation(),s.openNoteExpander(l,u)})}else if(s.isSelectCol(u))s.renderSelectField(f,l,u);else{let b=(p=l[u])!=null?p:"";f.setText(b),b.length>80&&(f.title=b),Fs(s,f,l,u)}});let d=c.createEl("td",{cls:"csv-table-action"}),h=s.notesFileExists(l);d.createEl("button",{cls:`csv-table-notes-btn ${h?"exists":""}`,text:h?"\u{1F4C4}":"\u271A",title:h?"Open notes":"Create notes"}).addEventListener("click",()=>s.openOrCreateNotes(l)),d.createEl("button",{cls:"csv-table-del-btn",text:"\u2715",title:"Delete row (Undo available)"}).addEventListener("click",()=>s.deleteWithUndo(l))}),r||requestAnimationFrame(()=>{a.querySelectorAll("td:not(.csv-table-notes-cell):not(.csv-table-action)").forEach(l=>{l.scrollHeight>l.clientHeight+1&&l.addClass("csv-cell--clipped")})})}function Fs(s,t,e,n){t.addEventListener("click",i=>{var h,u;if(t.querySelector("input"))return;t.empty();let o=(h=s.fileCfg.dateColumns)==null?void 0:h.includes(n),r=((u=e[n])!=null?u:"").trim(),a=o||wt(n)&&(r===""||fn.test(r)),l=a?r.slice(0,10):r,c=t.createEl("input",{cls:"csv-inline-input",value:l,type:a?"date":"text"});c.focus(),a||c.select(),c.addEventListener("click",f=>f.stopPropagation());let d=!1;c.addEventListener("blur",()=>{var f;!d&&c.value!==l&&(e[n]=c.value,s.scheduleSave()),t.empty(),t.setText(((f=e[n])!=null?f:"")||"\u2014")}),c.addEventListener("keydown",f=>{f.key==="Enter"&&c.blur(),f.key==="Escape"&&(d=!0,c.blur())})})}function xn(s){return!!(s.getCategoryCol()||s.getStatusCol()||fr(s)||s.authorKey())}function fr(s){return s.resolveCol(["Rating","rating","Score","score","Score /5","Stars","stars"])}function Bs(s){var i;let t=(s!=null?s:"").trim();if(!t)return null;let e=((i=t.match(/★/g))!=null?i:[]).length;if(e>0)return e;let n=parseFloat(t);return isNaN(n)||n<=0?null:Math.min(5,n)}var gr=["watched","read","finished","completed","done","yes","seen"],pr=["watching","reading","in progress","in-progress"],Kc=["dropped","abandoned","dnf"];function Gc(s){let t=s.toLowerCase();return gr.includes(t)?"is-done":pr.includes(t)?"is-progress":Kc.includes(t)?"is-dropped":""}function Is(s,t){let e=new Map;return s.forEach(n=>t(n).forEach(i=>{var o;return e.set(i,((o=e.get(i))!=null?o:0)+1)})),e}function Vs(s,t,e,n){if(!e.length)return;let i=s.createDiv({cls:"csv-stats-section"});i.createDiv({cls:"csv-stats-section-title",text:t});let o=Math.max(...e.map(r=>r.count));e.forEach(r=>{var h;let a=i.createDiv({cls:"csv-stats-bar-row"});a.createDiv({cls:"csv-stats-bar-label",text:r.label,attr:{title:r.label}});let c=a.createDiv({cls:"csv-stats-bar-track"}).createDiv({cls:`csv-stats-bar-fill ${(h=r.cls)!=null?h:""}`});c.style.width=`${Math.max(2,Math.round(r.count/o*100))}%`;let d=n>0?Math.round(r.count/n*100):0;a.createDiv({cls:"csv-stats-bar-count",text:`${r.count} \xB7 ${d}%`}),r.onClick&&(a.addClass("is-clickable"),a.title=`Show "${r.label}" in the library`,a.addEventListener("click",r.onClick))})}function mr(s,t){let e=s.getFilteredRows();if(s.searchQuery.trim()&&t.createDiv({cls:"csv-search-results",text:`Stats over ${e.length} of ${s.rows.length} entries`}),!e.length){t.createEl("p",{text:"No entries to chart.",cls:"csv-empty-state"});return}let n=t.createDiv({cls:"csv-stats-wrap"}),i=s.getStatusCol(),o=s.getCategoryCol(),r=fr(s),a=s.authorKey(),l=s.resolveCol(["Year","year"]),c=n.createDiv({cls:"csv-stats-overview"}),d=(u,f)=>{let g=c.createDiv({cls:"csv-stats-chip"});g.createDiv({cls:"csv-stats-chip-value",text:u}),g.createDiv({cls:"csv-stats-chip-label",text:f})};if(d(String(e.length),"entries"),i){let u=e.filter(g=>{var p;return gr.includes(((p=g[i])!=null?p:"").toLowerCase().trim())}).length;u>0&&d(`${u} \xB7 ${Math.round(u/e.length*100)}%`,"done");let f=e.filter(g=>{var p;return pr.includes(((p=g[i])!=null?p:"").toLowerCase().trim())}).length;f>0&&d(String(f),"in progress")}if(o){let u=Is(e,f=>{var g;return((g=f[o])!=null?g:"").split(",").map(p=>p.trim()).filter(Boolean)});u.size>0&&d(String(u.size),o.toLowerCase()==="genre"||o.toLowerCase()==="genres"?"genres":"categories")}if(r){let u=e.map(f=>Bs(f[r])).filter(f=>f!==null);if(u.length){let f=u.reduce((g,p)=>g+p,0)/u.length;d(`\u2605 ${f.toFixed(1)}`,`avg of ${u.length} rated`)}}let h=(u,f)=>{s.libraryStatusFilter=u!=null?u:"all",s.libraryGenreFilter=f!=null?f:"all",s.mode="library",s.renderView()};if(i){let u=Is(e,g=>{var b;let p=((b=g[i])!=null?b:"").trim();return p?[p]:[]}),f=Array.from(u.entries()).sort((g,p)=>p[1]-g[1]).map(([g,p])=>({label:g,count:p,cls:Gc(g),onClick:o?()=>h(g,null):void 0}));Vs(n,`By ${i.toLowerCase()}`,f,e.length)}if(o){let u=Is(e,g=>{var p;return((p=g[o])!=null?p:"").split(",").map(b=>b.trim()).filter(Boolean)}),f=Array.from(u.entries()).sort((g,p)=>p[1]-g[1]||g[0].localeCompare(p[0])).slice(0,12).map(([g,p])=>({label:g,count:p,onClick:()=>h(null,g)}));Vs(n,`By ${o.toLowerCase()}`,f,e.length)}if(r){let u=new Map,f=0;if(e.forEach(g=>{var m;let p=Bs(g[r]);if(p===null)return;let b=Math.min(5,Math.max(1,Math.round(p)));u.set(b,((m=u.get(b))!=null?m:0)+1),f++}),f>0){let g=[5,4,3,2,1].filter(p=>{var b;return((b=u.get(p))!=null?b:0)>0}).map(p=>({label:"\u2605".repeat(p),count:u.get(p),cls:"is-rating"}));Vs(n,"Ratings",g,f)}}if(l){let u=Is(e,f=>{var p;let g=((p=f[l])!=null?p:"").match(/\d{4}/);return g?[g[0]]:[]});if(u.size>1){let f=Array.from(u.entries()).sort((g,p)=>g[0].localeCompare(p[0])).map(([g,p])=>({label:g,count:p}));Vs(n,"By year",f,e.length)}}if(a){let u=Is(e,g=>{var b;let p=((b=g[a])!=null?b:"").trim();return p?[p]:[]}),f=Array.from(u.entries()).filter(([,g])=>g>1);if(f.length>=2){let g=f.sort((p,b)=>b[1]-p[1]||p[0].localeCompare(b[0])).slice(0,8).map(([p,b])=>({label:p,count:b}));Vs(n,`Top ${a.toLowerCase()}s`,g,e.length)}}}function $t(s){let t=s.fileCfg.kanbanGroupCol;if(t&&s.headers.includes(t))return t;let e=s.getCategoryCol();if(e)return e;let n=new Set;s.headers.forEach(r=>{s.isNotesCol(r)&&n.add(r)});let i=s.getDateCol();i&&n.add(i);let o=s.titleKey();return o&&n.add(o),tr(s.headers,s.rows,n)}function Cn(s,t){let e=$t(s);if(!e){t.createEl("p",{text:"No groupable column found.",cls:"csv-empty-state"});return}let n=s.getCategoryCol(),i=s.getStatusCol(),o=i===e?null:i,r=s.getFilteredRows();s.searchQuery.trim()&&t.createDiv({cls:"csv-search-results",text:`Found ${r.length} of ${s.rows.length} entries`});let a=t.createDiv({cls:"csv-kanban-groupbar"});a.createSpan({cls:"csv-kanban-groupbar-label",text:"Group by"});let l=a.createEl("select",{cls:"csv-library-filter-select"});s.headers.filter(b=>!s.isNotesCol(b)).forEach(b=>{let m=l.createEl("option",{text:b===n?`${b} (default)`:b,value:b});b===e&&(m.selected=!0)}),l.addEventListener("change",()=>{let b=s.fileCfg;b.kanbanGroupCol=l.value===n?void 0:l.value,s.saveFileCfg(b),s.renderView(!0)});let c=Zo(e,r.map(b=>{var m;return(m=b[e])!=null?m:""})),d=b=>{var C;let m=(C=b[e])!=null?C:"",y;if(c){let E=Jo(m);y=E?[E]:[]}else y=m.split(",").map(E=>E.trim()).filter(Boolean);return y.length||(y=["\u2014"]),y},h=new Set;r.forEach(b=>d(b).forEach(m=>h.add(m)));let u=Array.from(h).sort();if(!u.length){let b=t.createDiv({cls:"csv-empty-state"});b.createEl("p",{text:s.searchQuery?"No matching entries found.":`No "${e}" values found.`}),s.searchQuery&&b.createEl("button",{cls:"csv-clear-filters-btn",text:"Clear search"}).addEventListener("click",()=>{s.searchQuery="",s.renderView()});return}let f=["In progress","Finished","Not started"],g=o?Array.from(new Set([...f,...r.map(b=>{var m;return(m=b[o])!=null?m:""}).filter(Boolean)])).filter(b=>r.some(m=>{var y;return((y=m[o])!=null?y:"")==b})):[],p=t.createDiv({cls:"csv-kanban-board"});u.forEach(b=>{let m=r.filter(S=>d(S).includes(b));if(!m.length)return;let y=p.createDiv({cls:"csv-kanban-col"}),C=y.createDiv({cls:"csv-kanban-col-header"});C.createDiv({cls:"csv-kanban-col-title",text:b}),C.createDiv({cls:"csv-kanban-col-count",text:String(m.length)});let E=y.createDiv({cls:"csv-kanban-col-body"});if(o&&g.length){g.forEach(v=>{let _=m.filter(D=>{var k;return((k=D[o])!=null?k:"")===v});if(!_.length)return;let w=E.createDiv({cls:"csv-kanban-status-group"});w.createDiv({cls:`csv-kanban-status-label status-${v.toLowerCase().replace(/\s+/g,"-")}`,text:v}),_.forEach(D=>Ei(s,w,D,o,e))});let S=new Set(g),x=m.filter(v=>{var _;return!S.has((_=v[o])!=null?_:"")});if(x.length){let v=E.createDiv({cls:"csv-kanban-status-group"});v.createDiv({cls:"csv-kanban-status-label",text:"\u2014"}),x.forEach(_=>Ei(s,v,_,o,e))}}else m.forEach(S=>Ei(s,E,S,o,e))})}function Ei(s,t,e,n,i){var _,w,D,k,T,A,I,V;let o=t.createDiv({cls:"csv-kanban-card"}),r=s.getNotesCol(),a=(w=(_=s.getImageCol)==null?void 0:_.call(s))!=null?w:null;if(a){let O=un(s.app,(D=e[a])!=null?D:"",(T=(k=s.file)==null?void 0:k.path)!=null?T:"");if(O){let M=o.createEl("img",{cls:"csv-kanban-card-img",attr:{src:O,loading:"lazy",alt:""}});M.addEventListener("error",()=>M.remove())}}let l=o.createDiv({cls:"csv-kanban-card-title-row"});l.createDiv({cls:`csv-kanban-card-title ${(A=s.isHighlighted)!=null&&A.call(s,e)?"csv-title-highlight":""}`,text:s.getTitle(e)}).addEventListener("click",O=>{O.stopPropagation(),s.openNoteExpander(e,r!=null?r:"")});let d=s.notesFileExists(e);l.createEl("button",{cls:`csv-kanban-notes-icon ${d?"exists":""}`,text:d?"\u{1F4C4}":"+",title:d?"Open notes file":"Create notes file"}).addEventListener("click",O=>{O.stopPropagation(),s.openOrCreateNotes(e)});let u=s.getSubtitle(e);u&&o.createDiv({cls:"csv-kanban-card-sub",text:u});let f=s.titleKey(),g=s.authorKey(),p=new Set([n,f,g,i].filter(Boolean)),b=o.createDiv({cls:"csv-kanban-card-meta"});((I=s.fileCfg.cardFields)!=null?I:s.headers).forEach(O=>{if(!s.headers.includes(O)||p.has(O)||s.isNotesCol(O))return;let M=b.createDiv({cls:"csv-kanban-chip"});if(M.createSpan({cls:"csv-chip-label",text:O+": "}),s.isSelectCol(O)){let j=M.createSpan({cls:`csv-chip-value csv-chip-select${e[O]?"":" csv-chip-value--empty"}`,text:e[O]||"\u2014"});j.addEventListener("click",F=>{F.stopPropagation(),Ft(j,e[O],s.getColumnValues(O),Y=>{e[O]=Y,j.setText(Y||"\u2014"),j.classList.toggle("csv-chip-value--empty",!Y),s.scheduleSave()},s.contentEl,{multi:xt(O)})})}else{let j=e[O]?e[O].length>40?e[O].slice(0,38)+"\u2026":e[O]:"\u2014",F=M.createSpan({cls:`csv-chip-value${e[O]?"":" csv-chip-value--empty"}`,text:j});e[O]&&e[O].length>40&&(F.title=e[O])}});let y=s.getNotesCol(),C=!!(y&&((V=e[y])!=null&&V.trim())),E=o.createDiv({cls:"csv-kanban-notes-preview"});if(C&&y){let O=e[y].replace(/#{1,6}\s/g,"").replace(/[*_>`]/g,"").replace(/\n+/g," ").trim();E.setText(O.slice(0,120)+(O.length>120?"\u2026":"")),E.title="Click to edit"}else E.addClass("csv-kanban-notes-preview--empty"),y&&E.setText("+ Add note");let S=o.createDiv({cls:"csv-kanban-notes-editor"});S.style.display="none";let x=()=>{var W,K,N;let O=s.contentEl.querySelector(".csv-content-area"),M=(W=O==null?void 0:O.scrollLeft)!=null?W:0,j=(K=O==null?void 0:O.scrollTop)!=null?K:0;E.style.display="none",S.style.display="block",S.empty();let F=S.createEl("textarea",{cls:"csv-notes-textarea"});F.value=(N=y?e[y]:"")!=null?N:"",F.addEventListener("click",P=>P.stopPropagation()),F.addEventListener("mousedown",P=>P.stopPropagation()),F.addEventListener("input",()=>{F.style.height="auto",F.style.height=F.scrollHeight+"px"});let Y=F.value,$=!1,R=P=>{$||($=!0,v(P,O,M,j))};F.addEventListener("keydown",P=>{P.key==="Escape"&&R(Y)}),F.addEventListener("blur",()=>R(F.value)),F.focus({preventScroll:!0}),F.setSelectionRange(0,0),F.scrollTop=0,requestAnimationFrame(()=>{F.style.height="auto",F.style.height=Math.max(120,F.scrollHeight)+"px"})},v=(O,M,j,F)=>{var Y;if(y&&O!==((Y=e[y])!=null?Y:"")&&(e[y]=O,s.scheduleSave()),S.style.display="none",E.style.display="",O.trim()){let $=O.replace(/#{1,6}\s/g,"").replace(/[*_>`]/g,"").replace(/\n+/g," ").trim();E.setText($.slice(0,120)+($.length>120?"\u2026":"")),E.removeClass("csv-kanban-notes-preview--empty"),E.title="Click to edit"}else E.addClass("csv-kanban-notes-preview--empty"),E.setText(y?"+ Add note":""),E.removeAttribute("title");M&&(M.scrollLeft=j,M.scrollTop=F,requestAnimationFrame(()=>{M.scrollLeft=j,M.scrollTop=F,requestAnimationFrame(()=>{M.scrollLeft=j,M.scrollTop=F})}),setTimeout(()=>{M.scrollLeft=j,M.scrollTop=F},50))};E.addEventListener("click",O=>{if(O.stopPropagation(),y&&matchMedia("(pointer: coarse)").matches){s.openNoteExpander(e,y);return}x()}),o.addEventListener("contextmenu",O=>s.openRowContextMenu(e,O))}function _n(s,t){var w,D;let e=$t(s),n=s.getStatusCol(),i=(w=s.titleKey())!=null?w:s.headers[0],o=s.authorKey();if(!e){t.createEl("p",{text:"No groupable column found.",cls:"csv-empty-state"});return}let r=new Set;s.rows.forEach(k=>{var A;((A=k[e])!=null?A:"").split(",").map(I=>I.trim()).filter(Boolean).forEach(I=>r.add(I))});let a=new Set;n&&s.rows.forEach(k=>{var A;let T=((A=k[n])!=null?A:"").trim();T&&a.add(T)});let l=t.createDiv({cls:"csv-library-filters"}),c=l.createEl("select",{cls:"csv-library-filter-select"});c.createEl("option",{text:"All",value:"all"});let d=["watched","read","finished","completed","done","yes","seen"],h=["watching","reading","in progress","in-progress"],u=Array.from(a).some(k=>d.includes(k.toLowerCase())),f=Array.from(a).some(k=>h.includes(k.toLowerCase()));(u||f)&&(c.createEl("option",{text:"\u2500\u2500\u2500\u2500\u2500\u2500\u2500",value:"",attr:{disabled:"true"}}),u&&c.createEl("option",{text:"\u2713 Done",value:"__done__"}),f&&c.createEl("option",{text:"\u25D0 In Progress",value:"__inprogress__"}),c.createEl("option",{text:"\u25CB Not Started",value:"__notstarted__"})),a.size>0&&(c.createEl("option",{text:"\u2500\u2500\u2500\u2500\u2500\u2500\u2500",value:"",attr:{disabled:"true"}}),Array.from(a).sort().forEach(k=>{c.createEl("option",{text:k,value:k})})),c.value=s.libraryStatusFilter;let g=l.createEl("select",{cls:"csv-library-filter-select"});g.createEl("option",{text:"All genres",value:"all"}),Array.from(r).sort().forEach(k=>{g.createEl("option",{text:k,value:k})}),g.value=s.libraryGenreFilter;let p=s.resolveCol(["Year","year","Date","date"]),b=s.resolveCol(["Rating","rating","Score","score","Score /5","Stars","stars"]),m=s.resolveCol(["Theme","theme","Tags","tags","Tag","tag","Mood","mood"]),y=(D=s.fileCfg.librarySort)!=null?D:"status",C=l.createEl("select",{cls:"csv-library-filter-select"}),E=[["status","Sort: Status"],["title","Sort: Title"]];b&&E.push(["rating","Sort: Rating"]),p&&E.push(["year","Sort: Year"]),E.forEach(([k,T])=>{let A=C.createEl("option",{text:T,value:k});k===y&&(A.selected=!0)}),C.addEventListener("change",()=>{let k=s.fileCfg;k.librarySort=C.value==="status"?void 0:C.value,s.saveFileCfg(k),s.renderView(!0)});let S=()=>{s.libraryStatusFilter=c.value,s.libraryGenreFilter=g.value,s.renderView(!0)};c.addEventListener("change",S),g.addEventListener("change",S);let x=s.rows.filter(k=>{var T,A;if(s.libraryStatusFilter!=="all"&&n){let I=((T=k[n])!=null?T:"").toLowerCase();if(s.libraryStatusFilter==="__done__"){if(!d.includes(I))return!1}else if(s.libraryStatusFilter==="__inprogress__"){if(!h.includes(I))return!1}else if(s.libraryStatusFilter==="__notstarted__"){if(d.includes(I)||h.includes(I))return!1}else if(I!==s.libraryStatusFilter.toLowerCase())return!1}if(s.libraryGenreFilter!=="all"&&!((A=k[e])!=null?A:"").split(",").map(V=>V.trim().toLowerCase()).includes(s.libraryGenreFilter.toLowerCase()))return!1;if(s.searchQuery.trim()){let I=s.searchQuery.toLowerCase().trim();if(!s.headers.some(V=>{var O;return((O=k[V])!=null?O:"").toLowerCase().includes(I)}))return!1}return!0});(s.libraryStatusFilter!=="all"||s.libraryGenreFilter!=="all"||s.searchQuery.trim())&&t.createDiv({cls:"csv-library-result-count",text:`Showing ${x.length} of ${s.rows.length} entries`});let v={};x.forEach(k=>{var A;let T=s.libraryGenreFilter!=="all"?[s.libraryGenreFilter]:((A=k[e])!=null?A:"Uncategorized").split(",").map(I=>I.trim()).filter(Boolean);T.length===0&&T.push("Uncategorized"),T.forEach(I=>{v[I]||(v[I]=[]),v[I].push(k)})});let _=t.createDiv({cls:"csv-library-sections"});if(Object.keys(v).sort().forEach(k=>{var R,W,K,N,P;let T=v[k],A=_.createEl("details",{cls:"csv-library-section"}),I=k.toLowerCase(),V=((R=s.fileCfg.collapsedGroups)!=null?R:[]).map(L=>L.toLowerCase());A.open=!((W=s.collapsedGroups)!=null&&W.has(I)||V.includes(I)),A.addEventListener("toggle",()=>{var U;let L=s.fileCfg,z=((U=L.collapsedGroups)!=null?U:[]).map(q=>q.toLowerCase()),B=new Set(z);A.open?B.delete(I):B.add(I);let H=Array.from(B);H.length===z.length&&H.every(q=>z.includes(q))||(L.collapsedGroups=H,s.saveFileCfg(L))});let O=A.createEl("summary",{cls:"csv-library-section-header"});O.innerHTML=`<span class="csv-library-arrow">\u25B6</span> ${k} <span class="csv-library-count">${T.length}</span>`;let M=A.createDiv({cls:"csv-library-grid"}),j=(L,z)=>{var B,H;return((B=L[i])!=null?B:"").localeCompare((H=z[i])!=null?H:"")},F=(L,z)=>L===null&&z===null?0:L===null?1:z===null?-1:z-L;T.sort((L,z)=>{var B,H,U,q;if(y==="title")return j(L,z);if(y==="rating"&&b)return F(Bs((B=L[b])!=null?B:""),Bs((H=z[b])!=null?H:""))||j(L,z);if(y==="year"&&p){let X=Z=>{var Q;let at=((Q=Z[p])!=null?Q:"").match(/\d{4}/);return at?parseInt(at[0],10):null};return F(X(L),X(z))||j(L,z)}if(n){let X=((U=L[n])!=null?U:"").toLowerCase(),Z=((q=z[n])!=null?q:"").toLowerCase(),at=d.includes(X),Q=d.includes(Z);if(at!==Q)return at?-1:1;let st=h.includes(X),lt=h.includes(Z);if(st!==lt)return st?-1:1}return j(L,z)});let Y=(K=s.fileCfg.cardFields)!=null?K:s.headers,$=(P=(N=s.getImageCol)==null?void 0:N.call(s))!=null?P:null;T.forEach(L=>{var q,X,Z,at,Q,st,lt,Wt;let z=M.createDiv({cls:"csv-library-card"});if($){let ot=un(s.app,(q=L[$])!=null?q:"",(Z=(X=s.file)==null?void 0:X.path)!=null?Z:"");if(ot){let pt=z.createEl("img",{cls:"csv-library-card-img",attr:{src:ot,loading:"lazy",alt:""}});pt.addEventListener("error",()=>pt.remove())}}let B=z.createDiv({cls:`csv-library-card-title ${(at=s.isHighlighted)!=null&&at.call(s,L)?"csv-title-highlight":""}`});if(n){let ot=((Q=L[n])!=null?Q:"").toLowerCase();d.includes(ot)&&B.createSpan({cls:"csv-library-done-dot"})}B.createSpan({text:(st=L[i])!=null?st:"Untitled"});let H=[],U=[];for(let ot of Y){if(!ot)continue;let pt=String((lt=L[ot])!=null?lt:"").trim();if(pt)if(ot===b){let ft=Qo(pt,ot);ft&&z.createDiv({cls:"csv-library-card-rating",text:ft})}else if(ot===m)U.push(...pt.split(",").map(ft=>ft.trim()).filter(Boolean));else if(ot===p){let ft=pt.match(/\d{4}/);H.push(ft?ft[0]:pt)}else H.push(pt)}if(H.length&&z.createDiv({cls:"csv-library-card-meta",text:H.join(" \xB7 ")}),s.libraryGenreFilter!=="all"){let ot=((Wt=L[e])!=null?Wt:"").split(",").map(pt=>pt.trim()).filter(pt=>pt&&pt.toLowerCase()!==s.libraryGenreFilter.toLowerCase());U.push(...ot)}if(U.length){let ot=z.createDiv({cls:"csv-library-card-tags"});U.slice(0,3).forEach(pt=>{ot.createSpan({cls:"csv-library-card-tag",text:pt})})}z.addEventListener("click",()=>{var ot;s.openNoteExpander(L,(ot=s.getNotesCol())!=null?ot:"")}),z.addEventListener("contextmenu",ot=>s.openRowContextMenu(L,ot))})}),Object.keys(v).length===0){let k=_.createDiv({cls:"csv-empty-state"});k.createEl("p",{text:"No entries match your filters."}),k.createEl("button",{cls:"csv-clear-filters-btn",text:"Clear filters"}).addEventListener("click",()=>{s.libraryStatusFilter="all",s.libraryGenreFilter="all",s.searchQuery="",s.renderView()})}}var gi=require("obsidian");var Le=require("obsidian");var ki=`---
obsidianUIMode: preview
obsidianEditingMode: source
---
`,wi=`
---
<small style="color:var(--text-faint)">Requires Dataview plugin with DataviewJS enabled</small>
`;function br(s){let{filePath:t,csvPath:e,habitCols:n,labels:i,dateCol:o}=s;return`${ki}## Quick Add
\`\`\`csv-add
file: ${t}
\`\`\`
## Entries
\`\`\`csv-refresh
\`\`\`
\`\`\`dataviewjs
const csvData = await dv.io.csv("${e}");
if (!csvData || !csvData.length) {
dv.paragraph("No data found");
} else {
const data = csvData.array();
const habits = [${n.map(r=>`"${r}"`).join(", ")}];
const labels = [${i.map(r=>`"${r}"`).join(", ")}];
// View toggle state (stored in localStorage)
const viewKey = "csv-mobile-view-" + dv.current().file.path;
let showAll = localStorage.getItem(viewKey) === "all";
const container = dv.container;
// View toggle buttons
const toggleWrap = container.createEl("div", { cls: "csv-mobile-toggle" });
const recentBtn = toggleWrap.createEl("button", { text: "Recent", cls: showAll ? "" : "active" });
const allBtn = toggleWrap.createEl("button", { text: "All " + data.length, cls: showAll ? "active" : "" });
recentBtn.onclick = () => { localStorage.setItem(viewKey, "recent"); location.reload(); };
allBtn.onclick = () => { localStorage.setItem(viewKey, "all"); location.reload(); };
// Apply minimal styles
toggleWrap.style.cssText = "display:flex;gap:8px;margin-bottom:16px;";
[recentBtn, allBtn].forEach(btn => {
btn.style.cssText = "padding:6px 12px;border:none;background:transparent;color:var(--text-muted);font-size:13px;font-weight:500;cursor:pointer;border-radius:6px;";
if (btn.classList.contains("active")) {
btn.style.background = "var(--background-secondary)";
btn.style.color = "var(--text-normal)";
}
});
// Get entries based on view
const entries = showAll ? [...data].reverse() : data.slice(-10).reverse();
// Table wrapper
const tableWrap = container.createEl("div");
tableWrap.style.cssText = "overflow-x:auto;font-size:14px;";
// Render table
const table = tableWrap.createEl("table");
table.style.cssText = "width:100%;border-collapse:collapse;";
// Header
const thead = table.createEl("thead");
const headerRow = thead.createEl("tr");
["Date", ...labels].forEach(h => {
const th = headerRow.createEl("th", { text: h });
th.style.cssText = "text-align:left;padding:8px 10px;font-weight:500;color:var(--text-muted);font-size:12px;white-space:nowrap;border-bottom:1px solid var(--background-modifier-border);";
if (h !== "Date") th.style.textAlign = "center";
});
// Body
const tbody = table.createEl("tbody");
entries.forEach(r => {
const dateVal = r["${o}"];
let shortDate = "";
if (dateVal?.toFormat) {
shortDate = dateVal.toFormat("MM-dd");
} else if (dateVal instanceof Date) {
shortDate = (dateVal.getMonth()+1).toString().padStart(2,"0") + "-" + dateVal.getDate().toString().padStart(2,"0");
} else {
const s = String(dateVal ?? "");
shortDate = s.length >= 10 ? s.slice(5, 10) : s;
}
const row = tbody.createEl("tr");
const dateCell = row.createEl("td", { text: shortDate });
dateCell.style.cssText = "padding:10px;color:var(--text-muted);font-size:13px;";
habits.forEach(h => {
const td = row.createEl("td");
td.style.cssText = "padding:10px;text-align:center;";
const done = r[h] == "1" || r[h] == "true";
td.textContent = done ? "\u2713" : "\xB7";
td.style.color = done ? "var(--text-accent)" : "var(--text-faint)";
td.style.fontWeight = done ? "600" : "400";
});
});
if (!showAll && data.length > 10) {
const hint = container.createEl("p");
hint.style.cssText = "color:var(--text-faint);font-size:12px;margin-top:12px;";
hint.textContent = "Showing last 10 of " + data.length + " entries";
}
}
\`\`\`
${wi}`}function vr(s){let{filePath:t,csvPath:e,titleKey:n,categoryCol:i,statusCol:o,authorKey:r,yearCol:a,ratingCol:l,themeCol:c,compactGrid:d}=s;return`${ki}## Add Entry
\`\`\`csv-add
file: ${t}
\`\`\`
## Library
\`\`\`csv-refresh
\`\`\`
\`\`\`dataviewjs
const csvData = await dv.io.csv("${e}");
if (!csvData || !csvData.length) {
dv.paragraph("No data found");
} else {
const data = csvData.array();
const container = dv.container;
// Keys
const titleKey = "${n}";
const categoryCol = "${i}";
const statusCol = "${o}";
const authorKey = "${r}";
const yearCol = "${a}";
const ratingCol = "${l}";
const themeCol = "${c}";
const compactGrid = ${d};
// View state
const viewKey = "csv-mobile-view-" + dv.current().file.path;
const modeKey = "csv-mobile-mode-" + dv.current().file.path;
let viewMode = localStorage.getItem(modeKey) || "kanban";
// Inject styles
const style = container.createEl("style");
style.textContent = \`
.csv-m-toggle { display:flex; gap:8px; margin-bottom:16px; }
.csv-m-toggle button { padding:6px 12px; border:none; background:transparent; color:var(--text-muted); font-size:13px; font-weight:500; cursor:pointer; border-radius:6px; }
.csv-m-toggle button.active { background:var(--background-secondary); color:var(--text-normal); }
.csv-m-section { margin-bottom:14px; }
.csv-m-section summary { list-style:none; cursor:pointer; padding:6px 4px; font-weight:600; font-size:13px; display:flex; align-items:center; gap:8px; user-select:none; color:var(--text-normal); }
.csv-m-section summary::-webkit-details-marker { display:none; }
.csv-m-section summary .arrow { font-size:11px; color:var(--text-faint); transition:transform 0.2s; line-height:1; }
.csv-m-section[open] summary .arrow { transform:rotate(90deg); }
.csv-m-section summary .count { font-weight:500; font-size:12px; color:var(--text-faint); margin-left:auto; }
.csv-m-grid { display:grid; grid-template-columns:1fr; gap:8px; padding:8px 0 2px; }
.csv-m-grid.compact { grid-template-columns:1fr 1fr; gap:8px; }
.csv-m-card { padding:10px 12px; border-radius:10px; background:var(--background-secondary); display:flex; flex-direction:column; gap:4px; }
.csv-m-card-title { font-weight:600; font-size:13px; display:flex; align-items:center; gap:8px; line-height:1.3; }
.csv-m-watched-dot { display:inline-block; width:8px; height:8px; border-radius:50%; background:var(--csv-green, #30A14E); flex-shrink:0; }
.csv-m-card-meta { font-size:12px; color:var(--text-muted); }
.csv-m-card-year { font-size:11px; color:var(--text-muted); }
.csv-m-card-rating { font-size:11px; color:var(--text-muted); letter-spacing:1px; }
.csv-m-card-theme { display:inline-block; align-self:flex-start; font-size:11px; padding:2px 8px; border-radius:999px; background:var(--background-modifier-border); color:var(--text-muted); margin-top:4px; }
.csv-m-card-status { display:inline-block; align-self:flex-start; font-size:11px; padding:2px 8px; border-radius:999px; margin-top:4px; background:var(--background-modifier-border); color:var(--text-muted); }
.csv-m-card-status.finished, .csv-m-card-status.read, .csv-m-card-status.watched { background:var(--csv-green-bg, rgba(52,199,89,0.13)); color:var(--csv-green, #30A14E); }
.csv-m-card-status.in-progress, .csv-m-card-status.reading, .csv-m-card-status.watching { background:var(--csv-blue-bg, rgba(0,122,255,0.13)); color:var(--csv-blue, #2E7CE6); }
\`;
// View toggle
const toggleWrap = container.createEl("div", { cls: "csv-m-toggle" });
["Kanban", "Table"].forEach(mode => {
const btn = toggleWrap.createEl("button", { text: mode });
if (mode.toLowerCase() === viewMode) btn.classList.add("active");
btn.onclick = () => { localStorage.setItem(modeKey, mode.toLowerCase()); location.reload(); };
});
if (viewMode === "table") {
// Table view
const tableWrap = container.createEl("div");
tableWrap.style.cssText = "overflow-x:auto;font-size:14px;";
const table = tableWrap.createEl("table");
table.style.cssText = "width:100%;border-collapse:collapse;";
const thead = table.createEl("thead");
const headerRow = thead.createEl("tr");
[titleKey, categoryCol, statusCol].filter(Boolean).forEach(h => {
const th = headerRow.createEl("th", { text: h });
// Match desktop table convention: uppercase, 11px, tracked, muted.
th.style.cssText = "text-align:left;padding:8px 10px;font-weight:600;color:var(--text-faint);font-size:11px;text-transform:uppercase;letter-spacing:0.05em;border-bottom:1px solid var(--background-modifier-border);";
});
const tbody = table.createEl("tbody");
data.slice(-30).reverse().forEach(r => {
const row = tbody.createEl("tr");
[titleKey, categoryCol, statusCol].filter(Boolean).forEach(col => {
const td = row.createEl("td", { text: String(r[col] ?? "") });
td.style.cssText = "padding:10px;font-size:13px;";
});
});
} else {
// Kanban view \u2014 group by category. String() guards against numeric values that
// Dataview's CSV parser coerces (e.g. the book "1984" \u2192 Number).
const groups = {};
data.forEach(r => {
const cats = String(r[categoryCol] || "Uncategorized").split(",").map(c => c.trim());
cats.forEach(cat => {
if (!groups[cat]) groups[cat] = [];
groups[cat].push(r);
});
});
// Negative/default states render as nothing \u2014 keeps cards quiet by default.
const NEGATIVE_STATUS = new Set(["", "no", "not started", "unwatched", "unread", "todo"]);
// Affirmative-finished values render as a green dot prefix on the title (matches desktop Library).
const WATCHED_AFFIRMATIVE = new Set(["yes", "watched", "seen", "finished", "read"]);
Object.keys(groups).sort().forEach(cat => {
const items = groups[cat];
const section = container.createEl("details", { cls: "csv-m-section" });
section.open = true;
const summary = section.createEl("summary");
summary.innerHTML = '<span class="arrow">\u25B6</span> ' + cat + ' <span class="count">' + items.length + '</span>';
const grid = section.createEl("div", { cls: "csv-m-grid" + (compactGrid ? " compact" : "") });
// Sort: green-dotted (read/watched/finished) first, then in-progress,
// then the rest. Mirrors desktop Library: section reads as catalogue
// (consumed \u2192 backlog), not a todo list.
items.sort((a, b) => {
const statusA = String(a[statusCol] || "").toLowerCase();
const statusB = String(b[statusCol] || "").toLowerCase();
const isDone = (s) => /^(yes|watched|seen|finished|read|done|completed)$/.test(s);
const isInProgress = (s) => s.includes("progress") || s.includes("reading") || s.includes("watching");
const doneA = isDone(statusA), doneB = isDone(statusB);
if (doneA !== doneB) return doneA ? -1 : 1;
const inProgressA = isInProgress(statusA), inProgressB = isInProgress(statusB);
if (inProgressA !== inProgressB) return inProgressA ? -1 : 1;
return String(a[titleKey] || "").localeCompare(String(b[titleKey] || ""));
});
items.forEach(r => {
const title = String(r[titleKey] ?? "").trim();
if (!title) return; // skip rows with no title \u2014 keeps the kanban free of "Untitled" cards
const status = String(r[statusCol] || "").trim();
const statusLc = status.toLowerCase();
const affirmative = WATCHED_AFFIRMATIVE.has(statusLc);
const card = grid.createEl("div", { cls: "csv-m-card" });
const titleEl = card.createEl("div", { cls: "csv-m-card-title" });
if (affirmative) {
titleEl.createEl("span", { cls: "csv-m-watched-dot", attr: { title: status } });
}
titleEl.createEl("span", { text: title });
// Year (small muted, just under title)
const year = yearCol ? String(r[yearCol] ?? "").trim() : "";
if (year) {
card.createEl("div", { cls: "csv-m-card-year", text: year });
}
// Author/Director \u2014 only in non-compact mode (movies skip director to save vertical room).
if (!compactGrid && authorKey && r[authorKey]) {
card.createEl("div", { cls: "csv-m-card-meta", text: String(r[authorKey]) });
}
// Rating (data is already rendered as unicode stars \u2014 render as-is, hide "unrated").
const rating = ratingCol ? String(r[ratingCol] ?? "").trim() : "";
if (rating && rating.toLowerCase() !== "unrated") {
card.createEl("div", { cls: "csv-m-card-rating", text: rating });
}
// Theme \u2014 small inline pill at the bottom. Multi-value (comma-separated) renders just the first.
const theme = themeCol ? String(r[themeCol] ?? "").split(",")[0].trim() : "";
if (theme) {
card.createEl("span", { cls: "csv-m-card-theme", text: theme });
}
// Status pill only for non-trivial states (e.g. "In progress").
// Affirmative values became the dot above; negative values render nothing.
if (status && !NEGATIVE_STATUS.has(statusLc) && !affirmative) {
const statusEl = card.createEl("span", { cls: "csv-m-card-status", text: status });
statusEl.classList.add(statusLc.replace(/\\s+/g, "-"));
}
});
});
}
}
\`\`\`
${wi}`}function yr(s){let{filePath:t,csvPath:e,headers:n}=s;return`${ki}## Add Entry
\`\`\`csv-add
file: ${t}
\`\`\`
## Entries
\`\`\`csv-refresh
\`\`\`
\`\`\`dataviewjs
// Generic mobile dashboard \u2014 expandable, scrollable table.
// Used for files without a category column (e.g. dictionary).
const csvData = await dv.io.csv("${e}");
if (!csvData || !csvData.length) {
dv.paragraph("No data found");
} else {
const data = csvData.array();
const headers = [${n.map(i=>JSON.stringify(i)).join(", ")}];
const container = dv.container;
const viewKey = "csv-mobile-view-" + dv.current().file.path;
let showAll = localStorage.getItem(viewKey) === "all";
const style = container.createEl("style");
style.textContent = \`
.csv-m-toggle { display:flex; gap:8px; margin-bottom:16px; }
.csv-m-toggle button { padding:6px 12px; border:none; background:transparent; color:var(--text-muted); font-size:13px; font-weight:500; cursor:pointer; border-radius:6px; }
.csv-m-toggle button.active { background:var(--background-secondary); color:var(--text-normal); }
.csv-m-tablewrap { overflow-x:auto; -webkit-overflow-scrolling:touch; border:1px solid var(--background-modifier-border); border-radius:8px; }
.csv-m-tablewrap table { min-width:100%; border-collapse:collapse; font-size:13px; }
.csv-m-tablewrap th { text-align:left; padding:10px 12px; font-weight:600; color:var(--text-faint); font-size:11px; text-transform:uppercase; letter-spacing:0.05em; white-space:nowrap; border-bottom:1px solid var(--background-modifier-border); background:var(--background-secondary); position:sticky; top:0; }
.csv-m-tablewrap td { padding:10px 12px; vertical-align:top; border-bottom:1px solid var(--background-modifier-border); }
/* Keep short fields on one line; the last column (typically long text like
Meaning or Description) is the only one that wraps. */
.csv-m-tablewrap td:not(:last-child) { white-space:nowrap; }
.csv-m-tablewrap td:last-child { white-space:normal; min-width:200px; }
.csv-m-tablewrap tr:last-child td { border-bottom:none; }
.csv-m-hint { color:var(--text-faint); font-size:12px; margin-top:8px; }
\`;
// Recent / All toggle \u2014 expandable by tapping "All"
const toggleWrap = container.createEl("div", { cls: "csv-m-toggle" });
const recentBtn = toggleWrap.createEl("button", { text: "Recent" });
const allBtn = toggleWrap.createEl("button", { text: "All " + data.length });
if (!showAll) recentBtn.classList.add("active");
else allBtn.classList.add("active");
recentBtn.onclick = () => { localStorage.setItem(viewKey, "recent"); location.reload(); };
allBtn.onclick = () => { localStorage.setItem(viewKey, "all"); location.reload(); };
const entries = showAll ? [...data].reverse() : data.slice(-15).reverse();
const tableWrap = container.createEl("div", { cls: "csv-m-tablewrap" });
const table = tableWrap.createEl("table");
const thead = table.createEl("thead");
const headerRow = thead.createEl("tr");
headers.forEach(h => headerRow.createEl("th", { text: h }));
const tbody = table.createEl("tbody");
entries.forEach(r => {
const row = tbody.createEl("tr");
headers.forEach(h => row.createEl("td", { text: String(r[h] ?? "") }));
});
if (!showAll && data.length > 15) {
const hint = container.createEl("p", { cls: "csv-m-hint" });
hint.textContent = "Showing last 15 of " + data.length + " entries \u2014 tap All to expand";
}
}
\`\`\`
${wi}`}async function xr(s){var c,d,h,u,f,g,p,b,m,y;if(!s.file)return;let t=(d=(c=s.file.parent)==null?void 0:c.path)!=null?d:"",e=t?`${t}/Mobile`:"Mobile";await s.app.vault.adapter.exists(e)||await s.app.vault.adapter.mkdir(e);let n=`${e}/${s.file.basename}.md`,i=s.file.path,o=s.getDateCol(),r=s.getCategoryCol(),a="../"+s.file.name,l;if(o){let C=s.getBooleanColumns();l=br({filePath:a,csvPath:i,habitCols:C,labels:C.map(kt),dateCol:o})}else if(r){let C=(f=(u=(h=s.titleKey())!=null?h:s.resolveCol(["Quote","quote","Headline","headline","Phrase","phrase"]))!=null?u:s.headers[0])!=null?f:"Title";l=vr({filePath:a,csvPath:i,titleKey:C,categoryCol:r,statusCol:(g=s.getStatusCol())!=null?g:"Status",authorKey:(p=s.authorKey())!=null?p:"",yearCol:(b=s.resolveCol(["Year","year","Released","released"]))!=null?b:"",ratingCol:(m=s.resolveCol(["Rating","rating","Score","score","Stars","stars"]))!=null?m:"",themeCol:(y=s.resolveCol(["Theme","theme","Subgenre","subgenre","Mood","mood"]))!=null?y:"",compactGrid:s.titleKey()!==null})}else l=yr({filePath:a,csvPath:i,headers:s.headers});try{let C=s.app.vault.getAbstractFileByPath(n);C&&C instanceof Le.TFile?(await s.app.vault.modify(C,l),new Le.Notice(`Updated: ${n}`)):(await s.app.vault.create(n,l),new Le.Notice(`Created: ${n}`))}catch(C){let E=s.app.vault.getAbstractFileByPath(n);E instanceof Le.TFile&&(await s.app.vault.modify(E,l),new Le.Notice(`Updated: ${n}`))}}var ge=require("obsidian"),qc="http://127.0.0.1:8765",Xc=6;async function Cr(s,t){let e;try{e=await(0,ge.requestUrl)({url:qc,method:"POST",contentType:"application/json",body:JSON.stringify({action:s,version:Xc,params:t}),throw:!1})}catch(i){throw new Error("Couldn't reach Anki. Is the desktop app open with the AnkiConnect add-on installed?")}let n=e.json;if(n.error)throw new Error(n.error);return n.result}function Di(s){var t,e,n;return(n=(e=(t=s.titleKey())!=null?t:s.resolveCol(["Quote","Headline","Phrase","Term","Word","Question","Front","Name","Title"]))!=null?e:s.headers[0])!=null?n:null}function Qc(s){let t=s.fileCfg.ankiFrontCol;return t&&s.headers.includes(t)?t:Di(s)}function Mi(s){return s.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function Zc(s,t,e){return s.headers.filter(n=>{var i;return n!==e&&((i=t[n])!=null?i:"").trim()}).map(n=>`<b>${Mi(n)}:</b> ${Mi(t[n].trim())}`).join("<br>")}async function _r(s){if(!s.file)return;let t=Qc(s);if(!t){new ge.Notice("No column to use as the Anki card front.",6e3);return}let e=s.file.basename,n=s.rows.filter(o=>{var r;return((r=o[t])!=null?r:"").trim()});if(!n.length){new ge.Notice(`Nothing to sync \u2014 no rows with a "${t}" value.`,6e3);return}let i=new ge.Notice(`Syncing ${n.length} cards to Anki deck \u201C${e}\u201D\u2026`,0);try{await Cr("createDeck",{deck:e});let o=n.map(c=>({deckName:e,modelName:"Basic",fields:{Front:Mi(c[t].trim()),Back:Zc(s,c,t)},options:{allowDuplicate:!1,duplicateScope:"deck"},tags:["datadeck"]})),r=await Cr("addNotes",{notes:o}),a=r.filter(c=>c!=null).length,l=r.length-a;i.hide(),new ge.Notice(`Anki sync: ${a} added${l?`, ${l} already present`:""} (deck \u201C${e}\u201D).`,6e3)}catch(o){i.hide(),new ge.Notice(`Anki sync failed: ${o instanceof Error?o.message:String(o)}`,8e3)}}var Oo=null;async function Ue(){if(Oo)return Oo;let s=await Promise.resolve().then(()=>(Ql(),Xl));return s.Chart.register(s.LineController,s.ScatterController,s.BarController,s.LineElement,s.PointElement,s.BarElement,s.LinearScale,s.CategoryScale,s.Filler,s.Tooltip,s.Legend),Oo=s,s}var Zl={pi:Math.PI,e:Math.E},Jl={sin:Math.sin,cos:Math.cos,tan:Math.tan,asin:Math.asin,acos:Math.acos,atan:Math.atan,sqrt:Math.sqrt,log:Math.log10,ln:Math.log,exp:Math.exp,abs:Math.abs,floor:Math.floor,ceil:Math.ceil,round:Math.round,sign:Math.sign},Fo={min:Math.min,max:Math.max,pow:Math.pow,atan2:Math.atan2};function yg(s){let t=[],e=0;for(;e<s.length;){let n=s[e];if(/\s/.test(n)){e++;continue}if(/[0-9.]/.test(n)){let i=s.slice(e).match(/^\d*\.?\d+(?:[eE][+-]?\d+)?/);if(!i||i[0]==="")throw new Error(`Bad number at "${s.slice(e,e+8)}"`);t.push({kind:"num",value:parseFloat(i[0])}),e+=i[0].length;continue}if(/[a-zA-Z_]/.test(n)){let i=s.slice(e).match(/^[a-zA-Z_][a-zA-Z_0-9]*/);t.push({kind:"ident",name:i[0].toLowerCase()}),e+=i[0].length;continue}if("+-*/%^".includes(n)){t.push({kind:"op",op:n}),e++;continue}if(n==="("){t.push({kind:"lparen"}),e++;continue}if(n===")"){t.push({kind:"rparen"}),e++;continue}if(n===","){t.push({kind:"comma"}),e++;continue}throw new Error(`Unexpected character "${n}"`)}return t}function tc(s){let t=s.trim().replace(/^(y|f\s*\(\s*x\s*\))\s*=\s*/i,"");if(!t)throw new Error("Empty formula");let e=yg(t),n=0,i=()=>{var u;return(u=e[n])!=null?u:null},o=()=>{var u;return(u=e[n++])!=null?u:null};function r(){let u=a();for(;;){let f=i();if((f==null?void 0:f.kind)==="op"&&(f.op==="+"||f.op==="-")){n++;let g=a(),p=u;u=f.op==="+"?m=>p(m)+g(m):m=>p(m)-g(m)}else return u}}function a(){let u=l();for(;;){let f=i();if((f==null?void 0:f.kind)==="op"&&(f.op==="*"||f.op==="/"||f.op==="%")){n++;let g=l(),p=u,b=f.op;u=b==="*"?m=>p(m)*g(m):b==="/"?m=>p(m)/g(m):m=>p(m)%g(m)}else if(f&&(f.kind==="num"||f.kind==="ident"||f.kind==="lparen")){let g=l(),p=u;u=b=>p(b)*g(b)}else return u}}function l(){let u=i();if((u==null?void 0:u.kind)==="op"&&u.op==="-"){n++;let f=l();return g=>-f(g)}return(u==null?void 0:u.kind)==="op"&&u.op==="+"?(n++,l()):c()}function c(){let u=d(),f=i();if((f==null?void 0:f.kind)==="op"&&f.op==="^"){n++;let g=l();return p=>Math.pow(u(p),g(p))}return u}function d(){var f,g,p,b,m;let u=o();if(!u)throw new Error("Unexpected end of formula");if(u.kind==="num"){let y=u.value;return()=>y}if(u.kind==="lparen"){let y=r();if(((f=o())==null?void 0:f.kind)!=="rparen")throw new Error("Missing closing )");return y}if(u.kind==="ident"){if(u.name==="x")return C=>C;if(u.name in Zl){let C=Zl[u.name];return()=>C}let y=((g=i())==null?void 0:g.kind)==="lparen";if(u.name in Jl||u.name in Fo){if(!y)throw new Error(`${u.name} needs parentheses, e.g. ${u.name}(x)`);n++;let C=r();if(u.name in Fo){if(((p=o())==null?void 0:p.kind)!=="comma")throw new Error(`${u.name}(a, b) needs two arguments`);let S=r();if(((b=o())==null?void 0:b.kind)!=="rparen")throw new Error("Missing closing )");let x=Fo[u.name];return v=>x(C(v),S(v))}if(((m=o())==null?void 0:m.kind)!=="rparen")throw new Error("Missing closing )");let E=Jl[u.name];return S=>E(C(S))}throw new Error(`Unknown name "${u.name}" \u2014 use x, pi, e, or a function like sin()`)}throw new Error(`Unexpected "${u.kind==="op"?u.op:u.kind}"`)}let h=r();if(n<e.length){let u=e[n];throw new Error(`Unexpected "${u.kind==="op"?u.op:u.kind==="ident"?u.name:u.kind}" after end of expression`)}return h}function ln(s){let t=(s!=null?s:"").trim();if(!t||(/^-?\d{1,3}(?:[,\s]\d{3})+(?:\.\d+)?$/.test(t)?t=t.replace(/[,\s]/g,""):/^-?\d+,\d+$/.test(t)&&(t=t.replace(",",".")),!/^-?\d*\.?\d+(?:[eE][+-]?\d+)?$/.test(t)))return null;let e=parseFloat(t);return Number.isFinite(e)?e:null}function li(s,t){return s.filter(e=>{var o;let n=0,i=0;for(let r of t){let a=((o=r[e])!=null?o:"").trim();a&&(n++,ln(a)!==null&&i++)}return i>=2&&i/n>=.7})}function xg(s){let t=s.length;if(t<2)return null;let e=0,n=0,i=0,o=0,r=0;for(let f of s)e+=f.x,n+=f.y,i+=f.x*f.x,o+=f.x*f.y,r+=f.y*f.y;let a=t*i-e*e;if(a===0)return null;let l=(t*o-e*n)/a,c=(n-l*e)/t,d=n/t,h=0,u=0;for(let f of s){let g=f.y-(l*f.x+c);h+=g*g,u+=(f.y-d)*(f.y-d)}return{slope:l,intercept:c,r2:u===0?1:1-h/u}}function ks(s){var n;let t=(n=s.ownerDocument.defaultView)==null?void 0:n.getComputedStyle(s),e=(i,o)=>(t==null?void 0:t.getPropertyValue(i).trim())||o;return{accent:e("--interactive-accent","#378ADD"),muted:e("--text-muted","#888888"),grid:e("--background-modifier-border","rgba(128,128,128,0.25)"),fitLine:e("--text-faint","#999999"),formula:e("--color-orange","#e0883a"),series:[e("--color-blue","#4e79a7"),e("--color-green","#59a14f"),e("--color-red","#e15759"),e("--color-purple","#b07aa1"),e("--color-cyan","#76b7b2"),e("--color-pink","#ff9da7"),e("--color-yellow","#edc948")]}}var Es=s=>{if(!Number.isFinite(s))return String(s);let t=Math.abs(s);return t!==0&&(t>=1e6||t<.001)?s.toExponential(2):String(Math.round(s*1e3)/1e3)},ec=s=>{let t=new Date(s);return isNaN(t.getTime())?String(s):ts(t)};function ci(s,t){var b,m;let e=[],n=s.series.length>1,i=s.series.flatMap(y=>y.points),o=i.map(y=>y.x),r=i.length?Math.min(...o):(b=s.xMin)!=null?b:0,a=i.length?Math.max(...o):(m=s.xMax)!=null?m:10,l=i.filter(y=>y.size!==void 0),c=l.length?Math.min(...l.map(y=>y.size)):0,d=l.length?Math.max(...l.map(y=>y.size)):0,h=(y,C)=>y.size===void 0?C:d===c?7:3+11*Math.sqrt((y.size-c)/(d-c)),u=[];s.series.forEach((y,C)=>{let E=s.connect?[...y.points].sort((v,_)=>v.x-_.x):y.points;if(!E.length)return;let S=n?t.series[C%t.series.length]:t.accent,x=s.connect?3:4;if(e.push({type:s.connect?"line":"scatter",label:y.label||s.yLabel,data:E,backgroundColor:S,borderColor:S,borderWidth:1.5,pointRadius:l.length?E.map(v=>h(v,x)):x,pointHoverRadius:l.length?E.map(v=>h(v,x)+2):6,tension:.3}),s.fit==="linear"){let v=xg(E),_=E.map(k=>k.x),w=Math.min(..._),D=Math.max(..._);if(v&&D>w){e.push({type:"line",label:`${y.label||"Best"} fit`,csvIsFit:!0,data:[{x:w,y:v.slope*w+v.intercept},{x:D,y:v.slope*D+v.intercept}],borderColor:n?S:t.fitLine,borderDash:[6,4],borderWidth:1.5,pointRadius:0,pointHitRadius:0});let k=` \xB7 R\xB2 = ${(Math.round(v.r2*1e3)/1e3).toFixed(3)}`,T=s.xIsDate?`${v.slope*864e5>=0?"+":""}${Es(v.slope*864e5)} ${s.yLabel}/day${k}`:`y = ${Es(v.slope)}x ${v.intercept>=0?"+":"\u2212"} ${Es(Math.abs(v.intercept))}${k}`;u.push(n?`${y.label}: ${T}`:s.xIsDate?`Trend: ${T}`:T)}}});let f=u.length?u.join(" \xB7 "):null,g=null;if(s.formula.trim())try{let y=tc(s.formula),C=[],E=160;for(let S=0;S<=E;S++){let x=r+(a-r)*S/E,v=y(x);Number.isFinite(v)&&C.push({x,y:v})}C.length&&e.push({type:"line",label:s.formula.trim(),data:C,borderColor:t.formula,borderWidth:1.5,pointRadius:0,pointHitRadius:0,tension:0})}catch(y){g=y instanceof Error?y.message:String(y)}return{config:{type:"scatter",data:{datasets:e},options:{responsive:!0,maintainAspectRatio:!1,scales:{x:{type:"linear",title:{display:!s.xIsDate&&!!s.xLabel,text:s.xLabel,color:t.muted},ticks:{color:t.muted,...s.xIsDate?{callback:y=>ec(Number(y)),maxTicksLimit:8}:{}},grid:{color:t.grid}},y:{title:{display:!!s.yLabel,text:s.yLabel,color:t.muted},ticks:{color:t.muted},grid:{color:t.grid}}},plugins:{legend:{display:e.filter(y=>!y.csvIsFit).length>1,labels:{color:t.muted,boxWidth:12,filter:y=>{var C,E;return!((E=e[(C=y.datasetIndex)!=null?C:-1])!=null&&E.csvIsFit)}}},tooltip:{callbacks:{label:y=>{let C=y.raw,E=s.xIsDate?ec(C.x):Es(C.x),S=n&&y.dataset.label?`[${y.dataset.label}] `:"",x=C.label?`${C.label}: `:"",v=C.size!==void 0&&s.sizeLabel?` \xB7 ${s.sizeLabel}: ${Es(C.size)}`:"";return`${S}${x}(${E}, ${Es(C.y)})${v}`}}}}}},fitText:f,formulaError:g}}var ai="(row number)";function Io(s,t,e,n,i,o,r,a){let l=new Map,c=0;return s.forEach((h,u)=>{var y,C,E,S,x;let f=ln((y=h[e])!=null?y:""),g;if(t===ai)g=u+1;else if(o){let v=r((C=h[t])!=null?C:"");g=v?v.getTime():null}else g=ln((E=h[t])!=null?E:"");if(g===null||f===null){c++;return}let p=n?((S=h[n])!=null?S:"").trim()||"\u2014":"",b=l.get(p);b||(b=[],l.set(p,b));let m={x:g,y:f,label:a(h)};if(i){let v=ln((x=h[i])!=null?x:"");v!==null&&(m.size=v)}b.push(m)}),{series:[...l.entries()].sort((h,u)=>h[0]==="\u2014"?1:u[0]==="\u2014"?-1:h[0].localeCompare(u[0])).map(([h,u])=>({label:h,points:u})),skipped:c}}function Cg(s,t,e){return s.filter(n=>{if(e.has(n))return!1;let i=new Set(t.map(o=>{var r;return((r=o[n])!=null?r:"").trim()}).filter(Boolean));return i.size>=2&&i.size<=10})}function _g(s,t,e){return s.filter(n=>{if(e.has(n))return!1;let i=new Set(t.map(o=>{var r;return((r=o[n])!=null?r:"").trim()}).filter(Boolean));return i.size>=1&&i.size<=30})}function Vo(s,t,e,n,i){let o=new Map,r=new Set,a=0,l=xt(t);s.forEach(u=>{var m,y,C;let f=0;if(i!=="count"){let E=ln((m=u[e!=null?e:""])!=null?m:"");if(E===null){a++;return}f=E}let g=((y=u[t])!=null?y:"").trim(),p=l?g?g.split(",").map(E=>E.trim()).filter(Boolean):["\u2014"]:[g||"\u2014"],b=n?((C=u[n])!=null?C:"").trim()||"\u2014":"";r.add(b),p.forEach(E=>{var v;let S=o.get(E);S||(S=new Map,o.set(E,S));let x=(v=S.get(b))!=null?v:{sum:0,n:0};x.sum+=f,x.n+=1,S.set(b,x)})});let c=(u,f)=>u==="\u2014"?1:f==="\u2014"?-1:u.localeCompare(f,void 0,{numeric:!0}),d=[...o.keys()].sort(c),h=[...r].sort(c).map(u=>({label:u,values:d.map(f=>{var p;let g=(p=o.get(f))==null?void 0:p.get(u);return!g||g.n===0?0:i==="count"?g.n:i==="sum"?g.sum:g.sum/g.n})}));return{categories:d,series:h,skipped:a}}function Bo(s,t,e,n){let i=s.series.length>1;return{type:"bar",data:{labels:s.categories,datasets:s.series.map((o,r)=>({label:o.label||e,data:o.values,backgroundColor:i?n.series[r%n.series.length]:n.accent,borderRadius:3}))},options:{responsive:!0,maintainAspectRatio:!1,scales:{x:{title:{display:!!t,text:t,color:n.muted},ticks:{color:n.muted,autoSkip:!1,maxRotation:60},grid:{display:!1}},y:{beginAtZero:!0,title:{display:!!e,text:e,color:n.muted},ticks:{color:n.muted},grid:{color:n.grid}}},plugins:{legend:{display:i,labels:{color:n.muted,boxWidth:12}}}}}}function di(s){return s.rows.length>=2&&li(s.headers,s.rows).length>=1}async function sc(s,t){var K,N,P;let e=s.getFilteredRows(),n=li(s.headers,s.rows);if(!n.length){t.createEl("p",{text:"No numeric column to chart.",cls:"csv-empty-state"});return}s.searchQuery.trim()&&t.createDiv({cls:"csv-search-results",text:`Chart over ${e.length} of ${s.rows.length} entries`});let i=s.fileCfg,o=s.getDateCol(),r=(K=s.titleKey())!=null?K:s.headers[0],a=new Set([r,...n,...o?[o]:[]]);s.headers.forEach(L=>{s.isNotesCol(L)&&a.add(L)});let l=_g(s.headers,s.rows,a),c=[...o?[o]:[],...n.filter(L=>L!==o),ai,...l],d=i.chartXCol&&c.includes(i.chartXCol)?i.chartXCol:c[0],h=l.includes(d),u=i.chartAgg==="sum"||i.chartAgg==="avg"?i.chartAgg:"count",f=n,g=i.chartYCol&&f.includes(i.chartYCol)?i.chartYCol:(N=f.find(L=>L!==d))!=null?N:f[0],p=i.chartFit==="linear"?"linear":"none",b=(P=i.chartFormula)!=null?P:"",m=t.createDiv({cls:"csv-chart-view"}),y=m.createDiv({cls:"csv-chart-controls"}),C=L=>{s.saveFileCfg({...s.fileCfg,...L}),s.renderViewPreservingScroll()},E=(L,z,B,H)=>{let U=y.createDiv({cls:"csv-chart-control"});U.createSpan({cls:"csv-chart-control-label",text:L});let q=U.createEl("select",{cls:"csv-chart-select",attr:{"aria-label":L}});return z.forEach(X=>{let Z=q.createEl("option",{text:X,value:X});X===B&&(Z.selected=!0)}),q.addEventListener("change",()=>H(q.value)),q};E("X",c,d,L=>C({chartXCol:L})),(!h||u!=="count")&&E(h?`Y (${u})`:"Y",f,g,L=>C({chartYCol:L})),h&&E("Agg",["count","sum","avg"],u,L=>C({chartAgg:L}));let S=new Set([d,g,r]);s.headers.forEach(L=>{s.isNotesCol(L)&&S.add(L)});let x=Cg(s.headers,s.rows,S),v="\u2014",_=i.chartHueCol&&x.includes(i.chartHueCol)?i.chartHueCol:null;x.length&&E("Color",[v,...x],_!=null?_:v,L=>C({chartHueCol:L===v?void 0:L}));let w=n.filter(L=>L!==g&&L!==d),D=!h&&i.chartSizeCol&&w.includes(i.chartSizeCol)?i.chartSizeCol:null;if(!h&&w.length&&E("Size",[v,...w],D!=null?D:v,L=>C({chartSizeCol:L===v?void 0:L})),h){let L=Vo(e,d,u==="count"?null:g,_,u),z=m.createDiv({cls:"csv-chart-wrap"}),B=z.createEl("canvas",{cls:"csv-chart-canvas"});if(!L.categories.length){z.remove(),m.createEl("p",{text:`No rows with a "${d}" value to chart.`,cls:"csv-empty-state"});return}L.skipped>0&&m.createDiv({cls:"csv-chart-footer"}).createSpan({cls:"csv-chart-skipped",text:`${L.skipped} row${L.skipped===1?"":"s"} skipped (no numeric value)`});let H=u==="count"?"count":`${u}(${g})`,U=Bo(L,d,H,ks(t));s.chartInstance&&(s.chartInstance.destroy(),s.chartInstance=null);let{Chart:q}=await Ue();if(!B.isConnected)return;s.chartInstance=new q(B,U);return}y.createEl("button",{cls:`csv-cfg-btn csv-chart-fit-btn ${p==="linear"?"active":""}`,text:"Best fit",title:"Toggle a least-squares fit line"}).addEventListener("click",()=>C({chartFit:p==="linear"?"none":"linear"}));let T=y.createDiv({cls:"csv-chart-control csv-chart-formula-wrap"});T.createSpan({cls:"csv-chart-control-label",text:"y ="});let A=T.createEl("input",{cls:"csv-chart-formula-input",type:"text",value:b,placeholder:"overlay, e.g. 2x + 1",attr:{spellcheck:"false",autocomplete:"off",enterkeyhint:"done"}}),I=()=>{A.value.trim()!==b.trim()&&C({chartFormula:A.value})};A.addEventListener("change",I),A.addEventListener("keydown",L=>{L.key==="Enter"&&(L.preventDefault(),A.blur())});let V=d!==ai&&(d===o||s.isDateCol(d)),{series:O,skipped:M}=Io(e,d,g,_,D,V,L=>s.parseDate(L),L=>s.getTitle(L)),j=m.createDiv({cls:"csv-chart-wrap"}),F=j.createEl("canvas",{cls:"csv-chart-canvas"}),Y=m.createDiv({cls:"csv-chart-footer"});if(!O.some(L=>L.points.length)){j.remove(),Y.remove(),m.createEl("p",{text:`No rows with both "${d}" and "${g}" values to plot.`,cls:"csv-empty-state"});return}let $={series:O,xIsDate:V,xLabel:d===ai?"row":d,yLabel:g,connect:V,fit:p,formula:b,sizeLabel:D!=null?D:""},R=ci($,ks(t));R.fitText&&Y.createSpan({cls:"csv-chart-fit-text",text:R.fitText}),R.formulaError&&Y.createSpan({cls:"csv-chart-formula-error",text:`formula: ${R.formulaError}`}),M>0&&Y.createSpan({cls:"csv-chart-skipped",text:`${M} row${M===1?"":"s"} skipped (no numeric value)`}),s.chartInstance&&(s.chartInstance.destroy(),s.chartInstance=null);let{Chart:W}=await Ue();F.isConnected&&(s.chartInstance=new W(F,R.config))}function hi(s){return s.resolveCol(["Type","type","Kind","kind","Item","item"])}function $o(s){var t;return(t=s.resolveCol(["Project","project","Projects","projects","Area","area"]))!=null?t:$t(s)}function oc(s){return s.resolveCol(["Due","due","Deadline","deadline","Due Date","Due date","due date"])}function ui(s){return s.resolveCol(["Priority","priority","Prio","prio","Importance","importance"])}var Sg=["task","todo","to-do","action",""],Eg=["task","todo","to-do","action","note","idea","reference","ref"],rc=["done","complete","completed","finished","closed","resolved","yes","x","\u2713","true","1"],kg={high:0,med:1,medium:1,normal:1,low:2};function ws(s){if(oc(s)||ui(s))return!0;let t=hi(s);return t?s.rows.some(e=>{var n;return Eg.includes(((n=e[t])!=null?n:"").trim().toLowerCase())}):!1}function No(s,t,e){var n;return e?rc.includes(((n=t[e])!=null?n:"").trim().toLowerCase()):!1}function nc(s){let t=kg[(s!=null?s:"").trim().toLowerCase()];return t===void 0?3:t}function ic(s){return(s!=null?s:"").trim()?0:1}function wg(){return ts()}function Mg(s,t){let e=new Map;s.rows.forEach(o=>{var a,l;let r=((a=o[t])!=null?a:"").trim();r&&rc.includes(r.toLowerCase())&&e.set(r,((l=e.get(r))!=null?l:0)+1)});let n="done",i=0;return e.forEach((o,r)=>{o>i&&(n=r,i=o)}),n}function ac(s,t){var D,k;let e=$o(s),n=hi(s),i=s.getStatusCol(),o=oc(s),r=ui(s),a=(D=s.titleKey())!=null?D:s.headers[0],l=t.createDiv({cls:"csv-library-filters"}),c=new Set;e&&s.rows.forEach(T=>{var A;((A=T[e])!=null?A:"").split(",").map(I=>I.trim()).filter(Boolean).forEach(I=>c.add(I))});let d=l.createEl("select",{cls:"csv-library-filter-select"});d.createEl("option",{text:e?"All projects":"All",value:"all"}),Array.from(c).sort().forEach(T=>d.createEl("option",{text:T,value:T})),d.value=s.taskProjectFilter;let h=new Set;n&&s.rows.forEach(T=>{var I;let A=((I=T[n])!=null?I:"").trim();A&&h.add(A)});let u=null;h.size>0&&(u=l.createEl("select",{cls:"csv-library-filter-select"}),u.createEl("option",{text:"All types",value:"all"}),Array.from(h).sort().forEach(T=>u.createEl("option",{text:T,value:T})),u.value=s.taskTypeFilter);let f=()=>{s.taskProjectFilter=d.value,u&&(s.taskTypeFilter=u.value),s.renderView(!0)};d.addEventListener("change",f),u==null||u.addEventListener("change",f);let g=s.searchQuery.toLowerCase().trim(),p=s.rows.filter(T=>{var A,I;return!(s.taskProjectFilter!=="all"&&e&&!((A=T[e])!=null?A:"").split(",").map(O=>O.trim().toLowerCase()).includes(s.taskProjectFilter.toLowerCase())||s.taskTypeFilter!=="all"&&n&&((I=T[n])!=null?I:"").trim().toLowerCase()!==s.taskTypeFilter.toLowerCase()||g&&!s.headers.some(V=>{var O;return((O=T[V])!=null?O:"").toLowerCase().includes(g)}))});(s.taskProjectFilter!=="all"||s.taskTypeFilter!=="all"||g)&&t.createDiv({cls:"csv-library-result-count",text:`Showing ${p.length} of ${s.rows.length} entries`});let b={},m=T=>{var I;return e&&((I=T[e])!=null?I:"").split(",").map(V=>V.trim()).filter(Boolean)[0]||"\u2014"};p.forEach(T=>{var O,M,j;let A=n?((O=T[n])!=null?O:"").trim():"",I=Sg.includes(A.toLowerCase())?"Tasks":A,V=m(T);b[I]||(b[I]={}),((j=(M=b[I])[V])!=null?j:M[V]=[]).push(T)});let y=t.createDiv({cls:"csv-tasks"}),C=wg(),E=i?Mg(s,i):"done",x=((k=s.fileCfg.cardFields)!=null?k:s.headers).filter(T=>T!==e&&T!==n&&T!==i),v=[];i&&v.push({name:"",cls:"csv-tasks-check-cell"}),x.forEach(T=>{let A="";T===a?A="csv-tasks-name-cell":T===o?A="csv-tasks-due":T===r?A="csv-tasks-priority":s.isNotesCol(T)?A="csv-tasks-generic-cell csv-tasks-notes-cell":A="csv-tasks-generic-cell",v.push({name:T,cls:A})});let _=(T,A)=>{A.sort((I,V)=>{var j,F,Y,$,R,W;let O=No(s,I,i),M=No(s,V,i);if(O!==M)return O?1:-1;if(r){let K=nc((j=I[r])!=null?j:"")-nc((F=V[r])!=null?F:"");if(K)return K}if(o){let K=ic((Y=I[o])!=null?Y:"")-ic(($=V[o])!=null?$:"");if(K)return K;let N=((R=I[o])!=null?R:"").localeCompare((W=V[o])!=null?W:"");if(N)return N}return s.getTitle(I).localeCompare(s.getTitle(V))}),A.forEach(I=>{let V=No(s,I,i),O=T.createEl("tr");if(i){let j=O.createEl("td",{cls:"csv-tasks-check-cell"}).createEl("span",{cls:`csv-tasks-check ${V?"is-done":""}`,text:V?"\u2713":""});j.setAttr("title",V?"Mark not done":"Mark done"),j.addEventListener("click",F=>{F.stopPropagation(),I[i]=V?"":E,s.scheduleSave(),s.renderView(!0)})}x.forEach(M=>{var j,F,Y;if(M===a)Tg(s,O,I,a,V);else if(M===o){let $=O.createEl("td",{cls:"csv-tasks-due csv-tasks-editable"}),R=o?((j=I[o])!=null?j:"").slice(0,10):"";$.setText(R||"\u2014"),R&&!V&&R<C&&$.addClass("csv-tasks-overdue"),Fs(s,$,I,M)}else if(M===r){let $=O.createEl("td",{cls:"csv-tasks-priority csv-tasks-editable",text:r&&I[r]||"\u2014"});$.addEventListener("click",R=>{var K;R.stopPropagation();let W=Array.from(new Set([...s.getColumnValues(r),"high","medium","low"]));Ft($,(K=I[r])!=null?K:"",W,N=>{I[r]=N,s.scheduleSave(),s.renderView(!0)},s.contentEl)})}else if(s.isNotesCol(M)){let $=((F=I[M])!=null?F:"").replace(/#{1,6}\s/g,"").replace(/[*_>`]/g,"").replace(/\n+/g," ").trim(),R=$?$.length>50?$.slice(0,48)+"\u2026":$:"\u2014",W=O.createEl("td",{text:R,cls:"csv-tasks-generic-cell csv-tasks-notes-cell csv-tasks-editable"});Fs(s,W,I,M)}else{let $=(Y=I[M])!=null?Y:"",R=$.length>40?$.slice(0,38)+"\u2026":$,W=O.createEl("td",{text:R||"\u2014",cls:"csv-tasks-generic-cell csv-tasks-editable"});Fs(s,W,I,M)}}),O.addEventListener("contextmenu",M=>s.openRowContextMenu(I,M))})},w=Object.keys(b).sort((T,A)=>T==="Tasks"?-1:A==="Tasks"?1:T.localeCompare(A));if(w.forEach(T=>{Dg(s,y,T==="Tasks"?T:kt(T),b[T],_,v)}),w.length===0){let T=y.createDiv({cls:"csv-empty-state"});T.createEl("p",{text:g||s.taskProjectFilter!=="all"||s.taskTypeFilter!=="all"?"No entries match your filters.":"No tasks yet."}),(g||s.taskProjectFilter!=="all"||s.taskTypeFilter!=="all")&&T.createEl("button",{cls:"csv-clear-filters-btn",text:"Clear filters"}).addEventListener("click",()=>{s.taskProjectFilter="all",s.taskTypeFilter="all",s.searchQuery="",s.renderView()})}}function Dg(s,t,e,n,i,o){if(Object.keys(n).length===0)return;t.createDiv({cls:"csv-tasks-section-header",text:e});let r=t.createDiv({cls:"csv-tasks-section"});Object.keys(n).sort().forEach(a=>{let l=n[a],c=r.createEl("details",{cls:"csv-tasks-group"});c.open=!0;let d=c.createEl("summary",{cls:"csv-tasks-group-header"});d.innerHTML=`<span class="csv-tasks-arrow">\u25B6</span> ${a} <span class="csv-tasks-count">${l.length}</span>`;let u=c.createDiv({cls:"csv-tasks-table-wrapper"}).createEl("table",{cls:"csv-tasks-table"}),f=120;o.forEach(m=>{m.cls.includes("check-cell")?f+=30:m.cls.includes("priority")?f+=90:m.cls.includes("due")?f+=150:m.cls.includes("notes-cell")?f+=140:m.cls.includes("generic-cell")&&(f+=150)}),u.style.minWidth=`${f}px`;let p=u.createEl("thead").createEl("tr");o.forEach(m=>p.createEl("th",{text:m.name,cls:m.cls}));let b=u.createEl("tbody");i(b,l)})}function Tg(s,t,e,n,i){var h;let o=t.createEl("td",{cls:"csv-tasks-name-cell"}),r=(h=s.isHighlighted)!=null&&h.call(s,e)?"csv-title-highlight":"",a=o.createSpan({cls:`csv-tasks-link ${i?"csv-tasks-done":""} ${r}`,text:e[n]||"Untitled"}),l=s.getNotesCol();a.addEventListener("click",()=>{l?s.openNoteExpander(e,l):s.openOrCreateNotes(e)});let c=s.notesFileExists(e),d=o.createEl("button",{cls:`csv-tasks-page-icon ${c?"exists":""}`,text:c?"\u{1F4C4}":"+"});d.setAttr("title",c?"Open page":"Create page"),d.addEventListener("click",u=>{u.stopPropagation(),s.openOrCreateNotes(e)})}function fi(s){let t=[];return s.isTravelFile()&&t.push({id:"travel",label:"Travel"}),s.hasDateColumn()&&t.push({id:"dashboard",label:"Dashboard"}),ws(s)&&t.push({id:"tasks",label:"Tasks"}),$t(s)&&(t.push({id:"library",label:"Cards"}),t.push({id:"kanban-genre",label:"Kanban"})),t.push({id:"table",label:"Table"}),s.rows.length>0&&t.push({id:"focus",label:"Focus"}),xn(s)&&t.push({id:"stats",label:"Stats"}),di(s)&&t.push({id:"chart",label:"Chart"}),t}function lc(s,t){var f,g,p;let e=t.createDiv({cls:"csv-toolbar"});e.createDiv({cls:"csv-toolbar-title",text:(g=(f=s.file)==null?void 0:f.basename)!=null?g:""});let n=e.createDiv({cls:"csv-toolbar-controls"});n.createDiv({cls:"csv-row-count",text:`${s.rows.length} entries`});let i=n.createDiv({cls:"csv-mode-group"}),o=fi(s),r=i.createEl("select",{cls:"csv-mode-select",attr:{"aria-label":"View mode"}});if(o.forEach(({id:b,label:m})=>{let y=r.createEl("option",{text:m,value:b});s.mode===b&&(y.selected=!0)}),r.addEventListener("change",()=>{s.mode=r.value,s.renderView()}),s.mode!=="dashboard"){let b=n.createEl("button",{cls:"csv-cfg-btn csv-search-toggle",text:"\u{1F50D}",title:"Search"}),m=n.createDiv({cls:"csv-search-wrap"}),y=m.createDiv({cls:"csv-search-input-wrap"}),C=y.createEl("input",{cls:"csv-search-input",type:"text",placeholder:"Search...",value:s.searchQuery,attr:{inputmode:"search",enterkeyhint:"search",autocomplete:"off"}}),E=y.createEl("button",{cls:"csv-search-clear",text:"\xD7",title:"Clear search"});E.toggleClass("is-hidden",!s.searchQuery),m.createEl("button",{cls:"csv-search-done",text:"Done",title:"Dismiss keyboard"}).addEventListener("click",v=>{if(v.preventDefault(),!C.value){e.removeClass("csv-toolbar--search-expanded"),b.removeClass("has-query"),s.searchQuery="",s.renderView(!0);return}C.blur()});let x=null;C.addEventListener("input",v=>{s.searchQuery=v.target.value,E.toggleClass("is-hidden",!s.searchQuery),b.toggleClass("has-query",!!s.searchQuery),x!==null&&window.clearTimeout(x),x=window.setTimeout(()=>{x=null,s.renderView(!0)},120)}),C.addEventListener("keydown",v=>{v.key==="Enter"&&(v.preventDefault(),C.blur())}),E.addEventListener("click",()=>{s.searchQuery="",C.value="",E.addClass("is-hidden"),b.removeClass("has-query"),C.focus({preventScroll:!0}),s.renderView(!0)}),s.searchQuery&&b.addClass("has-query"),b.addEventListener("click",()=>{e.addClass("csv-toolbar--search-expanded"),C.focus({preventScroll:!0})})}if(s.mode==="table"&&s.hasDateColumn()){let b=(p=s.fileCfg.sortNewestFirst)!=null?p:!0;n.createEl("button",{cls:`csv-cfg-btn ${b?"active":""}`,text:b?"\u2193 Newest":"\u2191 Oldest",title:"Toggle sort order"}).addEventListener("click",()=>{var C;let y=s.fileCfg;y.sortNewestFirst=!((C=y.sortNewestFirst)==null||C),s.saveFileCfg(y),s.tableSortCol=null,s.renderViewPreservingScroll()})}let a=()=>{var m,y;let b={title:s.resolveCol(Ge),category:s.resolveCol(qe),status:s.resolveCol(Xe),notes:s.resolveCol(Qe),image:s.resolveCol(Ke),anki:Di(s)};new gn(s.app,s.headers,(y=(m=s.file)==null?void 0:m.path)!=null?y:"",s.fileCfg,s.autoDetectBooleanColumns(),s.autoDetectCategoricalColumns(),b,fi(s),C=>{s.saveFileCfg(C),C.defaultMode&&(s.mode=C.defaultMode),s.renderView()},()=>s.headers,()=>s.fileCfg,C=>s.addColumn(C),C=>s.removeColumn(C),C=>s.cleanupBooleanColumn(C)).open()},l=()=>xr(s),c=()=>s.backupToArchive(),d=()=>_r(s);n.createEl("button",{cls:"csv-cfg-btn csv-cfg-btn-secondary",text:"\u2699 Config",title:"Configure this file's columns and views"}).addEventListener("click",a),n.createEl("button",{cls:"csv-cfg-btn csv-cfg-btn-secondary",text:"\u{1F4F1} Mobile",title:"Generate mobile dashboard with add form"}).addEventListener("click",l),n.createEl("button",{cls:"csv-cfg-btn csv-cfg-btn-secondary",text:"\u{1F4BE} Backup",title:"Copy this file to Archive/ with today's date"}).addEventListener("click",c),n.createEl("button",{cls:"csv-cfg-btn csv-cfg-btn-secondary",text:"\u{1F3B4} Anki",title:"Sync rows to Anki (needs Anki desktop + AnkiConnect)"}).addEventListener("click",d),n.createEl("button",{cls:"csv-add-btn",text:"+ Add"}).addEventListener("click",()=>s.openAddModal()),n.createEl("button",{cls:"csv-cfg-btn csv-cfg-btn-overflow",text:"\u22EF",title:"More actions"}).addEventListener("click",b=>{let m=new gi.Menu;m.addItem(y=>y.setTitle("Config").setIcon("settings").onClick(a)),m.addItem(y=>y.setTitle("Mobile dashboard").setIcon("smartphone").onClick(l)),m.addItem(y=>y.setTitle("Backup").setIcon("save").onClick(c)),m.addItem(y=>y.setTitle("Sync to Anki").setIcon("layers").onClick(d)),m.addSeparator(),m.addItem(y=>y.setTitle("Built 2026-07-12 09:41").setIcon("info").setDisabled(!0)),m.showAtMouseEvent(b)}),n.createEl("button",{cls:"csv-cfg-btn csv-cfg-btn-secondary csv-info-btn",text:"\u24D8",title:"Built 2026-07-12 09:41 \u2014 click to confirm"}).addEventListener("click",()=>new gi.Notice("datadeck \u2014 built 2026-07-12 09:41",4e3))}function Lg(s){return s&&typeof s=="object"&&"basename"in s?s:null}var Ag=["Author","author","By","by","Source","source","Speaker","speaker","Artist","artist","Director","director"];async function cc(s,t,e,n){var y,C,E;let i=t.split(`
`).map(S=>S.trim()).filter(Boolean),o=S=>{var x,v;return(v=(x=i.find(_=>_.startsWith(S+":")))==null?void 0:x.slice(S.length+1).trim())!=null?v:""},r=o("file");if(!r){e.createEl("p",{text:"Error: No file specified. Use: file: yourfile.csv",cls:"csv-add-error"});return}let a=s.vault.getAbstractFileByPath(n.sourcePath),l=(C=(y=a==null?void 0:a.parent)==null?void 0:y.path)!=null?C:"",c=ue(r,l),d=Lg(s.vault.getAbstractFileByPath(c));if(!d){e.createEl("p",{text:`Error: File not found: ${c}`,cls:"csv-add-error"});return}let h=[],u=[];try{let S=Bt(await s.vault.read(d));h=S.headers,u=S.rows}catch(S){e.createEl("p",{text:`Error reading file: ${S}`,cls:"csv-add-error"});return}if(!u.length){e.createEl("p",{text:"No entries in file.",cls:"csv-add-error"});return}let f=o("field"),g=(E=h.find(S=>S.toLowerCase()===f.toLowerCase()))!=null?E:h[0],p=Ag.map(S=>h.find(x=>x===S)).find(Boolean),b=e.createDiv({cls:"csv-random-card"}),m=()=>{var k;b.empty();let S=u.filter(T=>{var A;return((A=T[g])!=null?A:"").trim()}),x=S.length?S:u,v=x[Math.floor(Math.random()*x.length)];b.createDiv({cls:"csv-random-text",text:v[g]||"\u2014"});let _=p?((k=v[p])!=null?k:"").trim():"";_&&b.createDiv({cls:"csv-random-sub",text:`\u2014 ${_}`});let w=b.createDiv({cls:"csv-random-foot"});w.createSpan({cls:"csv-random-src",text:d.basename}),w.createEl("button",{cls:"csv-random-btn",text:"\u21BB",title:"Another one"}).addEventListener("click",m)};m()}async function dc(s,t){var R,W,K;let e=s.getDateCol();if(!e){t.createEl("p",{text:"No date column detected.",cls:"csv-empty-state"});return}let n=s.getBooleanColumns(),i=s.getNotesCol(),o=s.formatDate(new Date),r=[...s.rows].sort((N,P)=>{var L,z;return((L=N[e])!=null?L:"").localeCompare((z=P[e])!=null?z:"")});s.selectedDate||(s.selectedDate=o);let a=r.find(N=>N[e]===s.selectedDate),l=s.selectedDate===o;t.addClass("csv-dashboard");let c=[...new Set([...r.map(N=>N[e]),o])].filter(Boolean).sort(),d=t.createDiv({cls:"csv-dash-nav"});d.createEl("button",{cls:"csv-dash-nav-btn csv-dash-back-btn",text:"\u25C0"}).addEventListener("click",()=>{let N=c.indexOf(s.selectedDate);if(N>0)s.selectedDate=c[N-1],s.renderView();else if(N===-1&&c.length>0){let P=c.filter(L=>L<s.selectedDate);P.length>0&&(s.selectedDate=P[P.length-1],s.renderView())}});let u=d.createDiv({cls:"csv-dash-date"});l&&u.createSpan({cls:"csv-dash-today-dot"});let f=u.createEl("select",{cls:"csv-dash-date-select"});if(c.forEach(N=>{let P=f.createEl("option",{text:N,value:N});N===s.selectedDate&&(P.selected=!0)}),f.addEventListener("change",()=>{s.selectedDate=f.value,s.renderView()}),d.createEl("button",{cls:"csv-dash-nav-btn",text:"\u25B6"}).addEventListener("click",()=>{let N=c.indexOf(s.selectedDate);if(N>=0&&N<c.length-1)s.selectedDate=c[N+1],s.renderView();else if(N===-1){let P=c.filter(L=>L>s.selectedDate);P.length>0&&(s.selectedDate=P[0],s.renderView())}}),l||d.createEl("button",{cls:"csv-dash-today-btn",text:"Today"}).addEventListener("click",()=>{s.selectedDate=o,s.renderView()}),!a){let N=t.createDiv({cls:"csv-dash-add-section"});N.createEl("p",{text:`No entry for ${s.selectedDate}`}),N.createEl("button",{cls:"csv-dash-add-btn",text:`+ Add entry for ${s.selectedDate}`}).addEventListener("click",()=>{let L={};s.headers.forEach(z=>L[z]=""),L[e]=s.selectedDate,s.rows.push(L),s.scheduleSave(),s.renderView()})}if(a){let N=t.createDiv({cls:"csv-dash-habits"});N.createEl("h3",{text:s.selectedDate===o?"Today":s.selectedDate,cls:"csv-dash-section-title"});let P=N.createDiv({cls:"csv-dash-habits-grid"});n.forEach(z=>{let B=s.isTruthy(a[z]),H=P.createDiv({cls:`csv-dash-habit ${B?"checked":""}`}),U=H.createEl("button",{cls:"csv-dash-habit-check",text:B?"\u25CF":"\u25CB"});H.createSpan({cls:"csv-dash-habit-label",text:z}),U.addEventListener("click",()=>{a[z]=B?"0":"1",s.scheduleSave(),s.renderViewPreservingScroll()})});let L=n.filter(z=>s.isTruthy(a[z])).length;if(N.createDiv({cls:"csv-dash-habits-count",text:`${L} of ${n.length} complete`}),i&&((R=a[i])!=null&&R.trim())){let z=N.createDiv({cls:"csv-dash-notes-preview"});z.createEl("strong",{text:"Notes: "}),z.createSpan({text:a[i].slice(0,200)+(a[i].length>200?"\u2026":"")})}}let p=t.createDiv({cls:"csv-dash-chart-section"});p.createEl("h3",{text:"Progress",cls:"csv-dash-section-title"});let m=p.createDiv({cls:"csv-dash-chart-wrap"}).createEl("canvas",{cls:"csv-dash-chart"}),y=r.map(N=>{var L;return((L=N[e])!=null?L:"").slice(5)}),C=r.map(N=>n.filter(P=>s.isTruthy(N[P])).length);s.chartInstance&&(s.chartInstance.destroy(),s.chartInstance=null);let{Chart:E}=await Ue();if(!m.isConnected)return;s.chartInstance=new E(m,{type:"line",data:{labels:y,datasets:[{label:"Habits done",data:C,borderColor:"#378ADD",backgroundColor:"rgba(55,138,221,0.08)",borderWidth:1.5,pointRadius:3,tension:.3,fill:!0}]},options:{responsive:!0,maintainAspectRatio:!1,scales:{y:{min:0,max:n.length||8,ticks:{stepSize:1}}},plugins:{tooltip:{enabled:!0}}}});let S=t.createDiv({cls:"csv-dash-stats-section"});S.createEl("h3",{text:"Stats",cls:"csv-dash-section-title"});let x=r.length,v=r.reduce((N,P)=>N+n.filter(L=>s.isTruthy(P[L])).length,0),_=x>0?(v/x).toFixed(1):"0",w=r.filter(N=>n.every(P=>s.isTruthy(N[P]))).length,D=0,k=0,T=null;for(let N of r){let P=n.filter(B=>s.isTruthy(N[B])).length,L=s.parseDate((W=N[e])!=null?W:""),z=!0;T&&L&&Math.round((L.getTime()-T.getTime())/864e5)!==1&&(z=!1),P>=1&&(z||T===null)?(k++,k>D&&(D=k)):P>=1?(k=1,k>D&&(D=k)):k=0,T=L}let A=0,I=new Date;I.setHours(0,0,0,0);let V=I;for(let N=r.length-1;N>=0;N--){let P=s.parseDate((K=r[N][e])!=null?K:"");if(!P)break;let L=Math.round((V.getTime()-P.getTime())/(1e3*60*60*24));if(A===0&&L>1||A>0&&L!==1)break;if(n.filter(B=>s.isTruthy(r[N][B])).length>=1)A++,V=P;else break}let O=S.createDiv({cls:"csv-dash-stats-bar"});O.innerHTML=`<strong>${x}</strong> days logged \xB7 <strong>${_}</strong> avg/day \xB7 <strong>${w}</strong> perfect days \xB7 current streak <strong>${A}d</strong> \xB7 best streak <strong>${D}d</strong>`;let j=t.createDiv({cls:"csv-dash-cards-section"}).createDiv({cls:"csv-dash-cards-grid"}),F=new Date().getFullYear(),Y={language:"\u25CB",read:"\u2261",gym:"\u229E",vitamins:"\u2299",cardio:"\u2191",meditate:"\u25CE",challenge:"\u273F",journal:"\u270E",exercise:"\u229E",water:"\u{1F4A7}",sleep:"\u{1F319}",study:"\u{1F4DA}"};n.map(N=>{let P=r.filter(U=>s.isTruthy(U[N])),L=P.length>0?P[P.length-1][e]:null,z=new Set;P.forEach(U=>{var X;let q=s.parseDate((X=U[e])!=null?X:"");q&&z.add(q.getFullYear())});let B=r.filter(U=>{var X;let q=s.parseDate((X=U[e])!=null?X:"");return q&&q.getFullYear()===F}),H=B.filter(U=>s.isTruthy(U[N])).length;return{habit:N,doneCount:P.length,doneThisYear:H,totalThisYear:B.length,lastDone:L,years:Array.from(z).sort()}}).sort((N,P)=>!N.lastDone&&!P.lastDone?0:N.lastDone?P.lastDone?P.lastDone.localeCompare(N.lastDone):-1:1).forEach(({habit:N,doneCount:P,doneThisYear:L,totalThisYear:z,lastDone:B,years:H})=>{var st;let U=j.createDiv({cls:"csv-dash-habit-card"}),q=(st=Y[N.toLowerCase()])!=null?st:"\u25CB",X=U.createDiv({cls:"csv-dash-habit-card-header"});if(X.createSpan({cls:"csv-dash-habit-icon",text:q}),X.createSpan({cls:"csv-dash-habit-card-name",text:kt(N)}),H.length>0&&U.createDiv({cls:"csv-dash-habit-years"}).setText(H.join(" \xB7 ")),U.createDiv({cls:"csv-dash-habit-card-thisyear",text:`${L} of ${z} complete this year`}),U.createDiv({cls:"csv-dash-habit-card-alltime",text:`${P} of ${x} all time`}),B){let lt=s.parseDate(B),Wt=lt?lt.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}):B;U.createDiv({cls:"csv-dash-habit-card-last",text:`Last logged: ${Wt}`})}else U.createDiv({cls:"csv-dash-habit-card-last",text:"Never logged"});let Z=x>0?P/x*100:0,Q=U.createDiv({cls:"csv-dash-habit-progress"}).createDiv({cls:"csv-dash-habit-progress-bar"});Q.style.width=`${Z}%`,U.addEventListener("click",()=>{s.selectedHabit=s.selectedHabit===N?null:N,s.renderViewPreservingScroll()}),s.selectedHabit===N&&U.addClass("selected")}),s.selectedHabit&&n.includes(s.selectedHabit)&&Rg(s,t,r,e,s.selectedHabit)}function Rg(s,t,e,n,i){var D,k,T;let o=t.createDiv({cls:"csv-dash-timeline-section"}),r=o.createDiv({cls:"csv-dash-timeline-header"});r.createEl("h3",{text:`${kt(i)} Timeline`,cls:"csv-dash-section-title"});let a=r.createEl("select",{cls:"csv-dash-year-select"}),l=new Set;e.forEach(A=>{var V;let I=s.parseDate((V=A[n])!=null?V:"");I&&l.add(I.getFullYear())}),l.add(new Date().getFullYear()),Array.from(l).sort().reverse().forEach(A=>{let I=a.createEl("option",{text:String(A),value:String(A)});A===s.timelineYear&&(I.selected=!0)}),a.addEventListener("change",()=>{s.timelineYear=parseInt(a.value),s.renderViewPreservingScroll()}),r.createEl("button",{cls:"csv-dash-timeline-close",text:"\u2715"}).addEventListener("click",()=>{s.selectedHabit=null,s.renderViewPreservingScroll()});let d=new Map;e.forEach(A=>{var I;d.set((I=A[n])!=null?I:"",s.isTruthy(A[i]))});let h=o.createDiv({cls:"csv-dash-timeline-grid-wrap"}),u=h.createDiv({cls:"csv-dash-timeline-months"});["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"].forEach(A=>u.createSpan({cls:"csv-dash-timeline-month-label",text:A}));let g=h.createDiv({cls:"csv-dash-timeline-calendar"}),p=g.createDiv({cls:"csv-dash-timeline-day-labels"});for(let A=1;A<=31;A++)p.createDiv({cls:"csv-dash-timeline-day-label",text:A%5===0||A===1?String(A):""});for(let A=0;A<12;A++){let I=g.createDiv({cls:"csv-dash-timeline-month-col"}),V=new Date(s.timelineYear,A+1,0).getDate();for(let O=1;O<=31;O++){if(O>V){I.createDiv({cls:"csv-dash-timeline-cell empty"});continue}let M=`${s.timelineYear}-${String(A+1).padStart(2,"0")}-${String(O).padStart(2,"0")}`,j=(D=d.get(M))!=null?D:!1,F=d.has(M),Y=new Date(s.timelineYear,A,O)>new Date,$=I.createDiv({cls:`csv-dash-timeline-cell ${Y?"future":""} ${j?"done":""} ${F&&!j?"missed":""} ${!F&&!Y?"no-entry":""}`});$.title=`${M}: ${Y?"Future":j?"\u2713 Done":F?"\u2717 Missed":"No entry"}`}}let b=e.filter(A=>{var V;let I=s.parseDate((V=A[n])!=null?V:"");return I&&I.getFullYear()===s.timelineYear}),m=b.filter(A=>s.isTruthy(A[i])).length,y=b.length,C=0,E=0,S=0,x=null;for(let A of e){let I=s.isTruthy(A[i]),V=s.parseDate((k=A[n])!=null?k:""),O=!0;x&&V&&Math.round((V.getTime()-x.getTime())/864e5)!==1&&(O=!1),I&&(O||x===null)?(S++,S>E&&(E=S)):I?S=1:S=0,x=V}let v=new Date;v.setHours(0,0,0,0);let _=v;for(let A=e.length-1;A>=0;A--){let I=s.parseDate((T=e[A][n])!=null?T:"");if(!I)break;let V=Math.round((_.getTime()-I.getTime())/(1e3*60*60*24));if(C===0&&V>1||C>0&&V!==1)break;if(s.isTruthy(e[A][i]))C++,_=I;else break}let w=o.createDiv({cls:"csv-dash-timeline-stats"});w.innerHTML=`<strong>${m}</strong> of ${y} in ${s.timelineYear} \xB7 current streak <strong>${C}d</strong> \xB7 best streak <strong>${E}d</strong>`}function hc(s,t){var y,C,E;let e=s.getFilteredRows();if(s.searchQuery.trim()&&t.createDiv({cls:"csv-search-results",text:`Found ${e.length} of ${s.rows.length} entries`}),!e.length){let S=t.createDiv({cls:"csv-empty-state"});S.createEl("p",{text:s.searchQuery?"No matching entries found.":"No entries yet."}),s.searchQuery&&S.createEl("button",{cls:"csv-clear-filters-btn",text:"Clear search"}).addEventListener("click",()=>{s.searchQuery="",s.renderView()});return}s.focusIndex>=e.length&&(s.focusIndex=e.length-1),s.focusIndex<0&&(s.focusIndex=0);let n=e[s.focusIndex],i=(y=s.titleKey())!=null?y:s.headers[0],o=s.getNotesCol(),r=s.authorKey(),a=t.createDiv({cls:"csv-focus-wrap",attr:{tabindex:"0"}}),l=S=>{s.focusIndex=(S%e.length+e.length)%e.length,s.focusNavPending=!0,s.renderView(!0)},c=a.createDiv({cls:"csv-focus-card"});c.createDiv({cls:"csv-focus-position",text:`${s.focusIndex+1} / ${e.length}`});let d=c.createDiv({cls:`csv-focus-title ${(C=s.isHighlighted)!=null&&C.call(s,n)?"csv-title-highlight":""}`,text:s.getTitle(n)});o&&(d.addClass("is-clickable"),d.title="Open entry",d.addEventListener("click",()=>s.openNoteExpander(n,o)));let h=s.getSubtitle(n);if(h&&c.createDiv({cls:"csv-focus-sub",text:h}),o&&o!==i&&((E=n[o])!=null&&E.trim())){let S=c.createDiv({cls:"csv-focus-notes"});s.renderMarkdownInto(S,n[o])}let u=new Set([i,o,r].filter(Boolean)),f=s.headers.filter(S=>{var x;return!u.has(S)&&((x=n[S])!=null?x:"").trim()});if(f.length){let S=c.createDiv({cls:"csv-focus-meta"});f.forEach(x=>{let v=S.createDiv({cls:"csv-kanban-chip"});if(v.createSpan({cls:"csv-chip-label",text:x+": "}),s.isSelectCol(x)){let _=v.createSpan({cls:"csv-chip-value csv-chip-select",text:n[x]});_.addEventListener("click",w=>{w.stopPropagation(),Ft(_,n[x],s.getColumnValues(x),D=>{n[x]=D,_.setText(D||"\u2014"),s.scheduleSave()},s.contentEl,{multi:xt(x)})})}else v.createSpan({cls:"csv-chip-value",text:n[x]})})}c.addEventListener("contextmenu",S=>s.openRowContextMenu(n,S));let g=a.createDiv({cls:"csv-focus-nav"}),p=g.createEl("button",{cls:"csv-focus-nav-btn",text:"\u2039",title:"Previous (\u2190)"}),b=g.createEl("button",{cls:"csv-focus-nav-btn csv-focus-nav-rand",text:"\u{1F500}",title:"Random entry"}),m=g.createEl("button",{cls:"csv-focus-nav-btn",text:"\u203A",title:"Next (\u2192)"});p.addEventListener("click",()=>l(s.focusIndex-1)),m.addEventListener("click",()=>l(s.focusIndex+1)),b.addEventListener("click",()=>{if(e.length<2)return;let S=s.focusIndex;for(;S===s.focusIndex;)S=Math.floor(Math.random()*e.length);l(S)}),a.addEventListener("keydown",S=>{S.key==="ArrowLeft"?(S.preventDefault(),l(s.focusIndex-1)):S.key==="ArrowRight"&&(S.preventDefault(),l(s.focusIndex+1))}),(s.focusNavPending||document.activeElement===document.body)&&(s.focusNavPending=!1,a.focus({preventScroll:!0}))}var Ot=require("obsidian"),fc=dn(Ls());var Pg=[{id:"table",label:"Table"},{id:"library",label:"Cards"},{id:"kanban-genre",label:"Kanban"}];function uc(s){return s&&typeof s=="object"&&"basename"in s?s:null}function Og(s){let t=s.split(`
`).map(r=>r.trim()).filter(Boolean),e=r=>{var a,l;return(l=(a=t.find(c=>c.toLowerCase().startsWith(r+":")))==null?void 0:a.slice(r.length+1).trim())!=null?l:""},n=e("mode").toLowerCase(),i=n==="kanban"||n==="kanban-genre"?"kanban-genre":n==="cards"||n==="card"||n==="library"?"library":"table",o=parseInt(e("height"),10);return{file:e("file"),mode:i,height:Number.isFinite(o)&&o>0?o:null,collapse:e("collapse").split(",").map(r=>r.trim()).filter(Boolean)}}var zo=class extends Ot.MarkdownRenderChild{constructor(e,n,i,o,r){super(e);this.file=null;this.headers=[];this.rows=[];this.searchQuery="";this.tableSortCol=null;this.tableSortDir="asc";this.libraryStatusFilter="all";this.libraryGenreFilter="all";this.collapsedGroups=new Set;this.saveTimer=null;this.lastWritten=null;this.contentArea=null;this.app=n,this.settings=i,this.persistSettings=o,this.opts=r,this.mode=r.mode,this.collapsedGroups=new Set(r.collapse.map(a=>a.toLowerCase()))}get renderComponent(){return this}get contentEl(){return this.containerEl}get asView(){return this}async onload(){if(this.containerEl.addClass("csv-inline-view"),!this.opts.file){this.renderError("No file specified. Use: file: yourfile.csv");return}await this.reload()&&(this.renderView(),this.registerEvent(this.app.vault.on("modify",async e=>{if(!this.file||e.path!==this.file.path)return;let n=await this.app.vault.read(this.file);if(n===this.lastWritten)return;let i=Bt(n);this.headers=i.headers,this.rows=i.rows,this.renderView()})),this.registerEvent(this.app.vault.on("rename",(e,n)=>{this.file&&n===this.file.path&&(this.file=uc(e))})))}onunload(){this.saveTimer&&window.clearTimeout(this.saveTimer)}async reload(){let e=uc(this.app.vault.getAbstractFileByPath(this.opts.file));if(!e)return this.renderError(`File not found: ${this.opts.file}`),!1;this.file=e;try{let n=Bt(await this.app.vault.read(e));this.headers=n.headers,this.rows=n.rows}catch(n){return this.renderError(`Error reading file: ${n instanceof Error?n.message:String(n)}`),!1}return!0}renderError(e){this.containerEl.empty(),this.containerEl.createEl("p",{text:`csv-view: ${e}`,cls:"csv-add-error"})}scheduleSave(){this.saveTimer&&window.clearTimeout(this.saveTimer),this.saveTimer=window.setTimeout(()=>void this.doSave(),600)}async doSave(){if(this.file)try{let e=fc.default.unparse(this.rows,{columns:this.headers});this.lastWritten=e,await this.app.vault.modify(this.file,e)}catch(e){new Ot.Notice(`Couldn't save ${this.file.name}: ${e instanceof Error?e.message:String(e)}`,8e3)}}get fileCfg(){var e;return this.file?(e=this.settings.fileConfigs[this.file.path])!=null?e:{}:{}}saveFileCfg(e){this.file&&(this.settings.fileConfigs[this.file.path]=e,this.persistSettings())}isHighlighted(e){var n;return((n=this.fileCfg.highlightedTitles)!=null?n:[]).includes(this.getTitle(e))}toggleHighlight(e){let n=this.getTitle(e),i=this.fileCfg,o=i.highlightedTitles?[...i.highlightedTitles]:[],r=o.indexOf(n);r>=0?o.splice(r,1):o.push(n),i.highlightedTitles=o,this.saveFileCfg(i)}resolveCol(e){for(let n of e){let i=this.headers.find(o=>o.toLowerCase()===n.toLowerCase());if(i)return i}return null}getNotesCol(){return this.fileCfg.notesColumn!==void 0?this.fileCfg.notesColumn===""?null:this.fileCfg.notesColumn:this.resolveCol(Qe)}isNotesCol(e){let n=this.getNotesCol();return n?e===n:this.settings.notesColumns.some(i=>i.toLowerCase()===e.toLowerCase())}isSelectCol(e){return this.settings.selectColumns.some(n=>n.toLowerCase()===e.toLowerCase())}isCategoricalCol(e){var i;let n=(i=this.titleKey())!=null?i:this.headers[0];return e===n||this.getDateCol()===e||xt(e)?!1:this.fileCfg.categoricalColumns?this.fileCfg.categoricalColumns.includes(e):this.isSelectCol(e)||Xt(this.getColumnValues(e).length)}getStatusCol(){var e;return this.fileCfg.statusColumn!==void 0?this.fileCfg.statusColumn===""?null:(e=this.headers.find(n=>n.toLowerCase()===this.fileCfg.statusColumn.toLowerCase()))!=null?e:null:this.resolveCol(Xe)}getCategoryCol(){var e;return this.fileCfg.categoryColumn!==void 0?this.fileCfg.categoryColumn===""?null:(e=this.headers.find(n=>n.toLowerCase()===this.fileCfg.categoryColumn.toLowerCase()))!=null?e:null:this.resolveCol(qe)}titleKey(){var e,n;return this.fileCfg.titleColumn!==void 0?this.fileCfg.titleColumn===""?void 0:(e=this.headers.find(i=>i.toLowerCase()===this.fileCfg.titleColumn.toLowerCase()))!=null?e:void 0:(n=this.resolveCol(Ge))!=null?n:void 0}authorKey(){var e;return(e=this.resolveCol(["Author","author","Authors","authors","Director","director","Artist","artist","Creator","creator","By","by"]))!=null?e:void 0}getTitle(e){var i;let n=this.titleKey();return(i=n?e[n]:e[this.headers[0]])!=null?i:"\u2014"}getSubtitle(e){var i;let n=this.authorKey();return n&&(i=e[n])!=null?i:""}getColumnValues(e){return Array.from(new Set(this.rows.map(n=>{var i;return(i=n[e])!=null?i:""}).filter(Boolean))).sort()}getImageCol(){var e;return this.fileCfg.imageColumn!==void 0?this.fileCfg.imageColumn===""?null:(e=this.headers.find(n=>n.toLowerCase()===this.fileCfg.imageColumn.toLowerCase()))!=null?e:null:this.resolveCol(Ke)}getBooleanColumns(){return this.fileCfg.habitColumns?this.fileCfg.habitColumns.filter(e=>this.headers.includes(e)):this.headers.filter(e=>{if(e===this.getDateCol()||this.isNotesCol(e))return!1;let n=this.rows.map(i=>{var o;return((o=i[e])!=null?o:"").toLowerCase().trim()});return Ze(n)})}getDateCol(){var o,r;if(this.fileCfg.dateColumns&&this.fileCfg.dateColumns.length>0){let a=this.fileCfg.dateColumns[0];return(o=this.headers.find(l=>l===a))!=null?o:null}if(this.headers.length===0)return null;let e=this.headers[0];if(["date","day","datum"].includes(e.toLowerCase()))return e;let n=/^\d{4}-\d{2}-\d{2}$/,i=this.rows.slice(0,5);return i.length>0&&i.every(a=>{var l;return n.test((l=a[e])!=null?l:"")})?e:(r=this.headers.find(a=>this.isDateCol(a)))!=null?r:null}isDateCol(e){var n;return(n=this.fileCfg.dateColumns)!=null&&n.includes(e)?!0:wt(e)}getFilteredRows(){var i;let e=this.rows;if(this.searchQuery.trim()){let o=this.searchQuery.toLowerCase().trim();e=e.filter(r=>this.headers.some(a=>{var l;return((l=r[a])!=null?l:"").toLowerCase().includes(o)}))}if(this.mode==="table"&&this.tableSortCol&&this.headers.includes(this.tableSortCol)){let o=this.tableSortCol,r=this.tableSortDir;return[...e].sort((a,l)=>{var d,h;let c=((d=a[o])!=null?d:"").localeCompare((h=l[o])!=null?h:"",void 0,{numeric:!0});return r==="asc"?c:-c})}let n=this.getDateCol();if(this.mode==="table"&&n){let o=(i=this.fileCfg.sortNewestFirst)!=null?i:!0;e=[...e].sort((r,a)=>{var c,d;let l=((c=r[n])!=null?c:"").localeCompare((d=a[n])!=null?d:"");return o?-l:l})}return e}notesFilePath(e){var a,l,c;let n=As(this.getTitle(e)),i=(c=(l=(a=this.file)==null?void 0:a.parent)==null?void 0:l.path)!=null?c:"",o=this.settings.notesSubfolder.trim(),r=o?i?`${i}/${o}`:o:i;return(0,Ot.normalizePath)(`${r}/${n}.md`)}notesFileExists(e){return!!this.app.vault.getAbstractFileByPath(this.notesFilePath(e))}async openOrCreateNotes(e){var o;let n=this.notesFilePath(e),i=this.app.vault.getAbstractFileByPath(n);if(!i){let a=["---",...this.headers.filter(h=>!this.isNotesCol(h)&&e[h]).map(h=>`${h}: "${e[h].replace(/"/g,'\\"')}"`),"---","",`# ${this.getTitle(e)}`,"",""].join(`
`),l=this.headers.find(h=>this.isNotesCol(h)),c=a+(l&&((o=e[l])!=null&&o.trim())?e[l]:""),d=n.substring(0,n.lastIndexOf("/"));d&&!this.app.vault.getAbstractFileByPath(d)&&await this.app.vault.createFolder(d),i=await this.app.vault.create(n,c),new Ot.Notice(`Created: ${i.name}`)}await this.app.workspace.getLeaf("tab").openFile(i)}deleteWithUndo(e){let n=this.rows.indexOf(e);if(n<0)return;this.rows.splice(n,1),this.scheduleSave(),this.renderView();let i=this.getTitle(e)||"entry",o=document.createDocumentFragment();o.createSpan({text:`Deleted \u201C${i}\u201D. `});let r=o.createEl("button",{text:"Undo",cls:"csv-notice-undo"}),a=new Ot.Notice(o,6e3);r.addEventListener("click",()=>{r.hasAttribute("disabled")||(r.setAttribute("disabled","true"),this.rows.splice(Math.min(n,this.rows.length),0,e),this.scheduleSave(),this.renderView(),a.hide(),new Ot.Notice(`Restored \u201C${i}\u201D`,2500))})}openRowContextMenu(e,n){let i=new Ot.Menu;i.addItem(a=>a.setTitle("Open / Create Notes file").setIcon("file-text").onClick(()=>void this.openOrCreateNotes(e))),i.addItem(a=>a.setTitle("Open entry").setIcon("maximize").onClick(()=>{var l;return this.openNoteExpander(e,(l=this.getNotesCol())!=null?l:"")}));let o=this.getStatusCol();if(o){let a=this.getColumnValues(o);a.length&&(i.addSeparator(),a.forEach(l=>{l!==e[o]&&i.addItem(c=>c.setTitle(`Mark as: ${l}`).onClick(()=>{e[o]=l,this.scheduleSave(),this.renderView()}))}))}i.addSeparator();let r=this.isHighlighted(e);i.addItem(a=>a.setTitle(r?"Remove highlight":"Highlight").setIcon("highlighter").onClick(()=>{this.toggleHighlight(e),this.renderView()})),i.addSeparator(),i.addItem(a=>a.setTitle("Delete").setIcon("trash").onClick(()=>this.deleteWithUndo(e))),i.showAtMouseEvent(n)}openNoteExpander(e,n){var i,o;new ss(this.app,e,n,this.headers,(o=(i=this.file)==null?void 0:i.path)!=null?o:"",this.isNotesCol.bind(this),this.isSelectCol.bind(this),this.getColumnValues.bind(this),r=>{Object.assign(e,r),this.scheduleSave(),this.renderView()},()=>this.deleteWithUndo(e),this.isCategoricalCol.bind(this),this.titleKey(),r=>this.getBooleanColumns().includes(r),r=>this.isDateCol(r)).open()}openAddModal(){new es(this.app,this.headers,this.isNotesCol.bind(this),this.isSelectCol.bind(this),this.getColumnValues.bind(this),e=>{this.rows.push(e),this.scheduleSave(),this.renderView(),new Ot.Notice(`Added: ${this.getTitle(e)}`)},{},e=>this.getBooleanColumns().includes(e),e=>this.isCategoricalCol(e),this.titleKey(),e=>this.isDateCol(e)).open()}renderSelectField(e,n,i){var a;let o=(a=n[i])!=null?a:"",r=e.createDiv({cls:`csv-select-chip ${o?"":"empty"}`});return r.setText(o||"\u2014"),i.toLowerCase()==="status"&&o&&r.addClass(`status-chip-${o.toLowerCase().replace(/\s+/g,"-")}`),r.addEventListener("click",l=>{var c;l.stopPropagation(),Ft(r,(c=n[i])!=null?c:"",this.getColumnValues(i),d=>{n[i]=d,r.setText(d||"\u2014"),this.scheduleSave()},this.contentEl)}),r}renderMarkdownInto(e,n){var i,o;Ot.MarkdownRenderer.render(this.app,n,e,(o=(i=this.file)==null?void 0:i.path)!=null?o:"",this.renderComponent)}renderViewPreservingScroll(){this.renderView()}renderView(e=!1){let n=this.containerEl;e?this.contentArea&&this.contentArea.empty():(n.empty(),this.renderToolbar(n),this.contentArea=n.createDiv({cls:"csv-content-area"}),this.opts.height&&(this.contentArea.style.maxHeight=this.opts.height+"px"));let i=this.contentArea;if(i){if(i.toggleClass("csv-content-area--no-yscroll",this.mode==="kanban-genre"||this.mode==="table"),!this.headers.length){i.createDiv({cls:"csv-empty-state"}).createEl("p",{text:"This file is empty."});return}if(this.rows.length===0){let o=i.createDiv({cls:"csv-empty-state"});o.createEl("p",{text:"No entries yet."}),o.createEl("button",{cls:"csv-empty-state-action",text:"+ Add the first entry"}).addEventListener("click",()=>this.openAddModal());return}(this.mode==="library"||this.mode==="kanban-genre")&&!$t(this.asView)&&(this.mode="table"),this.mode==="library"?_n(this.asView,i):this.mode==="kanban-genre"?Cn(this.asView,i):yn(this.asView,i)}}renderToolbar(e){var c,d;let n=e.createDiv({cls:"csv-toolbar csv-inline-toolbar"});n.createDiv({cls:"csv-toolbar-title",text:(d=(c=this.file)==null?void 0:c.basename)!=null?d:""}).addEventListener("click",()=>{this.file&&this.app.workspace.getLeaf("tab").openFile(this.file)});let i=n.createDiv({cls:"csv-toolbar-controls"});i.createDiv({cls:"csv-row-count",text:`${this.rows.length} entries`});let o=!!$t(this.asView),r=i.createDiv({cls:"csv-mode-group"});Pg.forEach(({id:h,label:u})=>{if((h==="library"||h==="kanban-genre")&&!o)return;r.createEl("button",{cls:`csv-mode-btn ${this.mode===h?"active":""}`,text:u}).addEventListener("click",()=>{this.mode=h,this.renderView()})});let a=i.createEl("input",{cls:"csv-search-input",type:"text",placeholder:"Search\u2026",value:this.searchQuery,attr:{inputmode:"search",enterkeyhint:"search",autocomplete:"off"}}),l=null;a.addEventListener("input",h=>{this.searchQuery=h.target.value,l!==null&&window.clearTimeout(l),l=window.setTimeout(()=>{l=null,this.renderView(!0)},120)}),i.createEl("button",{cls:"csv-add-btn",text:"+ Add"}).addEventListener("click",()=>this.openAddModal())}};function gc(s,t,e,n){n("csv-view",(i,o,r)=>{var h,u,f;let a=Og(i),l=(f=(u=(h=s.vault.getAbstractFileByPath(r.sourcePath))==null?void 0:h.parent)==null?void 0:u.path)!=null?f:"",c=a.file?ue(a.file,l):a.file,d=new zo(o,s,t,e,{...a,file:c});r.addChild(d)})}var mc=require("obsidian");function Fg(s){let t=s.split(`
`).map(i=>i.trim()).filter(Boolean),e=i=>{var o,r;return(r=(o=t.find(a=>a.toLowerCase().startsWith(i+":")))==null?void 0:o.slice(i.length+1).trim())!=null?r:""},n=i=>{let o=parseFloat(e(i));return Number.isFinite(o)?o:null};return{file:e("file"),x:e("x"),y:e("y"),hue:e("hue")||e("color"),size:e("size"),agg:["count","sum","avg"].includes(e("agg").toLowerCase())?e("agg").toLowerCase():"",fit:e("fit").toLowerCase()==="linear"?"linear":"none",formula:e("formula"),xmin:n("xmin"),xmax:n("xmax"),height:n("height")}}function Ig(s){return s&&typeof s=="object"&&"basename"in s?s:null}function pc(s){let t=(s!=null?s:"").trim().match(/^(\d{4})-(\d{2})-(\d{2})/);return t?new Date(parseInt(t[1]),parseInt(t[2])-1,parseInt(t[3])):null}var Ho=class extends mc.MarkdownRenderChild{constructor(e,n,i){super(e);this.app=n;this.opts=i;this.chart=null}async onload(){this.containerEl.addClass("csv-chart-block"),await this.render(),this.opts.file&&(this.registerEvent(this.app.vault.on("modify",e=>{e.path===this.opts.file&&this.render()})),this.registerEvent(this.app.vault.on("rename",(e,n)=>{n===this.opts.file&&(this.opts.file=e.path)})))}onunload(){this.chart&&(this.chart.destroy(),this.chart=null)}renderError(e){this.containerEl.empty(),this.containerEl.createEl("p",{text:`csv-chart: ${e}`,cls:"csv-add-error"})}async render(){var l,c,d,h,u;let e=this.containerEl;this.chart&&(this.chart.destroy(),this.chart=null),e.empty();let n,i=0;if(this.opts.file){let f=Ig(this.app.vault.getAbstractFileByPath(this.opts.file));if(!f)return this.renderError(`File not found: ${this.opts.file}`);let g,p;try{({headers:g,rows:p}=Bt(await this.app.vault.read(f)))}catch(_){return this.renderError(`Error reading file: ${_ instanceof Error?_.message:String(_)}`)}let b=_=>{var w;return(w=g.find(D=>D.toLowerCase()===_.toLowerCase()))!=null?w:null},m=li(g,p),y=(l=g.find(_=>wt(_)))!=null?l:p.slice(0,5).length&&p.slice(0,5).every(_=>{var w;return pc((w=_[g[0]])!=null?w:"")})?g[0]:null,C=this.opts.x?b(this.opts.x):(c=y!=null?y:m[0])!=null?c:null;if(this.opts.x&&!C)return this.renderError(`No column "${this.opts.x}" in ${f.basename}`);let E=this.opts.y?b(this.opts.y):(d=m.find(_=>_!==C))!=null?d:null;if(this.opts.y&&!E)return this.renderError(`No column "${this.opts.y}" in ${f.basename}`);if(!C||!E)return this.renderError(`Couldn't auto-pick x/y columns \u2014 add "x:" and "y:" lines`);let S=this.opts.hue?b(this.opts.hue):null;if(this.opts.hue&&!S)return this.renderError(`No column "${this.opts.hue}" in ${f.basename}`);let x=this.opts.size?b(this.opts.size):null;if(this.opts.size&&!x)return this.renderError(`No column "${this.opts.size}" in ${f.basename}`);let v=C===y||wt(C);if(!v&&!m.includes(C)){let _=this.opts.agg||"count",w=Vo(p,C,_==="count"?null:E,S,_);if(i=w.skipped,!w.categories.length)return this.renderError(`No rows with a "${C}" value to chart`);let D=_==="count"?"count":`${_}(${E})`;n={config:Bo(w,C,D,ks(e)),fitText:null,formulaError:null}}else{let _=Io(p,C,E,S,x,v,pc,D=>{var k;return(k=D[g[0]])!=null?k:""});if(i=_.skipped,!_.series.some(D=>D.points.length))return this.renderError(`No rows with numeric "${C}" and "${E}" values`);let w={series:_.series,xIsDate:v,xLabel:C,yLabel:E,connect:v,fit:this.opts.fit,formula:this.opts.formula,sizeLabel:x!=null?x:""};n=ci(w,ks(e))}}else{if(!this.opts.formula.trim())return this.renderError('Give a "file:" line, a "formula:" line, or both');n=ci({series:[],xIsDate:!1,xLabel:"x",yLabel:"y",connect:!1,fit:"none",formula:this.opts.formula,xMin:(h=this.opts.xmin)!=null?h:-10,xMax:(u=this.opts.xmax)!=null?u:10},ks(e))}if(n.formulaError)return this.renderError(`formula: ${n.formulaError}`);let o=e.createDiv({cls:"csv-chart-wrap"});this.opts.height&&(o.style.height=this.opts.height+"px");let r=o.createEl("canvas",{cls:"csv-chart-canvas"});if(n.fitText||i>0){let f=e.createDiv({cls:"csv-chart-footer"});n.fitText&&f.createSpan({cls:"csv-chart-fit-text",text:n.fitText}),i>0&&f.createSpan({cls:"csv-chart-skipped",text:`${i} row${i===1?"":"s"} skipped (no numeric value)`})}let{Chart:a}=await Ue();r.isConnected&&(this.chart=new a(r,n.config))}};function bc(s,t){t("csv-chart",(e,n,i)=>{var l,c,d;let o=Fg(e),r=(d=(c=(l=s.vault.getAbstractFileByPath(i.sourcePath))==null?void 0:l.parent)==null?void 0:c.path)!=null?d:"",a=o.file?ue(o.file,r):o.file;i.addChild(new Ho(n,s,{...o,file:a}))})}var cn,Ms=class extends it.FileView{constructor(e,n,i){super(e);this.headers=[];this.rows=[];this.saveTimer=null;this.searchQuery="";this.contentArea=null;this.selectedDate=null;this.selectedHabit=null;this.chartInstance=null;this.timelineYear=new Date().getFullYear();this.libraryStatusFilter="all";this.libraryGenreFilter="all";this.collapsedGroups=new Set;this.taskProjectFilter="all";this.taskTypeFilter="all";this.focusIndex=0;this.focusNavPending=!1;this.tableSortCol=null;this.tableSortDir="asc";this.settings=n,this.persistSettings=i,this.mode=n.defaultMode,this.renderComponent=new it.Component,this.renderComponent.load()}getViewType(){return hn}getDisplayText(){var e,n;return(n=(e=this.file)==null?void 0:e.basename)!=null?n:"Card View"}getIcon(){return"table"}async onLoadFile(e){var o;try{let r=await this.app.vault.read(e),a=Bt(r);this.headers=a.headers,this.rows=a.rows}catch(r){console.error("CardView load error",r),this.headers=[],this.rows=[],new it.Notice(`Couldn't read ${e.name}: ${r instanceof Error?r.message:String(r)}`,8e3)}this.file&&((o=this.settings.fileConfigs[this.file.path])!=null&&o.defaultMode)?this.mode=this.settings.fileConfigs[this.file.path].defaultMode:this.isTravelFile()?this.mode="travel":this.hasDateColumn()?this.mode="dashboard":this.mode=this.settings.defaultMode;let n=this.mode==="kanban-genre"||this.mode==="library",i=this.mode==="dashboard";(n&&!$t(this)||i&&!this.hasDateColumn()||this.mode==="travel"&&!this.isTravelFile()||this.mode==="stats"&&!xn(this)||this.mode==="chart"&&!di(this)||this.mode==="tasks"&&!ws(this))&&(this.mode="table"),this.selectedDate=null,this.focusIndex=0,this.tableSortCol=null,this.renderView()}async onUnloadFile(e){this.chartInstance&&(this.chartInstance.destroy(),this.chartInstance=null),this.headers=[],this.rows=[],this.contentEl.empty()}scheduleSave(){this.saveTimer&&window.clearTimeout(this.saveTimer),this.saveTimer=window.setTimeout(()=>this.doSave(),600)}async doSave(){if(this.file)try{let e=vc.default.unparse(this.rows,{columns:this.headers});await this.app.vault.modify(this.file,e)}catch(e){console.error("CardView save error",e),new it.Notice(`Couldn't save ${this.file.name}: ${e instanceof Error?e.message:String(e)}`,8e3)}}get fileCfg(){var e;return this.file?(e=this.settings.fileConfigs[this.file.path])!=null?e:{}:{}}saveFileCfg(e){this.file&&(this.settings.fileConfigs[this.file.path]=e,this.persistSettings())}isHighlighted(e){var n;return((n=this.fileCfg.highlightedTitles)!=null?n:[]).includes(this.getTitle(e))}toggleHighlight(e){let n=this.getTitle(e),i=this.fileCfg,o=i.highlightedTitles?[...i.highlightedTitles]:[],r=o.indexOf(n);r>=0?o.splice(r,1):o.push(n),i.highlightedTitles=o,this.saveFileCfg(i)}addColumn(e){let n=e.trim();return n?this.headers.some(i=>i.toLowerCase()===n.toLowerCase())?`"${n}" already exists.`:(this.headers.push(n),this.rows.forEach(i=>{i[n]=""}),this.scheduleSave(),this.renderViewPreservingScroll(),null):"Column name can't be empty."}removeColumn(e){this.headers=this.headers.filter(i=>i!==e),this.rows.forEach(i=>{delete i[e]});let n=this.fileCfg;n.categoryColumn===e&&(n.categoryColumn=void 0),n.statusColumn===e&&(n.statusColumn=void 0),n.notesColumn===e&&(n.notesColumn=void 0),n.ankiFrontCol===e&&(n.ankiFrontCol=void 0),n.kanbanGroupCol===e&&(n.kanbanGroupCol=void 0),n.habitColumns&&(n.habitColumns=n.habitColumns.filter(i=>i!==e)),n.cardFields&&(n.cardFields=n.cardFields.filter(i=>i!==e)),n.categoricalColumns&&(n.categoricalColumns=n.categoricalColumns.filter(i=>i!==e)),this.saveFileCfg(n),this.scheduleSave(),this.renderViewPreservingScroll()}resolveCol(e){for(let n of e){let i=this.headers.find(o=>o.toLowerCase()===n.toLowerCase());if(i)return i}return null}getNotesCol(){return this.fileCfg.notesColumn!==void 0?this.fileCfg.notesColumn===""?null:this.fileCfg.notesColumn:this.resolveCol(Qe)}isNotesCol(e){let n=this.getNotesCol();return n?e===n:this.settings.notesColumns.some(i=>i.toLowerCase()===e.toLowerCase())}isSelectCol(e){return this.settings.selectColumns.some(n=>n.toLowerCase()===e.toLowerCase())}isCategoricalCol(e){var i;let n=(i=this.titleKey())!=null?i:this.headers[0];return e===n||this.isDateCol(e)||xt(e)?!1:this.fileCfg.categoricalColumns?this.fileCfg.categoricalColumns.includes(e):this.isSelectCol(e)||Xt(this.getColumnValues(e).length)}autoDetectCategoricalColumns(){var n;let e=(n=this.titleKey())!=null?n:this.headers[0];return this.headers.filter(i=>i===e||this.isDateCol(i)||xt(i)||this.isNotesCol(i)?!1:this.isSelectCol(i)||Xt(this.getColumnValues(i).length))}isDateCol(e){var n;return(n=this.fileCfg.dateColumns)!=null&&n.includes(e)?!0:wt(e)}getStatusCol(){var e;return this.fileCfg.statusColumn!==void 0?this.fileCfg.statusColumn===""?null:(e=this.headers.find(n=>n.toLowerCase()===this.fileCfg.statusColumn.toLowerCase()))!=null?e:null:this.resolveCol(Xe)}getCategoryCol(){var e;return this.fileCfg.categoryColumn!==void 0?this.fileCfg.categoryColumn===""?null:(e=this.headers.find(n=>n.toLowerCase()===this.fileCfg.categoryColumn.toLowerCase()))!=null?e:null:this.resolveCol(qe)}titleKey(){var e,n;return this.fileCfg.titleColumn!==void 0?this.fileCfg.titleColumn===""?void 0:(e=this.headers.find(i=>i.toLowerCase()===this.fileCfg.titleColumn.toLowerCase()))!=null?e:void 0:(n=this.resolveCol(Ge))!=null?n:void 0}authorKey(){var e;return(e=this.resolveCol(["Author","author","Authors","authors","Director","director","Artist","artist","Creator","creator","By","by"]))!=null?e:void 0}getTitle(e){var i;let n=this.titleKey();return(i=n?e[n]:e[this.headers[0]])!=null?i:"\u2014"}getSubtitle(e){var i;let n=this.authorKey();return n&&(i=e[n])!=null?i:""}getColumnValues(e){return Array.from(new Set(this.rows.map(n=>{var i;return(i=n[e])!=null?i:""}).filter(Boolean))).sort()}getImageCol(){var e;return this.fileCfg.imageColumn!==void 0?this.fileCfg.imageColumn===""?null:(e=this.headers.find(n=>n.toLowerCase()===this.fileCfg.imageColumn.toLowerCase()))!=null?e:null:this.resolveCol(Ke)}notesFilePath(e){var a,l,c;let n=As(this.getTitle(e)),i=(c=(l=(a=this.file)==null?void 0:a.parent)==null?void 0:l.path)!=null?c:"",o=this.settings.notesSubfolder.trim(),r=o?i?`${i}/${o}`:o:i;return(0,it.normalizePath)(`${r}/${n}.md`)}notesFileExists(e){return!!this.app.vault.getAbstractFileByPath(this.notesFilePath(e))}deleteWithUndo(e){let n=this.rows.indexOf(e);if(n<0)return;this.rows.splice(n,1),this.scheduleSave(),this.renderViewPreservingScroll();let i=this.getTitle(e)||"entry",o=document.createDocumentFragment();o.createSpan({text:`Deleted \u201C${i}\u201D. `});let r=o.createEl("button",{text:"Undo",cls:"csv-notice-undo"}),a=new it.Notice(o,6e3);r.addEventListener("click",()=>{if(r.hasAttribute("disabled"))return;r.setAttribute("disabled","true");let l=Math.min(n,this.rows.length);this.rows.splice(l,0,e),this.scheduleSave(),this.renderViewPreservingScroll(),a.hide(),new it.Notice(`Restored \u201C${i}\u201D`,2500)})}openRowContextMenu(e,n){let i=new it.Menu;i.addItem(a=>a.setTitle("Open / Create Notes file").setIcon("file-text").onClick(()=>this.openOrCreateNotes(e))),i.addItem(a=>a.setTitle("Open entry").setIcon("maximize").onClick(()=>{var l;return this.openNoteExpander(e,(l=this.getNotesCol())!=null?l:"")}));let o=this.getStatusCol();if(o){let a=this.getColumnValues(o);a.length&&(i.addSeparator(),a.forEach(l=>{l!==e[o]&&i.addItem(c=>c.setTitle(`Mark as: ${l}`).onClick(()=>{e[o]=l,this.scheduleSave(),this.renderViewPreservingScroll()}))}))}i.addSeparator();let r=this.isHighlighted(e);i.addItem(a=>a.setTitle(r?"Remove highlight":"Highlight").setIcon("highlighter").onClick(()=>{this.toggleHighlight(e),this.renderViewPreservingScroll()})),i.addSeparator(),i.addItem(a=>a.setTitle("Delete").setIcon("trash").onClick(()=>this.deleteWithUndo(e))),i.showAtMouseEvent(n)}async openOrCreateNotes(e){var o,r;let n=this.notesFilePath(e),i=this.app.vault.getAbstractFileByPath(n);if(!i){let a={},l=ws(this)?$o(this):null,c=l?((o=e[l])!=null?o:"").split(",").map(g=>qo(g.trim())).filter(Boolean).map(g=>`project-${g}`):[];c.length&&(a.tags=c);for(let g of this.headers)!this.isNotesCol(g)&&e[g]&&(a[g]=e[g]);this.file&&!Object.keys(a).some(g=>g.toLowerCase()==="source")&&(a.source=`[[${this.file.path}]]`);let d=["---",(0,it.stringifyYaml)(a).trimEnd(),"---","",`# ${this.getTitle(e)}`,"",""].join(`
`),h=this.headers.find(g=>this.isNotesCol(g)),u=d+(h&&((r=e[h])!=null&&r.trim())?e[h]:""),f=n.substring(0,n.lastIndexOf("/"));f&&!this.app.vault.getAbstractFileByPath(f)&&await this.app.vault.createFolder(f),i=await this.app.vault.create(n,u),new it.Notice(`Created: ${i.name}`)}await this.app.workspace.getLeaf("tab").openFile(i)}openNoteExpander(e,n){var i,o;new ss(this.app,e,n,this.headers,(o=(i=this.file)==null?void 0:i.path)!=null?o:"",this.isNotesCol.bind(this),this.isSelectCol.bind(this),this.getColumnValues.bind(this),r=>{Object.assign(e,r),this.scheduleSave(),this.renderViewPreservingScroll()},()=>this.deleteWithUndo(e),r=>this.isCategoricalCol(r),this.titleKey(),r=>this.getBooleanColumns().includes(r),r=>this.isDateCol(r)).open()}renderViewPreservingScroll(){var l,c,d,h,u;let e=this.contentEl,n=e.querySelector(".csv-content-area"),i=e.querySelector(".csv-table-wrapper"),o=e.querySelector(".csv-kanban-board"),r={contentTop:(l=n==null?void 0:n.scrollTop)!=null?l:0,contentLeft:(c=n==null?void 0:n.scrollLeft)!=null?c:0,tableLeft:(d=i==null?void 0:i.scrollLeft)!=null?d:0,tableTop:(h=i==null?void 0:i.scrollTop)!=null?h:0,boardLeft:(u=o==null?void 0:o.scrollLeft)!=null?u:0,cols:new Map};e.querySelectorAll(".csv-kanban-col").forEach(f=>{var b,m;let g=(m=(b=f.querySelector(".csv-kanban-col-title"))==null?void 0:b.textContent)!=null?m:"",p=f.querySelector(".csv-kanban-col-body");g&&p&&r.cols.set(g,p.scrollTop)}),this.renderView();let a=()=>{let f=this.contentEl.querySelector(".csv-content-area"),g=this.contentEl.querySelector(".csv-table-wrapper"),p=this.contentEl.querySelector(".csv-kanban-board");f&&(f.scrollTop=r.contentTop,f.scrollLeft=r.contentLeft),g&&(g.scrollLeft=r.tableLeft,g.scrollTop=r.tableTop),p&&(p.scrollLeft=r.boardLeft),this.contentEl.querySelectorAll(".csv-kanban-col").forEach(b=>{var E,S;let m=(S=(E=b.querySelector(".csv-kanban-col-title"))==null?void 0:E.textContent)!=null?S:"",y=b.querySelector(".csv-kanban-col-body"),C=r.cols.get(m);y&&C!=null&&(y.scrollTop=C)})};a(),requestAnimationFrame(()=>{a(),requestAnimationFrame(a)}),setTimeout(a,50)}openAddModal(){let e={};if(ws(this)){let n=hi(this);n&&(e[n]=["Task","Note","Idea"]);let i=ui(this);i&&(e[i]=["Low","Medium","High"])}new es(this.app,this.headers,this.isNotesCol.bind(this),this.isSelectCol.bind(this),this.getColumnValues.bind(this),n=>{this.rows.push(n),this.scheduleSave(),this.renderViewPreservingScroll(),new it.Notice(`Added: ${this.getTitle(n)}`)},e,n=>this.getBooleanColumns().includes(n),n=>this.isCategoricalCol(n),this.titleKey(),n=>this.isDateCol(n)).open()}renderSelectField(e,n,i){var a;let o=(a=n[i])!=null?a:"",r=e.createDiv({cls:`csv-select-chip ${o?"":"empty"}`});return r.setText(o||"\u2014"),i.toLowerCase()==="status"&&o&&r.addClass(`status-chip-${o.toLowerCase().replace(/\s+/g,"-")}`),r.addEventListener("click",l=>{var c;l.stopPropagation(),Ft(r,(c=n[i])!=null?c:"",this.getColumnValues(i),d=>{n[i]=d,r.setText(d||"\u2014"),r.className=`csv-select-chip ${d?"":"empty"}`,i.toLowerCase()==="status"&&d&&r.addClass(`status-chip-${d.toLowerCase().replace(/\s+/g,"-")}`),this.scheduleSave()},this.contentEl,{multi:xt(i)})}),r}renderView(e=!1){var o;let n=this.contentEl;e?this.contentArea&&this.contentArea.empty():(n.empty(),n.addClass("datadeck-root"),this.renderComponent.unload(),this.renderComponent=new it.Component,this.renderComponent.load(),lc(this,n),this.contentArea=n.createDiv({cls:"csv-content-area"}),this.installTouchScrollGuard(this.contentArea));let i=this.contentArea;if(i){if(i.toggleClass("csv-content-area--no-yscroll",this.mode==="kanban-genre"||this.mode==="table"),!this.headers.length){let r=i.createDiv({cls:"csv-empty-state csv-empty-state--big"});r.createEl("h3",{text:"This file is empty"}),r.createEl("p",{text:"Add a header row in your spreadsheet app, then come back \u2014 or click + Add in the toolbar to start fresh."});return}if(this.rows.length===0){let r=i.createDiv({cls:"csv-empty-state csv-empty-state--big"});r.createEl("h3",{text:"No entries yet"}),r.createEl("button",{cls:"csv-empty-state-action",text:"+ Add the first entry"}).addEventListener("click",()=>this.openAddModal()),r.createEl("p",{cls:"csv-empty-state-hint",text:`${this.headers.length} column${this.headers.length===1?"":"s"} detected: ${this.headers.slice(0,5).join(", ")}${this.headers.length>5?"\u2026":""}`});return}this.mode==="travel"?dr(i,this.rows,()=>this.loadMapSvg(),()=>this.scheduleSave(),this.settings.showResidency===!1?null:(o=this.settings.residencyRules)!=null?o:null,r=>this.renderComponent.register(r)):this.mode==="dashboard"?dc(this,i):this.mode==="library"?_n(this,i):this.mode==="kanban-genre"?Cn(this,i):this.mode==="stats"?mr(this,i):this.mode==="chart"?sc(this,i):this.mode==="focus"?hc(this,i):this.mode==="tasks"?ac(this,i):yn(this,i)}}installTouchScrollGuard(e){if(!matchMedia("(pointer: coarse)").matches)return;let n=0,i=0,o=!1;e.addEventListener("touchstart",r=>{r.touches.length===1&&(n=r.touches[0].clientX,i=r.touches[0].clientY,o=!1)},{capture:!0,passive:!0}),e.addEventListener("touchmove",r=>{if(r.touches.length!==1||o)return;let a=Math.abs(r.touches[0].clientX-n),l=Math.abs(r.touches[0].clientY-i);(a>10||l>10)&&(o=!0)},{capture:!0,passive:!0}),e.addEventListener("click",r=>{o&&(r.preventDefault(),r.stopImmediatePropagation())},!0)}async backupToArchive(){var a,l;if(!this.file)return;let e=(l=(a=this.file.parent)==null?void 0:a.path)!=null?l:"",n=e?`${e}/Archive`:"Archive";await this.app.vault.adapter.exists(n)||await this.app.vault.adapter.mkdir(n);let i=this.formatDate(new Date),o=`${n}/${this.file.basename}_${i}.${this.file.extension}`;if(await this.app.vault.adapter.exists(o)){new it.Notice(`Backup already exists for today: ${o}`);return}let r=await this.app.vault.readBinary(this.file);await this.app.vault.adapter.writeBinary(o,r),new it.Notice(`Backed up to ${o}`)}hasDateColumn(){return this.getDateCol()!==null}isTravelFile(){let e=new Set(this.headers.map(n=>n.toLowerCase()));return e.has("country")&&e.has("date_entered")&&e.has("date_left")&&e.has("source")}async loadMapSvg(){if(cn!==void 0)return cn;let e=(0,it.normalizePath)(`${this.app.vault.configDir}/plugins/datadeck/world-map.svg`);try{cn=await this.app.vault.adapter.read(e)}catch(n){cn=null}return cn}getFilteredRows(){var i;let e=this.rows;if(this.searchQuery.trim()){let o=this.searchQuery.toLowerCase().trim();e=e.filter(r=>this.headers.some(a=>{var c;return((c=r[a])!=null?c:"").toLowerCase().includes(o)}))}if(this.mode==="table"&&this.tableSortCol&&this.headers.includes(this.tableSortCol))return Xo(e,this.tableSortCol,this.tableSortDir);let n=this.getDateCol();if(this.mode==="table"&&n){let o=(i=this.fileCfg.sortNewestFirst)!=null?i:!0;e=[...e].sort((r,a)=>{var h,u;let l=(h=r[n])!=null?h:"",c=(u=a[n])!=null?u:"",d=l.localeCompare(c);return o?-d:d})}return e}getDateCol(){var a;if(this.fileCfg.dateColumns&&this.fileCfg.dateColumns.length>0){let l=this.fileCfg.dateColumns[0];return(a=this.headers.find(c=>c===l))!=null?a:null}if(this.headers.length===0)return null;let e=this.headers[0],n=e.toLowerCase();if(["date","day","datum"].includes(n))return e;let i=this.rows.slice(0,5),o=/^\d{4}-\d{2}-\d{2}$/;return i.length>0&&i.every(l=>{var c;return o.test((c=l[e])!=null?c:"")})?e:null}getBooleanColumns(){return this.fileCfg.habitColumns?this.fileCfg.habitColumns.filter(e=>this.headers.includes(e)):this.autoDetectBooleanColumns()}cleanupBooleanColumn(e){let n=0;return this.rows.forEach(i=>{var r;let o=this.isTruthy((r=i[e])!=null?r:"")?"1":"0";i[e]!==o&&n++,i[e]=o}),n>0&&(this.scheduleSave(),this.renderViewPreservingScroll()),n}autoDetectBooleanColumns(){return this.headers.filter(e=>{if(e===this.getDateCol()||this.isNotesCol(e))return!1;let n=this.rows.map(i=>{var o;return((o=i[e])!=null?o:"").toLowerCase().trim()});return Ze(n)})}parseDate(e){let n=e.match(/^(\d{4})-(\d{2})-(\d{2})$/);return n?new Date(parseInt(n[1]),parseInt(n[2])-1,parseInt(n[3])):null}formatDate(e){let n=e.getFullYear(),i=String(e.getMonth()+1).padStart(2,"0"),o=String(e.getDate()).padStart(2,"0");return`${n}-${i}-${o}`}isTruthy(e){return Je(e)}renderMarkdownInto(e,n){var i,o;it.MarkdownRenderer.render(this.app,n,e,(o=(i=this.file)==null?void 0:i.path)!=null?o:"",this.renderComponent)}cycleMode(){let e=fi(this);if(e.length<2)return;let n=e.findIndex(i=>i.id===this.mode);this.mode=e[(n+1)%e.length].id,this.renderView()}onunload(){this.renderComponent.unload(),this.saveTimer&&window.clearTimeout(this.saveTimer)}},Vg=[{id:"tasks",command:"Create tasks file",defaultName:"Tasks",headers:["Title","Type","Project","Priority","Due","Status","Notes"],mode:"tasks",configOverrides:{categoricalColumns:["Type","Priority"],dateColumns:["Due"],statusColumn:"Status",notesColumn:"Notes"}},{id:"travel",command:"Create travel file",defaultName:"Travel",headers:["date_entered","date_left","country","city","visa_status","notes","source","resolved"],mode:"travel"},{id:"habits",command:"Create habit tracker file",defaultName:"Habits",headers:["Date","Exercise","Meditate","Read","Notes"],mode:"dashboard",configOverrides:{habitColumns:["Exercise","Meditate","Read"],notesColumn:"Notes",statusColumn:""}},{id:"chart",command:"Create chart file",defaultName:"Measurements",headers:["Date","Value","Notes"],mode:"chart",configOverrides:{chartYCol:"Value",chartFit:"linear",notesColumn:"Notes"}}],pi=class extends it.Plugin{constructor(){super(...arguments);this.settings=xi}async onload(){await this.loadSettings(),this.registerView(hn,e=>new Ms(e,this.settings,()=>this.saveSettings())),this.registerExtensions(["csv"],hn),this.addSettingTab(new vn(this.app,this)),this.registerMarkdownCodeBlockProcessor("csv-add",async(e,n,i)=>{await ur(this.app,e.trim(),n,i,this.settings.fileConfigs)}),this.registerMarkdownCodeBlockProcessor("csv-random",async(e,n,i)=>{await cc(this.app,e.trim(),n,i)}),gc(this.app,this.settings,()=>this.saveSettings(),(e,n)=>this.registerMarkdownCodeBlockProcessor(e,n)),bc(this.app,(e,n)=>this.registerMarkdownCodeBlockProcessor(e,n)),this.addCommand({id:"add-entry",name:"Add entry to current CSV",checkCallback:e=>{let n=this.app.workspace.getActiveViewOfType(Ms);return n?(e||n.openAddModal(),!0):!1}}),this.addCommand({id:"cycle-view-mode",name:"Cycle view mode",checkCallback:e=>{let n=this.app.workspace.getActiveViewOfType(Ms);return n?(e||n.cycleMode(),!0):!1}});for(let e of Vg)this.addCommand({id:`create-${e.id}`,name:e.command,callback:()=>this.createTemplateFile(e)});this.registerEvent(this.app.vault.on("rename",async(e,n)=>{e instanceof it.TFile&&e.extension==="csv"&&this.settings.fileConfigs[n]&&(er(this.settings.fileConfigs,n,e.path),await this.saveSettings())})),this.registerEvent(this.app.vault.on("delete",async e=>{e instanceof it.TFile&&this.settings.fileConfigs[e.path]&&(delete this.settings.fileConfigs[e.path],await this.saveSettings())})),this.registerMarkdownCodeBlockProcessor("csv-refresh",(e,n,i)=>{let o=n.createEl("button",{cls:"csv-refresh-btn"});o.innerHTML="\u21BB refresh",o.addEventListener("click",async()=>{let r=i.sourcePath,a=this.app.vault.getAbstractFileByPath(r);if(a instanceof it.TFile){let l=this.app.workspace.activeLeaf;l&&await l.openFile(a,{state:{mode:"preview"}})}})})}async createTemplateFile(e){new pn(this.app,e.command,e.defaultName,"File name (without .csv)",async n=>{let i=this.app.workspace.getActiveFile(),o=i!=null&&i.parent&&i.parent.path!=="/"?`${i.parent.path}/`:"",r=As(n),a=(0,it.normalizePath)(`${o}${r}.csv`);for(let d=2;this.app.vault.getAbstractFileByPath(a);d++)a=(0,it.normalizePath)(`${o}${r} ${d}.csv`);let l=await this.app.vault.create(a,e.headers.join(",")+`
`),c=this.settings.fileConfigs[l.path]||{};this.settings.fileConfigs[l.path]={...c,defaultMode:e.mode,...e.configOverrides||{}},await this.saveSettings(),await this.app.workspace.getLeaf("tab").openFile(l),new it.Notice(`Created: ${l.name}`)}).open()}async loadSettings(){var e;this.settings=Object.assign({},xi,await this.loadData()),this.settings.residencyRules=JSON.parse(JSON.stringify((e=this.settings.residencyRules)!=null?e:[]))}async saveSettings(){await this.saveData(this.settings)}};
/*! Bundled license information:
papaparse/papaparse.min.js:
(* @license
Papa Parse
v5.5.3
https://github.com/mholt/PapaParse
License: MIT
*)
@kurkle/color/dist/color.esm.js:
(*!
* @kurkle/color v0.3.4
* https://github.com/kurkle/color#readme
* (c) 2024 Jukka Kurkela
* Released under the MIT License
*)
chart.js/dist/chunks/helpers.dataset.js:
(*!
* Chart.js v4.5.1
* https://www.chartjs.org
* (c) 2025 Chart.js Contributors
* Released under the MIT License
*)
chart.js/dist/chart.js:
(*!
* Chart.js v4.5.1
* https://www.chartjs.org
* (c) 2025 Chart.js Contributors
* Released under the MIT License
*)
*/