@tabworthy/components 0.2.0

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 (84) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +69 -0
  3. package/dist/cjs/app-globals-V2Kpy_OQ.js +5 -0
  4. package/dist/cjs/index-C15oswCE.js +2148 -0
  5. package/dist/cjs/index.cjs.js +2 -0
  6. package/dist/cjs/loader.cjs.js +13 -0
  7. package/dist/cjs/moment-CdViwxPQ.js +5681 -0
  8. package/dist/cjs/tabworthy-components.cjs.js +25 -0
  9. package/dist/cjs/tabworthy-dates-calendar_2.cjs.entry.js +884 -0
  10. package/dist/cjs/tabworthy-dates.cjs.entry.js +10906 -0
  11. package/dist/cjs/tabworthy-times-picker.cjs.entry.js +181 -0
  12. package/dist/cjs/tabworthy-times.cjs.entry.js +242 -0
  13. package/dist/cjs/utils-y5Vtky2t.js +214 -0
  14. package/dist/collection/collection-manifest.json +16 -0
  15. package/dist/collection/components/tabworthy-dates/tabworthy-dates.css +10 -0
  16. package/dist/collection/components/tabworthy-dates/tabworthy-dates.js +1197 -0
  17. package/dist/collection/components/tabworthy-dates-calendar/tabworthy-dates-calendar.css +10 -0
  18. package/dist/collection/components/tabworthy-dates-calendar/tabworthy-dates-calendar.js +986 -0
  19. package/dist/collection/components/tabworthy-modal/tabworthy-dates-modal.css +14 -0
  20. package/dist/collection/components/tabworthy-modal/tabworthy-dates-modal.js +237 -0
  21. package/dist/collection/components/tabworthy-times/tabworthy-times.js +832 -0
  22. package/dist/collection/components/tabworthy-times-picker/tabworthy-times-picker.js +356 -0
  23. package/dist/collection/index.js +1 -0
  24. package/dist/components/index.d.ts +35 -0
  25. package/dist/components/index.js +1 -0
  26. package/dist/components/moment.js +8 -0
  27. package/dist/components/tabworthy-dates-calendar.d.ts +11 -0
  28. package/dist/components/tabworthy-dates-calendar.js +1 -0
  29. package/dist/components/tabworthy-dates-calendar2.js +1 -0
  30. package/dist/components/tabworthy-dates-modal.d.ts +11 -0
  31. package/dist/components/tabworthy-dates-modal.js +1 -0
  32. package/dist/components/tabworthy-dates-modal2.js +1 -0
  33. package/dist/components/tabworthy-dates.d.ts +11 -0
  34. package/dist/components/tabworthy-dates.js +1 -0
  35. package/dist/components/tabworthy-times-picker.d.ts +11 -0
  36. package/dist/components/tabworthy-times-picker.js +1 -0
  37. package/dist/components/tabworthy-times-picker2.js +1 -0
  38. package/dist/components/tabworthy-times.d.ts +11 -0
  39. package/dist/components/tabworthy-times.js +1 -0
  40. package/dist/esm/app-globals-DQuL1Twl.js +3 -0
  41. package/dist/esm/index-BusoZVTR.js +2139 -0
  42. package/dist/esm/index.js +1 -0
  43. package/dist/esm/loader.js +11 -0
  44. package/dist/esm/moment-Mki5YqAR.js +5679 -0
  45. package/dist/esm/tabworthy-components.js +21 -0
  46. package/dist/esm/tabworthy-dates-calendar_2.entry.js +881 -0
  47. package/dist/esm/tabworthy-dates.entry.js +10904 -0
  48. package/dist/esm/tabworthy-times-picker.entry.js +179 -0
  49. package/dist/esm/tabworthy-times.entry.js +240 -0
  50. package/dist/esm/utils-BVHu5CWV.js +188 -0
  51. package/dist/index.cjs.js +1 -0
  52. package/dist/index.js +1 -0
  53. package/dist/loader/cdn.js +1 -0
  54. package/dist/loader/index.cjs.js +1 -0
  55. package/dist/loader/index.d.ts +24 -0
  56. package/dist/loader/index.es2017.js +1 -0
  57. package/dist/loader/index.js +2 -0
  58. package/dist/shared/utils/chrono-parser/chrono-parser.js +146 -0
  59. package/dist/shared/utils/chrono-parser/chrono-parser.type.js +1 -0
  60. package/dist/shared/utils/utils.js +186 -0
  61. package/dist/tabworthy-components/index.esm.js +0 -0
  62. package/dist/tabworthy-components/p-170bc6ca.entry.js +1 -0
  63. package/dist/tabworthy-components/p-3ce9a767.entry.js +1 -0
  64. package/dist/tabworthy-components/p-77bd1bd4.entry.js +1 -0
  65. package/dist/tabworthy-components/p-BVHu5CWV.js +1 -0
  66. package/dist/tabworthy-components/p-BusoZVTR.js +2 -0
  67. package/dist/tabworthy-components/p-DQuL1Twl.js +1 -0
  68. package/dist/tabworthy-components/p-Mki5YqAR.js +8 -0
  69. package/dist/tabworthy-components/p-ebbb4c46.entry.js +1 -0
  70. package/dist/tabworthy-components/tabworthy-components.esm.js +1 -0
  71. package/dist/themes/dark.css +1 -0
  72. package/dist/themes/light.css +1 -0
  73. package/dist/types/Users/damirbogdanov_1/work/tabworthy-components/.stencil/shared/utils/chrono-parser/chrono-parser.d.ts +3 -0
  74. package/dist/types/Users/damirbogdanov_1/work/tabworthy-components/.stencil/shared/utils/chrono-parser/chrono-parser.type.d.ts +40 -0
  75. package/dist/types/Users/damirbogdanov_1/work/tabworthy-components/.stencil/shared/utils/utils.d.ts +28 -0
  76. package/dist/types/components/tabworthy-dates/tabworthy-dates.d.ts +80 -0
  77. package/dist/types/components/tabworthy-dates-calendar/tabworthy-dates-calendar.d.ts +89 -0
  78. package/dist/types/components/tabworthy-modal/tabworthy-dates-modal.d.ts +29 -0
  79. package/dist/types/components/tabworthy-times/tabworthy-times.d.ts +65 -0
  80. package/dist/types/components/tabworthy-times-picker/tabworthy-times-picker.d.ts +46 -0
  81. package/dist/types/components.d.ts +879 -0
  82. package/dist/types/index.d.ts +1 -0
  83. package/dist/types/stencil-public-runtime.d.ts +1858 -0
  84. package/package.json +132 -0
@@ -0,0 +1,146 @@
1
+ import * as chrono from "chrono-node";
2
+ import { dateIsWithinBounds, dateIsWithinLowerBounds, dateIsWithinUpperBounds, extractDates, isValidISODate, removeTimezoneOffset } from "../utils";
3
+ const supportedChronoLocales = ["en", "fr", "ru", "pt", "ja", "nl"];
4
+ export const chronoParseDate = async (dateString, options) => {
5
+ // Assign default values if no options object provided
6
+ if (!options) {
7
+ options = {
8
+ referenceDate: removeTimezoneOffset(new Date()),
9
+ useStrict: false,
10
+ locale: "en",
11
+ customExpressions: [],
12
+ minDate: undefined,
13
+ maxDate: undefined
14
+ };
15
+ }
16
+ // Destructure options object
17
+ let { referenceDate = removeTimezoneOffset(new Date()), useStrict = false, locale = "en", customExpressions = [], minDate = undefined, maxDate = undefined } = options;
18
+ const chronoSupportedLocale = supportedChronoLocales.includes(locale);
19
+ // Return if Chrono is not supported
20
+ if (!chronoSupportedLocale) {
21
+ if (isValidISODate(dateString))
22
+ return { value: removeTimezoneOffset(new Date(dateString)) };
23
+ else
24
+ return null;
25
+ }
26
+ const custom = chrono[locale].casual.clone();
27
+ customExpressions.forEach((expression) => custom.parsers.push({
28
+ pattern: () => expression.pattern,
29
+ extract: () => {
30
+ return expression.match;
31
+ }
32
+ }));
33
+ let parsedDate;
34
+ if (useStrict)
35
+ parsedDate = await chrono[locale].strict.parseDate(dateString, {
36
+ instant: referenceDate,
37
+ timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
38
+ }, {
39
+ forwardDate: true
40
+ });
41
+ else {
42
+ parsedDate = await custom.parseDate(dateString, {
43
+ instant: referenceDate,
44
+ timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
45
+ }, {
46
+ forwardDate: true
47
+ });
48
+ }
49
+ if (parsedDate instanceof Date) {
50
+ if (dateIsWithinBounds(parsedDate, minDate, maxDate))
51
+ return { value: parsedDate };
52
+ else if (parsedDate instanceof Date &&
53
+ !dateIsWithinLowerBounds(parsedDate, minDate)) {
54
+ return { value: null, reason: "minDate" };
55
+ }
56
+ else if (parsedDate instanceof Date &&
57
+ !dateIsWithinUpperBounds(parsedDate, maxDate)) {
58
+ return { value: null, reason: "maxDate" };
59
+ }
60
+ }
61
+ else
62
+ return { value: null, reason: "invalid" };
63
+ };
64
+ export const chronoParseRange = async (dateString, options) => {
65
+ var _a;
66
+ // Assign default values if no options object provided
67
+ if (!options) {
68
+ options = {
69
+ referenceDate: removeTimezoneOffset(new Date()),
70
+ useStrict: false,
71
+ locale: "en",
72
+ customExpressions: [],
73
+ minDate: undefined,
74
+ maxDate: undefined
75
+ };
76
+ }
77
+ // Destructure options object
78
+ let { referenceDate = removeTimezoneOffset(new Date()), useStrict = false, locale = "en", customExpressions = [], minDate = undefined, maxDate = undefined } = options;
79
+ const chronoSupportedLocale = supportedChronoLocales.includes(locale);
80
+ // Return if Chrono is not supported
81
+ if (!chronoSupportedLocale) {
82
+ const possibleDates = extractDates(dateString);
83
+ possibleDates === null || possibleDates === void 0 ? void 0 : possibleDates.filter((dateString) => isValidISODate(dateString));
84
+ if ((possibleDates || []).length > 0)
85
+ return {
86
+ value: {
87
+ start: removeTimezoneOffset(new Date(possibleDates === null || possibleDates === void 0 ? void 0 : possibleDates[0])),
88
+ end: (possibleDates === null || possibleDates === void 0 ? void 0 : possibleDates[1])
89
+ ? removeTimezoneOffset(new Date(possibleDates[1]))
90
+ : undefined
91
+ }
92
+ };
93
+ else
94
+ return null;
95
+ }
96
+ const custom = chrono[locale].casual.clone();
97
+ customExpressions.forEach((expression) => custom.parsers.push({
98
+ pattern: () => expression.pattern,
99
+ extract: () => {
100
+ return expression.match;
101
+ }
102
+ }));
103
+ let parsedRange;
104
+ if (useStrict)
105
+ parsedRange = await chrono[locale].strict.parse(dateString, {
106
+ instant: referenceDate,
107
+ timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
108
+ }, {
109
+ forwardDate: true
110
+ });
111
+ else {
112
+ parsedRange = custom.parse(dateString, {
113
+ instant: referenceDate,
114
+ timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
115
+ }, {
116
+ forwardDate: true
117
+ });
118
+ }
119
+ let startDate;
120
+ let endDate;
121
+ if (parsedRange.length > 0 &&
122
+ parsedRange[0].start &&
123
+ parsedRange[0].start.date() instanceof Date)
124
+ startDate = parsedRange[0].start.date();
125
+ if (parsedRange.length > 0 &&
126
+ parsedRange[0].end &&
127
+ parsedRange[0].end.date() instanceof Date)
128
+ endDate = parsedRange[0].end.date();
129
+ const returnValue = { value: { start: null, end: null } };
130
+ // TODO: fix this
131
+ // @ts-ignore
132
+ if (startDate instanceof Date || endDate instanceof Date) {
133
+ // @ts-ignore
134
+ if (startDate && dateIsWithinBounds(startDate, minDate, maxDate))
135
+ returnValue.value.start = startDate;
136
+ // @ts-ignore
137
+ if (endDate && dateIsWithinBounds(endDate, minDate, maxDate))
138
+ returnValue.value.end = endDate;
139
+ if (((_a = returnValue.value) === null || _a === void 0 ? void 0 : _a.start) !== null || returnValue.value.end !== null)
140
+ return returnValue;
141
+ else
142
+ return { value: null, reason: "rangeOutOfBounds" };
143
+ }
144
+ else
145
+ return { value: null, reason: "invalid" };
146
+ };
@@ -0,0 +1,186 @@
1
+ export function addDays(date, days) {
2
+ const newDate = new Date(date);
3
+ newDate.setDate(newDate.getDate() + days);
4
+ return newDate;
5
+ }
6
+ export function getDaysOfMonth(date, padded, firstDayOfWeek) {
7
+ const days = [];
8
+ const firstOfMonth = getFirstOfMonth(date);
9
+ const firstDayMonth = firstOfMonth.getDay() === 0 ? 7 : firstOfMonth.getDay();
10
+ const lastOfMonth = getLastOfMonth(date);
11
+ const lastDayOfMonth = lastOfMonth.getDay() === 0 ? 7 : lastOfMonth.getDay();
12
+ const lastDayOfWeek = firstDayOfWeek === 1 ? 7 : firstDayOfWeek - 1;
13
+ const leftPaddingDays = [];
14
+ const rightPaddingDays = [];
15
+ if (padded) {
16
+ const leftPadding = (7 - firstDayOfWeek + firstDayMonth) % 7;
17
+ let leftPaddingAmount = leftPadding;
18
+ let leftPaddingDay = getPreviousDay(firstOfMonth);
19
+ while (leftPaddingAmount > 0) {
20
+ leftPaddingDays.push(leftPaddingDay);
21
+ leftPaddingDay = getPreviousDay(leftPaddingDay);
22
+ leftPaddingAmount -= 1;
23
+ }
24
+ leftPaddingDays.reverse();
25
+ const rightPadding = (7 - lastDayOfMonth + lastDayOfWeek) % 7;
26
+ let rightPaddingAmount = rightPadding;
27
+ let rightPaddingDay = getNextDay(lastOfMonth);
28
+ while (rightPaddingAmount > 0) {
29
+ rightPaddingDays.push(rightPaddingDay);
30
+ rightPaddingDay = getNextDay(rightPaddingDay);
31
+ rightPaddingAmount -= 1;
32
+ }
33
+ }
34
+ let currentDay = firstOfMonth;
35
+ while (currentDay.getMonth() === date.getMonth()) {
36
+ days.push(currentDay);
37
+ currentDay = getNextDay(currentDay);
38
+ }
39
+ return [...leftPaddingDays, ...days, ...rightPaddingDays];
40
+ }
41
+ export function getFirstOfMonth(date) {
42
+ const firstOfMonth = removeTimezoneOffset(new Date(`${getYear(date)}-${String(getMonth(date)).padStart(2, "0")}-01`));
43
+ return firstOfMonth;
44
+ }
45
+ function getISODateStringHistoricalImplementation(date) {
46
+ if (!(date instanceof Date)) {
47
+ return;
48
+ }
49
+ return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}-${String(date.getDate()).padStart(2, "0")}`;
50
+ }
51
+ export function getISODateString(date) {
52
+ // this is a lie, but can have unpredictable issues because heavily used,
53
+ // so atm keeping historical implementation, until better test coverage and confidence is achieved
54
+ return getISODateStringHistoricalImplementation(date);
55
+ }
56
+ export function getLastOfMonth(date) {
57
+ const newDate = getFirstOfMonth(date);
58
+ newDate.setMonth(newDate.getMonth() + 1);
59
+ newDate.setDate(newDate.getDate() - 1);
60
+ return newDate;
61
+ }
62
+ export function getMonth(date) {
63
+ return date.getMonth() + 1;
64
+ }
65
+ export function getMonths(locale) {
66
+ return new Array(12).fill(undefined).map((_, month) => {
67
+ const date = removeTimezoneOffset(new Date(`2006-${String(month + 1).padStart(2, "0")}-01`));
68
+ return Intl.DateTimeFormat(locale, {
69
+ month: "long"
70
+ }).format(date);
71
+ });
72
+ }
73
+ export function getNextDay(date) {
74
+ return addDays(date, 1);
75
+ }
76
+ export function getNextMonth(date) {
77
+ const newDate = new Date(date);
78
+ newDate.setMonth(newDate.getMonth() + 1);
79
+ return newDate;
80
+ }
81
+ export function getNextYear(date) {
82
+ const newDate = new Date(date);
83
+ newDate.setFullYear(newDate.getFullYear() + 1);
84
+ return newDate;
85
+ }
86
+ export function getPreviousDay(date) {
87
+ return subDays(date, 1);
88
+ }
89
+ export function getPreviousMonth(date) {
90
+ const newDate = new Date(date);
91
+ newDate.setMonth(newDate.getMonth() - 1);
92
+ return newDate;
93
+ }
94
+ export function getPreviousYear(date) {
95
+ const newDate = new Date(date);
96
+ newDate.setFullYear(newDate.getFullYear() - 1);
97
+ return newDate;
98
+ }
99
+ export function getWeekDays(firstDayOfWeek, locale) {
100
+ return new Array(7)
101
+ .fill(undefined)
102
+ .map((_, index) => ((firstDayOfWeek + index) % 7) + 1)
103
+ .map((day) => {
104
+ const date = new Date(2006, 0, day);
105
+ return [
106
+ Intl.DateTimeFormat(locale, {
107
+ weekday: "short"
108
+ }).format(date),
109
+ Intl.DateTimeFormat(locale, {
110
+ weekday: "long"
111
+ }).format(date)
112
+ ];
113
+ });
114
+ }
115
+ export function getYear(date) {
116
+ return date.getFullYear();
117
+ }
118
+ export function isDateInRange(date, range) {
119
+ if (!date || !range || !range.from || !range.to) {
120
+ return false;
121
+ }
122
+ const earlyDate = range.from < range.to ? range.from : range.to;
123
+ const laterDate = range.from < range.to ? range.to : range.from;
124
+ return date >= earlyDate && date <= laterDate;
125
+ }
126
+ export function isSameDay(date1, date2) {
127
+ if (!date1 || !date2) {
128
+ return false;
129
+ }
130
+ return (date1.getFullYear() === date2.getFullYear() &&
131
+ date1.getMonth() === date2.getMonth() &&
132
+ date1.getDate() === date2.getDate());
133
+ }
134
+ export function removeTimezoneOffset(date) {
135
+ const newDate = new Date(date);
136
+ newDate.setMinutes(newDate.getMinutes() + newDate.getTimezoneOffset());
137
+ return newDate;
138
+ }
139
+ export function subDays(date, days) {
140
+ const newDate = new Date(date);
141
+ newDate.setDate(newDate.getDate() - days);
142
+ return newDate;
143
+ }
144
+ export function dateIsWithinLowerBounds(date, minDate) {
145
+ if (minDate) {
146
+ const min = removeTimezoneOffset(new Date(minDate));
147
+ return date >= min || isSameDay(min, date);
148
+ }
149
+ else
150
+ return true;
151
+ }
152
+ export function dateIsWithinUpperBounds(date, maxDate) {
153
+ if (maxDate) {
154
+ const max = removeTimezoneOffset(new Date(maxDate));
155
+ return date <= max || isSameDay(date, max);
156
+ }
157
+ else
158
+ return true;
159
+ }
160
+ export function dateIsWithinBounds(date, minDate, maxDate) {
161
+ return (dateIsWithinLowerBounds(date, minDate) &&
162
+ dateIsWithinUpperBounds(date, maxDate));
163
+ }
164
+ export function monthIsDisabled(month, year, minDate, maxDate) {
165
+ const firstDate = new Date(year, month, 1);
166
+ firstDate.setDate(firstDate.getDate() - 1);
167
+ const lastDate = new Date(year, month + 1, 0);
168
+ lastDate.setDate(firstDate.getDate() + 1);
169
+ return (!dateIsWithinBounds(firstDate, minDate, maxDate) &&
170
+ !dateIsWithinBounds(lastDate, minDate, maxDate));
171
+ }
172
+ export function isValidISODate(dateString) {
173
+ var isoFormat = /^\d{4}-\d{2}-\d{2}$/;
174
+ if (dateString.match(isoFormat) == null) {
175
+ return false;
176
+ }
177
+ else {
178
+ var d = new Date(dateString);
179
+ return !isNaN(d.getTime());
180
+ }
181
+ }
182
+ export function extractDates(text) {
183
+ var dateRegex = /\d{4}-\d{2}-\d{2}/g;
184
+ var matches = text.match(dateRegex);
185
+ return matches === null || matches === void 0 ? void 0 : matches.slice(0, 2);
186
+ }
File without changes
@@ -0,0 +1 @@
1
+ import{r as t,c as s,h as i,H as e,g as h}from"./p-BusoZVTR.js";import{h as a}from"./p-Mki5YqAR.js";import{g as r,r as o}from"./p-BVHu5CWV.js";const n={selected:"selected",openCalendar:"Open date and time picker",calendar:"date and time picker",invalidDateError:"We could not find a matching date",minDateError:"Please fill in a date after ",maxDateError:"Please fill in a date before ",rangeOutOfBoundsError:"Please enter a valid range of dates",disabledDateError:"Please choose an available date",to:"to",startDate:"Start date",timeLabel:"Time"},d=class{constructor(i){t(this,i),this.selectDateTime=s(this,"selectDateTime"),this.changeYear=s(this,"changeYear"),this.componentReady=s(this,"componentReady"),this.range=!1,this.label="Choose a date and time",this.placeholder="",this.locale=(null===navigator||void 0===navigator?void 0:navigator.language)||"en-US",this.disabled=!1,this.startDate=r(new Date),this.referenceDate=r(new Date),this.use12HourFormat=!0,this.timesLabels=n,this.inline=!1,this.hasError=!1,this.showYearStepper=!1,this.showMonthStepper=!0,this.showClearButton=!0,this.showTodayButton=!0,this.disableDate=()=>!1,this.elementClassName="tabworthy-times",this.firstDayOfWeek=1,this.format="YYYY-MM-DDTHH:mm:ss",this.selectedHours=12,this.selectedMinutes=0,this.errorState=this.hasError,this.disabledState=this.disabled,this.errorMessage="",this.handlePickerSelection=async t=>{const s=t.split(",");if(this.range&&2===s.length){const t=o(new Date(s[0])),i=o(new Date(s[1]));this.updateValue([t,i]),this.pickerRef&&(this.pickerRef.value=[t,i])}else{const t=o(new Date(s[0]));this.updateValue(t),this.pickerRef&&(this.pickerRef.value=t)}},this.handleTimeChange=t=>{this.selectedHours=t.detail.hours,this.selectedMinutes=t.detail.minutes,this.selectedDate&&this.updateValue(this.selectedDate)},this.handleCalendarButtonClick=async()=>{this.modalRef&&(await this.modalRef.setTriggerElement(this.calendarButtonRef),await this.modalRef.open())},this.handleYearChange=t=>{this.changeYear&&this.changeYear.emit(t)},this.handleChangedMonths=()=>{},this.handleInputBlur=()=>{this.formatInput()},this.handleInputChange=t=>{const s=a(t.target.value);s.isValid()&&(this.selectedHours=s.hours(),this.selectedMinutes=s.minutes(),this.updateValue(s.toDate()))}}watchValue(t){this.syncFromValueProp()}watchDisabled(t){this.disabledState=t}watchHasError(t){this.errorState=t}componentDidLoad(){this.syncFromValueProp(),this.componentReady.emit(),this.id||console.error('tabworthy-times: The "id" prop is required for accessibility')}syncFromValueProp(){if(this.value){this.internalValue=this.value;const t=Array.isArray(this.value)?this.value[0]:this.value;if(t){const s=a(t,this.format);s.isValid()&&(this.selectedDate=s.toDate(),this.selectedHours=s.hours(),this.selectedMinutes=s.minutes())}}else this.internalValue=null}updateValue(t){if(Array.isArray(t)){const s=t.map((t=>{const s=a(t);return s.hours(this.selectedHours),s.minutes(this.selectedMinutes),s.seconds(0),s.format(this.format)}));this.internalValue=s,this.value=s,this.selectDateTime.emit(s)}else{const s=a(t);s.hours(this.selectedHours),s.minutes(this.selectedMinutes),s.seconds(0);const i=s.format(this.format);this.internalValue=i,this.value=i,this.selectedDate=t,this.selectDateTime.emit(i)}this.errorState=!1,this.formatInput()}formatInput(){if(this.internalValue)if(Array.isArray(this.internalValue)){const t=this.internalValue.map((t=>a(t,this.format).format("lll"))).join(` ${this.timesLabels.to} `);this.inputRef.value=t}else this.inputRef.value=a(this.internalValue,this.format).format("lll")}getClassName(t){return`${this.elementClassName}__${t}`}async clearValue(){this.internalValue=null,this.value=void 0,this.selectedDate=void 0,this.inputRef.value="",this.pickerRef&&(this.pickerRef.value=null),this.selectDateTime.emit(void 0)}render(){var t;return i(e,{key:"e922c649f8ed2bf03711fe99ae73bca550c9d8ef",class:this.elementClassName,"has-error":this.errorState,disabled:this.disabledState},i("label",{key:"6b8c053bcb4d232c52e0b95da141e4a433f2bc16",htmlFor:`${this.id}-input`,class:this.getClassName("label")},this.label),i("div",{key:"1950259cf662cedae9b8f0fed6a61f095d3a4424",class:this.getClassName("input-container")},i("input",{key:"1c6bfced55bd60706eadf6304eb7204c89bda8d6",id:`${this.id}-input`,ref:t=>this.inputRef=t,type:"text",class:this.getClassName("input"),placeholder:this.placeholder,disabled:this.disabledState,value:null===(t=this.internalValue)||void 0===t?void 0:t.toString(),onBlur:this.handleInputBlur,onChange:this.handleInputChange,"aria-describedby":this.errorState?`${this.id}-error`:void 0,"aria-invalid":this.errorState}),!this.inline&&i("button",{key:"60b202b017d7ffe5de182908c809a24eba4f8e56",type:"button",ref:t=>this.calendarButtonRef=t,onClick:this.handleCalendarButtonClick,class:this.getClassName("calendar-button"),disabled:this.disabledState},this.calendarButtonContent?i("span",{innerHTML:this.calendarButtonContent}):this.timesLabels.openCalendar)),i("tabworthy-dates-modal",{key:"83716e92fd3711c65b23f007bba209bcc60a4d7d",label:this.timesLabels.calendar,ref:t=>this.modalRef=t,onOpened:()=>{this.pickerRef&&(this.pickerRef.modalIsOpen=!0)},onClosed:()=>{this.pickerRef&&(this.pickerRef.modalIsOpen=!1)},inline:this.inline},i("div",{key:"3972712165cdc3069498d5683ca7b8b25041e44d",class:this.getClassName("picker-container")},i("tabworthy-dates-calendar",{key:"e6472861402e4926227657fb68f57d8671452260",range:this.range,locale:this.locale,onSelectDate:t=>this.handlePickerSelection(t.detail),onChangeMonth:t=>this.handleChangedMonths(t.detail),onChangeYear:t=>this.handleYearChange(t.detail),labels:this.datesCalendarLabels,ref:t=>this.pickerRef=t,startDate:this.startDate,firstDayOfWeek:this.firstDayOfWeek,showHiddenTitle:!0,disabled:this.disabledState,showMonthStepper:this.showMonthStepper,showYearStepper:this.showYearStepper,showClearButton:this.showClearButton,showTodayButton:this.showTodayButton,disableDate:this.disableDate,minDate:this.minDate,maxDate:this.maxDate,inline:this.inline},i("div",{key:"e9f7b9baa9544ae651b4b6b73094a215cabcc796",slot:"after-calendar",class:this.getClassName("time-section")},i("tabworthy-times-picker",{key:"b4c2f14b9311d1e3c186825785d6f64580f2896c",hours:this.selectedHours,minutes:this.selectedMinutes,use12HourFormat:this.use12HourFormat,disabled:this.disabledState,onTimeChanged:this.handleTimeChange}))))),this.errorState&&i("div",{key:"684dce5fc46c53feea28b19eca46746d7538aa3f",class:this.getClassName("input-error"),id:this.id?`${this.id}-error`:void 0,role:"status"},this.errorMessage))}get el(){return h(this)}static get watchers(){return{value:[{watchValue:0}],disabled:[{watchDisabled:0}],hasError:[{watchHasError:0}]}}};export{d as tabworthy_times}
@@ -0,0 +1 @@
1
+ import{r as t,c as e,h as i,H as s,g as a}from"./p-BusoZVTR.js";import{g as h,r as n,a as o,b as d,c as r,d as c,e as l,f as u,h as b,s as f,i as v,j as y,k as p,l as k,m as w,n as m,o as g,p as D,q as M,t as x,u as C,v as A,w as L}from"./p-BVHu5CWV.js";const T={clearButton:"Clear value",monthSelect:"Select month",nextMonthButton:"Next month",nextYearButton:"Next year",picker:"Choose date",previousMonthButton:"Previous month",previousYearButton:"Previous year",todayButton:"Show today",yearSelect:"Select year",keyboardHint:"Keyboard commands",selected:"Selected date",chooseAsStartDate:"choose as start date",chooseAsEndDate:"choose as end date"},B=class{constructor(i){t(this,i),this.selectDate=e(this,"selectDate"),this.changeMonth=e(this,"changeMonth"),this.changeYear=e(this,"changeYear"),this.disabled=!1,this.modalIsOpen=!1,this.disableDate=()=>!1,this.elementClassName="tabworthy-dates-calendar",this.firstDayOfWeek=0,this.range=!1,this.labels=T,this.locale=(null===navigator||void 0===navigator?void 0:navigator.language)||"en-US",this.inline=!1,this.showClearButton=!1,this.showMonthStepper=!0,this.showTodayButton=!0,this.showYearStepper=!1,this.showKeyboardHint=!1,this.showHiddenTitle=!0,this.startDate=h(new Date),this.init=()=>{this.currentDate=this.startDate?n(new Date(this.startDate)):new Date,this.updateWeekdays()},this.nextMonth=()=>{this.updateCurrentDate(o(this.currentDate))},this.nextYear=()=>{this.updateCurrentDate(d(this.currentDate))},this.previousMonth=()=>{this.updateCurrentDate(r(this.currentDate))},this.previousYear=()=>{this.updateCurrentDate(c(this.currentDate))},this.showToday=()=>{this.updateCurrentDate(new Date,!0)},this.clear=()=>{var t;this.value=void 0,null===(t=this.selectDate)||void 0===t||t.emit(void 0)},this.onClick=t=>{if(this.disabled)return;const e=t.target.closest("[data-date]");if(!Boolean(e))return;const i=n(new Date(e.dataset.date));this.updateCurrentDate(i),this.onSelectDate(i)},this.onMonthSelect=t=>{const e=+t.target.value-1,i=new Date(this.currentDate);l(i,this.minDate,this.maxDate)&&(i.setMonth(e),this.updateCurrentDate(i))},this.onYearSelect=t=>{var e;const i=+t.target.value,s=new Date(this.currentDate);l(s,this.minDate,this.maxDate)&&(s.setFullYear(i),null===(e=this.changeYear)||void 0===e||e.emit({year:i}),this.updateCurrentDate(s))},this.onKeyDown=t=>{this.disabled||("ArrowLeft"===t.code?(t.preventDefault(),this.updateCurrentDate(u(this.currentDate),!0)):"ArrowRight"===t.code?(t.preventDefault(),this.updateCurrentDate(b(this.currentDate),!0)):"ArrowUp"===t.code?(t.preventDefault(),this.updateCurrentDate(f(this.currentDate,7),!0)):"ArrowDown"===t.code?(t.preventDefault(),this.updateCurrentDate(v(this.currentDate,7),!0)):"PageUp"===t.code?(t.preventDefault(),this.updateCurrentDate(t.shiftKey?c(this.currentDate):r(this.currentDate),!0)):"PageDown"===t.code?(t.preventDefault(),this.updateCurrentDate(t.shiftKey?d(this.currentDate):o(this.currentDate),!0)):"Home"===t.code?(t.preventDefault(),this.updateCurrentDate(y(this.currentDate),!0)):"End"===t.code?(t.preventDefault(),this.updateCurrentDate(p(this.currentDate),!0)):"Space"!==t.code&&"Enter"!==t.code||(t.preventDefault(),this.onSelectDate(this.currentDate)))},this.onMouseEnter=t=>{var e;if(this.disabled)return;const i=n(new Date(null===(e=t.target.closest("td"))||void 0===e?void 0:e.dataset.date));this.hoveredDate=i},this.onMouseLeave=()=>{this.hoveredDate=void 0}}componentWillLoad(){this.init()}watchModalIsOpen(){!0===this.modalIsOpen&&(this.moveFocusOnModalOpen=!0)}watchFirstDayOfWeek(){this.updateWeekdays()}watchLocale(){Boolean(this.locale)||(this.locale=(null===navigator||void 0===navigator?void 0:navigator.language)||"en-US"),this.updateWeekdays()}watchRange(){var t;this.value=void 0,null===(t=this.selectDate)||void 0===t||t.emit(void 0)}watchStartDate(){this.currentDate=this.startDate?n(new Date(this.startDate)):new Date}watchValue(){Boolean(this.value)&&(Array.isArray(this.value)&&this.value.length>=1?this.currentDate=this.value[0]:this.value instanceof Date&&(this.currentDate=this.value))}componentDidRender(){this.moveFocusAfterMonthChanged&&(this.focusDate(this.currentDate),this.moveFocusAfterMonthChanged=!1),this.moveFocusOnModalOpen&&setTimeout((()=>{this.focusDate(this.currentDate),this.moveFocusOnModalOpen=!1}),100)}updateWeekdays(){this.weekdays=k(this.firstDayOfWeek,this.locale)}getClassName(t){return Boolean(t)?`${this.elementClassName}__${t}`:this.elementClassName}getCalendarRows(){const t=w(this.currentDate,!0,0===this.firstDayOfWeek?7:this.firstDayOfWeek),e=[];for(let i=0;i<t.length;i+=7){const s=t.slice(i,i+7);e.push(s)}return e}getTitle(){if(Boolean(this.currentDate))return Intl.DateTimeFormat(this.locale,{month:"long",year:"numeric"}).format(this.currentDate)}focusDate(t){var e;t&&(null===(e=this.el.querySelector(`[data-date="${h(t)}"]`))||void 0===e||e.focus())}updateCurrentDate(t,e){var i,s;const a=t.getMonth(),h=t.getFullYear();m(t,this.minDate)||(t=new Date(this.minDate)),g(t,this.maxDate)||(t=new Date(this.maxDate)),(a!==(null===(i=this.currentDate)||void 0===i?void 0:i.getMonth())||h!==this.currentDate.getFullYear())&&(null===(s=this.changeMonth)||void 0===s||s.emit({month:M(t),year:D(t)}),e&&(this.moveFocusAfterMonthChanged=!0)),this.currentDate=t,e&&this.focusDate(this.currentDate)}onSelectDate(t){var e,i,s,a;if(!this.disableDate(t)&&l(t,this.minDate,this.maxDate))if(this.isRangeValue(this.value)){const s=void 0===(null===(e=this.value)||void 0===e?void 0:e[0])||2===this.value.length?[t]:[this.value[0],t];2===s.length&&s[0]>s[1]&&s.reverse();const a=void 0===s[1]?[h(s[0])]:[h(s[0]),h(s[1])];this.value=s,null===(i=this.selectDate)||void 0===i||i.emit(a)}else{if((null===(s=this.value)||void 0===s?void 0:s.getTime())===t.getTime())return;this.value=t,null===(a=this.selectDate)||void 0===a||a.emit(h(t))}}isRangeValue(t){return!!this.range}render(){var t;const e=this.showTodayButton||this.showClearButton||this.showKeyboardHint,a={year:{prev:this.disabled||!!this.minDate&&new Date(this.minDate).getFullYear()>c(this.currentDate).getFullYear(),next:this.disabled||!!this.maxDate&&new Date(this.maxDate).getFullYear()<d(this.currentDate).getFullYear()},month:{prev:this.disabled||x(r(this.currentDate).getMonth(),r(this.currentDate).getFullYear(),this.minDate,this.maxDate),next:this.disabled||x(o(this.currentDate).getMonth(),o(this.currentDate).getFullYear(),this.minDate,this.maxDate)}};return i(s,{key:"79018439c3f99dc228ac0d429763d1e86fe9bb03"},i("div",{key:"8863cf5d0de75a1f358723440f11b70128d7c739",class:{[`${this.getClassName()}-wrapper`]:!0,[`${this.getClassName()}-wrapper--inline`]:this.inline}},i("div",{key:"b47630e94a50c0bb74da62f1d9e9931ed06e15ab",class:{[this.getClassName()]:!0,[`${this.getClassName()}--disabled`]:this.disabled}},i("div",{key:"594429a8b241c0024edde2e4adb211935e3579fd",class:this.getClassName("header")},this.showHiddenTitle&&i("span",{key:"3258ebc3b0a325f0f21af5126fa31c5cb0197ebb","aria-atomic":"true","aria-live":"polite",class:"visually-hidden"},this.getTitle()),this.showYearStepper&&i("button",{key:"0f7d853b969a89b76b5794d9b8c5e03f7ece778b","aria-label":this.labels.previousYearButton,class:this.getClassName("previous-year-button"),"aria-disabled":a.year.prev,innerHTML:this.previousYearButtonContent||void 0,onClick:this.previousYear,type:"button"},i("svg",{key:"1d4da9d54e875a85e22beae6f608de9ec0495a03",fill:"none",height:"24","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",stroke:"currentColor",viewBox:"0 0 24 24",width:"24"},i("polyline",{key:"0fd84be75c074c61a0d839694e5e1b8e7efa480e",points:"11 17 6 12 11 7"}),i("polyline",{key:"4b1c8d3e29718cabc669d9194af749ffc2cac7aa",points:"18 17 13 12 18 7"}))),this.showMonthStepper&&i("button",{key:"27402a2f431d68487775e4fbe548804755c569cc","aria-label":this.labels.previousMonthButton,class:this.getClassName("previous-month-button"),"aria-disabled":a.month.prev,innerHTML:this.previousMonthButtonContent||void 0,onClick:this.previousMonth,type:"button"},i("svg",{key:"b503e9f1d393c1a245da483b25edb14f473aac7d",fill:"none",height:"24","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",stroke:"currentColor",viewBox:"0 0 24 24",width:"24"},i("polyline",{key:"37241e518f64e1a7aba4153d0222649e62671ed4",points:"15 18 9 12 15 6"}))),i("span",{key:"3e87bb8129d4d7b1db718ee87f5164dec158fb1a",class:this.getClassName("current-month")},i("select",{key:"ae6c5128f2dc9ec17bd4d4c0090df4a62743b09c","aria-label":this.labels.monthSelect,class:this.getClassName("month-select"),"aria-disabled":this.disabled,name:"month",onChange:this.onMonthSelect},C(this.locale).map(((t,e)=>i("option",{key:t,selected:this.currentDate.getMonth()===e,value:e+1,disabled:x(e,this.currentDate.getFullYear(),this.minDate,this.maxDate)},t)))),i("input",{key:"733a5e0025571c54fc27616c200bfbf07de436cc","aria-label":this.labels.yearSelect,class:this.getClassName("year-select"),"aria-disabled":this.disabled,max:this.maxDate?this.maxDate.slice(0,4):9999,min:this.minDate?this.minDate.slice(0,4):1,name:"year",onChange:this.onYearSelect,type:"number",value:this.currentDate.getFullYear()})),this.showMonthStepper&&i("button",{key:"eaa9e5e613835a9108f17991ba4743020cfa3146","aria-label":this.labels.nextMonthButton,class:this.getClassName("next-month-button"),"aria-disabled":a.month.next,innerHTML:this.nextMonthButtonContent||void 0,onClick:this.nextMonth,type:"button"},i("svg",{key:"5729113b90336e0e8d2ade0a24952d186e12867c",fill:"none",height:"24","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",stroke:"currentColor",viewBox:"0 0 24 24",width:"24"},i("polyline",{key:"a6cc05a5b83eb6f162654782466a43bd98ada883",points:"9 18 15 12 9 6"}))),this.showYearStepper&&i("button",{key:"6a8556ddc516e5c9a06fd9d71cfa939de48e9bbe","aria-label":this.labels.nextYearButton,class:this.getClassName("next-year-button"),"aria-disabled":a.year.next,innerHTML:this.nextYearButtonContent||void 0,onClick:this.nextYear,type:"button"},i("svg",{key:"17e51e43e8a378fb73e1d51c8a75bb8e890af433",fill:"none",height:"24","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",stroke:"currentColor",viewBox:"0 0 24 24",width:"24"},i("polyline",{key:"bdf9cf173de2dc96beaf2bc615aea901899e5907",points:"13 17 18 12 13 7"}),i("polyline",{key:"638e86d7b823782b2331c2569531def9f267dce9",points:"6 17 11 12 6 7"})))),i("div",{key:"8fbe9e86646e09853205865351f3aa298877c43a",class:this.getClassName("body")},i("table",{key:"bf374b391788b26485362a368a10c009b42a9d84",class:this.getClassName("calendar"),onKeyDown:this.onKeyDown,role:"grid","aria-label":this.getTitle()},i("thead",{key:"7cb065ee0fa4bd944c79a130b107d59e8e622b89",class:this.getClassName("calendar-header")},i("tr",{key:"30b196641286a6f9adb3d37167172858a34f2933",class:this.getClassName("weekday-row")},null===(t=this.weekdays)||void 0===t?void 0:t.map((t=>i("th",{role:"columnheader",abbr:t[1],class:this.getClassName("weekday"),key:t[0],scope:"col"},i("span",{"aria-hidden":"true"},t[0]),i("span",{class:"visually-hidden"},t[1])))))),i("tbody",{key:"922edf01c35e7512654d8661348301d275c67647"},this.getCalendarRows().map((t=>{const e=`row-${t[0].getMonth()}-${t[0].getDate()}`;return i("tr",{class:this.getClassName("calendar-row"),key:e},t.map((t=>{var e,s,a;const n=A(t,this.currentDate),o=t.getMonth()!==(null===(e=this.currentDate)||void 0===e?void 0:e.getMonth()),d=Array.isArray(this.value)?A(t,this.value[0])||this.value[1]&&l(t,h(this.value[0]),h(this.value[1])):A(t,this.value),r=this.disableDate(t)||!l(t,this.minDate,this.maxDate),c=!!this.isRangeValue(this.value)&&L(t,{from:null===(s=this.value)||void 0===s?void 0:s[0],to:(null===(a=this.value)||void 0===a?void 0:a[1])||this.hoveredDate||this.currentDate})&&!r,u=A(t,new Date),b=`cell-${t.getMonth()}-${t.getDate()}`,f={[this.getClassName("date")]:!0,[this.getClassName("date--current")]:n,[this.getClassName("date--disabled")]:r,[this.getClassName("date--overflowing")]:o,[this.getClassName("date--today")]:u,[this.getClassName("date--selected")]:d,[this.getClassName("date--in-range")]:c},v=d?"strong":u?"em":"span";return i("td",{"aria-disabled":String(r),"aria-selected":d?"true":void 0,class:f,"data-date":h(t),key:b,onClick:this.onClick,onMouseEnter:this.onMouseEnter,onMouseLeave:this.onMouseLeave,role:"gridcell",tabIndex:A(t,this.currentDate)&&!this.disabled?0:-1},i(v,{"aria-hidden":"true"},t.getDate()),i("span",{class:"visually-hidden"},(()=>{if(this.range){let e=this.value?"":`, ${this.labels.chooseAsStartDate}.`;return Array.isArray(this.value)&&(e={1:`, ${this.labels.chooseAsEndDate}.`,2:`, ${this.labels.chooseAsStartDate}.`}[this.value.length]),`${d?`${this.labels.selected}, `:""}${Intl.DateTimeFormat(this.locale,{day:"numeric",month:"long",year:"numeric"}).format(t)}${e}`}return`${d?`${this.labels.selected}, `:""}${Intl.DateTimeFormat(this.locale,{day:"numeric",month:"long",year:"numeric"}).format(t)}`})()))})))}))))),e&&i("div",{key:"0a189fdb44b39bddc7a26c7bd3e4a889307fee39",class:this.getClassName("footer")},i("div",{key:"fbdf81d3a93afa19cdedba1423d2c64ab4e1fbcb",class:this.getClassName("footer-buttons")},this.showTodayButton&&i("button",{key:"4faad216c53bda804e8b660d758e30e0bf538940",class:this.getClassName("today-button"),disabled:this.disabled,innerHTML:this.todayButtonContent||void 0,onClick:this.showToday,type:"button"},this.labels.todayButton),this.showClearButton&&i("button",{key:"84ad553438da2c701c0ec75328eac36d01b3daa3",class:this.getClassName("clear-button"),disabled:this.disabled,innerHTML:this.clearButtonContent||void 0,onClick:this.clear,type:"button"},this.labels.clearButton)),this.showKeyboardHint&&!window.matchMedia("(pointer: coarse)").matches&&i("button",{key:"f63c1d1c802173072424a098ab52fffe35df7f56",type:"button",onClick:()=>alert("Todo: Add Keyboard helper!"),class:this.getClassName("keyboard-hint")},i("svg",{key:"790b14010416be81d39a52549a5677116e436a63",xmlns:"http://www.w3.org/2000/svg",height:"1em",width:"1em",viewBox:"0 0 48 48",fill:"currentColor"},i("path",{key:"83a801f97bf0a2fbd33f728cd00c5dfab75eb213",d:"M7 38q-1.2 0-2.1-.925Q4 36.15 4 35V13q0-1.2.9-2.1.9-.9 2.1-.9h34q1.2 0 2.1.9.9.9.9 2.1v22q0 1.15-.9 2.075Q42.2 38 41 38Zm0-3h34V13H7v22Zm8-3.25h18v-3H15Zm-4.85-6.25h3v-3h-3Zm6.2 0h3v-3h-3Zm6.15 0h3v-3h-3Zm6.2 0h3v-3h-3Zm6.15 0h3v-3h-3Zm-24.7-6.25h3v-3h-3Zm6.2 0h3v-3h-3Zm6.15 0h3v-3h-3Zm6.2 0h3v-3h-3Zm6.15 0h3v-3h-3ZM7 35V13v22Z"})),this.labels.keyboardHint))),i("slot",{key:"1b6c88f7c9e4e6fa7109b99ef774af1ee8de24ea",name:"after-calendar"})))}get el(){return a(this)}static get watchers(){return{modalIsOpen:[{watchModalIsOpen:0}],firstDayOfWeek:[{watchFirstDayOfWeek:0}],locale:[{watchLocale:0}],range:[{watchRange:0}],startDate:[{watchStartDate:0}],value:[{watchValue:0}]}}};function H(t,e,i,s=20,a=0){let h=[];if(a>=s)return h;const n=t=>{const h=t.assignedNodes().filter((t=>1===t.nodeType));return h.length>0?H(h[0].parentElement,e,i,s,a+1):[]},o=Array.from(t.children||[]);for(const t of o)e(t)||(i(t)&&h.push(t),null!=t.shadowRoot?h.push(...H(t.shadowRoot,e,i,s,a+1)):"SLOT"===t.tagName?h.push(...n(t)):h.push(...H(t,e,i,s,a+1)));return h}function $(t){return t.hasAttribute("hidden")||t.hasAttribute("aria-hidden")&&"false"!==t.getAttribute("aria-hidden")||"none"===t.style.display||"0"===t.style.opacity||"hidden"===t.style.visibility||"collapse"===t.style.visibility}function S(t){return"-1"!==t.getAttribute("tabindex")&&!$(t)&&!function(t){return t.hasAttribute("disabled")||t.hasAttribute("aria-disabled")&&"false"!==t.getAttribute("aria-disabled")}(t)&&(t.hasAttribute("tabindex")||(t instanceof HTMLAnchorElement||t instanceof HTMLAreaElement)&&t.hasAttribute("href")||t instanceof HTMLButtonElement||t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement||t instanceof HTMLSelectElement||t instanceof HTMLIFrameElement)}B.style=".visually-hidden.sc-tabworthy-dates-calendar{position:absolute;overflow:hidden;width:1px;height:1px;white-space:nowrap;clip:rect(0 0 0 0);-webkit-clip-path:inset(50%);clip-path:inset(50%)}";const E=new Map,Z=document.createElement("template");Z.innerHTML='\n\t<div id="start"></div>\n\t<div id="backup"></div>\n\t<slot></slot>\n\t<div id="end"></div>\n';class W extends HTMLElement{constructor(){super(),this.debounceId=Math.random().toString(),this._focused=!1;const t=this.attachShadow({mode:"open"});t.appendChild(Z.content.cloneNode(!0)),this.$backup=t.querySelector("#backup"),this.$start=t.querySelector("#start"),this.$end=t.querySelector("#end"),this.focusLastElement=this.focusLastElement.bind(this),this.focusFirstElement=this.focusFirstElement.bind(this),this.onFocusIn=this.onFocusIn.bind(this),this.onFocusOut=this.onFocusOut.bind(this)}static get observedAttributes(){return["inactive"]}get inactive(){return this.hasAttribute("inactive")}set inactive(t){t?this.setAttribute("inactive",""):this.removeAttribute("inactive")}get focused(){return this._focused}connectedCallback(){this.$start.addEventListener("focus",this.focusLastElement),this.$end.addEventListener("focus",this.focusFirstElement),this.addEventListener("focusin",this.onFocusIn),this.addEventListener("focusout",this.onFocusOut),this.render()}disconnectedCallback(){this.$start.removeEventListener("focus",this.focusLastElement),this.$end.removeEventListener("focus",this.focusFirstElement),this.removeEventListener("focusin",this.onFocusIn),this.removeEventListener("focusout",this.onFocusOut)}attributeChangedCallback(){this.render()}focusFirstElement(){this.trapFocus()}focusLastElement(){this.trapFocus(!0)}getFocusableElements(){return H(this,$,S)}trapFocus(t){if(this.inactive)return;let e=this.getFocusableElements();e.length>0?(t?e[e.length-1].focus():e[0].focus(),this.$backup.setAttribute("tabindex","-1")):(this.$backup.setAttribute("tabindex","0"),this.$backup.focus())}onFocusIn(){this.updateFocused(!0)}onFocusOut(){this.updateFocused(!1)}updateFocused(t){!function(t,e,i){const s=E.get(i);null!=s&&window.clearTimeout(s),E.set(i,window.setTimeout((()=>{t(),E.delete(i)}),0))}((()=>{this.focused!==t&&(this._focused=t,this.render())}),0,this.debounceId)}render(){this.$start.setAttribute("tabindex",!this.focused||this.inactive?"-1":"0"),this.$end.setAttribute("tabindex",!this.focused||this.inactive?"-1":"0"),this.focused?this.setAttribute("focused",""):this.removeAttribute("focused")}}window.customElements.define("focus-trap",W);var I=new WeakMap,F=new WeakMap,V={},O=0,j=function(t){return t&&(t.host||j(t.parentNode))},R=function(t,e,i){void 0===i&&(i="data-aria-hidden");var s=Array.from(Array.isArray(t)?t:[t]),a=function(t){return"undefined"==typeof document?null:(Array.isArray(t)?t[0]:t).ownerDocument.body}(t);return a?(s.push.apply(s,Array.from(a.querySelectorAll("[aria-live]"))),function(t,e,i,s){var a=function(t,e){return e.map((function(e){if(t.contains(e))return e;var i=j(e);return i&&t.contains(i)?i:(console.error("aria-hidden",e,"in not contained inside",t,". Doing nothing"),null)})).filter((function(t){return Boolean(t)}))}(e,Array.isArray(t)?t:[t]);V[i]||(V[i]=new WeakMap);var h=V[i],n=[],o=new Set,d=new Set(a),r=function(t){t&&!o.has(t)&&(o.add(t),r(t.parentNode))};a.forEach(r);var c=function(t){t&&!d.has(t)&&Array.prototype.forEach.call(t.children,(function(t){if(o.has(t))c(t);else{var e=t.getAttribute(s),a=null!==e&&"false"!==e,d=(I.get(t)||0)+1,r=(h.get(t)||0)+1;I.set(t,d),h.set(t,r),n.push(t),1===d&&a&&F.set(t,!0),1===r&&t.setAttribute(i,"true"),a||t.setAttribute(s,"true")}}))};return c(e),o.clear(),O++,function(){n.forEach((function(t){var e=I.get(t)-1,a=h.get(t)-1;I.set(t,e),h.set(t,a),e||(F.has(t)||t.removeAttribute(s),F.delete(t)),a||t.removeAttribute(i)})),--O||(I=new WeakMap,I=new WeakMap,F=new WeakMap,V={})}}(s,a,i,"aria-hidden")):function(){return null}};const _=class{constructor(i){t(this,i),this.opened=e(this,"opened"),this.closed=e(this,"closed"),this.inline=!1,this.closing=!1,this.showing=this.inline||!1,this.onKeyDown=t=>{"Escape"===t.code&&this.close()}}async open(){this.inline||(this.showing=!0,this.undo=R(this.el),this.opened.emit(void 0))}async close(){this.inline||(this.showing=!1,this.closed.emit(void 0),this.undo(),this.triggerElement&&this.triggerElement.focus())}async getState(){return this.showing}async setTriggerElement(t){this.triggerElement=t}handleClick(t){this.showing&&!this.el.contains(t.target)&&this.close()}render(){return i(s,{key:"dd44f82a23c471268369362e7f0899d197b6686a",showing:this.showing,ref:t=>t&&(this.el=t)},!this.inline&&this.showing&&i("div",{key:"6c5d845e75737c366defff2434f51ca345a172f3",part:"body",onKeyDown:this.onKeyDown,role:"dialog",tabindex:-1,"aria-hidden":!this.showing,"aria-label":this.label,"aria-modal":this.showing},i("focus-trap",{key:"56beecf073b790849d2761b3ac135641612744e1"},i("div",{key:"85aca24946135337732f404ac164553f4374c9ec",part:"content"},i("slot",{key:"cb7b7c57ed1012256e3e045f64b40ce8c5d8dd8b"})))),this.inline&&i("div",{key:"0a6d50757d0c77f1cc781dfe7676a4b3f8e74c22",part:"content"},i("slot",{key:"17e71b147f00061c3f3f4deb3b66abb465714f8a"})))}};_.style=":host::part(body){position:absolute;width:-moz-fit-content;width:fit-content;z-index:1200;margin-top:0.5rem}:host::part(backdrop){}:host::part(content){}";export{B as tabworthy_dates_calendar,_ as tabworthy_dates_modal}