kimai-plugin-heatmap/Resources/public/heatmap.js
2026-04-08 17:14:48 +02:00

1 line
38 KiB
JavaScript

"use strict";var KimaiHeatmap=(()=>{var Wt=Object.defineProperty;var tn=Object.getOwnPropertyDescriptor;var en=Object.getOwnPropertyNames;var rn=Object.prototype.hasOwnProperty;var nn=(t,e)=>{for(var r in e)Wt(t,r,{get:e[r],enumerable:!0})},on=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of en(e))!rn.call(t,o)&&o!==r&&Wt(t,o,{get:()=>e[o],enumerable:!(n=tn(e,o))||n.enumerable});return t};var an=t=>on(Wt({},"__esModule",{value:!0}),t);var za={};nn(za,{calculateStats:()=>$r,calculateStreak:()=>zr,init:()=>Ra,renderHeatmap:()=>Vr});var St="http://www.w3.org/1999/xhtml",Pt={svg:"http://www.w3.org/2000/svg",xhtml:St,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function Tt(t){var e=t+="",r=e.indexOf(":");return r>=0&&(e=t.slice(0,r))!=="xmlns"&&(t=t.slice(r+1)),Pt.hasOwnProperty(e)?{space:Pt[e],local:t}:t}function un(t){return function(){var e=this.ownerDocument,r=this.namespaceURI;return r===St&&e.documentElement.namespaceURI===St?e.createElement(t):e.createElementNS(r,t)}}function sn(t){return function(){return this.ownerDocument.createElementNS(t.space,t.local)}}function Dt(t){var e=Tt(t);return(e.local?sn:un)(e)}function ln(){}function Ct(t){return t==null?ln:function(){return this.querySelector(t)}}function ce(t){typeof t!="function"&&(t=Ct(t));for(var e=this._groups,r=e.length,n=new Array(r),o=0;o<r;++o)for(var a=e[o],i=a.length,u=n[o]=new Array(i),l,s,m=0;m<i;++m)(l=a[m])&&(s=t.call(l,l.__data__,m,a))&&("__data__"in l&&(s.__data__=l.__data__),u[m]=s);return new C(n,this._parents)}function It(t){return t==null?[]:Array.isArray(t)?t:Array.from(t)}function fn(){return[]}function me(t){return t==null?fn:function(){return this.querySelectorAll(t)}}function cn(t){return function(){return It(t.apply(this,arguments))}}function pe(t){typeof t=="function"?t=cn(t):t=me(t);for(var e=this._groups,r=e.length,n=[],o=[],a=0;a<r;++a)for(var i=e[a],u=i.length,l,s=0;s<u;++s)(l=i[s])&&(n.push(t.call(l,l.__data__,s,i)),o.push(l));return new C(n,o)}function he(t){return function(){return this.matches(t)}}function bt(t){return function(e){return e.matches(t)}}var mn=Array.prototype.find;function pn(t){return function(){return mn.call(this.children,t)}}function hn(){return this.firstElementChild}function de(t){return this.select(t==null?hn:pn(typeof t=="function"?t:bt(t)))}var dn=Array.prototype.filter;function yn(){return Array.from(this.children)}function gn(t){return function(){return dn.call(this.children,t)}}function ye(t){return this.selectAll(t==null?yn:gn(typeof t=="function"?t:bt(t)))}function ge(t){typeof t!="function"&&(t=he(t));for(var e=this._groups,r=e.length,n=new Array(r),o=0;o<r;++o)for(var a=e[o],i=a.length,u=n[o]=[],l,s=0;s<i;++s)(l=a[s])&&t.call(l,l.__data__,s,a)&&u.push(l);return new C(n,this._parents)}function Ut(t){return new Array(t.length)}function xe(){return new C(this._enter||this._groups.map(Ut),this._parents)}function mt(t,e){this.ownerDocument=t.ownerDocument,this.namespaceURI=t.namespaceURI,this._next=null,this._parent=t,this.__data__=e}mt.prototype={constructor:mt,appendChild:function(t){return this._parent.insertBefore(t,this._next)},insertBefore:function(t,e){return this._parent.insertBefore(t,e)},querySelector:function(t){return this._parent.querySelector(t)},querySelectorAll:function(t){return this._parent.querySelectorAll(t)}};function ve(t){return function(){return t}}function xn(t,e,r,n,o,a){for(var i=0,u,l=e.length,s=a.length;i<s;++i)(u=e[i])?(u.__data__=a[i],n[i]=u):r[i]=new mt(t,a[i]);for(;i<l;++i)(u=e[i])&&(o[i]=u)}function vn(t,e,r,n,o,a,i){var u,l,s=new Map,m=e.length,p=a.length,w=new Array(m),h;for(u=0;u<m;++u)(l=e[u])&&(w[u]=h=i.call(l,l.__data__,u,e)+"",s.has(h)?o[u]=l:s.set(h,l));for(u=0;u<p;++u)h=i.call(t,a[u],u,a)+"",(l=s.get(h))?(n[u]=l,l.__data__=a[u],s.delete(h)):r[u]=new mt(t,a[u]);for(u=0;u<m;++u)(l=e[u])&&s.get(w[u])===l&&(o[u]=l)}function Mn(t){return t.__data__}function Me(t,e){if(!arguments.length)return Array.from(this,Mn);var r=e?vn:xn,n=this._parents,o=this._groups;typeof t!="function"&&(t=ve(t));for(var a=o.length,i=new Array(a),u=new Array(a),l=new Array(a),s=0;s<a;++s){var m=n[s],p=o[s],w=p.length,h=wn(t.call(m,m&&m.__data__,s,n)),x=h.length,S=u[s]=new Array(x),U=i[s]=new Array(x),L=l[s]=new Array(w);r(m,p,S,U,L,h,e);for(var b=0,N=0,k,E;b<x;++b)if(k=S[b]){for(b>=N&&(N=b+1);!(E=U[N])&&++N<x;);k._next=E||null}}return i=new C(i,n),i._enter=u,i._exit=l,i}function wn(t){return typeof t=="object"&&"length"in t?t:Array.from(t)}function we(){return new C(this._exit||this._groups.map(Ut),this._parents)}function _e(t,e,r){var n=this.enter(),o=this,a=this.exit();return typeof t=="function"?(n=t(n),n&&(n=n.selection())):n=n.append(t+""),e!=null&&(o=e(o),o&&(o=o.selection())),r==null?a.remove():r(a),n&&o?n.merge(o).order():o}function Se(t){for(var e=t.selection?t.selection():t,r=this._groups,n=e._groups,o=r.length,a=n.length,i=Math.min(o,a),u=new Array(o),l=0;l<i;++l)for(var s=r[l],m=n[l],p=s.length,w=u[l]=new Array(p),h,x=0;x<p;++x)(h=s[x]||m[x])&&(w[x]=h);for(;l<o;++l)u[l]=r[l];return new C(u,this._parents)}function Te(){for(var t=this._groups,e=-1,r=t.length;++e<r;)for(var n=t[e],o=n.length-1,a=n[o],i;--o>=0;)(i=n[o])&&(a&&i.compareDocumentPosition(a)^4&&a.parentNode.insertBefore(i,a),a=i);return this}function De(t){t||(t=_n);function e(p,w){return p&&w?t(p.__data__,w.__data__):!p-!w}for(var r=this._groups,n=r.length,o=new Array(n),a=0;a<n;++a){for(var i=r[a],u=i.length,l=o[a]=new Array(u),s,m=0;m<u;++m)(s=i[m])&&(l[m]=s);l.sort(e)}return new C(o,this._parents).order()}function _n(t,e){return t<e?-1:t>e?1:t>=e?0:NaN}function Ce(){var t=arguments[0];return arguments[0]=this,t.apply(null,arguments),this}function be(){return Array.from(this)}function Ue(){for(var t=this._groups,e=0,r=t.length;e<r;++e)for(var n=t[e],o=0,a=n.length;o<a;++o){var i=n[o];if(i)return i}return null}function ke(){let t=0;for(let e of this)++t;return t}function Ae(){return!this.node()}function Fe(t){for(var e=this._groups,r=0,n=e.length;r<n;++r)for(var o=e[r],a=0,i=o.length,u;a<i;++a)(u=o[a])&&t.call(u,u.__data__,a,o);return this}function Sn(t){return function(){this.removeAttribute(t)}}function Tn(t){return function(){this.removeAttributeNS(t.space,t.local)}}function Dn(t,e){return function(){this.setAttribute(t,e)}}function Cn(t,e){return function(){this.setAttributeNS(t.space,t.local,e)}}function bn(t,e){return function(){var r=e.apply(this,arguments);r==null?this.removeAttribute(t):this.setAttribute(t,r)}}function Un(t,e){return function(){var r=e.apply(this,arguments);r==null?this.removeAttributeNS(t.space,t.local):this.setAttributeNS(t.space,t.local,r)}}function Le(t,e){var r=Tt(t);if(arguments.length<2){var n=this.node();return r.local?n.getAttributeNS(r.space,r.local):n.getAttribute(r)}return this.each((e==null?r.local?Tn:Sn:typeof e=="function"?r.local?Un:bn:r.local?Cn:Dn)(r,e))}function kt(t){return t.ownerDocument&&t.ownerDocument.defaultView||t.document&&t||t.defaultView}function kn(t){return function(){this.style.removeProperty(t)}}function An(t,e,r){return function(){this.style.setProperty(t,e,r)}}function Fn(t,e,r){return function(){var n=e.apply(this,arguments);n==null?this.style.removeProperty(t):this.style.setProperty(t,n,r)}}function Ne(t,e,r){return arguments.length>1?this.each((e==null?kn:typeof e=="function"?Fn:An)(t,e,r??"")):Ln(this.node(),t)}function Ln(t,e){return t.style.getPropertyValue(e)||kt(t).getComputedStyle(t,null).getPropertyValue(e)}function Nn(t){return function(){delete this[t]}}function Hn(t,e){return function(){this[t]=e}}function Yn(t,e){return function(){var r=e.apply(this,arguments);r==null?delete this[t]:this[t]=r}}function He(t,e){return arguments.length>1?this.each((e==null?Nn:typeof e=="function"?Yn:Hn)(t,e)):this.node()[t]}function Ye(t){return t.trim().split(/^|\s+/)}function Ot(t){return t.classList||new Ee(t)}function Ee(t){this._node=t,this._names=Ye(t.getAttribute("class")||"")}Ee.prototype={add:function(t){var e=this._names.indexOf(t);e<0&&(this._names.push(t),this._node.setAttribute("class",this._names.join(" ")))},remove:function(t){var e=this._names.indexOf(t);e>=0&&(this._names.splice(e,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(t){return this._names.indexOf(t)>=0}};function We(t,e){for(var r=Ot(t),n=-1,o=e.length;++n<o;)r.add(e[n])}function Pe(t,e){for(var r=Ot(t),n=-1,o=e.length;++n<o;)r.remove(e[n])}function En(t){return function(){We(this,t)}}function Wn(t){return function(){Pe(this,t)}}function Pn(t,e){return function(){(e.apply(this,arguments)?We:Pe)(this,t)}}function Ie(t,e){var r=Ye(t+"");if(arguments.length<2){for(var n=Ot(this.node()),o=-1,a=r.length;++o<a;)if(!n.contains(r[o]))return!1;return!0}return this.each((typeof e=="function"?Pn:e?En:Wn)(r,e))}function In(){this.textContent=""}function On(t){return function(){this.textContent=t}}function qn(t){return function(){var e=t.apply(this,arguments);this.textContent=e??""}}function Oe(t){return arguments.length?this.each(t==null?In:(typeof t=="function"?qn:On)(t)):this.node().textContent}function Rn(){this.innerHTML=""}function zn(t){return function(){this.innerHTML=t}}function $n(t){return function(){var e=t.apply(this,arguments);this.innerHTML=e??""}}function qe(t){return arguments.length?this.each(t==null?Rn:(typeof t=="function"?$n:zn)(t)):this.node().innerHTML}function Vn(){this.nextSibling&&this.parentNode.appendChild(this)}function Re(){return this.each(Vn)}function Bn(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function ze(){return this.each(Bn)}function $e(t){var e=typeof t=="function"?t:Dt(t);return this.select(function(){return this.appendChild(e.apply(this,arguments))})}function Zn(){return null}function Ve(t,e){var r=typeof t=="function"?t:Dt(t),n=e==null?Zn:typeof e=="function"?e:Ct(e);return this.select(function(){return this.insertBefore(r.apply(this,arguments),n.apply(this,arguments)||null)})}function Qn(){var t=this.parentNode;t&&t.removeChild(this)}function Be(){return this.each(Qn)}function Xn(){var t=this.cloneNode(!1),e=this.parentNode;return e?e.insertBefore(t,this.nextSibling):t}function Gn(){var t=this.cloneNode(!0),e=this.parentNode;return e?e.insertBefore(t,this.nextSibling):t}function Ze(t){return this.select(t?Gn:Xn)}function Qe(t){return arguments.length?this.property("__data__",t):this.node().__data__}function Jn(t){return function(e){t.call(this,e,this.__data__)}}function Kn(t){return t.trim().split(/^|\s+/).map(function(e){var r="",n=e.indexOf(".");return n>=0&&(r=e.slice(n+1),e=e.slice(0,n)),{type:e,name:r}})}function jn(t){return function(){var e=this.__on;if(e){for(var r=0,n=-1,o=e.length,a;r<o;++r)a=e[r],(!t.type||a.type===t.type)&&a.name===t.name?this.removeEventListener(a.type,a.listener,a.options):e[++n]=a;++n?e.length=n:delete this.__on}}}function to(t,e,r){return function(){var n=this.__on,o,a=Jn(e);if(n){for(var i=0,u=n.length;i<u;++i)if((o=n[i]).type===t.type&&o.name===t.name){this.removeEventListener(o.type,o.listener,o.options),this.addEventListener(o.type,o.listener=a,o.options=r),o.value=e;return}}this.addEventListener(t.type,a,r),o={type:t.type,name:t.name,value:e,listener:a,options:r},n?n.push(o):this.__on=[o]}}function Xe(t,e,r){var n=Kn(t+""),o,a=n.length,i;if(arguments.length<2){var u=this.node().__on;if(u){for(var l=0,s=u.length,m;l<s;++l)for(o=0,m=u[l];o<a;++o)if((i=n[o]).type===m.type&&i.name===m.name)return m.value}return}for(u=e?to:jn,o=0;o<a;++o)this.each(u(n[o],e,r));return this}function Ge(t,e,r){var n=kt(t),o=n.CustomEvent;typeof o=="function"?o=new o(e,r):(o=n.document.createEvent("Event"),r?(o.initEvent(e,r.bubbles,r.cancelable),o.detail=r.detail):o.initEvent(e,!1,!1)),t.dispatchEvent(o)}function eo(t,e){return function(){return Ge(this,t,e)}}function ro(t,e){return function(){return Ge(this,t,e.apply(this,arguments))}}function Je(t,e){return this.each((typeof e=="function"?ro:eo)(t,e))}function*Ke(){for(var t=this._groups,e=0,r=t.length;e<r;++e)for(var n=t[e],o=0,a=n.length,i;o<a;++o)(i=n[o])&&(yield i)}var qt=[null];function C(t,e){this._groups=t,this._parents=e}function no(){return new C([[document.documentElement]],qt)}function oo(){return this}C.prototype=no.prototype={constructor:C,select:ce,selectAll:pe,selectChild:de,selectChildren:ye,filter:ge,data:Me,enter:xe,exit:we,join:_e,merge:Se,selection:oo,order:Te,sort:De,call:Ce,nodes:be,node:Ue,size:ke,empty:Ae,each:Fe,attr:Le,style:Ne,property:He,classed:Ie,text:Oe,html:qe,raise:Re,lower:ze,append:$e,insert:Ve,remove:Be,clone:Ze,datum:Qe,on:Xe,dispatch:Je,[Symbol.iterator]:Ke};function Rt(t){return typeof t=="string"?new C([[document.querySelector(t)]],[document.documentElement]):new C([[t]],qt)}function ot(t,e){return t==null||e==null?NaN:t<e?-1:t>e?1:t>=e?0:NaN}function zt(t,e){return t==null||e==null?NaN:e<t?-1:e>t?1:e>=t?0:NaN}function At(t){let e,r,n;t.length!==2?(e=ot,r=(u,l)=>ot(t(u),l),n=(u,l)=>t(u)-l):(e=t===ot||t===zt?t:ao,r=t,n=t);function o(u,l,s=0,m=u.length){if(s<m){if(e(l,l)!==0)return m;do{let p=s+m>>>1;r(u[p],l)<0?s=p+1:m=p}while(s<m)}return s}function a(u,l,s=0,m=u.length){if(s<m){if(e(l,l)!==0)return m;do{let p=s+m>>>1;r(u[p],l)<=0?s=p+1:m=p}while(s<m)}return s}function i(u,l,s=0,m=u.length){let p=o(u,l,s,m-1);return p>s&&n(u[p-1],l)>-n(u[p],l)?p-1:p}return{left:o,center:i,right:a}}function ao(){return 0}function $t(t){return t===null?NaN:+t}var je=At(ot),tr=je.right,io=je.left,uo=At($t).center,Vt=tr;var so=Math.sqrt(50),lo=Math.sqrt(10),fo=Math.sqrt(2);function Ft(t,e,r){let n=(e-t)/Math.max(0,r),o=Math.floor(Math.log10(n)),a=n/Math.pow(10,o),i=a>=so?10:a>=lo?5:a>=fo?2:1,u,l,s;return o<0?(s=Math.pow(10,-o)/i,u=Math.round(t*s),l=Math.round(e*s),u/s<t&&++u,l/s>e&&--l,s=-s):(s=Math.pow(10,o)*i,u=Math.round(t/s),l=Math.round(e/s),u*s<t&&++u,l*s>e&&--l),l<u&&.5<=r&&r<2?Ft(t,e,r*2):[u,l,s]}function Lt(t,e,r){if(e=+e,t=+t,r=+r,!(r>0))return[];if(t===e)return[t];let n=e<t,[o,a,i]=n?Ft(e,t,r):Ft(t,e,r);if(!(a>=o))return[];let u=a-o+1,l=new Array(u);if(n)if(i<0)for(let s=0;s<u;++s)l[s]=(a-s)/-i;else for(let s=0;s<u;++s)l[s]=(a-s)*i;else if(i<0)for(let s=0;s<u;++s)l[s]=(o+s)/-i;else for(let s=0;s<u;++s)l[s]=(o+s)*i;return l}function pt(t,e,r){return e=+e,t=+t,r=+r,Ft(t,e,r)[2]}function Bt(t,e,r){e=+e,t=+t,r=+r;let n=e<t,o=n?pt(e,t,r):pt(t,e,r);return(n?-1:1)*(o<0?1/-o:o)}function ht(t,e){let r;if(e===void 0)for(let n of t)n!=null&&(r<n||r===void 0&&n>=n)&&(r=n);else{let n=-1;for(let o of t)(o=e(o,++n,t))!=null&&(r<o||r===void 0&&o>=o)&&(r=o)}return r}function er(t,e){switch(arguments.length){case 0:break;case 1:this.range(t);break;default:this.range(e).domain(t);break}return this}function rr(t){return Math.abs(t=Math.round(t))>=1e21?t.toLocaleString("en").replace(/,/g,""):t.toString(10)}function at(t,e){if(!isFinite(t)||t===0)return null;var r=(t=e?t.toExponential(e-1):t.toExponential()).indexOf("e"),n=t.slice(0,r);return[n.length>1?n[0]+n.slice(2):n,+t.slice(r+1)]}function q(t){return t=at(Math.abs(t)),t?t[1]:NaN}function nr(t,e){return function(r,n){for(var o=r.length,a=[],i=0,u=t[0],l=0;o>0&&u>0&&(l+u+1>n&&(u=Math.max(1,n-l)),a.push(r.substring(o-=u,o+u)),!((l+=u+1)>n));)u=t[i=(i+1)%t.length];return a.reverse().join(e)}}function or(t){return function(e){return e.replace(/[0-9]/g,function(r){return t[+r]})}}var co=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function G(t){if(!(e=co.exec(t)))throw new Error("invalid format: "+t);var e;return new Nt({fill:e[1],align:e[2],sign:e[3],symbol:e[4],zero:e[5],width:e[6],comma:e[7],precision:e[8]&&e[8].slice(1),trim:e[9],type:e[10]})}G.prototype=Nt.prototype;function Nt(t){this.fill=t.fill===void 0?" ":t.fill+"",this.align=t.align===void 0?">":t.align+"",this.sign=t.sign===void 0?"-":t.sign+"",this.symbol=t.symbol===void 0?"":t.symbol+"",this.zero=!!t.zero,this.width=t.width===void 0?void 0:+t.width,this.comma=!!t.comma,this.precision=t.precision===void 0?void 0:+t.precision,this.trim=!!t.trim,this.type=t.type===void 0?"":t.type+""}Nt.prototype.toString=function(){return this.fill+this.align+this.sign+this.symbol+(this.zero?"0":"")+(this.width===void 0?"":Math.max(1,this.width|0))+(this.comma?",":"")+(this.precision===void 0?"":"."+Math.max(0,this.precision|0))+(this.trim?"~":"")+this.type};function ar(t){t:for(var e=t.length,r=1,n=-1,o;r<e;++r)switch(t[r]){case".":n=o=r;break;case"0":n===0&&(n=r),o=r;break;default:if(!+t[r])break t;n>0&&(n=0);break}return n>0?t.slice(0,n)+t.slice(o+1):t}var dt;function ir(t,e){var r=at(t,e);if(!r)return dt=void 0,t.toPrecision(e);var n=r[0],o=r[1],a=o-(dt=Math.max(-8,Math.min(8,Math.floor(o/3)))*3)+1,i=n.length;return a===i?n:a>i?n+new Array(a-i+1).join("0"):a>0?n.slice(0,a)+"."+n.slice(a):"0."+new Array(1-a).join("0")+at(t,Math.max(0,e+a-1))[0]}function Zt(t,e){var r=at(t,e);if(!r)return t+"";var n=r[0],o=r[1];return o<0?"0."+new Array(-o).join("0")+n:n.length>o+1?n.slice(0,o+1)+"."+n.slice(o+1):n+new Array(o-n.length+2).join("0")}var Qt={"%":(t,e)=>(t*100).toFixed(e),b:t=>Math.round(t).toString(2),c:t=>t+"",d:rr,e:(t,e)=>t.toExponential(e),f:(t,e)=>t.toFixed(e),g:(t,e)=>t.toPrecision(e),o:t=>Math.round(t).toString(8),p:(t,e)=>Zt(t*100,e),r:Zt,s:ir,X:t=>Math.round(t).toString(16).toUpperCase(),x:t=>Math.round(t).toString(16)};function Xt(t){return t}var ur=Array.prototype.map,sr=["y","z","a","f","p","n","\xB5","m","","k","M","G","T","P","E","Z","Y"];function lr(t){var e=t.grouping===void 0||t.thousands===void 0?Xt:nr(ur.call(t.grouping,Number),t.thousands+""),r=t.currency===void 0?"":t.currency[0]+"",n=t.currency===void 0?"":t.currency[1]+"",o=t.decimal===void 0?".":t.decimal+"",a=t.numerals===void 0?Xt:or(ur.call(t.numerals,String)),i=t.percent===void 0?"%":t.percent+"",u=t.minus===void 0?"\u2212":t.minus+"",l=t.nan===void 0?"NaN":t.nan+"";function s(p,w){p=G(p);var h=p.fill,x=p.align,S=p.sign,U=p.symbol,L=p.zero,b=p.width,N=p.comma,k=p.precision,E=p.trim,_=p.type;_==="n"?(N=!0,_="g"):Qt[_]||(k===void 0&&(k=12),E=!0,_="g"),(L||h==="0"&&x==="=")&&(L=!0,h="0",x="=");var tt=(w&&w.prefix!==void 0?w.prefix:"")+(U==="$"?r:U==="#"&&/[boxX]/.test(_)?"0"+_.toLowerCase():""),Z=(U==="$"?n:/[%p]/.test(_)?i:"")+(w&&w.suffix!==void 0?w.suffix:""),R=Qt[_],et=/[defgprs%]/.test(_);k=k===void 0?6:/[gprs]/.test(_)?Math.max(1,Math.min(21,k)):Math.max(0,Math.min(20,k));function rt(y){var I=tt,D=Z,d,A,Q;if(_==="c")D=R(y)+D,y="";else{y=+y;var X=y<0||1/y<0;if(y=isNaN(y)?l:R(Math.abs(y),k),E&&(y=ar(y)),X&&+y==0&&S!=="+"&&(X=!1),I=(X?S==="("?S:u:S==="-"||S==="("?"":S)+I,D=(_==="s"&&!isNaN(y)&&dt!==void 0?sr[8+dt/3]:"")+D+(X&&S==="("?")":""),et){for(d=-1,A=y.length;++d<A;)if(Q=y.charCodeAt(d),48>Q||Q>57){D=(Q===46?o+y.slice(d+1):y.slice(d))+D,y=y.slice(0,d);break}}}N&&!L&&(y=e(y,1/0));var z=I.length+y.length+D.length,O=z<b?new Array(b-z+1).join(h):"";switch(N&&L&&(y=e(O+y,O.length?b-D.length:1/0),O=""),x){case"<":y=I+y+D+O;break;case"=":y=I+O+y+D;break;case"^":y=O.slice(0,z=O.length>>1)+I+y+D+O.slice(z);break;default:y=O+I+y+D;break}return a(y)}return rt.toString=function(){return p+""},rt}function m(p,w){var h=Math.max(-8,Math.min(8,Math.floor(q(w)/3)))*3,x=Math.pow(10,-h),S=s((p=G(p),p.type="f",p),{suffix:sr[8+h/3]});return function(U){return S(x*U)}}return{format:s,formatPrefix:m}}var Ht,Yt,Et;Gt({thousands:",",grouping:[3],currency:["$",""]});function Gt(t){return Ht=lr(t),Yt=Ht.format,Et=Ht.formatPrefix,Ht}function Jt(t){return Math.max(0,-q(Math.abs(t)))}function Kt(t,e){return Math.max(0,Math.max(-8,Math.min(8,Math.floor(q(e)/3)))*3-q(Math.abs(t)))}function jt(t,e){return t=Math.abs(t),e=Math.abs(e)-t,Math.max(0,q(e)-q(t))+1}function te(t,e,r,n){var o=Bt(t,e,r),a;switch(n=G(n??",f"),n.type){case"s":{var i=Math.max(Math.abs(t),Math.abs(e));return n.precision==null&&!isNaN(a=Kt(o,i))&&(n.precision=a),Et(n,i)}case"":case"e":case"g":case"p":case"r":{n.precision==null&&!isNaN(a=jt(o,Math.max(Math.abs(t),Math.abs(e))))&&(n.precision=a-(n.type==="e"));break}case"f":case"%":{n.precision==null&&!isNaN(a=Jt(o))&&(n.precision=a-(n.type==="%")*2);break}}return Yt(n)}function fr(t){var e=t.domain;return t.ticks=function(r){var n=e();return Lt(n[0],n[n.length-1],r??10)},t.tickFormat=function(r,n){var o=e();return te(o[0],o[o.length-1],r??10,n)},t.nice=function(r){r==null&&(r=10);var n=e(),o=0,a=n.length-1,i=n[o],u=n[a],l,s,m=10;for(u<i&&(s=i,i=u,u=s,s=o,o=a,a=s);m-- >0;){if(s=pt(i,u,r),s===l)return n[o]=i,n[a]=u,e(n);if(s>0)i=Math.floor(i/s)*s,u=Math.ceil(u/s)*s;else if(s<0)i=Math.ceil(i*s)/s,u=Math.floor(u*s)/s;else break;l=s}return t},t}function yt(){var t=0,e=1,r=1,n=[.5],o=[0,1],a;function i(l){return l!=null&&l<=l?o[Vt(n,l,0,r)]:a}function u(){var l=-1;for(n=new Array(r);++l<r;)n[l]=((l+1)*e-(l-r)*t)/(r+1);return i}return i.domain=function(l){return arguments.length?([t,e]=l,t=+t,e=+e,u()):[t,e]},i.range=function(l){return arguments.length?(r=(o=Array.from(l)).length-1,u()):o.slice()},i.invertExtent=function(l){var s=o.indexOf(l);return s<0?[NaN,NaN]:s<1?[t,n[0]]:s>=r?[n[r-1],e]:[n[s-1],n[s]]},i.unknown=function(l){return arguments.length&&(a=l),i},i.thresholds=function(){return n.slice()},i.copy=function(){return yt().domain([t,e]).range(o).unknown(a)},er.apply(fr(i),arguments)}var ee=new Date,re=new Date;function H(t,e,r,n){function o(a){return t(a=arguments.length===0?new Date:new Date(+a)),a}return o.floor=a=>(t(a=new Date(+a)),a),o.ceil=a=>(t(a=new Date(a-1)),e(a,1),t(a),a),o.round=a=>{let i=o(a),u=o.ceil(a);return a-i<u-a?i:u},o.offset=(a,i)=>(e(a=new Date(+a),i==null?1:Math.floor(i)),a),o.range=(a,i,u)=>{let l=[];if(a=o.ceil(a),u=u==null?1:Math.floor(u),!(a<i)||!(u>0))return l;let s;do l.push(s=new Date(+a)),e(a,u),t(a);while(s<a&&a<i);return l},o.filter=a=>H(i=>{if(i>=i)for(;t(i),!a(i);)i.setTime(i-1)},(i,u)=>{if(i>=i)if(u<0)for(;++u<=0;)for(;e(i,-1),!a(i););else for(;--u>=0;)for(;e(i,1),!a(i););}),r&&(o.count=(a,i)=>(ee.setTime(+a),re.setTime(+i),t(ee),t(re),Math.floor(r(ee,re))),o.every=a=>(a=Math.floor(a),!isFinite(a)||!(a>0)?null:a>1?o.filter(n?i=>n(i)%a===0:i=>o.count(0,i)%a===0):o)),o}var $=H(t=>t.setHours(0,0,0,0),(t,e)=>t.setDate(t.getDate()+e),(t,e)=>(e-t-(e.getTimezoneOffset()-t.getTimezoneOffset())*6e4)/864e5,t=>t.getDate()-1),po=$.range,gt=H(t=>{t.setUTCHours(0,0,0,0)},(t,e)=>{t.setUTCDate(t.getUTCDate()+e)},(t,e)=>(e-t)/864e5,t=>t.getUTCDate()-1),ho=gt.range,cr=H(t=>{t.setUTCHours(0,0,0,0)},(t,e)=>{t.setUTCDate(t.getUTCDate()+e)},(t,e)=>(e-t)/864e5,t=>Math.floor(t/864e5)),yo=cr.range;function it(t){return H(e=>{e.setDate(e.getDate()-(e.getDay()+7-t)%7),e.setHours(0,0,0,0)},(e,r)=>{e.setDate(e.getDate()+r*7)},(e,r)=>(r-e-(r.getTimezoneOffset()-e.getTimezoneOffset())*6e4)/6048e5)}var ut=it(0),J=it(1),mr=it(2),pr=it(3),K=it(4),hr=it(5),dr=it(6),yr=ut.range,xo=J.range,vo=mr.range,Mo=pr.range,wo=K.range,_o=hr.range,So=dr.range;function st(t){return H(e=>{e.setUTCDate(e.getUTCDate()-(e.getUTCDay()+7-t)%7),e.setUTCHours(0,0,0,0)},(e,r)=>{e.setUTCDate(e.getUTCDate()+r*7)},(e,r)=>(r-e)/6048e5)}var xt=st(0),lt=st(1),gr=st(2),xr=st(3),j=st(4),vr=st(5),Mr=st(6),wr=xt.range,To=lt.range,Do=gr.range,Co=xr.range,bo=j.range,Uo=vr.range,ko=Mr.range;var vt=H(t=>{t.setDate(1),t.setHours(0,0,0,0)},(t,e)=>{t.setMonth(t.getMonth()+e)},(t,e)=>e.getMonth()-t.getMonth()+(e.getFullYear()-t.getFullYear())*12,t=>t.getMonth()),Ao=vt.range,_r=H(t=>{t.setUTCDate(1),t.setUTCHours(0,0,0,0)},(t,e)=>{t.setUTCMonth(t.getUTCMonth()+e)},(t,e)=>e.getUTCMonth()-t.getUTCMonth()+(e.getUTCFullYear()-t.getUTCFullYear())*12,t=>t.getUTCMonth()),Fo=_r.range;var V=H(t=>{t.setMonth(0,1),t.setHours(0,0,0,0)},(t,e)=>{t.setFullYear(t.getFullYear()+e)},(t,e)=>e.getFullYear()-t.getFullYear(),t=>t.getFullYear());V.every=t=>!isFinite(t=Math.floor(t))||!(t>0)?null:H(e=>{e.setFullYear(Math.floor(e.getFullYear()/t)*t),e.setMonth(0,1),e.setHours(0,0,0,0)},(e,r)=>{e.setFullYear(e.getFullYear()+r*t)});var Lo=V.range,B=H(t=>{t.setUTCMonth(0,1),t.setUTCHours(0,0,0,0)},(t,e)=>{t.setUTCFullYear(t.getUTCFullYear()+e)},(t,e)=>e.getUTCFullYear()-t.getUTCFullYear(),t=>t.getUTCFullYear());B.every=t=>!isFinite(t=Math.floor(t))||!(t>0)?null:H(e=>{e.setUTCFullYear(Math.floor(e.getUTCFullYear()/t)*t),e.setUTCMonth(0,1),e.setUTCHours(0,0,0,0)},(e,r)=>{e.setUTCFullYear(e.getUTCFullYear()+r*t)});var No=B.range;function oe(t){if(0<=t.y&&t.y<100){var e=new Date(-1,t.m,t.d,t.H,t.M,t.S,t.L);return e.setFullYear(t.y),e}return new Date(t.y,t.m,t.d,t.H,t.M,t.S,t.L)}function ae(t){if(0<=t.y&&t.y<100){var e=new Date(Date.UTC(-1,t.m,t.d,t.H,t.M,t.S,t.L));return e.setUTCFullYear(t.y),e}return new Date(Date.UTC(t.y,t.m,t.d,t.H,t.M,t.S,t.L))}function Mt(t,e,r){return{y:t,m:e,d:r,H:0,M:0,S:0,L:0}}function ie(t){var e=t.dateTime,r=t.date,n=t.time,o=t.periods,a=t.days,i=t.shortDays,u=t.months,l=t.shortMonths,s=wt(o),m=_t(o),p=wt(a),w=_t(a),h=wt(i),x=_t(i),S=wt(u),U=_t(u),L=wt(l),b=_t(l),N={a:Q,A:X,b:z,B:O,c:null,d:Ur,e:Ur,f:ra,g:ma,G:ha,H:jo,I:ta,j:ea,L:Nr,m:na,M:oa,p:Br,q:Zr,Q:Fr,s:Lr,S:aa,u:ia,U:ua,V:sa,w:la,W:fa,x:null,X:null,y:ca,Y:pa,Z:da,"%":Ar},k={a:Qr,A:Xr,b:Gr,B:Jr,c:null,d:kr,e:kr,f:va,g:ka,G:Fa,H:ya,I:ga,j:xa,L:Yr,m:Ma,M:wa,p:Kr,q:jr,Q:Fr,s:Lr,S:_a,u:Sa,U:Ta,V:Da,w:Ca,W:ba,x:null,X:null,y:Ua,Y:Aa,Z:La,"%":Ar},E={a:et,A:rt,b:y,B:I,c:D,d:Cr,e:Cr,f:Xo,g:Dr,G:Tr,H:br,I:br,j:Vo,L:Qo,m:$o,M:Bo,p:R,q:zo,Q:Jo,s:Ko,S:Zo,u:Po,U:Io,V:Oo,w:Wo,W:qo,x:d,X:A,y:Dr,Y:Tr,Z:Ro,"%":Go};N.x=_(r,N),N.X=_(n,N),N.c=_(e,N),k.x=_(r,k),k.X=_(n,k),k.c=_(e,k);function _(c,g){return function(v){var f=[],Y=-1,T=0,W=c.length,P,nt,fe;for(v instanceof Date||(v=new Date(+v));++Y<W;)c.charCodeAt(Y)===37&&(f.push(c.slice(T,Y)),(nt=Sr[P=c.charAt(++Y)])!=null?P=c.charAt(++Y):nt=P==="e"?" ":"0",(fe=g[P])&&(P=fe(v,nt)),f.push(P),T=Y+1);return f.push(c.slice(T,Y)),f.join("")}}function tt(c,g){return function(v){var f=Mt(1900,void 0,1),Y=Z(f,c,v+="",0),T,W;if(Y!=v.length)return null;if("Q"in f)return new Date(f.Q);if("s"in f)return new Date(f.s*1e3+("L"in f?f.L:0));if(g&&!("Z"in f)&&(f.Z=0),"p"in f&&(f.H=f.H%12+f.p*12),f.m===void 0&&(f.m="q"in f?f.q:0),"V"in f){if(f.V<1||f.V>53)return null;"w"in f||(f.w=1),"Z"in f?(T=ae(Mt(f.y,0,1)),W=T.getUTCDay(),T=W>4||W===0?lt.ceil(T):lt(T),T=gt.offset(T,(f.V-1)*7),f.y=T.getUTCFullYear(),f.m=T.getUTCMonth(),f.d=T.getUTCDate()+(f.w+6)%7):(T=oe(Mt(f.y,0,1)),W=T.getDay(),T=W>4||W===0?J.ceil(T):J(T),T=$.offset(T,(f.V-1)*7),f.y=T.getFullYear(),f.m=T.getMonth(),f.d=T.getDate()+(f.w+6)%7)}else("W"in f||"U"in f)&&("w"in f||(f.w="u"in f?f.u%7:"W"in f?1:0),W="Z"in f?ae(Mt(f.y,0,1)).getUTCDay():oe(Mt(f.y,0,1)).getDay(),f.m=0,f.d="W"in f?(f.w+6)%7+f.W*7-(W+5)%7:f.w+f.U*7-(W+6)%7);return"Z"in f?(f.H+=f.Z/100|0,f.M+=f.Z%100,ae(f)):oe(f)}}function Z(c,g,v,f){for(var Y=0,T=g.length,W=v.length,P,nt;Y<T;){if(f>=W)return-1;if(P=g.charCodeAt(Y++),P===37){if(P=g.charAt(Y++),nt=E[P in Sr?g.charAt(Y++):P],!nt||(f=nt(c,v,f))<0)return-1}else if(P!=v.charCodeAt(f++))return-1}return f}function R(c,g,v){var f=s.exec(g.slice(v));return f?(c.p=m.get(f[0].toLowerCase()),v+f[0].length):-1}function et(c,g,v){var f=h.exec(g.slice(v));return f?(c.w=x.get(f[0].toLowerCase()),v+f[0].length):-1}function rt(c,g,v){var f=p.exec(g.slice(v));return f?(c.w=w.get(f[0].toLowerCase()),v+f[0].length):-1}function y(c,g,v){var f=L.exec(g.slice(v));return f?(c.m=b.get(f[0].toLowerCase()),v+f[0].length):-1}function I(c,g,v){var f=S.exec(g.slice(v));return f?(c.m=U.get(f[0].toLowerCase()),v+f[0].length):-1}function D(c,g,v){return Z(c,e,g,v)}function d(c,g,v){return Z(c,r,g,v)}function A(c,g,v){return Z(c,n,g,v)}function Q(c){return i[c.getDay()]}function X(c){return a[c.getDay()]}function z(c){return l[c.getMonth()]}function O(c){return u[c.getMonth()]}function Br(c){return o[+(c.getHours()>=12)]}function Zr(c){return 1+~~(c.getMonth()/3)}function Qr(c){return i[c.getUTCDay()]}function Xr(c){return a[c.getUTCDay()]}function Gr(c){return l[c.getUTCMonth()]}function Jr(c){return u[c.getUTCMonth()]}function Kr(c){return o[+(c.getUTCHours()>=12)]}function jr(c){return 1+~~(c.getUTCMonth()/3)}return{format:function(c){var g=_(c+="",N);return g.toString=function(){return c},g},parse:function(c){var g=tt(c+="",!1);return g.toString=function(){return c},g},utcFormat:function(c){var g=_(c+="",k);return g.toString=function(){return c},g},utcParse:function(c){var g=tt(c+="",!0);return g.toString=function(){return c},g}}}var Sr={"-":"",_:" ",0:"0"},F=/^\s*\d+/,Ho=/^%/,Yo=/[\\^$*+?|[\]().{}]/g;function M(t,e,r){var n=t<0?"-":"",o=(n?-t:t)+"",a=o.length;return n+(a<r?new Array(r-a+1).join(e)+o:o)}function Eo(t){return t.replace(Yo,"\\$&")}function wt(t){return new RegExp("^(?:"+t.map(Eo).join("|")+")","i")}function _t(t){return new Map(t.map((e,r)=>[e.toLowerCase(),r]))}function Wo(t,e,r){var n=F.exec(e.slice(r,r+1));return n?(t.w=+n[0],r+n[0].length):-1}function Po(t,e,r){var n=F.exec(e.slice(r,r+1));return n?(t.u=+n[0],r+n[0].length):-1}function Io(t,e,r){var n=F.exec(e.slice(r,r+2));return n?(t.U=+n[0],r+n[0].length):-1}function Oo(t,e,r){var n=F.exec(e.slice(r,r+2));return n?(t.V=+n[0],r+n[0].length):-1}function qo(t,e,r){var n=F.exec(e.slice(r,r+2));return n?(t.W=+n[0],r+n[0].length):-1}function Tr(t,e,r){var n=F.exec(e.slice(r,r+4));return n?(t.y=+n[0],r+n[0].length):-1}function Dr(t,e,r){var n=F.exec(e.slice(r,r+2));return n?(t.y=+n[0]+(+n[0]>68?1900:2e3),r+n[0].length):-1}function Ro(t,e,r){var n=/^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(e.slice(r,r+6));return n?(t.Z=n[1]?0:-(n[2]+(n[3]||"00")),r+n[0].length):-1}function zo(t,e,r){var n=F.exec(e.slice(r,r+1));return n?(t.q=n[0]*3-3,r+n[0].length):-1}function $o(t,e,r){var n=F.exec(e.slice(r,r+2));return n?(t.m=n[0]-1,r+n[0].length):-1}function Cr(t,e,r){var n=F.exec(e.slice(r,r+2));return n?(t.d=+n[0],r+n[0].length):-1}function Vo(t,e,r){var n=F.exec(e.slice(r,r+3));return n?(t.m=0,t.d=+n[0],r+n[0].length):-1}function br(t,e,r){var n=F.exec(e.slice(r,r+2));return n?(t.H=+n[0],r+n[0].length):-1}function Bo(t,e,r){var n=F.exec(e.slice(r,r+2));return n?(t.M=+n[0],r+n[0].length):-1}function Zo(t,e,r){var n=F.exec(e.slice(r,r+2));return n?(t.S=+n[0],r+n[0].length):-1}function Qo(t,e,r){var n=F.exec(e.slice(r,r+3));return n?(t.L=+n[0],r+n[0].length):-1}function Xo(t,e,r){var n=F.exec(e.slice(r,r+6));return n?(t.L=Math.floor(n[0]/1e3),r+n[0].length):-1}function Go(t,e,r){var n=Ho.exec(e.slice(r,r+1));return n?r+n[0].length:-1}function Jo(t,e,r){var n=F.exec(e.slice(r));return n?(t.Q=+n[0],r+n[0].length):-1}function Ko(t,e,r){var n=F.exec(e.slice(r));return n?(t.s=+n[0],r+n[0].length):-1}function Ur(t,e){return M(t.getDate(),e,2)}function jo(t,e){return M(t.getHours(),e,2)}function ta(t,e){return M(t.getHours()%12||12,e,2)}function ea(t,e){return M(1+$.count(V(t),t),e,3)}function Nr(t,e){return M(t.getMilliseconds(),e,3)}function ra(t,e){return Nr(t,e)+"000"}function na(t,e){return M(t.getMonth()+1,e,2)}function oa(t,e){return M(t.getMinutes(),e,2)}function aa(t,e){return M(t.getSeconds(),e,2)}function ia(t){var e=t.getDay();return e===0?7:e}function ua(t,e){return M(ut.count(V(t)-1,t),e,2)}function Hr(t){var e=t.getDay();return e>=4||e===0?K(t):K.ceil(t)}function sa(t,e){return t=Hr(t),M(K.count(V(t),t)+(V(t).getDay()===4),e,2)}function la(t){return t.getDay()}function fa(t,e){return M(J.count(V(t)-1,t),e,2)}function ca(t,e){return M(t.getFullYear()%100,e,2)}function ma(t,e){return t=Hr(t),M(t.getFullYear()%100,e,2)}function pa(t,e){return M(t.getFullYear()%1e4,e,4)}function ha(t,e){var r=t.getDay();return t=r>=4||r===0?K(t):K.ceil(t),M(t.getFullYear()%1e4,e,4)}function da(t){var e=t.getTimezoneOffset();return(e>0?"-":(e*=-1,"+"))+M(e/60|0,"0",2)+M(e%60,"0",2)}function kr(t,e){return M(t.getUTCDate(),e,2)}function ya(t,e){return M(t.getUTCHours(),e,2)}function ga(t,e){return M(t.getUTCHours()%12||12,e,2)}function xa(t,e){return M(1+gt.count(B(t),t),e,3)}function Yr(t,e){return M(t.getUTCMilliseconds(),e,3)}function va(t,e){return Yr(t,e)+"000"}function Ma(t,e){return M(t.getUTCMonth()+1,e,2)}function wa(t,e){return M(t.getUTCMinutes(),e,2)}function _a(t,e){return M(t.getUTCSeconds(),e,2)}function Sa(t){var e=t.getUTCDay();return e===0?7:e}function Ta(t,e){return M(xt.count(B(t)-1,t),e,2)}function Er(t){var e=t.getUTCDay();return e>=4||e===0?j(t):j.ceil(t)}function Da(t,e){return t=Er(t),M(j.count(B(t),t)+(B(t).getUTCDay()===4),e,2)}function Ca(t){return t.getUTCDay()}function ba(t,e){return M(lt.count(B(t)-1,t),e,2)}function Ua(t,e){return M(t.getUTCFullYear()%100,e,2)}function ka(t,e){return t=Er(t),M(t.getUTCFullYear()%100,e,2)}function Aa(t,e){return M(t.getUTCFullYear()%1e4,e,4)}function Fa(t,e){var r=t.getUTCDay();return t=r>=4||r===0?j(t):j.ceil(t),M(t.getUTCFullYear()%1e4,e,4)}function La(){return"+0000"}function Ar(){return"%"}function Fr(t){return+t}function Lr(t){return Math.floor(+t/1e3)}var ft,ct,Wr,Pr,Ir;ue({dateTime:"%x, %X",date:"%-m/%-d/%Y",time:"%-I:%M:%S %p",periods:["AM","PM"],days:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],shortDays:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],months:["January","February","March","April","May","June","July","August","September","October","November","December"],shortMonths:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]});function ue(t){return ft=ie(t),ct=ft.format,Wr=ft.parse,Pr=ft.utcFormat,Ir=ft.utcParse,ft}var Or={cellSize:13,cellGap:2,marginTop:20,marginLeft:30,marginBottom:4},se=["#9be9a8","#40c463","#30a14e","#216e39"],Na=["Mon","","Wed","","Fri","",""],Ha=["Sun","","Tue","","Thu","","Sat"];function Ya(t){return t==="sunday"?Ha:Na}var Ea=ct("%b"),le=ct("%Y-%m-%d"),qr=ct("%a, %b %-d, %Y");function Wa(t){try{return getComputedStyle(t).getPropertyValue("--tblr-bg-surface"),se}catch{return se}}function Pa(t){let e=new Map;for(let r of t)e.set(r.date,r);return e}function Rr(t){return t==="sunday"?ut:J}function Ia(t,e,r,n="monday"){let o=Rr(n),a=o.floor(t),i=[],u=new Date(t);for(;u<=e;){let l=le(u),s=o.count(a,u),m=u.getDay(),p=n==="sunday"?m:(m+6)%7,w=m===0||m===6;i.push({date:new Date(u),dateStr:l,entry:r.get(l)||null,week:s,day:p,isWeekend:w}),u=$.offset(u,1)}return i}function Oa(){let t=document.createElement("div");return t.className="heatmap-tooltip",t.style.display="none",t}function zr(t){if(t.length===0)return 0;let e=new Set(t.filter(a=>a.hours>0).map(a=>a.date));if(e.size===0)return 0;let r=new Date;r.setHours(0,0,0,0);let n=new Date(r);e.has(le(n))||(n=$.offset(n,-1));let o=0;for(;e.has(le(n));)o++,n=$.offset(n,-1);return o}function $r(t){let e=t.filter(a=>a.hours>0);if(e.length===0)return{totalHours:0,avgHours:0,busiestDay:null};let r=Math.round(e.reduce((a,i)=>a+i.hours,0)*10)/10,n=Math.round(r/e.length*10)/10,o=e.reduce((a,i)=>i.hours>a.hours?i:a);return{totalHours:r,avgHours:n,busiestDay:{date:o.date,hours:o.hours}}}function qa(t,e){let r=t.querySelector(".heatmap-stats");r&&r.remove();let n=zr(e),o=$r(e),a=document.createElement("div");a.className="heatmap-stats";let i=[];if(i.push(`<span>\u{1F525} <span class="stat-value">${n}</span> days</span>`),i.push(`<span>Total: <span class="stat-value">${o.totalHours}h</span></span>`),i.push(`<span>Avg: <span class="stat-value">${o.avgHours}h/day</span></span>`),o.busiestDay){let u=new Date(o.busiestDay.date+"T00:00:00"),l=qr(u);i.push(`<span>Busiest: <span class="stat-value">${l} \u2014 ${o.busiestDay.hours.toFixed(1)}h</span></span>`)}a.innerHTML=i.join(""),t.appendChild(a)}function Vr(t,e,r=Or,n,o,a="monday"){if(t.innerHTML="",!e.days||e.days.length===0){let d=document.createElement("div");d.textContent=o||"No tracking data available",d.style.padding="1rem",d.style.color="var(--tblr-secondary, #6c757d)",t.appendChild(d);return}let i=Pa(e.days),u=new Date(e.range.begin),l=new Date(e.range.end),s=Ia(u,l,i,a),m=ht(e.days,d=>d.hours)||1,p=Wa(t),w=yt().domain([0,m]).range(p),{cellGap:h,marginTop:x,marginLeft:S,marginBottom:U}=r,L=(ht(s,d=>d.week)??0)+1,b=t.clientWidth||800,E=Math.min(22,Math.max(10,Math.floor((b-S)/L)-h)),_=E+h,tt=S+L*_,Z=x+7*_+U,R=document.createElement("div");R.style.maxWidth=`${tt}px`,R.style.margin="0 auto",t.appendChild(R);let et=Rt(R).append("svg").attr("width",tt).attr("height",Z).attr("class","heatmap-svg"),rt=Rr(a),y=[],I=rt.floor(u);vt.range(vt.ceil(u),l).forEach(d=>{y.push({date:d,week:rt.count(I,d)})}),et.selectAll(".month-label").data(y).join("text").attr("class","heatmap-label month-label").attr("x",d=>S+d.week*_).attr("y",x-6).text(d=>Ea(d.date)),et.selectAll(".day-label").data(Ya(a)).join("text").attr("class","heatmap-label day-label").attr("x",S-6).attr("y",(d,A)=>x+A*_+E-2).attr("text-anchor","end").text(d=>d),document.querySelectorAll(".heatmap-tooltip").forEach(d=>d.remove());let D=Oa();D.style.position="fixed",document.body.appendChild(D),et.selectAll(".heatmap-cell").data(s).join("rect").attr("class",d=>{let A="heatmap-cell";return d.entry||(A+=" heatmap-empty"),d.isWeekend&&(A+=" heatmap-weekend"),A}).attr("x",d=>S+d.week*_).attr("y",d=>x+d.day*_).attr("width",E).attr("height",E).attr("fill",d=>d.entry?w(d.entry.hours):"").on("mouseenter",function(d,A){let Q=A.entry?A.entry.hours.toFixed(1):"0.0",X=A.entry?A.entry.count:0;D.innerHTML=`<strong>${qr(A.date)}</strong><br>${Q}h (${X} entries)`,D.style.display="block";let z=d.target.getBoundingClientRect();D.style.left=`${z.left+E/2}px`,D.style.top=`${z.top-D.offsetHeight-8}px`}).on("mouseleave",function(){D.style.display="none"}).on("click",function(d,A){n&&n(A.dateStr)})}function Ra(t){let e=t.getAttribute("data-url");if(!e){console.error("KimaiHeatmap: missing data-url attribute");return}let r=t.getAttribute("data-timesheet-url")||"/en/timesheet/",n=t.getAttribute("data-week-start")||"monday",o=t.getAttribute("data-projects"),a=o?JSON.parse(o):[],i=null,u=h=>{let x=`${h} - ${h}`,S=`${r}?daterange=${encodeURIComponent(x)}`;i&&(S+=`&projects[]=${i}`),window.location.href=S};t.innerHTML="";let l=document.createElement("div");l.className="heatmap-wrapper";let s=document.createElement("div");s.className="heatmap-svg-area",l.appendChild(s);let m=null,p=(h,x)=>{m=h,Vr(s,h,Or,u,x,n),qa(t,h.days),s.scrollLeft=s.scrollWidth};if(a.length>0){let h=document.createElement("div");h.className="heatmap-filter";let x=document.createElement("select");x.className="form-select form-select-sm",x.setAttribute("aria-label","Filter by project");let S=document.createElement("option");S.value="",S.textContent="All Projects",x.appendChild(S);for(let U of a){let L=document.createElement("option");L.value=String(U.id),L.textContent=U.name,x.appendChild(L)}x.addEventListener("change",()=>{let U=x.value;i=U?parseInt(U,10):null;let L=U?`${e}?project=${U}`:e;fetch(L).then(b=>{if(!b.ok)throw new Error(`HTTP ${b.status}`);return b.json()}).then(b=>{p(b,"No tracking data for this project")}).catch(b=>{console.error("KimaiHeatmap: failed to load filtered data",b)})}),h.appendChild(x),l.appendChild(h)}t.appendChild(l);let w;window.addEventListener("resize",()=>{clearTimeout(w),w=setTimeout(()=>{m&&p(m)},200)}),fetch(e).then(h=>{if(!h.ok)throw new Error(`HTTP ${h.status}`);return h.json()}).then(h=>{p(h)}).catch(h=>{console.error("KimaiHeatmap: failed to load data",h),s.textContent="Failed to load heatmap data"})}return an(za);})();