monobill-mintui 0.6.650 → 0.6.652

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.
Files changed (122) hide show
  1. package/bin/component-dependencies.json +13 -1
  2. package/dist/components/chunks/ScrollFade-D1FPF6ZS.js +82 -0
  3. package/dist/components/chunks/ScrollFade-DT2Br2g7.js +1 -0
  4. package/dist/components/chunks/date-picker-BQsCoKaK.js +1282 -0
  5. package/dist/components/chunks/date-picker-tm5Oc92c.js +1 -0
  6. package/dist/components/chunks/{input-CYv5hraJ.js → input-DcglGwsR.js} +13 -6
  7. package/dist/components/chunks/input-awdYlp-G.js +1 -0
  8. package/dist/components/chunks/{popover-DB1OaYVe.js → popover-FdMS4yAD.js} +54 -14
  9. package/dist/components/chunks/popover-wGdggZ-a.js +1 -0
  10. package/dist/components/chunks/{table-DRdsVUJL.js → table-B9e-cnAC.js} +7 -6
  11. package/dist/components/chunks/table-vjF3q3J5.js +1 -0
  12. package/dist/components/chunks/time-picker-Cq3qzkDb.js +1 -0
  13. package/dist/components/chunks/time-picker-S0bc0BPU.js +360 -0
  14. package/dist/components/date-picker/DatePicker.d.ts +5 -0
  15. package/dist/components/date-picker/DatePicker.d.ts.map +1 -1
  16. package/dist/components/date-picker/browser.js +2 -1270
  17. package/dist/components/date-picker/index.cjs +1 -1
  18. package/dist/components/date-picker/index.js +2 -1270
  19. package/dist/components/datetime-picker/DateTimePicker.d.ts +44 -0
  20. package/dist/components/datetime-picker/DateTimePicker.d.ts.map +1 -0
  21. package/dist/components/datetime-picker/browser.js +255 -0
  22. package/dist/components/datetime-picker/index.cjs +1 -0
  23. package/dist/components/datetime-picker/index.d.ts +4 -0
  24. package/dist/components/datetime-picker/index.d.ts.map +1 -0
  25. package/dist/components/datetime-picker/index.js +243 -0
  26. package/dist/components/form/Form.d.ts.map +1 -1
  27. package/dist/components/form/browser.js +9 -8
  28. package/dist/components/form/index.cjs +1 -1
  29. package/dist/components/form/index.js +9 -8
  30. package/dist/components/input/browser.js +1 -1
  31. package/dist/components/input/index.cjs +1 -1
  32. package/dist/components/input/index.js +1 -1
  33. package/dist/components/link/browser.js +1 -1
  34. package/dist/components/link/index.cjs +1 -1
  35. package/dist/components/link/index.js +1 -1
  36. package/dist/components/navigation/browser.js +2 -2
  37. package/dist/components/navigation/index.cjs +1 -1
  38. package/dist/components/navigation/index.js +2 -2
  39. package/dist/components/popover/Popover.d.ts.map +1 -1
  40. package/dist/components/popover/browser.js +1 -1
  41. package/dist/components/popover/index.cjs +1 -1
  42. package/dist/components/popover/index.js +1 -1
  43. package/dist/components/resource-table/ResourceTable.d.ts +1 -0
  44. package/dist/components/resource-table/ResourceTable.d.ts.map +1 -1
  45. package/dist/components/resource-table/browser.js +22 -22
  46. package/dist/components/resource-table/index.cjs +2 -2
  47. package/dist/components/resource-table/index.js +22 -22
  48. package/dist/components/scroll-fade/ScrollFade.d.ts +15 -0
  49. package/dist/components/scroll-fade/ScrollFade.d.ts.map +1 -0
  50. package/dist/components/scroll-fade/browser.js +16 -0
  51. package/dist/components/scroll-fade/index.cjs +1 -0
  52. package/dist/components/scroll-fade/index.d.ts +6 -0
  53. package/dist/components/scroll-fade/index.d.ts.map +1 -0
  54. package/dist/components/scroll-fade/index.js +4 -0
  55. package/dist/components/search/Search.d.ts.map +1 -1
  56. package/dist/components/search/browser.js +3 -3
  57. package/dist/components/search/index.cjs +1 -1
  58. package/dist/components/search/index.js +3 -3
  59. package/dist/components/select/NativeSelect.d.ts +38 -0
  60. package/dist/components/select/NativeSelect.d.ts.map +1 -0
  61. package/dist/components/select/Select.d.ts +36 -29
  62. package/dist/components/select/Select.d.ts.map +1 -1
  63. package/dist/components/select/browser.js +313 -19
  64. package/dist/components/select/index.cjs +1 -1
  65. package/dist/components/select/index.d.ts +3 -2
  66. package/dist/components/select/index.d.ts.map +1 -1
  67. package/dist/components/select/index.js +313 -19
  68. package/dist/components/side-navigation/SideNavigation.d.ts +1 -0
  69. package/dist/components/side-navigation/SideNavigation.d.ts.map +1 -1
  70. package/dist/components/side-navigation/browser.js +24 -23
  71. package/dist/components/side-navigation/index.cjs +1 -1
  72. package/dist/components/side-navigation/index.js +24 -23
  73. package/dist/components/sortable/browser.js +1 -1
  74. package/dist/components/sortable/index.cjs +1 -1
  75. package/dist/components/sortable/index.js +1 -1
  76. package/dist/components/table/Table.d.ts +1 -0
  77. package/dist/components/table/Table.d.ts.map +1 -1
  78. package/dist/components/table/browser.js +1 -1
  79. package/dist/components/table/index.cjs +1 -1
  80. package/dist/components/table/index.js +1 -1
  81. package/dist/components/tags/browser.js +1 -1
  82. package/dist/components/tags/index.cjs +1 -1
  83. package/dist/components/tags/index.js +1 -1
  84. package/dist/components/time-picker/TimePicker.d.ts +1 -0
  85. package/dist/components/time-picker/TimePicker.d.ts.map +1 -1
  86. package/dist/components/time-picker/browser.js +2 -347
  87. package/dist/components/time-picker/index.cjs +1 -1
  88. package/dist/components/time-picker/index.js +2 -347
  89. package/dist/components/tree/Tree.d.ts +2 -0
  90. package/dist/components/tree/Tree.d.ts.map +1 -1
  91. package/dist/components/tree/browser.js +15 -7
  92. package/dist/components/tree/index.cjs +1 -1
  93. package/dist/components/tree/index.js +15 -7
  94. package/dist/datetime-picker.css +3 -0
  95. package/dist/index.cjs +4 -4
  96. package/dist/index.css +22 -9
  97. package/dist/index.d.ts +3 -1
  98. package/dist/index.js +1413 -739
  99. package/dist/modal.css +1 -1
  100. package/dist/navigation-search.json +15 -1
  101. package/dist/navigation.css +1 -1
  102. package/dist/off-canvas.css +1 -1
  103. package/dist/popover.css +1 -1
  104. package/dist/scroll-fade.css +3 -0
  105. package/dist/select.css +1 -1
  106. package/dist/side-navigation.css +1 -1
  107. package/dist/theme.css +7 -2
  108. package/dist/time-picker.css +1 -1
  109. package/package.json +19 -1
  110. package/dist/components/chunks/caret-up-DzrY-bTy.js +0 -1
  111. package/dist/components/chunks/caret-up-ZK3v_oWQ.js +0 -9
  112. package/dist/components/chunks/input-Du8C2LW8.js +0 -1
  113. package/dist/components/chunks/popover-CNZ5u-MA.js +0 -1
  114. package/dist/components/chunks/table-2-0iNQJy.js +0 -1
  115. /package/dist/components/chunks/{caret-right-BzeJ0Fw3.js → caret-right-BcZ9bOhS.js} +0 -0
  116. /package/dist/components/chunks/{caret-right-Bh7uMg-Y.js → caret-right-CgIVfus7.js} +0 -0
  117. /package/dist/components/chunks/{link-BsC3zT_I.js → link-BjbBJpI6.js} +0 -0
  118. /package/dist/components/chunks/{link-dTjSvr4E.js → link-CU-gTgir.js} +0 -0
  119. /package/dist/components/chunks/{search-v06eZL4m.js → search--bcFMYMP.js} +0 -0
  120. /package/dist/components/chunks/{search-CTAGy5ab.js → search-Cixhf7hA.js} +0 -0
  121. /package/dist/components/chunks/{sortable-B1nMJBah.js → sortable-CNlF0_gv.js} +0 -0
  122. /package/dist/components/chunks/{sortable-CXM-7eyL.js → sortable-CVK48xj1.js} +0 -0
@@ -16,1273 +16,5 @@ __mintLoadStyle('icon', '../../icon.css')
16
16
  __mintLoadStyle('popover', '../../popover.css')
17
17
  __mintLoadStyle('stack', '../../stack.css')
18
18
  __mintLoadStyle('date-picker', '../../date-picker.css')
19
- import { a as e } from "../chunks/icon-Cxv9k3CY.js";
20
- import { t } from "../chunks/register-element-BFYmIynH.js";
21
- import "../chunks/icon-DMa6Oo80.js";
22
- import "../chunks/caret-right-Bh7uMg-Y.js";
23
- import "../chunks/input-CYv5hraJ.js";
24
- import "../chunks/popover-DB1OaYVe.js";
25
- e({
26
- name: "calendar",
27
- viewBox: "0 0 24 24",
28
- path: "M8 7V3m8 4V3M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2zM6 11h12M6 14h12M6 17h12",
29
- strokeLinecap: "round",
30
- strokeLinejoin: "round"
31
- }), e({
32
- name: "caret-left",
33
- viewBox: "0 0 24 24",
34
- path: "M15 19l-7-7 7-7",
35
- strokeLinecap: "round",
36
- strokeLinejoin: "round"
37
- });
38
- //#endregion
39
- //#region src/components/date-picker/DatePicker.ts
40
- var n = class extends HTMLElement {
41
- static get observedAttributes() {
42
- return [
43
- "value",
44
- "label",
45
- "info",
46
- "disabled",
47
- "id",
48
- "name",
49
- "required",
50
- "readonly",
51
- "format",
52
- "min",
53
- "max",
54
- "range",
55
- "shortcuts",
56
- "display-format",
57
- "error",
58
- "error-message",
59
- "loading",
60
- "selection-mode",
61
- "week-start-day",
62
- "mode",
63
- "disabled-dates"
64
- ];
65
- }
66
- constructor() {
67
- super(), this._input = null, this._textInput = null, this._popover = null, this._calendarContainer = null, this._iconButton = null, this._hiddenInput = null, this._startPartInputs = [], this._endPartInputs = [], this._displayEl = null, this._inputsWrapperEl = null, this._fieldsContainer = null, this._resetHandler = null, this._isInputMode = !1, this._currentMonth = (/* @__PURE__ */ new Date()).getMonth(), this._currentYear = (/* @__PURE__ */ new Date()).getFullYear(), this._viewMode = "calendar", this._selectedStartDate = null, this._selectedEndDate = null, this._isRange = !1, this._hoveredDate = null, this._isHandlingClick = !1, this._touchStartDate = null, this._touchStartElement = null, this._isTouchActive = !1, this._resizeObserver = null, this._popoverObserver = null, this._focusTrapHandler = null, this._escapeHandler = null, this._a11yId = `mint-date-picker-${Math.random().toString(36).slice(2, 10)}`;
68
- }
69
- connectedCallback() {
70
- this.classList.add("mint-date-picker"), this.render(), this._setupPopoverWithRetry(), this._attachFormResetListener();
71
- }
72
- disconnectedCallback() {
73
- if (this._popoverObserver &&= (this._popoverObserver.disconnect(), null), this._resizeObserver &&= (this._resizeObserver.disconnect(), null), this._removeFocusTrap(), this._resetHandler) {
74
- let e = this.closest("form");
75
- e && e.removeEventListener("reset", this._resetHandler), this._resetHandler = null;
76
- }
77
- }
78
- isLoading() {
79
- return this.getAttribute("loading") === "true";
80
- }
81
- attributeChangedCallback(e, t, n) {
82
- if (t !== n) {
83
- if (e === "error" || e === "error-message") {
84
- let e = this.hasError(), t = this.getErrorMessage();
85
- this._applyErrorVisuals(e, t, this.isDisabled());
86
- return;
87
- }
88
- if (e === "loading") {
89
- this.render();
90
- return;
91
- }
92
- if (e === "mode" || e === "format") {
93
- let e = this.getMode();
94
- e === "month" ? this._viewMode = "month" : e === "year" ? this._viewMode = "year" : this._viewMode = "calendar", this._popover && this._calendarContainer && this._buildCalendar();
95
- }
96
- this.render(), this._input && this._setupPopoverWithRetry();
97
- }
98
- }
99
- getValue() {
100
- return this.getAttribute("value") || "";
101
- }
102
- setValue(e) {
103
- e ? (this.setAttribute("value", e), this._textInput && (this._textInput.value = e), this._parseValue(e)) : (this.removeAttribute("value"), this._textInput && (this._textInput.value = ""), this._selectedStartDate = null, this._selectedEndDate = null), this._buildCalendar(), this._updateDisplayText();
104
- }
105
- get value() {
106
- try {
107
- return this.getValue() || "";
108
- } catch {
109
- return "";
110
- }
111
- }
112
- set value(e) {
113
- try {
114
- this.setValue(e || "");
115
- } catch {}
116
- }
117
- getFormat() {
118
- return this.getAttribute("format") || "mm/dd/yyyy";
119
- }
120
- getLabel() {
121
- return this.getAttribute("label") || "";
122
- }
123
- getInfo() {
124
- return this.getAttribute("info") || "";
125
- }
126
- isDisabled() {
127
- return this.getAttribute("disabled") === "true";
128
- }
129
- isReadonly() {
130
- return this.getAttribute("readonly") === "true";
131
- }
132
- isRequired() {
133
- return this.getAttribute("required") === "true";
134
- }
135
- hasError() {
136
- return this.getAttribute("error") === "true";
137
- }
138
- getErrorMessage() {
139
- return this.getAttribute("error-message") || "";
140
- }
141
- isRange() {
142
- return this.getAttribute("range") === "true";
143
- }
144
- getId() {
145
- return this.getAttribute("id") || "";
146
- }
147
- getName() {
148
- return this.getAttribute("name") || "";
149
- }
150
- getMin() {
151
- return this.getAttribute("min") || "";
152
- }
153
- getMax() {
154
- return this.getAttribute("max") || "";
155
- }
156
- getDisabledDates() {
157
- let e = this.getAttribute("disabled-dates");
158
- if (!e) return [];
159
- try {
160
- let t = JSON.parse(e), n = this.getFormat();
161
- return t.map((e) => this._parseDateString(e, n)).filter((e) => e !== null);
162
- } catch {
163
- return [];
164
- }
165
- }
166
- getDisabledDateStrings() {
167
- let e = this.getAttribute("disabled-dates");
168
- if (!e) return [];
169
- try {
170
- return JSON.parse(e);
171
- } catch {
172
- return [];
173
- }
174
- }
175
- disableDate(e) {
176
- let t = this.getFormat(), n = this.getDisabledDateStrings(), r = Array.isArray(e) ? e : [e], i = [];
177
- for (let e of r) {
178
- let r = this._parseDateString(e, t);
179
- if (r) {
180
- let e = this._formatDate(r, t);
181
- n.includes(e) || i.push(e);
182
- }
183
- }
184
- if (i.length > 0) {
185
- let e = [...n, ...i];
186
- this.setAttribute("disabled-dates", JSON.stringify(e)), this._buildCalendar();
187
- }
188
- }
189
- enableDate(e) {
190
- let t = this.getFormat(), n = this.getDisabledDateStrings(), r = Array.isArray(e) ? e : [e], i = [];
191
- for (let e of r) {
192
- let n = this._parseDateString(e, t);
193
- if (n) {
194
- let e = this._formatDate(n, t);
195
- i.push(e);
196
- }
197
- }
198
- if (i.length > 0) {
199
- let e = n.filter((e) => !i.includes(e));
200
- e.length === 0 ? this.removeAttribute("disabled-dates") : this.setAttribute("disabled-dates", JSON.stringify(e)), this._buildCalendar();
201
- }
202
- }
203
- getSelectionMode() {
204
- let e = this.getAttribute("selection-mode");
205
- return e === "week" || e === "month" ? e : "day";
206
- }
207
- getMode() {
208
- let e = this.getAttribute("mode");
209
- if (e === "month" || e === "year") return e;
210
- let t = this.getFormat().toLowerCase(), n = t.includes("d"), r = t.includes("m");
211
- return !n && !r ? "year" : !n && r ? "month" : "default";
212
- }
213
- getWeekStartDay() {
214
- return {
215
- sunday: 0,
216
- monday: 1,
217
- tuesday: 2,
218
- wednesday: 3,
219
- thursday: 4,
220
- friday: 5,
221
- saturday: 6
222
- }[this.getAttribute("week-start-day")?.toLowerCase() || "sunday"] ?? 0;
223
- }
224
- getDisplayFormat() {
225
- return this.getAttribute("display-format") || "F j, Y";
226
- }
227
- getShortcuts() {
228
- let e = this.getAttribute("shortcuts");
229
- if (!e) return [];
230
- try {
231
- let t = JSON.parse(e);
232
- if (Array.isArray(t)) return t.map((e) => ({
233
- label: e.label,
234
- action: this._createShortcutAction(e.action)
235
- }));
236
- } catch {
237
- let t = e.trim();
238
- if (t && typeof window[t] == "function") {
239
- let e = window[t]();
240
- if (Array.isArray(e)) return e.map((e) => ({
241
- label: e.label,
242
- action: typeof e.action == "function" ? e.action : this._createShortcutAction(e.action)
243
- }));
244
- }
245
- }
246
- return [];
247
- }
248
- _createShortcutAction(e) {
249
- return typeof e == "function" ? e : typeof e == "string" && typeof window[e] == "function" ? window[e] : () => null;
250
- }
251
- _getDefaultShortcuts() {
252
- let e = [{
253
- label: "Today",
254
- action: () => /* @__PURE__ */ new Date()
255
- }];
256
- return this._isRange && e.push({
257
- label: "This Week",
258
- action: () => {
259
- let e = /* @__PURE__ */ new Date(), t = e.getDay(), n = new Date(e);
260
- n.setDate(e.getDate() - t), n.setHours(0, 0, 0, 0);
261
- let r = new Date(n);
262
- return r.setDate(n.getDate() + 6), r.setHours(23, 59, 59, 999), {
263
- start: n,
264
- end: r
265
- };
266
- }
267
- }, {
268
- label: "This Month",
269
- action: () => {
270
- let e = /* @__PURE__ */ new Date(), t = new Date(e.getFullYear(), e.getMonth(), 1), n = new Date(e.getFullYear(), e.getMonth() + 1, 0);
271
- return n.setHours(23, 59, 59, 999), {
272
- start: t,
273
- end: n
274
- };
275
- }
276
- }), e;
277
- }
278
- _getFormatTokens(e) {
279
- let t = [], n = 0, r = e.toLowerCase();
280
- for (; n < r.length;) {
281
- let i = r[n];
282
- if (i === "d" || i === "m" || i === "y") {
283
- let e = 1, a = n + 1;
284
- for (; a < r.length && r[a] === i;) e++, a++;
285
- t.push({
286
- type: "part",
287
- part: i,
288
- len: e
289
- }), n = a;
290
- } else t.push({
291
- type: "sep",
292
- value: e[n]
293
- }), n++;
294
- }
295
- return t;
296
- }
297
- _createPartInput(e, t, n, r, i) {
298
- let a = document.createElement("input");
299
- return a.type = "text", a.inputMode = "numeric", a.pattern = "\\d*", a.maxLength = e, a.placeholder = t, a.className = "mint-date-picker-part-input", a.disabled = n || r, a.readOnly = r, a.required = i, e === 4 ? a.classList.add("is-year-part") : e === 2 && a.classList.add("is-short-part"), a;
300
- }
301
- _buildValueFromParts(e, t) {
302
- let n = 0;
303
- return t.map((t) => {
304
- if (t.type === "sep") return t.value;
305
- let r = e[n]?.value || "";
306
- return n++, r;
307
- }).join("");
308
- }
309
- _applyDateToParts(e, t, n, r) {
310
- if (!t.length) return;
311
- if (!e) {
312
- t.forEach((e) => e.value = "");
313
- return;
314
- }
315
- let i = this._formatDate(e, r), a = 0, o = 0;
316
- n.forEach((e) => {
317
- if (e.type === "sep") a += e.value.length;
318
- else {
319
- let n = i.substr(a, e.len);
320
- t[o] && (t[o].value = n), o++, a += e.len;
321
- }
322
- });
323
- }
324
- _syncHiddenInput() {
325
- if (!this._hiddenInput) return;
326
- let e = this.getFormat(), t = this._getFormatTokens(e), n = this._buildValueFromParts(this._startPartInputs, t);
327
- if (this._isRange) {
328
- let e = this._buildValueFromParts(this._endPartInputs, t);
329
- this._hiddenInput.value = e ? `${n} - ${e}` : n;
330
- } else this._hiddenInput.value = n;
331
- }
332
- _focusNext(e, t) {
333
- if (t + 1 < e.length) {
334
- let n = e[t + 1];
335
- n.focus(), n.setSelectionRange(0, n.value.length);
336
- }
337
- }
338
- _focusPrev(e, t) {
339
- if (t - 1 >= 0) {
340
- let n = e[t - 1];
341
- n.focus(), n.setSelectionRange(n.value.length, n.value.length);
342
- }
343
- }
344
- _attachPartInputHandlers(e, t, n) {
345
- e.forEach((t, n) => {
346
- let r = t.maxLength || 2;
347
- t.addEventListener("input", () => {
348
- t.value = t.value.replace(/\D/g, "").slice(0, r), t.value.length >= r && this._focusNext(e, n), this._syncHiddenInput();
349
- }), t.addEventListener("keydown", (r) => {
350
- r.key === "Backspace" && t.selectionStart === 0 && t.selectionEnd === 0 && this._focusPrev(e, n), r.key === "ArrowLeft" && t.selectionStart === 0 && t.selectionEnd === 0 && (this._focusPrev(e, n), r.preventDefault()), r.key === "ArrowRight" && t.selectionStart === t.value.length && t.selectionEnd === t.value.length && (this._focusNext(e, n), r.preventDefault());
351
- }), t.addEventListener("blur", (e) => {
352
- this._syncHiddenInput();
353
- let t = e.relatedTarget, n = t && (this._startPartInputs.includes(t) || this._endPartInputs.includes(t));
354
- setTimeout(() => {
355
- if (!(this._startPartInputs.some((e) => e === document.activeElement) || this._endPartInputs.some((e) => e === document.activeElement)) && (n || this._handleBlur(this._hiddenInput?.value || ""), this._exitInputMode(), !n && this._hiddenInput)) {
356
- let t = new FocusEvent("blur", {
357
- bubbles: !0,
358
- cancelable: !0,
359
- relatedTarget: e.relatedTarget
360
- });
361
- this._hiddenInput.dispatchEvent(t);
362
- }
363
- }, 0);
364
- });
365
- });
366
- }
367
- _splitRangeInput(e, t) {
368
- let n = e.split(/\s*-\s*/);
369
- return n.length >= 2 ? [n[0], n.slice(1).join("-")] : [e];
370
- }
371
- _parseValue(e) {
372
- let t = this.getFormat(), n = this._getFormatTokens(t), r = this.getSelectionMode();
373
- if (this._isRange || r === "week" || r === "month") {
374
- let [r, i] = this._splitRangeInput(e, t), a = r ? this._parseDateString(r, t) : null, o = i ? this._parseDateString(i, t) : null;
375
- if (a && o) {
376
- let [e, t] = a <= o ? [a, o] : [o, a];
377
- this._selectedStartDate = e, this._selectedEndDate = t, this._currentMonth = e.getMonth(), this._currentYear = e.getFullYear();
378
- } else a && (this._selectedStartDate = a, this._selectedEndDate = null, this._currentMonth = a.getMonth(), this._currentYear = a.getFullYear());
379
- this._applyDateToParts(this._selectedStartDate, this._startPartInputs, n, t), this._applyDateToParts(this._selectedEndDate, this._endPartInputs, n, t);
380
- } else {
381
- let r = this._parseDateString(e, t);
382
- r && !isNaN(r.getTime()) ? (this._selectedStartDate = r, this._selectedEndDate = null, this._currentMonth = r.getMonth(), this._currentYear = r.getFullYear(), this._applyDateToParts(r, this._startPartInputs, n, t)) : this._applyDateToParts(null, this._startPartInputs, n, t);
383
- }
384
- this._syncHiddenInput(), this._updateDisplayText();
385
- }
386
- _parseDateString(e, t) {
387
- let n = /[\/\-\.\s]+/;
388
- if (n.test(e)) {
389
- let r = e.split(n).filter((e) => e.length > 0), i = t.split(/[\/\-\.\s]+/).filter((e) => e.length > 0);
390
- if (r.length === i.length) {
391
- let e = 0, t = 0, n = 0;
392
- for (let a = 0; a < i.length; a++) {
393
- let o = i[a].toLowerCase(), s = r[a];
394
- if (o.includes("d")) e = parseInt(s, 10);
395
- else if (o.includes("m")) t = parseInt(s, 10) - 1;
396
- else if (o.includes("y")) {
397
- let e = parseInt(s, 10), t = o.length, r = s.length;
398
- (r === 2 && t === 4 || r === 2 && t === 2) && (e = Math.floor((/* @__PURE__ */ new Date()).getFullYear() / 100) * 100 + e), n = e;
399
- }
400
- }
401
- let a = i.some((e) => e.toLowerCase().includes("d")), o = i.some((e) => e.toLowerCase().includes("m"));
402
- if (a || (e = 1), o || (t = 0), t >= 0 && t <= 11 && n) {
403
- let r = new Date(n, t, e);
404
- if (!isNaN(r.getTime())) return a && r.getDate() !== e || r.getMonth() !== t || r.getFullYear() !== n ? null : r;
405
- }
406
- }
407
- }
408
- let r = e.replace(/[\/\-\.]/g, ""), i = t.replace(/[\/\-\.]/g, "").toLowerCase(), a = i.indexOf("d"), o = i.indexOf("m"), s = i.indexOf("y"), c = [
409
- {
410
- char: "d",
411
- index: a
412
- },
413
- {
414
- char: "m",
415
- index: o
416
- },
417
- {
418
- char: "y",
419
- index: s
420
- }
421
- ].sort((e, t) => e.index - t.index), l = 0, u = 0, d = 0, f = 0;
422
- i.length, r.length;
423
- for (let e of c) if (e.char === "d") {
424
- let e = i.lastIndexOf("d") - i.indexOf("d") + 1, t = r.substr(f, e);
425
- if (t.length === 0) return null;
426
- l = parseInt(t, 10), f += t.length;
427
- } else if (e.char === "m") {
428
- let e = i.lastIndexOf("m") - i.indexOf("m") + 1, t = r.substr(f, e);
429
- if (t.length === 0) return null;
430
- u = parseInt(t, 10) - 1, f += t.length;
431
- } else if (e.char === "y") {
432
- let e = i.lastIndexOf("y") - i.indexOf("y") + 1, t = r.substr(f), n = Math.min(e, t.length), a = t.substr(0, n);
433
- if (a.length === 0) return null;
434
- let o = parseInt(a, 10);
435
- (n === 2 && e === 4 || n === 2 && e === 2) && (o = Math.floor((/* @__PURE__ */ new Date()).getFullYear() / 100) * 100 + o), d = o, f += n;
436
- }
437
- let p = t.toLowerCase(), m = p.includes("d"), h = p.includes("m");
438
- if (m || (l = 1), h || (u = 0), u < 0 || u > 11 || !d) return null;
439
- let g = new Date(d, u, l);
440
- return isNaN(g.getTime()) || m && g.getDate() !== l || g.getMonth() !== u || g.getFullYear() !== d ? null : g;
441
- }
442
- _formatDate(e, t) {
443
- let n = e.getDate(), r = e.getMonth() + 1, i = e.getFullYear(), a = t.toLowerCase(), o = t;
444
- return a.includes("dd") ? o = o.replace(/dd/gi, String(n).padStart(2, "0")) : a.includes("d") && (o = o.replace(/d/gi, String(n))), a.includes("mm") ? o = o.replace(/mm/gi, String(r).padStart(2, "0")) : a.includes("m") && (o = o.replace(/m/gi, String(r))), a.includes("yyyy") ? o = o.replace(/yyyy/gi, String(i)) : a.includes("yy") && (o = o.replace(/yy/gi, String(i).substr(2))), o;
445
- }
446
- _formatDatePhp(e, t) {
447
- let n = e.getDate(), r = e.getMonth() + 1, i = e.getFullYear(), a = [
448
- "Sunday",
449
- "Monday",
450
- "Tuesday",
451
- "Wednesday",
452
- "Thursday",
453
- "Friday",
454
- "Saturday"
455
- ], o = [
456
- "Sun",
457
- "Mon",
458
- "Tue",
459
- "Wed",
460
- "Thu",
461
- "Fri",
462
- "Sat"
463
- ], s = [
464
- "January",
465
- "February",
466
- "March",
467
- "April",
468
- "May",
469
- "June",
470
- "July",
471
- "August",
472
- "September",
473
- "October",
474
- "November",
475
- "December"
476
- ], c = [
477
- "Jan",
478
- "Feb",
479
- "Mar",
480
- "Apr",
481
- "May",
482
- "Jun",
483
- "Jul",
484
- "Aug",
485
- "Sep",
486
- "Oct",
487
- "Nov",
488
- "Dec"
489
- ], l = (e, t = 2) => e.toString().padStart(t, "0"), u = (e) => {
490
- let t = e % 10, n = e % 100;
491
- return t === 1 && n !== 11 ? "st" : t === 2 && n !== 12 ? "nd" : t === 3 && n !== 13 ? "rd" : "th";
492
- }, d = "";
493
- for (let f = 0; f < t.length; f++) {
494
- let p = t[f];
495
- if (p === "\\" && f + 1 < t.length) {
496
- d += t[f + 1], f++;
497
- continue;
498
- }
499
- switch (p) {
500
- case "Y":
501
- d += i.toString();
502
- break;
503
- case "y":
504
- d += i.toString().slice(-2);
505
- break;
506
- case "m":
507
- d += l(r);
508
- break;
509
- case "n":
510
- d += r.toString();
511
- break;
512
- case "M":
513
- d += c[r - 1];
514
- break;
515
- case "F":
516
- d += s[r - 1];
517
- break;
518
- case "d":
519
- d += l(n);
520
- break;
521
- case "j":
522
- d += n.toString();
523
- break;
524
- case "D":
525
- d += o[e.getDay()];
526
- break;
527
- case "l":
528
- d += a[e.getDay()];
529
- break;
530
- case "S":
531
- d += u(n);
532
- break;
533
- default:
534
- d += p;
535
- break;
536
- }
537
- }
538
- return d;
539
- }
540
- _validateDateString(e, t) {
541
- let n = this._parseDateString(e, t);
542
- return n !== null && !isNaN(n.getTime());
543
- }
544
- render() {
545
- let e = this.isLoading(), t = this.getLabel(), n = this.getInfo(), r = this.getValue(), i = this.isDisabled(), a = this.isReadonly(), o = this.isRequired(), s = this.getId() || this._a11yId, c = this.getName(), l = this.getFormat(), u = this.hasError(), d = this.getErrorMessage(), f = this.getSelectionMode();
546
- this._isRange = this.isRange() || f === "week" || f === "month", this._input || (this._input = document.createElement("div"), this._input.className = "mint-date-picker-field", this.appendChild(this._input));
547
- let p = this.querySelector(".mint-date-picker-label-container");
548
- if (t || n) {
549
- p || (p = document.createElement("div"), p.className = "mint-date-picker-label-container", this.contains(this._input) ? this.insertBefore(p, this._input) : this.appendChild(p));
550
- let e = p.querySelector(".mint-date-picker-label");
551
- t ? (e || (e = document.createElement("label"), e.className = "mint-date-picker-label", p.insertBefore(e, p.firstChild)), e.textContent = t, s && this._textInput && e.setAttribute("for", s)) : e && e.remove();
552
- let r = p.querySelector(".mint-date-picker-info");
553
- n ? (r || (r = document.createElement("span"), r.className = "mint-date-picker-info", p.appendChild(r)), r.textContent = n) : r && r.remove();
554
- } else p && p.remove();
555
- this._hiddenInput || (this._hiddenInput = document.createElement("input"), this._hiddenInput.type = "hidden", this._hiddenInput.value = r || "", this._textInput = this._hiddenInput, this._input.appendChild(this._hiddenInput)), s && (this._hiddenInput.id = s), c && (this._hiddenInput.name = c), this._hiddenInput.value = r || "", this._hiddenInput.setAttribute("aria-invalid", u ? "true" : "false");
556
- let m = this._input.querySelector(".mint-date-fields");
557
- m || (m = document.createElement("div"), this._input.appendChild(m)), this._fieldsContainer = m, this._applyErrorVisuals(u, d, i), m.innerHTML = "", this._displayEl = document.createElement("div"), this._displayEl.className = `mint-date-picker-display${a ? " is-readonly" : ""}`, this._displayEl.tabIndex = i || a ? -1 : 0, this._displayEl.setAttribute("role", "button"), this._displayEl.setAttribute("aria-label", `${this.getLabel() || "Date"}: ${r || "Select date"}`), this._displayEl.addEventListener("click", () => {
558
- i || a || this._enterInputMode();
559
- }), this._displayEl.addEventListener("keydown", (e) => {
560
- i || a || (e.key === "Enter" || e.key === " ") && (e.preventDefault(), this._enterInputMode());
561
- }), this._inputsWrapperEl = document.createElement("div"), this._isRange, this._inputsWrapperEl.className = "mint-date-picker-inputs";
562
- let h = this._getFormatTokens(l);
563
- this._startPartInputs = [], this._endPartInputs = [];
564
- let g = (e) => {
565
- let t = document.createDocumentFragment();
566
- return h.forEach((n) => {
567
- if (n.type === "sep") {
568
- let e = document.createElement("span");
569
- e.textContent = n.value, e.className = "mint-date-picker-separator", t.appendChild(e);
570
- } else {
571
- let r = n.part === "d" ? "dd" : n.part === "m" ? "mm" : n.len === 2 ? "yy" : "yyyy", s = this._createPartInput(n.len, r, i, a, o), c = n.part === "d" ? "day" : n.part === "m" ? "month" : "year", l = this.getLabel() || "Date";
572
- s.setAttribute("aria-label", `${e === "end" ? `End ${l.toLowerCase()}` : l} ${c}`), e === "start" ? this._startPartInputs.push(s) : this._endPartInputs.push(s), t.appendChild(s);
573
- }
574
- }), t;
575
- };
576
- if (this._isRange) {
577
- let e = document.createElement("div");
578
- e.className = "mint-date-picker-range-part", e.appendChild(g("start")), this._inputsWrapperEl.appendChild(e);
579
- let t = document.createElement("span");
580
- t.textContent = " - ", t.className = "mint-date-picker-range-dash", this._inputsWrapperEl.appendChild(t);
581
- let n = document.createElement("div");
582
- n.className = "mint-date-picker-range-part", n.appendChild(g("end")), this._inputsWrapperEl.appendChild(n);
583
- } else this._inputsWrapperEl.appendChild(g("start"));
584
- let _ = document.createElement("div");
585
- if (_.className = "mint-date-picker-stacked", this.classList.toggle("is-input-mode", this._isInputMode), _.appendChild(this._displayEl), _.appendChild(this._inputsWrapperEl), m.appendChild(_), this._isRange && this._inputsWrapperEl && this._setupContainerObserver(), m.addEventListener("click", () => {
586
- this._isInputMode || i || a || this._enterInputMode();
587
- }), this._attachPartInputHandlers(this._startPartInputs, h, m), this._isRange && this._attachPartInputHandlers(this._endPartInputs, h, m), this._parseValue(r), this._syncHiddenInput(), this._updateDisplayText(), this._iconButton) this._iconButton.disabled = i || a, !i && !a ? this._iconButton.tabIndex = 0 : this._iconButton.tabIndex = -1;
588
- else {
589
- this._iconButton = document.createElement("button"), this._iconButton.type = "button", this._iconButton.tabIndex = 0, this._iconButton.className = "mint-date-picker-icon-button", this._iconButton.setAttribute("aria-label", "Open calendar"), this._iconButton.setAttribute("aria-haspopup", "dialog"), this._iconButton.setAttribute("aria-expanded", "false");
590
- let e = `date-icon-${Math.random().toString(36).substr(2, 9)}`;
591
- this._iconButton.id = e;
592
- let t = document.createElement("mint-icon");
593
- t.setAttribute("name", "calendar"), t.className = "mint-date-picker-icon", this._iconButton.appendChild(t), this._input.prepend(this._iconButton), this._iconButton.disabled = i || a;
594
- }
595
- this._renderErrorState(u, d), this._syncDateFieldDescriptions(), this._renderSkeleton(e);
596
- }
597
- _renderErrorState(e, t) {
598
- let n = this.querySelector(".mint-date-picker-error");
599
- e && t ? (n || (n = document.createElement("div"), n.className = "mint-date-picker-error", this.appendChild(n)), n.textContent = t) : n && n.remove();
600
- }
601
- _syncDateFieldDescriptions() {
602
- let e = Array.from(this.querySelectorAll(".mint-date-fields input"));
603
- if (!e.length) return;
604
- let t = (this.getAttribute("aria-describedby") || "").split(/\s+/).filter(Boolean), n = this.querySelector(".mint-date-picker-info"), r = this.querySelector(".mint-date-picker-error"), i = this.getAttribute("id") || this._a11yId;
605
- n && (n.id = `${i}-info`, t.push(n.id)), r && (r.id = `${i}-error`, t.push(r.id));
606
- let a = Array.from(new Set(t)).join(" ");
607
- e.forEach((e) => {
608
- e.setAttribute("aria-invalid", String(this._hiddenInput?.getAttribute("aria-invalid") === "true")), a ? e.setAttribute("aria-describedby", a) : e.removeAttribute("aria-describedby");
609
- });
610
- }
611
- _applyErrorVisuals(e, t, n) {
612
- if (this._renderErrorState(e, t), this._fieldsContainer) {
613
- let t = this._getFieldContainerClass(e, n);
614
- this._fieldsContainer.className = t;
615
- }
616
- this._hiddenInput && this._hiddenInput.setAttribute("aria-invalid", e ? "true" : "false"), this._syncDateFieldDescriptions();
617
- }
618
- _attachFormResetListener() {
619
- let e = this.closest("form");
620
- !e || this._resetHandler || (this._resetHandler = () => {
621
- this.setValue(""), this._clearPartInputs(this._startPartInputs), this._clearPartInputs(this._endPartInputs), this._isInputMode = !1, this._updateDisplayText(), this._applyErrorVisuals(!1, "", this.isDisabled());
622
- }, e.addEventListener("reset", this._resetHandler));
623
- }
624
- _clearPartInputs(e) {
625
- e.forEach((e) => {
626
- e.value = "";
627
- });
628
- }
629
- _getFieldContainerClass(e, t) {
630
- return `mint-date-fields${e ? " has-error" : ""}${t ? " is-disabled" : ""}`;
631
- }
632
- _handleInputChange(e) {}
633
- _cleanInputValue(e, t) {
634
- return e;
635
- }
636
- _handleBlur(e) {
637
- let t = this.getFormat(), n = this.getSelectionMode(), r = this._isRange || n === "week" || n === "month";
638
- if (!e) {
639
- this.setValue(""), this._updateDisplayText();
640
- return;
641
- }
642
- if (r) {
643
- let [n, r] = this._splitRangeInput(e, t), i = n ? this._parseDateString(n, t) : null, a = r ? this._parseDateString(r, t) : null;
644
- if (i && a) {
645
- let [e, n] = i <= a ? [i, a] : [a, i], r = `${this._formatDate(e, t)} - ${this._formatDate(n, t)}`;
646
- this.setValue(r), this._applyDateToParts(e, this._startPartInputs, this._getFormatTokens(t), t), this._applyDateToParts(n, this._endPartInputs, this._getFormatTokens(t), t), this._selectedStartDate = e, this._selectedEndDate = n, this._currentMonth = e.getMonth(), this._currentYear = e.getFullYear();
647
- } else if (i) {
648
- let e = this._formatDate(i, t);
649
- this.setValue(e), this._applyDateToParts(i, this._startPartInputs, this._getFormatTokens(t), t), this._applyDateToParts(null, this._endPartInputs, this._getFormatTokens(t), t), this._selectedStartDate = i, this._selectedEndDate = null, this._currentMonth = i.getMonth(), this._currentYear = i.getFullYear();
650
- } else this.setValue(""), this._applyDateToParts(null, this._startPartInputs, this._getFormatTokens(t), t), this._applyDateToParts(null, this._endPartInputs, this._getFormatTokens(t), t), this._selectedStartDate = null, this._selectedEndDate = null;
651
- } else if (this._validateDateString(e, t)) {
652
- let n = this._parseDateString(e, t);
653
- if (n) {
654
- let e = this._formatDate(n, t);
655
- this.setValue(e), this._applyDateToParts(n, this._startPartInputs, this._getFormatTokens(t), t), this._selectedStartDate = n, this._selectedEndDate = null, this._currentMonth = n.getMonth(), this._currentYear = n.getFullYear();
656
- }
657
- } else this.setValue(""), this._applyDateToParts(null, this._startPartInputs, this._getFormatTokens(t), t), this._selectedStartDate = null, this._selectedEndDate = null;
658
- }
659
- _setupPopoverWithRetry(e = 0) {
660
- if (!this._iconButton) {
661
- e < 10 && requestAnimationFrame(() => {
662
- this._setupPopoverWithRetry(e + 1);
663
- });
664
- return;
665
- }
666
- let t = this._iconButton.id;
667
- t && this._iconButton.isConnected && document.getElementById(t) ? this._createPopover(t) : e < 10 && requestAnimationFrame(() => {
668
- this._setupPopoverWithRetry(e + 1);
669
- });
670
- }
671
- _createPopover(e) {
672
- if (e) {
673
- if (!document.getElementById(e)) {
674
- setTimeout(() => {
675
- this._createPopover(e);
676
- }, 50);
677
- return;
678
- }
679
- if (this._popover) {
680
- if (this._popover.getAttribute("trigger-id") !== e) {
681
- this._popover.setAttribute("trigger-id", e);
682
- let t = this._popover;
683
- typeof t._setupTrigger == "function" && t._setupTrigger();
684
- }
685
- this._buildCalendar();
686
- } else {
687
- this._popover = document.createElement("mint-popover"), this._popover.classList.add("mint-date-picker-popover"), this._popover.setAttribute("direction", "down"), this._popover.setAttribute("padding", "0");
688
- let t = this.closest("mint-modal"), n = this.closest("mint-off-canvas");
689
- t || n ? document.body.appendChild(this._popover) : this.parentNode ? this.parentNode.insertBefore(this._popover, this.nextSibling) : document.body.appendChild(this._popover), requestAnimationFrame(() => {
690
- requestAnimationFrame(() => {
691
- this._popover && this._popover.isConnected && (this._popover.setAttribute("trigger-id", e), this._popoverObserver || (this._popoverObserver = new MutationObserver((e) => {
692
- e.forEach((e) => {
693
- if (e.type === "attributes" && e.attributeName === "open") if (this._popover?.hasAttribute("open")) requestAnimationFrame(() => {
694
- this._buildCalendar();
695
- let e = this._popover;
696
- typeof e.render == "function" && e.render(), this._setupFocusTrap();
697
- });
698
- else {
699
- if (this._removeFocusTrap(), this._iconButton && !this._iconButton.disabled && requestAnimationFrame(() => {
700
- this._iconButton?.focus();
701
- }), this._viewMode = "calendar", this._selectedStartDate) this._currentMonth = this._selectedStartDate.getMonth(), this._currentYear = this._selectedStartDate.getFullYear();
702
- else {
703
- let e = /* @__PURE__ */ new Date();
704
- this._currentMonth = e.getMonth(), this._currentYear = e.getFullYear();
705
- }
706
- requestAnimationFrame(() => {
707
- this._buildCalendar();
708
- }), this._hiddenInput && (this._syncHiddenInput(), setTimeout(() => {
709
- let e = new FocusEvent("blur", {
710
- bubbles: !0,
711
- cancelable: !0,
712
- relatedTarget: null
713
- });
714
- this._hiddenInput?.dispatchEvent(e);
715
- }, 0));
716
- }
717
- });
718
- }), this._popoverObserver.observe(this._popover, {
719
- attributes: !0,
720
- attributeFilter: ["open"]
721
- })), requestAnimationFrame(() => {
722
- this._buildCalendar();
723
- }));
724
- });
725
- });
726
- }
727
- }
728
- }
729
- _buildCalendar() {
730
- if (!this._popover) return;
731
- this._calendarContainer && this._calendarContainer.parentNode && this._calendarContainer.remove(), this._calendarContainer = document.createElement("div"), this._calendarContainer.className = "mint-date-calendar";
732
- let e = this.getMode();
733
- e === "month" && this._viewMode === "calendar" ? this._viewMode = "month" : e === "year" && this._viewMode === "calendar" ? this._viewMode = "year" : e === "default" && this._viewMode !== "month" && this._viewMode !== "year" && (this._viewMode = "calendar"), this._viewMode === "calendar" ? this._buildCalendarView() : this._viewMode === "month" ? this._buildMonthView() : this._viewMode === "year" && this._buildYearView(), this._popover.replaceChildren(this._calendarContainer);
734
- }
735
- _buildCalendarView() {
736
- if (!this._calendarContainer) return;
737
- let e = this._getDaysInMonth(this._currentMonth, this._currentYear), t = this._getFirstDayOfMonth(this._currentMonth, this._currentYear), n = [
738
- "January",
739
- "February",
740
- "March",
741
- "April",
742
- "May",
743
- "June",
744
- "July",
745
- "August",
746
- "September",
747
- "October",
748
- "November",
749
- "December"
750
- ], r = this.getWeekStartDay(), i = [
751
- "Sun",
752
- "Mon",
753
- "Tue",
754
- "Wed",
755
- "Thu",
756
- "Fri",
757
- "Sat"
758
- ], a = [...i.slice(r), ...i.slice(0, r)], o = this.getShortcuts(), s = o.length > 0;
759
- this._calendarContainer.className = `mint-date-calendar${s ? " has-shortcuts" : ""}`;
760
- let c = document.createElement("div");
761
- c.className = "mint-date-calendar-layout";
762
- let l = document.createElement("div");
763
- l.className = "mint-date-calendar-content";
764
- let u = document.createElement("div");
765
- u.className = "mint-date-calendar-header";
766
- let d = document.createElement("button");
767
- d.type = "button", d.tabIndex = 0, d.className = "mint-date-calendar-nav-button", d.setAttribute("aria-label", "Previous month"), d.setAttribute("data-keep-popover-open", "true");
768
- let f = document.createElement("mint-icon");
769
- f.setAttribute("name", "caret-left"), f.className = "mint-date-calendar-icon", d.appendChild(f), d.addEventListener("click", () => {
770
- let e = this._currentMonth, t = this._currentYear;
771
- this._currentMonth === 0 ? (this._currentMonth = 11, this._currentYear--) : this._currentMonth--, this._buildCalendar(), this._dispatchMonthChangeEvent(e, t, this._currentMonth, this._currentYear);
772
- }), u.appendChild(d);
773
- let p = document.createElement("div");
774
- p.className = "mint-date-calendar-month-year";
775
- let m = document.createElement("button");
776
- m.type = "button", m.tabIndex = 0, m.className = "mint-date-calendar-title-button", m.setAttribute("data-keep-popover-open", "true"), m.textContent = n[this._currentMonth], m.setAttribute("aria-label", `Choose month, ${n[this._currentMonth]}`);
777
- let h = () => {
778
- let e = this.getMode();
779
- e !== "month" && e !== "year" && (this._viewMode = "month", this._buildCalendar());
780
- };
781
- m.addEventListener("click", h), m.addEventListener("touchend", (e) => {
782
- e.preventDefault(), h();
783
- }, { passive: !1 }), p.appendChild(m);
784
- let g = document.createElement("button");
785
- g.type = "button", g.tabIndex = 0, g.className = "mint-date-calendar-title-button", g.setAttribute("data-keep-popover-open", "true"), g.textContent = String(this._currentYear), g.setAttribute("aria-label", `Choose year, ${this._currentYear}`), g.addEventListener("click", () => {
786
- this.getMode() !== "year" && (this._viewMode = "year", this._buildCalendar());
787
- }), p.appendChild(g), u.appendChild(p);
788
- let _ = document.createElement("button");
789
- _.type = "button", _.tabIndex = 0, _.className = "mint-date-calendar-nav-button", _.setAttribute("aria-label", "Next month"), _.setAttribute("data-keep-popover-open", "true");
790
- let v = document.createElement("mint-icon");
791
- v.setAttribute("name", "caret-right"), v.className = "mint-date-calendar-icon", _.appendChild(v);
792
- let y = () => {
793
- let e = this._currentMonth, t = this._currentYear;
794
- this._currentMonth === 11 ? (this._currentMonth = 0, this._currentYear++) : this._currentMonth++, this._buildCalendar(), this._dispatchMonthChangeEvent(e, t, this._currentMonth, this._currentYear);
795
- };
796
- _.addEventListener("click", y), _.addEventListener("touchend", (e) => {
797
- e.preventDefault(), y();
798
- }, { passive: !1 }), u.appendChild(_);
799
- let b = document.createElement("div");
800
- b.className = "mint-date-calendar-day-names", a.forEach((e) => {
801
- let t = document.createElement("div");
802
- t.className = "mint-date-calendar-day-name", t.textContent = e, b.appendChild(t);
803
- });
804
- let x = document.createElement("div");
805
- x.className = "mint-date-calendar-grid", x.setAttribute("role", "group"), x.setAttribute("aria-label", `${n[this._currentMonth]} ${this._currentYear}`);
806
- let S = this.getMin() ? this._parseDateString(this.getMin(), this.getFormat()) : null, C = this.getMax() ? this._parseDateString(this.getMax(), this.getFormat()) : null;
807
- this.getDisabledDates();
808
- let w = this._currentMonth === 0 ? 11 : this._currentMonth - 1, T = this._currentMonth === 0 ? this._currentYear - 1 : this._currentYear, E = this._getDaysInMonth(w, T), D = this._currentMonth === 11 ? 0 : this._currentMonth + 1, O = this._currentMonth === 11 ? this._currentYear + 1 : this._currentYear, k = t + e, A = Math.ceil(k / 7) * 7 - k, j = (e, t, n) => {
809
- let r = this._isToday(e), i = this._isDateSelected(e), a = this._isDateInRange(e), o = S && e < S || C && e > C || this._isDateDisabled(e), s = "is-fully-rounded", c = this._isRange && this._selectedStartDate && !this._selectedEndDate && this._hoveredDate, l = c && this._selectedStartDate && this._hoveredDate && this._selectedStartDate < this._hoveredDate ? this._selectedStartDate : c && this._hoveredDate ? this._hoveredDate : null, u = c && this._selectedStartDate && this._hoveredDate && this._selectedStartDate < this._hoveredDate ? this._hoveredDate : c && this._selectedStartDate ? this._selectedStartDate : null, d = l !== null && this._isSameDate(e, l), f = u !== null && this._isSameDate(e, u), p = this._hoveredDate !== null && this._isSameDate(e, this._hoveredDate), m = c && this._hoveredDate && this._selectedStartDate ? !this._rangeIncludesDisabledDates(this._selectedStartDate < this._hoveredDate ? this._selectedStartDate : this._hoveredDate, this._selectedStartDate < this._hoveredDate ? this._hoveredDate : this._selectedStartDate) : !1;
810
- if (this._isRange && this._selectedStartDate && this._selectedEndDate) {
811
- let t = this._isSameDate(e, this._selectedStartDate), n = this._isSameDate(e, this._selectedEndDate);
812
- t && n ? s = "is-fully-rounded" : t ? s = "is-range-start" : n ? s = "is-range-end" : a && (s = "is-range-middle");
813
- } else c && (d || f) && m ? d && f ? s = "is-fully-rounded" : d ? s = "is-range-start" : f && (s = "is-range-end") : i && !this._isRange || i && this._isRange && !this._selectedEndDate ? s = "is-fully-rounded" : a && c && m && (s = "is-range-middle");
814
- let h = document.createElement("button");
815
- h.type = "button", h.disabled = !!o, h.tabIndex = o ? -1 : 0;
816
- let g = ["mint-date-picker-day", s], _ = i || c && p && m;
817
- return n || g.push("is-outside-month"), _ && g.push("is-selected"), a && !_ && g.push("is-in-range"), r && !_ && g.push("is-today"), o && g.push("is-disabled"), h.className = g.join(" "), h.textContent = t.toString(), h.setAttribute("aria-label", e.toLocaleDateString(void 0, {
818
- weekday: "long",
819
- year: "numeric",
820
- month: "long",
821
- day: "numeric"
822
- })), h.setAttribute("aria-pressed", String(i)), r && h.setAttribute("aria-current", "date"), o || (h.addEventListener("click", (t) => {
823
- t.preventDefault(), t.stopPropagation(), this._handleDateClick(e);
824
- }), h.addEventListener("touchstart", (t) => {
825
- t.preventDefault(), t.stopPropagation(), this._isTouchActive = !0, this._touchStartDate = e, this._touchStartElement = h, h.classList.add("is-touch-active");
826
- }, { passive: !1 }), h.addEventListener("touchend", (t) => {
827
- t.preventDefault(), t.stopPropagation(), this._isTouchActive && this._touchStartDate && this._isSameDate(this._touchStartDate, e) && this._handleDateClick(e), this._touchStartElement && this._touchStartElement.classList.remove("is-touch-active"), this._isTouchActive = !1, this._touchStartDate = null, this._touchStartElement = null;
828
- }, { passive: !1 }), h.addEventListener("touchcancel", () => {
829
- this._touchStartElement && this._touchStartElement.classList.remove("is-touch-active"), this._isTouchActive = !1, this._touchStartDate = null, this._touchStartElement = null;
830
- }), this._isRange && this._selectedStartDate && !this._selectedEndDate && !o && (h.addEventListener("mouseenter", () => {
831
- this._isHandlingClick || this._isTouchActive || this._isDateDisabled(e) || (!this._hoveredDate || !this._isSameDate(this._hoveredDate, e)) && (this._hoveredDate = e, this._buildCalendar());
832
- }), h.addEventListener("touchmove", (e) => {
833
- if (!this._isTouchActive || !this._touchStartDate) return;
834
- let t = e.touches[0], n = document.elementFromPoint(t.clientX, t.clientY);
835
- for (; n && !n.classList.contains("mint-date-picker-day");) n = n.parentElement;
836
- if (n && n !== h) {
837
- let e = n.getAttribute("data-date");
838
- if (e) {
839
- let t = new Date(e);
840
- this._isDateDisabled(t) || (!this._hoveredDate || !this._isSameDate(this._hoveredDate, t)) && (this._hoveredDate = t, this._buildCalendar());
841
- }
842
- }
843
- }, { passive: !0 }))), h;
844
- };
845
- for (let e = t - 1; e >= 0; e--) {
846
- let t = E - e, n = j(new Date(T, w, t), t, !1);
847
- x.appendChild(n);
848
- }
849
- for (let t = 1; t <= e; t++) {
850
- let e = j(new Date(this._currentYear, this._currentMonth, t), t, !0);
851
- x.appendChild(e);
852
- }
853
- for (let e = 1; e <= A; e++) {
854
- let t = j(new Date(O, D, e), e, !1);
855
- x.appendChild(t);
856
- }
857
- if (this._isRange && this._selectedStartDate && !this._selectedEndDate && (x.addEventListener("mouseleave", () => {
858
- this._isTouchActive || (this._hoveredDate = null, this._buildCalendar());
859
- }), x.addEventListener("touchend", (e) => {
860
- let t = e.changedTouches[0], n = document.elementFromPoint(t.clientX, t.clientY);
861
- n && !x.contains(n) && (this._hoveredDate = null, this._buildCalendar());
862
- }, { passive: !0 })), s) {
863
- let e = document.createElement("div");
864
- e.className = "mint-date-shortcuts";
865
- let t = document.createElement("div");
866
- t.className = "mint-date-shortcuts-wrapper";
867
- let n = document.createElement("div");
868
- n.className = "mint-date-shortcuts-row";
869
- let r = document.createElement("div");
870
- r.className = "mint-date-shortcuts-fade is-horizontal is-left", t.appendChild(r);
871
- let i = document.createElement("div");
872
- i.className = "mint-date-shortcuts-fade is-horizontal is-right is-visible", t.appendChild(i);
873
- let a = document.createElement("div");
874
- a.className = "mint-date-shortcuts-fade is-vertical is-top", t.appendChild(a);
875
- let s = document.createElement("div");
876
- s.className = "mint-date-shortcuts-fade is-vertical is-bottom is-visible", t.appendChild(s);
877
- let l = () => {
878
- if (window.innerWidth >= 768) {
879
- let e = n.scrollTop, t = n.scrollHeight, o = n.clientHeight;
880
- e > 0 ? a.classList.add("is-visible") : a.classList.remove("is-visible"), e + o < t - 1 ? s.classList.add("is-visible") : s.classList.remove("is-visible"), r.classList.remove("is-visible"), i.classList.remove("is-visible");
881
- } else {
882
- let e = n.scrollLeft, t = n.scrollWidth, o = n.clientWidth;
883
- e > 0 ? r.classList.add("is-visible") : r.classList.remove("is-visible"), e + o < t - 1 ? i.classList.add("is-visible") : i.classList.remove("is-visible"), a.classList.remove("is-visible"), s.classList.remove("is-visible");
884
- }
885
- };
886
- n.addEventListener("scroll", l), window.addEventListener("resize", l), setTimeout(l, 0), o.forEach((e) => {
887
- let t = document.createElement("button");
888
- t.type = "button", t.tabIndex = 0, t.className = "mint-date-shortcut-button", t.textContent = e.label;
889
- let r = () => {
890
- let t = e.action();
891
- if (t) {
892
- if (this._isRange && "start" in t && "end" in t) {
893
- this._selectedStartDate = t.start, this._selectedEndDate = t.end;
894
- let e = this.getFormat(), n = `${this._formatDate(t.start, e)} - ${this._formatDate(t.end, e)}`;
895
- this.setValue(n), this._currentMonth = t.start.getMonth(), this._currentYear = t.start.getFullYear();
896
- } else if (t instanceof Date) {
897
- this._selectedStartDate = t, this._selectedEndDate = null;
898
- let e = this.getFormat(), n = this._formatDate(t, e);
899
- this.setValue(n), this._currentMonth = t.getMonth(), this._currentYear = t.getFullYear();
900
- }
901
- this._buildCalendar(), this._popover && typeof this._popover.close == "function" && this._popover.close(), this.dispatchEvent(new CustomEvent("input", {
902
- detail: { value: this.getValue() },
903
- bubbles: !0,
904
- cancelable: !0
905
- })), this.dispatchEvent(new CustomEvent("change", {
906
- detail: { value: this.getValue() },
907
- bubbles: !0,
908
- cancelable: !0
909
- }));
910
- }
911
- };
912
- t.addEventListener("click", r), t.addEventListener("touchend", (e) => {
913
- e.preventDefault(), r();
914
- }, { passive: !1 }), n.appendChild(t);
915
- }), t.appendChild(n), e.appendChild(t), c.appendChild(e);
916
- }
917
- l.appendChild(u), l.appendChild(b), l.appendChild(x), c.appendChild(l), this._calendarContainer.appendChild(c);
918
- }
919
- _buildMonthView() {
920
- if (!this._calendarContainer) return;
921
- let e = [
922
- "January",
923
- "February",
924
- "March",
925
- "April",
926
- "May",
927
- "June",
928
- "July",
929
- "August",
930
- "September",
931
- "October",
932
- "November",
933
- "December"
934
- ], t = document.createElement("div");
935
- t.className = "mint-date-calendar-header";
936
- let n = document.createElement("button");
937
- n.type = "button", n.tabIndex = 0, n.className = "mint-date-calendar-nav-button", n.setAttribute("data-keep-popover-open", "true");
938
- let r = document.createElement("mint-icon");
939
- r.setAttribute("name", "caret-left"), r.className = "mint-date-calendar-icon", n.appendChild(r);
940
- let i = () => {
941
- let e = this._currentMonth, t = this._currentYear;
942
- this._currentYear--, this._buildCalendar(), this._dispatchMonthChangeEvent(e, t, this._currentMonth, this._currentYear);
943
- };
944
- n.addEventListener("click", i), n.addEventListener("touchend", (e) => {
945
- e.preventDefault(), i();
946
- }, { passive: !1 }), t.appendChild(n);
947
- let a = document.createElement("button");
948
- a.type = "button", a.tabIndex = 0, a.className = "mint-date-calendar-title-button", a.setAttribute("data-keep-popover-open", "true"), a.textContent = String(this._currentYear);
949
- let o = () => {
950
- this.getMode() !== "year" && (this._viewMode = "year", this._buildCalendar());
951
- };
952
- a.addEventListener("click", o), a.addEventListener("touchend", (e) => {
953
- e.preventDefault(), o();
954
- }, { passive: !1 }), t.appendChild(a);
955
- let s = document.createElement("button");
956
- s.type = "button", s.tabIndex = 0, s.className = "mint-date-calendar-nav-button", s.setAttribute("data-keep-popover-open", "true");
957
- let c = document.createElement("mint-icon");
958
- c.setAttribute("name", "caret-right"), c.className = "mint-date-calendar-icon", s.appendChild(c);
959
- let l = () => {
960
- let e = this._currentMonth, t = this._currentYear;
961
- this._currentYear++, this._buildCalendar(), this._dispatchMonthChangeEvent(e, t, this._currentMonth, this._currentYear);
962
- };
963
- s.addEventListener("click", l), s.addEventListener("touchend", (e) => {
964
- e.preventDefault(), l();
965
- }, { passive: !1 }), t.appendChild(s);
966
- let u = document.createElement("div");
967
- u.className = "mint-date-calendar-option-grid", e.forEach((e, t) => {
968
- let n = document.createElement("button");
969
- n.type = "button", n.tabIndex = 0, this.getMode() !== "month" && n.setAttribute("data-keep-popover-open", "true"), n.className = `mint-date-calendar-option${this._currentMonth === t ? " is-selected" : ""}`, n.textContent = e;
970
- let r = () => {
971
- if (this.getMode() === "month") {
972
- let e = new Date(this._currentYear, t, 1), n = this.getFormat(), r = this._formatDate(e, n);
973
- this.setValue(r), this._selectedStartDate = e, this._selectedEndDate = null;
974
- let i = this._currentMonth, a = this._currentYear;
975
- this._currentMonth = t, this._dispatchMonthChangeEvent(i, a, this._currentMonth, this._currentYear), this.dispatchEvent(new CustomEvent("input", {
976
- detail: { value: this.getValue() },
977
- bubbles: !0,
978
- cancelable: !0
979
- })), this.dispatchEvent(new CustomEvent("change", {
980
- detail: { value: this.getValue() },
981
- bubbles: !0,
982
- cancelable: !0
983
- })), this._dispatchDateChangeEvent(), this._popover && typeof this._popover.close == "function" && this._popover.close();
984
- } else {
985
- let e = this._currentMonth, n = this._currentYear;
986
- this._currentMonth = t, this._viewMode = "calendar", this._buildCalendar(), this._dispatchMonthChangeEvent(e, n, this._currentMonth, this._currentYear);
987
- }
988
- };
989
- n.addEventListener("click", r), n.addEventListener("touchend", (e) => {
990
- e.preventDefault(), r();
991
- }, { passive: !1 }), u.appendChild(n);
992
- }), this._calendarContainer.appendChild(t), this._calendarContainer.appendChild(u);
993
- }
994
- _buildYearView() {
995
- if (!this._calendarContainer) return;
996
- let e = this._currentYear - 6, t = this._currentYear + 6, n = document.createElement("div");
997
- n.className = "mint-date-calendar-header";
998
- let r = document.createElement("button");
999
- r.type = "button", r.tabIndex = 0, r.className = "mint-date-calendar-nav-button", r.setAttribute("data-keep-popover-open", "true");
1000
- let i = document.createElement("mint-icon");
1001
- i.setAttribute("name", "caret-left"), i.className = "mint-date-calendar-icon", r.appendChild(i);
1002
- let a = () => {
1003
- let e = this._currentMonth, t = this._currentYear;
1004
- this._currentYear -= 12, this._buildCalendar(), this._dispatchMonthChangeEvent(e, t, this._currentMonth, this._currentYear);
1005
- };
1006
- r.addEventListener("click", a), r.addEventListener("touchend", (e) => {
1007
- e.preventDefault(), a();
1008
- }, { passive: !1 }), n.appendChild(r);
1009
- let o = document.createElement("div");
1010
- o.className = "mint-date-calendar-title", o.textContent = `${e} - ${t}`, n.appendChild(o);
1011
- let s = document.createElement("button");
1012
- s.type = "button", s.tabIndex = 0, s.className = "mint-date-calendar-nav-button", s.setAttribute("data-keep-popover-open", "true");
1013
- let c = document.createElement("mint-icon");
1014
- c.setAttribute("name", "caret-right"), c.className = "mint-date-calendar-icon", s.appendChild(c);
1015
- let l = () => {
1016
- let e = this._currentMonth, t = this._currentYear;
1017
- this._currentYear += 12, this._buildCalendar(), this._dispatchMonthChangeEvent(e, t, this._currentMonth, this._currentYear);
1018
- };
1019
- s.addEventListener("click", l), s.addEventListener("touchend", (e) => {
1020
- e.preventDefault(), l();
1021
- }, { passive: !1 }), n.appendChild(s);
1022
- let u = document.createElement("div");
1023
- u.className = "mint-date-calendar-option-grid";
1024
- for (let n = e; n <= t; n++) {
1025
- let e = document.createElement("button");
1026
- e.type = "button", e.tabIndex = 0, this.getMode() !== "year" && e.setAttribute("data-keep-popover-open", "true"), e.className = `mint-date-calendar-option${this._currentYear === n ? " is-selected" : ""}`, e.textContent = String(n), e.addEventListener("click", () => {
1027
- let e = this.getMode();
1028
- if (e === "year") {
1029
- let e = new Date(n, 0, 1), t = this.getFormat(), r = this._formatDate(e, t);
1030
- this.setValue(r), this._selectedStartDate = e, this._selectedEndDate = null;
1031
- let i = this._currentMonth, a = this._currentYear;
1032
- this._currentYear = n, this._currentMonth = 0, this._dispatchMonthChangeEvent(i, a, this._currentMonth, this._currentYear), this.dispatchEvent(new CustomEvent("input", {
1033
- detail: { value: this.getValue() },
1034
- bubbles: !0,
1035
- cancelable: !0
1036
- })), this.dispatchEvent(new CustomEvent("change", {
1037
- detail: { value: this.getValue() },
1038
- bubbles: !0,
1039
- cancelable: !0
1040
- })), this._dispatchDateChangeEvent(), this._popover && typeof this._popover.close == "function" && this._popover.close();
1041
- } else if (e === "month") {
1042
- let e = this._currentMonth, t = this._currentYear;
1043
- this._currentYear = n, this._viewMode = "month", this._buildCalendar(), this._dispatchMonthChangeEvent(e, t, this._currentMonth, this._currentYear);
1044
- } else {
1045
- let e = this._currentMonth, t = this._currentYear;
1046
- this._currentYear = n, this._viewMode = "calendar", this._buildCalendar(), this._dispatchMonthChangeEvent(e, t, this._currentMonth, this._currentYear);
1047
- }
1048
- }), u.appendChild(e);
1049
- }
1050
- this._calendarContainer.appendChild(n), this._calendarContainer.appendChild(u);
1051
- }
1052
- _getDaysInMonth(e, t) {
1053
- return new Date(t, e + 1, 0).getDate();
1054
- }
1055
- _getFirstDayOfMonth(e, t) {
1056
- let n = this.getWeekStartDay(), r = new Date(t, e, 1).getDay();
1057
- return r >= n ? r - n : 7 - (n - r);
1058
- }
1059
- _isToday(e) {
1060
- let t = /* @__PURE__ */ new Date();
1061
- return e.getDate() === t.getDate() && e.getMonth() === t.getMonth() && e.getFullYear() === t.getFullYear();
1062
- }
1063
- _isDateSelected(e) {
1064
- let t = this.getSelectionMode();
1065
- return this._isRange || t === "week" || t === "month" ? this._selectedStartDate && this._selectedEndDate ? this._isSameDate(e, this._selectedStartDate) || this._isSameDate(e, this._selectedEndDate) : this._isRange && this._selectedStartDate && !this._selectedEndDate ? this._isSameDate(e, this._selectedStartDate) : !1 : this._selectedStartDate !== null && this._isSameDate(e, this._selectedStartDate);
1066
- }
1067
- _isDateInRange(e) {
1068
- let t = this.getSelectionMode();
1069
- if ((this._isRange || t === "week" || t === "month") && this._selectedStartDate && this._selectedEndDate) return this._rangeIncludesDisabledDates(this._selectedStartDate, this._selectedEndDate) ? !1 : e >= this._selectedStartDate && e <= this._selectedEndDate;
1070
- if (this._isRange && this._selectedStartDate && !this._selectedEndDate && this._hoveredDate) {
1071
- let t = this._selectedStartDate < this._hoveredDate ? this._selectedStartDate : this._hoveredDate, n = this._selectedStartDate < this._hoveredDate ? this._hoveredDate : this._selectedStartDate;
1072
- if (this._rangeIncludesDisabledDates(t, n)) {
1073
- let r = this._findFirstDisabledDateInRange(t, n);
1074
- return r ? this._selectedStartDate < this._hoveredDate ? e >= t && e < r && !this._isSameDate(e, t) : e > r && e <= n && !this._isSameDate(e, n) : !1;
1075
- }
1076
- return e >= t && e <= n && !this._isSameDate(e, t) && !this._isSameDate(e, n);
1077
- }
1078
- return !1;
1079
- }
1080
- _rangeIncludesDisabledDates(e, t) {
1081
- let n = this.getDisabledDates(), r = new Date(e.getFullYear(), e.getMonth(), e.getDate()), i = new Date(t.getFullYear(), t.getMonth(), t.getDate());
1082
- return n.some((e) => {
1083
- let t = new Date(e.getFullYear(), e.getMonth(), e.getDate());
1084
- return t >= r && t <= i;
1085
- });
1086
- }
1087
- _findFirstDisabledDateInRange(e, t) {
1088
- let n = this.getDisabledDates(), r = new Date(e.getFullYear(), e.getMonth(), e.getDate()), i = new Date(t.getFullYear(), t.getMonth(), t.getDate()), a = n.map((e) => new Date(e.getFullYear(), e.getMonth(), e.getDate())).filter((e) => e >= r && e <= i).sort((e, t) => e.getTime() - t.getTime());
1089
- return a.length > 0 ? a[0] : null;
1090
- }
1091
- _hasIncompleteRange() {
1092
- return this._isRange && this._selectedStartDate !== null && this._selectedEndDate === null;
1093
- }
1094
- _isSameDate(e, t) {
1095
- return e.getDate() === t.getDate() && e.getMonth() === t.getMonth() && e.getFullYear() === t.getFullYear();
1096
- }
1097
- _isDateDisabled(e) {
1098
- return this.getDisabledDates().some((t) => this._isSameDate(e, t));
1099
- }
1100
- _dispatchMonthChangeEvent(e, t, n, r) {
1101
- (e !== n || t !== r) && this.dispatchEvent(new CustomEvent("month-change", {
1102
- detail: {
1103
- month: n,
1104
- year: r,
1105
- oldMonth: e,
1106
- oldYear: t
1107
- },
1108
- bubbles: !0,
1109
- cancelable: !0,
1110
- composed: !0
1111
- }));
1112
- }
1113
- _dispatchDateChangeEvent() {
1114
- let e = this.getFormat(), t = { value: this.getValue() };
1115
- this._selectedStartDate && (t.startDate = this._selectedStartDate, t.startDateFormatted = this._formatDate(this._selectedStartDate, e)), this._selectedEndDate && (t.endDate = this._selectedEndDate, t.endDateFormatted = this._formatDate(this._selectedEndDate, e)), this.dispatchEvent(new CustomEvent("date-change", {
1116
- detail: t,
1117
- bubbles: !0,
1118
- cancelable: !0,
1119
- composed: !0
1120
- }));
1121
- }
1122
- _setupContainerObserver() {
1123
- if (this._resizeObserver &&= (this._resizeObserver.disconnect(), null), !this._inputsWrapperEl) return;
1124
- let e = (e) => {
1125
- this._inputsWrapperEl && (e < 400 ? (this._inputsWrapperEl.classList.add("is-wrapping"), this._inputsWrapperEl.classList.remove("is-nowrap")) : (this._inputsWrapperEl.classList.remove("is-wrapping"), this._inputsWrapperEl.classList.add("is-nowrap")));
1126
- };
1127
- e(this._inputsWrapperEl.offsetWidth || this.offsetWidth), this._resizeObserver = new ResizeObserver((t) => {
1128
- for (let n of t) {
1129
- let t = n.contentRect.width;
1130
- e(t);
1131
- }
1132
- }), this._resizeObserver.observe(this);
1133
- }
1134
- _getWeekStart(e) {
1135
- let t = this.getWeekStartDay(), n = e.getDay(), r;
1136
- r = n >= t ? n - t : 7 - (t - n);
1137
- let i = new Date(e);
1138
- return i.setDate(e.getDate() - r), i.setHours(0, 0, 0, 0), i;
1139
- }
1140
- _getWeekEnd(e) {
1141
- let t = this._getWeekStart(e), n = new Date(t);
1142
- return n.setDate(t.getDate() + 6), n.setHours(23, 59, 59, 999), n;
1143
- }
1144
- _getMonthStart(e) {
1145
- let t = new Date(e.getFullYear(), e.getMonth(), 1);
1146
- return t.setHours(0, 0, 0, 0), t;
1147
- }
1148
- _getMonthEnd(e) {
1149
- let t = new Date(e.getFullYear(), e.getMonth() + 1, 0);
1150
- return t.setHours(23, 59, 59, 999), t;
1151
- }
1152
- _handleDateClick(e) {
1153
- this._isHandlingClick = !0;
1154
- try {
1155
- let t = this.getFormat(), n = this.getSelectionMode(), r, i;
1156
- if (n === "week" ? (r = this._getWeekStart(e), i = this._getWeekEnd(e)) : n === "month" ? (r = this._getMonthStart(e), i = this._getMonthEnd(e)) : (r = e, i = e), this.isRange() || n === "week" || n === "month") if (n === "week" || n === "month") {
1157
- if (this._rangeIncludesDisabledDates(r, i)) {
1158
- this._buildCalendar();
1159
- return;
1160
- }
1161
- this._selectedStartDate = r, this._selectedEndDate = i;
1162
- let e = `${this._formatDate(this._selectedStartDate, t)} - ${this._formatDate(this._selectedEndDate, t)}`;
1163
- this.setValue(e), this._textInput && (this._textInput.value = e), this._popover && typeof this._popover.close == "function" && this._popover.close();
1164
- } else if (this._hoveredDate = null, this._selectedStartDate === null) {
1165
- if (this._isDateDisabled(r)) {
1166
- this._buildCalendar();
1167
- return;
1168
- }
1169
- this._selectedStartDate = new Date(r.getFullYear(), r.getMonth(), r.getDate()), this._selectedEndDate = null, this._currentMonth = this._selectedStartDate.getMonth(), this._currentYear = this._selectedStartDate.getFullYear(), this._hoveredDate = null, this._buildCalendar();
1170
- } else if (this._selectedEndDate === null) {
1171
- let n = new Date(e.getFullYear(), e.getMonth(), e.getDate()), r = this._selectedStartDate ? new Date(this._selectedStartDate.getFullYear(), this._selectedStartDate.getMonth(), this._selectedStartDate.getDate()) : null, i, a;
1172
- if (r && n < r ? (i = n, a = r) : (i = r, a = n), this._rangeIncludesDisabledDates(i, a)) {
1173
- this._buildCalendar();
1174
- return;
1175
- }
1176
- r && n < r ? (this._selectedEndDate = r, this._selectedStartDate = n) : (this._selectedEndDate = n, r && (this._selectedStartDate = r)), this._currentMonth = this._selectedStartDate.getMonth(), this._currentYear = this._selectedStartDate.getFullYear();
1177
- let o = `${this._formatDate(this._selectedStartDate, t)} - ${this._formatDate(this._selectedEndDate, t)}`;
1178
- this.setAttribute("value", o), this._textInput && (this._textInput.value = o), this._hiddenInput && (this._hiddenInput.value = o), this._updateDisplayText(), this._buildCalendar(), this._popover && typeof this._popover.close == "function" && this._popover.close();
1179
- } else this._selectedStartDate = r, this._selectedEndDate = null;
1180
- else {
1181
- this._selectedStartDate = r, this._selectedEndDate = null;
1182
- let e = this._formatDate(r, t);
1183
- this.setValue(e), this._textInput && (this._textInput.value = e), this._popover && typeof this._popover.close == "function" && this._popover.close();
1184
- }
1185
- this._buildCalendar(), this._updateDisplayText(), this._exitInputMode();
1186
- let a = new Event("input", {
1187
- bubbles: !0,
1188
- cancelable: !0,
1189
- composed: !0
1190
- });
1191
- this.dispatchEvent(a), this.dispatchEvent(new CustomEvent("input", {
1192
- detail: { value: this.getValue() },
1193
- bubbles: !0,
1194
- cancelable: !0,
1195
- composed: !0
1196
- })), this.dispatchEvent(new CustomEvent("change", {
1197
- detail: { value: this.getValue() },
1198
- bubbles: !0,
1199
- cancelable: !0,
1200
- composed: !0
1201
- })), this._dispatchDateChangeEvent();
1202
- } finally {
1203
- this._isHandlingClick = !1;
1204
- }
1205
- }
1206
- _updateDisplayText() {
1207
- if (!this._displayEl) return;
1208
- let e = this.getDisplayFormat(), t = this.getSelectionMode(), n = this._isRange || t === "week" || t === "month", r = "";
1209
- n && this._selectedStartDate && this._selectedEndDate ? r = `${this._formatDatePhp(this._selectedStartDate, e)} - ${this._formatDatePhp(this._selectedEndDate, e)}` : this._selectedStartDate && (r = this._formatDatePhp(this._selectedStartDate, e)), r ? (this._displayEl.textContent = r, this._displayEl.classList.remove("is-empty")) : (this._displayEl.textContent = "Select date", this._displayEl.classList.add("is-empty")), this._displayEl && this._inputsWrapperEl && this.classList.toggle("is-input-mode", this._isInputMode);
1210
- }
1211
- _enterInputMode() {
1212
- if (!this._isInputMode && !(this.isReadonly() || this.isDisabled()) && (this._isInputMode = !0, this._displayEl && this._inputsWrapperEl && this.classList.add("is-input-mode"), this._startPartInputs.length > 0)) {
1213
- let e = this._startPartInputs[0];
1214
- requestAnimationFrame(() => {
1215
- e.focus();
1216
- try {
1217
- e.setSelectionRange(0, e.value.length);
1218
- } catch {}
1219
- });
1220
- }
1221
- }
1222
- _exitInputMode() {
1223
- this._isInputMode && (this._isInputMode = !1, this._displayEl && this._inputsWrapperEl && this.classList.remove("is-input-mode"), this._updateDisplayText());
1224
- }
1225
- _renderSkeleton(e) {
1226
- let t = this.querySelector(".mint-date-picker-skeleton-container");
1227
- this._fieldsContainer;
1228
- let n = this._input;
1229
- if (e) {
1230
- t || (t = document.createElement("div"), t.className = "mint-date-picker-skeleton-container", n ? n.appendChild(t) : (this.classList.add("is-positioned"), this.appendChild(t)));
1231
- let e = t.querySelector(".mint-date-picker-skeleton");
1232
- e || (e = document.createElement("div"), e.className = "mint-date-picker-skeleton", t.appendChild(e)), this.classList.add("is-loading");
1233
- } else t?.remove(), this.classList.remove("is-loading", "is-positioned");
1234
- }
1235
- _getFocusableElements() {
1236
- if (!this._calendarContainer) return [];
1237
- let e = [
1238
- "button:not([disabled])",
1239
- "a[href]",
1240
- "input:not([disabled]):not([type=\"hidden\"])",
1241
- "select:not([disabled])",
1242
- "textarea:not([disabled])",
1243
- "[tabindex]:not([tabindex=\"-1\"])"
1244
- ].join(", ");
1245
- return Array.from(this._calendarContainer.querySelectorAll(e)).filter((e) => {
1246
- let t = window.getComputedStyle(e);
1247
- return t.display !== "none" && t.visibility !== "hidden";
1248
- });
1249
- }
1250
- _setupFocusTrap() {
1251
- if (!this._popover || !this._popover.hasAttribute("open")) return;
1252
- this._removeFocusTrap();
1253
- let e = this;
1254
- this._focusTrapHandler = function(t) {
1255
- if (t.key !== "Tab") return;
1256
- if (!e._popover || !e._popover.hasAttribute("open")) {
1257
- e._removeFocusTrap();
1258
- return;
1259
- }
1260
- let n = e._getFocusableElements();
1261
- if (n.length === 0) return;
1262
- let r = n[0], i = n[n.length - 1], a = document.activeElement;
1263
- if (!e._calendarContainer?.contains(a)) {
1264
- t.preventDefault(), r.focus();
1265
- return;
1266
- }
1267
- if (t.shiftKey && a === r) {
1268
- t.preventDefault(), i.focus();
1269
- return;
1270
- }
1271
- if (!t.shiftKey && a === i) {
1272
- t.preventDefault(), r.focus();
1273
- return;
1274
- }
1275
- }, this._escapeHandler = function(t) {
1276
- (t.key === "Escape" || t.key === "Esc") && e._popover && e._popover.hasAttribute("open") && (t.preventDefault(), t.stopPropagation(), typeof e._popover.close == "function" && e._popover.close());
1277
- }, document.addEventListener("keydown", this._focusTrapHandler, !0), document.addEventListener("keydown", this._escapeHandler, !0), requestAnimationFrame(() => {
1278
- let e = this._getFocusableElements();
1279
- e.length > 0 && e[0].focus();
1280
- });
1281
- }
1282
- _removeFocusTrap() {
1283
- this._focusTrapHandler &&= (document.removeEventListener("keydown", this._focusTrapHandler, !0), null), this._escapeHandler &&= (document.removeEventListener("keydown", this._escapeHandler, !0), null);
1284
- }
1285
- };
1286
- customElements.get("mint-date-picker") || t("mint-date-picker", n);
1287
- //#endregion
1288
- export { n as default };
19
+ import { t as e } from "../chunks/date-picker-BQsCoKaK.js";
20
+ export { e as default };