monobill-mintui 0.6.619 → 0.6.620
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/components/alert/browser.js +3 -3
- package/dist/components/alert/index.cjs +1 -1
- package/dist/components/alert/index.js +3 -3
- package/dist/components/back-button/browser.js +2 -2
- package/dist/components/back-button/index.cjs +1 -1
- package/dist/components/back-button/index.js +2 -2
- package/dist/components/bottom-navigation/browser.js +2 -2
- package/dist/components/bottom-navigation/index.cjs +1 -1
- package/dist/components/bottom-navigation/index.js +2 -2
- package/dist/components/button/browser.js +1 -1
- package/dist/components/button/index.cjs +1 -1
- package/dist/components/button/index.js +1 -1
- package/dist/components/checkbox/browser.js +2 -2
- package/dist/components/checkbox/index.cjs +1 -1
- package/dist/components/checkbox/index.js +2 -2
- package/dist/components/chip/browser.js +1 -1
- package/dist/components/chip/index.cjs +1 -1
- package/dist/components/chip/index.js +1 -1
- package/dist/components/chunks/{button-BZ25puI2.js → button-BYQbRAwl.js} +2 -2
- package/dist/components/chunks/{button-CgYC1lB7.js → button-DbxqmBWQ.js} +1 -1
- package/dist/components/chunks/caret-down-CeADWana.js +1 -0
- package/dist/components/chunks/{caret-down-CDGP3GB2.js → caret-down-DD9Ie5js.js} +1 -1
- package/dist/components/chunks/caret-right-3V_JDnOP.js +1 -0
- package/dist/components/chunks/{caret-right-CQ5hBjsy.js → caret-right-fnCcTJKp.js} +1 -1
- package/dist/components/chunks/{caret-up-1paz-pnI.js → caret-up-CK7JOG6X.js} +1 -1
- package/dist/components/chunks/caret-up-hwsMK8n3.js +1 -0
- package/dist/components/chunks/{chip-p6RXdzHa.js → chip-08aR26vc.js} +3 -3
- package/dist/components/chunks/{chip-Bb1Epj5C.js → chip-8BYSJ7yI.js} +1 -1
- package/dist/components/chunks/close-BdZJfr6m.js +1 -0
- package/dist/components/chunks/{close-y8q0rMSE.js → close-CFxX3WCG.js} +1 -1
- package/dist/components/chunks/icon-B8p3Co0-.js +1 -0
- package/dist/components/chunks/{icon-B01tq_aJ.js → icon-BWUYe89V.js} +4 -3
- package/dist/components/chunks/{icon-BcsWL4kZ.js → icon-B_7c8b8e.js} +1 -1
- package/dist/components/chunks/icon-CSqBgTae.js +1 -0
- package/dist/components/chunks/{input-BzrCXBg4.js → input-Dwrs8tJH.js} +4 -4
- package/dist/components/chunks/{input-DnVgj6QV.js → input-lLl8cB6r.js} +1 -1
- package/dist/components/chunks/{modal-9S-FF3_o.js → modal-CNBmdA63.js} +1 -1
- package/dist/components/chunks/{modal-D7KKb4f9.js → modal-CPcIPIO7.js} +2 -2
- package/dist/components/chunks/search-Bsaoxa30.js +1 -0
- package/dist/components/chunks/{search-Dd28O4mG.js → search-xHKqAXph.js} +1 -1
- package/dist/components/confirm-action/browser.js +2 -2
- package/dist/components/confirm-action/index.cjs +1 -1
- package/dist/components/confirm-action/index.js +2 -2
- package/dist/components/date-picker/browser.js +4 -4
- package/dist/components/date-picker/index.cjs +1 -1
- package/dist/components/date-picker/index.js +4 -4
- package/dist/components/dropzone/browser.js +3 -3
- package/dist/components/dropzone/index.cjs +1 -1
- package/dist/components/dropzone/index.js +3 -3
- package/dist/components/icon/browser.js +1 -1
- package/dist/components/icon/index.cjs +1 -1
- package/dist/components/icon/index.js +1 -1
- package/dist/components/input/browser.js +1 -1
- package/dist/components/input/index.cjs +1 -1
- package/dist/components/input/index.js +1 -1
- package/dist/components/modal/browser.js +1 -1
- package/dist/components/modal/index.cjs +1 -1
- package/dist/components/modal/index.js +1 -1
- package/dist/components/navigation/browser.js +2 -2
- package/dist/components/navigation/index.cjs +1 -1
- package/dist/components/navigation/index.js +2 -2
- package/dist/components/off-canvas/browser.js +2 -2
- package/dist/components/off-canvas/index.cjs +1 -1
- package/dist/components/off-canvas/index.js +2 -2
- package/dist/components/resource-table/browser.js +7 -7
- package/dist/components/resource-table/index.cjs +1 -1
- package/dist/components/resource-table/index.js +7 -7
- package/dist/components/search/browser.js +7 -7
- package/dist/components/search/index.cjs +1 -1
- package/dist/components/search/index.js +7 -7
- package/dist/components/select/browser.js +4 -4
- package/dist/components/select/index.cjs +1 -1
- package/dist/components/select/index.js +4 -4
- package/dist/components/side-navigation/browser.js +4 -4
- package/dist/components/side-navigation/index.cjs +1 -1
- package/dist/components/side-navigation/index.js +4 -4
- package/dist/components/switch/browser.js +2 -2
- package/dist/components/switch/index.cjs +1 -1
- package/dist/components/switch/index.js +2 -2
- package/dist/components/tags/browser.js +3 -3
- package/dist/components/tags/index.cjs +1 -1
- package/dist/components/tags/index.js +3 -3
- package/dist/components/time-picker/browser.js +2 -2
- package/dist/components/time-picker/index.cjs +1 -1
- package/dist/components/time-picker/index.js +2 -2
- package/dist/icons/pin.svg +1 -3
- package/dist/index.cjs +1 -1
- package/dist/index.js +4 -3
- package/package.json +1 -1
- package/dist/components/chunks/caret-down-C5a1fGvt.js +0 -1
- package/dist/components/chunks/caret-right-BMyWflHN.js +0 -1
- package/dist/components/chunks/caret-up-BJAyfrty.js +0 -1
- package/dist/components/chunks/close-Bg0kqvrY.js +0 -1
- package/dist/components/chunks/icon-DNWs0suS.js +0 -1
- package/dist/components/chunks/icon-uMo_iGkX.js +0 -1
- package/dist/components/chunks/search-C5jD2OC-.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
require(`./icon-BcsWL4kZ.js`);const e=require(`./register-element-tCL_F1YI.js`);require(`./icon-uMo_iGkX.js`),require(`./caret-up-BJAyfrty.js`),require(`./caret-down-C5a1fGvt.js`);var t=class extends HTMLElement{static get observedAttributes(){return[`type`,`placeholder`,`value`,`disabled`,`id`,`name`,`required`,`readonly`,`rows`,`icon`,`label`,`info`,`error`,`error-message`,`loading`,`aria-label`,`aria-labelledby`,`aria-describedby`]}constructor(){super(),this._input=null,this._textarea=null,this._element=null,this._wrapper=null,this._icon=null,this._prependSlotContainer=null,this._appendSlotContainer=null,this._colorPicker=null,this._colorTextInput=null,this._colorContainer=null,this._colorPickerWrapper=null,this._numberSpinnerContainer=null,this._numberIncrementButton=null,this._numberDecrementButton=null,this._contentObserver=null,this._focusHandler=null,this._a11yId=``,this._blurHandler=null,this._clickHandler=null,this._clickOutsideHandler=null,this._renderFrame=null}connectedCallback(){this.classList.add(`mint-input-host`),this.render(),this._observeContentMutations()}disconnectedCallback(){this.removeEventListeners(),this._contentObserver&&=(this._contentObserver.disconnect(),null),this._renderFrame!==null&&(cancelAnimationFrame(this._renderFrame),this._renderFrame=null)}attributeChangedCallback(e,t,n){if(t!==n){if(e===`error`||e===`error-message`){this._renderErrorState(),this._syncControlAccessibility(),this._element&&(this._element.className=this.getInputClasses()),this._colorTextInput&&(this._colorTextInput.className=this.getInputClasses());return}if(e===`loading`){this.render();return}this.render()}}_scheduleRender(){this._renderFrame===null&&(this._renderFrame=requestAnimationFrame(()=>{this._renderFrame=null,this.render()}))}_observeContentMutations(){this._contentObserver||=new MutationObserver(()=>{this._scheduleRender()}),this._contentObserver.disconnect(),this._contentObserver.observe(this,{childList:!0,attributes:!0,attributeFilter:[`slot`]})}getType(){return this.getAttribute(`type`)||`text`}getRows(){let e=this.getAttribute(`rows`);return e?parseInt(e,10):3}_getNormalizedType(){let e=this.getType();return e===`datetime`?`datetime-local`:e===`money`?`text`:e===`textarea`?`textarea`:e}_isTextarea(){return this.getType()===`textarea`}_isMoney(){return this.getType()===`money`}_isColor(){return this.getType()===`color`}_isNumber(){return this.getType()===`number`}getPlaceholder(){return this.getAttribute(`placeholder`)||``}getValue(){return this._isColor()?this._colorTextInput?this._colorTextInput.value:this._colorPicker?this._colorPicker.value:this.getAttribute(`value`)||`#000000`:this._element?this._element.value:this.getAttribute(`value`)||``}set value(e){try{this._isColor()?(this._colorPicker&&(this._colorPicker.value=e||`#000000`),this._colorTextInput&&(this._colorTextInput.value=e||`#000000`)):this._element&&(this._element.value=e),e?this.setAttribute(`value`,e):this.removeAttribute(`value`)}catch{}}get value(){try{return this.getValue()||``}catch{return``}}isDisabled(){return this.getAttribute(`disabled`)===`true`}isReadonly(){return this.getAttribute(`readonly`)===`true`}isRequired(){return this.getAttribute(`required`)===`true`}hasError(){return this.getAttribute(`error`)===`true`}getErrorMessage(){return this.getAttribute(`error-message`)||``}getId(){return this.getAttribute(`id`)||``}getName(){return this.getAttribute(`name`)||``}getIcon(){return this.getAttribute(`icon`)||``}getLabel(){return this.getAttribute(`label`)||``}getInfo(){return this.getAttribute(`info`)||``}getInputClasses(){let e=this._isTextarea(),t=!!this.getIcon(),n=this.querySelector(`[slot="prepend"]`)!==null,r=this.querySelector(`[slot="append"]`)!==null,i=this._isColor(),a=this._isNumber(),o=this.hasError();return[`mint-input-control`,e&&`is-textarea`,t&&`has-icon`,i&&`is-color`,n&&`has-prepend`,r&&`has-append`,a&&`is-number`,o&&`has-error`].filter(Boolean).join(` `)}_syncSlotAdornments(e,t){if(!this._wrapper||e||this._isColor()){this._prependSlotContainer&&=(this._prependSlotContainer.remove(),null),this._appendSlotContainer&&=(this._appendSlotContainer.remove(),null);return}this._prependSlotContainer||(this._prependSlotContainer=document.createElement(`div`),this._prependSlotContainer.className=`mint-input-adornment mint-input-prepend-slot`,this._wrapper.appendChild(this._prependSlotContainer)),this._appendSlotContainer||(this._appendSlotContainer=document.createElement(`div`),this._appendSlotContainer.className=`mint-input-adornment mint-input-append-slot`,this._wrapper.appendChild(this._appendSlotContainer)),this._prependSlotContainer.classList.toggle(`has-icon-offset`,t);let n=Array.from(this.querySelectorAll(`[slot="prepend"]`)),r=Array.from(this.querySelectorAll(`[slot="append"]`));this._prependSlotContainer.replaceChildren(),this._appendSlotContainer.replaceChildren(),n.forEach(e=>this._prependSlotContainer.appendChild(e)),r.forEach(e=>this._appendSlotContainer.appendChild(e)),this._prependSlotContainer.classList.toggle(`is-hidden`,n.length===0),this._appendSlotContainer.classList.toggle(`is-hidden`,r.length===0)}isLoading(){return this.getAttribute(`loading`)===`true`}render(){this.getType();let e=this._getNormalizedType(),t=this._isTextarea(),n=this._isMoney(),r=this._isColor(),i=this.getPlaceholder(),a=this.isDisabled(),o=this.isReadonly(),s=this.isRequired(),c=this.getId(),l=this.getName(),u=this.getAttribute(`value`)||(r?`#000000`:``),d=this.getRows(),f=this.getIcon(),p=this.getLabel(),m=this.getInfo(),h=this.isLoading();if(r&&this._renderSkeleton(h),r){this._input&&=(this._input.remove(),null),this._textarea&&=(this._textarea.remove(),null),this._wrapper||(this._wrapper=document.createElement(`div`),this._wrapper.className=`mint-input-wrapper`,this.appendChild(this._wrapper)),this._colorContainer&&=(this._colorContainer.remove(),null),this._colorPickerWrapper&&!r&&(this._colorPickerWrapper.remove(),this._colorPickerWrapper=null),this._colorPickerWrapper||(this._colorPickerWrapper=document.createElement(`div`),this._colorPickerWrapper.className=`mint-color-picker-wrapper`,this._wrapper.appendChild(this._colorPickerWrapper),this._colorPicker=document.createElement(`input`),this._colorPicker.type=`color`,this._colorPicker.className=`mint-color-picker`,this._colorPickerWrapper.appendChild(this._colorPicker),this._focusHandler=e=>{this._colorPickerWrapper&&this._colorPicker&&this._colorPicker.matches(`:focus-visible`)&&requestAnimationFrame(()=>{this._colorPicker&&this._colorPicker.matches(`:focus-visible`)&&this._colorPickerWrapper?.classList.add(`is-focused`)})},this._blurHandler=()=>{this._colorPickerWrapper&&this._colorPickerWrapper.classList.remove(`is-focused`)},this._colorPicker.addEventListener(`focus`,this._focusHandler),this._colorPicker.addEventListener(`blur`,this._blurHandler),this._colorPicker.addEventListener(`input`,()=>{let e=this._colorPicker?.value||`#000000`;this._colorTextInput&&(this._colorTextInput.value=e),this.setAttribute(`value`,e),this.dispatchEvent(new CustomEvent(`input`,{detail:{value:e},bubbles:!0,cancelable:!0}))}),this._colorPicker.addEventListener(`change`,()=>{let e=this._colorPicker?.value||`#000000`;this.setAttribute(`value`,e),this.dispatchEvent(new CustomEvent(`change`,{detail:{value:e},bubbles:!0,cancelable:!0}))})),this._colorTextInput||(this._colorTextInput=document.createElement(`input`),this._colorTextInput.type=`text`,this._colorTextInput.className=this.getInputClasses(),this._colorTextInput.placeholder=i||`#000000`,this._colorTextInput.pattern=`^#[0-9A-Fa-f]{6}$`,this._wrapper.appendChild(this._colorTextInput),this._colorTextInput.addEventListener(`input`,()=>{let e=this._colorTextInput?.value||``;/^#[0-9A-Fa-f]{6}$/.test(e)&&(this._colorPicker&&(this._colorPicker.value=e),this.setAttribute(`value`,e),this.dispatchEvent(new CustomEvent(`input`,{detail:{value:e},bubbles:!0,cancelable:!0})))}),this._colorTextInput.addEventListener(`blur`,()=>{let e=this._colorTextInput?.value||``;/^#[0-9A-Fa-f]{6}$/.test(e)?(this._colorPicker&&(this._colorPicker.value=e),this.setAttribute(`value`,e)):this._colorPicker&&this._colorTextInput&&(this._colorTextInput.value=this._colorPicker.value),this.dispatchEvent(new CustomEvent(`change`,{detail:{value:this._colorPicker?.value||`#000000`},bubbles:!0,cancelable:!0}))}));let e=u||`#000000`;if(this._colorPicker&&this._colorPicker.value!==e&&(this._colorPicker.value=e),this._colorTextInput&&this._colorTextInput.value!==e&&(this._colorTextInput.value=e),this._colorPicker&&(this._colorPicker.disabled=a),this._colorPickerWrapper&&(a?this._colorPickerWrapper.classList.add(`is-disabled`):this._colorPickerWrapper.classList.remove(`is-disabled`)),this._colorTextInput&&(this._colorTextInput.disabled=a,this._colorTextInput.readOnly=o,this._colorTextInput.required=s),this._colorTextInput){let e=this._colorTextInput;c?e.id=c:e.removeAttribute(`id`),l?e.name=l:e.removeAttribute(`name`),e.setAttribute(`aria-invalid`,this.hasError()?`true`:`false`),this._element=e}this._renderErrorState();let t=this.querySelector(`.mint-input-label-container`);if(p||m){t||(t=document.createElement(`div`),t.className=`mint-input-label-container`,this._wrapper&&this._wrapper.parentElement===this?this.insertBefore(t,this._wrapper):this.insertBefore(t,this.firstChild));let e=t.querySelector(`.mint-input-label`);if(p){e||(e=document.createElement(`label`),e.className=`mint-input-label`,t.insertBefore(e,t.firstChild)),e.textContent=p;let n=c||this._colorTextInput?.id;if(n)e.setAttribute(`for`,n);else{let t=`mint-input-${Math.random().toString(36).substr(2,9)}`;this._colorTextInput&&(this._colorTextInput.id=t),e.setAttribute(`for`,t)}a?e.classList.add(`is-disabled`):e.classList.remove(`is-disabled`)}else e&&e.remove();let n=t.querySelector(`.mint-input-info`);m?(n||(n=document.createElement(`span`),n.className=`mint-input-info`,t.appendChild(n)),n.textContent=m,a?n.classList.add(`is-disabled`):n.classList.remove(`is-disabled`)):n&&n.remove()}else t&&t.remove();return}if(this._wrapper||(this._wrapper=document.createElement(`div`),this._wrapper.className=`mint-input-wrapper`,this.appendChild(this._wrapper)),this._colorContainer&&(this._colorContainer.remove(),this._colorContainer=null,this._colorPicker=null,this._colorTextInput=null),this._colorPickerWrapper&&!r&&(this._colorPickerWrapper.remove(),this._colorPickerWrapper=null,this._colorPicker=null,this._colorTextInput=null),f&&!t?this._icon?this._icon.setAttribute(`name`,f):(this._icon=document.createElement(`mint-icon`),this._icon.setAttribute(`name`,f),this._icon.className=`mint-input-icon`,this._wrapper.appendChild(this._icon)):this._icon&&=(this._icon.remove(),null),this._syncSlotAdornments(t,!!f),this._isNumber()&&!t){if(!this._numberSpinnerContainer){this._numberSpinnerContainer=document.createElement(`div`),this._numberSpinnerContainer.className=`mint-input-spinner`,this._wrapper.appendChild(this._numberSpinnerContainer),this._numberIncrementButton=document.createElement(`button`),this._numberIncrementButton.type=`button`,this._numberIncrementButton.className=`mint-input-spinner-button`;let e=document.createElement(`mint-icon`);e.setAttribute(`name`,`caret-up`),e.className=`mint-input-spinner-icon`,this._numberIncrementButton.appendChild(e),this._numberSpinnerContainer.appendChild(this._numberIncrementButton),this._numberDecrementButton=document.createElement(`button`),this._numberDecrementButton.type=`button`,this._numberDecrementButton.className=`mint-input-spinner-button`;let t=document.createElement(`mint-icon`);t.setAttribute(`name`,`caret-down`),t.className=`mint-input-spinner-icon`,this._numberDecrementButton.appendChild(t),this._numberSpinnerContainer.appendChild(this._numberDecrementButton),this._numberIncrementButton.addEventListener(`click`,e=>{if(e.preventDefault(),e.stopPropagation(),this._input&&!this._input.disabled&&!this._input.readOnly){let e=parseFloat(this._input.value)||0,t=parseFloat(this._input.step)||1,n=this._input.min?parseFloat(this._input.min):void 0,r=this._input.max?parseFloat(this._input.max):void 0,i=e+t;r!==void 0&&i>r&&(i=r),n!==void 0&&i<n&&(i=n),this._input.value=i.toString(),this.setAttribute(`value`,i.toString()),this._input.dispatchEvent(new Event(`input`,{bubbles:!0})),this._input.dispatchEvent(new Event(`change`,{bubbles:!0}))}}),this._numberDecrementButton.addEventListener(`click`,e=>{if(e.preventDefault(),e.stopPropagation(),this._input&&!this._input.disabled&&!this._input.readOnly){let e=parseFloat(this._input.value)||0,t=parseFloat(this._input.step)||1,n=this._input.min?parseFloat(this._input.min):void 0,r=this._input.max?parseFloat(this._input.max):void 0,i=e-t;n!==void 0&&i<n&&(i=n),r!==void 0&&i>r&&(i=r),this._input.value=i.toString(),this.setAttribute(`value`,i.toString()),this._input.dispatchEvent(new Event(`input`,{bubbles:!0})),this._input.dispatchEvent(new Event(`change`,{bubbles:!0}))}})}this._numberIncrementButton&&(this._numberIncrementButton.disabled=a||o),this._numberDecrementButton&&(this._numberDecrementButton.disabled=a||o)}else this._numberSpinnerContainer&&(this._numberSpinnerContainer.remove(),this._numberSpinnerContainer=null,this._numberIncrementButton=null,this._numberDecrementButton=null);if(t){if(this._input&&=(this._input.remove(),null),this._textarea||(this._textarea=document.createElement(`textarea`),this._element=this._textarea,this._wrapper.appendChild(this._textarea),this.setupEventListeners()),this._element=this._textarea,this._textarea.placeholder=i,this._textarea.disabled=a,this._textarea.readOnly=o,this._textarea.required=s,this._textarea.rows=d,this._textarea.setAttribute(`aria-invalid`,this.hasError()?`true`:`false`),u!==this._textarea.value&&(this._textarea.value=u),c?this._textarea.id=c:this._textarea.removeAttribute(`id`),l?this._textarea.name=l:this._textarea.removeAttribute(`name`),this._textarea.className=this.getInputClasses(),this.firstChild&&this.firstChild!==this._wrapper&&this.firstChild.nodeType===Node.TEXT_NODE){let e=this.firstChild.textContent;e&&!this._textarea.value&&(this._textarea.value=e.trim()),this.removeChild(this.firstChild)}}else if(this._textarea&&=(this._textarea.remove(),null),this._input||(this._input=document.createElement(`input`),this._element=this._input,this._wrapper.appendChild(this._input),this.setupEventListeners()),this._element=this._input,this._input.type=e,this._input.placeholder=i,this._input.disabled=a,this._input.readOnly=o,this._input.required=s,this._input.setAttribute(`aria-invalid`,this.hasError()?`true`:`false`),n?(this._input.inputMode=`decimal`,this._input.pattern=`[0-9]*\\.?[0-9]*`):(this._input.removeAttribute(`inputmode`),this._input.removeAttribute(`pattern`)),u!==this._input.value&&(this._input.value=u),c?this._input.id=c:this._input.removeAttribute(`id`),l?this._input.name=l:this._input.removeAttribute(`name`),this._input.className=this.getInputClasses(),this.firstChild&&this.firstChild!==this._wrapper&&this.firstChild.nodeType===Node.TEXT_NODE){let e=this.firstChild.textContent;e&&!this._input.value&&(this._input.value=e.trim()),this.removeChild(this.firstChild)}let g=this.querySelector(`.mint-input-label-container`);if(p||m){g||(g=document.createElement(`div`),g.className=`mint-input-label-container`,this._wrapper&&this._wrapper.parentElement===this?this.insertBefore(g,this._wrapper):this.insertBefore(g,this.firstChild));let e=g.querySelector(`.mint-input-label`);if(p){e||(e=document.createElement(`label`),e.className=`mint-input-label`,g.insertBefore(e,g.firstChild)),e.textContent=p;let t=c||this._element?.id||this._colorTextInput?.id||this._input?.id||this._textarea?.id;if(t)e.setAttribute(`for`,t);else{let t=`mint-input-${Math.random().toString(36).substr(2,9)}`;this._element?this._element.id=t:this._colorTextInput?this._colorTextInput.id=t:this._input?this._input.id=t:this._textarea&&(this._textarea.id=t),e.setAttribute(`for`,t)}a?e.classList.add(`is-disabled`):e.classList.remove(`is-disabled`)}else e&&e.remove();let t=g.querySelector(`.mint-input-info`);m?(t||(t=document.createElement(`span`),t.className=`mint-input-info`,g.appendChild(t)),t.textContent=m,a?t.classList.add(`is-disabled`):t.classList.remove(`is-disabled`)):t&&t.remove()}else g&&g.remove();this._syncSlotAdornments(t,!!f),this._renderErrorState(),this._syncControlAccessibility(),this._renderSkeleton(h)}_renderErrorState(){let e=this.hasError(),t=this.getErrorMessage(),n=this.querySelector(`.mint-input-error`);e&&t?(n||(n=document.createElement(`div`),n.className=`mint-input-error`,this.appendChild(n)),n.textContent=t):n&&n.remove()}_syncControlAccessibility(){let e=this._element;if(!e)return;this._a11yId||=this.getId()||`mint-input-${Math.random().toString(36).slice(2,10)}`;let t=this.getAttribute(`aria-label`)?.trim(),n=!!this.querySelector(`.mint-input-label`);t?e.setAttribute(`aria-label`,t):!n&&this.getAttribute(`placeholder`)?.trim()?e.setAttribute(`aria-label`,this.getAttribute(`placeholder`).trim()):e.removeAttribute(`aria-label`);let r=this.querySelector(`.mint-input-info`),i=this.querySelector(`.mint-input-error`),a=(this.getAttribute(`aria-describedby`)||``).split(/\s+/).filter(Boolean);r&&(r.id=`${this._a11yId}-info`,a.push(r.id)),i&&(i.id=`${this._a11yId}-error`,a.push(i.id)),e.setAttribute(`aria-invalid`,String(this.hasError())),a.length?e.setAttribute(`aria-describedby`,Array.from(new Set(a)).join(` `)):e.removeAttribute(`aria-describedby`);let o=this.getAttribute(`aria-labelledby`)?.trim();o?e.setAttribute(`aria-labelledby`,o):e.removeAttribute(`aria-labelledby`)}setupEventListeners(){this._element&&(this._element.addEventListener(`input`,()=>{let e=this._element?.value||``;e?this.setAttribute(`value`,e):this.removeAttribute(`value`);let t=new Event(`input`,{bubbles:!0,cancelable:!0,composed:!0});this.dispatchEvent(t),this.dispatchEvent(new CustomEvent(`input`,{detail:{value:e},bubbles:!0,cancelable:!0,composed:!0}))}),this._element.addEventListener(`blur`,()=>{let e=this._element?.value||``;e?this.setAttribute(`value`,e):this.removeAttribute(`value`),this.dispatchEvent(new CustomEvent(`change`,{detail:{value:e},bubbles:!0,cancelable:!0}))}))}removeEventListeners(){this._colorPicker&&(this._focusHandler&&=(this._colorPicker.removeEventListener(`focus`,this._focusHandler),null),this._blurHandler&&=(this._colorPicker.removeEventListener(`blur`,this._blurHandler),null))}focus(){this._isColor()&&this._colorTextInput?this._colorTextInput.focus():this._element?.focus()}blur(){this._isColor()&&this._colorTextInput?this._colorTextInput.blur():this._element?.blur()}_renderSkeleton(e){this.classList.toggle(`is-loading`,e);let t=this.querySelector(`.mint-input-skeleton-container`),n=this._wrapper||this.querySelector(`.mint-input-wrapper`);if(e){t||(t=document.createElement(`div`),t.className=`mint-input-skeleton-container`,n?(n.classList.add(`mint-input-positioned`),n.appendChild(t)):(this.classList.add(`mint-input-positioned`),this.appendChild(t)));let e=t.querySelector(`.mint-input-skeleton`);e||(e=document.createElement(`div`),e.className=`mint-input-skeleton`,t.appendChild(e)),e.parentElement||t.appendChild(e)}}};customElements.get(`mint-input`)||e.t(`mint-input`,t),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return t}});
|
|
1
|
+
require(`./icon-B_7c8b8e.js`);const e=require(`./register-element-tCL_F1YI.js`);require(`./icon-CSqBgTae.js`),require(`./caret-up-hwsMK8n3.js`),require(`./caret-down-CeADWana.js`);var t=class extends HTMLElement{static get observedAttributes(){return[`type`,`placeholder`,`value`,`disabled`,`id`,`name`,`required`,`readonly`,`rows`,`icon`,`label`,`info`,`error`,`error-message`,`loading`,`aria-label`,`aria-labelledby`,`aria-describedby`]}constructor(){super(),this._input=null,this._textarea=null,this._element=null,this._wrapper=null,this._icon=null,this._prependSlotContainer=null,this._appendSlotContainer=null,this._colorPicker=null,this._colorTextInput=null,this._colorContainer=null,this._colorPickerWrapper=null,this._numberSpinnerContainer=null,this._numberIncrementButton=null,this._numberDecrementButton=null,this._contentObserver=null,this._focusHandler=null,this._a11yId=``,this._blurHandler=null,this._clickHandler=null,this._clickOutsideHandler=null,this._renderFrame=null}connectedCallback(){this.classList.add(`mint-input-host`),this.render(),this._observeContentMutations()}disconnectedCallback(){this.removeEventListeners(),this._contentObserver&&=(this._contentObserver.disconnect(),null),this._renderFrame!==null&&(cancelAnimationFrame(this._renderFrame),this._renderFrame=null)}attributeChangedCallback(e,t,n){if(t!==n){if(e===`error`||e===`error-message`){this._renderErrorState(),this._syncControlAccessibility(),this._element&&(this._element.className=this.getInputClasses()),this._colorTextInput&&(this._colorTextInput.className=this.getInputClasses());return}if(e===`loading`){this.render();return}this.render()}}_scheduleRender(){this._renderFrame===null&&(this._renderFrame=requestAnimationFrame(()=>{this._renderFrame=null,this.render()}))}_observeContentMutations(){this._contentObserver||=new MutationObserver(()=>{this._scheduleRender()}),this._contentObserver.disconnect(),this._contentObserver.observe(this,{childList:!0,attributes:!0,attributeFilter:[`slot`]})}getType(){return this.getAttribute(`type`)||`text`}getRows(){let e=this.getAttribute(`rows`);return e?parseInt(e,10):3}_getNormalizedType(){let e=this.getType();return e===`datetime`?`datetime-local`:e===`money`?`text`:e===`textarea`?`textarea`:e}_isTextarea(){return this.getType()===`textarea`}_isMoney(){return this.getType()===`money`}_isColor(){return this.getType()===`color`}_isNumber(){return this.getType()===`number`}getPlaceholder(){return this.getAttribute(`placeholder`)||``}getValue(){return this._isColor()?this._colorTextInput?this._colorTextInput.value:this._colorPicker?this._colorPicker.value:this.getAttribute(`value`)||`#000000`:this._element?this._element.value:this.getAttribute(`value`)||``}set value(e){try{this._isColor()?(this._colorPicker&&(this._colorPicker.value=e||`#000000`),this._colorTextInput&&(this._colorTextInput.value=e||`#000000`)):this._element&&(this._element.value=e),e?this.setAttribute(`value`,e):this.removeAttribute(`value`)}catch{}}get value(){try{return this.getValue()||``}catch{return``}}isDisabled(){return this.getAttribute(`disabled`)===`true`}isReadonly(){return this.getAttribute(`readonly`)===`true`}isRequired(){return this.getAttribute(`required`)===`true`}hasError(){return this.getAttribute(`error`)===`true`}getErrorMessage(){return this.getAttribute(`error-message`)||``}getId(){return this.getAttribute(`id`)||``}getName(){return this.getAttribute(`name`)||``}getIcon(){return this.getAttribute(`icon`)||``}getLabel(){return this.getAttribute(`label`)||``}getInfo(){return this.getAttribute(`info`)||``}getInputClasses(){let e=this._isTextarea(),t=!!this.getIcon(),n=this.querySelector(`[slot="prepend"]`)!==null,r=this.querySelector(`[slot="append"]`)!==null,i=this._isColor(),a=this._isNumber(),o=this.hasError();return[`mint-input-control`,e&&`is-textarea`,t&&`has-icon`,i&&`is-color`,n&&`has-prepend`,r&&`has-append`,a&&`is-number`,o&&`has-error`].filter(Boolean).join(` `)}_syncSlotAdornments(e,t){if(!this._wrapper||e||this._isColor()){this._prependSlotContainer&&=(this._prependSlotContainer.remove(),null),this._appendSlotContainer&&=(this._appendSlotContainer.remove(),null);return}this._prependSlotContainer||(this._prependSlotContainer=document.createElement(`div`),this._prependSlotContainer.className=`mint-input-adornment mint-input-prepend-slot`,this._wrapper.appendChild(this._prependSlotContainer)),this._appendSlotContainer||(this._appendSlotContainer=document.createElement(`div`),this._appendSlotContainer.className=`mint-input-adornment mint-input-append-slot`,this._wrapper.appendChild(this._appendSlotContainer)),this._prependSlotContainer.classList.toggle(`has-icon-offset`,t);let n=Array.from(this.querySelectorAll(`[slot="prepend"]`)),r=Array.from(this.querySelectorAll(`[slot="append"]`));this._prependSlotContainer.replaceChildren(),this._appendSlotContainer.replaceChildren(),n.forEach(e=>this._prependSlotContainer.appendChild(e)),r.forEach(e=>this._appendSlotContainer.appendChild(e)),this._prependSlotContainer.classList.toggle(`is-hidden`,n.length===0),this._appendSlotContainer.classList.toggle(`is-hidden`,r.length===0)}isLoading(){return this.getAttribute(`loading`)===`true`}render(){this.getType();let e=this._getNormalizedType(),t=this._isTextarea(),n=this._isMoney(),r=this._isColor(),i=this.getPlaceholder(),a=this.isDisabled(),o=this.isReadonly(),s=this.isRequired(),c=this.getId(),l=this.getName(),u=this.getAttribute(`value`)||(r?`#000000`:``),d=this.getRows(),f=this.getIcon(),p=this.getLabel(),m=this.getInfo(),h=this.isLoading();if(r&&this._renderSkeleton(h),r){this._input&&=(this._input.remove(),null),this._textarea&&=(this._textarea.remove(),null),this._wrapper||(this._wrapper=document.createElement(`div`),this._wrapper.className=`mint-input-wrapper`,this.appendChild(this._wrapper)),this._colorContainer&&=(this._colorContainer.remove(),null),this._colorPickerWrapper&&!r&&(this._colorPickerWrapper.remove(),this._colorPickerWrapper=null),this._colorPickerWrapper||(this._colorPickerWrapper=document.createElement(`div`),this._colorPickerWrapper.className=`mint-color-picker-wrapper`,this._wrapper.appendChild(this._colorPickerWrapper),this._colorPicker=document.createElement(`input`),this._colorPicker.type=`color`,this._colorPicker.className=`mint-color-picker`,this._colorPickerWrapper.appendChild(this._colorPicker),this._focusHandler=e=>{this._colorPickerWrapper&&this._colorPicker&&this._colorPicker.matches(`:focus-visible`)&&requestAnimationFrame(()=>{this._colorPicker&&this._colorPicker.matches(`:focus-visible`)&&this._colorPickerWrapper?.classList.add(`is-focused`)})},this._blurHandler=()=>{this._colorPickerWrapper&&this._colorPickerWrapper.classList.remove(`is-focused`)},this._colorPicker.addEventListener(`focus`,this._focusHandler),this._colorPicker.addEventListener(`blur`,this._blurHandler),this._colorPicker.addEventListener(`input`,()=>{let e=this._colorPicker?.value||`#000000`;this._colorTextInput&&(this._colorTextInput.value=e),this.setAttribute(`value`,e),this.dispatchEvent(new CustomEvent(`input`,{detail:{value:e},bubbles:!0,cancelable:!0}))}),this._colorPicker.addEventListener(`change`,()=>{let e=this._colorPicker?.value||`#000000`;this.setAttribute(`value`,e),this.dispatchEvent(new CustomEvent(`change`,{detail:{value:e},bubbles:!0,cancelable:!0}))})),this._colorTextInput||(this._colorTextInput=document.createElement(`input`),this._colorTextInput.type=`text`,this._colorTextInput.className=this.getInputClasses(),this._colorTextInput.placeholder=i||`#000000`,this._colorTextInput.pattern=`^#[0-9A-Fa-f]{6}$`,this._wrapper.appendChild(this._colorTextInput),this._colorTextInput.addEventListener(`input`,()=>{let e=this._colorTextInput?.value||``;/^#[0-9A-Fa-f]{6}$/.test(e)&&(this._colorPicker&&(this._colorPicker.value=e),this.setAttribute(`value`,e),this.dispatchEvent(new CustomEvent(`input`,{detail:{value:e},bubbles:!0,cancelable:!0})))}),this._colorTextInput.addEventListener(`blur`,()=>{let e=this._colorTextInput?.value||``;/^#[0-9A-Fa-f]{6}$/.test(e)?(this._colorPicker&&(this._colorPicker.value=e),this.setAttribute(`value`,e)):this._colorPicker&&this._colorTextInput&&(this._colorTextInput.value=this._colorPicker.value),this.dispatchEvent(new CustomEvent(`change`,{detail:{value:this._colorPicker?.value||`#000000`},bubbles:!0,cancelable:!0}))}));let e=u||`#000000`;if(this._colorPicker&&this._colorPicker.value!==e&&(this._colorPicker.value=e),this._colorTextInput&&this._colorTextInput.value!==e&&(this._colorTextInput.value=e),this._colorPicker&&(this._colorPicker.disabled=a),this._colorPickerWrapper&&(a?this._colorPickerWrapper.classList.add(`is-disabled`):this._colorPickerWrapper.classList.remove(`is-disabled`)),this._colorTextInput&&(this._colorTextInput.disabled=a,this._colorTextInput.readOnly=o,this._colorTextInput.required=s),this._colorTextInput){let e=this._colorTextInput;c?e.id=c:e.removeAttribute(`id`),l?e.name=l:e.removeAttribute(`name`),e.setAttribute(`aria-invalid`,this.hasError()?`true`:`false`),this._element=e}this._renderErrorState();let t=this.querySelector(`.mint-input-label-container`);if(p||m){t||(t=document.createElement(`div`),t.className=`mint-input-label-container`,this._wrapper&&this._wrapper.parentElement===this?this.insertBefore(t,this._wrapper):this.insertBefore(t,this.firstChild));let e=t.querySelector(`.mint-input-label`);if(p){e||(e=document.createElement(`label`),e.className=`mint-input-label`,t.insertBefore(e,t.firstChild)),e.textContent=p;let n=c||this._colorTextInput?.id;if(n)e.setAttribute(`for`,n);else{let t=`mint-input-${Math.random().toString(36).substr(2,9)}`;this._colorTextInput&&(this._colorTextInput.id=t),e.setAttribute(`for`,t)}a?e.classList.add(`is-disabled`):e.classList.remove(`is-disabled`)}else e&&e.remove();let n=t.querySelector(`.mint-input-info`);m?(n||(n=document.createElement(`span`),n.className=`mint-input-info`,t.appendChild(n)),n.textContent=m,a?n.classList.add(`is-disabled`):n.classList.remove(`is-disabled`)):n&&n.remove()}else t&&t.remove();return}if(this._wrapper||(this._wrapper=document.createElement(`div`),this._wrapper.className=`mint-input-wrapper`,this.appendChild(this._wrapper)),this._colorContainer&&(this._colorContainer.remove(),this._colorContainer=null,this._colorPicker=null,this._colorTextInput=null),this._colorPickerWrapper&&!r&&(this._colorPickerWrapper.remove(),this._colorPickerWrapper=null,this._colorPicker=null,this._colorTextInput=null),f&&!t?this._icon?this._icon.setAttribute(`name`,f):(this._icon=document.createElement(`mint-icon`),this._icon.setAttribute(`name`,f),this._icon.className=`mint-input-icon`,this._wrapper.appendChild(this._icon)):this._icon&&=(this._icon.remove(),null),this._syncSlotAdornments(t,!!f),this._isNumber()&&!t){if(!this._numberSpinnerContainer){this._numberSpinnerContainer=document.createElement(`div`),this._numberSpinnerContainer.className=`mint-input-spinner`,this._wrapper.appendChild(this._numberSpinnerContainer),this._numberIncrementButton=document.createElement(`button`),this._numberIncrementButton.type=`button`,this._numberIncrementButton.className=`mint-input-spinner-button`;let e=document.createElement(`mint-icon`);e.setAttribute(`name`,`caret-up`),e.className=`mint-input-spinner-icon`,this._numberIncrementButton.appendChild(e),this._numberSpinnerContainer.appendChild(this._numberIncrementButton),this._numberDecrementButton=document.createElement(`button`),this._numberDecrementButton.type=`button`,this._numberDecrementButton.className=`mint-input-spinner-button`;let t=document.createElement(`mint-icon`);t.setAttribute(`name`,`caret-down`),t.className=`mint-input-spinner-icon`,this._numberDecrementButton.appendChild(t),this._numberSpinnerContainer.appendChild(this._numberDecrementButton),this._numberIncrementButton.addEventListener(`click`,e=>{if(e.preventDefault(),e.stopPropagation(),this._input&&!this._input.disabled&&!this._input.readOnly){let e=parseFloat(this._input.value)||0,t=parseFloat(this._input.step)||1,n=this._input.min?parseFloat(this._input.min):void 0,r=this._input.max?parseFloat(this._input.max):void 0,i=e+t;r!==void 0&&i>r&&(i=r),n!==void 0&&i<n&&(i=n),this._input.value=i.toString(),this.setAttribute(`value`,i.toString()),this._input.dispatchEvent(new Event(`input`,{bubbles:!0})),this._input.dispatchEvent(new Event(`change`,{bubbles:!0}))}}),this._numberDecrementButton.addEventListener(`click`,e=>{if(e.preventDefault(),e.stopPropagation(),this._input&&!this._input.disabled&&!this._input.readOnly){let e=parseFloat(this._input.value)||0,t=parseFloat(this._input.step)||1,n=this._input.min?parseFloat(this._input.min):void 0,r=this._input.max?parseFloat(this._input.max):void 0,i=e-t;n!==void 0&&i<n&&(i=n),r!==void 0&&i>r&&(i=r),this._input.value=i.toString(),this.setAttribute(`value`,i.toString()),this._input.dispatchEvent(new Event(`input`,{bubbles:!0})),this._input.dispatchEvent(new Event(`change`,{bubbles:!0}))}})}this._numberIncrementButton&&(this._numberIncrementButton.disabled=a||o),this._numberDecrementButton&&(this._numberDecrementButton.disabled=a||o)}else this._numberSpinnerContainer&&(this._numberSpinnerContainer.remove(),this._numberSpinnerContainer=null,this._numberIncrementButton=null,this._numberDecrementButton=null);if(t){if(this._input&&=(this._input.remove(),null),this._textarea||(this._textarea=document.createElement(`textarea`),this._element=this._textarea,this._wrapper.appendChild(this._textarea),this.setupEventListeners()),this._element=this._textarea,this._textarea.placeholder=i,this._textarea.disabled=a,this._textarea.readOnly=o,this._textarea.required=s,this._textarea.rows=d,this._textarea.setAttribute(`aria-invalid`,this.hasError()?`true`:`false`),u!==this._textarea.value&&(this._textarea.value=u),c?this._textarea.id=c:this._textarea.removeAttribute(`id`),l?this._textarea.name=l:this._textarea.removeAttribute(`name`),this._textarea.className=this.getInputClasses(),this.firstChild&&this.firstChild!==this._wrapper&&this.firstChild.nodeType===Node.TEXT_NODE){let e=this.firstChild.textContent;e&&!this._textarea.value&&(this._textarea.value=e.trim()),this.removeChild(this.firstChild)}}else if(this._textarea&&=(this._textarea.remove(),null),this._input||(this._input=document.createElement(`input`),this._element=this._input,this._wrapper.appendChild(this._input),this.setupEventListeners()),this._element=this._input,this._input.type=e,this._input.placeholder=i,this._input.disabled=a,this._input.readOnly=o,this._input.required=s,this._input.setAttribute(`aria-invalid`,this.hasError()?`true`:`false`),n?(this._input.inputMode=`decimal`,this._input.pattern=`[0-9]*\\.?[0-9]*`):(this._input.removeAttribute(`inputmode`),this._input.removeAttribute(`pattern`)),u!==this._input.value&&(this._input.value=u),c?this._input.id=c:this._input.removeAttribute(`id`),l?this._input.name=l:this._input.removeAttribute(`name`),this._input.className=this.getInputClasses(),this.firstChild&&this.firstChild!==this._wrapper&&this.firstChild.nodeType===Node.TEXT_NODE){let e=this.firstChild.textContent;e&&!this._input.value&&(this._input.value=e.trim()),this.removeChild(this.firstChild)}let g=this.querySelector(`.mint-input-label-container`);if(p||m){g||(g=document.createElement(`div`),g.className=`mint-input-label-container`,this._wrapper&&this._wrapper.parentElement===this?this.insertBefore(g,this._wrapper):this.insertBefore(g,this.firstChild));let e=g.querySelector(`.mint-input-label`);if(p){e||(e=document.createElement(`label`),e.className=`mint-input-label`,g.insertBefore(e,g.firstChild)),e.textContent=p;let t=c||this._element?.id||this._colorTextInput?.id||this._input?.id||this._textarea?.id;if(t)e.setAttribute(`for`,t);else{let t=`mint-input-${Math.random().toString(36).substr(2,9)}`;this._element?this._element.id=t:this._colorTextInput?this._colorTextInput.id=t:this._input?this._input.id=t:this._textarea&&(this._textarea.id=t),e.setAttribute(`for`,t)}a?e.classList.add(`is-disabled`):e.classList.remove(`is-disabled`)}else e&&e.remove();let t=g.querySelector(`.mint-input-info`);m?(t||(t=document.createElement(`span`),t.className=`mint-input-info`,g.appendChild(t)),t.textContent=m,a?t.classList.add(`is-disabled`):t.classList.remove(`is-disabled`)):t&&t.remove()}else g&&g.remove();this._syncSlotAdornments(t,!!f),this._renderErrorState(),this._syncControlAccessibility(),this._renderSkeleton(h)}_renderErrorState(){let e=this.hasError(),t=this.getErrorMessage(),n=this.querySelector(`.mint-input-error`);e&&t?(n||(n=document.createElement(`div`),n.className=`mint-input-error`,this.appendChild(n)),n.textContent=t):n&&n.remove()}_syncControlAccessibility(){let e=this._element;if(!e)return;this._a11yId||=this.getId()||`mint-input-${Math.random().toString(36).slice(2,10)}`;let t=this.getAttribute(`aria-label`)?.trim(),n=!!this.querySelector(`.mint-input-label`);t?e.setAttribute(`aria-label`,t):!n&&this.getAttribute(`placeholder`)?.trim()?e.setAttribute(`aria-label`,this.getAttribute(`placeholder`).trim()):e.removeAttribute(`aria-label`);let r=this.querySelector(`.mint-input-info`),i=this.querySelector(`.mint-input-error`),a=(this.getAttribute(`aria-describedby`)||``).split(/\s+/).filter(Boolean);r&&(r.id=`${this._a11yId}-info`,a.push(r.id)),i&&(i.id=`${this._a11yId}-error`,a.push(i.id)),e.setAttribute(`aria-invalid`,String(this.hasError())),a.length?e.setAttribute(`aria-describedby`,Array.from(new Set(a)).join(` `)):e.removeAttribute(`aria-describedby`);let o=this.getAttribute(`aria-labelledby`)?.trim();o?e.setAttribute(`aria-labelledby`,o):e.removeAttribute(`aria-labelledby`)}setupEventListeners(){this._element&&(this._element.addEventListener(`input`,()=>{let e=this._element?.value||``;e?this.setAttribute(`value`,e):this.removeAttribute(`value`);let t=new Event(`input`,{bubbles:!0,cancelable:!0,composed:!0});this.dispatchEvent(t),this.dispatchEvent(new CustomEvent(`input`,{detail:{value:e},bubbles:!0,cancelable:!0,composed:!0}))}),this._element.addEventListener(`blur`,()=>{let e=this._element?.value||``;e?this.setAttribute(`value`,e):this.removeAttribute(`value`),this.dispatchEvent(new CustomEvent(`change`,{detail:{value:e},bubbles:!0,cancelable:!0}))}))}removeEventListeners(){this._colorPicker&&(this._focusHandler&&=(this._colorPicker.removeEventListener(`focus`,this._focusHandler),null),this._blurHandler&&=(this._colorPicker.removeEventListener(`blur`,this._blurHandler),null))}focus(){this._isColor()&&this._colorTextInput?this._colorTextInput.focus():this._element?.focus()}blur(){this._isColor()&&this._colorTextInput?this._colorTextInput.blur():this._element?.blur()}_renderSkeleton(e){this.classList.toggle(`is-loading`,e);let t=this.querySelector(`.mint-input-skeleton-container`),n=this._wrapper||this.querySelector(`.mint-input-wrapper`);if(e){t||(t=document.createElement(`div`),t.className=`mint-input-skeleton-container`,n?(n.classList.add(`mint-input-positioned`),n.appendChild(t)):(this.classList.add(`mint-input-positioned`),this.appendChild(t)));let e=t.querySelector(`.mint-input-skeleton`);e||(e=document.createElement(`div`),e.className=`mint-input-skeleton`,t.appendChild(e)),e.parentElement||t.appendChild(e)}}};customElements.get(`mint-input`)||e.t(`mint-input`,t),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return t}});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
require(`./icon-
|
|
1
|
+
require(`./icon-B_7c8b8e.js`);const e=require(`./register-element-tCL_F1YI.js`);require(`./text-Cpl5ljSe.js`),require(`./button-DbxqmBWQ.js`),require(`./stack-D1uh4L79.js`);var t=class extends HTMLElement{static get observedAttributes(){return[`id`,`heading`,`open`]}constructor(){super(),this._overlay=null,this._modal=null,this._header=null,this._headingSlot=null,this._bodySlot=null,this._actionsSlot=null,this._closeButton=null,this._triggerElement=null,this._triggerPoint=null,this._renderedOpen=!1,this._lastPointerPoint=null,this._pointerDownHandler=null,this._darkModeObserver=null,this._exitTimer=null,this._backdropTimer=null}connectedCallback(){this.isOpen()||this.classList.add(`mint-hidden`),this.render(),this._observeDarkMode(),this._pointerDownHandler=e=>{this._lastPointerPoint={x:e.clientX,y:e.clientY,target:e.target,time:Date.now()}},document.addEventListener(`pointerdown`,this._pointerDownHandler,!0)}disconnectedCallback(){this._pointerDownHandler&&=(document.removeEventListener(`pointerdown`,this._pointerDownHandler,!0),null),this._exitTimer&&=(clearTimeout(this._exitTimer),null),this._backdropTimer&&=(clearTimeout(this._backdropTimer),null),this._darkModeObserver&&=(this._darkModeObserver.disconnect(),null)}attributeChangedCallback(e,t,n){t!==n&&(e===`open`&&n!==null&&!this._triggerElement&&(this._triggerElement=this._findTriggerElement(),this._triggerPoint=this._findTriggerPoint(this._triggerElement)),this.render())}getId(){return this.getAttribute(`id`)||``}getHeading(){return this.getAttribute(`heading`)||``}isOpen(){return this.hasAttribute(`open`)}open(e){this._triggerElement=this._findTriggerElement(e),this._triggerPoint=this._findTriggerPoint(this._triggerElement),this.setAttribute(`open`,``)}close(){this.removeAttribute(`open`)}render(){let e=this.getId(),t=this.getHeading(),n=this.isOpen();if(e&&(this.id=e),this._overlay||(this._overlay=document.createElement(`div`),this._overlay.className=`mint-modal-overlay`,this._overlay.addEventListener(`click`,()=>this.close()),this.appendChild(this._overlay)),this._modal||(this._modal=document.createElement(`div`),this._modal.className=`mint-modal-shell`,this.appendChild(this._modal)),n){let e=this._modal.querySelector(`.modal-content`);e||(e=document.createElement(`div`),e.className=`modal-content`,this._modal.appendChild(e)),this._renderedOpen||(this._renderedOpen=!0,this._animateEnter())}else this._renderedOpen&&(this._renderedOpen=!1,this._animateExit());let r=this._modal.querySelector(`.modal-content`);r||(r=document.createElement(`div`),r.className=`modal-content`,this._modal.appendChild(r)),this._header||(this._header=document.createElement(`div`),this._header.className=`mint-modal-header`,r.appendChild(this._header)),this._headingSlot||(this._headingSlot=document.createElement(`div`),this._headingSlot.className=`mint-modal-heading`,this._headingSlot.setAttribute(`slot`,`heading`),this._header.appendChild(this._headingSlot));let i=this._headingSlot.querySelector(`mint-text`);t?(i||(i=document.createElement(`mint-text`),i.setAttribute(`size`,`sub-heading`),i.setAttribute(`bold`,``),this._headingSlot.appendChild(i)),i.textContent=t):i&&i.remove(),Array.from(this.children).filter(e=>e!==this._overlay&&e!==this._modal&&e!==this._headingSlot&&e.getAttribute(`slot`)===`heading`).forEach(e=>{e.parentElement!==this._headingSlot&&this._headingSlot.appendChild(e)}),this._closeButton||(this._closeButton=document.createElement(`mint-button`),this._closeButton.setAttribute(`variant`,`ghost`),this._closeButton.setAttribute(`icon`,`close`),this._closeButton.addEventListener(`click`,()=>this.close()),this._header.appendChild(this._closeButton)),this._bodySlot||(this._bodySlot=document.createElement(`div`),this._bodySlot.className=`mint-modal-body`,this._bodySlot.setAttribute(`slot`,`body`),r.appendChild(this._bodySlot)),Array.from(this.children).filter(e=>e!==this._overlay&&e!==this._modal&&e!==this._bodySlot&&e.getAttribute(`slot`)===`body`).forEach(e=>{e.parentElement!==this._bodySlot&&this._bodySlot.appendChild(e)}),this._actionsSlot||(this._actionsSlot=document.createElement(`div`),this._actionsSlot.className=`mint-modal-actions`,this._actionsSlot.setAttribute(`slot`,`actions`),r.appendChild(this._actionsSlot));let a=this._actionsSlot.querySelector(`mint-stack`);a||(a=document.createElement(`mint-stack`),a.setAttribute(`direction`,`horizontal`),a.className=`mint-actions-stack`,this._actionsSlot.appendChild(a)),Array.from(this.children).filter(e=>e!==this._overlay&&e!==this._modal&&e!==this._actionsSlot&&e.getAttribute(`slot`)===`actions`).forEach(e=>{Array.from(e.children).forEach(e=>{e.parentElement!==a&&a.appendChild(e)}),e.parentElement&&e.remove()}),Array.from(this.children).forEach(e=>{e!==this._overlay&&e!==this._modal&&e.getAttribute(`slot`)!==`heading`&&e.getAttribute(`slot`)!==`body`&&e.getAttribute(`slot`)!==`actions`&&e!==this._headingSlot&&e!==this._bodySlot&&e!==this._actionsSlot&&e.parentElement!==this._bodySlot&&this._bodySlot.appendChild(e)}),this._updateBackgroundColor()}_updateBackgroundColor(){if(!this._modal)return;document.documentElement?.classList.contains(`dark`)||document.documentElement?.dataset.mintTheme;let e=this._modal.querySelector(`.modal-content`);e&&(e.style.background=`var(--mint-color-surface-raised)`)}_observeDarkMode(){if(!this._darkModeObserver){if(this._darkModeObserver=new MutationObserver(()=>{this._updateBackgroundColor()}),!document.documentElement)return;this._darkModeObserver.observe(document.documentElement,{attributes:!0,attributeFilter:[`class`,`data-mint-theme`]})}}_animateEnter(){let e=this._modal?.querySelector(`.modal-content`);e&&(this._exitTimer&&=(clearTimeout(this._exitTimer),null),this._backdropTimer&&=(clearTimeout(this._backdropTimer),null),this.classList.remove(`mint-modal-closing`),this.classList.remove(`mint-modal-open`),this.classList.add(`mint-modal-open`),this.classList.remove(`mint-hidden`),e.style.transform=`none`,e.style.opacity=`0`,e.style.transition=`none`,requestAnimationFrame(()=>{if(!this.isOpen())return;let t=window.getComputedStyle(e).borderRadius;this._setTransformOrigin(e),e.style.borderRadius=`50%`,e.style.transform=`scale(0.1, 0.2)`,e.style.opacity=`0.9`,e.getBoundingClientRect(),e.style.transition=`opacity 320ms ease-out, transform 360ms cubic-bezier(0.2, 0.8, 0.2, 1), border-radius 360ms cubic-bezier(0.2, 0.8, 0.2, 1)`,requestAnimationFrame(()=>{this.isOpen()&&(e.style.transform=`scale(1)`,e.style.opacity=`1`,e.style.borderRadius=t)})}))}_findTriggerElement(e){if(typeof e==`string`){let t=document.getElementById(e);return t&&!this.contains(t)?t:null}if(e instanceof HTMLElement)return e.isConnected&&!this.contains(e)?e:null;let t=this.getAttribute(`trigger-id`);if(t){let e=document.getElementById(t);if(e&&!this.contains(e))return e}let n=document.activeElement;return n instanceof HTMLElement&&n.isConnected&&n!==document.body&&!this.contains(n)?n:null}_findTriggerPoint(e){if(!e)return null;let t=this._lastPointerPoint;if(!t||Date.now()-t.time>1e3)return null;let n=t.target instanceof Node?t.target:null;return n===e||n&&e.contains(n)?{x:t.x,y:t.y}:null}_setTransformOrigin(e){let t=this._findTriggerElement(this._triggerElement);this._triggerElement=t;let n=this._findTriggerPoint(t);if(n){let t=e.getBoundingClientRect();e.style.transformOrigin=`${n.x-t.left}px ${n.y-t.top}px`,this._triggerPoint=n;return}this._triggerPoint={x:window.innerWidth/2,y:0};let r=e.getBoundingClientRect();e.style.transformOrigin=`${this._triggerPoint.x-r.left}px ${this._triggerPoint.y-r.top}px`}_animateExit(){this.classList.remove(`mint-modal-open`),this._backdropTimer&&=(clearTimeout(this._backdropTimer),null);let e=this._modal?.querySelector(`.modal-content`);if(!e){this.classList.add(`mint-hidden`),this.classList.remove(`mint-modal-closing`);return}this._exitTimer&&clearTimeout(this._exitTimer),this.classList.add(`mint-modal-closing`),e.style.transition=`opacity 220ms ease-in, transform 260ms cubic-bezier(0.4, 0, 1, 1), border-radius 260ms cubic-bezier(0.4, 0, 1, 1)`,e.style.borderRadius=`50%`,e.style.transform=`scale(0.1, 0.2)`,e.style.opacity=`0.9`,this._exitTimer=setTimeout(()=>{this._exitTimer=null,!this.isOpen()&&(this.classList.add(`mint-hidden`),this.classList.remove(`mint-modal-closing`),e.style.transform=``,e.style.opacity=``,e.style.borderRadius=``,e.style.transition=``)},280)}};typeof customElements<`u`&&!customElements.get(`mint-modal`)&&e.t(`mint-modal`,t),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return t}});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import "./icon-
|
|
1
|
+
import "./icon-BWUYe89V.js";
|
|
2
2
|
import { t as e } from "./register-element-BFYmIynH.js";
|
|
3
3
|
import "./text-Bmfl6CxJ.js";
|
|
4
|
-
import "./button-
|
|
4
|
+
import "./button-BYQbRAwl.js";
|
|
5
5
|
import "./stack-DyQfjPDh.js";
|
|
6
6
|
//#region src/components/modal/Modal.js
|
|
7
7
|
var t = class extends HTMLElement {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require(`./icon-B_7c8b8e.js`).a({name:`search`,viewBox:`0 0 24 24`,path:`M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z`,strokeLinecap:`round`,strokeLinejoin:`round`});
|
|
@@ -20,8 +20,8 @@ __mintLoadStyle('stack', '../../stack.css')
|
|
|
20
20
|
__mintLoadStyle('confirm-action', '../../confirm-action.css')
|
|
21
21
|
import { t as e } from "../chunks/register-element-BFYmIynH.js";
|
|
22
22
|
import "../chunks/text-Bmfl6CxJ.js";
|
|
23
|
-
import "../chunks/button-
|
|
24
|
-
import "../chunks/modal-
|
|
23
|
+
import "../chunks/button-BYQbRAwl.js";
|
|
24
|
+
import "../chunks/modal-CPcIPIO7.js";
|
|
25
25
|
//#region src/components/confirm-action/ConfirmAction.ts
|
|
26
26
|
var t = class extends HTMLElement {
|
|
27
27
|
constructor(...e) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require(`../chunks/register-element-tCL_F1YI.js`);require(`../chunks/text-Cpl5ljSe.js`),require(`../chunks/button-
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require(`../chunks/register-element-tCL_F1YI.js`);require(`../chunks/text-Cpl5ljSe.js`),require(`../chunks/button-DbxqmBWQ.js`),require(`../chunks/modal-CNBmdA63.js`);var t=class extends HTMLElement{constructor(...e){super(...e),this._modal=null,this._actionsFooter=null,this._confirmButton=null,this._cancelButton=null,this._pendingResolve=null,this._modalObserver=null,this._lastAction=null,this._onConfirmClick=null,this._onCancelClick=null}connectedCallback(){this._ensureModal(),this._observeModalOpenState()}disconnectedCallback(){this._modalObserver&&=(this._modalObserver.disconnect(),null),this._pendingResolve=null}async showConfirm(e){if(this._ensureModal(),!this._modal||!this._confirmButton||!this._cancelButton)return!1;let t=e.question?.trim()||`Are you sure?`,n=e.tone||`action`,r=e.confirmLabel?.trim()||`Confirm`,i=e.cancelLabel?.trim()||`Cancel`;this._lastAction=null,this._modal.setAttribute(`heading`,t),this._cancelButton.className=`mint-button-core mint-button-ghost mint-button-tone-neutral mint-confirm-action-cancel`,this._confirmButton.className=`mint-button-core mint-button-solid mint-button-tone-${n} mint-confirm-action-confirm`,this._confirmButton.textContent=r,this._cancelButton.textContent=i;let a=new Promise(e=>{this._pendingResolve=e});return requestAnimationFrame(()=>{this._modal.open?.(),this._mountActionsFooter()}),a}_ensureModal(){this._modal||(this._modal=document.createElement(`mint-modal`),this._modal.setAttribute(`heading`,`Are you sure?`),this._modal.setAttribute(`size`,`small`),this._cancelButton=document.createElement(`button`),this._cancelButton.type=`button`,this._cancelButton.className=`mint-button-core mint-button-ghost mint-button-tone-neutral mint-confirm-action-cancel`,this._cancelButton.textContent=`Cancel`,this._confirmButton=document.createElement(`button`),this._confirmButton.type=`button`,this._confirmButton.className=`mint-button-core mint-button-solid mint-button-tone-action mint-confirm-action-confirm`,this._confirmButton.textContent=`Confirm`,this._actionsFooter=document.createElement(`div`),this._actionsFooter.className=`mint-confirm-action-footer`,this._actionsFooter.append(this._cancelButton,this._confirmButton),this._onCancelClick=()=>{this._lastAction=`cancel`,this._modal?.close?.()},this._onConfirmClick=()=>{this._lastAction=`confirm`,this._modal?.close?.()},this._cancelButton.addEventListener(`click`,this._onCancelClick),this._confirmButton.addEventListener(`click`,this._onConfirmClick),this.appendChild(this._modal))}_mountActionsFooter(){let e=this._modal?.querySelector(`.modal-content`);!e||!this._actionsFooter||(e.querySelectorAll(`:scope > [slot="body"], :scope > [slot="actions"]`).forEach(e=>{!e.textContent?.trim()&&!e.querySelector(`button, mint-button, a, input, select, textarea`)&&e.remove()}),this._actionsFooter.parentElement!==e&&e.appendChild(this._actionsFooter))}_observeModalOpenState(){!this._modal||this._modalObserver||(this._modalObserver=new MutationObserver(()=>{if((this._modal?.hasAttribute(`open`)??!1)||!this._pendingResolve)return;let e=this._pendingResolve;this._pendingResolve=null;let t=this._lastAction===`confirm`;this._lastAction=null,e(t)}),this._modalObserver.observe(this._modal,{attributes:!0,attributeFilter:[`open`]}))}};customElements.get(`mint-confirm-action`)||e.t(`mint-confirm-action`,t);var n=[],r=!1;function i(){return typeof document>`u`||document.body?Promise.resolve():new Promise(e=>{if(typeof window>`u`){e();return}window.addEventListener(`DOMContentLoaded`,()=>e(),{once:!0})})}async function a(){if(await i(),typeof document>`u`)throw Error(`mintui.confirm is only available in browser environments.`);let e=document.querySelector(`mint-confirm-action[data-mint-confirm-action-root="true"]`);if(e)return e;let t=document.createElement(`mint-confirm-action`);return t.setAttribute(`data-mint-confirm-action-root`,`true`),document.body.appendChild(t),t}function o(e){let t=(e||`action`).toString().trim().toLowerCase().replace(/^tone:\s*/,``);return t===`action`||t===`info`||t===`warning`||t===`danger`?t:`action`}async function s(){if(!r){r=!0;try{for(;n.length>0;){let e=n.shift();e&&(await(await a()).showConfirm({question:e.question,tone:o(e.tone),confirmLabel:e.confirmLabel||`Confirm`,cancelLabel:e.cancelLabel||`Cancel`})?e.confirmed?.():e.cancelled?.())}}finally{r=!1}}}function c(e,t,r,i=`action`,a=`Confirm`,o=`Cancel`){typeof window>`u`||(n.push({question:e,confirmed:t,cancelled:r,tone:i,confirmLabel:a,cancelLabel:o}),s())}if(typeof window<`u`){let e=window.mintui||{};e.confirm=c,window.mintui=e}exports.confirm=c,exports.default=t;
|
|
@@ -8,8 +8,8 @@ import '../../stack.css'
|
|
|
8
8
|
import '../../confirm-action.css'
|
|
9
9
|
import { t as e } from "../chunks/register-element-BFYmIynH.js";
|
|
10
10
|
import "../chunks/text-Bmfl6CxJ.js";
|
|
11
|
-
import "../chunks/button-
|
|
12
|
-
import "../chunks/modal-
|
|
11
|
+
import "../chunks/button-BYQbRAwl.js";
|
|
12
|
+
import "../chunks/modal-CPcIPIO7.js";
|
|
13
13
|
//#region src/components/confirm-action/ConfirmAction.ts
|
|
14
14
|
var t = class extends HTMLElement {
|
|
15
15
|
constructor(...e) {
|
|
@@ -16,11 +16,11 @@ __mintLoadStyle('icon', '../../icon.css')
|
|
|
16
16
|
__mintLoadStyle('popover', '../../popover.css')
|
|
17
17
|
__mintLoadStyle('stack', '../../stack.css')
|
|
18
18
|
__mintLoadStyle('date-picker', '../../date-picker.css')
|
|
19
|
-
import { a as e } from "../chunks/icon-
|
|
19
|
+
import { a as e } from "../chunks/icon-BWUYe89V.js";
|
|
20
20
|
import { t } from "../chunks/register-element-BFYmIynH.js";
|
|
21
|
-
import "../chunks/icon-
|
|
22
|
-
import "../chunks/caret-right-
|
|
23
|
-
import "../chunks/input-
|
|
21
|
+
import "../chunks/icon-B8p3Co0-.js";
|
|
22
|
+
import "../chunks/caret-right-fnCcTJKp.js";
|
|
23
|
+
import "../chunks/input-Dwrs8tJH.js";
|
|
24
24
|
import "../chunks/popover-gviDCspV.js";
|
|
25
25
|
e({
|
|
26
26
|
name: "calendar",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`../chunks/icon-BcsWL4kZ.js`),t=require(`../chunks/register-element-tCL_F1YI.js`);require(`../chunks/icon-uMo_iGkX.js`),require(`../chunks/caret-right-BMyWflHN.js`),require(`../chunks/input-DnVgj6QV.js`),require(`../chunks/popover-BeaGf_JC.js`),e.a({name:`calendar`,viewBox:`0 0 24 24`,path:`M8 7V3m8 4V3M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2zM6 11h12M6 14h12M6 17h12`,strokeLinecap:`round`,strokeLinejoin:`round`}),e.a({name:`caret-left`,viewBox:`0 0 24 24`,path:`M15 19l-7-7 7-7`,strokeLinecap:`round`,strokeLinejoin:`round`});var n=class extends HTMLElement{static get observedAttributes(){return[`value`,`label`,`info`,`disabled`,`id`,`name`,`required`,`readonly`,`format`,`min`,`max`,`range`,`shortcuts`,`display-format`,`error`,`error-message`,`loading`,`selection-mode`,`week-start-day`,`mode`,`disabled-dates`]}constructor(){super(),this._input=null,this._textInput=null,this._popover=null,this._calendarContainer=null,this._iconButton=null,this._hiddenInput=null,this._startPartInputs=[],this._endPartInputs=[],this._displayEl=null,this._inputsWrapperEl=null,this._fieldsContainer=null,this._resetHandler=null,this._isInputMode=!1,this._currentMonth=new Date().getMonth(),this._currentYear=new Date().getFullYear(),this._viewMode=`calendar`,this._selectedStartDate=null,this._selectedEndDate=null,this._isRange=!1,this._hoveredDate=null,this._isHandlingClick=!1,this._touchStartDate=null,this._touchStartElement=null,this._isTouchActive=!1,this._resizeObserver=null,this._popoverObserver=null,this._focusTrapHandler=null,this._escapeHandler=null,this._a11yId=`mint-date-picker-${Math.random().toString(36).slice(2,10)}`}connectedCallback(){this.classList.add(`mint-date-picker`),this.render(),this._setupPopoverWithRetry(),this._attachFormResetListener()}disconnectedCallback(){if(this._popoverObserver&&=(this._popoverObserver.disconnect(),null),this._resizeObserver&&=(this._resizeObserver.disconnect(),null),this._removeFocusTrap(),this._resetHandler){let e=this.closest(`form`);e&&e.removeEventListener(`reset`,this._resetHandler),this._resetHandler=null}}isLoading(){return this.getAttribute(`loading`)===`true`}attributeChangedCallback(e,t,n){if(t!==n){if(e===`error`||e===`error-message`){let e=this.hasError(),t=this.getErrorMessage();this._applyErrorVisuals(e,t,this.isDisabled());return}if(e===`loading`){this.render();return}if(e===`mode`||e===`format`){let e=this.getMode();e===`month`?this._viewMode=`month`:e===`year`?this._viewMode=`year`:this._viewMode=`calendar`,this._popover&&this._calendarContainer&&this._buildCalendar()}this.render(),this._input&&this._setupPopoverWithRetry()}}getValue(){return this.getAttribute(`value`)||``}setValue(e){e?(this.setAttribute(`value`,e),this._textInput&&(this._textInput.value=e),this._parseValue(e)):(this.removeAttribute(`value`),this._textInput&&(this._textInput.value=``),this._selectedStartDate=null,this._selectedEndDate=null),this._buildCalendar(),this._updateDisplayText()}get value(){try{return this.getValue()||``}catch{return``}}set value(e){try{this.setValue(e||``)}catch{}}getFormat(){return this.getAttribute(`format`)||`mm/dd/yyyy`}getLabel(){return this.getAttribute(`label`)||``}getInfo(){return this.getAttribute(`info`)||``}isDisabled(){return this.getAttribute(`disabled`)===`true`}isReadonly(){return this.getAttribute(`readonly`)===`true`}isRequired(){return this.getAttribute(`required`)===`true`}hasError(){return this.getAttribute(`error`)===`true`}getErrorMessage(){return this.getAttribute(`error-message`)||``}isRange(){return this.getAttribute(`range`)===`true`}getId(){return this.getAttribute(`id`)||``}getName(){return this.getAttribute(`name`)||``}getMin(){return this.getAttribute(`min`)||``}getMax(){return this.getAttribute(`max`)||``}getDisabledDates(){let e=this.getAttribute(`disabled-dates`);if(!e)return[];try{let t=JSON.parse(e),n=this.getFormat();return t.map(e=>this._parseDateString(e,n)).filter(e=>e!==null)}catch{return[]}}getDisabledDateStrings(){let e=this.getAttribute(`disabled-dates`);if(!e)return[];try{return JSON.parse(e)}catch{return[]}}disableDate(e){let t=this.getFormat(),n=this.getDisabledDateStrings(),r=Array.isArray(e)?e:[e],i=[];for(let e of r){let r=this._parseDateString(e,t);if(r){let e=this._formatDate(r,t);n.includes(e)||i.push(e)}}if(i.length>0){let e=[...n,...i];this.setAttribute(`disabled-dates`,JSON.stringify(e)),this._buildCalendar()}}enableDate(e){let t=this.getFormat(),n=this.getDisabledDateStrings(),r=Array.isArray(e)?e:[e],i=[];for(let e of r){let n=this._parseDateString(e,t);if(n){let e=this._formatDate(n,t);i.push(e)}}if(i.length>0){let e=n.filter(e=>!i.includes(e));e.length===0?this.removeAttribute(`disabled-dates`):this.setAttribute(`disabled-dates`,JSON.stringify(e)),this._buildCalendar()}}getSelectionMode(){let e=this.getAttribute(`selection-mode`);return e===`week`||e===`month`?e:`day`}getMode(){let e=this.getAttribute(`mode`);if(e===`month`||e===`year`)return e;let t=this.getFormat().toLowerCase(),n=t.includes(`d`),r=t.includes(`m`);return!n&&!r?`year`:!n&&r?`month`:`default`}getWeekStartDay(){return{sunday:0,monday:1,tuesday:2,wednesday:3,thursday:4,friday:5,saturday:6}[this.getAttribute(`week-start-day`)?.toLowerCase()||`sunday`]??0}getDisplayFormat(){return this.getAttribute(`display-format`)||`F j, Y`}getShortcuts(){let e=this.getAttribute(`shortcuts`);if(!e)return[];try{let t=JSON.parse(e);if(Array.isArray(t))return t.map(e=>({label:e.label,action:this._createShortcutAction(e.action)}))}catch{let t=e.trim();if(t&&typeof window[t]==`function`){let e=window[t]();if(Array.isArray(e))return e.map(e=>({label:e.label,action:typeof e.action==`function`?e.action:this._createShortcutAction(e.action)}))}}return[]}_createShortcutAction(e){return typeof e==`function`?e:typeof e==`string`&&typeof window[e]==`function`?window[e]:()=>null}_getDefaultShortcuts(){let e=[{label:`Today`,action:()=>new Date}];return this._isRange&&e.push({label:`This Week`,action:()=>{let e=new Date,t=e.getDay(),n=new Date(e);n.setDate(e.getDate()-t),n.setHours(0,0,0,0);let r=new Date(n);return r.setDate(n.getDate()+6),r.setHours(23,59,59,999),{start:n,end:r}}},{label:`This Month`,action:()=>{let e=new Date,t=new Date(e.getFullYear(),e.getMonth(),1),n=new Date(e.getFullYear(),e.getMonth()+1,0);return n.setHours(23,59,59,999),{start:t,end:n}}}),e}_getFormatTokens(e){let t=[],n=0,r=e.toLowerCase();for(;n<r.length;){let i=r[n];if(i===`d`||i===`m`||i===`y`){let e=1,a=n+1;for(;a<r.length&&r[a]===i;)e++,a++;t.push({type:`part`,part:i,len:e}),n=a}else t.push({type:`sep`,value:e[n]}),n++}return t}_createPartInput(e,t,n,r,i){let a=document.createElement(`input`);return a.type=`text`,a.inputMode=`numeric`,a.pattern=`\\d*`,a.maxLength=e,a.placeholder=t,a.className=`mint-date-picker-part-input`,a.disabled=n||r,a.readOnly=r,a.required=i,e===4?a.classList.add(`is-year-part`):e===2&&a.classList.add(`is-short-part`),a}_buildValueFromParts(e,t){let n=0;return t.map(t=>{if(t.type===`sep`)return t.value;let r=e[n]?.value||``;return n++,r}).join(``)}_applyDateToParts(e,t,n,r){if(!t.length)return;if(!e){t.forEach(e=>e.value=``);return}let i=this._formatDate(e,r),a=0,o=0;n.forEach(e=>{if(e.type===`sep`)a+=e.value.length;else{let n=i.substr(a,e.len);t[o]&&(t[o].value=n),o++,a+=e.len}})}_syncHiddenInput(){if(!this._hiddenInput)return;let e=this.getFormat(),t=this._getFormatTokens(e),n=this._buildValueFromParts(this._startPartInputs,t);if(this._isRange){let e=this._buildValueFromParts(this._endPartInputs,t);this._hiddenInput.value=e?`${n} - ${e}`:n}else this._hiddenInput.value=n}_focusNext(e,t){if(t+1<e.length){let n=e[t+1];n.focus(),n.setSelectionRange(0,n.value.length)}}_focusPrev(e,t){if(t-1>=0){let n=e[t-1];n.focus(),n.setSelectionRange(n.value.length,n.value.length)}}_attachPartInputHandlers(e,t,n){e.forEach((t,n)=>{let r=t.maxLength||2;t.addEventListener(`input`,()=>{t.value=t.value.replace(/\D/g,``).slice(0,r),t.value.length>=r&&this._focusNext(e,n),this._syncHiddenInput()}),t.addEventListener(`keydown`,r=>{r.key===`Backspace`&&t.selectionStart===0&&t.selectionEnd===0&&this._focusPrev(e,n),r.key===`ArrowLeft`&&t.selectionStart===0&&t.selectionEnd===0&&(this._focusPrev(e,n),r.preventDefault()),r.key===`ArrowRight`&&t.selectionStart===t.value.length&&t.selectionEnd===t.value.length&&(this._focusNext(e,n),r.preventDefault())}),t.addEventListener(`blur`,e=>{this._syncHiddenInput();let t=e.relatedTarget,n=t&&(this._startPartInputs.includes(t)||this._endPartInputs.includes(t));setTimeout(()=>{if(!(this._startPartInputs.some(e=>e===document.activeElement)||this._endPartInputs.some(e=>e===document.activeElement))&&(n||this._handleBlur(this._hiddenInput?.value||``),this._exitInputMode(),!n&&this._hiddenInput)){let t=new FocusEvent(`blur`,{bubbles:!0,cancelable:!0,relatedTarget:e.relatedTarget});this._hiddenInput.dispatchEvent(t)}},0)})})}_splitRangeInput(e,t){let n=e.split(/\s*-\s*/);return n.length>=2?[n[0],n.slice(1).join(`-`)]:[e]}_parseValue(e){let t=this.getFormat(),n=this._getFormatTokens(t),r=this.getSelectionMode();if(this._isRange||r===`week`||r===`month`){let[r,i]=this._splitRangeInput(e,t),a=r?this._parseDateString(r,t):null,o=i?this._parseDateString(i,t):null;if(a&&o){let[e,t]=a<=o?[a,o]:[o,a];this._selectedStartDate=e,this._selectedEndDate=t,this._currentMonth=e.getMonth(),this._currentYear=e.getFullYear()}else a&&(this._selectedStartDate=a,this._selectedEndDate=null,this._currentMonth=a.getMonth(),this._currentYear=a.getFullYear());this._applyDateToParts(this._selectedStartDate,this._startPartInputs,n,t),this._applyDateToParts(this._selectedEndDate,this._endPartInputs,n,t)}else{let r=this._parseDateString(e,t);r&&!isNaN(r.getTime())?(this._selectedStartDate=r,this._selectedEndDate=null,this._currentMonth=r.getMonth(),this._currentYear=r.getFullYear(),this._applyDateToParts(r,this._startPartInputs,n,t)):this._applyDateToParts(null,this._startPartInputs,n,t)}this._syncHiddenInput(),this._updateDisplayText()}_parseDateString(e,t){let n=/[\/\-\.\s]+/;if(n.test(e)){let r=e.split(n).filter(e=>e.length>0),i=t.split(/[\/\-\.\s]+/).filter(e=>e.length>0);if(r.length===i.length){let e=0,t=0,n=0;for(let a=0;a<i.length;a++){let o=i[a].toLowerCase(),s=r[a];if(o.includes(`d`))e=parseInt(s,10);else if(o.includes(`m`))t=parseInt(s,10)-1;else if(o.includes(`y`)){let e=parseInt(s,10),t=o.length,r=s.length;(r===2&&t===4||r===2&&t===2)&&(e=Math.floor(new Date().getFullYear()/100)*100+e),n=e}}let a=i.some(e=>e.toLowerCase().includes(`d`)),o=i.some(e=>e.toLowerCase().includes(`m`));if(a||(e=1),o||(t=0),t>=0&&t<=11&&n){let r=new Date(n,t,e);if(!isNaN(r.getTime()))return a&&r.getDate()!==e||r.getMonth()!==t||r.getFullYear()!==n?null:r}}}let r=e.replace(/[\/\-\.]/g,``),i=t.replace(/[\/\-\.]/g,``).toLowerCase(),a=i.indexOf(`d`),o=i.indexOf(`m`),s=i.indexOf(`y`),c=[{char:`d`,index:a},{char:`m`,index:o},{char:`y`,index:s}].sort((e,t)=>e.index-t.index),l=0,u=0,d=0,f=0;i.length,r.length;for(let e of c)if(e.char===`d`){let e=i.lastIndexOf(`d`)-i.indexOf(`d`)+1,t=r.substr(f,e);if(t.length===0)return null;l=parseInt(t,10),f+=t.length}else if(e.char===`m`){let e=i.lastIndexOf(`m`)-i.indexOf(`m`)+1,t=r.substr(f,e);if(t.length===0)return null;u=parseInt(t,10)-1,f+=t.length}else if(e.char===`y`){let e=i.lastIndexOf(`y`)-i.indexOf(`y`)+1,t=r.substr(f),n=Math.min(e,t.length),a=t.substr(0,n);if(a.length===0)return null;let o=parseInt(a,10);(n===2&&e===4||n===2&&e===2)&&(o=Math.floor(new Date().getFullYear()/100)*100+o),d=o,f+=n}let p=t.toLowerCase(),m=p.includes(`d`),h=p.includes(`m`);if(m||(l=1),h||(u=0),u<0||u>11||!d)return null;let g=new Date(d,u,l);return isNaN(g.getTime())||m&&g.getDate()!==l||g.getMonth()!==u||g.getFullYear()!==d?null:g}_formatDate(e,t){let n=e.getDate(),r=e.getMonth()+1,i=e.getFullYear(),a=t.toLowerCase(),o=t;return a.includes(`dd`)?o=o.replace(/dd/gi,String(n).padStart(2,`0`)):a.includes(`d`)&&(o=o.replace(/d/gi,String(n))),a.includes(`mm`)?o=o.replace(/mm/gi,String(r).padStart(2,`0`)):a.includes(`m`)&&(o=o.replace(/m/gi,String(r))),a.includes(`yyyy`)?o=o.replace(/yyyy/gi,String(i)):a.includes(`yy`)&&(o=o.replace(/yy/gi,String(i).substr(2))),o}_formatDatePhp(e,t){let n=e.getDate(),r=e.getMonth()+1,i=e.getFullYear(),a=[`Sunday`,`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`],o=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`],s=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],c=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],l=(e,t=2)=>e.toString().padStart(t,`0`),u=e=>{let t=e%10,n=e%100;return t===1&&n!==11?`st`:t===2&&n!==12?`nd`:t===3&&n!==13?`rd`:`th`},d=``;for(let f=0;f<t.length;f++){let p=t[f];if(p===`\\`&&f+1<t.length){d+=t[f+1],f++;continue}switch(p){case`Y`:d+=i.toString();break;case`y`:d+=i.toString().slice(-2);break;case`m`:d+=l(r);break;case`n`:d+=r.toString();break;case`M`:d+=c[r-1];break;case`F`:d+=s[r-1];break;case`d`:d+=l(n);break;case`j`:d+=n.toString();break;case`D`:d+=o[e.getDay()];break;case`l`:d+=a[e.getDay()];break;case`S`:d+=u(n);break;default:d+=p;break}}return d}_validateDateString(e,t){let n=this._parseDateString(e,t);return n!==null&&!isNaN(n.getTime())}render(){let e=this.isLoading(),t=this.getLabel(),n=this.getInfo(),r=this.getValue(),i=this.isDisabled(),a=this.isReadonly(),o=this.isRequired(),s=this.getId()||this._a11yId,c=this.getName(),l=this.getFormat(),u=this.hasError(),d=this.getErrorMessage(),f=this.getSelectionMode();this._isRange=this.isRange()||f===`week`||f===`month`,this._input||(this._input=document.createElement(`div`),this._input.className=`mint-date-picker-field`,this.appendChild(this._input));let p=this.querySelector(`.mint-date-picker-label-container`);if(t||n){p||(p=document.createElement(`div`),p.className=`mint-date-picker-label-container`,this.contains(this._input)?this.insertBefore(p,this._input):this.appendChild(p));let e=p.querySelector(`.mint-date-picker-label`);t?(e||(e=document.createElement(`label`),e.className=`mint-date-picker-label`,p.insertBefore(e,p.firstChild)),e.textContent=t,s&&this._textInput&&e.setAttribute(`for`,s)):e&&e.remove();let r=p.querySelector(`.mint-date-picker-info`);n?(r||(r=document.createElement(`span`),r.className=`mint-date-picker-info`,p.appendChild(r)),r.textContent=n):r&&r.remove()}else p&&p.remove();this._hiddenInput||(this._hiddenInput=document.createElement(`input`),this._hiddenInput.type=`hidden`,this._hiddenInput.value=r||``,this._textInput=this._hiddenInput,this._input.appendChild(this._hiddenInput)),s&&(this._hiddenInput.id=s),c&&(this._hiddenInput.name=c),this._hiddenInput.value=r||``,this._hiddenInput.setAttribute(`aria-invalid`,u?`true`:`false`);let m=this._input.querySelector(`.mint-date-fields`);m||(m=document.createElement(`div`),this._input.appendChild(m)),this._fieldsContainer=m,this._applyErrorVisuals(u,d,i),m.innerHTML=``,this._displayEl=document.createElement(`div`),this._displayEl.className=`mint-date-picker-display${a?` is-readonly`:``}`,this._displayEl.tabIndex=i||a?-1:0,this._displayEl.setAttribute(`role`,`button`),this._displayEl.setAttribute(`aria-label`,`${this.getLabel()||`Date`}: ${r||`Select date`}`),this._displayEl.addEventListener(`click`,()=>{i||a||this._enterInputMode()}),this._displayEl.addEventListener(`keydown`,e=>{i||a||(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),this._enterInputMode())}),this._inputsWrapperEl=document.createElement(`div`),this._isRange,this._inputsWrapperEl.className=`mint-date-picker-inputs`;let h=this._getFormatTokens(l);this._startPartInputs=[],this._endPartInputs=[];let g=e=>{let t=document.createDocumentFragment();return h.forEach(n=>{if(n.type===`sep`){let e=document.createElement(`span`);e.textContent=n.value,e.className=`mint-date-picker-separator`,t.appendChild(e)}else{let r=n.part===`d`?`dd`:n.part===`m`?`mm`:n.len===2?`yy`:`yyyy`,s=this._createPartInput(n.len,r,i,a,o),c=n.part===`d`?`day`:n.part===`m`?`month`:`year`,l=this.getLabel()||`Date`;s.setAttribute(`aria-label`,`${e===`end`?`End ${l.toLowerCase()}`:l} ${c}`),e===`start`?this._startPartInputs.push(s):this._endPartInputs.push(s),t.appendChild(s)}}),t};if(this._isRange){let e=document.createElement(`div`);e.className=`mint-date-picker-range-part`,e.appendChild(g(`start`)),this._inputsWrapperEl.appendChild(e);let t=document.createElement(`span`);t.textContent=` - `,t.className=`mint-date-picker-range-dash`,this._inputsWrapperEl.appendChild(t);let n=document.createElement(`div`);n.className=`mint-date-picker-range-part`,n.appendChild(g(`end`)),this._inputsWrapperEl.appendChild(n)}else this._inputsWrapperEl.appendChild(g(`start`));let _=document.createElement(`div`);if(_.className=`mint-date-picker-stacked`,this.classList.toggle(`is-input-mode`,this._isInputMode),_.appendChild(this._displayEl),_.appendChild(this._inputsWrapperEl),m.appendChild(_),this._isRange&&this._inputsWrapperEl&&this._setupContainerObserver(),m.addEventListener(`click`,()=>{this._isInputMode||i||a||this._enterInputMode()}),this._attachPartInputHandlers(this._startPartInputs,h,m),this._isRange&&this._attachPartInputHandlers(this._endPartInputs,h,m),this._parseValue(r),this._syncHiddenInput(),this._updateDisplayText(),this._iconButton)this._iconButton.disabled=i||a,!i&&!a?this._iconButton.tabIndex=0:this._iconButton.tabIndex=-1;else{this._iconButton=document.createElement(`button`),this._iconButton.type=`button`,this._iconButton.tabIndex=0,this._iconButton.className=`mint-date-picker-icon-button`,this._iconButton.setAttribute(`aria-label`,`Open calendar`),this._iconButton.setAttribute(`aria-haspopup`,`dialog`),this._iconButton.setAttribute(`aria-expanded`,`false`);let e=`date-icon-${Math.random().toString(36).substr(2,9)}`;this._iconButton.id=e;let t=document.createElement(`mint-icon`);t.setAttribute(`name`,`calendar`),t.className=`mint-date-picker-icon`,this._iconButton.appendChild(t),this._input.prepend(this._iconButton),this._iconButton.disabled=i||a}this._renderErrorState(u,d),this._syncDateFieldDescriptions(),this._renderSkeleton(e)}_renderErrorState(e,t){let n=this.querySelector(`.mint-date-picker-error`);e&&t?(n||(n=document.createElement(`div`),n.className=`mint-date-picker-error`,this.appendChild(n)),n.textContent=t):n&&n.remove()}_syncDateFieldDescriptions(){let e=Array.from(this.querySelectorAll(`.mint-date-fields input`));if(!e.length)return;let t=(this.getAttribute(`aria-describedby`)||``).split(/\s+/).filter(Boolean),n=this.querySelector(`.mint-date-picker-info`),r=this.querySelector(`.mint-date-picker-error`),i=this.getAttribute(`id`)||this._a11yId;n&&(n.id=`${i}-info`,t.push(n.id)),r&&(r.id=`${i}-error`,t.push(r.id));let a=Array.from(new Set(t)).join(` `);e.forEach(e=>{e.setAttribute(`aria-invalid`,String(this._hiddenInput?.getAttribute(`aria-invalid`)===`true`)),a?e.setAttribute(`aria-describedby`,a):e.removeAttribute(`aria-describedby`)})}_applyErrorVisuals(e,t,n){if(this._renderErrorState(e,t),this._fieldsContainer){let t=this._getFieldContainerClass(e,n);this._fieldsContainer.className=t}this._hiddenInput&&this._hiddenInput.setAttribute(`aria-invalid`,e?`true`:`false`),this._syncDateFieldDescriptions()}_attachFormResetListener(){let e=this.closest(`form`);!e||this._resetHandler||(this._resetHandler=()=>{this.setValue(``),this._clearPartInputs(this._startPartInputs),this._clearPartInputs(this._endPartInputs),this._isInputMode=!1,this._updateDisplayText(),this._applyErrorVisuals(!1,``,this.isDisabled())},e.addEventListener(`reset`,this._resetHandler))}_clearPartInputs(e){e.forEach(e=>{e.value=``})}_getFieldContainerClass(e,t){return`mint-date-fields${e?` has-error`:``}${t?` is-disabled`:``}`}_handleInputChange(e){}_cleanInputValue(e,t){return e}_handleBlur(e){let t=this.getFormat(),n=this.getSelectionMode(),r=this._isRange||n===`week`||n===`month`;if(!e){this.setValue(``),this._updateDisplayText();return}if(r){let[n,r]=this._splitRangeInput(e,t),i=n?this._parseDateString(n,t):null,a=r?this._parseDateString(r,t):null;if(i&&a){let[e,n]=i<=a?[i,a]:[a,i],r=`${this._formatDate(e,t)} - ${this._formatDate(n,t)}`;this.setValue(r),this._applyDateToParts(e,this._startPartInputs,this._getFormatTokens(t),t),this._applyDateToParts(n,this._endPartInputs,this._getFormatTokens(t),t),this._selectedStartDate=e,this._selectedEndDate=n,this._currentMonth=e.getMonth(),this._currentYear=e.getFullYear()}else if(i){let e=this._formatDate(i,t);this.setValue(e),this._applyDateToParts(i,this._startPartInputs,this._getFormatTokens(t),t),this._applyDateToParts(null,this._endPartInputs,this._getFormatTokens(t),t),this._selectedStartDate=i,this._selectedEndDate=null,this._currentMonth=i.getMonth(),this._currentYear=i.getFullYear()}else this.setValue(``),this._applyDateToParts(null,this._startPartInputs,this._getFormatTokens(t),t),this._applyDateToParts(null,this._endPartInputs,this._getFormatTokens(t),t),this._selectedStartDate=null,this._selectedEndDate=null}else if(this._validateDateString(e,t)){let n=this._parseDateString(e,t);if(n){let e=this._formatDate(n,t);this.setValue(e),this._applyDateToParts(n,this._startPartInputs,this._getFormatTokens(t),t),this._selectedStartDate=n,this._selectedEndDate=null,this._currentMonth=n.getMonth(),this._currentYear=n.getFullYear()}}else this.setValue(``),this._applyDateToParts(null,this._startPartInputs,this._getFormatTokens(t),t),this._selectedStartDate=null,this._selectedEndDate=null}_setupPopoverWithRetry(e=0){if(!this._iconButton){e<10&&requestAnimationFrame(()=>{this._setupPopoverWithRetry(e+1)});return}let t=this._iconButton.id;t&&this._iconButton.isConnected&&document.getElementById(t)?this._createPopover(t):e<10&&requestAnimationFrame(()=>{this._setupPopoverWithRetry(e+1)})}_createPopover(e){if(e){if(!document.getElementById(e)){setTimeout(()=>{this._createPopover(e)},50);return}if(this._popover){if(this._popover.getAttribute(`trigger-id`)!==e){this._popover.setAttribute(`trigger-id`,e);let t=this._popover;typeof t._setupTrigger==`function`&&t._setupTrigger()}this._buildCalendar()}else{this._popover=document.createElement(`mint-popover`),this._popover.classList.add(`mint-date-picker-popover`),this._popover.setAttribute(`direction`,`down`),this._popover.setAttribute(`padding`,`0`);let t=this.closest(`mint-modal`),n=this.closest(`mint-off-canvas`);t||n?document.body.appendChild(this._popover):this.parentNode?this.parentNode.insertBefore(this._popover,this.nextSibling):document.body.appendChild(this._popover),requestAnimationFrame(()=>{requestAnimationFrame(()=>{this._popover&&this._popover.isConnected&&(this._popover.setAttribute(`trigger-id`,e),this._popoverObserver||(this._popoverObserver=new MutationObserver(e=>{e.forEach(e=>{if(e.type===`attributes`&&e.attributeName===`open`)if(this._popover?.hasAttribute(`open`))requestAnimationFrame(()=>{this._buildCalendar();let e=this._popover;typeof e.render==`function`&&e.render(),this._setupFocusTrap()});else{if(this._removeFocusTrap(),this._iconButton&&!this._iconButton.disabled&&requestAnimationFrame(()=>{this._iconButton?.focus()}),this._viewMode=`calendar`,this._selectedStartDate)this._currentMonth=this._selectedStartDate.getMonth(),this._currentYear=this._selectedStartDate.getFullYear();else{let e=new Date;this._currentMonth=e.getMonth(),this._currentYear=e.getFullYear()}requestAnimationFrame(()=>{this._buildCalendar()}),this._hiddenInput&&(this._syncHiddenInput(),setTimeout(()=>{let e=new FocusEvent(`blur`,{bubbles:!0,cancelable:!0,relatedTarget:null});this._hiddenInput?.dispatchEvent(e)},0))}})}),this._popoverObserver.observe(this._popover,{attributes:!0,attributeFilter:[`open`]})),requestAnimationFrame(()=>{this._buildCalendar()}))})})}}}_buildCalendar(){if(!this._popover)return;this._calendarContainer&&this._calendarContainer.parentNode&&this._calendarContainer.remove(),this._calendarContainer=document.createElement(`div`),this._calendarContainer.className=`mint-date-calendar`;let e=this.getMode();e===`month`&&this._viewMode===`calendar`?this._viewMode=`month`:e===`year`&&this._viewMode===`calendar`?this._viewMode=`year`:e===`default`&&this._viewMode!==`month`&&this._viewMode!==`year`&&(this._viewMode=`calendar`),this._viewMode===`calendar`?this._buildCalendarView():this._viewMode===`month`?this._buildMonthView():this._viewMode===`year`&&this._buildYearView(),this._popover.replaceChildren(this._calendarContainer)}_buildCalendarView(){if(!this._calendarContainer)return;let e=this._getDaysInMonth(this._currentMonth,this._currentYear),t=this._getFirstDayOfMonth(this._currentMonth,this._currentYear),n=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],r=this.getWeekStartDay(),i=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`],a=[...i.slice(r),...i.slice(0,r)],o=this.getShortcuts(),s=o.length>0;this._calendarContainer.className=`mint-date-calendar${s?` has-shortcuts`:``}`;let c=document.createElement(`div`);c.className=`mint-date-calendar-layout`;let l=document.createElement(`div`);l.className=`mint-date-calendar-content`;let u=document.createElement(`div`);u.className=`mint-date-calendar-header`;let d=document.createElement(`button`);d.type=`button`,d.tabIndex=0,d.className=`mint-date-calendar-nav-button`,d.setAttribute(`aria-label`,`Previous month`),d.setAttribute(`data-keep-popover-open`,`true`);let f=document.createElement(`mint-icon`);f.setAttribute(`name`,`caret-left`),f.className=`mint-date-calendar-icon`,d.appendChild(f),d.addEventListener(`click`,()=>{let e=this._currentMonth,t=this._currentYear;this._currentMonth===0?(this._currentMonth=11,this._currentYear--):this._currentMonth--,this._buildCalendar(),this._dispatchMonthChangeEvent(e,t,this._currentMonth,this._currentYear)}),u.appendChild(d);let p=document.createElement(`div`);p.className=`mint-date-calendar-month-year`;let m=document.createElement(`button`);m.type=`button`,m.tabIndex=0,m.className=`mint-date-calendar-title-button`,m.setAttribute(`data-keep-popover-open`,`true`),m.textContent=n[this._currentMonth],m.setAttribute(`aria-label`,`Choose month, ${n[this._currentMonth]}`);let h=()=>{let e=this.getMode();e!==`month`&&e!==`year`&&(this._viewMode=`month`,this._buildCalendar())};m.addEventListener(`click`,h),m.addEventListener(`touchend`,e=>{e.preventDefault(),h()},{passive:!1}),p.appendChild(m);let g=document.createElement(`button`);g.type=`button`,g.tabIndex=0,g.className=`mint-date-calendar-title-button`,g.setAttribute(`data-keep-popover-open`,`true`),g.textContent=String(this._currentYear),g.setAttribute(`aria-label`,`Choose year, ${this._currentYear}`),g.addEventListener(`click`,()=>{this.getMode()!==`year`&&(this._viewMode=`year`,this._buildCalendar())}),p.appendChild(g),u.appendChild(p);let _=document.createElement(`button`);_.type=`button`,_.tabIndex=0,_.className=`mint-date-calendar-nav-button`,_.setAttribute(`aria-label`,`Next month`),_.setAttribute(`data-keep-popover-open`,`true`);let v=document.createElement(`mint-icon`);v.setAttribute(`name`,`caret-right`),v.className=`mint-date-calendar-icon`,_.appendChild(v);let y=()=>{let e=this._currentMonth,t=this._currentYear;this._currentMonth===11?(this._currentMonth=0,this._currentYear++):this._currentMonth++,this._buildCalendar(),this._dispatchMonthChangeEvent(e,t,this._currentMonth,this._currentYear)};_.addEventListener(`click`,y),_.addEventListener(`touchend`,e=>{e.preventDefault(),y()},{passive:!1}),u.appendChild(_);let b=document.createElement(`div`);b.className=`mint-date-calendar-day-names`,a.forEach(e=>{let t=document.createElement(`div`);t.className=`mint-date-calendar-day-name`,t.textContent=e,b.appendChild(t)});let x=document.createElement(`div`);x.className=`mint-date-calendar-grid`,x.setAttribute(`role`,`group`),x.setAttribute(`aria-label`,`${n[this._currentMonth]} ${this._currentYear}`);let S=this.getMin()?this._parseDateString(this.getMin(),this.getFormat()):null,C=this.getMax()?this._parseDateString(this.getMax(),this.getFormat()):null;this.getDisabledDates();let w=this._currentMonth===0?11:this._currentMonth-1,T=this._currentMonth===0?this._currentYear-1:this._currentYear,E=this._getDaysInMonth(w,T),D=this._currentMonth===11?0:this._currentMonth+1,O=this._currentMonth===11?this._currentYear+1:this._currentYear,k=t+e,A=Math.ceil(k/7)*7-k,j=(e,t,n)=>{let r=this._isToday(e),i=this._isDateSelected(e),a=this._isDateInRange(e),o=S&&e<S||C&&e>C||this._isDateDisabled(e),s=`is-fully-rounded`,c=this._isRange&&this._selectedStartDate&&!this._selectedEndDate&&this._hoveredDate,l=c&&this._selectedStartDate&&this._hoveredDate&&this._selectedStartDate<this._hoveredDate?this._selectedStartDate:c&&this._hoveredDate?this._hoveredDate:null,u=c&&this._selectedStartDate&&this._hoveredDate&&this._selectedStartDate<this._hoveredDate?this._hoveredDate:c&&this._selectedStartDate?this._selectedStartDate:null,d=l!==null&&this._isSameDate(e,l),f=u!==null&&this._isSameDate(e,u),p=this._hoveredDate!==null&&this._isSameDate(e,this._hoveredDate),m=c&&this._hoveredDate&&this._selectedStartDate?!this._rangeIncludesDisabledDates(this._selectedStartDate<this._hoveredDate?this._selectedStartDate:this._hoveredDate,this._selectedStartDate<this._hoveredDate?this._hoveredDate:this._selectedStartDate):!1;if(this._isRange&&this._selectedStartDate&&this._selectedEndDate){let t=this._isSameDate(e,this._selectedStartDate),n=this._isSameDate(e,this._selectedEndDate);t&&n?s=`is-fully-rounded`:t?s=`is-range-start`:n?s=`is-range-end`:a&&(s=`is-range-middle`)}else c&&(d||f)&&m?d&&f?s=`is-fully-rounded`:d?s=`is-range-start`:f&&(s=`is-range-end`):i&&!this._isRange||i&&this._isRange&&!this._selectedEndDate?s=`is-fully-rounded`:a&&c&&m&&(s=`is-range-middle`);let h=document.createElement(`button`);h.type=`button`,h.disabled=!!o,h.tabIndex=o?-1:0;let g=[`mint-date-picker-day`,s],_=i||c&&p&&m;return n||g.push(`is-outside-month`),_&&g.push(`is-selected`),a&&!_&&g.push(`is-in-range`),r&&!_&&g.push(`is-today`),o&&g.push(`is-disabled`),h.className=g.join(` `),h.textContent=t.toString(),h.setAttribute(`aria-label`,e.toLocaleDateString(void 0,{weekday:`long`,year:`numeric`,month:`long`,day:`numeric`})),h.setAttribute(`aria-pressed`,String(i)),r&&h.setAttribute(`aria-current`,`date`),o||(h.addEventListener(`click`,t=>{t.preventDefault(),t.stopPropagation(),this._handleDateClick(e)}),h.addEventListener(`touchstart`,t=>{t.preventDefault(),t.stopPropagation(),this._isTouchActive=!0,this._touchStartDate=e,this._touchStartElement=h,h.classList.add(`is-touch-active`)},{passive:!1}),h.addEventListener(`touchend`,t=>{t.preventDefault(),t.stopPropagation(),this._isTouchActive&&this._touchStartDate&&this._isSameDate(this._touchStartDate,e)&&this._handleDateClick(e),this._touchStartElement&&this._touchStartElement.classList.remove(`is-touch-active`),this._isTouchActive=!1,this._touchStartDate=null,this._touchStartElement=null},{passive:!1}),h.addEventListener(`touchcancel`,()=>{this._touchStartElement&&this._touchStartElement.classList.remove(`is-touch-active`),this._isTouchActive=!1,this._touchStartDate=null,this._touchStartElement=null}),this._isRange&&this._selectedStartDate&&!this._selectedEndDate&&!o&&(h.addEventListener(`mouseenter`,()=>{this._isHandlingClick||this._isTouchActive||this._isDateDisabled(e)||(!this._hoveredDate||!this._isSameDate(this._hoveredDate,e))&&(this._hoveredDate=e,this._buildCalendar())}),h.addEventListener(`touchmove`,e=>{if(!this._isTouchActive||!this._touchStartDate)return;let t=e.touches[0],n=document.elementFromPoint(t.clientX,t.clientY);for(;n&&!n.classList.contains(`mint-date-picker-day`);)n=n.parentElement;if(n&&n!==h){let e=n.getAttribute(`data-date`);if(e){let t=new Date(e);this._isDateDisabled(t)||(!this._hoveredDate||!this._isSameDate(this._hoveredDate,t))&&(this._hoveredDate=t,this._buildCalendar())}}},{passive:!0}))),h};for(let e=t-1;e>=0;e--){let t=E-e,n=j(new Date(T,w,t),t,!1);x.appendChild(n)}for(let t=1;t<=e;t++){let e=j(new Date(this._currentYear,this._currentMonth,t),t,!0);x.appendChild(e)}for(let e=1;e<=A;e++){let t=j(new Date(O,D,e),e,!1);x.appendChild(t)}if(this._isRange&&this._selectedStartDate&&!this._selectedEndDate&&(x.addEventListener(`mouseleave`,()=>{this._isTouchActive||(this._hoveredDate=null,this._buildCalendar())}),x.addEventListener(`touchend`,e=>{let t=e.changedTouches[0],n=document.elementFromPoint(t.clientX,t.clientY);n&&!x.contains(n)&&(this._hoveredDate=null,this._buildCalendar())},{passive:!0})),s){let e=document.createElement(`div`);e.className=`mint-date-shortcuts`;let t=document.createElement(`div`);t.className=`mint-date-shortcuts-wrapper`;let n=document.createElement(`div`);n.className=`mint-date-shortcuts-row`;let r=document.createElement(`div`);r.className=`mint-date-shortcuts-fade is-horizontal is-left`,t.appendChild(r);let i=document.createElement(`div`);i.className=`mint-date-shortcuts-fade is-horizontal is-right is-visible`,t.appendChild(i);let a=document.createElement(`div`);a.className=`mint-date-shortcuts-fade is-vertical is-top`,t.appendChild(a);let s=document.createElement(`div`);s.className=`mint-date-shortcuts-fade is-vertical is-bottom is-visible`,t.appendChild(s);let l=()=>{if(window.innerWidth>=768){let e=n.scrollTop,t=n.scrollHeight,o=n.clientHeight;e>0?a.classList.add(`is-visible`):a.classList.remove(`is-visible`),e+o<t-1?s.classList.add(`is-visible`):s.classList.remove(`is-visible`),r.classList.remove(`is-visible`),i.classList.remove(`is-visible`)}else{let e=n.scrollLeft,t=n.scrollWidth,o=n.clientWidth;e>0?r.classList.add(`is-visible`):r.classList.remove(`is-visible`),e+o<t-1?i.classList.add(`is-visible`):i.classList.remove(`is-visible`),a.classList.remove(`is-visible`),s.classList.remove(`is-visible`)}};n.addEventListener(`scroll`,l),window.addEventListener(`resize`,l),setTimeout(l,0),o.forEach(e=>{let t=document.createElement(`button`);t.type=`button`,t.tabIndex=0,t.className=`mint-date-shortcut-button`,t.textContent=e.label;let r=()=>{let t=e.action();if(t){if(this._isRange&&`start`in t&&`end`in t){this._selectedStartDate=t.start,this._selectedEndDate=t.end;let e=this.getFormat(),n=`${this._formatDate(t.start,e)} - ${this._formatDate(t.end,e)}`;this.setValue(n),this._currentMonth=t.start.getMonth(),this._currentYear=t.start.getFullYear()}else if(t instanceof Date){this._selectedStartDate=t,this._selectedEndDate=null;let e=this.getFormat(),n=this._formatDate(t,e);this.setValue(n),this._currentMonth=t.getMonth(),this._currentYear=t.getFullYear()}this._buildCalendar(),this._popover&&typeof this._popover.close==`function`&&this._popover.close(),this.dispatchEvent(new CustomEvent(`input`,{detail:{value:this.getValue()},bubbles:!0,cancelable:!0})),this.dispatchEvent(new CustomEvent(`change`,{detail:{value:this.getValue()},bubbles:!0,cancelable:!0}))}};t.addEventListener(`click`,r),t.addEventListener(`touchend`,e=>{e.preventDefault(),r()},{passive:!1}),n.appendChild(t)}),t.appendChild(n),e.appendChild(t),c.appendChild(e)}l.appendChild(u),l.appendChild(b),l.appendChild(x),c.appendChild(l),this._calendarContainer.appendChild(c)}_buildMonthView(){if(!this._calendarContainer)return;let e=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],t=document.createElement(`div`);t.className=`mint-date-calendar-header`;let n=document.createElement(`button`);n.type=`button`,n.tabIndex=0,n.className=`mint-date-calendar-nav-button`,n.setAttribute(`data-keep-popover-open`,`true`);let r=document.createElement(`mint-icon`);r.setAttribute(`name`,`caret-left`),r.className=`mint-date-calendar-icon`,n.appendChild(r);let i=()=>{let e=this._currentMonth,t=this._currentYear;this._currentYear--,this._buildCalendar(),this._dispatchMonthChangeEvent(e,t,this._currentMonth,this._currentYear)};n.addEventListener(`click`,i),n.addEventListener(`touchend`,e=>{e.preventDefault(),i()},{passive:!1}),t.appendChild(n);let a=document.createElement(`button`);a.type=`button`,a.tabIndex=0,a.className=`mint-date-calendar-title-button`,a.setAttribute(`data-keep-popover-open`,`true`),a.textContent=String(this._currentYear);let o=()=>{this.getMode()!==`year`&&(this._viewMode=`year`,this._buildCalendar())};a.addEventListener(`click`,o),a.addEventListener(`touchend`,e=>{e.preventDefault(),o()},{passive:!1}),t.appendChild(a);let s=document.createElement(`button`);s.type=`button`,s.tabIndex=0,s.className=`mint-date-calendar-nav-button`,s.setAttribute(`data-keep-popover-open`,`true`);let c=document.createElement(`mint-icon`);c.setAttribute(`name`,`caret-right`),c.className=`mint-date-calendar-icon`,s.appendChild(c);let l=()=>{let e=this._currentMonth,t=this._currentYear;this._currentYear++,this._buildCalendar(),this._dispatchMonthChangeEvent(e,t,this._currentMonth,this._currentYear)};s.addEventListener(`click`,l),s.addEventListener(`touchend`,e=>{e.preventDefault(),l()},{passive:!1}),t.appendChild(s);let u=document.createElement(`div`);u.className=`mint-date-calendar-option-grid`,e.forEach((e,t)=>{let n=document.createElement(`button`);n.type=`button`,n.tabIndex=0,this.getMode()!==`month`&&n.setAttribute(`data-keep-popover-open`,`true`),n.className=`mint-date-calendar-option${this._currentMonth===t?` is-selected`:``}`,n.textContent=e;let r=()=>{if(this.getMode()===`month`){let e=new Date(this._currentYear,t,1),n=this.getFormat(),r=this._formatDate(e,n);this.setValue(r),this._selectedStartDate=e,this._selectedEndDate=null;let i=this._currentMonth,a=this._currentYear;this._currentMonth=t,this._dispatchMonthChangeEvent(i,a,this._currentMonth,this._currentYear),this.dispatchEvent(new CustomEvent(`input`,{detail:{value:this.getValue()},bubbles:!0,cancelable:!0})),this.dispatchEvent(new CustomEvent(`change`,{detail:{value:this.getValue()},bubbles:!0,cancelable:!0})),this._dispatchDateChangeEvent(),this._popover&&typeof this._popover.close==`function`&&this._popover.close()}else{let e=this._currentMonth,n=this._currentYear;this._currentMonth=t,this._viewMode=`calendar`,this._buildCalendar(),this._dispatchMonthChangeEvent(e,n,this._currentMonth,this._currentYear)}};n.addEventListener(`click`,r),n.addEventListener(`touchend`,e=>{e.preventDefault(),r()},{passive:!1}),u.appendChild(n)}),this._calendarContainer.appendChild(t),this._calendarContainer.appendChild(u)}_buildYearView(){if(!this._calendarContainer)return;let e=this._currentYear-6,t=this._currentYear+6,n=document.createElement(`div`);n.className=`mint-date-calendar-header`;let r=document.createElement(`button`);r.type=`button`,r.tabIndex=0,r.className=`mint-date-calendar-nav-button`,r.setAttribute(`data-keep-popover-open`,`true`);let i=document.createElement(`mint-icon`);i.setAttribute(`name`,`caret-left`),i.className=`mint-date-calendar-icon`,r.appendChild(i);let a=()=>{let e=this._currentMonth,t=this._currentYear;this._currentYear-=12,this._buildCalendar(),this._dispatchMonthChangeEvent(e,t,this._currentMonth,this._currentYear)};r.addEventListener(`click`,a),r.addEventListener(`touchend`,e=>{e.preventDefault(),a()},{passive:!1}),n.appendChild(r);let o=document.createElement(`div`);o.className=`mint-date-calendar-title`,o.textContent=`${e} - ${t}`,n.appendChild(o);let s=document.createElement(`button`);s.type=`button`,s.tabIndex=0,s.className=`mint-date-calendar-nav-button`,s.setAttribute(`data-keep-popover-open`,`true`);let c=document.createElement(`mint-icon`);c.setAttribute(`name`,`caret-right`),c.className=`mint-date-calendar-icon`,s.appendChild(c);let l=()=>{let e=this._currentMonth,t=this._currentYear;this._currentYear+=12,this._buildCalendar(),this._dispatchMonthChangeEvent(e,t,this._currentMonth,this._currentYear)};s.addEventListener(`click`,l),s.addEventListener(`touchend`,e=>{e.preventDefault(),l()},{passive:!1}),n.appendChild(s);let u=document.createElement(`div`);u.className=`mint-date-calendar-option-grid`;for(let n=e;n<=t;n++){let e=document.createElement(`button`);e.type=`button`,e.tabIndex=0,this.getMode()!==`year`&&e.setAttribute(`data-keep-popover-open`,`true`),e.className=`mint-date-calendar-option${this._currentYear===n?` is-selected`:``}`,e.textContent=String(n),e.addEventListener(`click`,()=>{let e=this.getMode();if(e===`year`){let e=new Date(n,0,1),t=this.getFormat(),r=this._formatDate(e,t);this.setValue(r),this._selectedStartDate=e,this._selectedEndDate=null;let i=this._currentMonth,a=this._currentYear;this._currentYear=n,this._currentMonth=0,this._dispatchMonthChangeEvent(i,a,this._currentMonth,this._currentYear),this.dispatchEvent(new CustomEvent(`input`,{detail:{value:this.getValue()},bubbles:!0,cancelable:!0})),this.dispatchEvent(new CustomEvent(`change`,{detail:{value:this.getValue()},bubbles:!0,cancelable:!0})),this._dispatchDateChangeEvent(),this._popover&&typeof this._popover.close==`function`&&this._popover.close()}else if(e===`month`){let e=this._currentMonth,t=this._currentYear;this._currentYear=n,this._viewMode=`month`,this._buildCalendar(),this._dispatchMonthChangeEvent(e,t,this._currentMonth,this._currentYear)}else{let e=this._currentMonth,t=this._currentYear;this._currentYear=n,this._viewMode=`calendar`,this._buildCalendar(),this._dispatchMonthChangeEvent(e,t,this._currentMonth,this._currentYear)}}),u.appendChild(e)}this._calendarContainer.appendChild(n),this._calendarContainer.appendChild(u)}_getDaysInMonth(e,t){return new Date(t,e+1,0).getDate()}_getFirstDayOfMonth(e,t){let n=this.getWeekStartDay(),r=new Date(t,e,1).getDay();return r>=n?r-n:7-(n-r)}_isToday(e){let t=new Date;return e.getDate()===t.getDate()&&e.getMonth()===t.getMonth()&&e.getFullYear()===t.getFullYear()}_isDateSelected(e){let t=this.getSelectionMode();return this._isRange||t===`week`||t===`month`?this._selectedStartDate&&this._selectedEndDate?this._isSameDate(e,this._selectedStartDate)||this._isSameDate(e,this._selectedEndDate):this._isRange&&this._selectedStartDate&&!this._selectedEndDate?this._isSameDate(e,this._selectedStartDate):!1:this._selectedStartDate!==null&&this._isSameDate(e,this._selectedStartDate)}_isDateInRange(e){let t=this.getSelectionMode();if((this._isRange||t===`week`||t===`month`)&&this._selectedStartDate&&this._selectedEndDate)return this._rangeIncludesDisabledDates(this._selectedStartDate,this._selectedEndDate)?!1:e>=this._selectedStartDate&&e<=this._selectedEndDate;if(this._isRange&&this._selectedStartDate&&!this._selectedEndDate&&this._hoveredDate){let t=this._selectedStartDate<this._hoveredDate?this._selectedStartDate:this._hoveredDate,n=this._selectedStartDate<this._hoveredDate?this._hoveredDate:this._selectedStartDate;if(this._rangeIncludesDisabledDates(t,n)){let r=this._findFirstDisabledDateInRange(t,n);return r?this._selectedStartDate<this._hoveredDate?e>=t&&e<r&&!this._isSameDate(e,t):e>r&&e<=n&&!this._isSameDate(e,n):!1}return e>=t&&e<=n&&!this._isSameDate(e,t)&&!this._isSameDate(e,n)}return!1}_rangeIncludesDisabledDates(e,t){let n=this.getDisabledDates(),r=new Date(e.getFullYear(),e.getMonth(),e.getDate()),i=new Date(t.getFullYear(),t.getMonth(),t.getDate());return n.some(e=>{let t=new Date(e.getFullYear(),e.getMonth(),e.getDate());return t>=r&&t<=i})}_findFirstDisabledDateInRange(e,t){let n=this.getDisabledDates(),r=new Date(e.getFullYear(),e.getMonth(),e.getDate()),i=new Date(t.getFullYear(),t.getMonth(),t.getDate()),a=n.map(e=>new Date(e.getFullYear(),e.getMonth(),e.getDate())).filter(e=>e>=r&&e<=i).sort((e,t)=>e.getTime()-t.getTime());return a.length>0?a[0]:null}_hasIncompleteRange(){return this._isRange&&this._selectedStartDate!==null&&this._selectedEndDate===null}_isSameDate(e,t){return e.getDate()===t.getDate()&&e.getMonth()===t.getMonth()&&e.getFullYear()===t.getFullYear()}_isDateDisabled(e){return this.getDisabledDates().some(t=>this._isSameDate(e,t))}_dispatchMonthChangeEvent(e,t,n,r){(e!==n||t!==r)&&this.dispatchEvent(new CustomEvent(`month-change`,{detail:{month:n,year:r,oldMonth:e,oldYear:t},bubbles:!0,cancelable:!0,composed:!0}))}_dispatchDateChangeEvent(){let e=this.getFormat(),t={value:this.getValue()};this._selectedStartDate&&(t.startDate=this._selectedStartDate,t.startDateFormatted=this._formatDate(this._selectedStartDate,e)),this._selectedEndDate&&(t.endDate=this._selectedEndDate,t.endDateFormatted=this._formatDate(this._selectedEndDate,e)),this.dispatchEvent(new CustomEvent(`date-change`,{detail:t,bubbles:!0,cancelable:!0,composed:!0}))}_setupContainerObserver(){if(this._resizeObserver&&=(this._resizeObserver.disconnect(),null),!this._inputsWrapperEl)return;let e=e=>{this._inputsWrapperEl&&(e<400?(this._inputsWrapperEl.classList.add(`is-wrapping`),this._inputsWrapperEl.classList.remove(`is-nowrap`)):(this._inputsWrapperEl.classList.remove(`is-wrapping`),this._inputsWrapperEl.classList.add(`is-nowrap`)))};e(this._inputsWrapperEl.offsetWidth||this.offsetWidth),this._resizeObserver=new ResizeObserver(t=>{for(let n of t){let t=n.contentRect.width;e(t)}}),this._resizeObserver.observe(this)}_getWeekStart(e){let t=this.getWeekStartDay(),n=e.getDay(),r;r=n>=t?n-t:7-(t-n);let i=new Date(e);return i.setDate(e.getDate()-r),i.setHours(0,0,0,0),i}_getWeekEnd(e){let t=this._getWeekStart(e),n=new Date(t);return n.setDate(t.getDate()+6),n.setHours(23,59,59,999),n}_getMonthStart(e){let t=new Date(e.getFullYear(),e.getMonth(),1);return t.setHours(0,0,0,0),t}_getMonthEnd(e){let t=new Date(e.getFullYear(),e.getMonth()+1,0);return t.setHours(23,59,59,999),t}_handleDateClick(e){this._isHandlingClick=!0;try{let t=this.getFormat(),n=this.getSelectionMode(),r,i;if(n===`week`?(r=this._getWeekStart(e),i=this._getWeekEnd(e)):n===`month`?(r=this._getMonthStart(e),i=this._getMonthEnd(e)):(r=e,i=e),this.isRange()||n===`week`||n===`month`)if(n===`week`||n===`month`){if(this._rangeIncludesDisabledDates(r,i)){this._buildCalendar();return}this._selectedStartDate=r,this._selectedEndDate=i;let e=`${this._formatDate(this._selectedStartDate,t)} - ${this._formatDate(this._selectedEndDate,t)}`;this.setValue(e),this._textInput&&(this._textInput.value=e),this._popover&&typeof this._popover.close==`function`&&this._popover.close()}else if(this._hoveredDate=null,this._selectedStartDate===null){if(this._isDateDisabled(r)){this._buildCalendar();return}this._selectedStartDate=new Date(r.getFullYear(),r.getMonth(),r.getDate()),this._selectedEndDate=null,this._currentMonth=this._selectedStartDate.getMonth(),this._currentYear=this._selectedStartDate.getFullYear(),this._hoveredDate=null,this._buildCalendar()}else if(this._selectedEndDate===null){let n=new Date(e.getFullYear(),e.getMonth(),e.getDate()),r=this._selectedStartDate?new Date(this._selectedStartDate.getFullYear(),this._selectedStartDate.getMonth(),this._selectedStartDate.getDate()):null,i,a;if(r&&n<r?(i=n,a=r):(i=r,a=n),this._rangeIncludesDisabledDates(i,a)){this._buildCalendar();return}r&&n<r?(this._selectedEndDate=r,this._selectedStartDate=n):(this._selectedEndDate=n,r&&(this._selectedStartDate=r)),this._currentMonth=this._selectedStartDate.getMonth(),this._currentYear=this._selectedStartDate.getFullYear();let o=`${this._formatDate(this._selectedStartDate,t)} - ${this._formatDate(this._selectedEndDate,t)}`;this.setAttribute(`value`,o),this._textInput&&(this._textInput.value=o),this._hiddenInput&&(this._hiddenInput.value=o),this._updateDisplayText(),this._buildCalendar(),this._popover&&typeof this._popover.close==`function`&&this._popover.close()}else this._selectedStartDate=r,this._selectedEndDate=null;else{this._selectedStartDate=r,this._selectedEndDate=null;let e=this._formatDate(r,t);this.setValue(e),this._textInput&&(this._textInput.value=e),this._popover&&typeof this._popover.close==`function`&&this._popover.close()}this._buildCalendar(),this._updateDisplayText(),this._exitInputMode();let a=new Event(`input`,{bubbles:!0,cancelable:!0,composed:!0});this.dispatchEvent(a),this.dispatchEvent(new CustomEvent(`input`,{detail:{value:this.getValue()},bubbles:!0,cancelable:!0,composed:!0})),this.dispatchEvent(new CustomEvent(`change`,{detail:{value:this.getValue()},bubbles:!0,cancelable:!0,composed:!0})),this._dispatchDateChangeEvent()}finally{this._isHandlingClick=!1}}_updateDisplayText(){if(!this._displayEl)return;let e=this.getDisplayFormat(),t=this.getSelectionMode(),n=this._isRange||t===`week`||t===`month`,r=``;n&&this._selectedStartDate&&this._selectedEndDate?r=`${this._formatDatePhp(this._selectedStartDate,e)} - ${this._formatDatePhp(this._selectedEndDate,e)}`:this._selectedStartDate&&(r=this._formatDatePhp(this._selectedStartDate,e)),r?(this._displayEl.textContent=r,this._displayEl.classList.remove(`is-empty`)):(this._displayEl.textContent=`Select date`,this._displayEl.classList.add(`is-empty`)),this._displayEl&&this._inputsWrapperEl&&this.classList.toggle(`is-input-mode`,this._isInputMode)}_enterInputMode(){if(!this._isInputMode&&!(this.isReadonly()||this.isDisabled())&&(this._isInputMode=!0,this._displayEl&&this._inputsWrapperEl&&this.classList.add(`is-input-mode`),this._startPartInputs.length>0)){let e=this._startPartInputs[0];requestAnimationFrame(()=>{e.focus();try{e.setSelectionRange(0,e.value.length)}catch{}})}}_exitInputMode(){this._isInputMode&&(this._isInputMode=!1,this._displayEl&&this._inputsWrapperEl&&this.classList.remove(`is-input-mode`),this._updateDisplayText())}_renderSkeleton(e){let t=this.querySelector(`.mint-date-picker-skeleton-container`);this._fieldsContainer;let n=this._input;if(e){t||(t=document.createElement(`div`),t.className=`mint-date-picker-skeleton-container`,n?n.appendChild(t):(this.classList.add(`is-positioned`),this.appendChild(t)));let e=t.querySelector(`.mint-date-picker-skeleton`);e||(e=document.createElement(`div`),e.className=`mint-date-picker-skeleton`,t.appendChild(e)),this.classList.add(`is-loading`)}else t?.remove(),this.classList.remove(`is-loading`,`is-positioned`)}_getFocusableElements(){if(!this._calendarContainer)return[];let e=[`button:not([disabled])`,`a[href]`,`input:not([disabled]):not([type="hidden"])`,`select:not([disabled])`,`textarea:not([disabled])`,`[tabindex]:not([tabindex="-1"])`].join(`, `);return Array.from(this._calendarContainer.querySelectorAll(e)).filter(e=>{let t=window.getComputedStyle(e);return t.display!==`none`&&t.visibility!==`hidden`})}_setupFocusTrap(){if(!this._popover||!this._popover.hasAttribute(`open`))return;this._removeFocusTrap();let e=this;this._focusTrapHandler=function(t){if(t.key!==`Tab`)return;if(!e._popover||!e._popover.hasAttribute(`open`)){e._removeFocusTrap();return}let n=e._getFocusableElements();if(n.length===0)return;let r=n[0],i=n[n.length-1],a=document.activeElement;if(!e._calendarContainer?.contains(a)){t.preventDefault(),r.focus();return}if(t.shiftKey&&a===r){t.preventDefault(),i.focus();return}if(!t.shiftKey&&a===i){t.preventDefault(),r.focus();return}},this._escapeHandler=function(t){(t.key===`Escape`||t.key===`Esc`)&&e._popover&&e._popover.hasAttribute(`open`)&&(t.preventDefault(),t.stopPropagation(),typeof e._popover.close==`function`&&e._popover.close())},document.addEventListener(`keydown`,this._focusTrapHandler,!0),document.addEventListener(`keydown`,this._escapeHandler,!0),requestAnimationFrame(()=>{let e=this._getFocusableElements();e.length>0&&e[0].focus()})}_removeFocusTrap(){this._focusTrapHandler&&=(document.removeEventListener(`keydown`,this._focusTrapHandler,!0),null),this._escapeHandler&&=(document.removeEventListener(`keydown`,this._escapeHandler,!0),null)}};customElements.get(`mint-date-picker`)||t.t(`mint-date-picker`,n),module.exports=n;
|
|
1
|
+
const e=require(`../chunks/icon-B_7c8b8e.js`),t=require(`../chunks/register-element-tCL_F1YI.js`);require(`../chunks/icon-CSqBgTae.js`),require(`../chunks/caret-right-3V_JDnOP.js`),require(`../chunks/input-lLl8cB6r.js`),require(`../chunks/popover-BeaGf_JC.js`),e.a({name:`calendar`,viewBox:`0 0 24 24`,path:`M8 7V3m8 4V3M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2zM6 11h12M6 14h12M6 17h12`,strokeLinecap:`round`,strokeLinejoin:`round`}),e.a({name:`caret-left`,viewBox:`0 0 24 24`,path:`M15 19l-7-7 7-7`,strokeLinecap:`round`,strokeLinejoin:`round`});var n=class extends HTMLElement{static get observedAttributes(){return[`value`,`label`,`info`,`disabled`,`id`,`name`,`required`,`readonly`,`format`,`min`,`max`,`range`,`shortcuts`,`display-format`,`error`,`error-message`,`loading`,`selection-mode`,`week-start-day`,`mode`,`disabled-dates`]}constructor(){super(),this._input=null,this._textInput=null,this._popover=null,this._calendarContainer=null,this._iconButton=null,this._hiddenInput=null,this._startPartInputs=[],this._endPartInputs=[],this._displayEl=null,this._inputsWrapperEl=null,this._fieldsContainer=null,this._resetHandler=null,this._isInputMode=!1,this._currentMonth=new Date().getMonth(),this._currentYear=new Date().getFullYear(),this._viewMode=`calendar`,this._selectedStartDate=null,this._selectedEndDate=null,this._isRange=!1,this._hoveredDate=null,this._isHandlingClick=!1,this._touchStartDate=null,this._touchStartElement=null,this._isTouchActive=!1,this._resizeObserver=null,this._popoverObserver=null,this._focusTrapHandler=null,this._escapeHandler=null,this._a11yId=`mint-date-picker-${Math.random().toString(36).slice(2,10)}`}connectedCallback(){this.classList.add(`mint-date-picker`),this.render(),this._setupPopoverWithRetry(),this._attachFormResetListener()}disconnectedCallback(){if(this._popoverObserver&&=(this._popoverObserver.disconnect(),null),this._resizeObserver&&=(this._resizeObserver.disconnect(),null),this._removeFocusTrap(),this._resetHandler){let e=this.closest(`form`);e&&e.removeEventListener(`reset`,this._resetHandler),this._resetHandler=null}}isLoading(){return this.getAttribute(`loading`)===`true`}attributeChangedCallback(e,t,n){if(t!==n){if(e===`error`||e===`error-message`){let e=this.hasError(),t=this.getErrorMessage();this._applyErrorVisuals(e,t,this.isDisabled());return}if(e===`loading`){this.render();return}if(e===`mode`||e===`format`){let e=this.getMode();e===`month`?this._viewMode=`month`:e===`year`?this._viewMode=`year`:this._viewMode=`calendar`,this._popover&&this._calendarContainer&&this._buildCalendar()}this.render(),this._input&&this._setupPopoverWithRetry()}}getValue(){return this.getAttribute(`value`)||``}setValue(e){e?(this.setAttribute(`value`,e),this._textInput&&(this._textInput.value=e),this._parseValue(e)):(this.removeAttribute(`value`),this._textInput&&(this._textInput.value=``),this._selectedStartDate=null,this._selectedEndDate=null),this._buildCalendar(),this._updateDisplayText()}get value(){try{return this.getValue()||``}catch{return``}}set value(e){try{this.setValue(e||``)}catch{}}getFormat(){return this.getAttribute(`format`)||`mm/dd/yyyy`}getLabel(){return this.getAttribute(`label`)||``}getInfo(){return this.getAttribute(`info`)||``}isDisabled(){return this.getAttribute(`disabled`)===`true`}isReadonly(){return this.getAttribute(`readonly`)===`true`}isRequired(){return this.getAttribute(`required`)===`true`}hasError(){return this.getAttribute(`error`)===`true`}getErrorMessage(){return this.getAttribute(`error-message`)||``}isRange(){return this.getAttribute(`range`)===`true`}getId(){return this.getAttribute(`id`)||``}getName(){return this.getAttribute(`name`)||``}getMin(){return this.getAttribute(`min`)||``}getMax(){return this.getAttribute(`max`)||``}getDisabledDates(){let e=this.getAttribute(`disabled-dates`);if(!e)return[];try{let t=JSON.parse(e),n=this.getFormat();return t.map(e=>this._parseDateString(e,n)).filter(e=>e!==null)}catch{return[]}}getDisabledDateStrings(){let e=this.getAttribute(`disabled-dates`);if(!e)return[];try{return JSON.parse(e)}catch{return[]}}disableDate(e){let t=this.getFormat(),n=this.getDisabledDateStrings(),r=Array.isArray(e)?e:[e],i=[];for(let e of r){let r=this._parseDateString(e,t);if(r){let e=this._formatDate(r,t);n.includes(e)||i.push(e)}}if(i.length>0){let e=[...n,...i];this.setAttribute(`disabled-dates`,JSON.stringify(e)),this._buildCalendar()}}enableDate(e){let t=this.getFormat(),n=this.getDisabledDateStrings(),r=Array.isArray(e)?e:[e],i=[];for(let e of r){let n=this._parseDateString(e,t);if(n){let e=this._formatDate(n,t);i.push(e)}}if(i.length>0){let e=n.filter(e=>!i.includes(e));e.length===0?this.removeAttribute(`disabled-dates`):this.setAttribute(`disabled-dates`,JSON.stringify(e)),this._buildCalendar()}}getSelectionMode(){let e=this.getAttribute(`selection-mode`);return e===`week`||e===`month`?e:`day`}getMode(){let e=this.getAttribute(`mode`);if(e===`month`||e===`year`)return e;let t=this.getFormat().toLowerCase(),n=t.includes(`d`),r=t.includes(`m`);return!n&&!r?`year`:!n&&r?`month`:`default`}getWeekStartDay(){return{sunday:0,monday:1,tuesday:2,wednesday:3,thursday:4,friday:5,saturday:6}[this.getAttribute(`week-start-day`)?.toLowerCase()||`sunday`]??0}getDisplayFormat(){return this.getAttribute(`display-format`)||`F j, Y`}getShortcuts(){let e=this.getAttribute(`shortcuts`);if(!e)return[];try{let t=JSON.parse(e);if(Array.isArray(t))return t.map(e=>({label:e.label,action:this._createShortcutAction(e.action)}))}catch{let t=e.trim();if(t&&typeof window[t]==`function`){let e=window[t]();if(Array.isArray(e))return e.map(e=>({label:e.label,action:typeof e.action==`function`?e.action:this._createShortcutAction(e.action)}))}}return[]}_createShortcutAction(e){return typeof e==`function`?e:typeof e==`string`&&typeof window[e]==`function`?window[e]:()=>null}_getDefaultShortcuts(){let e=[{label:`Today`,action:()=>new Date}];return this._isRange&&e.push({label:`This Week`,action:()=>{let e=new Date,t=e.getDay(),n=new Date(e);n.setDate(e.getDate()-t),n.setHours(0,0,0,0);let r=new Date(n);return r.setDate(n.getDate()+6),r.setHours(23,59,59,999),{start:n,end:r}}},{label:`This Month`,action:()=>{let e=new Date,t=new Date(e.getFullYear(),e.getMonth(),1),n=new Date(e.getFullYear(),e.getMonth()+1,0);return n.setHours(23,59,59,999),{start:t,end:n}}}),e}_getFormatTokens(e){let t=[],n=0,r=e.toLowerCase();for(;n<r.length;){let i=r[n];if(i===`d`||i===`m`||i===`y`){let e=1,a=n+1;for(;a<r.length&&r[a]===i;)e++,a++;t.push({type:`part`,part:i,len:e}),n=a}else t.push({type:`sep`,value:e[n]}),n++}return t}_createPartInput(e,t,n,r,i){let a=document.createElement(`input`);return a.type=`text`,a.inputMode=`numeric`,a.pattern=`\\d*`,a.maxLength=e,a.placeholder=t,a.className=`mint-date-picker-part-input`,a.disabled=n||r,a.readOnly=r,a.required=i,e===4?a.classList.add(`is-year-part`):e===2&&a.classList.add(`is-short-part`),a}_buildValueFromParts(e,t){let n=0;return t.map(t=>{if(t.type===`sep`)return t.value;let r=e[n]?.value||``;return n++,r}).join(``)}_applyDateToParts(e,t,n,r){if(!t.length)return;if(!e){t.forEach(e=>e.value=``);return}let i=this._formatDate(e,r),a=0,o=0;n.forEach(e=>{if(e.type===`sep`)a+=e.value.length;else{let n=i.substr(a,e.len);t[o]&&(t[o].value=n),o++,a+=e.len}})}_syncHiddenInput(){if(!this._hiddenInput)return;let e=this.getFormat(),t=this._getFormatTokens(e),n=this._buildValueFromParts(this._startPartInputs,t);if(this._isRange){let e=this._buildValueFromParts(this._endPartInputs,t);this._hiddenInput.value=e?`${n} - ${e}`:n}else this._hiddenInput.value=n}_focusNext(e,t){if(t+1<e.length){let n=e[t+1];n.focus(),n.setSelectionRange(0,n.value.length)}}_focusPrev(e,t){if(t-1>=0){let n=e[t-1];n.focus(),n.setSelectionRange(n.value.length,n.value.length)}}_attachPartInputHandlers(e,t,n){e.forEach((t,n)=>{let r=t.maxLength||2;t.addEventListener(`input`,()=>{t.value=t.value.replace(/\D/g,``).slice(0,r),t.value.length>=r&&this._focusNext(e,n),this._syncHiddenInput()}),t.addEventListener(`keydown`,r=>{r.key===`Backspace`&&t.selectionStart===0&&t.selectionEnd===0&&this._focusPrev(e,n),r.key===`ArrowLeft`&&t.selectionStart===0&&t.selectionEnd===0&&(this._focusPrev(e,n),r.preventDefault()),r.key===`ArrowRight`&&t.selectionStart===t.value.length&&t.selectionEnd===t.value.length&&(this._focusNext(e,n),r.preventDefault())}),t.addEventListener(`blur`,e=>{this._syncHiddenInput();let t=e.relatedTarget,n=t&&(this._startPartInputs.includes(t)||this._endPartInputs.includes(t));setTimeout(()=>{if(!(this._startPartInputs.some(e=>e===document.activeElement)||this._endPartInputs.some(e=>e===document.activeElement))&&(n||this._handleBlur(this._hiddenInput?.value||``),this._exitInputMode(),!n&&this._hiddenInput)){let t=new FocusEvent(`blur`,{bubbles:!0,cancelable:!0,relatedTarget:e.relatedTarget});this._hiddenInput.dispatchEvent(t)}},0)})})}_splitRangeInput(e,t){let n=e.split(/\s*-\s*/);return n.length>=2?[n[0],n.slice(1).join(`-`)]:[e]}_parseValue(e){let t=this.getFormat(),n=this._getFormatTokens(t),r=this.getSelectionMode();if(this._isRange||r===`week`||r===`month`){let[r,i]=this._splitRangeInput(e,t),a=r?this._parseDateString(r,t):null,o=i?this._parseDateString(i,t):null;if(a&&o){let[e,t]=a<=o?[a,o]:[o,a];this._selectedStartDate=e,this._selectedEndDate=t,this._currentMonth=e.getMonth(),this._currentYear=e.getFullYear()}else a&&(this._selectedStartDate=a,this._selectedEndDate=null,this._currentMonth=a.getMonth(),this._currentYear=a.getFullYear());this._applyDateToParts(this._selectedStartDate,this._startPartInputs,n,t),this._applyDateToParts(this._selectedEndDate,this._endPartInputs,n,t)}else{let r=this._parseDateString(e,t);r&&!isNaN(r.getTime())?(this._selectedStartDate=r,this._selectedEndDate=null,this._currentMonth=r.getMonth(),this._currentYear=r.getFullYear(),this._applyDateToParts(r,this._startPartInputs,n,t)):this._applyDateToParts(null,this._startPartInputs,n,t)}this._syncHiddenInput(),this._updateDisplayText()}_parseDateString(e,t){let n=/[\/\-\.\s]+/;if(n.test(e)){let r=e.split(n).filter(e=>e.length>0),i=t.split(/[\/\-\.\s]+/).filter(e=>e.length>0);if(r.length===i.length){let e=0,t=0,n=0;for(let a=0;a<i.length;a++){let o=i[a].toLowerCase(),s=r[a];if(o.includes(`d`))e=parseInt(s,10);else if(o.includes(`m`))t=parseInt(s,10)-1;else if(o.includes(`y`)){let e=parseInt(s,10),t=o.length,r=s.length;(r===2&&t===4||r===2&&t===2)&&(e=Math.floor(new Date().getFullYear()/100)*100+e),n=e}}let a=i.some(e=>e.toLowerCase().includes(`d`)),o=i.some(e=>e.toLowerCase().includes(`m`));if(a||(e=1),o||(t=0),t>=0&&t<=11&&n){let r=new Date(n,t,e);if(!isNaN(r.getTime()))return a&&r.getDate()!==e||r.getMonth()!==t||r.getFullYear()!==n?null:r}}}let r=e.replace(/[\/\-\.]/g,``),i=t.replace(/[\/\-\.]/g,``).toLowerCase(),a=i.indexOf(`d`),o=i.indexOf(`m`),s=i.indexOf(`y`),c=[{char:`d`,index:a},{char:`m`,index:o},{char:`y`,index:s}].sort((e,t)=>e.index-t.index),l=0,u=0,d=0,f=0;i.length,r.length;for(let e of c)if(e.char===`d`){let e=i.lastIndexOf(`d`)-i.indexOf(`d`)+1,t=r.substr(f,e);if(t.length===0)return null;l=parseInt(t,10),f+=t.length}else if(e.char===`m`){let e=i.lastIndexOf(`m`)-i.indexOf(`m`)+1,t=r.substr(f,e);if(t.length===0)return null;u=parseInt(t,10)-1,f+=t.length}else if(e.char===`y`){let e=i.lastIndexOf(`y`)-i.indexOf(`y`)+1,t=r.substr(f),n=Math.min(e,t.length),a=t.substr(0,n);if(a.length===0)return null;let o=parseInt(a,10);(n===2&&e===4||n===2&&e===2)&&(o=Math.floor(new Date().getFullYear()/100)*100+o),d=o,f+=n}let p=t.toLowerCase(),m=p.includes(`d`),h=p.includes(`m`);if(m||(l=1),h||(u=0),u<0||u>11||!d)return null;let g=new Date(d,u,l);return isNaN(g.getTime())||m&&g.getDate()!==l||g.getMonth()!==u||g.getFullYear()!==d?null:g}_formatDate(e,t){let n=e.getDate(),r=e.getMonth()+1,i=e.getFullYear(),a=t.toLowerCase(),o=t;return a.includes(`dd`)?o=o.replace(/dd/gi,String(n).padStart(2,`0`)):a.includes(`d`)&&(o=o.replace(/d/gi,String(n))),a.includes(`mm`)?o=o.replace(/mm/gi,String(r).padStart(2,`0`)):a.includes(`m`)&&(o=o.replace(/m/gi,String(r))),a.includes(`yyyy`)?o=o.replace(/yyyy/gi,String(i)):a.includes(`yy`)&&(o=o.replace(/yy/gi,String(i).substr(2))),o}_formatDatePhp(e,t){let n=e.getDate(),r=e.getMonth()+1,i=e.getFullYear(),a=[`Sunday`,`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`],o=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`],s=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],c=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],l=(e,t=2)=>e.toString().padStart(t,`0`),u=e=>{let t=e%10,n=e%100;return t===1&&n!==11?`st`:t===2&&n!==12?`nd`:t===3&&n!==13?`rd`:`th`},d=``;for(let f=0;f<t.length;f++){let p=t[f];if(p===`\\`&&f+1<t.length){d+=t[f+1],f++;continue}switch(p){case`Y`:d+=i.toString();break;case`y`:d+=i.toString().slice(-2);break;case`m`:d+=l(r);break;case`n`:d+=r.toString();break;case`M`:d+=c[r-1];break;case`F`:d+=s[r-1];break;case`d`:d+=l(n);break;case`j`:d+=n.toString();break;case`D`:d+=o[e.getDay()];break;case`l`:d+=a[e.getDay()];break;case`S`:d+=u(n);break;default:d+=p;break}}return d}_validateDateString(e,t){let n=this._parseDateString(e,t);return n!==null&&!isNaN(n.getTime())}render(){let e=this.isLoading(),t=this.getLabel(),n=this.getInfo(),r=this.getValue(),i=this.isDisabled(),a=this.isReadonly(),o=this.isRequired(),s=this.getId()||this._a11yId,c=this.getName(),l=this.getFormat(),u=this.hasError(),d=this.getErrorMessage(),f=this.getSelectionMode();this._isRange=this.isRange()||f===`week`||f===`month`,this._input||(this._input=document.createElement(`div`),this._input.className=`mint-date-picker-field`,this.appendChild(this._input));let p=this.querySelector(`.mint-date-picker-label-container`);if(t||n){p||(p=document.createElement(`div`),p.className=`mint-date-picker-label-container`,this.contains(this._input)?this.insertBefore(p,this._input):this.appendChild(p));let e=p.querySelector(`.mint-date-picker-label`);t?(e||(e=document.createElement(`label`),e.className=`mint-date-picker-label`,p.insertBefore(e,p.firstChild)),e.textContent=t,s&&this._textInput&&e.setAttribute(`for`,s)):e&&e.remove();let r=p.querySelector(`.mint-date-picker-info`);n?(r||(r=document.createElement(`span`),r.className=`mint-date-picker-info`,p.appendChild(r)),r.textContent=n):r&&r.remove()}else p&&p.remove();this._hiddenInput||(this._hiddenInput=document.createElement(`input`),this._hiddenInput.type=`hidden`,this._hiddenInput.value=r||``,this._textInput=this._hiddenInput,this._input.appendChild(this._hiddenInput)),s&&(this._hiddenInput.id=s),c&&(this._hiddenInput.name=c),this._hiddenInput.value=r||``,this._hiddenInput.setAttribute(`aria-invalid`,u?`true`:`false`);let m=this._input.querySelector(`.mint-date-fields`);m||(m=document.createElement(`div`),this._input.appendChild(m)),this._fieldsContainer=m,this._applyErrorVisuals(u,d,i),m.innerHTML=``,this._displayEl=document.createElement(`div`),this._displayEl.className=`mint-date-picker-display${a?` is-readonly`:``}`,this._displayEl.tabIndex=i||a?-1:0,this._displayEl.setAttribute(`role`,`button`),this._displayEl.setAttribute(`aria-label`,`${this.getLabel()||`Date`}: ${r||`Select date`}`),this._displayEl.addEventListener(`click`,()=>{i||a||this._enterInputMode()}),this._displayEl.addEventListener(`keydown`,e=>{i||a||(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),this._enterInputMode())}),this._inputsWrapperEl=document.createElement(`div`),this._isRange,this._inputsWrapperEl.className=`mint-date-picker-inputs`;let h=this._getFormatTokens(l);this._startPartInputs=[],this._endPartInputs=[];let g=e=>{let t=document.createDocumentFragment();return h.forEach(n=>{if(n.type===`sep`){let e=document.createElement(`span`);e.textContent=n.value,e.className=`mint-date-picker-separator`,t.appendChild(e)}else{let r=n.part===`d`?`dd`:n.part===`m`?`mm`:n.len===2?`yy`:`yyyy`,s=this._createPartInput(n.len,r,i,a,o),c=n.part===`d`?`day`:n.part===`m`?`month`:`year`,l=this.getLabel()||`Date`;s.setAttribute(`aria-label`,`${e===`end`?`End ${l.toLowerCase()}`:l} ${c}`),e===`start`?this._startPartInputs.push(s):this._endPartInputs.push(s),t.appendChild(s)}}),t};if(this._isRange){let e=document.createElement(`div`);e.className=`mint-date-picker-range-part`,e.appendChild(g(`start`)),this._inputsWrapperEl.appendChild(e);let t=document.createElement(`span`);t.textContent=` - `,t.className=`mint-date-picker-range-dash`,this._inputsWrapperEl.appendChild(t);let n=document.createElement(`div`);n.className=`mint-date-picker-range-part`,n.appendChild(g(`end`)),this._inputsWrapperEl.appendChild(n)}else this._inputsWrapperEl.appendChild(g(`start`));let _=document.createElement(`div`);if(_.className=`mint-date-picker-stacked`,this.classList.toggle(`is-input-mode`,this._isInputMode),_.appendChild(this._displayEl),_.appendChild(this._inputsWrapperEl),m.appendChild(_),this._isRange&&this._inputsWrapperEl&&this._setupContainerObserver(),m.addEventListener(`click`,()=>{this._isInputMode||i||a||this._enterInputMode()}),this._attachPartInputHandlers(this._startPartInputs,h,m),this._isRange&&this._attachPartInputHandlers(this._endPartInputs,h,m),this._parseValue(r),this._syncHiddenInput(),this._updateDisplayText(),this._iconButton)this._iconButton.disabled=i||a,!i&&!a?this._iconButton.tabIndex=0:this._iconButton.tabIndex=-1;else{this._iconButton=document.createElement(`button`),this._iconButton.type=`button`,this._iconButton.tabIndex=0,this._iconButton.className=`mint-date-picker-icon-button`,this._iconButton.setAttribute(`aria-label`,`Open calendar`),this._iconButton.setAttribute(`aria-haspopup`,`dialog`),this._iconButton.setAttribute(`aria-expanded`,`false`);let e=`date-icon-${Math.random().toString(36).substr(2,9)}`;this._iconButton.id=e;let t=document.createElement(`mint-icon`);t.setAttribute(`name`,`calendar`),t.className=`mint-date-picker-icon`,this._iconButton.appendChild(t),this._input.prepend(this._iconButton),this._iconButton.disabled=i||a}this._renderErrorState(u,d),this._syncDateFieldDescriptions(),this._renderSkeleton(e)}_renderErrorState(e,t){let n=this.querySelector(`.mint-date-picker-error`);e&&t?(n||(n=document.createElement(`div`),n.className=`mint-date-picker-error`,this.appendChild(n)),n.textContent=t):n&&n.remove()}_syncDateFieldDescriptions(){let e=Array.from(this.querySelectorAll(`.mint-date-fields input`));if(!e.length)return;let t=(this.getAttribute(`aria-describedby`)||``).split(/\s+/).filter(Boolean),n=this.querySelector(`.mint-date-picker-info`),r=this.querySelector(`.mint-date-picker-error`),i=this.getAttribute(`id`)||this._a11yId;n&&(n.id=`${i}-info`,t.push(n.id)),r&&(r.id=`${i}-error`,t.push(r.id));let a=Array.from(new Set(t)).join(` `);e.forEach(e=>{e.setAttribute(`aria-invalid`,String(this._hiddenInput?.getAttribute(`aria-invalid`)===`true`)),a?e.setAttribute(`aria-describedby`,a):e.removeAttribute(`aria-describedby`)})}_applyErrorVisuals(e,t,n){if(this._renderErrorState(e,t),this._fieldsContainer){let t=this._getFieldContainerClass(e,n);this._fieldsContainer.className=t}this._hiddenInput&&this._hiddenInput.setAttribute(`aria-invalid`,e?`true`:`false`),this._syncDateFieldDescriptions()}_attachFormResetListener(){let e=this.closest(`form`);!e||this._resetHandler||(this._resetHandler=()=>{this.setValue(``),this._clearPartInputs(this._startPartInputs),this._clearPartInputs(this._endPartInputs),this._isInputMode=!1,this._updateDisplayText(),this._applyErrorVisuals(!1,``,this.isDisabled())},e.addEventListener(`reset`,this._resetHandler))}_clearPartInputs(e){e.forEach(e=>{e.value=``})}_getFieldContainerClass(e,t){return`mint-date-fields${e?` has-error`:``}${t?` is-disabled`:``}`}_handleInputChange(e){}_cleanInputValue(e,t){return e}_handleBlur(e){let t=this.getFormat(),n=this.getSelectionMode(),r=this._isRange||n===`week`||n===`month`;if(!e){this.setValue(``),this._updateDisplayText();return}if(r){let[n,r]=this._splitRangeInput(e,t),i=n?this._parseDateString(n,t):null,a=r?this._parseDateString(r,t):null;if(i&&a){let[e,n]=i<=a?[i,a]:[a,i],r=`${this._formatDate(e,t)} - ${this._formatDate(n,t)}`;this.setValue(r),this._applyDateToParts(e,this._startPartInputs,this._getFormatTokens(t),t),this._applyDateToParts(n,this._endPartInputs,this._getFormatTokens(t),t),this._selectedStartDate=e,this._selectedEndDate=n,this._currentMonth=e.getMonth(),this._currentYear=e.getFullYear()}else if(i){let e=this._formatDate(i,t);this.setValue(e),this._applyDateToParts(i,this._startPartInputs,this._getFormatTokens(t),t),this._applyDateToParts(null,this._endPartInputs,this._getFormatTokens(t),t),this._selectedStartDate=i,this._selectedEndDate=null,this._currentMonth=i.getMonth(),this._currentYear=i.getFullYear()}else this.setValue(``),this._applyDateToParts(null,this._startPartInputs,this._getFormatTokens(t),t),this._applyDateToParts(null,this._endPartInputs,this._getFormatTokens(t),t),this._selectedStartDate=null,this._selectedEndDate=null}else if(this._validateDateString(e,t)){let n=this._parseDateString(e,t);if(n){let e=this._formatDate(n,t);this.setValue(e),this._applyDateToParts(n,this._startPartInputs,this._getFormatTokens(t),t),this._selectedStartDate=n,this._selectedEndDate=null,this._currentMonth=n.getMonth(),this._currentYear=n.getFullYear()}}else this.setValue(``),this._applyDateToParts(null,this._startPartInputs,this._getFormatTokens(t),t),this._selectedStartDate=null,this._selectedEndDate=null}_setupPopoverWithRetry(e=0){if(!this._iconButton){e<10&&requestAnimationFrame(()=>{this._setupPopoverWithRetry(e+1)});return}let t=this._iconButton.id;t&&this._iconButton.isConnected&&document.getElementById(t)?this._createPopover(t):e<10&&requestAnimationFrame(()=>{this._setupPopoverWithRetry(e+1)})}_createPopover(e){if(e){if(!document.getElementById(e)){setTimeout(()=>{this._createPopover(e)},50);return}if(this._popover){if(this._popover.getAttribute(`trigger-id`)!==e){this._popover.setAttribute(`trigger-id`,e);let t=this._popover;typeof t._setupTrigger==`function`&&t._setupTrigger()}this._buildCalendar()}else{this._popover=document.createElement(`mint-popover`),this._popover.classList.add(`mint-date-picker-popover`),this._popover.setAttribute(`direction`,`down`),this._popover.setAttribute(`padding`,`0`);let t=this.closest(`mint-modal`),n=this.closest(`mint-off-canvas`);t||n?document.body.appendChild(this._popover):this.parentNode?this.parentNode.insertBefore(this._popover,this.nextSibling):document.body.appendChild(this._popover),requestAnimationFrame(()=>{requestAnimationFrame(()=>{this._popover&&this._popover.isConnected&&(this._popover.setAttribute(`trigger-id`,e),this._popoverObserver||(this._popoverObserver=new MutationObserver(e=>{e.forEach(e=>{if(e.type===`attributes`&&e.attributeName===`open`)if(this._popover?.hasAttribute(`open`))requestAnimationFrame(()=>{this._buildCalendar();let e=this._popover;typeof e.render==`function`&&e.render(),this._setupFocusTrap()});else{if(this._removeFocusTrap(),this._iconButton&&!this._iconButton.disabled&&requestAnimationFrame(()=>{this._iconButton?.focus()}),this._viewMode=`calendar`,this._selectedStartDate)this._currentMonth=this._selectedStartDate.getMonth(),this._currentYear=this._selectedStartDate.getFullYear();else{let e=new Date;this._currentMonth=e.getMonth(),this._currentYear=e.getFullYear()}requestAnimationFrame(()=>{this._buildCalendar()}),this._hiddenInput&&(this._syncHiddenInput(),setTimeout(()=>{let e=new FocusEvent(`blur`,{bubbles:!0,cancelable:!0,relatedTarget:null});this._hiddenInput?.dispatchEvent(e)},0))}})}),this._popoverObserver.observe(this._popover,{attributes:!0,attributeFilter:[`open`]})),requestAnimationFrame(()=>{this._buildCalendar()}))})})}}}_buildCalendar(){if(!this._popover)return;this._calendarContainer&&this._calendarContainer.parentNode&&this._calendarContainer.remove(),this._calendarContainer=document.createElement(`div`),this._calendarContainer.className=`mint-date-calendar`;let e=this.getMode();e===`month`&&this._viewMode===`calendar`?this._viewMode=`month`:e===`year`&&this._viewMode===`calendar`?this._viewMode=`year`:e===`default`&&this._viewMode!==`month`&&this._viewMode!==`year`&&(this._viewMode=`calendar`),this._viewMode===`calendar`?this._buildCalendarView():this._viewMode===`month`?this._buildMonthView():this._viewMode===`year`&&this._buildYearView(),this._popover.replaceChildren(this._calendarContainer)}_buildCalendarView(){if(!this._calendarContainer)return;let e=this._getDaysInMonth(this._currentMonth,this._currentYear),t=this._getFirstDayOfMonth(this._currentMonth,this._currentYear),n=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],r=this.getWeekStartDay(),i=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`],a=[...i.slice(r),...i.slice(0,r)],o=this.getShortcuts(),s=o.length>0;this._calendarContainer.className=`mint-date-calendar${s?` has-shortcuts`:``}`;let c=document.createElement(`div`);c.className=`mint-date-calendar-layout`;let l=document.createElement(`div`);l.className=`mint-date-calendar-content`;let u=document.createElement(`div`);u.className=`mint-date-calendar-header`;let d=document.createElement(`button`);d.type=`button`,d.tabIndex=0,d.className=`mint-date-calendar-nav-button`,d.setAttribute(`aria-label`,`Previous month`),d.setAttribute(`data-keep-popover-open`,`true`);let f=document.createElement(`mint-icon`);f.setAttribute(`name`,`caret-left`),f.className=`mint-date-calendar-icon`,d.appendChild(f),d.addEventListener(`click`,()=>{let e=this._currentMonth,t=this._currentYear;this._currentMonth===0?(this._currentMonth=11,this._currentYear--):this._currentMonth--,this._buildCalendar(),this._dispatchMonthChangeEvent(e,t,this._currentMonth,this._currentYear)}),u.appendChild(d);let p=document.createElement(`div`);p.className=`mint-date-calendar-month-year`;let m=document.createElement(`button`);m.type=`button`,m.tabIndex=0,m.className=`mint-date-calendar-title-button`,m.setAttribute(`data-keep-popover-open`,`true`),m.textContent=n[this._currentMonth],m.setAttribute(`aria-label`,`Choose month, ${n[this._currentMonth]}`);let h=()=>{let e=this.getMode();e!==`month`&&e!==`year`&&(this._viewMode=`month`,this._buildCalendar())};m.addEventListener(`click`,h),m.addEventListener(`touchend`,e=>{e.preventDefault(),h()},{passive:!1}),p.appendChild(m);let g=document.createElement(`button`);g.type=`button`,g.tabIndex=0,g.className=`mint-date-calendar-title-button`,g.setAttribute(`data-keep-popover-open`,`true`),g.textContent=String(this._currentYear),g.setAttribute(`aria-label`,`Choose year, ${this._currentYear}`),g.addEventListener(`click`,()=>{this.getMode()!==`year`&&(this._viewMode=`year`,this._buildCalendar())}),p.appendChild(g),u.appendChild(p);let _=document.createElement(`button`);_.type=`button`,_.tabIndex=0,_.className=`mint-date-calendar-nav-button`,_.setAttribute(`aria-label`,`Next month`),_.setAttribute(`data-keep-popover-open`,`true`);let v=document.createElement(`mint-icon`);v.setAttribute(`name`,`caret-right`),v.className=`mint-date-calendar-icon`,_.appendChild(v);let y=()=>{let e=this._currentMonth,t=this._currentYear;this._currentMonth===11?(this._currentMonth=0,this._currentYear++):this._currentMonth++,this._buildCalendar(),this._dispatchMonthChangeEvent(e,t,this._currentMonth,this._currentYear)};_.addEventListener(`click`,y),_.addEventListener(`touchend`,e=>{e.preventDefault(),y()},{passive:!1}),u.appendChild(_);let b=document.createElement(`div`);b.className=`mint-date-calendar-day-names`,a.forEach(e=>{let t=document.createElement(`div`);t.className=`mint-date-calendar-day-name`,t.textContent=e,b.appendChild(t)});let x=document.createElement(`div`);x.className=`mint-date-calendar-grid`,x.setAttribute(`role`,`group`),x.setAttribute(`aria-label`,`${n[this._currentMonth]} ${this._currentYear}`);let S=this.getMin()?this._parseDateString(this.getMin(),this.getFormat()):null,C=this.getMax()?this._parseDateString(this.getMax(),this.getFormat()):null;this.getDisabledDates();let w=this._currentMonth===0?11:this._currentMonth-1,T=this._currentMonth===0?this._currentYear-1:this._currentYear,E=this._getDaysInMonth(w,T),D=this._currentMonth===11?0:this._currentMonth+1,O=this._currentMonth===11?this._currentYear+1:this._currentYear,k=t+e,A=Math.ceil(k/7)*7-k,j=(e,t,n)=>{let r=this._isToday(e),i=this._isDateSelected(e),a=this._isDateInRange(e),o=S&&e<S||C&&e>C||this._isDateDisabled(e),s=`is-fully-rounded`,c=this._isRange&&this._selectedStartDate&&!this._selectedEndDate&&this._hoveredDate,l=c&&this._selectedStartDate&&this._hoveredDate&&this._selectedStartDate<this._hoveredDate?this._selectedStartDate:c&&this._hoveredDate?this._hoveredDate:null,u=c&&this._selectedStartDate&&this._hoveredDate&&this._selectedStartDate<this._hoveredDate?this._hoveredDate:c&&this._selectedStartDate?this._selectedStartDate:null,d=l!==null&&this._isSameDate(e,l),f=u!==null&&this._isSameDate(e,u),p=this._hoveredDate!==null&&this._isSameDate(e,this._hoveredDate),m=c&&this._hoveredDate&&this._selectedStartDate?!this._rangeIncludesDisabledDates(this._selectedStartDate<this._hoveredDate?this._selectedStartDate:this._hoveredDate,this._selectedStartDate<this._hoveredDate?this._hoveredDate:this._selectedStartDate):!1;if(this._isRange&&this._selectedStartDate&&this._selectedEndDate){let t=this._isSameDate(e,this._selectedStartDate),n=this._isSameDate(e,this._selectedEndDate);t&&n?s=`is-fully-rounded`:t?s=`is-range-start`:n?s=`is-range-end`:a&&(s=`is-range-middle`)}else c&&(d||f)&&m?d&&f?s=`is-fully-rounded`:d?s=`is-range-start`:f&&(s=`is-range-end`):i&&!this._isRange||i&&this._isRange&&!this._selectedEndDate?s=`is-fully-rounded`:a&&c&&m&&(s=`is-range-middle`);let h=document.createElement(`button`);h.type=`button`,h.disabled=!!o,h.tabIndex=o?-1:0;let g=[`mint-date-picker-day`,s],_=i||c&&p&&m;return n||g.push(`is-outside-month`),_&&g.push(`is-selected`),a&&!_&&g.push(`is-in-range`),r&&!_&&g.push(`is-today`),o&&g.push(`is-disabled`),h.className=g.join(` `),h.textContent=t.toString(),h.setAttribute(`aria-label`,e.toLocaleDateString(void 0,{weekday:`long`,year:`numeric`,month:`long`,day:`numeric`})),h.setAttribute(`aria-pressed`,String(i)),r&&h.setAttribute(`aria-current`,`date`),o||(h.addEventListener(`click`,t=>{t.preventDefault(),t.stopPropagation(),this._handleDateClick(e)}),h.addEventListener(`touchstart`,t=>{t.preventDefault(),t.stopPropagation(),this._isTouchActive=!0,this._touchStartDate=e,this._touchStartElement=h,h.classList.add(`is-touch-active`)},{passive:!1}),h.addEventListener(`touchend`,t=>{t.preventDefault(),t.stopPropagation(),this._isTouchActive&&this._touchStartDate&&this._isSameDate(this._touchStartDate,e)&&this._handleDateClick(e),this._touchStartElement&&this._touchStartElement.classList.remove(`is-touch-active`),this._isTouchActive=!1,this._touchStartDate=null,this._touchStartElement=null},{passive:!1}),h.addEventListener(`touchcancel`,()=>{this._touchStartElement&&this._touchStartElement.classList.remove(`is-touch-active`),this._isTouchActive=!1,this._touchStartDate=null,this._touchStartElement=null}),this._isRange&&this._selectedStartDate&&!this._selectedEndDate&&!o&&(h.addEventListener(`mouseenter`,()=>{this._isHandlingClick||this._isTouchActive||this._isDateDisabled(e)||(!this._hoveredDate||!this._isSameDate(this._hoveredDate,e))&&(this._hoveredDate=e,this._buildCalendar())}),h.addEventListener(`touchmove`,e=>{if(!this._isTouchActive||!this._touchStartDate)return;let t=e.touches[0],n=document.elementFromPoint(t.clientX,t.clientY);for(;n&&!n.classList.contains(`mint-date-picker-day`);)n=n.parentElement;if(n&&n!==h){let e=n.getAttribute(`data-date`);if(e){let t=new Date(e);this._isDateDisabled(t)||(!this._hoveredDate||!this._isSameDate(this._hoveredDate,t))&&(this._hoveredDate=t,this._buildCalendar())}}},{passive:!0}))),h};for(let e=t-1;e>=0;e--){let t=E-e,n=j(new Date(T,w,t),t,!1);x.appendChild(n)}for(let t=1;t<=e;t++){let e=j(new Date(this._currentYear,this._currentMonth,t),t,!0);x.appendChild(e)}for(let e=1;e<=A;e++){let t=j(new Date(O,D,e),e,!1);x.appendChild(t)}if(this._isRange&&this._selectedStartDate&&!this._selectedEndDate&&(x.addEventListener(`mouseleave`,()=>{this._isTouchActive||(this._hoveredDate=null,this._buildCalendar())}),x.addEventListener(`touchend`,e=>{let t=e.changedTouches[0],n=document.elementFromPoint(t.clientX,t.clientY);n&&!x.contains(n)&&(this._hoveredDate=null,this._buildCalendar())},{passive:!0})),s){let e=document.createElement(`div`);e.className=`mint-date-shortcuts`;let t=document.createElement(`div`);t.className=`mint-date-shortcuts-wrapper`;let n=document.createElement(`div`);n.className=`mint-date-shortcuts-row`;let r=document.createElement(`div`);r.className=`mint-date-shortcuts-fade is-horizontal is-left`,t.appendChild(r);let i=document.createElement(`div`);i.className=`mint-date-shortcuts-fade is-horizontal is-right is-visible`,t.appendChild(i);let a=document.createElement(`div`);a.className=`mint-date-shortcuts-fade is-vertical is-top`,t.appendChild(a);let s=document.createElement(`div`);s.className=`mint-date-shortcuts-fade is-vertical is-bottom is-visible`,t.appendChild(s);let l=()=>{if(window.innerWidth>=768){let e=n.scrollTop,t=n.scrollHeight,o=n.clientHeight;e>0?a.classList.add(`is-visible`):a.classList.remove(`is-visible`),e+o<t-1?s.classList.add(`is-visible`):s.classList.remove(`is-visible`),r.classList.remove(`is-visible`),i.classList.remove(`is-visible`)}else{let e=n.scrollLeft,t=n.scrollWidth,o=n.clientWidth;e>0?r.classList.add(`is-visible`):r.classList.remove(`is-visible`),e+o<t-1?i.classList.add(`is-visible`):i.classList.remove(`is-visible`),a.classList.remove(`is-visible`),s.classList.remove(`is-visible`)}};n.addEventListener(`scroll`,l),window.addEventListener(`resize`,l),setTimeout(l,0),o.forEach(e=>{let t=document.createElement(`button`);t.type=`button`,t.tabIndex=0,t.className=`mint-date-shortcut-button`,t.textContent=e.label;let r=()=>{let t=e.action();if(t){if(this._isRange&&`start`in t&&`end`in t){this._selectedStartDate=t.start,this._selectedEndDate=t.end;let e=this.getFormat(),n=`${this._formatDate(t.start,e)} - ${this._formatDate(t.end,e)}`;this.setValue(n),this._currentMonth=t.start.getMonth(),this._currentYear=t.start.getFullYear()}else if(t instanceof Date){this._selectedStartDate=t,this._selectedEndDate=null;let e=this.getFormat(),n=this._formatDate(t,e);this.setValue(n),this._currentMonth=t.getMonth(),this._currentYear=t.getFullYear()}this._buildCalendar(),this._popover&&typeof this._popover.close==`function`&&this._popover.close(),this.dispatchEvent(new CustomEvent(`input`,{detail:{value:this.getValue()},bubbles:!0,cancelable:!0})),this.dispatchEvent(new CustomEvent(`change`,{detail:{value:this.getValue()},bubbles:!0,cancelable:!0}))}};t.addEventListener(`click`,r),t.addEventListener(`touchend`,e=>{e.preventDefault(),r()},{passive:!1}),n.appendChild(t)}),t.appendChild(n),e.appendChild(t),c.appendChild(e)}l.appendChild(u),l.appendChild(b),l.appendChild(x),c.appendChild(l),this._calendarContainer.appendChild(c)}_buildMonthView(){if(!this._calendarContainer)return;let e=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],t=document.createElement(`div`);t.className=`mint-date-calendar-header`;let n=document.createElement(`button`);n.type=`button`,n.tabIndex=0,n.className=`mint-date-calendar-nav-button`,n.setAttribute(`data-keep-popover-open`,`true`);let r=document.createElement(`mint-icon`);r.setAttribute(`name`,`caret-left`),r.className=`mint-date-calendar-icon`,n.appendChild(r);let i=()=>{let e=this._currentMonth,t=this._currentYear;this._currentYear--,this._buildCalendar(),this._dispatchMonthChangeEvent(e,t,this._currentMonth,this._currentYear)};n.addEventListener(`click`,i),n.addEventListener(`touchend`,e=>{e.preventDefault(),i()},{passive:!1}),t.appendChild(n);let a=document.createElement(`button`);a.type=`button`,a.tabIndex=0,a.className=`mint-date-calendar-title-button`,a.setAttribute(`data-keep-popover-open`,`true`),a.textContent=String(this._currentYear);let o=()=>{this.getMode()!==`year`&&(this._viewMode=`year`,this._buildCalendar())};a.addEventListener(`click`,o),a.addEventListener(`touchend`,e=>{e.preventDefault(),o()},{passive:!1}),t.appendChild(a);let s=document.createElement(`button`);s.type=`button`,s.tabIndex=0,s.className=`mint-date-calendar-nav-button`,s.setAttribute(`data-keep-popover-open`,`true`);let c=document.createElement(`mint-icon`);c.setAttribute(`name`,`caret-right`),c.className=`mint-date-calendar-icon`,s.appendChild(c);let l=()=>{let e=this._currentMonth,t=this._currentYear;this._currentYear++,this._buildCalendar(),this._dispatchMonthChangeEvent(e,t,this._currentMonth,this._currentYear)};s.addEventListener(`click`,l),s.addEventListener(`touchend`,e=>{e.preventDefault(),l()},{passive:!1}),t.appendChild(s);let u=document.createElement(`div`);u.className=`mint-date-calendar-option-grid`,e.forEach((e,t)=>{let n=document.createElement(`button`);n.type=`button`,n.tabIndex=0,this.getMode()!==`month`&&n.setAttribute(`data-keep-popover-open`,`true`),n.className=`mint-date-calendar-option${this._currentMonth===t?` is-selected`:``}`,n.textContent=e;let r=()=>{if(this.getMode()===`month`){let e=new Date(this._currentYear,t,1),n=this.getFormat(),r=this._formatDate(e,n);this.setValue(r),this._selectedStartDate=e,this._selectedEndDate=null;let i=this._currentMonth,a=this._currentYear;this._currentMonth=t,this._dispatchMonthChangeEvent(i,a,this._currentMonth,this._currentYear),this.dispatchEvent(new CustomEvent(`input`,{detail:{value:this.getValue()},bubbles:!0,cancelable:!0})),this.dispatchEvent(new CustomEvent(`change`,{detail:{value:this.getValue()},bubbles:!0,cancelable:!0})),this._dispatchDateChangeEvent(),this._popover&&typeof this._popover.close==`function`&&this._popover.close()}else{let e=this._currentMonth,n=this._currentYear;this._currentMonth=t,this._viewMode=`calendar`,this._buildCalendar(),this._dispatchMonthChangeEvent(e,n,this._currentMonth,this._currentYear)}};n.addEventListener(`click`,r),n.addEventListener(`touchend`,e=>{e.preventDefault(),r()},{passive:!1}),u.appendChild(n)}),this._calendarContainer.appendChild(t),this._calendarContainer.appendChild(u)}_buildYearView(){if(!this._calendarContainer)return;let e=this._currentYear-6,t=this._currentYear+6,n=document.createElement(`div`);n.className=`mint-date-calendar-header`;let r=document.createElement(`button`);r.type=`button`,r.tabIndex=0,r.className=`mint-date-calendar-nav-button`,r.setAttribute(`data-keep-popover-open`,`true`);let i=document.createElement(`mint-icon`);i.setAttribute(`name`,`caret-left`),i.className=`mint-date-calendar-icon`,r.appendChild(i);let a=()=>{let e=this._currentMonth,t=this._currentYear;this._currentYear-=12,this._buildCalendar(),this._dispatchMonthChangeEvent(e,t,this._currentMonth,this._currentYear)};r.addEventListener(`click`,a),r.addEventListener(`touchend`,e=>{e.preventDefault(),a()},{passive:!1}),n.appendChild(r);let o=document.createElement(`div`);o.className=`mint-date-calendar-title`,o.textContent=`${e} - ${t}`,n.appendChild(o);let s=document.createElement(`button`);s.type=`button`,s.tabIndex=0,s.className=`mint-date-calendar-nav-button`,s.setAttribute(`data-keep-popover-open`,`true`);let c=document.createElement(`mint-icon`);c.setAttribute(`name`,`caret-right`),c.className=`mint-date-calendar-icon`,s.appendChild(c);let l=()=>{let e=this._currentMonth,t=this._currentYear;this._currentYear+=12,this._buildCalendar(),this._dispatchMonthChangeEvent(e,t,this._currentMonth,this._currentYear)};s.addEventListener(`click`,l),s.addEventListener(`touchend`,e=>{e.preventDefault(),l()},{passive:!1}),n.appendChild(s);let u=document.createElement(`div`);u.className=`mint-date-calendar-option-grid`;for(let n=e;n<=t;n++){let e=document.createElement(`button`);e.type=`button`,e.tabIndex=0,this.getMode()!==`year`&&e.setAttribute(`data-keep-popover-open`,`true`),e.className=`mint-date-calendar-option${this._currentYear===n?` is-selected`:``}`,e.textContent=String(n),e.addEventListener(`click`,()=>{let e=this.getMode();if(e===`year`){let e=new Date(n,0,1),t=this.getFormat(),r=this._formatDate(e,t);this.setValue(r),this._selectedStartDate=e,this._selectedEndDate=null;let i=this._currentMonth,a=this._currentYear;this._currentYear=n,this._currentMonth=0,this._dispatchMonthChangeEvent(i,a,this._currentMonth,this._currentYear),this.dispatchEvent(new CustomEvent(`input`,{detail:{value:this.getValue()},bubbles:!0,cancelable:!0})),this.dispatchEvent(new CustomEvent(`change`,{detail:{value:this.getValue()},bubbles:!0,cancelable:!0})),this._dispatchDateChangeEvent(),this._popover&&typeof this._popover.close==`function`&&this._popover.close()}else if(e===`month`){let e=this._currentMonth,t=this._currentYear;this._currentYear=n,this._viewMode=`month`,this._buildCalendar(),this._dispatchMonthChangeEvent(e,t,this._currentMonth,this._currentYear)}else{let e=this._currentMonth,t=this._currentYear;this._currentYear=n,this._viewMode=`calendar`,this._buildCalendar(),this._dispatchMonthChangeEvent(e,t,this._currentMonth,this._currentYear)}}),u.appendChild(e)}this._calendarContainer.appendChild(n),this._calendarContainer.appendChild(u)}_getDaysInMonth(e,t){return new Date(t,e+1,0).getDate()}_getFirstDayOfMonth(e,t){let n=this.getWeekStartDay(),r=new Date(t,e,1).getDay();return r>=n?r-n:7-(n-r)}_isToday(e){let t=new Date;return e.getDate()===t.getDate()&&e.getMonth()===t.getMonth()&&e.getFullYear()===t.getFullYear()}_isDateSelected(e){let t=this.getSelectionMode();return this._isRange||t===`week`||t===`month`?this._selectedStartDate&&this._selectedEndDate?this._isSameDate(e,this._selectedStartDate)||this._isSameDate(e,this._selectedEndDate):this._isRange&&this._selectedStartDate&&!this._selectedEndDate?this._isSameDate(e,this._selectedStartDate):!1:this._selectedStartDate!==null&&this._isSameDate(e,this._selectedStartDate)}_isDateInRange(e){let t=this.getSelectionMode();if((this._isRange||t===`week`||t===`month`)&&this._selectedStartDate&&this._selectedEndDate)return this._rangeIncludesDisabledDates(this._selectedStartDate,this._selectedEndDate)?!1:e>=this._selectedStartDate&&e<=this._selectedEndDate;if(this._isRange&&this._selectedStartDate&&!this._selectedEndDate&&this._hoveredDate){let t=this._selectedStartDate<this._hoveredDate?this._selectedStartDate:this._hoveredDate,n=this._selectedStartDate<this._hoveredDate?this._hoveredDate:this._selectedStartDate;if(this._rangeIncludesDisabledDates(t,n)){let r=this._findFirstDisabledDateInRange(t,n);return r?this._selectedStartDate<this._hoveredDate?e>=t&&e<r&&!this._isSameDate(e,t):e>r&&e<=n&&!this._isSameDate(e,n):!1}return e>=t&&e<=n&&!this._isSameDate(e,t)&&!this._isSameDate(e,n)}return!1}_rangeIncludesDisabledDates(e,t){let n=this.getDisabledDates(),r=new Date(e.getFullYear(),e.getMonth(),e.getDate()),i=new Date(t.getFullYear(),t.getMonth(),t.getDate());return n.some(e=>{let t=new Date(e.getFullYear(),e.getMonth(),e.getDate());return t>=r&&t<=i})}_findFirstDisabledDateInRange(e,t){let n=this.getDisabledDates(),r=new Date(e.getFullYear(),e.getMonth(),e.getDate()),i=new Date(t.getFullYear(),t.getMonth(),t.getDate()),a=n.map(e=>new Date(e.getFullYear(),e.getMonth(),e.getDate())).filter(e=>e>=r&&e<=i).sort((e,t)=>e.getTime()-t.getTime());return a.length>0?a[0]:null}_hasIncompleteRange(){return this._isRange&&this._selectedStartDate!==null&&this._selectedEndDate===null}_isSameDate(e,t){return e.getDate()===t.getDate()&&e.getMonth()===t.getMonth()&&e.getFullYear()===t.getFullYear()}_isDateDisabled(e){return this.getDisabledDates().some(t=>this._isSameDate(e,t))}_dispatchMonthChangeEvent(e,t,n,r){(e!==n||t!==r)&&this.dispatchEvent(new CustomEvent(`month-change`,{detail:{month:n,year:r,oldMonth:e,oldYear:t},bubbles:!0,cancelable:!0,composed:!0}))}_dispatchDateChangeEvent(){let e=this.getFormat(),t={value:this.getValue()};this._selectedStartDate&&(t.startDate=this._selectedStartDate,t.startDateFormatted=this._formatDate(this._selectedStartDate,e)),this._selectedEndDate&&(t.endDate=this._selectedEndDate,t.endDateFormatted=this._formatDate(this._selectedEndDate,e)),this.dispatchEvent(new CustomEvent(`date-change`,{detail:t,bubbles:!0,cancelable:!0,composed:!0}))}_setupContainerObserver(){if(this._resizeObserver&&=(this._resizeObserver.disconnect(),null),!this._inputsWrapperEl)return;let e=e=>{this._inputsWrapperEl&&(e<400?(this._inputsWrapperEl.classList.add(`is-wrapping`),this._inputsWrapperEl.classList.remove(`is-nowrap`)):(this._inputsWrapperEl.classList.remove(`is-wrapping`),this._inputsWrapperEl.classList.add(`is-nowrap`)))};e(this._inputsWrapperEl.offsetWidth||this.offsetWidth),this._resizeObserver=new ResizeObserver(t=>{for(let n of t){let t=n.contentRect.width;e(t)}}),this._resizeObserver.observe(this)}_getWeekStart(e){let t=this.getWeekStartDay(),n=e.getDay(),r;r=n>=t?n-t:7-(t-n);let i=new Date(e);return i.setDate(e.getDate()-r),i.setHours(0,0,0,0),i}_getWeekEnd(e){let t=this._getWeekStart(e),n=new Date(t);return n.setDate(t.getDate()+6),n.setHours(23,59,59,999),n}_getMonthStart(e){let t=new Date(e.getFullYear(),e.getMonth(),1);return t.setHours(0,0,0,0),t}_getMonthEnd(e){let t=new Date(e.getFullYear(),e.getMonth()+1,0);return t.setHours(23,59,59,999),t}_handleDateClick(e){this._isHandlingClick=!0;try{let t=this.getFormat(),n=this.getSelectionMode(),r,i;if(n===`week`?(r=this._getWeekStart(e),i=this._getWeekEnd(e)):n===`month`?(r=this._getMonthStart(e),i=this._getMonthEnd(e)):(r=e,i=e),this.isRange()||n===`week`||n===`month`)if(n===`week`||n===`month`){if(this._rangeIncludesDisabledDates(r,i)){this._buildCalendar();return}this._selectedStartDate=r,this._selectedEndDate=i;let e=`${this._formatDate(this._selectedStartDate,t)} - ${this._formatDate(this._selectedEndDate,t)}`;this.setValue(e),this._textInput&&(this._textInput.value=e),this._popover&&typeof this._popover.close==`function`&&this._popover.close()}else if(this._hoveredDate=null,this._selectedStartDate===null){if(this._isDateDisabled(r)){this._buildCalendar();return}this._selectedStartDate=new Date(r.getFullYear(),r.getMonth(),r.getDate()),this._selectedEndDate=null,this._currentMonth=this._selectedStartDate.getMonth(),this._currentYear=this._selectedStartDate.getFullYear(),this._hoveredDate=null,this._buildCalendar()}else if(this._selectedEndDate===null){let n=new Date(e.getFullYear(),e.getMonth(),e.getDate()),r=this._selectedStartDate?new Date(this._selectedStartDate.getFullYear(),this._selectedStartDate.getMonth(),this._selectedStartDate.getDate()):null,i,a;if(r&&n<r?(i=n,a=r):(i=r,a=n),this._rangeIncludesDisabledDates(i,a)){this._buildCalendar();return}r&&n<r?(this._selectedEndDate=r,this._selectedStartDate=n):(this._selectedEndDate=n,r&&(this._selectedStartDate=r)),this._currentMonth=this._selectedStartDate.getMonth(),this._currentYear=this._selectedStartDate.getFullYear();let o=`${this._formatDate(this._selectedStartDate,t)} - ${this._formatDate(this._selectedEndDate,t)}`;this.setAttribute(`value`,o),this._textInput&&(this._textInput.value=o),this._hiddenInput&&(this._hiddenInput.value=o),this._updateDisplayText(),this._buildCalendar(),this._popover&&typeof this._popover.close==`function`&&this._popover.close()}else this._selectedStartDate=r,this._selectedEndDate=null;else{this._selectedStartDate=r,this._selectedEndDate=null;let e=this._formatDate(r,t);this.setValue(e),this._textInput&&(this._textInput.value=e),this._popover&&typeof this._popover.close==`function`&&this._popover.close()}this._buildCalendar(),this._updateDisplayText(),this._exitInputMode();let a=new Event(`input`,{bubbles:!0,cancelable:!0,composed:!0});this.dispatchEvent(a),this.dispatchEvent(new CustomEvent(`input`,{detail:{value:this.getValue()},bubbles:!0,cancelable:!0,composed:!0})),this.dispatchEvent(new CustomEvent(`change`,{detail:{value:this.getValue()},bubbles:!0,cancelable:!0,composed:!0})),this._dispatchDateChangeEvent()}finally{this._isHandlingClick=!1}}_updateDisplayText(){if(!this._displayEl)return;let e=this.getDisplayFormat(),t=this.getSelectionMode(),n=this._isRange||t===`week`||t===`month`,r=``;n&&this._selectedStartDate&&this._selectedEndDate?r=`${this._formatDatePhp(this._selectedStartDate,e)} - ${this._formatDatePhp(this._selectedEndDate,e)}`:this._selectedStartDate&&(r=this._formatDatePhp(this._selectedStartDate,e)),r?(this._displayEl.textContent=r,this._displayEl.classList.remove(`is-empty`)):(this._displayEl.textContent=`Select date`,this._displayEl.classList.add(`is-empty`)),this._displayEl&&this._inputsWrapperEl&&this.classList.toggle(`is-input-mode`,this._isInputMode)}_enterInputMode(){if(!this._isInputMode&&!(this.isReadonly()||this.isDisabled())&&(this._isInputMode=!0,this._displayEl&&this._inputsWrapperEl&&this.classList.add(`is-input-mode`),this._startPartInputs.length>0)){let e=this._startPartInputs[0];requestAnimationFrame(()=>{e.focus();try{e.setSelectionRange(0,e.value.length)}catch{}})}}_exitInputMode(){this._isInputMode&&(this._isInputMode=!1,this._displayEl&&this._inputsWrapperEl&&this.classList.remove(`is-input-mode`),this._updateDisplayText())}_renderSkeleton(e){let t=this.querySelector(`.mint-date-picker-skeleton-container`);this._fieldsContainer;let n=this._input;if(e){t||(t=document.createElement(`div`),t.className=`mint-date-picker-skeleton-container`,n?n.appendChild(t):(this.classList.add(`is-positioned`),this.appendChild(t)));let e=t.querySelector(`.mint-date-picker-skeleton`);e||(e=document.createElement(`div`),e.className=`mint-date-picker-skeleton`,t.appendChild(e)),this.classList.add(`is-loading`)}else t?.remove(),this.classList.remove(`is-loading`,`is-positioned`)}_getFocusableElements(){if(!this._calendarContainer)return[];let e=[`button:not([disabled])`,`a[href]`,`input:not([disabled]):not([type="hidden"])`,`select:not([disabled])`,`textarea:not([disabled])`,`[tabindex]:not([tabindex="-1"])`].join(`, `);return Array.from(this._calendarContainer.querySelectorAll(e)).filter(e=>{let t=window.getComputedStyle(e);return t.display!==`none`&&t.visibility!==`hidden`})}_setupFocusTrap(){if(!this._popover||!this._popover.hasAttribute(`open`))return;this._removeFocusTrap();let e=this;this._focusTrapHandler=function(t){if(t.key!==`Tab`)return;if(!e._popover||!e._popover.hasAttribute(`open`)){e._removeFocusTrap();return}let n=e._getFocusableElements();if(n.length===0)return;let r=n[0],i=n[n.length-1],a=document.activeElement;if(!e._calendarContainer?.contains(a)){t.preventDefault(),r.focus();return}if(t.shiftKey&&a===r){t.preventDefault(),i.focus();return}if(!t.shiftKey&&a===i){t.preventDefault(),r.focus();return}},this._escapeHandler=function(t){(t.key===`Escape`||t.key===`Esc`)&&e._popover&&e._popover.hasAttribute(`open`)&&(t.preventDefault(),t.stopPropagation(),typeof e._popover.close==`function`&&e._popover.close())},document.addEventListener(`keydown`,this._focusTrapHandler,!0),document.addEventListener(`keydown`,this._escapeHandler,!0),requestAnimationFrame(()=>{let e=this._getFocusableElements();e.length>0&&e[0].focus()})}_removeFocusTrap(){this._focusTrapHandler&&=(document.removeEventListener(`keydown`,this._focusTrapHandler,!0),null),this._escapeHandler&&=(document.removeEventListener(`keydown`,this._escapeHandler,!0),null)}};customElements.get(`mint-date-picker`)||t.t(`mint-date-picker`,n),module.exports=n;
|
|
@@ -4,11 +4,11 @@ import '../../icon.css'
|
|
|
4
4
|
import '../../popover.css'
|
|
5
5
|
import '../../stack.css'
|
|
6
6
|
import '../../date-picker.css'
|
|
7
|
-
import { a as e } from "../chunks/icon-
|
|
7
|
+
import { a as e } from "../chunks/icon-BWUYe89V.js";
|
|
8
8
|
import { t } from "../chunks/register-element-BFYmIynH.js";
|
|
9
|
-
import "../chunks/icon-
|
|
10
|
-
import "../chunks/caret-right-
|
|
11
|
-
import "../chunks/input-
|
|
9
|
+
import "../chunks/icon-B8p3Co0-.js";
|
|
10
|
+
import "../chunks/caret-right-fnCcTJKp.js";
|
|
11
|
+
import "../chunks/input-Dwrs8tJH.js";
|
|
12
12
|
import "../chunks/popover-gviDCspV.js";
|
|
13
13
|
e({
|
|
14
14
|
name: "calendar",
|
|
@@ -13,10 +13,10 @@ const __mintLoadStyle = (key, url) => {
|
|
|
13
13
|
__mintLoadStyle('theme', '../../theme.css')
|
|
14
14
|
__mintLoadStyle('icon', '../../icon.css')
|
|
15
15
|
__mintLoadStyle('dropzone', '../../dropzone.css')
|
|
16
|
-
import { a as e } from "../chunks/icon-
|
|
16
|
+
import { a as e } from "../chunks/icon-BWUYe89V.js";
|
|
17
17
|
import { t } from "../chunks/register-element-BFYmIynH.js";
|
|
18
|
-
import "../chunks/icon-
|
|
19
|
-
import "../chunks/close-
|
|
18
|
+
import "../chunks/icon-B8p3Co0-.js";
|
|
19
|
+
import "../chunks/close-CFxX3WCG.js";
|
|
20
20
|
e({
|
|
21
21
|
name: "upload",
|
|
22
22
|
viewBox: "0 0 24 24",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`../chunks/icon-BcsWL4kZ.js`),t=require(`../chunks/register-element-tCL_F1YI.js`);require(`../chunks/icon-uMo_iGkX.js`),require(`../chunks/close-Bg0kqvrY.js`),e.a({name:`upload`,viewBox:`0 0 24 24`,path:`M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M15 13l-3-3m0 0l-3 3m3-3v12`,strokeLinecap:`round`,strokeLinejoin:`round`}),e.a({name:`attach`,viewBox:`0 0 24 24`,path:`M15.172 7l-6.586 6.586a2 2 0 102.828 2.828l6.414-6.586a4 4 0 00-5.656-5.656l-6.415 6.585a6 6 0 108.486 8.486L20.5 13`,strokeLinecap:`round`,strokeLinejoin:`round`});var n=class extends HTMLElement{static get observedAttributes(){return[`label`,`accept`,`multiple`,`width`,`height`,`disabled`,`name`,`error`,`error-message`,`loading`,`aria-label`,`aria-describedby`]}constructor(){super(),this._dropzone=null,this._fileInput=null,this._previewContainer=null,this._isDragging=!1,this._wasDragging=!1,this._isUpdatingFiles=!1,this._listenersInitialized=!1,this._selectedFiles=[],this._previewUrls=[],this._resetHandler=null,this._a11yId=`mint-dropzone-${Math.random().toString(36).slice(2,10)}`}connectedCallback(){this.classList.add(`mint-dropzone`),this.render(),this._attachFormResetListener()}disconnectedCallback(){if(this.removeEventListeners(),this._cleanupPreviewUrls(),this._resetHandler){let e=this.closest(`form`);e&&e.removeEventListener(`reset`,this._resetHandler),this._resetHandler=null}}attributeChangedCallback(e,t,n){if(t!==n){if(e===`error`||e===`error-message`){this._updateDragStateClass(),this._renderErrorState(this.hasError(),this.getErrorMessage());return}if(e===`loading`){this.render();return}this.render()}}getLabel(){return this.getAttribute(`label`)||``}getAccept(){return this.getAttribute(`accept`)||``}isMultiple(){return this.getAttribute(`multiple`)===`true`}getWidth(){return this.getAttribute(`width`)||`200px`}getHeight(){return this.getAttribute(`height`)||`200px`}_renderSkeleton(e){let t=this.querySelector(`.mint-dropzone-skeleton-container`),n=this._dropzone;if(e){this.classList.add(`is-loading`),t||(t=document.createElement(`div`),t.className=`mint-dropzone-skeleton-container`,n?(n.classList.add(`is-positioned`),n.appendChild(t)):this.appendChild(t));let e=t.querySelector(`.mint-dropzone-skeleton`);e||(e=document.createElement(`div`),e.className=`mint-dropzone-skeleton`,t.appendChild(e)),t.classList.add(`is-visible`),n?.classList.add(`is-loading`)}else this.classList.remove(`is-loading`),t&&t.classList.remove(`is-visible`),n?.classList.remove(`is-loading`)}getName(){return this.getAttribute(`name`)||``}hasError(){return this.getAttribute(`error`)===`true`}getErrorMessage(){return this.getAttribute(`error-message`)||``}isDisabled(){return this.getAttribute(`disabled`)===`true`}isLoading(){return this.getAttribute(`loading`)===`true`}render(){let e=this.isLoading(),t=this.getLabel(),n=this.getAccept(),r=this.isMultiple(),i=this.isDisabled(),a=this.getWidth(),o=this.getHeight(),s=this.getName(),c=this.hasError(),l=this.getErrorMessage();if(this._dropzone||(this._dropzone=document.createElement(`div`),this.appendChild(this._dropzone)),this._updateDragStateClass(),this._dropzone.setAttribute(`aria-invalid`,c?`true`:`false`),i)this._dropzone.setAttribute(`tabindex`,`-1`),this._dropzone.removeAttribute(`role`);else{this._dropzone.setAttribute(`tabindex`,`0`),this._dropzone.setAttribute(`role`,`button`),this._dropzone.setAttribute(`aria-label`,this.getAttribute(`aria-label`)||t||`File upload dropzone`);let e=(this.getAttribute(`aria-describedby`)||``).split(/\s+/).filter(Boolean),n=this.querySelector(`.mint-dropzone-error`);n&&(n.id=`${this.id||this._a11yId}-error`,e.push(n.id)),e.length?this._dropzone.setAttribute(`aria-describedby`,Array.from(new Set(e)).join(` `)):this._dropzone.removeAttribute(`aria-describedby`)}this._dropzone.style.width=a,this._dropzone.style.height=o,this._dropzone.style.minWidth=a,this._dropzone.style.minHeight=o,this._fileInput||(this._fileInput=document.createElement(`input`),this._fileInput.type=`file`,this._fileInput.className=`mint-dropzone-file-input`,this._fileInput.setAttribute(`tabindex`,`-1`),this._fileInput.setAttribute(`aria-hidden`,`true`),this._dropzone.appendChild(this._fileInput)),this._fileInput.accept=n,this._fileInput.multiple=r,this._fileInput.disabled=i,s?this._fileInput.name=s:this._fileInput.removeAttribute(`name`),this._fileInput.setAttribute(`aria-invalid`,c?`true`:`false`);let u=this._dropzone.querySelector(`.mint-dropzone-icon`),d=this._dropzone.querySelector(`.mint-dropzone-label`);u&&u.remove(),d&&d.remove();let f=document.createElement(`div`);f.className=`mint-dropzone-icon`;let p=document.createElement(`mint-icon`);if(p.setAttribute(`name`,`upload`),p.className=`mint-dropzone-upload-icon`,f.appendChild(p),this._dropzone.appendChild(f),t){let e=document.createElement(`div`);e.className=`mint-dropzone-label`,e.textContent=t,this._dropzone.appendChild(e)}this.setupEventListeners(),this._renderErrorState(c,l),this._renderPreviews(),this._renderSkeleton(e)}_updateDragState(){this._dropzone&&this._updateDragStateClass()}_renderErrorState(e,t){let n=this.querySelector(`.mint-dropzone-error`);if(e&&t?(n||(n=document.createElement(`div`),n.className=`mint-dropzone-error`,this.appendChild(n)),n.textContent=t):n&&n.remove(),this._dropzone){this._dropzone.setAttribute(`aria-invalid`,String(e)),n&&(n.id=`${this.id||this._a11yId}-error`);let t=(this.getAttribute(`aria-describedby`)||``).split(/\s+/).filter(Boolean);n&&t.push(n.id),t.length?this._dropzone.setAttribute(`aria-describedby`,Array.from(new Set(t)).join(` `)):this._dropzone.removeAttribute(`aria-describedby`)}}_updateDragStateClass(){if(!this._dropzone)return;let e=this.isDisabled(),t=this.hasError();this._dropzone.className=`mint-dropzone-target`,this._dropzone.classList.toggle(`has-files`,this._selectedFiles.length>0),this._dropzone.classList.toggle(`is-dragging`,this._isDragging),this._dropzone.classList.toggle(`has-error`,t),this._dropzone.classList.toggle(`is-disabled`,e)}setupEventListeners(){this._listenersInitialized||(this._listenersInitialized=!0,this.removeEventListeners(),!(!this._dropzone||!this._fileInput||this.isDisabled())&&(this._onDropzoneClick||=e=>{if(!(this.isDisabled()||!this._fileInput)&&e.target!==this._fileInput&&(e.stopPropagation(),e.preventDefault(),e.isTrusted))try{this._fileInput.click()}catch(e){console.debug(`File chooser blocked:`,e)}},this._onDragOver||=e=>{e.preventDefault(),e.stopPropagation(),this.isDisabled()||this._isDragging||(this._isDragging=!0,this._wasDragging=!0,this._updateDragState())},this._onDragLeave||=e=>{e.preventDefault(),e.stopPropagation();let t=this._dropzone?.getBoundingClientRect();t&&(e.clientX<t.left||e.clientX>t.right||e.clientY<t.top||e.clientY>t.bottom)&&this._isDragging&&(this._isDragging=!1,this._wasDragging=!1,this._updateDragState())},this._onDrop||=e=>{if(e.preventDefault(),e.stopPropagation(),this._isDragging&&(this._isDragging=!1,this._wasDragging=!1,this._updateDragState()),this.isDisabled())return;let t=e.dataTransfer?.files;t&&t.length>0&&this._handleFiles(t)},this._onFileInputInput||=e=>{e.stopImmediatePropagation(),e.stopPropagation()},this._onKeyDown||=e=>{if(!(this.isDisabled()||!this._fileInput)&&(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),e.stopPropagation(),e.isTrusted))try{this._fileInput.click()}catch(e){console.debug(`File chooser blocked:`,e)}},this._onFocus||=e=>{this._dropzone&&!this.isDisabled()&&this._dropzone.classList.add(`is-focused`)},this._onBlur||=e=>{this._dropzone},this._onFileInputChange||=e=>{if(e.stopImmediatePropagation(),e.stopPropagation(),this._isUpdatingFiles)return;let t=e.target.files;if(t&&t.length>0){let e=this.getAccept(),n=this.isMultiple(),r=[],i=[];for(let n=0;n<t.length;n++){let a=t[n];this._isFileAccepted(a,e)?r.push(a):i.push(a)}if(!n&&r.length>1&&(i.push(...r.slice(1)),r.splice(1)),i.length>0){let e=new CustomEvent(`dropRejected`,{detail:{files:i,reason:`File type not accepted or multiple files not allowed`},bubbles:!0,cancelable:!0});this.dispatchEvent(e)}r.length>0&&this._applyValidFiles(r)}},this._dropzone.addEventListener(`click`,this._onDropzoneClick),this._dropzone.addEventListener(`dragover`,this._onDragOver),this._dropzone.addEventListener(`dragleave`,this._onDragLeave),this._dropzone.addEventListener(`drop`,this._onDrop),this._dropzone.addEventListener(`keydown`,this._onKeyDown),this._dropzone.addEventListener(`focus`,this._onFocus),this._dropzone.addEventListener(`blur`,this._onBlur),this._fileInput.addEventListener(`change`,this._onFileInputChange),this._fileInput.addEventListener(`input`,this._onFileInputInput,!0)))}removeEventListeners(){this._dropzone&&(this._onDropzoneClick&&this._dropzone.removeEventListener(`click`,this._onDropzoneClick),this._onDragOver&&this._dropzone.removeEventListener(`dragover`,this._onDragOver),this._onDragLeave&&this._dropzone.removeEventListener(`dragleave`,this._onDragLeave),this._onDrop&&this._dropzone.removeEventListener(`drop`,this._onDrop),this._onKeyDown&&this._dropzone.removeEventListener(`keydown`,this._onKeyDown),this._onFocus&&this._dropzone.removeEventListener(`focus`,this._onFocus),this._onBlur&&this._dropzone.removeEventListener(`blur`,this._onBlur)),this._fileInput&&(this._onFileInputChange&&this._fileInput.removeEventListener(`change`,this._onFileInputChange),this._onFileInputInput&&this._fileInput.removeEventListener(`input`,this._onFileInputInput,!0)),this._isDragging=!1,this._listenersInitialized=!1}_handleFiles(e){let t=this.getAccept(),n=this.isMultiple(),r=[],i=[];for(let n=0;n<e.length;n++){let a=e[n];this._isFileAccepted(a,t)?r.push(a):i.push(a)}if(!n&&r.length>1&&(i.push(...r.slice(1)),r.splice(1)),i.length>0){let e=new CustomEvent(`dropRejected`,{detail:{files:i,reason:`File type not accepted or multiple files not allowed`},bubbles:!0,cancelable:!0});this.dispatchEvent(e)}r.length>0&&this._applyValidFiles(r)}_isFileAccepted(e,t){if(!t)return!0;let n=t.split(`,`).map(e=>e.trim().toLowerCase());for(let t of n)if(t.startsWith(`.`)){if(`.`+e.name.split(`.`).pop()?.toLowerCase()===t)return!0}else if(t.includes(`/*`)){if(t.split(`/`)[0]===e.type.split(`/`)[0])return!0}else if(e.type===t)return!0;return!1}_dispatchEvent(e,t){let n=t.target,r=new CustomEvent(e,{detail:{files:n.files?Array.from(n.files):[],value:n.value||``},bubbles:!0,cancelable:!0});this.dispatchEvent(r)}_dispatchSelectionEvents(){let e={files:[...this._selectedFiles],value:``};this.dispatchEvent(new CustomEvent(`input`,{detail:e,bubbles:!0,cancelable:!0,composed:!0})),this.dispatchEvent(new CustomEvent(`change`,{detail:e,bubbles:!0,cancelable:!0,composed:!0}))}_syncFileInputFromSelected(){if(!this._fileInput)return;let e=new DataTransfer;this._selectedFiles.forEach(t=>{try{e.items.add(t)}catch(e){console.warn(`Failed to add file to DataTransfer:`,e)}}),this._isUpdatingFiles=!0;try{this._fileInput.files=e.files}catch(e){console.warn(`Failed to set files on input:`,e)}setTimeout(()=>{this._isUpdatingFiles=!1},0)}get files(){return this._syncFileInputFromSelected(),this._fileInput?.files||null}syncFiles(){this._syncFileInputFromSelected()}_renderPreviews(){if(!this._dropzone)return;if(this._previewContainer&&(this._cleanupPreviewUrls(),this._previewContainer.remove()),this._selectedFiles.length===0){this._previewContainer=null,this._updateDragStateClass();return}let e=document.createElement(`div`);e.className=`mint-dropzone-previews-wrapper`,e.classList.toggle(`has-error`,this.hasError()),e.classList.toggle(`is-dragging`,this._isDragging);let t=document.createElement(`div`);t.className=`mint-dropzone-previews`,this._selectedFiles.forEach((e,n)=>{let r=document.createElement(`div`);if(r.className=`mint-dropzone-file`,e.type.startsWith(`image/`)){let t=document.createElement(`img`);t.className=`mint-dropzone-file-image`;let n=URL.createObjectURL(e);this._previewUrls.push(n),t.src=n,r.appendChild(t)}else{let e=document.createElement(`mint-icon`);e.setAttribute(`name`,`attach`),e.className=`mint-dropzone-file-icon`,r.appendChild(e)}let i=document.createElement(`div`);i.className=`mint-dropzone-file-name`,i.textContent=e.name,r.appendChild(i);let a=document.createElement(`button`);a.type=`button`,a.className=`mint-dropzone-file-remove`;let o=document.createElement(`mint-icon`);o.setAttribute(`name`,`close`),o.className=`mint-dropzone-file-remove-icon`,a.appendChild(o),a.addEventListener(`click`,e=>{e.preventDefault(),e.stopPropagation(),this._removeFileAt(n)}),r.appendChild(a),t.appendChild(r)});let n=document.createElement(`div`);n.className=`mint-dropzone-preview-fade is-top`,e.appendChild(n);let r=document.createElement(`div`);r.className=`mint-dropzone-preview-fade is-bottom is-visible`,e.appendChild(r);let i=()=>{let e=t.scrollTop,i=t.scrollHeight,a=t.clientHeight;e>0?n.classList.add(`is-visible`):n.classList.remove(`is-visible`),e+a<i-1?r.classList.add(`is-visible`):r.classList.remove(`is-visible`)};i(),t.addEventListener(`scroll`,i),e.appendChild(t),this._previewContainer=e,this._dropzone.appendChild(e),this._updateDragStateClass()}_removeFileAt(e){if(e<0||e>=this._selectedFiles.length)return;let[t]=this._selectedFiles.splice(e,1);t&&this._cleanupPreviewUrls(),this._syncFileInputFromSelected(),this._renderPreviews(),this._dispatchSelectionEvents()}_cleanupPreviewUrls(){this._previewUrls.forEach(e=>URL.revokeObjectURL(e)),this._previewUrls=[]}_attachFormResetListener(){let e=this.closest(`form`);!e||this._resetHandler||(this._resetHandler=()=>{this._selectedFiles=[],this._syncFileInputFromSelected(),this._renderPreviews(),this._cleanupPreviewUrls()},e.addEventListener(`reset`,this._resetHandler))}_applyValidFiles(e){if(this.isMultiple()){let t=e.filter(e=>!this._isDuplicateFile(e));this._selectedFiles.push(...t)}else this._selectedFiles=[e[0]];this._syncFileInputFromSelected(),this._selectedFiles.length>0&&(this.removeAttribute(`error`),this.removeAttribute(`error-message`),this._fileInput&&this._fileInput.removeAttribute(`aria-invalid`)),this._renderPreviews(),this._dispatchSelectionEvents()}_isDuplicateFile(e){return this._selectedFiles.some(t=>t.name===e.name&&t.size===e.size&&t.lastModified===e.lastModified)}};customElements.get(`mint-dropzone`)||t.t(`mint-dropzone`,n),module.exports=n;
|
|
1
|
+
const e=require(`../chunks/icon-B_7c8b8e.js`),t=require(`../chunks/register-element-tCL_F1YI.js`);require(`../chunks/icon-CSqBgTae.js`),require(`../chunks/close-BdZJfr6m.js`),e.a({name:`upload`,viewBox:`0 0 24 24`,path:`M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M15 13l-3-3m0 0l-3 3m3-3v12`,strokeLinecap:`round`,strokeLinejoin:`round`}),e.a({name:`attach`,viewBox:`0 0 24 24`,path:`M15.172 7l-6.586 6.586a2 2 0 102.828 2.828l6.414-6.586a4 4 0 00-5.656-5.656l-6.415 6.585a6 6 0 108.486 8.486L20.5 13`,strokeLinecap:`round`,strokeLinejoin:`round`});var n=class extends HTMLElement{static get observedAttributes(){return[`label`,`accept`,`multiple`,`width`,`height`,`disabled`,`name`,`error`,`error-message`,`loading`,`aria-label`,`aria-describedby`]}constructor(){super(),this._dropzone=null,this._fileInput=null,this._previewContainer=null,this._isDragging=!1,this._wasDragging=!1,this._isUpdatingFiles=!1,this._listenersInitialized=!1,this._selectedFiles=[],this._previewUrls=[],this._resetHandler=null,this._a11yId=`mint-dropzone-${Math.random().toString(36).slice(2,10)}`}connectedCallback(){this.classList.add(`mint-dropzone`),this.render(),this._attachFormResetListener()}disconnectedCallback(){if(this.removeEventListeners(),this._cleanupPreviewUrls(),this._resetHandler){let e=this.closest(`form`);e&&e.removeEventListener(`reset`,this._resetHandler),this._resetHandler=null}}attributeChangedCallback(e,t,n){if(t!==n){if(e===`error`||e===`error-message`){this._updateDragStateClass(),this._renderErrorState(this.hasError(),this.getErrorMessage());return}if(e===`loading`){this.render();return}this.render()}}getLabel(){return this.getAttribute(`label`)||``}getAccept(){return this.getAttribute(`accept`)||``}isMultiple(){return this.getAttribute(`multiple`)===`true`}getWidth(){return this.getAttribute(`width`)||`200px`}getHeight(){return this.getAttribute(`height`)||`200px`}_renderSkeleton(e){let t=this.querySelector(`.mint-dropzone-skeleton-container`),n=this._dropzone;if(e){this.classList.add(`is-loading`),t||(t=document.createElement(`div`),t.className=`mint-dropzone-skeleton-container`,n?(n.classList.add(`is-positioned`),n.appendChild(t)):this.appendChild(t));let e=t.querySelector(`.mint-dropzone-skeleton`);e||(e=document.createElement(`div`),e.className=`mint-dropzone-skeleton`,t.appendChild(e)),t.classList.add(`is-visible`),n?.classList.add(`is-loading`)}else this.classList.remove(`is-loading`),t&&t.classList.remove(`is-visible`),n?.classList.remove(`is-loading`)}getName(){return this.getAttribute(`name`)||``}hasError(){return this.getAttribute(`error`)===`true`}getErrorMessage(){return this.getAttribute(`error-message`)||``}isDisabled(){return this.getAttribute(`disabled`)===`true`}isLoading(){return this.getAttribute(`loading`)===`true`}render(){let e=this.isLoading(),t=this.getLabel(),n=this.getAccept(),r=this.isMultiple(),i=this.isDisabled(),a=this.getWidth(),o=this.getHeight(),s=this.getName(),c=this.hasError(),l=this.getErrorMessage();if(this._dropzone||(this._dropzone=document.createElement(`div`),this.appendChild(this._dropzone)),this._updateDragStateClass(),this._dropzone.setAttribute(`aria-invalid`,c?`true`:`false`),i)this._dropzone.setAttribute(`tabindex`,`-1`),this._dropzone.removeAttribute(`role`);else{this._dropzone.setAttribute(`tabindex`,`0`),this._dropzone.setAttribute(`role`,`button`),this._dropzone.setAttribute(`aria-label`,this.getAttribute(`aria-label`)||t||`File upload dropzone`);let e=(this.getAttribute(`aria-describedby`)||``).split(/\s+/).filter(Boolean),n=this.querySelector(`.mint-dropzone-error`);n&&(n.id=`${this.id||this._a11yId}-error`,e.push(n.id)),e.length?this._dropzone.setAttribute(`aria-describedby`,Array.from(new Set(e)).join(` `)):this._dropzone.removeAttribute(`aria-describedby`)}this._dropzone.style.width=a,this._dropzone.style.height=o,this._dropzone.style.minWidth=a,this._dropzone.style.minHeight=o,this._fileInput||(this._fileInput=document.createElement(`input`),this._fileInput.type=`file`,this._fileInput.className=`mint-dropzone-file-input`,this._fileInput.setAttribute(`tabindex`,`-1`),this._fileInput.setAttribute(`aria-hidden`,`true`),this._dropzone.appendChild(this._fileInput)),this._fileInput.accept=n,this._fileInput.multiple=r,this._fileInput.disabled=i,s?this._fileInput.name=s:this._fileInput.removeAttribute(`name`),this._fileInput.setAttribute(`aria-invalid`,c?`true`:`false`);let u=this._dropzone.querySelector(`.mint-dropzone-icon`),d=this._dropzone.querySelector(`.mint-dropzone-label`);u&&u.remove(),d&&d.remove();let f=document.createElement(`div`);f.className=`mint-dropzone-icon`;let p=document.createElement(`mint-icon`);if(p.setAttribute(`name`,`upload`),p.className=`mint-dropzone-upload-icon`,f.appendChild(p),this._dropzone.appendChild(f),t){let e=document.createElement(`div`);e.className=`mint-dropzone-label`,e.textContent=t,this._dropzone.appendChild(e)}this.setupEventListeners(),this._renderErrorState(c,l),this._renderPreviews(),this._renderSkeleton(e)}_updateDragState(){this._dropzone&&this._updateDragStateClass()}_renderErrorState(e,t){let n=this.querySelector(`.mint-dropzone-error`);if(e&&t?(n||(n=document.createElement(`div`),n.className=`mint-dropzone-error`,this.appendChild(n)),n.textContent=t):n&&n.remove(),this._dropzone){this._dropzone.setAttribute(`aria-invalid`,String(e)),n&&(n.id=`${this.id||this._a11yId}-error`);let t=(this.getAttribute(`aria-describedby`)||``).split(/\s+/).filter(Boolean);n&&t.push(n.id),t.length?this._dropzone.setAttribute(`aria-describedby`,Array.from(new Set(t)).join(` `)):this._dropzone.removeAttribute(`aria-describedby`)}}_updateDragStateClass(){if(!this._dropzone)return;let e=this.isDisabled(),t=this.hasError();this._dropzone.className=`mint-dropzone-target`,this._dropzone.classList.toggle(`has-files`,this._selectedFiles.length>0),this._dropzone.classList.toggle(`is-dragging`,this._isDragging),this._dropzone.classList.toggle(`has-error`,t),this._dropzone.classList.toggle(`is-disabled`,e)}setupEventListeners(){this._listenersInitialized||(this._listenersInitialized=!0,this.removeEventListeners(),!(!this._dropzone||!this._fileInput||this.isDisabled())&&(this._onDropzoneClick||=e=>{if(!(this.isDisabled()||!this._fileInput)&&e.target!==this._fileInput&&(e.stopPropagation(),e.preventDefault(),e.isTrusted))try{this._fileInput.click()}catch(e){console.debug(`File chooser blocked:`,e)}},this._onDragOver||=e=>{e.preventDefault(),e.stopPropagation(),this.isDisabled()||this._isDragging||(this._isDragging=!0,this._wasDragging=!0,this._updateDragState())},this._onDragLeave||=e=>{e.preventDefault(),e.stopPropagation();let t=this._dropzone?.getBoundingClientRect();t&&(e.clientX<t.left||e.clientX>t.right||e.clientY<t.top||e.clientY>t.bottom)&&this._isDragging&&(this._isDragging=!1,this._wasDragging=!1,this._updateDragState())},this._onDrop||=e=>{if(e.preventDefault(),e.stopPropagation(),this._isDragging&&(this._isDragging=!1,this._wasDragging=!1,this._updateDragState()),this.isDisabled())return;let t=e.dataTransfer?.files;t&&t.length>0&&this._handleFiles(t)},this._onFileInputInput||=e=>{e.stopImmediatePropagation(),e.stopPropagation()},this._onKeyDown||=e=>{if(!(this.isDisabled()||!this._fileInput)&&(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),e.stopPropagation(),e.isTrusted))try{this._fileInput.click()}catch(e){console.debug(`File chooser blocked:`,e)}},this._onFocus||=e=>{this._dropzone&&!this.isDisabled()&&this._dropzone.classList.add(`is-focused`)},this._onBlur||=e=>{this._dropzone},this._onFileInputChange||=e=>{if(e.stopImmediatePropagation(),e.stopPropagation(),this._isUpdatingFiles)return;let t=e.target.files;if(t&&t.length>0){let e=this.getAccept(),n=this.isMultiple(),r=[],i=[];for(let n=0;n<t.length;n++){let a=t[n];this._isFileAccepted(a,e)?r.push(a):i.push(a)}if(!n&&r.length>1&&(i.push(...r.slice(1)),r.splice(1)),i.length>0){let e=new CustomEvent(`dropRejected`,{detail:{files:i,reason:`File type not accepted or multiple files not allowed`},bubbles:!0,cancelable:!0});this.dispatchEvent(e)}r.length>0&&this._applyValidFiles(r)}},this._dropzone.addEventListener(`click`,this._onDropzoneClick),this._dropzone.addEventListener(`dragover`,this._onDragOver),this._dropzone.addEventListener(`dragleave`,this._onDragLeave),this._dropzone.addEventListener(`drop`,this._onDrop),this._dropzone.addEventListener(`keydown`,this._onKeyDown),this._dropzone.addEventListener(`focus`,this._onFocus),this._dropzone.addEventListener(`blur`,this._onBlur),this._fileInput.addEventListener(`change`,this._onFileInputChange),this._fileInput.addEventListener(`input`,this._onFileInputInput,!0)))}removeEventListeners(){this._dropzone&&(this._onDropzoneClick&&this._dropzone.removeEventListener(`click`,this._onDropzoneClick),this._onDragOver&&this._dropzone.removeEventListener(`dragover`,this._onDragOver),this._onDragLeave&&this._dropzone.removeEventListener(`dragleave`,this._onDragLeave),this._onDrop&&this._dropzone.removeEventListener(`drop`,this._onDrop),this._onKeyDown&&this._dropzone.removeEventListener(`keydown`,this._onKeyDown),this._onFocus&&this._dropzone.removeEventListener(`focus`,this._onFocus),this._onBlur&&this._dropzone.removeEventListener(`blur`,this._onBlur)),this._fileInput&&(this._onFileInputChange&&this._fileInput.removeEventListener(`change`,this._onFileInputChange),this._onFileInputInput&&this._fileInput.removeEventListener(`input`,this._onFileInputInput,!0)),this._isDragging=!1,this._listenersInitialized=!1}_handleFiles(e){let t=this.getAccept(),n=this.isMultiple(),r=[],i=[];for(let n=0;n<e.length;n++){let a=e[n];this._isFileAccepted(a,t)?r.push(a):i.push(a)}if(!n&&r.length>1&&(i.push(...r.slice(1)),r.splice(1)),i.length>0){let e=new CustomEvent(`dropRejected`,{detail:{files:i,reason:`File type not accepted or multiple files not allowed`},bubbles:!0,cancelable:!0});this.dispatchEvent(e)}r.length>0&&this._applyValidFiles(r)}_isFileAccepted(e,t){if(!t)return!0;let n=t.split(`,`).map(e=>e.trim().toLowerCase());for(let t of n)if(t.startsWith(`.`)){if(`.`+e.name.split(`.`).pop()?.toLowerCase()===t)return!0}else if(t.includes(`/*`)){if(t.split(`/`)[0]===e.type.split(`/`)[0])return!0}else if(e.type===t)return!0;return!1}_dispatchEvent(e,t){let n=t.target,r=new CustomEvent(e,{detail:{files:n.files?Array.from(n.files):[],value:n.value||``},bubbles:!0,cancelable:!0});this.dispatchEvent(r)}_dispatchSelectionEvents(){let e={files:[...this._selectedFiles],value:``};this.dispatchEvent(new CustomEvent(`input`,{detail:e,bubbles:!0,cancelable:!0,composed:!0})),this.dispatchEvent(new CustomEvent(`change`,{detail:e,bubbles:!0,cancelable:!0,composed:!0}))}_syncFileInputFromSelected(){if(!this._fileInput)return;let e=new DataTransfer;this._selectedFiles.forEach(t=>{try{e.items.add(t)}catch(e){console.warn(`Failed to add file to DataTransfer:`,e)}}),this._isUpdatingFiles=!0;try{this._fileInput.files=e.files}catch(e){console.warn(`Failed to set files on input:`,e)}setTimeout(()=>{this._isUpdatingFiles=!1},0)}get files(){return this._syncFileInputFromSelected(),this._fileInput?.files||null}syncFiles(){this._syncFileInputFromSelected()}_renderPreviews(){if(!this._dropzone)return;if(this._previewContainer&&(this._cleanupPreviewUrls(),this._previewContainer.remove()),this._selectedFiles.length===0){this._previewContainer=null,this._updateDragStateClass();return}let e=document.createElement(`div`);e.className=`mint-dropzone-previews-wrapper`,e.classList.toggle(`has-error`,this.hasError()),e.classList.toggle(`is-dragging`,this._isDragging);let t=document.createElement(`div`);t.className=`mint-dropzone-previews`,this._selectedFiles.forEach((e,n)=>{let r=document.createElement(`div`);if(r.className=`mint-dropzone-file`,e.type.startsWith(`image/`)){let t=document.createElement(`img`);t.className=`mint-dropzone-file-image`;let n=URL.createObjectURL(e);this._previewUrls.push(n),t.src=n,r.appendChild(t)}else{let e=document.createElement(`mint-icon`);e.setAttribute(`name`,`attach`),e.className=`mint-dropzone-file-icon`,r.appendChild(e)}let i=document.createElement(`div`);i.className=`mint-dropzone-file-name`,i.textContent=e.name,r.appendChild(i);let a=document.createElement(`button`);a.type=`button`,a.className=`mint-dropzone-file-remove`;let o=document.createElement(`mint-icon`);o.setAttribute(`name`,`close`),o.className=`mint-dropzone-file-remove-icon`,a.appendChild(o),a.addEventListener(`click`,e=>{e.preventDefault(),e.stopPropagation(),this._removeFileAt(n)}),r.appendChild(a),t.appendChild(r)});let n=document.createElement(`div`);n.className=`mint-dropzone-preview-fade is-top`,e.appendChild(n);let r=document.createElement(`div`);r.className=`mint-dropzone-preview-fade is-bottom is-visible`,e.appendChild(r);let i=()=>{let e=t.scrollTop,i=t.scrollHeight,a=t.clientHeight;e>0?n.classList.add(`is-visible`):n.classList.remove(`is-visible`),e+a<i-1?r.classList.add(`is-visible`):r.classList.remove(`is-visible`)};i(),t.addEventListener(`scroll`,i),e.appendChild(t),this._previewContainer=e,this._dropzone.appendChild(e),this._updateDragStateClass()}_removeFileAt(e){if(e<0||e>=this._selectedFiles.length)return;let[t]=this._selectedFiles.splice(e,1);t&&this._cleanupPreviewUrls(),this._syncFileInputFromSelected(),this._renderPreviews(),this._dispatchSelectionEvents()}_cleanupPreviewUrls(){this._previewUrls.forEach(e=>URL.revokeObjectURL(e)),this._previewUrls=[]}_attachFormResetListener(){let e=this.closest(`form`);!e||this._resetHandler||(this._resetHandler=()=>{this._selectedFiles=[],this._syncFileInputFromSelected(),this._renderPreviews(),this._cleanupPreviewUrls()},e.addEventListener(`reset`,this._resetHandler))}_applyValidFiles(e){if(this.isMultiple()){let t=e.filter(e=>!this._isDuplicateFile(e));this._selectedFiles.push(...t)}else this._selectedFiles=[e[0]];this._syncFileInputFromSelected(),this._selectedFiles.length>0&&(this.removeAttribute(`error`),this.removeAttribute(`error-message`),this._fileInput&&this._fileInput.removeAttribute(`aria-invalid`)),this._renderPreviews(),this._dispatchSelectionEvents()}_isDuplicateFile(e){return this._selectedFiles.some(t=>t.name===e.name&&t.size===e.size&&t.lastModified===e.lastModified)}};customElements.get(`mint-dropzone`)||t.t(`mint-dropzone`,n),module.exports=n;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import '../../theme.css'
|
|
2
2
|
import '../../icon.css'
|
|
3
3
|
import '../../dropzone.css'
|
|
4
|
-
import { a as e } from "../chunks/icon-
|
|
4
|
+
import { a as e } from "../chunks/icon-BWUYe89V.js";
|
|
5
5
|
import { t } from "../chunks/register-element-BFYmIynH.js";
|
|
6
|
-
import "../chunks/icon-
|
|
7
|
-
import "../chunks/close-
|
|
6
|
+
import "../chunks/icon-B8p3Co0-.js";
|
|
7
|
+
import "../chunks/close-CFxX3WCG.js";
|
|
8
8
|
e({
|
|
9
9
|
name: "upload",
|
|
10
10
|
viewBox: "0 0 24 24",
|