@taskgenius/calendar
Version:
A lightweight, configurable TypeScript calendar component with drag-and-drop support
1 lines • 61.7 kB
JavaScript
"use strict";const t=require("./adapters/native.cjs"),e=require("./adapters/dayjs.cjs");function n(t,e,n){const i=document.createElement(t);if(e&&(i.className=e),n)for(const[a,s]of Object.entries(n))i.setAttribute(a,s);return i}function i(t,e){Object.assign(t.style,e)}function a(t){t.innerHTML=""}function s(t,e=document){return e.querySelectorAll(t)}class r{constructor(t,e,n,i,a=60,s){this.adapter=t,this.config=e,this.onDrop=n,this.onResize=i,this.cellHeight=a,this.dateFormats=s,this.state=null,this.proxyElement=null,this.boundOnMove=this.onMove.bind(this),this.boundOnUp=this.onUp.bind(this)}resolveCellWidth(t,e){const n=t.getBoundingClientRect().width,i=parseFloat(getComputedStyle(t).width||"0")||0;return(t.offsetWidth||n||i||e||1)/Math.max(e,1)}getAllDayColumnCount(t){const e=getComputedStyle(t).getPropertyValue("--tg-allday-columns");return parseInt(e,10)||7}initMonthDrag(t,e,n){this.config.enabled&&(t.onmousedown=i=>{if(0!==i.button)return;if(!this.config.enabled)return;i.stopPropagation();const a=t.closest(".tg-month-row"),s=t.closest(".tg-allday-events-container");let r,o;if(a)o=7,r=this.resolveCellWidth(a,o);else{if(!s)return;o=this.getAllDayColumnCount(s),r=this.resolveCellWidth(s,o)}let d="move";const l=i.target;l.classList.contains("tg-left")&&(d="resize-left"),l.classList.contains("tg-right")&&(d="resize-right");const h=this.adapter.parse(e.start),c=this.adapter.parse(e.end),p=this.adapter.diff(this.adapter.startOf(c,"day"),this.adapter.startOf(h,"day"),"day")+1,g=t.getBoundingClientRect(),u=i.clientX-g.left,v=g.width||r,m=Math.max(0,Math.min(p-1,Math.floor(u/v*p)));this.startDrag({type:"month",mode:d,event:e,startX:i.clientX,startY:i.clientY,startDate:h,endDate:c,cellW:r,renderCallback:n,clickOffsetDays:m})})}initTimeDrag(t,e,n){this.config.enabled&&(t.onmousedown=i=>{if(0!==i.button)return;if(!this.config.enabled)return;i.stopPropagation();const a=t.closest(".tg-day-column");if(!a)return;const s=a.getBoundingClientRect();let r="move";const o=i.target;o.classList.contains("tg-resize-v")&&(r=o.classList.contains("tg-top")?"resize-top":"resize-bottom");const d=this.adapter.parse(e.start),l=this.adapter.parse(e.end);this.startDrag({type:"time",mode:r,event:e,startX:i.clientX,startY:i.clientY,startDate:d,endDate:l,colW:s.width,renderCallback:n,origStartMin:60*this.adapter.hour(d)+this.adapter.minute(d),origDuration:this.adapter.diff(l,d,"minute")})})}setCellHeight(t){this.cellHeight=t}isDragging(){return null!==this.state}destroy(){document.removeEventListener("mousemove",this.boundOnMove),document.removeEventListener("mouseup",this.boundOnUp),this.removeProxy(),this.state=null}startDrag(t){this.state=t,document.body.style.cursor="grabbing",s(`[data-eid="${t.event.id}"]`).forEach(t=>{t.classList.add("tg-is-dragging-source")}),this.createProxy(t.event),document.addEventListener("mousemove",this.boundOnMove),document.addEventListener("mouseup",this.boundOnUp)}createProxy(t){this.proxyElement=document.getElementById("tg-drag-proxy"),this.proxyElement||(this.proxyElement=n("div",void 0,{id:"tg-drag-proxy"}),document.body.appendChild(this.proxyElement)),this.proxyElement.textContent=t.title,i(this.proxyElement,{backgroundColor:t.color||"#3b82f6",color:"white",padding:"4px 8px",fontSize:"12px"})}removeProxy(){this.proxyElement&&(this.proxyElement.style.visibility="hidden")}onMove(t){this.state&&(this.proxyElement&&i(this.proxyElement,{visibility:"visible",left:`${t.clientX+10}px`,top:`${t.clientY+10}px`,transform:"none"}),"month"===this.state.type?this.handleMonthMove(t):this.handleTimeMove(t))}handleMonthMove(t){var e,n;const i=this.state,a=null==(e=document.elementFromPoint(t.clientX,t.clientY))?void 0:e.closest(".tg-month-row"),s=null==(n=document.elementFromPoint(t.clientX,t.clientY))?void 0:n.closest(".tg-allday-events-container");let r;if(null==a?void 0:a.dataset.date){const e=this.adapter.parse(a.dataset.date),n=a.getBoundingClientRect(),i=n.width/7,s=Math.floor((t.clientX-n.left)/(i||1));r=this.adapter.add(e,Math.max(0,Math.min(6,s)),"day")}else{if(!s)return;{const e=s.getBoundingClientRect(),n=this.getAllDayColumnCount(s),i=e.width/n,a=Math.floor((t.clientX-e.left)/i),o=s.closest(".tg-time-view, .tg-calendar");if(!o)return;const d=o.querySelector(".tg-day-column[data-date]");if(!(null==d?void 0:d.dataset.date))return;{const t=this.adapter.parse(d.dataset.date);r=this.adapter.add(t,Math.max(0,Math.min(n-1,a)),"day")}}}let o=i.startDate,d=i.endDate;if("move"===i.mode){const t=this.adapter.startOf(i.startDate,"day"),e=this.adapter.startOf(i.endDate,"day"),n=this.adapter.diff(e,t,"day"),a=i.clickOffsetDays||0,s=this.adapter.add(r,-a,"day");if(this.config.dateOnly){const e=this.adapter.diff(s,t,"day");o=this.adapter.add(i.startDate,e,"day"),d=this.adapter.add(i.endDate,e,"day")}else{const t=this.adapter.hour(i.startDate),e=this.adapter.minute(i.startDate),a=this.adapter.hour(i.endDate),r=this.adapter.minute(i.endDate);o=this.adapter.setMinute(this.adapter.setHour(s,t),e),d=this.adapter.setMinute(this.adapter.setHour(this.adapter.add(s,n,"day"),a),r)}}else if("resize-right"===i.mode){if(o=i.startDate,this.config.dateOnly){const t=this.adapter.hour(i.endDate),e=this.adapter.minute(i.endDate);d=this.adapter.setMinute(this.adapter.setHour(r,t),e),this.adapter.isSame(d,o,"day")&&this.adapter.isBefore(d,o)&&(d=this.adapter.setMinute(this.adapter.setHour(r,23),59))}else d=r;this.adapter.isBefore(d,o)&&(d=o)}else if("resize-left"===i.mode){if(d=i.endDate,this.config.dateOnly){const t=this.adapter.hour(i.startDate),e=this.adapter.minute(i.startDate);o=this.adapter.setMinute(this.adapter.setHour(r,t),e),this.adapter.isSame(o,d,"day")&&this.adapter.isAfter(o,d)&&(o=this.adapter.setMinute(this.adapter.setHour(r,0),0))}else o=r;this.adapter.isAfter(o,d)&&(o=d)}this.renderMonthGhost(o,d),i.tentativeStart=o,i.tentativeEnd=d}handleTimeMove(t){var e;const n=this.state,i=null==(e=document.elementFromPoint(t.clientX,t.clientY))?void 0:e.closest(".tg-day-column");if(!(null==i?void 0:i.dataset.date))return;const a=this.adapter.parse(i.dataset.date),s=i.getBoundingClientRect(),r=(t.clientY-s.top)/this.cellHeight*60,o=this.config.dateOnly?1440:this.config.snapMinutes||15,d=Math.max(0,Math.min(1440,Math.round(r/o)*o));let l,h;if("move"===n.mode)if(this.config.dateOnly){const t=this.adapter.diff(a,n.startDate,"day");l=this.adapter.add(n.startDate,t,"day"),h=this.adapter.add(n.endDate,t,"day")}else l=this.adapter.setMinute(this.adapter.setHour(a,0),d),h=this.adapter.add(l,n.origDuration||60,"minute");else if("resize-top"===n.mode){if(h=n.endDate,this.config.dateOnly){const t=this.adapter.diff(a,n.startDate,"day");l=this.adapter.add(n.startDate,t,"day")}else if(this.adapter.isSame(a,n.endDate,"day")){const t=60*this.adapter.hour(n.endDate)+this.adapter.minute(n.endDate),e=Math.min(t-15,d);l=this.adapter.setMinute(this.adapter.setHour(a,0),e)}else l=this.adapter.setMinute(this.adapter.setHour(a,0),d);this.adapter.isAfter(l,h)&&(l=h)}else if(this.config.dateOnly){l=n.startDate;const t=this.adapter.diff(a,n.endDate,"day");h=this.adapter.add(n.endDate,t,"day")}else if(l=n.startDate,this.adapter.isSame(a,n.startDate,"day")){const t=Math.max((n.origStartMin||0)+15,d);h=this.adapter.setMinute(this.adapter.setHour(a,0),t)}else h=n.endDate;this.renderTimeGhost(l,h),n.tentativeStart=l,n.tentativeEnd=h}renderMonthGhost(t,e){var a,r;s(".tg-ghost-event").forEach(t=>t.remove());const o=s(".tg-month-row");if(o.length>0){const a=7,s=100/a;for(const r of o){if(!r.dataset.date)continue;const o=this.adapter.parse(r.dataset.date),d=this.adapter.add(o,a-1,"day");if(!this.adapter.isBefore(e,o)&&!this.adapter.isAfter(t,d)){const a=this.adapter.isBefore(t,o)?o:t,l=this.adapter.isAfter(e,d)?d:e,h=this.adapter.diff(a,o,"day"),c=this.adapter.diff(l,a,"day")+1,p=h*s,g=c*s,u=h+c-1,v=r.querySelectorAll(".tg-event-bar");let m=26;for(const t of v){const e=t.style.left.match(/calc\(\s*([\d.]+)%/),n=t.style.width.match(/calc\(\s*([\d.]+)%/);if(!(null==e?void 0:e[1])||!(null==n?void 0:n[1]))continue;const i=parseFloat(e[1]),a=parseFloat(n[1]),r=Math.round(i/s),o=Math.round(a/s);if(r<=u&&r+o-1>=h){const e=parseFloat(t.style.top)||0,n=t.offsetHeight||26;m=Math.max(m,e+n)}}const f=n("div","tg-ghost-event");i(f,{left:`calc(${p}% + 2px)`,width:`calc(${g}% - 4px)`,top:`${m+2}px`,height:"26px"}),r.appendChild(f)}}}else{const s=document.querySelector(".tg-allday-events-container");if(!s)return;const o=this.getAllDayColumnCount(s),d=s.closest(".tg-time-view, .tg-calendar");if(!d)return;const l=Array.from(d.querySelectorAll(".tg-day-column[data-date]"));if(0===l.length)return;const h=null==(a=l[0])?void 0:a.dataset.date,c=null==(r=l[l.length-1])?void 0:r.dataset.date;if(!h||!c)return;const p=this.adapter.parse(h),g=this.adapter.parse(c);if(!this.adapter.isBefore(e,p,"day")&&!this.adapter.isAfter(t,g,"day")){const a=this.adapter.isBefore(t,p)?p:t,r=this.adapter.isAfter(e,g)?g:e,d=this.adapter.diff(a,p,"day"),l=this.adapter.diff(r,a,"day")+1,h=100/o,c=d*h,u=l*h,v=d+l-1,m=s.querySelectorAll(".tg-allday-event");let f=0;for(const t of m){const e=t.style.left.match(/calc\(\s*([\d.]+)%/),n=t.style.width.match(/calc\(\s*([\d.]+)%/);if(!(null==e?void 0:e[1])||!(null==n?void 0:n[1]))continue;const i=parseFloat(e[1]),a=parseFloat(n[1]),s=Math.round(i/h),r=Math.round(a/h);if(s<=v&&s+r-1>=d){const e=parseFloat(t.style.top)||0,n=t.offsetHeight||22;f=Math.max(f,e+n)}}const y=n("div","tg-ghost-event");i(y,{left:`calc(${c}% + 2px)`,width:`calc(${u}% - 4px)`,top:`${f+4}px`,height:"22px"}),s.appendChild(y)}}}renderTimeGhost(t,e){s(".tg-ghost-event").forEach(t=>t.remove());const a=this.adapter.format(t,this.dateFormats.date),r=document.querySelector(`.tg-day-column[data-date="${a}"]`);if(!r)return;const o=(60*this.adapter.hour(t)+this.adapter.minute(t))*(this.cellHeight/60),d=this.adapter.diff(e,t,"minute")*(this.cellHeight/60),l=n("div","tg-ghost-event");i(l,{top:`${o}px`,height:`${d}px`,width:"90%",left:"5%"}),l.textContent=`${this.adapter.format(t,this.dateFormats.time)} - ${this.adapter.format(e,this.dateFormats.time)}`,i(l,{color:"#3b82f6",fontSize:"10px",padding:"2px"}),r.appendChild(l)}onUp(t){if(!this.state)return;const e=this.state;if(document.body.style.cursor="",this.removeProxy(),s(".tg-ghost-event").forEach(t=>t.remove()),s(".tg-is-dragging-source").forEach(t=>{t.classList.remove("tg-is-dragging-source")}),document.removeEventListener("mousemove",this.boundOnMove),document.removeEventListener("mouseup",this.boundOnUp),e.tentativeStart&&e.tentativeEnd){const t=this.toDate(e.tentativeStart),n=this.toDate(e.tentativeEnd);"move"===e.mode?this.onDrop(e.event,t,n):this.onResize(e.event,t,n),e.renderCallback()}this.state=null}toDate(t){return new Date(this.adapter.year(t),this.adapter.month(t),this.adapter.date(t),this.adapter.hour(t),this.adapter.minute(t))}}class o{constructor(t){this.events=[],t&&(this.events=[...t])}addEvent(t){this.events.push(t)}removeEvent(t){const e=this.events.findIndex(e=>e.id===t);return e>-1&&(this.events.splice(e,1),!0)}updateEvent(t,e){const n=this.events.find(e=>e.id===t);return!!n&&(Object.assign(n,e),!0)}getEvents(){return[...this.events]}findEvent(t){return this.events.find(e=>e.id===t)}clear(){this.events=[]}setEvents(t){this.events=[...t]}get count(){return this.events.length}}class d{constructor(t,e,n,i,a){this.adapter=t,this.config=e,this.dragController=n,this.currentView=i,this.eventManager=a,this.container=null,this.rangeState=null,this.boundHandleClick=this.handleClick.bind(this),this.boundHandleDblClick=this.handleDblClick.bind(this),this.boundHandleContextMenu=this.handleContextMenu.bind(this),this.boundHandleMouseDown=this.handleMouseDown.bind(this),this.boundHandleRangeMove=this.handleRangeMove.bind(this),this.boundHandleRangeEnd=this.handleRangeEnd.bind(this)}init(t){this.destroy(),this.container=t,t.addEventListener("click",this.boundHandleClick),t.addEventListener("dblclick",this.boundHandleDblClick),t.addEventListener("contextmenu",this.boundHandleContextMenu),t.addEventListener("mousedown",this.boundHandleMouseDown)}destroy(){this.container&&(this.container.removeEventListener("click",this.boundHandleClick),this.container.removeEventListener("dblclick",this.boundHandleDblClick),this.container.removeEventListener("contextmenu",this.boundHandleContextMenu),this.container.removeEventListener("mousedown",this.boundHandleMouseDown)),document.removeEventListener("mousemove",this.boundHandleRangeMove),document.removeEventListener("mouseup",this.boundHandleRangeEnd),this.clearRangePreview(),this.rangeState=null,this.container=null}handleClick(t){const e=t.target;if(!e.closest(".tg-event-block, .tg-event-bar")){if("month"===this.currentView()){const t=e.closest(".tg-month-cell");if(t)return void this.handleDateClick(t)}if("week"===this.currentView()||"day"===this.currentView()){const n=e.closest(".tg-day-column");if(n&&!e.closest(".tg-event-block"))return void this.handleTimeSlotClick(t,n)}}}handleDblClick(t){var e,n,i,a,s,r;const o=t.target,d=o.closest(".tg-event-block, .tg-event-bar");if(d){const t=d.getAttribute("data-eid"),i=this.getEventById(t);return void(i&&(null==(n=(e=this.config).onEventDoubleClick)||n.call(e,i)))}if("month"===this.currentView()){const t=o.closest(".tg-month-cell");if(t){const e=this.getDateFromCell(t);return void(e&&(null==(a=(i=this.config).onDateDoubleClick)||a.call(i,this.toDate(e))))}}if("week"===this.currentView()||"day"===this.currentView()){const e=o.closest(".tg-day-column");if(e&&!o.closest(".tg-event-block")){const n=this.getDateTimeFromSlot(t,e);return void(n&&(null==(r=(s=this.config).onTimeSlotDoubleClick)||r.call(s,this.toDate(n))))}}}handleContextMenu(t){const e=t.target;if(!(this.config.onEventContextMenu||this.config.onDateContextMenu||this.config.onTimeSlotContextMenu))return;const n=e.closest(".tg-event-block, .tg-event-bar");if(n&&this.config.onEventContextMenu){t.preventDefault();const e=n.getAttribute("data-eid"),i=this.getEventById(e);return void(i&&this.config.onEventContextMenu(i,t.clientX,t.clientY))}if("month"===this.currentView()&&this.config.onDateContextMenu){const n=e.closest(".tg-month-cell");if(n){t.preventDefault();const e=this.getDateFromCell(n);return void(e&&this.config.onDateContextMenu(this.toDate(e),t.clientX,t.clientY))}}if(("week"===this.currentView()||"day"===this.currentView())&&this.config.onTimeSlotContextMenu){const n=e.closest(".tg-day-column");if(n&&!e.closest(".tg-event-block")){t.preventDefault();const e=this.getDateTimeFromSlot(t,n);return void(e&&this.config.onTimeSlotContextMenu(this.toDate(e),t.clientX,t.clientY))}}}handleMouseDown(t){if(0!==t.button)return;const e=t.target;if(e.closest(".tg-event-block, .tg-event-bar"))return;if(this.dragController.isDragging())return;if(this.config.onDateRangeSelect||this.config.onTimeRangeSelect){if("month"===this.currentView()&&this.config.onDateRangeSelect){const n=e.closest(".tg-month-cell");if(!n)return;const i=this.getDateFromCell(n);if(!i)return;return this.rangeState={isSelecting:!0,startDate:i,startX:t.clientX,startY:t.clientY,currentDate:i,viewType:"month"},document.addEventListener("mousemove",this.boundHandleRangeMove),document.addEventListener("mouseup",this.boundHandleRangeEnd),void(this.container&&this.container.classList.add("tg-selecting"))}if(("week"===this.currentView()||"day"===this.currentView())&&this.config.onTimeRangeSelect){const n=e.closest(".tg-day-column");if(!n)return;const i=this.getDateTimeFromSlot(t,n);if(!i)return;return this.rangeState={isSelecting:!0,startDate:i,startX:t.clientX,startY:t.clientY,currentDate:i,viewType:"time",columnEl:n},document.addEventListener("mousemove",this.boundHandleRangeMove),document.addEventListener("mouseup",this.boundHandleRangeEnd),void(this.container&&this.container.classList.add("tg-selecting"))}}}handleRangeMove(t){var e;if(!(null==(e=this.rangeState)?void 0:e.isSelecting))return;const n=document.elementFromPoint(t.clientX,t.clientY);if(n)if("month"===this.rangeState.viewType){const t=n.closest(".tg-month-cell");if(t){const e=this.getDateFromCell(t);e&&(this.rangeState.currentDate=e,this.renderMonthRangePreview())}}else{const e=n.closest(".tg-day-column");if(e){const n=this.getDateTimeFromSlot(t,e);n&&(this.rangeState.currentDate=n,this.renderTimeRangePreview())}}}handleRangeEnd(t){var e,n,i,a,s;if(null==(e=this.rangeState)?void 0:e.isSelecting){if(document.removeEventListener("mousemove",this.boundHandleRangeMove),document.removeEventListener("mouseup",this.boundHandleRangeEnd),this.container&&this.container.classList.remove("tg-selecting"),this.rangeState.startDate&&this.rangeState.currentDate){const t=this.rangeState.startDate,e=this.rangeState.currentDate,r=this.adapter.isAfter(t,e);if("month"===this.rangeState.viewType){const a=this.toDate(r?e:t),s=this.toDate(r?t:e);null==(i=(n=this.config).onDateRangeSelect)||i.call(n,a,s)}else{const n=this.toDate(r?e:t),i=this.toDate(r?t:e);null==(s=(a=this.config).onTimeRangeSelect)||s.call(a,n,i)}}this.clearRangePreview(),this.rangeState=null}}toDate(t){return new Date(this.adapter.year(t),this.adapter.month(t),this.adapter.date(t),this.adapter.hour(t),this.adapter.minute(t))}getEventById(t){if(t)return this.eventManager.findEvent(t)}getDateFromCell(t){const e=t.closest(".tg-month-row");if(!(null==e?void 0:e.dataset.date))return null;const n=Array.from(e.querySelectorAll(".tg-month-cell")).indexOf(t);if(n<0)return null;const i=this.adapter.parse(e.dataset.date);return this.adapter.add(i,n,"day")}getDateTimeFromSlot(t,e){const n=e.dataset.date;if(!n)return null;const i=e.getBoundingClientRect(),a=t.clientY-i.top,s=this.config.theme.cellHeight,r=this.config.draggable.snapMinutes,o=a/s*60,d=Math.max(0,Math.min(1440,Math.round(o/r)*r)),l=this.adapter.parse(n);return this.adapter.setMinute(this.adapter.setHour(l,Math.floor(d/60)),d%60)}handleDateClick(t){var e,n;const i=this.getDateFromCell(t);i&&(null==(n=(e=this.config).onDateClick)||n.call(e,this.toDate(i)))}handleTimeSlotClick(t,e){var n,i;const a=this.getDateTimeFromSlot(t,e);a&&(null==(i=(n=this.config).onTimeSlotClick)||i.call(n,this.toDate(a)))}renderMonthRangePreview(){var t,e;if(!(null==(t=this.rangeState)?void 0:t.startDate)||!(null==(e=this.rangeState)?void 0:e.currentDate))return;this.clearRangePreview();const n=this.adapter.isBefore(this.rangeState.startDate,this.rangeState.currentDate)?this.rangeState.startDate:this.rangeState.currentDate,i=this.adapter.isAfter(this.rangeState.startDate,this.rangeState.currentDate)?this.rangeState.startDate:this.rangeState.currentDate,a=s(".tg-month-row");for(const s of a){if(!s.dataset.date)continue;const t=this.adapter.parse(s.dataset.date),e=Array.from(s.querySelectorAll(".tg-month-cell")),a=this.adapter.add(t,e.length-1,"day");if(!this.adapter.isBefore(i,t)&&!this.adapter.isAfter(n,a))for(let s=0;s<e.length;s++){const a=this.adapter.add(t,s,"day");if(!this.adapter.isBefore(a,n)&&!this.adapter.isAfter(a,i)){const t=e[s];t&&t.classList.add("tg-range-preview")}}}}renderTimeRangePreview(){var t,e;if(!(null==(t=this.rangeState)?void 0:t.startDate)||!(null==(e=this.rangeState)?void 0:e.currentDate))return;this.clearRangePreview();const a=this.adapter.isBefore(this.rangeState.startDate,this.rangeState.currentDate)?this.rangeState.startDate:this.rangeState.currentDate,r=this.adapter.isAfter(this.rangeState.startDate,this.rangeState.currentDate)?this.rangeState.startDate:this.rangeState.currentDate;if(this.adapter.isSame(a,r,"day")){const t=s(".tg-day-column");let e=null;for(const n of t){const t=n.dataset.date;if(t){const i=this.adapter.parse(t);if(this.adapter.isSame(i,a,"day")){e=n;break}}}if(!e)return;const o=60*this.adapter.hour(a)+this.adapter.minute(a),d=60*this.adapter.hour(r)+this.adapter.minute(r),l=this.config.theme.cellHeight,h=o/60*l,c=(d-o)/60*l,p=n("div","tg-time-range-preview");i(p,{top:`${h}px`,height:`${Math.max(c,l/4)}px`,width:"100%",left:"0"}),e.appendChild(p)}else{const t=s(".tg-day-column");for(const e of t){const t=e.dataset.date;if(!t)continue;const n=this.adapter.parse(t);this.adapter.isBefore(n,a,"day")||this.adapter.isAfter(n,r,"day")||e.classList.add("tg-range-preview")}}}clearRangePreview(){s(".tg-time-range-preview").forEach(t=>t.remove()),s(".tg-range-preview").forEach(t=>{t.classList.remove("tg-range-preview")})}}function l(t,e){t.style.setProperty("--tg-primary-color",e.primaryColor),t.style.setProperty("--tg-primary-rgb",function(t){const e=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t);if(e)return`${parseInt(e[1],16)}, ${parseInt(e[2],16)}, ${parseInt(e[3],16)}`;return"59, 130, 246"}(e.primaryColor)),t.style.setProperty("--tg-cell-height",`${e.cellHeight}px`),t.style.setProperty("--tg-font-header",e.fontSize.header),t.style.setProperty("--tg-font-event",e.fontSize.event)}const h="yyyy-MM-dd",c="yyyy-MM-dd HH:mm",p="HH:mm",g="yyyy年 M月",u="yyyy年M月d日",v="yyyy-MM-dd",m="yyyy-MM-dd HH:mm";class f{constructor(){this.mounted=!1}init(t){this.context=t}onMount(){this.mounted=!0}onUnmount(){this.mounted=!1}onEventsUpdate(t){return!1}onDateChange(t){return!1}getNavigationUnit(){return"month"}getHeaderTitle(){const t="day"===this.getNavigationUnit()?this.context.config.dateFormats.dayHeader:this.context.config.dateFormats.monthHeader;return this.context.adapter.format(this.context.currentDate,t)}isMounted(){return this.mounted}getMeta(){return this.constructor.meta}}class y{constructor(){this.views=new Map}register(t,e={}){if(!(t.prototype instanceof f)&&t!==f)throw new Error(`View class must extend BaseView. Got: ${t.name||"anonymous class"}`);const n=t.meta;if(!n||"object"!=typeof n)throw new Error(`View class '${t.name||"anonymous"}' must have a static 'meta' property of type ViewMeta`);if(!n.type||"string"!=typeof n.type)throw new Error(`View class '${t.name||"anonymous"}' meta must have a 'type' string property`);if(!n.label||"string"!=typeof n.label)throw new Error(`View class '${t.name||"anonymous"}' meta must have a 'label' string property`);if(this.views.has(n.type)&&!e.override)throw new Error(`View type '${n.type}' is already registered. Use { override: true } to replace.`);this.views.set(n.type,{ctor:t,meta:{...n}})}unregister(t){return this.views.delete(t)}has(t){return this.views.has(t)}getMeta(t){var e;return null==(e=this.views.get(t))?void 0:e.meta}create(t){const e=this.views.get(t);if(e)return new e.ctor}getAll(){return Array.from(this.views.values()).map(t=>t.meta).sort((t,e)=>{const n=t.order??50,i=e.order??50;return n!==i?n-i:t.type.localeCompare(e.type)})}getTypes(){return Array.from(this.views.keys())}clear(){this.views.clear()}get size(){return this.views.size}}class w{constructor(t,e=0,n=!0,i){this.adapter=t,this.firstDayOfWeek=e,this.showWeekends=n,this.dateFormats=i}generateGrid(t,e){const n=this.adapter.startOf(t,"month"),i=this.adapter.endOf(t,"month"),a=this.adapter.create();let s=this.adapter.startOf(n,"week");const r=this.adapter.day(s);if(r!==this.firstDayOfWeek){let t=this.firstDayOfWeek-r;t>0&&(t-=7),s=this.adapter.add(s,t,"day")}let o=this.adapter.endOf(i,"week");const d=this.adapter.day(o),l=(this.firstDayOfWeek+6)%7;if(d!==l){const t=(l-d+7)%7;t>0&&(o=this.adapter.add(o,t,"day"))}const h=[];let c=s;for(;this.adapter.isBefore(c,o)||this.adapter.isSame(c,o,"day");){const n=[];for(let i=0;i<7;i++){const i=this.adapter.day(c),s=0===i||6===i,r={isWeekend:s,dayOfWeek:i,isToday:this.adapter.isSame(c,a,"day"),isThisMonth:this.adapter.isSame(c,t,"month")};let o=!0;if(e){const t=e(c,r);o="boolean"==typeof t?t:t.visible}else!this.showWeekends&&s&&(o=!1);o&&n.push({date:c,dateStr:this.adapter.format(c,this.dateFormats.date)}),c=this.adapter.add(c,1,"day")}n.length>0&&h.push(n)}return h}calculateLayoutWithVisibleDays(t,e){if(0===e.length)return[];const n=e[0].date,i=e[e.length-1].date,a=t.filter(t=>{const e=this.adapter.startOf(this.adapter.parse(t.start),"day"),a=this.adapter.startOf(this.adapter.parse(t.end),"day");return!this.adapter.isAfter(e,i,"day")&&!this.adapter.isBefore(a,n,"day")}),s=[];for(const o of a){const t=this.adapter.startOf(this.adapter.parse(o.start),"day"),n=this.adapter.startOf(this.adapter.parse(o.end),"day"),i=[];for(const s of e)s.disabled||this.adapter.isBefore(s.date,t,"day")||this.adapter.isAfter(s.date,n,"day")||i.push({colIndex:s.colIndex,date:s.date,dateStr:s.dateStr});if(0===i.length)continue;const a=[];let r=i[0],d=r,l=1;for(let e=1;e<i.length;e++){const s=i[e],o=this.adapter.add(d.date,1,"day");if(this.adapter.isSame(s.date,o,"day"))l++,d=s;else{const e=this.adapter.isSame(r.date,t,"day"),i=this.adapter.isSame(d.date,n,"day");a.push({startIdx:r.colIndex,span:l,isEventStart:e,isEventEnd:i}),r=s,d=s,l=1}}const h=this.adapter.isSame(r.date,t,"day"),c=this.adapter.isSame(d.date,n,"day");a.push({startIdx:r.colIndex,span:l,isEventStart:h,isEventEnd:c});const p=a.length;a.forEach((t,e)=>{const n={event:o,startIdx:t.startIdx,span:t.span,slot:0,isStart:t.isEventStart,isEnd:t.isEventEnd,sortKey:1e3*t.startIdx-t.span,...p>1?{segmentIndex:e,totalSegments:p}:{}};s.push(n)})}s.sort((t,e)=>t.sortKey-e.sortKey);const r=[];for(const o of s){let t=0;for(;;){const e=r[t];if(void 0===e||e<o.startIdx){r[t]=o.startIdx+o.span-1,o.slot=t;break}t++}}return s.map(({sortKey:t,...e})=>e)}calculateLayout(t,e,n){const i=[];let a=e,s=0;for(;this.adapter.isBefore(a,n,"day")||this.adapter.isSame(a,n,"day");){const t=this.adapter.day(a),e=0===t||6===t;!this.showWeekends&&e||(i.push({date:a,dateStr:this.adapter.format(a,this.dateFormats.date),colIndex:s}),s++),a=this.adapter.add(a,1,"day")}return this.calculateLayoutWithVisibleDays(t,i)}getWeekCount(t){return this.generateGrid(t).length}}class x{constructor(t,e,n,i=!1,a,s,r,o,d,l){this.engine=t,this.adapter=e,this.showEventCounts=i,this.onRenderDateCell=s,this.onStyleEvent=r,this.maxEventsPerRow=o,this.onRenderMoreEventsPopover=d,this.onRenderEvent=l,this.activePopover=null,this.popoverCloseHandler=null}render(t,e,i,s,r,o,d){var l;this.closePopover(),a(t);const h=this.engine.generateGrid(e,d),c=this.renderHeader((null==(l=h[0])?void 0:l.length)||7);t.appendChild(c);const p=n("div","tg-month-body");for(const n of h){const t=this.renderWeekRow(n,e,i,s,r,o,d);p.appendChild(t)}t.appendChild(p)}renderHeader(t){const e=n("div","tg-month-header"),i=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],a=[],s=this.engine.firstDayOfWeek||0;for(let n=0;n<t;n++){const t=(s+n)%7;a.push(i[t])}e.style.setProperty("--tg-grid-columns",String(a.length)),e.style.gridTemplateColumns="repeat(var(--tg-grid-columns), 1fr)";for(const r of a){const t=n("div","tg-month-header-cell");t.textContent=r,e.appendChild(t)}return e}renderWeekRow(t,e,i,a,s,r,o){const d=n("div","tg-month-row");d.dataset.date=t[0].dateStr;const l=t.length;d.style.setProperty("--tg-grid-columns",String(t.length)),d.style.gridTemplateColumns="repeat(var(--tg-grid-columns), 1fr)";const h=t.map((t,n)=>{let i=!1;if(o){const n=this.adapter.day(t.date),a=0===n||6===n,s=this.adapter.create(),r={isWeekend:a,dayOfWeek:n,isToday:this.adapter.isSame(t.date,s,"day"),isThisMonth:this.adapter.isSame(t.date,e,"month")},d=o(t.date,r);"object"==typeof d&&d.disabled&&(i=!0)}return{date:t.date,dateStr:t.dateStr,colIndex:n,disabled:i}}),c=this.engine.calculateLayoutWithVisibleDays(i,h),p=void 0!==this.maxEventsPerRow?c.filter(t=>t.slot<this.maxEventsPerRow):c,g=new Map;if(void 0!==this.maxEventsPerRow)for(const n of c)if(n.slot>=this.maxEventsPerRow)for(let t=n.startIdx;t<n.startIdx+n.span;t++){g.has(t)||g.set(t,[]);const e=g.get(t);e.find(t=>t.id===n.event.id)||e.push(n.event)}const u=p.reduce((t,e)=>Math.max(t,e.slot),-1);let v=u>=0?26+28*(u+1):0;g.size>0&&(v+=24);const m=Math.max(80,v+8);d.style.setProperty("--tg-row-min-height",`${m}px`);const f=new Map;for(const n of i){const e=this.adapter.parse(n.start),i=this.adapter.parse(n.end);for(const a of t)this.adapter.isBefore(i,a.date)||this.adapter.isAfter(e,a.date)||(f.has(a.dateStr)||f.set(a.dateStr,[]),f.get(a.dateStr).push(n))}for(const n of t){const t=f.get(n.dateStr)||[],i=this.renderDateCell(n,e,t,o);d.appendChild(i)}for(const n of p){const t=this.renderEventBar(n,l,a,s,r);d.appendChild(t)}for(const[n,y]of g){const e=this.renderMoreIndicator(n,y,t[n],l,u,r);d.appendChild(e)}return d}renderDateCell(t,e,i,a){const s=n("div","tg-month-cell"),r=n("div","tg-date-number");r.textContent=String(this.adapter.date(t.date));const o=this.adapter.create(),d=this.adapter.isSame(t.date,o,"day"),l=this.adapter.isBefore(t.date,o,"day"),h=this.adapter.isAfter(t.date,o,"day"),c=this.adapter.month(t.date)===this.adapter.month(e),p=this.adapter.day(t.date),g={isWeekend:0===p||6===p,dayOfWeek:p,isToday:d,isThisMonth:c};if(a){const e=a(t.date,g);if("object"==typeof e){const t=e;t.className&&s.classList.add(t.className),t.style&&Object.assign(s.style,t.style),t.disabled&&s.classList.add("tg-disabled")}}if(c?r.classList.add("tg-current-month"):r.classList.add("tg-other-month"),d&&r.classList.add("tg-today"),s.appendChild(r),this.showEventCounts&&i.length>0){const t=n("div","tg-event-count-badge");t.textContent=i.length.toString(),s.appendChild(t)}if(this.onRenderDateCell){const e=new Date(this.adapter.year(t.date),this.adapter.month(t.date),this.adapter.date(t.date));this.onRenderDateCell({date:e,events:i,cellEl:s,isToday:d,isPastDue:l,isFuture:h,isThisMonth:c})}return s}renderEventBar(t,e,i,a,s){const r=n("div","tg-event-base tg-event-bar");r.dataset.eid=t.event.id,void 0!==t.segmentIndex&&void 0!==t.totalSegments&&(r.dataset.segmentIndex=String(t.segmentIndex),r.dataset.totalSegments=String(t.totalSegments),r.classList.add("tg-event-segmented"),0===t.segmentIndex&&r.classList.add("tg-event-segment-first"),t.segmentIndex===t.totalSegments-1&&r.classList.add("tg-event-segment-last"),t.segmentIndex>0&&t.segmentIndex<t.totalSegments-1&&r.classList.add("tg-event-segment-middle"));let o,d=t.event.color||"#3b82f6";if(this.onStyleEvent){const e=this.onStyleEvent(t.event);e.className&&r.classList.add(e.className),e.color&&(d=e.color),void 0!==e.opacity&&(o=e.opacity)}const l=100/e,h=t.startIdx*l,c=26+28*t.slot;r.style.left=`calc(${h}% + 2px)`,r.style.top=`${c}px`,r.style.width=`calc(${t.span*l}% - 4px)`,r.style.backgroundColor=d,void 0!==o&&(r.style.opacity=o.toString());const p=()=>{r.textContent=t.event.title};if(this.onRenderEvent){const e={event:t.event,el:r,viewType:"month",isAllDay:!0,isStart:t.isStart,isEnd:t.isEnd,defaultRender:p};void 0!==t.segmentIndex&&(e.segmentIndex=t.segmentIndex),void 0!==t.totalSegments&&(e.totalSegments=t.totalSegments),this.onRenderEvent(e)}else p();if(t.isStart){const t=n("div","tg-resize-handle tg-resize-h tg-left");r.appendChild(t)}if(t.isEnd){const t=n("div","tg-resize-handle tg-resize-h tg-right");r.appendChild(t)}return s&&r.addEventListener("click",e=>{e.stopPropagation(),s(t.event)}),i.initMonthDrag(r,t.event,a),r}renderMoreIndicator(t,e,i,a,s,r){const o=n("div","tg-more-indicator");o.textContent=`+${e.length} more`;const d=100/a,l=t*d,h=26+28*(s+1)+2;o.style.left=`calc(${l}% + 2px)`,o.style.top=`${h}px`,o.style.width=`calc(${d}% - 4px)`;const c=new Date(this.adapter.year(i.date),this.adapter.month(i.date),this.adapter.date(i.date));return o.addEventListener("click",t=>{t.stopPropagation();const n=()=>{this.renderDefaultPopover(o,e,c,r)};this.onRenderMoreEventsPopover?this.onRenderMoreEventsPopover(e,c,o,n):n()}),o}renderDefaultPopover(t,e,i,a){this.closePopover();const s=n("div","tg-more-popover");this.activePopover=s;const r=n("div","tg-more-popover-header");r.textContent=i.toLocaleDateString(void 0,{weekday:"short",month:"short",day:"numeric"}),s.appendChild(r);const o=n("div","tg-more-popover-list");for(const d of e){const t=n("div","tg-more-popover-item");let e,i=d.color||"#3b82f6";if(this.onStyleEvent){const n=this.onStyleEvent(d);n.className&&t.classList.add(n.className),n.color&&(i=n.color),void 0!==n.opacity&&(e=n.opacity)}const s=n("span","tg-more-popover-dot");s.style.backgroundColor=i,t.appendChild(s);const r=n("span","tg-more-popover-title");r.textContent=d.title,t.appendChild(r),void 0!==e&&(t.style.opacity=e.toString()),a&&(t.addEventListener("click",t=>{t.stopPropagation(),this.closePopover(),a(d)}),t.style.cursor="pointer"),o.appendChild(t)}s.appendChild(o),document.body.appendChild(s),this.positionPopover(s,t),this.popoverCloseHandler=e=>{s.contains(e.target)||e.target===t||this.closePopover()},setTimeout(()=>{document.addEventListener("click",this.popoverCloseHandler)},0)}positionPopover(t,e){const n=e.getBoundingClientRect(),i=t.getBoundingClientRect(),a=window.innerHeight,s=window.innerWidth;let r=n.bottom+4,o=n.left;r+i.height>a-8&&(r=n.top-i.height-4),o+i.width>s-8&&(o=s-i.width-8),o<8&&(o=8),t.style.top=`${r}px`,t.style.left=`${o}px`}closePopover(){this.activePopover&&(this.activePopover.remove(),this.activePopover=null),this.popoverCloseHandler&&(document.removeEventListener("click",this.popoverCloseHandler),this.popoverCloseHandler=null)}}const C=class extends f{init(t){super.init(t),this.engine=new w(this.context.adapter,this.context.config.view.firstDayOfWeek,this.context.config.view.showWeekends,this.context.config.dateFormats),this.renderer=new x(this.engine,this.context.adapter,this.context.config.theme,this.context.config.showEventCounts,this.context.config.dateFormats,this.context.config.onRenderDateCell,this.context.config.onStyleEvent,this.context.config.view.maxEventsPerRow,this.context.config.onRenderMoreEventsPopover,this.context.config.onRenderEvent)}render(t,e,n){this.renderer.render(t,this.context.currentDate,e,this.context.dragController,this.context.requestRender,this.context.config.onEventClick,this.context.config.view.dayFilter)}getNavigationUnit(){return"month"}getEngine(){return this.engine}getRenderer(){return this.renderer}};C.meta={type:"month",label:"Month",shortLabel:"M",order:10};let D=C;class S{constructor(t,e=60,n=!0,i=0,a){this.adapter=t,this.showWeekends=n,this.firstDayOfWeek=i,this.dateFormats=a,this.cellHeight=e}generateColumns(t,e,n){const i=[],a=this.adapter.create();if("day"===e)i.push({date:t,dateStr:this.adapter.format(t,this.dateFormats.date)});else{let e=this.adapter.startOf(t,"week");const s=this.adapter.day(e);if(s!==this.firstDayOfWeek){let t=this.firstDayOfWeek-s;e=this.adapter.add(e,t,"day")}let r=e;for(let o=0;o<7;o++){const e=this.adapter.day(r),s=0===e||6===e,o={isWeekend:s,dayOfWeek:e,isToday:this.adapter.isSame(r,a,"day"),isThisMonth:this.adapter.isSame(r,t,"month")};let d=!0;if(n){const t=n(r,o);d="boolean"==typeof t?t:t.visible}else!this.showWeekends&&s&&(d=!1);d&&i.push({date:r,dateStr:this.adapter.format(r,this.dateFormats.date)}),r=this.adapter.add(r,1,"day")}}return i}generateTimeSlots(t){const e=[];for(let n=0;n<24;n++){if(!t){e.push({hour:n});continue}const i=t(n);"boolean"==typeof i?i&&e.push({hour:n}):i.visible&&e.push({hour:n,config:i})}return e}calculateLayout(t,e){const n=this.filterAndCalculateGeometry(t,e);if(0===n.length)return[];n.sort((t,e)=>t.startMin-e.startMin||e.endMin-t.endMin);const i=this.groupOverlappingEvents(n);for(const a of i)this.calculateColumnPositions(a);return n.map(t=>{const e={event:t.event,top:t.top,height:t.height,leftPercent:t.leftPercent,widthPercent:t.widthPercent,colIndex:t.colIndex,startMin:t.startMin,endMin:t.endMin,isStart:t.isStart,isEnd:t.isEnd};return void 0!==t.segmentIndex&&void 0!==t.totalSegments&&(e.segmentIndex=t.segmentIndex,e.totalSegments=t.totalSegments),e})}isSingleDayEvent(t){const e=this.adapter.parse(t.start),n=this.adapter.parse(t.end);return this.adapter.isSame(e,n,"day")}isCrossMidnightEvent(t){return!this.isAllDayEvent(t)&&!this.isSingleDayEvent(t)}getEventDaySpan(t){const e=this.adapter.startOf(this.adapter.parse(t.start),"day"),n=this.adapter.startOf(this.adapter.parse(t.end),"day");return this.adapter.diff(n,e,"day")+1}isAllDayEvent(t){const e=this.adapter.parse(t.start),n=this.adapter.parse(t.end),i=this.adapter.hour(e),a=this.adapter.minute(e),s=this.adapter.hour(n),r=this.adapter.minute(n);return 0===i&&0===a&&0===s&&0===r||0===i&&0===a&&23===s&&r>=59}calculateAllDayLayout(t,e){if(0===e.length||0===t.length)return[];const n=e[0].date,i=e[e.length-1].date,a=t.filter(t=>{const e=this.adapter.startOf(this.adapter.parse(t.start),"day"),a=this.adapter.startOf(this.adapter.parse(t.end),"day");return!this.adapter.isAfter(e,i,"day")&&!this.adapter.isBefore(a,n,"day")}),s=[];for(const o of a){const t=this.adapter.startOf(this.adapter.parse(o.start),"day"),n=this.adapter.startOf(this.adapter.parse(o.end),"day"),i=[];for(let s=0;s<e.length;s++){const a=e[s];this.adapter.isBefore(a.date,t,"day")||this.adapter.isAfter(a.date,n,"day")||i.push({colIndex:s,date:a.date,dateStr:a.dateStr})}if(0===i.length)continue;const a=[];let r=i[0],d=r,l=1;for(let e=1;e<i.length;e++){const s=i[e],o=this.adapter.add(d.date,1,"day");if(this.adapter.isSame(s.date,o,"day"))l++,d=s;else{const e=this.adapter.isSame(r.date,t,"day"),i=this.adapter.isSame(d.date,n,"day");a.push({startIdx:r.colIndex,span:l,isEventStart:e,isEventEnd:i}),r=s,d=s,l=1}}const h=this.adapter.isSame(r.date,t,"day"),c=this.adapter.isSame(d.date,n,"day");a.push({startIdx:r.colIndex,span:l,isEventStart:h,isEventEnd:c});const p=a.length;a.forEach((t,e)=>{const n={event:o,startIdx:t.startIdx,span:t.span,slot:0,isStart:t.isEventStart,isEnd:t.isEventEnd,sortKey:1e3*t.startIdx-t.span,...p>1?{segmentIndex:e,totalSegments:p}:{}};s.push(n)})}s.sort((t,e)=>t.sortKey-e.sortKey);const r=[];for(const o of s){let t=0;for(;;){const e=r[t];if(void 0===e||e<o.startIdx){r[t]=o.startIdx+o.span-1,o.slot=t;break}t++}}return s.map(({sortKey:t,...e})=>e)}setCellHeight(t){this.cellHeight=t}getCellHeight(){return this.cellHeight}filterAndCalculateGeometry(t,e){const n=[],i=this.adapter.parse(e),a=this.adapter.startOf(i,"day");for(const s of t){if(this.isAllDayEvent(s))continue;const t=this.adapter.parse(s.start),e=this.adapter.parse(s.end),i=this.adapter.startOf(t,"day"),r=this.adapter.startOf(e,"day");if(!(!this.adapter.isBefore(a,i,"day")&&!this.adapter.isAfter(a,r,"day")))continue;const o=this.adapter.isSame(a,i,"day"),d=this.adapter.isSame(a,r,"day"),l=this.adapter.diff(r,i,"day")+1,h=this.adapter.diff(a,i,"day");let c,p;if(o&&d?(c=60*this.adapter.hour(t)+this.adapter.minute(t),p=60*this.adapter.hour(e)+this.adapter.minute(e)):o?(c=60*this.adapter.hour(t)+this.adapter.minute(t),p=1440):d?(c=0,p=60*this.adapter.hour(e)+this.adapter.minute(e)):(c=0,p=1440),p<=c)continue;const g=this.cellHeight/60,u=p-c,v={event:s,top:c*g,height:Math.max(20,u*g),startMin:c,endMin:p,colIndex:0,widthPercent:100,leftPercent:0,isStart:o,isEnd:d};l>1&&(v.segmentIndex=h,v.totalSegments=l),n.push(v)}return n}groupOverlappingEvents(t){if(0===t.length)return[];const e=[];let n=[t[0]],i=t[0].endMin;for(let a=1;a<t.length;a++){const s=t[a];s.startMin<i?(n.push(s),i=Math.max(i,s.endMin)):(e.push(n),n=[s],i=s.endMin)}return e.push(n),e}calculateColumnPositions(t){const e=[];for(const s of t){let t=!1;for(let n=0;n<e.length;n++)if(e[n]<=s.startMin){e[n]=s.endMin,s.colIndex=n,t=!0;break}t||(e.push(s.endMin),s.colIndex=e.length-1)}const n=e.length;if(1===n){for(const e of t)e.widthPercent=100,e.leftPercent=0;return}const i=100/n,a=n<=3?1.6:n<=5?1.5:1.4;for(const s of t){const e=s.colIndex*i;let r=1;for(let i=s.colIndex+1;i<n;i++){if(t.some(t=>t.colIndex===i&&t.startMin<s.endMin&&t.endMin>s.startMin))break;r++}const o=i*(r-1+a),d=100-e;s.leftPercent=e,s.widthPercent=Math.min(o,d),s.colIndex+r===n&&(s.widthPercent=d)}}}class E{constructor(t,e,n,i,a,s,r,o){this.engine=t,this.adapter=e,this.theme=n,this.dateFormats=i,this.onStyleEvent=a,this.onRenderEvent=s,this.maxEventsPerRow=r,this.onRenderMoreEventsPopover=o,this.currentViewType="week",this.activePopover=null,this.popoverCloseHandler=null}render(t,e,i,s,r,o,d,l,h,c,p){this.currentViewType=i,a(t);const g=this.engine.generateColumns(e,i,h),u=this.engine.generateTimeSlots(c),v=s.filter(t=>this.engine.isAllDayEvent(t)),m=s.filter(t=>!this.engine.isAllDayEvent(t)),f=this.renderHeader(g,e,h);if(t.appendChild(f),v.length>0){const e=this.renderAllDaySection(g,v,r,o,d);t.appendChild(e)}const y=n("div","tg-time-grid-container"),w=n("div","tg-time-body"),x=this.renderTimeAxis(u,p);w.appendChild(x);for(const n of g){const t=this.renderDayColumn(n,m,r,o,d,u);w.appendChild(t)}y.appendChild(w),t.appendChild(y);const C=()=>{if(null!=l)y.scrollTop=l;else{const t=8,e=u.findIndex(e=>e.hour>=t);e>=0&&(y.scrollTop=e*this.theme.cellHeight)}};t.isConnected?C():requestAnimationFrame(C)}renderHeader(t,e,i){const a=n("div","tg-time-header"),s=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],r=this.adapter.create();for(const o of t){const t=n("div","tg-time-header-cell"),d=this.adapter.day(o.date),l=0===d||6===d,h=this.adapter.isSame(o.date,r,"day"),c={isWeekend:l,dayOfWeek:d,isToday:h,isThisMonth:this.adapter.isSame(o.date,e,"month")};if(i){const e=i(o.date,c);if("object"==typeof e){const n=e;n.className&&t.classList.add(n.className),n.style&&Object.assign(t.style,n.style),n.disabled&&t.classList.add("tg-disabled")}}h&&!i&&t.classList.add("tg-today");const p=s[d],g=this.adapter.date(o.date),u=n("div");u.textContent=p;const v=n("div","tg-header-date");v.textContent=String(g),t.appendChild(u),t.appendChild(v),a.appendChild(t)}return a}renderAllDaySection(t,e,i,a,s){const r=n("div","tg-allday-section"),o=n("div","tg-allday-spacer");r.appendChild(o);const d=n("div","tg-allday-events-container");d.style.setProperty("--tg-allday-columns",String(t.length));const l=this.engine.calculateAllDayLayout(e,t),h=void 0!==this.maxEventsPerRow?l.filter(t=>t.slot<this.maxEventsPerRow):l,c=new Map;if(void 0!==this.maxEventsPerRow)for(const n of l)if(n.slot>=this.maxEventsPerRow)for(let t=n.startIdx;t<n.startIdx+n.span;t++){c.has(t)||c.set(t,[]);const e=c.get(t);e.find(t=>t.id===n.event.id)||e.push(n.event)}const p=h.reduce((t,e)=>Math.max(t,e.slot),-1);let g=p>=0?8+26*(p+1):0;c.size>0&&(g+=22),d.style.height=`${Math.max(g,28)}px`;for(const n of h){const e=this.renderAllDayEventBar(n,t.length,i,a,s);d.appendChild(e)}for(const[n,u]of c){const e=this.renderAllDayMoreIndicator(n,u,t[n],t.length,p,s);d.appendChild(e)}return r.appendChild(d),r}renderAllDayEventBar(t,e,i,a,s){const r=n("div","tg-event-base tg-allday-event");r.dataset.eid=t.event.id,void 0!==t.segmentIndex&&void 0!==t.totalSegments&&(r.dataset.segmentIndex=String(t.segmentIndex),r.dataset.totalSegments=String(t.totalSegments),r.classList.add("tg-event-segmented"),0===t.segmentIndex&&r.classList.add("tg-event-segment-first"),t.segmentIndex===t.totalSegments-1&&r.classList.add("tg-event-segment-last"),t.segmentIndex>0&&t.segmentIndex<t.totalSegments-1&&r.classList.add("tg-event-segment-middle"));let o,d=t.event.color||"#3b82f6";if(this.onStyleEvent){const e=this.onStyleEvent(t.event);e.className&&r.classList.add(e.className),e.color&&(d=e.color),void 0!==e.opacity&&(o=e.opacity)}const l=100/e,h=t.startIdx*l,c=4+26*t.slot;r.style.left=`calc(${h}% + 2px)`,r.style.top=`${c}px`,r.style.width=`calc(${t.span*l}% - 4px)`,r.style.backgroundColor=d,void 0!==o&&(r.style.opacity=o.toString());const p=()=>{r.textContent=t.event.title};if(this.onRenderEvent){const e={event:t.event,el:r,viewType:this.currentViewType,isAllDay:!0,isStart:t.isStart,isEnd:t.isEnd,defaultRender:p};void 0!==t.segmentIndex&&(e.segmentIndex=t.segmentIndex),void 0!==t.totalSegments&&(e.totalSegments=t.totalSegments),this.onRenderEvent(e)}else p();if(t.isStart){const t=n("div","tg-resize-handle tg-resize-h tg-left");r.appendChild(t)}if(t.isEnd){const t=n("div","tg-resize-handle tg-resize-h tg-right");r.appendChild(t)}return s&&r.addEventListener("click",e=>{e.stopPropagation(),s(t.event)}),i.initMonthDrag(r,t.event,a),r}renderAllDayMoreIndicator(t,e,i,a,s,r){const o=n("div","tg-more-indicator tg-allday-more");o.textContent=`+${e.length} more`;const d=100/a,l=t*d,h=4+26*(s+1)+2;o.style.left=`calc(${l}% + 2px)`,o.style.top=`${h}px`,o.style.width=`calc(${d}% - 4px)`;const c=new Date(this.adapter.year(i.date),this.adapter.month(i.date),this.adapter.date(i.date));return o.addEventListener("click",t=>{t.stopPropagation();const n=()=>{this.renderDefaultPopover(o,e,c,r)};this.onRenderMoreEventsPopover?this.onRenderMoreEventsPopover(e,c,o,n):n()}),o}renderDefaultPopover(t,e,i,a){this.closePopover();const s=n("div","tg-more-popover");this.activePopover=s;const r=n("div","tg-more-popover-header");r.textContent=i.toLocaleDateString(void 0,{weekday:"short",month:"short",day:"numeric"}),s.appendChild(r);const o=n("div","tg-more-popover-list");for(const d of e){const t=n("div","tg-more-popover-item");let e,i=d.color||"#3b82f6";if(this.onStyleEvent){const n=this.onStyleEvent(d);n.className&&t.classList.add(n.className),n.color&&(i=n.color),void 0!==n.opacity&&(e=n.opacity)}const s=n("span","tg-more-popover-dot");s.style.backgroundColor=i,t.appendChild(s);const r=n("span","tg-more-popover-title");r.textContent=d.title,t.appendChild(r),void 0!==e&&(t.style.opacity=e.toString()),a&&(t.addEventListener("click",t=>{t.stopPropagation(),this.closePopover(),a(d)}),t.style.cursor="pointer"),o.appendChild(t)}s.appendChild(o),document.body.appendChild(s),this.positionPopover(s,t),this.popoverCloseHandler=e=>{s.contains(e.target)||e.target===t||this.closePopover()},setTimeout(()=>{document.addEventListener("click",this.popoverCloseHandler)},0)}positionPopover(t,e){const n=e.getBoundingClientRect(),i=t.getBoundingClientRect(),a=window.innerHeight,s=window.innerWidth;let r=n.bottom+4,o=n.left;r+i.height>a-8&&(r=n.top-i.height-4),o+i.width>s-8&&(o=s-i.width-8),o<8&&(o=8),t.style.top=`${r}px`,t.style.left=`${o}px`}closePopover(){this.activePopover&&(this.activePopover.remove(),this.activePopover=null),this.popoverCloseHandler&&(document.removeEventListener("click",this.popoverCloseHandler),this.popoverCloseHandler=null)}renderTimeAxis(t,e){var i,a;const s=n("div","tg-time-axis");for(let r=0;r<t.length;r++){const o=t[r],d=n("div","tg-time-axis-label");(null==(i=o.config)?void 0:i.label)?d.textContent=o.config.label:d.textContent=e?e(o.hour,0):`${o.hour}:00`,(null==(a=o.config)?void 0:a.className)&&d.classList.add(o.config.className);const l=r*this.theme.cellHeight;d.style.transform=`translateY(${l}px)`,s.appendChild(d)}return s}renderDayColumn(t,e,i,a,s,r){const o=n("div","tg-day-column");if(o.dataset.date=t.dateStr,r&&r.length>0){const t=r.length*this.theme.cellHeight;o.style.setProperty("--tg-column-height",`${t}px`),o.style.height="var(--tg-column-height)"}const d=this.engine.calculateLayout(e,t.dateStr);for(const n of d){const t=this.renderEventBlock(n,i,a,s);o.appendChild(t)}return o}renderEventBlock(t,e,i,a){const s=n("div","tg-event-base tg-event-block");s.dataset.eid=t.event.id,void 0!==t.segmentIndex&&void 0!==t.totalSegments&&(s.dataset.segmentIndex=String(t.segmentIndex),s.dataset.totalSegments=String(t.totalSegments),s.classList.add("tg-event-segmented"),0===t.segmentIndex&&s.classList.add("tg-event-segment-first"),t.segmentIndex===t.totalSegments-1&&s.classList.add("tg-event-segment-last"),t.segmentIndex>0&&t.segmentIndex<t.totalSegments-1&&s.classList.add("tg-event-segment-middle")),t.isStart||s.classList.add("tg-event-continuation"),t.isEnd||s.classList.add("tg-event-continued");let r,o=t.event.color||"#3b82f6";if(this.onStyleEvent){const e=this.onStyleEvent(t.event);e.className&&s.classList.add(e.className),e.color&&(o=e.color),void 0!==e.opacity&&(r=e.opacity)}s.style.transform=`translate(${t.leftPercent}%, ${t.top}px)`,s.style.width=`calc(${t.widthPercent}% - 2px)`,s.style.height=`${t.height}px`,s.style.backgroundColor=o;const d=t.endMin-t.startMin,l=Math.max(0,Math.min(50,Math.floor((120-d)/2)));s.style.zIndex=`${10+l}`,void 0!==r&&(s.style.opacity=r.toString());const h=this.engine.isAllDayEvent(t.event),c=this.adapter.parse(t.event.start),p=this.adapter.parse(t.event.end),g=this.adapter.format(c,this.dateFormats.time),u=this.adapter.format(p,this.dateFormats.time),v=()=>{if(!h){const e=n("div","tg-time-text");t.isStart&&t.isEnd?e.textContent=`${g} - ${u}`:t.isStart?e.textContent=`${g} →`:t.isEnd?e.textContent=`→ ${u}`:e.textContent="→ →",s.appendChild(e)}const e=n("div","tg-event-title");e.textContent=t.event.title,s.appendChild(e)};if(this.onRenderEvent){const e={event:t.event,el:s,viewType:this.currentViewType,isAllDay:h,isStart:t.isStart,isEnd:t.isEnd,defaultRender:v};h||(e.startTime=g,e.endTime=u),void 0!==t.segmentIndex&&(e.segmentIndex=t.segmentIndex),void 0!==t.totalSegments&&(e.totalSegments=t.totalSegments),this.onRenderEvent(e)}else v();if(t.isStart){const t=n("div","tg-resize-handle tg-resize-v tg-top");s.appendChild(t)}if(t.isEnd){const t=n("div","tg-resize-handle tg-resize-v tg-bottom");s.appendChild(t)}return a&&s.addEventListener("click",e=>{e.stopPropagation(),a(t.event)}),e.initTimeDrag(s,t.event,i),s}}const M=class extends f{constructor(){super(...arguments),this.timeViewType="week"}init(t){super.init(t),this.engine=new S(this.context.adapter,this.context.config.theme.cellHeight,this.context.config.view.showWeekends,this.context.config.view.firstDayOfWeek,this.context.config.dateFormats),this.renderer=new E(this.engine,this.context.adapter,this.context.config.theme,this.context.config.dateFormats,this.context.config.onStyleEvent,this.context.config.onRenderEvent,this.context.config.view.maxEventsPerRow,this.context.config.onRenderMoreEventsPopover)}render(t,e,n){this.renderer.render(t,this.context.currentDate,this.timeViewType,e,this.context.dragController,this.context.requestRender,this.context.config.onEventClick,null==n?void 0:n.preservedScrollTop,this.context.config.view.dayFilter,this.context.config.view.timeFilter,this.context.config.view.timeFormatter)}getEngine(){return this.engine}getRenderer(){return this.renderer}};M.meta={type:"time",label:"Time",shortLabel:"T",order:20};let b=M;const k=class extends b{constructor(){super(...arguments),this.timeViewType="week"}getNavigationUnit(){return"week"}};k.meta={type:"week",label:"Week",shortLabel:"W",order:20};let R=k;const T=class extends b{constructor(){super(...arguments),this.timeViewType="day"}getNavigationUnit(){return"day"}getHeaderTitle(){return this.context.adapter.format(this.context.currentDate,this.context.config.dateFormats.dayHeader)}};T.meta={