@wpmoo/ui 1.0.0-rc.6 → 1.0.0-rc.7
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 +4 -4
- package/certification.json +1 -1
- package/dist/assets/css/moo-ui.css +7742 -8126
- package/dist/assets/css/moo-ui.min.css +2 -2
- package/dist/assets/css/moo.css +242 -290
- package/dist/assets/css/moo.min.css +2 -2
- package/dist/js/chart.js +57 -5
- package/dist/js/chart.min.js +3 -3
- package/dist/js/combobox.js +1 -1
- package/dist/js/context-menu.js +1 -1
- package/dist/js/datatable.js +114 -213
- package/dist/js/datepicker.js +79 -37
- package/dist/js/datepicker.min.js +2 -2
- package/dist/js/moo-ui.js +168 -51
- package/dist/js/moo-ui.min.js +3 -3
- package/dist/js/sidebar.js +121 -174
- package/dist/js/slider.js +1 -1
- package/package.json +8 -8
- package/scss/components/_alert.scss +1 -2
- package/scss/components/_card.scss +5 -5
- package/scss/components/_close_button.scss +8 -3
- package/scss/components/_dialog.scss +16 -0
- package/scss/components/_dropdown.scss +2 -7
- package/scss/components/_switch.scss +13 -5
- package/scss/components/_tabs.scss +1 -1
- package/scss/components/sidebar/_collapsed.scss +20 -23
- package/scss/components/sidebar/_inset.scss +14 -44
- package/scss/components/sidebar/_layout.scss +86 -11
- package/scss/foundations/_backdrop.scss +128 -0
- package/scss/foundations/_scope.scss +5 -0
- package/scss/mixins/_banner.scss +3 -0
- package/scss/moo-core.scss +6 -34
- package/scss/moo-ui.scss +6 -6
- package/scss/settings/_bootstrap_overrides.scss +4 -0
- package/scss/settings/_component_variables.scss +6 -1
- package/scss/settings/_options.scss +2 -0
- package/scss/settings/_palette.scss +1 -1
- package/scss/themes/_forms.scss +15 -0
- package/scss/themes/_root.scss +16 -0
- package/scss/themes/_standalone.scss +5 -0
- package/scss/themes/{_scoped_core.scss → _theme.scss} +1 -0
- package/scss/foundations/_core_state_layer.scss +0 -25
- package/scss/foundations/_overlay_backdrop.scss +0 -19
- package/scss/themes/_standalone_root.scss +0 -119
- /package/scss/foundations/{_core_global_primitives.scss → _globals.scss} +0 -0
package/dist/js/datepicker.js
CHANGED
|
@@ -1,8 +1,39 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* Moo UI datepicker.js v1.0.0-rc.
|
|
2
|
+
* Moo UI datepicker.js v1.0.0-rc.7 (https://ui.wpmoo.org/)
|
|
3
3
|
* Copyright 2026 WPMoo (https://wpmoo.org)
|
|
4
4
|
* Licensed under MIT (https://github.com/wpmoo-org/ui/blob/main/LICENSE)
|
|
5
5
|
*/
|
|
6
|
+
// src/js/theme-owner.js
|
|
7
|
+
var OWNER_SELECTOR = '.moo-ui[data-bs-theme="light"], .moo-ui[data-bs-theme="dark"]';
|
|
8
|
+
var PORTAL_SELECTOR = "[data-moo-overlay-portal-host]";
|
|
9
|
+
function documentFor(node) {
|
|
10
|
+
if (node?.nodeType === 9) return node;
|
|
11
|
+
if (node?.ownerDocument) return node.ownerDocument;
|
|
12
|
+
return typeof document === "undefined" ? null : document;
|
|
13
|
+
}
|
|
14
|
+
function isResolvedOwner(node) {
|
|
15
|
+
return Boolean(node?.matches?.(OWNER_SELECTOR));
|
|
16
|
+
}
|
|
17
|
+
function ownerRootFor(node) {
|
|
18
|
+
const ownerDocument = documentFor(node);
|
|
19
|
+
if (node?.nodeType === 9 || node === ownerDocument?.body) {
|
|
20
|
+
return ownerDocument?.body?.firstElementChild || null;
|
|
21
|
+
}
|
|
22
|
+
return node;
|
|
23
|
+
}
|
|
24
|
+
function findThemeOwner(node = typeof document === "undefined" ? null : document) {
|
|
25
|
+
const start = ownerRootFor(node);
|
|
26
|
+
if (!start) return null;
|
|
27
|
+
if (isResolvedOwner(start)) return start;
|
|
28
|
+
return start.closest?.(OWNER_SELECTOR) || null;
|
|
29
|
+
}
|
|
30
|
+
function ownerPortalRoot(owner) {
|
|
31
|
+
if (!owner) return null;
|
|
32
|
+
return Array.from(owner.children || []).find(
|
|
33
|
+
(child) => child.matches?.(PORTAL_SELECTOR)
|
|
34
|
+
) || owner;
|
|
35
|
+
}
|
|
36
|
+
|
|
6
37
|
// src/js/components/datepicker.js
|
|
7
38
|
var datepickerInstances = /* @__PURE__ */ new WeakMap();
|
|
8
39
|
var calendarInstances = /* @__PURE__ */ new WeakMap();
|
|
@@ -211,42 +242,54 @@ function datepickerContains(instance, target) {
|
|
|
211
242
|
);
|
|
212
243
|
}
|
|
213
244
|
function syncPortaledPopoverContext(instance) {
|
|
214
|
-
const
|
|
215
|
-
const
|
|
245
|
+
const owner = findThemeOwner(instance._trigger);
|
|
246
|
+
const theme = owner?.getAttribute("data-bs-theme") || null;
|
|
247
|
+
const direction = instance._document.defaultView?.getComputedStyle(
|
|
248
|
+
instance._trigger
|
|
249
|
+
).direction;
|
|
216
250
|
if (theme) {
|
|
217
251
|
instance._popover.setAttribute("data-bs-theme", theme);
|
|
252
|
+
} else {
|
|
253
|
+
instance._popover.removeAttribute("data-bs-theme");
|
|
218
254
|
}
|
|
219
|
-
if (direction === "rtl") {
|
|
220
|
-
instance._popover.setAttribute("dir",
|
|
255
|
+
if (direction === "ltr" || direction === "rtl") {
|
|
256
|
+
instance._popover.setAttribute("dir", direction);
|
|
257
|
+
} else {
|
|
258
|
+
instance._popover.removeAttribute("dir");
|
|
221
259
|
}
|
|
222
260
|
}
|
|
223
261
|
function portalDatepickerPopover(instance) {
|
|
224
262
|
const popover = instance._popover;
|
|
225
|
-
|
|
263
|
+
const owner = findThemeOwner(instance._trigger);
|
|
264
|
+
const portalRoot = ownerPortalRoot(owner) || instance._document.body || instance._document.documentElement;
|
|
265
|
+
if (!portalRoot) {
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
if (instance._popoverPortal?.portal === portalRoot && popover.parentElement === portalRoot) {
|
|
226
269
|
syncPortaledPopoverContext(instance);
|
|
227
270
|
return;
|
|
228
271
|
}
|
|
229
|
-
|
|
230
|
-
host.className = "moo-ui";
|
|
231
|
-
host.dataset.datepickerPortalHost = "";
|
|
272
|
+
restoreDatepickerPopover(instance);
|
|
232
273
|
instance._popoverPortal = {
|
|
233
274
|
parent: popover.parentNode,
|
|
234
275
|
nextSibling: popover.nextSibling,
|
|
235
|
-
|
|
276
|
+
owner,
|
|
277
|
+
portal: portalRoot,
|
|
236
278
|
hadTheme: popover.hasAttribute("data-bs-theme"),
|
|
237
279
|
theme: popover.getAttribute("data-bs-theme"),
|
|
238
280
|
hadDirection: popover.hasAttribute("dir"),
|
|
239
281
|
direction: popover.getAttribute("dir")
|
|
240
282
|
};
|
|
241
|
-
|
|
242
|
-
instance._document.body.appendChild(host);
|
|
283
|
+
portalRoot.appendChild(popover);
|
|
243
284
|
syncPortaledPopoverContext(instance);
|
|
244
285
|
}
|
|
245
286
|
function restoreDatepickerPopover(instance) {
|
|
246
287
|
const portal = instance._popoverPortal;
|
|
247
288
|
if (!portal) return;
|
|
248
289
|
const popover = instance._popover;
|
|
249
|
-
if (portal.
|
|
290
|
+
if (portal.owner?.isConnected === false) {
|
|
291
|
+
popover.remove();
|
|
292
|
+
} else if (portal.parent?.isConnected) {
|
|
250
293
|
if (portal.nextSibling?.parentNode === portal.parent) {
|
|
251
294
|
portal.parent.insertBefore(popover, portal.nextSibling);
|
|
252
295
|
} else {
|
|
@@ -255,7 +298,6 @@ function restoreDatepickerPopover(instance) {
|
|
|
255
298
|
} else {
|
|
256
299
|
popover.remove();
|
|
257
300
|
}
|
|
258
|
-
portal.host?.remove();
|
|
259
301
|
if (portal.hadTheme) {
|
|
260
302
|
popover.setAttribute("data-bs-theme", portal.theme);
|
|
261
303
|
} else {
|
|
@@ -357,8 +399,8 @@ function yearOptions(minDate, maxDate, viewDate) {
|
|
|
357
399
|
}
|
|
358
400
|
return years;
|
|
359
401
|
}
|
|
360
|
-
function createIcon(
|
|
361
|
-
const span =
|
|
402
|
+
function createIcon(document2, glyph, className = "") {
|
|
403
|
+
const span = document2.createElement("span");
|
|
362
404
|
span.className = className;
|
|
363
405
|
span.setAttribute("aria-hidden", "true");
|
|
364
406
|
span.textContent = glyph;
|
|
@@ -655,44 +697,44 @@ var MooCalendar = class _MooCalendar {
|
|
|
655
697
|
return this._element.querySelector(`[data-calendar-day="${toIso(date)}"]`);
|
|
656
698
|
}
|
|
657
699
|
_render() {
|
|
658
|
-
const
|
|
659
|
-
const fragment =
|
|
660
|
-
const header =
|
|
700
|
+
const document2 = this._document;
|
|
701
|
+
const fragment = document2.createDocumentFragment();
|
|
702
|
+
const header = document2.createElement("div");
|
|
661
703
|
header.className = "moo-calendar__header";
|
|
662
|
-
const prev =
|
|
704
|
+
const prev = document2.createElement("button");
|
|
663
705
|
prev.className = "btn btn-ghost btn-icon-sm moo-calendar__nav";
|
|
664
706
|
prev.type = "button";
|
|
665
707
|
prev.dataset.calendarPrev = "true";
|
|
666
708
|
prev.setAttribute("aria-label", "Previous month");
|
|
667
|
-
prev.appendChild(createIcon(
|
|
668
|
-
const next =
|
|
709
|
+
prev.appendChild(createIcon(document2, "\u2039", "moo-calendar__nav-icon"));
|
|
710
|
+
const next = document2.createElement("button");
|
|
669
711
|
next.className = "btn btn-ghost btn-icon-sm moo-calendar__nav";
|
|
670
712
|
next.type = "button";
|
|
671
713
|
next.dataset.calendarNext = "true";
|
|
672
714
|
next.setAttribute("aria-label", "Next month");
|
|
673
|
-
next.appendChild(createIcon(
|
|
674
|
-
const caption =
|
|
715
|
+
next.appendChild(createIcon(document2, "\u203A", "moo-calendar__nav-icon"));
|
|
716
|
+
const caption = document2.createElement("div");
|
|
675
717
|
caption.className = "moo-calendar__caption";
|
|
676
718
|
caption.id = this._captionId;
|
|
677
719
|
caption.setAttribute("aria-live", "polite");
|
|
678
720
|
if (this._config.captionLayout === "dropdown") {
|
|
679
|
-
const month =
|
|
721
|
+
const month = document2.createElement("select");
|
|
680
722
|
month.className = "moo-calendar__select";
|
|
681
723
|
month.dataset.calendarMonth = "true";
|
|
682
724
|
month.setAttribute("aria-label", "Month");
|
|
683
725
|
for (let index = 0; index < 12; index += 1) {
|
|
684
|
-
const option =
|
|
726
|
+
const option = document2.createElement("option");
|
|
685
727
|
option.value = String(index);
|
|
686
728
|
option.textContent = monthName(index, this._config.locale);
|
|
687
729
|
option.selected = index === this._viewDate.getMonth();
|
|
688
730
|
month.appendChild(option);
|
|
689
731
|
}
|
|
690
|
-
const year =
|
|
732
|
+
const year = document2.createElement("select");
|
|
691
733
|
year.className = "moo-calendar__select";
|
|
692
734
|
year.dataset.calendarYear = "true";
|
|
693
735
|
year.setAttribute("aria-label", "Year");
|
|
694
736
|
yearOptions(this._config.minDate, this._config.maxDate, this._viewDate).forEach((value) => {
|
|
695
|
-
const option =
|
|
737
|
+
const option = document2.createElement("option");
|
|
696
738
|
option.value = String(value);
|
|
697
739
|
option.textContent = String(value);
|
|
698
740
|
option.selected = value === this._viewDate.getFullYear();
|
|
@@ -704,22 +746,22 @@ var MooCalendar = class _MooCalendar {
|
|
|
704
746
|
}
|
|
705
747
|
header.append(prev, caption, next);
|
|
706
748
|
fragment.appendChild(header);
|
|
707
|
-
const gridLabel =
|
|
749
|
+
const gridLabel = document2.createElement("div");
|
|
708
750
|
gridLabel.id = this._labelId;
|
|
709
751
|
gridLabel.className = "visually-hidden";
|
|
710
752
|
gridLabel.textContent = this._element.getAttribute("aria-label") || formatMonthYear(this._viewDate, this._config.locale);
|
|
711
753
|
fragment.appendChild(gridLabel);
|
|
712
|
-
const weekdays =
|
|
754
|
+
const weekdays = document2.createElement("div");
|
|
713
755
|
weekdays.className = "moo-calendar__weekdays";
|
|
714
756
|
weekdays.setAttribute("role", "row");
|
|
715
757
|
weekdayDates(this._config.locale).forEach((date) => {
|
|
716
|
-
const label =
|
|
758
|
+
const label = document2.createElement("span");
|
|
717
759
|
label.className = "moo-calendar__weekday";
|
|
718
760
|
label.setAttribute("role", "columnheader");
|
|
719
761
|
label.textContent = new Intl.DateTimeFormat(this._config.locale, { weekday: "narrow" }).format(date);
|
|
720
762
|
weekdays.appendChild(label);
|
|
721
763
|
});
|
|
722
|
-
const grid =
|
|
764
|
+
const grid = document2.createElement("div");
|
|
723
765
|
grid.className = "moo-calendar__grid";
|
|
724
766
|
grid.setAttribute("role", "grid");
|
|
725
767
|
grid.setAttribute("aria-labelledby", this._labelId);
|
|
@@ -728,16 +770,16 @@ var MooCalendar = class _MooCalendar {
|
|
|
728
770
|
const weekStart = firstDayOfWeek(this._config.locale);
|
|
729
771
|
const start = addDays(first, -((first.getDay() - weekStart + 7) % 7));
|
|
730
772
|
for (let week = 0; week < 6; week += 1) {
|
|
731
|
-
const row =
|
|
773
|
+
const row = document2.createElement("div");
|
|
732
774
|
row.className = "moo-calendar__week";
|
|
733
775
|
row.setAttribute("role", "row");
|
|
734
776
|
for (let day = 0; day < 7; day += 1) {
|
|
735
777
|
const date = addDays(start, week * 7 + day);
|
|
736
778
|
const iso = toIso(date);
|
|
737
|
-
const cell =
|
|
779
|
+
const cell = document2.createElement("div");
|
|
738
780
|
cell.className = "moo-calendar__cell";
|
|
739
781
|
cell.setAttribute("role", "gridcell");
|
|
740
|
-
const button =
|
|
782
|
+
const button = document2.createElement("button");
|
|
741
783
|
button.className = "moo-calendar__day";
|
|
742
784
|
button.type = "button";
|
|
743
785
|
button.dataset.calendarDay = iso;
|
|
@@ -769,7 +811,7 @@ var MooCalendar = class _MooCalendar {
|
|
|
769
811
|
}
|
|
770
812
|
fragment.appendChild(grid);
|
|
771
813
|
if (this._config.showPresets) {
|
|
772
|
-
const presets =
|
|
814
|
+
const presets = document2.createElement("div");
|
|
773
815
|
presets.className = "moo-calendar__presets";
|
|
774
816
|
[
|
|
775
817
|
["today", "Today"],
|
|
@@ -778,7 +820,7 @@ var MooCalendar = class _MooCalendar {
|
|
|
778
820
|
["in-a-week", "In a week"],
|
|
779
821
|
["in-2-weeks", "In 2 weeks"]
|
|
780
822
|
].forEach(([value, label]) => {
|
|
781
|
-
const button =
|
|
823
|
+
const button = document2.createElement("button");
|
|
782
824
|
button.className = "btn btn-outline-secondary btn-sm moo-calendar__preset";
|
|
783
825
|
button.type = "button";
|
|
784
826
|
button.dataset.calendarPreset = value;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* Moo UI datepicker.min.js v1.0.0-rc.
|
|
2
|
+
* Moo UI datepicker.min.js v1.0.0-rc.7 (https://ui.wpmoo.org/)
|
|
3
3
|
* Copyright 2026 WPMoo (https://wpmoo.org)
|
|
4
4
|
* Licensed under MIT (https://github.com/wpmoo-org/ui/blob/main/LICENSE)
|
|
5
5
|
*/
|
|
6
|
-
var x=new WeakMap,V=new WeakMap,M=new WeakMap,w="en",pt=1440*60*1e3,nt=new Date(2026,7,16),C=8;function H(i,t){return i?.nodeType===1&&!!i.matches?.(t)}function h(i,t,e,a,s){t&&(t.addEventListener(e,a,s),i.push({target:t,type:e,handler:a,options:s}))}function S(i){i.forEach(({target:t,type:e,handler:a,options:s})=>{t.removeEventListener(e,a,s)}),i.length=0}function d(i){if(!i)return null;if(i instanceof Date)return Number.isNaN(i.getTime())?null:new Date(i.getFullYear(),i.getMonth(),i.getDate());if(typeof i=="number")return d(new Date(i));let t=String(i).trim(),e=/^(\d{4})-(\d{2})-(\d{2})$/.exec(t);if(e){let a=new Date(Number(e[1]),Number(e[2])-1,Number(e[3]));return a.getFullYear()===Number(e[1])&&a.getMonth()===Number(e[2])-1&&a.getDate()===Number(e[3])?a:null}return null}function j(i){return String(i).padStart(2,"0")}function f(i){return`${i.getFullYear()}-${j(i.getMonth()+1)}-${j(i.getDate())}`}function g(i,t){return!i||!t?0:i.getTime()-t.getTime()}function k(i,t){return!!(i&&t&&f(i)===f(t))}function b(i,t){return new Date(i.getFullYear(),i.getMonth(),i.getDate()+t)}function q(i,t){let e=new Date(i.getFullYear(),i.getMonth()+t,1),a=Math.min(i.getDate(),$(e.getFullYear(),e.getMonth()));return new Date(e.getFullYear(),e.getMonth(),a)}function L(i=w){try{if(typeof Intl<"u"&&typeof Intl.Locale=="function"){let t=new Intl.Locale(i||w),e=t.weekInfo||t.getWeekInfo?.();if(Number.isInteger(e?.firstDay))return e.firstDay%7}}catch{}return 0}function rt(i=w){let t=L(i);return Array.from({length:7},(e,a)=>b(nt,(t+a)%7))}function y(i){return new Date(i.getFullYear(),i.getMonth(),1)}function $(i,t){return new Date(i,t+1,0).getDate()}function ot(i,t,e){return t&&g(i,t)<0?new Date(t):e&&g(i,e)>0?new Date(e):i}function lt(i){if(Array.isArray(i))return i.map(d).filter(Boolean).map(f);if(!i)return[];let t=String(i).trim();if(!t)return[];try{let e=JSON.parse(t);if(Array.isArray(e))return e.map(d).filter(Boolean).map(f)}catch{}return t.split(",").map(d).filter(Boolean).map(f)}function A(i,t=w){return i?new Intl.DateTimeFormat(t||w,{month:"short",day:"numeric",year:"numeric"}).format(i):""}function Q(i,t=w){return new Intl.DateTimeFormat(t||w,{month:"long",year:"numeric"}).format(i)}function R(i,t,e=w){if(i)return t==="yyyy-mm-dd"?f(i):t?A(i,e):new Date(i)}function z(i,t={}){let e=i.dataset||{},a=t.locale||e.datepickerLocale||e.calendarLocale||w,s=d(t.minDate||e.calendarMinDate||e.datepickerMinDate),n=d(t.maxDate||e.calendarMaxDate||e.datepickerMaxDate);return{locale:a,mode:t.mode||e.calendarMode||e.datepickerMode||"single",placeholder:t.placeholder||e.datepickerPlaceholder||"Pick a date",value:t.value||e.calendarValue||e.datepickerValue||"",startValue:t.startValue||e.calendarStartValue||e.datepickerStartValue||"",endValue:t.endValue||e.calendarEndValue||e.datepickerEndValue||"",minDate:s,maxDate:n,disabledDates:lt(t.disabledDates||e.calendarDisabledDates||e.datepickerDisabledDates),captionLayout:t.captionLayout||e.calendarCaptionLayout||"",showPresets:t.showPresets??(e.calendarShowPresets==="true"||e.datepickerShowPresets==="true")}}function m(i,t,e,a={},s=!1){return i.dispatchEvent(new t.CustomEvent(e,{bubbles:!0,cancelable:s,detail:a}))}function B(i,t){i&&(i.value=t||"")}function it(i,t){i&&(i.value=t||"")}function U(i,t,e){if(e){i.dataset.invalid="true",t.classList.add("is-invalid"),t.setAttribute("aria-invalid","true");return}delete i.dataset.invalid,t.classList.remove("is-invalid"),t.removeAttribute("aria-invalid")}function at(i,t,e){e?.required&&e.checkValidity()&&U(i,t,!1)}function X(i,t,e){return e<t?t:Math.min(Math.max(i,t),e)}function dt(i,t,e){let a=i?.ownerDocument?.defaultView||window,s=i?a.getComputedStyle(i).getPropertyValue(t).trim():"",n=Number.parseFloat(s);if(!Number.isFinite(n))return e;if(s.endsWith("rem")){let r=i.ownerDocument.documentElement,_=Number.parseFloat(a.getComputedStyle(r).fontSize);return Number.isFinite(_)?n*_:e}if(s.endsWith("em")){let r=Number.parseFloat(a.getComputedStyle(i).fontSize);return Number.isFinite(r)?n*r:e}return Number.isFinite(n)?n:e}function P(i,t){return!!(t&&(i._element.contains(t)||i._popover.contains(t)))}function Z(i){let t=i._element.closest("[data-bs-theme]")?.getAttribute("data-bs-theme")||i._document.documentElement.getAttribute("data-bs-theme"),e=getComputedStyle(i._trigger).direction;t&&i._popover.setAttribute("data-bs-theme",t),e==="rtl"&&i._popover.setAttribute("dir","rtl")}function ht(i){let t=i._popover;if(i._popoverPortal?.host?.parentElement===i._document.body){Z(i);return}let e=i._document.createElement("div");e.className="moo-ui",e.dataset.datepickerPortalHost="",i._popoverPortal={parent:t.parentNode,nextSibling:t.nextSibling,host:e,hadTheme:t.hasAttribute("data-bs-theme"),theme:t.getAttribute("data-bs-theme"),hadDirection:t.hasAttribute("dir"),direction:t.getAttribute("dir")},e.appendChild(t),i._document.body.appendChild(e),Z(i)}function K(i){let t=i._popoverPortal;if(!t)return;let e=i._popover;t.parent?.isConnected?t.nextSibling?.parentNode===t.parent?t.parent.insertBefore(e,t.nextSibling):t.parent.appendChild(e):e.remove(),t.host?.remove(),t.hadTheme?e.setAttribute("data-bs-theme",t.theme):e.removeAttribute("data-bs-theme"),t.hadDirection?e.setAttribute("dir",t.direction):e.removeAttribute("dir"),i._popoverPortal=null}function ct(i,t,e,a){let s=dt(e,"--moo-datepicker-popover-offset",6),n=getComputedStyle(i).direction;t.style.position="fixed",t.style.inset="auto",t.style.right="auto",t.style.bottom="auto",t.style.maxHeight="",t.style.overflowY="";let r=i.getBoundingClientRect(),_=t.getBoundingClientRect(),E=a.innerWidth,D=a.innerHeight,N=n==="rtl"?r.right-_.width:r.left,Y=X(N,C,E-_.width-C),I=r.bottom+s<=D?D-r.bottom-s-C:0,c=r.top-s-C,l=_.height>I&&c>I,u=l?"top":"bottom",o=Math.max(0,l?c:I),F=Math.min(_.height,o),v=l?r.top-s-F:r.bottom+s;t.style.left=`${Math.round(Y)}px`,t.style.top=`${Math.round(X(v,C,D-F-C))}px`,o>0&&(t.style.maxHeight=`${Math.floor(o)}px`,t.style.overflowY="auto"),t.dataset.datepickerPlacement=u}function ut(i){i.style.position="",i.style.inset="",i.style.right="",i.style.bottom="",i.style.left="",i.style.top="",i.style.maxHeight="",i.style.overflowY="",delete i.dataset.datepickerPlacement}function st(i){S(i._floatingListeners),ht(i);let t=()=>{i.isOpen()&&ct(i._trigger,i._popover,i._element,i._window)};i._positionPopover=t,t(),h(i._floatingListeners,i._window,"resize",t),h(i._floatingListeners,i._window,"scroll",t,!0),h(i._floatingListeners,i._document,"scroll",t,!0)}function O(i){S(i._floatingListeners),i._positionPopover=null,ut(i._popover),K(i)}function _t(i,t){return new Intl.DateTimeFormat(t||w,{month:"short"}).format(new Date(2026,i,1))}function ft(i,t,e){let a=i?i.getFullYear():e.getFullYear()-100,s=t?t.getFullYear():e.getFullYear()+20,n=[];for(let r=a;r<=s;r+=1)n.push(r);return n}function tt(i,t,e=""){let a=i.createElement("span");return a.className=e,a.setAttribute("aria-hidden","true"),a.textContent=t,a}var T=class i{static getInstance(t){return t?.nodeType===1&&V.get(t)||null}static getOrCreateInstance(t,e={}){return i.getInstance(t)||new i(t,e)}constructor(t,e={}){if(!H(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=z(t,e),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=y(this._activeDate),this._captionId=this._element.id?`${this._element.id}-caption`:`moo-calendar-caption-${Math.random().toString(36).slice(2)}`,this._labelId=this._element.id?`${this._element.id}-label`:`moo-calendar-label-${Math.random().toString(36).slice(2)}`,V.set(t,this),this._bindEvents(),this._render()}dispose(){this._disposed||(this._disposed=!0,S(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):R(this._selectedDate,t,this._config.locale)}getDates(t=void 0){return[R(this._rangeStart,t,this._config.locale),R(this._rangeEnd,t,this._config.locale)]}setDate(t,e={}){if(this._mode!=="single")return!1;let a=d(t);return!a||this._isDisabled(a)?!1:(this._selectedDate=a,this._activeDate=a,this._viewDate=y(a),this._render(),e.emit!==!1&&this._emitChange(!0),!0)}setDates(t,e,a={}){if(this._mode!=="range")return!1;let s=d(t),n=d(e);return s&&this._isDisabled(s)||n&&this._isDisabled(n)?!1:(this._rangeStart=s,this._rangeEnd=n,this._rangeStart&&this._rangeEnd&&g(this._rangeStart,this._rangeEnd)>0&&([this._rangeStart,this._rangeEnd]=[this._rangeEnd,this._rangeStart]),this._activeDate=this._rangeEnd||this._rangeStart||this._activeDate,this._viewDate=y(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(){h(this._listeners,this._element,"click",t=>{let e=t.target,a=e.closest?.("[data-calendar-day]"),s=e.closest?.("[data-calendar-prev]"),n=e.closest?.("[data-calendar-next]"),r=e.closest?.("[data-calendar-preset]");s?this._changeMonth(-1,!0):n?this._changeMonth(1,!0):r?this._selectPreset(r.dataset.calendarPreset):a&&this._selectDate(d(a.dataset.calendarDay),!0)}),h(this._listeners,this._element,"keydown",t=>{t.target.closest?.("[data-calendar-day]")&&this._handleDayKeydown(t)}),h(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){m(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,e){let a=y(q(this._viewDate,t));this._setActiveMonth(a.getFullYear(),a.getMonth(),e)}_setActiveMonth(t,e,a=!1){let s=Math.min(this._activeDate.getDate(),$(t,e));this._activeDate=this._nearestEnabledDate(new Date(t,e,s)),this._viewDate=y(this._activeDate),this._render(),a&&this.focusActiveDay()}_selectPreset(t){if(!t)return;let e=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(e,a[t]),!0)}_handleDayKeydown(t){let e=t.target.closest?.("[data-calendar-day]"),a=d(e?.dataset?.calendarDay);a&&g(a,this._activeDate)!==0&&(this._activeDate=a);let s={ArrowRight:1,ArrowLeft:-1,ArrowDown:7,ArrowUp:-7},n=null;if(t.key in s)n=b(this._activeDate,s[t.key]);else if(t.key==="Home"){let r=L(this._config.locale),_=(this._activeDate.getDay()-r+7)%7;n=b(this._activeDate,-_)}else if(t.key==="End"){let r=L(this._config.locale),_=(this._activeDate.getDay()-r+7)%7;n=b(this._activeDate,6-_)}else if(t.key==="PageUp")n=q(this._activeDate,-1);else if(t.key==="PageDown")n=q(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(n,!0,g(n,this._activeDate)<0?-1:1)}_setActiveDate(t,e=!1,a=0){let s=a===0?this._nearestEnabledDate(t):this._nextEnabledDate(t,a);this._activeDate=s,this._viewDate=y(s),this._render(),e&&this.focusActiveDay()}_nextEnabledDate(t,e){let a=d(t);if(!a)return this._activeDate;let s=e<0?-1:1;for(let n=0;n<366&&!(this._config.minDate&&g(a,this._config.minDate)<0||this._config.maxDate&&g(a,this._config.maxDate)>0);n+=1){if(!this._isDisabled(a))return a;a=b(a,s)}return this._activeDate}_nearestEnabledDate(t){let e=ot(d(t)||new Date,this._config.minDate,this._config.maxDate);if(!this._isDisabled(e))return e;let a=y(e),s=$(a.getFullYear(),a.getMonth());for(let n=1;n<=s;n+=1){let r=new Date(a.getFullYear(),a.getMonth(),n);if(!this._isDisabled(r))return r}return e}_selectDate(t,e){if(!(!t||this._isDisabled(t))){if(this._activeDate=t,this._viewDate=y(t),this._mode==="range"){!this._rangeStart||this._rangeEnd||g(t,this._rangeStart)<0?(this._rangeStart=t,this._rangeEnd=null):this._rangeEnd=t,this._render(),e&&this._emitChange(!!(this._rangeStart&&this._rangeEnd));return}this._selectedDate=t,this._render(),e&&this._emitChange(!0)}}_isDisabled(t){return!t||this._config.minDate&&g(t,this._config.minDate)<0||this._config.maxDate&&g(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&&g(t,this._rangeStart)>0&&g(t,this._rangeEnd)<0?"middle":""}_dayButton(t){return this._element.querySelector(`[data-calendar-day="${f(t)}"]`)}_render(){let t=this._document,e=t.createDocumentFragment(),a=t.createElement("div");a.className="moo-calendar__header";let s=t.createElement("button");s.className="btn btn-ghost btn-icon-sm moo-calendar__nav",s.type="button",s.dataset.calendarPrev="true",s.setAttribute("aria-label","Previous month"),s.appendChild(tt(t,"\u2039","moo-calendar__nav-icon"));let n=t.createElement("button");n.className="btn btn-ghost btn-icon-sm moo-calendar__nav",n.type="button",n.dataset.calendarNext="true",n.setAttribute("aria-label","Next month"),n.appendChild(tt(t,"\u203A","moo-calendar__nav-icon"));let r=t.createElement("div");if(r.className="moo-calendar__caption",r.id=this._captionId,r.setAttribute("aria-live","polite"),this._config.captionLayout==="dropdown"){let c=t.createElement("select");c.className="moo-calendar__select",c.dataset.calendarMonth="true",c.setAttribute("aria-label","Month");for(let u=0;u<12;u+=1){let o=t.createElement("option");o.value=String(u),o.textContent=_t(u,this._config.locale),o.selected=u===this._viewDate.getMonth(),c.appendChild(o)}let l=t.createElement("select");l.className="moo-calendar__select",l.dataset.calendarYear="true",l.setAttribute("aria-label","Year"),ft(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)}),r.append(c,l)}else r.textContent=Q(this._viewDate,this._config.locale);a.append(s,r,n),e.appendChild(a);let _=t.createElement("div");_.id=this._labelId,_.className="visually-hidden",_.textContent=this._element.getAttribute("aria-label")||Q(this._viewDate,this._config.locale),e.appendChild(_);let E=t.createElement("div");E.className="moo-calendar__weekdays",E.setAttribute("role","row"),rt(this._config.locale).forEach(c=>{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(c),E.appendChild(l)});let D=t.createElement("div");D.className="moo-calendar__grid",D.setAttribute("role","grid"),D.setAttribute("aria-labelledby",this._labelId),D.appendChild(E);let N=y(this._viewDate),Y=L(this._config.locale),I=b(N,-((N.getDay()-Y+7)%7));for(let c=0;c<6;c+=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(I,c*7+u),F=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=F,p.textContent=String(o.getDate()),p.tabIndex=k(o,this._activeDate)?0:-1,p.setAttribute("aria-label",A(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(e.appendChild(D),this._config.showPresets){let c=t.createElement("div");c.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,c.appendChild(o)}),e.appendChild(c)}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(e)}},W=class i{static getInstance(t){return t?.nodeType===1&&x.get(t)||null}static getOrCreateInstance(t,e={}){return i.getInstance(t)||new i(t,e)}constructor(t,e={}){if(!H(t,"[data-datepicker]"))throw new TypeError("MooDatepicker requires a [data-datepicker] root element.");let a=x.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=z(t,{...e,value:e.value||this._input.value||t.dataset.datepickerValue}),this._placeholder=this._config.placeholder,this._defaultValue=this._input.defaultValue||this._input.getAttribute("value")||"",this.calendar=T.getOrCreateInstance(this._calendarRoot,{...this._config,mode:"single",value:this._input.value||this._config.value}),x.set(t,this),this._syncFromCalendar(),this._bindEvents()}dispose(){this._disposed||(this._disposed=!0,S(this._listeners),this.hide(!1),O(this),K(this),S(this._floatingListeners),this.calendar?.dispose(),x.get(this._element)===this&&x.delete(this._element))}show(){this._trigger.disabled||this._element.dataset.datepickerDisabled==="true"||this.isOpen()||m(this._element,this._window,"show.moo.datepicker",{},!0)&&(this._popover.hidden=!1,this._popover.classList.add("show"),st(this),this._trigger.setAttribute("aria-expanded","true"),this.calendar.focusActiveDay(),m(this._element,this._window,"shown.moo.datepicker"))}hide(t=!0){this.isOpen()&&m(this._element,this._window,"hide.moo.datepicker",{},!0)&&(this._popover.hidden=!0,this._popover.classList.remove("show"),O(this),this._trigger.setAttribute("aria-expanded","false"),t&&this._trigger.focus(),m(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,e={}){let a=this.calendar.setDate(t,{emit:!1});return a&&(this._syncFromCalendar(),e.emit!==!1&&this._emitChange()),a}clear(t={}){this.calendar.clear({emit:!1}),this._syncFromCalendar(),t.emit!==!1&&this._emitChange()}_bindEvents(){h(this._listeners,this._trigger,"click",()=>this.toggle()),h(this._listeners,this._popover,"keydown",e=>{e.key==="Escape"&&(e.preventDefault(),this.hide())}),h(this._listeners,this._document,"pointerdown",e=>{this.isOpen()&&!P(this,e.target)&&this._window.setTimeout(()=>{this.isOpen()&&!P(this,e.target)&&this.hide()},0)}),h(this._listeners,this._calendarRoot,"change.moo.calendar",e=>{this._syncFromCalendar(),this._emitChange(),e.detail.complete&&this.hide()});let t=this._input.form||this._element.closest("form");h(this._listeners,this._validationInput,"invalid",e=>{e.preventDefault(),U(this._element,this._trigger,!0),this._trigger.focus({preventScroll:!0})}),h(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")||"";B(this._input,t),it(this._validationInput,t),at(this._element,this._trigger,this._validationInput),this._element.dataset.datepickerValue=t,this._label.textContent=t?A(d(t),this._config.locale):this._placeholder}_emitChange(){m(this._element,this._window,"change.moo.datepicker",{date:this.getDate(),value:this.getDate("yyyy-mm-dd")||""})}},et=class i{static getInstance(t){return t?.nodeType===1&&M.get(t)||null}static getOrCreateInstance(t,e={}){return i.getInstance(t)||new i(t,e)}constructor(t,e={}){if(!H(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=z(t,{...e,mode:"range",startValue:e.startValue||this._startInput.value||t.dataset.datepickerStartValue,endValue:e.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=T.getOrCreateInstance(this._calendarRoot,this._config),M.set(t,this),this._syncFromCalendar(),this._bindEvents()}dispose(){this._disposed||(this._disposed=!0,S(this._listeners),this.hide(!1),O(this),K(this),S(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()||m(this._element,this._window,"show.moo.datepicker",{},!0)&&(this._popover.hidden=!1,this._popover.classList.add("show"),st(this),this._trigger.setAttribute("aria-expanded","true"),this.calendar.focusActiveDay(),m(this._element,this._window,"shown.moo.datepicker"))}hide(t=!0){this.isOpen()&&m(this._element,this._window,"hide.moo.datepicker",{},!0)&&(this._popover.hidden=!0,this._popover.classList.remove("show"),O(this),this._trigger.setAttribute("aria-expanded","false"),t&&this._trigger.focus(),m(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,e,a={}){let s=this.calendar.setDates(t,e,{emit:!1});return s&&(this._syncFromCalendar(),a.emit!==!1&&this._emitChange()),s}clear(t={}){this.calendar.clear({emit:!1}),this._syncFromCalendar(),t.emit!==!1&&this._emitChange()}_bindEvents(){h(this._listeners,this._trigger,"click",()=>this.toggle()),h(this._listeners,this._popover,"keydown",a=>{a.key==="Escape"&&(a.preventDefault(),this.hide())}),h(this._listeners,this._document,"pointerdown",a=>{this.isOpen()&&!P(this,a.target)&&this._window.setTimeout(()=>{this.isOpen()&&!P(this,a.target)&&this.hide()},0)});let t=()=>{this._window.setTimeout(()=>{this.isOpen()&&!P(this,this._document.activeElement)&&this.hide(!1)},0)};h(this._listeners,this._element,"focusout",t),h(this._listeners,this._popover,"focusout",t),h(this._listeners,this._calendarRoot,"change.moo.calendar",a=>{this._syncFromCalendar(),this._emitChange(),a.detail.complete?this.hide():this.calendar.focusActiveDay()});let e=this._startInput.form||this._element.closest("form");h(this._listeners,this._validationInput,"invalid",a=>{a.preventDefault(),U(this._element,this._trigger,!0),this._trigger.focus({preventScroll:!0})}),h(this._listeners,e,"reset",()=>{this._window.setTimeout(()=>{this.setDates(this._defaultStartValue,this._defaultEndValue,{emit:!1})},0)})}_syncFromCalendar(){let[t="",e=""]=this.calendar.getDates("yyyy-mm-dd");B(this._startInput,t||""),B(this._endInput,e||""),it(this._validationInput,t&&e?`${t} - ${e}`:""),at(this._element,this._trigger,this._validationInput),this._element.dataset.datepickerStartValue=t||"",this._element.dataset.datepickerEndValue=e||"",t&&e?this._label.textContent=`${A(d(t),this._config.locale)} - ${A(d(e),this._config.locale)}`:t?this._label.textContent=A(d(t),this._config.locale):this._label.textContent=this._placeholder}_emitChange(){let[t,e]=this.getDates(),[a="",s=""]=this.getDates("yyyy-mm-dd");m(this._element,this._window,"change.moo.datepicker",{startDate:t,endDate:e,startValue:a,endValue:s})}};export{T as MooCalendar,et as MooDateRangePicker,W as default};
|
|
6
|
+
var Q='.moo-ui[data-bs-theme="light"], .moo-ui[data-bs-theme="dark"]',le="[data-moo-overlay-portal-host]";function de(t){return t?.nodeType===9?t:t?.ownerDocument?t.ownerDocument:typeof document>"u"?null:document}function ce(t){return!!t?.matches?.(Q)}function he(t){let e=de(t);return t?.nodeType===9||t===e?.body?e?.body?.firstElementChild||null:t}function q(t=typeof document>"u"?null:document){let e=he(t);return e?ce(e)?e:e.closest?.(Q)||null:null}function X(t){return t?Array.from(t.children||[]).find(e=>e.matches?.(le))||t:null}var I=new WeakMap,V=new WeakMap,M=new WeakMap,y="en",Ee=1440*60*1e3,ue=new Date(2026,7,16),C=8;function z(t,e){return t?.nodeType===1&&!!t.matches?.(e)}function c(t,e,i,a,n){e&&(e.addEventListener(i,a,n),t.push({target:e,type:i,handler:a,options:n}))}function E(t){t.forEach(({target:e,type:i,handler:a,options:n})=>{e.removeEventListener(i,a,n)}),t.length=0}function d(t){if(!t)return null;if(t instanceof Date)return Number.isNaN(t.getTime())?null:new Date(t.getFullYear(),t.getMonth(),t.getDate());if(typeof t=="number")return d(new Date(t));let e=String(t).trim(),i=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e);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(t){return String(t).padStart(2,"0")}function f(t){return`${t.getFullYear()}-${Z(t.getMonth()+1)}-${Z(t.getDate())}`}function m(t,e){return!t||!e?0:t.getTime()-e.getTime()}function k(t,e){return!!(t&&e&&f(t)===f(e))}function b(t,e){return new Date(t.getFullYear(),t.getMonth(),t.getDate()+e)}function B(t,e){let i=new Date(t.getFullYear(),t.getMonth()+e,1),a=Math.min(t.getDate(),W(i.getFullYear(),i.getMonth()));return new Date(i.getFullYear(),i.getMonth(),a)}function T(t=y){try{if(typeof Intl<"u"&&typeof Intl.Locale=="function"){let e=new Intl.Locale(t||y),i=e.weekInfo||e.getWeekInfo?.();if(Number.isInteger(i?.firstDay))return i.firstDay%7}}catch{}return 0}function _e(t=y){let e=T(t);return Array.from({length:7},(i,a)=>b(ue,(e+a)%7))}function w(t){return new Date(t.getFullYear(),t.getMonth(),1)}function W(t,e){return new Date(t,e+1,0).getDate()}function fe(t,e,i){return e&&m(t,e)<0?new Date(e):i&&m(t,i)>0?new Date(i):t}function pe(t){if(Array.isArray(t))return t.map(d).filter(Boolean).map(f);if(!t)return[];let e=String(t).trim();if(!e)return[];try{let i=JSON.parse(e);if(Array.isArray(i))return i.map(d).filter(Boolean).map(f)}catch{}return e.split(",").map(d).filter(Boolean).map(f)}function A(t,e=y){return t?new Intl.DateTimeFormat(e||y,{month:"short",day:"numeric",year:"numeric"}).format(t):""}function ee(t,e=y){return new Intl.DateTimeFormat(e||y,{month:"long",year:"numeric"}).format(t)}function $(t,e,i=y){if(t)return e==="yyyy-mm-dd"?f(t):e?A(t,i):new Date(t)}function U(t,e={}){let i=t.dataset||{},a=e.locale||i.datepickerLocale||i.calendarLocale||y,n=d(e.minDate||i.calendarMinDate||i.datepickerMinDate),r=d(e.maxDate||i.calendarMaxDate||i.datepickerMaxDate);return{locale:a,mode:e.mode||i.calendarMode||i.datepickerMode||"single",placeholder:e.placeholder||i.datepickerPlaceholder||"Pick a date",value:e.value||i.calendarValue||i.datepickerValue||"",startValue:e.startValue||i.calendarStartValue||i.datepickerStartValue||"",endValue:e.endValue||i.calendarEndValue||i.datepickerEndValue||"",minDate:n,maxDate:r,disabledDates:pe(e.disabledDates||i.calendarDisabledDates||i.datepickerDisabledDates),captionLayout:e.captionLayout||i.calendarCaptionLayout||"",showPresets:e.showPresets??(i.calendarShowPresets==="true"||i.datepickerShowPresets==="true")}}function g(t,e,i,a={},n=!1){return t.dispatchEvent(new e.CustomEvent(i,{bubbles:!0,cancelable:n,detail:a}))}function K(t,e){t&&(t.value=e||"")}function re(t,e){t&&(t.value=e||"")}function j(t,e,i){if(i){t.dataset.invalid="true",e.classList.add("is-invalid"),e.setAttribute("aria-invalid","true");return}delete t.dataset.invalid,e.classList.remove("is-invalid"),e.removeAttribute("aria-invalid")}function se(t,e,i){i?.required&&i.checkValidity()&&j(t,e,!1)}function te(t,e,i){return i<e?e:Math.min(Math.max(t,e),i)}function me(t,e,i){let a=t?.ownerDocument?.defaultView||window,n=t?a.getComputedStyle(t).getPropertyValue(e).trim():"",r=Number.parseFloat(n);if(!Number.isFinite(r))return i;if(n.endsWith("rem")){let s=t.ownerDocument.documentElement,_=Number.parseFloat(a.getComputedStyle(s).fontSize);return Number.isFinite(_)?r*_:i}if(n.endsWith("em")){let s=Number.parseFloat(a.getComputedStyle(t).fontSize);return Number.isFinite(s)?r*s:i}return Number.isFinite(r)?r:i}function O(t,e){return!!(e&&(t._element.contains(e)||t._popover.contains(e)))}function ie(t){let i=q(t._trigger)?.getAttribute("data-bs-theme")||null,a=t._document.defaultView?.getComputedStyle(t._trigger).direction;i?t._popover.setAttribute("data-bs-theme",i):t._popover.removeAttribute("data-bs-theme"),a==="ltr"||a==="rtl"?t._popover.setAttribute("dir",a):t._popover.removeAttribute("dir")}function ge(t){let e=t._popover,i=q(t._trigger),a=X(i)||t._document.body||t._document.documentElement;if(a){if(t._popoverPortal?.portal===a&&e.parentElement===a){ie(t);return}R(t),t._popoverPortal={parent:e.parentNode,nextSibling:e.nextSibling,owner:i,portal:a,hadTheme:e.hasAttribute("data-bs-theme"),theme:e.getAttribute("data-bs-theme"),hadDirection:e.hasAttribute("dir"),direction:e.getAttribute("dir")},a.appendChild(e),ie(t)}}function R(t){let e=t._popoverPortal;if(!e)return;let i=t._popover;e.owner?.isConnected===!1?i.remove():e.parent?.isConnected?e.nextSibling?.parentNode===e.parent?e.parent.insertBefore(i,e.nextSibling):e.parent.appendChild(i):i.remove(),e.hadTheme?i.setAttribute("data-bs-theme",e.theme):i.removeAttribute("data-bs-theme"),e.hadDirection?i.setAttribute("dir",e.direction):i.removeAttribute("dir"),t._popoverPortal=null}function De(t,e,i,a){let n=me(i,"--moo-datepicker-popover-offset",6),r=getComputedStyle(t).direction;e.style.position="fixed",e.style.inset="auto",e.style.right="auto",e.style.bottom="auto",e.style.maxHeight="",e.style.overflowY="";let s=t.getBoundingClientRect(),_=e.getBoundingClientRect(),S=a.innerWidth,D=a.innerHeight,P=r==="rtl"?s.right-_.width:s.left,Y=te(P,C,S-_.width-C),x=s.bottom+n<=D?D-s.bottom-n-C:0,h=s.top-n-C,l=_.height>x&&h>x,u=l?"top":"bottom",o=Math.max(0,l?h:x),N=Math.min(_.height,o),v=l?s.top-n-N:s.bottom+n;e.style.left=`${Math.round(Y)}px`,e.style.top=`${Math.round(te(v,C,D-N-C))}px`,o>0&&(e.style.maxHeight=`${Math.floor(o)}px`,e.style.overflowY="auto"),e.dataset.datepickerPlacement=u}function ye(t){t.style.position="",t.style.inset="",t.style.right="",t.style.bottom="",t.style.left="",t.style.top="",t.style.maxHeight="",t.style.overflowY="",delete t.dataset.datepickerPlacement}function oe(t){E(t._floatingListeners),ge(t);let e=()=>{t.isOpen()&&De(t._trigger,t._popover,t._element,t._window)};t._positionPopover=e,e(),c(t._floatingListeners,t._window,"resize",e),c(t._floatingListeners,t._window,"scroll",e,!0),c(t._floatingListeners,t._document,"scroll",e,!0)}function F(t){E(t._floatingListeners),t._positionPopover=null,ye(t._popover),R(t)}function we(t,e){return new Intl.DateTimeFormat(e||y,{month:"short"}).format(new Date(2026,t,1))}function be(t,e,i){let a=t?t.getFullYear():i.getFullYear()-100,n=e?e.getFullYear():i.getFullYear()+20,r=[];for(let s=a;s<=n;s+=1)r.push(s);return r}function ae(t,e,i=""){let a=t.createElement("span");return a.className=i,a.setAttribute("aria-hidden","true"),a.textContent=e,a}var L=class t{static getInstance(e){return e?.nodeType===1&&V.get(e)||null}static getOrCreateInstance(e,i={}){return t.getInstance(e)||new t(e,i)}constructor(e,i={}){if(!z(e,"[data-calendar]"))throw new TypeError("MooCalendar requires a [data-calendar] root element.");let a=V.get(e);if(a)return a;this._element=e,this._document=e.ownerDocument,this._window=this._document.defaultView||window,this._listeners=[],this._disposed=!1,this._config=U(e,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?`${this._element.id}-caption`:`moo-calendar-caption-${Math.random().toString(36).slice(2)}`,this._labelId=this._element.id?`${this._element.id}-label`:`moo-calendar-label-${Math.random().toString(36).slice(2)}`,V.set(e,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(e=void 0){return this._mode==="range"?this.getDates(e):$(this._selectedDate,e,this._config.locale)}getDates(e=void 0){return[$(this._rangeStart,e,this._config.locale),$(this._rangeEnd,e,this._config.locale)]}setDate(e,i={}){if(this._mode!=="single")return!1;let a=d(e);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(e,i,a={}){if(this._mode!=="range")return!1;let n=d(e),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(e={}){this._selectedDate=null,this._rangeStart=null,this._rangeEnd=null,this._render(),e.emit!==!1&&this._emitChange(!1)}focusActiveDay(){this._dayButton(this._activeDate)?.focus()}_bindEvents(){c(this._listeners,this._element,"click",e=>{let i=e.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",e=>{e.target.closest?.("[data-calendar-day]")&&this._handleDayKeydown(e)}),c(this._listeners,this._element,"change",e=>{e.target.matches?.("[data-calendar-month]")&&this._setActiveMonth(this._viewDate.getFullYear(),Number(e.target.value),!0),e.target.matches?.("[data-calendar-year]")&&this._setActiveMonth(Number(e.target.value),this._viewDate.getMonth(),!0)})}_emitChange(e){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:e})}_changeMonth(e,i){let a=w(B(this._viewDate,e));this._setActiveMonth(a.getFullYear(),a.getMonth(),i)}_setActiveMonth(e,i,a=!1){let n=Math.min(this._activeDate.getDate(),W(e,i));this._activeDate=this._nearestEnabledDate(new Date(e,i,n)),this._viewDate=w(this._activeDate),this._render(),a&&this.focusActiveDay()}_selectPreset(e){if(!e)return;let i=new Date,a={today:0,tomorrow:1,"in-3-days":3,"in-a-week":7,"in-2-weeks":14};e in a&&this._selectDate(b(i,a[e]),!0)}_handleDayKeydown(e){let i=e.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(e.key in n)r=b(this._activeDate,n[e.key]);else if(e.key==="Home"){let s=T(this._config.locale),_=(this._activeDate.getDay()-s+7)%7;r=b(this._activeDate,-_)}else if(e.key==="End"){let s=T(this._config.locale),_=(this._activeDate.getDay()-s+7)%7;r=b(this._activeDate,6-_)}else if(e.key==="PageUp")r=B(this._activeDate,-1);else if(e.key==="PageDown")r=B(this._activeDate,1);else if(e.key==="Enter"||e.key===" "||e.key==="Spacebar"){e.preventDefault(),this._selectDate(this._activeDate,!0);return}else return;e.preventDefault(),this._setActiveDate(r,!0,m(r,this._activeDate)<0?-1:1)}_setActiveDate(e,i=!1,a=0){let n=a===0?this._nearestEnabledDate(e):this._nextEnabledDate(e,a);this._activeDate=n,this._viewDate=w(n),this._render(),i&&this.focusActiveDay()}_nextEnabledDate(e,i){let a=d(e);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(e){let i=fe(d(e)||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(e,i){if(!(!e||this._isDisabled(e))){if(this._activeDate=e,this._viewDate=w(e),this._mode==="range"){!this._rangeStart||this._rangeEnd||m(e,this._rangeStart)<0?(this._rangeStart=e,this._rangeEnd=null):this._rangeEnd=e,this._render(),i&&this._emitChange(!!(this._rangeStart&&this._rangeEnd));return}this._selectedDate=e,this._render(),i&&this._emitChange(!0)}}_isDisabled(e){return!e||this._config.minDate&&m(e,this._config.minDate)<0||this._config.maxDate&&m(e,this._config.maxDate)>0?!0:this._disabledDates.has(f(e))}_isSelected(e){return this._mode==="range"?k(e,this._rangeStart)||k(e,this._rangeEnd):k(e,this._selectedDate)}_rangeState(e){return this._mode!=="range"||!this._rangeStart?"":k(e,this._rangeStart)?"start":k(e,this._rangeEnd)?"end":this._rangeStart&&this._rangeEnd&&m(e,this._rangeStart)>0&&m(e,this._rangeEnd)<0?"middle":""}_dayButton(e){return this._element.querySelector(`[data-calendar-day="${f(e)}"]`)}_render(){let e=this._document,i=e.createDocumentFragment(),a=e.createElement("div");a.className="moo-calendar__header";let n=e.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(ae(e,"\u2039","moo-calendar__nav-icon"));let r=e.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(ae(e,"\u203A","moo-calendar__nav-icon"));let s=e.createElement("div");if(s.className="moo-calendar__caption",s.id=this._captionId,s.setAttribute("aria-live","polite"),this._config.captionLayout==="dropdown"){let h=e.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=e.createElement("option");o.value=String(u),o.textContent=we(u,this._config.locale),o.selected=u===this._viewDate.getMonth(),h.appendChild(o)}let l=e.createElement("select");l.className="moo-calendar__select",l.dataset.calendarYear="true",l.setAttribute("aria-label","Year"),be(this._config.minDate,this._config.maxDate,this._viewDate).forEach(u=>{let o=e.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=ee(this._viewDate,this._config.locale);a.append(n,s,r),i.appendChild(a);let _=e.createElement("div");_.id=this._labelId,_.className="visually-hidden",_.textContent=this._element.getAttribute("aria-label")||ee(this._viewDate,this._config.locale),i.appendChild(_);let S=e.createElement("div");S.className="moo-calendar__weekdays",S.setAttribute("role","row"),_e(this._config.locale).forEach(h=>{let l=e.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=e.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),x=b(P,-((P.getDay()-Y+7)%7));for(let h=0;h<6;h+=1){let l=e.createElement("div");l.className="moo-calendar__week",l.setAttribute("role","row");for(let u=0;u<7;u+=1){let o=b(x,h*7+u),N=f(o),v=e.createElement("div");v.className="moo-calendar__cell",v.setAttribute("role","gridcell");let p=e.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",A(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=e.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=e.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 t{static getInstance(e){return e?.nodeType===1&&I.get(e)||null}static getOrCreateInstance(e,i={}){return t.getInstance(e)||new t(e,i)}constructor(e,i={}){if(!z(e,"[data-datepicker]"))throw new TypeError("MooDatepicker requires a [data-datepicker] root element.");let a=I.get(e);if(a)return a;if(this._element=e,this._document=e.ownerDocument,this._window=this._document.defaultView||window,this._listeners=[],this._floatingListeners=[],this._disposed=!1,this._positionPopover=null,this._popoverPortal=null,this._trigger=e.querySelector("[data-datepicker-trigger]"),this._popover=e.querySelector("[data-datepicker-popover]"),this._label=e.querySelector("[data-datepicker-label]"),this._input=e.querySelector("[data-datepicker-input]")||e.querySelector('input[type="hidden"]'),this._validationInput=e.querySelector("[data-datepicker-validation]"),this._calendarRoot=e.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(e,{...i,value:i.value||this._input.value||e.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(e,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"),oe(this),this._trigger.setAttribute("aria-expanded","true"),this.calendar.focusActiveDay(),g(this._element,this._window,"shown.moo.datepicker"))}hide(e=!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"),e&&this._trigger.focus(),g(this._element,this._window,"hidden.moo.datepicker"))}toggle(){this.isOpen()?this.hide():this.show()}isOpen(){return!this._popover.hidden}getDate(e=void 0){return this.calendar.getDate(e)}setDate(e,i={}){let a=this.calendar.setDate(e,{emit:!1});return a&&(this._syncFromCalendar(),i.emit!==!1&&this._emitChange()),a}clear(e={}){this.calendar.clear({emit:!1}),this._syncFromCalendar(),e.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 e=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,e,"reset",()=>{this._window.setTimeout(()=>{this._defaultValue?this.setDate(this._defaultValue,{emit:!1}):this.clear({emit:!1})},0)})}_syncFromCalendar(){let e=this.calendar.getDate("yyyy-mm-dd")||"";K(this._input,e),re(this._validationInput,e),se(this._element,this._trigger,this._validationInput),this._element.dataset.datepickerValue=e,this._label.textContent=e?A(d(e),this._config.locale):this._placeholder}_emitChange(){g(this._element,this._window,"change.moo.datepicker",{date:this.getDate(),value:this.getDate("yyyy-mm-dd")||""})}},ne=class t{static getInstance(e){return e?.nodeType===1&&M.get(e)||null}static getOrCreateInstance(e,i={}){return t.getInstance(e)||new t(e,i)}constructor(e,i={}){if(!z(e,"[data-datepicker-range]"))throw new TypeError("MooDateRangePicker requires a [data-datepicker-range] root element.");let a=M.get(e);if(a)return a;if(this._element=e,this._document=e.ownerDocument,this._window=this._document.defaultView||window,this._listeners=[],this._floatingListeners=[],this._disposed=!1,this._positionPopover=null,this._popoverPortal=null,this._trigger=e.querySelector("[data-datepicker-trigger]"),this._popover=e.querySelector("[data-datepicker-popover]"),this._label=e.querySelector("[data-datepicker-label]"),this._startInput=e.querySelector("[data-datepicker-range-start]"),this._endInput=e.querySelector("[data-datepicker-range-end]"),this._validationInput=e.querySelector("[data-datepicker-validation]"),this._calendarRoot=e.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(e,{...i,mode:"range",startValue:i.startValue||this._startInput.value||e.dataset.datepickerStartValue,endValue:i.endValue||this._endInput.value||e.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(e,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"),oe(this),this._trigger.setAttribute("aria-expanded","true"),this.calendar.focusActiveDay(),g(this._element,this._window,"shown.moo.datepicker"))}hide(e=!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"),e&&this._trigger.focus(),g(this._element,this._window,"hidden.moo.datepicker"))}toggle(){this.isOpen()?this.hide():this.show()}isOpen(){return!this._popover.hidden}getDates(e=void 0){return this.calendar.getDates(e)}setDates(e,i,a={}){let n=this.calendar.setDates(e,i,{emit:!1});return n&&(this._syncFromCalendar(),a.emit!==!1&&this._emitChange()),n}clear(e={}){this.calendar.clear({emit:!1}),this._syncFromCalendar(),e.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 e=()=>{this._window.setTimeout(()=>{this.isOpen()&&!O(this,this._document.activeElement)&&this.hide(!1)},0)};c(this._listeners,this._element,"focusout",e),c(this._listeners,this._popover,"focusout",e),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[e="",i=""]=this.calendar.getDates("yyyy-mm-dd");K(this._startInput,e||""),K(this._endInput,i||""),re(this._validationInput,e&&i?`${e} - ${i}`:""),se(this._element,this._trigger,this._validationInput),this._element.dataset.datepickerStartValue=e||"",this._element.dataset.datepickerEndValue=i||"",e&&i?this._label.textContent=`${A(d(e),this._config.locale)} - ${A(d(i),this._config.locale)}`:e?this._label.textContent=A(d(e),this._config.locale):this._label.textContent=this._placeholder}_emitChange(){let[e,i]=this.getDates(),[a="",n=""]=this.getDates("yyyy-mm-dd");g(this._element,this._window,"change.moo.datepicker",{startDate:e,endDate:i,startValue:a,endValue:n})}};export{L as MooCalendar,ne as MooDateRangePicker,H as default};
|