@kupola/kupola 1.6.1 → 1.6.2
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/kupola.cjs.js +1 -1
- package/dist/kupola.cjs.js.map +1 -1
- package/dist/kupola.esm.js +3 -3
- package/dist/kupola.esm.js.map +1 -1
- package/dist/kupola.umd.js +1 -1
- package/dist/kupola.umd.js.map +1 -1
- package/js/dropdown.js +2 -2
- package/js/select.js +4 -4
- package/package.json +1 -1
package/dist/kupola.cjs.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
<div style="font-weight: bold; margin-bottom: 8px;">Component Error</div>
|
|
4
4
|
<div style="font-size: 12px; white-space: pre-wrap;">${t.message}</div>
|
|
5
5
|
</div>
|
|
6
|
-
`}}_bindLifecycleHooks(){if(this._hooksBound)return;const t={beforeMount:"beforeMount",render:["mount","update"],afterMount:"afterMount",updated:"afterUpdate",beforeUnmount:"beforeUnmount",afterUnmount:"afterUnmount",renderError:"errorBoundary"};let e=Object.getPrototypeOf(this);const s=new Set;for(;e&&e.constructor!==Object&&e.constructor!==J;){for(const[n,r]of Object.entries(t))s.has(n)||e.hasOwnProperty(n)&&(Array.isArray(r)?r.forEach(a=>{n==="render"&&this.lifecycle.on(a,()=>this.render?.())}):n==="renderError"?this.lifecycle.on(r,a=>(this.renderError(a.error),"handled")):this.lifecycle.on(r,()=>this[n]?.()),s.add(n));e=Object.getPrototypeOf(e)}this._hooksBound=!0}async unmount(){if(!(!this.isMounted||this.isDestroyed))try{this.setupContext?._executeUnmounted(),await this.lifecycle.unmount(),this.isMounted=!1,this.isDestroyed=!0,await this.lifecycle.destroy()}catch(t){console.error(`[KupolaComponent] Error unmounting component "${this.constructor.name}":`,t),this.lifecycle&&typeof this.lifecycle._handleError=="function"&&await this.lifecycle._handleError({phase:"unmount",hook:"component",error:t,args:[]}),this.isMounted=!1,this.isDestroyed=!0}}beforeMount(){}afterMount(){}beforeUnmount(){}afterUnmount(){}render(){}renderError(t){}updated(){}setup(){}}function ut(i,t){Object.keys(t).forEach(e=>{if(e!=="constructor")if(typeof t[e]=="function"){const s=i.prototype[e];s?i.prototype[e]=function(...n){return t[e].apply(this,n),s.apply(this,n)}:i.prototype[e]=t[e]}else i.prototype[e]=t[e]})}class Ve{constructor(){this.components=new Map,this.lazyComponents=new Map,this.loadedComponents=new Map,this.instances=new Map,this.observer=null,this.mixins=new Map,this.loadingPromises=new Map}register(t,e){if(!(e.prototype instanceof J))throw new Error(`Component ${t} must extend KupolaComponent`);this.components.set(t,e)}registerLazy(t,e){this.lazyComponents.set(t,e)}unregister(t){this.components.delete(t),this.lazyComponents.delete(t),this.loadedComponents.delete(t),this.loadingPromises.delete(t)}get(t){return this.components.get(t)||this.loadedComponents.get(t)}async getAsync(t){const e=this.components.get(t)||this.loadedComponents.get(t);if(e)return e;if(this.loadingPromises.has(t))return this.loadingPromises.get(t);const s=this.lazyComponents.get(t);if(!s)throw new Error(`Component ${t} not found`);const n=(async()=>{try{const r=await s(),a=r.default||r;if(!(a.prototype instanceof J))throw new Error(`Component ${t} must extend KupolaComponent`);return this.loadedComponents.set(t,a),a}catch(r){throw this.loadingPromises.delete(t),r}})();return this.loadingPromises.set(t,n),n}defineMixin(t,e){this.mixins.set(t,e)}useMixin(t,...e){e.forEach(s=>{const n=this.mixins.get(s);n&&ut(t,n)})}async bootstrap(t=document){await this._upgradeElements(t),this._startObserver(t)}async _upgradeElements(t){const e=t.querySelectorAll("[data-component]"),s=[];e.forEach(n=>{s.push(this._upgradeElement(n))}),await Promise.all(s)}async _upgradeElement(t){if(!(t.__kupolaInstance||t.__kupolaUpgrading)){t.__kupolaUpgrading=!0;try{const e=t.getAttribute("data-component");if(e){const o=E.get(e);if(o)try{await o(t);return}catch(l){console.warn(`[KupolaComponentRegistry] Initializer for "${e}" failed, trying component class:`,l)}}let s=this.components.get(e);if(!s){try{s=await this.getAsync(e)}catch(o){console.error(`Failed to load component ${e}:`,o);return}if(!t.isConnected)return}const n=t.getAttribute("data-mixins"),r=s;n&&n.split(",").forEach(o=>{const l=this.mixins.get(o.trim());l&&ut(r,l)});const a=new r(t);t.__kupolaInstance=a,this.instances.set(t,a),a.mount()}finally{t.__kupolaUpgrading=!1}}}_startObserver(t){this.observer||(this.observer=new MutationObserver(e=>{e.forEach(s=>{s.addedNodes.forEach(n=>{if(n.nodeType===Node.ELEMENT_NODE){n.hasAttribute("data-component")&&this._upgradeElement(n).catch(a=>console.error(a)),this._upgradeElements(n).catch(a=>console.error(a)),E.initialize(n).catch(()=>{});const r=E._buildSelector();r&&n.querySelectorAll?.(r).forEach(a=>{E.initialize(a).catch(()=>{})})}}),s.removedNodes.forEach(n=>{if(n.nodeType===Node.ELEMENT_NODE){const r=this.instances.get(n);r&&(r.unmount(),this.instances.delete(n)),n.querySelectorAll("[data-component]").forEach(a=>{const o=this.instances.get(a);o&&(o.unmount(),this.instances.delete(a))}),E.cleanup(n),n.querySelectorAll?.("*").forEach(a=>{E.cleanup(a)})}})})}),this.observer.observe(t,{childList:!0,subtree:!0}))}destroy(){this.observer&&(this.observer.disconnect(),this.observer=null),this.instances.forEach(t=>{t.unmount()}),this.instances.clear(),this.components.clear(),this.mixins.clear()}}exports.kupolaRegistry=null;typeof window<"u"&&(exports.kupolaRegistry=new Ve);function $a(){if(Z().xssProtection&&typeof document<"u"){let t=document.querySelector('meta[http-equiv="X-XSS-Protection"]');t||(t=document.createElement("meta"),t.setAttribute("http-equiv","X-XSS-Protection"),t.setAttribute("content","1; mode=block"),document.head.insertBefore(t,document.head.firstChild)),t=document.querySelector('meta[http-equiv="X-Content-Type-Options"]'),t||(t=document.createElement("meta"),t.setAttribute("http-equiv","X-Content-Type-Options"),t.setAttribute("content","nosniff"),document.head.insertBefore(t,document.head.firstChild)),t=document.querySelector('meta[http-equiv="X-Frame-Options"]'),t||(t=document.createElement("meta"),t.setAttribute("http-equiv","X-Frame-Options"),t.setAttribute("content","SAMEORIGIN"),document.head.insertBefore(t,document.head.firstChild))}}async function pt(){if(typeof window<"u"){$a();const i=ot();q.loadPersisted(),q.bind(),Ne(),i.components?.autoInit!==!1&&(await E.initializeAll(),exports.kupolaRegistry&&await exports.kupolaRegistry.bootstrap())}}typeof document<"u"&&document.readyState==="loading"?document.addEventListener("DOMContentLoaded",pt):typeof window<"u"&&setTimeout(pt,0);function Ba(i,t){exports.kupolaRegistry&&exports.kupolaRegistry.register(i,t)}function qa(i,t){exports.kupolaRegistry&&exports.kupolaRegistry.registerLazy(i,t)}function Fa(i){return exports.kupolaRegistry?exports.kupolaRegistry.bootstrap(i):Promise.resolve()}function Oa(i,t){exports.kupolaRegistry&&exports.kupolaRegistry.defineMixin(i,t)}function Na(i,...t){exports.kupolaRegistry&&exports.kupolaRegistry.useMixin(i,...t)}function Ra(i,t){if(!t||typeof t!="object")throw new Error(`defineComponent("${i}"): options must be an object`);t.componentClass?exports.kupolaRegistry&&exports.kupolaRegistry.register(i,t.componentClass):t.lazy&&exports.kupolaRegistry&&exports.kupolaRegistry.registerLazy(i,t.lazy),t.init?E.register(i,t.init,t.cleanup||null,{dataAttribute:t.dataAttribute,cssClass:t.cssClass}):(t.dataAttribute||t.cssClass)&&E.register(i,()=>{},null,{dataAttribute:t.dataAttribute,cssClass:t.cssClass})}class _t{constructor(t={}){const e=ot();this.locales=t.locales||{},this.currentLocale=t.defaultLocale||e.i18n?.locale||"zh-CN",this.fallbackLocale=t.fallbackLocale||e.i18n?.fallbackLocale||"en-US",this.delimiter=t.delimiter||".",this.missingHandler=t.missingHandler||(s=>(console.warn(`Missing translation: ${s}`),s)),this._initFromDOM()}_initFromDOM(){document.querySelectorAll('script[type="application/json"][data-kupola-i18n]').forEach(s=>{const n=s.dataset.kupolaI18n;if(n)try{const r=JSON.parse(s.textContent);this.addLocale(n,r)}catch(r){console.error("Failed to parse i18n data:",r)}});const e=document.documentElement.lang;e&&this.locales[e]&&(this.currentLocale=e)}addLocale(t,e){this.locales[t]||(this.locales[t]={}),this._mergeDeep(this.locales[t],e)}_mergeDeep(t,e){for(const s of Object.keys(e))e[s]instanceof Object&&s in t?this._mergeDeep(t[s],e[s]):t[s]=e[s]}setLocale(t){return this.locales[t]?(this.currentLocale=t,document.documentElement.lang=t,this._emitChange(),!0):!1}getLocale(){return this.currentLocale}t(t,e={}){let s=this._getTranslation(t,this.currentLocale);return s||(s=this._getTranslation(t,this.fallbackLocale)),s?this._interpolate(s,e):this.missingHandler(t)}_getTranslation(t,e){if(!this.locales[e])return null;const s=t.split(this.delimiter);let n=this.locales[e];for(const r of s)if(n&&typeof n=="object"&&r in n)n=n[r];else return null;return typeof n=="string"?n:null}_interpolate(t,e){return t.replace(/\{(\w+)\}/g,(s,n)=>e[n]!==void 0?e[n]:s)}n(t,e,s={}){const n=this.t(t,{...s,count:e});if(!n)return n;const r=n.split("|");return r.length===1?n.replace("{count}",e):r.length===2?e===1?r[0]:r[1]:r.length>=3?e===0?r[0]:e===1?r[1]:r[2]:n}_emitChange(){const t=new CustomEvent("kupola:i18n:change",{detail:{locale:this.currentLocale},bubbles:!0});document.dispatchEvent(t)}async loadLocale(t,e){try{const n=await(await fetch(e)).json();return this.addLocale(t,n),!0}catch(s){return console.error("Failed to load locale:",s),!1}}getAvailableLocales(){return Object.keys(this.locales)}hasLocale(t){return!!this.locales[t]}formatDate(t,e={}){const s=e.locale||this.currentLocale,n=typeof t=="string"?new Date(t):t;return new Intl.DateTimeFormat(s,e).format(n)}formatNumber(t,e={}){const s=e.locale||this.currentLocale;return new Intl.NumberFormat(s,e).format(t)}formatCurrency(t,e,s={}){const n=s.locale||this.currentLocale;return new Intl.NumberFormat(n,{style:"currency",currency:e,...s}).format(t)}formatRelativeTime(t,e,s={}){const n=s.locale||this.currentLocale;return new Intl.RelativeTimeFormat(n,s).format(t,e)}}const O=new _t;function Va(i){return new _t(i)}function Ka(i,t={}){return O.t(i,t)}function Wa(i,t,e={}){return O.n(i,t,e)}function Ua(i){return O.setLocale(i)}function Ya(){return O.getLocale()}function Xa(i,t={}){return O.formatDate(i,t)}function ja(i,t={}){return O.formatNumber(i,t)}function Ja(i,t,e={}){return O.formatCurrency(i,t,e)}class Ke{constructor(){this._listeners=new Map,this._scopeListeners=new Map}on(t,e,s,n={}){const{scope:r=null,once:a=!1,passive:o=!1,capture:l=!1}=n,c=this._generateId(),h={id:c,target:t,eventName:e,handler:s,scope:r,once:a,wrappedHandler:null};h.wrappedHandler=u=>{a&&this.offById(c),s.call(t,u)};const d=this._getEventKey(t,e);return this._listeners.has(d)||this._listeners.set(d,[]),this._listeners.get(d).push(h),r&&(this._scopeListeners.has(r)||this._scopeListeners.set(r,[]),this._scopeListeners.get(r).push(c)),t.addEventListener(e,h.wrappedHandler,{passive:o,capture:l}),{unsubscribe:()=>this.offById(c)}}once(t,e,s,n={}){return this.on(t,e,s,{...n,once:!0})}off(t,e,s){const n=this._getEventKey(t,e);if(!this._listeners.has(n))return;const r=this._listeners.get(n),a=r.filter(o=>o.handler!==s);r.forEach(o=>{o.handler===s&&(t.removeEventListener(e,o.wrappedHandler),this._removeFromScope(o))}),a.length===0?this._listeners.delete(n):this._listeners.set(n,a)}offById(t){for(const[e,s]of this._listeners){const n=s.findIndex(r=>r.id===t);if(n!==-1){const r=s[n];return r.target.removeEventListener(r.eventName,r.wrappedHandler),s.splice(n,1),s.length===0&&this._listeners.delete(e),this._removeFromScope(r),!0}}return!1}offByScope(t){if(!this._scopeListeners.has(t))return;this._scopeListeners.get(t).forEach(s=>{this.offById(s)}),this._scopeListeners.delete(t)}offAll(t,e=null){if(e){const s=this._getEventKey(t,e);if(!this._listeners.has(s))return;this._listeners.get(s).forEach(r=>{t.removeEventListener(e,r.wrappedHandler),this._removeFromScope(r)}),this._listeners.delete(s)}else for(const[s,n]of this._listeners){const[r]=s.split(":");this._getTargetId(t)===r&&(n.forEach(a=>{t.removeEventListener(a.eventName,a.wrappedHandler),this._removeFromScope(a)}),this._listeners.delete(s))}}emit(t,e,s={}){const n=new CustomEvent(e,{detail:s,bubbles:!0,cancelable:!0});return t.dispatchEvent(n),n}emitGlobal(t,e={}){return this.emit(document,t,e)}emitToScope(t,e,s={}){if(!this._scopeListeners.has(t))return;const n=this._scopeListeners.get(t),r=new Set;for(const[a,o]of this._listeners)o.forEach(l=>{n.includes(l.id)&&r.add(l.target)});r.forEach(a=>{this.emit(a,e,s)})}getListenerCount(t,e=null){if(e){const r=this._getEventKey(t,e);return this._listeners.has(r)?this._listeners.get(r).length:0}let s=0;const n=this._getTargetId(t);for(const[r,a]of this._listeners){const[o]=r.split(":");o===n&&(s+=a.length)}return s}getScopeListenerCount(t){return this._scopeListeners.has(t)?this._scopeListeners.get(t).length:0}hasListeners(t,e=null){return this.getListenerCount(t,e)>0}_getEventKey(t,e){return`${this._getTargetId(t)}:${e}`}_getTargetId(t){return t===document?"document":t===window?"window":t===document.body?"body":(t._kupolaId||(t._kupolaId=this._generateId()),t._kupolaId)}_generateId(){return`ge-${Math.random().toString(36).substr(2,9)}-${Date.now()}`}_removeFromScope(t){if(!t.scope||!this._scopeListeners.has(t.scope))return;const e=this._scopeListeners.get(t.scope),s=e.indexOf(t.id);s!==-1&&(e.splice(s,1),e.length===0&&this._scopeListeners.delete(t.scope))}destroy(){for(const[t,e]of this._listeners)e.forEach(s=>{s.target.removeEventListener(s.eventName,s.wrappedHandler)});this._listeners.clear(),this._scopeListeners.clear()}}const H=new Ke;function Za(i,t,e,s){return H.on(i,t,e,s)}function Ga(i,t,e,s){return H.once(i,t,e,s)}function Qa(i,t,e){H.off(i,t,e)}function to(i,t,e){return H.emit(i,t,e)}function eo(i,t){return H.emitGlobal(i,t)}function so(i){H.offByScope(i)}function io(i,t){H.offAll(i,t)}function no(i,t){return H.getListenerCount(i,t)}class We{constructor(t,e={}){this.element=t,this.trigger=t.querySelector(".ds-dropdown__trigger"),this.menu=t.querySelector(".ds-dropdown__menu"),this.triggerText=this.trigger?this.trigger.querySelector("span"):null,this.scope=`dropdown-${Math.random().toString(36).substr(2,9)}`;const s=U();this.triggerMode=e.trigger||t.getAttribute("data-dropdown-trigger")||"click",this.hoverDelay=e.hoverDelay||parseInt(t.getAttribute("data-dropdown-hover-delay"))||150,this.disabled=e.disabled||t.hasAttribute("data-dropdown-disabled"),this.keyboardNav=e.keyboardNav!==!1,this.autoPosition=e.autoPosition!==!1,this.closeOnClick=e.closeOnClick!==void 0?e.closeOnClick:s.dropdown?.closeOnClick!==void 0?s.dropdown.closeOnClick:!0,this.appendToBody=e.appendToBody!==!1,this.onSelect=e.onSelect||null,this.onShow=e.onShow||null,this.onHide=e.onHide||null,this.isOpen=!1,this.focusIndex=-1,this._hoverTimer=null,this._hoverLeaveTimer=null,this._originalParent=null,this._originalPosition=null,this._triggerClickHandler=null,this._documentClickHandler=null,this._documentClickListener=null,this._itemClickHandler=null,this._keydownHandler=null,this._mouseenterHandler=null,this._mouseleaveHandler=null,this._triggerMouseenterHandler=null,this._triggerMouseleaveHandler=null,this._triggerKeydownHandler=null}init(){!this.trigger||!this.menu||this.element.__kupolaInitialized||(this._itemClickHandler=t=>{t.stopPropagation();const e=t.currentTarget;e.classList.contains("is-disabled")||e.classList.contains("ds-dropdown__divider")||(this.menu.querySelectorAll(".ds-dropdown__item").forEach(s=>s.classList.remove("is-selected")),e.classList.add("is-selected"),this.triggerText&&!e.hasAttribute("data-no-update-trigger")&&(this.triggerText.textContent=e.textContent.trim()),this.element.setAttribute("data-value",e.getAttribute("data-value")||""),this.onSelect&&this.onSelect({item:e,value:e.getAttribute("data-value"),text:e.textContent.trim()}),this.closeOnClick&&(this.hideMenu(),this.trigger.focus()))},this._bindMenuItems(),this._triggerClickHandler=t=>{t.stopPropagation(),!this.disabled&&this.toggleMenu()},this._triggerMouseenterHandler=()=>{this.disabled||this.triggerMode!=="hover"||(clearTimeout(this._hoverLeaveTimer),this._hoverTimer=setTimeout(()=>this.showMenu(),this.hoverDelay))},this._triggerMouseleaveHandler=()=>{this.triggerMode==="hover"&&(clearTimeout(this._hoverTimer),this._hoverLeaveTimer=setTimeout(()=>this.hideMenu(),this.hoverDelay))},this._mouseenterHandler=()=>{this.disabled||this.triggerMode!=="hover"||clearTimeout(this._hoverLeaveTimer)},this._mouseleaveHandler=()=>{this.triggerMode==="hover"&&(this._hoverLeaveTimer=setTimeout(()=>this.hideMenu(),this.hoverDelay))},this._keydownHandler=t=>{if(!this.isOpen||this.disabled)return;const e=this._getNavigableItems();if(e.length)switch(t.key){case"ArrowDown":t.preventDefault(),this.focusIndex=Math.min(this.focusIndex+1,e.length-1),this._focusItem(e);break;case"ArrowUp":t.preventDefault(),this.focusIndex=Math.max(this.focusIndex-1,0),this._focusItem(e);break;case"Enter":case" ":t.preventDefault(),this.focusIndex>=0&&e[this.focusIndex]&&e[this.focusIndex].click();break;case"Escape":t.preventDefault(),this.hideMenu(),this.trigger.focus();break;case"Home":t.preventDefault(),this.focusIndex=0,this._focusItem(e);break;case"End":t.preventDefault(),this.focusIndex=e.length-1,this._focusItem(e);break}},this.triggerMode==="hover"?(this.trigger.addEventListener("mouseenter",this._triggerMouseenterHandler),this.trigger.addEventListener("mouseleave",this._triggerMouseleaveHandler),this.menu.addEventListener("mouseenter",this._mouseenterHandler),this.menu.addEventListener("mouseleave",this._mouseleaveHandler)):this.trigger.addEventListener("click",this._triggerClickHandler),this._triggerKeydownHandler=t=>{this.disabled||(t.key==="Enter"||t.key===" "||t.key==="ArrowDown")&&(t.preventDefault(),this.showMenu())},this.trigger.addEventListener("keydown",this._triggerKeydownHandler),document.addEventListener("keydown",this._keydownHandler),this._documentClickHandler=t=>{!this.element.contains(t.target)&&!this.menu.contains(t.target)&&this.hideMenu()},this._documentClickListener=H.on(document,"click",this._documentClickHandler,{scope:this.scope}),this.menu.style.display="none",this.element.__kupolaInitialized=!0)}_bindMenuItems(){this.menu.querySelectorAll(".ds-dropdown__item").forEach(t=>{t.addEventListener("click",this._itemClickHandler),t._dropdownItemClickHandler=this._itemClickHandler})}_getNavigableItems(){return Array.from(this.menu.querySelectorAll(".ds-dropdown__item")).filter(t=>!t.classList.contains("is-disabled")&&!t.classList.contains("ds-dropdown__divider"))}_focusItem(t){t.forEach(e=>e.classList.remove("is-focused")),t[this.focusIndex]&&(t[this.focusIndex].classList.add("is-focused"),t[this.focusIndex].scrollIntoView({block:"nearest"}))}_calculatePosition(){if(!this.autoPosition)return;const t=this.element.getBoundingClientRect(),e=this.menu.getBoundingClientRect(),s=window.innerHeight,n=window.innerWidth;if(this.menu.classList.remove("ds-dropdown--top","ds-dropdown--right","ds-dropdown--dropup"),this.appendToBody){this.menu.style.width=`${Math.max(t.width,e.width)}px`;const r=s-t.bottom,a=t.top;r<e.height&&a>r?(this.menu.style.top=`${t.top-e.height-4}px`,this.menu.style.bottom="auto"):(this.menu.style.top=`${t.bottom+4}px`,this.menu.style.bottom="auto"),t.left+e.width>n?(this.menu.style.left=`${t.right-Math.max(t.width,e.width)}px`,this.menu.style.right="auto"):(this.menu.style.left=`${t.left}px`,this.menu.style.right="auto")}else{const r=s-t.bottom,a=t.top;r<e.height&&a>r?(this.menu.classList.add("ds-dropdown--dropup"),this.menu.style.top="auto",this.menu.style.bottom="100%",this.menu.style.marginBottom="4px"):(this.menu.style.top="100%",this.menu.style.bottom="auto",this.menu.style.marginBottom="0"),t.left+e.width>n?(this.menu.style.left="auto",this.menu.style.right="0"):(this.menu.style.left="0",this.menu.style.right="auto")}}showMenu(){this.disabled||this.isOpen||(this.isOpen=!0,this.focusIndex=-1,this.element.classList.add("is-open"),this.appendToBody&&(this._appendMenuToBody(),this._addScrollListener()),this.menu.style.display="block",this._calculatePosition(),this.onShow&&this.onShow(),this.element.dispatchEvent(new CustomEvent("kupola:dropdown-show",{bubbles:!0})))}hideMenu(){this.isOpen&&(this.isOpen=!1,this.menu.style.display="none",this.element.classList.remove("is-open"),this.appendToBody&&(this._restoreMenuFromBody(),this._removeScrollListener()),this.menu.querySelectorAll(".ds-dropdown__item").forEach(t=>t.classList.remove("is-focused")),this.onHide&&this.onHide(),this.element.dispatchEvent(new CustomEvent("kupola:dropdown-hide",{bubbles:!0})))}_appendMenuToBody(){if(!this.menu)return;this._originalParent=this.menu.parentNode,this._originalPosition=this.menu.style.position,this._originalTop=this.menu.style.top,this._originalLeft=this.menu.style.left,this._originalRight=this.menu.style.right,this._originalBottom=this.menu.style.bottom,this._originalMarginBottom=this.menu.style.marginBottom,this._originalWidth=this.menu.style.width,this._originalTransform=this.menu.style.transform,this._originalZIndex=this.menu.style.zIndex;const t=Y().dropdown;this.menu.style.position="fixed",this.menu.style.zIndex=t,this.menu.style.transform="translateZ(0)",document.body.appendChild(this.menu)}_restoreMenuFromBody(){!this.menu||!this._originalParent||(this._originalParent.appendChild(this.menu),this.menu.style.position=this._originalPosition||"",this.menu.style.top=this._originalTop||"",this.menu.style.left=this._originalLeft||"",this.menu.style.right=this._originalRight||"",this.menu.style.bottom=this._originalBottom||"",this.menu.style.marginBottom=this._originalMarginBottom||"",this.menu.style.width=this._originalWidth||"",this.menu.style.zIndex=this._originalZIndex||"",this.menu.style.transform=this._originalTransform||"",this._originalParent=null)}_addScrollListener(){this._scrollHandler=()=>{this.hideMenu()},window.addEventListener("scroll",this._scrollHandler,!0)}_removeScrollListener(){this._scrollHandler&&(window.removeEventListener("scroll",this._scrollHandler,!0),this._scrollHandler=null)}toggleMenu(){this.isOpen?this.hideMenu():this.showMenu()}enable(){this.disabled=!1,this.element.removeAttribute("data-dropdown-disabled")}disable(){this.disabled=!0,this.element.setAttribute("data-dropdown-disabled",""),this.hideMenu()}setItems(t){this.menu.querySelectorAll(".ds-dropdown__item").forEach(e=>{e._dropdownItemClickHandler&&e.removeEventListener("click",e._dropdownItemClickHandler)}),this.menu.innerHTML="",t.forEach(e=>{if(e.type==="divider"){const s=document.createElement("div");s.className="ds-dropdown__divider",this.menu.appendChild(s)}else{const s=document.createElement("div");s.className="ds-dropdown__item"+(e.disabled?" is-disabled":"")+(e.active?" is-selected":""),s.textContent=e.text||e.label||"",e.value!==void 0&&s.setAttribute("data-value",e.value),e.icon&&(s.innerHTML=e.icon+s.innerHTML),e.disabled&&s.classList.add("is-disabled"),this.menu.appendChild(s)}}),this._bindMenuItems()}destroy(){this.element.__kupolaInitialized&&(clearTimeout(this._hoverTimer),clearTimeout(this._hoverLeaveTimer),this.trigger&&(this._triggerClickHandler&&this.trigger.removeEventListener("click",this._triggerClickHandler),this._triggerMouseenterHandler&&this.trigger.removeEventListener("mouseenter",this._triggerMouseenterHandler),this._triggerMouseleaveHandler&&this.trigger.removeEventListener("mouseleave",this._triggerMouseleaveHandler),this._triggerKeydownHandler&&this.trigger.removeEventListener("keydown",this._triggerKeydownHandler)),this.menu&&(this.menu.querySelectorAll(".ds-dropdown__item").forEach(t=>{t._dropdownItemClickHandler&&t.removeEventListener("click",t._dropdownItemClickHandler)}),this._mouseenterHandler&&this.menu.removeEventListener("mouseenter",this._mouseenterHandler),this._mouseleaveHandler&&this.menu.removeEventListener("mouseleave",this._mouseleaveHandler)),this._keydownHandler&&document.removeEventListener("keydown",this._keydownHandler),this._documentClickListener&&this._documentClickListener.unsubscribe?this._documentClickListener.unsubscribe():this._documentClickHandler&&document.removeEventListener("click",this._documentClickHandler),this.appendToBody&&this._originalParent&&this._restoreMenuFromBody(),this._documentClickHandler=null,this._documentClickListener=null,this._triggerClickHandler=null,this._itemClickHandler=null,this._keydownHandler=null,this._mouseenterHandler=null,this._mouseleaveHandler=null,this._triggerMouseenterHandler=null,this._triggerMouseleaveHandler=null,this._triggerKeydownHandler=null,this.element.__kupolaInitialized=!1)}}function yt(i,t){const e=new We(i,t);e.init(),i._kupolaDropdown=e}function ro(i=document){i.querySelectorAll(".ds-dropdown").forEach(t=>{yt(t)})}function vt(i){i._kupolaDropdown&&(i._kupolaDropdown.destroy(),i._kupolaDropdown=null)}function ao(){document.querySelectorAll(".ds-dropdown").forEach(i=>{vt(i)})}E.register("dropdown",yt,vt);class Ue{constructor(t,e={}){this.element=t,this.trigger=t.querySelector(".ds-select__trigger"),this.valueEl=t.querySelector(".ds-select__value")||t.querySelector(".ds-select__trigger span"),this.optionsEl=t.querySelector(".ds-select__options")||t.querySelector(".ds-select__menu"),this.nativeSelect=t.querySelector("select"),this.icon=t.querySelector(".ds-select__icon"),this.scope=`select-${Math.random().toString(36).substr(2,9)}`,this.multiple=e.multiple||t.hasAttribute("data-select-multiple"),this.searchable=e.searchable||t.hasAttribute("data-select-search"),this.clearable=e.clearable||t.hasAttribute("data-select-clear"),this.placeholder=e.placeholder||t.getAttribute("data-select-placeholder")||"",this.disabled=e.disabled||t.hasAttribute("data-select-disabled"),this.maxSelection=e.maxSelection||parseInt(t.getAttribute("data-select-max"))||1/0,this.remoteMethod=e.remoteMethod||null,this.onChange=e.onChange||null,this.appendToBody=e.appendToBody!==!1,this.isOpen=!1,this.selectedValues=new Set,this.allOptions=[],this.filteredOptions=[],this.focusIndex=-1,this.searchInput=null,this.clearBtn=null,this.tagsWrap=null,this._originalParent=null,this._originalPosition=null,this._triggerClickHandler=null,this._documentClickHandler=null,this._documentClickListener=null,this._optionClickHandler=null,this._keydownHandler=null}init(){!this.trigger||!this.optionsEl||this.element.__kupolaInitialized||(this._collectOptions(),this.searchable&&this._createSearchInput(),this.clearable&&this._createClearButton(),this.multiple&&this._createTagsWrap(),this.placeholder&&this.valueEl&&(this.valueEl.setAttribute("data-placeholder",this.placeholder),this.selectedValues.size||(this.valueEl.classList.add("ds-select__value--placeholder"),this.valueEl.textContent=this.placeholder)),this._optionClickHandler=t=>{t.stopPropagation();const e=t.currentTarget;if(e.classList.contains("is-disabled"))return;const s=e.getAttribute("data-value");this.multiple?this._toggleMultiOption(s,e):this._selectSingleOption(s,e)},this._bindOptionClicks(),this._triggerClickHandler=t=>{t.stopPropagation(),!this.disabled&&this.toggleOptions()},this.trigger.addEventListener("click",this._triggerClickHandler),this._keydownHandler=t=>{if(!this.isOpen||this.disabled)return;const e=this._getVisibleOptions();if(e.length)switch(t.key){case"ArrowDown":t.preventDefault(),this.focusIndex=Math.min(this.focusIndex+1,e.length-1),this._focusOption(e);break;case"ArrowUp":t.preventDefault(),this.focusIndex=Math.max(this.focusIndex-1,0),this._focusOption(e);break;case"Enter":t.preventDefault(),this.focusIndex>=0&&e[this.focusIndex]&&e[this.focusIndex].click();break;case"Escape":t.preventDefault(),this.hideOptions(),this.trigger.focus();break}},document.addEventListener("keydown",this._keydownHandler),this._documentClickHandler=t=>{!this.element.contains(t.target)&&!this.optionsEl.contains(t.target)&&this.hideOptions()},this._documentClickListener=H.on(document,"click",this._documentClickHandler,{scope:this.scope}),this._restoreSelectedState(),this.optionsEl.style.display="none",this.element.__kupolaInitialized=!0)}_collectOptions(){this.allOptions=[],this.optionsEl.querySelectorAll(".ds-select__option, .ds-select__item").forEach(t=>{this.allOptions.push({el:t,value:t.getAttribute("data-value"),text:t.textContent.trim(),group:t.closest(".ds-select__group")?.getAttribute("data-group")||"",disabled:t.classList.contains("is-disabled")})}),this.filteredOptions=[...this.allOptions]}_createSearchInput(){this.searchInput=document.createElement("input"),this.searchInput.className="ds-select__search",this.searchInput.type="text",this.searchInput.placeholder="Search...",this.searchInput.setAttribute("autocomplete","off"),this.searchInput.addEventListener("input",()=>this._handleSearch()),this.searchInput.addEventListener("click",t=>t.stopPropagation()),this.optionsEl.insertBefore(this.searchInput,this.optionsEl.firstChild)}_createClearButton(){this.clearBtn=document.createElement("button"),this.clearBtn.className="ds-select__clear",this.clearBtn.type="button",this.clearBtn.innerHTML='<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>',this.clearBtn.style.display="none",this.clearBtn.addEventListener("click",e=>{e.stopPropagation(),this.clear()});const t=this.trigger.querySelector(".ds-select__value")||this.trigger;t.parentNode.insertBefore(this.clearBtn,t.nextSibling)}_createTagsWrap(){this.tagsWrap=document.createElement("div"),this.tagsWrap.className="ds-select__tags";const t=this.valueEl||this.trigger;t.parentNode.insertBefore(this.tagsWrap,t.nextSibling)}_handleSearch(){const t=this.searchInput.value.toLowerCase().trim();if(this.remoteMethod){this.remoteMethod(t,e=>{this._renderRemoteOptions(e)});return}this.filteredOptions=this.allOptions.filter(e=>e.text.toLowerCase().includes(t)),this.allOptions.forEach(e=>{const s=this.filteredOptions.includes(e);e.el.style.display=s?"":"none"}),this.optionsEl.querySelectorAll(".ds-select__group-title").forEach(e=>{const s=e.getAttribute("data-group"),n=this.filteredOptions.some(r=>r.group===s);e.style.display=n?"":"none"}),this.focusIndex=-1}_renderRemoteOptions(t){this.optionsEl.querySelectorAll(".ds-select__option, .ds-select__item").forEach(e=>{e._selectOptionClickHandler&&e.removeEventListener("click",e._selectOptionClickHandler),e.remove()}),t.forEach(e=>{const s=document.createElement("div");s.className="ds-select__option",s.setAttribute("data-value",e.value),s.textContent=e.text||e.label,e.disabled&&s.classList.add("is-disabled"),this.selectedValues.has(e.value)&&s.classList.add("is-selected"),s.addEventListener("click",this._optionClickHandler),s._selectOptionClickHandler=this._optionClickHandler,this.optionsEl.appendChild(s)}),this.allOptions=t.map(e=>({el:this.optionsEl.querySelector(`[data-value="${e.value}"]`),value:e.value,text:e.text||e.label,group:"",disabled:!!e.disabled})),this.filteredOptions=[...this.allOptions]}_selectSingleOption(t,e){this.optionsEl.querySelectorAll(".ds-select__option, .ds-select__item").forEach(s=>s.classList.remove("is-selected")),e.classList.add("is-selected"),this.selectedValues.clear(),this.selectedValues.add(t),this.updateValue(e.textContent.trim()),this._syncNativeSelect(),this.hideOptions(),this._updateClearBtn(),this._fireChange()}_toggleMultiOption(t,e){if(this.selectedValues.has(t))this.selectedValues.delete(t),e.classList.remove("is-selected");else{if(this.selectedValues.size>=this.maxSelection)return;this.selectedValues.add(t),e.classList.add("is-selected")}this._updateTags(),this._updateValueDisplay(),this._syncNativeSelect(),this._updateClearBtn(),this._fireChange()}_updateTags(){this.tagsWrap&&(this.tagsWrap.innerHTML="",this.selectedValues.forEach(t=>{const e=this.allOptions.find(r=>r.value===t);if(!e)return;const s=document.createElement("span");s.className="ds-select__tag",s.textContent=e.text;const n=document.createElement("button");n.className="ds-select__tag-close",n.type="button",n.innerHTML='<svg width="10" height="10" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>',n.addEventListener("click",r=>{r.stopPropagation(),this.selectedValues.delete(t);const a=this.optionsEl.querySelector(`[data-value="${t}"]`);a&&a.classList.remove("is-selected"),this._updateTags(),this._updateValueDisplay(),this._syncNativeSelect(),this._updateClearBtn(),this._fireChange()}),s.appendChild(n),this.tagsWrap.appendChild(s)}))}_updateValueDisplay(){if(this.valueEl)if(this.multiple){const t=this.selectedValues.size;t===0?(this.valueEl.textContent=this.placeholder||"",this.valueEl.classList.add("ds-select__value--placeholder")):(this.valueEl.textContent=`Selected ${t}`,this.valueEl.classList.remove("ds-select__value--placeholder")),this.tagsWrap&&(this.valueEl.style.display=t>0?"none":"")}else this.selectedValues.size===0&&(this.valueEl.textContent=this.placeholder||"",this.valueEl.classList.add("ds-select__value--placeholder"))}_updateClearBtn(){this.clearBtn&&(this.clearBtn.style.display=this.selectedValues.size>0?"":"none")}_syncNativeSelect(){this.nativeSelect&&(this.multiple?Array.from(this.nativeSelect.options).forEach(t=>{t.selected=this.selectedValues.has(t.value)}):this.nativeSelect.value=Array.from(this.selectedValues)[0]||"")}_fireChange(){this.nativeSelect&&this.nativeSelect.dispatchEvent(new Event("change",{bubbles:!0}));const t=this.multiple?Array.from(this.selectedValues):Array.from(this.selectedValues)[0];this.onChange&&this.onChange({values:t,selectedOptions:this.getSelectedOptions()}),this.element.dispatchEvent(new CustomEvent("kupola:select-change",{detail:{values:t,selectedOptions:this.getSelectedOptions()},bubbles:!0}))}_restoreSelectedState(){if(this.nativeSelect){if(this.multiple)Array.from(this.nativeSelect.selectedOptions).forEach(t=>{this.selectedValues.add(t.value);const e=this.optionsEl.querySelector(`[data-value="${t.value}"]`);e&&e.classList.add("is-selected")}),this._updateTags(),this._updateValueDisplay();else if(this.nativeSelect.value){this.selectedValues.add(this.nativeSelect.value);const t=this.optionsEl.querySelector(`[data-value="${this.nativeSelect.value}"]`);t&&(t.classList.add("is-selected"),this.updateValue(t.textContent.trim()))}}this._updateClearBtn()}_bindOptionClicks(){this.optionsEl.querySelectorAll(".ds-select__option, .ds-select__item").forEach(t=>{t.addEventListener("click",this._optionClickHandler),t._selectOptionClickHandler=this._optionClickHandler})}_getVisibleOptions(){return Array.from(this.optionsEl.querySelectorAll(".ds-select__option, .ds-select__item")).filter(t=>t.style.display!=="none"&&!t.classList.contains("is-disabled"))}_focusOption(t){t.forEach(e=>e.classList.remove("is-focused")),t[this.focusIndex]&&(t[this.focusIndex].classList.add("is-focused"),t[this.focusIndex].scrollIntoView({block:"nearest"}))}updateValue(t){this.valueEl&&(this.valueEl.textContent=t||this.valueEl.textContent,this.valueEl.classList.remove("ds-select__value--placeholder"))}showOptions(){this.disabled||this.isOpen||(this.isOpen=!0,this.element.classList.add("is-open"),this.icon&&(this.icon.style.transform="rotate(180deg)"),this.focusIndex=-1,this.appendToBody&&(this._appendOptionsToBody(),this._addScrollListener()),this.optionsEl.style.display="block",this._calculateOptionsPosition(),this.searchInput&&setTimeout(()=>this.searchInput.focus(),50))}hideOptions(){this.isOpen&&(this.isOpen=!1,this.optionsEl.style.display="none",this.icon&&(this.icon.style.transform="rotate(0deg)"),this.element.classList.remove("is-open"),this.appendToBody&&(this._restoreOptionsFromBody(),this._removeScrollListener()),this.searchInput&&(this.searchInput.value="",this._handleSearch()),this.optionsEl.querySelectorAll(".ds-select__option, .ds-select__item").forEach(t=>t.classList.remove("is-focused")))}_addScrollListener(){this._scrollHandler=()=>{this.hideOptions()},window.addEventListener("scroll",this._scrollHandler,!0)}_removeScrollListener(){this._scrollHandler&&(window.removeEventListener("scroll",this._scrollHandler,!0),this._scrollHandler=null)}_appendOptionsToBody(){if(!this.optionsEl)return;this._originalParent=this.optionsEl.parentNode,this._originalPosition=this.optionsEl.style.position,this._originalTop=this.optionsEl.style.top,this._originalLeft=this.optionsEl.style.left,this._originalRight=this.optionsEl.style.right,this._originalWidth=this.optionsEl.style.width,this._originalTransform=this.optionsEl.style.transform,this._originalZIndex=this.optionsEl.style.zIndex;const t=Y().dropdown;this.optionsEl.style.position="fixed",this.optionsEl.style.zIndex=t,this.optionsEl.style.transform="translateZ(0)",document.body.appendChild(this.optionsEl)}_restoreOptionsFromBody(){!this.optionsEl||!this._originalParent||(this._originalParent.appendChild(this.optionsEl),this.optionsEl.style.position=this._originalPosition||"",this.optionsEl.style.top=this._originalTop||"",this.optionsEl.style.left=this._originalLeft||"",this.optionsEl.style.right=this._originalRight||"",this.optionsEl.style.width=this._originalWidth||"",this.optionsEl.style.zIndex=this._originalZIndex||"",this.optionsEl.style.transform=this._originalTransform||"",this._originalParent=null)}_calculateOptionsPosition(){if(!this.appendToBody||!this.optionsEl)return;const t=this.element.getBoundingClientRect(),e=this.optionsEl.getBoundingClientRect(),s=window.innerHeight,n=window.innerWidth;this.optionsEl.style.width=`${Math.max(t.width,e.width)}px`;const r=s-t.bottom,a=t.top;r<e.height&&a>r?this.optionsEl.style.top=`${t.top-e.height-4}px`:this.optionsEl.style.top=`${t.bottom+4}px`,t.left+e.width>n?this.optionsEl.style.left=`${t.right-Math.max(t.width,e.width)}px`:this.optionsEl.style.left=`${t.left}px`}toggleOptions(){this.isOpen?this.hideOptions():this.showOptions()}clear(){this.selectedValues.clear(),this.optionsEl.querySelectorAll(".ds-select__option, .ds-select__item").forEach(t=>t.classList.remove("is-selected")),this._updateTags(),this._updateValueDisplay(),this._syncNativeSelect(),this._updateClearBtn(),this._fireChange()}getSelectedOptions(){return Array.from(this.selectedValues).map(t=>{const e=this.allOptions.find(s=>s.value===t);return e?{value:e.value,text:e.text}:{value:t,text:""}})}getValue(){return this.multiple?Array.from(this.selectedValues):Array.from(this.selectedValues)[0]||""}setValue(t){this.multiple&&Array.isArray(t)?(this.selectedValues.clear(),t.forEach(e=>this.selectedValues.add(e)),this.optionsEl.querySelectorAll(".ds-select__option, .ds-select__item").forEach(e=>{e.classList.toggle("is-selected",this.selectedValues.has(e.getAttribute("data-value")))}),this._updateTags(),this._updateValueDisplay()):(this.selectedValues.clear(),this.selectedValues.add(t),this.optionsEl.querySelectorAll(".ds-select__option, .ds-select__item").forEach(e=>{const s=e.getAttribute("data-value")===t;e.classList.toggle("is-selected",s),s&&this.updateValue(e.textContent.trim())})),this._syncNativeSelect(),this._updateClearBtn()}enable(){this.disabled=!1,this.element.removeAttribute("data-select-disabled")}disable(){this.disabled=!0,this.element.setAttribute("data-select-disabled",""),this.hideOptions()}destroy(){this.element.__kupolaInitialized&&(this.trigger&&this._triggerClickHandler&&this.trigger.removeEventListener("click",this._triggerClickHandler),this.optionsEl&&this.optionsEl.querySelectorAll(".ds-select__option, .ds-select__item").forEach(t=>{t._selectOptionClickHandler&&t.removeEventListener("click",t._selectOptionClickHandler)}),this._keydownHandler&&document.removeEventListener("keydown",this._keydownHandler),this._documentClickListener&&this._documentClickListener.unsubscribe?this._documentClickListener.unsubscribe():this._documentClickHandler&&document.removeEventListener("click",this._documentClickHandler),this.searchInput&&this.searchInput.remove(),this.clearBtn&&this.clearBtn.remove(),this.tagsWrap&&this.tagsWrap.remove(),this.appendToBody&&this._originalParent&&this._restoreOptionsFromBody(),this._documentClickHandler=null,this._documentClickListener=null,this._triggerClickHandler=null,this._optionClickHandler=null,this._keydownHandler=null,this.element.__kupolaInitialized=!1)}}function bt(i,t){const e=new Ue(i,t);e.init(),i._kupolaSelect=e}function oo(i=document){i.querySelectorAll(".ds-select").forEach(t=>{bt(t)})}function Ye(i){i._kupolaSelect&&(i._kupolaSelect.destroy(),i._kupolaSelect=null)}E.register("select",bt,Ye);class Xe{constructor(t,e={}){this.element=t,this.input=t.querySelector("input"),this.endInput=t.querySelector(".ds-datepicker__end-input"),this.icon=t.querySelector(".ds-datepicker__icon"),this.calendarEl=t.querySelector(".ds-datepicker__calendar"),this.scope=`datepicker-${Math.random().toString(36).substr(2,9)}`;const s=U(),n=s.datepicker?.weekStart!==void 0?s.datepicker.weekStart:1;this.format=e.format||t.getAttribute("data-datepicker-format")||"YYYY-MM-DD",this.range=e.range||t.hasAttribute("data-datepicker-range"),this.minDate=e.minDate||t.getAttribute("data-datepicker-min")||null,this.maxDate=e.maxDate||t.getAttribute("data-datepicker-max")||null,this.disabledDate=e.disabledDate||null,this.weekStart=e.weekStart!==void 0?e.weekStart:parseInt(t.getAttribute("data-datepicker-week-start"))||n,this.appendToBody=e.appendToBody!==!1,this.placeholder=e.placeholder||t.getAttribute("data-datepicker-placeholder")||"",this.showToday=e.showToday!==!1,this.showWeekNumber=e.showWeekNumber||t.hasAttribute("data-datepicker-week-number"),this.onChange=e.onChange||null,this.months=e.months||["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],this.weekDays=e.weekDays||["Su","Mo","Tu","We","Th","Fr","Sa"],this.todayText=e.todayText||"Today",this.clearText=e.clearText||"Clear",this.currentDate=new Date,this.viewMode="days",this.selectedDate=null,this.rangeStart=null,this.rangeEnd=null,this.isSelectingEnd=!1,this._iconClickHandler=null,this._inputClickHandler=null,this._endInputClickHandler=null,this._documentClickHandler=null,this._originalParent=null,this._documentClickListener=null,this._resizeHandler=null,this._resizeListener=null,this._keydownHandler=null}init(){if(this.calendarEl&&!this.element.__kupolaInitialized){if(this.input&&this.input.value)if(this.range){const t=this.input.value.split(" ~ ");t.length===2&&(this.rangeStart=this._parseDate(t[0].trim()),this.rangeEnd=this._parseDate(t[1].trim()),this.currentDate=new Date(this.rangeStart))}else this.selectedDate=this._parseDate(this.input.value),this.currentDate=new Date(this.selectedDate);this.placeholder&&this.input&&(this.input.placeholder=this.placeholder),this._iconClickHandler=t=>this.toggleCalendar(t),this._inputClickHandler=t=>this.toggleCalendar(t),this.icon&&this.icon.addEventListener("click",this._iconClickHandler),this.input&&this.input.addEventListener("click",this._inputClickHandler),this.endInput&&(this._endInputClickHandler=t=>{this.isSelectingEnd=!0,this.toggleCalendar(t)},this.endInput.addEventListener("click",this._endInputClickHandler)),this._documentClickListener=H.on(document,"click",t=>this.hideCalendar(t),{scope:this.scope}),this._resizeListener=H.on(window,"resize",()=>this.resizeHandler(),{scope:this.scope}),this._keydownHandler=t=>{t.key==="Escape"&&this.calendarEl.style.display==="block"&&this.hideCalendar(t)},document.addEventListener("keydown",this._keydownHandler),this.element.__kupolaInitialized=!0,this._renderCalendar()}}_parseDate(t){if(!t)return null;const e=t.split("-");return e.length===3?new Date(parseInt(e[0]),parseInt(e[1])-1,parseInt(e[2])):null}_formatDate(t){if(!t)return"";const e=t.getFullYear(),s=String(t.getMonth()+1).padStart(2,"0"),n=String(t.getDate()).padStart(2,"0");return this.format.replace("YYYY",e).replace("MM",s).replace("DD",n)}_isDateDisabled(t){if(this.minDate){const e=typeof this.minDate=="string"?this._parseDate(this.minDate):this.minDate;if(t<e)return!0}if(this.maxDate){const e=typeof this.maxDate=="string"?this._parseDate(this.maxDate):this.maxDate;if(t>e)return!0}return this.disabledDate?this.disabledDate(t):!1}_isToday(t){const e=new Date;return t.getFullYear()===e.getFullYear()&&t.getMonth()===e.getMonth()&&t.getDate()===e.getDate()}_isSameDay(t,e){return!t||!e?!1:t.getFullYear()===e.getFullYear()&&t.getMonth()===e.getMonth()&&t.getDate()===e.getDate()}_isInRange(t){if(!this.range||!this.rangeStart||!this.rangeEnd)return!1;const e=t.getTime(),s=Math.min(this.rangeStart.getTime(),this.rangeEnd.getTime()),n=Math.max(this.rangeStart.getTime(),this.rangeEnd.getTime());return e>=s&&e<=n}calculatePosition(){const t=this.element.getBoundingClientRect(),e=this.calendarEl.getBoundingClientRect(),n=window.innerHeight-t.bottom,r=t.top,a=e.height||320;this.appendToBody?(this.calendarEl.style.left=`${t.left}px`,n>=a?(this.calendarEl.style.top=`${t.bottom+4}px`,this.calendarEl.style.bottom="auto"):r>=a?(this.calendarEl.style.top=`${t.top-a-4}px`,this.calendarEl.style.bottom="auto"):(this.calendarEl.style.top=`${t.bottom+4}px`,this.calendarEl.style.bottom="auto")):n>=a?(this.calendarEl.style.top="calc(100% + 4px)",this.calendarEl.style.bottom="auto"):r>=a?(this.calendarEl.style.top="auto",this.calendarEl.style.bottom="calc(100% + 4px)"):(this.calendarEl.style.top="calc(100% + 4px)",this.calendarEl.style.bottom="auto")}toggleCalendar(t){t.preventDefault(),t.stopPropagation();const e=this.calendarEl.style.display==="block";document.querySelectorAll(".ds-datepicker__calendar").forEach(s=>{s!==this.calendarEl&&(s.style.display="none",s.setAttribute("hidden",""))}),e||(this.appendToBody&&(this._appendCalendarToBody(),this._addScrollListener()),this.calendarEl.style.display="block",this.calendarEl.removeAttribute("hidden"),this.calculatePosition())}hideCalendar(t){!this.element.contains(t.target)&&!this.calendarEl.contains(t.target)&&(this.calendarEl.style.display="none",this.calendarEl.setAttribute("hidden",""),this.viewMode="days",this.appendToBody&&(this._restoreCalendarFromBody(),this._removeScrollListener()))}_addScrollListener(){this._scrollHandler=()=>{this.hideCalendar({target:document})},window.addEventListener("scroll",this._scrollHandler,!0)}_removeScrollListener(){this._scrollHandler&&(window.removeEventListener("scroll",this._scrollHandler,!0),this._scrollHandler=null)}_appendCalendarToBody(){if(!this.calendarEl)return;this._originalParent=this.calendarEl.parentNode,this._originalPosition=this.calendarEl.style.position,this._originalTop=this.calendarEl.style.top,this._originalLeft=this.calendarEl.style.left,this._originalWidth=this.calendarEl.style.width,this._originalTransform=this.calendarEl.style.transform,this._originalZIndex=this.calendarEl.style.zIndex;const t=Y().datepicker;this.calendarEl.style.position="fixed",this.calendarEl.style.zIndex=t,this.calendarEl.style.transform="translateZ(0)",document.body.appendChild(this.calendarEl)}_restoreCalendarFromBody(){!this.calendarEl||!this._originalParent||(this._originalParent.appendChild(this.calendarEl),this.calendarEl.style.position=this._originalPosition||"",this.calendarEl.style.top=this._originalTop||"",this.calendarEl.style.left=this._originalLeft||"",this.calendarEl.style.width=this._originalWidth||"",this.calendarEl.style.zIndex=this._originalZIndex||"",this.calendarEl.style.transform=this._originalTransform||"",this._originalParent=null)}resizeHandler(){this.calendarEl.style.display==="block"&&this.calculatePosition()}_renderCalendar(){const t=this.calendarEl;if(!t)return;if(t.querySelectorAll(".ds-datepicker__day").forEach(p=>{p._dayClickHandler&&p.removeEventListener("click",p._dayClickHandler)}),this.viewMode==="years"){this._renderYearsView();return}if(this.viewMode==="months"){this._renderMonthsView();return}const e=this.currentDate.getFullYear(),s=this.currentDate.getMonth();t.innerHTML="";const n=document.createElement("div");n.className="ds-datepicker__header";const r=document.createElement("button");r.className="ds-datepicker__nav ds-datepicker__nav--prev",r.type="button",r.innerHTML='<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="15 18 9 12 15 6"/></svg>',r.addEventListener("click",p=>{p.stopPropagation(),this._prevMonth()});const a=document.createElement("button");a.className="ds-datepicker__title",a.type="button",a.textContent=`${e} ${this.months[s]}`,a.addEventListener("click",p=>{p.stopPropagation(),this.viewMode="months",this._renderCalendar()});const o=document.createElement("button");o.className="ds-datepicker__nav ds-datepicker__nav--next",o.type="button",o.innerHTML='<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="9 18 15 12 9 6"/></svg>',o.addEventListener("click",p=>{p.stopPropagation(),this._nextMonth()}),n.appendChild(r),n.appendChild(a),n.appendChild(o),t.appendChild(n);const l=document.createElement("div");l.className="ds-datepicker__weekdays",[...this.weekDays.slice(this.weekStart),...this.weekDays.slice(0,this.weekStart)].forEach(p=>{const m=document.createElement("span");m.className="ds-datepicker__weekday",m.textContent=p,l.appendChild(m)}),t.appendChild(l);const h=document.createElement("div");h.className="ds-datepicker__days";const d=new Date(e,s,1).getDay(),u=new Date(e,s+1,0).getDate(),f=(d-this.weekStart+7)%7;for(let p=0;p<f;p++){const m=document.createElement("span");m.className="ds-datepicker__day ds-datepicker__day--empty",h.appendChild(m)}for(let p=1;p<=u;p++){const m=new Date(e,s,p),y=document.createElement("button");y.className="ds-datepicker__day",y.type="button",y.textContent=p,this._formatDate(m),this._isToday(m)&&y.classList.add("is-today"),this.range?((this._isSameDay(m,this.rangeStart)||this._isSameDay(m,this.rangeEnd))&&y.classList.add("is-selected"),this._isInRange(m)&&y.classList.add("is-in-range")):this._isSameDay(m,this.selectedDate)&&y.classList.add("is-selected"),this._isDateDisabled(m)&&(y.classList.add("is-disabled"),y.disabled=!0);const _=()=>this._selectDate(m);y.addEventListener("click",_),y._dayClickHandler=_,h.appendChild(y)}if(t.appendChild(h),this.showToday){const p=document.createElement("div");p.className="ds-datepicker__footer";const m=document.createElement("button");m.className="ds-datepicker__today-btn",m.type="button",m.textContent=this.todayText,m.addEventListener("click",_=>{_.stopPropagation(),this._goToToday()});const y=document.createElement("button");y.className="ds-datepicker__clear-btn",y.type="button",y.textContent=this.clearText,y.addEventListener("click",_=>{_.stopPropagation(),this._clearDate()}),p.appendChild(m),p.appendChild(y),t.appendChild(p)}}_renderYearsView(){const t=this.calendarEl;t.innerHTML="";const e=this.currentDate.getFullYear(),s=e-6,n=document.createElement("div");n.className="ds-datepicker__header";const r=document.createElement("button");r.className="ds-datepicker__nav ds-datepicker__nav--prev",r.type="button",r.innerHTML='<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="15 18 9 12 15 6"/></svg>',r.addEventListener("click",c=>{c.stopPropagation(),this.currentDate.setFullYear(this.currentDate.getFullYear()-12),this._renderCalendar()});const a=document.createElement("button");a.className="ds-datepicker__title",a.type="button",a.textContent=`${s} - ${s+11}`,a.addEventListener("click",c=>{c.stopPropagation()});const o=document.createElement("button");o.className="ds-datepicker__nav ds-datepicker__nav--next",o.type="button",o.innerHTML='<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="9 18 15 12 9 6"/></svg>',o.addEventListener("click",c=>{c.stopPropagation(),this.currentDate.setFullYear(this.currentDate.getFullYear()+12),this._renderCalendar()}),n.appendChild(r),n.appendChild(a),n.appendChild(o),t.appendChild(n);const l=document.createElement("div");l.className="ds-datepicker__years-grid";for(let c=0;c<12;c++){const h=s+c,d=document.createElement("button");d.className="ds-datepicker__year-cell",d.type="button",d.textContent=h,h===e&&d.classList.add("is-selected"),d.addEventListener("click",u=>{u.stopPropagation(),this.currentDate.setFullYear(h),this.viewMode="months",this._renderCalendar()}),l.appendChild(d)}t.appendChild(l)}_renderMonthsView(){const t=this.calendarEl;t.innerHTML="";const e=this.currentDate.getFullYear(),s=document.createElement("div");s.className="ds-datepicker__header";const n=document.createElement("button");n.className="ds-datepicker__nav ds-datepicker__nav--prev",n.type="button",n.innerHTML='<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="15 18 9 12 15 6"/></svg>',n.addEventListener("click",l=>{l.stopPropagation(),this.currentDate.setFullYear(this.currentDate.getFullYear()-1),this._renderCalendar()});const r=document.createElement("button");r.className="ds-datepicker__title",r.type="button",r.textContent=e,r.addEventListener("click",l=>{l.stopPropagation(),this.viewMode="years",this._renderCalendar()});const a=document.createElement("button");a.className="ds-datepicker__nav ds-datepicker__nav--next",a.type="button",a.innerHTML='<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="9 18 15 12 9 6"/></svg>',a.addEventListener("click",l=>{l.stopPropagation(),this.currentDate.setFullYear(this.currentDate.getFullYear()+1),this._renderCalendar()}),s.appendChild(n),s.appendChild(r),s.appendChild(a),t.appendChild(s);const o=document.createElement("div");o.className="ds-datepicker__months-grid",this.months.forEach((l,c)=>{const h=document.createElement("button");h.className="ds-datepicker__month-cell",h.type="button",h.textContent=l,c===this.currentDate.getMonth()&&h.classList.add("is-selected"),h.addEventListener("click",d=>{d.stopPropagation(),this.currentDate.setMonth(c),this.viewMode="days",this._renderCalendar()}),o.appendChild(h)}),t.appendChild(o)}_selectDate(t){if(!this._isDateDisabled(t)){if(this.range)if(!this.isSelectingEnd||!this.rangeStart)this.rangeStart=t,this.rangeEnd=null,this.isSelectingEnd=!0;else{this.rangeEnd=t,this.rangeEnd<this.rangeStart&&([this.rangeStart,this.rangeEnd]=[this.rangeEnd,this.rangeStart]),this.isSelectingEnd=!1,this.input&&(this.input.value=this._formatDate(this.rangeStart)),this.endInput&&(this.endInput.value=this._formatDate(this.rangeEnd)),this.calendarEl.style.display="none",this.calendarEl.setAttribute("hidden",""),this._fireChange();return}else{this.selectedDate=t,this.input&&(this.input.value=this._formatDate(t)),this.calendarEl.style.display="none",this.calendarEl.setAttribute("hidden",""),this._fireChange();return}this._renderCalendar()}}_fireChange(){this.input&&this.input.dispatchEvent(new Event("change",{bubbles:!0})),this.onChange&&(this.range?this.onChange({start:this.rangeStart,end:this.rangeEnd,startStr:this._formatDate(this.rangeStart),endStr:this._formatDate(this.rangeEnd)}):this.onChange({date:this.selectedDate,dateStr:this._formatDate(this.selectedDate)})),this.element.dispatchEvent(new CustomEvent("kupola:datepicker-change",{detail:{date:this.selectedDate,dateStr:this._formatDate(this.selectedDate),rangeStart:this.rangeStart,rangeEnd:this.rangeEnd},bubbles:!0}))}_prevMonth(){this.currentDate.setMonth(this.currentDate.getMonth()-1),this._renderCalendar()}_nextMonth(){this.currentDate.setMonth(this.currentDate.getMonth()+1),this._renderCalendar()}_goToToday(){const t=new Date;this.currentDate=new Date(t),this._isDateDisabled(t)?this._renderCalendar():this._selectDate(t)}_clearDate(){this.selectedDate=null,this.rangeStart=null,this.rangeEnd=null,this.isSelectingEnd=!1,this.input&&(this.input.value=""),this.endInput&&(this.endInput.value=""),this.calendarEl.style.display="none",this.calendarEl.setAttribute("hidden",""),this._fireChange()}setDate(t){const e=typeof t=="string"?this._parseDate(t):t;e&&(this.selectedDate=e,this.currentDate=new Date(e),this.input&&(this.input.value=this._formatDate(e)),this._renderCalendar())}getDate(){return this.selectedDate}setRange(t,e){this.rangeStart=typeof t=="string"?this._parseDate(t):t,this.rangeEnd=typeof e=="string"?this._parseDate(e):e,this.input&&(this.input.value=this._formatDate(this.rangeStart)),this.endInput&&(this.endInput.value=this._formatDate(this.rangeEnd)),this._renderCalendar()}destroy(){this.element.__kupolaInitialized&&(this.icon&&this._iconClickHandler&&this.icon.removeEventListener("click",this._iconClickHandler),this.input&&this._inputClickHandler&&this.input.removeEventListener("click",this._inputClickHandler),this.endInput&&this._endInputClickHandler&&this.endInput.removeEventListener("click",this._endInputClickHandler),this._keydownHandler&&document.removeEventListener("keydown",this._keydownHandler),this._documentClickListener&&this._documentClickListener.unsubscribe?this._documentClickListener.unsubscribe():this._documentClickHandler&&document.removeEventListener("click",this._documentClickHandler),this._resizeListener&&this._resizeListener.unsubscribe?this._resizeListener.unsubscribe():this._resizeHandler&&window.removeEventListener("resize",this._resizeHandler),this.calendarEl&&this.calendarEl.querySelectorAll(".ds-datepicker__day").forEach(t=>{t._dayClickHandler&&t.removeEventListener("click",t._dayClickHandler)}),this.appendToBody&&this._originalParent&&this._restoreCalendarFromBody(),this._documentClickHandler=null,this._resizeHandler=null,this._documentClickListener=null,this._resizeListener=null,this._iconClickHandler=null,this._inputClickHandler=null,this._endInputClickHandler=null,this._keydownHandler=null,this.element.__kupolaInitialized=!1)}}function xt(i,t){const e=new Xe(i,t);e.init(),i._kupolaDatepicker=e}function lo(i=document){i.querySelectorAll(".ds-datepicker").forEach(t=>{xt(t)})}function je(i){i._kupolaDatepicker&&(i._kupolaDatepicker.destroy(),i._kupolaDatepicker=null)}E.register("datepicker",xt,je);class Je{constructor(t,e={}){this.element=t,this.input=t.querySelector("input"),this.inputWrap=t.querySelector(".ds-timepicker__input-wrap"),this.panelEl=null,this.scope=`timepicker-${Math.random().toString(36).substr(2,9)}`,this.showSeconds=e.showSeconds||t.hasAttribute("data-timepicker-seconds"),this.use12Hour=e.use12Hour||t.hasAttribute("data-timepicker-12h"),this.hourStep=e.hourStep||parseInt(t.getAttribute("data-timepicker-hour-step"))||1,this.minuteStep=e.minuteStep||parseInt(t.getAttribute("data-timepicker-minute-step"))||5,this.secondStep=e.secondStep||parseInt(t.getAttribute("data-timepicker-second-step"))||5,this.minTime=e.minTime||t.getAttribute("data-timepicker-min")||null,this.maxTime=e.maxTime||t.getAttribute("data-timepicker-max")||null,this.disabledTime=e.disabledTime||null,this.placeholder=e.placeholder||t.getAttribute("data-timepicker-placeholder")||"",this.clearable=e.clearable||t.hasAttribute("data-timepicker-clear"),this.onChange=e.onChange||null,this.selectedHour=12,this.selectedMinute=0,this.selectedSecond=0,this.isPM=!1,this._inputWrapClickHandler=null,this._documentClickHandler=null,this._documentClickListener=null,this._resizeHandler=null,this._resizeListener=null,this._keydownHandler=null}init(){this.element.__kupolaInitialized||(this.placeholder&&this.input&&(this.input.placeholder=this.placeholder),this.input&&this.input.value&&this._parseInputValue(),this._inputWrapClickHandler=t=>{t.stopPropagation(),this.panelEl&&this.panelEl.style.display==="block"?this.hideTimepicker():this.showTimepicker()},this.inputWrap.addEventListener("click",this._inputWrapClickHandler),this._documentClickListener=H.on(document,"click",t=>this.hideTimepicker(t),{scope:this.scope}),this._resizeListener=H.on(window,"resize",()=>this.resizeHandler(),{scope:this.scope}),this._keydownHandler=t=>{t.key==="Escape"&&this.panelEl&&this.panelEl.style.display==="block"&&this.hideTimepicker()},document.addEventListener("keydown",this._keydownHandler),this.element.__kupolaInitialized=!0)}_parseInputValue(){const t=this.input.value.trim();if(!t)return;const e=t.match(/^(\d{1,2}):(\d{2})(?::(\d{2}))?\s*(AM|PM|am|pm)$/i);if(e){this.selectedHour=parseInt(e[1])%12,e[4].toUpperCase()==="PM"&&(this.selectedHour+=12),this.selectedMinute=parseInt(e[2]),this.selectedSecond=e[3]?parseInt(e[3]):0;return}const s=t.split(":");s.length>=2&&(this.selectedHour=parseInt(s[0])||0,this.selectedMinute=parseInt(s[1])||0,this.selectedSecond=s[2]&&parseInt(s[2])||0)}_isTimeDisabled(t,e,s){if(this.disabledTime)return this.disabledTime(t,e,s);const n=t*3600+e*60+s;if(this.minTime){const r=this.minTime.split(":"),a=parseInt(r[0])*3600+parseInt(r[1])*60+(parseInt(r[2])||0);if(n<a)return!0}if(this.maxTime){const r=this.maxTime.split(":"),a=parseInt(r[0])*3600+parseInt(r[1])*60+(parseInt(r[2])||0);if(n>a)return!0}return!1}_formatTime(){let t=this.selectedHour,e=this.selectedMinute,s=this.selectedSecond;if(this.use12Hour){const n=t>=12?"PM":"AM";return t=t%12||12,this.showSeconds?`${t}:${String(e).padStart(2,"0")}:${String(s).padStart(2,"0")} ${n}`:`${t}:${String(e).padStart(2,"0")} ${n}`}return this.showSeconds?`${String(t).padStart(2,"0")}:${String(e).padStart(2,"0")}:${String(s).padStart(2,"0")}`:`${String(t).padStart(2,"0")}:${String(e).padStart(2,"0")}`}calculatePosition(){if(!this.panelEl)return;const t=this.element.getBoundingClientRect(),e=this.panelEl.getBoundingClientRect(),n=window.innerHeight-t.bottom,r=t.top,a=e.height||320;n>=a?(this.panelEl.style.top="calc(100% + 4px)",this.panelEl.style.bottom="auto"):r>=a?(this.panelEl.style.top="auto",this.panelEl.style.bottom="calc(100% + 4px)"):(this.panelEl.style.top="calc(100% + 4px)",this.panelEl.style.bottom="auto")}showTimepicker(){if(this.panelEl){this.panelEl.style.display="block",this._syncPanelSelection(),this.calculatePosition();return}this.panelEl=document.createElement("div"),this.panelEl.className="ds-timepicker__panel";let t="";if(t+=`<div class="ds-timepicker__section">
|
|
6
|
+
`}}_bindLifecycleHooks(){if(this._hooksBound)return;const t={beforeMount:"beforeMount",render:["mount","update"],afterMount:"afterMount",updated:"afterUpdate",beforeUnmount:"beforeUnmount",afterUnmount:"afterUnmount",renderError:"errorBoundary"};let e=Object.getPrototypeOf(this);const s=new Set;for(;e&&e.constructor!==Object&&e.constructor!==J;){for(const[n,r]of Object.entries(t))s.has(n)||e.hasOwnProperty(n)&&(Array.isArray(r)?r.forEach(a=>{n==="render"&&this.lifecycle.on(a,()=>this.render?.())}):n==="renderError"?this.lifecycle.on(r,a=>(this.renderError(a.error),"handled")):this.lifecycle.on(r,()=>this[n]?.()),s.add(n));e=Object.getPrototypeOf(e)}this._hooksBound=!0}async unmount(){if(!(!this.isMounted||this.isDestroyed))try{this.setupContext?._executeUnmounted(),await this.lifecycle.unmount(),this.isMounted=!1,this.isDestroyed=!0,await this.lifecycle.destroy()}catch(t){console.error(`[KupolaComponent] Error unmounting component "${this.constructor.name}":`,t),this.lifecycle&&typeof this.lifecycle._handleError=="function"&&await this.lifecycle._handleError({phase:"unmount",hook:"component",error:t,args:[]}),this.isMounted=!1,this.isDestroyed=!0}}beforeMount(){}afterMount(){}beforeUnmount(){}afterUnmount(){}render(){}renderError(t){}updated(){}setup(){}}function ut(i,t){Object.keys(t).forEach(e=>{if(e!=="constructor")if(typeof t[e]=="function"){const s=i.prototype[e];s?i.prototype[e]=function(...n){return t[e].apply(this,n),s.apply(this,n)}:i.prototype[e]=t[e]}else i.prototype[e]=t[e]})}class Ve{constructor(){this.components=new Map,this.lazyComponents=new Map,this.loadedComponents=new Map,this.instances=new Map,this.observer=null,this.mixins=new Map,this.loadingPromises=new Map}register(t,e){if(!(e.prototype instanceof J))throw new Error(`Component ${t} must extend KupolaComponent`);this.components.set(t,e)}registerLazy(t,e){this.lazyComponents.set(t,e)}unregister(t){this.components.delete(t),this.lazyComponents.delete(t),this.loadedComponents.delete(t),this.loadingPromises.delete(t)}get(t){return this.components.get(t)||this.loadedComponents.get(t)}async getAsync(t){const e=this.components.get(t)||this.loadedComponents.get(t);if(e)return e;if(this.loadingPromises.has(t))return this.loadingPromises.get(t);const s=this.lazyComponents.get(t);if(!s)throw new Error(`Component ${t} not found`);const n=(async()=>{try{const r=await s(),a=r.default||r;if(!(a.prototype instanceof J))throw new Error(`Component ${t} must extend KupolaComponent`);return this.loadedComponents.set(t,a),a}catch(r){throw this.loadingPromises.delete(t),r}})();return this.loadingPromises.set(t,n),n}defineMixin(t,e){this.mixins.set(t,e)}useMixin(t,...e){e.forEach(s=>{const n=this.mixins.get(s);n&&ut(t,n)})}async bootstrap(t=document){await this._upgradeElements(t),this._startObserver(t)}async _upgradeElements(t){const e=t.querySelectorAll("[data-component]"),s=[];e.forEach(n=>{s.push(this._upgradeElement(n))}),await Promise.all(s)}async _upgradeElement(t){if(!(t.__kupolaInstance||t.__kupolaUpgrading)){t.__kupolaUpgrading=!0;try{const e=t.getAttribute("data-component");if(e){const o=E.get(e);if(o)try{await o(t);return}catch(l){console.warn(`[KupolaComponentRegistry] Initializer for "${e}" failed, trying component class:`,l)}}let s=this.components.get(e);if(!s){try{s=await this.getAsync(e)}catch(o){console.error(`Failed to load component ${e}:`,o);return}if(!t.isConnected)return}const n=t.getAttribute("data-mixins"),r=s;n&&n.split(",").forEach(o=>{const l=this.mixins.get(o.trim());l&&ut(r,l)});const a=new r(t);t.__kupolaInstance=a,this.instances.set(t,a),a.mount()}finally{t.__kupolaUpgrading=!1}}}_startObserver(t){this.observer||(this.observer=new MutationObserver(e=>{e.forEach(s=>{s.addedNodes.forEach(n=>{if(n.nodeType===Node.ELEMENT_NODE){n.hasAttribute("data-component")&&this._upgradeElement(n).catch(a=>console.error(a)),this._upgradeElements(n).catch(a=>console.error(a)),E.initialize(n).catch(()=>{});const r=E._buildSelector();r&&n.querySelectorAll?.(r).forEach(a=>{E.initialize(a).catch(()=>{})})}}),s.removedNodes.forEach(n=>{if(n.nodeType===Node.ELEMENT_NODE){const r=this.instances.get(n);r&&(r.unmount(),this.instances.delete(n)),n.querySelectorAll("[data-component]").forEach(a=>{const o=this.instances.get(a);o&&(o.unmount(),this.instances.delete(a))}),E.cleanup(n),n.querySelectorAll?.("*").forEach(a=>{E.cleanup(a)})}})})}),this.observer.observe(t,{childList:!0,subtree:!0}))}destroy(){this.observer&&(this.observer.disconnect(),this.observer=null),this.instances.forEach(t=>{t.unmount()}),this.instances.clear(),this.components.clear(),this.mixins.clear()}}exports.kupolaRegistry=null;typeof window<"u"&&(exports.kupolaRegistry=new Ve);function $a(){if(Z().xssProtection&&typeof document<"u"){let t=document.querySelector('meta[http-equiv="X-XSS-Protection"]');t||(t=document.createElement("meta"),t.setAttribute("http-equiv","X-XSS-Protection"),t.setAttribute("content","1; mode=block"),document.head.insertBefore(t,document.head.firstChild)),t=document.querySelector('meta[http-equiv="X-Content-Type-Options"]'),t||(t=document.createElement("meta"),t.setAttribute("http-equiv","X-Content-Type-Options"),t.setAttribute("content","nosniff"),document.head.insertBefore(t,document.head.firstChild)),t=document.querySelector('meta[http-equiv="X-Frame-Options"]'),t||(t=document.createElement("meta"),t.setAttribute("http-equiv","X-Frame-Options"),t.setAttribute("content","SAMEORIGIN"),document.head.insertBefore(t,document.head.firstChild))}}async function pt(){if(typeof window<"u"){$a();const i=ot();q.loadPersisted(),q.bind(),Ne(),i.components?.autoInit!==!1&&(await E.initializeAll(),exports.kupolaRegistry&&await exports.kupolaRegistry.bootstrap())}}typeof document<"u"&&document.readyState==="loading"?document.addEventListener("DOMContentLoaded",pt):typeof window<"u"&&setTimeout(pt,0);function Ba(i,t){exports.kupolaRegistry&&exports.kupolaRegistry.register(i,t)}function qa(i,t){exports.kupolaRegistry&&exports.kupolaRegistry.registerLazy(i,t)}function Fa(i){return exports.kupolaRegistry?exports.kupolaRegistry.bootstrap(i):Promise.resolve()}function Oa(i,t){exports.kupolaRegistry&&exports.kupolaRegistry.defineMixin(i,t)}function Na(i,...t){exports.kupolaRegistry&&exports.kupolaRegistry.useMixin(i,...t)}function Ra(i,t){if(!t||typeof t!="object")throw new Error(`defineComponent("${i}"): options must be an object`);t.componentClass?exports.kupolaRegistry&&exports.kupolaRegistry.register(i,t.componentClass):t.lazy&&exports.kupolaRegistry&&exports.kupolaRegistry.registerLazy(i,t.lazy),t.init?E.register(i,t.init,t.cleanup||null,{dataAttribute:t.dataAttribute,cssClass:t.cssClass}):(t.dataAttribute||t.cssClass)&&E.register(i,()=>{},null,{dataAttribute:t.dataAttribute,cssClass:t.cssClass})}class _t{constructor(t={}){const e=ot();this.locales=t.locales||{},this.currentLocale=t.defaultLocale||e.i18n?.locale||"zh-CN",this.fallbackLocale=t.fallbackLocale||e.i18n?.fallbackLocale||"en-US",this.delimiter=t.delimiter||".",this.missingHandler=t.missingHandler||(s=>(console.warn(`Missing translation: ${s}`),s)),this._initFromDOM()}_initFromDOM(){document.querySelectorAll('script[type="application/json"][data-kupola-i18n]').forEach(s=>{const n=s.dataset.kupolaI18n;if(n)try{const r=JSON.parse(s.textContent);this.addLocale(n,r)}catch(r){console.error("Failed to parse i18n data:",r)}});const e=document.documentElement.lang;e&&this.locales[e]&&(this.currentLocale=e)}addLocale(t,e){this.locales[t]||(this.locales[t]={}),this._mergeDeep(this.locales[t],e)}_mergeDeep(t,e){for(const s of Object.keys(e))e[s]instanceof Object&&s in t?this._mergeDeep(t[s],e[s]):t[s]=e[s]}setLocale(t){return this.locales[t]?(this.currentLocale=t,document.documentElement.lang=t,this._emitChange(),!0):!1}getLocale(){return this.currentLocale}t(t,e={}){let s=this._getTranslation(t,this.currentLocale);return s||(s=this._getTranslation(t,this.fallbackLocale)),s?this._interpolate(s,e):this.missingHandler(t)}_getTranslation(t,e){if(!this.locales[e])return null;const s=t.split(this.delimiter);let n=this.locales[e];for(const r of s)if(n&&typeof n=="object"&&r in n)n=n[r];else return null;return typeof n=="string"?n:null}_interpolate(t,e){return t.replace(/\{(\w+)\}/g,(s,n)=>e[n]!==void 0?e[n]:s)}n(t,e,s={}){const n=this.t(t,{...s,count:e});if(!n)return n;const r=n.split("|");return r.length===1?n.replace("{count}",e):r.length===2?e===1?r[0]:r[1]:r.length>=3?e===0?r[0]:e===1?r[1]:r[2]:n}_emitChange(){const t=new CustomEvent("kupola:i18n:change",{detail:{locale:this.currentLocale},bubbles:!0});document.dispatchEvent(t)}async loadLocale(t,e){try{const n=await(await fetch(e)).json();return this.addLocale(t,n),!0}catch(s){return console.error("Failed to load locale:",s),!1}}getAvailableLocales(){return Object.keys(this.locales)}hasLocale(t){return!!this.locales[t]}formatDate(t,e={}){const s=e.locale||this.currentLocale,n=typeof t=="string"?new Date(t):t;return new Intl.DateTimeFormat(s,e).format(n)}formatNumber(t,e={}){const s=e.locale||this.currentLocale;return new Intl.NumberFormat(s,e).format(t)}formatCurrency(t,e,s={}){const n=s.locale||this.currentLocale;return new Intl.NumberFormat(n,{style:"currency",currency:e,...s}).format(t)}formatRelativeTime(t,e,s={}){const n=s.locale||this.currentLocale;return new Intl.RelativeTimeFormat(n,s).format(t,e)}}const O=new _t;function Va(i){return new _t(i)}function Ka(i,t={}){return O.t(i,t)}function Wa(i,t,e={}){return O.n(i,t,e)}function Ua(i){return O.setLocale(i)}function Ya(){return O.getLocale()}function Xa(i,t={}){return O.formatDate(i,t)}function ja(i,t={}){return O.formatNumber(i,t)}function Ja(i,t,e={}){return O.formatCurrency(i,t,e)}class Ke{constructor(){this._listeners=new Map,this._scopeListeners=new Map}on(t,e,s,n={}){const{scope:r=null,once:a=!1,passive:o=!1,capture:l=!1}=n,c=this._generateId(),h={id:c,target:t,eventName:e,handler:s,scope:r,once:a,wrappedHandler:null};h.wrappedHandler=u=>{a&&this.offById(c),s.call(t,u)};const d=this._getEventKey(t,e);return this._listeners.has(d)||this._listeners.set(d,[]),this._listeners.get(d).push(h),r&&(this._scopeListeners.has(r)||this._scopeListeners.set(r,[]),this._scopeListeners.get(r).push(c)),t.addEventListener(e,h.wrappedHandler,{passive:o,capture:l}),{unsubscribe:()=>this.offById(c)}}once(t,e,s,n={}){return this.on(t,e,s,{...n,once:!0})}off(t,e,s){const n=this._getEventKey(t,e);if(!this._listeners.has(n))return;const r=this._listeners.get(n),a=r.filter(o=>o.handler!==s);r.forEach(o=>{o.handler===s&&(t.removeEventListener(e,o.wrappedHandler),this._removeFromScope(o))}),a.length===0?this._listeners.delete(n):this._listeners.set(n,a)}offById(t){for(const[e,s]of this._listeners){const n=s.findIndex(r=>r.id===t);if(n!==-1){const r=s[n];return r.target.removeEventListener(r.eventName,r.wrappedHandler),s.splice(n,1),s.length===0&&this._listeners.delete(e),this._removeFromScope(r),!0}}return!1}offByScope(t){if(!this._scopeListeners.has(t))return;this._scopeListeners.get(t).forEach(s=>{this.offById(s)}),this._scopeListeners.delete(t)}offAll(t,e=null){if(e){const s=this._getEventKey(t,e);if(!this._listeners.has(s))return;this._listeners.get(s).forEach(r=>{t.removeEventListener(e,r.wrappedHandler),this._removeFromScope(r)}),this._listeners.delete(s)}else for(const[s,n]of this._listeners){const[r]=s.split(":");this._getTargetId(t)===r&&(n.forEach(a=>{t.removeEventListener(a.eventName,a.wrappedHandler),this._removeFromScope(a)}),this._listeners.delete(s))}}emit(t,e,s={}){const n=new CustomEvent(e,{detail:s,bubbles:!0,cancelable:!0});return t.dispatchEvent(n),n}emitGlobal(t,e={}){return this.emit(document,t,e)}emitToScope(t,e,s={}){if(!this._scopeListeners.has(t))return;const n=this._scopeListeners.get(t),r=new Set;for(const[a,o]of this._listeners)o.forEach(l=>{n.includes(l.id)&&r.add(l.target)});r.forEach(a=>{this.emit(a,e,s)})}getListenerCount(t,e=null){if(e){const r=this._getEventKey(t,e);return this._listeners.has(r)?this._listeners.get(r).length:0}let s=0;const n=this._getTargetId(t);for(const[r,a]of this._listeners){const[o]=r.split(":");o===n&&(s+=a.length)}return s}getScopeListenerCount(t){return this._scopeListeners.has(t)?this._scopeListeners.get(t).length:0}hasListeners(t,e=null){return this.getListenerCount(t,e)>0}_getEventKey(t,e){return`${this._getTargetId(t)}:${e}`}_getTargetId(t){return t===document?"document":t===window?"window":t===document.body?"body":(t._kupolaId||(t._kupolaId=this._generateId()),t._kupolaId)}_generateId(){return`ge-${Math.random().toString(36).substr(2,9)}-${Date.now()}`}_removeFromScope(t){if(!t.scope||!this._scopeListeners.has(t.scope))return;const e=this._scopeListeners.get(t.scope),s=e.indexOf(t.id);s!==-1&&(e.splice(s,1),e.length===0&&this._scopeListeners.delete(t.scope))}destroy(){for(const[t,e]of this._listeners)e.forEach(s=>{s.target.removeEventListener(s.eventName,s.wrappedHandler)});this._listeners.clear(),this._scopeListeners.clear()}}const H=new Ke;function Za(i,t,e,s){return H.on(i,t,e,s)}function Ga(i,t,e,s){return H.once(i,t,e,s)}function Qa(i,t,e){H.off(i,t,e)}function to(i,t,e){return H.emit(i,t,e)}function eo(i,t){return H.emitGlobal(i,t)}function so(i){H.offByScope(i)}function io(i,t){H.offAll(i,t)}function no(i,t){return H.getListenerCount(i,t)}class We{constructor(t,e={}){this.element=t,this.trigger=t.querySelector(".ds-dropdown__trigger"),this.menu=t.querySelector(".ds-dropdown__menu"),this.triggerText=this.trigger?this.trigger.querySelector("span"):null,this.scope=`dropdown-${Math.random().toString(36).substr(2,9)}`;const s=U();this.triggerMode=e.trigger||t.getAttribute("data-dropdown-trigger")||"click",this.hoverDelay=e.hoverDelay||parseInt(t.getAttribute("data-dropdown-hover-delay"))||150,this.disabled=e.disabled||t.hasAttribute("data-dropdown-disabled"),this.keyboardNav=e.keyboardNav!==!1,this.autoPosition=e.autoPosition!==!1,this.closeOnClick=e.closeOnClick!==void 0?e.closeOnClick:s.dropdown?.closeOnClick!==void 0?s.dropdown.closeOnClick:!0,this.appendToBody=e.appendToBody!==!1,this.onSelect=e.onSelect||null,this.onShow=e.onShow||null,this.onHide=e.onHide||null,this.isOpen=!1,this.focusIndex=-1,this._hoverTimer=null,this._hoverLeaveTimer=null,this._originalParent=null,this._originalPosition=null,this._triggerClickHandler=null,this._documentClickHandler=null,this._documentClickListener=null,this._itemClickHandler=null,this._keydownHandler=null,this._mouseenterHandler=null,this._mouseleaveHandler=null,this._triggerMouseenterHandler=null,this._triggerMouseleaveHandler=null,this._triggerKeydownHandler=null}init(){!this.trigger||!this.menu||this.element.__kupolaInitialized||(this._itemClickHandler=t=>{t.stopPropagation();const e=t.currentTarget;e.classList.contains("is-disabled")||e.classList.contains("ds-dropdown__divider")||(this.menu.querySelectorAll(".ds-dropdown__item").forEach(s=>s.classList.remove("is-selected")),e.classList.add("is-selected"),this.triggerText&&!e.hasAttribute("data-no-update-trigger")&&(this.triggerText.textContent=e.textContent.trim()),this.element.setAttribute("data-value",e.getAttribute("data-value")||""),this.onSelect&&this.onSelect({item:e,value:e.getAttribute("data-value"),text:e.textContent.trim()}),this.closeOnClick&&(this.hideMenu(),this.trigger.focus()))},this._bindMenuItems(),this._triggerClickHandler=t=>{t.stopPropagation(),!this.disabled&&this.toggleMenu()},this._triggerMouseenterHandler=()=>{this.disabled||this.triggerMode!=="hover"||(clearTimeout(this._hoverLeaveTimer),this._hoverTimer=setTimeout(()=>this.showMenu(),this.hoverDelay))},this._triggerMouseleaveHandler=()=>{this.triggerMode==="hover"&&(clearTimeout(this._hoverTimer),this._hoverLeaveTimer=setTimeout(()=>this.hideMenu(),this.hoverDelay))},this._mouseenterHandler=()=>{this.disabled||this.triggerMode!=="hover"||clearTimeout(this._hoverLeaveTimer)},this._mouseleaveHandler=()=>{this.triggerMode==="hover"&&(this._hoverLeaveTimer=setTimeout(()=>this.hideMenu(),this.hoverDelay))},this._keydownHandler=t=>{if(!this.isOpen||this.disabled)return;const e=this._getNavigableItems();if(e.length)switch(t.key){case"ArrowDown":t.preventDefault(),this.focusIndex=Math.min(this.focusIndex+1,e.length-1),this._focusItem(e);break;case"ArrowUp":t.preventDefault(),this.focusIndex=Math.max(this.focusIndex-1,0),this._focusItem(e);break;case"Enter":case" ":t.preventDefault(),this.focusIndex>=0&&e[this.focusIndex]&&e[this.focusIndex].click();break;case"Escape":t.preventDefault(),this.hideMenu(),this.trigger.focus();break;case"Home":t.preventDefault(),this.focusIndex=0,this._focusItem(e);break;case"End":t.preventDefault(),this.focusIndex=e.length-1,this._focusItem(e);break}},this.triggerMode==="hover"?(this.trigger.addEventListener("mouseenter",this._triggerMouseenterHandler),this.trigger.addEventListener("mouseleave",this._triggerMouseleaveHandler),this.menu.addEventListener("mouseenter",this._mouseenterHandler),this.menu.addEventListener("mouseleave",this._mouseleaveHandler)):this.trigger.addEventListener("click",this._triggerClickHandler),this._triggerKeydownHandler=t=>{this.disabled||(t.key==="Enter"||t.key===" "||t.key==="ArrowDown")&&(t.preventDefault(),this.showMenu())},this.trigger.addEventListener("keydown",this._triggerKeydownHandler),document.addEventListener("keydown",this._keydownHandler),this._documentClickHandler=t=>{!this.element.contains(t.target)&&!this.menu.contains(t.target)&&this.hideMenu()},this._documentClickListener=H.on(document,"click",this._documentClickHandler,{scope:this.scope}),this.menu.style.display="none",this.element.__kupolaInitialized=!0)}_bindMenuItems(){this.menu.querySelectorAll(".ds-dropdown__item").forEach(t=>{t.addEventListener("click",e=>this._itemClickHandler(e)),t._dropdownItemClickHandler=e=>this._itemClickHandler(e)})}_getNavigableItems(){return Array.from(this.menu.querySelectorAll(".ds-dropdown__item")).filter(t=>!t.classList.contains("is-disabled")&&!t.classList.contains("ds-dropdown__divider"))}_focusItem(t){t.forEach(e=>e.classList.remove("is-focused")),t[this.focusIndex]&&(t[this.focusIndex].classList.add("is-focused"),t[this.focusIndex].scrollIntoView({block:"nearest"}))}_calculatePosition(){if(!this.autoPosition)return;const t=this.element.getBoundingClientRect(),e=this.menu.getBoundingClientRect(),s=window.innerHeight,n=window.innerWidth;if(this.menu.classList.remove("ds-dropdown--top","ds-dropdown--right","ds-dropdown--dropup"),this.appendToBody){this.menu.style.width=`${Math.max(t.width,e.width)}px`;const r=s-t.bottom,a=t.top;r<e.height&&a>r?(this.menu.style.top=`${t.top-e.height-4}px`,this.menu.style.bottom="auto"):(this.menu.style.top=`${t.bottom+4}px`,this.menu.style.bottom="auto"),t.left+e.width>n?(this.menu.style.left=`${t.right-Math.max(t.width,e.width)}px`,this.menu.style.right="auto"):(this.menu.style.left=`${t.left}px`,this.menu.style.right="auto")}else{const r=s-t.bottom,a=t.top;r<e.height&&a>r?(this.menu.classList.add("ds-dropdown--dropup"),this.menu.style.top="auto",this.menu.style.bottom="100%",this.menu.style.marginBottom="4px"):(this.menu.style.top="100%",this.menu.style.bottom="auto",this.menu.style.marginBottom="0"),t.left+e.width>n?(this.menu.style.left="auto",this.menu.style.right="0"):(this.menu.style.left="0",this.menu.style.right="auto")}}showMenu(){this.disabled||this.isOpen||(this.isOpen=!0,this.focusIndex=-1,this.element.classList.add("is-open"),this.appendToBody&&(this._appendMenuToBody(),this._addScrollListener()),this.menu.style.display="block",this._calculatePosition(),this.onShow&&this.onShow(),this.element.dispatchEvent(new CustomEvent("kupola:dropdown-show",{bubbles:!0})))}hideMenu(){this.isOpen&&(this.isOpen=!1,this.menu.style.display="none",this.element.classList.remove("is-open"),this.appendToBody&&(this._restoreMenuFromBody(),this._removeScrollListener()),this.menu.querySelectorAll(".ds-dropdown__item").forEach(t=>t.classList.remove("is-focused")),this.onHide&&this.onHide(),this.element.dispatchEvent(new CustomEvent("kupola:dropdown-hide",{bubbles:!0})))}_appendMenuToBody(){if(!this.menu)return;this._originalParent=this.menu.parentNode,this._originalPosition=this.menu.style.position,this._originalTop=this.menu.style.top,this._originalLeft=this.menu.style.left,this._originalRight=this.menu.style.right,this._originalBottom=this.menu.style.bottom,this._originalMarginBottom=this.menu.style.marginBottom,this._originalWidth=this.menu.style.width,this._originalTransform=this.menu.style.transform,this._originalZIndex=this.menu.style.zIndex;const t=Y().dropdown;this.menu.style.position="fixed",this.menu.style.zIndex=t,this.menu.style.transform="translateZ(0)",document.body.appendChild(this.menu)}_restoreMenuFromBody(){!this.menu||!this._originalParent||(this._originalParent.appendChild(this.menu),this.menu.style.position=this._originalPosition||"",this.menu.style.top=this._originalTop||"",this.menu.style.left=this._originalLeft||"",this.menu.style.right=this._originalRight||"",this.menu.style.bottom=this._originalBottom||"",this.menu.style.marginBottom=this._originalMarginBottom||"",this.menu.style.width=this._originalWidth||"",this.menu.style.zIndex=this._originalZIndex||"",this.menu.style.transform=this._originalTransform||"",this._originalParent=null)}_addScrollListener(){this._scrollHandler=()=>{this.hideMenu()},window.addEventListener("scroll",this._scrollHandler,!0)}_removeScrollListener(){this._scrollHandler&&(window.removeEventListener("scroll",this._scrollHandler,!0),this._scrollHandler=null)}toggleMenu(){this.isOpen?this.hideMenu():this.showMenu()}enable(){this.disabled=!1,this.element.removeAttribute("data-dropdown-disabled")}disable(){this.disabled=!0,this.element.setAttribute("data-dropdown-disabled",""),this.hideMenu()}setItems(t){this.menu.querySelectorAll(".ds-dropdown__item").forEach(e=>{e._dropdownItemClickHandler&&e.removeEventListener("click",e._dropdownItemClickHandler)}),this.menu.innerHTML="",t.forEach(e=>{if(e.type==="divider"){const s=document.createElement("div");s.className="ds-dropdown__divider",this.menu.appendChild(s)}else{const s=document.createElement("div");s.className="ds-dropdown__item"+(e.disabled?" is-disabled":"")+(e.active?" is-selected":""),s.textContent=e.text||e.label||"",e.value!==void 0&&s.setAttribute("data-value",e.value),e.icon&&(s.innerHTML=e.icon+s.innerHTML),e.disabled&&s.classList.add("is-disabled"),this.menu.appendChild(s)}}),this._bindMenuItems()}destroy(){this.element.__kupolaInitialized&&(clearTimeout(this._hoverTimer),clearTimeout(this._hoverLeaveTimer),this.trigger&&(this._triggerClickHandler&&this.trigger.removeEventListener("click",this._triggerClickHandler),this._triggerMouseenterHandler&&this.trigger.removeEventListener("mouseenter",this._triggerMouseenterHandler),this._triggerMouseleaveHandler&&this.trigger.removeEventListener("mouseleave",this._triggerMouseleaveHandler),this._triggerKeydownHandler&&this.trigger.removeEventListener("keydown",this._triggerKeydownHandler)),this.menu&&(this.menu.querySelectorAll(".ds-dropdown__item").forEach(t=>{t._dropdownItemClickHandler&&t.removeEventListener("click",t._dropdownItemClickHandler)}),this._mouseenterHandler&&this.menu.removeEventListener("mouseenter",this._mouseenterHandler),this._mouseleaveHandler&&this.menu.removeEventListener("mouseleave",this._mouseleaveHandler)),this._keydownHandler&&document.removeEventListener("keydown",this._keydownHandler),this._documentClickListener&&this._documentClickListener.unsubscribe?this._documentClickListener.unsubscribe():this._documentClickHandler&&document.removeEventListener("click",this._documentClickHandler),this.appendToBody&&this._originalParent&&this._restoreMenuFromBody(),this._documentClickHandler=null,this._documentClickListener=null,this._triggerClickHandler=null,this._itemClickHandler=null,this._keydownHandler=null,this._mouseenterHandler=null,this._mouseleaveHandler=null,this._triggerMouseenterHandler=null,this._triggerMouseleaveHandler=null,this._triggerKeydownHandler=null,this.element.__kupolaInitialized=!1)}}function yt(i,t){const e=new We(i,t);e.init(),i._kupolaDropdown=e}function ro(i=document){i.querySelectorAll(".ds-dropdown").forEach(t=>{yt(t)})}function vt(i){i._kupolaDropdown&&(i._kupolaDropdown.destroy(),i._kupolaDropdown=null)}function ao(){document.querySelectorAll(".ds-dropdown").forEach(i=>{vt(i)})}E.register("dropdown",yt,vt);class Ue{constructor(t,e={}){this.element=t,this.trigger=t.querySelector(".ds-select__trigger"),this.valueEl=t.querySelector(".ds-select__value")||t.querySelector(".ds-select__trigger span"),this.optionsEl=t.querySelector(".ds-select__options")||t.querySelector(".ds-select__menu"),this.nativeSelect=t.querySelector("select"),this.icon=t.querySelector(".ds-select__icon"),this.scope=`select-${Math.random().toString(36).substr(2,9)}`,this.multiple=e.multiple||t.hasAttribute("data-select-multiple"),this.searchable=e.searchable||t.hasAttribute("data-select-search"),this.clearable=e.clearable||t.hasAttribute("data-select-clear"),this.placeholder=e.placeholder||t.getAttribute("data-select-placeholder")||"",this.disabled=e.disabled||t.hasAttribute("data-select-disabled"),this.maxSelection=e.maxSelection||parseInt(t.getAttribute("data-select-max"))||1/0,this.remoteMethod=e.remoteMethod||null,this.onChange=e.onChange||null,this.appendToBody=e.appendToBody!==!1,this.isOpen=!1,this.selectedValues=new Set,this.allOptions=[],this.filteredOptions=[],this.focusIndex=-1,this.searchInput=null,this.clearBtn=null,this.tagsWrap=null,this._originalParent=null,this._originalPosition=null,this._triggerClickHandler=null,this._documentClickHandler=null,this._documentClickListener=null,this._optionClickHandler=null,this._keydownHandler=null}init(){!this.trigger||!this.optionsEl||this.element.__kupolaInitialized||(this._collectOptions(),this.searchable&&this._createSearchInput(),this.clearable&&this._createClearButton(),this.multiple&&this._createTagsWrap(),this.placeholder&&this.valueEl&&(this.valueEl.setAttribute("data-placeholder",this.placeholder),this.selectedValues.size||(this.valueEl.classList.add("ds-select__value--placeholder"),this.valueEl.textContent=this.placeholder)),this._optionClickHandler=t=>{t.stopPropagation();const e=t.currentTarget;if(e.classList.contains("is-disabled"))return;const s=e.getAttribute("data-value");this.multiple?this._toggleMultiOption(s,e):this._selectSingleOption(s,e)},this._bindOptionClicks(),this._triggerClickHandler=t=>{t.stopPropagation(),!this.disabled&&this.toggleOptions()},this.trigger.addEventListener("click",this._triggerClickHandler),this._keydownHandler=t=>{if(!this.isOpen||this.disabled)return;const e=this._getVisibleOptions();if(e.length)switch(t.key){case"ArrowDown":t.preventDefault(),this.focusIndex=Math.min(this.focusIndex+1,e.length-1),this._focusOption(e);break;case"ArrowUp":t.preventDefault(),this.focusIndex=Math.max(this.focusIndex-1,0),this._focusOption(e);break;case"Enter":t.preventDefault(),this.focusIndex>=0&&e[this.focusIndex]&&e[this.focusIndex].click();break;case"Escape":t.preventDefault(),this.hideOptions(),this.trigger.focus();break}},document.addEventListener("keydown",this._keydownHandler),this._documentClickHandler=t=>{!this.element.contains(t.target)&&!this.optionsEl.contains(t.target)&&this.hideOptions()},this._documentClickListener=H.on(document,"click",this._documentClickHandler,{scope:this.scope}),this._restoreSelectedState(),this.optionsEl.style.display="none",this.element.__kupolaInitialized=!0)}_collectOptions(){this.allOptions=[],this.optionsEl.querySelectorAll(".ds-select__option, .ds-select__item").forEach(t=>{this.allOptions.push({el:t,value:t.getAttribute("data-value"),text:t.textContent.trim(),group:t.closest(".ds-select__group")?.getAttribute("data-group")||"",disabled:t.classList.contains("is-disabled")})}),this.filteredOptions=[...this.allOptions]}_createSearchInput(){this.searchInput=document.createElement("input"),this.searchInput.className="ds-select__search",this.searchInput.type="text",this.searchInput.placeholder="Search...",this.searchInput.setAttribute("autocomplete","off"),this.searchInput.addEventListener("input",()=>this._handleSearch()),this.searchInput.addEventListener("click",t=>t.stopPropagation()),this.optionsEl.insertBefore(this.searchInput,this.optionsEl.firstChild)}_createClearButton(){this.clearBtn=document.createElement("button"),this.clearBtn.className="ds-select__clear",this.clearBtn.type="button",this.clearBtn.innerHTML='<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>',this.clearBtn.style.display="none",this.clearBtn.addEventListener("click",e=>{e.stopPropagation(),this.clear()});const t=this.trigger.querySelector(".ds-select__value")||this.trigger;t.parentNode.insertBefore(this.clearBtn,t.nextSibling)}_createTagsWrap(){this.tagsWrap=document.createElement("div"),this.tagsWrap.className="ds-select__tags";const t=this.valueEl||this.trigger;t.parentNode.insertBefore(this.tagsWrap,t.nextSibling)}_handleSearch(){const t=this.searchInput.value.toLowerCase().trim();if(this.remoteMethod){this.remoteMethod(t,e=>{this._renderRemoteOptions(e)});return}this.filteredOptions=this.allOptions.filter(e=>e.text.toLowerCase().includes(t)),this.allOptions.forEach(e=>{const s=this.filteredOptions.includes(e);e.el.style.display=s?"":"none"}),this.optionsEl.querySelectorAll(".ds-select__group-title").forEach(e=>{const s=e.getAttribute("data-group"),n=this.filteredOptions.some(r=>r.group===s);e.style.display=n?"":"none"}),this.focusIndex=-1}_renderRemoteOptions(t){this.optionsEl.querySelectorAll(".ds-select__option, .ds-select__item").forEach(e=>{e._selectOptionClickHandler&&e.removeEventListener("click",e._selectOptionClickHandler),e.remove()}),t.forEach(e=>{const s=document.createElement("div");s.className="ds-select__option",s.setAttribute("data-value",e.value),s.textContent=e.text||e.label,e.disabled&&s.classList.add("is-disabled"),this.selectedValues.has(e.value)&&s.classList.add("is-selected"),s.addEventListener("click",n=>this._optionClickHandler(n)),s._selectOptionClickHandler=n=>this._optionClickHandler(n),this.optionsEl.appendChild(s)}),this.allOptions=t.map(e=>({el:this.optionsEl.querySelector(`[data-value="${e.value}"]`),value:e.value,text:e.text||e.label,group:"",disabled:!!e.disabled})),this.filteredOptions=[...this.allOptions]}_selectSingleOption(t,e){this.optionsEl.querySelectorAll(".ds-select__option, .ds-select__item").forEach(s=>s.classList.remove("is-selected")),e.classList.add("is-selected"),this.selectedValues.clear(),this.selectedValues.add(t),this.updateValue(e.textContent.trim()),this._syncNativeSelect(),this.hideOptions(),this._updateClearBtn(),this._fireChange()}_toggleMultiOption(t,e){if(this.selectedValues.has(t))this.selectedValues.delete(t),e.classList.remove("is-selected");else{if(this.selectedValues.size>=this.maxSelection)return;this.selectedValues.add(t),e.classList.add("is-selected")}this._updateTags(),this._updateValueDisplay(),this._syncNativeSelect(),this._updateClearBtn(),this._fireChange()}_updateTags(){this.tagsWrap&&(this.tagsWrap.innerHTML="",this.selectedValues.forEach(t=>{const e=this.allOptions.find(r=>r.value===t);if(!e)return;const s=document.createElement("span");s.className="ds-select__tag",s.textContent=e.text;const n=document.createElement("button");n.className="ds-select__tag-close",n.type="button",n.innerHTML='<svg width="10" height="10" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>',n.addEventListener("click",r=>{r.stopPropagation(),this.selectedValues.delete(t);const a=this.optionsEl.querySelector(`[data-value="${t}"]`);a&&a.classList.remove("is-selected"),this._updateTags(),this._updateValueDisplay(),this._syncNativeSelect(),this._updateClearBtn(),this._fireChange()}),s.appendChild(n),this.tagsWrap.appendChild(s)}))}_updateValueDisplay(){if(this.valueEl)if(this.multiple){const t=this.selectedValues.size;t===0?(this.valueEl.textContent=this.placeholder||"",this.valueEl.classList.add("ds-select__value--placeholder")):(this.valueEl.textContent=`Selected ${t}`,this.valueEl.classList.remove("ds-select__value--placeholder")),this.tagsWrap&&(this.valueEl.style.display=t>0?"none":"")}else this.selectedValues.size===0&&(this.valueEl.textContent=this.placeholder||"",this.valueEl.classList.add("ds-select__value--placeholder"))}_updateClearBtn(){this.clearBtn&&(this.clearBtn.style.display=this.selectedValues.size>0?"":"none")}_syncNativeSelect(){this.nativeSelect&&(this.multiple?Array.from(this.nativeSelect.options).forEach(t=>{t.selected=this.selectedValues.has(t.value)}):this.nativeSelect.value=Array.from(this.selectedValues)[0]||"")}_fireChange(){this.nativeSelect&&this.nativeSelect.dispatchEvent(new Event("change",{bubbles:!0}));const t=this.multiple?Array.from(this.selectedValues):Array.from(this.selectedValues)[0];this.onChange&&this.onChange({values:t,selectedOptions:this.getSelectedOptions()}),this.element.dispatchEvent(new CustomEvent("kupola:select-change",{detail:{values:t,selectedOptions:this.getSelectedOptions()},bubbles:!0}))}_restoreSelectedState(){if(this.nativeSelect){if(this.multiple)Array.from(this.nativeSelect.selectedOptions).forEach(t=>{this.selectedValues.add(t.value);const e=this.optionsEl.querySelector(`[data-value="${t.value}"]`);e&&e.classList.add("is-selected")}),this._updateTags(),this._updateValueDisplay();else if(this.nativeSelect.value){this.selectedValues.add(this.nativeSelect.value);const t=this.optionsEl.querySelector(`[data-value="${this.nativeSelect.value}"]`);t&&(t.classList.add("is-selected"),this.updateValue(t.textContent.trim()))}}this._updateClearBtn()}_bindOptionClicks(){this.optionsEl.querySelectorAll(".ds-select__option, .ds-select__item").forEach(t=>{t.addEventListener("click",e=>this._optionClickHandler(e)),t._selectOptionClickHandler=e=>this._optionClickHandler(e)})}_getVisibleOptions(){return Array.from(this.optionsEl.querySelectorAll(".ds-select__option, .ds-select__item")).filter(t=>t.style.display!=="none"&&!t.classList.contains("is-disabled"))}_focusOption(t){t.forEach(e=>e.classList.remove("is-focused")),t[this.focusIndex]&&(t[this.focusIndex].classList.add("is-focused"),t[this.focusIndex].scrollIntoView({block:"nearest"}))}updateValue(t){this.valueEl&&(this.valueEl.textContent=t||this.valueEl.textContent,this.valueEl.classList.remove("ds-select__value--placeholder"))}showOptions(){this.disabled||this.isOpen||(this.isOpen=!0,this.element.classList.add("is-open"),this.icon&&(this.icon.style.transform="rotate(180deg)"),this.focusIndex=-1,this.appendToBody&&(this._appendOptionsToBody(),this._addScrollListener()),this.optionsEl.style.display="block",this._calculateOptionsPosition(),this.searchInput&&setTimeout(()=>this.searchInput.focus(),50))}hideOptions(){this.isOpen&&(this.isOpen=!1,this.optionsEl.style.display="none",this.icon&&(this.icon.style.transform="rotate(0deg)"),this.element.classList.remove("is-open"),this.appendToBody&&(this._restoreOptionsFromBody(),this._removeScrollListener()),this.searchInput&&(this.searchInput.value="",this._handleSearch()),this.optionsEl.querySelectorAll(".ds-select__option, .ds-select__item").forEach(t=>t.classList.remove("is-focused")))}_addScrollListener(){this._scrollHandler=()=>{this.hideOptions()},window.addEventListener("scroll",this._scrollHandler,!0)}_removeScrollListener(){this._scrollHandler&&(window.removeEventListener("scroll",this._scrollHandler,!0),this._scrollHandler=null)}_appendOptionsToBody(){if(!this.optionsEl)return;this._originalParent=this.optionsEl.parentNode,this._originalPosition=this.optionsEl.style.position,this._originalTop=this.optionsEl.style.top,this._originalLeft=this.optionsEl.style.left,this._originalRight=this.optionsEl.style.right,this._originalWidth=this.optionsEl.style.width,this._originalTransform=this.optionsEl.style.transform,this._originalZIndex=this.optionsEl.style.zIndex;const t=Y().dropdown;this.optionsEl.style.position="fixed",this.optionsEl.style.zIndex=t,this.optionsEl.style.transform="translateZ(0)",document.body.appendChild(this.optionsEl)}_restoreOptionsFromBody(){!this.optionsEl||!this._originalParent||(this._originalParent.appendChild(this.optionsEl),this.optionsEl.style.position=this._originalPosition||"",this.optionsEl.style.top=this._originalTop||"",this.optionsEl.style.left=this._originalLeft||"",this.optionsEl.style.right=this._originalRight||"",this.optionsEl.style.width=this._originalWidth||"",this.optionsEl.style.zIndex=this._originalZIndex||"",this.optionsEl.style.transform=this._originalTransform||"",this._originalParent=null)}_calculateOptionsPosition(){if(!this.appendToBody||!this.optionsEl)return;const t=this.element.getBoundingClientRect(),e=this.optionsEl.getBoundingClientRect(),s=window.innerHeight,n=window.innerWidth;this.optionsEl.style.width=`${Math.max(t.width,e.width)}px`;const r=s-t.bottom,a=t.top;r<e.height&&a>r?this.optionsEl.style.top=`${t.top-e.height-4}px`:this.optionsEl.style.top=`${t.bottom+4}px`,t.left+e.width>n?this.optionsEl.style.left=`${t.right-Math.max(t.width,e.width)}px`:this.optionsEl.style.left=`${t.left}px`}toggleOptions(){this.isOpen?this.hideOptions():this.showOptions()}clear(){this.selectedValues.clear(),this.optionsEl.querySelectorAll(".ds-select__option, .ds-select__item").forEach(t=>t.classList.remove("is-selected")),this._updateTags(),this._updateValueDisplay(),this._syncNativeSelect(),this._updateClearBtn(),this._fireChange()}getSelectedOptions(){return Array.from(this.selectedValues).map(t=>{const e=this.allOptions.find(s=>s.value===t);return e?{value:e.value,text:e.text}:{value:t,text:""}})}getValue(){return this.multiple?Array.from(this.selectedValues):Array.from(this.selectedValues)[0]||""}setValue(t){this.multiple&&Array.isArray(t)?(this.selectedValues.clear(),t.forEach(e=>this.selectedValues.add(e)),this.optionsEl.querySelectorAll(".ds-select__option, .ds-select__item").forEach(e=>{e.classList.toggle("is-selected",this.selectedValues.has(e.getAttribute("data-value")))}),this._updateTags(),this._updateValueDisplay()):(this.selectedValues.clear(),this.selectedValues.add(t),this.optionsEl.querySelectorAll(".ds-select__option, .ds-select__item").forEach(e=>{const s=e.getAttribute("data-value")===t;e.classList.toggle("is-selected",s),s&&this.updateValue(e.textContent.trim())})),this._syncNativeSelect(),this._updateClearBtn()}enable(){this.disabled=!1,this.element.removeAttribute("data-select-disabled")}disable(){this.disabled=!0,this.element.setAttribute("data-select-disabled",""),this.hideOptions()}destroy(){this.element.__kupolaInitialized&&(this.trigger&&this._triggerClickHandler&&this.trigger.removeEventListener("click",this._triggerClickHandler),this.optionsEl&&this.optionsEl.querySelectorAll(".ds-select__option, .ds-select__item").forEach(t=>{t._selectOptionClickHandler&&t.removeEventListener("click",t._selectOptionClickHandler)}),this._keydownHandler&&document.removeEventListener("keydown",this._keydownHandler),this._documentClickListener&&this._documentClickListener.unsubscribe?this._documentClickListener.unsubscribe():this._documentClickHandler&&document.removeEventListener("click",this._documentClickHandler),this.searchInput&&this.searchInput.remove(),this.clearBtn&&this.clearBtn.remove(),this.tagsWrap&&this.tagsWrap.remove(),this.appendToBody&&this._originalParent&&this._restoreOptionsFromBody(),this._documentClickHandler=null,this._documentClickListener=null,this._triggerClickHandler=null,this._optionClickHandler=null,this._keydownHandler=null,this.element.__kupolaInitialized=!1)}}function bt(i,t){const e=new Ue(i,t);e.init(),i._kupolaSelect=e}function oo(i=document){i.querySelectorAll(".ds-select").forEach(t=>{bt(t)})}function Ye(i){i._kupolaSelect&&(i._kupolaSelect.destroy(),i._kupolaSelect=null)}E.register("select",bt,Ye);class Xe{constructor(t,e={}){this.element=t,this.input=t.querySelector("input"),this.endInput=t.querySelector(".ds-datepicker__end-input"),this.icon=t.querySelector(".ds-datepicker__icon"),this.calendarEl=t.querySelector(".ds-datepicker__calendar"),this.scope=`datepicker-${Math.random().toString(36).substr(2,9)}`;const s=U(),n=s.datepicker?.weekStart!==void 0?s.datepicker.weekStart:1;this.format=e.format||t.getAttribute("data-datepicker-format")||"YYYY-MM-DD",this.range=e.range||t.hasAttribute("data-datepicker-range"),this.minDate=e.minDate||t.getAttribute("data-datepicker-min")||null,this.maxDate=e.maxDate||t.getAttribute("data-datepicker-max")||null,this.disabledDate=e.disabledDate||null,this.weekStart=e.weekStart!==void 0?e.weekStart:parseInt(t.getAttribute("data-datepicker-week-start"))||n,this.appendToBody=e.appendToBody!==!1,this.placeholder=e.placeholder||t.getAttribute("data-datepicker-placeholder")||"",this.showToday=e.showToday!==!1,this.showWeekNumber=e.showWeekNumber||t.hasAttribute("data-datepicker-week-number"),this.onChange=e.onChange||null,this.months=e.months||["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],this.weekDays=e.weekDays||["Su","Mo","Tu","We","Th","Fr","Sa"],this.todayText=e.todayText||"Today",this.clearText=e.clearText||"Clear",this.currentDate=new Date,this.viewMode="days",this.selectedDate=null,this.rangeStart=null,this.rangeEnd=null,this.isSelectingEnd=!1,this._iconClickHandler=null,this._inputClickHandler=null,this._endInputClickHandler=null,this._documentClickHandler=null,this._originalParent=null,this._documentClickListener=null,this._resizeHandler=null,this._resizeListener=null,this._keydownHandler=null}init(){if(this.calendarEl&&!this.element.__kupolaInitialized){if(this.input&&this.input.value)if(this.range){const t=this.input.value.split(" ~ ");t.length===2&&(this.rangeStart=this._parseDate(t[0].trim()),this.rangeEnd=this._parseDate(t[1].trim()),this.currentDate=new Date(this.rangeStart))}else this.selectedDate=this._parseDate(this.input.value),this.currentDate=new Date(this.selectedDate);this.placeholder&&this.input&&(this.input.placeholder=this.placeholder),this._iconClickHandler=t=>this.toggleCalendar(t),this._inputClickHandler=t=>this.toggleCalendar(t),this.icon&&this.icon.addEventListener("click",this._iconClickHandler),this.input&&this.input.addEventListener("click",this._inputClickHandler),this.endInput&&(this._endInputClickHandler=t=>{this.isSelectingEnd=!0,this.toggleCalendar(t)},this.endInput.addEventListener("click",this._endInputClickHandler)),this._documentClickListener=H.on(document,"click",t=>this.hideCalendar(t),{scope:this.scope}),this._resizeListener=H.on(window,"resize",()=>this.resizeHandler(),{scope:this.scope}),this._keydownHandler=t=>{t.key==="Escape"&&this.calendarEl.style.display==="block"&&this.hideCalendar(t)},document.addEventListener("keydown",this._keydownHandler),this.element.__kupolaInitialized=!0,this._renderCalendar()}}_parseDate(t){if(!t)return null;const e=t.split("-");return e.length===3?new Date(parseInt(e[0]),parseInt(e[1])-1,parseInt(e[2])):null}_formatDate(t){if(!t)return"";const e=t.getFullYear(),s=String(t.getMonth()+1).padStart(2,"0"),n=String(t.getDate()).padStart(2,"0");return this.format.replace("YYYY",e).replace("MM",s).replace("DD",n)}_isDateDisabled(t){if(this.minDate){const e=typeof this.minDate=="string"?this._parseDate(this.minDate):this.minDate;if(t<e)return!0}if(this.maxDate){const e=typeof this.maxDate=="string"?this._parseDate(this.maxDate):this.maxDate;if(t>e)return!0}return this.disabledDate?this.disabledDate(t):!1}_isToday(t){const e=new Date;return t.getFullYear()===e.getFullYear()&&t.getMonth()===e.getMonth()&&t.getDate()===e.getDate()}_isSameDay(t,e){return!t||!e?!1:t.getFullYear()===e.getFullYear()&&t.getMonth()===e.getMonth()&&t.getDate()===e.getDate()}_isInRange(t){if(!this.range||!this.rangeStart||!this.rangeEnd)return!1;const e=t.getTime(),s=Math.min(this.rangeStart.getTime(),this.rangeEnd.getTime()),n=Math.max(this.rangeStart.getTime(),this.rangeEnd.getTime());return e>=s&&e<=n}calculatePosition(){const t=this.element.getBoundingClientRect(),e=this.calendarEl.getBoundingClientRect(),n=window.innerHeight-t.bottom,r=t.top,a=e.height||320;this.appendToBody?(this.calendarEl.style.left=`${t.left}px`,n>=a?(this.calendarEl.style.top=`${t.bottom+4}px`,this.calendarEl.style.bottom="auto"):r>=a?(this.calendarEl.style.top=`${t.top-a-4}px`,this.calendarEl.style.bottom="auto"):(this.calendarEl.style.top=`${t.bottom+4}px`,this.calendarEl.style.bottom="auto")):n>=a?(this.calendarEl.style.top="calc(100% + 4px)",this.calendarEl.style.bottom="auto"):r>=a?(this.calendarEl.style.top="auto",this.calendarEl.style.bottom="calc(100% + 4px)"):(this.calendarEl.style.top="calc(100% + 4px)",this.calendarEl.style.bottom="auto")}toggleCalendar(t){t.preventDefault(),t.stopPropagation();const e=this.calendarEl.style.display==="block";document.querySelectorAll(".ds-datepicker__calendar").forEach(s=>{s!==this.calendarEl&&(s.style.display="none",s.setAttribute("hidden",""))}),e||(this.appendToBody&&(this._appendCalendarToBody(),this._addScrollListener()),this.calendarEl.style.display="block",this.calendarEl.removeAttribute("hidden"),this.calculatePosition())}hideCalendar(t){!this.element.contains(t.target)&&!this.calendarEl.contains(t.target)&&(this.calendarEl.style.display="none",this.calendarEl.setAttribute("hidden",""),this.viewMode="days",this.appendToBody&&(this._restoreCalendarFromBody(),this._removeScrollListener()))}_addScrollListener(){this._scrollHandler=()=>{this.hideCalendar({target:document})},window.addEventListener("scroll",this._scrollHandler,!0)}_removeScrollListener(){this._scrollHandler&&(window.removeEventListener("scroll",this._scrollHandler,!0),this._scrollHandler=null)}_appendCalendarToBody(){if(!this.calendarEl)return;this._originalParent=this.calendarEl.parentNode,this._originalPosition=this.calendarEl.style.position,this._originalTop=this.calendarEl.style.top,this._originalLeft=this.calendarEl.style.left,this._originalWidth=this.calendarEl.style.width,this._originalTransform=this.calendarEl.style.transform,this._originalZIndex=this.calendarEl.style.zIndex;const t=Y().datepicker;this.calendarEl.style.position="fixed",this.calendarEl.style.zIndex=t,this.calendarEl.style.transform="translateZ(0)",document.body.appendChild(this.calendarEl)}_restoreCalendarFromBody(){!this.calendarEl||!this._originalParent||(this._originalParent.appendChild(this.calendarEl),this.calendarEl.style.position=this._originalPosition||"",this.calendarEl.style.top=this._originalTop||"",this.calendarEl.style.left=this._originalLeft||"",this.calendarEl.style.width=this._originalWidth||"",this.calendarEl.style.zIndex=this._originalZIndex||"",this.calendarEl.style.transform=this._originalTransform||"",this._originalParent=null)}resizeHandler(){this.calendarEl.style.display==="block"&&this.calculatePosition()}_renderCalendar(){const t=this.calendarEl;if(!t)return;if(t.querySelectorAll(".ds-datepicker__day").forEach(p=>{p._dayClickHandler&&p.removeEventListener("click",p._dayClickHandler)}),this.viewMode==="years"){this._renderYearsView();return}if(this.viewMode==="months"){this._renderMonthsView();return}const e=this.currentDate.getFullYear(),s=this.currentDate.getMonth();t.innerHTML="";const n=document.createElement("div");n.className="ds-datepicker__header";const r=document.createElement("button");r.className="ds-datepicker__nav ds-datepicker__nav--prev",r.type="button",r.innerHTML='<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="15 18 9 12 15 6"/></svg>',r.addEventListener("click",p=>{p.stopPropagation(),this._prevMonth()});const a=document.createElement("button");a.className="ds-datepicker__title",a.type="button",a.textContent=`${e} ${this.months[s]}`,a.addEventListener("click",p=>{p.stopPropagation(),this.viewMode="months",this._renderCalendar()});const o=document.createElement("button");o.className="ds-datepicker__nav ds-datepicker__nav--next",o.type="button",o.innerHTML='<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="9 18 15 12 9 6"/></svg>',o.addEventListener("click",p=>{p.stopPropagation(),this._nextMonth()}),n.appendChild(r),n.appendChild(a),n.appendChild(o),t.appendChild(n);const l=document.createElement("div");l.className="ds-datepicker__weekdays",[...this.weekDays.slice(this.weekStart),...this.weekDays.slice(0,this.weekStart)].forEach(p=>{const m=document.createElement("span");m.className="ds-datepicker__weekday",m.textContent=p,l.appendChild(m)}),t.appendChild(l);const h=document.createElement("div");h.className="ds-datepicker__days";const d=new Date(e,s,1).getDay(),u=new Date(e,s+1,0).getDate(),f=(d-this.weekStart+7)%7;for(let p=0;p<f;p++){const m=document.createElement("span");m.className="ds-datepicker__day ds-datepicker__day--empty",h.appendChild(m)}for(let p=1;p<=u;p++){const m=new Date(e,s,p),y=document.createElement("button");y.className="ds-datepicker__day",y.type="button",y.textContent=p,this._formatDate(m),this._isToday(m)&&y.classList.add("is-today"),this.range?((this._isSameDay(m,this.rangeStart)||this._isSameDay(m,this.rangeEnd))&&y.classList.add("is-selected"),this._isInRange(m)&&y.classList.add("is-in-range")):this._isSameDay(m,this.selectedDate)&&y.classList.add("is-selected"),this._isDateDisabled(m)&&(y.classList.add("is-disabled"),y.disabled=!0);const _=()=>this._selectDate(m);y.addEventListener("click",_),y._dayClickHandler=_,h.appendChild(y)}if(t.appendChild(h),this.showToday){const p=document.createElement("div");p.className="ds-datepicker__footer";const m=document.createElement("button");m.className="ds-datepicker__today-btn",m.type="button",m.textContent=this.todayText,m.addEventListener("click",_=>{_.stopPropagation(),this._goToToday()});const y=document.createElement("button");y.className="ds-datepicker__clear-btn",y.type="button",y.textContent=this.clearText,y.addEventListener("click",_=>{_.stopPropagation(),this._clearDate()}),p.appendChild(m),p.appendChild(y),t.appendChild(p)}}_renderYearsView(){const t=this.calendarEl;t.innerHTML="";const e=this.currentDate.getFullYear(),s=e-6,n=document.createElement("div");n.className="ds-datepicker__header";const r=document.createElement("button");r.className="ds-datepicker__nav ds-datepicker__nav--prev",r.type="button",r.innerHTML='<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="15 18 9 12 15 6"/></svg>',r.addEventListener("click",c=>{c.stopPropagation(),this.currentDate.setFullYear(this.currentDate.getFullYear()-12),this._renderCalendar()});const a=document.createElement("button");a.className="ds-datepicker__title",a.type="button",a.textContent=`${s} - ${s+11}`,a.addEventListener("click",c=>{c.stopPropagation()});const o=document.createElement("button");o.className="ds-datepicker__nav ds-datepicker__nav--next",o.type="button",o.innerHTML='<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="9 18 15 12 9 6"/></svg>',o.addEventListener("click",c=>{c.stopPropagation(),this.currentDate.setFullYear(this.currentDate.getFullYear()+12),this._renderCalendar()}),n.appendChild(r),n.appendChild(a),n.appendChild(o),t.appendChild(n);const l=document.createElement("div");l.className="ds-datepicker__years-grid";for(let c=0;c<12;c++){const h=s+c,d=document.createElement("button");d.className="ds-datepicker__year-cell",d.type="button",d.textContent=h,h===e&&d.classList.add("is-selected"),d.addEventListener("click",u=>{u.stopPropagation(),this.currentDate.setFullYear(h),this.viewMode="months",this._renderCalendar()}),l.appendChild(d)}t.appendChild(l)}_renderMonthsView(){const t=this.calendarEl;t.innerHTML="";const e=this.currentDate.getFullYear(),s=document.createElement("div");s.className="ds-datepicker__header";const n=document.createElement("button");n.className="ds-datepicker__nav ds-datepicker__nav--prev",n.type="button",n.innerHTML='<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="15 18 9 12 15 6"/></svg>',n.addEventListener("click",l=>{l.stopPropagation(),this.currentDate.setFullYear(this.currentDate.getFullYear()-1),this._renderCalendar()});const r=document.createElement("button");r.className="ds-datepicker__title",r.type="button",r.textContent=e,r.addEventListener("click",l=>{l.stopPropagation(),this.viewMode="years",this._renderCalendar()});const a=document.createElement("button");a.className="ds-datepicker__nav ds-datepicker__nav--next",a.type="button",a.innerHTML='<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="9 18 15 12 9 6"/></svg>',a.addEventListener("click",l=>{l.stopPropagation(),this.currentDate.setFullYear(this.currentDate.getFullYear()+1),this._renderCalendar()}),s.appendChild(n),s.appendChild(r),s.appendChild(a),t.appendChild(s);const o=document.createElement("div");o.className="ds-datepicker__months-grid",this.months.forEach((l,c)=>{const h=document.createElement("button");h.className="ds-datepicker__month-cell",h.type="button",h.textContent=l,c===this.currentDate.getMonth()&&h.classList.add("is-selected"),h.addEventListener("click",d=>{d.stopPropagation(),this.currentDate.setMonth(c),this.viewMode="days",this._renderCalendar()}),o.appendChild(h)}),t.appendChild(o)}_selectDate(t){if(!this._isDateDisabled(t)){if(this.range)if(!this.isSelectingEnd||!this.rangeStart)this.rangeStart=t,this.rangeEnd=null,this.isSelectingEnd=!0;else{this.rangeEnd=t,this.rangeEnd<this.rangeStart&&([this.rangeStart,this.rangeEnd]=[this.rangeEnd,this.rangeStart]),this.isSelectingEnd=!1,this.input&&(this.input.value=this._formatDate(this.rangeStart)),this.endInput&&(this.endInput.value=this._formatDate(this.rangeEnd)),this.calendarEl.style.display="none",this.calendarEl.setAttribute("hidden",""),this._fireChange();return}else{this.selectedDate=t,this.input&&(this.input.value=this._formatDate(t)),this.calendarEl.style.display="none",this.calendarEl.setAttribute("hidden",""),this._fireChange();return}this._renderCalendar()}}_fireChange(){this.input&&this.input.dispatchEvent(new Event("change",{bubbles:!0})),this.onChange&&(this.range?this.onChange({start:this.rangeStart,end:this.rangeEnd,startStr:this._formatDate(this.rangeStart),endStr:this._formatDate(this.rangeEnd)}):this.onChange({date:this.selectedDate,dateStr:this._formatDate(this.selectedDate)})),this.element.dispatchEvent(new CustomEvent("kupola:datepicker-change",{detail:{date:this.selectedDate,dateStr:this._formatDate(this.selectedDate),rangeStart:this.rangeStart,rangeEnd:this.rangeEnd},bubbles:!0}))}_prevMonth(){this.currentDate.setMonth(this.currentDate.getMonth()-1),this._renderCalendar()}_nextMonth(){this.currentDate.setMonth(this.currentDate.getMonth()+1),this._renderCalendar()}_goToToday(){const t=new Date;this.currentDate=new Date(t),this._isDateDisabled(t)?this._renderCalendar():this._selectDate(t)}_clearDate(){this.selectedDate=null,this.rangeStart=null,this.rangeEnd=null,this.isSelectingEnd=!1,this.input&&(this.input.value=""),this.endInput&&(this.endInput.value=""),this.calendarEl.style.display="none",this.calendarEl.setAttribute("hidden",""),this._fireChange()}setDate(t){const e=typeof t=="string"?this._parseDate(t):t;e&&(this.selectedDate=e,this.currentDate=new Date(e),this.input&&(this.input.value=this._formatDate(e)),this._renderCalendar())}getDate(){return this.selectedDate}setRange(t,e){this.rangeStart=typeof t=="string"?this._parseDate(t):t,this.rangeEnd=typeof e=="string"?this._parseDate(e):e,this.input&&(this.input.value=this._formatDate(this.rangeStart)),this.endInput&&(this.endInput.value=this._formatDate(this.rangeEnd)),this._renderCalendar()}destroy(){this.element.__kupolaInitialized&&(this.icon&&this._iconClickHandler&&this.icon.removeEventListener("click",this._iconClickHandler),this.input&&this._inputClickHandler&&this.input.removeEventListener("click",this._inputClickHandler),this.endInput&&this._endInputClickHandler&&this.endInput.removeEventListener("click",this._endInputClickHandler),this._keydownHandler&&document.removeEventListener("keydown",this._keydownHandler),this._documentClickListener&&this._documentClickListener.unsubscribe?this._documentClickListener.unsubscribe():this._documentClickHandler&&document.removeEventListener("click",this._documentClickHandler),this._resizeListener&&this._resizeListener.unsubscribe?this._resizeListener.unsubscribe():this._resizeHandler&&window.removeEventListener("resize",this._resizeHandler),this.calendarEl&&this.calendarEl.querySelectorAll(".ds-datepicker__day").forEach(t=>{t._dayClickHandler&&t.removeEventListener("click",t._dayClickHandler)}),this.appendToBody&&this._originalParent&&this._restoreCalendarFromBody(),this._documentClickHandler=null,this._resizeHandler=null,this._documentClickListener=null,this._resizeListener=null,this._iconClickHandler=null,this._inputClickHandler=null,this._endInputClickHandler=null,this._keydownHandler=null,this.element.__kupolaInitialized=!1)}}function xt(i,t){const e=new Xe(i,t);e.init(),i._kupolaDatepicker=e}function lo(i=document){i.querySelectorAll(".ds-datepicker").forEach(t=>{xt(t)})}function je(i){i._kupolaDatepicker&&(i._kupolaDatepicker.destroy(),i._kupolaDatepicker=null)}E.register("datepicker",xt,je);class Je{constructor(t,e={}){this.element=t,this.input=t.querySelector("input"),this.inputWrap=t.querySelector(".ds-timepicker__input-wrap"),this.panelEl=null,this.scope=`timepicker-${Math.random().toString(36).substr(2,9)}`,this.showSeconds=e.showSeconds||t.hasAttribute("data-timepicker-seconds"),this.use12Hour=e.use12Hour||t.hasAttribute("data-timepicker-12h"),this.hourStep=e.hourStep||parseInt(t.getAttribute("data-timepicker-hour-step"))||1,this.minuteStep=e.minuteStep||parseInt(t.getAttribute("data-timepicker-minute-step"))||5,this.secondStep=e.secondStep||parseInt(t.getAttribute("data-timepicker-second-step"))||5,this.minTime=e.minTime||t.getAttribute("data-timepicker-min")||null,this.maxTime=e.maxTime||t.getAttribute("data-timepicker-max")||null,this.disabledTime=e.disabledTime||null,this.placeholder=e.placeholder||t.getAttribute("data-timepicker-placeholder")||"",this.clearable=e.clearable||t.hasAttribute("data-timepicker-clear"),this.onChange=e.onChange||null,this.selectedHour=12,this.selectedMinute=0,this.selectedSecond=0,this.isPM=!1,this._inputWrapClickHandler=null,this._documentClickHandler=null,this._documentClickListener=null,this._resizeHandler=null,this._resizeListener=null,this._keydownHandler=null}init(){this.element.__kupolaInitialized||(this.placeholder&&this.input&&(this.input.placeholder=this.placeholder),this.input&&this.input.value&&this._parseInputValue(),this._inputWrapClickHandler=t=>{t.stopPropagation(),this.panelEl&&this.panelEl.style.display==="block"?this.hideTimepicker():this.showTimepicker()},this.inputWrap.addEventListener("click",this._inputWrapClickHandler),this._documentClickListener=H.on(document,"click",t=>this.hideTimepicker(t),{scope:this.scope}),this._resizeListener=H.on(window,"resize",()=>this.resizeHandler(),{scope:this.scope}),this._keydownHandler=t=>{t.key==="Escape"&&this.panelEl&&this.panelEl.style.display==="block"&&this.hideTimepicker()},document.addEventListener("keydown",this._keydownHandler),this.element.__kupolaInitialized=!0)}_parseInputValue(){const t=this.input.value.trim();if(!t)return;const e=t.match(/^(\d{1,2}):(\d{2})(?::(\d{2}))?\s*(AM|PM|am|pm)$/i);if(e){this.selectedHour=parseInt(e[1])%12,e[4].toUpperCase()==="PM"&&(this.selectedHour+=12),this.selectedMinute=parseInt(e[2]),this.selectedSecond=e[3]?parseInt(e[3]):0;return}const s=t.split(":");s.length>=2&&(this.selectedHour=parseInt(s[0])||0,this.selectedMinute=parseInt(s[1])||0,this.selectedSecond=s[2]&&parseInt(s[2])||0)}_isTimeDisabled(t,e,s){if(this.disabledTime)return this.disabledTime(t,e,s);const n=t*3600+e*60+s;if(this.minTime){const r=this.minTime.split(":"),a=parseInt(r[0])*3600+parseInt(r[1])*60+(parseInt(r[2])||0);if(n<a)return!0}if(this.maxTime){const r=this.maxTime.split(":"),a=parseInt(r[0])*3600+parseInt(r[1])*60+(parseInt(r[2])||0);if(n>a)return!0}return!1}_formatTime(){let t=this.selectedHour,e=this.selectedMinute,s=this.selectedSecond;if(this.use12Hour){const n=t>=12?"PM":"AM";return t=t%12||12,this.showSeconds?`${t}:${String(e).padStart(2,"0")}:${String(s).padStart(2,"0")} ${n}`:`${t}:${String(e).padStart(2,"0")} ${n}`}return this.showSeconds?`${String(t).padStart(2,"0")}:${String(e).padStart(2,"0")}:${String(s).padStart(2,"0")}`:`${String(t).padStart(2,"0")}:${String(e).padStart(2,"0")}`}calculatePosition(){if(!this.panelEl)return;const t=this.element.getBoundingClientRect(),e=this.panelEl.getBoundingClientRect(),n=window.innerHeight-t.bottom,r=t.top,a=e.height||320;n>=a?(this.panelEl.style.top="calc(100% + 4px)",this.panelEl.style.bottom="auto"):r>=a?(this.panelEl.style.top="auto",this.panelEl.style.bottom="calc(100% + 4px)"):(this.panelEl.style.top="calc(100% + 4px)",this.panelEl.style.bottom="auto")}showTimepicker(){if(this.panelEl){this.panelEl.style.display="block",this._syncPanelSelection(),this.calculatePosition();return}this.panelEl=document.createElement("div"),this.panelEl.className="ds-timepicker__panel";let t="";if(t+=`<div class="ds-timepicker__section">
|
|
7
7
|
<div class="ds-timepicker__section-label">Hour</div>
|
|
8
8
|
<div class="ds-timepicker__grid ds-timepicker__grid--hour" data-type="hour"></div>
|
|
9
9
|
</div>`,t+=`<div class="ds-timepicker__section">
|