var U=Object.defineProperty;var X=(e,t,n)=>t in e?U(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var w=(e,t,n)=>(X(e,typeof t!="symbol"?t+"":t,n),n);import{C as k,d as J,c as T,i as Q,D as Z,E as tt,t as et,a as B,b as nt,A as ot,L as st,B as at,P as rt,e as it,f as lt,g as dt,h as ct,j as ut,T as pt,p as ft,k as gt,l as ht,m as mt,n as bt,u as yt}from"./use-chart-tooltip-45ovlg1Q.js";import{a as W,f as v,$ as wt}from"./app-JmgyQoR0.js";import{p as xt}from"./chartjs-adapter-date-fns.esm-ogm-isT_.js";import{b as vt,s as A,a as Ct,w as kt,e as St,D as Mt,h as L,t as G,i as Rt,u as It,n as Dt}from"./vue-y3KLWBaS.js";const Et=(e,t)=>{const n=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e),o=parseInt(n[1],16),s=parseInt(n[2],16),a=parseInt(n[3],16);return`rgba(${o}, ${s}, ${a}, ${t})`};/*!
 * chartjs-plugin-gradient v0.6.1
 * https://github.com/kurkle/chartjs-plugin-gradient#readme
 * (c) 2022 Jukka Kurkela
 * Released under the MIT License
 */const Pt=k.version,_t=(e,t)=>e.parse(t);function Bt(e,t){const n=Q(t)?parseFloat(t):_t(e,t);return e.getPixelForValue(n)}const q=e=>e&&e.right>e.left&&e.bottom>e.top;function z(e,t,n){return t==="r"?e.createRadialGradient(n.xCenter,n.yCenter,0,n.xCenter,n.yCenter,n.drawingArea):t==="y"?e.createLinearGradient(0,n.bottom,0,n.top):e.createLinearGradient(n.left,0,n.right,0)}function j(e,t){t.forEach(function(n){e.addColorStop(n.stop,n.color.rgbString())})}function Y(e,t,n){if(e.options.has(t.key)){const s=e.options.get(t.key).filter(a=>a.datasetIndex===n);if(s.length)return s[0]}}function H(e,t){if(e.type==="radialLinear"){const a=e.getDistanceFromCenterForValue(t);return{pixel:a,stop:a/e.drawingArea}}const n=e.options.reverse,o=Bt(e,t),s=e.getDecimalForPixel(o);return{pixel:o,stop:n?1-s:s}}const F=e=>e<=.0031308?e*12.92:Math.pow(e,1/2.4)*1.055-.055,C=e=>e<=.04045?e/12.92:Math.pow((e+.055)/1.055,2.4);function Lt(e,t,n){const o=t.color.rgb,s=C(o.r/255),a=C(o.g/255),r=C(o.b/255),i=n.color.rgb,u=C(i.r/255),b=C(i.g/255),g=C(i.b/255);return T({r:Math.round(F(s+e*(u-s))*255),g:Math.round(F(a+e*(b-a))*255),b:Math.round(F(r+e*(g-r))*255),a:o.a+e*Math.abs(i.a-o.a)})}function Ft(e,t,n,o){const s=Y(e,t,n);if(!s||!s.stopColors.length)return;const{stop:a}=H(s.scale,o);let r,i;for(const u of s.stopColors){if(u.stop===a)return u.color;u.stop<a?r=u:u.stop>a&&!i&&(i=u)}return i?Lt(a,r,i):r}const K=[{key:"backgroundColor",legendItemKey:"fillStyle"},{key:"borderColor",legendItemKey:"strokeStyle"}],$t=(e,t)=>t.labels&&t.labels.font&&J(t.labels.font.size)?t.labels.font.size:e.options.font.size;function Ot(e,t,n,o,s){const a=Y(e,n,o.datasetIndex);if(!a||!a.stopColors.length)return;const r=z(t,a.axis,s);j(r,a.stopColors),o[n.legendItemKey]=r}function Vt(e,{boxWidth:t,boxHeight:n}){return{top:e.top,left:e.left,bottom:e.top+n,right:e.left+t,xCenter:e.left+t/2,yCenter:e.top+n/2,drawingArea:Math.max(t,n)/2}}function At(e,t,n,o){const s=e.legend.legendHitBoxes[n.datasetIndex],a=Vt(s,o);q(a)&&K.forEach(function(r){Ot(t,e.ctx,r,n,a)})}function Gt(e,t,n,o){for(const s of e.legend.legendItems)K.forEach(function(a){const r=n.data[s.index],i=Ft(t,a,o,r);i&&i.valid&&(s[a.legendItemKey]=i.rgbString())})}function Tt(e,t){const n=e.legend,o=n.options,s=o.labels.boxHeight?o.labels.boxHeight:$t(e,o),a=o.labels.boxWidth,r=e.data.datasets;for(let i=0;i<r.length;i++){const u=n.legendItems[i];u.datasetIndex===i?At(e,t,u,{boxWidth:a,boxHeight:s}):Gt(e,t,r[i],i)}}const D=new Map,Wt=(e,t)=>e[t+"Scale"];function qt(e,t,n){for(const o of Object.keys(t)){const{pixel:s,stop:a}=H(e,o);if(isFinite(s)&&isFinite(a)){const r=T(t[o]);r&&r.valid&&n.push({stop:Math.max(0,Math.min(1,a)),color:r})}}n.sort((o,s)=>o.stop-s.stop)}function zt(e,t,n,o){t[n]=o,e.dataset&&(e.dataset.options?e.dataset.options[n]=o:e.dataset[n]=o)}function jt(e,t,n,o){let s=e.options.get(n);return s?t.hidden||(s=s.filter(a=>a.datasetIndex!==o),e.options.set(n,s)):(s=[],e.options.set(n,s)),s}function Yt(e,t,n,o,s){const a=e.ctx,r=e.getDatasetMeta(s);if(!r.hidden)for(const[i,u]of Object.entries(n)){const{axis:b,colors:g}=u;if(!g)continue;const d=Wt(r,b);if(!d){console.warn(`Scale not found for '${b}'-axis in datasets[${s}] of chart id ${e.id}, skipping.`);continue}const h=jt(t,r,i,s),p={datasetIndex:s,axis:b,scale:d,stopColors:[]};h.push(p);const y=z(a,b,d);qt(d,g,p.stopColors),p.stopColors.length&&(j(y,p.stopColors),zt(r,o,i,y))}}var Ht={id:"gradient",beforeInit(e){const t={};t.options=new Map,D.set(e,t)},beforeDatasetsUpdate(e){const t=e.chartArea;if(!q(t))return;const n=D.get(e),o=e.data.datasets;for(let s=0;s<o.length;s++){const a=o[s],r=a.gradient;r&&Yt(e,n,r,a,s)}},afterUpdate(e){const t=D.get(e);e.legend&&e.legend.options.display!==!1&&Pt&&Tt(e,t)},destroy(e){D.delete(e)}};/*!
 * chartjs-chart-matrix v2.0.1
 * https://chartjs-chart-matrix.pages.dev/
 * (c) 2023 Jukka Kurkela
 * Released under the MIT license
 */var Kt="2.0.1";class S extends Z{initialize(){this.enableOptionSharing=!0,super.initialize()}update(t){const n=this,o=n._cachedMeta;n.updateElements(o.data,0,o.data.length,t)}updateElements(t,n,o,s){const a=this,r=s==="reset",{xScale:i,yScale:u}=a._cachedMeta,b=a.resolveDataElementOptions(n,s),g=a.getSharedOptions(s,t[n],b);for(let d=n;d<n+o;d++){const h=!r&&a.getParsed(d),p=r?i.getBasePixel():i.getPixelForValue(h.x),y=r?u.getBasePixel():u.getPixelForValue(h.y),M=a.resolveDataElementOptions(d,s),{width:m,height:R,anchorX:P,anchorY:_}=M,I={x:Nt(P,p,m),y:Ut(_,y,R),width:m,height:R,options:M};a.updateElement(t[d],d,I,s)}a.updateSharedOptions(g,s)}draw(){const t=this,n=t.getMeta().data||[];let o,s;for(o=0,s=n.length;o<s;++o)n[o].draw(t._ctx)}}w(S,"id","matrix"),w(S,"version",Kt),w(S,"defaults",{dataElementType:"matrix",animations:{numbers:{type:"number",properties:["x","y","width","height"]}}}),w(S,"overrides",{interaction:{mode:"nearest",intersect:!0},scales:{x:{type:"linear",offset:!0},y:{type:"linear",reverse:!0}}});function Nt(e,t,n){return e==="left"||e==="start"?t:e==="right"||e==="end"?t-n:t-n/2}function Ut(e,t,n){return e==="top"||e==="start"?t:e==="bottom"||e==="end"?t-n:t-n/2}function N(e,t){const{x:n,y:o,width:s,height:a}=e.getProps(["x","y","width","height"],t);return{left:n,top:o,right:n+s,bottom:o+a}}function E(e,t,n){return Math.max(Math.min(e,n),t)}function Xt(e,t,n){const o=e.options.borderWidth;let s,a,r,i;return nt(o)?(s=+o.top||0,a=+o.right||0,r=+o.bottom||0,i=+o.left||0):s=a=r=i=+o||0,{t:E(s,0,n),r:E(a,0,t),b:E(r,0,n),l:E(i,0,t)}}function Jt(e){const t=N(e),n=t.right-t.left,o=t.bottom-t.top,s=Xt(e,n/2,o/2);return{outer:{x:t.left,y:t.top,w:n,h:o},inner:{x:t.left+s.l,y:t.top+s.t,w:n-s.l-s.r,h:o-s.t-s.b}}}function $(e,t,n,o){const s=t===null,a=n===null,r=!e||s&&a?!1:N(e,o);return r&&(s||t>=r.left&&t<=r.right)&&(a||n>=r.top&&n<=r.bottom)}class O extends tt{constructor(t){super(),this.options=void 0,this.width=void 0,this.height=void 0,t&&Object.assign(this,t)}draw(t){const n=this.options,{inner:o,outer:s}=Jt(this),a=et(n.borderRadius);t.save(),s.w!==o.w||s.h!==o.h?(t.beginPath(),B(t,{x:s.x,y:s.y,w:s.w,h:s.h,radius:a}),B(t,{x:o.x,y:o.y,w:o.w,h:o.h,radius:a}),t.fillStyle=n.backgroundColor,t.fill(),t.fillStyle=n.borderColor,t.fill("evenodd")):(t.beginPath(),B(t,{x:o.x,y:o.y,w:o.w,h:o.h,radius:a}),t.fillStyle=n.backgroundColor,t.fill()),t.restore()}inRange(t,n,o){return $(this,t,n,o)}inXRange(t,n){return $(this,t,null,n)}inYRange(t,n){return $(this,null,t,n)}getCenterPoint(t){const{x:n,y:o,width:s,height:a}=this.getProps(["x","y","width","height"],t);return{x:n+s/2,y:o+a/2}}tooltipPosition(){return this.getCenterPoint()}getRange(t){return t==="x"?this.width/2:this.height/2}}w(O,"id","matrix"),w(O,"defaults",{backgroundColor:void 0,borderColor:void 0,borderWidth:void 0,borderRadius:0,anchorX:"center",anchorY:"center",width:20,height:20});function Qt(){k.register(ot,st,at,rt,it,lt,dt,ct,ut,pt,ft,gt,ht,mt,bt,S,O,xt,Ht),k.defaults.color=getComputedStyle(document.documentElement).getPropertyValue("--fg"),k.defaults.borderColor=W.state.darkMode?"rgba(255, 255, 255, 0.1)":"rgba(0, 0, 0, 0.1)",k.defaults.animation=!1}const Zt={key:1},ae=vt({__name:"MkHeatmap",props:{src:{}},setup(e){Qt();const t=e,n=A(null),o=A(null),s=new Date;let a=null,r=Ct(!0);const{handler:i}=yt({position:"middle"}),u=(g,d,h)=>g.length===d.length&&d.length===h.length?g.map((p,y)=>p+d[y]+h[y]):null;async function b(){a&&a.destroy();const g=n.value.offsetWidth>700,d=n.value.offsetWidth<400,h=g?50:d?10:25,p=7*h,y=l=>{const c=s.getFullYear(),f=s.getMonth(),x=s.getDate();return new Date(c,f,x-l)},M=l=>l.map((c,f)=>{const x=y(f),V=`${x.getFullYear()}-${(x.getMonth()+1).toString().padStart(2,"0")}-${x.getDate().toString().padStart(2,"0")}`;return{x:V,y:x.getDay(),d:V,v:c}});let m;if(t.src==="active-users")m=(await v("charts/active-users",{limit:p,span:"day"})).readWrite;else if(t.src==="notes")m=(await v("charts/notes",{limit:p,span:"day"})).local.inc;else if(t.src==="ap-requests-inbox-received")m=(await v("charts/ap-request",{limit:p,span:"day"})).inboxReceived;else if(t.src==="ap-requests-deliver-succeeded")m=(await v("charts/ap-request",{limit:p,span:"day"})).deliverSucceeded;else if(t.src==="ap-requests-deliver-failed")m=(await v("charts/ap-request",{limit:p,span:"day"})).deliverFailed;else if(t.src==="my-notes"){const l=await v("charts/user/notes",{limit:p,span:"day",userId:wt.id});m=u(l.diffs.normal,l.diffs.reply,l.diffs.renote)}r.value=!1,await Dt();const R=W.state.darkMode?"#ebbcba":"#d7827e",P=m.slice().sort((l,c)=>c-l).slice(0,3).reduce((l,c)=>l+c,0)/3,_=Math.max(0,Math.min(...m)-1),I=4;a=new k(o.value,{type:"matrix",data:{datasets:[{label:"Read & Write",data:M(m),pointRadius:0,borderWidth:0,borderJoinStyle:"round",borderRadius:3,backgroundColor(l){const c=l.dataset.data[l.dataIndex].v;let f=(c-_)/P;return c!==0&&(f=Math.max(f,.05)),Et(R,f)},fill:!0,width(l){var f;const c=(f=l.chart.chartArea)!=null?f:{};return(c.right-c.left)/h-I},height(l){var f;const c=(f=l.chart.chartArea)!=null?f:{};return(c.bottom-c.top)/7-I}}]},options:{aspectRatio:g?6:d?1.8:3.2,layout:{padding:{left:8,right:0,top:0,bottom:0}},scales:{x:{type:"time",offset:!0,position:"bottom",time:{unit:"week",round:"week",isoWeekday:0,displayFormats:{day:"M/d",month:"Y/M",week:"M/d"}},grid:{display:!1},ticks:{display:!0,maxRotation:0,autoSkipPadding:8}},y:{offset:!0,reverse:!0,position:"right",grid:{display:!1},ticks:{maxRotation:0,autoSkip:!0,padding:1,font:{size:9},callback:(l,c,f)=>["","Mon","","Wed","","Fri",""][l]}}},plugins:{legend:{display:!1},tooltip:{enabled:!1,callbacks:{title(l){return l[0].dataset.data[l[0].dataIndex].d},label(l){return["Active: "+l.dataset.data[l.dataIndex].v]}},animation:{duration:0},external:i}}}})}return kt(()=>t.src,()=>{r.value=!0,b()}),St(async()=>{b()}),(g,d)=>{const h=Mt("MkLoading");return L(),G("div",{ref_key:"rootEl",ref:n},[r.value?(L(),Rt(h,{key:0})):(L(),G("div",Zt,[It("canvas",{ref_key:"chartEl",ref:o},null,512)]))],512)}}});export{ae as _,Et as a,Ht as b,Qt as i};
