@wpmoo/ui 1.3.0 → 1.4.1
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/ASSET_LICENSE.md +1 -1
- package/README.md +28 -4
- package/certification.json +2 -1
- package/dist/assets/css/moo-ui.css +159 -14
- package/dist/assets/css/moo-ui.min.css +2 -2
- package/dist/assets/css/moo.css +147 -2
- package/dist/assets/css/moo.min.css +2 -2
- package/dist/js/chart.js +1 -1
- package/dist/js/chart.min.js +1 -1
- package/dist/js/combobox.js +1 -1
- package/dist/js/context-menu.js +1 -1
- package/dist/js/datatable.js +1 -1
- package/dist/js/datepicker.js +3 -1
- package/dist/js/datepicker.min.js +2 -2
- package/dist/js/moo-ui.js +306 -1
- package/dist/js/moo-ui.min.js +2 -2
- package/dist/js/overlay-scrollbar.js +308 -0
- package/dist/js/sheet.js +1 -1
- package/dist/js/sidebar.js +1 -1
- package/dist/js/slider.js +1 -1
- package/dist/js/state.js +1 -1
- package/dist/js/table-of-contents.js +1 -1
- package/dist/js/toc.js +1 -1
- package/dist/release-manifest.json +4 -4
- package/package.json +3 -1
- package/scss/components/_datepicker.scss +5 -0
- package/scss/components/_field.scss +3 -0
- package/scss/components/_select.scss +4 -0
- package/scss/foundations/_globals.scss +1 -0
- package/scss/foundations/_scope.scss +2 -0
- package/scss/mixins/_banner.scss +1 -1
- package/scss/moo-core.scss +2 -0
- package/scss/moo-ui.scss +3 -0
- package/scss/settings/_component_variables.scss +2 -0
- package/scss/settings/_forms.scss +1 -1
- package/scss/utilities/_overlay_scrollbar.scss +68 -0
- package/scss/utilities/_overlay_scrollbar_native.scss +1 -0
- package/scss/utilities/_text_alignment.scss +29 -0
package/dist/js/chart.js
CHANGED
package/dist/js/chart.min.js
CHANGED
package/dist/js/combobox.js
CHANGED
package/dist/js/context-menu.js
CHANGED
package/dist/js/datatable.js
CHANGED
package/dist/js/datepicker.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* Moo UI datepicker.js v1.
|
|
2
|
+
* Moo UI datepicker.js v1.4.1 (https://wpmoo.org/)
|
|
3
3
|
* Copyright 2026 WPMoo Authors
|
|
4
4
|
* Licensed under MIT (https://github.com/wpmoo-org/ui/blob/main/LICENSE)
|
|
5
5
|
*/
|
|
@@ -1001,6 +1001,7 @@ var MooDatepicker = class _MooDatepicker {
|
|
|
1001
1001
|
setValidationValue(this._validationInput, value);
|
|
1002
1002
|
syncDatepickerValidation(this._element, this._trigger, this._validationInput);
|
|
1003
1003
|
this._element.dataset.datepickerValue = value;
|
|
1004
|
+
this._label.dataset.datepickerEmpty = value ? "false" : "true";
|
|
1004
1005
|
this._label.textContent = value ? formatDisplay(parseDate(value), this._config.locale) : this._placeholder;
|
|
1005
1006
|
}
|
|
1006
1007
|
_emitChange() {
|
|
@@ -1171,6 +1172,7 @@ var MooDateRangePicker = class _MooDateRangePicker {
|
|
|
1171
1172
|
syncDatepickerValidation(this._element, this._trigger, this._validationInput);
|
|
1172
1173
|
this._element.dataset.datepickerStartValue = startValue || "";
|
|
1173
1174
|
this._element.dataset.datepickerEndValue = endValue || "";
|
|
1175
|
+
this._label.dataset.datepickerEmpty = startValue ? "false" : "true";
|
|
1174
1176
|
if (startValue && endValue) {
|
|
1175
1177
|
this._label.textContent = `${formatDisplay(parseDate(startValue), this._config.locale)} - ${formatDisplay(parseDate(endValue), this._config.locale)}`;
|
|
1176
1178
|
} else if (startValue) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* Moo UI datepicker.min.js v1.
|
|
2
|
+
* Moo UI datepicker.min.js v1.4.1 (https://wpmoo.org/)
|
|
3
3
|
* Copyright 2026 WPMoo Authors
|
|
4
4
|
* Licensed under MIT (https://github.com/wpmoo-org/ui/blob/main/LICENSE)
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
var Q='.moo-ui[data-bs-theme="light"], .moo-ui[data-bs-theme="dark"]',lt="[data-moo-overlay-host]";function dt(e){return e?.nodeType===9?e:e?.ownerDocument?e.ownerDocument:typeof document>"u"?null:document}function ct(e){return!!e?.matches?.(Q)}function ht(e){let t=dt(e);return e?.nodeType===9||e===t?.body?t?.body?.firstElementChild||null:e}function q(e=typeof document>"u"?null:document){let t=ht(e);return t?ct(t)?t:t.closest?.(Q)||null:null}function X(e){return e?Array.from(e.children||[]).find(t=>t.matches?.(lt))||e:null}var I=new WeakMap,V=new WeakMap,M=new WeakMap,y="en",Et=1440*60*1e3,ut=new Date(2026,7,16),C=8;function z(e,t){return e?.nodeType===1&&!!e.matches?.(t)}function c(e,t,i,a,n){t&&(t.addEventListener(i,a,n),e.push({target:t,type:i,handler:a,options:n}))}function E(e){e.forEach(({target:t,type:i,handler:a,options:n})=>{t.removeEventListener(i,a,n)}),e.length=0}function d(e){if(!e)return null;if(e instanceof Date)return Number.isNaN(e.getTime())?null:new Date(e.getFullYear(),e.getMonth(),e.getDate());if(typeof e=="number")return d(new Date(e));let t=String(e).trim(),i=/^(\d{4})-(\d{2})-(\d{2})$/.exec(t);if(i){let a=new Date(Number(i[1]),Number(i[2])-1,Number(i[3]));return a.getFullYear()===Number(i[1])&&a.getMonth()===Number(i[2])-1&&a.getDate()===Number(i[3])?a:null}return null}function Z(e){return String(e).padStart(2,"0")}function f(e){return"".concat(e.getFullYear(),"-").concat(Z(e.getMonth()+1),"-").concat(Z(e.getDate()))}function p(e,t){return!e||!t?0:e.getTime()-t.getTime()}function k(e,t){return!!(e&&t&&f(e)===f(t))}function b(e,t){return new Date(e.getFullYear(),e.getMonth(),e.getDate()+t)}function B(e,t){let i=new Date(e.getFullYear(),e.getMonth()+t,1),a=Math.min(e.getDate(),W(i.getFullYear(),i.getMonth()));return new Date(i.getFullYear(),i.getMonth(),a)}function T(e=y){try{if(typeof Intl<"u"&&typeof Intl.Locale=="function"){let t=new Intl.Locale(e||y),i=t.weekInfo||t.getWeekInfo?.();if(Number.isInteger(i?.firstDay))return i.firstDay%7}}catch{}return 0}function _t(e=y){let t=T(e);return Array.from({length:7},(i,a)=>b(ut,(t+a)%7))}function w(e){return new Date(e.getFullYear(),e.getMonth(),1)}function W(e,t){return new Date(e,t+1,0).getDate()}function ft(e,t,i){return t&&p(e,t)<0?new Date(t):i&&p(e,i)>0?new Date(i):e}function mt(e){if(Array.isArray(e))return e.map(d).filter(Boolean).map(f);if(!e)return[];let t=String(e).trim();if(!t)return[];try{let i=JSON.parse(t);if(Array.isArray(i))return i.map(d).filter(Boolean).map(f)}catch{}return t.split(",").map(d).filter(Boolean).map(f)}function x(e,t=y){return e?new Intl.DateTimeFormat(t||y,{month:"short",day:"numeric",year:"numeric"}).format(e):""}function tt(e,t=y){return new Intl.DateTimeFormat(t||y,{month:"long",year:"numeric"}).format(e)}function $(e,t,i=y){if(e)return t==="yyyy-mm-dd"?f(e):t?x(e,i):new Date(e)}function U(e,t={}){let i=e.dataset||{},a=t.locale||i.datepickerLocale||i.calendarLocale||y,n=d(t.minDate||i.calendarMinDate||i.datepickerMinDate),r=d(t.maxDate||i.calendarMaxDate||i.datepickerMaxDate);return{locale:a,mode:t.mode||i.calendarMode||i.datepickerMode||"single",placeholder:t.placeholder||i.datepickerPlaceholder||"Pick a date",value:t.value||i.calendarValue||i.datepickerValue||"",startValue:t.startValue||i.calendarStartValue||i.datepickerStartValue||"",endValue:t.endValue||i.calendarEndValue||i.datepickerEndValue||"",minDate:n,maxDate:r,disabledDates:mt(t.disabledDates||i.calendarDisabledDates||i.datepickerDisabledDates),captionLayout:t.captionLayout||i.calendarCaptionLayout||"",showPresets:t.showPresets??(i.calendarShowPresets==="true"||i.datepickerShowPresets==="true")}}function g(e,t,i,a={},n=!1){return e.dispatchEvent(new t.CustomEvent(i,{bubbles:!0,cancelable:n,detail:a}))}function K(e,t){e&&(e.value=t||"")}function rt(e,t){e&&(e.value=t||"")}function j(e,t,i){if(i){e.dataset.invalid="true",t.classList.add("is-invalid"),t.setAttribute("aria-invalid","true");return}delete e.dataset.invalid,t.classList.remove("is-invalid"),t.removeAttribute("aria-invalid")}function st(e,t,i){i?.required&&i.checkValidity()&&j(e,t,!1)}function et(e,t,i){return i<t?t:Math.min(Math.max(e,t),i)}function pt(e,t,i){let a=e?.ownerDocument?.defaultView||window,n=e?a.getComputedStyle(e).getPropertyValue(t).trim():"",r=Number.parseFloat(n);if(!Number.isFinite(r))return i;if(n.endsWith("rem")){let s=e.ownerDocument.documentElement,_=Number.parseFloat(a.getComputedStyle(s).fontSize);return Number.isFinite(_)?r*_:i}if(n.endsWith("em")){let s=Number.parseFloat(a.getComputedStyle(e).fontSize);return Number.isFinite(s)?r*s:i}return Number.isFinite(r)?r:i}function O(e,t){return!!(t&&(e._element.contains(t)||e._popover.contains(t)))}function it(e){let i=q(e._trigger)?.getAttribute("data-bs-theme")||null,a=e._document.defaultView?.getComputedStyle(e._trigger).direction;i?e._popover.setAttribute("data-bs-theme",i):e._popover.removeAttribute("data-bs-theme"),a==="ltr"||a==="rtl"?e._popover.setAttribute("dir",a):e._popover.removeAttribute("dir")}function gt(e){let t=e._popover,i=q(e._trigger),a=X(i)||e._document.body||e._document.documentElement;if(a){if(e._popoverPortal?.portal===a&&t.parentElement===a){it(e);return}R(e),e._popoverPortal={parent:t.parentNode,nextSibling:t.nextSibling,owner:i,portal:a,hadTheme:t.hasAttribute("data-bs-theme"),theme:t.getAttribute("data-bs-theme"),hadDirection:t.hasAttribute("dir"),direction:t.getAttribute("dir")},a.appendChild(t),it(e)}}function R(e){let t=e._popoverPortal;if(!t)return;let i=e._popover;t.owner?.isConnected===!1?i.remove():t.parent?.isConnected?t.nextSibling?.parentNode===t.parent?t.parent.insertBefore(i,t.nextSibling):t.parent.appendChild(i):i.remove(),t.hadTheme?i.setAttribute("data-bs-theme",t.theme):i.removeAttribute("data-bs-theme"),t.hadDirection?i.setAttribute("dir",t.direction):i.removeAttribute("dir"),e._popoverPortal=null}function Dt(e,t,i,a){let n=pt(i,"--moo-datepicker-popover-offset",6),r=getComputedStyle(e).direction;t.style.position="fixed",t.style.inset="auto",t.style.right="auto",t.style.bottom="auto",t.style.maxHeight="",t.style.overflowY="";let s=e.getBoundingClientRect(),_=t.getBoundingClientRect(),S=a.innerWidth,D=a.innerHeight,P=r==="rtl"?s.right-_.width:s.left,Y=et(P,C,S-_.width-C),A=s.bottom+n<=D?D-s.bottom-n-C:0,h=s.top-n-C,l=_.height>A&&h>A,u=l?"top":"bottom",o=Math.max(0,l?h:A),N=Math.min(_.height,o),v=l?s.top-n-N:s.bottom+n;t.style.left="".concat(Math.round(Y),"px"),t.style.top="".concat(Math.round(et(v,C,D-N-C)),"px"),o>0&&(t.style.maxHeight="".concat(Math.floor(o),"px"),t.style.overflowY="auto"),t.dataset.datepickerPlacement=u}function yt(e){e.style.position="",e.style.inset="",e.style.right="",e.style.bottom="",e.style.left="",e.style.top="",e.style.maxHeight="",e.style.overflowY="",delete e.dataset.datepickerPlacement}function ot(e){E(e._floatingListeners),gt(e);let t=()=>{e.isOpen()&&Dt(e._trigger,e._popover,e._element,e._window)};e._positionPopover=t,t(),c(e._floatingListeners,e._window,"resize",t),c(e._floatingListeners,e._window,"scroll",t,!0),c(e._floatingListeners,e._document,"scroll",t,!0)}function F(e){E(e._floatingListeners),e._positionPopover=null,yt(e._popover),R(e)}function wt(e,t){return new Intl.DateTimeFormat(t||y,{month:"short"}).format(new Date(2026,e,1))}function bt(e,t,i){let a=e?e.getFullYear():i.getFullYear()-100,n=t?t.getFullYear():i.getFullYear()+20,r=[];for(let s=a;s<=n;s+=1)r.push(s);return r}function at(e,t,i=""){let a=e.createElement("span");return a.className=i,a.setAttribute("aria-hidden","true"),a.textContent=t,a}var L=class e{static getInstance(t){return t?.nodeType===1&&V.get(t)||null}static getOrCreateInstance(t,i={}){return e.getInstance(t)||new e(t,i)}constructor(t,i={}){if(!z(t,"[data-calendar]"))throw new TypeError("MooCalendar requires a [data-calendar] root element.");let a=V.get(t);if(a)return a;this._element=t,this._document=t.ownerDocument,this._window=this._document.defaultView||window,this._listeners=[],this._disposed=!1,this._config=U(t,i),this._mode=this._config.mode==="range"?"range":"single",this._disabledDates=new Set(this._config.disabledDates),this._selectedDate=d(this._config.value),this._rangeStart=d(this._config.startValue),this._rangeEnd=d(this._config.endValue),this._activeDate=this._nearestEnabledDate(this._rangeStart||this._selectedDate||new Date),this._viewDate=w(this._activeDate),this._captionId=this._element.id?"".concat(this._element.id,"-caption"):"moo-calendar-caption-".concat(Math.random().toString(36).slice(2)),this._labelId=this._element.id?"".concat(this._element.id,"-label"):"moo-calendar-label-".concat(Math.random().toString(36).slice(2)),V.set(t,this),this._bindEvents(),this._render()}dispose(){this._disposed||(this._disposed=!0,E(this._listeners),this._element.replaceChildren(),V.get(this._element)===this&&V.delete(this._element))}getDate(t=void 0){return this._mode==="range"?this.getDates(t):$(this._selectedDate,t,this._config.locale)}getDates(t=void 0){return[$(this._rangeStart,t,this._config.locale),$(this._rangeEnd,t,this._config.locale)]}setDate(t,i={}){if(this._mode!=="single")return!1;let a=d(t);return!a||this._isDisabled(a)?!1:(this._selectedDate=a,this._activeDate=a,this._viewDate=w(a),this._render(),i.emit!==!1&&this._emitChange(!0),!0)}setDates(t,i,a={}){if(this._mode!=="range")return!1;let n=d(t),r=d(i);return n&&this._isDisabled(n)||r&&this._isDisabled(r)?!1:(this._rangeStart=n,this._rangeEnd=r,this._rangeStart&&this._rangeEnd&&p(this._rangeStart,this._rangeEnd)>0&&([this._rangeStart,this._rangeEnd]=[this._rangeEnd,this._rangeStart]),this._activeDate=this._rangeEnd||this._rangeStart||this._activeDate,this._viewDate=w(this._activeDate),this._render(),a.emit!==!1&&this._emitChange(!!(this._rangeStart&&this._rangeEnd)),!0)}clear(t={}){this._selectedDate=null,this._rangeStart=null,this._rangeEnd=null,this._render(),t.emit!==!1&&this._emitChange(!1)}focusActiveDay(){this._dayButton(this._activeDate)?.focus()}_bindEvents(){c(this._listeners,this._element,"click",t=>{let i=t.target,a=i.closest?.("[data-calendar-day]"),n=i.closest?.("[data-calendar-prev]"),r=i.closest?.("[data-calendar-next]"),s=i.closest?.("[data-calendar-preset]");n?this._changeMonth(-1,!0):r?this._changeMonth(1,!0):s?this._selectPreset(s.dataset.calendarPreset):a&&this._selectDate(d(a.dataset.calendarDay),!0)}),c(this._listeners,this._element,"keydown",t=>{t.target.closest?.("[data-calendar-day]")&&this._handleDayKeydown(t)}),c(this._listeners,this._element,"change",t=>{t.target.matches?.("[data-calendar-month]")&&this._setActiveMonth(this._viewDate.getFullYear(),Number(t.target.value),!0),t.target.matches?.("[data-calendar-year]")&&this._setActiveMonth(Number(t.target.value),this._viewDate.getMonth(),!0)})}_emitChange(t){g(this._element,this._window,"change.moo.calendar",{date:this._selectedDate?new Date(this._selectedDate):void 0,value:this._selectedDate?f(this._selectedDate):"",startDate:this._rangeStart?new Date(this._rangeStart):void 0,endDate:this._rangeEnd?new Date(this._rangeEnd):void 0,startValue:this._rangeStart?f(this._rangeStart):"",endValue:this._rangeEnd?f(this._rangeEnd):"",complete:t})}_changeMonth(t,i){let a=w(B(this._viewDate,t));this._setActiveMonth(a.getFullYear(),a.getMonth(),i)}_setActiveMonth(t,i,a=!1){let n=Math.min(this._activeDate.getDate(),W(t,i));this._activeDate=this._nearestEnabledDate(new Date(t,i,n)),this._viewDate=w(this._activeDate),this._render(),a&&this.focusActiveDay()}_selectPreset(t){if(!t)return;let i=new Date,a={today:0,tomorrow:1,"in-3-days":3,"in-a-week":7,"in-2-weeks":14};t in a&&this._selectDate(b(i,a[t]),!0)}_handleDayKeydown(t){let i=t.target.closest?.("[data-calendar-day]"),a=d(i?.dataset?.calendarDay);a&&p(a,this._activeDate)!==0&&(this._activeDate=a);let n={ArrowRight:1,ArrowLeft:-1,ArrowDown:7,ArrowUp:-7},r=null;if(t.key in n)r=b(this._activeDate,n[t.key]);else if(t.key==="Home"){let s=T(this._config.locale),_=(this._activeDate.getDay()-s+7)%7;r=b(this._activeDate,-_)}else if(t.key==="End"){let s=T(this._config.locale),_=(this._activeDate.getDay()-s+7)%7;r=b(this._activeDate,6-_)}else if(t.key==="PageUp")r=B(this._activeDate,-1);else if(t.key==="PageDown")r=B(this._activeDate,1);else if(t.key==="Enter"||t.key===" "||t.key==="Spacebar"){t.preventDefault(),this._selectDate(this._activeDate,!0);return}else return;t.preventDefault(),this._setActiveDate(r,!0,p(r,this._activeDate)<0?-1:1)}_setActiveDate(t,i=!1,a=0){let n=a===0?this._nearestEnabledDate(t):this._nextEnabledDate(t,a);this._activeDate=n,this._viewDate=w(n),this._render(),i&&this.focusActiveDay()}_nextEnabledDate(t,i){let a=d(t);if(!a)return this._activeDate;let n=i<0?-1:1;for(let r=0;r<366&&!(this._config.minDate&&p(a,this._config.minDate)<0||this._config.maxDate&&p(a,this._config.maxDate)>0);r+=1){if(!this._isDisabled(a))return a;a=b(a,n)}return this._activeDate}_nearestEnabledDate(t){let i=ft(d(t)||new Date,this._config.minDate,this._config.maxDate);if(!this._isDisabled(i))return i;let a=w(i),n=W(a.getFullYear(),a.getMonth());for(let r=1;r<=n;r+=1){let s=new Date(a.getFullYear(),a.getMonth(),r);if(!this._isDisabled(s))return s}return i}_selectDate(t,i){if(!(!t||this._isDisabled(t))){if(this._activeDate=t,this._viewDate=w(t),this._mode==="range"){!this._rangeStart||this._rangeEnd||p(t,this._rangeStart)<0?(this._rangeStart=t,this._rangeEnd=null):this._rangeEnd=t,this._render(),i&&this._emitChange(!!(this._rangeStart&&this._rangeEnd));return}this._selectedDate=t,this._render(),i&&this._emitChange(!0)}}_isDisabled(t){return!t||this._config.minDate&&p(t,this._config.minDate)<0||this._config.maxDate&&p(t,this._config.maxDate)>0?!0:this._disabledDates.has(f(t))}_isSelected(t){return this._mode==="range"?k(t,this._rangeStart)||k(t,this._rangeEnd):k(t,this._selectedDate)}_rangeState(t){return this._mode!=="range"||!this._rangeStart?"":k(t,this._rangeStart)?"start":k(t,this._rangeEnd)?"end":this._rangeStart&&this._rangeEnd&&p(t,this._rangeStart)>0&&p(t,this._rangeEnd)<0?"middle":""}_dayButton(t){return this._element.querySelector('[data-calendar-day="'.concat(f(t),'"]'))}_render(){let t=this._document,i=t.createDocumentFragment(),a=t.createElement("div");a.className="moo-calendar__header";let n=t.createElement("button");n.className="btn btn-ghost btn-icon-sm moo-calendar__nav",n.type="button",n.dataset.calendarPrev="true",n.setAttribute("aria-label","Previous month"),n.appendChild(at(t,"\u2039","moo-calendar__nav-icon"));let r=t.createElement("button");r.className="btn btn-ghost btn-icon-sm moo-calendar__nav",r.type="button",r.dataset.calendarNext="true",r.setAttribute("aria-label","Next month"),r.appendChild(at(t,"\u203A","moo-calendar__nav-icon"));let s=t.createElement("div");if(s.className="moo-calendar__caption",s.id=this._captionId,s.setAttribute("aria-live","polite"),this._config.captionLayout==="dropdown"){let h=t.createElement("select");h.className="moo-calendar__select",h.dataset.calendarMonth="true",h.setAttribute("aria-label","Month");for(let u=0;u<12;u+=1){let o=t.createElement("option");o.value=String(u),o.textContent=wt(u,this._config.locale),o.selected=u===this._viewDate.getMonth(),h.appendChild(o)}let l=t.createElement("select");l.className="moo-calendar__select",l.dataset.calendarYear="true",l.setAttribute("aria-label","Year"),bt(this._config.minDate,this._config.maxDate,this._viewDate).forEach(u=>{let o=t.createElement("option");o.value=String(u),o.textContent=String(u),o.selected=u===this._viewDate.getFullYear(),l.appendChild(o)}),s.append(h,l)}else s.textContent=tt(this._viewDate,this._config.locale);a.append(n,s,r),i.appendChild(a);let _=t.createElement("div");_.id=this._labelId,_.className="visually-hidden",_.textContent=this._element.getAttribute("aria-label")||tt(this._viewDate,this._config.locale),i.appendChild(_);let S=t.createElement("div");S.className="moo-calendar__weekdays",S.setAttribute("role","row"),_t(this._config.locale).forEach(h=>{let l=t.createElement("span");l.className="moo-calendar__weekday",l.setAttribute("role","columnheader"),l.textContent=new Intl.DateTimeFormat(this._config.locale,{weekday:"narrow"}).format(h),S.appendChild(l)});let D=t.createElement("div");D.className="moo-calendar__grid",D.setAttribute("role","grid"),D.setAttribute("aria-labelledby",this._labelId),D.appendChild(S);let P=w(this._viewDate),Y=T(this._config.locale),A=b(P,-((P.getDay()-Y+7)%7));for(let h=0;h<6;h+=1){let l=t.createElement("div");l.className="moo-calendar__week",l.setAttribute("role","row");for(let u=0;u<7;u+=1){let o=b(A,h*7+u),N=f(o),v=t.createElement("div");v.className="moo-calendar__cell",v.setAttribute("role","gridcell");let m=t.createElement("button");m.className="moo-calendar__day",m.type="button",m.dataset.calendarDay=N,m.textContent=String(o.getDate()),m.tabIndex=k(o,this._activeDate)?0:-1,m.setAttribute("aria-label",x(o,this._config.locale));let G=this._isSelected(o);m.dataset.calendarSelected=String(G),v.setAttribute("aria-selected",G?"true":"false"),o.getMonth()!==this._viewDate.getMonth()&&(m.dataset.calendarOutside="true"),k(o,new Date)&&(m.dataset.calendarToday="true",m.setAttribute("aria-current","date"));let J=this._rangeState(o);J&&(m.dataset.calendarRange=J),this._isDisabled(o)&&(m.disabled=!0,m.setAttribute("aria-disabled","true")),v.appendChild(m),l.appendChild(v)}D.appendChild(l)}if(i.appendChild(D),this._config.showPresets){let h=t.createElement("div");h.className="moo-calendar__presets",[["today","Today"],["tomorrow","Tomorrow"],["in-3-days","In 3 days"],["in-a-week","In a week"],["in-2-weeks","In 2 weeks"]].forEach(([l,u])=>{let o=t.createElement("button");o.className="btn btn-outline-secondary btn-sm moo-calendar__preset",o.type="button",o.dataset.calendarPreset=l,o.textContent=u,h.appendChild(o)}),i.appendChild(h)}this._element.classList.add("moo-calendar"),this._element.dataset.calendar=this._element.dataset.calendar||"",this._element.dataset.calendarMode=this._mode,this._element.dataset.calendarActiveDate=f(this._activeDate),this._mode==="single"&&this._selectedDate?this._element.dataset.calendarValue=f(this._selectedDate):delete this._element.dataset.calendarValue,this._mode==="range"?(this._element.dataset.calendarStartValue=this._rangeStart?f(this._rangeStart):"",this._element.dataset.calendarEndValue=this._rangeEnd?f(this._rangeEnd):""):(delete this._element.dataset.calendarStartValue,delete this._element.dataset.calendarEndValue),this._element.replaceChildren(i)}},H=class e{static getInstance(t){return t?.nodeType===1&&I.get(t)||null}static getOrCreateInstance(t,i={}){return e.getInstance(t)||new e(t,i)}constructor(t,i={}){if(!z(t,"[data-datepicker]"))throw new TypeError("MooDatepicker requires a [data-datepicker] root element.");let a=I.get(t);if(a)return a;if(this._element=t,this._document=t.ownerDocument,this._window=this._document.defaultView||window,this._listeners=[],this._floatingListeners=[],this._disposed=!1,this._positionPopover=null,this._popoverPortal=null,this._trigger=t.querySelector("[data-datepicker-trigger]"),this._popover=t.querySelector("[data-datepicker-popover]"),this._label=t.querySelector("[data-datepicker-label]"),this._input=t.querySelector("[data-datepicker-input]")||t.querySelector('input[type="hidden"]'),this._validationInput=t.querySelector("[data-datepicker-validation]"),this._calendarRoot=t.querySelector("[data-calendar]"),!this._trigger||!this._popover||!this._label||!this._input||!this._calendarRoot)throw new TypeError("MooDatepicker requires a trigger, popover, calendar, and hidden input.");this._config=U(t,{...i,value:i.value||this._input.value||t.dataset.datepickerValue}),this._placeholder=this._config.placeholder,this._defaultValue=this._input.defaultValue||this._input.getAttribute("value")||"",this.calendar=L.getOrCreateInstance(this._calendarRoot,{...this._config,mode:"single",value:this._input.value||this._config.value}),I.set(t,this),this._syncFromCalendar(),this._bindEvents()}dispose(){this._disposed||(this._disposed=!0,E(this._listeners),this.hide(!1),F(this),R(this),E(this._floatingListeners),this.calendar?.dispose(),I.get(this._element)===this&&I.delete(this._element))}show(){this._trigger.disabled||this._element.dataset.datepickerDisabled==="true"||this.isOpen()||g(this._element,this._window,"show.moo.datepicker",{},!0)&&(this._popover.hidden=!1,this._popover.classList.add("show"),ot(this),this._trigger.setAttribute("aria-expanded","true"),this.calendar.focusActiveDay(),g(this._element,this._window,"shown.moo.datepicker"))}hide(t=!0){this.isOpen()&&g(this._element,this._window,"hide.moo.datepicker",{},!0)&&(this._popover.hidden=!0,this._popover.classList.remove("show"),F(this),this._trigger.setAttribute("aria-expanded","false"),t&&this._trigger.focus({preventScroll:!0}),g(this._element,this._window,"hidden.moo.datepicker"))}toggle(){this.isOpen()?this.hide():this.show()}isOpen(){return!this._popover.hidden}getDate(t=void 0){return this.calendar.getDate(t)}setDate(t,i={}){let a=this.calendar.setDate(t,{emit:!1});return a&&(this._syncFromCalendar(),i.emit!==!1&&this._emitChange()),a}clear(t={}){this.calendar.clear({emit:!1}),this._syncFromCalendar(),t.emit!==!1&&this._emitChange()}_bindEvents(){c(this._listeners,this._trigger,"click",()=>this.toggle()),c(this._listeners,this._popover,"keydown",i=>{i.key==="Escape"&&(i.preventDefault(),this.hide())}),c(this._listeners,this._document,"pointerdown",i=>{this.isOpen()&&!O(this,i.target)&&this._window.setTimeout(()=>{this.isOpen()&&!O(this,i.target)&&this.hide()},0)}),c(this._listeners,this._calendarRoot,"change.moo.calendar",i=>{this._syncFromCalendar(),this._emitChange(),i.detail.complete&&this.hide()});let t=this._input.form||this._element.closest("form");c(this._listeners,this._validationInput,"invalid",i=>{i.preventDefault(),j(this._element,this._trigger,!0),this._trigger.focus({preventScroll:!0})}),c(this._listeners,t,"reset",()=>{this._window.setTimeout(()=>{this._defaultValue?this.setDate(this._defaultValue,{emit:!1}):this.clear({emit:!1})},0)})}_syncFromCalendar(){let t=this.calendar.getDate("yyyy-mm-dd")||"";K(this._input,t),rt(this._validationInput,t),st(this._element,this._trigger,this._validationInput),this._element.dataset.datepickerValue=t,this._label.textContent=t?x(d(t),this._config.locale):this._placeholder}_emitChange(){g(this._element,this._window,"change.moo.datepicker",{date:this.getDate(),value:this.getDate("yyyy-mm-dd")||""})}},nt=class e{static getInstance(t){return t?.nodeType===1&&M.get(t)||null}static getOrCreateInstance(t,i={}){return e.getInstance(t)||new e(t,i)}constructor(t,i={}){if(!z(t,"[data-datepicker-range]"))throw new TypeError("MooDateRangePicker requires a [data-datepicker-range] root element.");let a=M.get(t);if(a)return a;if(this._element=t,this._document=t.ownerDocument,this._window=this._document.defaultView||window,this._listeners=[],this._floatingListeners=[],this._disposed=!1,this._positionPopover=null,this._popoverPortal=null,this._trigger=t.querySelector("[data-datepicker-trigger]"),this._popover=t.querySelector("[data-datepicker-popover]"),this._label=t.querySelector("[data-datepicker-label]"),this._startInput=t.querySelector("[data-datepicker-range-start]"),this._endInput=t.querySelector("[data-datepicker-range-end]"),this._validationInput=t.querySelector("[data-datepicker-validation]"),this._calendarRoot=t.querySelector("[data-calendar]"),!this._trigger||!this._popover||!this._label||!this._startInput||!this._endInput||!this._calendarRoot)throw new TypeError("MooDateRangePicker requires a trigger, popover, calendar, and start/end hidden inputs.");this._config=U(t,{...i,mode:"range",startValue:i.startValue||this._startInput.value||t.dataset.datepickerStartValue,endValue:i.endValue||this._endInput.value||t.dataset.datepickerEndValue}),this._placeholder=this._config.placeholder,this._defaultStartValue=this._startInput.defaultValue||this._startInput.getAttribute("value")||"",this._defaultEndValue=this._endInput.defaultValue||this._endInput.getAttribute("value")||"",this.calendar=L.getOrCreateInstance(this._calendarRoot,this._config),M.set(t,this),this._syncFromCalendar(),this._bindEvents()}dispose(){this._disposed||(this._disposed=!0,E(this._listeners),this.hide(!1),F(this),R(this),E(this._floatingListeners),this.calendar?.dispose(),M.get(this._element)===this&&M.delete(this._element))}show(){this._trigger.disabled||this._element.dataset.datepickerDisabled==="true"||this.isOpen()||g(this._element,this._window,"show.moo.datepicker",{},!0)&&(this._popover.hidden=!1,this._popover.classList.add("show"),ot(this),this._trigger.setAttribute("aria-expanded","true"),this.calendar.focusActiveDay(),g(this._element,this._window,"shown.moo.datepicker"))}hide(t=!0){this.isOpen()&&g(this._element,this._window,"hide.moo.datepicker",{},!0)&&(this._popover.hidden=!0,this._popover.classList.remove("show"),F(this),this._trigger.setAttribute("aria-expanded","false"),t&&this._trigger.focus({preventScroll:!0}),g(this._element,this._window,"hidden.moo.datepicker"))}toggle(){this.isOpen()?this.hide():this.show()}isOpen(){return!this._popover.hidden}getDates(t=void 0){return this.calendar.getDates(t)}setDates(t,i,a={}){let n=this.calendar.setDates(t,i,{emit:!1});return n&&(this._syncFromCalendar(),a.emit!==!1&&this._emitChange()),n}clear(t={}){this.calendar.clear({emit:!1}),this._syncFromCalendar(),t.emit!==!1&&this._emitChange()}_bindEvents(){c(this._listeners,this._trigger,"click",()=>this.toggle()),c(this._listeners,this._popover,"keydown",a=>{a.key==="Escape"&&(a.preventDefault(),this.hide())}),c(this._listeners,this._document,"pointerdown",a=>{this.isOpen()&&!O(this,a.target)&&this._window.setTimeout(()=>{this.isOpen()&&!O(this,a.target)&&this.hide()},0)});let t=()=>{this._window.setTimeout(()=>{this.isOpen()&&!O(this,this._document.activeElement)&&this.hide(!1)},0)};c(this._listeners,this._element,"focusout",t),c(this._listeners,this._popover,"focusout",t),c(this._listeners,this._calendarRoot,"change.moo.calendar",a=>{this._syncFromCalendar(),this._emitChange(),a.detail.complete?this.hide():this.calendar.focusActiveDay()});let i=this._startInput.form||this._element.closest("form");c(this._listeners,this._validationInput,"invalid",a=>{a.preventDefault(),j(this._element,this._trigger,!0),this._trigger.focus({preventScroll:!0})}),c(this._listeners,i,"reset",()=>{this._window.setTimeout(()=>{this.setDates(this._defaultStartValue,this._defaultEndValue,{emit:!1})},0)})}_syncFromCalendar(){let[t="",i=""]=this.calendar.getDates("yyyy-mm-dd");K(this._startInput,t||""),K(this._endInput,i||""),rt(this._validationInput,t&&i?"".concat(t," - ").concat(i):""),st(this._element,this._trigger,this._validationInput),this._element.dataset.datepickerStartValue=t||"",this._element.dataset.datepickerEndValue=i||"",t&&i?this._label.textContent="".concat(x(d(t),this._config.locale)," - ").concat(x(d(i),this._config.locale)):t?this._label.textContent=x(d(t),this._config.locale):this._label.textContent=this._placeholder}_emitChange(){let[t,i]=this.getDates(),[a="",n=""]=this.getDates("yyyy-mm-dd");g(this._element,this._window,"change.moo.datepicker",{startDate:t,endDate:i,startValue:a,endValue:n})}};export{L as MooCalendar,nt as MooDateRangePicker,H as default};
|
|
7
|
+
var Q='.moo-ui[data-bs-theme="light"], .moo-ui[data-bs-theme="dark"]',lt="[data-moo-overlay-host]";function dt(e){return e?.nodeType===9?e:e?.ownerDocument?e.ownerDocument:typeof document>"u"?null:document}function ct(e){return!!e?.matches?.(Q)}function ht(e){let t=dt(e);return e?.nodeType===9||e===t?.body?t?.body?.firstElementChild||null:e}function q(e=typeof document>"u"?null:document){let t=ht(e);return t?ct(t)?t:t.closest?.(Q)||null:null}function X(e){return e?Array.from(e.children||[]).find(t=>t.matches?.(lt))||e:null}var I=new WeakMap,V=new WeakMap,M=new WeakMap,y="en",Et=1440*60*1e3,ut=new Date(2026,7,16),C=8;function z(e,t){return e?.nodeType===1&&!!e.matches?.(t)}function c(e,t,i,a,n){t&&(t.addEventListener(i,a,n),e.push({target:t,type:i,handler:a,options:n}))}function E(e){e.forEach(({target:t,type:i,handler:a,options:n})=>{t.removeEventListener(i,a,n)}),e.length=0}function d(e){if(!e)return null;if(e instanceof Date)return Number.isNaN(e.getTime())?null:new Date(e.getFullYear(),e.getMonth(),e.getDate());if(typeof e=="number")return d(new Date(e));let t=String(e).trim(),i=/^(\d{4})-(\d{2})-(\d{2})$/.exec(t);if(i){let a=new Date(Number(i[1]),Number(i[2])-1,Number(i[3]));return a.getFullYear()===Number(i[1])&&a.getMonth()===Number(i[2])-1&&a.getDate()===Number(i[3])?a:null}return null}function Z(e){return String(e).padStart(2,"0")}function f(e){return"".concat(e.getFullYear(),"-").concat(Z(e.getMonth()+1),"-").concat(Z(e.getDate()))}function m(e,t){return!e||!t?0:e.getTime()-t.getTime()}function k(e,t){return!!(e&&t&&f(e)===f(t))}function b(e,t){return new Date(e.getFullYear(),e.getMonth(),e.getDate()+t)}function B(e,t){let i=new Date(e.getFullYear(),e.getMonth()+t,1),a=Math.min(e.getDate(),W(i.getFullYear(),i.getMonth()));return new Date(i.getFullYear(),i.getMonth(),a)}function T(e=y){try{if(typeof Intl<"u"&&typeof Intl.Locale=="function"){let t=new Intl.Locale(e||y),i=t.weekInfo||t.getWeekInfo?.();if(Number.isInteger(i?.firstDay))return i.firstDay%7}}catch{}return 0}function _t(e=y){let t=T(e);return Array.from({length:7},(i,a)=>b(ut,(t+a)%7))}function w(e){return new Date(e.getFullYear(),e.getMonth(),1)}function W(e,t){return new Date(e,t+1,0).getDate()}function ft(e,t,i){return t&&m(e,t)<0?new Date(t):i&&m(e,i)>0?new Date(i):e}function pt(e){if(Array.isArray(e))return e.map(d).filter(Boolean).map(f);if(!e)return[];let t=String(e).trim();if(!t)return[];try{let i=JSON.parse(t);if(Array.isArray(i))return i.map(d).filter(Boolean).map(f)}catch{}return t.split(",").map(d).filter(Boolean).map(f)}function x(e,t=y){return e?new Intl.DateTimeFormat(t||y,{month:"short",day:"numeric",year:"numeric"}).format(e):""}function tt(e,t=y){return new Intl.DateTimeFormat(t||y,{month:"long",year:"numeric"}).format(e)}function $(e,t,i=y){if(e)return t==="yyyy-mm-dd"?f(e):t?x(e,i):new Date(e)}function U(e,t={}){let i=e.dataset||{},a=t.locale||i.datepickerLocale||i.calendarLocale||y,n=d(t.minDate||i.calendarMinDate||i.datepickerMinDate),r=d(t.maxDate||i.calendarMaxDate||i.datepickerMaxDate);return{locale:a,mode:t.mode||i.calendarMode||i.datepickerMode||"single",placeholder:t.placeholder||i.datepickerPlaceholder||"Pick a date",value:t.value||i.calendarValue||i.datepickerValue||"",startValue:t.startValue||i.calendarStartValue||i.datepickerStartValue||"",endValue:t.endValue||i.calendarEndValue||i.datepickerEndValue||"",minDate:n,maxDate:r,disabledDates:pt(t.disabledDates||i.calendarDisabledDates||i.datepickerDisabledDates),captionLayout:t.captionLayout||i.calendarCaptionLayout||"",showPresets:t.showPresets??(i.calendarShowPresets==="true"||i.datepickerShowPresets==="true")}}function g(e,t,i,a={},n=!1){return e.dispatchEvent(new t.CustomEvent(i,{bubbles:!0,cancelable:n,detail:a}))}function K(e,t){e&&(e.value=t||"")}function rt(e,t){e&&(e.value=t||"")}function j(e,t,i){if(i){e.dataset.invalid="true",t.classList.add("is-invalid"),t.setAttribute("aria-invalid","true");return}delete e.dataset.invalid,t.classList.remove("is-invalid"),t.removeAttribute("aria-invalid")}function st(e,t,i){i?.required&&i.checkValidity()&&j(e,t,!1)}function et(e,t,i){return i<t?t:Math.min(Math.max(e,t),i)}function mt(e,t,i){let a=e?.ownerDocument?.defaultView||window,n=e?a.getComputedStyle(e).getPropertyValue(t).trim():"",r=Number.parseFloat(n);if(!Number.isFinite(r))return i;if(n.endsWith("rem")){let s=e.ownerDocument.documentElement,_=Number.parseFloat(a.getComputedStyle(s).fontSize);return Number.isFinite(_)?r*_:i}if(n.endsWith("em")){let s=Number.parseFloat(a.getComputedStyle(e).fontSize);return Number.isFinite(s)?r*s:i}return Number.isFinite(r)?r:i}function O(e,t){return!!(t&&(e._element.contains(t)||e._popover.contains(t)))}function it(e){let i=q(e._trigger)?.getAttribute("data-bs-theme")||null,a=e._document.defaultView?.getComputedStyle(e._trigger).direction;i?e._popover.setAttribute("data-bs-theme",i):e._popover.removeAttribute("data-bs-theme"),a==="ltr"||a==="rtl"?e._popover.setAttribute("dir",a):e._popover.removeAttribute("dir")}function gt(e){let t=e._popover,i=q(e._trigger),a=X(i)||e._document.body||e._document.documentElement;if(a){if(e._popoverPortal?.portal===a&&t.parentElement===a){it(e);return}R(e),e._popoverPortal={parent:t.parentNode,nextSibling:t.nextSibling,owner:i,portal:a,hadTheme:t.hasAttribute("data-bs-theme"),theme:t.getAttribute("data-bs-theme"),hadDirection:t.hasAttribute("dir"),direction:t.getAttribute("dir")},a.appendChild(t),it(e)}}function R(e){let t=e._popoverPortal;if(!t)return;let i=e._popover;t.owner?.isConnected===!1?i.remove():t.parent?.isConnected?t.nextSibling?.parentNode===t.parent?t.parent.insertBefore(i,t.nextSibling):t.parent.appendChild(i):i.remove(),t.hadTheme?i.setAttribute("data-bs-theme",t.theme):i.removeAttribute("data-bs-theme"),t.hadDirection?i.setAttribute("dir",t.direction):i.removeAttribute("dir"),e._popoverPortal=null}function Dt(e,t,i,a){let n=mt(i,"--moo-datepicker-popover-offset",6),r=getComputedStyle(e).direction;t.style.position="fixed",t.style.inset="auto",t.style.right="auto",t.style.bottom="auto",t.style.maxHeight="",t.style.overflowY="";let s=e.getBoundingClientRect(),_=t.getBoundingClientRect(),S=a.innerWidth,D=a.innerHeight,P=r==="rtl"?s.right-_.width:s.left,Y=et(P,C,S-_.width-C),A=s.bottom+n<=D?D-s.bottom-n-C:0,h=s.top-n-C,l=_.height>A&&h>A,u=l?"top":"bottom",o=Math.max(0,l?h:A),N=Math.min(_.height,o),v=l?s.top-n-N:s.bottom+n;t.style.left="".concat(Math.round(Y),"px"),t.style.top="".concat(Math.round(et(v,C,D-N-C)),"px"),o>0&&(t.style.maxHeight="".concat(Math.floor(o),"px"),t.style.overflowY="auto"),t.dataset.datepickerPlacement=u}function yt(e){e.style.position="",e.style.inset="",e.style.right="",e.style.bottom="",e.style.left="",e.style.top="",e.style.maxHeight="",e.style.overflowY="",delete e.dataset.datepickerPlacement}function ot(e){E(e._floatingListeners),gt(e);let t=()=>{e.isOpen()&&Dt(e._trigger,e._popover,e._element,e._window)};e._positionPopover=t,t(),c(e._floatingListeners,e._window,"resize",t),c(e._floatingListeners,e._window,"scroll",t,!0),c(e._floatingListeners,e._document,"scroll",t,!0)}function F(e){E(e._floatingListeners),e._positionPopover=null,yt(e._popover),R(e)}function wt(e,t){return new Intl.DateTimeFormat(t||y,{month:"short"}).format(new Date(2026,e,1))}function bt(e,t,i){let a=e?e.getFullYear():i.getFullYear()-100,n=t?t.getFullYear():i.getFullYear()+20,r=[];for(let s=a;s<=n;s+=1)r.push(s);return r}function at(e,t,i=""){let a=e.createElement("span");return a.className=i,a.setAttribute("aria-hidden","true"),a.textContent=t,a}var L=class e{static getInstance(t){return t?.nodeType===1&&V.get(t)||null}static getOrCreateInstance(t,i={}){return e.getInstance(t)||new e(t,i)}constructor(t,i={}){if(!z(t,"[data-calendar]"))throw new TypeError("MooCalendar requires a [data-calendar] root element.");let a=V.get(t);if(a)return a;this._element=t,this._document=t.ownerDocument,this._window=this._document.defaultView||window,this._listeners=[],this._disposed=!1,this._config=U(t,i),this._mode=this._config.mode==="range"?"range":"single",this._disabledDates=new Set(this._config.disabledDates),this._selectedDate=d(this._config.value),this._rangeStart=d(this._config.startValue),this._rangeEnd=d(this._config.endValue),this._activeDate=this._nearestEnabledDate(this._rangeStart||this._selectedDate||new Date),this._viewDate=w(this._activeDate),this._captionId=this._element.id?"".concat(this._element.id,"-caption"):"moo-calendar-caption-".concat(Math.random().toString(36).slice(2)),this._labelId=this._element.id?"".concat(this._element.id,"-label"):"moo-calendar-label-".concat(Math.random().toString(36).slice(2)),V.set(t,this),this._bindEvents(),this._render()}dispose(){this._disposed||(this._disposed=!0,E(this._listeners),this._element.replaceChildren(),V.get(this._element)===this&&V.delete(this._element))}getDate(t=void 0){return this._mode==="range"?this.getDates(t):$(this._selectedDate,t,this._config.locale)}getDates(t=void 0){return[$(this._rangeStart,t,this._config.locale),$(this._rangeEnd,t,this._config.locale)]}setDate(t,i={}){if(this._mode!=="single")return!1;let a=d(t);return!a||this._isDisabled(a)?!1:(this._selectedDate=a,this._activeDate=a,this._viewDate=w(a),this._render(),i.emit!==!1&&this._emitChange(!0),!0)}setDates(t,i,a={}){if(this._mode!=="range")return!1;let n=d(t),r=d(i);return n&&this._isDisabled(n)||r&&this._isDisabled(r)?!1:(this._rangeStart=n,this._rangeEnd=r,this._rangeStart&&this._rangeEnd&&m(this._rangeStart,this._rangeEnd)>0&&([this._rangeStart,this._rangeEnd]=[this._rangeEnd,this._rangeStart]),this._activeDate=this._rangeEnd||this._rangeStart||this._activeDate,this._viewDate=w(this._activeDate),this._render(),a.emit!==!1&&this._emitChange(!!(this._rangeStart&&this._rangeEnd)),!0)}clear(t={}){this._selectedDate=null,this._rangeStart=null,this._rangeEnd=null,this._render(),t.emit!==!1&&this._emitChange(!1)}focusActiveDay(){this._dayButton(this._activeDate)?.focus()}_bindEvents(){c(this._listeners,this._element,"click",t=>{let i=t.target,a=i.closest?.("[data-calendar-day]"),n=i.closest?.("[data-calendar-prev]"),r=i.closest?.("[data-calendar-next]"),s=i.closest?.("[data-calendar-preset]");n?this._changeMonth(-1,!0):r?this._changeMonth(1,!0):s?this._selectPreset(s.dataset.calendarPreset):a&&this._selectDate(d(a.dataset.calendarDay),!0)}),c(this._listeners,this._element,"keydown",t=>{t.target.closest?.("[data-calendar-day]")&&this._handleDayKeydown(t)}),c(this._listeners,this._element,"change",t=>{t.target.matches?.("[data-calendar-month]")&&this._setActiveMonth(this._viewDate.getFullYear(),Number(t.target.value),!0),t.target.matches?.("[data-calendar-year]")&&this._setActiveMonth(Number(t.target.value),this._viewDate.getMonth(),!0)})}_emitChange(t){g(this._element,this._window,"change.moo.calendar",{date:this._selectedDate?new Date(this._selectedDate):void 0,value:this._selectedDate?f(this._selectedDate):"",startDate:this._rangeStart?new Date(this._rangeStart):void 0,endDate:this._rangeEnd?new Date(this._rangeEnd):void 0,startValue:this._rangeStart?f(this._rangeStart):"",endValue:this._rangeEnd?f(this._rangeEnd):"",complete:t})}_changeMonth(t,i){let a=w(B(this._viewDate,t));this._setActiveMonth(a.getFullYear(),a.getMonth(),i)}_setActiveMonth(t,i,a=!1){let n=Math.min(this._activeDate.getDate(),W(t,i));this._activeDate=this._nearestEnabledDate(new Date(t,i,n)),this._viewDate=w(this._activeDate),this._render(),a&&this.focusActiveDay()}_selectPreset(t){if(!t)return;let i=new Date,a={today:0,tomorrow:1,"in-3-days":3,"in-a-week":7,"in-2-weeks":14};t in a&&this._selectDate(b(i,a[t]),!0)}_handleDayKeydown(t){let i=t.target.closest?.("[data-calendar-day]"),a=d(i?.dataset?.calendarDay);a&&m(a,this._activeDate)!==0&&(this._activeDate=a);let n={ArrowRight:1,ArrowLeft:-1,ArrowDown:7,ArrowUp:-7},r=null;if(t.key in n)r=b(this._activeDate,n[t.key]);else if(t.key==="Home"){let s=T(this._config.locale),_=(this._activeDate.getDay()-s+7)%7;r=b(this._activeDate,-_)}else if(t.key==="End"){let s=T(this._config.locale),_=(this._activeDate.getDay()-s+7)%7;r=b(this._activeDate,6-_)}else if(t.key==="PageUp")r=B(this._activeDate,-1);else if(t.key==="PageDown")r=B(this._activeDate,1);else if(t.key==="Enter"||t.key===" "||t.key==="Spacebar"){t.preventDefault(),this._selectDate(this._activeDate,!0);return}else return;t.preventDefault(),this._setActiveDate(r,!0,m(r,this._activeDate)<0?-1:1)}_setActiveDate(t,i=!1,a=0){let n=a===0?this._nearestEnabledDate(t):this._nextEnabledDate(t,a);this._activeDate=n,this._viewDate=w(n),this._render(),i&&this.focusActiveDay()}_nextEnabledDate(t,i){let a=d(t);if(!a)return this._activeDate;let n=i<0?-1:1;for(let r=0;r<366&&!(this._config.minDate&&m(a,this._config.minDate)<0||this._config.maxDate&&m(a,this._config.maxDate)>0);r+=1){if(!this._isDisabled(a))return a;a=b(a,n)}return this._activeDate}_nearestEnabledDate(t){let i=ft(d(t)||new Date,this._config.minDate,this._config.maxDate);if(!this._isDisabled(i))return i;let a=w(i),n=W(a.getFullYear(),a.getMonth());for(let r=1;r<=n;r+=1){let s=new Date(a.getFullYear(),a.getMonth(),r);if(!this._isDisabled(s))return s}return i}_selectDate(t,i){if(!(!t||this._isDisabled(t))){if(this._activeDate=t,this._viewDate=w(t),this._mode==="range"){!this._rangeStart||this._rangeEnd||m(t,this._rangeStart)<0?(this._rangeStart=t,this._rangeEnd=null):this._rangeEnd=t,this._render(),i&&this._emitChange(!!(this._rangeStart&&this._rangeEnd));return}this._selectedDate=t,this._render(),i&&this._emitChange(!0)}}_isDisabled(t){return!t||this._config.minDate&&m(t,this._config.minDate)<0||this._config.maxDate&&m(t,this._config.maxDate)>0?!0:this._disabledDates.has(f(t))}_isSelected(t){return this._mode==="range"?k(t,this._rangeStart)||k(t,this._rangeEnd):k(t,this._selectedDate)}_rangeState(t){return this._mode!=="range"||!this._rangeStart?"":k(t,this._rangeStart)?"start":k(t,this._rangeEnd)?"end":this._rangeStart&&this._rangeEnd&&m(t,this._rangeStart)>0&&m(t,this._rangeEnd)<0?"middle":""}_dayButton(t){return this._element.querySelector('[data-calendar-day="'.concat(f(t),'"]'))}_render(){let t=this._document,i=t.createDocumentFragment(),a=t.createElement("div");a.className="moo-calendar__header";let n=t.createElement("button");n.className="btn btn-ghost btn-icon-sm moo-calendar__nav",n.type="button",n.dataset.calendarPrev="true",n.setAttribute("aria-label","Previous month"),n.appendChild(at(t,"\u2039","moo-calendar__nav-icon"));let r=t.createElement("button");r.className="btn btn-ghost btn-icon-sm moo-calendar__nav",r.type="button",r.dataset.calendarNext="true",r.setAttribute("aria-label","Next month"),r.appendChild(at(t,"\u203A","moo-calendar__nav-icon"));let s=t.createElement("div");if(s.className="moo-calendar__caption",s.id=this._captionId,s.setAttribute("aria-live","polite"),this._config.captionLayout==="dropdown"){let h=t.createElement("select");h.className="moo-calendar__select",h.dataset.calendarMonth="true",h.setAttribute("aria-label","Month");for(let u=0;u<12;u+=1){let o=t.createElement("option");o.value=String(u),o.textContent=wt(u,this._config.locale),o.selected=u===this._viewDate.getMonth(),h.appendChild(o)}let l=t.createElement("select");l.className="moo-calendar__select",l.dataset.calendarYear="true",l.setAttribute("aria-label","Year"),bt(this._config.minDate,this._config.maxDate,this._viewDate).forEach(u=>{let o=t.createElement("option");o.value=String(u),o.textContent=String(u),o.selected=u===this._viewDate.getFullYear(),l.appendChild(o)}),s.append(h,l)}else s.textContent=tt(this._viewDate,this._config.locale);a.append(n,s,r),i.appendChild(a);let _=t.createElement("div");_.id=this._labelId,_.className="visually-hidden",_.textContent=this._element.getAttribute("aria-label")||tt(this._viewDate,this._config.locale),i.appendChild(_);let S=t.createElement("div");S.className="moo-calendar__weekdays",S.setAttribute("role","row"),_t(this._config.locale).forEach(h=>{let l=t.createElement("span");l.className="moo-calendar__weekday",l.setAttribute("role","columnheader"),l.textContent=new Intl.DateTimeFormat(this._config.locale,{weekday:"narrow"}).format(h),S.appendChild(l)});let D=t.createElement("div");D.className="moo-calendar__grid",D.setAttribute("role","grid"),D.setAttribute("aria-labelledby",this._labelId),D.appendChild(S);let P=w(this._viewDate),Y=T(this._config.locale),A=b(P,-((P.getDay()-Y+7)%7));for(let h=0;h<6;h+=1){let l=t.createElement("div");l.className="moo-calendar__week",l.setAttribute("role","row");for(let u=0;u<7;u+=1){let o=b(A,h*7+u),N=f(o),v=t.createElement("div");v.className="moo-calendar__cell",v.setAttribute("role","gridcell");let p=t.createElement("button");p.className="moo-calendar__day",p.type="button",p.dataset.calendarDay=N,p.textContent=String(o.getDate()),p.tabIndex=k(o,this._activeDate)?0:-1,p.setAttribute("aria-label",x(o,this._config.locale));let G=this._isSelected(o);p.dataset.calendarSelected=String(G),v.setAttribute("aria-selected",G?"true":"false"),o.getMonth()!==this._viewDate.getMonth()&&(p.dataset.calendarOutside="true"),k(o,new Date)&&(p.dataset.calendarToday="true",p.setAttribute("aria-current","date"));let J=this._rangeState(o);J&&(p.dataset.calendarRange=J),this._isDisabled(o)&&(p.disabled=!0,p.setAttribute("aria-disabled","true")),v.appendChild(p),l.appendChild(v)}D.appendChild(l)}if(i.appendChild(D),this._config.showPresets){let h=t.createElement("div");h.className="moo-calendar__presets",[["today","Today"],["tomorrow","Tomorrow"],["in-3-days","In 3 days"],["in-a-week","In a week"],["in-2-weeks","In 2 weeks"]].forEach(([l,u])=>{let o=t.createElement("button");o.className="btn btn-outline-secondary btn-sm moo-calendar__preset",o.type="button",o.dataset.calendarPreset=l,o.textContent=u,h.appendChild(o)}),i.appendChild(h)}this._element.classList.add("moo-calendar"),this._element.dataset.calendar=this._element.dataset.calendar||"",this._element.dataset.calendarMode=this._mode,this._element.dataset.calendarActiveDate=f(this._activeDate),this._mode==="single"&&this._selectedDate?this._element.dataset.calendarValue=f(this._selectedDate):delete this._element.dataset.calendarValue,this._mode==="range"?(this._element.dataset.calendarStartValue=this._rangeStart?f(this._rangeStart):"",this._element.dataset.calendarEndValue=this._rangeEnd?f(this._rangeEnd):""):(delete this._element.dataset.calendarStartValue,delete this._element.dataset.calendarEndValue),this._element.replaceChildren(i)}},H=class e{static getInstance(t){return t?.nodeType===1&&I.get(t)||null}static getOrCreateInstance(t,i={}){return e.getInstance(t)||new e(t,i)}constructor(t,i={}){if(!z(t,"[data-datepicker]"))throw new TypeError("MooDatepicker requires a [data-datepicker] root element.");let a=I.get(t);if(a)return a;if(this._element=t,this._document=t.ownerDocument,this._window=this._document.defaultView||window,this._listeners=[],this._floatingListeners=[],this._disposed=!1,this._positionPopover=null,this._popoverPortal=null,this._trigger=t.querySelector("[data-datepicker-trigger]"),this._popover=t.querySelector("[data-datepicker-popover]"),this._label=t.querySelector("[data-datepicker-label]"),this._input=t.querySelector("[data-datepicker-input]")||t.querySelector('input[type="hidden"]'),this._validationInput=t.querySelector("[data-datepicker-validation]"),this._calendarRoot=t.querySelector("[data-calendar]"),!this._trigger||!this._popover||!this._label||!this._input||!this._calendarRoot)throw new TypeError("MooDatepicker requires a trigger, popover, calendar, and hidden input.");this._config=U(t,{...i,value:i.value||this._input.value||t.dataset.datepickerValue}),this._placeholder=this._config.placeholder,this._defaultValue=this._input.defaultValue||this._input.getAttribute("value")||"",this.calendar=L.getOrCreateInstance(this._calendarRoot,{...this._config,mode:"single",value:this._input.value||this._config.value}),I.set(t,this),this._syncFromCalendar(),this._bindEvents()}dispose(){this._disposed||(this._disposed=!0,E(this._listeners),this.hide(!1),F(this),R(this),E(this._floatingListeners),this.calendar?.dispose(),I.get(this._element)===this&&I.delete(this._element))}show(){this._trigger.disabled||this._element.dataset.datepickerDisabled==="true"||this.isOpen()||g(this._element,this._window,"show.moo.datepicker",{},!0)&&(this._popover.hidden=!1,this._popover.classList.add("show"),ot(this),this._trigger.setAttribute("aria-expanded","true"),this.calendar.focusActiveDay(),g(this._element,this._window,"shown.moo.datepicker"))}hide(t=!0){this.isOpen()&&g(this._element,this._window,"hide.moo.datepicker",{},!0)&&(this._popover.hidden=!0,this._popover.classList.remove("show"),F(this),this._trigger.setAttribute("aria-expanded","false"),t&&this._trigger.focus({preventScroll:!0}),g(this._element,this._window,"hidden.moo.datepicker"))}toggle(){this.isOpen()?this.hide():this.show()}isOpen(){return!this._popover.hidden}getDate(t=void 0){return this.calendar.getDate(t)}setDate(t,i={}){let a=this.calendar.setDate(t,{emit:!1});return a&&(this._syncFromCalendar(),i.emit!==!1&&this._emitChange()),a}clear(t={}){this.calendar.clear({emit:!1}),this._syncFromCalendar(),t.emit!==!1&&this._emitChange()}_bindEvents(){c(this._listeners,this._trigger,"click",()=>this.toggle()),c(this._listeners,this._popover,"keydown",i=>{i.key==="Escape"&&(i.preventDefault(),this.hide())}),c(this._listeners,this._document,"pointerdown",i=>{this.isOpen()&&!O(this,i.target)&&this._window.setTimeout(()=>{this.isOpen()&&!O(this,i.target)&&this.hide()},0)}),c(this._listeners,this._calendarRoot,"change.moo.calendar",i=>{this._syncFromCalendar(),this._emitChange(),i.detail.complete&&this.hide()});let t=this._input.form||this._element.closest("form");c(this._listeners,this._validationInput,"invalid",i=>{i.preventDefault(),j(this._element,this._trigger,!0),this._trigger.focus({preventScroll:!0})}),c(this._listeners,t,"reset",()=>{this._window.setTimeout(()=>{this._defaultValue?this.setDate(this._defaultValue,{emit:!1}):this.clear({emit:!1})},0)})}_syncFromCalendar(){let t=this.calendar.getDate("yyyy-mm-dd")||"";K(this._input,t),rt(this._validationInput,t),st(this._element,this._trigger,this._validationInput),this._element.dataset.datepickerValue=t,this._label.dataset.datepickerEmpty=t?"false":"true",this._label.textContent=t?x(d(t),this._config.locale):this._placeholder}_emitChange(){g(this._element,this._window,"change.moo.datepicker",{date:this.getDate(),value:this.getDate("yyyy-mm-dd")||""})}},nt=class e{static getInstance(t){return t?.nodeType===1&&M.get(t)||null}static getOrCreateInstance(t,i={}){return e.getInstance(t)||new e(t,i)}constructor(t,i={}){if(!z(t,"[data-datepicker-range]"))throw new TypeError("MooDateRangePicker requires a [data-datepicker-range] root element.");let a=M.get(t);if(a)return a;if(this._element=t,this._document=t.ownerDocument,this._window=this._document.defaultView||window,this._listeners=[],this._floatingListeners=[],this._disposed=!1,this._positionPopover=null,this._popoverPortal=null,this._trigger=t.querySelector("[data-datepicker-trigger]"),this._popover=t.querySelector("[data-datepicker-popover]"),this._label=t.querySelector("[data-datepicker-label]"),this._startInput=t.querySelector("[data-datepicker-range-start]"),this._endInput=t.querySelector("[data-datepicker-range-end]"),this._validationInput=t.querySelector("[data-datepicker-validation]"),this._calendarRoot=t.querySelector("[data-calendar]"),!this._trigger||!this._popover||!this._label||!this._startInput||!this._endInput||!this._calendarRoot)throw new TypeError("MooDateRangePicker requires a trigger, popover, calendar, and start/end hidden inputs.");this._config=U(t,{...i,mode:"range",startValue:i.startValue||this._startInput.value||t.dataset.datepickerStartValue,endValue:i.endValue||this._endInput.value||t.dataset.datepickerEndValue}),this._placeholder=this._config.placeholder,this._defaultStartValue=this._startInput.defaultValue||this._startInput.getAttribute("value")||"",this._defaultEndValue=this._endInput.defaultValue||this._endInput.getAttribute("value")||"",this.calendar=L.getOrCreateInstance(this._calendarRoot,this._config),M.set(t,this),this._syncFromCalendar(),this._bindEvents()}dispose(){this._disposed||(this._disposed=!0,E(this._listeners),this.hide(!1),F(this),R(this),E(this._floatingListeners),this.calendar?.dispose(),M.get(this._element)===this&&M.delete(this._element))}show(){this._trigger.disabled||this._element.dataset.datepickerDisabled==="true"||this.isOpen()||g(this._element,this._window,"show.moo.datepicker",{},!0)&&(this._popover.hidden=!1,this._popover.classList.add("show"),ot(this),this._trigger.setAttribute("aria-expanded","true"),this.calendar.focusActiveDay(),g(this._element,this._window,"shown.moo.datepicker"))}hide(t=!0){this.isOpen()&&g(this._element,this._window,"hide.moo.datepicker",{},!0)&&(this._popover.hidden=!0,this._popover.classList.remove("show"),F(this),this._trigger.setAttribute("aria-expanded","false"),t&&this._trigger.focus({preventScroll:!0}),g(this._element,this._window,"hidden.moo.datepicker"))}toggle(){this.isOpen()?this.hide():this.show()}isOpen(){return!this._popover.hidden}getDates(t=void 0){return this.calendar.getDates(t)}setDates(t,i,a={}){let n=this.calendar.setDates(t,i,{emit:!1});return n&&(this._syncFromCalendar(),a.emit!==!1&&this._emitChange()),n}clear(t={}){this.calendar.clear({emit:!1}),this._syncFromCalendar(),t.emit!==!1&&this._emitChange()}_bindEvents(){c(this._listeners,this._trigger,"click",()=>this.toggle()),c(this._listeners,this._popover,"keydown",a=>{a.key==="Escape"&&(a.preventDefault(),this.hide())}),c(this._listeners,this._document,"pointerdown",a=>{this.isOpen()&&!O(this,a.target)&&this._window.setTimeout(()=>{this.isOpen()&&!O(this,a.target)&&this.hide()},0)});let t=()=>{this._window.setTimeout(()=>{this.isOpen()&&!O(this,this._document.activeElement)&&this.hide(!1)},0)};c(this._listeners,this._element,"focusout",t),c(this._listeners,this._popover,"focusout",t),c(this._listeners,this._calendarRoot,"change.moo.calendar",a=>{this._syncFromCalendar(),this._emitChange(),a.detail.complete?this.hide():this.calendar.focusActiveDay()});let i=this._startInput.form||this._element.closest("form");c(this._listeners,this._validationInput,"invalid",a=>{a.preventDefault(),j(this._element,this._trigger,!0),this._trigger.focus({preventScroll:!0})}),c(this._listeners,i,"reset",()=>{this._window.setTimeout(()=>{this.setDates(this._defaultStartValue,this._defaultEndValue,{emit:!1})},0)})}_syncFromCalendar(){let[t="",i=""]=this.calendar.getDates("yyyy-mm-dd");K(this._startInput,t||""),K(this._endInput,i||""),rt(this._validationInput,t&&i?"".concat(t," - ").concat(i):""),st(this._element,this._trigger,this._validationInput),this._element.dataset.datepickerStartValue=t||"",this._element.dataset.datepickerEndValue=i||"",this._label.dataset.datepickerEmpty=t?"false":"true",t&&i?this._label.textContent="".concat(x(d(t),this._config.locale)," - ").concat(x(d(i),this._config.locale)):t?this._label.textContent=x(d(t),this._config.locale):this._label.textContent=this._placeholder}_emitChange(){let[t,i]=this.getDates(),[a="",n=""]=this.getDates("yyyy-mm-dd");g(this._element,this._window,"change.moo.datepicker",{startDate:t,endDate:i,startValue:a,endValue:n})}};export{L as MooCalendar,nt as MooDateRangePicker,H as default};
|
package/dist/js/moo-ui.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* Moo UI moo-ui.js v1.
|
|
2
|
+
* Moo UI moo-ui.js v1.4.1 (https://wpmoo.org/)
|
|
3
3
|
* Copyright 2026 WPMoo Authors
|
|
4
4
|
* Licensed under MIT (https://github.com/wpmoo-org/ui/blob/main/LICENSE)
|
|
5
5
|
*/
|
|
@@ -2949,6 +2949,7 @@ var MooDatepicker = class _MooDatepicker {
|
|
|
2949
2949
|
setValidationValue(this._validationInput, value);
|
|
2950
2950
|
syncDatepickerValidation(this._element, this._trigger, this._validationInput);
|
|
2951
2951
|
this._element.dataset.datepickerValue = value;
|
|
2952
|
+
this._label.dataset.datepickerEmpty = value ? "false" : "true";
|
|
2952
2953
|
this._label.textContent = value ? formatDisplay(parseDate(value), this._config.locale) : this._placeholder;
|
|
2953
2954
|
}
|
|
2954
2955
|
_emitChange() {
|
|
@@ -3119,6 +3120,7 @@ var MooDateRangePicker = class _MooDateRangePicker {
|
|
|
3119
3120
|
syncDatepickerValidation(this._element, this._trigger, this._validationInput);
|
|
3120
3121
|
this._element.dataset.datepickerStartValue = startValue || "";
|
|
3121
3122
|
this._element.dataset.datepickerEndValue = endValue || "";
|
|
3123
|
+
this._label.dataset.datepickerEmpty = startValue ? "false" : "true";
|
|
3122
3124
|
if (startValue && endValue) {
|
|
3123
3125
|
this._label.textContent = `${formatDisplay(parseDate(startValue), this._config.locale)} - ${formatDisplay(parseDate(endValue), this._config.locale)}`;
|
|
3124
3126
|
} else if (startValue) {
|
|
@@ -4068,6 +4070,307 @@ var TableOfContents = class _TableOfContents {
|
|
|
4068
4070
|
}
|
|
4069
4071
|
};
|
|
4070
4072
|
|
|
4073
|
+
// src/js/components/overlay-scrollbar.js
|
|
4074
|
+
var instances7 = /* @__PURE__ */ new WeakMap();
|
|
4075
|
+
var nextId = 0;
|
|
4076
|
+
var OverlayScrollbar = class _OverlayScrollbar {
|
|
4077
|
+
static getInstance(owner, scrollElement = owner?.ownerDocument?.scrollingElement) {
|
|
4078
|
+
const instance = scrollElement && instances7.get(scrollElement);
|
|
4079
|
+
return instance?._owner === owner ? instance : null;
|
|
4080
|
+
}
|
|
4081
|
+
static getOrCreateInstance(owner, options = {}) {
|
|
4082
|
+
return _OverlayScrollbar.getInstance(owner, options.scrollElement) || new _OverlayScrollbar(owner, options);
|
|
4083
|
+
}
|
|
4084
|
+
constructor(owner, { scrollElement = null, hideDelay = 900, label = "Page scroll position" } = {}) {
|
|
4085
|
+
if (!owner?.matches?.('.moo-ui[data-bs-theme="light"], .moo-ui[data-bs-theme="dark"]') || !owner.isConnected) {
|
|
4086
|
+
throw new TypeError("OverlayScrollbar requires a connected, resolved .moo-ui theme owner.");
|
|
4087
|
+
}
|
|
4088
|
+
if (!Number.isFinite(hideDelay) || hideDelay < 0 || typeof label !== "string" || !label.trim()) {
|
|
4089
|
+
throw new TypeError("OverlayScrollbar requires a nonnegative hideDelay and a nonempty label.");
|
|
4090
|
+
}
|
|
4091
|
+
const document2 = owner.ownerDocument;
|
|
4092
|
+
const root = scrollElement ?? document2.scrollingElement;
|
|
4093
|
+
const isDocument = root === document2.scrollingElement;
|
|
4094
|
+
if (root?.nodeType !== 1 || !root.isConnected || root.ownerDocument !== document2 || !isDocument && (!owner.contains(root) || root.closest('.moo-ui[data-bs-theme="light"], .moo-ui[data-bs-theme="dark"]') !== owner)) {
|
|
4095
|
+
throw new TypeError("OverlayScrollbar scrollElement must belong to the same resolved theme owner.");
|
|
4096
|
+
}
|
|
4097
|
+
const existing = instances7.get(root);
|
|
4098
|
+
if (existing) {
|
|
4099
|
+
if (existing._owner === owner) return existing;
|
|
4100
|
+
throw new Error("Only one OverlayScrollbar theme owner may control a scroll element.");
|
|
4101
|
+
}
|
|
4102
|
+
this._owner = owner;
|
|
4103
|
+
this._document = document2;
|
|
4104
|
+
this._window = document2.defaultView;
|
|
4105
|
+
this._root = root;
|
|
4106
|
+
this._isDocument = isDocument;
|
|
4107
|
+
if (isDocument && root !== document2.documentElement) {
|
|
4108
|
+
throw new TypeError("OverlayScrollbar requires a standards-mode document scroll root.");
|
|
4109
|
+
}
|
|
4110
|
+
this._hideDelay = hideDelay;
|
|
4111
|
+
this._listeners = [];
|
|
4112
|
+
this._frame = 0;
|
|
4113
|
+
this._timer = 0;
|
|
4114
|
+
this._disposed = false;
|
|
4115
|
+
this._originalNativeClass = this._root.classList.contains("scrollbar-overlay-native");
|
|
4116
|
+
this._originalId = this._root.getAttribute("id");
|
|
4117
|
+
this._forcedColors = this._window.matchMedia("(forced-colors: active)");
|
|
4118
|
+
this._bar = document2.createElement("div");
|
|
4119
|
+
this._bar.className = "scrollbar-overlay";
|
|
4120
|
+
this._bar.tabIndex = 0;
|
|
4121
|
+
this._bar.setAttribute("role", "scrollbar");
|
|
4122
|
+
this._bar.setAttribute("aria-label", label);
|
|
4123
|
+
this._bar.setAttribute("aria-orientation", "vertical");
|
|
4124
|
+
this._bar.setAttribute("aria-valuemin", "0");
|
|
4125
|
+
this._thumb = document2.createElement("div");
|
|
4126
|
+
this._thumb.className = "scrollbar-overlay-thumb";
|
|
4127
|
+
this._thumb.setAttribute("aria-hidden", "true");
|
|
4128
|
+
this._bar.append(this._thumb);
|
|
4129
|
+
owner.append(this._bar);
|
|
4130
|
+
if (this._window.getComputedStyle(this._bar).position !== "fixed") {
|
|
4131
|
+
this._bar.remove();
|
|
4132
|
+
throw new Error("OverlayScrollbar requires the Moo UI overlay scrollbar stylesheet.");
|
|
4133
|
+
}
|
|
4134
|
+
if (!this._originalId) {
|
|
4135
|
+
do {
|
|
4136
|
+
this._generatedId = `scrollbar-overlay-page-${++nextId}`;
|
|
4137
|
+
} while (document2.getElementById(this._generatedId));
|
|
4138
|
+
this._root.id = this._generatedId;
|
|
4139
|
+
}
|
|
4140
|
+
this._bar.setAttribute("aria-controls", this._root.id);
|
|
4141
|
+
instances7.set(root, this);
|
|
4142
|
+
try {
|
|
4143
|
+
this._listen(isDocument ? this._window : root, "scroll", () => {
|
|
4144
|
+
this._reveal();
|
|
4145
|
+
this._queue();
|
|
4146
|
+
}, { passive: true });
|
|
4147
|
+
if (!isDocument) {
|
|
4148
|
+
this._listen(document2, "scroll", () => this._queue(), { passive: true, capture: true });
|
|
4149
|
+
}
|
|
4150
|
+
this._listen(this._window, "resize", () => this._queue());
|
|
4151
|
+
this._listen(document2, "pointermove", (event) => this._onPointerMove(event), { passive: true });
|
|
4152
|
+
this._listen(document2, "pointerout", (event) => {
|
|
4153
|
+
if (event.pointerType === "mouse" && !event.relatedTarget) {
|
|
4154
|
+
this._nearEdge = false;
|
|
4155
|
+
if (!this._drag) delete this._bar.dataset.scrollbarInteractive;
|
|
4156
|
+
this._hideLater();
|
|
4157
|
+
}
|
|
4158
|
+
});
|
|
4159
|
+
this._listen(this._bar, "pointerdown", (event) => this._onPointerDown(event));
|
|
4160
|
+
this._listen(this._bar, "pointerup", () => this._finishDrag());
|
|
4161
|
+
this._listen(this._bar, "pointercancel", () => this._finishDrag());
|
|
4162
|
+
this._listen(this._bar, "lostpointercapture", () => this._finishDrag());
|
|
4163
|
+
this._listen(this._bar, "focus", () => this._reveal());
|
|
4164
|
+
this._listen(this._bar, "blur", () => this._hideLater());
|
|
4165
|
+
this._listen(this._bar, "keydown", (event) => this._onKeyDown(event));
|
|
4166
|
+
this._listen(this._forcedColors, "change", () => this.refresh());
|
|
4167
|
+
this._listen(this._window, "beforeprint", () => {
|
|
4168
|
+
this._printing = true;
|
|
4169
|
+
this.refresh();
|
|
4170
|
+
});
|
|
4171
|
+
this._listen(this._window, "afterprint", () => {
|
|
4172
|
+
this._printing = false;
|
|
4173
|
+
this.refresh();
|
|
4174
|
+
});
|
|
4175
|
+
this._resize = new this._window.ResizeObserver(() => this._queue());
|
|
4176
|
+
this._resize.observe(this._root);
|
|
4177
|
+
this._resize.observe(document2.body);
|
|
4178
|
+
this._mutations = new this._window.MutationObserver(() => this._queue());
|
|
4179
|
+
this._mutations.observe(this._root, { attributes: true, attributeFilter: ["class", "style", "dir"] });
|
|
4180
|
+
if (!isDocument) {
|
|
4181
|
+
this._mutations.observe(document2.documentElement, { attributes: true, attributeFilter: ["class", "style", "dir"] });
|
|
4182
|
+
}
|
|
4183
|
+
this._mutations.observe(document2.body, {
|
|
4184
|
+
attributes: true,
|
|
4185
|
+
attributeFilter: ["class", "style"]
|
|
4186
|
+
});
|
|
4187
|
+
this._mutations.observe(owner, { attributes: true, attributeFilter: ["class", "style", "dir", "data-bs-theme"] });
|
|
4188
|
+
this._contentMutations = new this._window.MutationObserver((records) => {
|
|
4189
|
+
if (records.some((record) => record.target !== this._bar && !this._bar.contains(record.target))) this._queue();
|
|
4190
|
+
});
|
|
4191
|
+
this._contentMutations.observe(isDocument ? document2.body : root, {
|
|
4192
|
+
childList: true,
|
|
4193
|
+
subtree: true,
|
|
4194
|
+
attributes: true,
|
|
4195
|
+
attributeFilter: ["class", "style", "hidden"]
|
|
4196
|
+
});
|
|
4197
|
+
this._listen(root, "load", () => this._queue(), { capture: true });
|
|
4198
|
+
if (document2.fonts) this._listen(document2.fonts, "loadingdone", () => this._queue());
|
|
4199
|
+
this.refresh();
|
|
4200
|
+
} catch (error) {
|
|
4201
|
+
this.dispose();
|
|
4202
|
+
throw error;
|
|
4203
|
+
}
|
|
4204
|
+
}
|
|
4205
|
+
refresh() {
|
|
4206
|
+
if (this._disposed) return this;
|
|
4207
|
+
const window2 = this._window;
|
|
4208
|
+
const root = this._root;
|
|
4209
|
+
const eligible = !this._forcedColors.matches && !this._printing;
|
|
4210
|
+
if (eligible) root.classList.add("scrollbar-overlay-native");
|
|
4211
|
+
const enabled = eligible && root.scrollWidth <= root.clientWidth + 1;
|
|
4212
|
+
root.classList.toggle("scrollbar-overlay-native", this._originalNativeClass || enabled);
|
|
4213
|
+
this._mutations?.takeRecords();
|
|
4214
|
+
this._contentMutations?.takeRecords();
|
|
4215
|
+
const locked = (this._isDocument ? [root, this._document.body] : [root]).some((element) => ["hidden", "clip"].includes(window2.getComputedStyle(element).overflowY));
|
|
4216
|
+
this._maximum = Math.max(0, root.scrollHeight - root.clientHeight);
|
|
4217
|
+
const visible = this._position();
|
|
4218
|
+
this._bar.hidden = !enabled || locked || !visible || this._maximum <= 0;
|
|
4219
|
+
if (this._bar.hidden) {
|
|
4220
|
+
if (this._document.activeElement === this._bar) this._bar.blur();
|
|
4221
|
+
delete this._bar.dataset.scrollbarVisible;
|
|
4222
|
+
delete this._bar.dataset.scrollbarInteractive;
|
|
4223
|
+
return this;
|
|
4224
|
+
}
|
|
4225
|
+
const minimum = this._bar.clientWidth;
|
|
4226
|
+
const height = this._bar.clientHeight;
|
|
4227
|
+
const thumbHeight = Math.min(height, Math.max(minimum, height * root.clientHeight / root.scrollHeight));
|
|
4228
|
+
this._travel = Math.max(0, height - thumbHeight);
|
|
4229
|
+
const position = Math.min(this._maximum, Math.max(0, root.scrollTop));
|
|
4230
|
+
this._thumb.style.height = `${thumbHeight}px`;
|
|
4231
|
+
this._thumb.style.transform = `translateY(${this._travel * position / this._maximum}px)`;
|
|
4232
|
+
this._bar.setAttribute("aria-valuemax", String(Math.round(this._maximum)));
|
|
4233
|
+
this._bar.setAttribute("aria-valuenow", String(Math.round(position)));
|
|
4234
|
+
return this;
|
|
4235
|
+
}
|
|
4236
|
+
_position() {
|
|
4237
|
+
if (this._isDocument) return true;
|
|
4238
|
+
const root = this._root;
|
|
4239
|
+
const bounds = root.getBoundingClientRect();
|
|
4240
|
+
const top = Math.max(0, bounds.top + root.clientTop);
|
|
4241
|
+
const bottom = Math.min(this._window.innerHeight, bounds.top + root.clientTop + root.clientHeight);
|
|
4242
|
+
const width = parseFloat(this._window.getComputedStyle(this._bar).inlineSize);
|
|
4243
|
+
const rtl = this._window.getComputedStyle(root).direction === "rtl";
|
|
4244
|
+
const left = bounds.left + root.clientLeft + (rtl ? 0 : root.clientWidth - width);
|
|
4245
|
+
Object.assign(this._bar.style, {
|
|
4246
|
+
insetInlineEnd: "auto",
|
|
4247
|
+
bottom: "auto",
|
|
4248
|
+
top: `${top}px`,
|
|
4249
|
+
height: `${Math.max(0, bottom - top)}px`,
|
|
4250
|
+
left: `${Math.max(0, Math.min(this._window.innerWidth - width, left))}px`,
|
|
4251
|
+
direction: rtl ? "rtl" : "ltr"
|
|
4252
|
+
});
|
|
4253
|
+
return bounds.width > 0 && bottom > top && left < this._window.innerWidth && left + width > 0;
|
|
4254
|
+
}
|
|
4255
|
+
dispose() {
|
|
4256
|
+
if (this._disposed) return;
|
|
4257
|
+
this._disposed = true;
|
|
4258
|
+
for (const [target, type, handler, options] of this._listeners) {
|
|
4259
|
+
target.removeEventListener(type, handler, options);
|
|
4260
|
+
}
|
|
4261
|
+
this._listeners = [];
|
|
4262
|
+
this._resize?.disconnect();
|
|
4263
|
+
this._mutations?.disconnect();
|
|
4264
|
+
this._contentMutations?.disconnect();
|
|
4265
|
+
this._window.cancelAnimationFrame(this._frame);
|
|
4266
|
+
this._window.clearTimeout(this._timer);
|
|
4267
|
+
if (this._drag && this._bar.hasPointerCapture(this._drag.id)) this._bar.releasePointerCapture(this._drag.id);
|
|
4268
|
+
this._drag = null;
|
|
4269
|
+
this._bar.remove();
|
|
4270
|
+
this._root.classList.toggle("scrollbar-overlay-native", this._originalNativeClass);
|
|
4271
|
+
if (this._generatedId && this._root.id === this._generatedId) {
|
|
4272
|
+
if (this._originalId === null) this._root.removeAttribute("id");
|
|
4273
|
+
else this._root.setAttribute("id", this._originalId);
|
|
4274
|
+
}
|
|
4275
|
+
if (instances7.get(this._root) === this) instances7.delete(this._root);
|
|
4276
|
+
}
|
|
4277
|
+
_listen(target, type, handler, options) {
|
|
4278
|
+
target.addEventListener(type, handler, options);
|
|
4279
|
+
this._listeners.push([target, type, handler, options]);
|
|
4280
|
+
}
|
|
4281
|
+
_queue() {
|
|
4282
|
+
if (this._disposed || this._frame) return;
|
|
4283
|
+
this._frame = this._window.requestAnimationFrame(() => {
|
|
4284
|
+
this._frame = 0;
|
|
4285
|
+
this.refresh();
|
|
4286
|
+
});
|
|
4287
|
+
}
|
|
4288
|
+
_reveal() {
|
|
4289
|
+
if (this._disposed || this._bar.hidden) return;
|
|
4290
|
+
this._bar.dataset.scrollbarVisible = "true";
|
|
4291
|
+
this._hideLater();
|
|
4292
|
+
}
|
|
4293
|
+
_hideLater() {
|
|
4294
|
+
this._window.clearTimeout(this._timer);
|
|
4295
|
+
this._timer = 0;
|
|
4296
|
+
if (this._disposed) return;
|
|
4297
|
+
if (!this._bar.hasAttribute("data-scrollbar-visible")) return;
|
|
4298
|
+
this._timer = this._window.setTimeout(() => {
|
|
4299
|
+
this._timer = 0;
|
|
4300
|
+
if (this._disposed || this._nearEdge || this._drag || this._bar.matches(":focus-visible")) return;
|
|
4301
|
+
delete this._bar.dataset.scrollbarVisible;
|
|
4302
|
+
}, this._hideDelay);
|
|
4303
|
+
}
|
|
4304
|
+
_onPointerMove(event) {
|
|
4305
|
+
if (this._disposed) return;
|
|
4306
|
+
if (this._drag?.id === event.pointerId) {
|
|
4307
|
+
if (this._travel) this._scroll(this._drag.top + (event.clientY - this._drag.y) * this._maximum / this._travel);
|
|
4308
|
+
return;
|
|
4309
|
+
}
|
|
4310
|
+
if (event.pointerType !== "mouse") {
|
|
4311
|
+
this._nearEdge = false;
|
|
4312
|
+
if (!this._drag) delete this._bar.dataset.scrollbarInteractive;
|
|
4313
|
+
return;
|
|
4314
|
+
}
|
|
4315
|
+
const bounds = this._bar.getBoundingClientRect();
|
|
4316
|
+
const nearEdge = !this._bar.hidden && event.clientX >= bounds.left && event.clientX <= bounds.right && event.clientY >= bounds.top && event.clientY <= bounds.bottom;
|
|
4317
|
+
if (nearEdge) {
|
|
4318
|
+
this._nearEdge = true;
|
|
4319
|
+
this._bar.dataset.scrollbarInteractive = "true";
|
|
4320
|
+
this._reveal();
|
|
4321
|
+
} else if (this._nearEdge) {
|
|
4322
|
+
this._nearEdge = false;
|
|
4323
|
+
if (!this._drag) delete this._bar.dataset.scrollbarInteractive;
|
|
4324
|
+
this._hideLater();
|
|
4325
|
+
}
|
|
4326
|
+
}
|
|
4327
|
+
_onPointerDown(event) {
|
|
4328
|
+
if (event.button !== 0 || this._bar.hidden || event.pointerType === "touch") return;
|
|
4329
|
+
event.preventDefault();
|
|
4330
|
+
this._reveal();
|
|
4331
|
+
const thumb = this._thumb.getBoundingClientRect();
|
|
4332
|
+
if (event.clientY >= thumb.top && event.clientY <= thumb.bottom) {
|
|
4333
|
+
this._drag = { id: event.pointerId, y: event.clientY, top: this._root.scrollTop };
|
|
4334
|
+
this._bar.setPointerCapture(event.pointerId);
|
|
4335
|
+
} else {
|
|
4336
|
+
const direction = event.clientY < this._thumb.getBoundingClientRect().top ? -1 : 1;
|
|
4337
|
+
this._scroll(this._root.scrollTop + direction * this._root.clientHeight);
|
|
4338
|
+
}
|
|
4339
|
+
}
|
|
4340
|
+
_finishDrag() {
|
|
4341
|
+
if (!this._drag || this._disposed) return;
|
|
4342
|
+
const id = this._drag.id;
|
|
4343
|
+
this._drag = null;
|
|
4344
|
+
if (!this._nearEdge) delete this._bar.dataset.scrollbarInteractive;
|
|
4345
|
+
if (this._bar.hasPointerCapture(id)) this._bar.releasePointerCapture(id);
|
|
4346
|
+
this._hideLater();
|
|
4347
|
+
}
|
|
4348
|
+
_onKeyDown(event) {
|
|
4349
|
+
if (event.altKey || event.ctrlKey || event.metaKey) return;
|
|
4350
|
+
this.refresh();
|
|
4351
|
+
const step = parseFloat(this._window.getComputedStyle(this._root).lineHeight) || 16;
|
|
4352
|
+
const page = this._root.clientHeight;
|
|
4353
|
+
const targets = {
|
|
4354
|
+
ArrowUp: this._root.scrollTop - step,
|
|
4355
|
+
ArrowDown: this._root.scrollTop + step,
|
|
4356
|
+
PageUp: this._root.scrollTop - page,
|
|
4357
|
+
PageDown: this._root.scrollTop + page,
|
|
4358
|
+
Home: 0,
|
|
4359
|
+
End: this._maximum,
|
|
4360
|
+
" ": this._root.scrollTop + (event.shiftKey ? -page : page)
|
|
4361
|
+
};
|
|
4362
|
+
if (!Object.hasOwn(targets, event.key)) return;
|
|
4363
|
+
event.preventDefault();
|
|
4364
|
+
this._scroll(targets[event.key]);
|
|
4365
|
+
this._reveal();
|
|
4366
|
+
}
|
|
4367
|
+
_scroll(top) {
|
|
4368
|
+
const target = this._isDocument ? this._window : this._root;
|
|
4369
|
+
target.scrollTo({ top: Math.min(this._maximum, Math.max(0, top)), behavior: "instant" });
|
|
4370
|
+
this._queue();
|
|
4371
|
+
}
|
|
4372
|
+
};
|
|
4373
|
+
|
|
4071
4374
|
// src/js/components/sheet.js
|
|
4072
4375
|
var states = /* @__PURE__ */ new WeakMap();
|
|
4073
4376
|
function initSheets(root = document) {
|
|
@@ -4122,6 +4425,7 @@ var MooUI = {
|
|
|
4122
4425
|
Sidebar,
|
|
4123
4426
|
Slider: MooSlider,
|
|
4124
4427
|
TableOfContents,
|
|
4428
|
+
OverlayScrollbar,
|
|
4125
4429
|
initSheets
|
|
4126
4430
|
};
|
|
4127
4431
|
var moo_ui_default = MooUI;
|
|
@@ -4132,6 +4436,7 @@ export {
|
|
|
4132
4436
|
MooDatepicker as Datepicker,
|
|
4133
4437
|
MooCalendar,
|
|
4134
4438
|
MooDateRangePicker,
|
|
4439
|
+
OverlayScrollbar,
|
|
4135
4440
|
Sidebar,
|
|
4136
4441
|
MooSlider as Slider,
|
|
4137
4442
|
TableOfContents,
|