timepicker-ui 4.1.2 → 4.1.3
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/css/index.css +1 -1
- package/dist/css/main.css +1 -1
- package/dist/index.cjs +4 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4 -4
- package/dist/index.umd.js +1 -1
- package/dist/plugins/range.cjs +1 -1
- package/dist/plugins/range.js +1 -1
- package/dist/plugins/range.umd.js +1 -1
- package/package.json +1 -1
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).TimepickerUI=t()}(this,function(){"use strict";const e=()=>"undefined"==typeof window,t=()=>"undefined"!=typeof document;class i{state;constructor(e,t,i,s){this.state={degreesHours:null,degreesMinutes:null,options:t,element:e,instanceId:i,isMobileView:!1,isTouchMouseMove:!1,disabledTime:null,cloned:null,isModalRemove:!0,isInitialized:!1,customId:s,eventHandlersRegistered:!1,isDestroyed:!1}}get degreesHours(){return this.state.degreesHours}get degreesMinutes(){return this.state.degreesMinutes}get options(){return this.state.options}get element(){return this.state.element}get instanceId(){return this.state.instanceId}get isMobileView(){return this.state.isMobileView}get isTouchMouseMove(){return this.state.isTouchMouseMove}get disabledTime(){return this.state.disabledTime}get cloned(){return this.state.cloned}get isModalRemove(){return this.state.isModalRemove}get isInitialized(){return this.state.isInitialized}get customId(){return this.state.customId}get eventHandlersRegistered(){return this.state.eventHandlersRegistered}get isDestroyed(){return this.state.isDestroyed}setDegreesHours(e){this.state={...this.state,degreesHours:e}}setDegreesMinutes(e){this.state={...this.state,degreesMinutes:e}}setOptions(e){this.state={...this.state,options:e}}setIsMobileView(e){this.state={...this.state,isMobileView:e}}setIsTouchMouseMove(e){this.state={...this.state,isTouchMouseMove:e}}setDisabledTime(e){this.state={...this.state,disabledTime:e}}setCloned(e){this.state={...this.state,cloned:e}}setIsModalRemove(e){this.state={...this.state,isModalRemove:e}}setIsInitialized(e){this.state={...this.state,isInitialized:e}}setEventHandlersRegistered(e){this.state={...this.state,eventHandlersRegistered:e}}setIsDestroyed(e){this.state={...this.state,isDestroyed:e}}updateOptions(e){this.state={...this.state,options:{...this.state.options,clock:{...this.state.options.clock,...e.clock||{}},ui:{...this.state.options.ui,...e.ui||{}},labels:{...this.state.options.labels,...e.labels||{}},behavior:{...this.state.options.behavior,...e.behavior||{}},callbacks:{...this.state.options.callbacks,...e.callbacks||{}}}}}reset(){this.state={...this.state,degreesHours:null,degreesMinutes:null,isTouchMouseMove:!1,disabledTime:null,cloned:null,isModalRemove:!0,isInitialized:!1,isDestroyed:!0,eventHandlersRegistered:!1}}getModalElement(){return!1===t()?null:document.querySelector(`[data-owner-id="${this.state.instanceId}"]`)}getInput(){return this.state.element?.querySelector("input")}getClockFace(){const e=this.getModalElement();return e?this.state.isMobileView?e.querySelector(".tp-ui-clock-face.mobile"):e.querySelector(".tp-ui-clock-face:not(.mobile)"):null}getClockHand(){const e=this.getModalElement();return e?this.state.isMobileView?e.querySelector(".tp-ui-mobile-clock-wrapper .tp-ui-clock-hand"):e.querySelector(".tp-ui-clock-hand:not(.mobile)"):null}getCircle(){const e=this.getModalElement();return e?this.state.isMobileView?e.querySelector(".tp-ui-mobile-clock-wrapper .tp-ui-circle-hand"):e.querySelector(".tp-ui-circle-hand:not(.mobile)"):null}getTipsWrapper(){const e=this.getModalElement();return e?this.state.isMobileView?e.querySelector(".tp-ui-mobile-clock-wrapper .tp-ui-tips-wrapper"):e.querySelector(".tp-ui-tips-wrapper:not(.mobile)"):null}getTipsWrapperFor24h(){const e=this.getModalElement();return e?this.state.isMobileView?e.querySelector(".tp-ui-mobile-clock-wrapper .tp-ui-tips-wrapper-24h"):e.querySelector(".tp-ui-tips-wrapper-24h:not(.mobile)"):null}getMinutes(){const e=this.getModalElement();return e?.querySelector(".tp-ui-minutes")||null}getHour(){const e=this.getModalElement();return e?.querySelector(".tp-ui-hour")||null}getAM(){const e=this.getModalElement();return e?.querySelector(".tp-ui-am")||null}getPM(){const e=this.getModalElement();return e?.querySelector(".tp-ui-pm")||null}getHourText(){const e=this.getModalElement();return e?.querySelector(".tp-ui-hour-text")||null}getMinutesText(){const e=this.getModalElement();return e?.querySelector(".tp-ui-minute-text")||null}getHeader(){const e=this.getModalElement();return e?.querySelector(".tp-ui-header")||null}getInputWrappers(){const e=this.getModalElement();return e?.querySelectorAll(".tp-ui-input-wrapper")||null}getDots(){const e=this.getModalElement();return e?.querySelector(".tp-ui-dots")||null}getMinutesTips(){const e=this.getModalElement();return e?.querySelector(".tp-ui-minutes-time")||null}getHourTips(){const e=this.getModalElement();return e?.querySelector(".tp-ui-hour-time-12")||null}getAllValueTips(){const e=this.getModalElement();return e?[...e.querySelectorAll(".tp-ui-value-tips"),...e.querySelectorAll(".tp-ui-value-tips-24h")]:[]}getOpenElementData(){const e=this.state.element?.querySelectorAll("[data-open]");if(e?.length>0){const t=[];return e.forEach(({dataset:e})=>t.push(e.open??"")),[...new Set(t)]}return null}getOpenElement(){const e=this.getInput(),t=this.getOpenElementData();return null===t?(e?.setAttribute("data-open","tp-ui-input"),[e]):t.map(e=>this.state.element?.querySelectorAll(`[data-open='${e}']`))[0]??""}getCancelButton(){const e=this.getModalElement();return e?.querySelector(".tp-ui-cancel-btn")||null}getOkButton(){const e=this.getModalElement();return e?.querySelector(".tp-ui-ok-btn")||null}getActiveTypeMode(){const e=this.getModalElement();return e?.querySelector(".tp-ui-type-mode.active")||null}getKeyboardClockIcon(){const e=this.getModalElement();return e?.querySelector(".tp-ui-keyboard-icon-wrapper")||null}getFooter(){const e=this.getModalElement();return e?.querySelector(".tp-ui-footer")||null}getWrapper(){const e=this.getModalElement();return e?.querySelector(".tp-ui-wrapper")||null}}const s=300,r=150,n=400,o=300,a=600,l=401,c=450,u=150;class h{core;emitter;timeouts=[];constructor(e,t){this.core=e,this.emitter=t,this.setupEventListeners()}setupEventListeners(){this.emitter.on("animation:clock",()=>{this.handleAnimationSwitchTipsMode()})}runWithAnimation(e,t=r){if(this.core.options.ui.animation){const i=setTimeout(e,t);this.timeouts.push(i)}else e()}clearAllTimeouts(){this.timeouts.forEach(clearTimeout),this.timeouts=[]}setAnimationToOpen(){this.clearAllTimeouts();const e=this.core.getModalElement();e?.classList.add("opacity"),this.runWithAnimation(()=>{this.core.getModalElement()?.classList.add("show")})}removeAnimationToClose(){this.clearAllTimeouts();this.core.getModalElement()&&this.runWithAnimation(()=>{const e=this.core.getModalElement();e?.classList.remove("show"),e?.classList.remove("opacity")})}handleAnimationClock(){this.core.options.ui.animation&&this.runWithAnimation(()=>{const e=this.core.getClockFace();e?.classList.add("tp-ui-clock-animation");const t=setTimeout(()=>{this.core.getClockFace()?.classList.remove("tp-ui-clock-animation")},a);this.timeouts.push(t)})}handleAnimationSwitchTipsMode(){const e=this.core.getClockHand();if(!e)return;this.emitter.emit("animation:start",{}),e.classList.add("tp-ui-tips-animation");const t=setTimeout(()=>{this.core.getClockHand()?.classList.remove("tp-ui-tips-animation"),this.emitter.emit("animation:end",{})},l);this.timeouts.push(t)}destroy(){this.clearAllTimeouts()}}const d=(e,t)=>Array.from({length:Number(t)-Number(e)+1},(t,i)=>Number(e)+i),m=(e,t)=>Array.from({length:Number(t)-Number(e)+1},(e,i)=>Number(t)-i).reverse(),p=(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")}`},g=e=>{const[t,i]=e.split(":");return`${t.padStart(2,"0")}:${i.padStart(2,"0")}`},v=(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: "${e}"`);r=p(i.trim()),n=p(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: "${e}"`);r=g(i.trim()),n=g(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 intervals: "${s.original}" and "${r.original}"`)}return!1};var b='<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#e3e3e3"><path d="M160-200q-33 0-56.5-23.5T80-280v-400q0-33 23.5-56.5T160-760h640q33 0 56.5 23.5T880-680v400q0 33-23.5 56.5T800-200H160Zm0-80h640v-400H160v400Zm160-40h320v-80H320v80ZM200-440h80v-80h-80v80Zm120 0h80v-80h-80v80Zm120 0h80v-80h-80v80Zm120 0h80v-80h-80v80Zm120 0h80v-80h-80v80ZM200-560h80v-80h-80v80Zm120 0h80v-80h-80v80Zm120 0h80v-80h-80v80Zm120 0h80v-80h-80v80Zm120 0h80v-80h-80v80ZM160-280v-400 400Z"/></svg>',y='<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#e3e3e3"><path d="m612-292 56-56-148-148v-184h-80v216l172 172ZM480-80q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-400Zm0 320q133 0 226.5-93.5T800-480q0-133-93.5-226.5T480-800q-133 0-226.5 93.5T160-480q0 133 93.5 226.5T480-160Z"/></svg>';const f=["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"],k=["00","05","10","15","20","25","30","35","40","45","50","55"];class M{core;emitter;timeouts=[];originalOverflow;originalPaddingRight;constructor(e,t){this.core=e,this.emitter=t}runWithTimeout(e,t=s){const i=setTimeout(e,t);this.timeouts.push(i)}clearAllTimeouts(){this.timeouts.forEach(clearTimeout),this.timeouts=[]}clearExistingModal(){if(!1===t())return;const e=document.querySelector(".tp-ui-modal");e&&e.remove()}setModalTemplate(){if(!1===t())return;this.clearExistingModal();const e=((e,t)=>{const{ui:{iconTemplate:i,enableSwitchIcon:s,animation:r,theme:n,mobile:o,editable:a,iconTemplateMobile:l},labels:{time:c,mobileTime:u,am:h,pm:d,cancel:m,ok:p,mobileMinute:g,mobileHour:v},clock:{type:f},timezone:{enabled:T,label:k},range:{enabled:M,fromLabel:C,toLabel:H}}=e,w=o?"mobile":"";return`<div class="tp-ui-modal normalize ${w}${M?" tp-ui-range-mode":""}" data-theme="${n}" role="dialog" aria-modal="true" aria-labelledby="tp-ui-label-${t}" data-owner-id="${t}" style='transition:${r?"opacity 0.15s linear":"none"}'><div class="tp-ui-wrapper ${w}" tabindex="0">${M?`<div class="tp-ui-range-header" role="tablist" aria-label="Range selection"><button type="button" class="tp-ui-range-tab tp-ui-range-from active" role="tab" tabindex="0" aria-selected="true"><span class="tp-ui-range-tab-label">${C}</span><span class="tp-ui-range-tab-value tp-ui-range-from-time">--:--</span></button><button type="button" class="tp-ui-range-tab tp-ui-range-to" role="tab" tabindex="-1" aria-selected="false"><span class="tp-ui-range-tab-label">${H}</span><span class="tp-ui-range-tab-value tp-ui-range-to-time">--:--</span></button></div>`:""}<div class="tp-ui-select-time ${w}" id="tp-ui-label-${t}">${w?u:c}</div><div class="tp-ui-header ${w}"><div class="tp-ui-wrapper-time ${w} ${"24h"===f?"tp-ui-wrapper-time-24h":""}" role="group" aria-label="${w?u:c}"><div class="tp-ui-input-wrapper ${w}"><div class="tp-ui-input-ripple-wrapper ${w}" data-md3-ripple><input name="hour" ${a||w?"":"readonly"} class="tp-ui-hour ${w}" tabindex="0" type="number" min="0" max="${"12h"===f?"12":"23"}" aria-label="${w?v:"Hour"}" role="spinbutton" aria-valuenow="12"></div><div class="tp-ui-hour-text ${w}">${v}</div></div><div class="tp-ui-dots ${w}" aria-hidden="true"><span></span><span></span></div><div class="tp-ui-input-wrapper ${w}"><div class="tp-ui-input-ripple-wrapper ${w}" data-md3-ripple><input name="minutes" ${a||w?"":"readonly"} class="tp-ui-minutes ${w}" tabindex="0" type="number" min="0" max="59" aria-label="${w?g:"Minute"}" role="spinbutton" aria-valuenow="0"></div><div class="tp-ui-minute-text ${w}">${g}</div></div></div>${"24h"!==f?`<div class="tp-ui-wrapper-type-time ${w}" role="group" aria-label="Period"><div class="tp-ui-type-mode tp-ui-am ${w?"mobile":"tp-ui-ripple"}" data-md3-ripple tabindex="0" role="button" aria-label="${h}" aria-pressed="false" data-type="AM">${h}</div><div class="tp-ui-type-mode tp-ui-pm ${w?"mobile":"tp-ui-ripple"}" data-md3-ripple tabindex="0" role="button" aria-label="${d}" aria-pressed="false" data-type="PM">${d}</div></div>`:""}</div>${T?`<div class="tp-ui-timezone ${w}">\n <span class="tp-ui-timezone-label" id="tp-tz-label-${t}">${k}</span>\n <div class="tp-ui-timezone-dropdown" role="combobox" aria-expanded="false" aria-haspopup="listbox" aria-labelledby="tp-tz-label-${t}" tabindex="0" data-tz-id="${t}">\n <div class="tp-ui-timezone-selected" data-placeholder="${k}...">${k}...</div>\n <svg class="tp-ui-timezone-arrow" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 9 12 15 18 9"></polyline></svg>\n <div class="tp-ui-timezone-menu" role="listbox" aria-labelledby="tp-tz-label-${t}"></div>\n </div>\n </div>`:""}<div class="tp-ui-mobile-clock-wrapper ${w}"><div class="tp-ui-body ${w}"><div class="tp-ui-clock-face ${w}" role="group" aria-label="Clock"><div class="tp-ui-dot ${w}" aria-hidden="true"></div><div class="tp-ui-clock-hand ${w}" aria-hidden="true"><div class="tp-ui-circle-hand ${w}"></div></div><div class="tp-ui-tips-wrapper ${w}" role="listbox" aria-label="Time"></div>${"24h"===f?`<div class="tp-ui-tips-wrapper-24h ${w}" role="listbox" aria-label="24h"></div>`:""}</div></div></div><div class="tp-ui-footer ${w}" ${w?'data-view="mobile"':""}>${s?`<div class="tp-ui-keyboard-icon-wrapper ${w}" tabindex="0" role="button" aria-pressed="false" aria-label="Toggle" data-view="desktop">${w?l||`<button aria-label="Clock" type="button" class="tp-ui-keyboard-icon">${l||y}</button>`:`<button aria-label="Keyboard" type="button" class="tp-ui-keyboard-icon">${i||b}</button>`}</div>`:""}<div class="tp-ui-wrapper-btn ${w}"><div class="tp-ui-cancel-btn ${w}" data-md3-ripple tabindex="0" role="button" aria-pressed="false" aria-label="${m}">${m}</div><div class="tp-ui-ok-btn ${w}" data-md3-ripple tabindex="0" role="button" aria-pressed="false" aria-label="${p}">${p}</div></div></div></div><div class="timepicker-announcer sr-only" role="status" aria-live="polite" aria-atomic="true"></div></div>`})(this.core.options,this.core.instanceId);if(this.core.options.ui.inline?.enabled){const t=document.getElementById(this.core.options.ui.inline.containerId);if(!t)return;t.innerHTML="",t.insertAdjacentHTML("beforeend",e);const i=t.querySelector(".tp-ui-modal");if(i){i.classList.add("tp-ui--inline");const{showButtons:e}=this.core.options.ui.inline;!1!==e&&void 0!==e||i.querySelectorAll(".tp-ui-wrapper-btn, .tp-ui-wrapper-btn.mobile").forEach(e=>e.style.display="none")}return}const{appendModalSelector:i}=this.core.options.ui;if(i){const t=document.querySelector(i);t?.insertAdjacentHTML("beforeend",e)}else document.body.insertAdjacentHTML("beforeend",e)}setScrollbarOrNot(){!1!==t()&&(this.core.options.ui.inline?.enabled||(this.core.options.ui.enableScrollbar?this.runWithTimeout(()=>{e()||this.runWithTimeout(()=>{"undefined"!=typeof document&&(document.body.style.overflowY=this.originalOverflow||"",document.body.style.paddingRight=this.originalPaddingRight||"")},n)},400):(this.originalOverflow=document.body.style.overflowY,this.originalPaddingRight=document.body.style.paddingRight,document.body.style.paddingRight=`${(()=>{if(!1===t())return 0;const e=document.createElement("div");e.className="tp-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(){if(this.core.options.ui.inline?.enabled||this.core.options.ui.backdrop)return;const e=this.core.getModalElement(),t=this.core.getOpenElement();e?.classList.add("removed"),t.forEach(e=>e?.classList.add("disabled"))}setNormalizeClass(){const e=this.core.getModalElement();if(!e)return;e.classList.add("tp-ui-normalize");e.querySelectorAll(":scope > div").forEach(e=>e.classList.add("tp-ui-normalize"))}setShowClassToBackdrop(){if(this.core.options.ui.inline?.enabled)return this.core.getModalElement()?.classList.add("show"),void this.setInitialFocus();this.core.options.ui.backdrop&&this.runWithTimeout(()=>{this.core.getModalElement()?.classList.add("show"),this.setInitialFocus()},r)}setInitialFocus(){if(!this.core.options.behavior.focusTrap)return;const e=this.core.getWrapper();e&&"undefined"!=typeof requestAnimationFrame&&requestAnimationFrame(()=>{e.focus()})}setFlexEndToFooterIfNoKeyboardIcon(){const e=this.core.getFooter();!this.core.options.ui.enableSwitchIcon&&e&&(e.style.justifyContent="flex-end")}destroy(){this.clearAllTimeouts(),e()||this.core.options.ui.inline?.enabled||(document.body.style.overflowY=this.originalOverflow||"",document.body.style.paddingRight=this.originalPaddingRight||""),this.clearExistingModal()}}const C=(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=i.padStart(2,"0");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:e.padStart(2,"0"),minutes:t,type:void 0}}const a=new Date(o).toLocaleTimeString(r||"en-US",{hour:"2-digit",minute:"2-digit",hour12:"12h"===t}),[l,c]=a.split(":");if("12h"===t&&/[a-z]/i.test(c)){const e=c.trim().split(" ");return{hour:l,minutes:e[0],type:e[1]||"AM"}}return{hour:l,minutes:c.replace(/\D/g,""),type:void 0}}const[o,a]=n.split(" "),[l="",c=""]=o.split(":"),u=l.replace(/\D/g,""),h=c.replace(/\D/g,""),d={hour:u.padStart(2,"0"),minutes:h.padStart(2,"0"),type:"12h"===t?a:void 0};if(u.length>2||h.length>2)return{...d,error:"Invalid input: too many digits.",currentHour:l,currentMin:c};if(/[a-z]/i.test(o))return{...d,error:"Input contains invalid letters."};if(n.includes(" ")&&(!a||n.length>8||"AM"!==a&&"PM"!==a))return{...d,error:"Invalid AM/PM format or length.",currentLength:n.length,currentType:a};const m=Number(u),p=Number(h);if("12h"===t){if(m<1||m>12||p<0||p>59||"AM"!==a&&"PM"!==a)return{...d,error:"Invalid 12h time.",currentHour:m,currentMin:p,currentType:a}}else if(m<0||m>23||p<0||p>59)return{...d,error:"Invalid 24h time.",currentHour:m,currentMin:p};return d},H=(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}},w="tp-ui",A="mousedown mouseup mousemove mouseleave mouseover touchstart touchmove touchend",E="active";class S{core;emitter;constructor(e,t){this.core=e,this.emitter=t}isCurrentTimeEnabled(e){const t=this.core.options.clock.currentTime;return"boolean"==typeof t?t:!!t?.[e]}preventClockTypeByCurrentTime(){if(!this.isCurrentTimeEnabled("preventClockType"))return;const e=this.core.getInput();if(!e)return;const{currentTime:t,clockType:i}={currentTime:this.core.options.clock.currentTime,clockType:this.core.options.clock.type},{type:s}=C(e,i,t,!0);this.core.updateOptions({clock:{type:s?"12h":"24h"}})}updateInputValueWithCurrentTimeOnStart(){if(!this.isCurrentTimeEnabled("updateInput"))return;const e=this.core.getInput();if(!e)return;const{hour:t,minutes:i,type:s}=C(e,this.core.options.clock.type,this.core.options.clock.currentTime);e.value=s?`${t}:${i} ${s}`:`${t}:${i}`}getInputValueOnOpenAndSet(){const e=this.core.getInput();if(!e)return;const t=C(e,this.core.options.clock.type,this.core.options.clock.currentTime),i=this.core.getHour(),s=this.core.getMinutes(),r=this.core.getActiveTypeMode(),n=this.core.getAM();if(void 0===t){i&&(i.value="12"),s&&(s.value="00");const e={hour:i?.value||"12",minutes:s?.value||"00",type:r?.dataset.type,degreesHours:this.core.degreesHours,degreesMinutes:this.core.degreesMinutes};this.emitter.emit("open",e);const t=!0===this.core.options.range?.enabled;return void("24h"!==this.core.options.clock.type&&n&&!t&&n.classList.add(E))}let[o,a,l]=e.value.split(":").join(" ").split(" ");0===e.value.length&&(o=t.hour,a=t.minutes,l=t.type),i&&(i.value=o.padStart(2,"0")),s&&(s.value=a.padStart(2,"0"));const c=this.core.getModalElement(),u=c?.querySelector(`[data-type='${l}']`);"24h"!==this.core.options.clock.type&&u&&u.classList.add(E);const h={...t,type:r?.dataset.type,degreesHours:this.core.degreesHours,degreesMinutes:this.core.degreesMinutes};this.emitter.emit("open",h)}getInputValue(e,t,i){return C(e,t,i)}destroy(){}}class L{core;emitter;isAnimating=!1;constructor(e,t){this.core=e,this.emitter=t,this.setupEventListeners()}setupEventListeners(){this.emitter.on("switch:view",()=>{this.toggleMobileClockFace()})}checkMobileOption(){this.core.setIsMobileView(!!this.core.options.ui.mobile),this.core.options.ui.mobile&&this.core.updateOptions({ui:{editable:!0}})}toggleMobileClockFace(){if(this.isAnimating)return;const e=this.core.getModalElement();if(!e)return;const t=e.querySelector(".tp-ui-wrapper"),i=this.core.getKeyboardClockIcon(),s=e.querySelector(".tp-ui-mobile-clock-wrapper"),r=e.querySelectorAll("*"),n=e.querySelector(".tp-ui-select-time"),o=this.core.getHour(),a=this.core.getMinutes(),l=this.core.getClockFace();if(!t)return;const c=t.classList.contains("expanded"),u=this.core.isMobileView;c?this.collapseClockFace(t,s,r,i,n,o,a,l,u):this.expandClockFace(t,s,r,i,n,o,a,l)}collapseClockFace(e,t,i,s,r,n,o,a,l){this.isAnimating=!0,this.switchView(r,s,n,o,!0),i.forEach(i=>{i!==t&&i!==e&&i!==r&&(i.classList.remove("expanded"),l&&i.classList.add("mobile"))}),r&&(r.classList.remove("expanded"),l&&r.classList.add("mobile")),"undefined"!=typeof requestAnimationFrame?requestAnimationFrame(()=>{t?.classList.remove("expanded"),l&&t?.classList.add("mobile"),e?.classList.remove("expanded"),l&&e?.classList.add("mobile"),l?a?.classList.remove("scale-in"):a?.classList.add("scale-in"),setTimeout(()=>{this.isAnimating=!1},c)}):this.isAnimating=!1,s?.setAttribute("aria-label","Show clock face"),s?.setAttribute("aria-pressed","false")}expandClockFace(e,t,i,s,r,n,o,a){this.isAnimating=!0;const l=o?.classList.contains("active");l&&o?this.emitter.emit("select:minute",{minutes:o.value}):n&&this.emitter.emit("select:hour",{hour:n.value}),i.forEach(i=>{i!==t&&i!==e&&i!==r&&(i.classList.remove("mobile"),i.classList.add("expanded"))}),r&&(r.classList.remove("mobile"),r.classList.add("expanded")),this.switchView(r,s,n,o,!1),"undefined"!=typeof requestAnimationFrame?requestAnimationFrame(()=>{e.classList.remove("mobile"),e.classList.add("expanded"),requestAnimationFrame(()=>{t&&(t.classList.remove("mobile"),t.classList.add("expanded")),a&&a.classList.remove("scale-in"),setTimeout(()=>{a&&a.classList.add("scale-in")},u),setTimeout(()=>{this.isAnimating=!1},c)})}):this.isAnimating=!1,s?.setAttribute("aria-label","Hide clock face"),s?.setAttribute("aria-pressed","true")}switchView(e,t,i,s,r){const n=this.core.getModalElement(),o=n?.querySelector(".tp-ui-hour-text"),a=n?.querySelector(".tp-ui-minute-text"),l=t?.querySelector(".tp-ui-keyboard-icon"),c=this.core.getInputWrappers(),u=this.core.getHeader(),{iconTemplate:h,iconTemplateMobile:d}=this.core.options.ui,{time:m,mobileTime:p}=this.core.options.labels;r?(e?.classList.add("mobile"),t?.classList.add("mobile"),i?.classList.add("mobile"),s?.classList.add("mobile"),o?.classList.add("mobile"),a?.classList.add("mobile"),u?.classList.add("mobile"),c?.forEach(e=>{e.classList.add("mobile")}),e&&p&&(e.textContent=p),l&&(l.innerHTML=d||y),this.updateClockFaceAccessibility(!0)):(e?.classList.remove("mobile"),t?.classList.remove("mobile"),i?.classList.remove("mobile"),s?.classList.remove("mobile"),o?.classList.remove("mobile"),a?.classList.remove("mobile"),u?.classList.remove("mobile"),c?.forEach(e=>{e.classList.remove("mobile")}),e&&m&&(e.textContent=m),l&&(l.innerHTML=h||b),this.updateClockFaceAccessibility(!1))}updateClockFaceAccessibility(e){const t=this.core.getClockFace();if(!t)return;const i=t.querySelector(".tp-ui-tips-wrapper"),s=t.querySelector(".tp-ui-tips-wrapper-24h"),r=t.querySelectorAll(".tp-ui-tip");e?(t.setAttribute("aria-hidden","true"),i?.setAttribute("aria-hidden","true"),s?.setAttribute("aria-hidden","true"),r.forEach(e=>{e.setAttribute("tabindex","-1"),e.setAttribute("aria-hidden","true")})):(t.removeAttribute("aria-hidden"),i?.removeAttribute("aria-hidden"),s?.removeAttribute("aria-hidden"),r.forEach(e=>{e.setAttribute("tabindex","0"),e.removeAttribute("aria-hidden")}))}destroy(){}}const I=(e,t,i,s)=>{if(e){if(Array.isArray(e)&&e.length>0){return!e.map(e=>H(e,t,i)).some(e=>!1===e)}if("string"==typeof e||"number"==typeof e){return!!H(e,t,i)}}};class x{core;constructor(e){this.core=e}getDisableTime(){const e=(e=>{if(!e)return;const{disabledTime:t,type:i}=e.clock;if(!t||!Object.keys(t).length)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 required for interval");return v(e,i),{value:e.map(e=>{const[t,s]=e.trim().split("-"),{hour:r,minutes:n,type:o}=C({value:t.trim()},i),{hour:a,minutes:l,type:c}=C({value:s.trim()},i);let u=d(r,a).map(e=>0===Number(e)?"00":String(Number(e)));const h=[],p=Number(n),g=Number(l);if(c===o)return p>0&&g<=0?(h.push(u[0],u[u.length-1]),u=u.slice(1,-1)):g<59&&g>0&&p<=0?(h.push(void 0,u[u.length-1]),u=u.slice(0,-1)):g>0&&p>0?(h.push(u[0],u[u.length-1]),u=u.slice(1,-1)):0===g&&0===p&&(h.push(void 0,u[u.length-1]),u.pop()),{removedStartedHour:void 0!==h[0]&&Number(h[0])<=9?`0${h[0]}`:h[0],removedEndHour:void 0!==h[1]&&Number(h[1])<=9?`0${h[1]}`:h[1],rangeArrHour:u,startMinutes:d(n,59).map(e=>Number(e)<=9?`0${e}`:`${e}`),endMinutes:m(0,l).map(e=>Number(e)<=9?`0${e}`:`${e}`),startType:o,endType:c};{const e=d(r,12).map(String),t=m(1,a).map(String),i=[],s=[];return p>0&&g<=0?(s.push(t[t.length-1]),i.push(e[0]),t.pop(),e.shift()):g<59&&g>0&&p<=0?(i.push(e[0]),s.push(t[t.length-1]),t.pop()):g>0&&p>0?(s.push(t[t.length-1]),i.push(e[0]),t.pop(),e.shift()):0===g&&0===p&&(s.push(t[t.length-1]),i.push(e[0]),t.pop()),{startType:o,endType:c,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)?[]:d(n,59).map(e=>Number(e)<=9?`0${e}`:`${e}`),endMinutes:m(0,l).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.core.options);this.core.setDisabledTime(e||null)}destroy(){}}class ${inputValueHandler;mobileViewHandler;disabledTimeHandler;core;constructor(e,t){this.core=e,this.inputValueHandler=new S(e,t),this.mobileViewHandler=new L(e,t),this.disabledTimeHandler=new x(e)}preventClockTypeByCurrentTime(){this.inputValueHandler.preventClockTypeByCurrentTime()}updateInputValueWithCurrentTimeOnStart(){this.inputValueHandler.updateInputValueWithCurrentTimeOnStart()}getInputValueOnOpenAndSet(){this.inputValueHandler.getInputValueOnOpenAndSet()}getInputValue(e,t,i){return this.inputValueHandler.getInputValue(e,t,i)}checkMobileOption(){this.mobileViewHandler.checkMobileOption()}toggleMobileClockFace(){this.mobileViewHandler.toggleMobileClockFace()}updateClockFaceAccessibility(e){this.mobileViewHandler.updateClockFaceAccessibility(e)}getDisableTime(){this.disabledTimeHandler.getDisableTime()}destroy(){this.inputValueHandler.destroy(),this.mobileViewHandler.destroy(),this.disabledTimeHandler.destroy()}}class P{core;emitter;constructor(e,t){this.core=e,this.emitter=t}setTheme(){const e=this.core.getModalElement();if(!e)return;const{theme:t}=this.core.options.ui;t&&e.setAttribute("data-theme",t)}setInputClassToInputElement(){const e=this.core.getInput();var t,i;e&&(i="tp-ui-input",(t=e)&&t.classList.contains(i)||e.classList.add("tp-ui-input"))}setDataOpenToInputIfDoesntExistInWrapper(){const e=this.core.getOpenElementData(),t=this.core.getInput();null===e&&t&&t.setAttribute("data-open","tp-ui-input")}setClassTopOpenElement(){const e=this.core.getOpenElement();for(const t of e)t&&t.classList.add("tp-ui-open-element")}setTimepickerClassToElement(){const e=this.core.element;if(!e)return;e.classList.add(w);const t=this.core.options.ui.cssClass;t&&t!==w&&e.classList.add(t)}destroy(){const e=this.core.getModalElement();e&&e.removeAttribute("data-theme")}}class D extends Error{code;constructor(e,t){super(`[TimepickerUI] ${e}`),this.code=t,this.name="TimepickerError",Object.setPrototypeOf(this,D.prototype)}}const F="INVALID_PARAMETER";class V{core;emitter;constructor(e,t){this.core=e,this.emitter=t}setErrorHandler(){const e=this.core.getInput();if(!e)return!0;const{error:i,currentHour:s,currentMin:r,currentType:n,currentLength:o}=C(e,this.core.options.clock.type);if(this.removeErrorHandler(),i){if(!1===t())return!1;const a=document.createElement("div");a.classList.add("tp-ui-invalid-text"),a.innerHTML="<b>Invalid Time Format</b>",e.classList.add("tp-ui-invalid-format"),e.nextElementSibling?.classList.contains("tp-ui-invalid-text")||e.after(a);const l={error:i,rejectedHour:void 0,rejectedMinute:void 0,inputHour:s,inputMinute:r,inputType:n,inputLength:o};return this.emitter.emit("error",l),!1}return!0}removeErrorHandler(){const e=this.core.getInput();if(!e)return;e.classList.remove("tp-ui-invalid-format");const t=e.nextElementSibling;t?.classList.contains("tp-ui-invalid-text")&&t.remove()}checkDisabledValuesOnStart(){if(!this.core.options.clock.disabledTime)return;const{disabledTime:e,type:t}=this.core.options.clock;if(e.interval){if(!t)throw new D("clockType is required when using disabledTime.interval",F);const i=Array.isArray(e.interval)?e.interval:[e.interval];try{v(i,t)}catch(e){throw new D(`Invalid disabledTime.interval: ${e.message}`,F)}return}const{hours:i,minutes:s}=e,r=!i||I(i,"hour",t),n=!s||I(s,"minutes",t);if(!r||!n)throw new D("Invalid hours or minutes in disabledTime option",F)}destroy(){this.removeErrorHandler()}}const q=(e,t)=>{if(!e)return;const i=e.querySelector(".timepicker-announcer");i&&(i.textContent="",setTimeout(()=>{i.textContent=t},100))},O=(e,t)=>{e&&e.setAttribute("aria-pressed",String(t))};class N{core;emitter;cleanupHandlers=[];constructor(e,t){this.core=e,this.emitter=t}handleOpenOnClick(){const e=this.core.getOpenElement();if(!e)return;const t=()=>{this.core.isDestroyed||this.emitter.emit("show",{})};e.forEach(e=>{e.addEventListener("click",t),this.cleanupHandlers.push(()=>e.removeEventListener("click",t))})}handleCancelButton(){const e=this.core.getCancelButton();if(!e)return;const t=()=>{this.core.isDestroyed||this.emitter.emit("cancel",{})};e.addEventListener("click",t),this.cleanupHandlers.push(()=>e.removeEventListener("click",t))}handleOkButton(){const e=this.core.getOkButton();if(!e)return;const t=()=>{if(this.core.isDestroyed)return;const e=this.core.getHour(),t=this.core.getMinutes(),i=this.core.getActiveTypeMode();this.emitter.emit("confirm",{hour:e?.value,minutes:t?.value,type:i?.textContent||void 0})};e.addEventListener("click",t),this.cleanupHandlers.push(()=>e.removeEventListener("click",t))}handleAmClick(){const e=this.core.getAM();if(!e)return;const t=()=>{if(this.core.isDestroyed)return;const t=this.core.getPM();e.classList.add("active"),t?.classList.remove("active"),O(e,!0),O(t,!1);const i=this.core.getModalElement();q(i,"AM selected"),this.emitter.emit("select:am",{});const s=this.core.getHour(),r=this.core.getMinutes();this.emitter.emit("update",{hour:s?.value,minutes:r?.value,type:"AM"})};e.addEventListener("click",t),this.cleanupHandlers.push(()=>e.removeEventListener("click",t))}handlePmClick(){const e=this.core.getPM();if(!e)return;const t=()=>{if(this.core.isDestroyed)return;const t=this.core.getAM();e.classList.add("active"),t?.classList.remove("active"),O(e,!0),O(t,!1);const i=this.core.getModalElement();q(i,"PM selected"),this.emitter.emit("select:pm",{});const s=this.core.getHour(),r=this.core.getMinutes();this.emitter.emit("update",{hour:s?.value,minutes:r?.value,type:"PM"})};e.addEventListener("click",t),this.cleanupHandlers.push(()=>e.removeEventListener("click",t))}handleSwitchViewButton(){const e=this.core.getKeyboardClockIcon();if(!e)return;const t=()=>{this.core.isDestroyed||this.emitter.emit("switch:view",{})};e.addEventListener("click",t),this.cleanupHandlers.push(()=>e.removeEventListener("click",t))}destroy(){this.cleanupHandlers.forEach(e=>e()),this.cleanupHandlers=[]}}const W=(e,t,i)=>Math.max(t,Math.min(i,e));class z{core;emitter;cleanupHandlers=[];constructor(e,t){this.core=e,this.emitter=t}handleHourEvents(){const e=this.core.getHour();if(!e)return;const t=()=>{if(this.core.isDestroyed)return;e.classList.add("active");const t=this.core.getMinutes();t?.classList.remove("active"),this.emitter.emit("select:hour",{hour:e.value});const i=this.core.getActiveTypeMode();this.emitter.emit("update",{hour:e.value,minutes:t?.value,type:i?.textContent||void 0})};if(e.addEventListener("click",t),this.cleanupHandlers.push(()=>e.removeEventListener("click",t)),this.core.options.ui.editable||this.core.options.ui.mobile){let t=e.value;const i=()=>{if(this.core.isDestroyed)return;const i="12h"===this.core.options.clock.type,s=((e,t)=>{if(""===e)return"";const i=parseInt(e,10);return Number.isNaN(i)?"":W(i,t?1:0,t?12:23).toString().padStart(2,"0")})(e.value,i);if(e.value=s,e.setAttribute("aria-valuenow",s),e.value!==t){t=e.value,this.emitter.emit("animation:clock",{}),this.emitter.emit("select:hour",{hour:e.value});const i=this.core.getMinutes(),s=this.core.getActiveTypeMode();this.emitter.emit("update",{hour:e.value,minutes:i?.value,type:s?.textContent||void 0})}};e.addEventListener("blur",i),this.cleanupHandlers.push(()=>e.removeEventListener("blur",i))}}handleMinutesEvents(){const e=this.core.getMinutes();if(!e)return;const t=()=>{if(this.core.isDestroyed)return;e.classList.add("active");const t=this.core.getHour();t?.classList.remove("active"),this.emitter.emit("select:minute",{minutes:e.value});const i=this.core.getActiveTypeMode();this.emitter.emit("update",{hour:t?.value,minutes:e.value,type:i?.textContent||void 0})};if(e.addEventListener("click",t),this.cleanupHandlers.push(()=>e.removeEventListener("click",t)),this.core.options.ui.editable||this.core.options.ui.mobile){let t=e.value;const i=()=>{if(this.core.isDestroyed)return;const i=(e=>{if(""===e)return"";const t=parseInt(e,10);return Number.isNaN(t)?"":W(t,0,59).toString().padStart(2,"0")})(e.value);if(e.value=i,e.setAttribute("aria-valuenow",i),e.value!==t){t=e.value,this.emitter.emit("animation:clock",{}),this.emitter.emit("select:minute",{minutes:e.value});const i=this.core.getHour(),s=this.core.getActiveTypeMode();this.emitter.emit("update",{hour:i?.value,minutes:e.value,type:s?.textContent||void 0})}};e.addEventListener("blur",i),this.cleanupHandlers.push(()=>e.removeEventListener("blur",i))}}destroy(){this.cleanupHandlers.forEach(e=>e()),this.cleanupHandlers=[]}}class B{core;emitter;cleanupHandlers=[];constructor(e,t){this.core=e,this.emitter=t}handleOpenOnEnterFocus(){const e=this.core.getInput();if(!e)return;const t=e=>{"Enter"!==e.key||this.core.isDestroyed||this.emitter.emit("show",{})};e.addEventListener("keydown",t),this.cleanupHandlers.push(()=>e.removeEventListener("keydown",t))}handleEscClick(){if(!1===t())return;const e=e=>{this.core.isDestroyed||"Escape"===e.key&&this.emitter.emit("cancel",{})};document.addEventListener("keydown",e),this.cleanupHandlers.push(()=>document.removeEventListener("keydown",e))}handleKeyboardInput(){const e=this.core.getHour(),t=this.core.getMinutes();if(e){const t=t=>{if(this.core.isDestroyed)return;if("ArrowUp"!==t.key&&"ArrowDown"!==t.key)return;t.preventDefault();const i=parseInt(e.value)||0,s=parseInt(e.getAttribute("max")||"23");parseInt(e.getAttribute("min")||"0");const r="12h"===this.core.options.clock.type;let n;n="ArrowUp"===t.key?r?i>=12?1:i+1:i>=s?0:i+1:r?i<=1?12:i-1:i<=0?s:i-1,e.value=n.toString().padStart(2,"0"),e.setAttribute("aria-valuenow",e.value);const o=this.core.getModalElement();q(o,`Hour: ${e.value}`),this.emitter.emit("animation:clock",{}),this.emitter.emit("select:hour",{hour:e.value});const a=this.core.getMinutes(),l=this.core.getActiveTypeMode();this.emitter.emit("update",{hour:e.value,minutes:a?.value,type:l?.textContent||void 0})};e.addEventListener("keydown",t),this.cleanupHandlers.push(()=>e.removeEventListener("keydown",t))}if(t){const e=e=>{if(this.core.isDestroyed)return;if("ArrowUp"!==e.key&&"ArrowDown"!==e.key)return;e.preventDefault();const i=parseInt(t.value)||0;let s;s="ArrowUp"===e.key?i>=59?0:i+1:i<=0?59:i-1,t.value=s.toString().padStart(2,"0"),t.setAttribute("aria-valuenow",t.value);const r=this.core.getModalElement();q(r,`Minutes: ${t.value}`),this.emitter.emit("animation:clock",{}),this.emitter.emit("select:minute",{minutes:t.value});const n=this.core.getHour(),o=this.core.getActiveTypeMode();this.emitter.emit("update",{hour:n?.value,minutes:t.value,type:o?.textContent||void 0})};t.addEventListener("keydown",e),this.cleanupHandlers.push(()=>t.removeEventListener("keydown",e))}}focusTrapHandler(){if(!1===t())return;const e=this.core.getWrapper();if(!e)return;const i=t=>{if(this.core.isDestroyed)return;if("Tab"!==t.key)return;const i=e.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'),s=i[0],r=i[i.length-1];t.shiftKey&&document.activeElement===s?(r?.focus(),t.preventDefault()):t.shiftKey||document.activeElement!==r||(s?.focus(),t.preventDefault())};e.addEventListener("keydown",i),this.cleanupHandlers.push(()=>e.removeEventListener("keydown",i))}destroy(){this.cleanupHandlers.forEach(e=>e()),this.cleanupHandlers=[]}}class R{core;emitter;cleanupHandlers=[];constructor(e,t){this.core=e,this.emitter=t}handleBackdropClick(){const e=this.core.getModalElement();if(!e)return;const t=t=>{this.core.isDestroyed||t.target===e&&this.emitter.emit("cancel",{})};e.addEventListener("click",t),this.cleanupHandlers.push(()=>e.removeEventListener("click",t))}handleMoveHand(){if(!1===t())return;const e=e=>{this.core.isDestroyed||e.preventDefault()};document.addEventListener("mousedown",e,!1),document.addEventListener("touchstart",e,{passive:!1}),this.cleanupHandlers.push(()=>{document.removeEventListener("mousedown",e),document.removeEventListener("touchstart",e)})}destroy(){this.cleanupHandlers.forEach(e=>e()),this.cleanupHandlers=[]}}class U{buttonHandlers;inputHandlers;keyboardHandlers;modalHandlers;constructor(e,t){this.buttonHandlers=new N(e,t),this.inputHandlers=new z(e,t),this.keyboardHandlers=new B(e,t),this.modalHandlers=new R(e,t)}handleOpenOnClick(){this.buttonHandlers.handleOpenOnClick()}handleOpenOnEnterFocus(){this.keyboardHandlers.handleOpenOnEnterFocus()}handleCancelButton(){this.buttonHandlers.handleCancelButton()}handleOkButton(){this.buttonHandlers.handleOkButton()}handleBackdropClick(){this.modalHandlers.handleBackdropClick()}handleEscClick(){this.keyboardHandlers.handleEscClick()}handleAmClick(){this.buttonHandlers.handleAmClick()}handlePmClick(){this.buttonHandlers.handlePmClick()}handleHourEvents(){this.inputHandlers.handleHourEvents()}handleMinutesEvents(){this.inputHandlers.handleMinutesEvents()}handleKeyboardInput(){this.keyboardHandlers.handleKeyboardInput()}focusTrapHandler(){this.keyboardHandlers.focusTrapHandler()}handleMoveHand(){this.modalHandlers.handleMoveHand()}handleSwitchViewButton(){this.buttonHandlers.handleSwitchViewButton()}destroy(){this.buttonHandlers.destroy(),this.inputHandlers.destroy(),this.keyboardHandlers.destroy(),this.modalHandlers.destroy()}}class Z{emitter;getClockSystem;setHoursToClock;setMinutesToClock;updateAmPm;convertDisabledTime;constructor(e,t,i,s,r,n){this.emitter=e,this.getClockSystem=t,this.setHoursToClock=i,this.setMinutesToClock=s,this.updateAmPm=r,this.convertDisabledTime=n}setup(){this.emitter.on("select:hour",({hour:e})=>{this.emitter.emit("animation:clock",{}),this.setHoursToClock(e||null)}),this.emitter.on("select:minute",({minutes:e})=>{this.emitter.emit("animation:clock",{}),this.setMinutesToClock(e||null)}),this.emitter.on("select:am",()=>{this.updateAmPm()}),this.emitter.on("select:pm",()=>{this.updateAmPm()}),this.emitter.on("animation:start",()=>{this.getClockSystem()?.blockInteractions()}),this.emitter.on("animation:end",()=>{this.getClockSystem()?.unblockInteractions()}),this.emitter.on("range:switch",e=>{this.refreshDisabledTimeForRange(e.disabledTime)})}refreshDisabledTimeForRange(e){const t=this.getClockSystem();if(!t)return;const i=this.convertDisabledTime();let s=i;if(e){const t=[...i?.hours||[],...e.hours||[]],r=[...i?.minutes||[],...e.minutes||[]];s={...i,hours:t.length>0?t:void 0,minutes:r.length>0?r:void 0,rangeFromType:e.fromType,rangeFromHour:e.fromHour}}t.updateDisabledTime(s)}}class Y{static angleToIndex(e,t,i){const s=Math.round(e/30)%12;if("24h"===t){if(i){const e=s+12;return 12===e?0:e}return 0===s?12:s}return 0===s?12:s}static indexToValue(e,t,i){if("24h"===t)return e.toString().padStart(2,"0");let s=e;return 0===s&&(s=12),s>12&&(s-=12),s.toString().padStart(2,"0")}static indexToAngle(e,t){if("24h"===t)return e>=12?(e-12)%12*30:e%12*30;return(0===e?12:e)%12*30}static isDisabled(e,t,i){return!!i&&(i.isInterval&&i.intervals&&i.clockType?this.isDisabledByInterval(e,t,i):void 0!==i.rangeFromType&&void 0!==i.rangeFromHour?this.isDisabledForRange12h(e,t,i):!!i.hours&&i.hours.some(t=>String(t)===e||Number(t)===Number(e)||t===e))}static isDisabledForRange12h(e,t,i){const s=i.rangeFromType,r=i.rangeFromHour,n=parseInt(e,10);return null!==s&&void 0!==r&&("AM"===t&&"PM"===s||("AM"===t&&"AM"===s?12!==r&&(12===n||n<r):("PM"!==t||"AM"!==s)&&("PM"===t&&"PM"===s&&(12!==r&&(12===n||n<r)))))}static isDisabledByInterval(e,t,i){if(!i.intervals)return!1;for(let s=0;s<60;s++){const r=s.toString().padStart(2,"0");if(!this.isTimeInIntervals(e,r,t,i.intervals,i.clockType))return!1}return!0}static isTimeInIntervals(e,t,i,s,r){const n="12h"===r?`${e}:${t} ${i}`:`${e}:${t}`;for(const e of s){const[t,i]=e.split("-").map(e=>e.trim());if(this.isTimeBetween(n,t,i,r))return!0}return!1}static isTimeBetween(e,t,i,s){const r=this.timeToMinutes(e,s),n=this.timeToMinutes(t,s),o=this.timeToMinutes(i,s);return r>=n&&r<=o}static timeToMinutes(e,t){if("12h"===t){const t=e.match(/(\d{1,2}):(\d{2})\s*(AM|PM)/i);if(!t)return 0;let i=parseInt(t[1]);const s=parseInt(t[2]),r=t[3].toUpperCase();return"PM"===r&&12!==i&&(i+=12),"AM"===r&&12===i&&(i=0),60*i+s}{const[t,i]=e.split(":").map(Number);return 60*t+i}}static findNearestValid(e,t,i,s,r){const n="24h"===t?23:12;for(let r=0;r<=n;r++){const o=0===r?[e]:[e+r,e-r];for(const e of o){let r=e;r<0&&(r+=n+1),r>n&&(r%=n+1);const o=this.indexToValue(r,t,i);if(!this.isDisabled(o,i,s))return r}}return e}}class j{static angleToIndex(e){return Math.round(e/6)%60}static indexToValue(e){return e.toString().padStart(2,"0")}static indexToAngle(e){return e%60*6}static isDisabled(e,t,i,s,r){return!!s&&(s.isInterval&&s.intervals?this.isDisabledByInterval(e,t,i,s,r):void 0!==s.rangeFromType&&void 0!==s.rangeFromHour?this.isDisabledForRange12h(e,t,i,s):!!s.minutes&&s.minutes.some(t=>String(t)===e||Number(t)===Number(e)||t===e))}static isDisabledForRange12h(e,t,i,s){const r=s.rangeFromType,n=s.rangeFromHour,o=parseInt(t,10),a=parseInt(e,10);if(null===r||void 0===n)return!1;const l=s.minutes||[],c=l.length>0?parseInt(l[l.length-1],10)+1:0;if("AM"===i&&"PM"===r)return!0;if("PM"===i&&"AM"===r)return!1;return!!(o===n||12===o&&12===n||i===r&&o===n)&&a<c}static isDisabledByInterval(e,t,i,s,r){if(!s.intervals)return!1;const n="12h"===r?`${t}:${e} ${i}`:`${t}:${e}`;for(const e of s.intervals){const[t,i]=e.split("-").map(e=>e.trim());if(this.isTimeBetween(n,t,i,r))return!0}return!1}static isTimeBetween(e,t,i,s){const r=this.timeToMinutes(e,s),n=this.timeToMinutes(t,s),o=this.timeToMinutes(i,s);return r>=n&&r<=o}static timeToMinutes(e,t){if("12h"===t){const t=e.match(/(\d{1,2}):(\d{2})\s*(AM|PM)/i);if(!t)return 0;let i=parseInt(t[1]);const s=parseInt(t[2]),r=t[3].toUpperCase();return"PM"===r&&12!==i&&(i+=12),"AM"===r&&12===i&&(i=0),60*i+s}{const[t,i]=e.split(":").map(Number);return 60*t+i}}static findNearestValid(e,t,i,s,r){for(let n=0;n<60;n++){const o=0===n?[e]:[e+n,e-n];for(const e of o){let n=e;n<0&&(n+=60),n>=60&&(n%=60);const o=this.indexToValue(n);if(!this.isDisabled(o,t,i,s,r))return n}}return e}}class K{static normalizeAngle(e){let t=e%360;return t<0&&(t+=360),t}static calculateRawAngle(e,t){const i=e.x-t.x,s=e.y-t.y,r=180*Math.atan2(s,i)/Math.PI+90;return this.normalizeAngle(r)}static snapToIncrement(e,t){const i=Math.round(e/t)*t;return this.normalizeAngle(i)}static calculateDistance(e,t){const i=e.x-t.x,s=e.y-t.y;return Math.sqrt(i*i+s*s)}static isInnerCircle(e,t){return e<.75*t}static calculateShortestPath(e,t){const i=this.normalizeAngle(e),s=this.normalizeAngle(t)-i,r=s>=0?s:s+360,n=s<=0?s:s-360;return e+(Math.abs(r)<Math.abs(n)?r:n)}}class X{config;currentAngle=0;tipsCache=new Map;cachedDimensions=new Map;constructor(e){this.config=e}getCachedDimensions(e){let t=this.cachedDimensions.get(e);if(!t){const i=(e.offsetWidth-32)/2;t={width:i,height:(e.offsetHeight-32)/2,radius:i-9},this.cachedDimensions.set(e,t)}return t}setHandAngle(e){const t=K.calculateShortestPath(this.currentAngle,e);Math.abs(this.currentAngle-t)<.01||(this.currentAngle=t,this.config.clockHand.style.transform=`rotateZ(${t}deg)`)}animateToAngle(e){const t=K.calculateShortestPath(this.currentAngle,e);this.currentAngle=t,this.config.tipsWrapper.classList.add("tp-ui-tips-animation"),this.config.clockHand.style.transform=`rotateZ(${t}deg)`,setTimeout(()=>{this.config.tipsWrapper.classList.remove("tp-ui-tips-animation")},401)}setActiveValue(e){const t=[this.config.tipsWrapper];this.config.tipsWrapperFor24h&&t.push(this.config.tipsWrapperFor24h),t.forEach(t=>{t.querySelectorAll(".tp-ui-value-tips, .tp-ui-value-tips-24h").forEach(t=>{const i=t;i.textContent===e||Number(i.textContent)===Number(e)?(i.classList.add("active"),i.setAttribute("aria-selected","true")):(i.classList.remove("active"),i.setAttribute("aria-selected","false"))})})}renderTips(e,i,s,r,n,o=!0,a,l="",c="12"){if(!1===t())return;const u=a||this.config.tipsWrapper;o&&(u.innerHTML="",this.tipsCache.clear());const{width:h,height:d,radius:m}=this.getCachedDimensions(u),p=document.createDocumentFragment(),g=`${i}-${this.config.theme||"default"}`;e.forEach((t,o)=>{const a=`${g}-${t}`;let u=this.tipsCache.get(a);u||(u=this.createTip(t,i,n),this.tipsCache.set(a,u));const{wrapper:v,tip:b}=u;this.updateTipState(v,b,t,s,r,n,l,c);const y=o*(360/e.length)*(Math.PI/180);v.style.left=`${h+Math.sin(y)*m}px`,v.style.bottom=`${d+Math.cos(y)*m}px`,p.appendChild(v)}),u.appendChild(p)}createTip(e,i,s){if(!1===t()){const e={};return{wrapper:e,tip:e}}const r=document.createElement("span"),n=document.createElement("span");n.textContent=e,n.setAttribute("role","option"),n.setAttribute("aria-selected","false"),n.tabIndex=0;const o="24h"===s&&i.includes("24")?"tp-ui-value-tips-24h":"tp-ui-value-tips";return n.classList.add(o),r.classList.add(i),this.config.theme&&(r.classList.add(this.config.theme),n.classList.add(this.config.theme)),r.appendChild(n),{wrapper:r,tip:n}}updateTipState(e,t,i,s,r,n,o,a){e.classList.remove("tp-ui-tips-disabled"),t.classList.remove("tp-ui-tips-disabled"),t.removeAttribute("aria-disabled"),t.tabIndex=0;this.checkIfDisabled(i,s,r,n,o,a)&&(e.classList.add("tp-ui-tips-disabled"),t.classList.add("tp-ui-tips-disabled"),t.setAttribute("aria-disabled","true"),t.tabIndex=-1)}checkIfDisabled(e,t,i,s,r,n){return!!i&&("hours"===t?Y.isDisabled(e,r,i):"minutes"===t&&j.isDisabled(e,n,r,i,s))}setCircleSize(e){e?this.config.circle.classList.remove("small-circle"):this.config.circle.classList.add("small-circle")}setCircle24hMode(e){e?(this.config.circle.classList.add("tp-ui-circle-hand-24h"),this.config.clockHand.classList.add("tp-ui-clock-hand-24h")):(this.config.circle.classList.remove("tp-ui-circle-hand-24h"),this.config.clockHand.classList.remove("tp-ui-clock-hand-24h"))}destroy(){this.tipsCache.clear(),this.cachedDimensions.clear(),this.config.tipsWrapper.innerHTML=""}}class _{static processPointerInput(e){const t=K.calculateRawAngle(e.pointerPosition,e.clockCenter);return"hours"===e.mode?this.processHours(t,e):this.processMinutes(t,e)}static processHours(e,t){const i=t.smoothHourSnap??!0;let s;if(i)s=e;else{const i=30*t.incrementHours;s=K.snapToIncrement(e,i)}const r=K.calculateDistance(t.pointerPosition,t.clockCenter),n="24h"===t.clockType&&K.isInnerCircle(r,t.clockRadius);let o=Y.angleToIndex(s,t.clockType,n);const a=Y.indexToValue(o,t.clockType,t.amPm),l=Y.isDisabled(a,t.amPm,t.disabledTime);l&&(o=Y.findNearestValid(o,t.clockType,t.amPm,t.disabledTime,n));const c=Y.indexToValue(o,t.clockType,t.amPm);let u;return u=i?e:Y.indexToAngle(o,t.clockType),{angle:u,value:c,index:o,isValid:!l,isInnerCircle:"24h"===t.clockType?n:void 0}}static processMinutes(e,t){const i=6*t.incrementMinutes,s=K.snapToIncrement(e,i);let r=j.angleToIndex(s);const n=j.indexToValue(r),o=t.currentHour||"00",a=j.isDisabled(n,o,t.amPm,t.disabledTime,t.clockType);a&&(r=j.findNearestValid(r,o,t.amPm,t.disabledTime,t.clockType));const l=j.indexToValue(r);return{angle:j.indexToAngle(r),value:l,index:r,isValid:!a}}static valueToAngle(e,t,i){const s=parseInt(e,10);return"hours"===t?Y.indexToAngle(s,i):j.indexToAngle(s)}}class G{state;renderer;clockType;disabledTime;incrementHours;incrementMinutes;smoothHourSnap;isDragging=!1;callbacks;lastProcessedX=null;lastProcessedY=null;constructor(e,t,i,s,r=1,n=1,o=!0,a={}){this.renderer=e,this.state={...t},this.clockType=i,this.disabledTime=s,this.incrementHours=r,this.incrementMinutes=n,this.smoothHourSnap=o,this.callbacks=a}handlePointerMove(e,t,i){if(this.isDragging=!0,this.lastProcessedX===e.x&&this.lastProcessedY===e.y)return;this.lastProcessedX=e.x,this.lastProcessedY=e.y;const s={pointerPosition:e,clockCenter:t,clockRadius:i,mode:this.state.mode,clockType:this.clockType,amPm:this.state.amPm,disabledTime:this.disabledTime,incrementHours:this.incrementHours,incrementMinutes:this.incrementMinutes,smoothHourSnap:this.smoothHourSnap,currentHour:this.state.hour},r=_.processPointerInput(s);if(r.isValid){if("hours"===this.state.mode){const e=this.state.hour;this.state.hour=r.value,this.state.hourAngle=r.angle,"24h"===this.clockType&&void 0!==r.isInnerCircle&&(this.renderer.setCircleSize(!0),this.renderer.setCircle24hMode(r.isInnerCircle)),this.callbacks.onHourChange&&e!==r.value&&this.callbacks.onHourChange(r.value)}else{const e=this.state.minute;this.state.minute=r.value,this.state.minuteAngle=r.angle,this.renderer.setCircleSize(!0),this.renderer.setCircle24hMode(!1),this.callbacks.onMinuteChange&&e!==r.value&&this.callbacks.onMinuteChange(r.value)}this.renderer.setHandAngle(r.angle),this.renderer.setActiveValue(r.value)}}handlePointerUp(){this.isDragging=!1,this.lastProcessedX=null,this.lastProcessedY=null}snapToNearestHour(){if("hours"!==this.state.mode)return;const e=_.valueToAngle(this.state.hour,"hours",this.clockType);this.state.hourAngle=e,this.renderer.animateToAngle(e)}switchMode(e){this.state.mode=e;const t="hours"===e?this.state.hourAngle:this.state.minuteAngle,i="hours"===e?this.state.hour:this.state.minute;if("hours"===e&&"24h"===this.clockType){const e=parseInt(i,10),t=0===e||e>=13;this.renderer.setCircleSize(!0),this.renderer.setCircle24hMode(t)}else this.renderer.setCircleSize(!0),this.renderer.setCircle24hMode(!1);this.renderer.setHandAngle(t),this.renderer.setActiveValue(i)}setValue(e,t){const i=_.valueToAngle(t,e,this.clockType);if("hours"===e)if(this.state.hour=t,this.state.hourAngle=i,"24h"===this.clockType){const e=parseInt(t,10),i=0===e||e>=13;this.renderer.setCircleSize(!0),this.renderer.setCircle24hMode(i)}else this.renderer.setCircle24hMode(!1);else this.state.minute=t,this.state.minuteAngle=i,this.renderer.setCircleSize(!0),this.renderer.setCircle24hMode(!1);this.state.mode===e&&(this.renderer.setHandAngle(i),this.renderer.setActiveValue(t))}setAmPm(e){this.state.amPm=e}getState(){return{...this.state}}getHour(){return this.state.hour}getMinute(){return this.state.minute}getAmPm(){return this.state.amPm}updateDisabledTime(e){this.disabledTime=e}destroy(){this.renderer.destroy()}}class J{controller;clockFace;isActive=!1;isBlocked=!1;config;cachedRect=null;cachedCenter=null;cachedRadius=null;rafId=null;constructor(e,t,i={}){this.controller=e,this.clockFace=t,this.config=i}attach(){this.clockFace.addEventListener("mousedown",this.handlePointerDown),this.clockFace.addEventListener("touchstart",this.handlePointerDown,{passive:!1})}detach(){this.clockFace.removeEventListener("mousedown",this.handlePointerDown),this.clockFace.removeEventListener("touchstart",this.handlePointerDown),this.removeGlobalListeners()}block(){this.isBlocked=!0}unblock(){this.isBlocked=!1}handlePointerDown=t=>{if(e()||this.isBlocked)return;const i=t.target;i&&i.classList&&i.classList.contains("tp-ui-tips-disabled")||(t.preventDefault(),this.isActive=!0,this.cachedRect=this.clockFace.getBoundingClientRect(),this.cachedCenter=this.getClockCenter(),this.cachedRadius=this.getClockRadius(),this.processPointerEvent(t),document.addEventListener("mousemove",this.handlePointerMove),document.addEventListener("touchmove",this.handlePointerMove,{passive:!1}),document.addEventListener("mouseup",this.handlePointerUp),document.addEventListener("touchend",this.handlePointerUp))};handlePointerMove=e=>{if(!this.isActive||this.isBlocked)return;const t=this.getTargetElement(e);t&&t.classList&&t.classList.contains("tp-ui-tips-disabled")||(e.preventDefault(),null===this.rafId&&(this.rafId=requestAnimationFrame(()=>{this.rafId=null,this.processPointerEvent(e)})))};handlePointerUp=()=>{if(!this.isActive)return;null!==this.rafId&&(cancelAnimationFrame(this.rafId),this.rafId=null),this.isActive=!1,this.cachedRect=null,this.cachedCenter=null,this.cachedRadius=null,this.controller.handlePointerUp();const{autoSwitchToMinutes:e,isMobileView:t,smoothHourSnap:i,hourElement:s,minutesElement:r}=this.config;i&&s?.classList.contains("active")&&this.controller.snapToNearestHour(),this.removeGlobalListeners(),e&&s?.classList.contains("active")&&!t?(s.classList.remove("active"),r?.classList.add("active"),r?.click(),r?.focus()):r?.classList.contains("active")&&this.config.onMinuteCommit&&this.config.onMinuteCommit()};processPointerEvent(e){const t=this.getPointerPosition(e),i=this.cachedCenter||this.getClockCenter(),s=this.cachedRadius||this.getClockRadius();this.controller.handlePointerMove(t,i,s)}getPointerPosition(e){const t=this.cachedRect||this.clockFace.getBoundingClientRect();if("touches"in e){const i=e.touches[0]||e.changedTouches[0];return{x:i.clientX-t.left,y:i.clientY-t.top}}return{x:e.clientX-t.left,y:e.clientY-t.top}}getTargetElement(t){if("touches"in t){const i=t.touches[0]||t.changedTouches[0];if(i&&!e())return document.elementFromPoint(i.clientX,i.clientY)}return t.target}getClockCenter(){return{x:this.clockFace.offsetWidth/2,y:this.clockFace.offsetHeight/2}}getClockRadius(){return this.clockFace.offsetWidth/2}removeGlobalListeners(){!1!==t()&&(document.removeEventListener("mousemove",this.handlePointerMove),document.removeEventListener("touchmove",this.handlePointerMove),document.removeEventListener("mouseup",this.handlePointerUp),document.removeEventListener("touchend",this.handlePointerUp))}}class Q{renderer;controller;dragHandlers;clockType;disabledTime;tipsWrapper;tipsWrapperFor24h;constructor(e){this.clockType=e.clockType,this.disabledTime=e.disabledTime,this.tipsWrapper=e.tipsWrapper,this.tipsWrapperFor24h=e.tipsWrapperFor24h;const t={clockFace:e.clockFace,tipsWrapper:e.tipsWrapper,tipsWrapperFor24h:e.tipsWrapperFor24h,clockHand:e.clockHand,circle:e.circle,theme:e.theme};this.renderer=new X(t);const i={hour:e.initialHour,minute:e.initialMinute,amPm:e.initialAmPm,hourAngle:this.calculateInitialAngle("hours",e.initialHour),minuteAngle:this.calculateInitialAngle("minutes",e.initialMinute),mode:"hours"},s={onHourChange:e.onHourChange,onMinuteChange:e.onMinuteChange};this.controller=new G(this.renderer,i,e.clockType,e.disabledTime,e.incrementHours||1,e.incrementMinutes||1,e.smoothHourSnap??!0,s),this.dragHandlers=new J(this.controller,e.clockFace,e.dragConfig||{})}initialize(){this.dragHandlers.attach(),this.switchToHours()}switchToHours(){this.controller.switchMode("hours"),"24h"===this.clockType&&this.tipsWrapperFor24h&&this.tipsWrapperFor24h.classList.remove("none"),this.renderHourTips();const e=this.controller.getState();this.renderer.setActiveValue(e.hour)}switchToMinutes(){this.controller.switchMode("minutes"),this.tipsWrapperFor24h&&this.tipsWrapperFor24h.classList.add("none"),this.renderMinuteTips();const e=this.controller.getState();this.renderer.setActiveValue(e.minute)}setHour(e){this.controller.setValue("hours",e)}setMinute(e){this.controller.setValue("minutes",e)}setAmPm(e){this.controller.setAmPm(e);const t=this.controller.getState();"hours"===t.mode?(this.renderHourTips(),this.renderer.setHandAngle(t.hourAngle),this.renderer.setActiveValue(t.hour)):(this.renderMinuteTips(),this.renderer.setHandAngle(t.minuteAngle),this.renderer.setActiveValue(t.minute))}getHour(){return this.controller.getHour()}getMinute(){return this.controller.getMinute()}getAmPm(){return this.controller.getAmPm()}updateDisabledTime(e){this.disabledTime=e,this.controller.updateDisabledTime(e);"hours"===this.controller.getState().mode?this.renderHourTips():this.renderMinuteTips()}renderHourTips(){const e=this.controller.getState().amPm;"24h"===this.clockType?(this.renderer.renderTips(T,"tp-ui-hour-time-12","hours",this.disabledTime,this.clockType,!0,this.tipsWrapper,e),this.tipsWrapperFor24h&&this.renderer.renderTips(f,"tp-ui-hour-time-24","hours",this.disabledTime,this.clockType,!0,this.tipsWrapperFor24h,e)):this.renderer.renderTips(T,"tp-ui-hour-time-12","hours",this.disabledTime,this.clockType,!0,void 0,e)}renderMinuteTips(){const e=this.controller.getState(),t=e.amPm,i=e.hour;this.renderer.renderTips(k,"tp-ui-minutes-time","minutes",this.disabledTime,this.clockType,!0,void 0,t,i)}calculateInitialAngle(e,t){const i=parseInt(t,10);return"hours"===e?i%12*30:6*i}destroy(){this.dragHandlers.detach(),this.controller.destroy()}blockInteractions(){this.dragHandlers.block()}unblockInteractions(){this.dragHandlers.unblock()}}class ee{core;emitter;clockSystem=null;constructor(e,t){this.core=e,this.emitter=t}getClockSystem(){return this.clockSystem}initialize(){const e=this.core.getClockFace(),t=this.core.getClockHand(),i=this.core.getCircle();if(!e||!t||!i)return;const s="24h"===this.core.options.clock.type,r=this.core.getTipsWrapper();if(!r)return;const n=this.core.getHour(),o=this.core.getMinutes(),a={clockFace:e,tipsWrapper:r,tipsWrapperFor24h:s&&this.core.getTipsWrapperFor24h()||void 0,clockHand:t,circle:i,clockType:this.core.options.clock.type||"12h",disabledTime:this.convertDisabledTime(),initialHour:n?.value||"12",initialMinute:o?.value||"00",initialAmPm:this.getAmPmValue(),theme:this.core.options.ui.theme,incrementHours:this.core.options.clock.incrementHours||1,incrementMinutes:this.core.options.clock.incrementMinutes||1,smoothHourSnap:this.core.options.clock.smoothHourSnap??!0,timepicker:null,dragConfig:{autoSwitchToMinutes:this.core.options.clock.autoSwitchToMinutes,isMobileView:this.core.isMobileView,smoothHourSnap:this.core.options.clock.smoothHourSnap??!0,hourElement:n,minutesElement:o,onMinuteCommit:()=>{const e=this.core.getMinutes(),t=this.core.getHour(),i=this.core.getActiveTypeMode();this.emitter.emit("range:minute:commit",{hour:t?.value??"12",minutes:e?.value??"00",type:i?.textContent??void 0})}},onHourChange:e=>{const t=this.core.getHour();t&&(t.value=e,t.setAttribute("aria-valuenow",e));const i=this.core.getModalElement();q(i,`Hour: ${e}`);const s=this.core.getMinutes(),r=this.core.getActiveTypeMode();this.emitter.emit("update",{hour:e,minutes:s?.value,type:r?.textContent||void 0})},onMinuteChange:e=>{const t=this.core.getMinutes();t&&(t.value=e,t.setAttribute("aria-valuenow",e));const i=this.core.getModalElement();q(i,`Minutes: ${e}`);const s=this.core.getHour(),r=this.core.getActiveTypeMode();this.emitter.emit("update",{hour:s?.value,minutes:e,type:r?.textContent||void 0})}};this.clockSystem=new Q(a),this.clockSystem.initialize()}convertDisabledTime(){const e=this.core.disabledTime?.value;if(!e)return null;let t;return e.intervals&&(t=Array.isArray(e.intervals)?e.intervals:[e.intervals]),{hours:e.hours,minutes:e.minutes,isInterval:e.isInterval,intervals:t,clockType:e.clockType}}getAmPmValue(){if("24h"===this.core.options.clock.type)return"";const e=this.core.getActiveTypeMode();if(e){const t=e.textContent?.trim();if("AM"===t||"PM"===t)return t}const t=this.core.getAM();return!0===this.core.options.range?.enabled?t?.classList.contains("active")?"AM":"":t?.classList.contains("active")?"AM":"PM"}destroy(){this.clockSystem&&(this.clockSystem.destroy(),this.clockSystem=null)}}class te{core;constructor(e){this.core=e}removeCircleClockClasses24h(){const e=this.core.getCircle(),t=this.core.getClockHand();e?.classList.remove("tp-ui-circle-hand-24h"),t?.classList.remove("tp-ui-clock-hand-24h")}setCircleClockClasses24h(){const e=this.core.getCircle(),t=this.core.getClockHand();e&&e.classList.add("tp-ui-circle-hand-24h"),t&&t.classList.add("tp-ui-clock-hand-24h")}setOnStartCSSClassesIfClockType24h(){if("24h"===this.core.options.clock.type){const e=this.core.getInput();if(!e)return;let t;e.value.length>0&&(t=e.value.split(":")[0]),t&&(Number(t)>12||0===Number(t))&&this.setCircleClockClasses24h()}}setBgColorToCircleWithMinutesTips(){const e=this.core.getMinutes(),t=this.core.getCircle();if(e&&t&&e.value&&k.includes(e.value)){const e=getComputedStyle(t).getPropertyValue("--timepicker-primary").trim();e&&(t.style.backgroundColor=e),t.classList.remove("small-circle")}}removeBgColorToCirleWithMinutesTips(){const e=this.core.getMinutes(),t=this.core.getCircle();e&&t&&(e.value&&k.includes(e.value)||(t.style.backgroundColor="",t.classList.add("small-circle")))}setClassActiveToHourOnOpen(){if(this.core.options.ui.mobile||this.core.isMobileView)return;const e=this.core.getHour();e?.classList.add(E)}toggleClassActiveToValueTips(e,t){if(e)return;const i=this.core.getAllValueTips();if(!i)return;const s=i.find(e=>Number(e.innerText)===Number(t));i.forEach(e=>{e.classList.remove(E),e.setAttribute("aria-selected","false")}),void 0!==s&&(s.classList.add(E),s.setAttribute("aria-selected","true"))}}class ie{getClockSystem;styleHandler;getAmPmValue;clockType;constructor(e,t,i,s){this.getClockSystem=e,this.styleHandler=t,this.getAmPmValue=i,this.clockType=s}setMinutesToClock(e){const t=this.getClockSystem();t&&(this.styleHandler.removeBgColorToCirleWithMinutesTips(),e&&t.setMinute(e),t.switchToMinutes())}setHoursToClock(e){const t=this.getClockSystem();t&&(e&&t.setHour(e),t.switchToHours())}setTransformToCircleWithSwitchesHour(e){const t=this.getClockSystem();t&&e&&t.setHour(e)}setTransformToCircleWithSwitchesMinutes(e){const t=this.getClockSystem();t&&e&&t.setMinute(e)}updateAmPm(){const e=this.getClockSystem();if(!e||"24h"===this.clockType)return;const t=this.getAmPmValue();""!==t&&e.setAmPm(t)}}class se{systemInitializer;styleHandler;timeHandler;eventHandler;constructor(e,t){this.systemInitializer=new ee(e,t),this.styleHandler=new te(e);const i=e.options.clock.type||"12h";this.timeHandler=new ie(()=>this.systemInitializer.getClockSystem(),this.styleHandler,()=>this.systemInitializer.getAmPmValue(),i),this.eventHandler=new Z(t,()=>this.systemInitializer.getClockSystem(),e=>this.timeHandler.setHoursToClock(e),e=>this.timeHandler.setMinutesToClock(e),()=>this.timeHandler.updateAmPm(),()=>this.systemInitializer.convertDisabledTime()),this.eventHandler.setup()}initializeClockSystem(){this.systemInitializer.initialize()}destroyClockSystem(){this.systemInitializer.destroy()}removeCircleClockClasses24h(){this.styleHandler.removeCircleClockClasses24h()}setCircleClockClasses24h(){this.styleHandler.setCircleClockClasses24h()}setOnStartCSSClassesIfClockType24h(){this.styleHandler.setOnStartCSSClassesIfClockType24h()}setBgColorToCircleWithMinutesTips=()=>{this.styleHandler.setBgColorToCircleWithMinutesTips()};removeBgColorToCirleWithMinutesTips=()=>{this.styleHandler.removeBgColorToCirleWithMinutesTips()};setClassActiveToHourOnOpen=()=>{this.styleHandler.setClassActiveToHourOnOpen()};setMinutesToClock=e=>{this.timeHandler.setMinutesToClock(e)};setHoursToClock=e=>{this.timeHandler.setHoursToClock(e)};setTransformToCircleWithSwitchesHour=e=>{this.timeHandler.setTransformToCircleWithSwitchesHour(e)};setTransformToCircleWithSwitchesMinutes=e=>{this.timeHandler.setTransformToCircleWithSwitchesMinutes(e)};updateAmPm=()=>{this.timeHandler.updateAmPm()};toggleClassActiveToValueTips=e=>{const t=null!==this.systemInitializer.getClockSystem();this.styleHandler.toggleClassActiveToValueTips(t,e)};destroy(){this.destroyClockSystem()}}const re=new class{plugins=new Map;register(e){this.plugins.has(e.name)||this.plugins.set(e.name,e)}getAll(){return Array.from(this.plugins.values())}has(e){return this.plugins.has(e)}get(e){return this.plugins.get(e)}};class ne{animation;modal;config;theme;validation;events;clock;plugins=new Map;constructor(e,t){this.animation=new h(e,t),this.modal=new M(e,t),this.config=new $(e,t),this.theme=new P(e,t),this.validation=new V(e,t),this.events=new U(e,t),this.clock=new se(e,t);re.getAll().forEach(i=>{const s=i.factory(e,t);this.plugins.set(i.name,s)})}getPlugin(e){return this.plugins.get(e)}destroy(){this.animation.destroy(),this.modal.destroy(),this.config.destroy(),this.theme.destroy(),this.validation.destroy(),this.events.destroy(),this.clock.destroy(),this.plugins.forEach(e=>e.destroy()),this.plugins.clear()}}const oe="is-rippling",ae="ripple-hold";let le=null;function ce(e){const t=e.target,i=t.hasAttribute("data-md3-ripple")?t:t.closest("[data-md3-ripple]");if(!i)return;if(0!==e.button&&"mouse"===e.pointerType)return;const s=i.getBoundingClientRect(),r=2*Math.max(s.width,s.height),n=e.clientX-s.left,o=e.clientY-s.top;i.style.setProperty("--ripple-size",`${r}px`),i.style.setProperty("--ripple-x",`${n}px`),i.style.setProperty("--ripple-y",`${o}px`),i.classList.remove(oe,ae),i.offsetWidth,i.classList.add(oe,ae),i._rippleHold=!0,le=i}function ue(e){const t=e.target,i=(t.hasAttribute("data-md3-ripple")?t:t.closest("[data-md3-ripple]"))||le;i&&(i._rippleHold=!1,i.classList.remove(ae),setTimeout(()=>{i.classList.remove(oe),le===i&&(le=null)},1e3))}function he(e){const t=e.currentTarget;t&&t._rippleHold&&(t._rippleHold=!1,t.classList.remove(ae),setTimeout(()=>{t.classList.remove(oe),le===t&&(le=null)},1e3))}class de{core;managers;emitter;eventsClickMobileHandler=()=>{};mutliEventsMoveHandler=()=>{};constructor(e,t,i){this.core=e,this.managers=t,this.emitter=i}init(){if(!this.core.isDestroyed&&!this.core.isInitialized){try{this.managers.config.updateInputValueWithCurrentTimeOnStart(),this.managers.validation.checkDisabledValuesOnStart()}catch(e){return void this.core.setIsDestroyed(!0)}this.managers.theme.setTimepickerClassToElement(),this.managers.theme.setInputClassToInputElement(),this.managers.theme.setDataOpenToInputIfDoesntExistInWrapper(),this.managers.theme.setClassTopOpenElement(),this.managers.config.getDisableTime(),this.core.options.ui.inline?.enabled||this.managers.events.handleOpenOnClick(),this.managers.events.handleOpenOnEnterFocus(),this.setupCallbackBridge(),this.core.setIsInitialized(!0)}}setupCallbackBridge(){const{callbacks:e}=this.core.options;e.onOpen&&this.emitter.on("open",e.onOpen),e.onCancel&&this.emitter.on("cancel",e.onCancel),e.onConfirm&&this.emitter.on("confirm",e.onConfirm),e.onUpdate&&this.emitter.on("update",e.onUpdate),e.onSelectHour&&this.emitter.on("select:hour",e.onSelectHour),e.onSelectMinute&&this.emitter.on("select:minute",e.onSelectMinute),e.onSelectAM&&this.emitter.on("select:am",e.onSelectAM),e.onSelectPM&&this.emitter.on("select:pm",e.onSelectPM),e.onError&&this.emitter.on("error",e.onError),e.onTimezoneChange&&this.emitter.on("timezone:change",e.onTimezoneChange),e.onRangeConfirm&&this.emitter.on("range:confirm",e.onRangeConfirm),e.onRangeSwitch&&this.emitter.on("range:switch",e.onRangeSwitch),e.onRangeValidation&&this.emitter.on("range:validation",e.onRangeValidation)}mount(){this.core.isDestroyed||(this.core.isInitialized||this.init(),this.eventsBundle())}unmount(e){const i=((e,t)=>{let i;return(...s)=>{clearTimeout(i),i=setTimeout(()=>{e(...s)},t)}})((...e)=>{if(e.length>2||!this.core.getModalElement())return;const[i]=e.filter(e=>"boolean"==typeof e),[s]=e.filter(e=>"function"==typeof e);if(this.core.setIsMobileView(!!this.core.options.ui.mobile),i){const e=this.core.getOkButton();e?.click()}this.core.setIsTouchMouseMove(!1),this.removeEventListeners(),this.managers.animation.removeAnimationToClose();this.core.getOpenElement().forEach(e=>e?.classList.remove("disabled")),setTimeout(()=>{t()&&(document.body.style.overflowY="",document.body.style.paddingRight="")},n),setTimeout(()=>{const e=this.core.getInput();this.core.options.behavior.focusInputAfterClose&&e?.focus();const t=this.core.getModalElement();null!==t&&(t.remove(),this.core.setIsModalRemove(!0))},o),s&&s()},this.core.options.behavior.delayHandler||s);e?i(e):i()}destroy(t){if(this.core.isDestroyed)return;const i="function"==typeof t?{callback:t}:t||{},{keepInputValue:s=!1,callback:r}=i,n=this.core.getInput(),o=s?n?.value:null;this.removeEventListeners();const a=this.core.getModalElement();a?.remove();const l=this.core.getOpenElement();l?.forEach(e=>{e&&(e.classList.remove("disabled","active","tp-ui-open-element"),e.classList.remove("basic","crane-straight","crane","m2","m3-green"))}),n&&(n.classList.remove("tp-ui-invalid-format","invalid-value","error","active","tp-ui-input"),n.removeAttribute("data-open"),n.removeAttribute("data-owner-id"),s&&o&&(n.value=o));const c=this.core.element;c&&(c.classList.remove("basic","crane-straight","crane","m2","m3-green"),c.classList.remove("error","active","disabled"),c.removeAttribute("data-owner-id"),c.removeAttribute("data-open"),this.core.options.ui.cssClass&&c.classList.remove(this.core.options.ui.cssClass));const u=c?.querySelectorAll(".tp-ui-invalid-text");u?.forEach(e=>e.remove()),this.mutliEventsMoveHandler=()=>{},this.eventsClickMobileHandler=()=>{},this.core.reset(),this.managers.destroy(),this.emitter.clear(),e()||(document.body.style.overflowY="",document.body.style.paddingRight=""),r&&r()}eventsBundle(){if(this.core.isDestroyed)return;if(!this.core.isModalRemove)return;if(this.managers.validation.setErrorHandler(),this.managers.validation.removeErrorHandler(),!this.core.options.ui.inline?.enabled){const e=this.core.getOpenElement(),t=this.core.getInput();e.forEach(e=>e?.classList.add("disabled")),t?.blur()}if(this.managers.modal.setScrollbarOrNot(),this.managers.modal.setModalTemplate(),this.managers.modal.setNormalizeClass(),this.managers.modal.removeBackdrop(),this.core.isMobileView)this.managers.config.updateClockFaceAccessibility(!0);else{const e=this.core.getModalElement(),t=e?.querySelector(".tp-ui-mobile-clock-wrapper"),i=e?.querySelector(".tp-ui-wrapper"),s=e?.querySelectorAll("*");t?.classList.add("expanded"),i?.classList.add("expanded"),s?.forEach(e=>{e.classList.contains("tp-ui-select-time")||e.classList.contains("tp-ui-mobile-clock-wrapper")||e.classList.contains("tp-ui-wrapper")||e.classList.add("expanded")})}this.managers.modal.setFlexEndToFooterIfNoKeyboardIcon(),setTimeout(()=>{this.managers.theme.setTheme();const e=this.core.getWrapper();e&&this.core.options.ui.cssClass&&e.classList.add(this.core.options.ui.cssClass)},0),this.managers.animation.setAnimationToOpen(),this.managers.config.getInputValueOnOpenAndSet(),this.managers.clock.initializeClockSystem(),this.managers.clock.setOnStartCSSClassesIfClockType24h(),this.managers.clock.setClassActiveToHourOnOpen();const e=this.managers.getPlugin("timezone");e&&e.init();const i=this.managers.getPlugin("range");i&&i.init(),this.managers.events.handleCancelButton(),this.managers.events.handleOkButton(),this.managers.events.handleHourEvents(),this.managers.events.handleMinutesEvents(),this.managers.events.handleKeyboardInput(),this.core.options.ui.enableSwitchIcon&&this.managers.events.handleSwitchViewButton(),"24h"!==this.core.options.clock.type&&(this.managers.events.handleAmClick(),this.managers.events.handlePmClick()),this.core.options.behavior.focusTrap&&this.managers.events.focusTrapHandler(),this.core.options.ui.inline?.enabled||(this.managers.events.handleEscClick(),this.managers.events.handleBackdropClick());const s=this.core.getModalElement();s&&function(e){if(!1===t())return;const i=e||document;i.addEventListener("pointerdown",ce),i.addEventListener("pointerup",ue),i.addEventListener("pointercancel",ue),i.querySelectorAll("[data-md3-ripple]").forEach(e=>{e.addEventListener("mouseleave",he)})}(s);const r=this.core.getClockFace();r&&"undefined"!=typeof requestAnimationFrame&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{r?.classList.add("scale-in")})}),this.managers.modal.setShowClassToBackdrop()}removeEventListeners(){if(!1===t())return;A.split(" ").forEach(e=>{document.removeEventListener(e,this.mutliEventsMoveHandler,!1)}),document.removeEventListener("mousedown",this.eventsClickMobileHandler)}}class me{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(e=>{e(t)})}clear(){this.events.clear()}hasListeners(e){return(this.events.get(e)?.size??0)>0}}const pe={type:"12h",incrementHours:1,incrementMinutes:1,autoSwitchToMinutes:!0,disabledTime:void 0,currentTime:void 0},ge={theme:"basic",animation:!0,backdrop:!0,mobile:!1,enableSwitchIcon:!1,editable:!1,enableScrollbar:!1,cssClass:void 0,appendModalSelector:"",iconTemplate:"",iconTemplateMobile:"",inline:void 0},ve={am:"AM",pm:"PM",ok:"OK",cancel:"Cancel",time:"Select time",mobileTime:"Enter Time",mobileHour:"Hour",mobileMinute:"Minute"},be={focusInputAfterClose:!1,focusTrap:!0,delayHandler:300,id:void 0},ye={onOpen:void 0,onCancel:void 0,onConfirm:void 0,onUpdate:void 0,onSelectHour:void 0,onSelectMinute:void 0,onSelectAM:void 0,onSelectPM:void 0,onError:void 0,onTimezoneChange:void 0,onRangeConfirm:void 0,onRangeSwitch:void 0,onRangeValidation:void 0},fe={enabled:!1,default:void 0,whitelist:void 0,label:"Timezone"},Te={enabled:!1,minDuration:void 0,maxDuration:void 0,fromLabel:"From",toLabel:"To"};const ke=new Map;return class{core;managers;lifecycle;emitter;constructor(t,s){if(e())throw new Error("TimepickerUI requires browser environment");const r=this.resolveInputElement(t);if(!r)throw new Error("Input element not found");const n=s?.behavior?.id,o=n||`tp-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)})}`,a=this.createWrapperElement(r),l=function(e={}){return{clock:{...pe,...e.clock||{}},ui:{...ge,...e.ui||{}},labels:{...ve,...e.labels||{}},behavior:{...be,...e.behavior||{}},callbacks:{...ye,...e.callbacks||{}},timezone:{...fe,...e.timezone||{}},range:{...Te,...e.range||{}}}}(s||{});if(l.ui.inline?.enabled&&void 0===s?.behavior?.focusTrap&&(l.behavior.focusTrap=!1),l.ui.inline?.enabled){if(!l.ui.inline.containerId)throw new Error("inline.containerId is required when inline mode is enabled");if(!e()){if(!document.getElementById(l.ui.inline.containerId))throw new Error(`Container element with id "${l.ui.inline.containerId}" not found`)}}this.emitter=new me,this.core=new i(a,l,o,n);const c=this.core.getInput();if(c){const e=C(c,l.clock.type),t=30*Number(e.hour),i=6*Number(e.minutes);this.core.setDegreesHours(t),this.core.setDegreesMinutes(i)}this.managers=new ne(this.core,this.emitter),this.lifecycle=new de(this.core,this.managers,this.emitter),this.managers.config.checkMobileOption(),this.managers.config.preventClockTypeByCurrentTime(),this.setupInternalEventListeners(),ke.set(this.core.instanceId,this)}setupInternalEventListeners(){this.emitter.on("show",()=>{this.core.isDestroyed||this.lifecycle.mount()}),this.emitter.on("cancel",()=>{this.core.isDestroyed||this.lifecycle.unmount()}),this.emitter.on("confirm",e=>{if(!this.core.isDestroyed){if(this.core.options.range?.enabled)return;const t=this.core.getInput();if(t&&e.hour&&e.minutes){const i=e.type?` ${e.type}`:"";t.value=`${e.hour}:${e.minutes}${i}`}this.lifecycle.unmount()}}),this.emitter.on("range:confirm",e=>{if(this.core.isDestroyed)return;const t=this.core.getInput();t&&(t.value=`${e.from} - ${e.to}`),this.lifecycle.unmount()})}create(){this.lifecycle.init(),this.core.options.ui.inline?.enabled&&this.lifecycle.mount()}open(e){this.lifecycle.mount(),e&&e()}close(e,t){this.lifecycle.unmount(e?t:void 0),!e&&t&&t()}destroy(e){ke.delete(this.core.instanceId),this.lifecycle.destroy(e)}update(e,t){this.core.isDestroyed||(this.core.updateOptions(e.options),this.managers.config.checkMobileOption(),e.create&&this.create(),t&&t())}getValue(){if(this.core.isDestroyed)return{hour:"",minutes:"",type:void 0,time:"",degreesHours:null,degreesMinutes:null};const e=this.core.getHour(),t=this.core.getMinutes(),i=this.core.getActiveTypeMode(),s=e?.value||"12",r=t?.value||"00",n="24h"===this.core.options.clock.type?void 0:i?.textContent||"AM";let o="";return o="24h"===this.core.options.clock.type?`${s.padStart(2,"0")}:${r.padStart(2,"0")}`:`${s}:${r.padStart(2,"0")} ${n}`,{hour:s,minutes:r,type:n,time:o,degreesHours:this.core.degreesHours,degreesMinutes:this.core.degreesMinutes}}setValue(e,t=!0){if(this.core.isDestroyed)return;if(!e||"string"!=typeof e)return;this.core.isInitialized||this.create();const i=e.trim().replace(/[^0-9:APMapm\s]/g,"");let s="12",r="00",n="AM";try{if("24h"===this.core.options.clock.type){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()}const e=this.core.getHour(),o=this.core.getMinutes(),a=this.core.getAM(),l=this.core.getPM();if(e&&(e.value=s,e.setAttribute("aria-valuenow",s),this.core.setDegreesHours(30*Number(s))),o&&(o.value=r,o.setAttribute("aria-valuenow",r),this.core.setDegreesMinutes(6*Number(r))),"24h"!==this.core.options.clock.type&&a&&l&&("AM"===n?(a.classList.add("active"),l.classList.remove("active")):(l.classList.add("active"),a.classList.remove("active"))),t){const e=this.core.getInput();e&&(e.value=i)}const c=this.core.getClockHand();c&&(c.style.transform=`rotateZ(${this.core.degreesHours||0}deg)`)}catch(e){return}}getElement(){return this.core.element}get instanceId(){return this.core.instanceId}get options(){return this.core.options}get isInitialized(){return this.core.isInitialized}get isDestroyed(){return this.core.isDestroyed}get hour(){return this.core.getHour()}get minutes(){return this.core.getMinutes()}get okButton(){return this.core.getOkButton()}get cancelButton(){return this.core.getCancelButton()}get clockHand(){return this.core.getClockHand()}on(e,t){this.core.isDestroyed||this.emitter.on(e,t)}once(e,t){this.core.isDestroyed||this.emitter.once(e,t)}off(e,t){this.core.isDestroyed||this.emitter.off(e,t)}resolveInputElement(e){if(!1===t())return null;let i=null;if("string"==typeof e){if(i=document.querySelector(e),!i)return null}else{if(!(e instanceof HTMLElement))return null;i=e}if("INPUT"===i.tagName)return i;return i.querySelector("input")}createWrapperElement(e){if(!1===t())return e;const i=e.parentElement;if("INPUT"===e.tagName&&!i?.classList.contains("tp-ui")){const t=document.createElement("div");return t.className="tp-ui",e.parentNode?.insertBefore(t,e),t.appendChild(e),t}return i&&!i.classList.contains("tp-ui")&&i.classList.add("tp-ui"),i||e}static getById(e){return ke.get(e)}static getAllInstances(){return Array.from(ke.values())}static isAvailable(t){return!e()&&("string"==typeof t?null!==document.querySelector(t):t instanceof HTMLElement&&document.contains(t))}static destroyAll(){Array.from(ke.values()).forEach(e=>e.destroy()),ke.clear()}}});
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).TimepickerUI=t()}(this,function(){"use strict";const e=()=>"undefined"==typeof window,t=()=>"undefined"!=typeof document;class i{state;constructor(e,t,i,s){this.state={degreesHours:null,degreesMinutes:null,options:t,element:e,instanceId:i,isMobileView:!1,isTouchMouseMove:!1,disabledTime:null,cloned:null,isModalRemove:!0,isInitialized:!1,customId:s,eventHandlersRegistered:!1,isDestroyed:!1}}get degreesHours(){return this.state.degreesHours}get degreesMinutes(){return this.state.degreesMinutes}get options(){return this.state.options}get element(){return this.state.element}get instanceId(){return this.state.instanceId}get isMobileView(){return this.state.isMobileView}get isTouchMouseMove(){return this.state.isTouchMouseMove}get disabledTime(){return this.state.disabledTime}get cloned(){return this.state.cloned}get isModalRemove(){return this.state.isModalRemove}get isInitialized(){return this.state.isInitialized}get customId(){return this.state.customId}get eventHandlersRegistered(){return this.state.eventHandlersRegistered}get isDestroyed(){return this.state.isDestroyed}setDegreesHours(e){this.state={...this.state,degreesHours:e}}setDegreesMinutes(e){this.state={...this.state,degreesMinutes:e}}setOptions(e){this.state={...this.state,options:e}}setIsMobileView(e){this.state={...this.state,isMobileView:e}}setIsTouchMouseMove(e){this.state={...this.state,isTouchMouseMove:e}}setDisabledTime(e){this.state={...this.state,disabledTime:e}}setCloned(e){this.state={...this.state,cloned:e}}setIsModalRemove(e){this.state={...this.state,isModalRemove:e}}setIsInitialized(e){this.state={...this.state,isInitialized:e}}setEventHandlersRegistered(e){this.state={...this.state,eventHandlersRegistered:e}}setIsDestroyed(e){this.state={...this.state,isDestroyed:e}}updateOptions(e){this.state={...this.state,options:{...this.state.options,clock:{...this.state.options.clock,...e.clock||{}},ui:{...this.state.options.ui,...e.ui||{}},labels:{...this.state.options.labels,...e.labels||{}},behavior:{...this.state.options.behavior,...e.behavior||{}},callbacks:{...this.state.options.callbacks,...e.callbacks||{}}}}}reset(){this.state={...this.state,degreesHours:null,degreesMinutes:null,isTouchMouseMove:!1,disabledTime:null,cloned:null,isModalRemove:!0,isInitialized:!1,isDestroyed:!0,eventHandlersRegistered:!1}}getModalElement(){return!1===t()?null:document.querySelector(`[data-owner-id="${this.state.instanceId}"]`)}getInput(){return this.state.element?.querySelector("input")}getClockFace(){const e=this.getModalElement();return e?this.state.isMobileView?e.querySelector(".tp-ui-clock-face.mobile"):e.querySelector(".tp-ui-clock-face:not(.mobile)"):null}getClockHand(){const e=this.getModalElement();return e?this.state.isMobileView?e.querySelector(".tp-ui-mobile-clock-wrapper .tp-ui-clock-hand"):e.querySelector(".tp-ui-clock-hand:not(.mobile)"):null}getCircle(){const e=this.getModalElement();return e?this.state.isMobileView?e.querySelector(".tp-ui-mobile-clock-wrapper .tp-ui-circle-hand"):e.querySelector(".tp-ui-circle-hand:not(.mobile)"):null}getTipsWrapper(){const e=this.getModalElement();return e?this.state.isMobileView?e.querySelector(".tp-ui-mobile-clock-wrapper .tp-ui-tips-wrapper"):e.querySelector(".tp-ui-tips-wrapper:not(.mobile)"):null}getTipsWrapperFor24h(){const e=this.getModalElement();return e?this.state.isMobileView?e.querySelector(".tp-ui-mobile-clock-wrapper .tp-ui-tips-wrapper-24h"):e.querySelector(".tp-ui-tips-wrapper-24h:not(.mobile)"):null}getMinutes(){const e=this.getModalElement();return e?.querySelector(".tp-ui-minutes")||null}getHour(){const e=this.getModalElement();return e?.querySelector(".tp-ui-hour")||null}getAM(){const e=this.getModalElement();return e?.querySelector(".tp-ui-am")||null}getPM(){const e=this.getModalElement();return e?.querySelector(".tp-ui-pm")||null}getHourText(){const e=this.getModalElement();return e?.querySelector(".tp-ui-hour-text")||null}getMinutesText(){const e=this.getModalElement();return e?.querySelector(".tp-ui-minute-text")||null}getHeader(){const e=this.getModalElement();return e?.querySelector(".tp-ui-header")||null}getInputWrappers(){const e=this.getModalElement();return e?.querySelectorAll(".tp-ui-input-wrapper")||null}getDots(){const e=this.getModalElement();return e?.querySelector(".tp-ui-dots")||null}getMinutesTips(){const e=this.getModalElement();return e?.querySelector(".tp-ui-minutes-time")||null}getHourTips(){const e=this.getModalElement();return e?.querySelector(".tp-ui-hour-time-12")||null}getAllValueTips(){const e=this.getModalElement();return e?[...e.querySelectorAll(".tp-ui-value-tips"),...e.querySelectorAll(".tp-ui-value-tips-24h")]:[]}getOpenElementData(){const e=this.state.element?.querySelectorAll("[data-open]");if(e?.length>0){const t=[];return e.forEach(({dataset:e})=>t.push(e.open??"")),[...new Set(t)]}return null}getOpenElement(){const e=this.getInput(),t=this.getOpenElementData();return null===t?(e?.setAttribute("data-open","tp-ui-input"),[e]):t.map(e=>this.state.element?.querySelectorAll(`[data-open='${e}']`))[0]??""}getCancelButton(){const e=this.getModalElement();return e?.querySelector(".tp-ui-cancel-btn")||null}getOkButton(){const e=this.getModalElement();return e?.querySelector(".tp-ui-ok-btn")||null}getActiveTypeMode(){const e=this.getModalElement();return e?.querySelector(".tp-ui-type-mode.active")||null}getKeyboardClockIcon(){const e=this.getModalElement();return e?.querySelector(".tp-ui-keyboard-icon-wrapper")||null}getFooter(){const e=this.getModalElement();return e?.querySelector(".tp-ui-footer")||null}getWrapper(){const e=this.getModalElement();return e?.querySelector(".tp-ui-wrapper")||null}}const s=300,r=150,n=400,o=300,a=600,l=401,c=450,u=150;class h{core;emitter;timeouts=[];constructor(e,t){this.core=e,this.emitter=t,this.setupEventListeners()}setupEventListeners(){this.emitter.on("animation:clock",()=>{this.handleAnimationSwitchTipsMode()})}runWithAnimation(e,t=r){if(this.core.options.ui.animation){const i=setTimeout(e,t);this.timeouts.push(i)}else e()}clearAllTimeouts(){this.timeouts.forEach(clearTimeout),this.timeouts=[]}setAnimationToOpen(){this.clearAllTimeouts();const e=this.core.getModalElement();e?.classList.add("opacity"),this.runWithAnimation(()=>{this.core.getModalElement()?.classList.add("show")})}removeAnimationToClose(){this.clearAllTimeouts();this.core.getModalElement()&&this.runWithAnimation(()=>{const e=this.core.getModalElement();e?.classList.remove("show"),e?.classList.remove("opacity")})}handleAnimationClock(){this.core.options.ui.animation&&this.runWithAnimation(()=>{const e=this.core.getClockFace();e?.classList.add("tp-ui-clock-animation");const t=setTimeout(()=>{this.core.getClockFace()?.classList.remove("tp-ui-clock-animation")},a);this.timeouts.push(t)})}handleAnimationSwitchTipsMode(){const e=this.core.getClockHand();if(!e)return;this.emitter.emit("animation:start",{}),e.classList.add("tp-ui-tips-animation");const t=setTimeout(()=>{this.core.getClockHand()?.classList.remove("tp-ui-tips-animation"),this.emitter.emit("animation:end",{})},l);this.timeouts.push(t)}destroy(){this.clearAllTimeouts()}}const d=(e,t)=>Array.from({length:Number(t)-Number(e)+1},(t,i)=>Number(e)+i),m=(e,t)=>Array.from({length:Number(t)-Number(e)+1},(e,i)=>Number(t)-i).reverse(),p=(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")}`},g=e=>{const[t,i]=e.split(":");return`${t.padStart(2,"0")}:${i.padStart(2,"0")}`},v=(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: "${e}"`);r=p(i.trim()),n=p(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: "${e}"`);r=g(i.trim()),n=g(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 intervals: "${s.original}" and "${r.original}"`)}return!1};var b='<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#e3e3e3"><path d="M160-200q-33 0-56.5-23.5T80-280v-400q0-33 23.5-56.5T160-760h640q33 0 56.5 23.5T880-680v400q0 33-23.5 56.5T800-200H160Zm0-80h640v-400H160v400Zm160-40h320v-80H320v80ZM200-440h80v-80h-80v80Zm120 0h80v-80h-80v80Zm120 0h80v-80h-80v80Zm120 0h80v-80h-80v80Zm120 0h80v-80h-80v80ZM200-560h80v-80h-80v80Zm120 0h80v-80h-80v80Zm120 0h80v-80h-80v80Zm120 0h80v-80h-80v80Zm120 0h80v-80h-80v80ZM160-280v-400 400Z"/></svg>',y='<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#e3e3e3"><path d="m612-292 56-56-148-148v-184h-80v216l172 172ZM480-80q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-400Zm0 320q133 0 226.5-93.5T800-480q0-133-93.5-226.5T480-800q-133 0-226.5 93.5T160-480q0 133 93.5 226.5T480-160Z"/></svg>';const f=["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"],k=["00","05","10","15","20","25","30","35","40","45","50","55"];class M{core;emitter;timeouts=[];originalOverflow;originalPaddingRight;constructor(e,t){this.core=e,this.emitter=t}runWithTimeout(e,t=s){const i=setTimeout(e,t);this.timeouts.push(i)}clearAllTimeouts(){this.timeouts.forEach(clearTimeout),this.timeouts=[]}clearExistingModal(){if(!1===t())return;const e=document.querySelector(".tp-ui-modal");e&&e.remove()}setModalTemplate(){if(!1===t())return;this.clearExistingModal();const e=((e,t)=>{const{ui:{iconTemplate:i,enableSwitchIcon:s,animation:r,theme:n,mobile:o,editable:a,iconTemplateMobile:l},labels:{time:c,mobileTime:u,am:h,pm:d,cancel:m,ok:p,mobileMinute:g,mobileHour:v},clock:{type:f},timezone:{enabled:T,label:k},range:{enabled:M,fromLabel:C,toLabel:H}}=e,A=o?"mobile":"";return`<div class="tp-ui-modal normalize ${A}${M?" tp-ui-range-mode":""}" data-theme="${n}" role="dialog" aria-modal="true" aria-labelledby="tp-ui-label-${t}" data-owner-id="${t}" style='transition:${r?"opacity 0.15s linear":"none"}'><div class="tp-ui-wrapper ${A}" tabindex="0">${M?`<div class="tp-ui-range-header" role="tablist" aria-label="Range selection"><button type="button" class="tp-ui-range-tab tp-ui-range-from active" role="tab" tabindex="0" aria-selected="true"><span class="tp-ui-range-tab-label">${C}</span><span class="tp-ui-range-tab-value tp-ui-range-from-time">--:--</span></button><button type="button" class="tp-ui-range-tab tp-ui-range-to" role="tab" tabindex="-1" aria-selected="false"><span class="tp-ui-range-tab-label">${H}</span><span class="tp-ui-range-tab-value tp-ui-range-to-time">--:--</span></button></div>`:""}<div class="tp-ui-select-time ${A}" id="tp-ui-label-${t}">${A?u:c}</div><div class="tp-ui-header ${A}"><div class="tp-ui-wrapper-time ${A} ${"24h"===f?"tp-ui-wrapper-time-24h":""}" role="group" aria-label="${A?u:c}"><div class="tp-ui-input-wrapper ${A}"><div class="tp-ui-input-ripple-wrapper ${A}" data-md3-ripple><input name="hour" ${a||A?"":"readonly"} class="tp-ui-hour ${A}" tabindex="0" type="number" min="0" max="${"12h"===f?"12":"23"}" aria-label="${A?v:"Hour"}" role="spinbutton" aria-valuenow="12"></div><div class="tp-ui-hour-text ${A}">${v}</div></div><div class="tp-ui-dots ${A}" aria-hidden="true"><span></span><span></span></div><div class="tp-ui-input-wrapper ${A}"><div class="tp-ui-input-ripple-wrapper ${A}" data-md3-ripple><input name="minutes" ${a||A?"":"readonly"} class="tp-ui-minutes ${A}" tabindex="0" type="number" min="0" max="59" aria-label="${A?g:"Minute"}" role="spinbutton" aria-valuenow="0"></div><div class="tp-ui-minute-text ${A}">${g}</div></div></div>${"24h"!==f?`<div class="tp-ui-wrapper-type-time ${A}" role="group" aria-label="Period"><div class="tp-ui-type-mode tp-ui-am ${A?"mobile":"tp-ui-ripple"}" data-md3-ripple tabindex="0" role="button" aria-label="${h}" aria-pressed="false" data-type="AM">${h}</div><div class="tp-ui-type-mode tp-ui-pm ${A?"mobile":"tp-ui-ripple"}" data-md3-ripple tabindex="0" role="button" aria-label="${d}" aria-pressed="false" data-type="PM">${d}</div></div>`:""}</div>${T?`<div class="tp-ui-timezone ${A}">\n <span class="tp-ui-timezone-label" id="tp-tz-label-${t}">${k}</span>\n <div class="tp-ui-timezone-dropdown" role="combobox" aria-expanded="false" aria-haspopup="listbox" aria-labelledby="tp-tz-label-${t}" tabindex="0" data-tz-id="${t}">\n <div class="tp-ui-timezone-selected" data-placeholder="${k}...">${k}...</div>\n <svg class="tp-ui-timezone-arrow" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 9 12 15 18 9"></polyline></svg>\n <div class="tp-ui-timezone-menu" role="listbox" aria-labelledby="tp-tz-label-${t}"></div>\n </div>\n </div>`:""}<div class="tp-ui-mobile-clock-wrapper ${A}"><div class="tp-ui-body ${A}"><div class="tp-ui-clock-face ${A}" role="group" aria-label="Clock"><div class="tp-ui-dot ${A}" aria-hidden="true"></div><div class="tp-ui-clock-hand ${A}" aria-hidden="true"><div class="tp-ui-circle-hand ${A}"></div></div><div class="tp-ui-tips-wrapper ${A}" role="listbox" aria-label="Time"></div>${"24h"===f?`<div class="tp-ui-tips-wrapper-24h ${A}" role="listbox" aria-label="24h"></div>`:""}</div></div></div><div class="tp-ui-footer ${A}" ${A?'data-view="mobile"':""}>${s?`<div class="tp-ui-keyboard-icon-wrapper ${A}" tabindex="0" role="button" aria-pressed="false" aria-label="Toggle" data-view="desktop">${A?l||`<button aria-label="Clock" type="button" class="tp-ui-keyboard-icon">${l||y}</button>`:`<button aria-label="Keyboard" type="button" class="tp-ui-keyboard-icon">${i||b}</button>`}</div>`:""}<div class="tp-ui-wrapper-btn ${A}"><div class="tp-ui-cancel-btn ${A}" data-md3-ripple tabindex="0" role="button" aria-pressed="false" aria-label="${m}">${m}</div><div class="tp-ui-ok-btn ${A}" data-md3-ripple tabindex="0" role="button" aria-pressed="false" aria-label="${p}">${p}</div></div></div></div><div class="timepicker-announcer sr-only" role="status" aria-live="polite" aria-atomic="true"></div></div>`})(this.core.options,this.core.instanceId);if(this.core.options.ui.inline?.enabled){const t=document.getElementById(this.core.options.ui.inline.containerId);if(!t)return;t.innerHTML="",t.insertAdjacentHTML("beforeend",e);const i=t.querySelector(".tp-ui-modal");if(i){i.classList.add("tp-ui--inline");const{showButtons:e}=this.core.options.ui.inline;!1!==e&&void 0!==e||i.querySelectorAll(".tp-ui-wrapper-btn, .tp-ui-wrapper-btn.mobile").forEach(e=>e.style.display="none")}return}const{appendModalSelector:i}=this.core.options.ui;if(i){const t=document.querySelector(i);t?.insertAdjacentHTML("beforeend",e)}else document.body.insertAdjacentHTML("beforeend",e)}setScrollbarOrNot(){!1!==t()&&(this.core.options.ui.inline?.enabled||(this.core.options.ui.enableScrollbar?this.runWithTimeout(()=>{e()||this.runWithTimeout(()=>{"undefined"!=typeof document&&(document.body.style.overflowY=this.originalOverflow||"",document.body.style.paddingRight=this.originalPaddingRight||"")},n)},400):(this.originalOverflow=document.body.style.overflowY,this.originalPaddingRight=document.body.style.paddingRight,document.body.style.paddingRight=`${(()=>{if(!1===t())return 0;const e=document.createElement("div");e.className="tp-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(){if(this.core.options.ui.inline?.enabled||this.core.options.ui.backdrop)return;const e=this.core.getModalElement(),t=this.core.getOpenElement();e?.classList.add("removed"),t.forEach(e=>e?.classList.add("disabled"))}setNormalizeClass(){const e=this.core.getModalElement();if(!e)return;e.classList.add("tp-ui-normalize");e.querySelectorAll(":scope > div").forEach(e=>e.classList.add("tp-ui-normalize"))}setShowClassToBackdrop(){if(this.core.options.ui.inline?.enabled)return this.core.getModalElement()?.classList.add("show"),void this.setInitialFocus();this.core.options.ui.backdrop&&this.runWithTimeout(()=>{this.core.getModalElement()?.classList.add("show"),this.setInitialFocus()},r)}setInitialFocus(){if(!this.core.options.behavior.focusTrap)return;const e=this.core.getWrapper();e&&"undefined"!=typeof requestAnimationFrame&&requestAnimationFrame(()=>{e.focus()})}setFlexEndToFooterIfNoKeyboardIcon(){const e=this.core.getFooter();!this.core.options.ui.enableSwitchIcon&&e&&(e.style.justifyContent="flex-end")}destroy(){this.clearAllTimeouts(),e()||this.core.options.ui.inline?.enabled||(document.body.style.overflowY=this.originalOverflow||"",document.body.style.paddingRight=this.originalPaddingRight||""),this.clearExistingModal()}}const C=(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=i.padStart(2,"0");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:e.padStart(2,"0"),minutes:t,type:void 0}}const a=new Date(o).toLocaleTimeString(r||"en-US",{hour:"2-digit",minute:"2-digit",hour12:"12h"===t}),[l,c]=a.split(":");if("12h"===t&&/[a-z]/i.test(c)){const e=c.trim().split(" ");return{hour:l,minutes:e[0],type:e[1]||"AM"}}return{hour:l,minutes:c.replace(/\D/g,""),type:void 0}}const[o,a]=n.split(" "),[l="",c=""]=o.split(":"),u=l.replace(/\D/g,""),h=c.replace(/\D/g,""),d={hour:u.padStart(2,"0"),minutes:h.padStart(2,"0"),type:"12h"===t?a:void 0};if(u.length>2||h.length>2)return{...d,error:"Invalid input: too many digits.",currentHour:l,currentMin:c};if(/[a-z]/i.test(o))return{...d,error:"Input contains invalid letters."};if(n.includes(" ")&&(!a||n.length>8||"AM"!==a&&"PM"!==a))return{...d,error:"Invalid AM/PM format or length.",currentLength:n.length,currentType:a};const m=Number(u),p=Number(h);if("12h"===t){if(m<1||m>12||p<0||p>59||"AM"!==a&&"PM"!==a)return{...d,error:"Invalid 12h time.",currentHour:m,currentMin:p,currentType:a}}else if(m<0||m>23||p<0||p>59)return{...d,error:"Invalid 24h time.",currentHour:m,currentMin:p};return d},H=(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}},A="tp-ui",w="mousedown mouseup mousemove mouseleave mouseover touchstart touchmove touchend",E="active";class L{core;emitter;constructor(e,t){this.core=e,this.emitter=t}isCurrentTimeEnabled(e){const t=this.core.options.clock.currentTime;return"boolean"==typeof t?t:!!t?.[e]}preventClockTypeByCurrentTime(){if(!this.isCurrentTimeEnabled("preventClockType"))return;const e=this.core.getInput();if(!e)return;const{currentTime:t,clockType:i}={currentTime:this.core.options.clock.currentTime,clockType:this.core.options.clock.type},{type:s}=C(e,i,t,!0);this.core.updateOptions({clock:{type:s?"12h":"24h"}})}updateInputValueWithCurrentTimeOnStart(){if(!this.isCurrentTimeEnabled("updateInput"))return;const e=this.core.getInput();if(!e)return;const{hour:t,minutes:i,type:s}=C(e,this.core.options.clock.type,this.core.options.clock.currentTime);e.value=s?`${t}:${i} ${s}`:`${t}:${i}`}getInputValueOnOpenAndSet(){const e=this.core.getInput();if(!e)return;const t=C(e,this.core.options.clock.type,this.core.options.clock.currentTime),i=this.core.getHour(),s=this.core.getMinutes(),r=this.core.getActiveTypeMode(),n=this.core.getAM();if(void 0===t){i&&(i.value="12"),s&&(s.value="00");const e={hour:i?.value||"12",minutes:s?.value||"00",type:r?.dataset.type,degreesHours:this.core.degreesHours,degreesMinutes:this.core.degreesMinutes};this.emitter.emit("open",e);const t=!0===this.core.options.range?.enabled;return void("24h"!==this.core.options.clock.type&&n&&!t&&n.classList.add(E))}let[o,a,l]=e.value.split(":").join(" ").split(" ");0===e.value.length&&(o=t.hour,a=t.minutes,l=t.type),i&&(i.value=o.padStart(2,"0")),s&&(s.value=a.padStart(2,"0"));const c=this.core.getModalElement(),u=c?.querySelector(`[data-type='${l}']`);"24h"!==this.core.options.clock.type&&u&&u.classList.add(E);const h={...t,type:r?.dataset.type,degreesHours:this.core.degreesHours,degreesMinutes:this.core.degreesMinutes};this.emitter.emit("open",h)}getInputValue(e,t,i){return C(e,t,i)}destroy(){}}class S{core;emitter;isAnimating=!1;constructor(e,t){this.core=e,this.emitter=t,this.setupEventListeners()}setupEventListeners(){this.emitter.on("switch:view",()=>{this.toggleMobileClockFace()})}checkMobileOption(){this.core.setIsMobileView(!!this.core.options.ui.mobile),this.core.options.ui.mobile&&this.core.updateOptions({ui:{editable:!0}})}toggleMobileClockFace(){if(this.isAnimating)return;const e=this.core.getModalElement();if(!e)return;const t=e.querySelector(".tp-ui-wrapper"),i=this.core.getKeyboardClockIcon(),s=e.querySelector(".tp-ui-mobile-clock-wrapper"),r=e.querySelectorAll("*"),n=e.querySelector(".tp-ui-select-time"),o=this.core.getHour(),a=this.core.getMinutes(),l=this.core.getClockFace();if(!t)return;const c=t.classList.contains("expanded"),u=this.core.isMobileView;c?this.collapseClockFace(t,s,r,i,n,o,a,l,u):this.expandClockFace(t,s,r,i,n,o,a,l)}collapseClockFace(e,t,i,s,r,n,o,a,l){this.isAnimating=!0,this.switchView(r,s,n,o,!0),i.forEach(i=>{i!==t&&i!==e&&i!==r&&(i.classList.remove("expanded"),l&&i.classList.add("mobile"))}),r&&(r.classList.remove("expanded"),l&&r.classList.add("mobile")),"undefined"!=typeof requestAnimationFrame?requestAnimationFrame(()=>{t?.classList.remove("expanded"),l&&t?.classList.add("mobile"),e?.classList.remove("expanded"),l&&e?.classList.add("mobile"),l?a?.classList.remove("scale-in"):a?.classList.add("scale-in"),setTimeout(()=>{this.isAnimating=!1},c)}):this.isAnimating=!1,s?.setAttribute("aria-label","Show clock face"),s?.setAttribute("aria-pressed","false")}expandClockFace(e,t,i,s,r,n,o,a){this.isAnimating=!0;const l=o?.classList.contains("active");l&&o?this.emitter.emit("select:minute",{minutes:o.value}):n&&this.emitter.emit("select:hour",{hour:n.value}),i.forEach(i=>{i!==t&&i!==e&&i!==r&&(i.classList.remove("mobile"),i.classList.add("expanded"))}),r&&(r.classList.remove("mobile"),r.classList.add("expanded")),this.switchView(r,s,n,o,!1),"undefined"!=typeof requestAnimationFrame?requestAnimationFrame(()=>{e.classList.remove("mobile"),e.classList.add("expanded"),requestAnimationFrame(()=>{t&&(t.classList.remove("mobile"),t.classList.add("expanded")),a&&a.classList.remove("scale-in"),setTimeout(()=>{a&&a.classList.add("scale-in")},u),setTimeout(()=>{this.isAnimating=!1},c)})}):this.isAnimating=!1,s?.setAttribute("aria-label","Hide clock face"),s?.setAttribute("aria-pressed","true")}switchView(e,t,i,s,r){const n=this.core.getModalElement(),o=n?.querySelector(".tp-ui-hour-text"),a=n?.querySelector(".tp-ui-minute-text"),l=t?.querySelector(".tp-ui-keyboard-icon"),c=this.core.getInputWrappers(),u=this.core.getHeader(),h=n?.querySelector(".tp-ui-wrapper-type-time"),d=n?.querySelector(".tp-ui-am"),m=n?.querySelector(".tp-ui-pm"),p=n?.querySelectorAll(".tp-ui-input-ripple-wrapper"),{iconTemplate:g,iconTemplateMobile:v}=this.core.options.ui,{time:f,mobileTime:T}=this.core.options.labels;r?(e?.classList.add("mobile"),t?.classList.add("mobile"),i?.classList.add("mobile"),i?.removeAttribute("readonly"),s?.classList.add("mobile"),s?.removeAttribute("readonly"),o?.classList.add("mobile"),a?.classList.add("mobile"),u?.classList.add("mobile"),h?.classList.add("mobile"),d?.classList.add("mobile"),d?.classList.remove("tp-ui-ripple"),m?.classList.add("mobile"),m?.classList.remove("tp-ui-ripple"),c?.forEach(e=>{e.classList.add("mobile")}),p?.forEach(e=>{e.classList.add("mobile")}),e&&T&&(e.textContent=T),l&&(l.innerHTML=v||y),this.updateClockFaceAccessibility(!0)):(e?.classList.remove("mobile"),t?.classList.remove("mobile"),i?.classList.remove("mobile"),s?.classList.remove("mobile"),this.core.options.ui.editable||(i?.setAttribute("readonly",""),s?.setAttribute("readonly","")),o?.classList.remove("mobile"),a?.classList.remove("mobile"),u?.classList.remove("mobile"),h?.classList.remove("mobile"),d?.classList.remove("mobile"),d?.classList.add("tp-ui-ripple"),m?.classList.remove("mobile"),m?.classList.add("tp-ui-ripple"),c?.forEach(e=>{e.classList.remove("mobile")}),p?.forEach(e=>{e.classList.remove("mobile")}),e&&f&&(e.textContent=f),l&&(l.innerHTML=g||b),this.updateClockFaceAccessibility(!1))}updateClockFaceAccessibility(e){const t=this.core.getClockFace();if(!t)return;const i=t.querySelector(".tp-ui-tips-wrapper"),s=t.querySelector(".tp-ui-tips-wrapper-24h"),r=t.querySelectorAll(".tp-ui-tip");e?(t.setAttribute("aria-hidden","true"),i?.setAttribute("aria-hidden","true"),s?.setAttribute("aria-hidden","true"),r.forEach(e=>{e.setAttribute("tabindex","-1"),e.setAttribute("aria-hidden","true")})):(t.removeAttribute("aria-hidden"),i?.removeAttribute("aria-hidden"),s?.removeAttribute("aria-hidden"),r.forEach(e=>{e.setAttribute("tabindex","0"),e.removeAttribute("aria-hidden")}))}destroy(){}}const I=(e,t,i,s)=>{if(e){if(Array.isArray(e)&&e.length>0){return!e.map(e=>H(e,t,i)).some(e=>!1===e)}if("string"==typeof e||"number"==typeof e){return!!H(e,t,i)}}};class x{core;constructor(e){this.core=e}getDisableTime(){const e=(e=>{if(!e)return;const{disabledTime:t,type:i}=e.clock;if(!t||!Object.keys(t).length)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 required for interval");return v(e,i),{value:e.map(e=>{const[t,s]=e.trim().split("-"),{hour:r,minutes:n,type:o}=C({value:t.trim()},i),{hour:a,minutes:l,type:c}=C({value:s.trim()},i);let u=d(r,a).map(e=>0===Number(e)?"00":String(Number(e)));const h=[],p=Number(n),g=Number(l);if(c===o)return p>0&&g<=0?(h.push(u[0],u[u.length-1]),u=u.slice(1,-1)):g<59&&g>0&&p<=0?(h.push(void 0,u[u.length-1]),u=u.slice(0,-1)):g>0&&p>0?(h.push(u[0],u[u.length-1]),u=u.slice(1,-1)):0===g&&0===p&&(h.push(void 0,u[u.length-1]),u.pop()),{removedStartedHour:void 0!==h[0]&&Number(h[0])<=9?`0${h[0]}`:h[0],removedEndHour:void 0!==h[1]&&Number(h[1])<=9?`0${h[1]}`:h[1],rangeArrHour:u,startMinutes:d(n,59).map(e=>Number(e)<=9?`0${e}`:`${e}`),endMinutes:m(0,l).map(e=>Number(e)<=9?`0${e}`:`${e}`),startType:o,endType:c};{const e=d(r,12).map(String),t=m(1,a).map(String),i=[],s=[];return p>0&&g<=0?(s.push(t[t.length-1]),i.push(e[0]),t.pop(),e.shift()):g<59&&g>0&&p<=0?(i.push(e[0]),s.push(t[t.length-1]),t.pop()):g>0&&p>0?(s.push(t[t.length-1]),i.push(e[0]),t.pop(),e.shift()):0===g&&0===p&&(s.push(t[t.length-1]),i.push(e[0]),t.pop()),{startType:o,endType:c,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)?[]:d(n,59).map(e=>Number(e)<=9?`0${e}`:`${e}`),endMinutes:m(0,l).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.core.options);this.core.setDisabledTime(e||null)}destroy(){}}class ${inputValueHandler;mobileViewHandler;disabledTimeHandler;core;constructor(e,t){this.core=e,this.inputValueHandler=new L(e,t),this.mobileViewHandler=new S(e,t),this.disabledTimeHandler=new x(e)}preventClockTypeByCurrentTime(){this.inputValueHandler.preventClockTypeByCurrentTime()}updateInputValueWithCurrentTimeOnStart(){this.inputValueHandler.updateInputValueWithCurrentTimeOnStart()}getInputValueOnOpenAndSet(){this.inputValueHandler.getInputValueOnOpenAndSet()}getInputValue(e,t,i){return this.inputValueHandler.getInputValue(e,t,i)}checkMobileOption(){this.mobileViewHandler.checkMobileOption()}toggleMobileClockFace(){this.mobileViewHandler.toggleMobileClockFace()}updateClockFaceAccessibility(e){this.mobileViewHandler.updateClockFaceAccessibility(e)}getDisableTime(){this.disabledTimeHandler.getDisableTime()}destroy(){this.inputValueHandler.destroy(),this.mobileViewHandler.destroy(),this.disabledTimeHandler.destroy()}}class P{core;emitter;constructor(e,t){this.core=e,this.emitter=t}setTheme(){const e=this.core.getModalElement();if(!e)return;const{theme:t}=this.core.options.ui;t&&e.setAttribute("data-theme",t)}setInputClassToInputElement(){const e=this.core.getInput();var t,i;e&&(i="tp-ui-input",(t=e)&&t.classList.contains(i)||e.classList.add("tp-ui-input"))}setDataOpenToInputIfDoesntExistInWrapper(){const e=this.core.getOpenElementData(),t=this.core.getInput();null===e&&t&&t.setAttribute("data-open","tp-ui-input")}setClassTopOpenElement(){const e=this.core.getOpenElement();for(const t of e)t&&t.classList.add("tp-ui-open-element")}setTimepickerClassToElement(){const e=this.core.element;if(!e)return;e.classList.add(A);const t=this.core.options.ui.cssClass;t&&t!==A&&e.classList.add(t)}destroy(){const e=this.core.getModalElement();e&&e.removeAttribute("data-theme")}}class D extends Error{code;constructor(e,t){super(`[TimepickerUI] ${e}`),this.code=t,this.name="TimepickerError",Object.setPrototypeOf(this,D.prototype)}}const F="INVALID_PARAMETER";class q{core;emitter;constructor(e,t){this.core=e,this.emitter=t}setErrorHandler(){const e=this.core.getInput();if(!e)return!0;const{error:i,currentHour:s,currentMin:r,currentType:n,currentLength:o}=C(e,this.core.options.clock.type);if(this.removeErrorHandler(),i){if(!1===t())return!1;const a=document.createElement("div");a.classList.add("tp-ui-invalid-text"),a.innerHTML="<b>Invalid Time Format</b>",e.classList.add("tp-ui-invalid-format"),e.nextElementSibling?.classList.contains("tp-ui-invalid-text")||e.after(a);const l={error:i,rejectedHour:void 0,rejectedMinute:void 0,inputHour:s,inputMinute:r,inputType:n,inputLength:o};return this.emitter.emit("error",l),!1}return!0}removeErrorHandler(){const e=this.core.getInput();if(!e)return;e.classList.remove("tp-ui-invalid-format");const t=e.nextElementSibling;t?.classList.contains("tp-ui-invalid-text")&&t.remove()}checkDisabledValuesOnStart(){if(!this.core.options.clock.disabledTime)return;const{disabledTime:e,type:t}=this.core.options.clock;if(e.interval){if(!t)throw new D("clockType is required when using disabledTime.interval",F);const i=Array.isArray(e.interval)?e.interval:[e.interval];try{v(i,t)}catch(e){throw new D(`Invalid disabledTime.interval: ${e.message}`,F)}return}const{hours:i,minutes:s}=e,r=!i||I(i,"hour",t),n=!s||I(s,"minutes",t);if(!r||!n)throw new D("Invalid hours or minutes in disabledTime option",F)}destroy(){this.removeErrorHandler()}}const V=(e,t)=>{if(!e)return;const i=e.querySelector(".timepicker-announcer");i&&(i.textContent="",setTimeout(()=>{i.textContent=t},100))},O=(e,t)=>{e&&e.setAttribute("aria-pressed",String(t))};class N{core;emitter;cleanupHandlers=[];constructor(e,t){this.core=e,this.emitter=t}handleOpenOnClick(){const e=this.core.getOpenElement();if(!e)return;const t=()=>{this.core.isDestroyed||this.emitter.emit("show",{})};e.forEach(e=>{e.addEventListener("click",t),this.cleanupHandlers.push(()=>e.removeEventListener("click",t))})}handleCancelButton(){const e=this.core.getCancelButton();if(!e)return;const t=()=>{this.core.isDestroyed||this.emitter.emit("cancel",{})};e.addEventListener("click",t),this.cleanupHandlers.push(()=>e.removeEventListener("click",t))}handleOkButton(){const e=this.core.getOkButton();if(!e)return;const t=()=>{if(this.core.isDestroyed)return;const e=this.core.getHour(),t=this.core.getMinutes(),i=this.core.getActiveTypeMode();this.emitter.emit("confirm",{hour:e?.value,minutes:t?.value,type:i?.textContent||void 0})};e.addEventListener("click",t),this.cleanupHandlers.push(()=>e.removeEventListener("click",t))}handleAmClick(){const e=this.core.getAM();if(!e)return;const t=()=>{if(this.core.isDestroyed)return;const t=this.core.getPM();e.classList.add("active"),t?.classList.remove("active"),O(e,!0),O(t,!1);const i=this.core.getModalElement();V(i,"AM selected"),this.emitter.emit("select:am",{});const s=this.core.getHour(),r=this.core.getMinutes();this.emitter.emit("update",{hour:s?.value,minutes:r?.value,type:"AM"})};e.addEventListener("click",t),this.cleanupHandlers.push(()=>e.removeEventListener("click",t))}handlePmClick(){const e=this.core.getPM();if(!e)return;const t=()=>{if(this.core.isDestroyed)return;const t=this.core.getAM();e.classList.add("active"),t?.classList.remove("active"),O(e,!0),O(t,!1);const i=this.core.getModalElement();V(i,"PM selected"),this.emitter.emit("select:pm",{});const s=this.core.getHour(),r=this.core.getMinutes();this.emitter.emit("update",{hour:s?.value,minutes:r?.value,type:"PM"})};e.addEventListener("click",t),this.cleanupHandlers.push(()=>e.removeEventListener("click",t))}handleSwitchViewButton(){const e=this.core.getKeyboardClockIcon();if(!e)return;const t=()=>{this.core.isDestroyed||this.emitter.emit("switch:view",{})};e.addEventListener("click",t),this.cleanupHandlers.push(()=>e.removeEventListener("click",t))}destroy(){this.cleanupHandlers.forEach(e=>e()),this.cleanupHandlers=[]}}const W=(e,t,i)=>Math.max(t,Math.min(i,e));class z{core;emitter;cleanupHandlers=[];constructor(e,t){this.core=e,this.emitter=t}handleHourEvents(){const e=this.core.getHour();if(!e)return;const t=()=>{if(this.core.isDestroyed)return;e.classList.add("active");const t=this.core.getMinutes();t?.classList.remove("active"),this.emitter.emit("select:hour",{hour:e.value});const i=this.core.getActiveTypeMode();this.emitter.emit("update",{hour:e.value,minutes:t?.value,type:i?.textContent||void 0})};e.addEventListener("click",t),this.cleanupHandlers.push(()=>e.removeEventListener("click",t));let i=e.value;const s=()=>{if(this.core.isDestroyed)return;if(e.hasAttribute("readonly"))return;const t="12h"===this.core.options.clock.type,s=((e,t)=>{if(""===e)return"";const i=parseInt(e,10);return Number.isNaN(i)?"":W(i,t?1:0,t?12:23).toString().padStart(2,"0")})(e.value,t);if(e.value=s,e.setAttribute("aria-valuenow",s),e.value!==i){i=e.value,this.emitter.emit("animation:clock",{}),this.emitter.emit("select:hour",{hour:e.value});const t=this.core.getMinutes(),s=this.core.getActiveTypeMode();this.emitter.emit("update",{hour:e.value,minutes:t?.value,type:s?.textContent||void 0})}};e.addEventListener("blur",s),this.cleanupHandlers.push(()=>e.removeEventListener("blur",s))}handleMinutesEvents(){const e=this.core.getMinutes();if(!e)return;const t=()=>{if(this.core.isDestroyed)return;e.classList.add("active");const t=this.core.getHour();t?.classList.remove("active"),this.emitter.emit("select:minute",{minutes:e.value});const i=this.core.getActiveTypeMode();this.emitter.emit("update",{hour:t?.value,minutes:e.value,type:i?.textContent||void 0})};e.addEventListener("click",t),this.cleanupHandlers.push(()=>e.removeEventListener("click",t));let i=e.value;const s=()=>{if(this.core.isDestroyed)return;if(e.hasAttribute("readonly"))return;const t=(e=>{if(""===e)return"";const t=parseInt(e,10);return Number.isNaN(t)?"":W(t,0,59).toString().padStart(2,"0")})(e.value);if(e.value=t,e.setAttribute("aria-valuenow",t),e.value!==i){i=e.value,this.emitter.emit("animation:clock",{}),this.emitter.emit("select:minute",{minutes:e.value});const t=this.core.getHour(),s=this.core.getActiveTypeMode();this.emitter.emit("update",{hour:t?.value,minutes:e.value,type:s?.textContent||void 0})}};e.addEventListener("blur",s),this.cleanupHandlers.push(()=>e.removeEventListener("blur",s))}destroy(){this.cleanupHandlers.forEach(e=>e()),this.cleanupHandlers=[]}}class B{core;emitter;cleanupHandlers=[];constructor(e,t){this.core=e,this.emitter=t}handleOpenOnEnterFocus(){const e=this.core.getInput();if(!e)return;const t=e=>{"Enter"!==e.key||this.core.isDestroyed||this.emitter.emit("show",{})};e.addEventListener("keydown",t),this.cleanupHandlers.push(()=>e.removeEventListener("keydown",t))}handleEscClick(){if(!1===t())return;const e=e=>{this.core.isDestroyed||"Escape"===e.key&&this.emitter.emit("cancel",{})};document.addEventListener("keydown",e),this.cleanupHandlers.push(()=>document.removeEventListener("keydown",e))}handleKeyboardInput(){const e=this.core.getHour(),t=this.core.getMinutes();if(e){const t=t=>{if(this.core.isDestroyed)return;if("ArrowUp"!==t.key&&"ArrowDown"!==t.key)return;t.preventDefault();const i=parseInt(e.value)||0,s=parseInt(e.getAttribute("max")||"23");parseInt(e.getAttribute("min")||"0");const r="12h"===this.core.options.clock.type;let n;n="ArrowUp"===t.key?r?i>=12?1:i+1:i>=s?0:i+1:r?i<=1?12:i-1:i<=0?s:i-1,e.value=n.toString().padStart(2,"0"),e.setAttribute("aria-valuenow",e.value);const o=this.core.getModalElement();V(o,`Hour: ${e.value}`),this.emitter.emit("animation:clock",{}),this.emitter.emit("select:hour",{hour:e.value});const a=this.core.getMinutes(),l=this.core.getActiveTypeMode();this.emitter.emit("update",{hour:e.value,minutes:a?.value,type:l?.textContent||void 0})};e.addEventListener("keydown",t),this.cleanupHandlers.push(()=>e.removeEventListener("keydown",t))}if(t){const e=e=>{if(this.core.isDestroyed)return;if("ArrowUp"!==e.key&&"ArrowDown"!==e.key)return;e.preventDefault();const i=parseInt(t.value)||0;let s;s="ArrowUp"===e.key?i>=59?0:i+1:i<=0?59:i-1,t.value=s.toString().padStart(2,"0"),t.setAttribute("aria-valuenow",t.value);const r=this.core.getModalElement();V(r,`Minutes: ${t.value}`),this.emitter.emit("animation:clock",{}),this.emitter.emit("select:minute",{minutes:t.value});const n=this.core.getHour(),o=this.core.getActiveTypeMode();this.emitter.emit("update",{hour:n?.value,minutes:t.value,type:o?.textContent||void 0})};t.addEventListener("keydown",e),this.cleanupHandlers.push(()=>t.removeEventListener("keydown",e))}}focusTrapHandler(){if(!1===t())return;const e=this.core.getWrapper();if(!e)return;const i=t=>{if(this.core.isDestroyed)return;if("Tab"!==t.key)return;const i=e.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'),s=i[0],r=i[i.length-1];t.shiftKey&&document.activeElement===s?(r?.focus(),t.preventDefault()):t.shiftKey||document.activeElement!==r||(s?.focus(),t.preventDefault())};e.addEventListener("keydown",i),this.cleanupHandlers.push(()=>e.removeEventListener("keydown",i))}destroy(){this.cleanupHandlers.forEach(e=>e()),this.cleanupHandlers=[]}}class R{core;emitter;cleanupHandlers=[];constructor(e,t){this.core=e,this.emitter=t}handleBackdropClick(){const e=this.core.getModalElement();if(!e)return;const t=t=>{this.core.isDestroyed||t.target===e&&this.emitter.emit("cancel",{})};e.addEventListener("click",t),this.cleanupHandlers.push(()=>e.removeEventListener("click",t))}handleMoveHand(){if(!1===t())return;const e=e=>{this.core.isDestroyed||e.preventDefault()};document.addEventListener("mousedown",e,!1),document.addEventListener("touchstart",e,{passive:!1}),this.cleanupHandlers.push(()=>{document.removeEventListener("mousedown",e),document.removeEventListener("touchstart",e)})}destroy(){this.cleanupHandlers.forEach(e=>e()),this.cleanupHandlers=[]}}class U{buttonHandlers;inputHandlers;keyboardHandlers;modalHandlers;constructor(e,t){this.buttonHandlers=new N(e,t),this.inputHandlers=new z(e,t),this.keyboardHandlers=new B(e,t),this.modalHandlers=new R(e,t)}handleOpenOnClick(){this.buttonHandlers.handleOpenOnClick()}handleOpenOnEnterFocus(){this.keyboardHandlers.handleOpenOnEnterFocus()}handleCancelButton(){this.buttonHandlers.handleCancelButton()}handleOkButton(){this.buttonHandlers.handleOkButton()}handleBackdropClick(){this.modalHandlers.handleBackdropClick()}handleEscClick(){this.keyboardHandlers.handleEscClick()}handleAmClick(){this.buttonHandlers.handleAmClick()}handlePmClick(){this.buttonHandlers.handlePmClick()}handleHourEvents(){this.inputHandlers.handleHourEvents()}handleMinutesEvents(){this.inputHandlers.handleMinutesEvents()}handleKeyboardInput(){this.keyboardHandlers.handleKeyboardInput()}focusTrapHandler(){this.keyboardHandlers.focusTrapHandler()}handleMoveHand(){this.modalHandlers.handleMoveHand()}handleSwitchViewButton(){this.buttonHandlers.handleSwitchViewButton()}destroy(){this.buttonHandlers.destroy(),this.inputHandlers.destroy(),this.keyboardHandlers.destroy(),this.modalHandlers.destroy()}}class Z{emitter;getClockSystem;setHoursToClock;setMinutesToClock;updateAmPm;convertDisabledTime;constructor(e,t,i,s,r,n){this.emitter=e,this.getClockSystem=t,this.setHoursToClock=i,this.setMinutesToClock=s,this.updateAmPm=r,this.convertDisabledTime=n}setup(){this.emitter.on("select:hour",({hour:e})=>{this.emitter.emit("animation:clock",{}),this.setHoursToClock(e||null)}),this.emitter.on("select:minute",({minutes:e})=>{this.emitter.emit("animation:clock",{}),this.setMinutesToClock(e||null)}),this.emitter.on("select:am",()=>{this.updateAmPm()}),this.emitter.on("select:pm",()=>{this.updateAmPm()}),this.emitter.on("animation:start",()=>{this.getClockSystem()?.blockInteractions()}),this.emitter.on("animation:end",()=>{this.getClockSystem()?.unblockInteractions()}),this.emitter.on("range:switch",e=>{this.refreshDisabledTimeForRange(e.disabledTime)})}refreshDisabledTimeForRange(e){const t=this.getClockSystem();if(!t)return;const i=this.convertDisabledTime();let s=i;if(e){const t=[...i?.hours||[],...e.hours||[]],r=[...i?.minutes||[],...e.minutes||[]];s={...i,hours:t.length>0?t:void 0,minutes:r.length>0?r:void 0,rangeFromType:e.fromType,rangeFromHour:e.fromHour}}t.updateDisabledTime(s)}}class Y{static angleToIndex(e,t,i){const s=Math.round(e/30)%12;if("24h"===t){if(i){const e=s+12;return 12===e?0:e}return 0===s?12:s}return 0===s?12:s}static indexToValue(e,t,i){if("24h"===t)return e.toString().padStart(2,"0");let s=e;return 0===s&&(s=12),s>12&&(s-=12),s.toString().padStart(2,"0")}static indexToAngle(e,t){if("24h"===t)return e>=12?(e-12)%12*30:e%12*30;return(0===e?12:e)%12*30}static isDisabled(e,t,i){return!!i&&(i.isInterval&&i.intervals&&i.clockType?this.isDisabledByInterval(e,t,i):void 0!==i.rangeFromType&&void 0!==i.rangeFromHour?this.isDisabledForRange12h(e,t,i):!!i.hours&&i.hours.some(t=>String(t)===e||Number(t)===Number(e)||t===e))}static isDisabledForRange12h(e,t,i){const s=i.rangeFromType,r=i.rangeFromHour,n=parseInt(e,10);return null!==s&&void 0!==r&&("AM"===t&&"PM"===s||("AM"===t&&"AM"===s?12!==r&&(12===n||n<r):("PM"!==t||"AM"!==s)&&("PM"===t&&"PM"===s&&(12!==r&&(12===n||n<r)))))}static isDisabledByInterval(e,t,i){if(!i.intervals)return!1;for(let s=0;s<60;s++){const r=s.toString().padStart(2,"0");if(!this.isTimeInIntervals(e,r,t,i.intervals,i.clockType))return!1}return!0}static isTimeInIntervals(e,t,i,s,r){const n="12h"===r?`${e}:${t} ${i}`:`${e}:${t}`;for(const e of s){const[t,i]=e.split("-").map(e=>e.trim());if(this.isTimeBetween(n,t,i,r))return!0}return!1}static isTimeBetween(e,t,i,s){const r=this.timeToMinutes(e,s),n=this.timeToMinutes(t,s),o=this.timeToMinutes(i,s);return r>=n&&r<=o}static timeToMinutes(e,t){if("12h"===t){const t=e.match(/(\d{1,2}):(\d{2})\s*(AM|PM)/i);if(!t)return 0;let i=parseInt(t[1]);const s=parseInt(t[2]),r=t[3].toUpperCase();return"PM"===r&&12!==i&&(i+=12),"AM"===r&&12===i&&(i=0),60*i+s}{const[t,i]=e.split(":").map(Number);return 60*t+i}}static findNearestValid(e,t,i,s,r){const n="24h"===t?23:12;for(let r=0;r<=n;r++){const o=0===r?[e]:[e+r,e-r];for(const e of o){let r=e;r<0&&(r+=n+1),r>n&&(r%=n+1);const o=this.indexToValue(r,t,i);if(!this.isDisabled(o,i,s))return r}}return e}}class j{static angleToIndex(e){return Math.round(e/6)%60}static indexToValue(e){return e.toString().padStart(2,"0")}static indexToAngle(e){return e%60*6}static isDisabled(e,t,i,s,r){return!!s&&(s.isInterval&&s.intervals?this.isDisabledByInterval(e,t,i,s,r):void 0!==s.rangeFromType&&void 0!==s.rangeFromHour?this.isDisabledForRange12h(e,t,i,s):!!s.minutes&&s.minutes.some(t=>String(t)===e||Number(t)===Number(e)||t===e))}static isDisabledForRange12h(e,t,i,s){const r=s.rangeFromType,n=s.rangeFromHour,o=parseInt(t,10),a=parseInt(e,10);if(null===r||void 0===n)return!1;const l=s.minutes||[],c=l.length>0?parseInt(l[l.length-1],10)+1:0;if("AM"===i&&"PM"===r)return!0;if("PM"===i&&"AM"===r)return!1;return!!(o===n||12===o&&12===n||i===r&&o===n)&&a<c}static isDisabledByInterval(e,t,i,s,r){if(!s.intervals)return!1;const n="12h"===r?`${t}:${e} ${i}`:`${t}:${e}`;for(const e of s.intervals){const[t,i]=e.split("-").map(e=>e.trim());if(this.isTimeBetween(n,t,i,r))return!0}return!1}static isTimeBetween(e,t,i,s){const r=this.timeToMinutes(e,s),n=this.timeToMinutes(t,s),o=this.timeToMinutes(i,s);return r>=n&&r<=o}static timeToMinutes(e,t){if("12h"===t){const t=e.match(/(\d{1,2}):(\d{2})\s*(AM|PM)/i);if(!t)return 0;let i=parseInt(t[1]);const s=parseInt(t[2]),r=t[3].toUpperCase();return"PM"===r&&12!==i&&(i+=12),"AM"===r&&12===i&&(i=0),60*i+s}{const[t,i]=e.split(":").map(Number);return 60*t+i}}static findNearestValid(e,t,i,s,r){for(let n=0;n<60;n++){const o=0===n?[e]:[e+n,e-n];for(const e of o){let n=e;n<0&&(n+=60),n>=60&&(n%=60);const o=this.indexToValue(n);if(!this.isDisabled(o,t,i,s,r))return n}}return e}}class K{static normalizeAngle(e){let t=e%360;return t<0&&(t+=360),t}static calculateRawAngle(e,t){const i=e.x-t.x,s=e.y-t.y,r=180*Math.atan2(s,i)/Math.PI+90;return this.normalizeAngle(r)}static snapToIncrement(e,t){const i=Math.round(e/t)*t;return this.normalizeAngle(i)}static calculateDistance(e,t){const i=e.x-t.x,s=e.y-t.y;return Math.sqrt(i*i+s*s)}static isInnerCircle(e,t){return e<.75*t}static calculateShortestPath(e,t){const i=this.normalizeAngle(e),s=this.normalizeAngle(t)-i,r=s>=0?s:s+360,n=s<=0?s:s-360;return e+(Math.abs(r)<Math.abs(n)?r:n)}}class X{config;currentAngle=0;tipsCache=new Map;cachedDimensions=new Map;constructor(e){this.config=e}getCachedDimensions(e){let t=this.cachedDimensions.get(e);if(!t){const i=(e.offsetWidth-32)/2;t={width:i,height:(e.offsetHeight-32)/2,radius:i-9},this.cachedDimensions.set(e,t)}return t}setHandAngle(e){const t=K.calculateShortestPath(this.currentAngle,e);Math.abs(this.currentAngle-t)<.01||(this.currentAngle=t,this.config.clockHand.style.transform=`rotateZ(${t}deg)`)}animateToAngle(e){const t=K.calculateShortestPath(this.currentAngle,e);this.currentAngle=t,this.config.tipsWrapper.classList.add("tp-ui-tips-animation"),this.config.clockHand.style.transform=`rotateZ(${t}deg)`,setTimeout(()=>{this.config.tipsWrapper.classList.remove("tp-ui-tips-animation")},401)}setActiveValue(e){const t=[this.config.tipsWrapper];this.config.tipsWrapperFor24h&&t.push(this.config.tipsWrapperFor24h),t.forEach(t=>{t.querySelectorAll(".tp-ui-value-tips, .tp-ui-value-tips-24h").forEach(t=>{const i=t;i.textContent===e||Number(i.textContent)===Number(e)?(i.classList.add("active"),i.setAttribute("aria-selected","true")):(i.classList.remove("active"),i.setAttribute("aria-selected","false"))})})}renderTips(e,i,s,r,n,o=!0,a,l="",c="12"){if(!1===t())return;const u=a||this.config.tipsWrapper;o&&(u.innerHTML="",this.tipsCache.clear());const{width:h,height:d,radius:m}=this.getCachedDimensions(u),p=document.createDocumentFragment(),g=`${i}-${this.config.theme||"default"}`;e.forEach((t,o)=>{const a=`${g}-${t}`;let u=this.tipsCache.get(a);u||(u=this.createTip(t,i,n),this.tipsCache.set(a,u));const{wrapper:v,tip:b}=u;this.updateTipState(v,b,t,s,r,n,l,c);const y=o*(360/e.length)*(Math.PI/180);v.style.left=`${h+Math.sin(y)*m}px`,v.style.bottom=`${d+Math.cos(y)*m}px`,p.appendChild(v)}),u.appendChild(p)}createTip(e,i,s){if(!1===t()){const e={};return{wrapper:e,tip:e}}const r=document.createElement("span"),n=document.createElement("span");n.textContent=e,n.setAttribute("role","option"),n.setAttribute("aria-selected","false"),n.tabIndex=0;const o="24h"===s&&i.includes("24")?"tp-ui-value-tips-24h":"tp-ui-value-tips";return n.classList.add(o),r.classList.add(i),this.config.theme&&(r.classList.add(this.config.theme),n.classList.add(this.config.theme)),r.appendChild(n),{wrapper:r,tip:n}}updateTipState(e,t,i,s,r,n,o,a){e.classList.remove("tp-ui-tips-disabled"),t.classList.remove("tp-ui-tips-disabled"),t.removeAttribute("aria-disabled"),t.tabIndex=0;this.checkIfDisabled(i,s,r,n,o,a)&&(e.classList.add("tp-ui-tips-disabled"),t.classList.add("tp-ui-tips-disabled"),t.setAttribute("aria-disabled","true"),t.tabIndex=-1)}checkIfDisabled(e,t,i,s,r,n){return!!i&&("hours"===t?Y.isDisabled(e,r,i):"minutes"===t&&j.isDisabled(e,n,r,i,s))}setCircleSize(e){e?this.config.circle.classList.remove("small-circle"):this.config.circle.classList.add("small-circle")}setCircle24hMode(e){e?(this.config.circle.classList.add("tp-ui-circle-hand-24h"),this.config.clockHand.classList.add("tp-ui-clock-hand-24h")):(this.config.circle.classList.remove("tp-ui-circle-hand-24h"),this.config.clockHand.classList.remove("tp-ui-clock-hand-24h"))}destroy(){this.tipsCache.clear(),this.cachedDimensions.clear(),this.config.tipsWrapper.innerHTML=""}}class _{static processPointerInput(e){const t=K.calculateRawAngle(e.pointerPosition,e.clockCenter);return"hours"===e.mode?this.processHours(t,e):this.processMinutes(t,e)}static processHours(e,t){const i=t.smoothHourSnap??!0;let s;if(i)s=e;else{const i=30*t.incrementHours;s=K.snapToIncrement(e,i)}const r=K.calculateDistance(t.pointerPosition,t.clockCenter),n="24h"===t.clockType&&K.isInnerCircle(r,t.clockRadius);let o=Y.angleToIndex(s,t.clockType,n);const a=Y.indexToValue(o,t.clockType,t.amPm),l=Y.isDisabled(a,t.amPm,t.disabledTime);l&&(o=Y.findNearestValid(o,t.clockType,t.amPm,t.disabledTime,n));const c=Y.indexToValue(o,t.clockType,t.amPm);let u;return u=i?e:Y.indexToAngle(o,t.clockType),{angle:u,value:c,index:o,isValid:!l,isInnerCircle:"24h"===t.clockType?n:void 0}}static processMinutes(e,t){const i=6*t.incrementMinutes,s=K.snapToIncrement(e,i);let r=j.angleToIndex(s);const n=j.indexToValue(r),o=t.currentHour||"00",a=j.isDisabled(n,o,t.amPm,t.disabledTime,t.clockType);a&&(r=j.findNearestValid(r,o,t.amPm,t.disabledTime,t.clockType));const l=j.indexToValue(r);return{angle:j.indexToAngle(r),value:l,index:r,isValid:!a}}static valueToAngle(e,t,i){const s=parseInt(e,10);return"hours"===t?Y.indexToAngle(s,i):j.indexToAngle(s)}}class G{state;renderer;clockType;disabledTime;incrementHours;incrementMinutes;smoothHourSnap;isDragging=!1;callbacks;lastProcessedX=null;lastProcessedY=null;constructor(e,t,i,s,r=1,n=1,o=!0,a={}){this.renderer=e,this.state={...t},this.clockType=i,this.disabledTime=s,this.incrementHours=r,this.incrementMinutes=n,this.smoothHourSnap=o,this.callbacks=a}handlePointerMove(e,t,i){if(this.isDragging=!0,this.lastProcessedX===e.x&&this.lastProcessedY===e.y)return;this.lastProcessedX=e.x,this.lastProcessedY=e.y;const s={pointerPosition:e,clockCenter:t,clockRadius:i,mode:this.state.mode,clockType:this.clockType,amPm:this.state.amPm,disabledTime:this.disabledTime,incrementHours:this.incrementHours,incrementMinutes:this.incrementMinutes,smoothHourSnap:this.smoothHourSnap,currentHour:this.state.hour},r=_.processPointerInput(s);if(r.isValid){if("hours"===this.state.mode){const e=this.state.hour;this.state.hour=r.value,this.state.hourAngle=r.angle,"24h"===this.clockType&&void 0!==r.isInnerCircle&&(this.renderer.setCircleSize(!0),this.renderer.setCircle24hMode(r.isInnerCircle)),this.callbacks.onHourChange&&e!==r.value&&this.callbacks.onHourChange(r.value)}else{const e=this.state.minute;this.state.minute=r.value,this.state.minuteAngle=r.angle,this.renderer.setCircleSize(!0),this.renderer.setCircle24hMode(!1),this.callbacks.onMinuteChange&&e!==r.value&&this.callbacks.onMinuteChange(r.value)}this.renderer.setHandAngle(r.angle),this.renderer.setActiveValue(r.value)}}handlePointerUp(){this.isDragging=!1,this.lastProcessedX=null,this.lastProcessedY=null}snapToNearestHour(){if("hours"!==this.state.mode)return;const e=_.valueToAngle(this.state.hour,"hours",this.clockType);this.state.hourAngle=e,this.renderer.animateToAngle(e)}switchMode(e){this.state.mode=e;const t="hours"===e?this.state.hourAngle:this.state.minuteAngle,i="hours"===e?this.state.hour:this.state.minute;if("hours"===e&&"24h"===this.clockType){const e=parseInt(i,10),t=0===e||e>=13;this.renderer.setCircleSize(!0),this.renderer.setCircle24hMode(t)}else this.renderer.setCircleSize(!0),this.renderer.setCircle24hMode(!1);this.renderer.setHandAngle(t),this.renderer.setActiveValue(i)}setValue(e,t){const i=_.valueToAngle(t,e,this.clockType);if("hours"===e)if(this.state.hour=t,this.state.hourAngle=i,"24h"===this.clockType){const e=parseInt(t,10),i=0===e||e>=13;this.renderer.setCircleSize(!0),this.renderer.setCircle24hMode(i)}else this.renderer.setCircle24hMode(!1);else this.state.minute=t,this.state.minuteAngle=i,this.renderer.setCircleSize(!0),this.renderer.setCircle24hMode(!1);this.state.mode===e&&(this.renderer.setHandAngle(i),this.renderer.setActiveValue(t))}setAmPm(e){this.state.amPm=e}getState(){return{...this.state}}getHour(){return this.state.hour}getMinute(){return this.state.minute}getAmPm(){return this.state.amPm}updateDisabledTime(e){this.disabledTime=e}destroy(){this.renderer.destroy()}}class J{controller;clockFace;isActive=!1;isBlocked=!1;config;cachedRect=null;cachedCenter=null;cachedRadius=null;rafId=null;constructor(e,t,i={}){this.controller=e,this.clockFace=t,this.config=i}attach(){this.clockFace.addEventListener("mousedown",this.handlePointerDown),this.clockFace.addEventListener("touchstart",this.handlePointerDown,{passive:!1})}detach(){this.clockFace.removeEventListener("mousedown",this.handlePointerDown),this.clockFace.removeEventListener("touchstart",this.handlePointerDown),this.removeGlobalListeners()}block(){this.isBlocked=!0}unblock(){this.isBlocked=!1}handlePointerDown=t=>{if(e()||this.isBlocked)return;const i=t.target;i&&i.classList&&i.classList.contains("tp-ui-tips-disabled")||(t.preventDefault(),this.isActive=!0,this.cachedRect=this.clockFace.getBoundingClientRect(),this.cachedCenter=this.getClockCenter(),this.cachedRadius=this.getClockRadius(),this.processPointerEvent(t),document.addEventListener("mousemove",this.handlePointerMove),document.addEventListener("touchmove",this.handlePointerMove,{passive:!1}),document.addEventListener("mouseup",this.handlePointerUp),document.addEventListener("touchend",this.handlePointerUp))};handlePointerMove=e=>{if(!this.isActive||this.isBlocked)return;const t=this.getTargetElement(e);t&&t.classList&&t.classList.contains("tp-ui-tips-disabled")||(e.preventDefault(),null===this.rafId&&(this.rafId=requestAnimationFrame(()=>{this.rafId=null,this.processPointerEvent(e)})))};handlePointerUp=()=>{if(!this.isActive)return;null!==this.rafId&&(cancelAnimationFrame(this.rafId),this.rafId=null),this.isActive=!1,this.cachedRect=null,this.cachedCenter=null,this.cachedRadius=null,this.controller.handlePointerUp();const{autoSwitchToMinutes:e,isMobileView:t,smoothHourSnap:i,hourElement:s,minutesElement:r}=this.config;i&&s?.classList.contains("active")&&this.controller.snapToNearestHour(),this.removeGlobalListeners(),e&&s?.classList.contains("active")&&!t?(s.classList.remove("active"),r?.classList.add("active"),r?.click(),r?.focus(),s.blur()):r?.classList.contains("active")&&this.config.onMinuteCommit&&this.config.onMinuteCommit()};processPointerEvent(e){const t=this.getPointerPosition(e),i=this.cachedCenter||this.getClockCenter(),s=this.cachedRadius||this.getClockRadius();this.controller.handlePointerMove(t,i,s)}getPointerPosition(e){const t=this.cachedRect||this.clockFace.getBoundingClientRect();if("touches"in e){const i=e.touches[0]||e.changedTouches[0];return{x:i.clientX-t.left,y:i.clientY-t.top}}return{x:e.clientX-t.left,y:e.clientY-t.top}}getTargetElement(t){if("touches"in t){const i=t.touches[0]||t.changedTouches[0];if(i&&!e())return document.elementFromPoint(i.clientX,i.clientY)}return t.target}getClockCenter(){return{x:this.clockFace.offsetWidth/2,y:this.clockFace.offsetHeight/2}}getClockRadius(){return this.clockFace.offsetWidth/2}removeGlobalListeners(){!1!==t()&&(document.removeEventListener("mousemove",this.handlePointerMove),document.removeEventListener("touchmove",this.handlePointerMove),document.removeEventListener("mouseup",this.handlePointerUp),document.removeEventListener("touchend",this.handlePointerUp))}}class Q{renderer;controller;dragHandlers;clockType;disabledTime;tipsWrapper;tipsWrapperFor24h;constructor(e){this.clockType=e.clockType,this.disabledTime=e.disabledTime,this.tipsWrapper=e.tipsWrapper,this.tipsWrapperFor24h=e.tipsWrapperFor24h;const t={clockFace:e.clockFace,tipsWrapper:e.tipsWrapper,tipsWrapperFor24h:e.tipsWrapperFor24h,clockHand:e.clockHand,circle:e.circle,theme:e.theme};this.renderer=new X(t);const i={hour:e.initialHour,minute:e.initialMinute,amPm:e.initialAmPm,hourAngle:this.calculateInitialAngle("hours",e.initialHour),minuteAngle:this.calculateInitialAngle("minutes",e.initialMinute),mode:"hours"},s={onHourChange:e.onHourChange,onMinuteChange:e.onMinuteChange};this.controller=new G(this.renderer,i,e.clockType,e.disabledTime,e.incrementHours||1,e.incrementMinutes||1,e.smoothHourSnap??!0,s),this.dragHandlers=new J(this.controller,e.clockFace,e.dragConfig||{})}initialize(){this.dragHandlers.attach(),this.switchToHours()}switchToHours(){this.controller.switchMode("hours"),"24h"===this.clockType&&this.tipsWrapperFor24h&&this.tipsWrapperFor24h.classList.remove("none"),this.renderHourTips();const e=this.controller.getState();this.renderer.setActiveValue(e.hour)}switchToMinutes(){this.controller.switchMode("minutes"),this.tipsWrapperFor24h&&this.tipsWrapperFor24h.classList.add("none"),this.renderMinuteTips();const e=this.controller.getState();this.renderer.setActiveValue(e.minute)}setHour(e){this.controller.setValue("hours",e)}setMinute(e){this.controller.setValue("minutes",e)}setAmPm(e){this.controller.setAmPm(e);const t=this.controller.getState();"hours"===t.mode?(this.renderHourTips(),this.renderer.setHandAngle(t.hourAngle),this.renderer.setActiveValue(t.hour)):(this.renderMinuteTips(),this.renderer.setHandAngle(t.minuteAngle),this.renderer.setActiveValue(t.minute))}getHour(){return this.controller.getHour()}getMinute(){return this.controller.getMinute()}getAmPm(){return this.controller.getAmPm()}updateDisabledTime(e){this.disabledTime=e,this.controller.updateDisabledTime(e);"hours"===this.controller.getState().mode?this.renderHourTips():this.renderMinuteTips()}renderHourTips(){const e=this.controller.getState().amPm;"24h"===this.clockType?(this.renderer.renderTips(T,"tp-ui-hour-time-12","hours",this.disabledTime,this.clockType,!0,this.tipsWrapper,e),this.tipsWrapperFor24h&&this.renderer.renderTips(f,"tp-ui-hour-time-24","hours",this.disabledTime,this.clockType,!0,this.tipsWrapperFor24h,e)):this.renderer.renderTips(T,"tp-ui-hour-time-12","hours",this.disabledTime,this.clockType,!0,void 0,e)}renderMinuteTips(){const e=this.controller.getState(),t=e.amPm,i=e.hour;this.renderer.renderTips(k,"tp-ui-minutes-time","minutes",this.disabledTime,this.clockType,!0,void 0,t,i)}calculateInitialAngle(e,t){const i=parseInt(t,10);return"hours"===e?i%12*30:6*i}destroy(){this.dragHandlers.detach(),this.controller.destroy()}blockInteractions(){this.dragHandlers.block()}unblockInteractions(){this.dragHandlers.unblock()}}class ee{core;emitter;clockSystem=null;constructor(e,t){this.core=e,this.emitter=t}getClockSystem(){return this.clockSystem}initialize(){const e=this.core.getClockFace(),t=this.core.getClockHand(),i=this.core.getCircle();if(!e||!t||!i)return;const s="24h"===this.core.options.clock.type,r=this.core.getTipsWrapper();if(!r)return;const n=this.core.getHour(),o=this.core.getMinutes(),a={clockFace:e,tipsWrapper:r,tipsWrapperFor24h:s&&this.core.getTipsWrapperFor24h()||void 0,clockHand:t,circle:i,clockType:this.core.options.clock.type||"12h",disabledTime:this.convertDisabledTime(),initialHour:n?.value||"12",initialMinute:o?.value||"00",initialAmPm:this.getAmPmValue(),theme:this.core.options.ui.theme,incrementHours:this.core.options.clock.incrementHours||1,incrementMinutes:this.core.options.clock.incrementMinutes||1,smoothHourSnap:this.core.options.clock.smoothHourSnap??!0,timepicker:null,dragConfig:{autoSwitchToMinutes:this.core.options.clock.autoSwitchToMinutes,isMobileView:this.core.isMobileView,smoothHourSnap:this.core.options.clock.smoothHourSnap??!0,hourElement:n,minutesElement:o,onMinuteCommit:()=>{const e=this.core.getMinutes(),t=this.core.getHour(),i=this.core.getActiveTypeMode();this.emitter.emit("range:minute:commit",{hour:t?.value??"12",minutes:e?.value??"00",type:i?.textContent??void 0})}},onHourChange:e=>{const t=this.core.getHour();t&&(t.value=e,t.setAttribute("aria-valuenow",e));const i=this.core.getModalElement();V(i,`Hour: ${e}`);const s=this.core.getMinutes(),r=this.core.getActiveTypeMode();this.emitter.emit("update",{hour:e,minutes:s?.value,type:r?.textContent||void 0})},onMinuteChange:e=>{const t=this.core.getMinutes();t&&(t.value=e,t.setAttribute("aria-valuenow",e));const i=this.core.getModalElement();V(i,`Minutes: ${e}`);const s=this.core.getHour(),r=this.core.getActiveTypeMode();this.emitter.emit("update",{hour:s?.value,minutes:e,type:r?.textContent||void 0})}};this.clockSystem=new Q(a),this.clockSystem.initialize()}convertDisabledTime(){const e=this.core.disabledTime?.value;if(!e)return null;let t;return e.intervals&&(t=Array.isArray(e.intervals)?e.intervals:[e.intervals]),{hours:e.hours,minutes:e.minutes,isInterval:e.isInterval,intervals:t,clockType:e.clockType}}getAmPmValue(){if("24h"===this.core.options.clock.type)return"";const e=this.core.getActiveTypeMode();if(e){const t=e.textContent?.trim();if("AM"===t||"PM"===t)return t}const t=this.core.getAM();return!0===this.core.options.range?.enabled?t?.classList.contains("active")?"AM":"":t?.classList.contains("active")?"AM":"PM"}destroy(){this.clockSystem&&(this.clockSystem.destroy(),this.clockSystem=null)}}class te{core;constructor(e){this.core=e}removeCircleClockClasses24h(){const e=this.core.getCircle(),t=this.core.getClockHand();e?.classList.remove("tp-ui-circle-hand-24h"),t?.classList.remove("tp-ui-clock-hand-24h")}setCircleClockClasses24h(){const e=this.core.getCircle(),t=this.core.getClockHand();e&&e.classList.add("tp-ui-circle-hand-24h"),t&&t.classList.add("tp-ui-clock-hand-24h")}setOnStartCSSClassesIfClockType24h(){if("24h"===this.core.options.clock.type){const e=this.core.getInput();if(!e)return;let t;e.value.length>0&&(t=e.value.split(":")[0]),t&&(Number(t)>12||0===Number(t))&&this.setCircleClockClasses24h()}}setBgColorToCircleWithMinutesTips(){const e=this.core.getMinutes(),t=this.core.getCircle();if(e&&t&&e.value&&k.includes(e.value)){const e=getComputedStyle(t).getPropertyValue("--timepicker-primary").trim();e&&(t.style.backgroundColor=e),t.classList.remove("small-circle")}}removeBgColorToCirleWithMinutesTips(){const e=this.core.getMinutes(),t=this.core.getCircle();e&&t&&(e.value&&k.includes(e.value)||(t.style.backgroundColor="",t.classList.add("small-circle")))}setClassActiveToHourOnOpen(){if(this.core.options.ui.mobile||this.core.isMobileView)return;const e=this.core.getHour();e?.classList.add(E)}toggleClassActiveToValueTips(e,t){if(e)return;const i=this.core.getAllValueTips();if(!i)return;const s=i.find(e=>Number(e.innerText)===Number(t));i.forEach(e=>{e.classList.remove(E),e.setAttribute("aria-selected","false")}),void 0!==s&&(s.classList.add(E),s.setAttribute("aria-selected","true"))}}class ie{getClockSystem;styleHandler;getAmPmValue;clockType;constructor(e,t,i,s){this.getClockSystem=e,this.styleHandler=t,this.getAmPmValue=i,this.clockType=s}setMinutesToClock(e){const t=this.getClockSystem();t&&(this.styleHandler.removeBgColorToCirleWithMinutesTips(),e&&t.setMinute(e),t.switchToMinutes())}setHoursToClock(e){const t=this.getClockSystem();t&&(e&&t.setHour(e),t.switchToHours())}setTransformToCircleWithSwitchesHour(e){const t=this.getClockSystem();t&&e&&t.setHour(e)}setTransformToCircleWithSwitchesMinutes(e){const t=this.getClockSystem();t&&e&&t.setMinute(e)}updateAmPm(){const e=this.getClockSystem();if(!e||"24h"===this.clockType)return;const t=this.getAmPmValue();""!==t&&e.setAmPm(t)}}class se{systemInitializer;styleHandler;timeHandler;eventHandler;constructor(e,t){this.systemInitializer=new ee(e,t),this.styleHandler=new te(e);const i=e.options.clock.type||"12h";this.timeHandler=new ie(()=>this.systemInitializer.getClockSystem(),this.styleHandler,()=>this.systemInitializer.getAmPmValue(),i),this.eventHandler=new Z(t,()=>this.systemInitializer.getClockSystem(),e=>this.timeHandler.setHoursToClock(e),e=>this.timeHandler.setMinutesToClock(e),()=>this.timeHandler.updateAmPm(),()=>this.systemInitializer.convertDisabledTime()),this.eventHandler.setup()}initializeClockSystem(){this.systemInitializer.initialize()}destroyClockSystem(){this.systemInitializer.destroy()}removeCircleClockClasses24h(){this.styleHandler.removeCircleClockClasses24h()}setCircleClockClasses24h(){this.styleHandler.setCircleClockClasses24h()}setOnStartCSSClassesIfClockType24h(){this.styleHandler.setOnStartCSSClassesIfClockType24h()}setBgColorToCircleWithMinutesTips=()=>{this.styleHandler.setBgColorToCircleWithMinutesTips()};removeBgColorToCirleWithMinutesTips=()=>{this.styleHandler.removeBgColorToCirleWithMinutesTips()};setClassActiveToHourOnOpen=()=>{this.styleHandler.setClassActiveToHourOnOpen()};setMinutesToClock=e=>{this.timeHandler.setMinutesToClock(e)};setHoursToClock=e=>{this.timeHandler.setHoursToClock(e)};setTransformToCircleWithSwitchesHour=e=>{this.timeHandler.setTransformToCircleWithSwitchesHour(e)};setTransformToCircleWithSwitchesMinutes=e=>{this.timeHandler.setTransformToCircleWithSwitchesMinutes(e)};updateAmPm=()=>{this.timeHandler.updateAmPm()};toggleClassActiveToValueTips=e=>{const t=null!==this.systemInitializer.getClockSystem();this.styleHandler.toggleClassActiveToValueTips(t,e)};destroy(){this.destroyClockSystem()}}const re=new class{plugins=new Map;register(e){this.plugins.has(e.name)||this.plugins.set(e.name,e)}getAll(){return Array.from(this.plugins.values())}has(e){return this.plugins.has(e)}get(e){return this.plugins.get(e)}};class ne{animation;modal;config;theme;validation;events;clock;plugins=new Map;constructor(e,t){this.animation=new h(e,t),this.modal=new M(e,t),this.config=new $(e,t),this.theme=new P(e,t),this.validation=new q(e,t),this.events=new U(e,t),this.clock=new se(e,t);re.getAll().forEach(i=>{const s=i.factory(e,t);this.plugins.set(i.name,s)})}getPlugin(e){return this.plugins.get(e)}destroy(){this.animation.destroy(),this.modal.destroy(),this.config.destroy(),this.theme.destroy(),this.validation.destroy(),this.events.destroy(),this.clock.destroy(),this.plugins.forEach(e=>e.destroy()),this.plugins.clear()}}const oe="is-rippling",ae="ripple-hold";let le=null;function ce(e){const t=e.target,i=t.hasAttribute("data-md3-ripple")?t:t.closest("[data-md3-ripple]");if(!i)return;if(0!==e.button&&"mouse"===e.pointerType)return;const s=i.getBoundingClientRect(),r=2*Math.max(s.width,s.height),n=e.clientX-s.left,o=e.clientY-s.top;i.style.setProperty("--ripple-size",`${r}px`),i.style.setProperty("--ripple-x",`${n}px`),i.style.setProperty("--ripple-y",`${o}px`),i.classList.remove(oe,ae),i.offsetWidth,i.classList.add(oe,ae),i._rippleHold=!0,le=i}function ue(e){const t=e.target,i=(t.hasAttribute("data-md3-ripple")?t:t.closest("[data-md3-ripple]"))||le;i&&(i._rippleHold=!1,i.classList.remove(ae),setTimeout(()=>{i.classList.remove(oe),le===i&&(le=null)},1e3))}function he(e){const t=e.currentTarget;t&&t._rippleHold&&(t._rippleHold=!1,t.classList.remove(ae),setTimeout(()=>{t.classList.remove(oe),le===t&&(le=null)},1e3))}class de{core;managers;emitter;eventsClickMobileHandler=()=>{};mutliEventsMoveHandler=()=>{};constructor(e,t,i){this.core=e,this.managers=t,this.emitter=i}init(){if(!this.core.isDestroyed&&!this.core.isInitialized){try{this.managers.config.updateInputValueWithCurrentTimeOnStart(),this.managers.validation.checkDisabledValuesOnStart()}catch(e){return void this.core.setIsDestroyed(!0)}this.managers.theme.setTimepickerClassToElement(),this.managers.theme.setInputClassToInputElement(),this.managers.theme.setDataOpenToInputIfDoesntExistInWrapper(),this.managers.theme.setClassTopOpenElement(),this.managers.config.getDisableTime(),this.core.options.ui.inline?.enabled||this.managers.events.handleOpenOnClick(),this.managers.events.handleOpenOnEnterFocus(),this.setupCallbackBridge(),this.core.setIsInitialized(!0)}}setupCallbackBridge(){const{callbacks:e}=this.core.options;e.onOpen&&this.emitter.on("open",e.onOpen),e.onCancel&&this.emitter.on("cancel",e.onCancel),e.onConfirm&&this.emitter.on("confirm",e.onConfirm),e.onUpdate&&this.emitter.on("update",e.onUpdate),e.onSelectHour&&this.emitter.on("select:hour",e.onSelectHour),e.onSelectMinute&&this.emitter.on("select:minute",e.onSelectMinute),e.onSelectAM&&this.emitter.on("select:am",e.onSelectAM),e.onSelectPM&&this.emitter.on("select:pm",e.onSelectPM),e.onError&&this.emitter.on("error",e.onError),e.onTimezoneChange&&this.emitter.on("timezone:change",e.onTimezoneChange),e.onRangeConfirm&&this.emitter.on("range:confirm",e.onRangeConfirm),e.onRangeSwitch&&this.emitter.on("range:switch",e.onRangeSwitch),e.onRangeValidation&&this.emitter.on("range:validation",e.onRangeValidation)}mount(){this.core.isDestroyed||(this.core.isInitialized||this.init(),this.eventsBundle())}unmount(e){const i=((e,t)=>{let i;return(...s)=>{clearTimeout(i),i=setTimeout(()=>{e(...s)},t)}})((...e)=>{if(e.length>2||!this.core.getModalElement())return;const[i]=e.filter(e=>"boolean"==typeof e),[s]=e.filter(e=>"function"==typeof e);if(this.core.setIsMobileView(!!this.core.options.ui.mobile),i){const e=this.core.getOkButton();e?.click()}this.core.setIsTouchMouseMove(!1),this.removeEventListeners(),this.managers.animation.removeAnimationToClose();this.core.getOpenElement().forEach(e=>e?.classList.remove("disabled")),setTimeout(()=>{t()&&(document.body.style.overflowY="",document.body.style.paddingRight="")},n),setTimeout(()=>{const e=this.core.getInput();this.core.options.behavior.focusInputAfterClose&&e?.focus();const t=this.core.getModalElement();null!==t&&(t.remove(),this.core.setIsModalRemove(!0))},o),s&&s()},this.core.options.behavior.delayHandler||s);e?i(e):i()}destroy(t){if(this.core.isDestroyed)return;const i="function"==typeof t?{callback:t}:t||{},{keepInputValue:s=!1,callback:r}=i,n=this.core.getInput(),o=s?n?.value:null;this.removeEventListeners();const a=this.core.getModalElement();a?.remove();const l=this.core.getOpenElement();l?.forEach(e=>{e&&(e.classList.remove("disabled","active","tp-ui-open-element"),e.classList.remove("basic","crane-straight","crane","m2","m3-green"))}),n&&(n.classList.remove("tp-ui-invalid-format","invalid-value","error","active","tp-ui-input"),n.removeAttribute("data-open"),n.removeAttribute("data-owner-id"),s&&o&&(n.value=o));const c=this.core.element;c&&(c.classList.remove("basic","crane-straight","crane","m2","m3-green"),c.classList.remove("error","active","disabled"),c.removeAttribute("data-owner-id"),c.removeAttribute("data-open"),this.core.options.ui.cssClass&&c.classList.remove(this.core.options.ui.cssClass));const u=c?.querySelectorAll(".tp-ui-invalid-text");u?.forEach(e=>e.remove()),this.mutliEventsMoveHandler=()=>{},this.eventsClickMobileHandler=()=>{},this.core.reset(),this.managers.destroy(),this.emitter.clear(),e()||(document.body.style.overflowY="",document.body.style.paddingRight=""),r&&r()}eventsBundle(){if(this.core.isDestroyed)return;if(!this.core.isModalRemove)return;if(this.managers.validation.setErrorHandler(),this.managers.validation.removeErrorHandler(),!this.core.options.ui.inline?.enabled){const e=this.core.getOpenElement(),t=this.core.getInput();e.forEach(e=>e?.classList.add("disabled")),t?.blur()}if(this.managers.modal.setScrollbarOrNot(),this.managers.modal.setModalTemplate(),this.managers.modal.setNormalizeClass(),this.managers.modal.removeBackdrop(),this.core.isMobileView)this.managers.config.updateClockFaceAccessibility(!0);else{const e=this.core.getModalElement(),t=e?.querySelector(".tp-ui-mobile-clock-wrapper"),i=e?.querySelector(".tp-ui-wrapper"),s=e?.querySelectorAll("*");t?.classList.add("expanded"),i?.classList.add("expanded"),s?.forEach(e=>{e.classList.contains("tp-ui-select-time")||e.classList.contains("tp-ui-mobile-clock-wrapper")||e.classList.contains("tp-ui-wrapper")||e.classList.add("expanded")})}this.managers.modal.setFlexEndToFooterIfNoKeyboardIcon(),setTimeout(()=>{this.managers.theme.setTheme();const e=this.core.getWrapper();e&&this.core.options.ui.cssClass&&e.classList.add(this.core.options.ui.cssClass)},0),this.managers.animation.setAnimationToOpen(),this.managers.config.getInputValueOnOpenAndSet(),this.managers.clock.initializeClockSystem(),this.managers.clock.setOnStartCSSClassesIfClockType24h(),this.managers.clock.setClassActiveToHourOnOpen();const e=this.managers.getPlugin("timezone");e&&e.init();const i=this.managers.getPlugin("range");i&&i.init(),this.managers.events.handleCancelButton(),this.managers.events.handleOkButton(),this.managers.events.handleHourEvents(),this.managers.events.handleMinutesEvents(),this.managers.events.handleKeyboardInput(),this.core.options.ui.enableSwitchIcon&&this.managers.events.handleSwitchViewButton(),"24h"!==this.core.options.clock.type&&(this.managers.events.handleAmClick(),this.managers.events.handlePmClick()),this.core.options.behavior.focusTrap&&this.managers.events.focusTrapHandler(),this.core.options.ui.inline?.enabled||(this.managers.events.handleEscClick(),this.managers.events.handleBackdropClick());const s=this.core.getModalElement();s&&function(e){if(!1===t())return;const i=e||document;i.addEventListener("pointerdown",ce),i.addEventListener("pointerup",ue),i.addEventListener("pointercancel",ue),i.querySelectorAll("[data-md3-ripple]").forEach(e=>{e.addEventListener("mouseleave",he)})}(s);const r=this.core.getClockFace();r&&"undefined"!=typeof requestAnimationFrame&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{r?.classList.add("scale-in")})}),this.managers.modal.setShowClassToBackdrop()}removeEventListeners(){if(!1===t())return;w.split(" ").forEach(e=>{document.removeEventListener(e,this.mutliEventsMoveHandler,!1)}),document.removeEventListener("mousedown",this.eventsClickMobileHandler)}}class me{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(e=>{e(t)})}clear(){this.events.clear()}hasListeners(e){return(this.events.get(e)?.size??0)>0}}const pe={type:"12h",incrementHours:1,incrementMinutes:1,autoSwitchToMinutes:!0,disabledTime:void 0,currentTime:void 0},ge={theme:"basic",animation:!0,backdrop:!0,mobile:!1,enableSwitchIcon:!1,editable:!1,enableScrollbar:!1,cssClass:void 0,appendModalSelector:"",iconTemplate:"",iconTemplateMobile:"",inline:void 0},ve={am:"AM",pm:"PM",ok:"OK",cancel:"Cancel",time:"Select time",mobileTime:"Enter Time",mobileHour:"Hour",mobileMinute:"Minute"},be={focusInputAfterClose:!1,focusTrap:!0,delayHandler:300,id:void 0},ye={onOpen:void 0,onCancel:void 0,onConfirm:void 0,onUpdate:void 0,onSelectHour:void 0,onSelectMinute:void 0,onSelectAM:void 0,onSelectPM:void 0,onError:void 0,onTimezoneChange:void 0,onRangeConfirm:void 0,onRangeSwitch:void 0,onRangeValidation:void 0},fe={enabled:!1,default:void 0,whitelist:void 0,label:"Timezone"},Te={enabled:!1,minDuration:void 0,maxDuration:void 0,fromLabel:"From",toLabel:"To"};const ke=new Map;return class{core;managers;lifecycle;emitter;constructor(t,s){if(e())throw new Error("TimepickerUI requires browser environment");const r=this.resolveInputElement(t);if(!r)throw new Error("Input element not found");const n=s?.behavior?.id,o=n||`tp-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)})}`,a=this.createWrapperElement(r),l=function(e={}){return{clock:{...pe,...e.clock||{}},ui:{...ge,...e.ui||{}},labels:{...ve,...e.labels||{}},behavior:{...be,...e.behavior||{}},callbacks:{...ye,...e.callbacks||{}},timezone:{...fe,...e.timezone||{}},range:{...Te,...e.range||{}}}}(s||{});if(l.ui.inline?.enabled&&void 0===s?.behavior?.focusTrap&&(l.behavior.focusTrap=!1),l.ui.inline?.enabled){if(!l.ui.inline.containerId)throw new Error("inline.containerId is required when inline mode is enabled");if(!e()){if(!document.getElementById(l.ui.inline.containerId))throw new Error(`Container element with id "${l.ui.inline.containerId}" not found`)}}this.emitter=new me,this.core=new i(a,l,o,n);const c=this.core.getInput();if(c){const e=C(c,l.clock.type),t=30*Number(e.hour),i=6*Number(e.minutes);this.core.setDegreesHours(t),this.core.setDegreesMinutes(i)}this.managers=new ne(this.core,this.emitter),this.lifecycle=new de(this.core,this.managers,this.emitter),this.managers.config.checkMobileOption(),this.managers.config.preventClockTypeByCurrentTime(),this.setupInternalEventListeners(),ke.set(this.core.instanceId,this)}setupInternalEventListeners(){this.emitter.on("show",()=>{this.core.isDestroyed||this.lifecycle.mount()}),this.emitter.on("cancel",()=>{this.core.isDestroyed||this.lifecycle.unmount()}),this.emitter.on("confirm",e=>{if(!this.core.isDestroyed){if(this.core.options.range?.enabled)return;const t=this.core.getInput();if(t&&e.hour&&e.minutes){const i=e.type?` ${e.type}`:"";t.value=`${e.hour}:${e.minutes}${i}`}this.lifecycle.unmount()}}),this.emitter.on("range:confirm",e=>{if(this.core.isDestroyed)return;const t=this.core.getInput();t&&(t.value=`${e.from} - ${e.to}`),this.lifecycle.unmount()})}create(){this.lifecycle.init(),this.core.options.ui.inline?.enabled&&this.lifecycle.mount()}open(e){this.lifecycle.mount(),e&&e()}close(e,t){this.lifecycle.unmount(e?t:void 0),!e&&t&&t()}destroy(e){ke.delete(this.core.instanceId),this.lifecycle.destroy(e)}update(e,t){this.core.isDestroyed||(this.core.updateOptions(e.options),this.managers.config.checkMobileOption(),e.create&&this.create(),t&&t())}getValue(){if(this.core.isDestroyed)return{hour:"",minutes:"",type:void 0,time:"",degreesHours:null,degreesMinutes:null};const e=this.core.getHour(),t=this.core.getMinutes(),i=this.core.getActiveTypeMode(),s=e?.value||"12",r=t?.value||"00",n="24h"===this.core.options.clock.type?void 0:i?.textContent||"AM";let o="";return o="24h"===this.core.options.clock.type?`${s.padStart(2,"0")}:${r.padStart(2,"0")}`:`${s}:${r.padStart(2,"0")} ${n}`,{hour:s,minutes:r,type:n,time:o,degreesHours:this.core.degreesHours,degreesMinutes:this.core.degreesMinutes}}setValue(e,t=!0){if(this.core.isDestroyed)return;if(!e||"string"!=typeof e)return;this.core.isInitialized||this.create();const i=e.trim().replace(/[^0-9:APMapm\s]/g,"");let s="12",r="00",n="AM";try{if("24h"===this.core.options.clock.type){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()}const e=this.core.getHour(),o=this.core.getMinutes(),a=this.core.getAM(),l=this.core.getPM();if(e&&(e.value=s,e.setAttribute("aria-valuenow",s),this.core.setDegreesHours(30*Number(s))),o&&(o.value=r,o.setAttribute("aria-valuenow",r),this.core.setDegreesMinutes(6*Number(r))),"24h"!==this.core.options.clock.type&&a&&l&&("AM"===n?(a.classList.add("active"),l.classList.remove("active")):(l.classList.add("active"),a.classList.remove("active"))),t){const e=this.core.getInput();e&&(e.value=i)}const c=this.core.getClockHand();c&&(c.style.transform=`rotateZ(${this.core.degreesHours||0}deg)`)}catch(e){return}}getElement(){return this.core.element}get instanceId(){return this.core.instanceId}get options(){return this.core.options}get isInitialized(){return this.core.isInitialized}get isDestroyed(){return this.core.isDestroyed}get hour(){return this.core.getHour()}get minutes(){return this.core.getMinutes()}get okButton(){return this.core.getOkButton()}get cancelButton(){return this.core.getCancelButton()}get clockHand(){return this.core.getClockHand()}on(e,t){this.core.isDestroyed||this.emitter.on(e,t)}once(e,t){this.core.isDestroyed||this.emitter.once(e,t)}off(e,t){this.core.isDestroyed||this.emitter.off(e,t)}resolveInputElement(e){if(!1===t())return null;let i=null;if("string"==typeof e){if(i=document.querySelector(e),!i)return null}else{if(!(e instanceof HTMLElement))return null;i=e}if("INPUT"===i.tagName)return i;return i.querySelector("input")}createWrapperElement(e){if(!1===t())return e;const i=e.parentElement;if("INPUT"===e.tagName&&!i?.classList.contains("tp-ui")){const t=document.createElement("div");return t.className="tp-ui",e.parentNode?.insertBefore(t,e),t.appendChild(e),t}return i&&!i.classList.contains("tp-ui")&&i.classList.add("tp-ui"),i||e}static getById(e){return ke.get(e)}static getAllInstances(){return Array.from(ke.values())}static isAvailable(t){return!e()&&("string"==typeof t?null!==document.querySelector(t):t instanceof HTMLElement&&document.contains(t))}static destroyAll(){Array.from(ke.values()).forEach(e=>e.destroy()),ke.clear()}}});
|
package/dist/plugins/range.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var d=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var R=(n,t)=>{for(var e in t)d(n,e,{get:t[e],enumerable:!0})},E=(n,t,e,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of P(t))!T.call(n,i)&&i!==e&&d(n,i,{get:()=>t[i],enumerable:!(a=y(t,i))||a.enumerable});return n};var C=n=>E(d({},"__esModule",{value:!0}),n);var D={};R(D,{RangeManager:()=>u,RangePlugin:()=>A});module.exports=C(D);function f(n){if(!n||n==="--:--")return null;let t=n.match(/^(\d{1,2}):(\d{2})\s*(AM|PM)$/i);if(t)return{hour:t[1],minutes:t[2],type:t[3].toUpperCase()};let e=n.match(/^(\d{1,2}):(\d{2})$/);return e?{hour:e[1],minutes:e[2]}:null}function o(n){let t=n.minutes==="--"?"--":n.minutes.padStart(2,"0"),e=`${n.hour}:${t}`;return n.type?`${e} ${n.type}`:e}function g(n,t){if(!n)return 0;let e=parseInt(n.hour,10),a=parseInt(n.minutes,10);return t==="12h"&&n.type&&(n.type==="PM"&&e!==12&&(e+=12),n.type==="AM"&&e===12&&(e=0)),e*60+a}function v(n,t,e){if(!n||!t)return 0;let a=g(n,e),i=g(t,e);return i<=a&&(i+=1440),i-a}function p(n,t){return n?t==="12h"?!!(n.hour&&n.minutes&&n.type):!!(n.hour&&n.minutes):!1}function V(n){if(!n||!n.includes(" - "))return{from:null,to:null};let t=n.split(" - ").map(e=>e.trim());return t.length!==2||t[0]==="--:--"||t[1]==="--:--"?{from:null,to:null}:{from:f(t[0]),to:f(t[1])}}var m=class{activePart="from";fromValue=null;toValue=null;previewValue=null;clockType;minDuration;maxDuration;emitter;constructor(t,e,a,i){this.clockType=t,this.minDuration=e,this.maxDuration=a,this.emitter=i}getActivePart(){return this.activePart}getFromValue(){return this.fromValue}getToValue(){return this.toValue}getPreviewValue(){return this.previewValue}setFromValue(t){this.fromValue=t}setToValue(t){this.toValue=t}setPreviewValue(t){this.previewValue=t}isFromComplete(){return p(this.fromValue,this.clockType)}isToComplete(){return p(this.toValue,this.clockType)}canSwitchToEnd(){return this.isFromComplete()}canConfirm(){return this.isFromComplete()&&this.isToComplete()}setActivePart(t){if(t==="to"&&!this.canSwitchToEnd())return!1;let e=this.activePart!==t;return this.activePart=t,e&&(this.previewValue=null),e}getCurrentValue(){return this.previewValue?this.previewValue:this.activePart==="from"?this.fromValue:this.toValue}getSavedValue(){return this.activePart==="from"?this.fromValue:this.toValue}commitPreview(){this.previewValue&&(this.activePart==="from"?this.fromValue=this.previewValue:this.toValue=this.previewValue,this.previewValue=null)}getDuration(){return v(this.fromValue,this.toValue,this.clockType)}validate(){if(!this.fromValue||!this.toValue)return{valid:!0,duration:0};let t=this.getDuration(),e=!0;return this.minDuration!==void 0&&t<this.minDuration&&(e=!1),this.maxDuration!==void 0&&t>this.maxDuration&&(e=!1),this.emitter.emit("range:validation",{valid:e,duration:t,minDuration:this.minDuration,maxDuration:this.maxDuration}),{valid:e,duration:t}}getDisabledTimeForEndPart(){if(this.activePart==="from"||!this.fromValue||!this.isFromComplete())return null;let t=[],e=[],a=parseInt(this.fromValue.hour,10),i=parseInt(this.fromValue.minutes,10),r=this.fromValue.type;if(this.clockType==="24h"){for(let s=0;s<a;s++)t.push(s.toString().padStart(2,"0"));for(let s=0;s<i;s++)e.push(s.toString().padStart(2,"0"));return{hours:t,minutes:e}}for(let s=0;s<i;s++)e.push(s.toString().padStart(2,"0"));return{hours:t,minutes:e,fromType:r,fromHour:a}}reset(){this.activePart="from",this.fromValue=null,this.toValue=null,this.previewValue=null}};var h=class{core;state;constructor(t,e){this.core=t,this.state=e}updateTabs(){let t=this.core.getModalElement();if(!t)return;let e=t.querySelector(".tp-ui-range-tab.tp-ui-range-from"),a=t.querySelector(".tp-ui-range-tab.tp-ui-range-to"),i=this.state.getActivePart()==="from",r=this.state.isFromComplete();e?.classList.toggle("active",i),a?.classList.toggle("active",!i),a?.classList.toggle("disabled",!r),e?.setAttribute("aria-selected",String(i)),a?.setAttribute("aria-selected",String(!i)),a?.setAttribute("aria-disabled",String(!r)),e?.setAttribute("tabindex",i?"0":"-1"),a?.setAttribute("tabindex",i||!r?"-1":"0")}updateTimeDisplay(){let t=this.core.getModalElement();if(!t)return;let e=t.querySelector(".tp-ui-range-from-time"),a=t.querySelector(".tp-ui-range-to-time"),i=this.state.getActivePart(),r=this.state.getPreviewValue(),s=this.state.getFromValue(),l=this.state.getToValue(),c=i==="from"&&r?o(r):s?o(s):"--:--",b=i==="to"&&r?o(r):l?o(l):"--:--";e&&(e.textContent=c),a&&(a.textContent=b)}updateOkButton(){let t=this.core.getOkButton();if(!t)return;let e=this.state.canConfirm();t.classList.toggle("disabled",!e),t.setAttribute("aria-disabled",String(!e))}updateInputValue(){let t=this.core.getInput();if(!t)return;let e=this.state.getFromValue(),a=this.state.getToValue(),i=e?o(e):"--:--",r=a?o(a):"--:--";t.value=`${i} - ${r}`}syncClockToActivePart(){let t=this.state.getSavedValue(),e=this.core.getHour(),a=this.core.getMinutes();if(e&&(e.value=t?.hour??"12"),a&&(a.value=t?.minutes??"00"),this.core.options.clock.type==="12h"){let i=this.core.getAM(),r=this.core.getPM();t?.type==="AM"?(i?.classList.add("active"),r?.classList.remove("active")):t?.type==="PM"?(r?.classList.add("active"),i?.classList.remove("active")):(i?.classList.remove("active"),r?.classList.remove("active"))}a&&(a.blur(),a.classList.remove("active")),e&&e.click()}updateAll(){this.updateTabs(),this.updateTimeDisplay(),this.updateOkButton(),this.updateInputValue()}};var u=class{core;emitter;state;ui;cleanupHandlers=[];boundHandleMinuteCommit;boundHandleConfirm;boundHandleUpdate;boundHandleAmPm;constructor(t,e){this.core=t,this.emitter=e;let{range:a,clock:i}=t.options;this.state=new m(i.type,a?.minDuration,a?.maxDuration,e),this.ui=new h(t,this.state),this.boundHandleMinuteCommit=this.handleMinuteCommit.bind(this),this.boundHandleConfirm=this.handleConfirm.bind(this),this.boundHandleUpdate=this.handleUpdate.bind(this),this.boundHandleAmPm=this.handleAmPm.bind(this)}get isEnabled(){return this.core.options.range?.enabled===!0}init(){if(!this.isEnabled)return;let e=this.core.getInput()?.value||"",{from:a,to:i}=V(e);this.state.setFromValue(a),this.state.setToValue(i),this.state.setActivePart("from"),this.state.setPreviewValue(null),this.bindEvents(),this.ui.syncClockToActivePart(),this.ui.updateAll()}getActivePart(){return this.state.getActivePart()}setActivePart(t){if(!this.isEnabled)return;this.state.setActivePart(t)&&this.emitter.emit("range:switch",{active:t,disabledTime:this.state.getDisabledTimeForEndPart()}),this.ui.syncClockToActivePart(),this.ui.updateAll()}getFromValue(){return this.state.getFromValue()}getToValue(){return this.state.getToValue()}getDisabledTimeForEndPart(){return this.isEnabled?this.state.getDisabledTimeForEndPart():null}getDuration(){return this.state.getDuration()}validateRange(){return this.isEnabled?this.state.validate():{valid:!0,duration:0}}canConfirm(){return this.isEnabled?this.state.canConfirm():!0}getFormattedRange(){let t=this.state.getFromValue(),e=this.state.getToValue();return!t||!e?null:{from:o(t),to:o(e)}}bindEvents(){let t=this.core.getModalElement();if(!t)return;let e=t.querySelector(".tp-ui-range-tab.tp-ui-range-from"),a=t.querySelector(".tp-ui-range-tab.tp-ui-range-to");if(e){let i=()=>this.setActivePart("from");e.addEventListener("click",i),this.cleanupHandlers.push(()=>e.removeEventListener("click",i))}if(a){let i=()=>this.setActivePart("to");a.addEventListener("click",i),this.cleanupHandlers.push(()=>a.removeEventListener("click",i))}this.emitter.on("update",this.boundHandleUpdate),this.cleanupHandlers.push(()=>this.emitter.off("update",this.boundHandleUpdate)),this.emitter.on("range:minute:commit",this.boundHandleMinuteCommit),this.cleanupHandlers.push(()=>this.emitter.off("range:minute:commit",this.boundHandleMinuteCommit)),this.emitter.on("confirm",this.boundHandleConfirm),this.cleanupHandlers.push(()=>this.emitter.off("confirm",this.boundHandleConfirm)),this.emitter.on("select:am",this.boundHandleAmPm),this.cleanupHandlers.push(()=>this.emitter.off("select:am",this.boundHandleAmPm)),this.emitter.on("select:pm",this.boundHandleAmPm),this.cleanupHandlers.push(()=>this.emitter.off("select:pm",this.boundHandleAmPm))}handleUpdate(){if(!this.isEnabled)return;let t=this.core.getHour(),e=this.core.getMinutes(),a=this.core.getActiveTypeMode(),i=t?.value??"12",r=this.state.getSavedValue(),l=r?.minutes&&r.minutes!=="--"?e?.value??"--":"--",c=this.core.options.clock.type==="12h"?a?.textContent??void 0:void 0;this.state.setPreviewValue({hour:i,minutes:l,type:c}),this.ui.updateAll()}handleMinuteCommit(t){if(!this.isEnabled)return;let e={hour:t.hour,minutes:t.minutes,type:t.type??void 0};this.state.getActivePart()==="from"?(this.state.setFromValue(e),this.state.setPreviewValue(null),this.state.isFromComplete()&&(this.state.setActivePart("to"),this.emitter.emit("range:switch",{active:"to",disabledTime:this.state.getDisabledTimeForEndPart()}),this.ui.syncClockToActivePart())):(this.state.setToValue(e),this.state.setPreviewValue(null)),this.state.validate(),this.ui.updateAll()}handleAmPm(){if(!this.isEnabled||this.core.options.clock.type!=="12h")return;let e=this.core.getActiveTypeMode()?.textContent;if(!e)return;if(this.state.getActivePart()==="from"){let i=this.state.getFromValue();i&&(this.state.setFromValue({...i,type:e}),this.state.isFromComplete()&&(this.state.setActivePart("to"),this.state.setPreviewValue(null),this.emitter.emit("range:switch",{active:"to",disabledTime:this.state.getDisabledTimeForEndPart()}),this.ui.syncClockToActivePart()))}else{let i=this.state.getToValue();i&&this.state.setToValue({...i,type:e}),this.emitter.emit("range:switch",{active:"to",disabledTime:this.state.getDisabledTimeForEndPart()})}this.state.validate(),this.ui.updateAll()}handleConfirm(t){if(!this.isEnabled)return;this.state.commitPreview();let e=this.state.getFromValue(),a=this.state.getToValue(),i=e?o(e):"--:--",r=a?o(a):"--:--",s=this.state.getDuration();this.emitter.emit("range:confirm",{from:i,to:r,duration:s})}reset(){this.state.reset()}destroy(){this.cleanupHandlers.forEach(t=>t()),this.cleanupHandlers=[],this.reset()}};var A={name:"range",factory:(n,t)=>new u(n,t)};0&&(module.exports={RangeManager,RangePlugin});
|
|
1
|
+
"use strict";var d=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var R=(n,t)=>{for(var e in t)d(n,e,{get:t[e],enumerable:!0})},E=(n,t,e,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of P(t))!T.call(n,i)&&i!==e&&d(n,i,{get:()=>t[i],enumerable:!(a=y(t,i))||a.enumerable});return n};var C=n=>E(d({},"__esModule",{value:!0}),n);var D={};R(D,{RangeManager:()=>u,RangePlugin:()=>A});module.exports=C(D);function f(n){if(!n||n==="--:--")return null;let t=n.match(/^(\d{1,2}):(\d{2})\s*(AM|PM)$/i);if(t)return{hour:t[1],minutes:t[2],type:t[3].toUpperCase()};let e=n.match(/^(\d{1,2}):(\d{2})$/);return e?{hour:e[1],minutes:e[2]}:null}function o(n){let t=n.minutes==="--"?"--":n.minutes.padStart(2,"0"),e=`${n.hour}:${t}`;return n.type?`${e} ${n.type}`:e}function g(n,t){if(!n)return 0;let e=parseInt(n.hour,10),a=parseInt(n.minutes,10);return t==="12h"&&n.type&&(n.type==="PM"&&e!==12&&(e+=12),n.type==="AM"&&e===12&&(e=0)),e*60+a}function v(n,t,e){if(!n||!t)return 0;let a=g(n,e),i=g(t,e);return i<=a&&(i+=1440),i-a}function p(n,t){return n?t==="12h"?!!(n.hour&&n.minutes&&n.type):!!(n.hour&&n.minutes):!1}function V(n){if(!n||!n.includes(" - "))return{from:null,to:null};let t=n.split(" - ").map(e=>e.trim());return t.length!==2||t[0]==="--:--"||t[1]==="--:--"?{from:null,to:null}:{from:f(t[0]),to:f(t[1])}}var m=class{activePart="from";fromValue=null;toValue=null;previewValue=null;clockType;minDuration;maxDuration;emitter;constructor(t,e,a,i){this.clockType=t,this.minDuration=e,this.maxDuration=a,this.emitter=i}getActivePart(){return this.activePart}getFromValue(){return this.fromValue}getToValue(){return this.toValue}getPreviewValue(){return this.previewValue}setFromValue(t){this.fromValue=t}setToValue(t){this.toValue=t}setPreviewValue(t){this.previewValue=t}isFromComplete(){return p(this.fromValue,this.clockType)}isToComplete(){return p(this.toValue,this.clockType)}canSwitchToEnd(){return this.isFromComplete()}canConfirm(){return this.isFromComplete()&&this.isToComplete()}setActivePart(t){if(t==="to"&&!this.canSwitchToEnd())return!1;let e=this.activePart!==t;return this.activePart=t,e&&(this.previewValue=null),e}getCurrentValue(){return this.previewValue?this.previewValue:this.activePart==="from"?this.fromValue:this.toValue}getSavedValue(){return this.activePart==="from"?this.fromValue:this.toValue}commitPreview(){this.previewValue&&(this.activePart==="from"?this.fromValue=this.previewValue:this.toValue=this.previewValue,this.previewValue=null)}getDuration(){return v(this.fromValue,this.toValue,this.clockType)}validate(){if(!this.fromValue||!this.toValue)return{valid:!0,duration:0};let t=this.getDuration(),e=!0;return this.minDuration!==void 0&&t<this.minDuration&&(e=!1),this.maxDuration!==void 0&&t>this.maxDuration&&(e=!1),this.emitter.emit("range:validation",{valid:e,duration:t,minDuration:this.minDuration,maxDuration:this.maxDuration}),{valid:e,duration:t}}getDisabledTimeForEndPart(){if(this.activePart==="from"||!this.fromValue||!this.isFromComplete())return null;let t=[],e=[],a=parseInt(this.fromValue.hour,10),i=parseInt(this.fromValue.minutes,10),r=this.fromValue.type;if(this.clockType==="24h"){for(let s=0;s<a;s++)t.push(s.toString().padStart(2,"0"));for(let s=0;s<i;s++)e.push(s.toString().padStart(2,"0"));return{hours:t,minutes:e}}for(let s=0;s<i;s++)e.push(s.toString().padStart(2,"0"));return{hours:t,minutes:e,fromType:r,fromHour:a}}reset(){this.activePart="from",this.fromValue=null,this.toValue=null,this.previewValue=null}};var h=class{core;state;constructor(t,e){this.core=t,this.state=e}updateTabs(){let t=this.core.getModalElement();if(!t)return;let e=t.querySelector(".tp-ui-range-tab.tp-ui-range-from"),a=t.querySelector(".tp-ui-range-tab.tp-ui-range-to"),i=this.state.getActivePart()==="from",r=this.state.isFromComplete();e?.classList.toggle("active",i),a?.classList.toggle("active",!i),a?.classList.toggle("disabled",!r),e?.setAttribute("aria-selected",String(i)),a?.setAttribute("aria-selected",String(!i)),a?.setAttribute("aria-disabled",String(!r)),e?.setAttribute("tabindex",i?"0":"-1"),a?.setAttribute("tabindex",i||!r?"-1":"0")}updateTimeDisplay(){let t=this.core.getModalElement();if(!t)return;let e=t.querySelector(".tp-ui-range-from-time"),a=t.querySelector(".tp-ui-range-to-time"),i=this.state.getActivePart(),r=this.state.getPreviewValue(),s=this.state.getFromValue(),l=this.state.getToValue(),c=i==="from"&&r?o(r):s?o(s):"--:--",b=i==="to"&&r?o(r):l?o(l):"--:--";e&&(e.textContent=c),a&&(a.textContent=b)}updateOkButton(){let t=this.core.getOkButton();if(!t)return;let e=this.state.canConfirm();t.classList.toggle("disabled",!e),t.setAttribute("aria-disabled",String(!e))}updateInputValue(){let t=this.core.getInput();if(!t)return;let e=this.state.getFromValue(),a=this.state.getToValue(),i=e?o(e):"--:--",r=a?o(a):"--:--";t.value=`${i} - ${r}`}syncClockToActivePart(){let t=this.state.getSavedValue(),e=this.core.getHour(),a=this.core.getMinutes();if(e&&(e.value=t?.hour??"12"),a&&(a.value=t?.minutes??"00"),this.core.options.clock.type==="12h"){let i=this.core.getAM(),r=this.core.getPM();t?.type==="AM"?(i?.classList.add("active"),r?.classList.remove("active")):t?.type==="PM"?(r?.classList.add("active"),i?.classList.remove("active")):(i?.classList.remove("active"),r?.classList.remove("active"))}a&&(a.blur(),a.classList.remove("active")),e&&e.click()}updateAll(){this.updateTabs(),this.updateTimeDisplay(),this.updateOkButton()}};var u=class{core;emitter;state;ui;cleanupHandlers=[];boundHandleMinuteCommit;boundHandleConfirm;boundHandleUpdate;boundHandleAmPm;constructor(t,e){this.core=t,this.emitter=e;let{range:a,clock:i}=t.options;this.state=new m(i.type,a?.minDuration,a?.maxDuration,e),this.ui=new h(t,this.state),this.boundHandleMinuteCommit=this.handleMinuteCommit.bind(this),this.boundHandleConfirm=this.handleConfirm.bind(this),this.boundHandleUpdate=this.handleUpdate.bind(this),this.boundHandleAmPm=this.handleAmPm.bind(this)}get isEnabled(){return this.core.options.range?.enabled===!0}init(){if(!this.isEnabled)return;let e=this.core.getInput()?.value||"",{from:a,to:i}=V(e);this.state.setFromValue(a),this.state.setToValue(i),this.state.setActivePart("from"),this.state.setPreviewValue(null),this.bindEvents(),this.ui.syncClockToActivePart(),this.ui.updateAll()}getActivePart(){return this.state.getActivePart()}setActivePart(t){if(!this.isEnabled)return;this.state.setActivePart(t)&&this.emitter.emit("range:switch",{active:t,disabledTime:this.state.getDisabledTimeForEndPart()}),this.ui.syncClockToActivePart(),this.ui.updateAll()}getFromValue(){return this.state.getFromValue()}getToValue(){return this.state.getToValue()}getDisabledTimeForEndPart(){return this.isEnabled?this.state.getDisabledTimeForEndPart():null}getDuration(){return this.state.getDuration()}validateRange(){return this.isEnabled?this.state.validate():{valid:!0,duration:0}}canConfirm(){return this.isEnabled?this.state.canConfirm():!0}getFormattedRange(){let t=this.state.getFromValue(),e=this.state.getToValue();return!t||!e?null:{from:o(t),to:o(e)}}bindEvents(){let t=this.core.getModalElement();if(!t)return;let e=t.querySelector(".tp-ui-range-tab.tp-ui-range-from"),a=t.querySelector(".tp-ui-range-tab.tp-ui-range-to");if(e){let i=()=>this.setActivePart("from");e.addEventListener("click",i),this.cleanupHandlers.push(()=>e.removeEventListener("click",i))}if(a){let i=()=>this.setActivePart("to");a.addEventListener("click",i),this.cleanupHandlers.push(()=>a.removeEventListener("click",i))}this.emitter.on("update",this.boundHandleUpdate),this.cleanupHandlers.push(()=>this.emitter.off("update",this.boundHandleUpdate)),this.emitter.on("range:minute:commit",this.boundHandleMinuteCommit),this.cleanupHandlers.push(()=>this.emitter.off("range:minute:commit",this.boundHandleMinuteCommit)),this.emitter.on("confirm",this.boundHandleConfirm),this.cleanupHandlers.push(()=>this.emitter.off("confirm",this.boundHandleConfirm)),this.emitter.on("select:am",this.boundHandleAmPm),this.cleanupHandlers.push(()=>this.emitter.off("select:am",this.boundHandleAmPm)),this.emitter.on("select:pm",this.boundHandleAmPm),this.cleanupHandlers.push(()=>this.emitter.off("select:pm",this.boundHandleAmPm))}handleUpdate(){if(!this.isEnabled)return;let t=this.core.getHour(),e=this.core.getMinutes(),a=this.core.getActiveTypeMode(),i=t?.value??"12",r=this.state.getSavedValue(),l=r?.minutes&&r.minutes!=="--"?e?.value??"--":"--",c=this.core.options.clock.type==="12h"?a?.textContent??void 0:void 0;this.state.setPreviewValue({hour:i,minutes:l,type:c}),this.ui.updateAll()}handleMinuteCommit(t){if(!this.isEnabled)return;let e={hour:t.hour,minutes:t.minutes,type:t.type??void 0};this.state.getActivePart()==="from"?(this.state.setFromValue(e),this.state.setPreviewValue(null),this.state.isFromComplete()&&(this.state.setActivePart("to"),this.emitter.emit("range:switch",{active:"to",disabledTime:this.state.getDisabledTimeForEndPart()}),this.ui.syncClockToActivePart())):(this.state.setToValue(e),this.state.setPreviewValue(null)),this.state.validate(),this.ui.updateAll()}handleAmPm(){if(!this.isEnabled||this.core.options.clock.type!=="12h")return;let e=this.core.getActiveTypeMode()?.textContent;if(!e)return;if(this.state.getActivePart()==="from"){let i=this.state.getFromValue();i&&(this.state.setFromValue({...i,type:e}),this.state.isFromComplete()&&(this.state.setActivePart("to"),this.state.setPreviewValue(null),this.emitter.emit("range:switch",{active:"to",disabledTime:this.state.getDisabledTimeForEndPart()}),this.ui.syncClockToActivePart()))}else{let i=this.state.getToValue();i&&this.state.setToValue({...i,type:e}),this.emitter.emit("range:switch",{active:"to",disabledTime:this.state.getDisabledTimeForEndPart()})}this.state.validate(),this.ui.updateAll()}handleConfirm(t){if(!this.isEnabled)return;this.state.commitPreview();let e=this.state.getFromValue(),a=this.state.getToValue(),i=e?o(e):"--:--",r=a?o(a):"--:--",s=this.state.getDuration();this.ui.updateInputValue(),this.emitter.emit("range:confirm",{from:i,to:r,duration:s})}reset(){this.state.reset()}destroy(){this.cleanupHandlers.forEach(t=>t()),this.cleanupHandlers=[],this.reset()}};var A={name:"range",factory:(n,t)=>new u(n,t)};0&&(module.exports={RangeManager,RangePlugin});
|
package/dist/plugins/range.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function p(n){if(!n||n==="--:--")return null;let t=n.match(/^(\d{1,2}):(\d{2})\s*(AM|PM)$/i);if(t)return{hour:t[1],minutes:t[2],type:t[3].toUpperCase()};let e=n.match(/^(\d{1,2}):(\d{2})$/);return e?{hour:e[1],minutes:e[2]}:null}function o(n){let t=n.minutes==="--"?"--":n.minutes.padStart(2,"0"),e=`${n.hour}:${t}`;return n.type?`${e} ${n.type}`:e}function f(n,t){if(!n)return 0;let e=parseInt(n.hour,10),a=parseInt(n.minutes,10);return t==="12h"&&n.type&&(n.type==="PM"&&e!==12&&(e+=12),n.type==="AM"&&e===12&&(e=0)),e*60+a}function g(n,t,e){if(!n||!t)return 0;let a=f(n,e),i=f(t,e);return i<=a&&(i+=1440),i-a}function d(n,t){return n?t==="12h"?!!(n.hour&&n.minutes&&n.type):!!(n.hour&&n.minutes):!1}function v(n){if(!n||!n.includes(" - "))return{from:null,to:null};let t=n.split(" - ").map(e=>e.trim());return t.length!==2||t[0]==="--:--"||t[1]==="--:--"?{from:null,to:null}:{from:p(t[0]),to:p(t[1])}}var m=class{activePart="from";fromValue=null;toValue=null;previewValue=null;clockType;minDuration;maxDuration;emitter;constructor(t,e,a,i){this.clockType=t,this.minDuration=e,this.maxDuration=a,this.emitter=i}getActivePart(){return this.activePart}getFromValue(){return this.fromValue}getToValue(){return this.toValue}getPreviewValue(){return this.previewValue}setFromValue(t){this.fromValue=t}setToValue(t){this.toValue=t}setPreviewValue(t){this.previewValue=t}isFromComplete(){return d(this.fromValue,this.clockType)}isToComplete(){return d(this.toValue,this.clockType)}canSwitchToEnd(){return this.isFromComplete()}canConfirm(){return this.isFromComplete()&&this.isToComplete()}setActivePart(t){if(t==="to"&&!this.canSwitchToEnd())return!1;let e=this.activePart!==t;return this.activePart=t,e&&(this.previewValue=null),e}getCurrentValue(){return this.previewValue?this.previewValue:this.activePart==="from"?this.fromValue:this.toValue}getSavedValue(){return this.activePart==="from"?this.fromValue:this.toValue}commitPreview(){this.previewValue&&(this.activePart==="from"?this.fromValue=this.previewValue:this.toValue=this.previewValue,this.previewValue=null)}getDuration(){return g(this.fromValue,this.toValue,this.clockType)}validate(){if(!this.fromValue||!this.toValue)return{valid:!0,duration:0};let t=this.getDuration(),e=!0;return this.minDuration!==void 0&&t<this.minDuration&&(e=!1),this.maxDuration!==void 0&&t>this.maxDuration&&(e=!1),this.emitter.emit("range:validation",{valid:e,duration:t,minDuration:this.minDuration,maxDuration:this.maxDuration}),{valid:e,duration:t}}getDisabledTimeForEndPart(){if(this.activePart==="from"||!this.fromValue||!this.isFromComplete())return null;let t=[],e=[],a=parseInt(this.fromValue.hour,10),i=parseInt(this.fromValue.minutes,10),r=this.fromValue.type;if(this.clockType==="24h"){for(let s=0;s<a;s++)t.push(s.toString().padStart(2,"0"));for(let s=0;s<i;s++)e.push(s.toString().padStart(2,"0"));return{hours:t,minutes:e}}for(let s=0;s<i;s++)e.push(s.toString().padStart(2,"0"));return{hours:t,minutes:e,fromType:r,fromHour:a}}reset(){this.activePart="from",this.fromValue=null,this.toValue=null,this.previewValue=null}};var h=class{core;state;constructor(t,e){this.core=t,this.state=e}updateTabs(){let t=this.core.getModalElement();if(!t)return;let e=t.querySelector(".tp-ui-range-tab.tp-ui-range-from"),a=t.querySelector(".tp-ui-range-tab.tp-ui-range-to"),i=this.state.getActivePart()==="from",r=this.state.isFromComplete();e?.classList.toggle("active",i),a?.classList.toggle("active",!i),a?.classList.toggle("disabled",!r),e?.setAttribute("aria-selected",String(i)),a?.setAttribute("aria-selected",String(!i)),a?.setAttribute("aria-disabled",String(!r)),e?.setAttribute("tabindex",i?"0":"-1"),a?.setAttribute("tabindex",i||!r?"-1":"0")}updateTimeDisplay(){let t=this.core.getModalElement();if(!t)return;let e=t.querySelector(".tp-ui-range-from-time"),a=t.querySelector(".tp-ui-range-to-time"),i=this.state.getActivePart(),r=this.state.getPreviewValue(),s=this.state.getFromValue(),l=this.state.getToValue(),c=i==="from"&&r?o(r):s?o(s):"--:--",V=i==="to"&&r?o(r):l?o(l):"--:--";e&&(e.textContent=c),a&&(a.textContent=V)}updateOkButton(){let t=this.core.getOkButton();if(!t)return;let e=this.state.canConfirm();t.classList.toggle("disabled",!e),t.setAttribute("aria-disabled",String(!e))}updateInputValue(){let t=this.core.getInput();if(!t)return;let e=this.state.getFromValue(),a=this.state.getToValue(),i=e?o(e):"--:--",r=a?o(a):"--:--";t.value=`${i} - ${r}`}syncClockToActivePart(){let t=this.state.getSavedValue(),e=this.core.getHour(),a=this.core.getMinutes();if(e&&(e.value=t?.hour??"12"),a&&(a.value=t?.minutes??"00"),this.core.options.clock.type==="12h"){let i=this.core.getAM(),r=this.core.getPM();t?.type==="AM"?(i?.classList.add("active"),r?.classList.remove("active")):t?.type==="PM"?(r?.classList.add("active"),i?.classList.remove("active")):(i?.classList.remove("active"),r?.classList.remove("active"))}a&&(a.blur(),a.classList.remove("active")),e&&e.click()}updateAll(){this.updateTabs(),this.updateTimeDisplay(),this.updateOkButton()
|
|
1
|
+
function p(n){if(!n||n==="--:--")return null;let t=n.match(/^(\d{1,2}):(\d{2})\s*(AM|PM)$/i);if(t)return{hour:t[1],minutes:t[2],type:t[3].toUpperCase()};let e=n.match(/^(\d{1,2}):(\d{2})$/);return e?{hour:e[1],minutes:e[2]}:null}function o(n){let t=n.minutes==="--"?"--":n.minutes.padStart(2,"0"),e=`${n.hour}:${t}`;return n.type?`${e} ${n.type}`:e}function f(n,t){if(!n)return 0;let e=parseInt(n.hour,10),a=parseInt(n.minutes,10);return t==="12h"&&n.type&&(n.type==="PM"&&e!==12&&(e+=12),n.type==="AM"&&e===12&&(e=0)),e*60+a}function g(n,t,e){if(!n||!t)return 0;let a=f(n,e),i=f(t,e);return i<=a&&(i+=1440),i-a}function d(n,t){return n?t==="12h"?!!(n.hour&&n.minutes&&n.type):!!(n.hour&&n.minutes):!1}function v(n){if(!n||!n.includes(" - "))return{from:null,to:null};let t=n.split(" - ").map(e=>e.trim());return t.length!==2||t[0]==="--:--"||t[1]==="--:--"?{from:null,to:null}:{from:p(t[0]),to:p(t[1])}}var m=class{activePart="from";fromValue=null;toValue=null;previewValue=null;clockType;minDuration;maxDuration;emitter;constructor(t,e,a,i){this.clockType=t,this.minDuration=e,this.maxDuration=a,this.emitter=i}getActivePart(){return this.activePart}getFromValue(){return this.fromValue}getToValue(){return this.toValue}getPreviewValue(){return this.previewValue}setFromValue(t){this.fromValue=t}setToValue(t){this.toValue=t}setPreviewValue(t){this.previewValue=t}isFromComplete(){return d(this.fromValue,this.clockType)}isToComplete(){return d(this.toValue,this.clockType)}canSwitchToEnd(){return this.isFromComplete()}canConfirm(){return this.isFromComplete()&&this.isToComplete()}setActivePart(t){if(t==="to"&&!this.canSwitchToEnd())return!1;let e=this.activePart!==t;return this.activePart=t,e&&(this.previewValue=null),e}getCurrentValue(){return this.previewValue?this.previewValue:this.activePart==="from"?this.fromValue:this.toValue}getSavedValue(){return this.activePart==="from"?this.fromValue:this.toValue}commitPreview(){this.previewValue&&(this.activePart==="from"?this.fromValue=this.previewValue:this.toValue=this.previewValue,this.previewValue=null)}getDuration(){return g(this.fromValue,this.toValue,this.clockType)}validate(){if(!this.fromValue||!this.toValue)return{valid:!0,duration:0};let t=this.getDuration(),e=!0;return this.minDuration!==void 0&&t<this.minDuration&&(e=!1),this.maxDuration!==void 0&&t>this.maxDuration&&(e=!1),this.emitter.emit("range:validation",{valid:e,duration:t,minDuration:this.minDuration,maxDuration:this.maxDuration}),{valid:e,duration:t}}getDisabledTimeForEndPart(){if(this.activePart==="from"||!this.fromValue||!this.isFromComplete())return null;let t=[],e=[],a=parseInt(this.fromValue.hour,10),i=parseInt(this.fromValue.minutes,10),r=this.fromValue.type;if(this.clockType==="24h"){for(let s=0;s<a;s++)t.push(s.toString().padStart(2,"0"));for(let s=0;s<i;s++)e.push(s.toString().padStart(2,"0"));return{hours:t,minutes:e}}for(let s=0;s<i;s++)e.push(s.toString().padStart(2,"0"));return{hours:t,minutes:e,fromType:r,fromHour:a}}reset(){this.activePart="from",this.fromValue=null,this.toValue=null,this.previewValue=null}};var h=class{core;state;constructor(t,e){this.core=t,this.state=e}updateTabs(){let t=this.core.getModalElement();if(!t)return;let e=t.querySelector(".tp-ui-range-tab.tp-ui-range-from"),a=t.querySelector(".tp-ui-range-tab.tp-ui-range-to"),i=this.state.getActivePart()==="from",r=this.state.isFromComplete();e?.classList.toggle("active",i),a?.classList.toggle("active",!i),a?.classList.toggle("disabled",!r),e?.setAttribute("aria-selected",String(i)),a?.setAttribute("aria-selected",String(!i)),a?.setAttribute("aria-disabled",String(!r)),e?.setAttribute("tabindex",i?"0":"-1"),a?.setAttribute("tabindex",i||!r?"-1":"0")}updateTimeDisplay(){let t=this.core.getModalElement();if(!t)return;let e=t.querySelector(".tp-ui-range-from-time"),a=t.querySelector(".tp-ui-range-to-time"),i=this.state.getActivePart(),r=this.state.getPreviewValue(),s=this.state.getFromValue(),l=this.state.getToValue(),c=i==="from"&&r?o(r):s?o(s):"--:--",V=i==="to"&&r?o(r):l?o(l):"--:--";e&&(e.textContent=c),a&&(a.textContent=V)}updateOkButton(){let t=this.core.getOkButton();if(!t)return;let e=this.state.canConfirm();t.classList.toggle("disabled",!e),t.setAttribute("aria-disabled",String(!e))}updateInputValue(){let t=this.core.getInput();if(!t)return;let e=this.state.getFromValue(),a=this.state.getToValue(),i=e?o(e):"--:--",r=a?o(a):"--:--";t.value=`${i} - ${r}`}syncClockToActivePart(){let t=this.state.getSavedValue(),e=this.core.getHour(),a=this.core.getMinutes();if(e&&(e.value=t?.hour??"12"),a&&(a.value=t?.minutes??"00"),this.core.options.clock.type==="12h"){let i=this.core.getAM(),r=this.core.getPM();t?.type==="AM"?(i?.classList.add("active"),r?.classList.remove("active")):t?.type==="PM"?(r?.classList.add("active"),i?.classList.remove("active")):(i?.classList.remove("active"),r?.classList.remove("active"))}a&&(a.blur(),a.classList.remove("active")),e&&e.click()}updateAll(){this.updateTabs(),this.updateTimeDisplay(),this.updateOkButton()}};var u=class{core;emitter;state;ui;cleanupHandlers=[];boundHandleMinuteCommit;boundHandleConfirm;boundHandleUpdate;boundHandleAmPm;constructor(t,e){this.core=t,this.emitter=e;let{range:a,clock:i}=t.options;this.state=new m(i.type,a?.minDuration,a?.maxDuration,e),this.ui=new h(t,this.state),this.boundHandleMinuteCommit=this.handleMinuteCommit.bind(this),this.boundHandleConfirm=this.handleConfirm.bind(this),this.boundHandleUpdate=this.handleUpdate.bind(this),this.boundHandleAmPm=this.handleAmPm.bind(this)}get isEnabled(){return this.core.options.range?.enabled===!0}init(){if(!this.isEnabled)return;let e=this.core.getInput()?.value||"",{from:a,to:i}=v(e);this.state.setFromValue(a),this.state.setToValue(i),this.state.setActivePart("from"),this.state.setPreviewValue(null),this.bindEvents(),this.ui.syncClockToActivePart(),this.ui.updateAll()}getActivePart(){return this.state.getActivePart()}setActivePart(t){if(!this.isEnabled)return;this.state.setActivePart(t)&&this.emitter.emit("range:switch",{active:t,disabledTime:this.state.getDisabledTimeForEndPart()}),this.ui.syncClockToActivePart(),this.ui.updateAll()}getFromValue(){return this.state.getFromValue()}getToValue(){return this.state.getToValue()}getDisabledTimeForEndPart(){return this.isEnabled?this.state.getDisabledTimeForEndPart():null}getDuration(){return this.state.getDuration()}validateRange(){return this.isEnabled?this.state.validate():{valid:!0,duration:0}}canConfirm(){return this.isEnabled?this.state.canConfirm():!0}getFormattedRange(){let t=this.state.getFromValue(),e=this.state.getToValue();return!t||!e?null:{from:o(t),to:o(e)}}bindEvents(){let t=this.core.getModalElement();if(!t)return;let e=t.querySelector(".tp-ui-range-tab.tp-ui-range-from"),a=t.querySelector(".tp-ui-range-tab.tp-ui-range-to");if(e){let i=()=>this.setActivePart("from");e.addEventListener("click",i),this.cleanupHandlers.push(()=>e.removeEventListener("click",i))}if(a){let i=()=>this.setActivePart("to");a.addEventListener("click",i),this.cleanupHandlers.push(()=>a.removeEventListener("click",i))}this.emitter.on("update",this.boundHandleUpdate),this.cleanupHandlers.push(()=>this.emitter.off("update",this.boundHandleUpdate)),this.emitter.on("range:minute:commit",this.boundHandleMinuteCommit),this.cleanupHandlers.push(()=>this.emitter.off("range:minute:commit",this.boundHandleMinuteCommit)),this.emitter.on("confirm",this.boundHandleConfirm),this.cleanupHandlers.push(()=>this.emitter.off("confirm",this.boundHandleConfirm)),this.emitter.on("select:am",this.boundHandleAmPm),this.cleanupHandlers.push(()=>this.emitter.off("select:am",this.boundHandleAmPm)),this.emitter.on("select:pm",this.boundHandleAmPm),this.cleanupHandlers.push(()=>this.emitter.off("select:pm",this.boundHandleAmPm))}handleUpdate(){if(!this.isEnabled)return;let t=this.core.getHour(),e=this.core.getMinutes(),a=this.core.getActiveTypeMode(),i=t?.value??"12",r=this.state.getSavedValue(),l=r?.minutes&&r.minutes!=="--"?e?.value??"--":"--",c=this.core.options.clock.type==="12h"?a?.textContent??void 0:void 0;this.state.setPreviewValue({hour:i,minutes:l,type:c}),this.ui.updateAll()}handleMinuteCommit(t){if(!this.isEnabled)return;let e={hour:t.hour,minutes:t.minutes,type:t.type??void 0};this.state.getActivePart()==="from"?(this.state.setFromValue(e),this.state.setPreviewValue(null),this.state.isFromComplete()&&(this.state.setActivePart("to"),this.emitter.emit("range:switch",{active:"to",disabledTime:this.state.getDisabledTimeForEndPart()}),this.ui.syncClockToActivePart())):(this.state.setToValue(e),this.state.setPreviewValue(null)),this.state.validate(),this.ui.updateAll()}handleAmPm(){if(!this.isEnabled||this.core.options.clock.type!=="12h")return;let e=this.core.getActiveTypeMode()?.textContent;if(!e)return;if(this.state.getActivePart()==="from"){let i=this.state.getFromValue();i&&(this.state.setFromValue({...i,type:e}),this.state.isFromComplete()&&(this.state.setActivePart("to"),this.state.setPreviewValue(null),this.emitter.emit("range:switch",{active:"to",disabledTime:this.state.getDisabledTimeForEndPart()}),this.ui.syncClockToActivePart()))}else{let i=this.state.getToValue();i&&this.state.setToValue({...i,type:e}),this.emitter.emit("range:switch",{active:"to",disabledTime:this.state.getDisabledTimeForEndPart()})}this.state.validate(),this.ui.updateAll()}handleConfirm(t){if(!this.isEnabled)return;this.state.commitPreview();let e=this.state.getFromValue(),a=this.state.getToValue(),i=e?o(e):"--:--",r=a?o(a):"--:--",s=this.state.getDuration();this.ui.updateInputValue(),this.emitter.emit("range:confirm",{from:i,to:r,duration:s})}reset(){this.state.reset()}destroy(){this.cleanupHandlers.forEach(t=>t()),this.cleanupHandlers=[],this.reset()}};var k={name:"range",factory:(n,t)=>new u(n,t)};export{u as RangeManager,k as RangePlugin};
|