timepicker-ui 3.0.1 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.umd.js CHANGED
@@ -1 +1 @@
1
- !function(e,i){"object"==typeof exports&&"undefined"!=typeof module?i(exports):"function"==typeof define&&define.amd?define(["exports"],i):i((e="undefined"!=typeof globalThis?globalThis:e||self).TimepickerUI={})}(this,function(e){"use strict";const i=(e,i)=>({...i,...e}),t=(e,i)=>{const{touches:t}=e,{clientX:s,clientY:r}=e;if(!i)return;const{left:n,top:c}=i.getBoundingClientRect();let o={x:0,y:0};if(void 0===t)o={x:s-n,y:r-c};else if(void 0!==t&&t.length>0&&Object.keys(t).length>0){const{clientX:e,clientY:i}=t[0];o={x:e-n,y:i-c}}return 0!==Object.keys(o).length||o.constructor!==Object?o:void 0},s=(e,i)=>!!e&&e.classList.contains(i),r=(e,i,t,s,r)=>{if(!e)return;const n=new CustomEvent(t,{detail:s,bubbles:!0,cancelable:!0});try{if(e.dispatchEvent(n)&&i!==t){const t=new CustomEvent(i,{detail:s,bubbles:!0,cancelable:!0});e.dispatchEvent(t)}}catch(e){console.warn(`TimepickerUI: Error dispatching event ${t}:`,e)}if(r&&"function"==typeof r)try{r(s)}catch(e){console.warn(`TimepickerUI: Error in ${t} callback:`,e)}},n=(e,i,t)=>((e,i)=>Math.round(e/i)*i)(e,i*t),c=(e,i)=>Array.from({length:Number(i)-Number(e)+1},(i,t)=>Number(e)+t),o=(e,i)=>Array.from({length:Number(i)-Number(e)+1},(e,t)=>Number(i)-t).reverse(),a=e=>{e&&"function"==typeof e&&e()},l=(e="")=>{const i=e.replace(/(AM|PM|am|pm)/,e=>` ${e}`),t=new Date(`September 20, 2000 ${i}`);return`${t.getHours().toString().padStart(2,"0")}:${t.getMinutes().toString().padStart(2,"0")}`},m=(e,i,t,s)=>{const r={hour:"12",minutes:"00",type:"24h"===i?void 0:"PM"};if(!e)return r;const n=e.value.trim();if(!t&&""===n)return r;if("boolean"==typeof t&&t){const e=new Date,[t,s]=e.toLocaleTimeString().split(":"),r=Number(t)<=9?`0${Number(t)}`:t;if(/[a-z]/i.test(s)&&"12h"===i){const[e,i]=s.split(" ");return{hour:r,minutes:e,type:i}}return{hour:r,minutes:s,type:void 0}}if("object"==typeof t){const{time:e,locales:r,preventClockType:n}=t,c=e??new Date;if(n&&s){const[e,i]=new Date(c).toLocaleTimeString().split(":");if(/[a-z]/i.test(i)){const[t,s]=i.split(" ");return{hour:e,minutes:t,type:s}}return{hour:Number(e)<=9?`0${Number(e)}`:e,minutes:i,type:void 0}}const[o,a]=new Date(c).toLocaleTimeString(r,{timeStyle:"short"}).split(":"),l=Number(o)<=9?`0${Number(o)}`:o;if(/[a-z]/i.test(a)&&"12h"===i){const[e,i]=a.split(" ");return{hour:l,minutes:e,type:i}}if("12h"===i){const[e,i]=new Date(`1970-01-01T${o}:${a}Z`).toLocaleTimeString("en-US",{timeZone:"UTC",hour12:!0,hour:"numeric",minute:"numeric"}).split(":"),[t,s]=i.split(" ");return{hour:Number(e)<=9?`0${Number(e)}`:e,minutes:t,type:s}}return{hour:l,minutes:a,type:void 0}}const[c,o]=n.split(" "),[a="",l=""]=c.split(":"),m=a.replace(/\D/g,""),p=l.replace(/\D/g,""),u={hour:m.padStart(2,"0"),minutes:p.padStart(2,"0"),type:"12h"===i?o:void 0};if(m.length>2||p.length>2)return{...u,error:"Invalid input: too many digits.",currentHour:a,currentMin:l};if(/[a-z]/i.test(c))return{...u,error:"Input contains invalid letters."};if(n.includes(" ")&&(!o||n.length>8||"AM"!==o&&"PM"!==o))return{...u,error:"Invalid AM/PM format or length.",currentLength:n.length,currentType:o};const h=Number(m),d=Number(p);if("12h"===i){if(h<1||h>12||d<0||d>59||"AM"!==o&&"PM"!==o)return{...u,error:"Invalid 12h time.",currentHour:h,currentMin:d,currentType:o}}else if(h<0||h>23||d<0||d>59)return{...u,error:"Invalid 24h time.",currentHour:h,currentMin:d};return u},p=(e,i,t)=>{const s=Number(e);if(Number.isNaN(s))return!1;switch(i){case"hour":return"24h"===t?s>=0&&s<=23:s>0&&s<=12;case"minutes":return s>=0&&s<=59;default:return}},u={amLabel:"AM",animation:!0,appendModalSelector:"",backdrop:!0,cancelLabel:"CANCEL",editable:!1,enableScrollbar:!1,enableSwitchIcon:!1,mobileTimeLabel:"Enter Time",focusInputAfterCloseModal:!1,hourMobileLabel:"Hour",iconTemplate:'<i class="material-icons timepicker-ui-keyboard-icon">keyboard</i>',iconTemplateMobile:'<i class="material-icons timepicker-ui-keyboard-icon">schedule</i>',incrementHours:1,incrementMinutes:1,minuteMobileLabel:"Minute",mobile:!1,okLabel:"OK",pmLabel:"PM",timeLabel:"Select Time",switchToMinutesAfterSelectHour:!1,theme:"basic",clockType:"12h",disabledTime:void 0,currentTime:void 0,focusTrap:!0,delayHandler:300,inline:void 0,cssClass:void 0},h="timepicker-ui",d="mousedown mouseup mousemove mouseleave mouseover touchstart touchmove touchend",k="active",v=(e,i)=>{let t;return(...s)=>{clearTimeout(t),t=setTimeout(()=>{e(...s)},i)}},b=["00","13","14","15","16","17","18","19","20","21","22","23"],T=["12","1","2","3","4","5","6","7","8","9","10","11"],y=["00","05","10","15","20","25","30","35","40","45","50","55"];class g{array;classToAdd;clockFace;tipsWrapper;theme;clockType;disabledTime;hour;constructor(e){this.array=e?.array,this.classToAdd=e?.classToAdd,this.clockFace=e?.clockFace,this.tipsWrapper=e?.tipsWrapper,this.theme=e?.theme,this.clockType=e?.clockType,this.disabledTime=e?.disabledTime,this.hour=e?.hour}clean=()=>{const e=this.tipsWrapper?.querySelectorAll("span.timepicker-ui-hour-time-12"),i=this.tipsWrapper?.querySelectorAll("span.timepicker-ui-minutes-time");this._removeClasses(e),this._removeClasses(i)};create=()=>{if(!(this.clockFace&&this.array&&this.classToAdd&&this.tipsWrapper))return;const e=(this.clockFace.offsetWidth-32)/2,i=(this.clockFace.offsetHeight-32)/2,t=e-9;this.tipsWrapper.innerHTML="",this.array?.forEach((r,n)=>{const c=n*(360/this.array.length)*(Math.PI/180);const o=document.createElement("span"),a=document.createElement("span");a.innerHTML=r,this.disabledTime&&(Array.isArray(this.disabledTime)&&this.disabledTime?.includes(r)&&(a.classList.add("timepicker-ui-tips-disabled"),o.classList.add("timepicker-ui-tips-disabled")),this.hour===this.disabledTime.removedStartedHour&&this.disabledTime?.startMinutes?.includes(r)&&(a.classList.add("timepicker-ui-tips-disabled"),o.classList.add("timepicker-ui-tips-disabled"),a.tabIndex=-1),this.hour===this.disabledTime.removedEndHour&&this.disabledTime?.endMinutes?.includes(r)&&(a.classList.add("timepicker-ui-tips-disabled"),o.classList.add("timepicker-ui-tips-disabled"),a.tabIndex=-1)),"24h"===this.clockType?(a.classList.add("timepicker-ui-value-tips-24h"),s(a,"timepicker-ui-tips-disabled")||(a.tabIndex=0)):(a.classList.add("timepicker-ui-value-tips"),s(a,"timepicker-ui-tips-disabled")||(a.tabIndex=0)),o.classList.add(this.classToAdd),"crane-straight"===this.theme&&(o.classList.add("crane-straight"),a.classList.add("crane-straight")),"m3"===this.theme&&(o.classList.add("m3"),a.classList.add("m3")),"dark"===this.theme&&(o.classList.add("dark"),a.classList.add("dark")),"glassmorphic"===this.theme&&(o.classList.add("glassmorphic"),a.classList.add("glassmorphic")),"pastel"===this.theme&&(o.classList.add("pastel"),a.classList.add("pastel")),"ai"===this.theme&&(o.classList.add("ai"),a.classList.add("ai")),"cyberpunk"===this.theme&&(o.classList.add("cyberpunk"),a.classList.add("cyberpunk")),o.style.left=e+Math.sin(c)*t-o.offsetWidth+"px",o.style.bottom=i+Math.cos(c)*t-o.offsetHeight+"px",o.appendChild(a),this.tipsWrapper?.appendChild(o)})};updateDisable=e=>{const i=this.tipsWrapper?.querySelectorAll("span.timepicker-ui-hour-time-12"),t=this.tipsWrapper?.querySelectorAll("span.timepicker-ui-minutes-time");if(this._removeClasses(i),this._removeClasses(t),e?.hoursToUpdate&&i&&this._addClassesWithIncludes(i,e.hoursToUpdate),e?.minutesToUpdate&&t){const{actualHour:i,removedEndHour:s,removedStartedHour:r,startMinutes:n,endMinutes:c}=e.minutesToUpdate;s===i&&c.length>0?this._addClassesWithIncludes(t,c):Number(i)>Number(r)&&Number(i)<Number(s)&&this._addClasses(t),r===i&&n.length>0?this._addClassesWithIncludes(t,n):Number(i)>Number(r)&&Number(i)<Number(s)&&this._addClasses(t)}if(e){const{amHours:s,pmHours:r,activeMode:n,startMinutes:c,endMinutes:o,removedAmHour:a,removedPmHour:l,actualHour:m}=e.minutesToUpdate;if(!s||!r)return;i&&(s&&"AM"===n&&this._addClassesWithIncludes(i,s),r&&"PM"===n&&this._addClassesWithIncludes(i,r)),t&&c&&o&&("AM"===n&&("00"===o[0]&&1===o.length&&0===c.length&&Number(m)>=Number(s[0])&&this._addClasses(t),0===c.length&&o.length>1&&Number(m)>=Number(a)&&this._addClasses(t),c.length>0&&o.length>1&&"00"===o[0]&&(Number(a)===Number(m)?this._addClassesWithIncludes(t,c):Number(m)>Number(a)&&this._addClasses(t)),"00"===o[0]&&1===o.length&&c.length>0&&(Number(a)===Number(m)?this._addClassesWithIncludes(t,c):Number(m)>Number(a)&&this._addClasses(t))),"PM"===n&&(m<Number(l)&&this._addClasses(t),m===l&&this._addClassesWithIncludes(t,o),o.length>0&&Number(m)===l-1&&this._addClassesWithIncludes(t,o)))}};_removeClasses=e=>{e?.forEach(({classList:e,children:i})=>{e.remove("timepicker-ui-tips-disabled"),i[0].classList.remove("timepicker-ui-tips-disabled"),i[0].tabIndex=0})};_addClasses=e=>{e?.forEach(({classList:e,children:i})=>{e.add("timepicker-ui-tips-disabled"),i[0].classList.add("timepicker-ui-tips-disabled"),i[0].tabIndex=-1})};_addClassesWithIncludes=(e,i)=>{e?.forEach(({classList:e,children:t,textContent:s})=>{i?.includes(s)&&(e.add("timepicker-ui-tips-disabled"),t[0].classList.add("timepicker-ui-tips-disabled"),t[0].tabIndex=-1)})}}const _=(e,i,t,s)=>{if(e){if(Array.isArray(e)&&e.length>0){return!e.map(e=>p(e,i,t)).some(e=>!1===e)}if("string"==typeof e||"number"==typeof e){const r=p(e,i,t),n=s?.map(Number).includes(Number(e));return!(!r||n)}}};class M{timepicker;constructor(e){this.timepicker=e}handleOpenOnClick=()=>{this.timepicker.openElement.forEach(e=>e?.addEventListener("click",()=>this.timepicker._eventsBundle()))};handleOpenOnEnterFocus=()=>{this.timepicker.input.addEventListener("keydown",({target:e,key:i})=>{e.disabled||"Enter"===i&&this.timepicker.open()})};handleCancelButton=()=>{this.timepicker.cancelButton.addEventListener("click",()=>{const e=m(this.timepicker.input,this.timepicker._options.clockType);r(this.timepicker._element,"cancel","timepicker:cancel",{...e,hourNotAccepted:this.timepicker.hour.value,minutesNotAccepted:this.timepicker.minutes.value,type:this.timepicker.activeTypeMode?.dataset.type,degreesHours:this.timepicker._degreesHours,degreesMinutes:this.timepicker._degreesMinutes},this.timepicker._options.onCancel),this.timepicker.close()()})};handleOkButton=()=>{this.timepicker.okButton?.addEventListener("click",()=>{const{clockType:e,disabledTime:i}=this.timepicker._options,t=p(this.timepicker.hour.value,"hour",e),s=p(this.timepicker.minutes.value,"minutes",e);let n;const c=_(this.timepicker.hour.value,"hour",e,i?.hours),o=_(this.timepicker.minutes.value,"minutes",e,i?.minutes);if(i?.interval&&(n=((e,i,t,s)=>{const r=t?l(`${e}:${i} ${t}`.trim()):`${e}:${i}`.trim();let n,c;if(t){const[e,i]=s.trim().split("-").map(e=>e.trim());n=l(e),c=l(i)}else{const[e,i]=s.trim().split("-"),t=e=>e.trim().split(":").map(e=>Number(e)<=9?`0${Number(e)}`:e).join(":");n=t(e),c=t(i)}return r<n||r>c})(this.timepicker.hour.value,this.timepicker.minutes.value,this.timepicker.activeTypeMode?.textContent,i.interval)),!1===n||!1===t||!1===s||!1===c||!1===o)return!1!==n&&s&&o||this.timepicker.minutes.classList.add("invalid-value"),void(!1!==n&&t&&c||this.timepicker.hour.classList.add("invalid-value"));this.timepicker.input.value=`${this.timepicker.hour.value}:${this.timepicker.minutes.value} ${"24h"===this.timepicker._options.clockType?"":this.timepicker.activeTypeMode?.dataset.type}`.trimEnd(),r(this.timepicker._element,"accept","timepicker:confirm",{hour:this.timepicker.hour.value,minutes:this.timepicker.minutes.value,type:this.timepicker.activeTypeMode?.dataset.type,degreesHours:this.timepicker._degreesHours,degreesMinutes:this.timepicker._degreesMinutes},this.timepicker._options.onConfirm),this.timepicker.close()()})};handleBackdropClick=()=>{this.timepicker.modalElement?.addEventListener("click",e=>{const i=e.target;if(!s(i,"timepicker-ui-modal"))return;const t=m(this.timepicker.input,this.timepicker._options.clockType);r(this.timepicker._element,"cancel","timepicker:cancel",{...t,hourNotAccepted:this.timepicker.hour.value,minutesNotAccepted:this.timepicker.minutes.value,type:this.timepicker.activeTypeMode?.dataset.type,degreesHours:this.timepicker._degreesHours,degreesMinutes:this.timepicker._degreesMinutes},this.timepicker._options.onCancel),this.timepicker.close()()})};getDestructuringObj(e){const{endMinutes:i,removedEndHour:t,removedStartedHour:s,startMinutes:r,pmHours:n,amHours:c,removedAmHour:o,removedPmHour:a}=this.timepicker._disabledTime.value;return e?{minutesToUpdate:{actualHour:this.timepicker.hour.value,pmHours:n,amHours:c,activeMode:this.timepicker.activeTypeMode?.textContent,startMinutes:r,endMinutes:i,removedAmHour:o,removedPmHour:a}}:{minutesToUpdate:{endMinutes:i,removedEndHour:t,removedStartedHour:s,actualHour:this.timepicker.hour.value,startMinutes:r}}}handleAmClick=()=>{this.timepicker._clickTouchEvents.forEach(e=>{this.timepicker.AM.addEventListener(e,e=>{if(e.target.classList.add(k),this.timepicker.PM.classList.remove(k),"12h"===this.timepicker._options.clockType&&this.timepicker._options.disabledTime?.interval){const e=new g({clockFace:this.timepicker.clockFace,tipsWrapper:this.timepicker.tipsWrapper,array:s(this.timepicker.hour,k)?T:y});this.timepicker._disabledTime?.value.startType===this.timepicker._disabledTime?.value.endType?setTimeout(()=>{this.timepicker._disabledTime?.value.startType===this.timepicker.activeTypeMode?.textContent?e.updateDisable({hoursToUpdate:this.timepicker._disabledTime?.value?.rangeArrHour,...this.getDestructuringObj()}):e.clean()},300):setTimeout(()=>{e.updateDisable({...this.getDestructuringObj(!0)})},300),e.updateDisable()}r(this.timepicker._element,"selectamtypemode","timepicker:select-am",{hour:this.timepicker.hour.value,minutes:this.timepicker.minutes.value,type:this.timepicker.activeTypeMode?.dataset.type,degreesHours:this.timepicker._degreesHours,degreesMinutes:this.timepicker._degreesMinutes},this.timepicker._options.onSelectAM)})})};handlePmClick=()=>{this.timepicker._clickTouchEvents.forEach(e=>{this.timepicker.PM.addEventListener(e,e=>{if(e.target.classList.add(k),this.timepicker.AM.classList.remove(k),"12h"===this.timepicker._options.clockType&&this.timepicker._options.disabledTime?.interval){const e=new g({clockFace:this.timepicker.clockFace,tipsWrapper:this.timepicker.tipsWrapper,array:s(this.timepicker.hour,k)?T:y});this.timepicker._disabledTime?.value.startType===this.timepicker._disabledTime?.value.endType?setTimeout(()=>{this.timepicker._disabledTime?.value.startType===this.timepicker.activeTypeMode?.textContent?e.updateDisable({hoursToUpdate:this.timepicker._disabledTime?.value?.rangeArrHour,...this.getDestructuringObj()}):e.clean()},300):setTimeout(()=>{e.updateDisable({...this.getDestructuringObj(!0)})},300)}r(this.timepicker._element,"selectpmtypemode","timepicker:select-pm",{hour:this.timepicker.hour.value,minutes:this.timepicker.minutes.value,type:this.timepicker.activeTypeMode?.dataset.type,degreesHours:this.timepicker._degreesHours,degreesMinutes:this.timepicker._degreesMinutes},this.timepicker._options.onSelectPM)})})};handleClasses24h=(e,i)=>{const t=e.target;this.timepicker.hourTips&&"24h"===this.timepicker._options.clockType&&(Number(t.textContent)>12||0===Number(t.textContent)?this.timepicker.clockManager.setCircleClockClasses24h():this.timepicker.clockManager.removeCircleClockClasses24h(),this.timepicker._options.mobile||this.timepicker.tipsWrapperFor24h?.classList.remove("timepicker-ui-tips-wrapper-24h-disabled")),t&&i&&(i.value=t.value.replace(/\D+/g,""),i.click())};handleHourEvents=()=>{this.timepicker._inputEvents.forEach(e=>{this.timepicker.hour?.addEventListener(e,e=>{const i=e.target;if(null!==this.timepicker.clockFace&&this.timepicker.animationManager.handleAnimationSwitchTipsMode(),"24h"===this.timepicker._options.clockType&&null!==this.timepicker.clockFace&&(Number(this.timepicker.hour.value)>12||"00"===this.timepicker.hour.value?this.timepicker.clockManager.setCircleClockClasses24h():this.timepicker.clockManager.removeCircleClockClasses24h(),this.timepicker._options.mobile||this.timepicker.tipsWrapperFor24h?.classList.remove("timepicker-ui-tips-wrapper-24h-disabled")),this.timepicker.clockManager.setHoursToClock(i.value),this.timepicker.minutes.classList.remove(k),this.timepicker.hour.classList.add(k),"12h"===this.timepicker._options.clockType&&this.timepicker._options.disabledTime?.interval){const e=new g({clockFace:this.timepicker.clockFace,tipsWrapper:this.timepicker.tipsWrapper,array:s(this.timepicker.hour,k)?T:y});this.timepicker._disabledTime?.value.startType===this.timepicker._disabledTime?.value.endType?setTimeout(()=>{this.timepicker._disabledTime?.value.startType===this.timepicker.activeTypeMode?.textContent?e.updateDisable({hoursToUpdate:this.timepicker._disabledTime?.value?.rangeArrHour,...this.getDestructuringObj()}):e.clean()},300):setTimeout(()=>{e.updateDisable({...this.getDestructuringObj(!0)})},300)}r(this.timepicker._element,"selecthourmode","timepicker:select-hour",{hour:this.timepicker.hour.value,minutes:this.timepicker.minutes.value,type:this.timepicker.activeTypeMode?.dataset.type,degreesHours:this.timepicker._degreesHours,degreesMinutes:this.timepicker._degreesMinutes},this.timepicker._options.onSelectHour),null!==this.timepicker.clockFace&&this.timepicker.circle.classList.remove("small-circle")})}),this.timepicker.hour?.addEventListener("blur",e=>this.handleClasses24h(e,this.timepicker.hour)),this.timepicker.hour?.addEventListener("focus",e=>this.handleClasses24h(e,this.timepicker.hour))};handleMinutesEvents=()=>{this.timepicker._inputEvents.forEach(e=>{this.timepicker.minutes.addEventListener(e,e=>{const i=e.target;if(null!==this.timepicker.clockFace&&(this.timepicker.animationManager.handleAnimationSwitchTipsMode(),this.timepicker.clockManager.setMinutesToClock(i.value)),"24h"===this.timepicker._options.clockType&&(this.timepicker.clockManager.removeCircleClockClasses24h(),this.timepicker._options.mobile||this.timepicker.tipsWrapperFor24h?.classList.add("timepicker-ui-tips-wrapper-24h-disabled")),this.timepicker.hour.classList.remove(k),this.timepicker.minutes.classList.add(k),"12h"===this.timepicker._options.clockType&&this.timepicker._options.disabledTime?.interval){const e=new g({clockFace:this.timepicker.clockFace,tipsWrapper:this.timepicker.tipsWrapper,array:s(this.timepicker.hour,k)?T:y});this.timepicker._disabledTime?.value.startType===this.timepicker._disabledTime?.value.endType?setTimeout(()=>{this.timepicker._disabledTime?.value.startType===this.timepicker.activeTypeMode?.textContent?e.updateDisable({hoursToUpdate:this.timepicker._disabledTime?.value?.rangeArrHour,...this.getDestructuringObj()}):e.clean()},300):setTimeout(()=>{e.updateDisable({...this.getDestructuringObj(!0)})},300)}r(this.timepicker._element,"selectminutemode","timepicker:select-minute",{hour:this.timepicker.hour.value,minutes:this.timepicker.minutes.value,type:this.timepicker.activeTypeMode?.dataset.type,degreesHours:this.timepicker._degreesHours,degreesMinutes:this.timepicker._degreesMinutes},this.timepicker._options.onSelectMinute)})}),this.timepicker.minutes?.addEventListener("blur",e=>this.handleClasses24h(e,this.timepicker.minutes)),this.timepicker.minutes?.addEventListener("focus",e=>this.handleClasses24h(e,this.timepicker.minutes))};handleEventToMoveHand=e=>{const{target:i,type:c,touches:o}=e,a=i,{incrementMinutes:l,incrementHours:p,switchToMinutesAfterSelectHour:u}=this.timepicker._options;if(!t(e,this.timepicker.clockFace))return;const h=t(e,this.timepicker.clockFace),d=this.timepicker.clockFace.offsetWidth/2,v=h&&Math.atan2(h.y-d,h.x-d);if("mouseup"===c||"touchend"===c)return this.timepicker._isTouchMouseMove=!1,void(u&&(s(a,"timepicker-ui-value-tips")||s(a,"timepicker-ui-value-tips-24h")||s(a,"timepicker-ui-tips-wrapper"))&&this.timepicker.minutes.click());if("mousedown"!==c&&"mousemove"!==c&&"touchmove"!==c&&"touchstart"!==c||"mousedown"!==c&&"touchstart"!==c&&"touchmove"!==c||((s(a,"timepicker-ui-clock-face")||s(a,"timepicker-ui-circle-hand")||s(a,"timepicker-ui-hour-time-12")||s(a,"timepicker-ui-minutes-time")||s(a,"timepicker-ui-clock-hand")||s(a,"timepicker-ui-value-tips")||s(a,"timepicker-ui-value-tips-24h")||s(a,"timepicker-ui-tips-wrapper")||s(a,"timepicker-ui-tips-wrapper-24h"))&&!s(a,"timepicker-ui-tips-disabled")?(e.preventDefault(),this.timepicker._isTouchMouseMove=!0):this.timepicker._isTouchMouseMove=!1),!this.timepicker._isTouchMouseMove)return;if(null!==this.timepicker.minutesTips){this.timepicker.minutes.classList.add(k);let e,i=v&&n(Math.trunc(180*v/Math.PI)+90,l,6);if(void 0===i)return;if(i<0?(e=Math.round(360+i/6)%60,i=360+6*Math.round(i/6)):(e=Math.round(i/6)%60,i=6*Math.round(i/6)),this.timepicker._disabledTime?.value.isInterval)if(this.timepicker._disabledTime?.value.endType===this.timepicker._disabledTime?.value.startType){if(this.timepicker._disabledTime?.value?.endMinutes?.includes(e<=9?`0${e}`:`${e}`)&&this.timepicker.hour.value===this.timepicker._disabledTime?.value?.removedEndHour&&this.timepicker._disabledTime?.value.endType===this.timepicker.activeTypeMode?.textContent)return;if(this.timepicker._disabledTime?.value?.startMinutes?.includes(e<=9?`0${e}`:`${e}`)&&this.timepicker.hour.value===this.timepicker._disabledTime?.value?.removedStartedHour&&this.timepicker._disabledTime?.value.startType===this.timepicker.activeTypeMode?.textContent)return}else{if(this.timepicker.activeTypeMode?.textContent===this.timepicker._disabledTime?.value.endType&&(this.timepicker._disabledTime?.value?.endMinutes?.includes(e<=9?`0${e}`:`${e}`)&&this.timepicker._disabledTime?.value.removedPmHour===this.timepicker.hour.value||this.timepicker._disabledTime?.value.pmHours.map(Number).includes(Number(this.timepicker.hour.value))))return;if(this.timepicker.activeTypeMode?.textContent===this.timepicker._disabledTime?.value.startType&&(this.timepicker._disabledTime?.value?.startMinutes?.includes(e<=9?`0${e}`:`${e}`)&&this.timepicker._disabledTime?.value.removedAmHour===this.timepicker.hour.value||this.timepicker._disabledTime?.value.amHours.map(Number).includes(Number(this.timepicker.hour.value))))return}else if(this.timepicker._disabledTime?.value?.minutes?.includes(e<=9?`0${e}`:`${e}`))return;this.timepicker.minutes.value=e>=10?`${e}`:`0${e}`,this.timepicker.clockHand.style.transform=`rotateZ(${i}deg)`,this.timepicker._degreesMinutes=i,this.timepicker.clockManager.toggleClassActiveToValueTips(this.timepicker.minutes.value),this.timepicker.clockManager.removeBgColorToCirleWithMinutesTips(),this.timepicker.clockManager.setBgColorToCircleWithMinutesTips(),r(this.timepicker._element,"update","timepicker:update",{...m(this.timepicker.input,this.timepicker._options.clockType),degreesHours:this.timepicker._degreesHours,degreesMinutes:this.timepicker._degreesMinutes,eventType:c,type:this.timepicker.activeTypeMode?.dataset.type},this.timepicker._options.onUpdate)}const b=o?o[0]:void 0,T=o&&b?document.elementFromPoint(b.clientX,b.clientY):null;if(null!==this.timepicker.hourTips){if(this.timepicker.hour?.classList.add(k),!s(T||a,"timepicker-ui-value-tips-24h")&&!s(T||a,"timepicker-ui-tips-disabled")&&(s(T||a,"timepicker-ui-value-tips")||s(T||a,"timepicker-ui-tips-wrapper"))){let e,i=v&&n(Math.trunc(180*v/Math.PI)+90,p,30);if(this.timepicker._degreesHours=i,void 0===i)return;i<0?(e=Math.round(360+i/30)%12,i=360+i):(e=Math.round(i/30)%12,(0===e||e>12)&&(e=12));const t=this.timepicker._disabledTime?.value.isInterval?"rangeArrHour":"hours";if(this.timepicker._disabledTime?.value.endType===this.timepicker._disabledTime?.value?.startType){if("string"==typeof this.timepicker._disabledTime?.value?.endType){if(this.timepicker._disabledTime?.value?.endType===this.timepicker.activeTypeMode?.textContent&&this.timepicker._disabledTime?.value?.startType===this.timepicker.activeTypeMode?.textContent&&this.timepicker._disabledTime?.value[t]?.includes(e.toString()))return}else if(this.timepicker._disabledTime?.value[t]?.includes(e.toString()))return}else{if(this.timepicker._disabledTime?.value.startType===this.timepicker.activeTypeMode?.textContent&&this.timepicker._disabledTime?.value.amHours.includes(e.toString()))return;if(this.timepicker._disabledTime?.value.endType===this.timepicker.activeTypeMode?.textContent&&this.timepicker._disabledTime?.value.pmHours.includes(e.toString()))return}this.timepicker.clockHand.style.transform=`rotateZ(${i}deg)`,this.timepicker.hour.value=e>9?`${e}`:`0${e}`,this.timepicker.clockManager.removeCircleClockClasses24h(),this.timepicker.clockManager.toggleClassActiveToValueTips(e)}if((s(T||a,"timepicker-ui-value-tips-24h")||s(T||a,"timepicker-ui-tips-wrapper-24h"))&&!s(T||a,"timepicker-ui-tips-disabled")){let e,i=v&&n(Math.trunc(180*v/Math.PI)+90,p,30);if(this.timepicker._degreesHours=i,void 0===i)return;i<0?(e=Math.round(360+i/30)%24,i=360+i):(e=Math.round(i/30)+12,12===e&&(e="00"));const t=this.timepicker._disabledTime?.value.isInterval?"rangeArrHour":"hours";if(this.timepicker._disabledTime?.value[t]?.includes(e.toString()))return;this.timepicker.clockManager.setCircleClockClasses24h(),this.timepicker.clockHand.style.transform=`rotateZ(${i}deg)`,this.timepicker.hour.value=`${e}`,this.timepicker.clockManager.toggleClassActiveToValueTips(e)}r(this.timepicker._element,"update","timepicker:update",{...m(this.timepicker.input,this.timepicker._options.clockType),degreesHours:this.timepicker._degreesHours,degreesMinutes:this.timepicker._degreesMinutes,eventType:c,type:this.timepicker.activeTypeMode?.dataset.type},this.timepicker._options.onUpdate)}};handleMoveHand=()=>{this.timepicker._options.mobile||this.timepicker._isMobileView||d.split(" ").forEach(e=>{"touchstart"===e||"touchmove"===e||"touchend"===e?document.addEventListener(e,this.timepicker._mutliEventsMoveHandler,{passive:!1}):document.addEventListener(e,this.timepicker._mutliEventsMoveHandler,!1)})};handleClickOnHourMobile=()=>{document.addEventListener("mousedown",this.timepicker._eventsClickMobileHandler),document.addEventListener("touchstart",this.timepicker._eventsClickMobileHandler)};handlerClickHourMinutes=async e=>{if(!this.timepicker.modalElement)return;const{clockType:i,editable:t}=this.timepicker._options,r=e.target,n=p(this.timepicker.hour.value,"hour",i),c=p(this.timepicker.minutes.value,"minutes",i);t&&(s(r,"timepicker-ui-hour")||s(r,"timepicker-ui-minutes")?!1!==n&&!1!==c||(c||this.timepicker.minutes.classList.add("invalid-value"),n||this.timepicker.hour?.classList.add("invalid-value")):!0===n&&!0===c&&(c&&this.timepicker.minutes.classList.remove("invalid-value"),n&&this.timepicker.hour?.classList.remove("invalid-value")))};handleIconChangeView=async()=>{this.timepicker._options.enableSwitchIcon&&(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)?this.timepicker.keyboardClockIcon.addEventListener("touchstart",this.timepicker.configManager.handlerViewChange()):this.timepicker.keyboardClockIcon.addEventListener("click",this.timepicker.configManager.handlerViewChange()))};handleKeyPress=e=>{if("Escape"===e.key&&this.timepicker.modalElement){const e=m(this.timepicker.input,this.timepicker._options.clockType);r(this.timepicker._element,"cancel","timepicker:cancel",{...e,hourNotAccepted:this.timepicker.hour.value,minutesNotAccepted:this.timepicker.minutes.value,type:this.timepicker.activeTypeMode?.dataset.type,degreesHours:this.timepicker._degreesHours,degreesMinutes:this.timepicker._degreesMinutes},this.timepicker._options.onCancel),this.timepicker.close()()}};handleEscClick=()=>{document.addEventListener("keydown",this.handleKeyPress)};focusTrapHandler=()=>{setTimeout(()=>{const e=this.timepicker.wrapper?.querySelectorAll('div[tabindex="0"]:not([disabled])'),i=this.timepicker.wrapper?.querySelectorAll('input[tabindex="0"]:not([disabled])');if(!e||e.length<=0||i.length<=0)return;const t=[...i,...e],r=t[0],n=t[t.length-1];this.timepicker.wrapper.focus(),this.timepicker.wrapper.addEventListener("keydown",({key:e,shiftKey:i,target:t})=>{const c=t;"Tab"===e&&(i?document.activeElement===r&&n.focus():document.activeElement===n&&r.focus()),"Enter"===e&&(s(c,"timepicker-ui-minutes")&&this.timepicker.minutes.click(),s(c,"timepicker-ui-hour")&&this.timepicker.hour.click(),s(c,"timepicker-ui-am")&&this.timepicker.AM.click(),s(c,"timepicker-ui-pm")&&this.timepicker.PM.click(),s(c,"timepicker-ui-ok-btn")&&this.timepicker.okButton.click(),s(c,"timepicker-ui-cancel-btn")&&this.timepicker.cancelButton.click(),s(c,"timepicker-ui-keyboard-icon-wrapper")&&this.timepicker.keyboardClockIcon.click())})},100)};handleInlineAutoUpdate=()=>{if(!this.timepicker._options.inline?.enabled||!1===this.timepicker._options.inline.autoUpdate)return;const e=()=>{const e=this.timepicker.hour?.value,i=this.timepicker.minutes?.value,t=this.timepicker.activeTypeMode?.textContent;if(e&&i){let s="";if("24h"===this.timepicker._options.clockType){s=`${e.padStart(2,"0")}:${i.padStart(2,"0")}`}else{s=`${e}:${i.padStart(2,"0")} ${t||"AM"}`}if(this.timepicker.input){this.timepicker.input.value=s;const n=new Event("change",{bubbles:!0});this.timepicker.input.dispatchEvent(n),r(this.timepicker._element,"accept","timepicker:confirm",{hour:e,minutes:i,type:t,degreesHours:this.timepicker._degreesHours,degreesMinutes:this.timepicker._degreesMinutes},this.timepicker._options.onConfirm)}}};["input","change"].forEach(i=>{this.timepicker.hour?.addEventListener(i,()=>{setTimeout(e,50)}),this.timepicker.minutes?.addEventListener(i,()=>{setTimeout(e,50)})}),"24h"!==this.timepicker._options.clockType&&this.timepicker._clickTouchEvents.forEach(i=>{this.timepicker.AM?.addEventListener(i,()=>{setTimeout(e,50)}),this.timepicker.PM?.addEventListener(i,()=>{setTimeout(e,50)})}),this.timepicker.clockFace?.addEventListener("click",()=>{setTimeout(e,100)})}}class f{timepicker;constructor(e){this.timepicker=e}setModalTemplate=()=>{if(!this.timepicker._options)return;if(this.timepicker._options.inline?.enabled){const e=document.getElementById(this.timepicker._options.inline.containerId);if(e){e.innerHTML="",e.insertAdjacentHTML("beforeend",this.timepicker.modalTemplate);const i=e.querySelector(".timepicker-ui-modal");if(i&&(i.classList.add("timepicker-ui--inline"),!1===this.timepicker._options.inline.showButtons||void 0===this.timepicker._options.inline.showButtons)){const e=i.querySelector(".timepicker-ui-wrapper-btn");e&&(e.style.display="none");const t=i.querySelector(".timepicker-ui-wrapper-btn.mobile");t&&(t.style.display="none")}}return}const{appendModalSelector:e}=this.timepicker._options;if(""!==e&&e){const i=document?.querySelector(e);i?.insertAdjacentHTML("beforeend",this.timepicker.modalTemplate)}else document.body.insertAdjacentHTML("afterend",this.timepicker.modalTemplate)};setScrollbarOrNot=()=>{this.timepicker._options.inline?.enabled||(this.timepicker._options.enableScrollbar?setTimeout(()=>{document.body.style.overflowY="",document.body.style.paddingRight=""},400):(document.body.style.paddingRight=`${(()=>{const e=document.createElement("div");e.className="timepicker-ui-measure",document.body.appendChild(e);const i=e.getBoundingClientRect().width-e.clientWidth;return document.body.removeChild(e),i})()}px`,document.body.style.overflowY="hidden"))};removeBackdrop=()=>{this.timepicker._options.inline?.enabled||this.timepicker._options.backdrop||(this.timepicker.modalElement?.classList.add("removed"),this.timepicker.openElement.forEach(e=>e?.classList.add("disabled")))};setNormalizeClass=()=>{const e=this.timepicker.modalElement?.querySelectorAll("div");this.timepicker.modalElement?.classList.add("timepicker-ui-normalize"),e?.forEach(e=>e.classList.add("timepicker-ui-normalize"))};setShowClassToBackdrop=()=>{this.timepicker._options.inline?.enabled?this.timepicker.modalElement?.classList.add("show"):this.timepicker._options.backdrop&&setTimeout(()=>{this.timepicker.modalElement.classList.add("show")},300)};setFlexEndToFooterIfNoKeyboardIcon=()=>{!this.timepicker._options.enableSwitchIcon&&this.timepicker.footer&&(this.timepicker.footer.style.justifyContent="flex-end")}}class C{timepicker;constructor(e){this.timepicker=e}setAnimationToOpen(){this.timepicker.modalElement?.classList.add("opacity"),this.timepicker._options.animation?setTimeout(()=>{this.timepicker.modalElement?.classList.add("show")},150):this.timepicker.modalElement?.classList.add("show")}removeAnimationToClose(){this.timepicker.modalElement&&(this.timepicker._options.animation?setTimeout(()=>{this.timepicker.modalElement?.classList.remove("show")},150):this.timepicker.modalElement?.classList.remove("show"))}handleAnimationClock(){this.timepicker._options.animation&&setTimeout(()=>{this.timepicker.clockFace?.classList.add("timepicker-ui-clock-animation"),setTimeout(()=>{this.timepicker.clockFace?.classList.remove("timepicker-ui-clock-animation")},600)},150)}handleAnimationSwitchTipsMode(){this.timepicker.clockHand.classList.add("timepicker-ui-tips-animation"),setTimeout(()=>{this.timepicker.clockHand?.classList.remove("timepicker-ui-tips-animation")},401)}}const E="#f7363e",w="#6200ee",L={"crane-straight":["crane-straight"],"crane-radius":["crane-straight","radius"],m3:["m3"],dark:["dark"],glassmorphic:["glassmorphic"],pastel:["pastel"],ai:["ai"],cyberpunk:["cyberpunk"]};class H{timepicker;constructor(e){this.timepicker=e}removeCircleClockClasses24h(){this.timepicker.circle?.classList.remove("timepicker-ui-circle-hand-24h"),this.timepicker.clockHand?.classList.remove("timepicker-ui-clock-hand-24h")}setCircleClockClasses24h(){this.timepicker.circle&&this.timepicker.circle?.classList.add("timepicker-ui-circle-hand-24h"),this.timepicker.clockHand&&this.timepicker.clockHand?.classList.add("timepicker-ui-clock-hand-24h")}setOnStartCSSClassesIfClockType24h(){if("24h"===this.timepicker._options.clockType){let{hour:e}=this.timepicker.configManager.getInputValue(this.timepicker.input,this.timepicker._options.clockType,this.timepicker._options.currentTime);this.timepicker.input.value.length>0&&(e=this.timepicker.input.value.split(":")[0]),(Number(e)>12||0===Number(e))&&this.setCircleClockClasses24h()}}setBgColorToCirleWithHourTips=()=>{if(!this.timepicker._options)return;const{mobile:e,theme:i}=this.timepicker._options;e||null===this.timepicker.circle||(this.timepicker.circle.style.backgroundColor="crane-straight"===i||"crane-radius"===i?E:w)};setBgColorToCircleWithMinutesTips=()=>{const{theme:e}=this.timepicker._options;this.timepicker.minutes.value&&y.includes(this.timepicker.minutes.value)&&(this.timepicker.circle.style.backgroundColor="crane-straight"===e||"crane-radius"===e?E:w,this.timepicker.circle.classList.remove("small-circle"))};removeBgColorToCirleWithMinutesTips=()=>{this.timepicker.minutes.value&&y.includes(this.timepicker.minutes.value)||(this.timepicker.circle.style.backgroundColor="",this.timepicker.circle.classList.add("small-circle"))};setClassActiveToHourOnOpen=()=>{this.timepicker._options.mobile||this.timepicker._isMobileView||this.timepicker.hour?.classList.add(k)};setMinutesToClock=e=>{null!==this.timepicker.clockFace&&this.setTransformToCircleWithSwitchesMinutes(e),this.removeBgColorToCirleWithMinutesTips();const i=this.timepicker._disabledTime?.value?.minutes?this.timepicker._disabledTime?.value?.minutes:this.timepicker._disabledTime?.value,t=new g({array:y,classToAdd:"timepicker-ui-minutes-time",clockFace:this.timepicker.clockFace,tipsWrapper:this.timepicker.tipsWrapper,theme:this.timepicker._options.theme,disabledTime:i,hour:this.timepicker.hour.value,clockType:this.timepicker._options.clockType});t.create(),"12h"===this.timepicker._options.clockType&&t.updateDisable(),this.toggleClassActiveToValueTips(e),"24h"===this.timepicker._options.clockType&&(this.timepicker.tipsWrapperFor24h.innerHTML="")};setHoursToClock=e=>{if(null!==this.timepicker.clockFace){this.setTransformToCircleWithSwitchesHour(e),this.setBgColorToCirleWithHourTips();const i=this.timepicker._disabledTime?.value?.isInterval?this.timepicker._disabledTime?.value.rangeArrHour:this.timepicker._disabledTime?.value?.hours,t=new g({array:T,classToAdd:"timepicker-ui-hour-time-12",clockFace:this.timepicker.clockFace,tipsWrapper:this.timepicker.tipsWrapper,theme:this.timepicker._options.theme,disabledTime:i,clockType:"12h",hour:this.timepicker.hour.value});t.create(),"24h"===this.timepicker._options.clockType?new g({array:b,classToAdd:"timepicker-ui-hour-time-24",clockFace:this.timepicker.tipsWrapperFor24h,tipsWrapper:this.timepicker.tipsWrapperFor24h,theme:this.timepicker._options.theme,clockType:"24h",disabledTime:i,hour:this.timepicker.hour.value}).create():t.updateDisable(),this.toggleClassActiveToValueTips(e)}};setTransformToCircleWithSwitchesHour=e=>{if(!this.timepicker.clockHand)return;const i=Number(e);let t=i>12?30*i-360:30*i;360===t&&(t=0),t>360||(this.timepicker.clockHand.style.transform=`rotateZ(${t}deg)`)};setTransformToCircleWithSwitchesMinutes=e=>{if(!this.timepicker.clockHand)return;const i=6*Number(e);i>360||(this.timepicker.clockHand.style.transform=`rotateZ(${i}deg)`)};toggleClassActiveToValueTips=e=>{const i=this.timepicker.allValueTips.find(i=>Number(i.innerText)===Number(e));this.timepicker.allValueTips.map(e=>e.classList.remove(k)),void 0!==i&&i.classList.add(k)}}class I{timepicker;constructor(e){this.timepicker=e}setErrorHandler(){const{error:e,currentHour:i,currentMin:t,currentType:s,currentLength:n}=m(this.timepicker.input,this.timepicker._options.clockType);if(e){const c=document.createElement("div");throw this.timepicker.input?.classList.add("timepicker-ui-invalid-format"),c.classList.add("timepicker-ui-invalid-text"),c.innerHTML="<b>Invalid Time Format</b>",this.timepicker.input?.parentElement&&null===this.timepicker.input?.parentElement.querySelector(".timepicker-ui-invalid-text")&&this.timepicker.input?.after(c),r(this.timepicker._element,"geterror","timepicker:error",{error:e,currentHour:i,currentMin:t,currentType:s,currentLength:n},this.timepicker._options.onError),new Error(`Invalid Time Format: ${e}`)}}removeErrorHandler(){this.timepicker.input?.classList.remove("timepicker-ui-invalid-format");const e=this.timepicker._element?.querySelector(".timepicker-ui-invalid-text");e&&e.remove()}checkDisabledValuesOnStart(){if(!this.timepicker._options.disabledTime||this.timepicker._options.disabledTime.interval)return;const{disabledTime:{hours:e,minutes:i},clockType:t}=this.timepicker._options,s=!e||_(e,"hour",t),r=!i||_(i,"minutes",t);if(!s||!r)throw new Error("You set wrong hours or minutes in disabled option")}}class S{timepicker;constructor(e){this.timepicker=e}setTheme=()=>{const e=[...this.timepicker.modalElement?.querySelectorAll("input")??[],...this.timepicker.modalElement?.querySelectorAll("div")??[]],{theme:i}=this.timepicker._options??{};i&&L[i]&&e.forEach(e=>e.classList.add(...L[i]))};setInputClassToInputElement=()=>{s(this.timepicker.input,"timepicker-ui-input")||this.timepicker.input?.classList.add("timepicker-ui-input")};setDataOpenToInputIfDosentExistInWrapper=()=>{null===this.timepicker.openElementData&&this.timepicker.input?.setAttribute("data-open","timepicker-ui-input")};setClassTopOpenElement=()=>{this.timepicker.openElement.forEach(e=>e?.classList.add("timepicker-ui-open-element"))};setTimepickerClassToElement=()=>{this.timepicker._element?.classList.add(h),this.timepicker._options.cssClass&&this.timepicker._options.cssClass!==h&&this.timepicker._element?.classList.add(this.timepicker._options.cssClass)}}class A{timepicker;constructor(e){this.timepicker=e}preventClockTypeByCurrentTime=()=>{if("boolean"!=typeof this.timepicker._options?.currentTime&&this.timepicker._options?.currentTime?.preventClockType||"boolean"==typeof this.timepicker._options?.currentTime&&this.timepicker._options?.currentTime){const{currentTime:e,clockType:i}=this.timepicker._options,{type:t}=m(this.timepicker.input,i,e,!0);this.timepicker._options.clockType=t?"12h":"24h"}};updateInputValueWithCurrentTimeOnStart=()=>{if("boolean"!=typeof this.timepicker._options?.currentTime&&this.timepicker._options?.currentTime?.updateInput||"boolean"==typeof this.timepicker._options?.currentTime&&this.timepicker._options?.currentTime){const{hour:e,minutes:i,type:t}=m(this.timepicker.input,this.timepicker._options.clockType,this.timepicker._options.currentTime);this.timepicker.input.value=t?`${e}:${i} ${t}`:`${e}:${i}`}};checkMobileOption(){this.timepicker._isMobileView=!!this.timepicker._options.mobile,this.timepicker._options.mobile&&(this.timepicker._options.editable=!0)}getDisableTime(){this.timepicker._disabledTime=(e=>{if(!e)return;const{disabledTime:i,clockType:t}=e;if(!i||Object.keys(i).length<=0||"Object"!==i.constructor.name)return;const{hours:s,interval:r,minutes:n}=i;if(r){delete i.hours,delete i.minutes;const[e,s]=r.toString().split("-"),{hour:n,minutes:a,type:l}=m({value:e.trimEnd()},t),{hour:p,minutes:u,type:h}=m({value:s.trimEnd().trimStart()},t);let d=c(n,p).map(e=>"00"===e||0===Number(e)?`0${Number(e)}`:`${Number(e)}`);const k=[],v=Number(a),b=Number(u);if(h===l)return v>0&&b<=0?(k.push(d[0],d[d.length-1]),d=d.slice(1,-1)):b<59&&b>0&&v<=0?(k.push(void 0,d[d.length-1]),d=d.slice(0,-1)):b>0&&v>0?(k.push(d[0],d[d.length-1]),d=d.slice(1,-1)):0===b&&0===v&&(k.push(void 0,d[d.length-1]),d.pop()),{value:{removedStartedHour:Number(k[0])<=9?`0${k[0]}`:k[0],removedEndHour:Number(k[1])<=9?`0${k[1]}`:k[1],rangeArrHour:d,isInterval:!0,startMinutes:c(a,59).map(e=>Number(e)<=9?`0${e}`:`${e}`),endMinutes:o(0,u).map(e=>Number(e)<=9?`0${e}`:`${e}`),endType:h,startType:l}};{const e=c(n,12).map(String),i=o(1,p).map(String),t=[],s=[];return v>0&&b<=0?(t.push(i[i.length-1]),s.push(e[0]),i.splice(-1,1),e.splice(0,1)):b<59&&b>0&&v<=0?(s.push(e[0]),t.push(i[i.length-1]),i.splice(-1,1)):b>0&&v>0?(t.push(i[i.length-1]),s.push(e[0]),i.splice(-1,1),e.splice(0,1)):0===b&&0===v&&(t.push(i[i.length-1]),s.push(e[0]),i.pop()),{value:{isInterval:!0,endType:h,startType:l,pmHours:i,amHours:e,startMinutes:0===Number(a)?[]:c(a,59).map(e=>Number(e)<=9?`0${e}`:`${e}`),endMinutes:o(0,u).map(e=>Number(e)<=9?`0${e}`:`${e}`),removedAmHour:Number(s[0])<=9?`0${s[0]}`:s[0],removedPmHour:Number(t[0])<=9?`0${t[0]}`:t[0]}}}}return s?.forEach(e=>{if("12h"===t&&Number(e)>12)throw new Error("The disabled hours value has to be less than 13");if("24h"===t&&Number(e)>23)throw new Error("The disabled hours value has to be less than 24")}),n?.forEach(e=>{if(Number(e)>59)throw new Error("The disabled minutes value has to be less than 60")}),{value:{hours:s?.map(e=>"00"===e||0===Number(e)?`0${Number(e)}`:`${Number(e)}`),minutes:n?.map(e=>Number(e)<=9?`0${e}`:`${e}`)}}})(this.timepicker._options)}getInputValueOnOpenAndSet=()=>{const e=m(this.timepicker.input,this.timepicker._options.clockType,this.timepicker._options.currentTime);if(void 0===e)return this.timepicker.hour.value="12",this.timepicker.minutes.value="00",r(this.timepicker._element,"show","timepicker:open",{hour:this.timepicker.hour.value,minutes:this.timepicker.minutes.value,type:this.timepicker.activeTypeMode?.dataset.type,degreesHours:this.timepicker._degreesHours,degreesMinutes:this.timepicker._degreesMinutes},this.timepicker._options.onOpen),void("24h"!==this.timepicker._options.clockType&&this.timepicker.AM.classList.add(k));let[i,t,s]=this.timepicker.input.value.split(":").join(" ").split(" ");0===this.timepicker.input.value.length&&(i=e.hour,t=e.minutes,s=e.type),this.timepicker.hour.value=i,this.timepicker.minutes.value=t;const n=this.timepicker.modalElement?.querySelector(`[data-type='${s}']`);"24h"!==this.timepicker._options.clockType&&n&&n.classList.add(k),r(this.timepicker._element,"show","timepicker:open",{...e,type:this.timepicker.activeTypeMode?.dataset.type,degreesHours:this.timepicker._degreesHours,degreesMinutes:this.timepicker._degreesMinutes},this.timepicker._options.onOpen)};handlerViewChange=()=>v(()=>{const{clockType:e}=this.timepicker._options;if(this.timepicker.modalElement?.classList.contains("mobile")){const i=p(this.timepicker.hour.value,"hour",e),t=p(this.timepicker.minutes.value,"minutes",e);if(!1===i||!1===t)return t||this.timepicker.minutes.classList.add("invalid-value"),void(i||this.timepicker.hour?.classList.add("invalid-value"));!0===i&&!0===t&&(t&&this.timepicker.minutes.classList.remove("invalid-value"),i&&this.timepicker.hour?.classList.remove("invalid-value")),this.timepicker.close()(),this.timepicker._isMobileView=!1,this.timepicker._options.mobile=!1;const s=this.timepicker.hour.value,r=this.timepicker.minutes.value,n=this.timepicker.activeTypeMode?.dataset.type;setTimeout(()=>{this.timepicker.destroy(),this.timepicker.update({options:{mobile:!1}}),setTimeout(()=>{if(this.timepicker.open(),this.timepicker.hour.value=s,this.timepicker.minutes.value=r,"12h"===this.timepicker._options.clockType){const e="PM"===n?"PM":"AM",i="PM"===n?"AM":"PM";this.timepicker[e].classList.add(k),this.timepicker[i].classList.remove(k)}this.timepicker.clockManager.setTransformToCircleWithSwitchesHour(this.timepicker.hour.value),this.timepicker.clockManager.toggleClassActiveToValueTips(this.timepicker.hour.value),Number(this.timepicker.hour.value)>12||0===Number(this.timepicker.hour.value)?this.timepicker.clockManager.setCircleClockClasses24h():this.timepicker.clockManager.removeCircleClockClasses24h()},300)},300)}else{this.timepicker.close()(),this.timepicker._isMobileView=!0,this.timepicker._options.mobile=!0;const e=this.timepicker.hour.value,i=this.timepicker.minutes.value,t=this.timepicker.activeTypeMode?.dataset.type;setTimeout(()=>{this.timepicker.destroy(),this.timepicker.update({options:{mobile:!0}}),setTimeout(()=>{if(this.timepicker.open(),this.timepicker.hour.value=e,this.timepicker.minutes.value=i,"12h"===this.timepicker._options.clockType){const e="PM"===t?"PM":"AM",i="PM"===t?"AM":"PM";this.timepicker[e].classList.add(k),this.timepicker[i].classList.remove(k)}},300)},300)}},this.timepicker._options.delayHandler||300);getInputValue=m}const $=new Map;e.TimepickerUI=class{_degreesHours=null;_degreesMinutes=null;_options;_eventsClickMobile=()=>Promise.resolve();_eventsClickMobileHandler=()=>{};_mutliEventsMove=()=>{};_mutliEventsMoveHandler;_clickTouchEvents;_element;_instanceId;_isMobileView;_isTouchMouseMove;_disabledTime;_cloned;_inputEvents;_isModalRemove;_isInitialized=!1;_customId;_eventHandlersRegistered=!1;_isDestroyed=!1;eventManager;modalManager;animationManager;clockManager;validationManager;themeManager;configManager;constructor(e,t){if("undefined"==typeof window)throw new Error("TimepickerUI: Cannot initialize in non-browser environment (SSR/Node.js)");const s=t?.id;if(this._customId=s,this._instanceId=s||`timepicker-ui-${"undefined"!=typeof window&&window.crypto&&"function"==typeof window.crypto.randomUUID?window.crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const i=16*Math.random()|0;return("x"===e?i:3&i|8).toString(16)})}`,s&&$.has(s))throw new Error(`TimepickerUI: Instance with ID "${s}" already exists`);let r=null;if("string"==typeof e){if(r=document.querySelector(e),!r)throw new Error(`TimepickerUI: Element with selector "${e}" not found`)}else{if(!(e instanceof HTMLElement))throw new Error("TimepickerUI: First parameter must be a string selector or HTMLElement");r=e}let n=null;if(n="INPUT"===r.tagName?r:r.querySelector("input"),!n){throw new Error(`TimepickerUI: No input element found for ${"string"==typeof e?`selector "${e}"`:"provided element"}`)}if("INPUT"===r.tagName){const e=document.createElement("div");e.className="timepicker-ui",r.parentNode?.insertBefore(e,r),e.appendChild(r),this._element=e}else this._element=r,this._element.classList.contains("timepicker-ui")||this._element.classList.add("timepicker-ui");this._cloned=null;const c=(e=>{if(!e)return;const i=JSON.parse(JSON.stringify(e)),t=Object.keys(i);return Object.values(i).reduce((e,i,s)=>(Number(i)?e[t[s]]=Number(i):e[t[s]]="true"===i||"false"===i?JSON.parse(i):i,e),{})})(this._element?.dataset);if(this._options={...i({...u,...t,...c},u)},this._options.inline?.enabled&&void 0===t?.focusTrap&&(this._options.focusTrap=!1),this._isTouchMouseMove=!1,this._degreesHours=30*Number(m(this._element?.querySelector("input"),this._options.clockType).hour),this._degreesMinutes=6*Number(m(this._element?.querySelector("input"),this._options.clockType).minutes),this._isMobileView=!1,this._mutliEventsMove=e=>this.eventManager.handleEventToMoveHand(e),this._mutliEventsMoveHandler=this._mutliEventsMove.bind(this),this._eventsClickMobile=e=>this.eventManager.handlerClickHourMinutes(e),this._eventsClickMobileHandler=this._eventsClickMobile.bind(this),this.eventManager=new M(this),this.modalManager=new f(this),this.animationManager=new C(this),this.clockManager=new H(this),this.validationManager=new I(this),this.themeManager=new S(this),this.configManager=new A(this),this.configManager.checkMobileOption(),this._clickTouchEvents=["click","mousedown","touchstart"],this._inputEvents=["change",...this._clickTouchEvents],this._disabledTime=null,this.configManager.preventClockTypeByCurrentTime(),this._isModalRemove=!0,this._isInitialized=!1,this._options.inline?.enabled){if(!this._options.inline.containerId)throw console.error("TimepickerUI: containerId is required when inline mode is enabled"),new Error("TimepickerUI: containerId is required when inline mode is enabled");if(!document.getElementById(this._options.inline.containerId))throw console.error(`TimepickerUI: Container element with ID "${this._options.inline.containerId}" not found`),new Error(`TimepickerUI: Container element with ID "${this._options.inline.containerId}" not found`)}$.set(this._instanceId,this)}static getById(e){return $.get(e)}static getAllInstances(){return Array.from($.values())}static isAvailable(e){return"undefined"!=typeof window&&("string"==typeof e?null!==document.querySelector(e):e instanceof HTMLElement&&document.contains(e))}static destroyAll(){Array.from($.values()).forEach(e=>e.destroy()),$.clear()}get modalTemplate(){return this._options.mobile&&this._isMobileView?((e,i)=>{const{mobileTimeLabel:t,amLabel:s,pmLabel:r,cancelLabel:n,okLabel:c,iconTemplateMobile:o,minuteMobileLabel:a,hourMobileLabel:l,enableSwitchIcon:m,animation:p,clockType:u,theme:h}=e;return`\n <div class="timepicker-ui-modal normalize mobile ${h}" role="dialog" data-owner-id="${i}" style='transition:${p?"opacity 0.15s linear":"none"}'>\n <div class="timepicker-ui-wrapper mobile" tabindex="0">\n <div class="timepicker-ui-header mobile">\n <div class="timepicker-ui-select-time mobile">${t}</div>\n <div class="timepicker-ui-wrapper-time mobile">\n <input class="timepicker-ui-hour mobile" tabindex="0" type="number" min="0" max="${"12h"===u?"12":"23"}" />\n <div class="timepicker-ui-hour-text mobile">${l}</div>\n <div class="timepicker-ui-dots mobile">\n <span></span>\n <span></span>\n </div> \n <div class="timepicker-ui-minute-text mobile">${a}</div>\n <input class="timepicker-ui-minutes mobile" tabindex="0" type="number" min="0" max="59" /> \n </div>\n ${"24h"!==u?`<div class="timepicker-ui-wrapper-type-time mobile">\n <div class="timepicker-ui-type-mode timepicker-ui-am mobile" data-type="AM" tabindex="0">${s}</div> \n <div class="timepicker-ui-type-mode timepicker-ui-pm mobile" data-type="PM" tabindex="0">${r}</div> \n </div>`:""}\n </div>\n <div class="timepicker-ui-footer mobile" data-view="mobile">\n ${m?`\n <div class="timepicker-ui-keyboard-icon-wrapper mobile" role="button" aria-pressed="false" data-view="desktop" tabindex="0">\n ${o}\n </div>`:""}\n <div class="timepicker-ui-wrapper-btn mobile">\n <div class="timepicker-ui-cancel-btn mobile" role="button" aria-pressed="false" tabindex="0">${n}</div>\n <div class="timepicker-ui-ok-btn mobile" role="button" aria-pressed="false" tabindex="0">${c}</div>\n </div>\n </div>\n </div> \n </div>`})(this._options,this._instanceId):((e,i)=>{const{iconTemplate:t,timeLabel:s,amLabel:r,pmLabel:n,cancelLabel:c,okLabel:o,enableSwitchIcon:a,animation:l,clockType:m,editable:p,theme:u}=e;return`\n <div class="timepicker-ui-modal normalize ${u}" role="dialog" data-owner-id="${i}" style='transition:${l?"opacity 0.15s linear":"none"}'>\n <div class="timepicker-ui-wrapper" tabindex="0">\n <div class="timepicker-ui-header">\n <div class="timepicker-ui-select-time">${s}</div>\n <div class="timepicker-ui-wrapper-time ${"24h"===m?"timepicker-ui-wrapper-time-24h":""}">\n <input name="hour" ${p?"":"readonly"} class="timepicker-ui-hour" tabindex="0" type="number" min="0" max="${"12h"===m?"12":"23"}" />\n <div class="timepicker-ui-dots"> \n <span></span>\n <span></span>\n </div> \n <input name="minutes" ${p?"":"readonly"} class="timepicker-ui-minutes" tabindex="0" type="number" min="0" max="59" /> \n </div>\n ${"24h"!==m?`\n <div class="timepicker-ui-wrapper-type-time">\n <div class="timepicker-ui-type-mode timepicker-ui-am" tabindex="0" role="button" data-type="AM">${r}</div> \n <div class="timepicker-ui-type-mode timepicker-ui-pm" tabindex="0" role="button" data-type="PM">${n}</div> \n </div>\n `:""}\n </div>\n <div class="timepicker-ui-wrapper-landspace">\n <div class="timepicker-ui-body">\n <div class="timepicker-ui-clock-face">\n <div class="timepicker-ui-dot"></div>\n <div class="timepicker-ui-clock-hand">\n <div class="timepicker-ui-circle-hand"></div>\n </div>\n <div class="timepicker-ui-tips-wrapper"></div>\n ${"24h"===m?'<div class="timepicker-ui-tips-wrapper-24h"></div>':""}\n </div>\n </div>\n <div class="timepicker-ui-footer">\n ${a?`\n <div class="timepicker-ui-keyboard-icon-wrapper" tabindex="0" role="button" aria-pressed="false" data-view="desktop">\n ${t}\n </div>`:""}\n <div class="timepicker-ui-wrapper-btn" >\n <div class="timepicker-ui-cancel-btn" tabindex="0" role="button" aria-pressed="false">${c}</div>\n <div class="timepicker-ui-ok-btn" tabindex="0" role="button" aria-pressed="false">${o}</div>\n </div>\n </div>\n </div>\n </div> \n </div>`})(this._options,this._instanceId)}get modalElement(){return document.querySelector(`[data-owner-id="${this._instanceId}"]`)}get clockFace(){return this.modalElement?.querySelector(".timepicker-ui-clock-face")}get input(){return this._element?.querySelector("input")}get clockHand(){return this.modalElement?.querySelector(".timepicker-ui-clock-hand")}get circle(){return this.modalElement?.querySelector(".timepicker-ui-circle-hand")}get tipsWrapper(){return this.modalElement?.querySelector(".timepicker-ui-tips-wrapper")}get tipsWrapperFor24h(){return this.modalElement?.querySelector(".timepicker-ui-tips-wrapper-24h")}get minutes(){return this.modalElement?.querySelector(".timepicker-ui-minutes")}get hour(){return this.modalElement?.querySelector(".timepicker-ui-hour")}get AM(){return this.modalElement?.querySelector(".timepicker-ui-am")}get PM(){return this.modalElement?.querySelector(".timepicker-ui-pm")}get minutesTips(){return this.modalElement?.querySelector(".timepicker-ui-minutes-time")}get hourTips(){return this.modalElement?.querySelector(".timepicker-ui-hour-time-12")}get allValueTips(){const e=this.modalElement;return e?[...e.querySelectorAll(".timepicker-ui-value-tips"),...e.querySelectorAll(".timepicker-ui-value-tips-24h")]:[]}get openElementData(){const e=this._element?.querySelectorAll("[data-open]");if(e?.length>0){const i=[];return e.forEach(({dataset:e})=>i.push(e.open??"")),[...new Set(i)]}return null}get openElement(){return null===this.openElementData?(this.input?.setAttribute("data-open","timepicker-ui-input"),[this.input]):this.openElementData.map(e=>this._element?.querySelectorAll(`[data-open='${e}']`))[0]??""}get cancelButton(){return this.modalElement?.querySelector(".timepicker-ui-cancel-btn")}get okButton(){return this.modalElement?.querySelector(".timepicker-ui-ok-btn")}get activeTypeMode(){return this.modalElement?.querySelector(".timepicker-ui-type-mode.active")}get keyboardClockIcon(){return this.modalElement?.querySelector(".timepicker-ui-keyboard-icon-wrapper")}get footer(){return this.modalElement?.querySelector(".timepicker-ui-footer")}get wrapper(){return this.modalElement?.querySelector(".timepicker-ui-wrapper")}getElement(){return this._element}create=()=>{this._isInitialized?console.warn("TimepickerUI: Instance is already initialized"):(this.configManager.updateInputValueWithCurrentTimeOnStart(),this.validationManager.checkDisabledValuesOnStart(),this.themeManager.setTimepickerClassToElement(),this.themeManager.setInputClassToInputElement(),this.themeManager.setDataOpenToInputIfDosentExistInWrapper(),this.themeManager.setClassTopOpenElement(),this._options.inline?.enabled?(this.eventManager.handleOpenOnEnterFocus(),this._eventsBundle()):(this.eventManager.handleOpenOnEnterFocus(),this.eventManager.handleOpenOnClick()),this.configManager.getDisableTime(),this._isInitialized=!0)};open=e=>{this._isInitialized||this.create(),this._eventsBundle(),a(e)};close=()=>v((...e)=>{if(e.length>2||!this.modalElement)return;const[i]=e.filter(e=>"boolean"==typeof e),[t]=e.filter(e=>"function"==typeof e);i&&(this.eventManager.handleOkButton(),this.okButton?.click()),this._isTouchMouseMove=!1,d.split(" ").map(e=>document.removeEventListener(e,this._mutliEventsMoveHandler,!1)),document.removeEventListener("mousedown",this._eventsClickMobileHandler),document.removeEventListener("touchstart",this._eventsClickMobileHandler),document.removeEventListener("keypress",this.eventManager.handleEscClick),this.wrapper.removeEventListener("keydown",this.eventManager.focusTrapHandler),this._options.enableSwitchIcon&&(this.keyboardClockIcon.removeEventListener("touchstart",this.configManager.handlerViewChange()),this.keyboardClockIcon.removeEventListener("mousedown",this.configManager.handlerViewChange())),this.animationManager.removeAnimationToClose(),this.openElement.forEach(e=>e?.classList.remove("disabled")),setTimeout(()=>{document.body.style.overflowY="",document.body.style.paddingRight=""},400),this.openElement.forEach(e=>e?.classList.remove("disabled")),setTimeout(()=>{this._options.focusInputAfterCloseModal&&this.input?.focus(),null!==this.modalElement&&(this.modalElement.remove(),this._isModalRemove=!0)},300),a(t)},this._options.delayHandler||300);destroy=e=>{if(this._isDestroyed)return void console.warn("TimepickerUI: Instance is already destroyed");const i="function"==typeof e?{callback:e}:e||{},{keepInputValue:t=!1,callback:s}=i,r=t?this.input?.value:null;d.split(" ").forEach(e=>{document.removeEventListener(e,this._mutliEventsMoveHandler,!1)}),document.removeEventListener("mousedown",this._eventsClickMobileHandler),document.removeEventListener("touchstart",this._eventsClickMobileHandler),document.removeEventListener("keypress",this.eventManager.handleEscClick),this._options.enableSwitchIcon&&this.keyboardClockIcon&&(this.keyboardClockIcon.removeEventListener("touchstart",this.configManager.handlerViewChange()),this.keyboardClockIcon.removeEventListener("mousedown",this.configManager.handlerViewChange())),this.input&&this._inputEvents.forEach(e=>{this.input.removeEventListener(e,()=>{})}),this.modalElement?.remove(),this.openElement?.forEach(e=>{e&&(e.classList.remove("disabled","active","timepicker-ui-open-element"),e.classList.remove("basic","crane-straight","crane-radius","m3"))}),this.input&&(this.input.classList.remove("timepicker-ui-invalid-format","invalid-value","error","active","timepicker-ui-input"),this.input.removeAttribute("data-open"),this.input.removeAttribute("data-owner-id"),t&&null!==r&&(this.input.value=r)),this._element&&(this._element.classList.remove("basic","crane-straight","crane-radius","m3"),this._element.classList.remove("error","active","disabled"),this._element.removeAttribute("data-owner-id"),this._element.removeAttribute("data-open"),this._options.cssClass&&this._element.classList.remove(this._options.cssClass));const n=this._element?.querySelectorAll(".timepicker-ui-invalid-text");n?.forEach(e=>e.remove()),this._mutliEventsMoveHandler=null,this._eventsClickMobileHandler=null,this._mutliEventsMove=()=>{},this._eventsClickMobile=()=>Promise.resolve(),this._isModalRemove=!0,this._isTouchMouseMove=!1,this._disabledTime=null,this._cloned=null,this._degreesHours=null,this._degreesMinutes=null,this._isInitialized=!1,this._isDestroyed=!0,"undefined"!=typeof document&&(document.body.style.overflowY="",document.body.style.paddingRight=""),$.delete(this._instanceId),a(s)};update=(e,i)=>{this._isDestroyed?console.warn("TimepickerUI: Instance is destroyed"):(this._options={...this._options,...e.options},this.configManager.checkMobileOption(),e.create&&this.create(),a(i))};getValue=()=>{if(this._isDestroyed)return console.warn("TimepickerUI: Instance is destroyed"),{hour:"",minutes:"",time:"",degreesHours:null,degreesMinutes:null};const e=this.hour?.value||"12",i=this.minutes?.value||"00",t="24h"===this._options.clockType?void 0:this.activeTypeMode?.textContent||"AM";let s="";return s="24h"===this._options.clockType?`${e.padStart(2,"0")}:${i.padStart(2,"0")}`:`${e}:${i.padStart(2,"0")} ${t}`,{hour:e,minutes:i,type:t,time:s,degreesHours:this._degreesHours,degreesMinutes:this._degreesMinutes}};setValue=(e,i=!0)=>{if(this._isDestroyed)return void console.warn("TimepickerUI: Instance is destroyed");if(!e||"string"!=typeof e)throw new Error("TimepickerUI: setValue requires a valid time string");const t=e.trim();let s="12",r="00",n="AM";try{if("24h"===this._options.clockType){const e=t.match(/^([0-1]?[0-9]|2[0-3]):([0-5][0-9])$/);if(!e)throw new Error("Invalid 24h format. Expected HH:MM");s=e[1].padStart(2,"0"),r=e[2]}else{const e=t.match(/^(1[0-2]|[1-9]):([0-5][0-9])\s*(AM|PM)$/i);if(!e)throw new Error("Invalid 12h format. Expected HH:MM AM/PM");s=e[1],r=e[2],n=e[3].toUpperCase()}this.hour&&(this.hour.value=s,this._degreesHours=30*Number(s)),this.minutes&&(this.minutes.value=r,this._degreesMinutes=6*Number(r)),"24h"!==this._options.clockType&&this.AM&&this.PM&&("AM"===n?(this.AM.classList.add("active"),this.PM.classList.remove("active")):(this.PM.classList.add("active"),this.AM.classList.remove("active"))),i&&this.input&&(this.input.value=t),this.clockHand&&(this.clockHand.style.transform=`rotateZ(${this._degreesHours||0}deg)`)}catch(e){throw new Error(`TimepickerUI: ${e instanceof Error?e.message:"Invalid time format"}`)}};_eventsBundle=()=>{if(this._isDestroyed)console.warn("TimepickerUI: Instance is destroyed");else if(this._isModalRemove){if(this._options.inline?.enabled||this.eventManager.handleEscClick(),this.validationManager.setErrorHandler(),this.validationManager.removeErrorHandler(),this._options.inline?.enabled||(this.openElement.forEach(e=>e?.classList.add("disabled")),this.input?.blur()),this.modalManager.setScrollbarOrNot(),this.modalManager.setModalTemplate(),this.modalManager.setNormalizeClass(),this.modalManager.removeBackdrop(),this.clockManager.setBgColorToCirleWithHourTips(),this.clockManager.setOnStartCSSClassesIfClockType24h(),this.clockManager.setClassActiveToHourOnOpen(),null!==this.clockFace){const e=new g({array:T,classToAdd:"timepicker-ui-hour-time-12",clockFace:this.clockFace,tipsWrapper:this.tipsWrapper,theme:this._options.theme,disabledTime:this._disabledTime?.value?.isInterval?this._disabledTime?.value.rangeArrHour:this._disabledTime?.value?.hours,clockType:"12h",hour:this.hour.value});if(e.create(),"24h"===this._options.clockType){new g({array:b,classToAdd:"timepicker-ui-hour-time-24",clockFace:this.tipsWrapperFor24h,tipsWrapper:this.tipsWrapperFor24h,theme:this._options.theme,clockType:"24h",disabledTime:this._disabledTime?.value?.isInterval?this._disabledTime?.value.rangeArrHour:this._disabledTime?.value?.hours,hour:this.hour.value}).create()}else this._disabledTime?.value.startType===this._disabledTime?.value.endType?setTimeout(()=>{this._disabledTime?.value.startType===this.activeTypeMode?.textContent&&e.updateDisable({hoursToUpdate:this._disabledTime?.value?.rangeArrHour,minutesToUpdate:{endMinutes:this._disabledTime?.value.endMinutes,removedEndHour:this._disabledTime?.value.removedEndHour,removedStartedHour:this._disabledTime?.value.removedStartedHour,actualHour:this.hour.value,startMinutes:this._disabledTime?.value.startMinutes}})},300):setTimeout(()=>{e.updateDisable({minutesToUpdate:{actualHour:this.hour.value,pmHours:this._disabledTime?.value.pmHours,amHours:this._disabledTime?.value.amHours,activeMode:this.activeTypeMode?.textContent}})},300),e.updateDisable()}this.modalManager.setFlexEndToFooterIfNoKeyboardIcon(),setTimeout(()=>{this.themeManager.setTheme()},0),this.animationManager.setAnimationToOpen(),this.configManager.getInputValueOnOpenAndSet(),this.clockManager.toggleClassActiveToValueTips(this.hour.value),this._isMobileView||(this.clockManager.setTransformToCircleWithSwitchesHour(this.hour.value),this.animationManager.handleAnimationClock()),this.eventManager.handleMinutesEvents(),this.eventManager.handleHourEvents(),"24h"!==this._options.clockType&&(this.eventManager.handleAmClick(),this.eventManager.handlePmClick()),this.clockFace&&this.eventManager.handleMoveHand(),this.eventManager.handleCancelButton(),this.eventManager.handleOkButton(),this.modalElement&&(this.modalManager.setShowClassToBackdrop(),this._options.inline?.enabled||this.eventManager.handleBackdropClick()),this.eventManager.handleIconChangeView(),this.eventManager.handleClickOnHourMobile(),this._options.focusTrap&&this.eventManager.focusTrapHandler(),this._options.inline?.enabled&&!1!==this._options.inline.autoUpdate&&this.eventManager.handleInlineAutoUpdate()}}}});
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TimepickerUI={})}(this,function(e){"use strict";const t=(e,t)=>({...t,...e}),i=(e,t)=>{const{touches:i}=e,{clientX:s,clientY:r}=e;if(!t)return;const{left:n,top:o}=t.getBoundingClientRect();let c={x:0,y:0};if(void 0===i)c={x:s-n,y:r-o};else if(void 0!==i&&i.length>0&&Object.keys(i).length>0){const{clientX:e,clientY:t}=i[0];c={x:e-n,y:t-o}}return 0!==Object.keys(c).length||c.constructor!==Object?c:void 0},s=(e,t)=>!!e&&e.classList.contains(t),r=(e,t,i,s,r,n)=>{if(!e)return;const o=new CustomEvent(i,{detail:s,bubbles:!0,cancelable:!0});try{if(e.dispatchEvent(o)&&t!==i){const i=new CustomEvent(t,{detail:s,bubbles:!0,cancelable:!0});e.dispatchEvent(i)}if(n&&"emit"in n&&"function"==typeof n.emit){const e=i.replace("timepicker:","").replace(/-/g,":");n.emit(e,s)}}catch(e){console.warn(`TimepickerUI: Error dispatching event ${i}:`,e)}if(r&&"function"==typeof r)try{r(s)}catch(e){console.warn(`TimepickerUI: Error in ${i} callback:`,e)}},n=(e,t,i)=>((e,t)=>Math.round(e/t)*t)(e,t*i),o=(e,t)=>Array.from({length:Number(t)-Number(e)+1},(t,i)=>Number(e)+i),c=(e,t)=>Array.from({length:Number(t)-Number(e)+1},(e,i)=>Number(t)-i).reverse(),a=e=>{e&&"function"==typeof e&&e()},l=(e="")=>{const t=e.replace(/(AM|PM|am|pm)/,e=>` ${e}`),i=new Date(`September 20, 2000 ${t}`);return`${i.getHours().toString().padStart(2,"0")}:${i.getMinutes().toString().padStart(2,"0")}`},m=e=>{const[t,i]=e.split(":"),s=Number(t),r=Number(i);return`${s<=9?"0"+s:s}:${r<=9?"0"+r:r}`},p=(e,t)=>{if(e.length<2)return!1;const i=e.map(e=>{const[i,s]=e.trim().split("-");let r,n;if("12h"===t){if(!/\s?(AM|PM|am|pm)\s?$/.test(i.trim())||!/\s?(AM|PM|am|pm)\s?$/.test(s.trim()))throw new Error(`Invalid 12h format in interval: "${e}". AM/PM is required for 12h clock type.`);r=l(i.trim()),n=l(s.trim())}else{if(/\s?(AM|PM|am|pm)\s?/.test(i.trim())||/\s?(AM|PM|am|pm)\s?/.test(s.trim()))throw new Error(`Invalid 24h format in interval: "${e}". AM/PM is not allowed for 24h clock type.`);r=m(i.trim()),n=m(s.trim())}return{start:r,end:n,original:e}});for(let e=0;e<i.length;e++)for(let t=e+1;t<i.length;t++){const s=i[e],r=i[t];if(s.start<=r.end&&s.end>=r.start||r.start<=s.end&&r.end>=s.start)throw new Error(`Overlapping time intervals detected: "${s.original}" overlaps with "${r.original}"`)}return!1},h=(e,t)=>{let i;return(...s)=>{clearTimeout(i),i=setTimeout(()=>{e(...s)},t)}},u="timepicker-ui",d="mousedown mouseup mousemove mouseleave mouseover touchstart touchmove touchend",k="active",v=["00","13","14","15","16","17","18","19","20","21","22","23"],g=["12","1","2","3","4","5","6","7","8","9","10","11"],M=["00","05","10","15","20","25","30","35","40","45","50","55"],T=(e,t,i,s)=>{const r={hour:"12",minutes:"00",type:"24h"===t?void 0:"PM"};if(!e)return r;const n=e.value.trim();if(!i&&""===n)return r;if("boolean"==typeof i&&i){const e=new Date,[i,s]=e.toLocaleTimeString().split(":"),r=Number(i)<=9?`0${Number(i)}`:i;if(/[a-z]/i.test(s)&&"12h"===t){const[e,t]=s.split(" ");return{hour:r,minutes:e,type:t}}return{hour:r,minutes:s,type:void 0}}if("object"==typeof i){const{time:e,locales:r,preventClockType:n}=i,o=e??new Date;if(n&&s){const[e,t]=new Date(o).toLocaleTimeString().split(":");if(/[a-z]/i.test(t)){const[i,s]=t.split(" ");return{hour:e,minutes:i,type:s}}return{hour:Number(e)<=9?`0${Number(e)}`:e,minutes:t,type:void 0}}const[c,a]=new Date(o).toLocaleTimeString(r,{timeStyle:"short"}).split(":"),l=Number(c)<=9?`0${Number(c)}`:c;if(/[a-z]/i.test(a)&&"12h"===t){const[e,t]=a.split(" ");return{hour:l,minutes:e,type:t}}if("12h"===t){const[e,t]=new Date(`1970-01-01T${c}:${a}Z`).toLocaleTimeString("en-US",{timeZone:"UTC",hour12:!0,hour:"numeric",minute:"numeric"}).split(":"),[i,s]=t.split(" ");return{hour:Number(e)<=9?`0${Number(e)}`:e,minutes:i,type:s}}return{hour:l,minutes:a,type:void 0}}const[o,c]=n.split(" "),[a="",l=""]=o.split(":"),m=a.replace(/\D/g,""),p=l.replace(/\D/g,""),h={hour:m.padStart(2,"0"),minutes:p.padStart(2,"0"),type:"12h"===t?c:void 0};if(m.length>2||p.length>2)return{...h,error:"Invalid input: too many digits.",currentHour:a,currentMin:l};if(/[a-z]/i.test(o))return{...h,error:"Input contains invalid letters."};if(n.includes(" ")&&(!c||n.length>8||"AM"!==c&&"PM"!==c))return{...h,error:"Invalid AM/PM format or length.",currentLength:n.length,currentType:c};const u=Number(m),d=Number(p);if("12h"===t){if(u<1||u>12||d<0||d>59||"AM"!==c&&"PM"!==c)return{...h,error:"Invalid 12h time.",currentHour:u,currentMin:d,currentType:c}}else if(u<0||u>23||d<0||d>59)return{...h,error:"Invalid 24h time.",currentHour:u,currentMin:d};return h},y=(e,t,i)=>{const s=Number(e);if(Number.isNaN(s))return!1;switch(t){case"hour":return"24h"===i?s>=0&&s<=23:s>0&&s<=12;case"minutes":return s>=0&&s<=59;default:return}},_={amLabel:"AM",animation:!0,appendModalSelector:"",backdrop:!0,cancelLabel:"CANCEL",editable:!1,enableScrollbar:!1,enableSwitchIcon:!1,mobileTimeLabel:"Enter Time",focusInputAfterCloseModal:!1,hourMobileLabel:"Hour",iconTemplate:'<i class="material-icons timepicker-ui-keyboard-icon">keyboard</i>',iconTemplateMobile:'<i class="material-icons timepicker-ui-keyboard-icon">schedule</i>',incrementHours:1,incrementMinutes:1,minuteMobileLabel:"Minute",mobile:!1,okLabel:"OK",pmLabel:"PM",timeLabel:"Select Time",switchToMinutesAfterSelectHour:!1,theme:"basic",clockType:"12h",disabledTime:void 0,currentTime:void 0,focusTrap:!0,delayHandler:300,inline:void 0,cssClass:void 0},b=(e,t,i,s)=>{if(e){if(Array.isArray(e)&&e.length>0){return!e.map(e=>y(e,t,i)).some(e=>!1===e)}if("string"==typeof e||"number"==typeof e){const r=y(e,t,i),n=s?.map(Number).includes(Number(e));return!(!r||n)}}},f=(e,t,i,s,r)=>{if(!(e&&t&&s&&r))return!1;const n="12h"===r?l(`${e}:${t} ${i||""}`.trim()):m(`${e}:${t}`),o=Array.isArray(s)?s:[s];for(const e of o){const[t,i]=e.trim().split("-");let s,o;if("12h"===r){const r=t.trim(),n=i.trim();if(!/\s?(AM|PM|am|pm)\s?$/.test(r)||!/\s?(AM|PM|am|pm)\s?$/.test(n)){console.warn(`Invalid 12h format in interval: "${e}". AM/PM is required for 12h clock type.`);continue}s=l(r),o=l(n)}else{const r=t.trim(),n=i.trim();if(/\s?(AM|PM|am|pm)\s?/.test(r)||/\s?(AM|PM|am|pm)\s?/.test(n)){console.warn(`Invalid 24h format in interval: "${e}". AM/PM is not allowed for 24h clock type.`);continue}s=m(r),o=m(n)}if(n>=s&&n<=o)return!1}return!0};class E{array;classToAdd;clockFace;tipsWrapper;theme;clockType;disabledTime;hour;activeTypeMode;constructor(e){Object.assign(this,e)}clean=()=>{const e=this.tipsWrapper?.querySelectorAll("span.timepicker-ui-hour-time-12"),t=this.tipsWrapper?.querySelectorAll("span.timepicker-ui-minutes-time");this._removeClasses(e),this._removeClasses(t)};create=()=>{if(!(this.clockFace&&this.array&&this.classToAdd&&this.tipsWrapper))return;const e=(this.clockFace.offsetWidth-32)/2,t=(this.clockFace.offsetHeight-32)/2,i=e-9;this.tipsWrapper.innerHTML="";const s=document.createDocumentFragment();this.array.forEach((r,n,o)=>{const c=n*(360/o.length)*(Math.PI/180);const a=document.createElement("span"),l=document.createElement("span");if(l.innerHTML=r,this.disabledTime&&(Array.isArray(this.disabledTime)&&this.disabledTime.includes(r)&&(l.classList.add("timepicker-ui-tips-disabled"),a.classList.add("timepicker-ui-tips-disabled"),l.setAttribute("aria-disabled","true")),this.disabledTime.isInterval&&this.disabledTime.clockType)){const e=this.classToAdd?.includes("minutes"),t=this.classToAdd?.includes("hour");if(e&&this.hour){!f(this.hour,r,this.activeTypeMode||"",this.disabledTime.intervals||[],this.disabledTime.clockType)&&(l.classList.add("timepicker-ui-tips-disabled"),a.classList.add("timepicker-ui-tips-disabled"),l.tabIndex=-1,l.setAttribute("aria-disabled","true"))}else if(t){let e=!0;for(let t=0;t<60;t++){const i=t.toString().padStart(2,"0");if(f(r,i,this.activeTypeMode||"",this.disabledTime.intervals||[],this.disabledTime.clockType)){e=!1;break}}e&&(l.classList.add("timepicker-ui-tips-disabled"),a.classList.add("timepicker-ui-tips-disabled"),l.tabIndex=-1,l.setAttribute("aria-disabled","true"))}}const m="24h"===this.clockType?"timepicker-ui-value-tips-24h":"timepicker-ui-value-tips";l.classList.add(m),l.setAttribute("role","option"),l.setAttribute("aria-selected","false"),l.tabIndex=0,a.classList.add(this.classToAdd||""),this.theme&&(a.classList.add(this.theme),l.classList.add(this.theme)),a.style.left=`${e+Math.sin(c)*i}px`,a.style.bottom=`${t+Math.cos(c)*i}px`,a.appendChild(l),s.appendChild(a)}),this.tipsWrapper.appendChild(s)};updateDisable=(e,t)=>{const i=this.tipsWrapper?.querySelectorAll("span.timepicker-ui-hour-time-12"),s=this.tipsWrapper?.querySelectorAll("span.timepicker-ui-minutes-time");if(this._removeClasses(i),this._removeClasses(s),!this.disabledTime?.isInterval||!this.disabledTime?.intervals)return;const r=this.disabledTime.intervals,n=this.disabledTime.clockType,o=t||this.activeTypeMode||"";i?.forEach(e=>{const t=e.querySelector(".timepicker-ui-value-tips");if(!t)return;const i=t.innerHTML;let s=!0;for(let e=0;e<60;e++){const t=e.toString().padStart(2,"0");if(f(i,t,o,r,n)){s=!1;break}}s&&(e.classList.add("timepicker-ui-tips-disabled"),t.classList.add("timepicker-ui-tips-disabled"),t.setAttribute("aria-disabled","true"),t.tabIndex=-1)}),s&&e&&s.forEach(t=>{const i=t.querySelector(".timepicker-ui-value-tips");if(!i)return;const s=i.innerHTML;!f(e,s,o,r,n)&&(t.classList.add("timepicker-ui-tips-disabled"),i.classList.add("timepicker-ui-tips-disabled"),i.setAttribute("aria-disabled","true"),i.tabIndex=-1)})};_removeClasses=e=>{e?.forEach(e=>{const t=e.children[0];e.classList.remove("timepicker-ui-tips-disabled"),t&&(t.classList.remove("timepicker-ui-tips-disabled"),t.removeAttribute("aria-disabled"),t.tabIndex=0)})};destroy(){this.tipsWrapper&&(this.tipsWrapper.innerHTML=""),this.array=this.classToAdd=this.theme=this.clockType=void 0,this.disabledTime=this.hour=this.activeTypeMode=void 0,this.clockFace=this.tipsWrapper=void 0}}class C{pool=[];maxSize=5;acquire(e){const t=this.pool.pop();return t?(Object.assign(t,e),t):new E(e)}release(e){this.pool.length<this.maxSize&&this.pool.push(e)}clear(){this.pool=[]}}class w{timepicker;cleanupHandlers;constructor(e,t){this.timepicker=e,this.cleanupHandlers=t}handleCancelButton=()=>{const e=()=>{const e=T(this.timepicker.input,this.timepicker._options.clockType);r(this.timepicker._element,"cancel","timepicker:cancel",{...e,hourNotAccepted:this.timepicker.hour.value,minutesNotAccepted:this.timepicker.minutes.value,type:this.timepicker.activeTypeMode?.dataset.type,degreesHours:this.timepicker._degreesHours,degreesMinutes:this.timepicker._degreesMinutes},this.timepicker._options.onCancel,this.timepicker),this.timepicker.close()()};this.timepicker.cancelButton.addEventListener("click",e),this.cleanupHandlers.push(()=>{this.timepicker.cancelButton?.removeEventListener("click",e)})};handleOkButton=()=>{const e=()=>{const{clockType:e,disabledTime:t}=this.timepicker._options,i=y(this.timepicker.hour.value,"hour",e),s=y(this.timepicker.minutes.value,"minutes",e);let n;const o=b(this.timepicker.hour.value,"hour",e,t?.hours),c=b(this.timepicker.minutes.value,"minutes",e,t?.minutes);if(t?.interval&&(n=f(this.timepicker.hour.value,this.timepicker.minutes.value,this.timepicker.activeTypeMode?.textContent||"",t.interval,e)),!1===n||!1===i||!1===s||!1===o||!1===c)return!1!==n&&s&&c||this.timepicker.minutes.classList.add("invalid-value"),void(!1!==n&&i&&o||this.timepicker.hour.classList.add("invalid-value"));this.timepicker.input.value=`${this.timepicker.hour.value}:${this.timepicker.minutes.value} ${"24h"===this.timepicker._options.clockType?"":this.timepicker.activeTypeMode?.dataset.type}`.trimEnd(),r(this.timepicker._element,"","timepicker:confirm",{hour:this.timepicker.hour.value,minutes:this.timepicker.minutes.value,type:this.timepicker.activeTypeMode?.dataset.type,degreesHours:this.timepicker._degreesHours,degreesMinutes:this.timepicker._degreesMinutes},this.timepicker._options.onConfirm,this.timepicker),this.timepicker.close()()};this.timepicker.okButton?.addEventListener("click",e),this.cleanupHandlers.push(()=>{this.timepicker.okButton?.removeEventListener("click",e)})};handleBackdropClick=()=>{const e=e=>{const t=e.target;if(!s(t,"timepicker-ui-modal"))return;const i=T(this.timepicker.input,this.timepicker._options.clockType);r(this.timepicker._element,"","timepicker:cancel",{...i,hourNotAccepted:this.timepicker.hour.value,minutesNotAccepted:this.timepicker.minutes.value,type:this.timepicker.activeTypeMode?.dataset.type,degreesHours:this.timepicker._degreesHours,degreesMinutes:this.timepicker._degreesMinutes},this.timepicker._options.onCancel,this.timepicker),this.timepicker.close()()};this.timepicker.modalElement?.addEventListener("click",e),this.cleanupHandlers.push(()=>{this.timepicker.modalElement?.removeEventListener("click",e)})}}class H{timepicker;_isDragging=!1;_animationFrameId=null;_pendingUpdate=!1;updateHandPosition;constructor(e,t){this.timepicker=e,this.updateHandPosition=t}get isDragging(){return this._isDragging}get animationFrameId(){return this._animationFrameId}cleanup(){document.removeEventListener("mousedown",this._onDragStart,!1),document.removeEventListener("touchstart",this._onDragStart),document.removeEventListener("mousemove",this._onDragMove,!1),document.removeEventListener("mouseup",this._onDragEnd,!1),document.removeEventListener("touchmove",this._onDragMove),document.removeEventListener("touchend",this._onDragEnd,!1),document.removeEventListener("mouseleave",this._onDragEnd,!1),this._animationFrameId&&(cancelAnimationFrame(this._animationFrameId),this._animationFrameId=null),this._isDragging=!1,this._pendingUpdate=!1}_onDragStart=e=>{const t=e.target;(s(t,"timepicker-ui-clock-face")||s(t,"timepicker-ui-circle-hand")||s(t,"timepicker-ui-hour-time-12")||s(t,"timepicker-ui-minutes-time")||s(t,"timepicker-ui-clock-hand")||s(t,"timepicker-ui-value-tips")||s(t,"timepicker-ui-value-tips-24h")||s(t,"timepicker-ui-tips-wrapper")||s(t,"timepicker-ui-tips-wrapper-24h"))&&!s(t,"timepicker-ui-tips-disabled")&&(e.preventDefault(),this._isDragging=!0,this.timepicker._isTouchMouseMove=!0,document.addEventListener("mousemove",this._onDragMove,!1),document.addEventListener("mouseup",this._onDragEnd,!1),document.addEventListener("touchmove",this._onDragMove,{passive:!1}),document.addEventListener("touchend",this._onDragEnd,!1),document.addEventListener("mouseleave",this._onDragEnd,!1),this._scheduleUpdate(e))};_onDragMove=e=>{this._isDragging&&(e.preventDefault(),this._scheduleUpdate(e))};_onDragEnd=e=>{if(!this._isDragging)return;this._isDragging=!1,this.timepicker._isTouchMouseMove=!1,document.removeEventListener("mousemove",this._onDragMove,!1),document.removeEventListener("mouseup",this._onDragEnd,!1),document.removeEventListener("touchmove",this._onDragMove),document.removeEventListener("touchend",this._onDragEnd,!1),document.removeEventListener("mouseleave",this._onDragEnd,!1),this._animationFrameId&&(cancelAnimationFrame(this._animationFrameId),this._animationFrameId=null,this._pendingUpdate=!1);const t=e.target,{switchToMinutesAfterSelectHour:i}=this.timepicker._options;i&&(s(t,"timepicker-ui-value-tips")||s(t,"timepicker-ui-value-tips-24h")||s(t,"timepicker-ui-tips-wrapper"))&&this.timepicker.minutes.click()};_scheduleUpdate=e=>{this._pendingUpdate||(this._pendingUpdate=!0,this._animationFrameId=requestAnimationFrame(()=>{this._pendingUpdate=!1,this.updateHandPosition(e)}))};handleEventToMoveHand=e=>{const{type:t}=e;"mousedown"===t||"touchstart"===t?this._onDragStart(e):"mouseup"===t||"touchend"===t?this._onDragEnd(e):"mousemove"!==t&&"touchmove"!==t||!this._isDragging||this._onDragMove(e)};handleMoveHand=()=>{this.timepicker._options.mobile||this.timepicker._isMobileView||(document.addEventListener("mousedown",this._onDragStart,!1),document.addEventListener("touchstart",this._onDragStart,{passive:!1}))}}const L=(e,t)=>{if(!e)return;const i=e.querySelector(".timepicker-announcer");i&&(i.textContent="",setTimeout(()=>{i.textContent=t},100))},A=(e,t)=>{e&&e.setAttribute("aria-pressed",String(t))};class I{timepicker;cleanupHandlers;constructor(e,t){this.timepicker=e,this.cleanupHandlers=t}handleAmClick=()=>{this.timepicker._clickTouchEvents.forEach(e=>{const t=e=>{const t=e.target;t.classList.add(k),this.timepicker.PM.classList.remove(k),A(t,!0),A(this.timepicker.PM,!1),L(this.timepicker.modalElement,"AM selected"),"12h"===this.timepicker._options.clockType&&this.timepicker._options.disabledTime?.interval&&setTimeout(()=>{const e=this.timepicker.clockFacePool.acquire({clockFace:this.timepicker.clockFace,tipsWrapper:this.timepicker.tipsWrapper,disabledTime:this.timepicker._disabledTime?.value,clockType:this.timepicker._options.clockType,activeTypeMode:"AM"});e.updateDisable(this.timepicker.hour.value,"AM"),this.timepicker.clockFacePool.release(e)},300),r(this.timepicker._element,"","timepicker:select-am",{hour:this.timepicker.hour.value,minutes:this.timepicker.minutes.value,type:this.timepicker.activeTypeMode?.dataset.type,degreesHours:this.timepicker._degreesHours,degreesMinutes:this.timepicker._degreesMinutes},this.timepicker._options.onSelectAM,this.timepicker)};this.timepicker.AM.addEventListener(e,t),this.cleanupHandlers.push(()=>{this.timepicker.AM?.removeEventListener(e,t)})})};handlePmClick=()=>{this.timepicker._clickTouchEvents.forEach(e=>{const t=e=>{const t=e.target;t.classList.add(k),this.timepicker.AM.classList.remove(k),A(t,!0),A(this.timepicker.AM,!1),L(this.timepicker.modalElement,"PM selected"),"12h"===this.timepicker._options.clockType&&this.timepicker._options.disabledTime?.interval&&setTimeout(()=>{const e=this.timepicker.clockFacePool.acquire({clockFace:this.timepicker.clockFace,tipsWrapper:this.timepicker.tipsWrapper,disabledTime:this.timepicker._disabledTime?.value,clockType:this.timepicker._options.clockType,activeTypeMode:"PM"});e.updateDisable(this.timepicker.hour.value,"PM"),this.timepicker.clockFacePool.release(e)},300),r(this.timepicker._element,"","timepicker:select-pm",{hour:this.timepicker.hour.value,minutes:this.timepicker.minutes.value,type:this.timepicker.activeTypeMode?.dataset.type,degreesHours:this.timepicker._degreesHours,degreesMinutes:this.timepicker._degreesMinutes},this.timepicker._options.onSelectPM,this.timepicker)};this.timepicker.PM.addEventListener(e,t),this.cleanupHandlers.push(()=>{this.timepicker.PM?.removeEventListener(e,t)})})}}class S{timepicker;cleanupHandlers;constructor(e,t){this.timepicker=e,this.cleanupHandlers=t}handleClasses24h=(e,t,i=!1)=>{const s=e.target,r=e.relatedTarget;if(this.timepicker.hourTips&&"24h"===this.timepicker._options.clockType&&(Number(s.textContent)>12||0===Number(s.textContent)?this.timepicker.clockManager&&this.timepicker.clockManager.setCircleClockClasses24h():this.timepicker.clockManager&&this.timepicker.clockManager.removeCircleClockClasses24h(),this.timepicker._options.mobile||this.timepicker.tipsWrapperFor24h?.classList.remove("timepicker-ui-tips-wrapper-24h-disabled")),s&&t)if(t.value=s.value.replace(/\D+/g,""),i&&r){r.classList.contains("timepicker-ui-am")||r.classList.contains("timepicker-ui-pm")||t.click()}else i&&t.click()};handleHourEvents=()=>{this.timepicker._inputEvents.forEach(e=>{const t=e=>{const t=e.target;null!==this.timepicker.clockFace&&this.timepicker.animationManager&&this.timepicker.animationManager.handleAnimationSwitchTipsMode(),"24h"===this.timepicker._options.clockType&&null!==this.timepicker.clockFace&&(Number(this.timepicker.hour.value)>12||"00"===this.timepicker.hour.value?this.timepicker.clockManager&&this.timepicker.clockManager.setCircleClockClasses24h():this.timepicker.clockManager&&this.timepicker.clockManager.removeCircleClockClasses24h(),this.timepicker._options.mobile||this.timepicker.tipsWrapperFor24h?.classList.remove("timepicker-ui-tips-wrapper-24h-disabled")),this.timepicker.clockManager&&this.timepicker.clockManager.setHoursToClock(t.value),this.timepicker.minutes.classList.remove(k),this.timepicker.hour.classList.add(k),"12h"===this.timepicker._options.clockType&&this.timepicker._options.disabledTime?.interval&&setTimeout(()=>{const e=this.timepicker.clockFacePool.acquire({clockFace:this.timepicker.clockFace,tipsWrapper:this.timepicker.tipsWrapper,disabledTime:this.timepicker._disabledTime?.value,clockType:this.timepicker._options.clockType,activeTypeMode:this.timepicker.activeTypeMode?.textContent||""});e.updateDisable(this.timepicker.hour.value,this.timepicker.activeTypeMode?.textContent||""),this.timepicker.clockFacePool.release(e)},300),r(this.timepicker._element,"","timepicker:select-hour",{hour:this.timepicker.hour.value,minutes:this.timepicker.minutes.value,type:this.timepicker.activeTypeMode?.dataset.type,degreesHours:this.timepicker._degreesHours,degreesMinutes:this.timepicker._degreesMinutes},this.timepicker._options.onSelectHour,this.timepicker),null!==this.timepicker.clockFace&&this.timepicker.circle.classList.remove("small-circle")};this.timepicker.hour?.addEventListener(e,t),this.cleanupHandlers.push(()=>{this.timepicker.hour?.removeEventListener(e,t)})});const e=e=>this.handleClasses24h(e,this.timepicker.hour,!0),t=e=>this.handleClasses24h(e,this.timepicker.hour,!1);this.timepicker.hour?.addEventListener("blur",e),this.timepicker.hour?.addEventListener("focus",t),this.cleanupHandlers.push(()=>{this.timepicker.hour?.removeEventListener("blur",e),this.timepicker.hour?.removeEventListener("focus",t)})};handleMinutesEvents=()=>{this.timepicker._inputEvents.forEach(e=>{const t=e=>{const t=e.target;null!==this.timepicker.clockFace&&(this.timepicker.animationManager&&this.timepicker.animationManager.handleAnimationSwitchTipsMode(),this.timepicker.clockManager&&this.timepicker.clockManager.setMinutesToClock(t.value)),"24h"===this.timepicker._options.clockType&&(this.timepicker.clockManager&&this.timepicker.clockManager.removeCircleClockClasses24h(),this.timepicker._options.mobile||this.timepicker.tipsWrapperFor24h?.classList.add("timepicker-ui-tips-wrapper-24h-disabled")),this.timepicker.hour.classList.remove(k),this.timepicker.minutes.classList.add(k),"12h"===this.timepicker._options.clockType&&this.timepicker._options.disabledTime?.interval&&setTimeout(()=>{const e=this.timepicker.clockFacePool.acquire({clockFace:this.timepicker.clockFace,tipsWrapper:this.timepicker.tipsWrapper,disabledTime:this.timepicker._disabledTime?.value,clockType:this.timepicker._options.clockType,activeTypeMode:this.timepicker.activeTypeMode?.textContent||""});e.updateDisable(this.timepicker.hour.value,this.timepicker.activeTypeMode?.textContent||""),this.timepicker.clockFacePool.release(e)},300),r(this.timepicker._element,"","timepicker:select-minute",{hour:this.timepicker.hour.value,minutes:this.timepicker.minutes.value,type:this.timepicker.activeTypeMode?.dataset.type,degreesHours:this.timepicker._degreesHours,degreesMinutes:this.timepicker._degreesMinutes},this.timepicker._options.onSelectMinute,this.timepicker)};this.timepicker.minutes.addEventListener(e,t),this.cleanupHandlers.push(()=>{this.timepicker.minutes?.removeEventListener(e,t)})});const e=e=>this.handleClasses24h(e,this.timepicker.minutes,!0),t=e=>this.handleClasses24h(e,this.timepicker.minutes,!1);this.timepicker.minutes?.addEventListener("blur",e),this.timepicker.minutes?.addEventListener("focus",t),this.cleanupHandlers.push(()=>{this.timepicker.minutes?.removeEventListener("blur",e),this.timepicker.minutes?.removeEventListener("focus",t)})}}class D{timepicker;constructor(e){this.timepicker=e}updateHandPosition=e=>{const{target:t,type:o}=e,c=t,{incrementMinutes:a,incrementHours:l}=this.timepicker._options;if(!i(e,this.timepicker.clockFace))return;const m=i(e,this.timepicker.clockFace),p=this.timepicker.clockFace.offsetWidth/2,h=m&&Math.atan2(m.y-p,m.x-p);if(null!==this.timepicker.minutesTips){this.timepicker.minutes.classList.add(k);let e,t=h&&n(Math.trunc(180*h/Math.PI)+90,a,6);if(void 0===t)return;if(t<0?(e=Math.round(360+t/6)%60,t=360+6*Math.round(t/6)):(e=Math.round(t/6)%60,t=6*Math.round(t/6)),this.timepicker?._disabledTime?.value?.isInterval){const t=e<=9?`0${e}`:`${e}`,i=this.timepicker.hour.value,s=this.timepicker.activeTypeMode?.textContent||"";if(!f(i,t,s,this.timepicker._disabledTime.value.intervals,this.timepicker._options.clockType))return}else{const t=this.timepicker._disabledTime?.value?.minutes;if(t&&Array.isArray(t)&&t.includes(e<=9?`0${e}`:`${e}`))return}this.timepicker.minutes.value=e>=10?`${e}`:`0${e}`,this.timepicker.minutes.setAttribute("aria-valuenow",this.timepicker.minutes.value),this.timepicker.clockHand.style.transform=`rotateZ(${t}deg)`,this.timepicker._degreesMinutes=t,this.timepicker.clockManager&&(this.timepicker.clockManager.toggleClassActiveToValueTips(this.timepicker.minutes.value),this.timepicker.clockManager.removeBgColorToCirleWithMinutesTips(),this.timepicker.clockManager.setBgColorToCircleWithMinutesTips()),L(this.timepicker.modalElement,`Minute ${this.timepicker.minutes.value}`),r(this.timepicker._element,"update","timepicker:update",{...T(this.timepicker.input,this.timepicker._options.clockType),degreesHours:this.timepicker._degreesHours,degreesMinutes:this.timepicker._degreesMinutes,eventType:o,type:this.timepicker.activeTypeMode?.dataset.type},this.timepicker._options.onUpdate,this.timepicker)}const u=e.touches,d=u?u[0]:void 0,v=u&&d?document.elementFromPoint(d.clientX,d.clientY):null;if(null!==this.timepicker.hourTips){this.timepicker.hour?.classList.add(k);const e="24h"===this.timepicker._options.clockType;let t=!1;if(e){const e=this.timepicker.clockFace.offsetWidth/2;t=(m?Math.sqrt(Math.pow(m.x-e,2)+Math.pow(m.y-e,2)):0)<.6*e}if(!s(v||c,"timepicker-ui-tips-disabled")&&(!e||!t)&&(s(v||c,"timepicker-ui-value-tips")||s(v||c,"timepicker-ui-tips-wrapper")||s(v||c,"timepicker-ui-value-tips-24h")||s(v||c,"timepicker-ui-tips-wrapper-24h"))){let e,t=h&&n(Math.trunc(180*h/Math.PI)+90,l,30);if(this.timepicker._degreesHours=t,void 0===t)return;if(t<0?(e=Math.round(360+t/30)%12,t=360+t):(e=Math.round(t/30)%12,(0===e||e>12)&&(e=12)),this.timepicker._disabledTime?.value?.isInterval){const t=e>9?`${e}`:`0${e}`,i=this.timepicker.activeTypeMode?.textContent||"";let s=!0;for(let e=0;e<60;e++){if(f(t,e<=9?`0${e}`:`${e}`,i,this.timepicker._disabledTime.value.intervals,this.timepicker._options.clockType)){s=!1;break}}if(s)return}else{const t=this.timepicker._disabledTime?.value?.hours;if(t&&Array.isArray(t)&&t.includes(e.toString()))return}this.timepicker.clockHand.style.transform=`rotateZ(${t}deg)`,this.timepicker.hour.value=e>9?`${e}`:`0${e}`,this.timepicker.hour.setAttribute("aria-valuenow",this.timepicker.hour.value),this.timepicker.clockManager&&(this.timepicker.clockManager.removeCircleClockClasses24h(),this.timepicker.clockManager.toggleClassActiveToValueTips(e)),L(this.timepicker.modalElement,`Hour ${this.timepicker.hour.value}`)}if(e&&!s(v||c,"timepicker-ui-tips-disabled")&&t&&(s(v||c,"timepicker-ui-value-tips-24h")||s(v||c,"timepicker-ui-tips-wrapper-24h")||s(v||c,"timepicker-ui-value-tips")||s(v||c,"timepicker-ui-tips-wrapper"))){let e,t=h&&n(Math.trunc(180*h/Math.PI)+90,l,30);if(this.timepicker._degreesHours=t,void 0===t)return;if(t<0?(e=Math.round(360+t/30)%24,t=360+t):(e=Math.round(t/30)+12,12===e&&(e="00")),this.timepicker._disabledTime?.value?.isInterval){const t="number"==typeof e?e<=9?`0${e}`:`${e}`:e;let i=!0;for(let e=0;e<60;e++){if(f(t,e<=9?`0${e}`:`${e}`,"",this.timepicker._disabledTime.value.intervals,this.timepicker._options.clockType)){i=!1;break}}if(i)return}else{const t=this.timepicker._disabledTime?.value?.hours;if(t&&Array.isArray(t)&&t.includes(e.toString()))return}this.timepicker.clockManager&&this.timepicker.clockManager.setCircleClockClasses24h(),this.timepicker.clockHand.style.transform=`rotateZ(${t}deg)`,this.timepicker.hour.value=`${e}`,this.timepicker.hour.setAttribute("aria-valuenow",this.timepicker.hour.value),this.timepicker.clockManager&&this.timepicker.clockManager.toggleClassActiveToValueTips(e),L(this.timepicker.modalElement,`Hour ${this.timepicker.hour.value}`)}r(this.timepicker._element,"","timepicker:update",{...T(this.timepicker.input,this.timepicker._options.clockType),degreesHours:this.timepicker._degreesHours,degreesMinutes:this.timepicker._degreesMinutes,eventType:o,type:this.timepicker.activeTypeMode?.dataset.type},this.timepicker._options.onUpdate,this.timepicker)}}}class ${timepicker;cleanupHandlers;constructor(e,t){this.timepicker=e,this.cleanupHandlers=t}handleOpenOnClick=()=>{this.timepicker.openElement.forEach(e=>{const t=()=>this.timepicker._eventsBundle();e?.addEventListener("click",t),this.cleanupHandlers.push(()=>{e?.removeEventListener("click",t)})})};handleOpenOnEnterFocus=()=>{const e=({target:e,key:t})=>{e.disabled||"Enter"===t&&this.timepicker.open()};this.timepicker.input.addEventListener("keydown",e),this.cleanupHandlers.push(()=>{this.timepicker.input.removeEventListener("keydown",e)})};handleClickOnHourMobile=()=>{document.addEventListener("mousedown",this.timepicker._eventsClickMobileHandler),document.addEventListener("touchstart",this.timepicker._eventsClickMobileHandler),this.cleanupHandlers.push(()=>{document.removeEventListener("mousedown",this.timepicker._eventsClickMobileHandler),document.removeEventListener("touchstart",this.timepicker._eventsClickMobileHandler)})};handlerClickHourMinutes=async e=>{if(!this.timepicker.modalElement)return;const{clockType:t,editable:i}=this.timepicker._options,r=e.target,n=y(this.timepicker.hour.value,"hour",t),o=y(this.timepicker.minutes.value,"minutes",t);i&&(s(r,"timepicker-ui-hour")||s(r,"timepicker-ui-minutes")?!1!==n&&!1!==o||(o||this.timepicker.minutes.classList.add("invalid-value"),n||this.timepicker.hour?.classList.add("invalid-value")):!0===n&&!0===o&&(o&&this.timepicker.minutes.classList.remove("invalid-value"),n&&this.timepicker.hour?.classList.remove("invalid-value")))};handleIconChangeView=async()=>{if(this.timepicker._options.enableSwitchIcon&&this.timepicker.configManager){const e=this.timepicker.configManager.handlerViewChange();/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)?(this.timepicker.keyboardClockIcon.addEventListener("touchstart",e),this.cleanupHandlers.push(()=>{this.timepicker.keyboardClockIcon?.removeEventListener("touchstart",e)})):(this.timepicker.keyboardClockIcon.addEventListener("click",e),this.cleanupHandlers.push(()=>{this.timepicker.keyboardClockIcon?.removeEventListener("click",e)}))}};handleKeyPress=e=>{if("Escape"===e.key&&this.timepicker.modalElement){const e=T(this.timepicker.input,this.timepicker._options.clockType);r(this.timepicker._element,"","timepicker:cancel",{...e,hourNotAccepted:this.timepicker.hour.value,minutesNotAccepted:this.timepicker.minutes.value,type:this.timepicker.activeTypeMode?.dataset.type,degreesHours:this.timepicker._degreesHours,degreesMinutes:this.timepicker._degreesMinutes},this.timepicker._options.onCancel,this.timepicker),this.timepicker.close()()}};handleEscClick=()=>{document.addEventListener("keydown",this.handleKeyPress),this.cleanupHandlers.push(()=>{document.removeEventListener("keydown",this.handleKeyPress)})};focusTrapHandler=()=>{setTimeout(()=>{const e=this.timepicker.wrapper?.querySelectorAll('div[tabindex="0"]:not([disabled])'),t=this.timepicker.wrapper?.querySelectorAll('input[tabindex="0"]:not([disabled])');if(!e||e.length<=0||t.length<=0)return;const i=[...t,...e],r=i[0],n=i[i.length-1];this.timepicker.wrapper.focus();const o=e=>{const{key:t,shiftKey:i,target:o}=e,c=o;if("Tab"===t&&(i?document.activeElement===r&&(n.focus(),e.preventDefault()):document.activeElement===n&&(r.focus(),e.preventDefault())),"ArrowUp"===t||"ArrowDown"===t||"ArrowLeft"===t||"ArrowRight"===t){const e=s(c,"timepicker-ui-value-tips")||s(c,"timepicker-ui-value-tips-24h"),i=s(c,"timepicker-ui-hour"),r=s(c,"timepicker-ui-minutes");if(e){const e=c.parentElement,i=s(e,"timepicker-ui-minutes-time"),r=s(e,"timepicker-ui-hour-time-12")||s(e,"timepicker-ui-hour-time-24");if(i){const e=parseInt(this.timepicker.minutes.value||"0");let i=e;"ArrowUp"===t||"ArrowRight"===t?i=e>=59?0:e+1:"ArrowDown"!==t&&"ArrowLeft"!==t||(i=e<=0?59:e-1);const s=i<10?`0${i}`:`${i}`,r=this.timepicker.hour.value,n=this.timepicker.activeTypeMode?.textContent||"";if(this.timepicker._disabledTime?.value?.isInterval&&this.timepicker._disabledTime?.value?.intervals){if(!f(r,s,n,this.timepicker._disabledTime.value.intervals,this.timepicker._options.clockType))return}this.timepicker.minutes.value=s,this.timepicker.minutes.setAttribute("aria-valuenow",this.timepicker.minutes.value),this.timepicker.clockManager&&(this.timepicker.clockManager.setTransformToCircleWithSwitchesMinutes(this.timepicker.minutes.value),this.timepicker.clockManager.toggleClassActiveToValueTips(i))}else if(r){const e=parseInt(this.timepicker.hour.value||"0"),i="24h"===this.timepicker._options.clockType,s=i?23:12,r=i?0:1;let n=e;"ArrowUp"===t||"ArrowRight"===t?n=e>=s?r:e+1:"ArrowDown"!==t&&"ArrowLeft"!==t||(n=e<=r?s:e-1);const o=n<10?`0${n}`:`${n}`,c=this.timepicker.activeTypeMode?.textContent||"";if(this.timepicker._disabledTime?.value?.isInterval&&this.timepicker._disabledTime?.value?.intervals){let e=!0;for(let t=0;t<60;t++){const i=t.toString().padStart(2,"0");if(f(o,i,c,this.timepicker._disabledTime.value.intervals,this.timepicker._options.clockType)){e=!1;break}}if(e)return}this.timepicker.hour.value=o,this.timepicker.hour.setAttribute("aria-valuenow",this.timepicker.hour.value),this.timepicker.clockManager&&(this.timepicker.clockManager.setTransformToCircleWithSwitchesHour(this.timepicker.hour.value),this.timepicker.clockManager.toggleClassActiveToValueTips(n))}}if(i||r){const e=parseInt(c.value)||0,s=i,r=s?"12h"===this.timepicker._options.clockType?12:23:59,n=s&&"12h"===this.timepicker._options.clockType?1:0;let o=e;"ArrowUp"===t?o=e>=r?n:e+1:"ArrowDown"===t&&(o=e<=n?r:e-1),c.value=o<10?`0${o}`:`${o}`,c.setAttribute("aria-valuenow",c.value)}}"a"!==t&&"A"!==t||!this.timepicker.AM||s(c,"timepicker-ui-hour")||s(c,"timepicker-ui-minutes")||this.timepicker.AM.click(),"p"!==t&&"P"!==t||!this.timepicker.PM||s(c,"timepicker-ui-hour")||s(c,"timepicker-ui-minutes")||this.timepicker.PM.click(),"Enter"===t&&(s(c,"timepicker-ui-minutes")&&this.timepicker.minutes.click(),s(c,"timepicker-ui-hour")&&this.timepicker.hour.click(),s(c,"timepicker-ui-am")&&this.timepicker.AM.click(),s(c,"timepicker-ui-pm")&&this.timepicker.PM.click(),s(c,"timepicker-ui-ok-btn")&&this.timepicker.okButton.click(),s(c,"timepicker-ui-cancel-btn")&&this.timepicker.cancelButton.click(),s(c,"timepicker-ui-keyboard-icon-wrapper")&&this.timepicker.keyboardClockIcon.click())};this.timepicker.wrapper.addEventListener("keydown",o),this.cleanupHandlers.push(()=>{this.timepicker.wrapper?.removeEventListener("keydown",o)})},100)}}class P{timepicker;cleanupHandlers;constructor(e,t){this.timepicker=e,this.cleanupHandlers=t}handleInlineAutoUpdate=()=>{if(!this.timepicker._options.inline?.enabled||!1===this.timepicker._options.inline.autoUpdate)return;const e=()=>{const e=this.timepicker.hour?.value,t=this.timepicker.minutes?.value,i=this.timepicker.activeTypeMode?.textContent;if(e&&t){let s="";if("24h"===this.timepicker._options.clockType){s=`${e.padStart(2,"0")}:${t.padStart(2,"0")}`}else{s=`${e}:${t.padStart(2,"0")} ${i||"AM"}`}if(this.timepicker.input){this.timepicker.input.value=s;const n=new Event("change",{bubbles:!0});this.timepicker.input.dispatchEvent(n),r(this.timepicker._element,"","timepicker:confirm",{hour:e,minutes:t,type:i,degreesHours:this.timepicker._degreesHours,degreesMinutes:this.timepicker._degreesMinutes},this.timepicker._options.onConfirm,this.timepicker)}}};["input","change"].forEach(t=>{const i=()=>setTimeout(e,50),s=()=>setTimeout(e,50);this.timepicker.hour?.addEventListener(t,i),this.timepicker.minutes?.addEventListener(t,s),this.cleanupHandlers.push(()=>{this.timepicker.hour?.removeEventListener(t,i),this.timepicker.minutes?.removeEventListener(t,s)})}),"24h"!==this.timepicker._options.clockType&&this.timepicker._clickTouchEvents.forEach(t=>{const i=()=>setTimeout(e,50),s=()=>setTimeout(e,50);this.timepicker.AM?.addEventListener(t,i),this.timepicker.PM?.addEventListener(t,s),this.cleanupHandlers.push(()=>{this.timepicker.AM?.removeEventListener(t,i),this.timepicker.PM?.removeEventListener(t,s)})});const t=()=>setTimeout(e,100);this.timepicker.clockFace?.addEventListener("click",t),this.cleanupHandlers.push(()=>{this.timepicker.clockFace?.removeEventListener("click",t)})}}class F{_cleanupHandlers=[];buttonHandlers;dragHandlers;typeModeHandlers;inputHandlers;clockHandPositionUpdater;miscHandlers;inlineHandlers;constructor(e){this.clockHandPositionUpdater=new D(e),this.dragHandlers=new H(e,this.clockHandPositionUpdater.updateHandPosition),this.buttonHandlers=new w(e,this._cleanupHandlers),this.typeModeHandlers=new I(e,this._cleanupHandlers),this.inputHandlers=new S(e,this._cleanupHandlers),this.miscHandlers=new $(e,this._cleanupHandlers),this.inlineHandlers=new P(e,this._cleanupHandlers)}destroy(){this._cleanupHandlers.forEach(e=>{try{e()}catch(e){console.error("EventManager cleanup error:",e)}}),this._cleanupHandlers=[],this.dragHandlers.cleanup()}handleOpenOnClick=()=>this.miscHandlers.handleOpenOnClick();handleOpenOnEnterFocus=()=>this.miscHandlers.handleOpenOnEnterFocus();handleCancelButton=()=>this.buttonHandlers.handleCancelButton();handleOkButton=()=>this.buttonHandlers.handleOkButton();handleBackdropClick=()=>this.buttonHandlers.handleBackdropClick();handleAmClick=()=>this.typeModeHandlers.handleAmClick();handlePmClick=()=>this.typeModeHandlers.handlePmClick();handleHourEvents=()=>this.inputHandlers.handleHourEvents();handleMinutesEvents=()=>this.inputHandlers.handleMinutesEvents();handleEventToMoveHand=e=>this.dragHandlers.handleEventToMoveHand(e);handleMoveHand=()=>this.dragHandlers.handleMoveHand();handleClickOnHourMobile=()=>this.miscHandlers.handleClickOnHourMobile();handlerClickHourMinutes=e=>this.miscHandlers.handlerClickHourMinutes(e);handleIconChangeView=()=>this.miscHandlers.handleIconChangeView();handleEscClick=()=>this.miscHandlers.handleEscClick();focusTrapHandler=()=>this.miscHandlers.focusTrapHandler();handleInlineAutoUpdate=()=>this.inlineHandlers.handleInlineAutoUpdate();get _isDragging(){return this.dragHandlers.isDragging}get _animationFrameId(){return this.dragHandlers.animationFrameId}_onDragStart=e=>this.dragHandlers._onDragStart(e);_onDragMove=e=>this.dragHandlers._onDragMove(e);_onDragEnd=e=>this.dragHandlers._onDragEnd(e)}class x{timepicker;timeouts=[];originalOverflow;originalPaddingRight;constructor(e){this.timepicker=e}runWithTimeout(e,t=300){const i=setTimeout(e,t);this.timeouts.push(i)}clearAllTimeouts(){this.timeouts.forEach(clearTimeout),this.timeouts=[]}clearExistingModal(){const e=document.querySelector(".timepicker-ui-modal");e&&e.remove()}setModalTemplate=()=>{if(!this.timepicker._options)return;if(this.clearExistingModal(),this.timepicker._options.inline?.enabled){const e=document.getElementById(this.timepicker._options.inline.containerId);if(!e)return;e.innerHTML="",e.insertAdjacentHTML("beforeend",this.timepicker.modalTemplate);const t=e.querySelector(".timepicker-ui-modal");if(t){t.classList.add("timepicker-ui--inline");const{showButtons:e}=this.timepicker._options.inline;!1!==e&&void 0!==e||t.querySelectorAll(".timepicker-ui-wrapper-btn, .timepicker-ui-wrapper-btn.mobile").forEach(e=>e.style.display="none")}return}const{appendModalSelector:e}=this.timepicker._options;if(e){const t=document.querySelector(e);t?.insertAdjacentHTML("beforeend",this.timepicker.modalTemplate)}else document.body.insertAdjacentHTML("beforeend",this.timepicker.modalTemplate)};setScrollbarOrNot=()=>{this.timepicker._options.inline?.enabled||(this.timepicker._options.enableScrollbar?this.runWithTimeout(()=>{document.body.style.overflowY=this.originalOverflow||"",document.body.style.paddingRight=this.originalPaddingRight||""},400):(this.originalOverflow=document.body.style.overflowY,this.originalPaddingRight=document.body.style.paddingRight,document.body.style.paddingRight=`${(()=>{const e=document.createElement("div");e.className="timepicker-ui-measure",document.body.appendChild(e);const t=e.getBoundingClientRect().width-e.clientWidth;return document.body.removeChild(e),t})()}px`,document.body.style.overflowY="hidden"))};removeBackdrop=()=>{this.timepicker._options.inline?.enabled||this.timepicker._options.backdrop||(this.timepicker.modalElement?.classList.add("removed"),this.timepicker.openElement.forEach(e=>e?.classList.add("disabled")))};setNormalizeClass=()=>{const e=this.timepicker.modalElement;if(!e)return;e.classList.add("timepicker-ui-normalize");e.querySelectorAll(":scope > div").forEach(e=>e.classList.add("timepicker-ui-normalize"))};setShowClassToBackdrop=()=>{this.timepicker._options.inline?.enabled?this.timepicker.modalElement?.classList.add("show"):this.timepicker._options.backdrop&&this.runWithTimeout(()=>{this.timepicker.modalElement?.classList.add("show")},300)};setFlexEndToFooterIfNoKeyboardIcon=()=>{!this.timepicker._options.enableSwitchIcon&&this.timepicker.footer&&(this.timepicker.footer.style.justifyContent="flex-end")};destroy(){this.clearAllTimeouts(),this.timepicker._options.inline?.enabled||(document.body.style.overflowY=this.originalOverflow||"",document.body.style.paddingRight=this.originalPaddingRight||""),this.clearExistingModal()}}const N=150,O=600,W=401;class q{timepicker;timeouts=[];constructor(e){this.timepicker=e}runWithAnimation(e,t=N){if(this.timepicker._options.animation){const i=setTimeout(e,t);this.timeouts.push(i)}else e()}clearAllTimeouts(){this.timeouts.forEach(clearTimeout),this.timeouts=[]}setAnimationToOpen(){this.clearAllTimeouts(),this.timepicker.modalElement?.classList.add("opacity"),this.runWithAnimation(()=>{this.timepicker.modalElement?.classList.add("show")})}removeAnimationToClose(){this.clearAllTimeouts(),this.timepicker.modalElement&&this.runWithAnimation(()=>{this.timepicker.modalElement?.classList.remove("show"),this.timepicker.modalElement?.classList.remove("opacity")})}handleAnimationClock(){this.timepicker._options.animation&&this.runWithAnimation(()=>{this.timepicker.clockFace?.classList.add("timepicker-ui-clock-animation");const e=setTimeout(()=>{this.timepicker.clockFace?.classList.remove("timepicker-ui-clock-animation")},O);this.timeouts.push(e)})}handleAnimationSwitchTipsMode(){const{clockHand:e}=this.timepicker;if(!e)return;e.classList.add("timepicker-ui-tips-animation");const t=setTimeout(()=>{e.classList.remove("timepicker-ui-tips-animation")},W);this.timeouts.push(t)}destroy(){this.clearAllTimeouts()}}class U{timepicker;constructor(e){this.timepicker=e}removeCircleClockClasses24h(){this.timepicker.circle?.classList.remove("timepicker-ui-circle-hand-24h"),this.timepicker.clockHand?.classList.remove("timepicker-ui-clock-hand-24h")}setCircleClockClasses24h(){this.timepicker.circle&&this.timepicker.circle?.classList.add("timepicker-ui-circle-hand-24h"),this.timepicker.clockHand&&this.timepicker.clockHand?.classList.add("timepicker-ui-clock-hand-24h")}setOnStartCSSClassesIfClockType24h(){if("24h"===this.timepicker._options.clockType){const e=this.timepicker?.configManager?.getInputValue(this.timepicker.input,this.timepicker._options.clockType,this.timepicker._options.currentTime);let t=e?.hour;this.timepicker.input.value.length>0&&(t=this.timepicker.input.value.split(":")[0]),(Number(t)>12||0===Number(t))&&this.setCircleClockClasses24h()}}setBgColorToCircleWithMinutesTips=()=>{if(this.timepicker.minutes.value&&M.includes(this.timepicker.minutes.value)){const e=getComputedStyle(this.timepicker.circle).getPropertyValue("--timepicker-primary").trim();e&&(this.timepicker.circle.style.backgroundColor=e),this.timepicker.circle.classList.remove("small-circle")}};removeBgColorToCirleWithMinutesTips=()=>{this.timepicker.minutes.value&&M.includes(this.timepicker.minutes.value)||(this.timepicker.circle.style.backgroundColor="",this.timepicker.circle.classList.add("small-circle"))};setClassActiveToHourOnOpen=()=>{this.timepicker._options.mobile||this.timepicker._isMobileView||this.timepicker.hour?.classList.add(k)};setMinutesToClock=e=>{null!==this.timepicker.clockFace&&this.setTransformToCircleWithSwitchesMinutes(e),this.removeBgColorToCirleWithMinutesTips();const t=this.timepicker._disabledTime?.value||null,i=this.timepicker.clockFacePool.acquire({array:M,classToAdd:"timepicker-ui-minutes-time",clockFace:this.timepicker.clockFace,tipsWrapper:this.timepicker.tipsWrapper,theme:this.timepicker._options.theme,disabledTime:t,hour:this.timepicker.hour.value,clockType:this.timepicker._options.clockType});i.create(),"12h"===this.timepicker._options.clockType&&i.updateDisable(),this.timepicker.clockFacePool.release(i),this.toggleClassActiveToValueTips(e),"24h"===this.timepicker._options.clockType&&(this.timepicker.tipsWrapperFor24h.innerHTML="")};setHoursToClock=e=>{if(null!==this.timepicker.clockFace){this.setTransformToCircleWithSwitchesHour(e);const t=this.timepicker._disabledTime?.value||null,i=this.timepicker.clockFacePool.acquire({array:g,classToAdd:"timepicker-ui-hour-time-12",clockFace:this.timepicker.clockFace,tipsWrapper:this.timepicker.tipsWrapper,theme:this.timepicker._options.theme,disabledTime:t,clockType:"12h",hour:this.timepicker.hour.value});if(i.create(),"24h"===this.timepicker._options.clockType){const e=this.timepicker.clockFacePool.acquire({array:v,classToAdd:"timepicker-ui-hour-time-24",clockFace:this.timepicker.tipsWrapperFor24h,tipsWrapper:this.timepicker.tipsWrapperFor24h,theme:this.timepicker._options.theme,clockType:"24h",disabledTime:t,hour:this.timepicker.hour.value});e.create(),this.timepicker.clockFacePool.release(e)}else i.updateDisable();this.timepicker.clockFacePool.release(i),this.toggleClassActiveToValueTips(e)}};setTransformToCircleWithSwitchesHour=e=>{if(!this.timepicker.clockHand)return;const t=Number(e);let i=t>12?30*t-360:30*t;360===i&&(i=0),i>360||(this.timepicker.clockHand.style.transform=`rotateZ(${i}deg)`)};setTransformToCircleWithSwitchesMinutes=e=>{if(!this.timepicker.clockHand)return;const t=6*Number(e);t>360||(this.timepicker.clockHand.style.transform=`rotateZ(${t}deg)`)};toggleClassActiveToValueTips=e=>{const t=this.timepicker.allValueTips.find(t=>Number(t.innerText)===Number(e));this.timepicker.allValueTips.map(e=>{e.classList.remove(k),e.setAttribute("aria-selected","false")}),void 0!==t&&(t.classList.add(k),t.setAttribute("aria-selected","true"))}}class B{timepicker;constructor(e){this.timepicker=e}setErrorHandler(){const e=this.timepicker.input;if(!e)return;const{error:t,currentHour:i,currentMin:s,currentType:n,currentLength:o}=T(e,this.timepicker._options.clockType);if(this.removeErrorHandler(),t){const c=document.createElement("div");return c.classList.add("timepicker-ui-invalid-text"),c.innerHTML="<b>Invalid Time Format</b>",e.classList.add("timepicker-ui-invalid-format"),e.nextElementSibling?.classList.contains("timepicker-ui-invalid-text")||e.after(c),r(this.timepicker._element,"","timepicker:error",{error:t,currentHour:i,currentMin:s,currentType:n,currentLength:o},this.timepicker._options.onError,this.timepicker),console.error(`Invalid Time Format: ${t}`),!1}return!0}removeErrorHandler(){const e=this.timepicker.input;if(!e)return;e.classList.remove("timepicker-ui-invalid-format");const t=e.nextElementSibling;t?.classList.contains("timepicker-ui-invalid-text")&&t.remove()}checkDisabledValuesOnStart(){if(!this.timepicker._options.disabledTime)return;const{disabledTime:e,clockType:t}=this.timepicker._options;if(e.interval){if(!t)throw new Error("clockType is required when using disabledTime.interval");const i=Array.isArray(e.interval)?e.interval:[e.interval];try{p(i,t)}catch(e){throw new Error(`Invalid disabledTime.interval: ${e.message}`)}return}const{hours:i,minutes:s}=e,r=!i||b(i,"hour",t),n=!s||b(s,"minutes",t);if(!r||!n)throw new Error("You set wrong hours or minutes in disabled option")}destroy(){this.removeErrorHandler()}}const V={"crane-straight":["crane-straight"],"crane-radius":["crane-straight","radius"],m3:["m3"],dark:["dark"],glassmorphic:["glassmorphic"],pastel:["pastel"],ai:["ai"],cyberpunk:["cyberpunk"],custom:["custom"]};class z{timepicker;constructor(e){this.timepicker=e}setTheme=()=>{const e=this.timepicker.modalElement;if(!e||!this.timepicker._options)return;const{theme:t}=this.timepicker._options;if(!t||!V[t])return;e.querySelectorAll("input, div").forEach(e=>{Object.values(V).forEach(t=>e.classList.remove(...t)),e.classList.add(...V[t])})};setInputClassToInputElement=()=>{const e=this.timepicker.input;e&&(s(e,"timepicker-ui-input")||e.classList.add("timepicker-ui-input"))};setDataOpenToInputIfDoesntExistInWrapper=()=>{null===this.timepicker.openElementData&&this.timepicker.input&&this.timepicker.input.setAttribute("data-open","timepicker-ui-input")};setClassTopOpenElement=()=>{for(const e of this.timepicker.openElement)e&&e.classList.add("timepicker-ui-open-element")};setTimepickerClassToElement=()=>{const e=this.timepicker._element;if(!e)return;e.classList.add(u);const t=this.timepicker._options?.cssClass;t&&t!==u&&e.classList.add(t)};destroy(){const e=this.timepicker.modalElement;if(!e)return;e.querySelectorAll("input, div").forEach(e=>{Object.values(V).forEach(t=>e.classList.remove(...t))})}}class R{timepicker;timeouts=[];debouncedHandler;constructor(e){this.timepicker=e}clearAllTimeouts(){this.timeouts.forEach(clearTimeout),this.timeouts=[]}runWithTimeout(e,t){const i=setTimeout(e,t);this.timeouts.push(i)}isCurrentTimeEnabled(e){const t=this.timepicker._options?.currentTime;return"boolean"==typeof t?t:!!t?.[e]}preventClockTypeByCurrentTime=()=>{if(!this.isCurrentTimeEnabled("preventClockType"))return;const{currentTime:e,clockType:t}=this.timepicker._options,{type:i}=T(this.timepicker.input,t,e,!0);this.timepicker._options.clockType=i?"12h":"24h"};updateInputValueWithCurrentTimeOnStart=()=>{if(!this.isCurrentTimeEnabled("updateInput"))return;const{hour:e,minutes:t,type:i}=T(this.timepicker.input,this.timepicker._options.clockType,this.timepicker._options.currentTime);this.timepicker.input.value=i?`${e}:${t} ${i}`:`${e}:${t}`};checkMobileOption(){this.timepicker._isMobileView=!!this.timepicker._options.mobile,this.timepicker._options.mobile&&(this.timepicker._options.editable=!0)}getDisableTime(){const e=(e=>{if(!e)return;const{disabledTime:t,clockType:i}=e;if(!t||Object.keys(t).length<=0||"Object"!==t.constructor.name)return;const{hours:s,minutes:r,interval:n}=t;if(n){delete t.hours,delete t.minutes;const e=Array.isArray(n)?n:[n];if(!i)throw new Error("clockType is required when using disabledTime.interval");try{p(e,i)}catch(e){throw e}return{value:e.map(e=>{const[t,s]=e.trim().split("-"),{hour:r,minutes:n,type:a}=T({value:t.trim()},i),{hour:l,minutes:m,type:p}=T({value:s.trim()},i);let h=o(r,l).map(e=>"00"===e||0===Number(e)?`0${Number(e)}`:`${Number(e)}`);const u=[],d=Number(n),k=Number(m);if(p===a)return d>0&&k<=0?(u.push(h[0],h[h.length-1]),h=h.slice(1,-1)):k<59&&k>0&&d<=0?(u.push(void 0,h[h.length-1]),h=h.slice(0,-1)):k>0&&d>0?(u.push(h[0],h[h.length-1]),h=h.slice(1,-1)):0===k&&0===d&&(u.push(void 0,h[h.length-1]),h.pop()),{removedStartedHour:void 0!==u[0]&&Number(u[0])<=9?`0${u[0]}`:u[0],removedEndHour:void 0!==u[1]&&Number(u[1])<=9?`0${u[1]}`:u[1],rangeArrHour:h,startMinutes:o(n,59).map(e=>Number(e)<=9?`0${e}`:`${e}`),endMinutes:c(0,m).map(e=>Number(e)<=9?`0${e}`:`${e}`),startType:a,endType:p};{const e=o(r,12).map(String),t=c(1,l).map(String),i=[],s=[];return d>0&&k<=0?(s.push(t[t.length-1]),i.push(e[0]),t.pop(),e.shift()):k<59&&k>0&&d<=0?(i.push(e[0]),s.push(t[t.length-1]),t.pop()):k>0&&d>0?(s.push(t[t.length-1]),i.push(e[0]),t.pop(),e.shift()):0===k&&0===d&&(s.push(t[t.length-1]),i.push(e[0]),t.pop()),{startType:a,endType:p,amHours:e,pmHours:t,removedAmHour:i[0]&&Number(i[0])<=9?`0${i[0]}`:i[0],removedPmHour:s[0]&&Number(s[0])<=9?`0${s[0]}`:s[0],startMinutes:0===Number(n)?[]:o(n,59).map(e=>Number(e)<=9?`0${e}`:`${e}`),endMinutes:c(0,m).map(e=>Number(e)<=9?`0${e}`:`${e}`)}}}).reduce((e,t)=>(Object.entries(t).forEach(([t,i])=>{Array.isArray(i)?e[t]=Array.isArray(e[t])?[...e[t],...i]:[...i]:e[t]=i}),e),{isInterval:!0,clockType:i,intervals:e})}}return s?.forEach(e=>{if("12h"===i&&Number(e)>12)throw new Error("The disabled hours value has to be less than 13");if("24h"===i&&Number(e)>23)throw new Error("The disabled hours value has to be less than 24")}),r?.forEach(e=>{if(Number(e)>59)throw new Error("The disabled minutes value has to be less than 60")}),{value:{hours:s?.map(e=>"00"===e||0===Number(e)?`0${Number(e)}`:`${Number(e)}`),minutes:r?.map(e=>Number(e)<=9?`0${e}`:`${e}`)}}})(this.timepicker._options);this.timepicker._disabledTime=e||null}getInputValueOnOpenAndSet=()=>{const e=T(this.timepicker.input,this.timepicker._options.clockType,this.timepicker._options.currentTime);if(void 0===e)return this.timepicker.hour.value="12",this.timepicker.minutes.value="00",r(this.timepicker._element,"show","timepicker:open",{hour:this.timepicker.hour.value,minutes:this.timepicker.minutes.value,type:this.timepicker.activeTypeMode?.dataset.type,degreesHours:this.timepicker._degreesHours,degreesMinutes:this.timepicker._degreesMinutes},this.timepicker._options.onOpen),void("24h"!==this.timepicker._options.clockType&&this.timepicker.AM.classList.add(k));let[t,i,s]=this.timepicker.input.value.split(":").join(" ").split(" ");0===this.timepicker.input.value.length&&(t=e.hour,i=e.minutes,s=e.type),this.timepicker.hour.value=t,this.timepicker.minutes.value=i;const n=this.timepicker.modalElement?.querySelector(`[data-type='${s}']`);"24h"!==this.timepicker._options.clockType&&n&&n.classList.add(k),r(this.timepicker._element,"show","timepicker:open",{...e,type:this.timepicker.activeTypeMode?.dataset.type,degreesHours:this.timepicker._degreesHours,degreesMinutes:this.timepicker._degreesMinutes},this.timepicker._options.onOpen)};handleModeSwitch(e){this.clearAllTimeouts();const t=this.timepicker.hour.value,i=this.timepicker.minutes.value,s=this.timepicker.activeTypeMode?.dataset.type;this.timepicker.close()(),this.timepicker._isMobileView=e,this.timepicker._options.mobile=e,this.runWithTimeout(()=>{this.timepicker.update({options:{mobile:e}}),this.runWithTimeout(()=>{if(this.timepicker.open(),this.timepicker.hour.value=t,this.timepicker.minutes.value=i,"12h"===this.timepicker._options.clockType){const e="PM"===s?"PM":"AM",t="PM"===s?"AM":"PM";this.timepicker[e].classList.add(k),this.timepicker[t].classList.remove(k)}this.timepicker.clockManager&&(this.timepicker.clockManager.setTransformToCircleWithSwitchesHour(this.timepicker.hour.value),this.timepicker.clockManager.toggleClassActiveToValueTips(this.timepicker.hour.value),Number(this.timepicker.hour.value)>12||0===Number(this.timepicker.hour.value)?this.timepicker.clockManager.setCircleClockClasses24h():this.timepicker.clockManager.removeCircleClockClasses24h())},300)},300)}handlerViewChange=()=>{const e=this.timepicker._options.delayHandler||300;return this.debouncedHandler=h(()=>{const{clockType:e}=this.timepicker._options;if(this.timepicker.modalElement?.classList.contains("mobile")){const t=y(this.timepicker.hour.value,"hour",e),i=y(this.timepicker.minutes.value,"minutes",e);if(!t||!i)return i||this.timepicker.minutes.classList.add("invalid-value"),void(t||this.timepicker.hour.classList.add("invalid-value"));this.timepicker.minutes.classList.remove("invalid-value"),this.timepicker.hour.classList.remove("invalid-value"),this.handleModeSwitch(!1)}else this.handleModeSwitch(!0)},e),this.debouncedHandler};getInputValue=T;destroy(){this.clearAllTimeouts(),this.debouncedHandler&&"cancel"in this.debouncedHandler&&this.debouncedHandler.cancel?.()}}class j{events=new Map;on(e,t){this.events.has(e)||this.events.set(e,new Set),this.events.get(e).add(t)}once(e,t){const i=s=>{t(s),this.off(e,i)};this.on(e,i)}off(e,t){t?this.events.get(e)?.delete(t):this.events.delete(e)}emit(e,t){this.events.get(e)?.forEach(i=>{try{i(t)}catch(t){console.error(`EventEmitter: Error in handler for "${String(e)}":`,t)}})}clear(){this.events.clear()}hasListeners(e){return(this.events.get(e)?.size??0)>0}}class Y{_degreesHours=null;_degreesMinutes=null;_options;_eventsClickMobile=()=>Promise.resolve();_eventsClickMobileHandler=()=>{};_mutliEventsMove=()=>{};_mutliEventsMoveHandler;_clickTouchEvents;_element;_instanceId;_isMobileView;_isTouchMouseMove;_disabledTime;_cloned;_inputEvents;_isModalRemove;_isInitialized=!1;_customId;_eventHandlersRegistered=!1;_isDestroyed=!1;_pendingThemeConfig;clockFacePool;eventManager;modalManager;animationManager;clockManager;validationManager;themeManager;configManager;_eventEmitter;constructor(e,i){if("undefined"==typeof window)throw new Error("TimepickerUI: Cannot initialize in non-browser environment (SSR/Node.js)");this._eventEmitter=new j;const s=i?.id;this._customId=s,this._instanceId=s||`timepicker-ui-${"undefined"!=typeof window&&window.crypto&&"function"==typeof window.crypto.randomUUID?window.crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)})}`;let r=null;if("string"==typeof e){if(r=document.querySelector(e),!r)return console.error(`TimepickerUI: Element with selector "${e}" not found`),void(this._isDestroyed=!0)}else{if(!(e instanceof HTMLElement))return console.error("TimepickerUI: First parameter must be a string selector or HTMLElement"),void(this._isDestroyed=!0);r=e}let n=null;if(n="INPUT"===r.tagName?r:r.querySelector("input"),!n){throw new Error(`TimepickerUI: No input element found for ${"string"==typeof e?`selector "${e}"`:"provided element"}`)}if("INPUT"===r.tagName){const e=document.createElement("div");e.className="timepicker-ui",r.parentNode?.insertBefore(e,r),e.appendChild(r),this._element=e}else this._element=r,this._element.classList.contains("timepicker-ui")||this._element.classList.add("timepicker-ui");this._cloned=null;const o=(e=>{if(!e)return;const t=JSON.parse(JSON.stringify(e)),i=Object.keys(t);return Object.values(t).reduce((e,t,s)=>(Number(t)?e[i[s]]=Number(t):e[i[s]]="true"===t||"false"===t?JSON.parse(t):t,e),{})})(this._element?.dataset);if(this._options={...t({..._,...i,...o},_)},this._options.inline?.enabled&&void 0===i?.focusTrap&&(this._options.focusTrap=!1),this._isTouchMouseMove=!1,this._degreesHours=30*Number(T(this._element?.querySelector("input"),this._options.clockType).hour),this._degreesMinutes=6*Number(T(this._element?.querySelector("input"),this._options.clockType).minutes),this._isMobileView=!1,this._mutliEventsMove=e=>this.eventManager.handleEventToMoveHand(e),this._mutliEventsMoveHandler=this._mutliEventsMove.bind(this),this._eventsClickMobile=e=>this.eventManager.handlerClickHourMinutes(e),this._eventsClickMobileHandler=this._eventsClickMobile.bind(this),this.clockFacePool=new C,this.eventManager=new F(this),this.modalManager=new x(this),this.animationManager=new q(this),this.clockManager=new U(this),this.validationManager=new B(this),this.themeManager=new z(this),this.configManager=new R(this),this.configManager.checkMobileOption(),this._clickTouchEvents=["click","mousedown","touchstart"],this._inputEvents=["change",...this._clickTouchEvents],this._disabledTime=null,this.configManager.preventClockTypeByCurrentTime(),this._isModalRemove=!0,this._isInitialized=!1,this._options.inline?.enabled){if(!this._options.inline.containerId)throw console.error("TimepickerUI: containerId is required when inline mode is enabled"),new Error("TimepickerUI: containerId is required when inline mode is enabled");if(!document.getElementById(this._options.inline.containerId))throw console.error(`TimepickerUI: Container element with ID "${this._options.inline.containerId}" not found`),new Error(`TimepickerUI: Container element with ID "${this._options.inline.containerId}" not found`)}}get modalTemplate(){const{getMobileModalTemplate:e,getModalTemplate:t}=require("../utils/template");return this._options.mobile&&this._isMobileView?e(this._options,this._instanceId):t(this._options,this._instanceId)}get modalElement(){return document.querySelector(`[data-owner-id="${this._instanceId}"]`)}get clockFace(){return this.modalElement?.querySelector(".timepicker-ui-clock-face")}get input(){return this._element?.querySelector("input")}get clockHand(){return this.modalElement?.querySelector(".timepicker-ui-clock-hand")}get circle(){return this.modalElement?.querySelector(".timepicker-ui-circle-hand")}get tipsWrapper(){return this.modalElement?.querySelector(".timepicker-ui-tips-wrapper")}get tipsWrapperFor24h(){return this.modalElement?.querySelector(".timepicker-ui-tips-wrapper-24h")}get minutes(){return this.modalElement?.querySelector(".timepicker-ui-minutes")}get hour(){return this.modalElement?.querySelector(".timepicker-ui-hour")}get AM(){return this.modalElement?.querySelector(".timepicker-ui-am")}get PM(){return this.modalElement?.querySelector(".timepicker-ui-pm")}get minutesTips(){return this.modalElement?.querySelector(".timepicker-ui-minutes-time")}get hourTips(){return this.modalElement?.querySelector(".timepicker-ui-hour-time-12")}get allValueTips(){const e=this.modalElement;return e?[...e.querySelectorAll(".timepicker-ui-value-tips"),...e.querySelectorAll(".timepicker-ui-value-tips-24h")]:[]}get openElementData(){const e=this._element?.querySelectorAll("[data-open]");if(e?.length>0){const t=[];return e.forEach(({dataset:e})=>t.push(e.open??"")),[...new Set(t)]}return null}get openElement(){return null===this.openElementData?(this.input?.setAttribute("data-open","timepicker-ui-input"),[this.input]):this.openElementData.map(e=>this._element?.querySelectorAll(`[data-open='${e}']`))[0]??""}get cancelButton(){return this.modalElement?.querySelector(".timepicker-ui-cancel-btn")}get okButton(){return this.modalElement?.querySelector(".timepicker-ui-ok-btn")}get activeTypeMode(){return this.modalElement?.querySelector(".timepicker-ui-type-mode.active")}get keyboardClockIcon(){return this.modalElement?.querySelector(".timepicker-ui-keyboard-icon-wrapper")}get footer(){return this.modalElement?.querySelector(".timepicker-ui-footer")}get wrapper(){return this.modalElement?.querySelector(".timepicker-ui-wrapper")}getElement(){return this._element}on(e,t){this._isDestroyed?console.warn("TimepickerUI: Cannot add event listener - instance failed to initialize"):this._eventEmitter.on(e,t)}once(e,t){this._isDestroyed?console.warn("TimepickerUI: Cannot add event listener - instance failed to initialize"):this._eventEmitter.once(e,t)}off(e,t){this._isDestroyed?console.warn("TimepickerUI: Cannot remove event listener - instance failed to initialize"):this._eventEmitter.off(e,t)}emit(e,t){this._eventEmitter.emit(e,t)}_applyThemeToWrapper(e){if(!this._pendingThemeConfig)return;const t={primaryColor:"--timepicker-primary",backgroundColor:"--timepicker-bg",surfaceColor:"--timepicker-surface",surfaceHoverColor:"--timepicker-surface-hover",textColor:"--timepicker-text",secondaryTextColor:"--timepicker-secondary-text",disabledTextColor:"--timepicker-disabled-text",onPrimaryColor:"--timepicker-on-primary",borderColor:"--timepicker-border",shadow:"--timepicker-shadow",borderRadius:"--timepicker-border-radius",fontFamily:"--timepicker-font-family"};Object.entries(this._pendingThemeConfig).forEach(([i,s])=>{s&&t[i]&&e.style.setProperty(t[i],s)})}}class Z extends Y{create=()=>{this._isDestroyed?console.warn("TimepickerUI: Cannot create - instance failed to initialize"):this._isInitialized?console.warn("TimepickerUI: Instance is already initialized"):(this.configManager.updateInputValueWithCurrentTimeOnStart(),this.validationManager.checkDisabledValuesOnStart(),this.themeManager.setTimepickerClassToElement(),this.themeManager.setInputClassToInputElement(),this.themeManager.setDataOpenToInputIfDoesntExistInWrapper(),this.themeManager.setClassTopOpenElement(),this._options.inline?.enabled?(this.eventManager.handleOpenOnEnterFocus(),this._eventsBundle()):(this.eventManager.handleOpenOnEnterFocus(),this.eventManager.handleOpenOnClick()),this.configManager.getDisableTime(),this._isInitialized=!0)};open=e=>{this._isDestroyed?console.warn("TimepickerUI: Cannot open - instance failed to initialize"):(this._isInitialized||this.create(),this._eventsBundle(),a(e))};close=()=>h((...e)=>{if(e.length>2||!this.modalElement)return;const[t]=e.filter(e=>"boolean"==typeof e),[i]=e.filter(e=>"function"==typeof e);t&&(this.eventManager.handleOkButton(),this.okButton?.click()),this._isTouchMouseMove=!1,document.removeEventListener("mousedown",this.eventManager._onDragStart,!1),document.removeEventListener("touchstart",this.eventManager._onDragStart),document.removeEventListener("mousemove",this.eventManager._onDragMove,!1),document.removeEventListener("mouseup",this.eventManager._onDragEnd,!1),document.removeEventListener("touchmove",this.eventManager._onDragMove),document.removeEventListener("touchend",this.eventManager._onDragEnd,!1),document.removeEventListener("mouseleave",this.eventManager._onDragEnd,!1),document.removeEventListener("mousedown",this._eventsClickMobileHandler),document.removeEventListener("touchstart",this._eventsClickMobileHandler),document.removeEventListener("keypress",this.eventManager.handleEscClick),this.wrapper.removeEventListener("keydown",this.eventManager.focusTrapHandler),this._options.enableSwitchIcon&&(this.keyboardClockIcon.removeEventListener("touchstart",this.configManager.handlerViewChange()),this.keyboardClockIcon.removeEventListener("mousedown",this.configManager.handlerViewChange())),this.animationManager.removeAnimationToClose(),this.openElement.forEach(e=>e?.classList.remove("disabled")),setTimeout(()=>{document.body.style.overflowY="",document.body.style.paddingRight=""},400),this.openElement.forEach(e=>e?.classList.remove("disabled")),setTimeout(()=>{this._options.focusInputAfterCloseModal&&this.input?.focus(),null!==this.modalElement&&(this.modalElement.remove(),this._isModalRemove=!0)},300),a(i)},this._options.delayHandler||300);destroy=e=>{if(this._isDestroyed)return void console.warn("TimepickerUI: Instance is already destroyed");const t="function"==typeof e?{callback:e}:e||{},{keepInputValue:i=!1,callback:s}=t,r=i?this.input?.value:null;this.clockFacePool.clear(),d.split(" ").forEach(e=>{document.removeEventListener(e,this._mutliEventsMoveHandler,!1)}),document.removeEventListener("mousedown",this.eventManager._onDragStart,!1),document.removeEventListener("touchstart",this.eventManager._onDragStart),document.removeEventListener("mousemove",this.eventManager._onDragMove,!1),document.removeEventListener("mouseup",this.eventManager._onDragEnd,!1),document.removeEventListener("touchmove",this.eventManager._onDragMove),document.removeEventListener("touchend",this.eventManager._onDragEnd,!1),document.removeEventListener("mouseleave",this.eventManager._onDragEnd,!1),document.removeEventListener("mousedown",this._eventsClickMobileHandler),document.removeEventListener("touchstart",this._eventsClickMobileHandler),this.modalElement?.remove(),this.openElement?.forEach(e=>{e&&(e.classList.remove("disabled","active","timepicker-ui-open-element"),e.classList.remove("basic","crane-straight","crane-radius","m3"))}),this.input&&(this.input.classList.remove("timepicker-ui-invalid-format","invalid-value","error","active","timepicker-ui-input"),this.input.removeAttribute("data-open"),this.input.removeAttribute("data-owner-id"),i&&null!==r&&(this.input.value=r)),this._element&&(this._element.classList.remove("basic","crane-straight","crane-radius","m3"),this._element.classList.remove("error","active","disabled"),this._element.removeAttribute("data-owner-id"),this._element.removeAttribute("data-open"),this._options.cssClass&&this._element.classList.remove(this._options.cssClass));const n=this._element?.querySelectorAll(".timepicker-ui-invalid-text");n?.forEach(e=>e.remove()),this._mutliEventsMoveHandler=()=>{},this._eventsClickMobileHandler=()=>{},this._mutliEventsMove=()=>{},this._eventsClickMobile=()=>Promise.resolve(),this._isModalRemove=!0,this._isTouchMouseMove=!1,this._disabledTime=null,this._cloned=null,this._degreesHours=null,this._degreesMinutes=null,this._isInitialized=!1,this._isDestroyed=!0,"undefined"!=typeof document&&(document.body.style.overflowY="",document.body.style.paddingRight=""),this.onDestroy?.(),a(s)};onDestroy;_eventsBundle=()=>{if(this._isDestroyed)console.warn("TimepickerUI: Instance is destroyed");else if(this._isModalRemove){if(this._options.inline?.enabled||this.eventManager.handleEscClick(),this.validationManager.setErrorHandler(),this.validationManager.removeErrorHandler(),this._options.inline?.enabled||(this.openElement.forEach(e=>e?.classList.add("disabled")),this.input?.blur()),this.modalManager.setScrollbarOrNot(),this.modalManager.setModalTemplate(),this.modalManager.setNormalizeClass(),this.modalManager.removeBackdrop(),this.clockManager.setOnStartCSSClassesIfClockType24h(),this.clockManager.setClassActiveToHourOnOpen(),null!==this.clockFace){const e=this.clockFacePool.acquire({array:g,classToAdd:"timepicker-ui-hour-time-12",clockFace:this.clockFace,tipsWrapper:this.tipsWrapper,theme:this._options.theme,disabledTime:this._disabledTime?.value?.isInterval?this._disabledTime?.value:this._disabledTime?.value?.hours,clockType:this._options.clockType,hour:this.hour.value,activeTypeMode:this.activeTypeMode?.textContent||""});if(e.create(),"24h"===this._options.clockType){const e=this.clockFacePool.acquire({array:v,classToAdd:"timepicker-ui-hour-time-24",clockFace:this.tipsWrapperFor24h,tipsWrapper:this.tipsWrapperFor24h,theme:this._options.theme,clockType:"24h",disabledTime:this._disabledTime?.value?.isInterval?this._disabledTime?.value:this._disabledTime?.value?.hours,hour:this.hour.value});e.create(),this.clockFacePool.release(e)}else"12h"===this._options.clockType&&this._disabledTime?.value?.isInterval&&setTimeout(()=>{e.updateDisable(this.hour.value,this.activeTypeMode?.textContent||"")},300);this.clockFacePool.release(e)}this.modalManager.setFlexEndToFooterIfNoKeyboardIcon(),setTimeout(()=>{this.themeManager.setTheme();const e=this.modalElement?.querySelector(".timepicker-ui-wrapper");e&&(this._options.cssClass&&e.classList.add(this._options.cssClass),this._pendingThemeConfig&&this._applyThemeToWrapper(e))},0),this.animationManager.setAnimationToOpen(),this.configManager.getInputValueOnOpenAndSet(),this.clockManager.toggleClassActiveToValueTips(this.hour.value),this._isMobileView||(this.clockManager.setTransformToCircleWithSwitchesHour(this.hour.value),this.animationManager.handleAnimationClock()),this.eventManager.handleMinutesEvents(),this.eventManager.handleHourEvents(),"24h"!==this._options.clockType&&(this.eventManager.handleAmClick(),this.eventManager.handlePmClick()),this.clockFace&&this.eventManager.handleMoveHand(),this.eventManager.handleCancelButton(),this.eventManager.handleOkButton(),this.modalElement&&(this.modalManager.setShowClassToBackdrop(),this._options.inline?.enabled||this.eventManager.handleBackdropClick()),this.eventManager.handleIconChangeView(),this.eventManager.handleClickOnHourMobile(),this._options.focusTrap&&this.eventManager.focusTrapHandler(),this._options.inline?.enabled&&!1!==this._options.inline.autoUpdate&&this.eventManager.handleInlineAutoUpdate()}}}class K extends Z{getValue=()=>{if(this._isDestroyed)return console.warn("TimepickerUI: Instance is destroyed"),{hour:"",minutes:"",time:"",degreesHours:null,degreesMinutes:null};const e=this.hour?.value||"12",t=this.minutes?.value||"00",i="24h"===this._options.clockType?void 0:this.activeTypeMode?.textContent||"AM";let s="";return s="24h"===this._options.clockType?`${e.padStart(2,"0")}:${t.padStart(2,"0")}`:`${e}:${t.padStart(2,"0")} ${i}`,{hour:e,minutes:t,type:i,time:s,degreesHours:this._degreesHours,degreesMinutes:this._degreesMinutes}};setValue=(e,t=!0)=>{if(this._isDestroyed)return void console.warn("TimepickerUI: Instance is destroyed");if(!e||"string"!=typeof e)throw new Error("TimepickerUI: setValue requires a valid time string");const i=e.trim();let s="12",r="00",n="AM";try{if("24h"===this._options.clockType){const e=i.match(/^([0-1]?[0-9]|2[0-3]):([0-5][0-9])$/);if(!e)throw new Error("Invalid 24h format. Expected HH:MM");s=e[1].padStart(2,"0"),r=e[2]}else{const e=i.match(/^(1[0-2]|[1-9]):([0-5][0-9])\s*(AM|PM)$/i);if(!e)throw new Error("Invalid 12h format. Expected HH:MM AM/PM");s=e[1],r=e[2],n=e[3].toUpperCase()}this.hour&&(this.hour.value=s,this.hour.setAttribute("aria-valuenow",s),this._degreesHours=30*Number(s)),this.minutes&&(this.minutes.value=r,this.minutes.setAttribute("aria-valuenow",r),this._degreesMinutes=6*Number(r)),"24h"!==this._options.clockType&&this.AM&&this.PM&&("AM"===n?(this.AM.classList.add("active"),this.PM.classList.remove("active")):(this.PM.classList.add("active"),this.AM.classList.remove("active"))),t&&this.input&&(this.input.value=i),this.clockHand&&(this.clockHand.style.transform=`rotateZ(${this._degreesHours||0}deg)`)}catch(e){throw new Error(`TimepickerUI: ${e instanceof Error?e.message:"Invalid time format"}`)}};update=(e,t)=>{this._isDestroyed?console.warn("TimepickerUI: Instance is destroyed"):(this._options={...this._options,...e.options},this.configManager.checkMobileOption(),e.create&&this.create(),a(t))};setTheme(e){if(this._isDestroyed)return void console.warn("TimepickerUI: Cannot set theme on destroyed instance");this._pendingThemeConfig=e;const t=this.modalElement?.querySelector(".timepicker-ui-wrapper");t&&this._applyThemeToWrapper(t)}}const J=new Map;class X extends K{constructor(e,t){if(super(e,t),this._isDestroyed)return;const i=t?.id;if(i&&J.has(i))return console.error(`TimepickerUI: Instance with ID "${i}" already exists`),void(this._isDestroyed=!0);J.set(this._instanceId,this),this.onDestroy=()=>{J.delete(this._instanceId)}}static getById(e){return J.get(e)}static getAllInstances(){return Array.from(J.values())}static isAvailable(e){return"undefined"!=typeof window&&("string"==typeof e?null!==document.querySelector(e):e instanceof HTMLElement&&document.contains(e))}static destroyAll(){Array.from(J.values()).forEach(e=>e.destroy()),J.clear()}}e.EventEmitter=j,e.TimepickerUI=X,e.default=X,Object.defineProperty(e,"__esModule",{value:!0})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "timepicker-ui",
3
- "version": "3.0.1",
3
+ "version": "3.1.0",
4
4
  "description": "timepicker-ui is a customizable time picker library built with TypeScript, inspired by Google's Material Design. Lightweight, themeable, and easy to integrate.",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -28,7 +28,8 @@
28
28
  "./theme-glassmorphic.css": "./dist/css/themes/theme-glassmorphic.css",
29
29
  "./theme-pastel.css": "./dist/css/themes/theme-pastel.css",
30
30
  "./theme-ai.css": "./dist/css/themes/theme-ai.css",
31
- "./theme-cyberpunk.css": "./dist/css/themes/theme-cyberpunk.css"
31
+ "./theme-cyberpunk.css": "./dist/css/themes/theme-cyberpunk.css",
32
+ "./theme-custom.css": "./dist/css/themes/theme-custom.css"
32
33
  },
33
34
  "keywords": [
34
35
  "material-design",