diff --git a/main.js b/main.js index 3359c85..119e1e3 100644 --- a/main.js +++ b/main.js @@ -1,24 +1,24 @@ -"use strict";var Kl=Object.create;var ys=Object.defineProperty;var Yl=Object.getOwnPropertyDescriptor;var Gl=Object.getOwnPropertyNames;var ql=Object.getPrototypeOf,Xl=Object.prototype.hasOwnProperty;var Ql=(s,t,e)=>t in s?ys(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e;var si=(s,t)=>()=>(s&&(t=s(s=0)),t);var Zl=(s,t)=>()=>(t||s((t={exports:{}}).exports,t),t.exports),Eo=(s,t)=>{for(var e in t)ys(s,e,{get:t[e],enumerable:!0})},ko=(s,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Gl(t))!Xl.call(s,i)&&i!==e&&ys(s,i,{get:()=>t[i],enumerable:!(n=Yl(t,i))||n.enumerable});return s};var Qs=(s,t,e)=>(e=s!=null?Kl(ql(s)):{},ko(t||!s||!s.__esModule?ys(e,"default",{value:s,enumerable:!0}):e,s)),Jl=s=>ko(ys({},"__esModule",{value:!0}),s);var W=(s,t,e)=>(Ql(s,typeof t!="symbol"?t+"":t,e),e);var xs=Zl((ni,ii)=>{((s,t)=>{typeof define=="function"&&define.amd?define([],t):typeof ii=="object"&&typeof ni!="undefined"?ii.exports=t():s.Papa=t()})(ni,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(y){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,y),this.parseChunk=function(v,_){var E=parseInt(this._config.skipFirstNLines)||0;if(this.isFirstChunk&&0=this._config.preview),i)t.postMessage({results:M,workerId:a.WORKER_ID,finished:E});else if(S(this._config.chunk)&&!_){if(this._config.chunk(M,this._handle),this._handle.paused()||this._handle.aborted())return void(this._halted=!0);this._completeResults=M=void 0}return this._config.step||this._config.chunk||(this._completeResults.data=this._completeResults.data.concat(M.data),this._completeResults.errors=this._completeResults.errors.concat(M.errors),this._completeResults.meta=M.meta),this._completed||!E||!S(this._config.complete)||M&&M.meta.aborted||(this._config.complete(this._completeResults,this._input),this._completed=!0),E||M&&M.meta.paused||this._nextChunk(),M}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(y){var v;(y=y||{}).chunkSize||(y.chunkSize=a.RemoteChunkSize),l.call(this,y),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=w(this._chunkLoaded,this),v.onerror=w(this._chunkError,this)),v.open(this._config.downloadRequestBody?"POST":"GET",this._input,!n),this._config.downloadRequestHeaders){var _,E=this._config.downloadRequestHeaders;for(_ in E)v.setRequestHeader(_,E[_])}var M;this._config.chunkSize&&(M=this._start+this._config.chunkSize-1,v.setRequestHeader("Range","bytes="+this._start+"-"+M));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(y){(y=y||{}).chunkSize||(y.chunkSize=a.LocalChunkSize),l.call(this,y);var v,_,E=typeof FileReader!="undefined";this.stream=function(M){this._input=M,_=M.slice||M.webkitSlice||M.mozSlice,E?((v=new FileReader).onload=w(this._chunkLoaded,this),v.onerror=w(this._chunkError,this)):v=new FileReaderSync,this._nextChunk()},this._nextChunk=function(){this._finished||this._config.preview&&!(this._rowCount=this._input.size,this.parseChunk(M.target.result)},this._chunkError=function(){this._sendError(v.error)}}function h(y){var v;l.call(this,y=y||{}),this.stream=function(_){return v=_,this._nextChunk()},this._nextChunk=function(){var _,E;if(!this._finished)return _=this._config.chunkSize,v=_?(E=v.substring(0,_),v.substring(_)):(E=v,""),this._finished=!v,this.parseChunk(E)}}function u(y){l.call(this,y=y||{});var v=[],_=!0,E=!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(M){this._input=M,this._input.on("data",this._streamData),this._input.on("end",this._streamEnd),this._input.on("error",this._streamError)},this._checkIsFinished=function(){E&&v.length===1&&(this._finished=!0)},this._nextChunk=function(){this._checkIsFinished(),v.length?this.parseChunk(v.shift()):_=!0},this._streamData=w(function(M){try{v.push(typeof M=="string"?M:M.toString(this._config.encoding)),_&&(_=!1,this._checkIsFinished(),this.parseChunk(v.shift()))}catch(k){this._streamError(k)}},this),this._streamError=w(function(M){this._streamCleanUp(),this._sendError(M)},this),this._streamEnd=w(function(){this._streamCleanUp(),E=!0,this._streamData("")},this),this._streamCleanUp=w(function(){this._input.removeListener("data",this._streamData),this._input.removeListener("end",this._streamEnd),this._input.removeListener("error",this._streamError)},this)}function f(y){var v,_,E,M,k=Math.pow(2,53),L=-k,D=/^\s*-?(\d+\.?|\.\d+|\d+\.\d+)([eE][-+]?\d+)?\s*$/,T=/^((\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)))$/,A=this,N=0,O=0,j=!1,z=!1,K=[],$={data:[],errors:[],meta:{}};function Q(P){return y.skipEmptyLines==="greedy"?P.join("").trim()==="":P.length===1&&P[0].length===0}function X(){if($&&E&&(I("Delimiter","UndetectableDelimiter","Unable to auto-detect delimiting character; defaulted to '"+a.DefaultDelimiter+"'"),E=!1),y.skipEmptyLines&&($.data=$.data.filter(function(q){return!Q(q)})),R()){let q=function(B,Y){S(y.transformHeader)&&(B=y.transformHeader(B,Y)),K.push(B)};var V=q;if($)if(Array.isArray($.data[0])){for(var P=0;R()&&P<$.data.length;P++)$.data[P].forEach(q);$.data.splice(0,1)}else $.data.forEach(q)}function H(q,B){for(var Y=y.header?{}:[],U=0;U(lt=>(y.dynamicTypingFunction&&y.dynamicTyping[lt]===void 0&&(y.dynamicTyping[lt]=y.dynamicTypingFunction(lt)),(y.dynamicTyping[lt]||y.dynamicTyping)===!0))(J)?st==="true"||st==="TRUE"||st!=="false"&&st!=="FALSE"&&((lt=>{if(D.test(lt)&&(lt=parseFloat(lt),L=K.length?"__parsed_extra":K[U]:G,nt=y.transform?y.transform(nt,G):nt);G==="__parsed_extra"?(Y[G]=Y[G]||[],Y[G].push(nt)):Y[G]=nt}return y.header&&(U>K.length?I("FieldMismatch","TooManyFields","Too many fields: expected "+K.length+" fields but parsed "+U,O+B):Uy.preview?_.abort():($.data=$.data[0],M($,A))))}),this.parse=function(P,H,F){var V=y.quoteChar||'"',V=(y.newline||(y.newline=this.guessLineEndings(P,V)),E=!1,y.delimiter?S(y.delimiter)&&(y.delimiter=y.delimiter(P),$.meta.delimiter=y.delimiter):((V=((q,B,Y,U,G)=>{var nt,J,st,lt;G=G||[","," ","|",";",a.RECORD_SEP,a.UNIT_SEP];for(var Ot=0;Ot=F.length/2?`\r +"use strict";var Xl=Object.create;var Ss=Object.defineProperty;var Ql=Object.getOwnPropertyDescriptor;var Zl=Object.getOwnPropertyNames;var Jl=Object.getPrototypeOf,tc=Object.prototype.hasOwnProperty;var ec=(s,t,e)=>t in s?Ss(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e;var oi=(s,t)=>()=>(s&&(t=s(s=0)),t);var sc=(s,t)=>()=>(t||s((t={exports:{}}).exports,t),t.exports),Do=(s,t)=>{for(var e in t)Ss(s,e,{get:t[e],enumerable:!0})},To=(s,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Zl(t))!tc.call(s,i)&&i!==e&&Ss(s,i,{get:()=>t[i],enumerable:!(n=Ql(t,i))||n.enumerable});return s};var en=(s,t,e)=>(e=s!=null?Xl(Jl(s)):{},To(t||!s||!s.__esModule?Ss(e,"default",{value:s,enumerable:!0}):e,s)),nc=s=>To(Ss({},"__esModule",{value:!0}),s);var W=(s,t,e)=>(ec(s,typeof t!="symbol"?t+"":t,e),e);var Es=sc((ri,ai)=>{((s,t)=>{typeof define=="function"&&define.amd?define([],t):typeof ai=="object"&&typeof ri!="undefined"?ai.exports=t():s.Papa=t()})(ri,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(y){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 _=x(v);_.chunkSize=parseInt(_.chunkSize),v.step||v.chunk||(_.chunkSize=null),this._handle=new f(_),(this._handle.streamer=this)._config=_}.call(this,y),this.parseChunk=function(v,_){var E=parseInt(this._config.skipFirstNLines)||0;if(this.isFirstChunk&&0=this._config.preview),i)t.postMessage({results:M,workerId:a.WORKER_ID,finished:E});else if(S(this._config.chunk)&&!_){if(this._config.chunk(M,this._handle),this._handle.paused()||this._handle.aborted())return void(this._halted=!0);this._completeResults=M=void 0}return this._config.step||this._config.chunk||(this._completeResults.data=this._completeResults.data.concat(M.data),this._completeResults.errors=this._completeResults.errors.concat(M.errors),this._completeResults.meta=M.meta),this._completed||!E||!S(this._config.complete)||M&&M.meta.aborted||(this._config.complete(this._completeResults,this._input),this._completed=!0),E||M&&M.meta.paused||this._nextChunk(),M}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(y){var v;(y=y||{}).chunkSize||(y.chunkSize=a.RemoteChunkSize),l.call(this,y),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=w(this._chunkLoaded,this),v.onerror=w(this._chunkError,this)),v.open(this._config.downloadRequestBody?"POST":"GET",this._input,!n),this._config.downloadRequestHeaders){var _,E=this._config.downloadRequestHeaders;for(_ in E)v.setRequestHeader(_,E[_])}var M;this._config.chunkSize&&(M=this._start+this._config.chunkSize-1,v.setRequestHeader("Range","bytes="+this._start+"-"+M));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(y){(y=y||{}).chunkSize||(y.chunkSize=a.LocalChunkSize),l.call(this,y);var v,_,E=typeof FileReader!="undefined";this.stream=function(M){this._input=M,_=M.slice||M.webkitSlice||M.mozSlice,E?((v=new FileReader).onload=w(this._chunkLoaded,this),v.onerror=w(this._chunkError,this)):v=new FileReaderSync,this._nextChunk()},this._nextChunk=function(){this._finished||this._config.preview&&!(this._rowCount=this._input.size,this.parseChunk(M.target.result)},this._chunkError=function(){this._sendError(v.error)}}function h(y){var v;l.call(this,y=y||{}),this.stream=function(_){return v=_,this._nextChunk()},this._nextChunk=function(){var _,E;if(!this._finished)return _=this._config.chunkSize,v=_?(E=v.substring(0,_),v.substring(_)):(E=v,""),this._finished=!v,this.parseChunk(E)}}function u(y){l.call(this,y=y||{});var v=[],_=!0,E=!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(M){this._input=M,this._input.on("data",this._streamData),this._input.on("end",this._streamEnd),this._input.on("error",this._streamError)},this._checkIsFinished=function(){E&&v.length===1&&(this._finished=!0)},this._nextChunk=function(){this._checkIsFinished(),v.length?this.parseChunk(v.shift()):_=!0},this._streamData=w(function(M){try{v.push(typeof M=="string"?M:M.toString(this._config.encoding)),_&&(_=!1,this._checkIsFinished(),this.parseChunk(v.shift()))}catch(k){this._streamError(k)}},this),this._streamError=w(function(M){this._streamCleanUp(),this._sendError(M)},this),this._streamEnd=w(function(){this._streamCleanUp(),E=!0,this._streamData("")},this),this._streamCleanUp=w(function(){this._input.removeListener("data",this._streamData),this._input.removeListener("end",this._streamEnd),this._input.removeListener("error",this._streamError)},this)}function f(y){var v,_,E,M,k=Math.pow(2,53),L=-k,D=/^\s*-?(\d+\.?|\.\d+|\d+\.\d+)([eE][-+]?\d+)?\s*$/,T=/^((\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)))$/,A=this,N=0,O=0,j=!1,z=!1,K=[],$={data:[],errors:[],meta:{}};function X(P){return y.skipEmptyLines==="greedy"?P.join("").trim()==="":P.length===1&&P[0].length===0}function Z(){if($&&E&&(F("Delimiter","UndetectableDelimiter","Unable to auto-detect delimiting character; defaulted to '"+a.DefaultDelimiter+"'"),E=!1),y.skipEmptyLines&&($.data=$.data.filter(function(q){return!X(q)})),R()){let q=function(B,Y){S(y.transformHeader)&&(B=y.transformHeader(B,Y)),K.push(B)};var V=q;if($)if(Array.isArray($.data[0])){for(var P=0;R()&&P<$.data.length;P++)$.data[P].forEach(q);$.data.splice(0,1)}else $.data.forEach(q)}function H(q,B){for(var Y=y.header?{}:[],U=0;U(lt=>(y.dynamicTypingFunction&&y.dynamicTyping[lt]===void 0&&(y.dynamicTyping[lt]=y.dynamicTypingFunction(lt)),(y.dynamicTyping[lt]||y.dynamicTyping)===!0))(J)?st==="true"||st==="TRUE"||st!=="false"&&st!=="FALSE"&&((lt=>{if(D.test(lt)&&(lt=parseFloat(lt),L=K.length?"__parsed_extra":K[U]:G,nt=y.transform?y.transform(nt,G):nt);G==="__parsed_extra"?(Y[G]=Y[G]||[],Y[G].push(nt)):Y[G]=nt}return y.header&&(U>K.length?F("FieldMismatch","TooManyFields","Too many fields: expected "+K.length+" fields but parsed "+U,O+B):Uy.preview?_.abort():($.data=$.data[0],M($,A))))}),this.parse=function(P,H,I){var V=y.quoteChar||'"',V=(y.newline||(y.newline=this.guessLineEndings(P,V)),E=!1,y.delimiter?S(y.delimiter)&&(y.delimiter=y.delimiter(P),$.meta.delimiter=y.delimiter):((V=((q,B,Y,U,G)=>{var nt,J,st,lt;G=G||[","," ","|",";",a.RECORD_SEP,a.UNIT_SEP];for(var Ot=0;Ot=I.length/2?`\r `:"\r"}}function g(y){return y.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function p(y){var v=(y=y||{}).delimiter,_=y.newline,E=y.comments,M=y.step,k=y.preview,L=y.fastMode,D=null,T=!1,A=y.quoteChar==null?'"':y.quoteChar,N=A;if(y.escapeChar!==void 0&&(N=y.escapeChar),(typeof v!="string"||-1=k)return it(!0);break}F.push({type:"Quotes",code:"InvalidQuotes",message:"Trailing quote on quoted field is malformed",row:H.length,index:O}),J++}}else if(E&&V.length===0&&z.substring(O,O+I)===E){if(G===-1)return it();O=G+R,G=z.indexOf(_,O),U=z.indexOf(v,O)}else if(U!==-1&&(U=k)return it(!0)}return Ft();function lt(yt){H.push(yt),q=O}function Ot(yt){var wt=0;return wt=yt!==-1&&(yt=z.substring(J+1,yt))&&yt.trim()===""?yt.length:wt}function Ft(yt){return $||(yt===void 0&&(yt=z.substring(O)),V.push(yt),O=Q,lt(V),P&&vt()),it()}function dt(yt){O=yt,lt(V),V=[],G=z.indexOf(_,O)}function it(yt){if(y.header&&!K&&H.length&&!T){var wt=H[0],ie=Object.create(null),ei=new Set(wt);let _o=!1;for(let je=0;jeE.charCodeAt(0)!==65279?E:E.slice(1))(y),_=new(v.download?c:h)(v)):y.readable===!0&&S(y.read)&&S(y.on)?_=new u(v):(t.File&&y instanceof File||y instanceof Object)&&(_=new d(v)),_.stream(y);(_=(()=>{var E;return!!a.WORKERS_SUPPORTED&&(E=(()=>{var M=t.URL||t.webkitURL||null,k=s.toString();return a.BLOB_URL||(a.BLOB_URL=M.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"})))})(),(E=new t.Worker(E)).onmessage=m,E.id=r++,o[E.id]=E)})()).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:y,config:v,workerId:_.id})},a.unparse=function(y,v){var _=!1,E=!0,M=",",k=`\r -`,L='"',D=L+L,T=!1,A=null,N=!1,O=((()=>{if(typeof v=="object"){if(typeof v.delimiter!="string"||a.BAD_DELIMITERS.filter(function(K){return v.delimiter.indexOf(K)!==-1}).length||(M=v.delimiter),typeof v.quotes!="boolean"&&typeof v.quotes!="function"&&!Array.isArray(v.quotes)||(_=v.quotes),typeof v.skipEmptyLines!="boolean"&&typeof v.skipEmptyLines!="string"||(T=v.skipEmptyLines),typeof v.newline=="string"&&(k=v.newline),typeof v.quoteChar=="string"&&(L=v.quoteChar),typeof v.header=="boolean"&&(E=v.header),Array.isArray(v.columns)){if(v.columns.length===0)throw new Error("Option columns is empty");A=v.columns}v.escapeChar!==void 0&&(D=v.escapeChar+L),v.escapeFormulae instanceof RegExp?N=v.escapeFormulae:typeof v.escapeFormulae=="boolean"&&v.escapeFormulae&&(N=/^[=+\-@\t\r].*$/)}})(),new RegExp(g(L),"g"));if(typeof y=="string"&&(y=JSON.parse(y)),Array.isArray(y)){if(!y.length||Array.isArray(y[0]))return j(null,y,T);if(typeof y[0]=="object")return j(A||Object.keys(y[0]),y,T)}else if(typeof y=="object")return typeof y.data=="string"&&(y.data=JSON.parse(y.data)),Array.isArray(y.data)&&(y.fields||(y.fields=y.meta&&y.meta.fields||A),y.fields||(y.fields=Array.isArray(y.data[0])?y.fields:typeof y.data[0]=="object"?Object.keys(y.data[0]):[]),Array.isArray(y.data[0])||typeof y.data[0]=="object"||(y.data=[y.data])),j(y.fields||[],y.data||[],T);throw new Error("Unable to serialize unrecognized input");function j(K,$,Q){var X="",R=(typeof K=="string"&&(K=JSON.parse(K)),typeof $=="string"&&($=JSON.parse($)),Array.isArray(K)&&0{for(var P=0;Pe-n*Math.max(Math.min(r-3,9-r,1),-1);return[i(0),i(8),i(4)]}function Wc(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 jc(s,t,e){let n=pr(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 Uc(s,t,e,n,i){return s===i?(t-e)/n+(t.5?d/(2-o-r):d/(o+r),l=Uc(e,n,i,d,o),l=l*60+.5),[l|0,c||0,a]}function vi(s,t,e,n){return(Array.isArray(t)?s(t[0],t[1],t[2]):s(t,e,n)).map(pe)}function yi(s,t,e){return vi(pr,s,t,e)}function Kc(s,t,e){return vi(jc,s,t,e)}function Yc(s,t,e){return vi(Wc,s,t,e)}function mr(s){return(s%360+360)%360}function Gc(s){let t=$c.exec(s),e=255,n;if(!t)return;t[5]!==n&&(e=t[6]?Ds(+t[5]):pe(+t[5]));let i=mr(+t[2]),o=+t[3]/100,r=+t[4]/100;return t[1]==="hwb"?n=Kc(i,o,r):t[1]==="hsv"?n=Yc(i,o,r):n=yi(i,o,r),{r:n[0],g:n[1],b:n[2],a:e}}function qc(s,t){var e=bi(s);e[0]=mr(e[0]+t),e=yi(e),s.r=e[0],s.g=e[1],s.b=e[2]}function Xc(s){if(!s)return;let t=bi(s),e=t[0],n=hr(t[1]),i=hr(t[2]);return s.a<255?`hsla(${e}, ${n}%, ${i}%, ${oe(s.a)})`:`hsl(${e}, ${n}%, ${i}%)`}function Qc(){let s={},t=Object.keys(fr),e=Object.keys(ur),n,i,o,r,a;for(n=0;n>16&255,o>>8&255,o&255]}return s}function Zc(s){bn||(bn=Qc(),bn.transparent=[0,0,0,0]);let t=bn[s.toLowerCase()];return t&&{r:t[0],g:t[1],b:t[2],a:t.length===4?t[3]:255}}function td(s){let t=Jc.exec(s),e=255,n,i,o;if(t){if(t[7]!==n){let r=+t[7];e=t[8]?Ds(r):ge(r*255,0,255)}return n=+t[1],i=+t[3],o=+t[5],n=255&(t[2]?Ds(n):ge(n,0,255)),i=255&(t[4]?Ds(i):ge(i,0,255)),o=255&(t[6]?Ds(o):ge(o,0,255)),{r:n,g:i,b:o,a:e}}}function ed(s){return s&&(s.a<255?`rgba(${s.r}, ${s.g}, ${s.b}, ${oe(s.a)})`:`rgb(${s.r}, ${s.g}, ${s.b})`)}function sd(s,t,e){let n=Qe(oe(s.r)),i=Qe(oe(s.g)),o=Qe(oe(s.b));return{r:pe(pi(n+e*(Qe(oe(t.r))-n))),g:pe(pi(i+e*(Qe(oe(t.g))-i))),b:pe(pi(o+e*(Qe(oe(t.b))-o))),a:s.a+e*(t.a-s.a)}}function vn(s,t,e){if(s){let n=bi(s);n[t]=Math.max(0,Math.min(n[t]+n[t]*e,t===0?360:1)),n=yi(n),s.r=n[0],s.g=n[1],s.b=n[2]}}function br(s,t){return s&&Object.assign(t||{},s)}function gr(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=pe(s[3]))):(t=br(s,{r:0,g:0,b:0,a:1}),t.a=pe(t.a)),t}function nd(s){return s.charAt(0)==="r"?td(s):Gc(s)}var ge,zt,mi,Ic,Vc,mn,Nc,Hc,$c,ur,fr,bn,Jc,pi,Qe,Ts,vr=si(()=>{ge=(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},mi=[..."0123456789ABCDEF"],Ic=s=>mi[s&15],Vc=s=>mi[(s&240)>>4]+mi[s&15],mn=s=>(s&240)>>4===(s&15),Nc=s=>mn(s.r)&&mn(s.g)&&mn(s.b)&&mn(s.a);Hc=(s,t)=>s<255?t(s):"";$c=/^(hsla?|hwb|hsv)\(\s*([-+.e\d]+)(?:deg)?[\s,]+([-+.e\d]+)%[\s,]+([-+.e\d]+)%(?:[\s,]+([-+.e\d]+)(%)?)?\s*\)$/;ur={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"},fr={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"};Jc=/^rgba?\(\s*([-+.\d]+)(%)?[\s,]+([-+.e\d]+)(%)?[\s,]+([-+.e\d]+)(%)?(?:[\s,/]+([-+.e\d]+)(%)?)?\s*\)$/;pi=s=>s<=.0031308?s*12.92:Math.pow(s,1/2.4)*1.055-.055,Qe=s=>s<=.04045?s/12.92:Math.pow((s+.055)/1.055,2.4);Ts=class s{constructor(t){if(t instanceof s)return t;let e=typeof t,n;e==="object"?n=gr(t):e==="string"&&(n=Bc(t)||Zc(t)||nd(t)),this._rgb=n,this._valid=!!n}get valid(){return this._valid}get rgb(){var t=br(this._rgb);return t&&(t.a=oe(t.a)),t}set rgb(t){this._rgb=gr(t)}rgbString(){return this._valid?ed(this._rgb):void 0}hexString(){return this._valid?zc(this._rgb):void 0}hslString(){return this._valid?Xc(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=sd(this._rgb,t._rgb,e)),this}clone(){return new s(this.rgb)}alpha(t){return this._rgb.a=pe(t),this}clearer(t){let e=this._rgb;return e.a*=1-t,this}greyscale(){let t=this._rgb,e=Ls(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 vn(this._rgb,2,t),this}darken(t){return vn(this._rgb,2,-t),this}saturate(t){return vn(this._rgb,1,t),this}desaturate(t){return vn(this._rgb,1,-t),this}rotate(t){return qc(this._rgb,t),this}}});function Zt(){}function tt(s){return s==null}function ht(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 Dt(s,t){return gt(s)?s:t}function Z(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 at(s,t,e,n){let i,o,r;if(ht(s))if(o=s.length,n)for(i=o-1;i>=0;i--)t.call(e,s[i],i);else for(i=0;i{for(let n of t){if(n==="")break;e=e&&e[n]}return e}}function le(s,t){return(yr[t]||(yr[t]=ad(t)))(s)}function wn(s){return s.charAt(0).toUpperCase()+s.slice(1)}function Pr(s){return s.type==="mouseup"||s.type==="click"||s.type==="contextmenu"}function ns(s,t,e){return Math.abs(s-t)i-o).pop(),t}function dd(s){return typeof s=="symbol"||typeof s=="object"&&s!==null&&!(Symbol.toPrimitive in s||"toString"in s||"valueOf"in s)}function Re(s){return!dd(s)&&!isNaN(parseFloat(s))&&isFinite(s)}function Or(s,t){let e=Math.round(s);return e-t<=s&&e+t>=s}function wi(s,t,e){let n,i,o;for(n=0,i=s.length;nl&&c=Math.min(t,e)-n&&s<=Math.max(t,e)+n}function Dn(s,t,e){e=e||(r=>s[r]1;)o=i+n>>1,e(o)?i=o:n=o;return{lo:i,hi:n}}function Vr(s,t,e){let n=0,i=s.length;for(;nn&&s[i-1]>e;)i--;return n>0||i{let n="_onData"+wn(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 Ti(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)&&(Nr.forEach(o=>{delete s[o]}),delete s._chartjs)}function Li(s){let t=new Set(s);return t.size===s.length?s:Array.from(t)}function Pi(s,t){let e=[],n=!1;return function(...i){e=i,n||(n=!0,Ai.call(window,()=>{n=!1,s.apply(t,e)}))}}function Hr(s,t){let e;return function(...n){return t?(clearTimeout(e),e=setTimeout(s,t,n)):s.apply(this,n),t}}function Ri(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(Xt(l,d,h).lo,e?n:Xt(t,d,r.getPixelForValue(h)).lo),c){let p=l.slice(0,i+1).reverse().findIndex(m=>!tt(m[a.axis]));i-=Math.max(0,p)}i=bt(i,0,n-1)}if(g){let p=Math.max(Xt(l,r.axis,u,!0).hi+1,e?0:Xt(t,d,r.getPixelForValue(u),!0).hi+1);if(c){let m=l.slice(p-1).findIndex(b=>!tt(b[a.axis]));p+=Math.max(0,m)}o=bt(p,i,n)-i}else o=n-i}return{start:i,count:o}}function Oi(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 Fi(s){if(s&&typeof s=="object"){let t=s.toString();return t==="[object CanvasPattern]"||t==="[object CanvasGradient]"}return!1}function Ii(s){return Fi(s)?s:new Ts(s)}function xi(s){return Fi(s)?s:new Ts(s).saturate(.5).darken(.1).hexString()}function gd(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:fd},numbers:{type:"number",properties:ud}}),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 pd(s){s.set("layout",{autoPadding:!0,padding:{top:0,right:0,bottom:0,left:0}})}function md(s,t){t=t||{};let e=s+JSON.stringify(t),n=Sr.get(e);return n||(n=new Intl.NumberFormat(s,t),Sr.set(e,n)),n}function os(s,t,e){return md(t,e).format(s)}function bd(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 vd(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:rs.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 As(s,t){if(!t)return s;let e=t.split(".");for(let n=0,i=e.length;nn&&(n=o),n}function Wr(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;le.length){for(l=0;l0&&s.stroke()}}function Qt(s,t,e){return e=e||.5,!t||s&&s.x>t.left-e&&s.xt.top-e&&s.y0&&o.strokeColor!=="",l,c;for(s.save(),s.font=i.string,xd(s,o),l=0;lZ(s[r],s[t[r]]):r=>s[r]:()=>s;for(let r of i)e[r]=wd(o(r));return e}function Bi(s){return Pn(s,{top:"y",right:"x",bottom:"y",left:"x"})}function Ce(s){return Pn(s,["topLeft","topRight","bottomLeft","bottomRight"])}function _t(s){let t=Bi(s);return t.width=t.left+t.right,t.height=t.top+t.bottom,t}function mt(s,t){s=s||{},t=t||ft.font;let e=Z(s.size,t.size);typeof e=="string"&&(e=parseInt(e,10));let n=Z(s.style,t.style);n&&!(""+n).match(Ed)&&(console.warn('Invalid font style specified: "'+n+'"'),n=void 0);let i={family:Z(s.family,t.family),lineHeight:kd(Z(s.lineHeight,t.lineHeight),e),size:e,style:n,weight:Z(s.weight,t.weight),string:""};return i.string=yd(i),i}function ls(s,t,e,n){let i=!0,o,r,a;for(o=0,r=s.length;oe&&a===0?0:a+l;return{min:r(n,-Math.abs(o)),max:r(i,o)}}function ce(s,t){return Object.assign(Object.create(s),t)}function Rn(s,t=[""],e,n,i=()=>s[0]){let o=e||s;typeof n=="undefined"&&(n=qr("_fallback",s));let r={[Symbol.toStringTag]:"Object",_cacheable:!0,_scopes:s,_rootScopes:o,_fallback:n,_getTarget:i,override:a=>Rn([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 Yr(a,l,()=>Od(l,t,s,a))},getOwnPropertyDescriptor(a,l){return Reflect.getOwnPropertyDescriptor(a._scopes[0],l)},getPrototypeOf(){return Reflect.getPrototypeOf(s[0])},has(a,l){return kr(a).includes(l)},ownKeys(a){return kr(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:Hi(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 Yr(o,r,()=>Dd(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 Hi(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:re(e)?e:()=>e,isIndexable:re(n)?n:()=>n}}function Yr(s,t,e){if(Object.prototype.hasOwnProperty.call(s,t)||t==="constructor")return s[t];let n=e();return s[t]=n,n}function Dd(s,t,e){let{_proxy:n,_context:i,_subProxy:o,_descriptors:r}=s,a=n[t];return re(a)&&r.isScriptable(t)&&(a=Td(t,a,s,e)),ht(a)&&a.length&&(a=Ld(t,a,s,r.isIndexable)),zi(t,a)&&(a=Pe(a,i,o&&o[t],r)),a}function Td(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),zi(s,l)&&(l=$i(i._scopes,i,s,l)),l}function Ld(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=$i(c,i,s,d);t.push(Pe(h,o,r&&r[s],a))}}return t}function Gr(s,t,e){return re(s)?s(t,e):s}function Pd(s,t,e,n,i){for(let o of t){let r=Ad(e,o);if(r){s.add(r);let a=Gr(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 $i(s,t,e,n){let i=t._rootScopes,o=Gr(t._fallback,e,n),r=[...s,...i],a=new Set;a.add(n);let l=Er(a,r,e,o||e,n);return l===null||typeof o!="undefined"&&o!==e&&(l=Er(a,r,o,l,n),l===null)?!1:Rn(Array.from(a),[""],i,o,()=>Rd(t,e,n))}function Er(s,t,e,n,i){for(;e;)e=Pd(s,t,e,n,i);return e}function Rd(s,t,e){let n=s._getTarget();t in n||(n[t]={});let i=n[t];return ht(i)&&et(e)?e:i||{}}function Od(s,t,e,n){let i;for(let o of t)if(i=qr(Md(o,s),e),typeof i!="undefined")return zi(s,i)?$i(e,n,s,i):i}function qr(s,t){for(let e of t){if(!e)continue;let n=e[s];if(typeof n!="undefined")return n}}function kr(s){let t=s._keys;return t||(t=s._keys=Fd(s._scopes)),t}function Fd(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 Wi(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!c.skip)),t.cubicInterpolationMode==="monotone")Hd(s,i);else{let c=n?s[s.length-1]:s[0];for(o=0,r=s.length;ol.height&&(d=l.height,c=be(Math.floor(d*n))),{width:c,height:d}}function ji(s,t,e){let n=t||1,i=be(s.height*n),o=be(s.width*n);s.height=be(s.height),s.width=be(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 Ui(s,t){let e=$d(s,t),n=e&&e.match(/^(\d+)(\.\d+)?px$/);return n?+n[1]:void 0}function me(s,t,e,n){return{x:s.x+e*(t.x-s.x),y:s.y+e*(t.y-s.y)}}function ta(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 ea(s,t,e,n){let i={x:s.cp2x,y:s.cp2y},o={x:t.cp1x,y:t.cp1y},r=me(s,i,e),a=me(i,o,e),l=me(o,t,e),c=me(r,a,e),d=me(a,l,e);return me(c,d,e)}function Oe(s,t,e){return s?Yd(t,e):Gd()}function Ki(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 Yi(s,t){t!==void 0&&(delete s.prevTextDirection,s.canvas.style.setProperty("direction",t[0],t[1]))}function sa(s){return s==="angle"?{between:is,compare:hd,normalize:xt}:{between:Jt,compare:(t,e)=>t-e,normalize:t=>t}}function wr({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 qd(s,t,e){let{property:n,start:i,end:o}=e,{between:r,normalize:a}=sa(n),l=t.length,{start:c,end:d,loop:h}=s,u,f;if(h){for(c+=l,d+=l,u=0,f=l;ul(i,C,b)&&a(i,C)!==0,S=()=>a(o,b)===0||l(o,C,b),y=()=>p||w(),v=()=>!p||S();for(let _=d,E=d;_<=h;++_)x=t[_%r],!x.skip&&(b=c(x[n]),b!==C&&(p=l(b,i,o),m===null&&y()&&(m=a(b,i)===0?_:E),m!==null&&v()&&(g.push(wr({start:m,end:_,loop:u,count:r,style:f})),m=null),E=_,C=b));return m!==null&&g.push(wr({start:m,end:h,loop:u,count:r,style:f})),g}function qi(s,t){let e=[],n=s.segments;for(let i=0;ii&&s[o%t].skip;)o--;return o%=t,{start:i,end:o}}function Qd(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 na(s,t){let e=s.points,n=s.options.spanGaps,i=e.length;if(!i)return[];let o=!!s._loop,{start:r,end:a}=Xd(e,i,o,n);if(n===!0)return Mr(s,[{start:r,end:a,loop:o}],e,t);let l=a{vr();Tr=(()=>{let s=0;return()=>s++})();Lr=(s,t)=>typeof s=="string"&&s.endsWith("%")?parseFloat(s)/100:+s/t,Si=(s,t)=>typeof s=="string"&&s.endsWith("%")?parseFloat(s)/100*t:+s;yr={"":s=>s,x:s=>s.x,y:s=>s.y};ss=s=>typeof s!="undefined",re=s=>typeof s=="function",Ei=(s,t)=>{if(s.size!==t.size)return!1;for(let e of s)if(!t.has(e))return!1;return!0};ot=Math.PI,ut=2*ot,ld=ut+ot,Sn=Number.POSITIVE_INFINITY,cd=ot/180,pt=ot/2,Le=ot/4,xr=ot*2/3,ae=Math.log10,jt=Math.sign;Xt=(s,t,e,n)=>Dn(s,e,n?i=>{let o=s[i][t];return os[i][t]Dn(s,e,n=>s[n][t]>=e);Nr=["push","pop","shift","splice","unshift"];Ai=function(){return typeof window=="undefined"?function(s){return s()}:window.requestAnimationFrame}();Tn=s=>s==="start"?"left":s==="end"?"right":"center",Ct=(s,t,e)=>s==="start"?t:s==="end"?e:(t+e)/2,zr=(s,t,e,n)=>s===(n?"left":"right")?e:s==="center"?(t+e)/2:t;yn=s=>s===0||s===1,Cr=(s,t,e)=>-(Math.pow(2,10*(s-=1))*Math.sin((s-t)*ut/e)),_r=(s,t,e)=>Math.pow(2,-10*s)*Math.sin((s-t)*ut/e)+1,Ze={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*pt)+1,easeOutSine:s=>Math.sin(s*pt),easeInOutSine:s=>-.5*(Math.cos(ot*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=>yn(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=>yn(s)?s:Cr(s,.075,.3),easeOutElastic:s=>yn(s)?s:_r(s,.075,.3),easeInOutElastic(s){return yn(s)?s:s<.5?.5*Cr(s*2,.1125,.45):.5+.5*_r(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-Ze.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?Ze.easeInBounce(s*2)*.5:Ze.easeOutBounce(s*2-1)*.5+.5};ud=["x","y","borderWidth","radius","tension"],fd=["color","borderColor","backgroundColor"];Sr=new Map;$r={values(s){return ht(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=bd(s,e)}let r=ae(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),os(s,n,l)},logarithmic(s,t,e){if(s===0)return"0";let n=e[t].significand||s/Math.pow(10,Math.floor(ae(s)));return[1,2,3,5,10,15].includes(n)||t>.8*e.length?$r.numeric.call(this,s,t,e):""}};rs={formatters:$r};ve=Object.create(null),Ln=Object.create(null);_i=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)=>xi(i.backgroundColor),this.hoverBorderColor=(n,i)=>xi(i.borderColor),this.hoverColor=(n,i)=>xi(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 Ci(this,t,e)}get(t){return As(this,t)}describe(t,e){return Ci(Ln,t,e)}override(t,e){return Ci(ve,t,e)}route(t,e,n,i){let o=As(this,t),r=As(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):Z(l,c)},set(l){this[a]=l}}})}apply(t){t.forEach(e=>e(this))}},ft=new _i({_scriptable:s=>!s.startsWith("on"),_indexable:s=>s!=="events",hover:{_fallback:"interaction"},interaction:{_scriptable:!1,_indexable:!1}},[gd,pd,vd]);Sd=/^(normal|(\d+(?:\.\d+)?)(px|em|%)?)$/,Ed=/^(normal|italic|initial|inherit|unset|(oblique( -?[0-9]?[0-9]deg)?))$/;wd=s=>+s||0;Md=(s,t)=>s?s+wn(t):t,zi=(s,t)=>et(t)&&s!=="adapters"&&(Object.getPrototypeOf(t)===null||t.constructor===Object);Ad=(s,t)=>s===!0?t:typeof s=="string"?le(t,s):void 0;Id=Number.EPSILON||1e-14,ts=(s,t)=>ts==="x"?"y":"x";In=s=>s.ownerDocument.defaultView.getComputedStyle(s,null);Wd=["top","right","bottom","left"];jd=(s,t,e)=>(s>0||t>0)&&(!e||!e.shadowRoot);be=s=>Math.round(s*10)/10;Jr=function(){let s=!1;try{let t={get passive(){return s=!0,!1}};On()&&(window.addEventListener("test",null,t),window.removeEventListener("test",null,t))}catch(t){}return s}();Yd=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}}},Gd=function(){return{x(s){return s},setWidth(s){},textAlign(s){return s},xPlus(s,t){return s+t},leftForLtr(s,t){return s}}}});var Nl={};Eo(Nl,{Animation:()=>Un,Animations:()=>js,ArcElement:()=>Se,BarController:()=>Ve,BarElement:()=>We,BasePlatform:()=>Us,BasicPlatform:()=>Kn,BubbleController:()=>Ne,CategoryScale:()=>us,Chart:()=>se,Colors:()=>El,DatasetController:()=>Lt,Decimation:()=>wl,DomPlatform:()=>Gn,DoughnutController:()=>ne,Element:()=>Pt,Filler:()=>Dl,Interaction:()=>ll,Legend:()=>Ll,LineController:()=>Be,LineElement:()=>Kt,LinearScale:()=>fs,LogarithmicScale:()=>gs,PieController:()=>ds,PointElement:()=>$e,PolarAreaController:()=>ke,RadarController:()=>He,RadialLinearScale:()=>Ee,Scale:()=>De,ScatterController:()=>ze,SubTitle:()=>Pl,Ticks:()=>rs,TimeScale:()=>Me,TimeSeriesScale:()=>ps,Title:()=>Al,Tooltip:()=>Ol,_adapters:()=>al,_detectPlatform:()=>fl,animator:()=>ee,controllers:()=>rl,defaults:()=>ft,elements:()=>Cl,layouts:()=>St,plugins:()=>Fl,registerables:()=>eg,registry:()=>Ut,scales:()=>Vl});function sh(s,t){let e=[],n=Object.keys(t);for(let i=0;i0||!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=ah(o,r,n),h=t.length,u;for(let f=0;fe[n].axis===t).shift()}function dh(s,t){return ce(s,{active:!1,dataset:void 0,datasetIndex:t,index:t,mode:"default",type:"dataset"})}function hh(s,t,e){return ce(s,{active:!1,dataIndex:t,parsed:void 0,raw:void 0,element:e,index:t,mode:"default",type:"data"})}function Is(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 fh(s,t){if(!s._cache.$bar){let e=s.getMatchingVisibleMetas(t),n=[];for(let i=0,o=e.length;ii-o))}return s._cache.$bar}function gh(s){let t=s.iScale,e=fh(t,s.type),n=t._length,i,o,r,a,l=()=>{r===32767||r===-32768||(ss(a)&&(n=Math.min(n,Math.abs(r-a)||n)),a=r)};for(i=0,o=e.length;i0?i[s-1]:null,a=sMath.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 ol(s,t,e,n){return ht(s)?bh(s,t,e,n):t[e.axis]=e.parse(s,n),t}function ha(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=e?1:-1)}function yh(s){let t,e,n,i,o;return s.horizontal?(t=s.base>s.x,e="left",n="right"):(t=s.baseis(C,a,l,!0)?1:Math.max(w,w*e,S,S*e),g=(C,w,S)=>is(C,a,l,!0)?-1:Math.min(w,w*e,S,S*e),p=f(0,c,h),m=f(pt,d,u),b=g(ot,c,h),x=g(ot+pt,d,u);n=(p-b)/2,i=(m-x)/2,o=-(p+b)/2,r=-(m+x)/2}return{ratioX:n,ratioY:i,offsetX:o,offsetY:r}}function Fe(){throw new Error("This method is not implemented: Check that a complete date adapter is provided.")}function Eh(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?Ir:Xt;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 qs(s,t,e,n,i){let o=s.getSortedVisibleDatasetMetas(),r=e[t];for(let a=0,l=o.length;a{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 Vs(s,t){return s.filter(e=>e.pos===t)}function pa(s,t){return s.filter(e=>cl.indexOf(e.pos)===-1&&e.box.axis===t)}function Ns(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 Dh(s){let t=[],e,n,i,o,r,a;for(e=0,n=(s||[]).length;ec.box.fullSize),!0),n=Ns(Vs(t,"left"),!0),i=Ns(Vs(t,"right")),o=Ns(Vs(t,"top"),!0),r=Ns(Vs(t,"bottom")),a=pa(t,"x"),l=pa(t,"y");return{fullSize:e,leftAndTop:n.concat(o),rightAndBottom:i.concat(l).concat(r).concat(a),chartArea:Vs(t,"chartArea"),vertical:n.concat(i).concat(l),horizontal:o.concat(r).concat(a)}}function ma(s,t,e,n){return Math.max(s[e],t[e])+Math.max(s[n],t[n])}function dl(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 Ph(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&&dl(r,o.getPadding());let a=Math.max(0,t.outerWidth-ma(r,s,"left","right")),l=Math.max(0,t.outerHeight-ma(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 Rh(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 Oh(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{let r=!1;for(let a of o)r=r||Yn(a.addedNodes,n),r=r&&!Yn(a.removedNodes,n);r&&e()});return i.observe(document,{childList:!0,subtree:!0}),i}function zh(s,t,e){let n=s.canvas,i=new MutationObserver(o=>{let r=!1;for(let a of o)r=r||Yn(a.removedNodes,n),r=r&&!Yn(a.addedNodes,n);r&&e()});return i.observe(document,{childList:!0,subtree:!0}),i}function ul(){let s=window.devicePixelRatio;s!==ya&&(ya=s,Ks.forEach((t,e)=>{e.currentDevicePixelRatio!==s&&t()}))}function $h(s,t){Ks.size||window.addEventListener("resize",ul),Ks.set(s,t)}function Wh(s){Ks.delete(s),Ks.size||window.removeEventListener("resize",ul)}function jh(s,t,e){let n=s.canvas,i=n&&Fn(n);if(!i)return;let o=Pi((a,l)=>{let c=i.clientWidth;e(a,l),c{let l=a[0],c=l.contentRect.width,d=l.contentRect.height;c===0&&d===0||o(c,d)});return r.observe(i),$h(s,o),r}function no(s,t,e){e&&e.disconnect(),t==="resize"&&Wh(s)}function Uh(s,t,e){let n=s.canvas,i=Pi(o=>{s.ctx!==null&&e(Bh(o,s))},s);return Vh(n,t,i),i}function fl(s){return!On()||typeof OffscreenCanvas!="undefined"&&s instanceof OffscreenCanvas?Kn:Gn}function Kh(s,t){let e=s.options.ticks,n=Yh(s),i=Math.min(e.maxTicksLimit||n,n),o=e.major.enabled?qh(t):[],r=o.length,a=o[0],l=o[r-1],c=[];if(r>i)return Xh(t,c,o,r/i),c;let d=Gh(o,t,i);if(r>0){let h,u,f=r>1?Math.round((l-a)/(r-1)):null;for(Nn(t,c,d,tt(f)?0:a-f,a),h=0,u=r-1;hi)return l}return Math.max(i,1)}function qh(s){let t=[],e,n;for(e=0,n=s.length;er+a)))return l}function tu(s,t){at(s,e=>{let n=e.gc,i=n.length/2,o;if(i>t){for(o=0;o{let n=e.split("."),i=n.pop(),o=[s].concat(n).join("."),r=t[e].split("."),a=r.pop(),l=r.join(".");ft.route(o,i,l,a)})}function au(s){return"id"in s&&"defaults"in s}function lu(s){let t={},e=[],n=Object.keys(Ut.plugins.items);for(let o=0;o1&&Ea(s[0].toLowerCase());if(n)return n}throw new Error(`Cannot determine type of '${s}' axis. Please provide 'axis' or 'position' option.`)}function ka(s,t,e){if(e[t+"AxisID"]===s)return{axis:t}}function pu(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 ka(s,"x",e[0])||ka(s,"y",e[0])}return{}}function mu(s,t){let e=ve[s.type]||{scales:{}},n=t.scales||{},i=fo(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=go(r,a,pu(r,s),ft.scales[a.type]),c=fu(l,i),d=e.scales||{};o[r]=es(Object.create(null),[{axis:l},a,d[l],d[c]])}),s.data.datasets.forEach(r=>{let a=r.type||s.type,l=r.indexAxis||fo(a,t),d=(ve[a]||{}).scales||{};Object.keys(d).forEach(h=>{let u=uu(h,l),f=r[u+"AxisID"]||u;o[f]=o[f]||Object.create(null),es(o[f],[{axis:u},n[f],d[h]])})}),Object.keys(o).forEach(r=>{let a=o[r];es(a,[ft.scales[a.type],ft.scale])}),o}function gl(s){let t=s.options||(s.options={});t.plugins=Z(t.plugins,{}),t.scales=mu(s,t)}function pl(s){return s=s||{},s.datasets=s.datasets||[],s.labels=s.labels||[],s}function bu(s){return s=s||{},s.data=pl(s.data),gl(s),s}function Bn(s,t){let e=wa.get(s);return e||(e=t(),wa.set(s,e),ml.add(e)),e}function Ma(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:Rn(t,e),subPrefixes:e.filter(a=>!a.toLowerCase().includes("hover"))},n.set(i,o)),o}function yu(s,t){let{isScriptable:e,isIndexable:n}=Hi(s);for(let i of t){let o=e(i),r=n(i),a=(r||o)&&s[i];if(o&&(re(a)||vu(a))||r&&ht(a))return!0}return!1}function Da(s,t){return s==="top"||s==="bottom"||Cu.indexOf(s)===-1&&t==="x"}function Ta(s,t){return function(e,n){return e[s]===n[s]?e[t]-n[t]:e[s]-n[s]}}function La(s){let t=s.chart,e=t.options.animation;t.notifyPlugins("afterRender"),ct(e&&e.onComplete,[s],t)}function _u(s){let t=s.chart,e=t.options.animation;ct(e&&e.onProgress,[s],t)}function bl(s){return On()&&typeof s=="string"?s=document.getElementById(s):s&&s.length&&(s=s[0]),s&&s.canvas&&(s=s.canvas),s}function Su(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 Eu(s,t,e,n){return!e||s.type==="mouseout"?null:n?t:s}function Pa(){return at(se.instances,s=>s._plugins.invalidate())}function ku(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,xt(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,xt(n-e));s.arc(i,o,a+c/2,e-u/2,n+u/2,!0)}else{let u=Math.min(c/2,r*xt(n-e));if(d==="round")s.arc(i,o,u,e-ot/2,n+ot/2,!0);else if(d==="bevel"){let f=2*u*u,g=-f*Math.cos(e+ot/2)+i,p=-f*Math.sin(e+ot/2)+o,m=f*Math.cos(n+ot/2)+i,b=f*Math.sin(n+ot/2)+o;s.lineTo(g,p),s.lineTo(m,b)}}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+pt,n-pt),s.closePath(),s.clip()}function Mu(s){return Pn(s,["outerStart","outerEnd","innerStart","innerEnd"])}function Du(s,t,e,n){let i=Mu(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 bt(l,0,Math.min(o,c))};return{outerStart:a(i.outerStart),outerEnd:a(i.outerEnd),innerStart:bt(i.innerStart,0,r),innerEnd:bt(i.innerEnd,0,r)}}function cs(s,t,e,n){return{x:e+s*Math.cos(t),y:n+s*Math.sin(t)}}function qn(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 A=d>0?d-n:0,N=h>0?h-n:0,O=(A+N)/2,j=O!==0?g*O/(O+n):g;f=(g-j)/2}let p=Math.max(.001,g*h-e/ot)/h,m=(g-p)/2,b=l+m+f,x=i-m-f,{outerStart:C,outerEnd:w,innerStart:S,innerEnd:y}=Du(t,u,h,x-b),v=h-C,_=h-w,E=b+C/v,M=x-w/_,k=u+S,L=u+y,D=b+S/k,T=x-y/L;if(s.beginPath(),o){let A=(E+M)/2;if(s.arc(r,a,h,E,A),s.arc(r,a,h,A,M),w>0){let z=cs(_,M,r,a);s.arc(z.x,z.y,w,M,x+pt)}let N=cs(L,x,r,a);if(s.lineTo(N.x,N.y),y>0){let z=cs(L,T,r,a);s.arc(z.x,z.y,y,x+pt,T+Math.PI)}let O=(x-y/u+(b+S/u))/2;if(s.arc(r,a,u,x-y/u,O,!0),s.arc(r,a,u,O,b+S/u,!0),S>0){let z=cs(k,D,r,a);s.arc(z.x,z.y,S,D+Math.PI,b-pt)}let j=cs(v,b,r,a);if(s.lineTo(j.x,j.y),C>0){let z=cs(v,E,r,a);s.arc(z.x,z.y,C,b-pt,E)}}else{s.moveTo(r,a);let A=Math.cos(E)*h+r,N=Math.sin(E)*h+a;s.lineTo(A,N);let O=Math.cos(M)*h+r,j=Math.sin(M)*h+a;s.lineTo(O,j)}s.closePath()}function Tu(s,t,e,n,i){let{fullCircles:o,startAngle:r,circumference:a}=t,l=t.endAngle;if(o){qn(s,t,e,n,l,i);for(let c=0;c=ot&&f===0&&d!=="miter"&&ku(s,t,p),o||(qn(s,t,e,n,p,i),s.stroke())}function vl(s,t,e=t){s.lineCap=Z(e.borderCapStyle,t.borderCapStyle),s.setLineDash(Z(e.borderDash,t.borderDash)),s.lineDashOffset=Z(e.borderDashOffset,t.borderDashOffset),s.lineJoin=Z(e.borderJoinStyle,t.borderJoinStyle),s.lineWidth=Z(e.borderWidth,t.borderWidth),s.strokeStyle=Z(e.borderColor,t.borderColor)}function Au(s,t,e){s.lineTo(e.x,e.y)}function Pu(s){return s.stepped?jr:s.tension||s.cubicInterpolationMode==="monotone"?Ur:Au}function yl(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=ia&&o>a;return{count:n,start:l,loop:t.loop,ilen:c(r+(c?a-w:w))%o,C=()=>{p!==m&&(s.lineTo(d,m),s.lineTo(d,p),s.lineTo(d,b))};for(l&&(f=i[x(0)],s.moveTo(f.x,f.y)),u=0;u<=a;++u){if(f=i[x(u)],f.skip)continue;let w=f.x,S=f.y,y=w|0;y===g?(Sm&&(m=S),d=(h*d+w)/++h):(C(),s.lineTo(w,S),g=y,h=0,p=m=S),b=S}C()}function mo(s){let t=s.options,e=t.borderDash&&t.borderDash.length;return!s._decimated&&!s._loop&&!t.tension&&t.cubicInterpolationMode!=="monotone"&&!t.stepped&&!e?Ou:Ru}function Fu(s){return s.stepped?ta:s.tension||s.cubicInterpolationMode==="monotone"?ea:me}function Iu(s,t,e,n){let i=t._path;i||(i=t._path=new Path2D,t.path(i,e,n)&&i.closePath()),vl(s,t.options),s.stroke(i)}function Vu(s,t,e,n){let{segments:i,options:o}=t,r=mo(t);for(let a of i)vl(s,o,a.style),s.beginPath(),r(s,t,a,{start:e,end:e+n-1})&&s.closePath(),s.stroke()}function Bu(s,t,e,n){Nu&&!t.options.segment?Iu(s,t,e,n):Vu(s,t,e,n)}function Ra(s,t,e,n){let i=s.options,{[e]:o}=s.getProps([e],n);return Math.abs(t-o)_l(t++)),t}function Yu(s,t){return s.backgroundColor=s.data.map(()=>Sl(t++)),t}function Gu(s){let t=0;return(e,n)=>{let i=s.getDatasetMeta(n).controller;i instanceof ne?t=Ku(e,t):i instanceof ke?t=Yu(e,t):i&&(t=Uu(e,t))}}function Fa(s){let t;for(t in s)if(s[t].borderColor||s[t].backgroundColor)return!0;return!1}function qu(s){return s&&(s.borderColor||s.backgroundColor)}function Xu(){return ft.borderColor!=="rgba(0,0,0,0.1)"||ft.backgroundColor!=="rgba(0,0,0,0.1)"}function Qu(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;hf&&(f=g,u=s[x],p=x);r[l++]=u,d=p}return r[l++]=s[c],r}function Zu(s,t,e,n){let i=0,o=0,r,a,l,c,d,h,u,f,g,p,m=[],b=t+e-1,x=s[t].x,w=s[b].x-x;for(r=t;rp&&(p=c,u=r),i=(o*i+a.x)/++o;else{let y=r-1;if(!tt(h)&&!tt(u)){let v=Math.min(h,u),_=Math.max(h,u);v!==f&&v!==y&&m.push({...s[v],x:i}),_!==f&&_!==y&&m.push({...s[_],x:i})}r>0&&y!==f&&m.push(s[y]),m.push(a),d=S,o=0,g=p=c,h=u=f=r}}return m}function kl(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 Ia(s){s.data.datasets.forEach(t=>{kl(t)})}function Ju(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=bt(Xt(t,o.axis,r).lo,0,e-1)),c?i=bt(Xt(t,o.axis,a).hi+1,n,e)-n:i=e-n,{start:n,count:i}}function tf(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=Zn(l,c,i);let d=vo(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=qi(t,d);for(let u of h){let f=vo(e,o[u.start],o[u.end],u.loop),g=Gi(a,i,f);for(let p of g)r.push({source:p,target:u,start:{[e]:Va(d,f,"start",Math.max)},end:{[e]:Va(d,f,"end",Math.min)}})}}return r}function vo(s,t,e,n){if(n)return;let i=t[s],o=e[s];return s==="angle"&&(i=xt(i),o=xt(o)),{property:s,start:i,end:o}}function ef(s,t){let{x:e=null,y:n=null}=s||{},i=t.points,o=[];return t.segments.forEach(({start:r,end:a})=>{a=Zn(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 Zn(s,t,e){for(;t>s;t--){let n=e[t];if(!isNaN(n.x)&&!isNaN(n.y))break}return t}function Va(s,t,e,n){return s&&t?n(s[e],t[e]):s?s[e]:t?t[e]:0}function Ml(s,t){let e=[],n=!1;return ht(s)?(n=!0,e=s):e=ef(s,t),e.length?new Kt({points:e,options:{tension:0},_loop:n,_fullLoop:n}):null}function Na(s){return s&&s.fill!==!1}function sf(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 nf(s,t,e){let n=lf(s);if(et(n))return isNaN(n.value)?!1:n;let i=parseFloat(n);return gt(i)&&Math.floor(i)===i?of(n[0],t,i,e):["origin","start","end","stack","shape"].indexOf(n)>=0&&n}function of(s,t,e,n){return(s==="-"||s==="+")&&(e=t+e),e===t||e<0||e>=n?!1:e}function rf(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 af(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 lf(s){let t=s.options,e=t.fill,n=Z(e&&e.target,e);return n===void 0&&(n=!!t.backgroundColor),n===!1||n===null?!1:n===!0?"origin":n}function cf(s){let{scale:t,index:e,line:n}=s,i=[],o=n.segments,r=n.points,a=df(t,e);a.push(Ml({x:null,y:t.bottom},n));for(let l=0;lo.length>r.length?o:r)),t+e.size/2+n.measureText(i).width}function Sf(s,t,e){let n=s;return typeof t.text!="string"&&(n=Tl(t,e)),n}function Tl(s,t){let e=s.text?s.text.length:0;return t*e}function Ef(s,t){return!!((s==="mousemove"||s==="mouseout")&&(t.onHover||t.onLeave)||t.onClick&&(s==="click"||s==="mouseup"))}function kf(s,t){let e=new Ys({ctx:s.ctx,options:t,chart:s});St.configure(s,e,t),St.addBox(s,e),s.titleBlock=e}function te(s,t){return t&&(ht(t)?Array.prototype.push.apply(s,t):s.push(t)),s}function de(s){return(typeof s=="string"||s instanceof String)&&s.indexOf(` +`);var O=0,j=!1;this.parse=function(z,K,$){if(typeof z!="string")throw new Error("Input must be a string");var X=z.length,Z=v.length,R=_.length,F=E.length,P=S(M),H=[],I=[],V=[],q=O=0;if(!z)return it();if(L||L!==!1&&z.indexOf(A)===-1){for(var B=z.split(_),Y=0;Y=k)return it(!0);break}I.push({type:"Quotes",code:"InvalidQuotes",message:"Trailing quote on quoted field is malformed",row:H.length,index:O}),J++}}else if(E&&V.length===0&&z.substring(O,O+F)===E){if(G===-1)return it();O=G+R,G=z.indexOf(_,O),U=z.indexOf(v,O)}else if(U!==-1&&(U=k)return it(!0)}return Ft();function lt(yt){H.push(yt),q=O}function Ot(yt){var wt=0;return wt=yt!==-1&&(yt=z.substring(J+1,yt))&&yt.trim()===""?yt.length:wt}function Ft(yt){return $||(yt===void 0&&(yt=z.substring(O)),V.push(yt),O=X,lt(V),P&&vt()),it()}function dt(yt){O=yt,lt(V),V=[],G=z.indexOf(_,O)}function it(yt){if(y.header&&!K&&H.length&&!T){var wt=H[0],ie=Object.create(null),ii=new Set(wt);let wo=!1;for(let je=0;jeE.charCodeAt(0)!==65279?E:E.slice(1))(y),_=new(v.download?c:h)(v)):y.readable===!0&&S(y.read)&&S(y.on)?_=new u(v):(t.File&&y instanceof File||y instanceof Object)&&(_=new d(v)),_.stream(y);(_=(()=>{var E;return!!a.WORKERS_SUPPORTED&&(E=(()=>{var M=t.URL||t.webkitURL||null,k=s.toString();return a.BLOB_URL||(a.BLOB_URL=M.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"})))})(),(E=new t.Worker(E)).onmessage=m,E.id=r++,o[E.id]=E)})()).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:y,config:v,workerId:_.id})},a.unparse=function(y,v){var _=!1,E=!0,M=",",k=`\r +`,L='"',D=L+L,T=!1,A=null,N=!1,O=((()=>{if(typeof v=="object"){if(typeof v.delimiter!="string"||a.BAD_DELIMITERS.filter(function(K){return v.delimiter.indexOf(K)!==-1}).length||(M=v.delimiter),typeof v.quotes!="boolean"&&typeof v.quotes!="function"&&!Array.isArray(v.quotes)||(_=v.quotes),typeof v.skipEmptyLines!="boolean"&&typeof v.skipEmptyLines!="string"||(T=v.skipEmptyLines),typeof v.newline=="string"&&(k=v.newline),typeof v.quoteChar=="string"&&(L=v.quoteChar),typeof v.header=="boolean"&&(E=v.header),Array.isArray(v.columns)){if(v.columns.length===0)throw new Error("Option columns is empty");A=v.columns}v.escapeChar!==void 0&&(D=v.escapeChar+L),v.escapeFormulae instanceof RegExp?N=v.escapeFormulae:typeof v.escapeFormulae=="boolean"&&v.escapeFormulae&&(N=/^[=+\-@\t\r].*$/)}})(),new RegExp(g(L),"g"));if(typeof y=="string"&&(y=JSON.parse(y)),Array.isArray(y)){if(!y.length||Array.isArray(y[0]))return j(null,y,T);if(typeof y[0]=="object")return j(A||Object.keys(y[0]),y,T)}else if(typeof y=="object")return typeof y.data=="string"&&(y.data=JSON.parse(y.data)),Array.isArray(y.data)&&(y.fields||(y.fields=y.meta&&y.meta.fields||A),y.fields||(y.fields=Array.isArray(y.data[0])?y.fields:typeof y.data[0]=="object"?Object.keys(y.data[0]):[]),Array.isArray(y.data[0])||typeof y.data[0]=="object"||(y.data=[y.data])),j(y.fields||[],y.data||[],T);throw new Error("Unable to serialize unrecognized input");function j(K,$,X){var Z="",R=(typeof K=="string"&&(K=JSON.parse(K)),typeof $=="string"&&($=JSON.parse($)),Array.isArray(K)&&0{for(var P=0;Pe-n*Math.max(Math.min(r-3,9-r,1),-1);return[i(0),i(8),i(4)]}function Yc(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 Gc(s,t,e){let n=yr(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 qc(s,t,e,n,i){return s===i?(t-e)/n+(t.5?d/(2-o-r):d/(o+r),l=qc(e,n,i,d,o),l=l*60+.5),[l|0,c||0,a]}function _i(s,t,e,n){return(Array.isArray(t)?s(t[0],t[1],t[2]):s(t,e,n)).map(pe)}function Si(s,t,e){return _i(yr,s,t,e)}function Xc(s,t,e){return _i(Gc,s,t,e)}function Qc(s,t,e){return _i(Yc,s,t,e)}function xr(s){return(s%360+360)%360}function Zc(s){let t=Kc.exec(s),e=255,n;if(!t)return;t[5]!==n&&(e=t[6]?Rs(+t[5]):pe(+t[5]));let i=xr(+t[2]),o=+t[3]/100,r=+t[4]/100;return t[1]==="hwb"?n=Xc(i,o,r):t[1]==="hsv"?n=Qc(i,o,r):n=Si(i,o,r),{r:n[0],g:n[1],b:n[2],a:e}}function Jc(s,t){var e=Ci(s);e[0]=xr(e[0]+t),e=Si(e),s.r=e[0],s.g=e[1],s.b=e[2]}function td(s){if(!s)return;let t=Ci(s),e=t[0],n=pr(t[1]),i=pr(t[2]);return s.a<255?`hsla(${e}, ${n}%, ${i}%, ${oe(s.a)})`:`hsl(${e}, ${n}%, ${i}%)`}function ed(){let s={},t=Object.keys(br),e=Object.keys(mr),n,i,o,r,a;for(n=0;n>16&255,o>>8&255,o&255]}return s}function sd(s){xn||(xn=ed(),xn.transparent=[0,0,0,0]);let t=xn[s.toLowerCase()];return t&&{r:t[0],g:t[1],b:t[2],a:t.length===4?t[3]:255}}function id(s){let t=nd.exec(s),e=255,n,i,o;if(t){if(t[7]!==n){let r=+t[7];e=t[8]?Rs(r):ge(r*255,0,255)}return n=+t[1],i=+t[3],o=+t[5],n=255&(t[2]?Rs(n):ge(n,0,255)),i=255&(t[4]?Rs(i):ge(i,0,255)),o=255&(t[6]?Rs(o):ge(o,0,255)),{r:n,g:i,b:o,a:e}}}function od(s){return s&&(s.a<255?`rgba(${s.r}, ${s.g}, ${s.b}, ${oe(s.a)})`:`rgb(${s.r}, ${s.g}, ${s.b})`)}function rd(s,t,e){let n=es(oe(s.r)),i=es(oe(s.g)),o=es(oe(s.b));return{r:pe(yi(n+e*(es(oe(t.r))-n))),g:pe(yi(i+e*(es(oe(t.g))-i))),b:pe(yi(o+e*(es(oe(t.b))-o))),a:s.a+e*(t.a-s.a)}}function Cn(s,t,e){if(s){let n=Ci(s);n[t]=Math.max(0,Math.min(n[t]+n[t]*e,t===0?360:1)),n=Si(n),s.r=n[0],s.g=n[1],s.b=n[2]}}function Cr(s,t){return s&&Object.assign(t||{},s)}function vr(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=pe(s[3]))):(t=Cr(s,{r:0,g:0,b:0,a:1}),t.a=pe(t.a)),t}function ad(s){return s.charAt(0)==="r"?id(s):Zc(s)}var ge,zt,xi,Hc,zc,yn,$c,jc,Kc,mr,br,xn,nd,yi,es,Ps,_r=oi(()=>{ge=(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},xi=[..."0123456789ABCDEF"],Hc=s=>xi[s&15],zc=s=>xi[(s&240)>>4]+xi[s&15],yn=s=>(s&240)>>4===(s&15),$c=s=>yn(s.r)&&yn(s.g)&&yn(s.b)&&yn(s.a);jc=(s,t)=>s<255?t(s):"";Kc=/^(hsla?|hwb|hsv)\(\s*([-+.e\d]+)(?:deg)?[\s,]+([-+.e\d]+)%[\s,]+([-+.e\d]+)%(?:[\s,]+([-+.e\d]+)(%)?)?\s*\)$/;mr={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"},br={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"};nd=/^rgba?\(\s*([-+.\d]+)(%)?[\s,]+([-+.e\d]+)(%)?[\s,]+([-+.e\d]+)(%)?(?:[\s,/]+([-+.e\d]+)(%)?)?\s*\)$/;yi=s=>s<=.0031308?s*12.92:Math.pow(s,1/2.4)*1.055-.055,es=s=>s<=.04045?s/12.92:Math.pow((s+.055)/1.055,2.4);Ps=class s{constructor(t){if(t instanceof s)return t;let e=typeof t,n;e==="object"?n=vr(t):e==="string"&&(n=Wc(t)||sd(t)||ad(t)),this._rgb=n,this._valid=!!n}get valid(){return this._valid}get rgb(){var t=Cr(this._rgb);return t&&(t.a=oe(t.a)),t}set rgb(t){this._rgb=vr(t)}rgbString(){return this._valid?od(this._rgb):void 0}hexString(){return this._valid?Uc(this._rgb):void 0}hslString(){return this._valid?td(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=rd(this._rgb,t._rgb,e)),this}clone(){return new s(this.rgb)}alpha(t){return this._rgb.a=pe(t),this}clearer(t){let e=this._rgb;return e.a*=1-t,this}greyscale(){let t=this._rgb,e=Os(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 Cn(this._rgb,2,t),this}darken(t){return Cn(this._rgb,2,-t),this}saturate(t){return Cn(this._rgb,1,t),this}desaturate(t){return Cn(this._rgb,1,-t),this}rotate(t){return Jc(this._rgb,t),this}}});function Zt(){}function tt(s){return s==null}function ht(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 Dt(s,t){return gt(s)?s:t}function Q(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 at(s,t,e,n){let i,o,r;if(ht(s))if(o=s.length,n)for(i=o-1;i>=0;i--)t.call(e,s[i],i);else for(i=0;i{for(let n of t){if(n==="")break;e=e&&e[n]}return e}}function le(s,t){return(Sr[t]||(Sr[t]=hd(t)))(s)}function Tn(s){return s.charAt(0).toUpperCase()+s.slice(1)}function Ir(s){return s.type==="mouseup"||s.type==="click"||s.type==="contextmenu"}function as(s,t,e){return Math.abs(s-t)i-o).pop(),t}function gd(s){return typeof s=="symbol"||typeof s=="object"&&s!==null&&!(Symbol.toPrimitive in s||"toString"in s||"valueOf"in s)}function Pe(s){return!gd(s)&&!isNaN(parseFloat(s))&&isFinite(s)}function Nr(s,t){let e=Math.round(s);return e-t<=s&&e+t>=s}function Li(s,t,e){let n,i,o;for(n=0,i=s.length;nl&&c=Math.min(t,e)-n&&s<=Math.max(t,e)+n}function An(s,t,e){e=e||(r=>s[r]1;)o=i+n>>1,e(o)?i=o:n=o;return{lo:i,hi:n}}function zr(s,t,e){let n=0,i=s.length;for(;nn&&s[i-1]>e;)i--;return n>0||i{let n="_onData"+Tn(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 Pi(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)&&($r.forEach(o=>{delete s[o]}),delete s._chartjs)}function Oi(s){let t=new Set(s);return t.size===s.length?s:Array.from(t)}function Ii(s,t){let e=[],n=!1;return function(...i){e=i,n||(n=!0,Fi.call(window,()=>{n=!1,s.apply(t,e)}))}}function jr(s,t){let e;return function(...n){return t?(clearTimeout(e),e=setTimeout(s,t,n)):s.apply(this,n),t}}function Vi(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(Xt(l,d,h).lo,e?n:Xt(t,d,r.getPixelForValue(h)).lo),c){let p=l.slice(0,i+1).reverse().findIndex(m=>!tt(m[a.axis]));i-=Math.max(0,p)}i=bt(i,0,n-1)}if(g){let p=Math.max(Xt(l,r.axis,u,!0).hi+1,e?0:Xt(t,d,r.getPixelForValue(u),!0).hi+1);if(c){let m=l.slice(p-1).findIndex(b=>!tt(b[a.axis]));p+=Math.max(0,m)}o=bt(p,i,n)-i}else o=n-i}return{start:i,count:o}}function Ni(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 Bi(s){if(s&&typeof s=="object"){let t=s.toString();return t==="[object CanvasPattern]"||t==="[object CanvasGradient]"}return!1}function Hi(s){return Bi(s)?s:new Ps(s)}function Ei(s){return Bi(s)?s:new Ps(s).saturate(.5).darken(.1).hexString()}function vd(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:bd},numbers:{type:"number",properties:md}}),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 yd(s){s.set("layout",{autoPadding:!0,padding:{top:0,right:0,bottom:0,left:0}})}function xd(s,t){t=t||{};let e=s+JSON.stringify(t),n=Mr.get(e);return n||(n=new Intl.NumberFormat(s,t),Mr.set(e,n)),n}function cs(s,t,e){return xd(t,e).format(s)}function Cd(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 _d(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:ds.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 Fs(s,t){if(!t)return s;let e=t.split(".");for(let n=0,i=e.length;nn&&(n=o),n}function Yr(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;le.length){for(l=0;l0&&s.stroke()}}function Qt(s,t,e){return e=e||.5,!t||s&&s.x>t.left-e&&s.xt.top-e&&s.y0&&o.strokeColor!=="",l,c;for(s.save(),s.font=i.string,Ed(s,o),l=0;lQ(s[r],s[t[r]]):r=>s[r]:()=>s;for(let r of i)e[r]=Ld(o(r));return e}function Wi(s){return Fn(s,{top:"y",right:"x",bottom:"y",left:"x"})}function Ce(s){return Fn(s,["topLeft","topRight","bottomLeft","bottomRight"])}function _t(s){let t=Wi(s);return t.width=t.left+t.right,t.height=t.top+t.bottom,t}function mt(s,t){s=s||{},t=t||ft.font;let e=Q(s.size,t.size);typeof e=="string"&&(e=parseInt(e,10));let n=Q(s.style,t.style);n&&!(""+n).match(Dd)&&(console.warn('Invalid font style specified: "'+n+'"'),n=void 0);let i={family:Q(s.family,t.family),lineHeight:Td(Q(s.lineHeight,t.lineHeight),e),size:e,style:n,weight:Q(s.weight,t.weight),string:""};return i.string=Sd(i),i}function us(s,t,e,n){let i=!0,o,r,a;for(o=0,r=s.length;oe&&a===0?0:a+l;return{min:r(n,-Math.abs(o)),max:r(i,o)}}function ce(s,t){return Object.assign(Object.create(s),t)}function In(s,t=[""],e,n,i=()=>s[0]){let o=e||s;typeof n=="undefined"&&(n=Jr("_fallback",s));let r={[Symbol.toStringTag]:"Object",_cacheable:!0,_scopes:s,_rootScopes:o,_fallback:n,_getTarget:i,override:a=>In([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 Qr(a,l,()=>Nd(l,t,s,a))},getOwnPropertyDescriptor(a,l){return Reflect.getOwnPropertyDescriptor(a._scopes[0],l)},getPrototypeOf(){return Reflect.getPrototypeOf(s[0])},has(a,l){return Tr(a).includes(l)},ownKeys(a){return Tr(a)},set(a,l,c){let d=a._storage||(a._storage=i());return a[l]=d[l]=c,delete a._keys,!0}})}function Re(s,t,e,n){let i={_cacheable:!1,_proxy:s,_context:t,_subProxy:e,_stack:new Set,_descriptors:ji(s,n),setContext:o=>Re(s,o,e,n),override:o=>Re(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 Qr(o,r,()=>Rd(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 ji(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:re(e)?e:()=>e,isIndexable:re(n)?n:()=>n}}function Qr(s,t,e){if(Object.prototype.hasOwnProperty.call(s,t)||t==="constructor")return s[t];let n=e();return s[t]=n,n}function Rd(s,t,e){let{_proxy:n,_context:i,_subProxy:o,_descriptors:r}=s,a=n[t];return re(a)&&r.isScriptable(t)&&(a=Pd(t,a,s,e)),ht(a)&&a.length&&(a=Od(t,a,s,r.isIndexable)),Ui(t,a)&&(a=Re(a,i,o&&o[t],r)),a}function Pd(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),Ui(s,l)&&(l=Ki(i._scopes,i,s,l)),l}function Od(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=Ki(c,i,s,d);t.push(Re(h,o,r&&r[s],a))}}return t}function Zr(s,t,e){return re(s)?s(t,e):s}function Id(s,t,e,n,i){for(let o of t){let r=Fd(e,o);if(r){s.add(r);let a=Zr(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 Ki(s,t,e,n){let i=t._rootScopes,o=Zr(t._fallback,e,n),r=[...s,...i],a=new Set;a.add(n);let l=Dr(a,r,e,o||e,n);return l===null||typeof o!="undefined"&&o!==e&&(l=Dr(a,r,o,l,n),l===null)?!1:In(Array.from(a),[""],i,o,()=>Vd(t,e,n))}function Dr(s,t,e,n,i){for(;e;)e=Id(s,t,e,n,i);return e}function Vd(s,t,e){let n=s._getTarget();t in n||(n[t]={});let i=n[t];return ht(i)&&et(e)?e:i||{}}function Nd(s,t,e,n){let i;for(let o of t)if(i=Jr(Ad(o,s),e),typeof i!="undefined")return Ui(s,i)?Ki(e,n,s,i):i}function Jr(s,t){for(let e of t){if(!e)continue;let n=e[s];if(typeof n!="undefined")return n}}function Tr(s){let t=s._keys;return t||(t=s._keys=Bd(s._scopes)),t}function Bd(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 Yi(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!c.skip)),t.cubicInterpolationMode==="monotone")jd(s,i);else{let c=n?s[s.length-1]:s[0];for(o=0,r=s.length;ol.height&&(d=l.height,c=be(Math.floor(d*n))),{width:c,height:d}}function Gi(s,t,e){let n=t||1,i=be(s.height*n),o=be(s.width*n);s.height=be(s.height),s.width=be(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 qi(s,t){let e=Kd(s,t),n=e&&e.match(/^(\d+)(\.\d+)?px$/);return n?+n[1]:void 0}function me(s,t,e,n){return{x:s.x+e*(t.x-s.x),y:s.y+e*(t.y-s.y)}}function ia(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 oa(s,t,e,n){let i={x:s.cp2x,y:s.cp2y},o={x:t.cp1x,y:t.cp1y},r=me(s,i,e),a=me(i,o,e),l=me(o,t,e),c=me(r,a,e),d=me(a,l,e);return me(c,d,e)}function Oe(s,t,e){return s?Qd(t,e):Zd()}function Xi(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 Qi(s,t){t!==void 0&&(delete s.prevTextDirection,s.canvas.style.setProperty("direction",t[0],t[1]))}function ra(s){return s==="angle"?{between:ls,compare:pd,normalize:xt}:{between:Jt,compare:(t,e)=>t-e,normalize:t=>t}}function Lr({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 Jd(s,t,e){let{property:n,start:i,end:o}=e,{between:r,normalize:a}=ra(n),l=t.length,{start:c,end:d,loop:h}=s,u,f;if(h){for(c+=l,d+=l,u=0,f=l;ul(i,x,b)&&a(i,x)!==0,S=()=>a(o,b)===0||l(o,x,b),y=()=>p||w(),v=()=>!p||S();for(let _=d,E=d;_<=h;++_)C=t[_%r],!C.skip&&(b=c(C[n]),b!==x&&(p=l(b,i,o),m===null&&y()&&(m=a(b,i)===0?_:E),m!==null&&v()&&(g.push(Lr({start:m,end:_,loop:u,count:r,style:f})),m=null),E=_,x=b));return m!==null&&g.push(Lr({start:m,end:h,loop:u,count:r,style:f})),g}function Ji(s,t){let e=[],n=s.segments;for(let i=0;ii&&s[o%t].skip;)o--;return o%=t,{start:i,end:o}}function eh(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 aa(s,t){let e=s.points,n=s.options.spanGaps,i=e.length;if(!i)return[];let o=!!s._loop,{start:r,end:a}=th(e,i,o,n);if(n===!0)return Ar(s,[{start:r,end:a,loop:o}],e,t);let l=a{_r();Pr=(()=>{let s=0;return()=>s++})();Or=(s,t)=>typeof s=="string"&&s.endsWith("%")?parseFloat(s)/100:+s/t,Mi=(s,t)=>typeof s=="string"&&s.endsWith("%")?parseFloat(s)/100*t:+s;Sr={"":s=>s,x:s=>s.x,y:s=>s.y};rs=s=>typeof s!="undefined",re=s=>typeof s=="function",Di=(s,t)=>{if(s.size!==t.size)return!1;for(let e of s)if(!t.has(e))return!1;return!0};ot=Math.PI,ut=2*ot,ud=ut+ot,wn=Number.POSITIVE_INFINITY,fd=ot/180,pt=ot/2,Le=ot/4,Er=ot*2/3,ae=Math.log10,jt=Math.sign;Xt=(s,t,e,n)=>An(s,e,n?i=>{let o=s[i][t];return os[i][t]An(s,e,n=>s[n][t]>=e);$r=["push","pop","shift","splice","unshift"];Fi=function(){return typeof window=="undefined"?function(s){return s()}:window.requestAnimationFrame}();Rn=s=>s==="start"?"left":s==="end"?"right":"center",Ct=(s,t,e)=>s==="start"?t:s==="end"?e:(t+e)/2,Ur=(s,t,e,n)=>s===(n?"left":"right")?e:s==="center"?(t+e)/2:t;_n=s=>s===0||s===1,kr=(s,t,e)=>-(Math.pow(2,10*(s-=1))*Math.sin((s-t)*ut/e)),wr=(s,t,e)=>Math.pow(2,-10*s)*Math.sin((s-t)*ut/e)+1,ss={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*pt)+1,easeOutSine:s=>Math.sin(s*pt),easeInOutSine:s=>-.5*(Math.cos(ot*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=>_n(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=>_n(s)?s:kr(s,.075,.3),easeOutElastic:s=>_n(s)?s:wr(s,.075,.3),easeInOutElastic(s){return _n(s)?s:s<.5?.5*kr(s*2,.1125,.45):.5+.5*wr(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-ss.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?ss.easeInBounce(s*2)*.5:ss.easeOutBounce(s*2-1)*.5+.5};md=["x","y","borderWidth","radius","tension"],bd=["color","borderColor","backgroundColor"];Mr=new Map;Kr={values(s){return ht(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=Cd(s,e)}let r=ae(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),cs(s,n,l)},logarithmic(s,t,e){if(s===0)return"0";let n=e[t].significand||s/Math.pow(10,Math.floor(ae(s)));return[1,2,3,5,10,15].includes(n)||t>.8*e.length?Kr.numeric.call(this,s,t,e):""}};ds={formatters:Kr};ve=Object.create(null),Pn=Object.create(null);wi=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)=>Ei(i.backgroundColor),this.hoverBorderColor=(n,i)=>Ei(i.borderColor),this.hoverColor=(n,i)=>Ei(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 ki(this,t,e)}get(t){return Fs(this,t)}describe(t,e){return ki(Pn,t,e)}override(t,e){return ki(ve,t,e)}route(t,e,n,i){let o=Fs(this,t),r=Fs(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):Q(l,c)},set(l){this[a]=l}}})}apply(t){t.forEach(e=>e(this))}},ft=new wi({_scriptable:s=>!s.startsWith("on"),_indexable:s=>s!=="events",hover:{_fallback:"interaction"},interaction:{_scriptable:!1,_indexable:!1}},[vd,yd,_d]);Md=/^(normal|(\d+(?:\.\d+)?)(px|em|%)?)$/,Dd=/^(normal|italic|initial|inherit|unset|(oblique( -?[0-9]?[0-9]deg)?))$/;Ld=s=>+s||0;Ad=(s,t)=>s?s+Tn(t):t,Ui=(s,t)=>et(t)&&s!=="adapters"&&(Object.getPrototypeOf(t)===null||t.constructor===Object);Fd=(s,t)=>s===!0?t:typeof s=="string"?le(t,s):void 0;Hd=Number.EPSILON||1e-14,is=(s,t)=>ts==="x"?"y":"x";Bn=s=>s.ownerDocument.defaultView.getComputedStyle(s,null);Yd=["top","right","bottom","left"];Gd=(s,t,e)=>(s>0||t>0)&&(!e||!e.shadowRoot);be=s=>Math.round(s*10)/10;na=function(){let s=!1;try{let t={get passive(){return s=!0,!1}};Vn()&&(window.addEventListener("test",null,t),window.removeEventListener("test",null,t))}catch(t){}return s}();Qd=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}}},Zd=function(){return{x(s){return s},setWidth(s){},textAlign(s){return s},xPlus(s,t){return s+t},leftForLtr(s,t){return s}}}});var $l={};Do($l,{Animation:()=>Gn,Animations:()=>Gs,ArcElement:()=>Se,BarController:()=>Ve,BarElement:()=>We,BasePlatform:()=>qs,BasicPlatform:()=>qn,BubbleController:()=>Ne,CategoryScale:()=>ms,Chart:()=>se,Colors:()=>Dl,DatasetController:()=>Lt,Decimation:()=>Ll,DomPlatform:()=>Qn,DoughnutController:()=>ne,Element:()=>Rt,Filler:()=>Rl,Interaction:()=>ul,Legend:()=>Ol,LineController:()=>Be,LineElement:()=>Kt,LinearScale:()=>bs,LogarithmicScale:()=>vs,PieController:()=>gs,PointElement:()=>$e,PolarAreaController:()=>ke,RadarController:()=>He,RadialLinearScale:()=>Ee,Scale:()=>De,ScatterController:()=>ze,SubTitle:()=>Il,Ticks:()=>ds,TimeScale:()=>Me,TimeSeriesScale:()=>ys,Title:()=>Fl,Tooltip:()=>Nl,_adapters:()=>hl,_detectPlatform:()=>bl,animator:()=>ee,controllers:()=>dl,defaults:()=>ft,elements:()=>kl,layouts:()=>St,plugins:()=>Bl,registerables:()=>og,registry:()=>Ut,scales:()=>zl});function rh(s,t){let e=[],n=Object.keys(t);for(let i=0;i0||!e&&o<0)return i.index}return null}function fa(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=hh(o,r,n),h=t.length,u;for(let f=0;fe[n].axis===t).shift()}function gh(s,t){return ce(s,{active:!1,dataset:void 0,datasetIndex:t,index:t,mode:"default",type:"dataset"})}function ph(s,t,e){return ce(s,{active:!1,dataIndex:t,parsed:void 0,raw:void 0,element:e,index:t,mode:"default",type:"data"})}function Hs(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 bh(s,t){if(!s._cache.$bar){let e=s.getMatchingVisibleMetas(t),n=[];for(let i=0,o=e.length;ii-o))}return s._cache.$bar}function vh(s){let t=s.iScale,e=bh(t,s.type),n=t._length,i,o,r,a,l=()=>{r===32767||r===-32768||(rs(a)&&(n=Math.min(n,Math.abs(r-a)||n)),a=r)};for(i=0,o=e.length;i0?i[s-1]:null,a=sMath.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 cl(s,t,e,n){return ht(s)?Ch(s,t,e,n):t[e.axis]=e.parse(s,n),t}function pa(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=e?1:-1)}function Sh(s){let t,e,n,i,o;return s.horizontal?(t=s.base>s.x,e="left",n="right"):(t=s.basels(x,a,l,!0)?1:Math.max(w,w*e,S,S*e),g=(x,w,S)=>ls(x,a,l,!0)?-1:Math.min(w,w*e,S,S*e),p=f(0,c,h),m=f(pt,d,u),b=g(ot,c,h),C=g(ot+pt,d,u);n=(p-b)/2,i=(m-C)/2,o=-(p+b)/2,r=-(m+C)/2}return{ratioX:n,ratioY:i,offsetX:o,offsetY:r}}function Fe(){throw new Error("This method is not implemented: Check that a complete date adapter is provided.")}function Dh(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?Hr:Xt;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 Js(s,t,e,n,i){let o=s.getSortedVisibleDatasetMetas(),r=e[t];for(let a=0,l=o.length;a{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 zs(s,t){return s.filter(e=>e.pos===t)}function ya(s,t){return s.filter(e=>fl.indexOf(e.pos)===-1&&e.box.axis===t)}function $s(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 Rh(s){let t=[],e,n,i,o,r,a;for(e=0,n=(s||[]).length;ec.box.fullSize),!0),n=$s(zs(t,"left"),!0),i=$s(zs(t,"right")),o=$s(zs(t,"top"),!0),r=$s(zs(t,"bottom")),a=ya(t,"x"),l=ya(t,"y");return{fullSize:e,leftAndTop:n.concat(o),rightAndBottom:i.concat(l).concat(r).concat(a),chartArea:zs(t,"chartArea"),vertical:n.concat(i).concat(l),horizontal:o.concat(r).concat(a)}}function xa(s,t,e,n){return Math.max(s[e],t[e])+Math.max(s[n],t[n])}function gl(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 Ih(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&&gl(r,o.getPadding());let a=Math.max(0,t.outerWidth-xa(r,s,"left","right")),l=Math.max(0,t.outerHeight-xa(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 Vh(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 Nh(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 Us(s,t,e,n){let i=[],o,r,a,l,c,d;for(o=0,r=s.length,c=0;o{let r=!1;for(let a of o)r=r||Xn(a.addedNodes,n),r=r&&!Xn(a.removedNodes,n);r&&e()});return i.observe(document,{childList:!0,subtree:!0}),i}function Uh(s,t,e){let n=s.canvas,i=new MutationObserver(o=>{let r=!1;for(let a of o)r=r||Xn(a.removedNodes,n),r=r&&!Xn(a.addedNodes,n);r&&e()});return i.observe(document,{childList:!0,subtree:!0}),i}function ml(){let s=window.devicePixelRatio;s!==Sa&&(Sa=s,Xs.forEach((t,e)=>{e.currentDevicePixelRatio!==s&&t()}))}function Kh(s,t){Xs.size||window.addEventListener("resize",ml),Xs.set(s,t)}function Yh(s){Xs.delete(s),Xs.size||window.removeEventListener("resize",ml)}function Gh(s,t,e){let n=s.canvas,i=n&&Nn(n);if(!i)return;let o=Ii((a,l)=>{let c=i.clientWidth;e(a,l),c{let l=a[0],c=l.contentRect.width,d=l.contentRect.height;c===0&&d===0||o(c,d)});return r.observe(i),Kh(s,o),r}function ao(s,t,e){e&&e.disconnect(),t==="resize"&&Yh(s)}function qh(s,t,e){let n=s.canvas,i=Ii(o=>{s.ctx!==null&&e(Wh(o,s))},s);return zh(n,t,i),i}function bl(s){return!Vn()||typeof OffscreenCanvas!="undefined"&&s instanceof OffscreenCanvas?qn:Qn}function Xh(s,t){let e=s.options.ticks,n=Qh(s),i=Math.min(e.maxTicksLimit||n,n),o=e.major.enabled?Jh(t):[],r=o.length,a=o[0],l=o[r-1],c=[];if(r>i)return tu(t,c,o,r/i),c;let d=Zh(o,t,i);if(r>0){let h,u,f=r>1?Math.round((l-a)/(r-1)):null;for(zn(t,c,d,tt(f)?0:a-f,a),h=0,u=r-1;hi)return l}return Math.max(i,1)}function Jh(s){let t=[],e,n;for(e=0,n=s.length;er+a)))return l}function iu(s,t){at(s,e=>{let n=e.gc,i=n.length/2,o;if(i>t){for(o=0;o{let n=e.split("."),i=n.pop(),o=[s].concat(n).join("."),r=t[e].split("."),a=r.pop(),l=r.join(".");ft.route(o,i,l,a)})}function hu(s){return"id"in s&&"defaults"in s}function uu(s){let t={},e=[],n=Object.keys(Ut.plugins.items);for(let o=0;o1&&Da(s[0].toLowerCase());if(n)return n}throw new Error(`Cannot determine type of '${s}' axis. Please provide 'axis' or 'position' option.`)}function Ta(s,t,e){if(e[t+"AxisID"]===s)return{axis:t}}function yu(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 Ta(s,"x",e[0])||Ta(s,"y",e[0])}return{}}function xu(s,t){let e=ve[s.type]||{scales:{}},n=t.scales||{},i=bo(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=vo(r,a,yu(r,s),ft.scales[a.type]),c=bu(l,i),d=e.scales||{};o[r]=os(Object.create(null),[{axis:l},a,d[l],d[c]])}),s.data.datasets.forEach(r=>{let a=r.type||s.type,l=r.indexAxis||bo(a,t),d=(ve[a]||{}).scales||{};Object.keys(d).forEach(h=>{let u=mu(h,l),f=r[u+"AxisID"]||u;o[f]=o[f]||Object.create(null),os(o[f],[{axis:u},n[f],d[h]])})}),Object.keys(o).forEach(r=>{let a=o[r];os(a,[ft.scales[a.type],ft.scale])}),o}function vl(s){let t=s.options||(s.options={});t.plugins=Q(t.plugins,{}),t.scales=xu(s,t)}function yl(s){return s=s||{},s.datasets=s.datasets||[],s.labels=s.labels||[],s}function Cu(s){return s=s||{},s.data=yl(s.data),vl(s),s}function $n(s,t){let e=La.get(s);return e||(e=t(),La.set(s,e),xl.add(e)),e}function Aa(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:In(t,e),subPrefixes:e.filter(a=>!a.toLowerCase().includes("hover"))},n.set(i,o)),o}function Su(s,t){let{isScriptable:e,isIndexable:n}=ji(s);for(let i of t){let o=e(i),r=n(i),a=(r||o)&&s[i];if(o&&(re(a)||_u(a))||r&&ht(a))return!0}return!1}function Ra(s,t){return s==="top"||s==="bottom"||ku.indexOf(s)===-1&&t==="x"}function Pa(s,t){return function(e,n){return e[s]===n[s]?e[t]-n[t]:e[s]-n[s]}}function Oa(s){let t=s.chart,e=t.options.animation;t.notifyPlugins("afterRender"),ct(e&&e.onComplete,[s],t)}function wu(s){let t=s.chart,e=t.options.animation;ct(e&&e.onProgress,[s],t)}function Cl(s){return Vn()&&typeof s=="string"?s=document.getElementById(s):s&&s.length&&(s=s[0]),s&&s.canvas&&(s=s.canvas),s}function Mu(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 Du(s,t,e,n){return!e||s.type==="mouseout"?null:n?t:s}function Ia(){return at(se.instances,s=>s._plugins.invalidate())}function Tu(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,xt(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,xt(n-e));s.arc(i,o,a+c/2,e-u/2,n+u/2,!0)}else{let u=Math.min(c/2,r*xt(n-e));if(d==="round")s.arc(i,o,u,e-ot/2,n+ot/2,!0);else if(d==="bevel"){let f=2*u*u,g=-f*Math.cos(e+ot/2)+i,p=-f*Math.sin(e+ot/2)+o,m=f*Math.cos(n+ot/2)+i,b=f*Math.sin(n+ot/2)+o;s.lineTo(g,p),s.lineTo(m,b)}}s.closePath(),s.moveTo(0,0),s.rect(0,0,s.canvas.width,s.canvas.height),s.clip("evenodd")}function Lu(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+pt,n-pt),s.closePath(),s.clip()}function Au(s){return Fn(s,["outerStart","outerEnd","innerStart","innerEnd"])}function Ru(s,t,e,n){let i=Au(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 bt(l,0,Math.min(o,c))};return{outerStart:a(i.outerStart),outerEnd:a(i.outerEnd),innerStart:bt(i.innerStart,0,r),innerEnd:bt(i.innerEnd,0,r)}}function fs(s,t,e,n){return{x:e+s*Math.cos(t),y:n+s*Math.sin(t)}}function Zn(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 A=d>0?d-n:0,N=h>0?h-n:0,O=(A+N)/2,j=O!==0?g*O/(O+n):g;f=(g-j)/2}let p=Math.max(.001,g*h-e/ot)/h,m=(g-p)/2,b=l+m+f,C=i-m-f,{outerStart:x,outerEnd:w,innerStart:S,innerEnd:y}=Ru(t,u,h,C-b),v=h-x,_=h-w,E=b+x/v,M=C-w/_,k=u+S,L=u+y,D=b+S/k,T=C-y/L;if(s.beginPath(),o){let A=(E+M)/2;if(s.arc(r,a,h,E,A),s.arc(r,a,h,A,M),w>0){let z=fs(_,M,r,a);s.arc(z.x,z.y,w,M,C+pt)}let N=fs(L,C,r,a);if(s.lineTo(N.x,N.y),y>0){let z=fs(L,T,r,a);s.arc(z.x,z.y,y,C+pt,T+Math.PI)}let O=(C-y/u+(b+S/u))/2;if(s.arc(r,a,u,C-y/u,O,!0),s.arc(r,a,u,O,b+S/u,!0),S>0){let z=fs(k,D,r,a);s.arc(z.x,z.y,S,D+Math.PI,b-pt)}let j=fs(v,b,r,a);if(s.lineTo(j.x,j.y),x>0){let z=fs(v,E,r,a);s.arc(z.x,z.y,x,b-pt,E)}}else{s.moveTo(r,a);let A=Math.cos(E)*h+r,N=Math.sin(E)*h+a;s.lineTo(A,N);let O=Math.cos(M)*h+r,j=Math.sin(M)*h+a;s.lineTo(O,j)}s.closePath()}function Pu(s,t,e,n,i){let{fullCircles:o,startAngle:r,circumference:a}=t,l=t.endAngle;if(o){Zn(s,t,e,n,l,i);for(let c=0;c=ot&&f===0&&d!=="miter"&&Tu(s,t,p),o||(Zn(s,t,e,n,p,i),s.stroke())}function _l(s,t,e=t){s.lineCap=Q(e.borderCapStyle,t.borderCapStyle),s.setLineDash(Q(e.borderDash,t.borderDash)),s.lineDashOffset=Q(e.borderDashOffset,t.borderDashOffset),s.lineJoin=Q(e.borderJoinStyle,t.borderJoinStyle),s.lineWidth=Q(e.borderWidth,t.borderWidth),s.strokeStyle=Q(e.borderColor,t.borderColor)}function Fu(s,t,e){s.lineTo(e.x,e.y)}function Iu(s){return s.stepped?Gr:s.tension||s.cubicInterpolationMode==="monotone"?qr:Fu}function Sl(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=ia&&o>a;return{count:n,start:l,loop:t.loop,ilen:c(r+(c?a-w:w))%o,x=()=>{p!==m&&(s.lineTo(d,m),s.lineTo(d,p),s.lineTo(d,b))};for(l&&(f=i[C(0)],s.moveTo(f.x,f.y)),u=0;u<=a;++u){if(f=i[C(u)],f.skip)continue;let w=f.x,S=f.y,y=w|0;y===g?(Sm&&(m=S),d=(h*d+w)/++h):(x(),s.lineTo(w,S),g=y,h=0,p=m=S),b=S}x()}function xo(s){let t=s.options,e=t.borderDash&&t.borderDash.length;return!s._decimated&&!s._loop&&!t.tension&&t.cubicInterpolationMode!=="monotone"&&!t.stepped&&!e?Nu:Vu}function Bu(s){return s.stepped?ia:s.tension||s.cubicInterpolationMode==="monotone"?oa:me}function Hu(s,t,e,n){let i=t._path;i||(i=t._path=new Path2D,t.path(i,e,n)&&i.closePath()),_l(s,t.options),s.stroke(i)}function zu(s,t,e,n){let{segments:i,options:o}=t,r=xo(t);for(let a of i)_l(s,o,a.style),s.beginPath(),r(s,t,a,{start:e,end:e+n-1})&&s.closePath(),s.stroke()}function Wu(s,t,e,n){$u&&!t.options.segment?Hu(s,t,e,n):zu(s,t,e,n)}function Va(s,t,e,n){let i=s.options,{[e]:o}=s.getProps([e],n);return Math.abs(t-o)wl(t++)),t}function Qu(s,t){return s.backgroundColor=s.data.map(()=>Ml(t++)),t}function Zu(s){let t=0;return(e,n)=>{let i=s.getDatasetMeta(n).controller;i instanceof ne?t=Xu(e,t):i instanceof ke?t=Qu(e,t):i&&(t=qu(e,t))}}function Ba(s){let t;for(t in s)if(s[t].borderColor||s[t].backgroundColor)return!0;return!1}function Ju(s){return s&&(s.borderColor||s.backgroundColor)}function tf(){return ft.borderColor!=="rgba(0,0,0,0.1)"||ft.backgroundColor!=="rgba(0,0,0,0.1)"}function ef(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;hf&&(f=g,u=s[C],p=C);r[l++]=u,d=p}return r[l++]=s[c],r}function sf(s,t,e,n){let i=0,o=0,r,a,l,c,d,h,u,f,g,p,m=[],b=t+e-1,C=s[t].x,w=s[b].x-C;for(r=t;rp&&(p=c,u=r),i=(o*i+a.x)/++o;else{let y=r-1;if(!tt(h)&&!tt(u)){let v=Math.min(h,u),_=Math.max(h,u);v!==f&&v!==y&&m.push({...s[v],x:i}),_!==f&&_!==y&&m.push({...s[_],x:i})}r>0&&y!==f&&m.push(s[y]),m.push(a),d=S,o=0,g=p=c,h=u=f=r}}return m}function Tl(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 Ha(s){s.data.datasets.forEach(t=>{Tl(t)})}function nf(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=bt(Xt(t,o.axis,r).lo,0,e-1)),c?i=bt(Xt(t,o.axis,a).hi+1,n,e)-n:i=e-n,{start:n,count:i}}function of(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=ei(l,c,i);let d=_o(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=Ji(t,d);for(let u of h){let f=_o(e,o[u.start],o[u.end],u.loop),g=Zi(a,i,f);for(let p of g)r.push({source:p,target:u,start:{[e]:za(d,f,"start",Math.max)},end:{[e]:za(d,f,"end",Math.min)}})}}return r}function _o(s,t,e,n){if(n)return;let i=t[s],o=e[s];return s==="angle"&&(i=xt(i),o=xt(o)),{property:s,start:i,end:o}}function rf(s,t){let{x:e=null,y:n=null}=s||{},i=t.points,o=[];return t.segments.forEach(({start:r,end:a})=>{a=ei(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 ei(s,t,e){for(;t>s;t--){let n=e[t];if(!isNaN(n.x)&&!isNaN(n.y))break}return t}function za(s,t,e,n){return s&&t?n(s[e],t[e]):s?s[e]:t?t[e]:0}function Al(s,t){let e=[],n=!1;return ht(s)?(n=!0,e=s):e=rf(s,t),e.length?new Kt({points:e,options:{tension:0},_loop:n,_fullLoop:n}):null}function $a(s){return s&&s.fill!==!1}function af(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 lf(s,t,e){let n=uf(s);if(et(n))return isNaN(n.value)?!1:n;let i=parseFloat(n);return gt(i)&&Math.floor(i)===i?cf(n[0],t,i,e):["origin","start","end","stack","shape"].indexOf(n)>=0&&n}function cf(s,t,e,n){return(s==="-"||s==="+")&&(e=t+e),e===t||e<0||e>=n?!1:e}function df(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 hf(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 uf(s){let t=s.options,e=t.fill,n=Q(e&&e.target,e);return n===void 0&&(n=!!t.backgroundColor),n===!1||n===null?!1:n===!0?"origin":n}function ff(s){let{scale:t,index:e,line:n}=s,i=[],o=n.segments,r=n.points,a=gf(t,e);a.push(Al({x:null,y:t.bottom},n));for(let l=0;lo.length>r.length?o:r)),t+e.size/2+n.measureText(i).width}function Mf(s,t,e){let n=s;return typeof t.text!="string"&&(n=Pl(t,e)),n}function Pl(s,t){let e=s.text?s.text.length:0;return t*e}function Df(s,t){return!!((s==="mousemove"||s==="mouseout")&&(t.onHover||t.onLeave)||t.onClick&&(s==="click"||s==="mouseup"))}function Tf(s,t){let e=new Qs({ctx:s.ctx,options:t,chart:s});St.configure(s,e,t),St.addBox(s,e),s.titleBlock=e}function te(s,t){return t&&(ht(t)?Array.prototype.push.apply(s,t):s.push(t)),s}function de(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 Wa(s,t){let e=s.chart.ctx,{body:n,footer:i,title:o}=s,{boxWidth:r,boxHeight:a}=t,l=mt(t.bodyFont),c=mt(t.titleFont),d=mt(t.footerFont),h=o.length,u=i.length,f=n.length,g=_t(t.padding),p=g.height,m=0,b=n.reduce((w,S)=>w+S.before.length+S.lines.length+S.after.length,0);if(b+=s.beforeBody.length+s.afterBody.length,h&&(p+=h*c.lineHeight+(h-1)*t.titleSpacing+t.titleMarginBottom),b){let w=t.displayColors?Math.max(a,l.lineHeight):l.lineHeight;p+=f*w+(b-f)*l.lineHeight+(b-1)*t.bodySpacing}u&&(p+=t.footerMarginTop+u*d.lineHeight+(u-1)*t.footerSpacing);let x=0,C=function(w){m=Math.max(m,e.measureText(w).width+x)};return e.save(),e.font=c.string,at(s.title,C),e.font=l.string,at(s.beforeBody.concat(s.afterBody),C),x=t.displayColors?r+2+t.boxPadding:0,at(n,w=>{at(w.before,C),at(w.lines,C),at(w.after,C)}),x=0,e.font=d.string,at(s.footer,C),e.restore(),m+=g.width,{width:m,height:p}}function Mf(s,t){let{y:e,height:n}=t;return es.height-n/2?"bottom":"center"}function Df(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 Tf(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"),Df(c,s,t,e)&&(c="center"),c}function ja(s,t,e){let n=e.yAlign||t.yAlign||Mf(s,e);return{xAlign:e.xAlign||t.xAlign||Tf(s,t,e,n),yAlign:n}}function Lf(s,t){let{x:e,width:n}=s;return t==="right"?e-=n:t==="center"&&(e-=n/2),e}function Af(s,t,e){let{y:n,height:i}=s;return t==="top"?n+=e:t==="bottom"?n-=i+e:n-=i/2,n}function Ua(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}=Ce(r),g=Lf(t,a),p=Af(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:bt(g,0,n.width-t.width),y:bt(p,0,n.height-t.height)}}function zn(s,t,e){let n=_t(e.padding);return t==="center"?s.x+s.width/2:t==="right"?s.x+s.width-n.right:s.x+n.left}function Ka(s){return te([],de(s))}function Pf(s,t,e){return ce(s,{tooltip:t,tooltipItems:e,type:"tooltip"})}function Ya(s,t){let e=t&&t.dataset&&t.dataset.tooltip&&t.dataset.tooltip.callbacks;return e?s.override(e):s}function Tt(s,t,e,n){let i=s[t].call(e,n);return typeof i=="undefined"?Rl[t].call(e,n):i}function Of(s,t,e,n){let i=s.indexOf(t);if(i===-1)return Rf(s,t,e,n);let o=s.lastIndexOf(t);return i!==o?e:i}function Ga(s){let t=this.getLabels();return s>=0&&sg&&(S=ki(E*S/g/f)*f),tt(l)||(y=Math.pow(10,l),S=Math.ceil(S*y)/y),i==="ticks"?(v=Math.floor(p/S)*S,_=Math.ceil(m/S)*S):(v=p,_=m),b&&x&&o&&Or((a-r)/o,S/1e3)?(E=Math.round(Math.min((a-r)/S,d)),S=(a-r)/E,v=r,_=a):C?(v=b?r:v,_=x?a:_,E=c-1,S=(_-v)/E):(E=(_-v)/S,ns(E,Math.round(E),S/1e3)?E=Math.round(E):E=Math.ceil(E));let M=Math.max(Mi(S),Mi(v));y=Math.pow(10,tt(l)?M:l),v=Math.round(v*y)/y,_=Math.round(_*y)/y;let k=0;for(b&&(u&&v!==r?(e.push({value:r}),va)break;e.push({value:L})}return x&&u&&_!==a?e.length&&ns(e[e.length-1].value,a,qa(a,w,s))?e[e.length-1].value=a:e.push({value:a}):(!x||_===a)&&e.push({value:_}),e}function qa(s,t,{horizontal:e,minRotation:n}){let i=$t(n),o=(e?Math.sin(i):Math.cos(i))||.001,r=.75*t*(""+s).length;return Math.min(t/o,r)}function Xa(s){return s/Math.pow(10,Gs(s))===1}function Qa(s,t,e){let n=Math.pow(10,e),i=Math.floor(s/n);return Math.ceil(t/n)-i}function Vf(s,t){let e=t-s,n=Gs(e);for(;Qa(s,t,n)>10;)n++;for(;Qa(s,t,n)<10;)n--;return Math.min(n,Gs(s))}function Nf(s,{min:t,max:e}){t=Dt(s.min,t);let n=[],i=Gs(t),o=Vf(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=Dt(s.min,Math.round((l+d+h*Math.pow(10,o))*r)/r);for(;u=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=Dt(s.max,u);return n.push({value:f,major:Xa(f),significand:h}),n}function yo(s){let t=s.ticks;if(t.display&&s.display){let e=_t(t.backdropPadding);return Z(t.font&&t.font.size,ft.font.size)+e.height}return 0}function Bf(s,t,e){return e=ht(e)?e:[e],{w:Wr(s,t.string,e),h:e.length*t.lineHeight}}function Za(s,t,e,n,i){return s===n||s===i?{start:t-e/2,end:t+e/2}:si?{start:t-e,end:t}:{start:t,end:t+e}}function Hf(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?ot/o:0;for(let l=0;lt.r&&(a=(n.end-t.r)/o,s.r=Math.max(s.r,t.r+a)),i.startt.b&&(l=(i.end-t.b)/r,s.b=Math.max(s.b,t.b+l))}function $f(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(Mn(xt(l.angle+pt))),d=Yf(l.y,a.h,c),h=Uf(c),u=Kf(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 Wf(s,t){if(!t)return!0;let{left:e,top:n,right:i,bottom:o}=s;return!(Qt({x:e,y:n},t)||Qt({x:e,y:o},t)||Qt({x:i,y:n},t)||Qt({x:i,y:o},t))}function jf(s,t,e){let n=[],i=s._pointLabels.length,o=s.options,{centerPointLabels:r,display:a}=o.pointLabels,l={extra:yo(o)/2,additionalAngle:r?ot/i:0},c;for(let d=0;d270||e<90)&&(s-=t),s}function Gf(s,t,e){let{left:n,top:i,right:o,bottom:r}=e,{backdropColor:a}=t;if(!tt(a)){let l=Ce(t.borderRadius),c=_t(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(),as(s,{x:d,y:h,w:u,h:f,radius:l}),s.fill()):s.fillRect(d,h,u,f)}}function qf(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));Gf(e,r,o);let a=mt(r.font),{x:l,y:c,textAlign:d}=o;xe(e,s._pointLabels[i],l,c+a.lineHeight/2,a,{color:r.color,textAlign:d,textBaseline:"middle"})}}function Il(s,t,e,n){let{ctx:i}=s;if(e)i.arc(s.xCenter,s.yCenter,t,0,ut);else{let o=s.getPointPosition(0,t);i.moveTo(o.x,o.y);for(let r=1;r=At.indexOf(e);o--){let r=At[o];if(Jn[r].common&&s._adapter.diff(i,n,r)>=t-1)return r}return At[e?At.indexOf(e):0]}function Jf(s){for(let t=At.indexOf(s)+1,e=At.length;t=t?e[n]:e[i];s[o]=!0}}function tg(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 nl(s,t,e){let n=[],i={},o=t.length,r,a;for(r=0;r=s[n].pos&&t<=s[i].pos&&({lo:n,hi:i}=Xt(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}=Xt(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 lo,ee,oa,eh,Un,js,Ji,da,uh,Lt,Ve,Ne,ne,Be,ke,ds,He,ze,rl,co,al,ll,cl,St,Us,Kn,Wn,Fh,va,hl,Ks,ya,Gn,Pt,Zh,xa,Ca,De,hs,ho,Ut,uo,wa,ml,Hs,po,vu,xu,Cu,jn,Aa,se,Se,Nu,Kt,$e,We,Cl,bo,Oa,El,wl,Xn,Dl,$a,xf,Qn,Ll,Ys,Al,Hn,Pl,$s,Rl,Ws,Ol,Fl,Rf,Ff,us,ms,fs,Gs,Ie,gs,Ee,Jn,At,Me,ps,Vl,eg,Bl=si(()=>{ia();lo=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=Ai.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)}},ee=new lo,oa="transparent",eh={boolean(s,t,e){return e>.5?t:s},color(s,t,e){let n=Ii(s||oa),i=n.valid&&Ii(t||oa);return i&&i.valid?i.mix(n,e).hexString():t},number(s,t,e){return s+(t-s)*e}},Un=class{constructor(t,e,n,i){let o=e[n];i=ls([t.to,i,o,t.from]);let r=ls([t.from,o,i]);this._active=!0,this._fn=t.fn||eh[t.type||typeof r],this._easing=Ze[t.easing]||Ze.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=ls([t.to,e,i,t.from]),this._from=ls([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||e1?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{let o=t[i];if(!et(o))return;let r={};for(let a of e)r[a]=o[a];(ht(o.properties)&&o.properties||[i]).forEach(a=>{(a===i||!n.has(a))&&n.set(a,r)})})}_animateOptions(t,e){let n=e.options,i=nh(t,n);if(!i)return[];let o=this._createAnimations(i,n);return n.$shared&&sh(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 Un(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 ee.add(this._chart,n),!0}};Ji=s=>s==="reset"||s==="none",da=(s,t)=>t?s:Object.assign({},s),uh=(s,t,e)=>s&&!t.hidden&&t._stacked&&{keys:il(e,!0),values:null},Lt=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=Qi(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&&Is(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=Z(n.xAxisID,Zi(t,"x")),r=e.yAxisID=Z(n.yAxisID,Zi(t,"y")),a=e.rAxisID=Z(n.rAxisID,Zi(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&&Ti(this._data,this),t._stacked&&Is(t)}_dataCheck(){let t=this.getDataset(),e=t.data||(t.data=[]),n=this._data;if(et(e)){let i=this._cachedMeta;this._data=rh(e,i)}else if(n!==e){if(n){Ti(n,this);let i=this._cachedMeta;Is(i),i._parsed=[]}e&&Object.isExtensible(e)&&Br(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=Qi(e.vScale,e),e.stack!==n.stack&&(i=!0,Is(e),e.stack=n.stack),this._resyncElements(t),(i||o!==e._stacked)&&(ca(this,e._parsed),e._stacked=Qi(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{ht(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]p||h=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=0&&tthis.getContext(n,i,e),p=c.resolveNamedOptions(u,f,g,h);return p.$shared&&(p.$shared=l,o[r]=Object.freeze(da(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 js(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||Ji(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){Ji(i)?Object.assign(t,n):this._resolveAnimations(e,i).update(t,n)}updateSharedOptions(t,e,n){t&&!Ji(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{for(c.length+=e,a=c.length-1;a>=r;a--)c[a]=c[a-e]};for(l(o),a=t;ad.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[Z(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=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+n[l];if(et(n[t])){let{key:l="value"}=this._parsing;o=c=>+le(n[c],l)}let r,a;for(r=t,a=t+e;r0&&!isNaN(t)?ut*(Math.abs(t)/e):0}getLabelAndValue(t){let e=this._cachedMeta,n=this.chart,i=n.data.labels||[],o=os(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;it!=="spacing",_indexable:t=>t!=="spacing"&&!t.startsWith("borderDash")&&!t.startsWith("hoverBorderDash")}),W(ne,"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()}}}});Be=class extends Lt{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}=Ri(e,i,r);this._drawStart=a,this._drawCount=l,Oi(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,m=Re(g)?g:Number.POSITIVE_INFINITY,b=this.chart._animationsDisabled||o||i==="none",x=e+n,C=t.length,w=e>0&&this.getParsed(e-1);for(let S=0;S=x){v.skip=!0;continue}let _=this.getParsed(S),E=tt(_[f]),M=v[u]=r.getPixelForValue(_[u],S),k=v[f]=o||E?a.getBasePixel():a.getPixelForValue(l?this.applyStack(a,_,l):_[f],S);v.skip=isNaN(M)||isNaN(k)||E,v.stop=S>0&&Math.abs(_[u]-w[u])>m,p&&(v.parsed=_,v.raw=c.data[S]),h&&(v.options=d||this.resolveDataElementOptions(S,y.active?"active":i)),b||this.updateElement(y,S,v,i),w=_}}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()}};W(Be,"id","line"),W(Be,"defaults",{datasetElementType:"line",dataElementType:"point",showLine:!0,spanGaps:!1}),W(Be,"overrides",{scales:{_index_:{type:"category"},_value_:{type:"linear"}}});ke=class extends Lt{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=os(e._parsed[t].r,n.options.locale);return{label:i[t]||"",value:o}}parseObjectData(t,e,n,i){return Wi.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)&&(oe.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*ot,f=u,g,p=360/this.countVisibleElements();for(g=0;g{!isNaN(this.getParsed(i).r)&&this.chart.getDataVisibility(i)&&e++}),e}_computeAngle(t,e,n){return this.chart.getDataVisibility(t)?$t(this.resolveDataElementOptions(t,e).angle||n):0}};W(ke,"id","polarArea"),W(ke,"defaults",{dataElementType:"arc",animation:{animateRotate:!0,animateScale:!0},animations:{numbers:{type:"number",properties:["x","y","startAngle","endAngle","innerRadius","outerRadius"]}},indexAxis:"r",startAngle:0}),W(ke,"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}}});ds=class extends ne{};W(ds,"id","pie"),W(ds,"defaults",{cutout:0,rotation:0,circumference:360,radius:"100%"});He=class extends Lt{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 Wi.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;a0&&this.getParsed(e-1);for(let w=e;w0&&Math.abs(y[f]-C[f])>b,m&&(v.parsed=y,v.raw=c.data[w]),u&&(v.options=h||this.resolveDataElementOptions(w,S.active?"active":i)),x||this.updateElement(S,w,v,i),C=y}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}};W(ze,"id","scatter"),W(ze,"defaults",{datasetElementType:!1,dataElementType:"point",showLine:!1,fill:!1}),W(ze,"overrides",{interaction:{mode:"point"},scales:{x:{type:"linear"},y:{type:"linear"}}});rl=Object.freeze({__proto__:null,BarController:Ve,BubbleController:Ne,DoughnutController:ne,LineController:Be,PieController:ds,PolarAreaController:ke,RadarController:He,ScatterController:ze});co=class s{constructor(t){W(this,"options");this.options=t||{}}static override(t){Object.assign(s.prototype,t)}init(){}formats(){return Fe()}parse(){return Fe()}format(){return Fe()}add(){return Fe()}diff(){return Fe()}startOf(){return Fe()}endOf(){return Fe()}},al={_date:co};ll={evaluateInteractionItems:qs,modes:{index(s,t,e,n){let i=_e(t,s),o=e.axis||"x",r=e.includeInvisible||!1,a=e.intersect?eo(s,i,o,n,r):so(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=_e(t,s),o=e.axis||"xy",r=e.includeInvisible||!1,a=e.intersect?eo(s,i,o,n,r):so(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{typeof p.beforeLayout=="function"&&p.beforeLayout()});let d=l.reduce((p,m)=>m.box.options&&m.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);dl(u,_t(n));let f=Object.assign({maxPadding:u,w:o,h:r,x:i.left,y:i.top},i),g=Lh(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),Rh(f),ba(a.leftAndTop,f,h,g),f.x+=f.w,f.y+=f.h,ba(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},at(a.chartArea,p=>{let m=p.box;Object.assign(m,s.chartArea),m.update(f.w,f.h,{left:0,top:0,right:0,bottom:0})})}},Us=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){}},Kn=class extends Us{acquireContext(t){return t&&t.getContext&&t.getContext("2d")||null}updateConfig(t){t.options.animation=!1}},Wn="$chartjs",Fh={touchstart:"mousedown",touchmove:"mousemove",touchend:"mouseup",pointerenter:"mouseenter",pointerdown:"mousedown",pointermove:"mousemove",pointerup:"mouseup",pointerleave:"mouseout",pointerout:"mouseout"},va=s=>s===null||s==="";hl=Jr?{passive:!0}:!1;Ks=new Map,ya=0;Gn=class extends Us{acquireContext(t,e){let n=t&&t.getContext&&t.getContext("2d");return n&&n.canvas===t?(Ih(t,e),n):null}releaseContext(t){let e=t.canvas;if(!e[Wn])return!1;let n=e[Wn].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[Wn],!0}addEventListener(t,e,n){this.removeEventListener(t,e);let i=t.$proxies||(t.$proxies={}),r={attach:Hh,detach:zh,resize:jh}[e]||Uh;i[e]=r(t,e,n)}removeEventListener(t,e){let n=t.$proxies||(t.$proxies={}),i=n[e];if(!i)return;({attach:no,detach:no,resize:no}[e]||Nh)(t,e,i),n[e]=void 0}getDevicePixelRatio(){return window.devicePixelRatio}getMaximumSize(t,e,n,i){return Zr(t,e,n,i)}isAttached(t){let e=t&&Fn(t);return!!(e&&e.isConnected)}};Pt=class{constructor(){W(this,"x");W(this,"y");W(this,"active",!1);W(this,"options");W(this,"$animations")}tooltipPosition(t){let{x:e,y:n}=this.getProps(["x","y"],t);return{x:e,y:n}}hasValue(){return Re(this.x)&&Re(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}};W(Pt,"defaults",{}),W(Pt,"defaultRoutes");Zh=s=>s==="left"?"right":s==="right"?"left":s,xa=(s,t,e)=>t==="top"||t==="left"?s[t]+e:s[t]-e,Ca=(s,t)=>Math.min(t||s,s);De=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=Dt(t,Number.POSITIVE_INFINITY),e=Dt(e,Number.NEGATIVE_INFINITY),n=Dt(n,Number.POSITIVE_INFINITY),i=Dt(i,Number.NEGATIVE_INFINITY),{min:Dt(t,n),max:Dt(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;ln?n:e,n=i&&e>n?e:n,{min:Dt(e,Dt(n,e)),max:Dt(n,Dt(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=Kr(this,o,i),this._dataLimitsCached=!0),this.beforeBuildTicks(),this.ticks=this.buildTicks()||[],this.afterBuildTicks();let l=a=o||n<=1||!this.isHorizontal()){this.labelRotation=i;return}let d=this._getLabelSizes(),h=d.widest.width,u=d.highest.height,f=bt(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-Bs(t.grid)-e.padding-Sa(t.title,this.chart.options.font),c=Math.sqrt(h*h+u*u),r=Mn(Math.min(Math.asin(bt((d.highest.height+6)/a,-1,1)),Math.asin(bt(l/c,-1,1))-Math.asin(bt(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=Sa(i,e.options.font);if(a?(t.width=this.maxWidth,t.height=Bs(o)+l):(t.height=this.maxHeight,t.width=Bs(o)+l),n.display&&this.ticks.length){let{first:c,last:d,widest:h,highest:u}=this._getLabelSizes(),f=n.padding*2,g=$t(this.labelRotation),p=Math.cos(g),m=Math.sin(g);if(a){let b=n.mirror?0:m*h.width+p*u.height;t.height=Math.min(this.maxHeight,t.height+b+f)}else{let b=n.mirror?0:p*h.width+m*u.height;t.width=Math.min(this.maxWidth,t.width+b+f)}this._calculatePadding(c,d,m,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({width:r[E]||0,height:a[E]||0});return{first:_(0),last:_(e-1),widest:_(y),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 Fr(this._alignToPixels?ye(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&&ta*i?a/n:l/i:l*i0}_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=Bs(o),f=[],g=a.setContext(this.getContext()),p=g.display?g.width:0,m=p/2,b=function(N){return ye(n,N,p)},x,C,w,S,y,v,_,E,M,k,L,D;if(r==="top")x=b(this.bottom),v=this.bottom-u,E=x-m,k=b(t.top)+m,D=t.bottom;else if(r==="bottom")x=b(this.top),k=t.top,D=b(t.bottom)-m,v=x+m,E=this.top+u;else if(r==="left")x=b(this.right),y=this.right-u,_=x-m,M=b(t.left)+m,L=t.right;else if(r==="right")x=b(this.left),M=t.left,L=b(t.right)-m,y=x+m,_=this.left+u;else if(e==="x"){if(r==="center")x=b((t.top+t.bottom)/2+.5);else if(et(r)){let N=Object.keys(r)[0],O=r[N];x=b(this.chart.scales[N].getPixelForValue(O))}k=t.top,D=t.bottom,v=x+m,E=v+u}else if(e==="y"){if(r==="center")x=b((t.left+t.right)/2);else if(et(r)){let N=Object.keys(r)[0],O=r[N];x=b(this.chart.scales[N].getPixelForValue(O))}y=x-m,_=y-u,M=t.left,L=t.right}let T=Z(i.ticks.maxTicksLimit,h),A=Math.max(1,Math.ceil(h/T));for(C=0;C0&&(P-=R/2);break}$={left:P,top:I,width:R+Q.width,height:X+Q.height,color:A.backdropColor}}m.push({label:w,font:E,textOffset:L,options:{rotation:p,color:O,strokeColor:j,strokeWidth:z,textAlign:K,textBaseline:D,translation:[S,y],backdrop:$}})}return m}_getXAxisLabelAlignment(){let{position:t,ticks:e}=this.options;if(-$t(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{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{let o=n||this._getRegistryForType(i);n||o.isForType(i)||o===this.plugins&&i.id?this._exec(t,o,i):at(i,r=>{let a=n||this._getRegistryForType(r);this._exec(t,a,r)})})}_exec(t,e,n){let i=wn(t);ct(n["before"+i],[],n),e[t](n),ct(n["after"+i],[],n)}_getRegistryForType(t){for(let e=0;eo.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")}};wa=new Map,ml=new Set;Hs=(s,t,e)=>{let n=le(t,e);n!==void 0&&s.add(n)},po=class{constructor(t){this._config=bu(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=pl(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(),gl(t)}clearCache(){this._scopeCache.clear(),this._resolverCache.clear()}datasetScopeKeys(t){return Bn(t,()=>[[`datasets.${t}`,""]])}datasetAnimationScopeKeys(t,e){return Bn(`${t}.transition.${e}`,()=>[[`datasets.${t}.transitions.${e}`,`transitions.${e}`],[`datasets.${t}`,""]])}datasetElementScopeKeys(t,e){return Bn(`${t}-${e}`,()=>[[`datasets.${t}.elements.${e}`,`datasets.${t}`,`elements.${e}`,""]])}pluginScopeKeys(t){let e=t.id,n=this.type;return Bn(`${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=>Hs(l,t,h))),d.forEach(h=>Hs(l,i,h)),d.forEach(h=>Hs(l,ve[o]||{},h)),d.forEach(h=>Hs(l,ft,h)),d.forEach(h=>Hs(l,Ln,h))});let c=Array.from(l);return c.length===0&&c.push(Object.create(null)),ml.has(e)&&r.set(e,c),c}chartOptionScopes(){let{options:t,type:e}=this;return[t,ve[e]||{},ft.datasets[e]||{},{type:e},ft,Ln]}resolveNamedOptions(t,e,n,i=[""]){let o={$shared:!0},{resolver:r,subPrefixes:a}=Ma(this._resolverCache,t,i),l=r;if(yu(r,e)){o.$shared=!1,n=re(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}=Ma(this._resolverCache,t,n);return et(e)?Pe(o,e,void 0,i):o}};vu=s=>et(s)&&Object.getOwnPropertyNames(s).some(t=>re(s[t]));xu="4.5.1",Cu=["top","bottom","left","right","chartArea"];jn={},Aa=s=>{let t=bl(s);return Object.values(jn).filter(e=>e.canvas===t).pop()};se=class{static register(...t){Ut.add(...t),Pa()}static unregister(...t){Ut.remove(...t),Pa()}constructor(t,e){let n=this.config=new po(e),i=bl(t),o=Aa(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||fl(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=Tr(),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 uo,this.$proxies={},this._hiddenIndices={},this.attached=!1,this._animationsDisabled=void 0,this.$context=void 0,this._doResize=Hr(h=>this.update(h),r.resizeDelay||0),this._dataChanges=[],jn[this.id]=this,!a||!l){console.error("Failed to create chart: can't acquire context from the given item");return}ee.listen(this,"complete",La),ee.listen(this,"progress",_u),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 Ut}_initialize(){return this.notifyPlugins("beforeInit"),this.options.responsive?this.resize():ji(this,this.options.devicePixelRatio),this.bindEvents(),this.notifyPlugins("afterInit"),this}clear(){return Vi(this.canvas,this.ctx),this}stop(){return ee.stop(this),this}resize(t,e){ee.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,ji(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||{};at(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=go(r,a),c=l==="r",d=l==="x";return{options:a,dposition:c?"chartArea":d?"bottom":"left",dtype:c?"radialLinear":d?"category":"linear"}}))),at(o,r=>{let a=r.options,l=a.id,c=go(l,a),d=Z(a.type,r.dtype);(a.position===void 0||Da(a.position,c)!==Da(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=Ut.getScale(d);h=new u({id:l,type:d,ctx:this.ctx,chart:this}),n[h.id]=h}h.init(a,t)}),at(i,(r,a)=>{r||delete n[a]}),at(n,r=>{St.configure(this,r,r.options),St.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;ie.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{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{c.reset()}),this._updateDatasets(t),this.notifyPlugins("afterUpdate",{mode:t}),this._layers.sort(Ta("z","_idx"));let{_active:a,_lastEvent:l}=this;l?this._eventHandler(l,!0):a.length&&this._updateHoverStyles(a,a,!0),this.render()}_updateScales(){at(this.scales,t=>{St.removeBox(this,t)}),this.ensureScalesHaveIDs(),this.buildOrUpdateScales()}_checkEventBindings(){let t=this.options,e=new Set(Object.keys(this._listeners)),n=new Set(t.events);(!Ei(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;Su(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;oo.split(",")).map(o=>({method:o[1],start:+o[2],count:+o[3]}))}_updateLayout(t){if(this.notifyPlugins("beforeLayout",{cancelable:!0})===!1)return;St.update(this,this.width,this.height,t);let e=this.chartArea,n=e.width<=0||e.height<=0;this._layers=[],at(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=0;--e)this._drawDataset(t[e]);this.notifyPlugins("afterDatasetsDraw")}_drawDataset(t){let e=this.ctx,n={meta:t,index:t.index,cancelable:!0},i=Xi(this,t);this.notifyPlugins("beforeDatasetDraw",n)!==!1&&(i&&Os(e,i),t.controller.draw(),i&&Fs(e),n.cancelable=!1,this.notifyPlugins("afterDatasetDraw",n))}isPointInArea(t){return Qt(t,this.chartArea,this._minPadding)}getElementsAtEventForMode(t,e,n,i){let o=ll.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=ce(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);ss(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(),ee.remove(this),t=0,e=this.data.datasets.length;t{e.addEventListener(this,o,r),t[o]=r},i=(o,r,a)=>{o.offsetX=r,o.offsetY=a,this._eventHandler(o)};at(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(){at(this._listeners,(t,e)=>{this.platform.removeEventListener(this,e,t)}),this._listeners={},at(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{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}});!Rs(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=Pr(t),c=Eu(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=!Rs(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)}};W(se,"defaults",ft),W(se,"instances",jn),W(se,"overrides",ve),W(se,"registry",Ut),W(se,"version",xu),W(se,"getChart",Aa);Se=class extends Pt{constructor(e){super();W(this,"circumference");W(this,"endAngle");W(this,"fullCircles");W(this,"innerRadius");W(this,"outerRadius");W(this,"pixelMargin");W(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}=Di(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=Z(u,c-l),p=is(r,l,c)&&l!==c,m=g>=ut||p,b=Jt(a,d+f,h+f);return m&&b}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>ut?Math.floor(i/ut):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(ot,i||0)),d=o*c;e.fillStyle=n.backgroundColor,e.strokeStyle=n.borderColor,Tu(e,this,d,r,a),Lu(e,this,d,r,a),e.restore()}};W(Se,"id","arc"),W(Se,"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}),W(Se,"defaultRoutes",{backgroundColor:"backgroundColor"}),W(Se,"descriptors",{_scriptable:!0,_indexable:e=>e!=="borderDash"});Nu=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;Qr(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=na(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=qi(this,{property:e,start:i,end:i});if(!r.length)return;let a=[],l=Fu(n),c,d;for(c=0,d=r.length;ct!=="borderDash"&&t!=="fill"});$e=class extends Pt{constructor(e){super();W(this,"parsed");W(this,"skip");W(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)s.replace("rgb(","rgba(").replace(")",", 0.5)"));El={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=Fa(n)||qu(i)||o&&Fa(o)||Xu();if(!e.forceOverride&&r)return;let a=Gu(s);n.forEach(a)}};wl={id:"decimation",defaults:{algorithm:"min-max",enabled:!1},beforeElementsUpdate:(s,t,e)=>{if(!e.enabled){Ia(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(ls([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}=Ju(l,c),f=e.threshold||4*n;if(u<=f){kl(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=Qu(c,h,u,n,e);break;case"min-max":g=Zu(c,h,u,n);break;default:throw new Error(`Unsupported decimation algorithm '${e.algorithm}'`)}i._decimated=g})},destroy(s){Ia(s)}};Xn=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:ut},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}}};Dl={id:"filler",afterDatasetsUpdate(s,t,e){let n=(s.data.datasets||[]).length,i=[],o,r,a,l;for(r=0;r=0;--r){let a=i[r].$filler;a&&(a.line.updateControlPoints(o,a.axis),n&&a.fill&&ro(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;Na(o)&&ro(s.ctx,o,s.chartArea)}},beforeDatasetDraw(s,t,e){let n=t.meta.$filler;!Na(n)||e.drawTime!=="beforeDatasetDraw"||ro(s.ctx,n,s.chartArea)},defaults:{propagate:!0,drawTime:"beforeDatasetDraw"}},$a=(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)}},xf=(s,t)=>s!==null&&t!==null&&s.datasetIndex===t.datasetIndex&&s.index===t.index,Qn=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=mt(n.font),o=i.size,r=this._computeTitleHeight(),{boxWidth:a,itemHeight:l}=$a(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 m=n+e/2+o.measureText(g.text).width;(p===0||c[c.length-1]+m+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:m,height:i},c[c.length-1]+=m+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((m,b)=>{let{itemWidth:x,itemHeight:C}=Cf(n,e,o,m,i);b>0&&f+C+2*a>d&&(h+=u+a,c.push({width:u,height:f}),g+=u+a,p++,u=f=0),l[b]={left:g,top:f,col:p,width:x,height:C},u=Math.max(u,x),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=Oe(o,this.left,this.width);if(this.isHorizontal()){let a=0,l=Ct(n,this.left+i,this.right-this.lineWidths[a]);for(let c of e)a!==c.row&&(a=c.row,l=Ct(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=Ct(n,this.top+t+i,this.bottom-this.columnSizes[a].height);for(let c of e)c.col!==a&&(a=c.col,l=Ct(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;Os(t,this),this._draw(),Fs(t)}}_draw(){let{options:t,columnSizes:e,lineWidths:n,ctx:i}=this,{align:o,labels:r}=t,a=ft.color,l=Oe(t.rtl,this.left,this.width),c=mt(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:m}=$a(r,h),b=function(y,v,_){if(isNaN(g)||g<=0||isNaN(p)||p<0)return;i.save();let E=Z(_.lineWidth,1);if(i.fillStyle=Z(_.fillStyle,a),i.lineCap=Z(_.lineCap,"butt"),i.lineDashOffset=Z(_.lineDashOffset,0),i.lineJoin=Z(_.lineJoin,"miter"),i.lineWidth=E,i.strokeStyle=Z(_.strokeStyle,a),i.setLineDash(Z(_.lineDash,[])),r.usePointStyle){let M={radius:p*Math.SQRT2/2,pointStyle:_.pointStyle,rotation:_.rotation,borderWidth:E},k=l.xPlus(y,g/2),L=v+u;Ni(i,M,k,L,r.pointStyleWidth&&g)}else{let M=v+Math.max((h-p)/2,0),k=l.leftForLtr(y,g),L=Ce(_.borderRadius);i.beginPath(),Object.values(L).some(D=>D!==0)?as(i,{x:k,y:M,w:g,h:p,radius:L}):i.rect(k,M,g,p),i.fill(),E!==0&&i.stroke()}i.restore()},x=function(y,v,_){xe(i,_.text,y,v+m/2,c,{strikethrough:_.hidden,textAlign:l.textAlign(_.textAlign)})},C=this.isHorizontal(),w=this._computeTitleHeight();C?f={x:Ct(o,this.left+d,this.right-n[0]),y:this.top+d+w,line:0}:f={x:this.left+d,y:Ct(o,this.top+w+d,this.bottom-e[0].height),line:0},Ki(this.ctx,t.textDirection);let S=m+d;this.legendItems.forEach((y,v)=>{i.strokeStyle=y.fontColor,i.fillStyle=y.fontColor;let _=i.measureText(y.text).width,E=l.textAlign(y.textAlign||(y.textAlign=r.textAlign)),M=g+u+_,k=f.x,L=f.y;l.setWidth(this.width),C?v>0&&k+M+d>this.right&&(L=f.y+=S,f.line++,k=f.x=Ct(o,this.left+d,this.right-n[f.line])):v>0&&L+S>this.bottom&&(k=f.x=k+e[f.line].width+d,f.line++,L=f.y=Ct(o,this.top+w+d,this.bottom-e[f.line].height));let D=l.x(k);if(b(D,L,y),k=zr(E,k+g+u,C?k+M:this.right,t.rtl),x(l.x(k),L,y),C)f.x+=M+d;else if(typeof y.text!="string"){let T=c.lineHeight;f.y+=Tl(y,T)+d}else f.y+=S}),Yi(this.ctx,t.textDirection)}drawTitle(){let t=this.options,e=t.title,n=mt(e.font),i=_t(e.padding);if(!e.display)return;let o=Oe(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=Ct(t.align,h,this.right-u);else{let g=this.columnSizes.reduce((p,m)=>Math.max(p,m.height),0);d=c+Ct(t.align,this.top,this.bottom-g-t.labels.padding-this._computeTitleHeight())}let f=Ct(a,h,h+u);r.textAlign=o.textAlign(Tn(a)),r.textBaseline="middle",r.strokeStyle=e.color,r.fillStyle=e.color,r.font=n.string,xe(r,e.text,f,d,n)}_computeTitleHeight(){let t=this.options.title,e=mt(t.font),n=_t(t.padding);return t.display?e.lineHeight+n.height:0}_getLegendItemAt(t,e){let n,i,o;if(Jt(t,this.left,this.right)&&Jt(e,this.top,this.bottom)){for(o=this.legendHitBoxes,n=0;ns.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=_t(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)}}},Ys=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=ht(n.text)?n.text.length:1;this._padding=_t(n.padding);let o=i*mt(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=Ct(a,n,o),h=e+t,c=o-n):(r.position==="left"?(d=n+t,h=Ct(a,i,e),l=ot*-.5):(d=o-t,h=Ct(a,e,i),l=ot*.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=mt(e.font),o=n.lineHeight/2+this._padding.top,{titleX:r,titleY:a,maxWidth:l,rotation:c}=this._drawArgs(o);xe(t,e.text,0,0,n,{color:e.color,maxWidth:l,rotation:c,textAlign:Tn(e.align),textBaseline:"middle",translation:[r,a]})}};Al={id:"title",_element:Ys,start(s,t,e){kf(s,e)},stop(s){let t=s.titleBlock;St.removeBox(s,t),delete s.titleBlock},beforeUpdate(s,t,e){let n=s.titleBlock;St.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}},Hn=new WeakMap,Pl={id:"subtitle",start(s,t,e){let n=new Ys({ctx:s.ctx,options:e,chart:s});St.configure(s,n,e),St.addBox(s,n),Hn.set(s,n)},stop(s){St.removeBox(s,Hn.get(s)),Hn.delete(s)},beforeUpdate(s,t,e){let n=Hn.get(s);St.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}},$s={average(s){if(!s.length)return!1;let t,e,n=new Set,i=0,o=0;for(t=0,e=s.length;ta+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;o0){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{let r={before:[],lines:[],after:[]},a=Ya(n,o);te(r.before,de(Tt(a,"beforeLabel",this,o))),te(r.lines,Tt(a,"label",this,o)),te(r.after,de(Tt(a,"afterLabel",this,o))),i.push(r)}),i}getAfterBody(t,e){return Ka(Tt(e.callbacks,"afterBody",this,t))}getFooter(t,e){let{callbacks:n}=e,i=Tt(n,"beforeFooter",this,t),o=Tt(n,"footer",this,t),r=Tt(n,"afterFooter",this,t),a=[];return a=te(a,de(i)),a=te(a,de(o)),a=te(a,de(r)),a}_createItems(t){let e=this._active,n=this.chart.data,i=[],o=[],r=[],a=[],l,c;for(l=0,c=e.length;lt.filter(d,h,u,n))),t.itemSort&&(a=a.sort((d,h)=>t.itemSort(d,h,n))),at(a,d=>{let h=Ya(t.callbacks,d);i.push(Tt(h,"labelColor",this,d)),o.push(Tt(h,"labelPointStyle",this,d)),r.push(Tt(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=$s[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=Wa(this,n),c=Object.assign({},a,l),d=ja(this.chart,n,c),h=Ua(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}=Ce(a),{x:u,y:f}=t,{width:g,height:p}=e,m,b,x,C,w,S;return o==="center"?(w=f+p/2,i==="left"?(m=u,b=m-r,C=w+r,S=w-r):(m=u+g,b=m+r,C=w-r,S=w+r),x=m):(i==="left"?b=u+Math.max(l,d)+r:i==="right"?b=u+g-Math.max(c,h)-r:b=this.caretX,o==="top"?(C=f,w=C-r,m=b-r,x=b+r):(C=f+p,w=C+r,m=b+r,x=b-r),S=C),{x1:m,x2:b,x3:x,y1:C,y2:w,y3:S}}drawTitle(t,e,n){let i=this.title,o=i.length,r,a,l;if(o){let c=Oe(n.rtl,this.x,this.width);for(t.x=zn(this,n.titleAlign,n),e.textAlign=c.textAlign(n.titleAlign),e.textBaseline="middle",r=mt(n.titleFont),a=n.titleSpacing,e.fillStyle=n.titleColor,e.font=r.string,l=0;lx!==0)?(t.beginPath(),t.fillStyle=o.multiKeyBackground,as(t,{x:p,y:g,w:c,h:l,radius:b}),t.fill(),t.stroke(),t.fillStyle=r.backgroundColor,t.beginPath(),as(t,{x:m,y:g+1,w:c-2,h:l-2,radius:b}),t.fill()):(t.fillStyle=o.multiKeyBackground,t.fillRect(p,g,c,l),t.strokeRect(p,g,c,l),t.fillStyle=r.backgroundColor,t.fillRect(m,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=mt(n.bodyFont),u=h.lineHeight,f=0,g=Oe(n.rtl,this.x,this.width),p=function(_){e.fillText(_,g.x(t.x+f),t.y+u/2),t.y+=u+o},m=g.textAlign(r),b,x,C,w,S,y,v;for(e.textAlign=r,e.textBaseline="middle",e.font=h.string,t.x=zn(this,m,n),e.fillStyle=n.bodyColor,at(this.beforeBody,p),f=a&&m!=="right"?r==="center"?c/2+d:c+2+d:0,w=0,y=i.length;w0&&e.stroke()}_updateAnimationTarget(t){let e=this.chart,n=this.$animations,i=n&&n.x,o=n&&n.y;if(i||o){let r=$s[t.position].call(this,this._active,this._eventPosition);if(!r)return;let a=this._size=Wa(this,t),l=Object.assign({},r,this._size),c=ja(e,t,l),d=Ua(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=_t(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),Ki(t,e.textDirection),o.y+=r.top,this.drawTitle(o,t,e),this.drawBody(o,t,e),this.drawFooter(o,t,e),Yi(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=!Rs(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||!Rs(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=$s[o.position].call(this,t,e);return r!==!1&&(n!==r.x||i!==r.y)}};W(Ws,"positioners",$s);Ol={id:"tooltip",_element:Ws,positioners:$s,afterInit(s,t,e){e&&(s.tooltip=new Ws({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:Rl},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"]},Fl=Object.freeze({__proto__:null,Colors:El,Decimation:wl,Filler:Dl,Legend:Ll,SubTitle:Pl,Title:Al,Tooltip:Ol}),Rf=(s,t,e,n)=>(typeof t=="string"?(e=s.push(t)-1,n.unshift({index:e,label:t})):isNaN(t)&&(e=null),e);Ff=(s,t)=>s===null?null:bt(Math.round(s),0,t);us=class extends De{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:Of(n,t,Z(e,t),this._addedLabels),Ff(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 Ga.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}};W(us,"id","category"),W(us,"defaults",{ticks:{callback:Ga}});ms=class extends De{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=jt(i),c=jt(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=If(i,o);return t.bounds==="ticks"&&wi(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 os(t,this.chart.options.locale,this.options.ticks.format)}},fs=class extends ms{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=$t(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}};W(fs,"id","linear"),W(fs,"defaults",{ticks:{callback:rs.formatters.numeric}});Gs=s=>Math.floor(ae(s)),Ie=(s,t)=>Math.pow(10,Gs(s)+t);gs=class extends De{constructor(t){super(t),this.start=void 0,this.end=void 0,this._startValue=void 0,this._valueRange=0}parse(t,e){let n=ms.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===Ie(this.min,0)?Ie(this.min,-1):Ie(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(Ie(n,-1)),r(Ie(i,1)))),n<=0&&o(Ie(i,-1)),i<=0&&r(Ie(n,1)),this.min=n,this.max=i}buildTicks(){let t=this.options,e={min:this._userMin,max:this._userMax},n=Nf(e,this);return t.bounds==="ticks"&&wi(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":os(t,this.chart.options.locale,this.options.ticks.format)}configure(){let t=this.min;super.configure(),this._startValue=ae(t),this._valueRange=ae(this.max)-ae(t)}getPixelForValue(t){return(t===void 0||t===0)&&(t=this.min),t===null||isNaN(t)?NaN:this.getPixelForDecimal(t===this.min?0:(ae(t)-this._startValue)/this._valueRange)}getValueForPixel(t){let e=this.getDecimalForPixel(t);return Math.pow(10,this._startValue+e*this._valueRange)}};W(gs,"id","logarithmic"),W(gs,"defaults",{ticks:{callback:rs.formatters.logarithmic,major:{enabled:!0}}});Ee=class extends ms{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=_t(yo(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/yo(this.options))}generateTickLabels(t){ms.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?Hf(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=ut/(this._pointLabels.length||1),n=this.options.startAngle||0;return xt(t*e+$t(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{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);Xf(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=mt(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=_t(c.backdropPadding);t.fillRect(-r/2-h.left,-o-d.size/2-h.top,r+h.width,d.size+h.height)}xe(t,a.label,0,-o,d,{color:c.color,strokeColor:c.textStrokeColor,strokeWidth:c.textStrokeWidth})}),t.restore()}drawTitle(){}};W(Ee,"id","radialLinear"),W(Ee,"defaults",{display:!0,animate:!0,position:"chartArea",angleLines:{display:!0,lineWidth:1,borderDash:[],borderDashOffset:0},grid:{circular:!1},startAngle:0,ticks:{showLabelBackdrop:!0,callback:rs.formatters.numeric},pointLabels:{backdropColor:void 0,backdropPadding:2,display:!0,font:{size:10},callback(t){return t},padding:5,centerPointLabels:!1}}),W(Ee,"defaultRoutes",{"angleLines.color":"borderColor","pointLabels.color":"color","ticks.color":"color"}),W(Ee,"descriptors",{angleLines:{_fallback:"grid"}});Jn={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}},At=Object.keys(Jn);Me=class extends De{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 al._date(t.adapters.date);i.init(e),es(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:tl(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=Vr(i,o,r);return this._unit=e.unit||(n.autoSkip?el(e.minUnit,this.min,this.max,this._getLabelCapacity(o)):Zf(this,a.length,e.minUnit,this.min,this.max)),this._majorUnit=!n.major.enabled||this._unit==="year"?void 0:Jf(this._unit),this.initOffsets(i),t.reverse&&a.reverse(),nl(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=bt(e,0,r),n=bt(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||el(o.minUnit,e,n,this._getLabelCapacity(e)),a=Z(i.ticks.stepSize,1),l=r==="week"?o.isoWeekday:!1,c=Re(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+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;e0?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=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;ri-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($n(this._table,t)-this._minPos)/this._tableRange}getValueForPixel(t){let e=this._offsets,n=this.getDecimalForPixel(t)/e.factor-e.end;return $n(this._table,n*this._tableRange+this._minPos,!0)}};W(ps,"id","timeseries"),W(ps,"defaults",Me.defaults);Vl=Object.freeze({__proto__:null,CategoryScale:us,LinearScale:fs,LogarithmicScale:gs,RadialLinearScale:Ee,TimeScale:Me,TimeSeriesScale:ps}),eg=[rl,Cl,Fl,Vl]});var ag={};Eo(ag,{CardView:()=>bs,default:()=>ti});module.exports=Jl(ag);var rt=require("obsidian"),Ul=Qs(xs());var tc=["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"],ec=[{label:"\u{1F1EA}\u{1F1FA} Schengen 90/180 (example)",scope:{countries:tc},window:{type:"rolling",days:180},threshold:90,note:"Example rule \u2014 add your own in Settings \u2192 CSV Card View."}],oi={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:ec,showResidency:!0},Zs="xlsx-card-view";var wo=Qs(xs()),Mo=require("obsidian"),Js=["Image","image","Cover","cover","Poster","poster","Thumbnail","thumbnail","Thumb","thumb","Photo","photo","Picture","picture","Img","img"];function tn(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 Mo.TFile?s.vault.getResourcePath(o):null}var sc=15;function Gt(s){return s>=1&&s<=sc}var nc=["0","1","true","false","yes","no",""];function en(s){return s.length>0&&s.every(t=>nc.includes(t))}function Cs(s){return s.replace(/[\\/:*?"<>|#^[\]]/g,"").replace(/\s+/g," ").trim().slice(0,100)}function Do(s){return s.toLowerCase().replace(/[^\p{L}\p{N}/_-]+/gu,"-").replace(/-+/g,"-").replace(/^-+|-+$/g,"")}function qt(s){var i,o;if(!s||!s.trim())return{headers:[],rows:[]};let t=wo.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 To(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 Mt(s){return s.split(/[\s_-]+/).map(t=>t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()).join(" ")}function Lo(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=ic(e,t);return i&&i!==e&&i!=="\u2014"?i:""}function ic(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 Ao(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 Po(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 Ro(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));ck.remove());let r=document.body.createDiv({cls:"csv-select-picker"});r.style.position="fixed",r.style.zIndex="9999";let a=()=>{let k=s.getBoundingClientRect(),L=r.offsetHeight||280,D=k.bottom+4+L>window.innerHeight&&k.top-4-L>0;r.style.left=k.left+"px",r.style.top=D?k.top-4-L+"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(L=>L.trim()).filter(Boolean),p=new Set(f?g(t):[]),m=()=>n([...p].join(", ")),b=f?Array.from(new Set(e.flatMap(g))):Array.from(new Set(e.filter(Boolean))),x=[],C=0,w=()=>{u.querySelectorAll(".csv-picker-item").forEach((k,L)=>{k.toggleClass("csv-picker-item--hover",L===C),L===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&&!b.includes(k.value)&&b.push(k.value)),m(),k.isAdd?(h.value="",_("")):_(h.value)},y=k=>f?p.has(k):k===t,v=()=>f?p.size>0:!!t,_=k=>{u.empty(),x=[];let L=k?b.filter(D=>D.toLowerCase().includes(k.toLowerCase())):b;if(v()){x.push({value:"",isClear:!0});let D=u.createDiv({cls:"csv-picker-item csv-picker-clear"});D.setText(f?"\u2715 Clear all":"\u2715 Clear"),D.addEventListener("mousedown",T=>{T.preventDefault(),S({value:"",isClear:!0})})}if(L.forEach(D=>{x.push({value:D});let T=u.createDiv({cls:`csv-picker-item ${y(D)?"active":""}`});T.setText(f?`${p.has(D)?"\u2713 ":""}${D}`:D),T.addEventListener("mousedown",A=>{A.preventDefault(),S({value:D})})}),k&&!b.some(D=>D.toLowerCase()===k.toLowerCase())){x.push({value:k,isAdd:!0});let D=u.createDiv({cls:"csv-picker-item csv-picker-add"});D.setText(`+ Add "${k}"`),D.addEventListener("mousedown",T=>{T.preventDefault(),S({value:k,isAdd:!0})})}!L.length&&!k&&u.createDiv({cls:"csv-picker-empty",text:"No options yet. Type to add."}),C=Math.min(C,Math.max(x.length-1,0)),w()};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 E=typeof window!="undefined"&&((M=window.matchMedia)==null?void 0:M.call(window,"(pointer: coarse)").matches);setTimeout(()=>{document.addEventListener("mousedown",l),E||(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(),x.length&&(C=(C+1)%x.length,w());return}if(k.key==="ArrowUp"){k.preventDefault(),x.length&&(C=(C-1+x.length)%x.length,w());return}if(k.key==="Enter")if(k.preventDefault(),x[C])S(x[C]);else{let L=h.value.trim();L&&(n(L),d())}})}function Oo(s,t,e){return!s[t]||t===e||(s[e]||(s[e]=s[t]),delete s[t]),s}var oc={source:["confirmed","inferred","conflict"],resolved:["yes","no"]};function Fo(s){var t;return(t=oc[s.trim().toLowerCase()])!=null?t:null}function he(s){return/(^|[_\s-])(date|due|deadline)([_\s-]|$)/i.test(s.trim())}var Io=/^\d{4}-\d{2}-\d{2}$/;var Nt=require("obsidian");function on(s,t,e,n){let i=he(t)&&(e===""||Io.test(e)),o=s.createEl("input",{cls:n,type:i?"date":"text",value:e});i||(o.placeholder=t);let r=Fo(t);if(r){let a=`csv-dl-${t.toLowerCase().replace(/[^a-z0-9]+/g,"-")}-${Math.random().toString(36).slice(2,7)}`,l=s.createEl("datalist");l.id=a,r.forEach(c=>l.createEl("option",{value:c})),o.setAttr("list",a)}return o}var Ke=class extends Nt.Modal{constructor(t,e,n,i,o,r,a={},l=()=>!1,c){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:d=>this.isSelectCol(d)||Gt(this.getColumnValues(d).length)}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.headers.find(d=>["title","name"].includes(d.toLowerCase())),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 m;let h=e.createDiv({cls:"csv-modal-row"});h.createEl("label",{text:Mt(d),cls:"csv-modal-label"});let u=(m=this.optionPresets[d])!=null?m:[],f=d===i,g=Et(d),p=!f&&!this.isNotesCol(d)&&!g&&(u.length>0||this.isCategoricalCol(d));if(this.isBooleanCol(d)){n[d]="0";let b=h.createDiv({cls:"csv-toggle"});b.createDiv({cls:"csv-toggle-knob"}),b.addEventListener("click",()=>{let x=!b.hasClass("is-on");b.toggleClass("is-on",x),n[d]=x?"1":"0"})}else if(this.isNotesCol(d)){let b=h.createEl("textarea",{cls:"csv-modal-textarea",placeholder:"Markdown supported\u2026"});b.addEventListener("input",()=>{n[d]=b.value})}else if(p){let b="__custom__",x=[];[...u,...this.getColumnValues(d)].forEach(S=>{let y=(S!=null?S:"").trim();y&&!x.some(v=>v.toLowerCase()===y.toLowerCase())&&x.push(y)});let C=h.createEl("select",{cls:"csv-modal-select"});C.createEl("option",{text:"\u2014",value:""}),x.forEach(S=>C.createEl("option",{text:S,value:S})),C.createEl("option",{text:"+ Custom\u2026",value:b});let w=h.createEl("input",{cls:"csv-modal-input csv-modal-custom",type:"text",placeholder:`Custom ${Mt(d).toLowerCase()}`});w.hide(),w.addEventListener("input",()=>{n[d]=w.value}),w.addEventListener("keydown",S=>{S.key==="Enter"&&c()}),C.addEventListener("change",()=>{C.value===b?(w.show(),w.focus(),n[d]=w.value):(w.hide(),n[d]=C.value)})}else if(!f&&g&&this.isSelectCol(d)){let x=h.createDiv({cls:"csv-modal-select-wrap"}).createDiv({cls:"csv-select-chip empty"});x.setText("\u2014 click to select \u2014"),x.addEventListener("click",C=>{C.stopPropagation(),It(x,n[d],this.getColumnValues(d),w=>{n[d]=w,x.setText(w||"\u2014 click to select \u2014"),x.toggleClass("empty",!w)},t,{multi:Et(d)})})}else{let b=on(h,d,"","csv-modal-input");if(b.addEventListener("input",()=>{n[d]=b.value}),b.addEventListener("keydown",x=>{x.key==="Enter"&&c()}),d===i&&o.size){let x=h.createDiv({cls:"csv-modal-dup-hint"});x.hide(),b.addEventListener("input",()=>{let C=o.get(b.value.trim().toLowerCase());C?(x.setText(`\u26A0 \u201C${C}\u201D is already in this file`),x.show()):x.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 Nt.Notice("Fill in at least one field.");return}this.onSubmit(n),this.close()}}onClose(){this.contentEl.empty()}},Ye=class extends Nt.Modal{constructor(e,n,i,o,r,a,l,c,d,h,u){super(e);this.vvHandler=null;this.row={...n},this.notesCol=i,this.headers=o,this.filePath=r,this.renderComponent=new Nt.Component,this.isNotesCol=a,this.isSelectCol=l,this.getColumnValues=c,this.onSave=d,this.onDelete=h,this.isCategoricalCol=u!=null?u:f=>this.isSelectCol(f)||!he(f)&&Gt(this.getColumnValues(f).length),this.modalEl.addClass("csv-note-expander-modal")}onOpen(){var g,p,m,b,x;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.headers.find(C=>["title","name","Title","Name"].includes(C)))!=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.headers.find(C=>["title","name","Title","Name"].includes(C)),l=this.headers.find(C=>["author","Author","director","Director","artist","Artist","creator","Creator"].includes(C));this.headers.forEach(C=>{if(this.isNotesCol(C))return;let w=r.createDiv({cls:"csv-expander-field-row"});w.createDiv({cls:"csv-expander-field-label",text:Mt(C)});let S=Et(C);if(C!==a&&(S?this.isSelectCol(C):this.isCategoricalCol(C))){let v=w.createDiv({cls:`csv-select-chip ${this.row[C]?"":"empty"}`});v.setText(this.row[C]||"\u2014"),v.addEventListener("click",_=>{_.stopPropagation(),It(v,this.row[C],this.getColumnValues(C),E=>{this.row[C]=E,v.setText(E||"\u2014"),v.toggleClass("empty",!E)},e,{multi:Et(C)})})}else{let v=w.createDiv({cls:"csv-expander-field-value",text:this.row[C]||"\u2014"});v.addEventListener("click",()=>{var M;v.empty();let _=on(v,C,(M=this.row[C])!=null?M:"","csv-inline-input");_.focus(),_.type==="text"&&_.select();let E=()=>{this.row[C]=_.value,v.empty(),v.setText(_.value||"\u2014")};_.addEventListener("blur",E),_.addEventListener("keydown",k=>{k.key==="Enter"&&_.blur(),k.key==="Escape"&&(v.empty(),v.setText(this.row[C]||"\u2014"))})})}});let c=!1,d=this.notesCol&&(m=this.row[this.notesCol])!=null?m:"",h=null;if(this.notesCol){e.createDiv({cls:"csv-expander-divider"}).createDiv({cls:"csv-expander-notes-label",text:this.notesCol});let w=e.createDiv({cls:"csv-expander-rendered markdown-rendered"});w.title="Click to edit";let S=e.createDiv({cls:"csv-expander-editor"});S.style.display="none";let y=()=>{w.empty(),d.trim()?Nt.MarkdownRenderer.render(this.app,d,w,this.filePath,this.renderComponent):w.createDiv({cls:"csv-notes-empty",text:"+ Add note"})};y(),h=S.createEl("textarea",{cls:"csv-expander-textarea"}),h.value=d,h.addEventListener("input",()=>{d=h.value});let v=()=>{c||(c=!0,w.style.display="none",S.style.display="flex",h.value=d,h.focus())},_=()=>{c&&(c=!1,S.style.display="none",w.style.display="",d=h.value,y())};w.addEventListener("click",E=>{if(E.target.closest("a, button, input, textarea, [contenteditable]"))return;let k=window.getSelection();k&&k.toString().length>0||v()}),h.addEventListener("keydown",E=>{E.key==="Escape"&&(E.preventDefault(),h.blur())}),h.addEventListener("blur",_)}let u=e.createDiv({cls:"csv-expander-footer"});if(this.onDelete){let C=String((x=this.row[(b=this.headers.find(w=>["title","name","Title","Name"].includes(w)))!=null?b:this.headers[0]])!=null?x:"").trim();u.createEl("button",{cls:"csv-expander-delete-btn",text:"Delete"}).addEventListener("click",()=>{let w=C||"this entry";window.confirm(`Delete "${w}"? 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 sn=class extends Nt.Modal{constructor(t,e,n,i,o,r,a,l,c,d,h,u){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.availableModes=a,this.onSave=l,this.getHeaders=c,this.getFileCfg=d,this.onAddColumn=h,this.onRemoveColumn=u}onOpen(){var v,_;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 E=this.getFileCfg();this.current={...E,habitColumns:E.habitColumns?[...E.habitColumns]:void 0,categoricalColumns:E.categoricalColumns?[...E.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:"Role is exclusive \u2014 picking it for one column clears it from any other. The three toggles can be combined freely."});let o=[{value:"",label:"\u2014 no special role \u2014"},{value:"category",label:"Category (Kanban grouping)"},{value:"status",label:"Status (checkmark / row subgroups)"},{value:"notes",label:"Notes"},{value:"image",label:"Image (card / kanban thumbnail)"},{value:"anki",label:"Anki card front"}],r=E=>this.current.categoryColumn===E?"category":this.current.statusColumn===E?"status":this.current.notesColumn===E?"notes":this.current.imageColumn===E?"image":this.current.ankiFrontCol===E?"anki":"",a=E=>{this.current.categoryColumn===E&&(this.current.categoryColumn=void 0),this.current.statusColumn===E&&(this.current.statusColumn=void 0),this.current.notesColumn===E&&(this.current.notesColumn=void 0),this.current.imageColumn===E&&(this.current.imageColumn=void 0),this.current.ankiFrontCol===E&&(this.current.ankiFrontCol=void 0)},l=(E,M)=>{a(E),M==="category"?this.current.categoryColumn=E:M==="status"?this.current.statusColumn=E:M==="notes"?this.current.notesColumn=E:M==="image"?this.current.imageColumn=E:M==="anki"&&(this.current.ankiFrontCol=E)},c=E=>this.headers.find(M=>E.some(k=>k.toLowerCase()===M.toLowerCase())),d=[c(["Author","Authors","Director","Artist","Creator","By"]),c(["Year","Date","Released"]),c(["Rating","Score","Score /5","Stars"]),c(["Theme","Tags","Tag","Mood"])].filter(E=>!!E),h=(v=this.headers.find(E=>["title","name","Title","Name"].includes(E)))!=null?v:this.headers[0],u=i.createDiv({cls:"csv-modal-column-list"}),f=()=>{var L,D,T;u.empty();let E=new Set((L=this.current.habitColumns)!=null?L:this.autoDetectedHabits),M=new Set((D=this.current.cardFields)!=null?D:d),k=new Set((T=this.current.categoricalColumns)!=null?T:this.autoDetectedCategorical);this.headers.forEach(A=>{let N=u.createDiv({cls:"csv-modal-colcfg-row"}),O=N.createDiv({cls:"csv-modal-colcfg-name"});O.createSpan({text:A});let j=O.createEl("button",{cls:"csv-modal-column-remove",text:"\u2715",attr:{title:`Remove "${A}" \u2014 deletes this column's data from every row`}});j.addEventListener("click",()=>{if(j.hasClass("confirm")){this.onRemoveColumn(A),n();return}u.querySelectorAll(".csv-modal-column-remove.confirm").forEach(X=>{X.removeClass("confirm"),X.setText("\u2715")}),j.addClass("confirm"),j.setText("Confirm?"),window.setTimeout(()=>{j.isConnected&&(j.removeClass("confirm"),j.setText("\u2715"))},3e3)});let z=N.createDiv({cls:"csv-modal-colcfg-controls"}),K=z.createEl("select",{cls:"csv-modal-select csv-modal-colcfg-role"}),$=r(A);o.forEach(X=>{let R=K.createEl("option",{text:X.label,value:X.value});X.value===$&&(R.selected=!0)}),K.addEventListener("change",()=>{l(A,K.value),f()});let Q=(X,R,I,P)=>{let H=z.createEl("label",{cls:"csv-modal-checkbox-label csv-modal-colcfg-toggle"}),F=H.createEl("input",{type:"checkbox"});F.checked=R,I&&H.addClass("auto-detected"),H.createSpan({text:X}),F.addEventListener("change",()=>P(F.checked))};Q("Habit",E.has(A),this.autoDetectedHabits.includes(A)&&!this.current.habitColumns,X=>{this.current.habitColumns||(this.current.habitColumns=[...this.autoDetectedHabits]),X?this.current.habitColumns.includes(A)||this.current.habitColumns.push(A):this.current.habitColumns=this.current.habitColumns.filter(R=>R!==A)}),Q("Card field",M.has(A),d.includes(A)&&!this.current.cardFields,X=>{this.current.cardFields||(this.current.cardFields=[...d]),X?this.current.cardFields.includes(A)||this.current.cardFields.push(A):this.current.cardFields=this.current.cardFields.filter(R=>R!==A)}),A!==h&&Q("Categorical",k.has(A),this.autoDetectedCategorical.includes(A)&&!this.current.categoricalColumns,X=>{this.current.categoricalColumns||(this.current.categoricalColumns=[...this.autoDetectedCategorical]),X?this.current.categoricalColumns.includes(A)||this.current.categoricalColumns.push(A):this.current.categoricalColumns=this.current.categoricalColumns.filter(R=>R!==A)})})};f();let g=i.createDiv({cls:"csv-modal-add-column"}),p=g.createEl("input",{cls:"csv-modal-input",type:"text",placeholder:"New column name"}),m=g.createEl("button",{cls:"csv-modal-cancel",text:"+ Add column"}),b=()=>{let E=this.onAddColumn(p.value);if(E){new Nt.Notice(E);return}n()};m.addEventListener("click",b),p.addEventListener("keydown",E=>{E.key==="Enter"&&(E.preventDefault(),b())});let x=e.createDiv({cls:"csv-modal-row"});x.createEl("label",{text:"Default view",cls:"csv-modal-label"});let C=x.createEl("select",{cls:"csv-modal-select"}),w=[["\u2014 use global default \u2014",""],...this.availableModes.map(E=>[E.label,E.id])],S=(_=this.current.defaultMode)!=null?_:"";S&&!this.availableModes.some(E=>E.id===S)&&w.push([`${S} (no longer available)`,S]),w.forEach(([E,M])=>{let k=C.createEl("option",{text:E,value:M});S===M&&(k.selected=!0)}),C.addEventListener("change",()=>{this.current.defaultMode=C.value?C.value:void 0});let y=t.createDiv({cls:"csv-modal-btns"});y.createEl("button",{text:"Cancel",cls:"csv-modal-cancel"}).addEventListener("click",()=>this.close()),y.createEl("button",{text:"Save",cls:"csv-modal-submit"}).addEventListener("click",()=>{this.onSave(this.current),this.close()})}onClose(){this.contentEl.empty()}},nn=class extends Nt.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 ri=195,rc={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"},ac={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"]},Vo={AF:"Africa",AN:"Antarctica",AS:"Asia",EU:"Europe",NA:"N. America",OC:"Oceania",SA:"S. America"},No={};for(let[s,t]of Object.entries(ac))for(let e of t)No[e]=s;function kt(s){return rc[s]||s}function Wt(s){return!s||s.length!==2?"":String.fromCodePoint(...s.toUpperCase().split("").map(t=>t.charCodeAt(0)+127397))}function Bt(s){if(!s||s.indexOf("?")!==-1)return null;let t=new Date(s+"T12:00:00Z");return isNaN(t.getTime())?null:t}function _s(s){let t=Bt(s.date_entered),e=Bt(s.date_left);return!t||!e?0:Math.max(Math.round((e.getTime()-t.getTime())/864e5),1)}function Bo(s,t=new Date){let e=t.getTime(),n=null,i=-1/0;for(let o of s){let r=Bt(o.date_entered);if(!(!r||r.getTime()>e)){if(o.date_left.trim()!==""){let a=Bt(o.date_left);if(!a||a.getTime()i&&(n=o,i=r.getTime())}}return n}function Ho(s){let t=b=>{var x,C,w,S,y,v,_,E;return{date_entered:(x=b.date_entered)!=null?x:"",date_left:(C=b.date_left)!=null?C:"",country:((w=b.country)!=null?w:"").trim().toUpperCase(),city:(S=b.city)!=null?S:"",visa_status:(y=b.visa_status)!=null?y:"",notes:(v=b.notes)!=null?v:"",source:((_=b.source)!=null?_:"").trim().toLowerCase(),resolved:(E=b.resolved)!=null?E:"",_src:b}},e=s.map(t).filter(b=>b.country),n=e.filter(b=>b.source==="confirmed"),i=e.filter(b=>b.source==="inferred"),o=e.filter(b=>b.source==="conflict"),r=[];for(let b of n){let x=Bt(b.date_entered),C=Bt(b.date_left);x&&C&&r.push([x.getTime(),C.getTime()])}let a=b=>{let x=Bt(b.date_entered),C=Bt(b.date_left);if(!x||!C)return!1;let w=x.getTime(),S=C.getTime();return r.some(([y,v])=>w<=v&&S>=y)},l=i.filter(b=>Bt(b.date_entered)&&Bt(b.date_left)&&!a(b)),c=new Set(n.map(b=>b.country)),d=new Set(i.map(b=>b.country)),h=new Set([...d].filter(b=>!c.has(b))),u=new Set([...c,...d]),f=new Map;for(let b of n)f.set(b.country,(f.get(b.country)||0)+_s(b));let g=[...f.entries()].map(([b,x])=>({iso:b,days:x})).sort((b,x)=>x.days-b.days||kt(b.iso).localeCompare(kt(x.iso))),p=g.reduce((b,x)=>b+x.days,0),m=new Set;for(let b of c){let x=No[b];x&&m.add(x)}return{confirmed:n,inferred:i,conflicts:o,inferredVisible:l,confRanges:r,confirmedCountries:c,inferredOnlyCountries:h,allCountries:u,countryDays:g,totalConfirmedDays:p,visitedContinents:m,worldPct:Math.round(c.size/ri*100)}}var ai=864e5;function zo(s){if(!s||s.indexOf("?")!==-1)return null;let t=Date.parse(s+"T00:00:00Z");return isNaN(t)?null:t}function lc(s,t,e,n){let i=Math.max(s,e),o=Math.min(t,n);return o<=i?0:Math.round((o-i)/ai)}function cc(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*ai,end:t+ai,label:`in last ${n} days`}}function $o(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=cc(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=zo(f.date_entered),p=zo(f.date_left);g===null||p===null||(a+=lc(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 Wo=["#c9a96e","#4a6fa5","#5ba06e","#a05b8a","#6ea0a0","#a0855b","#7a6ea0","#a06e6e","#6e8fa0","#a09e5b"],dc=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function hc(){let s=new Map,t=0;return e=>(s.has(e)||s.set(e,Wo[t++%Wo.length]),s.get(e))}function uc(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 li(s){let t=_s(s);return t?`${t}d`:"\u2014"}function Ge(s){return s||"\u2014"}function Es(s){return s.createDiv({cls:"csv-tv-table-wrap"}).createEl("table",{cls:"csv-tv-table"})}function Ss(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=on(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 jo(s,t,e,n=()=>{},i=null,o=()=>{}){let r=Ho(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(uc(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&&(pc(u,r,l,()=>d(null)),u.scrollIntoView({behavior:"smooth",block:"nearest"}))},d=f=>{l=f&&f!==l?f:null,c()};fc(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&&mc(a,r.confirmed,i),bc(a,r,d),vc(a,r,d),yc(a,r,n);try{let f=await e();h.empty(),f?gc(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 fc(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/ri*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=>Vo[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=_s(c);d>a&&(a=d,r=c)}if(r){let c=r.date_entered.slice(0,4);n("Longest trip",`${a}d`,`${Wt(r.country)} ${kt(r.country)}${c?` \xB7 ${c}`:""}`)}let l=Bo(t.confirmed);if(l){let c=Bt(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 ${Wt(l.country)} ${kt(l.country)}`}),h.createSpan({cls:"csv-tv-now-sub",text:` \u2014 since ${l.date_entered} (day ${d})${l.city?` \xB7 ${l.city}`:""}`})}}function gc(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",`${kt(a)} \u2014 ${l&&l.days?l.days+"d confirmed":"confirmed"}`),r.setAttr("data-tip",`${kt(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",`${kt(a)} \u2014 photo evidence`),r.setAttr("data-tip",`${kt(a)} \xB7 photo evidence \xB7 click for trips`)):a?(r.classList.add("cp-unvisited"),r.setAttr("data-tip",kt(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=' Confirmed',o.createSpan({cls:"csv-tv-leg"}).innerHTML=' Photo evidence'}function pc(s,t,e,n){var m,b;let i=s.createDiv({cls:"csv-tv-detail"}),o=i.createDiv({cls:"csv-tv-detail-head"});o.createSpan({cls:"csv-tv-detail-flag",text:Wt(e)});let r=o.createDiv({cls:"csv-tv-detail-titles"});r.createDiv({cls:"csv-tv-detail-name",text:kt(e)});let a=t.confirmed.filter(x=>x.country===e),l=t.inferred.filter(x=>x.country===e),c=(b=(m=t.countryDays.find(x=>x.iso===e))==null?void 0:m.days)!=null?b:0,d=new Set([...a,...l].map(x=>x.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=rn([...a.map(x=>({r:x,inf:!1,date_entered:x.date_entered})),...l.map(x=>({r:x,inf:!0,date_entered:x.date_entered}))]);if(!u.length)return;let f=Es(i),g=f.createEl("thead").createEl("tr");["","Entered","Left","Days","City","Visa"].forEach(x=>g.createEl("th",{text:x}));let p=f.createEl("tbody");for(let{r:x,inf:C}of u){let w=p.createEl("tr");w.createEl("td",{text:C?"\u{1F4F7}":"",cls:"csv-tv-flag",attr:C?{"data-tip":"Photo-inferred"}:{}}),w.createEl("td",{text:Ge(x.date_entered)}),w.createEl("td",{text:Ge(x.date_left)}),w.createEl("td",{text:li(x)}),w.createEl("td",{text:x.city}),w.createEl("td",{text:x.visa_status})}}function mc(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=$o(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 bc(s,t,e){s.createDiv({cls:"csv-tv-sec-title",text:"Countries visited"});let n=Es(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:Wt(r),cls:"csv-tv-flag"}),l.createEl("td",{text:kt(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(Wt).join(" ")})}}function vc(s,t,e){s.createDiv({cls:"csv-tv-sec-title",text:"Timeline"});let n=hc(),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 w=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);w<=S&&(g+=Math.max(Math.round((S-w)/864e5)+1,1))}let m=f.createDiv({cls:"csv-tv-tl-label"});m.createSpan({text:String(c)}),m.createSpan({cls:"csv-tv-tl-sub",text:`${g?`${g}d \xB7 `:""}${p.size} ${p.size===1?"country":"countries"}`});let b=f.createDiv({cls:"csv-tv-month-row"});dc.forEach(C=>b.createDiv({cls:"csv-tv-month-tick",text:C}));let x=f.createDiv({cls:"csv-tv-track"});for(let C of o.get(c)){let w=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(w>S)continue;let y=(w-d)/u*100,v=Math.max((S-w+864e5)/u*100,.5),_=n(C.country),E=x.createDiv({cls:`csv-tv-seg${C._inf?" csv-tv-seg-inf":""}`});E.style.left=`${y}%`,E.style.width=`${v}%`,C._inf?(E.style.borderColor=_,E.style.background=_+"22",E.style.color=_):E.style.background=_,E.setAttr("data-iso",C.country),E.setAttr("data-tip",`${kt(C.country)} ${C.date_entered} \u2192 ${C.date_left} (${_s(C)}d)${C.visa_status?" ["+C.visa_status+"]":""}${C._inf?" [photo]":""}`),E.addEventListener("click",()=>e(C.country)),v>4?E.createSpan({cls:"csv-tv-seg-lbl",text:`${Wt(C.country)} ${C.country}`}):v>2&&E.createSpan({cls:"csv-tv-seg-lbl",text:Wt(C.country)})}}a.createDiv({cls:"csv-tv-tl-legend"}).setText("Confirmed (solid) \xB7 Photo inferred (outlined)")}function rn(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=Es(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 rn(t.confirmed)){let a=o.createEl("tr");a.createEl("td",{text:Wt(r.country),cls:"csv-tv-flag"}),a.createEl("td",{text:kt(r.country)}),Ss(a.createEl("td"),r._src,"date_entered",e),Ss(a.createEl("td"),r._src,"date_left",e),a.createEl("td",{text:li(r)}),Ss(a.createEl("td"),r._src,"city",e),Ss(a.createEl("td"),r._src,"visa_status",e),Ss(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=Es(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 rn(t.inferred)){let h=c.createEl("tr");h.createEl("td",{text:Wt(d.country),cls:"csv-tv-flag"}),h.createEl("td",{text:kt(d.country)}),h.createEl("td",{text:Ge(d.date_entered)}),h.createEl("td",{text:Ge(d.date_left)}),h.createEl("td",{text:li(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=Es(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 rn(t.conflicts)){let h=c.createEl("tr");h.createEl("td",{text:Wt(d.country),cls:"csv-tv-flag"}),h.createEl("td",{text:d.country}),h.createEl("td",{text:`${Ge(d.date_entered)} \u2192 ${Ge(d.date_left)}`}),h.createEl("td",{text:d.notes})}}}var Vt=require("obsidian"),an=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 b,x,C,w,S,y;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,_,E,M="")=>{let k=u.createDiv({cls:"csv-rr-field"});k.createEl("label",{text:v});let L=k.createEl("input",{type:"text",value:_});M&&(L.placeholder=M),L.addEventListener("input",()=>{E(L.value),n()})},g=(b=r.scope.countries)!=null?b: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 m=p.createEl("select");[["calendar-year","Calendar year"],["rolling","Rolling N days"],["all-time","All time"]].forEach(([v,_])=>{let E=m.createEl("option",{text:_,value:v});r.window.type===v&&(E.selected=!0)}),m.addEventListener("change",()=>{r.window={type:m.value,days:r.window.days},n(),this.renderResidencyRules(t)}),r.window.type==="rolling"&&f("Rolling days",String((x=r.window.days)!=null?x: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)",((w=(C=r.exempt)==null?void 0:C.visa_status)!=null?w:[]).join(", "),v=>{let _=v.split(",").map(E=>E.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",(y=r.note)!=null?y:"",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 ue=require("obsidian"),Uo=Qs(xs());async function Ko(s,t,e,n,i={}){var $,Q,X;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=(Q=($=a==null?void 0:a.parent)==null?void 0:$.path)!=null?Q:"",c=Ue(r,l),d=s.vault.getAbstractFileByPath(c);if(!d||!(d instanceof ue.TFile)){e.createEl("p",{text:`Error: File not found: ${c}`,cls:"csv-add-error"});return}let h=(X=i[c])!=null?X:{},u=[],f=[];try{let R=await s.vault.read(d),I=qt(R);u=I.headers,f=I.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=["0","1","true","false","yes","no",""],p=R=>{let I=f.map(P=>{var H;return((H=P[R])!=null?H:"").toLowerCase().trim()});return I.length>0&&I.every(P=>g.includes(P))},m=R=>{let I=R.toLowerCase();if(["date","day","datum"].includes(I))return!0;let P=f.slice(0,5).map(H=>{var F;return(F=H[R])!=null?F:""});return P.length>0&&P.every(H=>/^\d{4}-\d{2}-\d{2}$/.test(H))},b=R=>{let I=R.toLowerCase();return["notes","note","comments","description","journal"].includes(I)},x=u.filter(R=>p(R)&&!m(R)),C=u.filter(R=>m(R)),w=u.filter(R=>b(R)),S=u.filter(R=>!x.includes(R)&&!C.includes(R)&&!w.includes(R)),y=u.find(R=>["title","name"].includes(R.toLowerCase())),v=e.createDiv({cls:"csv-add-form csv-add-compact"}),_=v.createEl("button",{cls:"csv-add-trigger",text:"+ New entry"});_.style.display="none";let E=v.createDiv({cls:"csv-add-card"}),M=E.createDiv({cls:"csv-add-card-header"});M.createEl("span",{cls:"csv-add-card-title",text:"New entry"});let k=M.createEl("button",{cls:"csv-add-card-close",text:"\xD7"}),L=E.createDiv({cls:"csv-add-rows"}),D={},T={},A=(R,I)=>{let P=L.createDiv({cls:`csv-add-row csv-add-row-${I}`});return P.createEl("span",{cls:"csv-add-row-label",text:Mt(R)}),P};C.forEach(R=>{let P=A(R,"date").createEl("input",{cls:"csv-add-row-control",type:"date"});P.value=new Date().toISOString().split("T")[0],D[R]=P}),x.forEach(R=>{T[R]=!1;let P=A(R,"toggle").createEl("label",{cls:"csv-add-switch"}),H=P.createEl("input",{type:"checkbox",cls:"csv-add-switch-input"});P.createEl("span",{cls:"csv-add-switch-track"}),H.addEventListener("change",()=>{T[R]=H.checked}),D[R]=H}),S.forEach(R=>{let I=A(R,"field"),P=new Set(f.map(F=>{var V;return((V=F[R])!=null?V:"").trim()}).filter(Boolean));if(R!==y&&(h.categoricalColumns?h.categoricalColumns.includes(R):Gt(P.size))){let F=I.createEl("select",{cls:"csv-add-row-control"});F.createEl("option",{text:"\u2014",value:""}),Array.from(P).sort().forEach(B=>F.createEl("option",{text:B,value:B})),F.createEl("option",{text:"+ Custom",value:"__custom__"});let V=L.createDiv({cls:"csv-add-row csv-add-row-custom"});V.style.display="none";let q=V.createEl("input",{cls:"csv-add-row-control",type:"text",placeholder:`Custom ${Mt(R).toLowerCase()}`});L.insertBefore(V,I.nextSibling),F.addEventListener("change",()=>{V.style.display=F.value==="__custom__"?"flex":"none",F.value==="__custom__"&&q.focus()}),D[R]=F,D[`${R}__custom`]=q}else D[R]=I.createEl("input",{cls:"csv-add-row-control",type:"text",placeholder:Mt(R)})}),w.forEach(R=>{let I=L.createDiv({cls:"csv-add-row csv-add-row-notes"});I.createEl("span",{cls:"csv-add-row-label",text:Mt(R)}),D[R]=I.createEl("textarea",{cls:"csv-add-row-textarea",placeholder:"Optional notes\u2026"})});let N=E.createEl("button",{text:"Add",cls:"csv-add-submit"}),O=M.querySelector(".csv-add-card-title"),j=()=>{if(!C.length)return;let R=D[C[0]];if(!R)return;let I=R.value,P=f.find(H=>H[C[0]]===I);O&&O.setText(P?`Updating ${I}`:"New entry"),E.classList.toggle("is-updating",!!P),N.setText(P?"Update":"Add"),x.forEach(H=>{var B;let F=D[H];if(!F)return;let V=((B=P==null?void 0:P[H])!=null?B:"").toLowerCase().trim(),q=V==="1"||V==="true"||V==="yes";F.checked=q,T[H]=q}),[...S,...w].forEach(H=>{var q,B;let F=D[H];if(!F)return;let V=(q=P==null?void 0:P[H])!=null?q:"";if(F instanceof HTMLSelectElement)if(Array.from(F.options).find(U=>U.value===V)){F.value=V;let U=(B=D[`${H}__custom`])==null?void 0:B.closest(".csv-add-row-custom");U&&(U.style.display="none")}else F.value="";else F instanceof HTMLTextAreaElement,F.value=V})};if(j(),C.length){let R=D[C[0]];R==null||R.addEventListener("change",j)}let z=()=>{E.style.display="block",_.style.display="none";let R=E.querySelector(".csv-add-row-control");R==null||R.focus()},K=()=>{E.style.display="none",_.style.display=""};_.addEventListener("click",z),k.addEventListener("click",K),N.addEventListener("click",async()=>{let R={};u.forEach(B=>{var Y,U,G,nt;x.includes(B)?R[B]=T[B]?"1":"0":D[B]instanceof HTMLSelectElement&&D[B].value==="__custom__"?R[B]=(U=(Y=D[`${B}__custom`])==null?void 0:Y.value)!=null?U:"":D[B]instanceof HTMLTextAreaElement?R[B]=D[B].value:R[B]=(nt=(G=D[B])==null?void 0:G.value)!=null?nt:""});let I=C.length>0&&C.some(B=>{var Y;return((Y=R[B])!=null?Y:"").trim()}),P=[...S,...w].some(B=>{var Y;return((Y=R[B])!=null?Y:"").trim()}),H=x.some(B=>T[B]);if(!I&&!P&&!H){new ue.Notice("Please fill at least one field");return}let F=[];try{let B=await s.vault.read(d);F=qt(B).rows}catch(B){new ue.Notice(`Error reading file: ${B}`);return}let V=!1,q=-1;if(C.length>0){let B=C[0],Y=R[B];if(q=F.findIndex(U=>U[B]===Y),q>=0){V=!0;let U=F[q];u.forEach(G=>{var nt;(x.includes(G)||((nt=R[G])!=null?nt:"").trim())&&(U[G]=R[G])})}else F.push(R)}else F.push(R);try{let B=Uo.default.unparse(F,{columns:u});await s.vault.modify(d,B),new ue.Notice(V?`Updated entry for ${R[C[0]]||""}`:`Added entry to ${d.basename}`),f.length=0,f.push(...F),C.length>0?j():(x.forEach(Y=>{T[Y]=!1;let U=D[Y];U&&(U.checked=!1)}),[...S,...w].forEach(Y=>{let U=D[Y];U instanceof HTMLSelectElement?U.selectedIndex=0:(U instanceof HTMLTextAreaElement||U)&&(U.value="");let G=D[`${Y}__custom`];if(G){G.value="";let nt=G.closest(".csv-add-row-custom");nt&&(nt.style.display="none")}})),setTimeout(async()=>{let Y=s.vault.getAbstractFileByPath(n.sourcePath);if(Y instanceof ue.TFile){let U=s.workspace.activeLeaf;U&&await U.openFile(Y,{state:{mode:"preview"}})}},300)}catch(B){new ue.Notice(`Error saving: ${B}`)}})}function ln(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=b=>{c.style.width=Math.max(60,f+b.clientX-u)+"px"},m=b=>{s.settings.columnWidths[l]=Math.max(60,f+b.clientX-u),h.removeEventListener("pointermove",p),h.removeEventListener("pointerup",m),s.persistSettings()};h.addEventListener("pointermove",p),h.addEventListener("pointerup",m)})}),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 m=((g=l[u])!=null?g:"").replace(/#{1,6}\s/g,"").replace(/[*_>`]/g,"").split(` -`).filter(C=>C.trim()).slice(0,3).join(" \xB7 "),b=m?m.slice(0,200)+(m.length>200?"\u2026":""):"+ Add note",x=f.createSpan({text:b});m||x.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 m=(p=l[u])!=null?p:"";f.setText(m),m.length>80&&(f.title=m),xc(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 xc(s,t,e,n){t.addEventListener("click",()=>{var o;t.empty();let i=t.createEl("input",{cls:"csv-inline-input",value:(o=e[n])!=null?o:"",type:"text"});i.focus(),i.select(),i.addEventListener("blur",()=>{e[n]=i.value,s.scheduleSave(),t.empty(),t.setText(i.value||"\u2014")}),i.addEventListener("keydown",r=>{r.key==="Enter"&&i.blur(),r.key==="Escape"&&(t.empty(),t.setText(e[n]||"\u2014"))})})}function cn(s){return!!(s.getCategoryCol()||s.getStatusCol()||Yo(s)||s.authorKey())}function Yo(s){return s.resolveCol(["Rating","rating","Score","score","Score /5","Stars","stars"])}function Ms(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 Go=["watched","read","finished","completed","done","yes","seen"],qo=["watching","reading","in progress","in-progress"],Cc=["dropped","abandoned","dnf"];function _c(s){let t=s.toLowerCase();return Go.includes(t)?"is-done":qo.includes(t)?"is-progress":Cc.includes(t)?"is-dropped":""}function ks(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 ws(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 Xo(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=Yo(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 Go.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 qo.includes(((p=g[i])!=null?p:"").toLowerCase().trim())}).length;f>0&&d(String(f),"in progress")}if(o){let u=ks(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=>Ms(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=ks(e,g=>{var m;let p=((m=g[i])!=null?m:"").trim();return p?[p]:[]}),f=Array.from(u.entries()).sort((g,p)=>p[1]-g[1]).map(([g,p])=>({label:g,count:p,cls:_c(g),onClick:o?()=>h(g,null):void 0}));ws(n,`By ${i.toLowerCase()}`,f,e.length)}if(o){let u=ks(e,g=>{var p;return((p=g[o])!=null?p:"").split(",").map(m=>m.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)}));ws(n,`By ${o.toLowerCase()}`,f,e.length)}if(r){let u=new Map,f=0;if(e.forEach(g=>{var b;let p=Ms(g[r]);if(p===null)return;let m=Math.min(5,Math.max(1,Math.round(p)));u.set(m,((b=u.get(m))!=null?b:0)+1),f++}),f>0){let g=[5,4,3,2,1].filter(p=>{var m;return((m=u.get(p))!=null?m:0)>0}).map(p=>({label:"\u2605".repeat(p),count:u.get(p),cls:"is-rating"}));ws(n,"Ratings",g,f)}}if(l){let u=ks(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}));ws(n,"By year",f,e.length)}}if(a){let u=ks(e,g=>{var m;let p=((m=g[a])!=null?m:"").trim();return p?[p]:[]}),f=Array.from(u.entries()).filter(([,g])=>g>1);if(f.length>=2){let g=f.sort((p,m)=>m[1]-p[1]||p[0].localeCompare(m[0])).slice(0,8).map(([p,m])=>({label:p,count:m}));ws(n,`Top ${a.toLowerCase()}s`,g,e.length)}}}function Ht(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),Ro(s.headers,s.rows,n)}function dn(s,t){let e=Ht(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(m=>!s.isNotesCol(m)).forEach(m=>{let b=l.createEl("option",{text:m===n?`${m} (default)`:m,value:m});m===e&&(b.selected=!0)}),l.addEventListener("change",()=>{let m=s.fileCfg;m.kanbanGroupCol=l.value===n?void 0:l.value,s.saveFileCfg(m),s.renderView(!0)});let c=Ao(e,r.map(m=>{var b;return(b=m[e])!=null?b:""})),d=m=>{var C;let b=(C=m[e])!=null?C:"",x;if(c){let w=Po(b);x=w?[w]:[]}else x=b.split(",").map(w=>w.trim()).filter(Boolean);return x.length||(x=["\u2014"]),x},h=new Set;r.forEach(m=>d(m).forEach(b=>h.add(b)));let u=Array.from(h).sort();if(!u.length){let m=t.createDiv({cls:"csv-empty-state"});m.createEl("p",{text:s.searchQuery?"No matching entries found.":`No "${e}" values found.`}),s.searchQuery&&m.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(m=>{var b;return(b=m[o])!=null?b:""}).filter(Boolean)])).filter(m=>r.some(b=>{var x;return((x=b[o])!=null?x:"")==m})):[],p=t.createDiv({cls:"csv-kanban-board"});u.forEach(m=>{let b=r.filter(S=>d(S).includes(m));if(!b.length)return;let x=p.createDiv({cls:"csv-kanban-col"}),C=x.createDiv({cls:"csv-kanban-col-header"});C.createDiv({cls:"csv-kanban-col-title",text:m}),C.createDiv({cls:"csv-kanban-col-count",text:String(b.length)});let w=x.createDiv({cls:"csv-kanban-col-body"});if(o&&g.length){g.forEach(v=>{let _=b.filter(M=>{var k;return((k=M[o])!=null?k:"")===v});if(!_.length)return;let E=w.createDiv({cls:"csv-kanban-status-group"});E.createDiv({cls:`csv-kanban-status-label status-${v.toLowerCase().replace(/\s+/g,"-")}`,text:v}),_.forEach(M=>ci(s,E,M,o,e))});let S=new Set(g),y=b.filter(v=>{var _;return!S.has((_=v[o])!=null?_:"")});if(y.length){let v=w.createDiv({cls:"csv-kanban-status-group"});v.createDiv({cls:"csv-kanban-status-label",text:"\u2014"}),y.forEach(_=>ci(s,v,_,o,e))}}else b.forEach(S=>ci(s,w,S,o,e))})}function ci(s,t,e,n,i){var v,_,E,M,k,L,D;let o=t.createDiv({cls:"csv-kanban-card"}),r=s.getNotesCol(),a=(_=(v=s.getImageCol)==null?void 0:v.call(s))!=null?_:null;if(a){let T=tn(s.app,(E=e[a])!=null?E:"",(k=(M=s.file)==null?void 0:M.path)!=null?k:"");if(T){let A=o.createEl("img",{cls:"csv-kanban-card-img",attr:{src:T,loading:"lazy",alt:""}});A.addEventListener("error",()=>A.remove())}}let l=o.createDiv({cls:"csv-kanban-card-title-row"});l.createDiv({cls:`csv-kanban-card-title ${(L=s.isHighlighted)!=null&&L.call(s,e)?"csv-title-highlight":""}`,text:s.getTitle(e)}).addEventListener("click",T=>{T.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",T=>{T.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)),m=o.createDiv({cls:"csv-kanban-card-meta"});s.headers.forEach(T=>{if(p.has(T)||s.isNotesCol(T))return;let A=m.createDiv({cls:"csv-kanban-chip"});if(A.createSpan({cls:"csv-chip-label",text:T+": "}),s.isSelectCol(T)){let N=A.createSpan({cls:`csv-chip-value csv-chip-select${e[T]?"":" csv-chip-value--empty"}`,text:e[T]||"\u2014"});N.addEventListener("click",O=>{O.stopPropagation(),It(N,e[T],s.getColumnValues(T),j=>{e[T]=j,N.setText(j||"\u2014"),N.classList.toggle("csv-chip-value--empty",!j),s.scheduleSave()},s.contentEl,{multi:Et(T)})})}else{let N=e[T]?e[T].length>40?e[T].slice(0,38)+"\u2026":e[T]:"\u2014",O=A.createSpan({cls:`csv-chip-value${e[T]?"":" csv-chip-value--empty"}`,text:N});e[T]&&e[T].length>40&&(O.title=e[T])}});let b=s.getNotesCol(),x=!!(b&&((D=e[b])!=null&&D.trim())),C=o.createDiv({cls:"csv-kanban-notes-preview"});if(x&&b){let T=e[b].replace(/#{1,6}\s/g,"").replace(/[*_>`]/g,"").replace(/\n+/g," ").trim();C.setText(T.slice(0,120)+(T.length>120?"\u2026":"")),C.title="Click to edit"}else C.addClass("csv-kanban-notes-preview--empty"),b&&C.setText("+ Add note");let w=o.createDiv({cls:"csv-kanban-notes-editor"});w.style.display="none";let S=()=>{var j,z,K;let T=s.contentEl.querySelector(".csv-content-area"),A=(j=T==null?void 0:T.scrollLeft)!=null?j:0,N=(z=T==null?void 0:T.scrollTop)!=null?z:0;C.style.display="none",w.style.display="block",w.empty();let O=w.createEl("textarea",{cls:"csv-notes-textarea"});O.value=(K=b?e[b]:"")!=null?K:"",O.addEventListener("click",$=>$.stopPropagation()),O.addEventListener("mousedown",$=>$.stopPropagation()),O.addEventListener("input",()=>{O.style.height="auto",O.style.height=O.scrollHeight+"px"}),O.addEventListener("keydown",$=>{$.key==="Escape"&&y(O.value,T,A,N)}),O.addEventListener("blur",()=>y(O.value,T,A,N)),O.focus({preventScroll:!0}),O.setSelectionRange(0,0),O.scrollTop=0,requestAnimationFrame(()=>{O.style.height="auto",O.style.height=Math.max(120,O.scrollHeight)+"px"})},y=(T,A,N,O)=>{if(b&&(e[b]=T,s.scheduleSave()),w.style.display="none",C.style.display="",T.trim()){let j=T.replace(/#{1,6}\s/g,"").replace(/[*_>`]/g,"").replace(/\n+/g," ").trim();C.setText(j.slice(0,120)+(j.length>120?"\u2026":"")),C.removeClass("csv-kanban-notes-preview--empty"),C.title="Click to edit"}else C.addClass("csv-kanban-notes-preview--empty"),C.setText(b?"+ Add note":""),C.removeAttribute("title");A&&(A.scrollLeft=N,A.scrollTop=O,requestAnimationFrame(()=>{A.scrollLeft=N,A.scrollTop=O,requestAnimationFrame(()=>{A.scrollLeft=N,A.scrollTop=O})}),setTimeout(()=>{A.scrollLeft=N,A.scrollTop=O},50))};C.addEventListener("click",T=>{if(T.stopPropagation(),b&&matchMedia("(pointer: coarse)").matches){s.openNoteExpander(e,b);return}S()}),o.addEventListener("contextmenu",T=>s.openRowContextMenu(e,T))}function hn(s,t){var E,M;let e=Ht(s),n=s.getStatusCol(),i=(E=s.titleKey())!=null?E: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 D;((D=k[e])!=null?D:"").split(",").map(T=>T.trim()).filter(Boolean).forEach(T=>r.add(T))});let a=new Set;n&&s.rows.forEach(k=>{var D;let L=((D=k[n])!=null?D:"").trim();L&&a.add(L)});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"]),m=s.resolveCol(["Rating","rating","Score","score","Score /5","Stars","stars"]),b=s.resolveCol(["Theme","theme","Tags","tags","Tag","tag","Mood","mood"]),x=(M=s.fileCfg.librarySort)!=null?M:"status",C=l.createEl("select",{cls:"csv-library-filter-select"}),w=[["status","Sort: Status"],["title","Sort: Title"]];m&&w.push(["rating","Sort: Rating"]),p&&w.push(["year","Sort: Year"]),w.forEach(([k,L])=>{let D=C.createEl("option",{text:L,value:k});k===x&&(D.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 y=s.rows.filter(k=>{var L,D;if(s.libraryStatusFilter!=="all"&&n){let T=((L=k[n])!=null?L:"").toLowerCase();if(s.libraryStatusFilter==="__done__"){if(!d.includes(T))return!1}else if(s.libraryStatusFilter==="__inprogress__"){if(!h.includes(T))return!1}else if(s.libraryStatusFilter==="__notstarted__"){if(d.includes(T)||h.includes(T))return!1}else if(T!==s.libraryStatusFilter.toLowerCase())return!1}if(s.libraryGenreFilter!=="all"&&!((D=k[e])!=null?D:"").split(",").map(A=>A.trim().toLowerCase()).includes(s.libraryGenreFilter.toLowerCase()))return!1;if(s.searchQuery.trim()){let T=s.searchQuery.toLowerCase().trim();if(!s.headers.some(A=>{var N;return((N=k[A])!=null?N:"").toLowerCase().includes(T)}))return!1}return!0});(s.libraryStatusFilter!=="all"||s.libraryGenreFilter!=="all"||s.searchQuery.trim())&&t.createDiv({cls:"csv-library-result-count",text:`Showing ${y.length} of ${s.rows.length} entries`});let v={};y.forEach(k=>{var D;let L=s.libraryGenreFilter!=="all"?[s.libraryGenreFilter]:((D=k[e])!=null?D:"Uncategorized").split(",").map(T=>T.trim()).filter(Boolean);L.length===0&&L.push("Uncategorized"),L.forEach(T=>{v[T]||(v[T]=[]),v[T].push(k)})});let _=t.createDiv({cls:"csv-library-sections"});if(Object.keys(v).sort().forEach(k=>{var X,R,I,P,H;let L=v[k],D=_.createEl("details",{cls:"csv-library-section"}),T=k.toLowerCase(),A=((X=s.fileCfg.collapsedGroups)!=null?X:[]).map(F=>F.toLowerCase());D.open=!((R=s.collapsedGroups)!=null&&R.has(T)||A.includes(T)),D.addEventListener("toggle",()=>{var Y;let F=s.fileCfg,V=((Y=F.collapsedGroups)!=null?Y:[]).map(U=>U.toLowerCase()),q=new Set(V);D.open?q.delete(T):q.add(T);let B=Array.from(q);B.length===V.length&&B.every(U=>V.includes(U))||(F.collapsedGroups=B,s.saveFileCfg(F))});let N=D.createEl("summary",{cls:"csv-library-section-header"});N.innerHTML=`\u25B6 ${k} ${L.length}`;let O=D.createDiv({cls:"csv-library-grid"}),j=(F,V)=>{var q,B;return((q=F[i])!=null?q:"").localeCompare((B=V[i])!=null?B:"")},z=(F,V)=>F===null&&V===null?0:F===null?1:V===null?-1:V-F;L.sort((F,V)=>{var q,B,Y,U;if(x==="title")return j(F,V);if(x==="rating"&&m)return z(Ms((q=F[m])!=null?q:""),Ms((B=V[m])!=null?B:""))||j(F,V);if(x==="year"&&p){let G=nt=>{var st;let J=((st=nt[p])!=null?st:"").match(/\d{4}/);return J?parseInt(J[0],10):null};return z(G(F),G(V))||j(F,V)}if(n){let G=((Y=F[n])!=null?Y:"").toLowerCase(),nt=((U=V[n])!=null?U:"").toLowerCase(),J=d.includes(G),st=d.includes(nt);if(J!==st)return J?-1:1;let lt=h.includes(G),Ot=h.includes(nt);if(lt!==Ot)return lt?-1:1}return j(F,V)});let K=[o,p,m,b].filter(F=>!!F),$=(I=s.fileCfg.cardFields)!=null?I:K,Q=(H=(P=s.getImageCol)==null?void 0:P.call(s))!=null?H:null;L.forEach(F=>{var U,G,nt,J,st,lt,Ot,Ft;let V=O.createDiv({cls:"csv-library-card"});if(Q){let dt=tn(s.app,(U=F[Q])!=null?U:"",(nt=(G=s.file)==null?void 0:G.path)!=null?nt:"");if(dt){let it=V.createEl("img",{cls:"csv-library-card-img",attr:{src:dt,loading:"lazy",alt:""}});it.addEventListener("error",()=>it.remove())}}let q=V.createDiv({cls:`csv-library-card-title ${(J=s.isHighlighted)!=null&&J.call(s,F)?"csv-title-highlight":""}`});if(n){let dt=((st=F[n])!=null?st:"").toLowerCase();d.includes(dt)&&q.createSpan({cls:"csv-library-done-dot"})}q.createSpan({text:(lt=F[i])!=null?lt:"Untitled"});let B=[],Y=[];for(let dt of $){if(!dt)continue;let it=String((Ot=F[dt])!=null?Ot:"").trim();if(it)if(dt===m){let vt=Lo(it,dt);vt&&V.createDiv({cls:"csv-library-card-rating",text:vt})}else if(dt===b)Y.push(...it.split(",").map(vt=>vt.trim()).filter(Boolean));else if(dt===p){let vt=it.match(/\d{4}/);B.push(vt?vt[0]:it)}else B.push(it)}if(B.length&&V.createDiv({cls:"csv-library-card-meta",text:B.join(" \xB7 ")}),s.libraryGenreFilter!=="all"){let dt=((Ft=F[e])!=null?Ft:"").split(",").map(it=>it.trim()).filter(it=>it&&it.toLowerCase()!==s.libraryGenreFilter.toLowerCase());Y.push(...dt)}if(Y.length){let dt=V.createDiv({cls:"csv-library-card-tags"});Y.slice(0,3).forEach(it=>{dt.createSpan({cls:"csv-library-card-tag",text:it})})}V.addEventListener("click",()=>{var dt;s.openNoteExpander(F,(dt=s.getNotesCol())!=null?dt:"")}),V.addEventListener("contextmenu",dt=>s.openRowContextMenu(F,dt))})}),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 pn=require("obsidian");var Te=require("obsidian");var di=`--- +`):s}function Lf(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 Ya(s,t){let e=s.chart.ctx,{body:n,footer:i,title:o}=s,{boxWidth:r,boxHeight:a}=t,l=mt(t.bodyFont),c=mt(t.titleFont),d=mt(t.footerFont),h=o.length,u=i.length,f=n.length,g=_t(t.padding),p=g.height,m=0,b=n.reduce((w,S)=>w+S.before.length+S.lines.length+S.after.length,0);if(b+=s.beforeBody.length+s.afterBody.length,h&&(p+=h*c.lineHeight+(h-1)*t.titleSpacing+t.titleMarginBottom),b){let w=t.displayColors?Math.max(a,l.lineHeight):l.lineHeight;p+=f*w+(b-f)*l.lineHeight+(b-1)*t.bodySpacing}u&&(p+=t.footerMarginTop+u*d.lineHeight+(u-1)*t.footerSpacing);let C=0,x=function(w){m=Math.max(m,e.measureText(w).width+C)};return e.save(),e.font=c.string,at(s.title,x),e.font=l.string,at(s.beforeBody.concat(s.afterBody),x),C=t.displayColors?r+2+t.boxPadding:0,at(n,w=>{at(w.before,x),at(w.lines,x),at(w.after,x)}),C=0,e.font=d.string,at(s.footer,x),e.restore(),m+=g.width,{width:m,height:p}}function Af(s,t){let{y:e,height:n}=t;return es.height-n/2?"bottom":"center"}function Rf(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 Pf(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"),Rf(c,s,t,e)&&(c="center"),c}function Ga(s,t,e){let n=e.yAlign||t.yAlign||Af(s,e);return{xAlign:e.xAlign||t.xAlign||Pf(s,t,e,n),yAlign:n}}function Of(s,t){let{x:e,width:n}=s;return t==="right"?e-=n:t==="center"&&(e-=n/2),e}function Ff(s,t,e){let{y:n,height:i}=s;return t==="top"?n+=e:t==="bottom"?n-=i+e:n-=i/2,n}function qa(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}=Ce(r),g=Of(t,a),p=Ff(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:bt(g,0,n.width-t.width),y:bt(p,0,n.height-t.height)}}function jn(s,t,e){let n=_t(e.padding);return t==="center"?s.x+s.width/2:t==="right"?s.x+s.width-n.right:s.x+n.left}function Xa(s){return te([],de(s))}function If(s,t,e){return ce(s,{tooltip:t,tooltipItems:e,type:"tooltip"})}function Qa(s,t){let e=t&&t.dataset&&t.dataset.tooltip&&t.dataset.tooltip.callbacks;return e?s.override(e):s}function Tt(s,t,e,n){let i=s[t].call(e,n);return typeof i=="undefined"?Vl[t].call(e,n):i}function Nf(s,t,e,n){let i=s.indexOf(t);if(i===-1)return Vf(s,t,e,n);let o=s.lastIndexOf(t);return i!==o?e:i}function Za(s){let t=this.getLabels();return s>=0&&sg&&(S=Ti(E*S/g/f)*f),tt(l)||(y=Math.pow(10,l),S=Math.ceil(S*y)/y),i==="ticks"?(v=Math.floor(p/S)*S,_=Math.ceil(m/S)*S):(v=p,_=m),b&&C&&o&&Nr((a-r)/o,S/1e3)?(E=Math.round(Math.min((a-r)/S,d)),S=(a-r)/E,v=r,_=a):x?(v=b?r:v,_=C?a:_,E=c-1,S=(_-v)/E):(E=(_-v)/S,as(E,Math.round(E),S/1e3)?E=Math.round(E):E=Math.ceil(E));let M=Math.max(Ai(S),Ai(v));y=Math.pow(10,tt(l)?M:l),v=Math.round(v*y)/y,_=Math.round(_*y)/y;let k=0;for(b&&(u&&v!==r?(e.push({value:r}),va)break;e.push({value:L})}return C&&u&&_!==a?e.length&&as(e[e.length-1].value,a,Ja(a,w,s))?e[e.length-1].value=a:e.push({value:a}):(!C||_===a)&&e.push({value:_}),e}function Ja(s,t,{horizontal:e,minRotation:n}){let i=$t(n),o=(e?Math.sin(i):Math.cos(i))||.001,r=.75*t*(""+s).length;return Math.min(t/o,r)}function tl(s){return s/Math.pow(10,Zs(s))===1}function el(s,t,e){let n=Math.pow(10,e),i=Math.floor(s/n);return Math.ceil(t/n)-i}function zf(s,t){let e=t-s,n=Zs(e);for(;el(s,t,n)>10;)n++;for(;el(s,t,n)<10;)n--;return Math.min(n,Zs(s))}function $f(s,{min:t,max:e}){t=Dt(s.min,t);let n=[],i=Zs(t),o=zf(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=Dt(s.min,Math.round((l+d+h*Math.pow(10,o))*r)/r);for(;u=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=Dt(s.max,u);return n.push({value:f,major:tl(f),significand:h}),n}function So(s){let t=s.ticks;if(t.display&&s.display){let e=_t(t.backdropPadding);return Q(t.font&&t.font.size,ft.font.size)+e.height}return 0}function Wf(s,t,e){return e=ht(e)?e:[e],{w:Yr(s,t.string,e),h:e.length*t.lineHeight}}function sl(s,t,e,n,i){return s===n||s===i?{start:t-e/2,end:t+e/2}:si?{start:t-e,end:t}:{start:t,end:t+e}}function jf(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?ot/o:0;for(let l=0;lt.r&&(a=(n.end-t.r)/o,s.r=Math.max(s.r,t.r+a)),i.startt.b&&(l=(i.end-t.b)/r,s.b=Math.max(s.b,t.b+l))}function Kf(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(Ln(xt(l.angle+pt))),d=Qf(l.y,a.h,c),h=qf(c),u=Xf(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 Yf(s,t){if(!t)return!0;let{left:e,top:n,right:i,bottom:o}=s;return!(Qt({x:e,y:n},t)||Qt({x:e,y:o},t)||Qt({x:i,y:n},t)||Qt({x:i,y:o},t))}function Gf(s,t,e){let n=[],i=s._pointLabels.length,o=s.options,{centerPointLabels:r,display:a}=o.pointLabels,l={extra:So(o)/2,additionalAngle:r?ot/i:0},c;for(let d=0;d270||e<90)&&(s-=t),s}function Zf(s,t,e){let{left:n,top:i,right:o,bottom:r}=e,{backdropColor:a}=t;if(!tt(a)){let l=Ce(t.borderRadius),c=_t(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(),hs(s,{x:d,y:h,w:u,h:f,radius:l}),s.fill()):s.fillRect(d,h,u,f)}}function Jf(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));Zf(e,r,o);let a=mt(r.font),{x:l,y:c,textAlign:d}=o;xe(e,s._pointLabels[i],l,c+a.lineHeight/2,a,{color:r.color,textAlign:d,textBaseline:"middle"})}}function Hl(s,t,e,n){let{ctx:i}=s;if(e)i.arc(s.xCenter,s.yCenter,t,0,ut);else{let o=s.getPointPosition(0,t);i.moveTo(o.x,o.y);for(let r=1;r=At.indexOf(e);o--){let r=At[o];if(si[r].common&&s._adapter.diff(i,n,r)>=t-1)return r}return At[e?At.indexOf(e):0]}function ng(s){for(let t=At.indexOf(s)+1,e=At.length;t=t?e[n]:e[i];s[o]=!0}}function ig(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 al(s,t,e){let n=[],i={},o=t.length,r,a;for(r=0;r=s[n].pos&&t<=s[i].pos&&({lo:n,hi:i}=Xt(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}=Xt(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 fo,ee,ca,oh,Gn,Gs,no,ga,mh,Lt,Ve,Ne,ne,Be,ke,gs,He,ze,dl,go,hl,ul,fl,St,qs,qn,Kn,Bh,_a,pl,Xs,Sa,Qn,Rt,su,Ea,ka,De,ps,po,Ut,mo,La,xl,js,yo,_u,Eu,ku,Yn,Fa,se,Se,$u,Kt,$e,We,kl,Co,Na,Dl,Ll,Jn,Rl,Ka,Ef,ti,Ol,Qs,Fl,Wn,Il,Ks,Vl,Ys,Nl,Bl,Vf,Bf,ms,xs,bs,Zs,Ie,vs,Ee,si,At,Me,ys,zl,og,Wl=oi(()=>{la();fo=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=Fi.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)}},ee=new fo,ca="transparent",oh={boolean(s,t,e){return e>.5?t:s},color(s,t,e){let n=Hi(s||ca),i=n.valid&&Hi(t||ca);return i&&i.valid?i.mix(n,e).hexString():t},number(s,t,e){return s+(t-s)*e}},Gn=class{constructor(t,e,n,i){let o=e[n];i=us([t.to,i,o,t.from]);let r=us([t.from,o,i]);this._active=!0,this._fn=t.fn||oh[t.type||typeof r],this._easing=ss[t.easing]||ss.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=us([t.to,e,i,t.from]),this._from=us([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||e1?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{let o=t[i];if(!et(o))return;let r={};for(let a of e)r[a]=o[a];(ht(o.properties)&&o.properties||[i]).forEach(a=>{(a===i||!n.has(a))&&n.set(a,r)})})}_animateOptions(t,e){let n=e.options,i=ah(t,n);if(!i)return[];let o=this._createAnimations(i,n);return n.$shared&&rh(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 Gn(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 ee.add(this._chart,n),!0}};no=s=>s==="reset"||s==="none",ga=(s,t)=>t?s:Object.assign({},s),mh=(s,t,e)=>s&&!t.hidden&&t._stacked&&{keys:ll(e,!0),values:null},Lt=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=eo(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&&Hs(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=Q(n.xAxisID,so(t,"x")),r=e.yAxisID=Q(n.yAxisID,so(t,"y")),a=e.rAxisID=Q(n.rAxisID,so(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&&Pi(this._data,this),t._stacked&&Hs(t)}_dataCheck(){let t=this.getDataset(),e=t.data||(t.data=[]),n=this._data;if(et(e)){let i=this._cachedMeta;this._data=dh(e,i)}else if(n!==e){if(n){Pi(n,this);let i=this._cachedMeta;Hs(i),i._parsed=[]}e&&Object.isExtensible(e)&&Wr(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=eo(e.vScale,e),e.stack!==n.stack&&(i=!0,Hs(e),e.stack=n.stack),this._resyncElements(t),(i||o!==e._stacked)&&(fa(this,e._parsed),e._stacked=eo(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{ht(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]p||h=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=0&&tthis.getContext(n,i,e),p=c.resolveNamedOptions(u,f,g,h);return p.$shared&&(p.$shared=l,o[r]=Object.freeze(ga(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 Gs(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||no(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){no(i)?Object.assign(t,n):this._resolveAnimations(e,i).update(t,n)}updateSharedOptions(t,e,n){t&&!no(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{for(c.length+=e,a=c.length-1;a>=r;a--)c[a]=c[a-e]};for(l(o),a=t;ad.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[Q(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=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+n[l];if(et(n[t])){let{key:l="value"}=this._parsing;o=c=>+le(n[c],l)}let r,a;for(r=t,a=t+e;r0&&!isNaN(t)?ut*(Math.abs(t)/e):0}getLabelAndValue(t){let e=this._cachedMeta,n=this.chart,i=n.data.labels||[],o=cs(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;it!=="spacing",_indexable:t=>t!=="spacing"&&!t.startsWith("borderDash")&&!t.startsWith("hoverBorderDash")}),W(ne,"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()}}}});Be=class extends Lt{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}=Vi(e,i,r);this._drawStart=a,this._drawCount=l,Ni(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,m=Pe(g)?g:Number.POSITIVE_INFINITY,b=this.chart._animationsDisabled||o||i==="none",C=e+n,x=t.length,w=e>0&&this.getParsed(e-1);for(let S=0;S=C){v.skip=!0;continue}let _=this.getParsed(S),E=tt(_[f]),M=v[u]=r.getPixelForValue(_[u],S),k=v[f]=o||E?a.getBasePixel():a.getPixelForValue(l?this.applyStack(a,_,l):_[f],S);v.skip=isNaN(M)||isNaN(k)||E,v.stop=S>0&&Math.abs(_[u]-w[u])>m,p&&(v.parsed=_,v.raw=c.data[S]),h&&(v.options=d||this.resolveDataElementOptions(S,y.active?"active":i)),b||this.updateElement(y,S,v,i),w=_}}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()}};W(Be,"id","line"),W(Be,"defaults",{datasetElementType:"line",dataElementType:"point",showLine:!0,spanGaps:!1}),W(Be,"overrides",{scales:{_index_:{type:"category"},_value_:{type:"linear"}}});ke=class extends Lt{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=cs(e._parsed[t].r,n.options.locale);return{label:i[t]||"",value:o}}parseObjectData(t,e,n,i){return Yi.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)&&(oe.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*ot,f=u,g,p=360/this.countVisibleElements();for(g=0;g{!isNaN(this.getParsed(i).r)&&this.chart.getDataVisibility(i)&&e++}),e}_computeAngle(t,e,n){return this.chart.getDataVisibility(t)?$t(this.resolveDataElementOptions(t,e).angle||n):0}};W(ke,"id","polarArea"),W(ke,"defaults",{dataElementType:"arc",animation:{animateRotate:!0,animateScale:!0},animations:{numbers:{type:"number",properties:["x","y","startAngle","endAngle","innerRadius","outerRadius"]}},indexAxis:"r",startAngle:0}),W(ke,"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}}});gs=class extends ne{};W(gs,"id","pie"),W(gs,"defaults",{cutout:0,rotation:0,circumference:360,radius:"100%"});He=class extends Lt{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 Yi.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;a0&&this.getParsed(e-1);for(let w=e;w0&&Math.abs(y[f]-x[f])>b,m&&(v.parsed=y,v.raw=c.data[w]),u&&(v.options=h||this.resolveDataElementOptions(w,S.active?"active":i)),C||this.updateElement(S,w,v,i),x=y}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}};W(ze,"id","scatter"),W(ze,"defaults",{datasetElementType:!1,dataElementType:"point",showLine:!1,fill:!1}),W(ze,"overrides",{interaction:{mode:"point"},scales:{x:{type:"linear"},y:{type:"linear"}}});dl=Object.freeze({__proto__:null,BarController:Ve,BubbleController:Ne,DoughnutController:ne,LineController:Be,PieController:gs,PolarAreaController:ke,RadarController:He,ScatterController:ze});go=class s{constructor(t){W(this,"options");this.options=t||{}}static override(t){Object.assign(s.prototype,t)}init(){}formats(){return Fe()}parse(){return Fe()}format(){return Fe()}add(){return Fe()}diff(){return Fe()}startOf(){return Fe()}endOf(){return Fe()}},hl={_date:go};ul={evaluateInteractionItems:Js,modes:{index(s,t,e,n){let i=_e(t,s),o=e.axis||"x",r=e.includeInvisible||!1,a=e.intersect?oo(s,i,o,n,r):ro(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=_e(t,s),o=e.axis||"xy",r=e.includeInvisible||!1,a=e.intersect?oo(s,i,o,n,r):ro(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{typeof p.beforeLayout=="function"&&p.beforeLayout()});let d=l.reduce((p,m)=>m.box.options&&m.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);gl(u,_t(n));let f=Object.assign({maxPadding:u,w:o,h:r,x:i.left,y:i.top},i),g=Oh(l.concat(c),h);Us(a.fullSize,f,h,g),Us(l,f,h,g),Us(c,f,h,g)&&Us(l,f,h,g),Vh(f),Ca(a.leftAndTop,f,h,g),f.x+=f.w,f.y+=f.h,Ca(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},at(a.chartArea,p=>{let m=p.box;Object.assign(m,s.chartArea),m.update(f.w,f.h,{left:0,top:0,right:0,bottom:0})})}},qs=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){}},qn=class extends qs{acquireContext(t){return t&&t.getContext&&t.getContext("2d")||null}updateConfig(t){t.options.animation=!1}},Kn="$chartjs",Bh={touchstart:"mousedown",touchmove:"mousemove",touchend:"mouseup",pointerenter:"mouseenter",pointerdown:"mousedown",pointermove:"mousemove",pointerup:"mouseup",pointerleave:"mouseout",pointerout:"mouseout"},_a=s=>s===null||s==="";pl=na?{passive:!0}:!1;Xs=new Map,Sa=0;Qn=class extends qs{acquireContext(t,e){let n=t&&t.getContext&&t.getContext("2d");return n&&n.canvas===t?(Hh(t,e),n):null}releaseContext(t){let e=t.canvas;if(!e[Kn])return!1;let n=e[Kn].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[Kn],!0}addEventListener(t,e,n){this.removeEventListener(t,e);let i=t.$proxies||(t.$proxies={}),r={attach:jh,detach:Uh,resize:Gh}[e]||qh;i[e]=r(t,e,n)}removeEventListener(t,e){let n=t.$proxies||(t.$proxies={}),i=n[e];if(!i)return;({attach:ao,detach:ao,resize:ao}[e]||$h)(t,e,i),n[e]=void 0}getDevicePixelRatio(){return window.devicePixelRatio}getMaximumSize(t,e,n,i){return sa(t,e,n,i)}isAttached(t){let e=t&&Nn(t);return!!(e&&e.isConnected)}};Rt=class{constructor(){W(this,"x");W(this,"y");W(this,"active",!1);W(this,"options");W(this,"$animations")}tooltipPosition(t){let{x:e,y:n}=this.getProps(["x","y"],t);return{x:e,y:n}}hasValue(){return Pe(this.x)&&Pe(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}};W(Rt,"defaults",{}),W(Rt,"defaultRoutes");su=s=>s==="left"?"right":s==="right"?"left":s,Ea=(s,t,e)=>t==="top"||t==="left"?s[t]+e:s[t]-e,ka=(s,t)=>Math.min(t||s,s);De=class s extends Rt{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=Dt(t,Number.POSITIVE_INFINITY),e=Dt(e,Number.NEGATIVE_INFINITY),n=Dt(n,Number.POSITIVE_INFINITY),i=Dt(i,Number.NEGATIVE_INFINITY),{min:Dt(t,n),max:Dt(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;ln?n:e,n=i&&e>n?e:n,{min:Dt(e,Dt(n,e)),max:Dt(n,Dt(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=Xr(this,o,i),this._dataLimitsCached=!0),this.beforeBuildTicks(),this.ticks=this.buildTicks()||[],this.afterBuildTicks();let l=a=o||n<=1||!this.isHorizontal()){this.labelRotation=i;return}let d=this._getLabelSizes(),h=d.widest.width,u=d.highest.height,f=bt(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-Ws(t.grid)-e.padding-Ma(t.title,this.chart.options.font),c=Math.sqrt(h*h+u*u),r=Ln(Math.min(Math.asin(bt((d.highest.height+6)/a,-1,1)),Math.asin(bt(l/c,-1,1))-Math.asin(bt(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=Ma(i,e.options.font);if(a?(t.width=this.maxWidth,t.height=Ws(o)+l):(t.height=this.maxHeight,t.width=Ws(o)+l),n.display&&this.ticks.length){let{first:c,last:d,widest:h,highest:u}=this._getLabelSizes(),f=n.padding*2,g=$t(this.labelRotation),p=Math.cos(g),m=Math.sin(g);if(a){let b=n.mirror?0:m*h.width+p*u.height;t.height=Math.min(this.maxHeight,t.height+b+f)}else{let b=n.mirror?0:p*h.width+m*u.height;t.width=Math.min(this.maxWidth,t.width+b+f)}this._calculatePadding(c,d,m,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({width:r[E]||0,height:a[E]||0});return{first:_(0),last:_(e-1),widest:_(y),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 Br(this._alignToPixels?ye(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&&ta*i?a/n:l/i:l*i0}_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=Ws(o),f=[],g=a.setContext(this.getContext()),p=g.display?g.width:0,m=p/2,b=function(N){return ye(n,N,p)},C,x,w,S,y,v,_,E,M,k,L,D;if(r==="top")C=b(this.bottom),v=this.bottom-u,E=C-m,k=b(t.top)+m,D=t.bottom;else if(r==="bottom")C=b(this.top),k=t.top,D=b(t.bottom)-m,v=C+m,E=this.top+u;else if(r==="left")C=b(this.right),y=this.right-u,_=C-m,M=b(t.left)+m,L=t.right;else if(r==="right")C=b(this.left),M=t.left,L=b(t.right)-m,y=C+m,_=this.left+u;else if(e==="x"){if(r==="center")C=b((t.top+t.bottom)/2+.5);else if(et(r)){let N=Object.keys(r)[0],O=r[N];C=b(this.chart.scales[N].getPixelForValue(O))}k=t.top,D=t.bottom,v=C+m,E=v+u}else if(e==="y"){if(r==="center")C=b((t.left+t.right)/2);else if(et(r)){let N=Object.keys(r)[0],O=r[N];C=b(this.chart.scales[N].getPixelForValue(O))}y=C-m,_=y-u,M=t.left,L=t.right}let T=Q(i.ticks.maxTicksLimit,h),A=Math.max(1,Math.ceil(h/T));for(x=0;x0&&(P-=R/2);break}$={left:P,top:F,width:R+X.width,height:Z+X.height,color:A.backdropColor}}m.push({label:w,font:E,textOffset:L,options:{rotation:p,color:O,strokeColor:j,strokeWidth:z,textAlign:K,textBaseline:D,translation:[S,y],backdrop:$}})}return m}_getXAxisLabelAlignment(){let{position:t,ticks:e}=this.options;if(-$t(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{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{let o=n||this._getRegistryForType(i);n||o.isForType(i)||o===this.plugins&&i.id?this._exec(t,o,i):at(i,r=>{let a=n||this._getRegistryForType(r);this._exec(t,a,r)})})}_exec(t,e,n){let i=Tn(t);ct(n["before"+i],[],n),e[t](n),ct(n["after"+i],[],n)}_getRegistryForType(t){for(let e=0;eo.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")}};La=new Map,xl=new Set;js=(s,t,e)=>{let n=le(t,e);n!==void 0&&s.add(n)},yo=class{constructor(t){this._config=Cu(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=yl(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(),vl(t)}clearCache(){this._scopeCache.clear(),this._resolverCache.clear()}datasetScopeKeys(t){return $n(t,()=>[[`datasets.${t}`,""]])}datasetAnimationScopeKeys(t,e){return $n(`${t}.transition.${e}`,()=>[[`datasets.${t}.transitions.${e}`,`transitions.${e}`],[`datasets.${t}`,""]])}datasetElementScopeKeys(t,e){return $n(`${t}-${e}`,()=>[[`datasets.${t}.elements.${e}`,`datasets.${t}`,`elements.${e}`,""]])}pluginScopeKeys(t){let e=t.id,n=this.type;return $n(`${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=>js(l,t,h))),d.forEach(h=>js(l,i,h)),d.forEach(h=>js(l,ve[o]||{},h)),d.forEach(h=>js(l,ft,h)),d.forEach(h=>js(l,Pn,h))});let c=Array.from(l);return c.length===0&&c.push(Object.create(null)),xl.has(e)&&r.set(e,c),c}chartOptionScopes(){let{options:t,type:e}=this;return[t,ve[e]||{},ft.datasets[e]||{},{type:e},ft,Pn]}resolveNamedOptions(t,e,n,i=[""]){let o={$shared:!0},{resolver:r,subPrefixes:a}=Aa(this._resolverCache,t,i),l=r;if(Su(r,e)){o.$shared=!1,n=re(n)?n():n;let c=this.createResolver(t,n,a);l=Re(r,n,c)}for(let c of e)o[c]=l[c];return o}createResolver(t,e,n=[""],i){let{resolver:o}=Aa(this._resolverCache,t,n);return et(e)?Re(o,e,void 0,i):o}};_u=s=>et(s)&&Object.getOwnPropertyNames(s).some(t=>re(s[t]));Eu="4.5.1",ku=["top","bottom","left","right","chartArea"];Yn={},Fa=s=>{let t=Cl(s);return Object.values(Yn).filter(e=>e.canvas===t).pop()};se=class{static register(...t){Ut.add(...t),Ia()}static unregister(...t){Ut.remove(...t),Ia()}constructor(t,e){let n=this.config=new yo(e),i=Cl(t),o=Fa(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||bl(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=Pr(),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 mo,this.$proxies={},this._hiddenIndices={},this.attached=!1,this._animationsDisabled=void 0,this.$context=void 0,this._doResize=jr(h=>this.update(h),r.resizeDelay||0),this._dataChanges=[],Yn[this.id]=this,!a||!l){console.error("Failed to create chart: can't acquire context from the given item");return}ee.listen(this,"complete",Oa),ee.listen(this,"progress",wu),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 Ut}_initialize(){return this.notifyPlugins("beforeInit"),this.options.responsive?this.resize():Gi(this,this.options.devicePixelRatio),this.bindEvents(),this.notifyPlugins("afterInit"),this}clear(){return zi(this.canvas,this.ctx),this}stop(){return ee.stop(this),this}resize(t,e){ee.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,Gi(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||{};at(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=vo(r,a),c=l==="r",d=l==="x";return{options:a,dposition:c?"chartArea":d?"bottom":"left",dtype:c?"radialLinear":d?"category":"linear"}}))),at(o,r=>{let a=r.options,l=a.id,c=vo(l,a),d=Q(a.type,r.dtype);(a.position===void 0||Ra(a.position,c)!==Ra(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=Ut.getScale(d);h=new u({id:l,type:d,ctx:this.ctx,chart:this}),n[h.id]=h}h.init(a,t)}),at(i,(r,a)=>{r||delete n[a]}),at(n,r=>{St.configure(this,r,r.options),St.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;ie.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{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{c.reset()}),this._updateDatasets(t),this.notifyPlugins("afterUpdate",{mode:t}),this._layers.sort(Pa("z","_idx"));let{_active:a,_lastEvent:l}=this;l?this._eventHandler(l,!0):a.length&&this._updateHoverStyles(a,a,!0),this.render()}_updateScales(){at(this.scales,t=>{St.removeBox(this,t)}),this.ensureScalesHaveIDs(),this.buildOrUpdateScales()}_checkEventBindings(){let t=this.options,e=new Set(Object.keys(this._listeners)),n=new Set(t.events);(!Di(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;Mu(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;oo.split(",")).map(o=>({method:o[1],start:+o[2],count:+o[3]}))}_updateLayout(t){if(this.notifyPlugins("beforeLayout",{cancelable:!0})===!1)return;St.update(this,this.width,this.height,t);let e=this.chartArea,n=e.width<=0||e.height<=0;this._layers=[],at(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=0;--e)this._drawDataset(t[e]);this.notifyPlugins("afterDatasetsDraw")}_drawDataset(t){let e=this.ctx,n={meta:t,index:t.index,cancelable:!0},i=to(this,t);this.notifyPlugins("beforeDatasetDraw",n)!==!1&&(i&&Ns(e,i),t.controller.draw(),i&&Bs(e),n.cancelable=!1,this.notifyPlugins("afterDatasetDraw",n))}isPointInArea(t){return Qt(t,this.chartArea,this._minPadding)}getElementsAtEventForMode(t,e,n,i){let o=ul.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=ce(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);rs(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(),ee.remove(this),t=0,e=this.data.datasets.length;t{e.addEventListener(this,o,r),t[o]=r},i=(o,r,a)=>{o.offsetX=r,o.offsetY=a,this._eventHandler(o)};at(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(){at(this._listeners,(t,e)=>{this.platform.removeEventListener(this,e,t)}),this._listeners={},at(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{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}});!Vs(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=Ir(t),c=Du(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=!Vs(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)}};W(se,"defaults",ft),W(se,"instances",Yn),W(se,"overrides",ve),W(se,"registry",Ut),W(se,"version",Eu),W(se,"getChart",Fa);Se=class extends Rt{constructor(e){super();W(this,"circumference");W(this,"endAngle");W(this,"fullCircles");W(this,"innerRadius");W(this,"outerRadius");W(this,"pixelMargin");W(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}=Ri(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=Q(u,c-l),p=ls(r,l,c)&&l!==c,m=g>=ut||p,b=Jt(a,d+f,h+f);return m&&b}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>ut?Math.floor(i/ut):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(ot,i||0)),d=o*c;e.fillStyle=n.backgroundColor,e.strokeStyle=n.borderColor,Pu(e,this,d,r,a),Ou(e,this,d,r,a),e.restore()}};W(Se,"id","arc"),W(Se,"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}),W(Se,"defaultRoutes",{backgroundColor:"backgroundColor"}),W(Se,"descriptors",{_scriptable:!0,_indexable:e=>e!=="borderDash"});$u=typeof Path2D=="function";Kt=class extends Rt{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;ea(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=aa(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=Ji(this,{property:e,start:i,end:i});if(!r.length)return;let a=[],l=Bu(n),c,d;for(c=0,d=r.length;ct!=="borderDash"&&t!=="fill"});$e=class extends Rt{constructor(e){super();W(this,"parsed");W(this,"skip");W(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)s.replace("rgb(","rgba(").replace(")",", 0.5)"));Dl={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=Ba(n)||Ju(i)||o&&Ba(o)||tf();if(!e.forceOverride&&r)return;let a=Zu(s);n.forEach(a)}};Ll={id:"decimation",defaults:{algorithm:"min-max",enabled:!1},beforeElementsUpdate:(s,t,e)=>{if(!e.enabled){Ha(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(us([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}=nf(l,c),f=e.threshold||4*n;if(u<=f){Tl(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=ef(c,h,u,n,e);break;case"min-max":g=sf(c,h,u,n);break;default:throw new Error(`Unsupported decimation algorithm '${e.algorithm}'`)}i._decimated=g})},destroy(s){Ha(s)}};Jn=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:ut},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}}};Rl={id:"filler",afterDatasetsUpdate(s,t,e){let n=(s.data.datasets||[]).length,i=[],o,r,a,l;for(r=0;r=0;--r){let a=i[r].$filler;a&&(a.line.updateControlPoints(o,a.axis),n&&a.fill&&ho(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;$a(o)&&ho(s.ctx,o,s.chartArea)}},beforeDatasetDraw(s,t,e){let n=t.meta.$filler;!$a(n)||e.drawTime!=="beforeDatasetDraw"||ho(s.ctx,n,s.chartArea)},defaults:{propagate:!0,drawTime:"beforeDatasetDraw"}},Ka=(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)}},Ef=(s,t)=>s!==null&&t!==null&&s.datasetIndex===t.datasetIndex&&s.index===t.index,ti=class extends Rt{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=mt(n.font),o=i.size,r=this._computeTitleHeight(),{boxWidth:a,itemHeight:l}=Ka(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 m=n+e/2+o.measureText(g.text).width;(p===0||c[c.length-1]+m+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:m,height:i},c[c.length-1]+=m+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((m,b)=>{let{itemWidth:C,itemHeight:x}=kf(n,e,o,m,i);b>0&&f+x+2*a>d&&(h+=u+a,c.push({width:u,height:f}),g+=u+a,p++,u=f=0),l[b]={left:g,top:f,col:p,width:C,height:x},u=Math.max(u,C),f+=x+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=Oe(o,this.left,this.width);if(this.isHorizontal()){let a=0,l=Ct(n,this.left+i,this.right-this.lineWidths[a]);for(let c of e)a!==c.row&&(a=c.row,l=Ct(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=Ct(n,this.top+t+i,this.bottom-this.columnSizes[a].height);for(let c of e)c.col!==a&&(a=c.col,l=Ct(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;Ns(t,this),this._draw(),Bs(t)}}_draw(){let{options:t,columnSizes:e,lineWidths:n,ctx:i}=this,{align:o,labels:r}=t,a=ft.color,l=Oe(t.rtl,this.left,this.width),c=mt(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:m}=Ka(r,h),b=function(y,v,_){if(isNaN(g)||g<=0||isNaN(p)||p<0)return;i.save();let E=Q(_.lineWidth,1);if(i.fillStyle=Q(_.fillStyle,a),i.lineCap=Q(_.lineCap,"butt"),i.lineDashOffset=Q(_.lineDashOffset,0),i.lineJoin=Q(_.lineJoin,"miter"),i.lineWidth=E,i.strokeStyle=Q(_.strokeStyle,a),i.setLineDash(Q(_.lineDash,[])),r.usePointStyle){let M={radius:p*Math.SQRT2/2,pointStyle:_.pointStyle,rotation:_.rotation,borderWidth:E},k=l.xPlus(y,g/2),L=v+u;$i(i,M,k,L,r.pointStyleWidth&&g)}else{let M=v+Math.max((h-p)/2,0),k=l.leftForLtr(y,g),L=Ce(_.borderRadius);i.beginPath(),Object.values(L).some(D=>D!==0)?hs(i,{x:k,y:M,w:g,h:p,radius:L}):i.rect(k,M,g,p),i.fill(),E!==0&&i.stroke()}i.restore()},C=function(y,v,_){xe(i,_.text,y,v+m/2,c,{strikethrough:_.hidden,textAlign:l.textAlign(_.textAlign)})},x=this.isHorizontal(),w=this._computeTitleHeight();x?f={x:Ct(o,this.left+d,this.right-n[0]),y:this.top+d+w,line:0}:f={x:this.left+d,y:Ct(o,this.top+w+d,this.bottom-e[0].height),line:0},Xi(this.ctx,t.textDirection);let S=m+d;this.legendItems.forEach((y,v)=>{i.strokeStyle=y.fontColor,i.fillStyle=y.fontColor;let _=i.measureText(y.text).width,E=l.textAlign(y.textAlign||(y.textAlign=r.textAlign)),M=g+u+_,k=f.x,L=f.y;l.setWidth(this.width),x?v>0&&k+M+d>this.right&&(L=f.y+=S,f.line++,k=f.x=Ct(o,this.left+d,this.right-n[f.line])):v>0&&L+S>this.bottom&&(k=f.x=k+e[f.line].width+d,f.line++,L=f.y=Ct(o,this.top+w+d,this.bottom-e[f.line].height));let D=l.x(k);if(b(D,L,y),k=Ur(E,k+g+u,x?k+M:this.right,t.rtl),C(l.x(k),L,y),x)f.x+=M+d;else if(typeof y.text!="string"){let T=c.lineHeight;f.y+=Pl(y,T)+d}else f.y+=S}),Qi(this.ctx,t.textDirection)}drawTitle(){let t=this.options,e=t.title,n=mt(e.font),i=_t(e.padding);if(!e.display)return;let o=Oe(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=Ct(t.align,h,this.right-u);else{let g=this.columnSizes.reduce((p,m)=>Math.max(p,m.height),0);d=c+Ct(t.align,this.top,this.bottom-g-t.labels.padding-this._computeTitleHeight())}let f=Ct(a,h,h+u);r.textAlign=o.textAlign(Rn(a)),r.textBaseline="middle",r.strokeStyle=e.color,r.fillStyle=e.color,r.font=n.string,xe(r,e.text,f,d,n)}_computeTitleHeight(){let t=this.options.title,e=mt(t.font),n=_t(t.padding);return t.display?e.lineHeight+n.height:0}_getLegendItemAt(t,e){let n,i,o;if(Jt(t,this.left,this.right)&&Jt(e,this.top,this.bottom)){for(o=this.legendHitBoxes,n=0;ns.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=_t(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)}}},Qs=class extends Rt{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=ht(n.text)?n.text.length:1;this._padding=_t(n.padding);let o=i*mt(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=Ct(a,n,o),h=e+t,c=o-n):(r.position==="left"?(d=n+t,h=Ct(a,i,e),l=ot*-.5):(d=o-t,h=Ct(a,e,i),l=ot*.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=mt(e.font),o=n.lineHeight/2+this._padding.top,{titleX:r,titleY:a,maxWidth:l,rotation:c}=this._drawArgs(o);xe(t,e.text,0,0,n,{color:e.color,maxWidth:l,rotation:c,textAlign:Rn(e.align),textBaseline:"middle",translation:[r,a]})}};Fl={id:"title",_element:Qs,start(s,t,e){Tf(s,e)},stop(s){let t=s.titleBlock;St.removeBox(s,t),delete s.titleBlock},beforeUpdate(s,t,e){let n=s.titleBlock;St.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}},Wn=new WeakMap,Il={id:"subtitle",start(s,t,e){let n=new Qs({ctx:s.ctx,options:e,chart:s});St.configure(s,n,e),St.addBox(s,n),Wn.set(s,n)},stop(s){St.removeBox(s,Wn.get(s)),Wn.delete(s)},beforeUpdate(s,t,e){let n=Wn.get(s);St.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}},Ks={average(s){if(!s.length)return!1;let t,e,n=new Set,i=0,o=0;for(t=0,e=s.length;ta+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;o0){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{let r={before:[],lines:[],after:[]},a=Qa(n,o);te(r.before,de(Tt(a,"beforeLabel",this,o))),te(r.lines,Tt(a,"label",this,o)),te(r.after,de(Tt(a,"afterLabel",this,o))),i.push(r)}),i}getAfterBody(t,e){return Xa(Tt(e.callbacks,"afterBody",this,t))}getFooter(t,e){let{callbacks:n}=e,i=Tt(n,"beforeFooter",this,t),o=Tt(n,"footer",this,t),r=Tt(n,"afterFooter",this,t),a=[];return a=te(a,de(i)),a=te(a,de(o)),a=te(a,de(r)),a}_createItems(t){let e=this._active,n=this.chart.data,i=[],o=[],r=[],a=[],l,c;for(l=0,c=e.length;lt.filter(d,h,u,n))),t.itemSort&&(a=a.sort((d,h)=>t.itemSort(d,h,n))),at(a,d=>{let h=Qa(t.callbacks,d);i.push(Tt(h,"labelColor",this,d)),o.push(Tt(h,"labelPointStyle",this,d)),r.push(Tt(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=Ks[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=Ya(this,n),c=Object.assign({},a,l),d=Ga(this.chart,n,c),h=qa(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}=Ce(a),{x:u,y:f}=t,{width:g,height:p}=e,m,b,C,x,w,S;return o==="center"?(w=f+p/2,i==="left"?(m=u,b=m-r,x=w+r,S=w-r):(m=u+g,b=m+r,x=w-r,S=w+r),C=m):(i==="left"?b=u+Math.max(l,d)+r:i==="right"?b=u+g-Math.max(c,h)-r:b=this.caretX,o==="top"?(x=f,w=x-r,m=b-r,C=b+r):(x=f+p,w=x+r,m=b+r,C=b-r),S=x),{x1:m,x2:b,x3:C,y1:x,y2:w,y3:S}}drawTitle(t,e,n){let i=this.title,o=i.length,r,a,l;if(o){let c=Oe(n.rtl,this.x,this.width);for(t.x=jn(this,n.titleAlign,n),e.textAlign=c.textAlign(n.titleAlign),e.textBaseline="middle",r=mt(n.titleFont),a=n.titleSpacing,e.fillStyle=n.titleColor,e.font=r.string,l=0;lC!==0)?(t.beginPath(),t.fillStyle=o.multiKeyBackground,hs(t,{x:p,y:g,w:c,h:l,radius:b}),t.fill(),t.stroke(),t.fillStyle=r.backgroundColor,t.beginPath(),hs(t,{x:m,y:g+1,w:c-2,h:l-2,radius:b}),t.fill()):(t.fillStyle=o.multiKeyBackground,t.fillRect(p,g,c,l),t.strokeRect(p,g,c,l),t.fillStyle=r.backgroundColor,t.fillRect(m,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=mt(n.bodyFont),u=h.lineHeight,f=0,g=Oe(n.rtl,this.x,this.width),p=function(_){e.fillText(_,g.x(t.x+f),t.y+u/2),t.y+=u+o},m=g.textAlign(r),b,C,x,w,S,y,v;for(e.textAlign=r,e.textBaseline="middle",e.font=h.string,t.x=jn(this,m,n),e.fillStyle=n.bodyColor,at(this.beforeBody,p),f=a&&m!=="right"?r==="center"?c/2+d:c+2+d:0,w=0,y=i.length;w0&&e.stroke()}_updateAnimationTarget(t){let e=this.chart,n=this.$animations,i=n&&n.x,o=n&&n.y;if(i||o){let r=Ks[t.position].call(this,this._active,this._eventPosition);if(!r)return;let a=this._size=Ya(this,t),l=Object.assign({},r,this._size),c=Ga(e,t,l),d=qa(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=_t(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),Xi(t,e.textDirection),o.y+=r.top,this.drawTitle(o,t,e),this.drawBody(o,t,e),this.drawFooter(o,t,e),Qi(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=!Vs(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||!Vs(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=Ks[o.position].call(this,t,e);return r!==!1&&(n!==r.x||i!==r.y)}};W(Ys,"positioners",Ks);Nl={id:"tooltip",_element:Ys,positioners:Ks,afterInit(s,t,e){e&&(s.tooltip=new Ys({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:Vl},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"]},Bl=Object.freeze({__proto__:null,Colors:Dl,Decimation:Ll,Filler:Rl,Legend:Ol,SubTitle:Il,Title:Fl,Tooltip:Nl}),Vf=(s,t,e,n)=>(typeof t=="string"?(e=s.push(t)-1,n.unshift({index:e,label:t})):isNaN(t)&&(e=null),e);Bf=(s,t)=>s===null?null:bt(Math.round(s),0,t);ms=class extends De{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:Nf(n,t,Q(e,t),this._addedLabels),Bf(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 Za.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}};W(ms,"id","category"),W(ms,"defaults",{ticks:{callback:Za}});xs=class extends De{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=jt(i),c=jt(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=Hf(i,o);return t.bounds==="ticks"&&Li(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 cs(t,this.chart.options.locale,this.options.ticks.format)}},bs=class extends xs{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=$t(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}};W(bs,"id","linear"),W(bs,"defaults",{ticks:{callback:ds.formatters.numeric}});Zs=s=>Math.floor(ae(s)),Ie=(s,t)=>Math.pow(10,Zs(s)+t);vs=class extends De{constructor(t){super(t),this.start=void 0,this.end=void 0,this._startValue=void 0,this._valueRange=0}parse(t,e){let n=xs.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===Ie(this.min,0)?Ie(this.min,-1):Ie(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(Ie(n,-1)),r(Ie(i,1)))),n<=0&&o(Ie(i,-1)),i<=0&&r(Ie(n,1)),this.min=n,this.max=i}buildTicks(){let t=this.options,e={min:this._userMin,max:this._userMax},n=$f(e,this);return t.bounds==="ticks"&&Li(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":cs(t,this.chart.options.locale,this.options.ticks.format)}configure(){let t=this.min;super.configure(),this._startValue=ae(t),this._valueRange=ae(this.max)-ae(t)}getPixelForValue(t){return(t===void 0||t===0)&&(t=this.min),t===null||isNaN(t)?NaN:this.getPixelForDecimal(t===this.min?0:(ae(t)-this._startValue)/this._valueRange)}getValueForPixel(t){let e=this.getDecimalForPixel(t);return Math.pow(10,this._startValue+e*this._valueRange)}};W(vs,"id","logarithmic"),W(vs,"defaults",{ticks:{callback:ds.formatters.logarithmic,major:{enabled:!0}}});Ee=class extends xs{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=_t(So(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/So(this.options))}generateTickLabels(t){xs.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?jf(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=ut/(this._pointLabels.length||1),n=this.options.startAngle||0;return xt(t*e+$t(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{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);tg(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=mt(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=_t(c.backdropPadding);t.fillRect(-r/2-h.left,-o-d.size/2-h.top,r+h.width,d.size+h.height)}xe(t,a.label,0,-o,d,{color:c.color,strokeColor:c.textStrokeColor,strokeWidth:c.textStrokeWidth})}),t.restore()}drawTitle(){}};W(Ee,"id","radialLinear"),W(Ee,"defaults",{display:!0,animate:!0,position:"chartArea",angleLines:{display:!0,lineWidth:1,borderDash:[],borderDashOffset:0},grid:{circular:!1},startAngle:0,ticks:{showLabelBackdrop:!0,callback:ds.formatters.numeric},pointLabels:{backdropColor:void 0,backdropPadding:2,display:!0,font:{size:10},callback(t){return t},padding:5,centerPointLabels:!1}}),W(Ee,"defaultRoutes",{"angleLines.color":"borderColor","pointLabels.color":"color","ticks.color":"color"}),W(Ee,"descriptors",{angleLines:{_fallback:"grid"}});si={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}},At=Object.keys(si);Me=class extends De{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 hl._date(t.adapters.date);i.init(e),os(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:il(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=zr(i,o,r);return this._unit=e.unit||(n.autoSkip?ol(e.minUnit,this.min,this.max,this._getLabelCapacity(o)):sg(this,a.length,e.minUnit,this.min,this.max)),this._majorUnit=!n.major.enabled||this._unit==="year"?void 0:ng(this._unit),this.initOffsets(i),t.reverse&&a.reverse(),al(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=bt(e,0,r),n=bt(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||ol(o.minUnit,e,n,this._getLabelCapacity(e)),a=Q(i.ticks.stepSize,1),l=r==="week"?o.isoWeekday:!1,c=Pe(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+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;e0?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=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;ri-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(Un(this._table,t)-this._minPos)/this._tableRange}getValueForPixel(t){let e=this._offsets,n=this.getDecimalForPixel(t)/e.factor-e.end;return Un(this._table,n*this._tableRange+this._minPos,!0)}};W(ys,"id","timeseries"),W(ys,"defaults",Me.defaults);zl=Object.freeze({__proto__:null,CategoryScale:ms,LinearScale:bs,LogarithmicScale:vs,RadialLinearScale:Ee,TimeScale:Me,TimeSeriesScale:ys}),og=[dl,kl,Bl,zl]});var hg={};Do(hg,{CardView:()=>Cs,default:()=>ni});module.exports=nc(hg);var rt=require("obsidian"),ql=en(Es());var ic=["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"],oc=[{label:"\u{1F1EA}\u{1F1FA} Schengen 90/180 (example)",scope:{countries:ic},window:{type:"rolling",days:180},threshold:90,note:"Example rule \u2014 add your own in Settings \u2192 CSV Card View."}],li={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:oc,showResidency:!0},sn="xlsx-card-view";var Lo=en(Es()),Ao=require("obsidian"),Ue=["Image","image","Cover","cover","Poster","poster","Thumbnail","thumbnail","Thumb","thumb","Photo","photo","Picture","picture","Img","img"],Ke=["Category","category","Categories","categories","Genre","genre","Genres","genres","Type","type","Types","types","Tag","tag","Tags","tags","Topic","topic","Topics","topics","Subject","subject","Section","section"],Ye=["Status","status","State","state","Progress","progress","Stage","stage","Read","read","Watched","watched","Seen","seen","Done","done","Completed","completed"],Ge=["Notes","notes","Note","note","Summary","summary","Review","review","Quote","quote","Quotes","quotes","Comment","comment","Comments","comments","Description","description","Annotation","annotation"];function nn(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 Ao.TFile?s.vault.getResourcePath(o):null}var rc=15;function Gt(s){return s>=1&&s<=rc}var ac=["0","1","true","false","yes","no",""];function on(s){return s.length>0&&s.every(t=>ac.includes(t))}function ks(s){return s.replace(/[\\/:*?"<>|#^[\]]/g,"").replace(/\s+/g," ").trim().slice(0,100)}function Ro(s){return s.toLowerCase().replace(/[^\p{L}\p{N}/_-]+/gu,"-").replace(/-+/g,"-").replace(/^-+|-+$/g,"")}function qt(s){var i,o;if(!s||!s.trim())return{headers:[],rows:[]};let t=Lo.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 qe(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 Po(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 Mt(s){return s.split(/[\s_-]+/).map(t=>t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()).join(" ")}function Oo(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=lc(e,t);return i&&i!==e&&i!=="\u2014"?i:""}function lc(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 Fo(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 Io(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 Vo(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));ck.remove());let r=document.body.createDiv({cls:"csv-select-picker"});r.style.position="fixed",r.style.zIndex="9999";let a=()=>{let k=s.getBoundingClientRect(),L=r.offsetHeight||280,D=k.bottom+4+L>window.innerHeight&&k.top-4-L>0;r.style.left=k.left+"px",r.style.top=D?k.top-4-L+"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(L=>L.trim()).filter(Boolean),p=new Set(f?g(t):[]),m=()=>n([...p].join(", ")),b=f?Array.from(new Set(e.flatMap(g))):Array.from(new Set(e.filter(Boolean))),C=[],x=0,w=()=>{u.querySelectorAll(".csv-picker-item").forEach((k,L)=>{k.toggleClass("csv-picker-item--hover",L===x),L===x&&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&&!b.includes(k.value)&&b.push(k.value)),m(),k.isAdd?(h.value="",_("")):_(h.value)},y=k=>f?p.has(k):k===t,v=()=>f?p.size>0:!!t,_=k=>{u.empty(),C=[];let L=k?b.filter(D=>D.toLowerCase().includes(k.toLowerCase())):b;if(v()){C.push({value:"",isClear:!0});let D=u.createDiv({cls:"csv-picker-item csv-picker-clear"});D.setText(f?"\u2715 Clear all":"\u2715 Clear"),D.addEventListener("mousedown",T=>{T.preventDefault(),S({value:"",isClear:!0})})}if(L.forEach(D=>{C.push({value:D});let T=u.createDiv({cls:`csv-picker-item ${y(D)?"active":""}`});T.setText(f?`${p.has(D)?"\u2713 ":""}${D}`:D),T.addEventListener("mousedown",A=>{A.preventDefault(),S({value:D})})}),k&&!b.some(D=>D.toLowerCase()===k.toLowerCase())){C.push({value:k,isAdd:!0});let D=u.createDiv({cls:"csv-picker-item csv-picker-add"});D.setText(`+ Add "${k}"`),D.addEventListener("mousedown",T=>{T.preventDefault(),S({value:k,isAdd:!0})})}!L.length&&!k&&u.createDiv({cls:"csv-picker-empty",text:"No options yet. Type to add."}),x=Math.min(x,Math.max(C.length-1,0)),w()};f&&r.createEl("button",{cls:"csv-picker-done",text:"Done"}).addEventListener("mousedown",k=>{k.preventDefault(),d()}),_(""),a(),h.addEventListener("input",()=>{x=0,_(h.value),a()});let E=typeof window!="undefined"&&((M=window.matchMedia)==null?void 0:M.call(window,"(pointer: coarse)").matches);setTimeout(()=>{document.addEventListener("mousedown",l),E||(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(),C.length&&(x=(x+1)%C.length,w());return}if(k.key==="ArrowUp"){k.preventDefault(),C.length&&(x=(x-1+C.length)%C.length,w());return}if(k.key==="Enter")if(k.preventDefault(),C[x])S(C[x]);else{let L=h.value.trim();L&&(n(L),d())}})}function No(s,t,e){return!s[t]||t===e||(s[e]||(s[e]=s[t]),delete s[t]),s}var cc={source:["confirmed","inferred","conflict"],resolved:["yes","no"]};function Bo(s){var t;return(t=cc[s.trim().toLowerCase()])!=null?t:null}function he(s){return/(^|[_\s-])(date|due|deadline)([_\s-]|$)/i.test(s.trim())}var Ho=/^\d{4}-\d{2}-\d{2}$/;var Nt=require("obsidian");function ln(s,t,e,n){let i=he(t)&&(e===""||Ho.test(e)),o=s.createEl("input",{cls:n,type:i?"date":"text",value:e});i||(o.placeholder=t);let r=Bo(t);if(r){let a=`csv-dl-${t.toLowerCase().replace(/[^a-z0-9]+/g,"-")}-${Math.random().toString(36).slice(2,7)}`,l=s.createEl("datalist");l.id=a,r.forEach(c=>l.createEl("option",{value:c})),o.setAttr("list",a)}return o}var Xe=class extends Nt.Modal{constructor(t,e,n,i,o,r,a={},l=()=>!1,c){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:d=>this.isSelectCol(d)||Gt(this.getColumnValues(d).length)}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.headers.find(d=>["title","name"].includes(d.toLowerCase())),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 m;let h=e.createDiv({cls:"csv-modal-row"});h.createEl("label",{text:Mt(d),cls:"csv-modal-label"});let u=(m=this.optionPresets[d])!=null?m:[],f=d===i,g=Et(d),p=!f&&!this.isNotesCol(d)&&!g&&(u.length>0||this.isCategoricalCol(d));if(this.isBooleanCol(d)){n[d]="0";let b=h.createDiv({cls:"csv-toggle"});b.createDiv({cls:"csv-toggle-knob"}),b.addEventListener("click",()=>{let C=!b.hasClass("is-on");b.toggleClass("is-on",C),n[d]=C?"1":"0"})}else if(this.isNotesCol(d)){let b=h.createEl("textarea",{cls:"csv-modal-textarea",placeholder:"Markdown supported\u2026"});b.addEventListener("input",()=>{n[d]=b.value})}else if(p){let b="__custom__",C=[];[...u,...this.getColumnValues(d)].forEach(S=>{let y=(S!=null?S:"").trim();y&&!C.some(v=>v.toLowerCase()===y.toLowerCase())&&C.push(y)});let x=h.createEl("select",{cls:"csv-modal-select"});x.createEl("option",{text:"\u2014",value:""}),C.forEach(S=>x.createEl("option",{text:S,value:S})),x.createEl("option",{text:"+ Custom\u2026",value:b});let w=h.createEl("input",{cls:"csv-modal-input csv-modal-custom",type:"text",placeholder:`Custom ${Mt(d).toLowerCase()}`});w.hide(),w.addEventListener("input",()=>{n[d]=w.value}),w.addEventListener("keydown",S=>{S.key==="Enter"&&c()}),x.addEventListener("change",()=>{x.value===b?(w.show(),w.focus(),n[d]=w.value):(w.hide(),n[d]=x.value)})}else if(!f&&g&&this.isSelectCol(d)){let C=h.createDiv({cls:"csv-modal-select-wrap"}).createDiv({cls:"csv-select-chip empty"});C.setText("\u2014 click to select \u2014"),C.addEventListener("click",x=>{x.stopPropagation(),It(C,n[d],this.getColumnValues(d),w=>{n[d]=w,C.setText(w||"\u2014 click to select \u2014"),C.toggleClass("empty",!w)},t,{multi:Et(d)})})}else{let b=ln(h,d,"","csv-modal-input");if(b.addEventListener("input",()=>{n[d]=b.value}),b.addEventListener("keydown",C=>{C.key==="Enter"&&c()}),d===i&&o.size){let C=h.createDiv({cls:"csv-modal-dup-hint"});C.hide(),b.addEventListener("input",()=>{let x=o.get(b.value.trim().toLowerCase());x?(C.setText(`\u26A0 \u201C${x}\u201D is already in this file`),C.show()):C.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 Nt.Notice("Fill in at least one field.");return}this.onSubmit(n),this.close()}}onClose(){this.contentEl.empty()}},Qe=class extends Nt.Modal{constructor(e,n,i,o,r,a,l,c,d,h,u){super(e);this.vvHandler=null;this.row={...n},this.notesCol=i,this.headers=o,this.filePath=r,this.renderComponent=new Nt.Component,this.isNotesCol=a,this.isSelectCol=l,this.getColumnValues=c,this.onSave=d,this.onDelete=h,this.isCategoricalCol=u!=null?u:f=>this.isSelectCol(f)||!he(f)&&Gt(this.getColumnValues(f).length),this.modalEl.addClass("csv-note-expander-modal")}onOpen(){var g,p,m,b,C;this.renderComponent.load();let{contentEl:e}=this;e.empty(),e.addClass("csv-note-expander");let n=window.visualViewport;if(n){let x=()=>{this.modalEl.style.setProperty("--csv-modal-vh",`${n.height}px`)};x(),n.addEventListener("resize",x),n.addEventListener("scroll",x),this.vvHandler=x}let i=e.createDiv({cls:"csv-expander-header"});i.createDiv({cls:"csv-expander-title",text:(p=this.row[(g=this.headers.find(x=>["title","name","Title","Name"].includes(x)))!=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.headers.find(x=>["title","name","Title","Name"].includes(x)),l=this.headers.find(x=>["author","Author","director","Director","artist","Artist","creator","Creator"].includes(x));this.headers.forEach(x=>{if(this.isNotesCol(x))return;let w=r.createDiv({cls:"csv-expander-field-row"});w.createDiv({cls:"csv-expander-field-label",text:Mt(x)});let S=Et(x);if(x!==a&&(S?this.isSelectCol(x):this.isCategoricalCol(x))){let v=w.createDiv({cls:`csv-select-chip ${this.row[x]?"":"empty"}`});v.setText(this.row[x]||"\u2014"),v.addEventListener("click",_=>{_.stopPropagation(),It(v,this.row[x],this.getColumnValues(x),E=>{this.row[x]=E,v.setText(E||"\u2014"),v.toggleClass("empty",!E)},e,{multi:Et(x)})})}else{let v=w.createDiv({cls:"csv-expander-field-value",text:this.row[x]||"\u2014"});v.addEventListener("click",()=>{var M;v.empty();let _=ln(v,x,(M=this.row[x])!=null?M:"","csv-inline-input");_.focus(),_.type==="text"&&_.select();let E=()=>{this.row[x]=_.value,v.empty(),v.setText(_.value||"\u2014")};_.addEventListener("blur",E),_.addEventListener("keydown",k=>{k.key==="Enter"&&_.blur(),k.key==="Escape"&&(v.empty(),v.setText(this.row[x]||"\u2014"))})})}});let c=!1,d=this.notesCol&&(m=this.row[this.notesCol])!=null?m:"",h=null;if(this.notesCol){e.createDiv({cls:"csv-expander-divider"}).createDiv({cls:"csv-expander-notes-label",text:this.notesCol});let w=e.createDiv({cls:"csv-expander-rendered markdown-rendered"});w.title="Click to edit";let S=e.createDiv({cls:"csv-expander-editor"});S.style.display="none";let y=()=>{w.empty(),d.trim()?Nt.MarkdownRenderer.render(this.app,d,w,this.filePath,this.renderComponent):w.createDiv({cls:"csv-notes-empty",text:"+ Add note"})};y(),h=S.createEl("textarea",{cls:"csv-expander-textarea"}),h.value=d,h.addEventListener("input",()=>{d=h.value});let v=()=>{c||(c=!0,w.style.display="none",S.style.display="flex",h.value=d,h.focus())},_=()=>{c&&(c=!1,S.style.display="none",w.style.display="",d=h.value,y())};w.addEventListener("click",E=>{if(E.target.closest("a, button, input, textarea, [contenteditable]"))return;let k=window.getSelection();k&&k.toString().length>0||v()}),h.addEventListener("keydown",E=>{E.key==="Escape"&&(E.preventDefault(),h.blur())}),h.addEventListener("blur",_)}let u=e.createDiv({cls:"csv-expander-footer"});if(this.onDelete){let x=String((C=this.row[(b=this.headers.find(w=>["title","name","Title","Name"].includes(w)))!=null?b:this.headers[0]])!=null?C:"").trim();u.createEl("button",{cls:"csv-expander-delete-btn",text:"Delete"}).addEventListener("click",()=>{let w=x||"this entry";window.confirm(`Delete "${w}"? 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 rn=class extends Nt.Modal{constructor(t,e,n,i,o,r,a,l,c,d,h,u,f){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}onOpen(){var v,_;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 E=this.getFileCfg();this.current={...E,habitColumns:E.habitColumns?[...E.habitColumns]:void 0,categoricalColumns:E.categoricalColumns?[...E.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:`Role is exclusive \u2014 picking it for one column clears it from any other. "auto (by name)" means it's already playing that role because of its column name, with nothing saved here yet. The three toggles can be combined freely.`});let o=[{value:"",label:"\u2014 no special role \u2014"},{value:"category",label:"Category (Kanban grouping)"},{value:"status",label:"Status (checkmark / row subgroups)"},{value:"notes",label:"Notes"},{value:"image",label:"Image (card / kanban thumbnail)"},{value:"anki",label:"Anki card front"}],r=E=>{if(this.current.categoryColumn!==void 0){if(this.current.categoryColumn===E)return{role:"category",auto:!1}}else if(this.autoDetectedRoles.category===E)return{role:"category",auto:!0};if(this.current.statusColumn!==void 0){if(this.current.statusColumn===E)return{role:"status",auto:!1}}else if(this.autoDetectedRoles.status===E)return{role:"status",auto:!0};if(this.current.notesColumn!==void 0){if(this.current.notesColumn===E)return{role:"notes",auto:!1}}else if(this.autoDetectedRoles.notes===E)return{role:"notes",auto:!0};if(this.current.imageColumn!==void 0){if(this.current.imageColumn===E)return{role:"image",auto:!1}}else if(this.autoDetectedRoles.image===E)return{role:"image",auto:!0};if(this.current.ankiFrontCol!==void 0){if(this.current.ankiFrontCol===E)return{role:"anki",auto:!1}}else if(this.autoDetectedRoles.anki===E)return{role:"anki",auto:!0};return{role:"",auto:!1}},a=E=>{this.current.categoryColumn===E&&(this.current.categoryColumn=void 0),this.current.statusColumn===E&&(this.current.statusColumn=void 0),this.current.notesColumn===E&&(this.current.notesColumn=void 0),this.current.imageColumn===E&&(this.current.imageColumn=void 0),this.current.ankiFrontCol===E&&(this.current.ankiFrontCol=void 0)},l=(E,M)=>{a(E),M==="category"?this.current.categoryColumn=E:M==="status"?this.current.statusColumn=E:M==="notes"?this.current.notesColumn=E:M==="image"?this.current.imageColumn=E:M==="anki"&&(this.current.ankiFrontCol=E)},c=E=>this.headers.find(M=>E.some(k=>k.toLowerCase()===M.toLowerCase())),d=[c(["Author","Authors","Director","Artist","Creator","By"]),c(["Year","Date","Released"]),c(["Rating","Score","Score /5","Stars"]),c(["Theme","Tags","Tag","Mood"])].filter(E=>!!E),h=(v=this.headers.find(E=>["title","name","Title","Name"].includes(E)))!=null?v:this.headers[0],u=i.createDiv({cls:"csv-modal-column-list"}),f=()=>{var L,D,T;u.empty();let E=new Set((L=this.current.habitColumns)!=null?L:this.autoDetectedHabits),M=new Set((D=this.current.cardFields)!=null?D:d),k=new Set((T=this.current.categoricalColumns)!=null?T:this.autoDetectedCategorical);this.headers.forEach(A=>{let N=u.createDiv({cls:"csv-modal-colcfg-row"}),O=N.createDiv({cls:"csv-modal-colcfg-name"});O.createSpan({text:A});let j=O.createEl("button",{cls:"csv-modal-column-remove",text:"\u2715",attr:{title:`Remove "${A}" \u2014 deletes this column's data from every row`}});j.addEventListener("click",()=>{if(j.hasClass("confirm")){this.onRemoveColumn(A),n();return}u.querySelectorAll(".csv-modal-column-remove.confirm").forEach(R=>{R.removeClass("confirm"),R.setText("\u2715")}),j.addClass("confirm"),j.setText("Confirm?"),window.setTimeout(()=>{j.isConnected&&(j.removeClass("confirm"),j.setText("\u2715"))},3e3)});let z=N.createDiv({cls:"csv-modal-colcfg-controls"}),K=z.createEl("select",{cls:"csv-modal-select csv-modal-colcfg-role"}),{role:$,auto:X}=r(A);o.forEach(R=>{let F=K.createEl("option",{text:R.label,value:R.value});R.value===$&&(F.selected=!0)}),X&&(K.addClass("auto-detected"),z.createSpan({cls:"csv-modal-colcfg-auto-badge",text:"auto (by name)"})),K.addEventListener("change",()=>{l(A,K.value),f()});let Z=(R,F,P,H)=>{let I=z.createEl("label",{cls:"csv-modal-checkbox-label csv-modal-colcfg-toggle"}),V=I.createEl("input",{type:"checkbox"});V.checked=F,P&&I.addClass("auto-detected"),I.createSpan({text:R}),V.addEventListener("change",()=>H(V.checked))};Z("Habit",E.has(A),this.autoDetectedHabits.includes(A)&&!this.current.habitColumns,R=>{this.current.habitColumns||(this.current.habitColumns=[...this.autoDetectedHabits]),R?this.current.habitColumns.includes(A)||this.current.habitColumns.push(A):this.current.habitColumns=this.current.habitColumns.filter(F=>F!==A)}),Z("Card field",M.has(A),d.includes(A)&&!this.current.cardFields,R=>{this.current.cardFields||(this.current.cardFields=[...d]),R?this.current.cardFields.includes(A)||this.current.cardFields.push(A):this.current.cardFields=this.current.cardFields.filter(F=>F!==A)}),A!==h&&Z("Categorical",k.has(A),this.autoDetectedCategorical.includes(A)&&!this.current.categoricalColumns,R=>{this.current.categoricalColumns||(this.current.categoricalColumns=[...this.autoDetectedCategorical]),R?this.current.categoricalColumns.includes(A)||this.current.categoricalColumns.push(A):this.current.categoricalColumns=this.current.categoricalColumns.filter(F=>F!==A)})})};f();let g=i.createDiv({cls:"csv-modal-add-column"}),p=g.createEl("input",{cls:"csv-modal-input",type:"text",placeholder:"New column name"}),m=g.createEl("button",{cls:"csv-modal-cancel",text:"+ Add column"}),b=()=>{let E=this.onAddColumn(p.value);if(E){new Nt.Notice(E);return}n()};m.addEventListener("click",b),p.addEventListener("keydown",E=>{E.key==="Enter"&&(E.preventDefault(),b())});let C=e.createDiv({cls:"csv-modal-row"});C.createEl("label",{text:"Default view",cls:"csv-modal-label"});let x=C.createEl("select",{cls:"csv-modal-select"}),w=[["\u2014 use global default \u2014",""],...this.availableModes.map(E=>[E.label,E.id])],S=(_=this.current.defaultMode)!=null?_:"";S&&!this.availableModes.some(E=>E.id===S)&&w.push([`${S} (no longer available)`,S]),w.forEach(([E,M])=>{let k=x.createEl("option",{text:E,value:M});S===M&&(k.selected=!0)}),x.addEventListener("change",()=>{this.current.defaultMode=x.value?x.value:void 0});let y=t.createDiv({cls:"csv-modal-btns"});y.createEl("button",{text:"Cancel",cls:"csv-modal-cancel"}).addEventListener("click",()=>this.close()),y.createEl("button",{text:"Save",cls:"csv-modal-submit"}).addEventListener("click",()=>{this.onSave(this.current),this.close()})}onClose(){this.contentEl.empty()}},an=class extends Nt.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,dc={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"},hc={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"]},zo={AF:"Africa",AN:"Antarctica",AS:"Asia",EU:"Europe",NA:"N. America",OC:"Oceania",SA:"S. America"},$o={};for(let[s,t]of Object.entries(hc))for(let e of t)$o[e]=s;function kt(s){return dc[s]||s}function Wt(s){return!s||s.length!==2?"":String.fromCodePoint(...s.toUpperCase().split("").map(t=>t.charCodeAt(0)+127397))}function Bt(s){if(!s||s.indexOf("?")!==-1)return null;let t=new Date(s+"T12:00:00Z");return isNaN(t.getTime())?null:t}function ws(s){let t=Bt(s.date_entered),e=Bt(s.date_left);return!t||!e?0:Math.max(Math.round((e.getTime()-t.getTime())/864e5),1)}function Wo(s,t=new Date){let e=t.getTime(),n=null,i=-1/0;for(let o of s){let r=Bt(o.date_entered);if(!(!r||r.getTime()>e)){if(o.date_left.trim()!==""){let a=Bt(o.date_left);if(!a||a.getTime()i&&(n=o,i=r.getTime())}}return n}function jo(s){let t=b=>{var C,x,w,S,y,v,_,E;return{date_entered:(C=b.date_entered)!=null?C:"",date_left:(x=b.date_left)!=null?x:"",country:((w=b.country)!=null?w:"").trim().toUpperCase(),city:(S=b.city)!=null?S:"",visa_status:(y=b.visa_status)!=null?y:"",notes:(v=b.notes)!=null?v:"",source:((_=b.source)!=null?_:"").trim().toLowerCase(),resolved:(E=b.resolved)!=null?E:"",_src:b}},e=s.map(t).filter(b=>b.country),n=e.filter(b=>b.source==="confirmed"),i=e.filter(b=>b.source==="inferred"),o=e.filter(b=>b.source==="conflict"),r=[];for(let b of n){let C=Bt(b.date_entered),x=Bt(b.date_left);C&&x&&r.push([C.getTime(),x.getTime()])}let a=b=>{let C=Bt(b.date_entered),x=Bt(b.date_left);if(!C||!x)return!1;let w=C.getTime(),S=x.getTime();return r.some(([y,v])=>w<=v&&S>=y)},l=i.filter(b=>Bt(b.date_entered)&&Bt(b.date_left)&&!a(b)),c=new Set(n.map(b=>b.country)),d=new Set(i.map(b=>b.country)),h=new Set([...d].filter(b=>!c.has(b))),u=new Set([...c,...d]),f=new Map;for(let b of n)f.set(b.country,(f.get(b.country)||0)+ws(b));let g=[...f.entries()].map(([b,C])=>({iso:b,days:C})).sort((b,C)=>C.days-b.days||kt(b.iso).localeCompare(kt(C.iso))),p=g.reduce((b,C)=>b+C.days,0),m=new Set;for(let b of c){let C=$o[b];C&&m.add(C)}return{confirmed:n,inferred:i,conflicts:o,inferredVisible:l,confRanges:r,confirmedCountries:c,inferredOnlyCountries:h,allCountries:u,countryDays:g,totalConfirmedDays:p,visitedContinents:m,worldPct:Math.round(c.size/ci*100)}}var di=864e5;function Uo(s){if(!s||s.indexOf("?")!==-1)return null;let t=Date.parse(s+"T00:00:00Z");return isNaN(t)?null:t}function uc(s,t,e,n){let i=Math.max(s,e),o=Math.min(t,n);return o<=i?0:Math.round((o-i)/di)}function fc(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*di,end:t+di,label:`in last ${n} days`}}function Ko(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=fc(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=Uo(f.date_entered),p=Uo(f.date_left);g===null||p===null||(a+=uc(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 Yo=["#c9a96e","#4a6fa5","#5ba06e","#a05b8a","#6ea0a0","#a0855b","#7a6ea0","#a06e6e","#6e8fa0","#a09e5b"],gc=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function pc(){let s=new Map,t=0;return e=>(s.has(e)||s.set(e,Yo[t++%Yo.length]),s.get(e))}function mc(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 hi(s){let t=ws(s);return t?`${t}d`:"\u2014"}function Ze(s){return s||"\u2014"}function Ds(s){return s.createDiv({cls:"csv-tv-table-wrap"}).createEl("table",{cls:"csv-tv-table"})}function Ms(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=ln(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 Go(s,t,e,n=()=>{},i=null,o=()=>{}){let r=jo(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(mc(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&&(yc(u,r,l,()=>d(null)),u.scrollIntoView({behavior:"smooth",block:"nearest"}))},d=f=>{l=f&&f!==l?f:null,c()};bc(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&&xc(a,r.confirmed,i),Cc(a,r,d),_c(a,r,d),Sc(a,r,n);try{let f=await e();h.empty(),f?vc(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 bc(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=>zo[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=ws(c);d>a&&(a=d,r=c)}if(r){let c=r.date_entered.slice(0,4);n("Longest trip",`${a}d`,`${Wt(r.country)} ${kt(r.country)}${c?` \xB7 ${c}`:""}`)}let l=Wo(t.confirmed);if(l){let c=Bt(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 ${Wt(l.country)} ${kt(l.country)}`}),h.createSpan({cls:"csv-tv-now-sub",text:` \u2014 since ${l.date_entered} (day ${d})${l.city?` \xB7 ${l.city}`:""}`})}}function vc(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",`${kt(a)} \u2014 ${l&&l.days?l.days+"d confirmed":"confirmed"}`),r.setAttr("data-tip",`${kt(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",`${kt(a)} \u2014 photo evidence`),r.setAttr("data-tip",`${kt(a)} \xB7 photo evidence \xB7 click for trips`)):a?(r.classList.add("cp-unvisited"),r.setAttr("data-tip",kt(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=' Confirmed',o.createSpan({cls:"csv-tv-leg"}).innerHTML=' Photo evidence'}function yc(s,t,e,n){var m,b;let i=s.createDiv({cls:"csv-tv-detail"}),o=i.createDiv({cls:"csv-tv-detail-head"});o.createSpan({cls:"csv-tv-detail-flag",text:Wt(e)});let r=o.createDiv({cls:"csv-tv-detail-titles"});r.createDiv({cls:"csv-tv-detail-name",text:kt(e)});let a=t.confirmed.filter(C=>C.country===e),l=t.inferred.filter(C=>C.country===e),c=(b=(m=t.countryDays.find(C=>C.iso===e))==null?void 0:m.days)!=null?b:0,d=new Set([...a,...l].map(C=>C.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=cn([...a.map(C=>({r:C,inf:!1,date_entered:C.date_entered})),...l.map(C=>({r:C,inf:!0,date_entered:C.date_entered}))]);if(!u.length)return;let f=Ds(i),g=f.createEl("thead").createEl("tr");["","Entered","Left","Days","City","Visa"].forEach(C=>g.createEl("th",{text:C}));let p=f.createEl("tbody");for(let{r:C,inf:x}of u){let w=p.createEl("tr");w.createEl("td",{text:x?"\u{1F4F7}":"",cls:"csv-tv-flag",attr:x?{"data-tip":"Photo-inferred"}:{}}),w.createEl("td",{text:Ze(C.date_entered)}),w.createEl("td",{text:Ze(C.date_left)}),w.createEl("td",{text:hi(C)}),w.createEl("td",{text:C.city}),w.createEl("td",{text:C.visa_status})}}function xc(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=Ko(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 Cc(s,t,e){s.createDiv({cls:"csv-tv-sec-title",text:"Countries visited"});let n=Ds(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:Wt(r),cls:"csv-tv-flag"}),l.createEl("td",{text:kt(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(Wt).join(" ")})}}function _c(s,t,e){s.createDiv({cls:"csv-tv-sec-title",text:"Timeline"});let n=pc(),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 x of o.get(c)){if(p.add(x.country),x._inf)continue;let w=Math.max(new Date(x.date_entered+"T12:00:00Z").getTime(),d),S=Math.min(new Date(x.date_left+"T12:00:00Z").getTime(),h);w<=S&&(g+=Math.max(Math.round((S-w)/864e5)+1,1))}let m=f.createDiv({cls:"csv-tv-tl-label"});m.createSpan({text:String(c)}),m.createSpan({cls:"csv-tv-tl-sub",text:`${g?`${g}d \xB7 `:""}${p.size} ${p.size===1?"country":"countries"}`});let b=f.createDiv({cls:"csv-tv-month-row"});gc.forEach(x=>b.createDiv({cls:"csv-tv-month-tick",text:x}));let C=f.createDiv({cls:"csv-tv-track"});for(let x of o.get(c)){let w=Math.max(new Date(x.date_entered+"T12:00:00Z").getTime(),d),S=Math.min(new Date(x.date_left+"T12:00:00Z").getTime(),h);if(w>S)continue;let y=(w-d)/u*100,v=Math.max((S-w+864e5)/u*100,.5),_=n(x.country),E=C.createDiv({cls:`csv-tv-seg${x._inf?" csv-tv-seg-inf":""}`});E.style.left=`${y}%`,E.style.width=`${v}%`,x._inf?(E.style.borderColor=_,E.style.background=_+"22",E.style.color=_):E.style.background=_,E.setAttr("data-iso",x.country),E.setAttr("data-tip",`${kt(x.country)} ${x.date_entered} \u2192 ${x.date_left} (${ws(x)}d)${x.visa_status?" ["+x.visa_status+"]":""}${x._inf?" [photo]":""}`),E.addEventListener("click",()=>e(x.country)),v>4?E.createSpan({cls:"csv-tv-seg-lbl",text:`${Wt(x.country)} ${x.country}`}):v>2&&E.createSpan({cls:"csv-tv-seg-lbl",text:Wt(x.country)})}}a.createDiv({cls:"csv-tv-tl-legend"}).setText("Confirmed (solid) \xB7 Photo inferred (outlined)")}function cn(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 Sc(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=Ds(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 cn(t.confirmed)){let a=o.createEl("tr");a.createEl("td",{text:Wt(r.country),cls:"csv-tv-flag"}),a.createEl("td",{text:kt(r.country)}),Ms(a.createEl("td"),r._src,"date_entered",e),Ms(a.createEl("td"),r._src,"date_left",e),a.createEl("td",{text:hi(r)}),Ms(a.createEl("td"),r._src,"city",e),Ms(a.createEl("td"),r._src,"visa_status",e),Ms(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=Ds(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 cn(t.inferred)){let h=c.createEl("tr");h.createEl("td",{text:Wt(d.country),cls:"csv-tv-flag"}),h.createEl("td",{text:kt(d.country)}),h.createEl("td",{text:Ze(d.date_entered)}),h.createEl("td",{text:Ze(d.date_left)}),h.createEl("td",{text:hi(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=Ds(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 cn(t.conflicts)){let h=c.createEl("tr");h.createEl("td",{text:Wt(d.country),cls:"csv-tv-flag"}),h.createEl("td",{text:d.country}),h.createEl("td",{text:`${Ze(d.date_entered)} \u2192 ${Ze(d.date_left)}`}),h.createEl("td",{text:d.notes})}}}var Vt=require("obsidian"),dn=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 b,C,x,w,S,y;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,_,E,M="")=>{let k=u.createDiv({cls:"csv-rr-field"});k.createEl("label",{text:v});let L=k.createEl("input",{type:"text",value:_});M&&(L.placeholder=M),L.addEventListener("input",()=>{E(L.value),n()})},g=(b=r.scope.countries)!=null?b: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 m=p.createEl("select");[["calendar-year","Calendar year"],["rolling","Rolling N days"],["all-time","All time"]].forEach(([v,_])=>{let E=m.createEl("option",{text:_,value:v});r.window.type===v&&(E.selected=!0)}),m.addEventListener("change",()=>{r.window={type:m.value,days:r.window.days},n(),this.renderResidencyRules(t)}),r.window.type==="rolling"&&f("Rolling days",String((C=r.window.days)!=null?C: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)",((w=(x=r.exempt)==null?void 0:x.visa_status)!=null?w:[]).join(", "),v=>{let _=v.split(",").map(E=>E.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",(y=r.note)!=null?y:"",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 ue=require("obsidian"),qo=en(Es());async function Xo(s,t,e,n,i={}){var $,X,Z;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=(X=($=a==null?void 0:a.parent)==null?void 0:$.path)!=null?X:"",c=qe(r,l),d=s.vault.getAbstractFileByPath(c);if(!d||!(d instanceof ue.TFile)){e.createEl("p",{text:`Error: File not found: ${c}`,cls:"csv-add-error"});return}let h=(Z=i[c])!=null?Z:{},u=[],f=[];try{let R=await s.vault.read(d),F=qt(R);u=F.headers,f=F.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=["0","1","true","false","yes","no",""],p=R=>{let F=f.map(P=>{var H;return((H=P[R])!=null?H:"").toLowerCase().trim()});return F.length>0&&F.every(P=>g.includes(P))},m=R=>{let F=R.toLowerCase();if(["date","day","datum"].includes(F))return!0;let P=f.slice(0,5).map(H=>{var I;return(I=H[R])!=null?I:""});return P.length>0&&P.every(H=>/^\d{4}-\d{2}-\d{2}$/.test(H))},b=R=>{let F=R.toLowerCase();return["notes","note","comments","description","journal"].includes(F)},C=u.filter(R=>p(R)&&!m(R)),x=u.filter(R=>m(R)),w=u.filter(R=>b(R)),S=u.filter(R=>!C.includes(R)&&!x.includes(R)&&!w.includes(R)),y=u.find(R=>["title","name"].includes(R.toLowerCase())),v=e.createDiv({cls:"csv-add-form csv-add-compact"}),_=v.createEl("button",{cls:"csv-add-trigger",text:"+ New entry"});_.style.display="none";let E=v.createDiv({cls:"csv-add-card"}),M=E.createDiv({cls:"csv-add-card-header"});M.createEl("span",{cls:"csv-add-card-title",text:"New entry"});let k=M.createEl("button",{cls:"csv-add-card-close",text:"\xD7"}),L=E.createDiv({cls:"csv-add-rows"}),D={},T={},A=(R,F)=>{let P=L.createDiv({cls:`csv-add-row csv-add-row-${F}`});return P.createEl("span",{cls:"csv-add-row-label",text:Mt(R)}),P};x.forEach(R=>{let P=A(R,"date").createEl("input",{cls:"csv-add-row-control",type:"date"});P.value=new Date().toISOString().split("T")[0],D[R]=P}),C.forEach(R=>{T[R]=!1;let P=A(R,"toggle").createEl("label",{cls:"csv-add-switch"}),H=P.createEl("input",{type:"checkbox",cls:"csv-add-switch-input"});P.createEl("span",{cls:"csv-add-switch-track"}),H.addEventListener("change",()=>{T[R]=H.checked}),D[R]=H}),S.forEach(R=>{let F=A(R,"field"),P=new Set(f.map(I=>{var V;return((V=I[R])!=null?V:"").trim()}).filter(Boolean));if(R!==y&&(h.categoricalColumns?h.categoricalColumns.includes(R):Gt(P.size))){let I=F.createEl("select",{cls:"csv-add-row-control"});I.createEl("option",{text:"\u2014",value:""}),Array.from(P).sort().forEach(B=>I.createEl("option",{text:B,value:B})),I.createEl("option",{text:"+ Custom",value:"__custom__"});let V=L.createDiv({cls:"csv-add-row csv-add-row-custom"});V.style.display="none";let q=V.createEl("input",{cls:"csv-add-row-control",type:"text",placeholder:`Custom ${Mt(R).toLowerCase()}`});L.insertBefore(V,F.nextSibling),I.addEventListener("change",()=>{V.style.display=I.value==="__custom__"?"flex":"none",I.value==="__custom__"&&q.focus()}),D[R]=I,D[`${R}__custom`]=q}else D[R]=F.createEl("input",{cls:"csv-add-row-control",type:"text",placeholder:Mt(R)})}),w.forEach(R=>{let F=L.createDiv({cls:"csv-add-row csv-add-row-notes"});F.createEl("span",{cls:"csv-add-row-label",text:Mt(R)}),D[R]=F.createEl("textarea",{cls:"csv-add-row-textarea",placeholder:"Optional notes\u2026"})});let N=E.createEl("button",{text:"Add",cls:"csv-add-submit"}),O=M.querySelector(".csv-add-card-title"),j=()=>{if(!x.length)return;let R=D[x[0]];if(!R)return;let F=R.value,P=f.find(H=>H[x[0]]===F);O&&O.setText(P?`Updating ${F}`:"New entry"),E.classList.toggle("is-updating",!!P),N.setText(P?"Update":"Add"),C.forEach(H=>{var B;let I=D[H];if(!I)return;let V=((B=P==null?void 0:P[H])!=null?B:"").toLowerCase().trim(),q=V==="1"||V==="true"||V==="yes";I.checked=q,T[H]=q}),[...S,...w].forEach(H=>{var q,B;let I=D[H];if(!I)return;let V=(q=P==null?void 0:P[H])!=null?q:"";if(I instanceof HTMLSelectElement)if(Array.from(I.options).find(U=>U.value===V)){I.value=V;let U=(B=D[`${H}__custom`])==null?void 0:B.closest(".csv-add-row-custom");U&&(U.style.display="none")}else I.value="";else I instanceof HTMLTextAreaElement,I.value=V})};if(j(),x.length){let R=D[x[0]];R==null||R.addEventListener("change",j)}let z=()=>{E.style.display="block",_.style.display="none";let R=E.querySelector(".csv-add-row-control");R==null||R.focus()},K=()=>{E.style.display="none",_.style.display=""};_.addEventListener("click",z),k.addEventListener("click",K),N.addEventListener("click",async()=>{let R={};u.forEach(B=>{var Y,U,G,nt;C.includes(B)?R[B]=T[B]?"1":"0":D[B]instanceof HTMLSelectElement&&D[B].value==="__custom__"?R[B]=(U=(Y=D[`${B}__custom`])==null?void 0:Y.value)!=null?U:"":D[B]instanceof HTMLTextAreaElement?R[B]=D[B].value:R[B]=(nt=(G=D[B])==null?void 0:G.value)!=null?nt:""});let F=x.length>0&&x.some(B=>{var Y;return((Y=R[B])!=null?Y:"").trim()}),P=[...S,...w].some(B=>{var Y;return((Y=R[B])!=null?Y:"").trim()}),H=C.some(B=>T[B]);if(!F&&!P&&!H){new ue.Notice("Please fill at least one field");return}let I=[];try{let B=await s.vault.read(d);I=qt(B).rows}catch(B){new ue.Notice(`Error reading file: ${B}`);return}let V=!1,q=-1;if(x.length>0){let B=x[0],Y=R[B];if(q=I.findIndex(U=>U[B]===Y),q>=0){V=!0;let U=I[q];u.forEach(G=>{var nt;(C.includes(G)||((nt=R[G])!=null?nt:"").trim())&&(U[G]=R[G])})}else I.push(R)}else I.push(R);try{let B=qo.default.unparse(I,{columns:u});await s.vault.modify(d,B),new ue.Notice(V?`Updated entry for ${R[x[0]]||""}`:`Added entry to ${d.basename}`),f.length=0,f.push(...I),x.length>0?j():(C.forEach(Y=>{T[Y]=!1;let U=D[Y];U&&(U.checked=!1)}),[...S,...w].forEach(Y=>{let U=D[Y];U instanceof HTMLSelectElement?U.selectedIndex=0:(U instanceof HTMLTextAreaElement||U)&&(U.value="");let G=D[`${Y}__custom`];if(G){G.value="";let nt=G.closest(".csv-add-row-custom");nt&&(nt.style.display="none")}})),setTimeout(async()=>{let Y=s.vault.getAbstractFileByPath(n.sourcePath);if(Y instanceof ue.TFile){let U=s.workspace.activeLeaf;U&&await U.openFile(Y,{state:{mode:"preview"}})}},300)}catch(B){new ue.Notice(`Error saving: ${B}`)}})}function hn(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=b=>{c.style.width=Math.max(60,f+b.clientX-u)+"px"},m=b=>{s.settings.columnWidths[l]=Math.max(60,f+b.clientX-u),h.removeEventListener("pointermove",p),h.removeEventListener("pointerup",m),s.persistSettings()};h.addEventListener("pointermove",p),h.addEventListener("pointerup",m)})}),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 m=((g=l[u])!=null?g:"").replace(/#{1,6}\s/g,"").replace(/[*_>`]/g,"").split(` +`).filter(x=>x.trim()).slice(0,3).join(" \xB7 "),b=m?m.slice(0,200)+(m.length>200?"\u2026":""):"+ Add note",C=f.createSpan({text:b});m||C.addClass("csv-table-notes-empty"),f.title="Click to open note",f.addEventListener("click",x=>{x.stopPropagation(),s.openNoteExpander(l,u)})}else if(s.isSelectCol(u))s.renderSelectField(f,l,u);else{let m=(p=l[u])!=null?p:"";f.setText(m),m.length>80&&(f.title=m),Ec(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 Ec(s,t,e,n){t.addEventListener("click",()=>{var o;t.empty();let i=t.createEl("input",{cls:"csv-inline-input",value:(o=e[n])!=null?o:"",type:"text"});i.focus(),i.select(),i.addEventListener("blur",()=>{e[n]=i.value,s.scheduleSave(),t.empty(),t.setText(i.value||"\u2014")}),i.addEventListener("keydown",r=>{r.key==="Enter"&&i.blur(),r.key==="Escape"&&(t.empty(),t.setText(e[n]||"\u2014"))})})}function un(s){return!!(s.getCategoryCol()||s.getStatusCol()||Qo(s)||s.authorKey())}function Qo(s){return s.resolveCol(["Rating","rating","Score","score","Score /5","Stars","stars"])}function As(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 Zo=["watched","read","finished","completed","done","yes","seen"],Jo=["watching","reading","in progress","in-progress"],kc=["dropped","abandoned","dnf"];function wc(s){let t=s.toLowerCase();return Zo.includes(t)?"is-done":Jo.includes(t)?"is-progress":kc.includes(t)?"is-dropped":""}function Ts(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 Ls(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 tr(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=Qo(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 Zo.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 Jo.includes(((p=g[i])!=null?p:"").toLowerCase().trim())}).length;f>0&&d(String(f),"in progress")}if(o){let u=Ts(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=>As(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=Ts(e,g=>{var m;let p=((m=g[i])!=null?m:"").trim();return p?[p]:[]}),f=Array.from(u.entries()).sort((g,p)=>p[1]-g[1]).map(([g,p])=>({label:g,count:p,cls:wc(g),onClick:o?()=>h(g,null):void 0}));Ls(n,`By ${i.toLowerCase()}`,f,e.length)}if(o){let u=Ts(e,g=>{var p;return((p=g[o])!=null?p:"").split(",").map(m=>m.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)}));Ls(n,`By ${o.toLowerCase()}`,f,e.length)}if(r){let u=new Map,f=0;if(e.forEach(g=>{var b;let p=As(g[r]);if(p===null)return;let m=Math.min(5,Math.max(1,Math.round(p)));u.set(m,((b=u.get(m))!=null?b:0)+1),f++}),f>0){let g=[5,4,3,2,1].filter(p=>{var m;return((m=u.get(p))!=null?m:0)>0}).map(p=>({label:"\u2605".repeat(p),count:u.get(p),cls:"is-rating"}));Ls(n,"Ratings",g,f)}}if(l){let u=Ts(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}));Ls(n,"By year",f,e.length)}}if(a){let u=Ts(e,g=>{var m;let p=((m=g[a])!=null?m:"").trim();return p?[p]:[]}),f=Array.from(u.entries()).filter(([,g])=>g>1);if(f.length>=2){let g=f.sort((p,m)=>m[1]-p[1]||p[0].localeCompare(m[0])).slice(0,8).map(([p,m])=>({label:p,count:m}));Ls(n,`Top ${a.toLowerCase()}s`,g,e.length)}}}function Ht(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),Vo(s.headers,s.rows,n)}function fn(s,t){let e=Ht(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(m=>!s.isNotesCol(m)).forEach(m=>{let b=l.createEl("option",{text:m===n?`${m} (default)`:m,value:m});m===e&&(b.selected=!0)}),l.addEventListener("change",()=>{let m=s.fileCfg;m.kanbanGroupCol=l.value===n?void 0:l.value,s.saveFileCfg(m),s.renderView(!0)});let c=Fo(e,r.map(m=>{var b;return(b=m[e])!=null?b:""})),d=m=>{var x;let b=(x=m[e])!=null?x:"",C;if(c){let w=Io(b);C=w?[w]:[]}else C=b.split(",").map(w=>w.trim()).filter(Boolean);return C.length||(C=["\u2014"]),C},h=new Set;r.forEach(m=>d(m).forEach(b=>h.add(b)));let u=Array.from(h).sort();if(!u.length){let m=t.createDiv({cls:"csv-empty-state"});m.createEl("p",{text:s.searchQuery?"No matching entries found.":`No "${e}" values found.`}),s.searchQuery&&m.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(m=>{var b;return(b=m[o])!=null?b:""}).filter(Boolean)])).filter(m=>r.some(b=>{var C;return((C=b[o])!=null?C:"")==m})):[],p=t.createDiv({cls:"csv-kanban-board"});u.forEach(m=>{let b=r.filter(S=>d(S).includes(m));if(!b.length)return;let C=p.createDiv({cls:"csv-kanban-col"}),x=C.createDiv({cls:"csv-kanban-col-header"});x.createDiv({cls:"csv-kanban-col-title",text:m}),x.createDiv({cls:"csv-kanban-col-count",text:String(b.length)});let w=C.createDiv({cls:"csv-kanban-col-body"});if(o&&g.length){g.forEach(v=>{let _=b.filter(M=>{var k;return((k=M[o])!=null?k:"")===v});if(!_.length)return;let E=w.createDiv({cls:"csv-kanban-status-group"});E.createDiv({cls:`csv-kanban-status-label status-${v.toLowerCase().replace(/\s+/g,"-")}`,text:v}),_.forEach(M=>ui(s,E,M,o,e))});let S=new Set(g),y=b.filter(v=>{var _;return!S.has((_=v[o])!=null?_:"")});if(y.length){let v=w.createDiv({cls:"csv-kanban-status-group"});v.createDiv({cls:"csv-kanban-status-label",text:"\u2014"}),y.forEach(_=>ui(s,v,_,o,e))}}else b.forEach(S=>ui(s,w,S,o,e))})}function ui(s,t,e,n,i){var v,_,E,M,k,L,D;let o=t.createDiv({cls:"csv-kanban-card"}),r=s.getNotesCol(),a=(_=(v=s.getImageCol)==null?void 0:v.call(s))!=null?_:null;if(a){let T=nn(s.app,(E=e[a])!=null?E:"",(k=(M=s.file)==null?void 0:M.path)!=null?k:"");if(T){let A=o.createEl("img",{cls:"csv-kanban-card-img",attr:{src:T,loading:"lazy",alt:""}});A.addEventListener("error",()=>A.remove())}}let l=o.createDiv({cls:"csv-kanban-card-title-row"});l.createDiv({cls:`csv-kanban-card-title ${(L=s.isHighlighted)!=null&&L.call(s,e)?"csv-title-highlight":""}`,text:s.getTitle(e)}).addEventListener("click",T=>{T.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",T=>{T.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)),m=o.createDiv({cls:"csv-kanban-card-meta"});s.headers.forEach(T=>{if(p.has(T)||s.isNotesCol(T))return;let A=m.createDiv({cls:"csv-kanban-chip"});if(A.createSpan({cls:"csv-chip-label",text:T+": "}),s.isSelectCol(T)){let N=A.createSpan({cls:`csv-chip-value csv-chip-select${e[T]?"":" csv-chip-value--empty"}`,text:e[T]||"\u2014"});N.addEventListener("click",O=>{O.stopPropagation(),It(N,e[T],s.getColumnValues(T),j=>{e[T]=j,N.setText(j||"\u2014"),N.classList.toggle("csv-chip-value--empty",!j),s.scheduleSave()},s.contentEl,{multi:Et(T)})})}else{let N=e[T]?e[T].length>40?e[T].slice(0,38)+"\u2026":e[T]:"\u2014",O=A.createSpan({cls:`csv-chip-value${e[T]?"":" csv-chip-value--empty"}`,text:N});e[T]&&e[T].length>40&&(O.title=e[T])}});let b=s.getNotesCol(),C=!!(b&&((D=e[b])!=null&&D.trim())),x=o.createDiv({cls:"csv-kanban-notes-preview"});if(C&&b){let T=e[b].replace(/#{1,6}\s/g,"").replace(/[*_>`]/g,"").replace(/\n+/g," ").trim();x.setText(T.slice(0,120)+(T.length>120?"\u2026":"")),x.title="Click to edit"}else x.addClass("csv-kanban-notes-preview--empty"),b&&x.setText("+ Add note");let w=o.createDiv({cls:"csv-kanban-notes-editor"});w.style.display="none";let S=()=>{var j,z,K;let T=s.contentEl.querySelector(".csv-content-area"),A=(j=T==null?void 0:T.scrollLeft)!=null?j:0,N=(z=T==null?void 0:T.scrollTop)!=null?z:0;x.style.display="none",w.style.display="block",w.empty();let O=w.createEl("textarea",{cls:"csv-notes-textarea"});O.value=(K=b?e[b]:"")!=null?K:"",O.addEventListener("click",$=>$.stopPropagation()),O.addEventListener("mousedown",$=>$.stopPropagation()),O.addEventListener("input",()=>{O.style.height="auto",O.style.height=O.scrollHeight+"px"}),O.addEventListener("keydown",$=>{$.key==="Escape"&&y(O.value,T,A,N)}),O.addEventListener("blur",()=>y(O.value,T,A,N)),O.focus({preventScroll:!0}),O.setSelectionRange(0,0),O.scrollTop=0,requestAnimationFrame(()=>{O.style.height="auto",O.style.height=Math.max(120,O.scrollHeight)+"px"})},y=(T,A,N,O)=>{if(b&&(e[b]=T,s.scheduleSave()),w.style.display="none",x.style.display="",T.trim()){let j=T.replace(/#{1,6}\s/g,"").replace(/[*_>`]/g,"").replace(/\n+/g," ").trim();x.setText(j.slice(0,120)+(j.length>120?"\u2026":"")),x.removeClass("csv-kanban-notes-preview--empty"),x.title="Click to edit"}else x.addClass("csv-kanban-notes-preview--empty"),x.setText(b?"+ Add note":""),x.removeAttribute("title");A&&(A.scrollLeft=N,A.scrollTop=O,requestAnimationFrame(()=>{A.scrollLeft=N,A.scrollTop=O,requestAnimationFrame(()=>{A.scrollLeft=N,A.scrollTop=O})}),setTimeout(()=>{A.scrollLeft=N,A.scrollTop=O},50))};x.addEventListener("click",T=>{if(T.stopPropagation(),b&&matchMedia("(pointer: coarse)").matches){s.openNoteExpander(e,b);return}S()}),o.addEventListener("contextmenu",T=>s.openRowContextMenu(e,T))}function gn(s,t){var E,M;let e=Ht(s),n=s.getStatusCol(),i=(E=s.titleKey())!=null?E: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 D;((D=k[e])!=null?D:"").split(",").map(T=>T.trim()).filter(Boolean).forEach(T=>r.add(T))});let a=new Set;n&&s.rows.forEach(k=>{var D;let L=((D=k[n])!=null?D:"").trim();L&&a.add(L)});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"]),m=s.resolveCol(["Rating","rating","Score","score","Score /5","Stars","stars"]),b=s.resolveCol(["Theme","theme","Tags","tags","Tag","tag","Mood","mood"]),C=(M=s.fileCfg.librarySort)!=null?M:"status",x=l.createEl("select",{cls:"csv-library-filter-select"}),w=[["status","Sort: Status"],["title","Sort: Title"]];m&&w.push(["rating","Sort: Rating"]),p&&w.push(["year","Sort: Year"]),w.forEach(([k,L])=>{let D=x.createEl("option",{text:L,value:k});k===C&&(D.selected=!0)}),x.addEventListener("change",()=>{let k=s.fileCfg;k.librarySort=x.value==="status"?void 0:x.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 y=s.rows.filter(k=>{var L,D;if(s.libraryStatusFilter!=="all"&&n){let T=((L=k[n])!=null?L:"").toLowerCase();if(s.libraryStatusFilter==="__done__"){if(!d.includes(T))return!1}else if(s.libraryStatusFilter==="__inprogress__"){if(!h.includes(T))return!1}else if(s.libraryStatusFilter==="__notstarted__"){if(d.includes(T)||h.includes(T))return!1}else if(T!==s.libraryStatusFilter.toLowerCase())return!1}if(s.libraryGenreFilter!=="all"&&!((D=k[e])!=null?D:"").split(",").map(A=>A.trim().toLowerCase()).includes(s.libraryGenreFilter.toLowerCase()))return!1;if(s.searchQuery.trim()){let T=s.searchQuery.toLowerCase().trim();if(!s.headers.some(A=>{var N;return((N=k[A])!=null?N:"").toLowerCase().includes(T)}))return!1}return!0});(s.libraryStatusFilter!=="all"||s.libraryGenreFilter!=="all"||s.searchQuery.trim())&&t.createDiv({cls:"csv-library-result-count",text:`Showing ${y.length} of ${s.rows.length} entries`});let v={};y.forEach(k=>{var D;let L=s.libraryGenreFilter!=="all"?[s.libraryGenreFilter]:((D=k[e])!=null?D:"Uncategorized").split(",").map(T=>T.trim()).filter(Boolean);L.length===0&&L.push("Uncategorized"),L.forEach(T=>{v[T]||(v[T]=[]),v[T].push(k)})});let _=t.createDiv({cls:"csv-library-sections"});if(Object.keys(v).sort().forEach(k=>{var Z,R,F,P,H;let L=v[k],D=_.createEl("details",{cls:"csv-library-section"}),T=k.toLowerCase(),A=((Z=s.fileCfg.collapsedGroups)!=null?Z:[]).map(I=>I.toLowerCase());D.open=!((R=s.collapsedGroups)!=null&&R.has(T)||A.includes(T)),D.addEventListener("toggle",()=>{var Y;let I=s.fileCfg,V=((Y=I.collapsedGroups)!=null?Y:[]).map(U=>U.toLowerCase()),q=new Set(V);D.open?q.delete(T):q.add(T);let B=Array.from(q);B.length===V.length&&B.every(U=>V.includes(U))||(I.collapsedGroups=B,s.saveFileCfg(I))});let N=D.createEl("summary",{cls:"csv-library-section-header"});N.innerHTML=`\u25B6 ${k} ${L.length}`;let O=D.createDiv({cls:"csv-library-grid"}),j=(I,V)=>{var q,B;return((q=I[i])!=null?q:"").localeCompare((B=V[i])!=null?B:"")},z=(I,V)=>I===null&&V===null?0:I===null?1:V===null?-1:V-I;L.sort((I,V)=>{var q,B,Y,U;if(C==="title")return j(I,V);if(C==="rating"&&m)return z(As((q=I[m])!=null?q:""),As((B=V[m])!=null?B:""))||j(I,V);if(C==="year"&&p){let G=nt=>{var st;let J=((st=nt[p])!=null?st:"").match(/\d{4}/);return J?parseInt(J[0],10):null};return z(G(I),G(V))||j(I,V)}if(n){let G=((Y=I[n])!=null?Y:"").toLowerCase(),nt=((U=V[n])!=null?U:"").toLowerCase(),J=d.includes(G),st=d.includes(nt);if(J!==st)return J?-1:1;let lt=h.includes(G),Ot=h.includes(nt);if(lt!==Ot)return lt?-1:1}return j(I,V)});let K=[o,p,m,b].filter(I=>!!I),$=(F=s.fileCfg.cardFields)!=null?F:K,X=(H=(P=s.getImageCol)==null?void 0:P.call(s))!=null?H:null;L.forEach(I=>{var U,G,nt,J,st,lt,Ot,Ft;let V=O.createDiv({cls:"csv-library-card"});if(X){let dt=nn(s.app,(U=I[X])!=null?U:"",(nt=(G=s.file)==null?void 0:G.path)!=null?nt:"");if(dt){let it=V.createEl("img",{cls:"csv-library-card-img",attr:{src:dt,loading:"lazy",alt:""}});it.addEventListener("error",()=>it.remove())}}let q=V.createDiv({cls:`csv-library-card-title ${(J=s.isHighlighted)!=null&&J.call(s,I)?"csv-title-highlight":""}`});if(n){let dt=((st=I[n])!=null?st:"").toLowerCase();d.includes(dt)&&q.createSpan({cls:"csv-library-done-dot"})}q.createSpan({text:(lt=I[i])!=null?lt:"Untitled"});let B=[],Y=[];for(let dt of $){if(!dt)continue;let it=String((Ot=I[dt])!=null?Ot:"").trim();if(it)if(dt===m){let vt=Oo(it,dt);vt&&V.createDiv({cls:"csv-library-card-rating",text:vt})}else if(dt===b)Y.push(...it.split(",").map(vt=>vt.trim()).filter(Boolean));else if(dt===p){let vt=it.match(/\d{4}/);B.push(vt?vt[0]:it)}else B.push(it)}if(B.length&&V.createDiv({cls:"csv-library-card-meta",text:B.join(" \xB7 ")}),s.libraryGenreFilter!=="all"){let dt=((Ft=I[e])!=null?Ft:"").split(",").map(it=>it.trim()).filter(it=>it&&it.toLowerCase()!==s.libraryGenreFilter.toLowerCase());Y.push(...dt)}if(Y.length){let dt=V.createDiv({cls:"csv-library-card-tags"});Y.slice(0,3).forEach(it=>{dt.createSpan({cls:"csv-library-card-tag",text:it})})}V.addEventListener("click",()=>{var dt;s.openNoteExpander(I,(dt=s.getNotesCol())!=null?dt:"")}),V.addEventListener("contextmenu",dt=>s.openRowContextMenu(I,dt))})}),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 vn=require("obsidian");var Te=require("obsidian");var fi=`--- obsidianUIMode: preview obsidianEditingMode: source --- -`,hi=` +`,gi=` --- Requires Dataview plugin with DataviewJS enabled -`;function Qo(s){let{filePath:t,csvPath:e,habitCols:n,labels:i,dateCol:o}=s;return`${di}## Quick Add +`;function er(s){let{filePath:t,csvPath:e,habitCols:n,labels:i,dateCol:o}=s;return`${fi}## Quick Add \`\`\`csv-add file: ${t} @@ -117,7 +117,7 @@ if (!csvData || !csvData.length) { } } \`\`\` -${hi}`}function Zo(s){let{filePath:t,csvPath:e,titleKey:n,categoryCol:i,statusCol:o,authorKey:r,yearCol:a,ratingCol:l,themeCol:c,compactGrid:d}=s;return`${di}## Add Entry +${gi}`}function sr(s){let{filePath:t,csvPath:e,titleKey:n,categoryCol:i,statusCol:o,authorKey:r,yearCol:a,ratingCol:l,themeCol:c,compactGrid:d}=s;return`${fi}## Add Entry \`\`\`csv-add file: ${t} @@ -295,7 +295,7 @@ if (!csvData || !csvData.length) { } } \`\`\` -${hi}`}function Jo(s){let{filePath:t,csvPath:e,headers:n}=s;return`${di}## Add Entry +${gi}`}function nr(s){let{filePath:t,csvPath:e,headers:n}=s;return`${fi}## Add Entry \`\`\`csv-add file: ${t} @@ -365,12 +365,12 @@ if (!csvData || !csvData.length) { } } \`\`\` -${hi}`}async function tr(s){var c,d,h,u,f,g,p,m,b,x;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=Qo({filePath:a,csvPath:i,habitCols:C,labels:C.map(Mt),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=Zo({filePath:a,csvPath:i,titleKey:C,categoryCol:r,statusCol:(g=s.getStatusCol())!=null?g:"Status",authorKey:(p=s.authorKey())!=null?p:"",yearCol:(m=s.resolveCol(["Year","year","Released","released"]))!=null?m:"",ratingCol:(b=s.resolveCol(["Rating","rating","Score","score","Stars","stars"]))!=null?b:"",themeCol:(x=s.resolveCol(["Theme","theme","Subgenre","subgenre","Mood","mood"]))!=null?x:"",compactGrid:s.titleKey()!==null})}else l=Jo({filePath:a,csvPath:i,headers:s.headers});try{let C=s.app.vault.getAbstractFileByPath(n);C&&C instanceof Te.TFile?(await s.app.vault.modify(C,l),new Te.Notice(`Updated: ${n}`)):(await s.app.vault.create(n,l),new Te.Notice(`Created: ${n}`))}catch(C){let w=s.app.vault.getAbstractFileByPath(n);w instanceof Te.TFile&&(await s.app.vault.modify(w,l),new Te.Notice(`Updated: ${n}`))}}var fe=require("obsidian"),Sc="http://127.0.0.1:8765",Ec=6;async function er(s,t){let e;try{e=await(0,fe.requestUrl)({url:Sc,method:"POST",contentType:"application/json",body:JSON.stringify({action:s,version:Ec,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 kc(s){var e,n,i;let t=s.fileCfg.ankiFrontCol;return t&&s.headers.includes(t)?t:(i=(n=(e=s.titleKey())!=null?e:s.resolveCol(["Quote","Headline","Phrase","Term","Word","Question","Front","Name","Title"]))!=null?n:s.headers[0])!=null?i:null}function ui(s){return s.replace(/&/g,"&").replace(//g,">")}function wc(s,t,e){return s.headers.filter(n=>{var i;return n!==e&&((i=t[n])!=null?i:"").trim()}).map(n=>`${ui(n)}: ${ui(t[n].trim())}`).join("
")}async function sr(s){if(!s.file)return;let t=kc(s);if(!t){new fe.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 fe.Notice(`Nothing to sync \u2014 no rows with a "${t}" value.`,6e3);return}let i=new fe.Notice(`Syncing ${n.length} cards to Anki deck \u201C${e}\u201D\u2026`,0);try{await er("createDeck",{deck:e});let o=n.map(c=>({deckName:e,modelName:"Basic",fields:{Front:ui(c[t].trim()),Back:wc(s,c,t)},options:{allowDuplicate:!1,duplicateScope:"deck"},tags:["datadeck"]})),r=await er("addNotes",{notes:o}),a=r.filter(c=>c!=null).length,l=r.length-a;i.hide(),new fe.Notice(`Anki sync: ${a} added${l?`, ${l} already present`:""} (deck \u201C${e}\u201D).`,6e3)}catch(o){i.hide(),new fe.Notice(`Anki sync failed: ${o instanceof Error?o.message:String(o)}`,8e3)}}function un(s){return s.resolveCol(["Type","type","Kind","kind","Item","item"])}function gi(s){var t;return(t=s.resolveCol(["Project","project","Projects","projects","Area","area"]))!=null?t:Ht(s)}function rr(s){return s.resolveCol(["Due","due","Deadline","deadline","Due Date","Due date","due date"])}function fn(s){return s.resolveCol(["Priority","priority","Prio","prio","Importance","importance"])}var Mc=["task","todo","to-do","action",""],Dc=["task","todo","to-do","action","note","idea","reference","ref"],ar=["done","complete","completed","finished","closed","resolved","yes","x","\u2713","true"],Tc={high:0,med:1,medium:1,normal:1,low:2};function Xe(s){if(rr(s)||fn(s))return!0;let t=un(s);return t?s.rows.some(e=>{var n;return Dc.includes(((n=e[t])!=null?n:"").trim().toLowerCase())}):!1}function Lc(s,t,e){var n;return e?Mc.includes(((n=t[e])!=null?n:"").trim().toLowerCase()):!0}function Ac(s,t,e){if(Lc(s,t,e))return"task";let n=(e?t[e]:"").trim().toLowerCase();return n==="idea"||n==="ideas"?"idea":"note"}function qe(s,t,e){var n;return e?ar.includes(((n=t[e])!=null?n:"").trim().toLowerCase()):!1}function nr(s){let t=Tc[(s!=null?s:"").trim().toLowerCase()];return t===void 0?3:t}function ir(s){return(s!=null?s:"").trim()?0:1}function Pc(){return new Date().toISOString().slice(0,10)}function Rc(s,t){let e=new Map;s.rows.forEach(o=>{var a,l;let r=((a=o[t])!=null?a:"").trim();r&&ar.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 lr(s,t){var E;let e=gi(s),n=un(s),i=s.getStatusCol(),o=rr(s),r=fn(s),a=(E=s.titleKey())!=null?E:s.headers[0],l=t.createDiv({cls:"csv-library-filters"}),c=new Set;e&&s.rows.forEach(M=>{var k;((k=M[e])!=null?k:"").split(",").map(L=>L.trim()).filter(Boolean).forEach(L=>c.add(L))});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(M=>d.createEl("option",{text:M,value:M})),d.value=s.taskProjectFilter;let h=new Set;n&&s.rows.forEach(M=>{var L;let k=((L=M[n])!=null?L:"").trim();k&&h.add(k)});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(M=>u.createEl("option",{text:M,value:M})),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(M=>{var k,L;return!(s.taskProjectFilter!=="all"&&e&&!((k=M[e])!=null?k:"").split(",").map(T=>T.trim().toLowerCase()).includes(s.taskProjectFilter.toLowerCase())||s.taskTypeFilter!=="all"&&n&&((L=M[n])!=null?L:"").trim().toLowerCase()!==s.taskTypeFilter.toLowerCase()||g&&!s.headers.some(D=>{var T;return((T=M[D])!=null?T:"").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 m={},b={},x={},C={task:m,note:b,idea:x},w=M=>{var L;return e&&((L=M[e])!=null?L:"").split(",").map(D=>D.trim()).filter(Boolean)[0]||"\u2014"};p.forEach(M=>{var D;let k=C[Ac(s,M,n)],L=w(M);((D=k[L])!=null?D:k[L]=[]).push(M)});let S=t.createDiv({cls:"csv-tasks"}),y=Pc(),v=i?Rc(s,i):"done";fi(S,"Tasks",m,(M,k)=>{k.sort((L,D)=>{var N,O,j,z,K,$;let T=qe(s,L,i),A=qe(s,D,i);if(T!==A)return T?1:-1;if(r){let Q=nr((N=L[r])!=null?N:"")-nr((O=D[r])!=null?O:"");if(Q)return Q}if(o){let Q=ir((j=L[o])!=null?j:"")-ir((z=D[o])!=null?z:"");if(Q)return Q;let X=((K=L[o])!=null?K:"").localeCompare(($=D[o])!=null?$:"");if(X)return X}return s.getTitle(L).localeCompare(s.getTitle(D))}),k.forEach(L=>{var z;let D=qe(s,L,i),T=M.createEl("tr"),A=T.createEl("td",{cls:"csv-tasks-check-cell"});if(i){let K=A.createEl("span",{cls:`csv-tasks-check ${D?"is-done":""}`,text:D?"\u2713":""});K.setAttr("title",D?"Mark not done":"Mark done"),K.addEventListener("click",$=>{$.stopPropagation(),L[i]=D?"":v,s.scheduleSave(),s.renderView(!0)})}or(s,T,L,a,D);let N=T.createEl("td",{cls:"csv-tasks-due"}),O=o?((z=L[o])!=null?z:"").slice(0,10):"";N.setText(O||"\u2014"),O&&!D&&O{var Q;K.stopPropagation();let $=Array.from(new Set([...s.getColumnValues(r),"high","medium","low"]));It(j,(Q=L[r])!=null?Q:"",$,X=>{L[r]=X,s.scheduleSave(),s.renderView(!0)},s.contentEl)})),T.addEventListener("contextmenu",K=>s.openRowContextMenu(L,K))})},["","Name","Due","Priority"]);let _=(M,k)=>{k.sort((L,D)=>{let T=qe(s,L,i),A=qe(s,D,i);return T!==A?T?1:-1:s.getTitle(L).localeCompare(s.getTitle(D))}),k.forEach(L=>{let D=qe(s,L,i),T=M.createEl("tr"),A=T.createEl("td",{cls:"csv-tasks-check-cell"});if(i){let j=A.createEl("span",{cls:`csv-tasks-check ${D?"is-done":""}`,text:D?"\u2713":""});j.setAttr("title",D?"Mark not done":"Mark done"),j.addEventListener("click",z=>{z.stopPropagation(),L[i]=D?"":v,s.scheduleSave(),s.renderView(!0)})}let N=n&&L[n]||"",O=T.createEl("td",{cls:"csv-tasks-type-cell"});N&&O.createSpan({cls:"csv-tasks-type-pill",text:N}),or(s,T,L,a,D),T.addEventListener("contextmenu",j=>s.openRowContextMenu(L,j))})};if(fi(S,"Notes",b,_,["","Type","Name"]),fi(S,"Ideas",x,_,["","Type","Name"]),Object.keys(m).length===0&&Object.keys(b).length===0&&Object.keys(x).length===0){let M=S.createDiv({cls:"csv-empty-state"});M.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")&&M.createEl("button",{cls:"csv-clear-filters-btn",text:"Clear filters"}).addEventListener("click",()=>{s.taskProjectFilter="all",s.taskTypeFilter="all",s.searchQuery="",s.renderView()})}}function fi(s,t,e,n,i){if(Object.keys(e).length===0)return;s.createDiv({cls:"csv-tasks-section-header",text:t});let o=s.createDiv({cls:"csv-tasks-section"});Object.keys(e).sort().forEach(r=>{let a=e[r],l=o.createEl("details",{cls:"csv-tasks-group"});l.open=!0;let c=l.createEl("summary",{cls:"csv-tasks-group-header"});c.innerHTML=`\u25B6 ${r} ${a.length}`;let d=l.createEl("table",{cls:"csv-tasks-table"}),u=d.createEl("thead").createEl("tr");i.forEach(g=>u.createEl("th",{text:g}));let f=d.createEl("tbody");n(f,a)})}function or(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 gn(s){let t=[];return s.isTravelFile()&&t.push({id:"travel",label:"Travel"}),s.hasDateColumn()&&t.push({id:"dashboard",label:"Dashboard"}),Xe(s)&&t.push({id:"tasks",label:"Tasks"}),Ht(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"}),cn(s)&&t.push({id:"stats",label:"Stats"}),t}function cr(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=gn(s),r=i.createEl("select",{cls:"csv-mode-select",attr:{"aria-label":"View mode"}});if(o.forEach(({id:m,label:b})=>{let x=r.createEl("option",{text:b,value:m});s.mode===m&&(x.selected=!0)}),r.addEventListener("change",()=>{s.mode=r.value,s.renderView()}),s.mode!=="dashboard"){let m=n.createEl("button",{cls:"csv-cfg-btn csv-search-toggle",text:"\u{1F50D}",title:"Search"}),b=n.createDiv({cls:"csv-search-wrap"}),x=b.createDiv({cls:"csv-search-input-wrap"}),C=x.createEl("input",{cls:"csv-search-input",type:"text",placeholder:"Search...",value:s.searchQuery,attr:{inputmode:"search",enterkeyhint:"search",autocomplete:"off"}}),w=x.createEl("button",{cls:"csv-search-clear",text:"\xD7",title:"Clear search"});w.toggleClass("is-hidden",!s.searchQuery),b.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"),m.removeClass("has-query"),s.searchQuery="",s.renderView(!0);return}C.blur()});let y=null;C.addEventListener("input",v=>{s.searchQuery=v.target.value,w.toggleClass("is-hidden",!s.searchQuery),m.toggleClass("has-query",!!s.searchQuery),y!==null&&window.clearTimeout(y),y=window.setTimeout(()=>{y=null,s.renderView(!0)},120)}),C.addEventListener("keydown",v=>{v.key==="Enter"&&(v.preventDefault(),C.blur())}),w.addEventListener("click",()=>{s.searchQuery="",C.value="",w.addClass("is-hidden"),m.removeClass("has-query"),C.focus({preventScroll:!0}),s.renderView(!0)}),s.searchQuery&&m.addClass("has-query"),m.addEventListener("click",()=>{e.addClass("csv-toolbar--search-expanded"),C.focus({preventScroll:!0})})}if(s.mode==="table"&&s.hasDateColumn()){let m=(p=s.fileCfg.sortNewestFirst)!=null?p:!0;n.createEl("button",{cls:`csv-cfg-btn ${m?"active":""}`,text:m?"\u2193 Newest":"\u2191 Oldest",title:"Toggle sort order"}).addEventListener("click",()=>{var C;let x=s.fileCfg;x.sortNewestFirst=!((C=x.sortNewestFirst)==null||C),s.saveFileCfg(x),s.tableSortCol=null,s.renderViewPreservingScroll()})}let a=()=>{var m,b;new sn(s.app,s.headers,(b=(m=s.file)==null?void 0:m.path)!=null?b:"",s.fileCfg,s.autoDetectBooleanColumns(),s.autoDetectCategoricalColumns(),gn(s),x=>{s.saveFileCfg(x),x.defaultMode&&(s.mode=x.defaultMode),s.renderView()},()=>s.headers,()=>s.fileCfg,x=>s.addColumn(x),x=>s.removeColumn(x)).open()},l=()=>tr(s),c=()=>s.backupToArchive(),d=()=>sr(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",m=>{let b=new pn.Menu;b.addItem(x=>x.setTitle("Config").setIcon("settings").onClick(a)),b.addItem(x=>x.setTitle("Mobile dashboard").setIcon("smartphone").onClick(l)),b.addItem(x=>x.setTitle("Backup").setIcon("save").onClick(c)),b.addItem(x=>x.setTitle("Sync to Anki").setIcon("layers").onClick(d)),b.addSeparator(),b.addItem(x=>x.setTitle("Built 2026-07-06 08:19").setIcon("info").setDisabled(!0)),b.showAtMouseEvent(m)}),n.createEl("button",{cls:"csv-cfg-btn csv-cfg-btn-secondary csv-info-btn",text:"\u24D8",title:"Built 2026-07-06 08:19 \u2014 click to confirm"}).addEventListener("click",()=>new pn.Notice("datadeck \u2014 built 2026-07-06 08:19",4e3))}function Oc(s){return s&&typeof s=="object"&&"basename"in s?s:null}var Fc=["Author","author","By","by","Source","source","Speaker","speaker","Artist","artist","Director","director"];async function dr(s,t,e,n){var x,C,w;let i=t.split(` -`).map(S=>S.trim()).filter(Boolean),o=S=>{var y,v;return(v=(y=i.find(_=>_.startsWith(S+":")))==null?void 0:y.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=(x=a==null?void 0:a.parent)==null?void 0:x.path)!=null?C:"",c=Ue(r,l),d=Oc(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=qt(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=(w=h.find(S=>S.toLowerCase()===f.toLowerCase()))!=null?w:h[0],p=Fc.map(S=>h.find(y=>y===S)).find(Boolean),m=e.createDiv({cls:"csv-random-card"}),b=()=>{var k;m.empty();let S=u.filter(L=>{var D;return((D=L[g])!=null?D:"").trim()}),y=S.length?S:u,v=y[Math.floor(Math.random()*y.length)];m.createDiv({cls:"csv-random-text",text:v[g]||"\u2014"});let _=p?((k=v[p])!=null?k:"").trim():"";_&&m.createDiv({cls:"csv-random-sub",text:`\u2014 ${_}`});let E=m.createDiv({cls:"csv-random-foot"});E.createSpan({cls:"csv-random-src",text:d.basename}),E.createEl("button",{cls:"csv-random-btn",text:"\u21BB",title:"Another one"}).addEventListener("click",b)};b()}var xo=null;async function sg(){if(xo)return xo;let s=await Promise.resolve().then(()=>(Bl(),Nl));return s.Chart.register(s.LineController,s.LineElement,s.PointElement,s.LinearScale,s.CategoryScale,s.Filler,s.Tooltip),xo=s,s}async function Hl(s,t){var Q,X,R;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((I,P)=>{var H,F;return((H=I[e])!=null?H:"").localeCompare((F=P[e])!=null?F:"")});s.selectedDate||(s.selectedDate=o);let a=r.find(I=>I[e]===s.selectedDate),l=s.selectedDate===o;t.addClass("csv-dashboard");let c=[...new Set([...r.map(I=>I[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 I=c.indexOf(s.selectedDate);if(I>0)s.selectedDate=c[I-1],s.renderView();else if(I===-1&&c.length>0){let P=c.filter(H=>H0&&(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(I=>{let P=f.createEl("option",{text:I,value:I});I===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 I=c.indexOf(s.selectedDate);if(I>=0&&IH>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 I=t.createDiv({cls:"csv-dash-add-section"});I.createEl("p",{text:`No entry for ${s.selectedDate}`}),I.createEl("button",{cls:"csv-dash-add-btn",text:`+ Add entry for ${s.selectedDate}`}).addEventListener("click",()=>{let H={};s.headers.forEach(F=>H[F]=""),H[e]=s.selectedDate,s.rows.push(H),s.scheduleSave(),s.renderView()})}if(a){let I=t.createDiv({cls:"csv-dash-habits"});I.createEl("h3",{text:s.selectedDate===o?"Today":s.selectedDate,cls:"csv-dash-section-title"});let P=I.createDiv({cls:"csv-dash-habits-grid"});n.forEach(F=>{let V=s.isTruthy(a[F]),q=P.createDiv({cls:`csv-dash-habit ${V?"checked":""}`}),B=q.createEl("button",{cls:"csv-dash-habit-check",text:V?"\u25CF":"\u25CB"});q.createSpan({cls:"csv-dash-habit-label",text:F}),B.addEventListener("click",()=>{a[F]=V?"0":"1",s.scheduleSave(),s.renderViewPreservingScroll()})});let H=n.filter(F=>s.isTruthy(a[F])).length;if(I.createDiv({cls:"csv-dash-habits-count",text:`${H} of ${n.length} complete`}),i&&((Q=a[i])!=null&&Q.trim())){let F=I.createDiv({cls:"csv-dash-notes-preview"});F.createEl("strong",{text:"Notes: "}),F.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 b=p.createDiv({cls:"csv-dash-chart-wrap"}).createEl("canvas",{cls:"csv-dash-chart"}),x=r.map(I=>{var H;return((H=I[e])!=null?H:"").slice(5)}),C=r.map(I=>n.filter(P=>s.isTruthy(I[P])).length);s.chartInstance&&(s.chartInstance.destroy(),s.chartInstance=null);let{Chart:w}=await sg();if(!b.isConnected)return;s.chartInstance=new w(b,{type:"line",data:{labels:x,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 y=r.length,v=r.reduce((I,P)=>I+n.filter(H=>s.isTruthy(P[H])).length,0),_=y>0?(v/y).toFixed(1):"0",E=r.filter(I=>n.every(P=>s.isTruthy(I[P]))).length,M=0,k=0,L=null;for(let I of r){let P=n.filter(V=>s.isTruthy(I[V])).length,H=s.parseDate((X=I[e])!=null?X:""),F=!0;L&&H&&Math.round((H.getTime()-L.getTime())/864e5)!==1&&(F=!1),P>=1&&(F||L===null)?(k++,k>M&&(M=k)):P>=1?(k=1,k>M&&(M=k)):k=0,L=H}let D=0,T=new Date;T.setHours(0,0,0,0);let A=T;for(let I=r.length-1;I>=0;I--){let P=s.parseDate((R=r[I][e])!=null?R:"");if(!P)break;let H=Math.round((A.getTime()-P.getTime())/(1e3*60*60*24));if(D===0&&H>1||D>0&&H!==1)break;if(n.filter(V=>s.isTruthy(r[I][V])).length>=1)D++,A=P;else break}let N=S.createDiv({cls:"csv-dash-stats-bar"});N.innerHTML=`${y} days logged \xB7 ${_} avg/day \xB7 ${E} perfect days \xB7 current streak ${D}d \xB7 best streak ${M}d`;let j=t.createDiv({cls:"csv-dash-cards-section"}).createDiv({cls:"csv-dash-cards-grid"}),z=new Date().getFullYear(),K={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(I=>{let P=r.filter(B=>s.isTruthy(B[I])),H=P.length>0?P[P.length-1][e]:null,F=new Set;P.forEach(B=>{var U;let Y=s.parseDate((U=B[e])!=null?U:"");Y&&F.add(Y.getFullYear())});let V=r.filter(B=>{var U;let Y=s.parseDate((U=B[e])!=null?U:"");return Y&&Y.getFullYear()===z}),q=V.filter(B=>s.isTruthy(B[I])).length;return{habit:I,doneCount:P.length,doneThisYear:q,totalThisYear:V.length,lastDone:H,years:Array.from(F).sort()}}).sort((I,P)=>!I.lastDone&&!P.lastDone?0:I.lastDone?P.lastDone?P.lastDone.localeCompare(I.lastDone):-1:1).forEach(({habit:I,doneCount:P,doneThisYear:H,totalThisYear:F,lastDone:V,years:q})=>{var st;let B=j.createDiv({cls:"csv-dash-habit-card"}),Y=(st=K[I.toLowerCase()])!=null?st:"\u25CB",U=B.createDiv({cls:"csv-dash-habit-card-header"});if(U.createSpan({cls:"csv-dash-habit-icon",text:Y}),U.createSpan({cls:"csv-dash-habit-card-name",text:Mt(I)}),q.length>0&&B.createDiv({cls:"csv-dash-habit-years"}).setText(q.join(" \xB7 ")),B.createDiv({cls:"csv-dash-habit-card-thisyear",text:`${H} of ${F} complete this year`}),B.createDiv({cls:"csv-dash-habit-card-alltime",text:`${P} of ${y} all time`}),V){let lt=s.parseDate(V),Ot=lt?lt.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}):V;B.createDiv({cls:"csv-dash-habit-card-last",text:`Last logged: ${Ot}`})}else B.createDiv({cls:"csv-dash-habit-card-last",text:"Never logged"});let G=y>0?P/y*100:0,J=B.createDiv({cls:"csv-dash-habit-progress"}).createDiv({cls:"csv-dash-habit-progress-bar"});J.style.width=`${G}%`,B.addEventListener("click",()=>{s.selectedHabit=s.selectedHabit===I?null:I,s.renderViewPreservingScroll()}),s.selectedHabit===I&&B.addClass("selected")}),s.selectedHabit&&n.includes(s.selectedHabit)&&ng(s,t,r,e,s.selectedHabit)}function ng(s,t,e,n,i){var M,k,L;let o=t.createDiv({cls:"csv-dash-timeline-section"}),r=o.createDiv({cls:"csv-dash-timeline-header"});r.createEl("h3",{text:`${Mt(i)} Timeline`,cls:"csv-dash-section-title"});let a=r.createEl("select",{cls:"csv-dash-year-select"}),l=new Set;e.forEach(D=>{var A;let T=s.parseDate((A=D[n])!=null?A:"");T&&l.add(T.getFullYear())}),l.add(new Date().getFullYear()),Array.from(l).sort().reverse().forEach(D=>{let T=a.createEl("option",{text:String(D),value:String(D)});D===s.timelineYear&&(T.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(D=>{var T;d.set((T=D[n])!=null?T:"",s.isTruthy(D[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(D=>u.createSpan({cls:"csv-dash-timeline-month-label",text:D}));let g=h.createDiv({cls:"csv-dash-timeline-calendar"}),p=g.createDiv({cls:"csv-dash-timeline-day-labels"});for(let D=1;D<=31;D++)p.createDiv({cls:"csv-dash-timeline-day-label",text:D%5===0||D===1?String(D):""});for(let D=0;D<12;D++){let T=g.createDiv({cls:"csv-dash-timeline-month-col"}),A=new Date(s.timelineYear,D+1,0).getDate();for(let N=1;N<=31;N++){if(N>A){T.createDiv({cls:"csv-dash-timeline-cell empty"});continue}let O=`${s.timelineYear}-${String(D+1).padStart(2,"0")}-${String(N).padStart(2,"0")}`,j=(M=d.get(O))!=null?M:!1,z=d.has(O),K=new Date(s.timelineYear,D,N)>new Date,$=T.createDiv({cls:`csv-dash-timeline-cell ${K?"future":""} ${j?"done":""} ${z&&!j?"missed":""} ${!z&&!K?"no-entry":""}`});$.title=`${O}: ${K?"Future":j?"\u2713 Done":z?"\u2717 Missed":"No entry"}`}}let m=e.filter(D=>{var A;let T=s.parseDate((A=D[n])!=null?A:"");return T&&T.getFullYear()===s.timelineYear}),b=m.filter(D=>s.isTruthy(D[i])).length,x=m.length,C=0,w=0,S=0,y=null;for(let D of e){let T=s.isTruthy(D[i]),A=s.parseDate((k=D[n])!=null?k:""),N=!0;y&&A&&Math.round((A.getTime()-y.getTime())/864e5)!==1&&(N=!1),T&&(N||y===null)?(S++,S>w&&(w=S)):T?S=1:S=0,y=A}let v=new Date;v.setHours(0,0,0,0);let _=v;for(let D=e.length-1;D>=0;D--){let T=s.parseDate((L=e[D][n])!=null?L:"");if(!T)break;let A=Math.round((_.getTime()-T.getTime())/(1e3*60*60*24));if(C===0&&A>1||C>0&&A!==1)break;if(s.isTruthy(e[D][i]))C++,_=T;else break}let E=o.createDiv({cls:"csv-dash-timeline-stats"});E.innerHTML=`${b} of ${x} in ${s.timelineYear} \xB7 current streak ${C}d \xB7 best streak ${w}d`}function zl(s,t){var x,C,w;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=(x=s.titleKey())!=null?x: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&&((w=n[o])!=null&&w.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 y;return!u.has(S)&&((y=n[S])!=null?y:"").trim()});if(f.length){let S=c.createDiv({cls:"csv-focus-meta"});f.forEach(y=>{let v=S.createDiv({cls:"csv-kanban-chip"});if(v.createSpan({cls:"csv-chip-label",text:y+": "}),s.isSelectCol(y)){let _=v.createSpan({cls:"csv-chip-value csv-chip-select",text:n[y]});_.addEventListener("click",E=>{E.stopPropagation(),It(_,n[y],s.getColumnValues(y),M=>{n[y]=M,_.setText(M||"\u2014"),s.scheduleSave()},s.contentEl,{multi:Et(y)})})}else v.createSpan({cls:"csv-chip-value",text:n[y]})})}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)"}),m=g.createEl("button",{cls:"csv-focus-nav-btn csv-focus-nav-rand",text:"\u{1F500}",title:"Random entry"}),b=g.createEl("button",{cls:"csv-focus-nav-btn",text:"\u203A",title:"Next (\u2192)"});p.addEventListener("click",()=>l(s.focusIndex-1)),b.addEventListener("click",()=>l(s.focusIndex+1)),m.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 Rt=require("obsidian"),Wl=Qs(xs());var ig=[{id:"table",label:"Table"},{id:"library",label:"Cards"},{id:"kanban-genre",label:"Kanban"}];function $l(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 Co=class extends Rt.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=qt(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=$l(e))})))}onunload(){this.saveTimer&&window.clearTimeout(this.saveTimer)}async reload(){let e=$l(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=qt(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=Wl.default.unparse(this.rows,{columns:this.headers});this.lastWritten=e,await this.app.vault.modify(this.file,e)}catch(e){new Rt.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?this.fileCfg.notesColumn:this.resolveCol(["Notes","notes","Note","note","Summary","summary","Review","review","Quote","quote","Quotes","quotes","Comment","comment","Comments","comments","Description","description","Annotation","annotation"])}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||he(e)||Et(e)?!1:this.fileCfg.categoricalColumns?this.fileCfg.categoricalColumns.includes(e):this.isSelectCol(e)||Gt(this.getColumnValues(e).length)}getStatusCol(){var e;return this.fileCfg.statusColumn?(e=this.headers.find(n=>n.toLowerCase()===this.fileCfg.statusColumn.toLowerCase()))!=null?e:null:this.resolveCol(["Status","status","State","state","Progress","progress","Stage","stage","Read","read","Watched","watched","Seen","seen","Done","done","Completed","completed"])}getCategoryCol(){var e;return this.fileCfg.categoryColumn?(e=this.headers.find(n=>n.toLowerCase()===this.fileCfg.categoryColumn.toLowerCase()))!=null?e:null:this.resolveCol(["Category","category","Categories","categories","Genre","genre","Genres","genres","Type","type","Types","types","Tag","tag","Tags","tags","Topic","topic","Topics","topics","Subject","subject","Section","section"])}titleKey(){var e;return(e=this.resolveCol(["Title","title","Name","name"]))!=null?e: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?(e=this.headers.find(n=>n.toLowerCase()===this.fileCfg.imageColumn.toLowerCase()))!=null?e:null:this.resolveCol(Js)}getBooleanColumns(){var e;return(e=this.fileCfg.habitColumns)!=null&&e.length?this.fileCfg.habitColumns.filter(n=>this.headers.includes(n)):this.headers.filter(n=>{if(n===this.getDateCol()||this.isNotesCol(n))return!1;let i=this.rows.map(o=>{var r;return((r=o[n])!=null?r:"").toLowerCase().trim()});return en(i)})}getDateCol(){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(o=>{var r;return n.test((r=o[e])!=null?r:"")})?e:null}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=Cs(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,Rt.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 Rt.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 Rt.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 Rt.Notice(`Restored \u201C${i}\u201D`,2500))})}openRowContextMenu(e,n){let i=new Rt.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 Ye(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)).open()}openAddModal(){new Ke(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 Rt.Notice(`Added: ${this.getTitle(e)}`)},{},e=>this.getBooleanColumns().includes(e),this.isCategoricalCol.bind(this)).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(),It(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;Rt.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")&&!Ht(this.asView)&&(this.mode="table"),this.mode==="library"?hn(this.asView,i):this.mode==="kanban-genre"?dn(this.asView,i):ln(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=!!Ht(this.asView),r=i.createDiv({cls:"csv-mode-group"});ig.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 jl(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 Co(o,s,t,e,{...a,file:c});r.addChild(d)})}var Xs,bs=class extends rt.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 rt.Component,this.renderComponent.load()}getViewType(){return Zs}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=qt(r);this.headers=a.headers,this.rows=a.rows}catch(r){console.error("CardView load error",r),this.headers=[],this.rows=[],new rt.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&&!Ht(this)||i&&!this.hasDateColumn()||this.mode==="travel"&&!this.isTravelFile()||this.mode==="stats"&&!cn(this)||this.mode==="tasks"&&!Xe(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=Ul.default.unparse(this.rows,{columns:this.headers});await this.app.vault.modify(this.file,e)}catch(e){console.error("CardView save error",e),new rt.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?this.fileCfg.notesColumn:this.resolveCol(["Notes","notes","Note","note","Summary","summary","Review","review","Quote","quote","Quotes","quotes","Comment","comment","Comments","comments","Description","description","Annotation","annotation"])}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||he(e)||Et(e)?!1:this.fileCfg.categoricalColumns?this.fileCfg.categoricalColumns.includes(e):this.isSelectCol(e)||Gt(this.getColumnValues(e).length)}autoDetectCategoricalColumns(){var n;let e=(n=this.titleKey())!=null?n:this.headers[0];return this.headers.filter(i=>i===e||he(i)||Et(i)||this.isNotesCol(i)?!1:this.isSelectCol(i)||Gt(this.getColumnValues(i).length))}getStatusCol(){var e;return this.fileCfg.statusColumn?(e=this.headers.find(n=>n.toLowerCase()===this.fileCfg.statusColumn.toLowerCase()))!=null?e:null:this.resolveCol(["Status","status","State","state","Progress","progress","Stage","stage","Read","read","Watched","watched","Seen","seen","Done","done","Completed","completed"])}getCategoryCol(){var e;return this.fileCfg.categoryColumn?(e=this.headers.find(n=>n.toLowerCase()===this.fileCfg.categoryColumn.toLowerCase()))!=null?e:null:this.resolveCol(["Category","category","Categories","categories","Genre","genre","Genres","genres","Type","type","Types","types","Tag","tag","Tags","tags","Topic","topic","Topics","topics","Subject","subject","Section","section"])}titleKey(){var e;return(e=this.resolveCol(["Title","title","Name","name"]))!=null?e: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?(e=this.headers.find(n=>n.toLowerCase()===this.fileCfg.imageColumn.toLowerCase()))!=null?e:null:this.resolveCol(Js)}notesFilePath(e){var a,l,c;let n=Cs(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,rt.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 rt.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 rt.Notice(`Restored \u201C${i}\u201D`,2500)})}openRowContextMenu(e,n){let i=new rt.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=Xe(this)?gi(this):null,c=l?((o=e[l])!=null?o:"").split(",").map(g=>Do(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,rt.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 rt.Notice(`Created: ${i.name}`)}await this.app.workspace.getLeaf("tab").openFile(i)}openNoteExpander(e,n){var i,o;new Ye(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),this.isCategoricalCol.bind(this)).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 m,b;let g=(b=(m=f.querySelector(".csv-kanban-col-title"))==null?void 0:m.textContent)!=null?b:"",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(m=>{var w,S;let b=(S=(w=m.querySelector(".csv-kanban-col-title"))==null?void 0:w.textContent)!=null?S:"",x=m.querySelector(".csv-kanban-col-body"),C=r.cols.get(b);x&&C!=null&&(x.scrollTop=C)})};a(),requestAnimationFrame(()=>{a(),requestAnimationFrame(a)}),setTimeout(a,50)}openAddModal(){let e={};if(Xe(this)){let n=un(this);n&&(e[n]=["Task","Note","Idea"]);let i=fn(this);i&&(e[i]=["Low","Medium","High"])}new Ke(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 rt.Notice(`Added: ${this.getTitle(n)}`)},e,n=>this.getBooleanColumns().includes(n),this.isCategoricalCol.bind(this)).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(),It(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:Et(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 rt.Component,this.renderComponent.load(),cr(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"?jo(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"?Hl(this,i):this.mode==="library"?hn(this,i):this.mode==="kanban-genre"?dn(this,i):this.mode==="stats"?Xo(this,i):this.mode==="focus"?zl(this,i):this.mode==="tasks"?lr(this,i):ln(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=new Date().toISOString().slice(0,10),o=`${n}/${this.file.basename}_${i}.${this.file.extension}`;if(await this.app.vault.adapter.exists(o)){new rt.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 rt.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(Xs!==void 0)return Xs;let e=(0,rt.normalizePath)(`${this.app.vault.configDir}/plugins/datadeck/world-map.svg`);try{Xs=await this.app.vault.adapter.read(e)}catch(n){Xs=null}return Xs}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 To(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(){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(a=>{var l;return o.test((l=a[e])!=null?l:"")})?e:null}getBooleanColumns(){return this.fileCfg.habitColumns&&this.fileCfg.habitColumns.length>0?this.fileCfg.habitColumns.filter(e=>this.headers.includes(e)):this.autoDetectBooleanColumns()}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 en(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){let n=(e!=null?e:"").toLowerCase().trim();return n==="1"||n==="true"||n==="yes"}renderMarkdownInto(e,n){var i,o;rt.MarkdownRenderer.render(this.app,n,e,(o=(i=this.file)==null?void 0:i.path)!=null?o:"",this.renderComponent)}cycleMode(){let e=gn(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)}},rg=[{id:"tasks",command:"Create tasks file",defaultName:"Tasks",headers:["Title","Type","Project","Status","Priority","Due","Notes"],mode:"tasks"},{id:"travel",command:"Create travel file",defaultName:"Travel",headers:["Country","date_entered","date_left","source","Notes"],mode:"travel"},{id:"habits",command:"Create habit tracker file",defaultName:"Habits",headers:["Date","Exercise","Meditate","Read","Notes"],mode:"dashboard"}],ti=class extends rt.Plugin{constructor(){super(...arguments);this.settings=oi}async onload(){await this.loadSettings(),this.registerView(Zs,e=>new bs(e,this.settings,()=>this.saveSettings())),this.registerExtensions(["csv"],Zs),this.addSettingTab(new an(this.app,this)),this.registerMarkdownCodeBlockProcessor("csv-add",async(e,n,i)=>{await Ko(this.app,e.trim(),n,i,this.settings.fileConfigs)}),this.registerMarkdownCodeBlockProcessor("csv-random",async(e,n,i)=>{await dr(this.app,e.trim(),n,i)}),jl(this.app,this.settings,()=>this.saveSettings(),(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(bs);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(bs);return n?(e||n.cycleMode(),!0):!1}});for(let e of rg)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 rt.TFile&&e.extension==="csv"&&this.settings.fileConfigs[n]&&(Oo(this.settings.fileConfigs,n,e.path),await this.saveSettings())})),this.registerEvent(this.app.vault.on("delete",async e=>{e instanceof rt.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 rt.TFile){let l=this.app.workspace.activeLeaf;l&&await l.openFile(a,{state:{mode:"preview"}})}})})}async createTemplateFile(e){new nn(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=Cs(n),a=(0,rt.normalizePath)(`${o}${r}.csv`);for(let c=2;this.app.vault.getAbstractFileByPath(a);c++)a=(0,rt.normalizePath)(`${o}${r} ${c}.csv`);let l=await this.app.vault.create(a,e.headers.join(",")+` -`);this.settings.fileConfigs[l.path]={...this.settings.fileConfigs[l.path],defaultMode:e.mode},await this.saveSettings(),await this.app.workspace.getLeaf("tab").openFile(l),new rt.Notice(`Created: ${l.name}`)}).open()}async loadSettings(){var e;this.settings=Object.assign({},oi,await this.loadData()),this.settings.residencyRules=JSON.parse(JSON.stringify((e=this.settings.residencyRules)!=null?e:[]))}async saveSettings(){await this.saveData(this.settings)}}; +${gi}`}async function ir(s){var c,d,h,u,f,g,p,m,b,C;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 x=s.getBooleanColumns();l=er({filePath:a,csvPath:i,habitCols:x,labels:x.map(Mt),dateCol:o})}else if(r){let x=(f=(u=(h=s.titleKey())!=null?h:s.resolveCol(["Quote","quote","Headline","headline","Phrase","phrase"]))!=null?u:s.headers[0])!=null?f:"Title";l=sr({filePath:a,csvPath:i,titleKey:x,categoryCol:r,statusCol:(g=s.getStatusCol())!=null?g:"Status",authorKey:(p=s.authorKey())!=null?p:"",yearCol:(m=s.resolveCol(["Year","year","Released","released"]))!=null?m:"",ratingCol:(b=s.resolveCol(["Rating","rating","Score","score","Stars","stars"]))!=null?b:"",themeCol:(C=s.resolveCol(["Theme","theme","Subgenre","subgenre","Mood","mood"]))!=null?C:"",compactGrid:s.titleKey()!==null})}else l=nr({filePath:a,csvPath:i,headers:s.headers});try{let x=s.app.vault.getAbstractFileByPath(n);x&&x instanceof Te.TFile?(await s.app.vault.modify(x,l),new Te.Notice(`Updated: ${n}`)):(await s.app.vault.create(n,l),new Te.Notice(`Created: ${n}`))}catch(x){let w=s.app.vault.getAbstractFileByPath(n);w instanceof Te.TFile&&(await s.app.vault.modify(w,l),new Te.Notice(`Updated: ${n}`))}}var fe=require("obsidian"),Mc="http://127.0.0.1:8765",Dc=6;async function or(s,t){let e;try{e=await(0,fe.requestUrl)({url:Mc,method:"POST",contentType:"application/json",body:JSON.stringify({action:s,version:Dc,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 mi(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 Tc(s){let t=s.fileCfg.ankiFrontCol;return t&&s.headers.includes(t)?t:mi(s)}function pi(s){return s.replace(/&/g,"&").replace(//g,">")}function Lc(s,t,e){return s.headers.filter(n=>{var i;return n!==e&&((i=t[n])!=null?i:"").trim()}).map(n=>`${pi(n)}: ${pi(t[n].trim())}`).join("
")}async function rr(s){if(!s.file)return;let t=Tc(s);if(!t){new fe.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 fe.Notice(`Nothing to sync \u2014 no rows with a "${t}" value.`,6e3);return}let i=new fe.Notice(`Syncing ${n.length} cards to Anki deck \u201C${e}\u201D\u2026`,0);try{await or("createDeck",{deck:e});let o=n.map(c=>({deckName:e,modelName:"Basic",fields:{Front:pi(c[t].trim()),Back:Lc(s,c,t)},options:{allowDuplicate:!1,duplicateScope:"deck"},tags:["datadeck"]})),r=await or("addNotes",{notes:o}),a=r.filter(c=>c!=null).length,l=r.length-a;i.hide(),new fe.Notice(`Anki sync: ${a} added${l?`, ${l} already present`:""} (deck \u201C${e}\u201D).`,6e3)}catch(o){i.hide(),new fe.Notice(`Anki sync failed: ${o instanceof Error?o.message:String(o)}`,8e3)}}function pn(s){return s.resolveCol(["Type","type","Kind","kind","Item","item"])}function vi(s){var t;return(t=s.resolveCol(["Project","project","Projects","projects","Area","area"]))!=null?t:Ht(s)}function dr(s){return s.resolveCol(["Due","due","Deadline","deadline","Due Date","Due date","due date"])}function mn(s){return s.resolveCol(["Priority","priority","Prio","prio","Importance","importance"])}var Ac=["task","todo","to-do","action",""],Rc=["task","todo","to-do","action","note","idea","reference","ref"],hr=["done","complete","completed","finished","closed","resolved","yes","x","\u2713","true"],Pc={high:0,med:1,medium:1,normal:1,low:2};function ts(s){if(dr(s)||mn(s))return!0;let t=pn(s);return t?s.rows.some(e=>{var n;return Rc.includes(((n=e[t])!=null?n:"").trim().toLowerCase())}):!1}function Oc(s,t,e){var n;return e?Ac.includes(((n=t[e])!=null?n:"").trim().toLowerCase()):!0}function Fc(s,t,e){if(Oc(s,t,e))return"task";let n=(e?t[e]:"").trim().toLowerCase();return n==="idea"||n==="ideas"?"idea":"note"}function Je(s,t,e){var n;return e?hr.includes(((n=t[e])!=null?n:"").trim().toLowerCase()):!1}function ar(s){let t=Pc[(s!=null?s:"").trim().toLowerCase()];return t===void 0?3:t}function lr(s){return(s!=null?s:"").trim()?0:1}function Ic(){return new Date().toISOString().slice(0,10)}function Vc(s,t){let e=new Map;s.rows.forEach(o=>{var a,l;let r=((a=o[t])!=null?a:"").trim();r&&hr.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 ur(s,t){var E;let e=vi(s),n=pn(s),i=s.getStatusCol(),o=dr(s),r=mn(s),a=(E=s.titleKey())!=null?E:s.headers[0],l=t.createDiv({cls:"csv-library-filters"}),c=new Set;e&&s.rows.forEach(M=>{var k;((k=M[e])!=null?k:"").split(",").map(L=>L.trim()).filter(Boolean).forEach(L=>c.add(L))});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(M=>d.createEl("option",{text:M,value:M})),d.value=s.taskProjectFilter;let h=new Set;n&&s.rows.forEach(M=>{var L;let k=((L=M[n])!=null?L:"").trim();k&&h.add(k)});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(M=>u.createEl("option",{text:M,value:M})),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(M=>{var k,L;return!(s.taskProjectFilter!=="all"&&e&&!((k=M[e])!=null?k:"").split(",").map(T=>T.trim().toLowerCase()).includes(s.taskProjectFilter.toLowerCase())||s.taskTypeFilter!=="all"&&n&&((L=M[n])!=null?L:"").trim().toLowerCase()!==s.taskTypeFilter.toLowerCase()||g&&!s.headers.some(D=>{var T;return((T=M[D])!=null?T:"").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 m={},b={},C={},x={task:m,note:b,idea:C},w=M=>{var L;return e&&((L=M[e])!=null?L:"").split(",").map(D=>D.trim()).filter(Boolean)[0]||"\u2014"};p.forEach(M=>{var D;let k=x[Fc(s,M,n)],L=w(M);((D=k[L])!=null?D:k[L]=[]).push(M)});let S=t.createDiv({cls:"csv-tasks"}),y=Ic(),v=i?Vc(s,i):"done";bi(S,"Tasks",m,(M,k)=>{k.sort((L,D)=>{var N,O,j,z,K,$;let T=Je(s,L,i),A=Je(s,D,i);if(T!==A)return T?1:-1;if(r){let X=ar((N=L[r])!=null?N:"")-ar((O=D[r])!=null?O:"");if(X)return X}if(o){let X=lr((j=L[o])!=null?j:"")-lr((z=D[o])!=null?z:"");if(X)return X;let Z=((K=L[o])!=null?K:"").localeCompare(($=D[o])!=null?$:"");if(Z)return Z}return s.getTitle(L).localeCompare(s.getTitle(D))}),k.forEach(L=>{var z;let D=Je(s,L,i),T=M.createEl("tr"),A=T.createEl("td",{cls:"csv-tasks-check-cell"});if(i){let K=A.createEl("span",{cls:`csv-tasks-check ${D?"is-done":""}`,text:D?"\u2713":""});K.setAttr("title",D?"Mark not done":"Mark done"),K.addEventListener("click",$=>{$.stopPropagation(),L[i]=D?"":v,s.scheduleSave(),s.renderView(!0)})}cr(s,T,L,a,D);let N=T.createEl("td",{cls:"csv-tasks-due"}),O=o?((z=L[o])!=null?z:"").slice(0,10):"";N.setText(O||"\u2014"),O&&!D&&O{var X;K.stopPropagation();let $=Array.from(new Set([...s.getColumnValues(r),"high","medium","low"]));It(j,(X=L[r])!=null?X:"",$,Z=>{L[r]=Z,s.scheduleSave(),s.renderView(!0)},s.contentEl)})),T.addEventListener("contextmenu",K=>s.openRowContextMenu(L,K))})},["","Name","Due","Priority"]);let _=(M,k)=>{k.sort((L,D)=>{let T=Je(s,L,i),A=Je(s,D,i);return T!==A?T?1:-1:s.getTitle(L).localeCompare(s.getTitle(D))}),k.forEach(L=>{let D=Je(s,L,i),T=M.createEl("tr"),A=T.createEl("td",{cls:"csv-tasks-check-cell"});if(i){let j=A.createEl("span",{cls:`csv-tasks-check ${D?"is-done":""}`,text:D?"\u2713":""});j.setAttr("title",D?"Mark not done":"Mark done"),j.addEventListener("click",z=>{z.stopPropagation(),L[i]=D?"":v,s.scheduleSave(),s.renderView(!0)})}let N=n&&L[n]||"",O=T.createEl("td",{cls:"csv-tasks-type-cell"});N&&O.createSpan({cls:"csv-tasks-type-pill",text:N}),cr(s,T,L,a,D),T.addEventListener("contextmenu",j=>s.openRowContextMenu(L,j))})};if(bi(S,"Notes",b,_,["","Type","Name"]),bi(S,"Ideas",C,_,["","Type","Name"]),Object.keys(m).length===0&&Object.keys(b).length===0&&Object.keys(C).length===0){let M=S.createDiv({cls:"csv-empty-state"});M.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")&&M.createEl("button",{cls:"csv-clear-filters-btn",text:"Clear filters"}).addEventListener("click",()=>{s.taskProjectFilter="all",s.taskTypeFilter="all",s.searchQuery="",s.renderView()})}}function bi(s,t,e,n,i){if(Object.keys(e).length===0)return;s.createDiv({cls:"csv-tasks-section-header",text:t});let o=s.createDiv({cls:"csv-tasks-section"});Object.keys(e).sort().forEach(r=>{let a=e[r],l=o.createEl("details",{cls:"csv-tasks-group"});l.open=!0;let c=l.createEl("summary",{cls:"csv-tasks-group-header"});c.innerHTML=`\u25B6 ${r} ${a.length}`;let d=l.createEl("table",{cls:"csv-tasks-table"}),u=d.createEl("thead").createEl("tr");i.forEach(g=>u.createEl("th",{text:g}));let f=d.createEl("tbody");n(f,a)})}function cr(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 bn(s){let t=[];return s.isTravelFile()&&t.push({id:"travel",label:"Travel"}),s.hasDateColumn()&&t.push({id:"dashboard",label:"Dashboard"}),ts(s)&&t.push({id:"tasks",label:"Tasks"}),Ht(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"}),un(s)&&t.push({id:"stats",label:"Stats"}),t}function fr(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=bn(s),r=i.createEl("select",{cls:"csv-mode-select",attr:{"aria-label":"View mode"}});if(o.forEach(({id:m,label:b})=>{let C=r.createEl("option",{text:b,value:m});s.mode===m&&(C.selected=!0)}),r.addEventListener("change",()=>{s.mode=r.value,s.renderView()}),s.mode!=="dashboard"){let m=n.createEl("button",{cls:"csv-cfg-btn csv-search-toggle",text:"\u{1F50D}",title:"Search"}),b=n.createDiv({cls:"csv-search-wrap"}),C=b.createDiv({cls:"csv-search-input-wrap"}),x=C.createEl("input",{cls:"csv-search-input",type:"text",placeholder:"Search...",value:s.searchQuery,attr:{inputmode:"search",enterkeyhint:"search",autocomplete:"off"}}),w=C.createEl("button",{cls:"csv-search-clear",text:"\xD7",title:"Clear search"});w.toggleClass("is-hidden",!s.searchQuery),b.createEl("button",{cls:"csv-search-done",text:"Done",title:"Dismiss keyboard"}).addEventListener("click",v=>{if(v.preventDefault(),!x.value){e.removeClass("csv-toolbar--search-expanded"),m.removeClass("has-query"),s.searchQuery="",s.renderView(!0);return}x.blur()});let y=null;x.addEventListener("input",v=>{s.searchQuery=v.target.value,w.toggleClass("is-hidden",!s.searchQuery),m.toggleClass("has-query",!!s.searchQuery),y!==null&&window.clearTimeout(y),y=window.setTimeout(()=>{y=null,s.renderView(!0)},120)}),x.addEventListener("keydown",v=>{v.key==="Enter"&&(v.preventDefault(),x.blur())}),w.addEventListener("click",()=>{s.searchQuery="",x.value="",w.addClass("is-hidden"),m.removeClass("has-query"),x.focus({preventScroll:!0}),s.renderView(!0)}),s.searchQuery&&m.addClass("has-query"),m.addEventListener("click",()=>{e.addClass("csv-toolbar--search-expanded"),x.focus({preventScroll:!0})})}if(s.mode==="table"&&s.hasDateColumn()){let m=(p=s.fileCfg.sortNewestFirst)!=null?p:!0;n.createEl("button",{cls:`csv-cfg-btn ${m?"active":""}`,text:m?"\u2193 Newest":"\u2191 Oldest",title:"Toggle sort order"}).addEventListener("click",()=>{var x;let C=s.fileCfg;C.sortNewestFirst=!((x=C.sortNewestFirst)==null||x),s.saveFileCfg(C),s.tableSortCol=null,s.renderViewPreservingScroll()})}let a=()=>{var b,C;let m={category:s.resolveCol(Ke),status:s.resolveCol(Ye),notes:s.resolveCol(Ge),image:s.resolveCol(Ue),anki:mi(s)};new rn(s.app,s.headers,(C=(b=s.file)==null?void 0:b.path)!=null?C:"",s.fileCfg,s.autoDetectBooleanColumns(),s.autoDetectCategoricalColumns(),m,bn(s),x=>{s.saveFileCfg(x),x.defaultMode&&(s.mode=x.defaultMode),s.renderView()},()=>s.headers,()=>s.fileCfg,x=>s.addColumn(x),x=>s.removeColumn(x)).open()},l=()=>ir(s),c=()=>s.backupToArchive(),d=()=>rr(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",m=>{let b=new vn.Menu;b.addItem(C=>C.setTitle("Config").setIcon("settings").onClick(a)),b.addItem(C=>C.setTitle("Mobile dashboard").setIcon("smartphone").onClick(l)),b.addItem(C=>C.setTitle("Backup").setIcon("save").onClick(c)),b.addItem(C=>C.setTitle("Sync to Anki").setIcon("layers").onClick(d)),b.addSeparator(),b.addItem(C=>C.setTitle("Built 2026-07-06 08:46").setIcon("info").setDisabled(!0)),b.showAtMouseEvent(m)}),n.createEl("button",{cls:"csv-cfg-btn csv-cfg-btn-secondary csv-info-btn",text:"\u24D8",title:"Built 2026-07-06 08:46 \u2014 click to confirm"}).addEventListener("click",()=>new vn.Notice("datadeck \u2014 built 2026-07-06 08:46",4e3))}function Nc(s){return s&&typeof s=="object"&&"basename"in s?s:null}var Bc=["Author","author","By","by","Source","source","Speaker","speaker","Artist","artist","Director","director"];async function gr(s,t,e,n){var C,x,w;let i=t.split(` +`).map(S=>S.trim()).filter(Boolean),o=S=>{var y,v;return(v=(y=i.find(_=>_.startsWith(S+":")))==null?void 0:y.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=(x=(C=a==null?void 0:a.parent)==null?void 0:C.path)!=null?x:"",c=qe(r,l),d=Nc(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=qt(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=(w=h.find(S=>S.toLowerCase()===f.toLowerCase()))!=null?w:h[0],p=Bc.map(S=>h.find(y=>y===S)).find(Boolean),m=e.createDiv({cls:"csv-random-card"}),b=()=>{var k;m.empty();let S=u.filter(L=>{var D;return((D=L[g])!=null?D:"").trim()}),y=S.length?S:u,v=y[Math.floor(Math.random()*y.length)];m.createDiv({cls:"csv-random-text",text:v[g]||"\u2014"});let _=p?((k=v[p])!=null?k:"").trim():"";_&&m.createDiv({cls:"csv-random-sub",text:`\u2014 ${_}`});let E=m.createDiv({cls:"csv-random-foot"});E.createSpan({cls:"csv-random-src",text:d.basename}),E.createEl("button",{cls:"csv-random-btn",text:"\u21BB",title:"Another one"}).addEventListener("click",b)};b()}var Eo=null;async function rg(){if(Eo)return Eo;let s=await Promise.resolve().then(()=>(Wl(),$l));return s.Chart.register(s.LineController,s.LineElement,s.PointElement,s.LinearScale,s.CategoryScale,s.Filler,s.Tooltip),Eo=s,s}async function jl(s,t){var X,Z,R;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((F,P)=>{var H,I;return((H=F[e])!=null?H:"").localeCompare((I=P[e])!=null?I:"")});s.selectedDate||(s.selectedDate=o);let a=r.find(F=>F[e]===s.selectedDate),l=s.selectedDate===o;t.addClass("csv-dashboard");let c=[...new Set([...r.map(F=>F[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 F=c.indexOf(s.selectedDate);if(F>0)s.selectedDate=c[F-1],s.renderView();else if(F===-1&&c.length>0){let P=c.filter(H=>H0&&(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(F=>{let P=f.createEl("option",{text:F,value:F});F===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 F=c.indexOf(s.selectedDate);if(F>=0&&FH>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 F=t.createDiv({cls:"csv-dash-add-section"});F.createEl("p",{text:`No entry for ${s.selectedDate}`}),F.createEl("button",{cls:"csv-dash-add-btn",text:`+ Add entry for ${s.selectedDate}`}).addEventListener("click",()=>{let H={};s.headers.forEach(I=>H[I]=""),H[e]=s.selectedDate,s.rows.push(H),s.scheduleSave(),s.renderView()})}if(a){let F=t.createDiv({cls:"csv-dash-habits"});F.createEl("h3",{text:s.selectedDate===o?"Today":s.selectedDate,cls:"csv-dash-section-title"});let P=F.createDiv({cls:"csv-dash-habits-grid"});n.forEach(I=>{let V=s.isTruthy(a[I]),q=P.createDiv({cls:`csv-dash-habit ${V?"checked":""}`}),B=q.createEl("button",{cls:"csv-dash-habit-check",text:V?"\u25CF":"\u25CB"});q.createSpan({cls:"csv-dash-habit-label",text:I}),B.addEventListener("click",()=>{a[I]=V?"0":"1",s.scheduleSave(),s.renderViewPreservingScroll()})});let H=n.filter(I=>s.isTruthy(a[I])).length;if(F.createDiv({cls:"csv-dash-habits-count",text:`${H} of ${n.length} complete`}),i&&((X=a[i])!=null&&X.trim())){let I=F.createDiv({cls:"csv-dash-notes-preview"});I.createEl("strong",{text:"Notes: "}),I.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 b=p.createDiv({cls:"csv-dash-chart-wrap"}).createEl("canvas",{cls:"csv-dash-chart"}),C=r.map(F=>{var H;return((H=F[e])!=null?H:"").slice(5)}),x=r.map(F=>n.filter(P=>s.isTruthy(F[P])).length);s.chartInstance&&(s.chartInstance.destroy(),s.chartInstance=null);let{Chart:w}=await rg();if(!b.isConnected)return;s.chartInstance=new w(b,{type:"line",data:{labels:C,datasets:[{label:"Habits done",data:x,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 y=r.length,v=r.reduce((F,P)=>F+n.filter(H=>s.isTruthy(P[H])).length,0),_=y>0?(v/y).toFixed(1):"0",E=r.filter(F=>n.every(P=>s.isTruthy(F[P]))).length,M=0,k=0,L=null;for(let F of r){let P=n.filter(V=>s.isTruthy(F[V])).length,H=s.parseDate((Z=F[e])!=null?Z:""),I=!0;L&&H&&Math.round((H.getTime()-L.getTime())/864e5)!==1&&(I=!1),P>=1&&(I||L===null)?(k++,k>M&&(M=k)):P>=1?(k=1,k>M&&(M=k)):k=0,L=H}let D=0,T=new Date;T.setHours(0,0,0,0);let A=T;for(let F=r.length-1;F>=0;F--){let P=s.parseDate((R=r[F][e])!=null?R:"");if(!P)break;let H=Math.round((A.getTime()-P.getTime())/(1e3*60*60*24));if(D===0&&H>1||D>0&&H!==1)break;if(n.filter(V=>s.isTruthy(r[F][V])).length>=1)D++,A=P;else break}let N=S.createDiv({cls:"csv-dash-stats-bar"});N.innerHTML=`${y} days logged \xB7 ${_} avg/day \xB7 ${E} perfect days \xB7 current streak ${D}d \xB7 best streak ${M}d`;let j=t.createDiv({cls:"csv-dash-cards-section"}).createDiv({cls:"csv-dash-cards-grid"}),z=new Date().getFullYear(),K={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(F=>{let P=r.filter(B=>s.isTruthy(B[F])),H=P.length>0?P[P.length-1][e]:null,I=new Set;P.forEach(B=>{var U;let Y=s.parseDate((U=B[e])!=null?U:"");Y&&I.add(Y.getFullYear())});let V=r.filter(B=>{var U;let Y=s.parseDate((U=B[e])!=null?U:"");return Y&&Y.getFullYear()===z}),q=V.filter(B=>s.isTruthy(B[F])).length;return{habit:F,doneCount:P.length,doneThisYear:q,totalThisYear:V.length,lastDone:H,years:Array.from(I).sort()}}).sort((F,P)=>!F.lastDone&&!P.lastDone?0:F.lastDone?P.lastDone?P.lastDone.localeCompare(F.lastDone):-1:1).forEach(({habit:F,doneCount:P,doneThisYear:H,totalThisYear:I,lastDone:V,years:q})=>{var st;let B=j.createDiv({cls:"csv-dash-habit-card"}),Y=(st=K[F.toLowerCase()])!=null?st:"\u25CB",U=B.createDiv({cls:"csv-dash-habit-card-header"});if(U.createSpan({cls:"csv-dash-habit-icon",text:Y}),U.createSpan({cls:"csv-dash-habit-card-name",text:Mt(F)}),q.length>0&&B.createDiv({cls:"csv-dash-habit-years"}).setText(q.join(" \xB7 ")),B.createDiv({cls:"csv-dash-habit-card-thisyear",text:`${H} of ${I} complete this year`}),B.createDiv({cls:"csv-dash-habit-card-alltime",text:`${P} of ${y} all time`}),V){let lt=s.parseDate(V),Ot=lt?lt.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}):V;B.createDiv({cls:"csv-dash-habit-card-last",text:`Last logged: ${Ot}`})}else B.createDiv({cls:"csv-dash-habit-card-last",text:"Never logged"});let G=y>0?P/y*100:0,J=B.createDiv({cls:"csv-dash-habit-progress"}).createDiv({cls:"csv-dash-habit-progress-bar"});J.style.width=`${G}%`,B.addEventListener("click",()=>{s.selectedHabit=s.selectedHabit===F?null:F,s.renderViewPreservingScroll()}),s.selectedHabit===F&&B.addClass("selected")}),s.selectedHabit&&n.includes(s.selectedHabit)&&ag(s,t,r,e,s.selectedHabit)}function ag(s,t,e,n,i){var M,k,L;let o=t.createDiv({cls:"csv-dash-timeline-section"}),r=o.createDiv({cls:"csv-dash-timeline-header"});r.createEl("h3",{text:`${Mt(i)} Timeline`,cls:"csv-dash-section-title"});let a=r.createEl("select",{cls:"csv-dash-year-select"}),l=new Set;e.forEach(D=>{var A;let T=s.parseDate((A=D[n])!=null?A:"");T&&l.add(T.getFullYear())}),l.add(new Date().getFullYear()),Array.from(l).sort().reverse().forEach(D=>{let T=a.createEl("option",{text:String(D),value:String(D)});D===s.timelineYear&&(T.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(D=>{var T;d.set((T=D[n])!=null?T:"",s.isTruthy(D[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(D=>u.createSpan({cls:"csv-dash-timeline-month-label",text:D}));let g=h.createDiv({cls:"csv-dash-timeline-calendar"}),p=g.createDiv({cls:"csv-dash-timeline-day-labels"});for(let D=1;D<=31;D++)p.createDiv({cls:"csv-dash-timeline-day-label",text:D%5===0||D===1?String(D):""});for(let D=0;D<12;D++){let T=g.createDiv({cls:"csv-dash-timeline-month-col"}),A=new Date(s.timelineYear,D+1,0).getDate();for(let N=1;N<=31;N++){if(N>A){T.createDiv({cls:"csv-dash-timeline-cell empty"});continue}let O=`${s.timelineYear}-${String(D+1).padStart(2,"0")}-${String(N).padStart(2,"0")}`,j=(M=d.get(O))!=null?M:!1,z=d.has(O),K=new Date(s.timelineYear,D,N)>new Date,$=T.createDiv({cls:`csv-dash-timeline-cell ${K?"future":""} ${j?"done":""} ${z&&!j?"missed":""} ${!z&&!K?"no-entry":""}`});$.title=`${O}: ${K?"Future":j?"\u2713 Done":z?"\u2717 Missed":"No entry"}`}}let m=e.filter(D=>{var A;let T=s.parseDate((A=D[n])!=null?A:"");return T&&T.getFullYear()===s.timelineYear}),b=m.filter(D=>s.isTruthy(D[i])).length,C=m.length,x=0,w=0,S=0,y=null;for(let D of e){let T=s.isTruthy(D[i]),A=s.parseDate((k=D[n])!=null?k:""),N=!0;y&&A&&Math.round((A.getTime()-y.getTime())/864e5)!==1&&(N=!1),T&&(N||y===null)?(S++,S>w&&(w=S)):T?S=1:S=0,y=A}let v=new Date;v.setHours(0,0,0,0);let _=v;for(let D=e.length-1;D>=0;D--){let T=s.parseDate((L=e[D][n])!=null?L:"");if(!T)break;let A=Math.round((_.getTime()-T.getTime())/(1e3*60*60*24));if(x===0&&A>1||x>0&&A!==1)break;if(s.isTruthy(e[D][i]))x++,_=T;else break}let E=o.createDiv({cls:"csv-dash-timeline-stats"});E.innerHTML=`${b} of ${C} in ${s.timelineYear} \xB7 current streak ${x}d \xB7 best streak ${w}d`}function Ul(s,t){var C,x,w;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=(C=s.titleKey())!=null?C: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 ${(x=s.isHighlighted)!=null&&x.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&&((w=n[o])!=null&&w.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 y;return!u.has(S)&&((y=n[S])!=null?y:"").trim()});if(f.length){let S=c.createDiv({cls:"csv-focus-meta"});f.forEach(y=>{let v=S.createDiv({cls:"csv-kanban-chip"});if(v.createSpan({cls:"csv-chip-label",text:y+": "}),s.isSelectCol(y)){let _=v.createSpan({cls:"csv-chip-value csv-chip-select",text:n[y]});_.addEventListener("click",E=>{E.stopPropagation(),It(_,n[y],s.getColumnValues(y),M=>{n[y]=M,_.setText(M||"\u2014"),s.scheduleSave()},s.contentEl,{multi:Et(y)})})}else v.createSpan({cls:"csv-chip-value",text:n[y]})})}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)"}),m=g.createEl("button",{cls:"csv-focus-nav-btn csv-focus-nav-rand",text:"\u{1F500}",title:"Random entry"}),b=g.createEl("button",{cls:"csv-focus-nav-btn",text:"\u203A",title:"Next (\u2192)"});p.addEventListener("click",()=>l(s.focusIndex-1)),b.addEventListener("click",()=>l(s.focusIndex+1)),m.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 Pt=require("obsidian"),Yl=en(Es());var lg=[{id:"table",label:"Table"},{id:"library",label:"Cards"},{id:"kanban-genre",label:"Kanban"}];function Kl(s){return s&&typeof s=="object"&&"basename"in s?s:null}function cg(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 ko=class extends Pt.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=qt(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=Kl(e))})))}onunload(){this.saveTimer&&window.clearTimeout(this.saveTimer)}async reload(){let e=Kl(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=qt(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=Yl.default.unparse(this.rows,{columns:this.headers});this.lastWritten=e,await this.app.vault.modify(this.file,e)}catch(e){new Pt.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?this.fileCfg.notesColumn:this.resolveCol(Ge)}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||he(e)||Et(e)?!1:this.fileCfg.categoricalColumns?this.fileCfg.categoricalColumns.includes(e):this.isSelectCol(e)||Gt(this.getColumnValues(e).length)}getStatusCol(){var e;return this.fileCfg.statusColumn?(e=this.headers.find(n=>n.toLowerCase()===this.fileCfg.statusColumn.toLowerCase()))!=null?e:null:this.resolveCol(Ye)}getCategoryCol(){var e;return this.fileCfg.categoryColumn?(e=this.headers.find(n=>n.toLowerCase()===this.fileCfg.categoryColumn.toLowerCase()))!=null?e:null:this.resolveCol(Ke)}titleKey(){var e;return(e=this.resolveCol(["Title","title","Name","name"]))!=null?e: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?(e=this.headers.find(n=>n.toLowerCase()===this.fileCfg.imageColumn.toLowerCase()))!=null?e:null:this.resolveCol(Ue)}getBooleanColumns(){var e;return(e=this.fileCfg.habitColumns)!=null&&e.length?this.fileCfg.habitColumns.filter(n=>this.headers.includes(n)):this.headers.filter(n=>{if(n===this.getDateCol()||this.isNotesCol(n))return!1;let i=this.rows.map(o=>{var r;return((r=o[n])!=null?r:"").toLowerCase().trim()});return on(i)})}getDateCol(){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(o=>{var r;return n.test((r=o[e])!=null?r:"")})?e:null}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=ks(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,Pt.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 Pt.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 Pt.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 Pt.Notice(`Restored \u201C${i}\u201D`,2500))})}openRowContextMenu(e,n){let i=new Pt.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 Qe(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)).open()}openAddModal(){new Xe(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 Pt.Notice(`Added: ${this.getTitle(e)}`)},{},e=>this.getBooleanColumns().includes(e),this.isCategoricalCol.bind(this)).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(),It(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;Pt.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")&&!Ht(this.asView)&&(this.mode="table"),this.mode==="library"?gn(this.asView,i):this.mode==="kanban-genre"?fn(this.asView,i):hn(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=!!Ht(this.asView),r=i.createDiv({cls:"csv-mode-group"});lg.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 Gl(s,t,e,n){n("csv-view",(i,o,r)=>{var h,u,f;let a=cg(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?qe(a.file,l):a.file,d=new ko(o,s,t,e,{...a,file:c});r.addChild(d)})}var tn,Cs=class extends rt.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 rt.Component,this.renderComponent.load()}getViewType(){return sn}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=qt(r);this.headers=a.headers,this.rows=a.rows}catch(r){console.error("CardView load error",r),this.headers=[],this.rows=[],new rt.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&&!Ht(this)||i&&!this.hasDateColumn()||this.mode==="travel"&&!this.isTravelFile()||this.mode==="stats"&&!un(this)||this.mode==="tasks"&&!ts(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=ql.default.unparse(this.rows,{columns:this.headers});await this.app.vault.modify(this.file,e)}catch(e){console.error("CardView save error",e),new rt.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?this.fileCfg.notesColumn:this.resolveCol(Ge)}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||he(e)||Et(e)?!1:this.fileCfg.categoricalColumns?this.fileCfg.categoricalColumns.includes(e):this.isSelectCol(e)||Gt(this.getColumnValues(e).length)}autoDetectCategoricalColumns(){var n;let e=(n=this.titleKey())!=null?n:this.headers[0];return this.headers.filter(i=>i===e||he(i)||Et(i)||this.isNotesCol(i)?!1:this.isSelectCol(i)||Gt(this.getColumnValues(i).length))}getStatusCol(){var e;return this.fileCfg.statusColumn?(e=this.headers.find(n=>n.toLowerCase()===this.fileCfg.statusColumn.toLowerCase()))!=null?e:null:this.resolveCol(Ye)}getCategoryCol(){var e;return this.fileCfg.categoryColumn?(e=this.headers.find(n=>n.toLowerCase()===this.fileCfg.categoryColumn.toLowerCase()))!=null?e:null:this.resolveCol(Ke)}titleKey(){var e;return(e=this.resolveCol(["Title","title","Name","name"]))!=null?e: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?(e=this.headers.find(n=>n.toLowerCase()===this.fileCfg.imageColumn.toLowerCase()))!=null?e:null:this.resolveCol(Ue)}notesFilePath(e){var a,l,c;let n=ks(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,rt.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 rt.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 rt.Notice(`Restored \u201C${i}\u201D`,2500)})}openRowContextMenu(e,n){let i=new rt.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=ts(this)?vi(this):null,c=l?((o=e[l])!=null?o:"").split(",").map(g=>Ro(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,rt.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 rt.Notice(`Created: ${i.name}`)}await this.app.workspace.getLeaf("tab").openFile(i)}openNoteExpander(e,n){var i,o;new Qe(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),this.isCategoricalCol.bind(this)).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 m,b;let g=(b=(m=f.querySelector(".csv-kanban-col-title"))==null?void 0:m.textContent)!=null?b:"",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(m=>{var w,S;let b=(S=(w=m.querySelector(".csv-kanban-col-title"))==null?void 0:w.textContent)!=null?S:"",C=m.querySelector(".csv-kanban-col-body"),x=r.cols.get(b);C&&x!=null&&(C.scrollTop=x)})};a(),requestAnimationFrame(()=>{a(),requestAnimationFrame(a)}),setTimeout(a,50)}openAddModal(){let e={};if(ts(this)){let n=pn(this);n&&(e[n]=["Task","Note","Idea"]);let i=mn(this);i&&(e[i]=["Low","Medium","High"])}new Xe(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 rt.Notice(`Added: ${this.getTitle(n)}`)},e,n=>this.getBooleanColumns().includes(n),this.isCategoricalCol.bind(this)).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(),It(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:Et(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 rt.Component,this.renderComponent.load(),fr(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"?Go(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"?jl(this,i):this.mode==="library"?gn(this,i):this.mode==="kanban-genre"?fn(this,i):this.mode==="stats"?tr(this,i):this.mode==="focus"?Ul(this,i):this.mode==="tasks"?ur(this,i):hn(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=new Date().toISOString().slice(0,10),o=`${n}/${this.file.basename}_${i}.${this.file.extension}`;if(await this.app.vault.adapter.exists(o)){new rt.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 rt.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(tn!==void 0)return tn;let e=(0,rt.normalizePath)(`${this.app.vault.configDir}/plugins/datadeck/world-map.svg`);try{tn=await this.app.vault.adapter.read(e)}catch(n){tn=null}return tn}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 Po(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(){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(a=>{var l;return o.test((l=a[e])!=null?l:"")})?e:null}getBooleanColumns(){return this.fileCfg.habitColumns&&this.fileCfg.habitColumns.length>0?this.fileCfg.habitColumns.filter(e=>this.headers.includes(e)):this.autoDetectBooleanColumns()}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 on(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){let n=(e!=null?e:"").toLowerCase().trim();return n==="1"||n==="true"||n==="yes"}renderMarkdownInto(e,n){var i,o;rt.MarkdownRenderer.render(this.app,n,e,(o=(i=this.file)==null?void 0:i.path)!=null?o:"",this.renderComponent)}cycleMode(){let e=bn(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)}},dg=[{id:"tasks",command:"Create tasks file",defaultName:"Tasks",headers:["Title","Type","Project","Status","Priority","Due","Notes"],mode:"tasks"},{id:"travel",command:"Create travel file",defaultName:"Travel",headers:["Country","date_entered","date_left","source","Notes"],mode:"travel"},{id:"habits",command:"Create habit tracker file",defaultName:"Habits",headers:["Date","Exercise","Meditate","Read","Notes"],mode:"dashboard"}],ni=class extends rt.Plugin{constructor(){super(...arguments);this.settings=li}async onload(){await this.loadSettings(),this.registerView(sn,e=>new Cs(e,this.settings,()=>this.saveSettings())),this.registerExtensions(["csv"],sn),this.addSettingTab(new dn(this.app,this)),this.registerMarkdownCodeBlockProcessor("csv-add",async(e,n,i)=>{await Xo(this.app,e.trim(),n,i,this.settings.fileConfigs)}),this.registerMarkdownCodeBlockProcessor("csv-random",async(e,n,i)=>{await gr(this.app,e.trim(),n,i)}),Gl(this.app,this.settings,()=>this.saveSettings(),(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(Cs);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(Cs);return n?(e||n.cycleMode(),!0):!1}});for(let e of dg)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 rt.TFile&&e.extension==="csv"&&this.settings.fileConfigs[n]&&(No(this.settings.fileConfigs,n,e.path),await this.saveSettings())})),this.registerEvent(this.app.vault.on("delete",async e=>{e instanceof rt.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 rt.TFile){let l=this.app.workspace.activeLeaf;l&&await l.openFile(a,{state:{mode:"preview"}})}})})}async createTemplateFile(e){new an(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=ks(n),a=(0,rt.normalizePath)(`${o}${r}.csv`);for(let c=2;this.app.vault.getAbstractFileByPath(a);c++)a=(0,rt.normalizePath)(`${o}${r} ${c}.csv`);let l=await this.app.vault.create(a,e.headers.join(",")+` +`);this.settings.fileConfigs[l.path]={...this.settings.fileConfigs[l.path],defaultMode:e.mode},await this.saveSettings(),await this.app.workspace.getLeaf("tab").openFile(l),new rt.Notice(`Created: ${l.name}`)}).open()}async loadSettings(){var e;this.settings=Object.assign({},li,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: diff --git a/main.ts b/main.ts index 752773d..fc3f78b 100644 --- a/main.ts +++ b/main.ts @@ -19,7 +19,7 @@ import type { Chart as ChartType } from "chart.js"; // Import from src modules import { CSVRow, ViewMode, FileConfig, CardViewSettings, DEFAULT_SETTINGS, CARD_VIEW_TYPE } from "./src/types"; -import { sanitizeFilename, tagify, titleCase, formatRatingForDisplay, showSelectPicker, parseCSV, migrateFileConfigKey, sortRowsByColumn, isMultiValueColName, IMAGE_COL_ALIASES, looksBoolean, looksCategorical } from "./src/utils"; +import { sanitizeFilename, tagify, titleCase, formatRatingForDisplay, showSelectPicker, parseCSV, migrateFileConfigKey, sortRowsByColumn, isMultiValueColName, IMAGE_COL_ALIASES, CATEGORY_COL_ALIASES, STATUS_COL_ALIASES, NOTES_COL_ALIASES, looksBoolean, looksCategorical } from "./src/utils"; import { isDateCol } from "./src/field-types"; import { AddEntryModal, NoteExpanderModal, FileConfigModal, SearchModal, PromptModal } from "./src/modals"; import { renderTravel } from "./src/travel-view"; @@ -233,15 +233,7 @@ export class CardView extends FileView { // 1. Per-file override if (this.fileCfg.notesColumn) return this.fileCfg.notesColumn; // 2. Fallback chain - return this.resolveCol([ - "Notes","notes","Note","note", - "Summary","summary", - "Review","review", - "Quote","quote","Quotes","quotes", - "Comment","comment","Comments","comments", - "Description","description", - "Annotation","annotation", - ]); + return this.resolveCol(NOTES_COL_ALIASES); } isNotesCol(h: string): boolean { @@ -283,31 +275,14 @@ export class CardView extends FileView { if (this.fileCfg.statusColumn) { return this.headers.find(h => h.toLowerCase() === this.fileCfg.statusColumn!.toLowerCase()) ?? null; } - return this.resolveCol([ - "Status","status", - "State","state", - "Progress","progress", - "Stage","stage", - "Read","read", - "Watched","watched","Seen","seen", - "Done","done","Completed","completed", - ]); + return this.resolveCol(STATUS_COL_ALIASES); } getCategoryCol(): string | null { if (this.fileCfg.categoryColumn) { return this.headers.find(h => h.toLowerCase() === this.fileCfg.categoryColumn!.toLowerCase()) ?? null; } - return this.resolveCol([ - "Category","category", - "Categories","categories", - "Genre","genre","Genres","genres", - "Type","type","Types","types", - "Tag","tag","Tags","tags", - "Topic","topic","Topics","topics", - "Subject","subject", - "Section","section", - ]); + return this.resolveCol(CATEGORY_COL_ALIASES); } titleKey(): string | undefined { diff --git a/src/inline-view.ts b/src/inline-view.ts index 7dbd434..d8624c2 100644 --- a/src/inline-view.ts +++ b/src/inline-view.ts @@ -32,7 +32,7 @@ import { import Papa from "papaparse"; import type { CardView } from "../main"; import { CSVRow, ViewMode, FileConfig, CardViewSettings } from "./types"; -import { parseCSV, resolvePath, sanitizeFilename, showSelectPicker, IMAGE_COL_ALIASES, looksBoolean, looksCategorical, isMultiValueColName } from "./utils"; +import { parseCSV, resolvePath, sanitizeFilename, showSelectPicker, IMAGE_COL_ALIASES, CATEGORY_COL_ALIASES, STATUS_COL_ALIASES, NOTES_COL_ALIASES, looksBoolean, looksCategorical, isMultiValueColName } from "./utils"; import { isDateCol } from "./field-types"; import { AddEntryModal, NoteExpanderModal } from "./modals"; import { renderTable } from "./view/table"; @@ -257,11 +257,7 @@ export class InlineCardHost extends MarkdownRenderChild { } getNotesCol(): string | null { if (this.fileCfg.notesColumn) return this.fileCfg.notesColumn; - return this.resolveCol([ - "Notes", "notes", "Note", "note", "Summary", "summary", "Review", "review", - "Quote", "quote", "Quotes", "quotes", "Comment", "comment", "Comments", "comments", - "Description", "description", "Annotation", "annotation", - ]); + return this.resolveCol(NOTES_COL_ALIASES); } isNotesCol(h: string): boolean { const notesCol = this.getNotesCol(); @@ -284,20 +280,13 @@ export class InlineCardHost extends MarkdownRenderChild { if (this.fileCfg.statusColumn) { return this.headers.find(h => h.toLowerCase() === this.fileCfg.statusColumn!.toLowerCase()) ?? null; } - return this.resolveCol([ - "Status", "status", "State", "state", "Progress", "progress", "Stage", "stage", - "Read", "read", "Watched", "watched", "Seen", "seen", "Done", "done", "Completed", "completed", - ]); + return this.resolveCol(STATUS_COL_ALIASES); } getCategoryCol(): string | null { if (this.fileCfg.categoryColumn) { return this.headers.find(h => h.toLowerCase() === this.fileCfg.categoryColumn!.toLowerCase()) ?? null; } - return this.resolveCol([ - "Category", "category", "Categories", "categories", "Genre", "genre", "Genres", "genres", - "Type", "type", "Types", "types", "Tag", "tag", "Tags", "tags", - "Topic", "topic", "Topics", "topics", "Subject", "subject", "Section", "section", - ]); + return this.resolveCol(CATEGORY_COL_ALIASES); } titleKey(): string | undefined { return this.resolveCol(["Title", "title", "Name", "name"]) ?? undefined; diff --git a/src/modals.ts b/src/modals.ts index 1890d68..ca9aec0 100644 --- a/src/modals.ts +++ b/src/modals.ts @@ -648,12 +648,26 @@ export class SearchModal extends Modal { // ─── File Config Modal ──────────────────────────────────────────────────────── // Per-file column mapping — which column is the kanban group, notes, status +// What each of the 5 exclusive per-column roles would resolve to with no +// explicit fileCfg override — i.e. what getCategoryCol/getStatusCol/ +// getNotesCol/getImageCol/ankiFrontCol already do by name/position at +// render time. Lets the Config modal show "(auto)" on whichever column is +// already fulfilling a role, instead of looking like no column does. +export interface AutoDetectedRoles { + category: string | null; + status: string | null; + notes: string | null; + image: string | null; + anki: string | null; +} + export class FileConfigModal extends Modal { headers: string[]; filePath: string; current: FileConfig; autoDetectedHabits: string[]; autoDetectedCategorical: string[]; + autoDetectedRoles: AutoDetectedRoles; availableModes: { id: ViewMode; label: string }[]; onSave: (cfg: FileConfig) => void; // Column-structure ops (add/remove the CSV column itself, not its role). @@ -666,7 +680,7 @@ export class FileConfigModal extends Modal { constructor( app: App, headers: string[], filePath: string, current: FileConfig, autoDetectedHabits: string[], - autoDetectedCategorical: string[], + autoDetectedCategorical: string[], autoDetectedRoles: AutoDetectedRoles, availableModes: { id: ViewMode; label: string }[], onSave: (cfg: FileConfig) => void, getHeaders: () => string[], getFileCfg: () => FileConfig, onAddColumn: (name: string) => string | null, onRemoveColumn: (header: string) => void, @@ -681,6 +695,7 @@ export class FileConfigModal extends Modal { }; this.autoDetectedHabits = autoDetectedHabits; this.autoDetectedCategorical = autoDetectedCategorical; + this.autoDetectedRoles = autoDetectedRoles; this.availableModes = availableModes; this.onSave = onSave; this.getHeaders = getHeaders; @@ -730,7 +745,7 @@ export class FileConfigModal extends Modal { colSection.createEl("label", { text: "Columns", cls: "csv-modal-label" }); colSection.createEl("p", { cls: "csv-modal-hint", - text: "Role is exclusive — picking it for one column clears it from any other. The three toggles can be combined freely.", + text: "Role is exclusive — picking it for one column clears it from any other. \"auto (by name)\" means it's already playing that role because of its column name, with nothing saved here yet. The three toggles can be combined freely.", }); type Role = "category" | "status" | "notes" | "image" | "anki" | ""; @@ -742,13 +757,28 @@ export class FileConfigModal extends Modal { { value: "image", label: "Image (card / kanban thumbnail)" }, { value: "anki", label: "Anki card front" }, ]; - const roleOf = (h: string): Role => { - if (this.current.categoryColumn === h) return "category"; - if (this.current.statusColumn === h) return "status"; - if (this.current.notesColumn === h) return "notes"; - if (this.current.imageColumn === h) return "image"; - if (this.current.ankiFrontCol === h) return "anki"; - return ""; + // Explicit fileCfg fields always win outright over name-based detection — + // mirrors getCategoryCol/getStatusCol/getNotesCol/getImageCol/ankiFrontCol, + // which never blend an auto guess in once a role has an override, even if + // that override points at a column that no longer looks like a great fit. + // So `auto: true` only ever appears when the role's field is fully unset. + const roleOf = (h: string): { role: Role; auto: boolean } => { + if (this.current.categoryColumn !== undefined) { if (this.current.categoryColumn === h) return { role: "category", auto: false }; } + else if (this.autoDetectedRoles.category === h) return { role: "category", auto: true }; + + if (this.current.statusColumn !== undefined) { if (this.current.statusColumn === h) return { role: "status", auto: false }; } + else if (this.autoDetectedRoles.status === h) return { role: "status", auto: true }; + + if (this.current.notesColumn !== undefined) { if (this.current.notesColumn === h) return { role: "notes", auto: false }; } + else if (this.autoDetectedRoles.notes === h) return { role: "notes", auto: true }; + + if (this.current.imageColumn !== undefined) { if (this.current.imageColumn === h) return { role: "image", auto: false }; } + else if (this.autoDetectedRoles.image === h) return { role: "image", auto: true }; + + if (this.current.ankiFrontCol !== undefined) { if (this.current.ankiFrontCol === h) return { role: "anki", auto: false }; } + else if (this.autoDetectedRoles.anki === h) return { role: "anki", auto: true }; + + return { role: "", auto: false }; }; // Only clears the role(s) *this* column currently holds — reassigning a // role to a different column evicts its previous holder for free, since @@ -813,11 +843,20 @@ export class FileConfigModal extends Modal { const controls = row.createDiv({ cls: "csv-modal-colcfg-controls" }); const roleSel = controls.createEl("select", { cls: "csv-modal-select csv-modal-colcfg-role" }); - const currentRole = roleOf(h); + // roleOf already reflects an auto-detected role in `role` (not just + // `auto`) — e.g. a column literally named "Status" shows "Status" + // selected here with no config saved at all, matching what + // getStatusCol() already resolves by name at render time. The badge + // is just there to distinguish "picked by name" from "picked by you". + const { role: currentRole, auto: isAutoRole } = roleOf(h); ROLE_OPTIONS.forEach(o => { const opt = roleSel.createEl("option", { text: o.label, value: o.value }); if (o.value === currentRole) opt.selected = true; }); + if (isAutoRole) { + roleSel.addClass("auto-detected"); + controls.createSpan({ cls: "csv-modal-colcfg-auto-badge", text: "auto (by name)" }); + } roleSel.addEventListener("change", () => { setRole(h, roleSel.value as Role); renderRows(); diff --git a/src/utils.ts b/src/utils.ts index 2bb4910..8197f3e 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -6,6 +6,39 @@ import { CSVRow } from "./types"; // thumbnails. Matched case-insensitively against headers (see getImageCol). export const IMAGE_COL_ALIASES = ["Image", "image", "Cover", "cover", "Poster", "poster", "Thumbnail", "thumbnail", "Thumb", "thumb", "Photo", "photo", "Picture", "picture", "Img", "img"]; +// Column-name aliases for the three other name-detected roles (see +// getCategoryCol/getStatusCol/getNotesCol). Shared between main.ts, +// inline-view.ts, and the ⚙ Config modal's auto-detected role indicator, so +// the modal's "this is auto-detected" badge always agrees with what the +// views actually resolve at render time. +export const CATEGORY_COL_ALIASES = [ + "Category","category","Categories","categories", + "Genre","genre","Genres","genres", + "Type","type","Types","types", + "Tag","tag","Tags","tags", + "Topic","topic","Topics","topics", + "Subject","subject", + "Section","section", +]; +export const STATUS_COL_ALIASES = [ + "Status","status", + "State","state", + "Progress","progress", + "Stage","stage", + "Read","read", + "Watched","watched","Seen","seen", + "Done","done","Completed","completed", +]; +export const NOTES_COL_ALIASES = [ + "Notes","notes","Note","note", + "Summary","summary", + "Review","review", + "Quote","quote","Quotes","quotes", + "Comment","comment","Comments","comments", + "Description","description", + "Annotation","annotation", +]; + /** * Resolve a cell value into an src, or null if it isn't resolvable. * Accepts: http(s)/data URLs (used as-is), `![[wikilink]]` / `[[wikilink]]`, diff --git a/src/view/anki.ts b/src/view/anki.ts index 1c0d3ac..73ea87d 100644 --- a/src/view/anki.ts +++ b/src/view/anki.ts @@ -38,20 +38,29 @@ async function ankiInvoke(action: string, params: Record): Prom } /** - * Resolve the column used as the Anki card front. Honours the per-file - * `ankiFrontCol`; otherwise falls back to the title/primary field, then to a - * content-bearing column (so a quotes file fronts on Quote, not its first - * column Author), then to the first column. + * What ankiFrontCol would resolve to with no per-file override — the + * title/primary field, then a content-bearing column (so a quotes file + * fronts on Quote, not its first column Author), then the first column. + * Exposed separately so the ⚙ Config modal can show which column is + * *already* the front by name/position, without an explicit `ankiFrontCol`. */ -export function ankiFrontCol(view: CardView): string | null { - const configured = view.fileCfg.ankiFrontCol; - if (configured && view.headers.includes(configured)) return configured; +export function autoAnkiFrontCol(view: CardView): string | null { return view.titleKey() ?? view.resolveCol(["Quote", "Headline", "Phrase", "Term", "Word", "Question", "Front", "Name", "Title"]) ?? view.headers[0] ?? null; } +/** + * Resolve the column used as the Anki card front. Honours the per-file + * `ankiFrontCol`; otherwise falls back to autoAnkiFrontCol. + */ +export function ankiFrontCol(view: CardView): string | null { + const configured = view.fileCfg.ankiFrontCol; + if (configured && view.headers.includes(configured)) return configured; + return autoAnkiFrontCol(view); +} + // HTML-escape a cell so quotes/dictionary entries with <, >, & render as text // in Anki rather than as broken markup. function esc(s: string): string { diff --git a/src/view/toolbar.ts b/src/view/toolbar.ts index 12a78c6..ed8664b 100644 --- a/src/view/toolbar.ts +++ b/src/view/toolbar.ts @@ -6,12 +6,13 @@ import { Menu, Notice } from "obsidian"; import type { CardView } from "../../main"; import { ViewMode } from "../types"; -import { FileConfigModal } from "../modals"; +import { FileConfigModal, AutoDetectedRoles } from "../modals"; import { generateMobileFiles } from "./mobile"; -import { syncToAnki } from "./anki"; +import { syncToAnki, autoAnkiFrontCol } from "./anki"; import { hasStatsColumns } from "./stats"; import { hasTaskColumns } from "./tasks"; import { effectiveGroupCol } from "./kanban"; +import { CATEGORY_COL_ALIASES, STATUS_COL_ALIASES, NOTES_COL_ALIASES, IMAGE_COL_ALIASES } from "../utils"; declare const __BUILD_TIME__: string; @@ -197,9 +198,20 @@ export function renderToolbar(view: CardView, root: HTMLElement): void { // Handlers are defined once and reused by both surfaces so there's a // single place to maintain behaviour. const openColumns = () => { + // What each exclusive role would resolve to with no fileCfg override, + // purely by column name/position — same lists/logic getCategoryCol etc. + // already use at render time — so the modal's "auto (by name)" badge + // always agrees with what's actually driving the view right now. + const autoDetectedRoles: AutoDetectedRoles = { + category: view.resolveCol(CATEGORY_COL_ALIASES), + status: view.resolveCol(STATUS_COL_ALIASES), + notes: view.resolveCol(NOTES_COL_ALIASES), + image: view.resolveCol(IMAGE_COL_ALIASES), + anki: autoAnkiFrontCol(view), + }; new FileConfigModal( view.app, view.headers, view.file?.path ?? "", view.fileCfg, view.autoDetectBooleanColumns(), - view.autoDetectCategoricalColumns(), availableModes(view), + view.autoDetectCategoricalColumns(), autoDetectedRoles, availableModes(view), (cfg) => { view.saveFileCfg(cfg); if (cfg.defaultMode) view.mode = cfg.defaultMode; diff --git a/styles.css b/styles.css index fdcf69b..d6cecc8 100644 --- a/styles.css +++ b/styles.css @@ -2032,6 +2032,18 @@ td .csv-select-chip { width: auto; } +.csv-modal-colcfg-role.auto-detected { + border-color: rgba(52, 168, 83, 0.4); + background: rgba(52, 168, 83, 0.08); +} + +.csv-modal-colcfg-auto-badge { + font-size: 11px; + font-style: italic; + color: var(--color-green, #34a853); + flex: 0 0 auto; +} + .csv-modal-colcfg-toggle { padding: 4px 8px; flex: 0 0 auto; diff --git a/test-view-smoke.mjs b/test-view-smoke.mjs index c47eca1..24cf8bb 100644 --- a/test-view-smoke.mjs +++ b/test-view-smoke.mjs @@ -828,9 +828,10 @@ await test("note-expander: an explicit isCategoricalCol override wins over auto- const { FileConfigModal } = await load("./src/modals.ts"); function openFileConfigModal(headers, current, autoDetectedCategorical, overrides = {}) { + const autoDetectedRoles = { category: null, status: null, notes: null, image: null, anki: null, ...overrides.autoDetectedRoles }; const modal = new FileConfigModal( new StubApp(), headers, "test.csv", current, overrides.autoDetectedHabits ?? [], - autoDetectedCategorical, overrides.availableModes ?? [], + autoDetectedCategorical, autoDetectedRoles, overrides.availableModes ?? [], overrides.onSave ?? (() => {}), overrides.getHeaders ?? (() => headers), overrides.getFileCfg ?? (() => current), @@ -921,6 +922,33 @@ await test("FileConfigModal: role/toggle edits don't touch disk — only add/rem assert(getFileCfgCalls === 0, "editing roles/toggles is a pending, in-memory draft until Save — it must not refetch from disk"); }); +await test("FileConfigModal: a name-detected column shows its role with an auto badge, no config needed", async () => { + // Mirrors a real project dash file: nothing in fileCfg, but "Status" already + // resolves by name at render time (getStatusCol) — the row should show + // that, not "— no special role —", which is what prompted this feature. + const headers = ["Title", "Type", "Project", "Status"]; + const modal = openFileConfigModal(headers, {}, [], { autoDetectedRoles: { status: "Status" } }); + const sel = roleSelectFor(modal, "Status"); + assert(sel.value === "status", "Status column shows the Status role even with nothing saved"); + assert(sel.hasClass("auto-detected"), "auto-detected role select gets the auto-detected styling"); + assert(colConfigRowFor(modal, "Status").textContent.includes("auto (by name)"), "row surfaces the auto badge text"); + + const typeSel = roleSelectFor(modal, "Type"); + assert(typeSel.value === "", "a column with no matching alias and no config shows no role"); + assert(!typeSel.hasClass("auto-detected"), "no badge when there's nothing auto-detected for this column"); +}); + +await test("FileConfigModal: an explicit override elsewhere suppresses the auto badge, matching runtime resolution", async () => { + // getStatusCol() never blends a name-based guess back in once statusColumn + // is set — even to a different column — so neither the auto pick nor the + // explicit pick should show "auto" once an override exists for the role. + const headers = ["Title", "Status", "Progress"]; + const modal = openFileConfigModal(headers, { statusColumn: "Progress" }, [], { autoDetectedRoles: { status: "Status" } }); + assert(roleSelectFor(modal, "Progress").value === "status", "the explicit override holds the Status role"); + assert(!roleSelectFor(modal, "Progress").hasClass("auto-detected"), "explicit picks aren't flagged as auto"); + assert(roleSelectFor(modal, "Status").value === "", "the name-matched column no longer shows the role once something else is configured"); +}); + // ── Multi-select picker ────────────────────────────────────────────────────── const { showSelectPicker, isMultiValueColName } = await load("./src/utils.ts");