From b04a553942fb6cebc647c89f67560b09b9e311cc Mon Sep 17 00:00:00 2001 From: Yury Uvarov Date: Mon, 11 Mar 2024 18:14:12 +0300 Subject: [PATCH 1/2] refactoring of show and hide methods --- package/index.d.ts | 2 ++ package/src/scripts/default.ts | 5 ++++- package/src/scripts/destroy.ts | 1 + package/src/scripts/handles/handleClickDay.ts | 2 -- package/src/scripts/handles/handleInput.ts | 7 +++---- package/src/scripts/helpers/actionsInput.ts | 15 --------------- package/src/scripts/hide.ts | 9 +++++++++ package/src/scripts/init.ts | 1 + package/src/scripts/methods/changeTime.ts | 3 +-- package/src/scripts/show.ts | 12 ++++++++++++ package/src/scripts/update.ts | 1 + package/src/vanilla-calendar.ts | 6 ++++++ package/types.ts | 16 +++++++--------- 13 files changed, 47 insertions(+), 33 deletions(-) delete mode 100644 package/src/scripts/helpers/actionsInput.ts create mode 100644 package/src/scripts/hide.ts create mode 100644 package/src/scripts/show.ts diff --git a/package/index.d.ts b/package/index.d.ts index 2ac1c766..3171c056 100644 --- a/package/index.d.ts +++ b/package/index.d.ts @@ -25,6 +25,8 @@ declare class VanillaCalendar implements T.IVanillaCalendar { init: () => () => void; update: (reset?: T.IReset) => void; destroy: () => void; + show: () => void; + hide: () => void; readonly HTMLElement: HTMLElement; readonly HTMLOriginalElement: HTMLElement; diff --git a/package/src/scripts/default.ts b/package/src/scripts/default.ts index 4587df53..1a18b327 100644 --- a/package/src/scripts/default.ts +++ b/package/src/scripts/default.ts @@ -73,8 +73,11 @@ export default class DefaultOptionsCalendar { getDays: null, getMonths: null, getYears: null, - hideCalendar: null, + initCalendar: null, + updateCalendar: null, + destroyCalendar: null, showCalendar: null, + hideCalendar: null, }; popups: T.IPopups = {}; CSSClasses: T.CSSClasses = { ...classes }; diff --git a/package/src/scripts/destroy.ts b/package/src/scripts/destroy.ts index c7c0cabe..1467a70c 100644 --- a/package/src/scripts/destroy.ts +++ b/package/src/scripts/destroy.ts @@ -13,6 +13,7 @@ const destroy = (self: VanillaCalendar) => { } self.HTMLElement = self.HTMLOriginalElement; + if (self.actions.destroyCalendar) self.actions.destroyCalendar(self); }; export default destroy; diff --git a/package/src/scripts/handles/handleClickDay.ts b/package/src/scripts/handles/handleClickDay.ts index 33b70b27..d19ccc86 100644 --- a/package/src/scripts/handles/handleClickDay.ts +++ b/package/src/scripts/handles/handleClickDay.ts @@ -1,6 +1,5 @@ import VanillaCalendar from '@src/vanilla-calendar'; import { FormatDateString } from '@package/types'; -import actionsInput from '@scripts/helpers/actionsInput'; import changeMonth from '@scripts/methods/changeMonth'; import createDays from '@scripts/methods/createDays'; import handleDayRangedSelection from '@scripts/handles/handleDayRangedSelection'; @@ -27,7 +26,6 @@ const handleClickDay = (self: VanillaCalendar, event: MouseEvent) => { if (isInitAsInput && self.actions.changeToInput) { self.actions.changeToInput( event, - actionsInput(self), self, ); } diff --git a/package/src/scripts/handles/handleInput.ts b/package/src/scripts/handles/handleInput.ts index 635a26f0..a81487dd 100644 --- a/package/src/scripts/handles/handleInput.ts +++ b/package/src/scripts/handles/handleInput.ts @@ -1,5 +1,4 @@ import VanillaCalendar from '@src/vanilla-calendar'; -import actionsInput from '@scripts/helpers/actionsInput'; import handleClick from '@scripts/handles/handleClick'; import update from '@scripts/update'; import { IVisibility, CSSClasses } from '@/package/types'; @@ -42,7 +41,7 @@ const handleInput = (self: VanillaCalendar) => { setTimeout(() => { setPositionCalendar(self.HTMLInputElement as HTMLInputElement, calendar, self.settings.visibility.positionToInput, self.CSSClasses); - actionsInput(self).show(); + self.show(); }, 0); update(self, { year: true, month: true, dates: true, holidays: true, time: true, @@ -55,7 +54,7 @@ const handleInput = (self: VanillaCalendar) => { const documentClickEvent = (e: MouseEvent) => { if (!self || e.target === self.HTMLInputElement || self.HTMLElement?.contains(e.target as Node)) return; - if (self.HTMLInputElement && self.HTMLElement) actionsInput(self as VanillaCalendar).hide(); + if (self.HTMLInputElement && self.HTMLElement) self.hide(); window.removeEventListener('resize', handleResize); document.removeEventListener('click', documentClickEvent, { capture: true }); }; @@ -65,7 +64,7 @@ const handleInput = (self: VanillaCalendar) => { cleanup.push(createCalendarToInput()); } else { setPositionCalendar(self.HTMLInputElement as HTMLInputElement, self.HTMLElement, self.settings.visibility.positionToInput, self.CSSClasses); - actionsInput(self as VanillaCalendar).show(); + self.show(); } window.addEventListener('resize', handleResize); document.addEventListener('click', documentClickEvent, { capture: true }); diff --git a/package/src/scripts/helpers/actionsInput.ts b/package/src/scripts/helpers/actionsInput.ts deleted file mode 100644 index 27627683..00000000 --- a/package/src/scripts/helpers/actionsInput.ts +++ /dev/null @@ -1,15 +0,0 @@ -import VanillaCalendar from '@src/vanilla-calendar'; - -const actionsInput = (self: VanillaCalendar) => ({ - hide() { - self.HTMLElement.classList.add(self.CSSClasses.calendarHidden); - if (self.actions.hideCalendar) self.actions.hideCalendar(self); - }, - show() { - self.HTMLElement.classList.remove(self.CSSClasses.calendarHidden); - if (self.actions.showCalendar) self.actions.showCalendar(self); - }, - self, -}); - -export default actionsInput; diff --git a/package/src/scripts/hide.ts b/package/src/scripts/hide.ts new file mode 100644 index 00000000..3d1976c7 --- /dev/null +++ b/package/src/scripts/hide.ts @@ -0,0 +1,9 @@ +import VanillaCalendar from '@src/vanilla-calendar'; + +const hide = (self: VanillaCalendar) => { + if (!self.currentType) return; + self.HTMLElement.classList.add(self.CSSClasses.calendarHidden); + if (self.actions.hideCalendar) self.actions.hideCalendar(self); +}; + +export default hide; diff --git a/package/src/scripts/init.ts b/package/src/scripts/init.ts index b48fa575..8556ba7f 100644 --- a/package/src/scripts/init.ts +++ b/package/src/scripts/init.ts @@ -14,6 +14,7 @@ const init = (self: VanillaCalendar) => { setVariables(self); create(self); + if (self.actions.initCalendar) self.actions.initCalendar(self); return handleClick(self); }; diff --git a/package/src/scripts/methods/changeTime.ts b/package/src/scripts/methods/changeTime.ts index b2913974..d66a99c0 100644 --- a/package/src/scripts/methods/changeTime.ts +++ b/package/src/scripts/methods/changeTime.ts @@ -1,5 +1,4 @@ import VanillaCalendar from '@src/vanilla-calendar'; -import actionsInput from '@scripts/helpers/actionsInput'; import transformTime12 from '@scripts/helpers/transformTime12'; import transformTime24 from '@scripts/helpers/transformTime24'; @@ -27,7 +26,7 @@ const setTime = (self: VanillaCalendar, e: Event, value: string, type: TypeTime) if (self.actions.changeTime) self.actions.changeTime(e, self); - if (self.input && self.HTMLInputElement && self.actions.changeToInput) self.actions.changeToInput(e, actionsInput(self), self); + if (self.input && self.HTMLInputElement && self.actions.changeToInput) self.actions.changeToInput(e, self); }; const changeRange = (self: VanillaCalendar, range: HTMLInputElement, input: HTMLInputElement, btnKeepingTime: HTMLButtonElement | null, type: TypeTime, max: number) => { diff --git a/package/src/scripts/show.ts b/package/src/scripts/show.ts new file mode 100644 index 00000000..33ec2708 --- /dev/null +++ b/package/src/scripts/show.ts @@ -0,0 +1,12 @@ +import VanillaCalendar from '@src/vanilla-calendar'; + +const show = (self: VanillaCalendar) => { + if (!self.currentType) { + self.HTMLElement.click(); + return; + } + self.HTMLElement.classList.remove(self.CSSClasses.calendarHidden); + if (self.actions.showCalendar) self.actions.showCalendar(self); +}; + +export default show; diff --git a/package/src/scripts/update.ts b/package/src/scripts/update.ts index 97a2070a..e28088fd 100644 --- a/package/src/scripts/update.ts +++ b/package/src/scripts/update.ts @@ -32,6 +32,7 @@ const update = (self: VanillaCalendar, { self.settings.selected = previousSelected; if (self.settings.selection.day === 'multiple-ranged' && dates) handleDayRangedSelection(self); + if (self.actions.updateCalendar) self.actions.updateCalendar(self); }; export default update; diff --git a/package/src/vanilla-calendar.ts b/package/src/vanilla-calendar.ts index 8e7d2ad8..8d0e5b39 100644 --- a/package/src/vanilla-calendar.ts +++ b/package/src/vanilla-calendar.ts @@ -3,6 +3,8 @@ import DefaultOptionsCalendar from '@scripts/default'; import init from '@scripts/init'; import update from '@scripts/update'; import destroy from '@scripts/destroy'; +import show from '@scripts/show'; +import hide from '@scripts/hide'; import messages from '@scripts/helpers/getMessages'; export default class VanillaCalendar extends DefaultOptionsCalendar implements T.IVanillaCalendar { @@ -32,4 +34,8 @@ export default class VanillaCalendar extends DefaultOptionsCalendar implements T update = (reset?: T.IReset) => update(this, reset); destroy = () => destroy(this); + + show = () => show(this); + + hide = () => hide(this); } diff --git a/package/types.ts b/package/types.ts index 3f0be81c..5ca991e6 100644 --- a/package/types.ts +++ b/package/types.ts @@ -78,19 +78,15 @@ export interface IActions { clickYear: ((e: MouseEvent, self: IVanillaCalendar) => void) | null; clickArrow: ((e: MouseEvent, self: IVanillaCalendar) => void) | null; changeTime: ((e: Event, self: IVanillaCalendar) => void) | null; - changeToInput: (( - e: Event, - calendar: { - hide(): void; - show(): void; - }, - self: IVanillaCalendar, - ) => void) | null; + changeToInput: ((e: Event, self: IVanillaCalendar) => void) | null; getDays: ((day: number, date: FormatDateString, HTMLElement: HTMLElement, HTMLButtonElement: HTMLButtonElement, self: IVanillaCalendar) => void) | null; getMonths: ((month: number, HTMLElement: HTMLElement, self: IVanillaCalendar) => void) | null; getYears: ((year: number, HTMLElement: HTMLElement, self: IVanillaCalendar) => void) | null; - hideCalendar: ((self: IVanillaCalendar) => void) | null; + initCalendar: ((self: IVanillaCalendar) => void) | null; + updateCalendar: ((self: IVanillaCalendar) => void) | null; + destroyCalendar: ((self: IVanillaCalendar) => void) | null; showCalendar: ((self: IVanillaCalendar) => void) | null; + hideCalendar: ((self: IVanillaCalendar) => void) | null; } export type IPopup = { @@ -161,6 +157,8 @@ export interface IVanillaCalendar { init: () => () => void; update: (reset?: IReset) => void; destroy: () => void; + show: () => void; + hide: () => void; readonly HTMLElement: HTMLElement; readonly HTMLOriginalElement: HTMLElement; From cbd60e49a2e8969e59154acf4055b16f22448de5 Mon Sep 17 00:00:00 2001 From: Yury Uvarov Date: Mon, 11 Mar 2024 19:05:13 +0300 Subject: [PATCH 2/2] add reset method and build package --- demo/pages/input/main.ts | 8 ++--- package/build/vanilla-calendar.min.js | 2 +- package/build/vanilla-calendar.min.mjs | 2 +- package/src/scripts/handles/handleInput.ts | 6 ++-- package/src/scripts/reset.ts | 34 ++++++++++++++++++++++ package/src/scripts/update.ts | 29 +++++------------- 6 files changed, 51 insertions(+), 30 deletions(-) create mode 100644 package/src/scripts/reset.ts diff --git a/demo/pages/input/main.ts b/demo/pages/input/main.ts index a4c51a13..ca228b2c 100644 --- a/demo/pages/input/main.ts +++ b/demo/pages/input/main.ts @@ -9,14 +9,14 @@ import '@src/styles/vanilla-calendar.css'; const configInput: IOptions = { input: true, actions: { - changeToInput(e, calendar, self) { + changeToInput(e, self) { if (!self.selectedDates || !self.HTMLInputElement) return; if (self.selectedDates[0]) { self.HTMLInputElement.value = self.selectedDates[0]; } else { self.HTMLInputElement.value = ''; } - calendar.hide(); + self.hide(); }, }, settings: { @@ -29,14 +29,14 @@ const configInput: IOptions = { const configDiv: IOptions = { input: true, actions: { - changeToInput(e, calendar, self) { + changeToInput(e, self) { if (!self.selectedDates || !self.HTMLInputElement) return; if (self.selectedDates[0]) { self.HTMLInputElement.innerHTML = self.selectedDates[0]; } else { self.HTMLInputElement.innerHTML = ''; } - calendar.hide(); + self.hide(); }, }, }; diff --git a/package/build/vanilla-calendar.min.js b/package/build/vanilla-calendar.min.js index 7534cc6b..b226353f 100644 --- a/package/build/vanilla-calendar.min.js +++ b/package/build/vanilla-calendar.min.js @@ -1,2 +1,2 @@ /*! name: vanilla-calendar-pro | url: https://github.com/uvarov-frontend/vanilla-calendar-pro */ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).VanillaCalendar=t()}(this,(function(){"use strict";var e=Object.defineProperty,t=Object.getOwnPropertySymbols,a=Object.prototype.hasOwnProperty,n=Object.prototype.propertyIsEnumerable,s=(t,a,n)=>a in t?e(t,a,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[a]=n,l=(e,l)=>{for(var r in l||(l={}))a.call(l,r)&&s(e,r,l[r]);if(t)for(var r of t(l))n.call(l,r)&&s(e,r,l[r]);return e},r=(e,t,a)=>(s(e,"symbol"!=typeof t?t+"":t,a),a);const i={calendar:"vanilla-calendar",calendarDefault:"vanilla-calendar_default",calendarMultiple:"vanilla-calendar_multiple",calendarMonth:"vanilla-calendar_month",calendarYear:"vanilla-calendar_year",calendarHidden:"vanilla-calendar_hidden",calendarToInput:"vanilla-calendar_to-input",calendarToInputTop:"vanilla-calendar_to-input_top",calendarToInputBottom:"vanilla-calendar_to-input_bottom",controls:"vanilla-calendar-controls",grid:"vanilla-calendar-grid",gridDisabled:"vanilla-calendar-grid_disabled",column:"vanilla-calendar-column",columnMonth:"vanilla-calendar-column_month",columnYear:"vanilla-calendar-column_year",header:"vanilla-calendar-header",headerContent:"vanilla-calendar-header__content",month:"vanilla-calendar-month",monthDisabled:"vanilla-calendar-month_disabled",year:"vanilla-calendar-year",yearDisabled:"vanilla-calendar-year_disabled",arrow:"vanilla-calendar-arrow",arrowPrev:"vanilla-calendar-arrow_prev",arrowNext:"vanilla-calendar-arrow_next",wrapper:"vanilla-calendar-wrapper",content:"vanilla-calendar-content",week:"vanilla-calendar-week",weekDay:"vanilla-calendar-week__day",weekDayWeekend:"vanilla-calendar-week__day_weekend",days:"vanilla-calendar-days",daysSelecting:"vanilla-calendar-days_selecting",months:"vanilla-calendar-months",monthsSelecting:"vanilla-calendar-months_selecting",monthsMonth:"vanilla-calendar-months__month",monthsMonthSelected:"vanilla-calendar-months__month_selected",monthsMonthDisabled:"vanilla-calendar-months__month_disabled",years:"vanilla-calendar-years",yearsSelecting:"vanilla-calendar-years_selecting",yearsYear:"vanilla-calendar-years__year",yearsYearSelected:"vanilla-calendar-years__year_selected",yearsYearDisabled:"vanilla-calendar-years__year_disabled",time:"vanilla-calendar-time",timeContent:"vanilla-calendar-time__content",timeHours:"vanilla-calendar-time__hours",timeMinutes:"vanilla-calendar-time__minutes",timeKeeping:"vanilla-calendar-time__keeping",timeRanges:"vanilla-calendar-time__ranges",timeRange:"vanilla-calendar-time__range",day:"vanilla-calendar-day",dayHoverFirst:"vanilla-calendar-day_hover-first",dayHoverLast:"vanilla-calendar-day_hover-last",dayHoverIntermediate:"vanilla-calendar-day_hover-intermediate",daySelectedFirst:"vanilla-calendar-day_selected-first",daySelectedLast:"vanilla-calendar-day_selected-last",daySelectedIntermediate:"vanilla-calendar-day_selected-intermediate",dayPopup:"vanilla-calendar-day__popup",dayBtn:"vanilla-calendar-day__btn",dayBtnPrev:"vanilla-calendar-day__btn_prev",dayBtnNext:"vanilla-calendar-day__btn_next",dayBtnToday:"vanilla-calendar-day__btn_today",dayBtnSelected:"vanilla-calendar-day__btn_selected",dayBtnHover:"vanilla-calendar-day__btn_hover",dayBtnDisabled:"vanilla-calendar-day__btn_disabled",dayBtnWeekend:"vanilla-calendar-day__btn_weekend",dayBtnHoliday:"vanilla-calendar-day__btn_holiday",weekNumbers:"vanilla-calendar-week-numbers",weekNumbersTitle:"vanilla-calendar-week-numbers__title",weekNumbersContent:"vanilla-calendar-week-numbers__content",weekNumber:"vanilla-calendar-week-number",isFocus:"vanilla-calendar-is-focus"},d=e=>`
<#ArrowPrev /><#ArrowNext />
<#Multiple>
<#Month /><#Year />
<#WeekNumbers />
<#Week /><#Days />
<#/Multiple>
<#ControlTime />`,o=e=>`
<#Month /><#Year />
<#Months />
`,c=e=>`
<#ArrowPrev />
<#Month /><#Year />
<#ArrowNext />
<#Years />
`;class u{constructor(){var e;r(this,"isInit",!1),r(this,"input",!1),r(this,"type","default"),r(this,"months",2),r(this,"jumpMonths",1),r(this,"date",{min:"1970-01-01",max:"2470-12-31",today:new Date}),r(this,"settings",{lang:"en",iso8601:!0,range:{min:this.date.min,max:this.date.max,disablePast:!1,disableGaps:!1,disableAllDays:!1,disableWeekday:void 0,disabled:void 0,enabled:void 0},selection:{day:"single",month:!0,year:!0,time:!1,controlTime:"all",stepHours:1,stepMinutes:1,cancelableDay:!0},selected:{dates:void 0,month:void 0,year:void 0,holidays:void 0,time:void 0},visibility:{theme:"system",themeDetect:"html[data-theme]",monthShort:!0,weekNumbers:!1,weekend:!0,today:!0,disabled:!1,daysOutside:!0,positionToInput:"left"}}),r(this,"locale",{months:[],weekday:[]}),r(this,"actions",{clickDay:null,clickWeekNumber:null,clickMonth:null,clickYear:null,clickArrow:null,changeTime:null,changeToInput:null,getDays:null,getMonths:null,getYears:null,hideCalendar:null,showCalendar:null}),r(this,"popups",{}),r(this,"CSSClasses",l({},i)),r(this,"DOMTemplates",{default:(e=this.CSSClasses,`
<#ArrowPrev />
<#Month /><#Year />
<#ArrowNext />
<#WeekNumbers />
<#Week /><#Days />
<#ControlTime />`),multiple:d(this.CSSClasses),month:o(this.CSSClasses),year:c(this.CSSClasses)}),r(this,"HTMLElement"),r(this,"HTMLOriginalElement"),r(this,"HTMLInputElement"),r(this,"rangeMin"),r(this,"rangeMax"),r(this,"rangeDisabled"),r(this,"rangeEnabled"),r(this,"selectedDates"),r(this,"selectedHolidays"),r(this,"selectedMonth"),r(this,"selectedYear"),r(this,"selectedHours"),r(this,"selectedMinutes"),r(this,"selectedKeeping"),r(this,"selectedTime"),r(this,"currentType"),r(this,"correctMonths"),r(this,"viewYear"),r(this,"dateMin"),r(this,"dateMax")}}const m=e=>`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}`,g=e=>new Date(`${e}T00:00:00`),h=e=>e.reduce(((e,t)=>(t.match(/^(\d{4}-\d{2}-\d{2})$/g)?e.push(t):t.replace(/(\d{4}-\d{2}-\d{2}).*?(\d{4}-\d{2}-\d{2})/g,((t,a,n)=>{const s=g(a),l=g(n),r=new Date(s.getTime());for(;r<=l;r.setDate(r.getDate()+1))e.push(m(r));return t})),e)),[]),y=e=>e?{0:"12",13:"01",14:"02",15:"03",16:"04",17:"05",18:"06",19:"07",20:"08",21:"09",22:"10",23:"11"}[Number(e)]||String(e):"",v=e=>`${e} is not found, check the first argument passed to new VanillaCalendar.`,M='The calendar has not been initialized, please initialize it using the "init()" method first.',S='You specified "define" for "settings.lang" but did not provide the required values for "locale.weekday" or "locale.months".',p='Incorrect name of theme in "settings.visibility.theme".',C="The value of the time property can be: false, true, 12 or 24.",b=e=>{e.currentType=e.type,(e=>{const t=void 0!==e.settings.selected.month&&Number(e.settings.selected.month)>=0&&Number(e.settings.selected.month)<12,a=void 0!==e.settings.selected.year&&Number(e.settings.selected.year)>=0&&Number(e.settings.selected.year)<=9999;e.selectedMonth=t?Number(e.settings.selected.month):e.date.today.getMonth(),e.selectedYear=a?Number(e.settings.selected.year):e.date.today.getFullYear(),e.viewYear=e.selectedYear})(e),(e=>{var t,a,n;e.settings.range.min=g(e.date.min)>=g(e.settings.range.min)?e.date.min:e.settings.range.min,e.settings.range.max=g(e.date.max)<=g(e.settings.range.max)?e.date.max:e.settings.range.max;const s=e.settings.range.disablePast&&!e.settings.range.disableAllDays&&g(e.settings.range.min)1&&e.rangeDisabled.sort(((e,t)=>+new Date(e)-+new Date(t))),e.rangeEnabled=e.settings.range.enabled?h(e.settings.range.enabled):[],(null==(t=e.rangeEnabled)?void 0:t[0])&&(null==(a=e.rangeDisabled)?void 0:a[0])&&(e.rangeDisabled=e.rangeDisabled.filter((t=>!e.rangeEnabled.includes(t)))),e.rangeEnabled.length>1&&e.rangeEnabled.sort(((e,t)=>+new Date(e)-+new Date(t))),(null==(n=e.rangeEnabled)?void 0:n[0])&&e.settings.range.disableAllDays&&(e.rangeMin=e.rangeEnabled[0],e.rangeMax=e.rangeEnabled[e.rangeEnabled.length-1])})(e),(e=>{var t,a;e.selectedDates=(null==(t=e.settings.selected.dates)?void 0:t[0])?h(e.settings.selected.dates):[],e.selectedHolidays=(null==(a=e.settings.selected.holidays)?void 0:a[0])?h(e.settings.selected.holidays):[]})(e),(e=>{e.dateMin=e.settings.visibility.disabled?g(e.date.min):g(e.rangeMin),e.dateMax=e.settings.visibility.disabled?g(e.date.max):g(e.rangeMax)})(e),(e=>{const t=!0===e.settings.selection.time||12===e.settings.selection.time;if(t||24===e.settings.selection.time){let a=!1;if("string"==typeof e.settings.selected.time){const n=t?/^([0-9]|0[1-9]|1[0-2]):([0-5][0-9])|(AM|PM)/g:/^([0-1]?[0-9]|2[0-3]):([0-5][0-9])/g;e.settings.selected.time.replace(n,((n,s,l,r)=>(s&&l&&(a=!0,e.selectedHours=s,e.selectedMinutes=l),r&&t?e.selectedKeeping=r:t&&(e.selectedKeeping="AM"),"")))}!a&&t?(e.selectedHours=y(String(e.date.today.getHours())),e.selectedMinutes=String(e.date.today.getMinutes()),e.selectedKeeping=Number(e.date.today.getHours())>=12?"PM":"AM"):a||(e.selectedHours=String(e.date.today.getHours()),e.selectedMinutes=String(e.date.today.getMinutes())),e.selectedHours=Number(e.selectedHours)<10?`0${Number(e.selectedHours)}`:`${e.selectedHours}`,e.selectedMinutes=Number(e.selectedMinutes)<10?`0${Number(e.selectedMinutes)}`:`${e.selectedMinutes}`,e.selectedTime=`${e.selectedHours}:${e.selectedMinutes}${e.selectedKeeping?` ${e.selectedKeeping}`:""}`}else if(e.settings.selection.time)throw new Error(C)})(e),(e=>{e.correctMonths="multiple"===e.type?1===e.months?2:e.months>12?12:e.months:1})(e)},f=e=>({hide(){e.HTMLElement.classList.add(e.CSSClasses.calendarHidden),e.actions.hideCalendar&&e.actions.hideCalendar(e)},show(){e.HTMLElement.classList.remove(e.CSSClasses.calendarHidden),e.actions.showCalendar&&e.actions.showCalendar(e)},self:e}),w=({arrowPrev:e,arrowNext:t,isPrevHidden:a,isNextHidden:n})=>{e.style.visibility=a?"hidden":"",t.style.visibility=n?"hidden":""},D=e=>{var t,a;if("month"===e.currentType)return;const n=null==(t=e.HTMLElement)?void 0:t.querySelector(`.${e.CSSClasses.arrowPrev}`),s=null==(a=e.HTMLElement)?void 0:a.querySelector(`.${e.CSSClasses.arrowNext}`);if(!n||!s)return;({default:()=>{const t=g(m(new Date(e.selectedYear,e.selectedMonth,1))),a=new Date(t.getTime()),l=new Date(t.getTime());a.setMonth(a.getMonth()-e.jumpMonths),l.setMonth(l.getMonth()+e.jumpMonths),e.settings.selection.year||(e.dateMin.setFullYear(t.getFullYear()),e.dateMax.setFullYear(t.getFullYear()));const r=!e.settings.selection.month||a.getFullYear()e.dateMax.getFullYear()||l.getFullYear()===e.dateMax.getFullYear()&&l.getMonth()>e.dateMax.getMonth();w({arrowPrev:n,arrowNext:s,isPrevHidden:r,isNextHidden:i})},year:()=>{w({arrowPrev:n,arrowNext:s,isPrevHidden:e.dateMin.getFullYear()&&e.viewYear-7<=e.dateMin.getFullYear(),isNextHidden:e.dateMax.getFullYear()&&e.viewYear+7>=e.dateMax.getFullYear()})}})["multiple"===e.currentType?"default":e.currentType]()},T=(e,t)=>{if(!e)return null;const a=g(e),n=t?a.getDay()||7:a.getDay();a.setDate(a.getDate()+4-n);const s=new Date(a.getFullYear(),0,1),l=Math.ceil(((+a-+s)/864e5+1)/7);return{year:a.getFullYear(),week:l}},$=(e,t,a,n,s)=>{const l=t[a].querySelector(`.${e.CSSClasses.dayBtn}`),r=T(null==l?void 0:l.dataset.calendarDay,e.settings.iso8601);if(!r)return;const i=n.cloneNode(!0);i.innerText=String(r.week),i.dataset.calendarYearWeek=String(r.year),s.append(i)},L=(e,t,a,n,s,l,r,i)=>{const d=document.createElement("div");d.className=e.CSSClasses.day;const o=document.createElement("button");o.className=`${e.CSSClasses.dayBtn}${i?` ${i}`:""}`,o.type="button",o.innerText=String(n),o.dataset.calendarDay=l;e.settings.visibility.weekNumbers&&(()=>{const t=T(l,e.settings.iso8601);t&&(o.dataset.calendarWeekNumber=String(t.week))})(),r?e.settings.visibility.daysOutside&&d.append(o):d.append(o),((e,t,a)=>{var n,s,l,r,i;const d=null==(n=e.settings.range.disableWeekday)?void 0:n.includes(a),o=e.settings.range.disableAllDays&&!!(null==(s=e.rangeEnabled)?void 0:s[0]);!d&&!o||(null==(l=e.rangeEnabled)?void 0:l.includes(t))||(null==(r=e.rangeDisabled)?void 0:r.includes(t))||(e.rangeDisabled.push(t),null==(i=e.rangeDisabled)||i.sort(((e,t)=>+new Date(e)-+new Date(t))))})(e,l,s),((e,t,a,n,s,l,r)=>{var i,d,o;(g(e.rangeMin)>g(l)||g(e.rangeMax)1&&"multiple-ranged"===e.settings.selection.day&&(e.selectedDates[0]===l&&a.classList.add(e.CSSClasses.daySelectedFirst),e.selectedDates[e.selectedDates.length-1]===l&&a.classList.add(e.CSSClasses.daySelectedLast),e.selectedDates[0]!==l&&e.selectedDates[e.selectedDates.length-1]!==l&&a.classList.add(e.CSSClasses.daySelectedIntermediate)))})(e,t,d,o,s,l,r),a.append(d),e.actions.getDays&&e.actions.getDays(n,l,d,o,e)},E=e=>{const t=e.HTMLElement.querySelectorAll(`.${e.CSSClasses.days}`),a=e.HTMLElement.querySelectorAll(`.${e.CSSClasses.weekNumbers}`),n=new Date(e.selectedYear,e.selectedMonth,1);t.forEach(((t,s)=>{const l=new Date(n);l.setMonth(l.getMonth()+s);const r=l.getMonth(),i=l.getFullYear(),d=new Date(i,r,1),o=new Date(i,r+1,0).getDate(),c=e.settings.iso8601?(0!==d.getDay()?d.getDay():7)-1:d.getDay();e.settings.selection.day&&t.classList.add(e.CSSClasses.daysSelecting),t.innerHTML="",((e,t,a,n,s)=>{let l=new Date(a,n,0).getDate()-(s-1);const r=0===n?a-1:a,i=0===n?12:n<10?`0${n}`:n;for(let n=s;n>0;n--,l++){const n=`${r}-${i}-${l}`,s=g(n).getDay();L(e,a,t,l,s,n,!0,e.CSSClasses.dayBtnPrev)}})(e,t,i,r,c),((e,t,a,n,s)=>{for(let l=1;l<=a;l++){const a=new Date(n,s,l),r=m(a),i=a.getDay();L(e,n,t,l,i,r,!1,null)}})(e,t,o,i,r),((e,t,a,n,s,l)=>{const r=l+a,i=7*Math.ceil(r/7)-r,d=s+1===12?n+1:n,o=s+1===12?"01":s+2<10?`0${s+2}`:s+2;for(let a=1;a<=i;a++){const s=`${d}-${o}-${a<10?`0${a}`:String(a)}`,l=g(s).getDay();L(e,n,t,a,l,s,!0,e.CSSClasses.dayBtnNext)}})(e,t,o,i,r,c),((e,t,a,n,s)=>{if(!e.settings.visibility.weekNumbers)return;n.innerHTML="";const l=document.createElement("b");l.className=e.CSSClasses.weekNumbersTitle,l.innerText="#",n.append(l);const r=document.createElement("div");r.className=e.CSSClasses.weekNumbersContent,n.append(r);const i=document.createElement("button");i.type="button",i.className=e.CSSClasses.weekNumber;const d=s.querySelectorAll(`.${e.CSSClasses.day}`),o=Math.ceil((t+a)/7);for(let t=0;t{var a;e.popups&&(null==(a=Object.entries(e.popups))||a.forEach((([a,n])=>((e,t,a,n)=>{const s=a.querySelector(`[data-calendar-day="${e}"]`);s&&((null==t?void 0:t.modifier)&&s.classList.add(...t.modifier.trim().split(" ")),(null==t?void 0:t.html)&&(s.parentElement.innerHTML+=`
${t.html}
`))})(a,n,t,e.CSSClasses.dayPopup))))})(e,t)}))},H=e=>{var t,a;const n=null==(t=e.HTMLElement)?void 0:t.querySelectorAll("[data-calendar-selected-month]"),s=null==(a=e.HTMLElement)?void 0:a.querySelectorAll("[data-calendar-selected-year]");if(!(null==n?void 0:n[0])&&(null==s?void 0:s[0]))return;const l=new Date(e.selectedYear,e.selectedMonth,1);null==n||n.forEach(((t,a)=>((e,t,a,n)=>{const s=new Date(n.setMonth(e.selectedMonth+a)).getMonth(),l=!1===e.settings.selection.month||"only-arrows"===e.settings.selection.month;t.tabIndex=l?-1:0,t.classList.toggle(e.CSSClasses.monthDisabled,l),t.setAttribute("data-calendar-selected-month",String(s)),t.innerText=e.locale.months[s]})(e,t,a,l))),null==s||s.forEach(((t,a)=>((e,t,a,n)=>{const s=new Date(n.setFullYear(e.selectedYear,e.selectedMonth+a)).getFullYear(),l=!1===e.settings.selection.year||"only-arrows"===e.settings.selection.year;t.tabIndex=l?-1:0,t.classList.toggle(e.CSSClasses.yearDisabled,l),t.setAttribute("data-calendar-selected-year",String(s)),t.innerText=String(s)})(e,t,a,l)))},Y=(e,t)=>{const a=g(m(new Date(e.selectedYear,e.selectedMonth,1)));({prev:()=>a.setMonth(a.getMonth()-e.jumpMonths),next:()=>a.setMonth(a.getMonth()+e.jumpMonths)})[t](),[e.selectedMonth,e.selectedYear]=[a.getMonth(),a.getFullYear()],H(e),D(e),E(e)},k=Object.freeze(Object.defineProperty({__proto__:null,ArrowNext:e=>``,ArrowPrev:e=>``,ControlTime:e=>e.settings.selection.time?`
`:"",Days:e=>`
`,Month:e=>``,Months:e=>`
`,Week:e=>`
`,WeekNumbers:e=>e.settings.visibility.weekNumbers?`
`:"",Year:e=>``,Years:e=>`
`},Symbol.toStringTag,{value:"Module"})),x=(e,t)=>t.replace(/[\n\t]/g,"").replace(/<#(?!\/?Multiple)(.*?)>/g,((t,a)=>{const n=(s=a.replace(/[/\s\n\t]/g,""),k[s]);var s;return n?n(e):""})).replace(/[\n\t]/g,""),_=(e,t)=>{const{HTMLElement:a,CSSClasses:n,DOMTemplates:s,type:l,currentType:r,correctMonths:i}=e,d=(s,l)=>{if(!t)return;const r=a.querySelector(`.${n.controls}`);r&&a.removeChild(r);a.querySelector(`.${n.grid}`).classList.add(n.gridDisabled);const i=t.closest(`.${n.column}`);i.classList.add(s),i.innerHTML=x(e,l)},o={default:()=>{a.classList.add(n.calendarDefault),a.classList.remove(n.calendarMonth,n.calendarYear),a.innerHTML=x(e,s.default)},multiple:()=>{i&&(a.classList.add(n.calendarMultiple),a.classList.remove(n.calendarMonth,n.calendarYear),a.innerHTML=((e,t)=>t.replace(/<#Multiple>(.*?)<#\/Multiple>/g,((t,a)=>{let n="";for(let t=0;t{"multiple"!==l?(a.classList.add(n.calendarMonth),a.classList.remove(n.calendarDefault,n.calendarYear),a.innerHTML=x(e,s.month)):d(n.columnMonth,s.month)},year:()=>{"multiple"!==l?(a.classList.add(n.calendarYear),a.classList.remove(n.calendarDefault,n.calendarMonth),a.innerHTML=x(e,s.year)):d(n.columnYear,s.year)}};a.classList.add(n.calendar),o[r]()},N=(e,t,a,n,s)=>{const l=t.cloneNode(!1);return l.className=`${e.CSSClasses.yearsYear}${a===s?` ${e.CSSClasses.yearsYearSelected}`:n?` ${e.CSSClasses.yearsYearDisabled}`:""}`,l.dataset.calendarYear=String(s),l.title=String(s),l.innerText=String(s),n&&(l.tabIndex=-1),l},A=(e,t)=>{const a=(null==t?void 0:t.dataset.calendarSelectedYear)?Number(null==t?void 0:t.dataset.calendarSelectedYear):e.selectedYear;e.currentType="year",_(e,t),H(e),D(e);const n=e.HTMLElement.querySelector(`.${e.CSSClasses.years}`);if(!e.settings.selection.year||!n)return;n.classList.add(e.CSSClasses.yearsSelecting);const s="multiple"!==e.type||e.selectedYear===a?0:1,l=document.createElement("button");l.type="button";for(let t=e.viewYear-7;te.dateMax.getFullYear(),i=N(e,l,a,r,t);n.append(i),e.actions.getYears&&e.actions.getYears(t,i,e)}},F=e=>`${e.charAt(0).toUpperCase()}${e.substring(1,e.length)}`.replace(/\./,""),I=(e,t)=>{const a=new Date(`1978-01-0${t+1}T00:00:00.000Z`).toLocaleString(e.settings.lang,{weekday:"short",timeZone:"UTC"});e.locale.weekday.push(F(a))},P=(e,t)=>{const a=new Date(`1978-${t+1<=9?`0${t+1}`:t+1}-01T00:00:00.000Z`).toLocaleString(e.settings.lang,{month:"long",timeZone:"UTC"});e.locale.months.push(F(a))},q=e=>{if("multiple"!==e.type)return 0;const t=[...e.HTMLElement.querySelectorAll(`.${e.CSSClasses.column}`)].findIndex((t=>t.classList.contains(`${e.CSSClasses.columnMonth}`)));return t>0?t:0},B=(e,t,a,n,s,l)=>{const r=t.cloneNode(!1);return r.className=`${e.CSSClasses.monthsMonth}${a===l?` ${e.CSSClasses.monthsMonthSelected}`:s?` ${e.CSSClasses.monthsMonthDisabled}`:""}`,r.title=n,r.innerText=`${e.settings.visibility.monthShort?n.substring(0,3):n}`,r.dataset.calendarMonth=String(l),s&&(r.tabIndex=-1),r},W=(e,t)=>{var a,n;const s=(null==t?void 0:t.dataset.calendarSelectedMonth)?Number(t.dataset.calendarSelectedMonth):e.selectedMonth,l=null==(a=null==t?void 0:t.closest(`.${e.CSSClasses.column}`))?void 0:a.querySelector(`.${e.CSSClasses.year}`),r=l?Number(l.dataset.calendarSelectedYear):e.selectedYear;e.currentType="month",_(e,t),H(e);const i=null==(n=e.HTMLElement)?void 0:n.querySelector(`.${e.CSSClasses.months}`);if(!e.settings.selection.month||!i)return;i.classList.add(e.CSSClasses.monthsSelecting);const d=e.jumpMonths>1?e.locale.months.map(((t,a)=>s-e.jumpMonths*a)).concat(e.locale.months.map(((t,a)=>s+e.jumpMonths*a))).filter((e=>e>=0&&e<=12)):Array.from(Array(12).keys()),o=document.createElement("button");o.type="button";for(let t=0;t<12;t++){const a=e.locale.months[t],n=te.dateMax.getMonth()+q(e)&&r>=e.dateMax.getFullYear()||t!==s&&!d.includes(t),l=B(e,o,s,a,n,t);i.append(l),e.actions.getMonths&&e.actions.getMonths(t,l,e)}},K=(e,t)=>e&&t?{0:{AM:"00",PM:"12"},1:{AM:"01",PM:"13"},2:{AM:"02",PM:"14"},3:{AM:"03",PM:"15"},4:{AM:"04",PM:"16"},5:{AM:"05",PM:"17"},6:{AM:"06",PM:"18"},7:{AM:"07",PM:"19"},8:{AM:"08",PM:"20"},9:{AM:"09",PM:"21"},10:{AM:"10",PM:"22"},11:{AM:"11",PM:"23"},12:{AM:"12",PM:"12"}}[Number(e)][t]:"",O=(e,t,a)=>e.querySelector(`.${t}${a?` input[name="${a}"]`:""}`),j=(e,t,a)=>{e.addEventListener("mouseover",(()=>t.classList.add(a))),e.addEventListener("mouseout",(()=>t.classList.remove(a)))},R=(e,t,a,n)=>{({hours:()=>{e.selectedHours=a},minutes:()=>{e.selectedMinutes=a}})[n](),e.selectedTime=`${e.selectedHours}:${e.selectedMinutes}${e.selectedKeeping?` ${e.selectedKeeping}`:""}`,e.actions.changeTime&&e.actions.changeTime(t,e),e.input&&e.HTMLInputElement&&e.actions.changeToInput&&e.actions.changeToInput(t,f(e),e)},z=(e,t,a,n,s,l)=>{t.addEventListener("input",(t=>{const r=t.target,i=Number(r.value),d=i<10?`0${i}`:`${i}`;if("hours"!==s||12!==l)return a.value=d,void R(e,t,d,s);i0?(a.value=d,e.selectedKeeping="AM",n.innerText=e.selectedKeeping,R(e,t,d,s)):(0===i?(e.selectedKeeping="AM",n.innerText="AM"):(e.selectedKeeping="PM",n.innerText="PM"),a.value=y(r.value),R(e,t,y(r.value),s))}))},G=(e,t,a,n,s,l)=>{a.addEventListener("change",(a=>{const r=a.target,i=Number(r.value),d=i<10?`0${i}`:`${i}`;"hours"===s&&12===l?r.value&&i<=l&&i>0?(r.value=d,t.value=K(d,e.selectedKeeping),R(e,a,d,s)):r.value&&i<24&&(i>l||0===i)?(0===i?(e.selectedKeeping="AM",n.innerText="AM"):(e.selectedKeeping="PM",n.innerText="PM"),r.value=y(r.value),t.value=d,R(e,a,y(r.value),s)):r.value=e.selectedHours:r.value&&i<=l&&i>=0?(r.value=d,t.value=d,R(e,a,d,s)):"hours"===s?r.value=e.selectedHours:"minutes"===s&&(r.value=e.selectedMinutes)}))},Z=(e,t,a)=>{const n=24===a?23:a||12,s=O(t,e.CSSClasses.timeRange,"hours"),l=O(t,e.CSSClasses.timeRange,"minutes"),r=O(t,e.CSSClasses.timeHours,"hours"),i=O(t,e.CSSClasses.timeMinutes,"minutes"),d=t.querySelector(`.${e.CSSClasses.timeKeeping}`);j(s,r,e.CSSClasses.isFocus),j(l,i,e.CSSClasses.isFocus),z(e,s,r,d,"hours",n),z(e,l,i,d,"minutes",0),G(e,s,r,d,"hours",n),G(e,l,i,d,"minutes",59),d&&((e,t,a)=>{t.addEventListener("click",(n=>{e.selectedKeeping=t.innerText.includes("AM")?"PM":"AM",t.innerText=e.selectedKeeping,a.value=K(e.selectedHours,e.selectedKeeping),R(e,n,e.selectedHours,"hours")}))})(e,d,s)},U=(e,t,a,n)=>``,V=(e,t,a,n,s,l)=>``,X=e=>{const t=[...e.locale.weekday];if(!t[0])return;e.settings.iso8601&&t.push(t.shift());e.HTMLElement.querySelectorAll(`.${e.CSSClasses.week}`).forEach((a=>((e,t,a)=>{const n=document.createElement("b");t.innerHTML="";for(let s=0;s{Q.value=!0},check:()=>Q.value},ee=(e,t)=>J.find((a=>{var n;return"system"!==a&&(null==(n=e.getAttribute(t))?void 0:n.includes(a))})),te=(e,t)=>{e.dataset.calendarTheme=t},ae=(e,t)=>{var a;if(a=t,te(e.HTMLElement,a.matches?"dark":"light"),"system"!==e.settings.visibility.theme||Q.check())return;const n=t=>{const a=document.querySelectorAll(`.${e.CSSClasses.calendar}`);null==a||a.forEach((e=>te(e,t.matches?"dark":"light")))};t.addEventListener?t.addEventListener("change",n):t.addListener(n),Q.set()},ne=(e,t)=>{const a=e.settings.visibility.themeDetect?document.querySelector(e.settings.visibility.themeDetect):null;if(!a)return void ae(e,t);const n=e.settings.visibility.themeDetect.replace(/^.*\[(.+)\]/g,((e,t)=>t)),s=ee(a,n);s?(te(e.HTMLElement,s),((e,t,a)=>{new MutationObserver((n=>{for(let s=0;s{const t={default:()=>{X(e),E(e)},multiple:()=>{X(e),E(e)},month:()=>W(e),year:()=>A(e)};(e=>{if(!J.includes(e.settings.visibility.theme))throw new Error(p);if("not all"===window.matchMedia("(prefers-color-scheme)").media)return void te(e.HTMLElement,"light");({light:()=>te(e.HTMLElement,"light"),dark:()=>te(e.HTMLElement,"dark"),system:()=>ne(e,window.matchMedia("(prefers-color-scheme: dark)"))})[e.settings.visibility.theme]()})(e),(e=>{if("define"!==e.settings.lang||!e.locale.weekday[6]||!e.locale.months[11]){if("define"===e.settings.lang)throw new Error(S);e.locale.weekday=[],e.locale.months=[];for(let t=0;t<7;t++)I(e,t);for(let t=0;t<12;t++)P(e,t)}})(e),_(e),H(e),D(e),(e=>{const t=e.HTMLElement.querySelector(`.${e.CSSClasses.time}`);if(!t)return;const a=!0===e.settings.selection.time?12:e.settings.selection.time,n="range"===e.settings.selection.controlTime,[s,l]=[0,23],[r,i]=[0,59];t.innerHTML=`
${U("hours",e.CSSClasses.timeHours,e.selectedHours,n)}${U("minutes",e.CSSClasses.timeMinutes,e.selectedMinutes,n)}${12===a?``:""}
${V("hours",e.CSSClasses.timeRange,s,l,e.settings.selection.stepHours,e.selectedKeeping?K(e.selectedHours,e.selectedKeeping):e.selectedHours)}${V("minutes",e.CSSClasses.timeRange,r,i,e.settings.selection.stepMinutes,e.selectedMinutes)}
`,Z(e,t,a)})(e),t[e.currentType]()},le={self:null,rangeMin:void 0,rangeMax:void 0},re=()=>{var e;if(!(null==(e=le.self)?void 0:e.HTMLElement))return;const{CSSClasses:t}=le.self;le.self.HTMLElement.querySelectorAll(`.${le.self.CSSClasses.dayBtnHover}`).forEach((e=>{var a;e.classList.remove(le.self.CSSClasses.dayBtnHover),null==(a=e.parentElement)||a.classList.remove(t.dayHoverIntermediate,t.dayHoverFirst,t.dayHoverLast)}))},ie=(e,t,a)=>{var n,s,l;if(!(null==(n=le.self)?void 0:n.selectedDates))return;const r=m(e),{CSSClasses:i}=le.self;if(null==(s=le.self.rangeDisabled)?void 0:s.includes(r))return;const d=null==(l=le.self.HTMLElement)?void 0:l.querySelectorAll(`[data-calendar-day="${r}"]`);null==d||d.forEach((e=>{var t;e.classList.add(i.dayBtnHover),null==(t=e.parentElement)||t.classList.add(i.dayHoverIntermediate)})),null==t||t.forEach((e=>{var t;return null==(t=e.parentElement)?void 0:t.classList.add(i.dayHoverFirst)})),null==a||a.forEach((e=>{var t;return null==(t=e.parentElement)?void 0:t.classList.add(i.dayHoverLast)}))},de=e=>{var t;if(!e.target||!(null==(t=le.self)?void 0:t.selectedDates))return;if(!e.target.closest(`.${le.self.CSSClasses.days}`))return void re();const a=e.target.closest("[data-calendar-day]");if(!a)return;const n=a.dataset.calendarDay,s=g(le.self.selectedDates[0]),l=g(n),r=le.self.HTMLElement.querySelectorAll(`[data-calendar-day="${le.self.selectedDates[0]}"]`),i=le.self.HTMLElement.querySelectorAll(`[data-calendar-day="${n}"]`),[d,o]=s{le.self&&"Escape"===e.key&&(le.self.selectedDates=[],le.self.HTMLElement.removeEventListener("mousemove",de),document.removeEventListener("keydown",oe),se(le.self))},ce=(e,t)=>{var a;if(t){const n=1===e.selectedDates.length&&e.selectedDates[0].includes(t);e.selectedDates=n&&!e.settings.selection.cancelableDay?[t,t]:n&&e.settings.selection.cancelableDay?[]:e.selectedDates.length>1?[t]:[...e.selectedDates,t],null==(a=e.selectedDates)||a.sort(((e,t)=>+new Date(e)-+new Date(t)))}e.settings.range.disableGaps&&(le.rangeMin=le.rangeMin?le.rangeMin:e.rangeMin,le.rangeMax=le.rangeMax?le.rangeMax:e.rangeMax),le.self=e;const n={set:()=>{e.HTMLElement.addEventListener("mousemove",de),document.addEventListener("keydown",oe),e.settings.range.disableGaps&&(()=>{var e,t,a;if(!(null==(t=null==(e=le.self)?void 0:e.selectedDates)?void 0:t[0])||!le.self.rangeDisabled||(null==(a=le.self.rangeDisabled)?void 0:a.length)<2)return;const n=g(le.self.selectedDates[0]),[s,l]=le.self.rangeDisabled.map((e=>g(e))).reduce((([e,t],a)=>[n>=a?a:e,n{const[t,a]=[e.selectedDates[0],e.selectedDates[e.selectedDates.length-1]];e.selectedDates=e.selectedDates[0]!==e.selectedDates[e.selectedDates.length-1]?h([`${t}:${a}`]):[e.selectedDates[0],e.selectedDates[0]],e.HTMLElement.removeEventListener("mousemove",de),document.removeEventListener("keydown",oe),e.settings.range.disableGaps&&le.self&&(le.self.rangeMin=le.rangeMin,le.self.rangeMax=le.rangeMax)}};n[1===e.selectedDates.length?"set":"reset"]()},ue=(e,t,a)=>{if(!t.dataset.calendarDay)return;const n=t.dataset.calendarDay,s=t.classList.contains(e.CSSClasses.dayBtnSelected);s&&!e.settings.selection.cancelableDay||(e.selectedDates=s?e.selectedDates.filter((e=>e!==n)):a?[...e.selectedDates,n]:[n])},me=(e,t,a,n,s)=>{const l=e.HTMLElement.querySelectorAll(`.${e.CSSClasses.column}`),r=[...l].findIndex((e=>e.classList.contains(t))),i=Number(l[r].querySelector(`.${a}`).getAttribute(s));return"month"===e.currentType&&r>=0?n-r:"year"===e.currentType&&e.selectedYear!==i?n-1:n},ge=(e,t,a,n)=>{if(!e.settings.selection[a])return;const s=t.target,l=e=>s.closest(`.${e}`),r=l(n.header),i=l(n.item),d=l(e.CSSClasses.grid),o=l(e.CSSClasses.column);if(e.currentType!==a&&r){({year:()=>A(e,s),month:()=>W(e,s)})[a]()}else i?((e,t,a,n,s)=>{const l={year:()=>{var a,n;return null==(n=(a=e.actions).clickYear)?void 0:n.call(a,t,e)},month:()=>{var a,n;return null==(n=(a=e.actions).clickMonth)?void 0:n.call(a,t,e)}};({year:()=>{if("multiple"===e.type){const t=me(e,e.CSSClasses.columnYear,e.CSSClasses.year,Number(s.dataset.calendarYear),"data-calendar-selected-year"),a=e.selectedMonthe.dateMax.getMonth()&&t>=e.dateMax.getFullYear(),l=te.dateMax.getFullYear();a||l?(e.selectedYear=e.dateMin.getFullYear(),e.selectedMonth=e.dateMin.getMonth()):n||r?(e.selectedYear=e.dateMax.getFullYear(),e.selectedMonth=e.dateMax.getMonth()):e.selectedYear=t}else e.selectedYear=Number(s.dataset.calendarYear)},month:()=>{if("multiple"===e.type){const t=me(e,e.CSSClasses.columnMonth,e.CSSClasses.month,Number(s.dataset.calendarMonth),"data-calendar-selected-month"),a=s.closest(`.${n.column}`).querySelector(`.${e.CSSClasses.year}`);e.selectedYear=Number(a.dataset.calendarSelectedYear);const l=te.dateMax.getMonth()&&e.selectedYear>=e.dateMax.getFullYear();e.selectedMonth=l?e.dateMin.getMonth():r?e.dateMax.getMonth():t}else e.selectedMonth=Number(s.dataset.calendarMonth)}})[a](),l[a](),e.currentType=e.type,se(e)})(e,t,a,n,i):(e.currentType===a&&r||"multiple"===e.type&&e.currentType===a&&d&&!o)&&(e.currentType=e.type,se(e))},he=e=>{const t=t=>{((e,t)=>{const a=t.target.closest(`.${e.CSSClasses.arrow}`);a&&(["default","multiple"].includes(e.currentType)?Y(e,a.dataset.calendarArrow):"year"===e.currentType&&void 0!==e.viewYear&&(e.viewYear+={prev:-15,next:15}[a.dataset.calendarArrow],A(e,t.target)),e.actions.clickArrow&&e.actions.clickArrow(t,e))})(e,t),((e,t)=>{var a;if(!e.settings.visibility.weekNumbers||!e.actions.clickWeekNumber)return;const n=t.target.closest(`.${e.CSSClasses.weekNumber}`),s=null==(a=e.HTMLElement)?void 0:a.querySelectorAll("[data-calendar-week-number]");if(!n||!s)return;const l=Number(n.innerText),r=Number(n.dataset.calendarYearWeek),i=[...s].filter((e=>Number(e.dataset.calendarWeekNumber)===l));e.actions.clickWeekNumber(t,l,i,r,e)})(e,t),((e,t)=>{var a;const n=t.target,s=e=>n.closest(`.${e}`),l=s(e.CSSClasses.dayBtn);if(!e.settings.selection.day||!["single","multiple","multiple-ranged"].includes(e.settings.selection.day)||!l)return;({single:()=>ue(e,l,!1),multiple:()=>ue(e,l,!0),"multiple-ranged":()=>ce(e,l.dataset.calendarDay)})[e.settings.selection.day](),null==(a=e.selectedDates)||a.sort(((e,t)=>+new Date(e)-+new Date(t))),e.actions.clickDay&&e.actions.clickDay(t,e),e.input&&e.HTMLInputElement&&e.HTMLElement&&e.actions.changeToInput&&e.actions.changeToInput(t,f(e),e);const r=s(e.CSSClasses.dayBtnPrev),i=s(e.CSSClasses.dayBtnNext);({prev:()=>Y(e,"prev"),next:()=>Y(e,"next"),default:()=>E(e)})[r?"prev":i?"next":"default"]()})(e,t),ge(e,t,"month",{header:e.CSSClasses.month,item:e.CSSClasses.monthsMonth,column:e.CSSClasses.columnMonth}),ge(e,t,"year",{header:e.CSSClasses.year,item:e.CSSClasses.yearsYear,column:e.CSSClasses.columnYear})};return e.HTMLElement.addEventListener("click",t),()=>e.HTMLElement.removeEventListener("click",t)},ye=(e,{year:t,month:a,dates:n,holidays:s,time:r}={})=>{var i;if(!e.isInit)throw new Error(M);const d=l({},e.settings.selected);e.settings.selected.year=t?d.year:e.selectedYear,e.settings.selected.month=a?d.month:e.selectedMonth,e.settings.selected.holidays=s?d.holidays:e.selectedHolidays,e.settings.selected.time=r?d.time:e.selectedTime,e.settings.selected.dates="only-first"===n&&(null==(i=e.selectedDates)?void 0:i[0])?[e.selectedDates[0]]:!0===n?d.dates:e.selectedDates,b(e),se(e),e.settings.selected=d,"multiple-ranged"===e.settings.selection.day&&n&&ce(e)},ve=(e,t,a,n)=>{const s={top:-t.offsetHeight,bottom:e.offsetHeight,left:0,center:e.offsetWidth/2-t.offsetWidth/2,right:e.offsetWidth-t.offsetWidth},l=Array.isArray(a)?a[0]:"bottom",r=Array.isArray(a)?a[1]:a;t.classList.add("bottom"===l?n.calendarToInputBottom:n.calendarToInputTop);const i=e.getBoundingClientRect(),d=window.scrollX||document.documentElement.scrollLeft,o=window.scrollY||document.documentElement.scrollTop,c=i.top+o+s[l],u=i.left+d+s[r];Object.assign(t.style,{left:`${u}px`,top:`${c}px`})},Me=e=>{let t=!0;const a=[];e.HTMLInputElement=e.HTMLElement;const n=()=>ve(e.HTMLInputElement,e.HTMLElement,e.settings.visibility.positionToInput,e.CSSClasses),s=t=>{var a;e&&t.target!==e.HTMLInputElement&&!(null==(a=e.HTMLElement)?void 0:a.contains(t.target))&&(e.HTMLInputElement&&e.HTMLElement&&f(e).hide(),window.removeEventListener("resize",n),document.removeEventListener("click",s,{capture:!0}))};return e.HTMLInputElement.addEventListener("click",(()=>{t?a.push((()=>{const a=document.createElement("div");return a.className=`${e.CSSClasses.calendar} ${e.CSSClasses.calendarToInput} ${e.CSSClasses.calendarHidden}`,e.HTMLElement=a,document.body.append(e.HTMLElement),t=!1,setTimeout((()=>{ve(e.HTMLInputElement,a,e.settings.visibility.positionToInput,e.CSSClasses),f(e).show()}),0),ye(e,{year:!0,month:!0,dates:!0,holidays:!0,time:!0}),he(e)})()):(ve(e.HTMLInputElement,e.HTMLElement,e.settings.visibility.positionToInput,e.CSSClasses),f(e).show()),window.addEventListener("resize",n),document.addEventListener("click",s,{capture:!0})})),()=>{a.forEach((e=>e()))}};return class extends u{constructor(e,t){if(super(),r(this,"init",(()=>{return(e=this).HTMLOriginalElement=e.HTMLElement.cloneNode(!0),e.isInit=!0,e.input?Me(e):(b(e),se(e),he(e));var e})),r(this,"update",(e=>ye(this,e))),r(this,"destroy",(()=>(e=>{var t,a,n,s;if(!e.isInit)throw new Error(M);e.input?(null==(a=null==(t=e.HTMLElement)?void 0:t.parentElement)||a.removeChild(e.HTMLElement),null==(n=e.HTMLInputElement)||n.replaceWith(e.HTMLOriginalElement),e.HTMLInputElement=void 0):null==(s=e.HTMLElement)||s.replaceWith(e.HTMLOriginalElement),e.HTMLElement=e.HTMLOriginalElement})(this))),this.HTMLElement="string"==typeof e?document.querySelector(e):e,!this.HTMLElement)throw new Error(v(e));if(!t)return;const a=(e,t)=>{Object.keys(t).forEach((n=>{"object"!=typeof e[n]||"object"!=typeof t[n]||t[n]instanceof Date?e[n]=t[n]:a(e[n],t[n])}))};a(this,t)}}})); \ No newline at end of file +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).VanillaCalendar=t()}(this,(function(){"use strict";var e=Object.defineProperty,t=Object.getOwnPropertySymbols,a=Object.prototype.hasOwnProperty,n=Object.prototype.propertyIsEnumerable,s=(t,a,n)=>a in t?e(t,a,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[a]=n,l=(e,l)=>{for(var r in l||(l={}))a.call(l,r)&&s(e,r,l[r]);if(t)for(var r of t(l))n.call(l,r)&&s(e,r,l[r]);return e},r=(e,t,a)=>(s(e,"symbol"!=typeof t?t+"":t,a),a);const i={calendar:"vanilla-calendar",calendarDefault:"vanilla-calendar_default",calendarMultiple:"vanilla-calendar_multiple",calendarMonth:"vanilla-calendar_month",calendarYear:"vanilla-calendar_year",calendarHidden:"vanilla-calendar_hidden",calendarToInput:"vanilla-calendar_to-input",calendarToInputTop:"vanilla-calendar_to-input_top",calendarToInputBottom:"vanilla-calendar_to-input_bottom",controls:"vanilla-calendar-controls",grid:"vanilla-calendar-grid",gridDisabled:"vanilla-calendar-grid_disabled",column:"vanilla-calendar-column",columnMonth:"vanilla-calendar-column_month",columnYear:"vanilla-calendar-column_year",header:"vanilla-calendar-header",headerContent:"vanilla-calendar-header__content",month:"vanilla-calendar-month",monthDisabled:"vanilla-calendar-month_disabled",year:"vanilla-calendar-year",yearDisabled:"vanilla-calendar-year_disabled",arrow:"vanilla-calendar-arrow",arrowPrev:"vanilla-calendar-arrow_prev",arrowNext:"vanilla-calendar-arrow_next",wrapper:"vanilla-calendar-wrapper",content:"vanilla-calendar-content",week:"vanilla-calendar-week",weekDay:"vanilla-calendar-week__day",weekDayWeekend:"vanilla-calendar-week__day_weekend",days:"vanilla-calendar-days",daysSelecting:"vanilla-calendar-days_selecting",months:"vanilla-calendar-months",monthsSelecting:"vanilla-calendar-months_selecting",monthsMonth:"vanilla-calendar-months__month",monthsMonthSelected:"vanilla-calendar-months__month_selected",monthsMonthDisabled:"vanilla-calendar-months__month_disabled",years:"vanilla-calendar-years",yearsSelecting:"vanilla-calendar-years_selecting",yearsYear:"vanilla-calendar-years__year",yearsYearSelected:"vanilla-calendar-years__year_selected",yearsYearDisabled:"vanilla-calendar-years__year_disabled",time:"vanilla-calendar-time",timeContent:"vanilla-calendar-time__content",timeHours:"vanilla-calendar-time__hours",timeMinutes:"vanilla-calendar-time__minutes",timeKeeping:"vanilla-calendar-time__keeping",timeRanges:"vanilla-calendar-time__ranges",timeRange:"vanilla-calendar-time__range",day:"vanilla-calendar-day",dayHoverFirst:"vanilla-calendar-day_hover-first",dayHoverLast:"vanilla-calendar-day_hover-last",dayHoverIntermediate:"vanilla-calendar-day_hover-intermediate",daySelectedFirst:"vanilla-calendar-day_selected-first",daySelectedLast:"vanilla-calendar-day_selected-last",daySelectedIntermediate:"vanilla-calendar-day_selected-intermediate",dayPopup:"vanilla-calendar-day__popup",dayBtn:"vanilla-calendar-day__btn",dayBtnPrev:"vanilla-calendar-day__btn_prev",dayBtnNext:"vanilla-calendar-day__btn_next",dayBtnToday:"vanilla-calendar-day__btn_today",dayBtnSelected:"vanilla-calendar-day__btn_selected",dayBtnHover:"vanilla-calendar-day__btn_hover",dayBtnDisabled:"vanilla-calendar-day__btn_disabled",dayBtnWeekend:"vanilla-calendar-day__btn_weekend",dayBtnHoliday:"vanilla-calendar-day__btn_holiday",weekNumbers:"vanilla-calendar-week-numbers",weekNumbersTitle:"vanilla-calendar-week-numbers__title",weekNumbersContent:"vanilla-calendar-week-numbers__content",weekNumber:"vanilla-calendar-week-number",isFocus:"vanilla-calendar-is-focus"},d=e=>`
<#ArrowPrev /><#ArrowNext />
<#Multiple>
<#Month /><#Year />
<#WeekNumbers />
<#Week /><#Days />
<#/Multiple>
<#ControlTime />`,o=e=>`
<#Month /><#Year />
<#Months />
`,c=e=>`
<#ArrowPrev />
<#Month /><#Year />
<#ArrowNext />
<#Years />
`;class u{constructor(){var e;r(this,"isInit",!1),r(this,"input",!1),r(this,"type","default"),r(this,"months",2),r(this,"jumpMonths",1),r(this,"date",{min:"1970-01-01",max:"2470-12-31",today:new Date}),r(this,"settings",{lang:"en",iso8601:!0,range:{min:this.date.min,max:this.date.max,disablePast:!1,disableGaps:!1,disableAllDays:!1,disableWeekday:void 0,disabled:void 0,enabled:void 0},selection:{day:"single",month:!0,year:!0,time:!1,controlTime:"all",stepHours:1,stepMinutes:1,cancelableDay:!0},selected:{dates:void 0,month:void 0,year:void 0,holidays:void 0,time:void 0},visibility:{theme:"system",themeDetect:"html[data-theme]",monthShort:!0,weekNumbers:!1,weekend:!0,today:!0,disabled:!1,daysOutside:!0,positionToInput:"left"}}),r(this,"locale",{months:[],weekday:[]}),r(this,"actions",{clickDay:null,clickWeekNumber:null,clickMonth:null,clickYear:null,clickArrow:null,changeTime:null,changeToInput:null,getDays:null,getMonths:null,getYears:null,initCalendar:null,updateCalendar:null,destroyCalendar:null,showCalendar:null,hideCalendar:null}),r(this,"popups",{}),r(this,"CSSClasses",l({},i)),r(this,"DOMTemplates",{default:(e=this.CSSClasses,`
<#ArrowPrev />
<#Month /><#Year />
<#ArrowNext />
<#WeekNumbers />
<#Week /><#Days />
<#ControlTime />`),multiple:d(this.CSSClasses),month:o(this.CSSClasses),year:c(this.CSSClasses)}),r(this,"HTMLElement"),r(this,"HTMLOriginalElement"),r(this,"HTMLInputElement"),r(this,"rangeMin"),r(this,"rangeMax"),r(this,"rangeDisabled"),r(this,"rangeEnabled"),r(this,"selectedDates"),r(this,"selectedHolidays"),r(this,"selectedMonth"),r(this,"selectedYear"),r(this,"selectedHours"),r(this,"selectedMinutes"),r(this,"selectedKeeping"),r(this,"selectedTime"),r(this,"currentType"),r(this,"correctMonths"),r(this,"viewYear"),r(this,"dateMin"),r(this,"dateMax")}}const m=e=>`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}`,g=e=>new Date(`${e}T00:00:00`),h=e=>e.reduce(((e,t)=>(t.match(/^(\d{4}-\d{2}-\d{2})$/g)?e.push(t):t.replace(/(\d{4}-\d{2}-\d{2}).*?(\d{4}-\d{2}-\d{2})/g,((t,a,n)=>{const s=g(a),l=g(n),r=new Date(s.getTime());for(;r<=l;r.setDate(r.getDate()+1))e.push(m(r));return t})),e)),[]),y=e=>e?{0:"12",13:"01",14:"02",15:"03",16:"04",17:"05",18:"06",19:"07",20:"08",21:"09",22:"10",23:"11"}[Number(e)]||String(e):"",v=e=>`${e} is not found, check the first argument passed to new VanillaCalendar.`,M='The calendar has not been initialized, please initialize it using the "init()" method first.',S='You specified "define" for "settings.lang" but did not provide the required values for "locale.weekday" or "locale.months".',p='Incorrect name of theme in "settings.visibility.theme".',C="The value of the time property can be: false, true, 12 or 24.",b=e=>{e.currentType=e.type,(e=>{const t=void 0!==e.settings.selected.month&&Number(e.settings.selected.month)>=0&&Number(e.settings.selected.month)<12,a=void 0!==e.settings.selected.year&&Number(e.settings.selected.year)>=0&&Number(e.settings.selected.year)<=9999;e.selectedMonth=t?Number(e.settings.selected.month):e.date.today.getMonth(),e.selectedYear=a?Number(e.settings.selected.year):e.date.today.getFullYear(),e.viewYear=e.selectedYear})(e),(e=>{var t,a,n;e.settings.range.min=g(e.date.min)>=g(e.settings.range.min)?e.date.min:e.settings.range.min,e.settings.range.max=g(e.date.max)<=g(e.settings.range.max)?e.date.max:e.settings.range.max;const s=e.settings.range.disablePast&&!e.settings.range.disableAllDays&&g(e.settings.range.min)1&&e.rangeDisabled.sort(((e,t)=>+new Date(e)-+new Date(t))),e.rangeEnabled=e.settings.range.enabled?h(e.settings.range.enabled):[],(null==(t=e.rangeEnabled)?void 0:t[0])&&(null==(a=e.rangeDisabled)?void 0:a[0])&&(e.rangeDisabled=e.rangeDisabled.filter((t=>!e.rangeEnabled.includes(t)))),e.rangeEnabled.length>1&&e.rangeEnabled.sort(((e,t)=>+new Date(e)-+new Date(t))),(null==(n=e.rangeEnabled)?void 0:n[0])&&e.settings.range.disableAllDays&&(e.rangeMin=e.rangeEnabled[0],e.rangeMax=e.rangeEnabled[e.rangeEnabled.length-1])})(e),(e=>{var t,a;e.selectedDates=(null==(t=e.settings.selected.dates)?void 0:t[0])?h(e.settings.selected.dates):[],e.selectedHolidays=(null==(a=e.settings.selected.holidays)?void 0:a[0])?h(e.settings.selected.holidays):[]})(e),(e=>{e.dateMin=e.settings.visibility.disabled?g(e.date.min):g(e.rangeMin),e.dateMax=e.settings.visibility.disabled?g(e.date.max):g(e.rangeMax)})(e),(e=>{const t=!0===e.settings.selection.time||12===e.settings.selection.time;if(t||24===e.settings.selection.time){let a=!1;if("string"==typeof e.settings.selected.time){const n=t?/^([0-9]|0[1-9]|1[0-2]):([0-5][0-9])|(AM|PM)/g:/^([0-1]?[0-9]|2[0-3]):([0-5][0-9])/g;e.settings.selected.time.replace(n,((n,s,l,r)=>(s&&l&&(a=!0,e.selectedHours=s,e.selectedMinutes=l),r&&t?e.selectedKeeping=r:t&&(e.selectedKeeping="AM"),"")))}!a&&t?(e.selectedHours=y(String(e.date.today.getHours())),e.selectedMinutes=String(e.date.today.getMinutes()),e.selectedKeeping=Number(e.date.today.getHours())>=12?"PM":"AM"):a||(e.selectedHours=String(e.date.today.getHours()),e.selectedMinutes=String(e.date.today.getMinutes())),e.selectedHours=Number(e.selectedHours)<10?`0${Number(e.selectedHours)}`:`${e.selectedHours}`,e.selectedMinutes=Number(e.selectedMinutes)<10?`0${Number(e.selectedMinutes)}`:`${e.selectedMinutes}`,e.selectedTime=`${e.selectedHours}:${e.selectedMinutes}${e.selectedKeeping?` ${e.selectedKeeping}`:""}`}else if(e.settings.selection.time)throw new Error(C)})(e),(e=>{e.correctMonths="multiple"===e.type?1===e.months?2:e.months>12?12:e.months:1})(e)},f=({arrowPrev:e,arrowNext:t,isPrevHidden:a,isNextHidden:n})=>{e.style.visibility=a?"hidden":"",t.style.visibility=n?"hidden":""},w=e=>{var t,a;if("month"===e.currentType)return;const n=null==(t=e.HTMLElement)?void 0:t.querySelector(`.${e.CSSClasses.arrowPrev}`),s=null==(a=e.HTMLElement)?void 0:a.querySelector(`.${e.CSSClasses.arrowNext}`);if(!n||!s)return;({default:()=>{const t=g(m(new Date(e.selectedYear,e.selectedMonth,1))),a=new Date(t.getTime()),l=new Date(t.getTime());a.setMonth(a.getMonth()-e.jumpMonths),l.setMonth(l.getMonth()+e.jumpMonths),e.settings.selection.year||(e.dateMin.setFullYear(t.getFullYear()),e.dateMax.setFullYear(t.getFullYear()));const r=!e.settings.selection.month||a.getFullYear()e.dateMax.getFullYear()||l.getFullYear()===e.dateMax.getFullYear()&&l.getMonth()>e.dateMax.getMonth();f({arrowPrev:n,arrowNext:s,isPrevHidden:r,isNextHidden:i})},year:()=>{f({arrowPrev:n,arrowNext:s,isPrevHidden:e.dateMin.getFullYear()&&e.viewYear-7<=e.dateMin.getFullYear(),isNextHidden:e.dateMax.getFullYear()&&e.viewYear+7>=e.dateMax.getFullYear()})}})["multiple"===e.currentType?"default":e.currentType]()},D=(e,t)=>{if(!e)return null;const a=g(e),n=t?a.getDay()||7:a.getDay();a.setDate(a.getDate()+4-n);const s=new Date(a.getFullYear(),0,1),l=Math.ceil(((+a-+s)/864e5+1)/7);return{year:a.getFullYear(),week:l}},T=(e,t,a,n,s)=>{const l=t[a].querySelector(`.${e.CSSClasses.dayBtn}`),r=D(null==l?void 0:l.dataset.calendarDay,e.settings.iso8601);if(!r)return;const i=n.cloneNode(!0);i.innerText=String(r.week),i.dataset.calendarYearWeek=String(r.year),s.append(i)},$=(e,t,a,n,s,l,r,i)=>{const d=document.createElement("div");d.className=e.CSSClasses.day;const o=document.createElement("button");o.className=`${e.CSSClasses.dayBtn}${i?` ${i}`:""}`,o.type="button",o.innerText=String(n),o.dataset.calendarDay=l;e.settings.visibility.weekNumbers&&(()=>{const t=D(l,e.settings.iso8601);t&&(o.dataset.calendarWeekNumber=String(t.week))})(),r?e.settings.visibility.daysOutside&&d.append(o):d.append(o),((e,t,a)=>{var n,s,l,r,i;const d=null==(n=e.settings.range.disableWeekday)?void 0:n.includes(a),o=e.settings.range.disableAllDays&&!!(null==(s=e.rangeEnabled)?void 0:s[0]);!d&&!o||(null==(l=e.rangeEnabled)?void 0:l.includes(t))||(null==(r=e.rangeDisabled)?void 0:r.includes(t))||(e.rangeDisabled.push(t),null==(i=e.rangeDisabled)||i.sort(((e,t)=>+new Date(e)-+new Date(t))))})(e,l,s),((e,t,a,n,s,l,r)=>{var i,d,o;(g(e.rangeMin)>g(l)||g(e.rangeMax)1&&"multiple-ranged"===e.settings.selection.day&&(e.selectedDates[0]===l&&a.classList.add(e.CSSClasses.daySelectedFirst),e.selectedDates[e.selectedDates.length-1]===l&&a.classList.add(e.CSSClasses.daySelectedLast),e.selectedDates[0]!==l&&e.selectedDates[e.selectedDates.length-1]!==l&&a.classList.add(e.CSSClasses.daySelectedIntermediate)))})(e,t,d,o,s,l,r),a.append(d),e.actions.getDays&&e.actions.getDays(n,l,d,o,e)},L=e=>{const t=e.HTMLElement.querySelectorAll(`.${e.CSSClasses.days}`),a=e.HTMLElement.querySelectorAll(`.${e.CSSClasses.weekNumbers}`),n=new Date(e.selectedYear,e.selectedMonth,1);t.forEach(((t,s)=>{const l=new Date(n);l.setMonth(l.getMonth()+s);const r=l.getMonth(),i=l.getFullYear(),d=new Date(i,r,1),o=new Date(i,r+1,0).getDate(),c=e.settings.iso8601?(0!==d.getDay()?d.getDay():7)-1:d.getDay();e.settings.selection.day&&t.classList.add(e.CSSClasses.daysSelecting),t.innerHTML="",((e,t,a,n,s)=>{let l=new Date(a,n,0).getDate()-(s-1);const r=0===n?a-1:a,i=0===n?12:n<10?`0${n}`:n;for(let n=s;n>0;n--,l++){const n=`${r}-${i}-${l}`,s=g(n).getDay();$(e,a,t,l,s,n,!0,e.CSSClasses.dayBtnPrev)}})(e,t,i,r,c),((e,t,a,n,s)=>{for(let l=1;l<=a;l++){const a=new Date(n,s,l),r=m(a),i=a.getDay();$(e,n,t,l,i,r,!1,null)}})(e,t,o,i,r),((e,t,a,n,s,l)=>{const r=l+a,i=7*Math.ceil(r/7)-r,d=s+1===12?n+1:n,o=s+1===12?"01":s+2<10?`0${s+2}`:s+2;for(let a=1;a<=i;a++){const s=`${d}-${o}-${a<10?`0${a}`:String(a)}`,l=g(s).getDay();$(e,n,t,a,l,s,!0,e.CSSClasses.dayBtnNext)}})(e,t,o,i,r,c),((e,t,a,n,s)=>{if(!e.settings.visibility.weekNumbers)return;n.innerHTML="";const l=document.createElement("b");l.className=e.CSSClasses.weekNumbersTitle,l.innerText="#",n.append(l);const r=document.createElement("div");r.className=e.CSSClasses.weekNumbersContent,n.append(r);const i=document.createElement("button");i.type="button",i.className=e.CSSClasses.weekNumber;const d=s.querySelectorAll(`.${e.CSSClasses.day}`),o=Math.ceil((t+a)/7);for(let t=0;t{var a;e.popups&&(null==(a=Object.entries(e.popups))||a.forEach((([a,n])=>((e,t,a,n)=>{const s=a.querySelector(`[data-calendar-day="${e}"]`);s&&((null==t?void 0:t.modifier)&&s.classList.add(...t.modifier.trim().split(" ")),(null==t?void 0:t.html)&&(s.parentElement.innerHTML+=`
${t.html}
`))})(a,n,t,e.CSSClasses.dayPopup))))})(e,t)}))},E=e=>{var t,a;const n=null==(t=e.HTMLElement)?void 0:t.querySelectorAll("[data-calendar-selected-month]"),s=null==(a=e.HTMLElement)?void 0:a.querySelectorAll("[data-calendar-selected-year]");if(!(null==n?void 0:n[0])&&(null==s?void 0:s[0]))return;const l=new Date(e.selectedYear,e.selectedMonth,1);null==n||n.forEach(((t,a)=>((e,t,a,n)=>{const s=new Date(n.setMonth(e.selectedMonth+a)).getMonth(),l=!1===e.settings.selection.month||"only-arrows"===e.settings.selection.month;t.tabIndex=l?-1:0,t.classList.toggle(e.CSSClasses.monthDisabled,l),t.setAttribute("data-calendar-selected-month",String(s)),t.innerText=e.locale.months[s]})(e,t,a,l))),null==s||s.forEach(((t,a)=>((e,t,a,n)=>{const s=new Date(n.setFullYear(e.selectedYear,e.selectedMonth+a)).getFullYear(),l=!1===e.settings.selection.year||"only-arrows"===e.settings.selection.year;t.tabIndex=l?-1:0,t.classList.toggle(e.CSSClasses.yearDisabled,l),t.setAttribute("data-calendar-selected-year",String(s)),t.innerText=String(s)})(e,t,a,l)))},H=(e,t)=>{const a=g(m(new Date(e.selectedYear,e.selectedMonth,1)));({prev:()=>a.setMonth(a.getMonth()-e.jumpMonths),next:()=>a.setMonth(a.getMonth()+e.jumpMonths)})[t](),[e.selectedMonth,e.selectedYear]=[a.getMonth(),a.getFullYear()],E(e),w(e),L(e)},k=Object.freeze(Object.defineProperty({__proto__:null,ArrowNext:e=>``,ArrowPrev:e=>``,ControlTime:e=>e.settings.selection.time?`
`:"",Days:e=>`
`,Month:e=>``,Months:e=>`
`,Week:e=>`
`,WeekNumbers:e=>e.settings.visibility.weekNumbers?`
`:"",Year:e=>``,Years:e=>`
`},Symbol.toStringTag,{value:"Module"})),Y=(e,t)=>t.replace(/[\n\t]/g,"").replace(/<#(?!\/?Multiple)(.*?)>/g,((t,a)=>{const n=(s=a.replace(/[/\s\n\t]/g,""),k[s]);var s;return n?n(e):""})).replace(/[\n\t]/g,""),x=(e,t)=>{const{HTMLElement:a,CSSClasses:n,DOMTemplates:s,type:l,currentType:r,correctMonths:i}=e,d=(s,l)=>{if(!t)return;const r=a.querySelector(`.${n.controls}`);r&&a.removeChild(r);a.querySelector(`.${n.grid}`).classList.add(n.gridDisabled);const i=t.closest(`.${n.column}`);i.classList.add(s),i.innerHTML=Y(e,l)},o={default:()=>{a.classList.add(n.calendarDefault),a.classList.remove(n.calendarMonth,n.calendarYear),a.innerHTML=Y(e,s.default)},multiple:()=>{i&&(a.classList.add(n.calendarMultiple),a.classList.remove(n.calendarMonth,n.calendarYear),a.innerHTML=((e,t)=>t.replace(/<#Multiple>(.*?)<#\/Multiple>/g,((t,a)=>{let n="";for(let t=0;t{"multiple"!==l?(a.classList.add(n.calendarMonth),a.classList.remove(n.calendarDefault,n.calendarYear),a.innerHTML=Y(e,s.month)):d(n.columnMonth,s.month)},year:()=>{"multiple"!==l?(a.classList.add(n.calendarYear),a.classList.remove(n.calendarDefault,n.calendarMonth),a.innerHTML=Y(e,s.year)):d(n.columnYear,s.year)}};a.classList.add(n.calendar),o[r]()},_=(e,t,a,n,s)=>{const l=t.cloneNode(!1);return l.className=`${e.CSSClasses.yearsYear}${a===s?` ${e.CSSClasses.yearsYearSelected}`:n?` ${e.CSSClasses.yearsYearDisabled}`:""}`,l.dataset.calendarYear=String(s),l.title=String(s),l.innerText=String(s),n&&(l.tabIndex=-1),l},N=(e,t)=>{const a=(null==t?void 0:t.dataset.calendarSelectedYear)?Number(null==t?void 0:t.dataset.calendarSelectedYear):e.selectedYear;e.currentType="year",x(e,t),E(e),w(e);const n=e.HTMLElement.querySelector(`.${e.CSSClasses.years}`);if(!e.settings.selection.year||!n)return;n.classList.add(e.CSSClasses.yearsSelecting);const s="multiple"!==e.type||e.selectedYear===a?0:1,l=document.createElement("button");l.type="button";for(let t=e.viewYear-7;te.dateMax.getFullYear(),i=_(e,l,a,r,t);n.append(i),e.actions.getYears&&e.actions.getYears(t,i,e)}},A=e=>`${e.charAt(0).toUpperCase()}${e.substring(1,e.length)}`.replace(/\./,""),F=(e,t)=>{const a=new Date(`1978-01-0${t+1}T00:00:00.000Z`).toLocaleString(e.settings.lang,{weekday:"short",timeZone:"UTC"});e.locale.weekday.push(A(a))},I=(e,t)=>{const a=new Date(`1978-${t+1<=9?`0${t+1}`:t+1}-01T00:00:00.000Z`).toLocaleString(e.settings.lang,{month:"long",timeZone:"UTC"});e.locale.months.push(A(a))},P=e=>{if("multiple"!==e.type)return 0;const t=[...e.HTMLElement.querySelectorAll(`.${e.CSSClasses.column}`)].findIndex((t=>t.classList.contains(`${e.CSSClasses.columnMonth}`)));return t>0?t:0},q=(e,t,a,n,s,l)=>{const r=t.cloneNode(!1);return r.className=`${e.CSSClasses.monthsMonth}${a===l?` ${e.CSSClasses.monthsMonthSelected}`:s?` ${e.CSSClasses.monthsMonthDisabled}`:""}`,r.title=n,r.innerText=`${e.settings.visibility.monthShort?n.substring(0,3):n}`,r.dataset.calendarMonth=String(l),s&&(r.tabIndex=-1),r},B=(e,t)=>{var a,n;const s=(null==t?void 0:t.dataset.calendarSelectedMonth)?Number(t.dataset.calendarSelectedMonth):e.selectedMonth,l=null==(a=null==t?void 0:t.closest(`.${e.CSSClasses.column}`))?void 0:a.querySelector(`.${e.CSSClasses.year}`),r=l?Number(l.dataset.calendarSelectedYear):e.selectedYear;e.currentType="month",x(e,t),E(e);const i=null==(n=e.HTMLElement)?void 0:n.querySelector(`.${e.CSSClasses.months}`);if(!e.settings.selection.month||!i)return;i.classList.add(e.CSSClasses.monthsSelecting);const d=e.jumpMonths>1?e.locale.months.map(((t,a)=>s-e.jumpMonths*a)).concat(e.locale.months.map(((t,a)=>s+e.jumpMonths*a))).filter((e=>e>=0&&e<=12)):Array.from(Array(12).keys()),o=document.createElement("button");o.type="button";for(let t=0;t<12;t++){const a=e.locale.months[t],n=te.dateMax.getMonth()+P(e)&&r>=e.dateMax.getFullYear()||t!==s&&!d.includes(t),l=q(e,o,s,a,n,t);i.append(l),e.actions.getMonths&&e.actions.getMonths(t,l,e)}},W=(e,t)=>e&&t?{0:{AM:"00",PM:"12"},1:{AM:"01",PM:"13"},2:{AM:"02",PM:"14"},3:{AM:"03",PM:"15"},4:{AM:"04",PM:"16"},5:{AM:"05",PM:"17"},6:{AM:"06",PM:"18"},7:{AM:"07",PM:"19"},8:{AM:"08",PM:"20"},9:{AM:"09",PM:"21"},10:{AM:"10",PM:"22"},11:{AM:"11",PM:"23"},12:{AM:"12",PM:"12"}}[Number(e)][t]:"",K=(e,t,a)=>e.querySelector(`.${t}${a?` input[name="${a}"]`:""}`),O=(e,t,a)=>{e.addEventListener("mouseover",(()=>t.classList.add(a))),e.addEventListener("mouseout",(()=>t.classList.remove(a)))},j=(e,t,a,n)=>{({hours:()=>{e.selectedHours=a},minutes:()=>{e.selectedMinutes=a}})[n](),e.selectedTime=`${e.selectedHours}:${e.selectedMinutes}${e.selectedKeeping?` ${e.selectedKeeping}`:""}`,e.actions.changeTime&&e.actions.changeTime(t,e),e.input&&e.HTMLInputElement&&e.actions.changeToInput&&e.actions.changeToInput(t,e)},R=(e,t,a,n,s,l)=>{t.addEventListener("input",(t=>{const r=t.target,i=Number(r.value),d=i<10?`0${i}`:`${i}`;if("hours"!==s||12!==l)return a.value=d,void j(e,t,d,s);i0?(a.value=d,e.selectedKeeping="AM",n.innerText=e.selectedKeeping,j(e,t,d,s)):(0===i?(e.selectedKeeping="AM",n.innerText="AM"):(e.selectedKeeping="PM",n.innerText="PM"),a.value=y(r.value),j(e,t,y(r.value),s))}))},z=(e,t,a,n,s,l)=>{a.addEventListener("change",(a=>{const r=a.target,i=Number(r.value),d=i<10?`0${i}`:`${i}`;"hours"===s&&12===l?r.value&&i<=l&&i>0?(r.value=d,t.value=W(d,e.selectedKeeping),j(e,a,d,s)):r.value&&i<24&&(i>l||0===i)?(0===i?(e.selectedKeeping="AM",n.innerText="AM"):(e.selectedKeeping="PM",n.innerText="PM"),r.value=y(r.value),t.value=d,j(e,a,y(r.value),s)):r.value=e.selectedHours:r.value&&i<=l&&i>=0?(r.value=d,t.value=d,j(e,a,d,s)):"hours"===s?r.value=e.selectedHours:"minutes"===s&&(r.value=e.selectedMinutes)}))},G=(e,t,a)=>{const n=24===a?23:a||12,s=K(t,e.CSSClasses.timeRange,"hours"),l=K(t,e.CSSClasses.timeRange,"minutes"),r=K(t,e.CSSClasses.timeHours,"hours"),i=K(t,e.CSSClasses.timeMinutes,"minutes"),d=t.querySelector(`.${e.CSSClasses.timeKeeping}`);O(s,r,e.CSSClasses.isFocus),O(l,i,e.CSSClasses.isFocus),R(e,s,r,d,"hours",n),R(e,l,i,d,"minutes",0),z(e,s,r,d,"hours",n),z(e,l,i,d,"minutes",59),d&&((e,t,a)=>{t.addEventListener("click",(n=>{e.selectedKeeping=t.innerText.includes("AM")?"PM":"AM",t.innerText=e.selectedKeeping,a.value=W(e.selectedHours,e.selectedKeeping),j(e,n,e.selectedHours,"hours")}))})(e,d,s)},Z=(e,t,a,n)=>``,U=(e,t,a,n,s,l)=>``,V=e=>{const t=[...e.locale.weekday];if(!t[0])return;e.settings.iso8601&&t.push(t.shift());e.HTMLElement.querySelectorAll(`.${e.CSSClasses.week}`).forEach((a=>((e,t,a)=>{const n=document.createElement("b");t.innerHTML="";for(let s=0;s{J.value=!0},check:()=>J.value},Q=(e,t)=>X.find((a=>{var n;return"system"!==a&&(null==(n=e.getAttribute(t))?void 0:n.includes(a))})),ee=(e,t)=>{e.dataset.calendarTheme=t},te=(e,t)=>{var a;if(a=t,ee(e.HTMLElement,a.matches?"dark":"light"),"system"!==e.settings.visibility.theme||J.check())return;const n=t=>{const a=document.querySelectorAll(`.${e.CSSClasses.calendar}`);null==a||a.forEach((e=>ee(e,t.matches?"dark":"light")))};t.addEventListener?t.addEventListener("change",n):t.addListener(n),J.set()},ae=(e,t)=>{const a=e.settings.visibility.themeDetect?document.querySelector(e.settings.visibility.themeDetect):null;if(!a)return void te(e,t);const n=e.settings.visibility.themeDetect.replace(/^.*\[(.+)\]/g,((e,t)=>t)),s=Q(a,n);s?(ee(e.HTMLElement,s),((e,t,a)=>{new MutationObserver((n=>{for(let s=0;s{const t={default:()=>{V(e),L(e)},multiple:()=>{V(e),L(e)},month:()=>B(e),year:()=>N(e)};(e=>{if(!X.includes(e.settings.visibility.theme))throw new Error(p);if("not all"===window.matchMedia("(prefers-color-scheme)").media)return void ee(e.HTMLElement,"light");({light:()=>ee(e.HTMLElement,"light"),dark:()=>ee(e.HTMLElement,"dark"),system:()=>ae(e,window.matchMedia("(prefers-color-scheme: dark)"))})[e.settings.visibility.theme]()})(e),(e=>{if("define"!==e.settings.lang||!e.locale.weekday[6]||!e.locale.months[11]){if("define"===e.settings.lang)throw new Error(S);e.locale.weekday=[],e.locale.months=[];for(let t=0;t<7;t++)F(e,t);for(let t=0;t<12;t++)I(e,t)}})(e),x(e),E(e),w(e),(e=>{const t=e.HTMLElement.querySelector(`.${e.CSSClasses.time}`);if(!t)return;const a=!0===e.settings.selection.time?12:e.settings.selection.time,n="range"===e.settings.selection.controlTime,[s,l]=[0,23],[r,i]=[0,59];t.innerHTML=`
${Z("hours",e.CSSClasses.timeHours,e.selectedHours,n)}${Z("minutes",e.CSSClasses.timeMinutes,e.selectedMinutes,n)}${12===a?``:""}
${U("hours",e.CSSClasses.timeRange,s,l,e.settings.selection.stepHours,e.selectedKeeping?W(e.selectedHours,e.selectedKeeping):e.selectedHours)}${U("minutes",e.CSSClasses.timeRange,r,i,e.settings.selection.stepMinutes,e.selectedMinutes)}
`,G(e,t,a)})(e),t[e.currentType]()},se={self:null,rangeMin:void 0,rangeMax:void 0},le=()=>{var e;if(!(null==(e=se.self)?void 0:e.HTMLElement))return;const{CSSClasses:t}=se.self;se.self.HTMLElement.querySelectorAll(`.${se.self.CSSClasses.dayBtnHover}`).forEach((e=>{var a;e.classList.remove(se.self.CSSClasses.dayBtnHover),null==(a=e.parentElement)||a.classList.remove(t.dayHoverIntermediate,t.dayHoverFirst,t.dayHoverLast)}))},re=(e,t,a)=>{var n,s,l;if(!(null==(n=se.self)?void 0:n.selectedDates))return;const r=m(e),{CSSClasses:i}=se.self;if(null==(s=se.self.rangeDisabled)?void 0:s.includes(r))return;const d=null==(l=se.self.HTMLElement)?void 0:l.querySelectorAll(`[data-calendar-day="${r}"]`);null==d||d.forEach((e=>{var t;e.classList.add(i.dayBtnHover),null==(t=e.parentElement)||t.classList.add(i.dayHoverIntermediate)})),null==t||t.forEach((e=>{var t;return null==(t=e.parentElement)?void 0:t.classList.add(i.dayHoverFirst)})),null==a||a.forEach((e=>{var t;return null==(t=e.parentElement)?void 0:t.classList.add(i.dayHoverLast)}))},ie=e=>{var t;if(!e.target||!(null==(t=se.self)?void 0:t.selectedDates))return;if(!e.target.closest(`.${se.self.CSSClasses.days}`))return void le();const a=e.target.closest("[data-calendar-day]");if(!a)return;const n=a.dataset.calendarDay,s=g(se.self.selectedDates[0]),l=g(n),r=se.self.HTMLElement.querySelectorAll(`[data-calendar-day="${se.self.selectedDates[0]}"]`),i=se.self.HTMLElement.querySelectorAll(`[data-calendar-day="${n}"]`),[d,o]=s{se.self&&"Escape"===e.key&&(se.self.selectedDates=[],se.self.HTMLElement.removeEventListener("mousemove",ie),document.removeEventListener("keydown",de),ne(se.self))},oe=(e,t)=>{var a;if(t){const n=1===e.selectedDates.length&&e.selectedDates[0].includes(t);e.selectedDates=n&&!e.settings.selection.cancelableDay?[t,t]:n&&e.settings.selection.cancelableDay?[]:e.selectedDates.length>1?[t]:[...e.selectedDates,t],null==(a=e.selectedDates)||a.sort(((e,t)=>+new Date(e)-+new Date(t)))}e.settings.range.disableGaps&&(se.rangeMin=se.rangeMin?se.rangeMin:e.rangeMin,se.rangeMax=se.rangeMax?se.rangeMax:e.rangeMax),se.self=e;const n={set:()=>{e.HTMLElement.addEventListener("mousemove",ie),document.addEventListener("keydown",de),e.settings.range.disableGaps&&(()=>{var e,t,a;if(!(null==(t=null==(e=se.self)?void 0:e.selectedDates)?void 0:t[0])||!se.self.rangeDisabled||(null==(a=se.self.rangeDisabled)?void 0:a.length)<2)return;const n=g(se.self.selectedDates[0]),[s,l]=se.self.rangeDisabled.map((e=>g(e))).reduce((([e,t],a)=>[n>=a?a:e,n{const[t,a]=[e.selectedDates[0],e.selectedDates[e.selectedDates.length-1]];e.selectedDates=e.selectedDates[0]!==e.selectedDates[e.selectedDates.length-1]?h([`${t}:${a}`]):[e.selectedDates[0],e.selectedDates[0]],e.HTMLElement.removeEventListener("mousemove",ie),document.removeEventListener("keydown",de),e.settings.range.disableGaps&&se.self&&(se.self.rangeMin=se.rangeMin,se.self.rangeMax=se.rangeMax)}};n[1===e.selectedDates.length?"set":"reset"]()},ce=(e,t,a)=>{if(!t.dataset.calendarDay)return;const n=t.dataset.calendarDay,s=t.classList.contains(e.CSSClasses.dayBtnSelected);s&&!e.settings.selection.cancelableDay||(e.selectedDates=s?e.selectedDates.filter((e=>e!==n)):a?[...e.selectedDates,n]:[n])},ue=(e,t,a,n,s)=>{const l=e.HTMLElement.querySelectorAll(`.${e.CSSClasses.column}`),r=[...l].findIndex((e=>e.classList.contains(t))),i=Number(l[r].querySelector(`.${a}`).getAttribute(s));return"month"===e.currentType&&r>=0?n-r:"year"===e.currentType&&e.selectedYear!==i?n-1:n},me=(e,t,a,n)=>{if(!e.settings.selection[a])return;const s=t.target,l=e=>s.closest(`.${e}`),r=l(n.header),i=l(n.item),d=l(e.CSSClasses.grid),o=l(e.CSSClasses.column);if(e.currentType!==a&&r){({year:()=>N(e,s),month:()=>B(e,s)})[a]()}else i?((e,t,a,n,s)=>{const l={year:()=>{var a,n;return null==(n=(a=e.actions).clickYear)?void 0:n.call(a,t,e)},month:()=>{var a,n;return null==(n=(a=e.actions).clickMonth)?void 0:n.call(a,t,e)}};({year:()=>{if("multiple"===e.type){const t=ue(e,e.CSSClasses.columnYear,e.CSSClasses.year,Number(s.dataset.calendarYear),"data-calendar-selected-year"),a=e.selectedMonthe.dateMax.getMonth()&&t>=e.dateMax.getFullYear(),l=te.dateMax.getFullYear();a||l?(e.selectedYear=e.dateMin.getFullYear(),e.selectedMonth=e.dateMin.getMonth()):n||r?(e.selectedYear=e.dateMax.getFullYear(),e.selectedMonth=e.dateMax.getMonth()):e.selectedYear=t}else e.selectedYear=Number(s.dataset.calendarYear)},month:()=>{if("multiple"===e.type){const t=ue(e,e.CSSClasses.columnMonth,e.CSSClasses.month,Number(s.dataset.calendarMonth),"data-calendar-selected-month"),a=s.closest(`.${n.column}`).querySelector(`.${e.CSSClasses.year}`);e.selectedYear=Number(a.dataset.calendarSelectedYear);const l=te.dateMax.getMonth()&&e.selectedYear>=e.dateMax.getFullYear();e.selectedMonth=l?e.dateMin.getMonth():r?e.dateMax.getMonth():t}else e.selectedMonth=Number(s.dataset.calendarMonth)}})[a](),l[a](),e.currentType=e.type,ne(e)})(e,t,a,n,i):(e.currentType===a&&r||"multiple"===e.type&&e.currentType===a&&d&&!o)&&(e.currentType=e.type,ne(e))},ge=e=>{const t=t=>{((e,t)=>{const a=t.target.closest(`.${e.CSSClasses.arrow}`);a&&(["default","multiple"].includes(e.currentType)?H(e,a.dataset.calendarArrow):"year"===e.currentType&&void 0!==e.viewYear&&(e.viewYear+={prev:-15,next:15}[a.dataset.calendarArrow],N(e,t.target)),e.actions.clickArrow&&e.actions.clickArrow(t,e))})(e,t),((e,t)=>{var a;if(!e.settings.visibility.weekNumbers||!e.actions.clickWeekNumber)return;const n=t.target.closest(`.${e.CSSClasses.weekNumber}`),s=null==(a=e.HTMLElement)?void 0:a.querySelectorAll("[data-calendar-week-number]");if(!n||!s)return;const l=Number(n.innerText),r=Number(n.dataset.calendarYearWeek),i=[...s].filter((e=>Number(e.dataset.calendarWeekNumber)===l));e.actions.clickWeekNumber(t,l,i,r,e)})(e,t),((e,t)=>{var a;const n=t.target,s=e=>n.closest(`.${e}`),l=s(e.CSSClasses.dayBtn);if(!e.settings.selection.day||!["single","multiple","multiple-ranged"].includes(e.settings.selection.day)||!l)return;({single:()=>ce(e,l,!1),multiple:()=>ce(e,l,!0),"multiple-ranged":()=>oe(e,l.dataset.calendarDay)})[e.settings.selection.day](),null==(a=e.selectedDates)||a.sort(((e,t)=>+new Date(e)-+new Date(t))),e.actions.clickDay&&e.actions.clickDay(t,e),e.input&&e.HTMLInputElement&&e.HTMLElement&&e.actions.changeToInput&&e.actions.changeToInput(t,e);const r=s(e.CSSClasses.dayBtnPrev),i=s(e.CSSClasses.dayBtnNext);({prev:()=>H(e,"prev"),next:()=>H(e,"next"),default:()=>L(e)})[r?"prev":i?"next":"default"]()})(e,t),me(e,t,"month",{header:e.CSSClasses.month,item:e.CSSClasses.monthsMonth,column:e.CSSClasses.columnMonth}),me(e,t,"year",{header:e.CSSClasses.year,item:e.CSSClasses.yearsYear,column:e.CSSClasses.columnYear})};return e.HTMLElement.addEventListener("click",t),()=>e.HTMLElement.removeEventListener("click",t)},he=(e,{year:t,month:a,dates:n,holidays:s,time:r}={})=>{var i;const d=l({},e.settings.selected);e.settings.selected.year=t?d.year:e.selectedYear,e.settings.selected.month=a?d.month:e.selectedMonth,e.settings.selected.holidays=s?d.holidays:e.selectedHolidays,e.settings.selected.time=r?d.time:e.selectedTime,e.settings.selected.dates="only-first"===n&&(null==(i=e.selectedDates)?void 0:i[0])?[e.selectedDates[0]]:!0===n?d.dates:e.selectedDates,b(e),ne(e),e.settings.selected=d,"multiple-ranged"===e.settings.selection.day&&n&&oe(e)},ye=(e,t,a,n)=>{const s={top:-t.offsetHeight,bottom:e.offsetHeight,left:0,center:e.offsetWidth/2-t.offsetWidth/2,right:e.offsetWidth-t.offsetWidth},l=Array.isArray(a)?a[0]:"bottom",r=Array.isArray(a)?a[1]:a;t.classList.add("bottom"===l?n.calendarToInputBottom:n.calendarToInputTop);const i=e.getBoundingClientRect(),d=window.scrollX||document.documentElement.scrollLeft,o=window.scrollY||document.documentElement.scrollTop,c=i.top+o+s[l],u=i.left+d+s[r];Object.assign(t.style,{left:`${u}px`,top:`${c}px`})},ve=e=>{let t=!0;const a=[];e.HTMLInputElement=e.HTMLElement;const n=()=>ye(e.HTMLInputElement,e.HTMLElement,e.settings.visibility.positionToInput,e.CSSClasses),s=t=>{var a;e&&t.target!==e.HTMLInputElement&&!(null==(a=e.HTMLElement)?void 0:a.contains(t.target))&&(e.HTMLInputElement&&e.HTMLElement&&e.hide(),window.removeEventListener("resize",n),document.removeEventListener("click",s,{capture:!0}))};return e.HTMLInputElement.addEventListener("click",(()=>{t?a.push((()=>{const a=document.createElement("div");return a.className=`${e.CSSClasses.calendar} ${e.CSSClasses.calendarToInput} ${e.CSSClasses.calendarHidden}`,e.HTMLElement=a,document.body.append(e.HTMLElement),t=!1,setTimeout((()=>{ye(e.HTMLInputElement,a,e.settings.visibility.positionToInput,e.CSSClasses),e.show()}),0),he(e,{year:!0,month:!0,dates:!0,holidays:!0,time:!0}),e.actions.initCalendar&&e.actions.initCalendar(e),ge(e)})()):(ye(e.HTMLInputElement,e.HTMLElement,e.settings.visibility.positionToInput,e.CSSClasses),e.show()),window.addEventListener("resize",n),document.addEventListener("click",s,{capture:!0})})),()=>{a.forEach((e=>e()))}};return class extends u{constructor(e,t){if(super(),r(this,"init",(()=>{return(e=this).HTMLOriginalElement=e.HTMLElement.cloneNode(!0),e.isInit=!0,e.input?ve(e):(b(e),ne(e),e.actions.initCalendar&&e.actions.initCalendar(e),ge(e));var e})),r(this,"update",(e=>((e,{year:t,month:a,dates:n,holidays:s,time:l}={})=>{if(!e.isInit)throw new Error(M);he(e,{year:t,month:a,dates:n,holidays:s,time:l}),e.actions.updateCalendar&&e.actions.updateCalendar(e)})(this,e))),r(this,"destroy",(()=>(e=>{var t,a,n,s;if(!e.isInit)throw new Error(M);e.input?(null==(a=null==(t=e.HTMLElement)?void 0:t.parentElement)||a.removeChild(e.HTMLElement),null==(n=e.HTMLInputElement)||n.replaceWith(e.HTMLOriginalElement),e.HTMLInputElement=void 0):null==(s=e.HTMLElement)||s.replaceWith(e.HTMLOriginalElement),e.HTMLElement=e.HTMLOriginalElement,e.actions.destroyCalendar&&e.actions.destroyCalendar(e)})(this))),r(this,"show",(()=>{var e;(e=this).currentType?(e.HTMLElement.classList.remove(e.CSSClasses.calendarHidden),e.actions.showCalendar&&e.actions.showCalendar(e)):e.HTMLElement.click()})),r(this,"hide",(()=>{var e;(e=this).currentType&&(e.HTMLElement.classList.add(e.CSSClasses.calendarHidden),e.actions.hideCalendar&&e.actions.hideCalendar(e))})),this.HTMLElement="string"==typeof e?document.querySelector(e):e,!this.HTMLElement)throw new Error(v(e));if(!t)return;const a=(e,t)=>{Object.keys(t).forEach((n=>{"object"!=typeof e[n]||"object"!=typeof t[n]||t[n]instanceof Date?e[n]=t[n]:a(e[n],t[n])}))};a(this,t)}}})); \ No newline at end of file diff --git a/package/build/vanilla-calendar.min.mjs b/package/build/vanilla-calendar.min.mjs index 38818168..afef69a8 100644 --- a/package/build/vanilla-calendar.min.mjs +++ b/package/build/vanilla-calendar.min.mjs @@ -1,2 +1,2 @@ /*! name: vanilla-calendar-pro | url: https://github.com/uvarov-frontend/vanilla-calendar-pro */ -var __defProp=Object.defineProperty,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(e,t,a)=>t in e?__defProp(e,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[t]=a,__spreadValues=(e,t)=>{for(var a in t||(t={}))__hasOwnProp.call(t,a)&&__defNormalProp(e,a,t[a]);if(__getOwnPropSymbols)for(var a of __getOwnPropSymbols(t))__propIsEnum.call(t,a)&&__defNormalProp(e,a,t[a]);return e},__publicField=(e,t,a)=>(__defNormalProp(e,"symbol"!=typeof t?t+"":t,a),a);const classes={calendar:"vanilla-calendar",calendarDefault:"vanilla-calendar_default",calendarMultiple:"vanilla-calendar_multiple",calendarMonth:"vanilla-calendar_month",calendarYear:"vanilla-calendar_year",calendarHidden:"vanilla-calendar_hidden",calendarToInput:"vanilla-calendar_to-input",calendarToInputTop:"vanilla-calendar_to-input_top",calendarToInputBottom:"vanilla-calendar_to-input_bottom",controls:"vanilla-calendar-controls",grid:"vanilla-calendar-grid",gridDisabled:"vanilla-calendar-grid_disabled",column:"vanilla-calendar-column",columnMonth:"vanilla-calendar-column_month",columnYear:"vanilla-calendar-column_year",header:"vanilla-calendar-header",headerContent:"vanilla-calendar-header__content",month:"vanilla-calendar-month",monthDisabled:"vanilla-calendar-month_disabled",year:"vanilla-calendar-year",yearDisabled:"vanilla-calendar-year_disabled",arrow:"vanilla-calendar-arrow",arrowPrev:"vanilla-calendar-arrow_prev",arrowNext:"vanilla-calendar-arrow_next",wrapper:"vanilla-calendar-wrapper",content:"vanilla-calendar-content",week:"vanilla-calendar-week",weekDay:"vanilla-calendar-week__day",weekDayWeekend:"vanilla-calendar-week__day_weekend",days:"vanilla-calendar-days",daysSelecting:"vanilla-calendar-days_selecting",months:"vanilla-calendar-months",monthsSelecting:"vanilla-calendar-months_selecting",monthsMonth:"vanilla-calendar-months__month",monthsMonthSelected:"vanilla-calendar-months__month_selected",monthsMonthDisabled:"vanilla-calendar-months__month_disabled",years:"vanilla-calendar-years",yearsSelecting:"vanilla-calendar-years_selecting",yearsYear:"vanilla-calendar-years__year",yearsYearSelected:"vanilla-calendar-years__year_selected",yearsYearDisabled:"vanilla-calendar-years__year_disabled",time:"vanilla-calendar-time",timeContent:"vanilla-calendar-time__content",timeHours:"vanilla-calendar-time__hours",timeMinutes:"vanilla-calendar-time__minutes",timeKeeping:"vanilla-calendar-time__keeping",timeRanges:"vanilla-calendar-time__ranges",timeRange:"vanilla-calendar-time__range",day:"vanilla-calendar-day",dayHoverFirst:"vanilla-calendar-day_hover-first",dayHoverLast:"vanilla-calendar-day_hover-last",dayHoverIntermediate:"vanilla-calendar-day_hover-intermediate",daySelectedFirst:"vanilla-calendar-day_selected-first",daySelectedLast:"vanilla-calendar-day_selected-last",daySelectedIntermediate:"vanilla-calendar-day_selected-intermediate",dayPopup:"vanilla-calendar-day__popup",dayBtn:"vanilla-calendar-day__btn",dayBtnPrev:"vanilla-calendar-day__btn_prev",dayBtnNext:"vanilla-calendar-day__btn_next",dayBtnToday:"vanilla-calendar-day__btn_today",dayBtnSelected:"vanilla-calendar-day__btn_selected",dayBtnHover:"vanilla-calendar-day__btn_hover",dayBtnDisabled:"vanilla-calendar-day__btn_disabled",dayBtnWeekend:"vanilla-calendar-day__btn_weekend",dayBtnHoliday:"vanilla-calendar-day__btn_holiday",weekNumbers:"vanilla-calendar-week-numbers",weekNumbersTitle:"vanilla-calendar-week-numbers__title",weekNumbersContent:"vanilla-calendar-week-numbers__content",weekNumber:"vanilla-calendar-week-number",isFocus:"vanilla-calendar-is-focus"},DOMDefault=e=>`
<#ArrowPrev />
<#Month /><#Year />
<#ArrowNext />
<#WeekNumbers />
<#Week /><#Days />
<#ControlTime />`,DOMMultiple=e=>`
<#ArrowPrev /><#ArrowNext />
<#Multiple>
<#Month /><#Year />
<#WeekNumbers />
<#Week /><#Days />
<#/Multiple>
<#ControlTime />`,DOMMonths=e=>`
<#Month /><#Year />
<#Months />
`,DOMYears=e=>`
<#ArrowPrev />
<#Month /><#Year />
<#ArrowNext />
<#Years />
`;class DefaultOptionsCalendar{constructor(){var e;__publicField(this,"isInit",!1),__publicField(this,"input",!1),__publicField(this,"type","default"),__publicField(this,"months",2),__publicField(this,"jumpMonths",1),__publicField(this,"date",{min:"1970-01-01",max:"2470-12-31",today:new Date}),__publicField(this,"settings",{lang:"en",iso8601:!0,range:{min:this.date.min,max:this.date.max,disablePast:!1,disableGaps:!1,disableAllDays:!1,disableWeekday:void 0,disabled:void 0,enabled:void 0},selection:{day:"single",month:!0,year:!0,time:!1,controlTime:"all",stepHours:1,stepMinutes:1,cancelableDay:!0},selected:{dates:void 0,month:void 0,year:void 0,holidays:void 0,time:void 0},visibility:{theme:"system",themeDetect:"html[data-theme]",monthShort:!0,weekNumbers:!1,weekend:!0,today:!0,disabled:!1,daysOutside:!0,positionToInput:"left"}}),__publicField(this,"locale",{months:[],weekday:[]}),__publicField(this,"actions",{clickDay:null,clickWeekNumber:null,clickMonth:null,clickYear:null,clickArrow:null,changeTime:null,changeToInput:null,getDays:null,getMonths:null,getYears:null,hideCalendar:null,showCalendar:null}),__publicField(this,"popups",{}),__publicField(this,"CSSClasses",__spreadValues({},classes)),__publicField(this,"DOMTemplates",{default:(e=this.CSSClasses,`
<#ArrowPrev />
<#Month /><#Year />
<#ArrowNext />
<#WeekNumbers />
<#Week /><#Days />
<#ControlTime />`),multiple:DOMMultiple(this.CSSClasses),month:DOMMonths(this.CSSClasses),year:DOMYears(this.CSSClasses)}),__publicField(this,"HTMLElement"),__publicField(this,"HTMLOriginalElement"),__publicField(this,"HTMLInputElement"),__publicField(this,"rangeMin"),__publicField(this,"rangeMax"),__publicField(this,"rangeDisabled"),__publicField(this,"rangeEnabled"),__publicField(this,"selectedDates"),__publicField(this,"selectedHolidays"),__publicField(this,"selectedMonth"),__publicField(this,"selectedYear"),__publicField(this,"selectedHours"),__publicField(this,"selectedMinutes"),__publicField(this,"selectedKeeping"),__publicField(this,"selectedTime"),__publicField(this,"currentType"),__publicField(this,"correctMonths"),__publicField(this,"viewYear"),__publicField(this,"dateMin"),__publicField(this,"dateMax")}}const getDateString=e=>`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}`,getDate=e=>new Date(`${e}T00:00:00`),parseDates=e=>e.reduce(((e,t)=>(t.match(/^(\d{4}-\d{2}-\d{2})$/g)?e.push(t):t.replace(/(\d{4}-\d{2}-\d{2}).*?(\d{4}-\d{2}-\d{2})/g,((t,a,n)=>{const s=getDate(a),l=getDate(n),r=new Date(s.getTime());for(;r<=l;r.setDate(r.getDate()+1))e.push(getDateString(r));return t})),e)),[]),transformTime12=e=>e?{0:"12",13:"01",14:"02",15:"03",16:"04",17:"05",18:"06",19:"07",20:"08",21:"09",22:"10",23:"11"}[Number(e)]||String(e):"",messages={notFoundSelector:e=>`${e} is not found, check the first argument passed to new VanillaCalendar.`,notInit:'The calendar has not been initialized, please initialize it using the "init()" method first.',notLocale:'You specified "define" for "settings.lang" but did not provide the required values for "locale.weekday" or "locale.months".',incorrectTheme:'Incorrect name of theme in "settings.visibility.theme".',incorrectTime:"The value of the time property can be: false, true, 12 or 24."},initSelectedMonthYear=e=>{const t=void 0!==e.settings.selected.month&&Number(e.settings.selected.month)>=0&&Number(e.settings.selected.month)<12,a=void 0!==e.settings.selected.year&&Number(e.settings.selected.year)>=0&&Number(e.settings.selected.year)<=9999;e.selectedMonth=t?Number(e.settings.selected.month):e.date.today.getMonth(),e.selectedYear=a?Number(e.settings.selected.year):e.date.today.getFullYear(),e.viewYear=e.selectedYear},initRange=e=>{var t,a,n;e.settings.range.min=getDate(e.date.min)>=getDate(e.settings.range.min)?e.date.min:e.settings.range.min,e.settings.range.max=getDate(e.date.max)<=getDate(e.settings.range.max)?e.date.max:e.settings.range.max;const s=e.settings.range.disablePast&&!e.settings.range.disableAllDays&&getDate(e.settings.range.min)1&&e.rangeDisabled.sort(((e,t)=>+new Date(e)-+new Date(t))),e.rangeEnabled=e.settings.range.enabled?parseDates(e.settings.range.enabled):[],(null==(t=e.rangeEnabled)?void 0:t[0])&&(null==(a=e.rangeDisabled)?void 0:a[0])&&(e.rangeDisabled=e.rangeDisabled.filter((t=>!e.rangeEnabled.includes(t)))),e.rangeEnabled.length>1&&e.rangeEnabled.sort(((e,t)=>+new Date(e)-+new Date(t))),(null==(n=e.rangeEnabled)?void 0:n[0])&&e.settings.range.disableAllDays&&(e.rangeMin=e.rangeEnabled[0],e.rangeMax=e.rangeEnabled[e.rangeEnabled.length-1])},initSelectedDates=e=>{var t,a;e.selectedDates=(null==(t=e.settings.selected.dates)?void 0:t[0])?parseDates(e.settings.selected.dates):[],e.selectedHolidays=(null==(a=e.settings.selected.holidays)?void 0:a[0])?parseDates(e.settings.selected.holidays):[]},initDateMinMax=e=>{e.dateMin=e.settings.visibility.disabled?getDate(e.date.min):getDate(e.rangeMin),e.dateMax=e.settings.visibility.disabled?getDate(e.date.max):getDate(e.rangeMax)},initTime=e=>{const t=!0===e.settings.selection.time||12===e.settings.selection.time;if(t||24===e.settings.selection.time){let a=!1;if("string"==typeof e.settings.selected.time){const n=t?/^([0-9]|0[1-9]|1[0-2]):([0-5][0-9])|(AM|PM)/g:/^([0-1]?[0-9]|2[0-3]):([0-5][0-9])/g;e.settings.selected.time.replace(n,((n,s,l,r)=>(s&&l&&(a=!0,e.selectedHours=s,e.selectedMinutes=l),r&&t?e.selectedKeeping=r:t&&(e.selectedKeeping="AM"),"")))}!a&&t?(e.selectedHours=transformTime12(String(e.date.today.getHours())),e.selectedMinutes=String(e.date.today.getMinutes()),e.selectedKeeping=Number(e.date.today.getHours())>=12?"PM":"AM"):a||(e.selectedHours=String(e.date.today.getHours()),e.selectedMinutes=String(e.date.today.getMinutes())),e.selectedHours=Number(e.selectedHours)<10?`0${Number(e.selectedHours)}`:`${e.selectedHours}`,e.selectedMinutes=Number(e.selectedMinutes)<10?`0${Number(e.selectedMinutes)}`:`${e.selectedMinutes}`,e.selectedTime=`${e.selectedHours}:${e.selectedMinutes}${e.selectedKeeping?` ${e.selectedKeeping}`:""}`}else if(e.settings.selection.time)throw new Error(messages.incorrectTime)},initCorrectMonths=e=>{e.correctMonths="multiple"===e.type?1===e.months?2:e.months>12?12:e.months:1},setVariables=e=>{e.currentType=e.type,initSelectedMonthYear(e),initRange(e),initSelectedDates(e),initDateMinMax(e),initTime(e),initCorrectMonths(e)},actionsInput=e=>({hide(){e.HTMLElement.classList.add(e.CSSClasses.calendarHidden),e.actions.hideCalendar&&e.actions.hideCalendar(e)},show(){e.HTMLElement.classList.remove(e.CSSClasses.calendarHidden),e.actions.showCalendar&&e.actions.showCalendar(e)},self:e}),setVisibilityArrows=({arrowPrev:e,arrowNext:t,isPrevHidden:a,isNextHidden:n})=>{e.style.visibility=a?"hidden":"",t.style.visibility=n?"hidden":""},visibilityArrows=e=>{var t,a;if("month"===e.currentType)return;const n=null==(t=e.HTMLElement)?void 0:t.querySelector(`.${e.CSSClasses.arrowPrev}`),s=null==(a=e.HTMLElement)?void 0:a.querySelector(`.${e.CSSClasses.arrowNext}`);if(!n||!s)return;({default:()=>{const t=getDate(getDateString(new Date(e.selectedYear,e.selectedMonth,1))),a=new Date(t.getTime()),l=new Date(t.getTime());a.setMonth(a.getMonth()-e.jumpMonths),l.setMonth(l.getMonth()+e.jumpMonths),e.settings.selection.year||(e.dateMin.setFullYear(t.getFullYear()),e.dateMax.setFullYear(t.getFullYear()));const r=!e.settings.selection.month||a.getFullYear()e.dateMax.getFullYear()||l.getFullYear()===e.dateMax.getFullYear()&&l.getMonth()>e.dateMax.getMonth();setVisibilityArrows({arrowPrev:n,arrowNext:s,isPrevHidden:r,isNextHidden:i})},year:()=>{setVisibilityArrows({arrowPrev:n,arrowNext:s,isPrevHidden:e.dateMin.getFullYear()&&e.viewYear-7<=e.dateMin.getFullYear(),isNextHidden:e.dateMax.getFullYear()&&e.viewYear+7>=e.dateMax.getFullYear()})}})["multiple"===e.currentType?"default":e.currentType]()},getWeekNumber=(e,t)=>{if(!e)return null;const a=getDate(e),n=t?a.getDay()||7:a.getDay();a.setDate(a.getDate()+4-n);const s=new Date(a.getFullYear(),0,1),l=Math.ceil(((+a-+s)/864e5+1)/7);return{year:a.getFullYear(),week:l}},handleDay=(e,t,a,n)=>{const s=a.querySelector(`[data-calendar-day="${e}"]`);s&&((null==t?void 0:t.modifier)&&s.classList.add(...t.modifier.trim().split(" ")),(null==t?void 0:t.html)&&(s.parentElement.innerHTML+=`
${t.html}
`))},createPopup=(e,t)=>{var a;e.popups&&(null==(a=Object.entries(e.popups))||a.forEach((([a,n])=>handleDay(a,n,t,e.CSSClasses.dayPopup))))},createWeekNumber=(e,t,a,n,s)=>{const l=t[a].querySelector(`.${e.CSSClasses.dayBtn}`),r=getWeekNumber(null==l?void 0:l.dataset.calendarDay,e.settings.iso8601);if(!r)return;const i=n.cloneNode(!0);i.innerText=String(r.week),i.dataset.calendarYearWeek=String(r.year),s.append(i)},createWeekNumbers=(e,t,a,n,s)=>{if(!e.settings.visibility.weekNumbers)return;n.innerHTML="";const l=document.createElement("b");l.className=e.CSSClasses.weekNumbersTitle,l.innerText="#",n.append(l);const r=document.createElement("div");r.className=e.CSSClasses.weekNumbersContent,n.append(r);const i=document.createElement("button");i.type="button",i.className=e.CSSClasses.weekNumber;const d=s.querySelectorAll(`.${e.CSSClasses.day}`),c=Math.ceil((t+a)/7);for(let t=0;t{var n,s,l,r,i;const d=null==(n=e.settings.range.disableWeekday)?void 0:n.includes(a),c=e.settings.range.disableAllDays&&!!(null==(s=e.rangeEnabled)?void 0:s[0]);!d&&!c||(null==(l=e.rangeEnabled)?void 0:l.includes(t))||(null==(r=e.rangeDisabled)?void 0:r.includes(t))||(e.rangeDisabled.push(t),null==(i=e.rangeDisabled)||i.sort(((e,t)=>+new Date(e)-+new Date(t))))},setDayModifier=(e,t,a,n,s,l,r)=>{var i,d,c;(getDate(e.rangeMin)>getDate(l)||getDate(e.rangeMax)1&&"multiple-ranged"===e.settings.selection.day&&(e.selectedDates[0]===l&&a.classList.add(e.CSSClasses.daySelectedFirst),e.selectedDates[e.selectedDates.length-1]===l&&a.classList.add(e.CSSClasses.daySelectedLast),e.selectedDates[0]!==l&&e.selectedDates[e.selectedDates.length-1]!==l&&a.classList.add(e.CSSClasses.daySelectedIntermediate)))},createDay=(e,t,a,n,s,l,r,i)=>{const d=document.createElement("div");d.className=e.CSSClasses.day;const c=document.createElement("button");c.className=`${e.CSSClasses.dayBtn}${i?` ${i}`:""}`,c.type="button",c.innerText=String(n),c.dataset.calendarDay=l;e.settings.visibility.weekNumbers&&(()=>{const t=getWeekNumber(l,e.settings.iso8601);t&&(c.dataset.calendarWeekNumber=String(t.week))})(),r?e.settings.visibility.daysOutside&&d.append(c):d.append(c),setDisabledDays(e,l,s),setDayModifier(e,t,d,c,s,l,r),a.append(d),e.actions.getDays&&e.actions.getDays(n,l,d,c,e)},prevMonth=(e,t,a,n,s)=>{let l=new Date(a,n,0).getDate()-(s-1);const r=0===n?a-1:a,i=0===n?12:n<10?`0${n}`:n;for(let n=s;n>0;n--,l++){const n=`${r}-${i}-${l}`,s=getDate(n).getDay();createDay(e,a,t,l,s,n,!0,e.CSSClasses.dayBtnPrev)}},currentMonth=(e,t,a,n,s)=>{for(let l=1;l<=a;l++){const a=new Date(n,s,l),r=getDateString(a),i=a.getDay();createDay(e,n,t,l,i,r,!1,null)}},nextMonth=(e,t,a,n,s,l)=>{const r=l+a,i=7*Math.ceil(r/7)-r,d=s+1===12?n+1:n,c=s+1===12?"01":s+2<10?`0${s+2}`:s+2;for(let a=1;a<=i;a++){const s=`${d}-${c}-${a<10?`0${a}`:String(a)}`,l=getDate(s).getDay();createDay(e,n,t,a,l,s,!0,e.CSSClasses.dayBtnNext)}},createDays=e=>{const t=e.HTMLElement.querySelectorAll(`.${e.CSSClasses.days}`),a=e.HTMLElement.querySelectorAll(`.${e.CSSClasses.weekNumbers}`),n=new Date(e.selectedYear,e.selectedMonth,1);t.forEach(((t,s)=>{const l=new Date(n);l.setMonth(l.getMonth()+s);const r=l.getMonth(),i=l.getFullYear(),d=new Date(i,r,1),c=new Date(i,r+1,0).getDate(),o=e.settings.iso8601?(0!==d.getDay()?d.getDay():7)-1:d.getDay();e.settings.selection.day&&t.classList.add(e.CSSClasses.daysSelecting),t.innerHTML="",prevMonth(e,t,i,r,o),currentMonth(e,t,c,i,r),nextMonth(e,t,c,i,r,o),createWeekNumbers(e,o,c,a[s],t),createPopup(e,t)}))},visibilityMonth=(e,t,a,n)=>{const s=new Date(n.setMonth(e.selectedMonth+a)).getMonth(),l=!1===e.settings.selection.month||"only-arrows"===e.settings.selection.month;t.tabIndex=l?-1:0,t.classList.toggle(e.CSSClasses.monthDisabled,l),t.setAttribute("data-calendar-selected-month",String(s)),t.innerText=e.locale.months[s]},visibilityYear=(e,t,a,n)=>{const s=new Date(n.setFullYear(e.selectedYear,e.selectedMonth+a)).getFullYear(),l=!1===e.settings.selection.year||"only-arrows"===e.settings.selection.year;t.tabIndex=l?-1:0,t.classList.toggle(e.CSSClasses.yearDisabled,l),t.setAttribute("data-calendar-selected-year",String(s)),t.innerText=String(s)},visibilityTitle=e=>{var t,a;const n=null==(t=e.HTMLElement)?void 0:t.querySelectorAll("[data-calendar-selected-month]"),s=null==(a=e.HTMLElement)?void 0:a.querySelectorAll("[data-calendar-selected-year]");if(!(null==n?void 0:n[0])&&(null==s?void 0:s[0]))return;const l=new Date(e.selectedYear,e.selectedMonth,1);null==n||n.forEach(((t,a)=>visibilityMonth(e,t,a,l))),null==s||s.forEach(((t,a)=>visibilityYear(e,t,a,l)))},changeMonth=(e,t)=>{const a=getDate(getDateString(new Date(e.selectedYear,e.selectedMonth,1)));({prev:()=>a.setMonth(a.getMonth()-e.jumpMonths),next:()=>a.setMonth(a.getMonth()+e.jumpMonths)})[t](),[e.selectedMonth,e.selectedYear]=[a.getMonth(),a.getFullYear()],visibilityTitle(e),visibilityArrows(e),createDays(e)},ArrowPrev=e=>``,ArrowNext=e=>``,Month=e=>``,Year=e=>``,Week=e=>`
`,Days=e=>`
`,Months=e=>`
`,Years=e=>`
`,WeekNumbers=e=>e.settings.visibility.weekNumbers?`
`:"",ControlTime=e=>e.settings.selection.time?`
`:"",components=Object.freeze(Object.defineProperty({__proto__:null,ArrowNext:ArrowNext,ArrowPrev:ArrowPrev,ControlTime:ControlTime,Days:Days,Month:Month,Months:Months,Week:Week,WeekNumbers:WeekNumbers,Year:Year,Years:Years},Symbol.toStringTag,{value:"Module"})),getComponent=e=>components[e],DOMParser=(e,t)=>t.replace(/[\n\t]/g,"").replace(/<#(?!\/?Multiple)(.*?)>/g,((t,a)=>{const n=(s=a.replace(/[/\s\n\t]/g,""),components[s]);var s;return n?n(e):""})).replace(/[\n\t]/g,""),MultipleParser=(e,t)=>t.replace(/<#Multiple>(.*?)<#\/Multiple>/g,((t,a)=>{let n="";for(let t=0;t{const{HTMLElement:a,CSSClasses:n,DOMTemplates:s,type:l,currentType:r,correctMonths:i}=e,d=(s,l)=>{if(!t)return;const r=a.querySelector(`.${n.controls}`);r&&a.removeChild(r);a.querySelector(`.${n.grid}`).classList.add(n.gridDisabled);const i=t.closest(`.${n.column}`);i.classList.add(s),i.innerHTML=DOMParser(e,l)},c={default:()=>{a.classList.add(n.calendarDefault),a.classList.remove(n.calendarMonth,n.calendarYear),a.innerHTML=DOMParser(e,s.default)},multiple:()=>{i&&(a.classList.add(n.calendarMultiple),a.classList.remove(n.calendarMonth,n.calendarYear),a.innerHTML=MultipleParser(e,DOMParser(e,s.multiple)))},month:()=>{"multiple"!==l?(a.classList.add(n.calendarMonth),a.classList.remove(n.calendarDefault,n.calendarYear),a.innerHTML=DOMParser(e,s.month)):d(n.columnMonth,s.month)},year:()=>{"multiple"!==l?(a.classList.add(n.calendarYear),a.classList.remove(n.calendarDefault,n.calendarMonth),a.innerHTML=DOMParser(e,s.year)):d(n.columnYear,s.year)}};a.classList.add(n.calendar),c[r]()},createYearEl=(e,t,a,n,s)=>{const l=t.cloneNode(!1);return l.className=`${e.CSSClasses.yearsYear}${a===s?` ${e.CSSClasses.yearsYearSelected}`:n?` ${e.CSSClasses.yearsYearDisabled}`:""}`,l.dataset.calendarYear=String(s),l.title=String(s),l.innerText=String(s),n&&(l.tabIndex=-1),l},createYears=(e,t)=>{const a=(null==t?void 0:t.dataset.calendarSelectedYear)?Number(null==t?void 0:t.dataset.calendarSelectedYear):e.selectedYear;e.currentType="year",createDOM(e,t),visibilityTitle(e),visibilityArrows(e);const n=e.HTMLElement.querySelector(`.${e.CSSClasses.years}`);if(!e.settings.selection.year||!n)return;n.classList.add(e.CSSClasses.yearsSelecting);const s="multiple"!==e.type||e.selectedYear===a?0:1,l=document.createElement("button");l.type="button";for(let t=e.viewYear-7;te.dateMax.getFullYear(),i=createYearEl(e,l,a,r,t);n.append(i),e.actions.getYears&&e.actions.getYears(t,i,e)}},handleClickArrow=(e,t)=>{const a=t.target.closest(`.${e.CSSClasses.arrow}`);a&&(["default","multiple"].includes(e.currentType)?changeMonth(e,a.dataset.calendarArrow):"year"===e.currentType&&void 0!==e.viewYear&&(e.viewYear+={prev:-15,next:15}[a.dataset.calendarArrow],createYears(e,t.target)),e.actions.clickArrow&&e.actions.clickArrow(t,e))},handleClickWeekNumber=(e,t)=>{var a;if(!e.settings.visibility.weekNumbers||!e.actions.clickWeekNumber)return;const n=t.target.closest(`.${e.CSSClasses.weekNumber}`),s=null==(a=e.HTMLElement)?void 0:a.querySelectorAll("[data-calendar-week-number]");if(!n||!s)return;const l=Number(n.innerText),r=Number(n.dataset.calendarYearWeek),i=[...s].filter((e=>Number(e.dataset.calendarWeekNumber)===l));e.actions.clickWeekNumber(t,l,i,r,e)},capitalizeFirstLetter=e=>`${e.charAt(0).toUpperCase()}${e.substring(1,e.length)}`.replace(/\./,""),getLocaleWeekday=(e,t)=>{const a=new Date(`1978-01-0${t+1}T00:00:00.000Z`).toLocaleString(e.settings.lang,{weekday:"short",timeZone:"UTC"});e.locale.weekday.push(capitalizeFirstLetter(a))},getLocaleMonth=(e,t)=>{const a=new Date(`1978-${t+1<=9?`0${t+1}`:t+1}-01T00:00:00.000Z`).toLocaleString(e.settings.lang,{month:"long",timeZone:"UTC"});e.locale.months.push(capitalizeFirstLetter(a))},getLocale=e=>{if("define"!==e.settings.lang||!e.locale.weekday[6]||!e.locale.months[11]){if("define"===e.settings.lang)throw new Error(messages.notLocale);e.locale.weekday=[],e.locale.months=[];for(let t=0;t<7;t++)getLocaleWeekday(e,t);for(let t=0;t<12;t++)getLocaleMonth(e,t)}},relationshipID=e=>{if("multiple"!==e.type)return 0;const t=[...e.HTMLElement.querySelectorAll(`.${e.CSSClasses.column}`)].findIndex((t=>t.classList.contains(`${e.CSSClasses.columnMonth}`)));return t>0?t:0},createMonthEl=(e,t,a,n,s,l)=>{const r=t.cloneNode(!1);return r.className=`${e.CSSClasses.monthsMonth}${a===l?` ${e.CSSClasses.monthsMonthSelected}`:s?` ${e.CSSClasses.monthsMonthDisabled}`:""}`,r.title=n,r.innerText=`${e.settings.visibility.monthShort?n.substring(0,3):n}`,r.dataset.calendarMonth=String(l),s&&(r.tabIndex=-1),r},createMonths=(e,t)=>{var a,n;const s=(null==t?void 0:t.dataset.calendarSelectedMonth)?Number(t.dataset.calendarSelectedMonth):e.selectedMonth,l=null==(a=null==t?void 0:t.closest(`.${e.CSSClasses.column}`))?void 0:a.querySelector(`.${e.CSSClasses.year}`),r=l?Number(l.dataset.calendarSelectedYear):e.selectedYear;e.currentType="month",createDOM(e,t),visibilityTitle(e);const i=null==(n=e.HTMLElement)?void 0:n.querySelector(`.${e.CSSClasses.months}`);if(!e.settings.selection.month||!i)return;i.classList.add(e.CSSClasses.monthsSelecting);const d=e.jumpMonths>1?e.locale.months.map(((t,a)=>s-e.jumpMonths*a)).concat(e.locale.months.map(((t,a)=>s+e.jumpMonths*a))).filter((e=>e>=0&&e<=12)):Array.from(Array(12).keys()),c=document.createElement("button");c.type="button";for(let t=0;t<12;t++){const a=e.locale.months[t],n=te.dateMax.getMonth()+relationshipID(e)&&r>=e.dateMax.getFullYear()||t!==s&&!d.includes(t),l=createMonthEl(e,c,s,a,n,t);i.append(l),e.actions.getMonths&&e.actions.getMonths(t,l,e)}},transformTime24=(e,t)=>e&&t?{0:{AM:"00",PM:"12"},1:{AM:"01",PM:"13"},2:{AM:"02",PM:"14"},3:{AM:"03",PM:"15"},4:{AM:"04",PM:"16"},5:{AM:"05",PM:"17"},6:{AM:"06",PM:"18"},7:{AM:"07",PM:"19"},8:{AM:"08",PM:"20"},9:{AM:"09",PM:"21"},10:{AM:"10",PM:"22"},11:{AM:"11",PM:"23"},12:{AM:"12",PM:"12"}}[Number(e)][t]:"",getInputElement=(e,t,a)=>e.querySelector(`.${t}${a?` input[name="${a}"]`:""}`),addMouseEvents=(e,t,a)=>{e.addEventListener("mouseover",(()=>t.classList.add(a))),e.addEventListener("mouseout",(()=>t.classList.remove(a)))},setTime=(e,t,a,n)=>{({hours:()=>{e.selectedHours=a},minutes:()=>{e.selectedMinutes=a}})[n](),e.selectedTime=`${e.selectedHours}:${e.selectedMinutes}${e.selectedKeeping?` ${e.selectedKeeping}`:""}`,e.actions.changeTime&&e.actions.changeTime(t,e),e.input&&e.HTMLInputElement&&e.actions.changeToInput&&e.actions.changeToInput(t,actionsInput(e),e)},changeRange=(e,t,a,n,s,l)=>{t.addEventListener("input",(t=>{const r=t.target,i=Number(r.value),d=i<10?`0${i}`:`${i}`;if("hours"!==s||12!==l)return a.value=d,void setTime(e,t,d,s);i0?(a.value=d,e.selectedKeeping="AM",n.innerText=e.selectedKeeping,setTime(e,t,d,s)):(0===i?(e.selectedKeeping="AM",n.innerText="AM"):(e.selectedKeeping="PM",n.innerText="PM"),a.value=transformTime12(r.value),setTime(e,t,transformTime12(r.value),s))}))},changeInput=(e,t,a,n,s,l)=>{a.addEventListener("change",(a=>{const r=a.target,i=Number(r.value),d=i<10?`0${i}`:`${i}`;"hours"===s&&12===l?r.value&&i<=l&&i>0?(r.value=d,t.value=transformTime24(d,e.selectedKeeping),setTime(e,a,d,s)):r.value&&i<24&&(i>l||0===i)?(0===i?(e.selectedKeeping="AM",n.innerText="AM"):(e.selectedKeeping="PM",n.innerText="PM"),r.value=transformTime12(r.value),t.value=d,setTime(e,a,transformTime12(r.value),s)):r.value=e.selectedHours:r.value&&i<=l&&i>=0?(r.value=d,t.value=d,setTime(e,a,d,s)):"hours"===s?r.value=e.selectedHours:"minutes"===s&&(r.value=e.selectedMinutes)}))},clickBtnKeepingTime=(e,t,a)=>{t.addEventListener("click",(n=>{e.selectedKeeping=t.innerText.includes("AM")?"PM":"AM",t.innerText=e.selectedKeeping,a.value=transformTime24(e.selectedHours,e.selectedKeeping),setTime(e,n,e.selectedHours,"hours")}))},changeTime=(e,t,a)=>{const n=24===a?23:a||12,s=getInputElement(t,e.CSSClasses.timeRange,"hours"),l=getInputElement(t,e.CSSClasses.timeRange,"minutes"),r=getInputElement(t,e.CSSClasses.timeHours,"hours"),i=getInputElement(t,e.CSSClasses.timeMinutes,"minutes"),d=t.querySelector(`.${e.CSSClasses.timeKeeping}`);addMouseEvents(s,r,e.CSSClasses.isFocus),addMouseEvents(l,i,e.CSSClasses.isFocus),changeRange(e,s,r,d,"hours",n),changeRange(e,l,i,d,"minutes",0),changeInput(e,s,r,d,"hours",n),changeInput(e,l,i,d,"minutes",59),d&&clickBtnKeepingTime(e,d,s)},InputTime=(e,t,a,n)=>``,RangeTime=(e,t,a,n,s,l)=>``,createTime=e=>{const t=e.HTMLElement.querySelector(`.${e.CSSClasses.time}`);if(!t)return;const a=!0===e.settings.selection.time?12:e.settings.selection.time,n="range"===e.settings.selection.controlTime,[s,l]=[0,23],[r,i]=[0,59];t.innerHTML=`
${InputTime("hours",e.CSSClasses.timeHours,e.selectedHours,n)}${InputTime("minutes",e.CSSClasses.timeMinutes,e.selectedMinutes,n)}${12===a?``:""}
${RangeTime("hours",e.CSSClasses.timeRange,s,l,e.settings.selection.stepHours,e.selectedKeeping?transformTime24(e.selectedHours,e.selectedKeeping):e.selectedHours)}${RangeTime("minutes",e.CSSClasses.timeRange,r,i,e.settings.selection.stepMinutes,e.selectedMinutes)}
`,changeTime(e,t,a)},createWeekDays=(e,t,a)=>{const n=document.createElement("b");t.innerHTML="";for(let s=0;s{const t=[...e.locale.weekday];if(!t[0])return;e.settings.iso8601&&t.push(t.shift());e.HTMLElement.querySelectorAll(`.${e.CSSClasses.week}`).forEach((a=>createWeekDays(e,a,t)))},themes=["light","dark","system"],haveListener={value:!1,set:()=>{haveListener.value=!0},check:()=>haveListener.value},getTheme=(e,t)=>themes.find((a=>{var n;return"system"!==a&&(null==(n=e.getAttribute(t))?void 0:n.includes(a))})),setTheme=(e,t)=>{e.dataset.calendarTheme=t},trackChangesThemeInSystemSettings=(e,t)=>{var a;if(a=t,setTheme(e.HTMLElement,a.matches?"dark":"light"),"system"!==e.settings.visibility.theme||haveListener.check())return;const n=t=>{const a=document.querySelectorAll(`.${e.CSSClasses.calendar}`);null==a||a.forEach((e=>setTheme(e,t.matches?"dark":"light")))};t.addEventListener?t.addEventListener("change",n):t.addListener(n),haveListener.set()},trackChangesThemeInHTMLElement=(e,t,a)=>{new MutationObserver((n=>{for(let s=0;s{const a=e.settings.visibility.themeDetect?document.querySelector(e.settings.visibility.themeDetect):null;if(!a)return void trackChangesThemeInSystemSettings(e,t);const n=e.settings.visibility.themeDetect.replace(/^.*\[(.+)\]/g,((e,t)=>t)),s=getTheme(a,n);s?(setTheme(e.HTMLElement,s),trackChangesThemeInHTMLElement(e,a,n)):trackChangesThemeInSystemSettings(e,t)},changeTheme=e=>{if(!themes.includes(e.settings.visibility.theme))throw new Error(messages.incorrectTheme);if("not all"===window.matchMedia("(prefers-color-scheme)").media)return void setTheme(e.HTMLElement,"light");({light:()=>setTheme(e.HTMLElement,"light"),dark:()=>setTheme(e.HTMLElement,"dark"),system:()=>detectTheme(e,window.matchMedia("(prefers-color-scheme: dark)"))})[e.settings.visibility.theme]()},create=e=>{const t={default:()=>{createWeek(e),createDays(e)},multiple:()=>{createWeek(e),createDays(e)},month:()=>createMonths(e),year:()=>createYears(e)};changeTheme(e),getLocale(e),createDOM(e),visibilityTitle(e),visibilityArrows(e),createTime(e),t[e.currentType]()},current={self:null,rangeMin:void 0,rangeMax:void 0},removeHoverEffect=()=>{var e;if(!(null==(e=current.self)?void 0:e.HTMLElement))return;const{CSSClasses:t}=current.self;current.self.HTMLElement.querySelectorAll(`.${current.self.CSSClasses.dayBtnHover}`).forEach((e=>{var a;e.classList.remove(current.self.CSSClasses.dayBtnHover),null==(a=e.parentElement)||a.classList.remove(t.dayHoverIntermediate,t.dayHoverFirst,t.dayHoverLast)}))},addHoverEffect=(e,t,a)=>{var n,s,l;if(!(null==(n=current.self)?void 0:n.selectedDates))return;const r=getDateString(e),{CSSClasses:i}=current.self;if(null==(s=current.self.rangeDisabled)?void 0:s.includes(r))return;const d=null==(l=current.self.HTMLElement)?void 0:l.querySelectorAll(`[data-calendar-day="${r}"]`);null==d||d.forEach((e=>{var t;e.classList.add(i.dayBtnHover),null==(t=e.parentElement)||t.classList.add(i.dayHoverIntermediate)})),null==t||t.forEach((e=>{var t;return null==(t=e.parentElement)?void 0:t.classList.add(i.dayHoverFirst)})),null==a||a.forEach((e=>{var t;return null==(t=e.parentElement)?void 0:t.classList.add(i.dayHoverLast)}))},handleHoverDaysEvent=e=>{var t;if(!e.target||!(null==(t=current.self)?void 0:t.selectedDates))return;if(!e.target.closest(`.${current.self.CSSClasses.days}`))return void removeHoverEffect();const a=e.target.closest("[data-calendar-day]");if(!a)return;const n=a.dataset.calendarDay,s=getDate(current.self.selectedDates[0]),l=getDate(n),r=current.self.HTMLElement.querySelectorAll(`[data-calendar-day="${current.self.selectedDates[0]}"]`),i=current.self.HTMLElement.querySelectorAll(`[data-calendar-day="${n}"]`),[d,c]=s{current.self&&"Escape"===e.key&&(current.self.selectedDates=[],current.self.HTMLElement.removeEventListener("mousemove",handleHoverDaysEvent),document.removeEventListener("keydown",handleCancelSelectionDays),create(current.self))},updateDisabledDates=()=>{var e,t,a;if(!(null==(t=null==(e=current.self)?void 0:e.selectedDates)?void 0:t[0])||!current.self.rangeDisabled||(null==(a=current.self.rangeDisabled)?void 0:a.length)<2)return;const n=getDate(current.self.selectedDates[0]),[s,l]=current.self.rangeDisabled.map((e=>getDate(e))).reduce((([e,t],a)=>[n>=a?a:e,n{current.self&&(current.self.rangeMin=current.rangeMin,current.self.rangeMax=current.rangeMax)},handleDayRangedSelection=(e,t)=>{var a;if(t){const n=1===e.selectedDates.length&&e.selectedDates[0].includes(t);e.selectedDates=n&&!e.settings.selection.cancelableDay?[t,t]:n&&e.settings.selection.cancelableDay?[]:e.selectedDates.length>1?[t]:[...e.selectedDates,t],null==(a=e.selectedDates)||a.sort(((e,t)=>+new Date(e)-+new Date(t)))}e.settings.range.disableGaps&&(current.rangeMin=current.rangeMin?current.rangeMin:e.rangeMin,current.rangeMax=current.rangeMax?current.rangeMax:e.rangeMax),current.self=e;({set:()=>{e.HTMLElement.addEventListener("mousemove",handleHoverDaysEvent),document.addEventListener("keydown",handleCancelSelectionDays),e.settings.range.disableGaps&&updateDisabledDates()},reset:()=>{const[t,a]=[e.selectedDates[0],e.selectedDates[e.selectedDates.length-1]];e.selectedDates=e.selectedDates[0]!==e.selectedDates[e.selectedDates.length-1]?parseDates([`${t}:${a}`]):[e.selectedDates[0],e.selectedDates[0]],e.HTMLElement.removeEventListener("mousemove",handleHoverDaysEvent),document.removeEventListener("keydown",handleCancelSelectionDays),e.settings.range.disableGaps&¤t.self&&(current.self.rangeMin=current.rangeMin,current.self.rangeMax=current.rangeMax)}})[1===e.selectedDates.length?"set":"reset"]()},handleDaySelection=(e,t,a)=>{if(!t.dataset.calendarDay)return;const n=t.dataset.calendarDay,s=t.classList.contains(e.CSSClasses.dayBtnSelected);s&&!e.settings.selection.cancelableDay||(e.selectedDates=s?e.selectedDates.filter((e=>e!==n)):a?[...e.selectedDates,n]:[n])},handleClickDay=(e,t)=>{var a;const n=t.target,s=e=>n.closest(`.${e}`),l=s(e.CSSClasses.dayBtn);if(!e.settings.selection.day||!["single","multiple","multiple-ranged"].includes(e.settings.selection.day)||!l)return;({single:()=>handleDaySelection(e,l,!1),multiple:()=>handleDaySelection(e,l,!0),"multiple-ranged":()=>handleDayRangedSelection(e,l.dataset.calendarDay)})[e.settings.selection.day](),null==(a=e.selectedDates)||a.sort(((e,t)=>+new Date(e)-+new Date(t))),e.actions.clickDay&&e.actions.clickDay(t,e);e.input&&e.HTMLInputElement&&e.HTMLElement&&e.actions.changeToInput&&e.actions.changeToInput(t,actionsInput(e),e);const r=s(e.CSSClasses.dayBtnPrev),i=s(e.CSSClasses.dayBtnNext);({prev:()=>changeMonth(e,"prev"),next:()=>changeMonth(e,"next"),default:()=>createDays(e)})[r?"prev":i?"next":"default"]()},getColumnID=(e,t,a,n,s)=>{const l=e.HTMLElement.querySelectorAll(`.${e.CSSClasses.column}`),r=[...l].findIndex((e=>e.classList.contains(t))),i=Number(l[r].querySelector(`.${a}`).getAttribute(s));return"month"===e.currentType&&r>=0?n-r:"year"===e.currentType&&e.selectedYear!==i?n-1:n},handleItemClick=(e,t,a,n,s)=>{const l={year:()=>{var a,n;return null==(n=(a=e.actions).clickYear)?void 0:n.call(a,t,e)},month:()=>{var a,n;return null==(n=(a=e.actions).clickMonth)?void 0:n.call(a,t,e)}};({year:()=>{if("multiple"===e.type){const t=getColumnID(e,e.CSSClasses.columnYear,e.CSSClasses.year,Number(s.dataset.calendarYear),"data-calendar-selected-year"),a=e.selectedMonthe.dateMax.getMonth()&&t>=e.dateMax.getFullYear(),l=te.dateMax.getFullYear();a||l?(e.selectedYear=e.dateMin.getFullYear(),e.selectedMonth=e.dateMin.getMonth()):n||r?(e.selectedYear=e.dateMax.getFullYear(),e.selectedMonth=e.dateMax.getMonth()):e.selectedYear=t}else e.selectedYear=Number(s.dataset.calendarYear)},month:()=>{if("multiple"===e.type){const t=getColumnID(e,e.CSSClasses.columnMonth,e.CSSClasses.month,Number(s.dataset.calendarMonth),"data-calendar-selected-month"),a=s.closest(`.${n.column}`).querySelector(`.${e.CSSClasses.year}`);e.selectedYear=Number(a.dataset.calendarSelectedYear);const l=te.dateMax.getMonth()&&e.selectedYear>=e.dateMax.getFullYear();e.selectedMonth=l?e.dateMin.getMonth():r?e.dateMax.getMonth():t}else e.selectedMonth=Number(s.dataset.calendarMonth)}})[a](),l[a](),e.currentType=e.type,create(e)},handleClickMonthOrYear=(e,t,a,n)=>{if(!e.settings.selection[a])return;const s=t.target,l=e=>s.closest(`.${e}`),r=l(n.header),i=l(n.item),d=l(e.CSSClasses.grid),c=l(e.CSSClasses.column);if(e.currentType!==a&&r){({year:()=>createYears(e,s),month:()=>createMonths(e,s)})[a]()}else i?handleItemClick(e,t,a,n,i):(e.currentType===a&&r||"multiple"===e.type&&e.currentType===a&&d&&!c)&&(e.currentType=e.type,create(e))},handleClick=e=>{const t=t=>{handleClickArrow(e,t),handleClickWeekNumber(e,t),handleClickDay(e,t),handleClickMonthOrYear(e,t,"month",{header:e.CSSClasses.month,item:e.CSSClasses.monthsMonth,column:e.CSSClasses.columnMonth}),handleClickMonthOrYear(e,t,"year",{header:e.CSSClasses.year,item:e.CSSClasses.yearsYear,column:e.CSSClasses.columnYear})};return e.HTMLElement.addEventListener("click",t),()=>e.HTMLElement.removeEventListener("click",t)},update=(e,{year:t,month:a,dates:n,holidays:s,time:l}={})=>{var r;if(!e.isInit)throw new Error(messages.notInit);const i=__spreadValues({},e.settings.selected);e.settings.selected.year=t?i.year:e.selectedYear,e.settings.selected.month=a?i.month:e.selectedMonth,e.settings.selected.holidays=s?i.holidays:e.selectedHolidays,e.settings.selected.time=l?i.time:e.selectedTime,e.settings.selected.dates="only-first"===n&&(null==(r=e.selectedDates)?void 0:r[0])?[e.selectedDates[0]]:!0===n?i.dates:e.selectedDates,setVariables(e),create(e),e.settings.selected=i,"multiple-ranged"===e.settings.selection.day&&n&&handleDayRangedSelection(e)},setPositionCalendar=(e,t,a,n)=>{const s={top:-t.offsetHeight,bottom:e.offsetHeight,left:0,center:e.offsetWidth/2-t.offsetWidth/2,right:e.offsetWidth-t.offsetWidth},l=Array.isArray(a)?a[0]:"bottom",r=Array.isArray(a)?a[1]:a;t.classList.add("bottom"===l?n.calendarToInputBottom:n.calendarToInputTop);const i=e.getBoundingClientRect(),d=window.scrollX||document.documentElement.scrollLeft,c=window.scrollY||document.documentElement.scrollTop,o=i.top+c+s[l],u=i.left+d+s[r];Object.assign(t.style,{left:`${u}px`,top:`${o}px`})},handleInput=e=>{let t=!0;const a=[];e.HTMLInputElement=e.HTMLElement;const n=()=>setPositionCalendar(e.HTMLInputElement,e.HTMLElement,e.settings.visibility.positionToInput,e.CSSClasses),s=t=>{var a;e&&t.target!==e.HTMLInputElement&&!(null==(a=e.HTMLElement)?void 0:a.contains(t.target))&&(e.HTMLInputElement&&e.HTMLElement&&actionsInput(e).hide(),window.removeEventListener("resize",n),document.removeEventListener("click",s,{capture:!0}))};return e.HTMLInputElement.addEventListener("click",(()=>{t?a.push((()=>{const a=document.createElement("div");return a.className=`${e.CSSClasses.calendar} ${e.CSSClasses.calendarToInput} ${e.CSSClasses.calendarHidden}`,e.HTMLElement=a,document.body.append(e.HTMLElement),t=!1,setTimeout((()=>{setPositionCalendar(e.HTMLInputElement,a,e.settings.visibility.positionToInput,e.CSSClasses),actionsInput(e).show()}),0),update(e,{year:!0,month:!0,dates:!0,holidays:!0,time:!0}),handleClick(e)})()):(setPositionCalendar(e.HTMLInputElement,e.HTMLElement,e.settings.visibility.positionToInput,e.CSSClasses),actionsInput(e).show()),window.addEventListener("resize",n),document.addEventListener("click",s,{capture:!0})})),()=>{a.forEach((e=>e()))}},init=e=>(e.HTMLOriginalElement=e.HTMLElement.cloneNode(!0),e.isInit=!0,e.input?handleInput(e):(setVariables(e),create(e),handleClick(e))),destroy=e=>{var t,a,n,s;if(!e.isInit)throw new Error(messages.notInit);e.input?(null==(a=null==(t=e.HTMLElement)?void 0:t.parentElement)||a.removeChild(e.HTMLElement),null==(n=e.HTMLInputElement)||n.replaceWith(e.HTMLOriginalElement),e.HTMLInputElement=void 0):null==(s=e.HTMLElement)||s.replaceWith(e.HTMLOriginalElement),e.HTMLElement=e.HTMLOriginalElement};class VanillaCalendar extends DefaultOptionsCalendar{constructor(e,t){if(super(),__publicField(this,"init",(()=>{return(e=this).HTMLOriginalElement=e.HTMLElement.cloneNode(!0),e.isInit=!0,e.input?handleInput(e):(setVariables(e),create(e),handleClick(e));var e})),__publicField(this,"update",(e=>update(this,e))),__publicField(this,"destroy",(()=>destroy(this))),this.HTMLElement="string"==typeof e?document.querySelector(e):e,!this.HTMLElement)throw new Error(messages.notFoundSelector(e));if(!t)return;const a=(e,t)=>{Object.keys(t).forEach((n=>{"object"!=typeof e[n]||"object"!=typeof t[n]||t[n]instanceof Date?e[n]=t[n]:a(e[n],t[n])}))};a(this,t)}}export{VanillaCalendar as default}; \ No newline at end of file +var __defProp=Object.defineProperty,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(e,t,a)=>t in e?__defProp(e,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[t]=a,__spreadValues=(e,t)=>{for(var a in t||(t={}))__hasOwnProp.call(t,a)&&__defNormalProp(e,a,t[a]);if(__getOwnPropSymbols)for(var a of __getOwnPropSymbols(t))__propIsEnum.call(t,a)&&__defNormalProp(e,a,t[a]);return e},__publicField=(e,t,a)=>(__defNormalProp(e,"symbol"!=typeof t?t+"":t,a),a);const classes={calendar:"vanilla-calendar",calendarDefault:"vanilla-calendar_default",calendarMultiple:"vanilla-calendar_multiple",calendarMonth:"vanilla-calendar_month",calendarYear:"vanilla-calendar_year",calendarHidden:"vanilla-calendar_hidden",calendarToInput:"vanilla-calendar_to-input",calendarToInputTop:"vanilla-calendar_to-input_top",calendarToInputBottom:"vanilla-calendar_to-input_bottom",controls:"vanilla-calendar-controls",grid:"vanilla-calendar-grid",gridDisabled:"vanilla-calendar-grid_disabled",column:"vanilla-calendar-column",columnMonth:"vanilla-calendar-column_month",columnYear:"vanilla-calendar-column_year",header:"vanilla-calendar-header",headerContent:"vanilla-calendar-header__content",month:"vanilla-calendar-month",monthDisabled:"vanilla-calendar-month_disabled",year:"vanilla-calendar-year",yearDisabled:"vanilla-calendar-year_disabled",arrow:"vanilla-calendar-arrow",arrowPrev:"vanilla-calendar-arrow_prev",arrowNext:"vanilla-calendar-arrow_next",wrapper:"vanilla-calendar-wrapper",content:"vanilla-calendar-content",week:"vanilla-calendar-week",weekDay:"vanilla-calendar-week__day",weekDayWeekend:"vanilla-calendar-week__day_weekend",days:"vanilla-calendar-days",daysSelecting:"vanilla-calendar-days_selecting",months:"vanilla-calendar-months",monthsSelecting:"vanilla-calendar-months_selecting",monthsMonth:"vanilla-calendar-months__month",monthsMonthSelected:"vanilla-calendar-months__month_selected",monthsMonthDisabled:"vanilla-calendar-months__month_disabled",years:"vanilla-calendar-years",yearsSelecting:"vanilla-calendar-years_selecting",yearsYear:"vanilla-calendar-years__year",yearsYearSelected:"vanilla-calendar-years__year_selected",yearsYearDisabled:"vanilla-calendar-years__year_disabled",time:"vanilla-calendar-time",timeContent:"vanilla-calendar-time__content",timeHours:"vanilla-calendar-time__hours",timeMinutes:"vanilla-calendar-time__minutes",timeKeeping:"vanilla-calendar-time__keeping",timeRanges:"vanilla-calendar-time__ranges",timeRange:"vanilla-calendar-time__range",day:"vanilla-calendar-day",dayHoverFirst:"vanilla-calendar-day_hover-first",dayHoverLast:"vanilla-calendar-day_hover-last",dayHoverIntermediate:"vanilla-calendar-day_hover-intermediate",daySelectedFirst:"vanilla-calendar-day_selected-first",daySelectedLast:"vanilla-calendar-day_selected-last",daySelectedIntermediate:"vanilla-calendar-day_selected-intermediate",dayPopup:"vanilla-calendar-day__popup",dayBtn:"vanilla-calendar-day__btn",dayBtnPrev:"vanilla-calendar-day__btn_prev",dayBtnNext:"vanilla-calendar-day__btn_next",dayBtnToday:"vanilla-calendar-day__btn_today",dayBtnSelected:"vanilla-calendar-day__btn_selected",dayBtnHover:"vanilla-calendar-day__btn_hover",dayBtnDisabled:"vanilla-calendar-day__btn_disabled",dayBtnWeekend:"vanilla-calendar-day__btn_weekend",dayBtnHoliday:"vanilla-calendar-day__btn_holiday",weekNumbers:"vanilla-calendar-week-numbers",weekNumbersTitle:"vanilla-calendar-week-numbers__title",weekNumbersContent:"vanilla-calendar-week-numbers__content",weekNumber:"vanilla-calendar-week-number",isFocus:"vanilla-calendar-is-focus"},DOMDefault=e=>`
<#ArrowPrev />
<#Month /><#Year />
<#ArrowNext />
<#WeekNumbers />
<#Week /><#Days />
<#ControlTime />`,DOMMultiple=e=>`
<#ArrowPrev /><#ArrowNext />
<#Multiple>
<#Month /><#Year />
<#WeekNumbers />
<#Week /><#Days />
<#/Multiple>
<#ControlTime />`,DOMMonths=e=>`
<#Month /><#Year />
<#Months />
`,DOMYears=e=>`
<#ArrowPrev />
<#Month /><#Year />
<#ArrowNext />
<#Years />
`;class DefaultOptionsCalendar{constructor(){var e;__publicField(this,"isInit",!1),__publicField(this,"input",!1),__publicField(this,"type","default"),__publicField(this,"months",2),__publicField(this,"jumpMonths",1),__publicField(this,"date",{min:"1970-01-01",max:"2470-12-31",today:new Date}),__publicField(this,"settings",{lang:"en",iso8601:!0,range:{min:this.date.min,max:this.date.max,disablePast:!1,disableGaps:!1,disableAllDays:!1,disableWeekday:void 0,disabled:void 0,enabled:void 0},selection:{day:"single",month:!0,year:!0,time:!1,controlTime:"all",stepHours:1,stepMinutes:1,cancelableDay:!0},selected:{dates:void 0,month:void 0,year:void 0,holidays:void 0,time:void 0},visibility:{theme:"system",themeDetect:"html[data-theme]",monthShort:!0,weekNumbers:!1,weekend:!0,today:!0,disabled:!1,daysOutside:!0,positionToInput:"left"}}),__publicField(this,"locale",{months:[],weekday:[]}),__publicField(this,"actions",{clickDay:null,clickWeekNumber:null,clickMonth:null,clickYear:null,clickArrow:null,changeTime:null,changeToInput:null,getDays:null,getMonths:null,getYears:null,initCalendar:null,updateCalendar:null,destroyCalendar:null,showCalendar:null,hideCalendar:null}),__publicField(this,"popups",{}),__publicField(this,"CSSClasses",__spreadValues({},classes)),__publicField(this,"DOMTemplates",{default:(e=this.CSSClasses,`
<#ArrowPrev />
<#Month /><#Year />
<#ArrowNext />
<#WeekNumbers />
<#Week /><#Days />
<#ControlTime />`),multiple:DOMMultiple(this.CSSClasses),month:DOMMonths(this.CSSClasses),year:DOMYears(this.CSSClasses)}),__publicField(this,"HTMLElement"),__publicField(this,"HTMLOriginalElement"),__publicField(this,"HTMLInputElement"),__publicField(this,"rangeMin"),__publicField(this,"rangeMax"),__publicField(this,"rangeDisabled"),__publicField(this,"rangeEnabled"),__publicField(this,"selectedDates"),__publicField(this,"selectedHolidays"),__publicField(this,"selectedMonth"),__publicField(this,"selectedYear"),__publicField(this,"selectedHours"),__publicField(this,"selectedMinutes"),__publicField(this,"selectedKeeping"),__publicField(this,"selectedTime"),__publicField(this,"currentType"),__publicField(this,"correctMonths"),__publicField(this,"viewYear"),__publicField(this,"dateMin"),__publicField(this,"dateMax")}}const getDateString=e=>`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}`,getDate=e=>new Date(`${e}T00:00:00`),parseDates=e=>e.reduce(((e,t)=>(t.match(/^(\d{4}-\d{2}-\d{2})$/g)?e.push(t):t.replace(/(\d{4}-\d{2}-\d{2}).*?(\d{4}-\d{2}-\d{2})/g,((t,a,n)=>{const s=getDate(a),l=getDate(n),r=new Date(s.getTime());for(;r<=l;r.setDate(r.getDate()+1))e.push(getDateString(r));return t})),e)),[]),transformTime12=e=>e?{0:"12",13:"01",14:"02",15:"03",16:"04",17:"05",18:"06",19:"07",20:"08",21:"09",22:"10",23:"11"}[Number(e)]||String(e):"",messages={notFoundSelector:e=>`${e} is not found, check the first argument passed to new VanillaCalendar.`,notInit:'The calendar has not been initialized, please initialize it using the "init()" method first.',notLocale:'You specified "define" for "settings.lang" but did not provide the required values for "locale.weekday" or "locale.months".',incorrectTheme:'Incorrect name of theme in "settings.visibility.theme".',incorrectTime:"The value of the time property can be: false, true, 12 or 24."},initSelectedMonthYear=e=>{const t=void 0!==e.settings.selected.month&&Number(e.settings.selected.month)>=0&&Number(e.settings.selected.month)<12,a=void 0!==e.settings.selected.year&&Number(e.settings.selected.year)>=0&&Number(e.settings.selected.year)<=9999;e.selectedMonth=t?Number(e.settings.selected.month):e.date.today.getMonth(),e.selectedYear=a?Number(e.settings.selected.year):e.date.today.getFullYear(),e.viewYear=e.selectedYear},initRange=e=>{var t,a,n;e.settings.range.min=getDate(e.date.min)>=getDate(e.settings.range.min)?e.date.min:e.settings.range.min,e.settings.range.max=getDate(e.date.max)<=getDate(e.settings.range.max)?e.date.max:e.settings.range.max;const s=e.settings.range.disablePast&&!e.settings.range.disableAllDays&&getDate(e.settings.range.min)1&&e.rangeDisabled.sort(((e,t)=>+new Date(e)-+new Date(t))),e.rangeEnabled=e.settings.range.enabled?parseDates(e.settings.range.enabled):[],(null==(t=e.rangeEnabled)?void 0:t[0])&&(null==(a=e.rangeDisabled)?void 0:a[0])&&(e.rangeDisabled=e.rangeDisabled.filter((t=>!e.rangeEnabled.includes(t)))),e.rangeEnabled.length>1&&e.rangeEnabled.sort(((e,t)=>+new Date(e)-+new Date(t))),(null==(n=e.rangeEnabled)?void 0:n[0])&&e.settings.range.disableAllDays&&(e.rangeMin=e.rangeEnabled[0],e.rangeMax=e.rangeEnabled[e.rangeEnabled.length-1])},initSelectedDates=e=>{var t,a;e.selectedDates=(null==(t=e.settings.selected.dates)?void 0:t[0])?parseDates(e.settings.selected.dates):[],e.selectedHolidays=(null==(a=e.settings.selected.holidays)?void 0:a[0])?parseDates(e.settings.selected.holidays):[]},initDateMinMax=e=>{e.dateMin=e.settings.visibility.disabled?getDate(e.date.min):getDate(e.rangeMin),e.dateMax=e.settings.visibility.disabled?getDate(e.date.max):getDate(e.rangeMax)},initTime=e=>{const t=!0===e.settings.selection.time||12===e.settings.selection.time;if(t||24===e.settings.selection.time){let a=!1;if("string"==typeof e.settings.selected.time){const n=t?/^([0-9]|0[1-9]|1[0-2]):([0-5][0-9])|(AM|PM)/g:/^([0-1]?[0-9]|2[0-3]):([0-5][0-9])/g;e.settings.selected.time.replace(n,((n,s,l,r)=>(s&&l&&(a=!0,e.selectedHours=s,e.selectedMinutes=l),r&&t?e.selectedKeeping=r:t&&(e.selectedKeeping="AM"),"")))}!a&&t?(e.selectedHours=transformTime12(String(e.date.today.getHours())),e.selectedMinutes=String(e.date.today.getMinutes()),e.selectedKeeping=Number(e.date.today.getHours())>=12?"PM":"AM"):a||(e.selectedHours=String(e.date.today.getHours()),e.selectedMinutes=String(e.date.today.getMinutes())),e.selectedHours=Number(e.selectedHours)<10?`0${Number(e.selectedHours)}`:`${e.selectedHours}`,e.selectedMinutes=Number(e.selectedMinutes)<10?`0${Number(e.selectedMinutes)}`:`${e.selectedMinutes}`,e.selectedTime=`${e.selectedHours}:${e.selectedMinutes}${e.selectedKeeping?` ${e.selectedKeeping}`:""}`}else if(e.settings.selection.time)throw new Error(messages.incorrectTime)},initCorrectMonths=e=>{e.correctMonths="multiple"===e.type?1===e.months?2:e.months>12?12:e.months:1},setVariables=e=>{e.currentType=e.type,initSelectedMonthYear(e),initRange(e),initSelectedDates(e),initDateMinMax(e),initTime(e),initCorrectMonths(e)},setVisibilityArrows=({arrowPrev:e,arrowNext:t,isPrevHidden:a,isNextHidden:n})=>{e.style.visibility=a?"hidden":"",t.style.visibility=n?"hidden":""},visibilityArrows=e=>{var t,a;if("month"===e.currentType)return;const n=null==(t=e.HTMLElement)?void 0:t.querySelector(`.${e.CSSClasses.arrowPrev}`),s=null==(a=e.HTMLElement)?void 0:a.querySelector(`.${e.CSSClasses.arrowNext}`);if(!n||!s)return;({default:()=>{const t=getDate(getDateString(new Date(e.selectedYear,e.selectedMonth,1))),a=new Date(t.getTime()),l=new Date(t.getTime());a.setMonth(a.getMonth()-e.jumpMonths),l.setMonth(l.getMonth()+e.jumpMonths),e.settings.selection.year||(e.dateMin.setFullYear(t.getFullYear()),e.dateMax.setFullYear(t.getFullYear()));const r=!e.settings.selection.month||a.getFullYear()e.dateMax.getFullYear()||l.getFullYear()===e.dateMax.getFullYear()&&l.getMonth()>e.dateMax.getMonth();setVisibilityArrows({arrowPrev:n,arrowNext:s,isPrevHidden:r,isNextHidden:i})},year:()=>{setVisibilityArrows({arrowPrev:n,arrowNext:s,isPrevHidden:e.dateMin.getFullYear()&&e.viewYear-7<=e.dateMin.getFullYear(),isNextHidden:e.dateMax.getFullYear()&&e.viewYear+7>=e.dateMax.getFullYear()})}})["multiple"===e.currentType?"default":e.currentType]()},getWeekNumber=(e,t)=>{if(!e)return null;const a=getDate(e),n=t?a.getDay()||7:a.getDay();a.setDate(a.getDate()+4-n);const s=new Date(a.getFullYear(),0,1),l=Math.ceil(((+a-+s)/864e5+1)/7);return{year:a.getFullYear(),week:l}},handleDay=(e,t,a,n)=>{const s=a.querySelector(`[data-calendar-day="${e}"]`);s&&((null==t?void 0:t.modifier)&&s.classList.add(...t.modifier.trim().split(" ")),(null==t?void 0:t.html)&&(s.parentElement.innerHTML+=`
${t.html}
`))},createPopup=(e,t)=>{var a;e.popups&&(null==(a=Object.entries(e.popups))||a.forEach((([a,n])=>handleDay(a,n,t,e.CSSClasses.dayPopup))))},createWeekNumber=(e,t,a,n,s)=>{const l=t[a].querySelector(`.${e.CSSClasses.dayBtn}`),r=getWeekNumber(null==l?void 0:l.dataset.calendarDay,e.settings.iso8601);if(!r)return;const i=n.cloneNode(!0);i.innerText=String(r.week),i.dataset.calendarYearWeek=String(r.year),s.append(i)},createWeekNumbers=(e,t,a,n,s)=>{if(!e.settings.visibility.weekNumbers)return;n.innerHTML="";const l=document.createElement("b");l.className=e.CSSClasses.weekNumbersTitle,l.innerText="#",n.append(l);const r=document.createElement("div");r.className=e.CSSClasses.weekNumbersContent,n.append(r);const i=document.createElement("button");i.type="button",i.className=e.CSSClasses.weekNumber;const d=s.querySelectorAll(`.${e.CSSClasses.day}`),c=Math.ceil((t+a)/7);for(let t=0;t{var n,s,l,r,i;const d=null==(n=e.settings.range.disableWeekday)?void 0:n.includes(a),c=e.settings.range.disableAllDays&&!!(null==(s=e.rangeEnabled)?void 0:s[0]);!d&&!c||(null==(l=e.rangeEnabled)?void 0:l.includes(t))||(null==(r=e.rangeDisabled)?void 0:r.includes(t))||(e.rangeDisabled.push(t),null==(i=e.rangeDisabled)||i.sort(((e,t)=>+new Date(e)-+new Date(t))))},setDayModifier=(e,t,a,n,s,l,r)=>{var i,d,c;(getDate(e.rangeMin)>getDate(l)||getDate(e.rangeMax)1&&"multiple-ranged"===e.settings.selection.day&&(e.selectedDates[0]===l&&a.classList.add(e.CSSClasses.daySelectedFirst),e.selectedDates[e.selectedDates.length-1]===l&&a.classList.add(e.CSSClasses.daySelectedLast),e.selectedDates[0]!==l&&e.selectedDates[e.selectedDates.length-1]!==l&&a.classList.add(e.CSSClasses.daySelectedIntermediate)))},createDay=(e,t,a,n,s,l,r,i)=>{const d=document.createElement("div");d.className=e.CSSClasses.day;const c=document.createElement("button");c.className=`${e.CSSClasses.dayBtn}${i?` ${i}`:""}`,c.type="button",c.innerText=String(n),c.dataset.calendarDay=l;e.settings.visibility.weekNumbers&&(()=>{const t=getWeekNumber(l,e.settings.iso8601);t&&(c.dataset.calendarWeekNumber=String(t.week))})(),r?e.settings.visibility.daysOutside&&d.append(c):d.append(c),setDisabledDays(e,l,s),setDayModifier(e,t,d,c,s,l,r),a.append(d),e.actions.getDays&&e.actions.getDays(n,l,d,c,e)},prevMonth=(e,t,a,n,s)=>{let l=new Date(a,n,0).getDate()-(s-1);const r=0===n?a-1:a,i=0===n?12:n<10?`0${n}`:n;for(let n=s;n>0;n--,l++){const n=`${r}-${i}-${l}`,s=getDate(n).getDay();createDay(e,a,t,l,s,n,!0,e.CSSClasses.dayBtnPrev)}},currentMonth=(e,t,a,n,s)=>{for(let l=1;l<=a;l++){const a=new Date(n,s,l),r=getDateString(a),i=a.getDay();createDay(e,n,t,l,i,r,!1,null)}},nextMonth=(e,t,a,n,s,l)=>{const r=l+a,i=7*Math.ceil(r/7)-r,d=s+1===12?n+1:n,c=s+1===12?"01":s+2<10?`0${s+2}`:s+2;for(let a=1;a<=i;a++){const s=`${d}-${c}-${a<10?`0${a}`:String(a)}`,l=getDate(s).getDay();createDay(e,n,t,a,l,s,!0,e.CSSClasses.dayBtnNext)}},createDays=e=>{const t=e.HTMLElement.querySelectorAll(`.${e.CSSClasses.days}`),a=e.HTMLElement.querySelectorAll(`.${e.CSSClasses.weekNumbers}`),n=new Date(e.selectedYear,e.selectedMonth,1);t.forEach(((t,s)=>{const l=new Date(n);l.setMonth(l.getMonth()+s);const r=l.getMonth(),i=l.getFullYear(),d=new Date(i,r,1),c=new Date(i,r+1,0).getDate(),o=e.settings.iso8601?(0!==d.getDay()?d.getDay():7)-1:d.getDay();e.settings.selection.day&&t.classList.add(e.CSSClasses.daysSelecting),t.innerHTML="",prevMonth(e,t,i,r,o),currentMonth(e,t,c,i,r),nextMonth(e,t,c,i,r,o),createWeekNumbers(e,o,c,a[s],t),createPopup(e,t)}))},visibilityMonth=(e,t,a,n)=>{const s=new Date(n.setMonth(e.selectedMonth+a)).getMonth(),l=!1===e.settings.selection.month||"only-arrows"===e.settings.selection.month;t.tabIndex=l?-1:0,t.classList.toggle(e.CSSClasses.monthDisabled,l),t.setAttribute("data-calendar-selected-month",String(s)),t.innerText=e.locale.months[s]},visibilityYear=(e,t,a,n)=>{const s=new Date(n.setFullYear(e.selectedYear,e.selectedMonth+a)).getFullYear(),l=!1===e.settings.selection.year||"only-arrows"===e.settings.selection.year;t.tabIndex=l?-1:0,t.classList.toggle(e.CSSClasses.yearDisabled,l),t.setAttribute("data-calendar-selected-year",String(s)),t.innerText=String(s)},visibilityTitle=e=>{var t,a;const n=null==(t=e.HTMLElement)?void 0:t.querySelectorAll("[data-calendar-selected-month]"),s=null==(a=e.HTMLElement)?void 0:a.querySelectorAll("[data-calendar-selected-year]");if(!(null==n?void 0:n[0])&&(null==s?void 0:s[0]))return;const l=new Date(e.selectedYear,e.selectedMonth,1);null==n||n.forEach(((t,a)=>visibilityMonth(e,t,a,l))),null==s||s.forEach(((t,a)=>visibilityYear(e,t,a,l)))},changeMonth=(e,t)=>{const a=getDate(getDateString(new Date(e.selectedYear,e.selectedMonth,1)));({prev:()=>a.setMonth(a.getMonth()-e.jumpMonths),next:()=>a.setMonth(a.getMonth()+e.jumpMonths)})[t](),[e.selectedMonth,e.selectedYear]=[a.getMonth(),a.getFullYear()],visibilityTitle(e),visibilityArrows(e),createDays(e)},ArrowPrev=e=>``,ArrowNext=e=>``,Month=e=>``,Year=e=>``,Week=e=>`
`,Days=e=>`
`,Months=e=>`
`,Years=e=>`
`,WeekNumbers=e=>e.settings.visibility.weekNumbers?`
`:"",ControlTime=e=>e.settings.selection.time?`
`:"",components=Object.freeze(Object.defineProperty({__proto__:null,ArrowNext:ArrowNext,ArrowPrev:ArrowPrev,ControlTime:ControlTime,Days:Days,Month:Month,Months:Months,Week:Week,WeekNumbers:WeekNumbers,Year:Year,Years:Years},Symbol.toStringTag,{value:"Module"})),getComponent=e=>components[e],DOMParser=(e,t)=>t.replace(/[\n\t]/g,"").replace(/<#(?!\/?Multiple)(.*?)>/g,((t,a)=>{const n=(s=a.replace(/[/\s\n\t]/g,""),components[s]);var s;return n?n(e):""})).replace(/[\n\t]/g,""),MultipleParser=(e,t)=>t.replace(/<#Multiple>(.*?)<#\/Multiple>/g,((t,a)=>{let n="";for(let t=0;t{const{HTMLElement:a,CSSClasses:n,DOMTemplates:s,type:l,currentType:r,correctMonths:i}=e,d=(s,l)=>{if(!t)return;const r=a.querySelector(`.${n.controls}`);r&&a.removeChild(r);a.querySelector(`.${n.grid}`).classList.add(n.gridDisabled);const i=t.closest(`.${n.column}`);i.classList.add(s),i.innerHTML=DOMParser(e,l)},c={default:()=>{a.classList.add(n.calendarDefault),a.classList.remove(n.calendarMonth,n.calendarYear),a.innerHTML=DOMParser(e,s.default)},multiple:()=>{i&&(a.classList.add(n.calendarMultiple),a.classList.remove(n.calendarMonth,n.calendarYear),a.innerHTML=MultipleParser(e,DOMParser(e,s.multiple)))},month:()=>{"multiple"!==l?(a.classList.add(n.calendarMonth),a.classList.remove(n.calendarDefault,n.calendarYear),a.innerHTML=DOMParser(e,s.month)):d(n.columnMonth,s.month)},year:()=>{"multiple"!==l?(a.classList.add(n.calendarYear),a.classList.remove(n.calendarDefault,n.calendarMonth),a.innerHTML=DOMParser(e,s.year)):d(n.columnYear,s.year)}};a.classList.add(n.calendar),c[r]()},createYearEl=(e,t,a,n,s)=>{const l=t.cloneNode(!1);return l.className=`${e.CSSClasses.yearsYear}${a===s?` ${e.CSSClasses.yearsYearSelected}`:n?` ${e.CSSClasses.yearsYearDisabled}`:""}`,l.dataset.calendarYear=String(s),l.title=String(s),l.innerText=String(s),n&&(l.tabIndex=-1),l},createYears=(e,t)=>{const a=(null==t?void 0:t.dataset.calendarSelectedYear)?Number(null==t?void 0:t.dataset.calendarSelectedYear):e.selectedYear;e.currentType="year",createDOM(e,t),visibilityTitle(e),visibilityArrows(e);const n=e.HTMLElement.querySelector(`.${e.CSSClasses.years}`);if(!e.settings.selection.year||!n)return;n.classList.add(e.CSSClasses.yearsSelecting);const s="multiple"!==e.type||e.selectedYear===a?0:1,l=document.createElement("button");l.type="button";for(let t=e.viewYear-7;te.dateMax.getFullYear(),i=createYearEl(e,l,a,r,t);n.append(i),e.actions.getYears&&e.actions.getYears(t,i,e)}},handleClickArrow=(e,t)=>{const a=t.target.closest(`.${e.CSSClasses.arrow}`);a&&(["default","multiple"].includes(e.currentType)?changeMonth(e,a.dataset.calendarArrow):"year"===e.currentType&&void 0!==e.viewYear&&(e.viewYear+={prev:-15,next:15}[a.dataset.calendarArrow],createYears(e,t.target)),e.actions.clickArrow&&e.actions.clickArrow(t,e))},handleClickWeekNumber=(e,t)=>{var a;if(!e.settings.visibility.weekNumbers||!e.actions.clickWeekNumber)return;const n=t.target.closest(`.${e.CSSClasses.weekNumber}`),s=null==(a=e.HTMLElement)?void 0:a.querySelectorAll("[data-calendar-week-number]");if(!n||!s)return;const l=Number(n.innerText),r=Number(n.dataset.calendarYearWeek),i=[...s].filter((e=>Number(e.dataset.calendarWeekNumber)===l));e.actions.clickWeekNumber(t,l,i,r,e)},capitalizeFirstLetter=e=>`${e.charAt(0).toUpperCase()}${e.substring(1,e.length)}`.replace(/\./,""),getLocaleWeekday=(e,t)=>{const a=new Date(`1978-01-0${t+1}T00:00:00.000Z`).toLocaleString(e.settings.lang,{weekday:"short",timeZone:"UTC"});e.locale.weekday.push(capitalizeFirstLetter(a))},getLocaleMonth=(e,t)=>{const a=new Date(`1978-${t+1<=9?`0${t+1}`:t+1}-01T00:00:00.000Z`).toLocaleString(e.settings.lang,{month:"long",timeZone:"UTC"});e.locale.months.push(capitalizeFirstLetter(a))},getLocale=e=>{if("define"!==e.settings.lang||!e.locale.weekday[6]||!e.locale.months[11]){if("define"===e.settings.lang)throw new Error(messages.notLocale);e.locale.weekday=[],e.locale.months=[];for(let t=0;t<7;t++)getLocaleWeekday(e,t);for(let t=0;t<12;t++)getLocaleMonth(e,t)}},relationshipID=e=>{if("multiple"!==e.type)return 0;const t=[...e.HTMLElement.querySelectorAll(`.${e.CSSClasses.column}`)].findIndex((t=>t.classList.contains(`${e.CSSClasses.columnMonth}`)));return t>0?t:0},createMonthEl=(e,t,a,n,s,l)=>{const r=t.cloneNode(!1);return r.className=`${e.CSSClasses.monthsMonth}${a===l?` ${e.CSSClasses.monthsMonthSelected}`:s?` ${e.CSSClasses.monthsMonthDisabled}`:""}`,r.title=n,r.innerText=`${e.settings.visibility.monthShort?n.substring(0,3):n}`,r.dataset.calendarMonth=String(l),s&&(r.tabIndex=-1),r},createMonths=(e,t)=>{var a,n;const s=(null==t?void 0:t.dataset.calendarSelectedMonth)?Number(t.dataset.calendarSelectedMonth):e.selectedMonth,l=null==(a=null==t?void 0:t.closest(`.${e.CSSClasses.column}`))?void 0:a.querySelector(`.${e.CSSClasses.year}`),r=l?Number(l.dataset.calendarSelectedYear):e.selectedYear;e.currentType="month",createDOM(e,t),visibilityTitle(e);const i=null==(n=e.HTMLElement)?void 0:n.querySelector(`.${e.CSSClasses.months}`);if(!e.settings.selection.month||!i)return;i.classList.add(e.CSSClasses.monthsSelecting);const d=e.jumpMonths>1?e.locale.months.map(((t,a)=>s-e.jumpMonths*a)).concat(e.locale.months.map(((t,a)=>s+e.jumpMonths*a))).filter((e=>e>=0&&e<=12)):Array.from(Array(12).keys()),c=document.createElement("button");c.type="button";for(let t=0;t<12;t++){const a=e.locale.months[t],n=te.dateMax.getMonth()+relationshipID(e)&&r>=e.dateMax.getFullYear()||t!==s&&!d.includes(t),l=createMonthEl(e,c,s,a,n,t);i.append(l),e.actions.getMonths&&e.actions.getMonths(t,l,e)}},transformTime24=(e,t)=>e&&t?{0:{AM:"00",PM:"12"},1:{AM:"01",PM:"13"},2:{AM:"02",PM:"14"},3:{AM:"03",PM:"15"},4:{AM:"04",PM:"16"},5:{AM:"05",PM:"17"},6:{AM:"06",PM:"18"},7:{AM:"07",PM:"19"},8:{AM:"08",PM:"20"},9:{AM:"09",PM:"21"},10:{AM:"10",PM:"22"},11:{AM:"11",PM:"23"},12:{AM:"12",PM:"12"}}[Number(e)][t]:"",getInputElement=(e,t,a)=>e.querySelector(`.${t}${a?` input[name="${a}"]`:""}`),addMouseEvents=(e,t,a)=>{e.addEventListener("mouseover",(()=>t.classList.add(a))),e.addEventListener("mouseout",(()=>t.classList.remove(a)))},setTime=(e,t,a,n)=>{({hours:()=>{e.selectedHours=a},minutes:()=>{e.selectedMinutes=a}})[n](),e.selectedTime=`${e.selectedHours}:${e.selectedMinutes}${e.selectedKeeping?` ${e.selectedKeeping}`:""}`,e.actions.changeTime&&e.actions.changeTime(t,e),e.input&&e.HTMLInputElement&&e.actions.changeToInput&&e.actions.changeToInput(t,e)},changeRange=(e,t,a,n,s,l)=>{t.addEventListener("input",(t=>{const r=t.target,i=Number(r.value),d=i<10?`0${i}`:`${i}`;if("hours"!==s||12!==l)return a.value=d,void setTime(e,t,d,s);i0?(a.value=d,e.selectedKeeping="AM",n.innerText=e.selectedKeeping,setTime(e,t,d,s)):(0===i?(e.selectedKeeping="AM",n.innerText="AM"):(e.selectedKeeping="PM",n.innerText="PM"),a.value=transformTime12(r.value),setTime(e,t,transformTime12(r.value),s))}))},changeInput=(e,t,a,n,s,l)=>{a.addEventListener("change",(a=>{const r=a.target,i=Number(r.value),d=i<10?`0${i}`:`${i}`;"hours"===s&&12===l?r.value&&i<=l&&i>0?(r.value=d,t.value=transformTime24(d,e.selectedKeeping),setTime(e,a,d,s)):r.value&&i<24&&(i>l||0===i)?(0===i?(e.selectedKeeping="AM",n.innerText="AM"):(e.selectedKeeping="PM",n.innerText="PM"),r.value=transformTime12(r.value),t.value=d,setTime(e,a,transformTime12(r.value),s)):r.value=e.selectedHours:r.value&&i<=l&&i>=0?(r.value=d,t.value=d,setTime(e,a,d,s)):"hours"===s?r.value=e.selectedHours:"minutes"===s&&(r.value=e.selectedMinutes)}))},clickBtnKeepingTime=(e,t,a)=>{t.addEventListener("click",(n=>{e.selectedKeeping=t.innerText.includes("AM")?"PM":"AM",t.innerText=e.selectedKeeping,a.value=transformTime24(e.selectedHours,e.selectedKeeping),setTime(e,n,e.selectedHours,"hours")}))},changeTime=(e,t,a)=>{const n=24===a?23:a||12,s=getInputElement(t,e.CSSClasses.timeRange,"hours"),l=getInputElement(t,e.CSSClasses.timeRange,"minutes"),r=getInputElement(t,e.CSSClasses.timeHours,"hours"),i=getInputElement(t,e.CSSClasses.timeMinutes,"minutes"),d=t.querySelector(`.${e.CSSClasses.timeKeeping}`);addMouseEvents(s,r,e.CSSClasses.isFocus),addMouseEvents(l,i,e.CSSClasses.isFocus),changeRange(e,s,r,d,"hours",n),changeRange(e,l,i,d,"minutes",0),changeInput(e,s,r,d,"hours",n),changeInput(e,l,i,d,"minutes",59),d&&clickBtnKeepingTime(e,d,s)},InputTime=(e,t,a,n)=>``,RangeTime=(e,t,a,n,s,l)=>``,createTime=e=>{const t=e.HTMLElement.querySelector(`.${e.CSSClasses.time}`);if(!t)return;const a=!0===e.settings.selection.time?12:e.settings.selection.time,n="range"===e.settings.selection.controlTime,[s,l]=[0,23],[r,i]=[0,59];t.innerHTML=`
${InputTime("hours",e.CSSClasses.timeHours,e.selectedHours,n)}${InputTime("minutes",e.CSSClasses.timeMinutes,e.selectedMinutes,n)}${12===a?``:""}
${RangeTime("hours",e.CSSClasses.timeRange,s,l,e.settings.selection.stepHours,e.selectedKeeping?transformTime24(e.selectedHours,e.selectedKeeping):e.selectedHours)}${RangeTime("minutes",e.CSSClasses.timeRange,r,i,e.settings.selection.stepMinutes,e.selectedMinutes)}
`,changeTime(e,t,a)},createWeekDays=(e,t,a)=>{const n=document.createElement("b");t.innerHTML="";for(let s=0;s{const t=[...e.locale.weekday];if(!t[0])return;e.settings.iso8601&&t.push(t.shift());e.HTMLElement.querySelectorAll(`.${e.CSSClasses.week}`).forEach((a=>createWeekDays(e,a,t)))},themes=["light","dark","system"],haveListener={value:!1,set:()=>{haveListener.value=!0},check:()=>haveListener.value},getTheme=(e,t)=>themes.find((a=>{var n;return"system"!==a&&(null==(n=e.getAttribute(t))?void 0:n.includes(a))})),setTheme=(e,t)=>{e.dataset.calendarTheme=t},trackChangesThemeInSystemSettings=(e,t)=>{var a;if(a=t,setTheme(e.HTMLElement,a.matches?"dark":"light"),"system"!==e.settings.visibility.theme||haveListener.check())return;const n=t=>{const a=document.querySelectorAll(`.${e.CSSClasses.calendar}`);null==a||a.forEach((e=>setTheme(e,t.matches?"dark":"light")))};t.addEventListener?t.addEventListener("change",n):t.addListener(n),haveListener.set()},trackChangesThemeInHTMLElement=(e,t,a)=>{new MutationObserver((n=>{for(let s=0;s{const a=e.settings.visibility.themeDetect?document.querySelector(e.settings.visibility.themeDetect):null;if(!a)return void trackChangesThemeInSystemSettings(e,t);const n=e.settings.visibility.themeDetect.replace(/^.*\[(.+)\]/g,((e,t)=>t)),s=getTheme(a,n);s?(setTheme(e.HTMLElement,s),trackChangesThemeInHTMLElement(e,a,n)):trackChangesThemeInSystemSettings(e,t)},changeTheme=e=>{if(!themes.includes(e.settings.visibility.theme))throw new Error(messages.incorrectTheme);if("not all"===window.matchMedia("(prefers-color-scheme)").media)return void setTheme(e.HTMLElement,"light");({light:()=>setTheme(e.HTMLElement,"light"),dark:()=>setTheme(e.HTMLElement,"dark"),system:()=>detectTheme(e,window.matchMedia("(prefers-color-scheme: dark)"))})[e.settings.visibility.theme]()},create=e=>{const t={default:()=>{createWeek(e),createDays(e)},multiple:()=>{createWeek(e),createDays(e)},month:()=>createMonths(e),year:()=>createYears(e)};changeTheme(e),getLocale(e),createDOM(e),visibilityTitle(e),visibilityArrows(e),createTime(e),t[e.currentType]()},current={self:null,rangeMin:void 0,rangeMax:void 0},removeHoverEffect=()=>{var e;if(!(null==(e=current.self)?void 0:e.HTMLElement))return;const{CSSClasses:t}=current.self;current.self.HTMLElement.querySelectorAll(`.${current.self.CSSClasses.dayBtnHover}`).forEach((e=>{var a;e.classList.remove(current.self.CSSClasses.dayBtnHover),null==(a=e.parentElement)||a.classList.remove(t.dayHoverIntermediate,t.dayHoverFirst,t.dayHoverLast)}))},addHoverEffect=(e,t,a)=>{var n,s,l;if(!(null==(n=current.self)?void 0:n.selectedDates))return;const r=getDateString(e),{CSSClasses:i}=current.self;if(null==(s=current.self.rangeDisabled)?void 0:s.includes(r))return;const d=null==(l=current.self.HTMLElement)?void 0:l.querySelectorAll(`[data-calendar-day="${r}"]`);null==d||d.forEach((e=>{var t;e.classList.add(i.dayBtnHover),null==(t=e.parentElement)||t.classList.add(i.dayHoverIntermediate)})),null==t||t.forEach((e=>{var t;return null==(t=e.parentElement)?void 0:t.classList.add(i.dayHoverFirst)})),null==a||a.forEach((e=>{var t;return null==(t=e.parentElement)?void 0:t.classList.add(i.dayHoverLast)}))},handleHoverDaysEvent=e=>{var t;if(!e.target||!(null==(t=current.self)?void 0:t.selectedDates))return;if(!e.target.closest(`.${current.self.CSSClasses.days}`))return void removeHoverEffect();const a=e.target.closest("[data-calendar-day]");if(!a)return;const n=a.dataset.calendarDay,s=getDate(current.self.selectedDates[0]),l=getDate(n),r=current.self.HTMLElement.querySelectorAll(`[data-calendar-day="${current.self.selectedDates[0]}"]`),i=current.self.HTMLElement.querySelectorAll(`[data-calendar-day="${n}"]`),[d,c]=s{current.self&&"Escape"===e.key&&(current.self.selectedDates=[],current.self.HTMLElement.removeEventListener("mousemove",handleHoverDaysEvent),document.removeEventListener("keydown",handleCancelSelectionDays),create(current.self))},updateDisabledDates=()=>{var e,t,a;if(!(null==(t=null==(e=current.self)?void 0:e.selectedDates)?void 0:t[0])||!current.self.rangeDisabled||(null==(a=current.self.rangeDisabled)?void 0:a.length)<2)return;const n=getDate(current.self.selectedDates[0]),[s,l]=current.self.rangeDisabled.map((e=>getDate(e))).reduce((([e,t],a)=>[n>=a?a:e,n{current.self&&(current.self.rangeMin=current.rangeMin,current.self.rangeMax=current.rangeMax)},handleDayRangedSelection=(e,t)=>{var a;if(t){const n=1===e.selectedDates.length&&e.selectedDates[0].includes(t);e.selectedDates=n&&!e.settings.selection.cancelableDay?[t,t]:n&&e.settings.selection.cancelableDay?[]:e.selectedDates.length>1?[t]:[...e.selectedDates,t],null==(a=e.selectedDates)||a.sort(((e,t)=>+new Date(e)-+new Date(t)))}e.settings.range.disableGaps&&(current.rangeMin=current.rangeMin?current.rangeMin:e.rangeMin,current.rangeMax=current.rangeMax?current.rangeMax:e.rangeMax),current.self=e;({set:()=>{e.HTMLElement.addEventListener("mousemove",handleHoverDaysEvent),document.addEventListener("keydown",handleCancelSelectionDays),e.settings.range.disableGaps&&updateDisabledDates()},reset:()=>{const[t,a]=[e.selectedDates[0],e.selectedDates[e.selectedDates.length-1]];e.selectedDates=e.selectedDates[0]!==e.selectedDates[e.selectedDates.length-1]?parseDates([`${t}:${a}`]):[e.selectedDates[0],e.selectedDates[0]],e.HTMLElement.removeEventListener("mousemove",handleHoverDaysEvent),document.removeEventListener("keydown",handleCancelSelectionDays),e.settings.range.disableGaps&¤t.self&&(current.self.rangeMin=current.rangeMin,current.self.rangeMax=current.rangeMax)}})[1===e.selectedDates.length?"set":"reset"]()},handleDaySelection=(e,t,a)=>{if(!t.dataset.calendarDay)return;const n=t.dataset.calendarDay,s=t.classList.contains(e.CSSClasses.dayBtnSelected);s&&!e.settings.selection.cancelableDay||(e.selectedDates=s?e.selectedDates.filter((e=>e!==n)):a?[...e.selectedDates,n]:[n])},handleClickDay=(e,t)=>{var a;const n=t.target,s=e=>n.closest(`.${e}`),l=s(e.CSSClasses.dayBtn);if(!e.settings.selection.day||!["single","multiple","multiple-ranged"].includes(e.settings.selection.day)||!l)return;({single:()=>handleDaySelection(e,l,!1),multiple:()=>handleDaySelection(e,l,!0),"multiple-ranged":()=>handleDayRangedSelection(e,l.dataset.calendarDay)})[e.settings.selection.day](),null==(a=e.selectedDates)||a.sort(((e,t)=>+new Date(e)-+new Date(t))),e.actions.clickDay&&e.actions.clickDay(t,e);e.input&&e.HTMLInputElement&&e.HTMLElement&&e.actions.changeToInput&&e.actions.changeToInput(t,e);const r=s(e.CSSClasses.dayBtnPrev),i=s(e.CSSClasses.dayBtnNext);({prev:()=>changeMonth(e,"prev"),next:()=>changeMonth(e,"next"),default:()=>createDays(e)})[r?"prev":i?"next":"default"]()},getColumnID=(e,t,a,n,s)=>{const l=e.HTMLElement.querySelectorAll(`.${e.CSSClasses.column}`),r=[...l].findIndex((e=>e.classList.contains(t))),i=Number(l[r].querySelector(`.${a}`).getAttribute(s));return"month"===e.currentType&&r>=0?n-r:"year"===e.currentType&&e.selectedYear!==i?n-1:n},handleItemClick=(e,t,a,n,s)=>{const l={year:()=>{var a,n;return null==(n=(a=e.actions).clickYear)?void 0:n.call(a,t,e)},month:()=>{var a,n;return null==(n=(a=e.actions).clickMonth)?void 0:n.call(a,t,e)}};({year:()=>{if("multiple"===e.type){const t=getColumnID(e,e.CSSClasses.columnYear,e.CSSClasses.year,Number(s.dataset.calendarYear),"data-calendar-selected-year"),a=e.selectedMonthe.dateMax.getMonth()&&t>=e.dateMax.getFullYear(),l=te.dateMax.getFullYear();a||l?(e.selectedYear=e.dateMin.getFullYear(),e.selectedMonth=e.dateMin.getMonth()):n||r?(e.selectedYear=e.dateMax.getFullYear(),e.selectedMonth=e.dateMax.getMonth()):e.selectedYear=t}else e.selectedYear=Number(s.dataset.calendarYear)},month:()=>{if("multiple"===e.type){const t=getColumnID(e,e.CSSClasses.columnMonth,e.CSSClasses.month,Number(s.dataset.calendarMonth),"data-calendar-selected-month"),a=s.closest(`.${n.column}`).querySelector(`.${e.CSSClasses.year}`);e.selectedYear=Number(a.dataset.calendarSelectedYear);const l=te.dateMax.getMonth()&&e.selectedYear>=e.dateMax.getFullYear();e.selectedMonth=l?e.dateMin.getMonth():r?e.dateMax.getMonth():t}else e.selectedMonth=Number(s.dataset.calendarMonth)}})[a](),l[a](),e.currentType=e.type,create(e)},handleClickMonthOrYear=(e,t,a,n)=>{if(!e.settings.selection[a])return;const s=t.target,l=e=>s.closest(`.${e}`),r=l(n.header),i=l(n.item),d=l(e.CSSClasses.grid),c=l(e.CSSClasses.column);if(e.currentType!==a&&r){({year:()=>createYears(e,s),month:()=>createMonths(e,s)})[a]()}else i?handleItemClick(e,t,a,n,i):(e.currentType===a&&r||"multiple"===e.type&&e.currentType===a&&d&&!c)&&(e.currentType=e.type,create(e))},handleClick=e=>{const t=t=>{handleClickArrow(e,t),handleClickWeekNumber(e,t),handleClickDay(e,t),handleClickMonthOrYear(e,t,"month",{header:e.CSSClasses.month,item:e.CSSClasses.monthsMonth,column:e.CSSClasses.columnMonth}),handleClickMonthOrYear(e,t,"year",{header:e.CSSClasses.year,item:e.CSSClasses.yearsYear,column:e.CSSClasses.columnYear})};return e.HTMLElement.addEventListener("click",t),()=>e.HTMLElement.removeEventListener("click",t)},reset=(e,{year:t,month:a,dates:n,holidays:s,time:l}={})=>{var r;const i=__spreadValues({},e.settings.selected);e.settings.selected.year=t?i.year:e.selectedYear,e.settings.selected.month=a?i.month:e.selectedMonth,e.settings.selected.holidays=s?i.holidays:e.selectedHolidays,e.settings.selected.time=l?i.time:e.selectedTime,e.settings.selected.dates="only-first"===n&&(null==(r=e.selectedDates)?void 0:r[0])?[e.selectedDates[0]]:!0===n?i.dates:e.selectedDates,setVariables(e),create(e),e.settings.selected=i,"multiple-ranged"===e.settings.selection.day&&n&&handleDayRangedSelection(e)},setPositionCalendar=(e,t,a,n)=>{const s={top:-t.offsetHeight,bottom:e.offsetHeight,left:0,center:e.offsetWidth/2-t.offsetWidth/2,right:e.offsetWidth-t.offsetWidth},l=Array.isArray(a)?a[0]:"bottom",r=Array.isArray(a)?a[1]:a;t.classList.add("bottom"===l?n.calendarToInputBottom:n.calendarToInputTop);const i=e.getBoundingClientRect(),d=window.scrollX||document.documentElement.scrollLeft,c=window.scrollY||document.documentElement.scrollTop,o=i.top+c+s[l],u=i.left+d+s[r];Object.assign(t.style,{left:`${u}px`,top:`${o}px`})},handleInput=e=>{let t=!0;const a=[];e.HTMLInputElement=e.HTMLElement;const n=()=>setPositionCalendar(e.HTMLInputElement,e.HTMLElement,e.settings.visibility.positionToInput,e.CSSClasses),s=t=>{var a;e&&t.target!==e.HTMLInputElement&&!(null==(a=e.HTMLElement)?void 0:a.contains(t.target))&&(e.HTMLInputElement&&e.HTMLElement&&e.hide(),window.removeEventListener("resize",n),document.removeEventListener("click",s,{capture:!0}))};return e.HTMLInputElement.addEventListener("click",(()=>{t?a.push((()=>{const a=document.createElement("div");return a.className=`${e.CSSClasses.calendar} ${e.CSSClasses.calendarToInput} ${e.CSSClasses.calendarHidden}`,e.HTMLElement=a,document.body.append(e.HTMLElement),t=!1,setTimeout((()=>{setPositionCalendar(e.HTMLInputElement,a,e.settings.visibility.positionToInput,e.CSSClasses),e.show()}),0),reset(e,{year:!0,month:!0,dates:!0,holidays:!0,time:!0}),e.actions.initCalendar&&e.actions.initCalendar(e),handleClick(e)})()):(setPositionCalendar(e.HTMLInputElement,e.HTMLElement,e.settings.visibility.positionToInput,e.CSSClasses),e.show()),window.addEventListener("resize",n),document.addEventListener("click",s,{capture:!0})})),()=>{a.forEach((e=>e()))}},init=e=>(e.HTMLOriginalElement=e.HTMLElement.cloneNode(!0),e.isInit=!0,e.input?handleInput(e):(setVariables(e),create(e),e.actions.initCalendar&&e.actions.initCalendar(e),handleClick(e))),update=(e,{year:t,month:a,dates:n,holidays:s,time:l}={})=>{if(!e.isInit)throw new Error(messages.notInit);reset(e,{year:t,month:a,dates:n,holidays:s,time:l}),e.actions.updateCalendar&&e.actions.updateCalendar(e)},destroy=e=>{var t,a,n,s;if(!e.isInit)throw new Error(messages.notInit);e.input?(null==(a=null==(t=e.HTMLElement)?void 0:t.parentElement)||a.removeChild(e.HTMLElement),null==(n=e.HTMLInputElement)||n.replaceWith(e.HTMLOriginalElement),e.HTMLInputElement=void 0):null==(s=e.HTMLElement)||s.replaceWith(e.HTMLOriginalElement),e.HTMLElement=e.HTMLOriginalElement,e.actions.destroyCalendar&&e.actions.destroyCalendar(e)},show=e=>{e.currentType?(e.HTMLElement.classList.remove(e.CSSClasses.calendarHidden),e.actions.showCalendar&&e.actions.showCalendar(e)):e.HTMLElement.click()},hide=e=>{e.currentType&&(e.HTMLElement.classList.add(e.CSSClasses.calendarHidden),e.actions.hideCalendar&&e.actions.hideCalendar(e))};class VanillaCalendar extends DefaultOptionsCalendar{constructor(e,t){if(super(),__publicField(this,"init",(()=>{return(e=this).HTMLOriginalElement=e.HTMLElement.cloneNode(!0),e.isInit=!0,e.input?handleInput(e):(setVariables(e),create(e),e.actions.initCalendar&&e.actions.initCalendar(e),handleClick(e));var e})),__publicField(this,"update",(e=>update(this,e))),__publicField(this,"destroy",(()=>destroy(this))),__publicField(this,"show",(()=>{var e;(e=this).currentType?(e.HTMLElement.classList.remove(e.CSSClasses.calendarHidden),e.actions.showCalendar&&e.actions.showCalendar(e)):e.HTMLElement.click()})),__publicField(this,"hide",(()=>{var e;(e=this).currentType&&(e.HTMLElement.classList.add(e.CSSClasses.calendarHidden),e.actions.hideCalendar&&e.actions.hideCalendar(e))})),this.HTMLElement="string"==typeof e?document.querySelector(e):e,!this.HTMLElement)throw new Error(messages.notFoundSelector(e));if(!t)return;const a=(e,t)=>{Object.keys(t).forEach((n=>{"object"!=typeof e[n]||"object"!=typeof t[n]||t[n]instanceof Date?e[n]=t[n]:a(e[n],t[n])}))};a(this,t)}}export{VanillaCalendar as default}; \ No newline at end of file diff --git a/package/src/scripts/handles/handleInput.ts b/package/src/scripts/handles/handleInput.ts index a81487dd..cd8601a8 100644 --- a/package/src/scripts/handles/handleInput.ts +++ b/package/src/scripts/handles/handleInput.ts @@ -1,6 +1,6 @@ import VanillaCalendar from '@src/vanilla-calendar'; import handleClick from '@scripts/handles/handleClick'; -import update from '@scripts/update'; +import reset from '@scripts/reset'; import { IVisibility, CSSClasses } from '@/package/types'; const setPositionCalendar = (input: HTMLInputElement, calendar: HTMLElement, position: IVisibility['positionToInput'], css: CSSClasses) => { @@ -43,10 +43,10 @@ const handleInput = (self: VanillaCalendar) => { setPositionCalendar(self.HTMLInputElement as HTMLInputElement, calendar, self.settings.visibility.positionToInput, self.CSSClasses); self.show(); }, 0); - update(self, { + reset(self, { year: true, month: true, dates: true, holidays: true, time: true, }); - + if (self.actions.initCalendar) self.actions.initCalendar(self); return handleClick(self); }; diff --git a/package/src/scripts/reset.ts b/package/src/scripts/reset.ts new file mode 100644 index 00000000..e3f0ffbc --- /dev/null +++ b/package/src/scripts/reset.ts @@ -0,0 +1,34 @@ +import { IReset } from '@package/types'; +import VanillaCalendar from '@src/vanilla-calendar'; +import setVariables from '@scripts/helpers/setVariables'; +import create from '@scripts/create'; +import handleDayRangedSelection from '@scripts/handles/handleDayRangedSelection'; + +const reset = (self: VanillaCalendar, { + year, + month, + dates, + holidays, + time, +}: IReset = {}) => { + const previousSelected = { ...self.settings.selected }; + + self.settings.selected.year = year ? previousSelected.year : self.selectedYear; + self.settings.selected.month = month ? previousSelected.month : self.selectedMonth; + self.settings.selected.holidays = holidays ? previousSelected.holidays : self.selectedHolidays; + self.settings.selected.time = time ? previousSelected.time : self.selectedTime; + + self.settings.selected.dates = dates === 'only-first' && self.selectedDates?.[0] + ? [self.selectedDates[0]] + : dates === true + ? previousSelected.dates + : self.selectedDates; + + setVariables(self); + create(self); + + self.settings.selected = previousSelected; + if (self.settings.selection.day === 'multiple-ranged' && dates) handleDayRangedSelection(self); +}; + +export default reset; diff --git a/package/src/scripts/update.ts b/package/src/scripts/update.ts index e28088fd..e49c1e13 100644 --- a/package/src/scripts/update.ts +++ b/package/src/scripts/update.ts @@ -1,9 +1,7 @@ import { IReset } from '@package/types'; import VanillaCalendar from '@src/vanilla-calendar'; import messages from '@scripts/helpers/getMessages'; -import setVariables from '@scripts/helpers/setVariables'; -import create from '@scripts/create'; -import handleDayRangedSelection from '@scripts/handles/handleDayRangedSelection'; +import reset from '@scripts/reset'; const update = (self: VanillaCalendar, { year, @@ -14,24 +12,13 @@ const update = (self: VanillaCalendar, { }: IReset = {}) => { if (!self.isInit) throw new Error(messages.notInit); - const previousSelected = { ...self.settings.selected }; - - self.settings.selected.year = year ? previousSelected.year : self.selectedYear; - self.settings.selected.month = month ? previousSelected.month : self.selectedMonth; - self.settings.selected.holidays = holidays ? previousSelected.holidays : self.selectedHolidays; - self.settings.selected.time = time ? previousSelected.time : self.selectedTime; - - self.settings.selected.dates = dates === 'only-first' && self.selectedDates?.[0] - ? [self.selectedDates[0]] - : dates === true - ? previousSelected.dates - : self.selectedDates; - - setVariables(self); - create(self); - - self.settings.selected = previousSelected; - if (self.settings.selection.day === 'multiple-ranged' && dates) handleDayRangedSelection(self); + reset(self, { + year, + month, + dates, + holidays, + time, + }); if (self.actions.updateCalendar) self.actions.updateCalendar(self); };