blog-hexo/themes/hexo-theme-cosy/source/js/668b438c.js
2023-10-25 22:05:16 +08:00

1 line
15 KiB
JavaScript

(()=>{var t={860:function(t){t.exports=function(){"use strict";var t=1e3,e=6e4,n=36e5,r="millisecond",s="second",i="minute",o="hour",a="day",d="week",l="month",c="quarter",u="year",h="date",p="Invalid Date",f=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,m=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,y={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),ordinal:function(t){var e=["th","st","nd","rd"],n=t%100;return"["+t+(e[(n-20)%10]||e[n]||e[0])+"]"}},w=function(t,e,n){var r=String(t);return!r||r.length>=e?t:""+Array(e+1-r.length).join(n)+t},$={s:w,z:function(t){var e=-t.utcOffset(),n=Math.abs(e),r=Math.floor(n/60),s=n%60;return(e<=0?"+":"-")+w(r,2,"0")+":"+w(s,2,"0")},m:function t(e,n){if(e.date()<n.date())return-t(n,e);var r=12*(n.year()-e.year())+(n.month()-e.month()),s=e.clone().add(r,l),i=n-s<0,o=e.clone().add(r+(i?-1:1),l);return+(-(r+(n-s)/(i?s-o:o-s))||0)},a:function(t){return t<0?Math.ceil(t)||0:Math.floor(t)},p:function(t){return{M:l,y:u,w:d,d:a,D:h,h:o,m:i,s,ms:r,Q:c}[t]||String(t||"").toLowerCase().replace(/s$/,"")},u:function(t){return void 0===t}},v="en",g={};g[v]=y;var D="$isDayjsObject",M=function(t){return t instanceof S||!(!t||!t[D])},b=function t(e,n,r){var s;if(!e)return v;if("string"==typeof e){var i=e.toLowerCase();g[i]&&(s=i),n&&(g[i]=n,s=i);var o=e.split("-");if(!s&&o.length>1)return t(o[0])}else{var a=e.name;g[a]=e,s=a}return!r&&s&&(v=s),s||!r&&v},E=function(t,e){if(M(t))return t.clone();var n="object"==typeof e?e:{};return n.date=t,n.args=arguments,new S(n)},C=$;C.l=b,C.i=M,C.w=function(t,e){return E(t,{locale:e.$L,utc:e.$u,x:e.$x,$offset:e.$offset})};var S=function(){function y(t){this.$L=b(t.locale,null,!0),this.parse(t),this.$x=this.$x||t.x||{},this[D]=!0}var w=y.prototype;return w.parse=function(t){this.$d=function(t){var e=t.date,n=t.utc;if(null===e)return new Date(NaN);if(C.u(e))return new Date;if(e instanceof Date)return new Date(e);if("string"==typeof e&&!/Z$/i.test(e)){var r=e.match(f);if(r){var s=r[2]-1||0,i=(r[7]||"0").substring(0,3);return n?new Date(Date.UTC(r[1],s,r[3]||1,r[4]||0,r[5]||0,r[6]||0,i)):new Date(r[1],s,r[3]||1,r[4]||0,r[5]||0,r[6]||0,i)}}return new Date(e)}(t),this.init()},w.init=function(){var t=this.$d;this.$y=t.getFullYear(),this.$M=t.getMonth(),this.$D=t.getDate(),this.$W=t.getDay(),this.$H=t.getHours(),this.$m=t.getMinutes(),this.$s=t.getSeconds(),this.$ms=t.getMilliseconds()},w.$utils=function(){return C},w.isValid=function(){return!(this.$d.toString()===p)},w.isSame=function(t,e){var n=E(t);return this.startOf(e)<=n&&n<=this.endOf(e)},w.isAfter=function(t,e){return E(t)<this.startOf(e)},w.isBefore=function(t,e){return this.endOf(e)<E(t)},w.$g=function(t,e,n){return C.u(t)?this[e]:this.set(n,t)},w.unix=function(){return Math.floor(this.valueOf()/1e3)},w.valueOf=function(){return this.$d.getTime()},w.startOf=function(t,e){var n=this,r=!!C.u(e)||e,c=C.p(t),p=function(t,e){var s=C.w(n.$u?Date.UTC(n.$y,e,t):new Date(n.$y,e,t),n);return r?s:s.endOf(a)},f=function(t,e){return C.w(n.toDate()[t].apply(n.toDate("s"),(r?[0,0,0,0]:[23,59,59,999]).slice(e)),n)},m=this.$W,y=this.$M,w=this.$D,$="set"+(this.$u?"UTC":"");switch(c){case u:return r?p(1,0):p(31,11);case l:return r?p(1,y):p(0,y+1);case d:var v=this.$locale().weekStart||0,g=(m<v?m+7:m)-v;return p(r?w-g:w+(6-g),y);case a:case h:return f($+"Hours",0);case o:return f($+"Minutes",1);case i:return f($+"Seconds",2);case s:return f($+"Milliseconds",3);default:return this.clone()}},w.endOf=function(t){return this.startOf(t,!1)},w.$set=function(t,e){var n,d=C.p(t),c="set"+(this.$u?"UTC":""),p=(n={},n[a]=c+"Date",n[h]=c+"Date",n[l]=c+"Month",n[u]=c+"FullYear",n[o]=c+"Hours",n[i]=c+"Minutes",n[s]=c+"Seconds",n[r]=c+"Milliseconds",n)[d],f=d===a?this.$D+(e-this.$W):e;if(d===l||d===u){var m=this.clone().set(h,1);m.$d[p](f),m.init(),this.$d=m.set(h,Math.min(this.$D,m.daysInMonth())).$d}else p&&this.$d[p](f);return this.init(),this},w.set=function(t,e){return this.clone().$set(t,e)},w.get=function(t){return this[C.p(t)]()},w.add=function(r,c){var h,p=this;r=Number(r);var f=C.p(c),m=function(t){var e=E(p);return C.w(e.date(e.date()+Math.round(t*r)),p)};if(f===l)return this.set(l,this.$M+r);if(f===u)return this.set(u,this.$y+r);if(f===a)return m(1);if(f===d)return m(7);var y=(h={},h[i]=e,h[o]=n,h[s]=t,h)[f]||1,w=this.$d.getTime()+r*y;return C.w(w,this)},w.subtract=function(t,e){return this.add(-1*t,e)},w.format=function(t){var e=this,n=this.$locale();if(!this.isValid())return n.invalidDate||p;var r=t||"YYYY-MM-DDTHH:mm:ssZ",s=C.z(this),i=this.$H,o=this.$m,a=this.$M,d=n.weekdays,l=n.months,c=n.meridiem,u=function(t,n,s,i){return t&&(t[n]||t(e,r))||s[n].slice(0,i)},h=function(t){return C.s(i%12||12,t,"0")},f=c||function(t,e,n){var r=t<12?"AM":"PM";return n?r.toLowerCase():r};return r.replace(m,(function(t,r){return r||function(t){switch(t){case"YY":return String(e.$y).slice(-2);case"YYYY":return C.s(e.$y,4,"0");case"M":return a+1;case"MM":return C.s(a+1,2,"0");case"MMM":return u(n.monthsShort,a,l,3);case"MMMM":return u(l,a);case"D":return e.$D;case"DD":return C.s(e.$D,2,"0");case"d":return String(e.$W);case"dd":return u(n.weekdaysMin,e.$W,d,2);case"ddd":return u(n.weekdaysShort,e.$W,d,3);case"dddd":return d[e.$W];case"H":return String(i);case"HH":return C.s(i,2,"0");case"h":return h(1);case"hh":return h(2);case"a":return f(i,o,!0);case"A":return f(i,o,!1);case"m":return String(o);case"mm":return C.s(o,2,"0");case"s":return String(e.$s);case"ss":return C.s(e.$s,2,"0");case"SSS":return C.s(e.$ms,3,"0");case"Z":return s}return null}(t)||s.replace(":","")}))},w.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},w.diff=function(r,h,p){var f,m=this,y=C.p(h),w=E(r),$=(w.utcOffset()-this.utcOffset())*e,v=this-w,g=function(){return C.m(m,w)};switch(y){case u:f=g()/12;break;case l:f=g();break;case c:f=g()/3;break;case d:f=(v-$)/6048e5;break;case a:f=(v-$)/864e5;break;case o:f=v/n;break;case i:f=v/e;break;case s:f=v/t;break;default:f=v}return p?f:C.a(f)},w.daysInMonth=function(){return this.endOf(l).$D},w.$locale=function(){return g[this.$L]},w.locale=function(t,e){if(!t)return this.$L;var n=this.clone(),r=b(t,e,!0);return r&&(n.$L=r),n},w.clone=function(){return C.w(this.$d,this)},w.toDate=function(){return new Date(this.valueOf())},w.toJSON=function(){return this.isValid()?this.toISOString():null},w.toISOString=function(){return this.$d.toISOString()},w.toString=function(){return this.$d.toUTCString()},y}(),x=S.prototype;return E.prototype=x,[["$ms",r],["$s",s],["$m",i],["$H",o],["$W",a],["$M",l],["$y",u],["$D",h]].forEach((function(t){x[t[1]]=function(e){return this.$g(e,t[0],t[1])}})),E.extend=function(t,e){return t.$i||(t(e,S,E),t.$i=!0),E},E.locale=b,E.isDayjs=M,E.unix=function(t){return E(1e3*t)},E.en=g[v],E.Ls=g,E.p={},E}()}},e={};function n(r){var s=e[r];if(void 0!==s)return s.exports;var i=e[r]={exports:{}};return t[r].call(i.exports,i,i.exports,n),i.exports}n.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return n.d(e,{a:e}),e},n.d=(t,e)=>{for(var r in e)n.o(e,r)&&!n.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),(()=>{"use strict";class t{constructor(t,e,n){this.dropdownElement=null,this.selector=t,this.options=e,this.element=document.querySelector(this.selector),this.onClickItem=n.onClickItem,this.init()}init(){this.element&&(this.element.addEventListener("click",this.toggleDropdown.bind(this)),document.addEventListener("click",this.handleDocumentClick.bind(this)))}toggleDropdown(e){e.stopPropagation(),t.activeDropdown&&t.activeDropdown!==this&&t.activeDropdown.removeDropdown(),this.dropdownElement?this.removeDropdown():(this.createDropdown(),t.activeDropdown=this)}fadeIn(t,e){let n=0;const r=16.7/e,s=()=>{if(n+=r,n>=1)return n=1,void(t.style.opacity=String(n));t.style.opacity=String(n),requestAnimationFrame(s)};s()}fadeOut(t,e,n){let r=1;const s=16.7/e,i=t,o=()=>{if(i){if(r-=s,r<=0)return r=0,i.style.opacity=String(r),void n();i.style.opacity=String(r),requestAnimationFrame(o)}};o()}createDropdown(){this.dropdownElement=document.createElement("div"),this.dropdownElement.classList.add("dropdown-menu"),this.dropdownElement.style.opacity="0",this.options.forEach((t=>{const e=document.createElement("div");if(e.style.padding="8px 12px",e.style.color="var(--color-font-2)",e.style.borderRadius="var(--radius)",e.style.fontSize="13px",e.style.cursor="pointer",e.style.display="flex",e.style.alignItems="center",e.classList.add("dropdown-item"),t.icon){const n=document.createElement("span");n.innerHTML=t.icon,n.style.marginRight="8px",n.style.width="16px",n.style.height="16px",e.appendChild(n)}const n=document.createTextNode(String(t.label));e.appendChild(n),e.addEventListener("click",(()=>{var e;null===(e=this.onClickItem)||void 0===e||e.call(this,t.value),this.removeDropdown()})),e.addEventListener("mouseenter",(()=>{e.style.backgroundColor="var(--color-menu-hover)",e.style.color="var(--color-font)"})),e.addEventListener("mouseleave",(()=>{e.style.backgroundColor="",e.style.color="var(--color-font-2)"})),this.dropdownElement.appendChild(e)})),document.body.appendChild(this.dropdownElement);const t=this.element.getBoundingClientRect(),e=this.dropdownElement.offsetWidth,n=document.documentElement.clientWidth;this.dropdownElement.style.position="absolute",this.dropdownElement.style.top=`${t.bottom}px`,this.dropdownElement.style.minWidth="140px",this.dropdownElement.style.padding="6px 4px",this.dropdownElement.style.borderRadius="var(--radius)",this.dropdownElement.style.backdropFilter="var(--dropdown-bdf)",this.dropdownElement.style.background="var(--dropdown-bg)",this.dropdownElement.style.border="var(--dropdown-border)",this.dropdownElement.style.boxShadow="var(--dropdown-boxShadow)",this.dropdownElement.style.position="absolute",this.dropdownElement.style.top=`${t.top}px`,t.left+t.width/2<n/2?(this.dropdownElement.style.left=`${t.left}px`,this.dropdownElement.style.right="auto"):(this.dropdownElement.style.right=n-t.right+"px",this.dropdownElement.style.left="auto"),t.left+e>n?(this.dropdownElement.style.right=n-t.right+"px",this.dropdownElement.style.left="auto"):(this.dropdownElement.style.left=`${t.left}px`,this.dropdownElement.style.right="auto"),this.fadeIn(this.dropdownElement,150)}removeDropdown(){if(this.dropdownElement){const t=this.dropdownElement;this.fadeOut(t,150,(()=>{t.remove(),this.dropdownElement===t&&(this.dropdownElement=null)}))}}handleDocumentClick(){this.removeDropdown()}}t.activeDropdown=null;var e=n(860),r=n.n(e);class s{constructor(t,e,n=r()().year()){if(this.isUserDragging=!1,this.lastMouseX=0,this.currentDayWidth=30,this.handleMouseDown=t=>{this.isUserDragging=!0,this.lastMouseX=t.clientX},this.handleMouseMove=t=>{if(this.isUserDragging){const e=t.clientX-this.lastMouseX;this.chartContainer.scrollBy(-e,0),this.lastMouseX=t.clientX}},this.handleMouseUp=()=>{this.isUserDragging=!1},this.currentYear=n,this.taskList=e,this.chartContainer=document.querySelector(t),!this.chartContainer)throw new Error(`Container with selector ${t} not found`);this.renderChart(),this.handleMouseWheelInView(),this.centerOnCurrentDay(),this.updateDayWidthOnScroll()}getDaysOfMonth(t,e){return new Date(t,e+1,0).getDate()}renderChart(){this.chartContainer.innerHTML="";const t=document.createElement("div");t.className="timeline-container";const e=document.createElement("div");e.className="task-container",this.chartContainer.addEventListener("mousedown",this.handleMouseDown),document.addEventListener("mousemove",this.handleMouseMove),document.addEventListener("mouseup",this.handleMouseUp);const n=document.createElement("div");n.className="months-row";const s=document.createElement("div");s.className="days-row";let i=0;for(let t=0;t<12;t++){const o=document.createElement("div");o.className="month",o.textContent=`${t+1} / ${this.currentYear}`,o.style.left=`${i}px`,n.appendChild(o);const a=this.getDaysOfMonth(this.currentYear,t);if(i>0){const t=document.createElement("div");t.style.position="absolute",t.style.height="100%",t.style.width="0",t.style.borderLeft="1px dashed var(--color-border)",t.style.left=`${i}px`,e.appendChild(t)}for(let e=1;e<=a;e++){const n=document.createElement("div");n.className="day";const o=`${this.currentYear}-${t+1}-${e}`;n.setAttribute("data-ymd",r()(o).format("YYYY-MM-DD")),n.textContent=`${e}`,n.style.position="absolute",n.style.left=`${i}px`,s.appendChild(n),i+=this.currentDayWidth}}this.taskList.forEach(((t,n)=>{const s=document.createElement("div");s.className="task-bar",s.setAttribute("data-start",r()(t.start).format("YYYY-MM-DD")),s.setAttribute("data-end",r()(t.end).format("YYYY-MM-DD")),s.style.position="absolute",s.style.height="30px",s.style.lineHeight="30px",s.style.top=30*n+"px",s.textContent=t.name,e.appendChild(s)})),t.appendChild(n),t.appendChild(s),this.chartContainer.appendChild(t),this.chartContainer.appendChild(e),this.renderTodayVerticalLine(),this.updateTaskBars()}centerOnCurrentDay(){const t=new Date,e=t.getFullYear(),n=t.getMonth(),r=t.getDate();if(this.currentYear===e){let t=0;for(let r=0;r<n;r++)t+=this.getDaysOfMonth(e,r);t+=r;const s=t*this.currentDayWidth-this.chartContainer.offsetWidth/2;this.chartContainer.scrollLeft=s}}handleMouseWheelInView(){this.chartContainer.addEventListener("wheel",(t=>{const e=this.chartContainer.scrollWidth,n=this.chartContainer.offsetWidth;t.deltaY>0&&e<=n||(this.currentDayWidth*=t.deltaY>0?.9:1.1,this.renderChart(),this.updateDayWidthOnScroll(),this.updateTaskBars())}))}updateDayWidthOnScroll(){const t=[...this.chartContainer.querySelectorAll(".day")];this.currentDayWidth<25?t.forEach(((t,e)=>{t.style.display=e%8==0?"block":"none"})):t.forEach((t=>{t.style.display="block"})),this.updateTaskBars()}updateTaskBars(){[...this.chartContainer.querySelectorAll(".task-bar")].forEach((t=>{const e=t.getAttribute("data-start"),n=t.getAttribute("data-end"),s=this.chartContainer.querySelector(`.day[data-ymd="${e}"]`),i=this.chartContainer.querySelector(`.day[data-ymd="${r()(n).add(1,"day").format("YYYY-MM-DD")}"]`);if(s&&i){const e=parseInt(s.style.left,10),n=parseInt(i.style.left,10)-e;t.style.left=`${e}px`,t.style.width=`${n}px`}}))}renderTodayVerticalLine(){const t=r()().format("YYYY-MM-DD"),e=this.chartContainer.querySelector(`.day[data-ymd="${t}"]`);if(!e)return;e.classList.add("today");const n=+e.style.left.replace("px","")+e.offsetWidth/2,s=document.createElement("div");s.className="today-vertical-line",s.style.position="absolute",s.style.height="100%",s.style.width="0",s.style.borderLeft="2px dashed var(--color-primary)",s.style.left=`${n}px`;this.chartContainer.querySelector(".task-container").appendChild(s)}updateTasks(t,e){this.currentDayWidth=30,this.currentYear=e,this.taskList=t,this.renderChart()}}const i=(t,e)=>e.map((e=>Object.assign(Object.assign({},e),{start:r()(`${t}-${e.start}`).toString(),end:r()(`${t}-${e.end}`).toString()})));document.addEventListener("DOMContentLoaded",(()=>{const{roadmapYears:e=null,initYear:n}=window,o=document.querySelector("#tody-button");if(n===r()().year().toString()&&o&&(o.style.display="block"),e){const a=Object.keys(e).map((t=>({value:String(Number(t)),label:Number(t)})));new t("#year-dropdown",a,{onClickItem:t=>{document.querySelector("#year-dropdown").textContent=t,o.style.display=t===r()().year().toString()?"block":"none";const n=i(t,e[t]);l.updateTasks(n,Number(t))}});const d=i(n,e[n]),l=new s("#gantt-container",d);null==o||o.addEventListener("click",(()=>l.centerOnCurrentDay()))}}))})()})();